source: mainline/uspace/drv/bus/usb/usbhub/usbhub.c@ 7010861

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7010861 was a0a0d9f4, checked in by Petr Manek <petr.manek@…>, 8 years ago

Removed redundant debug messages.

  • Property mode set to 100644
File size: 16.3 KB
RevLine 
[e080332]1/*
2 * Copyright (c) 2010 Matus Dekanek
[3b617579]3 * Copyright (c) 2011 Jan Vesely
[e080332]4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
[58563585]29
[281ebae]30/** @addtogroup drvusbhub
[e080332]31 * @{
32 */
33/** @file
34 * @brief usb hub main functionality
35 */
36
[eb1a2f4]37#include <ddf/driver.h>
[3e6a98c5]38#include <stdbool.h>
[e080332]39#include <errno.h>
[4e8e1f5]40#include <str_error.h>
[3e490eb]41#include <inttypes.h>
[193da9d6]42#include <stdio.h>
[e080332]43
[193da9d6]44#include <usb/usb.h>
[6c5abf9]45#include <usb/debug.h>
[193da9d6]46#include <usb/dev/pipes.h>
47#include <usb/classes/classes.h>
[e080332]48#include <usb/descriptor.h>
[7d521e24]49#include <usb/dev/recognise.h>
50#include <usb/dev/request.h>
[e080332]51#include <usb/classes/hub.h>
[7d521e24]52#include <usb/dev/poll.h>
[193da9d6]53#include <usb_iface.h>
[e080332]54
55#include "usbhub.h"
[400f363]56#include "status.h"
[e080332]57
[d46b13d]58#define HUB_FNC_NAME "hub"
[58563585]59
[bb70637]60/** Hub status-change endpoint description.
61 *
62 * For more information see section 11.15.1 of USB 1.1 specification.
63 */
64const usb_endpoint_description_t hub_status_change_endpoint_description =
65{
66 .transfer_type = USB_TRANSFER_INTERRUPT,
67 .direction = USB_DIRECTION_IN,
68 .interface_class = USB_CLASS_HUB,
69 .interface_subclass = 0,
70 .interface_protocol = 0,
71 .flags = 0
72};
[df3ad97]73
[bf73a02]74/** Standard get hub global status request */
75static const usb_device_request_setup_packet_t get_hub_status_request = {
76 .request_type = USB_HUB_REQ_TYPE_GET_HUB_STATUS,
77 .request = USB_HUB_REQUEST_GET_STATUS,
[bba0f1fc]78 .index = 0,
[bf73a02]79 .value = 0,
80 .length = sizeof(usb_hub_status_t),
81};
82
[193da9d6]83static int usb_set_first_configuration(usb_device_t *usb_device);
[eda7a4e0]84static int usb_hub_process_hub_specific_info(usb_hub_dev_t *hub_dev);
85static void usb_hub_over_current(const usb_hub_dev_t *hub_dev,
[f35b294]86 usb_hub_status_t status);
[eda7a4e0]87static void usb_hub_global_interrupt(const usb_hub_dev_t *hub_dev);
[5c1a65e]88static void usb_hub_polling_terminated_callback(usb_device_t *device,
[6ab7f3e9]89 bool was_error, void *data);
[205f0766]90
[a209648]91/**
[54d1ad9]92 * Initialize hub device driver structure.
[a209648]93 *
[ea6de35]94 * Creates hub representation and fibril that periodically checks hub's status.
[a209648]95 * Hub representation is passed to the fibril.
96 * @param usb_dev generic usb device information
97 * @return error code
98 */
[1a4ea01d]99int usb_hub_device_add(usb_device_t *usb_dev)
[d46b13d]100{
[193da9d6]101 assert(usb_dev);
102 /* Create driver soft-state structure */
[e27c2476]103 usb_hub_dev_t *hub_dev =
104 usb_device_data_alloc(usb_dev, sizeof(usb_hub_dev_t));
[eda7a4e0]105 if (hub_dev == NULL) {
[54d1ad9]106 usb_log_error("Failed to create hub driver structure.\n");
[193da9d6]107 return ENOMEM;
108 }
[e27c2476]109 hub_dev->usb_device = usb_dev;
110 hub_dev->pending_ops_count = 0;
111 hub_dev->running = false;
112 fibril_mutex_initialize(&hub_dev->pending_ops_mutex);
113 fibril_condvar_initialize(&hub_dev->pending_ops_cv);
[ee9ea16]114
[193da9d6]115 /* Set hub's first configuration. (There should be only one) */
[d93f5afb]116 int opResult = usb_set_first_configuration(usb_dev);
[a209648]117 if (opResult != EOK) {
[ee9ea16]118 usb_log_error("Could not set hub configuration: %s\n",
[5c1a65e]119 str_error(opResult));
[a209648]120 return opResult;
121 }
[d46b13d]122
[205f0766]123 /* Get port count and create attached_devices. */
[eda7a4e0]124 opResult = usb_hub_process_hub_specific_info(hub_dev);
[a209648]125 if (opResult != EOK) {
[5c1a65e]126 usb_log_error("Could process hub specific info, %s\n",
127 str_error(opResult));
[a209648]128 return opResult;
129 }
[9063484]130
[54d1ad9]131 /* Create hub control function. */
[d46b13d]132 usb_log_debug("Creating DDF function '" HUB_FNC_NAME "'.\n");
[6785b538]133 hub_dev->hub_fun = usb_device_ddf_fun_create(hub_dev->usb_device,
[d46b13d]134 fun_exposed, HUB_FNC_NAME);
[eda7a4e0]135 if (hub_dev->hub_fun == NULL) {
[d46b13d]136 usb_log_error("Failed to create hub function.\n");
137 return ENOMEM;
138 }
[a209648]139
[54d1ad9]140 /* Bind hub control function. */
[eda7a4e0]141 opResult = ddf_fun_bind(hub_dev->hub_fun);
[d46b13d]142 if (opResult != EOK) {
143 usb_log_error("Failed to bind hub function: %s.\n",
144 str_error(opResult));
[eda7a4e0]145 ddf_fun_destroy(hub_dev->hub_fun);
[d46b13d]146 return opResult;
147 }
[3e490eb]148
[54d1ad9]149 /* Start hub operation. */
[bb70637]150 opResult = usb_device_auto_poll_desc(hub_dev->usb_device,
151 &hub_status_change_endpoint_description,
[ea30cc1]152 hub_port_changes_callback, ((hub_dev->port_count + 1 + 7) / 8),
[bb70637]153 -1, usb_hub_polling_terminated_callback, hub_dev);
[d46b13d]154 if (opResult != EOK) {
[205f0766]155 /* Function is already bound */
[eda7a4e0]156 ddf_fun_unbind(hub_dev->hub_fun);
157 ddf_fun_destroy(hub_dev->hub_fun);
[d46b13d]158 usb_log_error("Failed to create polling fibril: %s.\n",
159 str_error(opResult));
160 return opResult;
161 }
[eda7a4e0]162 hub_dev->running = true;
[e98e5fc]163 usb_log_info("Controlling hub '%s' (%p: %zu ports).\n",
164 usb_device_get_name(hub_dev->usb_device), hub_dev,
165 hub_dev->port_count);
[d46b13d]166
167 return EOK;
[a209648]168}
[76fbd9a]169
[54d1ad9]170/**
171 * Turn off power to all ports.
172 *
173 * @param usb_dev generic usb device information
174 * @return error code
175 */
176int usb_hub_device_remove(usb_device_t *usb_dev)
177{
178 return ENOTSUP;
179}
[76fbd9a]180
[54d1ad9]181/**
182 * Remove all attached devices
183 * @param usb_dev generic usb device information
184 * @return error code
185 */
186int usb_hub_device_gone(usb_device_t *usb_dev)
187{
188 assert(usb_dev);
[0f4bff8]189 usb_hub_dev_t *hub = usb_device_data_get(usb_dev);
[54d1ad9]190 assert(hub);
191 unsigned tries = 10;
192 while (hub->running) {
193 async_usleep(100000);
194 if (!tries--) {
[e98e5fc]195 usb_log_error("(%p): Can't remove hub, still running.",
196 hub);
[fab2746]197 return EBUSY;
[54d1ad9]198 }
199 }
200
201 assert(!hub->running);
202
203 for (size_t port = 0; port < hub->port_count; ++port) {
[c9467b0]204 const int ret = usb_hub_port_fini(&hub->ports[port], hub);
205 if (ret != EOK)
206 return ret;
[54d1ad9]207 }
208 free(hub->ports);
209
210 const int ret = ddf_fun_unbind(hub->hub_fun);
211 if (ret != EOK) {
[e98e5fc]212 usb_log_error("(%p) Failed to unbind '%s' function: %s.",
213 hub, HUB_FNC_NAME, str_error(ret));
[54d1ad9]214 return ret;
215 }
216 ddf_fun_destroy(hub->hub_fun);
217
[e98e5fc]218 usb_log_info("(%p) USB hub driver stopped and cleaned.", hub);
[54d1ad9]219 return EOK;
220}
[76fbd9a]221
[1e1b1a9]222/** Callback for polling hub for changes.
[3e490eb]223 *
224 * @param dev Device where the change occured.
225 * @param change_bitmap Bitmap of changed ports.
226 * @param change_bitmap_size Size of the bitmap in bytes.
[6626bba9]227 * @param arg Custom argument, points to @c usb_hub_dev_t.
[3e490eb]228 * @return Whether to continue polling.
229 */
230bool hub_port_changes_callback(usb_device_t *dev,
[983e135]231 uint8_t *change_bitmap, size_t change_bitmap_size, void *arg)
232{
[6626bba9]233 usb_hub_dev_t *hub = arg;
[0212751]234 assert(hub);
[3e490eb]235
[0212751]236 /* It is an error condition if we didn't receive enough data */
[3e490eb]237 if (change_bitmap_size == 0) {
[0212751]238 return false;
[3e490eb]239 }
240
[983e135]241 /* Lowest bit indicates global change */
242 const bool change = change_bitmap[0] & 1;
[f35b294]243 if (change) {
[ea6de35]244 usb_hub_global_interrupt(hub);
[1e1b1a9]245 }
246
[983e135]247 /* N + 1 bit indicates change on port N */
[ea30cc1]248 for (size_t port = 0; port < hub->port_count; ++port) {
[a14d6a7]249 const size_t bit = port + 1;
250 const bool change = (change_bitmap[bit / 8] >> (bit % 8)) & 1;
[3e490eb]251 if (change) {
[0212751]252 usb_hub_port_process_interrupt(&hub->ports[port], hub);
[3e490eb]253 }
254 }
255 return true;
256}
[76fbd9a]257
[09daa8b]258/**
[eda7a4e0]259 * Load hub-specific information into hub_dev structure and process if needed
[09daa8b]260 *
[ea6de35]261 * Read port count and initialize structures holding per port information.
262 * If there are any non-removable devices, start initializing them.
[09daa8b]263 * This function is hub-specific and should be run only after the hub is
[193da9d6]264 * configured using usb_set_first_configuration function.
[eda7a4e0]265 * @param hub_dev hub representation
[09daa8b]266 * @return error code
267 */
[eda7a4e0]268static int usb_hub_process_hub_specific_info(usb_hub_dev_t *hub_dev)
[5fd0dc23]269{
[eda7a4e0]270 assert(hub_dev);
[ea6de35]271
272 /* Get hub descriptor. */
[e98e5fc]273 usb_log_debug("(%p): Retrieving descriptor.", hub_dev);
[0f4bff8]274 usb_pipe_t *control_pipe =
275 usb_device_get_default_pipe(hub_dev->usb_device);
[09daa8b]276
[621ba8c]277 usb_hub_descriptor_header_t descriptor;
[09daa8b]278 size_t received_size;
[621ba8c]279 int opResult = usb_request_get_descriptor(control_pipe,
[f35b294]280 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_DEVICE,
[621ba8c]281 USB_DESCTYPE_HUB, 0, 0, &descriptor,
[32cd37f]282 sizeof(usb_hub_descriptor_header_t), &received_size);
[09daa8b]283 if (opResult != EOK) {
[e98e5fc]284 usb_log_error("(%p): Failed to receive hub descriptor: %s.\n",
285 hub_dev, str_error(opResult));
[15b0432]286 return opResult;
287 }
[621ba8c]288
[e98e5fc]289 usb_log_debug("(%p): Setting port count to %d.\n", hub_dev,
290 descriptor.port_count);
[eda7a4e0]291 hub_dev->port_count = descriptor.port_count;
[5fd0dc23]292
[a14d6a7]293 hub_dev->ports = calloc(hub_dev->port_count, sizeof(usb_hub_port_t));
[eda7a4e0]294 if (!hub_dev->ports) {
[361fcec]295 return ENOMEM;
296 }
[5fd0dc23]297
[a14d6a7]298 for (size_t port = 0; port < hub_dev->port_count; ++port) {
299 usb_hub_port_init(
300 &hub_dev->ports[port], port + 1, control_pipe);
[15b0432]301 }
[5fd0dc23]302
[54d1ad9]303 hub_dev->power_switched =
[621ba8c]304 !(descriptor.characteristics & HUB_CHAR_NO_POWER_SWITCH_FLAG);
[54d1ad9]305 hub_dev->per_port_power =
306 descriptor.characteristics & HUB_CHAR_POWER_PER_PORT_FLAG;
307
308 if (!hub_dev->power_switched) {
[e98e5fc]309 usb_log_info("(%p): Power switching not supported, "
310 "ports always powered.", hub_dev);
[54d1ad9]311 return EOK;
312 }
313
[e98e5fc]314 usb_log_info("(%p): Hub port power switching enabled (%s).\n", hub_dev,
[dc1d499]315 hub_dev->per_port_power ? "per port" : "ganged");
[54d1ad9]316
[58563585]317 for (unsigned int port = 0; port < hub_dev->port_count; ++port) {
[34c9cfc]318 usb_log_debug("(%p): Powering port %u.", hub_dev, port);
[54d1ad9]319 const int ret = usb_hub_port_set_feature(
320 &hub_dev->ports[port], USB_HUB_FEATURE_PORT_POWER);
321
322 if (ret != EOK) {
[34c9cfc]323 usb_log_error("(%p-%u): Cannot power on port: %s.\n",
[e98e5fc]324 hub_dev, hub_dev->ports[port].port_number,
325 str_error(ret));
[54d1ad9]326 } else {
327 if (!hub_dev->per_port_power) {
[e98e5fc]328 usb_log_debug("(%p) Ganged power switching, "
329 "one port is enough.", hub_dev);
[54d1ad9]330 break;
[361fcec]331 }
332 }
[15b0432]333 }
[206f71a]334 return EOK;
[15b0432]335}
[76fbd9a]336
[15b0432]337/**
[193da9d6]338 * Set configuration of and USB device
[09daa8b]339 *
340 * Check whether there is at least one configuration and sets the first one.
341 * This function should be run prior to running any hub-specific action.
[193da9d6]342 * @param usb_device usb device representation
[df3ad97]343 * @return error code
[15b0432]344 */
[193da9d6]345static int usb_set_first_configuration(usb_device_t *usb_device)
[983e135]346{
[193da9d6]347 assert(usb_device);
348 /* Get number of possible configurations from device descriptor */
349 const size_t configuration_count =
[e2dfa86]350 usb_device_descriptors(usb_device)->device.configuration_count;
[e231d26]351 usb_log_debug("Hub has %zu configurations.\n", configuration_count);
[983e135]352
[193da9d6]353 if (configuration_count < 1) {
[5c1a65e]354 usb_log_error("There are no configurations available\n");
[625f1ba]355 return EINVAL;
[15b0432]356 }
357
[e2dfa86]358 const size_t config_size =
359 usb_device_descriptors(usb_device)->full_config_size;
[8b68bdf]360 const usb_standard_configuration_descriptor_t *config_descriptor =
[e2dfa86]361 usb_device_descriptors(usb_device)->full_config;
[8b68bdf]362
363 if (config_size < sizeof(usb_standard_configuration_descriptor_t)) {
[fec6bf2]364 usb_log_error("Configuration descriptor is not big enough"
365 " to fit standard configuration descriptor.\n");
366 return EOVERFLOW;
367 }
368
[193da9d6]369 /* Set configuration. Use the configuration that was in
[ea6de35]370 * usb_device->descriptors.configuration i.e. The first one. */
[193da9d6]371 const int opResult = usb_request_set_configuration(
[0f4bff8]372 usb_device_get_default_pipe(usb_device),
373 config_descriptor->configuration_number);
[15b0432]374 if (opResult != EOK) {
[d70e0a3c]375 usb_log_error("Failed to set hub configuration: %s.\n",
[f35b294]376 str_error(opResult));
[ea6de35]377 } else {
378 usb_log_debug("\tUsed configuration %d\n",
379 config_descriptor->configuration_number);
[15b0432]380 }
[ea6de35]381 return opResult;
[15b0432]382}
[76fbd9a]383
[3dba1ca]384/**
[ea6de35]385 * Process hub over current change
[3dba1ca]386 *
387 * This means either to power off the hub or power it on.
[eda7a4e0]388 * @param hub_dev hub instance
[3dba1ca]389 * @param status hub status bitmask
390 * @return error code
391 */
[eda7a4e0]392static void usb_hub_over_current(const usb_hub_dev_t *hub_dev,
[bf73a02]393 usb_hub_status_t status)
394{
395 if (status & USB_HUB_STATUS_OVER_CURRENT) {
[0212751]396 /* Hub should remove power from all ports if it detects OC */
[e98e5fc]397 usb_log_warning("(%p) Detected hub over-current condition, "
398 "all ports should be powered off.", hub_dev);
[54d1ad9]399 return;
[040ab02]400 }
[54d1ad9]401
402 /* Ports are always powered. */
403 if (!hub_dev->power_switched)
404 return;
405
406 /* Over-current condition is gone, it is safe to turn the ports on. */
407 for (size_t port = 0; port < hub_dev->port_count; ++port) {
408 const int ret = usb_hub_port_set_feature(
409 &hub_dev->ports[port], USB_HUB_FEATURE_PORT_POWER);
410 if (ret != EOK) {
[e98e5fc]411 usb_log_warning("(%p-%u): HUB OVER-CURRENT GONE: Cannot"
412 " power on port: %s\n", hub_dev,
413 hub_dev->ports[port].port_number, str_error(ret));
[54d1ad9]414 } else {
415 if (!hub_dev->per_port_power)
416 return;
417 }
[0212751]418 }
[54d1ad9]419
[040ab02]420}
[76fbd9a]421
[3dba1ca]422/**
[ea6de35]423 * Process hub interrupts.
[3dba1ca]424 *
[ea6de35]425 * The change can be either in the over-current condition or local-power change.
[eda7a4e0]426 * @param hub_dev hub instance
[3dba1ca]427 */
[eda7a4e0]428static void usb_hub_global_interrupt(const usb_hub_dev_t *hub_dev)
[bf73a02]429{
[eda7a4e0]430 assert(hub_dev);
431 assert(hub_dev->usb_device);
[e98e5fc]432 usb_log_debug("(%p): Global interrupt on th hub.", hub_dev);
[0f4bff8]433 usb_pipe_t *control_pipe =
434 usb_device_get_default_pipe(hub_dev->usb_device);
[040ab02]435
[bf73a02]436 usb_hub_status_t status;
[040ab02]437 size_t rcvd_size;
[ea6de35]438 /* NOTE: We can't use standard USB GET_STATUS request, because
439 * hubs reply is 4byte instead of 2 */
[75eb6735]440 const int opResult = usb_pipe_control_read(control_pipe,
441 &get_hub_status_request, sizeof(get_hub_status_request),
[bf73a02]442 &status, sizeof(usb_hub_status_t), &rcvd_size);
[040ab02]443 if (opResult != EOK) {
[e98e5fc]444 usb_log_error("(%p): Could not get hub status: %s.", hub_dev,
[5c1a65e]445 str_error(opResult));
[040ab02]446 return;
447 }
[bf73a02]448 if (rcvd_size != sizeof(usb_hub_status_t)) {
[e98e5fc]449 usb_log_error("(%p): Received status has incorrect size: "
450 "%zu != %zu", hub_dev, rcvd_size, sizeof(usb_hub_status_t));
[040ab02]451 return;
452 }
[bf73a02]453
454 /* Handle status changes */
[a61c683]455 if (status & USB_HUB_STATUS_C_OVER_CURRENT) {
[eda7a4e0]456 usb_hub_over_current(hub_dev, status);
[54d1ad9]457 /* Ack change in hub OC flag */
458 const int ret = usb_request_clear_feature(
[0f4bff8]459 control_pipe, USB_REQUEST_TYPE_CLASS,
[54d1ad9]460 USB_REQUEST_RECIPIENT_DEVICE,
461 USB_HUB_FEATURE_C_HUB_OVER_CURRENT, 0);
462 if (ret != EOK) {
[e98e5fc]463 usb_log_error("(%p): Failed to clear hub over-current "
464 "change flag: %s.\n", hub_dev, str_error(opResult));
[54d1ad9]465 }
[a61c683]466 }
[bf73a02]467
468 if (status & USB_HUB_STATUS_C_LOCAL_POWER) {
469 /* NOTE: Handling this is more complicated.
470 * If the transition is from bus power to local power, all
471 * is good and we may signal the parent hub that we don't
472 * need the power.
473 * If the transition is from local power to bus power
474 * the hub should turn off all the ports and devices need
475 * to be reinitialized taking into account the limited power
476 * that is now available.
477 * There is no support for power distribution in HelenOS,
478 * (or other OSes/hub devices that I've seen) so this is not
479 * implemented.
480 * Just ACK the change.
481 */
[54d1ad9]482 const int ret = usb_request_clear_feature(
[bba0f1fc]483 control_pipe, USB_REQUEST_TYPE_CLASS,
484 USB_REQUEST_RECIPIENT_DEVICE,
485 USB_HUB_FEATURE_C_HUB_LOCAL_POWER, 0);
[bf73a02]486 if (opResult != EOK) {
[e98e5fc]487 usb_log_error("(%p): Failed to clear hub power change "
488 "flag: %s.\n", hub_dev, str_error(ret));
[bf73a02]489 }
[040ab02]490 }
491}
[76fbd9a]492
[aca3489]493/**
494 * callback called from hub polling fibril when the fibril terminates
495 *
[eda7a4e0]496 * Does not perform cleanup, just marks the hub as not running.
[aca3489]497 * @param device usb device afected
498 * @param was_error indicates that the fibril is stoped due to an error
[6626bba9]499 * @param data pointer to usb_hub_dev_t structure
[aca3489]500 */
[5c1a65e]501static void usb_hub_polling_terminated_callback(usb_device_t *device,
[ea6de35]502 bool was_error, void *data)
503{
[6626bba9]504 usb_hub_dev_t *hub = data;
[3fb5a3e]505 assert(hub);
506
507 fibril_mutex_lock(&hub->pending_ops_mutex);
[dd143621]508
509 /* The device is dead. However there might be some pending operations
510 * that we need to wait for.
511 * One of them is device adding in progress.
512 * The respective fibril is probably waiting for status change
513 * in port reset (port enable) callback.
514 * Such change would never come (otherwise we would not be here).
515 * Thus, we would flush all pending port resets.
516 */
517 if (hub->pending_ops_count > 0) {
[a14d6a7]518 for (size_t port = 0; port < hub->port_count; ++port) {
[442fa6b]519 usb_hub_port_reset_fail(&hub->ports[port]);
[dd143621]520 }
521 }
522 /* And now wait for them. */
[3fb5a3e]523 while (hub->pending_ops_count > 0) {
524 fibril_condvar_wait(&hub->pending_ops_cv,
525 &hub->pending_ops_mutex);
526 }
527 fibril_mutex_unlock(&hub->pending_ops_mutex);
[205f0766]528 hub->running = false;
[aca3489]529}
[e080332]530/**
531 * @}
[71ed4849]532 */
Note: See TracBrowser for help on using the repository browser.