Changeset df6ded8 in mainline for uspace/lib/usbdev/src/pipesinit.c


Ignore:
Timestamp:
2018-02-28T16:37:50Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1b20da0
Parents:
f5e5f73 (diff), b2dca8de (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Jakub Jermar <jakub@…> (2018-02-28 16:06:42)
git-committer:
Jakub Jermar <jakub@…> (2018-02-28 16:37:50)
Message:

Merge github.com:helenos-xhci-team/helenos

This commit merges support for USB 3 and generally refactors, fixes,
extends and cleans up the existing USB framework.

Notable additions and features:

  • new host controller driver has been implemented to control various xHC models (among others, NEC Renesas uPD720200)
  • isochronous data transfer mode
  • support for explicit USB device removal
  • USB tablet driver
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbdev/src/pipesinit.c

    rf5e5f73 rdf6ded8  
    11/*
    22 * Copyright (c) 2011 Vojtech Horky
     3 * Copyright (c) 2018 Ondrej Hlavaty, Michal Staruch
    34 * All rights reserved.
    45 *
     
    3839#include <usb/dev/request.h>
    3940#include <usb/usb.h>
     41#include <usb/debug.h>
    4042#include <usb/descriptor.h>
    4143
     
    5961        NESTING(INTERFACE, HID),
    6062        NESTING(HID, HID_REPORT),
     63        NESTING(ENDPOINT, SSPEED_EP_COMPANION),
    6164        LAST_NESTING
    6265};
     
    7073{
    7174        return descriptor[1] == USB_DESCTYPE_ENDPOINT;
     75}
     76
     77/** Tells whether given descriptor is of superspeed companion type.
     78 *
     79 * @param descriptor Descriptor in question.
     80 * @return Whether the given descriptor is superspeed companion descriptor.
     81 */
     82static inline bool is_superspeed_companion_descriptor(const uint8_t *descriptor)
     83{
     84        return descriptor[1] == USB_DESCTYPE_SSPEED_EP_COMPANION;
    7285}
    7386
     
    134147                if (interface_number_fits
    135148                    && interface_setting_fits
    136                     && endpoint_descriptions_fits) {
     149                    && endpoint_descriptions_fits
     150                    && !mapping->present) {
    137151                        return mapping;
    138152                }
     
    141155                mapping_count--;
    142156        }
     157
    143158        return NULL;
    144159}
     
    150165 * @param interface Interface descriptor under which belongs the @p endpoint.
    151166 * @param endpoint Endpoint descriptor.
     167 * @param companion Superspeed companion descriptor.
    152168 * @return Error code.
    153169 */
     
    156172    usb_standard_interface_descriptor_t *interface,
    157173    usb_standard_endpoint_descriptor_t *endpoint_desc,
     174    usb_superspeed_endpoint_companion_descriptor_t *companion_desc,
    158175    usb_dev_session_t *bus_session)
    159176{
     
    162179         * Get endpoint characteristics.
    163180         */
    164 
    165         /* Actual endpoint number is in bits 0..3 */
    166         const usb_endpoint_t ep_no = endpoint_desc->endpoint_address & 0x0F;
    167 
    168181        const usb_endpoint_description_t description = {
    169                 /* Endpoint direction is set by bit 7 */
    170                 .direction = (endpoint_desc->endpoint_address & 128)
    171                     ? USB_DIRECTION_IN : USB_DIRECTION_OUT,
    172                 /* Transfer type is in bits 0..2 and
    173                  * the enum values corresponds 1:1 */
    174                 .transfer_type = endpoint_desc->attributes & 3,
     182                .transfer_type = USB_ED_GET_TRANSFER_TYPE(*endpoint_desc),
     183                .direction = USB_ED_GET_DIR(*endpoint_desc),
    175184
    176185                /* Get interface characteristics. */
     
    194203        }
    195204
    196         errno_t rc = usb_pipe_initialize(&ep_mapping->pipe,
    197             ep_no, description.transfer_type,
    198             ED_MPS_PACKET_SIZE_GET(
    199                 uint16_usb2host(endpoint_desc->max_packet_size)),
    200             description.direction,
    201             ED_MPS_TRANS_OPPORTUNITIES_GET(
    202                 uint16_usb2host(endpoint_desc->max_packet_size)), bus_session);
    203         if (rc != EOK) {
    204                 return rc;
    205         }
     205        errno_t err = usb_pipe_initialize(&ep_mapping->pipe, bus_session);
     206        if (err)
     207                return err;
    206208
    207209        ep_mapping->present = true;
    208210        ep_mapping->descriptor = endpoint_desc;
     211        ep_mapping->companion_descriptor = companion_desc;
    209212        ep_mapping->interface = interface;
    210213
     
    235238        do {
    236239                if (is_endpoint_descriptor(descriptor)) {
     240                        /* Check if companion descriptor is present too, it should immediatelly follow. */
     241                        const uint8_t *companion_desc = usb_dp_get_nested_descriptor(parser,
     242                                parser_data, descriptor);
     243                        if (companion_desc && !is_superspeed_companion_descriptor(companion_desc)) {
     244                                /* Not what we wanted, don't pass it further. */
     245                                companion_desc = NULL;
     246                        }
     247
    237248                        (void) process_endpoint(mapping, mapping_count,
    238249                            (usb_standard_interface_descriptor_t *)
     
    240251                            (usb_standard_endpoint_descriptor_t *)
    241252                                descriptor,
     253                            (usb_superspeed_endpoint_companion_descriptor_t *)
     254                                companion_desc,
    242255                            bus_session);
    243256                }
     
    288301        if (config_descriptor == NULL)
    289302                return EBADMEM;
    290        
     303
    291304        if (config_descriptor_size <
    292305            sizeof(usb_standard_configuration_descriptor_t)) {
     
    328341}
    329342
    330 /** Probe default control pipe for max packet size.
    331  *
    332  * The function tries to get the correct value of max packet size several
    333  * time before giving up.
    334  *
    335  * The session on the pipe shall not be started.
    336  *
    337  * @param pipe Default control pipe.
    338  * @return Error code.
    339  */
    340 errno_t usb_pipe_probe_default_control(usb_pipe_t *pipe)
    341 {
    342         assert(pipe);
    343         static_assert(DEV_DESCR_MAX_PACKET_SIZE_OFFSET < CTRL_PIPE_MIN_PACKET_SIZE);
    344 
    345         if ((pipe->direction != USB_DIRECTION_BOTH) ||
    346             (pipe->transfer_type != USB_TRANSFER_CONTROL) ||
    347             (pipe->endpoint_no != 0)) {
    348                 return EINVAL;
    349         }
    350 
    351         uint8_t dev_descr_start[CTRL_PIPE_MIN_PACKET_SIZE];
    352         size_t transferred_size;
    353         errno_t rc;
    354         for (size_t attempt_var = 0; attempt_var < 3; ++attempt_var) {
    355                 rc = usb_request_get_descriptor(pipe, USB_REQUEST_TYPE_STANDARD,
    356                     USB_REQUEST_RECIPIENT_DEVICE, USB_DESCTYPE_DEVICE,
    357                     0, 0, dev_descr_start, CTRL_PIPE_MIN_PACKET_SIZE,
    358                     &transferred_size);
    359                 if (rc == EOK) {
    360                         if (transferred_size != CTRL_PIPE_MIN_PACKET_SIZE) {
    361                                 rc = ELIMIT;
    362                                 continue;
    363                         }
    364                         break;
    365                 }
    366         }
    367         if (rc != EOK) {
    368                 return rc;
    369         }
    370 
    371         pipe->max_packet_size
    372             = dev_descr_start[DEV_DESCR_MAX_PACKET_SIZE_OFFSET];
    373 
    374         return EOK;
    375 }
    376 
    377343/**
    378344 * @}
Note: See TracChangeset for help on using the changeset viewer.