Changeset 2833bb4 in mainline


Ignore:
Timestamp:
2018-01-19T17:38:22Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
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)
Message:

xhci: recognise hubs

Location:
uspace
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/xhci/bus.c

    r944f8fdd r2833bb4  
    3737#include <usb/host/hcd.h>
    3838#include <usb/host/utility.h>
     39#include <usb/classes/classes.h>
     40#include <usb/classes/hub.h>
    3941#include <usb/descriptor.h>
    4042#include <usb/debug.h>
     
    136138
    137139/**
     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 */
     145static 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/**
    138166 * Respond to a new device on the XHCI bus. Address it, negotiate packet size
    139167 * and retrieve USB descriptors.
     
    184212        }
    185213
    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));
    189227                goto err_address;
    190228        }
  • uspace/drv/bus/usb/xhci/debug.c

    r944f8fdd r2833bb4  
    347347        SLOT_DUMP(SPEED);
    348348        SLOT_DUMP(MTT);
     349        SLOT_DUMP(HUB);
    349350        SLOT_DUMP(CTX_ENTRIES);
    350351        SLOT_DUMP(MAX_EXIT_LATENCY);
    351352        SLOT_DUMP(ROOT_HUB_PORT);
    352         SLOT_DUMP(NUM_OF_PORTS);
     353        SLOT_DUMP(NUM_PORTS);
    353354        SLOT_DUMP(TT_HUB_SLOT_ID);
    354355        SLOT_DUMP(TT_PORT_NUM);
  • uspace/drv/bus/usb/xhci/endpoint.h

    r944f8fdd r2833bb4  
    123123        dma_buffer_t dev_ctx;
    124124
    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;
    127129} xhci_device_t;
    128130
  • uspace/drv/bus/usb/xhci/hc.c

    r944f8fdd r2833bb4  
    777777        XHCI_SLOT_SPEED_SET(*ctx, usb_speed_to_psiv[dev->base.speed]);
    778778
     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
    779791        /* Setup Transaction Translation. TODO: Test this with HS hub. */
    780792        if (dev->base.tt.dev != NULL) {
  • uspace/drv/bus/usb/xhci/hw_struct/context.h

    r944f8fdd r2833bb4  
    130130#define XHCI_SLOT_MTT_SET(ctx, val) \
    131131        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)
    132134#define XHCI_SLOT_CTX_ENTRIES_SET(ctx, val) \
    133135        xhci_dword_set_bits(&(ctx).data[0], val, 31, 27)
     
    135137#define XHCI_SLOT_ROOT_HUB_PORT_SET(ctx, val) \
    136138        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)
    137141
    138142#define XHCI_SLOT_TT_HUB_SLOT_ID_SET(ctx, val) \
     
    140144#define XHCI_SLOT_TT_HUB_PORT_SET(ctx, val) \
    141145        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)
    142148
    143149#define XHCI_SLOT_ROUTE_STRING(ctx)     XHCI_DWORD_EXTRACT((ctx).data[0], 19,  0)
    144150#define XHCI_SLOT_SPEED(ctx)            XHCI_DWORD_EXTRACT((ctx).data[0], 23, 20)
    145151#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)
    146153#define XHCI_SLOT_CTX_ENTRIES(ctx)      XHCI_DWORD_EXTRACT((ctx).data[0], 31, 27)
    147154
    148155#define XHCI_SLOT_MAX_EXIT_LATENCY(ctx) XHCI_DWORD_EXTRACT((ctx).data[1], 15,  0)
    149156#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)
    151158
    152159#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  
    4141#include <usb/host/usb_transfer_batch.h>
    4242#include <usb/descriptor.h>
     43#include <usb/classes/hub.h>
    4344#include <usb/request.h>
    4445
     
    4748int hc_setup_virtual_root_hub(hc_device_t *);
    4849int hc_get_device_desc(device_t *, usb_standard_device_descriptor_t *);
     50int hc_get_hub_desc(device_t *, usb_hub_descriptor_header_t *);
    4951int hc_device_explore(device_t *);
    5052
  • uspace/lib/usbhost/src/utility.c

    r944f8fdd r2833bb4  
    162162}
    163163
     164int 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
    164192int hc_device_explore(device_t *device)
    165193{
Note: See TracChangeset for help on using the changeset viewer.