Ignore:
File:
1 edited

Legend:

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

    r400f363 r8895d05  
    11/*
    22 * Copyright (c) 2010 Matus Dekanek
    3  * Copyright (c) 2011 Jan Vesely
    43 * All rights reserved.
    54 *
     
    3938#include <str_error.h>
    4039#include <inttypes.h>
    41 #include <stdio.h>
    42 
    43 #include <usb/usb.h>
    44 #include <usb/debug.h>
    45 #include <usb/dev/pipes.h>
    46 #include <usb/classes/classes.h>
     40
     41#include <usb_iface.h>
    4742#include <usb/ddfiface.h>
    4843#include <usb/descriptor.h>
     
    5146#include <usb/classes/hub.h>
    5247#include <usb/dev/poll.h>
    53 #include <usb_iface.h>
     48#include <stdio.h>
    5449
    5550#include "usbhub.h"
    56 #include "status.h"
    57 
    58 #define HUB_FNC_NAME "hub"
    59 
    60 /** Standard get hub global status request */
    61 static const usb_device_request_setup_packet_t get_hub_status_request = {
    62         .request_type = USB_HUB_REQ_TYPE_GET_HUB_STATUS,
    63         .request = USB_HUB_REQUEST_GET_STATUS,
    64         .index = 0,
    65         .value = 0,
    66         .length = sizeof(usb_hub_status_t),
    67 };
    68 
    69 static int usb_set_first_configuration(usb_device_t *usb_device);
     51#include "usbhub_private.h"
     52#include "port_status.h"
     53#include <usb/usb.h>
     54#include <usb/dev/pipes.h>
     55#include <usb/classes/classes.h>
     56
     57
    7058static usb_hub_info_t * usb_hub_info_create(usb_device_t *usb_dev);
     59
    7160static int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info);
    72 static void usb_hub_over_current(const usb_hub_info_t *hub_info,
     61
     62static int usb_hub_set_configuration(usb_hub_info_t *hub_info);
     63
     64static int usb_hub_start_hub_fibril(usb_hub_info_t *hub_info);
     65
     66static int usb_process_hub_over_current(usb_hub_info_t *hub_info,
    7367    usb_hub_status_t status);
    74 static void usb_hub_global_interrupt(const usb_hub_info_t *hub_info);
     68
     69static int usb_process_hub_local_power_change(usb_hub_info_t *hub_info,
     70    usb_hub_status_t status);
     71
     72static void usb_hub_process_global_interrupt(usb_hub_info_t *hub_info);
     73
    7574static void usb_hub_polling_terminated_callback(usb_device_t *device,
    7675    bool was_error, void *data);
    7776
     77
     78//*********************************************
     79//
     80//  hub driver code, initialization
     81//
     82//*********************************************
     83
    7884/**
    7985 * Initialize hub device driver fibril
    8086 *
    81  * Creates hub representation and fibril that periodically checks hub's status.
     87 * Creates hub representation and fibril that periodically checks hub`s status.
    8288 * Hub representation is passed to the fibril.
    8389 * @param usb_dev generic usb device information
    8490 * @return error code
    8591 */
    86 int usb_hub_add_device(usb_device_t *usb_dev)
    87 {
    88         assert(usb_dev);
    89         /* Create driver soft-state structure */
     92int usb_hub_add_device(usb_device_t *usb_dev) {
     93        if (!usb_dev) return EINVAL;
    9094        usb_hub_info_t *hub_info = usb_hub_info_create(usb_dev);
    91         if (hub_info == NULL) {
    92                 usb_log_error("Failed to create hun driver structure.\n");
    93                 return ENOMEM;
    94         }
    95 
    96         /* Create hc connection */
     95        //create hc connection
    9796        usb_log_debug("Initializing USB wire abstraction.\n");
    9897        int opResult = usb_hc_connection_initialize_from_device(
    99             &hub_info->connection, hub_info->usb_device->ddf_dev);
    100         if (opResult != EOK) {
    101                 usb_log_error("Could not initialize connection to device: %s\n",
     98            &hub_info->connection,
     99            hub_info->usb_device->ddf_dev);
     100        if (opResult != EOK) {
     101                usb_log_error("Could not initialize connection to device, "
     102                    " %s\n",
    102103                    str_error(opResult));
    103104                free(hub_info);
     
    105106        }
    106107
    107         /* Set hub's first configuration. (There should be only one) */
    108         opResult = usb_set_first_configuration(usb_dev);
    109         if (opResult != EOK) {
    110                 usb_log_error("Could not set hub configuration: %s\n",
     108        //set hub configuration
     109        opResult = usb_hub_set_configuration(hub_info);
     110        if (opResult != EOK) {
     111                usb_log_error("Could not set hub configuration, %s\n",
    111112                    str_error(opResult));
    112113                free(hub_info);
    113114                return opResult;
    114115        }
    115 
    116116        //get port count and create attached_devs
    117117        opResult = usb_hub_process_hub_specific_info(hub_info);
     
    123123        }
    124124
    125         usb_log_debug("Creating DDF function '" HUB_FNC_NAME "'.\n");
     125        usb_log_debug("Creating 'hub' function in DDF.\n");
    126126        ddf_fun_t *hub_fun = ddf_fun_create(hub_info->usb_device->ddf_dev,
    127             fun_exposed, HUB_FNC_NAME);
    128         if (hub_fun == NULL) {
    129                 usb_log_error("Failed to create hub function.\n");
     127            fun_exposed, "hub");
     128        assert(hub_fun != NULL);
     129        hub_fun->ops = NULL;
     130
     131        opResult = ddf_fun_bind(hub_fun);
     132        assert(opResult == EOK);
     133
     134        opResult = usb_hub_start_hub_fibril(hub_info);
     135        if (opResult != EOK)
    130136                free(hub_info);
    131                 return ENOMEM;
    132         }
    133 
    134         opResult = ddf_fun_bind(hub_fun);
    135         if (opResult != EOK) {
    136                 usb_log_error("Failed to bind hub function: %s.\n",
    137                    str_error(opResult));
    138                 free(hub_info);
    139                 ddf_fun_destroy(hub_fun);
    140                 return opResult;
    141         }
    142 
    143         opResult = usb_device_auto_poll(hub_info->usb_device, 0,
    144             hub_port_changes_callback, ((hub_info->port_count + 1) / 8) + 1,
    145             usb_hub_polling_terminated_callback, hub_info);
    146         if (opResult != EOK) {
    147                 ddf_fun_destroy(hub_fun);
    148                 free(hub_info);
    149                 usb_log_error("Failed to create polling fibril: %s.\n",
    150                     str_error(opResult));
    151                 return opResult;
    152         }
    153         usb_log_info("Controlling hub '%s' (%zu ports).\n",
    154             hub_info->usb_device->ddf_dev->name, hub_info->port_count);
    155 
    156         return EOK;
    157 }
    158 /*----------------------------------------------------------------------------*/
     137        return opResult;
     138}
     139
    159140/** Callback for polling hub for changes.
    160141 *
     
    166147 */
    167148bool hub_port_changes_callback(usb_device_t *dev,
    168     uint8_t *change_bitmap, size_t change_bitmap_size, void *arg)
    169 {
     149    uint8_t *change_bitmap, size_t change_bitmap_size, void *arg) {
    170150        usb_log_debug("hub_port_changes_callback\n");
    171         usb_hub_info_t *hub = arg;
    172         assert(hub);
    173 
    174         /* It is an error condition if we didn't receive enough data */
     151        usb_hub_info_t *hub = (usb_hub_info_t *) arg;
     152
     153        /* FIXME: check that we received enough bytes. */
    175154        if (change_bitmap_size == 0) {
    176                 return false;
    177         }
    178 
    179         /* Lowest bit indicates global change */
    180         const bool change = change_bitmap[0] & 1;
     155                goto leave;
     156        }
     157
     158        bool change;
     159        change = ((uint8_t*) change_bitmap)[0] & 1;
    181160        if (change) {
    182                 usb_hub_global_interrupt(hub);
    183         }
    184 
    185         /* N + 1 bit indicates change on port N */
    186         size_t port = 1;
    187         for (; port < hub->port_count + 1; port++) {
    188                 const bool change = (change_bitmap[port / 8] >> (port % 8)) & 1;
     161                usb_hub_process_global_interrupt(hub);
     162        }
     163
     164        size_t port;
     165        for (port = 1; port < hub->port_count + 1; port++) {
     166                bool change = (change_bitmap[port / 8] >> (port % 8)) % 2;
    189167                if (change) {
    190                         usb_hub_port_process_interrupt(&hub->ports[port], hub);
     168                        usb_hub_process_port_interrupt(hub, port);
    191169                }
    192170        }
     171leave:
     172        /* FIXME: proper interval. */
     173        async_usleep(1000 * 250);
     174
    193175        return true;
    194176}
    195 /*----------------------------------------------------------------------------*/
     177
     178
     179//*********************************************
     180//
     181//  support functions
     182//
     183//*********************************************
     184
    196185/**
    197186 * create usb_hub_info_t structure
     
    201190 * @return basic usb_hub_info_t structure
    202191 */
    203 static usb_hub_info_t * usb_hub_info_create(usb_device_t *usb_dev)
    204 {
    205         assert(usb_dev);
    206         usb_hub_info_t *info = malloc(sizeof(usb_hub_info_t));
    207         if (!info)
    208             return NULL;
    209 
    210         info->usb_device = usb_dev;
    211 
    212         info->ports = NULL;
    213         info->port_count = -1;
    214         fibril_mutex_initialize(&info->pending_ops_mutex);
    215         fibril_condvar_initialize(&info->pending_ops_cv);
    216         info->pending_ops_count = 0;
    217 
    218         return info;
    219 }
    220 /*----------------------------------------------------------------------------*/
     192static usb_hub_info_t * usb_hub_info_create(usb_device_t *usb_dev) {
     193        usb_hub_info_t * result = malloc(sizeof (usb_hub_info_t));
     194        if (!result) return NULL;
     195        result->usb_device = usb_dev;
     196        result->status_change_pipe = usb_dev->pipes[0].pipe;
     197        result->control_pipe = &usb_dev->ctrl_pipe;
     198        result->is_default_address_used = false;
     199
     200        result->ports = NULL;
     201        result->port_count = (size_t) - 1;
     202        fibril_mutex_initialize(&result->port_mutex);
     203
     204        fibril_mutex_initialize(&result->pending_ops_mutex);
     205        fibril_condvar_initialize(&result->pending_ops_cv);
     206        result->pending_ops_count = 0;
     207        return result;
     208}
     209
    221210/**
    222211 * Load hub-specific information into hub_info structure and process if needed
    223212 *
    224  * Read port count and initialize structures holding per port information.
    225  * If there are any non-removable devices, start initializing them.
     213 * Particularly read port count and initialize structure holding port
     214 * information. If there are non-removable devices, start initializing them.
    226215 * This function is hub-specific and should be run only after the hub is
    227  * configured using usb_set_first_configuration function.
     216 * configured using usb_hub_set_configuration function.
    228217 * @param hub_info hub representation
    229218 * @return error code
    230219 */
    231 static int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info)
     220int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info)
    232221{
    233         assert(hub_info);
    234 
    235         /* Get hub descriptor. */
     222        // get hub descriptor
    236223        usb_log_debug("Retrieving descriptor\n");
    237         usb_pipe_t *control_pipe = &hub_info->usb_device->ctrl_pipe;
    238 
    239         usb_hub_descriptor_header_t descriptor;
     224        uint8_t serialized_descriptor[USB_HUB_MAX_DESCRIPTOR_SIZE];
     225        int opResult;
     226
    240227        size_t received_size;
    241         int opResult = usb_request_get_descriptor(control_pipe,
     228        opResult = usb_request_get_descriptor(hub_info->control_pipe,
    242229            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_DEVICE,
    243             USB_DESCTYPE_HUB, 0, 0, &descriptor,
    244             sizeof(usb_hub_descriptor_t), &received_size);
     230            USB_DESCTYPE_HUB, 0, 0, serialized_descriptor,
     231            USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size);
     232
    245233        if (opResult != EOK) {
    246234                usb_log_error("Failed to receive hub descriptor: %s.\n",
     
    248236                return opResult;
    249237        }
    250 
    251         usb_log_debug("Setting port count to %d.\n", descriptor.port_count);
    252         hub_info->port_count = descriptor.port_count;
    253 
    254         // TODO: +1 hack is no longer necessary
     238        usb_log_debug2("Parsing descriptor\n");
     239        usb_hub_descriptor_t descriptor;
     240        opResult = usb_deserialize_hub_desriptor(
     241                serialized_descriptor, received_size, &descriptor);
     242        if (opResult != EOK) {
     243                usb_log_error("Could not parse descriptor: %s\n",
     244                    str_error(opResult));
     245                return opResult;
     246        }
     247        usb_log_debug("Setting port count to %d.\n", descriptor.ports_count);
     248        hub_info->port_count = descriptor.ports_count;
     249
    255250        hub_info->ports =
    256251            malloc(sizeof(usb_hub_port_t) * (hub_info->port_count + 1));
     
    261256        size_t port;
    262257        for (port = 0; port < hub_info->port_count + 1; ++port) {
    263                 usb_hub_port_init(&hub_info->ports[port], port, control_pipe);
     258                usb_hub_port_init(&hub_info->ports[port]);
    264259        }
    265260
    266261        const bool is_power_switched =
    267             !(descriptor.characteristics & HUB_CHAR_NO_POWER_SWITCH_FLAG);
     262            !(descriptor.hub_characteristics & HUB_CHAR_NO_POWER_SWITCH_FLAG);
    268263        if (is_power_switched) {
    269264                usb_log_debug("Hub power switched\n");
    270                 const bool per_port_power = descriptor.characteristics
     265                const bool per_port_power = descriptor.hub_characteristics
    271266                    & HUB_CHAR_POWER_PER_PORT_FLAG;
    272267
    273268                for (port = 1; port <= hub_info->port_count; ++port) {
    274269                        usb_log_debug("Powering port %zu.\n", port);
    275                         opResult = usb_hub_port_set_feature(
    276                             &hub_info->ports[port], USB_HUB_FEATURE_PORT_POWER);
     270                        opResult = usb_hub_set_port_feature(
     271                            hub_info->control_pipe,
     272                            port, USB_HUB_FEATURE_PORT_POWER);
    277273                        if (opResult != EOK) {
    278274                                usb_log_error("Cannot power on port %zu: %s.\n",
     
    287283                        }
    288284                }
     285
    289286        } else {
    290                 usb_log_debug("Power not switched, ports always powered\n");
     287                usb_log_debug("Power not switched, not going to be powered\n");
    291288        }
    292289        return EOK;
    293290}
    294 /*----------------------------------------------------------------------------*/
    295 /**
    296  * Set configuration of and USB device
     291
     292/**
     293 * Set configuration of hub
    297294 *
    298295 * Check whether there is at least one configuration and sets the first one.
    299296 * This function should be run prior to running any hub-specific action.
    300  * @param usb_device usb device representation
     297 * @param hub_info hub representation
    301298 * @return error code
    302299 */
    303 static int usb_set_first_configuration(usb_device_t *usb_device)
    304 {
    305         assert(usb_device);
    306         /* Get number of possible configurations from device descriptor */
    307         const size_t configuration_count =
    308             usb_device->descriptors.device.configuration_count;
    309         usb_log_debug("Hub has %d configurations.\n", configuration_count);
    310 
    311         if (configuration_count < 1) {
     300static int usb_hub_set_configuration(usb_hub_info_t *hub_info) {
     301        //device descriptor
     302        usb_standard_device_descriptor_t *std_descriptor
     303            = &hub_info->usb_device->descriptors.device;
     304        usb_log_debug("Hub has %d configurations\n",
     305            std_descriptor->configuration_count);
     306        if (std_descriptor->configuration_count < 1) {
    312307                usb_log_error("There are no configurations available\n");
    313308                return EINVAL;
    314309        }
    315310
    316         // TODO: Make sure that there is enough data and the cast is correct
    317311        usb_standard_configuration_descriptor_t *config_descriptor
    318312            = (usb_standard_configuration_descriptor_t *)
    319             usb_device->descriptors.configuration;
    320 
    321         /* Set configuration. Use the configuration that was in
    322          * usb_device->descriptors.configuration i.e. The first one. */
    323         const int opResult = usb_request_set_configuration(
    324             &usb_device->ctrl_pipe, config_descriptor->configuration_number);
     313            hub_info->usb_device->descriptors.configuration;
     314
     315        /* Set configuration. */
     316        int opResult = usb_request_set_configuration(
     317            &hub_info->usb_device->ctrl_pipe,
     318            config_descriptor->configuration_number);
     319
    325320        if (opResult != EOK) {
    326321                usb_log_error("Failed to set hub configuration: %s.\n",
    327322                    str_error(opResult));
    328         } else {
    329                 usb_log_debug("\tUsed configuration %d\n",
    330                     config_descriptor->configuration_number);
    331         }
    332         return opResult;
    333 }
    334 /*----------------------------------------------------------------------------*/
    335 /**
    336  * Process hub over current change
     323                return opResult;
     324        }
     325        usb_log_debug("\tUsed configuration %d\n",
     326            config_descriptor->configuration_number);
     327
     328        return EOK;
     329}
     330
     331/**
     332 * create and start fibril with hub control loop
     333 *
     334 * Before the fibril is started, the control pipe and host controller
     335 * connection of the hub is open.
     336 *
     337 * @param hub_info hub representing structure
     338 * @return error code
     339 */
     340static int usb_hub_start_hub_fibril(usb_hub_info_t *hub_info) {
     341        int rc;
     342
     343        rc = usb_device_auto_poll(hub_info->usb_device, 0,
     344            hub_port_changes_callback, ((hub_info->port_count + 1) / 8) + 1,
     345            usb_hub_polling_terminated_callback, hub_info);
     346        if (rc != EOK) {
     347                usb_log_error("Failed to create polling fibril: %s.\n",
     348                    str_error(rc));
     349                free(hub_info);
     350                return rc;
     351        }
     352
     353        usb_log_info("Controlling hub `%s' (%zu ports).\n",
     354            hub_info->usb_device->ddf_dev->name, hub_info->port_count);
     355        return EOK;
     356}
     357
     358//*********************************************
     359//
     360//  change handling functions
     361//
     362//*********************************************
     363
     364/**
     365 * process hub over current change
    337366 *
    338367 * This means either to power off the hub or power it on.
     
    341370 * @return error code
    342371 */
    343 static void usb_hub_over_current(const usb_hub_info_t *hub_info,
    344     usb_hub_status_t status)
    345 {
    346         if (status & USB_HUB_STATUS_OVER_CURRENT) {
    347                 /* Hub should remove power from all ports if it detects OC */
    348                 usb_log_warning("Detected hub over-current condition, "
    349                     "all ports should be powered off.");
    350         } else {
    351                 /* Over-current condition is gone, it is safe to turn the
    352                  * ports on. */
    353                 size_t port;
     372static int usb_process_hub_over_current(usb_hub_info_t *hub_info,
     373    usb_hub_status_t status) {
     374        int opResult;
     375        if (usb_hub_is_status(status, USB_HUB_FEATURE_HUB_OVER_CURRENT)) {
     376                //poweroff all ports
     377                unsigned int port;
    354378                for (port = 1; port <= hub_info->port_count; ++port) {
    355                         const int opResult = usb_hub_port_set_feature(
    356                             &hub_info->ports[port], USB_HUB_FEATURE_PORT_POWER);
     379                        opResult = usb_hub_clear_port_feature(
     380                            hub_info->control_pipe, port,
     381                            USB_HUB_FEATURE_PORT_POWER);
    357382                        if (opResult != EOK) {
    358383                                usb_log_warning(
    359                                     "HUB OVER-CURRENT GONE: Cannot power on "
    360                                     "port %d;  %s\n",
     384                                    "Cannot power off port %d;  %s\n",
    361385                                    port, str_error(opResult));
    362386                        }
    363387                }
    364         }
    365         const int opResult = usb_request_clear_feature(
    366             &hub_info->usb_device->ctrl_pipe, USB_REQUEST_TYPE_CLASS,
    367             USB_REQUEST_RECIPIENT_DEVICE,
    368             USB_HUB_FEATURE_C_HUB_LOCAL_POWER, 0);
    369         if (opResult != EOK) {
    370                 usb_log_error(
    371                     "Failed to clear hub over-current change flag: %s.\n",
    372                     str_error(opResult));
    373         }
    374 }
    375 /*----------------------------------------------------------------------------*/
    376 /**
    377  * Process hub interrupts.
    378  *
    379  * The change can be either in the over-current condition or local-power change.
     388        } else {
     389                //power all ports
     390                unsigned int port;
     391                for (port = 1; port <= hub_info->port_count; ++port) {
     392                        opResult = usb_hub_set_port_feature(
     393                            hub_info->control_pipe, port,
     394                            USB_HUB_FEATURE_PORT_POWER);
     395                        if (opResult != EOK) {
     396                                usb_log_warning(
     397                                    "Cannot power off port %d;  %s\n",
     398                                    port, str_error(opResult));
     399                        }
     400                }
     401        }
     402        return opResult;
     403}
     404
     405/**
     406 * process hub local power change
     407 *
     408 * This change is ignored.
    380409 * @param hub_info hub instance
    381  */
    382 static void usb_hub_global_interrupt(const usb_hub_info_t *hub_info)
    383 {
    384         assert(hub_info);
    385         assert(hub_info->usb_device);
     410 * @param status hub status bitmask
     411 * @return error code
     412 */
     413static int usb_process_hub_local_power_change(usb_hub_info_t *hub_info,
     414    usb_hub_status_t status) {
     415        int opResult = EOK;
     416        opResult = usb_hub_clear_feature(hub_info->control_pipe,
     417            USB_HUB_FEATURE_C_HUB_LOCAL_POWER);
     418        if (opResult != EOK) {
     419                usb_log_error("Cannnot clear hub power change flag: "
     420                    "%s\n",
     421                    str_error(opResult));
     422        }
     423        return opResult;
     424}
     425
     426/**
     427 * process hub interrupts
     428 *
     429 * The change can be either in the over-current condition or
     430 * local-power change.
     431 * @param hub_info hub instance
     432 */
     433static void usb_hub_process_global_interrupt(usb_hub_info_t *hub_info) {
    386434        usb_log_debug("Global interrupt on a hub\n");
    387         usb_pipe_t *control_pipe = &hub_info->usb_device->ctrl_pipe;
    388 
    389         usb_hub_status_t status;
     435        usb_pipe_t *pipe = hub_info->control_pipe;
     436        int opResult;
     437
     438        usb_port_status_t status;
    390439        size_t rcvd_size;
    391         /* NOTE: We can't use standard USB GET_STATUS request, because
    392          * hubs reply is 4byte instead of 2 */
    393         const int opResult = usb_pipe_control_read(control_pipe,
    394             &get_hub_status_request, sizeof(get_hub_status_request),
    395             &status, sizeof(usb_hub_status_t), &rcvd_size);
     440        usb_device_request_setup_packet_t request;
     441        //int opResult;
     442        usb_hub_set_hub_status_request(&request);
     443        //endpoint 0
     444
     445        opResult = usb_pipe_control_read(
     446            pipe,
     447            &request, sizeof (usb_device_request_setup_packet_t),
     448            &status, 4, &rcvd_size
     449            );
    396450        if (opResult != EOK) {
    397451                usb_log_error("Could not get hub status: %s\n",
     
    399453                return;
    400454        }
    401         if (rcvd_size != sizeof(usb_hub_status_t)) {
     455        if (rcvd_size != sizeof (usb_port_status_t)) {
    402456                usb_log_error("Received status has incorrect size\n");
    403457                return;
    404458        }
    405 
    406         /* Handle status changes */
    407         if (status & USB_HUB_STATUS_C_OVER_CURRENT) {
    408                 usb_hub_over_current(hub_info, status);
    409         }
    410 
    411         if (status & USB_HUB_STATUS_C_LOCAL_POWER) {
    412                 /* NOTE: Handling this is more complicated.
    413                  * If the transition is from bus power to local power, all
    414                  * is good and we may signal the parent hub that we don't
    415                  * need the power.
    416                  * If the transition is from local power to bus power
    417                  * the hub should turn off all the ports and devices need
    418                  * to be reinitialized taking into account the limited power
    419                  * that is now available.
    420                  * There is no support for power distribution in HelenOS,
    421                  * (or other OSes/hub devices that I've seen) so this is not
    422                  * implemented.
    423                  * Just ACK the change.
    424                  */
    425                 const int opResult = usb_request_clear_feature(
    426                     control_pipe, USB_REQUEST_TYPE_CLASS,
    427                     USB_REQUEST_RECIPIENT_DEVICE,
    428                     USB_HUB_FEATURE_C_HUB_LOCAL_POWER, 0);
    429                 if (opResult != EOK) {
    430                         usb_log_error(
    431                             "Failed to clear hub power change flag: %s.\n",
    432                             str_error(opResult));
    433                 }
    434         }
    435 }
    436 /*----------------------------------------------------------------------------*/
     459        //port reset
     460        if (
     461            usb_hub_is_status(status, 16 + USB_HUB_FEATURE_C_HUB_OVER_CURRENT)) {
     462                usb_process_hub_over_current(hub_info, status);
     463        }
     464        if (
     465            usb_hub_is_status(status, 16 + USB_HUB_FEATURE_C_HUB_LOCAL_POWER)) {
     466                usb_process_hub_local_power_change(hub_info, status);
     467        }
     468}
     469
    437470/**
    438471 * callback called from hub polling fibril when the fibril terminates
     
    444477 */
    445478static void usb_hub_polling_terminated_callback(usb_device_t *device,
    446     bool was_error, void *data)
    447 {
    448         usb_hub_info_t *hub = data;
     479    bool was_error, void *data) {
     480        usb_hub_info_t * hub = data;
    449481        assert(hub);
    450482
     
    460492         */
    461493        if (hub->pending_ops_count > 0) {
     494                fibril_mutex_lock(&hub->port_mutex);
    462495                size_t port;
    463496                for (port = 0; port < hub->port_count; port++) {
    464                         usb_hub_port_reset_fail(&hub->ports[port]);
     497                        usb_hub_port_t *the_port = hub->ports + port;
     498                        fibril_mutex_lock(&the_port->reset_mutex);
     499                        the_port->reset_completed = true;
     500                        the_port->reset_okay = false;
     501                        fibril_condvar_broadcast(&the_port->reset_cv);
     502                        fibril_mutex_unlock(&the_port->reset_mutex);
    465503                }
     504                fibril_mutex_unlock(&hub->port_mutex);
    466505        }
    467506        /* And now wait for them. */
     
    477516        free(hub);
    478517}
     518
     519
     520
     521
    479522/**
    480523 * @}
Note: See TracChangeset for help on using the changeset viewer.