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