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


Ignore:
Timestamp:
2013-08-07T15:00:36Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
14dd4c9
Parents:
2757247
Message:

usb: Switch to using port number as device identifier.

Port number info will be needed for HS SPLIT transactions. Moreover,
it can be used to produce predictable, persistent device names.

Switch port_number from size_t to unsigned. There are max 256 ports so
even short would be enough.

File:
1 edited

Legend:

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

    r2757247 r0918382f  
    6464{
    6565        assert(port);
    66         if (port->attached_handle != USB_DEVICE_HANDLE_INVALID)
     66        if (port->device_attached)
    6767                return usb_hub_port_device_gone(port, hub);
    6868        return EOK;
     
    139139        assert(port);
    140140        assert(hub);
    141         usb_log_debug("Interrupt at port %zu\n", port->port_number);
     141        usb_log_debug("Interrupt at port %u\n", port->port_number);
    142142
    143143        usb_port_status_t status = 0;
    144144        const int opResult = get_port_status(port, &status);
    145145        if (opResult != EOK) {
    146                 usb_log_error("Failed to get port %zu status: %s.\n",
     146                usb_log_error("Failed to get port %u status: %s.\n",
    147147                    port->port_number, str_error(opResult));
    148148                return;
     
    153153                const bool connected =
    154154                    (status & USB_HUB_PORT_STATUS_CONNECTION) != 0;
    155                 usb_log_debug("Connection change on port %zu: device %s.\n",
     155                usb_log_debug("Connection change on port %u: device %s.\n",
    156156                    port->port_number, connected ? "attached" : "removed");
    157157
     
    169169                        if (opResult != EOK) {
    170170                                usb_log_error(
    171                                     "Cannot handle change on port %zu: %s.\n",
     171                                    "Cannot handle change on port %u: %s.\n",
    172172                                    port->port_number, str_error(opResult));
    173173                        }
     
    183183        /* Enable change, ports are automatically disabled on errors. */
    184184        if (status & USB_HUB_PORT_C_STATUS_ENABLED) {
    185                 usb_log_info("Port %zu, disabled because of errors.\n",
     185                usb_log_info("Port %u, disabled because of errors.\n",
    186186                   port->port_number);
    187187                usb_hub_port_device_gone(port, hub);
     
    190190                if (rc != EOK) {
    191191                        usb_log_error(
    192                             "Failed to clear port %zu enable change feature: "
     192                            "Failed to clear port %u enable change feature: "
    193193                            "%s.\n", port->port_number, str_error(rc));
    194194                }
     
    198198        /* Suspend change */
    199199        if (status & USB_HUB_PORT_C_STATUS_SUSPEND) {
    200                 usb_log_error("Port %zu went to suspend state, this should"
     200                usb_log_error("Port %u went to suspend state, this should"
    201201                    "NOT happen as we do not support suspend state!",
    202202                    port->port_number);
     
    205205                if (rc != EOK) {
    206206                        usb_log_error(
    207                             "Failed to clear port %zu suspend change feature: "
     207                            "Failed to clear port %u suspend change feature: "
    208208                            "%s.\n", port->port_number, str_error(rc));
    209209                }
     
    221221                if (rc != EOK) {
    222222                        usb_log_error(
    223                             "Failed to clear port %zu OC change feature: %s.\n",
     223                            "Failed to clear port %u OC change feature: %s.\n",
    224224                            port->port_number, str_error(rc));
    225225                }
     
    229229                        if (rc != EOK) {
    230230                                usb_log_error(
    231                                     "Failed to set port %zu power after OC:"
     231                                    "Failed to set port %u power after OC:"
    232232                                    " %s.\n", port->port_number, str_error(rc));
    233233                        }
     
    240240        }
    241241
    242         usb_log_debug("Port %zu status 0x%08" PRIx32 "\n",
     242        usb_log_debug("Port %u status %#08" PRIx32 "\n",
    243243            port->port_number, status);
    244244}
     
    260260        if (!exch)
    261261                return ENOMEM;
    262         const int rc = usb_device_remove(exch, port->attached_handle);
     262        const int rc = usb_device_remove(exch, port->port_number);
    263263        usb_device_bus_exchange_end(exch);
    264264        if (rc == EOK)
    265                 port->attached_handle = -1;
     265                port->device_attached = false;
    266266        return rc;
    267267
     
    286286
    287287        if (port->reset_okay) {
    288                 usb_log_debug("Port %zu reset complete.\n", port->port_number);
     288                usb_log_debug("Port %u reset complete.\n", port->port_number);
    289289        } else {
    290290                usb_log_warning(
    291                     "Port %zu reset complete but port not enabled.\n",
     291                    "Port %u reset complete but port not enabled.\n",
    292292                    port->port_number);
    293293        }
     
    299299        if (rc != EOK) {
    300300                usb_log_error(
    301                     "Failed to clear port %zu reset change feature: %s.\n",
     301                    "Failed to clear port %u reset change feature: %s.\n",
    302302                    port->port_number, str_error(rc));
    303303        }
     
    407407        port_enable(port, true);
    408408        if (!port->reset_completed || !port->reset_okay) {
    409                 usb_log_error("Failed to reset port %zu\n", port->port_number);
     409                usb_log_error("Failed to reset port %u\n", port->port_number);
    410410                if (usb_release_default_address(exch) != EOK)
    411411                        usb_log_warning("Failed to release default address\n");
     
    414414        }
    415415
    416         ret = usb_device_enumerate(exch, &port->attached_handle);
     416        ret = usb_device_enumerate(exch, port->port_number);
    417417        if (ret != EOK) {
    418                 usb_log_error("Failed to reset port %zu\n", port->port_number);
     418                usb_log_error("Failed to enumerate device on port %u\n",
     419                    port->port_number);
    419420                if (port_enable(port, false) != EOK) {
    420                         usb_log_warning("Failed to disable port %zu, NOT "
     421                        usb_log_warning("Failed to disable port %u, NOT "
    421422                            "releasing default address.\n", port->port_number);
    422423                } else {
     
    426427                }
    427428        } else {
     429                port->device_attached = true;
    428430                if (usb_release_default_address(exch) != EOK)
    429431                        usb_log_warning("Failed to release default address\n");
Note: See TracChangeset for help on using the changeset viewer.