usbai_util.c revision 269552cd714f2f1e308fdde0fc69b18a7f1142b2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * CDDL HEADER START
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * The contents of this file are subject to the terms of the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * Common Development and Distribution License (the "License").
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * You may not use this file except in compliance with the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * or http://www.opensolaris.org/os/licensing.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * See the License for the specific language governing permissions
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * and limitations under the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * When distributing Covered Code, include this CDDL HEADER in each
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * If applicable, add the following below this CDDL HEADER, with the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * fields enclosed by brackets "[]" replaced with your own identifying
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * information: Portions Copyright [yyyy] [name of copyright owner]
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * CDDL HEADER END
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * Use is subject to license terms.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * USBA: Solaris USB Architecture support
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * Utility functions
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyextern void usba_free_evdata(usba_evdata_t *);
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedystatic mblk_t *usba_get_cfg_cloud(dev_info_t *, usb_pipe_handle_t, int);
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy/* local functions */
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedystatic int usba_sync_set_cfg(dev_info_t *, usba_ph_impl_t *,
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedystatic int usba_sync_set_alt_if(dev_info_t *, usba_ph_impl_t *,
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedystatic int usba_sync_clear_feature(dev_info_t *, usba_ph_impl_t *,
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy * Wrapper functions returning parsed standard descriptors without
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * getting the config cloud first but by just providing the dip.
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy * The client can easily retrieve the device and config descriptor from
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy * the usb registration and no separate functions are provided
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * These functions return failure if the full descriptor can not be
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * retrieved. These functions will not access the device.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * The caller must allocate the buffer.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * usb_get_if_descr:
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * Function to get the cooked interface descriptor
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * This function will not access the device.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * dip - pointer to devinfo of the client
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * if_index - interface index
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * alt_setting - alt interface setting
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * descr - pointer to user allocated interface descr
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy * Return Values:
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * USB_SUCCESS - descriptor is valid
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * USB_FAILURE - full descriptor could not be retrieved
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * USB_* - refer to usbai.h
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy uchar_t *usb_cfg; /* buf for config descriptor */
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy USB_DPRINTF_L4(DPRINT_MASK_USBA, usbai_log_handle,
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy "usb_get_if_descr: %s, index=0x%x, alt#=0x%x",
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ddi_node_name(dip), if_index, alt_setting);
return (USB_INVALID_ARGS);
return (USB_FAILURE);
return (USB_SUCCESS);
* USB_* - refer to usbai.h
return (USB_INVALID_ARGS);
return (USB_FAILURE);
return (USB_SUCCESS);
return (NULL);
if (skip-- == 0) {
return (NULL);
* USB_* - refer to usbai.h
char *buf,
int rval;
return (USB_INVALID_ARGS);
goto done;
goto done;
goto done;
goto done;
buflen);
done:
return (rval);
if (dip) {
return (usb_dev_descr);
uchar_t *
return (NULL);
return (usb_cfg);
int address = 0;
if (dip) {
return (address);
* USB_* - refer to usbai.h
void (*cb)(
int rval,
return (USB_INVALID_ARGS);
return (USB_INVALID_CONTEXT);
return (USB_INVALID_PERM);
return (USB_INVALID_PIPE);
int rval;
int i, ph_open_cnt;
ph_open_cnt++;
return (USB_BUSY);
return (USB_FAILURE);
return (USB_FAILURE);
NULL, 0,
return (rval);
* USB_* - refer to usbai.h
int rval;
return (USB_INVALID_ARGS);
&data, 0,
return (rval);
return (ndx);
int interface_num;
if (usba_device) {
return (interface_num);
* USB_* - refer to usbai.h
void (*cb)(
int rval,
return (USB_INVALID_ARGS);
return (USB_INVALID_CONTEXT);
return (USB_INVALID_PIPE);
int rval;
return (USB_INVALID_PERM);
NULL, 0,
return (rval);
int rval;
return (USB_INVALID_ARGS);
&data, 0,
*alt_number = 0;
return (rval);
static mblk_t *
&pdata,
&cb_flags,
0) != USB_SUCCESS) {
return (NULL);
&pdata,
&cb_flags,
0) != USB_SUCCESS) {
return (NULL);
return (pdata);
int rval;
char *buf;
return (USB_INVALID_ARGS);
&pdata, 0,
return (USB_FAILURE);
sizeof (usb_dev_descr_t));
match =
if (allocated_here) {
if (allocated_here) {
return (USB_INVALID_VERSION);
return (USB_SUCCESS);
* USB_* - refer to usbai.h
if (ph_data) {
return (USB_INVALID_ARGS);
return (USB_SUCCESS);
return (USB_SUCCESS);
if (ph_data) {
return (pp);
int ep_num;
return (USB_INVALID_PIPE);
return (ep_num);
int rval;
return (USB_INVALID_ARGS);
return (USB_INVALID_PIPE);
type,
what,
&data, 0,
*status = 0;
return (rval);
* USB_* - refer to usbai.h
int rval;
return (USB_INVALID_ARGS);
return (USB_INVALID_PIPE);
type,
what,
NULL, 0,
return (rval);
* USB_* - refer to usbai.h
void (*cb)(
int rval,
return (USB_INVALID_ARGS);
return (USB_INVALID_CONTEXT);
return (USB_INVALID_PIPE);
int rval;
return (rval);
* USB_* - refer to usbai.h
void (*func)(void *),
void *arg,
int tq_flag;
return (USB_INVALID_ARGS);
tq_flag)) {
return (USB_FAILURE);
return (USB_SUCCESS);
* USB_* - refer to usbai.h
void (*func)(void *),
void *arg,
int tq_flag;
return (USB_INVALID_ARGS);
return (USB_FAILURE);
return (USB_SUCCESS);
typedef struct conv_table {
int what;
const char *name;
} conv_table_t;
{ 0, NULL }
{ 0, NULL }
return (buffer);
{ 0, NULL }
{ 0, NULL }
{ 0, NULL }
static struct usb_rval2errno_entry {
int rval;
int Errno;
} usb_rval2errno_table[] = {
{ USB_SUCCESS, 0 },
sizeof (struct usb_rval2errno_entry))
for (i = 0; i < USB_RVAL2ERRNO_TABLE_SIZE; i++) {
return (EIO);
if (dip) {
if (tokenp) {
if (rval <= 0) {
(void *)impl_tokenp,
return (rval);
switch (how_to_wait) {
case USB_WAIT:
case USB_WAIT_SIG:
case USB_TIMEDWAIT:
case USB_TIMEDWAIT_SIG:
(void *)curthread);
(void *)impl_tokenp);
return (USB_SUCCESS);
return (USB_FAILURE);
mblk_t *
return (bp1);
#ifdef ALLOCB_TEST
mblk_t *
return (NULL);
int rval;
switch (*dev_state) {
case USB_DEV_ONLINE:
case USB_DEV_DISCONNECTED:
case USB_DEV_SUSPENDED:
/* allow a disconnected/cpr'ed device to go to low pwr */
return (USB_SUCCESS);
case USB_DEV_PWRED_DOWN:
return (USB_FAILURE);
int rval;
return (USB_FAILURE);
int rval;
return (USB_FAILURE);
int rval;
switch (*dev_state) {
case USB_DEV_PWRED_DOWN:
case USB_DEV_ONLINE:
case USB_DEV_DISCONNECTED:
case USB_DEV_SUSPENDED:
/* allow a disconnected/cpr'ed device to go to low power */
return (USB_SUCCESS);
return (USB_FAILURE);
switch (level) {
case USB_DEV_OS_PWR_OFF:
case USB_DEV_OS_PWR_1:
case USB_DEV_OS_PWR_2:
case USB_DEV_OS_FULL_PWR:
int rval;
&cookie);
goto fail;
&cookie);
goto fail;
goto fail;
goto fail;
fail:
for (i = 0; i < if_num; i++) {