xref: /illumos-gate/usr/src/uts/common/sys/usb/hubd/hub.h (revision 993e3faf)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5fef1e07eSsl  * Common Development and Distribution License (the "License").
6fef1e07eSsl  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22d29f5a71Szhigang lu - Sun Microsystems - Beijing China  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
24*993e3fafSRobert Mustacchi  *
25*993e3fafSRobert Mustacchi  * Copyright 2016 Joyent, Inc.
267c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate #ifndef	_SYS_USB_HUB_H
297c478bd9Sstevel@tonic-gate #define	_SYS_USB_HUB_H
327c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
337c478bd9Sstevel@tonic-gate extern "C" {
347c478bd9Sstevel@tonic-gate #endif
36*993e3fafSRobert Mustacchi #define	HUBD_DEFAULT_DESC_INDEX		0
387c478bd9Sstevel@tonic-gate /*
397c478bd9Sstevel@tonic-gate  * Section allows up to 255 ports.
407c478bd9Sstevel@tonic-gate  * For simplicity, only a maximum of 31 ports is currently allowed
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate #define	MAX_PORTS 31
447c478bd9Sstevel@tonic-gate typedef struct usb_hub_descr {
457c478bd9Sstevel@tonic-gate 	uchar_t		bDescLength;	/* size of descriptor */
467c478bd9Sstevel@tonic-gate 	uchar_t		bDescriptorType; /* descriptor type */
477c478bd9Sstevel@tonic-gate 	uchar_t		bNbrPorts;	/* number of ports */
487c478bd9Sstevel@tonic-gate 	uint16_t	wHubCharacteristics; /* hub characteristics */
497c478bd9Sstevel@tonic-gate 	uchar_t		bPwrOn2PwrGood;	/* time in ms from the time */
507c478bd9Sstevel@tonic-gate 				/* power on sequence begins on a port */
517c478bd9Sstevel@tonic-gate 				/* until power is good on that port */
527c478bd9Sstevel@tonic-gate 	uchar_t		bHubContrCurrent; /* max current requirements */
537c478bd9Sstevel@tonic-gate 	uchar_t		DeviceRemovable;
547c478bd9Sstevel@tonic-gate 					/* removable device attached */
557c478bd9Sstevel@tonic-gate 	uchar_t		PortPwrCtrlMask;
567c478bd9Sstevel@tonic-gate 					/* power control mask */
577c478bd9Sstevel@tonic-gate } usb_hub_descr_t;
59*993e3fafSRobert Mustacchi /*
60*993e3fafSRobert Mustacchi  * In USB 3.x the format of the root hub description has changed. See USB 3.1 /
61*993e3fafSRobert Mustacchi  *
62*993e3fafSRobert Mustacchi  */
63*993e3fafSRobert Mustacchi #pragma pack(1)
64*993e3fafSRobert Mustacchi typedef struct usb_ss_hub_descr {
65*993e3fafSRobert Mustacchi 	uint8_t		bDescLength;		/* size of descriptor */
66*993e3fafSRobert Mustacchi 	uint8_t		bDescriptorType;	/* descriptor type (0x2A) */
67*993e3fafSRobert Mustacchi 	uint8_t		bNbrPorts;		/* number of ports */
68*993e3fafSRobert Mustacchi 	uint16_t	wHubCharacteristics;	/* hub characteristics */
69*993e3fafSRobert Mustacchi 	uint8_t		bPwrOn2PwrGood;	/* time in 2-ms from power on */
70*993e3fafSRobert Mustacchi 						/* until the port is ready */
71*993e3fafSRobert Mustacchi 	uint8_t		bHubContrCurrent;	/* max current requirements */
72*993e3fafSRobert Mustacchi 	uint8_t		bHubHdrDecLat;		/* hub packet decode latency */
73*993e3fafSRobert Mustacchi 	uint16_t	wHubDelay;		/* Forwarding delay in ns */
74*993e3fafSRobert Mustacchi 	uint16_t	DeviceRemovable[32];	/* indicates per-port whether */
75*993e3fafSRobert Mustacchi 					/* the device is removable with one */
76*993e3fafSRobert Mustacchi 					/* bit per port, up to 255 ports */
77*993e3fafSRobert Mustacchi } usb_ss_hub_descr_t;
78*993e3fafSRobert Mustacchi #pragma pack()
79*993e3fafSRobert Mustacchi 
807c478bd9Sstevel@tonic-gate #define	ROOT_HUB_DESCRIPTOR_LENGTH	9
817c478bd9Sstevel@tonic-gate #define	ROOT_HUB_DESCRIPTOR_TYPE	0x29
82*993e3fafSRobert Mustacchi #define	ROOT_HUB_SS_DESCRIPTOR_TYPE	0x2A
837c478bd9Sstevel@tonic-gate #define	ROOT_HUB_ADDR			0x01	/* address of root hub */
857c478bd9Sstevel@tonic-gate /* Values for wHubCharacteristics */
867c478bd9Sstevel@tonic-gate #define	HUB_CHARS_POWER_SWITCHING_MODE	0x03
877c478bd9Sstevel@tonic-gate #define	HUB_CHARS_GANGED_POWER		0x00
887c478bd9Sstevel@tonic-gate #define	HUB_CHARS_INDIVIDUAL_PORT_POWER	0x01
897c478bd9Sstevel@tonic-gate #define	HUB_CHARS_NO_POWER_SWITCHING	0x02
907c478bd9Sstevel@tonic-gate #define	HUB_CHARS_COMPOUND_DEV		0x04
917c478bd9Sstevel@tonic-gate #define	HUB_CHARS_GLOBAL_OVER_CURRENT	0x00
927c478bd9Sstevel@tonic-gate #define	HUB_CHARS_INDIV_OVER_CURRENT	0x08
937c478bd9Sstevel@tonic-gate #define	HUB_CHARS_NO_OVER_CURRENT	0x10
947c478bd9Sstevel@tonic-gate #define	HUB_CHARS_TT_THINK_TIME		0x60
957c478bd9Sstevel@tonic-gate #define	HUB_CHARS_TT_16FS_TIME		0x20
967c478bd9Sstevel@tonic-gate #define	HUB_CHARS_TT_24FS_TIME		0x40
977c478bd9Sstevel@tonic-gate #define	HUB_CHARS_TT_32FS_TIME		0x60
987c478bd9Sstevel@tonic-gate #define	HUB_CHARS_PORT_INDICATOR	0x80
100*993e3fafSRobert Mustacchi #define	HUB_CHARS_TT_SHIFT		5
101*993e3fafSRobert Mustacchi 
1027c478bd9Sstevel@tonic-gate /* Default Power On to Power Good time */
1037c478bd9Sstevel@tonic-gate #define	HUB_DEFAULT_POPG	10
1057c478bd9Sstevel@tonic-gate /* Hub Status */
1067c478bd9Sstevel@tonic-gate #define	HUB_CHANGE_STATUS	0x01
1087c478bd9Sstevel@tonic-gate /* Class Specific bmRequestType values Table 11-10 */
11035f36846Ssl 					|USB_DEV_REQ_TYPE_CLASS \
11135f36846Ssl 					|USB_DEV_REQ_RCPT_OTHER)
11435f36846Ssl 					|USB_DEV_REQ_TYPE_CLASS \
11535f36846Ssl 					|USB_DEV_REQ_RCPT_OTHER)
11735f36846Ssl #define	HUB_CLASS_REQ_TYPE		(USB_DEV_REQ_DEV_TO_HOST \
11835f36846Ssl 					|USB_DEV_REQ_TYPE_CLASS)
122*993e3fafSRobert Mustacchi #define	HUB_SET_HUB_DEPTH_TYPE		(USB_DEV_REQ_HOST_TO_DEV \
123*993e3fafSRobert Mustacchi 					|USB_DEV_REQ_TYPE_CLASS \
124*993e3fafSRobert Mustacchi 					|USB_DEV_REQ_RCPT_DEV)
125*993e3fafSRobert Mustacchi 
12635f36846Ssl /* bmRequestType for getting device status */
12835f36846Ssl 					|USB_DEV_REQ_TYPE_STANDARD \
12935f36846Ssl 					|USB_DEV_REQ_RCPT_DEV)
131*993e3fafSRobert Mustacchi /*
132*993e3fafSRobert Mustacchi  * Class specific bRequest values that don't line up with standard requests. See
133*993e3fafSRobert Mustacchi  * USB 3.1 / Table 10-8.
134*993e3fafSRobert Mustacchi  */
135*993e3fafSRobert Mustacchi #define	HUB_REQ_SET_HUB_DEPTH		12
136*993e3fafSRobert Mustacchi 
137*993e3fafSRobert Mustacchi /*
138*993e3fafSRobert Mustacchi  * Port Status Field Bits. While there is overlap between the USB 2.0 and USB
139*993e3fafSRobert Mustacchi  * 3.0 bits, they aren't entirely the same and some bits have different meanings
140*993e3fafSRobert Mustacchi  * across different versions of USB. Common bits are shared first and then this
141*993e3fafSRobert Mustacchi  * is broken down into device specific bits. The USB 3 version is in USB
142*993e3fafSRobert Mustacchi  * 3.1/ The USB 2 version is in USB 2/
143*993e3fafSRobert Mustacchi  */
1447c478bd9Sstevel@tonic-gate #define	PORT_STATUS_CCS		0x0001	/* port connection status */
1457c478bd9Sstevel@tonic-gate #define	PORT_STATUS_PES		0x0002	/* port enable status */
1467c478bd9Sstevel@tonic-gate #define	PORT_STATUS_PSS		0x0004	/* port suspend status */
1477c478bd9Sstevel@tonic-gate #define	PORT_STATUS_POCI	0x0008	/* port over current indicator */
1487c478bd9Sstevel@tonic-gate #define	PORT_STATUS_PRS		0x0010	/* port reset status */
1497c478bd9Sstevel@tonic-gate #define	PORT_STATUS_PPS		0x0100	/* port power status */
150*993e3fafSRobert Mustacchi 
151*993e3fafSRobert Mustacchi /* USB 2.0 specific bits */
1527c478bd9Sstevel@tonic-gate #define	PORT_STATUS_LSDA	0x0200	/* low speed device */
1537c478bd9Sstevel@tonic-gate #define	PORT_STATUS_HSDA	0x0400	/* high speed device */
1547c478bd9Sstevel@tonic-gate #define	PORT_STATUS_PIC		0x1000	/* port indicator control */
156*993e3fafSRobert Mustacchi /*
157*993e3fafSRobert Mustacchi  * The USB 2.0 and USB 3.0 port status bits are almost identical; however, the
158*993e3fafSRobert Mustacchi  * location of the port's power indicator is different for hubs. To deal with
159*993e3fafSRobert Mustacchi  * this, we have logic, hubd_status_unifornm, that transforms the USB 3 status
160*993e3fafSRobert Mustacchi  * to USB 2, hence why we only have one version of these macros below.
161*993e3fafSRobert Mustacchi  */
1627c478bd9Sstevel@tonic-gate #define	PORT_STATUS_MASK	0x171f
1637c478bd9Sstevel@tonic-gate #define	PORT_STATUS_OK		0x103	/* connected, enabled, power */
165*993e3fafSRobert Mustacchi /* USB 3 Specific bits */
166*993e3fafSRobert Mustacchi #define	PORT_STATUS_PPS_SS	0x0200	/* USB 3.0 port power status */
167*993e3fafSRobert Mustacchi #define	PORT_STATUS_SPMASK_SS	0x1c00
168*993e3fafSRobert Mustacchi #define	PORT_STATUS_SPSHIFT_SS	10
169*993e3fafSRobert Mustacchi 
1707c478bd9Sstevel@tonic-gate /* Port Change Field Bits - Table 11-16 */
1717c478bd9Sstevel@tonic-gate #define	PORT_CHANGE_CSC		0x0001	/* connect status change */
1727c478bd9Sstevel@tonic-gate #define	PORT_CHANGE_PESC	0x0002	/* port enable change */
1737c478bd9Sstevel@tonic-gate #define	PORT_CHANGE_PSSC	0x0004	/* port suspend change */
1747c478bd9Sstevel@tonic-gate #define	PORT_CHANGE_OCIC	0x0008	/* over current change */
1757c478bd9Sstevel@tonic-gate #define	PORT_CHANGE_PRSC	0x0010	/* port reset change */
177*993e3fafSRobert Mustacchi /*
178*993e3fafSRobert Mustacchi  * USB 3.x additions. See USB 3.1/
179*993e3fafSRobert Mustacchi  */
180*993e3fafSRobert Mustacchi #define	PORT_CHANGE_BHPR	0x0020	/* warm reset (BH) */
181*993e3fafSRobert Mustacchi #define	PORT_CHANGE_PLSC	0x0040	/* port link state change */
182*993e3fafSRobert Mustacchi #define	PORT_CHANGE_PCE		0x0080	/* port config error */
183*993e3fafSRobert Mustacchi 
184*993e3fafSRobert Mustacchi /*
185*993e3fafSRobert Mustacchi  * These represent masks for all of the change bits. Note that the USB 2 version
186*993e3fafSRobert Mustacchi  * has less than the USB 3. The _2X version of the macro is maintained for
187*993e3fafSRobert Mustacchi  * things that don't know about more than USB 2 (ehci).
188*993e3fafSRobert Mustacchi  */
189*993e3fafSRobert Mustacchi #define	PORT_CHANGE_MASK_2X	0x001f
190*993e3fafSRobert Mustacchi #define	PORT_CHANGE_MASK	0x00ff
191*993e3fafSRobert Mustacchi 
192*993e3fafSRobert Mustacchi /*
193*993e3fafSRobert Mustacchi  * Port status types and sizes USB 3.1/Table 10-12.
194*993e3fafSRobert Mustacchi  */
195*993e3fafSRobert Mustacchi #define	PORT_GET_STATUS_PORT	0x00
196*993e3fafSRobert Mustacchi #define	PORT_GET_STATUS_PD	0x01
197*993e3fafSRobert Mustacchi #define	PORT_GET_STATUS_EXT	0x02
198*993e3fafSRobert Mustacchi 
199*993e3fafSRobert Mustacchi #define	PORT_GET_STATUS_PORT_LEN	0x04
200*993e3fafSRobert Mustacchi #define	PORT_GET_STATUS_PD_LEN		0x08
201*993e3fafSRobert Mustacchi #define	PORT_GET_STATUS_EXT_LEN		0x08
203*993e3fafSRobert Mustacchi /* Hub status information USB 3.1/ */
204*993e3fafSRobert Mustacchi #define	HUB_GET_STATUS_LEN	0x04
2057c478bd9Sstevel@tonic-gate #define	HUB_LOCAL_POWER_STATUS	0x0001	/* state of the power supply */
2067c478bd9Sstevel@tonic-gate #define	HUB_OVER_CURRENT	0x0002  /* global hub OC condition */
2087c478bd9Sstevel@tonic-gate /* Hub change clear feature selectors - Table 11-15 */
2097c478bd9Sstevel@tonic-gate #define	C_HUB_LOCAL_POWER_STATUS 0x0001 /* state of the power supply */
2107c478bd9Sstevel@tonic-gate #define	C_HUB_OVER_CURRENT	 0x0002 /* global hub OC condition */
2127c478bd9Sstevel@tonic-gate /* hub class feature selectors - Table 11-12 */
2137c478bd9Sstevel@tonic-gate #define	CFS_C_HUB_LOCAL_POWER		0
2147c478bd9Sstevel@tonic-gate #define	CFS_C_HUB_OVER_CURRENT		1
2157c478bd9Sstevel@tonic-gate #define	CFS_PORT_CONNECTION		0
2167c478bd9Sstevel@tonic-gate #define	CFS_PORT_ENABLE			1
2177c478bd9Sstevel@tonic-gate #define	CFS_PORT_SUSPEND		2
2187c478bd9Sstevel@tonic-gate #define	CFS_PORT_OVER_CURRENT		3
2197c478bd9Sstevel@tonic-gate #define	CFS_PORT_RESET			4
220*993e3fafSRobert Mustacchi #define	CFS_PORT_LINK_STATE		5
2217c478bd9Sstevel@tonic-gate #define	CFS_PORT_POWER			8
2227c478bd9Sstevel@tonic-gate #define	CFS_PORT_LOW_SPEED		9
2237c478bd9Sstevel@tonic-gate #define	CFS_C_PORT_CONNECTION		16
2247c478bd9Sstevel@tonic-gate #define	CFS_C_PORT_ENABLE		17
2257c478bd9Sstevel@tonic-gate #define	CFS_C_PORT_SUSPEND		18
2267c478bd9Sstevel@tonic-gate #define	CFS_C_PORT_OVER_CURRENT 	19
2277c478bd9Sstevel@tonic-gate #define	CFS_C_PORT_RESET		20
228*993e3fafSRobert Mustacchi #define	CFS_PORT_TEST			21
229*993e3fafSRobert Mustacchi #define	CFS_PORT_INDICATOR		22
230*993e3fafSRobert Mustacchi 
231*993e3fafSRobert Mustacchi /*
232*993e3fafSRobert Mustacchi  * SuperSpeed specific HUB features. See USB 3.1 / 10.16.2.
233*993e3fafSRobert Mustacchi  */
234*993e3fafSRobert Mustacchi #define	CFS_PORT_U1_TIMEOUT		23
235*993e3fafSRobert Mustacchi #define	CFS_PORT_U2_TIMEOUT		24
236*993e3fafSRobert Mustacchi #define	CFS_C_PORT_LINK_STATE		25
237*993e3fafSRobert Mustacchi #define	CFS_C_PORT_CONFIG_ERROR		26
238*993e3fafSRobert Mustacchi #define	CFS_PORT_REMOTE_WAKE_MASK	27
239*993e3fafSRobert Mustacchi #define	CFS_BH_PORT_RESET		28
240*993e3fafSRobert Mustacchi #define	CFS_C_BH_PORT_RESET		29
241*993e3fafSRobert Mustacchi #define	CFS_FORCE_LINKPM_ACCEPT		30
242*993e3fafSRobert Mustacchi 
243*993e3fafSRobert Mustacchi /*
244*993e3fafSRobert Mustacchi  * Values for CFS_PORT_REMOTE_WAKE_MASK. See USB 3.1 / Table 10-18.
245*993e3fafSRobert Mustacchi  */
246*993e3fafSRobert Mustacchi #define	CFS_PRWM_CONN_ENABLE		0x01
247*993e3fafSRobert Mustacchi #define	CFS_PRWM_DISCONN_ENABLE		0x02
248*993e3fafSRobert Mustacchi #define	CFS_PRWM_OC_ENABLE		0x04
2507c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2517c478bd9Sstevel@tonic-gate }
2527c478bd9Sstevel@tonic-gate #endif
2547c478bd9Sstevel@tonic-gate #endif	/* _SYS_USB_HUB_H */