xref: /freebsd/sys/dev/usb/usb.h (revision 2f513db7)
1 /* $FreeBSD$ */
2 /*-
3  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
4  *
5  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
6  * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
7  * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 /*
32  * This file contains standard definitions for the following USB
33  * protocol versions:
34  *
35  * USB v1.0
36  * USB v1.1
37  * USB v2.0
38  * USB v3.0
39  */
40 
41 #ifndef _USB_STANDARD_H_
42 #define	_USB_STANDARD_H_
43 
44 #if defined(_KERNEL)
45 #ifndef USB_GLOBAL_INCLUDE_FILE
46 #include "opt_usb.h"
47 #endif
48 
49 /* Declare parent SYSCTL USB node. */
50 #ifdef SYSCTL_DECL
51 SYSCTL_DECL(_hw_usb);
52 #endif
53 
54 #ifndef USB_GLOBAL_INCLUDE_FILE
55 #include <sys/malloc.h>
56 #endif
57 
58 MALLOC_DECLARE(M_USB);
59 MALLOC_DECLARE(M_USBDEV);
60 #endif /* _KERNEL */
61 
62 #ifndef USB_GLOBAL_INCLUDE_FILE
63 #include <dev/usb/usb_endian.h>
64 #include <dev/usb/usb_freebsd.h>
65 #endif
66 
67 #define	USB_STACK_VERSION 2000		/* 2.0 */
68 
69 /* Definition of some hardcoded USB constants. */
70 
71 #define	USB_MAX_IPACKET		8	/* initial USB packet size */
72 #define	USB_EP_MAX (2*16)		/* hardcoded */
73 #define	USB_ROOT_HUB_ADDR 1		/* index */
74 #define	USB_MIN_DEVICES 2		/* unused + root HUB */
75 #define	USB_UNCONFIG_INDEX 0xFF		/* internal use only */
76 #define	USB_IFACE_INDEX_ANY 0xFF	/* internal use only */
77 #define	USB_START_ADDR 0		/* default USB device BUS address
78 					 * after USB bus reset */
79 #define	USB_CONTROL_ENDPOINT 0		/* default control endpoint */
80 
81 #define	USB_FRAMES_PER_SECOND_FS 1000	/* full speed */
82 #define	USB_FRAMES_PER_SECOND_HS 8000	/* high speed */
83 
84 #define	USB_FS_BYTES_PER_HS_UFRAME 188	/* bytes */
85 #define	USB_HS_MICRO_FRAMES_MAX 8	/* units */
86 
87 #define	USB_ISOC_TIME_MAX 128		/* ms */
88 
89 /*
90  * Minimum time a device needs to be powered down to go through a
91  * power cycle. These values are not in the USB specification.
92  */
93 #define	USB_POWER_DOWN_TIME	200	/* ms */
94 #define	USB_PORT_POWER_DOWN_TIME	100	/* ms */
95 
96 /* Definition of software USB power modes */
97 #define	USB_POWER_MODE_OFF 0		/* turn off device */
98 #define	USB_POWER_MODE_ON 1		/* always on */
99 #define	USB_POWER_MODE_SAVE 2		/* automatic suspend and resume */
100 #define	USB_POWER_MODE_SUSPEND 3	/* force suspend */
101 #define	USB_POWER_MODE_RESUME 4		/* force resume */
102 
103 /* These are the values from the USB specification. */
104 #define	USB_PORT_RESET_DELAY_SPEC	10	/* ms */
105 #define	USB_PORT_ROOT_RESET_DELAY_SPEC	50	/* ms */
106 #define	USB_PORT_RESET_RECOVERY_SPEC	10	/* ms */
107 #define	USB_PORT_POWERUP_DELAY_SPEC	100	/* ms */
108 #define	USB_PORT_RESUME_DELAY_SPEC	20	/* ms */
109 #define	USB_SET_ADDRESS_SETTLE_SPEC	2	/* ms */
110 #define	USB_RESUME_DELAY_SPEC		(20*5)	/* ms */
111 #define	USB_RESUME_WAIT_SPEC		10	/* ms */
112 #define	USB_RESUME_RECOVERY_SPEC	10	/* ms */
113 #define	USB_EXTRA_POWER_UP_TIME_SPEC	0	/* ms */
114 
115 /* Allow for marginal and non-conforming devices. */
116 #define	USB_PORT_RESET_DELAY		50	/* ms */
117 #define	USB_PORT_ROOT_RESET_DELAY	200	/* ms */
118 #define	USB_PORT_RESET_RECOVERY		250	/* ms */
119 #define	USB_PORT_POWERUP_DELAY		300	/* ms */
120 #define	USB_PORT_RESUME_DELAY		(20*2)	/* ms */
121 #define	USB_SET_ADDRESS_SETTLE		10	/* ms */
122 #define	USB_RESUME_DELAY		(50*5)	/* ms */
123 #define	USB_RESUME_WAIT			50	/* ms */
124 #define	USB_RESUME_RECOVERY		50	/* ms */
125 #define	USB_EXTRA_POWER_UP_TIME		20	/* ms */
126 
127 #define	USB_MIN_POWER		100	/* mA */
128 #define	USB_MAX_POWER		500	/* mA */
129 
130 #define	USB_BUS_RESET_DELAY	100	/* ms */
131 
132 /*
133  * USB record layout in memory:
134  *
135  * - USB config 0
136  *   - USB interfaces
137  *     - USB alternative interfaces
138  *       - USB endpoints
139  *
140  * - USB config 1
141  *   - USB interfaces
142  *     - USB alternative interfaces
143  *       - USB endpoints
144  */
145 
146 /* Declaration of USB records */
147 
148 struct usb_device_request {
149 	uByte	bmRequestType;
150 	uByte	bRequest;
151 	uWord	wValue;
152 	uWord	wIndex;
153 	uWord	wLength;
154 } __packed;
155 typedef struct usb_device_request usb_device_request_t;
156 
157 #define	UT_WRITE		0x00
158 #define	UT_READ			0x80
159 #define	UT_STANDARD		0x00
160 #define	UT_CLASS		0x20
161 #define	UT_VENDOR		0x40
162 #define	UT_DEVICE		0x00
163 #define	UT_INTERFACE		0x01
164 #define	UT_ENDPOINT		0x02
165 #define	UT_OTHER		0x03
166 
167 #define	UT_READ_DEVICE		(UT_READ  | UT_STANDARD | UT_DEVICE)
168 #define	UT_READ_INTERFACE	(UT_READ  | UT_STANDARD | UT_INTERFACE)
169 #define	UT_READ_ENDPOINT	(UT_READ  | UT_STANDARD | UT_ENDPOINT)
170 #define	UT_WRITE_DEVICE		(UT_WRITE | UT_STANDARD | UT_DEVICE)
171 #define	UT_WRITE_INTERFACE	(UT_WRITE | UT_STANDARD | UT_INTERFACE)
172 #define	UT_WRITE_ENDPOINT	(UT_WRITE | UT_STANDARD | UT_ENDPOINT)
173 #define	UT_READ_CLASS_DEVICE	(UT_READ  | UT_CLASS | UT_DEVICE)
174 #define	UT_READ_CLASS_INTERFACE	(UT_READ  | UT_CLASS | UT_INTERFACE)
175 #define	UT_READ_CLASS_OTHER	(UT_READ  | UT_CLASS | UT_OTHER)
176 #define	UT_READ_CLASS_ENDPOINT	(UT_READ  | UT_CLASS | UT_ENDPOINT)
177 #define	UT_WRITE_CLASS_DEVICE	(UT_WRITE | UT_CLASS | UT_DEVICE)
178 #define	UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
179 #define	UT_WRITE_CLASS_OTHER	(UT_WRITE | UT_CLASS | UT_OTHER)
180 #define	UT_WRITE_CLASS_ENDPOINT	(UT_WRITE | UT_CLASS | UT_ENDPOINT)
181 #define	UT_READ_VENDOR_DEVICE	(UT_READ  | UT_VENDOR | UT_DEVICE)
182 #define	UT_READ_VENDOR_INTERFACE (UT_READ  | UT_VENDOR | UT_INTERFACE)
183 #define	UT_READ_VENDOR_OTHER	(UT_READ  | UT_VENDOR | UT_OTHER)
184 #define	UT_READ_VENDOR_ENDPOINT	(UT_READ  | UT_VENDOR | UT_ENDPOINT)
185 #define	UT_WRITE_VENDOR_DEVICE	(UT_WRITE | UT_VENDOR | UT_DEVICE)
186 #define	UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
187 #define	UT_WRITE_VENDOR_OTHER	(UT_WRITE | UT_VENDOR | UT_OTHER)
188 #define	UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
189 
190 /* Requests */
191 #define	UR_GET_STATUS		0x00
192 #define	UR_CLEAR_FEATURE	0x01
193 #define	UR_SET_FEATURE		0x03
194 #define	UR_SET_ADDRESS		0x05
195 #define	UR_GET_DESCRIPTOR	0x06
196 #define	UDESC_DEVICE		0x01
197 #define	UDESC_CONFIG		0x02
198 #define	UDESC_STRING		0x03
199 #define	USB_LANGUAGE_TABLE	0x00	/* language ID string index */
200 #define	UDESC_INTERFACE		0x04
201 #define	UDESC_ENDPOINT		0x05
202 #define	UDESC_DEVICE_QUALIFIER	0x06
203 #define	UDESC_OTHER_SPEED_CONFIGURATION 0x07
204 #define	UDESC_INTERFACE_POWER	0x08
205 #define	UDESC_OTG		0x09
206 #define	UDESC_DEBUG		0x0A
207 #define	UDESC_IFACE_ASSOC	0x0B	/* interface association */
208 #define	UDESC_BOS		0x0F	/* binary object store */
209 #define	UDESC_DEVICE_CAPABILITY	0x10
210 #define	UDESC_CS_DEVICE		0x21	/* class specific */
211 #define	UDESC_CS_CONFIG		0x22
212 #define	UDESC_CS_STRING		0x23
213 #define	UDESC_CS_INTERFACE	0x24
214 #define	UDESC_CS_ENDPOINT	0x25
215 #define	UDESC_HUB		0x29
216 #define	UDESC_SS_HUB		0x2A	/* super speed */
217 #define	UDESC_ENDPOINT_SS_COMP	0x30	/* super speed */
218 #define	UR_SET_DESCRIPTOR	0x07
219 #define	UR_GET_CONFIG		0x08
220 #define	UR_SET_CONFIG		0x09
221 #define	UR_GET_INTERFACE	0x0a
222 #define	UR_SET_INTERFACE	0x0b
223 #define	UR_SYNCH_FRAME		0x0c
224 #define	UR_SET_SEL		0x30
225 #define	UR_ISOCH_DELAY		0x31
226 
227 /* HUB specific request */
228 #define	UR_GET_BUS_STATE	0x02
229 #define	UR_CLEAR_TT_BUFFER	0x08
230 #define	UR_RESET_TT		0x09
231 #define	UR_GET_TT_STATE		0x0a
232 #define	UR_STOP_TT		0x0b
233 #define	UR_SET_AND_TEST		0x0c	/* USB 2.0 only */
234 #define	UR_SET_HUB_DEPTH	0x0c	/* USB 3.0 only */
235 #define	USB_SS_HUB_DEPTH_MAX	5
236 #define	UR_GET_PORT_ERR_COUNT	0x0d
237 
238 /* Feature numbers */
239 #define	UF_ENDPOINT_HALT	0
240 #define	UF_DEVICE_REMOTE_WAKEUP	1
241 #define	UF_TEST_MODE		2
242 #define	UF_U1_ENABLE		0x30
243 #define	UF_U2_ENABLE		0x31
244 #define	UF_LTM_ENABLE		0x32
245 
246 /* HUB specific features */
247 #define	UHF_C_HUB_LOCAL_POWER	0
248 #define	UHF_C_HUB_OVER_CURRENT	1
249 #define	UHF_PORT_CONNECTION	0
250 #define	UHF_PORT_ENABLE		1
251 #define	UHF_PORT_SUSPEND	2
252 #define	UHF_PORT_OVER_CURRENT	3
253 #define	UHF_PORT_RESET		4
254 #define	UHF_PORT_LINK_STATE	5
255 #define	UHF_PORT_POWER		8
256 #define	UHF_PORT_LOW_SPEED	9
257 #define	UHF_PORT_L1		10
258 #define	UHF_C_PORT_CONNECTION	16
259 #define	UHF_C_PORT_ENABLE	17
260 #define	UHF_C_PORT_SUSPEND	18
261 #define	UHF_C_PORT_OVER_CURRENT	19
262 #define	UHF_C_PORT_RESET	20
263 #define	UHF_PORT_TEST		21
264 #define	UHF_PORT_INDICATOR	22
265 #define	UHF_C_PORT_L1		23
266 
267 /* SuperSpeed HUB specific features */
268 #define	UHF_PORT_U1_TIMEOUT	23
269 #define	UHF_PORT_U2_TIMEOUT	24
270 #define	UHF_C_PORT_LINK_STATE	25
271 #define	UHF_C_PORT_CONFIG_ERROR	26
272 #define	UHF_PORT_REMOTE_WAKE_MASK	27
273 #define	UHF_BH_PORT_RESET	28
274 #define	UHF_C_BH_PORT_RESET	29
275 #define	UHF_FORCE_LINKPM_ACCEPT	30
276 
277 struct usb_descriptor {
278 	uByte	bLength;
279 	uByte	bDescriptorType;
280 	uByte	bDescriptorSubtype;
281 } __packed;
282 typedef struct usb_descriptor usb_descriptor_t;
283 
284 struct usb_device_descriptor {
285 	uByte	bLength;
286 	uByte	bDescriptorType;
287 	uWord	bcdUSB;
288 #define	UD_USB_2_0		0x0200
289 #define	UD_USB_3_0		0x0300
290 #define	UD_IS_USB2(d) ((d)->bcdUSB[1] == 0x02)
291 #define	UD_IS_USB3(d) ((d)->bcdUSB[1] == 0x03)
292 	uByte	bDeviceClass;
293 	uByte	bDeviceSubClass;
294 	uByte	bDeviceProtocol;
295 	uByte	bMaxPacketSize;
296 	/* The fields below are not part of the initial descriptor. */
297 	uWord	idVendor;
298 	uWord	idProduct;
299 	uWord	bcdDevice;
300 	uByte	iManufacturer;
301 	uByte	iProduct;
302 	uByte	iSerialNumber;
303 	uByte	bNumConfigurations;
304 } __packed;
305 typedef struct usb_device_descriptor usb_device_descriptor_t;
306 
307 /* Binary Device Object Store (BOS) */
308 struct usb_bos_descriptor {
309 	uByte	bLength;
310 	uByte	bDescriptorType;
311 	uWord	wTotalLength;
312 	uByte	bNumDeviceCaps;
313 } __packed;
314 typedef struct usb_bos_descriptor usb_bos_descriptor_t;
315 
316 /* Binary Device Object Store Capability */
317 struct usb_bos_cap_descriptor {
318 	uByte	bLength;
319 	uByte	bDescriptorType;
320 	uByte	bDevCapabilityType;
321 #define	USB_DEVCAP_RESERVED	0x00
322 #define	USB_DEVCAP_WUSB		0x01
323 #define	USB_DEVCAP_USB2EXT	0x02
324 #define	USB_DEVCAP_SUPER_SPEED	0x03
325 #define	USB_DEVCAP_CONTAINER_ID	0x04
326 	/* data ... */
327 } __packed;
328 typedef struct usb_bos_cap_descriptor usb_bos_cap_descriptor_t;
329 
330 struct usb_devcap_usb2ext_descriptor {
331 	uByte	bLength;
332 	uByte	bDescriptorType;
333 	uByte	bDevCapabilityType;
334 	uDWord	bmAttributes;
335 #define	USB_V2EXT_LPM (1U << 1)
336 #define	USB_V2EXT_BESL_SUPPORTED (1U << 2)
337 #define	USB_V2EXT_BESL_BASELINE_VALID (1U << 3)
338 #define	USB_V2EXT_BESL_DEEP_VALID (1U << 4)
339 #define	USB_V2EXT_BESL_BASELINE_GET(x) (((x) >> 8) & 0xF)
340 #define	USB_V2EXT_BESL_DEEP_GET(x) (((x) >> 12) & 0xF)
341 } __packed;
342 typedef struct usb_devcap_usb2ext_descriptor usb_devcap_usb2ext_descriptor_t;
343 
344 struct usb_devcap_ss_descriptor {
345 	uByte	bLength;
346 	uByte	bDescriptorType;
347 	uByte	bDevCapabilityType;
348 	uByte	bmAttributes;
349 	uWord	wSpeedsSupported;
350 	uByte	bFunctionalitySupport;
351 	uByte	bU1DevExitLat;
352 	uWord	wU2DevExitLat;
353 } __packed;
354 typedef struct usb_devcap_ss_descriptor usb_devcap_ss_descriptor_t;
355 
356 struct usb_devcap_container_id_descriptor {
357 	uByte	bLength;
358 	uByte	bDescriptorType;
359 	uByte	bDevCapabilityType;
360 	uByte	bReserved;
361 	uByte	bContainerID;
362 } __packed;
363 typedef struct usb_devcap_container_id_descriptor
364 		usb_devcap_container_id_descriptor_t;
365 
366 /* Device class codes */
367 #define	UDCLASS_IN_INTERFACE	0x00
368 #define	UDCLASS_COMM		0x02
369 #define	UDCLASS_HUB		0x09
370 #define	UDSUBCLASS_HUB		0x00
371 #define	UDPROTO_FSHUB		0x00
372 #define	UDPROTO_HSHUBSTT	0x01
373 #define	UDPROTO_HSHUBMTT	0x02
374 #define	UDPROTO_SSHUB		0x03
375 #define	UDCLASS_DIAGNOSTIC	0xdc
376 #define	UDCLASS_WIRELESS	0xe0
377 #define	UDSUBCLASS_RF		0x01
378 #define	UDPROTO_BLUETOOTH	0x01
379 #define	UDCLASS_VENDOR		0xff
380 
381 struct usb_config_descriptor {
382 	uByte	bLength;
383 	uByte	bDescriptorType;
384 	uWord	wTotalLength;
385 	uByte	bNumInterface;
386 	uByte	bConfigurationValue;
387 #define	USB_UNCONFIG_NO 0
388 	uByte	iConfiguration;
389 	uByte	bmAttributes;
390 #define	UC_BUS_POWERED		0x80
391 #define	UC_SELF_POWERED		0x40
392 #define	UC_REMOTE_WAKEUP	0x20
393 	uByte	bMaxPower;		/* max current in 2 mA units */
394 #define	UC_POWER_FACTOR 2
395 } __packed;
396 typedef struct usb_config_descriptor usb_config_descriptor_t;
397 
398 struct usb_interface_descriptor {
399 	uByte	bLength;
400 	uByte	bDescriptorType;
401 	uByte	bInterfaceNumber;
402 	uByte	bAlternateSetting;
403 	uByte	bNumEndpoints;
404 	uByte	bInterfaceClass;
405 	uByte	bInterfaceSubClass;
406 	uByte	bInterfaceProtocol;
407 	uByte	iInterface;
408 } __packed;
409 typedef struct usb_interface_descriptor usb_interface_descriptor_t;
410 
411 struct usb_interface_assoc_descriptor {
412 	uByte	bLength;
413 	uByte	bDescriptorType;
414 	uByte	bFirstInterface;
415 	uByte	bInterfaceCount;
416 	uByte	bFunctionClass;
417 	uByte	bFunctionSubClass;
418 	uByte	bFunctionProtocol;
419 	uByte	iFunction;
420 } __packed;
421 typedef struct usb_interface_assoc_descriptor usb_interface_assoc_descriptor_t;
422 
423 /* Interface class codes */
424 #define	UICLASS_UNSPEC		0x00
425 #define	UICLASS_AUDIO		0x01	/* audio */
426 #define	UISUBCLASS_AUDIOCONTROL	1
427 #define	UISUBCLASS_AUDIOSTREAM		2
428 #define	UISUBCLASS_MIDISTREAM		3
429 
430 #define	UICLASS_CDC		0x02	/* communication */
431 #define	UISUBCLASS_DIRECT_LINE_CONTROL_MODEL	1
432 #define	UISUBCLASS_ABSTRACT_CONTROL_MODEL	2
433 #define	UISUBCLASS_TELEPHONE_CONTROL_MODEL	3
434 #define	UISUBCLASS_MULTICHANNEL_CONTROL_MODEL	4
435 #define	UISUBCLASS_CAPI_CONTROLMODEL		5
436 #define	UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
437 #define	UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
438 #define	UISUBCLASS_WIRELESS_HANDSET_CM 8
439 #define	UISUBCLASS_DEVICE_MGMT 9
440 #define	UISUBCLASS_MOBILE_DIRECT_LINE_MODEL 10
441 #define	UISUBCLASS_OBEX 11
442 #define	UISUBCLASS_ETHERNET_EMULATION_MODEL 12
443 #define	UISUBCLASS_NETWORK_CONTROL_MODEL 13
444 
445 #define	UIPROTO_CDC_NONE		0
446 #define	UIPROTO_CDC_AT			1
447 #define	UIPROTO_CDC_EEM			7
448 
449 #define	UICLASS_HID		0x03
450 #define	UISUBCLASS_BOOT		1
451 #define	UIPROTO_BOOT_KEYBOARD	1
452 #define	UIPROTO_MOUSE		2
453 
454 #define	UICLASS_PHYSICAL	0x05
455 #define	UICLASS_IMAGE		0x06
456 #define	UISUBCLASS_SIC		1	/* still image class */
457 #define	UICLASS_PRINTER		0x07
458 #define	UISUBCLASS_PRINTER	1
459 #define	UIPROTO_PRINTER_UNI	1
460 #define	UIPROTO_PRINTER_BI	2
461 #define	UIPROTO_PRINTER_1284	3
462 
463 #define	UICLASS_MASS		0x08
464 #define	UISUBCLASS_RBC		1
465 #define	UISUBCLASS_SFF8020I	2
466 #define	UISUBCLASS_QIC157	3
467 #define	UISUBCLASS_UFI		4
468 #define	UISUBCLASS_SFF8070I	5
469 #define	UISUBCLASS_SCSI		6
470 #define	UIPROTO_MASS_CBI_I	0
471 #define	UIPROTO_MASS_CBI	1
472 #define	UIPROTO_MASS_BBB_OLD	2	/* Not in the spec anymore */
473 #define	UIPROTO_MASS_BBB	80	/* 'P' for the Iomega Zip drive */
474 
475 #define	UICLASS_HUB		0x09
476 #define	UISUBCLASS_HUB		0
477 #define	UIPROTO_FSHUB		0
478 #define	UIPROTO_HSHUBSTT	0	/* Yes, same as previous */
479 #define	UIPROTO_HSHUBMTT	1
480 
481 #define	UICLASS_CDC_DATA	0x0a
482 #define	UISUBCLASS_DATA		0x00
483 #define	UIPROTO_DATA_ISDNBRI		0x30	/* Physical iface */
484 #define	UIPROTO_DATA_HDLC		0x31	/* HDLC */
485 #define	UIPROTO_DATA_TRANSPARENT	0x32	/* Transparent */
486 #define	UIPROTO_DATA_Q921M		0x50	/* Management for Q921 */
487 #define	UIPROTO_DATA_Q921		0x51	/* Data for Q921 */
488 #define	UIPROTO_DATA_Q921TM		0x52	/* TEI multiplexer for Q921 */
489 #define	UIPROTO_DATA_V42BIS		0x90	/* Data compression */
490 #define	UIPROTO_DATA_Q931		0x91	/* Euro-ISDN */
491 #define	UIPROTO_DATA_V120		0x92	/* V.24 rate adaption */
492 #define	UIPROTO_DATA_CAPI		0x93	/* CAPI 2.0 commands */
493 #define	UIPROTO_DATA_HOST_BASED		0xfd	/* Host based driver */
494 #define	UIPROTO_DATA_PUF		0xfe	/* see Prot. Unit Func. Desc. */
495 #define	UIPROTO_DATA_VENDOR		0xff	/* Vendor specific */
496 #define	UIPROTO_DATA_NCM		0x01	/* Network Control Model */
497 
498 #define	UICLASS_SMARTCARD	0x0b
499 #define	UICLASS_FIRM_UPD	0x0c
500 #define	UICLASS_SECURITY	0x0d
501 #define	UICLASS_DIAGNOSTIC	0xdc
502 #define	UICLASS_WIRELESS	0xe0
503 #define	UISUBCLASS_RF			0x01
504 #define	UIPROTO_BLUETOOTH		0x01
505 #define	UIPROTO_RNDIS			0x03
506 
507 #define	UICLASS_IAD		0xEF	/* Interface Association Descriptor */
508 #define	UISUBCLASS_SYNC			0x01
509 #define	UIPROTO_ACTIVESYNC		0x01
510 
511 #define	UICLASS_APPL_SPEC	0xfe
512 #define	UISUBCLASS_FIRMWARE_DOWNLOAD	1
513 #define	UISUBCLASS_IRDA			2
514 #define	UIPROTO_IRDA			0
515 
516 #define	UICLASS_VENDOR		0xff
517 #define	UISUBCLASS_XBOX360_CONTROLLER	0x5d
518 #define	UIPROTO_XBOX360_GAMEPAD	0x01
519 
520 struct usb_endpoint_descriptor {
521 	uByte	bLength;
522 	uByte	bDescriptorType;
523 	uByte	bEndpointAddress;
524 #define	UE_GET_DIR(a)	((a) & 0x80)
525 #define	UE_SET_DIR(a,d)	((a) | (((d)&1) << 7))
526 #define	UE_DIR_IN	0x80		/* IN-token endpoint, fixed */
527 #define	UE_DIR_OUT	0x00		/* OUT-token endpoint, fixed */
528 #define	UE_DIR_RX	0xfd		/* for internal use only! */
529 #define	UE_DIR_TX	0xfe		/* for internal use only! */
530 #define	UE_DIR_ANY	0xff		/* for internal use only! */
531 #define	UE_ADDR		0x0f
532 #define	UE_ADDR_ANY	0xff		/* for internal use only! */
533 #define	UE_GET_ADDR(a)	((a) & UE_ADDR)
534 	uByte	bmAttributes;
535 #define	UE_XFERTYPE	0x03
536 #define	UE_CONTROL	0x00
537 #define	UE_ISOCHRONOUS	0x01
538 #define	UE_BULK	0x02
539 #define	UE_INTERRUPT	0x03
540 #define	UE_BULK_INTR	0xfe		/* for internal use only! */
541 #define	UE_TYPE_ANY	0xff		/* for internal use only! */
542 #define	UE_GET_XFERTYPE(a)	((a) & UE_XFERTYPE)
543 #define	UE_ISO_TYPE	0x0c
544 #define	UE_ISO_ASYNC	0x04
545 #define	UE_ISO_ADAPT	0x08
546 #define	UE_ISO_SYNC	0x0c
547 #define	UE_GET_ISO_TYPE(a)	((a) & UE_ISO_TYPE)
548 #define	UE_ISO_USAGE	0x30
549 #define	UE_ISO_USAGE_DATA	0x00
550 #define	UE_ISO_USAGE_FEEDBACK	0x10
551 #define	UE_ISO_USAGE_IMPLICT_FB	0x20
552 #define	UE_GET_ISO_USAGE(a)	((a) & UE_ISO_USAGE)
553 	uWord	wMaxPacketSize;
554 #define	UE_ZERO_MPS 0xFFFF		/* for internal use only */
555 	uByte	bInterval;
556 } __packed;
557 typedef struct usb_endpoint_descriptor usb_endpoint_descriptor_t;
558 
559 struct usb_endpoint_ss_comp_descriptor {
560 	uByte	bLength;
561 	uByte	bDescriptorType;
562 	uByte	bMaxBurst;
563 	uByte	bmAttributes;
564 #define	UE_GET_BULK_STREAMS(x) ((x) & 0x0F)
565 #define	UE_GET_SS_ISO_MULT(x) ((x) & 0x03)
566 	uWord	wBytesPerInterval;
567 } __packed;
568 typedef struct usb_endpoint_ss_comp_descriptor
569 		usb_endpoint_ss_comp_descriptor_t;
570 
571 struct usb_string_descriptor {
572 	uByte	bLength;
573 	uByte	bDescriptorType;
574 	uWord	bString[126];
575 	uByte	bUnused;
576 } __packed;
577 typedef struct usb_string_descriptor usb_string_descriptor_t;
578 
579 #define	USB_MAKE_STRING_DESC(m,name)	\
580 static const struct {			\
581   uByte bLength;			\
582   uByte bDescriptorType;		\
583   uByte bData[sizeof((uint8_t []){m})];	\
584 } __packed name = {			\
585   .bLength = sizeof(name),		\
586   .bDescriptorType = UDESC_STRING,	\
587   .bData = { m },			\
588 }
589 
590 struct usb_string_lang {
591 	uByte bLength;
592 	uByte bDescriptorType;
593 	uByte bData[2];
594 } __packed;
595 typedef struct usb_string_lang usb_string_lang_t;
596 
597 struct usb_hub_descriptor {
598 	uByte	bDescLength;
599 	uByte	bDescriptorType;
600 	uByte	bNbrPorts;
601 	uWord	wHubCharacteristics;
602 #define	UHD_PWR			0x0003
603 #define	UHD_PWR_GANGED		0x0000
604 #define	UHD_PWR_INDIVIDUAL	0x0001
605 #define	UHD_PWR_NO_SWITCH	0x0002
606 #define	UHD_COMPOUND		0x0004
607 #define	UHD_OC			0x0018
608 #define	UHD_OC_GLOBAL		0x0000
609 #define	UHD_OC_INDIVIDUAL	0x0008
610 #define	UHD_OC_NONE		0x0010
611 #define	UHD_TT_THINK		0x0060
612 #define	UHD_TT_THINK_8		0x0000
613 #define	UHD_TT_THINK_16		0x0020
614 #define	UHD_TT_THINK_24		0x0040
615 #define	UHD_TT_THINK_32		0x0060
616 #define	UHD_PORT_IND		0x0080
617 	uByte	bPwrOn2PwrGood;		/* delay in 2 ms units */
618 #define	UHD_PWRON_FACTOR 2
619 	uByte	bHubContrCurrent;
620 	uByte	DeviceRemovable[32];	/* max 255 ports */
621 #define	UHD_NOT_REMOV(desc, i) \
622     (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
623 	uByte	PortPowerCtrlMask[1];	/* deprecated */
624 } __packed;
625 typedef struct usb_hub_descriptor usb_hub_descriptor_t;
626 
627 struct usb_hub_ss_descriptor {
628 	uByte	bLength;
629 	uByte	bDescriptorType;
630 	uByte	bNbrPorts;
631 	uWord	wHubCharacteristics;
632 	uByte	bPwrOn2PwrGood;		/* delay in 2 ms units */
633 	uByte	bHubContrCurrent;
634 	uByte	bHubHdrDecLat;
635 	uWord	wHubDelay;
636 	uByte	DeviceRemovable[32];	/* max 255 ports */
637 } __packed;
638 typedef struct usb_hub_ss_descriptor usb_hub_ss_descriptor_t;
639 
640 /* minimum HUB descriptor (8-ports maximum) */
641 struct usb_hub_descriptor_min {
642 	uByte	bDescLength;
643 	uByte	bDescriptorType;
644 	uByte	bNbrPorts;
645 	uWord	wHubCharacteristics;
646 	uByte	bPwrOn2PwrGood;
647 	uByte	bHubContrCurrent;
648 	uByte	DeviceRemovable[1];
649 	uByte	PortPowerCtrlMask[1];
650 } __packed;
651 typedef struct usb_hub_descriptor_min usb_hub_descriptor_min_t;
652 
653 struct usb_device_qualifier {
654 	uByte	bLength;
655 	uByte	bDescriptorType;
656 	uWord	bcdUSB;
657 	uByte	bDeviceClass;
658 	uByte	bDeviceSubClass;
659 	uByte	bDeviceProtocol;
660 	uByte	bMaxPacketSize0;
661 	uByte	bNumConfigurations;
662 	uByte	bReserved;
663 } __packed;
664 typedef struct usb_device_qualifier usb_device_qualifier_t;
665 
666 struct usb_otg_descriptor {
667 	uByte	bLength;
668 	uByte	bDescriptorType;
669 	uByte	bmAttributes;
670 #define	UOTG_SRP	0x01
671 #define	UOTG_HNP	0x02
672 } __packed;
673 typedef struct usb_otg_descriptor usb_otg_descriptor_t;
674 
675 /* OTG feature selectors */
676 #define	UOTG_B_HNP_ENABLE	3
677 #define	UOTG_A_HNP_SUPPORT	4
678 #define	UOTG_A_ALT_HNP_SUPPORT	5
679 
680 struct usb_status {
681 	uWord	wStatus;
682 /* Device status flags */
683 #define	UDS_SELF_POWERED		0x0001
684 #define	UDS_REMOTE_WAKEUP		0x0002
685 /* Endpoint status flags */
686 #define	UES_HALT			0x0001
687 } __packed;
688 typedef struct usb_status usb_status_t;
689 
690 struct usb_hub_status {
691 	uWord	wHubStatus;
692 #define	UHS_LOCAL_POWER			0x0001
693 #define	UHS_OVER_CURRENT		0x0002
694 	uWord	wHubChange;
695 } __packed;
696 typedef struct usb_hub_status usb_hub_status_t;
697 
698 struct usb_port_status {
699 	uWord	wPortStatus;
700 #define	UPS_CURRENT_CONNECT_STATUS	0x0001
701 #define	UPS_PORT_ENABLED		0x0002
702 #define	UPS_SUSPEND			0x0004
703 #define	UPS_OVERCURRENT_INDICATOR	0x0008
704 #define	UPS_RESET			0x0010
705 #define	UPS_PORT_L1			0x0020	/* USB 2.0 only */
706 /* The link-state bits are valid for Super-Speed USB HUBs */
707 #define	UPS_PORT_LINK_STATE_GET(x)	(((x) >> 5) & 0xF)
708 #define	UPS_PORT_LINK_STATE_SET(x)	(((x) & 0xF) << 5)
709 #define	UPS_PORT_LS_U0		0x00
710 #define	UPS_PORT_LS_U1		0x01
711 #define	UPS_PORT_LS_U2		0x02
712 #define	UPS_PORT_LS_U3		0x03
713 #define	UPS_PORT_LS_SS_DIS	0x04
714 #define	UPS_PORT_LS_RX_DET	0x05
715 #define	UPS_PORT_LS_SS_INA	0x06
716 #define	UPS_PORT_LS_POLL	0x07
717 #define	UPS_PORT_LS_RECOVER	0x08
718 #define	UPS_PORT_LS_HOT_RST	0x09
719 #define	UPS_PORT_LS_COMP_MODE	0x0A
720 #define	UPS_PORT_LS_LOOPBACK	0x0B
721 #define	UPS_PORT_LS_RESUME	0x0F
722 #define	UPS_PORT_POWER			0x0100
723 #define	UPS_PORT_POWER_SS		0x0200	/* super-speed only */
724 #define	UPS_LOW_SPEED			0x0200
725 #define	UPS_HIGH_SPEED			0x0400
726 #define	UPS_OTHER_SPEED			0x0600	/* currently FreeBSD specific */
727 #define	UPS_PORT_TEST			0x0800
728 #define	UPS_PORT_INDICATOR		0x1000
729 #define	UPS_PORT_MODE_DEVICE		0x8000	/* currently FreeBSD specific */
730 	uWord	wPortChange;
731 #define	UPS_C_CONNECT_STATUS		0x0001
732 #define	UPS_C_PORT_ENABLED		0x0002
733 #define	UPS_C_SUSPEND			0x0004
734 #define	UPS_C_OVERCURRENT_INDICATOR	0x0008
735 #define	UPS_C_PORT_RESET		0x0010
736 #define	UPS_C_PORT_L1			0x0020	/* USB 2.0 only */
737 #define	UPS_C_BH_PORT_RESET		0x0020	/* USB 3.0 only */
738 #define	UPS_C_PORT_LINK_STATE		0x0040
739 #define	UPS_C_PORT_CONFIG_ERROR		0x0080
740 } __packed;
741 typedef struct usb_port_status usb_port_status_t;
742 
743 /*
744  * The "USB_SPEED" macros defines all the supported USB speeds.
745  */
746 enum usb_dev_speed {
747 	USB_SPEED_VARIABLE,
748 	USB_SPEED_LOW,
749 	USB_SPEED_FULL,
750 	USB_SPEED_HIGH,
751 	USB_SPEED_SUPER,
752 };
753 #define	USB_SPEED_MAX	(USB_SPEED_SUPER+1)
754 
755 /*
756  * The "USB_REV" macros defines all the supported USB revisions.
757  */
758 enum usb_revision {
759 	USB_REV_UNKNOWN,
760 	USB_REV_PRE_1_0,
761 	USB_REV_1_0,
762 	USB_REV_1_1,
763 	USB_REV_2_0,
764 	USB_REV_2_5,
765 	USB_REV_3_0
766 };
767 #define	USB_REV_MAX	(USB_REV_3_0+1)
768 
769 /*
770  * Supported host controller modes.
771  */
772 enum usb_hc_mode {
773 	USB_MODE_HOST,		/* initiates transfers */
774 	USB_MODE_DEVICE,	/* bus transfer target */
775 	USB_MODE_DUAL		/* can be host or device */
776 };
777 #define	USB_MODE_MAX	(USB_MODE_DUAL+1)
778 
779 /*
780  * The "USB_STATE" enums define all the supported device states.
781  */
782 enum usb_dev_state {
783 	USB_STATE_DETACHED,
784 	USB_STATE_ATTACHED,
785 	USB_STATE_POWERED,
786 	USB_STATE_ADDRESSED,
787 	USB_STATE_CONFIGURED,
788 };
789 #define	USB_STATE_MAX	(USB_STATE_CONFIGURED+1)
790 
791 /*
792  * The "USB_EP_MODE" macros define all the currently supported
793  * endpoint modes.
794  */
795 enum usb_ep_mode {
796 	USB_EP_MODE_DEFAULT,
797 	USB_EP_MODE_STREAMS,	/* USB3.0 specific */
798 	USB_EP_MODE_HW_MASS_STORAGE,
799 	USB_EP_MODE_HW_SERIAL,
800 	USB_EP_MODE_HW_ETHERNET_CDC,
801 	USB_EP_MODE_HW_ETHERNET_NCM,
802 	USB_EP_MODE_MAX
803 };
804 #endif					/* _USB_STANDARD_H_ */
805