Index: uspace/drv/ehci-hcd/pci.c
===================================================================
--- uspace/drv/ehci-hcd/pci.c	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ uspace/drv/ehci-hcd/pci.c	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -247,9 +247,9 @@
 
 
-	if ((value & USBLEGSUP_BIOS_CONTROL) != 0) {
+	if ((value & USBLEGSUP_BIOS_CONTROL) == 0) {
 		usb_log_info("BIOS released control after %d usec.\n", wait);
 	} else {
 		/* BIOS failed to hand over control, this should not happen. */
-		usb_log_warning( "BIOS failed to release control after"
+		usb_log_warning( "BIOS failed to release control after "
 		    "%d usecs, force it.\n", wait);
 		ret = async_req_3_0(parent_phone, DEV_IFACE_ID(PCI_DEV_IFACE),
@@ -258,5 +258,4 @@
 		CHECK_RET_HANGUP_RETURN(ret,
 		    "Failed(%d) to force OS EHCI control.\n", ret);
-		/* TODO: This does not seem to work on my machine */
 	}
 
@@ -280,7 +279,7 @@
 	usb_log_debug2("USBLEGSUP: %x.\n", value);
 
-/*
- * TURN OFF EHCI FOR NOW, REMOVE IF THE DRIVER IS IMPLEMENTED
- */
+	/*
+	 * TURN OFF EHCI FOR NOW, DRIVER WILL REINITIALIZE IT
+	 */
 
 	/* Get size of capability registers in memory space. */
Index: uspace/drv/uhci-hcd/Makefile
===================================================================
--- uspace/drv/uhci-hcd/Makefile	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ uspace/drv/uhci-hcd/Makefile	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -35,7 +35,8 @@
 	iface.c \
 	main.c \
-	root_hub.c \
 	transfer_list.c \
 	uhci.c \
+	uhci_hc.c \
+	uhci_rh.c \
 	uhci_struct/transfer_descriptor.c \
 	utils/device_keeper.c \
Index: uspace/drv/uhci-hcd/batch.c
===================================================================
--- uspace/drv/uhci-hcd/batch.c	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ uspace/drv/uhci-hcd/batch.c	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -40,5 +40,5 @@
 #include "batch.h"
 #include "transfer_list.h"
-#include "uhci.h"
+#include "uhci_hc.h"
 #include "utils/malloc32.h"
 
@@ -100,8 +100,8 @@
 	bzero(instance, sizeof(batch_t));
 
-	instance->qh = malloc32(sizeof(queue_head_t));
+	instance->qh = malloc32(sizeof(qh_t));
 	CHECK_NULL_DISPOSE_RETURN(instance->qh,
 	    "Failed to allocate batch queue head.\n");
-	queue_head_init(instance->qh);
+	qh_init(instance->qh);
 
 	instance->packets = (size + max_packet_size - 1) / max_packet_size;
@@ -114,6 +114,4 @@
 	    instance->tds, "Failed to allocate transfer descriptors.\n");
 	bzero(instance->tds, sizeof(td_t) * instance->packets);
-
-//	const size_t transport_size = max_packet_size * instance->packets;
 
 	if (size > 0) {
@@ -143,11 +141,8 @@
 	instance->speed = speed;
 	instance->manager = manager;
-
-	if (func_out)
-		instance->callback_out = func_out;
-	if (func_in)
-		instance->callback_in = func_in;
-
-	queue_head_set_element_td(instance->qh, addr_to_phys(instance->tds));
+	instance->callback_out = func_out;
+	instance->callback_in = func_in;
+
+	qh_set_element_td(instance->qh, addr_to_phys(instance->tds));
 
 	usb_log_debug("Batch(%p) %d:%d memory structures ready.\n",
@@ -177,4 +172,5 @@
 			usb_log_debug("Batch(%p) found error TD(%d):%x.\n",
 			    instance, i, instance->tds[i].status);
+			td_print_status(&instance->tds[i]);
 
 			device_keeper_set_toggle(instance->manager,
@@ -318,4 +314,5 @@
 		++packet;
 	}
+	td_set_ioc(&instance->tds[packet - 1]);
 	device_keeper_set_toggle(instance->manager, instance->target, toggle);
 }
@@ -369,6 +366,5 @@
 	    0, 1, false, low_speed, instance->target, status_stage, NULL, NULL);
 
-
-	instance->tds[packet].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG;
+	td_set_ioc(&instance->tds[packet]);
 	usb_log_debug2("Control last TD status: %x.\n",
 	    instance->tds[packet].status);
@@ -454,7 +450,7 @@
 {
 	assert(instance);
-	uhci_t *hc = fun_to_uhci(instance->fun);
+	uhci_hc_t *hc = fun_to_uhci_hc(instance->fun);
 	assert(hc);
-	return uhci_schedule(hc, instance);
+	return uhci_hc_schedule(hc, instance);
 }
 /**
Index: uspace/drv/uhci-hcd/batch.h
===================================================================
--- uspace/drv/uhci-hcd/batch.h	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ uspace/drv/uhci-hcd/batch.h	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -50,8 +50,6 @@
 	usb_target_t target;
 	usb_transfer_type_t transfer_type;
-	union {
-		usbhc_iface_transfer_in_callback_t callback_in;
-		usbhc_iface_transfer_out_callback_t callback_out;
-	};
+	usbhc_iface_transfer_in_callback_t callback_in;
+	usbhc_iface_transfer_out_callback_t callback_out;
 	void *arg;
 	char *transport_buffer;
@@ -65,5 +63,5 @@
 	int error;
 	ddf_fun_t *fun;
-	queue_head_t *qh;
+	qh_t *qh;
 	td_t *tds;
 	void (*next_step)(struct batch*);
Index: uspace/drv/uhci-hcd/iface.c
===================================================================
--- uspace/drv/uhci-hcd/iface.c	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ uspace/drv/uhci-hcd/iface.c	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -40,5 +40,5 @@
 
 #include "iface.h"
-#include "uhci.h"
+#include "uhci_hc.h"
 #include "utils/device_keeper.h"
 
@@ -53,5 +53,5 @@
 {
 	assert(fun);
-	uhci_t *hc = fun_to_uhci(fun);
+	uhci_hc_t *hc = fun_to_uhci_hc(fun);
 	assert(hc);
 	usb_log_debug("Default address request with speed %d.\n", speed);
@@ -68,5 +68,5 @@
 {
 	assert(fun);
-	uhci_t *hc = fun_to_uhci(fun);
+	uhci_hc_t *hc = fun_to_uhci_hc(fun);
 	assert(hc);
 	usb_log_debug("Default address release.\n");
@@ -86,5 +86,5 @@
 {
 	assert(fun);
-	uhci_t *hc = fun_to_uhci(fun);
+	uhci_hc_t *hc = fun_to_uhci_hc(fun);
 	assert(hc);
 	assert(address);
@@ -109,5 +109,5 @@
 {
 	assert(fun);
-	uhci_t *hc = fun_to_uhci(fun);
+	uhci_hc_t *hc = fun_to_uhci_hc(fun);
 	assert(hc);
 	usb_log_debug("Address bind %d-%d.\n", address, handle);
@@ -125,5 +125,5 @@
 {
 	assert(fun);
-	uhci_t *hc = fun_to_uhci(fun);
+	uhci_hc_t *hc = fun_to_uhci_hc(fun);
 	assert(hc);
 	usb_log_debug("Address release %d.\n", address);
@@ -148,5 +148,5 @@
 {
 	assert(fun);
-	uhci_t *hc = fun_to_uhci(fun);
+	uhci_hc_t *hc = fun_to_uhci_hc(fun);
 	assert(hc);
 	usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
@@ -180,5 +180,5 @@
 {
 	assert(fun);
-	uhci_t *hc = fun_to_uhci(fun);
+	uhci_hc_t *hc = fun_to_uhci_hc(fun);
 	assert(hc);
 	usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
@@ -211,5 +211,5 @@
 {
 	assert(fun);
-	uhci_t *hc = fun_to_uhci(fun);
+	uhci_hc_t *hc = fun_to_uhci_hc(fun);
 	assert(hc);
 	usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
@@ -243,5 +243,5 @@
 {
 	assert(fun);
-	uhci_t *hc = fun_to_uhci(fun);
+	uhci_hc_t *hc = fun_to_uhci_hc(fun);
 	assert(hc);
 	usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
@@ -277,9 +277,9 @@
 {
 	assert(fun);
-	uhci_t *hc = fun_to_uhci(fun);
-	assert(hc);
-	usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
-	usb_log_debug("Control WRITE %d:%d %zu(%zu).\n",
-	    target.address, target.endpoint, size, max_packet_size);
+	uhci_hc_t *hc = fun_to_uhci_hc(fun);
+	assert(hc);
+	usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
+	usb_log_debug("Control WRITE (%d) %d:%d %zu(%zu).\n",
+	    speed, target.address, target.endpoint, size, max_packet_size);
 
 	if (setup_size != 8)
@@ -315,10 +315,10 @@
 {
 	assert(fun);
-	uhci_t *hc = fun_to_uhci(fun);
-	assert(hc);
-	usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
-
-	usb_log_debug("Control READ %d:%d %zu(%zu).\n",
-	    target.address, target.endpoint, size, max_packet_size);
+	uhci_hc_t *hc = fun_to_uhci_hc(fun);
+	assert(hc);
+	usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
+
+	usb_log_debug("Control READ(%d) %d:%d %zu(%zu).\n",
+	    speed, target.address, target.endpoint, size, max_packet_size);
 	batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
 	    max_packet_size, speed, data, size, setup_data, setup_size, callback,
@@ -330,5 +330,5 @@
 }
 /*----------------------------------------------------------------------------*/
-usbhc_iface_t uhci_iface = {
+usbhc_iface_t uhci_hc_iface = {
 	.reserve_default_address = reserve_default_address,
 	.release_default_address = release_default_address,
Index: uspace/drv/uhci-hcd/iface.h
===================================================================
--- uspace/drv/uhci-hcd/iface.h	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ uspace/drv/uhci-hcd/iface.h	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -38,5 +38,5 @@
 #include <usbhc_iface.h>
 
-extern usbhc_iface_t uhci_iface;
+extern usbhc_iface_t uhci_hc_iface;
 
 #endif
Index: uspace/drv/uhci-hcd/main.c
===================================================================
--- uspace/drv/uhci-hcd/main.c	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ uspace/drv/uhci-hcd/main.c	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -33,16 +33,11 @@
  */
 #include <ddf/driver.h>
-#include <ddf/interrupt.h>
-#include <device/hw_res.h>
 #include <errno.h>
 #include <str_error.h>
 
-#include <usb_iface.h>
 #include <usb/ddfiface.h>
 #include <usb/debug.h>
 
 #include "iface.h"
-#include "pci.h"
-#include "root_hub.h"
 #include "uhci.h"
 
@@ -60,20 +55,5 @@
 };
 /*----------------------------------------------------------------------------*/
-/** IRQ handling callback, identifies devic
- *
- * @param[in] dev DDF instance of the device to use.
- * @param[in] iid (Unused).
- * @param[in] call Pointer to the call that represents interrupt.
- */
-static void irq_handler(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *call)
-{
-	assert(dev);
-	uhci_t *hc = dev_to_uhci(dev);
-	uint16_t status = IPC_GET_ARG1(*call);
-	assert(hc);
-	uhci_interrupt(hc, status);
-}
-/*----------------------------------------------------------------------------*/
-/** Initializes a new ddf driver instance of UHCI hcd.
+/** Initializes a new ddf driver instance for uhci hc and hub.
  *
  * @param[in] device DDF instance of the device to initialize.
@@ -85,85 +65,19 @@
 int uhci_add_device(ddf_dev_t *device)
 {
+	usb_log_info("uhci_add_device() called\n");
 	assert(device);
-	uhci_t *hcd = NULL;
-#define CHECK_RET_FREE_HC_RETURN(ret, message...) \
-if (ret != EOK) { \
-	usb_log_error(message); \
-	if (hcd != NULL) \
-		free(hcd); \
-	return ret; \
-}
+	uhci_t *uhci = malloc(sizeof(uhci_t));
+	if (uhci == NULL) {
+		usb_log_error("Failed to allocate UHCI driver.\n");
+		return ENOMEM;
+	}
 
-	usb_log_info("uhci_add_device() called\n");
-
-	uintptr_t io_reg_base = 0;
-	size_t io_reg_size = 0;
-	int irq = 0;
-
-	int ret =
-	    pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq);
-	CHECK_RET_FREE_HC_RETURN(ret,
-	    "Failed(%d) to get I/O addresses:.\n", ret, device->handle);
-	usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n",
-	    io_reg_base, io_reg_size, irq);
-
-	ret = pci_disable_legacy(device);
-	CHECK_RET_FREE_HC_RETURN(ret,
-	    "Failed(%d) to disable legacy USB: %s.\n", ret, str_error(ret));
-
-#if 0
-	ret = pci_enable_interrupts(device);
+	int ret = uhci_init(uhci, device);
 	if (ret != EOK) {
-		usb_log_warning(
-		    "Failed(%d) to enable interrupts, fall back to polling.\n",
-		    ret);
+		usb_log_error("Failed to initialzie UHCI driver.\n");
+		return ret;
 	}
-#endif
-
-	hcd = malloc(sizeof(uhci_t));
-	ret = (hcd != NULL) ? EOK : ENOMEM;
-	CHECK_RET_FREE_HC_RETURN(ret,
-	    "Failed(%d) to allocate memory for uhci hcd.\n", ret);
-
-	ret = uhci_init(hcd, device, (void*)io_reg_base, io_reg_size);
-	CHECK_RET_FREE_HC_RETURN(ret, "Failed(%d) to init uhci-hcd.\n", ret);
-#undef CHECK_RET_FREE_HC_RETURN
-
-	/*
-	 * We might free hcd, but that does not matter since no one
-	 * else would access driver_data anyway.
-	 */
-	device->driver_data = hcd;
-
-	ddf_fun_t *rh = NULL;
-#define CHECK_RET_FINI_FREE_RETURN(ret, message...) \
-if (ret != EOK) { \
-	usb_log_error(message); \
-	if (hcd != NULL) {\
-		uhci_fini(hcd); \
-		free(hcd); \
-	} \
-	if (rh != NULL) \
-		free(rh); \
-	return ret; \
-}
-
-	/* It does no harm if we register this on polling */
-	ret = register_interrupt_handler(device, irq, irq_handler,
-	    &hcd->interrupt_code);
-	CHECK_RET_FINI_FREE_RETURN(ret,
-	    "Failed(%d) to register interrupt handler.\n", ret);
-
-	ret = setup_root_hub(&rh, device);
-	CHECK_RET_FINI_FREE_RETURN(ret,
-	    "Failed(%d) to setup UHCI root hub.\n", ret);
-	rh->driver_data = hcd->ddf_instance;
-
-	ret = ddf_fun_bind(rh);
-	CHECK_RET_FINI_FREE_RETURN(ret,
-	    "Failed(%d) to register UHCI root hub.\n", ret);
-
+	device->driver_data = uhci;
 	return EOK;
-#undef CHECK_RET_FINI_FREE_RETURN
 }
 /*----------------------------------------------------------------------------*/
Index: pace/drv/uhci-hcd/root_hub.c
===================================================================
--- uspace/drv/uhci-hcd/root_hub.c	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ 	(revision )
@@ -1,173 +1,0 @@
-/*
- * Copyright (c) 2011 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/** @addtogroup usb
- * @{
- */
-/** @file
- * @brief UHCI driver
- */
-#include <assert.h>
-#include <errno.h>
-#include <str_error.h>
-#include <stdio.h>
-#include <ops/hw_res.h>
-
-#include <usb_iface.h>
-#include <usb/debug.h>
-
-#include "root_hub.h"
-#include "uhci.h"
-
-/*----------------------------------------------------------------------------*/
-/** Gets handle of the respective hc (parent device).
- *
- * @param[in] root_hub_fun Root hub function seeking hc handle.
- * @param[out] handle Place to write the handle.
- * @return Error code.
- */
-static int usb_iface_get_hc_handle_rh_impl(
-    ddf_fun_t *root_hub_fun, devman_handle_t *handle)
-{
-	/* TODO: Can't this use parent pointer? */
-	ddf_fun_t *hc_fun = root_hub_fun->driver_data;
-	assert(hc_fun != NULL);
-
-	*handle = hc_fun->handle;
-
-	return EOK;
-}
-/*----------------------------------------------------------------------------*/
-/** Gets USB address of the calling device.
- *
- * @param[in] fun Root hub function.
- * @param[in] handle Handle of the device seeking address.
- * @param[out] address Place to store found address.
- * @return Error code.
- */
-static int usb_iface_get_address_rh_impl(
-    ddf_fun_t *fun, devman_handle_t handle, usb_address_t *address)
-{
-	/* TODO: What does this do? Is it neccessary? Can't it use implemented
-	 * hc function?*/
-	assert(fun);
-	ddf_fun_t *hc_fun = fun->driver_data;
-	assert(hc_fun);
-	uhci_t *hc = fun_to_uhci(hc_fun);
-	assert(hc);
-
-	usb_address_t addr = device_keeper_find(&hc->device_manager, handle);
-	if (addr < 0) {
-		return addr;
-	}
-
-	if (address != NULL) {
-		*address = addr;
-	}
-
-	return EOK;
-}
-/*----------------------------------------------------------------------------*/
-usb_iface_t usb_iface_root_hub_fun_impl = {
-	.get_hc_handle = usb_iface_get_hc_handle_rh_impl,
-	.get_address = usb_iface_get_address_rh_impl
-};
-/*----------------------------------------------------------------------------*/
-/** Gets root hub hw resources.
- *
- * @param[in] fun Root hub function.
- * @return Pointer to the resource list used by the root hub.
- */
-static hw_resource_list_t *get_resource_list(ddf_fun_t *dev)
-{
-	assert(dev);
-	ddf_fun_t *hc_ddf_instance = dev->driver_data;
-	assert(hc_ddf_instance);
-	uhci_t *hc = hc_ddf_instance->driver_data;
-	assert(hc);
-
-	/* TODO: fix memory leak */
-	hw_resource_list_t *resource_list = malloc(sizeof(hw_resource_list_t));
-	assert(resource_list);
-	resource_list->count = 1;
-	resource_list->resources = malloc(sizeof(hw_resource_t));
-	assert(resource_list->resources);
-	resource_list->resources[0].type = IO_RANGE;
-	resource_list->resources[0].res.io_range.address =
-	    ((uintptr_t)hc->registers) + 0x10; // see UHCI design guide
-	resource_list->resources[0].res.io_range.size = 4;
-	resource_list->resources[0].res.io_range.endianness = LITTLE_ENDIAN;
-
-	return resource_list;
-}
-/*----------------------------------------------------------------------------*/
-static hw_res_ops_t hw_res_iface = {
-	.get_resource_list = get_resource_list,
-	.enable_interrupt = NULL
-};
-/*----------------------------------------------------------------------------*/
-static ddf_dev_ops_t root_hub_ops = {
-	.interfaces[USB_DEV_IFACE] = &usb_iface_root_hub_fun_impl,
-	.interfaces[HW_RES_DEV_IFACE] = &hw_res_iface
-};
-/*----------------------------------------------------------------------------*/
-int setup_root_hub(ddf_fun_t **fun, ddf_dev_t *hc)
-{
-	assert(fun);
-	assert(hc);
-	int ret;
-
-	ddf_fun_t *hub = ddf_fun_create(hc, fun_inner, "root-hub");
-	if (!hub) {
-		usb_log_error("Failed to create root hub device structure.\n");
-		return ENOMEM;
-	}
-
-	char *match_str;
-	ret = asprintf(&match_str, "usb&uhci&root-hub");
-	if (ret < 0) {
-		usb_log_error("Failed to create root hub match string.\n");
-		ddf_fun_destroy(hub);
-		return ENOMEM;
-	}
-
-	ret = ddf_fun_add_match_id(hub, match_str, 100);
-	if (ret != EOK) {
-		usb_log_error("Failed(%d) to add root hub match id: %s\n",
-		    ret, str_error(ret));
-		ddf_fun_destroy(hub);
-		return ret;
-	}
-
-	hub->ops = &root_hub_ops;
-
-	*fun = hub;
-	return EOK;
-}
-/**
- * @}
- */
Index: pace/drv/uhci-hcd/root_hub.h
===================================================================
--- uspace/drv/uhci-hcd/root_hub.h	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ 	(revision )
@@ -1,45 +1,0 @@
-/*
- * Copyright (c) 2010 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup drvusbuhci
- * @{
- */
-/** @file
- * @brief UHCI driver
- */
-#ifndef DRV_UHCI_ROOT_HUB_H
-#define DRV_UHCI_ROOT_HUB_H
-
-#include <ddf/driver.h>
-
-int setup_root_hub(ddf_fun_t **device, ddf_dev_t *hc);
-
-#endif
-/**
- * @}
- */
Index: uspace/drv/uhci-hcd/transfer_list.c
===================================================================
--- uspace/drv/uhci-hcd/transfer_list.c	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ uspace/drv/uhci-hcd/transfer_list.c	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -47,12 +47,11 @@
  * @return Error code
  *
- * Allocates memory for internat queue_head_t structure.
+ * Allocates memory for internal qh_t structure.
  */
 int transfer_list_init(transfer_list_t *instance, const char *name)
 {
 	assert(instance);
-	instance->next = NULL;
 	instance->name = name;
-	instance->queue_head = malloc32(sizeof(queue_head_t));
+	instance->queue_head = malloc32(sizeof(qh_t));
 	if (!instance->queue_head) {
 		usb_log_error("Failed to allocate queue head.\n");
@@ -61,5 +60,5 @@
 	instance->queue_head_pa = addr_to_phys(instance->queue_head);
 
-	queue_head_init(instance->queue_head);
+	qh_init(instance->queue_head);
 	list_initialize(&instance->batch_list);
 	fibril_mutex_initialize(&instance->guard);
@@ -72,4 +71,6 @@
  * @param[in] next List to append.
  * @return Error code
+ *
+ * Does not check whether there was a next list already.
  */
 void transfer_list_set_next(transfer_list_t *instance, transfer_list_t *next)
@@ -79,6 +80,7 @@
 	if (!instance->queue_head)
 		return;
-	queue_head_append_qh(instance->queue_head, next->queue_head_pa);
-	instance->queue_head->element = instance->queue_head->next_queue;
+	/* set both next and element to point to the same QH */
+	qh_set_next_qh(instance->queue_head, next->queue_head_pa);
+	qh_set_element_qh(instance->queue_head, next->queue_head_pa);
 }
 /*----------------------------------------------------------------------------*/
@@ -93,43 +95,42 @@
 	assert(instance);
 	assert(batch);
-	usb_log_debug2(
-	    "Adding batch(%p) to queue %s.\n", batch, instance->name);
+	usb_log_debug2("Queue %s: Adding batch(%p).\n", instance->name, batch);
 
-	uint32_t pa = (uintptr_t)addr_to_phys(batch->qh);
+	const uint32_t pa = addr_to_phys(batch->qh);
 	assert((pa & LINK_POINTER_ADDRESS_MASK) == pa);
-	pa |= LINK_POINTER_QUEUE_HEAD_FLAG;
 
-	batch->qh->next_queue = instance->queue_head->next_queue;
+	/* New batch will be added to the end of the current list
+	 * so set the link accordingly */
+	qh_set_next_qh(batch->qh, instance->queue_head->next);
 
 	fibril_mutex_lock(&instance->guard);
 
-	if (instance->queue_head->element == instance->queue_head->next_queue) {
-		/* there is nothing scheduled */
-		list_append(&batch->link, &instance->batch_list);
-		instance->queue_head->element = pa;
-		usb_log_debug("Batch(%p) added to queue %s first.\n",
-			batch, instance->name);
-		fibril_mutex_unlock(&instance->guard);
-		return;
+	if (list_empty(&instance->batch_list)) {
+		/* There is nothing scheduled */
+		qh_t *qh = instance->queue_head;
+		assert(qh->element == qh->next);
+		qh_set_element_qh(qh, pa);
+	} else {
+		/* There is something scheduled */
+		batch_t *last = list_get_instance(
+		    instance->batch_list.prev, batch_t, link);
+		qh_set_next_qh(last->qh, pa);
 	}
-	/* now we can be sure that there is someting scheduled */
-	assert(!list_empty(&instance->batch_list));
-	batch_t *first = list_get_instance(
-	          instance->batch_list.next, batch_t, link);
-	batch_t *last = list_get_instance(
-	    instance->batch_list.prev, batch_t, link);
-	queue_head_append_qh(last->qh, pa);
 	list_append(&batch->link, &instance->batch_list);
 
-	usb_log_debug("Batch(%p) added to queue %s last, first is %p.\n",
+	batch_t *first = list_get_instance(
+	    instance->batch_list.next, batch_t, link);
+	usb_log_debug("Batch(%p) added to queue %s, first is %p.\n",
 		batch, instance->name, first);
 	fibril_mutex_unlock(&instance->guard);
 }
 /*----------------------------------------------------------------------------*/
-/** Removes a transfer batch from list and queue.
+/** Removes a transfer batch from the list and queue.
  *
  * @param[in] instance List to use.
  * @param[in] batch Transfer batch to remove.
  * @return Error code
+ *
+ * Does not lock the transfer list, caller is responsible for that.
  */
 void transfer_list_remove_batch(transfer_list_t *instance, batch_t *batch)
@@ -140,24 +141,23 @@
 	assert(batch->qh);
 	usb_log_debug2(
-	    "Removing batch(%p) from queue %s.\n", batch, instance->name);
+	    "Queue %s: removing batch(%p).\n", instance->name, batch);
 
+	const char * pos = NULL;
 	if (batch->link.prev == &instance->batch_list) {
 		/* I'm the first one here */
-		usb_log_debug(
-		    "Batch(%p) removed (FIRST) from %s, next element %x.\n",
-		    batch, instance->name, batch->qh->next_queue);
-		instance->queue_head->element = batch->qh->next_queue;
+		qh_set_element_qh(instance->queue_head, batch->qh->next);
+		pos = "FIRST";
 	} else {
-		usb_log_debug(
-		    "Batch(%p) removed (FIRST:NO) from %s, next element %x.\n",
-		    batch, instance->name, batch->qh->next_queue);
 		batch_t *prev =
 		    list_get_instance(batch->link.prev, batch_t, link);
-		prev->qh->next_queue = batch->qh->next_queue;
+		qh_set_next_qh(prev->qh, batch->qh->next);
+		pos = "NOT FIRST";
 	}
 	list_remove(&batch->link);
+	usb_log_debug("Batch(%p) removed (%s) from %s, next element %x.\n",
+	    batch, pos, instance->name, batch->qh->next);
 }
 /*----------------------------------------------------------------------------*/
-/** Checks list for finished transfers.
+/** Checks list for finished batches.
  *
  * @param[in] instance List to use.
Index: uspace/drv/uhci-hcd/transfer_list.h
===================================================================
--- uspace/drv/uhci-hcd/transfer_list.h	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ uspace/drv/uhci-hcd/transfer_list.h	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -44,7 +44,6 @@
 {
 	fibril_mutex_t guard;
-	queue_head_t *queue_head;
+	qh_t *queue_head;
 	uint32_t queue_head_pa;
-	struct transfer_list *next;
 	const char *name;
 	link_t batch_list;
Index: uspace/drv/uhci-hcd/uhci.c
===================================================================
--- uspace/drv/uhci-hcd/uhci.c	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ uspace/drv/uhci-hcd/uhci.c	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -26,5 +26,6 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-/** @addtogroup usb
+
+/** @addtogroup drvusbuhci
  * @{
  */
@@ -34,47 +35,36 @@
 #include <errno.h>
 #include <str_error.h>
-#include <adt/list.h>
-#include <libarch/ddi.h>
-
+#include <ddf/interrupt.h>
+#include <usb_iface.h>
+#include <usb/ddfiface.h>
 #include <usb/debug.h>
-#include <usb/usb.h>
-#include <usb/ddfiface.h>
-#include <usb_iface.h>
 
 #include "uhci.h"
 #include "iface.h"
-
-static irq_cmd_t uhci_cmds[] = {
-	{
-		.cmd = CMD_PIO_READ_16,
-		.addr = NULL, /* patched for every instance */
-		.dstarg = 1
-	},
-	{
-		.cmd = CMD_PIO_WRITE_16,
-		.addr = NULL, /* pathed for every instance */
-		.value = 0x1f
-	},
-	{
-		.cmd = CMD_ACCEPT
-	}
-};
-
-/** Gets USB address of the calling device.
- *
- * @param[in] fun UHCI hc function.
- * @param[in] handle Handle of the device seeking address.
- * @param[out] address Place to store found address.
- * @return Error code.
- */
+#include "pci.h"
+
+
+/** IRQ handling callback, identifies device
+ *
+ * @param[in] dev DDF instance of the device to use.
+ * @param[in] iid (Unused).
+ * @param[in] call Pointer to the call that represents interrupt.
+ */
+static void irq_handler(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *call)
+{
+	assert(dev);
+	uhci_hc_t *hc = &((uhci_t*)dev->driver_data)->hc;
+	uint16_t status = IPC_GET_ARG1(*call);
+	assert(hc);
+	uhci_hc_interrupt(hc, status);
+}
+/*----------------------------------------------------------------------------*/
 static int usb_iface_get_address(
     ddf_fun_t *fun, devman_handle_t handle, usb_address_t *address)
 {
 	assert(fun);
-	uhci_t *hc = fun_to_uhci(fun);
-	assert(hc);
-
-	usb_address_t addr = device_keeper_find(&hc->device_manager,
-	    handle);
+	device_keeper_t *manager = &((uhci_t*)fun->dev->driver_data)->hc.device_manager;
+
+	usb_address_t addr = device_keeper_find(manager, handle);
 	if (addr < 0) {
 		return addr;
@@ -88,408 +78,144 @@
 }
 /*----------------------------------------------------------------------------*/
-static usb_iface_t hc_usb_iface = {
-	.get_hc_handle = usb_iface_get_hc_handle_hc_impl,
+/** Gets handle of the respective hc (this or parent device).
+ *
+ * @param[in] root_hub_fun Root hub function seeking hc handle.
+ * @param[out] handle Place to write the handle.
+ * @return Error code.
+ */
+static int usb_iface_get_hc_handle(
+    ddf_fun_t *fun, devman_handle_t *handle)
+{
+	assert(handle);
+	ddf_fun_t *hc_fun = ((uhci_t*)fun->dev->driver_data)->hc_fun;
+	assert(hc_fun != NULL);
+
+	*handle = hc_fun->handle;
+	return EOK;
+}
+/*----------------------------------------------------------------------------*/
+/** This iface is generic for both RH and HC. */
+static usb_iface_t usb_iface = {
+	.get_hc_handle = usb_iface_get_hc_handle,
 	.get_address = usb_iface_get_address
 };
 /*----------------------------------------------------------------------------*/
-static ddf_dev_ops_t uhci_ops = {
-	.interfaces[USB_DEV_IFACE] = &hc_usb_iface,
-	.interfaces[USBHC_DEV_IFACE] = &uhci_iface,
-};
-/*----------------------------------------------------------------------------*/
-static int uhci_init_transfer_lists(uhci_t *instance);
-static int uhci_init_mem_structures(uhci_t *instance);
-static void uhci_init_hw(uhci_t *instance);
-
-static int uhci_interrupt_emulator(void *arg);
-static int uhci_debug_checker(void *arg);
-
-static bool allowed_usb_packet(
-    bool low_speed, usb_transfer_type_t transfer, size_t size);
-/*----------------------------------------------------------------------------*/
-/** Initializes UHCI hcd driver structure
- *
- * @param[in] instance Memory place to initialize.
- * @param[in] dev DDF device.
- * @param[in] regs Address of I/O control registers.
- * @param[in] size Size of I/O control registers.
- * @return Error code.
- * @note Should be called only once on any structure.
- */
-int uhci_init(uhci_t *instance, ddf_dev_t *dev, void *regs, size_t reg_size)
-{
-	assert(reg_size >= sizeof(regs_t));
-	int ret;
-
+static ddf_dev_ops_t uhci_hc_ops = {
+	.interfaces[USB_DEV_IFACE] = &usb_iface,
+	.interfaces[USBHC_DEV_IFACE] = &uhci_hc_iface, /* see iface.h/c */
+};
+/*----------------------------------------------------------------------------*/
+/** Gets root hub hw resources.
+ *
+ * @param[in] fun Root hub function.
+ * @return Pointer to the resource list used by the root hub.
+ */
+static hw_resource_list_t *get_resource_list(ddf_fun_t *fun)
+{
+	assert(fun);
+	return &((uhci_rh_t*)fun->driver_data)->resource_list;
+}
+/*----------------------------------------------------------------------------*/
+static hw_res_ops_t hw_res_iface = {
+	.get_resource_list = get_resource_list,
+	.enable_interrupt = NULL
+};
+/*----------------------------------------------------------------------------*/
+static ddf_dev_ops_t uhci_rh_ops = {
+	.interfaces[USB_DEV_IFACE] = &usb_iface,
+	.interfaces[HW_RES_DEV_IFACE] = &hw_res_iface
+};
+/*----------------------------------------------------------------------------*/
+int uhci_init(uhci_t *instance, ddf_dev_t *device)
+{
+	assert(instance);
+	instance->hc_fun = NULL;
+	instance->rh_fun = NULL;
 #define CHECK_RET_DEST_FUN_RETURN(ret, message...) \
-	if (ret != EOK) { \
-		usb_log_error(message); \
-		if (instance->ddf_instance) \
-			ddf_fun_destroy(instance->ddf_instance); \
-		return ret; \
-	} else (void) 0
-
-	/* Create UHCI function. */
-	instance->ddf_instance = ddf_fun_create(dev, fun_exposed, "uhci");
-	ret = (instance->ddf_instance == NULL) ? ENOMEM : EOK;
+if (ret != EOK) { \
+	usb_log_error(message); \
+	if (instance->hc_fun) \
+		ddf_fun_destroy(instance->hc_fun); \
+	if (instance->rh_fun) \
+		ddf_fun_destroy(instance->rh_fun); \
+	return ret; \
+}
+
+	uintptr_t io_reg_base = 0;
+	size_t io_reg_size = 0;
+	int irq = 0;
+
+	int ret =
+	    pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq);
 	CHECK_RET_DEST_FUN_RETURN(ret,
-	    "Failed to create UHCI device function.\n");
-
-	instance->ddf_instance->ops = &uhci_ops;
-	instance->ddf_instance->driver_data = instance;
-
-	ret = ddf_fun_bind(instance->ddf_instance);
+	    "Failed(%d) to get I/O addresses:.\n", ret, device->handle);
+	usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n",
+	    io_reg_base, io_reg_size, irq);
+
+	ret = pci_disable_legacy(device);
+	CHECK_RET_DEST_FUN_RETURN(ret,
+	    "Failed(%d) to disable legacy USB: %s.\n", ret, str_error(ret));
+
+#if 0
+	ret = pci_enable_interrupts(device);
+	if (ret != EOK) {
+		usb_log_warning(
+		    "Failed(%d) to enable interrupts, fall back to polling.\n",
+		    ret);
+	}
+#endif
+
+	instance->hc_fun = ddf_fun_create(device, fun_exposed, "uhci-hc");
+	ret = (instance->hc_fun == NULL) ? ENOMEM : EOK;
+	CHECK_RET_DEST_FUN_RETURN(ret, "Failed(%d) to create HC function.\n", ret);
+
+	ret = uhci_hc_init(
+	    &instance->hc, instance->hc_fun, (void*)io_reg_base, io_reg_size);
+	CHECK_RET_DEST_FUN_RETURN(ret, "Failed(%d) to init uhci-hcd.\n", ret);
+	instance->hc_fun->ops = &uhci_hc_ops;
+	instance->hc_fun->driver_data = &instance->hc;
+	ret = ddf_fun_bind(instance->hc_fun);
 	CHECK_RET_DEST_FUN_RETURN(ret,
 	    "Failed(%d) to bind UHCI device function: %s.\n",
 	    ret, str_error(ret));
-
-	/* allow access to hc control registers */
-	regs_t *io;
-	ret = pio_enable(regs, reg_size, (void**)&io);
-	CHECK_RET_DEST_FUN_RETURN(ret,
-	    "Failed(%d) to gain access to registers at %p: %s.\n",
-	    ret, str_error(ret), io);
-	instance->registers = io;
-	usb_log_debug("Device registers at %p(%u) accessible.\n",
-	    io, reg_size);
-
-	ret = uhci_init_mem_structures(instance);
-	CHECK_RET_DEST_FUN_RETURN(ret,
-	    "Failed to initialize UHCI memory structures.\n");
-
-	uhci_init_hw(instance);
-	instance->cleaner =
-	    fibril_create(uhci_interrupt_emulator, instance);
-	fibril_add_ready(instance->cleaner);
-
-	instance->debug_checker = fibril_create(uhci_debug_checker, instance);
-	fibril_add_ready(instance->debug_checker);
-
-	usb_log_info("Started UHCI driver.\n");
+#undef CHECK_RET_HC_RETURN
+
+#define CHECK_RET_FINI_RETURN(ret, message...) \
+if (ret != EOK) { \
+	usb_log_error(message); \
+	if (instance->hc_fun) \
+		ddf_fun_destroy(instance->hc_fun); \
+	if (instance->rh_fun) \
+		ddf_fun_destroy(instance->rh_fun); \
+	uhci_hc_fini(&instance->hc); \
+	return ret; \
+}
+
+	/* It does no harm if we register this on polling */
+	ret = register_interrupt_handler(device, irq, irq_handler,
+	    &instance->hc.interrupt_code);
+	CHECK_RET_FINI_RETURN(ret,
+	    "Failed(%d) to register interrupt handler.\n", ret);
+
+	instance->rh_fun = ddf_fun_create(device, fun_inner, "uhci-rh");
+	ret = (instance->rh_fun == NULL) ? ENOMEM : EOK;
+	CHECK_RET_FINI_RETURN(ret,
+	    "Failed(%d) to create root hub function.\n", ret);
+
+	ret = uhci_rh_init(&instance->rh, instance->rh_fun,
+	    (uintptr_t)instance->hc.registers + 0x10, 4);
+	CHECK_RET_FINI_RETURN(ret,
+	    "Failed(%d) to setup UHCI root hub.\n", ret);
+
+	instance->rh_fun->ops = &uhci_rh_ops;
+	instance->rh_fun->driver_data = &instance->rh;
+	ret = ddf_fun_bind(instance->rh_fun);
+	CHECK_RET_FINI_RETURN(ret,
+	    "Failed(%d) to register UHCI root hub.\n", ret);
+
 	return EOK;
-#undef CHECK_RET_DEST_FUN_RETURN
-}
-/*----------------------------------------------------------------------------*/
-/** Initializes UHCI hcd hw resources.
- *
- * @param[in] instance UHCI structure to use.
- */
-void uhci_init_hw(uhci_t *instance)
-{
-	assert(instance);
-	regs_t *registers = instance->registers;
-
-	/* Reset everything, who knows what touched it before us */
-	pio_write_16(&registers->usbcmd, UHCI_CMD_GLOBAL_RESET);
-	async_usleep(10000); /* 10ms according to USB spec */
-	pio_write_16(&registers->usbcmd, 0);
-
-	/* Reset hc, all states and counters */
-	pio_write_16(&registers->usbcmd, UHCI_CMD_HCRESET);
-	do { async_usleep(10); }
-	while ((pio_read_16(&registers->usbcmd) & UHCI_CMD_HCRESET) != 0);
-
-	/* Set framelist pointer */
-	const uint32_t pa = addr_to_phys(instance->frame_list);
-	pio_write_32(&registers->flbaseadd, pa);
-
-	/* Enable all interrupts, but resume interrupt */
-//	pio_write_16(&instance->registers->usbintr,
-//	    UHCI_INTR_CRC | UHCI_INTR_COMPLETE | UHCI_INTR_SHORT_PACKET);
-
-	uint16_t status = pio_read_16(&registers->usbcmd);
-	if (status != 0)
-		usb_log_warning("Previous command value: %x.\n", status);
-
-	/* Start the hc with large(64B) packet FSBR */
-	pio_write_16(&registers->usbcmd,
-	    UHCI_CMD_RUN_STOP | UHCI_CMD_MAX_PACKET | UHCI_CMD_CONFIGURE);
-}
-/*----------------------------------------------------------------------------*/
-/** Initializes UHCI hcd memory structures.
- *
- * @param[in] instance UHCI structure to use.
- * @return Error code
- * @note Should be called only once on any structure.
- */
-int uhci_init_mem_structures(uhci_t *instance)
-{
-	assert(instance);
-#define CHECK_RET_DEST_CMDS_RETURN(ret, message...) \
-	if (ret != EOK) { \
-		usb_log_error(message); \
-		if (instance->interrupt_code.cmds != NULL) \
-			free(instance->interrupt_code.cmds); \
-		return ret; \
-	} else (void) 0
-
-	/* Init interrupt code */
-	instance->interrupt_code.cmds = malloc(sizeof(uhci_cmds));
-	int ret = (instance->interrupt_code.cmds == NULL) ? ENOMEM : EOK;
-	CHECK_RET_DEST_CMDS_RETURN(ret,
-	    "Failed to allocate interrupt cmds space.\n");
-
-	{
-		irq_cmd_t *interrupt_commands = instance->interrupt_code.cmds;
-		memcpy(interrupt_commands, uhci_cmds, sizeof(uhci_cmds));
-		interrupt_commands[0].addr =
-		    (void*)&instance->registers->usbsts;
-		interrupt_commands[1].addr =
-		    (void*)&instance->registers->usbsts;
-		instance->interrupt_code.cmdcount =
-		    sizeof(uhci_cmds) / sizeof(irq_cmd_t);
-	}
-
-	/* Init transfer lists */
-	ret = uhci_init_transfer_lists(instance);
-	CHECK_RET_DEST_CMDS_RETURN(ret, "Failed to init transfer lists.\n");
-	usb_log_debug("Initialized transfer lists.\n");
-
-	/* Init USB frame list page*/
-	instance->frame_list = get_page();
-	ret = instance ? EOK : ENOMEM;
-	CHECK_RET_DEST_CMDS_RETURN(ret, "Failed to get frame list page.\n");
-	usb_log_debug("Initialized frame list.\n");
-
-	/* Set all frames to point to the first queue head */
-	const uint32_t queue =
-	  instance->transfers_interrupt.queue_head_pa
-	  | LINK_POINTER_QUEUE_HEAD_FLAG;
-
-	unsigned i = 0;
-	for(; i < UHCI_FRAME_LIST_COUNT; ++i) {
-		instance->frame_list[i] = queue;
-	}
-
-	/* Init device keeper*/
-	device_keeper_init(&instance->device_manager);
-	usb_log_debug("Initialized device manager.\n");
-
-	return EOK;
-#undef CHECK_RET_DEST_CMDS_RETURN
-}
-/*----------------------------------------------------------------------------*/
-/** Initializes UHCI hcd transfer lists.
- *
- * @param[in] instance UHCI structure to use.
- * @return Error code
- * @note Should be called only once on any structure.
- */
-int uhci_init_transfer_lists(uhci_t *instance)
-{
-	assert(instance);
-#define CHECK_RET_CLEAR_RETURN(ret, message...) \
-	if (ret != EOK) { \
-		usb_log_error(message); \
-		transfer_list_fini(&instance->transfers_bulk_full); \
-		transfer_list_fini(&instance->transfers_control_full); \
-		transfer_list_fini(&instance->transfers_control_slow); \
-		transfer_list_fini(&instance->transfers_interrupt); \
-		return ret; \
-	} else (void) 0
-
-	/* initialize TODO: check errors */
-	int ret;
-	ret = transfer_list_init(&instance->transfers_bulk_full, "BULK_FULL");
-	CHECK_RET_CLEAR_RETURN(ret, "Failed to init BULK list.");
-
-	ret = transfer_list_init(
-	    &instance->transfers_control_full, "CONTROL_FULL");
-	CHECK_RET_CLEAR_RETURN(ret, "Failed to init CONTROL FULL list.");
-
-	ret = transfer_list_init(
-	    &instance->transfers_control_slow, "CONTROL_SLOW");
-	CHECK_RET_CLEAR_RETURN(ret, "Failed to init CONTROL SLOW list.");
-
-	ret = transfer_list_init(&instance->transfers_interrupt, "INTERRUPT");
-	CHECK_RET_CLEAR_RETURN(ret, "Failed to init INTERRUPT list.");
-
-	transfer_list_set_next(&instance->transfers_control_full,
-		&instance->transfers_bulk_full);
-	transfer_list_set_next(&instance->transfers_control_slow,
-		&instance->transfers_control_full);
-	transfer_list_set_next(&instance->transfers_interrupt,
-		&instance->transfers_control_slow);
-
-	/*FSBR*/
-#ifdef FSBR
-	transfer_list_set_next(&instance->transfers_bulk_full,
-		&instance->transfers_control_full);
-#endif
-
-	/* Assign pointers to be used during scheduling */
-	instance->transfers[USB_SPEED_FULL][USB_TRANSFER_INTERRUPT] =
-	  &instance->transfers_interrupt;
-	instance->transfers[USB_SPEED_LOW][USB_TRANSFER_INTERRUPT] =
-	  &instance->transfers_interrupt;
-	instance->transfers[USB_SPEED_FULL][USB_TRANSFER_CONTROL] =
-	  &instance->transfers_control_full;
-	instance->transfers[USB_SPEED_LOW][USB_TRANSFER_CONTROL] =
-	  &instance->transfers_control_slow;
-	instance->transfers[USB_SPEED_FULL][USB_TRANSFER_BULK] =
-	  &instance->transfers_bulk_full;
-
-	return EOK;
-#undef CHECK_RET_CLEAR_RETURN
-}
-/*----------------------------------------------------------------------------*/
-/** Schedules batch for execution.
- *
- * @param[in] instance UHCI structure to use.
- * @param[in] batch Transfer batch to schedule.
- * @return Error code
- */
-int uhci_schedule(uhci_t *instance, batch_t *batch)
-{
-	assert(instance);
-	assert(batch);
-	const int low_speed = (batch->speed == USB_SPEED_LOW);
-	if (!allowed_usb_packet(
-	    low_speed, batch->transfer_type, batch->max_packet_size)) {
-		usb_log_warning(
-		    "Invalid USB packet specified %s SPEED %d %zu.\n",
-		    low_speed ? "LOW" : "FULL" , batch->transfer_type,
-		    batch->max_packet_size);
-		return ENOTSUP;
-	}
-	/* TODO: check available bandwith here */
-
-	transfer_list_t *list =
-	    instance->transfers[low_speed][batch->transfer_type];
-	assert(list);
-	transfer_list_add_batch(list, batch);
-
-	return EOK;
-}
-/*----------------------------------------------------------------------------*/
-/** Takes action based on the interrupt cause.
- *
- * @param[in] instance UHCI structure to use.
- * @param[in] status Value of the stsatus regiser at the time of interrupt.
- */
-void uhci_interrupt(uhci_t *instance, uint16_t status)
-{
-	assert(instance);
-	/* TODO: Check interrupt cause here */
-	transfer_list_remove_finished(&instance->transfers_interrupt);
-	transfer_list_remove_finished(&instance->transfers_control_slow);
-	transfer_list_remove_finished(&instance->transfers_control_full);
-	transfer_list_remove_finished(&instance->transfers_bulk_full);
-}
-/*----------------------------------------------------------------------------*/
-/** Polling function, emulates interrupts.
- *
- * @param[in] arg UHCI structure to use.
- * @return EOK
- */
-int uhci_interrupt_emulator(void* arg)
-{
-	usb_log_debug("Started interrupt emulator.\n");
-	uhci_t *instance = (uhci_t*)arg;
-	assert(instance);
-
-	while (1) {
-		uint16_t status = pio_read_16(&instance->registers->usbsts);
-		if (status != 0)
-			usb_log_debug2("UHCI status: %x.\n", status);
-		status |= 1;
-		uhci_interrupt(instance, status);
-		pio_write_16(&instance->registers->usbsts, 0x1f);
-		async_usleep(UHCI_CLEANER_TIMEOUT);
-	}
-	return EOK;
-}
-/*---------------------------------------------------------------------------*/
-/** Debug function, checks consistency of memory structures.
- *
- * @param[in] arg UHCI structure to use.
- * @return EOK
- */
-int uhci_debug_checker(void *arg)
-{
-	uhci_t *instance = (uhci_t*)arg;
-	assert(instance);
-
-#define QH(queue) \
-	instance->transfers_##queue.queue_head
-
-	while (1) {
-		const uint16_t cmd = pio_read_16(&instance->registers->usbcmd);
-		const uint16_t sts = pio_read_16(&instance->registers->usbsts);
-		const uint16_t intr =
-		    pio_read_16(&instance->registers->usbintr);
-
-		if (((cmd & UHCI_CMD_RUN_STOP) != 1) || (sts != 0)) {
-			usb_log_debug2("Command: %X Status: %X Intr: %x\n",
-			    cmd, sts, intr);
-		}
-
-		uintptr_t frame_list =
-		    pio_read_32(&instance->registers->flbaseadd) & ~0xfff;
-		if (frame_list != addr_to_phys(instance->frame_list)) {
-			usb_log_debug("Framelist address: %p vs. %p.\n",
-			    frame_list, addr_to_phys(instance->frame_list));
-		}
-
-		int frnum = pio_read_16(&instance->registers->frnum) & 0x3ff;
-		usb_log_debug2("Framelist item: %d \n", frnum );
-
-		uintptr_t expected_pa = instance->frame_list[frnum] & (~0xf);
-		uintptr_t real_pa = addr_to_phys(QH(interrupt));
-		if (expected_pa != real_pa) {
-			usb_log_debug("Interrupt QH: %p vs. %p.\n",
-			    expected_pa, real_pa);
-		}
-
-		expected_pa = QH(interrupt)->next_queue & (~0xf);
-		real_pa = addr_to_phys(QH(control_slow));
-		if (expected_pa != real_pa) {
-			usb_log_debug("Control Slow QH: %p vs. %p.\n",
-			    expected_pa, real_pa);
-		}
-
-		expected_pa = QH(control_slow)->next_queue & (~0xf);
-		real_pa = addr_to_phys(QH(control_full));
-		if (expected_pa != real_pa) {
-			usb_log_debug("Control Full QH: %p vs. %p.\n",
-			    expected_pa, real_pa);
-		}
-
-		expected_pa = QH(control_full)->next_queue & (~0xf);
-		real_pa = addr_to_phys(QH(bulk_full));
-		if (expected_pa != real_pa ) {
-			usb_log_debug("Bulk QH: %p vs. %p.\n",
-			    expected_pa, real_pa);
-		}
-		async_usleep(UHCI_DEBUGER_TIMEOUT);
-	}
-	return EOK;
-#undef QH
-}
-/*----------------------------------------------------------------------------*/
-/** Checks transfer packets, for USB validity
- *
- * @param[in] low_speed Transfer speed.
- * @param[in] transfer Transer type
- * @param[in] size Maximum size of used packets
- * @return EOK
- */
-bool allowed_usb_packet(
-    bool low_speed, usb_transfer_type_t transfer, size_t size)
-{
-	/* see USB specification chapter 5.5-5.8 for magic numbers used here */
-	switch(transfer)
-	{
-	case USB_TRANSFER_ISOCHRONOUS:
-		return (!low_speed && size < 1024);
-	case USB_TRANSFER_INTERRUPT:
-		return size <= (low_speed ? 8 : 64);
-	case USB_TRANSFER_CONTROL: /* device specifies its own max size */
-		return (size <= (low_speed ? 8 : 64));
-	case USB_TRANSFER_BULK: /* device specifies its own max size */
-		return (!low_speed && size <= 64);
-	}
-	return false;
-}
+#undef CHECK_RET_FINI_RETURN
+}
+
 /**
  * @}
Index: uspace/drv/uhci-hcd/uhci.h
===================================================================
--- uspace/drv/uhci-hcd/uhci.h	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ uspace/drv/uhci-hcd/uhci.h	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2010 Jan Vesely
+ * Copyright (c) 2011 Jan Vesely
  * All rights reserved.
  *
@@ -35,87 +35,19 @@
 #ifndef DRV_UHCI_UHCI_H
 #define DRV_UHCI_UHCI_H
+#include <ddi.h>
+#include <ddf/driver.h>
 
-#include <fibril.h>
-#include <fibril_synch.h>
-#include <adt/list.h>
-#include <ddi.h>
-
-#include <usbhc_iface.h>
-
-#include "batch.h"
-#include "transfer_list.h"
-#include "utils/device_keeper.h"
-
-typedef struct uhci_regs {
-	uint16_t usbcmd;
-#define UHCI_CMD_MAX_PACKET (1 << 7)
-#define UHCI_CMD_CONFIGURE  (1 << 6)
-#define UHCI_CMD_DEBUG  (1 << 5)
-#define UHCI_CMD_FORCE_GLOBAL_RESUME  (1 << 4)
-#define UHCI_CMD_FORCE_GLOBAL_SUSPEND  (1 << 3)
-#define UHCI_CMD_GLOBAL_RESET  (1 << 2)
-#define UHCI_CMD_HCRESET  (1 << 1)
-#define UHCI_CMD_RUN_STOP  (1 << 0)
-
-	uint16_t usbsts;
-#define UHCI_STATUS_HALTED (1 << 5)
-#define UHCI_STATUS_PROCESS_ERROR (1 << 4)
-#define UHCI_STATUS_SYSTEM_ERROR (1 << 3)
-#define UHCI_STATUS_RESUME (1 << 2)
-#define UHCI_STATUS_ERROR_INTERRUPT (1 << 1)
-#define UHCI_STATUS_INTERRUPT (1 << 0)
-
-	uint16_t usbintr;
-#define UHCI_INTR_SHORT_PACKET (1 << 3)
-#define UHCI_INTR_COMPLETE (1 << 2)
-#define UHCI_INTR_RESUME (1 << 1)
-#define UHCI_INTR_CRC (1 << 0)
-
-	uint16_t frnum;
-	uint32_t flbaseadd;
-	uint8_t sofmod;
-} regs_t;
-
-#define UHCI_FRAME_LIST_COUNT 1024
-#define UHCI_CLEANER_TIMEOUT 10000
-#define UHCI_DEBUGER_TIMEOUT 5000000
+#include "uhci_hc.h"
+#include "uhci_rh.h"
 
 typedef struct uhci {
-	device_keeper_t device_manager;
+	ddf_fun_t *hc_fun;
+	ddf_fun_t *rh_fun;
 
-	regs_t *registers;
-
-	link_pointer_t *frame_list;
-
-	transfer_list_t transfers_bulk_full;
-	transfer_list_t transfers_control_full;
-	transfer_list_t transfers_control_slow;
-	transfer_list_t transfers_interrupt;
-
-	transfer_list_t *transfers[2][4];
-
-	irq_code_t interrupt_code;
-
-	fid_t cleaner;
-	fid_t debug_checker;
-
-	ddf_fun_t *ddf_instance;
+	uhci_hc_t hc;
+	uhci_rh_t rh;
 } uhci_t;
 
-/* init uhci specifics in device.driver_data */
-int uhci_init(uhci_t *instance, ddf_dev_t *dev, void *regs, size_t reg_size);
-
-static inline void uhci_fini(uhci_t *instance) {};
-
-int uhci_schedule(uhci_t *instance, batch_t *batch);
-
-void uhci_interrupt(uhci_t *instance, uint16_t status);
-
-static inline uhci_t * dev_to_uhci(ddf_dev_t *dev)
-	{ return (uhci_t*)dev->driver_data; }
-
-static inline uhci_t * fun_to_uhci(ddf_fun_t *fun)
-	{ return (uhci_t*)fun->driver_data; }
-
+int uhci_init(uhci_t *instance, ddf_dev_t *device);
 
 #endif
Index: uspace/drv/uhci-hcd/uhci_hc.c
===================================================================
--- uspace/drv/uhci-hcd/uhci_hc.c	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
+++ uspace/drv/uhci-hcd/uhci_hc.c	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -0,0 +1,458 @@
+/*
+ * Copyright (c) 2011 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/** @addtogroup usb
+ * @{
+ */
+/** @file
+ * @brief UHCI driver
+ */
+#include <errno.h>
+#include <str_error.h>
+#include <adt/list.h>
+#include <libarch/ddi.h>
+
+#include <usb/debug.h>
+#include <usb/usb.h>
+#include <usb/ddfiface.h>
+#include <usb_iface.h>
+
+#include "uhci_hc.h"
+
+static irq_cmd_t uhci_cmds[] = {
+	{
+		.cmd = CMD_PIO_READ_16,
+		.addr = NULL, /* patched for every instance */
+		.dstarg = 1
+	},
+	{
+		.cmd = CMD_PIO_WRITE_16,
+		.addr = NULL, /* pathed for every instance */
+		.value = 0x1f
+	},
+	{
+		.cmd = CMD_ACCEPT
+	}
+};
+
+/** Gets USB address of the calling device.
+ *
+ * @param[in] fun UHCI hc function.
+ * @param[in] handle Handle of the device seeking address.
+ * @param[out] address Place to store found address.
+ * @return Error code.
+ */
+/*----------------------------------------------------------------------------*/
+static int uhci_hc_init_transfer_lists(uhci_hc_t *instance);
+static int uhci_hc_init_mem_structures(uhci_hc_t *instance);
+static void uhci_hc_init_hw(uhci_hc_t *instance);
+
+static int uhci_hc_interrupt_emulator(void *arg);
+static int uhci_hc_debug_checker(void *arg);
+
+static bool allowed_usb_packet(
+    bool low_speed, usb_transfer_type_t transfer, size_t size);
+/*----------------------------------------------------------------------------*/
+/** Initializes UHCI hcd driver structure
+ *
+ * @param[in] instance Memory place to initialize.
+ * @param[in] fun DDF function.
+ * @param[in] regs Address of I/O control registers.
+ * @param[in] size Size of I/O control registers.
+ * @return Error code.
+ * @note Should be called only once on any structure.
+ */
+int uhci_hc_init(uhci_hc_t *instance, ddf_fun_t *fun, void *regs, size_t reg_size)
+{
+	assert(reg_size >= sizeof(regs_t));
+	int ret;
+
+#define CHECK_RET_DEST_FUN_RETURN(ret, message...) \
+	if (ret != EOK) { \
+		usb_log_error(message); \
+		if (instance->ddf_instance) \
+			ddf_fun_destroy(instance->ddf_instance); \
+		return ret; \
+	} else (void) 0
+
+	/* Setup UHCI function. */
+	instance->ddf_instance = fun;
+
+	/* allow access to hc control registers */
+	regs_t *io;
+	ret = pio_enable(regs, reg_size, (void**)&io);
+	CHECK_RET_DEST_FUN_RETURN(ret,
+	    "Failed(%d) to gain access to registers at %p: %s.\n",
+	    ret, str_error(ret), io);
+	instance->registers = io;
+	usb_log_debug("Device registers at %p(%u) accessible.\n",
+	    io, reg_size);
+
+	ret = uhci_hc_init_mem_structures(instance);
+	CHECK_RET_DEST_FUN_RETURN(ret,
+	    "Failed to initialize UHCI memory structures.\n");
+
+	uhci_hc_init_hw(instance);
+	instance->cleaner =
+	    fibril_create(uhci_hc_interrupt_emulator, instance);
+	fibril_add_ready(instance->cleaner);
+
+	instance->debug_checker = fibril_create(uhci_hc_debug_checker, instance);
+	fibril_add_ready(instance->debug_checker);
+
+	usb_log_info("Started UHCI driver.\n");
+	return EOK;
+#undef CHECK_RET_DEST_FUN_RETURN
+}
+/*----------------------------------------------------------------------------*/
+/** Initializes UHCI hcd hw resources.
+ *
+ * @param[in] instance UHCI structure to use.
+ */
+void uhci_hc_init_hw(uhci_hc_t *instance)
+{
+	assert(instance);
+	regs_t *registers = instance->registers;
+
+	/* Reset everything, who knows what touched it before us */
+	pio_write_16(&registers->usbcmd, UHCI_CMD_GLOBAL_RESET);
+	async_usleep(10000); /* 10ms according to USB spec */
+	pio_write_16(&registers->usbcmd, 0);
+
+	/* Reset hc, all states and counters */
+	pio_write_16(&registers->usbcmd, UHCI_CMD_HCRESET);
+	do { async_usleep(10); }
+	while ((pio_read_16(&registers->usbcmd) & UHCI_CMD_HCRESET) != 0);
+
+	/* Set framelist pointer */
+	const uint32_t pa = addr_to_phys(instance->frame_list);
+	pio_write_32(&registers->flbaseadd, pa);
+
+	/* Enable all interrupts, but resume interrupt */
+//	pio_write_16(&instance->registers->usbintr,
+//	    UHCI_INTR_CRC | UHCI_INTR_COMPLETE | UHCI_INTR_SHORT_PACKET);
+
+	uint16_t status = pio_read_16(&registers->usbcmd);
+	if (status != 0)
+		usb_log_warning("Previous command value: %x.\n", status);
+
+	/* Start the hc with large(64B) packet FSBR */
+	pio_write_16(&registers->usbcmd,
+	    UHCI_CMD_RUN_STOP | UHCI_CMD_MAX_PACKET | UHCI_CMD_CONFIGURE);
+}
+/*----------------------------------------------------------------------------*/
+/** Initializes UHCI hcd memory structures.
+ *
+ * @param[in] instance UHCI structure to use.
+ * @return Error code
+ * @note Should be called only once on any structure.
+ */
+int uhci_hc_init_mem_structures(uhci_hc_t *instance)
+{
+	assert(instance);
+#define CHECK_RET_DEST_CMDS_RETURN(ret, message...) \
+	if (ret != EOK) { \
+		usb_log_error(message); \
+		if (instance->interrupt_code.cmds != NULL) \
+			free(instance->interrupt_code.cmds); \
+		return ret; \
+	} else (void) 0
+
+	/* Init interrupt code */
+	instance->interrupt_code.cmds = malloc(sizeof(uhci_cmds));
+	int ret = (instance->interrupt_code.cmds == NULL) ? ENOMEM : EOK;
+	CHECK_RET_DEST_CMDS_RETURN(ret,
+	    "Failed to allocate interrupt cmds space.\n");
+
+	{
+		irq_cmd_t *interrupt_commands = instance->interrupt_code.cmds;
+		memcpy(interrupt_commands, uhci_cmds, sizeof(uhci_cmds));
+		interrupt_commands[0].addr =
+		    (void*)&instance->registers->usbsts;
+		interrupt_commands[1].addr =
+		    (void*)&instance->registers->usbsts;
+		instance->interrupt_code.cmdcount =
+		    sizeof(uhci_cmds) / sizeof(irq_cmd_t);
+	}
+
+	/* Init transfer lists */
+	ret = uhci_hc_init_transfer_lists(instance);
+	CHECK_RET_DEST_CMDS_RETURN(ret, "Failed to init transfer lists.\n");
+	usb_log_debug("Initialized transfer lists.\n");
+
+	/* Init USB frame list page*/
+	instance->frame_list = get_page();
+	ret = instance ? EOK : ENOMEM;
+	CHECK_RET_DEST_CMDS_RETURN(ret, "Failed to get frame list page.\n");
+	usb_log_debug("Initialized frame list.\n");
+
+	/* Set all frames to point to the first queue head */
+	const uint32_t queue =
+	  instance->transfers_interrupt.queue_head_pa
+	  | LINK_POINTER_QUEUE_HEAD_FLAG;
+
+	unsigned i = 0;
+	for(; i < UHCI_FRAME_LIST_COUNT; ++i) {
+		instance->frame_list[i] = queue;
+	}
+
+	/* Init device keeper*/
+	device_keeper_init(&instance->device_manager);
+	usb_log_debug("Initialized device manager.\n");
+
+	return EOK;
+#undef CHECK_RET_DEST_CMDS_RETURN
+}
+/*----------------------------------------------------------------------------*/
+/** Initializes UHCI hcd transfer lists.
+ *
+ * @param[in] instance UHCI structure to use.
+ * @return Error code
+ * @note Should be called only once on any structure.
+ */
+int uhci_hc_init_transfer_lists(uhci_hc_t *instance)
+{
+	assert(instance);
+#define CHECK_RET_CLEAR_RETURN(ret, message...) \
+	if (ret != EOK) { \
+		usb_log_error(message); \
+		transfer_list_fini(&instance->transfers_bulk_full); \
+		transfer_list_fini(&instance->transfers_control_full); \
+		transfer_list_fini(&instance->transfers_control_slow); \
+		transfer_list_fini(&instance->transfers_interrupt); \
+		return ret; \
+	} else (void) 0
+
+	/* initialize TODO: check errors */
+	int ret;
+	ret = transfer_list_init(&instance->transfers_bulk_full, "BULK_FULL");
+	CHECK_RET_CLEAR_RETURN(ret, "Failed to init BULK list.");
+
+	ret = transfer_list_init(
+	    &instance->transfers_control_full, "CONTROL_FULL");
+	CHECK_RET_CLEAR_RETURN(ret, "Failed to init CONTROL FULL list.");
+
+	ret = transfer_list_init(
+	    &instance->transfers_control_slow, "CONTROL_SLOW");
+	CHECK_RET_CLEAR_RETURN(ret, "Failed to init CONTROL SLOW list.");
+
+	ret = transfer_list_init(&instance->transfers_interrupt, "INTERRUPT");
+	CHECK_RET_CLEAR_RETURN(ret, "Failed to init INTERRUPT list.");
+
+	transfer_list_set_next(&instance->transfers_control_full,
+		&instance->transfers_bulk_full);
+	transfer_list_set_next(&instance->transfers_control_slow,
+		&instance->transfers_control_full);
+	transfer_list_set_next(&instance->transfers_interrupt,
+		&instance->transfers_control_slow);
+
+	/*FSBR*/
+#ifdef FSBR
+	transfer_list_set_next(&instance->transfers_bulk_full,
+		&instance->transfers_control_full);
+#endif
+
+	/* Assign pointers to be used during scheduling */
+	instance->transfers[USB_SPEED_FULL][USB_TRANSFER_INTERRUPT] =
+	  &instance->transfers_interrupt;
+	instance->transfers[USB_SPEED_LOW][USB_TRANSFER_INTERRUPT] =
+	  &instance->transfers_interrupt;
+	instance->transfers[USB_SPEED_FULL][USB_TRANSFER_CONTROL] =
+	  &instance->transfers_control_full;
+	instance->transfers[USB_SPEED_LOW][USB_TRANSFER_CONTROL] =
+	  &instance->transfers_control_slow;
+	instance->transfers[USB_SPEED_FULL][USB_TRANSFER_BULK] =
+	  &instance->transfers_bulk_full;
+
+	return EOK;
+#undef CHECK_RET_CLEAR_RETURN
+}
+/*----------------------------------------------------------------------------*/
+/** Schedules batch for execution.
+ *
+ * @param[in] instance UHCI structure to use.
+ * @param[in] batch Transfer batch to schedule.
+ * @return Error code
+ */
+int uhci_hc_schedule(uhci_hc_t *instance, batch_t *batch)
+{
+	assert(instance);
+	assert(batch);
+	const int low_speed = (batch->speed == USB_SPEED_LOW);
+	if (!allowed_usb_packet(
+	    low_speed, batch->transfer_type, batch->max_packet_size)) {
+		usb_log_warning(
+		    "Invalid USB packet specified %s SPEED %d %zu.\n",
+		    low_speed ? "LOW" : "FULL" , batch->transfer_type,
+		    batch->max_packet_size);
+		return ENOTSUP;
+	}
+	/* TODO: check available bandwith here */
+
+	transfer_list_t *list =
+	    instance->transfers[batch->speed][batch->transfer_type];
+	assert(list);
+	transfer_list_add_batch(list, batch);
+
+	return EOK;
+}
+/*----------------------------------------------------------------------------*/
+/** Takes action based on the interrupt cause.
+ *
+ * @param[in] instance UHCI structure to use.
+ * @param[in] status Value of the stsatus regiser at the time of interrupt.
+ */
+void uhci_hc_interrupt(uhci_hc_t *instance, uint16_t status)
+{
+	assert(instance);
+	/* TODO: Check interrupt cause here */
+	/* Lower 2 bits are transaction error and transaction complete */
+	if (status & 0x3) {
+		transfer_list_remove_finished(&instance->transfers_interrupt);
+		transfer_list_remove_finished(&instance->transfers_control_slow);
+		transfer_list_remove_finished(&instance->transfers_control_full);
+		transfer_list_remove_finished(&instance->transfers_bulk_full);
+	}
+}
+/*----------------------------------------------------------------------------*/
+/** Polling function, emulates interrupts.
+ *
+ * @param[in] arg UHCI structure to use.
+ * @return EOK
+ */
+int uhci_hc_interrupt_emulator(void* arg)
+{
+	usb_log_debug("Started interrupt emulator.\n");
+	uhci_hc_t *instance = (uhci_hc_t*)arg;
+	assert(instance);
+
+	while (1) {
+		/* read and ack interrupts */
+		uint16_t status = pio_read_16(&instance->registers->usbsts);
+		pio_write_16(&instance->registers->usbsts, 0x1f);
+		if (status != 0)
+			usb_log_debug2("UHCI status: %x.\n", status);
+		uhci_hc_interrupt(instance, status);
+		async_usleep(UHCI_CLEANER_TIMEOUT);
+	}
+	return EOK;
+}
+/*---------------------------------------------------------------------------*/
+/** Debug function, checks consistency of memory structures.
+ *
+ * @param[in] arg UHCI structure to use.
+ * @return EOK
+ */
+int uhci_hc_debug_checker(void *arg)
+{
+	uhci_hc_t *instance = (uhci_hc_t*)arg;
+	assert(instance);
+
+#define QH(queue) \
+	instance->transfers_##queue.queue_head
+
+	while (1) {
+		const uint16_t cmd = pio_read_16(&instance->registers->usbcmd);
+		const uint16_t sts = pio_read_16(&instance->registers->usbsts);
+		const uint16_t intr =
+		    pio_read_16(&instance->registers->usbintr);
+
+		if (((cmd & UHCI_CMD_RUN_STOP) != 1) || (sts != 0)) {
+			usb_log_debug2("Command: %X Status: %X Intr: %x\n",
+			    cmd, sts, intr);
+		}
+
+		uintptr_t frame_list =
+		    pio_read_32(&instance->registers->flbaseadd) & ~0xfff;
+		if (frame_list != addr_to_phys(instance->frame_list)) {
+			usb_log_debug("Framelist address: %p vs. %p.\n",
+			    frame_list, addr_to_phys(instance->frame_list));
+		}
+
+		int frnum = pio_read_16(&instance->registers->frnum) & 0x3ff;
+
+		uintptr_t expected_pa = instance->frame_list[frnum]
+		    & LINK_POINTER_ADDRESS_MASK;
+		uintptr_t real_pa = addr_to_phys(QH(interrupt));
+		if (expected_pa != real_pa) {
+			usb_log_debug("Interrupt QH: %p(frame: %d) vs. %p.\n",
+			    expected_pa, frnum, real_pa);
+		}
+
+		expected_pa = QH(interrupt)->next & LINK_POINTER_ADDRESS_MASK;
+		real_pa = addr_to_phys(QH(control_slow));
+		if (expected_pa != real_pa) {
+			usb_log_debug("Control Slow QH: %p vs. %p.\n",
+			    expected_pa, real_pa);
+		}
+
+		expected_pa = QH(control_slow)->next & LINK_POINTER_ADDRESS_MASK;
+		real_pa = addr_to_phys(QH(control_full));
+		if (expected_pa != real_pa) {
+			usb_log_debug("Control Full QH: %p vs. %p.\n",
+			    expected_pa, real_pa);
+		}
+
+		expected_pa = QH(control_full)->next & LINK_POINTER_ADDRESS_MASK;
+		real_pa = addr_to_phys(QH(bulk_full));
+		if (expected_pa != real_pa ) {
+			usb_log_debug("Bulk QH: %p vs. %p.\n",
+			    expected_pa, real_pa);
+		}
+		async_usleep(UHCI_DEBUGER_TIMEOUT);
+	}
+	return EOK;
+#undef QH
+}
+/*----------------------------------------------------------------------------*/
+/** Checks transfer packets, for USB validity
+ *
+ * @param[in] low_speed Transfer speed.
+ * @param[in] transfer Transer type
+ * @param[in] size Maximum size of used packets
+ * @return EOK
+ */
+bool allowed_usb_packet(
+    bool low_speed, usb_transfer_type_t transfer, size_t size)
+{
+	/* see USB specification chapter 5.5-5.8 for magic numbers used here */
+	switch(transfer)
+	{
+	case USB_TRANSFER_ISOCHRONOUS:
+		return (!low_speed && size < 1024);
+	case USB_TRANSFER_INTERRUPT:
+		return size <= (low_speed ? 8 : 64);
+	case USB_TRANSFER_CONTROL: /* device specifies its own max size */
+		return (size <= (low_speed ? 8 : 64));
+	case USB_TRANSFER_BULK: /* device specifies its own max size */
+		return (!low_speed && size <= 64);
+	}
+	return false;
+}
+/**
+ * @}
+ */
Index: uspace/drv/uhci-hcd/uhci_hc.h
===================================================================
--- uspace/drv/uhci-hcd/uhci_hc.h	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
+++ uspace/drv/uhci-hcd/uhci_hc.h	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2011 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup drvusbuhci
+ * @{
+ */
+/** @file
+ * @brief UHCI driver
+ */
+#ifndef DRV_UHCI_UHCI_HC_H
+#define DRV_UHCI_UHCI_HC_H
+
+#include <fibril.h>
+#include <fibril_synch.h>
+#include <adt/list.h>
+#include <ddi.h>
+
+#include <usbhc_iface.h>
+
+#include "batch.h"
+#include "transfer_list.h"
+#include "utils/device_keeper.h"
+
+typedef struct uhci_regs {
+	uint16_t usbcmd;
+#define UHCI_CMD_MAX_PACKET (1 << 7)
+#define UHCI_CMD_CONFIGURE  (1 << 6)
+#define UHCI_CMD_DEBUG  (1 << 5)
+#define UHCI_CMD_FORCE_GLOBAL_RESUME  (1 << 4)
+#define UHCI_CMD_FORCE_GLOBAL_SUSPEND  (1 << 3)
+#define UHCI_CMD_GLOBAL_RESET  (1 << 2)
+#define UHCI_CMD_HCRESET  (1 << 1)
+#define UHCI_CMD_RUN_STOP  (1 << 0)
+
+	uint16_t usbsts;
+#define UHCI_STATUS_HALTED (1 << 5)
+#define UHCI_STATUS_PROCESS_ERROR (1 << 4)
+#define UHCI_STATUS_SYSTEM_ERROR (1 << 3)
+#define UHCI_STATUS_RESUME (1 << 2)
+#define UHCI_STATUS_ERROR_INTERRUPT (1 << 1)
+#define UHCI_STATUS_INTERRUPT (1 << 0)
+
+	uint16_t usbintr;
+#define UHCI_INTR_SHORT_PACKET (1 << 3)
+#define UHCI_INTR_COMPLETE (1 << 2)
+#define UHCI_INTR_RESUME (1 << 1)
+#define UHCI_INTR_CRC (1 << 0)
+
+	uint16_t frnum;
+	uint32_t flbaseadd;
+	uint8_t sofmod;
+} regs_t;
+
+#define UHCI_FRAME_LIST_COUNT 1024
+#define UHCI_CLEANER_TIMEOUT 10000
+#define UHCI_DEBUGER_TIMEOUT 5000000
+
+typedef struct uhci_hc {
+	device_keeper_t device_manager;
+
+	regs_t *registers;
+
+	link_pointer_t *frame_list;
+
+	transfer_list_t transfers_bulk_full;
+	transfer_list_t transfers_control_full;
+	transfer_list_t transfers_control_slow;
+	transfer_list_t transfers_interrupt;
+
+	transfer_list_t *transfers[2][4];
+
+	irq_code_t interrupt_code;
+
+	fid_t cleaner;
+	fid_t debug_checker;
+
+	ddf_fun_t *ddf_instance;
+} uhci_hc_t;
+
+/* init uhci specifics in device.driver_data */
+int uhci_hc_init(uhci_hc_t *instance, ddf_fun_t *fun, void *regs, size_t reg_size);
+
+static inline void uhci_hc_fini(uhci_hc_t *instance) { /* TODO: implement*/ };
+
+int uhci_hc_schedule(uhci_hc_t *instance, batch_t *batch);
+
+void uhci_hc_interrupt(uhci_hc_t *instance, uint16_t status);
+
+static inline uhci_hc_t * fun_to_uhci_hc(ddf_fun_t *fun)
+	{ return (uhci_hc_t*)fun->driver_data; }
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/uhci-hcd/uhci_rh.c
===================================================================
--- uspace/drv/uhci-hcd/uhci_rh.c	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
+++ uspace/drv/uhci-hcd/uhci_rh.c	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2011 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/** @addtogroup usb
+ * @{
+ */
+/** @file
+ * @brief UHCI driver
+ */
+#include <assert.h>
+#include <errno.h>
+#include <str_error.h>
+#include <stdio.h>
+
+#include <usb/debug.h>
+
+#include "uhci_rh.h"
+#include "uhci_hc.h"
+
+/*----------------------------------------------------------------------------*/
+int uhci_rh_init(
+    uhci_rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size)
+{
+	assert(fun);
+
+	char *match_str = NULL;
+	int ret = asprintf(&match_str, "usb&uhci&root-hub");
+	if (ret < 0) {
+		usb_log_error("Failed to create root hub match string.\n");
+		return ENOMEM;
+	}
+
+	ret = ddf_fun_add_match_id(fun, match_str, 100);
+	if (ret != EOK) {
+		usb_log_error("Failed(%d) to add root hub match id: %s\n",
+		    ret, str_error(ret));
+		return ret;
+	}
+
+	hw_resource_list_t *resource_list = &instance->resource_list;
+	resource_list->count = 1;
+	resource_list->resources = &instance->io_regs;
+	assert(resource_list->resources);
+	instance->io_regs.type = IO_RANGE;
+	instance->io_regs.res.io_range.address = reg_addr;
+//	    ((uintptr_t)hc->registers) + 0x10; // see UHCI design guide
+	instance->io_regs.res.io_range.size = reg_size;
+	instance->io_regs.res.io_range.endianness = LITTLE_ENDIAN;
+
+	return EOK;
+}
+/**
+ * @}
+ */
Index: uspace/drv/uhci-hcd/uhci_rh.h
===================================================================
--- uspace/drv/uhci-hcd/uhci_rh.h	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
+++ uspace/drv/uhci-hcd/uhci_rh.h	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2011 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup drvusbuhci
+ * @{
+ */
+/** @file
+ * @brief UHCI driver
+ */
+#ifndef DRV_UHCI_UHCI_RH_H
+#define DRV_UHCI_UHCI_RH_H
+
+#include <ddf/driver.h>
+#include <ops/hw_res.h>
+
+typedef struct uhci_rh {
+	hw_resource_list_t resource_list;
+	hw_resource_t io_regs;
+} uhci_rh_t;
+
+int uhci_rh_init(
+    uhci_rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size);
+
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/uhci-hcd/uhci_struct/link_pointer.h
===================================================================
--- uspace/drv/uhci-hcd/uhci_struct/link_pointer.h	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ uspace/drv/uhci-hcd/uhci_struct/link_pointer.h	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -46,4 +46,7 @@
 #define LINK_POINTER_ADDRESS_MASK 0xfffffff0 /* upper 28 bits */
 
+#define LINK_POINTER_QH(address) \
+	((address & LINK_POINTER_ADDRESS_MASK) | LINK_POINTER_QUEUE_HEAD_FLAG)
+
 #endif
 /**
Index: uspace/drv/uhci-hcd/uhci_struct/queue_head.h
===================================================================
--- uspace/drv/uhci-hcd/uhci_struct/queue_head.h	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ uspace/drv/uhci-hcd/uhci_struct/queue_head.h	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -43,36 +43,44 @@
 
 typedef struct queue_head {
-	volatile link_pointer_t next_queue;
+	volatile link_pointer_t next;
 	volatile link_pointer_t element;
-} __attribute__((packed)) queue_head_t;
-
-static inline void queue_head_init(queue_head_t *instance)
+} __attribute__((packed)) qh_t;
+/*----------------------------------------------------------------------------*/
+static inline void qh_init(qh_t *instance)
 {
 	assert(instance);
 
 	instance->element = 0 | LINK_POINTER_TERMINATE_FLAG;
-	instance->next_queue = 0 | LINK_POINTER_TERMINATE_FLAG;
+	instance->next = 0 | LINK_POINTER_TERMINATE_FLAG;
 }
-
-static inline void queue_head_append_qh(queue_head_t *instance, uint32_t pa)
+/*----------------------------------------------------------------------------*/
+static inline void qh_set_next_qh(qh_t *instance, uint32_t pa)
 {
-	if (pa) {
-		instance->next_queue = (pa & LINK_POINTER_ADDRESS_MASK)
+	/* address is valid and not terminal */
+	if (pa && ((pa & LINK_POINTER_TERMINATE_FLAG) == 0)) {
+		instance->next = (pa & LINK_POINTER_ADDRESS_MASK)
 		    | LINK_POINTER_QUEUE_HEAD_FLAG;
+	} else {
+		instance->next = 0 | LINK_POINTER_TERMINATE_FLAG;
 	}
 }
-
-static inline void queue_head_element_qh(queue_head_t *instance, uint32_t pa)
+/*----------------------------------------------------------------------------*/
+static inline void qh_set_element_qh(qh_t *instance, uint32_t pa)
 {
-	if (pa) {
-		instance->next_queue = (pa & LINK_POINTER_ADDRESS_MASK)
+	/* address is valid and not terminal */
+	if (pa && ((pa & LINK_POINTER_TERMINATE_FLAG) == 0)) {
+		instance->element = (pa & LINK_POINTER_ADDRESS_MASK)
 		    | LINK_POINTER_QUEUE_HEAD_FLAG;
+	} else {
+		instance->element = 0 | LINK_POINTER_TERMINATE_FLAG;
 	}
 }
-
-static inline void queue_head_set_element_td(queue_head_t *instance, uint32_t pa)
+/*----------------------------------------------------------------------------*/
+static inline void qh_set_element_td(qh_t *instance, uint32_t pa)
 {
-	if (pa) {
+	if (pa && ((pa & LINK_POINTER_TERMINATE_FLAG) == 0)) {
 		instance->element = (pa & LINK_POINTER_ADDRESS_MASK);
+	} else {
+		instance->element = 0 | LINK_POINTER_TERMINATE_FLAG;
 	}
 }
Index: uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.c
===================================================================
--- uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.c	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.c	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -44,5 +44,5 @@
  * @param[in] size Size of data source.
  * @param[in] toggle Value of toggle bit.
- * @param[in] iso True if TD is for Isochronous transfer.
+ * @param[in] iso True if TD represents Isochronous transfer.
  * @param[in] low_speed Target device's speed.
  * @param[in] target Address and endpoint receiving the transfer.
@@ -51,4 +51,12 @@
  * @param[in] next Net TD in transaction.
  * @return Error code.
+ *
+ * Uses a mix of supplied and default values.
+ * Implicit values:
+ *  - all TDs have vertical flag set (makes transfers to endpoints atomic)
+ *  - in the error field only active it is set
+ *  - if the packet uses PID_IN and is not isochronous SPD is set
+ *
+ * Dumps 8 bytes of buffer if PID_SETUP is used.
  */
 void td_init(td_t *instance, int err_count, size_t size, bool toggle, bool iso,
@@ -88,10 +96,11 @@
 	}
 
-	usb_log_debug2("Created TD: %X:%X:%X:%X(%p).\n",
-	    instance->next, instance->status, instance->device,
+	usb_log_debug2("Created TD(%p): %X:%X:%X:%X(%p).\n",
+	    instance, instance->next, instance->status, instance->device,
 	    instance->buffer_ptr, buffer);
+	td_print_status(instance);
 	if (pid == USB_PID_SETUP) {
 		usb_log_debug("SETUP BUFFER: %s\n",
-			usb_debug_str_buffer(buffer, 8, 8));
+		    usb_debug_str_buffer(buffer, 8, 8));
 	}
 }
@@ -126,4 +135,31 @@
 	return EOK;
 }
+/*----------------------------------------------------------------------------*/
+/** Print values in status field (dw1) in a human readable way.
+ *
+ * @param[in] instance TD structure to use.
+ */
+void td_print_status(td_t *instance)
+{
+	assert(instance);
+	const uint32_t s = instance->status;
+	usb_log_debug2("TD(%p) status(%#x):%s %d,%s%s%s%s%s%s%s%s%s%s%s %d.\n",
+	    instance, instance->status,
+	    (s & TD_STATUS_SPD_FLAG) ? " SPD," : "",
+	    (s >> TD_STATUS_ERROR_COUNT_POS) & TD_STATUS_ERROR_COUNT_MASK,
+	    (s & TD_STATUS_LOW_SPEED_FLAG) ? " LOW SPEED," : "",
+	    (s & TD_STATUS_ISOCHRONOUS_FLAG) ? " ISOCHRONOUS," : "",
+	    (s & TD_STATUS_IOC_FLAG) ? " IOC," : "",
+	    (s & TD_STATUS_ERROR_ACTIVE) ? " ACTIVE," : "",
+	    (s & TD_STATUS_ERROR_STALLED) ? " STALLED," : "",
+	    (s & TD_STATUS_ERROR_BUFFER) ? " BUFFER," : "",
+	    (s & TD_STATUS_ERROR_BABBLE) ? " BABBLE," : "",
+	    (s & TD_STATUS_ERROR_NAK) ? " NAK," : "",
+	    (s & TD_STATUS_ERROR_CRC) ? " CRC/TIMEOUT," : "",
+	    (s & TD_STATUS_ERROR_BIT_STUFF) ? " BIT_STUFF," : "",
+	    (s & TD_STATUS_ERROR_RESERVED) ? " RESERVED," : "",
+	    (s >> TD_STATUS_ACTLEN_POS) & TD_STATUS_ACTLEN_MASK
+	);
+}
 /**
  * @}
Index: uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.h
===================================================================
--- uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.h	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.h	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -45,13 +45,11 @@
 
 	volatile uint32_t status;
-
 #define TD_STATUS_RESERVED_MASK 0xc000f800
 #define TD_STATUS_SPD_FLAG ( 1 << 29 )
 #define TD_STATUS_ERROR_COUNT_POS ( 27 )
 #define TD_STATUS_ERROR_COUNT_MASK ( 0x3 )
-#define TD_STATUS_ERROR_COUNT_DEFAULT 3
 #define TD_STATUS_LOW_SPEED_FLAG ( 1 << 26 )
 #define TD_STATUS_ISOCHRONOUS_FLAG ( 1 << 25 )
-#define TD_STATUS_COMPLETE_INTERRUPT_FLAG ( 1 << 24 )
+#define TD_STATUS_IOC_FLAG ( 1 << 24 )
 
 #define TD_STATUS_ERROR_ACTIVE ( 1 << 23 )
@@ -70,5 +68,4 @@
 
 	volatile uint32_t device;
-
 #define TD_DEVICE_MAXLEN_POS 21
 #define TD_DEVICE_MAXLEN_MASK ( 0x7ff )
@@ -85,24 +82,36 @@
 
 	/* there is 16 bytes of data available here, according to UHCI
-	 * Design guide, according to linux kernel the hardware does not care
-	 * we don't use it anyway
+	 * Design guide, according to linux kernel the hardware does not care,
+	 * it just needs to be aligned, we don't use it anyway
 	 */
 } __attribute__((packed)) td_t;
 
 
-void td_init(td_t *instance, int error_count, size_t size, bool toggle, bool iso,
-    bool low_speed, usb_target_t target, usb_packet_id pid, void *buffer,
-    td_t *next);
+void td_init(td_t *instance, int error_count, size_t size, bool toggle,
+    bool iso, bool low_speed, usb_target_t target, usb_packet_id pid,
+    void *buffer, td_t *next);
 
 int td_status(td_t *instance);
 
+void td_print_status(td_t *instance);
+/*----------------------------------------------------------------------------*/
+/** Helper function for parsing actual size out of TD.
+ *
+ * @param[in] instance TD structure to use.
+ * @return Parsed actual size.
+ */
 static inline size_t td_act_size(td_t *instance)
 {
 	assert(instance);
-	return
-	    ((instance->status >> TD_STATUS_ACTLEN_POS) + 1)
-	    & TD_STATUS_ACTLEN_MASK;
+	const uint32_t s = instance->status;
+	return ((s >> TD_STATUS_ACTLEN_POS) + 1) & TD_STATUS_ACTLEN_MASK;
 }
-
+/*----------------------------------------------------------------------------*/
+/** Checks whether less than max data were recieved and packet is marked as SPD.
+ *
+ * @param[in] instance TD structure to use.
+ * @return True if packet is short (less than max bytes and SPD set), false
+ *     otherwise.
+ */
 static inline bool td_is_short(td_t *instance)
 {
@@ -114,12 +123,21 @@
 	    (instance->status | TD_STATUS_SPD_FLAG) && act_size < max_size;
 }
-
+/*----------------------------------------------------------------------------*/
+/** Helper function for parsing value of toggle bit.
+ *
+ * @param[in] instance TD structure to use.
+ * @return Toggle bit value.
+ */
 static inline int td_toggle(td_t *instance)
 {
 	assert(instance);
-	return ((instance->device & TD_DEVICE_DATA_TOGGLE_ONE_FLAG) != 0)
-	    ? 1 : 0;
+	return (instance->device & TD_DEVICE_DATA_TOGGLE_ONE_FLAG) ? 1 : 0;
 }
-
+/*----------------------------------------------------------------------------*/
+/** Helper function for parsing value of active bit
+ *
+ * @param[in] instance TD structure to use.
+ * @return Active bit value.
+ */
 static inline bool td_is_active(td_t *instance)
 {
@@ -127,4 +145,15 @@
 	return (instance->status & TD_STATUS_ERROR_ACTIVE) != 0;
 }
+/*----------------------------------------------------------------------------*/
+/** Helper function for setting IOC bit.
+ *
+ * @param[in] instance TD structure to use.
+ */
+static inline void td_set_ioc(td_t *instance)
+{
+	assert(instance);
+	instance->status |= TD_STATUS_IOC_FLAG;
+}
+/*----------------------------------------------------------------------------*/
 #endif
 /**
Index: uspace/drv/uhci-rhd/Makefile
===================================================================
--- uspace/drv/uhci-rhd/Makefile	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ uspace/drv/uhci-rhd/Makefile	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -35,5 +35,4 @@
 	main.c \
 	port.c \
-	port_status.c \
 	root_hub.c
 
Index: uspace/drv/uhci-rhd/port.c
===================================================================
--- uspace/drv/uhci-rhd/port.c	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ uspace/drv/uhci-rhd/port.c	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -44,5 +44,4 @@
 
 #include "port.h"
-#include "port_status.h"
 
 static int uhci_port_new_device(uhci_port_t *port, usb_speed_t speed);
@@ -67,4 +66,8 @@
 {
 	assert(port);
+	asprintf(&port->id_string, "Port (%p - %d)", port, number);
+	if (port->id_string == NULL) {
+		return ENOMEM;
+	}
 
 	port->address = address;
@@ -116,33 +119,25 @@
 	assert(instance);
 
-	/* Iteration count, for debug purposes only */
-	unsigned count = 0;
-
 	while (1) {
 		async_usleep(instance->wait_period_usec);
 
 		/* read register value */
-		port_status_t port_status = port_status_read(instance->address);
-
-		/* debug print mutex */
-		static fibril_mutex_t dbg_mtx =
-		    FIBRIL_MUTEX_INITIALIZER(dbg_mtx);
-		fibril_mutex_lock(&dbg_mtx);
-		usb_log_debug2("Port(%p - %d): Status: %#04x. === %u\n",
-		  instance->address, instance->number, port_status, count++);
-//		print_port_status(port_status);
-		fibril_mutex_unlock(&dbg_mtx);
+		port_status_t port_status = uhci_port_read_status(instance);
+
+		/* print the value if it's interesting */
+		if (port_status & ~STATUS_ALWAYS_ONE)
+			uhci_port_print_status(instance, port_status);
 
 		if ((port_status & STATUS_CONNECTED_CHANGED) == 0)
 			continue;
 
-		usb_log_debug("Port(%p - %d): Connected change detected: %x.\n",
-		    instance->address, instance->number, port_status);
+		usb_log_debug("%s: Connected change detected: %x.\n",
+		    instance->id_string, port_status);
 
 		int rc =
 		    usb_hc_connection_open(&instance->hc_connection);
 		if (rc != EOK) {
-			usb_log_error("Port(%p - %d): Failed to connect to HC.",
-			    instance->address, instance->number);
+			usb_log_error("%s: Failed to connect to HC.",
+			    instance->id_string);
 			continue;
 		}
@@ -150,6 +145,6 @@
 		/* Remove any old device */
 		if (instance->attached_device) {
-			usb_log_debug2("Port(%p - %d): Removing device.\n",
-			    instance->address, instance->number);
+			usb_log_debug2("%s: Removing device.\n",
+			    instance->id_string);
 			uhci_port_remove_device(instance);
 		}
@@ -163,13 +158,13 @@
 		} else {
 			/* Write one to WC bits, to ack changes */
-			port_status_write(instance->address, port_status);
-			usb_log_debug("Port(%p - %d): Change status ACK.\n",
-			    instance->address, instance->number);
+			uhci_port_write_status(instance, port_status);
+			usb_log_debug("%s: status change ACK.\n",
+			    instance->id_string);
 		}
 
 		rc = usb_hc_connection_close(&instance->hc_connection);
 		if (rc != EOK) {
-			usb_log_error("Port(%p - %d): Failed to disconnect.",
-			    instance->address, instance->number);
+			usb_log_error("%s: Failed to disconnect.",
+			    instance->id_string);
 		}
 	}
@@ -187,6 +182,5 @@
 	uhci_port_t *port = (uhci_port_t *) arg;
 
-	usb_log_debug2("Port(%p - %d): new_device_enable_port.\n",
-	    port->address, port->number);
+	usb_log_debug2("%s: new_device_enable_port.\n", port->id_string);
 
 	/*
@@ -196,25 +190,25 @@
 	async_usleep(100000);
 
-
-	/* The hub maintains the reset signal to that port for 10 ms
-	 * (See Section 11.5.1.5)
+	/*
+	 * Resets from root ports should be nominally 50ms
 	 */
 	{
-		usb_log_debug("Port(%p - %d): Reset Signal start.\n",
-		    port->address, port->number);
-		port_status_t port_status =
-			port_status_read(port->address);
+		usb_log_debug("%s: Reset Signal start.\n", port->id_string);
+		port_status_t port_status = uhci_port_read_status(port);
 		port_status |= STATUS_IN_RESET;
-		port_status_write(port->address, port_status);
-		async_usleep(10000);
-		port_status = port_status_read(port->address);
+		uhci_port_write_status(port, port_status);
+		async_usleep(50000);
+		port_status = uhci_port_read_status(port);
 		port_status &= ~STATUS_IN_RESET;
-		port_status_write(port->address, port_status);
-		usb_log_debug("Port(%p - %d): Reset Signal stop.\n",
-		    port->address, port->number);
-	}
+		uhci_port_write_status(port, port_status);
+		usb_log_debug("%s: Reset Signal stop.\n", port->id_string);
+	}
+
+	/* the reset recovery time 10ms */
+	async_usleep(10000);
 
 	/* Enable the port. */
 	uhci_port_set_enabled(port, true);
+
 	return EOK;
 }
