6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 *
25 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
26 * Copyright 2016 Joyent, Inc.
27 */
28
29 /*
30 * USBA: Solaris USB Architecture support
31 *
32 * This module builds a tree of parsed USB standard descriptors and unparsed
33 * Class/Vendor specific (C/V) descriptors. Routines are grouped into three
34 * groups: those which build the tree, those which take it down, and those which
35 * dump it.
36 *
37 * The tree built hangs off of the dev_cfg field of the usb_client_dev_data_t
38 * structure returned by usb_get_dev_data(). The tree consists of different
39 * kinds of tree nodes (usb_xxx_data_t) each containing a standard USB
40 * descriptor (usb_xxx_descr_t) and pointers to arrays of other nodes.
41 *
42 * Arrays are dynamically sized, as the descriptors coming from the device may
43 * lie, but the number of descriptors from the device is a more reliable
44 * indicator of configuration. This makes the code more robust. After the raw
45 * descriptor data has been parsed into a non-sparse tree, the tree is ordered
46 * and made sparse with a bin-sort style algorithm.
1125 USB_DPRINTF_L4(DPRINT_MASK_REGISTER, usbai_reg_log_handle,
1126 "usba_process_cv_descr starting. Processing c/v for descr type %d",
1127 state->st_last_processed_descr_type);
1128
1129 /*
1130 * Attach the c/v to a node based on the last descr type processed.
1131 * Save handles to appropriate c/v node array and count to update.
1132 */
1133 switch (state->st_last_processed_descr_type) {
1134 case USB_DESCR_TYPE_CFG:
1135 n_cvs_ptr = &state->st_curr_cfg->cfg_n_cvs;
1136 cvs_ptr = &state->st_curr_cfg->cfg_cvs;
1137 break;
1138
1139 case USB_DESCR_TYPE_IF:
1140 n_cvs_ptr = &state->st_curr_alt->altif_n_cvs;
1141 cvs_ptr = &state->st_curr_alt->altif_cvs;
1142 break;
1143
1144 case USB_DESCR_TYPE_EP:
1145 n_cvs_ptr = &state->st_curr_ep->ep_n_cvs;
1146 cvs_ptr = &state->st_curr_ep->ep_cvs;
1147 break;
1148
1149 default:
1150 USB_DPRINTF_L2(DPRINT_MASK_ALL, usbai_reg_log_handle,
1151 "usba_process_cv_descr: Type of last descriptor unknown. ");
1152
1153 return (USB_FAILURE);
1154 }
1155
1156 usba_augment_array((void **)cvs_ptr, *n_cvs_ptr,
1157 sizeof (usb_cvs_data_t));
1158 curr_cv_descr = &(*cvs_ptr)[(*n_cvs_ptr)++];
1159
1160 curr_cv_descr->cvs_buf =
1161 kmem_zalloc(state->st_curr_raw_descr_len, KM_SLEEP);
1162 curr_cv_descr->cvs_buf_len = state->st_curr_raw_descr_len;
1163 bcopy(state->st_curr_raw_descr, curr_cv_descr->cvs_buf,
1164 state->st_curr_raw_descr_len);
|
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 *
25 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
26 * Copyright 2017 Joyent, Inc.
27 */
28
29 /*
30 * USBA: Solaris USB Architecture support
31 *
32 * This module builds a tree of parsed USB standard descriptors and unparsed
33 * Class/Vendor specific (C/V) descriptors. Routines are grouped into three
34 * groups: those which build the tree, those which take it down, and those which
35 * dump it.
36 *
37 * The tree built hangs off of the dev_cfg field of the usb_client_dev_data_t
38 * structure returned by usb_get_dev_data(). The tree consists of different
39 * kinds of tree nodes (usb_xxx_data_t) each containing a standard USB
40 * descriptor (usb_xxx_descr_t) and pointers to arrays of other nodes.
41 *
42 * Arrays are dynamically sized, as the descriptors coming from the device may
43 * lie, but the number of descriptors from the device is a more reliable
44 * indicator of configuration. This makes the code more robust. After the raw
45 * descriptor data has been parsed into a non-sparse tree, the tree is ordered
46 * and made sparse with a bin-sort style algorithm.
1125 USB_DPRINTF_L4(DPRINT_MASK_REGISTER, usbai_reg_log_handle,
1126 "usba_process_cv_descr starting. Processing c/v for descr type %d",
1127 state->st_last_processed_descr_type);
1128
1129 /*
1130 * Attach the c/v to a node based on the last descr type processed.
1131 * Save handles to appropriate c/v node array and count to update.
1132 */
1133 switch (state->st_last_processed_descr_type) {
1134 case USB_DESCR_TYPE_CFG:
1135 n_cvs_ptr = &state->st_curr_cfg->cfg_n_cvs;
1136 cvs_ptr = &state->st_curr_cfg->cfg_cvs;
1137 break;
1138
1139 case USB_DESCR_TYPE_IF:
1140 n_cvs_ptr = &state->st_curr_alt->altif_n_cvs;
1141 cvs_ptr = &state->st_curr_alt->altif_cvs;
1142 break;
1143
1144 case USB_DESCR_TYPE_EP:
1145 case USB_DESCR_TYPE_SS_EP_COMP:
1146 n_cvs_ptr = &state->st_curr_ep->ep_n_cvs;
1147 cvs_ptr = &state->st_curr_ep->ep_cvs;
1148 break;
1149
1150 default:
1151 USB_DPRINTF_L2(DPRINT_MASK_ALL, usbai_reg_log_handle,
1152 "usba_process_cv_descr: Type of last descriptor unknown. ");
1153
1154 return (USB_FAILURE);
1155 }
1156
1157 usba_augment_array((void **)cvs_ptr, *n_cvs_ptr,
1158 sizeof (usb_cvs_data_t));
1159 curr_cv_descr = &(*cvs_ptr)[(*n_cvs_ptr)++];
1160
1161 curr_cv_descr->cvs_buf =
1162 kmem_zalloc(state->st_curr_raw_descr_len, KM_SLEEP);
1163 curr_cv_descr->cvs_buf_len = state->st_curr_raw_descr_len;
1164 bcopy(state->st_curr_raw_descr, curr_cv_descr->cvs_buf,
1165 state->st_curr_raw_descr_len);
|