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


Ignore:
Timestamp:
2013-01-24T21:19:56Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ffa254f1
Parents:
ef40434
Message:

libusbdev: Add and use few new wrappers.

File:
1 edited

Legend:

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

    ref40434 r0f4bff8  
    258258        assert(port);
    259259        assert(hub);
    260         async_exch_t *exch = async_exchange_begin(hub->usb_device->bus_session);
     260        async_exch_t *exch = usb_device_bus_exchange_begin(hub->usb_device);
    261261        if (!exch)
    262262                return ENOMEM;
    263263        const int rc = usb_device_remove(exch, port->attached_handle);
    264         async_exchange_end(exch);
     264        usb_device_bus_exchange_end(exch);
    265265        if (rc == EOK)
    266266                port->attached_handle = -1;
    267267        return rc;
    268268
    269 #if 0
    270         if (port->attached_device.address < 0) {
    271                 usb_log_warning(
    272                     "Device on port %zu removed before being registered.\n",
    273                     port->port_number);
    274 
    275                 /*
    276                  * Device was removed before port reset completed.
    277                  * We will announce a failed port reset to unblock the
    278                  * port reset callback from new device wrapper.
    279                  */
    280                 usb_hub_port_reset_fail(port);
    281                 return EOK;
    282         }
    283 
    284         fibril_mutex_lock(&port->mutex);
    285         assert(port->attached_device.fun);
    286         usb_log_debug("Removing device on port %zu.\n", port->port_number);
    287         int ret = ddf_fun_unbind(port->attached_device.fun);
    288         if (ret != EOK) {
    289                 usb_log_error("Failed to unbind child function on port"
    290                     " %zu: %s.\n", port->port_number, str_error(ret));
    291                 fibril_mutex_unlock(&port->mutex);
    292                 return ret;
    293         }
    294 
    295         ddf_fun_destroy(port->attached_device.fun);
    296         port->attached_device.fun = NULL;
    297 
    298         ret = usb_hub_unregister_device(&hub->usb_device->hc_conn,
    299             &port->attached_device);
    300         if (ret != EOK) {
    301                 usb_log_warning("Failed to unregister address of the "
    302                     "removed device: %s.\n", str_error(ret));
    303         }
    304 
    305         port->attached_device.address = -1;
    306         fibril_mutex_unlock(&port->mutex);
    307         usb_log_info("Removed device on port %zu.\n", port->port_number);
    308         return EOK;
    309 #endif
    310269}
    311270
     
    410369}
    411370
    412 /** Callback for enabling a specific port.
    413  *
    414  * We wait on a CV until port is reseted.
    415  * That is announced via change on interrupt pipe.
    416  *
    417  * @param port_no Port number (starting at 1).
    418  * @param arg Custom argument, points to @c usb_hub_dev_t.
    419  * @return Error code.
    420  */
    421 #if 0
    422 static int enable_port_callback(void *arg)
    423 {
    424         usb_hub_port_t *port = arg;
    425         assert(port);
    426         const int rc =
    427             usb_hub_port_set_feature(port, USB_HUB_FEATURE_PORT_RESET);
    428         if (rc != EOK) {
    429                 usb_log_warning("Port reset failed: %s.\n", str_error(rc));
    430                 return rc;
    431         }
    432 
    433         /*
    434          * Wait until reset completes.
    435          */
    436         fibril_mutex_lock(&port->mutex);
    437         while (!port->reset_completed) {
    438                 fibril_condvar_wait(&port->reset_cv, &port->mutex);
    439         }
    440         fibril_mutex_unlock(&port->mutex);
    441 
    442         return port->reset_okay ? EOK : ESTALL;
    443 }
    444 #endif
    445 
    446371/** Fibril for adding a new device.
    447372 *
     
    463388        free(arg);
    464389
    465         usb_log_fatal("Creating Exchange on session %p\n",
    466             hub->usb_device->bus_session);
    467         async_exch_t *exch = async_exchange_begin(hub->usb_device->bus_session);
     390        async_exch_t *exch = usb_device_bus_exchange_begin(hub->usb_device);
    468391        if (!exch) {
    469392                usb_log_error("Failed to begin bus exchange\n");
     
    508431        }
    509432out:
    510         async_exchange_end(exch);
     433        usb_device_bus_exchange_end(exch);
    511434
    512435        fibril_mutex_lock(&hub->pending_ops_mutex);
     
    517440
    518441        return ret;
    519 #if 0
    520         struct add_device_phase1 *data = arg;
    521         assert(data);
    522 
    523         usb_address_t new_address;
    524         ddf_fun_t *child_fun;
    525 
    526         const int rc = usb_hc_new_device_wrapper(data->hub->usb_device->ddf_dev,
    527             &data->hub->usb_device->hc_conn, data->speed, enable_port_callback,
    528             data->port, &new_address, &child_fun);
    529 
    530         if (rc == EOK) {
    531                 fibril_mutex_lock(&data->port->mutex);
    532                 data->port->attached_device.fun = child_fun;
    533                 data->port->attached_device.address = new_address;
    534                 fibril_mutex_unlock(&data->port->mutex);
    535 
    536                 usb_log_info("Detected new device on `%s' (port %zu), "
    537                     "address %d (handle %" PRIun ").\n",
    538                     ddf_dev_get_name(data->hub->usb_device->ddf_dev),
    539                     data->port->port_number, new_address,
    540                     ddf_fun_get_handle(child_fun));
    541         } else {
    542                 usb_log_error("Failed registering device on port %zu: %s.\n",
    543                     data->port->port_number, str_error(rc));
    544         }
    545 
    546 
    547         fibril_mutex_lock(&data->hub->pending_ops_mutex);
    548         assert(data->hub->pending_ops_count > 0);
    549         --data->hub->pending_ops_count;
    550         fibril_condvar_signal(&data->hub->pending_ops_cv);
    551         fibril_mutex_unlock(&data->hub->pending_ops_mutex);
    552 
    553         free(arg);
    554 
    555         return rc;
    556 #endif
    557442}
    558443
Note: See TracChangeset for help on using the changeset viewer.