Index: uspace/drv/uhci-hcd/batch.c
===================================================================
--- uspace/drv/uhci-hcd/batch.c	(revision 1fb1339c2806d3d992b780c1f6c3a411fc3fdfe6)
+++ uspace/drv/uhci-hcd/batch.c	(revision 81dce9f771a48fddabf8296e844817d7c79b4879)
@@ -42,12 +42,18 @@
 #include "uhci_hc.h"
 #include "utils/malloc32.h"
+#include "uhci_struct/transfer_descriptor.h"
 
 #define DEFAULT_ERROR_COUNT 3
+
+typedef struct uhci_batch {
+	qh_t *qh;
+	td_t *tds;
+	size_t packets;
+	device_keeper_t *manager;
+} uhci_batch_t;
 
 static void batch_control(batch_t *instance,
     usb_packet_id data_stage, usb_packet_id status_stage);
 static void batch_data(batch_t *instance, usb_packet_id pid);
-static void batch_call_in(batch_t *instance);
-static void batch_call_out(batch_t *instance);
 static void batch_call_in_and_dispose(batch_t *instance);
 static void batch_call_out_and_dispose(batch_t *instance);
@@ -78,5 +84,5 @@
 batch_t * batch_get(ddf_fun_t *fun, usb_target_t target,
     usb_transfer_type_t transfer_type, size_t max_packet_size,
-    usb_speed_t speed, char *buffer, size_t size,
+    usb_speed_t speed, char *buffer, size_t buffer_size,
     char* setup_buffer, size_t setup_size,
     usbhc_iface_transfer_in_callback_t func_in,
@@ -100,23 +106,34 @@
 	CHECK_NULL_DISPOSE_RETURN(instance,
 	    "Failed to allocate batch instance.\n");
-	bzero(instance, sizeof(batch_t));
-
-	instance->qh = malloc32(sizeof(qh_t));
-	CHECK_NULL_DISPOSE_RETURN(instance->qh,
+	batch_init(instance, target, transfer_type, speed, max_packet_size,
+	    buffer, NULL, buffer_size, NULL, setup_size, func_in,
+	    func_out, arg, fun, NULL);
+
+
+	uhci_batch_t *data = malloc(sizeof(uhci_batch_t));
+	CHECK_NULL_DISPOSE_RETURN(instance,
+	    "Failed to allocate batch instance.\n");
+	bzero(data, sizeof(uhci_batch_t));
+	data->manager = manager;
+	instance->private_data = data;
+
+	data->packets = (buffer_size + max_packet_size - 1) / max_packet_size;
+	if (transfer_type == USB_TRANSFER_CONTROL) {
+		data->packets += 2;
+	}
+
+	data->tds = malloc32(sizeof(td_t) * data->packets);
+	CHECK_NULL_DISPOSE_RETURN(
+	    data->tds, "Failed to allocate transfer descriptors.\n");
+	bzero(data->tds, sizeof(td_t) * data->packets);
+
+	data->qh = malloc32(sizeof(qh_t));
+	CHECK_NULL_DISPOSE_RETURN(data->qh,
 	    "Failed to allocate batch queue head.\n");
-	qh_init(instance->qh);
-
-	instance->packets = (size + max_packet_size - 1) / max_packet_size;
-	if (transfer_type == USB_TRANSFER_CONTROL) {
-		instance->packets += 2;
-	}
-
-	instance->tds = malloc32(sizeof(td_t) * instance->packets);
-	CHECK_NULL_DISPOSE_RETURN(
-	    instance->tds, "Failed to allocate transfer descriptors.\n");
-	bzero(instance->tds, sizeof(td_t) * instance->packets);
-
-	if (size > 0) {
-		instance->transport_buffer = malloc32(size);
+	qh_init(data->qh);
+	qh_set_element_td(data->qh, addr_to_phys(data->tds));
+
+	if (buffer_size > 0) {
+		instance->transport_buffer = malloc32(buffer_size);
 		CHECK_NULL_DISPOSE_RETURN(instance->transport_buffer,
 		    "Failed to allocate device accessible buffer.\n");
@@ -130,22 +147,4 @@
 	}
 
-
-	link_initialize(&instance->link);
-
-	instance->max_packet_size = max_packet_size;
-	instance->target = target;
-	instance->transfer_type = transfer_type;
-	instance->buffer = buffer;
-	instance->buffer_size = size;
-	instance->setup_size = setup_size;
-	instance->fun = fun;
-	instance->arg = arg;
-	instance->speed = speed;
-	instance->manager = manager;
-	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",
 	    instance, target.address, target.endpoint);
@@ -153,16 +152,4 @@
 }
 /*----------------------------------------------------------------------------*/
-/** Mark batch as failed and continue with next step.
- *
- * @param[in] instance Batch structure to use.
- *
- */
-void batch_abort(batch_t *instance)
-{
-	assert(instance);
-	instance->error = EIO;
-	instance->next_step(instance);
-}
-/*----------------------------------------------------------------------------*/
 /** Check batch TDs for activity.
  *
@@ -177,21 +164,24 @@
 {
 	assert(instance);
+	uhci_batch_t *data = instance->private_data;
+	assert(data);
+
 	usb_log_debug2("Batch(%p) checking %d packet(s) for completion.\n",
-	    instance, instance->packets);
+	    instance, data->packets);
 	instance->transfered_size = 0;
 	size_t i = 0;
-	for (;i < instance->packets; ++i) {
-		if (td_is_active(&instance->tds[i])) {
+	for (;i < data->packets; ++i) {
+		if (td_is_active(&data->tds[i])) {
 			return false;
 		}
 
-		instance->error = td_status(&instance->tds[i]);
+		instance->error = td_status(&data->tds[i]);
 		if (instance->error != EOK) {
 			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,
-			    instance->target, td_toggle(&instance->tds[i]));
+			    instance, i, data->tds[i].status);
+			td_print_status(&data->tds[i]);
+
+			device_keeper_set_toggle(data->manager,
+			    instance->target, td_toggle(&data->tds[i]));
 			if (i > 0)
 				goto substract_ret;
@@ -199,6 +189,6 @@
 		}
 
-		instance->transfered_size += td_act_size(&instance->tds[i]);
-		if (td_is_short(&instance->tds[i]))
+		instance->transfered_size += td_act_size(&data->tds[i]);
+		if (td_is_short(&data->tds[i]))
 			goto substract_ret;
 	}
@@ -312,7 +302,9 @@
 {
 	assert(instance);
+	uhci_batch_t *data = instance->private_data;
+	assert(data);
+
 	const bool low_speed = instance->speed == USB_SPEED_LOW;
-	int toggle =
-	    device_keeper_get_toggle(instance->manager, instance->target);
+	int toggle = device_keeper_get_toggle(data->manager, instance->target);
 	assert(toggle == 0 || toggle == 1);
 
@@ -320,5 +312,5 @@
 	size_t remain_size = instance->buffer_size;
 	while (remain_size > 0) {
-		char *data =
+		char *trans_data =
 		    instance->transport_buffer + instance->buffer_size
 		    - remain_size;
@@ -328,13 +320,13 @@
 		    remain_size : instance->max_packet_size;
 
-		td_t *next_packet = (packet + 1 < instance->packets)
-		    ? &instance->tds[packet + 1] : NULL;
-
-		assert(packet < instance->packets);
+		td_t *next_packet = (packet + 1 < data->packets)
+		    ? &data->tds[packet + 1] : NULL;
+
+		assert(packet < data->packets);
 		assert(packet_size <= remain_size);
 
 		td_init(
-		    &instance->tds[packet], DEFAULT_ERROR_COUNT, packet_size,
-		    toggle, false, low_speed, instance->target, pid, data,
+		    &data->tds[packet], DEFAULT_ERROR_COUNT, packet_size,
+		    toggle, false, low_speed, instance->target, pid, trans_data,
 		    next_packet);
 
@@ -344,6 +336,6 @@
 		++packet;
 	}
-	td_set_ioc(&instance->tds[packet - 1]);
-	device_keeper_set_toggle(instance->manager, instance->target, toggle);
+	td_set_ioc(&data->tds[packet - 1]);
+	device_keeper_set_toggle(data->manager, instance->target, toggle);
 }
 /*----------------------------------------------------------------------------*/
@@ -363,11 +355,15 @@
 {
 	assert(instance);
+	uhci_batch_t *data = instance->private_data;
+	assert(data);
+	assert(data->packets >= 2);
 
 	const bool low_speed = instance->speed == USB_SPEED_LOW;
 	int toggle = 0;
 	/* setup stage */
-	td_init(instance->tds, DEFAULT_ERROR_COUNT,
-	    instance->setup_size, toggle, false, low_speed, instance->target,
-	    USB_PID_SETUP, instance->setup_buffer, &instance->tds[1]);
+	td_init(
+	    data->tds, DEFAULT_ERROR_COUNT, instance->setup_size, toggle, false,
+	    low_speed, instance->target, USB_PID_SETUP, instance->setup_buffer,
+	    &data->tds[1]);
 
 	/* data stage */
@@ -375,5 +371,5 @@
 	size_t remain_size = instance->buffer_size;
 	while (remain_size > 0) {
-		char *data =
+		char *control_data =
 		    instance->transport_buffer + instance->buffer_size
 		    - remain_size;
@@ -386,10 +382,10 @@
 
 		td_init(
-		    &instance->tds[packet], DEFAULT_ERROR_COUNT, packet_size,
+		    &data->tds[packet], DEFAULT_ERROR_COUNT, packet_size,
 		    toggle, false, low_speed, instance->target, data_stage,
-		    data, &instance->tds[packet + 1]);
+		    control_data, &data->tds[packet + 1]);
 
 		++packet;
-		assert(packet < instance->packets);
+		assert(packet < data->packets);
 		assert(packet_size <= remain_size);
 		remain_size -= packet_size;
@@ -397,51 +393,21 @@
 
 	/* status stage */
-	assert(packet == instance->packets - 1);
-	td_init(&instance->tds[packet], DEFAULT_ERROR_COUNT,
-	    0, 1, false, low_speed, instance->target, status_stage, NULL, NULL);
-
-	td_set_ioc(&instance->tds[packet]);
+	assert(packet == data->packets - 1);
+
+	td_init(
+	    &data->tds[packet], DEFAULT_ERROR_COUNT, 0, 1, false, low_speed,
+	    instance->target, status_stage, NULL, NULL);
+	td_set_ioc(&data->tds[packet]);
+
 	usb_log_debug2("Control last TD status: %x.\n",
-	    instance->tds[packet].status);
-}
-/*----------------------------------------------------------------------------*/
-/** Prepare data, get error status and call callback in.
- *
- * @param[in] instance Batch structure to use.
- * Copies data from transport buffer, and calls callback with appropriate
- * parameters.
- */
-void batch_call_in(batch_t *instance)
-{
-	assert(instance);
-	assert(instance->callback_in);
-
-	/* We are data in, we need data */
-	memcpy(instance->buffer, instance->transport_buffer,
-	    instance->buffer_size);
-
-	int err = instance->error;
-	usb_log_debug("Batch(%p) callback IN(type:%d): %s(%d), %zu.\n",
-	    instance, instance->transfer_type, str_error(err), err,
-	    instance->transfered_size);
-
-	instance->callback_in(
-	    instance->fun, err, instance->transfered_size, instance->arg);
-}
-/*----------------------------------------------------------------------------*/
-/** Get error status and call callback out.
- *
- * @param[in] instance Batch structure to use.
- */
-void batch_call_out(batch_t *instance)
-{
-	assert(instance);
-	assert(instance->callback_out);
-
-	int err = instance->error;
-	usb_log_debug("Batch(%p) callback OUT(type:%d): %s(%d).\n",
-	    instance, instance->transfer_type, str_error(err), err);
-	instance->callback_out(instance->fun,
-	    err, instance->arg);
+	    data->tds[packet].status);
+}
+/*----------------------------------------------------------------------------*/
+qh_t * batch_qh(batch_t *instance)
+{
+	assert(instance);
+	uhci_batch_t *data = instance->private_data;
+	assert(data);
+	return data->qh;
 }
 /*----------------------------------------------------------------------------*/
