xref: /illumos-gate/usr/src/contrib/bhyve/dev/usb/usb.h (revision d0b3c59b)
14c87aefeSPatrick Mooney /* $FreeBSD$ */
24c87aefeSPatrick Mooney /*-
34c87aefeSPatrick Mooney  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
44c87aefeSPatrick Mooney  * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
54c87aefeSPatrick Mooney  * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
64c87aefeSPatrick Mooney  *
74c87aefeSPatrick Mooney  * Redistribution and use in source and binary forms, with or without
84c87aefeSPatrick Mooney  * modification, are permitted provided that the following conditions
94c87aefeSPatrick Mooney  * are met:
104c87aefeSPatrick Mooney  * 1. Redistributions of source code must retain the above copyright
114c87aefeSPatrick Mooney  *    notice, this list of conditions and the following disclaimer.
124c87aefeSPatrick Mooney  * 2. Redistributions in binary form must reproduce the above copyright
134c87aefeSPatrick Mooney  *    notice, this list of conditions and the following disclaimer in the
144c87aefeSPatrick Mooney  *    documentation and/or other materials provided with the distribution.
154c87aefeSPatrick Mooney  *
264c87aefeSPatrick Mooney  * SUCH DAMAGE.
274c87aefeSPatrick Mooney  */
284c87aefeSPatrick Mooney 
294c87aefeSPatrick Mooney /*
304c87aefeSPatrick Mooney  * This file contains standard definitions for the following USB
314c87aefeSPatrick Mooney  * protocol versions:
324c87aefeSPatrick Mooney  *
334c87aefeSPatrick Mooney  * USB v1.0
344c87aefeSPatrick Mooney  * USB v1.1
354c87aefeSPatrick Mooney  * USB v2.0
364c87aefeSPatrick Mooney  * USB v3.0
374c87aefeSPatrick Mooney  */
384c87aefeSPatrick Mooney 
394c87aefeSPatrick Mooney #ifndef _USB_STANDARD_H_
404c87aefeSPatrick Mooney #define	_USB_STANDARD_H_
414c87aefeSPatrick Mooney 
424c87aefeSPatrick Mooney #if defined(_KERNEL)
434c87aefeSPatrick Mooney #ifndef USB_GLOBAL_INCLUDE_FILE
444c87aefeSPatrick Mooney #include "opt_usb.h"
454c87aefeSPatrick Mooney #endif
464c87aefeSPatrick Mooney 
474c87aefeSPatrick Mooney /* Declare parent SYSCTL USB node. */
484c87aefeSPatrick Mooney #ifdef SYSCTL_DECL
494c87aefeSPatrick Mooney SYSCTL_DECL(_hw_usb);
504c87aefeSPatrick Mooney #endif
514c87aefeSPatrick Mooney 
524c87aefeSPatrick Mooney #ifndef USB_GLOBAL_INCLUDE_FILE
534c87aefeSPatrick Mooney #include <sys/malloc.h>
544c87aefeSPatrick Mooney #endif
554c87aefeSPatrick Mooney 
564c87aefeSPatrick Mooney MALLOC_DECLARE(M_USB);
574c87aefeSPatrick Mooney MALLOC_DECLARE(M_USBDEV);
584c87aefeSPatrick Mooney #endif /* _KERNEL */
594c87aefeSPatrick Mooney 
604c87aefeSPatrick Mooney #ifndef USB_GLOBAL_INCLUDE_FILE
614c87aefeSPatrick Mooney #include <dev/usb/usb_endian.h>
624c87aefeSPatrick Mooney #include <dev/usb/usb_freebsd.h>
634c87aefeSPatrick Mooney #endif
644c87aefeSPatrick Mooney 
654c87aefeSPatrick Mooney #define	USB_STACK_VERSION 2000		/* 2.0 */
664c87aefeSPatrick Mooney 
674c87aefeSPatrick Mooney /* Definition of some hardcoded USB constants. */
684c87aefeSPatrick Mooney 
694c87aefeSPatrick Mooney #define	USB_MAX_IPACKET		8	/* initial USB packet size */
704c87aefeSPatrick Mooney #define	USB_EP_MAX (2*16)		/* hardcoded */
714c87aefeSPatrick Mooney #define	USB_ROOT_HUB_ADDR 1		/* index */
724c87aefeSPatrick Mooney #define	USB_MIN_DEVICES 2		/* unused + root HUB */
734c87aefeSPatrick Mooney #define	USB_UNCONFIG_INDEX 0xFF		/* internal use only */
744c87aefeSPatrick Mooney #define	USB_IFACE_INDEX_ANY 0xFF	/* internal use only */
754c87aefeSPatrick Mooney #define	USB_START_ADDR 0		/* default USB device BUS address
764c87aefeSPatrick Mooney 					 * after USB bus reset */
774c87aefeSPatrick Mooney #define	USB_CONTROL_ENDPOINT 0		/* default control endpoint */
784c87aefeSPatrick Mooney 
794c87aefeSPatrick Mooney #define	USB_FRAMES_PER_SECOND_FS 1000	/* full speed */
804c87aefeSPatrick Mooney #define	USB_FRAMES_PER_SECOND_HS 8000	/* high speed */
814c87aefeSPatrick Mooney 
824c87aefeSPatrick Mooney #define	USB_FS_BYTES_PER_HS_UFRAME 188	/* bytes */
834c87aefeSPatrick Mooney #define	USB_HS_MICRO_FRAMES_MAX 8	/* units */
844c87aefeSPatrick Mooney 
854c87aefeSPatrick Mooney #define	USB_ISOC_TIME_MAX 128		/* ms */
864c87aefeSPatrick Mooney 
874c87aefeSPatrick Mooney /*
884c87aefeSPatrick Mooney  * Minimum time a device needs to be powered down to go through a
894c87aefeSPatrick Mooney  * power cycle. These values are not in the USB specification.
904c87aefeSPatrick Mooney  */
914c87aefeSPatrick Mooney #define	USB_POWER_DOWN_TIME	200	/* ms */
924c87aefeSPatrick Mooney #define	USB_PORT_POWER_DOWN_TIME	100	/* ms */
934c87aefeSPatrick Mooney 
944c87aefeSPatrick Mooney /* Definition of software USB power modes */
954c87aefeSPatrick Mooney #define	USB_POWER_MODE_OFF 0		/* turn off device */
964c87aefeSPatrick Mooney #define	USB_POWER_MODE_ON 1		/* always on */
974c87aefeSPatrick Mooney #define	USB_POWER_MODE_SAVE 2		/* automatic suspend and resume */
984c87aefeSPatrick Mooney #define	USB_POWER_MODE_SUSPEND 3	/* force suspend */
994c87aefeSPatrick Mooney #define	USB_POWER_MODE_RESUME 4		/* force resume */
1004c87aefeSPatrick Mooney 
1014c87aefeSPatrick Mooney /* These are the values from the USB specification. */
1024c87aefeSPatrick Mooney #define	USB_PORT_RESET_DELAY_SPEC	10	/* ms */
1034c87aefeSPatrick Mooney #define	USB_PORT_ROOT_RESET_DELAY_SPEC	50	/* ms */
1044c87aefeSPatrick Mooney #define	USB_PORT_RESET_RECOVERY_SPEC	10	/* ms */
1054c87aefeSPatrick Mooney #define	USB_PORT_POWERUP_DELAY_SPEC	100	/* ms */
1064c87aefeSPatrick Mooney #define	USB_PORT_RESUME_DELAY_SPEC	20	/* ms */
1074c87aefeSPatrick Mooney #define	USB_SET_ADDRESS_SETTLE_SPEC	2	/* ms */
1084c87aefeSPatrick Mooney #define	USB_RESUME_DELAY_SPEC		(20*5)	/* ms */
1094c87aefeSPatrick Mooney #define	USB_RESUME_WAIT_SPEC		10	/* ms */
1104c87aefeSPatrick Mooney #define	USB_RESUME_RECOVERY_SPEC	10	/* ms */
1114c87aefeSPatrick Mooney #define	USB_EXTRA_POWER_UP_TIME_SPEC	0	/* ms */
1124c87aefeSPatrick Mooney 
1134c87aefeSPatrick Mooney /* Allow for marginal and non-conforming devices. */
1144c87aefeSPatrick Mooney #define	USB_PORT_RESET_DELAY		50	/* ms */
1154c87aefeSPatrick Mooney #define	USB_PORT_ROOT_RESET_DELAY	200	/* ms */
1164c87aefeSPatrick Mooney #define	USB_PORT_RESET_RECOVERY		250	/* ms */
1174c87aefeSPatrick Mooney #define	USB_PORT_POWERUP_DELAY		300	/* ms */
1184c87aefeSPatrick Mooney #define	USB_PORT_RESUME_DELAY		(20*2)	/* ms */
1194c87aefeSPatrick Mooney #define	USB_SET_ADDRESS_SETTLE		10	/* ms */
1204c87aefeSPatrick Mooney #define	USB_RESUME_DELAY		(50*5)	/* ms */
1214c87aefeSPatrick Mooney #define	USB_RESUME_WAIT			50	/* ms */
1224c87aefeSPatrick Mooney #define	USB_RESUME_RECOVERY		50	/* ms */
1234c87aefeSPatrick Mooney #define	USB_EXTRA_POWER_UP_TIME		20	/* ms */
1244c87aefeSPatrick Mooney 
1254c87aefeSPatrick Mooney #define	USB_MIN_POWER		100	/* mA */
1264c87aefeSPatrick Mooney #define	USB_MAX_POWER		500	/* mA */
1274c87aefeSPatrick Mooney 
1284c87aefeSPatrick Mooney #define	USB_BUS_RESET_DELAY	100	/* ms */
1294c87aefeSPatrick Mooney 
1304c87aefeSPatrick Mooney /*
1314c87aefeSPatrick Mooney  * USB record layout in memory:
1324c87aefeSPatrick Mooney  *
1334c87aefeSPatrick Mooney  * - USB config 0
1344c87aefeSPatrick Mooney  *   - USB interfaces
1354c87aefeSPatrick Mooney  *     - USB alternative interfaces
1364c87aefeSPatrick Mooney  *       - USB endpoints
1374c87aefeSPatrick Mooney  *
1384c87aefeSPatrick Mooney  * - USB config 1
1394c87aefeSPatrick Mooney  *   - USB interfaces
1404c87aefeSPatrick Mooney  *     - USB alternative interfaces
1414c87aefeSPatrick Mooney  *       - USB endpoints
1424c87aefeSPatrick Mooney  */
1434c87aefeSPatrick Mooney 
1444c87aefeSPatrick Mooney /* Declaration of USB records */
1454c87aefeSPatrick Mooney 
1464c87aefeSPatrick Mooney struct usb_device_request {
1474c87aefeSPatrick Mooney 	uByte	bmRequestType;
1484c87aefeSPatrick Mooney 	uByte	bRequest;
1494c87aefeSPatrick Mooney 	uWord	wValue;
1504c87aefeSPatrick Mooney 	uWord	wIndex;
1514c87aefeSPatrick Mooney 	uWord	wLength;
1524c87aefeSPatrick Mooney } __packed;
1534c87aefeSPatrick Mooney typedef struct usb_device_request usb_device_request_t;
1544c87aefeSPatrick Mooney 
1554c87aefeSPatrick Mooney #define	UT_WRITE		0x00
1564c87aefeSPatrick Mooney #define	UT_READ			0x80
1574c87aefeSPatrick Mooney #define	UT_STANDARD		0x00
1584c87aefeSPatrick Mooney #define	UT_CLASS		0x20
1594c87aefeSPatrick Mooney #define	UT_VENDOR		0x40
1604c87aefeSPatrick Mooney #define	UT_DEVICE		0x00
1614c87aefeSPatrick Mooney #define	UT_INTERFACE		0x01
1624c87aefeSPatrick Mooney #define	UT_ENDPOINT		0x02
1634c87aefeSPatrick Mooney #define	UT_OTHER		0x03
1644c87aefeSPatrick Mooney 
1654c87aefeSPatrick Mooney #define	UT_READ_DEVICE		(UT_READ  | UT_STANDARD | UT_DEVICE)
1664c87aefeSPatrick Mooney #define	UT_READ_INTERFACE	(UT_READ  | UT_STANDARD | UT_INTERFACE)
1674c87aefeSPatrick Mooney #define	UT_READ_ENDPOINT	(UT_READ  | UT_STANDARD | UT_ENDPOINT)
1684c87aefeSPatrick Mooney #define	UT_WRITE_DEVICE		(UT_WRITE | UT_STANDARD | UT_DEVICE)
1704c87aefeSPatrick Mooney #define	UT_WRITE_ENDPOINT	(UT_WRITE | UT_STANDARD | UT_ENDPOINT)
1714c87aefeSPatrick Mooney #define	UT_READ_CLASS_DEVICE	(UT_READ  | UT_CLASS | UT_DEVICE)
1724c87aefeSPatrick Mooney #define	UT_READ_CLASS_INTERFACE	(UT_READ  | UT_CLASS | UT_INTERFACE)
1734c87aefeSPatrick Mooney #define	UT_READ_CLASS_OTHER	(UT_READ  | UT_CLASS | UT_OTHER)
1744c87aefeSPatrick Mooney #define	UT_READ_CLASS_ENDPOINT	(UT_READ  | UT_CLASS | UT_ENDPOINT)
1754c87aefeSPatrick Mooney #define	UT_WRITE_CLASS_DEVICE	(UT_WRITE | UT_CLASS | UT_DEVICE)
1774c87aefeSPatrick Mooney #define	UT_WRITE_CLASS_OTHER	(UT_WRITE | UT_CLASS | UT_OTHER)
1784c87aefeSPatrick Mooney #define	UT_WRITE_CLASS_ENDPOINT	(UT_WRITE | UT_CLASS | UT_ENDPOINT)
1794c87aefeSPatrick Mooney #define	UT_READ_VENDOR_DEVICE	(UT_READ  | UT_VENDOR | UT_DEVICE)
1814c87aefeSPatrick Mooney #define	UT_READ_VENDOR_OTHER	(UT_READ  | UT_VENDOR | UT_OTHER)
1824c87aefeSPatrick Mooney #define	UT_READ_VENDOR_ENDPOINT	(UT_READ  | UT_VENDOR | UT_ENDPOINT)
1834c87aefeSPatrick Mooney #define	UT_WRITE_VENDOR_DEVICE	(UT_WRITE | UT_VENDOR | UT_DEVICE)
1854c87aefeSPatrick Mooney #define	UT_WRITE_VENDOR_OTHER	(UT_WRITE | UT_VENDOR | UT_OTHER)
1874c87aefeSPatrick Mooney 
1884c87aefeSPatrick Mooney /* Requests */
1894c87aefeSPatrick Mooney #define	UR_GET_STATUS		0x00
1904c87aefeSPatrick Mooney #define	UR_CLEAR_FEATURE	0x01
1914c87aefeSPatrick Mooney #define	UR_SET_FEATURE		0x03
1924c87aefeSPatrick Mooney #define	UR_SET_ADDRESS		0x05
1934c87aefeSPatrick Mooney #define	UR_GET_DESCRIPTOR	0x06
1944c87aefeSPatrick Mooney #define	UDESC_DEVICE		0x01
1954c87aefeSPatrick Mooney #define	UDESC_CONFIG		0x02
1964c87aefeSPatrick Mooney #define	UDESC_STRING		0x03
1974c87aefeSPatrick Mooney #define	USB_LANGUAGE_TABLE	0x00	/* language ID string index */
1984c87aefeSPatrick Mooney #define	UDESC_INTERFACE		0x04
1994c87aefeSPatrick Mooney #define	UDESC_ENDPOINT		0x05
2004c87aefeSPatrick Mooney #define	UDESC_DEVICE_QUALIFIER	0x06
2014c87aefeSPatrick Mooney #define	UDESC_OTHER_SPEED_CONFIGURATION 0x07
2024c87aefeSPatrick Mooney #define	UDESC_INTERFACE_POWER	0x08
2034c87aefeSPatrick Mooney #define	UDESC_OTG		0x09
2044c87aefeSPatrick Mooney #define	UDESC_DEBUG		0x0A
2054c87aefeSPatrick Mooney #define	UDESC_IFACE_ASSOC	0x0B	/* interface association */
2064c87aefeSPatrick Mooney #define	UDESC_BOS		0x0F	/* binary object store */
2074c87aefeSPatrick Mooney #define	UDESC_DEVICE_CAPABILITY	0x10
2084c87aefeSPatrick Mooney #define	UDESC_CS_DEVICE		0x21	/* class specific */
2094c87aefeSPatrick Mooney #define	UDESC_CS_CONFIG		0x22
2104c87aefeSPatrick Mooney #define	UDESC_CS_STRING		0x23
2114c87aefeSPatrick Mooney #define	UDESC_CS_INTERFACE	0x24
2124c87aefeSPatrick Mooney #define	UDESC_CS_ENDPOINT	0x25
2134c87aefeSPatrick Mooney #define	UDESC_HUB		0x29
2144c87aefeSPatrick Mooney #define	UDESC_SS_HUB		0x2A	/* super speed */
2154c87aefeSPatrick Mooney #define	UDESC_ENDPOINT_SS_COMP	0x30	/* super speed */
2164c87aefeSPatrick Mooney #define	UR_SET_DESCRIPTOR	0x07
2174c87aefeSPatrick Mooney #define	UR_GET_CONFIG		0x08
2184c87aefeSPatrick Mooney #define	UR_SET_CONFIG		0x09
2194c87aefeSPatrick Mooney #define	UR_GET_INTERFACE	0x0a
2204c87aefeSPatrick Mooney #define	UR_SET_INTERFACE	0x0b
2214c87aefeSPatrick Mooney #define	UR_SYNCH_FRAME		0x0c
2224c87aefeSPatrick Mooney #define	UR_SET_SEL		0x30
2234c87aefeSPatrick Mooney #define	UR_ISOCH_DELAY		0x31
2244c87aefeSPatrick Mooney 
2254c87aefeSPatrick Mooney /* HUB specific request */
2264c87aefeSPatrick Mooney #define	UR_GET_BUS_STATE	0x02
2274c87aefeSPatrick Mooney #define	UR_CLEAR_TT_BUFFER	0x08
2284c87aefeSPatrick Mooney #define	UR_RESET_TT		0x09
2294c87aefeSPatrick Mooney #define	UR_GET_TT_STATE		0x0a
2304c87aefeSPatrick Mooney #define	UR_STOP_TT		0x0b
2314c87aefeSPatrick Mooney #define	UR_SET_AND_TEST		0x0c	/* USB 2.0 only */
2324c87aefeSPatrick Mooney #define	UR_SET_HUB_DEPTH	0x0c	/* USB 3.0 only */
2334c87aefeSPatrick Mooney #define	USB_SS_HUB_DEPTH_MAX	5
2344c87aefeSPatrick Mooney #define	UR_GET_PORT_ERR_COUNT	0x0d
2354c87aefeSPatrick Mooney 
2364c87aefeSPatrick Mooney /* Feature numbers */
2374c87aefeSPatrick Mooney #define	UF_ENDPOINT_HALT	0
2384c87aefeSPatrick Mooney #define	UF_DEVICE_REMOTE_WAKEUP	1
2394c87aefeSPatrick Mooney #define	UF_TEST_MODE		2
2404c87aefeSPatrick Mooney #define	UF_U1_ENABLE		0x30
2414c87aefeSPatrick Mooney #define	UF_U2_ENABLE		0x31
2424c87aefeSPatrick Mooney #define	UF_LTM_ENABLE		0x32
2434c87aefeSPatrick Mooney 
2444c87aefeSPatrick Mooney /* HUB specific features */
2454c87aefeSPatrick Mooney #define	UHF_C_HUB_LOCAL_POWER	0
2464c87aefeSPatrick Mooney #define	UHF_C_HUB_OVER_CURRENT	1
2474c87aefeSPatrick Mooney #define	UHF_PORT_CONNECTION	0
2484c87aefeSPatrick Mooney #define	UHF_PORT_ENABLE		1
2494c87aefeSPatrick Mooney #define	UHF_PORT_SUSPEND	2
2504c87aefeSPatrick Mooney #define	UHF_PORT_OVER_CURRENT	3
2514c87aefeSPatrick Mooney #define	UHF_PORT_RESET		4
2524c87aefeSPatrick Mooney #define	UHF_PORT_LINK_STATE	5
2534c87aefeSPatrick Mooney #define	UHF_PORT_POWER		8
2544c87aefeSPatrick Mooney #define	UHF_PORT_LOW_SPEED	9
2554c87aefeSPatrick Mooney #define	UHF_PORT_L1		10
2564c87aefeSPatrick Mooney #define	UHF_C_PORT_CONNECTION	16
2574c87aefeSPatrick Mooney #define	UHF_C_PORT_ENABLE	17
2584c87aefeSPatrick Mooney #define	UHF_C_PORT_SUSPEND	18
2594c87aefeSPatrick Mooney #define	UHF_C_PORT_OVER_CURRENT	19
2604c87aefeSPatrick Mooney #define	UHF_C_PORT_RESET	20
2614c87aefeSPatrick Mooney #define	UHF_PORT_TEST		21
2624c87aefeSPatrick Mooney #define	UHF_PORT_INDICATOR	22
2634c87aefeSPatrick Mooney #define	UHF_C_PORT_L1		23
2644c87aefeSPatrick Mooney 
2654c87aefeSPatrick Mooney /* SuperSpeed HUB specific features */
2664c87aefeSPatrick Mooney #define	UHF_PORT_U1_TIMEOUT	23
2674c87aefeSPatrick Mooney #define	UHF_PORT_U2_TIMEOUT	24
2684c87aefeSPatrick Mooney #define	UHF_C_PORT_LINK_STATE	25
2694c87aefeSPatrick Mooney #define	UHF_C_PORT_CONFIG_ERROR	26
2704c87aefeSPatrick Mooney #define	UHF_PORT_REMOTE_WAKE_MASK	27
2714c87aefeSPatrick Mooney #define	UHF_BH_PORT_RESET	28
2724c87aefeSPatrick Mooney #define	UHF_C_BH_PORT_RESET	29
2734c87aefeSPatrick Mooney #define	UHF_FORCE_LINKPM_ACCEPT	30
2744c87aefeSPatrick Mooney 
2754c87aefeSPatrick Mooney struct usb_descriptor {
2764c87aefeSPatrick Mooney 	uByte	bLength;
2774c87aefeSPatrick Mooney 	uByte	bDescriptorType;
2784c87aefeSPatrick Mooney 	uByte	bDescriptorSubtype;
2794c87aefeSPatrick Mooney } __packed;
2804c87aefeSPatrick Mooney typedef struct usb_descriptor usb_descriptor_t;
2814c87aefeSPatrick Mooney 
2824c87aefeSPatrick Mooney struct usb_device_descriptor {
2834c87aefeSPatrick Mooney 	uByte	bLength;
2844c87aefeSPatrick Mooney 	uByte	bDescriptorType;
2854c87aefeSPatrick Mooney 	uWord	bcdUSB;
2864c87aefeSPatrick Mooney #define	UD_USB_2_0		0x0200
2874c87aefeSPatrick Mooney #define	UD_USB_3_0		0x0300
2884c87aefeSPatrick Mooney #define	UD_IS_USB2(d) ((d)->bcdUSB[1] == 0x02)
2894c87aefeSPatrick Mooney #define	UD_IS_USB3(d) ((d)->bcdUSB[1] == 0x03)
2904c87aefeSPatrick Mooney 	uByte	bDeviceClass;
2914c87aefeSPatrick Mooney 	uByte	bDeviceSubClass;
2924c87aefeSPatrick Mooney 	uByte	bDeviceProtocol;
2934c87aefeSPatrick Mooney 	uByte	bMaxPacketSize;
2944c87aefeSPatrick Mooney 	/* The fields below are not part of the initial descriptor. */
2954c87aefeSPatrick Mooney 	uWord	idVendor;
2964c87aefeSPatrick Mooney 	uWord	idProduct;
2974c87aefeSPatrick Mooney 	uWord	bcdDevice;
2984c87aefeSPatrick Mooney 	uByte	iManufacturer;
2994c87aefeSPatrick Mooney 	uByte	iProduct;
3004c87aefeSPatrick Mooney 	uByte	iSerialNumber;
3014c87aefeSPatrick Mooney 	uByte	bNumConfigurations;
3024c87aefeSPatrick Mooney } __packed;
3034c87aefeSPatrick Mooney typedef struct usb_device_descriptor usb_device_descriptor_t;
3044c87aefeSPatrick Mooney 
3054c87aefeSPatrick Mooney /* Binary Device Object Store (BOS) */
3064c87aefeSPatrick Mooney struct usb_bos_descriptor {
3074c87aefeSPatrick Mooney 	uByte	bLength;
3084c87aefeSPatrick Mooney 	uByte	bDescriptorType;
3094c87aefeSPatrick Mooney 	uWord	wTotalLength;
3104c87aefeSPatrick Mooney 	uByte	bNumDeviceCaps;
3114c87aefeSPatrick Mooney } __packed;
3124c87aefeSPatrick Mooney typedef struct usb_bos_descriptor usb_bos_descriptor_t;
3134c87aefeSPatrick Mooney 
3144c87aefeSPatrick Mooney /* Binary Device Object Store Capability */
3154c87aefeSPatrick Mooney struct usb_bos_cap_descriptor {
3164c87aefeSPatrick Mooney 	uByte	bLength;
3174c87aefeSPatrick Mooney 	uByte	bDescriptorType;
3184c87aefeSPatrick Mooney 	uByte	bDevCapabilityType;
3194c87aefeSPatrick Mooney #define	USB_DEVCAP_RESERVED	0x00
3204c87aefeSPatrick Mooney #define	USB_DEVCAP_WUSB		0x01
3214c87aefeSPatrick Mooney #define	USB_DEVCAP_USB2EXT	0x02
3224c87aefeSPatrick Mooney #define	USB_DEVCAP_SUPER_SPEED	0x03
3234c87aefeSPatrick Mooney #define	USB_DEVCAP_CONTAINER_ID	0x04
3244c87aefeSPatrick Mooney 	/* data ... */
3254c87aefeSPatrick Mooney } __packed;
3264c87aefeSPatrick Mooney typedef struct usb_bos_cap_descriptor usb_bos_cap_descriptor_t;
3274c87aefeSPatrick Mooney 
3284c87aefeSPatrick Mooney struct usb_devcap_usb2ext_descriptor {
3294c87aefeSPatrick Mooney 	uByte	bLength;
3304c87aefeSPatrick Mooney 	uByte	bDescriptorType;
3314c87aefeSPatrick Mooney 	uByte	bDevCapabilityType;
3324c87aefeSPatrick Mooney 	uDWord	bmAttributes;
3334c87aefeSPatrick Mooney #define	USB_V2EXT_LPM (1U << 1)
3344c87aefeSPatrick Mooney #define	USB_V2EXT_BESL_SUPPORTED (1U << 2)
3354c87aefeSPatrick Mooney #define	USB_V2EXT_BESL_BASELINE_VALID (1U << 3)
3364c87aefeSPatrick Mooney #define	USB_V2EXT_BESL_DEEP_VALID (1U << 4)
3374c87aefeSPatrick Mooney #define	USB_V2EXT_BESL_BASELINE_GET(x) (((x) >> 8) & 0xF)
3384c87aefeSPatrick Mooney #define	USB_V2EXT_BESL_DEEP_GET(x) (((x) >> 12) & 0xF)
3394c87aefeSPatrick Mooney } __packed;
3404c87aefeSPatrick Mooney typedef struct usb_devcap_usb2ext_descriptor usb_devcap_usb2ext_descriptor_t;
3414c87aefeSPatrick Mooney 
3424c87aefeSPatrick Mooney struct usb_devcap_ss_descriptor {
3434c87aefeSPatrick Mooney 	uByte	bLength;
3444c87aefeSPatrick Mooney 	uByte	bDescriptorType;
3454c87aefeSPatrick Mooney 	uByte	bDevCapabilityType;
3464c87aefeSPatrick Mooney 	uByte	bmAttributes;
3474c87aefeSPatrick Mooney 	uWord	wSpeedsSupported;
3484c87aefeSPatrick Mooney 	uByte	bFunctionalitySupport;
3494c87aefeSPatrick Mooney 	uByte	bU1DevExitLat;
3504c87aefeSPatrick Mooney 	uWord	wU2DevExitLat;
3514c87aefeSPatrick Mooney } __packed;
3524c87aefeSPatrick Mooney typedef struct usb_devcap_ss_descriptor usb_devcap_ss_descriptor_t;
3534c87aefeSPatrick Mooney 
3544c87aefeSPatrick Mooney struct usb_devcap_container_id_descriptor {
3554c87aefeSPatrick Mooney 	uByte	bLength;
3564c87aefeSPatrick Mooney 	uByte	bDescriptorType;
3574c87aefeSPatrick Mooney 	uByte	bDevCapabilityType;
3584c87aefeSPatrick Mooney 	uByte	bReserved;
3594c87aefeSPatrick Mooney 	uByte	bContainerID;
3604c87aefeSPatrick Mooney } __packed;
3614c87aefeSPatrick Mooney typedef struct usb_devcap_container_id_descriptor
3624c87aefeSPatrick Mooney 		usb_devcap_container_id_descriptor_t;
3634c87aefeSPatrick Mooney 
3644c87aefeSPatrick Mooney /* Device class codes */
3654c87aefeSPatrick Mooney #define	UDCLASS_IN_INTERFACE	0x00
3664c87aefeSPatrick Mooney #define	UDCLASS_COMM		0x02
3674c87aefeSPatrick Mooney #define	UDCLASS_HUB		0x09
3684c87aefeSPatrick Mooney #define	UDSUBCLASS_HUB		0x00
3694c87aefeSPatrick Mooney #define	UDPROTO_FSHUB		0x00
3704c87aefeSPatrick Mooney #define	UDPROTO_HSHUBSTT	0x01
3714c87aefeSPatrick Mooney #define	UDPROTO_HSHUBMTT	0x02
3724c87aefeSPatrick Mooney #define	UDPROTO_SSHUB		0x03
3734c87aefeSPatrick Mooney #define	UDCLASS_DIAGNOSTIC	0xdc
3744c87aefeSPatrick Mooney #define	UDCLASS_WIRELESS	0xe0
3754c87aefeSPatrick Mooney #define	UDSUBCLASS_RF		0x01
3764c87aefeSPatrick Mooney #define	UDPROTO_BLUETOOTH	0x01
3774c87aefeSPatrick Mooney #define	UDCLASS_VENDOR		0xff
3784c87aefeSPatrick Mooney 
3794c87aefeSPatrick Mooney struct usb_config_descriptor {
3804c87aefeSPatrick Mooney 	uByte	bLength;
3814c87aefeSPatrick Mooney 	uByte	bDescriptorType;
3824c87aefeSPatrick Mooney 	uWord	wTotalLength;
3834c87aefeSPatrick Mooney 	uByte	bNumInterface;
3844c87aefeSPatrick Mooney 	uByte	bConfigurationValue;
3854c87aefeSPatrick Mooney #define	USB_UNCONFIG_NO 0
3864c87aefeSPatrick Mooney 	uByte	iConfiguration;
3874c87aefeSPatrick Mooney 	uByte	bmAttributes;
3884c87aefeSPatrick Mooney #define	UC_BUS_POWERED		0x80
3894c87aefeSPatrick Mooney #define	UC_SELF_POWERED		0x40
3904c87aefeSPatrick Mooney #define	UC_REMOTE_WAKEUP	0x20
3914c87aefeSPatrick Mooney 	uByte	bMaxPower;		/* max current in 2 mA units */
3924c87aefeSPatrick Mooney #define	UC_POWER_FACTOR 2
3934c87aefeSPatrick Mooney } __packed;
3944c87aefeSPatrick Mooney typedef struct usb_config_descriptor usb_config_descriptor_t;
3954c87aefeSPatrick Mooney 
3964c87aefeSPatrick Mooney struct usb_interface_descriptor {
3974c87aefeSPatrick Mooney 	uByte	bLength;
3984c87aefeSPatrick Mooney 	uByte	bDescriptorType;
3994c87aefeSPatrick Mooney 	uByte	bInterfaceNumber;
4004c87aefeSPatrick Mooney 	uByte	bAlternateSetting;
4014c87aefeSPatrick Mooney 	uByte	bNumEndpoints;
4024c87aefeSPatrick Mooney 	uByte	bInterfaceClass;
4034c87aefeSPatrick Mooney 	uByte	bInterfaceSubClass;
4044c87aefeSPatrick Mooney 	uByte	bInterfaceProtocol;
4054c87aefeSPatrick Mooney 	uByte	iInterface;
4064c87aefeSPatrick Mooney } __packed;
4074c87aefeSPatrick Mooney typedef struct usb_interface_descriptor usb_interface_descriptor_t;
4084c87aefeSPatrick Mooney 
4094c87aefeSPatrick Mooney struct usb_interface_assoc_descriptor {
4104c87aefeSPatrick Mooney 	uByte	bLength;
4114c87aefeSPatrick Mooney 	uByte	bDescriptorType;
4124c87aefeSPatrick Mooney 	uByte	bFirstInterface;
4134c87aefeSPatrick Mooney 	uByte	bInterfaceCount;
4144c87aefeSPatrick Mooney 	uByte	bFunctionClass;
4154c87aefeSPatrick Mooney 	uByte	bFunctionSubClass;
4164c87aefeSPatrick Mooney 	uByte	bFunctionProtocol;
4174c87aefeSPatrick Mooney 	uByte	iFunction;
4184c87aefeSPatrick Mooney } __packed;
4194c87aefeSPatrick Mooney typedef struct usb_interface_assoc_descriptor usb_interface_assoc_descriptor_t;
4204c87aefeSPatrick Mooney 
4214c87aefeSPatrick Mooney /* Interface class codes */
4224c87aefeSPatrick Mooney #define	UICLASS_UNSPEC		0x00
4234c87aefeSPatrick Mooney #define	UICLASS_AUDIO		0x01	/* audio */
4244c87aefeSPatrick Mooney #define	UISUBCLASS_AUDIOCONTROL	1
4254c87aefeSPatrick Mooney #define	UISUBCLASS_AUDIOSTREAM		2
4264c87aefeSPatrick Mooney #define	UISUBCLASS_MIDISTREAM		3
4274c87aefeSPatrick Mooney 
4284c87aefeSPatrick Mooney #define	UICLASS_CDC		0x02	/* communication */
4294c87aefeSPatrick Mooney #define	UISUBCLASS_DIRECT_LINE_CONTROL_MODEL	1
4304c87aefeSPatrick Mooney #define	UISUBCLASS_ABSTRACT_CONTROL_MODEL	2
4314c87aefeSPatrick Mooney #define	UISUBCLASS_TELEPHONE_CONTROL_MODEL	3
4324c87aefeSPatrick Mooney #define	UISUBCLASS_MULTICHANNEL_CONTROL_MODEL	4
4334c87aefeSPatrick Mooney #define	UISUBCLASS_CAPI_CONTROLMODEL		5
4354c87aefeSPatrick Mooney #define	UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
4364c87aefeSPatrick Mooney #define	UISUBCLASS_WIRELESS_HANDSET_CM 8
4374c87aefeSPatrick Mooney #define	UISUBCLASS_DEVICE_MGMT 9
4384c87aefeSPatrick Mooney #define	UISUBCLASS_MOBILE_DIRECT_LINE_MODEL 10
4394c87aefeSPatrick Mooney #define	UISUBCLASS_OBEX 11
4404c87aefeSPatrick Mooney #define	UISUBCLASS_ETHERNET_EMULATION_MODEL 12
4414c87aefeSPatrick Mooney #define	UISUBCLASS_NETWORK_CONTROL_MODEL 13
4424c87aefeSPatrick Mooney 
4434c87aefeSPatrick Mooney #define	UIPROTO_CDC_NONE		0
4444c87aefeSPatrick Mooney #define	UIPROTO_CDC_AT			1
4454c87aefeSPatrick Mooney 
4464c87aefeSPatrick Mooney #define	UICLASS_HID		0x03
4474c87aefeSPatrick Mooney #define	UISUBCLASS_BOOT		1
4484c87aefeSPatrick Mooney #define	UIPROTO_BOOT_KEYBOARD	1
4494c87aefeSPatrick Mooney #define	UIPROTO_MOUSE		2
4504c87aefeSPatrick Mooney 
4514c87aefeSPatrick Mooney #define	UICLASS_PHYSICAL	0x05
4524c87aefeSPatrick Mooney #define	UICLASS_IMAGE		0x06
4534c87aefeSPatrick Mooney #define	UISUBCLASS_SIC		1	/* still image class */
4544c87aefeSPatrick Mooney #define	UICLASS_PRINTER		0x07
4554c87aefeSPatrick Mooney #define	UISUBCLASS_PRINTER	1
4564c87aefeSPatrick Mooney #define	UIPROTO_PRINTER_UNI	1
4574c87aefeSPatrick Mooney #define	UIPROTO_PRINTER_BI	2
4584c87aefeSPatrick Mooney #define	UIPROTO_PRINTER_1284	3
4594c87aefeSPatrick Mooney 
4604c87aefeSPatrick Mooney #define	UICLASS_MASS		0x08
4614c87aefeSPatrick Mooney #define	UISUBCLASS_RBC		1
4624c87aefeSPatrick Mooney #define	UISUBCLASS_SFF8020I	2
4634c87aefeSPatrick Mooney #define	UISUBCLASS_QIC157	3
4644c87aefeSPatrick Mooney #define	UISUBCLASS_UFI		4
4654c87aefeSPatrick Mooney #define	UISUBCLASS_SFF8070I	5
4664c87aefeSPatrick Mooney #define	UISUBCLASS_SCSI		6
4674c87aefeSPatrick Mooney #define	UIPROTO_MASS_CBI_I	0
4684c87aefeSPatrick Mooney #define	UIPROTO_MASS_CBI	1
4694c87aefeSPatrick Mooney #define	UIPROTO_MASS_BBB_OLD	2	/* Not in the spec anymore */
4704c87aefeSPatrick Mooney #define	UIPROTO_MASS_BBB	80	/* 'P' for the Iomega Zip drive */
4714c87aefeSPatrick Mooney 
4724c87aefeSPatrick Mooney #define	UICLASS_HUB		0x09
4734c87aefeSPatrick Mooney #define	UISUBCLASS_HUB		0
4744c87aefeSPatrick Mooney #define	UIPROTO_FSHUB		0
4754c87aefeSPatrick Mooney #define	UIPROTO_HSHUBSTT	0	/* Yes, same as previous */
4764c87aefeSPatrick Mooney #define	UIPROTO_HSHUBMTT	1
4774c87aefeSPatrick Mooney 
4784c87aefeSPatrick Mooney #define	UICLASS_CDC_DATA	0x0a
4794c87aefeSPatrick Mooney #define	UISUBCLASS_DATA		0x00
4804c87aefeSPatrick Mooney #define	UIPROTO_DATA_ISDNBRI		0x30	/* Physical iface */
4814c87aefeSPatrick Mooney #define	UIPROTO_DATA_HDLC		0x31	/* HDLC */
4824c87aefeSPatrick Mooney #define	UIPROTO_DATA_TRANSPARENT	0x32	/* Transparent */
4834c87aefeSPatrick Mooney #define	UIPROTO_DATA_Q921M		0x50	/* Management for Q921 */
4844c87aefeSPatrick Mooney #define	UIPROTO_DATA_Q921		0x51	/* Data for Q921 */
4854c87aefeSPatrick Mooney #define	UIPROTO_DATA_Q921TM		0x52	/* TEI multiplexer for Q921 */
4864c87aefeSPatrick Mooney #define	UIPROTO_DATA_V42BIS		0x90	/* Data compression */
4874c87aefeSPatrick Mooney #define	UIPROTO_DATA_Q931		0x91	/* Euro-ISDN */
4884c87aefeSPatrick Mooney #define	UIPROTO_DATA_V120		0x92	/* V.24 rate adaption */
4894c87aefeSPatrick Mooney #define	UIPROTO_DATA_CAPI		0x93	/* CAPI 2.0 commands */
4904c87aefeSPatrick Mooney #define	UIPROTO_DATA_HOST_BASED		0xfd	/* Host based driver */
4914c87aefeSPatrick Mooney #define	UIPROTO_DATA_PUF		0xfe	/* see Prot. Unit Func. Desc. */
4924c87aefeSPatrick Mooney #define	UIPROTO_DATA_VENDOR		0xff	/* Vendor specific */
4934c87aefeSPatrick Mooney #define	UIPROTO_DATA_NCM		0x01	/* Network Control Model */
4944c87aefeSPatrick Mooney 
4954c87aefeSPatrick Mooney #define	UICLASS_SMARTCARD	0x0b
4964c87aefeSPatrick Mooney #define	UICLASS_FIRM_UPD	0x0c
4974c87aefeSPatrick Mooney #define	UICLASS_SECURITY	0x0d
4984c87aefeSPatrick Mooney #define	UICLASS_DIAGNOSTIC	0xdc
4994c87aefeSPatrick Mooney #define	UICLASS_WIRELESS	0xe0
5004c87aefeSPatrick Mooney #define	UISUBCLASS_RF			0x01
5014c87aefeSPatrick Mooney #define	UIPROTO_BLUETOOTH		0x01
5024c87aefeSPatrick Mooney #define	UIPROTO_RNDIS			0x03
5034c87aefeSPatrick Mooney 
5044c87aefeSPatrick Mooney #define	UICLASS_IAD		0xEF	/* Interface Association Descriptor */
5054c87aefeSPatrick Mooney #define	UISUBCLASS_SYNC			0x01
5064c87aefeSPatrick Mooney #define	UIPROTO_ACTIVESYNC		0x01
5074c87aefeSPatrick Mooney 
5084c87aefeSPatrick Mooney #define	UICLASS_APPL_SPEC	0xfe
5094c87aefeSPatrick Mooney #define	UISUBCLASS_FIRMWARE_DOWNLOAD	1
5104c87aefeSPatrick Mooney #define	UISUBCLASS_IRDA			2
5114c87aefeSPatrick Mooney #define	UIPROTO_IRDA			0
5124c87aefeSPatrick Mooney 
5134c87aefeSPatrick Mooney #define	UICLASS_VENDOR		0xff
5144c87aefeSPatrick Mooney #define	UISUBCLASS_XBOX360_CONTROLLER	0x5d
5154c87aefeSPatrick Mooney #define	UIPROTO_XBOX360_GAMEPAD	0x01
5164c87aefeSPatrick Mooney 
5174c87aefeSPatrick Mooney struct usb_endpoint_descriptor {
5184c87aefeSPatrick Mooney 	uByte	bLength;
5194c87aefeSPatrick Mooney 	uByte	bDescriptorType;
5204c87aefeSPatrick Mooney 	uByte	bEndpointAddress;
5214c87aefeSPatrick Mooney #define	UE_GET_DIR(a)	((a) & 0x80)
5224c87aefeSPatrick Mooney #define	UE_SET_DIR(a,d)	((a) | (((d)&1) << 7))
5234c87aefeSPatrick Mooney #define	UE_DIR_IN	0x80		/* IN-token endpoint, fixed */
5244c87aefeSPatrick Mooney #define	UE_DIR_OUT	0x00		/* OUT-token endpoint, fixed */
5254c87aefeSPatrick Mooney #define	UE_DIR_RX	0xfd		/* for internal use only! */
5264c87aefeSPatrick Mooney #define	UE_DIR_TX	0xfe		/* for internal use only! */
5274c87aefeSPatrick Mooney #define	UE_DIR_ANY	0xff		/* for internal use only! */
5284c87aefeSPatrick Mooney #define	UE_ADDR		0x0f
5294c87aefeSPatrick Mooney #define	UE_ADDR_ANY	0xff		/* for internal use only! */
5304c87aefeSPatrick Mooney #define	UE_GET_ADDR(a)	((a) & UE_ADDR)
5314c87aefeSPatrick Mooney 	uByte	bmAttributes;
5324c87aefeSPatrick Mooney #define	UE_XFERTYPE	0x03
5334c87aefeSPatrick Mooney #define	UE_CONTROL	0x00
5344c87aefeSPatrick Mooney #define	UE_ISOCHRONOUS	0x01
5354c87aefeSPatrick Mooney #define	UE_BULK	0x02
5364c87aefeSPatrick Mooney #define	UE_INTERRUPT	0x03
5374c87aefeSPatrick Mooney #define	UE_BULK_INTR	0xfe		/* for internal use only! */
5384c87aefeSPatrick Mooney #define	UE_TYPE_ANY	0xff		/* for internal use only! */
5394c87aefeSPatrick Mooney #define	UE_GET_XFERTYPE(a)	((a) & UE_XFERTYPE)
5404c87aefeSPatrick Mooney #define	UE_ISO_TYPE	0x0c
5414c87aefeSPatrick Mooney #define	UE_ISO_ASYNC	0x04
5424c87aefeSPatrick Mooney #define	UE_ISO_ADAPT	0x08
5434c87aefeSPatrick Mooney #define	UE_ISO_SYNC	0x0c
5444c87aefeSPatrick Mooney #define	UE_GET_ISO_TYPE(a)	((a) & UE_ISO_TYPE)
5454c87aefeSPatrick Mooney #define	UE_ISO_USAGE	0x30
5464c87aefeSPatrick Mooney #define	UE_ISO_USAGE_DATA	0x00
5474c87aefeSPatrick Mooney #define	UE_ISO_USAGE_FEEDBACK	0x10
5484c87aefeSPatrick Mooney #define	UE_ISO_USAGE_IMPLICT_FB	0x20
5494c87aefeSPatrick Mooney #define	UE_GET_ISO_USAGE(a)	((a) & UE_ISO_USAGE)
5504c87aefeSPatrick Mooney 	uWord	wMaxPacketSize;
5514c87aefeSPatrick Mooney #define	UE_ZERO_MPS 0xFFFF		/* for internal use only */
5524c87aefeSPatrick Mooney 	uByte	bInterval;
5534c87aefeSPatrick Mooney } __packed;
5544c87aefeSPatrick Mooney typedef struct usb_endpoint_descriptor usb_endpoint_descriptor_t;
5554c87aefeSPatrick Mooney 
5564c87aefeSPatrick Mooney struct usb_endpoint_ss_comp_descriptor {
5574c87aefeSPatrick Mooney 	uByte	bLength;
5584c87aefeSPatrick Mooney 	uByte	bDescriptorType;
5594c87aefeSPatrick Mooney 	uByte	bMaxBurst;
5604c87aefeSPatrick Mooney 	uByte	bmAttributes;
5614c87aefeSPatrick Mooney #define	UE_GET_BULK_STREAMS(x) ((x) & 0x0F)
5624c87aefeSPatrick Mooney #define	UE_GET_SS_ISO_MULT(x) ((x) & 0x03)
5634c87aefeSPatrick Mooney 	uWord	wBytesPerInterval;
5644c87aefeSPatrick Mooney } __packed;
5654c87aefeSPatrick Mooney typedef struct usb_endpoint_ss_comp_descriptor
5664c87aefeSPatrick Mooney 		usb_endpoint_ss_comp_descriptor_t;
5674c87aefeSPatrick Mooney 
5684c87aefeSPatrick Mooney struct usb_string_descriptor {
5694c87aefeSPatrick Mooney 	uByte	bLength;
5704c87aefeSPatrick Mooney 	uByte	bDescriptorType;
5714c87aefeSPatrick Mooney 	uWord	bString[126];
5724c87aefeSPatrick Mooney 	uByte	bUnused;
5734c87aefeSPatrick Mooney } __packed;
5744c87aefeSPatrick Mooney typedef struct usb_string_descriptor usb_string_descriptor_t;
5754c87aefeSPatrick Mooney 
5764c87aefeSPatrick Mooney #define	USB_MAKE_STRING_DESC(m,name)	\
5774c87aefeSPatrick Mooney static const struct {			\
5784c87aefeSPatrick Mooney   uByte bLength;			\
5794c87aefeSPatrick Mooney   uByte bDescriptorType;		\
5804c87aefeSPatrick Mooney   uByte bData[sizeof((uint8_t []){m})];	\
5814c87aefeSPatrick Mooney } __packed name = {			\
5824c87aefeSPatrick Mooney   .bLength = sizeof(name),		\
5834c87aefeSPatrick Mooney   .bDescriptorType = UDESC_STRING,	\
5844c87aefeSPatrick Mooney   .bData = { m },			\
5854c87aefeSPatrick Mooney }
5864c87aefeSPatrick Mooney 
5874c87aefeSPatrick Mooney struct usb_string_lang {
5884c87aefeSPatrick Mooney 	uByte bLength;
5894c87aefeSPatrick Mooney 	uByte bDescriptorType;
5904c87aefeSPatrick Mooney 	uByte bData[2];
5914c87aefeSPatrick Mooney } __packed;
5924c87aefeSPatrick Mooney typedef struct usb_string_lang usb_string_lang_t;
5934c87aefeSPatrick Mooney 
5944c87aefeSPatrick Mooney struct usb_hub_descriptor {
5954c87aefeSPatrick Mooney 	uByte	bDescLength;
5964c87aefeSPatrick Mooney 	uByte	bDescriptorType;
5974c87aefeSPatrick Mooney 	uByte	bNbrPorts;
5984c87aefeSPatrick Mooney 	uWord	wHubCharacteristics;
5994c87aefeSPatrick Mooney #define	UHD_PWR			0x0003
6004c87aefeSPatrick Mooney #define	UHD_PWR_GANGED		0x0000
6014c87aefeSPatrick Mooney #define	UHD_PWR_INDIVIDUAL	0x0001
6024c87aefeSPatrick Mooney #define	UHD_PWR_NO_SWITCH	0x0002
6034c87aefeSPatrick Mooney #define	UHD_COMPOUND		0x0004
6044c87aefeSPatrick Mooney #define	UHD_OC			0x0018
6054c87aefeSPatrick Mooney #define	UHD_OC_GLOBAL		0x0000
6064c87aefeSPatrick Mooney #define	UHD_OC_INDIVIDUAL	0x0008
6074c87aefeSPatrick Mooney #define	UHD_OC_NONE		0x0010
6084c87aefeSPatrick Mooney #define	UHD_TT_THINK		0x0060
6094c87aefeSPatrick Mooney #define	UHD_TT_THINK_8		0x0000
6104c87aefeSPatrick Mooney #define	UHD_TT_THINK_16		0x0020
6114c87aefeSPatrick Mooney #define	UHD_TT_THINK_24		0x0040
6124c87aefeSPatrick Mooney #define	UHD_TT_THINK_32		0x0060
6134c87aefeSPatrick Mooney #define	UHD_PORT_IND		0x0080
6144c87aefeSPatrick Mooney 	uByte	bPwrOn2PwrGood;		/* delay in 2 ms units */
6154c87aefeSPatrick Mooney #define	UHD_PWRON_FACTOR 2
6164c87aefeSPatrick Mooney 	uByte	bHubContrCurrent;
6174c87aefeSPatrick Mooney 	uByte	DeviceRemovable[32];	/* max 255 ports */
6184c87aefeSPatrick Mooney #define	UHD_NOT_REMOV(desc, i) \
6194c87aefeSPatrick Mooney     (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
6204c87aefeSPatrick Mooney 	uByte	PortPowerCtrlMask[1];	/* deprecated */
6214c87aefeSPatrick Mooney } __packed;
6224c87aefeSPatrick Mooney typedef struct usb_hub_descriptor usb_hub_descriptor_t;
6234c87aefeSPatrick Mooney 
6244c87aefeSPatrick Mooney struct usb_hub_ss_descriptor {
6254c87aefeSPatrick Mooney 	uByte	bLength;
6264c87aefeSPatrick Mooney 	uByte	bDescriptorType;
6274c87aefeSPatrick Mooney 	uByte	bNbrPorts;
6284c87aefeSPatrick Mooney 	uWord	wHubCharacteristics;
6294c87aefeSPatrick Mooney 	uByte	bPwrOn2PwrGood;		/* delay in 2 ms units */
6304c87aefeSPatrick Mooney 	uByte	bHubContrCurrent;
6314c87aefeSPatrick Mooney 	uByte	bHubHdrDecLat;
6324c87aefeSPatrick Mooney 	uWord	wHubDelay;
6334c87aefeSPatrick Mooney 	uByte	DeviceRemovable[32];	/* max 255 ports */
6344c87aefeSPatrick Mooney } __packed;
6354c87aefeSPatrick Mooney typedef struct usb_hub_ss_descriptor usb_hub_ss_descriptor_t;
6364c87aefeSPatrick Mooney 
6374c87aefeSPatrick Mooney /* minimum HUB descriptor (8-ports maximum) */
6384c87aefeSPatrick Mooney struct usb_hub_descriptor_min {
6394c87aefeSPatrick Mooney 	uByte	bDescLength;
6404c87aefeSPatrick Mooney 	uByte	bDescriptorType;
6414c87aefeSPatrick Mooney 	uByte	bNbrPorts;
6424c87aefeSPatrick Mooney 	uWord	wHubCharacteristics;
6434c87aefeSPatrick Mooney 	uByte	bPwrOn2PwrGood;
6444c87aefeSPatrick Mooney 	uByte	bHubContrCurrent;
6454c87aefeSPatrick Mooney 	uByte	DeviceRemovable[1];
6464c87aefeSPatrick Mooney 	uByte	PortPowerCtrlMask[1];
6474c87aefeSPatrick Mooney } __packed;
6484c87aefeSPatrick Mooney typedef struct usb_hub_descriptor_min usb_hub_descriptor_min_t;
6494c87aefeSPatrick Mooney 
6504c87aefeSPatrick Mooney struct usb_device_qualifier {
6514c87aefeSPatrick Mooney 	uByte	bLength;
6524c87aefeSPatrick Mooney 	uByte	bDescriptorType;
6534c87aefeSPatrick Mooney 	uWord	bcdUSB;
6544c87aefeSPatrick Mooney 	uByte	bDeviceClass;
6554c87aefeSPatrick Mooney 	uByte	bDeviceSubClass;
6564c87aefeSPatrick Mooney 	uByte	bDeviceProtocol;
6574c87aefeSPatrick Mooney 	uByte	bMaxPacketSize0;
6584c87aefeSPatrick Mooney 	uByte	bNumConfigurations;
6594c87aefeSPatrick Mooney 	uByte	bReserved;
6604c87aefeSPatrick Mooney } __packed;
6614c87aefeSPatrick Mooney typedef struct usb_device_qualifier usb_device_qualifier_t;
6624c87aefeSPatrick Mooney 
6634c87aefeSPatrick Mooney struct usb_otg_descriptor {
6644c87aefeSPatrick Mooney 	uByte	bLength;
6654c87aefeSPatrick Mooney 	uByte	bDescriptorType;
6664c87aefeSPatrick Mooney 	uByte	bmAttributes;
6674c87aefeSPatrick Mooney #define	UOTG_SRP	0x01
6684c87aefeSPatrick Mooney #define	UOTG_HNP	0x02
6694c87aefeSPatrick Mooney } __packed;
6704c87aefeSPatrick Mooney typedef struct usb_otg_descriptor usb_otg_descriptor_t;
6714c87aefeSPatrick Mooney 
6724c87aefeSPatrick Mooney /* OTG feature selectors */
6734c87aefeSPatrick Mooney #define	UOTG_B_HNP_ENABLE	3
6744c87aefeSPatrick Mooney #define	UOTG_A_HNP_SUPPORT	4
6754c87aefeSPatrick Mooney #define	UOTG_A_ALT_HNP_SUPPORT	5
6764c87aefeSPatrick Mooney 
6774c87aefeSPatrick Mooney struct usb_status {
6784c87aefeSPatrick Mooney 	uWord	wStatus;
6794c87aefeSPatrick Mooney /* Device status flags */
6804c87aefeSPatrick Mooney #define	UDS_SELF_POWERED		0x0001
6814c87aefeSPatrick Mooney #define	UDS_REMOTE_WAKEUP		0x0002
6824c87aefeSPatrick Mooney /* Endpoint status flags */
6834c87aefeSPatrick Mooney #define	UES_HALT			0x0001
6844c87aefeSPatrick Mooney } __packed;
6854c87aefeSPatrick Mooney typedef struct usb_status usb_status_t;
6864c87aefeSPatrick Mooney 
6874c87aefeSPatrick Mooney struct usb_hub_status {
6884c87aefeSPatrick Mooney 	uWord	wHubStatus;
6894c87aefeSPatrick Mooney #define	UHS_LOCAL_POWER			0x0001
6904c87aefeSPatrick Mooney #define	UHS_OVER_CURRENT		0x0002
6914c87aefeSPatrick Mooney 	uWord	wHubChange;
6924c87aefeSPatrick Mooney } __packed;
6934c87aefeSPatrick Mooney typedef struct usb_hub_status usb_hub_status_t;
6944c87aefeSPatrick Mooney 
6954c87aefeSPatrick Mooney struct usb_port_status {
6964c87aefeSPatrick Mooney 	uWord	wPortStatus;
6974c87aefeSPatrick Mooney #define	UPS_CURRENT_CONNECT_STATUS	0x0001
6984c87aefeSPatrick Mooney #define	UPS_PORT_ENABLED		0x0002
6994c87aefeSPatrick Mooney #define	UPS_SUSPEND			0x0004
7004c87aefeSPatrick Mooney #define	UPS_OVERCURRENT_INDICATOR	0x0008
7014c87aefeSPatrick Mooney #define	UPS_RESET			0x0010
7024c87aefeSPatrick Mooney #define	UPS_PORT_L1			0x0020	/* USB 2.0 only */
7034c87aefeSPatrick Mooney /* The link-state bits are valid for Super-Speed USB HUBs */
7044c87aefeSPatrick Mooney #define	UPS_PORT_LINK_STATE_GET(x)	(((x) >> 5) & 0xF)
7054c87aefeSPatrick Mooney #define	UPS_PORT_LINK_STATE_SET(x)	(((x) & 0xF) << 5)
7064c87aefeSPatrick Mooney #define	UPS_PORT_LS_U0		0x00
7074c87aefeSPatrick Mooney #define	UPS_PORT_LS_U1		0x01
7084c87aefeSPatrick Mooney #define	UPS_PORT_LS_U2		0x02
7094c87aefeSPatrick Mooney #define	UPS_PORT_LS_U3		0x03
7104c87aefeSPatrick Mooney #define	UPS_PORT_LS_SS_DIS	0x04
7114c87aefeSPatrick Mooney #define	UPS_PORT_LS_RX_DET	0x05
7124c87aefeSPatrick Mooney #define	UPS_PORT_LS_SS_INA	0x06
7134c87aefeSPatrick Mooney #define	UPS_PORT_LS_POLL	0x07
7144c87aefeSPatrick Mooney #define	UPS_PORT_LS_RECOVER	0x08
7154c87aefeSPatrick Mooney #define	UPS_PORT_LS_HOT_RST	0x09
7164c87aefeSPatrick Mooney #define	UPS_PORT_LS_COMP_MODE	0x0A
7174c87aefeSPatrick Mooney #define	UPS_PORT_LS_LOOPBACK	0x0B
7184c87aefeSPatrick Mooney #define	UPS_PORT_LS_RESUME	0x0F
7194c87aefeSPatrick Mooney #define	UPS_PORT_POWER			0x0100
7204c87aefeSPatrick Mooney #define	UPS_PORT_POWER_SS		0x0200	/* super-speed only */
7214c87aefeSPatrick Mooney #define	UPS_LOW_SPEED			0x0200
7224c87aefeSPatrick Mooney #define	UPS_HIGH_SPEED			0x0400
7234c87aefeSPatrick Mooney #define	UPS_OTHER_SPEED			0x0600	/* currently FreeBSD specific */
7244c87aefeSPatrick Mooney #define	UPS_PORT_TEST			0x0800
7254c87aefeSPatrick Mooney #define	UPS_PORT_INDICATOR		0x1000
7264c87aefeSPatrick Mooney #define	UPS_PORT_MODE_DEVICE		0x8000	/* currently FreeBSD specific */
7274c87aefeSPatrick Mooney 	uWord	wPortChange;
7284c87aefeSPatrick Mooney #define	UPS_C_CONNECT_STATUS		0x0001
7294c87aefeSPatrick Mooney #define	UPS_C_PORT_ENABLED		0x0002
7304c87aefeSPatrick Mooney #define	UPS_C_SUSPEND			0x0004
7314c87aefeSPatrick Mooney #define	UPS_C_OVERCURRENT_INDICATOR	0x0008
7324c87aefeSPatrick Mooney #define	UPS_C_PORT_RESET		0x0010
7334c87aefeSPatrick Mooney #define	UPS_C_PORT_L1			0x0020	/* USB 2.0 only */
7344c87aefeSPatrick Mooney #define	UPS_C_BH_PORT_RESET		0x0020	/* USB 3.0 only */
7354c87aefeSPatrick Mooney #define	UPS_C_PORT_LINK_STATE		0x0040
7364c87aefeSPatrick Mooney #define	UPS_C_PORT_CONFIG_ERROR		0x0080
7374c87aefeSPatrick Mooney } __packed;
7384c87aefeSPatrick Mooney typedef struct usb_port_status usb_port_status_t;
7394c87aefeSPatrick Mooney 
7404c87aefeSPatrick Mooney /*
7414c87aefeSPatrick Mooney  * The "USB_SPEED" macros defines all the supported USB speeds.
7424c87aefeSPatrick Mooney  */
7434c87aefeSPatrick Mooney enum usb_dev_speed {
7444c87aefeSPatrick Mooney 	USB_SPEED_VARIABLE,
7454c87aefeSPatrick Mooney 	USB_SPEED_LOW,
7464c87aefeSPatrick Mooney 	USB_SPEED_FULL,
7474c87aefeSPatrick Mooney 	USB_SPEED_HIGH,
7484c87aefeSPatrick Mooney 	USB_SPEED_SUPER,
7494c87aefeSPatrick Mooney };
7504c87aefeSPatrick Mooney #define	USB_SPEED_MAX	(USB_SPEED_SUPER+1)
7514c87aefeSPatrick Mooney 
7524c87aefeSPatrick Mooney /*
7534c87aefeSPatrick Mooney  * The "USB_REV" macros defines all the supported USB revisions.
7544c87aefeSPatrick Mooney  */
7554c87aefeSPatrick Mooney enum usb_revision {
7564c87aefeSPatrick Mooney 	USB_REV_UNKNOWN,
7574c87aefeSPatrick Mooney 	USB_REV_PRE_1_0,
7584c87aefeSPatrick Mooney 	USB_REV_1_0,
7594c87aefeSPatrick Mooney 	USB_REV_1_1,
7604c87aefeSPatrick Mooney 	USB_REV_2_0,
7614c87aefeSPatrick Mooney 	USB_REV_2_5,
7624c87aefeSPatrick Mooney 	USB_REV_3_0
7634c87aefeSPatrick Mooney };
7644c87aefeSPatrick Mooney #define	USB_REV_MAX	(USB_REV_3_0+1)
7654c87aefeSPatrick Mooney 
7664c87aefeSPatrick Mooney /*
7674c87aefeSPatrick Mooney  * Supported host controller modes.
7684c87aefeSPatrick Mooney  */
7694c87aefeSPatrick Mooney enum usb_hc_mode {
7704c87aefeSPatrick Mooney 	USB_MODE_HOST,		/* initiates transfers */
7714c87aefeSPatrick Mooney 	USB_MODE_DEVICE,	/* bus transfer target */
7724c87aefeSPatrick Mooney 	USB_MODE_DUAL		/* can be host or device */
7734c87aefeSPatrick Mooney };
7744c87aefeSPatrick Mooney #define	USB_MODE_MAX	(USB_MODE_DUAL+1)
7754c87aefeSPatrick Mooney 
7764c87aefeSPatrick Mooney /*
7774c87aefeSPatrick Mooney  * The "USB_STATE" enums define all the supported device states.
7784c87aefeSPatrick Mooney  */
7794c87aefeSPatrick Mooney enum usb_dev_state {
7804c87aefeSPatrick Mooney 	USB_STATE_DETACHED,
7814c87aefeSPatrick Mooney 	USB_STATE_ATTACHED,
7824c87aefeSPatrick Mooney 	USB_STATE_POWERED,
7834c87aefeSPatrick Mooney 	USB_STATE_ADDRESSED,
7844c87aefeSPatrick Mooney 	USB_STATE_CONFIGURED,
7854c87aefeSPatrick Mooney };
7864c87aefeSPatrick Mooney #define	USB_STATE_MAX	(USB_STATE_CONFIGURED+1)
7874c87aefeSPatrick Mooney 
7884c87aefeSPatrick Mooney /*
7894c87aefeSPatrick Mooney  * The "USB_EP_MODE" macros define all the currently supported
7904c87aefeSPatrick Mooney  * endpoint modes.
7914c87aefeSPatrick Mooney  */
7924c87aefeSPatrick Mooney enum usb_ep_mode {
7934c87aefeSPatrick Mooney 	USB_EP_MODE_DEFAULT,
7944c87aefeSPatrick Mooney 	USB_EP_MODE_STREAMS,	/* USB3.0 specific */
7954c87aefeSPatrick Mooney 	USB_EP_MODE_HW_MASS_STORAGE,
7964c87aefeSPatrick Mooney 	USB_EP_MODE_HW_SERIAL,
7974c87aefeSPatrick Mooney 	USB_EP_MODE_HW_ETHERNET_CDC,
7984c87aefeSPatrick Mooney 	USB_EP_MODE_HW_ETHERNET_NCM,
7994c87aefeSPatrick Mooney 	USB_EP_MODE_MAX
8004c87aefeSPatrick Mooney };
8014c87aefeSPatrick Mooney #endif					/* _USB_STANDARD_H_ */