Changes in uspace/drv/uhci-hcd/batch.c [06c552c:910ca3f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-hcd/batch.c
r06c552c r910ca3f 30 30 */ 31 31 /** @file 32 * @brief UHCI driver USB trans actionstructure32 * @brief UHCI driver USB transfer structure 33 33 */ 34 34 #include <errno.h> … … 48 48 qh_t *qh; 49 49 td_t *tds; 50 size_t t ransfers;50 size_t td_count; 51 51 } uhci_batch_t; 52 52 … … 61 61 * 62 62 * @param[in] fun DDF function to pass to callback. 63 * @param[in] target Device and endpoint target of the transaction. 64 * @param[in] transfer_type Interrupt, Control or Bulk. 65 * @param[in] max_packet_size maximum allowed size of data transfers. 66 * @param[in] speed Speed of the transaction. 63 * @param[in] ep Communication target 67 64 * @param[in] buffer Data source/destination. 68 65 * @param[in] size Size of the buffer. 69 66 * @param[in] setup_buffer Setup data source (if not NULL) 70 67 * @param[in] setup_size Size of setup_buffer (should be always 8) 71 * @param[in] func_in function to call on inbound trans actioncompletion72 * @param[in] func_out function to call on outbound trans actioncompletion68 * @param[in] func_in function to call on inbound transfer completion 69 * @param[in] func_out function to call on outbound transfer completion 73 70 * @param[in] arg additional parameter to func_in or func_out 74 * @param[in] ep Pointer to endpoint toggle management structure.75 71 * @return Valid pointer if all substructures were successfully created, 76 72 * NULL otherwise. 77 73 * 78 * Determines the number of needed transfer s (TDs). Prepares a transport buffer79 * (that is accessible by the hardware). Initializes parameters needed for the80 * transactionand callback.74 * Determines the number of needed transfer descriptors (TDs). 75 * Prepares a transport buffer (that is accessible by the hardware). 76 * Initializes parameters needed for the transfer and callback. 81 77 */ 82 78 usb_transfer_batch_t * batch_get(ddf_fun_t *fun, endpoint_t *ep, … … 103 99 usb_target_t target = 104 100 { .address = ep->address, .endpoint = ep->endpoint }; 105 usb_transfer_batch_init(instance, target, ep->transfer_type, ep->speed,106 ep->max_packet_size,buffer, NULL, buffer_size, NULL, setup_size,107 func_in, func_out, arg, fun, ep,NULL);101 usb_transfer_batch_init(instance, ep, 102 buffer, NULL, buffer_size, NULL, setup_size, 103 func_in, func_out, arg, fun, NULL); 108 104 109 105 … … 113 109 instance->private_data = data; 114 110 115 data->t ransfers=111 data->td_count = 116 112 (buffer_size + ep->max_packet_size - 1) / ep->max_packet_size; 117 113 if (ep->transfer_type == USB_TRANSFER_CONTROL) { 118 data->t ransfers+= 2;119 } 120 121 data->tds = malloc32(sizeof(td_t) * data->t ransfers);114 data->td_count += 2; 115 } 116 117 data->tds = malloc32(sizeof(td_t) * data->td_count); 122 118 CHECK_NULL_DISPOSE_RETURN( 123 119 data->tds, "Failed to allocate transfer descriptors.\n"); 124 bzero(data->tds, sizeof(td_t) * data->t ransfers);120 bzero(data->tds, sizeof(td_t) * data->td_count); 125 121 126 122 data->qh = malloc32(sizeof(qh_t)); … … 131 127 132 128 if (buffer_size > 0) { 133 instance-> transport_buffer = malloc32(buffer_size);134 CHECK_NULL_DISPOSE_RETURN(instance-> transport_buffer,129 instance->data_buffer = malloc32(buffer_size); 130 CHECK_NULL_DISPOSE_RETURN(instance->data_buffer, 135 131 "Failed to allocate device accessible buffer.\n"); 136 132 } … … 154 150 * 155 151 * Walk all TDs. Stop with false if there is an active one (it is to be 156 * processed). Stop with true if an error is found. Return true if the last T S152 * processed). Stop with true if an error is found. Return true if the last TD 157 153 * is reached. 158 154 */ … … 164 160 165 161 usb_log_debug2("Batch(%p) checking %d transfer(s) for completion.\n", 166 instance, data->t ransfers);162 instance, data->td_count); 167 163 instance->transfered_size = 0; 168 164 size_t i = 0; 169 for (;i < data->t ransfers; ++i) {165 for (;i < data->td_count; ++i) { 170 166 if (td_is_active(&data->tds[i])) { 171 167 return false; … … 177 173 instance, i, data->tds[i].status); 178 174 td_print_status(&data->tds[i]); 175 179 176 assert(instance->ep != NULL); 180 181 177 endpoint_toggle_set(instance->ep, 182 178 td_toggle(&data->tds[i])); … … 195 191 } 196 192 /*----------------------------------------------------------------------------*/ 197 /** Prepares control write trans action.198 * 199 * @param[in] instance Batch structure to use. 200 * 201 * Uses gener circontrol function with pids OUT and IN.193 /** Prepares control write transfer. 194 * 195 * @param[in] instance Batch structure to use. 196 * 197 * Uses generic control function with pids OUT and IN. 202 198 */ 203 199 void batch_control_write(usb_transfer_batch_t *instance) … … 205 201 assert(instance); 206 202 /* We are data out, we are supposed to provide data */ 207 memcpy(instance->transport_buffer, instance->buffer, 208 instance->buffer_size); 203 memcpy(instance->data_buffer, instance->buffer, instance->buffer_size); 209 204 batch_control(instance, USB_PID_OUT, USB_PID_IN); 210 205 instance->next_step = batch_call_out_and_dispose; … … 212 207 } 213 208 /*----------------------------------------------------------------------------*/ 214 /** Prepares control read trans action.209 /** Prepares control read transfer. 215 210 * 216 211 * @param[in] instance Batch structure to use. … … 226 221 } 227 222 /*----------------------------------------------------------------------------*/ 228 /** Prepare interrupt in trans action.229 * 230 * @param[in] instance Batch structure to use. 231 * 232 * Data trans actionwith PID_IN.223 /** Prepare interrupt in transfer. 224 * 225 * @param[in] instance Batch structure to use. 226 * 227 * Data transfer with PID_IN. 233 228 */ 234 229 void batch_interrupt_in(usb_transfer_batch_t *instance) 235 230 { 236 231 assert(instance); 237 instance->direction = USB_DIRECTION_IN;238 232 batch_data(instance, USB_PID_IN); 239 233 instance->next_step = batch_call_in_and_dispose; … … 241 235 } 242 236 /*----------------------------------------------------------------------------*/ 243 /** Prepare interrupt out trans action.244 * 245 * @param[in] instance Batch structure to use. 246 * 247 * Data trans actionwith PID_OUT.237 /** Prepare interrupt out transfer. 238 * 239 * @param[in] instance Batch structure to use. 240 * 241 * Data transfer with PID_OUT. 248 242 */ 249 243 void batch_interrupt_out(usb_transfer_batch_t *instance) 250 244 { 251 245 assert(instance); 252 instance->direction = USB_DIRECTION_OUT;253 246 /* We are data out, we are supposed to provide data */ 254 memcpy(instance->transport_buffer, instance->buffer, 255 instance->buffer_size); 247 memcpy(instance->data_buffer, instance->buffer, instance->buffer_size); 256 248 batch_data(instance, USB_PID_OUT); 257 249 instance->next_step = batch_call_out_and_dispose; … … 259 251 } 260 252 /*----------------------------------------------------------------------------*/ 261 /** Prepare bulk in trans action.262 * 263 * @param[in] instance Batch structure to use. 264 * 265 * Data trans actionwith PID_IN.253 /** Prepare bulk in transfer. 254 * 255 * @param[in] instance Batch structure to use. 256 * 257 * Data transfer with PID_IN. 266 258 */ 267 259 void batch_bulk_in(usb_transfer_batch_t *instance) … … 269 261 assert(instance); 270 262 batch_data(instance, USB_PID_IN); 271 instance->direction = USB_DIRECTION_IN;272 263 instance->next_step = batch_call_in_and_dispose; 273 264 usb_log_debug("Batch(%p) BULK IN initialized.\n", instance); 274 265 } 275 266 /*----------------------------------------------------------------------------*/ 276 /** Prepare bulk out trans action.277 * 278 * @param[in] instance Batch structure to use. 279 * 280 * Data trans actionwith PID_OUT.267 /** Prepare bulk out transfer. 268 * 269 * @param[in] instance Batch structure to use. 270 * 271 * Data transfer with PID_OUT. 281 272 */ 282 273 void batch_bulk_out(usb_transfer_batch_t *instance) 283 274 { 284 275 assert(instance); 285 instance->direction = USB_DIRECTION_OUT;286 276 /* We are data out, we are supposed to provide data */ 287 memcpy(instance->transport_buffer, instance->buffer, 288 instance->buffer_size); 277 memcpy(instance->data_buffer, instance->buffer, instance->buffer_size); 289 278 batch_data(instance, USB_PID_OUT); 290 279 instance->next_step = batch_call_out_and_dispose; … … 292 281 } 293 282 /*----------------------------------------------------------------------------*/ 294 /** Prepare generic data trans action295 * 296 * @param[in] instance Batch structure to use. 297 * @param[in] pid Pid to use for data trans fers.298 * 299 * Packets with alternating toggle bit and supplied pid value.283 /** Prepare generic data transfer 284 * 285 * @param[in] instance Batch structure to use. 286 * @param[in] pid Pid to use for data transactions. 287 * 288 * Transactions with alternating toggle bit and supplied pid value. 300 289 * The last transfer is marked with IOC flag. 301 290 */ … … 306 295 assert(data); 307 296 308 const bool low_speed = instance-> speed == USB_SPEED_LOW;297 const bool low_speed = instance->ep->speed == USB_SPEED_LOW; 309 298 int toggle = endpoint_toggle_get(instance->ep); 310 299 assert(toggle == 0 || toggle == 1); 311 300 312 size_t t ransfer= 0;301 size_t td = 0; 313 302 size_t remain_size = instance->buffer_size; 303 char *buffer = instance->data_buffer; 314 304 while (remain_size > 0) { 315 char *trans_data =316 instance->transport_buffer + instance->buffer_size317 - remain_size;318 319 305 const size_t packet_size = 320 (instance->max_packet_size > remain_size) ? 321 remain_size : instance->max_packet_size; 322 323 td_t *next_transfer = (transfer + 1 < data->transfers) 324 ? &data->tds[transfer + 1] : NULL; 325 326 assert(transfer < data->transfers); 306 (instance->ep->max_packet_size > remain_size) ? 307 remain_size : instance->ep->max_packet_size; 308 309 td_t *next_td = (td + 1 < data->td_count) 310 ? &data->tds[td + 1] : NULL; 311 312 313 usb_target_t target = 314 { instance->ep->address, instance->ep->endpoint }; 315 316 assert(td < data->td_count); 317 td_init( 318 &data->tds[td], DEFAULT_ERROR_COUNT, packet_size, 319 toggle, false, low_speed, target, pid, buffer, next_td); 320 321 ++td; 322 toggle = 1 - toggle; 323 buffer += packet_size; 327 324 assert(packet_size <= remain_size); 328 329 td_init(330 &data->tds[transfer], DEFAULT_ERROR_COUNT, packet_size,331 toggle, false, low_speed, instance->target, pid, trans_data,332 next_transfer);333 334 335 toggle = 1 - toggle;336 325 remain_size -= packet_size; 337 ++transfer; 338 } 339 td_set_ioc(&data->tds[transfer - 1]); 326 } 327 td_set_ioc(&data->tds[td - 1]); 340 328 endpoint_toggle_set(instance->ep, toggle); 341 329 } 342 330 /*----------------------------------------------------------------------------*/ 343 /** Prepare generic control trans action344 * 345 * @param[in] instance Batch structure to use. 346 * @param[in] data_stage Pid to use for data t ransfers.347 * @param[in] status_stage Pid to use for data t ransfers.331 /** Prepare generic control transfer 332 * 333 * @param[in] instance Batch structure to use. 334 * @param[in] data_stage Pid to use for data tds. 335 * @param[in] status_stage Pid to use for data tds. 348 336 * 349 337 * Setup stage with toggle 0 and USB_PID_SETUP. … … 358 346 uhci_batch_t *data = instance->private_data; 359 347 assert(data); 360 assert(data->transfers >= 2); 361 362 const bool low_speed = instance->speed == USB_SPEED_LOW; 363 int toggle = 0; 348 assert(data->td_count >= 2); 349 350 const bool low_speed = instance->ep->speed == USB_SPEED_LOW; 351 const usb_target_t target = 352 { instance->ep->address, instance->ep->endpoint }; 353 364 354 /* setup stage */ 365 355 td_init( 366 data->tds, DEFAULT_ERROR_COUNT, instance->setup_size, toggle, false,367 low_speed, instance->target, USB_PID_SETUP, instance->setup_buffer,356 data->tds, DEFAULT_ERROR_COUNT, instance->setup_size, 0, false, 357 low_speed, target, USB_PID_SETUP, instance->setup_buffer, 368 358 &data->tds[1]); 369 359 370 360 /* data stage */ 371 size_t transfer = 1; 361 size_t td = 1; 362 unsigned toggle = 1; 372 363 size_t remain_size = instance->buffer_size; 364 char *buffer = instance->data_buffer; 373 365 while (remain_size > 0) { 374 char *control_data = 375 instance->transport_buffer + instance->buffer_size 376 - remain_size; 377 366 const size_t packet_size = 367 (instance->ep->max_packet_size > remain_size) ? 368 remain_size : instance->ep->max_packet_size; 369 370 td_init( 371 &data->tds[td], DEFAULT_ERROR_COUNT, packet_size, 372 toggle, false, low_speed, target, data_stage, 373 buffer, &data->tds[td + 1]); 374 375 ++td; 378 376 toggle = 1 - toggle; 379 380 const size_t packet_size = 381 (instance->max_packet_size > remain_size) ? 382 remain_size : instance->max_packet_size; 383 384 td_init( 385 &data->tds[transfer], DEFAULT_ERROR_COUNT, packet_size, 386 toggle, false, low_speed, instance->target, data_stage, 387 control_data, &data->tds[transfer + 1]); 388 389 ++transfer; 390 assert(transfer < data->transfers); 377 buffer += packet_size; 378 assert(td < data->td_count); 391 379 assert(packet_size <= remain_size); 392 380 remain_size -= packet_size; … … 394 382 395 383 /* status stage */ 396 assert(t ransfer == data->transfers- 1);384 assert(td == data->td_count - 1); 397 385 398 386 td_init( 399 &data->tds[t ransfer], DEFAULT_ERROR_COUNT, 0, 1, false, low_speed,400 instance->target, status_stage, NULL, NULL);401 td_set_ioc(&data->tds[t ransfer]);387 &data->tds[td], DEFAULT_ERROR_COUNT, 0, 1, false, low_speed, 388 target, status_stage, NULL, NULL); 389 td_set_ioc(&data->tds[td]); 402 390 403 391 usb_log_debug2("Control last TD status: %x.\n", 404 data->tds[t ransfer].status);392 data->tds[td].status); 405 393 } 406 394 /*----------------------------------------------------------------------------*/ … … 413 401 } 414 402 /*----------------------------------------------------------------------------*/ 415 /** Helper function calls callback and correctly disposes ofbatch structure.403 /** Helper function, calls callback and correctly destroys batch structure. 416 404 * 417 405 * @param[in] instance Batch structure to use. … … 424 412 } 425 413 /*----------------------------------------------------------------------------*/ 426 /** Helper function calls callback and correctly d isposes ofbatch structure.414 /** Helper function calls callback and correctly destroys batch structure. 427 415 * 428 416 * @param[in] instance Batch structure to use. … … 449 437 free32(data->qh); 450 438 free32(instance->setup_buffer); 451 free32(instance-> transport_buffer);439 free32(instance->data_buffer); 452 440 free(data); 453 441 free(instance);
Note:
See TracChangeset
for help on using the changeset viewer.