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

Changeset 306a36d in mainline for uspace/lib/usbhost/src/hcd.c


Ignore:
Timestamp:
2017-11-19T23:43:31Z (4 years ago)
Author:
Aearsis <Hlavaty.Ondrej@…>
Branches:
lfn, master
Children:
ff14aede
Parents:
e76c0ea
Message:

xhci: configuration of endpoint 0

Moved fetching of the first 8B of device descriptor from usb2_bus to
hcd, and using it in xhci bus. Also, the value was previously read wrong
by the endpoint descriptor macros, although the value is raw in the
device descriptor - now fixed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/hcd.c

    re76c0ea r306a36d  
    3535
    3636#include <usb/debug.h>
     37#include <usb/descriptor.h>
    3738#include <usb/request.h>
    3839
     
    4041#include <async.h>
    4142#include <errno.h>
     43#include <macros.h>
    4244#include <usb_iface.h>
    4345#include <str_error.h>
     
    5961        hcd_set_implementation(hcd, NULL, NULL, NULL);
    6062}
     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 */
     72int 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
    61109
    62110/** Prepare generic usb_transfer_batch and schedule it.
Note: See TracChangeset for help on using the changeset viewer.