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


Ignore:
Timestamp:
2018-02-26T16:51:40Z (8 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e773f58
Parents:
3692678
Message:

usb: cstyle

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

Legend:

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

    r3692678 rae3a941  
    4949#include "status.h"
    5050
    51 #define port_log(lvl, port, fmt, ...) do { usb_log_##lvl("(%p-%u): " fmt, (port->hub), (port->port_number), ##__VA_ARGS__); } while (0)
     51#define port_log(lvl, port, fmt, ...) do { \
     52                usb_log_##lvl("(%p-%u): " fmt, \
     53                    (port->hub), (port->port_number), ##__VA_ARGS__); \
     54        } while (0)
    5255
    5356/** Initialize hub port information.
     
    5558 * @param port Port to be initialized.
    5659 */
    57 void usb_hub_port_init(usb_hub_port_t *port, usb_hub_dev_t *hub, unsigned int port_number)
     60void usb_hub_port_init(usb_hub_port_t *port, usb_hub_dev_t *hub,
     61    unsigned int port_number)
    5862{
    5963        assert(port);
     
    7983        async_exch_t *exch = usb_device_bus_exchange_begin(port->hub->usb_device);
    8084        if (!exch) {
    81                 port_log(error, port, "Cannot remove the device, failed creating exchange.");
     85                port_log(error, port, "Cannot remove the device, "
     86                    "failed creating exchange.");
    8287                return;
    8388        }
     
    8590        const errno_t err = usbhc_device_remove(exch, port->port_number);
    8691        if (err)
    87                 port_log(error, port, "Failed to remove device: %s", str_error(err));
     92                port_log(error, port, "Failed to remove device: %s",
     93                    str_error(err));
    8894
    8995        usb_device_bus_exchange_end(exch);
     
    109115        err = usb_hub_reserve_default_address(port->hub, exch, &port->base);
    110116        if (err != EOK) {
    111                 port_log(error, port, "Failed to reserve default address: %s", str_error(err));
     117                port_log(error, port, "Failed to reserve default address: %s",
     118                    str_error(err));
    112119                return err;
    113120        }
     
    118125
    119126        port_log(debug, port, "Resetting port.");
    120         if ((err = usb_hub_set_port_feature(port->hub, port->port_number, USB_HUB_FEATURE_PORT_RESET))) {
    121                 port_log(warning, port, "Port reset request failed: %s", str_error(err));
     127        if ((err = usb_hub_set_port_feature(port->hub, port->port_number,
     128                            USB_HUB_FEATURE_PORT_RESET))) {
     129                port_log(warning, port, "Port reset request failed: %s",
     130                    str_error(err));
    122131                goto out_address;
    123132        }
    124133
    125134        if ((err = usb_port_wait_for_enabled(&port->base))) {
    126                 port_log(error, port, "Failed to reset port: %s", str_error(err));
     135                port_log(error, port, "Failed to reset port: %s",
     136                    str_error(err));
    127137                goto out_address;
    128138        }
    129139
    130140        port_log(debug, port, "Enumerating device.");
    131         if ((err = usbhc_device_enumerate(exch, port->port_number, port->speed))) {
    132                 port_log(error, port, "Failed to enumerate device: %s", str_error(err));
     141        if ((err = usbhc_device_enumerate(exch, port->port_number,
     142                            port->speed))) {
     143                port_log(error, port, "Failed to enumerate device: %s",
     144                    str_error(err));
    133145                /* Disable the port */
    134                 usb_hub_clear_port_feature(port->hub, port->port_number, USB2_HUB_FEATURE_PORT_ENABLE);
     146                usb_hub_clear_port_feature(port->hub, port->port_number,
     147                    USB2_HUB_FEATURE_PORT_ENABLE);
    135148                goto out_address;
    136149        }
     
    151164
    152165        port_log(debug, port, "Issuing a warm reset.");
    153         if ((err = usb_hub_set_port_feature(port->hub, port->port_number, USB3_HUB_FEATURE_BH_PORT_RESET))) {
    154                 port_log(warning, port, "Port reset request failed: %s", str_error(err));
     166        if ((err = usb_hub_set_port_feature(port->hub, port->port_number,
     167                            USB3_HUB_FEATURE_BH_PORT_RESET))) {
     168                port_log(warning, port, "Port reset request failed: %s",
     169                    str_error(err));
    155170                return err;
    156171        }
    157172
    158173        if ((err = usb_port_wait_for_enabled(&port->base))) {
    159                 port_log(error, port, "Failed to reset port: %s", str_error(err));
     174                port_log(error, port, "Failed to reset port: %s",
     175                    str_error(err));
    160176                return err;
    161177        }
    162178
    163179        port_log(debug, port, "Enumerating device.");
    164         if ((err = usbhc_device_enumerate(exch, port->port_number, port->speed))) {
    165                 port_log(error, port, "Failed to enumerate device: %s", str_error(err));
     180        if ((err = usbhc_device_enumerate(exch, port->port_number,
     181                            port->speed))) {
     182                port_log(error, port, "Failed to enumerate device: %s",
     183                    str_error(err));
    166184                return err;
    167185        }
     
    193211{
    194212        const bool connected = !!(status & USB_HUB_PORT_STATUS_CONNECTION);
    195         port_log(debug, port, "Connection change: device %s.", connected ? "attached" : "removed");
     213        port_log(debug, port, "Connection change: device %s.", connected
     214            ? "attached" : "removed");
    196215
    197216        if (connected) {
     
    212231}
    213232
    214 static void port_changed_overcurrent(usb_hub_port_t *port, usb_port_status_t status)
     233static void port_changed_overcurrent(usb_hub_port_t *port,
     234    usb_port_status_t status)
    215235{
    216236        const bool overcurrent = !!(status & USB_HUB_PORT_STATUS_OC);
     
    225245
    226246        if (!overcurrent) {
    227                 const errno_t err = usb_hub_set_port_feature(port->hub, port->port_number, USB_HUB_FEATURE_PORT_POWER);
     247                const errno_t err = usb_hub_set_port_feature(port->hub,
     248                    port->port_number, USB_HUB_FEATURE_PORT_POWER);
    228249                if (err)
    229                         port_log(error, port, "Failed to set port power after OC: %s.", str_error(err));
     250                        port_log(error, port, "Failed to set port power "
     251                            "after OC: %s.", str_error(err));
    230252        }
    231253}
     
    245267
    246268static void check_port_change(usb_hub_port_t *port, usb_port_status_t *status,
    247     change_handler_t handler, usb_port_status_t mask, usb_hub_class_feature_t feature)
     269    change_handler_t handler, usb_port_status_t mask,
     270    usb_hub_class_feature_t feature)
    248271{
    249272        if ((*status & mask) == 0)
     
    273296
    274297        usb_port_status_t status = 0;
    275         const errno_t err = usb_hub_get_port_status(port->hub, port->port_number, &status);
     298        const errno_t err = usb_hub_get_port_status(port->hub,
     299            port->port_number, &status);
    276300        if (err != EOK) {
    277                 port_log(error, port, "Failed to get port status: %s.", str_error(err));
     301                port_log(error, port, "Failed to get port status: %s.",
     302                    str_error(err));
    278303                return;
    279304        }
    280305
    281306        check_port_change(port, &status, &port_changed_connection,
    282             USB_HUB_PORT_STATUS_C_CONNECTION, USB_HUB_FEATURE_C_PORT_CONNECTION);
     307            USB_HUB_PORT_STATUS_C_CONNECTION,
     308            USB_HUB_FEATURE_C_PORT_CONNECTION);
    283309
    284310        check_port_change(port, &status, &port_changed_overcurrent,
     
    290316        if (port->hub->speed <= USB_SPEED_HIGH) {
    291317                check_port_change(port, &status, &port_changed_enabled,
    292                     USB2_HUB_PORT_STATUS_C_ENABLE, USB2_HUB_FEATURE_C_PORT_ENABLE);
     318                    USB2_HUB_PORT_STATUS_C_ENABLE,
     319                    USB2_HUB_FEATURE_C_PORT_ENABLE);
    293320        } else {
    294321                check_port_change(port, &status, &port_changed_reset,
    295                     USB3_HUB_PORT_STATUS_C_BH_RESET, USB3_HUB_FEATURE_C_BH_PORT_RESET);
     322                    USB3_HUB_PORT_STATUS_C_BH_RESET,
     323                    USB3_HUB_FEATURE_C_BH_PORT_RESET);
    296324
    297325                check_port_change(port, &status, NULL,
    298                     USB3_HUB_PORT_STATUS_C_LINK_STATE, USB3_HUB_FEATURE_C_PORT_LINK_STATE);
     326                    USB3_HUB_PORT_STATUS_C_LINK_STATE,
     327                    USB3_HUB_FEATURE_C_PORT_LINK_STATE);
    299328        }
    300329
    301330        /* Check for changes we ignored */
    302331        if (status & 0xffff0000) {
    303                 port_log(debug, port, "Port status change igored. Status: %#08" PRIx32, status);
     332                port_log(debug, port, "Port status change igored. "
     333                    "Status: %#08" PRIx32, status);
    304334        }
    305335}
  • uspace/drv/bus/usb/usbhub/status.h

    r3692678 rae3a941  
    5959        if (hub_speed == USB_SPEED_SUPER)
    6060                return USB_SPEED_SUPER;
    61         if (hub_speed == USB_SPEED_HIGH && (status & USB2_HUB_PORT_STATUS_HIGH_SPEED))
     61        if (hub_speed == USB_SPEED_HIGH
     62            && (status & USB2_HUB_PORT_STATUS_HIGH_SPEED))
    6263                return USB_SPEED_HIGH;
    6364        if ((status & USB2_HUB_PORT_STATUS_LOW_SPEED) != 0)
  • uspace/drv/bus/usb/usbhub/usbhub.h

    r3692678 rae3a941  
    8484
    8585errno_t usb_hub_set_depth(const usb_hub_dev_t *);
    86 errno_t usb_hub_get_port_status(const usb_hub_dev_t *, size_t, usb_port_status_t *);
    87 errno_t usb_hub_set_port_feature(const usb_hub_dev_t *, size_t, usb_hub_class_feature_t);
    88 errno_t usb_hub_clear_port_feature(const usb_hub_dev_t *, size_t, usb_hub_class_feature_t);
     86errno_t usb_hub_get_port_status(const usb_hub_dev_t *, size_t,
     87    usb_port_status_t *);
     88errno_t usb_hub_set_port_feature(const usb_hub_dev_t *, size_t,
     89    usb_hub_class_feature_t);
     90errno_t usb_hub_clear_port_feature(const usb_hub_dev_t *, size_t,
     91    usb_hub_class_feature_t);
    8992
    9093bool hub_port_changes_callback(usb_device_t *, uint8_t *, size_t, void *);
    9194
    92 errno_t usb_hub_reserve_default_address(usb_hub_dev_t *, async_exch_t *, usb_port_t *);
     95errno_t usb_hub_reserve_default_address(usb_hub_dev_t *, async_exch_t *,
     96    usb_port_t *);
    9397errno_t usb_hub_release_default_address(usb_hub_dev_t *, async_exch_t *);
    9498
Note: See TracChangeset for help on using the changeset viewer.