@@ -233,6 +227,5 @@
 	assert(usb_hc_connection_is_opened(&port->hc_connection));
 
-	usb_log_info("Port(%p-%d): Detected new device.\n",
-	    port->address, port->number);
+	usb_log_info("%s: Detected new device.\n", port->id_string);
 
 	usb_address_t dev_addr;
@@ -242,12 +235,12 @@
 
 	if (rc != EOK) {
-		usb_log_error("Port(%p-%d): Failed(%d) to add device: %s.\n",
-		    port->address, port->number, rc, str_error(rc));
+		usb_log_error("%s: Failed(%d) to add device: %s.\n",
+		    port->id_string, rc, str_error(rc));
 		uhci_port_set_enabled(port, false);
 		return rc;
 	}
 
-	usb_log_info("Port(%p-%d): New device has address %d (handle %zu).\n",
-	    port->address, port->number, dev_addr, port->attached_device);
+	usb_log_info("%s: New device has address %d (handle %zu).\n",
+	    port->id_string, dev_addr, port->attached_device);
 
 	return EOK;
@@ -263,6 +256,6 @@
 int uhci_port_remove_device(uhci_port_t *port)
 {
-	usb_log_error("Port(%p-%d): Don't know how to remove device %#x.\n",
-	    port->address, port->number, (unsigned int)port->attached_device);
+	usb_log_error("%s: Don't know how to remove device %d.\n",
+	    port->id_string, (unsigned int)port->attached_device);
 	return EOK;
 }
