source: mainline/uspace/drv/bus/usb/usbhub/port.h@ d60115a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since d60115a was c4e84ed6, checked in by Ondřej Hlavatý <aearsis@…>, 8 years ago

usbhub: rewrite port handling

The state space of a usb hub port is a bit more complex than what was
there originally. Got rid of the active operations counting, and
replaced that with finite state machine. Fixes a lot of race conditions
and lack of synchronization when connect and disconnect events come very
fast.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 * Copyright (c) 2011 Vojtech Horky
3 * Copyright (c) 2011 Jan Vesely
4 * Copyright (c) 2017 Ondra Hlavaty
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * - The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/** @addtogroup drvusbhub
32 * @{
33 */
34/** @file
35 * Hub port state machine.
36 */
37
38#ifndef DRV_USBHUB_PORT_H
39#define DRV_USBHUB_PORT_H
40
41#include <usb/dev/driver.h>
42#include <usb/classes/hub.h>
43
44typedef struct usb_hub_dev usb_hub_dev_t;
45
46typedef enum {
47 PORT_DISABLED, /* No device connected. */
48 PORT_CONNECTED, /* A device connected, not yet initialized. */
49 PORT_IN_RESET, /* An initial port reset in progress. */
50 PORT_ENABLED, /* Port reset complete, port enabled. Device announced to the HC. */
51 PORT_ERROR, /* An error occured. There is still a fibril that needs to know it. */
52} port_state_t;
53
54/** Information about single port on a hub. */
55typedef struct {
56 /* Parenting hub */
57 usb_hub_dev_t *hub;
58 /** Guarding all fields */
59 fibril_mutex_t guard;
60 /** Current state of the port */
61 port_state_t state;
62 /** A speed of the device connected (if any). Valid unless state == PORT_DISABLED. */
63 usb_speed_t speed;
64 /** Port number as reported in descriptors. */
65 unsigned int port_number;
66 /** CV for waiting to port reset completion. */
67 fibril_condvar_t state_cv;
68} usb_hub_port_t;
69
70void usb_hub_port_init(usb_hub_port_t *, usb_hub_dev_t *, unsigned int);
71void usb_hub_port_fini(usb_hub_port_t *);
72
73void usb_hub_port_process_interrupt(usb_hub_port_t *port, usb_hub_dev_t *hub);
74
75#endif
76
77/**
78 * @}
79 */
Note: See TracBrowser for help on using the repository browser.