Changeset 3df8ea9 in mainline


Ignore:
Timestamp:
2013-01-07T16:52:15Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e6becb9
Parents:
c8c758d
Message:

usbhub: Switch to new usb interface functions and provided bus_session.

NOTE: This changes tree usb heirarchy into flat.
Cleanup will follow.

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

Legend:

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

    rc8c758d r3df8ea9  
    5858    usb_port_status_t status);
    5959static int get_port_status(usb_hub_port_t *port, usb_port_status_t *status);
    60 static int enable_port_callback(void *arg);
     60//static int enable_port_callback(void *arg);
    6161static int add_device_phase1_worker_fibril(void *arg);
    6262static int create_add_device_fibril(usb_hub_port_t *port, usb_hub_dev_t *hub,
     
    259259        assert(port);
    260260        assert(hub);
     261        async_exch_t *exch = async_exchange_begin(hub->usb_device->bus_session);
     262        if (!exch)
     263                return ENOMEM;
     264        const int rc = usb_device_remove(exch, port->attached_handle);
     265        async_exchange_end(exch);
     266        if (rc == EOK)
     267                port->attached_handle = -1;
     268        return rc;
     269
     270#if 0
    261271        if (port->attached_device.address < 0) {
    262272                usb_log_warning(
     
    298308        usb_log_info("Removed device on port %zu.\n", port->port_number);
    299309        return EOK;
     310#endif
    300311}
    301312
     
    376387}
    377388
     389static int port_enable(usb_hub_port_t *port, bool enable)
     390{
     391        if (enable) {
     392                const int rc =
     393                    usb_hub_port_set_feature(port, USB_HUB_FEATURE_PORT_RESET);
     394                if (rc != EOK) {
     395                        usb_log_error("Port reset failed: %s.\n",
     396                            str_error(rc));
     397                } else {
     398                        /* Wait until reset completes. */
     399                        fibril_mutex_lock(&port->mutex);
     400                        while (!port->reset_completed) {
     401                                fibril_condvar_wait(&port->reset_cv,
     402                                    &port->mutex);
     403                        }
     404                        fibril_mutex_unlock(&port->mutex);
     405                }
     406                return port->reset_okay ? EOK : ESTALL;
     407        } else {
     408                return usb_hub_port_clear_feature(port,
     409                                USB_HUB_FEATURE_PORT_ENABLE);
     410        }
     411}
     412
    378413/** Callback for enabling a specific port.
    379414 *
     
    385420 * @return Error code.
    386421 */
     422#if 0
    387423static int enable_port_callback(void *arg)
    388424{
     
    407443        return port->reset_okay ? EOK : ESTALL;
    408444}
     445#endif
    409446
    410447/** Fibril for adding a new device.
     
    418455int add_device_phase1_worker_fibril(void *arg)
    419456{
     457        struct add_device_phase1 *params = arg;
     458        assert(params);
     459
     460        usb_hub_dev_t *hub = params->hub;
     461        usb_hub_port_t *port = params->port;
     462        const usb_speed_t speed = params->speed;
     463        free(arg);
     464
     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);
     468        if (!exch) {
     469                usb_log_error("Failed to begin bus exchange\n");
     470                return ENOMEM;
     471        }
     472
     473        usb_log_fatal("reserving default address\n");
     474
     475        /* Reserve default address */
     476        int ret;
     477        while ((ret = usb_reserve_default_address(exch, speed)) == ENOENT) {
     478                usb_log_fatal("reserving default address %d\n", ret);
     479                async_usleep(1000000);
     480        }
     481        if (ret != EOK) {
     482                usb_log_error("Failed to reserve default address: %s\n",
     483                    str_error(ret));
     484                async_exchange_end(exch);
     485                return ret;
     486        }
     487
     488        /* Reset port */
     489        port_enable(port, true);
     490        if (!port->reset_completed || !port->reset_okay) {
     491                usb_log_error("Failed to reset port %zu\n", port->port_number);
     492                if (usb_release_default_address(exch) != EOK)
     493                        usb_log_warning("Failed to release default address\n");
     494                async_exchange_end(exch);
     495                return EIO;
     496        }
     497
     498        ret = usb_device_enumerate(exch, &port->attached_handle);
     499        if (ret != EOK) {
     500                usb_log_error("Failed to reset port %zu\n", port->port_number);
     501                if (port_enable(port, false) != EOK) {
     502                        usb_log_warning("Failed to disable port %zu, NOT "
     503                            "releasing default address.\n", port->port_number);
     504                } else {
     505                        if (usb_release_default_address(exch) != EOK)
     506                                usb_log_warning(
     507                                    "Failed to release default address\n");
     508                }
     509        }
     510        async_exchange_end(exch);
     511        return ret;
     512#if 0
    420513        struct add_device_phase1 *data = arg;
    421514        assert(data);
     
    454547
    455548        return rc;
     549#endif
    456550}
    457551
  • uspace/drv/bus/usb/usbhub/port.h

    rc8c758d r3df8ea9  
    5959        bool reset_okay;
    6060
     61        usb_device_handle_t attached_handle;
     62
    6163        /** Information about attached device. */
    6264        usb_hub_attached_device_t attached_device;
     
    7577        port->port_number = port_number;
    7678        port->control_pipe = control_pipe;
     79        port->attached_handle = USB_DEVICE_HANDLE_INVALID;
    7780        fibril_mutex_initialize(&port->mutex);
    7881        fibril_condvar_initialize(&port->reset_cv);
Note: See TracChangeset for help on using the changeset viewer.