xref: /freebsd/sys/dev/usb/usb.h (revision 4076dd2309e07c75bda7ac9931ea3ef49ab5b459)
102ac6454SAndrew Thompson /* $FreeBSD$ */
202ac6454SAndrew Thompson /*-
302ac6454SAndrew Thompson  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
402ac6454SAndrew Thompson  * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
502ac6454SAndrew Thompson  * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
602ac6454SAndrew Thompson  *
702ac6454SAndrew Thompson  * Redistribution and use in source and binary forms, with or without
802ac6454SAndrew Thompson  * modification, are permitted provided that the following conditions
902ac6454SAndrew Thompson  * are met:
1002ac6454SAndrew Thompson  * 1. Redistributions of source code must retain the above copyright
1102ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer.
1202ac6454SAndrew Thompson  * 2. Redistributions in binary form must reproduce the above copyright
1302ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer in the
1402ac6454SAndrew Thompson  *    documentation and/or other materials provided with the distribution.
1502ac6454SAndrew Thompson  *
1602ac6454SAndrew Thompson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1702ac6454SAndrew Thompson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1802ac6454SAndrew Thompson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1902ac6454SAndrew Thompson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2002ac6454SAndrew Thompson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2102ac6454SAndrew Thompson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2202ac6454SAndrew Thompson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2302ac6454SAndrew Thompson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2402ac6454SAndrew Thompson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2502ac6454SAndrew Thompson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2602ac6454SAndrew Thompson  * SUCH DAMAGE.
2702ac6454SAndrew Thompson  */
2802ac6454SAndrew Thompson 
2902ac6454SAndrew Thompson /*
3002ac6454SAndrew Thompson  * This file contains standard definitions for the following USB
3102ac6454SAndrew Thompson  * protocol versions:
3202ac6454SAndrew Thompson  *
3302ac6454SAndrew Thompson  * USB v1.0
3402ac6454SAndrew Thompson  * USB v1.1
3502ac6454SAndrew Thompson  * USB v2.0
3602ac6454SAndrew Thompson  * USB v3.0
3702ac6454SAndrew Thompson  */
3802ac6454SAndrew Thompson 
3975973647SAndrew Thompson #ifndef _USB_STANDARD_H_
4075973647SAndrew Thompson #define	_USB_STANDARD_H_
4102ac6454SAndrew Thompson 
42ed6d949aSAndrew Thompson #if defined(_KERNEL)
43ed6d949aSAndrew Thompson #include "opt_usb.h"
44ed6d949aSAndrew Thompson 
45ed6d949aSAndrew Thompson /* Declare parent SYSCTL USB node. */
46ed6d949aSAndrew Thompson #ifdef SYSCTL_DECL
47ed6d949aSAndrew Thompson SYSCTL_DECL(_hw_usb);
48ed6d949aSAndrew Thompson #endif
49ed6d949aSAndrew Thompson 
50ed6d949aSAndrew Thompson #include <sys/malloc.h>
51ed6d949aSAndrew Thompson 
52ed6d949aSAndrew Thompson MALLOC_DECLARE(M_USB);
53ed6d949aSAndrew Thompson MALLOC_DECLARE(M_USBDEV);
54ed6d949aSAndrew Thompson MALLOC_DECLARE(M_USBHC);
55ed6d949aSAndrew Thompson #endif /* _KERNEL */
56ed6d949aSAndrew Thompson 
5702ac6454SAndrew Thompson #include <dev/usb/usb_endian.h>
58ed6d949aSAndrew Thompson #include <dev/usb/usb_freebsd.h>
59ed6d949aSAndrew Thompson 
60ed6d949aSAndrew Thompson #define	USB_STACK_VERSION 2000		/* 2.0 */
61ed6d949aSAndrew Thompson 
62ed6d949aSAndrew Thompson /* Definition of some hardcoded USB constants. */
63ed6d949aSAndrew Thompson 
64ed6d949aSAndrew Thompson #define	USB_MAX_IPACKET		8	/* initial USB packet size */
65ed6d949aSAndrew Thompson #define	USB_EP_MAX (2*16)		/* hardcoded */
66ed6d949aSAndrew Thompson #define	USB_ROOT_HUB_ADDR 1		/* index */
67ed6d949aSAndrew Thompson #define	USB_MIN_DEVICES 2		/* unused + root HUB */
68ed6d949aSAndrew Thompson #define	USB_UNCONFIG_INDEX 0xFF		/* internal use only */
69ed6d949aSAndrew Thompson #define	USB_IFACE_INDEX_ANY 0xFF	/* internal use only */
70ed6d949aSAndrew Thompson #define	USB_START_ADDR 0		/* default USB device BUS address
71ed6d949aSAndrew Thompson 					 * after USB bus reset */
72ed6d949aSAndrew Thompson #define	USB_CONTROL_ENDPOINT 0		/* default control endpoint */
73ed6d949aSAndrew Thompson 
74ed6d949aSAndrew Thompson #define	USB_FRAMES_PER_SECOND_FS 1000	/* full speed */
75ed6d949aSAndrew Thompson #define	USB_FRAMES_PER_SECOND_HS 8000	/* high speed */
76ed6d949aSAndrew Thompson 
77ed6d949aSAndrew Thompson #define	USB_FS_BYTES_PER_HS_UFRAME 188	/* bytes */
78ed6d949aSAndrew Thompson #define	USB_HS_MICRO_FRAMES_MAX 8	/* units */
79ed6d949aSAndrew Thompson 
80ed6d949aSAndrew Thompson #define	USB_ISOC_TIME_MAX 128		/* ms */
8102ac6454SAndrew Thompson 
8202ac6454SAndrew Thompson /*
8302ac6454SAndrew Thompson  * Minimum time a device needs to be powered down to go through a
8402ac6454SAndrew Thompson  * power cycle. These values are not in the USB specification.
8502ac6454SAndrew Thompson  */
8602ac6454SAndrew Thompson #define	USB_POWER_DOWN_TIME	200	/* ms */
8702ac6454SAndrew Thompson #define	USB_PORT_POWER_DOWN_TIME	100	/* ms */
8802ac6454SAndrew Thompson 
8902ac6454SAndrew Thompson /* Definition of software USB power modes */
9002ac6454SAndrew Thompson #define	USB_POWER_MODE_OFF 0		/* turn off device */
9102ac6454SAndrew Thompson #define	USB_POWER_MODE_ON 1		/* always on */
9202ac6454SAndrew Thompson #define	USB_POWER_MODE_SAVE 2		/* automatic suspend and resume */
9302ac6454SAndrew Thompson #define	USB_POWER_MODE_SUSPEND 3	/* force suspend */
9402ac6454SAndrew Thompson #define	USB_POWER_MODE_RESUME 4		/* force resume */
9502ac6454SAndrew Thompson 
9602ac6454SAndrew Thompson #if 0
9702ac6454SAndrew Thompson /* These are the values from the USB specification. */
9802ac6454SAndrew Thompson #define	USB_PORT_RESET_DELAY	10	/* ms */
9902ac6454SAndrew Thompson #define	USB_PORT_ROOT_RESET_DELAY 50	/* ms */
10002ac6454SAndrew Thompson #define	USB_PORT_RESET_RECOVERY	10	/* ms */
10102ac6454SAndrew Thompson #define	USB_PORT_POWERUP_DELAY	100	/* ms */
10202ac6454SAndrew Thompson #define	USB_PORT_RESUME_DELAY	20	/* ms */
10302ac6454SAndrew Thompson #define	USB_SET_ADDRESS_SETTLE	2	/* ms */
10402ac6454SAndrew Thompson #define	USB_RESUME_DELAY	(20*5)	/* ms */
10502ac6454SAndrew Thompson #define	USB_RESUME_WAIT		10	/* ms */
10602ac6454SAndrew Thompson #define	USB_RESUME_RECOVERY	10	/* ms */
10702ac6454SAndrew Thompson #define	USB_EXTRA_POWER_UP_TIME	0	/* ms */
10802ac6454SAndrew Thompson #else
10902ac6454SAndrew Thompson /* Allow for marginal and non-conforming devices. */
11002ac6454SAndrew Thompson #define	USB_PORT_RESET_DELAY	50	/* ms */
11102ac6454SAndrew Thompson #define	USB_PORT_ROOT_RESET_DELAY 250	/* ms */
11202ac6454SAndrew Thompson #define	USB_PORT_RESET_RECOVERY	250	/* ms */
11302ac6454SAndrew Thompson #define	USB_PORT_POWERUP_DELAY	300	/* ms */
11402ac6454SAndrew Thompson #define	USB_PORT_RESUME_DELAY	(20*2)	/* ms */
11502ac6454SAndrew Thompson #define	USB_SET_ADDRESS_SETTLE	10	/* ms */
11602ac6454SAndrew Thompson #define	USB_RESUME_DELAY	(50*5)	/* ms */
11702ac6454SAndrew Thompson #define	USB_RESUME_WAIT		50	/* ms */
11802ac6454SAndrew Thompson #define	USB_RESUME_RECOVERY	50	/* ms */
11902ac6454SAndrew Thompson #define	USB_EXTRA_POWER_UP_TIME	20	/* ms */
12002ac6454SAndrew Thompson #endif
12102ac6454SAndrew Thompson 
12202ac6454SAndrew Thompson #define	USB_MIN_POWER		100	/* mA */
12302ac6454SAndrew Thompson #define	USB_MAX_POWER		500	/* mA */
12402ac6454SAndrew Thompson 
12502ac6454SAndrew Thompson #define	USB_BUS_RESET_DELAY	100	/* ms */
12602ac6454SAndrew Thompson 
12702ac6454SAndrew Thompson /*
12802ac6454SAndrew Thompson  * USB record layout in memory:
12902ac6454SAndrew Thompson  *
13002ac6454SAndrew Thompson  * - USB config 0
13102ac6454SAndrew Thompson  *   - USB interfaces
13202ac6454SAndrew Thompson  *     - USB alternative interfaces
133ae60fdfbSAndrew Thompson  *       - USB endpoints
13402ac6454SAndrew Thompson  *
13502ac6454SAndrew Thompson  * - USB config 1
13602ac6454SAndrew Thompson  *   - USB interfaces
13702ac6454SAndrew Thompson  *     - USB alternative interfaces
138ae60fdfbSAndrew Thompson  *       - USB endpoints
13902ac6454SAndrew Thompson  */
14002ac6454SAndrew Thompson 
14102ac6454SAndrew Thompson /* Declaration of USB records */
14202ac6454SAndrew Thompson 
143760bc48eSAndrew Thompson struct usb_device_request {
14402ac6454SAndrew Thompson 	uByte	bmRequestType;
14502ac6454SAndrew Thompson 	uByte	bRequest;
14602ac6454SAndrew Thompson 	uWord	wValue;
14702ac6454SAndrew Thompson 	uWord	wIndex;
14802ac6454SAndrew Thompson 	uWord	wLength;
14902ac6454SAndrew Thompson } __packed;
150760bc48eSAndrew Thompson typedef struct usb_device_request usb_device_request_t;
15102ac6454SAndrew Thompson 
15202ac6454SAndrew Thompson #define	UT_WRITE		0x00
15302ac6454SAndrew Thompson #define	UT_READ			0x80
15402ac6454SAndrew Thompson #define	UT_STANDARD		0x00
15502ac6454SAndrew Thompson #define	UT_CLASS		0x20
15602ac6454SAndrew Thompson #define	UT_VENDOR		0x40
15702ac6454SAndrew Thompson #define	UT_DEVICE		0x00
15802ac6454SAndrew Thompson #define	UT_INTERFACE		0x01
15902ac6454SAndrew Thompson #define	UT_ENDPOINT		0x02
16002ac6454SAndrew Thompson #define	UT_OTHER		0x03
16102ac6454SAndrew Thompson 
16202ac6454SAndrew Thompson #define	UT_READ_DEVICE		(UT_READ  | UT_STANDARD | UT_DEVICE)
16302ac6454SAndrew Thompson #define	UT_READ_INTERFACE	(UT_READ  | UT_STANDARD | UT_INTERFACE)
16402ac6454SAndrew Thompson #define	UT_READ_ENDPOINT	(UT_READ  | UT_STANDARD | UT_ENDPOINT)
16502ac6454SAndrew Thompson #define	UT_WRITE_DEVICE		(UT_WRITE | UT_STANDARD | UT_DEVICE)
16602ac6454SAndrew Thompson #define	UT_WRITE_INTERFACE	(UT_WRITE | UT_STANDARD | UT_INTERFACE)
16702ac6454SAndrew Thompson #define	UT_WRITE_ENDPOINT	(UT_WRITE | UT_STANDARD | UT_ENDPOINT)
16802ac6454SAndrew Thompson #define	UT_READ_CLASS_DEVICE	(UT_READ  | UT_CLASS | UT_DEVICE)
16902ac6454SAndrew Thompson #define	UT_READ_CLASS_INTERFACE	(UT_READ  | UT_CLASS | UT_INTERFACE)
17002ac6454SAndrew Thompson #define	UT_READ_CLASS_OTHER	(UT_READ  | UT_CLASS | UT_OTHER)
17102ac6454SAndrew Thompson #define	UT_READ_CLASS_ENDPOINT	(UT_READ  | UT_CLASS | UT_ENDPOINT)
17202ac6454SAndrew Thompson #define	UT_WRITE_CLASS_DEVICE	(UT_WRITE | UT_CLASS | UT_DEVICE)
17302ac6454SAndrew Thompson #define	UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
17402ac6454SAndrew Thompson #define	UT_WRITE_CLASS_OTHER	(UT_WRITE | UT_CLASS | UT_OTHER)
17502ac6454SAndrew Thompson #define	UT_WRITE_CLASS_ENDPOINT	(UT_WRITE | UT_CLASS | UT_ENDPOINT)
17602ac6454SAndrew Thompson #define	UT_READ_VENDOR_DEVICE	(UT_READ  | UT_VENDOR | UT_DEVICE)
17702ac6454SAndrew Thompson #define	UT_READ_VENDOR_INTERFACE (UT_READ  | UT_VENDOR | UT_INTERFACE)
17802ac6454SAndrew Thompson #define	UT_READ_VENDOR_OTHER	(UT_READ  | UT_VENDOR | UT_OTHER)
17902ac6454SAndrew Thompson #define	UT_READ_VENDOR_ENDPOINT	(UT_READ  | UT_VENDOR | UT_ENDPOINT)
18002ac6454SAndrew Thompson #define	UT_WRITE_VENDOR_DEVICE	(UT_WRITE | UT_VENDOR | UT_DEVICE)
18102ac6454SAndrew Thompson #define	UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
18202ac6454SAndrew Thompson #define	UT_WRITE_VENDOR_OTHER	(UT_WRITE | UT_VENDOR | UT_OTHER)
18302ac6454SAndrew Thompson #define	UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
18402ac6454SAndrew Thompson 
18502ac6454SAndrew Thompson /* Requests */
18602ac6454SAndrew Thompson #define	UR_GET_STATUS		0x00
18702ac6454SAndrew Thompson #define	UR_CLEAR_FEATURE	0x01
18802ac6454SAndrew Thompson #define	UR_SET_FEATURE		0x03
18902ac6454SAndrew Thompson #define	UR_SET_ADDRESS		0x05
19002ac6454SAndrew Thompson #define	UR_GET_DESCRIPTOR	0x06
19102ac6454SAndrew Thompson #define	UDESC_DEVICE		0x01
19202ac6454SAndrew Thompson #define	UDESC_CONFIG		0x02
19302ac6454SAndrew Thompson #define	UDESC_STRING		0x03
19402ac6454SAndrew Thompson #define	USB_LANGUAGE_TABLE	0x00	/* language ID string index */
19502ac6454SAndrew Thompson #define	UDESC_INTERFACE		0x04
19602ac6454SAndrew Thompson #define	UDESC_ENDPOINT		0x05
19702ac6454SAndrew Thompson #define	UDESC_DEVICE_QUALIFIER	0x06
19802ac6454SAndrew Thompson #define	UDESC_OTHER_SPEED_CONFIGURATION 0x07
19902ac6454SAndrew Thompson #define	UDESC_INTERFACE_POWER	0x08
20002ac6454SAndrew Thompson #define	UDESC_OTG		0x09
20102ac6454SAndrew Thompson #define	UDESC_DEBUG		0x0A
20202ac6454SAndrew Thompson #define	UDESC_IFACE_ASSOC	0x0B	/* interface association */
20302ac6454SAndrew Thompson #define	UDESC_BOS		0x0F	/* binary object store */
20402ac6454SAndrew Thompson #define	UDESC_DEVICE_CAPABILITY	0x10
20502ac6454SAndrew Thompson #define	UDESC_CS_DEVICE		0x21	/* class specific */
20602ac6454SAndrew Thompson #define	UDESC_CS_CONFIG		0x22
20702ac6454SAndrew Thompson #define	UDESC_CS_STRING		0x23
20802ac6454SAndrew Thompson #define	UDESC_CS_INTERFACE	0x24
20902ac6454SAndrew Thompson #define	UDESC_CS_ENDPOINT	0x25
21002ac6454SAndrew Thompson #define	UDESC_HUB		0x29
21102ac6454SAndrew Thompson #define	UDESC_ENDPOINT_SS_COMP	0x30	/* super speed */
21202ac6454SAndrew Thompson #define	UR_SET_DESCRIPTOR	0x07
21302ac6454SAndrew Thompson #define	UR_GET_CONFIG		0x08
21402ac6454SAndrew Thompson #define	UR_SET_CONFIG		0x09
21502ac6454SAndrew Thompson #define	UR_GET_INTERFACE	0x0a
21602ac6454SAndrew Thompson #define	UR_SET_INTERFACE	0x0b
21702ac6454SAndrew Thompson #define	UR_SYNCH_FRAME		0x0c
21802ac6454SAndrew Thompson #define	UR_SET_SEL		0x30
21902ac6454SAndrew Thompson #define	UR_ISOCH_DELAY		0x31
22002ac6454SAndrew Thompson 
22102ac6454SAndrew Thompson /* HUB specific request */
22202ac6454SAndrew Thompson #define	UR_GET_BUS_STATE	0x02
22302ac6454SAndrew Thompson #define	UR_CLEAR_TT_BUFFER	0x08
22402ac6454SAndrew Thompson #define	UR_RESET_TT		0x09
22502ac6454SAndrew Thompson #define	UR_GET_TT_STATE		0x0a
22602ac6454SAndrew Thompson #define	UR_STOP_TT		0x0b
22702ac6454SAndrew Thompson #define	UR_SET_HUB_DEPTH	0x0c
22802ac6454SAndrew Thompson #define	UR_GET_PORT_ERR_COUNT	0x0d
22902ac6454SAndrew Thompson 
23002ac6454SAndrew Thompson /* Feature numbers */
23102ac6454SAndrew Thompson #define	UF_ENDPOINT_HALT	0
23202ac6454SAndrew Thompson #define	UF_DEVICE_REMOTE_WAKEUP	1
23302ac6454SAndrew Thompson #define	UF_TEST_MODE		2
23402ac6454SAndrew Thompson #define	UF_U1_ENABLE		0x30
23502ac6454SAndrew Thompson #define	UF_U2_ENABLE		0x31
23602ac6454SAndrew Thompson #define	UF_LTM_ENABLE		0x32
23702ac6454SAndrew Thompson 
23802ac6454SAndrew Thompson /* HUB specific features */
23902ac6454SAndrew Thompson #define	UHF_C_HUB_LOCAL_POWER	0
24002ac6454SAndrew Thompson #define	UHF_C_HUB_OVER_CURRENT	1
24102ac6454SAndrew Thompson #define	UHF_PORT_CONNECTION	0
24202ac6454SAndrew Thompson #define	UHF_PORT_ENABLE		1
24302ac6454SAndrew Thompson #define	UHF_PORT_SUSPEND	2
24402ac6454SAndrew Thompson #define	UHF_PORT_OVER_CURRENT	3
24502ac6454SAndrew Thompson #define	UHF_PORT_RESET		4
24602ac6454SAndrew Thompson #define	UHF_PORT_LINK_STATE	5
24702ac6454SAndrew Thompson #define	UHF_PORT_POWER		8
24802ac6454SAndrew Thompson #define	UHF_PORT_LOW_SPEED	9
24902ac6454SAndrew Thompson #define	UHF_C_PORT_CONNECTION	16
25002ac6454SAndrew Thompson #define	UHF_C_PORT_ENABLE	17
25102ac6454SAndrew Thompson #define	UHF_C_PORT_SUSPEND	18
25202ac6454SAndrew Thompson #define	UHF_C_PORT_OVER_CURRENT	19
25302ac6454SAndrew Thompson #define	UHF_C_PORT_RESET	20
25402ac6454SAndrew Thompson #define	UHF_PORT_TEST		21
25502ac6454SAndrew Thompson #define	UHF_PORT_INDICATOR	22
25602ac6454SAndrew Thompson 
25702ac6454SAndrew Thompson /* SuperSpeed HUB specific features */
25802ac6454SAndrew Thompson #define	UHF_PORT_U1_TIMEOUT	23
25902ac6454SAndrew Thompson #define	UHF_PORT_U2_TIMEOUT	24
26002ac6454SAndrew Thompson #define	UHF_C_PORT_LINK_STATE	25
26102ac6454SAndrew Thompson #define	UHF_C_PORT_CONFIG_ERROR	26
26202ac6454SAndrew Thompson #define	UHF_PORT_REMOTE_WAKE_MASK	27
26302ac6454SAndrew Thompson #define	UHF_BH_PORT_RESET	28
26402ac6454SAndrew Thompson #define	UHF_C_BH_PORT_RESET	29
26502ac6454SAndrew Thompson #define	UHF_FORCE_LINKPM_ACCEPT	30
26602ac6454SAndrew Thompson 
267760bc48eSAndrew Thompson struct usb_descriptor {
26802ac6454SAndrew Thompson 	uByte	bLength;
26902ac6454SAndrew Thompson 	uByte	bDescriptorType;
27002ac6454SAndrew Thompson 	uByte	bDescriptorSubtype;
27102ac6454SAndrew Thompson } __packed;
272760bc48eSAndrew Thompson typedef struct usb_descriptor usb_descriptor_t;
27302ac6454SAndrew Thompson 
274760bc48eSAndrew Thompson struct usb_device_descriptor {
27502ac6454SAndrew Thompson 	uByte	bLength;
27602ac6454SAndrew Thompson 	uByte	bDescriptorType;
27702ac6454SAndrew Thompson 	uWord	bcdUSB;
27802ac6454SAndrew Thompson #define	UD_USB_2_0		0x0200
27902ac6454SAndrew Thompson #define	UD_USB_3_0		0x0300
28002ac6454SAndrew Thompson #define	UD_IS_USB2(d) ((d)->bcdUSB[1] == 0x02)
28102ac6454SAndrew Thompson #define	UD_IS_USB3(d) ((d)->bcdUSB[1] == 0x03)
28202ac6454SAndrew Thompson 	uByte	bDeviceClass;
28302ac6454SAndrew Thompson 	uByte	bDeviceSubClass;
28402ac6454SAndrew Thompson 	uByte	bDeviceProtocol;
28502ac6454SAndrew Thompson 	uByte	bMaxPacketSize;
28602ac6454SAndrew Thompson 	/* The fields below are not part of the initial descriptor. */
28702ac6454SAndrew Thompson 	uWord	idVendor;
28802ac6454SAndrew Thompson 	uWord	idProduct;
28902ac6454SAndrew Thompson 	uWord	bcdDevice;
29002ac6454SAndrew Thompson 	uByte	iManufacturer;
29102ac6454SAndrew Thompson 	uByte	iProduct;
29202ac6454SAndrew Thompson 	uByte	iSerialNumber;
29302ac6454SAndrew Thompson 	uByte	bNumConfigurations;
29402ac6454SAndrew Thompson } __packed;
295760bc48eSAndrew Thompson typedef struct usb_device_descriptor usb_device_descriptor_t;
29602ac6454SAndrew Thompson 
29702ac6454SAndrew Thompson /* Binary Device Object Store (BOS) */
298760bc48eSAndrew Thompson struct usb_bos_descriptor {
29902ac6454SAndrew Thompson 	uByte	bLength;
30002ac6454SAndrew Thompson 	uByte	bDescriptorType;
30102ac6454SAndrew Thompson 	uWord	wTotalLength;
30202ac6454SAndrew Thompson 	uByte	bNumDeviceCaps;
30302ac6454SAndrew Thompson } __packed;
304760bc48eSAndrew Thompson typedef struct usb_bos_descriptor usb_bos_descriptor_t;
30502ac6454SAndrew Thompson 
30602ac6454SAndrew Thompson /* Binary Device Object Store Capability */
307760bc48eSAndrew Thompson struct usb_bos_cap_descriptor {
30802ac6454SAndrew Thompson 	uByte	bLength;
30902ac6454SAndrew Thompson 	uByte	bDescriptorType;
31002ac6454SAndrew Thompson 	uByte	bDevCapabilityType;
31102ac6454SAndrew Thompson #define	USB_DEVCAP_RESERVED	0x00
31202ac6454SAndrew Thompson #define	USB_DEVCAP_WUSB		0x01
31302ac6454SAndrew Thompson #define	USB_DEVCAP_USB2EXT	0x02
31402ac6454SAndrew Thompson #define	USB_DEVCAP_SUPER_SPEED	0x03
31502ac6454SAndrew Thompson #define	USB_DEVCAP_CONTAINER_ID	0x04
31602ac6454SAndrew Thompson 	/* data ... */
31702ac6454SAndrew Thompson } __packed;
318760bc48eSAndrew Thompson typedef struct usb_bos_cap_descriptor usb_bos_cap_descriptor_t;
31902ac6454SAndrew Thompson 
320760bc48eSAndrew Thompson struct usb_devcap_usb2ext_descriptor {
32102ac6454SAndrew Thompson 	uByte	bLength;
32202ac6454SAndrew Thompson 	uByte	bDescriptorType;
32302ac6454SAndrew Thompson 	uByte	bDevCapabilityType;
32402ac6454SAndrew Thompson 	uByte	bmAttributes;
32502ac6454SAndrew Thompson #define	USB_V2EXT_LPM 0x02
32602ac6454SAndrew Thompson } __packed;
327760bc48eSAndrew Thompson typedef struct usb_devcap_usb2ext_descriptor usb_devcap_usb2ext_descriptor_t;
32802ac6454SAndrew Thompson 
329760bc48eSAndrew Thompson struct usb_devcap_ss_descriptor {
33002ac6454SAndrew Thompson 	uByte	bLength;
33102ac6454SAndrew Thompson 	uByte	bDescriptorType;
33202ac6454SAndrew Thompson 	uByte	bDevCapabilityType;
33302ac6454SAndrew Thompson 	uByte	bmAttributes;
33402ac6454SAndrew Thompson 	uWord	wSpeedsSupported;
33502ac6454SAndrew Thompson 	uByte	bFunctionaltySupport;
33602ac6454SAndrew Thompson 	uByte	bU1DevExitLat;
33702ac6454SAndrew Thompson 	uByte	bU2DevExitLat;
33802ac6454SAndrew Thompson } __packed;
339760bc48eSAndrew Thompson typedef struct usb_devcap_ss_descriptor usb_devcap_ss_descriptor_t;
34002ac6454SAndrew Thompson 
341760bc48eSAndrew Thompson struct usb_devcap_container_id_descriptor {
34202ac6454SAndrew Thompson 	uByte	bLength;
34302ac6454SAndrew Thompson 	uByte	bDescriptorType;
34402ac6454SAndrew Thompson 	uByte	bDevCapabilityType;
34502ac6454SAndrew Thompson 	uByte	bReserved;
34602ac6454SAndrew Thompson 	uByte	ContainerID;
34702ac6454SAndrew Thompson } __packed;
348760bc48eSAndrew Thompson typedef struct usb_devcap_container_id_descriptor
349d7e3163dSAndrew Thompson 		usb_devcap_container_id_descriptor_t;
35002ac6454SAndrew Thompson 
35102ac6454SAndrew Thompson /* Device class codes */
35202ac6454SAndrew Thompson #define	UDCLASS_IN_INTERFACE	0x00
35302ac6454SAndrew Thompson #define	UDCLASS_COMM		0x02
35402ac6454SAndrew Thompson #define	UDCLASS_HUB		0x09
35502ac6454SAndrew Thompson #define	UDSUBCLASS_HUB		0x00
35602ac6454SAndrew Thompson #define	UDPROTO_FSHUB		0x00
35702ac6454SAndrew Thompson #define	UDPROTO_HSHUBSTT	0x01
35802ac6454SAndrew Thompson #define	UDPROTO_HSHUBMTT	0x02
35902ac6454SAndrew Thompson #define	UDCLASS_DIAGNOSTIC	0xdc
36002ac6454SAndrew Thompson #define	UDCLASS_WIRELESS	0xe0
36102ac6454SAndrew Thompson #define	UDSUBCLASS_RF		0x01
36202ac6454SAndrew Thompson #define	UDPROTO_BLUETOOTH	0x01
36302ac6454SAndrew Thompson #define	UDCLASS_VENDOR		0xff
36402ac6454SAndrew Thompson 
365760bc48eSAndrew Thompson struct usb_config_descriptor {
36602ac6454SAndrew Thompson 	uByte	bLength;
36702ac6454SAndrew Thompson 	uByte	bDescriptorType;
36802ac6454SAndrew Thompson 	uWord	wTotalLength;
36902ac6454SAndrew Thompson 	uByte	bNumInterface;
37002ac6454SAndrew Thompson 	uByte	bConfigurationValue;
37102ac6454SAndrew Thompson #define	USB_UNCONFIG_NO 0
37202ac6454SAndrew Thompson 	uByte	iConfiguration;
37302ac6454SAndrew Thompson 	uByte	bmAttributes;
37402ac6454SAndrew Thompson #define	UC_BUS_POWERED		0x80
37502ac6454SAndrew Thompson #define	UC_SELF_POWERED		0x40
37602ac6454SAndrew Thompson #define	UC_REMOTE_WAKEUP	0x20
37702ac6454SAndrew Thompson 	uByte	bMaxPower;		/* max current in 2 mA units */
37802ac6454SAndrew Thompson #define	UC_POWER_FACTOR 2
37902ac6454SAndrew Thompson } __packed;
380760bc48eSAndrew Thompson typedef struct usb_config_descriptor usb_config_descriptor_t;
38102ac6454SAndrew Thompson 
382760bc48eSAndrew Thompson struct usb_interface_descriptor {
38302ac6454SAndrew Thompson 	uByte	bLength;
38402ac6454SAndrew Thompson 	uByte	bDescriptorType;
38502ac6454SAndrew Thompson 	uByte	bInterfaceNumber;
38602ac6454SAndrew Thompson 	uByte	bAlternateSetting;
38702ac6454SAndrew Thompson 	uByte	bNumEndpoints;
38802ac6454SAndrew Thompson 	uByte	bInterfaceClass;
38902ac6454SAndrew Thompson 	uByte	bInterfaceSubClass;
39002ac6454SAndrew Thompson 	uByte	bInterfaceProtocol;
39102ac6454SAndrew Thompson 	uByte	iInterface;
39202ac6454SAndrew Thompson } __packed;
393760bc48eSAndrew Thompson typedef struct usb_interface_descriptor usb_interface_descriptor_t;
39402ac6454SAndrew Thompson 
395760bc48eSAndrew Thompson struct usb_interface_assoc_descriptor {
39602ac6454SAndrew Thompson 	uByte	bLength;
39702ac6454SAndrew Thompson 	uByte	bDescriptorType;
39802ac6454SAndrew Thompson 	uByte	bFirstInterface;
39902ac6454SAndrew Thompson 	uByte	bInterfaceCount;
40002ac6454SAndrew Thompson 	uByte	bFunctionClass;
40102ac6454SAndrew Thompson 	uByte	bFunctionSubClass;
40202ac6454SAndrew Thompson 	uByte	bFunctionProtocol;
40302ac6454SAndrew Thompson 	uByte	iFunction;
40402ac6454SAndrew Thompson } __packed;
405760bc48eSAndrew Thompson typedef struct usb_interface_assoc_descriptor usb_interface_assoc_descriptor_t;
40602ac6454SAndrew Thompson 
40702ac6454SAndrew Thompson /* Interface class codes */
40802ac6454SAndrew Thompson #define	UICLASS_UNSPEC		0x00
40902ac6454SAndrew Thompson #define	UICLASS_AUDIO		0x01	/* audio */
41002ac6454SAndrew Thompson #define	UISUBCLASS_AUDIOCONTROL	1
41102ac6454SAndrew Thompson #define	UISUBCLASS_AUDIOSTREAM		2
41202ac6454SAndrew Thompson #define	UISUBCLASS_MIDISTREAM		3
41302ac6454SAndrew Thompson 
41402ac6454SAndrew Thompson #define	UICLASS_CDC		0x02	/* communication */
41502ac6454SAndrew Thompson #define	UISUBCLASS_DIRECT_LINE_CONTROL_MODEL	1
41602ac6454SAndrew Thompson #define	UISUBCLASS_ABSTRACT_CONTROL_MODEL	2
41702ac6454SAndrew Thompson #define	UISUBCLASS_TELEPHONE_CONTROL_MODEL	3
41802ac6454SAndrew Thompson #define	UISUBCLASS_MULTICHANNEL_CONTROL_MODEL	4
41902ac6454SAndrew Thompson #define	UISUBCLASS_CAPI_CONTROLMODEL		5
42002ac6454SAndrew Thompson #define	UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
42102ac6454SAndrew Thompson #define	UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
42202ac6454SAndrew Thompson #define	UISUBCLASS_WIRELESS_HANDSET_CM 8
42302ac6454SAndrew Thompson #define	UISUBCLASS_DEVICE_MGMT 9
42402ac6454SAndrew Thompson #define	UISUBCLASS_MOBILE_DIRECT_LINE_MODEL 10
42502ac6454SAndrew Thompson #define	UISUBCLASS_OBEX 11
42602ac6454SAndrew Thompson #define	UISUBCLASS_ETHERNET_EMULATION_MODEL 12
4274076dd23SAndrew Thompson #define	UISUBCLASS_NETWORK_CONTROL_MODEL 13
42802ac6454SAndrew Thompson 
42902ac6454SAndrew Thompson #define	UIPROTO_CDC_AT			1
43002ac6454SAndrew Thompson 
43102ac6454SAndrew Thompson #define	UICLASS_HID		0x03
43202ac6454SAndrew Thompson #define	UISUBCLASS_BOOT		1
43302ac6454SAndrew Thompson #define	UIPROTO_BOOT_KEYBOARD	1
43402ac6454SAndrew Thompson #define	UIPROTO_MOUSE		2
43502ac6454SAndrew Thompson 
43602ac6454SAndrew Thompson #define	UICLASS_PHYSICAL	0x05
43702ac6454SAndrew Thompson #define	UICLASS_IMAGE		0x06
43802ac6454SAndrew Thompson #define	UISUBCLASS_SIC		1	/* still image class */
43902ac6454SAndrew Thompson #define	UICLASS_PRINTER		0x07
44002ac6454SAndrew Thompson #define	UISUBCLASS_PRINTER	1
44102ac6454SAndrew Thompson #define	UIPROTO_PRINTER_UNI	1
44202ac6454SAndrew Thompson #define	UIPROTO_PRINTER_BI	2
44302ac6454SAndrew Thompson #define	UIPROTO_PRINTER_1284	3
44402ac6454SAndrew Thompson 
44502ac6454SAndrew Thompson #define	UICLASS_MASS		0x08
44602ac6454SAndrew Thompson #define	UISUBCLASS_RBC		1
44702ac6454SAndrew Thompson #define	UISUBCLASS_SFF8020I	2
44802ac6454SAndrew Thompson #define	UISUBCLASS_QIC157	3
44902ac6454SAndrew Thompson #define	UISUBCLASS_UFI		4
45002ac6454SAndrew Thompson #define	UISUBCLASS_SFF8070I	5
45102ac6454SAndrew Thompson #define	UISUBCLASS_SCSI		6
45202ac6454SAndrew Thompson #define	UIPROTO_MASS_CBI_I	0
45302ac6454SAndrew Thompson #define	UIPROTO_MASS_CBI	1
45402ac6454SAndrew Thompson #define	UIPROTO_MASS_BBB_OLD	2	/* Not in the spec anymore */
45502ac6454SAndrew Thompson #define	UIPROTO_MASS_BBB	80	/* 'P' for the Iomega Zip drive */
45602ac6454SAndrew Thompson 
45702ac6454SAndrew Thompson #define	UICLASS_HUB		0x09
45802ac6454SAndrew Thompson #define	UISUBCLASS_HUB		0
45902ac6454SAndrew Thompson #define	UIPROTO_FSHUB		0
46002ac6454SAndrew Thompson #define	UIPROTO_HSHUBSTT	0	/* Yes, same as previous */
46102ac6454SAndrew Thompson #define	UIPROTO_HSHUBMTT	1
46202ac6454SAndrew Thompson 
46302ac6454SAndrew Thompson #define	UICLASS_CDC_DATA	0x0a
4644076dd23SAndrew Thompson #define	UISUBCLASS_DATA		0x00
46502ac6454SAndrew Thompson #define	UIPROTO_DATA_ISDNBRI		0x30	/* Physical iface */
46602ac6454SAndrew Thompson #define	UIPROTO_DATA_HDLC		0x31	/* HDLC */
46702ac6454SAndrew Thompson #define	UIPROTO_DATA_TRANSPARENT	0x32	/* Transparent */
46802ac6454SAndrew Thompson #define	UIPROTO_DATA_Q921M		0x50	/* Management for Q921 */
46902ac6454SAndrew Thompson #define	UIPROTO_DATA_Q921		0x51	/* Data for Q921 */
47002ac6454SAndrew Thompson #define	UIPROTO_DATA_Q921TM		0x52	/* TEI multiplexer for Q921 */
47102ac6454SAndrew Thompson #define	UIPROTO_DATA_V42BIS		0x90	/* Data compression */
47202ac6454SAndrew Thompson #define	UIPROTO_DATA_Q931		0x91	/* Euro-ISDN */
47302ac6454SAndrew Thompson #define	UIPROTO_DATA_V120		0x92	/* V.24 rate adaption */
47402ac6454SAndrew Thompson #define	UIPROTO_DATA_CAPI		0x93	/* CAPI 2.0 commands */
47502ac6454SAndrew Thompson #define	UIPROTO_DATA_HOST_BASED		0xfd	/* Host based driver */
47602ac6454SAndrew Thompson #define	UIPROTO_DATA_PUF		0xfe	/* see Prot. Unit Func. Desc. */
47702ac6454SAndrew Thompson #define	UIPROTO_DATA_VENDOR		0xff	/* Vendor specific */
4784076dd23SAndrew Thompson #define	UIPROTO_DATA_NCM		0x01	/* Network Control Model */
47902ac6454SAndrew Thompson 
48002ac6454SAndrew Thompson #define	UICLASS_SMARTCARD	0x0b
48102ac6454SAndrew Thompson #define	UICLASS_FIRM_UPD	0x0c
48202ac6454SAndrew Thompson #define	UICLASS_SECURITY	0x0d
48302ac6454SAndrew Thompson #define	UICLASS_DIAGNOSTIC	0xdc
48402ac6454SAndrew Thompson #define	UICLASS_WIRELESS	0xe0
48502ac6454SAndrew Thompson #define	UISUBCLASS_RF			0x01
48602ac6454SAndrew Thompson #define	UIPROTO_BLUETOOTH		0x01
48702ac6454SAndrew Thompson 
488ec1201a2SAlfred Perlstein #define	UICLASS_IAD		0xEF	/* Interface Association Descriptor */
489ec1201a2SAlfred Perlstein 
49002ac6454SAndrew Thompson #define	UICLASS_APPL_SPEC	0xfe
49102ac6454SAndrew Thompson #define	UISUBCLASS_FIRMWARE_DOWNLOAD	1
49202ac6454SAndrew Thompson #define	UISUBCLASS_IRDA			2
49302ac6454SAndrew Thompson #define	UIPROTO_IRDA			0
49402ac6454SAndrew Thompson 
49502ac6454SAndrew Thompson #define	UICLASS_VENDOR		0xff
49602ac6454SAndrew Thompson #define	UISUBCLASS_XBOX360_CONTROLLER	0x5d
49702ac6454SAndrew Thompson #define	UIPROTO_XBOX360_GAMEPAD	0x01
49802ac6454SAndrew Thompson 
499760bc48eSAndrew Thompson struct usb_endpoint_descriptor {
50002ac6454SAndrew Thompson 	uByte	bLength;
50102ac6454SAndrew Thompson 	uByte	bDescriptorType;
50202ac6454SAndrew Thompson 	uByte	bEndpointAddress;
50302ac6454SAndrew Thompson #define	UE_GET_DIR(a)	((a) & 0x80)
50402ac6454SAndrew Thompson #define	UE_SET_DIR(a,d)	((a) | (((d)&1) << 7))
50551ec1603SAndrew Thompson #define	UE_DIR_IN	0x80		/* IN-token endpoint, fixed */
50651ec1603SAndrew Thompson #define	UE_DIR_OUT	0x00		/* OUT-token endpoint, fixed */
50751ec1603SAndrew Thompson #define	UE_DIR_RX	0xfd		/* for internal use only! */
50851ec1603SAndrew Thompson #define	UE_DIR_TX	0xfe		/* for internal use only! */
50902ac6454SAndrew Thompson #define	UE_DIR_ANY	0xff		/* for internal use only! */
51002ac6454SAndrew Thompson #define	UE_ADDR		0x0f
51102ac6454SAndrew Thompson #define	UE_ADDR_ANY	0xff		/* for internal use only! */
51202ac6454SAndrew Thompson #define	UE_GET_ADDR(a)	((a) & UE_ADDR)
51302ac6454SAndrew Thompson 	uByte	bmAttributes;
51402ac6454SAndrew Thompson #define	UE_XFERTYPE	0x03
51502ac6454SAndrew Thompson #define	UE_CONTROL	0x00
51602ac6454SAndrew Thompson #define	UE_ISOCHRONOUS	0x01
51702ac6454SAndrew Thompson #define	UE_BULK	0x02
51802ac6454SAndrew Thompson #define	UE_INTERRUPT	0x03
51902ac6454SAndrew Thompson #define	UE_BULK_INTR	0xfe		/* for internal use only! */
52002ac6454SAndrew Thompson #define	UE_TYPE_ANY	0xff		/* for internal use only! */
52102ac6454SAndrew Thompson #define	UE_GET_XFERTYPE(a)	((a) & UE_XFERTYPE)
52202ac6454SAndrew Thompson #define	UE_ISO_TYPE	0x0c
52302ac6454SAndrew Thompson #define	UE_ISO_ASYNC	0x04
52402ac6454SAndrew Thompson #define	UE_ISO_ADAPT	0x08
52502ac6454SAndrew Thompson #define	UE_ISO_SYNC	0x0c
52602ac6454SAndrew Thompson #define	UE_GET_ISO_TYPE(a)	((a) & UE_ISO_TYPE)
52702ac6454SAndrew Thompson 	uWord	wMaxPacketSize;
52802ac6454SAndrew Thompson #define	UE_ZERO_MPS 0xFFFF		/* for internal use only */
52902ac6454SAndrew Thompson 	uByte	bInterval;
53002ac6454SAndrew Thompson } __packed;
531760bc48eSAndrew Thompson typedef struct usb_endpoint_descriptor usb_endpoint_descriptor_t;
53202ac6454SAndrew Thompson 
533760bc48eSAndrew Thompson struct usb_endpoint_ss_comp_descriptor {
53402ac6454SAndrew Thompson 	uByte	bLength;
53502ac6454SAndrew Thompson 	uByte	bDescriptorType;
53602ac6454SAndrew Thompson 	uWord	bMaxBurst;
53702ac6454SAndrew Thompson 	uByte	bmAttributes;
53802ac6454SAndrew Thompson 	uWord	wBytesPerInterval;
53902ac6454SAndrew Thompson } __packed;
540760bc48eSAndrew Thompson typedef struct usb_endpoint_ss_comp_descriptor
541d7e3163dSAndrew Thompson 		usb_endpoint_ss_comp_descriptor_t;
54202ac6454SAndrew Thompson 
543760bc48eSAndrew Thompson struct usb_string_descriptor {
54402ac6454SAndrew Thompson 	uByte	bLength;
54502ac6454SAndrew Thompson 	uByte	bDescriptorType;
54602ac6454SAndrew Thompson 	uWord	bString[126];
54702ac6454SAndrew Thompson 	uByte	bUnused;
54802ac6454SAndrew Thompson } __packed;
549760bc48eSAndrew Thompson typedef struct usb_string_descriptor usb_string_descriptor_t;
55002ac6454SAndrew Thompson 
55102ac6454SAndrew Thompson #define	USB_MAKE_STRING_DESC(m,name)	\
55202ac6454SAndrew Thompson struct name {				\
55302ac6454SAndrew Thompson   uByte bLength;			\
55402ac6454SAndrew Thompson   uByte bDescriptorType;		\
55502ac6454SAndrew Thompson   uByte bData[sizeof((uint8_t []){m})];	\
55602ac6454SAndrew Thompson } __packed;				\
55702ac6454SAndrew Thompson static const struct name name = {	\
55802ac6454SAndrew Thompson   .bLength = sizeof(struct name),	\
55902ac6454SAndrew Thompson   .bDescriptorType = UDESC_STRING,	\
56002ac6454SAndrew Thompson   .bData = { m },			\
56102ac6454SAndrew Thompson }
56202ac6454SAndrew Thompson 
563760bc48eSAndrew Thompson struct usb_hub_descriptor {
56402ac6454SAndrew Thompson 	uByte	bDescLength;
56502ac6454SAndrew Thompson 	uByte	bDescriptorType;
56602ac6454SAndrew Thompson 	uByte	bNbrPorts;
56702ac6454SAndrew Thompson 	uWord	wHubCharacteristics;
56802ac6454SAndrew Thompson #define	UHD_PWR			0x0003
56902ac6454SAndrew Thompson #define	UHD_PWR_GANGED		0x0000
57002ac6454SAndrew Thompson #define	UHD_PWR_INDIVIDUAL	0x0001
57102ac6454SAndrew Thompson #define	UHD_PWR_NO_SWITCH	0x0002
57202ac6454SAndrew Thompson #define	UHD_COMPOUND		0x0004
57302ac6454SAndrew Thompson #define	UHD_OC			0x0018
57402ac6454SAndrew Thompson #define	UHD_OC_GLOBAL		0x0000
57502ac6454SAndrew Thompson #define	UHD_OC_INDIVIDUAL	0x0008
57602ac6454SAndrew Thompson #define	UHD_OC_NONE		0x0010
57702ac6454SAndrew Thompson #define	UHD_TT_THINK		0x0060
57802ac6454SAndrew Thompson #define	UHD_TT_THINK_8		0x0000
57902ac6454SAndrew Thompson #define	UHD_TT_THINK_16		0x0020
58002ac6454SAndrew Thompson #define	UHD_TT_THINK_24		0x0040
58102ac6454SAndrew Thompson #define	UHD_TT_THINK_32		0x0060
58202ac6454SAndrew Thompson #define	UHD_PORT_IND		0x0080
58302ac6454SAndrew Thompson 	uByte	bPwrOn2PwrGood;		/* delay in 2 ms units */
58402ac6454SAndrew Thompson #define	UHD_PWRON_FACTOR 2
58502ac6454SAndrew Thompson 	uByte	bHubContrCurrent;
58602ac6454SAndrew Thompson 	uByte	DeviceRemovable[32];	/* max 255 ports */
58702ac6454SAndrew Thompson #define	UHD_NOT_REMOV(desc, i) \
58802ac6454SAndrew Thompson     (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
58902ac6454SAndrew Thompson 	uByte	PortPowerCtrlMask[1];	/* deprecated */
59002ac6454SAndrew Thompson } __packed;
591760bc48eSAndrew Thompson typedef struct usb_hub_descriptor usb_hub_descriptor_t;
59202ac6454SAndrew Thompson 
593760bc48eSAndrew Thompson struct usb_hub_ss_descriptor {
59402ac6454SAndrew Thompson 	uByte	bDescLength;
59502ac6454SAndrew Thompson 	uByte	bDescriptorType;
59602ac6454SAndrew Thompson 	uByte	bNbrPorts;		/* max 15 */
59702ac6454SAndrew Thompson 	uWord	wHubCharacteristics;
59802ac6454SAndrew Thompson 	uByte	bPwrOn2PwrGood;		/* delay in 2 ms units */
59902ac6454SAndrew Thompson 	uByte	bHubContrCurrent;
60002ac6454SAndrew Thompson 	uByte	bHubHdrDecLat;
60102ac6454SAndrew Thompson 	uWord	wHubDelay;
60202ac6454SAndrew Thompson 	uByte	DeviceRemovable[2];	/* max 15 ports */
60302ac6454SAndrew Thompson } __packed;
604760bc48eSAndrew Thompson typedef struct usb_hub_ss_descriptor usb_hub_ss_descriptor_t;
60502ac6454SAndrew Thompson 
60602ac6454SAndrew Thompson /* minimum HUB descriptor (8-ports maximum) */
607760bc48eSAndrew Thompson struct usb_hub_descriptor_min {
60802ac6454SAndrew Thompson 	uByte	bDescLength;
60902ac6454SAndrew Thompson 	uByte	bDescriptorType;
61002ac6454SAndrew Thompson 	uByte	bNbrPorts;
61102ac6454SAndrew Thompson 	uWord	wHubCharacteristics;
61202ac6454SAndrew Thompson 	uByte	bPwrOn2PwrGood;
61302ac6454SAndrew Thompson 	uByte	bHubContrCurrent;
61402ac6454SAndrew Thompson 	uByte	DeviceRemovable[1];
61502ac6454SAndrew Thompson 	uByte	PortPowerCtrlMask[1];
61602ac6454SAndrew Thompson } __packed;
617760bc48eSAndrew Thompson typedef struct usb_hub_descriptor_min usb_hub_descriptor_min_t;
61802ac6454SAndrew Thompson 
619760bc48eSAndrew Thompson struct usb_device_qualifier {
62002ac6454SAndrew Thompson 	uByte	bLength;
62102ac6454SAndrew Thompson 	uByte	bDescriptorType;
62202ac6454SAndrew Thompson 	uWord	bcdUSB;
62302ac6454SAndrew Thompson 	uByte	bDeviceClass;
62402ac6454SAndrew Thompson 	uByte	bDeviceSubClass;
62502ac6454SAndrew Thompson 	uByte	bDeviceProtocol;
62602ac6454SAndrew Thompson 	uByte	bMaxPacketSize0;
62702ac6454SAndrew Thompson 	uByte	bNumConfigurations;
62802ac6454SAndrew Thompson 	uByte	bReserved;
62902ac6454SAndrew Thompson } __packed;
630760bc48eSAndrew Thompson typedef struct usb_device_qualifier usb_device_qualifier_t;
63102ac6454SAndrew Thompson 
632760bc48eSAndrew Thompson struct usb_otg_descriptor {
63302ac6454SAndrew Thompson 	uByte	bLength;
63402ac6454SAndrew Thompson 	uByte	bDescriptorType;
63502ac6454SAndrew Thompson 	uByte	bmAttributes;
63602ac6454SAndrew Thompson #define	UOTG_SRP	0x01
63702ac6454SAndrew Thompson #define	UOTG_HNP	0x02
63802ac6454SAndrew Thompson } __packed;
639760bc48eSAndrew Thompson typedef struct usb_otg_descriptor usb_otg_descriptor_t;
64002ac6454SAndrew Thompson 
64102ac6454SAndrew Thompson /* OTG feature selectors */
64202ac6454SAndrew Thompson #define	UOTG_B_HNP_ENABLE	3
64302ac6454SAndrew Thompson #define	UOTG_A_HNP_SUPPORT	4
64402ac6454SAndrew Thompson #define	UOTG_A_ALT_HNP_SUPPORT	5
64502ac6454SAndrew Thompson 
646760bc48eSAndrew Thompson struct usb_status {
64702ac6454SAndrew Thompson 	uWord	wStatus;
64802ac6454SAndrew Thompson /* Device status flags */
64902ac6454SAndrew Thompson #define	UDS_SELF_POWERED		0x0001
65002ac6454SAndrew Thompson #define	UDS_REMOTE_WAKEUP		0x0002
65102ac6454SAndrew Thompson /* Endpoint status flags */
65202ac6454SAndrew Thompson #define	UES_HALT			0x0001
65302ac6454SAndrew Thompson } __packed;
654760bc48eSAndrew Thompson typedef struct usb_status usb_status_t;
65502ac6454SAndrew Thompson 
656760bc48eSAndrew Thompson struct usb_hub_status {
65702ac6454SAndrew Thompson 	uWord	wHubStatus;
65802ac6454SAndrew Thompson #define	UHS_LOCAL_POWER			0x0001
65902ac6454SAndrew Thompson #define	UHS_OVER_CURRENT		0x0002
66002ac6454SAndrew Thompson 	uWord	wHubChange;
66102ac6454SAndrew Thompson } __packed;
662760bc48eSAndrew Thompson typedef struct usb_hub_status usb_hub_status_t;
66302ac6454SAndrew Thompson 
664760bc48eSAndrew Thompson struct usb_port_status {
66502ac6454SAndrew Thompson 	uWord	wPortStatus;
66602ac6454SAndrew Thompson #define	UPS_CURRENT_CONNECT_STATUS	0x0001
66702ac6454SAndrew Thompson #define	UPS_PORT_ENABLED		0x0002
66802ac6454SAndrew Thompson #define	UPS_SUSPEND			0x0004
66902ac6454SAndrew Thompson #define	UPS_OVERCURRENT_INDICATOR	0x0008
67002ac6454SAndrew Thompson #define	UPS_RESET			0x0010
67102ac6454SAndrew Thompson #define	UPS_PORT_POWER			0x0100
67202ac6454SAndrew Thompson #define	UPS_LOW_SPEED			0x0200
67302ac6454SAndrew Thompson #define	UPS_HIGH_SPEED			0x0400
67402ac6454SAndrew Thompson #define	UPS_PORT_TEST			0x0800
67502ac6454SAndrew Thompson #define	UPS_PORT_INDICATOR		0x1000
67602ac6454SAndrew Thompson #define	UPS_PORT_MODE_DEVICE		0x8000	/* currently FreeBSD specific */
67702ac6454SAndrew Thompson 	uWord	wPortChange;
67802ac6454SAndrew Thompson #define	UPS_C_CONNECT_STATUS		0x0001
67902ac6454SAndrew Thompson #define	UPS_C_PORT_ENABLED		0x0002
68002ac6454SAndrew Thompson #define	UPS_C_SUSPEND			0x0004
68102ac6454SAndrew Thompson #define	UPS_C_OVERCURRENT_INDICATOR	0x0008
68202ac6454SAndrew Thompson #define	UPS_C_PORT_RESET		0x0010
68302ac6454SAndrew Thompson } __packed;
684760bc48eSAndrew Thompson typedef struct usb_port_status usb_port_status_t;
68502ac6454SAndrew Thompson 
686ed6d949aSAndrew Thompson /*
687ed6d949aSAndrew Thompson  * The "USB_SPEED" macros defines all the supported USB speeds.
688ed6d949aSAndrew Thompson  */
689ed6d949aSAndrew Thompson enum usb_dev_speed {
690ed6d949aSAndrew Thompson 	USB_SPEED_VARIABLE,
691ed6d949aSAndrew Thompson 	USB_SPEED_LOW,
692ed6d949aSAndrew Thompson 	USB_SPEED_FULL,
693ed6d949aSAndrew Thompson 	USB_SPEED_HIGH,
694ed6d949aSAndrew Thompson 	USB_SPEED_SUPER,
695ed6d949aSAndrew Thompson };
696ed6d949aSAndrew Thompson #define	USB_SPEED_MAX	(USB_SPEED_SUPER+1)
697ed6d949aSAndrew Thompson 
698ed6d949aSAndrew Thompson /*
699ed6d949aSAndrew Thompson  * The "USB_REV" macros defines all the supported USB revisions.
700ed6d949aSAndrew Thompson  */
701ed6d949aSAndrew Thompson enum usb_revision {
702ed6d949aSAndrew Thompson 	USB_REV_UNKNOWN,
703ed6d949aSAndrew Thompson 	USB_REV_PRE_1_0,
704ed6d949aSAndrew Thompson 	USB_REV_1_0,
705ed6d949aSAndrew Thompson 	USB_REV_1_1,
706ed6d949aSAndrew Thompson 	USB_REV_2_0,
707ed6d949aSAndrew Thompson 	USB_REV_2_5,
708ed6d949aSAndrew Thompson 	USB_REV_3_0
709ed6d949aSAndrew Thompson };
710ed6d949aSAndrew Thompson #define	USB_REV_MAX	(USB_REV_3_0+1)
711ed6d949aSAndrew Thompson 
712ed6d949aSAndrew Thompson /*
713ed6d949aSAndrew Thompson  * Supported host contoller modes.
714ed6d949aSAndrew Thompson  */
715ed6d949aSAndrew Thompson enum usb_hc_mode {
716ed6d949aSAndrew Thompson 	USB_MODE_HOST,		/* initiates transfers */
717ed6d949aSAndrew Thompson 	USB_MODE_DEVICE,	/* bus transfer target */
718ed6d949aSAndrew Thompson 	USB_MODE_DUAL		/* can be host or device */
719ed6d949aSAndrew Thompson };
720ed6d949aSAndrew Thompson #define	USB_MODE_MAX	(USB_MODE_DUAL+1)
721ed6d949aSAndrew Thompson 
722ed6d949aSAndrew Thompson /*
723ed6d949aSAndrew Thompson  * The "USB_MODE" macros defines all the supported device states.
724ed6d949aSAndrew Thompson  */
725ed6d949aSAndrew Thompson enum usb_dev_state {
726ed6d949aSAndrew Thompson 	USB_STATE_DETACHED,
727ed6d949aSAndrew Thompson 	USB_STATE_ATTACHED,
728ed6d949aSAndrew Thompson 	USB_STATE_POWERED,
729ed6d949aSAndrew Thompson 	USB_STATE_ADDRESSED,
730ed6d949aSAndrew Thompson 	USB_STATE_CONFIGURED,
731ed6d949aSAndrew Thompson };
732ed6d949aSAndrew Thompson #define	USB_STATE_MAX	(USB_STATE_CONFIGURED+1)
73375973647SAndrew Thompson #endif					/* _USB_STANDARD_H_ */
734