Changeset 306a36d in mainline
- Timestamp:
- 2017-11-19T23:43:31Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ff14aede
- Parents:
- e76c0ea
- Location:
- uspace
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ehci/hc.c
re76c0ea r306a36d 238 238 assert(ep); 239 239 ehci_endpoint_t *ehci_ep = ehci_endpoint_get(ep); 240 usb_log_debug("HC(%p) dequeue EP( %d:%d:%s:%s)\n", instance,241 ep-> device->address, ep->endpoint,240 usb_log_debug("HC(%p) dequeue EP(?:%d:%s:%s)\n", instance, 241 ep->endpoint, 242 242 usb_str_transfer_type_short(ep->transfer_type), 243 243 usb_str_direction(ep->direction)); -
uspace/drv/bus/usb/xhci/bus.c
re76c0ea r306a36d 50 50 51 51 52 /* FIXME Are these really static? Older HCs fetch it from descriptor. */ 53 /* FIXME Add USB3 options, if applicable. */ 54 static const usb_endpoint_desc_t ep0_desc = { 52 static const usb_endpoint_desc_t ep0_initial_desc = { 55 53 .endpoint_no = 0, 56 54 .direction = USB_DIRECTION_BOTH, … … 97 95 xhci_endpoint_t *ep0 = xhci_endpoint_get(ep0_base); 98 96 99 if ((err = prepare_endpoint(ep0, &ep0_ desc)))97 if ((err = prepare_endpoint(ep0, &ep0_initial_desc))) 100 98 goto err_ep; 101 99 … … 124 122 } 125 123 124 static int setup_ep0_packet_size(xhci_hc_t *hc, xhci_device_t *dev) 125 { 126 int err; 127 128 uint16_t max_packet_size; 129 if ((err = hcd_get_ep0_max_packet_size(&max_packet_size, hc->hcd, &dev->base))) 130 return err; 131 132 xhci_endpoint_t *ep0 = dev->endpoints[0]; 133 assert(ep0); 134 135 if (ep0->base.max_packet_size == max_packet_size) 136 return EOK; 137 138 ep0->base.max_packet_size = max_packet_size; 139 140 xhci_ep_ctx_t ep_ctx; 141 xhci_setup_endpoint_context(ep0, &ep_ctx); 142 143 if ((err = hc_update_endpoint(hc, dev->slot_id, 0, &ep_ctx))) 144 return err; 145 146 return EOK; 147 } 148 126 149 int xhci_bus_enumerate_device(xhci_bus_t *bus, xhci_hc_t *hc, device_t *dev) 127 150 { … … 160 183 } 161 184 162 // TODO: Fetch descriptor of EP0 and reconfigure it accordingly 163 assert(xhci_dev->endpoints[0]); 185 if ((err = setup_ep0_packet_size(hc, xhci_dev))) { 186 usb_log_error("Failed to setup control endpoint of the new device: %s", str_error(err)); 187 goto err_address; 188 } 164 189 165 190 assert(bus->devices_by_slot[xhci_dev->slot_id] == NULL); -
uspace/drv/bus/usb/xhci/hc.c
re76c0ea r306a36d 651 651 } 652 652 653 // TODO: This currently assumes the device is attached to rh directly654 // -> calculate route string655 653 int hc_address_device(xhci_hc_t *hc, xhci_device_t *dev, xhci_endpoint_t *ep0) 656 654 { … … 767 765 } 768 766 767 int hc_update_endpoint(xhci_hc_t *hc, uint32_t slot_id, uint8_t ep_idx, xhci_ep_ctx_t *ep_ctx) 768 { 769 dma_buffer_t ictx_dma_buf; 770 const int err = dma_buffer_alloc(&ictx_dma_buf, sizeof(xhci_input_ctx_t)); 771 if (err) 772 return err; 773 774 xhci_input_ctx_t *ictx = ictx_dma_buf.virt; 775 memset(ictx, 0, sizeof(xhci_input_ctx_t)); 776 777 XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, ep_idx + 1); 778 memcpy(&ictx->endpoint_ctx[ep_idx], ep_ctx, sizeof(xhci_ep_ctx_t)); 779 780 return xhci_cmd_sync_inline(hc, EVALUATE_CONTEXT, .slot_id = slot_id, .input_ctx = ictx_dma_buf); 781 } 782 769 783 /** 770 784 * @} -
uspace/drv/bus/usb/xhci/hc.h
re76c0ea r306a36d 110 110 int hc_add_endpoint(xhci_hc_t *, uint32_t, uint8_t, xhci_ep_ctx_t *); 111 111 int hc_drop_endpoint(xhci_hc_t *, uint32_t, uint8_t); 112 int hc_update_endpoint(xhci_hc_t *, uint32_t, uint8_t, xhci_ep_ctx_t *); 112 113 113 114 #endif -
uspace/lib/usbhost/include/usb/host/hcd.h
re76c0ea r306a36d 102 102 } 103 103 104 extern int hcd_get_ep0_max_packet_size(uint16_t *, hcd_t *, device_t *); 105 104 106 extern int hcd_send_batch(hcd_t *, device_t *, usb_target_t, 105 107 usb_direction_t direction, char *, size_t, uint64_t, -
uspace/lib/usbhost/src/hcd.c
re76c0ea r306a36d 35 35 36 36 #include <usb/debug.h> 37 #include <usb/descriptor.h> 37 38 #include <usb/request.h> 38 39 … … 40 41 #include <async.h> 41 42 #include <errno.h> 43 #include <macros.h> 42 44 #include <usb_iface.h> 43 45 #include <str_error.h> … … 59 61 hcd_set_implementation(hcd, NULL, NULL, NULL); 60 62 } 63 64 /** Get max packet size for the control endpoint 0. 65 * 66 * For LS, HS, and SS devices this value is fixed. For FS devices we must fetch 67 * the first 8B of the device descriptor to determine it. 68 * 69 * @return Combined value of max_packet_size and scheduling oppertunities, 70 * see usb_standard_device_descriptor_t. 71 */ 72 int hcd_get_ep0_max_packet_size(uint16_t *mps, hcd_t *hcd, device_t *dev) 73 { 74 static const uint16_t mps_fixed [] = { 75 [USB_SPEED_LOW] = 8, 76 [USB_SPEED_HIGH] = 64, 77 [USB_SPEED_SUPER] = 512, 78 }; 79 80 if (dev->speed < ARRAY_SIZE(mps_fixed) && mps_fixed[dev->speed] != 0) { 81 *mps = mps_fixed[dev->speed]; 82 return EOK; 83 } 84 85 const usb_target_t control_ep = {{ 86 .address = dev->address, 87 .endpoint = 0, 88 }}; 89 90 usb_standard_device_descriptor_t desc = { 0 }; 91 const usb_device_request_setup_packet_t get_device_desc_8 = 92 GET_DEVICE_DESC(CTRL_PIPE_MIN_PACKET_SIZE); 93 94 usb_log_debug("Requesting first 8B of device descriptor."); 95 ssize_t got = hcd_send_batch_sync(hcd, dev, control_ep, USB_DIRECTION_IN, 96 (char *) &desc, CTRL_PIPE_MIN_PACKET_SIZE, *(uint64_t *)&get_device_desc_8, 97 "read first 8 bytes of dev descriptor"); 98 99 if (got != CTRL_PIPE_MIN_PACKET_SIZE) { 100 const int err = got < 0 ? got : EOVERFLOW; 101 usb_log_error("Failed to get 8B of dev descr: %s.", str_error(err)); 102 return err; 103 } 104 105 *mps = uint16_usb2host(desc.max_packet_size); 106 return EOK; 107 } 108 61 109 62 110 /** Prepare generic usb_transfer_batch and schedule it. -
uspace/lib/usbhost/src/usb2_bus.c
re76c0ea r306a36d 132 132 } 133 133 134 /* Get max packet size for default pipe */ 135 usb_standard_device_descriptor_t desc = { 0 }; 136 const usb_device_request_setup_packet_t get_device_desc_8 = 137 GET_DEVICE_DESC(CTRL_PIPE_MIN_PACKET_SIZE); 138 139 usb_log_debug("Device(%d): Requesting first 8B of device descriptor.", 140 address); 141 ssize_t got = hcd_send_batch_sync(hcd, dev, usb2_default_target, USB_DIRECTION_IN, 142 (char *) &desc, CTRL_PIPE_MIN_PACKET_SIZE, *(uint64_t *)&get_device_desc_8, 143 "read first 8 bytes of dev descriptor"); 144 145 if (got != CTRL_PIPE_MIN_PACKET_SIZE) { 146 err = got < 0 ? got : EOVERFLOW; 147 usb_log_error("Device(%d): Failed to get 8B of dev descr: %s.", 148 address, str_error(err)); 149 goto err_default_control_ep; 150 } 134 uint16_t max_packet_size; 135 if ((err = hcd_get_ep0_max_packet_size(&max_packet_size, hcd, dev))) 136 goto err_address; 151 137 152 138 /* Set new address */ … … 158 144 if (err != 0) { 159 145 usb_log_error("Device(%d): Failed to set new address: %s.", 160 address, str_error( got));146 address, str_error(err)); 161 147 goto err_default_control_ep; 162 148 } … … 175 161 .transfer_type = USB_TRANSFER_CONTROL, 176 162 .direction = USB_DIRECTION_BOTH, 177 .max_packet_size = ED_MPS_PACKET_SIZE_GET(uint16_usb2host(desc.max_packet_size)),178 .packets = ED_MPS_TRANS_OPPORTUNITIES_GET(uint16_usb2host(desc.max_packet_size)),163 .max_packet_size = max_packet_size, 164 .packets = 1, 179 165 }; 180 166
Note:
See TracChangeset
for help on using the changeset viewer.