blob: 576c704e3fb8b13f358ae67b3a415417f2c37cb5 [file] [log] [blame]
Eric Lescouetd20db4b2010-04-24 23:38:17 +02001/*
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
Alan Stern3b02ca32010-04-30 12:42:23 -04009#ifndef __LINUX_CH11_H
10#define __LINUX_CH11_H
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Alan Stern3b02ca32010-04-30 12:42:23 -040012#include <linux/types.h> /* __u8 etc */
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
Alan Stern36ff66d2013-06-27 15:27:07 -040014/* 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
Johan Hovold93491ce2017-05-10 18:18:29 +020025/* See USB 3.1 spec Table 10-5 */
26#define USB_SS_MAXPORTS 15
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028/*
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/*
Mathias Nyman0cdd49a2015-12-10 09:59:29 +020036 * Port status type for GetPortStatus requests added in USB 3.1
37 * See USB 3.1 spec Table 10-12
38 */
39#define HUB_PORT_STATUS 0
40#define HUB_PORT_PD_STATUS 1
41#define HUB_EXT_PORT_STATUS 2
42
43/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 * Hub class requests
45 * See USB 2.0 spec Table 11-16
46 */
47#define HUB_CLEAR_TT_BUFFER 8
48#define HUB_RESET_TT 9
49#define HUB_GET_TT_STATE 10
50#define HUB_STOP_TT 11
51
52/*
Tatyana Brokhman0eadcc02010-11-01 18:18:24 +020053 * Hub class additional requests defined by USB 3.0 spec
54 * See USB 3.0 spec Table 10-6
55 */
56#define HUB_SET_DEPTH 12
57#define HUB_GET_PORT_ERR_COUNT 13
58
59/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 * Hub Class feature numbers
61 * See USB 2.0 spec Table 11-17
62 */
63#define C_HUB_LOCAL_POWER 0
64#define C_HUB_OVER_CURRENT 1
65
66/*
67 * Port feature numbers
68 * See USB 2.0 spec Table 11-17
69 */
70#define USB_PORT_FEAT_CONNECTION 0
71#define USB_PORT_FEAT_ENABLE 1
David Brownelldbe0dbb2008-02-10 12:24:00 -080072#define USB_PORT_FEAT_SUSPEND 2 /* L2 suspend */
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#define USB_PORT_FEAT_OVER_CURRENT 3
74#define USB_PORT_FEAT_RESET 4
David Brownelldbe0dbb2008-02-10 12:24:00 -080075#define USB_PORT_FEAT_L1 5 /* L1 suspend */
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#define USB_PORT_FEAT_POWER 8
Alan Stern288ead42010-03-04 11:32:30 -050077#define USB_PORT_FEAT_LOWSPEED 9 /* Should never be used */
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#define USB_PORT_FEAT_C_CONNECTION 16
79#define USB_PORT_FEAT_C_ENABLE 17
80#define USB_PORT_FEAT_C_SUSPEND 18
81#define USB_PORT_FEAT_C_OVER_CURRENT 19
82#define USB_PORT_FEAT_C_RESET 20
83#define USB_PORT_FEAT_TEST 21
84#define USB_PORT_FEAT_INDICATOR 22
David Brownelldbe0dbb2008-02-10 12:24:00 -080085#define USB_PORT_FEAT_C_PORT_L1 23
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Greg Kroah-Hartman84cca822008-01-30 15:21:33 -080087/*
Tatyana Brokhman0eadcc02010-11-01 18:18:24 +020088 * Port feature selectors added by USB 3.0 spec.
89 * See USB 3.0 spec Table 10-7
90 */
91#define USB_PORT_FEAT_LINK_STATE 5
92#define USB_PORT_FEAT_U1_TIMEOUT 23
93#define USB_PORT_FEAT_U2_TIMEOUT 24
Sarah Sharpd9f53432012-01-05 16:28:54 -080094#define USB_PORT_FEAT_C_PORT_LINK_STATE 25
95#define USB_PORT_FEAT_C_PORT_CONFIG_ERROR 26
Tatyana Brokhman0eadcc02010-11-01 18:18:24 +020096#define USB_PORT_FEAT_REMOTE_WAKE_MASK 27
97#define USB_PORT_FEAT_BH_PORT_RESET 28
98#define USB_PORT_FEAT_C_BH_PORT_RESET 29
99#define USB_PORT_FEAT_FORCE_LINKPM_ACCEPT 30
100
Sarah Sharp1ea7e0e2012-04-24 17:21:50 -0700101#define USB_PORT_LPM_TIMEOUT(p) (((p) & 0xff) << 8)
102
Sarah Sharp4296c70a2012-01-06 10:34:31 -0800103/* USB 3.0 hub remote wake mask bits, see table 10-14 */
104#define USB_PORT_FEAT_REMOTE_WAKE_CONNECT (1 << 8)
105#define USB_PORT_FEAT_REMOTE_WAKE_DISCONNECT (1 << 9)
106#define USB_PORT_FEAT_REMOTE_WAKE_OVER_CURRENT (1 << 10)
107
Tatyana Brokhman0eadcc02010-11-01 18:18:24 +0200108/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 * Hub Status and Hub Change results
110 * See USB 2.0 spec Table 11-19 and Table 11-20
Mathias Nyman0cdd49a2015-12-10 09:59:29 +0200111 * USB 3.1 extends the port status request and may return 4 additional bytes.
112 * See USB 3.1 spec section 10.16.2.6 Table 10-12 and 10-15
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 */
114struct usb_port_status {
115 __le16 wPortStatus;
Greg Kroah-Hartman84cca822008-01-30 15:21:33 -0800116 __le16 wPortChange;
Mathias Nyman0cdd49a2015-12-10 09:59:29 +0200117 __le32 dwExtPortStatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118} __attribute__ ((packed));
119
Greg Kroah-Hartman84cca822008-01-30 15:21:33 -0800120/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 * wPortStatus bit field
122 * See USB 2.0 spec Table 11-21
123 */
124#define USB_PORT_STAT_CONNECTION 0x0001
125#define USB_PORT_STAT_ENABLE 0x0002
126#define USB_PORT_STAT_SUSPEND 0x0004
127#define USB_PORT_STAT_OVERCURRENT 0x0008
128#define USB_PORT_STAT_RESET 0x0010
David Brownelldbe0dbb2008-02-10 12:24:00 -0800129#define USB_PORT_STAT_L1 0x0020
130/* bits 6 to 7 are reserved */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#define USB_PORT_STAT_POWER 0x0100
132#define USB_PORT_STAT_LOW_SPEED 0x0200
133#define USB_PORT_STAT_HIGH_SPEED 0x0400
134#define USB_PORT_STAT_TEST 0x0800
135#define USB_PORT_STAT_INDICATOR 0x1000
136/* bits 13 to 15 are reserved */
137
Greg Kroah-Hartman84cca822008-01-30 15:21:33 -0800138/*
Tatyana Brokhman0eadcc02010-11-01 18:18:24 +0200139 * Additions to wPortStatus bit field from USB 3.0
140 * See USB 3.0 spec Table 10-10
141 */
142#define USB_PORT_STAT_LINK_STATE 0x01e0
143#define USB_SS_PORT_STAT_POWER 0x0200
John Youndbe79bb2001-09-17 00:00:00 -0700144#define USB_SS_PORT_STAT_SPEED 0x1c00
Tatyana Brokhman0eadcc02010-11-01 18:18:24 +0200145#define USB_PORT_STAT_SPEED_5GBPS 0x0000
146/* Valid only if port is enabled */
John Youndbe79bb2001-09-17 00:00:00 -0700147/* Bits that are the same from USB 2.0 */
148#define USB_SS_PORT_STAT_MASK (USB_PORT_STAT_CONNECTION | \
149 USB_PORT_STAT_ENABLE | \
150 USB_PORT_STAT_OVERCURRENT | \
151 USB_PORT_STAT_RESET)
Tatyana Brokhman0eadcc02010-11-01 18:18:24 +0200152
153/*
154 * Definitions for PORT_LINK_STATE values
155 * (bits 5-8) in wPortStatus
156 */
157#define USB_SS_PORT_LS_U0 0x0000
158#define USB_SS_PORT_LS_U1 0x0020
159#define USB_SS_PORT_LS_U2 0x0040
160#define USB_SS_PORT_LS_U3 0x0060
161#define USB_SS_PORT_LS_SS_DISABLED 0x0080
162#define USB_SS_PORT_LS_RX_DETECT 0x00a0
163#define USB_SS_PORT_LS_SS_INACTIVE 0x00c0
164#define USB_SS_PORT_LS_POLLING 0x00e0
165#define USB_SS_PORT_LS_RECOVERY 0x0100
166#define USB_SS_PORT_LS_HOT_RESET 0x0120
167#define USB_SS_PORT_LS_COMP_MOD 0x0140
168#define USB_SS_PORT_LS_LOOPBACK 0x0160
169
170/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 * wPortChange bit field
Paul Bolleb9f2e9a2011-02-14 23:06:15 +0100172 * See USB 2.0 spec Table 11-22 and USB 2.0 LPM ECN Table-4.10
173 * Bits 0 to 5 shown, bits 6 to 15 are reserved
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 */
175#define USB_PORT_STAT_C_CONNECTION 0x0001
176#define USB_PORT_STAT_C_ENABLE 0x0002
177#define USB_PORT_STAT_C_SUSPEND 0x0004
178#define USB_PORT_STAT_C_OVERCURRENT 0x0008
179#define USB_PORT_STAT_C_RESET 0x0010
David Brownelldbe0dbb2008-02-10 12:24:00 -0800180#define USB_PORT_STAT_C_L1 0x0020
John Youndbe79bb2001-09-17 00:00:00 -0700181/*
182 * USB 3.0 wPortChange bit fields
183 * See USB 3.0 spec Table 10-11
184 */
185#define USB_PORT_STAT_C_BH_RESET 0x0020
186#define USB_PORT_STAT_C_LINK_STATE 0x0040
187#define USB_PORT_STAT_C_CONFIG_ERROR 0x0080
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189/*
Mathias Nyman0cdd49a2015-12-10 09:59:29 +0200190 * USB 3.1 dwExtPortStatus field masks
191 * See USB 3.1 spec 10.16.2.6.3 Table 10-15
192 */
193
194#define USB_EXT_PORT_STAT_RX_SPEED_ID 0x0000000f
195#define USB_EXT_PORT_STAT_TX_SPEED_ID 0x000000f0
196#define USB_EXT_PORT_STAT_RX_LANES 0x00000f00
197#define USB_EXT_PORT_STAT_TX_LANES 0x0000f000
198
199/*
Greg Kroah-Hartman84cca822008-01-30 15:21:33 -0800200 * wHubCharacteristics (masks)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 * See USB 2.0 spec Table 11-13, offset 3
202 */
Aman Deepc8421142011-11-22 19:33:36 +0530203#define HUB_CHAR_LPSM 0x0003 /* Logical Power Switching Mode mask */
204#define HUB_CHAR_COMMON_LPSM 0x0000 /* All ports power control at once */
205#define HUB_CHAR_INDV_PORT_LPSM 0x0001 /* per-port power control */
206#define HUB_CHAR_NO_LPSM 0x0002 /* no power switching */
207
208#define HUB_CHAR_COMPOUND 0x0004 /* hub is part of a compound device */
209
210#define HUB_CHAR_OCPM 0x0018 /* Over-Current Protection Mode mask */
211#define HUB_CHAR_COMMON_OCPM 0x0000 /* All ports Over-Current reporting */
212#define HUB_CHAR_INDV_PORT_OCPM 0x0008 /* per-port Over-current reporting */
213#define HUB_CHAR_NO_OCPM 0x0010 /* No Over-current Protection support */
214
215#define HUB_CHAR_TTTT 0x0060 /* TT Think Time mask */
216#define HUB_CHAR_PORTIND 0x0080 /* per-port indicators (LEDs) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
218struct usb_hub_status {
219 __le16 wHubStatus;
220 __le16 wHubChange;
221} __attribute__ ((packed));
222
223/*
224 * Hub Status & Hub Change bit masks
225 * See USB 2.0 spec Table 11-19 and Table 11-20
226 * Bits 0 and 1 for wHubStatus and wHubChange
227 * Bits 2 to 15 are reserved for both
228 */
229#define HUB_STATUS_LOCAL_POWER 0x0001
230#define HUB_STATUS_OVERCURRENT 0x0002
231#define HUB_CHANGE_LOCAL_POWER 0x0001
232#define HUB_CHANGE_OVERCURRENT 0x0002
233
234
Greg Kroah-Hartman84cca822008-01-30 15:21:33 -0800235/*
236 * Hub descriptor
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 * See USB 2.0 spec Table 11-13
238 */
239
240#define USB_DT_HUB (USB_TYPE_CLASS | 0x09)
John Youndbe79bb2001-09-17 00:00:00 -0700241#define USB_DT_SS_HUB (USB_TYPE_CLASS | 0x0a)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242#define USB_DT_HUB_NONVAR_SIZE 7
John Youndbe79bb2001-09-17 00:00:00 -0700243#define USB_DT_SS_HUB_SIZE 12
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Aman Deep7bf01182011-12-08 12:05:22 +0530245/*
246 * Hub Device descriptor
247 * USB Hub class device protocols
248 */
249
250#define USB_HUB_PR_FS 0 /* Full speed hub */
251#define USB_HUB_PR_HS_NO_TT 0 /* Hi-speed hub without TT */
252#define USB_HUB_PR_HS_SINGLE_TT 1 /* Hi-speed hub with single TT */
253#define USB_HUB_PR_HS_MULTI_TT 2 /* Hi-speed hub with multiple TT */
254#define USB_HUB_PR_SS 3 /* Super speed hub */
255
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256struct usb_hub_descriptor {
257 __u8 bDescLength;
258 __u8 bDescriptorType;
259 __u8 bNbrPorts;
Greg Kroah-Hartman74ad9bd2005-06-20 21:15:16 -0700260 __le16 wHubCharacteristics;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 __u8 bPwrOn2PwrGood;
262 __u8 bHubContrCurrent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
John Youndbe79bb2001-09-17 00:00:00 -0700264 /* 2.0 and 3.0 hubs differ here */
265 union {
266 struct {
267 /* add 1 bit for hub status change; round to bytes */
268 __u8 DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8];
269 __u8 PortPwrCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8];
270 } __attribute__ ((packed)) hs;
271
272 struct {
273 __u8 bHubHdrDecLat;
Lan Tianyu9c208902012-09-10 21:24:41 +0800274 __le16 wHubDelay;
275 __le16 DeviceRemovable;
John Youndbe79bb2001-09-17 00:00:00 -0700276 } __attribute__ ((packed)) ss;
277 } u;
278} __attribute__ ((packed));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
280/* port indicator status selectors, tables 11-7 and 11-25 */
281#define HUB_LED_AUTO 0
282#define HUB_LED_AMBER 1
283#define HUB_LED_GREEN 2
284#define HUB_LED_OFF 3
285
286enum hub_led_mode {
287 INDICATOR_AUTO = 0,
288 INDICATOR_CYCLE,
289 /* software blinks for attention: software, hardware, reserved */
290 INDICATOR_GREEN_BLINK, INDICATOR_GREEN_BLINK_OFF,
291 INDICATOR_AMBER_BLINK, INDICATOR_AMBER_BLINK_OFF,
292 INDICATOR_ALT_BLINK, INDICATOR_ALT_BLINK_OFF
293} __attribute__ ((packed));
294
david-b@pacbell.nete09711a2005-08-13 18:41:04 -0700295/* Transaction Translator Think Times, in bits */
296#define HUB_TTTT_8_BITS 0x00
297#define HUB_TTTT_16_BITS 0x20
298#define HUB_TTTT_24_BITS 0x40
299#define HUB_TTTT_32_BITS 0x60
300
Alan Stern3b02ca32010-04-30 12:42:23 -0400301#endif /* __LINUX_CH11_H */