Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 56db65d in mainline


Ignore:
Timestamp:
2017-10-24T11:06:32Z (3 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
master
Children:
0206d35
Parents:
894f58c
Message:

usbhost: provide usb_endpoint_desc_t to bus when registering endpoint

This finishes the path of arbitrary information fetched from device all the way down to registering the endpoint in the bus.

Location:
uspace
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ehci/ehci_bus.c

    r894f58c r56db65d  
    114114
    115115
    116 static int ehci_register_ep(bus_t *bus_base, endpoint_t *ep)
     116static int ehci_register_ep(bus_t *bus_base, endpoint_t *ep, const usb_endpoint_desc_t *desc)
    117117{
    118118        ehci_bus_t *bus = (ehci_bus_t *) bus_base;
    119119        ehci_endpoint_t *ehci_ep = ehci_endpoint_get(ep);
    120120
    121         const int err = bus->parent_ops.register_endpoint(bus_base, ep);
     121        // TODO utilize desc->usb2
     122
     123        const int err = bus->parent_ops.register_endpoint(bus_base, ep, desc);
    122124        if (err)
    123125                return err;
  • uspace/drv/bus/usb/ohci/ohci_bus.c

    r894f58c r56db65d  
    115115
    116116
    117 static int ohci_register_ep(bus_t *bus_base, endpoint_t *ep)
     117static int ohci_register_ep(bus_t *bus_base, endpoint_t *ep, const usb_endpoint_desc_t *desc)
    118118{
    119119        ohci_bus_t *bus = (ohci_bus_t *) bus_base;
    120120        ohci_endpoint_t *ohci_ep = ohci_endpoint_get(ep);
    121121
    122         const int err = bus->parent_ops.register_endpoint(bus_base, ep);
     122        const int err = bus->parent_ops.register_endpoint(bus_base, ep, desc);
    123123        if (err)
    124124                return err;
  • uspace/drv/bus/usb/xhci/bus.c

    r894f58c r56db65d  
    165165}
    166166
    167 static int register_endpoint(bus_t *bus_base, endpoint_t *ep)
     167static int register_endpoint(bus_t *bus_base, endpoint_t *ep, const usb_endpoint_desc_t *desc)
    168168{
    169169        xhci_bus_t *bus = bus_to_xhci_bus(bus_base);
    170170        assert(bus);
    171171
    172         usb_log_info("Endpoint(%d:%d) registered to XHCI bus.", ep->target.address, ep->target.endpoint);
     172        assert(ep->device);
     173
     174        /* Extract USB2-related information from endpoint_desc */
     175        ep->target = (usb_target_t) {{
     176                .address = ep->device->address,
     177                .endpoint = desc->endpoint_no,
     178        }};
     179        ep->direction = desc->direction;
     180        ep->transfer_type = desc->transfer_type;
     181        ep->max_packet_size = desc->max_packet_size;
     182        ep->packets = desc->packets;
    173183
    174184        xhci_device_t *xhci_dev = xhci_device_get(ep->device);
    175185        xhci_endpoint_t *xhci_ep = xhci_endpoint_get(ep);
     186
     187        xhci_ep->max_streams = desc->usb3.max_streams;
     188        xhci_ep->max_burst = desc->usb3.max_burst;
     189        // TODO add this property to usb_endpoint_desc_t and fetch it from ss companion desc
     190        xhci_ep->mult = 0;
     191
     192        usb_log_info("Endpoint(%d:%d) registered to XHCI bus.", ep->target.address, ep->target.endpoint);
    176193        return xhci_device_add_endpoint(xhci_dev, xhci_ep);
    177194}
  • uspace/drv/bus/usb/xhci/endpoint.c

    r894f58c r56db65d  
    275275        assert(&dev->base == ep->base.device);
    276276        assert(dev->base.address == ep->base.target.address);
     277
     278        // TODO Do not fail hard on runtime conditions
    277279        assert(!dev->endpoints[ep_num]);
    278280
     
    285287                return EOK;
    286288        }
    287 
    288         // FIXME: Set these from usb_superspeed_endpoint_companion_descriptor_t:
    289         ep->max_streams = 0;
    290         ep->max_burst = 0;
    291         ep->mult = 0;
    292289
    293290        /* Set up TRB ring / PSA. */
  • uspace/drv/bus/usb/xhci/rh.c

    r894f58c r56db65d  
    9090}
    9191
     92/* FIXME Are these really static? Older HCs fetch it from descriptor. */
     93/* FIXME Add USB3 options, if applicable. */
     94static const usb_endpoint_desc_t ep0_desc = {
     95        .endpoint_no = 0,
     96        .direction = USB_DIRECTION_BOTH,
     97        .transfer_type = USB_TRANSFER_CONTROL,
     98        .max_packet_size = CTRL_PIPE_MIN_PACKET_SIZE,
     99        .packets = 1,
     100};
     101
    92102// TODO: This currently assumes the device is attached to rh directly.
    93103//       Also, we should consider moving a lot of functionailty to xhci bus
     
    112122
    113123        xhci_endpoint_t *ep0 = xhci_endpoint_get(ep0_base);
    114         /* FIXME: Sync this with xhci_device_add_endpoint. */
    115         ep0->max_streams = 0;
    116         ep0->max_burst = 0;
    117         ep0->mult = 0;
    118124
    119125        if ((err = xhci_endpoint_alloc_transfer_ds(ep0)))
     
    144150        fibril_mutex_unlock(&dev->guard);
    145151
    146         // XXX: Going around bus, duplicating code
    147152        ep0_base->device = dev;
    148         ep0_base->target.address = dev->address;
    149         ep0_base->target.endpoint = 0;
    150         ep0_base->direction = USB_DIRECTION_BOTH;
    151         ep0_base->transfer_type = USB_TRANSFER_CONTROL;
    152         ep0_base->max_packet_size = CTRL_PIPE_MIN_PACKET_SIZE;
    153         ep0_base->packets = 1;
    154         ep0_base->bandwidth = CTRL_PIPE_MIN_PACKET_SIZE;
    155 
    156         bus_register_endpoint(&rh->hc->bus.base, ep0_base);
     153
     154        bus_register_endpoint(&rh->hc->bus.base, ep0_base, &ep0_desc);
    157155
    158156        if (!rh->devices[dev->port - 1]) {
  • uspace/lib/usbhost/include/usb/host/bus.h

    r894f58c r56db65d  
    8383
    8484        endpoint_t *(*create_endpoint)(bus_t *);
    85         int (*register_endpoint)(bus_t *, endpoint_t *);
     85        int (*register_endpoint)(bus_t *, endpoint_t *, const usb_endpoint_desc_t *);
    8686        int (*unregister_endpoint)(bus_t *, endpoint_t *);
    8787        endpoint_t *(*find_endpoint)(bus_t *, device_t*, usb_target_t, usb_direction_t);
     
    117117int device_init(device_t *);
    118118
    119 extern int bus_add_ep(bus_t *bus, device_t *device, usb_endpoint_t endpoint,
    120     usb_direction_t dir, usb_transfer_type_t type, size_t max_packet_size,
    121     unsigned packets, size_t size);
     119extern int bus_add_ep(bus_t *, device_t *, const usb_endpoint_desc_t *);
    122120extern int bus_remove_ep(bus_t *, device_t *, usb_target_t, usb_direction_t);
    123121
     
    128126
    129127endpoint_t *bus_create_endpoint(bus_t *);
    130 int bus_register_endpoint(bus_t *, endpoint_t *);
     128int bus_register_endpoint(bus_t *, endpoint_t *, const usb_endpoint_desc_t *);
    131129int bus_unregister_endpoint(bus_t *, endpoint_t *);
    132130endpoint_t *bus_find_endpoint(bus_t *, device_t *, usb_target_t, usb_direction_t);
  • uspace/lib/usbhost/src/bus.c

    r894f58c r56db65d  
    6666}
    6767
    68 int bus_add_ep(bus_t *bus, device_t *device, usb_endpoint_t endpoint,
    69     usb_direction_t dir, usb_transfer_type_t type, size_t max_packet_size,
    70     unsigned packets, size_t size)
     68int bus_add_ep(bus_t *bus, device_t *device, const usb_endpoint_desc_t *desc)
    7169{
    7270        assert(bus);
     
    7876                return ENOMEM;
    7977
    80         ep->target = (usb_target_t) {
    81                 .address = device->address,
    82                 .endpoint = endpoint,
    83         };
    84 
    8578        ep->device = device;
    86         ep->direction = dir;
    87         ep->transfer_type = type;
    88         ep->max_packet_size = max_packet_size;
    89         ep->packets = packets;
    90 
    91         ep->bandwidth = bus_count_bw(ep, size);
    92 
    93         const int err = bus_register_endpoint(bus, ep);
     79        const int err = bus_register_endpoint(bus, ep, desc);
    9480
    9581        /* drop Temporary reference */
     
    165151}
    166152
    167 int bus_register_endpoint(bus_t *bus, endpoint_t *ep)
     153int bus_register_endpoint(bus_t *bus, endpoint_t *ep, const usb_endpoint_desc_t *desc)
    168154{
    169155        assert(bus);
     
    174160
    175161        fibril_mutex_lock(&bus->guard);
    176         const int r = bus->ops.register_endpoint(bus, ep);
     162        const int r = bus->ops.register_endpoint(bus, ep, desc);
    177163        fibril_mutex_unlock(&bus->guard);
    178164
  • uspace/lib/usbhost/src/ddf_helpers.c

    r894f58c r56db65d  
    9898        assert(dev);
    9999
    100         const size_t size = endpoint_desc->max_packet_size;
    101 
    102100        usb_log_debug("Register endpoint %d:%d %s-%s %zuB %ums.\n",
    103101                dev->address, endpoint_desc->endpoint_no,
     
    106104                endpoint_desc->max_packet_size, endpoint_desc->usb2.polling_interval);
    107105
    108         // FIXME: we now have max_streams and max_burst in endpoint_desc->usb3 struct
    109         // Hand it down to XHCI, refactor, whatever
    110 
    111         return bus_add_ep(hcd->bus, dev, endpoint_desc->endpoint_no,
    112                 endpoint_desc->direction, endpoint_desc->transfer_type,
    113                 endpoint_desc->max_packet_size, endpoint_desc->packets,
    114                 size);
     106        return bus_add_ep(hcd->bus, dev, endpoint_desc);
    115107}
    116108
  • uspace/lib/usbhost/src/hcd.c

    r894f58c r56db65d  
    8787        assert(device->address == target.address);
    8888
     89        if (!hcd->ops.schedule) {
     90                usb_log_error("HCD does not implement scheduler.\n");
     91                return ENOTSUP;
     92        }
     93
    8994        endpoint_t *ep = bus_find_endpoint(hcd->bus, device, target, direction);
    9095        if (ep == NULL) {
     
    9398                return ENOENT;
    9499        }
     100
     101        // TODO cut here aka provide helper to call with instance of endpoint_t in hand
    95102
    96103        usb_log_debug2("%s %d:%d %zu(%zu).\n",
     
    104111                    ep->target.address, ep->target.endpoint, name, bw, ep->bandwidth);
    105112                return ENOSPC;
    106         }
    107         if (!hcd->ops.schedule) {
    108                 usb_log_error("HCD does not implement scheduler.\n");
    109                 return ENOTSUP;
    110113        }
    111114
  • uspace/lib/usbhost/src/usb2_bus.c

    r894f58c r56db65d  
    9191}
    9292
     93static const usb_endpoint_desc_t usb2_default_control_ep = {
     94        .endpoint_no = 0,
     95        .transfer_type = USB_TRANSFER_CONTROL,
     96        .direction = USB_DIRECTION_BOTH,
     97        .max_packet_size = CTRL_PIPE_MIN_PACKET_SIZE,
     98        .packets = 1,
     99};
     100
     101
     102static const usb_target_t usb2_default_target = {{
     103        .address = USB_ADDRESS_DEFAULT,
     104        .endpoint = 0,
     105}};
     106
    93107static int usb2_bus_address_device(bus_t *bus, hcd_t *hcd, device_t *dev)
    94108{
    95109        int err;
    96 
    97         static const usb_target_t default_target = {{
    98                 .address = USB_ADDRESS_DEFAULT,
    99                 .endpoint = 0,
    100         }};
    101110
    102111        /** Reserve address early, we want pretty log messages */
     
    111120        /* Add default pipe on default address */
    112121        usb_log_debug("Device(%d): Adding default target (0:0)", address);
    113         err = bus_add_ep(bus, dev, 0, USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL,
    114             CTRL_PIPE_MIN_PACKET_SIZE, CTRL_PIPE_MIN_PACKET_SIZE, 1);
     122        err = bus_add_ep(bus, dev, &usb2_default_control_ep);
    115123        if (err != EOK) {
    116124                usb_log_error("Device(%d): Failed to add default target: %s.",
     
    126134        usb_log_debug("Device(%d): Requesting first 8B of device descriptor.",
    127135            address);
    128         ssize_t got = hcd_send_batch_sync(hcd, dev, default_target, USB_DIRECTION_IN,
     136        ssize_t got = hcd_send_batch_sync(hcd, dev, usb2_default_target, USB_DIRECTION_IN,
    129137            (char *) &desc, CTRL_PIPE_MIN_PACKET_SIZE, *(uint64_t *)&get_device_desc_8,
    130138            "read first 8 bytes of dev descriptor");
     
    134142                usb_log_error("Device(%d): Failed to get 8B of dev descr: %s.",
    135143                    address, str_error(err));
    136                 goto err_default_target;
     144                goto err_default_control_ep;
    137145        }
    138146
     
    141149
    142150        usb_log_debug("Device(%d): Setting USB address.", address);
    143         err = hcd_send_batch_sync(hcd, dev, default_target, USB_DIRECTION_OUT,
     151        err = hcd_send_batch_sync(hcd, dev, usb2_default_target, USB_DIRECTION_OUT,
    144152            NULL, 0, *(uint64_t *)&set_address, "set address");
    145153        if (err != 0) {
    146154                usb_log_error("Device(%d): Failed to set new address: %s.",
    147155                    address, str_error(got));
    148                 goto err_default_target;
     156                goto err_default_control_ep;
    149157        }
    150158
    151159        dev->address = address;
     160
     161        const usb_endpoint_desc_t control_ep = {
     162                .endpoint_no = 0,
     163                .transfer_type = USB_TRANSFER_CONTROL,
     164                .direction = USB_DIRECTION_BOTH,
     165                .max_packet_size = ED_MPS_PACKET_SIZE_GET(uint16_usb2host(desc.max_packet_size)),
     166                .packets = ED_MPS_TRANS_OPPORTUNITIES_GET(uint16_usb2host(desc.max_packet_size)),
     167        };
    152168
    153169        /* Register EP on the new address */
    154170        usb_log_debug("Device(%d): Registering control EP.", address);
    155         err = bus_add_ep(bus, dev, 0, USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL,
    156             ED_MPS_PACKET_SIZE_GET(uint16_usb2host(desc.max_packet_size)),
    157             ED_MPS_TRANS_OPPORTUNITIES_GET(uint16_usb2host(desc.max_packet_size)),
    158             ED_MPS_PACKET_SIZE_GET(uint16_usb2host(desc.max_packet_size)));
     171        err = bus_add_ep(bus, dev, &control_ep);
    159172        if (err != EOK) {
    160173                usb_log_error("Device(%d): Failed to register EP0: %s",
    161174                    address, str_error(err));
    162                 goto err_default_target;
    163         }
    164 
    165         bus_remove_ep(bus, dev, default_target, USB_DIRECTION_BOTH);
    166         return EOK;
    167 
    168 err_default_target:
    169         bus_remove_ep(bus, dev, default_target, USB_DIRECTION_BOTH);
     175                goto err_default_control_ep;
     176        }
     177
     178        bus_remove_ep(bus, dev, usb2_default_target, USB_DIRECTION_BOTH);
     179        return EOK;
     180
     181err_default_control_ep:
     182        bus_remove_ep(bus, dev, usb2_default_target, USB_DIRECTION_BOTH);
    170183err_address:
    171184        bus_release_address(bus, address);
     
    278291 * @param endpoint USB endpoint number.
    279292 */
    280 static int usb2_bus_register_ep(bus_t *bus_base, endpoint_t *ep)
     293static int usb2_bus_register_ep(bus_t *bus_base, endpoint_t *ep, const usb_endpoint_desc_t *desc)
    281294{
    282295        usb2_bus_t *bus = bus_to_usb2_bus(bus_base);
    283296        assert(ep);
    284297
    285         usb_address_t address = ep->target.address;
    286 
    287         if (!usb_address_is_valid(address))
    288                 return EINVAL;
    289 
    290         /* Check for speed and address */
    291         if (!bus->devices[address].occupied)
    292                 return ENOENT;
     298        assert(ep->device);
     299
     300        /* Extract USB2-related information from endpoint_desc */
     301        ep->target = (usb_target_t) {{
     302                .address = ep->device->address,
     303                .endpoint = desc->endpoint_no,
     304        }};
     305        ep->direction = desc->direction;
     306        ep->transfer_type = desc->transfer_type;
     307        ep->max_packet_size = desc->max_packet_size;
     308        ep->packets = desc->packets;
     309
     310        ep->bandwidth = bus_base->ops.count_bw(ep, desc->max_packet_size);
    293311
    294312        /* Check for existence */
     
    300318                return ENOSPC;
    301319
    302         list_append(&ep->link, get_list(bus, ep->target.address));
     320        list_append(&ep->link, get_list(bus, ep->device->address));
    303321        bus->free_bw -= ep->bandwidth;
    304322
Note: See TracChangeset for help on using the changeset viewer.