xref: /illumos-gate/usr/src/uts/common/sys/usb/usbai.h (revision 0d2006e4)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5b3001defSlg  * Common Development and Distribution License (the "License").
6b3001defSlg  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
20b3001defSlg  */
21b3001defSlg /*
22ff0e937bSRaymond Chen  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
24e2c88f0cSGarrett D'Amore  *
25e2c88f0cSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
26*0d2006e4SRobert Mustacchi  * Copyright 2019 Joyent, Inc.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef	_SYS_USB_USBAI_H
307c478bd9Sstevel@tonic-gate #define	_SYS_USB_USBAI_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
347c478bd9Sstevel@tonic-gate extern "C" {
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
37993e3fafSRobert Mustacchi /* This header file is for USBA2.1 */
387c478bd9Sstevel@tonic-gate #define	USBA_MAJOR_VER 2
39993e3fafSRobert Mustacchi #define	USBA_MINOR_VER 1
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate  * USBAI: Interfaces Between USBA and Client Driver
437c478bd9Sstevel@tonic-gate  *
447c478bd9Sstevel@tonic-gate  *
457c478bd9Sstevel@tonic-gate  * Universal USB device state management :
467c478bd9Sstevel@tonic-gate  *
477c478bd9Sstevel@tonic-gate  *	PWRED_DWN---<3----4>--ONLINE---<2-----1>-DISCONNECTED
487c478bd9Sstevel@tonic-gate  *	    |			 ^		     |
497c478bd9Sstevel@tonic-gate  *	    |			 6		     |
507c478bd9Sstevel@tonic-gate  *	    |			 |		     |
517c478bd9Sstevel@tonic-gate  *	    |			 5		     |
527c478bd9Sstevel@tonic-gate  *	    |			 v		     |
537c478bd9Sstevel@tonic-gate  *	    +----5>----------SUSPENDED----<5----7>---+
547c478bd9Sstevel@tonic-gate  *
557c478bd9Sstevel@tonic-gate  *	1 = Device Unplug
567c478bd9Sstevel@tonic-gate  *	2 = Original Device reconnected
577c478bd9Sstevel@tonic-gate  *	3 = Device idles for time T & transitions to low power state
587c478bd9Sstevel@tonic-gate  *	4 = Remote wakeup by device OR Application kicking off IO to device
597c478bd9Sstevel@tonic-gate  *	5 = Notification to save state prior to DDI_SUSPEND
607c478bd9Sstevel@tonic-gate  *	6 = Notification to restore state after DDI_RESUME with correct device
617c478bd9Sstevel@tonic-gate  *	7 = Notification to restore state after DDI_RESUME with device
627c478bd9Sstevel@tonic-gate  *	    disconnected or a wrong device
637c478bd9Sstevel@tonic-gate  *
647c478bd9Sstevel@tonic-gate  *	NOTE: device states 0x80 to 0xff are device specific and can be
657c478bd9Sstevel@tonic-gate  *		used by client drivers
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate #define	USB_DEV_ONLINE		1	/* device is online */
687c478bd9Sstevel@tonic-gate #define	USB_DEV_DISCONNECTED	2	/* indicates disconnect */
697c478bd9Sstevel@tonic-gate #define	USB_DEV_SUSPENDED	3	/* DDI_SUSPEND operation */
707c478bd9Sstevel@tonic-gate #define	USB_DEV_PWRED_DOWN	4	/* indicates power off state */
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate /*
747c478bd9Sstevel@tonic-gate  * ***************************************************************************
757c478bd9Sstevel@tonic-gate  * USBA error and status definitions
767c478bd9Sstevel@tonic-gate  * ***************************************************************************
777c478bd9Sstevel@tonic-gate  */
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate /*
817c478bd9Sstevel@tonic-gate  * USBA function return values
827c478bd9Sstevel@tonic-gate  */
837c478bd9Sstevel@tonic-gate #define	USB_SUCCESS		0	/* call success			  */
847c478bd9Sstevel@tonic-gate #define	USB_FAILURE		-1	/* unspecified USBA or HCD error  */
857c478bd9Sstevel@tonic-gate #define	USB_NO_RESOURCES	-2	/* no resources available	  */
867c478bd9Sstevel@tonic-gate #define	USB_NO_BANDWIDTH	-3	/* no bandwidth available	  */
877c478bd9Sstevel@tonic-gate #define	USB_NOT_SUPPORTED	-4	/* function not supported by HCD  */
887c478bd9Sstevel@tonic-gate #define	USB_PIPE_ERROR		-5	/* error occured on the pipe	  */
897c478bd9Sstevel@tonic-gate #define	USB_INVALID_PIPE	-6	/* pipe handle passed is invalid  */
907c478bd9Sstevel@tonic-gate #define	USB_NO_FRAME_NUMBER	-7	/* frame No or ASAP not specified */
917c478bd9Sstevel@tonic-gate #define	USB_INVALID_START_FRAME	-8	/* starting USB frame not valid	  */
927c478bd9Sstevel@tonic-gate #define	USB_HC_HARDWARE_ERROR	-9	/* usb host controller error	  */
937c478bd9Sstevel@tonic-gate #define	USB_INVALID_REQUEST	-10	/* request had invalid values	  */
947c478bd9Sstevel@tonic-gate #define	USB_INVALID_CONTEXT	-11	/* sleep flag in interrupt context */
957c478bd9Sstevel@tonic-gate #define	USB_INVALID_VERSION	-12	/* invalid version specified	  */
967c478bd9Sstevel@tonic-gate #define	USB_INVALID_ARGS	-13	/* invalid func args specified	  */
977c478bd9Sstevel@tonic-gate #define	USB_INVALID_PERM	-14	/* privileged operation		  */
987c478bd9Sstevel@tonic-gate #define	USB_BUSY		-15	/* busy condition		  */
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate  * USB request completion flags, more than one may be set.
1037c478bd9Sstevel@tonic-gate  * The following flags are returned after a recovery action by
1047c478bd9Sstevel@tonic-gate  * HCD or USBA (autoclearing) or callbacks from pipe_close,
1057c478bd9Sstevel@tonic-gate  * abort, reset, or stop polling.  More than one may be set.
1067c478bd9Sstevel@tonic-gate  *
1077c478bd9Sstevel@tonic-gate  * For sync requests, the client should check the request structure
1087c478bd9Sstevel@tonic-gate  * for this flag to determine what has happened.
1097c478bd9Sstevel@tonic-gate  *
1107c478bd9Sstevel@tonic-gate  * All callbacks are queued to preserve order.	Note that if a normal callback
1117c478bd9Sstevel@tonic-gate  * uses a kernel thread, order is not guaranteed since each callback may use
1127c478bd9Sstevel@tonic-gate  * its own thread.  The next request will be submitted to the
1137c478bd9Sstevel@tonic-gate  * HCD after the threads exits.
1147c478bd9Sstevel@tonic-gate  *
1157c478bd9Sstevel@tonic-gate  * Exception callbacks using a kernel thread may do auto clearing and no
1167c478bd9Sstevel@tonic-gate  * new request will be started until this thread has completed its work.
1177c478bd9Sstevel@tonic-gate  */
1187c478bd9Sstevel@tonic-gate typedef enum {
1197c478bd9Sstevel@tonic-gate 	USB_CB_NO_INFO		= 0x00, /* no exception */
1207c478bd9Sstevel@tonic-gate 	USB_CB_STALL_CLEARED	= 0x01,	/* func stall cleared */
1217c478bd9Sstevel@tonic-gate 	USB_CB_FUNCTIONAL_STALL	= 0x02,	/* func stall occurred */
1227c478bd9Sstevel@tonic-gate 	USB_CB_PROTOCOL_STALL	= 0x04,	/* protocal stall occurred */
1237c478bd9Sstevel@tonic-gate 	USB_CB_RESET_PIPE	= 0x10, /* pipe was reset */
1247c478bd9Sstevel@tonic-gate 	USB_CB_ASYNC_REQ_FAILED = 0x80, /* thread couldn't be started */
1257c478bd9Sstevel@tonic-gate 	USB_CB_NO_RESOURCES	= 0x100, /* no resources */
1267c478bd9Sstevel@tonic-gate 	USB_CB_SUBMIT_FAILED	= 0x200, /* req was queued then submitted */
1277c478bd9Sstevel@tonic-gate 					/* to HCD which rejected it */
1287c478bd9Sstevel@tonic-gate 	USB_CB_INTR_CONTEXT	= 0x400 /* Callback is in interrupt context. */
1297c478bd9Sstevel@tonic-gate } usb_cb_flags_t;
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate /*
1337c478bd9Sstevel@tonic-gate  * completion reason
1347c478bd9Sstevel@tonic-gate  *
1357c478bd9Sstevel@tonic-gate  * Set by HCD; only one can be set.
1367c478bd9Sstevel@tonic-gate  */
1377c478bd9Sstevel@tonic-gate typedef enum {
1387c478bd9Sstevel@tonic-gate 	USB_CR_OK		= 0,	/* no errors detected		*/
1397c478bd9Sstevel@tonic-gate 	USB_CR_CRC		= 1,	/* crc error detected		*/
1407c478bd9Sstevel@tonic-gate 	USB_CR_BITSTUFFING	= 2,	/* bit stuffing violation	*/
1417c478bd9Sstevel@tonic-gate 	USB_CR_DATA_TOGGLE_MM	= 3,	/* d/t PID did not match	*/
1427c478bd9Sstevel@tonic-gate 	USB_CR_STALL		= 4,	/* e/p returned stall PID	*/
1437c478bd9Sstevel@tonic-gate 	USB_CR_DEV_NOT_RESP	= 5,	/* device not responding	*/
1447c478bd9Sstevel@tonic-gate 	USB_CR_PID_CHECKFAILURE = 6,	/* check bits on PID failed	*/
1457c478bd9Sstevel@tonic-gate 	USB_CR_UNEXP_PID	= 7,	/* receive PID was not valid	*/
1467c478bd9Sstevel@tonic-gate 	USB_CR_DATA_OVERRUN	= 8,	/* data size exceeded		*/
1477c478bd9Sstevel@tonic-gate 	USB_CR_DATA_UNDERRUN	= 9,	/* less data received		*/
1487c478bd9Sstevel@tonic-gate 	USB_CR_BUFFER_OVERRUN	= 10,	/* memory write can't keep up	*/
1497c478bd9Sstevel@tonic-gate 	USB_CR_BUFFER_UNDERRUN	= 11,	/* buffer underrun		*/
1507c478bd9Sstevel@tonic-gate 	USB_CR_TIMEOUT		= 12,	/* command timed out		*/
1517c478bd9Sstevel@tonic-gate 	USB_CR_NOT_ACCESSED	= 13,	/* Not accessed by hardware	*/
1527c478bd9Sstevel@tonic-gate 	USB_CR_NO_RESOURCES	= 14,	/* no resources			*/
1537c478bd9Sstevel@tonic-gate 	USB_CR_UNSPECIFIED_ERR	= 15,	/* unspecified usba or hcd err	*/
1547c478bd9Sstevel@tonic-gate 	USB_CR_STOPPED_POLLING	= 16,	/* intr/isoc IN polling stopped	*/
1557c478bd9Sstevel@tonic-gate 	USB_CR_PIPE_CLOSING	= 17,	/* intr/isoc IN pipe closed	*/
1567c478bd9Sstevel@tonic-gate 	USB_CR_PIPE_RESET	= 18,	/* intr/isoc IN pipe reset	*/
1577c478bd9Sstevel@tonic-gate 	USB_CR_NOT_SUPPORTED	= 19,	/* command not supported	*/
1587c478bd9Sstevel@tonic-gate 	USB_CR_FLUSHED		= 20,	/* this request was flushed	*/
1597c478bd9Sstevel@tonic-gate 	USB_CR_HC_HARDWARE_ERR	= 21	/* usb host controller error	*/
1607c478bd9Sstevel@tonic-gate } usb_cr_t;
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate /*
1647c478bd9Sstevel@tonic-gate  * ***************************************************************************
1657c478bd9Sstevel@tonic-gate  * General definitions, used all over
1667c478bd9Sstevel@tonic-gate  * ***************************************************************************
1677c478bd9Sstevel@tonic-gate  *
1687c478bd9Sstevel@tonic-gate  *	A pipe handle is returned by usb_pipe_open() on success for
1697c478bd9Sstevel@tonic-gate  *	all pipes except the default pipe which is accessed from
1707c478bd9Sstevel@tonic-gate  *	the registration structure.  Placed here as forward referenced by
1717c478bd9Sstevel@tonic-gate  *	usb_client_dev_data_t below.
1727c478bd9Sstevel@tonic-gate  *
1737c478bd9Sstevel@tonic-gate  *	The pipe_handle is opaque to the client driver.
1747c478bd9Sstevel@tonic-gate  */
1757c478bd9Sstevel@tonic-gate typedef	struct usb_pipe_handle	*usb_pipe_handle_t;
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate /*
1787c478bd9Sstevel@tonic-gate  * General opaque pointer.
1797c478bd9Sstevel@tonic-gate  */
1807c478bd9Sstevel@tonic-gate typedef struct usb_opaque *usb_opaque_t;
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate /*
1847c478bd9Sstevel@tonic-gate  * USB flags argument to USBA interfaces
1857c478bd9Sstevel@tonic-gate  */
1867c478bd9Sstevel@tonic-gate typedef enum {
1877c478bd9Sstevel@tonic-gate 	/* do not block until resources are available */
1887c478bd9Sstevel@tonic-gate 	USB_FLAGS_NOSLEEP		= 0x0000,
1897c478bd9Sstevel@tonic-gate 	/* block until resources are available */
1907c478bd9Sstevel@tonic-gate 	USB_FLAGS_SLEEP			= 0x0100,
1917c478bd9Sstevel@tonic-gate 	/* reserved */
1927c478bd9Sstevel@tonic-gate 	USB_FLAGS_RESERVED		= 0xFE00
1937c478bd9Sstevel@tonic-gate } usb_flags_t;
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate /*
1977c478bd9Sstevel@tonic-gate  * ***************************************************************************
198993e3fafSRobert Mustacchi  * Descriptor definitions (USB version and section noted with structure)
1997c478bd9Sstevel@tonic-gate  * ***************************************************************************
2007c478bd9Sstevel@tonic-gate  */
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate /*
2047c478bd9Sstevel@tonic-gate  * USB Descriptor Management
2057c478bd9Sstevel@tonic-gate  *
2067c478bd9Sstevel@tonic-gate  * Standard USB descriptors:
2077c478bd9Sstevel@tonic-gate  *
2087c478bd9Sstevel@tonic-gate  * USB devices present their configuration information in response to
2097c478bd9Sstevel@tonic-gate  * a GET_DESCRIPTOR request in a form which is little-endian and,
2107c478bd9Sstevel@tonic-gate  * for multibyte integers, unaligned.  It is also position-dependent,
2117c478bd9Sstevel@tonic-gate  * which makes non-sequential access to particular interface or
2127c478bd9Sstevel@tonic-gate  * endpoint data inconvenient.
2137c478bd9Sstevel@tonic-gate  * A GET_DESCRIPTOR request may yield a chunk of data that contains
2147c478bd9Sstevel@tonic-gate  * multiple descriptor types.  For example, a GET_DESCRIPTOR request
2157c478bd9Sstevel@tonic-gate  * for a CONFIGURATION descriptor could return the configuration
2167c478bd9Sstevel@tonic-gate  * descriptor followed by an interface descriptor and the relevant
2177c478bd9Sstevel@tonic-gate  * endpoint descriptors.
2187c478bd9Sstevel@tonic-gate  *
2197c478bd9Sstevel@tonic-gate  * usb_get_dev_data() interface provides an easy way to get all
2207c478bd9Sstevel@tonic-gate  * the descriptors and avoids parsing standard descriptors by each
2217c478bd9Sstevel@tonic-gate  * client driver
2227c478bd9Sstevel@tonic-gate  *
2237c478bd9Sstevel@tonic-gate  * usb_dev_descr:
2247c478bd9Sstevel@tonic-gate  *	usb device descriptor, refer to	USB 2.0/9.6.1,
2257c478bd9Sstevel@tonic-gate  */
2267c478bd9Sstevel@tonic-gate typedef struct usb_dev_descr {
2277c478bd9Sstevel@tonic-gate 	uint8_t		bLength;	/* descriptor size		*/
2287c478bd9Sstevel@tonic-gate 	uint8_t		bDescriptorType; /* set to DEVICE		*/
2297c478bd9Sstevel@tonic-gate 	uint16_t	bcdUSB;		/* USB spec rel. number	in bcd	*/
2307c478bd9Sstevel@tonic-gate 	uint8_t		bDeviceClass;	/* class code			*/
2317c478bd9Sstevel@tonic-gate 	uint8_t		bDeviceSubClass; /* sub	class code		*/
2327c478bd9Sstevel@tonic-gate 	uint8_t		bDeviceProtocol; /* protocol code		*/
2337c478bd9Sstevel@tonic-gate 	uint8_t		bMaxPacketSize0; /* max	pkt size of e/p	0	*/
2347c478bd9Sstevel@tonic-gate 	uint16_t	idVendor;	/* vendor ID			*/
2357c478bd9Sstevel@tonic-gate 	uint16_t	idProduct;	/* product ID			*/
2367c478bd9Sstevel@tonic-gate 	uint16_t	bcdDevice;	/* device release number in bcd	*/
2377c478bd9Sstevel@tonic-gate 	uint8_t		iManufacturer;	/* manufacturing string		*/
2387c478bd9Sstevel@tonic-gate 	uint8_t		iProduct;	/* product string		*/
2397c478bd9Sstevel@tonic-gate 	uint8_t		iSerialNumber;	/* serial number string index	*/
2407c478bd9Sstevel@tonic-gate 	uint8_t		bNumConfigurations; /* #configs for device	*/
2417c478bd9Sstevel@tonic-gate } usb_dev_descr_t;
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate /*
2457c478bd9Sstevel@tonic-gate  * USB Device Qualifier Descriptor
2467c478bd9Sstevel@tonic-gate  *
2477c478bd9Sstevel@tonic-gate  * The device_qualifier descriptor describes information about a High
2487c478bd9Sstevel@tonic-gate  * speed capable device that would change if the device were operating
2497c478bd9Sstevel@tonic-gate  * at other (Full) speed. Example: if the device is currently operating
2507c478bd9Sstevel@tonic-gate  * at Full-speed, the device_qualifier returns information about how if
2517c478bd9Sstevel@tonic-gate  * would operate at high-speed and vice-versa.
2527c478bd9Sstevel@tonic-gate  *
2537c478bd9Sstevel@tonic-gate  * usb_dev_qlf_descr:
2547c478bd9Sstevel@tonic-gate  *
2557c478bd9Sstevel@tonic-gate  *	usb device qualifier descriptor, refer to USB 2.0/9.6.2
2567c478bd9Sstevel@tonic-gate  */
2577c478bd9Sstevel@tonic-gate typedef struct usb_dev_qlf_descr {
2587c478bd9Sstevel@tonic-gate 	uint8_t		bLength;	/* descriptor size		*/
2597c478bd9Sstevel@tonic-gate 	uint8_t		bDescriptorType; /* set to DEVICE		*/
2607c478bd9Sstevel@tonic-gate 	uint16_t	bcdUSB;		/* USB spec rel. number	in bcd	*/
2617c478bd9Sstevel@tonic-gate 	uint8_t		bDeviceClass;	/* class code			*/
2627c478bd9Sstevel@tonic-gate 	uint8_t		bDeviceSubClass; /* sub	class code		*/
2637c478bd9Sstevel@tonic-gate 	uint8_t		bDeviceProtocol; /* protocol code		*/
2647c478bd9Sstevel@tonic-gate 	uint8_t		bMaxPacketSize0; /* max	pkt size of e/p	0	*/
2657c478bd9Sstevel@tonic-gate 	uint8_t		bNumConfigurations; /* #configs for device	*/
2667c478bd9Sstevel@tonic-gate 	uint8_t		bReserved;	/* reserved field		*/
2677c478bd9Sstevel@tonic-gate } usb_dev_qlf_descr_t;
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate /*
2717c478bd9Sstevel@tonic-gate  * usb_cfg_descr:
2727c478bd9Sstevel@tonic-gate  *	usb configuration descriptor, refer to USB 2.0/9.6.3
2737c478bd9Sstevel@tonic-gate  */
2747c478bd9Sstevel@tonic-gate typedef struct usb_cfg_descr {
2757c478bd9Sstevel@tonic-gate 	uint8_t		bLength;	/* descriptor size		*/
2767c478bd9Sstevel@tonic-gate 	uint8_t		bDescriptorType; /* set to CONFIGURATION	*/
2777c478bd9Sstevel@tonic-gate 	uint16_t	wTotalLength;	/* total length of data returned */
2787c478bd9Sstevel@tonic-gate 	uint8_t		bNumInterfaces;	/* # interfaces	in config	*/
2797c478bd9Sstevel@tonic-gate 	uint8_t		bConfigurationValue; /* arg for SetConfiguration */
2807c478bd9Sstevel@tonic-gate 	uint8_t		iConfiguration;	/* configuration string		*/
2817c478bd9Sstevel@tonic-gate 	uint8_t		bmAttributes;	/* config characteristics	*/
2827c478bd9Sstevel@tonic-gate 	uint8_t		bMaxPower;	/* max pwr consumption		*/
2837c478bd9Sstevel@tonic-gate } usb_cfg_descr_t;
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate /*
2867c478bd9Sstevel@tonic-gate  * Default configuration index setting for devices with multiple
2877c478bd9Sstevel@tonic-gate  * configurations. Note the distinction between config index and config
2887c478bd9Sstevel@tonic-gate  * number
2897c478bd9Sstevel@tonic-gate  */
2907c478bd9Sstevel@tonic-gate #define	USB_DEV_DEFAULT_CONFIG_INDEX	0
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate /*
2937c478bd9Sstevel@tonic-gate  * bmAttribute values for Configuration Descriptor
2947c478bd9Sstevel@tonic-gate  */
2957c478bd9Sstevel@tonic-gate #define	USB_CFG_ATTR_SELFPWR		0x40
2967c478bd9Sstevel@tonic-gate #define	USB_CFG_ATTR_REMOTE_WAKEUP	0x20
297ff0e937bSRaymond Chen #define	USB_CFG_ATTR_BAT_PWR		0x10
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate /*
3007c478bd9Sstevel@tonic-gate  * USB Other Speed Configuration Descriptor
3017c478bd9Sstevel@tonic-gate  *
3027c478bd9Sstevel@tonic-gate  * The other_speed_configuration descriptor describes a configuration of
3037c478bd9Sstevel@tonic-gate  * a High speed capable device if it were operating at its other possible
3047c478bd9Sstevel@tonic-gate  * (Full) speed and vice-versa.
3057c478bd9Sstevel@tonic-gate  *
3067c478bd9Sstevel@tonic-gate  * usb_other_speed_cfg_descr:
3077c478bd9Sstevel@tonic-gate  *	usb other speed configuration descriptor, refer to USB 2.0/9.6.4
3087c478bd9Sstevel@tonic-gate  */
3097c478bd9Sstevel@tonic-gate typedef struct usb_other_speed_cfg_descr {
3107c478bd9Sstevel@tonic-gate 	uint8_t		bLength;	/* descriptor size		*/
3117c478bd9Sstevel@tonic-gate 	uint8_t		bDescriptorType; /* set to CONFIGURATION	*/
3127c478bd9Sstevel@tonic-gate 	uint16_t	wTotalLength;	/* total length of data returned */
3137c478bd9Sstevel@tonic-gate 	uint8_t		bNumInterfaces;	/* # interfaces	in config	*/
3147c478bd9Sstevel@tonic-gate 	uint8_t		bConfigurationValue; /* arg for SetConfiguration */
3157c478bd9Sstevel@tonic-gate 	uint8_t		iConfiguration;	/* configuration string		*/
3167c478bd9Sstevel@tonic-gate 	uint8_t		bmAttributes;	/* config characteristics	*/
3177c478bd9Sstevel@tonic-gate 	uint8_t		bMaxPower;	/* max pwr consumption		*/
3187c478bd9Sstevel@tonic-gate } usb_other_speed_cfg_descr_t;
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 
321d73ae94eSgc /*
322d73ae94eSgc  * usb_ia_descr:
323d73ae94eSgc  *	usb interface association descriptor, refer to USB 2.0 ECN(IAD)
324d73ae94eSgc  */
325d73ae94eSgc typedef  struct usb_ia_descr {
326d73ae94eSgc 	uint8_t		bLength;		/* descriptor size	*/
327d73ae94eSgc 	uint8_t		bDescriptorType;	/* INTERFACE_ASSOCIATION */
328d73ae94eSgc 	uint8_t		bFirstInterface;	/* 1st interface number */
329d73ae94eSgc 	uint8_t		bInterfaceCount;	/* number of interfaces */
330d73ae94eSgc 	uint8_t		bFunctionClass;		/* class code		*/
331d73ae94eSgc 	uint8_t		bFunctionSubClass;	/* sub class code	*/
332d73ae94eSgc 	uint8_t		bFunctionProtocol;	/* protocol code	*/
333d73ae94eSgc 	uint8_t		iFunction;		/* description string	*/
334d73ae94eSgc } usb_ia_descr_t;
335d73ae94eSgc 
336d73ae94eSgc 
3377c478bd9Sstevel@tonic-gate /*
3387c478bd9Sstevel@tonic-gate  * usb_if_descr:
3397c478bd9Sstevel@tonic-gate  *	usb interface descriptor, refer	to USB 2.0/9.6.5
3407c478bd9Sstevel@tonic-gate  */
3417c478bd9Sstevel@tonic-gate typedef  struct usb_if_descr {
3427c478bd9Sstevel@tonic-gate 	uint8_t		bLength;		/* descriptor size	*/
3437c478bd9Sstevel@tonic-gate 	uint8_t		bDescriptorType;	/* set to INTERFACE	*/
3447c478bd9Sstevel@tonic-gate 	uint8_t		bInterfaceNumber;	/* interface number	*/
3457c478bd9Sstevel@tonic-gate 	uint8_t		bAlternateSetting;	/* alt. interface number */
3467c478bd9Sstevel@tonic-gate 	uint8_t		bNumEndpoints;		/* # of endpoints	*/
3477c478bd9Sstevel@tonic-gate 	uint8_t		bInterfaceClass;	/* class code		*/
3487c478bd9Sstevel@tonic-gate 	uint8_t		bInterfaceSubClass;	/* sub class code	*/
3497c478bd9Sstevel@tonic-gate 	uint8_t		bInterfaceProtocol;	/* protocol code	*/
3507c478bd9Sstevel@tonic-gate 	uint8_t		iInterface;		/* description string	*/
3517c478bd9Sstevel@tonic-gate } usb_if_descr_t;
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate /*
3557c478bd9Sstevel@tonic-gate  * usb_ep_descr:
3567c478bd9Sstevel@tonic-gate  *	usb endpoint descriptor, refer to USB 2.0/9.6.6
3577c478bd9Sstevel@tonic-gate  */
3587c478bd9Sstevel@tonic-gate typedef struct usb_ep_descr {
3597c478bd9Sstevel@tonic-gate 	uint8_t		bLength;		/* descriptor size	*/
3607c478bd9Sstevel@tonic-gate 	uint8_t		bDescriptorType;	/* set to ENDPOINT	*/
3617c478bd9Sstevel@tonic-gate 	uint8_t		bEndpointAddress;	/* address of this e/p */
3627c478bd9Sstevel@tonic-gate 	uint8_t		bmAttributes;		/* transfer type	*/
3637c478bd9Sstevel@tonic-gate 	uint16_t	wMaxPacketSize;		/* maximum packet size	*/
3647c478bd9Sstevel@tonic-gate 	uint8_t		bInterval;		/* e/p polling interval */
3657c478bd9Sstevel@tonic-gate } usb_ep_descr_t;
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate /*
3687c478bd9Sstevel@tonic-gate  * bEndpointAddress masks
3697c478bd9Sstevel@tonic-gate  */
3707c478bd9Sstevel@tonic-gate #define	USB_EP_NUM_MASK		0x0F		/* endpoint number mask */
3717c478bd9Sstevel@tonic-gate #define	USB_EP_DIR_MASK		0x80		/* direction mask */
3727c478bd9Sstevel@tonic-gate #define	USB_EP_DIR_OUT		0x00		/* OUT endpoint */
3737c478bd9Sstevel@tonic-gate #define	USB_EP_DIR_IN		0x80		/* IN endpoint */
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate /*
3767c478bd9Sstevel@tonic-gate  * bmAttribute transfer types for endpoints
3777c478bd9Sstevel@tonic-gate  */
3787c478bd9Sstevel@tonic-gate #define	USB_EP_ATTR_MASK	0x03		/* transfer type mask */
3797c478bd9Sstevel@tonic-gate #define	USB_EP_ATTR_CONTROL	0x00		/* control transfer */
3807c478bd9Sstevel@tonic-gate #define	USB_EP_ATTR_ISOCH	0x01		/* isochronous transfer */
3817c478bd9Sstevel@tonic-gate #define	USB_EP_ATTR_BULK	0x02		/* bulk transfer */
3827c478bd9Sstevel@tonic-gate #define	USB_EP_ATTR_INTR	0x03		/* interrupt transfer */
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate /*
3857c478bd9Sstevel@tonic-gate  * bmAttribute synchronization types for endpoints (isochronous only)
3867c478bd9Sstevel@tonic-gate  */
3877c478bd9Sstevel@tonic-gate #define	USB_EP_SYNC_MASK	0x0C		/* synchronization mask */
3887c478bd9Sstevel@tonic-gate #define	USB_EP_SYNC_NONE	0x00		/* no synchronization */
3897c478bd9Sstevel@tonic-gate #define	USB_EP_SYNC_ASYNC	0x04		/* asynchronous */
3907c478bd9Sstevel@tonic-gate #define	USB_EP_SYNC_ADPT	0x08		/* adaptive */
3917c478bd9Sstevel@tonic-gate #define	USB_EP_SYNC_SYNC	0x0C		/* synchronous */
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate /*
3947c478bd9Sstevel@tonic-gate  * bmAttribute synchronization feedback types for endpoints (isochronous only)
3957c478bd9Sstevel@tonic-gate  */
3967c478bd9Sstevel@tonic-gate #define	USB_EP_USAGE_MASK	0x30		/* sync feedback mask */
3977c478bd9Sstevel@tonic-gate #define	USB_EP_USAGE_DATA	0x00		/* data endpoint */
3987c478bd9Sstevel@tonic-gate #define	USB_EP_USAGE_FEED	0x10		/* feedback endpoint */
3997c478bd9Sstevel@tonic-gate #define	USB_EP_USAGE_IMPL	0x20		/* implicit feedback endpoint */
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate /*
4027c478bd9Sstevel@tonic-gate  * wMaxPacketSize values for endpoints (isoch and interrupt, high speed only)
4037c478bd9Sstevel@tonic-gate  */
404993e3fafSRobert Mustacchi #define	USB_EP_MAX_PKTSZ_MASK	0x07FF		/* Mask for packetsize bits */
405993e3fafSRobert Mustacchi #define	USB_EP_MAX_XACTS_MASK	0x1800		/* Max Transactns/microframe */
406993e3fafSRobert Mustacchi #define	USB_EP_MAX_XACTS_SHIFT	11		/* Above is 10 bits from end */
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate /*
4097c478bd9Sstevel@tonic-gate  * Ranges for endpoint parameter values.
4107c478bd9Sstevel@tonic-gate  */
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate /* Min and Max NAK rates for high sped control endpoints. */
4137c478bd9Sstevel@tonic-gate #define	USB_EP_MIN_HIGH_CONTROL_INTRVL	0
4147c478bd9Sstevel@tonic-gate #define	USB_EP_MAX_HIGH_CONTROL_INTRVL	255
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate /* Min and Max NAK rates for high speed bulk endpoints. */
4177c478bd9Sstevel@tonic-gate #define	USB_EP_MIN_HIGH_BULK_INTRVL	0
4187c478bd9Sstevel@tonic-gate #define	USB_EP_MAX_HIGH_BULK_INTRVL	255
4197c478bd9Sstevel@tonic-gate 
4207c478bd9Sstevel@tonic-gate /* Min and Max polling intervals for low, full speed interrupt endpoints. */
4217c478bd9Sstevel@tonic-gate #define	USB_EP_MIN_LOW_INTR_INTRVL	1
4227c478bd9Sstevel@tonic-gate #define	USB_EP_MAX_LOW_INTR_INTRVL	255
4237c478bd9Sstevel@tonic-gate #define	USB_EP_MIN_FULL_INTR_INTRVL	1
4247c478bd9Sstevel@tonic-gate #define	USB_EP_MAX_FULL_INTR_INTRVL	255
4257c478bd9Sstevel@tonic-gate 
4267c478bd9Sstevel@tonic-gate /*
4277c478bd9Sstevel@tonic-gate  * Min and Max polling intervals for high speed interrupt endpoints, and for
4287c478bd9Sstevel@tonic-gate  * isochronous endpoints.
4297c478bd9Sstevel@tonic-gate  * Note that the interval is 2**(value-1).  See Section 9.6.6 of USB 2.0 spec.
4307c478bd9Sstevel@tonic-gate  */
4317c478bd9Sstevel@tonic-gate #define	USB_EP_MIN_HIGH_INTR_INTRVL	1
4327c478bd9Sstevel@tonic-gate #define	USB_EP_MAX_HIGH_INTR_INTRVL	16
4337c478bd9Sstevel@tonic-gate #define	USB_EP_MIN_FULL_ISOCH_INTRVL	1
4347c478bd9Sstevel@tonic-gate #define	USB_EP_MAX_FULL_ISOCH_INTRVL	16
4357c478bd9Sstevel@tonic-gate #define	USB_EP_MIN_HIGH_ISOCH_INTRVL	1
4367c478bd9Sstevel@tonic-gate #define	USB_EP_MAX_HIGH_ISOCH_INTRVL	16
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate /*
4397c478bd9Sstevel@tonic-gate  * usb_string_descr:
4407c478bd9Sstevel@tonic-gate  *	usb string descriptor, refer to	 USB 2.0/9.6.7
4417c478bd9Sstevel@tonic-gate  */
4427c478bd9Sstevel@tonic-gate typedef struct usb_string_descr {
4437c478bd9Sstevel@tonic-gate 	uint8_t		bLength;		/* descr size */
4447c478bd9Sstevel@tonic-gate 	uint8_t		bDescriptorType;	/* set to STRING */
4457c478bd9Sstevel@tonic-gate 	uint8_t		bString[1];		/* variable length unicode */
4467c478bd9Sstevel@tonic-gate 						/* encoded string	*/
4477c478bd9Sstevel@tonic-gate } usb_string_descr_t;
4487c478bd9Sstevel@tonic-gate 
4497c478bd9Sstevel@tonic-gate #define	USB_MAXSTRINGLEN	255		/* max string descr length */
4507c478bd9Sstevel@tonic-gate 
451993e3fafSRobert Mustacchi /*
452993e3fafSRobert Mustacchi  * usb_ep_ss_comp_descr:
453993e3fafSRobert Mustacchi  * 	USB SuperSpeed endpoints are required to return this descriptor along
454993e3fafSRobert Mustacchi  * 	with the general endpoint descriptor. Refer to USB 3.1/9.6.7.
455993e3fafSRobert Mustacchi  */
456993e3fafSRobert Mustacchi typedef struct usb_ep_ss_comp_descr {
457993e3fafSRobert Mustacchi 	uint8_t		bLength;		/* descriptor size */
458993e3fafSRobert Mustacchi 	uint8_t		bDescriptorType;	/* USB_DESCR_TYPE_SS_EP_COMP */
459993e3fafSRobert Mustacchi 	uint8_t		bMaxBurst;		/* max packets per burst */
460993e3fafSRobert Mustacchi 	uint8_t		bmAttributes;		/* more endpoint attributes */
461993e3fafSRobert Mustacchi 	uint16_t	wBytesPerInterval;	/* bytes per service interval */
462993e3fafSRobert Mustacchi } usb_ep_ss_comp_descr_t;
463993e3fafSRobert Mustacchi 
464993e3fafSRobert Mustacchi #define	USB_EP_SS_COMP_ISOC_MULT_MASK	0x03
465993e3fafSRobert Mustacchi 
4667c478bd9Sstevel@tonic-gate /*
4677c478bd9Sstevel@tonic-gate  * ***************************************************************************
4687c478bd9Sstevel@tonic-gate  * Client driver registration with USBA
4697c478bd9Sstevel@tonic-gate  * ***************************************************************************
4707c478bd9Sstevel@tonic-gate  *
4717c478bd9Sstevel@tonic-gate  *	The client registers with USBA during attach in two steps
4727c478bd9Sstevel@tonic-gate  *	using usb_client_attach() and usb_get_dev_data(). On completion, the
4737c478bd9Sstevel@tonic-gate  *	registration data has been initialized.  Most data items are
4747c478bd9Sstevel@tonic-gate  *	straightforward.  Among the items returned in the data is the tree of
4757c478bd9Sstevel@tonic-gate  *	parsed descriptors, in dev_cfg;	 the number of configurations parsed,
4767c478bd9Sstevel@tonic-gate  *	in dev_n_cfg; a pointer to the current configuration in the tree,
4777c478bd9Sstevel@tonic-gate  *	in dev_curr_cfg; the index of the first valid interface in the
4787c478bd9Sstevel@tonic-gate  *	tree, in dev_curr_if, and a parse level that accurately reflects what
4797c478bd9Sstevel@tonic-gate  *	is in the tree, in dev_parse_level.
4807c478bd9Sstevel@tonic-gate  */
4817c478bd9Sstevel@tonic-gate 
4827c478bd9Sstevel@tonic-gate 
4837c478bd9Sstevel@tonic-gate /*
4847c478bd9Sstevel@tonic-gate  * ***************************************************************************
4857c478bd9Sstevel@tonic-gate  * Data structures used in the configuration tree
4867c478bd9Sstevel@tonic-gate  * ***************************************************************************
4877c478bd9Sstevel@tonic-gate  */
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate /*
4907c478bd9Sstevel@tonic-gate  * Tree data structure for each configuration in the tree
4917c478bd9Sstevel@tonic-gate  */
4927c478bd9Sstevel@tonic-gate typedef struct usb_cfg_data {
4937c478bd9Sstevel@tonic-gate 	struct usb_cfg_descr	cfg_descr;	/* parsed config descr */
4947c478bd9Sstevel@tonic-gate 	struct usb_if_data	*cfg_if;	/* interfaces for this cfg */
4957c478bd9Sstevel@tonic-gate 						/* indexed by interface num */
4967c478bd9Sstevel@tonic-gate 	struct usb_cvs_data	*cfg_cvs;	/* class/vendor specific */
4977c478bd9Sstevel@tonic-gate 						/* descrs mod/extend cfg */
4987c478bd9Sstevel@tonic-gate 	char			*cfg_str;	/* string descriptor */
4997c478bd9Sstevel@tonic-gate 	uint_t			cfg_n_if;	/* #elements in cfg_if[] */
5007c478bd9Sstevel@tonic-gate 	uint_t			cfg_n_cvs;	/* #elements in cfg_cvs[] */
5017c478bd9Sstevel@tonic-gate 	uint_t			cfg_strsize;	/* size of string descr */
5027c478bd9Sstevel@tonic-gate } usb_cfg_data_t;
5037c478bd9Sstevel@tonic-gate 
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate /*
5067c478bd9Sstevel@tonic-gate  * Tree data structure for each alternate interface set
5077c478bd9Sstevel@tonic-gate  * in each represented configuration
5087c478bd9Sstevel@tonic-gate  */
5097c478bd9Sstevel@tonic-gate typedef struct usb_if_data {
5107c478bd9Sstevel@tonic-gate 	struct usb_alt_if_data	*if_alt;	/* sparse array of alts */
5117c478bd9Sstevel@tonic-gate 						/* indexed by alt setting */
5127c478bd9Sstevel@tonic-gate 	uint_t			if_n_alt;	/* #elements in if_alt[] */
5137c478bd9Sstevel@tonic-gate } usb_if_data_t;
5147c478bd9Sstevel@tonic-gate 
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate /*
5177c478bd9Sstevel@tonic-gate  * Tree data structure for each alternate of each alternate interface set
5187c478bd9Sstevel@tonic-gate  */
5197c478bd9Sstevel@tonic-gate typedef struct usb_alt_if_data {
5207c478bd9Sstevel@tonic-gate 	usb_if_descr_t		altif_descr;	/* parsed alternate if descr */
5217c478bd9Sstevel@tonic-gate 	struct usb_ep_data	*altif_ep;	/* endpts for alt if */
5227c478bd9Sstevel@tonic-gate 						/* (not a sparse array */
5237c478bd9Sstevel@tonic-gate 	struct usb_cvs_data	*altif_cvs;	/* cvs for this alt if */
5247c478bd9Sstevel@tonic-gate 	char			*altif_str;	/* string descriptor */
5257c478bd9Sstevel@tonic-gate 	uint_t			altif_n_ep;	/* #elements in altif_ep[] */
5267c478bd9Sstevel@tonic-gate 	uint_t			altif_n_cvs;	/* #elements in  altif_cvs[] */
5277c478bd9Sstevel@tonic-gate 	uint_t			altif_strsize;	/* size of string descr */
5287c478bd9Sstevel@tonic-gate } usb_alt_if_data_t;
5297c478bd9Sstevel@tonic-gate 
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate /*
5327c478bd9Sstevel@tonic-gate  * Tree data structure for each endpoint of each alternate
5337c478bd9Sstevel@tonic-gate  */
5347c478bd9Sstevel@tonic-gate typedef struct usb_ep_data {
5357c478bd9Sstevel@tonic-gate 	usb_ep_descr_t		ep_descr;	/* endpoint descriptor */
5367c478bd9Sstevel@tonic-gate 	struct usb_cvs_data	*ep_cvs;	/* cv mod/extending this ep */
5377c478bd9Sstevel@tonic-gate 	uint_t			ep_n_cvs;	/* #elements in ep_cvs[] */
538993e3fafSRobert Mustacchi 	boolean_t		ep_ss_valid;
539993e3fafSRobert Mustacchi 	usb_ep_ss_comp_descr_t	ep_ss_comp;	/* superspeed ep desc */
5407c478bd9Sstevel@tonic-gate } usb_ep_data_t;
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate 
5437c478bd9Sstevel@tonic-gate /*
5447c478bd9Sstevel@tonic-gate  * Tree data structure for each class/vendor specific descriptor
5457c478bd9Sstevel@tonic-gate  */
5467c478bd9Sstevel@tonic-gate typedef struct usb_cvs_data {
5477c478bd9Sstevel@tonic-gate 	uchar_t			*cvs_buf;	/* raw data of cvs descr */
5487c478bd9Sstevel@tonic-gate 	uint_t			cvs_buf_len;	/* cvs_buf size */
5497c478bd9Sstevel@tonic-gate } usb_cvs_data_t;
5507c478bd9Sstevel@tonic-gate 
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate /*
5537c478bd9Sstevel@tonic-gate  *	Parse_level determines the extent to which the tree is built, the amount
5547c478bd9Sstevel@tonic-gate  *	of parsing usb_client_attach() is to do.  It has the following values:
5557c478bd9Sstevel@tonic-gate  *
5567c478bd9Sstevel@tonic-gate  *	USB_PARSE_LVL_NONE - Build no tree.  dev_n_cfg will return 0, dev_cfg
5577c478bd9Sstevel@tonic-gate  *			     will return NULL, the dev_curr_xxx fields will be
5587c478bd9Sstevel@tonic-gate  *			     invalid.
5597c478bd9Sstevel@tonic-gate  *	USB_PARSE_LVL_IF   - Parse configured interface only, if configuration#
5607c478bd9Sstevel@tonic-gate  *			     and interface properties are set (as when different
5617c478bd9Sstevel@tonic-gate  *			     interfaces are viewed by the OS as different device
5627c478bd9Sstevel@tonic-gate  *			     instances). If an OS device instance is set up to
5637c478bd9Sstevel@tonic-gate  *			     represent an entire physical device, this works
5647c478bd9Sstevel@tonic-gate  *			     like USB_PARSE_LVL_ALL.
5657c478bd9Sstevel@tonic-gate  *	USB_PARSE_LVL_CFG  - Parse entire configuration of configured interface
5667c478bd9Sstevel@tonic-gate  *			     only.  This is like USB_PARSE_LVL_IF except entire
5677c478bd9Sstevel@tonic-gate  *			     configuration is returned.
5687c478bd9Sstevel@tonic-gate  *	USB_PARSE_LVL_ALL  - Parse entire device (all configurations), even
5697c478bd9Sstevel@tonic-gate  *			     when driver is bound to a single interface of a
5707c478bd9Sstevel@tonic-gate  *			     single configuration.
5717c478bd9Sstevel@tonic-gate  */
5727c478bd9Sstevel@tonic-gate typedef enum {
5737c478bd9Sstevel@tonic-gate 	USB_PARSE_LVL_NONE		= 0,
5747c478bd9Sstevel@tonic-gate 	USB_PARSE_LVL_IF		= 1,
5757c478bd9Sstevel@tonic-gate 	USB_PARSE_LVL_CFG		= 2,
5767c478bd9Sstevel@tonic-gate 	USB_PARSE_LVL_ALL		= 3
5777c478bd9Sstevel@tonic-gate } usb_reg_parse_lvl_t;
5787c478bd9Sstevel@tonic-gate 
5797c478bd9Sstevel@tonic-gate 
5807c478bd9Sstevel@tonic-gate /*
5817c478bd9Sstevel@tonic-gate  * Registration data returned by usb_get_dev_data().  Configuration tree roots
5827c478bd9Sstevel@tonic-gate  * are returned in dev_cfg array.
5837c478bd9Sstevel@tonic-gate  */
5847c478bd9Sstevel@tonic-gate typedef struct usb_client_dev_data {
5857c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	dev_default_ph;	/* default pipe handle */
5867c478bd9Sstevel@tonic-gate 	ddi_iblock_cookie_t	dev_iblock_cookie; /* for mutex_init's */
5877c478bd9Sstevel@tonic-gate 	struct usb_dev_descr	*dev_descr;	/* cooked device descriptor */
5887c478bd9Sstevel@tonic-gate 	char			*dev_mfg;	/* manufacturing ID */
5897c478bd9Sstevel@tonic-gate 	char			*dev_product;	/* product ID */
5907c478bd9Sstevel@tonic-gate 	char			*dev_serial;	/* serial number */
5917c478bd9Sstevel@tonic-gate 	usb_reg_parse_lvl_t	dev_parse_level; /* USB_PARSE_LVL_* flag */
5927c478bd9Sstevel@tonic-gate 	struct usb_cfg_data	*dev_cfg;	/* configs for this device */
5937c478bd9Sstevel@tonic-gate 						/* indexed by config index */
5947c478bd9Sstevel@tonic-gate 	uint_t			dev_n_cfg;	/* #elements in dev_cfg[] */
5957c478bd9Sstevel@tonic-gate 	struct usb_cfg_data	*dev_curr_cfg;	/* current cfg */
5967c478bd9Sstevel@tonic-gate 	int			dev_curr_if;	/* current interface number */
5977c478bd9Sstevel@tonic-gate } usb_client_dev_data_t;
5987c478bd9Sstevel@tonic-gate 
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate /*
6017c478bd9Sstevel@tonic-gate  * ***************************************************************************
6027c478bd9Sstevel@tonic-gate  * Device configuration descriptor tree functions
6037c478bd9Sstevel@tonic-gate  * ***************************************************************************
6047c478bd9Sstevel@tonic-gate  */
6057c478bd9Sstevel@tonic-gate 
6067c478bd9Sstevel@tonic-gate /*
6077c478bd9Sstevel@tonic-gate  * usb_get_dev_data:
6087c478bd9Sstevel@tonic-gate  *	returns initialized registration data. 	Most data items are clear.
6097c478bd9Sstevel@tonic-gate  *	Among the items returned is the tree ofparsed descriptors in dev_cfg;
6107c478bd9Sstevel@tonic-gate  *	and the number of configurations parsed in dev_n_cfg.
6117c478bd9Sstevel@tonic-gate  *
6127c478bd9Sstevel@tonic-gate  * Arguments:
6137c478bd9Sstevel@tonic-gate  *	dip		- pointer to devinfo node of the client
6147c478bd9Sstevel@tonic-gate  *	dev_data	- return registration data at this address
6157c478bd9Sstevel@tonic-gate  *	parse_level	- See above
6167c478bd9Sstevel@tonic-gate  *	flags		- None used
6177c478bd9Sstevel@tonic-gate  *
6187c478bd9Sstevel@tonic-gate  * Return Values:
6197c478bd9Sstevel@tonic-gate  *	USB_SUCCESS		- usb_register_client succeeded
6207c478bd9Sstevel@tonic-gate  *	USB_INVALID_ARGS	- received null dip or reg argument
6217c478bd9Sstevel@tonic-gate  *	USB_INVALID_CONTEXT	- called with sleep from callback context
6227c478bd9Sstevel@tonic-gate  *	USB_FAILURE		- bad descriptor info or other internal failure
6237c478bd9Sstevel@tonic-gate  *
6247c478bd9Sstevel@tonic-gate  * Notes:
6257c478bd9Sstevel@tonic-gate  * 	1) The non-standard USB descriptors are returned in RAW format.
6267c478bd9Sstevel@tonic-gate  *
6277c478bd9Sstevel@tonic-gate  *	2) The registration data is unshared. Each client receives its own copy.
6287c478bd9Sstevel@tonic-gate  *	(The default control pipe may be shared, even though its tree
6297c478bd9Sstevel@tonic-gate  *	description will be unique per device.)
6307c478bd9Sstevel@tonic-gate  *
6317c478bd9Sstevel@tonic-gate  */
6327c478bd9Sstevel@tonic-gate int usb_get_dev_data(
6337c478bd9Sstevel@tonic-gate 	dev_info_t			*dip,
6347c478bd9Sstevel@tonic-gate 	usb_client_dev_data_t		**dev_data,
6357c478bd9Sstevel@tonic-gate 	usb_reg_parse_lvl_t		parse_level,
6367c478bd9Sstevel@tonic-gate 	usb_flags_t			flags);
6377c478bd9Sstevel@tonic-gate 
6387c478bd9Sstevel@tonic-gate /*
6397c478bd9Sstevel@tonic-gate  * usb_free_dev_data:
6407c478bd9Sstevel@tonic-gate  * undoes what usb_get_dev_data() set up.  It releases
6417c478bd9Sstevel@tonic-gate  * memory for all strings, descriptors, and trees set up by usb_get_dev_data().
6427c478bd9Sstevel@tonic-gate  *
6437c478bd9Sstevel@tonic-gate  * Arguments:
6447c478bd9Sstevel@tonic-gate  *	dip		- pointer to devinfo node of the client
6457c478bd9Sstevel@tonic-gate  *	dev_data	- pointer to registration data containing the tree.
6467c478bd9Sstevel@tonic-gate  */
6477c478bd9Sstevel@tonic-gate void usb_free_dev_data(
6487c478bd9Sstevel@tonic-gate 	dev_info_t			*dip,
6497c478bd9Sstevel@tonic-gate 	usb_client_dev_data_t		*dev_data);
6507c478bd9Sstevel@tonic-gate 
6517c478bd9Sstevel@tonic-gate /*
6527c478bd9Sstevel@tonic-gate  * usb_free_descr_tree:
6537c478bd9Sstevel@tonic-gate  *	Take down the configuration tree while leaving the rest	of the
6547c478bd9Sstevel@tonic-gate  *	registration intact.  This can be used, for example, after attach has
6557c478bd9Sstevel@tonic-gate  *	copied any descriptors it needs from the tree, but the rest of the
6567c478bd9Sstevel@tonic-gate  *	registration data needs to remain intact.
6577c478bd9Sstevel@tonic-gate  *
6587c478bd9Sstevel@tonic-gate  *	The following usb_client_dev_data_t fields will be modified:
6597c478bd9Sstevel@tonic-gate  *		dev_cfg will be NULL
6607c478bd9Sstevel@tonic-gate  *		dev_n_cfg will be 0
6617c478bd9Sstevel@tonic-gate  *		dev_curr_cfg_ndx and dev_curr_if will be invalid
6627c478bd9Sstevel@tonic-gate  *		dev_parse_level will be USB_REG_DESCR_NONE
6637c478bd9Sstevel@tonic-gate  *
6647c478bd9Sstevel@tonic-gate  * Arguments:
6657c478bd9Sstevel@tonic-gate  *	dip		- pointer to devinfo node of the client
6667c478bd9Sstevel@tonic-gate  *	dev_data	- pointer to registration data containing the tree.
6677c478bd9Sstevel@tonic-gate  */
6687c478bd9Sstevel@tonic-gate void usb_free_descr_tree(
6697c478bd9Sstevel@tonic-gate 	dev_info_t			*dip,
6707c478bd9Sstevel@tonic-gate 	usb_client_dev_data_t		*dev_data);
6717c478bd9Sstevel@tonic-gate 
6727c478bd9Sstevel@tonic-gate 
6737c478bd9Sstevel@tonic-gate /*
6747c478bd9Sstevel@tonic-gate  * usb_print_descr_tree:
6757c478bd9Sstevel@tonic-gate  *	Dump to the screen a descriptor tree as returned by
6767c478bd9Sstevel@tonic-gate  *	usbai_register_client.
6777c478bd9Sstevel@tonic-gate  *
6787c478bd9Sstevel@tonic-gate  * Arguments:
6797c478bd9Sstevel@tonic-gate  *	dip		- pointer to devinfo of the client
6807c478bd9Sstevel@tonic-gate  *	dev_data	- pointer to registration area containing the tree
6817c478bd9Sstevel@tonic-gate  *
6827c478bd9Sstevel@tonic-gate  * Returns:
6837c478bd9Sstevel@tonic-gate  *	USB_SUCCESS		- tree successfully dumped
6847c478bd9Sstevel@tonic-gate  *	USB_INVALID_CONTEXT	- called from callback context
6857c478bd9Sstevel@tonic-gate  *	USB_INVALID_ARGS	- bad arguments given
6867c478bd9Sstevel@tonic-gate  */
6877c478bd9Sstevel@tonic-gate int usb_print_descr_tree(
6887c478bd9Sstevel@tonic-gate 	dev_info_t		*dip,
6897c478bd9Sstevel@tonic-gate 	usb_client_dev_data_t	*dev_data);
6907c478bd9Sstevel@tonic-gate 
6917c478bd9Sstevel@tonic-gate 
6927c478bd9Sstevel@tonic-gate /*
6937c478bd9Sstevel@tonic-gate  * ***************************************************************************
6947c478bd9Sstevel@tonic-gate  * Registration and versioning
6957c478bd9Sstevel@tonic-gate  * ***************************************************************************
6967c478bd9Sstevel@tonic-gate  */
6977c478bd9Sstevel@tonic-gate 
6987c478bd9Sstevel@tonic-gate 
6997c478bd9Sstevel@tonic-gate /*
7007c478bd9Sstevel@tonic-gate  * USBA client drivers are required to define USBDRV_MAJOR_VER
7017c478bd9Sstevel@tonic-gate  * USBDRV_MINOR_VER and pass USBDRV_VERSION as the version
7027c478bd9Sstevel@tonic-gate  * number to usb_client_attach
7037c478bd9Sstevel@tonic-gate  */
7047c478bd9Sstevel@tonic-gate #if !defined(USBA_MAJOR_VER) || !defined(USBA_MINOR_VER)
7057c478bd9Sstevel@tonic-gate #error incorrect USBA header
7067c478bd9Sstevel@tonic-gate #endif
7077c478bd9Sstevel@tonic-gate 
7087c478bd9Sstevel@tonic-gate /*
7097c478bd9Sstevel@tonic-gate  * Driver major version must be the same as USBA major version, and
7107c478bd9Sstevel@tonic-gate  * driver minor version must be <= USBA minor version
7117c478bd9Sstevel@tonic-gate  */
7127c478bd9Sstevel@tonic-gate #if !defined(USBA_FRAMEWORK)
7137c478bd9Sstevel@tonic-gate #if defined(USBDRV_MAJOR_VER) && defined(USBDRV_MINOR_VER)
7147c478bd9Sstevel@tonic-gate 
7157c478bd9Sstevel@tonic-gate #if (USBDRV_MAJOR_VER != USBA_MAJOR_VER)
7167c478bd9Sstevel@tonic-gate #error USBA and driver major versions do not match
7177c478bd9Sstevel@tonic-gate #endif
7187c478bd9Sstevel@tonic-gate #if (USBDRV_MINOR_VER > USBA_MINOR_VER)
7197c478bd9Sstevel@tonic-gate #error USBA and driver minor versions do not match
7207c478bd9Sstevel@tonic-gate #endif
7217c478bd9Sstevel@tonic-gate 
7227c478bd9Sstevel@tonic-gate #endif
7237c478bd9Sstevel@tonic-gate #endif
7247c478bd9Sstevel@tonic-gate 
7257c478bd9Sstevel@tonic-gate #define	USBA_MAKE_VER(major, minor) ((major) << 8 | (minor))
7267c478bd9Sstevel@tonic-gate #define	USBA_GET_MAJOR(ver) ((ver) >> 8)
7277c478bd9Sstevel@tonic-gate #define	USBA_GET_MINOR(ver) ((ver) & 0xff)
7287c478bd9Sstevel@tonic-gate 
7297c478bd9Sstevel@tonic-gate #define	USBDRV_VERSION	USBA_MAKE_VER(USBDRV_MAJOR_VER, USBDRV_MINOR_VER)
7307c478bd9Sstevel@tonic-gate 
7317c478bd9Sstevel@tonic-gate 
7327c478bd9Sstevel@tonic-gate /*
7337c478bd9Sstevel@tonic-gate  * usb_client_attach:
7347c478bd9Sstevel@tonic-gate  *
7357c478bd9Sstevel@tonic-gate  * Arguments:
7367c478bd9Sstevel@tonic-gate  *	dip		- pointer to devinfo node of the client
7377c478bd9Sstevel@tonic-gate  *	version 	- USBA registration version number
7387c478bd9Sstevel@tonic-gate  *	flags		- None used
7397c478bd9Sstevel@tonic-gate  *
7407c478bd9Sstevel@tonic-gate  * Return Values:
7417c478bd9Sstevel@tonic-gate  *	USB_SUCCESS		- attach succeeded
7427c478bd9Sstevel@tonic-gate  *	USB_INVALID_ARGS	- received null dip or reg argument
7437c478bd9Sstevel@tonic-gate  *	USB_INVALID_CONTEXT	- called with sleep from callback context
7447c478bd9Sstevel@tonic-gate  *				  or not at attach time
7457c478bd9Sstevel@tonic-gate  *	USB_INVALID_VERSION	- version argument is incorrect.
7467c478bd9Sstevel@tonic-gate  *	USB_FAILURE		- other internal failure
7477c478bd9Sstevel@tonic-gate  */
7487c478bd9Sstevel@tonic-gate int usb_client_attach(
7497c478bd9Sstevel@tonic-gate 	dev_info_t			*dip,
7507c478bd9Sstevel@tonic-gate 	uint_t				version,
7517c478bd9Sstevel@tonic-gate 	usb_flags_t			flags);
7527c478bd9Sstevel@tonic-gate 
7537c478bd9Sstevel@tonic-gate /*
7547c478bd9Sstevel@tonic-gate  * usb_client_detach:
7557c478bd9Sstevel@tonic-gate  *
7567c478bd9Sstevel@tonic-gate  * Arguments:
7577c478bd9Sstevel@tonic-gate  *	dip		- pointer to devinfo node of the client
7587c478bd9Sstevel@tonic-gate  *	dev_data	- pointer to data to free. may be NULL
7597c478bd9Sstevel@tonic-gate  */
7607c478bd9Sstevel@tonic-gate void usb_client_detach(
7617c478bd9Sstevel@tonic-gate 	dev_info_t			*dip,
7627c478bd9Sstevel@tonic-gate 	struct usb_client_dev_data	*dev_data);
7637c478bd9Sstevel@tonic-gate 
7647c478bd9Sstevel@tonic-gate /*
7657c478bd9Sstevel@tonic-gate  * ***************************************************************************
7667c478bd9Sstevel@tonic-gate  * Functions for parsing / retrieving data from the descriptor tree
7677c478bd9Sstevel@tonic-gate  * ***************************************************************************
7687c478bd9Sstevel@tonic-gate  */
7697c478bd9Sstevel@tonic-gate 
7707c478bd9Sstevel@tonic-gate /*
7717c478bd9Sstevel@tonic-gate  * Function for unpacking any kind of little endian data, usually desriptors
7727c478bd9Sstevel@tonic-gate  *
7737c478bd9Sstevel@tonic-gate  * Arguments:
7747c478bd9Sstevel@tonic-gate  *	format		- string indicating the format in c, s, w, eg. "2c4ws"
7757c478bd9Sstevel@tonic-gate  *			  which describes 2 bytes, 4 int, one short.
7767c478bd9Sstevel@tonic-gate  *			  The number prefix parses the number of items of
7777c478bd9Sstevel@tonic-gate  *			  the following type.
7787c478bd9Sstevel@tonic-gate  *	data		- pointer to the LE data buffer
7797c478bd9Sstevel@tonic-gate  *	datalen		- length of the data
7807c478bd9Sstevel@tonic-gate  *	structure	- pointer to return structure where the unpacked data
7817c478bd9Sstevel@tonic-gate  *			  will be written
7827c478bd9Sstevel@tonic-gate  *	structlen	- length of the return structure
7837c478bd9Sstevel@tonic-gate  *
7847c478bd9Sstevel@tonic-gate  * return value:
7857c478bd9Sstevel@tonic-gate  *	total number of bytes of the original data that was unpacked
7867c478bd9Sstevel@tonic-gate  *	or USB_PARSE_ERROR
7877c478bd9Sstevel@tonic-gate  */
7887c478bd9Sstevel@tonic-gate #define	USB_PARSE_ERROR	0
7897c478bd9Sstevel@tonic-gate 
7907c478bd9Sstevel@tonic-gate size_t usb_parse_data(
7917c478bd9Sstevel@tonic-gate 	char			*format,
792*0d2006e4SRobert Mustacchi 	const uchar_t 		*data,
7937c478bd9Sstevel@tonic-gate 	size_t			datalen,
7947c478bd9Sstevel@tonic-gate 	void			*structure,
7957c478bd9Sstevel@tonic-gate 	size_t			structlen);
7967c478bd9Sstevel@tonic-gate 
7977c478bd9Sstevel@tonic-gate /*
7987c478bd9Sstevel@tonic-gate  * usb_lookup_ep_data:
7997c478bd9Sstevel@tonic-gate  *	Function to get specific endpoint data
8007c478bd9Sstevel@tonic-gate  *	This function will not access the device.
8017c478bd9Sstevel@tonic-gate  *
8027c478bd9Sstevel@tonic-gate  * Arguments:
8037c478bd9Sstevel@tonic-gate  *	dip		- pointer to dev info
8047c478bd9Sstevel@tonic-gate  *	dev_datap	- pointer to registration data
8057c478bd9Sstevel@tonic-gate  *	interface	- requested interface
8067c478bd9Sstevel@tonic-gate  *	alternate	- requested alternate
8077c478bd9Sstevel@tonic-gate  *	skip		- number of endpoints which match the requested type and
8087c478bd9Sstevel@tonic-gate  *			  direction to skip before finding one to retrieve
8097c478bd9Sstevel@tonic-gate  *	type		- endpoint type
8107c478bd9Sstevel@tonic-gate  *	direction	- endpoint direction: USB_EP_DIR_IN/OUT or none
8117c478bd9Sstevel@tonic-gate  *
8127c478bd9Sstevel@tonic-gate  * Return Values:
8137c478bd9Sstevel@tonic-gate  *	NULL or an endpoint data pointer
8147c478bd9Sstevel@tonic-gate  */
8157c478bd9Sstevel@tonic-gate usb_ep_data_t *usb_lookup_ep_data(
8167c478bd9Sstevel@tonic-gate 	dev_info_t		*dip,
8177c478bd9Sstevel@tonic-gate 	usb_client_dev_data_t	*dev_datap,
8187c478bd9Sstevel@tonic-gate 	uint_t			interface,
8197c478bd9Sstevel@tonic-gate 	uint_t			alternate,
8207c478bd9Sstevel@tonic-gate 	uint_t			skip,
8217c478bd9Sstevel@tonic-gate 	uint_t			type,
8227c478bd9Sstevel@tonic-gate 	uint_t			direction);
8237c478bd9Sstevel@tonic-gate 
8247c478bd9Sstevel@tonic-gate 
8257c478bd9Sstevel@tonic-gate /* Language ID for string descriptors. */
8267c478bd9Sstevel@tonic-gate #define	USB_LANG_ID		0x0409		/* English, US */
8277c478bd9Sstevel@tonic-gate 
8287c478bd9Sstevel@tonic-gate /*
8297c478bd9Sstevel@tonic-gate  * usb_get_string_descr:
8307c478bd9Sstevel@tonic-gate  *	Reads the string descriptor.  This function access the device and
8317c478bd9Sstevel@tonic-gate  *	blocks.
8327c478bd9Sstevel@tonic-gate  *
8337c478bd9Sstevel@tonic-gate  * Arguments:
8347c478bd9Sstevel@tonic-gate  *	dip		- pointer to devinfo of the client.
8357c478bd9Sstevel@tonic-gate  *	langid		- LANGID to read different LOCALEs.
8367c478bd9Sstevel@tonic-gate  *	index		- index to the string.
8377c478bd9Sstevel@tonic-gate  *	buf		- user provided buffer for string descriptor.
8387c478bd9Sstevel@tonic-gate  *	buflen		- user provided length of the buffer.
8397c478bd9Sstevel@tonic-gate  *
8407c478bd9Sstevel@tonic-gate  * Return Values:
8417c478bd9Sstevel@tonic-gate  *	USB_SUCCESS	- descriptor is valid.
8427c478bd9Sstevel@tonic-gate  *	USB_FAILURE	- full descriptor could not be retrieved.
8437c478bd9Sstevel@tonic-gate  */
8447c478bd9Sstevel@tonic-gate int usb_get_string_descr(
8457c478bd9Sstevel@tonic-gate 	dev_info_t		*dip,
8467c478bd9Sstevel@tonic-gate 	uint16_t		langid,
8477c478bd9Sstevel@tonic-gate 	uint8_t			index,
8487c478bd9Sstevel@tonic-gate 	char			*buf,
8497c478bd9Sstevel@tonic-gate 	size_t			buflen);
8507c478bd9Sstevel@tonic-gate 
851993e3fafSRobert Mustacchi /*
852993e3fafSRobert Mustacchi  * With the advent of USB 3.x, several endpoint compantion descriptors have been
853993e3fafSRobert Mustacchi  * added. These provide additional information required by HCI drivers to
854993e3fafSRobert Mustacchi  * properly open and configure the pipes.
855993e3fafSRobert Mustacchi  */
856993e3fafSRobert Mustacchi 
857993e3fafSRobert Mustacchi /*
858993e3fafSRobert Mustacchi  * usb_ep_xdescr
859993e3fafSRobert Mustacchi  *
860993e3fafSRobert Mustacchi  * 	Versioned data structure that's used for usb_pipe_xopen() and should be
861993e3fafSRobert Mustacchi  * 	filled in by a call to usb_ep_xdescr_fill(). Drivers should always use
862993e3fafSRobert Mustacchi  * 	USB_EP_XDESCR_CURRENT_VERSION.
863993e3fafSRobert Mustacchi  */
864993e3fafSRobert Mustacchi 
865993e3fafSRobert Mustacchi #define	USB_EP_XDESCR_VERSION_ONE	1
866993e3fafSRobert Mustacchi #define	USB_EP_XDESCR_CURRENT_VERSION	USB_EP_XDESCR_VERSION_ONE
867993e3fafSRobert Mustacchi 
868993e3fafSRobert Mustacchi typedef enum usb_ep_xdescr_flags {
869993e3fafSRobert Mustacchi 	USB_EP_XFLAGS_SS_COMP	= (1 << 0)
870993e3fafSRobert Mustacchi } usb_ep_xdescr_flags_t;
871993e3fafSRobert Mustacchi 
872993e3fafSRobert Mustacchi typedef struct usb_ep_xdescr {
873993e3fafSRobert Mustacchi 	uint_t			uex_version;
874993e3fafSRobert Mustacchi 	usb_ep_xdescr_flags_t	uex_flags;
875993e3fafSRobert Mustacchi 	usb_ep_descr_t		uex_ep;
876993e3fafSRobert Mustacchi 	usb_ep_ss_comp_descr_t	uex_ep_ss;
877993e3fafSRobert Mustacchi } usb_ep_xdescr_t;
878993e3fafSRobert Mustacchi 
879993e3fafSRobert Mustacchi /*
880993e3fafSRobert Mustacchi  * usb_ep_xdescr_fill:
881993e3fafSRobert Mustacchi  *
882993e3fafSRobert Mustacchi  * Fills in the extended endpoint descriptor based on data from the
883993e3fafSRobert Mustacchi  * configuration tree.
884993e3fafSRobert Mustacchi  *
885993e3fafSRobert Mustacchi  * Arguments:
886993e3fafSRobert Mustacchi  * 	version		- Should be USB_EP_XDESCR_CURRENT_VERSION
887993e3fafSRobert Mustacchi  * 	dip		- devinfo pointer
888993e3fafSRobert Mustacchi  * 	ep_data		- endpoint data pointer
889993e3fafSRobert Mustacchi  * 	ep_xdesc	- An extended descriptor structure, filled upon
890993e3fafSRobert Mustacchi  *                        successful completion.
891993e3fafSRobert Mustacchi  *
892993e3fafSRobert Mustacchi  * Return values:
893993e3fafSRobert Mustacchi  *	USB_SUCCESS	 - filling data succeeded
894993e3fafSRobert Mustacchi  *	USB_INVALID_ARGS - invalid arguments
895993e3fafSRobert Mustacchi  */
896993e3fafSRobert Mustacchi int usb_ep_xdescr_fill(
897993e3fafSRobert Mustacchi 	uint_t 		version,
898993e3fafSRobert Mustacchi 	dev_info_t	*dip,
899993e3fafSRobert Mustacchi 	usb_ep_data_t	*ep_data,
900993e3fafSRobert Mustacchi 	usb_ep_xdescr_t	*ep_xdesc);
901993e3fafSRobert Mustacchi 
9027c478bd9Sstevel@tonic-gate 
9037c478bd9Sstevel@tonic-gate /*
9047c478bd9Sstevel@tonic-gate  * ***************************************************************************
9057c478bd9Sstevel@tonic-gate  * Addressing utility functions
9067c478bd9Sstevel@tonic-gate  * ***************************************************************************
9077c478bd9Sstevel@tonic-gate  */
9087c478bd9Sstevel@tonic-gate 
9097c478bd9Sstevel@tonic-gate /*
9107c478bd9Sstevel@tonic-gate  * usb_get_addr returns the current usb address, mostly for debugging
9117c478bd9Sstevel@tonic-gate  * purposes. The address may change after hotremove/insert.
9127c478bd9Sstevel@tonic-gate  * This address will not change on a disconnect/reconnect of open device.
9137c478bd9Sstevel@tonic-gate  */
9147c478bd9Sstevel@tonic-gate int usb_get_addr(dev_info_t *dip);
9157c478bd9Sstevel@tonic-gate 
9167c478bd9Sstevel@tonic-gate 
9177c478bd9Sstevel@tonic-gate /*
9187c478bd9Sstevel@tonic-gate  * usb_get_if_number returns USB_COMBINED_NODE or USB_DEVICE_NODE
9197c478bd9Sstevel@tonic-gate  * if the driver is responsible for the entire device.
9207c478bd9Sstevel@tonic-gate  * Otherwise it returns the interface number.
9217c478bd9Sstevel@tonic-gate  */
9227c478bd9Sstevel@tonic-gate #define	USB_COMBINED_NODE	-1
9237c478bd9Sstevel@tonic-gate #define	USB_DEVICE_NODE		-2
9247c478bd9Sstevel@tonic-gate 
9257c478bd9Sstevel@tonic-gate int usb_get_if_number(
9267c478bd9Sstevel@tonic-gate 	dev_info_t		*dip);
9277c478bd9Sstevel@tonic-gate 
9287c478bd9Sstevel@tonic-gate boolean_t usb_owns_device(
9297c478bd9Sstevel@tonic-gate 	dev_info_t		*dip);
9307c478bd9Sstevel@tonic-gate 
9317c478bd9Sstevel@tonic-gate 
9327c478bd9Sstevel@tonic-gate /*
9337c478bd9Sstevel@tonic-gate  * ***************************************************************************
9347c478bd9Sstevel@tonic-gate  * Pipe	Management definitions and functions
9357c478bd9Sstevel@tonic-gate  * ***************************************************************************
9367c478bd9Sstevel@tonic-gate  */
9377c478bd9Sstevel@tonic-gate 
9387c478bd9Sstevel@tonic-gate 
9397c478bd9Sstevel@tonic-gate /*
9407c478bd9Sstevel@tonic-gate  *
9417c478bd9Sstevel@tonic-gate  * usb_pipe_state:
9427c478bd9Sstevel@tonic-gate  *
9437c478bd9Sstevel@tonic-gate  * PIPE_STATE_IDLE:
9447c478bd9Sstevel@tonic-gate  *	The pipe's policy is set, but the pipe currently isn't transferring
9457c478bd9Sstevel@tonic-gate  *	data.
9467c478bd9Sstevel@tonic-gate  *
9477c478bd9Sstevel@tonic-gate  * PIPE_STATE_ACTIVE:
9487c478bd9Sstevel@tonic-gate  *	The pipe's policy has been set, and the pipe is able to transmit data.
9497c478bd9Sstevel@tonic-gate  *	When a control or bulk pipe is opened, the pipe's state is
9507c478bd9Sstevel@tonic-gate  *	automatically set to PIPE_STATE_ACTIVE.  For an interrupt or
9517c478bd9Sstevel@tonic-gate  *	isochronous pipe, the pipe state becomes PIPE_STATE_ACTIVE once
9527c478bd9Sstevel@tonic-gate  *	the polling on the pipe has been initiated.
9537c478bd9Sstevel@tonic-gate  *
9547c478bd9Sstevel@tonic-gate  * PIPE_STATE_ERROR:
9557c478bd9Sstevel@tonic-gate  *	The device has generated a error on the pipe.  The client driver
9567c478bd9Sstevel@tonic-gate  *	must call usb_pipe_reset() to clear any leftover state that's associated
9577c478bd9Sstevel@tonic-gate  *	with the pipe, clear the data toggle, and reset the state of the pipe.
9587c478bd9Sstevel@tonic-gate  *
9597c478bd9Sstevel@tonic-gate  *	Calling usb_pipe_reset() on a control or bulk pipe resets the state to
9607c478bd9Sstevel@tonic-gate  *	PIPE_STATE_ACTIVE.  Calling usb_pipe_reset() on an interrupt or
9617c478bd9Sstevel@tonic-gate  *	isochronous pipe, resets the state to PIPE_STATE_IDLE.
9627c478bd9Sstevel@tonic-gate  *
9637c478bd9Sstevel@tonic-gate  * State Diagram for Bulk/Control
9647c478bd9Sstevel@tonic-gate  *
9657c478bd9Sstevel@tonic-gate  *			+-<--normal completion------------------<-------^
9667c478bd9Sstevel@tonic-gate  *			|						|
9677c478bd9Sstevel@tonic-gate  *			V						|
9687c478bd9Sstevel@tonic-gate  * usb_pipe_open-->[PIPE_STATE_IDLE]-usb_pipe_*_xfer->[PIPE_STATE_ACTIVE]
9697c478bd9Sstevel@tonic-gate  *			^						|
9707c478bd9Sstevel@tonic-gate  *			|						v
9717c478bd9Sstevel@tonic-gate  *			- usb_pipe_reset<-[PIPE_STATE_ERROR]<-device error
9727c478bd9Sstevel@tonic-gate  *
9737c478bd9Sstevel@tonic-gate  * State Diagram for Interrupt/Isochronous IN
9747c478bd9Sstevel@tonic-gate  *
9757c478bd9Sstevel@tonic-gate  *			+-<--usb_pipe_stop_isoc/intr_polling----<-------^
9767c478bd9Sstevel@tonic-gate  *			|						|
9777c478bd9Sstevel@tonic-gate  *			V						|
9787c478bd9Sstevel@tonic-gate  * usb_pipe_open-->[PIPE_STATE_IDLE]-usb_pipe_*_xfer->[PIPE_STATE_ACTIVE]
9797c478bd9Sstevel@tonic-gate  *			^						|
9807c478bd9Sstevel@tonic-gate  *			|						v
9817c478bd9Sstevel@tonic-gate  *			+ usb_pipe_reset<-[PIPE_STATE_ERROR]<-device error
9827c478bd9Sstevel@tonic-gate  *
9837c478bd9Sstevel@tonic-gate  * State Diagram for Interrupt/Isochronous OUT
9847c478bd9Sstevel@tonic-gate  *
9857c478bd9Sstevel@tonic-gate  *			+-<--normal completion------------------<-------^
9867c478bd9Sstevel@tonic-gate  *			|						|
9877c478bd9Sstevel@tonic-gate  *			V						|
9887c478bd9Sstevel@tonic-gate  * usb_pipe_open-->[PIPE_STATE_IDLE]-usb_pipe_*_xfer->[PIPE_STATE_ACTIVE]
9897c478bd9Sstevel@tonic-gate  *			^						|
9907c478bd9Sstevel@tonic-gate  *			|						v
9917c478bd9Sstevel@tonic-gate  *			+ usb_pipe_reset<-[PIPE_STATE_ERROR]<-device error
9927c478bd9Sstevel@tonic-gate  *
9937c478bd9Sstevel@tonic-gate  *
9947c478bd9Sstevel@tonic-gate  * The following table indicates which operations are allowed with each
9957c478bd9Sstevel@tonic-gate  * pipe state:
9967c478bd9Sstevel@tonic-gate  *
9977c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------------+
9987c478bd9Sstevel@tonic-gate  * ctrl/bulk	| idle	| active     | error  | sync closing | async closing|
9997c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------------+
10007c478bd9Sstevel@tonic-gate  * pipe xfer	|  OK	|queue (USBA)| reject | reject	     | reject	    |
10017c478bd9Sstevel@tonic-gate  * pipe reset	| no-op | OK	     |	OK    | reject	     | reject	    |
10027c478bd9Sstevel@tonic-gate  * pipe close	|  OK	| wait&close |	OK    | no-op	     | no-op	    |
10037c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------------+
10047c478bd9Sstevel@tonic-gate  *
10057c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------------+
10067c478bd9Sstevel@tonic-gate  * intr/isoc IN | idle	| active     | error  | sync closing | async closing|
10077c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------------+
10087c478bd9Sstevel@tonic-gate  * pipe xfer	|  OK	| reject     | reject | reject	     | reject	    |
10097c478bd9Sstevel@tonic-gate  * pipe stoppoll| no-op | OK	     | no-op  | reject	     | reject	    |
10107c478bd9Sstevel@tonic-gate  * pipe reset	| no-op | OK	     |	OK    | reject	     | reject	    |
10117c478bd9Sstevel@tonic-gate  * pipe close	|  OK	| wait&close |	OK    | no-op	     | no-op	    |
10127c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------------+
10137c478bd9Sstevel@tonic-gate  *
10147c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------------+
10157c478bd9Sstevel@tonic-gate  * intr/isoc OUT| idle	| active     | error  | sync closing | async closing|
10167c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------------+
10177c478bd9Sstevel@tonic-gate  * pipe xfer	|  OK	|queue (HCD) | reject | reject	     | reject	    |
10187c478bd9Sstevel@tonic-gate  * pipe stoppoll| reject| reject     | reject | reject	     | reject	    |
10197c478bd9Sstevel@tonic-gate  * pipe reset	| no-op | OK	     |	OK    | reject	     | reject	    |
10207c478bd9Sstevel@tonic-gate  * pipe close	|  OK	| wait&close |	OK    | no-op	     | no-op	    |
10217c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------------+
10227c478bd9Sstevel@tonic-gate  */
10237c478bd9Sstevel@tonic-gate typedef enum {
10247c478bd9Sstevel@tonic-gate 	USB_PIPE_STATE_CLOSED		= 0,
10257c478bd9Sstevel@tonic-gate 	USB_PIPE_STATE_IDLE		= 1,
10267c478bd9Sstevel@tonic-gate 	USB_PIPE_STATE_ACTIVE		= 2,
10277c478bd9Sstevel@tonic-gate 	USB_PIPE_STATE_ERROR		= 3,
10287c478bd9Sstevel@tonic-gate 	USB_PIPE_STATE_CLOSING		= 4
10297c478bd9Sstevel@tonic-gate } usb_pipe_state_t;
10307c478bd9Sstevel@tonic-gate 
10317c478bd9Sstevel@tonic-gate 
10327c478bd9Sstevel@tonic-gate /*
10337c478bd9Sstevel@tonic-gate  * pipe state control:
10347c478bd9Sstevel@tonic-gate  *
10357c478bd9Sstevel@tonic-gate  * return values:
10367c478bd9Sstevel@tonic-gate  *	USB_SUCCESS	 - success
10377c478bd9Sstevel@tonic-gate  *	USB_FAILURE	 - unspecified failure
10387c478bd9Sstevel@tonic-gate  */
10397c478bd9Sstevel@tonic-gate int usb_pipe_get_state(
10407c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
10417c478bd9Sstevel@tonic-gate 	usb_pipe_state_t	*pipe_state,
10427c478bd9Sstevel@tonic-gate 	usb_flags_t		flags);
10437c478bd9Sstevel@tonic-gate 
10447c478bd9Sstevel@tonic-gate /*
10457c478bd9Sstevel@tonic-gate  * usb_pipe_policy
10467c478bd9Sstevel@tonic-gate  *
10477c478bd9Sstevel@tonic-gate  *	Pipe policy specifies how a pipe to an endpoint	should be used
10487c478bd9Sstevel@tonic-gate  *	by the client driver and the HCD.
10497c478bd9Sstevel@tonic-gate  */
10507c478bd9Sstevel@tonic-gate typedef struct usb_pipe_policy {
10517c478bd9Sstevel@tonic-gate 	/*
10527c478bd9Sstevel@tonic-gate 	 * This is a hint indicating how many asynchronous operations
10537c478bd9Sstevel@tonic-gate 	 * requiring a kernel thread will be concurrently active.
10547c478bd9Sstevel@tonic-gate 	 * Allow at least one for synch exception callback handling
10557c478bd9Sstevel@tonic-gate 	 * and another for asynchronous closing of pipes.
10567c478bd9Sstevel@tonic-gate 	 */
10577c478bd9Sstevel@tonic-gate 	uchar_t		pp_max_async_reqs;
10587c478bd9Sstevel@tonic-gate } usb_pipe_policy_t;
10597c478bd9Sstevel@tonic-gate 
10607c478bd9Sstevel@tonic-gate 
10617c478bd9Sstevel@tonic-gate /*
1062993e3fafSRobert Mustacchi  * usb_pipe_open() and usb_pipe_xopen():
10637c478bd9Sstevel@tonic-gate  *
10647c478bd9Sstevel@tonic-gate  * Before using any pipe including the default pipe, it must be opened.
10657c478bd9Sstevel@tonic-gate  * On success, a pipe handle is returned for use in other usb_pipe_*()
10667c478bd9Sstevel@tonic-gate  * functions.
10677c478bd9Sstevel@tonic-gate  *
10687c478bd9Sstevel@tonic-gate  * The default pipe can only be opened by the hub driver.
10697c478bd9Sstevel@tonic-gate  *
10707c478bd9Sstevel@tonic-gate  * For isochronous and interrupt pipes, bandwidth has been allocated and
10717c478bd9Sstevel@tonic-gate  * guaranteed.
10727c478bd9Sstevel@tonic-gate  *
10737c478bd9Sstevel@tonic-gate  * Only the default pipe can be shared.  All other control pipes are
10747c478bd9Sstevel@tonic-gate  * excusively opened by default.  A pipe policy and endpoint descriptor
10757c478bd9Sstevel@tonic-gate  * must always be provided except for default pipe.
10767c478bd9Sstevel@tonic-gate  *
1077993e3fafSRobert Mustacchi  * usb_pipe_open() only functions for USB 2.0 and older devices. For USB 3.0
1078993e3fafSRobert Mustacchi  * "SuperSpeed" devices, usb_pipe_xopen() must be used.
1079993e3fafSRobert Mustacchi  *
10807c478bd9Sstevel@tonic-gate  * Arguments:
10817c478bd9Sstevel@tonic-gate  *	dip		- devinfo ptr.
10827c478bd9Sstevel@tonic-gate  *	ep		- endpoint descriptor pointer.
10837c478bd9Sstevel@tonic-gate  *	pipe_policy	- pointer to pipe policy which provides hints on how
10847c478bd9Sstevel@tonic-gate  *			  the pipe will be used.
10857c478bd9Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP wait for resources to become
10867c478bd9Sstevel@tonic-gate  *			  available.
10877c478bd9Sstevel@tonic-gate  *	pipe_handle	- a pipe handle pointer.  on a successful open,
10887c478bd9Sstevel@tonic-gate  *			  a pipe_handle is returned in this pointer.
10897c478bd9Sstevel@tonic-gate  *
10907c478bd9Sstevel@tonic-gate  * Return values:
10917c478bd9Sstevel@tonic-gate  *	USB_SUCCESS	 - open succeeded.
10927c478bd9Sstevel@tonic-gate  *	USB_FAILURE	 - unspecified open failure or pipe is already open.
10937c478bd9Sstevel@tonic-gate  *	USB_NO_RESOURCES - no resources were available to complete the open.
10947c478bd9Sstevel@tonic-gate  *	USB_NO_BANDWIDTH - no bandwidth available (isoc/intr pipes).
1095993e3fafSRobert Mustacchi  *	USB_NOT_SUPPORTED - USB 3.0 or greater device
10967c478bd9Sstevel@tonic-gate  *	USB_*		 - refer to list of all possible return values in
10977c478bd9Sstevel@tonic-gate  *			   this file
10987c478bd9Sstevel@tonic-gate  */
10997c478bd9Sstevel@tonic-gate int usb_pipe_open(
11007c478bd9Sstevel@tonic-gate 	dev_info_t		*dip,
11017c478bd9Sstevel@tonic-gate 	usb_ep_descr_t		*ep,
11027c478bd9Sstevel@tonic-gate 	usb_pipe_policy_t	*pipe_policy,
11037c478bd9Sstevel@tonic-gate 	usb_flags_t		flags,
11047c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	*pipe_handle);
11057c478bd9Sstevel@tonic-gate 
1106993e3fafSRobert Mustacchi int usb_pipe_xopen(
1107993e3fafSRobert Mustacchi 	dev_info_t		*dip,
1108993e3fafSRobert Mustacchi 	usb_ep_xdescr_t		*ep_xdesc,
1109993e3fafSRobert Mustacchi 	usb_pipe_policy_t	*pipe_policy,
1110993e3fafSRobert Mustacchi 	usb_flags_t		flags,
1111993e3fafSRobert Mustacchi 	usb_pipe_handle_t	*pipe_handle);
1112993e3fafSRobert Mustacchi 
11137c478bd9Sstevel@tonic-gate 
11147c478bd9Sstevel@tonic-gate /*
11157c478bd9Sstevel@tonic-gate  * usb_pipe_close():
11167c478bd9Sstevel@tonic-gate  *
11177c478bd9Sstevel@tonic-gate  * Closes the pipe, releases resources and frees the pipe_handle.
11187c478bd9Sstevel@tonic-gate  * Automatic polling, if active,  will be terminated.
11197c478bd9Sstevel@tonic-gate  *
11207c478bd9Sstevel@tonic-gate  * Arguments:
11217c478bd9Sstevel@tonic-gate  *	dip		- devinfo ptr.
11227c478bd9Sstevel@tonic-gate  *	pipe_handle	- pipe handle.
11237c478bd9Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
11247c478bd9Sstevel@tonic-gate  *				wait for resources, pipe
11257c478bd9Sstevel@tonic-gate  *				to become free, and all callbacks completed.
11267c478bd9Sstevel@tonic-gate  *	cb		- If USB_FLAGS_SLEEP has not been specified, a
11277c478bd9Sstevel@tonic-gate  *			  callback will be performed.
11287c478bd9Sstevel@tonic-gate  *	cb_arg		- the 2nd argument of the callback. Note that the
11297c478bd9Sstevel@tonic-gate  *			  pipehandle will be zeroed and therefore not passed.
11307c478bd9Sstevel@tonic-gate  *
11317c478bd9Sstevel@tonic-gate  * Notes:
11327c478bd9Sstevel@tonic-gate  *
11337c478bd9Sstevel@tonic-gate  * Pipe close always succeeds regardless whether USB_FLAGS_SLEEP has been
11347c478bd9Sstevel@tonic-gate  * specified or not.  An async close will always succeed if the hint in the
11357c478bd9Sstevel@tonic-gate  * pipe policy has been correct about the max number of async requests
11367c478bd9Sstevel@tonic-gate  * required.
11377c478bd9Sstevel@tonic-gate  * In the unlikely event that no async requests can be queued, this
11387c478bd9Sstevel@tonic-gate  * function will continue retrying before returning
11397c478bd9Sstevel@tonic-gate  *
11407c478bd9Sstevel@tonic-gate  * USBA prevents the client from submitting subsequent requests to a pipe
11417c478bd9Sstevel@tonic-gate  * that is being closed.
11427c478bd9Sstevel@tonic-gate  * Additional usb_pipe_close() requests on the same pipe causes USBA to
11437c478bd9Sstevel@tonic-gate  * wait for the previous close(s) to complete.
11447c478bd9Sstevel@tonic-gate  *
11457c478bd9Sstevel@tonic-gate  * The pipe will not be destroyed until all activity on the pipe has
11467c478bd9Sstevel@tonic-gate  * been drained, including outstanding request callbacks, async requests,
11477c478bd9Sstevel@tonic-gate  * and other usb_pipe_*() calls.
11487c478bd9Sstevel@tonic-gate  *
11497c478bd9Sstevel@tonic-gate  * Calling usb_pipe_close() from a deferred callback (in kernel context)
11507c478bd9Sstevel@tonic-gate  * with USB_FLAGS_SLEEP set, will cause deadlock
11517c478bd9Sstevel@tonic-gate  */
11527c478bd9Sstevel@tonic-gate void usb_pipe_close(
11537c478bd9Sstevel@tonic-gate 	dev_info_t		*dip,
11547c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
11557c478bd9Sstevel@tonic-gate 	usb_flags_t		flags,
11567c478bd9Sstevel@tonic-gate 	void			(*cb)(
11577c478bd9Sstevel@tonic-gate 				    usb_pipe_handle_t	ph,
11587c478bd9Sstevel@tonic-gate 				    usb_opaque_t	arg,	/* cb arg */
11597c478bd9Sstevel@tonic-gate 				    int			rval,
11607c478bd9Sstevel@tonic-gate 				    usb_cb_flags_t	flags),
11617c478bd9Sstevel@tonic-gate 	usb_opaque_t		cb_arg);
11627c478bd9Sstevel@tonic-gate 
11637c478bd9Sstevel@tonic-gate 
11647c478bd9Sstevel@tonic-gate /*
11657c478bd9Sstevel@tonic-gate  * usb_pipe_drain_reqs
11667c478bd9Sstevel@tonic-gate  *	this function blocks until there are no more requests
11677c478bd9Sstevel@tonic-gate  *	owned by this dip on the pipe
11687c478bd9Sstevel@tonic-gate  *
11697c478bd9Sstevel@tonic-gate  * Arguments:
11707c478bd9Sstevel@tonic-gate  *	dip		- devinfo pointer
11717c478bd9Sstevel@tonic-gate  *	pipe_handle	- opaque pipe handle
11727c478bd9Sstevel@tonic-gate  *	timeout 	- timeout in seconds
11737c478bd9Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
11747c478bd9Sstevel@tonic-gate  *				wait for completion.
11757c478bd9Sstevel@tonic-gate  *	cb		- if USB_FLAGS_SLEEP has not been specified
11767c478bd9Sstevel@tonic-gate  *			  this callback function will be called on
11777c478bd9Sstevel@tonic-gate  *			  completion. This callback may be NULL
11787c478bd9Sstevel@tonic-gate  *			  and no notification of completion will then
11797c478bd9Sstevel@tonic-gate  *			  be provided.
11807c478bd9Sstevel@tonic-gate  *	cb_arg		- 2nd argument to callback function.
11817c478bd9Sstevel@tonic-gate  *
11827c478bd9Sstevel@tonic-gate  * callback and callback_arg should be NULL if USB_FLAGS_SLEEP has
11837c478bd9Sstevel@tonic-gate  * been specified
11847c478bd9Sstevel@tonic-gate  *
11857c478bd9Sstevel@tonic-gate  * Returns:
11867c478bd9Sstevel@tonic-gate  *	USB_SUCCESS	- pipe successfully reset or request queued
11877c478bd9Sstevel@tonic-gate  *	USB_FAILURE	- timeout
11887c478bd9Sstevel@tonic-gate  *	USB_INVALID_PIPE - pipe is invalid or already closed
11897c478bd9Sstevel@tonic-gate  *	USB_INVALID_CONTEXT - called from interrupt context
11907c478bd9Sstevel@tonic-gate  *	USB_INVALID_ARGS - invalid arguments
11917c478bd9Sstevel@tonic-gate  *	USB_*		- refer to return values defines in this file
11927c478bd9Sstevel@tonic-gate  */
11937c478bd9Sstevel@tonic-gate int usb_pipe_drain_reqs(
11947c478bd9Sstevel@tonic-gate 	dev_info_t		*dip,
11957c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
11967c478bd9Sstevel@tonic-gate 	uint_t			time,
11977c478bd9Sstevel@tonic-gate 	usb_flags_t		flags,
11987c478bd9Sstevel@tonic-gate 	void			(*cb)(
11997c478bd9Sstevel@tonic-gate 				    usb_pipe_handle_t	ph,
12007c478bd9Sstevel@tonic-gate 				    usb_opaque_t	arg,	/* cb arg */
12017c478bd9Sstevel@tonic-gate 				    int			rval,
12027c478bd9Sstevel@tonic-gate 				    usb_cb_flags_t	flags),
12037c478bd9Sstevel@tonic-gate 	usb_opaque_t		cb_arg);
12047c478bd9Sstevel@tonic-gate 
12057c478bd9Sstevel@tonic-gate 
12067c478bd9Sstevel@tonic-gate /*
12077c478bd9Sstevel@tonic-gate  * Resetting a pipe: Refer to USB 2.0/10.5.2.2
12087c478bd9Sstevel@tonic-gate  *	The pipe's requests are retired and the pipe is cleared.  The host state
12097c478bd9Sstevel@tonic-gate  *	is moved to active. If the reflected endpoint state needs to be changed,
12107c478bd9Sstevel@tonic-gate  *	that must be explicitly requested by the client driver.  The reset
12117c478bd9Sstevel@tonic-gate  *	completes after all request callbacks have been completed.
12127c478bd9Sstevel@tonic-gate  *
12137c478bd9Sstevel@tonic-gate  * Arguments:
12147c478bd9Sstevel@tonic-gate  *	dip		- devinfo pointer.
12157c478bd9Sstevel@tonic-gate  *	pipe_handle	- pipe handle.
12167c478bd9Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
12177c478bd9Sstevel@tonic-gate  *				wait for completion.
12187c478bd9Sstevel@tonic-gate  *	cb		- if USB_FLAGS_SLEEP has not been specified
12197c478bd9Sstevel@tonic-gate  *			  this callback function will be called on
12207c478bd9Sstevel@tonic-gate  *			  completion. This callback may be NULL
12217c478bd9Sstevel@tonic-gate  *			  and no notification of completion will then
12227c478bd9Sstevel@tonic-gate  *			  be provided.
12237c478bd9Sstevel@tonic-gate  *	cb_arg		- 2nd argument to callback function.
12247c478bd9Sstevel@tonic-gate  *
12257c478bd9Sstevel@tonic-gate  * callback and callback_arg should be NULL if USB_FLAGS_SLEEP has
12267c478bd9Sstevel@tonic-gate  * been specified
12277c478bd9Sstevel@tonic-gate  *
12287c478bd9Sstevel@tonic-gate  * Note: Completion notification may be *before* all async request threads
12297c478bd9Sstevel@tonic-gate  *	have completed but *after* all immediate callbacks have completed.
12307c478bd9Sstevel@tonic-gate  */
12317c478bd9Sstevel@tonic-gate void usb_pipe_reset(
12327c478bd9Sstevel@tonic-gate 	dev_info_t		*dip,
12337c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
12347c478bd9Sstevel@tonic-gate 	usb_flags_t		usb_flags,
12357c478bd9Sstevel@tonic-gate 	void			(*cb)(
12367c478bd9Sstevel@tonic-gate 					usb_pipe_handle_t ph,
12377c478bd9Sstevel@tonic-gate 					usb_opaque_t	arg,
12387c478bd9Sstevel@tonic-gate 					int		rval,
12397c478bd9Sstevel@tonic-gate 					usb_cb_flags_t	flags),
12407c478bd9Sstevel@tonic-gate 	usb_opaque_t		cb_arg);
12417c478bd9Sstevel@tonic-gate 
12427c478bd9Sstevel@tonic-gate 
12437c478bd9Sstevel@tonic-gate /*
12447c478bd9Sstevel@tonic-gate  * The client driver can store a private data pointer in the
12457c478bd9Sstevel@tonic-gate  * pipe_handle.
12467c478bd9Sstevel@tonic-gate  *
12477c478bd9Sstevel@tonic-gate  * return values:
12487c478bd9Sstevel@tonic-gate  *	USB_SUCCESS	 - success
12497c478bd9Sstevel@tonic-gate  *	USB_FAILURE	 - unspecified failure
12507c478bd9Sstevel@tonic-gate  */
12517c478bd9Sstevel@tonic-gate int usb_pipe_set_private(
12527c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
12537c478bd9Sstevel@tonic-gate 	usb_opaque_t		data);
12547c478bd9Sstevel@tonic-gate 
12557c478bd9Sstevel@tonic-gate 
12567c478bd9Sstevel@tonic-gate usb_opaque_t usb_pipe_get_private(
12577c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle);
12587c478bd9Sstevel@tonic-gate 
12597c478bd9Sstevel@tonic-gate 
12607c478bd9Sstevel@tonic-gate /*
12617c478bd9Sstevel@tonic-gate  * ***************************************************************************
12627c478bd9Sstevel@tonic-gate  * Transfer request definitions and functions
12637c478bd9Sstevel@tonic-gate  * ***************************************************************************
12647c478bd9Sstevel@tonic-gate  */
12657c478bd9Sstevel@tonic-gate 
12667c478bd9Sstevel@tonic-gate 
12677c478bd9Sstevel@tonic-gate /*
12687c478bd9Sstevel@tonic-gate  * USB xfer request attributes.
12697c478bd9Sstevel@tonic-gate  * Set by the client driver, more than one may be set
12707c478bd9Sstevel@tonic-gate  *
12717c478bd9Sstevel@tonic-gate  * SHORT_XFER_OK if less data is transferred than specified, no error is
12727c478bd9Sstevel@tonic-gate  *		returned.
12737c478bd9Sstevel@tonic-gate  * AUTOCLEARING	if there is an exception, the pipe will be reset first
12747c478bd9Sstevel@tonic-gate  *		and a functional stall cleared before a callback is done.
12757c478bd9Sstevel@tonic-gate  * PIPE_RESET	if there is an exception, the pipe will be reset only
12767c478bd9Sstevel@tonic-gate  * ONE_XFER	polling will automatically stop on the first callback.
12777c478bd9Sstevel@tonic-gate  * ISOC_START_FRAME use startframe specified.
12787c478bd9Sstevel@tonic-gate  * USB_ATTRS_ISOC_XFER_ASAP let the host controller decide on the first
12797c478bd9Sstevel@tonic-gate  *		available frame.
12807c478bd9Sstevel@tonic-gate  *
12817c478bd9Sstevel@tonic-gate  * USB_ATTRS_ISOC_START_FRAME and USB_ATTRS_ISOC_XFER_ASAP are mutually
12827c478bd9Sstevel@tonic-gate  * exclusive
12837c478bd9Sstevel@tonic-gate  *
12847c478bd9Sstevel@tonic-gate  * combinations of flag and attributes:
12857c478bd9Sstevel@tonic-gate  *
12867c478bd9Sstevel@tonic-gate  * usb_flags	usb_req_attrs			semantics
12877c478bd9Sstevel@tonic-gate  * ---------------------------------------------------------
12887c478bd9Sstevel@tonic-gate  * SLEEP	USB_ATTRS_SHORT_XFER_OK		legal for IN pipes
12897c478bd9Sstevel@tonic-gate  * SLEEP	USB_ATTRS_AUTOCLEARING		legal
12907c478bd9Sstevel@tonic-gate  * SLEEP	USB_ATTRS_PIPE_RESET		legal
12917c478bd9Sstevel@tonic-gate  * SLEEP	USB_ATTRS_ONE_XFER		legal for interrupt IN pipes
12927c478bd9Sstevel@tonic-gate  * SLEEP	USB_ATTRS_ISOC_START_FRAME	illegal
12937c478bd9Sstevel@tonic-gate  * SLEEP	USB_ATTRS_ISOC_XFER_ASAP	illegal
12947c478bd9Sstevel@tonic-gate  *
12957c478bd9Sstevel@tonic-gate  * noSLEEP	USB_ATTRS_SHORT_XFER_OK		legal for all IN pipes
12967c478bd9Sstevel@tonic-gate  * noSLEEP	USB_ATTRS_AUTOCLEARING		legal
12977c478bd9Sstevel@tonic-gate  * noSLEEP	USB_ATTRS_PIPE_RESET		legal
12987c478bd9Sstevel@tonic-gate  * noSLEEP	USB_ATTRS_ONE_XFER		legal
12997c478bd9Sstevel@tonic-gate  * noSLEEP	USB_ATTRS_ISOC_START_FRAME	legal
13007c478bd9Sstevel@tonic-gate  * noSLEEP	USB_ATTRS_ISOC_XFER_ASAP	legal
13017c478bd9Sstevel@tonic-gate  */
13027c478bd9Sstevel@tonic-gate typedef enum {
13037c478bd9Sstevel@tonic-gate 	USB_ATTRS_NONE			= 0,
13047c478bd9Sstevel@tonic-gate 
13057c478bd9Sstevel@tonic-gate 	/* only ctrl/bulk/intr IN pipes */
13067c478bd9Sstevel@tonic-gate 	USB_ATTRS_SHORT_XFER_OK		= 0x01,	/* short data xfer is ok */
13077c478bd9Sstevel@tonic-gate 	USB_ATTRS_PIPE_RESET		= 0x02,	/* reset pipe only on exc */
13087c478bd9Sstevel@tonic-gate 	USB_ATTRS_AUTOCLEARING		= 0x12, /* autoclear STALLs */
13097c478bd9Sstevel@tonic-gate 
13107c478bd9Sstevel@tonic-gate 	/* intr pipes only: one poll with data */
13117c478bd9Sstevel@tonic-gate 	USB_ATTRS_ONE_XFER		= 0x100,
13127c478bd9Sstevel@tonic-gate 
13137c478bd9Sstevel@tonic-gate 	/* only for isoch pipe */
13147c478bd9Sstevel@tonic-gate 	USB_ATTRS_ISOC_START_FRAME	= 0x200, /* Starting frame# specified */
13157c478bd9Sstevel@tonic-gate 	USB_ATTRS_ISOC_XFER_ASAP	= 0x400	/* HCD decides START_FRAME#  */
13167c478bd9Sstevel@tonic-gate } usb_req_attrs_t;
13177c478bd9Sstevel@tonic-gate 
13187c478bd9Sstevel@tonic-gate 
13197c478bd9Sstevel@tonic-gate /*
13207c478bd9Sstevel@tonic-gate  * Note: client drivers are required to provide data buffers (mblks) for most
13217c478bd9Sstevel@tonic-gate  * requests
13227c478bd9Sstevel@tonic-gate  *			IN		OUT
13237c478bd9Sstevel@tonic-gate  * ctlr request		if wLength > 0	if wLength > 0
13247c478bd9Sstevel@tonic-gate  * bulk request		yes		yes
13257c478bd9Sstevel@tonic-gate  * intr request		no		yes
13267c478bd9Sstevel@tonic-gate  * isoc request		no		yes
13277c478bd9Sstevel@tonic-gate  */
13287c478bd9Sstevel@tonic-gate 
13297c478bd9Sstevel@tonic-gate /*
13307c478bd9Sstevel@tonic-gate  * ===========================================================================
13317c478bd9Sstevel@tonic-gate  * USB control request management
13327c478bd9Sstevel@tonic-gate  * ===========================================================================
13337c478bd9Sstevel@tonic-gate  */
13347c478bd9Sstevel@tonic-gate 
13357c478bd9Sstevel@tonic-gate /*
13367c478bd9Sstevel@tonic-gate  * A client driver allocates and uses the usb_ctrl_req_t for all control
13377c478bd9Sstevel@tonic-gate  * pipe requests.
13387c478bd9Sstevel@tonic-gate  *
13397c478bd9Sstevel@tonic-gate  * Direction of the xfer will be determined based on the bmRequestType.
13407c478bd9Sstevel@tonic-gate  *
13417c478bd9Sstevel@tonic-gate  * NULL callbacks are permitted, timeout = 0 indicates infinite timeout.
13427c478bd9Sstevel@tonic-gate  * All timeouts are in seconds.
13437c478bd9Sstevel@tonic-gate  *
13447c478bd9Sstevel@tonic-gate  * All fields are initialized by client except for data on IN request
13457c478bd9Sstevel@tonic-gate  * in which case the client is responsible for deallocating.
13467c478bd9Sstevel@tonic-gate  *
13477c478bd9Sstevel@tonic-gate  * Control requests may be reused.  The client driver is responsible
13487c478bd9Sstevel@tonic-gate  * for reinitializing some fields, eg data read/write pointers.
13497c478bd9Sstevel@tonic-gate  *
13507c478bd9Sstevel@tonic-gate  * Control requests can be queued.
13517c478bd9Sstevel@tonic-gate  */
13527c478bd9Sstevel@tonic-gate typedef struct usb_ctrl_req {
13537c478bd9Sstevel@tonic-gate 	uint8_t		ctrl_bmRequestType; /* characteristics of request */
13547c478bd9Sstevel@tonic-gate 	uint8_t		ctrl_bRequest;	/* specific request		*/
13557c478bd9Sstevel@tonic-gate 	uint16_t	ctrl_wValue;	/* varies according to request	*/
13567c478bd9Sstevel@tonic-gate 	uint16_t	ctrl_wIndex;	/* index or offset		*/
13577c478bd9Sstevel@tonic-gate 	uint16_t	ctrl_wLength;	/* number of bytes to xfer	*/
13587c478bd9Sstevel@tonic-gate 
13597c478bd9Sstevel@tonic-gate 	mblk_t		*ctrl_data;	/* the data for the data phase	*/
13607c478bd9Sstevel@tonic-gate 					/* IN: allocated by HCD		*/
13617c478bd9Sstevel@tonic-gate 					/* OUT: allocated by client	*/
13627c478bd9Sstevel@tonic-gate 	uint_t		ctrl_timeout;	/* how long before HCD retires req */
13637c478bd9Sstevel@tonic-gate 	usb_opaque_t	ctrl_client_private; /* for client private info	*/
13647c478bd9Sstevel@tonic-gate 	usb_req_attrs_t ctrl_attributes; /* attributes for this req */
13657c478bd9Sstevel@tonic-gate 
13667c478bd9Sstevel@tonic-gate 	/*
13677c478bd9Sstevel@tonic-gate 	 * callback function for control pipe requests
13687c478bd9Sstevel@tonic-gate 	 *
13697c478bd9Sstevel@tonic-gate 	 * a normal callback will be done upon:
13707c478bd9Sstevel@tonic-gate 	 *	- successful completion of a control pipe request
13717c478bd9Sstevel@tonic-gate 	 *
13727c478bd9Sstevel@tonic-gate 	 * callback arguments are:
13737c478bd9Sstevel@tonic-gate 	 *	- the pipe_handle
13747c478bd9Sstevel@tonic-gate 	 *	- usb_ctrl_req_t pointer
13757c478bd9Sstevel@tonic-gate 	 */
13767c478bd9Sstevel@tonic-gate 	void		(*ctrl_cb)(usb_pipe_handle_t ph,
13777c478bd9Sstevel@tonic-gate 				struct usb_ctrl_req *req);
13787c478bd9Sstevel@tonic-gate 
13797c478bd9Sstevel@tonic-gate 	/*
13807c478bd9Sstevel@tonic-gate 	 * exception callback function for control pipe
13817c478bd9Sstevel@tonic-gate 	 *
13827c478bd9Sstevel@tonic-gate 	 * a exception callback will be done upon:
13837c478bd9Sstevel@tonic-gate 	 *	- an exception/error (all types)
13847c478bd9Sstevel@tonic-gate 	 *	- partial xfer of data unless SHORT_XFER_OK has been set
13857c478bd9Sstevel@tonic-gate 	 *
13867c478bd9Sstevel@tonic-gate 	 * callback arguments are:
13877c478bd9Sstevel@tonic-gate 	 *	- the pipe_handle
13887c478bd9Sstevel@tonic-gate 	 *	- usb_ctrl_req_t pointer
13897c478bd9Sstevel@tonic-gate 	 *
13907c478bd9Sstevel@tonic-gate 	 * if USB_ATTRS_AUTOCLEARING was set, autoclearing will be attempted
13917c478bd9Sstevel@tonic-gate 	 * and usb_cb_flags_t in usb_ctrl_req may indicate what was done
13927c478bd9Sstevel@tonic-gate 	 */
13937c478bd9Sstevel@tonic-gate 	void		(*ctrl_exc_cb)(usb_pipe_handle_t ph,
13947c478bd9Sstevel@tonic-gate 				struct usb_ctrl_req *req);
13957c478bd9Sstevel@tonic-gate 
13967c478bd9Sstevel@tonic-gate 	/* set by USBA/HCD on completion */
13977c478bd9Sstevel@tonic-gate 	usb_cr_t	ctrl_completion_reason;	/* set by HCD */
13987c478bd9Sstevel@tonic-gate 	usb_cb_flags_t	ctrl_cb_flags;  /* Callback context / handling flgs */
13997c478bd9Sstevel@tonic-gate } usb_ctrl_req_t;
14007c478bd9Sstevel@tonic-gate 
14017c478bd9Sstevel@tonic-gate 
14027c478bd9Sstevel@tonic-gate /*
14037c478bd9Sstevel@tonic-gate  * In the setup packet, the descriptor type is passed in the high byte of the
14047c478bd9Sstevel@tonic-gate  * wValue field.
14057c478bd9Sstevel@tonic-gate  * descriptor types:
14067c478bd9Sstevel@tonic-gate  */
14077c478bd9Sstevel@tonic-gate #define	USB_DESCR_TYPE_SETUP_DEV		0x0100
14087c478bd9Sstevel@tonic-gate #define	USB_DESCR_TYPE_SETUP_CFG		0x0200
14097c478bd9Sstevel@tonic-gate #define	USB_DESCR_TYPE_SETUP_STRING		0x0300
14107c478bd9Sstevel@tonic-gate #define	USB_DESCR_TYPE_SETUP_IF			0x0400
14117c478bd9Sstevel@tonic-gate #define	USB_DESCR_TYPE_SETUP_EP			0x0500
14127c478bd9Sstevel@tonic-gate #define	USB_DESCR_TYPE_SETUP_DEV_QLF		0x0600
14137c478bd9Sstevel@tonic-gate #define	USB_DESCR_TYPE_SETUP_OTHER_SPEED_CFG	0x0700
14147c478bd9Sstevel@tonic-gate #define	USB_DESCR_TYPE_SETUP_IF_PWR		0x0800
14157c478bd9Sstevel@tonic-gate 
14167c478bd9Sstevel@tonic-gate #define	USB_DESCR_TYPE_DEV			0x01
14177c478bd9Sstevel@tonic-gate #define	USB_DESCR_TYPE_CFG			0x02
14187c478bd9Sstevel@tonic-gate #define	USB_DESCR_TYPE_STRING			0x03
14197c478bd9Sstevel@tonic-gate #define	USB_DESCR_TYPE_IF			0x04
14207c478bd9Sstevel@tonic-gate #define	USB_DESCR_TYPE_EP			0x05
14217c478bd9Sstevel@tonic-gate #define	USB_DESCR_TYPE_DEV_QLF			0x06
14227c478bd9Sstevel@tonic-gate #define	USB_DESCR_TYPE_OTHER_SPEED_CFG		0x07
14237c478bd9Sstevel@tonic-gate #define	USB_DESCR_TYPE_IF_PWR			0x08
1424d73ae94eSgc #define	USB_DESCR_TYPE_IA			0x0B
14257c478bd9Sstevel@tonic-gate 
1426ff0e937bSRaymond Chen #define	USB_DESCR_TYPE_WA			0x21
1427ff0e937bSRaymond Chen #define	USB_DESCR_TYPE_RPIPE			0x22
1428993e3fafSRobert Mustacchi #define	USB_DESCR_TYPE_HUB			0x29
1429ff0e937bSRaymond Chen 
1430ff0e937bSRaymond Chen /* Wireless USB extension, refer to WUSB 1.0/7.4 */
1431ff0e937bSRaymond Chen #define	USB_DESCR_TYPE_SECURITY			0x0c
1432ff0e937bSRaymond Chen #define	USB_DESCR_TYPE_KEY			0x0d
1433ff0e937bSRaymond Chen #define	USB_DESCR_TYPE_ENCRYPTION		0x0e
1434ff0e937bSRaymond Chen #define	USB_DESCR_TYPE_BOS			0x0f
1435ff0e937bSRaymond Chen #define	USB_DESCR_TYPE_DEV_CAPABILITY		0x10
1436ff0e937bSRaymond Chen #define	USB_DESCR_TYPE_WIRELESS_EP_COMP		0x11
1437ff0e937bSRaymond Chen 
1438ff0e937bSRaymond Chen #define	USB_WA_DESCR_SIZE			14
1439ff0e937bSRaymond Chen #define	USB_RPIPE_DESCR_SIZE			28
1440ff0e937bSRaymond Chen 
1441993e3fafSRobert Mustacchi /*
1442993e3fafSRobert Mustacchi  * USB 3.0 Super Speed specifics. See USB 3.1/9.4.
1443993e3fafSRobert Mustacchi  */
1444993e3fafSRobert Mustacchi #define	USB_DESCR_TYPE_SS_HUB			0x2A
1445993e3fafSRobert Mustacchi #define	USB_DESCR_TYPE_SS_EP_COMP		0x30
1446993e3fafSRobert Mustacchi #define	USB_DESCR_TYPE_SS_ISO_EP_COMP		0x31
1447993e3fafSRobert Mustacchi 
14487c478bd9Sstevel@tonic-gate /*
14497c478bd9Sstevel@tonic-gate  * device request type
14507c478bd9Sstevel@tonic-gate  */
14517c478bd9Sstevel@tonic-gate #define	USB_DEV_REQ_HOST_TO_DEV		0x00
14527c478bd9Sstevel@tonic-gate #define	USB_DEV_REQ_DEV_TO_HOST		0x80
14537c478bd9Sstevel@tonic-gate #define	USB_DEV_REQ_DIR_MASK		0x80
14547c478bd9Sstevel@tonic-gate 
14557c478bd9Sstevel@tonic-gate #define	USB_DEV_REQ_TYPE_STANDARD	0x00
14567c478bd9Sstevel@tonic-gate #define	USB_DEV_REQ_TYPE_CLASS		0x20
14577c478bd9Sstevel@tonic-gate #define	USB_DEV_REQ_TYPE_VENDOR		0x40
14587c478bd9Sstevel@tonic-gate #define	USB_DEV_REQ_TYPE_MASK		0x60
14597c478bd9Sstevel@tonic-gate 
14607c478bd9Sstevel@tonic-gate #define	USB_DEV_REQ_RCPT_DEV		0x00
14617c478bd9Sstevel@tonic-gate #define	USB_DEV_REQ_RCPT_IF		0x01
14627c478bd9Sstevel@tonic-gate #define	USB_DEV_REQ_RCPT_EP		0x02
14637c478bd9Sstevel@tonic-gate #define	USB_DEV_REQ_RCPT_OTHER		0x03
14647c478bd9Sstevel@tonic-gate #define	USB_DEV_REQ_RCPT_MASK		0x03
14657c478bd9Sstevel@tonic-gate 
1466ff0e937bSRaymond Chen /* Wire adapter class extension for request recipient */
1467ff0e937bSRaymond Chen #define	USB_DEV_REQ_RCPT_PORT		0x04
1468ff0e937bSRaymond Chen #define	USB_DEV_REQ_RCPT_RPIPE		0x05
1469ff0e937bSRaymond Chen 
14707c478bd9Sstevel@tonic-gate /*
14717c478bd9Sstevel@tonic-gate  * device request
14727c478bd9Sstevel@tonic-gate  */
14737c478bd9Sstevel@tonic-gate #define	USB_REQ_GET_STATUS		0x00
14747c478bd9Sstevel@tonic-gate #define	USB_REQ_CLEAR_FEATURE		0x01
14757c478bd9Sstevel@tonic-gate #define	USB_REQ_SET_FEATURE		0x03
14767c478bd9Sstevel@tonic-gate #define	USB_REQ_SET_ADDRESS		0x05
14777c478bd9Sstevel@tonic-gate #define	USB_REQ_GET_DESCR		0x06
14787c478bd9Sstevel@tonic-gate #define	USB_REQ_SET_DESCR		0x07
14797c478bd9Sstevel@tonic-gate #define	USB_REQ_GET_CFG			0x08
14807c478bd9Sstevel@tonic-gate #define	USB_REQ_SET_CFG			0x09
14817c478bd9Sstevel@tonic-gate #define	USB_REQ_GET_IF			0x0a
14827c478bd9Sstevel@tonic-gate #define	USB_REQ_SET_IF			0x0b
14837c478bd9Sstevel@tonic-gate #define	USB_REQ_SYNC_FRAME		0x0c
1484ff0e937bSRaymond Chen /* Wireless USB extension, refer to WUSB 1.0/7.3.1 */
1485ff0e937bSRaymond Chen #define	USB_REQ_SET_ENCRYPTION		0x0d
1486ff0e937bSRaymond Chen #define	USB_REQ_GET_ENCRYPTION		0x0e
1487ff0e937bSRaymond Chen #define	USB_REQ_RPIPE_ABORT		0x0e
1488ff0e937bSRaymond Chen #define	USB_REQ_SET_HANDSHAKE		0x0f
1489ff0e937bSRaymond Chen #define	USB_REQ_RPIPE_RESET		0x0f
1490ff0e937bSRaymond Chen #define	USB_REQ_GET_HANDSHAKE		0x10
1491ff0e937bSRaymond Chen #define	USB_REQ_SET_CONNECTION		0x11
1492ff0e937bSRaymond Chen #define	USB_REQ_SET_SECURITY_DATA	0x12
1493ff0e937bSRaymond Chen #define	USB_REQ_GET_SECURITY_DATA	0x13
1494ff0e937bSRaymond Chen #define	USB_REQ_SET_WUSB_DATA		0x14
1495ff0e937bSRaymond Chen #define	USB_REQ_LOOPBACK_DATA_WRITE	0x15
1496ff0e937bSRaymond Chen #define	USB_REQ_LOOPBACK_DATA_READ	0x16
1497ff0e937bSRaymond Chen #define	USB_REQ_SET_INTERFACE_DS	0x17
14987c478bd9Sstevel@tonic-gate 
14997c478bd9Sstevel@tonic-gate /* language ID for string descriptors */
15007c478bd9Sstevel@tonic-gate #define	USB_LANG_ID			0x0409
15017c478bd9Sstevel@tonic-gate 
15027c478bd9Sstevel@tonic-gate /*
15037c478bd9Sstevel@tonic-gate  * Standard Feature Selectors
15047c478bd9Sstevel@tonic-gate  */
15057c478bd9Sstevel@tonic-gate #define	USB_EP_HALT			0x0000
15067c478bd9Sstevel@tonic-gate #define	USB_DEV_REMOTE_WAKEUP		0x0001
15077c478bd9Sstevel@tonic-gate #define	USB_DEV_TEST_MODE		0x0002
1508ff0e937bSRaymond Chen /* Wireless USB extension, refer to WUSB 1.0/7.3.1 */
1509ff0e937bSRaymond Chen #define	USB_DEV_WUSB			0x0003
15107c478bd9Sstevel@tonic-gate 
15117c478bd9Sstevel@tonic-gate 
15127c478bd9Sstevel@tonic-gate /*
15137c478bd9Sstevel@tonic-gate  * Allocate usb control request
15147c478bd9Sstevel@tonic-gate  *
15157c478bd9Sstevel@tonic-gate  * Arguments:
15167c478bd9Sstevel@tonic-gate  *	dip	- dev_info pointer of the client driver
15177c478bd9Sstevel@tonic-gate  *	len	- length of "data" for this control request.
15187c478bd9Sstevel@tonic-gate  *		  if 0, no mblk is alloc'ed
15197c478bd9Sstevel@tonic-gate  *	flags	- USB_FLAGS_SLEEP: Sleep if resources are not available
15207c478bd9Sstevel@tonic-gate  *
15217c478bd9Sstevel@tonic-gate  * Return Values:
15227c478bd9Sstevel@tonic-gate  *	usb_ctrl_req_t pointer on success, NULL on failure
15237c478bd9Sstevel@tonic-gate  *
15247c478bd9Sstevel@tonic-gate  * Implementation NOTE: the dip allows checking on detach for memory leaks
15257c478bd9Sstevel@tonic-gate  */
15267c478bd9Sstevel@tonic-gate usb_ctrl_req_t *usb_alloc_ctrl_req(
15277c478bd9Sstevel@tonic-gate 	dev_info_t		*dip,
15287c478bd9Sstevel@tonic-gate 	size_t			len,
15297c478bd9Sstevel@tonic-gate 	usb_flags_t		flags);
15307c478bd9Sstevel@tonic-gate 
15317c478bd9Sstevel@tonic-gate 
15327c478bd9Sstevel@tonic-gate /*
15337c478bd9Sstevel@tonic-gate  * free USB control request
15347c478bd9Sstevel@tonic-gate  */
15357c478bd9Sstevel@tonic-gate void usb_free_ctrl_req(
15367c478bd9Sstevel@tonic-gate 	usb_ctrl_req_t	*reqp);
15377c478bd9Sstevel@tonic-gate 
15387c478bd9Sstevel@tonic-gate 
15397c478bd9Sstevel@tonic-gate /*
15407c478bd9Sstevel@tonic-gate  * usb_pipe_ctrl_xfer();
15417c478bd9Sstevel@tonic-gate  *	Client driver calls this function to issue the control
15427c478bd9Sstevel@tonic-gate  *	request to the USBA which will queue or transport it to the device
15437c478bd9Sstevel@tonic-gate  *
15447c478bd9Sstevel@tonic-gate  * Arguments:
15457c478bd9Sstevel@tonic-gate  *	pipe_handle	- control pipe pipehandle (obtained via usb_pipe_open()
15467c478bd9Sstevel@tonic-gate  *	reqp		- pointer to control request
15477c478bd9Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
15487c478bd9Sstevel@tonic-gate  *				wait for the request to complete
15497c478bd9Sstevel@tonic-gate  *
15507c478bd9Sstevel@tonic-gate  * Return values:
15517c478bd9Sstevel@tonic-gate  *	USB_SUCCESS	- successfully queued (no sleep) or successfully
15527c478bd9Sstevel@tonic-gate  *			  completed (with sleep specified)
15537c478bd9Sstevel@tonic-gate  *	USB_FAILURE	- failure
15547c478bd9Sstevel@tonic-gate  *	USB_NO_RESOURCES - no resources
15557c478bd9Sstevel@tonic-gate  */
15567c478bd9Sstevel@tonic-gate int usb_pipe_ctrl_xfer(usb_pipe_handle_t pipe_handle,
15577c478bd9Sstevel@tonic-gate 	usb_ctrl_req_t	*reqp,
15587c478bd9Sstevel@tonic-gate 	usb_flags_t		flags);
15597c478bd9Sstevel@tonic-gate 
15607c478bd9Sstevel@tonic-gate 
15617c478bd9Sstevel@tonic-gate /*
15627c478bd9Sstevel@tonic-gate  * ---------------------------------------------------------------------------
15637c478bd9Sstevel@tonic-gate  * Wrapper function which allocates and deallocates a request structure, and
15647c478bd9Sstevel@tonic-gate  * performs a control transfer.
15657c478bd9Sstevel@tonic-gate  * ---------------------------------------------------------------------------
15667c478bd9Sstevel@tonic-gate  */
15677c478bd9Sstevel@tonic-gate 
15687c478bd9Sstevel@tonic-gate /*
15697c478bd9Sstevel@tonic-gate  * Setup arguments for usb_pipe_ctrl_xfer_wait:
15707c478bd9Sstevel@tonic-gate  *
15717c478bd9Sstevel@tonic-gate  *	bmRequestType	- characteristics of request
15727c478bd9Sstevel@tonic-gate  *	bRequest	- specific request
15737c478bd9Sstevel@tonic-gate  *	wValue		- varies according to request
15747c478bd9Sstevel@tonic-gate  *	wIndex		- index or offset
15757c478bd9Sstevel@tonic-gate  *	wLength		- number of bytes to xfer
15767c478bd9Sstevel@tonic-gate  *	attrs		- required request attributes
15777c478bd9Sstevel@tonic-gate  *	data		- pointer to pointer to data
15787c478bd9Sstevel@tonic-gate  *				IN: HCD will allocate data
15797c478bd9Sstevel@tonic-gate  *				OUT: clients driver allocates data
15807c478bd9Sstevel@tonic-gate  */
15817c478bd9Sstevel@tonic-gate typedef struct usb_ctrl_setup {
15827c478bd9Sstevel@tonic-gate 	uchar_t		bmRequestType;
15837c478bd9Sstevel@tonic-gate 	uchar_t		bRequest;
15847c478bd9Sstevel@tonic-gate 	uint16_t	wValue;
15857c478bd9Sstevel@tonic-gate 	uint16_t	wIndex;
15867c478bd9Sstevel@tonic-gate 	uint16_t	wLength;
15877c478bd9Sstevel@tonic-gate 	usb_req_attrs_t	attrs;
15887c478bd9Sstevel@tonic-gate } usb_ctrl_setup_t;
15897c478bd9Sstevel@tonic-gate 
15907c478bd9Sstevel@tonic-gate 
15917c478bd9Sstevel@tonic-gate /*
15927c478bd9Sstevel@tonic-gate  * usb_pipe_ctrl_xfer_wait():
15937c478bd9Sstevel@tonic-gate  *	for simple synchronous control transactions this wrapper function
15947c478bd9Sstevel@tonic-gate  *	will perform the allocation, xfer, and deallocation.
15957c478bd9Sstevel@tonic-gate  *	USB_ATTRS_AUTOCLEARING will be enabled
15967c478bd9Sstevel@tonic-gate  *
15977c478bd9Sstevel@tonic-gate  * Arguments:
15987c478bd9Sstevel@tonic-gate  *	pipe_handle	- control pipe pipehandle (obtained via usb_pipe_open())
15997c478bd9Sstevel@tonic-gate  *	setup		- contains pointer to client's devinfo,
16007c478bd9Sstevel@tonic-gate  *			  setup descriptor params, attributes and data
16017c478bd9Sstevel@tonic-gate  *	completion_reason - completion status.
16027c478bd9Sstevel@tonic-gate  *	cb_flags	- request completions flags.
16037c478bd9Sstevel@tonic-gate  *	flags		- none.
16047c478bd9Sstevel@tonic-gate  *
16057c478bd9Sstevel@tonic-gate  * Return Values:
16067c478bd9Sstevel@tonic-gate  *	USB_SUCCESS	- request successfully executed.
16077c478bd9Sstevel@tonic-gate  *	USB_FAILURE	- request failed.
16087c478bd9Sstevel@tonic-gate  *	USB_*		- refer to list of all possible return values in
16097c478bd9Sstevel@tonic-gate  *			  this file
16107c478bd9Sstevel@tonic-gate  *
16117c478bd9Sstevel@tonic-gate  * NOTES:
16127c478bd9Sstevel@tonic-gate  * - in the case of failure, the client should check completion_reason and
16137c478bd9Sstevel@tonic-gate  *   and cb_flags and determine further recovery action
16147c478bd9Sstevel@tonic-gate  * - the client should check data and if non-zero, free the data on
16157c478bd9Sstevel@tonic-gate  *   completion
16167c478bd9Sstevel@tonic-gate  */
16177c478bd9Sstevel@tonic-gate int usb_pipe_ctrl_xfer_wait(
16187c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
16197c478bd9Sstevel@tonic-gate 	usb_ctrl_setup_t	*setup,
16207c478bd9Sstevel@tonic-gate 	mblk_t			**data,
16217c478bd9Sstevel@tonic-gate 	usb_cr_t		*completion_reason,
16227c478bd9Sstevel@tonic-gate 	usb_cb_flags_t		*cb_flags,
16237c478bd9Sstevel@tonic-gate 	usb_flags_t		flags);
16247c478bd9Sstevel@tonic-gate 
16257c478bd9Sstevel@tonic-gate 
16267c478bd9Sstevel@tonic-gate /*
16277c478bd9Sstevel@tonic-gate  * ---------------------------------------------------------------------------
16287c478bd9Sstevel@tonic-gate  * Some utility defines and wrapper functions for standard control requests.
16297c478bd9Sstevel@tonic-gate  * ---------------------------------------------------------------------------
16307c478bd9Sstevel@tonic-gate  */
16317c478bd9Sstevel@tonic-gate 
16327c478bd9Sstevel@tonic-gate /*
1633993e3fafSRobert Mustacchi  * USB STATUS request types and sizes.
1634993e3fafSRobert Mustacchi  */
1635993e3fafSRobert Mustacchi #define	USB_GET_STATUS_STANDARD		0
1636993e3fafSRobert Mustacchi #define	USB_GET_STATUS_PTM		1
1637993e3fafSRobert Mustacchi 
1638993e3fafSRobert Mustacchi #define	USB_GET_STATUS_LEN		2
1639993e3fafSRobert Mustacchi #define	USB_GET_STATUS_PTM_LEN		4
1640993e3fafSRobert Mustacchi 
1641993e3fafSRobert Mustacchi /*
1642993e3fafSRobert Mustacchi  * Status bits returned by a usb_get_status() for a STATUS_STANDARD request.
16437c478bd9Sstevel@tonic-gate  */
16447c478bd9Sstevel@tonic-gate #define	USB_DEV_SLF_PWRD_STATUS	1	/* Supports Self Power	 */
16457c478bd9Sstevel@tonic-gate #define	USB_DEV_RWAKEUP_STATUS	2	/* Remote Wakeup Enabled */
1646ff0e937bSRaymond Chen #define	USB_DEV_BAT_PWRD_STATUS	4	/* Battery Powered */
16477c478bd9Sstevel@tonic-gate #define	USB_EP_HALT_STATUS	1	/* Endpoint is Halted	 */
16487c478bd9Sstevel@tonic-gate #define	USB_IF_STATUS		0	/* Interface Status is 0 */
16497c478bd9Sstevel@tonic-gate 
16507c478bd9Sstevel@tonic-gate /*
16517c478bd9Sstevel@tonic-gate  * wrapper function returning status of device, interface, or endpoint
16527c478bd9Sstevel@tonic-gate  *
16537c478bd9Sstevel@tonic-gate  * Arguments:
16547c478bd9Sstevel@tonic-gate  *	dip		- devinfo pointer.
16557c478bd9Sstevel@tonic-gate  *	ph		- pipe handle
16567c478bd9Sstevel@tonic-gate  *	type		- bmRequestType to be used
16577c478bd9Sstevel@tonic-gate  *	what		- 0 for device, otherwise interface or ep number
16587c478bd9Sstevel@tonic-gate  *	status		- pointer to returned status.
16597c478bd9Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP (mandatory)
16607c478bd9Sstevel@tonic-gate  *
16617c478bd9Sstevel@tonic-gate  * Return Values:
16627c478bd9Sstevel@tonic-gate  *	valid usb_status_t	or USB_FAILURE
16637c478bd9Sstevel@tonic-gate  *
16647c478bd9Sstevel@tonic-gate  */
16657c478bd9Sstevel@tonic-gate int usb_get_status(
16667c478bd9Sstevel@tonic-gate 	dev_info_t		*dip,
16677c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	ph,
16687c478bd9Sstevel@tonic-gate 	uint_t			type,	/* bmRequestType */
16697c478bd9Sstevel@tonic-gate 	uint_t			what,	/* 0, interface, endpoint number */
16707c478bd9Sstevel@tonic-gate 	uint16_t		*status,
16717c478bd9Sstevel@tonic-gate 	usb_flags_t		flags);
16727c478bd9Sstevel@tonic-gate 
16737c478bd9Sstevel@tonic-gate 
16747c478bd9Sstevel@tonic-gate /*
16757c478bd9Sstevel@tonic-gate  * function for clearing feature of device, interface, or endpoint
16767c478bd9Sstevel@tonic-gate  *
16777c478bd9Sstevel@tonic-gate  * Arguments:
16787c478bd9Sstevel@tonic-gate  *	dip		- devinfo pointer.
16797c478bd9Sstevel@tonic-gate  *	type		- bmRequestType to be used
16807c478bd9Sstevel@tonic-gate  *	feature		- feature to be cleared
16817c478bd9Sstevel@tonic-gate  *	what		- 0 for device, otherwise interface or ep number
16827c478bd9Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP (mandatory)
16837c478bd9Sstevel@tonic-gate  *	cb		- if USB_FLAGS_SLEEP has not been specified
16847c478bd9Sstevel@tonic-gate  *			  this callback function will be called on
16857c478bd9Sstevel@tonic-gate  *			  completion. This callback may be NULL
16867c478bd9Sstevel@tonic-gate  *			  and no notification of completion will then
16877c478bd9Sstevel@tonic-gate  *			  be provided.
16887c478bd9Sstevel@tonic-gate  *	cb_arg		- 2nd argument to callback function.
16897c478bd9Sstevel@tonic-gate  *
16907c478bd9Sstevel@tonic-gate  * Return Values:
16917c478bd9Sstevel@tonic-gate  *	USB_SUCCESS	clearing feature succeeded
16927c478bd9Sstevel@tonic-gate  *	USB_FAILURE	clearing feature failed
16937c478bd9Sstevel@tonic-gate  *	USB_*		refer to list of all possible return values in
16947c478bd9Sstevel@tonic-gate  *			this file
16957c478bd9Sstevel@tonic-gate  */
16967c478bd9Sstevel@tonic-gate int usb_clr_feature(
16977c478bd9Sstevel@tonic-gate 	dev_info_t		*dip,
16987c478bd9Sstevel@tonic-gate 	uint_t			type,	/* bmRequestType */
16997c478bd9Sstevel@tonic-gate 	uint_t			feature,
17007c478bd9Sstevel@tonic-gate 	uint_t			what,	/* 0, interface, endpoint number */
17017c478bd9Sstevel@tonic-gate 	usb_flags_t		flags,
17027c478bd9Sstevel@tonic-gate 	void			(*cb)(
17037c478bd9Sstevel@tonic-gate 					usb_pipe_handle_t ph,
17047c478bd9Sstevel@tonic-gate 					usb_opaque_t	arg,
17057c478bd9Sstevel@tonic-gate 					int		rval,
17067c478bd9Sstevel@tonic-gate 					usb_cb_flags_t	flags),
17077c478bd9Sstevel@tonic-gate 	usb_opaque_t		cb_arg);
17087c478bd9Sstevel@tonic-gate 
17097c478bd9Sstevel@tonic-gate 
17107c478bd9Sstevel@tonic-gate /*
17117c478bd9Sstevel@tonic-gate  * usb_set_cfg():
17127c478bd9Sstevel@tonic-gate  *	Sets the configuration.  Use this function with caution as
17137c478bd9Sstevel@tonic-gate  *	the framework is normally responsible for configuration changes.
17147c478bd9Sstevel@tonic-gate  *	Changing configuration will fail if pipes are still open or
17157c478bd9Sstevel@tonic-gate  *	when invoked from a driver bound to an interface on a composite
17167c478bd9Sstevel@tonic-gate  *	device. This function access the device and blocks.
17177c478bd9Sstevel@tonic-gate  *
17187c478bd9Sstevel@tonic-gate  * Arguments:
17197c478bd9Sstevel@tonic-gate  *	dip		- devinfo pointer.
17207c478bd9Sstevel@tonic-gate  *	cfg_index	- Index of configuration to set.  Corresponds to
17217c478bd9Sstevel@tonic-gate  *			  index in the usb_client_dev_data_t tree of
17227c478bd9Sstevel@tonic-gate  *			  configurations.  See usb_client_dev_data_t(9F).
17237c478bd9Sstevel@tonic-gate  *	usb_flags	- USB_FLAGS_SLEEP:
17247c478bd9Sstevel@tonic-gate  *				wait for completion.
17257c478bd9Sstevel@tonic-gate  *	cb		- if USB_FLAGS_SLEEP has not been specified
17267c478bd9Sstevel@tonic-gate  *			  this callback function will be called on
17277c478bd9Sstevel@tonic-gate  *			  completion. This callback may be NULL
17287c478bd9Sstevel@tonic-gate  *			  and no notification of completion will then
17297c478bd9Sstevel@tonic-gate  *			  be provided.
17307c478bd9Sstevel@tonic-gate  *	cb_arg		- 2nd argument to callback function.
17317c478bd9Sstevel@tonic-gate  *
17327c478bd9Sstevel@tonic-gate  * callback and callback_arg should be NULL if USB_FLAGS_SLEEP has
17337c478bd9Sstevel@tonic-gate  * been specified
17347c478bd9Sstevel@tonic-gate  *
17357c478bd9Sstevel@tonic-gate  * Return Values:
17367c478bd9Sstevel@tonic-gate  *	USB_SUCCESS:	new configuration was set or async request
17377c478bd9Sstevel@tonic-gate  *			submitted successfully.
17387c478bd9Sstevel@tonic-gate  *	USB_FAILURE:	new configuration could not be set because
17397c478bd9Sstevel@tonic-gate  *			it may been illegal configuration or this
17407c478bd9Sstevel@tonic-gate  *			caller was not allowed to change configs or
17417c478bd9Sstevel@tonic-gate  *			pipes were still open or async request
17427c478bd9Sstevel@tonic-gate  *			could not be submitted.
17437c478bd9Sstevel@tonic-gate  *	USB_*		refer to list of all possible return values in
17447c478bd9Sstevel@tonic-gate  *			this file
17457c478bd9Sstevel@tonic-gate  *
17467c478bd9Sstevel@tonic-gate  * the pipe handle argument in the callback will be the default pipe handle
17477c478bd9Sstevel@tonic-gate  */
17487c478bd9Sstevel@tonic-gate int usb_set_cfg(
17497c478bd9Sstevel@tonic-gate 	dev_info_t		*dip,
17507c478bd9Sstevel@tonic-gate 	uint_t			cfg_index,
17517c478bd9Sstevel@tonic-gate 	usb_flags_t		usb_flags,
17527c478bd9Sstevel@tonic-gate 	void			(*cb)(
17537c478bd9Sstevel@tonic-gate 					usb_pipe_handle_t ph,
17547c478bd9Sstevel@tonic-gate 					usb_opaque_t	arg,
17557c478bd9Sstevel@tonic-gate 					int		rval,
17567c478bd9Sstevel@tonic-gate 					usb_cb_flags_t	flags),
17577c478bd9Sstevel@tonic-gate 	usb_opaque_t		cb_arg);
17587c478bd9Sstevel@tonic-gate 
17597c478bd9Sstevel@tonic-gate 
17607c478bd9Sstevel@tonic-gate /*
17617c478bd9Sstevel@tonic-gate  * usb_get_cfg:
17627c478bd9Sstevel@tonic-gate  *	dip		- pointer to devinfo node
17637c478bd9Sstevel@tonic-gate  *	cfgval		- pointer to cfgval
17647c478bd9Sstevel@tonic-gate  *	usb_flags	- none, will always block
17657c478bd9Sstevel@tonic-gate  *
17667c478bd9Sstevel@tonic-gate  * return values:
17677c478bd9Sstevel@tonic-gate  *	USB_SUCCESS	- current cfg value is returned to cfgval
17687c478bd9Sstevel@tonic-gate  *	USB_*		- refer to list of all possible return values in
17697c478bd9Sstevel@tonic-gate  *			  this file
17707c478bd9Sstevel@tonic-gate  */
17717c478bd9Sstevel@tonic-gate int usb_get_cfg(
17727c478bd9Sstevel@tonic-gate 	dev_info_t		*dip,
17737c478bd9Sstevel@tonic-gate 	uint_t			*cfgval,
17747c478bd9Sstevel@tonic-gate 	usb_flags_t		usb_flags);
17757c478bd9Sstevel@tonic-gate 
17767c478bd9Sstevel@tonic-gate 
17777c478bd9Sstevel@tonic-gate /*
17787c478bd9Sstevel@tonic-gate  * The following functions set or get the alternate interface
17797c478bd9Sstevel@tonic-gate  * setting.
17807c478bd9Sstevel@tonic-gate  *
17817c478bd9Sstevel@tonic-gate  * usb_set_alt_if:
17827c478bd9Sstevel@tonic-gate  *	dip		- pointer to devinfo node
17837c478bd9Sstevel@tonic-gate  *	interface	- interface
17847c478bd9Sstevel@tonic-gate  *	alt_number	- alternate to set to
17857c478bd9Sstevel@tonic-gate  *	usb_flags	- USB_FLAGS_SLEEP:
17867c478bd9Sstevel@tonic-gate  *				wait for completion.
17877c478bd9Sstevel@tonic-gate  *	cb		- if USB_FLAGS_SLEEP has not been specified
17887c478bd9Sstevel@tonic-gate  *			  this callback function will be called on
17897c478bd9Sstevel@tonic-gate  *			  completion. This callback may be NULL
17907c478bd9Sstevel@tonic-gate  *			  and no notification of completion will then
17917c478bd9Sstevel@tonic-gate  *			  be provided.
17927c478bd9Sstevel@tonic-gate  *	cb_arg		- 2nd argument to callback function.
17937c478bd9Sstevel@tonic-gate  *
17947c478bd9Sstevel@tonic-gate  * callback and callback_arg should be NULL if USB_FLAGS_SLEEP has
17957c478bd9Sstevel@tonic-gate  * been specified
17967c478bd9Sstevel@tonic-gate  *
17977c478bd9Sstevel@tonic-gate  * the pipe handle argument in the callback will be the default pipe handle
17987c478bd9Sstevel@tonic-gate  *
17997c478bd9Sstevel@tonic-gate  * return values:
18007c478bd9Sstevel@tonic-gate  *	USB_SUCCESS:	alternate was set or async request was
18017c478bd9Sstevel@tonic-gate  *			submitted.
18027c478bd9Sstevel@tonic-gate  *	USB_FAILURE:	alternate could not be set because pipes
18037c478bd9Sstevel@tonic-gate  *			were still open or some access error occurred
18047c478bd9Sstevel@tonic-gate  *			or an invalid alt if value was passed or
18057c478bd9Sstevel@tonic-gate  *			async request could not be submitted
18067c478bd9Sstevel@tonic-gate  *	USB_INVALID_PERM the driver does not own the device or the interface
18077c478bd9Sstevel@tonic-gate  *	USB_*		refer to list of all possible return values in
18087c478bd9Sstevel@tonic-gate  *			this file
18097c478bd9Sstevel@tonic-gate  */
18107c478bd9Sstevel@tonic-gate int usb_set_alt_if(
18117c478bd9Sstevel@tonic-gate 	dev_info_t		*dip,
18127c478bd9Sstevel@tonic-gate 	uint_t			interface,
18137c478bd9Sstevel@tonic-gate 	uint_t			alt_number,
18147c478bd9Sstevel@tonic-gate 	usb_flags_t		usb_flags,
18157c478bd9Sstevel@tonic-gate 	void			(*cb)(
18167c478bd9Sstevel@tonic-gate 					usb_pipe_handle_t ph,
18177c478bd9Sstevel@tonic-gate 					usb_opaque_t	arg,
18187c478bd9Sstevel@tonic-gate 					int		rval,
18197c478bd9Sstevel@tonic-gate 					usb_cb_flags_t	flags),
18207c478bd9Sstevel@tonic-gate 	usb_opaque_t		cb_arg);
18217c478bd9Sstevel@tonic-gate 
18227c478bd9Sstevel@tonic-gate 
18237c478bd9Sstevel@tonic-gate 
18247c478bd9Sstevel@tonic-gate /* flags must be USB_FLAGS_SLEEP, and this function will block */
18257c478bd9Sstevel@tonic-gate int usb_get_alt_if(
18267c478bd9Sstevel@tonic-gate 	dev_info_t		*dip,
18277c478bd9Sstevel@tonic-gate 	uint_t			if_number,
18287c478bd9Sstevel@tonic-gate 	uint_t			*alt_number,
18297c478bd9Sstevel@tonic-gate 	usb_flags_t		flags);
18307c478bd9Sstevel@tonic-gate 
18317c478bd9Sstevel@tonic-gate 
18327c478bd9Sstevel@tonic-gate /*
18337c478bd9Sstevel@tonic-gate  * ===========================================================================
18347c478bd9Sstevel@tonic-gate  * USB bulk request management
18357c478bd9Sstevel@tonic-gate  * ===========================================================================
18367c478bd9Sstevel@tonic-gate  */
18377c478bd9Sstevel@tonic-gate 
18387c478bd9Sstevel@tonic-gate /*
18397c478bd9Sstevel@tonic-gate  * A client driver allocates/uses the usb_bulk_req_t for bulk pipe xfers.
18407c478bd9Sstevel@tonic-gate  *
18417c478bd9Sstevel@tonic-gate  * NOTES:
18427c478bd9Sstevel@tonic-gate  * - bulk pipe sharing is not supported
18437c478bd9Sstevel@tonic-gate  * - semantics of combinations of flag and attributes:
18447c478bd9Sstevel@tonic-gate  *
18457c478bd9Sstevel@tonic-gate  * flags     Type  attributes	data	timeout semantics
18467c478bd9Sstevel@tonic-gate  * ----------------------------------------------------------------
18477c478bd9Sstevel@tonic-gate  *  x	      x    x		== NULL    x	   illegal
18487c478bd9Sstevel@tonic-gate  *
18497c478bd9Sstevel@tonic-gate  * no sleep  IN    x		!= NULL    0	   fill buffer, no timeout
18507c478bd9Sstevel@tonic-gate  *						   callback when xfer-len has
18517c478bd9Sstevel@tonic-gate  *						   been xferred
18527c478bd9Sstevel@tonic-gate  * no sleep  IN    x		!= NULL    > 0	   fill buffer, with timeout
18537c478bd9Sstevel@tonic-gate  *						   callback when xfer-len has
18547c478bd9Sstevel@tonic-gate  *						   been xferred
18557c478bd9Sstevel@tonic-gate  *
18567c478bd9Sstevel@tonic-gate  * sleep     IN    x		!= NULL    0	   fill buffer, no timeout
18577c478bd9Sstevel@tonic-gate  *						   unblock when xfer-len has
18587c478bd9Sstevel@tonic-gate  *						   been xferred
18597c478bd9Sstevel@tonic-gate  *						   no callback
18607c478bd9Sstevel@tonic-gate  * sleep     IN    x		!= NULL    > 0	   fill buffer, with timeout
18617c478bd9Sstevel@tonic-gate  *						   unblock when xfer-len has
18627c478bd9Sstevel@tonic-gate  *						   been xferred or timeout
18637c478bd9Sstevel@tonic-gate  *						   no callback
18647c478bd9Sstevel@tonic-gate  *
18657c478bd9Sstevel@tonic-gate  *  X	     OUT SHORT_XFER_OK	  x	   x	   illegal
18667c478bd9Sstevel@tonic-gate  *
18677c478bd9Sstevel@tonic-gate  * no sleep  OUT   x		!= NULL    0	   empty buffer, no timeout
18687c478bd9Sstevel@tonic-gate  *						   callback when xfer-len has
18697c478bd9Sstevel@tonic-gate  *						   been xferred
18707c478bd9Sstevel@tonic-gate  * no sleep  OUT   x		!= NULL    > 0	   empty buffer, with timeout
18717c478bd9Sstevel@tonic-gate  *						   callback when xfer-len has
18727c478bd9Sstevel@tonic-gate  *						   been xferred or timeout
18737c478bd9Sstevel@tonic-gate  *
18747c478bd9Sstevel@tonic-gate  * sleep     OUT   x		!= NULL    0	   empty buffer, no timeout
18757c478bd9Sstevel@tonic-gate  *						   unblock when xfer-len has
18767c478bd9Sstevel@tonic-gate  *						   been xferred
18777c478bd9Sstevel@tonic-gate  *						   no callback
18787c478bd9Sstevel@tonic-gate  * sleep     OUT   x		!= NULL    > 0	   empty buffer, with timeout
18797c478bd9Sstevel@tonic-gate  *						   unblock when xfer-len has
18807c478bd9Sstevel@tonic-gate  *						   been xferred or timeout
18817c478bd9Sstevel@tonic-gate  *						   no callback
18827c478bd9Sstevel@tonic-gate  *
18837c478bd9Sstevel@tonic-gate  * - bulk_len and bulk_data must be > 0.  SHORT_XFER_OK is not applicable.
18847c478bd9Sstevel@tonic-gate  *
18857c478bd9Sstevel@tonic-gate  * - multiple bulk requests can be queued
18867c478bd9Sstevel@tonic-gate  *
18877c478bd9Sstevel@tonic-gate  * - Splitting large Bulk xfer:
18887c478bd9Sstevel@tonic-gate  * The HCD driver, due to internal constraints, can only do a limited size bulk
18897c478bd9Sstevel@tonic-gate  * data xfer per request.  The current limitations are 32K for UHCI and 128K
18907c478bd9Sstevel@tonic-gate  * for OHCI.  So, a client driver may first determine this limitation (by
18917c478bd9Sstevel@tonic-gate  * calling the USBA interface usb_pipe_bulk_transfer_size()); and restrict
18927c478bd9Sstevel@tonic-gate  * itself to doing xfers in multiples of this fixed size.  This forces a client
18937c478bd9Sstevel@tonic-gate  * driver to do data xfers in a loop for a large request, splitting it into
18947c478bd9Sstevel@tonic-gate  * multiple chunks of fixed size.
18957c478bd9Sstevel@tonic-gate  */
18967c478bd9Sstevel@tonic-gate typedef struct usb_bulk_req {
18977c478bd9Sstevel@tonic-gate 	uint_t		bulk_len;	/* number of bytes to xfer	*/
18987c478bd9Sstevel@tonic-gate 	mblk_t		*bulk_data;	/* the data for the data phase	*/
18997c478bd9Sstevel@tonic-gate 					/* IN: allocated by HCD		*/
19007c478bd9Sstevel@tonic-gate 					/* OUT: allocated by client	*/
19017c478bd9Sstevel@tonic-gate 	uint_t		bulk_timeout;	/* xfer timeout value in secs	*/
19027c478bd9Sstevel@tonic-gate 	usb_opaque_t	bulk_client_private; /* Client specific information */
19037c478bd9Sstevel@tonic-gate 	usb_req_attrs_t bulk_attributes; /* xfer-attributes	*/
19047c478bd9Sstevel@tonic-gate 
19057c478bd9Sstevel@tonic-gate 	/* Normal Callback function (For synch xfers) */
19067c478bd9Sstevel@tonic-gate 	void		(*bulk_cb)(usb_pipe_handle_t ph,
19077c478bd9Sstevel@tonic-gate 				struct usb_bulk_req *req);
19087c478bd9Sstevel@tonic-gate 
19097c478bd9Sstevel@tonic-gate 	/* Exception Callback function (For asynch xfers) */
19107c478bd9Sstevel@tonic-gate 	void		(*bulk_exc_cb)(usb_pipe_handle_t ph,
19117c478bd9Sstevel@tonic-gate 				struct usb_bulk_req *req);
19127c478bd9Sstevel@tonic-gate 
19137c478bd9Sstevel@tonic-gate 	/* set by USBA/HCD on completion */
19147c478bd9Sstevel@tonic-gate 	usb_cr_t	bulk_completion_reason;	/* set by HCD		*/
19157c478bd9Sstevel@tonic-gate 	usb_cb_flags_t	bulk_cb_flags;  /* Callback context / handling flgs */
19167c478bd9Sstevel@tonic-gate } usb_bulk_req_t;
19177c478bd9Sstevel@tonic-gate 
19187c478bd9Sstevel@tonic-gate 
19197c478bd9Sstevel@tonic-gate /*
19207c478bd9Sstevel@tonic-gate  * Allocate/free usb bulk request
19217c478bd9Sstevel@tonic-gate  *
19227c478bd9Sstevel@tonic-gate  * Arguments:
19237c478bd9Sstevel@tonic-gate  *	dip		- pointer to dev_info_t of the client driver
19247c478bd9Sstevel@tonic-gate  *	len		- 0 or length of mblk to be allocated
19257c478bd9Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
19267c478bd9Sstevel@tonic-gate  *				wait for resources
19277c478bd9Sstevel@tonic-gate  *
19287c478bd9Sstevel@tonic-gate  * Return Values:
19297c478bd9Sstevel@tonic-gate  *	usb_bulk_req_t on success, NULL on failure
19307c478bd9Sstevel@tonic-gate  */
19317c478bd9Sstevel@tonic-gate usb_bulk_req_t *usb_alloc_bulk_req(
19327c478bd9Sstevel@tonic-gate 	dev_info_t		*dip,
19337c478bd9Sstevel@tonic-gate 	size_t			len,
19347c478bd9Sstevel@tonic-gate 	usb_flags_t		flags);
19357c478bd9Sstevel@tonic-gate 
19367c478bd9Sstevel@tonic-gate 
19377c478bd9Sstevel@tonic-gate void usb_free_bulk_req(
19387c478bd9Sstevel@tonic-gate 	usb_bulk_req_t	*reqp);
19397c478bd9Sstevel@tonic-gate 
19407c478bd9Sstevel@tonic-gate 
19417c478bd9Sstevel@tonic-gate /*
19427c478bd9Sstevel@tonic-gate  * usb_pipe_bulk_xfer():
19437c478bd9Sstevel@tonic-gate  *
19447c478bd9Sstevel@tonic-gate  * Client drivers call this function to issue the bulk xfer to the USBA
19457c478bd9Sstevel@tonic-gate  * which will queue or transfer it to the device
19467c478bd9Sstevel@tonic-gate  *
19477c478bd9Sstevel@tonic-gate  * Arguments:
19487c478bd9Sstevel@tonic-gate  *	pipe_handle	- bulk pipe handle (obtained via usb_pipe_open()
19497c478bd9Sstevel@tonic-gate  *	reqp		- pointer to bulk data xfer request (IN or OUT)
19507c478bd9Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
19517c478bd9Sstevel@tonic-gate  *				wait for the request to complete
19527c478bd9Sstevel@tonic-gate  *
19537c478bd9Sstevel@tonic-gate  * Return Values:
19547c478bd9Sstevel@tonic-gate  *	USB_SUCCESS	- success
19557c478bd9Sstevel@tonic-gate  *	USB_FAILURE	- unspecified failure
19567c478bd9Sstevel@tonic-gate  *	USB_NO_RESOURCES - no resources
19577c478bd9Sstevel@tonic-gate  *
19587c478bd9Sstevel@tonic-gate  */
19597c478bd9Sstevel@tonic-gate int usb_pipe_bulk_xfer(
19607c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
19617c478bd9Sstevel@tonic-gate 	usb_bulk_req_t		*reqp,
19627c478bd9Sstevel@tonic-gate 	usb_flags_t		flags);
19637c478bd9Sstevel@tonic-gate 
19647c478bd9Sstevel@tonic-gate /* Get maximum bulk transfer size */
19657c478bd9Sstevel@tonic-gate int usb_pipe_get_max_bulk_transfer_size(
19667c478bd9Sstevel@tonic-gate 	dev_info_t		*dip,
19677c478bd9Sstevel@tonic-gate 	size_t			*size);
19687c478bd9Sstevel@tonic-gate 
19697c478bd9Sstevel@tonic-gate 
19707c478bd9Sstevel@tonic-gate /*
19717c478bd9Sstevel@tonic-gate  * ===========================================================================
19727c478bd9Sstevel@tonic-gate  * USB interrupt pipe request management
19737c478bd9Sstevel@tonic-gate  * ===========================================================================
19747c478bd9Sstevel@tonic-gate  */
19757c478bd9Sstevel@tonic-gate 
19767c478bd9Sstevel@tonic-gate /*
19777c478bd9Sstevel@tonic-gate  * A client driver allocates and uses the usb_intr_req_t for
19787c478bd9Sstevel@tonic-gate  * all interrupt pipe transfers.
19797c478bd9Sstevel@tonic-gate  *
19807c478bd9Sstevel@tonic-gate  * USB_FLAGS_SLEEP indicates here just to wait for resources except
19817c478bd9Sstevel@tonic-gate  * for ONE_XFER where we also wait for completion
19827c478bd9Sstevel@tonic-gate  *
19837c478bd9Sstevel@tonic-gate  * semantics flags and attribute combinations:
19847c478bd9Sstevel@tonic-gate  *
19857c478bd9Sstevel@tonic-gate  * Notes:
19867c478bd9Sstevel@tonic-gate  * none attributes indicates neither ONE_XFER nor SHORT_XFER_OK
19877c478bd9Sstevel@tonic-gate  *
19887c478bd9Sstevel@tonic-gate  * flags     Type  attributes	   data    timeout semantics
19897c478bd9Sstevel@tonic-gate  * ----------------------------------------------------------------
19907c478bd9Sstevel@tonic-gate  *  x	     IN      x		   != NULL  x	    illegal
19917c478bd9Sstevel@tonic-gate  *  x	     IN   ONE_XFER=0	   x	   !=0	    illegal
19927c478bd9Sstevel@tonic-gate  *
19937c478bd9Sstevel@tonic-gate  *  x	     IN   ONE_XFER=0	   NULL     0	   continuous polling,
19947c478bd9Sstevel@tonic-gate  *						   many callbacks
19957c478bd9Sstevel@tonic-gate  *						   request is returned on
19967c478bd9Sstevel@tonic-gate  *						   stop polling
19977c478bd9Sstevel@tonic-gate  *
19987c478bd9Sstevel@tonic-gate  * no sleep  IN   ONE_XFER	   NULL     0	   one time poll, no timeout,
19997c478bd9Sstevel@tonic-gate  *						   one callback
20007c478bd9Sstevel@tonic-gate  * no sleep  IN   ONE_XFER	   NULL    !=0	   one time poll, with
20017c478bd9Sstevel@tonic-gate  *						   timeout, one callback
20027c478bd9Sstevel@tonic-gate  *
20037c478bd9Sstevel@tonic-gate  * sleep     IN   ONE_XFER	   NULL     0	   one time poll, no timeout,
20047c478bd9Sstevel@tonic-gate  *						   no callback,
20057c478bd9Sstevel@tonic-gate  *						   block for completion
20067c478bd9Sstevel@tonic-gate  * sleep     IN   ONE_XFER	   NULL    !=0	   one time poll, with timeout,
20077c478bd9Sstevel@tonic-gate  *						   no callback
20087c478bd9Sstevel@tonic-gate  *						   block for completion
20097c478bd9Sstevel@tonic-gate  *
20107c478bd9Sstevel@tonic-gate  *  x	     OUT     x		   NULL    x	   illegal
20117c478bd9Sstevel@tonic-gate  *  x	     OUT  ONE_XFER	   x	   x	   illegal
20127c478bd9Sstevel@tonic-gate  *  x	     OUT  SHORT_XFER_OK    x	   x	   illegal
20137c478bd9Sstevel@tonic-gate  *
20147c478bd9Sstevel@tonic-gate  *  x	     OUT   none		   != NULL 0	   xfer until data exhausted,
20157c478bd9Sstevel@tonic-gate  *						   no timeout,	one callback
20167c478bd9Sstevel@tonic-gate  *  x	     OUT   none		   != NULL !=0	   xfer until data exhausted,
20177c478bd9Sstevel@tonic-gate  *						   with timeout, one callback
20187c478bd9Sstevel@tonic-gate  *
20197c478bd9Sstevel@tonic-gate  * - Reads (IN):
20207c478bd9Sstevel@tonic-gate  *
20217c478bd9Sstevel@tonic-gate  * The client driver does *not* provide a data buffer.
20227c478bd9Sstevel@tonic-gate  * By default, a READ request would mean continuous polling for data IN. The
20237c478bd9Sstevel@tonic-gate  * HCD typically reads "wMaxPacketSize" amount of 'periodic data'. A client
20247c478bd9Sstevel@tonic-gate  * driver may force the HCD to read instead intr_len
20257c478bd9Sstevel@tonic-gate  * amount of 'periodic data' (See section 1).
20267c478bd9Sstevel@tonic-gate  *
20277c478bd9Sstevel@tonic-gate  * The HCD issues a callback to the client after each polling interval if
20287c478bd9Sstevel@tonic-gate  * it has read in some data. Note that the amount of data read IN is either
20297c478bd9Sstevel@tonic-gate  * intr_len or 'wMaxPacketSize' in length.
20307c478bd9Sstevel@tonic-gate  *
20317c478bd9Sstevel@tonic-gate  * Normally, the HCD keeps polling interrupt pipe forever even if there is
20327c478bd9Sstevel@tonic-gate  * no data to be read IN.  A client driver may stop this polling by
20337c478bd9Sstevel@tonic-gate  * calling usb_pipe_stop_intr_polling().
20347c478bd9Sstevel@tonic-gate  *
20357c478bd9Sstevel@tonic-gate  * If a client driver chooses to pass USB_ATTRS_ONE_XFER as
20367c478bd9Sstevel@tonic-gate  * 'xfer_attributes' the HCD will poll for data until some data is received.
20377c478bd9Sstevel@tonic-gate  * HCD reads in the data and does a callback and stops polling for any more
20387c478bd9Sstevel@tonic-gate  * data.  In this case, the client driver need not explicitly call
20397c478bd9Sstevel@tonic-gate  * usb_pipe_stop_intr_polling().
20407c478bd9Sstevel@tonic-gate  *
20417c478bd9Sstevel@tonic-gate  * When continuous polling is stopped, the original request is returned with
20427c478bd9Sstevel@tonic-gate  * USB_CR_STOPPED_POLLING.
20437c478bd9Sstevel@tonic-gate  *
20447c478bd9Sstevel@tonic-gate  * - Writes (OUT):
20457c478bd9Sstevel@tonic-gate  *
20467c478bd9Sstevel@tonic-gate  * A client driver provides the data buffer, and data, needed for intr write.
20477c478bd9Sstevel@tonic-gate  * There is no continuous write mode, a la  read (See previous section).
20487c478bd9Sstevel@tonic-gate  * The USB_ATTRS_ONE_XFER attribute is illegal.
20497c478bd9Sstevel@tonic-gate  * By default USBA keeps writing intr data until the provided data buffer
20507c478bd9Sstevel@tonic-gate  * has been written out. The HCD does ONE callback to the client driver.
20517c478bd9Sstevel@tonic-gate  * Queueing is supported.
20527c478bd9Sstevel@tonic-gate  * Max size is 8k
20537c478bd9Sstevel@tonic-gate  */
20547c478bd9Sstevel@tonic-gate typedef struct usb_intr_req {
20557c478bd9Sstevel@tonic-gate 	uint_t		intr_len;	/* OUT: size of total xfer */
20567c478bd9Sstevel@tonic-gate 					/* IN : packet size */
20577c478bd9Sstevel@tonic-gate 	mblk_t		*intr_data;	/* the data for the data phase	*/
20587c478bd9Sstevel@tonic-gate 					/* IN: allocated by HCD		*/
20597c478bd9Sstevel@tonic-gate 					/* OUT: allocated by client	*/
20607c478bd9Sstevel@tonic-gate 	usb_opaque_t	intr_client_private; /* Client specific information  */
20617c478bd9Sstevel@tonic-gate 	uint_t		intr_timeout;	/* only with ONE TIME POLL, in secs */
20627c478bd9Sstevel@tonic-gate 	usb_req_attrs_t	intr_attributes;
20637c478bd9Sstevel@tonic-gate 
20647c478bd9Sstevel@tonic-gate 	/* Normal callback function (For synch transfers) */
20657c478bd9Sstevel@tonic-gate 	void		(*intr_cb)(usb_pipe_handle_t ph,
20667c478bd9Sstevel@tonic-gate 				struct usb_intr_req *req);
20677c478bd9Sstevel@tonic-gate 
20687c478bd9Sstevel@tonic-gate 	/* Exception callback function (For asynch transfers) */
20697c478bd9Sstevel@tonic-gate 	void		(*intr_exc_cb)(usb_pipe_handle_t ph,
20707c478bd9Sstevel@tonic-gate 				struct usb_intr_req *req);
20717c478bd9Sstevel@tonic-gate 
20727c478bd9Sstevel@tonic-gate 	/* set by USBA/HCD on completion */
20737c478bd9Sstevel@tonic-gate 	usb_cr_t	intr_completion_reason;	/* set by HCD */
20747c478bd9Sstevel@tonic-gate 	usb_cb_flags_t	intr_cb_flags;  /* Callback context / handling flgs */
20757c478bd9Sstevel@tonic-gate } usb_intr_req_t;
20767c478bd9Sstevel@tonic-gate 
20777c478bd9Sstevel@tonic-gate 
20787c478bd9Sstevel@tonic-gate /*
20797c478bd9Sstevel@tonic-gate  * Allocate/free usb interrupt pipe request
20807c478bd9Sstevel@tonic-gate  *
20817c478bd9Sstevel@tonic-gate  * Arguments:
20827c478bd9Sstevel@tonic-gate  *	dip		- pointer to dev_info_t of the client driver
20837c478bd9Sstevel@tonic-gate  *	reqp		- pointer to request structure
20847c478bd9Sstevel@tonic-gate  *	len		- 0 or length of mblk for this interrupt request
20857c478bd9Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
20867c478bd9Sstevel@tonic-gate  *				Sleep if resources are not available
20877c478bd9Sstevel@tonic-gate  *
20887c478bd9Sstevel@tonic-gate  * Return Values:
20897c478bd9Sstevel@tonic-gate  *	usb_intr_req_t on success, NULL on failure
20907c478bd9Sstevel@tonic-gate  */
20917c478bd9Sstevel@tonic-gate usb_intr_req_t *usb_alloc_intr_req(
20927c478bd9Sstevel@tonic-gate 	dev_info_t		*dip,
20937c478bd9Sstevel@tonic-gate 	size_t			len,
20947c478bd9Sstevel@tonic-gate 	usb_flags_t		flags);
20957c478bd9Sstevel@tonic-gate 
20967c478bd9Sstevel@tonic-gate 
20977c478bd9Sstevel@tonic-gate void usb_free_intr_req(
20987c478bd9Sstevel@tonic-gate 	usb_intr_req_t	*reqp);
20997c478bd9Sstevel@tonic-gate 
21007c478bd9Sstevel@tonic-gate 
21017c478bd9Sstevel@tonic-gate /*
21027c478bd9Sstevel@tonic-gate  * usb_pipe_intr_xfer():
21037c478bd9Sstevel@tonic-gate  *
21047c478bd9Sstevel@tonic-gate  * Client drivers call this function to issue the intr xfer to USBA/HCD
21057c478bd9Sstevel@tonic-gate  * which starts polling the device
21067c478bd9Sstevel@tonic-gate  *
21077c478bd9Sstevel@tonic-gate  * Arguments:
21087c478bd9Sstevel@tonic-gate  *	pipe_handle	- interrupt pipe handle (obtained via usb_pipe_open()
21097c478bd9Sstevel@tonic-gate  *	reqp		- pointer tothe interrupt pipe xfer request (IN or OUT)
21107c478bd9Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
21117c478bd9Sstevel@tonic-gate  *				wait for resources to be available
21127c478bd9Sstevel@tonic-gate  *
21137c478bd9Sstevel@tonic-gate  * return values:
21147c478bd9Sstevel@tonic-gate  *	USB_SUCCESS	- success
21157c478bd9Sstevel@tonic-gate  *	USB_FAILURE	- unspecified failure
21167c478bd9Sstevel@tonic-gate  *	USB_NO_RESOURCES  - no resources
21177c478bd9Sstevel@tonic-gate  *
21187c478bd9Sstevel@tonic-gate  * NOTE: start polling on an IN pipe that is already being polled is a NOP.
21197c478bd9Sstevel@tonic-gate  *	 We don't queue requests on OUT pipe
21207c478bd9Sstevel@tonic-gate  */
21217c478bd9Sstevel@tonic-gate int usb_pipe_intr_xfer(
21227c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
21237c478bd9Sstevel@tonic-gate 	usb_intr_req_t		*req,
21247c478bd9Sstevel@tonic-gate 	usb_flags_t		flags);
21257c478bd9Sstevel@tonic-gate 
21267c478bd9Sstevel@tonic-gate 
21277c478bd9Sstevel@tonic-gate /*
21287c478bd9Sstevel@tonic-gate  * usb_pipe_stop_intr_polling():
21297c478bd9Sstevel@tonic-gate  *
21307c478bd9Sstevel@tonic-gate  * Client drivers call this function to stop the automatic data-in/out transfers
21317c478bd9Sstevel@tonic-gate  * without closing the pipe.
21327c478bd9Sstevel@tonic-gate  *
21337c478bd9Sstevel@tonic-gate  * If USB_FLAGS_SLEEP  has been specified then this function will block until
21347c478bd9Sstevel@tonic-gate  * polling has been stopped and all callbacks completed. If USB_FLAGS_SLEEP
21357c478bd9Sstevel@tonic-gate  * has NOT been specified then polling is terminated when the original
21367c478bd9Sstevel@tonic-gate  * request that started the polling has been returned with
21377c478bd9Sstevel@tonic-gate  * USB_CR_STOPPED_POLLING
21387c478bd9Sstevel@tonic-gate  *
21397c478bd9Sstevel@tonic-gate  * Stop polling should never fail.
21407c478bd9Sstevel@tonic-gate  *
21417c478bd9Sstevel@tonic-gate  * Args:-
21427c478bd9Sstevel@tonic-gate  *	pipe_handle	- interrupt pipe handle (obtained via usb_pipe_open()).
21437c478bd9Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
21447c478bd9Sstevel@tonic-gate  *				wait for the resources to be available.
21457c478bd9Sstevel@tonic-gate  */
21467c478bd9Sstevel@tonic-gate void usb_pipe_stop_intr_polling(
21477c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
21487c478bd9Sstevel@tonic-gate 	usb_flags_t		flags);
21497c478bd9Sstevel@tonic-gate 
21507c478bd9Sstevel@tonic-gate 
21517c478bd9Sstevel@tonic-gate /*
21527c478bd9Sstevel@tonic-gate  * ===========================================================================
21537c478bd9Sstevel@tonic-gate  * USB isochronous xfer management
21547c478bd9Sstevel@tonic-gate  * ===========================================================================
21557c478bd9Sstevel@tonic-gate  */
21567c478bd9Sstevel@tonic-gate 
21577c478bd9Sstevel@tonic-gate /*
21587c478bd9Sstevel@tonic-gate  * The usb frame number is an absolute number since boot and incremented
21597c478bd9Sstevel@tonic-gate  * every 1 ms.
21607c478bd9Sstevel@tonic-gate  */
21617c478bd9Sstevel@tonic-gate typedef	uint64_t	usb_frame_number_t;
21627c478bd9Sstevel@tonic-gate 
21637c478bd9Sstevel@tonic-gate /*
21647c478bd9Sstevel@tonic-gate  * USB ischronous packet descriptor
21657c478bd9Sstevel@tonic-gate  *
21667c478bd9Sstevel@tonic-gate  * An array of structures of type usb_isoc_pkt_descr_t must be allocated and
21677c478bd9Sstevel@tonic-gate  * initialized by the client driver using usb_alloc_isoc_req(). The client
21687c478bd9Sstevel@tonic-gate  * driver must set isoc_pkt_length in each packet descriptor before submitting
21697c478bd9Sstevel@tonic-gate  * the request.
21707c478bd9Sstevel@tonic-gate  */
21717c478bd9Sstevel@tonic-gate typedef struct usb_isoc_pkt_descr {
21727c478bd9Sstevel@tonic-gate 	/*
21737c478bd9Sstevel@tonic-gate 	 * Set by the client driver, for all isochronous requests, to the
21747c478bd9Sstevel@tonic-gate 	 * number of bytes to transfer in a frame.
21757c478bd9Sstevel@tonic-gate 	 */
21767c478bd9Sstevel@tonic-gate 	ushort_t	isoc_pkt_length;
21777c478bd9Sstevel@tonic-gate 
21787c478bd9Sstevel@tonic-gate 	/*
21797c478bd9Sstevel@tonic-gate 	 * Set by HCD to actual number of bytes sent/received in frame.
21807c478bd9Sstevel@tonic-gate 	 */
21817c478bd9Sstevel@tonic-gate 	ushort_t	isoc_pkt_actual_length;
21827c478bd9Sstevel@tonic-gate 
21837c478bd9Sstevel@tonic-gate 	/*
21847c478bd9Sstevel@tonic-gate 	 * Per frame status set by HCD both for the isochronous IN and OUT
21857c478bd9Sstevel@tonic-gate 	 * requests.  If any status is non-zero then isoc_error_count in the
21867c478bd9Sstevel@tonic-gate 	 * isoc_req will be non-zero.
21877c478bd9Sstevel@tonic-gate 	 */
21887c478bd9Sstevel@tonic-gate 	usb_cr_t	isoc_pkt_status;
21897c478bd9Sstevel@tonic-gate } usb_isoc_pkt_descr_t;
21907c478bd9Sstevel@tonic-gate 
21917c478bd9Sstevel@tonic-gate 
21927c478bd9Sstevel@tonic-gate /*
21937c478bd9Sstevel@tonic-gate  * USB isochronous request
21947c478bd9Sstevel@tonic-gate  *
21957c478bd9Sstevel@tonic-gate  * The client driver allocates the usb_isoc_req_t before sending an
21967c478bd9Sstevel@tonic-gate  * isochronous requests.
21977c478bd9Sstevel@tonic-gate  *
21987c478bd9Sstevel@tonic-gate  * USB_FLAGS_SLEEP indicates here just to wait for resources but not
21997c478bd9Sstevel@tonic-gate  * to wait for completion
22007c478bd9Sstevel@tonic-gate  *
22017c478bd9Sstevel@tonic-gate  * Semantics of various combinations for data xfers:
22027c478bd9Sstevel@tonic-gate  *
22037c478bd9Sstevel@tonic-gate  * Note: attributes considered in this table are ONE_XFER, START_FRAME,
22047c478bd9Sstevel@tonic-gate  *	XFER_ASAP, SHORT_XFER
22057c478bd9Sstevel@tonic-gate  *
22067c478bd9Sstevel@tonic-gate  *
22077c478bd9Sstevel@tonic-gate  * flags     Type  attributes		   data    semantics
22087c478bd9Sstevel@tonic-gate  * ---------------------------------------------------------------------
22097c478bd9Sstevel@tonic-gate  * x	     x	   x			NULL	   illegal
22107c478bd9Sstevel@tonic-gate  *
22117c478bd9Sstevel@tonic-gate  * x	     x	   ONE_XFER		 x	   illegal
22127c478bd9Sstevel@tonic-gate  *
22137c478bd9Sstevel@tonic-gate  * x	     IN    x			!=NULL	   continuous polling,
22147c478bd9Sstevel@tonic-gate  *						   many callbacks
22157c478bd9Sstevel@tonic-gate  *
22167c478bd9Sstevel@tonic-gate  * x	     IN    ISOC_START_FRAME	!=NULL	   invalid if Current_frame# >
22177c478bd9Sstevel@tonic-gate  *						   "isoc_frame_no"
22187c478bd9Sstevel@tonic-gate  * x	     IN    ISOC_XFER_ASAP	!=NULL	   "isoc_frame_no" ignored.
22197c478bd9Sstevel@tonic-gate  *						   HCD determines when to
22207c478bd9Sstevel@tonic-gate  *						   insert xfer
22217c478bd9Sstevel@tonic-gate  *
22227c478bd9Sstevel@tonic-gate  * x	     OUT   ONE_XFER		x	   illegal
22237c478bd9Sstevel@tonic-gate  * x	     OUT   SHORT_XFER_OK	x	   illegal
22247c478bd9Sstevel@tonic-gate  *
22257c478bd9Sstevel@tonic-gate  * x	     OUT   ISOC_START_FRAME	!=NULL	   invalid if Current_frame# >
22267c478bd9Sstevel@tonic-gate  *						   "isoc_frame_no"
22277c478bd9Sstevel@tonic-gate  * x	     OUT   ISOC_XFER_ASAP	!=NULL	   "isoc_frame_no" ignored.
22287c478bd9Sstevel@tonic-gate  *						    HCD determines when to
22297c478bd9Sstevel@tonic-gate  *						   insert xfer
22307c478bd9Sstevel@tonic-gate  */
22317c478bd9Sstevel@tonic-gate typedef struct usb_isoc_req {
22327c478bd9Sstevel@tonic-gate 	/*
22337c478bd9Sstevel@tonic-gate 	 * Starting frame number will be set by the client driver in which
22347c478bd9Sstevel@tonic-gate 	 * to begin this request. This frame number is used to synchronize
22357c478bd9Sstevel@tonic-gate 	 * requests queued to different isochronous pipes. The frame number
22367c478bd9Sstevel@tonic-gate 	 * is optional and client driver can skip starting frame number by
22377c478bd9Sstevel@tonic-gate 	 * setting USB_ISOC_ATTRS_ASAP. In this case, HCD will decide starting
22387c478bd9Sstevel@tonic-gate 	 * frame number for this isochronous request.  If this field is 0,
22397c478bd9Sstevel@tonic-gate 	 * then this indicates an invalid frame number.
22407c478bd9Sstevel@tonic-gate 	 */
22417c478bd9Sstevel@tonic-gate 	usb_frame_number_t	isoc_frame_no;
22427c478bd9Sstevel@tonic-gate 
22437c478bd9Sstevel@tonic-gate 	/*
2244b3001defSlg 	 * Number of isochronous data packets.
22457c478bd9Sstevel@tonic-gate 	 * The first field is set by client  driver and may not exceed
22467c478bd9Sstevel@tonic-gate 	 * the maximum number of entries in the usb isochronous packet
22477c478bd9Sstevel@tonic-gate 	 * descriptors.
22487c478bd9Sstevel@tonic-gate 	 */
22497c478bd9Sstevel@tonic-gate 	ushort_t		isoc_pkts_count;
2250b3001defSlg 
2251b3001defSlg 	/*
2252b3001defSlg 	 * The sum of all pkt lengths in the isoc request. Recommend to
2253b3001defSlg 	 * set it to zero, so the sum of isoc_pkt_length in the
2254b3001defSlg 	 * isoc_pkt_descr list will be used automatically and no check
2255b3001defSlg 	 * will be apply to this element.
2256b3001defSlg 	 */
22577c478bd9Sstevel@tonic-gate 	ushort_t		isoc_pkts_length;
22587c478bd9Sstevel@tonic-gate 
22597c478bd9Sstevel@tonic-gate 	/*
22607c478bd9Sstevel@tonic-gate 	 * This field will be set by HCD and this field indicates the number
22617c478bd9Sstevel@tonic-gate 	 * of packets that completed with errors.
22627c478bd9Sstevel@tonic-gate 	 */
22637c478bd9Sstevel@tonic-gate 	ushort_t		isoc_error_count;
22647c478bd9Sstevel@tonic-gate 
22657c478bd9Sstevel@tonic-gate 	/*
22667c478bd9Sstevel@tonic-gate 	 * Attributes specific to particular usb isochronous request.
22677c478bd9Sstevel@tonic-gate 	 * Supported values are: USB_ATTRS_ISOC_START_FRAME,
22687c478bd9Sstevel@tonic-gate 	 * USB_ATTRS_ISOC_XFER_ASAP.
22697c478bd9Sstevel@tonic-gate 	 */
22707c478bd9Sstevel@tonic-gate 	usb_req_attrs_t 	isoc_attributes;
22717c478bd9Sstevel@tonic-gate 
22727c478bd9Sstevel@tonic-gate 	/*
22737c478bd9Sstevel@tonic-gate 	 * Isochronous OUT:
22747c478bd9Sstevel@tonic-gate 	 *	allocated and set by client driver, freed and zeroed by HCD
22757c478bd9Sstevel@tonic-gate 	 *	on successful completion
22767c478bd9Sstevel@tonic-gate 	 * Isochronous IN:
22777c478bd9Sstevel@tonic-gate 	 *	allocated and set by HCD, freed by client driver
22787c478bd9Sstevel@tonic-gate 	 */
22797c478bd9Sstevel@tonic-gate 	mblk_t			*isoc_data;
22807c478bd9Sstevel@tonic-gate 
22817c478bd9Sstevel@tonic-gate 	/*
22827c478bd9Sstevel@tonic-gate 	 * The client driver specific private information.
22837c478bd9Sstevel@tonic-gate 	 */
22847c478bd9Sstevel@tonic-gate 	usb_opaque_t		isoc_client_private;
22857c478bd9Sstevel@tonic-gate 
22867c478bd9Sstevel@tonic-gate 	/*
22877c478bd9Sstevel@tonic-gate 	 * Isochronous OUT:
22887c478bd9Sstevel@tonic-gate 	 *	must be allocated & initialized by client driver
22897c478bd9Sstevel@tonic-gate 	 * Isochronous IN:
22907c478bd9Sstevel@tonic-gate 	 *	must be allocated by client driver
22917c478bd9Sstevel@tonic-gate 	 */
22927c478bd9Sstevel@tonic-gate 	struct usb_isoc_pkt_descr *isoc_pkt_descr;
22937c478bd9Sstevel@tonic-gate 
22947c478bd9Sstevel@tonic-gate 	/* Normal callback function (For synch transfers) */
22957c478bd9Sstevel@tonic-gate 	void			(*isoc_cb)(usb_pipe_handle_t ph,
22967c478bd9Sstevel@tonic-gate 					struct usb_isoc_req *req);
22977c478bd9Sstevel@tonic-gate 
22987c478bd9Sstevel@tonic-gate 	/* Exception callback function (For asynch transfers) */
22997c478bd9Sstevel@tonic-gate 	void			(*isoc_exc_cb)(usb_pipe_handle_t ph,
23007c478bd9Sstevel@tonic-gate 					struct usb_isoc_req *req);
23017c478bd9Sstevel@tonic-gate 
23027c478bd9Sstevel@tonic-gate 	/* set by USBA/HCD on completion */
23037c478bd9Sstevel@tonic-gate 	usb_cr_t		isoc_completion_reason;	/* set by HCD */
23047c478bd9Sstevel@tonic-gate 					/* Callback context / handling flgs */
23057c478bd9Sstevel@tonic-gate 	usb_cb_flags_t		isoc_cb_flags;
23067c478bd9Sstevel@tonic-gate } usb_isoc_req_t;
23077c478bd9Sstevel@tonic-gate 
23087c478bd9Sstevel@tonic-gate 
23097c478bd9Sstevel@tonic-gate /*
23107c478bd9Sstevel@tonic-gate  * Allocate/free usb isochronous resources
23117c478bd9Sstevel@tonic-gate  *
23127c478bd9Sstevel@tonic-gate  * isoc_pkts_count must be > 0
23137c478bd9Sstevel@tonic-gate  *
23147c478bd9Sstevel@tonic-gate  * Arguments:
23157c478bd9Sstevel@tonic-gate  *	dip		- client driver's devinfo pointer
23167c478bd9Sstevel@tonic-gate  *	isoc_pkts_count - number of pkts required
23177c478bd9Sstevel@tonic-gate  *	len		- 0 or size of mblk to allocate
23187c478bd9Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
23197c478bd9Sstevel@tonic-gate  *				wait for resources
23207c478bd9Sstevel@tonic-gate  *
23217c478bd9Sstevel@tonic-gate  * Return Values:
23227c478bd9Sstevel@tonic-gate  *	usb_isoc_req pointer or NULL
23237c478bd9Sstevel@tonic-gate  */
23247c478bd9Sstevel@tonic-gate usb_isoc_req_t *usb_alloc_isoc_req(
23257c478bd9Sstevel@tonic-gate 	dev_info_t		*dip,
23267c478bd9Sstevel@tonic-gate 	uint_t			isoc_pkts_count,
23277c478bd9Sstevel@tonic-gate 	size_t			len,
23287c478bd9Sstevel@tonic-gate 	usb_flags_t		flags);
23297c478bd9Sstevel@tonic-gate 
23307c478bd9Sstevel@tonic-gate void	usb_free_isoc_req(
23317c478bd9Sstevel@tonic-gate 	usb_isoc_req_t		*usb_isoc_req);
23327c478bd9Sstevel@tonic-gate 
23337c478bd9Sstevel@tonic-gate /*
23347c478bd9Sstevel@tonic-gate  * Returns current usb frame number.
23357c478bd9Sstevel@tonic-gate  */
23367c478bd9Sstevel@tonic-gate usb_frame_number_t usb_get_current_frame_number(
23377c478bd9Sstevel@tonic-gate 	dev_info_t		*dip);
23387c478bd9Sstevel@tonic-gate 
23397c478bd9Sstevel@tonic-gate /*
23407c478bd9Sstevel@tonic-gate  * Get maximum isochronous packets per usb isochronous request
23417c478bd9Sstevel@tonic-gate  */
23427c478bd9Sstevel@tonic-gate uint_t usb_get_max_pkts_per_isoc_request(
23437c478bd9Sstevel@tonic-gate 	dev_info_t		*dip);
23447c478bd9Sstevel@tonic-gate 
23457c478bd9Sstevel@tonic-gate /*
23467c478bd9Sstevel@tonic-gate  * usb_pipe_isoc_xfer()
23477c478bd9Sstevel@tonic-gate  *
23487c478bd9Sstevel@tonic-gate  * Client drivers call this to issue the isoch xfer (IN and OUT) to the USBA
23497c478bd9Sstevel@tonic-gate  * which starts polling the device.
23507c478bd9Sstevel@tonic-gate  *
23517c478bd9Sstevel@tonic-gate  * Arguments:
23527c478bd9Sstevel@tonic-gate  *	pipe_handle	- isoc pipe handle (obtained via usb_pipe_open().
23537c478bd9Sstevel@tonic-gate  *	reqp		- pointer to the isochronous pipe IN xfer request
23547c478bd9Sstevel@tonic-gate  *			  allocated by the client driver.
23557c478bd9Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
23567c478bd9Sstevel@tonic-gate  *				wait for the resources to be available.
23577c478bd9Sstevel@tonic-gate  *
23587c478bd9Sstevel@tonic-gate  * return values:
23597c478bd9Sstevel@tonic-gate  *	USB_SUCCESS	- success.
23607c478bd9Sstevel@tonic-gate  *	USB_FAILURE	- unspecified failure.
23617c478bd9Sstevel@tonic-gate  *	USB_NO_RESOURCES  - no resources.
23627c478bd9Sstevel@tonic-gate  *	USB_NO_FRAME_NUMBER - START_FRAME, ASAP flags not specified.
23637c478bd9Sstevel@tonic-gate  *	USB_INVALID_START_FRAME	- Starting USB frame number invalid.
23647c478bd9Sstevel@tonic-gate  *
23657c478bd9Sstevel@tonic-gate  * Notes:
23667c478bd9Sstevel@tonic-gate  * - usb_pipe_isoc_xfer on an IN pipe that is already being polled is a NOP.
23677c478bd9Sstevel@tonic-gate  * - requests can be queued on an OUT pipe.
23687c478bd9Sstevel@tonic-gate  */
23697c478bd9Sstevel@tonic-gate int usb_pipe_isoc_xfer(
23707c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
23717c478bd9Sstevel@tonic-gate 	usb_isoc_req_t		*reqp,
23727c478bd9Sstevel@tonic-gate 	usb_flags_t		flags);
23737c478bd9Sstevel@tonic-gate 
23747c478bd9Sstevel@tonic-gate /*
23757c478bd9Sstevel@tonic-gate  * usb_pipe_stop_isoc_polling():
23767c478bd9Sstevel@tonic-gate  *
23777c478bd9Sstevel@tonic-gate  * Client drivers call this function to stop the automatic data-in/out
23787c478bd9Sstevel@tonic-gate  * transfers without closing the isoc pipe.
23797c478bd9Sstevel@tonic-gate  *
23807c478bd9Sstevel@tonic-gate  * If USB_FLAGS_SLEEP  has been specified then this function will block until
23817c478bd9Sstevel@tonic-gate  * polling has been stopped and all callbacks completed. If USB_FLAGS_SLEEP
23827c478bd9Sstevel@tonic-gate  * has NOT been specified then polling is terminated when the original
23837c478bd9Sstevel@tonic-gate  * request that started the polling has been returned with
23847c478bd9Sstevel@tonic-gate  * USB_CR_STOPPED_POLLING
23857c478bd9Sstevel@tonic-gate  *
23867c478bd9Sstevel@tonic-gate  * Stop polling should never fail.
23877c478bd9Sstevel@tonic-gate  *
23887c478bd9Sstevel@tonic-gate  * Arguments:
23897c478bd9Sstevel@tonic-gate  *	pipe_handle	- isoc pipe handle (obtained via usb_pipe_open().
23907c478bd9Sstevel@tonic-gate  *	flags		- USB_FLAGS_SLEEP:
23917c478bd9Sstevel@tonic-gate  *				wait for polling to be stopped and all
23927c478bd9Sstevel@tonic-gate  *				callbacks completed.
23937c478bd9Sstevel@tonic-gate  */
23947c478bd9Sstevel@tonic-gate void usb_pipe_stop_isoc_polling(
23957c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle,
23967c478bd9Sstevel@tonic-gate 	usb_flags_t		flags);
23977c478bd9Sstevel@tonic-gate 
23987c478bd9Sstevel@tonic-gate /*
23997c478bd9Sstevel@tonic-gate  * ***************************************************************************
24007c478bd9Sstevel@tonic-gate  * USB device power management:
24017c478bd9Sstevel@tonic-gate  * ***************************************************************************
24027c478bd9Sstevel@tonic-gate  */
24037c478bd9Sstevel@tonic-gate 
24047c478bd9Sstevel@tonic-gate /*
24057c478bd9Sstevel@tonic-gate  *
24067c478bd9Sstevel@tonic-gate  * As any usb device will have a max of 4 possible power states
24077c478bd9Sstevel@tonic-gate  * the #define	for them are provided below with mapping to the
24087c478bd9Sstevel@tonic-gate  * corresponding OS power levels.
24097c478bd9Sstevel@tonic-gate  */
24107c478bd9Sstevel@tonic-gate #define	USB_DEV_PWR_D0		USB_DEV_OS_FULL_PWR
24117c478bd9Sstevel@tonic-gate #define	USB_DEV_PWR_D1		5
24127c478bd9Sstevel@tonic-gate #define	USB_DEV_PWR_D2		6
24137c478bd9Sstevel@tonic-gate #define	USB_DEV_PWR_D3		USB_DEV_OS_PWR_OFF
24147c478bd9Sstevel@tonic-gate 
24157c478bd9Sstevel@tonic-gate #define	USB_DEV_OS_PWR_0	0
24167c478bd9Sstevel@tonic-gate #define	USB_DEV_OS_PWR_1	1
24177c478bd9Sstevel@tonic-gate #define	USB_DEV_OS_PWR_2	2
24187c478bd9Sstevel@tonic-gate #define	USB_DEV_OS_PWR_3	3
24197c478bd9Sstevel@tonic-gate #define	USB_DEV_OS_PWR_OFF	USB_DEV_OS_PWR_0
24207c478bd9Sstevel@tonic-gate #define	USB_DEV_OS_FULL_PWR	USB_DEV_OS_PWR_3
24217c478bd9Sstevel@tonic-gate 
24227c478bd9Sstevel@tonic-gate /* Bit Masks for Power States */
24237c478bd9Sstevel@tonic-gate #define	USB_DEV_OS_PWRMASK_D0	1
24247c478bd9Sstevel@tonic-gate #define	USB_DEV_OS_PWRMASK_D1	2
24257c478bd9Sstevel@tonic-gate #define	USB_DEV_OS_PWRMASK_D2	4
24267c478bd9Sstevel@tonic-gate #define	USB_DEV_OS_PWRMASK_D3	8
24277c478bd9Sstevel@tonic-gate 
24287c478bd9Sstevel@tonic-gate /* conversion for OS to Dx levels */
24297c478bd9Sstevel@tonic-gate #define	USB_DEV_OS_PWR2USB_PWR(l)	(USB_DEV_OS_FULL_PWR - (l))
24307c478bd9Sstevel@tonic-gate 
24317c478bd9Sstevel@tonic-gate /* from OS level to Dx mask */
24327c478bd9Sstevel@tonic-gate #define	USB_DEV_PWRMASK(l)	(1 << (USB_DEV_OS_FULL_PWR - (l)))
24337c478bd9Sstevel@tonic-gate 
24347c478bd9Sstevel@tonic-gate /* Macro to check valid power level */
24357c478bd9Sstevel@tonic-gate #define	USB_DEV_PWRSTATE_OK(state, level) \
24367c478bd9Sstevel@tonic-gate 		(((state) & USB_DEV_PWRMASK((level))) == 0)
24377c478bd9Sstevel@tonic-gate 
24387c478bd9Sstevel@tonic-gate int usb_handle_remote_wakeup(
24397c478bd9Sstevel@tonic-gate 	dev_info_t	*dip,
24407c478bd9Sstevel@tonic-gate 	int		cmd);
24417c478bd9Sstevel@tonic-gate 
24427c478bd9Sstevel@tonic-gate /* argument to usb_handle_remote wakeup function */
24437c478bd9Sstevel@tonic-gate #define	USB_REMOTE_WAKEUP_ENABLE	1
24447c478bd9Sstevel@tonic-gate #define	USB_REMOTE_WAKEUP_DISABLE	2
24457c478bd9Sstevel@tonic-gate 
24467c478bd9Sstevel@tonic-gate int usb_create_pm_components(
24477c478bd9Sstevel@tonic-gate 	dev_info_t	*dip,
24487c478bd9Sstevel@tonic-gate 	uint_t		*pwrstates);
24497c478bd9Sstevel@tonic-gate 
24507c478bd9Sstevel@tonic-gate /*
24517c478bd9Sstevel@tonic-gate  * ***************************************************************************
24527c478bd9Sstevel@tonic-gate  * System event registration
24537c478bd9Sstevel@tonic-gate  * ***************************************************************************
24547c478bd9Sstevel@tonic-gate  */
24557c478bd9Sstevel@tonic-gate 
24567c478bd9Sstevel@tonic-gate /* Functions for registering hotplug callback functions. */
24577c478bd9Sstevel@tonic-gate 
24587c478bd9Sstevel@tonic-gate int usb_register_hotplug_cbs(
24597c478bd9Sstevel@tonic-gate 	dev_info_t	*dip,
24607c478bd9Sstevel@tonic-gate 	int		(*disconnect_event_handler)(dev_info_t *dip),
24617c478bd9Sstevel@tonic-gate 	int		(*reconnect_event_handler)(dev_info_t *dip));
24627c478bd9Sstevel@tonic-gate 
24637c478bd9Sstevel@tonic-gate void usb_unregister_hotplug_cbs(dev_info_t *dip);
24647c478bd9Sstevel@tonic-gate 
2465ffcd51f3Slg /*
2466ffcd51f3Slg  *	Reset_level determines the extent to which the device is reset,
2467ffcd51f3Slg  *	It has the following values:
2468ffcd51f3Slg  *
2469ffcd51f3Slg  *	USB_RESET_LVL_REATTACH	- The device is reset, the original driver is
2470ffcd51f3Slg  *				  detached and a new driver attaching process
2471ffcd51f3Slg  *				  is started according to the updated
2472ffcd51f3Slg  *				  compatible name. This reset level applies to
2473ffcd51f3Slg  *				  the firmware download with the descriptors
2474ffcd51f3Slg  *				  changing, or other situations in which the
2475ffcd51f3Slg  *				  device needs to be reenumerated.
2476ffcd51f3Slg  *
2477ffcd51f3Slg  *	USB_RESET_LVL_DEFAULT	- Default reset level. The device is reset, all
2478ffcd51f3Slg  *				  error status is cleared, the device state
2479ffcd51f3Slg  *				  machines and registers are also cleared and
2480ffcd51f3Slg  *				  need to be reinitialized in the driver. The
2481ffcd51f3Slg  *				  current driver remains attached. This reset
2482ffcd51f3Slg  *				  level applies to hardware error recovery, or
2483ffcd51f3Slg  *				  firmware download without descriptors
2484ffcd51f3Slg  *				  changing.
2485ffcd51f3Slg  */
2486ffcd51f3Slg typedef enum {
2487ffcd51f3Slg 	USB_RESET_LVL_REATTACH		= 0,
2488ffcd51f3Slg 	USB_RESET_LVL_DEFAULT		= 1
2489ffcd51f3Slg } usb_dev_reset_lvl_t;
2490ffcd51f3Slg 
2491ffcd51f3Slg /*
2492ffcd51f3Slg  * usb_reset_device:
2493ffcd51f3Slg  *
2494ffcd51f3Slg  * Client drivers call this function to request hardware reset for themselves,
2495ffcd51f3Slg  * which may be required in some situations such as:
2496ffcd51f3Slg  *
2497ffcd51f3Slg  * 1) Some USB devices need the driver to upload firmware into devices' RAM
2498ffcd51f3Slg  *    and initiate a hardware reset in order to activate the new firmware.
2499ffcd51f3Slg  * 2) Hardware reset may help drivers to recover devices from an error state
2500ffcd51f3Slg  *    caused by physical or firmware defects.
2501ffcd51f3Slg  *
2502ffcd51f3Slg  * Arguments:
2503ffcd51f3Slg  *	dip		    - pointer to devinfo of the client
2504ffcd51f3Slg  *	reset_level	    - see above
2505ffcd51f3Slg  *
2506ffcd51f3Slg  * Return values:
2507ffcd51f3Slg  *	USB_SUCCESS	    - With USB_RESET_LVL_DEFAULT: the device was reset
2508ffcd51f3Slg  *			      successfully.
2509ffcd51f3Slg  *			    - With USB_RESET_LVL_REATTACH: reenumeration was
2510ffcd51f3Slg  *			      started successfully or a previous reset is still
2511ffcd51f3Slg  *			      in progress.
2512ffcd51f3Slg  *	USB_FAILURE	    - The state of the device's parent hub is invalid
2513ffcd51f3Slg  *			      (disconnected or suspended).
2514ffcd51f3Slg  *			    - Called when the driver being detached.
2515ffcd51f3Slg  *			    - The device failed to be reset with
2516ffcd51f3Slg  *			      USB_RESET_LVL_DEFAULT specified.
2517ffcd51f3Slg  *			    - Reenumeration failed to start up with
2518ffcd51f3Slg  *			    - USB_RESET_LVL_REATTACH specified.
2519ffcd51f3Slg  *	USB_INVALID_ARGS    - Invalid arguments.
2520ffcd51f3Slg  *	USB_INVALID_PERM    - The driver of the dip doesn't own entire device.
2521ffcd51f3Slg  *	USB_BUSY	    - One or more pipes other than the default control
2522ffcd51f3Slg  *			      pipe are open on the device with
2523ffcd51f3Slg  *			      USB_RESET_LVL_DEFAULT specified.
2524ffcd51f3Slg  *	USB_INVALID_CONTEXT - Called from interrupt context with
2525ffcd51f3Slg  *			      USB_RESET_LVL_DEFAULT specified.
2526ffcd51f3Slg  */
2527ffcd51f3Slg 
2528ffcd51f3Slg int usb_reset_device(
2529ffcd51f3Slg 	dev_info_t 		*dip,
2530ffcd51f3Slg 	usb_dev_reset_lvl_t	reset_level);
2531ffcd51f3Slg 
25327c478bd9Sstevel@tonic-gate 
2533a7df97baSStrony Zhang - Solaris China Team /*
2534a7df97baSStrony Zhang - Solaris China Team  * **************************************************************************
2535a7df97baSStrony Zhang - Solaris China Team  * USB device driver registration and callback functions remaining
2536a7df97baSStrony Zhang - Solaris China Team  * Contracted Project Private (for VirtualBox USB Device Capture)
2537a7df97baSStrony Zhang - Solaris China Team  * **************************************************************************
2538a7df97baSStrony Zhang - Solaris China Team  */
2539a7df97baSStrony Zhang - Solaris China Team 
2540a7df97baSStrony Zhang - Solaris China Team /*
2541a7df97baSStrony Zhang - Solaris China Team  * getting the device strings of manufacturer, product and serial number
2542a7df97baSStrony Zhang - Solaris China Team  */
2543a7df97baSStrony Zhang - Solaris China Team typedef struct usb_dev_str {
2544a7df97baSStrony Zhang - Solaris China Team 	char	*usb_mfg;	/* manufacturer string */
2545a7df97baSStrony Zhang - Solaris China Team 	char	*usb_product;	/* product string */
2546a7df97baSStrony Zhang - Solaris China Team 	char	*usb_serialno;	/* serial number string */
2547a7df97baSStrony Zhang - Solaris China Team } usb_dev_str_t;
2548a7df97baSStrony Zhang - Solaris China Team 
2549a7df97baSStrony Zhang - Solaris China Team /*
2550a7df97baSStrony Zhang - Solaris China Team  * It is the callback function type for capture driver.
2551a7df97baSStrony Zhang - Solaris China Team  * Arguments:
2552a7df97baSStrony Zhang - Solaris China Team  *	dev_descr	- pointer to device descriptor
2553a7df97baSStrony Zhang - Solaris China Team  *	dev_str		- pointer to device strings
2554a7df97baSStrony Zhang - Solaris China Team  *	path		- pointer to device physical path
2555a7df97baSStrony Zhang - Solaris China Team  *	bus		- USB bus address
2556a7df97baSStrony Zhang - Solaris China Team  *	port		- USB port number
2557a7df97baSStrony Zhang - Solaris China Team  *	drv		- capture driver name.
2558a7df97baSStrony Zhang - Solaris China Team  *			  It is returned by the callback func.
2559a7df97baSStrony Zhang - Solaris China Team  * Return Values:
2560a7df97baSStrony Zhang - Solaris China Team  *      USB_SUCCESS     - VirtualBox will capture the device
2561a7df97baSStrony Zhang - Solaris China Team  *      USB_FAILURE     - VirtualBox will not capture the device
2562a7df97baSStrony Zhang - Solaris China Team  */
2563a7df97baSStrony Zhang - Solaris China Team typedef int (*usb_dev_driver_callback_t)(
2564a7df97baSStrony Zhang - Solaris China Team 	usb_dev_descr_t	*dev_descr,
2565a7df97baSStrony Zhang - Solaris China Team 	usb_dev_str_t	*dev_str,
2566a7df97baSStrony Zhang - Solaris China Team 	char		*path,
2567a7df97baSStrony Zhang - Solaris China Team 	int		bus,
2568a7df97baSStrony Zhang - Solaris China Team 	int		port,
2569a7df97baSStrony Zhang - Solaris China Team 	char		**drv,
2570a7df97baSStrony Zhang - Solaris China Team 	void		*reserved);
2571a7df97baSStrony Zhang - Solaris China Team 
2572a7df97baSStrony Zhang - Solaris China Team /*
2573a7df97baSStrony Zhang - Solaris China Team  * Register the callback function in the usba.
2574a7df97baSStrony Zhang - Solaris China Team  * Argument:
2575a7df97baSStrony Zhang - Solaris China Team  *	dip		- client driver's devinfo pointer
2576a7df97baSStrony Zhang - Solaris China Team  *	cb		- callback function
2577a7df97baSStrony Zhang - Solaris China Team  *
2578a7df97baSStrony Zhang - Solaris China Team  * Return Values:
2579a7df97baSStrony Zhang - Solaris China Team  *	USB_SUCCESS	- the registeration was successful
2580a7df97baSStrony Zhang - Solaris China Team  *	USB_FAILURE	- the registeration failed
2581a7df97baSStrony Zhang - Solaris China Team  */
2582a7df97baSStrony Zhang - Solaris China Team int usb_register_dev_driver(
2583a7df97baSStrony Zhang - Solaris China Team 	dev_info_t			*dip,
2584a7df97baSStrony Zhang - Solaris China Team 	usb_dev_driver_callback_t	cb);
2585a7df97baSStrony Zhang - Solaris China Team 
2586a7df97baSStrony Zhang - Solaris China Team /*
2587a7df97baSStrony Zhang - Solaris China Team  * Unregister the callback function in the usba.
2588a7df97baSStrony Zhang - Solaris China Team  */
2589a7df97baSStrony Zhang - Solaris China Team void usb_unregister_dev_driver(dev_info_t *dip);
2590a7df97baSStrony Zhang - Solaris China Team 
2591a7df97baSStrony Zhang - Solaris China Team 
25927c478bd9Sstevel@tonic-gate /*
25937c478bd9Sstevel@tonic-gate  * ***************************************************************************
25947c478bd9Sstevel@tonic-gate  * USB Device and interface class, subclass and protocol codes
25957c478bd9Sstevel@tonic-gate  * ***************************************************************************
25967c478bd9Sstevel@tonic-gate  */
25977c478bd9Sstevel@tonic-gate 
25987c478bd9Sstevel@tonic-gate /*
25997c478bd9Sstevel@tonic-gate  * Available device and interface class codes.
26007c478bd9Sstevel@tonic-gate  * Those which are device class codes are noted.
26017c478bd9Sstevel@tonic-gate  */
26027c478bd9Sstevel@tonic-gate 
26037c478bd9Sstevel@tonic-gate #define	USB_CLASS_AUDIO		1
26047c478bd9Sstevel@tonic-gate #define	USB_CLASS_COMM		2	/* Communication device class and */
26057c478bd9Sstevel@tonic-gate #define	USB_CLASS_CDC_CTRL	2	/* CDC-control iface class, also 2 */
26067c478bd9Sstevel@tonic-gate #define	USB_CLASS_HID		3
26077c478bd9Sstevel@tonic-gate #define	USB_CLASS_PHYSICAL	5
2608d73ae94eSgc #define	USB_CLASS_IMAGE		6
26097c478bd9Sstevel@tonic-gate #define	USB_CLASS_PRINTER	7
26107c478bd9Sstevel@tonic-gate #define	USB_CLASS_MASS_STORAGE	8
26117c478bd9Sstevel@tonic-gate #define	USB_CLASS_HUB		9	/* Device class */
26127c478bd9Sstevel@tonic-gate #define	USB_CLASS_CDC_DATA	10
26137c478bd9Sstevel@tonic-gate #define	USB_CLASS_CCID		11
26147c478bd9Sstevel@tonic-gate #define	USB_CLASS_SECURITY	13
2615d73ae94eSgc #define	USB_CLASS_VIDEO		14
26167c478bd9Sstevel@tonic-gate #define	USB_CLASS_DIAG		220	/* Device class */
2617d73ae94eSgc #define	USB_CLASS_WIRELESS	224
26187c478bd9Sstevel@tonic-gate #define	USB_CLASS_MISC		239	/* Device class */
26197c478bd9Sstevel@tonic-gate #define	USB_CLASS_APP		254
26207c478bd9Sstevel@tonic-gate #define	USB_CLASS_VENDOR_SPEC	255	/* Device class */
26217c478bd9Sstevel@tonic-gate 
26227c478bd9Sstevel@tonic-gate #define	USB_CLASS_PER_INTERFACE	0	/* Class info is at interface level */
26237c478bd9Sstevel@tonic-gate 
26247c478bd9Sstevel@tonic-gate /* Audio subclass. */
26257c478bd9Sstevel@tonic-gate #define	USB_SUBCLS_AUD_CONTROL		0x01
26267c478bd9Sstevel@tonic-gate #define	USB_SUBCLS_AUD_STREAMING	0x02
26277c478bd9Sstevel@tonic-gate #define	USB_SUBCLS_AUD_MIDI_STREAMING	0x03
26287c478bd9Sstevel@tonic-gate 
26297c478bd9Sstevel@tonic-gate /* Comms  subclass. */
26307c478bd9Sstevel@tonic-gate #define	USB_SUBCLS_CDCC_DIRECT_LINE	0x01
26317c478bd9Sstevel@tonic-gate #define	USB_SUBCLS_CDCC_ABSTRCT_CTRL	0x02
26327c478bd9Sstevel@tonic-gate #define	USB_SUBCLS_CDCC_PHONE_CTRL	0x03
26337c478bd9Sstevel@tonic-gate #define	USB_SUBCLS_CDCC_MULTCNL_ISDN	0x04
26347c478bd9Sstevel@tonic-gate #define	USB_SUBCLS_CDCC_ISDN		0x05
26357c478bd9Sstevel@tonic-gate #define	USB_SUBCLS_CDCC_ETHERNET	0x06
26367c478bd9Sstevel@tonic-gate #define	USB_SUBCLS_CDCC_ATM_NETWORK	0x07
26377c478bd9Sstevel@tonic-gate 
26387c478bd9Sstevel@tonic-gate /* HID subclass and protocols. */
26397c478bd9Sstevel@tonic-gate #define	USB_SUBCLS_HID_1		1
26407c478bd9Sstevel@tonic-gate 
26417c478bd9Sstevel@tonic-gate #define	USB_PROTO_HID_KEYBOARD		0x01	/* legacy keyboard */
26427c478bd9Sstevel@tonic-gate #define	USB_PROTO_HID_MOUSE		0x02	/* legacy mouse */
26437c478bd9Sstevel@tonic-gate 
26447c478bd9Sstevel@tonic-gate /* Printer subclass and protocols. */
26457c478bd9Sstevel@tonic-gate #define	USB_SUBCLS_PRINTER_1		1
26467c478bd9Sstevel@tonic-gate 
26477c478bd9Sstevel@tonic-gate #define	USB_PROTO_PRINTER_UNI		0x01	/* Unidirectional interface */
26487c478bd9Sstevel@tonic-gate #define	USB_PROTO_PRINTER_BI		0x02	/* Bidirectional interface */
26497c478bd9Sstevel@tonic-gate 
26507c478bd9Sstevel@tonic-gate /* Mass storage subclasses and protocols. */
26517c478bd9Sstevel@tonic-gate #define	USB_SUBCLS_MS_RBC_T10		0x1	/* flash */
26527c478bd9Sstevel@tonic-gate #define	USB_SUBCLS_MS_SFF8020I		0x2	/* CD-ROM */
26537c478bd9Sstevel@tonic-gate #define	USB_SUBCLS_MS_QIC_157		0x3	/* tape */
26547c478bd9Sstevel@tonic-gate #define	USB_SUBCLS_MS_UFI		0x4	/* USB Floppy Disk Drive   */
26557c478bd9Sstevel@tonic-gate #define	USB_SUBCLS_MS_SFF8070I		0x5	/* floppy */
26567c478bd9Sstevel@tonic-gate #define	USB_SUBCLS_MS_SCSI		0x6	/* transparent scsi */
26577c478bd9Sstevel@tonic-gate 
26587c478bd9Sstevel@tonic-gate #define	USB_PROTO_MS_CBI_WC		0x00	/* USB CBI Proto w/cmp intr */
26597c478bd9Sstevel@tonic-gate #define	USB_PROTO_MS_CBI		0x01    /* USB CBI Protocol */
26607c478bd9Sstevel@tonic-gate #define	USB_PROTO_MS_ISD_1999_SILICN	0x02    /* ZIP Protocol */
26617c478bd9Sstevel@tonic-gate #define	USB_PROTO_MS_BULK_ONLY		0x50    /* USB Bulk Only Protocol */
26627c478bd9Sstevel@tonic-gate 
2663993e3fafSRobert Mustacchi /* Hub subclass and protocols */
2664993e3fafSRobert Mustacchi #define	USB_PROTO_HUB_FULL		0x00	/* Full Speed Protocol */
2665993e3fafSRobert Mustacchi #define	USB_PROTO_HUB_HIGH_STT		0x01	/* High Speed with STT */
2666993e3fafSRobert Mustacchi #define	USB_PROTO_HUB_HIGH_MTT		0x02	/* High Speed with MTT */
2667993e3fafSRobert Mustacchi #define	USB_PROTO_HUB_SUPER		0x03	/* SuperSpeed Protocol */
2668993e3fafSRobert Mustacchi 
26697c478bd9Sstevel@tonic-gate /* Application subclasses. */
26707c478bd9Sstevel@tonic-gate #define	USB_SUBCLS_APP_FIRMWARE		0x01	/* app spec f/w subclass */
26717c478bd9Sstevel@tonic-gate #define	USB_SUBCLS_APP_IRDA		0x02	/* app spec IrDa subclass */
26727c478bd9Sstevel@tonic-gate #define	USB_SUBCLS_APP_TEST		0x03	/* app spec test subclass */
26737c478bd9Sstevel@tonic-gate 
2674d73ae94eSgc /* Video subclasses */
2675d73ae94eSgc #define	USB_SUBCLS_VIDEO_CONTROL	0x01	/* video control */
2676d73ae94eSgc #define	USB_SUBCLS_VIDEO_STREAM		0x02	/* video stream */
2677d73ae94eSgc #define	USB_SUBCLS_VIDEO_COLLECTION	0x03	/* video interface collection */
2678d73ae94eSgc 
2679ff0e937bSRaymond Chen /* Wireless controller subclasses and protocols, refer to WUSB 1.0 chapter 8 */
2680ff0e937bSRaymond Chen #define	USB_SUBCLS_WUSB_1		0x01	/* RF controller */
2681ff0e937bSRaymond Chen #define	USB_SUBCLS_WUSB_2		0x02	/* Wireless adapter */
2682d73ae94eSgc #define	USB_PROTO_WUSB_HWA		0x01	/* host wire adapter */
2683d73ae94eSgc #define	USB_PROTO_WUSB_DWA		0x02	/* device wire adapter */
2684d73ae94eSgc #define	USB_PROTO_WUSB_DWA_ISO		0x03	/* device wire adapter isoc */
2685ff0e937bSRaymond Chen #define	USB_PROTO_WUSB_RC		0x02	/* UWB radio controller */
2686ff0e937bSRaymond Chen 
2687ff0e937bSRaymond Chen /* Association subclass and protocol, Association Model Supplement to WUSB1.0 */
2688ff0e937bSRaymond Chen #define	USB_SUBCLS_CBAF			0x03	/* cable association */
2689ff0e937bSRaymond Chen #define	USB_PROTO_CBAF			0x01	/* CBAF protocol */
2690ff0e937bSRaymond Chen 
2691ff0e937bSRaymond Chen /* Misc subclasses and protocols, refer to WUSB 1.0 chapter 8 */
2692ff0e937bSRaymond Chen #define	USB_SUBCLS_MISC_COMMON		0x02	/* common class */
2693ff0e937bSRaymond Chen #define	USB_PROTO_MISC_WA		0x02	/* multifunction wire adapter */
26947c478bd9Sstevel@tonic-gate 
26957c478bd9Sstevel@tonic-gate #ifdef __cplusplus
26967c478bd9Sstevel@tonic-gate }
26977c478bd9Sstevel@tonic-gate #endif
26987c478bd9Sstevel@tonic-gate 
26997c478bd9Sstevel@tonic-gate #endif /* _SYS_USB_USBAI_H */
2700