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