Changeset 3bacee1 in mainline for uspace/drv/bus/usb/xhci/transfers.c
- Timestamp:
- 2018-04-12T16:27:17Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3cf22f9
- Parents:
- 76d0981d
- git-author:
- Jiri Svoboda <jiri@…> (2018-04-11 19:25:33)
- git-committer:
- Jiri Svoboda <jiri@…> (2018-04-12 16:27:17)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/transfers.c
r76d0981d r3bacee1 51 51 * See Table 7 of xHCI specification. 52 52 */ 53 static inline stage_dir_flag_t get_status_direction_flag(xhci_trb_t *trb,54 53 static inline stage_dir_flag_t get_status_direction_flag(xhci_trb_t *trb, 54 uint8_t bmRequestType, uint16_t wLength) 55 55 { 56 56 /* See Table 7 of xHCI specification */ 57 return SETUP_REQUEST_TYPE_IS_DEVICE_TO_HOST(bmRequestType) && (wLength > 0) 58 ? STAGE_OUT59 :STAGE_IN;57 return SETUP_REQUEST_TYPE_IS_DEVICE_TO_HOST(bmRequestType) && (wLength > 0) ? 58 STAGE_OUT : 59 STAGE_IN; 60 60 } 61 61 … … 69 69 * See Table 8 of xHCI specification. 70 70 */ 71 static inline data_stage_type_t get_transfer_type(xhci_trb_t *trb, uint8_t72 71 static inline data_stage_type_t get_transfer_type(xhci_trb_t *trb, uint8_t 72 bmRequestType, uint16_t wLength) 73 73 { 74 74 if (wLength == 0) … … 76 76 77 77 /* See Table 7 of xHCI specification */ 78 return SETUP_REQUEST_TYPE_IS_DEVICE_TO_HOST(bmRequestType) 79 ? DATA_STAGE_IN80 :DATA_STAGE_NO;78 return SETUP_REQUEST_TYPE_IS_DEVICE_TO_HOST(bmRequestType) ? 79 DATA_STAGE_IN : 80 DATA_STAGE_NO; 81 81 } 82 82 … … 86 86 87 87 return request_type == USB_REQUEST_TYPE_STANDARD && 88 (setup->request == USB_DEVREQ_SET_CONFIGURATION89 ||setup->request == USB_DEVREQ_SET_INTERFACE);88 (setup->request == USB_DEVREQ_SET_CONFIGURATION || 89 setup->request == USB_DEVREQ_SET_INTERFACE); 90 90 } 91 91 … … 95 95 * Bus callback. 96 96 */ 97 usb_transfer_batch_t * xhci_transfer_create(endpoint_t*ep)97 usb_transfer_batch_t *xhci_transfer_create(endpoint_t *ep) 98 98 { 99 99 xhci_transfer_t *transfer = calloc(1, sizeof(xhci_transfer_t)); … … 108 108 * Destroy a xHCI transfer. 109 109 */ 110 void xhci_transfer_destroy(usb_transfer_batch_t *batch)110 void xhci_transfer_destroy(usb_transfer_batch_t *batch) 111 111 { 112 112 xhci_transfer_t *transfer = xhci_transfer_from_batch(batch); … … 137 137 138 138 const size_t chunk_mask = dma_policy_chunk_mask(ts->buf.policy); 139 ts->chunk_size = (chunk_mask > MAX_CHUNK_SIZE + 1) 140 ?MAX_CHUNK_SIZE : (chunk_mask + 1);139 ts->chunk_size = (chunk_mask > MAX_CHUNK_SIZE + 1) ? 140 MAX_CHUNK_SIZE : (chunk_mask + 1); 141 141 142 142 ts->remaining = transfer->batch.size; … … 183 183 } 184 184 185 static errno_t schedule_control(xhci_hc_t * hc, xhci_transfer_t*transfer)185 static errno_t schedule_control(xhci_hc_t *hc, xhci_transfer_t *transfer) 186 186 { 187 187 usb_transfer_batch_t *batch = &transfer->batch; 188 188 xhci_endpoint_t *xhci_ep = xhci_endpoint_get(transfer->batch.ep); 189 189 190 usb_device_request_setup_packet_t *setup = &batch->setup.packet;190 usb_device_request_setup_packet_t *setup = &batch->setup.packet; 191 191 192 192 trb_splitter_t splitter; … … 210 210 get_transfer_type(trb_setup, setup->request_type, setup->length)); 211 211 212 stage_dir_flag_t stage_dir = (transfer->batch.dir == USB_DIRECTION_IN) 213 ?STAGE_IN : STAGE_OUT;212 stage_dir_flag_t stage_dir = (transfer->batch.dir == USB_DIRECTION_IN) ? 213 STAGE_IN : STAGE_OUT; 214 214 215 215 /* Data stage - first TRB is special */ … … 243 243 } 244 244 245 static errno_t schedule_bulk_intr(xhci_hc_t *hc, xhci_transfer_t *transfer)246 { 247 xhci_trb_ring_t * 245 static errno_t schedule_bulk_intr(xhci_hc_t *hc, xhci_transfer_t *transfer) 246 { 247 xhci_trb_ring_t *const ring = get_ring(transfer); 248 248 if (!ring) 249 249 return EINVAL; … … 266 266 /* Set the interrupt bit for last TRB */ 267 267 TRB_CTRL_SET_IOC(trbs[trbs_used - 1], 1); 268 } 269 else { 268 } else { 270 269 /* Clear the chain bit on the last TRB */ 271 270 TRB_CTRL_SET_CHAIN(trbs[trbs_used - 1], 1); … … 280 279 281 280 return xhci_trb_ring_enqueue_multiple(ring, trbs, trbs_used, 282 283 } 284 285 static int schedule_isochronous(xhci_transfer_t *transfer)281 &transfer->interrupt_trb_phys); 282 } 283 284 static int schedule_isochronous(xhci_transfer_t *transfer) 286 285 { 287 286 endpoint_t *ep = transfer->batch.ep; 288 287 289 return ep->direction == USB_DIRECTION_OUT 290 ? isoch_schedule_out(transfer)291 :isoch_schedule_in(transfer);292 } 293 294 errno_t xhci_handle_transfer_event(xhci_hc_t * hc, xhci_trb_t*trb)288 return ep->direction == USB_DIRECTION_OUT ? 289 isoch_schedule_out(transfer) : 290 isoch_schedule_in(transfer); 291 } 292 293 errno_t xhci_handle_transfer_event(xhci_hc_t *hc, xhci_trb_t *trb) 295 294 { 296 295 uintptr_t addr = trb->parameter; … … 327 326 transfer->interrupt_trb_phys); 328 327 batch = &transfer->batch; 329 } 330 else { 328 } else { 331 329 xhci_trb_ring_update_dequeue(&ep->ring, addr); 332 330 … … 354 352 const xhci_trb_completion_code_t completion_code = TRB_COMPLETION_CODE(*trb); 355 353 switch (completion_code) { 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 354 case XHCI_TRBC_SHORT_PACKET: 355 case XHCI_TRBC_SUCCESS: 356 batch->error = EOK; 357 batch->transferred_size = batch->size - TRB_TRANSFER_LENGTH(*trb); 358 break; 359 360 case XHCI_TRBC_DATA_BUFFER_ERROR: 361 usb_log_warning("Transfer ended with data buffer error."); 362 batch->error = EAGAIN; 363 batch->transferred_size = 0; 364 break; 365 366 case XHCI_TRBC_BABBLE_DETECTED_ERROR: 367 usb_log_warning("Babble detected during the transfer."); 368 batch->error = EAGAIN; 369 batch->transferred_size = 0; 370 break; 371 372 case XHCI_TRBC_USB_TRANSACTION_ERROR: 373 usb_log_warning("USB Transaction error."); 374 batch->error = EAGAIN; 375 batch->transferred_size = 0; 376 break; 377 378 case XHCI_TRBC_TRB_ERROR: 379 usb_log_error("Invalid transfer parameters."); 380 batch->error = EINVAL; 381 batch->transferred_size = 0; 382 break; 383 384 case XHCI_TRBC_STALL_ERROR: 385 usb_log_warning("Stall condition detected."); 386 batch->error = ESTALL; 387 batch->transferred_size = 0; 388 break; 389 390 case XHCI_TRBC_SPLIT_TRANSACTION_ERROR: 391 usb_log_error("Split transcation error detected."); 392 batch->error = EAGAIN; 393 batch->transferred_size = 0; 394 break; 395 396 default: 397 usb_log_warning("Transfer not successfull: %u", completion_code); 398 batch->error = EIO; 401 399 } 402 400 … … 456 454 * the Reset Endpoint command. 457 455 */ 458 if (batch->ep->transfer_type == USB_TRANSFER_CONTROL 459 &&batch->dir == USB_DIRECTION_OUT) {456 if (batch->ep->transfer_type == USB_TRANSFER_CONTROL && 457 batch->dir == USB_DIRECTION_OUT) { 460 458 const usb_device_request_setup_packet_t *request = &batch->setup.packet; 461 if (request->request == USB_DEVREQ_CLEAR_FEATURE 462 && request->request_type == USB_REQUEST_RECIPIENT_ENDPOINT463 &&request->value == USB_FEATURE_ENDPOINT_HALT) {459 if (request->request == USB_DEVREQ_CLEAR_FEATURE && 460 request->request_type == USB_REQUEST_RECIPIENT_ENDPOINT && 461 request->value == USB_FEATURE_ENDPOINT_HALT) { 464 462 const uint16_t index = uint16_usb2host(request->index); 465 463 const usb_endpoint_t ep_num = index & 0xf; 466 const usb_direction_t dir = (index >> 7) 467 ? USB_DIRECTION_IN468 :USB_DIRECTION_OUT;464 const usb_direction_t dir = (index >> 7) ? 465 USB_DIRECTION_IN : 466 USB_DIRECTION_OUT; 469 467 endpoint_t *halted_ep = bus_find_endpoint(&xhci_dev->base, ep_num, dir); 470 468 if (halted_ep) { … … 488 486 } else { 489 487 usb_log_warning("Device(%u): Resetting unregistered endpoint" 490 491 488 " %u %s.", xhci_dev->base.address, ep_num, 489 usb_str_direction(dir)); 492 490 } 493 491 }
Note:
See TracChangeset
for help on using the changeset viewer.