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