xref: /onnv-gate/usr/src/uts/common/sys/usb/usbai.h (revision 10316:d68e26bd3bfd)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
53255Slg150142  * Common Development and Distribution License (the "License").
63255Slg150142  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
203255Slg150142  */
213255Slg150142 /*
229430SRaymond.Chen@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_SYS_USB_USBAI_H
270Sstevel@tonic-gate #define	_SYS_USB_USBAI_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #ifdef	__cplusplus
310Sstevel@tonic-gate extern "C" {
320Sstevel@tonic-gate #endif
330Sstevel@tonic-gate 
340Sstevel@tonic-gate /* This header file is for USBA2.0 */
350Sstevel@tonic-gate #define	USBA_MAJOR_VER 2
360Sstevel@tonic-gate #define	USBA_MINOR_VER 0
370Sstevel@tonic-gate 
380Sstevel@tonic-gate /*
390Sstevel@tonic-gate  * USBAI: Interfaces Between USBA and Client Driver
400Sstevel@tonic-gate  *
410Sstevel@tonic-gate  *
420Sstevel@tonic-gate  * Universal USB device state management :
430Sstevel@tonic-gate  *
440Sstevel@tonic-gate  *	PWRED_DWN---<3----4>--ONLINE---<2-----1>-DISCONNECTED
450Sstevel@tonic-gate  *	    |			 ^		     |
460Sstevel@tonic-gate  *	    |			 6		     |
470Sstevel@tonic-gate  *	    |			 |		     |
480Sstevel@tonic-gate  *	    |			 5		     |
490Sstevel@tonic-gate  *	    |			 v		     |
500Sstevel@tonic-gate  *	    +----5>----------SUSPENDED----<5----7>---+
510Sstevel@tonic-gate  *
520Sstevel@tonic-gate  *	1 = Device Unplug
530Sstevel@tonic-gate  *	2 = Original Device reconnected
540Sstevel@tonic-gate  *	3 = Device idles for time T & transitions to low power state
550Sstevel@tonic-gate  *	4 = Remote wakeup by device OR Application kicking off IO to device
560Sstevel@tonic-gate  *	5 = Notification to save state prior to DDI_SUSPEND
570Sstevel@tonic-gate  *	6 = Notification to restore state after DDI_RESUME with correct device
580Sstevel@tonic-gate  *	7 = Notification to restore state after DDI_RESUME with device
590Sstevel@tonic-gate  *	    disconnected or a wrong device
600Sstevel@tonic-gate  *
610Sstevel@tonic-gate  *	NOTE: device states 0x80 to 0xff are device specific and can be
620Sstevel@tonic-gate  *		used by client drivers
630Sstevel@tonic-gate  */
640Sstevel@tonic-gate #define	USB_DEV_ONLINE		1	/* device is online */
650Sstevel@tonic-gate #define	USB_DEV_DISCONNECTED	2	/* indicates disconnect */
660Sstevel@tonic-gate #define	USB_DEV_SUSPENDED	3	/* DDI_SUSPEND operation */
670Sstevel@tonic-gate #define	USB_DEV_PWRED_DOWN	4	/* indicates power off state */
680Sstevel@tonic-gate 
690Sstevel@tonic-gate 
700Sstevel@tonic-gate /*
710Sstevel@tonic-gate  * ***************************************************************************
720Sstevel@tonic-gate  * USBA error and status definitions
730Sstevel@tonic-gate  * ***************************************************************************
740Sstevel@tonic-gate  */
750Sstevel@tonic-gate 
760Sstevel@tonic-gate 
770Sstevel@tonic-gate /*
780Sstevel@tonic-gate  * USBA function return values
790Sstevel@tonic-gate  */
800Sstevel@tonic-gate #define	USB_SUCCESS		0	/* call success			  */
810Sstevel@tonic-gate #define	USB_FAILURE		-1	/* unspecified USBA or HCD error  */
820Sstevel@tonic-gate #define	USB_NO_RESOURCES	-2	/* no resources available	  */
830Sstevel@tonic-gate #define	USB_NO_BANDWIDTH	-3	/* no bandwidth available	  */
840Sstevel@tonic-gate #define	USB_NOT_SUPPORTED	-4	/* function not supported by HCD  */
850Sstevel@tonic-gate #define	USB_PIPE_ERROR		-5	/* error occured on the pipe	  */
860Sstevel@tonic-gate #define	USB_INVALID_PIPE	-6	/* pipe handle passed is invalid  */
870Sstevel@tonic-gate #define	USB_NO_FRAME_NUMBER	-7	/* frame No or ASAP not specified */
880Sstevel@tonic-gate #define	USB_INVALID_START_FRAME	-8	/* starting USB frame not valid	  */
890Sstevel@tonic-gate #define	USB_HC_HARDWARE_ERROR	-9	/* usb host controller error	  */
900Sstevel@tonic-gate #define	USB_INVALID_REQUEST	-10	/* request had invalid values	  */
910Sstevel@tonic-gate #define	USB_INVALID_CONTEXT	-11	/* sleep flag in interrupt context */
920Sstevel@tonic-gate #define	USB_INVALID_VERSION	-12	/* invalid version specified	  */
930Sstevel@tonic-gate #define	USB_INVALID_ARGS	-13	/* invalid func args specified	  */
940Sstevel@tonic-gate #define	USB_INVALID_PERM	-14	/* privileged operation		  */
950Sstevel@tonic-gate #define	USB_BUSY		-15	/* busy condition		  */
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 
980Sstevel@tonic-gate /*
990Sstevel@tonic-gate  * USB request completion flags, more than one may be set.
1000Sstevel@tonic-gate  * The following flags are returned after a recovery action by
1010Sstevel@tonic-gate  * HCD or USBA (autoclearing) or callbacks from pipe_close,
1020Sstevel@tonic-gate  * abort, reset, or stop polling.  More than one may be set.
1030Sstevel@tonic-gate  *
1040Sstevel@tonic-gate  * For sync requests, the client should check the request structure
1050Sstevel@tonic-gate  * for this flag to determine what has happened.
1060Sstevel@tonic-gate  *
1070Sstevel@tonic-gate  * All callbacks are queued to preserve order.	Note that if a normal callback
1080Sstevel@tonic-gate  * uses a kernel thread, order is not guaranteed since each callback may use
1090Sstevel@tonic-gate  * its own thread.  The next request will be submitted to the
1100Sstevel@tonic-gate  * HCD after the threads exits.
1110Sstevel@tonic-gate  *
1120Sstevel@tonic-gate  * Exception callbacks using a kernel thread may do auto clearing and no
1130Sstevel@tonic-gate  * new request will be started until this thread has completed its work.
1140Sstevel@tonic-gate  */
1150Sstevel@tonic-gate typedef enum {
1160Sstevel@tonic-gate 	USB_CB_NO_INFO		= 0x00, /* no exception */
1170Sstevel@tonic-gate 	USB_CB_STALL_CLEARED	= 0x01,	/* func stall cleared */
1180Sstevel@tonic-gate 	USB_CB_FUNCTIONAL_STALL	= 0x02,	/* func stall occurred */
1190Sstevel@tonic-gate 	USB_CB_PROTOCOL_STALL	= 0x04,	/* protocal stall occurred */
1200Sstevel@tonic-gate 	USB_CB_RESET_PIPE	= 0x10, /* pipe was reset */
1210Sstevel@tonic-gate 	USB_CB_ASYNC_REQ_FAILED = 0x80, /* thread couldn't be started */
1220Sstevel@tonic-gate 	USB_CB_NO_RESOURCES	= 0x100, /* no resources */
1230Sstevel@tonic-gate 	USB_CB_SUBMIT_FAILED	= 0x200, /* req was queued then submitted */
1240Sstevel@tonic-gate 					/* to HCD which rejected it */
1250Sstevel@tonic-gate 	USB_CB_INTR_CONTEXT	= 0x400 /* Callback is in interrupt context. */
1260Sstevel@tonic-gate } usb_cb_flags_t;
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate /*
1300Sstevel@tonic-gate  * completion reason
1310Sstevel@tonic-gate  *
1320Sstevel@tonic-gate  * Set by HCD; only one can be set.
1330Sstevel@tonic-gate  */
1340Sstevel@tonic-gate typedef enum {
1350Sstevel@tonic-gate 	USB_CR_OK		= 0,	/* no errors detected		*/
1360Sstevel@tonic-gate 	USB_CR_CRC		= 1,	/* crc error detected		*/
1370Sstevel@tonic-gate 	USB_CR_BITSTUFFING	= 2,	/* bit stuffing violation	*/
1380Sstevel@tonic-gate 	USB_CR_DATA_TOGGLE_MM	= 3,	/* d/t PID did not match	*/
1390Sstevel@tonic-gate 	USB_CR_STALL		= 4,	/* e/p returned stall PID	*/
1400Sstevel@tonic-gate 	USB_CR_DEV_NOT_RESP	= 5,	/* device not responding	*/
1410Sstevel@tonic-gate 	USB_CR_PID_CHECKFAILURE = 6,	/* check bits on PID failed	*/
1420Sstevel@tonic-gate 	USB_CR_UNEXP_PID	= 7,	/* receive PID was not valid	*/
1430Sstevel@tonic-gate 	USB_CR_DATA_OVERRUN	= 8,	/* data size exceeded		*/
1440Sstevel@tonic-gate 	USB_CR_DATA_UNDERRUN	= 9,	/* less data received		*/
1450Sstevel@tonic-gate 	USB_CR_BUFFER_OVERRUN	= 10,	/* memory write can't keep up	*/
1460Sstevel@tonic-gate 	USB_CR_BUFFER_UNDERRUN	= 11,	/* buffer underrun		*/
1470Sstevel@tonic-gate 	USB_CR_TIMEOUT		= 12,	/* command timed out		*/
1480Sstevel@tonic-gate 	USB_CR_NOT_ACCESSED	= 13,	/* Not accessed by hardware	*/
1490Sstevel@tonic-gate 	USB_CR_NO_RESOURCES	= 14,	/* no resources			*/
1500Sstevel@tonic-gate 	USB_CR_UNSPECIFIED_ERR	= 15,	/* unspecified usba or hcd err	*/
1510Sstevel@tonic-gate 	USB_CR_STOPPED_POLLING	= 16,	/* intr/isoc IN polling stopped	*/
1520Sstevel@tonic-gate 	USB_CR_PIPE_CLOSING	= 17,	/* intr/isoc IN pipe closed	*/
1530Sstevel@tonic-gate 	USB_CR_PIPE_RESET	= 18,	/* intr/isoc IN pipe reset	*/
1540Sstevel@tonic-gate 	USB_CR_NOT_SUPPORTED	= 19,	/* command not supported	*/
1550Sstevel@tonic-gate 	USB_CR_FLUSHED		= 20,	/* this request was flushed	*/
1560Sstevel@tonic-gate 	USB_CR_HC_HARDWARE_ERR	= 21	/* usb host controller error	*/
1570Sstevel@tonic-gate } usb_cr_t;
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate /*
1610Sstevel@tonic-gate  * ***************************************************************************
1620Sstevel@tonic-gate  * General definitions, used all over
1630Sstevel@tonic-gate  * ***************************************************************************
1640Sstevel@tonic-gate  *
1650Sstevel@tonic-gate  *	A pipe handle is returned by usb_pipe_open() on success for
1660Sstevel@tonic-gate  *	all pipes except the default pipe which is accessed from
1670Sstevel@tonic-gate  *	the registration structure.  Placed here as forward referenced by
1680Sstevel@tonic-gate  *	usb_client_dev_data_t below.
1690Sstevel@tonic-gate  *
1700Sstevel@tonic-gate  *	The pipe_handle is opaque to the client driver.
1710Sstevel@tonic-gate  */
1720Sstevel@tonic-gate typedef	struct usb_pipe_handle	*usb_pipe_handle_t;
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate /*
1750Sstevel@tonic-gate  * General opaque pointer.
1760Sstevel@tonic-gate  */
1770Sstevel@tonic-gate typedef struct usb_opaque *usb_opaque_t;
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate /*
1810Sstevel@tonic-gate  * USB flags argument to USBA interfaces
1820Sstevel@tonic-gate  */
1830Sstevel@tonic-gate typedef enum {
1840Sstevel@tonic-gate 	/* do not block until resources are available */
1850Sstevel@tonic-gate 	USB_FLAGS_NOSLEEP		= 0x0000,
1860Sstevel@tonic-gate 	/* block until resources are available */
1870Sstevel@tonic-gate 	USB_FLAGS_SLEEP			= 0x0100,
1880Sstevel@tonic-gate 	/* reserved */
1890Sstevel@tonic-gate 	USB_FLAGS_RESERVED		= 0xFE00
1900Sstevel@tonic-gate } usb_flags_t;
1910Sstevel@tonic-gate 
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate /*
1940Sstevel@tonic-gate  * ***************************************************************************
1950Sstevel@tonic-gate  * Descriptor definitions (from USB 2.0 specification, chapter 9)
1960Sstevel@tonic-gate  * ***************************************************************************
1970Sstevel@tonic-gate  */
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate 
2000Sstevel@tonic-gate /*
2010Sstevel@tonic-gate  * USB Descriptor Management
2020Sstevel@tonic-gate  *
2030Sstevel@tonic-gate  * Standard USB descriptors:
2040Sstevel@tonic-gate  *
2050Sstevel@tonic-gate  * USB devices present their configuration information in response to
2060Sstevel@tonic-gate  * a GET_DESCRIPTOR request in a form which is little-endian and,
2070Sstevel@tonic-gate  * for multibyte integers, unaligned.  It is also position-dependent,
2080Sstevel@tonic-gate  * which makes non-sequential access to particular interface or
2090Sstevel@tonic-gate  * endpoint data inconvenient.
2100Sstevel@tonic-gate  * A GET_DESCRIPTOR request may yield a chunk of data that contains
2110Sstevel@tonic-gate  * multiple descriptor types.  For example, a GET_DESCRIPTOR request
2120Sstevel@tonic-gate  * for a CONFIGURATION descriptor could return the configuration
2130Sstevel@tonic-gate  * descriptor followed by an interface descriptor and the relevant
2140Sstevel@tonic-gate  * endpoint descriptors.
2150Sstevel@tonic-gate  *
2160Sstevel@tonic-gate  * usb_get_dev_data() interface provides an easy way to get all
2170Sstevel@tonic-gate  * the descriptors and avoids parsing standard descriptors by each
2180Sstevel@tonic-gate  * client driver
2190Sstevel@tonic-gate  *
2200Sstevel@tonic-gate  * usb_dev_descr:
2210Sstevel@tonic-gate  *	usb device descriptor, refer to	USB 2.0/9.6.1,
2220Sstevel@tonic-gate  */
2230Sstevel@tonic-gate typedef struct usb_dev_descr {
2240Sstevel@tonic-gate 	uint8_t		bLength;	/* descriptor size		*/
2250Sstevel@tonic-gate 	uint8_t		bDescriptorType; /* set to DEVICE		*/
2260Sstevel@tonic-gate 	uint16_t	bcdUSB;		/* USB spec rel. number	in bcd	*/
2270Sstevel@tonic-gate 	uint8_t		bDeviceClass;	/* class code			*/
2280Sstevel@tonic-gate 	uint8_t		bDeviceSubClass; /* sub	class code		*/
2290Sstevel@tonic-gate 	uint8_t		bDeviceProtocol; /* protocol code		*/
2300Sstevel@tonic-gate 	uint8_t		bMaxPacketSize0; /* max	pkt size of e/p	0	*/
2310Sstevel@tonic-gate 	uint16_t	idVendor;	/* vendor ID			*/
2320Sstevel@tonic-gate 	uint16_t	idProduct;	/* product ID			*/
2330Sstevel@tonic-gate 	uint16_t	bcdDevice;	/* device release number in bcd	*/
2340Sstevel@tonic-gate 	uint8_t		iManufacturer;	/* manufacturing string		*/
2350Sstevel@tonic-gate 	uint8_t		iProduct;	/* product string		*/
2360Sstevel@tonic-gate 	uint8_t		iSerialNumber;	/* serial number string index	*/
2370Sstevel@tonic-gate 	uint8_t		bNumConfigurations; /* #configs for device	*/
2380Sstevel@tonic-gate } usb_dev_descr_t;
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate 
2410Sstevel@tonic-gate /*
2420Sstevel@tonic-gate  * USB Device Qualifier Descriptor
2430Sstevel@tonic-gate  *
2440Sstevel@tonic-gate  * The device_qualifier descriptor describes information about a High
2450Sstevel@tonic-gate  * speed capable device that would change if the device were operating
2460Sstevel@tonic-gate  * at other (Full) speed. Example: if the device is currently operating
2470Sstevel@tonic-gate  * at Full-speed, the device_qualifier returns information about how if
2480Sstevel@tonic-gate  * would operate at high-speed and vice-versa.
2490Sstevel@tonic-gate  *
2500Sstevel@tonic-gate  * usb_dev_qlf_descr:
2510Sstevel@tonic-gate  *
2520Sstevel@tonic-gate  *	usb device qualifier descriptor, refer to USB 2.0/9.6.2
2530Sstevel@tonic-gate  */
2540Sstevel@tonic-gate typedef struct usb_dev_qlf_descr {
2550Sstevel@tonic-gate 	uint8_t		bLength;	/* descriptor size		*/
2560Sstevel@tonic-gate 	uint8_t		bDescriptorType; /* set to DEVICE		*/
2570Sstevel@tonic-gate 	uint16_t	bcdUSB;		/* USB spec rel. number	in bcd	*/
2580Sstevel@tonic-gate 	uint8_t		bDeviceClass;	/* class code			*/
2590Sstevel@tonic-gate 	uint8_t		bDeviceSubClass; /* sub	class code		*/
2600Sstevel@tonic-gate 	uint8_t		bDeviceProtocol; /* protocol code		*/
2610Sstevel@tonic-gate 	uint8_t		bMaxPacketSize0; /* max	pkt size of e/p	0	*/
2620Sstevel@tonic-gate 	uint8_t		bNumConfigurations; /* #configs for device	*/
2630Sstevel@tonic-gate 	uint8_t		bReserved;	/* reserved field		*/
2640Sstevel@tonic-gate } usb_dev_qlf_descr_t;
2650Sstevel@tonic-gate 
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate /*
2680Sstevel@tonic-gate  * usb_cfg_descr:
2690Sstevel@tonic-gate  *	usb configuration descriptor, refer to USB 2.0/9.6.3
2700Sstevel@tonic-gate  */
2710Sstevel@tonic-gate typedef struct usb_cfg_descr {
2720Sstevel@tonic-gate 	uint8_t		bLength;	/* descriptor size		*/
2730Sstevel@tonic-gate 	uint8_t		bDescriptorType; /* set to CONFIGURATION	*/
2740Sstevel@tonic-gate 	uint16_t	wTotalLength;	/* total length of data returned */
2750Sstevel@tonic-gate 	uint8_t		bNumInterfaces;	/* # interfaces	in config	*/
2760Sstevel@tonic-gate 	uint8_t		bConfigurationValue; /* arg for SetConfiguration */
2770Sstevel@tonic-gate 	uint8_t		iConfiguration;	/* configuration string		*/
2780Sstevel@tonic-gate 	uint8_t		bmAttributes;	/* config characteristics	*/
2790Sstevel@tonic-gate 	uint8_t		bMaxPower;	/* max pwr consumption		*/
2800Sstevel@tonic-gate } usb_cfg_descr_t;
2810Sstevel@tonic-gate 
2820Sstevel@tonic-gate /*
2830Sstevel@tonic-gate  * Default configuration index setting for devices with multiple
2840Sstevel@tonic-gate  * configurations. Note the distinction between config index and config
2850Sstevel@tonic-gate  * number
2860Sstevel@tonic-gate  */
2870Sstevel@tonic-gate #define	USB_DEV_DEFAULT_CONFIG_INDEX	0
2880Sstevel@tonic-gate 
2890Sstevel@tonic-gate /*
2900Sstevel@tonic-gate  * bmAttribute values for Configuration Descriptor
2910Sstevel@tonic-gate  */
2920Sstevel@tonic-gate #define	USB_CFG_ATTR_SELFPWR		0x40
2930Sstevel@tonic-gate #define	USB_CFG_ATTR_REMOTE_WAKEUP	0x20
2949430SRaymond.Chen@Sun.COM #define	USB_CFG_ATTR_BAT_PWR		0x10
2950Sstevel@tonic-gate 
2960Sstevel@tonic-gate /*
2970Sstevel@tonic-gate  * USB Other Speed Configuration Descriptor
2980Sstevel@tonic-gate  *
2990Sstevel@tonic-gate  * The other_speed_configuration descriptor describes a configuration of
3000Sstevel@tonic-gate  * a High speed capable device if it were operating at its other possible
3010Sstevel@tonic-gate  * (Full) speed and vice-versa.
3020Sstevel@tonic-gate  *
3030Sstevel@tonic-gate  * usb_other_speed_cfg_descr:
3040Sstevel@tonic-gate  *	usb other speed configuration descriptor, refer to USB 2.0/9.6.4
3050Sstevel@tonic-gate  */
3060Sstevel@tonic-gate typedef struct usb_other_speed_cfg_descr {
3070Sstevel@tonic-gate 	uint8_t		bLength;	/* descriptor size		*/
3080Sstevel@tonic-gate 	uint8_t		bDescriptorType; /* set to CONFIGURATION	*/
3090Sstevel@tonic-gate 	uint16_t	wTotalLength;	/* total length of data returned */
3100Sstevel@tonic-gate 	uint8_t		bNumInterfaces;	/* # interfaces	in config	*/
3110Sstevel@tonic-gate 	uint8_t		bConfigurationValue; /* arg for SetConfiguration */
3120Sstevel@tonic-gate 	uint8_t		iConfiguration;	/* configuration string		*/
3130Sstevel@tonic-gate 	uint8_t		bmAttributes;	/* config characteristics	*/
3140Sstevel@tonic-gate 	uint8_t		bMaxPower;	/* max pwr consumption		*/
3150Sstevel@tonic-gate } usb_other_speed_cfg_descr_t;
3160Sstevel@tonic-gate 
3170Sstevel@tonic-gate 
3180Sstevel@tonic-gate /*
3193341Sgc161489  * usb_ia_descr:
3203341Sgc161489  *	usb interface association descriptor, refer to USB 2.0 ECN(IAD)
3213341Sgc161489  */
3223341Sgc161489 typedef  struct usb_ia_descr {
3233341Sgc161489 	uint8_t		bLength;		/* descriptor size	*/
3243341Sgc161489 	uint8_t		bDescriptorType;	/* INTERFACE_ASSOCIATION */
3253341Sgc161489 	uint8_t		bFirstInterface;	/* 1st interface number */
3263341Sgc161489 	uint8_t		bInterfaceCount;	/* number of interfaces */
3273341Sgc161489 	uint8_t		bFunctionClass;		/* class code		*/
3283341Sgc161489 	uint8_t		bFunctionSubClass;	/* sub class code	*/
3293341Sgc161489 	uint8_t		bFunctionProtocol;	/* protocol code	*/
3303341Sgc161489 	uint8_t		iFunction;		/* description string	*/
3313341Sgc161489 } usb_ia_descr_t;
3323341Sgc161489 
3333341Sgc161489 
3343341Sgc161489 /*
3350Sstevel@tonic-gate  * usb_if_descr:
3360Sstevel@tonic-gate  *	usb interface descriptor, refer	to USB 2.0/9.6.5
3370Sstevel@tonic-gate  */
3380Sstevel@tonic-gate typedef  struct usb_if_descr {
3390Sstevel@tonic-gate 	uint8_t		bLength;		/* descriptor size	*/
3400Sstevel@tonic-gate 	uint8_t		bDescriptorType;	/* set to INTERFACE	*/
3410Sstevel@tonic-gate 	uint8_t		bInterfaceNumber;	/* interface number	*/
3420Sstevel@tonic-gate 	uint8_t		bAlternateSetting;	/* alt. interface number */
3430Sstevel@tonic-gate 	uint8_t		bNumEndpoints;		/* # of endpoints	*/
3440Sstevel@tonic-gate 	uint8_t		bInterfaceClass;	/* class code		*/
3450Sstevel@tonic-gate 	uint8_t		bInterfaceSubClass;	/* sub class code	*/
3460Sstevel@tonic-gate 	uint8_t		bInterfaceProtocol;	/* protocol code	*/
3470Sstevel@tonic-gate 	uint8_t		iInterface;		/* description string	*/
3480Sstevel@tonic-gate } usb_if_descr_t;
3490Sstevel@tonic-gate 
3500Sstevel@tonic-gate 
3510Sstevel@tonic-gate /*
3520Sstevel@tonic-gate  * usb_ep_descr:
3530Sstevel@tonic-gate  *	usb endpoint descriptor, refer to USB 2.0/9.6.6
3540Sstevel@tonic-gate  */
3550Sstevel@tonic-gate typedef struct usb_ep_descr {
3560Sstevel@tonic-gate 	uint8_t		bLength;		/* descriptor size	*/
3570Sstevel@tonic-gate 	uint8_t		bDescriptorType;	/* set to ENDPOINT	*/
3580Sstevel@tonic-gate 	uint8_t		bEndpointAddress;	/* address of this e/p */
3590Sstevel@tonic-gate 	uint8_t		bmAttributes;		/* transfer type	*/
3600Sstevel@tonic-gate 	uint16_t	wMaxPacketSize;		/* maximum packet size	*/
3610Sstevel@tonic-gate 	uint8_t		bInterval;		/* e/p polling interval */
3620Sstevel@tonic-gate } usb_ep_descr_t;
3630Sstevel@tonic-gate 
3640Sstevel@tonic-gate /*
3650Sstevel@tonic-gate  * bEndpointAddress masks
3660Sstevel@tonic-gate  */
3670Sstevel@tonic-gate #define	USB_EP_NUM_MASK		0x0F		/* endpoint number mask */
3680Sstevel@tonic-gate #define	USB_EP_DIR_MASK		0x80		/* direction mask */
3690Sstevel@tonic-gate #define	USB_EP_DIR_OUT		0x00		/* OUT endpoint */
3700Sstevel@tonic-gate #define	USB_EP_DIR_IN		0x80		/* IN endpoint */
3710Sstevel@tonic-gate 
3720Sstevel@tonic-gate /*
3730Sstevel@tonic-gate  * bmAttribute transfer types for endpoints
3740Sstevel@tonic-gate  */
3750Sstevel@tonic-gate #define	USB_EP_ATTR_MASK	0x03		/* transfer type mask */
3760Sstevel@tonic-gate #define	USB_EP_ATTR_CONTROL	0x00		/* control transfer */
3770Sstevel@tonic-gate #define	USB_EP_ATTR_ISOCH	0x01		/* isochronous transfer */
3780Sstevel@tonic-gate #define	USB_EP_ATTR_BULK	0x02		/* bulk transfer */
3790Sstevel@tonic-gate #define	USB_EP_ATTR_INTR	0x03		/* interrupt transfer */
3800Sstevel@tonic-gate 
3810Sstevel@tonic-gate /*
3820Sstevel@tonic-gate  * bmAttribute synchronization types for endpoints (isochronous only)
3830Sstevel@tonic-gate  */
3840Sstevel@tonic-gate #define	USB_EP_SYNC_MASK	0x0C		/* synchronization mask */
3850Sstevel@tonic-gate #define	USB_EP_SYNC_NONE	0x00		/* no synchronization */
3860Sstevel@tonic-gate #define	USB_EP_SYNC_ASYNC	0x04		/* asynchronous */
3870Sstevel@tonic-gate #define	USB_EP_SYNC_ADPT	0x08		/* adaptive */
3880Sstevel@tonic-gate #define	USB_EP_SYNC_SYNC	0x0C		/* synchronous */
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate /*
3910Sstevel@tonic-gate  * bmAttribute synchronization feedback types for endpoints (isochronous only)
3920Sstevel@tonic-gate  */
3930Sstevel@tonic-gate #define	USB_EP_USAGE_MASK	0x30		/* sync feedback mask */
3940Sstevel@tonic-gate #define	USB_EP_USAGE_DATA	0x00		/* data endpoint */
3950Sstevel@tonic-gate #define	USB_EP_USAGE_FEED	0x10		/* feedback endpoint */
3960Sstevel@tonic-gate #define	USB_EP_USAGE_IMPL	0x20		/* implicit feedback endpoint */
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate /*
3990Sstevel@tonic-gate  * wMaxPacketSize values for endpoints (isoch and interrupt, high speed only)
4000Sstevel@tonic-gate  */
4010Sstevel@tonic-gate #define	USB_EP_MAX_PKTSZ_MASK	0x03FF		/* Mask for packetsize bits */
4020Sstevel@tonic-gate #define	USB_EP_MAX_XACTS_MASK	0x0C00		/* Max Transactns/microframe */
4030Sstevel@tonic-gate #define	USB_EP_MAX_XACTS_SHIFT	10		/* Above is 10 bits from end */
4040Sstevel@tonic-gate 
4050Sstevel@tonic-gate /*
4060Sstevel@tonic-gate  * Ranges for endpoint parameter values.
4070Sstevel@tonic-gate  */
4080Sstevel@tonic-gate 
4090Sstevel@tonic-gate /* Min and Max NAK rates for high sped control endpoints. */
4100Sstevel@tonic-gate #define	USB_EP_MIN_HIGH_CONTROL_INTRVL	0
4110Sstevel@tonic-gate #define	USB_EP_MAX_HIGH_CONTROL_INTRVL	255
4120Sstevel@tonic-gate 
4130Sstevel@tonic-gate /* Min and Max NAK rates for high speed bulk endpoints. */
4140Sstevel@tonic-gate #define	USB_EP_MIN_HIGH_BULK_INTRVL	0
4150Sstevel@tonic-gate #define	USB_EP_MAX_HIGH_BULK_INTRVL	255
4160Sstevel@tonic-gate 
4170Sstevel@tonic-gate /* Min and Max polling intervals for low, full speed interrupt endpoints. */
4180Sstevel@tonic-gate #define	USB_EP_MIN_LOW_INTR_INTRVL	1
4190Sstevel@tonic-gate #define	USB_EP_MAX_LOW_INTR_INTRVL	255
4200Sstevel@tonic-gate #define	USB_EP_MIN_FULL_INTR_INTRVL	1
4210Sstevel@tonic-gate #define	USB_EP_MAX_FULL_INTR_INTRVL	255
4220Sstevel@tonic-gate 
4230Sstevel@tonic-gate /*
4240Sstevel@tonic-gate  * Min and Max polling intervals for high speed interrupt endpoints, and for
4250Sstevel@tonic-gate  * isochronous endpoints.
4260Sstevel@tonic-gate  * Note that the interval is 2**(value-1).  See Section 9.6.6 of USB 2.0 spec.
4270Sstevel@tonic-gate  */
4280Sstevel@tonic-gate #define	USB_EP_MIN_HIGH_INTR_INTRVL	1
4290Sstevel@tonic-gate #define	USB_EP_MAX_HIGH_INTR_INTRVL	16
4300Sstevel@tonic-gate #define	USB_EP_MIN_FULL_ISOCH_INTRVL	1
4310Sstevel@tonic-gate #define	USB_EP_MAX_FULL_ISOCH_INTRVL	16
4320Sstevel@tonic-gate #define	USB_EP_MIN_HIGH_ISOCH_INTRVL	1
4330Sstevel@tonic-gate #define	USB_EP_MAX_HIGH_ISOCH_INTRVL	16
4340Sstevel@tonic-gate 
4350Sstevel@tonic-gate /*
4360Sstevel@tonic-gate  * usb_string_descr:
4370Sstevel@tonic-gate  *	usb string descriptor, refer to	 USB 2.0/9.6.7
4380Sstevel@tonic-gate  */
4390Sstevel@tonic-gate typedef struct usb_string_descr {
4400Sstevel@tonic-gate 	uint8_t		bLength;		/* descr size */
4410Sstevel@tonic-gate 	uint8_t		bDescriptorType;	/* set to STRING */
4420Sstevel@tonic-gate 	uint8_t		bString[1];		/* variable length unicode */
4430Sstevel@tonic-gate 						/* encoded string	*/
4440Sstevel@tonic-gate } usb_string_descr_t;
4450Sstevel@tonic-gate 
4460Sstevel@tonic-gate #define	USB_MAXSTRINGLEN	255		/* max string descr length */
4470Sstevel@tonic-gate 
4480Sstevel@tonic-gate 
4490Sstevel@tonic-gate /*
4509430SRaymond.Chen@Sun.COM  * usb_bos_descr:
4519430SRaymond.Chen@Sun.COM  *	usb BOS descriptor, refer to WUSB 1.0/7.4.1
4529430SRaymond.Chen@Sun.COM  */
4539430SRaymond.Chen@Sun.COM typedef struct usb_bos_descr {
4549430SRaymond.Chen@Sun.COM 	uint8_t		bLength;
4559430SRaymond.Chen@Sun.COM 	uint8_t		bDescriptorType;
4569430SRaymond.Chen@Sun.COM 	uint16_t	wTotalLength;
4579430SRaymond.Chen@Sun.COM 	uint8_t		bNumDeviceCaps;
4589430SRaymond.Chen@Sun.COM } usb_bos_descr_t;
4599430SRaymond.Chen@Sun.COM 
4609430SRaymond.Chen@Sun.COM /*
4619430SRaymond.Chen@Sun.COM  * usb_dev_cap_header:
4629430SRaymond.Chen@Sun.COM  *	usb device capability descriptor header, refer to WUSB 1.0/7.4.1
4639430SRaymond.Chen@Sun.COM  */
4649430SRaymond.Chen@Sun.COM typedef struct usb_cap_descr_header {
4659430SRaymond.Chen@Sun.COM 	uint8_t		bLength;
4669430SRaymond.Chen@Sun.COM 	uint8_t		bDescriptorType;
4679430SRaymond.Chen@Sun.COM 	uint8_t		bDevCapabilityType;
4689430SRaymond.Chen@Sun.COM } usb_cap_descr_header_t;
4699430SRaymond.Chen@Sun.COM 
4709430SRaymond.Chen@Sun.COM typedef struct usb_cap_descr {
4719430SRaymond.Chen@Sun.COM 	uint8_t		bLength;
4729430SRaymond.Chen@Sun.COM 	uint8_t		bDescriptorType;	/* set to DEVICE CAPABILITY */
4739430SRaymond.Chen@Sun.COM 	uint8_t		bDevCapabilityType;
4749430SRaymond.Chen@Sun.COM 	uint8_t		bCapValue[1];		/* variable length data */
4759430SRaymond.Chen@Sun.COM } usb_cap_descr_t;
4769430SRaymond.Chen@Sun.COM 
4779430SRaymond.Chen@Sun.COM #define	USB_CAP_TYPE_WUSB	1
4789430SRaymond.Chen@Sun.COM 
4799430SRaymond.Chen@Sun.COM /* Wireless USB device capability descriptor - UWB descriptor */
4809430SRaymond.Chen@Sun.COM typedef struct usb_uwb_cap_descr {
4819430SRaymond.Chen@Sun.COM 	uint8_t		bLength;
4829430SRaymond.Chen@Sun.COM 	uint8_t		bDescriptorType;
4839430SRaymond.Chen@Sun.COM 	uint8_t		bDevCapabilityType;
4849430SRaymond.Chen@Sun.COM 	uint8_t		bmAttributes;
4859430SRaymond.Chen@Sun.COM 	uint16_t	wPHYRates;
4869430SRaymond.Chen@Sun.COM 	uint8_t		bmTFITXPowerInfo;
4879430SRaymond.Chen@Sun.COM 	uint8_t		bmFFITXPowerInfo;
4889430SRaymond.Chen@Sun.COM 	uint16_t	bmBandGroup;
4899430SRaymond.Chen@Sun.COM 	uint8_t		bReserved;
4909430SRaymond.Chen@Sun.COM } usb_uwb_cap_descr_t;
4919430SRaymond.Chen@Sun.COM 
4929430SRaymond.Chen@Sun.COM /*
4939430SRaymond.Chen@Sun.COM  * usb_ep_comp_descr:
4949430SRaymond.Chen@Sun.COM  *	usb endpoint companion descriptor, refer to WUSB 1.0/7.4.4
4959430SRaymond.Chen@Sun.COM  */
4969430SRaymond.Chen@Sun.COM typedef struct usb_ep_comp_descr {
4979430SRaymond.Chen@Sun.COM 	uint8_t		bLength;
4989430SRaymond.Chen@Sun.COM 	uint8_t		bDescriptorType;
4999430SRaymond.Chen@Sun.COM 	uint8_t		bMaxBurst;
5009430SRaymond.Chen@Sun.COM 	uint8_t		bMaxSequence;
5019430SRaymond.Chen@Sun.COM 	uint16_t	wMaxStreamDelay;
5029430SRaymond.Chen@Sun.COM 	uint16_t	wOverTheAirPacketSize;
5039430SRaymond.Chen@Sun.COM 	uint8_t		bOverTheAirInterval;
5049430SRaymond.Chen@Sun.COM 	uint8_t		bmCompAttributes;
5059430SRaymond.Chen@Sun.COM } usb_ep_comp_descr_t;
5069430SRaymond.Chen@Sun.COM 
5079430SRaymond.Chen@Sun.COM /*
5089430SRaymond.Chen@Sun.COM  * usb_security_descr:
5099430SRaymond.Chen@Sun.COM  *	usb security descriptor, refer to WUSB 1.0/7.4.5
5109430SRaymond.Chen@Sun.COM  */
5119430SRaymond.Chen@Sun.COM typedef struct usb_security_descr {
5129430SRaymond.Chen@Sun.COM 	uint8_t		bLength;
5139430SRaymond.Chen@Sun.COM 	uint8_t		bDescriptorType;
5149430SRaymond.Chen@Sun.COM 	uint16_t	wTotalLength;
5159430SRaymond.Chen@Sun.COM 	uint8_t		bNumEncryptionTypes;
5169430SRaymond.Chen@Sun.COM } usb_security_descr_t;
5179430SRaymond.Chen@Sun.COM 
5189430SRaymond.Chen@Sun.COM /*
5199430SRaymond.Chen@Sun.COM  * usb_encryption_descr:
5209430SRaymond.Chen@Sun.COM  *	usb encryption descriptor, refer to WUSB 1.0/7.4.5
5219430SRaymond.Chen@Sun.COM  */
5229430SRaymond.Chen@Sun.COM typedef struct usb_encryption_descr {
5239430SRaymond.Chen@Sun.COM 	uint8_t		bLength;
5249430SRaymond.Chen@Sun.COM 	uint8_t		bDescriptorType;
5259430SRaymond.Chen@Sun.COM 	uint8_t		bEncryptionType;
5269430SRaymond.Chen@Sun.COM 	uint8_t		bEncryptionValue;
5279430SRaymond.Chen@Sun.COM 	uint8_t		bAuthKeyIndex;
5289430SRaymond.Chen@Sun.COM } usb_encryption_descr_t;
5299430SRaymond.Chen@Sun.COM 
5309430SRaymond.Chen@Sun.COM #define	USB_ENC_TYPE_UNSECURE		0x00
5319430SRaymond.Chen@Sun.COM #define	USB_ENC_TYPE_WIRED		0x01
5329430SRaymond.Chen@Sun.COM #define	USB_ENC_TYPE_CCM_1		0x02
5339430SRaymond.Chen@Sun.COM #define	USB_ENC_TYPE_RSA_1		0x03
5349430SRaymond.Chen@Sun.COM 
5359430SRaymond.Chen@Sun.COM /*
5369430SRaymond.Chen@Sun.COM  * usb_key_descr:
5379430SRaymond.Chen@Sun.COM  *	usb key descriptor, refer to WUSB 1.0/7.4.5
5389430SRaymond.Chen@Sun.COM  */
5399430SRaymond.Chen@Sun.COM typedef struct usb_key_descr {
5409430SRaymond.Chen@Sun.COM 	uint8_t		bLength;
5419430SRaymond.Chen@Sun.COM 	uint8_t		bDescriptorType;
5429430SRaymond.Chen@Sun.COM 	uint8_t		tTKID[3];
5439430SRaymond.Chen@Sun.COM 	uint8_t		bReserved;
5449430SRaymond.Chen@Sun.COM 	uint8_t		KeyData[1];	/* variable length */
5459430SRaymond.Chen@Sun.COM } usb_key_descr_t;
5469430SRaymond.Chen@Sun.COM 
5479430SRaymond.Chen@Sun.COM #define	USB_EP_COMP_DESCR_SIZE		10
5489430SRaymond.Chen@Sun.COM #define	USB_BOS_DESCR_SIZE		5
5499430SRaymond.Chen@Sun.COM #define	USB_CAP_DESCR_HEADER_SIZE	3
5509430SRaymond.Chen@Sun.COM #define	USB_UWB_CAP_DESCR_SIZE		11
5519430SRaymond.Chen@Sun.COM #define	USB_SECURITY_DESCR_SIZE		5
5529430SRaymond.Chen@Sun.COM #define	USB_ENCRYPTION_DESCR_SIZE	5
5539430SRaymond.Chen@Sun.COM 
5549430SRaymond.Chen@Sun.COM 
5559430SRaymond.Chen@Sun.COM /*
5560Sstevel@tonic-gate  * ***************************************************************************
5570Sstevel@tonic-gate  * Client driver registration with USBA
5580Sstevel@tonic-gate  * ***************************************************************************
5590Sstevel@tonic-gate  *
5600Sstevel@tonic-gate  *	The client registers with USBA during attach in two steps
5610Sstevel@tonic-gate  *	using usb_client_attach() and usb_get_dev_data(). On completion, the
5620Sstevel@tonic-gate  *	registration data has been initialized.  Most data items are
5630Sstevel@tonic-gate  *	straightforward.  Among the items returned in the data is the tree of
5640Sstevel@tonic-gate  *	parsed descriptors, in dev_cfg;	 the number of configurations parsed,
5650Sstevel@tonic-gate  *	in dev_n_cfg; a pointer to the current configuration in the tree,
5660Sstevel@tonic-gate  *	in dev_curr_cfg; the index of the first valid interface in the
5670Sstevel@tonic-gate  *	tree, in dev_curr_if, and a parse level that accurately reflects what
5680Sstevel@tonic-gate  *	is in the tree, in dev_parse_level.
5690Sstevel@tonic-gate  */
5700Sstevel@tonic-gate 
5710Sstevel@tonic-gate 
5720Sstevel@tonic-gate /*
5730Sstevel@tonic-gate  * ***************************************************************************
5740Sstevel@tonic-gate  * Data structures used in the configuration tree
5750Sstevel@tonic-gate  * ***************************************************************************
5760Sstevel@tonic-gate  */
5770Sstevel@tonic-gate 
5780Sstevel@tonic-gate /*
5790Sstevel@tonic-gate  * Tree data structure for each configuration in the tree
5800Sstevel@tonic-gate  */
5810Sstevel@tonic-gate typedef struct usb_cfg_data {
5820Sstevel@tonic-gate 	struct usb_cfg_descr	cfg_descr;	/* parsed config descr */
5830Sstevel@tonic-gate 	struct usb_if_data	*cfg_if;	/* interfaces for this cfg */
5840Sstevel@tonic-gate 						/* indexed by interface num */
5850Sstevel@tonic-gate 	struct usb_cvs_data	*cfg_cvs;	/* class/vendor specific */
5860Sstevel@tonic-gate 						/* descrs mod/extend cfg */
5870Sstevel@tonic-gate 	char			*cfg_str;	/* string descriptor */
5880Sstevel@tonic-gate 	uint_t			cfg_n_if;	/* #elements in cfg_if[] */
5890Sstevel@tonic-gate 	uint_t			cfg_n_cvs;	/* #elements in cfg_cvs[] */
5900Sstevel@tonic-gate 	uint_t			cfg_strsize;	/* size of string descr */
5910Sstevel@tonic-gate } usb_cfg_data_t;
5920Sstevel@tonic-gate 
5930Sstevel@tonic-gate 
5940Sstevel@tonic-gate /*
5950Sstevel@tonic-gate  * Tree data structure for each alternate interface set
5960Sstevel@tonic-gate  * in each represented configuration
5970Sstevel@tonic-gate  */
5980Sstevel@tonic-gate typedef struct usb_if_data {
5990Sstevel@tonic-gate 	struct usb_alt_if_data	*if_alt;	/* sparse array of alts */
6000Sstevel@tonic-gate 						/* indexed by alt setting */
6010Sstevel@tonic-gate 	uint_t			if_n_alt;	/* #elements in if_alt[] */
6020Sstevel@tonic-gate } usb_if_data_t;
6030Sstevel@tonic-gate 
6040Sstevel@tonic-gate 
6050Sstevel@tonic-gate /*
6060Sstevel@tonic-gate  * Tree data structure for each alternate of each alternate interface set
6070Sstevel@tonic-gate  */
6080Sstevel@tonic-gate typedef struct usb_alt_if_data {
6090Sstevel@tonic-gate 	usb_if_descr_t		altif_descr;	/* parsed alternate if descr */
6100Sstevel@tonic-gate 	struct usb_ep_data	*altif_ep;	/* endpts for alt if */
6110Sstevel@tonic-gate 						/* (not a sparse array */
6120Sstevel@tonic-gate 	struct usb_cvs_data	*altif_cvs;	/* cvs for this alt if */
6130Sstevel@tonic-gate 	char			*altif_str;	/* string descriptor */
6140Sstevel@tonic-gate 	uint_t			altif_n_ep;	/* #elements in altif_ep[] */
6150Sstevel@tonic-gate 	uint_t			altif_n_cvs;	/* #elements in  altif_cvs[] */
6160Sstevel@tonic-gate 	uint_t			altif_strsize;	/* size of string descr */
6170Sstevel@tonic-gate } usb_alt_if_data_t;
6180Sstevel@tonic-gate 
6190Sstevel@tonic-gate 
6200Sstevel@tonic-gate /*
6210Sstevel@tonic-gate  * Tree data structure for each endpoint of each alternate
6220Sstevel@tonic-gate  */
6230Sstevel@tonic-gate typedef struct usb_ep_data {
6240Sstevel@tonic-gate 	usb_ep_descr_t		ep_descr;	/* endpoint descriptor */
6259430SRaymond.Chen@Sun.COM 	usb_ep_comp_descr_t	ep_comp_descr;	/* endpoint companion descr */
6260Sstevel@tonic-gate 	struct usb_cvs_data	*ep_cvs;	/* cv mod/extending this ep */
6270Sstevel@tonic-gate 	uint_t			ep_n_cvs;	/* #elements in ep_cvs[] */
6280Sstevel@tonic-gate } usb_ep_data_t;
6290Sstevel@tonic-gate 
6300Sstevel@tonic-gate 
6310Sstevel@tonic-gate /*
6320Sstevel@tonic-gate  * Tree data structure for each class/vendor specific descriptor
6330Sstevel@tonic-gate  */
6340Sstevel@tonic-gate typedef struct usb_cvs_data {
6350Sstevel@tonic-gate 	uchar_t			*cvs_buf;	/* raw data of cvs descr */
6360Sstevel@tonic-gate 	uint_t			cvs_buf_len;	/* cvs_buf size */
6370Sstevel@tonic-gate } usb_cvs_data_t;
6380Sstevel@tonic-gate 
6390Sstevel@tonic-gate 
6400Sstevel@tonic-gate /*
6419430SRaymond.Chen@Sun.COM  * Data structure for wireless USB specific descriptor
6429430SRaymond.Chen@Sun.COM  */
6439430SRaymond.Chen@Sun.COM typedef struct usb_bos_data {
6449430SRaymond.Chen@Sun.COM 	usb_bos_descr_t		bos_descr;	/* parsed bos descr */
6459430SRaymond.Chen@Sun.COM 	usb_uwb_cap_descr_t	bos_uwb_cap;	/* uwb cap descr */
6469430SRaymond.Chen@Sun.COM } usb_bos_data_t;
6479430SRaymond.Chen@Sun.COM 
6489430SRaymond.Chen@Sun.COM 
6499430SRaymond.Chen@Sun.COM /*
6500Sstevel@tonic-gate  *	Parse_level determines the extent to which the tree is built, the amount
6510Sstevel@tonic-gate  *	of parsing usb_client_attach() is to do.  It has the following values:
6520Sstevel@tonic-gate  *
6530Sstevel@tonic-gate  *	USB_PARSE_LVL_NONE - Build no tree.  dev_n_cfg will return 0, dev_cfg
6540Sstevel@tonic-gate  *			     will return NULL, the dev_curr_xxx fields will be
6550Sstevel@tonic-gate  *			     invalid.
6560Sstevel@tonic-gate  *	USB_PARSE_LVL_IF   - Parse configured interface only, if configuration#
6570Sstevel@tonic-gate  *			     and interface properties are set (as when different
6580Sstevel@tonic-gate  *			     interfaces are viewed by the OS as different device
6590Sstevel@tonic-gate  *			     instances). If an OS device instance is set up to
6600Sstevel@tonic-gate  *			     represent an entire physical device, this works
6610Sstevel@tonic-gate  *			     like USB_PARSE_LVL_ALL.
6620Sstevel@tonic-gate  *	USB_PARSE_LVL_CFG  - Parse entire configuration of configured interface
6630Sstevel@tonic-gate  *			     only.  This is like USB_PARSE_LVL_IF except entire
6640Sstevel@tonic-gate  *			     configuration is returned.
6650Sstevel@tonic-gate  *	USB_PARSE_LVL_ALL  - Parse entire device (all configurations), even
6660Sstevel@tonic-gate  *			     when driver is bound to a single interface of a
6670Sstevel@tonic-gate  *			     single configuration.
6680Sstevel@tonic-gate  */
6690Sstevel@tonic-gate typedef enum {
6700Sstevel@tonic-gate 	USB_PARSE_LVL_NONE		= 0,
6710Sstevel@tonic-gate 	USB_PARSE_LVL_IF		= 1,
6720Sstevel@tonic-gate 	USB_PARSE_LVL_CFG		= 2,
6730Sstevel@tonic-gate 	USB_PARSE_LVL_ALL		= 3
6740Sstevel@tonic-gate } usb_reg_parse_lvl_t;
6750Sstevel@tonic-gate 
6760Sstevel@tonic-gate 
6770Sstevel@tonic-gate /*
6780Sstevel@tonic-gate  * Registration data returned by usb_get_dev_data().  Configuration tree roots
6790Sstevel@tonic-gate  * are returned in dev_cfg array.
6800Sstevel@tonic-gate  */
6810Sstevel@tonic-gate typedef struct usb_client_dev_data {
6820Sstevel@tonic-gate 	usb_pipe_handle_t	dev_default_ph;	/* default pipe handle */
6830Sstevel@tonic-gate 	ddi_iblock_cookie_t	dev_iblock_cookie; /* for mutex_init's */
6840Sstevel@tonic-gate 	struct usb_dev_descr	*dev_descr;	/* cooked device descriptor */
6850Sstevel@tonic-gate 	char			*dev_mfg;	/* manufacturing ID */
6860Sstevel@tonic-gate 	char			*dev_product;	/* product ID */
6870Sstevel@tonic-gate 	char			*dev_serial;	/* serial number */
6880Sstevel@tonic-gate 	usb_reg_parse_lvl_t	dev_parse_level; /* USB_PARSE_LVL_* flag */
6890Sstevel@tonic-gate 	struct usb_cfg_data	*dev_cfg;	/* configs for this device */
6900Sstevel@tonic-gate 						/* indexed by config index */
6910Sstevel@tonic-gate 	uint_t			dev_n_cfg;	/* #elements in dev_cfg[] */
6920Sstevel@tonic-gate 	struct usb_cfg_data	*dev_curr_cfg;	/* current cfg */
6930Sstevel@tonic-gate 	int			dev_curr_if;	/* current interface number */
6949430SRaymond.Chen@Sun.COM 	struct usb_bos_data	*dev_bos;	/* bos for this device */
6950Sstevel@tonic-gate } usb_client_dev_data_t;
6960Sstevel@tonic-gate 
6970Sstevel@tonic-gate 
6980Sstevel@tonic-gate /*
6990Sstevel@tonic-gate  * ***************************************************************************
7000Sstevel@tonic-gate  * Device configuration descriptor tree functions
7010Sstevel@tonic-gate  * ***************************************************************************
7020Sstevel@tonic-gate  */
7030Sstevel@tonic-gate 
7040Sstevel@tonic-gate /*
7050Sstevel@tonic-gate  * usb_get_dev_data:
7060Sstevel@tonic-gate  *	returns initialized registration data. 	Most data items are clear.
7070Sstevel@tonic-gate  *	Among the items returned is the tree ofparsed descriptors in dev_cfg;
7080Sstevel@tonic-gate  *	and the number of configurations parsed in dev_n_cfg.
7090Sstevel@tonic-gate  *
7100Sstevel@tonic-gate  * Arguments:
7110Sstevel@tonic-gate  *	dip		- pointer to devinfo node of the client
7120Sstevel@tonic-gate  *	dev_data	- return registration data at this address
7130Sstevel@tonic-gate  *	parse_level	- See above
7140Sstevel@tonic-gate  *	flags		- None used
7150Sstevel@tonic-gate  *
7160Sstevel@tonic-gate  * Return Values:
7170Sstevel@tonic-gate  *	USB_SUCCESS		- usb_register_client succeeded
7180Sstevel@tonic-gate  *	USB_INVALID_ARGS	- received null dip or reg argument
7190Sstevel@tonic-gate  *	USB_INVALID_CONTEXT	- called with sleep from callback context
7200Sstevel@tonic-gate  *	USB_FAILURE		- bad descriptor info or other internal failure
7210Sstevel@tonic-gate  *
7220Sstevel@tonic-gate  * Notes:
7230Sstevel@tonic-gate  * 	1) The non-standard USB descriptors are returned in RAW format.
7240Sstevel@tonic-gate  *
7250Sstevel@tonic-gate  *	2) The registration data is unshared. Each client receives its own copy.
7260Sstevel@tonic-gate  *	(The default control pipe may be shared, even though its tree
7270Sstevel@tonic-gate  *	description will be unique per device.)
7280Sstevel@tonic-gate  *
7290Sstevel@tonic-gate  */
7300Sstevel@tonic-gate int usb_get_dev_data(
7310Sstevel@tonic-gate 	dev_info_t			*dip,
7320Sstevel@tonic-gate 	usb_client_dev_data_t		**dev_data,
7330Sstevel@tonic-gate 	usb_reg_parse_lvl_t		parse_level,
7340Sstevel@tonic-gate 	usb_flags_t			flags);
7350Sstevel@tonic-gate 
7360Sstevel@tonic-gate /*
7370Sstevel@tonic-gate  * usb_free_dev_data:
7380Sstevel@tonic-gate  * undoes what usb_get_dev_data() set up.  It releases
7390Sstevel@tonic-gate  * memory for all strings, descriptors, and trees set up by usb_get_dev_data().
7400Sstevel@tonic-gate  *
7410Sstevel@tonic-gate  * Arguments:
7420Sstevel@tonic-gate  *	dip		- pointer to devinfo node of the client
7430Sstevel@tonic-gate  *	dev_data	- pointer to registration data containing the tree.
7440Sstevel@tonic-gate  */
7450Sstevel@tonic-gate void usb_free_dev_data(
7460Sstevel@tonic-gate 	dev_info_t			*dip,
7470Sstevel@tonic-gate 	usb_client_dev_data_t		*dev_data);
7480Sstevel@tonic-gate 
7490Sstevel@tonic-gate /*
7500Sstevel@tonic-gate  * usb_free_descr_tree:
7510Sstevel@tonic-gate  *	Take down the configuration tree while leaving the rest	of the
7520Sstevel@tonic-gate  *	registration intact.  This can be used, for example, after attach has
7530Sstevel@tonic-gate  *	copied any descriptors it needs from the tree, but the rest of the
7540Sstevel@tonic-gate  *	registration data needs to remain intact.
7550Sstevel@tonic-gate  *
7560Sstevel@tonic-gate  *	The following usb_client_dev_data_t fields will be modified:
7570Sstevel@tonic-gate  *		dev_cfg will be NULL
7580Sstevel@tonic-gate  *		dev_n_cfg will be 0
7590Sstevel@tonic-gate  *		dev_curr_cfg_ndx and dev_curr_if will be invalid
7600Sstevel@tonic-gate  *		dev_parse_level will be USB_REG_DESCR_NONE
7610Sstevel@tonic-gate  *
7620Sstevel@tonic-gate  * Arguments:
7630Sstevel@tonic-gate  *	dip		- pointer to devinfo node of the client
7640Sstevel@tonic-gate  *	dev_data	- pointer to registration data containing the tree.
7650Sstevel@tonic-gate  */
7660Sstevel@tonic-gate void usb_free_descr_tree(
7670Sstevel@tonic-gate 	dev_info_t			*dip,
7680Sstevel@tonic-gate 	usb_client_dev_data_t		*dev_data);
7690Sstevel@tonic-gate 
7700Sstevel@tonic-gate 
7710Sstevel@tonic-gate /*
7720Sstevel@tonic-gate  * usb_print_descr_tree:
7730Sstevel@tonic-gate  *	Dump to the screen a descriptor tree as returned by
7740Sstevel@tonic-gate  *	usbai_register_client.
7750Sstevel@tonic-gate  *
7760Sstevel@tonic-gate  * Arguments:
7770Sstevel@tonic-gate  *	dip		- pointer to devinfo of the client
7780Sstevel@tonic-gate  *	dev_data	- pointer to registration area containing the tree
7790Sstevel@tonic-gate  *
7800Sstevel@tonic-gate  * Returns:
7810Sstevel@tonic-gate  *	USB_SUCCESS		- tree successfully dumped
7820Sstevel@tonic-gate  *	USB_INVALID_CONTEXT	- called from callback context
7830Sstevel@tonic-gate  *	USB_INVALID_ARGS	- bad arguments given
7840Sstevel@tonic-gate  */
7850Sstevel@tonic-gate int usb_print_descr_tree(
7860Sstevel@tonic-gate 	dev_info_t		*dip,
7870Sstevel@tonic-gate 	usb_client_dev_data_t	*dev_data);
7880Sstevel@tonic-gate 
7890Sstevel@tonic-gate 
7900Sstevel@tonic-gate /*
7910Sstevel@tonic-gate  * ***************************************************************************
7920Sstevel@tonic-gate  * Registration and versioning
7930Sstevel@tonic-gate  * ***************************************************************************
7940Sstevel@tonic-gate  */
7950Sstevel@tonic-gate 
7960Sstevel@tonic-gate 
7970Sstevel@tonic-gate /*
7980Sstevel@tonic-gate  * USBA client drivers are required to define USBDRV_MAJOR_VER
7990Sstevel@tonic-gate  * USBDRV_MINOR_VER and pass USBDRV_VERSION as the version
8000Sstevel@tonic-gate  * number to usb_client_attach
8010Sstevel@tonic-gate  */
8020Sstevel@tonic-gate #if !defined(USBA_MAJOR_VER) || !defined(USBA_MINOR_VER)
8030Sstevel@tonic-gate #error incorrect USBA header
8040Sstevel@tonic-gate #endif
8050Sstevel@tonic-gate 
8060Sstevel@tonic-gate /*
8070Sstevel@tonic-gate  * Driver major version must be the same as USBA major version, and
8080Sstevel@tonic-gate  * driver minor version must be <= USBA minor version
8090Sstevel@tonic-gate  */
8100Sstevel@tonic-gate #if !defined(USBA_FRAMEWORK)
8110Sstevel@tonic-gate #if defined(USBDRV_MAJOR_VER) && defined(USBDRV_MINOR_VER)
8120Sstevel@tonic-gate 
8130Sstevel@tonic-gate #if (USBDRV_MAJOR_VER != USBA_MAJOR_VER)
8140Sstevel@tonic-gate #error USBA and driver major versions do not match
8150Sstevel@tonic-gate #endif
8160Sstevel@tonic-gate #if (USBDRV_MINOR_VER > USBA_MINOR_VER)
8170Sstevel@tonic-gate #error USBA and driver minor versions do not match
8180Sstevel@tonic-gate #endif
8190Sstevel@tonic-gate 
8200Sstevel@tonic-gate #endif
8210Sstevel@tonic-gate #endif
8220Sstevel@tonic-gate 
8230Sstevel@tonic-gate #define	USBA_MAKE_VER(major, minor) ((major) << 8 | (minor))
8240Sstevel@tonic-gate #define	USBA_GET_MAJOR(ver) ((ver) >> 8)
8250Sstevel@tonic-gate #define	USBA_GET_MINOR(ver) ((ver) & 0xff)
8260Sstevel@tonic-gate 
8270Sstevel@tonic-gate #define	USBDRV_VERSION	USBA_MAKE_VER(USBDRV_MAJOR_VER, USBDRV_MINOR_VER)
8280Sstevel@tonic-gate 
8290Sstevel@tonic-gate 
8300Sstevel@tonic-gate /*
8310Sstevel@tonic-gate  * usb_client_attach:
8320Sstevel@tonic-gate  *
8330Sstevel@tonic-gate  * Arguments:
8340Sstevel@tonic-gate  *	dip		- pointer to devinfo node of the client
8350Sstevel@tonic-gate  *	version 	- USBA registration version number
8360Sstevel@tonic-gate  *	flags		- None used
8370Sstevel@tonic-gate  *
8380Sstevel@tonic-gate  * Return Values:
8390Sstevel@tonic-gate  *	USB_SUCCESS		- attach succeeded
8400Sstevel@tonic-gate  *	USB_INVALID_ARGS	- received null dip or reg argument
8410Sstevel@tonic-gate  *	USB_INVALID_CONTEXT	- called with sleep from callback context
8420Sstevel@tonic-gate  *				  or not at attach time
8430Sstevel@tonic-gate  *	USB_INVALID_VERSION	- version argument is incorrect.
8440Sstevel@tonic-gate  *	USB_FAILURE		- other internal failure
8450Sstevel@tonic-gate  */
8460Sstevel@tonic-gate int usb_client_attach(
8470Sstevel@tonic-gate 	dev_info_t			*dip,
8480Sstevel@tonic-gate 	uint_t				version,
8490Sstevel@tonic-gate 	usb_flags_t			flags);
8500Sstevel@tonic-gate 
8510Sstevel@tonic-gate /*
8520Sstevel@tonic-gate  * usb_client_detach:
8530Sstevel@tonic-gate  *
8540Sstevel@tonic-gate  * Arguments:
8550Sstevel@tonic-gate  *	dip		- pointer to devinfo node of the client
8560Sstevel@tonic-gate  *	dev_data	- pointer to data to free. may be NULL
8570Sstevel@tonic-gate  */
8580Sstevel@tonic-gate void usb_client_detach(
8590Sstevel@tonic-gate 	dev_info_t			*dip,
8600Sstevel@tonic-gate 	struct usb_client_dev_data	*dev_data);
8610Sstevel@tonic-gate 
8620Sstevel@tonic-gate /*
8630Sstevel@tonic-gate  * ***************************************************************************
8640Sstevel@tonic-gate  * Functions for parsing / retrieving data from the descriptor tree
8650Sstevel@tonic-gate  * ***************************************************************************
8660Sstevel@tonic-gate  */
8670Sstevel@tonic-gate 
8680Sstevel@tonic-gate /*
8690Sstevel@tonic-gate  * Function for unpacking any kind of little endian data, usually desriptors
8700Sstevel@tonic-gate  *
8710Sstevel@tonic-gate  * Arguments:
8720Sstevel@tonic-gate  *	format		- string indicating the format in c, s, w, eg. "2c4ws"
8730Sstevel@tonic-gate  *			  which describes 2 bytes, 4 int, one short.
8740Sstevel@tonic-gate  *			  The number prefix parses the number of items of
8750Sstevel@tonic-gate  *			  the following type.
8760Sstevel@tonic-gate  *	data		- pointer to the LE data buffer
8770Sstevel@tonic-gate  *	datalen		- length of the data
8780Sstevel@tonic-gate  *	structure	- pointer to return structure where the unpacked data
8790Sstevel@tonic-gate  *			  will be written
8800Sstevel@tonic-gate  *	structlen	- length of the return structure
8810Sstevel@tonic-gate  *
8820Sstevel@tonic-gate  * return value:
8830Sstevel@tonic-gate  *	total number of bytes of the original data that was unpacked
8840Sstevel@tonic-gate  *	or USB_PARSE_ERROR
8850Sstevel@tonic-gate  */
8860Sstevel@tonic-gate #define	USB_PARSE_ERROR	0
8870Sstevel@tonic-gate 
8880Sstevel@tonic-gate size_t usb_parse_data(
8890Sstevel@tonic-gate 	char			*format,
8900Sstevel@tonic-gate 	uchar_t 		*data,
8910Sstevel@tonic-gate 	size_t			datalen,
8920Sstevel@tonic-gate 	void			*structure,
8930Sstevel@tonic-gate 	size_t			structlen);
8940Sstevel@tonic-gate 
8950Sstevel@tonic-gate /*
8960Sstevel@tonic-gate  * usb_lookup_ep_data:
8970Sstevel@tonic-gate  *	Function to get specific endpoint data
8980Sstevel@tonic-gate  *	This function will not access the device.
8990Sstevel@tonic-gate  *
9000Sstevel@tonic-gate  * Arguments:
9010Sstevel@tonic-gate  *	dip		- pointer to dev info
9020Sstevel@tonic-gate  *	dev_datap	- pointer to registration data
9030Sstevel@tonic-gate  *	interface	- requested interface
9040Sstevel@tonic-gate  *	alternate	- requested alternate
9050Sstevel@tonic-gate  *	skip		- number of endpoints which match the requested type and
9060Sstevel@tonic-gate  *			  direction to skip before finding one to retrieve
9070Sstevel@tonic-gate  *	type		- endpoint type
9080Sstevel@tonic-gate  *	direction	- endpoint direction: USB_EP_DIR_IN/OUT or none
9090Sstevel@tonic-gate  *
9100Sstevel@tonic-gate  * Return Values:
9110Sstevel@tonic-gate  *	NULL or an endpoint data pointer
9120Sstevel@tonic-gate  */
9130Sstevel@tonic-gate usb_ep_data_t *usb_lookup_ep_data(
9140Sstevel@tonic-gate 	dev_info_t		*dip,
9150Sstevel@tonic-gate 	usb_client_dev_data_t	*dev_datap,
9160Sstevel@tonic-gate 	uint_t			interface,
9170Sstevel@tonic-gate 	uint_t			alternate,
9180Sstevel@tonic-gate 	uint_t			skip,
9190Sstevel@tonic-gate 	uint_t			type,
9200Sstevel@tonic-gate 	uint_t			direction);
9210Sstevel@tonic-gate 
9220Sstevel@tonic-gate 
9230Sstevel@tonic-gate /* Language ID for string descriptors. */
9240Sstevel@tonic-gate #define	USB_LANG_ID		0x0409		/* English, US */
9250Sstevel@tonic-gate 
9260Sstevel@tonic-gate /*
9270Sstevel@tonic-gate  * usb_get_string_descr:
9280Sstevel@tonic-gate  *	Reads the string descriptor.  This function access the device and
9290Sstevel@tonic-gate  *	blocks.
9300Sstevel@tonic-gate  *
9310Sstevel@tonic-gate  * Arguments:
9320Sstevel@tonic-gate  *	dip		- pointer to devinfo of the client.
9330Sstevel@tonic-gate  *	langid		- LANGID to read different LOCALEs.
9340Sstevel@tonic-gate  *	index		- index to the string.
9350Sstevel@tonic-gate  *	buf		- user provided buffer for string descriptor.
9360Sstevel@tonic-gate  *	buflen		- user provided length of the buffer.
9370Sstevel@tonic-gate  *
9380Sstevel@tonic-gate  * Return Values:
9390Sstevel@tonic-gate  *	USB_SUCCESS	- descriptor is valid.
9400Sstevel@tonic-gate  *	USB_FAILURE	- full descriptor could not be retrieved.
9410Sstevel@tonic-gate  */
9420Sstevel@tonic-gate int usb_get_string_descr(
9430Sstevel@tonic-gate 	dev_info_t		*dip,
9440Sstevel@tonic-gate 	uint16_t		langid,
9450Sstevel@tonic-gate 	uint8_t			index,
9460Sstevel@tonic-gate 	char			*buf,
9470Sstevel@tonic-gate 	size_t			buflen);
9480Sstevel@tonic-gate 
9490Sstevel@tonic-gate 
9500Sstevel@tonic-gate /*
9510Sstevel@tonic-gate  * ***************************************************************************
9520Sstevel@tonic-gate  * Addressing utility functions
9530Sstevel@tonic-gate  * ***************************************************************************
9540Sstevel@tonic-gate  */
9550Sstevel@tonic-gate 
9560Sstevel@tonic-gate /*
9570Sstevel@tonic-gate  * usb_get_addr returns the current usb address, mostly for debugging
9580Sstevel@tonic-gate  * purposes. The address may change after hotremove/insert.
9590Sstevel@tonic-gate  * This address will not change on a disconnect/reconnect of open device.
9600Sstevel@tonic-gate  */
9610Sstevel@tonic-gate int usb_get_addr(dev_info_t *dip);
9620Sstevel@tonic-gate 
9630Sstevel@tonic-gate 
9640Sstevel@tonic-gate /*
9650Sstevel@tonic-gate  * usb_get_if_number returns USB_COMBINED_NODE or USB_DEVICE_NODE
9660Sstevel@tonic-gate  * if the driver is responsible for the entire device.
9670Sstevel@tonic-gate  * Otherwise it returns the interface number.
9680Sstevel@tonic-gate  */
9690Sstevel@tonic-gate #define	USB_COMBINED_NODE	-1
9700Sstevel@tonic-gate #define	USB_DEVICE_NODE		-2
9710Sstevel@tonic-gate 
9720Sstevel@tonic-gate int usb_get_if_number(
9730Sstevel@tonic-gate 	dev_info_t		*dip);
9740Sstevel@tonic-gate 
9750Sstevel@tonic-gate boolean_t usb_owns_device(
9760Sstevel@tonic-gate 	dev_info_t		*dip);
9770Sstevel@tonic-gate 
9780Sstevel@tonic-gate 
9790Sstevel@tonic-gate /*
9800Sstevel@tonic-gate  * ***************************************************************************
9810Sstevel@tonic-gate  * Pipe	Management definitions and functions
9820Sstevel@tonic-gate  * ***************************************************************************
9830Sstevel@tonic-gate  */
9840Sstevel@tonic-gate 
9850Sstevel@tonic-gate 
9860Sstevel@tonic-gate /*
9870Sstevel@tonic-gate  *
9880Sstevel@tonic-gate  * usb_pipe_state:
9890Sstevel@tonic-gate  *
9900Sstevel@tonic-gate  * PIPE_STATE_IDLE:
9910Sstevel@tonic-gate  *	The pipe's policy is set, but the pipe currently isn't transferring
9920Sstevel@tonic-gate  *	data.
9930Sstevel@tonic-gate  *
9940Sstevel@tonic-gate  * PIPE_STATE_ACTIVE:
9950Sstevel@tonic-gate  *	The pipe's policy has been set, and the pipe is able to transmit data.
9960Sstevel@tonic-gate  *	When a control or bulk pipe is opened, the pipe's state is
9970Sstevel@tonic-gate  *	automatically set to PIPE_STATE_ACTIVE.  For an interrupt or
9980Sstevel@tonic-gate  *	isochronous pipe, the pipe state becomes PIPE_STATE_ACTIVE once
9990Sstevel@tonic-gate  *	the polling on the pipe has been initiated.
10000Sstevel@tonic-gate  *
10010Sstevel@tonic-gate  * PIPE_STATE_ERROR:
10020Sstevel@tonic-gate  *	The device has generated a error on the pipe.  The client driver
10030Sstevel@tonic-gate  *	must call usb_pipe_reset() to clear any leftover state that's associated
10040Sstevel@tonic-gate  *	with the pipe, clear the data toggle, and reset the state of the pipe.
10050Sstevel@tonic-gate  *
10060Sstevel@tonic-gate  *	Calling usb_pipe_reset() on a control or bulk pipe resets the state to
10070Sstevel@tonic-gate  *	PIPE_STATE_ACTIVE.  Calling usb_pipe_reset() on an interrupt or
10080Sstevel@tonic-gate  *	isochronous pipe, resets the state to PIPE_STATE_IDLE.
10090Sstevel@tonic-gate  *
10100Sstevel@tonic-gate  * State Diagram for Bulk/Control
10110Sstevel@tonic-gate  *
10120Sstevel@tonic-gate  *			+-<--normal completion------------------<-------^
10130Sstevel@tonic-gate  *			|						|
10140Sstevel@tonic-gate  *			V						|
10150Sstevel@tonic-gate  * usb_pipe_open-->[PIPE_STATE_IDLE]-usb_pipe_*_xfer->[PIPE_STATE_ACTIVE]
10160Sstevel@tonic-gate  *			^						|
10170Sstevel@tonic-gate  *			|						v
10180Sstevel@tonic-gate  *			- usb_pipe_reset<-[PIPE_STATE_ERROR]<-device error
10190Sstevel@tonic-gate  *
10200Sstevel@tonic-gate  * State Diagram for Interrupt/Isochronous IN
10210Sstevel@tonic-gate  *
10220Sstevel@tonic-gate  *			+-<--usb_pipe_stop_isoc/intr_polling----<-------^
10230Sstevel@tonic-gate  *			|						|
10240Sstevel@tonic-gate  *			V						|
10250Sstevel@tonic-gate  * usb_pipe_open-->[PIPE_STATE_IDLE]-usb_pipe_*_xfer->[PIPE_STATE_ACTIVE]
10260Sstevel@tonic-gate  *			^						|
10270Sstevel@tonic-gate  *			|						v
10280Sstevel@tonic-gate  *			+ usb_pipe_reset<-[PIPE_STATE_ERROR]<-device error
10290Sstevel@tonic-gate  *
10300Sstevel@tonic-gate  * State Diagram for Interrupt/Isochronous OUT
10310Sstevel@tonic-gate  *
10320Sstevel@tonic-gate  *			+-<--normal completion------------------<-------^
10330Sstevel@tonic-gate  *			|						|
10340Sstevel@tonic-gate  *			V						|
10350Sstevel@tonic-gate  * usb_pipe_open-->[PIPE_STATE_IDLE]-usb_pipe_*_xfer->[PIPE_STATE_ACTIVE]
10360Sstevel@tonic-gate  *			^						|
10370Sstevel@tonic-gate  *			|						v
10380Sstevel@tonic-gate  *			+ usb_pipe_reset<-[PIPE_STATE_ERROR]<-device error
10390Sstevel@tonic-gate  *
10400Sstevel@tonic-gate  *
10410Sstevel@tonic-gate  * The following table indicates which operations are allowed with each
10420Sstevel@tonic-gate  * pipe state:
10430Sstevel@tonic-gate  *
10440Sstevel@tonic-gate  * -------------------------------------------------------------------------+
10450Sstevel@tonic-gate  * ctrl/bulk	| idle	| active     | error  | sync closing | async closing|
10460Sstevel@tonic-gate  * -------------------------------------------------------------------------+
10470Sstevel@tonic-gate  * pipe xfer	|  OK	|queue (USBA)| reject | reject	     | reject	    |
10480Sstevel@tonic-gate  * pipe reset	| no-op | OK	     |	OK    | reject	     | reject	    |
10490Sstevel@tonic-gate  * pipe close	|  OK	| wait&close |	OK    | no-op	     | no-op	    |
10500Sstevel@tonic-gate  * -------------------------------------------------------------------------+
10510Sstevel@tonic-gate  *
10520Sstevel@tonic-gate  * -------------------------------------------------------------------------+
10530Sstevel@tonic-gate  * intr/isoc IN | idle	| active     | error  | sync closing | async closing|
10540Sstevel@tonic-gate  * -------------------------------------------------------------------------+
10550Sstevel@tonic-gate  * pipe xfer	|  OK	| reject     | reject | reject	     | reject	    |
10560Sstevel@tonic-gate  * pipe stoppoll| no-op | OK	     | no-op  | reject	     | reject	    |
10570Sstevel@tonic-gate  * pipe reset	| no-op | OK	     |	OK    | reject	     | reject	    |
10580Sstevel@tonic-gate  * pipe close	|  OK	| wait&close |	OK    | no-op	     | no-op	    |
10590Sstevel@tonic-gate  * -------------------------------------------------------------------------+
10600Sstevel@tonic-gate  *
10610Sstevel@tonic-gate  * -------------------------------------------------------------------------+
10620Sstevel@tonic-gate  * intr/isoc OUT| idle	| active     | error  | sync closing | async closing|
10630Sstevel@tonic-gate  * -------------------------------------------------------------------------+
10640Sstevel@tonic-gate  * pipe xfer	|  OK	|queue (HCD) | reject | reject	     | reject	    |
10650Sstevel@tonic-gate  * pipe stoppoll| reject| reject     | reject | reject	     | reject	    |
10660Sstevel@tonic-gate  * pipe reset	| no-op | OK	     |	OK    | reject	     | reject	    |
10670Sstevel@tonic-gate  * pipe close	|  OK	| wait&close |	OK    | no-op	     | no-op	    |
10680Sstevel@tonic-gate  * -------------------------------------------------------------------------+
10690Sstevel@tonic-gate  */
10700Sstevel@tonic-gate typedef enum {
10710Sstevel@tonic-gate 	USB_PIPE_STATE_CLOSED		= 0,
10720Sstevel@tonic-gate 	USB_PIPE_STATE_IDLE		= 1,
10730Sstevel@tonic-gate 	USB_PIPE_STATE_ACTIVE		= 2,
10740Sstevel@tonic-gate 	USB_PIPE_STATE_ERROR		= 3,
10750Sstevel@tonic-gate 	USB_PIPE_STATE_CLOSING		= 4
10760Sstevel@tonic-gate } usb_pipe_state_t;
10770Sstevel@tonic-gate 
10780Sstevel@tonic-gate 
10790Sstevel@tonic-gate /*
10800Sstevel@tonic-gate  * pipe state control:
10810Sstevel@tonic-gate  *
10820Sstevel@tonic-gate  * return values:
10830Sstevel@tonic-gate  *	USB_SUCCESS	 - success
10840Sstevel@tonic-gate  *	USB_FAILURE	 - unspecified failure
10850Sstevel@tonic-gate  */
10860Sstevel@tonic-gate int usb_pipe_get_state(
10870Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
10880Sstevel@tonic-gate 	usb_pipe_state_t	*pipe_state,
10890Sstevel@tonic-gate 	usb_flags_t		flags);
10900Sstevel@tonic-gate 
10910Sstevel@tonic-gate 
10920Sstevel@tonic-gate /*
10930Sstevel@tonic-gate  * usb_pipe_policy
10940Sstevel@tonic-gate  *
10950Sstevel@tonic-gate  *	Pipe policy specifies how a pipe to an endpoint	should be used
10960Sstevel@tonic-gate  *	by the client driver and the HCD.
10970Sstevel@tonic-gate  */
10980Sstevel@tonic-gate typedef struct usb_pipe_policy {
10990Sstevel@tonic-gate 	/*
11000Sstevel@tonic-gate 	 * This is a hint indicating how many asynchronous operations
11010Sstevel@tonic-gate 	 * requiring a kernel thread will be concurrently active.
11020Sstevel@tonic-gate 	 * Allow at least one for synch exception callback handling
11030Sstevel@tonic-gate 	 * and another for asynchronous closing of pipes.
11040Sstevel@tonic-gate 	 */
11050Sstevel@tonic-gate 	uchar_t		pp_max_async_reqs;
11060Sstevel@tonic-gate } usb_pipe_policy_t;
11070Sstevel@tonic-gate 
11080Sstevel@tonic-gate 
11090Sstevel@tonic-gate /*
11100Sstevel@tonic-gate  * usb_pipe_open():
11110Sstevel@tonic-gate  *
11120Sstevel@tonic-gate  * Before using any pipe including the default pipe, it must be opened.
11130Sstevel@tonic-gate  * On success, a pipe handle is returned for use in other usb_pipe_*()
11140Sstevel@tonic-gate  * functions.
11150Sstevel@tonic-gate  *
11160Sstevel@tonic-gate  * The default pipe can only be opened by the hub driver.
11170Sstevel@tonic-gate  *
11180Sstevel@tonic-gate  * For isochronous and interrupt pipes, bandwidth has been allocated and
11190Sstevel@tonic-gate  * guaranteed.
11200Sstevel@tonic-gate  *
11210Sstevel@tonic-gate  * Only the default pipe can be shared.  All other control pipes are
11220Sstevel@tonic-gate  * excusively opened by default.  A pipe policy and endpoint descriptor
11230Sstevel@tonic-gate  * must always be provided except for default pipe.
11240Sstevel@tonic-gate  *
11250Sstevel@tonic-gate  * Arguments:
11260Sstevel@tonic-gate  *	dip		- devinfo ptr.
11270Sstevel@tonic-gate  *	ep		- endpoint descriptor pointer.
11280Sstevel@tonic-gate  *	pipe_policy	- pointer to pipe policy which provides hints on how
11290Sstevel@tonic-gate  *			  the pipe will be used.
11300Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP wait for resources to become
11310Sstevel@tonic-gate  *			  available.
11320Sstevel@tonic-gate  *	pipe_handle	- a pipe handle pointer.  on a successful open,
11330Sstevel@tonic-gate  *			  a pipe_handle is returned in this pointer.
11340Sstevel@tonic-gate  *
11350Sstevel@tonic-gate  * Return values:
11360Sstevel@tonic-gate  *	USB_SUCCESS	 - open succeeded.
11370Sstevel@tonic-gate  *	USB_FAILURE	 - unspecified open failure or pipe is already open.
11380Sstevel@tonic-gate  *	USB_NO_RESOURCES - no resources were available to complete the open.
11390Sstevel@tonic-gate  *	USB_NO_BANDWIDTH - no bandwidth available (isoc/intr pipes).
11400Sstevel@tonic-gate  *	USB_*		 - refer to list of all possible return values in
11410Sstevel@tonic-gate  *			   this file
11420Sstevel@tonic-gate  */
11430Sstevel@tonic-gate int usb_pipe_open(
11440Sstevel@tonic-gate 	dev_info_t		*dip,
11450Sstevel@tonic-gate 	usb_ep_descr_t		*ep,
11460Sstevel@tonic-gate 	usb_pipe_policy_t	*pipe_policy,
11470Sstevel@tonic-gate 	usb_flags_t		flags,
11480Sstevel@tonic-gate 	usb_pipe_handle_t	*pipe_handle);
11490Sstevel@tonic-gate 
11500Sstevel@tonic-gate 
11510Sstevel@tonic-gate /*
11520Sstevel@tonic-gate  * usb_pipe_close():
11530Sstevel@tonic-gate  *
11540Sstevel@tonic-gate  * Closes the pipe, releases resources and frees the pipe_handle.
11550Sstevel@tonic-gate  * Automatic polling, if active,  will be terminated.
11560Sstevel@tonic-gate  *
11570Sstevel@tonic-gate  * Arguments:
11580Sstevel@tonic-gate  *	dip		- devinfo ptr.
11590Sstevel@tonic-gate  *	pipe_handle	- pipe handle.
11600Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
11610Sstevel@tonic-gate  *				wait for resources, pipe
11620Sstevel@tonic-gate  *				to become free, and all callbacks completed.
11630Sstevel@tonic-gate  *	cb		- If USB_FLAGS_SLEEP has not been specified, a
11640Sstevel@tonic-gate  *			  callback will be performed.
11650Sstevel@tonic-gate  *	cb_arg		- the 2nd argument of the callback. Note that the
11660Sstevel@tonic-gate  *			  pipehandle will be zeroed and therefore not passed.
11670Sstevel@tonic-gate  *
11680Sstevel@tonic-gate  * Notes:
11690Sstevel@tonic-gate  *
11700Sstevel@tonic-gate  * Pipe close always succeeds regardless whether USB_FLAGS_SLEEP has been
11710Sstevel@tonic-gate  * specified or not.  An async close will always succeed if the hint in the
11720Sstevel@tonic-gate  * pipe policy has been correct about the max number of async requests
11730Sstevel@tonic-gate  * required.
11740Sstevel@tonic-gate  * In the unlikely event that no async requests can be queued, this
11750Sstevel@tonic-gate  * function will continue retrying before returning
11760Sstevel@tonic-gate  *
11770Sstevel@tonic-gate  * USBA prevents the client from submitting subsequent requests to a pipe
11780Sstevel@tonic-gate  * that is being closed.
11790Sstevel@tonic-gate  * Additional usb_pipe_close() requests on the same pipe causes USBA to
11800Sstevel@tonic-gate  * wait for the previous close(s) to complete.
11810Sstevel@tonic-gate  *
11820Sstevel@tonic-gate  * The pipe will not be destroyed until all activity on the pipe has
11830Sstevel@tonic-gate  * been drained, including outstanding request callbacks, async requests,
11840Sstevel@tonic-gate  * and other usb_pipe_*() calls.
11850Sstevel@tonic-gate  *
11860Sstevel@tonic-gate  * Calling usb_pipe_close() from a deferred callback (in kernel context)
11870Sstevel@tonic-gate  * with USB_FLAGS_SLEEP set, will cause deadlock
11880Sstevel@tonic-gate  */
11890Sstevel@tonic-gate void usb_pipe_close(
11900Sstevel@tonic-gate 	dev_info_t		*dip,
11910Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
11920Sstevel@tonic-gate 	usb_flags_t		flags,
11930Sstevel@tonic-gate 	void			(*cb)(
11940Sstevel@tonic-gate 				    usb_pipe_handle_t	ph,
11950Sstevel@tonic-gate 				    usb_opaque_t	arg,	/* cb arg */
11960Sstevel@tonic-gate 				    int			rval,
11970Sstevel@tonic-gate 				    usb_cb_flags_t	flags),
11980Sstevel@tonic-gate 	usb_opaque_t		cb_arg);
11990Sstevel@tonic-gate 
12000Sstevel@tonic-gate 
12010Sstevel@tonic-gate /*
12020Sstevel@tonic-gate  * usb_pipe_drain_reqs
12030Sstevel@tonic-gate  *	this function blocks until there are no more requests
12040Sstevel@tonic-gate  *	owned by this dip on the pipe
12050Sstevel@tonic-gate  *
12060Sstevel@tonic-gate  * Arguments:
12070Sstevel@tonic-gate  *	dip		- devinfo pointer
12080Sstevel@tonic-gate  *	pipe_handle	- opaque pipe handle
12090Sstevel@tonic-gate  *	timeout 	- timeout in seconds
12100Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
12110Sstevel@tonic-gate  *				wait for completion.
12120Sstevel@tonic-gate  *	cb		- if USB_FLAGS_SLEEP has not been specified
12130Sstevel@tonic-gate  *			  this callback function will be called on
12140Sstevel@tonic-gate  *			  completion. This callback may be NULL
12150Sstevel@tonic-gate  *			  and no notification of completion will then
12160Sstevel@tonic-gate  *			  be provided.
12170Sstevel@tonic-gate  *	cb_arg		- 2nd argument to callback function.
12180Sstevel@tonic-gate  *
12190Sstevel@tonic-gate  * callback and callback_arg should be NULL if USB_FLAGS_SLEEP has
12200Sstevel@tonic-gate  * been specified
12210Sstevel@tonic-gate  *
12220Sstevel@tonic-gate  * Returns:
12230Sstevel@tonic-gate  *	USB_SUCCESS	- pipe successfully reset or request queued
12240Sstevel@tonic-gate  *	USB_FAILURE	- timeout
12250Sstevel@tonic-gate  *	USB_INVALID_PIPE - pipe is invalid or already closed
12260Sstevel@tonic-gate  *	USB_INVALID_CONTEXT - called from interrupt context
12270Sstevel@tonic-gate  *	USB_INVALID_ARGS - invalid arguments
12280Sstevel@tonic-gate  *	USB_*		- refer to return values defines in this file
12290Sstevel@tonic-gate  */
12300Sstevel@tonic-gate int usb_pipe_drain_reqs(
12310Sstevel@tonic-gate 	dev_info_t		*dip,
12320Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
12330Sstevel@tonic-gate 	uint_t			time,
12340Sstevel@tonic-gate 	usb_flags_t		flags,
12350Sstevel@tonic-gate 	void			(*cb)(
12360Sstevel@tonic-gate 				    usb_pipe_handle_t	ph,
12370Sstevel@tonic-gate 				    usb_opaque_t	arg,	/* cb arg */
12380Sstevel@tonic-gate 				    int			rval,
12390Sstevel@tonic-gate 				    usb_cb_flags_t	flags),
12400Sstevel@tonic-gate 	usb_opaque_t		cb_arg);
12410Sstevel@tonic-gate 
12420Sstevel@tonic-gate 
12430Sstevel@tonic-gate /*
12440Sstevel@tonic-gate  * Resetting a pipe: Refer to USB 2.0/10.5.2.2
12450Sstevel@tonic-gate  *	The pipe's requests are retired and the pipe is cleared.  The host state
12460Sstevel@tonic-gate  *	is moved to active. If the reflected endpoint state needs to be changed,
12470Sstevel@tonic-gate  *	that must be explicitly requested by the client driver.  The reset
12480Sstevel@tonic-gate  *	completes after all request callbacks have been completed.
12490Sstevel@tonic-gate  *
12500Sstevel@tonic-gate  * Arguments:
12510Sstevel@tonic-gate  *	dip		- devinfo pointer.
12520Sstevel@tonic-gate  *	pipe_handle	- pipe handle.
12530Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
12540Sstevel@tonic-gate  *				wait for completion.
12550Sstevel@tonic-gate  *	cb		- if USB_FLAGS_SLEEP has not been specified
12560Sstevel@tonic-gate  *			  this callback function will be called on
12570Sstevel@tonic-gate  *			  completion. This callback may be NULL
12580Sstevel@tonic-gate  *			  and no notification of completion will then
12590Sstevel@tonic-gate  *			  be provided.
12600Sstevel@tonic-gate  *	cb_arg		- 2nd argument to callback function.
12610Sstevel@tonic-gate  *
12620Sstevel@tonic-gate  * callback and callback_arg should be NULL if USB_FLAGS_SLEEP has
12630Sstevel@tonic-gate  * been specified
12640Sstevel@tonic-gate  *
12650Sstevel@tonic-gate  * Note: Completion notification may be *before* all async request threads
12660Sstevel@tonic-gate  *	have completed but *after* all immediate callbacks have completed.
12670Sstevel@tonic-gate  */
12680Sstevel@tonic-gate void usb_pipe_reset(
12690Sstevel@tonic-gate 	dev_info_t		*dip,
12700Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
12710Sstevel@tonic-gate 	usb_flags_t		usb_flags,
12720Sstevel@tonic-gate 	void			(*cb)(
12730Sstevel@tonic-gate 					usb_pipe_handle_t ph,
12740Sstevel@tonic-gate 					usb_opaque_t	arg,
12750Sstevel@tonic-gate 					int		rval,
12760Sstevel@tonic-gate 					usb_cb_flags_t	flags),
12770Sstevel@tonic-gate 	usb_opaque_t		cb_arg);
12780Sstevel@tonic-gate 
12790Sstevel@tonic-gate 
12800Sstevel@tonic-gate /*
12810Sstevel@tonic-gate  * The client driver can store a private data pointer in the
12820Sstevel@tonic-gate  * pipe_handle.
12830Sstevel@tonic-gate  *
12840Sstevel@tonic-gate  * return values:
12850Sstevel@tonic-gate  *	USB_SUCCESS	 - success
12860Sstevel@tonic-gate  *	USB_FAILURE	 - unspecified failure
12870Sstevel@tonic-gate  */
12880Sstevel@tonic-gate int usb_pipe_set_private(
12890Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
12900Sstevel@tonic-gate 	usb_opaque_t		data);
12910Sstevel@tonic-gate 
12920Sstevel@tonic-gate 
12930Sstevel@tonic-gate usb_opaque_t usb_pipe_get_private(
12940Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle);
12950Sstevel@tonic-gate 
12960Sstevel@tonic-gate 
12970Sstevel@tonic-gate /*
12980Sstevel@tonic-gate  * ***************************************************************************
12990Sstevel@tonic-gate  * Transfer request definitions and functions
13000Sstevel@tonic-gate  * ***************************************************************************
13010Sstevel@tonic-gate  */
13020Sstevel@tonic-gate 
13030Sstevel@tonic-gate 
13040Sstevel@tonic-gate /*
13050Sstevel@tonic-gate  * USB xfer request attributes.
13060Sstevel@tonic-gate  * Set by the client driver, more than one may be set
13070Sstevel@tonic-gate  *
13080Sstevel@tonic-gate  * SHORT_XFER_OK if less data is transferred than specified, no error is
13090Sstevel@tonic-gate  *		returned.
13100Sstevel@tonic-gate  * AUTOCLEARING	if there is an exception, the pipe will be reset first
13110Sstevel@tonic-gate  *		and a functional stall cleared before a callback is done.
13120Sstevel@tonic-gate  * PIPE_RESET	if there is an exception, the pipe will be reset only
13130Sstevel@tonic-gate  * ONE_XFER	polling will automatically stop on the first callback.
13140Sstevel@tonic-gate  * ISOC_START_FRAME use startframe specified.
13150Sstevel@tonic-gate  * USB_ATTRS_ISOC_XFER_ASAP let the host controller decide on the first
13160Sstevel@tonic-gate  *		available frame.
13170Sstevel@tonic-gate  *
13180Sstevel@tonic-gate  * USB_ATTRS_ISOC_START_FRAME and USB_ATTRS_ISOC_XFER_ASAP are mutually
13190Sstevel@tonic-gate  * exclusive
13200Sstevel@tonic-gate  *
13210Sstevel@tonic-gate  * combinations of flag and attributes:
13220Sstevel@tonic-gate  *
13230Sstevel@tonic-gate  * usb_flags	usb_req_attrs			semantics
13240Sstevel@tonic-gate  * ---------------------------------------------------------
13250Sstevel@tonic-gate  * SLEEP	USB_ATTRS_SHORT_XFER_OK		legal for IN pipes
13260Sstevel@tonic-gate  * SLEEP	USB_ATTRS_AUTOCLEARING		legal
13270Sstevel@tonic-gate  * SLEEP	USB_ATTRS_PIPE_RESET		legal
13280Sstevel@tonic-gate  * SLEEP	USB_ATTRS_ONE_XFER		legal for interrupt IN pipes
13290Sstevel@tonic-gate  * SLEEP	USB_ATTRS_ISOC_START_FRAME	illegal
13300Sstevel@tonic-gate  * SLEEP	USB_ATTRS_ISOC_XFER_ASAP	illegal
13310Sstevel@tonic-gate  *
13320Sstevel@tonic-gate  * noSLEEP	USB_ATTRS_SHORT_XFER_OK		legal for all IN pipes
13330Sstevel@tonic-gate  * noSLEEP	USB_ATTRS_AUTOCLEARING		legal
13340Sstevel@tonic-gate  * noSLEEP	USB_ATTRS_PIPE_RESET		legal
13350Sstevel@tonic-gate  * noSLEEP	USB_ATTRS_ONE_XFER		legal
13360Sstevel@tonic-gate  * noSLEEP	USB_ATTRS_ISOC_START_FRAME	legal
13370Sstevel@tonic-gate  * noSLEEP	USB_ATTRS_ISOC_XFER_ASAP	legal
13380Sstevel@tonic-gate  */
13390Sstevel@tonic-gate typedef enum {
13400Sstevel@tonic-gate 	USB_ATTRS_NONE			= 0,
13410Sstevel@tonic-gate 
13420Sstevel@tonic-gate 	/* only ctrl/bulk/intr IN pipes */
13430Sstevel@tonic-gate 	USB_ATTRS_SHORT_XFER_OK		= 0x01,	/* short data xfer is ok */
13440Sstevel@tonic-gate 	USB_ATTRS_PIPE_RESET		= 0x02,	/* reset pipe only on exc */
13450Sstevel@tonic-gate 	USB_ATTRS_AUTOCLEARING		= 0x12, /* autoclear STALLs */
13460Sstevel@tonic-gate 
13470Sstevel@tonic-gate 	/* intr pipes only: one poll with data */
13480Sstevel@tonic-gate 	USB_ATTRS_ONE_XFER		= 0x100,
13490Sstevel@tonic-gate 
13500Sstevel@tonic-gate 	/* only for isoch pipe */
13510Sstevel@tonic-gate 	USB_ATTRS_ISOC_START_FRAME	= 0x200, /* Starting frame# specified */
13520Sstevel@tonic-gate 	USB_ATTRS_ISOC_XFER_ASAP	= 0x400	/* HCD decides START_FRAME#  */
13530Sstevel@tonic-gate } usb_req_attrs_t;
13540Sstevel@tonic-gate 
13550Sstevel@tonic-gate 
13560Sstevel@tonic-gate /*
13570Sstevel@tonic-gate  * Note: client drivers are required to provide data buffers (mblks) for most
13580Sstevel@tonic-gate  * requests
13590Sstevel@tonic-gate  *			IN		OUT
13600Sstevel@tonic-gate  * ctlr request		if wLength > 0	if wLength > 0
13610Sstevel@tonic-gate  * bulk request		yes		yes
13620Sstevel@tonic-gate  * intr request		no		yes
13630Sstevel@tonic-gate  * isoc request		no		yes
13640Sstevel@tonic-gate  */
13650Sstevel@tonic-gate 
13660Sstevel@tonic-gate /*
13670Sstevel@tonic-gate  * ===========================================================================
13680Sstevel@tonic-gate  * USB control request management
13690Sstevel@tonic-gate  * ===========================================================================
13700Sstevel@tonic-gate  */
13710Sstevel@tonic-gate 
13720Sstevel@tonic-gate /*
13730Sstevel@tonic-gate  * A client driver allocates and uses the usb_ctrl_req_t for all control
13740Sstevel@tonic-gate  * pipe requests.
13750Sstevel@tonic-gate  *
13760Sstevel@tonic-gate  * Direction of the xfer will be determined based on the bmRequestType.
13770Sstevel@tonic-gate  *
13780Sstevel@tonic-gate  * NULL callbacks are permitted, timeout = 0 indicates infinite timeout.
13790Sstevel@tonic-gate  * All timeouts are in seconds.
13800Sstevel@tonic-gate  *
13810Sstevel@tonic-gate  * All fields are initialized by client except for data on IN request
13820Sstevel@tonic-gate  * in which case the client is responsible for deallocating.
13830Sstevel@tonic-gate  *
13840Sstevel@tonic-gate  * Control requests may be reused.  The client driver is responsible
13850Sstevel@tonic-gate  * for reinitializing some fields, eg data read/write pointers.
13860Sstevel@tonic-gate  *
13870Sstevel@tonic-gate  * Control requests can be queued.
13880Sstevel@tonic-gate  */
13890Sstevel@tonic-gate typedef struct usb_ctrl_req {
13900Sstevel@tonic-gate 	uint8_t		ctrl_bmRequestType; /* characteristics of request */
13910Sstevel@tonic-gate 	uint8_t		ctrl_bRequest;	/* specific request		*/
13920Sstevel@tonic-gate 	uint16_t	ctrl_wValue;	/* varies according to request	*/
13930Sstevel@tonic-gate 	uint16_t	ctrl_wIndex;	/* index or offset		*/
13940Sstevel@tonic-gate 	uint16_t	ctrl_wLength;	/* number of bytes to xfer	*/
13950Sstevel@tonic-gate 
13960Sstevel@tonic-gate 	mblk_t		*ctrl_data;	/* the data for the data phase	*/
13970Sstevel@tonic-gate 					/* IN: allocated by HCD		*/
13980Sstevel@tonic-gate 					/* OUT: allocated by client	*/
13990Sstevel@tonic-gate 	uint_t		ctrl_timeout;	/* how long before HCD retires req */
14000Sstevel@tonic-gate 	usb_opaque_t	ctrl_client_private; /* for client private info	*/
14010Sstevel@tonic-gate 	usb_req_attrs_t ctrl_attributes; /* attributes for this req */
14020Sstevel@tonic-gate 
14030Sstevel@tonic-gate 	/*
14040Sstevel@tonic-gate 	 * callback function for control pipe requests
14050Sstevel@tonic-gate 	 *
14060Sstevel@tonic-gate 	 * a normal callback will be done upon:
14070Sstevel@tonic-gate 	 *	- successful completion of a control pipe request
14080Sstevel@tonic-gate 	 *
14090Sstevel@tonic-gate 	 * callback arguments are:
14100Sstevel@tonic-gate 	 *	- the pipe_handle
14110Sstevel@tonic-gate 	 *	- usb_ctrl_req_t pointer
14120Sstevel@tonic-gate 	 */
14130Sstevel@tonic-gate 	void		(*ctrl_cb)(usb_pipe_handle_t ph,
14140Sstevel@tonic-gate 				struct usb_ctrl_req *req);
14150Sstevel@tonic-gate 
14160Sstevel@tonic-gate 	/*
14170Sstevel@tonic-gate 	 * exception callback function for control pipe
14180Sstevel@tonic-gate 	 *
14190Sstevel@tonic-gate 	 * a exception callback will be done upon:
14200Sstevel@tonic-gate 	 *	- an exception/error (all types)
14210Sstevel@tonic-gate 	 *	- partial xfer of data unless SHORT_XFER_OK has been set
14220Sstevel@tonic-gate 	 *
14230Sstevel@tonic-gate 	 * callback arguments are:
14240Sstevel@tonic-gate 	 *	- the pipe_handle
14250Sstevel@tonic-gate 	 *	- usb_ctrl_req_t pointer
14260Sstevel@tonic-gate 	 *
14270Sstevel@tonic-gate 	 * if USB_ATTRS_AUTOCLEARING was set, autoclearing will be attempted
14280Sstevel@tonic-gate 	 * and usb_cb_flags_t in usb_ctrl_req may indicate what was done
14290Sstevel@tonic-gate 	 */
14300Sstevel@tonic-gate 	void		(*ctrl_exc_cb)(usb_pipe_handle_t ph,
14310Sstevel@tonic-gate 				struct usb_ctrl_req *req);
14320Sstevel@tonic-gate 
14330Sstevel@tonic-gate 	/* set by USBA/HCD on completion */
14340Sstevel@tonic-gate 	usb_cr_t	ctrl_completion_reason;	/* set by HCD */
14350Sstevel@tonic-gate 	usb_cb_flags_t	ctrl_cb_flags;  /* Callback context / handling flgs */
14360Sstevel@tonic-gate } usb_ctrl_req_t;
14370Sstevel@tonic-gate 
14380Sstevel@tonic-gate 
14390Sstevel@tonic-gate /*
14400Sstevel@tonic-gate  * In the setup packet, the descriptor type is passed in the high byte of the
14410Sstevel@tonic-gate  * wValue field.
14420Sstevel@tonic-gate  * descriptor types:
14430Sstevel@tonic-gate  */
14440Sstevel@tonic-gate #define	USB_DESCR_TYPE_SETUP_DEV		0x0100
14450Sstevel@tonic-gate #define	USB_DESCR_TYPE_SETUP_CFG		0x0200
14460Sstevel@tonic-gate #define	USB_DESCR_TYPE_SETUP_STRING		0x0300
14470Sstevel@tonic-gate #define	USB_DESCR_TYPE_SETUP_IF			0x0400
14480Sstevel@tonic-gate #define	USB_DESCR_TYPE_SETUP_EP			0x0500
14490Sstevel@tonic-gate #define	USB_DESCR_TYPE_SETUP_DEV_QLF		0x0600
14500Sstevel@tonic-gate #define	USB_DESCR_TYPE_SETUP_OTHER_SPEED_CFG	0x0700
14510Sstevel@tonic-gate #define	USB_DESCR_TYPE_SETUP_IF_PWR		0x0800
14520Sstevel@tonic-gate 
14530Sstevel@tonic-gate #define	USB_DESCR_TYPE_DEV			0x01
14540Sstevel@tonic-gate #define	USB_DESCR_TYPE_CFG			0x02
14550Sstevel@tonic-gate #define	USB_DESCR_TYPE_STRING			0x03
14560Sstevel@tonic-gate #define	USB_DESCR_TYPE_IF			0x04
14570Sstevel@tonic-gate #define	USB_DESCR_TYPE_EP			0x05
14580Sstevel@tonic-gate #define	USB_DESCR_TYPE_DEV_QLF			0x06
14590Sstevel@tonic-gate #define	USB_DESCR_TYPE_OTHER_SPEED_CFG		0x07
14600Sstevel@tonic-gate #define	USB_DESCR_TYPE_IF_PWR			0x08
14613341Sgc161489 #define	USB_DESCR_TYPE_IA			0x0B
14620Sstevel@tonic-gate 
14639430SRaymond.Chen@Sun.COM #define	USB_DESCR_TYPE_WA			0x21
14649430SRaymond.Chen@Sun.COM #define	USB_DESCR_TYPE_RPIPE			0x22
14659430SRaymond.Chen@Sun.COM 
14669430SRaymond.Chen@Sun.COM /* Wireless USB extension, refer to WUSB 1.0/7.4 */
14679430SRaymond.Chen@Sun.COM #define	USB_DESCR_TYPE_SECURITY			0x0c
14689430SRaymond.Chen@Sun.COM #define	USB_DESCR_TYPE_KEY			0x0d
14699430SRaymond.Chen@Sun.COM #define	USB_DESCR_TYPE_ENCRYPTION		0x0e
14709430SRaymond.Chen@Sun.COM #define	USB_DESCR_TYPE_BOS			0x0f
14719430SRaymond.Chen@Sun.COM #define	USB_DESCR_TYPE_DEV_CAPABILITY		0x10
14729430SRaymond.Chen@Sun.COM #define	USB_DESCR_TYPE_WIRELESS_EP_COMP		0x11
14739430SRaymond.Chen@Sun.COM 
14749430SRaymond.Chen@Sun.COM #define	USB_WA_DESCR_SIZE			14
14759430SRaymond.Chen@Sun.COM #define	USB_RPIPE_DESCR_SIZE			28
14769430SRaymond.Chen@Sun.COM 
14770Sstevel@tonic-gate /*
14780Sstevel@tonic-gate  * device request type
14790Sstevel@tonic-gate  */
14800Sstevel@tonic-gate #define	USB_DEV_REQ_HOST_TO_DEV		0x00
14810Sstevel@tonic-gate #define	USB_DEV_REQ_DEV_TO_HOST		0x80
14820Sstevel@tonic-gate #define	USB_DEV_REQ_DIR_MASK		0x80
14830Sstevel@tonic-gate 
14840Sstevel@tonic-gate #define	USB_DEV_REQ_TYPE_STANDARD	0x00
14850Sstevel@tonic-gate #define	USB_DEV_REQ_TYPE_CLASS		0x20
14860Sstevel@tonic-gate #define	USB_DEV_REQ_TYPE_VENDOR		0x40
14870Sstevel@tonic-gate #define	USB_DEV_REQ_TYPE_MASK		0x60
14880Sstevel@tonic-gate 
14890Sstevel@tonic-gate #define	USB_DEV_REQ_RCPT_DEV		0x00
14900Sstevel@tonic-gate #define	USB_DEV_REQ_RCPT_IF		0x01
14910Sstevel@tonic-gate #define	USB_DEV_REQ_RCPT_EP		0x02
14920Sstevel@tonic-gate #define	USB_DEV_REQ_RCPT_OTHER		0x03
14930Sstevel@tonic-gate #define	USB_DEV_REQ_RCPT_MASK		0x03
14940Sstevel@tonic-gate 
14959430SRaymond.Chen@Sun.COM /* Wire adapter class extension for request recipient */
14969430SRaymond.Chen@Sun.COM #define	USB_DEV_REQ_RCPT_PORT		0x04
14979430SRaymond.Chen@Sun.COM #define	USB_DEV_REQ_RCPT_RPIPE		0x05
14989430SRaymond.Chen@Sun.COM 
14990Sstevel@tonic-gate /*
15000Sstevel@tonic-gate  * device request
15010Sstevel@tonic-gate  */
15020Sstevel@tonic-gate #define	USB_REQ_GET_STATUS		0x00
15030Sstevel@tonic-gate #define	USB_REQ_CLEAR_FEATURE		0x01
15040Sstevel@tonic-gate #define	USB_REQ_SET_FEATURE		0x03
15050Sstevel@tonic-gate #define	USB_REQ_SET_ADDRESS		0x05
15060Sstevel@tonic-gate #define	USB_REQ_GET_DESCR		0x06
15070Sstevel@tonic-gate #define	USB_REQ_SET_DESCR		0x07
15080Sstevel@tonic-gate #define	USB_REQ_GET_CFG			0x08
15090Sstevel@tonic-gate #define	USB_REQ_SET_CFG			0x09
15100Sstevel@tonic-gate #define	USB_REQ_GET_IF			0x0a
15110Sstevel@tonic-gate #define	USB_REQ_SET_IF			0x0b
15120Sstevel@tonic-gate #define	USB_REQ_SYNC_FRAME		0x0c
15139430SRaymond.Chen@Sun.COM /* Wireless USB extension, refer to WUSB 1.0/7.3.1 */
15149430SRaymond.Chen@Sun.COM #define	USB_REQ_SET_ENCRYPTION		0x0d
15159430SRaymond.Chen@Sun.COM #define	USB_REQ_GET_ENCRYPTION		0x0e
15169430SRaymond.Chen@Sun.COM #define	USB_REQ_RPIPE_ABORT		0x0e
15179430SRaymond.Chen@Sun.COM #define	USB_REQ_SET_HANDSHAKE		0x0f
15189430SRaymond.Chen@Sun.COM #define	USB_REQ_RPIPE_RESET		0x0f
15199430SRaymond.Chen@Sun.COM #define	USB_REQ_GET_HANDSHAKE		0x10
15209430SRaymond.Chen@Sun.COM #define	USB_REQ_SET_CONNECTION		0x11
15219430SRaymond.Chen@Sun.COM #define	USB_REQ_SET_SECURITY_DATA	0x12
15229430SRaymond.Chen@Sun.COM #define	USB_REQ_GET_SECURITY_DATA	0x13
15239430SRaymond.Chen@Sun.COM #define	USB_REQ_SET_WUSB_DATA		0x14
15249430SRaymond.Chen@Sun.COM #define	USB_REQ_LOOPBACK_DATA_WRITE	0x15
15259430SRaymond.Chen@Sun.COM #define	USB_REQ_LOOPBACK_DATA_READ	0x16
15269430SRaymond.Chen@Sun.COM #define	USB_REQ_SET_INTERFACE_DS	0x17
15270Sstevel@tonic-gate 
15280Sstevel@tonic-gate /* language ID for string descriptors */
15290Sstevel@tonic-gate #define	USB_LANG_ID			0x0409
15300Sstevel@tonic-gate 
15310Sstevel@tonic-gate /*
15320Sstevel@tonic-gate  * Standard Feature Selectors
15330Sstevel@tonic-gate  */
15340Sstevel@tonic-gate #define	USB_EP_HALT			0x0000
15350Sstevel@tonic-gate #define	USB_DEV_REMOTE_WAKEUP		0x0001
15360Sstevel@tonic-gate #define	USB_DEV_TEST_MODE		0x0002
15379430SRaymond.Chen@Sun.COM /* Wireless USB extension, refer to WUSB 1.0/7.3.1 */
15389430SRaymond.Chen@Sun.COM #define	USB_DEV_WUSB			0x0003
15390Sstevel@tonic-gate 
15400Sstevel@tonic-gate 
15410Sstevel@tonic-gate /*
15420Sstevel@tonic-gate  * Allocate usb control request
15430Sstevel@tonic-gate  *
15440Sstevel@tonic-gate  * Arguments:
15450Sstevel@tonic-gate  *	dip	- dev_info pointer of the client driver
15460Sstevel@tonic-gate  *	len	- length of "data" for this control request.
15470Sstevel@tonic-gate  *		  if 0, no mblk is alloc'ed
15480Sstevel@tonic-gate  *	flags	- USB_FLAGS_SLEEP: Sleep if resources are not available
15490Sstevel@tonic-gate  *
15500Sstevel@tonic-gate  * Return Values:
15510Sstevel@tonic-gate  *	usb_ctrl_req_t pointer on success, NULL on failure
15520Sstevel@tonic-gate  *
15530Sstevel@tonic-gate  * Implementation NOTE: the dip allows checking on detach for memory leaks
15540Sstevel@tonic-gate  */
15550Sstevel@tonic-gate usb_ctrl_req_t *usb_alloc_ctrl_req(
15560Sstevel@tonic-gate 	dev_info_t		*dip,
15570Sstevel@tonic-gate 	size_t			len,
15580Sstevel@tonic-gate 	usb_flags_t		flags);
15590Sstevel@tonic-gate 
15600Sstevel@tonic-gate 
15610Sstevel@tonic-gate /*
15620Sstevel@tonic-gate  * free USB control request
15630Sstevel@tonic-gate  */
15640Sstevel@tonic-gate void usb_free_ctrl_req(
15650Sstevel@tonic-gate 	usb_ctrl_req_t	*reqp);
15660Sstevel@tonic-gate 
15670Sstevel@tonic-gate 
15680Sstevel@tonic-gate /*
15690Sstevel@tonic-gate  * usb_pipe_ctrl_xfer();
15700Sstevel@tonic-gate  *	Client driver calls this function to issue the control
15710Sstevel@tonic-gate  *	request to the USBA which will queue or transport it to the device
15720Sstevel@tonic-gate  *
15730Sstevel@tonic-gate  * Arguments:
15740Sstevel@tonic-gate  *	pipe_handle	- control pipe pipehandle (obtained via usb_pipe_open()
15750Sstevel@tonic-gate  *	reqp		- pointer to control request
15760Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
15770Sstevel@tonic-gate  *				wait for the request to complete
15780Sstevel@tonic-gate  *
15790Sstevel@tonic-gate  * Return values:
15800Sstevel@tonic-gate  *	USB_SUCCESS	- successfully queued (no sleep) or successfully
15810Sstevel@tonic-gate  *			  completed (with sleep specified)
15820Sstevel@tonic-gate  *	USB_FAILURE	- failure
15830Sstevel@tonic-gate  *	USB_NO_RESOURCES - no resources
15840Sstevel@tonic-gate  */
15850Sstevel@tonic-gate int usb_pipe_ctrl_xfer(usb_pipe_handle_t pipe_handle,
15860Sstevel@tonic-gate 	usb_ctrl_req_t	*reqp,
15870Sstevel@tonic-gate 	usb_flags_t		flags);
15880Sstevel@tonic-gate 
15890Sstevel@tonic-gate 
15900Sstevel@tonic-gate /*
15910Sstevel@tonic-gate  * ---------------------------------------------------------------------------
15920Sstevel@tonic-gate  * Wrapper function which allocates and deallocates a request structure, and
15930Sstevel@tonic-gate  * performs a control transfer.
15940Sstevel@tonic-gate  * ---------------------------------------------------------------------------
15950Sstevel@tonic-gate  */
15960Sstevel@tonic-gate 
15970Sstevel@tonic-gate /*
15980Sstevel@tonic-gate  * Setup arguments for usb_pipe_ctrl_xfer_wait:
15990Sstevel@tonic-gate  *
16000Sstevel@tonic-gate  *	bmRequestType	- characteristics of request
16010Sstevel@tonic-gate  *	bRequest	- specific request
16020Sstevel@tonic-gate  *	wValue		- varies according to request
16030Sstevel@tonic-gate  *	wIndex		- index or offset
16040Sstevel@tonic-gate  *	wLength		- number of bytes to xfer
16050Sstevel@tonic-gate  *	attrs		- required request attributes
16060Sstevel@tonic-gate  *	data		- pointer to pointer to data
16070Sstevel@tonic-gate  *				IN: HCD will allocate data
16080Sstevel@tonic-gate  *				OUT: clients driver allocates data
16090Sstevel@tonic-gate  */
16100Sstevel@tonic-gate typedef struct usb_ctrl_setup {
16110Sstevel@tonic-gate 	uchar_t		bmRequestType;
16120Sstevel@tonic-gate 	uchar_t		bRequest;
16130Sstevel@tonic-gate 	uint16_t	wValue;
16140Sstevel@tonic-gate 	uint16_t	wIndex;
16150Sstevel@tonic-gate 	uint16_t	wLength;
16160Sstevel@tonic-gate 	usb_req_attrs_t	attrs;
16170Sstevel@tonic-gate } usb_ctrl_setup_t;
16180Sstevel@tonic-gate 
16190Sstevel@tonic-gate 
16200Sstevel@tonic-gate /*
16210Sstevel@tonic-gate  * usb_pipe_ctrl_xfer_wait():
16220Sstevel@tonic-gate  *	for simple synchronous control transactions this wrapper function
16230Sstevel@tonic-gate  *	will perform the allocation, xfer, and deallocation.
16240Sstevel@tonic-gate  *	USB_ATTRS_AUTOCLEARING will be enabled
16250Sstevel@tonic-gate  *
16260Sstevel@tonic-gate  * Arguments:
16270Sstevel@tonic-gate  *	pipe_handle	- control pipe pipehandle (obtained via usb_pipe_open())
16280Sstevel@tonic-gate  *	setup		- contains pointer to client's devinfo,
16290Sstevel@tonic-gate  *			  setup descriptor params, attributes and data
16300Sstevel@tonic-gate  *	completion_reason - completion status.
16310Sstevel@tonic-gate  *	cb_flags	- request completions flags.
16320Sstevel@tonic-gate  *	flags		- none.
16330Sstevel@tonic-gate  *
16340Sstevel@tonic-gate  * Return Values:
16350Sstevel@tonic-gate  *	USB_SUCCESS	- request successfully executed.
16360Sstevel@tonic-gate  *	USB_FAILURE	- request failed.
16370Sstevel@tonic-gate  *	USB_*		- refer to list of all possible return values in
16380Sstevel@tonic-gate  *			  this file
16390Sstevel@tonic-gate  *
16400Sstevel@tonic-gate  * NOTES:
16410Sstevel@tonic-gate  * - in the case of failure, the client should check completion_reason and
16420Sstevel@tonic-gate  *   and cb_flags and determine further recovery action
16430Sstevel@tonic-gate  * - the client should check data and if non-zero, free the data on
16440Sstevel@tonic-gate  *   completion
16450Sstevel@tonic-gate  */
16460Sstevel@tonic-gate int usb_pipe_ctrl_xfer_wait(
16470Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
16480Sstevel@tonic-gate 	usb_ctrl_setup_t	*setup,
16490Sstevel@tonic-gate 	mblk_t			**data,
16500Sstevel@tonic-gate 	usb_cr_t		*completion_reason,
16510Sstevel@tonic-gate 	usb_cb_flags_t		*cb_flags,
16520Sstevel@tonic-gate 	usb_flags_t		flags);
16530Sstevel@tonic-gate 
16540Sstevel@tonic-gate 
16550Sstevel@tonic-gate /*
16560Sstevel@tonic-gate  * ---------------------------------------------------------------------------
16570Sstevel@tonic-gate  * Some utility defines and wrapper functions for standard control requests.
16580Sstevel@tonic-gate  * ---------------------------------------------------------------------------
16590Sstevel@tonic-gate  */
16600Sstevel@tonic-gate 
16610Sstevel@tonic-gate /*
16620Sstevel@tonic-gate  *
16630Sstevel@tonic-gate  * Status bits returned by a usb_get_status().
16640Sstevel@tonic-gate  */
16650Sstevel@tonic-gate #define	USB_DEV_SLF_PWRD_STATUS	1	/* Supports Self Power	 */
16660Sstevel@tonic-gate #define	USB_DEV_RWAKEUP_STATUS	2	/* Remote Wakeup Enabled */
16679430SRaymond.Chen@Sun.COM #define	USB_DEV_BAT_PWRD_STATUS	4	/* Battery Powered */
16680Sstevel@tonic-gate #define	USB_EP_HALT_STATUS	1	/* Endpoint is Halted	 */
16690Sstevel@tonic-gate #define	USB_IF_STATUS		0	/* Interface Status is 0 */
16700Sstevel@tonic-gate 
16710Sstevel@tonic-gate /* length of data returned by USB_REQ_GET_STATUS */
16720Sstevel@tonic-gate #define	USB_GET_STATUS_LEN		2
16730Sstevel@tonic-gate 
16740Sstevel@tonic-gate /*
16750Sstevel@tonic-gate  * wrapper function returning status of device, interface, or endpoint
16760Sstevel@tonic-gate  *
16770Sstevel@tonic-gate  * Arguments:
16780Sstevel@tonic-gate  *	dip		- devinfo pointer.
16790Sstevel@tonic-gate  *	ph		- pipe handle
16800Sstevel@tonic-gate  *	type		- bmRequestType to be used
16810Sstevel@tonic-gate  *	what		- 0 for device, otherwise interface or ep number
16820Sstevel@tonic-gate  *	status		- pointer to returned status.
16830Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP (mandatory)
16840Sstevel@tonic-gate  *
16850Sstevel@tonic-gate  * Return Values:
16860Sstevel@tonic-gate  *	valid usb_status_t	or USB_FAILURE
16870Sstevel@tonic-gate  *
16880Sstevel@tonic-gate  */
16890Sstevel@tonic-gate int usb_get_status(
16900Sstevel@tonic-gate 	dev_info_t		*dip,
16910Sstevel@tonic-gate 	usb_pipe_handle_t	ph,
16920Sstevel@tonic-gate 	uint_t			type,	/* bmRequestType */
16930Sstevel@tonic-gate 	uint_t			what,	/* 0, interface, endpoint number */
16940Sstevel@tonic-gate 	uint16_t		*status,
16950Sstevel@tonic-gate 	usb_flags_t		flags);
16960Sstevel@tonic-gate 
16970Sstevel@tonic-gate 
16980Sstevel@tonic-gate /*
16990Sstevel@tonic-gate  * function for clearing feature of device, interface, or endpoint
17000Sstevel@tonic-gate  *
17010Sstevel@tonic-gate  * Arguments:
17020Sstevel@tonic-gate  *	dip		- devinfo pointer.
17030Sstevel@tonic-gate  *	type		- bmRequestType to be used
17040Sstevel@tonic-gate  *	feature		- feature to be cleared
17050Sstevel@tonic-gate  *	what		- 0 for device, otherwise interface or ep number
17060Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP (mandatory)
17070Sstevel@tonic-gate  *	cb		- if USB_FLAGS_SLEEP has not been specified
17080Sstevel@tonic-gate  *			  this callback function will be called on
17090Sstevel@tonic-gate  *			  completion. This callback may be NULL
17100Sstevel@tonic-gate  *			  and no notification of completion will then
17110Sstevel@tonic-gate  *			  be provided.
17120Sstevel@tonic-gate  *	cb_arg		- 2nd argument to callback function.
17130Sstevel@tonic-gate  *
17140Sstevel@tonic-gate  * Return Values:
17150Sstevel@tonic-gate  *	USB_SUCCESS	clearing feature succeeded
17160Sstevel@tonic-gate  *	USB_FAILURE	clearing feature failed
17170Sstevel@tonic-gate  *	USB_*		refer to list of all possible return values in
17180Sstevel@tonic-gate  *			this file
17190Sstevel@tonic-gate  */
17200Sstevel@tonic-gate int usb_clr_feature(
17210Sstevel@tonic-gate 	dev_info_t		*dip,
17220Sstevel@tonic-gate 	uint_t			type,	/* bmRequestType */
17230Sstevel@tonic-gate 	uint_t			feature,
17240Sstevel@tonic-gate 	uint_t			what,	/* 0, interface, endpoint number */
17250Sstevel@tonic-gate 	usb_flags_t		flags,
17260Sstevel@tonic-gate 	void			(*cb)(
17270Sstevel@tonic-gate 					usb_pipe_handle_t ph,
17280Sstevel@tonic-gate 					usb_opaque_t	arg,
17290Sstevel@tonic-gate 					int		rval,
17300Sstevel@tonic-gate 					usb_cb_flags_t	flags),
17310Sstevel@tonic-gate 	usb_opaque_t		cb_arg);
17320Sstevel@tonic-gate 
17330Sstevel@tonic-gate 
17340Sstevel@tonic-gate /*
17350Sstevel@tonic-gate  * usb_set_cfg():
17360Sstevel@tonic-gate  *	Sets the configuration.  Use this function with caution as
17370Sstevel@tonic-gate  *	the framework is normally responsible for configuration changes.
17380Sstevel@tonic-gate  *	Changing configuration will fail if pipes are still open or
17390Sstevel@tonic-gate  *	when invoked from a driver bound to an interface on a composite
17400Sstevel@tonic-gate  *	device. This function access the device and blocks.
17410Sstevel@tonic-gate  *
17420Sstevel@tonic-gate  * Arguments:
17430Sstevel@tonic-gate  *	dip		- devinfo pointer.
17440Sstevel@tonic-gate  *	cfg_index	- Index of configuration to set.  Corresponds to
17450Sstevel@tonic-gate  *			  index in the usb_client_dev_data_t tree of
17460Sstevel@tonic-gate  *			  configurations.  See usb_client_dev_data_t(9F).
17470Sstevel@tonic-gate  *	usb_flags	- USB_FLAGS_SLEEP:
17480Sstevel@tonic-gate  *				wait for completion.
17490Sstevel@tonic-gate  *	cb		- if USB_FLAGS_SLEEP has not been specified
17500Sstevel@tonic-gate  *			  this callback function will be called on
17510Sstevel@tonic-gate  *			  completion. This callback may be NULL
17520Sstevel@tonic-gate  *			  and no notification of completion will then
17530Sstevel@tonic-gate  *			  be provided.
17540Sstevel@tonic-gate  *	cb_arg		- 2nd argument to callback function.
17550Sstevel@tonic-gate  *
17560Sstevel@tonic-gate  * callback and callback_arg should be NULL if USB_FLAGS_SLEEP has
17570Sstevel@tonic-gate  * been specified
17580Sstevel@tonic-gate  *
17590Sstevel@tonic-gate  * Return Values:
17600Sstevel@tonic-gate  *	USB_SUCCESS:	new configuration was set or async request
17610Sstevel@tonic-gate  *			submitted successfully.
17620Sstevel@tonic-gate  *	USB_FAILURE:	new configuration could not be set because
17630Sstevel@tonic-gate  *			it may been illegal configuration or this
17640Sstevel@tonic-gate  *			caller was not allowed to change configs or
17650Sstevel@tonic-gate  *			pipes were still open or async request
17660Sstevel@tonic-gate  *			could not be submitted.
17670Sstevel@tonic-gate  *	USB_*		refer to list of all possible return values in
17680Sstevel@tonic-gate  *			this file
17690Sstevel@tonic-gate  *
17700Sstevel@tonic-gate  * the pipe handle argument in the callback will be the default pipe handle
17710Sstevel@tonic-gate  */
17720Sstevel@tonic-gate int usb_set_cfg(
17730Sstevel@tonic-gate 	dev_info_t		*dip,
17740Sstevel@tonic-gate 	uint_t			cfg_index,
17750Sstevel@tonic-gate 	usb_flags_t		usb_flags,
17760Sstevel@tonic-gate 	void			(*cb)(
17770Sstevel@tonic-gate 					usb_pipe_handle_t ph,
17780Sstevel@tonic-gate 					usb_opaque_t	arg,
17790Sstevel@tonic-gate 					int		rval,
17800Sstevel@tonic-gate 					usb_cb_flags_t	flags),
17810Sstevel@tonic-gate 	usb_opaque_t		cb_arg);
17820Sstevel@tonic-gate 
17830Sstevel@tonic-gate 
17840Sstevel@tonic-gate /*
17850Sstevel@tonic-gate  * usb_get_cfg:
17860Sstevel@tonic-gate  *	dip		- pointer to devinfo node
17870Sstevel@tonic-gate  *	cfgval		- pointer to cfgval
17880Sstevel@tonic-gate  *	usb_flags	- none, will always block
17890Sstevel@tonic-gate  *
17900Sstevel@tonic-gate  * return values:
17910Sstevel@tonic-gate  *	USB_SUCCESS	- current cfg value is returned to cfgval
17920Sstevel@tonic-gate  *	USB_*		- refer to list of all possible return values in
17930Sstevel@tonic-gate  *			  this file
17940Sstevel@tonic-gate  */
17950Sstevel@tonic-gate int usb_get_cfg(
17960Sstevel@tonic-gate 	dev_info_t		*dip,
17970Sstevel@tonic-gate 	uint_t			*cfgval,
17980Sstevel@tonic-gate 	usb_flags_t		usb_flags);
17990Sstevel@tonic-gate 
18000Sstevel@tonic-gate 
18010Sstevel@tonic-gate /*
18020Sstevel@tonic-gate  * The following functions set or get the alternate interface
18030Sstevel@tonic-gate  * setting.
18040Sstevel@tonic-gate  *
18050Sstevel@tonic-gate  * usb_set_alt_if:
18060Sstevel@tonic-gate  *	dip		- pointer to devinfo node
18070Sstevel@tonic-gate  *	interface	- interface
18080Sstevel@tonic-gate  *	alt_number	- alternate to set to
18090Sstevel@tonic-gate  *	usb_flags	- USB_FLAGS_SLEEP:
18100Sstevel@tonic-gate  *				wait for completion.
18110Sstevel@tonic-gate  *	cb		- if USB_FLAGS_SLEEP has not been specified
18120Sstevel@tonic-gate  *			  this callback function will be called on
18130Sstevel@tonic-gate  *			  completion. This callback may be NULL
18140Sstevel@tonic-gate  *			  and no notification of completion will then
18150Sstevel@tonic-gate  *			  be provided.
18160Sstevel@tonic-gate  *	cb_arg		- 2nd argument to callback function.
18170Sstevel@tonic-gate  *
18180Sstevel@tonic-gate  * callback and callback_arg should be NULL if USB_FLAGS_SLEEP has
18190Sstevel@tonic-gate  * been specified
18200Sstevel@tonic-gate  *
18210Sstevel@tonic-gate  * the pipe handle argument in the callback will be the default pipe handle
18220Sstevel@tonic-gate  *
18230Sstevel@tonic-gate  * return values:
18240Sstevel@tonic-gate  *	USB_SUCCESS:	alternate was set or async request was
18250Sstevel@tonic-gate  *			submitted.
18260Sstevel@tonic-gate  *	USB_FAILURE:	alternate could not be set because pipes
18270Sstevel@tonic-gate  *			were still open or some access error occurred
18280Sstevel@tonic-gate  *			or an invalid alt if value was passed or
18290Sstevel@tonic-gate  *			async request could not be submitted
18300Sstevel@tonic-gate  *	USB_INVALID_PERM the driver does not own the device or the interface
18310Sstevel@tonic-gate  *	USB_*		refer to list of all possible return values in
18320Sstevel@tonic-gate  *			this file
18330Sstevel@tonic-gate  */
18340Sstevel@tonic-gate int usb_set_alt_if(
18350Sstevel@tonic-gate 	dev_info_t		*dip,
18360Sstevel@tonic-gate 	uint_t			interface,
18370Sstevel@tonic-gate 	uint_t			alt_number,
18380Sstevel@tonic-gate 	usb_flags_t		usb_flags,
18390Sstevel@tonic-gate 	void			(*cb)(
18400Sstevel@tonic-gate 					usb_pipe_handle_t ph,
18410Sstevel@tonic-gate 					usb_opaque_t	arg,
18420Sstevel@tonic-gate 					int		rval,
18430Sstevel@tonic-gate 					usb_cb_flags_t	flags),
18440Sstevel@tonic-gate 	usb_opaque_t		cb_arg);
18450Sstevel@tonic-gate 
18460Sstevel@tonic-gate 
18470Sstevel@tonic-gate 
18480Sstevel@tonic-gate /* flags must be USB_FLAGS_SLEEP, and this function will block */
18490Sstevel@tonic-gate int usb_get_alt_if(
18500Sstevel@tonic-gate 	dev_info_t		*dip,
18510Sstevel@tonic-gate 	uint_t			if_number,
18520Sstevel@tonic-gate 	uint_t			*alt_number,
18530Sstevel@tonic-gate 	usb_flags_t		flags);
18540Sstevel@tonic-gate 
18550Sstevel@tonic-gate 
18560Sstevel@tonic-gate /*
18570Sstevel@tonic-gate  * ===========================================================================
18580Sstevel@tonic-gate  * USB bulk request management
18590Sstevel@tonic-gate  * ===========================================================================
18600Sstevel@tonic-gate  */
18610Sstevel@tonic-gate 
18620Sstevel@tonic-gate /*
18630Sstevel@tonic-gate  * A client driver allocates/uses the usb_bulk_req_t for bulk pipe xfers.
18640Sstevel@tonic-gate  *
18650Sstevel@tonic-gate  * NOTES:
18660Sstevel@tonic-gate  * - bulk pipe sharing is not supported
18670Sstevel@tonic-gate  * - semantics of combinations of flag and attributes:
18680Sstevel@tonic-gate  *
18690Sstevel@tonic-gate  * flags     Type  attributes	data	timeout semantics
18700Sstevel@tonic-gate  * ----------------------------------------------------------------
18710Sstevel@tonic-gate  *  x	      x    x		== NULL    x	   illegal
18720Sstevel@tonic-gate  *
18730Sstevel@tonic-gate  * no sleep  IN    x		!= NULL    0	   fill buffer, no timeout
18740Sstevel@tonic-gate  *						   callback when xfer-len has
18750Sstevel@tonic-gate  *						   been xferred
18760Sstevel@tonic-gate  * no sleep  IN    x		!= NULL    > 0	   fill buffer, with timeout
18770Sstevel@tonic-gate  *						   callback when xfer-len has
18780Sstevel@tonic-gate  *						   been xferred
18790Sstevel@tonic-gate  *
18800Sstevel@tonic-gate  * sleep     IN    x		!= NULL    0	   fill buffer, no timeout
18810Sstevel@tonic-gate  *						   unblock when xfer-len has
18820Sstevel@tonic-gate  *						   been xferred
18830Sstevel@tonic-gate  *						   no callback
18840Sstevel@tonic-gate  * sleep     IN    x		!= NULL    > 0	   fill buffer, with timeout
18850Sstevel@tonic-gate  *						   unblock when xfer-len has
18860Sstevel@tonic-gate  *						   been xferred or timeout
18870Sstevel@tonic-gate  *						   no callback
18880Sstevel@tonic-gate  *
18890Sstevel@tonic-gate  *  X	     OUT SHORT_XFER_OK	  x	   x	   illegal
18900Sstevel@tonic-gate  *
18910Sstevel@tonic-gate  * no sleep  OUT   x		!= NULL    0	   empty buffer, no timeout
18920Sstevel@tonic-gate  *						   callback when xfer-len has
18930Sstevel@tonic-gate  *						   been xferred
18940Sstevel@tonic-gate  * no sleep  OUT   x		!= NULL    > 0	   empty buffer, with timeout
18950Sstevel@tonic-gate  *						   callback when xfer-len has
18960Sstevel@tonic-gate  *						   been xferred or timeout
18970Sstevel@tonic-gate  *
18980Sstevel@tonic-gate  * sleep     OUT   x		!= NULL    0	   empty buffer, no timeout
18990Sstevel@tonic-gate  *						   unblock when xfer-len has
19000Sstevel@tonic-gate  *						   been xferred
19010Sstevel@tonic-gate  *						   no callback
19020Sstevel@tonic-gate  * sleep     OUT   x		!= NULL    > 0	   empty buffer, with timeout
19030Sstevel@tonic-gate  *						   unblock when xfer-len has
19040Sstevel@tonic-gate  *						   been xferred or timeout
19050Sstevel@tonic-gate  *						   no callback
19060Sstevel@tonic-gate  *
19070Sstevel@tonic-gate  * - bulk_len and bulk_data must be > 0.  SHORT_XFER_OK is not applicable.
19080Sstevel@tonic-gate  *
19090Sstevel@tonic-gate  * - multiple bulk requests can be queued
19100Sstevel@tonic-gate  *
19110Sstevel@tonic-gate  * - Splitting large Bulk xfer:
19120Sstevel@tonic-gate  * The HCD driver, due to internal constraints, can only do a limited size bulk
19130Sstevel@tonic-gate  * data xfer per request.  The current limitations are 32K for UHCI and 128K
19140Sstevel@tonic-gate  * for OHCI.  So, a client driver may first determine this limitation (by
19150Sstevel@tonic-gate  * calling the USBA interface usb_pipe_bulk_transfer_size()); and restrict
19160Sstevel@tonic-gate  * itself to doing xfers in multiples of this fixed size.  This forces a client
19170Sstevel@tonic-gate  * driver to do data xfers in a loop for a large request, splitting it into
19180Sstevel@tonic-gate  * multiple chunks of fixed size.
19190Sstevel@tonic-gate  */
19200Sstevel@tonic-gate typedef struct usb_bulk_req {
19210Sstevel@tonic-gate 	uint_t		bulk_len;	/* number of bytes to xfer	*/
19220Sstevel@tonic-gate 	mblk_t		*bulk_data;	/* the data for the data phase	*/
19230Sstevel@tonic-gate 					/* IN: allocated by HCD		*/
19240Sstevel@tonic-gate 					/* OUT: allocated by client	*/
19250Sstevel@tonic-gate 	uint_t		bulk_timeout;	/* xfer timeout value in secs	*/
19260Sstevel@tonic-gate 	usb_opaque_t	bulk_client_private; /* Client specific information */
19270Sstevel@tonic-gate 	usb_req_attrs_t bulk_attributes; /* xfer-attributes	*/
19280Sstevel@tonic-gate 
19290Sstevel@tonic-gate 	/* Normal Callback function (For synch xfers) */
19300Sstevel@tonic-gate 	void		(*bulk_cb)(usb_pipe_handle_t ph,
19310Sstevel@tonic-gate 				struct usb_bulk_req *req);
19320Sstevel@tonic-gate 
19330Sstevel@tonic-gate 	/* Exception Callback function (For asynch xfers) */
19340Sstevel@tonic-gate 	void		(*bulk_exc_cb)(usb_pipe_handle_t ph,
19350Sstevel@tonic-gate 				struct usb_bulk_req *req);
19360Sstevel@tonic-gate 
19370Sstevel@tonic-gate 	/* set by USBA/HCD on completion */
19380Sstevel@tonic-gate 	usb_cr_t	bulk_completion_reason;	/* set by HCD		*/
19390Sstevel@tonic-gate 	usb_cb_flags_t	bulk_cb_flags;  /* Callback context / handling flgs */
19400Sstevel@tonic-gate } usb_bulk_req_t;
19410Sstevel@tonic-gate 
19420Sstevel@tonic-gate 
19430Sstevel@tonic-gate /*
19440Sstevel@tonic-gate  * Allocate/free usb bulk request
19450Sstevel@tonic-gate  *
19460Sstevel@tonic-gate  * Arguments:
19470Sstevel@tonic-gate  *	dip		- pointer to dev_info_t of the client driver
19480Sstevel@tonic-gate  *	len		- 0 or length of mblk to be allocated
19490Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
19500Sstevel@tonic-gate  *				wait for resources
19510Sstevel@tonic-gate  *
19520Sstevel@tonic-gate  * Return Values:
19530Sstevel@tonic-gate  *	usb_bulk_req_t on success, NULL on failure
19540Sstevel@tonic-gate  */
19550Sstevel@tonic-gate usb_bulk_req_t *usb_alloc_bulk_req(
19560Sstevel@tonic-gate 	dev_info_t		*dip,
19570Sstevel@tonic-gate 	size_t			len,
19580Sstevel@tonic-gate 	usb_flags_t		flags);
19590Sstevel@tonic-gate 
19600Sstevel@tonic-gate 
19610Sstevel@tonic-gate void usb_free_bulk_req(
19620Sstevel@tonic-gate 	usb_bulk_req_t	*reqp);
19630Sstevel@tonic-gate 
19640Sstevel@tonic-gate 
19650Sstevel@tonic-gate /*
19660Sstevel@tonic-gate  * usb_pipe_bulk_xfer():
19670Sstevel@tonic-gate  *
19680Sstevel@tonic-gate  * Client drivers call this function to issue the bulk xfer to the USBA
19690Sstevel@tonic-gate  * which will queue or transfer it to the device
19700Sstevel@tonic-gate  *
19710Sstevel@tonic-gate  * Arguments:
19720Sstevel@tonic-gate  *	pipe_handle	- bulk pipe handle (obtained via usb_pipe_open()
19730Sstevel@tonic-gate  *	reqp		- pointer to bulk data xfer request (IN or OUT)
19740Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
19750Sstevel@tonic-gate  *				wait for the request to complete
19760Sstevel@tonic-gate  *
19770Sstevel@tonic-gate  * Return Values:
19780Sstevel@tonic-gate  *	USB_SUCCESS	- success
19790Sstevel@tonic-gate  *	USB_FAILURE	- unspecified failure
19800Sstevel@tonic-gate  *	USB_NO_RESOURCES - no resources
19810Sstevel@tonic-gate  *
19820Sstevel@tonic-gate  */
19830Sstevel@tonic-gate int usb_pipe_bulk_xfer(
19840Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
19850Sstevel@tonic-gate 	usb_bulk_req_t		*reqp,
19860Sstevel@tonic-gate 	usb_flags_t		flags);
19870Sstevel@tonic-gate 
19880Sstevel@tonic-gate /* Get maximum bulk transfer size */
19890Sstevel@tonic-gate int usb_pipe_get_max_bulk_transfer_size(
19900Sstevel@tonic-gate 	dev_info_t		*dip,
19910Sstevel@tonic-gate 	size_t			*size);
19920Sstevel@tonic-gate 
19930Sstevel@tonic-gate 
19940Sstevel@tonic-gate /*
19950Sstevel@tonic-gate  * ===========================================================================
19960Sstevel@tonic-gate  * USB interrupt pipe request management
19970Sstevel@tonic-gate  * ===========================================================================
19980Sstevel@tonic-gate  */
19990Sstevel@tonic-gate 
20000Sstevel@tonic-gate /*
20010Sstevel@tonic-gate  * A client driver allocates and uses the usb_intr_req_t for
20020Sstevel@tonic-gate  * all interrupt pipe transfers.
20030Sstevel@tonic-gate  *
20040Sstevel@tonic-gate  * USB_FLAGS_SLEEP indicates here just to wait for resources except
20050Sstevel@tonic-gate  * for ONE_XFER where we also wait for completion
20060Sstevel@tonic-gate  *
20070Sstevel@tonic-gate  * semantics flags and attribute combinations:
20080Sstevel@tonic-gate  *
20090Sstevel@tonic-gate  * Notes:
20100Sstevel@tonic-gate  * none attributes indicates neither ONE_XFER nor SHORT_XFER_OK
20110Sstevel@tonic-gate  *
20120Sstevel@tonic-gate  * flags     Type  attributes	   data    timeout semantics
20130Sstevel@tonic-gate  * ----------------------------------------------------------------
20140Sstevel@tonic-gate  *  x	     IN      x		   != NULL  x	    illegal
20150Sstevel@tonic-gate  *  x	     IN   ONE_XFER=0	   x	   !=0	    illegal
20160Sstevel@tonic-gate  *
20170Sstevel@tonic-gate  *  x	     IN   ONE_XFER=0	   NULL     0	   continuous polling,
20180Sstevel@tonic-gate  *						   many callbacks
20190Sstevel@tonic-gate  *						   request is returned on
20200Sstevel@tonic-gate  *						   stop polling
20210Sstevel@tonic-gate  *
20220Sstevel@tonic-gate  * no sleep  IN   ONE_XFER	   NULL     0	   one time poll, no timeout,
20230Sstevel@tonic-gate  *						   one callback
20240Sstevel@tonic-gate  * no sleep  IN   ONE_XFER	   NULL    !=0	   one time poll, with
20250Sstevel@tonic-gate  *						   timeout, one callback
20260Sstevel@tonic-gate  *
20270Sstevel@tonic-gate  * sleep     IN   ONE_XFER	   NULL     0	   one time poll, no timeout,
20280Sstevel@tonic-gate  *						   no callback,
20290Sstevel@tonic-gate  *						   block for completion
20300Sstevel@tonic-gate  * sleep     IN   ONE_XFER	   NULL    !=0	   one time poll, with timeout,
20310Sstevel@tonic-gate  *						   no callback
20320Sstevel@tonic-gate  *						   block for completion
20330Sstevel@tonic-gate  *
20340Sstevel@tonic-gate  *  x	     OUT     x		   NULL    x	   illegal
20350Sstevel@tonic-gate  *  x	     OUT  ONE_XFER	   x	   x	   illegal
20360Sstevel@tonic-gate  *  x	     OUT  SHORT_XFER_OK    x	   x	   illegal
20370Sstevel@tonic-gate  *
20380Sstevel@tonic-gate  *  x	     OUT   none		   != NULL 0	   xfer until data exhausted,
20390Sstevel@tonic-gate  *						   no timeout,	one callback
20400Sstevel@tonic-gate  *  x	     OUT   none		   != NULL !=0	   xfer until data exhausted,
20410Sstevel@tonic-gate  *						   with timeout, one callback
20420Sstevel@tonic-gate  *
20430Sstevel@tonic-gate  * - Reads (IN):
20440Sstevel@tonic-gate  *
20450Sstevel@tonic-gate  * The client driver does *not* provide a data buffer.
20460Sstevel@tonic-gate  * By default, a READ request would mean continuous polling for data IN. The
20470Sstevel@tonic-gate  * HCD typically reads "wMaxPacketSize" amount of 'periodic data'. A client
20480Sstevel@tonic-gate  * driver may force the HCD to read instead intr_len
20490Sstevel@tonic-gate  * amount of 'periodic data' (See section 1).
20500Sstevel@tonic-gate  *
20510Sstevel@tonic-gate  * The HCD issues a callback to the client after each polling interval if
20520Sstevel@tonic-gate  * it has read in some data. Note that the amount of data read IN is either
20530Sstevel@tonic-gate  * intr_len or 'wMaxPacketSize' in length.
20540Sstevel@tonic-gate  *
20550Sstevel@tonic-gate  * Normally, the HCD keeps polling interrupt pipe forever even if there is
20560Sstevel@tonic-gate  * no data to be read IN.  A client driver may stop this polling by
20570Sstevel@tonic-gate  * calling usb_pipe_stop_intr_polling().
20580Sstevel@tonic-gate  *
20590Sstevel@tonic-gate  * If a client driver chooses to pass USB_ATTRS_ONE_XFER as
20600Sstevel@tonic-gate  * 'xfer_attributes' the HCD will poll for data until some data is received.
20610Sstevel@tonic-gate  * HCD reads in the data and does a callback and stops polling for any more
20620Sstevel@tonic-gate  * data.  In this case, the client driver need not explicitly call
20630Sstevel@tonic-gate  * usb_pipe_stop_intr_polling().
20640Sstevel@tonic-gate  *
20650Sstevel@tonic-gate  * When continuous polling is stopped, the original request is returned with
20660Sstevel@tonic-gate  * USB_CR_STOPPED_POLLING.
20670Sstevel@tonic-gate  *
20680Sstevel@tonic-gate  * - Writes (OUT):
20690Sstevel@tonic-gate  *
20700Sstevel@tonic-gate  * A client driver provides the data buffer, and data, needed for intr write.
20710Sstevel@tonic-gate  * There is no continuous write mode, a la  read (See previous section).
20720Sstevel@tonic-gate  * The USB_ATTRS_ONE_XFER attribute is illegal.
20730Sstevel@tonic-gate  * By default USBA keeps writing intr data until the provided data buffer
20740Sstevel@tonic-gate  * has been written out. The HCD does ONE callback to the client driver.
20750Sstevel@tonic-gate  * Queueing is supported.
20760Sstevel@tonic-gate  * Max size is 8k
20770Sstevel@tonic-gate  */
20780Sstevel@tonic-gate typedef struct usb_intr_req {
20790Sstevel@tonic-gate 	uint_t		intr_len;	/* OUT: size of total xfer */
20800Sstevel@tonic-gate 					/* IN : packet size */
20810Sstevel@tonic-gate 	mblk_t		*intr_data;	/* the data for the data phase	*/
20820Sstevel@tonic-gate 					/* IN: allocated by HCD		*/
20830Sstevel@tonic-gate 					/* OUT: allocated by client	*/
20840Sstevel@tonic-gate 	usb_opaque_t	intr_client_private; /* Client specific information  */
20850Sstevel@tonic-gate 	uint_t		intr_timeout;	/* only with ONE TIME POLL, in secs */
20860Sstevel@tonic-gate 	usb_req_attrs_t	intr_attributes;
20870Sstevel@tonic-gate 
20880Sstevel@tonic-gate 	/* Normal callback function (For synch transfers) */
20890Sstevel@tonic-gate 	void		(*intr_cb)(usb_pipe_handle_t ph,
20900Sstevel@tonic-gate 				struct usb_intr_req *req);
20910Sstevel@tonic-gate 
20920Sstevel@tonic-gate 	/* Exception callback function (For asynch transfers) */
20930Sstevel@tonic-gate 	void		(*intr_exc_cb)(usb_pipe_handle_t ph,
20940Sstevel@tonic-gate 				struct usb_intr_req *req);
20950Sstevel@tonic-gate 
20960Sstevel@tonic-gate 	/* set by USBA/HCD on completion */
20970Sstevel@tonic-gate 	usb_cr_t	intr_completion_reason;	/* set by HCD */
20980Sstevel@tonic-gate 	usb_cb_flags_t	intr_cb_flags;  /* Callback context / handling flgs */
20990Sstevel@tonic-gate } usb_intr_req_t;
21000Sstevel@tonic-gate 
21010Sstevel@tonic-gate 
21020Sstevel@tonic-gate /*
21030Sstevel@tonic-gate  * Allocate/free usb interrupt pipe request
21040Sstevel@tonic-gate  *
21050Sstevel@tonic-gate  * Arguments:
21060Sstevel@tonic-gate  *	dip		- pointer to dev_info_t of the client driver
21070Sstevel@tonic-gate  *	reqp		- pointer to request structure
21080Sstevel@tonic-gate  *	len		- 0 or length of mblk for this interrupt request
21090Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
21100Sstevel@tonic-gate  *				Sleep if resources are not available
21110Sstevel@tonic-gate  *
21120Sstevel@tonic-gate  * Return Values:
21130Sstevel@tonic-gate  *	usb_intr_req_t on success, NULL on failure
21140Sstevel@tonic-gate  */
21150Sstevel@tonic-gate usb_intr_req_t *usb_alloc_intr_req(
21160Sstevel@tonic-gate 	dev_info_t		*dip,
21170Sstevel@tonic-gate 	size_t			len,
21180Sstevel@tonic-gate 	usb_flags_t		flags);
21190Sstevel@tonic-gate 
21200Sstevel@tonic-gate 
21210Sstevel@tonic-gate void usb_free_intr_req(
21220Sstevel@tonic-gate 	usb_intr_req_t	*reqp);
21230Sstevel@tonic-gate 
21240Sstevel@tonic-gate 
21250Sstevel@tonic-gate /*
21260Sstevel@tonic-gate  * usb_pipe_intr_xfer():
21270Sstevel@tonic-gate  *
21280Sstevel@tonic-gate  * Client drivers call this function to issue the intr xfer to USBA/HCD
21290Sstevel@tonic-gate  * which starts polling the device
21300Sstevel@tonic-gate  *
21310Sstevel@tonic-gate  * Arguments:
21320Sstevel@tonic-gate  *	pipe_handle	- interrupt pipe handle (obtained via usb_pipe_open()
21330Sstevel@tonic-gate  *	reqp		- pointer tothe interrupt pipe xfer request (IN or OUT)
21340Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
21350Sstevel@tonic-gate  *				wait for resources to be available
21360Sstevel@tonic-gate  *
21370Sstevel@tonic-gate  * return values:
21380Sstevel@tonic-gate  *	USB_SUCCESS	- success
21390Sstevel@tonic-gate  *	USB_FAILURE	- unspecified failure
21400Sstevel@tonic-gate  *	USB_NO_RESOURCES  - no resources
21410Sstevel@tonic-gate  *
21420Sstevel@tonic-gate  * NOTE: start polling on an IN pipe that is already being polled is a NOP.
21430Sstevel@tonic-gate  *	 We don't queue requests on OUT pipe
21440Sstevel@tonic-gate  */
21450Sstevel@tonic-gate int usb_pipe_intr_xfer(
21460Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
21470Sstevel@tonic-gate 	usb_intr_req_t		*req,
21480Sstevel@tonic-gate 	usb_flags_t		flags);
21490Sstevel@tonic-gate 
21500Sstevel@tonic-gate 
21510Sstevel@tonic-gate /*
21520Sstevel@tonic-gate  * usb_pipe_stop_intr_polling():
21530Sstevel@tonic-gate  *
21540Sstevel@tonic-gate  * Client drivers call this function to stop the automatic data-in/out transfers
21550Sstevel@tonic-gate  * without closing the pipe.
21560Sstevel@tonic-gate  *
21570Sstevel@tonic-gate  * If USB_FLAGS_SLEEP  has been specified then this function will block until
21580Sstevel@tonic-gate  * polling has been stopped and all callbacks completed. If USB_FLAGS_SLEEP
21590Sstevel@tonic-gate  * has NOT been specified then polling is terminated when the original
21600Sstevel@tonic-gate  * request that started the polling has been returned with
21610Sstevel@tonic-gate  * USB_CR_STOPPED_POLLING
21620Sstevel@tonic-gate  *
21630Sstevel@tonic-gate  * Stop polling should never fail.
21640Sstevel@tonic-gate  *
21650Sstevel@tonic-gate  * Args:-
21660Sstevel@tonic-gate  *	pipe_handle	- interrupt pipe handle (obtained via usb_pipe_open()).
21670Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
21680Sstevel@tonic-gate  *				wait for the resources to be available.
21690Sstevel@tonic-gate  */
21700Sstevel@tonic-gate void usb_pipe_stop_intr_polling(
21710Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
21720Sstevel@tonic-gate 	usb_flags_t		flags);
21730Sstevel@tonic-gate 
21740Sstevel@tonic-gate 
21750Sstevel@tonic-gate /*
21760Sstevel@tonic-gate  * ===========================================================================
21770Sstevel@tonic-gate  * USB isochronous xfer management
21780Sstevel@tonic-gate  * ===========================================================================
21790Sstevel@tonic-gate  */
21800Sstevel@tonic-gate 
21810Sstevel@tonic-gate /*
21820Sstevel@tonic-gate  * The usb frame number is an absolute number since boot and incremented
21830Sstevel@tonic-gate  * every 1 ms.
21840Sstevel@tonic-gate  */
21850Sstevel@tonic-gate typedef	uint64_t	usb_frame_number_t;
21860Sstevel@tonic-gate 
21870Sstevel@tonic-gate /*
21880Sstevel@tonic-gate  * USB ischronous packet descriptor
21890Sstevel@tonic-gate  *
21900Sstevel@tonic-gate  * An array of structures of type usb_isoc_pkt_descr_t must be allocated and
21910Sstevel@tonic-gate  * initialized by the client driver using usb_alloc_isoc_req(). The client
21920Sstevel@tonic-gate  * driver must set isoc_pkt_length in each packet descriptor before submitting
21930Sstevel@tonic-gate  * the request.
21940Sstevel@tonic-gate  */
21950Sstevel@tonic-gate typedef struct usb_isoc_pkt_descr {
21960Sstevel@tonic-gate 	/*
21970Sstevel@tonic-gate 	 * Set by the client driver, for all isochronous requests, to the
21980Sstevel@tonic-gate 	 * number of bytes to transfer in a frame.
21990Sstevel@tonic-gate 	 */
22000Sstevel@tonic-gate 	ushort_t	isoc_pkt_length;
22010Sstevel@tonic-gate 
22020Sstevel@tonic-gate 	/*
22030Sstevel@tonic-gate 	 * Set by HCD to actual number of bytes sent/received in frame.
22040Sstevel@tonic-gate 	 */
22050Sstevel@tonic-gate 	ushort_t	isoc_pkt_actual_length;
22060Sstevel@tonic-gate 
22070Sstevel@tonic-gate 	/*
22080Sstevel@tonic-gate 	 * Per frame status set by HCD both for the isochronous IN and OUT
22090Sstevel@tonic-gate 	 * requests.  If any status is non-zero then isoc_error_count in the
22100Sstevel@tonic-gate 	 * isoc_req will be non-zero.
22110Sstevel@tonic-gate 	 */
22120Sstevel@tonic-gate 	usb_cr_t	isoc_pkt_status;
22130Sstevel@tonic-gate } usb_isoc_pkt_descr_t;
22140Sstevel@tonic-gate 
22150Sstevel@tonic-gate 
22160Sstevel@tonic-gate /*
22170Sstevel@tonic-gate  * USB isochronous request
22180Sstevel@tonic-gate  *
22190Sstevel@tonic-gate  * The client driver allocates the usb_isoc_req_t before sending an
22200Sstevel@tonic-gate  * isochronous requests.
22210Sstevel@tonic-gate  *
22220Sstevel@tonic-gate  * USB_FLAGS_SLEEP indicates here just to wait for resources but not
22230Sstevel@tonic-gate  * to wait for completion
22240Sstevel@tonic-gate  *
22250Sstevel@tonic-gate  * Semantics of various combinations for data xfers:
22260Sstevel@tonic-gate  *
22270Sstevel@tonic-gate  * Note: attributes considered in this table are ONE_XFER, START_FRAME,
22280Sstevel@tonic-gate  *	XFER_ASAP, SHORT_XFER
22290Sstevel@tonic-gate  *
22300Sstevel@tonic-gate  *
22310Sstevel@tonic-gate  * flags     Type  attributes		   data    semantics
22320Sstevel@tonic-gate  * ---------------------------------------------------------------------
22330Sstevel@tonic-gate  * x	     x	   x			NULL	   illegal
22340Sstevel@tonic-gate  *
22350Sstevel@tonic-gate  * x	     x	   ONE_XFER		 x	   illegal
22360Sstevel@tonic-gate  *
22370Sstevel@tonic-gate  * x	     IN    x			!=NULL	   continuous polling,
22380Sstevel@tonic-gate  *						   many callbacks
22390Sstevel@tonic-gate  *
22400Sstevel@tonic-gate  * x	     IN    ISOC_START_FRAME	!=NULL	   invalid if Current_frame# >
22410Sstevel@tonic-gate  *						   "isoc_frame_no"
22420Sstevel@tonic-gate  * x	     IN    ISOC_XFER_ASAP	!=NULL	   "isoc_frame_no" ignored.
22430Sstevel@tonic-gate  *						   HCD determines when to
22440Sstevel@tonic-gate  *						   insert xfer
22450Sstevel@tonic-gate  *
22460Sstevel@tonic-gate  * x	     OUT   ONE_XFER		x	   illegal
22470Sstevel@tonic-gate  * x	     OUT   SHORT_XFER_OK	x	   illegal
22480Sstevel@tonic-gate  *
22490Sstevel@tonic-gate  * x	     OUT   ISOC_START_FRAME	!=NULL	   invalid if Current_frame# >
22500Sstevel@tonic-gate  *						   "isoc_frame_no"
22510Sstevel@tonic-gate  * x	     OUT   ISOC_XFER_ASAP	!=NULL	   "isoc_frame_no" ignored.
22520Sstevel@tonic-gate  *						    HCD determines when to
22530Sstevel@tonic-gate  *						   insert xfer
22540Sstevel@tonic-gate  */
22550Sstevel@tonic-gate typedef struct usb_isoc_req {
22560Sstevel@tonic-gate 	/*
22570Sstevel@tonic-gate 	 * Starting frame number will be set by the client driver in which
22580Sstevel@tonic-gate 	 * to begin this request. This frame number is used to synchronize
22590Sstevel@tonic-gate 	 * requests queued to different isochronous pipes. The frame number
22600Sstevel@tonic-gate 	 * is optional and client driver can skip starting frame number by
22610Sstevel@tonic-gate 	 * setting USB_ISOC_ATTRS_ASAP. In this case, HCD will decide starting
22620Sstevel@tonic-gate 	 * frame number for this isochronous request.  If this field is 0,
22630Sstevel@tonic-gate 	 * then this indicates an invalid frame number.
22640Sstevel@tonic-gate 	 */
22650Sstevel@tonic-gate 	usb_frame_number_t	isoc_frame_no;
22660Sstevel@tonic-gate 
22670Sstevel@tonic-gate 	/*
22683255Slg150142 	 * Number of isochronous data packets.
22690Sstevel@tonic-gate 	 * The first field is set by client  driver and may not exceed
22700Sstevel@tonic-gate 	 * the maximum number of entries in the usb isochronous packet
22710Sstevel@tonic-gate 	 * descriptors.
22720Sstevel@tonic-gate 	 */
22730Sstevel@tonic-gate 	ushort_t		isoc_pkts_count;
22743255Slg150142 
22753255Slg150142 	/*
22763255Slg150142 	 * The sum of all pkt lengths in the isoc request. Recommend to
22773255Slg150142 	 * set it to zero, so the sum of isoc_pkt_length in the
22783255Slg150142 	 * isoc_pkt_descr list will be used automatically and no check
22793255Slg150142 	 * will be apply to this element.
22803255Slg150142 	 */
22810Sstevel@tonic-gate 	ushort_t		isoc_pkts_length;
22820Sstevel@tonic-gate 
22830Sstevel@tonic-gate 	/*
22840Sstevel@tonic-gate 	 * This field will be set by HCD and this field indicates the number
22850Sstevel@tonic-gate 	 * of packets that completed with errors.
22860Sstevel@tonic-gate 	 */
22870Sstevel@tonic-gate 	ushort_t		isoc_error_count;
22880Sstevel@tonic-gate 
22890Sstevel@tonic-gate 	/*
22900Sstevel@tonic-gate 	 * Attributes specific to particular usb isochronous request.
22910Sstevel@tonic-gate 	 * Supported values are: USB_ATTRS_ISOC_START_FRAME,
22920Sstevel@tonic-gate 	 * USB_ATTRS_ISOC_XFER_ASAP.
22930Sstevel@tonic-gate 	 */
22940Sstevel@tonic-gate 	usb_req_attrs_t 	isoc_attributes;
22950Sstevel@tonic-gate 
22960Sstevel@tonic-gate 	/*
22970Sstevel@tonic-gate 	 * Isochronous OUT:
22980Sstevel@tonic-gate 	 *	allocated and set by client driver, freed and zeroed by HCD
22990Sstevel@tonic-gate 	 *	on successful completion
23000Sstevel@tonic-gate 	 * Isochronous IN:
23010Sstevel@tonic-gate 	 *	allocated and set by HCD, freed by client driver
23020Sstevel@tonic-gate 	 */
23030Sstevel@tonic-gate 	mblk_t			*isoc_data;
23040Sstevel@tonic-gate 
23050Sstevel@tonic-gate 	/*
23060Sstevel@tonic-gate 	 * The client driver specific private information.
23070Sstevel@tonic-gate 	 */
23080Sstevel@tonic-gate 	usb_opaque_t		isoc_client_private;
23090Sstevel@tonic-gate 
23100Sstevel@tonic-gate 	/*
23110Sstevel@tonic-gate 	 * Isochronous OUT:
23120Sstevel@tonic-gate 	 *	must be allocated & initialized by client driver
23130Sstevel@tonic-gate 	 * Isochronous IN:
23140Sstevel@tonic-gate 	 *	must be allocated by client driver
23150Sstevel@tonic-gate 	 */
23160Sstevel@tonic-gate 	struct usb_isoc_pkt_descr *isoc_pkt_descr;
23170Sstevel@tonic-gate 
23180Sstevel@tonic-gate 	/* Normal callback function (For synch transfers) */
23190Sstevel@tonic-gate 	void			(*isoc_cb)(usb_pipe_handle_t ph,
23200Sstevel@tonic-gate 					struct usb_isoc_req *req);
23210Sstevel@tonic-gate 
23220Sstevel@tonic-gate 	/* Exception callback function (For asynch transfers) */
23230Sstevel@tonic-gate 	void			(*isoc_exc_cb)(usb_pipe_handle_t ph,
23240Sstevel@tonic-gate 					struct usb_isoc_req *req);
23250Sstevel@tonic-gate 
23260Sstevel@tonic-gate 	/* set by USBA/HCD on completion */
23270Sstevel@tonic-gate 	usb_cr_t		isoc_completion_reason;	/* set by HCD */
23280Sstevel@tonic-gate 					/* Callback context / handling flgs */
23290Sstevel@tonic-gate 	usb_cb_flags_t		isoc_cb_flags;
23300Sstevel@tonic-gate } usb_isoc_req_t;
23310Sstevel@tonic-gate 
23320Sstevel@tonic-gate 
23330Sstevel@tonic-gate /*
23340Sstevel@tonic-gate  * Allocate/free usb isochronous resources
23350Sstevel@tonic-gate  *
23360Sstevel@tonic-gate  * isoc_pkts_count must be > 0
23370Sstevel@tonic-gate  *
23380Sstevel@tonic-gate  * Arguments:
23390Sstevel@tonic-gate  *	dip		- client driver's devinfo pointer
23400Sstevel@tonic-gate  *	isoc_pkts_count - number of pkts required
23410Sstevel@tonic-gate  *	len		- 0 or size of mblk to allocate
23420Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
23430Sstevel@tonic-gate  *				wait for resources
23440Sstevel@tonic-gate  *
23450Sstevel@tonic-gate  * Return Values:
23460Sstevel@tonic-gate  *	usb_isoc_req pointer or NULL
23470Sstevel@tonic-gate  */
23480Sstevel@tonic-gate usb_isoc_req_t *usb_alloc_isoc_req(
23490Sstevel@tonic-gate 	dev_info_t		*dip,
23500Sstevel@tonic-gate 	uint_t			isoc_pkts_count,
23510Sstevel@tonic-gate 	size_t			len,
23520Sstevel@tonic-gate 	usb_flags_t		flags);
23530Sstevel@tonic-gate 
23540Sstevel@tonic-gate void	usb_free_isoc_req(
23550Sstevel@tonic-gate 	usb_isoc_req_t		*usb_isoc_req);
23560Sstevel@tonic-gate 
23570Sstevel@tonic-gate /*
23580Sstevel@tonic-gate  * Returns current usb frame number.
23590Sstevel@tonic-gate  */
23600Sstevel@tonic-gate usb_frame_number_t usb_get_current_frame_number(
23610Sstevel@tonic-gate 	dev_info_t		*dip);
23620Sstevel@tonic-gate 
23630Sstevel@tonic-gate /*
23640Sstevel@tonic-gate  * Get maximum isochronous packets per usb isochronous request
23650Sstevel@tonic-gate  */
23660Sstevel@tonic-gate uint_t usb_get_max_pkts_per_isoc_request(
23670Sstevel@tonic-gate 	dev_info_t		*dip);
23680Sstevel@tonic-gate 
23690Sstevel@tonic-gate /*
23700Sstevel@tonic-gate  * usb_pipe_isoc_xfer()
23710Sstevel@tonic-gate  *
23720Sstevel@tonic-gate  * Client drivers call this to issue the isoch xfer (IN and OUT) to the USBA
23730Sstevel@tonic-gate  * which starts polling the device.
23740Sstevel@tonic-gate  *
23750Sstevel@tonic-gate  * Arguments:
23760Sstevel@tonic-gate  *	pipe_handle	- isoc pipe handle (obtained via usb_pipe_open().
23770Sstevel@tonic-gate  *	reqp		- pointer to the isochronous pipe IN xfer request
23780Sstevel@tonic-gate  *			  allocated by the client driver.
23790Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
23800Sstevel@tonic-gate  *				wait for the resources to be available.
23810Sstevel@tonic-gate  *
23820Sstevel@tonic-gate  * return values:
23830Sstevel@tonic-gate  *	USB_SUCCESS	- success.
23840Sstevel@tonic-gate  *	USB_FAILURE	- unspecified failure.
23850Sstevel@tonic-gate  *	USB_NO_RESOURCES  - no resources.
23860Sstevel@tonic-gate  *	USB_NO_FRAME_NUMBER - START_FRAME, ASAP flags not specified.
23870Sstevel@tonic-gate  *	USB_INVALID_START_FRAME	- Starting USB frame number invalid.
23880Sstevel@tonic-gate  *
23890Sstevel@tonic-gate  * Notes:
23900Sstevel@tonic-gate  * - usb_pipe_isoc_xfer on an IN pipe that is already being polled is a NOP.
23910Sstevel@tonic-gate  * - requests can be queued on an OUT pipe.
23920Sstevel@tonic-gate  */
23930Sstevel@tonic-gate int usb_pipe_isoc_xfer(
23940Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
23950Sstevel@tonic-gate 	usb_isoc_req_t		*reqp,
23960Sstevel@tonic-gate 	usb_flags_t		flags);
23970Sstevel@tonic-gate 
23980Sstevel@tonic-gate /*
23990Sstevel@tonic-gate  * usb_pipe_stop_isoc_polling():
24000Sstevel@tonic-gate  *
24010Sstevel@tonic-gate  * Client drivers call this function to stop the automatic data-in/out
24020Sstevel@tonic-gate  * transfers without closing the isoc pipe.
24030Sstevel@tonic-gate  *
24040Sstevel@tonic-gate  * If USB_FLAGS_SLEEP  has been specified then this function will block until
24050Sstevel@tonic-gate  * polling has been stopped and all callbacks completed. If USB_FLAGS_SLEEP
24060Sstevel@tonic-gate  * has NOT been specified then polling is terminated when the original
24070Sstevel@tonic-gate  * request that started the polling has been returned with
24080Sstevel@tonic-gate  * USB_CR_STOPPED_POLLING
24090Sstevel@tonic-gate  *
24100Sstevel@tonic-gate  * Stop polling should never fail.
24110Sstevel@tonic-gate  *
24120Sstevel@tonic-gate  * Arguments:
24130Sstevel@tonic-gate  *	pipe_handle	- isoc pipe handle (obtained via usb_pipe_open().
24140Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
24150Sstevel@tonic-gate  *				wait for polling to be stopped and all
24160Sstevel@tonic-gate  *				callbacks completed.
24170Sstevel@tonic-gate  */
24180Sstevel@tonic-gate void usb_pipe_stop_isoc_polling(
24190Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
24200Sstevel@tonic-gate 	usb_flags_t		flags);
24210Sstevel@tonic-gate 
24220Sstevel@tonic-gate /*
24230Sstevel@tonic-gate  * ***************************************************************************
24240Sstevel@tonic-gate  * USB device power management:
24250Sstevel@tonic-gate  * ***************************************************************************
24260Sstevel@tonic-gate  */
24270Sstevel@tonic-gate 
24280Sstevel@tonic-gate /*
24290Sstevel@tonic-gate  *
24300Sstevel@tonic-gate  * As any usb device will have a max of 4 possible power states
24310Sstevel@tonic-gate  * the #define	for them are provided below with mapping to the
24320Sstevel@tonic-gate  * corresponding OS power levels.
24330Sstevel@tonic-gate  */
24340Sstevel@tonic-gate #define	USB_DEV_PWR_D0		USB_DEV_OS_FULL_PWR
24350Sstevel@tonic-gate #define	USB_DEV_PWR_D1		5
24360Sstevel@tonic-gate #define	USB_DEV_PWR_D2		6
24370Sstevel@tonic-gate #define	USB_DEV_PWR_D3		USB_DEV_OS_PWR_OFF
24380Sstevel@tonic-gate 
24390Sstevel@tonic-gate #define	USB_DEV_OS_PWR_0	0
24400Sstevel@tonic-gate #define	USB_DEV_OS_PWR_1	1
24410Sstevel@tonic-gate #define	USB_DEV_OS_PWR_2	2
24420Sstevel@tonic-gate #define	USB_DEV_OS_PWR_3	3
24430Sstevel@tonic-gate #define	USB_DEV_OS_PWR_OFF	USB_DEV_OS_PWR_0
24440Sstevel@tonic-gate #define	USB_DEV_OS_FULL_PWR	USB_DEV_OS_PWR_3
24450Sstevel@tonic-gate 
24460Sstevel@tonic-gate /* Bit Masks for Power States */
24470Sstevel@tonic-gate #define	USB_DEV_OS_PWRMASK_D0	1
24480Sstevel@tonic-gate #define	USB_DEV_OS_PWRMASK_D1	2
24490Sstevel@tonic-gate #define	USB_DEV_OS_PWRMASK_D2	4
24500Sstevel@tonic-gate #define	USB_DEV_OS_PWRMASK_D3	8
24510Sstevel@tonic-gate 
24520Sstevel@tonic-gate /* conversion for OS to Dx levels */
24530Sstevel@tonic-gate #define	USB_DEV_OS_PWR2USB_PWR(l)	(USB_DEV_OS_FULL_PWR - (l))
24540Sstevel@tonic-gate 
24550Sstevel@tonic-gate /* from OS level to Dx mask */
24560Sstevel@tonic-gate #define	USB_DEV_PWRMASK(l)	(1 << (USB_DEV_OS_FULL_PWR - (l)))
24570Sstevel@tonic-gate 
24580Sstevel@tonic-gate /* Macro to check valid power level */
24590Sstevel@tonic-gate #define	USB_DEV_PWRSTATE_OK(state, level) \
24600Sstevel@tonic-gate 		(((state) & USB_DEV_PWRMASK((level))) == 0)
24610Sstevel@tonic-gate 
24620Sstevel@tonic-gate int usb_handle_remote_wakeup(
24630Sstevel@tonic-gate 	dev_info_t	*dip,
24640Sstevel@tonic-gate 	int		cmd);
24650Sstevel@tonic-gate 
24660Sstevel@tonic-gate /* argument to usb_handle_remote wakeup function */
24670Sstevel@tonic-gate #define	USB_REMOTE_WAKEUP_ENABLE	1
24680Sstevel@tonic-gate #define	USB_REMOTE_WAKEUP_DISABLE	2
24690Sstevel@tonic-gate 
24700Sstevel@tonic-gate int usb_create_pm_components(
24710Sstevel@tonic-gate 	dev_info_t	*dip,
24720Sstevel@tonic-gate 	uint_t		*pwrstates);
24730Sstevel@tonic-gate 
24740Sstevel@tonic-gate /*
24750Sstevel@tonic-gate  * ***************************************************************************
24760Sstevel@tonic-gate  * System event registration
24770Sstevel@tonic-gate  * ***************************************************************************
24780Sstevel@tonic-gate  */
24790Sstevel@tonic-gate 
24800Sstevel@tonic-gate /* Functions for registering hotplug callback functions. */
24810Sstevel@tonic-gate 
24820Sstevel@tonic-gate int usb_register_hotplug_cbs(
24830Sstevel@tonic-gate 	dev_info_t	*dip,
24840Sstevel@tonic-gate 	int		(*disconnect_event_handler)(dev_info_t *dip),
24850Sstevel@tonic-gate 	int		(*reconnect_event_handler)(dev_info_t *dip));
24860Sstevel@tonic-gate 
24870Sstevel@tonic-gate void usb_unregister_hotplug_cbs(dev_info_t *dip);
24880Sstevel@tonic-gate 
24894844Slg150142 /*
24904844Slg150142  *	Reset_level determines the extent to which the device is reset,
24914844Slg150142  *	It has the following values:
24924844Slg150142  *
24934844Slg150142  *	USB_RESET_LVL_REATTACH	- The device is reset, the original driver is
24944844Slg150142  *				  detached and a new driver attaching process
24954844Slg150142  *				  is started according to the updated
24964844Slg150142  *				  compatible name. This reset level applies to
24974844Slg150142  *				  the firmware download with the descriptors
24984844Slg150142  *				  changing, or other situations in which the
24994844Slg150142  *				  device needs to be reenumerated.
25004844Slg150142  *
25014844Slg150142  *	USB_RESET_LVL_DEFAULT	- Default reset level. The device is reset, all
25024844Slg150142  *				  error status is cleared, the device state
25034844Slg150142  *				  machines and registers are also cleared and
25044844Slg150142  *				  need to be reinitialized in the driver. The
25054844Slg150142  *				  current driver remains attached. This reset
25064844Slg150142  *				  level applies to hardware error recovery, or
25074844Slg150142  *				  firmware download without descriptors
25084844Slg150142  *				  changing.
25094844Slg150142  */
25104844Slg150142 typedef enum {
25114844Slg150142 	USB_RESET_LVL_REATTACH		= 0,
25124844Slg150142 	USB_RESET_LVL_DEFAULT		= 1
25134844Slg150142 } usb_dev_reset_lvl_t;
25144844Slg150142 
25154844Slg150142 /*
25164844Slg150142  * usb_reset_device:
25174844Slg150142  *
25184844Slg150142  * Client drivers call this function to request hardware reset for themselves,
25194844Slg150142  * which may be required in some situations such as:
25204844Slg150142  *
25214844Slg150142  * 1) Some USB devices need the driver to upload firmware into devices' RAM
25224844Slg150142  *    and initiate a hardware reset in order to activate the new firmware.
25234844Slg150142  * 2) Hardware reset may help drivers to recover devices from an error state
25244844Slg150142  *    caused by physical or firmware defects.
25254844Slg150142  *
25264844Slg150142  * Arguments:
25274844Slg150142  *	dip		    - pointer to devinfo of the client
25284844Slg150142  *	reset_level	    - see above
25294844Slg150142  *
25304844Slg150142  * Return values:
25314844Slg150142  *	USB_SUCCESS	    - With USB_RESET_LVL_DEFAULT: the device was reset
25324844Slg150142  *			      successfully.
25334844Slg150142  *			    - With USB_RESET_LVL_REATTACH: reenumeration was
25344844Slg150142  *			      started successfully or a previous reset is still
25354844Slg150142  *			      in progress.
25364844Slg150142  *	USB_FAILURE	    - The state of the device's parent hub is invalid
25374844Slg150142  *			      (disconnected or suspended).
25384844Slg150142  *			    - Called when the driver being detached.
25394844Slg150142  *			    - The device failed to be reset with
25404844Slg150142  *			      USB_RESET_LVL_DEFAULT specified.
25414844Slg150142  *			    - Reenumeration failed to start up with
25424844Slg150142  *			    - USB_RESET_LVL_REATTACH specified.
25434844Slg150142  *	USB_INVALID_ARGS    - Invalid arguments.
25444844Slg150142  *	USB_INVALID_PERM    - The driver of the dip doesn't own entire device.
25454844Slg150142  *	USB_BUSY	    - One or more pipes other than the default control
25464844Slg150142  *			      pipe are open on the device with
25474844Slg150142  *			      USB_RESET_LVL_DEFAULT specified.
25484844Slg150142  *	USB_INVALID_CONTEXT - Called from interrupt context with
25494844Slg150142  *			      USB_RESET_LVL_DEFAULT specified.
25504844Slg150142  */
25514844Slg150142 
25524844Slg150142 int usb_reset_device(
25534844Slg150142 	dev_info_t 		*dip,
25544844Slg150142 	usb_dev_reset_lvl_t	reset_level);
25554844Slg150142 
25560Sstevel@tonic-gate 
25570Sstevel@tonic-gate /*
2558*10316SStrony.Zhang@Sun.COM  * **************************************************************************
2559*10316SStrony.Zhang@Sun.COM  * USB device driver registration and callback functions remaining
2560*10316SStrony.Zhang@Sun.COM  * Contracted Project Private (for VirtualBox USB Device Capture)
2561*10316SStrony.Zhang@Sun.COM  * **************************************************************************
2562*10316SStrony.Zhang@Sun.COM  */
2563*10316SStrony.Zhang@Sun.COM 
2564*10316SStrony.Zhang@Sun.COM /*
2565*10316SStrony.Zhang@Sun.COM  * getting the device strings of manufacturer, product and serial number
2566*10316SStrony.Zhang@Sun.COM  */
2567*10316SStrony.Zhang@Sun.COM typedef struct usb_dev_str {
2568*10316SStrony.Zhang@Sun.COM 	char	*usb_mfg;	/* manufacturer string */
2569*10316SStrony.Zhang@Sun.COM 	char	*usb_product;	/* product string */
2570*10316SStrony.Zhang@Sun.COM 	char	*usb_serialno;	/* serial number string */
2571*10316SStrony.Zhang@Sun.COM } usb_dev_str_t;
2572*10316SStrony.Zhang@Sun.COM 
2573*10316SStrony.Zhang@Sun.COM /*
2574*10316SStrony.Zhang@Sun.COM  * It is the callback function type for capture driver.
2575*10316SStrony.Zhang@Sun.COM  * Arguments:
2576*10316SStrony.Zhang@Sun.COM  *	dev_descr	- pointer to device descriptor
2577*10316SStrony.Zhang@Sun.COM  *	dev_str		- pointer to device strings
2578*10316SStrony.Zhang@Sun.COM  *	path		- pointer to device physical path
2579*10316SStrony.Zhang@Sun.COM  *	bus		- USB bus address
2580*10316SStrony.Zhang@Sun.COM  *	port		- USB port number
2581*10316SStrony.Zhang@Sun.COM  *	drv		- capture driver name.
2582*10316SStrony.Zhang@Sun.COM  *			  It is returned by the callback func.
2583*10316SStrony.Zhang@Sun.COM  * Return Values:
2584*10316SStrony.Zhang@Sun.COM  *      USB_SUCCESS     - VirtualBox will capture the device
2585*10316SStrony.Zhang@Sun.COM  *      USB_FAILURE     - VirtualBox will not capture the device
2586*10316SStrony.Zhang@Sun.COM  */
2587*10316SStrony.Zhang@Sun.COM typedef int (*usb_dev_driver_callback_t)(
2588*10316SStrony.Zhang@Sun.COM 	usb_dev_descr_t	*dev_descr,
2589*10316SStrony.Zhang@Sun.COM 	usb_dev_str_t	*dev_str,
2590*10316SStrony.Zhang@Sun.COM 	char		*path,
2591*10316SStrony.Zhang@Sun.COM 	int		bus,
2592*10316SStrony.Zhang@Sun.COM 	int		port,
2593*10316SStrony.Zhang@Sun.COM 	char		**drv,
2594*10316SStrony.Zhang@Sun.COM 	void		*reserved);
2595*10316SStrony.Zhang@Sun.COM 
2596*10316SStrony.Zhang@Sun.COM /*
2597*10316SStrony.Zhang@Sun.COM  * Register the callback function in the usba.
2598*10316SStrony.Zhang@Sun.COM  * Argument:
2599*10316SStrony.Zhang@Sun.COM  *	dip		- client driver's devinfo pointer
2600*10316SStrony.Zhang@Sun.COM  *	cb		- callback function
2601*10316SStrony.Zhang@Sun.COM  *
2602*10316SStrony.Zhang@Sun.COM  * Return Values:
2603*10316SStrony.Zhang@Sun.COM  *	USB_SUCCESS	- the registeration was successful
2604*10316SStrony.Zhang@Sun.COM  *	USB_FAILURE	- the registeration failed
2605*10316SStrony.Zhang@Sun.COM  */
2606*10316SStrony.Zhang@Sun.COM int usb_register_dev_driver(
2607*10316SStrony.Zhang@Sun.COM 	dev_info_t			*dip,
2608*10316SStrony.Zhang@Sun.COM 	usb_dev_driver_callback_t	cb);
2609*10316SStrony.Zhang@Sun.COM 
2610*10316SStrony.Zhang@Sun.COM /*
2611*10316SStrony.Zhang@Sun.COM  * Unregister the callback function in the usba.
2612*10316SStrony.Zhang@Sun.COM  */
2613*10316SStrony.Zhang@Sun.COM void usb_unregister_dev_driver(dev_info_t *dip);
2614*10316SStrony.Zhang@Sun.COM 
2615*10316SStrony.Zhang@Sun.COM 
2616*10316SStrony.Zhang@Sun.COM /*
26170Sstevel@tonic-gate  * ***************************************************************************
26180Sstevel@tonic-gate  * USB Device and interface class, subclass and protocol codes
26190Sstevel@tonic-gate  * ***************************************************************************
26200Sstevel@tonic-gate  */
26210Sstevel@tonic-gate 
26220Sstevel@tonic-gate /*
26230Sstevel@tonic-gate  * Available device and interface class codes.
26240Sstevel@tonic-gate  * Those which are device class codes are noted.
26250Sstevel@tonic-gate  */
26260Sstevel@tonic-gate 
26270Sstevel@tonic-gate #define	USB_CLASS_AUDIO		1
26280Sstevel@tonic-gate #define	USB_CLASS_COMM		2	/* Communication device class and */
26290Sstevel@tonic-gate #define	USB_CLASS_CDC_CTRL	2	/* CDC-control iface class, also 2 */
26300Sstevel@tonic-gate #define	USB_CLASS_HID		3
26310Sstevel@tonic-gate #define	USB_CLASS_PHYSICAL	5
26323341Sgc161489 #define	USB_CLASS_IMAGE		6
26330Sstevel@tonic-gate #define	USB_CLASS_PRINTER	7
26340Sstevel@tonic-gate #define	USB_CLASS_MASS_STORAGE	8
26350Sstevel@tonic-gate #define	USB_CLASS_HUB		9	/* Device class */
26360Sstevel@tonic-gate #define	USB_CLASS_CDC_DATA	10
26370Sstevel@tonic-gate #define	USB_CLASS_CCID		11
26380Sstevel@tonic-gate #define	USB_CLASS_SECURITY	13
26393341Sgc161489 #define	USB_CLASS_VIDEO		14
26400Sstevel@tonic-gate #define	USB_CLASS_DIAG		220	/* Device class */
26413341Sgc161489 #define	USB_CLASS_WIRELESS	224
26420Sstevel@tonic-gate #define	USB_CLASS_MISC		239	/* Device class */
26430Sstevel@tonic-gate #define	USB_CLASS_APP		254
26440Sstevel@tonic-gate #define	USB_CLASS_VENDOR_SPEC	255	/* Device class */
26450Sstevel@tonic-gate 
26460Sstevel@tonic-gate #define	USB_CLASS_PER_INTERFACE	0	/* Class info is at interface level */
26470Sstevel@tonic-gate 
26480Sstevel@tonic-gate /* Audio subclass. */
26490Sstevel@tonic-gate #define	USB_SUBCLS_AUD_CONTROL		0x01
26500Sstevel@tonic-gate #define	USB_SUBCLS_AUD_STREAMING	0x02
26510Sstevel@tonic-gate #define	USB_SUBCLS_AUD_MIDI_STREAMING	0x03
26520Sstevel@tonic-gate 
26530Sstevel@tonic-gate /* Comms  subclass. */
26540Sstevel@tonic-gate #define	USB_SUBCLS_CDCC_DIRECT_LINE	0x01
26550Sstevel@tonic-gate #define	USB_SUBCLS_CDCC_ABSTRCT_CTRL	0x02
26560Sstevel@tonic-gate #define	USB_SUBCLS_CDCC_PHONE_CTRL	0x03
26570Sstevel@tonic-gate #define	USB_SUBCLS_CDCC_MULTCNL_ISDN	0x04
26580Sstevel@tonic-gate #define	USB_SUBCLS_CDCC_ISDN		0x05
26590Sstevel@tonic-gate #define	USB_SUBCLS_CDCC_ETHERNET	0x06
26600Sstevel@tonic-gate #define	USB_SUBCLS_CDCC_ATM_NETWORK	0x07
26610Sstevel@tonic-gate 
26620Sstevel@tonic-gate /* HID subclass and protocols. */
26630Sstevel@tonic-gate #define	USB_SUBCLS_HID_1		1
26640Sstevel@tonic-gate 
26650Sstevel@tonic-gate #define	USB_PROTO_HID_KEYBOARD		0x01	/* legacy keyboard */
26660Sstevel@tonic-gate #define	USB_PROTO_HID_MOUSE		0x02	/* legacy mouse */
26670Sstevel@tonic-gate 
26680Sstevel@tonic-gate /* Printer subclass and protocols. */
26690Sstevel@tonic-gate #define	USB_SUBCLS_PRINTER_1		1
26700Sstevel@tonic-gate 
26710Sstevel@tonic-gate #define	USB_PROTO_PRINTER_UNI		0x01	/* Unidirectional interface */
26720Sstevel@tonic-gate #define	USB_PROTO_PRINTER_BI		0x02	/* Bidirectional interface */
26730Sstevel@tonic-gate 
26740Sstevel@tonic-gate /* Mass storage subclasses and protocols. */
26750Sstevel@tonic-gate #define	USB_SUBCLS_MS_RBC_T10		0x1	/* flash */
26760Sstevel@tonic-gate #define	USB_SUBCLS_MS_SFF8020I		0x2	/* CD-ROM */
26770Sstevel@tonic-gate #define	USB_SUBCLS_MS_QIC_157		0x3	/* tape */
26780Sstevel@tonic-gate #define	USB_SUBCLS_MS_UFI		0x4	/* USB Floppy Disk Drive   */
26790Sstevel@tonic-gate #define	USB_SUBCLS_MS_SFF8070I		0x5	/* floppy */
26800Sstevel@tonic-gate #define	USB_SUBCLS_MS_SCSI		0x6	/* transparent scsi */
26810Sstevel@tonic-gate 
26820Sstevel@tonic-gate #define	USB_PROTO_MS_CBI_WC		0x00	/* USB CBI Proto w/cmp intr */
26830Sstevel@tonic-gate #define	USB_PROTO_MS_CBI		0x01    /* USB CBI Protocol */
26840Sstevel@tonic-gate #define	USB_PROTO_MS_ISD_1999_SILICN	0x02    /* ZIP Protocol */
26850Sstevel@tonic-gate #define	USB_PROTO_MS_BULK_ONLY		0x50    /* USB Bulk Only Protocol */
26860Sstevel@tonic-gate 
26870Sstevel@tonic-gate /* Application subclasses. */
26880Sstevel@tonic-gate #define	USB_SUBCLS_APP_FIRMWARE		0x01	/* app spec f/w subclass */
26890Sstevel@tonic-gate #define	USB_SUBCLS_APP_IRDA		0x02	/* app spec IrDa subclass */
26900Sstevel@tonic-gate #define	USB_SUBCLS_APP_TEST		0x03	/* app spec test subclass */
26910Sstevel@tonic-gate 
26923341Sgc161489 /* Video subclasses */
26933341Sgc161489 #define	USB_SUBCLS_VIDEO_CONTROL	0x01	/* video control */
26943341Sgc161489 #define	USB_SUBCLS_VIDEO_STREAM		0x02	/* video stream */
26953341Sgc161489 #define	USB_SUBCLS_VIDEO_COLLECTION	0x03	/* video interface collection */
26960Sstevel@tonic-gate 
26979430SRaymond.Chen@Sun.COM /* Wireless controller subclasses and protocols, refer to WUSB 1.0 chapter 8 */
26989430SRaymond.Chen@Sun.COM #define	USB_SUBCLS_WUSB_1		0x01	/* RF controller */
26999430SRaymond.Chen@Sun.COM #define	USB_SUBCLS_WUSB_2		0x02	/* Wireless adapter */
27003341Sgc161489 #define	USB_PROTO_WUSB_HWA		0x01	/* host wire adapter */
27013341Sgc161489 #define	USB_PROTO_WUSB_DWA		0x02	/* device wire adapter */
27023341Sgc161489 #define	USB_PROTO_WUSB_DWA_ISO		0x03	/* device wire adapter isoc */
27039430SRaymond.Chen@Sun.COM #define	USB_PROTO_WUSB_RC		0x02	/* UWB radio controller */
27049430SRaymond.Chen@Sun.COM 
27059430SRaymond.Chen@Sun.COM /* Association subclass and protocol, Association Model Supplement to WUSB1.0 */
27069430SRaymond.Chen@Sun.COM #define	USB_SUBCLS_CBAF			0x03	/* cable association */
27079430SRaymond.Chen@Sun.COM #define	USB_PROTO_CBAF			0x01	/* CBAF protocol */
27089430SRaymond.Chen@Sun.COM 
27099430SRaymond.Chen@Sun.COM /* Misc subclasses and protocols, refer to WUSB 1.0 chapter 8 */
27109430SRaymond.Chen@Sun.COM #define	USB_SUBCLS_MISC_COMMON		0x02	/* common class */
27119430SRaymond.Chen@Sun.COM #define	USB_PROTO_MISC_WA		0x02	/* multifunction wire adapter */
27120Sstevel@tonic-gate 
27130Sstevel@tonic-gate #ifdef __cplusplus
27140Sstevel@tonic-gate }
27150Sstevel@tonic-gate #endif
27160Sstevel@tonic-gate 
27170Sstevel@tonic-gate #endif /* _SYS_USB_USBAI_H */
2718