xref: /freebsd/sys/dev/usb/usb.h (revision e152944f1a16a4ff33b4e20b813ce4a54b884b90)
102ac6454SAndrew Thompson /*-
2b61a5730SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
402ac6454SAndrew Thompson  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
502ac6454SAndrew Thompson  * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
602ac6454SAndrew Thompson  * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
702ac6454SAndrew Thompson  *
802ac6454SAndrew Thompson  * Redistribution and use in source and binary forms, with or without
902ac6454SAndrew Thompson  * modification, are permitted provided that the following conditions
1002ac6454SAndrew Thompson  * are met:
1102ac6454SAndrew Thompson  * 1. Redistributions of source code must retain the above copyright
1202ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer.
1302ac6454SAndrew Thompson  * 2. Redistributions in binary form must reproduce the above copyright
1402ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer in the
1502ac6454SAndrew Thompson  *    documentation and/or other materials provided with the distribution.
1602ac6454SAndrew Thompson  *
1702ac6454SAndrew Thompson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1802ac6454SAndrew Thompson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1902ac6454SAndrew Thompson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2002ac6454SAndrew Thompson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2102ac6454SAndrew Thompson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2202ac6454SAndrew Thompson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2302ac6454SAndrew Thompson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2402ac6454SAndrew Thompson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2502ac6454SAndrew Thompson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2602ac6454SAndrew Thompson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2702ac6454SAndrew Thompson  * SUCH DAMAGE.
2802ac6454SAndrew Thompson  */
2902ac6454SAndrew Thompson 
3002ac6454SAndrew Thompson /*
3102ac6454SAndrew Thompson  * This file contains standard definitions for the following USB
3202ac6454SAndrew Thompson  * protocol versions:
3302ac6454SAndrew Thompson  *
3402ac6454SAndrew Thompson  * USB v1.0
3502ac6454SAndrew Thompson  * USB v1.1
3602ac6454SAndrew Thompson  * USB v2.0
3702ac6454SAndrew Thompson  * USB v3.0
3802ac6454SAndrew Thompson  */
3902ac6454SAndrew Thompson 
4075973647SAndrew Thompson #ifndef _USB_STANDARD_H_
4175973647SAndrew Thompson #define	_USB_STANDARD_H_
4202ac6454SAndrew Thompson 
43a2dd1caaSHans Petter Selasky #if defined(_KERNEL) || defined(_STANDALONE)
44d2b99310SHans Petter Selasky #ifndef USB_GLOBAL_INCLUDE_FILE
45ed6d949aSAndrew Thompson #include "opt_usb.h"
46d2b99310SHans Petter Selasky #endif
47ed6d949aSAndrew Thompson 
48ed6d949aSAndrew Thompson /* Declare parent SYSCTL USB node. */
49ed6d949aSAndrew Thompson #ifdef SYSCTL_DECL
50ed6d949aSAndrew Thompson SYSCTL_DECL(_hw_usb);
51ed6d949aSAndrew Thompson #endif
52ed6d949aSAndrew Thompson 
53d2b99310SHans Petter Selasky #ifndef USB_GLOBAL_INCLUDE_FILE
54ed6d949aSAndrew Thompson #include <sys/malloc.h>
55d2b99310SHans Petter Selasky #endif
56ed6d949aSAndrew Thompson 
57ed6d949aSAndrew Thompson MALLOC_DECLARE(M_USB);
58ed6d949aSAndrew Thompson MALLOC_DECLARE(M_USBDEV);
59a2dd1caaSHans Petter Selasky #endif	/* _KERNEL || _STANDALONE */
60ed6d949aSAndrew Thompson 
61d2b99310SHans Petter Selasky #ifndef USB_GLOBAL_INCLUDE_FILE
6202ac6454SAndrew Thompson #include <dev/usb/usb_endian.h>
63ed6d949aSAndrew Thompson #include <dev/usb/usb_freebsd.h>
64d2b99310SHans Petter Selasky #endif
65ed6d949aSAndrew Thompson 
66ed6d949aSAndrew Thompson #define	USB_STACK_VERSION 2000		/* 2.0 */
67ed6d949aSAndrew Thompson 
68ed6d949aSAndrew Thompson /* Definition of some hardcoded USB constants. */
69ed6d949aSAndrew Thompson 
70ed6d949aSAndrew Thompson #define	USB_MAX_IPACKET		8	/* initial USB packet size */
71ed6d949aSAndrew Thompson #define	USB_EP_MAX (2*16)		/* hardcoded */
72ed6d949aSAndrew Thompson #define	USB_ROOT_HUB_ADDR 1		/* index */
73ed6d949aSAndrew Thompson #define	USB_MIN_DEVICES 2		/* unused + root HUB */
74ed6d949aSAndrew Thompson #define	USB_UNCONFIG_INDEX 0xFF		/* internal use only */
75ed6d949aSAndrew Thompson #define	USB_IFACE_INDEX_ANY 0xFF	/* internal use only */
76ed6d949aSAndrew Thompson #define	USB_START_ADDR 0		/* default USB device BUS address
77ed6d949aSAndrew Thompson 					 * after USB bus reset */
78ed6d949aSAndrew Thompson #define	USB_CONTROL_ENDPOINT 0		/* default control endpoint */
79ed6d949aSAndrew Thompson 
80ed6d949aSAndrew Thompson #define	USB_FRAMES_PER_SECOND_FS 1000	/* full speed */
81ed6d949aSAndrew Thompson #define	USB_FRAMES_PER_SECOND_HS 8000	/* high speed */
82ed6d949aSAndrew Thompson 
83ed6d949aSAndrew Thompson #define	USB_FS_BYTES_PER_HS_UFRAME 188	/* bytes */
84ed6d949aSAndrew Thompson #define	USB_HS_MICRO_FRAMES_MAX 8	/* units */
85ed6d949aSAndrew Thompson 
86ed6d949aSAndrew Thompson #define	USB_ISOC_TIME_MAX 128		/* ms */
8702ac6454SAndrew Thompson 
8802ac6454SAndrew Thompson /*
8902ac6454SAndrew Thompson  * Minimum time a device needs to be powered down to go through a
9002ac6454SAndrew Thompson  * power cycle. These values are not in the USB specification.
9102ac6454SAndrew Thompson  */
9202ac6454SAndrew Thompson #define	USB_POWER_DOWN_TIME	200	/* ms */
9302ac6454SAndrew Thompson #define	USB_PORT_POWER_DOWN_TIME	100	/* ms */
9402ac6454SAndrew Thompson 
9502ac6454SAndrew Thompson /* Definition of software USB power modes */
9602ac6454SAndrew Thompson #define	USB_POWER_MODE_OFF 0		/* turn off device */
9702ac6454SAndrew Thompson #define	USB_POWER_MODE_ON 1		/* always on */
9802ac6454SAndrew Thompson #define	USB_POWER_MODE_SAVE 2		/* automatic suspend and resume */
9902ac6454SAndrew Thompson #define	USB_POWER_MODE_SUSPEND 3	/* force suspend */
10002ac6454SAndrew Thompson #define	USB_POWER_MODE_RESUME 4		/* force resume */
10102ac6454SAndrew Thompson 
10202ac6454SAndrew Thompson /* These are the values from the USB specification. */
10337506412SHans Petter Selasky #define	USB_PORT_RESET_DELAY_SPEC	10	/* ms */
10437506412SHans Petter Selasky #define	USB_PORT_ROOT_RESET_DELAY_SPEC	50	/* ms */
10537506412SHans Petter Selasky #define	USB_PORT_RESET_RECOVERY_SPEC	10	/* ms */
10637506412SHans Petter Selasky #define	USB_PORT_POWERUP_DELAY_SPEC	100	/* ms */
10737506412SHans Petter Selasky #define	USB_PORT_RESUME_DELAY_SPEC	20	/* ms */
10837506412SHans Petter Selasky #define	USB_SET_ADDRESS_SETTLE_SPEC	2	/* ms */
10937506412SHans Petter Selasky #define	USB_RESUME_DELAY_SPEC		(20*5)	/* ms */
11037506412SHans Petter Selasky #define	USB_RESUME_WAIT_SPEC		10	/* ms */
11137506412SHans Petter Selasky #define	USB_RESUME_RECOVERY_SPEC	10	/* ms */
11237506412SHans Petter Selasky #define	USB_EXTRA_POWER_UP_TIME_SPEC	0	/* ms */
11337506412SHans Petter Selasky 
11402ac6454SAndrew Thompson /* Allow for marginal and non-conforming devices. */
11502ac6454SAndrew Thompson #define	USB_PORT_RESET_DELAY		50	/* ms */
116c61ee529SHans Petter Selasky #define	USB_PORT_ROOT_RESET_DELAY	200	/* ms */
117*e152944fSAhmad Khalifa #define	USB_PORT_RESET_RECOVERY		20	/* ms */
11802ac6454SAndrew Thompson #define	USB_PORT_POWERUP_DELAY		300	/* ms */
11902ac6454SAndrew Thompson #define	USB_PORT_RESUME_DELAY		(20*2)	/* ms */
12002ac6454SAndrew Thompson #define	USB_SET_ADDRESS_SETTLE		10	/* ms */
12102ac6454SAndrew Thompson #define	USB_RESUME_DELAY		(50*5)	/* ms */
12202ac6454SAndrew Thompson #define	USB_RESUME_WAIT			50	/* ms */
12302ac6454SAndrew Thompson #define	USB_RESUME_RECOVERY		50	/* ms */
12402ac6454SAndrew Thompson #define	USB_EXTRA_POWER_UP_TIME		20	/* ms */
1258758aabbSHans Petter Selasky #define	USB_ENUM_NICE_TIME		16	/* ms */
12602ac6454SAndrew Thompson 
12702ac6454SAndrew Thompson #define	USB_MIN_POWER		100	/* mA */
12802ac6454SAndrew Thompson #define	USB_MAX_POWER		500	/* mA */
12902ac6454SAndrew Thompson 
13002ac6454SAndrew Thompson #define	USB_BUS_RESET_DELAY	100	/* ms */
13102ac6454SAndrew Thompson 
13202ac6454SAndrew Thompson /*
13302ac6454SAndrew Thompson  * USB record layout in memory:
13402ac6454SAndrew Thompson  *
13502ac6454SAndrew Thompson  * - USB config 0
13602ac6454SAndrew Thompson  *   - USB interfaces
13702ac6454SAndrew Thompson  *     - USB alternative interfaces
138ae60fdfbSAndrew Thompson  *       - USB endpoints
13902ac6454SAndrew Thompson  *
14002ac6454SAndrew Thompson  * - USB config 1
14102ac6454SAndrew Thompson  *   - USB interfaces
14202ac6454SAndrew Thompson  *     - USB alternative interfaces
143ae60fdfbSAndrew Thompson  *       - USB endpoints
14402ac6454SAndrew Thompson  */
14502ac6454SAndrew Thompson 
14602ac6454SAndrew Thompson /* Declaration of USB records */
14702ac6454SAndrew Thompson 
148760bc48eSAndrew Thompson struct usb_device_request {
14902ac6454SAndrew Thompson 	uByte	bmRequestType;
15002ac6454SAndrew Thompson 	uByte	bRequest;
15102ac6454SAndrew Thompson 	uWord	wValue;
15202ac6454SAndrew Thompson 	uWord	wIndex;
15302ac6454SAndrew Thompson 	uWord	wLength;
15402ac6454SAndrew Thompson } __packed;
155760bc48eSAndrew Thompson typedef struct usb_device_request usb_device_request_t;
15602ac6454SAndrew Thompson 
15702ac6454SAndrew Thompson #define	UT_WRITE		0x00
15802ac6454SAndrew Thompson #define	UT_READ			0x80
15902ac6454SAndrew Thompson #define	UT_STANDARD		0x00
16002ac6454SAndrew Thompson #define	UT_CLASS		0x20
16102ac6454SAndrew Thompson #define	UT_VENDOR		0x40
16202ac6454SAndrew Thompson #define	UT_DEVICE		0x00
16302ac6454SAndrew Thompson #define	UT_INTERFACE		0x01
16402ac6454SAndrew Thompson #define	UT_ENDPOINT		0x02
16502ac6454SAndrew Thompson #define	UT_OTHER		0x03
16602ac6454SAndrew Thompson 
16702ac6454SAndrew Thompson #define	UT_READ_DEVICE		(UT_READ  | UT_STANDARD | UT_DEVICE)
16802ac6454SAndrew Thompson #define	UT_READ_INTERFACE	(UT_READ  | UT_STANDARD | UT_INTERFACE)
16902ac6454SAndrew Thompson #define	UT_READ_ENDPOINT	(UT_READ  | UT_STANDARD | UT_ENDPOINT)
17002ac6454SAndrew Thompson #define	UT_WRITE_DEVICE		(UT_WRITE | UT_STANDARD | UT_DEVICE)
17102ac6454SAndrew Thompson #define	UT_WRITE_INTERFACE	(UT_WRITE | UT_STANDARD | UT_INTERFACE)
17202ac6454SAndrew Thompson #define	UT_WRITE_ENDPOINT	(UT_WRITE | UT_STANDARD | UT_ENDPOINT)
17302ac6454SAndrew Thompson #define	UT_READ_CLASS_DEVICE	(UT_READ  | UT_CLASS | UT_DEVICE)
17402ac6454SAndrew Thompson #define	UT_READ_CLASS_INTERFACE	(UT_READ  | UT_CLASS | UT_INTERFACE)
17502ac6454SAndrew Thompson #define	UT_READ_CLASS_OTHER	(UT_READ  | UT_CLASS | UT_OTHER)
17602ac6454SAndrew Thompson #define	UT_READ_CLASS_ENDPOINT	(UT_READ  | UT_CLASS | UT_ENDPOINT)
17702ac6454SAndrew Thompson #define	UT_WRITE_CLASS_DEVICE	(UT_WRITE | UT_CLASS | UT_DEVICE)
17802ac6454SAndrew Thompson #define	UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
17902ac6454SAndrew Thompson #define	UT_WRITE_CLASS_OTHER	(UT_WRITE | UT_CLASS | UT_OTHER)
18002ac6454SAndrew Thompson #define	UT_WRITE_CLASS_ENDPOINT	(UT_WRITE | UT_CLASS | UT_ENDPOINT)
18102ac6454SAndrew Thompson #define	UT_READ_VENDOR_DEVICE	(UT_READ  | UT_VENDOR | UT_DEVICE)
18202ac6454SAndrew Thompson #define	UT_READ_VENDOR_INTERFACE (UT_READ  | UT_VENDOR | UT_INTERFACE)
18302ac6454SAndrew Thompson #define	UT_READ_VENDOR_OTHER	(UT_READ  | UT_VENDOR | UT_OTHER)
18402ac6454SAndrew Thompson #define	UT_READ_VENDOR_ENDPOINT	(UT_READ  | UT_VENDOR | UT_ENDPOINT)
18502ac6454SAndrew Thompson #define	UT_WRITE_VENDOR_DEVICE	(UT_WRITE | UT_VENDOR | UT_DEVICE)
18602ac6454SAndrew Thompson #define	UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
18702ac6454SAndrew Thompson #define	UT_WRITE_VENDOR_OTHER	(UT_WRITE | UT_VENDOR | UT_OTHER)
18802ac6454SAndrew Thompson #define	UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
18902ac6454SAndrew Thompson 
19002ac6454SAndrew Thompson /* Requests */
19102ac6454SAndrew Thompson #define	UR_GET_STATUS		0x00
19202ac6454SAndrew Thompson #define	UR_CLEAR_FEATURE	0x01
19302ac6454SAndrew Thompson #define	UR_SET_FEATURE		0x03
19402ac6454SAndrew Thompson #define	UR_SET_ADDRESS		0x05
19502ac6454SAndrew Thompson #define	UR_GET_DESCRIPTOR	0x06
19602ac6454SAndrew Thompson #define	UDESC_DEVICE		0x01
19702ac6454SAndrew Thompson #define	UDESC_CONFIG		0x02
19802ac6454SAndrew Thompson #define	UDESC_STRING		0x03
19902ac6454SAndrew Thompson #define	USB_LANGUAGE_TABLE	0x00	/* language ID string index */
20002ac6454SAndrew Thompson #define	UDESC_INTERFACE		0x04
20102ac6454SAndrew Thompson #define	UDESC_ENDPOINT		0x05
20202ac6454SAndrew Thompson #define	UDESC_DEVICE_QUALIFIER	0x06
20302ac6454SAndrew Thompson #define	UDESC_OTHER_SPEED_CONFIGURATION 0x07
20402ac6454SAndrew Thompson #define	UDESC_INTERFACE_POWER	0x08
20502ac6454SAndrew Thompson #define	UDESC_OTG		0x09
20602ac6454SAndrew Thompson #define	UDESC_DEBUG		0x0A
20702ac6454SAndrew Thompson #define	UDESC_IFACE_ASSOC	0x0B	/* interface association */
20802ac6454SAndrew Thompson #define	UDESC_BOS		0x0F	/* binary object store */
20902ac6454SAndrew Thompson #define	UDESC_DEVICE_CAPABILITY	0x10
21002ac6454SAndrew Thompson #define	UDESC_CS_DEVICE		0x21	/* class specific */
21102ac6454SAndrew Thompson #define	UDESC_CS_CONFIG		0x22
21202ac6454SAndrew Thompson #define	UDESC_CS_STRING		0x23
21302ac6454SAndrew Thompson #define	UDESC_CS_INTERFACE	0x24
21402ac6454SAndrew Thompson #define	UDESC_CS_ENDPOINT	0x25
21502ac6454SAndrew Thompson #define	UDESC_HUB		0x29
2167b039740SHans Petter Selasky #define	UDESC_SS_HUB		0x2A	/* super speed */
21702ac6454SAndrew Thompson #define	UDESC_ENDPOINT_SS_COMP	0x30	/* super speed */
21802ac6454SAndrew Thompson #define	UR_SET_DESCRIPTOR	0x07
21902ac6454SAndrew Thompson #define	UR_GET_CONFIG		0x08
22002ac6454SAndrew Thompson #define	UR_SET_CONFIG		0x09
22102ac6454SAndrew Thompson #define	UR_GET_INTERFACE	0x0a
22202ac6454SAndrew Thompson #define	UR_SET_INTERFACE	0x0b
22302ac6454SAndrew Thompson #define	UR_SYNCH_FRAME		0x0c
22402ac6454SAndrew Thompson #define	UR_SET_SEL		0x30
22502ac6454SAndrew Thompson #define	UR_ISOCH_DELAY		0x31
22602ac6454SAndrew Thompson 
22702ac6454SAndrew Thompson /* HUB specific request */
22802ac6454SAndrew Thompson #define	UR_GET_BUS_STATE	0x02
22902ac6454SAndrew Thompson #define	UR_CLEAR_TT_BUFFER	0x08
23002ac6454SAndrew Thompson #define	UR_RESET_TT		0x09
23102ac6454SAndrew Thompson #define	UR_GET_TT_STATE		0x0a
23202ac6454SAndrew Thompson #define	UR_STOP_TT		0x0b
2334563ba7aSHans Petter Selasky #define	UR_SET_AND_TEST		0x0c	/* USB 2.0 only */
2344563ba7aSHans Petter Selasky #define	UR_SET_HUB_DEPTH	0x0c	/* USB 3.0 only */
2357b039740SHans Petter Selasky #define	USB_SS_HUB_DEPTH_MAX	5
23602ac6454SAndrew Thompson #define	UR_GET_PORT_ERR_COUNT	0x0d
23702ac6454SAndrew Thompson 
23802ac6454SAndrew Thompson /* Feature numbers */
23902ac6454SAndrew Thompson #define	UF_ENDPOINT_HALT	0
24002ac6454SAndrew Thompson #define	UF_DEVICE_REMOTE_WAKEUP	1
24102ac6454SAndrew Thompson #define	UF_TEST_MODE		2
24202ac6454SAndrew Thompson #define	UF_U1_ENABLE		0x30
24302ac6454SAndrew Thompson #define	UF_U2_ENABLE		0x31
24402ac6454SAndrew Thompson #define	UF_LTM_ENABLE		0x32
24502ac6454SAndrew Thompson 
24602ac6454SAndrew Thompson /* HUB specific features */
24702ac6454SAndrew Thompson #define	UHF_C_HUB_LOCAL_POWER	0
24802ac6454SAndrew Thompson #define	UHF_C_HUB_OVER_CURRENT	1
24902ac6454SAndrew Thompson #define	UHF_PORT_CONNECTION	0
25002ac6454SAndrew Thompson #define	UHF_PORT_ENABLE		1
25102ac6454SAndrew Thompson #define	UHF_PORT_SUSPEND	2
25202ac6454SAndrew Thompson #define	UHF_PORT_OVER_CURRENT	3
25302ac6454SAndrew Thompson #define	UHF_PORT_RESET		4
25402ac6454SAndrew Thompson #define	UHF_PORT_LINK_STATE	5
25502ac6454SAndrew Thompson #define	UHF_PORT_POWER		8
25602ac6454SAndrew Thompson #define	UHF_PORT_LOW_SPEED	9
2574563ba7aSHans Petter Selasky #define	UHF_PORT_L1		10
25802ac6454SAndrew Thompson #define	UHF_C_PORT_CONNECTION	16
25902ac6454SAndrew Thompson #define	UHF_C_PORT_ENABLE	17
26002ac6454SAndrew Thompson #define	UHF_C_PORT_SUSPEND	18
26102ac6454SAndrew Thompson #define	UHF_C_PORT_OVER_CURRENT	19
26202ac6454SAndrew Thompson #define	UHF_C_PORT_RESET	20
26302ac6454SAndrew Thompson #define	UHF_PORT_TEST		21
26402ac6454SAndrew Thompson #define	UHF_PORT_INDICATOR	22
2654563ba7aSHans Petter Selasky #define	UHF_C_PORT_L1		23
26602ac6454SAndrew Thompson 
26702ac6454SAndrew Thompson /* SuperSpeed HUB specific features */
26802ac6454SAndrew Thompson #define	UHF_PORT_U1_TIMEOUT	23
26902ac6454SAndrew Thompson #define	UHF_PORT_U2_TIMEOUT	24
27002ac6454SAndrew Thompson #define	UHF_C_PORT_LINK_STATE	25
27102ac6454SAndrew Thompson #define	UHF_C_PORT_CONFIG_ERROR	26
27202ac6454SAndrew Thompson #define	UHF_PORT_REMOTE_WAKE_MASK	27
27302ac6454SAndrew Thompson #define	UHF_BH_PORT_RESET	28
27402ac6454SAndrew Thompson #define	UHF_C_BH_PORT_RESET	29
27502ac6454SAndrew Thompson #define	UHF_FORCE_LINKPM_ACCEPT	30
27602ac6454SAndrew Thompson 
277d76ca5b1SHans Petter Selasky /* SuperSpeed suspend support */
278d76ca5b1SHans Petter Selasky #define	USB_INTERFACE_FUNC_SUSPEND 0
279d76ca5b1SHans Petter Selasky #define	USB_INTERFACE_FUNC_SUSPEND_LP	(1 << 8)
280d76ca5b1SHans Petter Selasky #define	USB_INTERFACE_FUNC_SUSPEND_RW	(1 << 9)
281d76ca5b1SHans Petter Selasky 
282760bc48eSAndrew Thompson struct usb_descriptor {
28302ac6454SAndrew Thompson 	uByte	bLength;
28402ac6454SAndrew Thompson 	uByte	bDescriptorType;
28502ac6454SAndrew Thompson 	uByte	bDescriptorSubtype;
28602ac6454SAndrew Thompson } __packed;
287760bc48eSAndrew Thompson typedef struct usb_descriptor usb_descriptor_t;
28802ac6454SAndrew Thompson 
289760bc48eSAndrew Thompson struct usb_device_descriptor {
29002ac6454SAndrew Thompson 	uByte	bLength;
29102ac6454SAndrew Thompson 	uByte	bDescriptorType;
29202ac6454SAndrew Thompson 	uWord	bcdUSB;
29302ac6454SAndrew Thompson #define	UD_USB_2_0		0x0200
29402ac6454SAndrew Thompson #define	UD_USB_3_0		0x0300
29502ac6454SAndrew Thompson #define	UD_IS_USB2(d) ((d)->bcdUSB[1] == 0x02)
29602ac6454SAndrew Thompson #define	UD_IS_USB3(d) ((d)->bcdUSB[1] == 0x03)
29702ac6454SAndrew Thompson 	uByte	bDeviceClass;
29802ac6454SAndrew Thompson 	uByte	bDeviceSubClass;
29902ac6454SAndrew Thompson 	uByte	bDeviceProtocol;
30002ac6454SAndrew Thompson 	uByte	bMaxPacketSize;
30102ac6454SAndrew Thompson 	/* The fields below are not part of the initial descriptor. */
30202ac6454SAndrew Thompson 	uWord	idVendor;
30302ac6454SAndrew Thompson 	uWord	idProduct;
30402ac6454SAndrew Thompson 	uWord	bcdDevice;
30502ac6454SAndrew Thompson 	uByte	iManufacturer;
30602ac6454SAndrew Thompson 	uByte	iProduct;
30702ac6454SAndrew Thompson 	uByte	iSerialNumber;
30802ac6454SAndrew Thompson 	uByte	bNumConfigurations;
30902ac6454SAndrew Thompson } __packed;
310760bc48eSAndrew Thompson typedef struct usb_device_descriptor usb_device_descriptor_t;
31102ac6454SAndrew Thompson 
31202ac6454SAndrew Thompson /* Binary Device Object Store (BOS) */
313760bc48eSAndrew Thompson struct usb_bos_descriptor {
31402ac6454SAndrew Thompson 	uByte	bLength;
31502ac6454SAndrew Thompson 	uByte	bDescriptorType;
31602ac6454SAndrew Thompson 	uWord	wTotalLength;
31702ac6454SAndrew Thompson 	uByte	bNumDeviceCaps;
31802ac6454SAndrew Thompson } __packed;
319760bc48eSAndrew Thompson typedef struct usb_bos_descriptor usb_bos_descriptor_t;
32002ac6454SAndrew Thompson 
32102ac6454SAndrew Thompson /* Binary Device Object Store Capability */
322760bc48eSAndrew Thompson struct usb_bos_cap_descriptor {
32302ac6454SAndrew Thompson 	uByte	bLength;
32402ac6454SAndrew Thompson 	uByte	bDescriptorType;
32502ac6454SAndrew Thompson 	uByte	bDevCapabilityType;
32602ac6454SAndrew Thompson #define	USB_DEVCAP_RESERVED	0x00
32702ac6454SAndrew Thompson #define	USB_DEVCAP_WUSB		0x01
32802ac6454SAndrew Thompson #define	USB_DEVCAP_USB2EXT	0x02
32902ac6454SAndrew Thompson #define	USB_DEVCAP_SUPER_SPEED	0x03
33002ac6454SAndrew Thompson #define	USB_DEVCAP_CONTAINER_ID	0x04
33102ac6454SAndrew Thompson 	/* data ... */
33202ac6454SAndrew Thompson } __packed;
333760bc48eSAndrew Thompson typedef struct usb_bos_cap_descriptor usb_bos_cap_descriptor_t;
33402ac6454SAndrew Thompson 
335760bc48eSAndrew Thompson struct usb_devcap_usb2ext_descriptor {
33602ac6454SAndrew Thompson 	uByte	bLength;
33702ac6454SAndrew Thompson 	uByte	bDescriptorType;
33802ac6454SAndrew Thompson 	uByte	bDevCapabilityType;
339b3b1747aSHans Petter Selasky 	uDWord	bmAttributes;
3404563ba7aSHans Petter Selasky #define	USB_V2EXT_LPM (1U << 1)
3414563ba7aSHans Petter Selasky #define	USB_V2EXT_BESL_SUPPORTED (1U << 2)
3424563ba7aSHans Petter Selasky #define	USB_V2EXT_BESL_BASELINE_VALID (1U << 3)
3434563ba7aSHans Petter Selasky #define	USB_V2EXT_BESL_DEEP_VALID (1U << 4)
3444563ba7aSHans Petter Selasky #define	USB_V2EXT_BESL_BASELINE_GET(x) (((x) >> 8) & 0xF)
3454563ba7aSHans Petter Selasky #define	USB_V2EXT_BESL_DEEP_GET(x) (((x) >> 12) & 0xF)
34602ac6454SAndrew Thompson } __packed;
347760bc48eSAndrew Thompson typedef struct usb_devcap_usb2ext_descriptor usb_devcap_usb2ext_descriptor_t;
34802ac6454SAndrew Thompson 
349760bc48eSAndrew Thompson struct usb_devcap_ss_descriptor {
35002ac6454SAndrew Thompson 	uByte	bLength;
35102ac6454SAndrew Thompson 	uByte	bDescriptorType;
35202ac6454SAndrew Thompson 	uByte	bDevCapabilityType;
35302ac6454SAndrew Thompson 	uByte	bmAttributes;
35402ac6454SAndrew Thompson 	uWord	wSpeedsSupported;
3557b039740SHans Petter Selasky 	uByte	bFunctionalitySupport;
35602ac6454SAndrew Thompson 	uByte	bU1DevExitLat;
357c089ba5eSHans Petter Selasky 	uWord	wU2DevExitLat;
35802ac6454SAndrew Thompson } __packed;
359760bc48eSAndrew Thompson typedef struct usb_devcap_ss_descriptor usb_devcap_ss_descriptor_t;
36002ac6454SAndrew Thompson 
361760bc48eSAndrew Thompson struct usb_devcap_container_id_descriptor {
36202ac6454SAndrew Thompson 	uByte	bLength;
36302ac6454SAndrew Thompson 	uByte	bDescriptorType;
36402ac6454SAndrew Thompson 	uByte	bDevCapabilityType;
36502ac6454SAndrew Thompson 	uByte	bReserved;
3667b039740SHans Petter Selasky 	uByte	bContainerID;
36702ac6454SAndrew Thompson } __packed;
368760bc48eSAndrew Thompson typedef struct usb_devcap_container_id_descriptor
369d7e3163dSAndrew Thompson 		usb_devcap_container_id_descriptor_t;
37002ac6454SAndrew Thompson 
37102ac6454SAndrew Thompson /* Device class codes */
37202ac6454SAndrew Thompson #define	UDCLASS_IN_INTERFACE	0x00
37302ac6454SAndrew Thompson #define	UDCLASS_COMM		0x02
37402ac6454SAndrew Thompson #define	UDCLASS_HUB		0x09
37502ac6454SAndrew Thompson #define	UDSUBCLASS_HUB		0x00
37602ac6454SAndrew Thompson #define	UDPROTO_FSHUB		0x00
37702ac6454SAndrew Thompson #define	UDPROTO_HSHUBSTT	0x01
37802ac6454SAndrew Thompson #define	UDPROTO_HSHUBMTT	0x02
3797b039740SHans Petter Selasky #define	UDPROTO_SSHUB		0x03
38002ac6454SAndrew Thompson #define	UDCLASS_DIAGNOSTIC	0xdc
38102ac6454SAndrew Thompson #define	UDCLASS_WIRELESS	0xe0
38202ac6454SAndrew Thompson #define	UDSUBCLASS_RF		0x01
38302ac6454SAndrew Thompson #define	UDPROTO_BLUETOOTH	0x01
38402ac6454SAndrew Thompson #define	UDCLASS_VENDOR		0xff
38502ac6454SAndrew Thompson 
386760bc48eSAndrew Thompson struct usb_config_descriptor {
38702ac6454SAndrew Thompson 	uByte	bLength;
38802ac6454SAndrew Thompson 	uByte	bDescriptorType;
38902ac6454SAndrew Thompson 	uWord	wTotalLength;
39002ac6454SAndrew Thompson 	uByte	bNumInterface;
39102ac6454SAndrew Thompson 	uByte	bConfigurationValue;
39202ac6454SAndrew Thompson #define	USB_UNCONFIG_NO 0
39302ac6454SAndrew Thompson 	uByte	iConfiguration;
39402ac6454SAndrew Thompson 	uByte	bmAttributes;
39502ac6454SAndrew Thompson #define	UC_BUS_POWERED		0x80
39602ac6454SAndrew Thompson #define	UC_SELF_POWERED		0x40
39702ac6454SAndrew Thompson #define	UC_REMOTE_WAKEUP	0x20
39802ac6454SAndrew Thompson 	uByte	bMaxPower;		/* max current in 2 mA units */
39902ac6454SAndrew Thompson #define	UC_POWER_FACTOR 2
40002ac6454SAndrew Thompson } __packed;
401760bc48eSAndrew Thompson typedef struct usb_config_descriptor usb_config_descriptor_t;
40202ac6454SAndrew Thompson 
403760bc48eSAndrew Thompson struct usb_interface_descriptor {
40402ac6454SAndrew Thompson 	uByte	bLength;
40502ac6454SAndrew Thompson 	uByte	bDescriptorType;
40602ac6454SAndrew Thompson 	uByte	bInterfaceNumber;
40702ac6454SAndrew Thompson 	uByte	bAlternateSetting;
40802ac6454SAndrew Thompson 	uByte	bNumEndpoints;
40902ac6454SAndrew Thompson 	uByte	bInterfaceClass;
41002ac6454SAndrew Thompson 	uByte	bInterfaceSubClass;
41102ac6454SAndrew Thompson 	uByte	bInterfaceProtocol;
41202ac6454SAndrew Thompson 	uByte	iInterface;
41302ac6454SAndrew Thompson } __packed;
414760bc48eSAndrew Thompson typedef struct usb_interface_descriptor usb_interface_descriptor_t;
41502ac6454SAndrew Thompson 
416760bc48eSAndrew Thompson struct usb_interface_assoc_descriptor {
41702ac6454SAndrew Thompson 	uByte	bLength;
41802ac6454SAndrew Thompson 	uByte	bDescriptorType;
41902ac6454SAndrew Thompson 	uByte	bFirstInterface;
42002ac6454SAndrew Thompson 	uByte	bInterfaceCount;
42102ac6454SAndrew Thompson 	uByte	bFunctionClass;
42202ac6454SAndrew Thompson 	uByte	bFunctionSubClass;
42302ac6454SAndrew Thompson 	uByte	bFunctionProtocol;
42402ac6454SAndrew Thompson 	uByte	iFunction;
42502ac6454SAndrew Thompson } __packed;
426760bc48eSAndrew Thompson typedef struct usb_interface_assoc_descriptor usb_interface_assoc_descriptor_t;
42702ac6454SAndrew Thompson 
42802ac6454SAndrew Thompson /* Interface class codes */
42902ac6454SAndrew Thompson #define	UICLASS_UNSPEC		0x00
43002ac6454SAndrew Thompson #define	UICLASS_AUDIO		0x01	/* audio */
43102ac6454SAndrew Thompson #define	UISUBCLASS_AUDIOCONTROL	1
43202ac6454SAndrew Thompson #define	UISUBCLASS_AUDIOSTREAM		2
43302ac6454SAndrew Thompson #define	UISUBCLASS_MIDISTREAM		3
43402ac6454SAndrew Thompson 
43502ac6454SAndrew Thompson #define	UICLASS_CDC		0x02	/* communication */
43602ac6454SAndrew Thompson #define	UISUBCLASS_DIRECT_LINE_CONTROL_MODEL	1
43702ac6454SAndrew Thompson #define	UISUBCLASS_ABSTRACT_CONTROL_MODEL	2
43802ac6454SAndrew Thompson #define	UISUBCLASS_TELEPHONE_CONTROL_MODEL	3
43902ac6454SAndrew Thompson #define	UISUBCLASS_MULTICHANNEL_CONTROL_MODEL	4
44002ac6454SAndrew Thompson #define	UISUBCLASS_CAPI_CONTROLMODEL		5
44102ac6454SAndrew Thompson #define	UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
44202ac6454SAndrew Thompson #define	UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
44302ac6454SAndrew Thompson #define	UISUBCLASS_WIRELESS_HANDSET_CM 8
44402ac6454SAndrew Thompson #define	UISUBCLASS_DEVICE_MGMT 9
44502ac6454SAndrew Thompson #define	UISUBCLASS_MOBILE_DIRECT_LINE_MODEL 10
44602ac6454SAndrew Thompson #define	UISUBCLASS_OBEX 11
44702ac6454SAndrew Thompson #define	UISUBCLASS_ETHERNET_EMULATION_MODEL 12
4484076dd23SAndrew Thompson #define	UISUBCLASS_NETWORK_CONTROL_MODEL 13
44902ac6454SAndrew Thompson 
450c48efaecSAdrian Chadd #define	UIPROTO_CDC_NONE		0
45102ac6454SAndrew Thompson #define	UIPROTO_CDC_AT			1
45263722e52SEdward Tomasz Napierala #define	UIPROTO_CDC_EEM			7
45302ac6454SAndrew Thompson 
45402ac6454SAndrew Thompson #define	UICLASS_HID		0x03
45502ac6454SAndrew Thompson #define	UISUBCLASS_BOOT		1
45602ac6454SAndrew Thompson #define	UIPROTO_BOOT_KEYBOARD	1
45702ac6454SAndrew Thompson #define	UIPROTO_MOUSE		2
45802ac6454SAndrew Thompson 
45902ac6454SAndrew Thompson #define	UICLASS_PHYSICAL	0x05
46002ac6454SAndrew Thompson #define	UICLASS_IMAGE		0x06
46102ac6454SAndrew Thompson #define	UISUBCLASS_SIC		1	/* still image class */
46202ac6454SAndrew Thompson #define	UICLASS_PRINTER		0x07
46302ac6454SAndrew Thompson #define	UISUBCLASS_PRINTER	1
46402ac6454SAndrew Thompson #define	UIPROTO_PRINTER_UNI	1
46502ac6454SAndrew Thompson #define	UIPROTO_PRINTER_BI	2
46602ac6454SAndrew Thompson #define	UIPROTO_PRINTER_1284	3
46702ac6454SAndrew Thompson 
46802ac6454SAndrew Thompson #define	UICLASS_MASS		0x08
46902ac6454SAndrew Thompson #define	UISUBCLASS_RBC		1
47002ac6454SAndrew Thompson #define	UISUBCLASS_SFF8020I	2
47102ac6454SAndrew Thompson #define	UISUBCLASS_QIC157	3
47202ac6454SAndrew Thompson #define	UISUBCLASS_UFI		4
47302ac6454SAndrew Thompson #define	UISUBCLASS_SFF8070I	5
47402ac6454SAndrew Thompson #define	UISUBCLASS_SCSI		6
47502ac6454SAndrew Thompson #define	UIPROTO_MASS_CBI_I	0
47602ac6454SAndrew Thompson #define	UIPROTO_MASS_CBI	1
47702ac6454SAndrew Thompson #define	UIPROTO_MASS_BBB_OLD	2	/* Not in the spec anymore */
47802ac6454SAndrew Thompson #define	UIPROTO_MASS_BBB	80	/* 'P' for the Iomega Zip drive */
47902ac6454SAndrew Thompson 
48002ac6454SAndrew Thompson #define	UICLASS_HUB		0x09
48102ac6454SAndrew Thompson #define	UISUBCLASS_HUB		0
48202ac6454SAndrew Thompson #define	UIPROTO_FSHUB		0
48302ac6454SAndrew Thompson #define	UIPROTO_HSHUBSTT	0	/* Yes, same as previous */
48402ac6454SAndrew Thompson #define	UIPROTO_HSHUBMTT	1
48502ac6454SAndrew Thompson 
48602ac6454SAndrew Thompson #define	UICLASS_CDC_DATA	0x0a
4874076dd23SAndrew Thompson #define	UISUBCLASS_DATA		0x00
48802ac6454SAndrew Thompson #define	UIPROTO_DATA_ISDNBRI		0x30	/* Physical iface */
48902ac6454SAndrew Thompson #define	UIPROTO_DATA_HDLC		0x31	/* HDLC */
49002ac6454SAndrew Thompson #define	UIPROTO_DATA_TRANSPARENT	0x32	/* Transparent */
49102ac6454SAndrew Thompson #define	UIPROTO_DATA_Q921M		0x50	/* Management for Q921 */
49202ac6454SAndrew Thompson #define	UIPROTO_DATA_Q921		0x51	/* Data for Q921 */
49302ac6454SAndrew Thompson #define	UIPROTO_DATA_Q921TM		0x52	/* TEI multiplexer for Q921 */
49402ac6454SAndrew Thompson #define	UIPROTO_DATA_V42BIS		0x90	/* Data compression */
49502ac6454SAndrew Thompson #define	UIPROTO_DATA_Q931		0x91	/* Euro-ISDN */
49602ac6454SAndrew Thompson #define	UIPROTO_DATA_V120		0x92	/* V.24 rate adaption */
49702ac6454SAndrew Thompson #define	UIPROTO_DATA_CAPI		0x93	/* CAPI 2.0 commands */
49802ac6454SAndrew Thompson #define	UIPROTO_DATA_HOST_BASED		0xfd	/* Host based driver */
49902ac6454SAndrew Thompson #define	UIPROTO_DATA_PUF		0xfe	/* see Prot. Unit Func. Desc. */
50002ac6454SAndrew Thompson #define	UIPROTO_DATA_VENDOR		0xff	/* Vendor specific */
5014076dd23SAndrew Thompson #define	UIPROTO_DATA_NCM		0x01	/* Network Control Model */
50202ac6454SAndrew Thompson 
50302ac6454SAndrew Thompson #define	UICLASS_SMARTCARD	0x0b
50402ac6454SAndrew Thompson #define	UICLASS_FIRM_UPD	0x0c
50502ac6454SAndrew Thompson #define	UICLASS_SECURITY	0x0d
50602ac6454SAndrew Thompson #define	UICLASS_DIAGNOSTIC	0xdc
50702ac6454SAndrew Thompson #define	UICLASS_WIRELESS	0xe0
50802ac6454SAndrew Thompson #define	UISUBCLASS_RF			0x01
50902ac6454SAndrew Thompson #define	UIPROTO_BLUETOOTH		0x01
51029311227SHans Petter Selasky #define	UIPROTO_RNDIS			0x03
51102ac6454SAndrew Thompson 
512ec1201a2SAlfred Perlstein #define	UICLASS_IAD		0xEF	/* Interface Association Descriptor */
51329311227SHans Petter Selasky #define	UISUBCLASS_SYNC			0x01
51429311227SHans Petter Selasky #define	UIPROTO_ACTIVESYNC		0x01
515ec1201a2SAlfred Perlstein 
51602ac6454SAndrew Thompson #define	UICLASS_APPL_SPEC	0xfe
51702ac6454SAndrew Thompson #define	UISUBCLASS_FIRMWARE_DOWNLOAD	1
51802ac6454SAndrew Thompson #define	UISUBCLASS_IRDA			2
51902ac6454SAndrew Thompson #define	UIPROTO_IRDA			0
52002ac6454SAndrew Thompson 
52102ac6454SAndrew Thompson #define	UICLASS_VENDOR		0xff
52202ac6454SAndrew Thompson #define	UISUBCLASS_XBOX360_CONTROLLER	0x5d
523dab84426SHans Petter Selasky #define	UISUBCLASS_VENDOR	0xff
52402ac6454SAndrew Thompson #define	UIPROTO_XBOX360_GAMEPAD	0x01
52502ac6454SAndrew Thompson 
526760bc48eSAndrew Thompson struct usb_endpoint_descriptor {
52702ac6454SAndrew Thompson 	uByte	bLength;
52802ac6454SAndrew Thompson 	uByte	bDescriptorType;
52902ac6454SAndrew Thompson 	uByte	bEndpointAddress;
53002ac6454SAndrew Thompson #define	UE_GET_DIR(a)	((a) & 0x80)
53102ac6454SAndrew Thompson #define	UE_SET_DIR(a,d)	((a) | (((d)&1) << 7))
53251ec1603SAndrew Thompson #define	UE_DIR_IN	0x80		/* IN-token endpoint, fixed */
53351ec1603SAndrew Thompson #define	UE_DIR_OUT	0x00		/* OUT-token endpoint, fixed */
53451ec1603SAndrew Thompson #define	UE_DIR_RX	0xfd		/* for internal use only! */
53551ec1603SAndrew Thompson #define	UE_DIR_TX	0xfe		/* for internal use only! */
53602ac6454SAndrew Thompson #define	UE_DIR_ANY	0xff		/* for internal use only! */
53702ac6454SAndrew Thompson #define	UE_ADDR		0x0f
53802ac6454SAndrew Thompson #define	UE_ADDR_ANY	0xff		/* for internal use only! */
53902ac6454SAndrew Thompson #define	UE_GET_ADDR(a)	((a) & UE_ADDR)
54002ac6454SAndrew Thompson 	uByte	bmAttributes;
54102ac6454SAndrew Thompson #define	UE_XFERTYPE	0x03
54202ac6454SAndrew Thompson #define	UE_CONTROL	0x00
54302ac6454SAndrew Thompson #define	UE_ISOCHRONOUS	0x01
54402ac6454SAndrew Thompson #define	UE_BULK	0x02
54502ac6454SAndrew Thompson #define	UE_INTERRUPT	0x03
54602ac6454SAndrew Thompson #define	UE_BULK_INTR	0xfe		/* for internal use only! */
54702ac6454SAndrew Thompson #define	UE_TYPE_ANY	0xff		/* for internal use only! */
54802ac6454SAndrew Thompson #define	UE_GET_XFERTYPE(a)	((a) & UE_XFERTYPE)
54902ac6454SAndrew Thompson #define	UE_ISO_TYPE	0x0c
55002ac6454SAndrew Thompson #define	UE_ISO_ASYNC	0x04
55102ac6454SAndrew Thompson #define	UE_ISO_ADAPT	0x08
55202ac6454SAndrew Thompson #define	UE_ISO_SYNC	0x0c
55302ac6454SAndrew Thompson #define	UE_GET_ISO_TYPE(a)	((a) & UE_ISO_TYPE)
5545c155f23SHans Petter Selasky #define	UE_ISO_USAGE	0x30
5555c155f23SHans Petter Selasky #define	UE_ISO_USAGE_DATA	0x00
5565c155f23SHans Petter Selasky #define	UE_ISO_USAGE_FEEDBACK	0x10
5575c155f23SHans Petter Selasky #define	UE_ISO_USAGE_IMPLICT_FB	0x20
5585c155f23SHans Petter Selasky #define	UE_GET_ISO_USAGE(a)	((a) & UE_ISO_USAGE)
55902ac6454SAndrew Thompson 	uWord	wMaxPacketSize;
56002ac6454SAndrew Thompson #define	UE_ZERO_MPS 0xFFFF		/* for internal use only */
56102ac6454SAndrew Thompson 	uByte	bInterval;
56202ac6454SAndrew Thompson } __packed;
563760bc48eSAndrew Thompson typedef struct usb_endpoint_descriptor usb_endpoint_descriptor_t;
56402ac6454SAndrew Thompson 
565760bc48eSAndrew Thompson struct usb_endpoint_ss_comp_descriptor {
56602ac6454SAndrew Thompson 	uByte	bLength;
56702ac6454SAndrew Thompson 	uByte	bDescriptorType;
5687b039740SHans Petter Selasky 	uByte	bMaxBurst;
56902ac6454SAndrew Thompson 	uByte	bmAttributes;
570a5cf1aaaSHans Petter Selasky #define	UE_GET_BULK_STREAMS(x) ((x) & 0x0F)
571a5cf1aaaSHans Petter Selasky #define	UE_GET_SS_ISO_MULT(x) ((x) & 0x03)
57202ac6454SAndrew Thompson 	uWord	wBytesPerInterval;
57302ac6454SAndrew Thompson } __packed;
574760bc48eSAndrew Thompson typedef struct usb_endpoint_ss_comp_descriptor
575d7e3163dSAndrew Thompson 		usb_endpoint_ss_comp_descriptor_t;
57602ac6454SAndrew Thompson 
577760bc48eSAndrew Thompson struct usb_string_descriptor {
57802ac6454SAndrew Thompson 	uByte	bLength;
57902ac6454SAndrew Thompson 	uByte	bDescriptorType;
58002ac6454SAndrew Thompson 	uWord	bString[126];
58102ac6454SAndrew Thompson 	uByte	bUnused;
58202ac6454SAndrew Thompson } __packed;
583760bc48eSAndrew Thompson typedef struct usb_string_descriptor usb_string_descriptor_t;
58402ac6454SAndrew Thompson 
58502ac6454SAndrew Thompson #define	USB_MAKE_STRING_DESC(m,name)	\
58601923b39SHans Petter Selasky static const struct {			\
58702ac6454SAndrew Thompson   uByte bLength;			\
58802ac6454SAndrew Thompson   uByte bDescriptorType;		\
58902ac6454SAndrew Thompson   uByte bData[sizeof((uint8_t []){m})];	\
59001923b39SHans Petter Selasky } __packed name = {			\
59101923b39SHans Petter Selasky   .bLength = sizeof(name),		\
59202ac6454SAndrew Thompson   .bDescriptorType = UDESC_STRING,	\
59302ac6454SAndrew Thompson   .bData = { m },			\
59402ac6454SAndrew Thompson }
59502ac6454SAndrew Thompson 
59623ab0871SHans Petter Selasky struct usb_string_lang {
59723ab0871SHans Petter Selasky 	uByte bLength;
59823ab0871SHans Petter Selasky 	uByte bDescriptorType;
59923ab0871SHans Petter Selasky 	uByte bData[2];
60023ab0871SHans Petter Selasky } __packed;
60123ab0871SHans Petter Selasky typedef struct usb_string_lang usb_string_lang_t;
60223ab0871SHans Petter Selasky 
603760bc48eSAndrew Thompson struct usb_hub_descriptor {
60402ac6454SAndrew Thompson 	uByte	bDescLength;
60502ac6454SAndrew Thompson 	uByte	bDescriptorType;
60602ac6454SAndrew Thompson 	uByte	bNbrPorts;
60702ac6454SAndrew Thompson 	uWord	wHubCharacteristics;
60802ac6454SAndrew Thompson #define	UHD_PWR			0x0003
60902ac6454SAndrew Thompson #define	UHD_PWR_GANGED		0x0000
61002ac6454SAndrew Thompson #define	UHD_PWR_INDIVIDUAL	0x0001
61102ac6454SAndrew Thompson #define	UHD_PWR_NO_SWITCH	0x0002
61202ac6454SAndrew Thompson #define	UHD_COMPOUND		0x0004
61302ac6454SAndrew Thompson #define	UHD_OC			0x0018
61402ac6454SAndrew Thompson #define	UHD_OC_GLOBAL		0x0000
61502ac6454SAndrew Thompson #define	UHD_OC_INDIVIDUAL	0x0008
61602ac6454SAndrew Thompson #define	UHD_OC_NONE		0x0010
61702ac6454SAndrew Thompson #define	UHD_TT_THINK		0x0060
61802ac6454SAndrew Thompson #define	UHD_TT_THINK_8		0x0000
61902ac6454SAndrew Thompson #define	UHD_TT_THINK_16		0x0020
62002ac6454SAndrew Thompson #define	UHD_TT_THINK_24		0x0040
62102ac6454SAndrew Thompson #define	UHD_TT_THINK_32		0x0060
62202ac6454SAndrew Thompson #define	UHD_PORT_IND		0x0080
62302ac6454SAndrew Thompson 	uByte	bPwrOn2PwrGood;		/* delay in 2 ms units */
62402ac6454SAndrew Thompson #define	UHD_PWRON_FACTOR 2
62502ac6454SAndrew Thompson 	uByte	bHubContrCurrent;
62602ac6454SAndrew Thompson 	uByte	DeviceRemovable[32];	/* max 255 ports */
62702ac6454SAndrew Thompson #define	UHD_NOT_REMOV(desc, i) \
62802ac6454SAndrew Thompson     (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
62902ac6454SAndrew Thompson 	uByte	PortPowerCtrlMask[1];	/* deprecated */
63002ac6454SAndrew Thompson } __packed;
631760bc48eSAndrew Thompson typedef struct usb_hub_descriptor usb_hub_descriptor_t;
63202ac6454SAndrew Thompson 
633760bc48eSAndrew Thompson struct usb_hub_ss_descriptor {
6347b039740SHans Petter Selasky 	uByte	bLength;
63502ac6454SAndrew Thompson 	uByte	bDescriptorType;
6367b039740SHans Petter Selasky 	uByte	bNbrPorts;
63702ac6454SAndrew Thompson 	uWord	wHubCharacteristics;
63802ac6454SAndrew Thompson 	uByte	bPwrOn2PwrGood;		/* delay in 2 ms units */
63902ac6454SAndrew Thompson 	uByte	bHubContrCurrent;
64002ac6454SAndrew Thompson 	uByte	bHubHdrDecLat;
64102ac6454SAndrew Thompson 	uWord	wHubDelay;
6427b039740SHans Petter Selasky 	uByte	DeviceRemovable[32];	/* max 255 ports */
64302ac6454SAndrew Thompson } __packed;
644760bc48eSAndrew Thompson typedef struct usb_hub_ss_descriptor usb_hub_ss_descriptor_t;
64502ac6454SAndrew Thompson 
64602ac6454SAndrew Thompson /* minimum HUB descriptor (8-ports maximum) */
647760bc48eSAndrew Thompson struct usb_hub_descriptor_min {
64802ac6454SAndrew Thompson 	uByte	bDescLength;
64902ac6454SAndrew Thompson 	uByte	bDescriptorType;
65002ac6454SAndrew Thompson 	uByte	bNbrPorts;
65102ac6454SAndrew Thompson 	uWord	wHubCharacteristics;
65202ac6454SAndrew Thompson 	uByte	bPwrOn2PwrGood;
65302ac6454SAndrew Thompson 	uByte	bHubContrCurrent;
65402ac6454SAndrew Thompson 	uByte	DeviceRemovable[1];
65502ac6454SAndrew Thompson 	uByte	PortPowerCtrlMask[1];
65602ac6454SAndrew Thompson } __packed;
657760bc48eSAndrew Thompson typedef struct usb_hub_descriptor_min usb_hub_descriptor_min_t;
65802ac6454SAndrew Thompson 
659760bc48eSAndrew Thompson struct usb_device_qualifier {
66002ac6454SAndrew Thompson 	uByte	bLength;
66102ac6454SAndrew Thompson 	uByte	bDescriptorType;
66202ac6454SAndrew Thompson 	uWord	bcdUSB;
66302ac6454SAndrew Thompson 	uByte	bDeviceClass;
66402ac6454SAndrew Thompson 	uByte	bDeviceSubClass;
66502ac6454SAndrew Thompson 	uByte	bDeviceProtocol;
66602ac6454SAndrew Thompson 	uByte	bMaxPacketSize0;
66702ac6454SAndrew Thompson 	uByte	bNumConfigurations;
66802ac6454SAndrew Thompson 	uByte	bReserved;
66902ac6454SAndrew Thompson } __packed;
670760bc48eSAndrew Thompson typedef struct usb_device_qualifier usb_device_qualifier_t;
67102ac6454SAndrew Thompson 
672760bc48eSAndrew Thompson struct usb_otg_descriptor {
67302ac6454SAndrew Thompson 	uByte	bLength;
67402ac6454SAndrew Thompson 	uByte	bDescriptorType;
67502ac6454SAndrew Thompson 	uByte	bmAttributes;
67602ac6454SAndrew Thompson #define	UOTG_SRP	0x01
67702ac6454SAndrew Thompson #define	UOTG_HNP	0x02
67802ac6454SAndrew Thompson } __packed;
679760bc48eSAndrew Thompson typedef struct usb_otg_descriptor usb_otg_descriptor_t;
68002ac6454SAndrew Thompson 
68102ac6454SAndrew Thompson /* OTG feature selectors */
68202ac6454SAndrew Thompson #define	UOTG_B_HNP_ENABLE	3
68302ac6454SAndrew Thompson #define	UOTG_A_HNP_SUPPORT	4
68402ac6454SAndrew Thompson #define	UOTG_A_ALT_HNP_SUPPORT	5
68502ac6454SAndrew Thompson 
686760bc48eSAndrew Thompson struct usb_status {
68702ac6454SAndrew Thompson 	uWord	wStatus;
68802ac6454SAndrew Thompson /* Device status flags */
68902ac6454SAndrew Thompson #define	UDS_SELF_POWERED		0x0001
69002ac6454SAndrew Thompson #define	UDS_REMOTE_WAKEUP		0x0002
69102ac6454SAndrew Thompson /* Endpoint status flags */
69202ac6454SAndrew Thompson #define	UES_HALT			0x0001
69302ac6454SAndrew Thompson } __packed;
694760bc48eSAndrew Thompson typedef struct usb_status usb_status_t;
69502ac6454SAndrew Thompson 
696760bc48eSAndrew Thompson struct usb_hub_status {
69702ac6454SAndrew Thompson 	uWord	wHubStatus;
69802ac6454SAndrew Thompson #define	UHS_LOCAL_POWER			0x0001
69902ac6454SAndrew Thompson #define	UHS_OVER_CURRENT		0x0002
70002ac6454SAndrew Thompson 	uWord	wHubChange;
70102ac6454SAndrew Thompson } __packed;
702760bc48eSAndrew Thompson typedef struct usb_hub_status usb_hub_status_t;
70302ac6454SAndrew Thompson 
704760bc48eSAndrew Thompson struct usb_port_status {
70502ac6454SAndrew Thompson 	uWord	wPortStatus;
70602ac6454SAndrew Thompson #define	UPS_CURRENT_CONNECT_STATUS	0x0001
70702ac6454SAndrew Thompson #define	UPS_PORT_ENABLED		0x0002
70802ac6454SAndrew Thompson #define	UPS_SUSPEND			0x0004
70902ac6454SAndrew Thompson #define	UPS_OVERCURRENT_INDICATOR	0x0008
71002ac6454SAndrew Thompson #define	UPS_RESET			0x0010
7114563ba7aSHans Petter Selasky #define	UPS_PORT_L1			0x0020	/* USB 2.0 only */
7127b039740SHans Petter Selasky /* The link-state bits are valid for Super-Speed USB HUBs */
7137b039740SHans Petter Selasky #define	UPS_PORT_LINK_STATE_GET(x)	(((x) >> 5) & 0xF)
7147b039740SHans Petter Selasky #define	UPS_PORT_LINK_STATE_SET(x)	(((x) & 0xF) << 5)
7157b039740SHans Petter Selasky #define	UPS_PORT_LS_U0		0x00
7167b039740SHans Petter Selasky #define	UPS_PORT_LS_U1		0x01
7177b039740SHans Petter Selasky #define	UPS_PORT_LS_U2		0x02
7187b039740SHans Petter Selasky #define	UPS_PORT_LS_U3		0x03
7197b039740SHans Petter Selasky #define	UPS_PORT_LS_SS_DIS	0x04
7207b039740SHans Petter Selasky #define	UPS_PORT_LS_RX_DET	0x05
7217b039740SHans Petter Selasky #define	UPS_PORT_LS_SS_INA	0x06
7227b039740SHans Petter Selasky #define	UPS_PORT_LS_POLL	0x07
7237b039740SHans Petter Selasky #define	UPS_PORT_LS_RECOVER	0x08
7247b039740SHans Petter Selasky #define	UPS_PORT_LS_HOT_RST	0x09
7257b039740SHans Petter Selasky #define	UPS_PORT_LS_COMP_MODE	0x0A
7267b039740SHans Petter Selasky #define	UPS_PORT_LS_LOOPBACK	0x0B
7273d09c7b3SHans Petter Selasky #define	UPS_PORT_LS_RESUME	0x0F
72802ac6454SAndrew Thompson #define	UPS_PORT_POWER			0x0100
7294131f6fbSHans Petter Selasky #define	UPS_PORT_POWER_SS		0x0200	/* super-speed only */
73002ac6454SAndrew Thompson #define	UPS_LOW_SPEED			0x0200
73102ac6454SAndrew Thompson #define	UPS_HIGH_SPEED			0x0400
7327b039740SHans Petter Selasky #define	UPS_OTHER_SPEED			0x0600	/* currently FreeBSD specific */
73302ac6454SAndrew Thompson #define	UPS_PORT_TEST			0x0800
73402ac6454SAndrew Thompson #define	UPS_PORT_INDICATOR		0x1000
73502ac6454SAndrew Thompson #define	UPS_PORT_MODE_DEVICE		0x8000	/* currently FreeBSD specific */
73602ac6454SAndrew Thompson 	uWord	wPortChange;
73702ac6454SAndrew Thompson #define	UPS_C_CONNECT_STATUS		0x0001
73802ac6454SAndrew Thompson #define	UPS_C_PORT_ENABLED		0x0002
73902ac6454SAndrew Thompson #define	UPS_C_SUSPEND			0x0004
74002ac6454SAndrew Thompson #define	UPS_C_OVERCURRENT_INDICATOR	0x0008
74102ac6454SAndrew Thompson #define	UPS_C_PORT_RESET		0x0010
7424563ba7aSHans Petter Selasky #define	UPS_C_PORT_L1			0x0020	/* USB 2.0 only */
7434563ba7aSHans Petter Selasky #define	UPS_C_BH_PORT_RESET		0x0020	/* USB 3.0 only */
7447b039740SHans Petter Selasky #define	UPS_C_PORT_LINK_STATE		0x0040
7457b039740SHans Petter Selasky #define	UPS_C_PORT_CONFIG_ERROR		0x0080
74602ac6454SAndrew Thompson } __packed;
747760bc48eSAndrew Thompson typedef struct usb_port_status usb_port_status_t;
74802ac6454SAndrew Thompson 
749ed6d949aSAndrew Thompson /*
750ed6d949aSAndrew Thompson  * The "USB_SPEED" macros defines all the supported USB speeds.
751ed6d949aSAndrew Thompson  */
752ed6d949aSAndrew Thompson enum usb_dev_speed {
753ed6d949aSAndrew Thompson 	USB_SPEED_VARIABLE,
754ed6d949aSAndrew Thompson 	USB_SPEED_LOW,
755ed6d949aSAndrew Thompson 	USB_SPEED_FULL,
756ed6d949aSAndrew Thompson 	USB_SPEED_HIGH,
757ed6d949aSAndrew Thompson 	USB_SPEED_SUPER,
758ed6d949aSAndrew Thompson };
759ed6d949aSAndrew Thompson #define	USB_SPEED_MAX	(USB_SPEED_SUPER+1)
760ed6d949aSAndrew Thompson 
761ed6d949aSAndrew Thompson /*
762ed6d949aSAndrew Thompson  * The "USB_REV" macros defines all the supported USB revisions.
763ed6d949aSAndrew Thompson  */
764ed6d949aSAndrew Thompson enum usb_revision {
765ed6d949aSAndrew Thompson 	USB_REV_UNKNOWN,
766ed6d949aSAndrew Thompson 	USB_REV_PRE_1_0,
767ed6d949aSAndrew Thompson 	USB_REV_1_0,
768ed6d949aSAndrew Thompson 	USB_REV_1_1,
769ed6d949aSAndrew Thompson 	USB_REV_2_0,
770ed6d949aSAndrew Thompson 	USB_REV_2_5,
771ed6d949aSAndrew Thompson 	USB_REV_3_0
772ed6d949aSAndrew Thompson };
773ed6d949aSAndrew Thompson #define	USB_REV_MAX	(USB_REV_3_0+1)
774ed6d949aSAndrew Thompson 
775ed6d949aSAndrew Thompson /*
776a5cf1aaaSHans Petter Selasky  * Supported host controller modes.
777ed6d949aSAndrew Thompson  */
778ed6d949aSAndrew Thompson enum usb_hc_mode {
779ed6d949aSAndrew Thompson 	USB_MODE_HOST,		/* initiates transfers */
780ed6d949aSAndrew Thompson 	USB_MODE_DEVICE,	/* bus transfer target */
781ed6d949aSAndrew Thompson 	USB_MODE_DUAL		/* can be host or device */
782ed6d949aSAndrew Thompson };
783ed6d949aSAndrew Thompson #define	USB_MODE_MAX	(USB_MODE_DUAL+1)
784ed6d949aSAndrew Thompson 
785ed6d949aSAndrew Thompson /*
786a5cf1aaaSHans Petter Selasky  * The "USB_STATE" enums define all the supported device states.
787ed6d949aSAndrew Thompson  */
788ed6d949aSAndrew Thompson enum usb_dev_state {
789ed6d949aSAndrew Thompson 	USB_STATE_DETACHED,
790ed6d949aSAndrew Thompson 	USB_STATE_ATTACHED,
791ed6d949aSAndrew Thompson 	USB_STATE_POWERED,
792ed6d949aSAndrew Thompson 	USB_STATE_ADDRESSED,
793ed6d949aSAndrew Thompson 	USB_STATE_CONFIGURED,
794ed6d949aSAndrew Thompson };
795ed6d949aSAndrew Thompson #define	USB_STATE_MAX	(USB_STATE_CONFIGURED+1)
796a5cf1aaaSHans Petter Selasky 
797a5cf1aaaSHans Petter Selasky /*
798a5cf1aaaSHans Petter Selasky  * The "USB_EP_MODE" macros define all the currently supported
799a5cf1aaaSHans Petter Selasky  * endpoint modes.
800a5cf1aaaSHans Petter Selasky  */
801a5cf1aaaSHans Petter Selasky enum usb_ep_mode {
802a5cf1aaaSHans Petter Selasky 	USB_EP_MODE_DEFAULT,
803a5cf1aaaSHans Petter Selasky 	USB_EP_MODE_STREAMS,	/* USB3.0 specific */
804a5cf1aaaSHans Petter Selasky 	USB_EP_MODE_HW_MASS_STORAGE,
805a5cf1aaaSHans Petter Selasky 	USB_EP_MODE_HW_SERIAL,
806a5cf1aaaSHans Petter Selasky 	USB_EP_MODE_HW_ETHERNET_CDC,
807a5cf1aaaSHans Petter Selasky 	USB_EP_MODE_HW_ETHERNET_NCM,
808a5cf1aaaSHans Petter Selasky 	USB_EP_MODE_MAX
809a5cf1aaaSHans Petter Selasky };
81075973647SAndrew Thompson #endif					/* _USB_STANDARD_H_ */
811