xref: /titanic_50/usr/src/uts/common/sys/usb/usbai.h (revision 1cb84fbf006414a451b65e461cfdb78736884f53)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_USB_USBAI_H
27 #define	_SYS_USB_USBAI_H
28 
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 /* This header file is for USBA2.0 */
35 #define	USBA_MAJOR_VER 2
36 #define	USBA_MINOR_VER 0
37 
38 /*
39  * USBAI: Interfaces Between USBA and Client Driver
40  *
41  *
42  * Universal USB device state management :
43  *
44  *	PWRED_DWN---<3----4>--ONLINE---<2-----1>-DISCONNECTED
45  *	    |			 ^		     |
46  *	    |			 6		     |
47  *	    |			 |		     |
48  *	    |			 5		     |
49  *	    |			 v		     |
50  *	    +----5>----------SUSPENDED----<5----7>---+
51  *
52  *	1 = Device Unplug
53  *	2 = Original Device reconnected
54  *	3 = Device idles for time T & transitions to low power state
55  *	4 = Remote wakeup by device OR Application kicking off IO to device
56  *	5 = Notification to save state prior to DDI_SUSPEND
57  *	6 = Notification to restore state after DDI_RESUME with correct device
58  *	7 = Notification to restore state after DDI_RESUME with device
59  *	    disconnected or a wrong device
60  *
61  *	NOTE: device states 0x80 to 0xff are device specific and can be
62  *		used by client drivers
63  */
64 #define	USB_DEV_ONLINE		1	/* device is online */
65 #define	USB_DEV_DISCONNECTED	2	/* indicates disconnect */
66 #define	USB_DEV_SUSPENDED	3	/* DDI_SUSPEND operation */
67 #define	USB_DEV_PWRED_DOWN	4	/* indicates power off state */
68 
69 
70 /*
71  * ***************************************************************************
72  * USBA error and status definitions
73  * ***************************************************************************
74  */
75 
76 
77 /*
78  * USBA function return values
79  */
80 #define	USB_SUCCESS		0	/* call success			  */
81 #define	USB_FAILURE		-1	/* unspecified USBA or HCD error  */
82 #define	USB_NO_RESOURCES	-2	/* no resources available	  */
83 #define	USB_NO_BANDWIDTH	-3	/* no bandwidth available	  */
84 #define	USB_NOT_SUPPORTED	-4	/* function not supported by HCD  */
85 #define	USB_PIPE_ERROR		-5	/* error occured on the pipe	  */
86 #define	USB_INVALID_PIPE	-6	/* pipe handle passed is invalid  */
87 #define	USB_NO_FRAME_NUMBER	-7	/* frame No or ASAP not specified */
88 #define	USB_INVALID_START_FRAME	-8	/* starting USB frame not valid	  */
89 #define	USB_HC_HARDWARE_ERROR	-9	/* usb host controller error	  */
90 #define	USB_INVALID_REQUEST	-10	/* request had invalid values	  */
91 #define	USB_INVALID_CONTEXT	-11	/* sleep flag in interrupt context */
92 #define	USB_INVALID_VERSION	-12	/* invalid version specified	  */
93 #define	USB_INVALID_ARGS	-13	/* invalid func args specified	  */
94 #define	USB_INVALID_PERM	-14	/* privileged operation		  */
95 #define	USB_BUSY		-15	/* busy condition		  */
96 
97 
98 /*
99  * USB request completion flags, more than one may be set.
100  * The following flags are returned after a recovery action by
101  * HCD or USBA (autoclearing) or callbacks from pipe_close,
102  * abort, reset, or stop polling.  More than one may be set.
103  *
104  * For sync requests, the client should check the request structure
105  * for this flag to determine what has happened.
106  *
107  * All callbacks are queued to preserve order.	Note that if a normal callback
108  * uses a kernel thread, order is not guaranteed since each callback may use
109  * its own thread.  The next request will be submitted to the
110  * HCD after the threads exits.
111  *
112  * Exception callbacks using a kernel thread may do auto clearing and no
113  * new request will be started until this thread has completed its work.
114  */
115 typedef enum {
116 	USB_CB_NO_INFO		= 0x00, /* no exception */
117 	USB_CB_STALL_CLEARED	= 0x01,	/* func stall cleared */
118 	USB_CB_FUNCTIONAL_STALL	= 0x02,	/* func stall occurred */
119 	USB_CB_PROTOCOL_STALL	= 0x04,	/* protocal stall occurred */
120 	USB_CB_RESET_PIPE	= 0x10, /* pipe was reset */
121 	USB_CB_ASYNC_REQ_FAILED = 0x80, /* thread couldn't be started */
122 	USB_CB_NO_RESOURCES	= 0x100, /* no resources */
123 	USB_CB_SUBMIT_FAILED	= 0x200, /* req was queued then submitted */
124 					/* to HCD which rejected it */
125 	USB_CB_INTR_CONTEXT	= 0x400 /* Callback is in interrupt context. */
126 } usb_cb_flags_t;
127 
128 
129 /*
130  * completion reason
131  *
132  * Set by HCD; only one can be set.
133  */
134 typedef enum {
135 	USB_CR_OK		= 0,	/* no errors detected		*/
136 	USB_CR_CRC		= 1,	/* crc error detected		*/
137 	USB_CR_BITSTUFFING	= 2,	/* bit stuffing violation	*/
138 	USB_CR_DATA_TOGGLE_MM	= 3,	/* d/t PID did not match	*/
139 	USB_CR_STALL		= 4,	/* e/p returned stall PID	*/
140 	USB_CR_DEV_NOT_RESP	= 5,	/* device not responding	*/
141 	USB_CR_PID_CHECKFAILURE = 6,	/* check bits on PID failed	*/
142 	USB_CR_UNEXP_PID	= 7,	/* receive PID was not valid	*/
143 	USB_CR_DATA_OVERRUN	= 8,	/* data size exceeded		*/
144 	USB_CR_DATA_UNDERRUN	= 9,	/* less data received		*/
145 	USB_CR_BUFFER_OVERRUN	= 10,	/* memory write can't keep up	*/
146 	USB_CR_BUFFER_UNDERRUN	= 11,	/* buffer underrun		*/
147 	USB_CR_TIMEOUT		= 12,	/* command timed out		*/
148 	USB_CR_NOT_ACCESSED	= 13,	/* Not accessed by hardware	*/
149 	USB_CR_NO_RESOURCES	= 14,	/* no resources			*/
150 	USB_CR_UNSPECIFIED_ERR	= 15,	/* unspecified usba or hcd err	*/
151 	USB_CR_STOPPED_POLLING	= 16,	/* intr/isoc IN polling stopped	*/
152 	USB_CR_PIPE_CLOSING	= 17,	/* intr/isoc IN pipe closed	*/
153 	USB_CR_PIPE_RESET	= 18,	/* intr/isoc IN pipe reset	*/
154 	USB_CR_NOT_SUPPORTED	= 19,	/* command not supported	*/
155 	USB_CR_FLUSHED		= 20,	/* this request was flushed	*/
156 	USB_CR_HC_HARDWARE_ERR	= 21	/* usb host controller error	*/
157 } usb_cr_t;
158 
159 
160 /*
161  * ***************************************************************************
162  * General definitions, used all over
163  * ***************************************************************************
164  *
165  *	A pipe handle is returned by usb_pipe_open() on success for
166  *	all pipes except the default pipe which is accessed from
167  *	the registration structure.  Placed here as forward referenced by
168  *	usb_client_dev_data_t below.
169  *
170  *	The pipe_handle is opaque to the client driver.
171  */
172 typedef	struct usb_pipe_handle	*usb_pipe_handle_t;
173 
174 /*
175  * General opaque pointer.
176  */
177 typedef struct usb_opaque *usb_opaque_t;
178 
179 
180 /*
181  * USB flags argument to USBA interfaces
182  */
183 typedef enum {
184 	/* do not block until resources are available */
185 	USB_FLAGS_NOSLEEP		= 0x0000,
186 	/* block until resources are available */
187 	USB_FLAGS_SLEEP			= 0x0100,
188 	/* reserved */
189 	USB_FLAGS_RESERVED		= 0xFE00
190 } usb_flags_t;
191 
192 
193 /*
194  * ***************************************************************************
195  * Descriptor definitions (from USB 2.0 specification, chapter 9)
196  * ***************************************************************************
197  */
198 
199 
200 /*
201  * USB Descriptor Management
202  *
203  * Standard USB descriptors:
204  *
205  * USB devices present their configuration information in response to
206  * a GET_DESCRIPTOR request in a form which is little-endian and,
207  * for multibyte integers, unaligned.  It is also position-dependent,
208  * which makes non-sequential access to particular interface or
209  * endpoint data inconvenient.
210  * A GET_DESCRIPTOR request may yield a chunk of data that contains
211  * multiple descriptor types.  For example, a GET_DESCRIPTOR request
212  * for a CONFIGURATION descriptor could return the configuration
213  * descriptor followed by an interface descriptor and the relevant
214  * endpoint descriptors.
215  *
216  * usb_get_dev_data() interface provides an easy way to get all
217  * the descriptors and avoids parsing standard descriptors by each
218  * client driver
219  *
220  * usb_dev_descr:
221  *	usb device descriptor, refer to	USB 2.0/9.6.1,
222  */
223 typedef struct usb_dev_descr {
224 	uint8_t		bLength;	/* descriptor size		*/
225 	uint8_t		bDescriptorType; /* set to DEVICE		*/
226 	uint16_t	bcdUSB;		/* USB spec rel. number	in bcd	*/
227 	uint8_t		bDeviceClass;	/* class code			*/
228 	uint8_t		bDeviceSubClass; /* sub	class code		*/
229 	uint8_t		bDeviceProtocol; /* protocol code		*/
230 	uint8_t		bMaxPacketSize0; /* max	pkt size of e/p	0	*/
231 	uint16_t	idVendor;	/* vendor ID			*/
232 	uint16_t	idProduct;	/* product ID			*/
233 	uint16_t	bcdDevice;	/* device release number in bcd	*/
234 	uint8_t		iManufacturer;	/* manufacturing string		*/
235 	uint8_t		iProduct;	/* product string		*/
236 	uint8_t		iSerialNumber;	/* serial number string index	*/
237 	uint8_t		bNumConfigurations; /* #configs for device	*/
238 } usb_dev_descr_t;
239 
240 
241 /*
242  * USB Device Qualifier Descriptor
243  *
244  * The device_qualifier descriptor describes information about a High
245  * speed capable device that would change if the device were operating
246  * at other (Full) speed. Example: if the device is currently operating
247  * at Full-speed, the device_qualifier returns information about how if
248  * would operate at high-speed and vice-versa.
249  *
250  * usb_dev_qlf_descr:
251  *
252  *	usb device qualifier descriptor, refer to USB 2.0/9.6.2
253  */
254 typedef struct usb_dev_qlf_descr {
255 	uint8_t		bLength;	/* descriptor size		*/
256 	uint8_t		bDescriptorType; /* set to DEVICE		*/
257 	uint16_t	bcdUSB;		/* USB spec rel. number	in bcd	*/
258 	uint8_t		bDeviceClass;	/* class code			*/
259 	uint8_t		bDeviceSubClass; /* sub	class code		*/
260 	uint8_t		bDeviceProtocol; /* protocol code		*/
261 	uint8_t		bMaxPacketSize0; /* max	pkt size of e/p	0	*/
262 	uint8_t		bNumConfigurations; /* #configs for device	*/
263 	uint8_t		bReserved;	/* reserved field		*/
264 } usb_dev_qlf_descr_t;
265 
266 
267 /*
268  * usb_cfg_descr:
269  *	usb configuration descriptor, refer to USB 2.0/9.6.3
270  */
271 typedef struct usb_cfg_descr {
272 	uint8_t		bLength;	/* descriptor size		*/
273 	uint8_t		bDescriptorType; /* set to CONFIGURATION	*/
274 	uint16_t	wTotalLength;	/* total length of data returned */
275 	uint8_t		bNumInterfaces;	/* # interfaces	in config	*/
276 	uint8_t		bConfigurationValue; /* arg for SetConfiguration */
277 	uint8_t		iConfiguration;	/* configuration string		*/
278 	uint8_t		bmAttributes;	/* config characteristics	*/
279 	uint8_t		bMaxPower;	/* max pwr consumption		*/
280 } usb_cfg_descr_t;
281 
282 /*
283  * Default configuration index setting for devices with multiple
284  * configurations. Note the distinction between config index and config
285  * number
286  */
287 #define	USB_DEV_DEFAULT_CONFIG_INDEX	0
288 
289 /*
290  * bmAttribute values for Configuration Descriptor
291  */
292 #define	USB_CFG_ATTR_SELFPWR		0x40
293 #define	USB_CFG_ATTR_REMOTE_WAKEUP	0x20
294 
295 
296 /*
297  * USB Other Speed Configuration Descriptor
298  *
299  * The other_speed_configuration descriptor describes a configuration of
300  * a High speed capable device if it were operating at its other possible
301  * (Full) speed and vice-versa.
302  *
303  * usb_other_speed_cfg_descr:
304  *	usb other speed configuration descriptor, refer to USB 2.0/9.6.4
305  */
306 typedef struct usb_other_speed_cfg_descr {
307 	uint8_t		bLength;	/* descriptor size		*/
308 	uint8_t		bDescriptorType; /* set to CONFIGURATION	*/
309 	uint16_t	wTotalLength;	/* total length of data returned */
310 	uint8_t		bNumInterfaces;	/* # interfaces	in config	*/
311 	uint8_t		bConfigurationValue; /* arg for SetConfiguration */
312 	uint8_t		iConfiguration;	/* configuration string		*/
313 	uint8_t		bmAttributes;	/* config characteristics	*/
314 	uint8_t		bMaxPower;	/* max pwr consumption		*/
315 } usb_other_speed_cfg_descr_t;
316 
317 
318 /*
319  * usb_ia_descr:
320  *	usb interface association descriptor, refer to USB 2.0 ECN(IAD)
321  */
322 typedef  struct usb_ia_descr {
323 	uint8_t		bLength;		/* descriptor size	*/
324 	uint8_t		bDescriptorType;	/* INTERFACE_ASSOCIATION */
325 	uint8_t		bFirstInterface;	/* 1st interface number */
326 	uint8_t		bInterfaceCount;	/* number of interfaces */
327 	uint8_t		bFunctionClass;		/* class code		*/
328 	uint8_t		bFunctionSubClass;	/* sub class code	*/
329 	uint8_t		bFunctionProtocol;	/* protocol code	*/
330 	uint8_t		iFunction;		/* description string	*/
331 } usb_ia_descr_t;
332 
333 
334 /*
335  * usb_if_descr:
336  *	usb interface descriptor, refer	to USB 2.0/9.6.5
337  */
338 typedef  struct usb_if_descr {
339 	uint8_t		bLength;		/* descriptor size	*/
340 	uint8_t		bDescriptorType;	/* set to INTERFACE	*/
341 	uint8_t		bInterfaceNumber;	/* interface number	*/
342 	uint8_t		bAlternateSetting;	/* alt. interface number */
343 	uint8_t		bNumEndpoints;		/* # of endpoints	*/
344 	uint8_t		bInterfaceClass;	/* class code		*/
345 	uint8_t		bInterfaceSubClass;	/* sub class code	*/
346 	uint8_t		bInterfaceProtocol;	/* protocol code	*/
347 	uint8_t		iInterface;		/* description string	*/
348 } usb_if_descr_t;
349 
350 
351 /*
352  * usb_ep_descr:
353  *	usb endpoint descriptor, refer to USB 2.0/9.6.6
354  */
355 typedef struct usb_ep_descr {
356 	uint8_t		bLength;		/* descriptor size	*/
357 	uint8_t		bDescriptorType;	/* set to ENDPOINT	*/
358 	uint8_t		bEndpointAddress;	/* address of this e/p */
359 	uint8_t		bmAttributes;		/* transfer type	*/
360 	uint16_t	wMaxPacketSize;		/* maximum packet size	*/
361 	uint8_t		bInterval;		/* e/p polling interval */
362 } usb_ep_descr_t;
363 
364 /*
365  * bEndpointAddress masks
366  */
367 #define	USB_EP_NUM_MASK		0x0F		/* endpoint number mask */
368 #define	USB_EP_DIR_MASK		0x80		/* direction mask */
369 #define	USB_EP_DIR_OUT		0x00		/* OUT endpoint */
370 #define	USB_EP_DIR_IN		0x80		/* IN endpoint */
371 
372 /*
373  * bmAttribute transfer types for endpoints
374  */
375 #define	USB_EP_ATTR_MASK	0x03		/* transfer type mask */
376 #define	USB_EP_ATTR_CONTROL	0x00		/* control transfer */
377 #define	USB_EP_ATTR_ISOCH	0x01		/* isochronous transfer */
378 #define	USB_EP_ATTR_BULK	0x02		/* bulk transfer */
379 #define	USB_EP_ATTR_INTR	0x03		/* interrupt transfer */
380 
381 /*
382  * bmAttribute synchronization types for endpoints (isochronous only)
383  */
384 #define	USB_EP_SYNC_MASK	0x0C		/* synchronization mask */
385 #define	USB_EP_SYNC_NONE	0x00		/* no synchronization */
386 #define	USB_EP_SYNC_ASYNC	0x04		/* asynchronous */
387 #define	USB_EP_SYNC_ADPT	0x08		/* adaptive */
388 #define	USB_EP_SYNC_SYNC	0x0C		/* synchronous */
389 
390 /*
391  * bmAttribute synchronization feedback types for endpoints (isochronous only)
392  */
393 #define	USB_EP_USAGE_MASK	0x30		/* sync feedback mask */
394 #define	USB_EP_USAGE_DATA	0x00		/* data endpoint */
395 #define	USB_EP_USAGE_FEED	0x10		/* feedback endpoint */
396 #define	USB_EP_USAGE_IMPL	0x20		/* implicit feedback endpoint */
397 
398 /*
399  * wMaxPacketSize values for endpoints (isoch and interrupt, high speed only)
400  */
401 #define	USB_EP_MAX_PKTSZ_MASK	0x03FF		/* Mask for packetsize bits */
402 #define	USB_EP_MAX_XACTS_MASK	0x0C00		/* Max Transactns/microframe */
403 #define	USB_EP_MAX_XACTS_SHIFT	10		/* Above is 10 bits from end */
404 
405 /*
406  * Ranges for endpoint parameter values.
407  */
408 
409 /* Min and Max NAK rates for high sped control endpoints. */
410 #define	USB_EP_MIN_HIGH_CONTROL_INTRVL	0
411 #define	USB_EP_MAX_HIGH_CONTROL_INTRVL	255
412 
413 /* Min and Max NAK rates for high speed bulk endpoints. */
414 #define	USB_EP_MIN_HIGH_BULK_INTRVL	0
415 #define	USB_EP_MAX_HIGH_BULK_INTRVL	255
416 
417 /* Min and Max polling intervals for low, full speed interrupt endpoints. */
418 #define	USB_EP_MIN_LOW_INTR_INTRVL	1
419 #define	USB_EP_MAX_LOW_INTR_INTRVL	255
420 #define	USB_EP_MIN_FULL_INTR_INTRVL	1
421 #define	USB_EP_MAX_FULL_INTR_INTRVL	255
422 
423 /*
424  * Min and Max polling intervals for high speed interrupt endpoints, and for
425  * isochronous endpoints.
426  * Note that the interval is 2**(value-1).  See Section 9.6.6 of USB 2.0 spec.
427  */
428 #define	USB_EP_MIN_HIGH_INTR_INTRVL	1
429 #define	USB_EP_MAX_HIGH_INTR_INTRVL	16
430 #define	USB_EP_MIN_FULL_ISOCH_INTRVL	1
431 #define	USB_EP_MAX_FULL_ISOCH_INTRVL	16
432 #define	USB_EP_MIN_HIGH_ISOCH_INTRVL	1
433 #define	USB_EP_MAX_HIGH_ISOCH_INTRVL	16
434 
435 /*
436  * usb_string_descr:
437  *	usb string descriptor, refer to	 USB 2.0/9.6.7
438  */
439 typedef struct usb_string_descr {
440 	uint8_t		bLength;		/* descr size */
441 	uint8_t		bDescriptorType;	/* set to STRING */
442 	uint8_t		bString[1];		/* variable length unicode */
443 						/* encoded string	*/
444 } usb_string_descr_t;
445 
446 #define	USB_MAXSTRINGLEN	255		/* max string descr length */
447 
448 
449 /*
450  * ***************************************************************************
451  * Client driver registration with USBA
452  * ***************************************************************************
453  *
454  *	The client registers with USBA during attach in two steps
455  *	using usb_client_attach() and usb_get_dev_data(). On completion, the
456  *	registration data has been initialized.  Most data items are
457  *	straightforward.  Among the items returned in the data is the tree of
458  *	parsed descriptors, in dev_cfg;	 the number of configurations parsed,
459  *	in dev_n_cfg; a pointer to the current configuration in the tree,
460  *	in dev_curr_cfg; the index of the first valid interface in the
461  *	tree, in dev_curr_if, and a parse level that accurately reflects what
462  *	is in the tree, in dev_parse_level.
463  */
464 
465 
466 /*
467  * ***************************************************************************
468  * Data structures used in the configuration tree
469  * ***************************************************************************
470  */
471 
472 /*
473  * Tree data structure for each configuration in the tree
474  */
475 typedef struct usb_cfg_data {
476 	struct usb_cfg_descr	cfg_descr;	/* parsed config descr */
477 	struct usb_if_data	*cfg_if;	/* interfaces for this cfg */
478 						/* indexed by interface num */
479 	struct usb_cvs_data	*cfg_cvs;	/* class/vendor specific */
480 						/* descrs mod/extend cfg */
481 	char			*cfg_str;	/* string descriptor */
482 	uint_t			cfg_n_if;	/* #elements in cfg_if[] */
483 	uint_t			cfg_n_cvs;	/* #elements in cfg_cvs[] */
484 	uint_t			cfg_strsize;	/* size of string descr */
485 } usb_cfg_data_t;
486 
487 
488 /*
489  * Tree data structure for each alternate interface set
490  * in each represented configuration
491  */
492 typedef struct usb_if_data {
493 	struct usb_alt_if_data	*if_alt;	/* sparse array of alts */
494 						/* indexed by alt setting */
495 	uint_t			if_n_alt;	/* #elements in if_alt[] */
496 } usb_if_data_t;
497 
498 
499 /*
500  * Tree data structure for each alternate of each alternate interface set
501  */
502 typedef struct usb_alt_if_data {
503 	usb_if_descr_t		altif_descr;	/* parsed alternate if descr */
504 	struct usb_ep_data	*altif_ep;	/* endpts for alt if */
505 						/* (not a sparse array */
506 	struct usb_cvs_data	*altif_cvs;	/* cvs for this alt if */
507 	char			*altif_str;	/* string descriptor */
508 	uint_t			altif_n_ep;	/* #elements in altif_ep[] */
509 	uint_t			altif_n_cvs;	/* #elements in  altif_cvs[] */
510 	uint_t			altif_strsize;	/* size of string descr */
511 } usb_alt_if_data_t;
512 
513 
514 /*
515  * Tree data structure for each endpoint of each alternate
516  */
517 typedef struct usb_ep_data {
518 	usb_ep_descr_t		ep_descr;	/* endpoint descriptor */
519 	struct usb_cvs_data	*ep_cvs;	/* cv mod/extending this ep */
520 	uint_t			ep_n_cvs;	/* #elements in ep_cvs[] */
521 } usb_ep_data_t;
522 
523 
524 /*
525  * Tree data structure for each class/vendor specific descriptor
526  */
527 typedef struct usb_cvs_data {
528 	uchar_t			*cvs_buf;	/* raw data of cvs descr */
529 	uint_t			cvs_buf_len;	/* cvs_buf size */
530 } usb_cvs_data_t;
531 
532 
533 /*
534  *	Parse_level determines the extent to which the tree is built, the amount
535  *	of parsing usb_client_attach() is to do.  It has the following values:
536  *
537  *	USB_PARSE_LVL_NONE - Build no tree.  dev_n_cfg will return 0, dev_cfg
538  *			     will return NULL, the dev_curr_xxx fields will be
539  *			     invalid.
540  *	USB_PARSE_LVL_IF   - Parse configured interface only, if configuration#
541  *			     and interface properties are set (as when different
542  *			     interfaces are viewed by the OS as different device
543  *			     instances). If an OS device instance is set up to
544  *			     represent an entire physical device, this works
545  *			     like USB_PARSE_LVL_ALL.
546  *	USB_PARSE_LVL_CFG  - Parse entire configuration of configured interface
547  *			     only.  This is like USB_PARSE_LVL_IF except entire
548  *			     configuration is returned.
549  *	USB_PARSE_LVL_ALL  - Parse entire device (all configurations), even
550  *			     when driver is bound to a single interface of a
551  *			     single configuration.
552  */
553 typedef enum {
554 	USB_PARSE_LVL_NONE		= 0,
555 	USB_PARSE_LVL_IF		= 1,
556 	USB_PARSE_LVL_CFG		= 2,
557 	USB_PARSE_LVL_ALL		= 3
558 } usb_reg_parse_lvl_t;
559 
560 
561 /*
562  * Registration data returned by usb_get_dev_data().  Configuration tree roots
563  * are returned in dev_cfg array.
564  */
565 typedef struct usb_client_dev_data {
566 	usb_pipe_handle_t	dev_default_ph;	/* default pipe handle */
567 	ddi_iblock_cookie_t	dev_iblock_cookie; /* for mutex_init's */
568 	struct usb_dev_descr	*dev_descr;	/* cooked device descriptor */
569 	char			*dev_mfg;	/* manufacturing ID */
570 	char			*dev_product;	/* product ID */
571 	char			*dev_serial;	/* serial number */
572 	usb_reg_parse_lvl_t	dev_parse_level; /* USB_PARSE_LVL_* flag */
573 	struct usb_cfg_data	*dev_cfg;	/* configs for this device */
574 						/* indexed by config index */
575 	uint_t			dev_n_cfg;	/* #elements in dev_cfg[] */
576 	struct usb_cfg_data	*dev_curr_cfg;	/* current cfg */
577 	int			dev_curr_if;	/* current interface number */
578 } usb_client_dev_data_t;
579 
580 
581 /*
582  * ***************************************************************************
583  * Device configuration descriptor tree functions
584  * ***************************************************************************
585  */
586 
587 /*
588  * usb_get_dev_data:
589  *	returns initialized registration data. 	Most data items are clear.
590  *	Among the items returned is the tree ofparsed descriptors in dev_cfg;
591  *	and the number of configurations parsed in dev_n_cfg.
592  *
593  * Arguments:
594  *	dip		- pointer to devinfo node of the client
595  *	dev_data	- return registration data at this address
596  *	parse_level	- See above
597  *	flags		- None used
598  *
599  * Return Values:
600  *	USB_SUCCESS		- usb_register_client succeeded
601  *	USB_INVALID_ARGS	- received null dip or reg argument
602  *	USB_INVALID_CONTEXT	- called with sleep from callback context
603  *	USB_FAILURE		- bad descriptor info or other internal failure
604  *
605  * Notes:
606  * 	1) The non-standard USB descriptors are returned in RAW format.
607  *
608  *	2) The registration data is unshared. Each client receives its own copy.
609  *	(The default control pipe may be shared, even though its tree
610  *	description will be unique per device.)
611  *
612  */
613 int usb_get_dev_data(
614 	dev_info_t			*dip,
615 	usb_client_dev_data_t		**dev_data,
616 	usb_reg_parse_lvl_t		parse_level,
617 	usb_flags_t			flags);
618 
619 /*
620  * usb_free_dev_data:
621  * undoes what usb_get_dev_data() set up.  It releases
622  * memory for all strings, descriptors, and trees set up by usb_get_dev_data().
623  *
624  * Arguments:
625  *	dip		- pointer to devinfo node of the client
626  *	dev_data	- pointer to registration data containing the tree.
627  */
628 void usb_free_dev_data(
629 	dev_info_t			*dip,
630 	usb_client_dev_data_t		*dev_data);
631 
632 /*
633  * usb_free_descr_tree:
634  *	Take down the configuration tree while leaving the rest	of the
635  *	registration intact.  This can be used, for example, after attach has
636  *	copied any descriptors it needs from the tree, but the rest of the
637  *	registration data needs to remain intact.
638  *
639  *	The following usb_client_dev_data_t fields will be modified:
640  *		dev_cfg will be NULL
641  *		dev_n_cfg will be 0
642  *		dev_curr_cfg_ndx and dev_curr_if will be invalid
643  *		dev_parse_level will be USB_REG_DESCR_NONE
644  *
645  * Arguments:
646  *	dip		- pointer to devinfo node of the client
647  *	dev_data	- pointer to registration data containing the tree.
648  */
649 void usb_free_descr_tree(
650 	dev_info_t			*dip,
651 	usb_client_dev_data_t		*dev_data);
652 
653 
654 /*
655  * usb_print_descr_tree:
656  *	Dump to the screen a descriptor tree as returned by
657  *	usbai_register_client.
658  *
659  * Arguments:
660  *	dip		- pointer to devinfo of the client
661  *	dev_data	- pointer to registration area containing the tree
662  *
663  * Returns:
664  *	USB_SUCCESS		- tree successfully dumped
665  *	USB_INVALID_CONTEXT	- called from callback context
666  *	USB_INVALID_ARGS	- bad arguments given
667  */
668 int usb_print_descr_tree(
669 	dev_info_t		*dip,
670 	usb_client_dev_data_t	*dev_data);
671 
672 
673 /*
674  * ***************************************************************************
675  * Registration and versioning
676  * ***************************************************************************
677  */
678 
679 
680 /*
681  * USBA client drivers are required to define USBDRV_MAJOR_VER
682  * USBDRV_MINOR_VER and pass USBDRV_VERSION as the version
683  * number to usb_client_attach
684  */
685 #if !defined(USBA_MAJOR_VER) || !defined(USBA_MINOR_VER)
686 #error incorrect USBA header
687 #endif
688 
689 /*
690  * Driver major version must be the same as USBA major version, and
691  * driver minor version must be <= USBA minor version
692  */
693 #if !defined(USBA_FRAMEWORK)
694 #if defined(USBDRV_MAJOR_VER) && defined(USBDRV_MINOR_VER)
695 
696 #if (USBDRV_MAJOR_VER != USBA_MAJOR_VER)
697 #error USBA and driver major versions do not match
698 #endif
699 #if (USBDRV_MINOR_VER > USBA_MINOR_VER)
700 #error USBA and driver minor versions do not match
701 #endif
702 
703 #endif
704 #endif
705 
706 #define	USBA_MAKE_VER(major, minor) ((major) << 8 | (minor))
707 #define	USBA_GET_MAJOR(ver) ((ver) >> 8)
708 #define	USBA_GET_MINOR(ver) ((ver) & 0xff)
709 
710 #define	USBDRV_VERSION	USBA_MAKE_VER(USBDRV_MAJOR_VER, USBDRV_MINOR_VER)
711 
712 
713 /*
714  * usb_client_attach:
715  *
716  * Arguments:
717  *	dip		- pointer to devinfo node of the client
718  *	version 	- USBA registration version number
719  *	flags		- None used
720  *
721  * Return Values:
722  *	USB_SUCCESS		- attach succeeded
723  *	USB_INVALID_ARGS	- received null dip or reg argument
724  *	USB_INVALID_CONTEXT	- called with sleep from callback context
725  *				  or not at attach time
726  *	USB_INVALID_VERSION	- version argument is incorrect.
727  *	USB_FAILURE		- other internal failure
728  */
729 int usb_client_attach(
730 	dev_info_t			*dip,
731 	uint_t				version,
732 	usb_flags_t			flags);
733 
734 /*
735  * usb_client_detach:
736  *
737  * Arguments:
738  *	dip		- pointer to devinfo node of the client
739  *	dev_data	- pointer to data to free. may be NULL
740  */
741 void usb_client_detach(
742 	dev_info_t			*dip,
743 	struct usb_client_dev_data	*dev_data);
744 
745 /*
746  * ***************************************************************************
747  * Functions for parsing / retrieving data from the descriptor tree
748  * ***************************************************************************
749  */
750 
751 /*
752  * Function for unpacking any kind of little endian data, usually desriptors
753  *
754  * Arguments:
755  *	format		- string indicating the format in c, s, w, eg. "2c4ws"
756  *			  which describes 2 bytes, 4 int, one short.
757  *			  The number prefix parses the number of items of
758  *			  the following type.
759  *	data		- pointer to the LE data buffer
760  *	datalen		- length of the data
761  *	structure	- pointer to return structure where the unpacked data
762  *			  will be written
763  *	structlen	- length of the return structure
764  *
765  * return value:
766  *	total number of bytes of the original data that was unpacked
767  *	or USB_PARSE_ERROR
768  */
769 #define	USB_PARSE_ERROR	0
770 
771 size_t usb_parse_data(
772 	char			*format,
773 	uchar_t 		*data,
774 	size_t			datalen,
775 	void			*structure,
776 	size_t			structlen);
777 
778 /*
779  * usb_lookup_ep_data:
780  *	Function to get specific endpoint data
781  *	This function will not access the device.
782  *
783  * Arguments:
784  *	dip		- pointer to dev info
785  *	dev_datap	- pointer to registration data
786  *	interface	- requested interface
787  *	alternate	- requested alternate
788  *	skip		- number of endpoints which match the requested type and
789  *			  direction to skip before finding one to retrieve
790  *	type		- endpoint type
791  *	direction	- endpoint direction: USB_EP_DIR_IN/OUT or none
792  *
793  * Return Values:
794  *	NULL or an endpoint data pointer
795  */
796 usb_ep_data_t *usb_lookup_ep_data(
797 	dev_info_t		*dip,
798 	usb_client_dev_data_t	*dev_datap,
799 	uint_t			interface,
800 	uint_t			alternate,
801 	uint_t			skip,
802 	uint_t			type,
803 	uint_t			direction);
804 
805 
806 /* Language ID for string descriptors. */
807 #define	USB_LANG_ID		0x0409		/* English, US */
808 
809 /*
810  * usb_get_string_descr:
811  *	Reads the string descriptor.  This function access the device and
812  *	blocks.
813  *
814  * Arguments:
815  *	dip		- pointer to devinfo of the client.
816  *	langid		- LANGID to read different LOCALEs.
817  *	index		- index to the string.
818  *	buf		- user provided buffer for string descriptor.
819  *	buflen		- user provided length of the buffer.
820  *
821  * Return Values:
822  *	USB_SUCCESS	- descriptor is valid.
823  *	USB_FAILURE	- full descriptor could not be retrieved.
824  */
825 int usb_get_string_descr(
826 	dev_info_t		*dip,
827 	uint16_t		langid,
828 	uint8_t			index,
829 	char			*buf,
830 	size_t			buflen);
831 
832 
833 /*
834  * ***************************************************************************
835  * Addressing utility functions
836  * ***************************************************************************
837  */
838 
839 /*
840  * usb_get_addr returns the current usb address, mostly for debugging
841  * purposes. The address may change after hotremove/insert.
842  * This address will not change on a disconnect/reconnect of open device.
843  */
844 int usb_get_addr(dev_info_t *dip);
845 
846 
847 /*
848  * usb_get_if_number returns USB_COMBINED_NODE or USB_DEVICE_NODE
849  * if the driver is responsible for the entire device.
850  * Otherwise it returns the interface number.
851  */
852 #define	USB_COMBINED_NODE	-1
853 #define	USB_DEVICE_NODE		-2
854 
855 int usb_get_if_number(
856 	dev_info_t		*dip);
857 
858 boolean_t usb_owns_device(
859 	dev_info_t		*dip);
860 
861 
862 /*
863  * ***************************************************************************
864  * Pipe	Management definitions and functions
865  * ***************************************************************************
866  */
867 
868 
869 /*
870  *
871  * usb_pipe_state:
872  *
873  * PIPE_STATE_IDLE:
874  *	The pipe's policy is set, but the pipe currently isn't transferring
875  *	data.
876  *
877  * PIPE_STATE_ACTIVE:
878  *	The pipe's policy has been set, and the pipe is able to transmit data.
879  *	When a control or bulk pipe is opened, the pipe's state is
880  *	automatically set to PIPE_STATE_ACTIVE.  For an interrupt or
881  *	isochronous pipe, the pipe state becomes PIPE_STATE_ACTIVE once
882  *	the polling on the pipe has been initiated.
883  *
884  * PIPE_STATE_ERROR:
885  *	The device has generated a error on the pipe.  The client driver
886  *	must call usb_pipe_reset() to clear any leftover state that's associated
887  *	with the pipe, clear the data toggle, and reset the state of the pipe.
888  *
889  *	Calling usb_pipe_reset() on a control or bulk pipe resets the state to
890  *	PIPE_STATE_ACTIVE.  Calling usb_pipe_reset() on an interrupt or
891  *	isochronous pipe, resets the state to PIPE_STATE_IDLE.
892  *
893  * State Diagram for Bulk/Control
894  *
895  *			+-<--normal completion------------------<-------^
896  *			|						|
897  *			V						|
898  * usb_pipe_open-->[PIPE_STATE_IDLE]-usb_pipe_*_xfer->[PIPE_STATE_ACTIVE]
899  *			^						|
900  *			|						v
901  *			- usb_pipe_reset<-[PIPE_STATE_ERROR]<-device error
902  *
903  * State Diagram for Interrupt/Isochronous IN
904  *
905  *			+-<--usb_pipe_stop_isoc/intr_polling----<-------^
906  *			|						|
907  *			V						|
908  * usb_pipe_open-->[PIPE_STATE_IDLE]-usb_pipe_*_xfer->[PIPE_STATE_ACTIVE]
909  *			^						|
910  *			|						v
911  *			+ usb_pipe_reset<-[PIPE_STATE_ERROR]<-device error
912  *
913  * State Diagram for Interrupt/Isochronous OUT
914  *
915  *			+-<--normal completion------------------<-------^
916  *			|						|
917  *			V						|
918  * usb_pipe_open-->[PIPE_STATE_IDLE]-usb_pipe_*_xfer->[PIPE_STATE_ACTIVE]
919  *			^						|
920  *			|						v
921  *			+ usb_pipe_reset<-[PIPE_STATE_ERROR]<-device error
922  *
923  *
924  * The following table indicates which operations are allowed with each
925  * pipe state:
926  *
927  * -------------------------------------------------------------------------+
928  * ctrl/bulk	| idle	| active     | error  | sync closing | async closing|
929  * -------------------------------------------------------------------------+
930  * pipe xfer	|  OK	|queue (USBA)| reject | reject	     | reject	    |
931  * pipe reset	| no-op | OK	     |	OK    | reject	     | reject	    |
932  * pipe close	|  OK	| wait&close |	OK    | no-op	     | no-op	    |
933  * -------------------------------------------------------------------------+
934  *
935  * -------------------------------------------------------------------------+
936  * intr/isoc IN | idle	| active     | error  | sync closing | async closing|
937  * -------------------------------------------------------------------------+
938  * pipe xfer	|  OK	| reject     | reject | reject	     | reject	    |
939  * pipe stoppoll| no-op | OK	     | no-op  | reject	     | reject	    |
940  * pipe reset	| no-op | OK	     |	OK    | reject	     | reject	    |
941  * pipe close	|  OK	| wait&close |	OK    | no-op	     | no-op	    |
942  * -------------------------------------------------------------------------+
943  *
944  * -------------------------------------------------------------------------+
945  * intr/isoc OUT| idle	| active     | error  | sync closing | async closing|
946  * -------------------------------------------------------------------------+
947  * pipe xfer	|  OK	|queue (HCD) | reject | reject	     | reject	    |
948  * pipe stoppoll| reject| reject     | reject | reject	     | reject	    |
949  * pipe reset	| no-op | OK	     |	OK    | reject	     | reject	    |
950  * pipe close	|  OK	| wait&close |	OK    | no-op	     | no-op	    |
951  * -------------------------------------------------------------------------+
952  */
953 typedef enum {
954 	USB_PIPE_STATE_CLOSED		= 0,
955 	USB_PIPE_STATE_IDLE		= 1,
956 	USB_PIPE_STATE_ACTIVE		= 2,
957 	USB_PIPE_STATE_ERROR		= 3,
958 	USB_PIPE_STATE_CLOSING		= 4
959 } usb_pipe_state_t;
960 
961 
962 /*
963  * pipe state control:
964  *
965  * return values:
966  *	USB_SUCCESS	 - success
967  *	USB_FAILURE	 - unspecified failure
968  */
969 int usb_pipe_get_state(
970 	usb_pipe_handle_t	pipe_handle,
971 	usb_pipe_state_t	*pipe_state,
972 	usb_flags_t		flags);
973 
974 
975 /*
976  * usb_pipe_policy
977  *
978  *	Pipe policy specifies how a pipe to an endpoint	should be used
979  *	by the client driver and the HCD.
980  */
981 typedef struct usb_pipe_policy {
982 	/*
983 	 * This is a hint indicating how many asynchronous operations
984 	 * requiring a kernel thread will be concurrently active.
985 	 * Allow at least one for synch exception callback handling
986 	 * and another for asynchronous closing of pipes.
987 	 */
988 	uchar_t		pp_max_async_reqs;
989 } usb_pipe_policy_t;
990 
991 
992 /*
993  * usb_pipe_open():
994  *
995  * Before using any pipe including the default pipe, it must be opened.
996  * On success, a pipe handle is returned for use in other usb_pipe_*()
997  * functions.
998  *
999  * The default pipe can only be opened by the hub driver.
1000  *
1001  * For isochronous and interrupt pipes, bandwidth has been allocated and
1002  * guaranteed.
1003  *
1004  * Only the default pipe can be shared.  All other control pipes are
1005  * excusively opened by default.  A pipe policy and endpoint descriptor
1006  * must always be provided except for default pipe.
1007  *
1008  * Arguments:
1009  *	dip		- devinfo ptr.
1010  *	ep		- endpoint descriptor pointer.
1011  *	pipe_policy	- pointer to pipe policy which provides hints on how
1012  *			  the pipe will be used.
1013  *	flags		- USB_FLAGS_SLEEP wait for resources to become
1014  *			  available.
1015  *	pipe_handle	- a pipe handle pointer.  on a successful open,
1016  *			  a pipe_handle is returned in this pointer.
1017  *
1018  * Return values:
1019  *	USB_SUCCESS	 - open succeeded.
1020  *	USB_FAILURE	 - unspecified open failure or pipe is already open.
1021  *	USB_NO_RESOURCES - no resources were available to complete the open.
1022  *	USB_NO_BANDWIDTH - no bandwidth available (isoc/intr pipes).
1023  *	USB_*		 - refer to list of all possible return values in
1024  *			   this file
1025  */
1026 int usb_pipe_open(
1027 	dev_info_t		*dip,
1028 	usb_ep_descr_t		*ep,
1029 	usb_pipe_policy_t	*pipe_policy,
1030 	usb_flags_t		flags,
1031 	usb_pipe_handle_t	*pipe_handle);
1032 
1033 
1034 /*
1035  * usb_pipe_close():
1036  *
1037  * Closes the pipe, releases resources and frees the pipe_handle.
1038  * Automatic polling, if active,  will be terminated.
1039  *
1040  * Arguments:
1041  *	dip		- devinfo ptr.
1042  *	pipe_handle	- pipe handle.
1043  *	flags		- USB_FLAGS_SLEEP:
1044  *				wait for resources, pipe
1045  *				to become free, and all callbacks completed.
1046  *	cb		- If USB_FLAGS_SLEEP has not been specified, a
1047  *			  callback will be performed.
1048  *	cb_arg		- the 2nd argument of the callback. Note that the
1049  *			  pipehandle will be zeroed and therefore not passed.
1050  *
1051  * Notes:
1052  *
1053  * Pipe close always succeeds regardless whether USB_FLAGS_SLEEP has been
1054  * specified or not.  An async close will always succeed if the hint in the
1055  * pipe policy has been correct about the max number of async requests
1056  * required.
1057  * In the unlikely event that no async requests can be queued, this
1058  * function will continue retrying before returning
1059  *
1060  * USBA prevents the client from submitting subsequent requests to a pipe
1061  * that is being closed.
1062  * Additional usb_pipe_close() requests on the same pipe causes USBA to
1063  * wait for the previous close(s) to complete.
1064  *
1065  * The pipe will not be destroyed until all activity on the pipe has
1066  * been drained, including outstanding request callbacks, async requests,
1067  * and other usb_pipe_*() calls.
1068  *
1069  * Calling usb_pipe_close() from a deferred callback (in kernel context)
1070  * with USB_FLAGS_SLEEP set, will cause deadlock
1071  */
1072 void usb_pipe_close(
1073 	dev_info_t		*dip,
1074 	usb_pipe_handle_t	pipe_handle,
1075 	usb_flags_t		flags,
1076 	void			(*cb)(
1077 				    usb_pipe_handle_t	ph,
1078 				    usb_opaque_t	arg,	/* cb arg */
1079 				    int			rval,
1080 				    usb_cb_flags_t	flags),
1081 	usb_opaque_t		cb_arg);
1082 
1083 
1084 /*
1085  * usb_pipe_drain_reqs
1086  *	this function blocks until there are no more requests
1087  *	owned by this dip on the pipe
1088  *
1089  * Arguments:
1090  *	dip		- devinfo pointer
1091  *	pipe_handle	- opaque pipe handle
1092  *	timeout 	- timeout in seconds
1093  *	flags		- USB_FLAGS_SLEEP:
1094  *				wait for completion.
1095  *	cb		- if USB_FLAGS_SLEEP has not been specified
1096  *			  this callback function will be called on
1097  *			  completion. This callback may be NULL
1098  *			  and no notification of completion will then
1099  *			  be provided.
1100  *	cb_arg		- 2nd argument to callback function.
1101  *
1102  * callback and callback_arg should be NULL if USB_FLAGS_SLEEP has
1103  * been specified
1104  *
1105  * Returns:
1106  *	USB_SUCCESS	- pipe successfully reset or request queued
1107  *	USB_FAILURE	- timeout
1108  *	USB_INVALID_PIPE - pipe is invalid or already closed
1109  *	USB_INVALID_CONTEXT - called from interrupt context
1110  *	USB_INVALID_ARGS - invalid arguments
1111  *	USB_*		- refer to return values defines in this file
1112  */
1113 int usb_pipe_drain_reqs(
1114 	dev_info_t		*dip,
1115 	usb_pipe_handle_t	pipe_handle,
1116 	uint_t			time,
1117 	usb_flags_t		flags,
1118 	void			(*cb)(
1119 				    usb_pipe_handle_t	ph,
1120 				    usb_opaque_t	arg,	/* cb arg */
1121 				    int			rval,
1122 				    usb_cb_flags_t	flags),
1123 	usb_opaque_t		cb_arg);
1124 
1125 
1126 /*
1127  * Resetting a pipe: Refer to USB 2.0/10.5.2.2
1128  *	The pipe's requests are retired and the pipe is cleared.  The host state
1129  *	is moved to active. If the reflected endpoint state needs to be changed,
1130  *	that must be explicitly requested by the client driver.  The reset
1131  *	completes after all request callbacks have been completed.
1132  *
1133  * Arguments:
1134  *	dip		- devinfo pointer.
1135  *	pipe_handle	- pipe handle.
1136  *	flags		- USB_FLAGS_SLEEP:
1137  *				wait for completion.
1138  *	cb		- if USB_FLAGS_SLEEP has not been specified
1139  *			  this callback function will be called on
1140  *			  completion. This callback may be NULL
1141  *			  and no notification of completion will then
1142  *			  be provided.
1143  *	cb_arg		- 2nd argument to callback function.
1144  *
1145  * callback and callback_arg should be NULL if USB_FLAGS_SLEEP has
1146  * been specified
1147  *
1148  * Note: Completion notification may be *before* all async request threads
1149  *	have completed but *after* all immediate callbacks have completed.
1150  */
1151 void usb_pipe_reset(
1152 	dev_info_t		*dip,
1153 	usb_pipe_handle_t	pipe_handle,
1154 	usb_flags_t		usb_flags,
1155 	void			(*cb)(
1156 					usb_pipe_handle_t ph,
1157 					usb_opaque_t	arg,
1158 					int		rval,
1159 					usb_cb_flags_t	flags),
1160 	usb_opaque_t		cb_arg);
1161 
1162 
1163 /*
1164  * The client driver can store a private data pointer in the
1165  * pipe_handle.
1166  *
1167  * return values:
1168  *	USB_SUCCESS	 - success
1169  *	USB_FAILURE	 - unspecified failure
1170  */
1171 int usb_pipe_set_private(
1172 	usb_pipe_handle_t	pipe_handle,
1173 	usb_opaque_t		data);
1174 
1175 
1176 usb_opaque_t usb_pipe_get_private(
1177 	usb_pipe_handle_t	pipe_handle);
1178 
1179 
1180 /*
1181  * ***************************************************************************
1182  * Transfer request definitions and functions
1183  * ***************************************************************************
1184  */
1185 
1186 
1187 /*
1188  * USB xfer request attributes.
1189  * Set by the client driver, more than one may be set
1190  *
1191  * SHORT_XFER_OK if less data is transferred than specified, no error is
1192  *		returned.
1193  * AUTOCLEARING	if there is an exception, the pipe will be reset first
1194  *		and a functional stall cleared before a callback is done.
1195  * PIPE_RESET	if there is an exception, the pipe will be reset only
1196  * ONE_XFER	polling will automatically stop on the first callback.
1197  * ISOC_START_FRAME use startframe specified.
1198  * USB_ATTRS_ISOC_XFER_ASAP let the host controller decide on the first
1199  *		available frame.
1200  *
1201  * USB_ATTRS_ISOC_START_FRAME and USB_ATTRS_ISOC_XFER_ASAP are mutually
1202  * exclusive
1203  *
1204  * combinations of flag and attributes:
1205  *
1206  * usb_flags	usb_req_attrs			semantics
1207  * ---------------------------------------------------------
1208  * SLEEP	USB_ATTRS_SHORT_XFER_OK		legal for IN pipes
1209  * SLEEP	USB_ATTRS_AUTOCLEARING		legal
1210  * SLEEP	USB_ATTRS_PIPE_RESET		legal
1211  * SLEEP	USB_ATTRS_ONE_XFER		legal for interrupt IN pipes
1212  * SLEEP	USB_ATTRS_ISOC_START_FRAME	illegal
1213  * SLEEP	USB_ATTRS_ISOC_XFER_ASAP	illegal
1214  *
1215  * noSLEEP	USB_ATTRS_SHORT_XFER_OK		legal for all IN pipes
1216  * noSLEEP	USB_ATTRS_AUTOCLEARING		legal
1217  * noSLEEP	USB_ATTRS_PIPE_RESET		legal
1218  * noSLEEP	USB_ATTRS_ONE_XFER		legal
1219  * noSLEEP	USB_ATTRS_ISOC_START_FRAME	legal
1220  * noSLEEP	USB_ATTRS_ISOC_XFER_ASAP	legal
1221  */
1222 typedef enum {
1223 	USB_ATTRS_NONE			= 0,
1224 
1225 	/* only ctrl/bulk/intr IN pipes */
1226 	USB_ATTRS_SHORT_XFER_OK		= 0x01,	/* short data xfer is ok */
1227 	USB_ATTRS_PIPE_RESET		= 0x02,	/* reset pipe only on exc */
1228 	USB_ATTRS_AUTOCLEARING		= 0x12, /* autoclear STALLs */
1229 
1230 	/* intr pipes only: one poll with data */
1231 	USB_ATTRS_ONE_XFER		= 0x100,
1232 
1233 	/* only for isoch pipe */
1234 	USB_ATTRS_ISOC_START_FRAME	= 0x200, /* Starting frame# specified */
1235 	USB_ATTRS_ISOC_XFER_ASAP	= 0x400	/* HCD decides START_FRAME#  */
1236 } usb_req_attrs_t;
1237 
1238 
1239 /*
1240  * Note: client drivers are required to provide data buffers (mblks) for most
1241  * requests
1242  *			IN		OUT
1243  * ctlr request		if wLength > 0	if wLength > 0
1244  * bulk request		yes		yes
1245  * intr request		no		yes
1246  * isoc request		no		yes
1247  */
1248 
1249 /*
1250  * ===========================================================================
1251  * USB control request management
1252  * ===========================================================================
1253  */
1254 
1255 /*
1256  * A client driver allocates and uses the usb_ctrl_req_t for all control
1257  * pipe requests.
1258  *
1259  * Direction of the xfer will be determined based on the bmRequestType.
1260  *
1261  * NULL callbacks are permitted, timeout = 0 indicates infinite timeout.
1262  * All timeouts are in seconds.
1263  *
1264  * All fields are initialized by client except for data on IN request
1265  * in which case the client is responsible for deallocating.
1266  *
1267  * Control requests may be reused.  The client driver is responsible
1268  * for reinitializing some fields, eg data read/write pointers.
1269  *
1270  * Control requests can be queued.
1271  */
1272 typedef struct usb_ctrl_req {
1273 	uint8_t		ctrl_bmRequestType; /* characteristics of request */
1274 	uint8_t		ctrl_bRequest;	/* specific request		*/
1275 	uint16_t	ctrl_wValue;	/* varies according to request	*/
1276 	uint16_t	ctrl_wIndex;	/* index or offset		*/
1277 	uint16_t	ctrl_wLength;	/* number of bytes to xfer	*/
1278 
1279 	mblk_t		*ctrl_data;	/* the data for the data phase	*/
1280 					/* IN: allocated by HCD		*/
1281 					/* OUT: allocated by client	*/
1282 	uint_t		ctrl_timeout;	/* how long before HCD retires req */
1283 	usb_opaque_t	ctrl_client_private; /* for client private info	*/
1284 	usb_req_attrs_t ctrl_attributes; /* attributes for this req */
1285 
1286 	/*
1287 	 * callback function for control pipe requests
1288 	 *
1289 	 * a normal callback will be done upon:
1290 	 *	- successful completion of a control pipe request
1291 	 *
1292 	 * callback arguments are:
1293 	 *	- the pipe_handle
1294 	 *	- usb_ctrl_req_t pointer
1295 	 */
1296 	void		(*ctrl_cb)(usb_pipe_handle_t ph,
1297 				struct usb_ctrl_req *req);
1298 
1299 	/*
1300 	 * exception callback function for control pipe
1301 	 *
1302 	 * a exception callback will be done upon:
1303 	 *	- an exception/error (all types)
1304 	 *	- partial xfer of data unless SHORT_XFER_OK has been set
1305 	 *
1306 	 * callback arguments are:
1307 	 *	- the pipe_handle
1308 	 *	- usb_ctrl_req_t pointer
1309 	 *
1310 	 * if USB_ATTRS_AUTOCLEARING was set, autoclearing will be attempted
1311 	 * and usb_cb_flags_t in usb_ctrl_req may indicate what was done
1312 	 */
1313 	void		(*ctrl_exc_cb)(usb_pipe_handle_t ph,
1314 				struct usb_ctrl_req *req);
1315 
1316 	/* set by USBA/HCD on completion */
1317 	usb_cr_t	ctrl_completion_reason;	/* set by HCD */
1318 	usb_cb_flags_t	ctrl_cb_flags;  /* Callback context / handling flgs */
1319 } usb_ctrl_req_t;
1320 
1321 
1322 /*
1323  * In the setup packet, the descriptor type is passed in the high byte of the
1324  * wValue field.
1325  * descriptor types:
1326  */
1327 #define	USB_DESCR_TYPE_SETUP_DEV		0x0100
1328 #define	USB_DESCR_TYPE_SETUP_CFG		0x0200
1329 #define	USB_DESCR_TYPE_SETUP_STRING		0x0300
1330 #define	USB_DESCR_TYPE_SETUP_IF			0x0400
1331 #define	USB_DESCR_TYPE_SETUP_EP			0x0500
1332 #define	USB_DESCR_TYPE_SETUP_DEV_QLF		0x0600
1333 #define	USB_DESCR_TYPE_SETUP_OTHER_SPEED_CFG	0x0700
1334 #define	USB_DESCR_TYPE_SETUP_IF_PWR		0x0800
1335 
1336 #define	USB_DESCR_TYPE_DEV			0x01
1337 #define	USB_DESCR_TYPE_CFG			0x02
1338 #define	USB_DESCR_TYPE_STRING			0x03
1339 #define	USB_DESCR_TYPE_IF			0x04
1340 #define	USB_DESCR_TYPE_EP			0x05
1341 #define	USB_DESCR_TYPE_DEV_QLF			0x06
1342 #define	USB_DESCR_TYPE_OTHER_SPEED_CFG		0x07
1343 #define	USB_DESCR_TYPE_IF_PWR			0x08
1344 #define	USB_DESCR_TYPE_IA			0x0B
1345 
1346 /*
1347  * device request type
1348  */
1349 #define	USB_DEV_REQ_HOST_TO_DEV		0x00
1350 #define	USB_DEV_REQ_DEV_TO_HOST		0x80
1351 #define	USB_DEV_REQ_DIR_MASK		0x80
1352 
1353 #define	USB_DEV_REQ_TYPE_STANDARD	0x00
1354 #define	USB_DEV_REQ_TYPE_CLASS		0x20
1355 #define	USB_DEV_REQ_TYPE_VENDOR		0x40
1356 #define	USB_DEV_REQ_TYPE_MASK		0x60
1357 
1358 #define	USB_DEV_REQ_RCPT_DEV		0x00
1359 #define	USB_DEV_REQ_RCPT_IF		0x01
1360 #define	USB_DEV_REQ_RCPT_EP		0x02
1361 #define	USB_DEV_REQ_RCPT_OTHER		0x03
1362 #define	USB_DEV_REQ_RCPT_MASK		0x03
1363 
1364 /*
1365  * device request
1366  */
1367 #define	USB_REQ_GET_STATUS		0x00
1368 #define	USB_REQ_CLEAR_FEATURE		0x01
1369 #define	USB_REQ_SET_FEATURE		0x03
1370 #define	USB_REQ_SET_ADDRESS		0x05
1371 #define	USB_REQ_GET_DESCR		0x06
1372 #define	USB_REQ_SET_DESCR		0x07
1373 #define	USB_REQ_GET_CFG			0x08
1374 #define	USB_REQ_SET_CFG			0x09
1375 #define	USB_REQ_GET_IF			0x0a
1376 #define	USB_REQ_SET_IF			0x0b
1377 #define	USB_REQ_SYNC_FRAME		0x0c
1378 
1379 /* language ID for string descriptors */
1380 #define	USB_LANG_ID			0x0409
1381 
1382 /*
1383  * Standard Feature Selectors
1384  */
1385 #define	USB_EP_HALT			0x0000
1386 #define	USB_DEV_REMOTE_WAKEUP		0x0001
1387 #define	USB_DEV_TEST_MODE		0x0002
1388 
1389 
1390 /*
1391  * Allocate usb control request
1392  *
1393  * Arguments:
1394  *	dip	- dev_info pointer of the client driver
1395  *	len	- length of "data" for this control request.
1396  *		  if 0, no mblk is alloc'ed
1397  *	flags	- USB_FLAGS_SLEEP: Sleep if resources are not available
1398  *
1399  * Return Values:
1400  *	usb_ctrl_req_t pointer on success, NULL on failure
1401  *
1402  * Implementation NOTE: the dip allows checking on detach for memory leaks
1403  */
1404 usb_ctrl_req_t *usb_alloc_ctrl_req(
1405 	dev_info_t		*dip,
1406 	size_t			len,
1407 	usb_flags_t		flags);
1408 
1409 
1410 /*
1411  * free USB control request
1412  */
1413 void usb_free_ctrl_req(
1414 	usb_ctrl_req_t	*reqp);
1415 
1416 
1417 /*
1418  * usb_pipe_ctrl_xfer();
1419  *	Client driver calls this function to issue the control
1420  *	request to the USBA which will queue or transport it to the device
1421  *
1422  * Arguments:
1423  *	pipe_handle	- control pipe pipehandle (obtained via usb_pipe_open()
1424  *	reqp		- pointer to control request
1425  *	flags		- USB_FLAGS_SLEEP:
1426  *				wait for the request to complete
1427  *
1428  * Return values:
1429  *	USB_SUCCESS	- successfully queued (no sleep) or successfully
1430  *			  completed (with sleep specified)
1431  *	USB_FAILURE	- failure
1432  *	USB_NO_RESOURCES - no resources
1433  */
1434 int usb_pipe_ctrl_xfer(usb_pipe_handle_t pipe_handle,
1435 	usb_ctrl_req_t	*reqp,
1436 	usb_flags_t		flags);
1437 
1438 
1439 /*
1440  * ---------------------------------------------------------------------------
1441  * Wrapper function which allocates and deallocates a request structure, and
1442  * performs a control transfer.
1443  * ---------------------------------------------------------------------------
1444  */
1445 
1446 /*
1447  * Setup arguments for usb_pipe_ctrl_xfer_wait:
1448  *
1449  *	bmRequestType	- characteristics of request
1450  *	bRequest	- specific request
1451  *	wValue		- varies according to request
1452  *	wIndex		- index or offset
1453  *	wLength		- number of bytes to xfer
1454  *	attrs		- required request attributes
1455  *	data		- pointer to pointer to data
1456  *				IN: HCD will allocate data
1457  *				OUT: clients driver allocates data
1458  */
1459 typedef struct usb_ctrl_setup {
1460 	uchar_t		bmRequestType;
1461 	uchar_t		bRequest;
1462 	uint16_t	wValue;
1463 	uint16_t	wIndex;
1464 	uint16_t	wLength;
1465 	usb_req_attrs_t	attrs;
1466 } usb_ctrl_setup_t;
1467 
1468 
1469 /*
1470  * usb_pipe_ctrl_xfer_wait():
1471  *	for simple synchronous control transactions this wrapper function
1472  *	will perform the allocation, xfer, and deallocation.
1473  *	USB_ATTRS_AUTOCLEARING will be enabled
1474  *
1475  * Arguments:
1476  *	pipe_handle	- control pipe pipehandle (obtained via usb_pipe_open())
1477  *	setup		- contains pointer to client's devinfo,
1478  *			  setup descriptor params, attributes and data
1479  *	completion_reason - completion status.
1480  *	cb_flags	- request completions flags.
1481  *	flags		- none.
1482  *
1483  * Return Values:
1484  *	USB_SUCCESS	- request successfully executed.
1485  *	USB_FAILURE	- request failed.
1486  *	USB_*		- refer to list of all possible return values in
1487  *			  this file
1488  *
1489  * NOTES:
1490  * - in the case of failure, the client should check completion_reason and
1491  *   and cb_flags and determine further recovery action
1492  * - the client should check data and if non-zero, free the data on
1493  *   completion
1494  */
1495 int usb_pipe_ctrl_xfer_wait(
1496 	usb_pipe_handle_t	pipe_handle,
1497 	usb_ctrl_setup_t	*setup,
1498 	mblk_t			**data,
1499 	usb_cr_t		*completion_reason,
1500 	usb_cb_flags_t		*cb_flags,
1501 	usb_flags_t		flags);
1502 
1503 
1504 /*
1505  * ---------------------------------------------------------------------------
1506  * Some utility defines and wrapper functions for standard control requests.
1507  * ---------------------------------------------------------------------------
1508  */
1509 
1510 /*
1511  *
1512  * Status bits returned by a usb_get_status().
1513  */
1514 #define	USB_DEV_SLF_PWRD_STATUS	1	/* Supports Self Power	 */
1515 #define	USB_DEV_RWAKEUP_STATUS	2	/* Remote Wakeup Enabled */
1516 #define	USB_EP_HALT_STATUS	1	/* Endpoint is Halted	 */
1517 #define	USB_IF_STATUS		0	/* Interface Status is 0 */
1518 
1519 /* length of data returned by USB_REQ_GET_STATUS */
1520 #define	USB_GET_STATUS_LEN		2
1521 
1522 /*
1523  * wrapper function returning status of device, interface, or endpoint
1524  *
1525  * Arguments:
1526  *	dip		- devinfo pointer.
1527  *	ph		- pipe handle
1528  *	type		- bmRequestType to be used
1529  *	what		- 0 for device, otherwise interface or ep number
1530  *	status		- pointer to returned status.
1531  *	flags		- USB_FLAGS_SLEEP (mandatory)
1532  *
1533  * Return Values:
1534  *	valid usb_status_t	or USB_FAILURE
1535  *
1536  */
1537 int usb_get_status(
1538 	dev_info_t		*dip,
1539 	usb_pipe_handle_t	ph,
1540 	uint_t			type,	/* bmRequestType */
1541 	uint_t			what,	/* 0, interface, endpoint number */
1542 	uint16_t		*status,
1543 	usb_flags_t		flags);
1544 
1545 
1546 /*
1547  * function for clearing feature of device, interface, or endpoint
1548  *
1549  * Arguments:
1550  *	dip		- devinfo pointer.
1551  *	type		- bmRequestType to be used
1552  *	feature		- feature to be cleared
1553  *	what		- 0 for device, otherwise interface or ep number
1554  *	flags		- USB_FLAGS_SLEEP (mandatory)
1555  *	cb		- if USB_FLAGS_SLEEP has not been specified
1556  *			  this callback function will be called on
1557  *			  completion. This callback may be NULL
1558  *			  and no notification of completion will then
1559  *			  be provided.
1560  *	cb_arg		- 2nd argument to callback function.
1561  *
1562  * Return Values:
1563  *	USB_SUCCESS	clearing feature succeeded
1564  *	USB_FAILURE	clearing feature failed
1565  *	USB_*		refer to list of all possible return values in
1566  *			this file
1567  */
1568 int usb_clr_feature(
1569 	dev_info_t		*dip,
1570 	uint_t			type,	/* bmRequestType */
1571 	uint_t			feature,
1572 	uint_t			what,	/* 0, interface, endpoint number */
1573 	usb_flags_t		flags,
1574 	void			(*cb)(
1575 					usb_pipe_handle_t ph,
1576 					usb_opaque_t	arg,
1577 					int		rval,
1578 					usb_cb_flags_t	flags),
1579 	usb_opaque_t		cb_arg);
1580 
1581 
1582 /*
1583  * usb_set_cfg():
1584  *	Sets the configuration.  Use this function with caution as
1585  *	the framework is normally responsible for configuration changes.
1586  *	Changing configuration will fail if pipes are still open or
1587  *	when invoked from a driver bound to an interface on a composite
1588  *	device. This function access the device and blocks.
1589  *
1590  * Arguments:
1591  *	dip		- devinfo pointer.
1592  *	cfg_index	- Index of configuration to set.  Corresponds to
1593  *			  index in the usb_client_dev_data_t tree of
1594  *			  configurations.  See usb_client_dev_data_t(9F).
1595  *	usb_flags	- USB_FLAGS_SLEEP:
1596  *				wait for completion.
1597  *	cb		- if USB_FLAGS_SLEEP has not been specified
1598  *			  this callback function will be called on
1599  *			  completion. This callback may be NULL
1600  *			  and no notification of completion will then
1601  *			  be provided.
1602  *	cb_arg		- 2nd argument to callback function.
1603  *
1604  * callback and callback_arg should be NULL if USB_FLAGS_SLEEP has
1605  * been specified
1606  *
1607  * Return Values:
1608  *	USB_SUCCESS:	new configuration was set or async request
1609  *			submitted successfully.
1610  *	USB_FAILURE:	new configuration could not be set because
1611  *			it may been illegal configuration or this
1612  *			caller was not allowed to change configs or
1613  *			pipes were still open or async request
1614  *			could not be submitted.
1615  *	USB_*		refer to list of all possible return values in
1616  *			this file
1617  *
1618  * the pipe handle argument in the callback will be the default pipe handle
1619  */
1620 int usb_set_cfg(
1621 	dev_info_t		*dip,
1622 	uint_t			cfg_index,
1623 	usb_flags_t		usb_flags,
1624 	void			(*cb)(
1625 					usb_pipe_handle_t ph,
1626 					usb_opaque_t	arg,
1627 					int		rval,
1628 					usb_cb_flags_t	flags),
1629 	usb_opaque_t		cb_arg);
1630 
1631 
1632 /*
1633  * usb_get_cfg:
1634  *	dip		- pointer to devinfo node
1635  *	cfgval		- pointer to cfgval
1636  *	usb_flags	- none, will always block
1637  *
1638  * return values:
1639  *	USB_SUCCESS	- current cfg value is returned to cfgval
1640  *	USB_*		- refer to list of all possible return values in
1641  *			  this file
1642  */
1643 int usb_get_cfg(
1644 	dev_info_t		*dip,
1645 	uint_t			*cfgval,
1646 	usb_flags_t		usb_flags);
1647 
1648 
1649 /*
1650  * The following functions set or get the alternate interface
1651  * setting.
1652  *
1653  * usb_set_alt_if:
1654  *	dip		- pointer to devinfo node
1655  *	interface	- interface
1656  *	alt_number	- alternate to set to
1657  *	usb_flags	- USB_FLAGS_SLEEP:
1658  *				wait for completion.
1659  *	cb		- if USB_FLAGS_SLEEP has not been specified
1660  *			  this callback function will be called on
1661  *			  completion. This callback may be NULL
1662  *			  and no notification of completion will then
1663  *			  be provided.
1664  *	cb_arg		- 2nd argument to callback function.
1665  *
1666  * callback and callback_arg should be NULL if USB_FLAGS_SLEEP has
1667  * been specified
1668  *
1669  * the pipe handle argument in the callback will be the default pipe handle
1670  *
1671  * return values:
1672  *	USB_SUCCESS:	alternate was set or async request was
1673  *			submitted.
1674  *	USB_FAILURE:	alternate could not be set because pipes
1675  *			were still open or some access error occurred
1676  *			or an invalid alt if value was passed or
1677  *			async request could not be submitted
1678  *	USB_INVALID_PERM the driver does not own the device or the interface
1679  *	USB_*		refer to list of all possible return values in
1680  *			this file
1681  */
1682 int usb_set_alt_if(
1683 	dev_info_t		*dip,
1684 	uint_t			interface,
1685 	uint_t			alt_number,
1686 	usb_flags_t		usb_flags,
1687 	void			(*cb)(
1688 					usb_pipe_handle_t ph,
1689 					usb_opaque_t	arg,
1690 					int		rval,
1691 					usb_cb_flags_t	flags),
1692 	usb_opaque_t		cb_arg);
1693 
1694 
1695 
1696 /* flags must be USB_FLAGS_SLEEP, and this function will block */
1697 int usb_get_alt_if(
1698 	dev_info_t		*dip,
1699 	uint_t			if_number,
1700 	uint_t			*alt_number,
1701 	usb_flags_t		flags);
1702 
1703 
1704 /*
1705  * ===========================================================================
1706  * USB bulk request management
1707  * ===========================================================================
1708  */
1709 
1710 /*
1711  * A client driver allocates/uses the usb_bulk_req_t for bulk pipe xfers.
1712  *
1713  * NOTES:
1714  * - bulk pipe sharing is not supported
1715  * - semantics of combinations of flag and attributes:
1716  *
1717  * flags     Type  attributes	data	timeout semantics
1718  * ----------------------------------------------------------------
1719  *  x	      x    x		== NULL    x	   illegal
1720  *
1721  * no sleep  IN    x		!= NULL    0	   fill buffer, no timeout
1722  *						   callback when xfer-len has
1723  *						   been xferred
1724  * no sleep  IN    x		!= NULL    > 0	   fill buffer, with timeout
1725  *						   callback when xfer-len has
1726  *						   been xferred
1727  *
1728  * sleep     IN    x		!= NULL    0	   fill buffer, no timeout
1729  *						   unblock when xfer-len has
1730  *						   been xferred
1731  *						   no callback
1732  * sleep     IN    x		!= NULL    > 0	   fill buffer, with timeout
1733  *						   unblock when xfer-len has
1734  *						   been xferred or timeout
1735  *						   no callback
1736  *
1737  *  X	     OUT SHORT_XFER_OK	  x	   x	   illegal
1738  *
1739  * no sleep  OUT   x		!= NULL    0	   empty buffer, no timeout
1740  *						   callback when xfer-len has
1741  *						   been xferred
1742  * no sleep  OUT   x		!= NULL    > 0	   empty buffer, with timeout
1743  *						   callback when xfer-len has
1744  *						   been xferred or timeout
1745  *
1746  * sleep     OUT   x		!= NULL    0	   empty buffer, no timeout
1747  *						   unblock when xfer-len has
1748  *						   been xferred
1749  *						   no callback
1750  * sleep     OUT   x		!= NULL    > 0	   empty buffer, with timeout
1751  *						   unblock when xfer-len has
1752  *						   been xferred or timeout
1753  *						   no callback
1754  *
1755  * - bulk_len and bulk_data must be > 0.  SHORT_XFER_OK is not applicable.
1756  *
1757  * - multiple bulk requests can be queued
1758  *
1759  * - Splitting large Bulk xfer:
1760  * The HCD driver, due to internal constraints, can only do a limited size bulk
1761  * data xfer per request.  The current limitations are 32K for UHCI and 128K
1762  * for OHCI.  So, a client driver may first determine this limitation (by
1763  * calling the USBA interface usb_pipe_bulk_transfer_size()); and restrict
1764  * itself to doing xfers in multiples of this fixed size.  This forces a client
1765  * driver to do data xfers in a loop for a large request, splitting it into
1766  * multiple chunks of fixed size.
1767  */
1768 typedef struct usb_bulk_req {
1769 	uint_t		bulk_len;	/* number of bytes to xfer	*/
1770 	mblk_t		*bulk_data;	/* the data for the data phase	*/
1771 					/* IN: allocated by HCD		*/
1772 					/* OUT: allocated by client	*/
1773 	uint_t		bulk_timeout;	/* xfer timeout value in secs	*/
1774 	usb_opaque_t	bulk_client_private; /* Client specific information */
1775 	usb_req_attrs_t bulk_attributes; /* xfer-attributes	*/
1776 
1777 	/* Normal Callback function (For synch xfers) */
1778 	void		(*bulk_cb)(usb_pipe_handle_t ph,
1779 				struct usb_bulk_req *req);
1780 
1781 	/* Exception Callback function (For asynch xfers) */
1782 	void		(*bulk_exc_cb)(usb_pipe_handle_t ph,
1783 				struct usb_bulk_req *req);
1784 
1785 	/* set by USBA/HCD on completion */
1786 	usb_cr_t	bulk_completion_reason;	/* set by HCD		*/
1787 	usb_cb_flags_t	bulk_cb_flags;  /* Callback context / handling flgs */
1788 } usb_bulk_req_t;
1789 
1790 
1791 /*
1792  * Allocate/free usb bulk request
1793  *
1794  * Arguments:
1795  *	dip		- pointer to dev_info_t of the client driver
1796  *	len		- 0 or length of mblk to be allocated
1797  *	flags		- USB_FLAGS_SLEEP:
1798  *				wait for resources
1799  *
1800  * Return Values:
1801  *	usb_bulk_req_t on success, NULL on failure
1802  */
1803 usb_bulk_req_t *usb_alloc_bulk_req(
1804 	dev_info_t		*dip,
1805 	size_t			len,
1806 	usb_flags_t		flags);
1807 
1808 
1809 void usb_free_bulk_req(
1810 	usb_bulk_req_t	*reqp);
1811 
1812 
1813 /*
1814  * usb_pipe_bulk_xfer():
1815  *
1816  * Client drivers call this function to issue the bulk xfer to the USBA
1817  * which will queue or transfer it to the device
1818  *
1819  * Arguments:
1820  *	pipe_handle	- bulk pipe handle (obtained via usb_pipe_open()
1821  *	reqp		- pointer to bulk data xfer request (IN or OUT)
1822  *	flags		- USB_FLAGS_SLEEP:
1823  *				wait for the request to complete
1824  *
1825  * Return Values:
1826  *	USB_SUCCESS	- success
1827  *	USB_FAILURE	- unspecified failure
1828  *	USB_NO_RESOURCES - no resources
1829  *
1830  */
1831 int usb_pipe_bulk_xfer(
1832 	usb_pipe_handle_t	pipe_handle,
1833 	usb_bulk_req_t		*reqp,
1834 	usb_flags_t		flags);
1835 
1836 /* Get maximum bulk transfer size */
1837 int usb_pipe_get_max_bulk_transfer_size(
1838 	dev_info_t		*dip,
1839 	size_t			*size);
1840 
1841 
1842 /*
1843  * ===========================================================================
1844  * USB interrupt pipe request management
1845  * ===========================================================================
1846  */
1847 
1848 /*
1849  * A client driver allocates and uses the usb_intr_req_t for
1850  * all interrupt pipe transfers.
1851  *
1852  * USB_FLAGS_SLEEP indicates here just to wait for resources except
1853  * for ONE_XFER where we also wait for completion
1854  *
1855  * semantics flags and attribute combinations:
1856  *
1857  * Notes:
1858  * none attributes indicates neither ONE_XFER nor SHORT_XFER_OK
1859  *
1860  * flags     Type  attributes	   data    timeout semantics
1861  * ----------------------------------------------------------------
1862  *  x	     IN      x		   != NULL  x	    illegal
1863  *  x	     IN   ONE_XFER=0	   x	   !=0	    illegal
1864  *
1865  *  x	     IN   ONE_XFER=0	   NULL     0	   continuous polling,
1866  *						   many callbacks
1867  *						   request is returned on
1868  *						   stop polling
1869  *
1870  * no sleep  IN   ONE_XFER	   NULL     0	   one time poll, no timeout,
1871  *						   one callback
1872  * no sleep  IN   ONE_XFER	   NULL    !=0	   one time poll, with
1873  *						   timeout, one callback
1874  *
1875  * sleep     IN   ONE_XFER	   NULL     0	   one time poll, no timeout,
1876  *						   no callback,
1877  *						   block for completion
1878  * sleep     IN   ONE_XFER	   NULL    !=0	   one time poll, with timeout,
1879  *						   no callback
1880  *						   block for completion
1881  *
1882  *  x	     OUT     x		   NULL    x	   illegal
1883  *  x	     OUT  ONE_XFER	   x	   x	   illegal
1884  *  x	     OUT  SHORT_XFER_OK    x	   x	   illegal
1885  *
1886  *  x	     OUT   none		   != NULL 0	   xfer until data exhausted,
1887  *						   no timeout,	one callback
1888  *  x	     OUT   none		   != NULL !=0	   xfer until data exhausted,
1889  *						   with timeout, one callback
1890  *
1891  * - Reads (IN):
1892  *
1893  * The client driver does *not* provide a data buffer.
1894  * By default, a READ request would mean continuous polling for data IN. The
1895  * HCD typically reads "wMaxPacketSize" amount of 'periodic data'. A client
1896  * driver may force the HCD to read instead intr_len
1897  * amount of 'periodic data' (See section 1).
1898  *
1899  * The HCD issues a callback to the client after each polling interval if
1900  * it has read in some data. Note that the amount of data read IN is either
1901  * intr_len or 'wMaxPacketSize' in length.
1902  *
1903  * Normally, the HCD keeps polling interrupt pipe forever even if there is
1904  * no data to be read IN.  A client driver may stop this polling by
1905  * calling usb_pipe_stop_intr_polling().
1906  *
1907  * If a client driver chooses to pass USB_ATTRS_ONE_XFER as
1908  * 'xfer_attributes' the HCD will poll for data until some data is received.
1909  * HCD reads in the data and does a callback and stops polling for any more
1910  * data.  In this case, the client driver need not explicitly call
1911  * usb_pipe_stop_intr_polling().
1912  *
1913  * When continuous polling is stopped, the original request is returned with
1914  * USB_CR_STOPPED_POLLING.
1915  *
1916  * - Writes (OUT):
1917  *
1918  * A client driver provides the data buffer, and data, needed for intr write.
1919  * There is no continuous write mode, a la  read (See previous section).
1920  * The USB_ATTRS_ONE_XFER attribute is illegal.
1921  * By default USBA keeps writing intr data until the provided data buffer
1922  * has been written out. The HCD does ONE callback to the client driver.
1923  * Queueing is supported.
1924  * Max size is 8k
1925  */
1926 typedef struct usb_intr_req {
1927 	uint_t		intr_len;	/* OUT: size of total xfer */
1928 					/* IN : packet size */
1929 	mblk_t		*intr_data;	/* the data for the data phase	*/
1930 					/* IN: allocated by HCD		*/
1931 					/* OUT: allocated by client	*/
1932 	usb_opaque_t	intr_client_private; /* Client specific information  */
1933 	uint_t		intr_timeout;	/* only with ONE TIME POLL, in secs */
1934 	usb_req_attrs_t	intr_attributes;
1935 
1936 	/* Normal callback function (For synch transfers) */
1937 	void		(*intr_cb)(usb_pipe_handle_t ph,
1938 				struct usb_intr_req *req);
1939 
1940 	/* Exception callback function (For asynch transfers) */
1941 	void		(*intr_exc_cb)(usb_pipe_handle_t ph,
1942 				struct usb_intr_req *req);
1943 
1944 	/* set by USBA/HCD on completion */
1945 	usb_cr_t	intr_completion_reason;	/* set by HCD */
1946 	usb_cb_flags_t	intr_cb_flags;  /* Callback context / handling flgs */
1947 } usb_intr_req_t;
1948 
1949 
1950 /*
1951  * Allocate/free usb interrupt pipe request
1952  *
1953  * Arguments:
1954  *	dip		- pointer to dev_info_t of the client driver
1955  *	reqp		- pointer to request structure
1956  *	len		- 0 or length of mblk for this interrupt request
1957  *	flags		- USB_FLAGS_SLEEP:
1958  *				Sleep if resources are not available
1959  *
1960  * Return Values:
1961  *	usb_intr_req_t on success, NULL on failure
1962  */
1963 usb_intr_req_t *usb_alloc_intr_req(
1964 	dev_info_t		*dip,
1965 	size_t			len,
1966 	usb_flags_t		flags);
1967 
1968 
1969 void usb_free_intr_req(
1970 	usb_intr_req_t	*reqp);
1971 
1972 
1973 /*
1974  * usb_pipe_intr_xfer():
1975  *
1976  * Client drivers call this function to issue the intr xfer to USBA/HCD
1977  * which starts polling the device
1978  *
1979  * Arguments:
1980  *	pipe_handle	- interrupt pipe handle (obtained via usb_pipe_open()
1981  *	reqp		- pointer tothe interrupt pipe xfer request (IN or OUT)
1982  *	flags		- USB_FLAGS_SLEEP:
1983  *				wait for resources to be available
1984  *
1985  * return values:
1986  *	USB_SUCCESS	- success
1987  *	USB_FAILURE	- unspecified failure
1988  *	USB_NO_RESOURCES  - no resources
1989  *
1990  * NOTE: start polling on an IN pipe that is already being polled is a NOP.
1991  *	 We don't queue requests on OUT pipe
1992  */
1993 int usb_pipe_intr_xfer(
1994 	usb_pipe_handle_t	pipe_handle,
1995 	usb_intr_req_t		*req,
1996 	usb_flags_t		flags);
1997 
1998 
1999 /*
2000  * usb_pipe_stop_intr_polling():
2001  *
2002  * Client drivers call this function to stop the automatic data-in/out transfers
2003  * without closing the pipe.
2004  *
2005  * If USB_FLAGS_SLEEP  has been specified then this function will block until
2006  * polling has been stopped and all callbacks completed. If USB_FLAGS_SLEEP
2007  * has NOT been specified then polling is terminated when the original
2008  * request that started the polling has been returned with
2009  * USB_CR_STOPPED_POLLING
2010  *
2011  * Stop polling should never fail.
2012  *
2013  * Args:-
2014  *	pipe_handle	- interrupt pipe handle (obtained via usb_pipe_open()).
2015  *	flags		- USB_FLAGS_SLEEP:
2016  *				wait for the resources to be available.
2017  */
2018 void usb_pipe_stop_intr_polling(
2019 	usb_pipe_handle_t	pipe_handle,
2020 	usb_flags_t		flags);
2021 
2022 
2023 /*
2024  * ===========================================================================
2025  * USB isochronous xfer management
2026  * ===========================================================================
2027  */
2028 
2029 /*
2030  * The usb frame number is an absolute number since boot and incremented
2031  * every 1 ms.
2032  */
2033 typedef	uint64_t	usb_frame_number_t;
2034 
2035 /*
2036  * USB ischronous packet descriptor
2037  *
2038  * An array of structures of type usb_isoc_pkt_descr_t must be allocated and
2039  * initialized by the client driver using usb_alloc_isoc_req(). The client
2040  * driver must set isoc_pkt_length in each packet descriptor before submitting
2041  * the request.
2042  */
2043 typedef struct usb_isoc_pkt_descr {
2044 	/*
2045 	 * Set by the client driver, for all isochronous requests, to the
2046 	 * number of bytes to transfer in a frame.
2047 	 */
2048 	ushort_t	isoc_pkt_length;
2049 
2050 	/*
2051 	 * Set by HCD to actual number of bytes sent/received in frame.
2052 	 */
2053 	ushort_t	isoc_pkt_actual_length;
2054 
2055 	/*
2056 	 * Per frame status set by HCD both for the isochronous IN and OUT
2057 	 * requests.  If any status is non-zero then isoc_error_count in the
2058 	 * isoc_req will be non-zero.
2059 	 */
2060 	usb_cr_t	isoc_pkt_status;
2061 } usb_isoc_pkt_descr_t;
2062 
2063 
2064 /*
2065  * USB isochronous request
2066  *
2067  * The client driver allocates the usb_isoc_req_t before sending an
2068  * isochronous requests.
2069  *
2070  * USB_FLAGS_SLEEP indicates here just to wait for resources but not
2071  * to wait for completion
2072  *
2073  * Semantics of various combinations for data xfers:
2074  *
2075  * Note: attributes considered in this table are ONE_XFER, START_FRAME,
2076  *	XFER_ASAP, SHORT_XFER
2077  *
2078  *
2079  * flags     Type  attributes		   data    semantics
2080  * ---------------------------------------------------------------------
2081  * x	     x	   x			NULL	   illegal
2082  *
2083  * x	     x	   ONE_XFER		 x	   illegal
2084  *
2085  * x	     IN    x			!=NULL	   continuous polling,
2086  *						   many callbacks
2087  *
2088  * x	     IN    ISOC_START_FRAME	!=NULL	   invalid if Current_frame# >
2089  *						   "isoc_frame_no"
2090  * x	     IN    ISOC_XFER_ASAP	!=NULL	   "isoc_frame_no" ignored.
2091  *						   HCD determines when to
2092  *						   insert xfer
2093  *
2094  * x	     OUT   ONE_XFER		x	   illegal
2095  * x	     OUT   SHORT_XFER_OK	x	   illegal
2096  *
2097  * x	     OUT   ISOC_START_FRAME	!=NULL	   invalid if Current_frame# >
2098  *						   "isoc_frame_no"
2099  * x	     OUT   ISOC_XFER_ASAP	!=NULL	   "isoc_frame_no" ignored.
2100  *						    HCD determines when to
2101  *						   insert xfer
2102  */
2103 typedef struct usb_isoc_req {
2104 	/*
2105 	 * Starting frame number will be set by the client driver in which
2106 	 * to begin this request. This frame number is used to synchronize
2107 	 * requests queued to different isochronous pipes. The frame number
2108 	 * is optional and client driver can skip starting frame number by
2109 	 * setting USB_ISOC_ATTRS_ASAP. In this case, HCD will decide starting
2110 	 * frame number for this isochronous request.  If this field is 0,
2111 	 * then this indicates an invalid frame number.
2112 	 */
2113 	usb_frame_number_t	isoc_frame_no;
2114 
2115 	/*
2116 	 * Number of isochronous data packets.
2117 	 * The first field is set by client  driver and may not exceed
2118 	 * the maximum number of entries in the usb isochronous packet
2119 	 * descriptors.
2120 	 */
2121 	ushort_t		isoc_pkts_count;
2122 
2123 	/*
2124 	 * The sum of all pkt lengths in the isoc request. Recommend to
2125 	 * set it to zero, so the sum of isoc_pkt_length in the
2126 	 * isoc_pkt_descr list will be used automatically and no check
2127 	 * will be apply to this element.
2128 	 */
2129 	ushort_t		isoc_pkts_length;
2130 
2131 	/*
2132 	 * This field will be set by HCD and this field indicates the number
2133 	 * of packets that completed with errors.
2134 	 */
2135 	ushort_t		isoc_error_count;
2136 
2137 	/*
2138 	 * Attributes specific to particular usb isochronous request.
2139 	 * Supported values are: USB_ATTRS_ISOC_START_FRAME,
2140 	 * USB_ATTRS_ISOC_XFER_ASAP.
2141 	 */
2142 	usb_req_attrs_t 	isoc_attributes;
2143 
2144 	/*
2145 	 * Isochronous OUT:
2146 	 *	allocated and set by client driver, freed and zeroed by HCD
2147 	 *	on successful completion
2148 	 * Isochronous IN:
2149 	 *	allocated and set by HCD, freed by client driver
2150 	 */
2151 	mblk_t			*isoc_data;
2152 
2153 	/*
2154 	 * The client driver specific private information.
2155 	 */
2156 	usb_opaque_t		isoc_client_private;
2157 
2158 	/*
2159 	 * Isochronous OUT:
2160 	 *	must be allocated & initialized by client driver
2161 	 * Isochronous IN:
2162 	 *	must be allocated by client driver
2163 	 */
2164 	struct usb_isoc_pkt_descr *isoc_pkt_descr;
2165 
2166 	/* Normal callback function (For synch transfers) */
2167 	void			(*isoc_cb)(usb_pipe_handle_t ph,
2168 					struct usb_isoc_req *req);
2169 
2170 	/* Exception callback function (For asynch transfers) */
2171 	void			(*isoc_exc_cb)(usb_pipe_handle_t ph,
2172 					struct usb_isoc_req *req);
2173 
2174 	/* set by USBA/HCD on completion */
2175 	usb_cr_t		isoc_completion_reason;	/* set by HCD */
2176 					/* Callback context / handling flgs */
2177 	usb_cb_flags_t		isoc_cb_flags;
2178 } usb_isoc_req_t;
2179 
2180 
2181 /*
2182  * Allocate/free usb isochronous resources
2183  *
2184  * isoc_pkts_count must be > 0
2185  *
2186  * Arguments:
2187  *	dip		- client driver's devinfo pointer
2188  *	isoc_pkts_count - number of pkts required
2189  *	len		- 0 or size of mblk to allocate
2190  *	flags		- USB_FLAGS_SLEEP:
2191  *				wait for resources
2192  *
2193  * Return Values:
2194  *	usb_isoc_req pointer or NULL
2195  */
2196 usb_isoc_req_t *usb_alloc_isoc_req(
2197 	dev_info_t		*dip,
2198 	uint_t			isoc_pkts_count,
2199 	size_t			len,
2200 	usb_flags_t		flags);
2201 
2202 void	usb_free_isoc_req(
2203 	usb_isoc_req_t		*usb_isoc_req);
2204 
2205 /*
2206  * Returns current usb frame number.
2207  */
2208 usb_frame_number_t usb_get_current_frame_number(
2209 	dev_info_t		*dip);
2210 
2211 /*
2212  * Get maximum isochronous packets per usb isochronous request
2213  */
2214 uint_t usb_get_max_pkts_per_isoc_request(
2215 	dev_info_t		*dip);
2216 
2217 /*
2218  * usb_pipe_isoc_xfer()
2219  *
2220  * Client drivers call this to issue the isoch xfer (IN and OUT) to the USBA
2221  * which starts polling the device.
2222  *
2223  * Arguments:
2224  *	pipe_handle	- isoc pipe handle (obtained via usb_pipe_open().
2225  *	reqp		- pointer to the isochronous pipe IN xfer request
2226  *			  allocated by the client driver.
2227  *	flags		- USB_FLAGS_SLEEP:
2228  *				wait for the resources to be available.
2229  *
2230  * return values:
2231  *	USB_SUCCESS	- success.
2232  *	USB_FAILURE	- unspecified failure.
2233  *	USB_NO_RESOURCES  - no resources.
2234  *	USB_NO_FRAME_NUMBER - START_FRAME, ASAP flags not specified.
2235  *	USB_INVALID_START_FRAME	- Starting USB frame number invalid.
2236  *
2237  * Notes:
2238  * - usb_pipe_isoc_xfer on an IN pipe that is already being polled is a NOP.
2239  * - requests can be queued on an OUT pipe.
2240  */
2241 int usb_pipe_isoc_xfer(
2242 	usb_pipe_handle_t	pipe_handle,
2243 	usb_isoc_req_t		*reqp,
2244 	usb_flags_t		flags);
2245 
2246 /*
2247  * usb_pipe_stop_isoc_polling():
2248  *
2249  * Client drivers call this function to stop the automatic data-in/out
2250  * transfers without closing the isoc pipe.
2251  *
2252  * If USB_FLAGS_SLEEP  has been specified then this function will block until
2253  * polling has been stopped and all callbacks completed. If USB_FLAGS_SLEEP
2254  * has NOT been specified then polling is terminated when the original
2255  * request that started the polling has been returned with
2256  * USB_CR_STOPPED_POLLING
2257  *
2258  * Stop polling should never fail.
2259  *
2260  * Arguments:
2261  *	pipe_handle	- isoc pipe handle (obtained via usb_pipe_open().
2262  *	flags		- USB_FLAGS_SLEEP:
2263  *				wait for polling to be stopped and all
2264  *				callbacks completed.
2265  */
2266 void usb_pipe_stop_isoc_polling(
2267 	usb_pipe_handle_t	pipe_handle,
2268 	usb_flags_t		flags);
2269 
2270 /*
2271  * ***************************************************************************
2272  * USB device power management:
2273  * ***************************************************************************
2274  */
2275 
2276 /*
2277  *
2278  * As any usb device will have a max of 4 possible power states
2279  * the #define	for them are provided below with mapping to the
2280  * corresponding OS power levels.
2281  */
2282 #define	USB_DEV_PWR_D0		USB_DEV_OS_FULL_PWR
2283 #define	USB_DEV_PWR_D1		5
2284 #define	USB_DEV_PWR_D2		6
2285 #define	USB_DEV_PWR_D3		USB_DEV_OS_PWR_OFF
2286 
2287 #define	USB_DEV_OS_PWR_0	0
2288 #define	USB_DEV_OS_PWR_1	1
2289 #define	USB_DEV_OS_PWR_2	2
2290 #define	USB_DEV_OS_PWR_3	3
2291 #define	USB_DEV_OS_PWR_OFF	USB_DEV_OS_PWR_0
2292 #define	USB_DEV_OS_FULL_PWR	USB_DEV_OS_PWR_3
2293 
2294 /* Bit Masks for Power States */
2295 #define	USB_DEV_OS_PWRMASK_D0	1
2296 #define	USB_DEV_OS_PWRMASK_D1	2
2297 #define	USB_DEV_OS_PWRMASK_D2	4
2298 #define	USB_DEV_OS_PWRMASK_D3	8
2299 
2300 /* conversion for OS to Dx levels */
2301 #define	USB_DEV_OS_PWR2USB_PWR(l)	(USB_DEV_OS_FULL_PWR - (l))
2302 
2303 /* from OS level to Dx mask */
2304 #define	USB_DEV_PWRMASK(l)	(1 << (USB_DEV_OS_FULL_PWR - (l)))
2305 
2306 /* Macro to check valid power level */
2307 #define	USB_DEV_PWRSTATE_OK(state, level) \
2308 		(((state) & USB_DEV_PWRMASK((level))) == 0)
2309 
2310 int usb_handle_remote_wakeup(
2311 	dev_info_t	*dip,
2312 	int		cmd);
2313 
2314 /* argument to usb_handle_remote wakeup function */
2315 #define	USB_REMOTE_WAKEUP_ENABLE	1
2316 #define	USB_REMOTE_WAKEUP_DISABLE	2
2317 
2318 int usb_create_pm_components(
2319 	dev_info_t	*dip,
2320 	uint_t		*pwrstates);
2321 
2322 /*
2323  * ***************************************************************************
2324  * System event registration
2325  * ***************************************************************************
2326  */
2327 
2328 /* Functions for registering hotplug callback functions. */
2329 
2330 int usb_register_hotplug_cbs(
2331 	dev_info_t	*dip,
2332 	int		(*disconnect_event_handler)(dev_info_t *dip),
2333 	int		(*reconnect_event_handler)(dev_info_t *dip));
2334 
2335 void usb_unregister_hotplug_cbs(dev_info_t *dip);
2336 
2337 /*
2338  *	Reset_level determines the extent to which the device is reset,
2339  *	It has the following values:
2340  *
2341  *	USB_RESET_LVL_REATTACH	- The device is reset, the original driver is
2342  *				  detached and a new driver attaching process
2343  *				  is started according to the updated
2344  *				  compatible name. This reset level applies to
2345  *				  the firmware download with the descriptors
2346  *				  changing, or other situations in which the
2347  *				  device needs to be reenumerated.
2348  *
2349  *	USB_RESET_LVL_DEFAULT	- Default reset level. The device is reset, all
2350  *				  error status is cleared, the device state
2351  *				  machines and registers are also cleared and
2352  *				  need to be reinitialized in the driver. The
2353  *				  current driver remains attached. This reset
2354  *				  level applies to hardware error recovery, or
2355  *				  firmware download without descriptors
2356  *				  changing.
2357  */
2358 typedef enum {
2359 	USB_RESET_LVL_REATTACH		= 0,
2360 	USB_RESET_LVL_DEFAULT		= 1
2361 } usb_dev_reset_lvl_t;
2362 
2363 /*
2364  * usb_reset_device:
2365  *
2366  * Client drivers call this function to request hardware reset for themselves,
2367  * which may be required in some situations such as:
2368  *
2369  * 1) Some USB devices need the driver to upload firmware into devices' RAM
2370  *    and initiate a hardware reset in order to activate the new firmware.
2371  * 2) Hardware reset may help drivers to recover devices from an error state
2372  *    caused by physical or firmware defects.
2373  *
2374  * Arguments:
2375  *	dip		    - pointer to devinfo of the client
2376  *	reset_level	    - see above
2377  *
2378  * Return values:
2379  *	USB_SUCCESS	    - With USB_RESET_LVL_DEFAULT: the device was reset
2380  *			      successfully.
2381  *			    - With USB_RESET_LVL_REATTACH: reenumeration was
2382  *			      started successfully or a previous reset is still
2383  *			      in progress.
2384  *	USB_FAILURE	    - The state of the device's parent hub is invalid
2385  *			      (disconnected or suspended).
2386  *			    - Called when the driver being detached.
2387  *			    - The device failed to be reset with
2388  *			      USB_RESET_LVL_DEFAULT specified.
2389  *			    - Reenumeration failed to start up with
2390  *			    - USB_RESET_LVL_REATTACH specified.
2391  *	USB_INVALID_ARGS    - Invalid arguments.
2392  *	USB_INVALID_PERM    - The driver of the dip doesn't own entire device.
2393  *	USB_BUSY	    - One or more pipes other than the default control
2394  *			      pipe are open on the device with
2395  *			      USB_RESET_LVL_DEFAULT specified.
2396  *	USB_INVALID_CONTEXT - Called from interrupt context with
2397  *			      USB_RESET_LVL_DEFAULT specified.
2398  */
2399 
2400 int usb_reset_device(
2401 	dev_info_t 		*dip,
2402 	usb_dev_reset_lvl_t	reset_level);
2403 
2404 
2405 /*
2406  * ***************************************************************************
2407  * USB Device and interface class, subclass and protocol codes
2408  * ***************************************************************************
2409  */
2410 
2411 /*
2412  * Available device and interface class codes.
2413  * Those which are device class codes are noted.
2414  */
2415 
2416 #define	USB_CLASS_AUDIO		1
2417 #define	USB_CLASS_COMM		2	/* Communication device class and */
2418 #define	USB_CLASS_CDC_CTRL	2	/* CDC-control iface class, also 2 */
2419 #define	USB_CLASS_HID		3
2420 #define	USB_CLASS_PHYSICAL	5
2421 #define	USB_CLASS_IMAGE		6
2422 #define	USB_CLASS_PRINTER	7
2423 #define	USB_CLASS_MASS_STORAGE	8
2424 #define	USB_CLASS_HUB		9	/* Device class */
2425 #define	USB_CLASS_CDC_DATA	10
2426 #define	USB_CLASS_CCID		11
2427 #define	USB_CLASS_SECURITY	13
2428 #define	USB_CLASS_VIDEO		14
2429 #define	USB_CLASS_DIAG		220	/* Device class */
2430 #define	USB_CLASS_WIRELESS	224
2431 #define	USB_CLASS_MISC		239	/* Device class */
2432 #define	USB_CLASS_APP		254
2433 #define	USB_CLASS_VENDOR_SPEC	255	/* Device class */
2434 
2435 #define	USB_CLASS_PER_INTERFACE	0	/* Class info is at interface level */
2436 
2437 /* Audio subclass. */
2438 #define	USB_SUBCLS_AUD_CONTROL		0x01
2439 #define	USB_SUBCLS_AUD_STREAMING	0x02
2440 #define	USB_SUBCLS_AUD_MIDI_STREAMING	0x03
2441 
2442 /* Comms  subclass. */
2443 #define	USB_SUBCLS_CDCC_DIRECT_LINE	0x01
2444 #define	USB_SUBCLS_CDCC_ABSTRCT_CTRL	0x02
2445 #define	USB_SUBCLS_CDCC_PHONE_CTRL	0x03
2446 #define	USB_SUBCLS_CDCC_MULTCNL_ISDN	0x04
2447 #define	USB_SUBCLS_CDCC_ISDN		0x05
2448 #define	USB_SUBCLS_CDCC_ETHERNET	0x06
2449 #define	USB_SUBCLS_CDCC_ATM_NETWORK	0x07
2450 
2451 /* HID subclass and protocols. */
2452 #define	USB_SUBCLS_HID_1		1
2453 
2454 #define	USB_PROTO_HID_KEYBOARD		0x01	/* legacy keyboard */
2455 #define	USB_PROTO_HID_MOUSE		0x02	/* legacy mouse */
2456 
2457 /* Printer subclass and protocols. */
2458 #define	USB_SUBCLS_PRINTER_1		1
2459 
2460 #define	USB_PROTO_PRINTER_UNI		0x01	/* Unidirectional interface */
2461 #define	USB_PROTO_PRINTER_BI		0x02	/* Bidirectional interface */
2462 
2463 /* Mass storage subclasses and protocols. */
2464 #define	USB_SUBCLS_MS_RBC_T10		0x1	/* flash */
2465 #define	USB_SUBCLS_MS_SFF8020I		0x2	/* CD-ROM */
2466 #define	USB_SUBCLS_MS_QIC_157		0x3	/* tape */
2467 #define	USB_SUBCLS_MS_UFI		0x4	/* USB Floppy Disk Drive   */
2468 #define	USB_SUBCLS_MS_SFF8070I		0x5	/* floppy */
2469 #define	USB_SUBCLS_MS_SCSI		0x6	/* transparent scsi */
2470 
2471 #define	USB_PROTO_MS_CBI_WC		0x00	/* USB CBI Proto w/cmp intr */
2472 #define	USB_PROTO_MS_CBI		0x01    /* USB CBI Protocol */
2473 #define	USB_PROTO_MS_ISD_1999_SILICN	0x02    /* ZIP Protocol */
2474 #define	USB_PROTO_MS_BULK_ONLY		0x50    /* USB Bulk Only Protocol */
2475 
2476 /* Application subclasses. */
2477 #define	USB_SUBCLS_APP_FIRMWARE		0x01	/* app spec f/w subclass */
2478 #define	USB_SUBCLS_APP_IRDA		0x02	/* app spec IrDa subclass */
2479 #define	USB_SUBCLS_APP_TEST		0x03	/* app spec test subclass */
2480 
2481 /* Video subclasses */
2482 #define	USB_SUBCLS_VIDEO_CONTROL	0x01	/* video control */
2483 #define	USB_SUBCLS_VIDEO_STREAM		0x02	/* video stream */
2484 #define	USB_SUBCLS_VIDEO_COLLECTION	0x03	/* video interface collection */
2485 
2486 /* Wireless controller subclasses and protocols */
2487 #define	USB_SUBCLS_WUSB_1		0x01
2488 #define	USB_SUBCLS_WUSB_2		0x02
2489 #define	USB_PROTO_WUSB_HWA		0x01	/* host wire adapter */
2490 #define	USB_PROTO_WUSB_DWA		0x02	/* device wire adapter */
2491 #define	USB_PROTO_WUSB_DWA_ISO		0x03	/* device wire adapter isoc */
2492 
2493 #ifdef __cplusplus
2494 }
2495 #endif
2496 
2497 #endif /* _SYS_USB_USBAI_H */
2498