Changeset cd3fa47 in mainline for uspace/drv/bus/usb/usbhub/port.c


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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.