@@ -475,10 +441,13 @@
 {
 	assert(instance);
+	uhci_batch_t *data = instance->private_data;
+	assert(data);
 	usb_log_debug("Batch(%p) disposing.\n", instance);
 	/* free32 is NULL safe */
-	free32(instance->tds);
-	free32(instance->qh);
+	free32(data->tds);
+	free32(data->qh);
 	free32(instance->setup_buffer);
 	free32(instance->transport_buffer);
+	free(data);
 	free(instance);
 }
Index: uspace/drv/uhci-hcd/batch.h
===================================================================
--- uspace/drv/uhci-hcd/batch.h	(revision 1fb1339c2806d3d992b780c1f6c3a411fc3fdfe6)
+++ uspace/drv/uhci-hcd/batch.h	(revision 81dce9f771a48fddabf8296e844817d7c79b4879)
@@ -40,32 +40,7 @@
 #include <usb/usb.h>
 #include <usb/host/device_keeper.h>
+#include <usb/host/batch.h>
 
-#include "uhci_struct/transfer_descriptor.h"
 #include "uhci_struct/queue_head.h"
-
-typedef struct batch
-{
-	link_t link;
-	usb_speed_t speed;
-	usb_target_t target;
-	usb_transfer_type_t transfer_type;
-	usbhc_iface_transfer_in_callback_t callback_in;
-	usbhc_iface_transfer_out_callback_t callback_out;
-	void *arg;
-	char *transport_buffer;
-	char *setup_buffer;
-	size_t setup_size;
-	char *buffer;
-	size_t buffer_size;
-	size_t max_packet_size;
-	size_t packets;
-	size_t transfered_size;
-	int error;
-	ddf_fun_t *fun;
-	qh_t *qh;
-	td_t *tds;
-	void (*next_step)(struct batch*);
-	device_keeper_t *manager;
-} batch_t;
 
 batch_t * batch_get(
@@ -87,6 +62,4 @@
 void batch_dispose(batch_t *instance);
 
-void batch_abort(batch_t *instance);
-
 bool batch_is_complete(batch_t *instance);
 
@@ -102,4 +75,6 @@
 
 void batch_bulk_out(batch_t *instance);
+
+qh_t * batch_qh(batch_t *instance);
 #endif
 /**
Index: uspace/drv/uhci-hcd/transfer_list.c
===================================================================
--- uspace/drv/uhci-hcd/transfer_list.c	(revision 1fb1339c2806d3d992b780c1f6c3a411fc3fdfe6)
+++ uspace/drv/uhci-hcd/transfer_list.c	(revision 81dce9f771a48fddabf8296e844817d7c79b4879)
@@ -98,10 +98,10 @@
 	usb_log_debug2("Queue %s: Adding batch(%p).\n", instance->name, batch);
 
-	const uint32_t pa = addr_to_phys(batch->qh);
+	const uint32_t pa = addr_to_phys(batch_qh(batch));
 	assert((pa & LINK_POINTER_ADDRESS_MASK) == pa);
 
 	/* 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);
+	qh_set_next_qh(batch_qh(batch), instance->queue_head->next);
 
 	fibril_mutex_lock(&instance->guard);
@@ -117,5 +117,5 @@
 		batch_t *last = list_get_instance(
 		    instance->batch_list.prev, batch_t, link);
-		qh_set_next_qh(last->qh, pa);
+		qh_set_next_qh(batch_qh(last), pa);
 	}
 	/* Add to the driver list */
@@ -178,5 +178,5 @@
 		batch_t *batch = list_get_instance(current, batch_t, link);
 		transfer_list_remove_batch(instance, batch);
-		batch_abort(batch);
+		batch_finish(batch, EIO);
 	}
 	fibril_mutex_unlock(&instance->guard);
@@ -194,7 +194,7 @@
 {
 	assert(instance);
+	assert(instance->queue_head);
 	assert(batch);
-	assert(instance->queue_head);
-	assert(batch->qh);
+	assert(batch_qh(batch));
 	usb_log_debug2(
 	    "Queue %s: removing batch(%p).\n", instance->name, batch);
@@ -204,10 +204,10 @@
 	if (batch->link.prev == &instance->batch_list) {
 		/* I'm the first one here */
-		qh_set_element_qh(instance->queue_head, batch->qh->next);
+		qh_set_element_qh(instance->queue_head, batch_qh(batch)->next);
 		pos = "FIRST";
 	} else {
 		batch_t *prev =
 		    list_get_instance(batch->link.prev, batch_t, link);
-		qh_set_next_qh(prev->qh, batch->qh->next);
+		qh_set_next_qh(batch_qh(prev), batch_qh(batch)->next);
 		pos = "NOT FIRST";
 	}
@@ -215,5 +215,5 @@
 	list_remove(&batch->link);
 	usb_log_debug("Batch(%p) removed (%s) from %s, next element %x.\n",
-	    batch, pos, instance->name, batch->qh->next);
+	    batch, pos, instance->name, batch_qh(batch)->next);
 }
 /**
