Changeset cd3fa47 in mainline for uspace/drv/bus/usb/usbhub


Ignore:
Timestamp:
2018-01-21T18:35:09Z (8 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3f02935
Parents:
32b2a6f2
Message:

usb: definition of status bits have changed between USB 2 and 3, remove the confusion

Location:
uspace/drv/bus/usb/usbhub
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhub/port.c

    r32b2a6f2 rcd3fa47  
    145145        if ((err = usbhc_device_enumerate(exch, port->port_number, port->speed))) {
    146146                port_log(error, port, "Failed to enumerate device: %s", str_error(err));
    147                 /* Disable the port */
    148                 usb_hub_clear_port_feature(port->hub, port->port_number, USB_HUB_FEATURE_PORT_ENABLE);
     147                /* Disable the port in USB 2 (impossible in USB3) */
     148                if (port->speed <= USB_SPEED_HIGH)
     149                        usb_hub_clear_port_feature(port->hub, port->port_number, USB2_HUB_FEATURE_PORT_ENABLE);
    149150                goto out_address;
    150151        }
     
    173174static void port_changed_enabled(usb_hub_port_t *port, usb_port_status_t status)
    174175{
    175         const bool enabled = !!(status & USB_HUB_PORT_STATUS_ENABLED);
     176        const bool enabled = !!(status & USB_HUB_PORT_STATUS_ENABLE);
    176177        if (enabled) {
    177178                port_log(warning, port, "Port unexpectedly changed to enabled.");
     
    179180                usb_port_disabled(&port->base, &remove_device);
    180181        }
    181 }
    182 
    183 static void port_changed_suspend(usb_hub_port_t *port, usb_port_status_t status)
    184 {
    185         port_log(error, port, "Port unexpectedly suspend. Weird, we do not support suspending!");
    186182}
    187183
     
    207203static void port_changed_reset(usb_hub_port_t *port, usb_port_status_t status)
    208204{
    209         const bool enabled = !!(status & USB_HUB_PORT_STATUS_ENABLED);
     205        const bool enabled = !!(status & USB_HUB_PORT_STATUS_ENABLE);
    210206
    211207        if (enabled) {
     
    220216typedef void (*change_handler_t)(usb_hub_port_t *, usb_port_status_t);
    221217
    222 static const change_handler_t port_change_handlers [] = {
    223         [USB_HUB_FEATURE_C_PORT_CONNECTION] = &port_changed_connection,
    224         [USB_HUB_FEATURE_C_PORT_ENABLE] = &port_changed_enabled,
    225         [USB_HUB_FEATURE_C_PORT_SUSPEND] = &port_changed_suspend,
    226         [USB_HUB_FEATURE_C_PORT_OVER_CURRENT] = &port_changed_overcurrent,
    227         [USB_HUB_FEATURE_C_PORT_RESET] = &port_changed_reset,
    228         [sizeof(usb_port_status_t) * 8] = NULL,
    229 };
     218static void check_port_change(usb_hub_port_t *port, usb_port_status_t *status,
     219    change_handler_t handler, usb_port_status_t mask, usb_hub_class_feature_t feature)
     220{
     221        if ((*status & mask) == 0)
     222                return;
     223
     224        /* Clear the change so it won't come again */
     225        usb_hub_clear_port_feature(port->hub, port->port_number, feature);
     226
     227        if (handler)
     228                handler(port, *status);
     229
     230        /* Mark the change as resolved */
     231        *status &= ~mask;
     232}
    230233
    231234/**
     
    248251        }
    249252
    250         if (port->hub->speed == USB_SPEED_SUPER)
    251                 /* Link state change is not a change we shall clear, nor we care about it */
    252                 status &= ~(1 << USB_HUB_FEATURE_C_PORT_LINK_STATE);
    253 
    254         for (uint32_t feature = 16; feature < sizeof(usb_port_status_t) * 8; ++feature) {
    255                 uint32_t mask = 1 << feature;
    256 
    257                 if ((status & mask) == 0)
    258                         continue;
    259 
    260                 /* Clear the change so it won't come again */
    261                 usb_hub_clear_port_feature(port->hub, port->port_number, feature);
    262 
    263                 if (!port_change_handlers[feature])
    264                         continue;
    265 
    266                 /* ACK this change */
    267                 status &= ~mask;
    268 
    269                 port_change_handlers[feature](port, status);
     253        check_port_change(port, &status, &port_changed_connection,
     254            USB_HUB_PORT_STATUS_C_CONNECTION, USB_HUB_FEATURE_C_PORT_CONNECTION);
     255
     256        check_port_change(port, &status, &port_changed_overcurrent,
     257            USB_HUB_PORT_STATUS_C_OC, USB_HUB_FEATURE_C_PORT_OVER_CURRENT);
     258
     259        check_port_change(port, &status, &port_changed_reset,
     260            USB_HUB_PORT_STATUS_C_RESET, USB_HUB_FEATURE_C_PORT_RESET);
     261
     262        if (port->hub->speed <= USB_SPEED_HIGH) {
     263                check_port_change(port, &status, &port_changed_enabled,
     264                    USB2_HUB_PORT_STATUS_C_ENABLE, USB2_HUB_FEATURE_C_PORT_ENABLE);
     265        } else {
     266                check_port_change(port, &status, &port_changed_reset,
     267                    USB3_HUB_PORT_STATUS_C_BH_RESET, USB3_HUB_FEATURE_C_BH_PORT_RESET);
     268
     269                check_port_change(port, &status, NULL,
     270                    USB3_HUB_PORT_STATUS_C_LINK_STATE, USB3_HUB_FEATURE_C_PORT_LINK_STATE);
    270271        }
    271272
  • uspace/drv/bus/usb/usbhub/status.h

    r32b2a6f2 rcd3fa47  
    3838
    3939/**
    40  * structure holding port status and changes flags.
    41  * should not be accessed directly, use supplied getter/setter methods.
    42  *
    43  * For more information refer to tables 11-15 and 11-16 in
    44  * "Universal Serial Bus Specification Revision 1.1" pages 274 and 277
    45  * (290 and 293 in pdf)
    46  *
    47  */
    48 typedef uint32_t usb_port_status_t;
    49 #define USB_HUB_PORT_STATUS_CONNECTION \
    50     (uint32_usb2host(1 << (USB_HUB_FEATURE_PORT_CONNECTION)))
    51 #define USB_HUB_PORT_STATUS_ENABLED \
    52     (uint32_usb2host(1 << (USB_HUB_FEATURE_PORT_ENABLE)))
    53 #define USB_HUB_PORT_STATUS_SUSPEND \
    54     (uint32_usb2host(1 << (USB_HUB_FEATURE_PORT_SUSPEND)))
    55 #define USB_HUB_PORT_STATUS_OC \
    56     (uint32_usb2host(1 << (USB_HUB_FEATURE_PORT_OVER_CURRENT)))
    57 #define USB_HUB_PORT_STATUS_RESET \
    58     (uint32_usb2host(1 << (USB_HUB_FEATURE_PORT_RESET)))
    59 #define USB_HUB_PORT_STATUS_POWER \
    60     (uint32_usb2host(1 << (USB_HUB_FEATURE_PORT_POWER)))
    61 #define USB_HUB_PORT_STATUS_LOW_SPEED \
    62     (uint32_usb2host(1 << (USB_HUB_FEATURE_PORT_LOW_SPEED)))
    63 #define USB_HUB_PORT_STATUS_HIGH_SPEED \
    64     (uint32_usb2host(1 << 10))
    65 #define USB_HUB_PORT_STATUS_TEST_MODE \
    66     (uint32_usb2host(1 << 11))
    67 #define USB_HUB_PORT_INDICATOR_CONTROL \
    68     (uint32_usb2host(1 << 12))
    69 
    70 #define USB_HUB_PORT_C_STATUS_CONNECTION \
    71     (uint32_usb2host(1 << (USB_HUB_FEATURE_C_PORT_CONNECTION)))
    72 #define USB_HUB_PORT_C_STATUS_ENABLED \
    73     (uint32_usb2host(1 << (USB_HUB_FEATURE_C_PORT_ENABLE)))
    74 #define USB_HUB_PORT_C_STATUS_SUSPEND \
    75     (uint32_usb2host(1 << (USB_HUB_FEATURE_C_PORT_SUSPEND)))
    76 #define USB_HUB_PORT_C_STATUS_OC \
    77     (uint32_usb2host(1 << (USB_HUB_FEATURE_C_PORT_OVER_CURRENT)))
    78 #define USB_HUB_PORT_C_STATUS_RESET \
    79     (uint32_usb2host(1 << (USB_HUB_FEATURE_C_PORT_RESET)))
    80 
    81 /**
    8240 * structure holding hub status and changes flags.
    8341 *
     
    10159        if (hub_speed == USB_SPEED_SUPER)
    10260                return USB_SPEED_SUPER;
    103         if (hub_speed == USB_SPEED_HIGH && (status & USB_HUB_PORT_STATUS_HIGH_SPEED))
     61        if (hub_speed == USB_SPEED_HIGH && (status & USB2_HUB_PORT_STATUS_HIGH_SPEED))
    10462                return USB_SPEED_HIGH;
    105         if ((status & USB_HUB_PORT_STATUS_LOW_SPEED) != 0)
     63        if ((status & USB2_HUB_PORT_STATUS_LOW_SPEED) != 0)
    10664                return USB_SPEED_LOW;
    10765        return USB_SPEED_FULL;
Note: See TracChangeset for help on using the changeset viewer.