@@ -278,5 +271,5 @@
 
 	/* Read register value */
-	port_status_t port_status = port_status_read(port->address);
+	port_status_t port_status = uhci_port_read_status(port);
 
 	/* Set enabled bit */
@@ -288,8 +281,8 @@
 
 	/* Write new value. */
-	port_status_write(port->address, port_status);
-
-	usb_log_info("Port(%p-%d): %sabled port.\n",
-		port->address, port->number, enabled ? "En" : "Dis");
+	uhci_port_write_status(port, port_status);
+
+	usb_log_info("%s: %sabled port.\n",
+		port->id_string, enabled ? "En" : "Dis");
 	return EOK;
 }
Index: uspace/drv/uhci-rhd/port.h
===================================================================
--- uspace/drv/uhci-rhd/port.h	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ uspace/drv/uhci-rhd/port.h	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -36,12 +36,27 @@
 
 #include <assert.h>
+#include <stdint.h>
 #include <ddf/driver.h>
-#include <stdint.h>
+#include <libarch/ddi.h> /* pio_read and pio_write */
 #include <usb/usbdevice.h>
 
-#include "port_status.h"
+typedef uint16_t port_status_t;
+
+#define STATUS_CONNECTED         (1 << 0)
+#define STATUS_CONNECTED_CHANGED (1 << 1)
+#define STATUS_ENABLED           (1 << 2)
+#define STATUS_ENABLED_CHANGED   (1 << 3)
+#define STATUS_LINE_D_PLUS       (1 << 4)
+#define STATUS_LINE_D_MINUS      (1 << 5)
+#define STATUS_RESUME            (1 << 6)
+#define STATUS_ALWAYS_ONE        (1 << 7)
+
+#define STATUS_LOW_SPEED (1 <<  8)
+#define STATUS_IN_RESET  (1 <<  9)
+#define STATUS_SUSPEND   (1 << 12)
 
 typedef struct uhci_port
 {
+	char *id_string;
 	port_status_t *address;
 	unsigned number;
@@ -58,4 +73,37 @@
 
 void uhci_port_fini(uhci_port_t *port);
+
+static inline port_status_t uhci_port_read_status(uhci_port_t *port)
+{
+	assert(port);
+	return pio_read_16(port->address);
+}
+
+static inline void uhci_port_write_status(
+    uhci_port_t *port, port_status_t value)
+{
+	assert(port);
+	pio_write_16(port->address, value);
+}
+
+static inline void uhci_port_print_status(
+    uhci_port_t *port, const port_status_t value)
+{
+	assert(port);
+	usb_log_debug2("%s Port status(%#x):%s%s%s%s%s%s%s%s%s%s%s.\n",
+	    port->id_string, value,
+	    (value & STATUS_SUSPEND) ? " SUSPENDED," : "",
+	    (value & STATUS_RESUME) ? " IN RESUME," : "",
+	    (value & STATUS_IN_RESET) ? " IN RESET," : "",
+	    (value & STATUS_LINE_D_MINUS) ? " VD-," : "",
+	    (value & STATUS_LINE_D_PLUS) ? " VD+," : "",
+	    (value & STATUS_LOW_SPEED) ? " LOWSPEED," : "",
+	    (value & STATUS_ENABLED_CHANGED) ? " ENABLED-CHANGE," : "",
+	    (value & STATUS_ENABLED) ? " ENABLED," : "",
+	    (value & STATUS_CONNECTED_CHANGED) ? " CONNECTED-CHANGE," : "",
+	    (value & STATUS_CONNECTED) ? " CONNECTED," : "",
+	    (value & STATUS_ALWAYS_ONE) ? " ALWAYS ONE" : " ERROR: NO ALWAYS ONE"
+	);
+}
 #endif
 /**
Index: pace/drv/uhci-rhd/port_status.c
===================================================================
--- uspace/drv/uhci-rhd/port_status.c	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ 	(revision )
@@ -1,77 +1,0 @@
-/*
- * Copyright (c) 2011 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/** @addtogroup usb
- * @{
- */
-/** @file
- * @brief UHCI driver
- */
-#include <assert.h>
-#include <stdio.h>
-
-#include <usb/debug.h>
-
-#include "port_status.h"
-
-struct flag_name
-{
-	uint16_t flag;
-	const char *name;
-};
-
-static const struct flag_name flags[] =
-{
-	{ STATUS_SUSPEND, "suspended" },
-	{ STATUS_IN_RESET, "in reset" },
-	{ STATUS_LOW_SPEED, "low speed device" },
-	{ STATUS_ALWAYS_ONE, "always 1 bit" },
-	{ STATUS_RESUME, "resume" },
-	{ STATUS_LINE_D_MINUS, "line D- value" },
-	{ STATUS_LINE_D_PLUS, "line D+ value" },
-	{ STATUS_ENABLED_CHANGED, "enabled changed" },
-	{ STATUS_ENABLED, "enabled" },
-	{ STATUS_CONNECTED_CHANGED, "connected changed" },
-	{ STATUS_CONNECTED, "connected" }
-};
-
-/** Prints portr status in a human readable way.
- *
- * @param[in] value Port value to print.
- * @return Error code.
- */
-void print_port_status(port_status_t value)
-{
-	unsigned i = 0;
-	for (;i < sizeof(flags)/sizeof(struct flag_name); ++i) {
-		usb_log_debug2("\t%s status: %s.\n", flags[i].name,
-		  ((value & flags[i].flag) != 0) ? "YES" : "NO");
-	}
-}
-/**
- * @}
- */
Index: pace/drv/uhci-rhd/port_status.h
===================================================================
--- uspace/drv/uhci-rhd/port_status.h	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ 	(revision )
@@ -1,67 +1,0 @@
-/*
- * Copyright (c) 2010 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/** @addtogroup usb
- * @{
- */
-/** @file
- * @brief UHCI driver
- */
-#ifndef DRV_UHCI_TD_PORT_STATUS_H
-#define DRV_UHCI_TD_PORT_STATUS_H
-
-#include <libarch/ddi.h> /* pio_read and pio_write */
-
-#include <stdint.h>
-
-typedef uint16_t port_status_t;
-
-#define STATUS_CONNECTED         (1 << 0)
-#define STATUS_CONNECTED_CHANGED (1 << 1)
-#define STATUS_ENABLED           (1 << 2)
-#define STATUS_ENABLED_CHANGED   (1 << 3)
-#define STATUS_LINE_D_PLUS       (1 << 4)
-#define STATUS_LINE_D_MINUS      (1 << 5)
-#define STATUS_RESUME            (1 << 6)
-#define STATUS_ALWAYS_ONE        (1 << 7)
-
-#define STATUS_LOW_SPEED (1 <<  8)
-#define STATUS_IN_RESET  (1 <<  9)
-#define STATUS_SUSPEND   (1 << 12)
-
-static inline port_status_t port_status_read(port_status_t * address)
-	{ return pio_read_16(address); }
-
-static inline void port_status_write(
-  port_status_t *address, port_status_t value)
-	{ pio_write_16(address, value); }
-
-void print_port_status(const port_status_t status);
-#endif
-/**
- * @}
- */
Index: uspace/lib/usb/src/pipesinit.c
===================================================================
--- uspace/lib/usb/src/pipesinit.c	(revision adfe5ec430133414328032779903e14f4472fd85)
+++ uspace/lib/usb/src/pipesinit.c	(revision deb4ba7a231f7bf47e9f3a952e7a7e4fe5506de5)
@@ -37,4 +37,5 @@
 #include <usb/pipes.h>
 #include <usb/dp.h>
+#include <usb/request.h>
 #include <errno.h>
 #include <assert.h>
@@ -370,5 +371,23 @@
 	int rc = usb_endpoint_pipe_initialize(pipe, connection,
 	    0, USB_TRANSFER_CONTROL, 8, USB_DIRECTION_BOTH);
-
+	if (rc != EOK) {
+		return rc;
+	}
+	rc = usb_endpoint_pipe_start_session(pipe);
+	if (rc != EOK) {
+		return rc;
+	}
+
+	uint8_t first[8];
+	size_t size = 0;
+	rc = usb_control_request_get(pipe, USB_REQUEST_TYPE_STANDARD,
+	    USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_GET_DESCRIPTOR, 1 << 8,
+			0, first, 8, &size);
+	usb_endpoint_pipe_end_session(pipe);
+	if (rc != EOK || size  != 8) {
+		return rc;
+	}
+
+	pipe->max_packet_size = first[7];
 	return rc;
 }
