Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 0918382f in mainline


Ignore:
Timestamp:
2013-08-07T15:00:36Z (7 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
master
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.

Location:
uspace
Files:
6 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");
  • uspace/drv/bus/usb/usbhub/port.h

    r2757247 r0918382f  
    4444/** Information about single port on a hub. */
    4545typedef struct {
    46         /* Port number as reported in descriptors. */
    47         size_t port_number;
     46        /** Port number as reported in descriptors. */
     47        unsigned port_number;
    4848        /** Device communication pipe. */
    4949        usb_pipe_t *control_pipe;
     
    5858        /** Whether to announce the port reset as successful. */
    5959        bool reset_okay;
    60 
    61         usb_device_handle_t attached_handle;
    62 
     60        /** Device reported to USB bus driver */
     61        bool device_attached;
    6362} usb_hub_port_t;
    6463
     
    6766 * @param port Port to be initialized.
    6867 */
    69 static inline void usb_hub_port_init(usb_hub_port_t *port, size_t port_number,
     68static inline void usb_hub_port_init(usb_hub_port_t *port, unsigned port_number,
    7069    usb_pipe_t *control_pipe)
    7170{
     
    7372        port->port_number = port_number;
    7473        port->control_pipe = control_pipe;
    75         port->attached_handle = USB_DEVICE_HANDLE_INVALID;
     74        port->reset_completed = false;
     75        port->reset_okay = false;
     76        port->device_attached = false;
    7677        fibril_mutex_initialize(&port->mutex);
    7778        fibril_condvar_initialize(&port->reset_cv);
  • uspace/drv/bus/usb/usbhub/usbhub.c

    r2757247 r0918382f  
    317317
    318318                if (ret != EOK) {
    319                         usb_log_error("Cannot power on port %zu: %s.\n",
     319                        usb_log_error("Cannot power on port %u: %s.\n",
    320320                            hub_dev->ports[port].port_number, str_error(ret));
    321321                } else {
     
    406406                if (ret != EOK) {
    407407                        usb_log_warning("HUB OVER-CURRENT GONE: Cannot power on"
    408                             " port %zu: %s\n", hub_dev->ports[port].port_number,
     408                            " port %u: %s\n", hub_dev->ports[port].port_number,
    409409                            str_error(ret));
    410410                } else {
  • uspace/lib/drv/generic/remote_usb.c

    r2757247 r0918382f  
    139139 * @return Error code.
    140140 */
    141 int usb_device_enumerate(async_exch_t *exch, usb_device_handle_t *handle)
    142 {
    143         if (!exch || !handle)
    144                 return EBADMEM;
    145         sysarg_t h;
    146         const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
    147             IPC_M_USB_DEVICE_ENUMERATE, &h);
    148         if (ret == EOK)
    149                 *handle = (usb_device_handle_t)h;
     141int usb_device_enumerate(async_exch_t *exch, unsigned port)
     142{
     143        if (!exch)
     144                return EBADMEM;
     145        const int ret = async_req_2_0(exch, DEV_IFACE_ID(USB_DEV_IFACE),
     146            IPC_M_USB_DEVICE_ENUMERATE, port);
    150147        return ret;
    151148}
     
    156153 * @return Error code.
    157154 */
    158 int usb_device_remove(async_exch_t *exch, usb_device_handle_t handle)
     155int usb_device_remove(async_exch_t *exch, unsigned port)
    159156{
    160157        if (!exch)
    161158                return EBADMEM;
    162159        return async_req_2_0(exch, DEV_IFACE_ID(USB_DEV_IFACE),
    163             IPC_M_USB_DEVICE_REMOVE, handle);
     160            IPC_M_USB_DEVICE_REMOVE, port);
    164161}
    165162
     
    381378        }
    382379
    383         usb_device_handle_t handle = 0;
    384         const int ret = usb_iface->device_enumerate(fun, &handle);
    385         if (ret != EOK) {
    386                 async_answer_0(callid, ret);
    387         }
    388 
    389         async_answer_1(callid, EOK, (sysarg_t) handle);
     380        const unsigned port = DEV_IPC_GET_ARG1(*call);
     381        const int ret = usb_iface->device_enumerate(fun, port);
     382        async_answer_0(callid, ret);
    390383}
    391384
     
    400393        }
    401394
    402         usb_device_handle_t handle = DEV_IPC_GET_ARG1(*call);
    403         const int ret = usb_iface->device_remove(fun, handle);
     395        const unsigned port = DEV_IPC_GET_ARG1(*call);
     396        const int ret = usb_iface->device_remove(fun, port);
    404397        async_answer_0(callid, ret);
    405398}
  • uspace/lib/drv/include/usb_iface.h

    r2757247 r0918382f  
    4242#include <usb/usb.h>
    4343
    44 typedef intptr_t usb_device_handle_t;
    45 enum {
    46         USB_DEVICE_HANDLE_INVALID = -1
    47 };
    4844typedef async_sess_t usb_dev_session_t;
    4945
     
    5854int usb_release_default_address(async_exch_t *);
    5955
    60 int usb_device_enumerate(async_exch_t *, usb_device_handle_t *);
    61 int usb_device_remove(async_exch_t *, usb_device_handle_t);
     56int usb_device_enumerate(async_exch_t *, unsigned port);
     57int usb_device_remove(async_exch_t *, unsigned port);
    6258
    6359int usb_register_endpoint(async_exch_t *, usb_endpoint_t, usb_transfer_type_t,
     
    8177        int (*release_default_address)(ddf_fun_t *);
    8278
    83         int (*device_enumerate)(ddf_fun_t *, usb_device_handle_t *);
    84         int (*device_remove)(ddf_fun_t *, usb_device_handle_t);
     79        int (*device_enumerate)(ddf_fun_t *, unsigned);
     80        int (*device_remove)(ddf_fun_t *, unsigned);
    8581
    8682        int (*register_endpoint)(ddf_fun_t *, usb_endpoint_t,
  • uspace/lib/usbhost/src/ddf_helpers.c

    r2757247 r0918382f  
    7777} usb_dev_t;
    7878
    79 static int hcd_ddf_new_device(ddf_dev_t *device, usb_dev_t *hub, unsigned port,
    80     usb_address_t *id);
    81 static int hcd_ddf_remove_device(ddf_dev_t *device, usb_dev_t *hub,
    82     usb_address_t id);
     79static int hcd_ddf_new_device(ddf_dev_t *device, usb_dev_t *hub, unsigned port);
     80static int hcd_ddf_remove_device(ddf_dev_t *device, usb_dev_t *hub, unsigned port);
    8381
    8482
     
    164162}
    165163
    166 static int device_enumerate(ddf_fun_t *fun, usb_device_handle_t *handle)
     164static int device_enumerate(ddf_fun_t *fun, unsigned port)
    167165{
    168166        assert(fun);
     
    171169        assert(ddf_dev);
    172170        assert(dev);
    173         usb_address_t address = 0;
    174         unsigned port = 0; //TODO provide real value here
    175         usb_log_debug("Device %d reported a new USB device\n", dev->address);
    176         const int ret = hcd_ddf_new_device(ddf_dev, dev, port, &address);
    177         if (ret == EOK && handle)
    178                 *handle = address;
    179         return ret;
    180 }
    181 
    182 static int device_remove(ddf_fun_t *fun, usb_device_handle_t handle)
     171        usb_log_debug("Hub %d reported a new USB device on port: %u\n",
     172            dev->address, port);
     173        return hcd_ddf_new_device(ddf_dev, dev, port);
     174}
     175
     176static int device_remove(ddf_fun_t *fun, unsigned port)
    183177{
    184178        assert(fun);
     
    187181        assert(ddf_dev);
    188182        assert(dev);
    189         usb_log_debug("Hub `%s' reported removal of device %d\n",
    190             ddf_fun_get_name(fun), (int)handle);
    191         return hcd_ddf_remove_device(ddf_dev, dev, (usb_address_t)handle);
     183        usb_log_debug("Hub `%s' reported removal of device on port %u\n",
     184            ddf_fun_get_name(fun), port);
     185        return hcd_ddf_remove_device(ddf_dev, dev, port);
    192186}
    193187
     
    405399
    406400static int hcd_ddf_remove_device(ddf_dev_t *device, usb_dev_t *hub,
    407     usb_address_t id)
     401    unsigned port)
    408402{
    409403        assert(device);
     
    421415        list_foreach(hub->devices, it) {
    422416                victim = list_get_instance(it, usb_dev_t, link);
    423                 if (victim->address == id)
     417                if (victim->port == port)
    424418                        break;
    425419        }
    426         if (victim && victim->address == id) {
     420        if (victim && victim->port == port) {
    427421                list_remove(&victim->link);
    428422                fibril_mutex_unlock(&hc_dev->guard);
     
    432426                        hcd_release_address(hcd, victim->address);
    433427                } else {
    434                         usb_log_warning("Failed to unbind device %d: %s\n",
    435                             id, str_error(ret));
     428                        usb_log_warning("Failed to unbind device `%s': %s\n",
     429                            ddf_fun_get_name(victim->fun), str_error(ret));
    436430                }
    437431                return EOK;
     
    440434}
    441435
    442 static int hcd_ddf_new_device(ddf_dev_t *device, usb_dev_t *hub, unsigned port,
    443     usb_address_t *id)
     436static int hcd_ddf_new_device(ddf_dev_t *device, usb_dev_t *hub, unsigned port)
    444437{
    445438        assert(device);
     
    552545                hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
    553546                hcd_release_address(hcd, target.address);
    554                 return ret;
    555         }
    556         if (ret == EOK && id)
    557                 *id = target.address;
     547        }
    558548
    559549        return ret;
     
    574564
    575565        hcd_reserve_default_address(hcd, speed);
    576         const int ret = hcd_ddf_new_device(device, NULL, 0, NULL);
     566        const int ret = hcd_ddf_new_device(device, NULL, 0);
    577567        hcd_release_default_address(hcd);
    578568        return ret;
Note: See TracChangeset for help on using the changeset viewer.