• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file holds Hub protocol constants and data structures that are
3  * defined in chapter 11 (Hub Specification) of the USB 2.0 specification.
4  *
5  * It is used/shared between the USB core, the HCDs and couple of other USB
6  * drivers.
7  */
8 
9 #ifndef __LINUX_CH11_H
10 #define __LINUX_CH11_H
11 
12 #include <linux/types.h>	/* __u8 etc */
13 
14 /* This is arbitrary.
15  * From USB 2.0 spec Table 11-13, offset 7, a hub can
16  * have up to 255 ports. The most yet reported is 10.
17  *
18  * Current Wireless USB host hardware (Intel i1480 for example) allows
19  * up to 22 devices to connect. Upcoming hardware might raise that
20  * limit. Because the arrays need to add a bit for hub status data, we
21  * use 31, so plus one evens out to four bytes.
22  */
23 #define USB_MAXCHILDREN		31
24 
25 /* See USB 3.1 spec Table 10-5 */
26 #define USB_SS_MAXPORTS		15
27 
28 /*
29  * Hub request types
30  */
31 
32 #define USB_RT_HUB	(USB_TYPE_CLASS | USB_RECIP_DEVICE)
33 #define USB_RT_PORT	(USB_TYPE_CLASS | USB_RECIP_OTHER)
34 
35 /*
36  * Hub class requests
37  * See USB 2.0 spec Table 11-16
38  */
39 #define HUB_CLEAR_TT_BUFFER	8
40 #define HUB_RESET_TT		9
41 #define HUB_GET_TT_STATE	10
42 #define HUB_STOP_TT		11
43 
44 /*
45  * Hub class additional requests defined by USB 3.0 spec
46  * See USB 3.0 spec Table 10-6
47  */
48 #define HUB_SET_DEPTH		12
49 #define HUB_GET_PORT_ERR_COUNT	13
50 
51 /*
52  * Hub Class feature numbers
53  * See USB 2.0 spec Table 11-17
54  */
55 #define C_HUB_LOCAL_POWER	0
56 #define C_HUB_OVER_CURRENT	1
57 
58 /*
59  * Port feature numbers
60  * See USB 2.0 spec Table 11-17
61  */
62 #define USB_PORT_FEAT_CONNECTION	0
63 #define USB_PORT_FEAT_ENABLE		1
64 #define USB_PORT_FEAT_SUSPEND		2	/* L2 suspend */
65 #define USB_PORT_FEAT_OVER_CURRENT	3
66 #define USB_PORT_FEAT_RESET		4
67 #define USB_PORT_FEAT_L1		5	/* L1 suspend */
68 #define USB_PORT_FEAT_POWER		8
69 #define USB_PORT_FEAT_LOWSPEED		9	/* Should never be used */
70 #define USB_PORT_FEAT_C_CONNECTION	16
71 #define USB_PORT_FEAT_C_ENABLE		17
72 #define USB_PORT_FEAT_C_SUSPEND		18
73 #define USB_PORT_FEAT_C_OVER_CURRENT	19
74 #define USB_PORT_FEAT_C_RESET		20
75 #define USB_PORT_FEAT_TEST              21
76 #define USB_PORT_FEAT_INDICATOR         22
77 #define USB_PORT_FEAT_C_PORT_L1         23
78 
79 /*
80  * Port feature selectors added by USB 3.0 spec.
81  * See USB 3.0 spec Table 10-7
82  */
83 #define USB_PORT_FEAT_LINK_STATE		5
84 #define USB_PORT_FEAT_U1_TIMEOUT		23
85 #define USB_PORT_FEAT_U2_TIMEOUT		24
86 #define USB_PORT_FEAT_C_PORT_LINK_STATE		25
87 #define USB_PORT_FEAT_C_PORT_CONFIG_ERROR	26
88 #define USB_PORT_FEAT_REMOTE_WAKE_MASK		27
89 #define USB_PORT_FEAT_BH_PORT_RESET		28
90 #define USB_PORT_FEAT_C_BH_PORT_RESET		29
91 #define USB_PORT_FEAT_FORCE_LINKPM_ACCEPT	30
92 
93 #define USB_PORT_LPM_TIMEOUT(p)			(((p) & 0xff) << 8)
94 
95 /* USB 3.0 hub remote wake mask bits, see table 10-14 */
96 #define USB_PORT_FEAT_REMOTE_WAKE_CONNECT	(1 << 8)
97 #define USB_PORT_FEAT_REMOTE_WAKE_DISCONNECT	(1 << 9)
98 #define USB_PORT_FEAT_REMOTE_WAKE_OVER_CURRENT	(1 << 10)
99 
100 /*
101  * Hub Status and Hub Change results
102  * See USB 2.0 spec Table 11-19 and Table 11-20
103  */
104 struct usb_port_status {
105 	__le16 wPortStatus;
106 	__le16 wPortChange;
107 } __attribute__ ((packed));
108 
109 /*
110  * wPortStatus bit field
111  * See USB 2.0 spec Table 11-21
112  */
113 #define USB_PORT_STAT_CONNECTION	0x0001
114 #define USB_PORT_STAT_ENABLE		0x0002
115 #define USB_PORT_STAT_SUSPEND		0x0004
116 #define USB_PORT_STAT_OVERCURRENT	0x0008
117 #define USB_PORT_STAT_RESET		0x0010
118 #define USB_PORT_STAT_L1		0x0020
119 /* bits 6 to 7 are reserved */
120 #define USB_PORT_STAT_POWER		0x0100
121 #define USB_PORT_STAT_LOW_SPEED		0x0200
122 #define USB_PORT_STAT_HIGH_SPEED        0x0400
123 #define USB_PORT_STAT_TEST              0x0800
124 #define USB_PORT_STAT_INDICATOR         0x1000
125 /* bits 13 to 15 are reserved */
126 
127 /*
128  * Additions to wPortStatus bit field from USB 3.0
129  * See USB 3.0 spec Table 10-10
130  */
131 #define USB_PORT_STAT_LINK_STATE	0x01e0
132 #define USB_SS_PORT_STAT_POWER		0x0200
133 #define USB_SS_PORT_STAT_SPEED		0x1c00
134 #define USB_PORT_STAT_SPEED_5GBPS	0x0000
135 /* Valid only if port is enabled */
136 /* Bits that are the same from USB 2.0 */
137 #define USB_SS_PORT_STAT_MASK (USB_PORT_STAT_CONNECTION |	    \
138 				USB_PORT_STAT_ENABLE |	    \
139 				USB_PORT_STAT_OVERCURRENT | \
140 				USB_PORT_STAT_RESET)
141 
142 /*
143  * Definitions for PORT_LINK_STATE values
144  * (bits 5-8) in wPortStatus
145  */
146 #define USB_SS_PORT_LS_U0		0x0000
147 #define USB_SS_PORT_LS_U1		0x0020
148 #define USB_SS_PORT_LS_U2		0x0040
149 #define USB_SS_PORT_LS_U3		0x0060
150 #define USB_SS_PORT_LS_SS_DISABLED	0x0080
151 #define USB_SS_PORT_LS_RX_DETECT	0x00a0
152 #define USB_SS_PORT_LS_SS_INACTIVE	0x00c0
153 #define USB_SS_PORT_LS_POLLING		0x00e0
154 #define USB_SS_PORT_LS_RECOVERY		0x0100
155 #define USB_SS_PORT_LS_HOT_RESET	0x0120
156 #define USB_SS_PORT_LS_COMP_MOD		0x0140
157 #define USB_SS_PORT_LS_LOOPBACK		0x0160
158 
159 /*
160  * wPortChange bit field
161  * See USB 2.0 spec Table 11-22 and USB 2.0 LPM ECN Table-4.10
162  * Bits 0 to 5 shown, bits 6 to 15 are reserved
163  */
164 #define USB_PORT_STAT_C_CONNECTION	0x0001
165 #define USB_PORT_STAT_C_ENABLE		0x0002
166 #define USB_PORT_STAT_C_SUSPEND		0x0004
167 #define USB_PORT_STAT_C_OVERCURRENT	0x0008
168 #define USB_PORT_STAT_C_RESET		0x0010
169 #define USB_PORT_STAT_C_L1		0x0020
170 /*
171  * USB 3.0 wPortChange bit fields
172  * See USB 3.0 spec Table 10-11
173  */
174 #define USB_PORT_STAT_C_BH_RESET	0x0020
175 #define USB_PORT_STAT_C_LINK_STATE	0x0040
176 #define USB_PORT_STAT_C_CONFIG_ERROR	0x0080
177 
178 /*
179  * wHubCharacteristics (masks)
180  * See USB 2.0 spec Table 11-13, offset 3
181  */
182 #define HUB_CHAR_LPSM		0x0003 /* Logical Power Switching Mode mask */
183 #define HUB_CHAR_COMMON_LPSM	0x0000 /* All ports power control at once */
184 #define HUB_CHAR_INDV_PORT_LPSM	0x0001 /* per-port power control */
185 #define HUB_CHAR_NO_LPSM	0x0002 /* no power switching */
186 
187 #define HUB_CHAR_COMPOUND	0x0004 /* hub is part of a compound device */
188 
189 #define HUB_CHAR_OCPM		0x0018 /* Over-Current Protection Mode mask */
190 #define HUB_CHAR_COMMON_OCPM	0x0000 /* All ports Over-Current reporting */
191 #define HUB_CHAR_INDV_PORT_OCPM	0x0008 /* per-port Over-current reporting */
192 #define HUB_CHAR_NO_OCPM	0x0010 /* No Over-current Protection support */
193 
194 #define HUB_CHAR_TTTT		0x0060 /* TT Think Time mask */
195 #define HUB_CHAR_PORTIND	0x0080 /* per-port indicators (LEDs) */
196 
197 struct usb_hub_status {
198 	__le16 wHubStatus;
199 	__le16 wHubChange;
200 } __attribute__ ((packed));
201 
202 /*
203  * Hub Status & Hub Change bit masks
204  * See USB 2.0 spec Table 11-19 and Table 11-20
205  * Bits 0 and 1 for wHubStatus and wHubChange
206  * Bits 2 to 15 are reserved for both
207  */
208 #define HUB_STATUS_LOCAL_POWER	0x0001
209 #define HUB_STATUS_OVERCURRENT	0x0002
210 #define HUB_CHANGE_LOCAL_POWER	0x0001
211 #define HUB_CHANGE_OVERCURRENT	0x0002
212 
213 
214 /*
215  * Hub descriptor
216  * See USB 2.0 spec Table 11-13
217  */
218 
219 #define USB_DT_HUB			(USB_TYPE_CLASS | 0x09)
220 #define USB_DT_SS_HUB			(USB_TYPE_CLASS | 0x0a)
221 #define USB_DT_HUB_NONVAR_SIZE		7
222 #define USB_DT_SS_HUB_SIZE              12
223 
224 /*
225  * Hub Device descriptor
226  * USB Hub class device protocols
227  */
228 
229 #define USB_HUB_PR_FS		0 /* Full speed hub */
230 #define USB_HUB_PR_HS_NO_TT	0 /* Hi-speed hub without TT */
231 #define USB_HUB_PR_HS_SINGLE_TT	1 /* Hi-speed hub with single TT */
232 #define USB_HUB_PR_HS_MULTI_TT	2 /* Hi-speed hub with multiple TT */
233 #define USB_HUB_PR_SS		3 /* Super speed hub */
234 
235 struct usb_hub_descriptor {
236 	__u8  bDescLength;
237 	__u8  bDescriptorType;
238 	__u8  bNbrPorts;
239 	__le16 wHubCharacteristics;
240 	__u8  bPwrOn2PwrGood;
241 	__u8  bHubContrCurrent;
242 
243 	/* 2.0 and 3.0 hubs differ here */
244 	union {
245 		struct {
246 			/* add 1 bit for hub status change; round to bytes */
247 			__u8  DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8];
248 			__u8  PortPwrCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8];
249 		}  __attribute__ ((packed)) hs;
250 
251 		struct {
252 			__u8 bHubHdrDecLat;
253 			__le16 wHubDelay;
254 			__le16 DeviceRemovable;
255 		}  __attribute__ ((packed)) ss;
256 	} u;
257 } __attribute__ ((packed));
258 
259 /* port indicator status selectors, tables 11-7 and 11-25 */
260 #define HUB_LED_AUTO	0
261 #define HUB_LED_AMBER	1
262 #define HUB_LED_GREEN	2
263 #define HUB_LED_OFF	3
264 
265 enum hub_led_mode {
266 	INDICATOR_AUTO = 0,
267 	INDICATOR_CYCLE,
268 	/* software blinks for attention:  software, hardware, reserved */
269 	INDICATOR_GREEN_BLINK, INDICATOR_GREEN_BLINK_OFF,
270 	INDICATOR_AMBER_BLINK, INDICATOR_AMBER_BLINK_OFF,
271 	INDICATOR_ALT_BLINK, INDICATOR_ALT_BLINK_OFF
272 } __attribute__ ((packed));
273 
274 /* Transaction Translator Think Times, in bits */
275 #define HUB_TTTT_8_BITS		0x00
276 #define HUB_TTTT_16_BITS	0x20
277 #define HUB_TTTT_24_BITS	0x40
278 #define HUB_TTTT_32_BITS	0x60
279 
280 #endif /* __LINUX_CH11_H */
281