xref: /illumos-gate/usr/src/uts/common/sys/usb/hubd/hub.h (revision a17ce84520dc4e972c913e0fa1d1545ddd22b55e)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  *
25  * Copyright 2016 Joyent, Inc.
26  */
27 
28 #ifndef	_SYS_USB_HUB_H
29 #define	_SYS_USB_HUB_H
30 
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #define	HUBD_DEFAULT_DESC_INDEX		0
37 
38 /*
39  * Section 11.11.2.1 allows up to 255 ports.
40  * For simplicity, only a maximum of 31 ports is currently allowed
41  */
42 #define	MAX_PORTS 31
43 
44 typedef struct usb_hub_descr {
45 	uchar_t		bDescLength;	/* size of descriptor */
46 	uchar_t		bDescriptorType; /* descriptor type */
47 	uchar_t		bNbrPorts;	/* number of ports */
48 	uint16_t	wHubCharacteristics; /* hub characteristics */
49 	uchar_t		bPwrOn2PwrGood;	/* time in ms from the time */
50 				/* power on sequence begins on a port */
51 				/* until power is good on that port */
52 	uchar_t		bHubContrCurrent; /* max current requirements */
53 	uchar_t		DeviceRemovable;
54 					/* removable device attached */
55 	uchar_t		PortPwrCtrlMask;
56 					/* power control mask */
57 } usb_hub_descr_t;
58 
59 /*
60  * In USB 3.x the format of the root hub description has changed. See USB 3.1 /
61  * 10.15.12.1.
62  */
63 #pragma pack(1)
64 typedef struct usb_ss_hub_descr {
65 	uint8_t		bDescLength;		/* size of descriptor */
66 	uint8_t		bDescriptorType;	/* descriptor type (0x2A) */
67 	uint8_t		bNbrPorts;		/* number of ports */
68 	uint16_t	wHubCharacteristics;	/* hub characteristics */
69 	uint8_t		bPwrOn2PwrGood;	/* time in 2-ms from power on */
70 						/* until the port is ready */
71 	uint8_t		bHubContrCurrent;	/* max current requirements */
72 	uint8_t		bHubHdrDecLat;		/* hub packet decode latency */
73 	uint16_t	wHubDelay;		/* Forwarding delay in ns */
74 	uint16_t	DeviceRemovable[32];	/* indicates per-port whether */
75 					/* the device is removable with one */
76 					/* bit per port, up to 255 ports */
77 } usb_ss_hub_descr_t;
78 #pragma pack()
79 
80 #define	ROOT_HUB_DESCRIPTOR_LENGTH	9
81 #define	ROOT_HUB_DESCRIPTOR_TYPE	0x29
82 #define	ROOT_HUB_SS_DESCRIPTOR_TYPE	0x2A
83 #define	ROOT_HUB_ADDR			0x01	/* address of root hub */
84 
85 /* Values for wHubCharacteristics */
86 #define	HUB_CHARS_POWER_SWITCHING_MODE	0x03
87 #define	HUB_CHARS_GANGED_POWER		0x00
88 #define	HUB_CHARS_INDIVIDUAL_PORT_POWER	0x01
89 #define	HUB_CHARS_NO_POWER_SWITCHING	0x02
90 #define	HUB_CHARS_COMPOUND_DEV		0x04
91 #define	HUB_CHARS_GLOBAL_OVER_CURRENT	0x00
92 #define	HUB_CHARS_INDIV_OVER_CURRENT	0x08
93 #define	HUB_CHARS_NO_OVER_CURRENT	0x10
94 #define	HUB_CHARS_TT_THINK_TIME		0x60
95 #define	HUB_CHARS_TT_16FS_TIME		0x20
96 #define	HUB_CHARS_TT_24FS_TIME		0x40
97 #define	HUB_CHARS_TT_32FS_TIME		0x60
98 #define	HUB_CHARS_PORT_INDICATOR	0x80
99 
100 #define	HUB_CHARS_TT_SHIFT		5
101 
102 /* Default Power On to Power Good time */
103 #define	HUB_DEFAULT_POPG	10
104 
105 /* Hub Status */
106 #define	HUB_CHANGE_STATUS	0x01
107 
108 /* Class Specific bmRequestType values Table 11-10 */
109 #define	HUB_HANDLE_PORT_FEATURE_TYPE	(USB_DEV_REQ_HOST_TO_DEV \
110 					|USB_DEV_REQ_TYPE_CLASS \
111 					|USB_DEV_REQ_RCPT_OTHER)
112 
113 #define	HUB_GET_PORT_STATUS_TYPE	(USB_DEV_REQ_DEV_TO_HOST \
114 					|USB_DEV_REQ_TYPE_CLASS \
115 					|USB_DEV_REQ_RCPT_OTHER)
116 
117 #define	HUB_CLASS_REQ_TYPE		(USB_DEV_REQ_DEV_TO_HOST \
118 					|USB_DEV_REQ_TYPE_CLASS)
119 
120 #define	HUB_HANDLE_HUB_FEATURE_TYPE	USB_DEV_REQ_TYPE_CLASS
121 
122 #define	HUB_SET_HUB_DEPTH_TYPE		(USB_DEV_REQ_HOST_TO_DEV \
123 					|USB_DEV_REQ_TYPE_CLASS \
124 					|USB_DEV_REQ_RCPT_DEV)
125 
126 /* bmRequestType for getting device status */
127 #define	HUB_GET_DEVICE_STATUS_TYPE	(USB_DEV_REQ_DEV_TO_HOST \
128 					|USB_DEV_REQ_TYPE_STANDARD \
129 					|USB_DEV_REQ_RCPT_DEV)
130 
131 /*
132  * Class specific bRequest values that don't line up with standard requests. See
133  * USB 3.1 / Table 10-8.
134  */
135 #define	HUB_REQ_SET_HUB_DEPTH		12
136 
137 /*
138  * Port Status Field Bits. While there is overlap between the USB 2.0 and USB
139  * 3.0 bits, they aren't entirely the same and some bits have different meanings
140  * across different versions of USB. Common bits are shared first and then this
141  * is broken down into device specific bits. The USB 3 version is in USB
142  * 3.1/10.16.2.6.1. The USB 2 version is in USB 2/11.24.2.7.1.
143  */
144 #define	PORT_STATUS_CCS		0x0001	/* port connection status */
145 #define	PORT_STATUS_PES		0x0002	/* port enable status */
146 #define	PORT_STATUS_PSS		0x0004	/* port suspend status */
147 #define	PORT_STATUS_POCI	0x0008	/* port over current indicator */
148 #define	PORT_STATUS_PRS		0x0010	/* port reset status */
149 #define	PORT_STATUS_PPS		0x0100	/* port power status */
150 
151 /* USB 2.0 specific bits */
152 #define	PORT_STATUS_LSDA	0x0200	/* low speed device */
153 #define	PORT_STATUS_HSDA	0x0400	/* high speed device */
154 #define	PORT_STATUS_PIC		0x1000	/* port indicator control */
155 
156 /*
157  * The USB 2.0 and USB 3.0 port status bits are almost identical; however, the
158  * location of the port's power indicator is different for hubs. To deal with
159  * this, we have logic, hubd_status_unifornm, that transforms the USB 3 status
160  * to USB 2, hence why we only have one version of these macros below.
161  */
162 #define	PORT_STATUS_MASK	0x171f
163 #define	PORT_STATUS_OK		0x103	/* connected, enabled, power */
164 
165 /* USB 3 Specific bits */
166 #define	PORT_STATUS_PPS_SS	0x0200	/* USB 3.0 port power status */
167 #define	PORT_STATUS_SPMASK_SS	0x1c00
168 #define	PORT_STATUS_SPSHIFT_SS	10
169 
170 /* Port Change Field Bits - Table 11-16 */
171 #define	PORT_CHANGE_CSC		0x0001	/* connect status change */
172 #define	PORT_CHANGE_PESC	0x0002	/* port enable change */
173 #define	PORT_CHANGE_PSSC	0x0004	/* port suspend change */
174 #define	PORT_CHANGE_OCIC	0x0008	/* over current change */
175 #define	PORT_CHANGE_PRSC	0x0010	/* port reset change */
176 
177 /*
178  * USB 3.x additions. See USB 3.1/10.16.2.6.2.
179  */
180 #define	PORT_CHANGE_BHPR	0x0020	/* warm reset (BH) */
181 #define	PORT_CHANGE_PLSC	0x0040	/* port link state change */
182 #define	PORT_CHANGE_PCE		0x0080	/* port config error */
183 
184 /*
185  * These represent masks for all of the change bits. Note that the USB 2 version
186  * has less than the USB 3. The _2X version of the macro is maintained for
187  * things that don't know about more than USB 2 (ehci).
188  */
189 #define	PORT_CHANGE_MASK_2X	0x001f
190 #define	PORT_CHANGE_MASK	0x00ff
191 
192 /*
193  * Port status types and sizes USB 3.1/Table 10-12.
194  */
195 #define	PORT_GET_STATUS_PORT	0x00
196 #define	PORT_GET_STATUS_PD	0x01
197 #define	PORT_GET_STATUS_EXT	0x02
198 
199 #define	PORT_GET_STATUS_PORT_LEN	0x04
200 #define	PORT_GET_STATUS_PD_LEN		0x08
201 #define	PORT_GET_STATUS_EXT_LEN		0x08
202 
203 /* Hub status information USB 3.1/11.24.2.6 */
204 #define	HUB_GET_STATUS_LEN	0x04
205 #define	HUB_LOCAL_POWER_STATUS	0x0001	/* state of the power supply */
206 #define	HUB_OVER_CURRENT	0x0002  /* global hub OC condition */
207 
208 /* Hub change clear feature selectors - Table 11-15 */
209 #define	C_HUB_LOCAL_POWER_STATUS 0x0001 /* state of the power supply */
210 #define	C_HUB_OVER_CURRENT	 0x0002 /* global hub OC condition */
211 
212 /* hub class feature selectors - Table 11-12 */
213 #define	CFS_C_HUB_LOCAL_POWER		0
214 #define	CFS_C_HUB_OVER_CURRENT		1
215 #define	CFS_PORT_CONNECTION		0
216 #define	CFS_PORT_ENABLE			1
217 #define	CFS_PORT_SUSPEND		2
218 #define	CFS_PORT_OVER_CURRENT		3
219 #define	CFS_PORT_RESET			4
220 #define	CFS_PORT_LINK_STATE		5
221 #define	CFS_PORT_POWER			8
222 #define	CFS_PORT_LOW_SPEED		9
223 #define	CFS_C_PORT_CONNECTION		16
224 #define	CFS_C_PORT_ENABLE		17
225 #define	CFS_C_PORT_SUSPEND		18
226 #define	CFS_C_PORT_OVER_CURRENT 	19
227 #define	CFS_C_PORT_RESET		20
228 #define	CFS_PORT_TEST			21
229 #define	CFS_PORT_INDICATOR		22
230 
231 /*
232  * SuperSpeed specific HUB features. See USB 3.1 / 10.16.2.
233  */
234 #define	CFS_PORT_U1_TIMEOUT		23
235 #define	CFS_PORT_U2_TIMEOUT		24
236 #define	CFS_C_PORT_LINK_STATE		25
237 #define	CFS_C_PORT_CONFIG_ERROR		26
238 #define	CFS_PORT_REMOTE_WAKE_MASK	27
239 #define	CFS_BH_PORT_RESET		28
240 #define	CFS_C_BH_PORT_RESET		29
241 #define	CFS_FORCE_LINKPM_ACCEPT		30
242 
243 /*
244  * Values for CFS_PORT_REMOTE_WAKE_MASK. See USB 3.1 / Table 10-18.
245  */
246 #define	CFS_PRWM_CONN_ENABLE		0x01
247 #define	CFS_PRWM_DISCONN_ENABLE		0x02
248 #define	CFS_PRWM_OC_ENABLE		0x04
249 
250 #ifdef	__cplusplus
251 }
252 #endif
253 
254 #endif	/* _SYS_USB_HUB_H */
255