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