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

Changeset 0f4bff8 in mainline


Ignore:
Timestamp:
2013-01-24T21:19:56Z (9 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
ffa254f1
Parents:
ef40434
Message:

libusbdev: Add and use few new wrappers.

Location:
uspace
Files:
4 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
  • uspace/drv/bus/usb/usbhub/usbhub.c

    ref40434 r0f4bff8  
    9999        fibril_condvar_initialize(&hub_dev->pending_ops_cv);
    100100
    101 
    102         int opResult = usb_pipe_start_long_transfer(&usb_dev->ctrl_pipe);
     101        usb_pipe_t *control_pipe = usb_device_get_default_pipe(usb_dev);
     102
     103        int opResult = usb_pipe_start_long_transfer(control_pipe);
    103104        if (opResult != EOK) {
    104105                usb_log_error("Failed to start long ctrl pipe transfer: %s\n",
     
    110111        opResult = usb_set_first_configuration(usb_dev);
    111112        if (opResult != EOK) {
    112                 usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
     113                usb_pipe_end_long_transfer(control_pipe);
    113114                usb_log_error("Could not set hub configuration: %s\n",
    114115                    str_error(opResult));
     
    119120        opResult = usb_hub_process_hub_specific_info(hub_dev);
    120121        if (opResult != EOK) {
    121                 usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
     122                usb_pipe_end_long_transfer(control_pipe);
    122123                usb_log_error("Could process hub specific info, %s\n",
    123124                    str_error(opResult));
     
    130131            fun_exposed, HUB_FNC_NAME);
    131132        if (hub_dev->hub_fun == NULL) {
    132                 usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
     133                usb_pipe_end_long_transfer(control_pipe);
    133134                usb_log_error("Failed to create hub function.\n");
    134135                return ENOMEM;
     
    138139        opResult = ddf_fun_bind(hub_dev->hub_fun);
    139140        if (opResult != EOK) {
    140                 usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
     141                usb_pipe_end_long_transfer(control_pipe);
    141142                usb_log_error("Failed to bind hub function: %s.\n",
    142143                   str_error(opResult));
     
    151152            usb_hub_polling_terminated_callback, hub_dev);
    152153        if (opResult != EOK) {
    153                 usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
     154                usb_pipe_end_long_transfer(control_pipe);
    154155                /* Function is already bound */
    155156                ddf_fun_unbind(hub_dev->hub_fun);
     
    163164            ddf_dev_get_name(hub_dev->usb_device->ddf_dev), hub_dev->port_count);
    164165
    165         usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
     166        usb_pipe_end_long_transfer(control_pipe);
    166167        return EOK;
    167168}
     
    186187{
    187188        assert(usb_dev);
    188         usb_hub_dev_t *hub = usb_dev->driver_data;
     189        usb_hub_dev_t *hub = usb_device_data_get(usb_dev);
    189190        assert(hub);
    190191        unsigned tries = 10;
     
    271272        /* Get hub descriptor. */
    272273        usb_log_debug("Retrieving descriptor\n");
    273         usb_pipe_t *control_pipe = &hub_dev->usb_device->ctrl_pipe;
     274        usb_pipe_t *control_pipe =
     275            usb_device_get_default_pipe(hub_dev->usb_device);
    274276
    275277        usb_hub_descriptor_header_t descriptor;
     
    360362
    361363        // TODO: Make sure that the cast is correct
    362         usb_standard_configuration_descriptor_t *config_descriptor
     364        const usb_standard_configuration_descriptor_t *config_descriptor
    363365            = (usb_standard_configuration_descriptor_t *)
    364366            usb_device->descriptors.configuration;
     
    367369         * usb_device->descriptors.configuration i.e. The first one. */
    368370        const int opResult = usb_request_set_configuration(
    369             &usb_device->ctrl_pipe, config_descriptor->configuration_number);
     371            usb_device_get_default_pipe(usb_device),
     372            config_descriptor->configuration_number);
    370373        if (opResult != EOK) {
    371374                usb_log_error("Failed to set hub configuration: %s.\n",
     
    427430        assert(hub_dev->usb_device);
    428431        usb_log_debug("Global interrupt on a hub\n");
    429         usb_pipe_t *control_pipe = &hub_dev->usb_device->ctrl_pipe;
     432        usb_pipe_t *control_pipe =
     433            usb_device_get_default_pipe(hub_dev->usb_device);
    430434
    431435        usb_hub_status_t status;
     
    451455                /* Ack change in hub OC flag */
    452456                const int ret = usb_request_clear_feature(
    453                     &hub_dev->usb_device->ctrl_pipe, USB_REQUEST_TYPE_CLASS,
     457                    control_pipe, USB_REQUEST_TYPE_CLASS,
    454458                    USB_REQUEST_RECIPIENT_DEVICE,
    455459                    USB_HUB_FEATURE_C_HUB_OVER_CURRENT, 0);
  • uspace/lib/usbdev/include/usb/dev/driver.h

    ref40434 r0f4bff8  
    110110         */
    111111        void *driver_data;
     112
    112113        usb_dev_session_t *bus_session;
    113114} usb_device_t;
     
    170171void usb_device_deinit(usb_device_t *);
    171172
     173async_exch_t * usb_device_bus_exchange_begin(usb_device_t *);
     174void usb_device_bus_exchange_end(async_exch_t *);
     175
    172176int usb_device_select_interface(usb_device_t *, uint8_t,
    173177    const usb_endpoint_description_t **);
     
    180184    usb_endpoint_mapping_t **, size_t *);
    181185void usb_device_destroy_pipes(usb_endpoint_mapping_t *, size_t);
     186usb_pipe_t *usb_device_get_default_pipe(usb_device_t *);
     187usb_pipe_t *usb_device_get_pipe(usb_device_t *, usb_endpoint_t, usb_direction_t);
    182188
    183189void * usb_device_data_alloc(usb_device_t *, size_t);
     190void * usb_device_data_get(usb_device_t *);
    184191
    185192size_t usb_interface_count_alternates(const uint8_t *, size_t, uint8_t);
  • uspace/lib/usbdev/src/devdrv.c

    ref40434 r0f4bff8  
    388388}
    389389
     390usb_pipe_t *usb_device_get_default_pipe(usb_device_t *usb_dev)
     391{
     392        assert(usb_dev);
     393        return &usb_dev->ctrl_pipe;
     394}
     395
    390396/** Initialize new instance of USB device.
    391397 *
     
    515521}
    516522
     523async_exch_t * usb_device_bus_exchange_begin(usb_device_t *usb_dev)
     524{
     525        assert(usb_dev);
     526        return async_exchange_begin(usb_dev->bus_session);
     527}
     528
     529void usb_device_bus_exchange_end(async_exch_t *exch)
     530{
     531        async_exchange_end(exch);
     532}
     533
    517534/** Allocate driver specific data.
    518535 * @param usb_dev usb_device structure.
     
    528545}
    529546
     547void * usb_device_data_get(usb_device_t *usb_dev)
     548{
     549        assert(usb_dev);
     550        return usb_dev->driver_data;
     551}
    530552/**
    531553 * @}
Note: See TracChangeset for help on using the changeset viewer.