Changeset 7c3fb9b in mainline for uspace/drv/bus/usb
- Timestamp:
- 2018-05-17T08:29:01Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6ff23ff
- Parents:
- fac0ac7
- git-author:
- Jiri Svoboda <jiri@…> (2018-05-16 17:28:17)
- git-committer:
- Jiri Svoboda <jiri@…> (2018-05-17 08:29:01)
- Location:
- uspace/drv/bus/usb
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ehci/ehci_batch.c
rfac0ac7 r7c3fb9b 47 47 #include "ehci_bus.h" 48 48 49 /* The buffer pointer list in the qTD is long enough to support a maximum 49 /* 50 * The buffer pointer list in the qTD is long enough to support a maximum 50 51 * transfer size of 20K bytes. This case occurs when all five buffer pointers 51 52 * are used and the first offset is zero. A qTD handles a 16Kbyte buffer 52 * with any starting buffer alignment. EHCI specs p. 87 (pdf p. 97) */ 53 * with any starting buffer alignment. EHCI specs p. 87 (pdf p. 97) 54 */ 53 55 #define EHCI_TD_MAX_TRANSFER (16 * 1024) 54 56 … … 177 179 return false; 178 180 179 /* Now we may be sure that either the ED is inactive because of errors 180 * or all transfer descriptors completed successfully */ 181 /* 182 * Now we may be sure that either the ED is inactive because of errors 183 * or all transfer descriptors completed successfully 184 */ 181 185 182 186 /* Assume all data got through */ … … 192 196 ehci_batch->base.error = td_error(&ehci_batch->tds[i]); 193 197 if (ehci_batch->base.error == EOK) { 194 /* If the TD got all its data through, it will report 198 /* 199 * If the TD got all its data through, it will report 195 200 * 0 bytes remain, the sole exception is INPUT with 196 201 * data rounding flag (short), i.e. every INPUT. -
uspace/drv/bus/usb/ehci/ehci_rh.c
rfac0ac7 r7c3fb9b 72 72 instance->hub_descriptor.header.descriptor_type = USB_DESCTYPE_HUB; 73 73 instance->hub_descriptor.header.port_count = instance->port_count; 74 /* Bits 0,1 indicate power switching mode 74 /* 75 * Bits 0,1 indicate power switching mode 75 76 * Bit 2 indicates device type (compound device) 76 * Bits 3,4 indicate over-current protection mode */ 77 * Bits 3,4 indicate over-current protection mode 78 */ 77 79 instance->hub_descriptor.header.characteristics = 0 | 78 80 ((hcs & EHCI_CAPS_HCS_PPC_FLAG) ? 0x09 : 0x12) | … … 313 315 EHCI2USB(reg, USB_PORTSC_OC_CHANGE_FLAG, USB_HUB_PORT_STATUS_C_OC) | 314 316 (hub->reset_flag[port] ? USB_HUB_PORT_STATUS_C_RESET : 0)); 315 /* Note feature numbers for test and indicator feature do not 316 * correspond to the port status bit locations */ 317 /* 318 * Note feature numbers for test and indicator feature do not 319 * correspond to the port status bit locations 320 */ 317 321 usb_log_debug2("RH(%p-%u) port status: %" PRIx32 "(%" PRIx32 ")", hub, port, 318 322 status, reg); … … 340 344 } 341 345 usb_log_debug("RH(%p-%u): Reset complete", job->hub, job->port); 342 /* Handle port ownership, if the port is not enabled 343 * after reset it's a full speed device */ 346 /* 347 * Handle port ownership, if the port is not enabled 348 * after reset it's a full speed device 349 */ 344 350 if (!(EHCI_RD(job->hub->registers->portsc[job->port]) & 345 351 USB_PORTSC_ENABLED_FLAG)) { -
uspace/drv/bus/usb/ehci/hc.c
rfac0ac7 r7c3fb9b 395 395 usb_log_debug("HC(%p): Starting HW.", instance); 396 396 397 /* Turn off the HC if it's running, Reseting a running device is 398 * undefined */ 397 /* 398 * Turn off the HC if it's running, Reseting a running device is 399 * undefined 400 */ 399 401 if (!(EHCI_RD(instance->registers->usbsts) & USB_STS_HC_HALTED_FLAG)) { 400 402 /* disable all interrupts */ … … 487 489 return ret; 488 490 } 489 /* Specs say "Software must set queue head horizontal pointer T-bits to 491 /* 492 * Specs say "Software must set queue head horizontal pointer T-bits to 490 493 * a zero for queue heads in the asynchronous schedule" (4.4.0). 491 494 * So we must maintain circular buffer (all horizontal pointers 492 * have to be valid */ 495 * have to be valid 496 */ 493 497 endpoint_list_chain(&instance->async_list, &instance->async_list); 494 498 -
uspace/drv/bus/usb/ehci/hw_struct/queue_head.c
rfac0ac7 r7c3fb9b 61 61 EHCI_MEM32_WR(instance->alternate, LINK_POINTER_TERM); 62 62 if (ep == NULL) { 63 /* Mark as halted and list head, 64 * used by endpoint lists as dummy */ 63 /* 64 * Mark as halted and list head, 65 * used by endpoint lists as dummy 66 */ 65 67 EHCI_MEM32_WR(instance->ep_char, QH_EP_CHAR_H_FLAG); 66 68 EHCI_MEM32_WR(instance->status, QH_STATUS_HALTED_FLAG); … … 76 78 if (ep->device->speed != USB_SPEED_HIGH) 77 79 EHCI_MEM32_SET(instance->ep_char, QH_EP_CHAR_C_FLAG); 78 /* Let BULK and INT use queue head managed toggle, 79 * CONTROL needs special toggle handling anyway */ 80 /* 81 * Let BULK and INT use queue head managed toggle, 82 * CONTROL needs special toggle handling anyway 83 */ 80 84 EHCI_MEM32_SET(instance->ep_char, QH_EP_CHAR_DTC_FLAG); 81 85 } … … 96 100 EHCI_MEM32_WR(instance->ep_cap, ep_cap); 97 101 98 /* The rest of the fields are transfer working area, it should be ok to 99 * leave it NULL */ 102 /* 103 * The rest of the fields are transfer working area, it should be ok to 104 * leave it NULL 105 */ 100 106 } 101 107 -
uspace/drv/bus/usb/ehci/res.c
rfac0ac7 r7c3fb9b 80 80 usb_log_debug2("USBLEGSUP: %" PRIx32 ".", usblegsup); 81 81 82 /* Request control from firmware/BIOS by writing 1 to highest 83 * byte. (OS Control semaphore)*/ 82 /* 83 * Request control from firmware/BIOS by writing 1 to highest 84 * byte. (OS Control semaphore) 85 */ 84 86 usb_log_debug("Requesting OS control."); 85 87 ret = pci_config_space_write_8(parent_sess, … … 187 189 usb_log_debug2("Value of hcc params register: %x.", hcc_params); 188 190 189 /* Read value of EHCI Extended Capabilities Pointer 190 * position of EEC registers (points to PCI config space) */ 191 /* 192 * Read value of EHCI Extended Capabilities Pointer 193 * position of EEC registers (points to PCI config space) 194 */ 191 195 const uint32_t eecp = 192 196 (hcc_params >> EHCI_CAPS_HCC_EECP_SHIFT) & EHCI_CAPS_HCC_EECP_MASK; -
uspace/drv/bus/usb/ohci/hc.c
rfac0ac7 r7c3fb9b 400 400 usb_log_debug("Requesting OHCI control."); 401 401 if (OHCI_RD(instance->registers->revision) & R_LEGACY_FLAG) { 402 /* Turn off legacy emulation, it should be enough to zero 402 /* 403 * Turn off legacy emulation, it should be enough to zero 403 404 * the lowest bit, but it caused problems. Thus clear all 404 405 * except GateA20 (causes restart on some hw). … … 447 448 } 448 449 449 /* HC is in reset (hw startup) => no other driver 450 * maintain reset for at least the time specified in USB spec (50 ms)*/ 450 /* 451 * HC is in reset (hw startup) => no other driver 452 * maintain reset for at least the time specified in USB spec (50 ms) 453 */ 451 454 usb_log_debug("Host controller found in reset state."); 452 455 async_usleep(50000); -
uspace/drv/bus/usb/ohci/hw_struct/endpoint_descriptor.c
rfac0ac7 r7c3fb9b 69 69 70 70 if (ep == NULL) { 71 /* Mark as dead, used for dummy EDs at the beginning of 72 * endpoint lists. */ 71 /* 72 * Mark as dead, used for dummy EDs at the beginning of 73 * endpoint lists. 74 */ 73 75 OHCI_MEM32_WR(instance->status, ED_STATUS_K_FLAG); 74 76 return; -
uspace/drv/bus/usb/ohci/hw_struct/endpoint_descriptor.h
rfac0ac7 r7c3fb9b 51 51 * OHCI Endpoint Descriptor representation. 52 52 * 53 * See OHCI spec. Chapter 4.2, page 16 (pdf page 30) for details */ 53 * See OHCI spec. Chapter 4.2, page 16 (pdf page 30) for details 54 */ 54 55 typedef struct ed { 55 56 /** -
uspace/drv/bus/usb/ohci/hw_struct/transfer_descriptor.h
rfac0ac7 r7c3fb9b 44 44 #include "completion_codes.h" 45 45 46 /* OHCI TDs can handle up to 8KB buffers, however, it can use max 2 pages. 46 /* 47 * OHCI TDs can handle up to 8KB buffers, however, it can use max 2 pages. 47 48 * Using 4KB buffers guarantees the page count condition. 48 * (OHCI assumes 4KB pages) */ 49 * (OHCI assumes 4KB pages) 50 */ 49 51 #define OHCI_TD_MAX_TRANSFER (4 * 1024) 50 52 … … 76 78 /** 77 79 * Current buffer pointer. 78 * Phys address of the first byte to be transferred. */ 80 * Phys address of the first byte to be transferred. 81 */ 79 82 volatile uint32_t cbp; 80 83 … … 105 108 const int cc = (OHCI_MEM32_RD(instance->status) >> TD_STATUS_CC_SHIFT) & 106 109 TD_STATUS_CC_MASK; 107 /* This value is changed on transfer completion, 110 /* 111 * This value is changed on transfer completion, 108 112 * either to CC_NOERROR or and error code. 109 * See OHCI spec 4.3.1.3.5 p. 23 (pdf 37) */ 113 * See OHCI spec 4.3.1.3.5 p. 23 (pdf 37) 114 */ 110 115 if (cc != CC_NOACCESS1 && cc != CC_NOACCESS2) { 111 116 return true; -
uspace/drv/bus/usb/ohci/ohci_batch.c
rfac0ac7 r7c3fb9b 163 163 return false; 164 164 165 /* Now we may be sure that either the ED is inactive because of errors 166 * or all transfer descriptors completed successfully */ 165 /* 166 * Now we may be sure that either the ED is inactive because of errors 167 * or all transfer descriptors completed successfully 168 */ 167 169 168 170 /* Assume all data got through */ … … 178 180 usb_batch->error = td_error(ohci_batch->tds[i]); 179 181 if (usb_batch->error == EOK) { 180 /* If the TD got all its data through, it will report 182 /* 183 * If the TD got all its data through, it will report 181 184 * 0 bytes remain, the sole exception is INPUT with 182 185 * data rounding flag (short), i.e. every INPUT. … … 199 202 assert((ohci_ep->ed->td_head & ED_TDHEAD_HALTED_FLAG) != 0); 200 203 201 /* We don't care where the processing stopped, we just 204 /* 205 * We don't care where the processing stopped, we just 202 206 * need to make sure it's not using any of the TDs owned 203 207 * by the transfer. -
uspace/drv/bus/usb/uhci/hw_struct/queue_head.h
rfac0ac7 r7c3fb9b 78 78 static inline void qh_set_next_qh(qh_t *instance, qh_t *next) 79 79 { 80 /* Physical address has to be below 4GB, 80 /* 81 * Physical address has to be below 4GB, 81 82 * it is an UHCI limitation and malloc32 82 * should guarantee this */ 83 * should guarantee this 84 */ 83 85 const uint32_t pa = addr_to_phys(next); 84 86 if (pa) { … … 98 100 static inline void qh_set_element_td(qh_t *instance, td_t *td) 99 101 { 100 /* Physical address has to be below 4GB, 102 /* 103 * Physical address has to be below 4GB, 101 104 * it is an UHCI limitation and malloc32 102 * should guarantee this */ 105 * should guarantee this 106 */ 103 107 const uint32_t pa = addr_to_phys(td); 104 108 if (pa) { -
uspace/drv/bus/usb/uhci/hw_struct/transfer_descriptor.c
rfac0ac7 r7c3fb9b 127 127 return EIO; 128 128 129 /* CRC or timeout error, like device not present or bad data, 130 * it won't be reported unless err count reached zero */ 129 /* 130 * CRC or timeout error, like device not present or bad data, 131 * it won't be reported unless err count reached zero 132 */ 131 133 if ((instance->status & TD_STATUS_ERROR_CRC) != 0) 132 134 return EBADCHECKSUM; … … 144 146 return EIO; 145 147 146 /* Stall might represent err count reaching zero or stall response from 147 * the device. If err count reached zero, one of the above is reported*/ 148 /* 149 * Stall might represent err count reaching zero or stall response from 150 * the device. If err count reached zero, one of the above is reported 151 */ 148 152 if ((instance->status & TD_STATUS_ERROR_STALLED) != 0) 149 153 return ESTALL; -
uspace/drv/bus/usb/uhci/hw_struct/transfer_descriptor.h
rfac0ac7 r7c3fb9b 90 90 volatile uint32_t buffer_ptr; 91 91 92 /* According to UHCI design guide, there is 16 bytes of 92 /* 93 * According to UHCI design guide, there is 16 bytes of 93 94 * data available here. 94 95 * According to Linux kernel the hardware does not care, -
uspace/drv/bus/usb/uhci/main.c
rfac0ac7 r7c3fb9b 76 76 return ENOMEM; 77 77 78 /* See UHCI design guide page 45 for these values. 79 * Write all WC bits in USB legacy register */ 78 /* 79 * See UHCI design guide page 45 for these values. 80 * Write all WC bits in USB legacy register 81 */ 80 82 return pci_config_space_write_16(parent_sess, 0xc0, 0xaf00); 81 83 } -
uspace/drv/bus/usb/uhci/uhci_batch.c
rfac0ac7 r7c3fb9b 87 87 } 88 88 89 /* Prepares batch for commiting. 89 /* 90 * Prepares batch for committing. 90 91 * 91 92 * Determines the number of needed transfer descriptors (TDs). -
uspace/drv/bus/usb/uhci/uhci_rh.c
rfac0ac7 r7c3fb9b 153 153 while ((port_status = pio_read_16(port)) & STATUS_IN_RESET) 154 154 ; 155 /* PIO delay, should not be longer than 3ms as the device might 156 * enter suspend state. */ 155 /* 156 * PIO delay, should not be longer than 3ms as the device might 157 * enter suspend state. 158 */ 157 159 udelay(10); 158 /* Drop ConnectionChange as some UHCI hw 159 * sets this bit after reset, that is incorrect */ 160 /* 161 * Drop ConnectionChange as some UHCI hw 162 * sets this bit after reset, that is incorrect 163 */ 160 164 port_status &= ~STATUS_WC_BITS; 161 165 pio_write_16(port, port_status | STATUS_ENABLED | STATUS_CONNECTED_CHANGED); … … 376 380 RH_DEBUG(hub, port, "Set port change flag (status %" PRIx16 377 381 ")", status); 378 /* These are voluntary and don't have to be set 379 * there is no way we could do it on UHCI anyway */ 382 /* 383 * These are voluntary and don't have to be set 384 * there is no way we could do it on UHCI anyway 385 */ 380 386 break; 381 387 default: … … 459 465 CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_CLEAR_FEATURE), 460 466 .name = "ClearHubFeature", 461 /* Hub features are overcurrent and supply good, 462 * this request may only clear changes that we never report*/ 467 /* 468 * Hub features are overcurrent and supply good, 469 * this request may only clear changes that we never report 470 */ 463 471 .callback = req_nop, 464 472 }, … … 471 479 CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_GET_STATUS), 472 480 .name = "GetHubStatus", 473 /* UHCI can't report OC condition or, 474 * lose power source */ 481 /* 482 * UHCI can't report OC condition or, 483 * lose power source 484 */ 475 485 .callback = virthub_base_get_null_status, 476 486 }, … … 483 493 CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_SET_FEATURE), 484 494 .name = "SetHubFeature", 485 /* Hub features are overcurrent and supply good, 486 * this request may only set changes that we never report*/ 495 /* 496 * Hub features are overcurrent and supply good, 497 * this request may only set changes that we never report 498 */ 487 499 .callback = req_nop, 488 500 }, -
uspace/drv/bus/usb/usbhub/port.c
rfac0ac7 r7c3fb9b 236 236 const bool overcurrent = !!(status & USB_HUB_PORT_STATUS_OC); 237 237 238 /* According to the USB specs: 238 /* 239 * According to the USB specs: 239 240 * 11.13.5 Over-current Reporting and Recovery 240 241 * Hub device is responsible for putting port in power off 241 242 * mode. USB system software is responsible for powering port 242 * back on when the over-current condition is gone */ 243 * back on when the over-current condition is gone 244 */ 243 245 244 246 usb_port_disabled(&port->base, &remove_device); -
uspace/drv/bus/usb/usbhub/usbhub.c
rfac0ac7 r7c3fb9b 460 460 } 461 461 462 /* Set configuration. Use the configuration that was in 463 * usb_device->descriptors.configuration i.e. The first one. */ 462 /* 463 * Set configuration. Use the configuration that was in 464 * usb_device->descriptors.configuration i.e. The first one. 465 */ 464 466 errno_t opResult = usb_request_set_configuration( 465 467 usb_device_get_default_pipe(usb_device), … … 593 595 assert(status); 594 596 595 /* USB hub specific GET_PORT_STATUS request. See USB Spec 11.16.2.6 597 /* 598 * USB hub specific GET_PORT_STATUS request. See USB Spec 11.16.2.6 596 599 * Generic GET_STATUS request cannot be used because of the difference 597 * in status data size (2B vs. 4B)*/ 600 * in status data size (2B vs. 4B) 601 */ 598 602 const usb_device_request_setup_packet_t request = { 599 603 .request_type = USB_HUB_REQ_TYPE_GET_PORT_STATUS, … … 635 639 usb_hub_status_t status; 636 640 size_t rcvd_size; 637 /* NOTE: We can't use standard USB GET_STATUS request, because 638 * hubs reply is 4byte instead of 2 */ 641 /* 642 * NOTE: We can't use standard USB GET_STATUS request, because 643 * hubs reply is 4byte instead of 2 644 */ 639 645 const errno_t opResult = usb_pipe_control_read(control_pipe, 640 646 &get_hub_status_request, sizeof(get_hub_status_request), … … 666 672 667 673 if (status & USB_HUB_STATUS_C_LOCAL_POWER) { 668 /* NOTE: Handling this is more complicated. 674 /* 675 * NOTE: Handling this is more complicated. 669 676 * If the transition is from bus power to local power, all 670 677 * is good and we may signal the parent hub that we don't -
uspace/drv/bus/usb/usbmid/explore.c
rfac0ac7 r7c3fb9b 85 85 usb_dp_get_nested_descriptor(&parser, &data, config_descriptor); 86 86 87 /* Walk all descriptors nested in the current configuration decriptor; 88 * i.e. all interface descriptors. */ 87 /* 88 * Walk all descriptors nested in the current configuration decriptor; 89 * i.e. all interface descriptors. 90 */ 89 91 for (; interface_ptr != NULL; 90 92 interface_ptr = usb_dp_get_sibling_descriptor( … … 99 101 /* Skip alternate interfaces. */ 100 102 if (interface_in_list(list, interface->interface_number)) { 101 /* TODO: add the alternatives and create match ids 102 * for them. */ 103 /* 104 * TODO: add the alternatives and create match ids 105 * for them. 106 */ 103 107 continue; 104 108 } -
uspace/drv/bus/usb/xhci/commands.c
rfac0ac7 r7c3fb9b 358 358 359 359 if (code == XHCI_TRBC_COMMAND_RING_STOPPED) { 360 /* This can either mean that the ring is being stopped, or 360 /* 361 * This can either mean that the ring is being stopped, or 361 362 * a command was aborted. In either way, wake threads waiting 362 363 * on stopped_cv. … … 671 672 672 673 if (XHCI_REG_RD(hc->op_regs, XHCI_OP_CRR)) { 673 /* 4.6.1.2, implementation note 674 /* 675 * 4.6.1.2, implementation note 674 676 * Assume there are larger problems with HC and 675 677 * reset it. … … 720 722 &cmd->_header.completed_mtx, XHCI_COMMAND_TIMEOUT); 721 723 722 /* The waiting timed out. Current command (not necessarily 724 /* 725 * The waiting timed out. Current command (not necessarily 723 726 * ours) is probably blocked. 724 727 */ -
uspace/drv/bus/usb/xhci/hc.c
rfac0ac7 r7c3fb9b 534 534 joinable_fibril_join(hc->event_worker); 535 535 536 /* Then, disconnect all roothub devices, which shall trigger 537 * disconnection of everything */ 536 /* 537 * Then, disconnect all roothub devices, which shall trigger 538 * disconnection of everything 539 */ 538 540 xhci_rh_stop(&hc->rh); 539 541 } … … 576 578 XHCI_REG_WR(hc->rt_regs->ir, XHCI_INTR_IP, 1); 577 579 578 /* interrupt handler expects status from irq_commands, which is 579 * in xhci order. */ 580 /* 581 * interrupt handler expects status from irq_commands, which is 582 * in xhci order. 583 */ 580 584 *status = host2xhci(32, *status); 581 585 } … … 873 877 xhci_endpoint_t *ep0 = xhci_endpoint_get(dev->base.endpoints[0]); 874 878 875 /* Although we have the precise PSIV value on devices of tier 1, 876 * we have to rely on reverse mapping on others. */ 879 /* 880 * Although we have the precise PSIV value on devices of tier 1, 881 * we have to rely on reverse mapping on others. 882 */ 877 883 if (!usb_speed_to_psiv[dev->base.speed]) { 878 884 usb_log_error("Device reported an USB speed (%s) that cannot be mapped " -
uspace/drv/bus/usb/xhci/hw_struct/regs.h
rfac0ac7 r7c3fb9b 368 368 ioport32_t dnctrl; 369 369 370 /* 3 2 1 0 370 /* 371 * 3 2 1 0 371 372 * 3:0 - CRR CA CS RCS 372 373 * 64:6 - Command Ring Pointer -
uspace/drv/bus/usb/xhci/rh.c
rfac0ac7 r7c3fb9b 291 291 joinable_fibril_start(rh->event_worker); 292 292 293 /* The reset changed status of all ports, and SW originated reason does 293 /* 294 * The reset changed status of all ports, and SW originated reason does 294 295 * not cause an interrupt. 295 296 */
Note:
See TracChangeset
for help on using the changeset viewer.