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