Changeset 9efad54 in mainline for uspace/drv


Ignore:
Timestamp:
2018-01-06T21:15:48Z (8 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
56257ba
Parents:
c901632
Message:

usb: move endpoint descriptor parsing to HC

This better separates responsibilities. Now the device driver does not
care about the contents of an endpoint descriptor, and HC can parse the
values according to device's actual speed.

Currently, it is device driver's responsibility to fetch endpoint
descriptors, map them and register pipes - sending the endpoint
descriptor back to HC. HC then parses it, and fills the pipe
description, which then sends back to device driver. We shall probably
fetch the endpoint descriptor from inside the HC (also fixing the USB
spec violation of communication with EP0).

Location:
uspace/drv
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/block/usbmast/main.c

    rc901632 r9efad54  
    172172            usb_device_get_name(dev));
    173173        usb_log_debug("Bulk in endpoint: %d [%zuB].\n",
    174             epm_in->pipe.desc.endpoint_no, epm_in->pipe.desc.max_packet_size);
     174            epm_in->pipe.desc.endpoint_no, epm_in->pipe.desc.max_transfer_size);
    175175        usb_log_debug("Bulk out endpoint: %d [%zuB].\n",
    176             epm_out->pipe.desc.endpoint_no, epm_out->pipe.desc.max_packet_size);
     176            epm_out->pipe.desc.endpoint_no, epm_out->pipe.desc.max_transfer_size);
    177177
    178178        usb_log_debug("Get LUN count...\n");
  • uspace/drv/bus/usb/ehci/ehci_bus.c

    rc901632 r9efad54  
    7878/** Creates new hcd endpoint representation.
    7979 */
    80 static endpoint_t *ehci_endpoint_create(device_t *dev, const usb_endpoint_desc_t *desc)
     80static endpoint_t *ehci_endpoint_create(device_t *dev, const usb_endpoint_descriptors_t *desc)
    8181{
    8282        assert(dev);
  • uspace/drv/bus/usb/ehci/hw_struct/queue_head.c

    rc901632 r9efad54  
    8282        }
    8383        uint32_t ep_cap = QH_EP_CAP_C_MASK_SET(3 << 2) |
    84                     QH_EP_CAP_MULTI_SET(ep->packets);
     84                    QH_EP_CAP_MULTI_SET(ep->packets_per_uframe);
    8585        if (ep->device->speed != USB_SPEED_HIGH) {
    8686                ep_cap |=
  • uspace/drv/bus/usb/ohci/ohci_bus.c

    rc901632 r9efad54  
    7272/** Creates new hcd endpoint representation.
    7373 */
    74 static endpoint_t *ohci_endpoint_create(device_t *dev, const usb_endpoint_desc_t *desc)
     74static endpoint_t *ohci_endpoint_create(device_t *dev, const usb_endpoint_descriptors_t *desc)
    7575{
    7676        assert(dev);
  • uspace/drv/bus/usb/xhci/bus.c

    rc901632 r9efad54  
    5151
    5252/** Initial descriptor used for control endpoint 0 before more configuration is retrieved. */
    53 static const usb_endpoint_desc_t ep0_initial_desc = {
    54         .endpoint_no = 0,
    55         .direction = USB_DIRECTION_BOTH,
    56         .transfer_type = USB_TRANSFER_CONTROL,
    57         .max_packet_size = CTRL_PIPE_MIN_PACKET_SIZE,
    58         .packets = 1,
     53static const usb_endpoint_descriptors_t ep0_initial_desc = {
     54        .endpoint.max_packet_size = CTRL_PIPE_MIN_PACKET_SIZE,
    5955};
    6056
    61 static endpoint_t *endpoint_create(device_t *, const usb_endpoint_desc_t *);
     57static endpoint_t *endpoint_create(device_t *, const usb_endpoint_descriptors_t *);
    6258
    6359/** Assign address and control endpoint to a new XHCI device.
     
    368364}
    369365
    370 static endpoint_t *endpoint_create(device_t *dev, const usb_endpoint_desc_t *desc)
     366static endpoint_t *endpoint_create(device_t *dev, const usb_endpoint_descriptors_t *desc)
    371367{
    372368        xhci_endpoint_t *ep = calloc(1, sizeof(xhci_endpoint_t));
  • uspace/drv/bus/usb/xhci/endpoint.c

    rc901632 r9efad54  
    5252 * @return Error code.
    5353 */
    54 int xhci_endpoint_init(xhci_endpoint_t *xhci_ep, device_t *dev, const usb_endpoint_desc_t *desc)
     54int xhci_endpoint_init(xhci_endpoint_t *xhci_ep, device_t *dev, const usb_endpoint_descriptors_t *desc)
    5555{
    5656        assert(xhci_ep);
     
    6060        endpoint_init(ep, dev, desc);
    6161
    62         xhci_ep->max_streams = desc->usb3.max_streams;
    63         xhci_ep->max_burst = desc->usb3.max_burst;
    64         xhci_ep->mult = desc->usb3.mult;
    65 
    66         // TODO: process according to 6.2.3.6 of XHCI specification; hardcoded for HS/SS EPs
    67         xhci_ep->interval = desc->interval - 1;
     62        xhci_ep->max_streams = USB_SSC_MAX_STREAMS(desc->companion);
     63        xhci_ep->max_burst = desc->companion.max_burst + 1;
     64        xhci_ep->mult = USB_SSC_MULT(desc->companion) + 1;
     65
     66        /* In USB 3, the semantics of wMaxPacketSize changed. Now the number of
     67         * packets per service interval is determined from max_burst and mult.
     68         */
     69        if (dev->speed >= USB_SPEED_SUPER) {
     70                ep->packets_per_uframe = xhci_ep->max_burst * xhci_ep->mult;
     71                ep->max_transfer_size = ep->max_packet_size * ep->packets_per_uframe;
     72        }
     73
     74        xhci_ep->interval = desc->endpoint.poll_interval;
     75        /* Only Low/Full speed interrupt endpoints have interval set directly,
     76         * others have 2-based log of it.
     77         */
     78        if (dev->speed >= USB_SPEED_HIGH || ep->transfer_type != USB_TRANSFER_INTERRUPT) {
     79                xhci_ep->interval = 1 << (xhci_ep->interval - 1);
     80        }
    6881
    6982        if (xhci_ep->base.transfer_type == USB_TRANSFER_ISOCHRONOUS) {
    70                 xhci_ep->isoch_max_size = desc->usb3.bytes_per_interval
    71                         ? desc->usb3.bytes_per_interval
    72                         : desc->max_packet_size * (desc->packets + 1);
     83                xhci_ep->isoch_max_size = desc->companion.bytes_per_interval
     84                        ? desc->companion.bytes_per_interval
     85                        : ep->max_transfer_size;
    7386                /* Technically there could be superspeed plus too. */
    7487
     
    497510        dev->endpoints[ep->base.endpoint] = NULL;
    498511        ep->base.device = NULL;
    499 
    500         endpoint_del_ref(&ep->base);
    501512}
    502513
  • uspace/drv/bus/usb/xhci/endpoint.h

    rc901632 r9efad54  
    149149#define XHCI_DEV_ARGS(dev)               ddf_fun_get_name((dev).base.fun), (dev).slot_id
    150150
    151 int xhci_endpoint_init(xhci_endpoint_t *, device_t *, const usb_endpoint_desc_t *);
     151int xhci_endpoint_init(xhci_endpoint_t *, device_t *, const usb_endpoint_descriptors_t *);
    152152void xhci_endpoint_fini(xhci_endpoint_t *);
    153153int xhci_endpoint_alloc_transfer_ds(xhci_endpoint_t *);
  • uspace/drv/hid/usbhid/main.c

    rc901632 r9efad54  
    9595           usb_hid_polling_callback,
    9696           /* How much data to request. */
    97            hid_dev->poll_pipe_mapping->pipe.desc.max_packet_size,
     97           hid_dev->poll_pipe_mapping->pipe.desc.max_transfer_size,
    9898           /* Delay */
    9999           -1,
Note: See TracChangeset for help on using the changeset viewer.