Changeset 2833bb4 in mainline
- Timestamp:
- 2018-01-19T17:38:22Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7e5a12b
- Parents:
- 944f8fdd
- git-author:
- Ondřej Hlavatý <aearsis@…> (2018-01-19 17:38:10)
- git-committer:
- Ondřej Hlavatý <aearsis@…> (2018-01-19 17:38:22)
- Location:
- uspace
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/bus.c
r944f8fdd r2833bb4 37 37 #include <usb/host/hcd.h> 38 38 #include <usb/host/utility.h> 39 #include <usb/classes/classes.h> 40 #include <usb/classes/hub.h> 39 41 #include <usb/descriptor.h> 40 42 #include <usb/debug.h> … … 136 138 137 139 /** 140 * Check whether the device is a hub and if so, fill its characterstics. 141 * 142 * If this fails, it does not necessarily mean the device is unusable. 143 * Just the TT will not work correctly. 144 */ 145 static int setup_hub(xhci_device_t *dev, usb_standard_device_descriptor_t *desc) 146 { 147 if (desc->device_class != USB_CLASS_HUB) 148 return EOK; 149 150 usb_hub_descriptor_header_t hub_desc = { 0 }; 151 const int err = hc_get_hub_desc(&dev->base, &hub_desc); 152 if (err) 153 return err; 154 155 dev->is_hub = 1; 156 dev->num_ports = hub_desc.port_count; 157 dev->tt_think_time = 8 + 158 8 * !!(hub_desc.characteristics & HUB_CHAR_TT_THINK_8) + 159 16 * !!(hub_desc.characteristics & HUB_CHAR_TT_THINK_16); 160 161 usb_log_debug2("Device(%u): recognised USB hub with %u ports", dev->base.address, dev->num_ports); 162 return EOK; 163 } 164 165 /** 138 166 * Respond to a new device on the XHCI bus. Address it, negotiate packet size 139 167 * and retrieve USB descriptors. … … 184 212 } 185 213 186 /* Read the device descriptor, derive the match ids */ 187 if ((err = hc_device_explore(dev))) { 188 usb_log_error("Device(%d): Failed to explore device: %s", dev->address, str_error(err)); 214 usb_standard_device_descriptor_t desc = { 0 }; 215 216 if ((err = hc_get_device_desc(dev, &desc))) { 217 usb_log_error("Device(%d): failed to get devices descriptor: %s", dev->address, str_error(err)); 218 goto err_address; 219 } 220 221 if ((err = setup_hub(xhci_dev, &desc))) 222 usb_log_warning("Device(%d): failed to setup hub characteristics: %s. " 223 " Continuing anyway.", dev->address, str_error(err)); 224 225 if ((err = hcd_ddf_setup_match_ids(dev, &desc))) { 226 usb_log_error("Device(%d): failed to setup match IDs: %s", dev->address, str_error(err)); 189 227 goto err_address; 190 228 } -
uspace/drv/bus/usb/xhci/debug.c
r944f8fdd r2833bb4 347 347 SLOT_DUMP(SPEED); 348 348 SLOT_DUMP(MTT); 349 SLOT_DUMP(HUB); 349 350 SLOT_DUMP(CTX_ENTRIES); 350 351 SLOT_DUMP(MAX_EXIT_LATENCY); 351 352 SLOT_DUMP(ROOT_HUB_PORT); 352 SLOT_DUMP(NUM_ OF_PORTS);353 SLOT_DUMP(NUM_PORTS); 353 354 SLOT_DUMP(TT_HUB_SLOT_ID); 354 355 SLOT_DUMP(TT_PORT_NUM); -
uspace/drv/bus/usb/xhci/endpoint.h
r944f8fdd r2833bb4 123 123 dma_buffer_t dev_ctx; 124 124 125 /** Flag indicating whether the device is USB3 (it's USB2 otherwise). */ 126 bool usb3; 125 /** Hub specific information. Valid only if the device is_hub. */ 126 bool is_hub; 127 uint8_t num_ports; 128 uint8_t tt_think_time; 127 129 } xhci_device_t; 128 130 -
uspace/drv/bus/usb/xhci/hc.c
r944f8fdd r2833bb4 777 777 XHCI_SLOT_SPEED_SET(*ctx, usb_speed_to_psiv[dev->base.speed]); 778 778 779 /* 780 * Note: This function is used even before this flag can be set, to 781 * issue the address device command. It is OK, because these 782 * flags are not required to be valid for that command. 783 */ 784 if (dev->is_hub) { 785 XHCI_SLOT_HUB_SET(*ctx, 1); 786 XHCI_SLOT_NUM_PORTS_SET(*ctx, dev->num_ports); 787 XHCI_SLOT_TT_THINK_TIME_SET(*ctx, dev->tt_think_time); 788 XHCI_SLOT_MTT_SET(*ctx, 0); // MTT not supported yet 789 } 790 779 791 /* Setup Transaction Translation. TODO: Test this with HS hub. */ 780 792 if (dev->base.tt.dev != NULL) { -
uspace/drv/bus/usb/xhci/hw_struct/context.h
r944f8fdd r2833bb4 130 130 #define XHCI_SLOT_MTT_SET(ctx, val) \ 131 131 xhci_dword_set_bits(&(ctx).data[0], !!val, 25, 25) 132 #define XHCI_SLOT_HUB_SET(ctx, val) \ 133 xhci_dword_set_bits(&(ctx).data[0], !!val, 25, 25) 132 134 #define XHCI_SLOT_CTX_ENTRIES_SET(ctx, val) \ 133 135 xhci_dword_set_bits(&(ctx).data[0], val, 31, 27) … … 135 137 #define XHCI_SLOT_ROOT_HUB_PORT_SET(ctx, val) \ 136 138 xhci_dword_set_bits(&(ctx).data[1], val, 23, 16) 139 #define XHCI_SLOT_NUM_PORTS_SET(ctx, val) \ 140 xhci_dword_set_bits(&(ctx).data[1], val, 31, 24) 137 141 138 142 #define XHCI_SLOT_TT_HUB_SLOT_ID_SET(ctx, val) \ … … 140 144 #define XHCI_SLOT_TT_HUB_PORT_SET(ctx, val) \ 141 145 xhci_dword_set_bits(&(ctx).data[2], (val & 0xFF), 15, 8) 146 #define XHCI_SLOT_TT_THINK_TIME_SET(ctx, val) \ 147 xhci_dword_set_bits(&(ctx).data[2], (val & 0xFF), 17, 16) 142 148 143 149 #define XHCI_SLOT_ROUTE_STRING(ctx) XHCI_DWORD_EXTRACT((ctx).data[0], 19, 0) 144 150 #define XHCI_SLOT_SPEED(ctx) XHCI_DWORD_EXTRACT((ctx).data[0], 23, 20) 145 151 #define XHCI_SLOT_MTT(ctx) XHCI_DWORD_EXTRACT((ctx).data[0], 25, 25) 152 #define XHCI_SLOT_HUB(ctx) XHCI_DWORD_EXTRACT((ctx).data[0], 26, 26) 146 153 #define XHCI_SLOT_CTX_ENTRIES(ctx) XHCI_DWORD_EXTRACT((ctx).data[0], 31, 27) 147 154 148 155 #define XHCI_SLOT_MAX_EXIT_LATENCY(ctx) XHCI_DWORD_EXTRACT((ctx).data[1], 15, 0) 149 156 #define XHCI_SLOT_ROOT_HUB_PORT(ctx) XHCI_DWORD_EXTRACT((ctx).data[1], 23, 16) 150 #define XHCI_SLOT_NUM_ OF_PORTS(ctx)XHCI_DWORD_EXTRACT((ctx).data[1], 31, 24)157 #define XHCI_SLOT_NUM_PORTS(ctx) XHCI_DWORD_EXTRACT((ctx).data[1], 31, 24) 151 158 152 159 #define XHCI_SLOT_TT_HUB_SLOT_ID(ctx) XHCI_DWORD_EXTRACT((ctx).data[2], 7, 0) -
uspace/lib/usbhost/include/usb/host/utility.h
r944f8fdd r2833bb4 41 41 #include <usb/host/usb_transfer_batch.h> 42 42 #include <usb/descriptor.h> 43 #include <usb/classes/hub.h> 43 44 #include <usb/request.h> 44 45 … … 47 48 int hc_setup_virtual_root_hub(hc_device_t *); 48 49 int hc_get_device_desc(device_t *, usb_standard_device_descriptor_t *); 50 int hc_get_hub_desc(device_t *, usb_hub_descriptor_header_t *); 49 51 int hc_device_explore(device_t *); 50 52 -
uspace/lib/usbhost/src/utility.c
r944f8fdd r2833bb4 162 162 } 163 163 164 int hc_get_hub_desc(device_t *device, usb_hub_descriptor_header_t *desc) 165 { 166 const usb_target_t control_ep = {{ 167 .address = device->address, 168 .endpoint = 0, 169 }}; 170 171 const usb_device_request_setup_packet_t get_hub_desc = { 172 .request_type = SETUP_REQUEST_TYPE_DEVICE_TO_HOST 173 | (USB_REQUEST_TYPE_CLASS << 5) 174 | USB_REQUEST_RECIPIENT_DEVICE, 175 .request = USB_DEVREQ_GET_DESCRIPTOR, \ 176 .value = uint16_host2usb(USB_DESCTYPE_HUB << 8), \ 177 .length = sizeof(*desc), 178 }; 179 180 usb_log_debug("Device(%d): Requesting hub descriptor.", 181 device->address); 182 ssize_t got = bus_device_send_batch_sync(device, control_ep, USB_DIRECTION_IN, 183 (char *) desc, sizeof(*desc), *(uint64_t *)&get_hub_desc, 184 "get hub descriptor"); 185 186 if (got < 0) 187 return got; 188 189 return got == sizeof(*desc) ? EOK : EOVERFLOW; 190 } 191 164 192 int hc_device_explore(device_t *device) 165 193 {
Note:
See TracChangeset
for help on using the changeset viewer.