Index: uspace/drv/uhci-hcd/batch.c
===================================================================
--- uspace/drv/uhci-hcd/batch.c	(revision a81736d5a19f612dd776f4dd81fbff64da31b2aa)
+++ uspace/drv/uhci-hcd/batch.c	(revision 910ca3f971a607c0cfe8546c14f33943967cb2bf)
@@ -30,5 +30,5 @@
  */
 /** @file
- * @brief UHCI driver USB transaction structure
+ * @brief UHCI driver USB transfer structure
  */
 #include <errno.h>
@@ -61,16 +61,12 @@
  *
  * @param[in] fun DDF function to pass to callback.
- * @param[in] target Device and endpoint target of the transaction.
- * @param[in] transfer_type Interrupt, Control or Bulk.
- * @param[in] max_packet_size maximum allowed size of data transactions.
- * @param[in] speed Speed of the transaction.
+ * @param[in] ep Communication target
  * @param[in] buffer Data source/destination.
  * @param[in] size Size of the buffer.
  * @param[in] setup_buffer Setup data source (if not NULL)
  * @param[in] setup_size Size of setup_buffer (should be always 8)
- * @param[in] func_in function to call on inbound transaction completion
- * @param[in] func_out function to call on outbound transaction completion
+ * @param[in] func_in function to call on inbound transfer completion
+ * @param[in] func_out function to call on outbound transfer completion
  * @param[in] arg additional parameter to func_in or func_out
- * @param[in] ep Pointer to endpoint toggle management structure.
  * @return Valid pointer if all substructures were successfully created,
  * NULL otherwise.
@@ -78,5 +74,5 @@
  * Determines the number of needed transfer descriptors (TDs).
  * Prepares a transport buffer (that is accessible by the hardware).
- * Initializes parameters needed for the transaction and callback.
+ * Initializes parameters needed for the transfer and callback.
  */
 usb_transfer_batch_t * batch_get(ddf_fun_t *fun, endpoint_t *ep,
@@ -154,5 +150,5 @@
  *
  * Walk all TDs. Stop with false if there is an active one (it is to be
- * processed). Stop with true if an error is found. Return true if the last TS
+ * processed). Stop with true if an error is found. Return true if the last TD
  * is reached.
  */
@@ -177,6 +173,6 @@
 			    instance, i, data->tds[i].status);
 			td_print_status(&data->tds[i]);
+
 			assert(instance->ep != NULL);
-
 			endpoint_toggle_set(instance->ep,
 			    td_toggle(&data->tds[i]));
@@ -195,9 +191,9 @@
 }
 /*----------------------------------------------------------------------------*/
-/** Prepares control write transaction.
- *
- * @param[in] instance Batch structure to use.
- *
- * Uses genercir control function with pids OUT and IN.
+/** Prepares control write transfer.
+ *
+ * @param[in] instance Batch structure to use.
+ *
+ * Uses generic control function with pids OUT and IN.
  */
 void batch_control_write(usb_transfer_batch_t *instance)
@@ -211,5 +207,5 @@
 }
 /*----------------------------------------------------------------------------*/
-/** Prepares control read transaction.
+/** Prepares control read transfer.
  *
  * @param[in] instance Batch structure to use.
@@ -225,14 +221,13 @@
 }
 /*----------------------------------------------------------------------------*/
-/** Prepare interrupt in transaction.
- *
- * @param[in] instance Batch structure to use.
- *
- * Data transaction with PID_IN.
+/** Prepare interrupt in transfer.
+ *
+ * @param[in] instance Batch structure to use.
+ *
+ * Data transfer with PID_IN.
  */
 void batch_interrupt_in(usb_transfer_batch_t *instance)
 {
 	assert(instance);
-//	instance->direction = USB_DIRECTION_IN;
 	batch_data(instance, USB_PID_IN);
 	instance->next_step = batch_call_in_and_dispose;
@@ -240,9 +235,9 @@
 }
 /*----------------------------------------------------------------------------*/
-/** Prepare interrupt out transaction.
- *
- * @param[in] instance Batch structure to use.
- *
- * Data transaction with PID_OUT.
+/** Prepare interrupt out transfer.
+ *
+ * @param[in] instance Batch structure to use.
+ *
+ * Data transfer with PID_OUT.
  */
 void batch_interrupt_out(usb_transfer_batch_t *instance)
@@ -256,9 +251,9 @@
 }
 /*----------------------------------------------------------------------------*/
-/** Prepare bulk in transaction.
- *
- * @param[in] instance Batch structure to use.
- *
- * Data transaction with PID_IN.
+/** Prepare bulk in transfer.
+ *
+ * @param[in] instance Batch structure to use.
+ *
+ * Data transfer with PID_IN.
  */
 void batch_bulk_in(usb_transfer_batch_t *instance)
