Ignore:
File:
1 edited

Legend:

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

    rfab2746 r0918382f  
    4545#include <usb/dev/pipes.h>
    4646#include <usb/classes/classes.h>
    47 #include <usb/ddfiface.h>
    4847#include <usb/descriptor.h>
    4948#include <usb/dev/recognise.h>
     
    5756
    5857#define HUB_FNC_NAME "hub"
     58/** Hub status-change endpoint description.
     59 *
     60 * For more information see section 11.15.1 of USB 1.1 specification.
     61 */
     62const usb_endpoint_description_t hub_status_change_endpoint_description =
     63{
     64        .transfer_type = USB_TRANSFER_INTERRUPT,
     65        .direction = USB_DIRECTION_IN,
     66        .interface_class = USB_CLASS_HUB,
     67        .interface_subclass = 0,
     68        .interface_protocol = 0,
     69        .flags = 0
     70};
    5971
    6072/** Standard get hub global status request */
     
    99111        fibril_condvar_initialize(&hub_dev->pending_ops_cv);
    100112
    101 
    102         int opResult = usb_pipe_start_long_transfer(&usb_dev->ctrl_pipe);
    103         if (opResult != EOK) {
    104                 usb_log_error("Failed to start long ctrl pipe transfer: %s\n",
    105                     str_error(opResult));
    106                 return opResult;
    107         }
    108 
    109113        /* Set hub's first configuration. (There should be only one) */
    110         opResult = usb_set_first_configuration(usb_dev);
    111         if (opResult != EOK) {
    112                 usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
     114        int opResult = usb_set_first_configuration(usb_dev);
     115        if (opResult != EOK) {
    113116                usb_log_error("Could not set hub configuration: %s\n",
    114117                    str_error(opResult));
     
    119122        opResult = usb_hub_process_hub_specific_info(hub_dev);
    120123        if (opResult != EOK) {
    121                 usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
    122124                usb_log_error("Could process hub specific info, %s\n",
    123125                    str_error(opResult));
     
    127129        /* Create hub control function. */
    128130        usb_log_debug("Creating DDF function '" HUB_FNC_NAME "'.\n");
    129         hub_dev->hub_fun = ddf_fun_create(hub_dev->usb_device->ddf_dev,
     131        hub_dev->hub_fun = usb_device_ddf_fun_create(hub_dev->usb_device,
    130132            fun_exposed, HUB_FNC_NAME);
    131133        if (hub_dev->hub_fun == NULL) {
    132                 usb_pipe_end_long_transfer(&usb_dev->ctrl_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);
    141141                usb_log_error("Failed to bind hub function: %s.\n",
    142142                   str_error(opResult));
     
    146146
    147147        /* Start hub operation. */
    148         opResult = usb_device_auto_poll(hub_dev->usb_device, 0,
    149             hub_port_changes_callback, ((hub_dev->port_count + 1 + 8) / 8),
    150             usb_hub_polling_terminated_callback, hub_dev);
    151         if (opResult != EOK) {
    152                 usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
     148        opResult = usb_device_auto_poll_desc(hub_dev->usb_device,
     149            &hub_status_change_endpoint_description,
     150            hub_port_changes_callback, ((hub_dev->port_count + 1 + 7) / 8),
     151            -1, usb_hub_polling_terminated_callback, hub_dev);
     152        if (opResult != EOK) {
    153153                /* Function is already bound */
    154154                ddf_fun_unbind(hub_dev->hub_fun);
     
    160160        hub_dev->running = true;
    161161        usb_log_info("Controlling hub '%s' (%zu ports).\n",
    162             ddf_dev_get_name(hub_dev->usb_device->ddf_dev), hub_dev->port_count);
    163 
    164         usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
     162            usb_device_get_name(hub_dev->usb_device), hub_dev->port_count);
     163
    165164        return EOK;
    166165}
     
    185184{
    186185        assert(usb_dev);
    187         usb_hub_dev_t *hub = usb_dev->driver_data;
     186        usb_hub_dev_t *hub = usb_device_data_get(usb_dev);
    188187        assert(hub);
    189188        unsigned tries = 10;
     
    192191                if (!tries--) {
    193192                        usb_log_error("Can't remove hub, still running.\n");
    194                         return EBUSY;
     193                        return EINPROGRESS;
    195194                }
    196195        }
     
    199198
    200199        for (size_t port = 0; port < hub->port_count; ++port) {
    201                 if (hub->ports[port].attached_device.fun) {
    202                         const int ret =
    203                             usb_hub_port_fini(&hub->ports[port], hub);
    204                         if (ret != EOK)
    205                                 return ret;
    206                 }
     200                const int ret = usb_hub_port_fini(&hub->ports[port], hub);
     201                if (ret != EOK)
     202                        return ret;
    207203        }
    208204        free(hub->ports);
     
    247243
    248244        /* N + 1 bit indicates change on port N */
    249         for (size_t port = 0; port < hub->port_count + 1; port++) {
     245        for (size_t port = 0; port < hub->port_count; ++port) {
    250246                const size_t bit = port + 1;
    251247                const bool change = (change_bitmap[bit / 8] >> (bit % 8)) & 1;
     
    273269        /* Get hub descriptor. */
    274270        usb_log_debug("Retrieving descriptor\n");
    275         usb_pipe_t *control_pipe = &hub_dev->usb_device->ctrl_pipe;
     271        usb_pipe_t *control_pipe =
     272            usb_device_get_default_pipe(hub_dev->usb_device);
    276273
    277274        usb_hub_descriptor_header_t descriptor;
     
    311308        }
    312309
    313         usb_log_info("Hub port power switching enabled.\n");
     310        usb_log_info("Hub port power switching enabled (%s).\n",
     311            hub_dev->per_port_power ? "per port" : "ganged");
    314312
    315313        for (size_t port = 0; port < hub_dev->port_count; ++port) {
     
    319317
    320318                if (ret != EOK) {
    321                         usb_log_error("Cannot power on port %zu: %s.\n",
     319                        usb_log_error("Cannot power on port %u: %s.\n",
    322320                            hub_dev->ports[port].port_number, str_error(ret));
    323321                } else {
     
    345343        /* Get number of possible configurations from device descriptor */
    346344        const size_t configuration_count =
    347             usb_device->descriptors.device.configuration_count;
     345            usb_device_descriptors(usb_device)->device.configuration_count;
    348346        usb_log_debug("Hub has %zu configurations.\n", configuration_count);
    349347
     
    353351        }
    354352
    355         if (usb_device->descriptors.configuration_size
    356             < sizeof(usb_standard_configuration_descriptor_t)) {
     353        // TODO: Make sure that the cast is correct
     354        const size_t config_size =
     355            usb_device_descriptors(usb_device)->full_config_size;
     356        const usb_standard_configuration_descriptor_t *config_descriptor =
     357            usb_device_descriptors(usb_device)->full_config;
     358
     359        if (config_size < sizeof(usb_standard_configuration_descriptor_t)) {
    357360            usb_log_error("Configuration descriptor is not big enough"
    358361                " to fit standard configuration descriptor.\n");
     
    360363        }
    361364
    362         // TODO: Make sure that the cast is correct
    363         usb_standard_configuration_descriptor_t *config_descriptor
    364             = (usb_standard_configuration_descriptor_t *)
    365             usb_device->descriptors.configuration;
    366 
    367365        /* Set configuration. Use the configuration that was in
    368366         * usb_device->descriptors.configuration i.e. The first one. */
    369367        const int opResult = usb_request_set_configuration(
    370             &usb_device->ctrl_pipe, config_descriptor->configuration_number);
     368            usb_device_get_default_pipe(usb_device),
     369            config_descriptor->configuration_number);
    371370        if (opResult != EOK) {
    372371                usb_log_error("Failed to set hub configuration: %s.\n",
     
    407406                if (ret != EOK) {
    408407                        usb_log_warning("HUB OVER-CURRENT GONE: Cannot power on"
    409                             " port %zu: %s\n", hub_dev->ports[port].port_number,
     408                            " port %u: %s\n", hub_dev->ports[port].port_number,
    410409                            str_error(ret));
    411410                } else {
     
    428427        assert(hub_dev->usb_device);
    429428        usb_log_debug("Global interrupt on a hub\n");
    430         usb_pipe_t *control_pipe = &hub_dev->usb_device->ctrl_pipe;
     429        usb_pipe_t *control_pipe =
     430            usb_device_get_default_pipe(hub_dev->usb_device);
    431431
    432432        usb_hub_status_t status;
     
    452452                /* Ack change in hub OC flag */
    453453                const int ret = usb_request_clear_feature(
    454                     &hub_dev->usb_device->ctrl_pipe, USB_REQUEST_TYPE_CLASS,
     454                    control_pipe, USB_REQUEST_TYPE_CLASS,
    455455                    USB_REQUEST_RECIPIENT_DEVICE,
    456456                    USB_HUB_FEATURE_C_HUB_OVER_CURRENT, 0);
Note: See TracChangeset for help on using the changeset viewer.