xref: /openbmc/linux/drivers/usb/core/hub.h (revision 87c2ce3b)
1 #ifndef __LINUX_HUB_H
2 #define __LINUX_HUB_H
3 
4 /*
5  * Hub protocol and driver data structures.
6  *
7  * Some of these are known to the "virtual root hub" code
8  * in host controller drivers.
9  */
10 
11 #include <linux/list.h>
12 #include <linux/workqueue.h>
13 #include <linux/compiler.h>	/* likely()/unlikely() */
14 
15 /*
16  * Hub request types
17  */
18 
19 #define USB_RT_HUB	(USB_TYPE_CLASS | USB_RECIP_DEVICE)
20 #define USB_RT_PORT	(USB_TYPE_CLASS | USB_RECIP_OTHER)
21 
22 /*
23  * Hub class requests
24  * See USB 2.0 spec Table 11-16
25  */
26 #define HUB_CLEAR_TT_BUFFER	8
27 #define HUB_RESET_TT		9
28 #define HUB_GET_TT_STATE	10
29 #define HUB_STOP_TT		11
30 
31 /*
32  * Hub Class feature numbers
33  * See USB 2.0 spec Table 11-17
34  */
35 #define C_HUB_LOCAL_POWER	0
36 #define C_HUB_OVER_CURRENT	1
37 
38 /*
39  * Port feature numbers
40  * See USB 2.0 spec Table 11-17
41  */
42 #define USB_PORT_FEAT_CONNECTION	0
43 #define USB_PORT_FEAT_ENABLE		1
44 #define USB_PORT_FEAT_SUSPEND		2
45 #define USB_PORT_FEAT_OVER_CURRENT	3
46 #define USB_PORT_FEAT_RESET		4
47 #define USB_PORT_FEAT_POWER		8
48 #define USB_PORT_FEAT_LOWSPEED		9
49 #define USB_PORT_FEAT_HIGHSPEED		10
50 #define USB_PORT_FEAT_C_CONNECTION	16
51 #define USB_PORT_FEAT_C_ENABLE		17
52 #define USB_PORT_FEAT_C_SUSPEND		18
53 #define USB_PORT_FEAT_C_OVER_CURRENT	19
54 #define USB_PORT_FEAT_C_RESET		20
55 #define USB_PORT_FEAT_TEST              21
56 #define USB_PORT_FEAT_INDICATOR         22
57 
58 /*
59  * Hub Status and Hub Change results
60  * See USB 2.0 spec Table 11-19 and Table 11-20
61  */
62 struct usb_port_status {
63 	__le16 wPortStatus;
64 	__le16 wPortChange;
65 } __attribute__ ((packed));
66 
67 /*
68  * wPortStatus bit field
69  * See USB 2.0 spec Table 11-21
70  */
71 #define USB_PORT_STAT_CONNECTION	0x0001
72 #define USB_PORT_STAT_ENABLE		0x0002
73 #define USB_PORT_STAT_SUSPEND		0x0004
74 #define USB_PORT_STAT_OVERCURRENT	0x0008
75 #define USB_PORT_STAT_RESET		0x0010
76 /* bits 5 to 7 are reserved */
77 #define USB_PORT_STAT_POWER		0x0100
78 #define USB_PORT_STAT_LOW_SPEED		0x0200
79 #define USB_PORT_STAT_HIGH_SPEED        0x0400
80 #define USB_PORT_STAT_TEST              0x0800
81 #define USB_PORT_STAT_INDICATOR         0x1000
82 /* bits 13 to 15 are reserved */
83 
84 /*
85  * wPortChange bit field
86  * See USB 2.0 spec Table 11-22
87  * Bits 0 to 4 shown, bits 5 to 15 are reserved
88  */
89 #define USB_PORT_STAT_C_CONNECTION	0x0001
90 #define USB_PORT_STAT_C_ENABLE		0x0002
91 #define USB_PORT_STAT_C_SUSPEND		0x0004
92 #define USB_PORT_STAT_C_OVERCURRENT	0x0008
93 #define USB_PORT_STAT_C_RESET		0x0010
94 
95 /*
96  * wHubCharacteristics (masks)
97  * See USB 2.0 spec Table 11-13, offset 3
98  */
99 #define HUB_CHAR_LPSM		0x0003 /* D1 .. D0 */
100 #define HUB_CHAR_COMPOUND	0x0004 /* D2       */
101 #define HUB_CHAR_OCPM		0x0018 /* D4 .. D3 */
102 #define HUB_CHAR_TTTT           0x0060 /* D6 .. D5 */
103 #define HUB_CHAR_PORTIND        0x0080 /* D7       */
104 
105 struct usb_hub_status {
106 	__le16 wHubStatus;
107 	__le16 wHubChange;
108 } __attribute__ ((packed));
109 
110 /*
111  * Hub Status & Hub Change bit masks
112  * See USB 2.0 spec Table 11-19 and Table 11-20
113  * Bits 0 and 1 for wHubStatus and wHubChange
114  * Bits 2 to 15 are reserved for both
115  */
116 #define HUB_STATUS_LOCAL_POWER	0x0001
117 #define HUB_STATUS_OVERCURRENT	0x0002
118 #define HUB_CHANGE_LOCAL_POWER	0x0001
119 #define HUB_CHANGE_OVERCURRENT	0x0002
120 
121 
122 /*
123  * Hub descriptor
124  * See USB 2.0 spec Table 11-13
125  */
126 
127 #define USB_DT_HUB			(USB_TYPE_CLASS | 0x09)
128 #define USB_DT_HUB_NONVAR_SIZE		7
129 
130 struct usb_hub_descriptor {
131 	__u8  bDescLength;
132 	__u8  bDescriptorType;
133 	__u8  bNbrPorts;
134 	__le16 wHubCharacteristics;
135 	__u8  bPwrOn2PwrGood;
136 	__u8  bHubContrCurrent;
137 	    	/* add 1 bit for hub status change; round to bytes */
138 	__u8  DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8];
139 	__u8  PortPwrCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8];
140 } __attribute__ ((packed));
141 
142 
143 /* port indicator status selectors, tables 11-7 and 11-25 */
144 #define HUB_LED_AUTO	0
145 #define HUB_LED_AMBER	1
146 #define HUB_LED_GREEN	2
147 #define HUB_LED_OFF	3
148 
149 enum hub_led_mode {
150 	INDICATOR_AUTO = 0,
151 	INDICATOR_CYCLE,
152 	/* software blinks for attention:  software, hardware, reserved */
153 	INDICATOR_GREEN_BLINK, INDICATOR_GREEN_BLINK_OFF,
154 	INDICATOR_AMBER_BLINK, INDICATOR_AMBER_BLINK_OFF,
155 	INDICATOR_ALT_BLINK, INDICATOR_ALT_BLINK_OFF
156 } __attribute__ ((packed));
157 
158 struct usb_device;
159 
160 /* Transaction Translator Think Times, in bits */
161 #define HUB_TTTT_8_BITS		0x00
162 #define HUB_TTTT_16_BITS	0x20
163 #define HUB_TTTT_24_BITS	0x40
164 #define HUB_TTTT_32_BITS	0x60
165 
166 /*
167  * As of USB 2.0, full/low speed devices are segregated into trees.
168  * One type grows from USB 1.1 host controllers (OHCI, UHCI etc).
169  * The other type grows from high speed hubs when they connect to
170  * full/low speed devices using "Transaction Translators" (TTs).
171  *
172  * TTs should only be known to the hub driver, and high speed bus
173  * drivers (only EHCI for now).  They affect periodic scheduling and
174  * sometimes control/bulk error recovery.
175  */
176 struct usb_tt {
177 	struct usb_device	*hub;	/* upstream highspeed hub */
178 	int			multi;	/* true means one TT per port */
179 	unsigned		think_time;	/* think time in ns */
180 
181 	/* for control/bulk error recovery (CLEAR_TT_BUFFER) */
182 	spinlock_t		lock;
183 	struct list_head	clear_list;	/* of usb_tt_clear */
184 	struct work_struct			kevent;
185 };
186 
187 struct usb_tt_clear {
188 	struct list_head	clear_list;
189 	unsigned		tt;
190 	u16			devinfo;
191 };
192 
193 extern void usb_hub_tt_clear_buffer (struct usb_device *dev, int pipe);
194 
195 struct usb_hub {
196 	struct device		*intfdev;	/* the "interface" device */
197 	struct usb_device	*hdev;
198 	struct urb		*urb;		/* for interrupt polling pipe */
199 
200 	/* buffer for urb ... with extra space in case of babble */
201 	char			(*buffer)[8];
202 	dma_addr_t		buffer_dma;	/* DMA address for buffer */
203 	union {
204 		struct usb_hub_status	hub;
205 		struct usb_port_status	port;
206 	}			*status;	/* buffer for status reports */
207 
208 	int			error;		/* last reported error */
209 	int			nerrors;	/* track consecutive errors */
210 
211 	struct list_head	event_list;	/* hubs w/data or errs ready */
212 	unsigned long		event_bits[1];	/* status change bitmask */
213 	unsigned long		change_bits[1];	/* ports with logical connect
214 							status change */
215 	unsigned long		busy_bits[1];	/* ports being reset */
216 #if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */
217 #error event_bits[] is too short!
218 #endif
219 
220 	struct usb_hub_descriptor *descriptor;	/* class descriptor */
221 	struct usb_tt		tt;		/* Transaction Translator */
222 
223 	unsigned		mA_per_port;	/* current for each child */
224 
225 	unsigned		limited_power:1;
226 	unsigned		quiescing:1;
227 	unsigned		activating:1;
228 	unsigned		resume_root_hub:1;
229 
230 	unsigned		has_indicators:1;
231 	enum hub_led_mode	indicator[USB_MAXCHILDREN];
232 	struct work_struct	leds;
233 };
234 
235 #endif /* __LINUX_HUB_H */
236