@@ -270,9 +265,9 @@
 }
 /*----------------------------------------------------------------------------*/
-/** Prepare bulk out transaction.
- *
- * @param[in] instance Batch structure to use.
- *
- * Data transaction with PID_OUT.
+/** Prepare bulk out transfer.
+ *
+ * @param[in] instance Batch structure to use.
+ *
+ * Data transfer with PID_OUT.
  */
 void batch_bulk_out(usb_transfer_batch_t *instance)
@@ -280,6 +275,5 @@
 	assert(instance);
 	/* We are data out, we are supposed to provide data */
-	memcpy(instance->data_buffer, instance->buffer,
-	    instance->buffer_size);
+	memcpy(instance->data_buffer, instance->buffer, instance->buffer_size);
 	batch_data(instance, USB_PID_OUT);
 	instance->next_step = batch_call_out_and_dispose;
@@ -287,10 +281,10 @@
 }
 /*----------------------------------------------------------------------------*/
-/** Prepare generic data transaction
+/** Prepare generic data transfer
  *
  * @param[in] instance Batch structure to use.
  * @param[in] pid Pid to use for data transactions.
  *
- * Packets with alternating toggle bit and supplied pid value.
+ * Transactions with alternating toggle bit and supplied pid value.
  * The last transfer is marked with IOC flag.
  */
@@ -307,9 +301,6 @@
 	size_t td = 0;
 	size_t remain_size = instance->buffer_size;
+	char *buffer = instance->data_buffer;
 	while (remain_size > 0) {
-		char *trans_data =
-		    instance->data_buffer + instance->buffer_size
-		    - remain_size;
-
 		const size_t packet_size =
 		    (instance->ep->max_packet_size > remain_size) ?
@@ -319,17 +310,18 @@
 		    ? &data->tds[td + 1] : NULL;
 
-		assert(td < data->td_count);
-		assert(packet_size <= remain_size);
+
 		usb_target_t target =
 		    { instance->ep->address, instance->ep->endpoint };
 
+		assert(td < data->td_count);
 		td_init(
 		    &data->tds[td], DEFAULT_ERROR_COUNT, packet_size,
-		    toggle, false, low_speed, target, pid, trans_data, next_td);
-
-
+		    toggle, false, low_speed, target, pid, buffer, next_td);
+
+		++td;
 		toggle = 1 - toggle;
+		buffer += packet_size;
+		assert(packet_size <= remain_size);
 		remain_size -= packet_size;
-		++td;
 	}
 	td_set_ioc(&data->tds[td - 1]);
@@ -337,5 +329,5 @@
 }
 /*----------------------------------------------------------------------------*/
-/** Prepare generic control transaction
+/** Prepare generic control transfer
  *
  * @param[in] instance Batch structure to use.
@@ -357,5 +349,4 @@
 
 	const bool low_speed = instance->ep->speed == USB_SPEED_LOW;
-	int toggle = 0;
 	const usb_target_t target =
 	    { instance->ep->address, instance->ep->endpoint };
@@ -363,5 +354,5 @@
 	/* setup stage */
 	td_init(
-	    data->tds, DEFAULT_ERROR_COUNT, instance->setup_size, toggle, false,
+	    data->tds, DEFAULT_ERROR_COUNT, instance->setup_size, 0, false,
 	    low_speed, target, USB_PID_SETUP, instance->setup_buffer,
 	    &data->tds[1]);
@@ -369,12 +360,8 @@
 	/* data stage */
 	size_t td = 1;
+	unsigned toggle = 1;
 	size_t remain_size = instance->buffer_size;
+	char *buffer = instance->data_buffer;
 	while (remain_size > 0) {
-		char *control_data =
-		    instance->data_buffer + instance->buffer_size
-		    - remain_size;
-
-		toggle = 1 - toggle;
-
 		const size_t packet_size =
 		    (instance->ep->max_packet_size > remain_size) ?
@@ -384,7 +371,9 @@
 		    &data->tds[td], DEFAULT_ERROR_COUNT, packet_size,
 		    toggle, false, low_speed, target, data_stage,
-		    control_data, &data->tds[td + 1]);
+		    buffer, &data->tds[td + 1]);
 
 		++td;
+		toggle = 1 - toggle;
+		buffer += packet_size;
 		assert(td < data->td_count);
 		assert(packet_size <= remain_size);
@@ -412,5 +401,5 @@
 }
 /*----------------------------------------------------------------------------*/
-/** Helper function calls callback and correctly disposes of batch structure.
+/** Helper function, calls callback and correctly destroys batch structure.
  *
  * @param[in] instance Batch structure to use.
@@ -423,5 +412,5 @@
 }
 /*----------------------------------------------------------------------------*/
-/** Helper function calls callback and correctly disposes of batch structure.
+/** Helper function calls callback and correctly destroys batch structure.
  *
  * @param[in] instance Batch structure to use.
