10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 52257Slg150142 * Common Development and Distribution License (the "License"). 62257Slg150142 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*3630Slg150142 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate /* 290Sstevel@tonic-gate * USBA: Solaris USB Architecture support 300Sstevel@tonic-gate */ 310Sstevel@tonic-gate #define USBA_FRAMEWORK 320Sstevel@tonic-gate #include <sys/usb/usba/usba_impl.h> 330Sstevel@tonic-gate #include <sys/usb/usba/hcdi_impl.h> 340Sstevel@tonic-gate #include <sys/usb/hubd/hub.h> 350Sstevel@tonic-gate #include <sys/fs/dv_node.h> 360Sstevel@tonic-gate 370Sstevel@tonic-gate static int usba_str_startcmp(char *, char *); 380Sstevel@tonic-gate 390Sstevel@tonic-gate /* 400Sstevel@tonic-gate * USBA private variables and tunables 410Sstevel@tonic-gate */ 420Sstevel@tonic-gate static kmutex_t usba_mutex; 430Sstevel@tonic-gate 440Sstevel@tonic-gate /* 450Sstevel@tonic-gate * ddivs forced binding: 460Sstevel@tonic-gate * 470Sstevel@tonic-gate * usbc usbc_xhubs usbc_xaddress node name 480Sstevel@tonic-gate * 490Sstevel@tonic-gate * 0 x x class name or "device" 500Sstevel@tonic-gate * 510Sstevel@tonic-gate * 1 0 0 ddivs_usbc 520Sstevel@tonic-gate * 1 0 >1 ddivs_usbc except device 530Sstevel@tonic-gate * at usbc_xaddress 540Sstevel@tonic-gate * 1 1 0 ddivs_usbc except hubs 550Sstevel@tonic-gate * 1 1 >1 ddivs_usbc except hubs and 560Sstevel@tonic-gate * device at usbc_xaddress 570Sstevel@tonic-gate */ 580Sstevel@tonic-gate uint_t usba_ddivs_usbc; 590Sstevel@tonic-gate uint_t usba_ddivs_usbc_xhubs; 600Sstevel@tonic-gate uint_t usba_ddivs_usbc_xaddress; 610Sstevel@tonic-gate 620Sstevel@tonic-gate uint_t usba_ugen_force_binding; 630Sstevel@tonic-gate 640Sstevel@tonic-gate /* 650Sstevel@tonic-gate * compatible name handling 660Sstevel@tonic-gate */ 670Sstevel@tonic-gate #define USBA_MAX_COMPAT_NAMES 15 680Sstevel@tonic-gate #define USBA_MAX_COMPAT_NAME_LEN 64 690Sstevel@tonic-gate 700Sstevel@tonic-gate /* double linked list for usba_devices */ 710Sstevel@tonic-gate usba_list_entry_t usba_device_list; 720Sstevel@tonic-gate 730Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(usba_mutex, usba_device_list)) 740Sstevel@tonic-gate 750Sstevel@tonic-gate /* 760Sstevel@tonic-gate * modload support 770Sstevel@tonic-gate */ 780Sstevel@tonic-gate extern struct mod_ops mod_miscops; 790Sstevel@tonic-gate 800Sstevel@tonic-gate struct modlmisc modlmisc = { 810Sstevel@tonic-gate &mod_miscops, /* Type of module */ 823341Sgc161489 "USBA: USB Architecture 2.0 1.66" 830Sstevel@tonic-gate }; 840Sstevel@tonic-gate 850Sstevel@tonic-gate struct modlinkage modlinkage = { 860Sstevel@tonic-gate MODREV_1, (void *)&modlmisc, NULL 870Sstevel@tonic-gate }; 880Sstevel@tonic-gate 890Sstevel@tonic-gate 900Sstevel@tonic-gate static usb_log_handle_t usba_log_handle; 91880Sfrits uint_t usba_errlevel = USB_LOG_L4; 92880Sfrits uint_t usba_errmask = (uint_t)-1; 930Sstevel@tonic-gate 940Sstevel@tonic-gate extern usb_log_handle_t hubdi_log_handle; 950Sstevel@tonic-gate 960Sstevel@tonic-gate int 970Sstevel@tonic-gate _init(void) 980Sstevel@tonic-gate { 99*3630Slg150142 int rval; 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate /* 1020Sstevel@tonic-gate * usbai providing log support needs to be init'ed first 1030Sstevel@tonic-gate * and destroyed last 1040Sstevel@tonic-gate */ 1050Sstevel@tonic-gate usba_usbai_initialization(); 1060Sstevel@tonic-gate usba_usba_initialization(); 1070Sstevel@tonic-gate usba_usbai_register_initialization(); 1080Sstevel@tonic-gate usba_hcdi_initialization(); 1090Sstevel@tonic-gate usba_hubdi_initialization(); 1100Sstevel@tonic-gate usba_devdb_initialization(); 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate if ((rval = mod_install(&modlinkage)) != 0) { 1130Sstevel@tonic-gate usba_devdb_destroy(); 1140Sstevel@tonic-gate usba_hubdi_destroy(); 1150Sstevel@tonic-gate usba_hcdi_destroy(); 1160Sstevel@tonic-gate usba_usbai_register_destroy(); 1170Sstevel@tonic-gate usba_usba_destroy(); 1180Sstevel@tonic-gate usba_usbai_destroy(); 1190Sstevel@tonic-gate } 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate return (rval); 1220Sstevel@tonic-gate } 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate int 1250Sstevel@tonic-gate _fini() 1260Sstevel@tonic-gate { 1270Sstevel@tonic-gate int rval; 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate if ((rval = mod_remove(&modlinkage)) == 0) { 1300Sstevel@tonic-gate usba_devdb_destroy(); 1310Sstevel@tonic-gate usba_hubdi_destroy(); 1320Sstevel@tonic-gate usba_hcdi_destroy(); 1330Sstevel@tonic-gate usba_usbai_register_destroy(); 1340Sstevel@tonic-gate usba_usba_destroy(); 1350Sstevel@tonic-gate usba_usbai_destroy(); 1360Sstevel@tonic-gate } 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate return (rval); 1390Sstevel@tonic-gate } 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate int 1420Sstevel@tonic-gate _info(struct modinfo *modinfop) 1430Sstevel@tonic-gate { 1440Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 1450Sstevel@tonic-gate } 1460Sstevel@tonic-gate 1473341Sgc161489 boolean_t 1483341Sgc161489 usba_owns_ia(dev_info_t *dip) 1493341Sgc161489 { 1503341Sgc161489 int if_count = ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 1513341Sgc161489 "interface-count", 0); 1523341Sgc161489 1533341Sgc161489 return ((if_count) ? B_TRUE : B_FALSE); 1543341Sgc161489 } 1550Sstevel@tonic-gate 1560Sstevel@tonic-gate /* 1570Sstevel@tonic-gate * common bus ctl for hcd, usb_mid, and hubd 1580Sstevel@tonic-gate */ 1590Sstevel@tonic-gate int 1600Sstevel@tonic-gate usba_bus_ctl(dev_info_t *dip, 1610Sstevel@tonic-gate dev_info_t *rdip, 1620Sstevel@tonic-gate ddi_ctl_enum_t op, 1630Sstevel@tonic-gate void *arg, 1640Sstevel@tonic-gate void *result) 1650Sstevel@tonic-gate { 1660Sstevel@tonic-gate dev_info_t *child_dip = (dev_info_t *)arg; 1670Sstevel@tonic-gate usba_device_t *usba_device; 1680Sstevel@tonic-gate usba_hcdi_t *usba_hcdi; 1690Sstevel@tonic-gate usba_hcdi_ops_t *usba_hcdi_ops; 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_USBA, hubdi_log_handle, 1720Sstevel@tonic-gate "usba_bus_ctl: %s%d %s%d op=%d", ddi_node_name(rdip), 1730Sstevel@tonic-gate ddi_get_instance(rdip), ddi_node_name(dip), 1740Sstevel@tonic-gate ddi_get_instance(dip), op); 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate switch (op) { 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV: 1790Sstevel@tonic-gate { 1800Sstevel@tonic-gate char *name, compat_name[64], *speed; 1810Sstevel@tonic-gate usba_device_t *hub_usba_device; 1820Sstevel@tonic-gate dev_info_t *hubdip; 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate usba_device = usba_get_usba_device(rdip); 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate /* find the parent hub */ 1870Sstevel@tonic-gate hubdip = ddi_get_parent(rdip); 1880Sstevel@tonic-gate while ((strcmp(ddi_driver_name(hubdip), "hubd") != 0) && 1890Sstevel@tonic-gate !(usba_is_root_hub(hubdip))) { 1900Sstevel@tonic-gate hubdip = ddi_get_parent(hubdip); 1910Sstevel@tonic-gate } 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate hub_usba_device = usba_get_usba_device(hubdip); 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate if (usba_device) { 1960Sstevel@tonic-gate if (usb_owns_device(rdip)) { 1970Sstevel@tonic-gate (void) snprintf(compat_name, 1980Sstevel@tonic-gate sizeof (compat_name), 1990Sstevel@tonic-gate "usb%x,%x", 2000Sstevel@tonic-gate usba_device->usb_dev_descr->idVendor, 2010Sstevel@tonic-gate usba_device->usb_dev_descr->idProduct); 2023341Sgc161489 } else if (usba_owns_ia(rdip)) { 2033341Sgc161489 (void) snprintf(compat_name, 2043341Sgc161489 sizeof (compat_name), 2053341Sgc161489 "usbia%x,%x.config%x.%x", 2063341Sgc161489 usba_device->usb_dev_descr->idVendor, 2073341Sgc161489 usba_device->usb_dev_descr->idProduct, 2083341Sgc161489 usba_device->usb_cfg_value, 2093341Sgc161489 usb_get_if_number(rdip)); 2100Sstevel@tonic-gate } else { 2110Sstevel@tonic-gate (void) snprintf(compat_name, 2120Sstevel@tonic-gate sizeof (compat_name), 2130Sstevel@tonic-gate "usbif%x,%x.config%x.%x", 2140Sstevel@tonic-gate usba_device->usb_dev_descr->idVendor, 2150Sstevel@tonic-gate usba_device->usb_dev_descr->idProduct, 2160Sstevel@tonic-gate usba_device->usb_cfg_value, 2170Sstevel@tonic-gate usb_get_if_number(rdip)); 2180Sstevel@tonic-gate } 2190Sstevel@tonic-gate switch (usba_device->usb_port_status) { 2200Sstevel@tonic-gate case USBA_HIGH_SPEED_DEV: 2210Sstevel@tonic-gate speed = "hi speed (USB 2.x)"; 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate break; 2240Sstevel@tonic-gate case USBA_LOW_SPEED_DEV: 2250Sstevel@tonic-gate speed = "low speed (USB 1.x)"; 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate break; 2280Sstevel@tonic-gate case USBA_FULL_SPEED_DEV: 2290Sstevel@tonic-gate default: 2300Sstevel@tonic-gate speed = "full speed (USB 1.x)"; 2310Sstevel@tonic-gate 2320Sstevel@tonic-gate break; 2330Sstevel@tonic-gate } 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate cmn_err(CE_CONT, 2360Sstevel@tonic-gate "?USB %x.%x %s (%s) operating at %s on " 2370Sstevel@tonic-gate "USB %x.%x %s hub: " 2380Sstevel@tonic-gate "%s@%s, %s%d at bus address %d\n", 2390Sstevel@tonic-gate (usba_device->usb_dev_descr->bcdUSB & 0xff00) >> 8, 2400Sstevel@tonic-gate usba_device->usb_dev_descr->bcdUSB & 0xff, 2413341Sgc161489 (usb_owns_device(rdip) ? "device" : 2423341Sgc161489 ((usba_owns_ia(rdip) ? "interface-association" : 2433341Sgc161489 "interface"))), 2440Sstevel@tonic-gate compat_name, speed, 2450Sstevel@tonic-gate (hub_usba_device->usb_dev_descr->bcdUSB & 2460Sstevel@tonic-gate 0xff00) >> 8, 2470Sstevel@tonic-gate hub_usba_device->usb_dev_descr->bcdUSB & 0xff, 2480Sstevel@tonic-gate usba_is_root_hub(hubdip) ? "root" : "external", 2490Sstevel@tonic-gate ddi_node_name(rdip), ddi_get_name_addr(rdip), 2500Sstevel@tonic-gate ddi_driver_name(rdip), 2510Sstevel@tonic-gate ddi_get_instance(rdip), usba_device->usb_addr); 2520Sstevel@tonic-gate 2530Sstevel@tonic-gate name = kmem_alloc(MAXNAMELEN, KM_SLEEP); 2540Sstevel@tonic-gate (void) usba_get_mfg_prod_sn_str(rdip, name, MAXNAMELEN); 2550Sstevel@tonic-gate if (name[0] != '\0') { 2560Sstevel@tonic-gate cmn_err(CE_CONT, "?\t%s\n", name); 2570Sstevel@tonic-gate } 2580Sstevel@tonic-gate kmem_free(name, MAXNAMELEN); 2590Sstevel@tonic-gate 2600Sstevel@tonic-gate } else { /* harden USBA against this case; if it happens */ 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate cmn_err(CE_CONT, 2630Sstevel@tonic-gate "?USB-device: %s@%s, %s%d\n", 2640Sstevel@tonic-gate ddi_node_name(rdip), ddi_get_name_addr(rdip), 2650Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip)); 2660Sstevel@tonic-gate } 2670Sstevel@tonic-gate 2680Sstevel@tonic-gate return (DDI_SUCCESS); 2690Sstevel@tonic-gate } 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD: 2720Sstevel@tonic-gate { 2730Sstevel@tonic-gate int usb_addr; 2740Sstevel@tonic-gate uint_t n; 2750Sstevel@tonic-gate char name[32]; 2760Sstevel@tonic-gate int *data; 2770Sstevel@tonic-gate int rval; 2780Sstevel@tonic-gate int len = sizeof (usb_addr); 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate usba_hcdi = usba_hcdi_get_hcdi(dip); 2810Sstevel@tonic-gate usba_hcdi_ops = usba_hcdi->hcdi_ops; 2820Sstevel@tonic-gate ASSERT(usba_hcdi_ops != NULL); 2830Sstevel@tonic-gate 2840Sstevel@tonic-gate /* 2850Sstevel@tonic-gate * as long as the dip exists, it should have 2860Sstevel@tonic-gate * usba_device structure associated with it 2870Sstevel@tonic-gate */ 2880Sstevel@tonic-gate usba_device = usba_get_usba_device(child_dip); 2890Sstevel@tonic-gate if (usba_device == NULL) { 2900Sstevel@tonic-gate 2910Sstevel@tonic-gate USB_DPRINTF_L2(DPRINT_MASK_USBA, hubdi_log_handle, 2920Sstevel@tonic-gate "usba_bus_ctl: DDI_NOT_WELL_FORMED (%s (0x%p))", 2930Sstevel@tonic-gate ddi_node_name(child_dip), (void *)child_dip); 2940Sstevel@tonic-gate 2950Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 2960Sstevel@tonic-gate } 2970Sstevel@tonic-gate 2980Sstevel@tonic-gate /* the dip should have an address and reg property */ 2990Sstevel@tonic-gate if (ddi_prop_op(DDI_DEV_T_NONE, child_dip, PROP_LEN_AND_VAL_BUF, 3000Sstevel@tonic-gate DDI_PROP_DONTPASS | DDI_PROP_CANSLEEP, "assigned-address", 3010Sstevel@tonic-gate (caddr_t)&usb_addr, &len) != DDI_SUCCESS) { 3020Sstevel@tonic-gate 303978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, hubdi_log_handle, 3040Sstevel@tonic-gate "usba_bus_ctl:\n\t" 3050Sstevel@tonic-gate "%s%d %s%d op=%d rdip = 0x%p dip = 0x%p", 3060Sstevel@tonic-gate ddi_node_name(rdip), ddi_get_instance(rdip), 3070Sstevel@tonic-gate ddi_node_name(dip), ddi_get_instance(dip), op, 3080Sstevel@tonic-gate rdip, dip); 3090Sstevel@tonic-gate 310978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, hubdi_log_handle, 3110Sstevel@tonic-gate "usba_bus_ctl: DDI_NOT_WELL_FORMED (%s (0x%p))", 3120Sstevel@tonic-gate ddi_node_name(child_dip), (void *)child_dip); 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 3150Sstevel@tonic-gate } 3160Sstevel@tonic-gate 3170Sstevel@tonic-gate if ((rval = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, child_dip, 3180Sstevel@tonic-gate DDI_PROP_DONTPASS, "reg", 3190Sstevel@tonic-gate &data, &n)) != DDI_SUCCESS) { 3200Sstevel@tonic-gate 321978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, hubdi_log_handle, 3220Sstevel@tonic-gate "usba_bus_ctl: %d, DDI_NOT_WELL_FORMED", rval); 3230Sstevel@tonic-gate 3240Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 3250Sstevel@tonic-gate } 3260Sstevel@tonic-gate 3270Sstevel@tonic-gate 3280Sstevel@tonic-gate /* 3290Sstevel@tonic-gate * if the configuration is 1, the unit address is 3300Sstevel@tonic-gate * just the interface number 3310Sstevel@tonic-gate */ 3320Sstevel@tonic-gate if ((n == 1) || ((n > 1) && (data[1] == 1))) { 3330Sstevel@tonic-gate (void) sprintf(name, "%x", data[0]); 3340Sstevel@tonic-gate } else { 3350Sstevel@tonic-gate (void) sprintf(name, "%x,%x", data[0], data[1]); 3360Sstevel@tonic-gate } 3370Sstevel@tonic-gate 3380Sstevel@tonic-gate USB_DPRINTF_L3(DPRINT_MASK_USBA, 3390Sstevel@tonic-gate hubdi_log_handle, "usba_bus_ctl: name = %s", name); 3400Sstevel@tonic-gate 3410Sstevel@tonic-gate ddi_prop_free(data); 3420Sstevel@tonic-gate ddi_set_name_addr(child_dip, name); 3430Sstevel@tonic-gate 3440Sstevel@tonic-gate /* 3450Sstevel@tonic-gate * increment the reference count for each child using this 3460Sstevel@tonic-gate * usba_device structure 3470Sstevel@tonic-gate */ 3480Sstevel@tonic-gate mutex_enter(&usba_device->usb_mutex); 3490Sstevel@tonic-gate usba_device->usb_ref_count++; 3500Sstevel@tonic-gate 3510Sstevel@tonic-gate USB_DPRINTF_L3(DPRINT_MASK_USBA, hubdi_log_handle, 3520Sstevel@tonic-gate "usba_bus_ctl: init usba_device = 0x%p ref_count = %d", 3530Sstevel@tonic-gate (void *)usba_device, usba_device->usb_ref_count); 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex); 3560Sstevel@tonic-gate 3570Sstevel@tonic-gate return (DDI_SUCCESS); 3580Sstevel@tonic-gate } 3590Sstevel@tonic-gate 3600Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD: 3610Sstevel@tonic-gate { 3620Sstevel@tonic-gate usba_device = usba_get_usba_device(child_dip); 3630Sstevel@tonic-gate 3640Sstevel@tonic-gate if (usba_device != NULL) { 3650Sstevel@tonic-gate /* 3660Sstevel@tonic-gate * decrement the reference count for each child 3670Sstevel@tonic-gate * using this usba_device structure 3680Sstevel@tonic-gate */ 3690Sstevel@tonic-gate mutex_enter(&usba_device->usb_mutex); 3700Sstevel@tonic-gate usba_device->usb_ref_count--; 3710Sstevel@tonic-gate 3720Sstevel@tonic-gate USB_DPRINTF_L3(DPRINT_MASK_USBA, hubdi_log_handle, 3730Sstevel@tonic-gate "usba_hcdi_bus_ctl: uninit usba_device=0x%p " 3740Sstevel@tonic-gate "ref_count=%d", 3750Sstevel@tonic-gate usba_device, usba_device->usb_ref_count); 3760Sstevel@tonic-gate 3770Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex); 3780Sstevel@tonic-gate } 3790Sstevel@tonic-gate ddi_set_name_addr(child_dip, NULL); 3800Sstevel@tonic-gate 3810Sstevel@tonic-gate return (DDI_SUCCESS); 3820Sstevel@tonic-gate } 3830Sstevel@tonic-gate 3840Sstevel@tonic-gate case DDI_CTLOPS_IOMIN: 3850Sstevel@tonic-gate /* Do nothing */ 3860Sstevel@tonic-gate return (DDI_SUCCESS); 3870Sstevel@tonic-gate 3880Sstevel@tonic-gate /* 3890Sstevel@tonic-gate * These ops correspond to functions that "shouldn't" be called 3900Sstevel@tonic-gate * by a USB client driver. So we whine when we're called. 3910Sstevel@tonic-gate */ 3920Sstevel@tonic-gate case DDI_CTLOPS_DMAPMAPC: 3930Sstevel@tonic-gate case DDI_CTLOPS_REPORTINT: 3940Sstevel@tonic-gate case DDI_CTLOPS_REGSIZE: 3950Sstevel@tonic-gate case DDI_CTLOPS_NREGS: 3960Sstevel@tonic-gate case DDI_CTLOPS_SIDDEV: 3970Sstevel@tonic-gate case DDI_CTLOPS_SLAVEONLY: 3980Sstevel@tonic-gate case DDI_CTLOPS_AFFINITY: 3990Sstevel@tonic-gate case DDI_CTLOPS_POKE: 4000Sstevel@tonic-gate case DDI_CTLOPS_PEEK: 4010Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d: invalid op (%d) from %s%d", 4020Sstevel@tonic-gate ddi_node_name(dip), ddi_get_instance(dip), 4030Sstevel@tonic-gate op, ddi_node_name(rdip), ddi_get_instance(rdip)); 4040Sstevel@tonic-gate return (DDI_FAILURE); 4050Sstevel@tonic-gate 4060Sstevel@tonic-gate /* 4070Sstevel@tonic-gate * Everything else (e.g. PTOB/BTOP/BTOPR requests) we pass up 4080Sstevel@tonic-gate */ 4090Sstevel@tonic-gate default: 4100Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, op, arg, result)); 4110Sstevel@tonic-gate } 4120Sstevel@tonic-gate } 4130Sstevel@tonic-gate 4140Sstevel@tonic-gate 4150Sstevel@tonic-gate /* 4160Sstevel@tonic-gate * initialize and destroy USBA module 4170Sstevel@tonic-gate */ 4180Sstevel@tonic-gate void 4190Sstevel@tonic-gate usba_usba_initialization() 4200Sstevel@tonic-gate { 4210Sstevel@tonic-gate usba_log_handle = usb_alloc_log_hdl(NULL, "usba", &usba_errlevel, 4220Sstevel@tonic-gate &usba_errmask, NULL, 0); 4230Sstevel@tonic-gate 4240Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_USBA, 4250Sstevel@tonic-gate usba_log_handle, "usba_usba_initialization"); 4260Sstevel@tonic-gate 4270Sstevel@tonic-gate mutex_init(&usba_mutex, NULL, MUTEX_DRIVER, NULL); 4280Sstevel@tonic-gate usba_init_list(&usba_device_list, NULL, NULL); 4290Sstevel@tonic-gate } 4300Sstevel@tonic-gate 4310Sstevel@tonic-gate 4320Sstevel@tonic-gate void 4330Sstevel@tonic-gate usba_usba_destroy() 4340Sstevel@tonic-gate { 4350Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_USBA, usba_log_handle, "usba_usba_destroy"); 4360Sstevel@tonic-gate 4370Sstevel@tonic-gate mutex_destroy(&usba_mutex); 4380Sstevel@tonic-gate usba_destroy_list(&usba_device_list); 4390Sstevel@tonic-gate 4400Sstevel@tonic-gate usb_free_log_hdl(usba_log_handle); 4410Sstevel@tonic-gate } 4420Sstevel@tonic-gate 4430Sstevel@tonic-gate 4440Sstevel@tonic-gate /* 4450Sstevel@tonic-gate * usba_set_usb_address: 4460Sstevel@tonic-gate * set usb address in usba_device structure 4470Sstevel@tonic-gate */ 4480Sstevel@tonic-gate int 4490Sstevel@tonic-gate usba_set_usb_address(usba_device_t *usba_device) 4500Sstevel@tonic-gate { 4510Sstevel@tonic-gate usb_addr_t address; 4520Sstevel@tonic-gate uchar_t s = 8; 4530Sstevel@tonic-gate usba_hcdi_t *hcdi; 4540Sstevel@tonic-gate char *usb_address_in_use; 4550Sstevel@tonic-gate 4560Sstevel@tonic-gate mutex_enter(&usba_device->usb_mutex); 4570Sstevel@tonic-gate 4580Sstevel@tonic-gate hcdi = usba_hcdi_get_hcdi(usba_device->usb_root_hub_dip); 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate mutex_enter(&hcdi->hcdi_mutex); 4610Sstevel@tonic-gate usb_address_in_use = hcdi->hcdi_usb_address_in_use; 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate for (address = ROOT_HUB_ADDR + 1; 4640Sstevel@tonic-gate address <= USBA_MAX_ADDRESS; address++) { 4650Sstevel@tonic-gate if (usb_address_in_use[address/s] & (1 << (address % s))) { 4660Sstevel@tonic-gate continue; 4670Sstevel@tonic-gate } 4680Sstevel@tonic-gate usb_address_in_use[address/s] |= (1 << (address % s)); 4690Sstevel@tonic-gate hcdi->hcdi_device_count++; 4700Sstevel@tonic-gate HCDI_HOTPLUG_STATS_DATA(hcdi)->hcdi_device_count.value.ui64++; 4710Sstevel@tonic-gate mutex_exit(&hcdi->hcdi_mutex); 4720Sstevel@tonic-gate 4730Sstevel@tonic-gate USB_DPRINTF_L3(DPRINT_MASK_USBA, usba_log_handle, 4740Sstevel@tonic-gate "usba_set_usb_address: %d", address); 4750Sstevel@tonic-gate 4760Sstevel@tonic-gate usba_device->usb_addr = address; 4770Sstevel@tonic-gate 4780Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex); 4790Sstevel@tonic-gate 4800Sstevel@tonic-gate return (USB_SUCCESS); 4810Sstevel@tonic-gate } 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate usba_device->usb_addr = 0; 4840Sstevel@tonic-gate 485978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 4860Sstevel@tonic-gate "no usb address available"); 4870Sstevel@tonic-gate 4880Sstevel@tonic-gate mutex_exit(&hcdi->hcdi_mutex); 4890Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex); 4900Sstevel@tonic-gate 4910Sstevel@tonic-gate return (USB_FAILURE); 4920Sstevel@tonic-gate } 4930Sstevel@tonic-gate 4940Sstevel@tonic-gate 4950Sstevel@tonic-gate /* 4960Sstevel@tonic-gate * usba_unset_usb_address: 4970Sstevel@tonic-gate * unset usb_address in usba_device structure 4980Sstevel@tonic-gate */ 4990Sstevel@tonic-gate void 5000Sstevel@tonic-gate usba_unset_usb_address(usba_device_t *usba_device) 5010Sstevel@tonic-gate { 5020Sstevel@tonic-gate usb_addr_t address; 5030Sstevel@tonic-gate usba_hcdi_t *hcdi; 5040Sstevel@tonic-gate uchar_t s = 8; 5050Sstevel@tonic-gate char *usb_address_in_use; 5060Sstevel@tonic-gate 5070Sstevel@tonic-gate mutex_enter(&usba_device->usb_mutex); 5080Sstevel@tonic-gate address = usba_device->usb_addr; 5090Sstevel@tonic-gate hcdi = usba_hcdi_get_hcdi(usba_device->usb_root_hub_dip); 5100Sstevel@tonic-gate 5110Sstevel@tonic-gate if (address > ROOT_HUB_ADDR) { 5120Sstevel@tonic-gate USB_DPRINTF_L3(DPRINT_MASK_USBA, usba_log_handle, 5130Sstevel@tonic-gate "usba_unset_usb_address: address=%d", address); 5140Sstevel@tonic-gate 5150Sstevel@tonic-gate mutex_enter(&hcdi->hcdi_mutex); 5160Sstevel@tonic-gate usb_address_in_use = hcdi->hcdi_usb_address_in_use; 5170Sstevel@tonic-gate 5180Sstevel@tonic-gate ASSERT(usb_address_in_use[address/s] & (1 << (address % s))); 5190Sstevel@tonic-gate 5200Sstevel@tonic-gate usb_address_in_use[address/s] &= ~(1 << (address % s)); 5210Sstevel@tonic-gate 5220Sstevel@tonic-gate hcdi->hcdi_device_count--; 5230Sstevel@tonic-gate HCDI_HOTPLUG_STATS_DATA(hcdi)->hcdi_device_count.value.ui64--; 5240Sstevel@tonic-gate 5250Sstevel@tonic-gate mutex_exit(&hcdi->hcdi_mutex); 5260Sstevel@tonic-gate 5270Sstevel@tonic-gate usba_device->usb_addr = 0; 5280Sstevel@tonic-gate } 5290Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex); 5300Sstevel@tonic-gate } 5310Sstevel@tonic-gate 5320Sstevel@tonic-gate 5330Sstevel@tonic-gate struct usba_evdata * 5340Sstevel@tonic-gate usba_get_evdata(dev_info_t *dip) 5350Sstevel@tonic-gate { 5360Sstevel@tonic-gate usba_evdata_t *evdata; 5370Sstevel@tonic-gate usba_device_t *usba_device = usba_get_usba_device(dip); 5380Sstevel@tonic-gate 5390Sstevel@tonic-gate /* called when dip attaches */ 5400Sstevel@tonic-gate ASSERT(usba_device != NULL); 5410Sstevel@tonic-gate 5420Sstevel@tonic-gate mutex_enter(&usba_device->usb_mutex); 5430Sstevel@tonic-gate evdata = usba_device->usb_evdata; 5440Sstevel@tonic-gate while (evdata) { 5450Sstevel@tonic-gate if (evdata->ev_dip == dip) { 5460Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex); 5470Sstevel@tonic-gate 5480Sstevel@tonic-gate return (evdata); 5490Sstevel@tonic-gate } 5500Sstevel@tonic-gate evdata = evdata->ev_next; 5510Sstevel@tonic-gate } 5520Sstevel@tonic-gate 5530Sstevel@tonic-gate evdata = kmem_zalloc(sizeof (usba_evdata_t), KM_SLEEP); 5540Sstevel@tonic-gate evdata->ev_dip = dip; 5550Sstevel@tonic-gate evdata->ev_next = usba_device->usb_evdata; 5560Sstevel@tonic-gate usba_device->usb_evdata = evdata; 5570Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex); 5580Sstevel@tonic-gate 5590Sstevel@tonic-gate return (evdata); 5600Sstevel@tonic-gate } 5610Sstevel@tonic-gate 5620Sstevel@tonic-gate 5630Sstevel@tonic-gate /* 5640Sstevel@tonic-gate * allocate a usb device structure and link it in the list 5650Sstevel@tonic-gate */ 5660Sstevel@tonic-gate usba_device_t * 5670Sstevel@tonic-gate usba_alloc_usba_device(dev_info_t *root_hub_dip) 5680Sstevel@tonic-gate { 5690Sstevel@tonic-gate usba_device_t *usba_device; 5700Sstevel@tonic-gate int ep_idx; 5710Sstevel@tonic-gate ddi_iblock_cookie_t iblock_cookie = 5720Sstevel@tonic-gate usba_hcdi_get_hcdi(root_hub_dip)->hcdi_iblock_cookie; 5730Sstevel@tonic-gate 5740Sstevel@tonic-gate /* 5750Sstevel@tonic-gate * create a new usba_device structure 5760Sstevel@tonic-gate */ 5770Sstevel@tonic-gate usba_device = kmem_zalloc(sizeof (usba_device_t), KM_SLEEP); 5780Sstevel@tonic-gate 5790Sstevel@tonic-gate /* 5800Sstevel@tonic-gate * initialize usba_device 5810Sstevel@tonic-gate */ 5820Sstevel@tonic-gate mutex_init(&usba_device->usb_mutex, NULL, MUTEX_DRIVER, 5830Sstevel@tonic-gate iblock_cookie); 5840Sstevel@tonic-gate 5850Sstevel@tonic-gate usba_init_list(&usba_device->usb_device_list, (usb_opaque_t)usba_device, 5860Sstevel@tonic-gate iblock_cookie); 5870Sstevel@tonic-gate usba_init_list(&usba_device->usb_allocated, (usb_opaque_t)usba_device, 5880Sstevel@tonic-gate iblock_cookie); 5890Sstevel@tonic-gate mutex_enter(&usba_device->usb_mutex); 5900Sstevel@tonic-gate usba_device->usb_root_hub_dip = root_hub_dip; 5910Sstevel@tonic-gate 5920Sstevel@tonic-gate /* 5930Sstevel@tonic-gate * add to list of usba_devices 5940Sstevel@tonic-gate */ 5950Sstevel@tonic-gate usba_add_to_list(&usba_device_list, &usba_device->usb_device_list); 5960Sstevel@tonic-gate 5970Sstevel@tonic-gate /* init mutex in each usba_ph_impl structure */ 5980Sstevel@tonic-gate for (ep_idx = 0; ep_idx < USBA_N_ENDPOINTS; ep_idx++) { 5990Sstevel@tonic-gate mutex_init(&usba_device->usb_ph_list[ep_idx].usba_ph_mutex, 6000Sstevel@tonic-gate NULL, MUTEX_DRIVER, iblock_cookie); 6010Sstevel@tonic-gate } 6020Sstevel@tonic-gate 6030Sstevel@tonic-gate USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 6040Sstevel@tonic-gate "allocated usba_device 0x%p", (void *)usba_device); 6050Sstevel@tonic-gate 6060Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex); 6070Sstevel@tonic-gate 6080Sstevel@tonic-gate return (usba_device); 6090Sstevel@tonic-gate } 6100Sstevel@tonic-gate 6110Sstevel@tonic-gate 6120Sstevel@tonic-gate /* free NDI event data associated with usba_device */ 6130Sstevel@tonic-gate void 6140Sstevel@tonic-gate usba_free_evdata(usba_evdata_t *evdata) 6150Sstevel@tonic-gate { 6160Sstevel@tonic-gate usba_evdata_t *next; 6170Sstevel@tonic-gate 6180Sstevel@tonic-gate while (evdata) { 6190Sstevel@tonic-gate next = evdata->ev_next; 6200Sstevel@tonic-gate kmem_free(evdata, sizeof (usba_evdata_t)); 6210Sstevel@tonic-gate evdata = next; 6220Sstevel@tonic-gate } 6230Sstevel@tonic-gate } 6240Sstevel@tonic-gate 6250Sstevel@tonic-gate 6260Sstevel@tonic-gate /* 6270Sstevel@tonic-gate * free usb device structure 6280Sstevel@tonic-gate */ 6290Sstevel@tonic-gate void 6300Sstevel@tonic-gate usba_free_usba_device(usba_device_t *usba_device) 6310Sstevel@tonic-gate { 6320Sstevel@tonic-gate int i, ep_idx; 6330Sstevel@tonic-gate usb_pipe_handle_t def_ph; 6340Sstevel@tonic-gate 6350Sstevel@tonic-gate if (usba_device == NULL) { 6360Sstevel@tonic-gate 6370Sstevel@tonic-gate return; 6380Sstevel@tonic-gate } 6390Sstevel@tonic-gate 6400Sstevel@tonic-gate mutex_enter(&usba_device->usb_mutex); 6410Sstevel@tonic-gate if (usba_device->usb_ref_count) { 6420Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex); 6430Sstevel@tonic-gate 6440Sstevel@tonic-gate return; 6450Sstevel@tonic-gate } 6460Sstevel@tonic-gate 6470Sstevel@tonic-gate USB_DPRINTF_L3(DPRINT_MASK_USBA, usba_log_handle, 6480Sstevel@tonic-gate "usba_free_usba_device 0x%p, address=0x%x, ref cnt=%d", 6490Sstevel@tonic-gate (void *)usba_device, usba_device->usb_addr, 6500Sstevel@tonic-gate usba_device->usb_ref_count); 6510Sstevel@tonic-gate 6520Sstevel@tonic-gate usba_free_evdata(usba_device->usb_evdata); 6530Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex); 6540Sstevel@tonic-gate 6550Sstevel@tonic-gate def_ph = usba_usbdev_to_dflt_pipe_handle(usba_device); 6560Sstevel@tonic-gate if (def_ph != NULL) { 6570Sstevel@tonic-gate usba_pipe_handle_data_t *ph_data = usba_get_ph_data(def_ph); 6580Sstevel@tonic-gate 6590Sstevel@tonic-gate if (ph_data) { 6600Sstevel@tonic-gate usb_pipe_close(ph_data->p_dip, def_ph, 6610Sstevel@tonic-gate USB_FLAGS_SLEEP | USBA_FLAGS_PRIVILEGED, 6620Sstevel@tonic-gate NULL, NULL); 6630Sstevel@tonic-gate } 6640Sstevel@tonic-gate } 6650Sstevel@tonic-gate 6660Sstevel@tonic-gate mutex_enter(&usba_mutex); 6670Sstevel@tonic-gate 6680Sstevel@tonic-gate /* destroy mutex in each usba_ph_impl structure */ 6690Sstevel@tonic-gate for (ep_idx = 0; ep_idx < USBA_N_ENDPOINTS; ep_idx++) { 6700Sstevel@tonic-gate mutex_destroy(&usba_device->usb_ph_list[ep_idx].usba_ph_mutex); 6710Sstevel@tonic-gate } 6720Sstevel@tonic-gate 6730Sstevel@tonic-gate (void) usba_rm_from_list(&usba_device_list, 6740Sstevel@tonic-gate &usba_device->usb_device_list); 6750Sstevel@tonic-gate 6760Sstevel@tonic-gate mutex_exit(&usba_mutex); 6770Sstevel@tonic-gate 6780Sstevel@tonic-gate usba_destroy_list(&usba_device->usb_device_list); 6790Sstevel@tonic-gate usba_destroy_list(&usba_device->usb_allocated); 6800Sstevel@tonic-gate 6810Sstevel@tonic-gate USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 6820Sstevel@tonic-gate "deallocating usba_device = 0x%p, address = 0x%x", 6830Sstevel@tonic-gate (void *)usba_device, usba_device->usb_addr); 6840Sstevel@tonic-gate 6850Sstevel@tonic-gate /* 6860Sstevel@tonic-gate * ohci allocates descriptors for root hub so we can't 6870Sstevel@tonic-gate * deallocate these here 6880Sstevel@tonic-gate */ 6890Sstevel@tonic-gate 6900Sstevel@tonic-gate if (usba_device->usb_addr != ROOT_HUB_ADDR) { 6910Sstevel@tonic-gate if (usba_device->usb_cfg_array) { 6920Sstevel@tonic-gate USB_DPRINTF_L3(DPRINT_MASK_USBA, usba_log_handle, 6930Sstevel@tonic-gate "deallocating usb_config_array: 0x%p", 6940Sstevel@tonic-gate usba_device->usb_cfg_array); 6950Sstevel@tonic-gate mutex_enter(&usba_device->usb_mutex); 6960Sstevel@tonic-gate for (i = 0; 6970Sstevel@tonic-gate i < usba_device->usb_dev_descr->bNumConfigurations; 6980Sstevel@tonic-gate i++) { 6990Sstevel@tonic-gate if (usba_device->usb_cfg_array[i]) { 7000Sstevel@tonic-gate kmem_free( 7010Sstevel@tonic-gate usba_device->usb_cfg_array[i], 7020Sstevel@tonic-gate usba_device->usb_cfg_array_len[i]); 7030Sstevel@tonic-gate } 7040Sstevel@tonic-gate } 7050Sstevel@tonic-gate 7060Sstevel@tonic-gate /* free the array pointers */ 7070Sstevel@tonic-gate kmem_free(usba_device->usb_cfg_array, 7080Sstevel@tonic-gate usba_device->usb_cfg_array_length); 7090Sstevel@tonic-gate kmem_free(usba_device->usb_cfg_array_len, 7100Sstevel@tonic-gate usba_device->usb_cfg_array_len_length); 7110Sstevel@tonic-gate 7120Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex); 7130Sstevel@tonic-gate } 7140Sstevel@tonic-gate 7150Sstevel@tonic-gate if (usba_device->usb_cfg_str_descr) { 7160Sstevel@tonic-gate USB_DPRINTF_L3(DPRINT_MASK_USBA, usba_log_handle, 7170Sstevel@tonic-gate "deallocating usb_cfg_str_descr: 0x%p", 7180Sstevel@tonic-gate usba_device->usb_cfg_str_descr); 7190Sstevel@tonic-gate for (i = 0; 7200Sstevel@tonic-gate i < usba_device->usb_dev_descr->bNumConfigurations; 7210Sstevel@tonic-gate i++) { 7220Sstevel@tonic-gate if (usba_device->usb_cfg_str_descr[i]) { 7230Sstevel@tonic-gate kmem_free( 7240Sstevel@tonic-gate usba_device->usb_cfg_str_descr[i], 7250Sstevel@tonic-gate strlen(usba_device-> 7260Sstevel@tonic-gate usb_cfg_str_descr[i]) + 1); 7270Sstevel@tonic-gate } 7280Sstevel@tonic-gate } 7290Sstevel@tonic-gate /* free the array pointers */ 7300Sstevel@tonic-gate kmem_free(usba_device->usb_cfg_str_descr, 7310Sstevel@tonic-gate sizeof (uchar_t *) * usba_device->usb_n_cfgs); 7320Sstevel@tonic-gate } 7330Sstevel@tonic-gate 7340Sstevel@tonic-gate if (usba_device->usb_dev_descr) { 7350Sstevel@tonic-gate kmem_free(usba_device->usb_dev_descr, 7360Sstevel@tonic-gate sizeof (usb_dev_descr_t)); 7370Sstevel@tonic-gate } 7380Sstevel@tonic-gate 7390Sstevel@tonic-gate if (usba_device->usb_mfg_str) { 7400Sstevel@tonic-gate kmem_free(usba_device->usb_mfg_str, 7410Sstevel@tonic-gate strlen(usba_device->usb_mfg_str) + 1); 7420Sstevel@tonic-gate } 7430Sstevel@tonic-gate 7440Sstevel@tonic-gate if (usba_device->usb_product_str) { 7450Sstevel@tonic-gate kmem_free(usba_device->usb_product_str, 7460Sstevel@tonic-gate strlen(usba_device->usb_product_str) + 1); 7470Sstevel@tonic-gate } 7480Sstevel@tonic-gate 7490Sstevel@tonic-gate if (usba_device->usb_serialno_str) { 7500Sstevel@tonic-gate kmem_free(usba_device->usb_serialno_str, 7510Sstevel@tonic-gate strlen(usba_device->usb_serialno_str) + 1); 7520Sstevel@tonic-gate } 7530Sstevel@tonic-gate 7540Sstevel@tonic-gate usba_unset_usb_address(usba_device); 7550Sstevel@tonic-gate } 7560Sstevel@tonic-gate 7570Sstevel@tonic-gate #ifndef __lock_lint 7580Sstevel@tonic-gate ASSERT(usba_device->usb_client_dev_data_list.cddl_next == NULL); 7590Sstevel@tonic-gate #endif 7600Sstevel@tonic-gate 7610Sstevel@tonic-gate if (usba_device->usb_client_flags) { 7620Sstevel@tonic-gate #ifndef __lock_lint 7630Sstevel@tonic-gate int i; 7640Sstevel@tonic-gate 7650Sstevel@tonic-gate for (i = 0; i < usba_device->usb_n_ifs; i++) { 7660Sstevel@tonic-gate ASSERT(usba_device->usb_client_flags[i] == 0); 7670Sstevel@tonic-gate } 7680Sstevel@tonic-gate #endif 7690Sstevel@tonic-gate kmem_free(usba_device->usb_client_flags, 7700Sstevel@tonic-gate usba_device->usb_n_ifs * USBA_CLIENT_FLAG_SIZE); 7710Sstevel@tonic-gate } 7720Sstevel@tonic-gate 7730Sstevel@tonic-gate 7740Sstevel@tonic-gate if (usba_device->usb_client_attach_list) { 7750Sstevel@tonic-gate kmem_free(usba_device->usb_client_attach_list, 7760Sstevel@tonic-gate usba_device->usb_n_ifs * 7770Sstevel@tonic-gate sizeof (*usba_device->usb_client_attach_list)); 7780Sstevel@tonic-gate } 7790Sstevel@tonic-gate if (usba_device->usb_client_ev_cb_list) { 7800Sstevel@tonic-gate kmem_free(usba_device->usb_client_ev_cb_list, 7810Sstevel@tonic-gate usba_device->usb_n_ifs * 7820Sstevel@tonic-gate sizeof (*usba_device->usb_client_ev_cb_list)); 7830Sstevel@tonic-gate } 7840Sstevel@tonic-gate 7850Sstevel@tonic-gate /* 7860Sstevel@tonic-gate * finally ready to destroy the structure 7870Sstevel@tonic-gate */ 7880Sstevel@tonic-gate mutex_destroy(&usba_device->usb_mutex); 7890Sstevel@tonic-gate 7900Sstevel@tonic-gate kmem_free((caddr_t)usba_device, sizeof (usba_device_t)); 7910Sstevel@tonic-gate } 7920Sstevel@tonic-gate 7930Sstevel@tonic-gate 7940Sstevel@tonic-gate /* clear the data toggle for all endpoints on this device */ 7950Sstevel@tonic-gate void 7960Sstevel@tonic-gate usba_clear_data_toggle(usba_device_t *usba_device) 7970Sstevel@tonic-gate { 7980Sstevel@tonic-gate int i; 7990Sstevel@tonic-gate 8000Sstevel@tonic-gate if (usba_device != NULL) { 8010Sstevel@tonic-gate mutex_enter(&usba_device->usb_mutex); 8020Sstevel@tonic-gate for (i = 0; i < USBA_N_ENDPOINTS; i++) { 8030Sstevel@tonic-gate usba_device->usb_ph_list[i].usba_ph_flags &= 8040Sstevel@tonic-gate ~USBA_PH_DATA_TOGGLE; 8050Sstevel@tonic-gate } 8060Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex); 8070Sstevel@tonic-gate } 8080Sstevel@tonic-gate } 8090Sstevel@tonic-gate 8100Sstevel@tonic-gate 8110Sstevel@tonic-gate /* 8120Sstevel@tonic-gate * usba_create_child_devi(): 8130Sstevel@tonic-gate * create a child devinfo node, usba_device, attach properties. 8140Sstevel@tonic-gate * the usba_device structure is shared between all interfaces 8150Sstevel@tonic-gate */ 8160Sstevel@tonic-gate int 8170Sstevel@tonic-gate usba_create_child_devi(dev_info_t *dip, 8180Sstevel@tonic-gate char *node_name, 8190Sstevel@tonic-gate usba_hcdi_ops_t *usba_hcdi_ops, 8200Sstevel@tonic-gate dev_info_t *usb_root_hub_dip, 8210Sstevel@tonic-gate usb_port_status_t port_status, 8220Sstevel@tonic-gate usba_device_t *usba_device, 8230Sstevel@tonic-gate dev_info_t **child_dip) 8240Sstevel@tonic-gate { 8250Sstevel@tonic-gate int rval = USB_FAILURE; 8260Sstevel@tonic-gate int usba_device_allocated = 0; 8270Sstevel@tonic-gate usb_addr_t address; 8280Sstevel@tonic-gate 8290Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_USBA, usba_log_handle, 8300Sstevel@tonic-gate "usba_create_child_devi: %s usba_device=0x%p " 8310Sstevel@tonic-gate "port status=0x%x", node_name, 8320Sstevel@tonic-gate (void *)usba_device, port_status); 8330Sstevel@tonic-gate 834789Sahrens ndi_devi_alloc_sleep(dip, node_name, (pnode_t)DEVI_SID_NODEID, 8350Sstevel@tonic-gate child_dip); 8360Sstevel@tonic-gate 8370Sstevel@tonic-gate USB_DPRINTF_L3(DPRINT_MASK_USBA, usba_log_handle, 8380Sstevel@tonic-gate "child dip=0x%p", *child_dip); 8390Sstevel@tonic-gate 8400Sstevel@tonic-gate if (usba_device == NULL) { 8410Sstevel@tonic-gate 8420Sstevel@tonic-gate usba_device = usba_alloc_usba_device(usb_root_hub_dip); 8430Sstevel@tonic-gate 8440Sstevel@tonic-gate /* grab the mutex to keep warlock happy */ 8450Sstevel@tonic-gate mutex_enter(&usba_device->usb_mutex); 8460Sstevel@tonic-gate usba_device->usb_hcdi_ops = usba_hcdi_ops; 8470Sstevel@tonic-gate usba_device->usb_port_status = port_status; 8480Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex); 8490Sstevel@tonic-gate 8500Sstevel@tonic-gate usba_device_allocated++; 8510Sstevel@tonic-gate } else { 8520Sstevel@tonic-gate mutex_enter(&usba_device->usb_mutex); 8530Sstevel@tonic-gate if (usba_hcdi_ops) { 8540Sstevel@tonic-gate ASSERT(usba_device->usb_hcdi_ops == usba_hcdi_ops); 8550Sstevel@tonic-gate } 8560Sstevel@tonic-gate if (usb_root_hub_dip) { 8570Sstevel@tonic-gate ASSERT(usba_device->usb_root_hub_dip == 8580Sstevel@tonic-gate usb_root_hub_dip); 8590Sstevel@tonic-gate } 8600Sstevel@tonic-gate 8610Sstevel@tonic-gate usba_device->usb_port_status = port_status; 8620Sstevel@tonic-gate 8630Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex); 8640Sstevel@tonic-gate } 8650Sstevel@tonic-gate 8660Sstevel@tonic-gate if (usba_device->usb_addr == 0) { 8670Sstevel@tonic-gate if (usba_set_usb_address(usba_device) == USB_FAILURE) { 8680Sstevel@tonic-gate address = 0; 8690Sstevel@tonic-gate 8700Sstevel@tonic-gate USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 8710Sstevel@tonic-gate "cannot set usb address for dip=0x%p", 8720Sstevel@tonic-gate *child_dip); 8730Sstevel@tonic-gate 8740Sstevel@tonic-gate goto fail; 8750Sstevel@tonic-gate } 8760Sstevel@tonic-gate } 8770Sstevel@tonic-gate address = usba_device->usb_addr; 8780Sstevel@tonic-gate 8790Sstevel@tonic-gate /* attach properties */ 8800Sstevel@tonic-gate rval = ndi_prop_update_int(DDI_DEV_T_NONE, *child_dip, 8810Sstevel@tonic-gate "assigned-address", address); 8820Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 8830Sstevel@tonic-gate USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 8840Sstevel@tonic-gate "cannot set usb address property for dip=0x%p", 8850Sstevel@tonic-gate *child_dip); 8860Sstevel@tonic-gate rval = USB_FAILURE; 8870Sstevel@tonic-gate 8880Sstevel@tonic-gate goto fail; 8890Sstevel@tonic-gate } 8900Sstevel@tonic-gate 8910Sstevel@tonic-gate /* 8920Sstevel@tonic-gate * store the usba_device point in the dip 8930Sstevel@tonic-gate */ 8940Sstevel@tonic-gate usba_set_usba_device(*child_dip, usba_device); 8950Sstevel@tonic-gate 8960Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_USBA, usba_log_handle, 8970Sstevel@tonic-gate "usba_create_child_devi: devi=0x%p (%s) ud=0x%p", 8980Sstevel@tonic-gate *child_dip, ddi_driver_name(*child_dip), usba_device); 8990Sstevel@tonic-gate 9000Sstevel@tonic-gate return (USB_SUCCESS); 9010Sstevel@tonic-gate 9020Sstevel@tonic-gate fail: 9030Sstevel@tonic-gate if (*child_dip) { 9040Sstevel@tonic-gate int rval = usba_destroy_child_devi(*child_dip, NDI_DEVI_REMOVE); 9050Sstevel@tonic-gate ASSERT(rval == USB_SUCCESS); 9060Sstevel@tonic-gate *child_dip = NULL; 9070Sstevel@tonic-gate } 9080Sstevel@tonic-gate 9090Sstevel@tonic-gate if (usba_device_allocated) { 9100Sstevel@tonic-gate usba_free_usba_device(usba_device); 9110Sstevel@tonic-gate } else if (address && usba_device) { 9120Sstevel@tonic-gate usba_unset_usb_address(usba_device); 9130Sstevel@tonic-gate } 9140Sstevel@tonic-gate 915978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 9160Sstevel@tonic-gate "usba_create_child_devi failed: rval=%d", rval); 9170Sstevel@tonic-gate 9180Sstevel@tonic-gate return (rval); 9190Sstevel@tonic-gate } 9200Sstevel@tonic-gate 9210Sstevel@tonic-gate 9220Sstevel@tonic-gate int 9230Sstevel@tonic-gate usba_destroy_child_devi(dev_info_t *dip, uint_t flag) 9240Sstevel@tonic-gate { 9250Sstevel@tonic-gate usba_device_t *usba_device; 9260Sstevel@tonic-gate int rval = NDI_SUCCESS; 9270Sstevel@tonic-gate 9280Sstevel@tonic-gate USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 9290Sstevel@tonic-gate "usba_destroy_child_devi: %s%d (0x%p)", 9300Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), dip); 9310Sstevel@tonic-gate 9320Sstevel@tonic-gate usba_device = usba_get_usba_device(dip); 9330Sstevel@tonic-gate 9340Sstevel@tonic-gate /* 9350Sstevel@tonic-gate * if the child hasn't been bound yet, we can just 9360Sstevel@tonic-gate * free the dip 9370Sstevel@tonic-gate */ 9380Sstevel@tonic-gate if (i_ddi_node_state(dip) < DS_INITIALIZED) { 9390Sstevel@tonic-gate /* 9400Sstevel@tonic-gate * do not call ndi_devi_free() since it might 9410Sstevel@tonic-gate * deadlock 9420Sstevel@tonic-gate */ 9430Sstevel@tonic-gate rval = ddi_remove_child(dip, 0); 9440Sstevel@tonic-gate 9450Sstevel@tonic-gate } else { 9460Sstevel@tonic-gate char *devnm = kmem_alloc(MAXNAMELEN + 1, KM_SLEEP); 9470Sstevel@tonic-gate dev_info_t *pdip = ddi_get_parent(dip); 9480Sstevel@tonic-gate 9490Sstevel@tonic-gate (void) ddi_deviname(dip, devnm); 9500Sstevel@tonic-gate 9510Sstevel@tonic-gate USB_DPRINTF_L3(DPRINT_MASK_USBA, usba_log_handle, 9520Sstevel@tonic-gate "usba_destroy_child_devi:\n\t" 9530Sstevel@tonic-gate "offlining dip 0x%p usba_device=0x%p (%s)", dip, 9540Sstevel@tonic-gate (void *)usba_device, devnm); 9550Sstevel@tonic-gate 9560Sstevel@tonic-gate (void) devfs_clean(pdip, NULL, DV_CLEAN_FORCE); 9570Sstevel@tonic-gate rval = ndi_devi_unconfig_one(pdip, devnm + 1, NULL, 9580Sstevel@tonic-gate flag | NDI_UNCONFIG | NDI_DEVI_OFFLINE); 9590Sstevel@tonic-gate if (rval != NDI_SUCCESS) { 9600Sstevel@tonic-gate USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 9610Sstevel@tonic-gate " ndi_devi_unconfig_one %s%d failed (%d)", 9620Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), 9630Sstevel@tonic-gate rval); 9640Sstevel@tonic-gate } 9650Sstevel@tonic-gate kmem_free(devnm, MAXNAMELEN + 1); 9660Sstevel@tonic-gate } 9670Sstevel@tonic-gate 9680Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_USBA, usba_log_handle, 9690Sstevel@tonic-gate "usba_destroy_child_devi: rval=%d", rval); 9700Sstevel@tonic-gate 9710Sstevel@tonic-gate return (rval == NDI_SUCCESS ? USB_SUCCESS : USB_FAILURE); 9720Sstevel@tonic-gate } 9730Sstevel@tonic-gate 9740Sstevel@tonic-gate 9750Sstevel@tonic-gate /* 9760Sstevel@tonic-gate * list management 9770Sstevel@tonic-gate */ 9780Sstevel@tonic-gate void 9790Sstevel@tonic-gate usba_init_list(usba_list_entry_t *element, usb_opaque_t private, 9800Sstevel@tonic-gate ddi_iblock_cookie_t iblock_cookie) 9810Sstevel@tonic-gate { 9820Sstevel@tonic-gate mutex_init(&element->list_mutex, NULL, MUTEX_DRIVER, 9830Sstevel@tonic-gate iblock_cookie); 9840Sstevel@tonic-gate mutex_enter(&element->list_mutex); 9850Sstevel@tonic-gate element->private = private; 9860Sstevel@tonic-gate mutex_exit(&element->list_mutex); 9870Sstevel@tonic-gate } 9880Sstevel@tonic-gate 9890Sstevel@tonic-gate 9900Sstevel@tonic-gate void 9910Sstevel@tonic-gate usba_destroy_list(usba_list_entry_t *head) 9920Sstevel@tonic-gate { 9930Sstevel@tonic-gate mutex_enter(&head->list_mutex); 9940Sstevel@tonic-gate ASSERT(head->next == NULL); 9950Sstevel@tonic-gate ASSERT(head->prev == NULL); 9960Sstevel@tonic-gate mutex_exit(&head->list_mutex); 9970Sstevel@tonic-gate 9980Sstevel@tonic-gate mutex_destroy(&head->list_mutex); 9990Sstevel@tonic-gate } 10000Sstevel@tonic-gate 10010Sstevel@tonic-gate 10020Sstevel@tonic-gate void 10030Sstevel@tonic-gate usba_add_to_list(usba_list_entry_t *head, usba_list_entry_t *element) 10040Sstevel@tonic-gate { 10050Sstevel@tonic-gate usba_list_entry_t *next; 10060Sstevel@tonic-gate int remaining; 10070Sstevel@tonic-gate 10080Sstevel@tonic-gate mutex_enter(&head->list_mutex); 10090Sstevel@tonic-gate mutex_enter(&element->list_mutex); 10100Sstevel@tonic-gate 10110Sstevel@tonic-gate remaining = head->count; 10120Sstevel@tonic-gate 10130Sstevel@tonic-gate /* check if it is not in another list */ 10140Sstevel@tonic-gate ASSERT(element->next == NULL); 10150Sstevel@tonic-gate ASSERT(element->prev == NULL); 10160Sstevel@tonic-gate 10170Sstevel@tonic-gate #ifdef DEBUG 10180Sstevel@tonic-gate /* 10190Sstevel@tonic-gate * only verify the list when not in interrupt context, we 10200Sstevel@tonic-gate * have to trust the HCD 10210Sstevel@tonic-gate */ 10220Sstevel@tonic-gate if (!servicing_interrupt()) { 10230Sstevel@tonic-gate 10240Sstevel@tonic-gate /* check if not already in this list */ 10250Sstevel@tonic-gate for (next = head->next; (next != NULL); 10260Sstevel@tonic-gate next = next->next) { 10270Sstevel@tonic-gate if (next == element) { 10280Sstevel@tonic-gate USB_DPRINTF_L0(DPRINT_MASK_USBA, 10290Sstevel@tonic-gate usba_log_handle, 10300Sstevel@tonic-gate "Attempt to corrupt USB list at 0x%p", 10310Sstevel@tonic-gate (void *)head); 10320Sstevel@tonic-gate ASSERT(next == element); 10330Sstevel@tonic-gate 10340Sstevel@tonic-gate goto done; 10350Sstevel@tonic-gate } 10360Sstevel@tonic-gate remaining--; 10370Sstevel@tonic-gate 10380Sstevel@tonic-gate /* 10390Sstevel@tonic-gate * Detect incorrect circ links or found 10400Sstevel@tonic-gate * unexpected elements. 10410Sstevel@tonic-gate */ 10420Sstevel@tonic-gate if ((next->next && (remaining == 0)) || 10430Sstevel@tonic-gate ((next->next == NULL) && remaining)) { 10440Sstevel@tonic-gate panic("Corrupted USB list at 0x%p", 10450Sstevel@tonic-gate (void *)head); 10460Sstevel@tonic-gate /*NOTREACHED*/ 10470Sstevel@tonic-gate } 10480Sstevel@tonic-gate } 10490Sstevel@tonic-gate } 10500Sstevel@tonic-gate #endif 10510Sstevel@tonic-gate 10520Sstevel@tonic-gate if (head->next == NULL) { 10530Sstevel@tonic-gate head->prev = head->next = element; 10540Sstevel@tonic-gate } else { 10550Sstevel@tonic-gate /* add to tail */ 10560Sstevel@tonic-gate head->prev->next = element; 10570Sstevel@tonic-gate element->prev = head->prev; 10580Sstevel@tonic-gate head->prev = element; 10590Sstevel@tonic-gate } 10600Sstevel@tonic-gate 10610Sstevel@tonic-gate head->count++; 10620Sstevel@tonic-gate 10630Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_USBA, usba_log_handle, 10640Sstevel@tonic-gate "usba_add_to_list: head=0x%p element=0x%p count=%d", 10650Sstevel@tonic-gate head, element, head->count); 10660Sstevel@tonic-gate 10670Sstevel@tonic-gate done: 10680Sstevel@tonic-gate mutex_exit(&head->list_mutex); 10690Sstevel@tonic-gate mutex_exit(&element->list_mutex); 10700Sstevel@tonic-gate } 10710Sstevel@tonic-gate 10720Sstevel@tonic-gate 10730Sstevel@tonic-gate int 10740Sstevel@tonic-gate usba_rm_from_list(usba_list_entry_t *head, usba_list_entry_t *element) 10750Sstevel@tonic-gate { 10760Sstevel@tonic-gate usba_list_entry_t *e; 10770Sstevel@tonic-gate int found = 0; 10780Sstevel@tonic-gate int remaining; 10790Sstevel@tonic-gate 10800Sstevel@tonic-gate /* find the element in the list first */ 10810Sstevel@tonic-gate mutex_enter(&head->list_mutex); 10820Sstevel@tonic-gate 10830Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_USBA, usba_log_handle, 10840Sstevel@tonic-gate "usba_rm_from_list: head=0x%p element=0x%p count=%d", 10850Sstevel@tonic-gate head, element, head->count); 10860Sstevel@tonic-gate 10870Sstevel@tonic-gate remaining = head->count; 10880Sstevel@tonic-gate e = head->next; 10890Sstevel@tonic-gate 10900Sstevel@tonic-gate while (e) { 10910Sstevel@tonic-gate if (e == element) { 10920Sstevel@tonic-gate found++; 10930Sstevel@tonic-gate break; 10940Sstevel@tonic-gate } 10950Sstevel@tonic-gate e = e->next; 10960Sstevel@tonic-gate 10970Sstevel@tonic-gate remaining--; 10980Sstevel@tonic-gate 10990Sstevel@tonic-gate /* Detect incorrect circ links or found unexpected elements. */ 11000Sstevel@tonic-gate if ((e && (remaining == 0)) || 11010Sstevel@tonic-gate ((e == NULL) && (remaining))) { 11020Sstevel@tonic-gate panic("Corrupted USB list at 0x%p", (void *)head); 11030Sstevel@tonic-gate /*NOTREACHED*/ 11040Sstevel@tonic-gate } 11050Sstevel@tonic-gate } 11060Sstevel@tonic-gate 11070Sstevel@tonic-gate if (!found) { 11080Sstevel@tonic-gate mutex_exit(&head->list_mutex); 11090Sstevel@tonic-gate 11100Sstevel@tonic-gate return (USB_FAILURE); 11110Sstevel@tonic-gate } 11120Sstevel@tonic-gate 11130Sstevel@tonic-gate /* now remove the element */ 11140Sstevel@tonic-gate mutex_enter(&element->list_mutex); 11150Sstevel@tonic-gate 11160Sstevel@tonic-gate if (element->next) { 11170Sstevel@tonic-gate element->next->prev = element->prev; 11180Sstevel@tonic-gate } 11190Sstevel@tonic-gate if (element->prev) { 11200Sstevel@tonic-gate element->prev->next = element->next; 11210Sstevel@tonic-gate } 11220Sstevel@tonic-gate if (head->next == element) { 11230Sstevel@tonic-gate head->next = element->next; 11240Sstevel@tonic-gate } 11250Sstevel@tonic-gate if (head->prev == element) { 11260Sstevel@tonic-gate head->prev = element->prev; 11270Sstevel@tonic-gate } 11280Sstevel@tonic-gate 11290Sstevel@tonic-gate element->prev = element->next = NULL; 11300Sstevel@tonic-gate if (head->next == NULL) { 11310Sstevel@tonic-gate ASSERT(head->prev == NULL); 11320Sstevel@tonic-gate } else { 11330Sstevel@tonic-gate ASSERT(head->next->prev == NULL); 11340Sstevel@tonic-gate } 11350Sstevel@tonic-gate if (head->prev == NULL) { 11360Sstevel@tonic-gate ASSERT(head->next == NULL); 11370Sstevel@tonic-gate } else { 11380Sstevel@tonic-gate ASSERT(head->prev->next == NULL); 11390Sstevel@tonic-gate } 11400Sstevel@tonic-gate 11410Sstevel@tonic-gate head->count--; 11420Sstevel@tonic-gate 11430Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_USBA, usba_log_handle, 11440Sstevel@tonic-gate "usba_rm_from_list success: head=0x%p element=0x%p cnt=%d", 11450Sstevel@tonic-gate head, element, head->count); 11460Sstevel@tonic-gate 11470Sstevel@tonic-gate mutex_exit(&element->list_mutex); 11480Sstevel@tonic-gate mutex_exit(&head->list_mutex); 11490Sstevel@tonic-gate 11500Sstevel@tonic-gate return (USB_SUCCESS); 11510Sstevel@tonic-gate } 11520Sstevel@tonic-gate 11530Sstevel@tonic-gate 11540Sstevel@tonic-gate usba_list_entry_t * 11550Sstevel@tonic-gate usba_rm_first_from_list(usba_list_entry_t *head) 11560Sstevel@tonic-gate { 11570Sstevel@tonic-gate usba_list_entry_t *element = NULL; 11580Sstevel@tonic-gate 11590Sstevel@tonic-gate if (head) { 11600Sstevel@tonic-gate mutex_enter(&head->list_mutex); 11610Sstevel@tonic-gate element = head->next; 11620Sstevel@tonic-gate if (element) { 11630Sstevel@tonic-gate /* now remove the element */ 11640Sstevel@tonic-gate mutex_enter(&element->list_mutex); 11650Sstevel@tonic-gate head->next = element->next; 11660Sstevel@tonic-gate if (head->next) { 11670Sstevel@tonic-gate head->next->prev = NULL; 11680Sstevel@tonic-gate } 11690Sstevel@tonic-gate if (head->prev == element) { 11700Sstevel@tonic-gate head->prev = element->next; 11710Sstevel@tonic-gate } 11720Sstevel@tonic-gate element->prev = element->next = NULL; 11730Sstevel@tonic-gate mutex_exit(&element->list_mutex); 11740Sstevel@tonic-gate head->count--; 11750Sstevel@tonic-gate } 11760Sstevel@tonic-gate if (head->next == NULL) { 11770Sstevel@tonic-gate ASSERT(head->prev == NULL); 11780Sstevel@tonic-gate } else { 11790Sstevel@tonic-gate ASSERT(head->next->prev == NULL); 11800Sstevel@tonic-gate } 11810Sstevel@tonic-gate if (head->prev == NULL) { 11820Sstevel@tonic-gate ASSERT(head->next == NULL); 11830Sstevel@tonic-gate } else { 11840Sstevel@tonic-gate ASSERT(head->prev->next == NULL); 11850Sstevel@tonic-gate } 11860Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_USBA, usba_log_handle, 11870Sstevel@tonic-gate "usba_rm_first_from_list: head=0x%p el=0x%p cnt=%d", 11880Sstevel@tonic-gate head, element, head->count); 11890Sstevel@tonic-gate 11900Sstevel@tonic-gate mutex_exit(&head->list_mutex); 11910Sstevel@tonic-gate } 11920Sstevel@tonic-gate 11930Sstevel@tonic-gate return (element); 11940Sstevel@tonic-gate } 11950Sstevel@tonic-gate 11960Sstevel@tonic-gate 11970Sstevel@tonic-gate usb_opaque_t 11980Sstevel@tonic-gate usba_rm_first_pvt_from_list(usba_list_entry_t *head) 11990Sstevel@tonic-gate { 12000Sstevel@tonic-gate usba_list_entry_t *element = usba_rm_first_from_list(head); 12010Sstevel@tonic-gate usb_opaque_t private = NULL; 12020Sstevel@tonic-gate 12030Sstevel@tonic-gate if (element) { 12040Sstevel@tonic-gate mutex_enter(&element->list_mutex); 12050Sstevel@tonic-gate private = element->private; 12060Sstevel@tonic-gate mutex_exit(&element->list_mutex); 12070Sstevel@tonic-gate } 12080Sstevel@tonic-gate 12090Sstevel@tonic-gate return (private); 12100Sstevel@tonic-gate } 12110Sstevel@tonic-gate 12120Sstevel@tonic-gate 12130Sstevel@tonic-gate /* 12140Sstevel@tonic-gate * move list to new list and zero original list 12150Sstevel@tonic-gate */ 12160Sstevel@tonic-gate void 12170Sstevel@tonic-gate usba_move_list(usba_list_entry_t *head, usba_list_entry_t *new, 12180Sstevel@tonic-gate ddi_iblock_cookie_t iblock_cookie) 12190Sstevel@tonic-gate { 12200Sstevel@tonic-gate usba_init_list(new, NULL, iblock_cookie); 12210Sstevel@tonic-gate mutex_enter(&head->list_mutex); 12220Sstevel@tonic-gate mutex_enter(&new->list_mutex); 12230Sstevel@tonic-gate 12240Sstevel@tonic-gate new->next = head->next; 12250Sstevel@tonic-gate new->prev = head->prev; 12260Sstevel@tonic-gate new->count = head->count; 12270Sstevel@tonic-gate new->private = head->private; 12280Sstevel@tonic-gate 12290Sstevel@tonic-gate head->next = NULL; 12300Sstevel@tonic-gate head->prev = NULL; 12310Sstevel@tonic-gate head->count = 0; 12320Sstevel@tonic-gate head->private = NULL; 12330Sstevel@tonic-gate mutex_exit(&head->list_mutex); 12340Sstevel@tonic-gate mutex_exit(&new->list_mutex); 12350Sstevel@tonic-gate } 12360Sstevel@tonic-gate 12370Sstevel@tonic-gate 12380Sstevel@tonic-gate int 12390Sstevel@tonic-gate usba_check_in_list(usba_list_entry_t *head, usba_list_entry_t *element) 12400Sstevel@tonic-gate { 12410Sstevel@tonic-gate int rval = USB_FAILURE; 12420Sstevel@tonic-gate int remaining; 12430Sstevel@tonic-gate usba_list_entry_t *next; 12440Sstevel@tonic-gate 12450Sstevel@tonic-gate mutex_enter(&head->list_mutex); 12460Sstevel@tonic-gate remaining = head->count; 12470Sstevel@tonic-gate 12480Sstevel@tonic-gate mutex_enter(&element->list_mutex); 12490Sstevel@tonic-gate for (next = head->next; next != NULL; next = next->next) { 12500Sstevel@tonic-gate if (next == element) { 12510Sstevel@tonic-gate rval = USB_SUCCESS; 12520Sstevel@tonic-gate break; 12530Sstevel@tonic-gate } 12540Sstevel@tonic-gate remaining--; 12550Sstevel@tonic-gate 12560Sstevel@tonic-gate /* Detect incorrect circ links or found unexpected elements. */ 12570Sstevel@tonic-gate if ((next->next && (remaining == 0)) || 12580Sstevel@tonic-gate ((next->next == NULL) && remaining)) { 12590Sstevel@tonic-gate panic("Corrupted USB list at 0x%p", (void *)head); 12600Sstevel@tonic-gate /*NOTREACHED*/ 12610Sstevel@tonic-gate } 12620Sstevel@tonic-gate } 12630Sstevel@tonic-gate mutex_exit(&element->list_mutex); 12640Sstevel@tonic-gate mutex_exit(&head->list_mutex); 12650Sstevel@tonic-gate 12660Sstevel@tonic-gate return (rval); 12670Sstevel@tonic-gate } 12680Sstevel@tonic-gate 12690Sstevel@tonic-gate 12700Sstevel@tonic-gate int 12710Sstevel@tonic-gate usba_list_entry_leaks(usba_list_entry_t *head, char *what) 12720Sstevel@tonic-gate { 12730Sstevel@tonic-gate int count = 0; 12740Sstevel@tonic-gate int remaining; 12750Sstevel@tonic-gate usba_list_entry_t *next; 12760Sstevel@tonic-gate 12770Sstevel@tonic-gate mutex_enter(&head->list_mutex); 12780Sstevel@tonic-gate remaining = head->count; 12790Sstevel@tonic-gate for (next = head->next; next != NULL; next = next->next) { 12800Sstevel@tonic-gate USB_DPRINTF_L2(DPRINT_MASK_HCDI, usba_log_handle, 12810Sstevel@tonic-gate "leaking %s 0x%p", what, next->private); 12820Sstevel@tonic-gate count++; 12830Sstevel@tonic-gate 12840Sstevel@tonic-gate remaining--; 12850Sstevel@tonic-gate 12860Sstevel@tonic-gate /* Detect incorrect circ links or found unexpected elements. */ 12870Sstevel@tonic-gate if ((next->next && (remaining == 0)) || 12880Sstevel@tonic-gate ((next->next == NULL) && remaining)) { 12890Sstevel@tonic-gate panic("Corrupted USB list at 0x%p", (void *)head); 12900Sstevel@tonic-gate /*NOTREACHED*/ 12910Sstevel@tonic-gate } 12920Sstevel@tonic-gate } 12930Sstevel@tonic-gate ASSERT(count == head->count); 12940Sstevel@tonic-gate mutex_exit(&head->list_mutex); 12950Sstevel@tonic-gate 12960Sstevel@tonic-gate if (count) { 12970Sstevel@tonic-gate USB_DPRINTF_L2(DPRINT_MASK_HCDI, usba_log_handle, 12980Sstevel@tonic-gate "usba_list_entry_count: leaking %d", count); 12990Sstevel@tonic-gate } 13000Sstevel@tonic-gate 13010Sstevel@tonic-gate return (count); 13020Sstevel@tonic-gate } 13030Sstevel@tonic-gate 13040Sstevel@tonic-gate 13050Sstevel@tonic-gate int 13060Sstevel@tonic-gate usba_list_entry_count(usba_list_entry_t *head) 13070Sstevel@tonic-gate { 13080Sstevel@tonic-gate int count; 13090Sstevel@tonic-gate 13100Sstevel@tonic-gate mutex_enter(&head->list_mutex); 13110Sstevel@tonic-gate count = head->count; 13120Sstevel@tonic-gate mutex_exit(&head->list_mutex); 13130Sstevel@tonic-gate 13140Sstevel@tonic-gate return (count); 13150Sstevel@tonic-gate } 13160Sstevel@tonic-gate 13170Sstevel@tonic-gate 13180Sstevel@tonic-gate /* 13190Sstevel@tonic-gate * check whether this dip is the root hub. instead of doing a 13200Sstevel@tonic-gate * strcmp on the node name we could also check the address 13210Sstevel@tonic-gate */ 13220Sstevel@tonic-gate int 13230Sstevel@tonic-gate usba_is_root_hub(dev_info_t *dip) 13240Sstevel@tonic-gate { 13250Sstevel@tonic-gate if (dip) { 13260Sstevel@tonic-gate return (ddi_prop_exists(DDI_DEV_T_ANY, dip, 13270Sstevel@tonic-gate DDI_PROP_DONTPASS|DDI_PROP_NOTPROM, "root-hub")); 13280Sstevel@tonic-gate } 13290Sstevel@tonic-gate return (0); 13300Sstevel@tonic-gate } 13310Sstevel@tonic-gate 13320Sstevel@tonic-gate 13330Sstevel@tonic-gate /* 13340Sstevel@tonic-gate * get and store usba_device pointer in the devi 13350Sstevel@tonic-gate */ 13360Sstevel@tonic-gate usba_device_t * 13370Sstevel@tonic-gate usba_get_usba_device(dev_info_t *dip) 13380Sstevel@tonic-gate { 13390Sstevel@tonic-gate /* 13400Sstevel@tonic-gate * we cannot use parent_data in the usb node because its 13410Sstevel@tonic-gate * bus parent (eg. PCI nexus driver) uses this data 13420Sstevel@tonic-gate * 13430Sstevel@tonic-gate * we cannot use driver data in the other usb nodes since 13440Sstevel@tonic-gate * usb drivers may need to use this 13450Sstevel@tonic-gate */ 13460Sstevel@tonic-gate if (usba_is_root_hub(dip)) { 13470Sstevel@tonic-gate usba_hcdi_t *hcdi = usba_hcdi_get_hcdi(dip); 13480Sstevel@tonic-gate 13490Sstevel@tonic-gate return (hcdi->hcdi_usba_device); 13500Sstevel@tonic-gate } else { 13510Sstevel@tonic-gate 13520Sstevel@tonic-gate return (ddi_get_parent_data(dip)); 13530Sstevel@tonic-gate } 13540Sstevel@tonic-gate } 13550Sstevel@tonic-gate 13560Sstevel@tonic-gate 13570Sstevel@tonic-gate /* 13580Sstevel@tonic-gate * Retrieve the usba_device pointer from the dev without checking for 13590Sstevel@tonic-gate * the root hub first. This function is only used in polled mode. 13600Sstevel@tonic-gate */ 13610Sstevel@tonic-gate usba_device_t * 13620Sstevel@tonic-gate usba_polled_get_usba_device(dev_info_t *dip) 13630Sstevel@tonic-gate { 13640Sstevel@tonic-gate /* 13650Sstevel@tonic-gate * Don't call usba_is_root_hub() to find out if this is 13660Sstevel@tonic-gate * the root hub usba_is_root_hub() calls into the DDI 13670Sstevel@tonic-gate * where there are locking issues. The dip sent in during 13680Sstevel@tonic-gate * polled mode will never be the root hub, so just get 13690Sstevel@tonic-gate * the usba_device pointer from the dip. 13700Sstevel@tonic-gate */ 13710Sstevel@tonic-gate return (ddi_get_parent_data(dip)); 13720Sstevel@tonic-gate } 13730Sstevel@tonic-gate 13740Sstevel@tonic-gate 13750Sstevel@tonic-gate void 13760Sstevel@tonic-gate usba_set_usba_device(dev_info_t *dip, usba_device_t *usba_device) 13770Sstevel@tonic-gate { 13780Sstevel@tonic-gate if (usba_is_root_hub(dip)) { 13790Sstevel@tonic-gate usba_hcdi_t *hcdi = usba_hcdi_get_hcdi(dip); 13800Sstevel@tonic-gate /* no locking is needed here */ 13810Sstevel@tonic-gate _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(hcdi->hcdi_usba_device)) 13820Sstevel@tonic-gate hcdi->hcdi_usba_device = usba_device; 13830Sstevel@tonic-gate _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(hcdi->hcdi_usba_device)) 13840Sstevel@tonic-gate } else { 13850Sstevel@tonic-gate ddi_set_parent_data(dip, usba_device); 13860Sstevel@tonic-gate } 13870Sstevel@tonic-gate } 13880Sstevel@tonic-gate 13890Sstevel@tonic-gate 13900Sstevel@tonic-gate /* 13910Sstevel@tonic-gate * usba_set_node_name() according to class, subclass, and protocol 13920Sstevel@tonic-gate * following the 1275 USB binding tables. 13930Sstevel@tonic-gate */ 13940Sstevel@tonic-gate 13950Sstevel@tonic-gate /* device node table, refer to section 3.2.2.1 of 1275 binding */ 13960Sstevel@tonic-gate static node_name_entry_t device_node_name_table[] = { 13970Sstevel@tonic-gate { USB_CLASS_COMM, DONTCARE, DONTCARE, "communications" }, 13980Sstevel@tonic-gate { USB_CLASS_HUB, DONTCARE, DONTCARE, "hub" }, 13993341Sgc161489 { USB_CLASS_DIAG, DONTCARE, DONTCARE, "diagnostics" }, 14003341Sgc161489 { USB_CLASS_MISC, DONTCARE, DONTCARE, "miscellaneous" }, 14010Sstevel@tonic-gate { DONTCARE, DONTCARE, DONTCARE, "device" } 14020Sstevel@tonic-gate }; 14030Sstevel@tonic-gate 14043341Sgc161489 /* interface-association node table */ 14053341Sgc161489 static node_name_entry_t ia_node_name_table[] = { 14063341Sgc161489 { USB_CLASS_AUDIO, DONTCARE, DONTCARE, "audio" }, 14073341Sgc161489 { USB_CLASS_VIDEO, DONTCARE, DONTCARE, "video" }, 14083341Sgc161489 { USB_CLASS_WIRELESS, USB_SUBCLS_WUSB_2, USB_PROTO_WUSB_DWA, 14093341Sgc161489 "device-wire-adaptor" }, 14103341Sgc161489 { USB_CLASS_WIRELESS, DONTCARE, DONTCARE, "wireless-controller" }, 14113341Sgc161489 { DONTCARE, DONTCARE, DONTCARE, "interface-association" } 14123341Sgc161489 }; 14133341Sgc161489 14140Sstevel@tonic-gate /* interface node table, refer to section 3.3.2.1 */ 14150Sstevel@tonic-gate static node_name_entry_t if_node_name_table[] = { 14160Sstevel@tonic-gate { USB_CLASS_AUDIO, USB_SUBCLS_AUD_CONTROL, DONTCARE, "sound-control" }, 14170Sstevel@tonic-gate { USB_CLASS_AUDIO, USB_SUBCLS_AUD_STREAMING, DONTCARE, "sound" }, 14180Sstevel@tonic-gate { USB_CLASS_AUDIO, USB_SUBCLS_AUD_MIDI_STREAMING, DONTCARE, "midi" }, 14190Sstevel@tonic-gate { USB_CLASS_AUDIO, DONTCARE, DONTCARE, "sound" }, 14200Sstevel@tonic-gate 14210Sstevel@tonic-gate { USB_CLASS_COMM, USB_SUBCLS_CDCC_DIRECT_LINE, DONTCARE, "line" }, 14220Sstevel@tonic-gate { USB_CLASS_COMM, USB_SUBCLS_CDCC_ABSTRCT_CTRL, DONTCARE, "modem" }, 14230Sstevel@tonic-gate { USB_CLASS_COMM, USB_SUBCLS_CDCC_PHONE_CTRL, DONTCARE, "telephone" }, 14240Sstevel@tonic-gate { USB_CLASS_COMM, USB_SUBCLS_CDCC_MULTCNL_ISDN, DONTCARE, "isdn" }, 14250Sstevel@tonic-gate { USB_CLASS_COMM, USB_SUBCLS_CDCC_ISDN, DONTCARE, "isdn" }, 14260Sstevel@tonic-gate { USB_CLASS_COMM, USB_SUBCLS_CDCC_ETHERNET, DONTCARE, "ethernet" }, 14270Sstevel@tonic-gate { USB_CLASS_COMM, USB_SUBCLS_CDCC_ATM_NETWORK, DONTCARE, "atm-network" }, 14283341Sgc161489 { USB_CLASS_COMM, DONTCARE, DONTCARE, "communications" }, 14290Sstevel@tonic-gate 14300Sstevel@tonic-gate { USB_CLASS_HID, USB_SUBCLS_HID_1, USB_PROTO_HID_KEYBOARD, "keyboard" }, 14310Sstevel@tonic-gate { USB_CLASS_HID, USB_SUBCLS_HID_1, USB_PROTO_HID_MOUSE, "mouse" }, 14320Sstevel@tonic-gate { USB_CLASS_HID, DONTCARE, DONTCARE, "input" }, 14330Sstevel@tonic-gate 14340Sstevel@tonic-gate { USB_CLASS_HUB, DONTCARE, DONTCARE, "hub" }, 14350Sstevel@tonic-gate 14360Sstevel@tonic-gate { USB_CLASS_PHYSICAL, DONTCARE, DONTCARE, "physical" }, 14370Sstevel@tonic-gate 14383341Sgc161489 { USB_CLASS_IMAGE, DONTCARE, DONTCARE, "image" }, 14393341Sgc161489 14400Sstevel@tonic-gate { USB_CLASS_PRINTER, DONTCARE, DONTCARE, "printer" }, 14410Sstevel@tonic-gate 14420Sstevel@tonic-gate { USB_CLASS_MASS_STORAGE, DONTCARE, DONTCARE, "storage" }, 14430Sstevel@tonic-gate 14440Sstevel@tonic-gate { USB_CLASS_CDC_DATA, DONTCARE, DONTCARE, "data" }, 14450Sstevel@tonic-gate 14460Sstevel@tonic-gate { USB_CLASS_SECURITY, DONTCARE, DONTCARE, "security" }, 14470Sstevel@tonic-gate 14483341Sgc161489 { USB_CLASS_VIDEO, USB_SUBCLS_VIDEO_CONTROL, DONTCARE, "video-control" }, 14493341Sgc161489 { USB_CLASS_VIDEO, USB_SUBCLS_VIDEO_STREAM, DONTCARE, "video-stream" }, 14503341Sgc161489 { USB_CLASS_VIDEO, DONTCARE, DONTCARE, "video" }, 14513341Sgc161489 14520Sstevel@tonic-gate { USB_CLASS_APP, USB_SUBCLS_APP_FIRMWARE, DONTCARE, "firmware" }, 14530Sstevel@tonic-gate { USB_CLASS_APP, USB_SUBCLS_APP_IRDA, DONTCARE, "IrDa" }, 14540Sstevel@tonic-gate { USB_CLASS_APP, USB_SUBCLS_APP_TEST, DONTCARE, "test" }, 14550Sstevel@tonic-gate 14560Sstevel@tonic-gate { DONTCARE, DONTCARE, DONTCARE, "interface" }, 14570Sstevel@tonic-gate 14580Sstevel@tonic-gate }; 14590Sstevel@tonic-gate 14600Sstevel@tonic-gate /* combined node table, refer to section 3.4.2.1 */ 14610Sstevel@tonic-gate static node_name_entry_t combined_node_name_table[] = { 14620Sstevel@tonic-gate { USB_CLASS_AUDIO, USB_SUBCLS_AUD_CONTROL, DONTCARE, "sound-control" }, 14630Sstevel@tonic-gate { USB_CLASS_AUDIO, USB_SUBCLS_AUD_STREAMING, DONTCARE, "sound" }, 14640Sstevel@tonic-gate { USB_CLASS_AUDIO, USB_SUBCLS_AUD_MIDI_STREAMING, DONTCARE, "midi" }, 14650Sstevel@tonic-gate { USB_CLASS_AUDIO, DONTCARE, DONTCARE, "sound" }, 14660Sstevel@tonic-gate 14670Sstevel@tonic-gate { USB_CLASS_COMM, USB_SUBCLS_CDCC_DIRECT_LINE, DONTCARE, "line" }, 14680Sstevel@tonic-gate { USB_CLASS_COMM, USB_SUBCLS_CDCC_ABSTRCT_CTRL, DONTCARE, "modem" }, 14690Sstevel@tonic-gate { USB_CLASS_COMM, USB_SUBCLS_CDCC_PHONE_CTRL, DONTCARE, "telephone" }, 14700Sstevel@tonic-gate { USB_CLASS_COMM, USB_SUBCLS_CDCC_MULTCNL_ISDN, DONTCARE, "isdn" }, 14710Sstevel@tonic-gate { USB_CLASS_COMM, USB_SUBCLS_CDCC_ISDN, DONTCARE, "isdn" }, 14720Sstevel@tonic-gate { USB_CLASS_COMM, USB_SUBCLS_CDCC_ETHERNET, DONTCARE, "ethernet" }, 14730Sstevel@tonic-gate { USB_CLASS_COMM, USB_SUBCLS_CDCC_ATM_NETWORK, DONTCARE, "atm-network" }, 14743341Sgc161489 { USB_CLASS_COMM, DONTCARE, DONTCARE, "communications" }, 14750Sstevel@tonic-gate 14760Sstevel@tonic-gate { USB_CLASS_HID, USB_SUBCLS_HID_1, USB_PROTO_HID_KEYBOARD, "keyboard" }, 14770Sstevel@tonic-gate { USB_CLASS_HID, USB_SUBCLS_HID_1, USB_PROTO_HID_MOUSE, "mouse" }, 14780Sstevel@tonic-gate { USB_CLASS_HID, DONTCARE, DONTCARE, "input" }, 14790Sstevel@tonic-gate 14800Sstevel@tonic-gate { USB_CLASS_PHYSICAL, DONTCARE, DONTCARE, "physical" }, 14810Sstevel@tonic-gate 14823341Sgc161489 { USB_CLASS_IMAGE, DONTCARE, DONTCARE, "image" }, 14833341Sgc161489 14840Sstevel@tonic-gate { USB_CLASS_PRINTER, DONTCARE, DONTCARE, "printer" }, 14850Sstevel@tonic-gate 14863341Sgc161489 { USB_CLASS_MASS_STORAGE, USB_SUBCLS_MS_RBC_T10, DONTCARE, "storage" }, 14873341Sgc161489 { USB_CLASS_MASS_STORAGE, USB_SUBCLS_MS_SFF8020I, DONTCARE, "cdrom" }, 14883341Sgc161489 { USB_CLASS_MASS_STORAGE, USB_SUBCLS_MS_QIC_157, DONTCARE, "tape" }, 14893341Sgc161489 { USB_CLASS_MASS_STORAGE, USB_SUBCLS_MS_UFI, DONTCARE, "floppy" }, 14903341Sgc161489 { USB_CLASS_MASS_STORAGE, USB_SUBCLS_MS_SFF8070I, DONTCARE, "storage" }, 14913341Sgc161489 { USB_CLASS_MASS_STORAGE, USB_SUBCLS_MS_SCSI, DONTCARE, "storage" }, 14920Sstevel@tonic-gate { USB_CLASS_MASS_STORAGE, DONTCARE, DONTCARE, "storage" }, 14930Sstevel@tonic-gate 14940Sstevel@tonic-gate { USB_CLASS_CDC_DATA, DONTCARE, DONTCARE, "data" }, 14950Sstevel@tonic-gate 14960Sstevel@tonic-gate { USB_CLASS_SECURITY, DONTCARE, DONTCARE, "security" }, 14970Sstevel@tonic-gate 14983341Sgc161489 { USB_CLASS_VIDEO, USB_SUBCLS_VIDEO_CONTROL, DONTCARE, "video-control" }, 14993341Sgc161489 { USB_CLASS_VIDEO, USB_SUBCLS_VIDEO_STREAM, DONTCARE, "video-stream" }, 15003341Sgc161489 { USB_CLASS_VIDEO, DONTCARE, DONTCARE, "video" }, 15013341Sgc161489 15020Sstevel@tonic-gate { USB_CLASS_APP, USB_SUBCLS_APP_FIRMWARE, DONTCARE, "firmware" }, 15030Sstevel@tonic-gate { USB_CLASS_APP, USB_SUBCLS_APP_IRDA, DONTCARE, "IrDa" }, 15040Sstevel@tonic-gate { USB_CLASS_APP, USB_SUBCLS_APP_TEST, DONTCARE, "test" }, 15050Sstevel@tonic-gate 15063341Sgc161489 { USB_CLASS_COMM, DONTCARE, DONTCARE, "communications" }, 15070Sstevel@tonic-gate { USB_CLASS_HUB, DONTCARE, DONTCARE, "hub" }, 15083341Sgc161489 { USB_CLASS_DIAG, DONTCARE, DONTCARE, "diagnostics" }, 15093341Sgc161489 { USB_CLASS_MISC, DONTCARE, DONTCARE, "miscellaneous" }, 15103341Sgc161489 { DONTCARE, DONTCARE, DONTCARE, "device" } 15110Sstevel@tonic-gate }; 15120Sstevel@tonic-gate 15130Sstevel@tonic-gate static size_t device_node_name_table_size = 15140Sstevel@tonic-gate sizeof (device_node_name_table)/sizeof (struct node_name_entry); 15153341Sgc161489 static size_t ia_node_name_table_size = 15163341Sgc161489 sizeof (ia_node_name_table)/sizeof (struct node_name_entry); 15170Sstevel@tonic-gate static size_t if_node_name_table_size = 15180Sstevel@tonic-gate sizeof (if_node_name_table)/sizeof (struct node_name_entry); 15190Sstevel@tonic-gate static size_t combined_node_name_table_size = 15200Sstevel@tonic-gate sizeof (combined_node_name_table)/sizeof (struct node_name_entry); 15210Sstevel@tonic-gate 15220Sstevel@tonic-gate 15230Sstevel@tonic-gate static void 15240Sstevel@tonic-gate usba_set_node_name(dev_info_t *dip, uint8_t class, uint8_t subclass, 15250Sstevel@tonic-gate uint8_t protocol, uint_t flag) 15260Sstevel@tonic-gate { 15270Sstevel@tonic-gate int i; 15280Sstevel@tonic-gate size_t size; 15290Sstevel@tonic-gate node_name_entry_t *node_name_table; 15300Sstevel@tonic-gate 15310Sstevel@tonic-gate switch (flag) { 15323341Sgc161489 /* interface share node names with interface-association */ 15333341Sgc161489 case FLAG_INTERFACE_ASSOCIATION_NODE: 15343341Sgc161489 node_name_table = ia_node_name_table; 15353341Sgc161489 size = ia_node_name_table_size; 15363341Sgc161489 break; 15370Sstevel@tonic-gate case FLAG_INTERFACE_NODE: 15380Sstevel@tonic-gate node_name_table = if_node_name_table; 15390Sstevel@tonic-gate size = if_node_name_table_size; 15400Sstevel@tonic-gate break; 15410Sstevel@tonic-gate case FLAG_DEVICE_NODE: 15420Sstevel@tonic-gate node_name_table = device_node_name_table; 15430Sstevel@tonic-gate size = device_node_name_table_size; 15440Sstevel@tonic-gate break; 15450Sstevel@tonic-gate case FLAG_COMBINED_NODE: 15460Sstevel@tonic-gate node_name_table = combined_node_name_table; 15470Sstevel@tonic-gate size = combined_node_name_table_size; 15480Sstevel@tonic-gate break; 15490Sstevel@tonic-gate default: 15500Sstevel@tonic-gate 15510Sstevel@tonic-gate return; 15520Sstevel@tonic-gate } 15530Sstevel@tonic-gate 15540Sstevel@tonic-gate for (i = 0; i < size; i++) { 15550Sstevel@tonic-gate int16_t c = node_name_table[i].class; 15560Sstevel@tonic-gate int16_t s = node_name_table[i].subclass; 15570Sstevel@tonic-gate int16_t p = node_name_table[i].protocol; 15580Sstevel@tonic-gate 15590Sstevel@tonic-gate if (((c == DONTCARE) || (c == class)) && 15600Sstevel@tonic-gate ((s == DONTCARE) || (s == subclass)) && 15610Sstevel@tonic-gate ((p == DONTCARE) || (p == protocol))) { 15620Sstevel@tonic-gate char *name = node_name_table[i].name; 15633341Sgc161489 15640Sstevel@tonic-gate (void) ndi_devi_set_nodename(dip, name, 0); 15650Sstevel@tonic-gate break; 15660Sstevel@tonic-gate } 15670Sstevel@tonic-gate } 15680Sstevel@tonic-gate } 15690Sstevel@tonic-gate 15700Sstevel@tonic-gate 15710Sstevel@tonic-gate #ifdef DEBUG 15720Sstevel@tonic-gate /* 15730Sstevel@tonic-gate * walk the children of the parent of this devi and compare the 15740Sstevel@tonic-gate * name and reg property of each child. If there is a match 15750Sstevel@tonic-gate * return this node 15760Sstevel@tonic-gate */ 15770Sstevel@tonic-gate static dev_info_t * 15780Sstevel@tonic-gate usba_find_existing_node(dev_info_t *odip) 15790Sstevel@tonic-gate { 15800Sstevel@tonic-gate dev_info_t *ndip, *child, *pdip; 15810Sstevel@tonic-gate int *odata, *ndata; 15820Sstevel@tonic-gate uint_t n_odata, n_ndata; 15830Sstevel@tonic-gate int circular; 15840Sstevel@tonic-gate 15850Sstevel@tonic-gate pdip = ddi_get_parent(odip); 15860Sstevel@tonic-gate if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, 15870Sstevel@tonic-gate odip, DDI_PROP_DONTPASS, "reg", 15880Sstevel@tonic-gate &odata, &n_odata) != DDI_SUCCESS) { 1589978Sfrits USB_DPRINTF_L2(DPRINT_MASK_HCDI, usba_log_handle, 15900Sstevel@tonic-gate "usba_find_existing_node: " 15910Sstevel@tonic-gate "%s: DDI_NOT_WELL_FORMED", ddi_driver_name(odip)); 15920Sstevel@tonic-gate 15930Sstevel@tonic-gate return (NULL); 15940Sstevel@tonic-gate } 15950Sstevel@tonic-gate 15960Sstevel@tonic-gate ndi_devi_enter(pdip, &circular); 15970Sstevel@tonic-gate ndip = (dev_info_t *)(DEVI(pdip)->devi_child); 15980Sstevel@tonic-gate while ((child = ndip) != NULL) { 15990Sstevel@tonic-gate 16000Sstevel@tonic-gate ndip = (dev_info_t *)(DEVI(child)->devi_sibling); 16010Sstevel@tonic-gate 16020Sstevel@tonic-gate if (child == odip) { 16030Sstevel@tonic-gate continue; 16040Sstevel@tonic-gate } 16050Sstevel@tonic-gate 16060Sstevel@tonic-gate if (strcmp(DEVI(child)->devi_node_name, 16070Sstevel@tonic-gate DEVI(odip)->devi_node_name)) { 16080Sstevel@tonic-gate continue; 16090Sstevel@tonic-gate } 16100Sstevel@tonic-gate 16110Sstevel@tonic-gate if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, 16120Sstevel@tonic-gate child, DDI_PROP_DONTPASS, "reg", 16130Sstevel@tonic-gate &ndata, &n_ndata) != DDI_SUCCESS) { 16140Sstevel@tonic-gate 1615978Sfrits USB_DPRINTF_L2(DPRINT_MASK_HCDI, usba_log_handle, 16160Sstevel@tonic-gate "usba_find_existing_node: " 16170Sstevel@tonic-gate "%s DDI_NOT_WELL_FORMED", ddi_driver_name(child)); 16180Sstevel@tonic-gate 16190Sstevel@tonic-gate } else if (n_ndata && n_odata && (bcmp(odata, ndata, 16200Sstevel@tonic-gate max(n_odata, n_ndata) * sizeof (int)) == 0)) { 16210Sstevel@tonic-gate 16220Sstevel@tonic-gate USB_DPRINTF_L3(DPRINT_MASK_HCDI, usba_log_handle, 16230Sstevel@tonic-gate "usba_find_existing_node: found %s%d (%p)", 16240Sstevel@tonic-gate ddi_driver_name(child), 16250Sstevel@tonic-gate ddi_get_instance(child), (void *)child); 16260Sstevel@tonic-gate 16270Sstevel@tonic-gate USB_DPRINTF_L3(DPRINT_MASK_HCDI, usba_log_handle, 16280Sstevel@tonic-gate "usba_find_existing_node: " 16290Sstevel@tonic-gate "reg: %x %x %x - %x %x %x", 16300Sstevel@tonic-gate n_odata, odata[0], odata[1], 16310Sstevel@tonic-gate n_ndata, ndata[0], ndata[1]); 16320Sstevel@tonic-gate 16330Sstevel@tonic-gate ddi_prop_free(ndata); 16340Sstevel@tonic-gate break; 16350Sstevel@tonic-gate 16360Sstevel@tonic-gate } else { 16370Sstevel@tonic-gate ddi_prop_free(ndata); 16380Sstevel@tonic-gate } 16390Sstevel@tonic-gate } 16400Sstevel@tonic-gate 16410Sstevel@tonic-gate ndi_devi_exit(pdip, circular); 16420Sstevel@tonic-gate 16430Sstevel@tonic-gate ddi_prop_free(odata); 16440Sstevel@tonic-gate 16450Sstevel@tonic-gate return (child); 16460Sstevel@tonic-gate } 16470Sstevel@tonic-gate #endif 16480Sstevel@tonic-gate 16490Sstevel@tonic-gate /* change all unprintable characters to spaces */ 16500Sstevel@tonic-gate static void 16510Sstevel@tonic-gate usba_filter_string(char *instr, char *outstr) 16520Sstevel@tonic-gate { 16530Sstevel@tonic-gate while (*instr) { 16540Sstevel@tonic-gate if ((*instr >= ' ') && (*instr <= '~')) { 16550Sstevel@tonic-gate *outstr = *instr; 16560Sstevel@tonic-gate } else { 16570Sstevel@tonic-gate *outstr = ' '; 16580Sstevel@tonic-gate } 16590Sstevel@tonic-gate outstr++; 16600Sstevel@tonic-gate instr++; 16610Sstevel@tonic-gate } 16620Sstevel@tonic-gate *outstr = '\0'; 16630Sstevel@tonic-gate } 16640Sstevel@tonic-gate 16650Sstevel@tonic-gate 16660Sstevel@tonic-gate /* 16670Sstevel@tonic-gate * lookup ugen binding specified in property in 16680Sstevel@tonic-gate * hcd.conf files 16690Sstevel@tonic-gate */ 16700Sstevel@tonic-gate int 16710Sstevel@tonic-gate usba_get_ugen_binding(dev_info_t *dip) 16720Sstevel@tonic-gate { 16730Sstevel@tonic-gate usba_device_t *usba_device = usba_get_usba_device(dip); 16740Sstevel@tonic-gate usba_hcdi_t *hcdi = 16750Sstevel@tonic-gate usba_hcdi_get_hcdi(usba_device->usb_root_hub_dip); 16760Sstevel@tonic-gate 16770Sstevel@tonic-gate return (hcdi->hcdi_ugen_default_binding); 16780Sstevel@tonic-gate } 16790Sstevel@tonic-gate 16800Sstevel@tonic-gate 16810Sstevel@tonic-gate /* 16820Sstevel@tonic-gate * driver binding support at device level 16830Sstevel@tonic-gate */ 16840Sstevel@tonic-gate dev_info_t * 16850Sstevel@tonic-gate usba_ready_device_node(dev_info_t *child_dip) 16860Sstevel@tonic-gate { 16870Sstevel@tonic-gate int rval, i; 16880Sstevel@tonic-gate int n = 0; 16890Sstevel@tonic-gate usba_device_t *usba_device = usba_get_usba_device(child_dip); 16900Sstevel@tonic-gate usb_dev_descr_t *usb_dev_descr; 16910Sstevel@tonic-gate uint_t n_cfgs; /* number of configs */ 16920Sstevel@tonic-gate uint_t n_ifs; /* number of interfaces */ 16930Sstevel@tonic-gate uint_t port; 16940Sstevel@tonic-gate size_t usb_config_length; 16950Sstevel@tonic-gate uchar_t *usb_config; 16960Sstevel@tonic-gate int reg[1]; 16970Sstevel@tonic-gate usb_addr_t address = usb_get_addr(child_dip); 16980Sstevel@tonic-gate usb_if_descr_t if_descr; 16990Sstevel@tonic-gate size_t size; 17000Sstevel@tonic-gate int combined_node = 0; 17010Sstevel@tonic-gate int is_hub; 17020Sstevel@tonic-gate char *devprop_str; 17030Sstevel@tonic-gate char *force_bind = NULL; 1704*3630Slg150142 char *usba_name_buf = NULL; 1705*3630Slg150142 char *usba_name[USBA_MAX_COMPAT_NAMES]; 17060Sstevel@tonic-gate 17070Sstevel@tonic-gate usb_config = usb_get_raw_cfg_data(child_dip, &usb_config_length); 17080Sstevel@tonic-gate 17090Sstevel@tonic-gate mutex_enter(&usba_device->usb_mutex); 17100Sstevel@tonic-gate mutex_enter(&usba_mutex); 17110Sstevel@tonic-gate 17120Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_USBA, usba_log_handle, 17130Sstevel@tonic-gate "usba_ready_device_node: child=0x%p", (void *)child_dip); 17140Sstevel@tonic-gate 17150Sstevel@tonic-gate port = usba_device->usb_port; 17160Sstevel@tonic-gate usb_dev_descr = usba_device->usb_dev_descr; 17170Sstevel@tonic-gate n_cfgs = usba_device->usb_n_cfgs; 17180Sstevel@tonic-gate n_ifs = usba_device->usb_n_ifs; 17190Sstevel@tonic-gate 17200Sstevel@tonic-gate 17210Sstevel@tonic-gate if (address != ROOT_HUB_ADDR) { 17220Sstevel@tonic-gate size = usb_parse_if_descr( 17230Sstevel@tonic-gate usb_config, 17240Sstevel@tonic-gate usb_config_length, 17250Sstevel@tonic-gate 0, /* interface index */ 17260Sstevel@tonic-gate 0, /* alt interface index */ 17270Sstevel@tonic-gate &if_descr, 17280Sstevel@tonic-gate USB_IF_DESCR_SIZE); 17290Sstevel@tonic-gate 17300Sstevel@tonic-gate if (size != USB_IF_DESCR_SIZE) { 1731978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 17320Sstevel@tonic-gate "parsing interface: " 17330Sstevel@tonic-gate "size (%lu) != USB_IF_DESCR_SIZE (%d)", 17340Sstevel@tonic-gate size, USB_IF_DESCR_SIZE); 17350Sstevel@tonic-gate 17360Sstevel@tonic-gate mutex_exit(&usba_mutex); 17370Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex); 17380Sstevel@tonic-gate 17390Sstevel@tonic-gate return (child_dip); 17400Sstevel@tonic-gate } 17410Sstevel@tonic-gate } else { 17420Sstevel@tonic-gate /* fake an interface descriptor for the root hub */ 17430Sstevel@tonic-gate bzero(&if_descr, sizeof (if_descr)); 17440Sstevel@tonic-gate 17450Sstevel@tonic-gate if_descr.bInterfaceClass = USB_CLASS_HUB; 17460Sstevel@tonic-gate } 17470Sstevel@tonic-gate 17480Sstevel@tonic-gate reg[0] = port; 17490Sstevel@tonic-gate 17500Sstevel@tonic-gate mutex_exit(&usba_mutex); 17510Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex); 17520Sstevel@tonic-gate 17530Sstevel@tonic-gate rval = ndi_prop_update_int_array( 17540Sstevel@tonic-gate DDI_DEV_T_NONE, child_dip, "reg", reg, 1); 17550Sstevel@tonic-gate 17560Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 1757978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 17580Sstevel@tonic-gate "usba_ready_device_node: property update failed"); 17590Sstevel@tonic-gate 17600Sstevel@tonic-gate return (child_dip); 17610Sstevel@tonic-gate } 17620Sstevel@tonic-gate 17630Sstevel@tonic-gate combined_node = ((n_cfgs == 1) && (n_ifs == 1) && 17640Sstevel@tonic-gate ((usb_dev_descr->bDeviceClass == USB_CLASS_HUB) || 17650Sstevel@tonic-gate (usb_dev_descr->bDeviceClass == 0))); 17660Sstevel@tonic-gate 17670Sstevel@tonic-gate is_hub = (if_descr.bInterfaceClass == USB_CLASS_HUB) || 17680Sstevel@tonic-gate (usb_dev_descr->bDeviceClass == USB_CLASS_HUB); 17690Sstevel@tonic-gate 17700Sstevel@tonic-gate /* set node name */ 17710Sstevel@tonic-gate if (combined_node) { 17720Sstevel@tonic-gate usba_set_node_name(child_dip, 17730Sstevel@tonic-gate if_descr.bInterfaceClass, 17740Sstevel@tonic-gate if_descr.bInterfaceSubClass, 17750Sstevel@tonic-gate if_descr.bInterfaceProtocol, 17760Sstevel@tonic-gate FLAG_COMBINED_NODE); 17770Sstevel@tonic-gate } else { 17780Sstevel@tonic-gate usba_set_node_name(child_dip, 17790Sstevel@tonic-gate usb_dev_descr->bDeviceClass, 17800Sstevel@tonic-gate usb_dev_descr->bDeviceSubClass, 17810Sstevel@tonic-gate usb_dev_descr->bDeviceProtocol, 17820Sstevel@tonic-gate FLAG_DEVICE_NODE); 17830Sstevel@tonic-gate } 17840Sstevel@tonic-gate 17850Sstevel@tonic-gate /* 17860Sstevel@tonic-gate * check force binding rules 17870Sstevel@tonic-gate */ 17880Sstevel@tonic-gate if ((address != ROOT_HUB_ADDR) && usba_ddivs_usbc && 17890Sstevel@tonic-gate (address != usba_ddivs_usbc_xaddress) && 17900Sstevel@tonic-gate (!(usba_ddivs_usbc_xhubs && is_hub))) { 17910Sstevel@tonic-gate force_bind = "ddivs_usbc"; 17920Sstevel@tonic-gate (void) ndi_devi_set_nodename(child_dip, "ddivs_usbc", 0); 17930Sstevel@tonic-gate 17940Sstevel@tonic-gate } else if (usba_device->usb_preferred_driver) { 17950Sstevel@tonic-gate force_bind = usba_device->usb_preferred_driver; 17960Sstevel@tonic-gate 17970Sstevel@tonic-gate } else if ((address != ROOT_HUB_ADDR) && 17980Sstevel@tonic-gate ((usba_ugen_force_binding == USBA_UGEN_DEVICE_BINDING) || 17990Sstevel@tonic-gate ((usba_ugen_force_binding == USBA_UGEN_INTERFACE_BINDING) && 18000Sstevel@tonic-gate combined_node)) && (!is_hub)) { 18010Sstevel@tonic-gate force_bind = "ugen"; 18020Sstevel@tonic-gate } 18030Sstevel@tonic-gate 18040Sstevel@tonic-gate #ifdef DEBUG 18050Sstevel@tonic-gate /* 18060Sstevel@tonic-gate * check whether there is another dip with this name and address 18070Sstevel@tonic-gate * If the dip contains usba_device, it is held by the previous 18080Sstevel@tonic-gate * round of configuration. 18090Sstevel@tonic-gate */ 18100Sstevel@tonic-gate ASSERT(usba_find_existing_node(child_dip) == NULL); 18110Sstevel@tonic-gate #endif 1812*3630Slg150142 1813*3630Slg150142 usba_name_buf = kmem_zalloc(USBA_MAX_COMPAT_NAMES * 1814*3630Slg150142 USBA_MAX_COMPAT_NAME_LEN, KM_SLEEP); 1815*3630Slg150142 1816*3630Slg150142 for (i = 0; i < USBA_MAX_COMPAT_NAMES; i++) { 1817*3630Slg150142 usba_name[i] = usba_name_buf + (i * USBA_MAX_COMPAT_NAME_LEN); 1818*3630Slg150142 } 18190Sstevel@tonic-gate 18200Sstevel@tonic-gate if (force_bind) { 18210Sstevel@tonic-gate (void) ndi_devi_set_nodename(child_dip, force_bind, 0); 18220Sstevel@tonic-gate (void) strncpy(usba_name[n++], force_bind, 18230Sstevel@tonic-gate USBA_MAX_COMPAT_NAME_LEN); 18240Sstevel@tonic-gate } 18250Sstevel@tonic-gate 18260Sstevel@tonic-gate /* create compatible names */ 18270Sstevel@tonic-gate if (combined_node) { 18280Sstevel@tonic-gate 18290Sstevel@tonic-gate /* 1. usbVID,PID.REV */ 18300Sstevel@tonic-gate (void) sprintf(usba_name[n++], 18310Sstevel@tonic-gate "usb%x,%x.%x", 18320Sstevel@tonic-gate usb_dev_descr->idVendor, 18330Sstevel@tonic-gate usb_dev_descr->idProduct, 18340Sstevel@tonic-gate usb_dev_descr->bcdDevice); 18350Sstevel@tonic-gate 18360Sstevel@tonic-gate /* 2. usbVID,PID */ 18370Sstevel@tonic-gate (void) sprintf(usba_name[n++], 18380Sstevel@tonic-gate "usb%x,%x", 18390Sstevel@tonic-gate usb_dev_descr->idVendor, 18400Sstevel@tonic-gate usb_dev_descr->idProduct); 18410Sstevel@tonic-gate 18420Sstevel@tonic-gate if (usb_dev_descr->bDeviceClass != 0) { 18430Sstevel@tonic-gate /* 3. usbVID,classDC.DSC.DPROTO */ 18440Sstevel@tonic-gate (void) sprintf(usba_name[n++], 18450Sstevel@tonic-gate "usb%x,class%x.%x.%x", 18460Sstevel@tonic-gate usb_dev_descr->idVendor, 18470Sstevel@tonic-gate usb_dev_descr->bDeviceClass, 18480Sstevel@tonic-gate usb_dev_descr->bDeviceSubClass, 18490Sstevel@tonic-gate usb_dev_descr->bDeviceProtocol); 18500Sstevel@tonic-gate 18510Sstevel@tonic-gate /* 4. usbVID,classDC.DSC */ 18520Sstevel@tonic-gate (void) sprintf(usba_name[n++], 18530Sstevel@tonic-gate "usb%x,class%x.%x", 18540Sstevel@tonic-gate usb_dev_descr->idVendor, 18550Sstevel@tonic-gate usb_dev_descr->bDeviceClass, 18560Sstevel@tonic-gate usb_dev_descr->bDeviceSubClass); 18570Sstevel@tonic-gate 18580Sstevel@tonic-gate /* 5. usbVID,classDC */ 18590Sstevel@tonic-gate (void) sprintf(usba_name[n++], 18600Sstevel@tonic-gate "usb%x,class%x", 18610Sstevel@tonic-gate usb_dev_descr->idVendor, 18620Sstevel@tonic-gate usb_dev_descr->bDeviceClass); 18630Sstevel@tonic-gate 18640Sstevel@tonic-gate /* 6. usb,classDC.DSC.DPROTO */ 18650Sstevel@tonic-gate (void) sprintf(usba_name[n++], 18660Sstevel@tonic-gate "usb,class%x.%x.%x", 18670Sstevel@tonic-gate usb_dev_descr->bDeviceClass, 18680Sstevel@tonic-gate usb_dev_descr->bDeviceSubClass, 18690Sstevel@tonic-gate usb_dev_descr->bDeviceProtocol); 18700Sstevel@tonic-gate 18710Sstevel@tonic-gate /* 7. usb,classDC.DSC */ 18720Sstevel@tonic-gate (void) sprintf(usba_name[n++], 18730Sstevel@tonic-gate "usb,class%x.%x", 18740Sstevel@tonic-gate usb_dev_descr->bDeviceClass, 18750Sstevel@tonic-gate usb_dev_descr->bDeviceSubClass); 18760Sstevel@tonic-gate 18770Sstevel@tonic-gate /* 8. usb,classDC */ 18780Sstevel@tonic-gate (void) sprintf(usba_name[n++], 18790Sstevel@tonic-gate "usb,class%x", 18800Sstevel@tonic-gate usb_dev_descr->bDeviceClass); 18810Sstevel@tonic-gate } 18820Sstevel@tonic-gate 18830Sstevel@tonic-gate if (if_descr.bInterfaceClass != 0) { 18840Sstevel@tonic-gate /* 9. usbifVID,classIC.ISC.IPROTO */ 18850Sstevel@tonic-gate (void) sprintf(usba_name[n++], 18860Sstevel@tonic-gate "usbif%x,class%x.%x.%x", 18870Sstevel@tonic-gate usb_dev_descr->idVendor, 18880Sstevel@tonic-gate if_descr.bInterfaceClass, 18890Sstevel@tonic-gate if_descr.bInterfaceSubClass, 18900Sstevel@tonic-gate if_descr.bInterfaceProtocol); 18910Sstevel@tonic-gate 18920Sstevel@tonic-gate /* 10. usbifVID,classIC.ISC */ 18930Sstevel@tonic-gate (void) sprintf(usba_name[n++], 18940Sstevel@tonic-gate "usbif%x,class%x.%x", 18950Sstevel@tonic-gate usb_dev_descr->idVendor, 18960Sstevel@tonic-gate if_descr.bInterfaceClass, 18970Sstevel@tonic-gate if_descr.bInterfaceSubClass); 18980Sstevel@tonic-gate 18990Sstevel@tonic-gate /* 11. usbifVID,classIC */ 19000Sstevel@tonic-gate (void) sprintf(usba_name[n++], 19010Sstevel@tonic-gate "usbif%x,class%x", 19020Sstevel@tonic-gate usb_dev_descr->idVendor, 19030Sstevel@tonic-gate if_descr.bInterfaceClass); 19040Sstevel@tonic-gate 19050Sstevel@tonic-gate /* 12. usbif,classIC.ISC.IPROTO */ 19060Sstevel@tonic-gate (void) sprintf(usba_name[n++], 19070Sstevel@tonic-gate "usbif,class%x.%x.%x", 19080Sstevel@tonic-gate if_descr.bInterfaceClass, 19090Sstevel@tonic-gate if_descr.bInterfaceSubClass, 19100Sstevel@tonic-gate if_descr.bInterfaceProtocol); 19110Sstevel@tonic-gate 19120Sstevel@tonic-gate /* 13. usbif,classIC.ISC */ 19130Sstevel@tonic-gate (void) sprintf(usba_name[n++], 19140Sstevel@tonic-gate "usbif,class%x.%x", 19150Sstevel@tonic-gate if_descr.bInterfaceClass, 19160Sstevel@tonic-gate if_descr.bInterfaceSubClass); 19170Sstevel@tonic-gate 19180Sstevel@tonic-gate /* 14. usbif,classIC */ 19190Sstevel@tonic-gate (void) sprintf(usba_name[n++], 19200Sstevel@tonic-gate "usbif,class%x", 19210Sstevel@tonic-gate if_descr.bInterfaceClass); 19220Sstevel@tonic-gate } 19230Sstevel@tonic-gate 19240Sstevel@tonic-gate /* 15. ugen or usb_mid */ 19250Sstevel@tonic-gate if (usba_get_ugen_binding(child_dip) == 19260Sstevel@tonic-gate USBA_UGEN_DEVICE_BINDING) { 19270Sstevel@tonic-gate (void) sprintf(usba_name[n++], "ugen"); 19280Sstevel@tonic-gate } else { 19290Sstevel@tonic-gate (void) sprintf(usba_name[n++], "usb,device"); 19300Sstevel@tonic-gate } 19310Sstevel@tonic-gate 19320Sstevel@tonic-gate } else { 19330Sstevel@tonic-gate if (n_cfgs > 1) { 19340Sstevel@tonic-gate /* 1. usbVID,PID.REV.configCN */ 19350Sstevel@tonic-gate (void) sprintf(usba_name[n++], 19360Sstevel@tonic-gate "usb%x,%x.%x.config%x", 19370Sstevel@tonic-gate usb_dev_descr->idVendor, 19380Sstevel@tonic-gate usb_dev_descr->idProduct, 19390Sstevel@tonic-gate usb_dev_descr->bcdDevice, 19400Sstevel@tonic-gate usba_device->usb_cfg_value); 19410Sstevel@tonic-gate } 19420Sstevel@tonic-gate 19430Sstevel@tonic-gate /* 2. usbVID,PID.REV */ 19440Sstevel@tonic-gate (void) sprintf(usba_name[n++], 19450Sstevel@tonic-gate "usb%x,%x.%x", 19460Sstevel@tonic-gate usb_dev_descr->idVendor, 19470Sstevel@tonic-gate usb_dev_descr->idProduct, 19480Sstevel@tonic-gate usb_dev_descr->bcdDevice); 19490Sstevel@tonic-gate 19500Sstevel@tonic-gate /* 3. usbVID,PID.configCN */ 19510Sstevel@tonic-gate if (n_cfgs > 1) { 19520Sstevel@tonic-gate (void) sprintf(usba_name[n++], 19530Sstevel@tonic-gate "usb%x,%x.%x", 19540Sstevel@tonic-gate usb_dev_descr->idVendor, 19550Sstevel@tonic-gate usb_dev_descr->idProduct, 19560Sstevel@tonic-gate usba_device->usb_cfg_value); 19570Sstevel@tonic-gate } 19580Sstevel@tonic-gate 19590Sstevel@tonic-gate /* 4. usbVID,PID */ 19600Sstevel@tonic-gate (void) sprintf(usba_name[n++], 19610Sstevel@tonic-gate "usb%x,%x", 19620Sstevel@tonic-gate usb_dev_descr->idVendor, 19630Sstevel@tonic-gate usb_dev_descr->idProduct); 19640Sstevel@tonic-gate 19650Sstevel@tonic-gate if (usb_dev_descr->bDeviceClass != 0) { 19660Sstevel@tonic-gate /* 5. usbVID,classDC.DSC.DPROTO */ 19670Sstevel@tonic-gate (void) sprintf(usba_name[n++], 19680Sstevel@tonic-gate "usb%x,class%x.%x.%x", 19690Sstevel@tonic-gate usb_dev_descr->idVendor, 19700Sstevel@tonic-gate usb_dev_descr->bDeviceClass, 19710Sstevel@tonic-gate usb_dev_descr->bDeviceSubClass, 19720Sstevel@tonic-gate usb_dev_descr->bDeviceProtocol); 19730Sstevel@tonic-gate 19740Sstevel@tonic-gate /* 6. usbVID,classDC.DSC */ 19750Sstevel@tonic-gate (void) sprintf(usba_name[n++], 19760Sstevel@tonic-gate "usb%x.class%x.%x", 19770Sstevel@tonic-gate usb_dev_descr->idVendor, 19780Sstevel@tonic-gate usb_dev_descr->bDeviceClass, 19790Sstevel@tonic-gate usb_dev_descr->bDeviceSubClass); 19800Sstevel@tonic-gate 19810Sstevel@tonic-gate /* 7. usbVID,classDC */ 19820Sstevel@tonic-gate (void) sprintf(usba_name[n++], 19830Sstevel@tonic-gate "usb%x.class%x", 19840Sstevel@tonic-gate usb_dev_descr->idVendor, 19850Sstevel@tonic-gate usb_dev_descr->bDeviceClass); 19860Sstevel@tonic-gate 19870Sstevel@tonic-gate /* 8. usb,classDC.DSC.DPROTO */ 19880Sstevel@tonic-gate (void) sprintf(usba_name[n++], 19890Sstevel@tonic-gate "usb,class%x.%x.%x", 19900Sstevel@tonic-gate usb_dev_descr->bDeviceClass, 19910Sstevel@tonic-gate usb_dev_descr->bDeviceSubClass, 19920Sstevel@tonic-gate usb_dev_descr->bDeviceProtocol); 19930Sstevel@tonic-gate 19940Sstevel@tonic-gate /* 9. usb,classDC.DSC */ 19950Sstevel@tonic-gate (void) sprintf(usba_name[n++], 19960Sstevel@tonic-gate "usb,class%x.%x", 19970Sstevel@tonic-gate usb_dev_descr->bDeviceClass, 19980Sstevel@tonic-gate usb_dev_descr->bDeviceSubClass); 19990Sstevel@tonic-gate 20000Sstevel@tonic-gate /* 10. usb,classDC */ 20010Sstevel@tonic-gate (void) sprintf(usba_name[n++], 20020Sstevel@tonic-gate "usb,class%x", 20030Sstevel@tonic-gate usb_dev_descr->bDeviceClass); 20040Sstevel@tonic-gate } 20050Sstevel@tonic-gate 20060Sstevel@tonic-gate if (usba_get_ugen_binding(child_dip) == 20070Sstevel@tonic-gate USBA_UGEN_DEVICE_BINDING) { 20080Sstevel@tonic-gate /* 11. ugen */ 20090Sstevel@tonic-gate (void) sprintf(usba_name[n++], "ugen"); 20100Sstevel@tonic-gate } else { 20110Sstevel@tonic-gate /* 11. usb,device */ 20120Sstevel@tonic-gate (void) sprintf(usba_name[n++], "usb,device"); 20130Sstevel@tonic-gate } 20140Sstevel@tonic-gate } 20150Sstevel@tonic-gate 20160Sstevel@tonic-gate for (i = 0; i < n; i += 2) { 20170Sstevel@tonic-gate USB_DPRINTF_L3(DPRINT_MASK_USBA, usba_log_handle, 2018*3630Slg150142 "compatible name:\t%s\t%s", usba_name[i], 2019*3630Slg150142 (((i+1) < n)? usba_name[i+1] : "")); 20200Sstevel@tonic-gate } 2021*3630Slg150142 2022*3630Slg150142 rval = ndi_prop_update_string_array(DDI_DEV_T_NONE, child_dip, 2023*3630Slg150142 "compatible", (char **)usba_name, n); 2024*3630Slg150142 2025*3630Slg150142 kmem_free(usba_name_buf, USBA_MAX_COMPAT_NAMES * 2026*3630Slg150142 USBA_MAX_COMPAT_NAME_LEN); 2027*3630Slg150142 2028*3630Slg150142 if (rval != DDI_PROP_SUCCESS) { 2029*3630Slg150142 2030*3630Slg150142 USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 2031*3630Slg150142 "usba_ready_device_node: property update failed"); 2032*3630Slg150142 2033*3630Slg150142 return (child_dip); 20340Sstevel@tonic-gate } 20350Sstevel@tonic-gate 20360Sstevel@tonic-gate /* update the address property */ 20370Sstevel@tonic-gate rval = ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 20380Sstevel@tonic-gate "assigned-address", usba_device->usb_addr); 20390Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 2040978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 20410Sstevel@tonic-gate "usba_ready_device_node: address update failed"); 20420Sstevel@tonic-gate } 20430Sstevel@tonic-gate 20440Sstevel@tonic-gate /* update the usb device properties (PSARC/2000/454) */ 20450Sstevel@tonic-gate rval = ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 20460Sstevel@tonic-gate "usb-vendor-id", usb_dev_descr->idVendor); 20470Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 2048978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 20490Sstevel@tonic-gate "usba_ready_device_node: usb-vendor-id update failed"); 20500Sstevel@tonic-gate } 20510Sstevel@tonic-gate 20520Sstevel@tonic-gate rval = ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 20530Sstevel@tonic-gate "usb-product-id", usb_dev_descr->idProduct); 20540Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 2055978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 20560Sstevel@tonic-gate "usba_ready_device_node: usb-product-id update failed"); 20570Sstevel@tonic-gate } 20580Sstevel@tonic-gate 20590Sstevel@tonic-gate rval = ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 20600Sstevel@tonic-gate "usb-revision-id", usb_dev_descr->bcdDevice); 20610Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 2062978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 20630Sstevel@tonic-gate "usba_ready_device_node: usb-revision-id update failed"); 20640Sstevel@tonic-gate } 20650Sstevel@tonic-gate 20660Sstevel@tonic-gate rval = ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 20670Sstevel@tonic-gate "usb-num-configs", usb_dev_descr->bNumConfigurations); 20680Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 2069978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 20700Sstevel@tonic-gate "usba_ready_device_node: usb-num-configs update failed"); 20710Sstevel@tonic-gate } 20720Sstevel@tonic-gate 20730Sstevel@tonic-gate rval = ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 20740Sstevel@tonic-gate "usb-release", usb_dev_descr->bcdUSB); 20750Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 2076978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 20770Sstevel@tonic-gate "usba_ready_device_node: usb-release update failed"); 20780Sstevel@tonic-gate } 20790Sstevel@tonic-gate 20800Sstevel@tonic-gate devprop_str = kmem_zalloc(USB_MAXSTRINGLEN, KM_SLEEP); 20810Sstevel@tonic-gate 20820Sstevel@tonic-gate if (usba_device->usb_serialno_str) { 20830Sstevel@tonic-gate usba_filter_string(usba_device->usb_serialno_str, devprop_str); 20840Sstevel@tonic-gate rval = ndi_prop_update_string(DDI_DEV_T_NONE, child_dip, 20850Sstevel@tonic-gate "usb-serialno", devprop_str); 20860Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 2087978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 20880Sstevel@tonic-gate "usba_ready_device_node: " 20890Sstevel@tonic-gate "usb-serialno update failed"); 20900Sstevel@tonic-gate } 20910Sstevel@tonic-gate } 20920Sstevel@tonic-gate 20930Sstevel@tonic-gate if (usba_device->usb_mfg_str) { 20940Sstevel@tonic-gate usba_filter_string(usba_device->usb_mfg_str, devprop_str); 20950Sstevel@tonic-gate rval = ndi_prop_update_string(DDI_DEV_T_NONE, child_dip, 20960Sstevel@tonic-gate "usb-vendor-name", devprop_str); 20970Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 2098978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 20990Sstevel@tonic-gate "usba_ready_device_node: " 21000Sstevel@tonic-gate "usb-vendor-name update failed"); 21010Sstevel@tonic-gate } 21020Sstevel@tonic-gate } 21030Sstevel@tonic-gate 21040Sstevel@tonic-gate if (usba_device->usb_product_str) { 21050Sstevel@tonic-gate usba_filter_string(usba_device->usb_product_str, devprop_str); 21060Sstevel@tonic-gate rval = ndi_prop_update_string(DDI_DEV_T_NONE, child_dip, 21070Sstevel@tonic-gate "usb-product-name", devprop_str); 21080Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 2109978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 21100Sstevel@tonic-gate "usba_ready_device_node: " 21110Sstevel@tonic-gate "usb-product-name update failed"); 21120Sstevel@tonic-gate } 21130Sstevel@tonic-gate } 21140Sstevel@tonic-gate 21150Sstevel@tonic-gate kmem_free(devprop_str, USB_MAXSTRINGLEN); 21160Sstevel@tonic-gate 21170Sstevel@tonic-gate if (!combined_node) { 21180Sstevel@tonic-gate /* update the configuration property */ 21190Sstevel@tonic-gate rval = ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 21200Sstevel@tonic-gate "configuration#", usba_device->usb_cfg_value); 21210Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 21220Sstevel@tonic-gate USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 21230Sstevel@tonic-gate "usba_ready_device_node: " 21240Sstevel@tonic-gate "config prop update failed"); 21250Sstevel@tonic-gate } 21260Sstevel@tonic-gate } 21270Sstevel@tonic-gate 21280Sstevel@tonic-gate if (usba_device->usb_port_status == USBA_LOW_SPEED_DEV) { 21290Sstevel@tonic-gate /* create boolean property */ 21300Sstevel@tonic-gate rval = ndi_prop_create_boolean(DDI_DEV_T_NONE, child_dip, 21310Sstevel@tonic-gate "low-speed"); 21320Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 2133978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 21340Sstevel@tonic-gate "usba_ready_device_node: " 21350Sstevel@tonic-gate "low speed prop update failed"); 21360Sstevel@tonic-gate } 21370Sstevel@tonic-gate } 21380Sstevel@tonic-gate 21390Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_USBA, usba_log_handle, 21400Sstevel@tonic-gate "%s%d at port %d: %s, dip=0x%p", 21410Sstevel@tonic-gate ddi_node_name(ddi_get_parent(child_dip)), 21420Sstevel@tonic-gate ddi_get_instance(ddi_get_parent(child_dip)), 21430Sstevel@tonic-gate port, ddi_node_name(child_dip), child_dip); 21440Sstevel@tonic-gate 21450Sstevel@tonic-gate usba_set_usba_device(child_dip, usba_device); 21460Sstevel@tonic-gate 21470Sstevel@tonic-gate ASSERT(!mutex_owned(&(usba_get_usba_device(child_dip)->usb_mutex))); 21480Sstevel@tonic-gate 21490Sstevel@tonic-gate return (child_dip); 21500Sstevel@tonic-gate } 21510Sstevel@tonic-gate 21520Sstevel@tonic-gate 21530Sstevel@tonic-gate /* 21543341Sgc161489 * driver binding at interface association level. the first arg is the parent 21553341Sgc161489 * dip. if_count returns amount of interfaces which are associated within 21563341Sgc161489 * this interface-association that starts from first_if. 21573341Sgc161489 */ 21583341Sgc161489 /*ARGSUSED*/ 21593341Sgc161489 dev_info_t * 21603341Sgc161489 usba_ready_interface_association_node(dev_info_t *dip, 21613341Sgc161489 uint_t first_if, 21623341Sgc161489 uint_t *if_count) 21633341Sgc161489 { 21643341Sgc161489 dev_info_t *child_dip = NULL; 21653341Sgc161489 usba_device_t *child_ud = usba_get_usba_device(dip); 21663341Sgc161489 usb_dev_descr_t *usb_dev_descr; 21673341Sgc161489 size_t usb_cfg_length; 21683341Sgc161489 uchar_t *usb_cfg; 21693341Sgc161489 usb_ia_descr_t ia_descr; 21703341Sgc161489 int i, n, rval; 21713341Sgc161489 int reg[2]; 21723341Sgc161489 size_t size; 21733341Sgc161489 usb_port_status_t port_status; 21743341Sgc161489 char *force_bind = NULL; 2175*3630Slg150142 char *usba_name_buf = NULL; 2176*3630Slg150142 char *usba_name[USBA_MAX_COMPAT_NAMES]; 21773341Sgc161489 21783341Sgc161489 usb_cfg = usb_get_raw_cfg_data(dip, &usb_cfg_length); 21793341Sgc161489 21803341Sgc161489 mutex_enter(&child_ud->usb_mutex); 21813341Sgc161489 21823341Sgc161489 usb_dev_descr = child_ud->usb_dev_descr; 21833341Sgc161489 21843341Sgc161489 /* 21853341Sgc161489 * for each interface association, determine all compatible names 21863341Sgc161489 */ 21873341Sgc161489 USB_DPRINTF_L3(DPRINT_MASK_USBA, usba_log_handle, 21883341Sgc161489 "usba_ready_ia_node: " 21893341Sgc161489 "port %d, interface = %d, port_status = %x", 21903341Sgc161489 child_ud->usb_port, first_if, child_ud->usb_port_status); 21913341Sgc161489 21923341Sgc161489 /* Parse the interface descriptor */ 21933341Sgc161489 size = usb_parse_ia_descr( 21943341Sgc161489 usb_cfg, 21953341Sgc161489 usb_cfg_length, 21963341Sgc161489 first_if, /* interface index */ 21973341Sgc161489 &ia_descr, 21983341Sgc161489 USB_IA_DESCR_SIZE); 21993341Sgc161489 22003341Sgc161489 *if_count = 1; 22013341Sgc161489 if (size != USB_IA_DESCR_SIZE) { 22023341Sgc161489 USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 22033341Sgc161489 "parsing ia: size (%lu) != USB_IA_DESCR_SIZE (%d)", 22043341Sgc161489 size, USB_IA_DESCR_SIZE); 22053341Sgc161489 mutex_exit(&child_ud->usb_mutex); 22063341Sgc161489 22073341Sgc161489 return (NULL); 22083341Sgc161489 } 22093341Sgc161489 22103341Sgc161489 port_status = child_ud->usb_port_status; 22113341Sgc161489 22123341Sgc161489 /* create reg property */ 22133341Sgc161489 reg[0] = first_if; 22143341Sgc161489 reg[1] = child_ud->usb_cfg_value; 22153341Sgc161489 22163341Sgc161489 mutex_exit(&child_ud->usb_mutex); 22173341Sgc161489 22183341Sgc161489 /* clone this dip */ 22193341Sgc161489 rval = usba_create_child_devi(dip, 22203341Sgc161489 "interface-association", 22213341Sgc161489 NULL, /* usba_hcdi ops */ 22223341Sgc161489 NULL, /* root hub dip */ 22233341Sgc161489 port_status, /* port status */ 22243341Sgc161489 child_ud, /* share this usba_device */ 22253341Sgc161489 &child_dip); 22263341Sgc161489 22273341Sgc161489 if (rval != USB_SUCCESS) { 22283341Sgc161489 22293341Sgc161489 goto fail; 22303341Sgc161489 } 22313341Sgc161489 22323341Sgc161489 rval = ndi_prop_update_int_array( 22333341Sgc161489 DDI_DEV_T_NONE, child_dip, "reg", reg, 2); 22343341Sgc161489 22353341Sgc161489 if (rval != DDI_PROP_SUCCESS) { 22363341Sgc161489 22373341Sgc161489 goto fail; 22383341Sgc161489 } 22393341Sgc161489 22403341Sgc161489 usba_set_node_name(child_dip, ia_descr.bFunctionClass, 22413341Sgc161489 ia_descr.bFunctionSubClass, ia_descr.bFunctionProtocol, 22423341Sgc161489 FLAG_INTERFACE_ASSOCIATION_NODE); 22433341Sgc161489 22443341Sgc161489 /* check force binding */ 22453341Sgc161489 if (usba_ugen_force_binding == 22463341Sgc161489 USBA_UGEN_INTERFACE_ASSOCIATION_BINDING) { 22473341Sgc161489 force_bind = "ugen"; 22483341Sgc161489 } 22493341Sgc161489 22503341Sgc161489 /* 22513341Sgc161489 * check whether there is another dip with this name and address 22523341Sgc161489 */ 22533341Sgc161489 ASSERT(usba_find_existing_node(child_dip) == NULL); 22543341Sgc161489 2255*3630Slg150142 usba_name_buf = kmem_zalloc(USBA_MAX_COMPAT_NAMES * 2256*3630Slg150142 USBA_MAX_COMPAT_NAME_LEN, KM_SLEEP); 2257*3630Slg150142 2258*3630Slg150142 for (i = 0; i < USBA_MAX_COMPAT_NAMES; i++) { 2259*3630Slg150142 usba_name[i] = usba_name_buf + (i * USBA_MAX_COMPAT_NAME_LEN); 2260*3630Slg150142 } 2261*3630Slg150142 22623341Sgc161489 n = 0; 22633341Sgc161489 22643341Sgc161489 if (force_bind) { 22653341Sgc161489 (void) ndi_devi_set_nodename(child_dip, force_bind, 0); 22663341Sgc161489 (void) strncpy(usba_name[n++], force_bind, 22673341Sgc161489 USBA_MAX_COMPAT_NAME_LEN); 22683341Sgc161489 } 22693341Sgc161489 22703341Sgc161489 /* 1) usbiaVID,PID.REV.configCN.FN */ 22713341Sgc161489 (void) sprintf(usba_name[n++], 22723341Sgc161489 "usbia%x,%x.%x.config%x.%x", 22733341Sgc161489 usb_dev_descr->idVendor, 22743341Sgc161489 usb_dev_descr->idProduct, 22753341Sgc161489 usb_dev_descr->bcdDevice, 22763341Sgc161489 child_ud->usb_cfg_value, 22773341Sgc161489 first_if); 22783341Sgc161489 22793341Sgc161489 /* 2) usbiaVID,PID.configCN.FN */ 22803341Sgc161489 (void) sprintf(usba_name[n++], 22813341Sgc161489 "usbia%x,%x.config%x.%x", 22823341Sgc161489 usb_dev_descr->idVendor, 22833341Sgc161489 usb_dev_descr->idProduct, 22843341Sgc161489 child_ud->usb_cfg_value, 22853341Sgc161489 first_if); 22863341Sgc161489 22873341Sgc161489 22883341Sgc161489 if (ia_descr.bFunctionClass) { 22893341Sgc161489 /* 3) usbiaVID,classFC.FSC.FPROTO */ 22903341Sgc161489 (void) sprintf(usba_name[n++], 22913341Sgc161489 "usbia%x,class%x.%x.%x", 22923341Sgc161489 usb_dev_descr->idVendor, 22933341Sgc161489 ia_descr.bFunctionClass, 22943341Sgc161489 ia_descr.bFunctionSubClass, 22953341Sgc161489 ia_descr.bFunctionProtocol); 22963341Sgc161489 22973341Sgc161489 /* 4) usbiaVID,classFC.FSC */ 22983341Sgc161489 (void) sprintf(usba_name[n++], 22993341Sgc161489 "usbia%x,class%x.%x", 23003341Sgc161489 usb_dev_descr->idVendor, 23013341Sgc161489 ia_descr.bFunctionClass, 23023341Sgc161489 ia_descr.bFunctionSubClass); 23033341Sgc161489 23043341Sgc161489 /* 5) usbiaVID,classFC */ 23053341Sgc161489 (void) sprintf(usba_name[n++], 23063341Sgc161489 "usbia%x,class%x", 23073341Sgc161489 usb_dev_descr->idVendor, 23083341Sgc161489 ia_descr.bFunctionClass); 23093341Sgc161489 23103341Sgc161489 /* 6) usbia,classFC.FSC.FPROTO */ 23113341Sgc161489 (void) sprintf(usba_name[n++], 23123341Sgc161489 "usbia,class%x.%x.%x", 23133341Sgc161489 ia_descr.bFunctionClass, 23143341Sgc161489 ia_descr.bFunctionSubClass, 23153341Sgc161489 ia_descr.bFunctionProtocol); 23163341Sgc161489 23173341Sgc161489 /* 7) usbia,classFC.FSC */ 23183341Sgc161489 (void) sprintf(usba_name[n++], 23193341Sgc161489 "usbia,class%x.%x", 23203341Sgc161489 ia_descr.bFunctionClass, 23213341Sgc161489 ia_descr.bFunctionSubClass); 23223341Sgc161489 23233341Sgc161489 /* 8) usbia,classFC */ 23243341Sgc161489 (void) sprintf(usba_name[n++], 23253341Sgc161489 "usbia,class%x", 23263341Sgc161489 ia_descr.bFunctionClass); 23273341Sgc161489 } 23283341Sgc161489 23293341Sgc161489 if (usba_get_ugen_binding(child_dip) == 23303341Sgc161489 USBA_UGEN_INTERFACE_ASSOCIATION_BINDING) { 23313341Sgc161489 /* 9) ugen */ 23323341Sgc161489 (void) sprintf(usba_name[n++], "ugen"); 23333341Sgc161489 } else { 23343341Sgc161489 23353341Sgc161489 (void) sprintf(usba_name[n++], "usb,ia"); 23363341Sgc161489 } 23373341Sgc161489 23383341Sgc161489 for (i = 0; i < n; i += 2) { 23393341Sgc161489 USB_DPRINTF_L3(DPRINT_MASK_USBA, usba_log_handle, 2340*3630Slg150142 "compatible name:\t%s\t%s", usba_name[i], 2341*3630Slg150142 (((i+1) < n)? usba_name[i+1] : "")); 23423341Sgc161489 } 23433341Sgc161489 23443341Sgc161489 /* create compatible property */ 2345*3630Slg150142 rval = ndi_prop_update_string_array(DDI_DEV_T_NONE, child_dip, 2346*3630Slg150142 "compatible", (char **)usba_name, n); 2347*3630Slg150142 2348*3630Slg150142 kmem_free(usba_name_buf, USBA_MAX_COMPAT_NAMES * 2349*3630Slg150142 USBA_MAX_COMPAT_NAME_LEN); 2350*3630Slg150142 2351*3630Slg150142 if (rval != DDI_PROP_SUCCESS) { 2352*3630Slg150142 2353*3630Slg150142 goto fail; 23543341Sgc161489 } 23553341Sgc161489 23563341Sgc161489 /* update the address property */ 23573341Sgc161489 rval = ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 23583341Sgc161489 "assigned-address", child_ud->usb_addr); 23593341Sgc161489 if (rval != DDI_PROP_SUCCESS) { 23603341Sgc161489 USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 23613341Sgc161489 "usba_ready_interface_node: address update failed"); 23623341Sgc161489 } 23633341Sgc161489 23643341Sgc161489 /* create property with first interface number */ 23653341Sgc161489 rval = ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 23663341Sgc161489 "interface", ia_descr.bFirstInterface); 23673341Sgc161489 23683341Sgc161489 if (rval != DDI_PROP_SUCCESS) { 23693341Sgc161489 23703341Sgc161489 goto fail; 23713341Sgc161489 } 23723341Sgc161489 23733341Sgc161489 /* create property with the count of interfaces in this ia */ 23743341Sgc161489 rval = ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 23753341Sgc161489 "interface-count", ia_descr.bInterfaceCount); 23763341Sgc161489 23773341Sgc161489 if (rval != DDI_PROP_SUCCESS) { 23783341Sgc161489 23793341Sgc161489 goto fail; 23803341Sgc161489 } 23813341Sgc161489 23823341Sgc161489 USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 23833341Sgc161489 "%s%d port %d: %s, dip = 0x%p", 23843341Sgc161489 ddi_node_name(ddi_get_parent(dip)), 23853341Sgc161489 ddi_get_instance(ddi_get_parent(dip)), 23863341Sgc161489 child_ud->usb_port, ddi_node_name(child_dip), child_dip); 23873341Sgc161489 23883341Sgc161489 *if_count = ia_descr.bInterfaceCount; 23893341Sgc161489 usba_set_usba_device(child_dip, child_ud); 23903341Sgc161489 ASSERT(!mutex_owned(&(usba_get_usba_device(child_dip)->usb_mutex))); 23913341Sgc161489 23923341Sgc161489 return (child_dip); 23933341Sgc161489 23943341Sgc161489 fail: 23953341Sgc161489 (void) usba_destroy_child_devi(child_dip, NDI_DEVI_REMOVE); 23963341Sgc161489 23973341Sgc161489 return (NULL); 23983341Sgc161489 } 23993341Sgc161489 24003341Sgc161489 24013341Sgc161489 /* 24020Sstevel@tonic-gate * driver binding at interface level, the first arg will be the 24030Sstevel@tonic-gate * the parent dip 24040Sstevel@tonic-gate */ 24050Sstevel@tonic-gate /*ARGSUSED*/ 24060Sstevel@tonic-gate dev_info_t * 24070Sstevel@tonic-gate usba_ready_interface_node(dev_info_t *dip, uint_t intf) 24080Sstevel@tonic-gate { 24090Sstevel@tonic-gate dev_info_t *child_dip = NULL; 24100Sstevel@tonic-gate usba_device_t *child_ud = usba_get_usba_device(dip); 24110Sstevel@tonic-gate usb_dev_descr_t *usb_dev_descr; 24120Sstevel@tonic-gate size_t usb_cfg_length; 24130Sstevel@tonic-gate uchar_t *usb_cfg; 24140Sstevel@tonic-gate usb_if_descr_t if_descr; 24150Sstevel@tonic-gate int i, n, rval; 24160Sstevel@tonic-gate int reg[2]; 24170Sstevel@tonic-gate size_t size; 24180Sstevel@tonic-gate usb_port_status_t port_status; 24190Sstevel@tonic-gate char *force_bind = NULL; 2420*3630Slg150142 char *usba_name_buf = NULL; 2421*3630Slg150142 char *usba_name[USBA_MAX_COMPAT_NAMES]; 24220Sstevel@tonic-gate 24230Sstevel@tonic-gate usb_cfg = usb_get_raw_cfg_data(dip, &usb_cfg_length); 24240Sstevel@tonic-gate 24250Sstevel@tonic-gate mutex_enter(&child_ud->usb_mutex); 24260Sstevel@tonic-gate 24270Sstevel@tonic-gate usb_dev_descr = child_ud->usb_dev_descr; 24280Sstevel@tonic-gate 24290Sstevel@tonic-gate /* 24300Sstevel@tonic-gate * for each interface, determine all compatible names 24310Sstevel@tonic-gate */ 24320Sstevel@tonic-gate USB_DPRINTF_L3(DPRINT_MASK_USBA, usba_log_handle, 24330Sstevel@tonic-gate "usba_ready_interface_node: " 24340Sstevel@tonic-gate "port %d, interface = %d port status = %x", 24350Sstevel@tonic-gate child_ud->usb_port, intf, child_ud->usb_port_status); 24360Sstevel@tonic-gate 24370Sstevel@tonic-gate /* Parse the interface descriptor */ 24380Sstevel@tonic-gate size = usb_parse_if_descr( 24390Sstevel@tonic-gate usb_cfg, 24400Sstevel@tonic-gate usb_cfg_length, 24410Sstevel@tonic-gate intf, /* interface index */ 24420Sstevel@tonic-gate 0, /* alt interface index */ 24430Sstevel@tonic-gate &if_descr, 24440Sstevel@tonic-gate USB_IF_DESCR_SIZE); 24450Sstevel@tonic-gate 24460Sstevel@tonic-gate if (size != USB_IF_DESCR_SIZE) { 2447978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 24480Sstevel@tonic-gate "parsing interface: size (%lu) != USB_IF_DESCR_SIZE (%d)", 24490Sstevel@tonic-gate size, USB_IF_DESCR_SIZE); 24500Sstevel@tonic-gate mutex_exit(&child_ud->usb_mutex); 24510Sstevel@tonic-gate 24520Sstevel@tonic-gate return (NULL); 24530Sstevel@tonic-gate } 24540Sstevel@tonic-gate 24550Sstevel@tonic-gate port_status = child_ud->usb_port_status; 24560Sstevel@tonic-gate 24570Sstevel@tonic-gate /* create reg property */ 24580Sstevel@tonic-gate reg[0] = intf; 24590Sstevel@tonic-gate reg[1] = child_ud->usb_cfg_value; 24600Sstevel@tonic-gate 24610Sstevel@tonic-gate mutex_exit(&child_ud->usb_mutex); 24620Sstevel@tonic-gate 24630Sstevel@tonic-gate /* clone this dip */ 24640Sstevel@tonic-gate rval = usba_create_child_devi(dip, 24650Sstevel@tonic-gate "interface", 24660Sstevel@tonic-gate NULL, /* usba_hcdi ops */ 24670Sstevel@tonic-gate NULL, /* root hub dip */ 24680Sstevel@tonic-gate port_status, /* port status */ 24690Sstevel@tonic-gate child_ud, /* share this usba_device */ 24700Sstevel@tonic-gate &child_dip); 24710Sstevel@tonic-gate 24720Sstevel@tonic-gate if (rval != USB_SUCCESS) { 24730Sstevel@tonic-gate 24740Sstevel@tonic-gate goto fail; 24750Sstevel@tonic-gate } 24760Sstevel@tonic-gate 24770Sstevel@tonic-gate rval = ndi_prop_update_int_array( 24780Sstevel@tonic-gate DDI_DEV_T_NONE, child_dip, "reg", reg, 2); 24790Sstevel@tonic-gate 24800Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 24810Sstevel@tonic-gate 24820Sstevel@tonic-gate goto fail; 24830Sstevel@tonic-gate } 24840Sstevel@tonic-gate 24850Sstevel@tonic-gate usba_set_node_name(child_dip, if_descr.bInterfaceClass, 24860Sstevel@tonic-gate if_descr.bInterfaceSubClass, if_descr.bInterfaceProtocol, 24870Sstevel@tonic-gate FLAG_INTERFACE_NODE); 24880Sstevel@tonic-gate 24890Sstevel@tonic-gate /* check force binding */ 24900Sstevel@tonic-gate if (usba_ugen_force_binding == USBA_UGEN_INTERFACE_BINDING) { 24910Sstevel@tonic-gate force_bind = "ugen"; 24920Sstevel@tonic-gate } 24930Sstevel@tonic-gate 24940Sstevel@tonic-gate /* 24950Sstevel@tonic-gate * check whether there is another dip with this name and address 24960Sstevel@tonic-gate */ 24970Sstevel@tonic-gate ASSERT(usba_find_existing_node(child_dip) == NULL); 24980Sstevel@tonic-gate 2499*3630Slg150142 usba_name_buf = kmem_zalloc(USBA_MAX_COMPAT_NAMES * 2500*3630Slg150142 USBA_MAX_COMPAT_NAME_LEN, KM_SLEEP); 2501*3630Slg150142 2502*3630Slg150142 for (i = 0; i < USBA_MAX_COMPAT_NAMES; i++) { 2503*3630Slg150142 usba_name[i] = usba_name_buf + (i * USBA_MAX_COMPAT_NAME_LEN); 2504*3630Slg150142 } 2505*3630Slg150142 25060Sstevel@tonic-gate n = 0; 25070Sstevel@tonic-gate 25080Sstevel@tonic-gate if (force_bind) { 25090Sstevel@tonic-gate (void) ndi_devi_set_nodename(child_dip, force_bind, 0); 25100Sstevel@tonic-gate (void) strncpy(usba_name[n++], force_bind, 25110Sstevel@tonic-gate USBA_MAX_COMPAT_NAME_LEN); 25120Sstevel@tonic-gate } 25130Sstevel@tonic-gate 25140Sstevel@tonic-gate /* 1) usbifVID,PID.REV.configCN.IN */ 25150Sstevel@tonic-gate (void) sprintf(usba_name[n++], 25160Sstevel@tonic-gate "usbif%x,%x.%x.config%x.%x", 25170Sstevel@tonic-gate usb_dev_descr->idVendor, 25180Sstevel@tonic-gate usb_dev_descr->idProduct, 25190Sstevel@tonic-gate usb_dev_descr->bcdDevice, 25200Sstevel@tonic-gate child_ud->usb_cfg_value, 25210Sstevel@tonic-gate intf); 25220Sstevel@tonic-gate 25230Sstevel@tonic-gate /* 2) usbifVID,PID.configCN.IN */ 25240Sstevel@tonic-gate (void) sprintf(usba_name[n++], 25250Sstevel@tonic-gate "usbif%x,%x.config%x.%x", 25260Sstevel@tonic-gate usb_dev_descr->idVendor, 25270Sstevel@tonic-gate usb_dev_descr->idProduct, 25280Sstevel@tonic-gate child_ud->usb_cfg_value, 25290Sstevel@tonic-gate intf); 25300Sstevel@tonic-gate 25310Sstevel@tonic-gate 25320Sstevel@tonic-gate if (if_descr.bInterfaceClass) { 25330Sstevel@tonic-gate /* 3) usbifVID,classIC.ISC.IPROTO */ 25340Sstevel@tonic-gate (void) sprintf(usba_name[n++], 25350Sstevel@tonic-gate "usbif%x,class%x.%x.%x", 25360Sstevel@tonic-gate usb_dev_descr->idVendor, 25370Sstevel@tonic-gate if_descr.bInterfaceClass, 25380Sstevel@tonic-gate if_descr.bInterfaceSubClass, 25390Sstevel@tonic-gate if_descr.bInterfaceProtocol); 25400Sstevel@tonic-gate 25410Sstevel@tonic-gate /* 4) usbifVID,classIC.ISC */ 25420Sstevel@tonic-gate (void) sprintf(usba_name[n++], 25430Sstevel@tonic-gate "usbif%x,class%x.%x", 25440Sstevel@tonic-gate usb_dev_descr->idVendor, 25450Sstevel@tonic-gate if_descr.bInterfaceClass, 25460Sstevel@tonic-gate if_descr.bInterfaceSubClass); 25470Sstevel@tonic-gate 25480Sstevel@tonic-gate /* 5) usbifVID,classIC */ 25490Sstevel@tonic-gate (void) sprintf(usba_name[n++], 25500Sstevel@tonic-gate "usbif%x,class%x", 25510Sstevel@tonic-gate usb_dev_descr->idVendor, 25520Sstevel@tonic-gate if_descr.bInterfaceClass); 25530Sstevel@tonic-gate 25540Sstevel@tonic-gate /* 6) usbif,classIC.ISC.IPROTO */ 25550Sstevel@tonic-gate (void) sprintf(usba_name[n++], 25560Sstevel@tonic-gate "usbif,class%x.%x.%x", 25570Sstevel@tonic-gate if_descr.bInterfaceClass, 25580Sstevel@tonic-gate if_descr.bInterfaceSubClass, 25590Sstevel@tonic-gate if_descr.bInterfaceProtocol); 25600Sstevel@tonic-gate 25610Sstevel@tonic-gate /* 7) usbif,classIC.ISC */ 25620Sstevel@tonic-gate (void) sprintf(usba_name[n++], 25630Sstevel@tonic-gate "usbif,class%x.%x", 25640Sstevel@tonic-gate if_descr.bInterfaceClass, 25650Sstevel@tonic-gate if_descr.bInterfaceSubClass); 25660Sstevel@tonic-gate 25670Sstevel@tonic-gate /* 8) usbif,classIC */ 25680Sstevel@tonic-gate (void) sprintf(usba_name[n++], 25690Sstevel@tonic-gate "usbif,class%x", 25700Sstevel@tonic-gate if_descr.bInterfaceClass); 25710Sstevel@tonic-gate } 25720Sstevel@tonic-gate 25730Sstevel@tonic-gate if (usba_get_ugen_binding(child_dip) == 25740Sstevel@tonic-gate USBA_UGEN_INTERFACE_BINDING) { 25750Sstevel@tonic-gate /* 9) ugen */ 25760Sstevel@tonic-gate (void) sprintf(usba_name[n++], "ugen"); 25770Sstevel@tonic-gate } 25780Sstevel@tonic-gate 25790Sstevel@tonic-gate for (i = 0; i < n; i += 2) { 25800Sstevel@tonic-gate USB_DPRINTF_L3(DPRINT_MASK_USBA, usba_log_handle, 2581*3630Slg150142 "compatible name:\t%s\t%s", usba_name[i], 2582*3630Slg150142 (((i+1) < n)? usba_name[i+1] : "")); 25830Sstevel@tonic-gate } 25840Sstevel@tonic-gate 25850Sstevel@tonic-gate /* create compatible property */ 2586*3630Slg150142 rval = ndi_prop_update_string_array(DDI_DEV_T_NONE, child_dip, 2587*3630Slg150142 "compatible", (char **)usba_name, n); 2588*3630Slg150142 2589*3630Slg150142 kmem_free(usba_name_buf, USBA_MAX_COMPAT_NAMES * 2590*3630Slg150142 USBA_MAX_COMPAT_NAME_LEN); 2591*3630Slg150142 2592*3630Slg150142 if (rval != DDI_PROP_SUCCESS) { 2593*3630Slg150142 2594*3630Slg150142 goto fail; 25950Sstevel@tonic-gate } 25960Sstevel@tonic-gate 25970Sstevel@tonic-gate /* update the address property */ 25980Sstevel@tonic-gate rval = ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 25990Sstevel@tonic-gate "assigned-address", child_ud->usb_addr); 26000Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 2601978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 26020Sstevel@tonic-gate "usba_ready_interface_node: address update failed"); 26030Sstevel@tonic-gate } 26040Sstevel@tonic-gate 26050Sstevel@tonic-gate /* create property with if number */ 26060Sstevel@tonic-gate rval = ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 26070Sstevel@tonic-gate "interface", intf); 26080Sstevel@tonic-gate 26090Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 26100Sstevel@tonic-gate 26110Sstevel@tonic-gate goto fail; 26120Sstevel@tonic-gate } 26130Sstevel@tonic-gate 26140Sstevel@tonic-gate USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 26150Sstevel@tonic-gate "%s%d port %d: %s, dip = 0x%p", 26160Sstevel@tonic-gate ddi_node_name(ddi_get_parent(dip)), 26170Sstevel@tonic-gate ddi_get_instance(ddi_get_parent(dip)), 26180Sstevel@tonic-gate child_ud->usb_port, ddi_node_name(child_dip), child_dip); 26190Sstevel@tonic-gate 26200Sstevel@tonic-gate usba_set_usba_device(child_dip, child_ud); 26210Sstevel@tonic-gate ASSERT(!mutex_owned(&(usba_get_usba_device(child_dip)->usb_mutex))); 26220Sstevel@tonic-gate 26230Sstevel@tonic-gate return (child_dip); 26240Sstevel@tonic-gate 26250Sstevel@tonic-gate fail: 26260Sstevel@tonic-gate (void) usba_destroy_child_devi(child_dip, NDI_DEVI_REMOVE); 26270Sstevel@tonic-gate 26280Sstevel@tonic-gate return (NULL); 26290Sstevel@tonic-gate } 26300Sstevel@tonic-gate 26310Sstevel@tonic-gate 26320Sstevel@tonic-gate /* 26330Sstevel@tonic-gate * retrieve string descriptors for manufacturer, vendor and serial 26340Sstevel@tonic-gate * number 26350Sstevel@tonic-gate */ 26360Sstevel@tonic-gate void 26370Sstevel@tonic-gate usba_get_dev_string_descrs(dev_info_t *dip, usba_device_t *ud) 26380Sstevel@tonic-gate { 26390Sstevel@tonic-gate char *tmpbuf, *str; 26400Sstevel@tonic-gate int l; 26410Sstevel@tonic-gate usb_dev_descr_t *usb_dev_descr = ud->usb_dev_descr; 26420Sstevel@tonic-gate 26430Sstevel@tonic-gate 26440Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_USBA, usba_log_handle, 26450Sstevel@tonic-gate "usba_get_usb_string_descr: m=%d, p=%d, s=%d", 26460Sstevel@tonic-gate usb_dev_descr->iManufacturer, 26470Sstevel@tonic-gate usb_dev_descr->iProduct, 26480Sstevel@tonic-gate usb_dev_descr->iSerialNumber); 26490Sstevel@tonic-gate 26500Sstevel@tonic-gate tmpbuf = kmem_zalloc(USB_MAXSTRINGLEN, KM_SLEEP); 26510Sstevel@tonic-gate 26520Sstevel@tonic-gate /* fetch manufacturer string */ 26530Sstevel@tonic-gate if ((ud->usb_mfg_str == NULL) && usb_dev_descr->iManufacturer && 26540Sstevel@tonic-gate (usb_get_string_descr(dip, USB_LANG_ID, 26550Sstevel@tonic-gate usb_dev_descr->iManufacturer, tmpbuf, USB_MAXSTRINGLEN) == 26560Sstevel@tonic-gate USB_SUCCESS)) { 26570Sstevel@tonic-gate 26580Sstevel@tonic-gate l = strlen(tmpbuf); 26590Sstevel@tonic-gate if (l > 0) { 26600Sstevel@tonic-gate str = kmem_zalloc(l + 1, KM_SLEEP); 26610Sstevel@tonic-gate mutex_enter(&ud->usb_mutex); 26620Sstevel@tonic-gate ud->usb_mfg_str = str; 26630Sstevel@tonic-gate (void) strcpy(ud->usb_mfg_str, tmpbuf); 26640Sstevel@tonic-gate mutex_exit(&ud->usb_mutex); 26650Sstevel@tonic-gate } 26660Sstevel@tonic-gate } 26670Sstevel@tonic-gate 26680Sstevel@tonic-gate /* fetch product string */ 26690Sstevel@tonic-gate if ((ud->usb_product_str == NULL) && usb_dev_descr->iProduct && 26700Sstevel@tonic-gate (usb_get_string_descr(dip, USB_LANG_ID, usb_dev_descr->iProduct, 26710Sstevel@tonic-gate tmpbuf, USB_MAXSTRINGLEN) == 26720Sstevel@tonic-gate USB_SUCCESS)) { 26730Sstevel@tonic-gate 26740Sstevel@tonic-gate l = strlen(tmpbuf); 26750Sstevel@tonic-gate if (l > 0) { 26760Sstevel@tonic-gate str = kmem_zalloc(l + 1, KM_SLEEP); 26770Sstevel@tonic-gate mutex_enter(&ud->usb_mutex); 26780Sstevel@tonic-gate ud->usb_product_str = str; 26790Sstevel@tonic-gate (void) strcpy(ud->usb_product_str, tmpbuf); 26800Sstevel@tonic-gate mutex_exit(&ud->usb_mutex); 26810Sstevel@tonic-gate } 26820Sstevel@tonic-gate } 26830Sstevel@tonic-gate 26840Sstevel@tonic-gate /* fetch device serial number string */ 26850Sstevel@tonic-gate if ((ud->usb_serialno_str == NULL) && usb_dev_descr->iSerialNumber && 26860Sstevel@tonic-gate (usb_get_string_descr(dip, USB_LANG_ID, 26870Sstevel@tonic-gate usb_dev_descr->iSerialNumber, tmpbuf, USB_MAXSTRINGLEN) == 26880Sstevel@tonic-gate USB_SUCCESS)) { 26890Sstevel@tonic-gate 26900Sstevel@tonic-gate l = strlen(tmpbuf); 26910Sstevel@tonic-gate if (l > 0) { 26920Sstevel@tonic-gate str = kmem_zalloc(l + 1, KM_SLEEP); 26930Sstevel@tonic-gate mutex_enter(&ud->usb_mutex); 26940Sstevel@tonic-gate ud->usb_serialno_str = str; 26950Sstevel@tonic-gate (void) strcpy(ud->usb_serialno_str, tmpbuf); 26960Sstevel@tonic-gate mutex_exit(&ud->usb_mutex); 26970Sstevel@tonic-gate } 26980Sstevel@tonic-gate } 26990Sstevel@tonic-gate 27000Sstevel@tonic-gate kmem_free(tmpbuf, USB_MAXSTRINGLEN); 27010Sstevel@tonic-gate } 27020Sstevel@tonic-gate 27030Sstevel@tonic-gate 27040Sstevel@tonic-gate /* 27050Sstevel@tonic-gate * usba_str_startcmp: 27060Sstevel@tonic-gate * Return the number of characters duplicated from the beginning of the 27070Sstevel@tonic-gate * string. Return -1 if a complete duplicate. 27080Sstevel@tonic-gate * 27090Sstevel@tonic-gate * Arguments: 27100Sstevel@tonic-gate * Two strings to compare. 27110Sstevel@tonic-gate */ 27120Sstevel@tonic-gate static int usba_str_startcmp(char *first, char *second) 27130Sstevel@tonic-gate { 27140Sstevel@tonic-gate int num_same_chars = 0; 27150Sstevel@tonic-gate while (*first == *second++) { 27160Sstevel@tonic-gate if (*first++ == '\0') { 27170Sstevel@tonic-gate return (-1); 27180Sstevel@tonic-gate } 27190Sstevel@tonic-gate num_same_chars++; 27200Sstevel@tonic-gate } 27210Sstevel@tonic-gate 27220Sstevel@tonic-gate return (num_same_chars); 27230Sstevel@tonic-gate } 27240Sstevel@tonic-gate 27250Sstevel@tonic-gate 27260Sstevel@tonic-gate /* 27270Sstevel@tonic-gate * usba_get_mfg_prod_sn_str: 27280Sstevel@tonic-gate * Return a string containing mfg, product, serial number strings. 27290Sstevel@tonic-gate * Remove duplicates if some strings are the same. 27300Sstevel@tonic-gate * 27310Sstevel@tonic-gate * Arguments: 27320Sstevel@tonic-gate * dip - pointer to dev info 27330Sstevel@tonic-gate * buffer - Where string is returned 27340Sstevel@tonic-gate * buflen - Length of buffer 27350Sstevel@tonic-gate * 27360Sstevel@tonic-gate * Returns: 27370Sstevel@tonic-gate * Same as second arg. 27380Sstevel@tonic-gate */ 27390Sstevel@tonic-gate char * 27400Sstevel@tonic-gate usba_get_mfg_prod_sn_str( 27410Sstevel@tonic-gate dev_info_t *dip, 27420Sstevel@tonic-gate char *buffer, 27430Sstevel@tonic-gate int buflen) 27440Sstevel@tonic-gate { 27450Sstevel@tonic-gate usba_device_t *usba_device = usba_get_usba_device(dip); 27460Sstevel@tonic-gate int return_len = 0; 27470Sstevel@tonic-gate int len = 0; 27480Sstevel@tonic-gate int duplen; 27490Sstevel@tonic-gate 27500Sstevel@tonic-gate buffer[0] = '\0'; 27510Sstevel@tonic-gate buffer[buflen-1] = '\0'; 27520Sstevel@tonic-gate 27530Sstevel@tonic-gate if ((usba_device->usb_mfg_str) && 27540Sstevel@tonic-gate ((len = strlen(usba_device->usb_mfg_str)) != 0)) { 27550Sstevel@tonic-gate (void) strncpy(buffer, usba_device->usb_mfg_str, buflen - 1); 27560Sstevel@tonic-gate return_len = min(buflen - 1, len); 27570Sstevel@tonic-gate } 27580Sstevel@tonic-gate 27590Sstevel@tonic-gate /* Product string exists to append. */ 27600Sstevel@tonic-gate if ((usba_device->usb_product_str) && 27610Sstevel@tonic-gate ((len = strlen(usba_device->usb_product_str)) != 0)) { 27620Sstevel@tonic-gate 27630Sstevel@tonic-gate /* Append only parts of string that don't match mfg string. */ 27640Sstevel@tonic-gate duplen = usba_str_startcmp(buffer, 27650Sstevel@tonic-gate usba_device->usb_product_str); 27660Sstevel@tonic-gate 27670Sstevel@tonic-gate if (duplen != -1) { /* Not a complete match. */ 27680Sstevel@tonic-gate if (return_len > 0) { 27690Sstevel@tonic-gate buffer[return_len++] = ' '; 27700Sstevel@tonic-gate } 27710Sstevel@tonic-gate 27720Sstevel@tonic-gate /* Skip over the dup part of the concat'ed string. */ 27730Sstevel@tonic-gate len -= duplen; 27740Sstevel@tonic-gate (void) strncpy(&buffer[return_len], 27750Sstevel@tonic-gate &usba_device->usb_product_str[duplen], 27760Sstevel@tonic-gate buflen - return_len - 1); 27770Sstevel@tonic-gate return_len = min(buflen - 1, return_len + len); 27780Sstevel@tonic-gate } 27790Sstevel@tonic-gate } 27800Sstevel@tonic-gate 27810Sstevel@tonic-gate if ((usba_device->usb_serialno_str) && 27820Sstevel@tonic-gate ((len = strlen(usba_device->usb_serialno_str)) != 0)) { 27830Sstevel@tonic-gate if (return_len > 0) { 27840Sstevel@tonic-gate buffer[return_len++] = ' '; 27850Sstevel@tonic-gate } 27860Sstevel@tonic-gate (void) strncpy(&buffer[return_len], 27870Sstevel@tonic-gate usba_device->usb_serialno_str, 27880Sstevel@tonic-gate buflen - return_len - 1); 27890Sstevel@tonic-gate } 27900Sstevel@tonic-gate 27910Sstevel@tonic-gate return (buffer); 27920Sstevel@tonic-gate } 27930Sstevel@tonic-gate 27940Sstevel@tonic-gate 27950Sstevel@tonic-gate /* 27960Sstevel@tonic-gate * USB enumeration statistic functions 27970Sstevel@tonic-gate */ 27980Sstevel@tonic-gate 27990Sstevel@tonic-gate /* 28000Sstevel@tonic-gate * Increments the hotplug statistics based on flags. 28010Sstevel@tonic-gate */ 28020Sstevel@tonic-gate void 28030Sstevel@tonic-gate usba_update_hotplug_stats(dev_info_t *dip, usb_flags_t flags) 28040Sstevel@tonic-gate { 28050Sstevel@tonic-gate usba_device_t *usba_device = usba_get_usba_device(dip); 28060Sstevel@tonic-gate usba_hcdi_t *hcdi = 28070Sstevel@tonic-gate usba_hcdi_get_hcdi(usba_device->usb_root_hub_dip); 28080Sstevel@tonic-gate 28090Sstevel@tonic-gate mutex_enter(&hcdi->hcdi_mutex); 28100Sstevel@tonic-gate if (flags & USBA_TOTAL_HOTPLUG_SUCCESS) { 28110Sstevel@tonic-gate hcdi->hcdi_total_hotplug_success++; 28120Sstevel@tonic-gate HCDI_HOTPLUG_STATS_DATA(hcdi)-> 28130Sstevel@tonic-gate hcdi_hotplug_total_success.value.ui64++; 28140Sstevel@tonic-gate } 28150Sstevel@tonic-gate if (flags & USBA_HOTPLUG_SUCCESS) { 28160Sstevel@tonic-gate hcdi->hcdi_hotplug_success++; 28170Sstevel@tonic-gate HCDI_HOTPLUG_STATS_DATA(hcdi)-> 28180Sstevel@tonic-gate hcdi_hotplug_success.value.ui64++; 28190Sstevel@tonic-gate } 28200Sstevel@tonic-gate if (flags & USBA_TOTAL_HOTPLUG_FAILURE) { 28210Sstevel@tonic-gate hcdi->hcdi_total_hotplug_failure++; 28220Sstevel@tonic-gate HCDI_HOTPLUG_STATS_DATA(hcdi)-> 28230Sstevel@tonic-gate hcdi_hotplug_total_failure.value.ui64++; 28240Sstevel@tonic-gate } 28250Sstevel@tonic-gate if (flags & USBA_HOTPLUG_FAILURE) { 28260Sstevel@tonic-gate hcdi->hcdi_hotplug_failure++; 28270Sstevel@tonic-gate HCDI_HOTPLUG_STATS_DATA(hcdi)-> 28280Sstevel@tonic-gate hcdi_hotplug_failure.value.ui64++; 28290Sstevel@tonic-gate } 28300Sstevel@tonic-gate mutex_exit(&hcdi->hcdi_mutex); 28310Sstevel@tonic-gate } 28320Sstevel@tonic-gate 28330Sstevel@tonic-gate 28340Sstevel@tonic-gate /* 28350Sstevel@tonic-gate * Retrieve the current enumeration statistics 28360Sstevel@tonic-gate */ 28370Sstevel@tonic-gate void 28380Sstevel@tonic-gate usba_get_hotplug_stats(dev_info_t *dip, ulong_t *total_success, 28390Sstevel@tonic-gate ulong_t *success, ulong_t *total_failure, ulong_t *failure, 28400Sstevel@tonic-gate uchar_t *device_count) 28410Sstevel@tonic-gate { 28420Sstevel@tonic-gate usba_device_t *usba_device = usba_get_usba_device(dip); 28430Sstevel@tonic-gate usba_hcdi_t *hcdi = 28440Sstevel@tonic-gate usba_hcdi_get_hcdi(usba_device->usb_root_hub_dip); 28450Sstevel@tonic-gate 28460Sstevel@tonic-gate mutex_enter(&hcdi->hcdi_mutex); 28470Sstevel@tonic-gate *total_success = hcdi->hcdi_total_hotplug_success; 28480Sstevel@tonic-gate *success = hcdi->hcdi_hotplug_success; 28490Sstevel@tonic-gate *total_failure = hcdi->hcdi_total_hotplug_failure; 28500Sstevel@tonic-gate *failure = hcdi->hcdi_hotplug_failure; 28510Sstevel@tonic-gate *device_count = hcdi->hcdi_device_count; 28520Sstevel@tonic-gate mutex_exit(&hcdi->hcdi_mutex); 28530Sstevel@tonic-gate } 28540Sstevel@tonic-gate 28550Sstevel@tonic-gate 28560Sstevel@tonic-gate /* 28570Sstevel@tonic-gate * Reset the resetable hotplug stats 28580Sstevel@tonic-gate */ 28590Sstevel@tonic-gate void 28600Sstevel@tonic-gate usba_reset_hotplug_stats(dev_info_t *dip) 28610Sstevel@tonic-gate { 28620Sstevel@tonic-gate usba_device_t *usba_device = usba_get_usba_device(dip); 28630Sstevel@tonic-gate usba_hcdi_t *hcdi = 28640Sstevel@tonic-gate usba_hcdi_get_hcdi(usba_device->usb_root_hub_dip); 28650Sstevel@tonic-gate hcdi_hotplug_stats_t *hsp; 28660Sstevel@tonic-gate 28670Sstevel@tonic-gate mutex_enter(&hcdi->hcdi_mutex); 28680Sstevel@tonic-gate hcdi->hcdi_hotplug_success = 0; 28690Sstevel@tonic-gate hcdi->hcdi_hotplug_failure = 0; 28700Sstevel@tonic-gate 28710Sstevel@tonic-gate hsp = HCDI_HOTPLUG_STATS_DATA(hcdi); 28720Sstevel@tonic-gate hsp->hcdi_hotplug_success.value.ui64 = 0; 28730Sstevel@tonic-gate hsp->hcdi_hotplug_failure.value.ui64 = 0; 28740Sstevel@tonic-gate mutex_exit(&hcdi->hcdi_mutex); 28750Sstevel@tonic-gate } 28760Sstevel@tonic-gate 28770Sstevel@tonic-gate 28780Sstevel@tonic-gate /* 28790Sstevel@tonic-gate * usba_bind_driver(): 28800Sstevel@tonic-gate * This function calls ndi_devi_bind_driver() which tries to 28810Sstevel@tonic-gate * bind a driver to the device. If the driver binding fails 28820Sstevel@tonic-gate * we get an rval of NDI_UNBOUD and report an error to the 28830Sstevel@tonic-gate * syslog that the driver failed binding. 28840Sstevel@tonic-gate * If rval is something other than NDI_UNBOUND we report an 28850Sstevel@tonic-gate * error to the console. 28860Sstevel@tonic-gate * 28870Sstevel@tonic-gate * This function returns USB_SUCCESS if no errors were 28880Sstevel@tonic-gate * encountered while binding. 28890Sstevel@tonic-gate */ 28900Sstevel@tonic-gate int 28910Sstevel@tonic-gate usba_bind_driver(dev_info_t *dip) 28920Sstevel@tonic-gate { 28930Sstevel@tonic-gate int rval; 28940Sstevel@tonic-gate char *name; 28950Sstevel@tonic-gate uint8_t if_num = usba_get_ifno(dip); 28960Sstevel@tonic-gate 28970Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_USBA, usba_log_handle, 28980Sstevel@tonic-gate "usba_bind_driver: dip = 0x%p, if_num = 0x%x", dip, if_num); 28990Sstevel@tonic-gate 29000Sstevel@tonic-gate name = kmem_zalloc(MAXNAMELEN, KM_SLEEP); 29010Sstevel@tonic-gate 29020Sstevel@tonic-gate /* bind device to the driver */ 29030Sstevel@tonic-gate if ((rval = ndi_devi_bind_driver(dip, 0)) != NDI_SUCCESS) { 29040Sstevel@tonic-gate /* if we fail to bind report an error */ 29050Sstevel@tonic-gate (void) usba_get_mfg_prod_sn_str(dip, name, MAXNAMELEN); 29060Sstevel@tonic-gate if (name[0] != '\0') { 29070Sstevel@tonic-gate if (!usb_owns_device(dip)) { 29080Sstevel@tonic-gate USB_DPRINTF_L1(DPRINT_MASK_USBA, 29090Sstevel@tonic-gate usba_log_handle, 29100Sstevel@tonic-gate "no driver found for " 29110Sstevel@tonic-gate "interface %d (nodename: '%s') of %s", 29120Sstevel@tonic-gate if_num, ddi_node_name(dip), name); 29130Sstevel@tonic-gate } else { 29140Sstevel@tonic-gate USB_DPRINTF_L1(DPRINT_MASK_USBA, 29150Sstevel@tonic-gate usba_log_handle, 29160Sstevel@tonic-gate "no driver found for device %s", name); 29170Sstevel@tonic-gate } 29180Sstevel@tonic-gate } else { 29190Sstevel@tonic-gate (void) ddi_pathname(dip, name); 29200Sstevel@tonic-gate USB_DPRINTF_L1(DPRINT_MASK_USBA, 29210Sstevel@tonic-gate usba_log_handle, 29220Sstevel@tonic-gate "no driver found for device %s", name); 29230Sstevel@tonic-gate } 29240Sstevel@tonic-gate 29250Sstevel@tonic-gate kmem_free(name, MAXNAMELEN); 29260Sstevel@tonic-gate 29270Sstevel@tonic-gate return (USB_FAILURE); 29280Sstevel@tonic-gate } 29290Sstevel@tonic-gate kmem_free(name, MAXNAMELEN); 29300Sstevel@tonic-gate 29310Sstevel@tonic-gate return ((rval == NDI_SUCCESS) ? USB_SUCCESS : USB_FAILURE); 29320Sstevel@tonic-gate } 29330Sstevel@tonic-gate 29340Sstevel@tonic-gate 29350Sstevel@tonic-gate /* 29360Sstevel@tonic-gate * usba_get_hc_dma_attr: 29370Sstevel@tonic-gate * function returning dma attributes of the HCD 29380Sstevel@tonic-gate * 29390Sstevel@tonic-gate * Arguments: 29400Sstevel@tonic-gate * dip - pointer to devinfo of the client 29410Sstevel@tonic-gate * 29420Sstevel@tonic-gate * Return Values: 29430Sstevel@tonic-gate * hcdi_dma_attr 29440Sstevel@tonic-gate */ 29450Sstevel@tonic-gate ddi_dma_attr_t * 29460Sstevel@tonic-gate usba_get_hc_dma_attr(dev_info_t *dip) 29470Sstevel@tonic-gate { 29480Sstevel@tonic-gate usba_device_t *usba_device = usba_get_usba_device(dip); 29490Sstevel@tonic-gate usba_hcdi_t *hcdi = usba_hcdi_get_hcdi(usba_device->usb_root_hub_dip); 29500Sstevel@tonic-gate 29510Sstevel@tonic-gate return (hcdi->hcdi_dma_attr); 29520Sstevel@tonic-gate } 29530Sstevel@tonic-gate 29540Sstevel@tonic-gate 29550Sstevel@tonic-gate /* 29560Sstevel@tonic-gate * usba_check_for_leaks: 29570Sstevel@tonic-gate * check usba_device structure for leaks 29580Sstevel@tonic-gate * 29590Sstevel@tonic-gate * Arguments: 29600Sstevel@tonic-gate * usba_device - usba_device structure pointer 29610Sstevel@tonic-gate */ 29620Sstevel@tonic-gate void 29630Sstevel@tonic-gate usba_check_for_leaks(usba_device_t *usba_device) 29640Sstevel@tonic-gate { 29650Sstevel@tonic-gate int i, ph_open_cnt, req_wrp_leaks, iface; 29660Sstevel@tonic-gate int leaks = 0; 29670Sstevel@tonic-gate 29680Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_USBA, usba_log_handle, 29690Sstevel@tonic-gate "usba_check_for_leaks: %s%d usba_device=0x%p", 29700Sstevel@tonic-gate ddi_driver_name(usba_device->usb_dip), 29710Sstevel@tonic-gate ddi_get_instance(usba_device->usb_dip), usba_device); 29720Sstevel@tonic-gate 29730Sstevel@tonic-gate /* 29740Sstevel@tonic-gate * default pipe is still open 29750Sstevel@tonic-gate * all other pipes should be closed 29760Sstevel@tonic-gate */ 29770Sstevel@tonic-gate for (ph_open_cnt = 0, i = 1; i < USBA_N_ENDPOINTS; i++) { 29780Sstevel@tonic-gate usba_ph_impl_t *ph_impl = 29790Sstevel@tonic-gate &usba_device->usb_ph_list[i]; 29800Sstevel@tonic-gate if (ph_impl->usba_ph_data) { 2981978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, 29820Sstevel@tonic-gate usba_log_handle, 29830Sstevel@tonic-gate "%s%d: leaking pipehandle=0x%p (0x%p) ep_addr=0x%x", 29840Sstevel@tonic-gate ddi_driver_name(ph_impl->usba_ph_data->p_dip), 29850Sstevel@tonic-gate ddi_get_instance(ph_impl->usba_ph_data->p_dip), 29860Sstevel@tonic-gate ph_impl, 29870Sstevel@tonic-gate ph_impl->usba_ph_data, 29880Sstevel@tonic-gate ph_impl->usba_ph_ep.bEndpointAddress); 29890Sstevel@tonic-gate ph_open_cnt++; 29900Sstevel@tonic-gate leaks++; 29910Sstevel@tonic-gate #ifndef DEBUG 29920Sstevel@tonic-gate usb_pipe_close(ph_impl->usba_ph_data->p_dip, 29930Sstevel@tonic-gate (usb_pipe_handle_t)ph_impl, USB_FLAGS_SLEEP, 29940Sstevel@tonic-gate NULL, NULL); 29950Sstevel@tonic-gate #endif 29960Sstevel@tonic-gate } 29970Sstevel@tonic-gate } 29980Sstevel@tonic-gate req_wrp_leaks = usba_list_entry_leaks(&usba_device-> 29990Sstevel@tonic-gate usb_allocated, "request wrappers"); 30000Sstevel@tonic-gate 30010Sstevel@tonic-gate ASSERT(ph_open_cnt == 0); 30020Sstevel@tonic-gate ASSERT(req_wrp_leaks == 0); 30030Sstevel@tonic-gate 30040Sstevel@tonic-gate if (req_wrp_leaks) { 30050Sstevel@tonic-gate usba_list_entry_t *entry; 30060Sstevel@tonic-gate 30070Sstevel@tonic-gate while ((entry = usba_rm_first_from_list( 30080Sstevel@tonic-gate &usba_device->usb_allocated)) != NULL) { 30090Sstevel@tonic-gate usba_req_wrapper_t *wrp; 30100Sstevel@tonic-gate 30110Sstevel@tonic-gate mutex_enter(&entry->list_mutex); 30120Sstevel@tonic-gate wrp = (usba_req_wrapper_t *)entry->private; 30130Sstevel@tonic-gate mutex_exit(&entry->list_mutex); 30140Sstevel@tonic-gate leaks++; 30150Sstevel@tonic-gate 3016978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, 30170Sstevel@tonic-gate usba_log_handle, 30180Sstevel@tonic-gate "%s%d: leaking request 0x%p", 30190Sstevel@tonic-gate ddi_driver_name(wrp->wr_dip), 30200Sstevel@tonic-gate ddi_get_instance(wrp->wr_dip), 30210Sstevel@tonic-gate wrp->wr_req); 30220Sstevel@tonic-gate 30230Sstevel@tonic-gate /* 30240Sstevel@tonic-gate * put it back, usba_req_wrapper_free 30250Sstevel@tonic-gate * expects it on the list 30260Sstevel@tonic-gate */ 30270Sstevel@tonic-gate usba_add_to_list(&usba_device->usb_allocated, 30280Sstevel@tonic-gate &wrp->wr_allocated_list); 30290Sstevel@tonic-gate 30300Sstevel@tonic-gate usba_req_wrapper_free(wrp); 30310Sstevel@tonic-gate } 30320Sstevel@tonic-gate } 30330Sstevel@tonic-gate 30340Sstevel@tonic-gate mutex_enter(&usba_device->usb_mutex); 30350Sstevel@tonic-gate for (iface = 0; iface < usba_device->usb_n_ifs; iface++) { 30360Sstevel@tonic-gate USB_DPRINTF_L3(DPRINT_MASK_USBA, usba_log_handle, 30370Sstevel@tonic-gate "usba_check_for_leaks: if=%d client_flags=0x%x", 30380Sstevel@tonic-gate iface, usba_device->usb_client_flags[iface]); 30390Sstevel@tonic-gate 30400Sstevel@tonic-gate if (usba_device->usb_client_flags[iface] & 30410Sstevel@tonic-gate USBA_CLIENT_FLAG_DEV_DATA) { 30420Sstevel@tonic-gate usb_client_dev_data_list_t *entry = 30430Sstevel@tonic-gate usba_device->usb_client_dev_data_list.cddl_next; 30440Sstevel@tonic-gate usb_client_dev_data_list_t *next; 30450Sstevel@tonic-gate usb_client_dev_data_t *dev_data; 30460Sstevel@tonic-gate 30470Sstevel@tonic-gate while (entry) { 30480Sstevel@tonic-gate dev_info_t *dip = entry->cddl_dip; 30490Sstevel@tonic-gate next = entry->cddl_next; 30500Sstevel@tonic-gate dev_data = entry->cddl_dev_data; 30510Sstevel@tonic-gate 30520Sstevel@tonic-gate 30531333Scth if (!i_ddi_devi_attached(dip)) { 3054978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, 30550Sstevel@tonic-gate usba_log_handle, 30560Sstevel@tonic-gate "%s%d: leaking dev_data 0x%p", 30570Sstevel@tonic-gate ddi_driver_name(dip), 30580Sstevel@tonic-gate ddi_get_instance(dip), 30590Sstevel@tonic-gate (void *)dev_data); 30600Sstevel@tonic-gate 30610Sstevel@tonic-gate leaks++; 30620Sstevel@tonic-gate 30630Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex); 30640Sstevel@tonic-gate usb_free_dev_data(dip, dev_data); 30650Sstevel@tonic-gate mutex_enter(&usba_device->usb_mutex); 30660Sstevel@tonic-gate } 30670Sstevel@tonic-gate 30680Sstevel@tonic-gate entry = next; 30690Sstevel@tonic-gate } 30700Sstevel@tonic-gate } 30710Sstevel@tonic-gate if (usba_device->usb_client_flags[iface] & 30720Sstevel@tonic-gate USBA_CLIENT_FLAG_ATTACH) { 30730Sstevel@tonic-gate dev_info_t *dip = usba_device-> 30740Sstevel@tonic-gate usb_client_attach_list[iface].dip; 30750Sstevel@tonic-gate 3076978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, 30770Sstevel@tonic-gate usba_log_handle, 30780Sstevel@tonic-gate "%s%d: did no usb_client_detach", 30790Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 30800Sstevel@tonic-gate leaks++; 30810Sstevel@tonic-gate 30820Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex); 30830Sstevel@tonic-gate usb_client_detach(dip, NULL); 30840Sstevel@tonic-gate mutex_enter(&usba_device->usb_mutex); 30850Sstevel@tonic-gate 30860Sstevel@tonic-gate usba_device-> 30870Sstevel@tonic-gate usb_client_attach_list[iface].dip = NULL; 30880Sstevel@tonic-gate 30890Sstevel@tonic-gate usba_device->usb_client_flags[iface] &= 30900Sstevel@tonic-gate ~USBA_CLIENT_FLAG_ATTACH; 30910Sstevel@tonic-gate 30920Sstevel@tonic-gate } 30930Sstevel@tonic-gate if (usba_device->usb_client_flags[iface] & 30940Sstevel@tonic-gate USBA_CLIENT_FLAG_EV_CBS) { 30950Sstevel@tonic-gate dev_info_t *dip = 30960Sstevel@tonic-gate usba_device->usb_client_ev_cb_list[iface]. 30970Sstevel@tonic-gate dip; 30980Sstevel@tonic-gate usb_event_t *ev_data = 30990Sstevel@tonic-gate usba_device->usb_client_ev_cb_list[iface]. 31000Sstevel@tonic-gate ev_data; 31010Sstevel@tonic-gate 3102978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, 31030Sstevel@tonic-gate usba_log_handle, 31040Sstevel@tonic-gate "%s%d: did no usb_unregister_event_cbs", 31050Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 31060Sstevel@tonic-gate leaks++; 31070Sstevel@tonic-gate 31080Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex); 31090Sstevel@tonic-gate usb_unregister_event_cbs(dip, ev_data); 31100Sstevel@tonic-gate mutex_enter(&usba_device->usb_mutex); 31110Sstevel@tonic-gate 31120Sstevel@tonic-gate usba_device->usb_client_ev_cb_list[iface]. 31130Sstevel@tonic-gate dip = NULL; 31140Sstevel@tonic-gate usba_device->usb_client_ev_cb_list[iface]. 31150Sstevel@tonic-gate ev_data = NULL; 31160Sstevel@tonic-gate usba_device->usb_client_flags[iface] &= 31170Sstevel@tonic-gate ~USBA_CLIENT_FLAG_EV_CBS; 31180Sstevel@tonic-gate } 31190Sstevel@tonic-gate } 31200Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex); 31210Sstevel@tonic-gate 31220Sstevel@tonic-gate if (leaks) { 3123978Sfrits USB_DPRINTF_L2(DPRINT_MASK_USBA, usba_log_handle, 31240Sstevel@tonic-gate "all %d leaks fixed", leaks); 31250Sstevel@tonic-gate } 31260Sstevel@tonic-gate } 3127