xref: /onnv-gate/usr/src/uts/common/io/usb/usba/hcdi.c (revision 7492:2387323b838f)
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
53341Sgc161489  * Common Development and Distribution License (the "License").
63341Sgc161489  * 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 /*
226898Sfb209375  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*
270Sstevel@tonic-gate  * USBA: Solaris USB Architecture support
280Sstevel@tonic-gate  *
290Sstevel@tonic-gate  * hcdi.c contains the code for client driver callbacks.  A host controller
300Sstevel@tonic-gate  * driver registers/unregisters with usba through usba_hcdi_register/unregister.
310Sstevel@tonic-gate  *
320Sstevel@tonic-gate  * When the transfer has finished, the host controller driver will call into
330Sstevel@tonic-gate  * usba with the result.  The call is usba_hcdi_cb().
340Sstevel@tonic-gate  *
350Sstevel@tonic-gate  * The callback queue is maintained in FIFO order.  usba_hcdi_cb
360Sstevel@tonic-gate  * adds to the queue, and hcdi_cb_thread takes the callbacks off the queue
370Sstevel@tonic-gate  * and executes them.
380Sstevel@tonic-gate  */
390Sstevel@tonic-gate #define	USBA_FRAMEWORK
400Sstevel@tonic-gate #include <sys/usb/usba/usba_impl.h>
410Sstevel@tonic-gate #include <sys/usb/usba/hcdi_impl.h>
420Sstevel@tonic-gate #include <sys/kstat.h>
430Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
440Sstevel@tonic-gate 
450Sstevel@tonic-gate /* function prototypes, XXXX use hcdi_ prefix?	*/
460Sstevel@tonic-gate static void usba_hcdi_create_stats(usba_hcdi_t *, int);
470Sstevel@tonic-gate static void usba_hcdi_update_error_stats(usba_hcdi_t *, usb_cr_t);
480Sstevel@tonic-gate static void usba_hcdi_destroy_stats(usba_hcdi_t *);
490Sstevel@tonic-gate 
500Sstevel@tonic-gate /* internal functions */
510Sstevel@tonic-gate static uint_t hcdi_soft_intr(caddr_t arg1, caddr_t arg2);
520Sstevel@tonic-gate 
530Sstevel@tonic-gate static void hcdi_cb_thread(void *);
540Sstevel@tonic-gate static void hcdi_shared_cb_thread(void *);
550Sstevel@tonic-gate static void hcdi_do_cb(usba_pipe_handle_data_t *, usba_req_wrapper_t *,
560Sstevel@tonic-gate 							usba_hcdi_t *);
570Sstevel@tonic-gate static void hcdi_autoclearing(usba_req_wrapper_t *);
580Sstevel@tonic-gate 
590Sstevel@tonic-gate /* private function from USBAI */
600Sstevel@tonic-gate void	usba_pipe_clear(usb_pipe_handle_t);
610Sstevel@tonic-gate 
620Sstevel@tonic-gate /* for debug messages */
63880Sfrits uint_t	hcdi_errmask	= (uint_t)DPRINT_MASK_ALL;
64880Sfrits uint_t	hcdi_errlevel	= USB_LOG_L4;
65880Sfrits uint_t	hcdi_instance_debug = (uint_t)-1;
660Sstevel@tonic-gate 
670Sstevel@tonic-gate void
usba_hcdi_initialization()680Sstevel@tonic-gate usba_hcdi_initialization()
690Sstevel@tonic-gate {
700Sstevel@tonic-gate }
710Sstevel@tonic-gate 
720Sstevel@tonic-gate 
730Sstevel@tonic-gate void
usba_hcdi_destroy()740Sstevel@tonic-gate usba_hcdi_destroy()
750Sstevel@tonic-gate {
760Sstevel@tonic-gate }
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 
790Sstevel@tonic-gate /*
800Sstevel@tonic-gate  * store hcdi structure in the dip
810Sstevel@tonic-gate  */
820Sstevel@tonic-gate void
usba_hcdi_set_hcdi(dev_info_t * dip,usba_hcdi_t * hcdi)830Sstevel@tonic-gate usba_hcdi_set_hcdi(dev_info_t *dip, usba_hcdi_t *hcdi)
840Sstevel@tonic-gate {
850Sstevel@tonic-gate 	ddi_set_driver_private(dip, hcdi);
860Sstevel@tonic-gate }
870Sstevel@tonic-gate 
880Sstevel@tonic-gate 
890Sstevel@tonic-gate /*
900Sstevel@tonic-gate  * retrieve hcdi structure from the dip
910Sstevel@tonic-gate  */
920Sstevel@tonic-gate usba_hcdi_t *
usba_hcdi_get_hcdi(dev_info_t * dip)930Sstevel@tonic-gate usba_hcdi_get_hcdi(dev_info_t *dip)
940Sstevel@tonic-gate {
950Sstevel@tonic-gate 	return (ddi_get_driver_private(dip));
960Sstevel@tonic-gate }
970Sstevel@tonic-gate 
980Sstevel@tonic-gate /*
990Sstevel@tonic-gate  * Called by an	HCD to attach an instance of the driver
1000Sstevel@tonic-gate  *	make this instance known to USBA
1010Sstevel@tonic-gate  *	the HCD	should initialize usba_hcdi structure prior
1020Sstevel@tonic-gate  *	to calling this	interface
1030Sstevel@tonic-gate  */
1040Sstevel@tonic-gate int
usba_hcdi_register(usba_hcdi_register_args_t * args,uint_t flags)1050Sstevel@tonic-gate usba_hcdi_register(usba_hcdi_register_args_t *args, uint_t flags)
1060Sstevel@tonic-gate {
1070Sstevel@tonic-gate 	char		*datap;
1080Sstevel@tonic-gate 	uint_t		soft_prip;
1090Sstevel@tonic-gate 	usba_hcdi_t	*hcdi = kmem_zalloc(sizeof (usba_hcdi_t), KM_SLEEP);
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 	if (args->usba_hcdi_register_version != HCDI_REGISTER_VERS_0) {
1120Sstevel@tonic-gate 		kmem_free(hcdi, sizeof (usba_hcdi_t));
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate 		return (USB_FAILURE);
1150Sstevel@tonic-gate 	}
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate 	hcdi->hcdi_dip = args->usba_hcdi_register_dip;
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate 	/*
1200Sstevel@tonic-gate 	 * Create a log_handle
1210Sstevel@tonic-gate 	 */
1220Sstevel@tonic-gate 	hcdi->hcdi_log_handle = usb_alloc_log_hdl(hcdi->hcdi_dip, NULL,
1236898Sfb209375 	    &hcdi_errlevel, &hcdi_errmask, &hcdi_instance_debug,
1246898Sfb209375 	    0);
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate 	USB_DPRINTF_L4(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
1270Sstevel@tonic-gate 	    "usba_hcdi_register: %s", ddi_node_name(hcdi->hcdi_dip));
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate 	/*
1300Sstevel@tonic-gate 	 * Initialize the mutex.  Use the iblock cookie passed in
1310Sstevel@tonic-gate 	 * by the host controller driver.
1320Sstevel@tonic-gate 	 */
1330Sstevel@tonic-gate 	mutex_init(&hcdi->hcdi_mutex, NULL, MUTEX_DRIVER,
1346898Sfb209375 	    args->usba_hcdi_register_iblock_cookie);
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate 	/* add soft interrupt */
1370Sstevel@tonic-gate 	if (ddi_intr_add_softint(hcdi->hcdi_dip, &hcdi->hcdi_softint_hdl,
1380Sstevel@tonic-gate 	    DDI_INTR_SOFTPRI_MAX, hcdi_soft_intr, (caddr_t)hcdi) !=
1390Sstevel@tonic-gate 	    DDI_SUCCESS) {
1400Sstevel@tonic-gate 		USB_DPRINTF_L2(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
1410Sstevel@tonic-gate 		    "usba_hcd_register: add soft interrupt failed");
1420Sstevel@tonic-gate 		mutex_destroy(&hcdi->hcdi_mutex);
1430Sstevel@tonic-gate 		usb_free_log_hdl(hcdi->hcdi_log_handle);
1440Sstevel@tonic-gate 		kmem_free(hcdi, sizeof (usba_hcdi_t));
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate 		return (USB_FAILURE);
1470Sstevel@tonic-gate 	}
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate 	if (ddi_intr_get_softint_pri(hcdi->hcdi_softint_hdl, &soft_prip) !=
1500Sstevel@tonic-gate 	    DDI_SUCCESS) {
1510Sstevel@tonic-gate 		USB_DPRINTF_L2(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
1520Sstevel@tonic-gate 		    "usba_hcd_register: get soft interrupt priority failed");
1530Sstevel@tonic-gate 		(void) ddi_intr_remove_softint(hcdi->hcdi_softint_hdl);
1540Sstevel@tonic-gate 		mutex_destroy(&hcdi->hcdi_mutex);
1550Sstevel@tonic-gate 		usb_free_log_hdl(hcdi->hcdi_log_handle);
1560Sstevel@tonic-gate 		kmem_free(hcdi, sizeof (usba_hcdi_t));
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate 		return (USB_FAILURE);
1590Sstevel@tonic-gate 	}
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate 	/*
1620Sstevel@tonic-gate 	 * Priority and iblock_cookie are one and the same
1630Sstevel@tonic-gate 	 * (However, retaining hcdi_soft_iblock_cookie for now
1640Sstevel@tonic-gate 	 * assigning it w/ priority. In future all iblock_cookie
1650Sstevel@tonic-gate 	 * could just go)
1660Sstevel@tonic-gate 	 */
1670Sstevel@tonic-gate 	hcdi->hcdi_soft_iblock_cookie =
16842Sagiri 	    (ddi_iblock_cookie_t)(uintptr_t)soft_prip;
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate 	usba_init_list(&hcdi->hcdi_cb_queue, NULL, NULL);
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate 	hcdi->hcdi_dma_attr	= args->usba_hcdi_register_dma_attr;
1730Sstevel@tonic-gate 	hcdi->hcdi_flags	= flags;
1740Sstevel@tonic-gate 	hcdi->hcdi_ops		= args->usba_hcdi_register_ops;
1750Sstevel@tonic-gate 	hcdi->hcdi_iblock_cookie = args->usba_hcdi_register_iblock_cookie;
1760Sstevel@tonic-gate 	usba_hcdi_create_stats(hcdi, ddi_get_instance(hcdi->hcdi_dip));
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate 	hcdi->hcdi_min_xfer	= hcdi->hcdi_dma_attr->dma_attr_minxfer;
1790Sstevel@tonic-gate 	hcdi->hcdi_min_burst_size =
1806898Sfb209375 	    (1<<(ddi_ffs(hcdi->hcdi_dma_attr->dma_attr_burstsizes)-1));
1810Sstevel@tonic-gate 	hcdi->hcdi_max_burst_size =
1826898Sfb209375 	    (1<<(ddi_fls(hcdi->hcdi_dma_attr->dma_attr_burstsizes)-1));
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate 	usba_hcdi_set_hcdi(hcdi->hcdi_dip, hcdi);
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate 	if (ddi_prop_lookup_string(DDI_DEV_T_ANY,
1870Sstevel@tonic-gate 	    hcdi->hcdi_dip,
1880Sstevel@tonic-gate 	    DDI_PROP_DONTPASS, "ugen-default-binding", &datap) ==
1890Sstevel@tonic-gate 	    DDI_PROP_SUCCESS) {
1900Sstevel@tonic-gate 		if (strcmp(datap, "device") == 0) {
1910Sstevel@tonic-gate 			hcdi->hcdi_ugen_default_binding =
1920Sstevel@tonic-gate 			    USBA_UGEN_DEVICE_BINDING;
1930Sstevel@tonic-gate 		} else if (strcmp(datap, "interface") == 0) {
1940Sstevel@tonic-gate 			hcdi->hcdi_ugen_default_binding =
1950Sstevel@tonic-gate 			    USBA_UGEN_INTERFACE_BINDING;
1963341Sgc161489 		} else if (strcmp(datap, "interface-association") == 0) {
1973341Sgc161489 			hcdi->hcdi_ugen_default_binding =
1983341Sgc161489 			    USBA_UGEN_INTERFACE_ASSOCIATION_BINDING;
1990Sstevel@tonic-gate 		} else {
200978Sfrits 			USB_DPRINTF_L2(DPRINT_MASK_HCDI,
2010Sstevel@tonic-gate 			    hcdi->hcdi_log_handle,
2020Sstevel@tonic-gate 			    "illegal value (%s) for "
2030Sstevel@tonic-gate 			    "ugen_default_binding property",
2040Sstevel@tonic-gate 			    datap);
2050Sstevel@tonic-gate 		}
2060Sstevel@tonic-gate 		ddi_prop_free(datap);
2070Sstevel@tonic-gate 	}
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate 	return (USB_SUCCESS);
2100Sstevel@tonic-gate }
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate 
2130Sstevel@tonic-gate /*
2140Sstevel@tonic-gate  * Called by an	HCD to detach an instance of the driver
2150Sstevel@tonic-gate  */
2160Sstevel@tonic-gate /*ARGSUSED*/
2170Sstevel@tonic-gate void
usba_hcdi_unregister(dev_info_t * dip)2180Sstevel@tonic-gate usba_hcdi_unregister(dev_info_t *dip)
2190Sstevel@tonic-gate {
2200Sstevel@tonic-gate 	usba_hcdi_t *hcdi = usba_hcdi_get_hcdi(dip);
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate 	if (hcdi) {
2230Sstevel@tonic-gate 		USB_DPRINTF_L4(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
2240Sstevel@tonic-gate 		    "usba_hcdi_unregister: %s", ddi_node_name(dip));
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate 		usba_hcdi_set_hcdi(dip, NULL);
2270Sstevel@tonic-gate 
2280Sstevel@tonic-gate 		mutex_destroy(&hcdi->hcdi_mutex);
2290Sstevel@tonic-gate 		usba_hcdi_destroy_stats(hcdi);
2300Sstevel@tonic-gate 		usb_free_log_hdl(hcdi->hcdi_log_handle);
2310Sstevel@tonic-gate 
2320Sstevel@tonic-gate 		/* Destroy the soft interrupt */
2330Sstevel@tonic-gate 		(void) ddi_intr_remove_softint(hcdi->hcdi_softint_hdl);
2340Sstevel@tonic-gate 		kmem_free(hcdi, sizeof (usba_hcdi_t));
2350Sstevel@tonic-gate 	}
2360Sstevel@tonic-gate }
2370Sstevel@tonic-gate 
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate /*
2400Sstevel@tonic-gate  * alloc usba_hcdi_ops structure
2410Sstevel@tonic-gate  *	called from the HCD attach routine
2420Sstevel@tonic-gate  */
2430Sstevel@tonic-gate usba_hcdi_ops_t *
usba_alloc_hcdi_ops()2440Sstevel@tonic-gate usba_alloc_hcdi_ops()
2450Sstevel@tonic-gate {
2460Sstevel@tonic-gate 	usba_hcdi_ops_t	*usba_hcdi_ops;
2470Sstevel@tonic-gate 
2480Sstevel@tonic-gate 	usba_hcdi_ops = kmem_zalloc(sizeof (usba_hcdi_ops_t), KM_SLEEP);
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate 	return (usba_hcdi_ops);
2510Sstevel@tonic-gate }
2520Sstevel@tonic-gate 
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate /*
2550Sstevel@tonic-gate  * dealloc usba_hcdi_ops structure
2560Sstevel@tonic-gate  */
2570Sstevel@tonic-gate void
usba_free_hcdi_ops(usba_hcdi_ops_t * hcdi_ops)2580Sstevel@tonic-gate usba_free_hcdi_ops(usba_hcdi_ops_t *hcdi_ops)
2590Sstevel@tonic-gate {
2600Sstevel@tonic-gate 	if (hcdi_ops) {
2610Sstevel@tonic-gate 		kmem_free(hcdi_ops, sizeof (usba_hcdi_ops_t));
2620Sstevel@tonic-gate 	}
2630Sstevel@tonic-gate }
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate 
2660Sstevel@tonic-gate /*
2670Sstevel@tonic-gate  * Allocate the hotplug kstats structure
2680Sstevel@tonic-gate  */
2690Sstevel@tonic-gate void
usba_hcdi_create_stats(usba_hcdi_t * hcdi,int instance)2700Sstevel@tonic-gate usba_hcdi_create_stats(usba_hcdi_t *hcdi, int instance)
2710Sstevel@tonic-gate {
2720Sstevel@tonic-gate 	char			kstatname[KSTAT_STRLEN];
2730Sstevel@tonic-gate 	const char		*dname = ddi_driver_name(hcdi->hcdi_dip);
2740Sstevel@tonic-gate 	hcdi_hotplug_stats_t	*hsp;
2750Sstevel@tonic-gate 	hcdi_error_stats_t	*esp;
2760Sstevel@tonic-gate 
2770Sstevel@tonic-gate 	if (HCDI_HOTPLUG_STATS(hcdi) == NULL) {
2780Sstevel@tonic-gate 		(void) snprintf(kstatname, KSTAT_STRLEN, "%s%d,hotplug",
2790Sstevel@tonic-gate 		    dname, instance);
2800Sstevel@tonic-gate 		HCDI_HOTPLUG_STATS(hcdi) = kstat_create("usba", instance,
2810Sstevel@tonic-gate 		    kstatname, "usb_hotplug", KSTAT_TYPE_NAMED,
2820Sstevel@tonic-gate 		    sizeof (hcdi_hotplug_stats_t) / sizeof (kstat_named_t),
2830Sstevel@tonic-gate 		    KSTAT_FLAG_PERSISTENT);
2840Sstevel@tonic-gate 
2850Sstevel@tonic-gate 		if (HCDI_HOTPLUG_STATS(hcdi) == NULL) {
2860Sstevel@tonic-gate 
2870Sstevel@tonic-gate 			return;
2880Sstevel@tonic-gate 		}
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate 		hsp = HCDI_HOTPLUG_STATS_DATA(hcdi);
2910Sstevel@tonic-gate 		kstat_named_init(&hsp->hcdi_hotplug_total_success,
2920Sstevel@tonic-gate 		    "Total Hotplug Successes", KSTAT_DATA_UINT64);
2930Sstevel@tonic-gate 		kstat_named_init(&hsp->hcdi_hotplug_success,
2940Sstevel@tonic-gate 		    "Hotplug Successes", KSTAT_DATA_UINT64);
2950Sstevel@tonic-gate 		kstat_named_init(&hsp->hcdi_hotplug_total_failure,
2960Sstevel@tonic-gate 		    "Hotplug Total Failures", KSTAT_DATA_UINT64);
2970Sstevel@tonic-gate 		kstat_named_init(&hsp->hcdi_hotplug_failure,
2980Sstevel@tonic-gate 		    "Hotplug Failures", KSTAT_DATA_UINT64);
2990Sstevel@tonic-gate 		kstat_named_init(&hsp->hcdi_device_count,
3000Sstevel@tonic-gate 		    "Device Count", KSTAT_DATA_UINT64);
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate 		HCDI_HOTPLUG_STATS(hcdi)->ks_private = hcdi;
3030Sstevel@tonic-gate 		HCDI_HOTPLUG_STATS(hcdi)->ks_update = nulldev;
3040Sstevel@tonic-gate 		kstat_install(HCDI_HOTPLUG_STATS(hcdi));
3050Sstevel@tonic-gate 	}
3060Sstevel@tonic-gate 
3070Sstevel@tonic-gate 	if (HCDI_ERROR_STATS(hcdi) == NULL) {
3080Sstevel@tonic-gate 		(void) snprintf(kstatname, KSTAT_STRLEN, "%s%d,error",
3090Sstevel@tonic-gate 		    dname, instance);
3100Sstevel@tonic-gate 		HCDI_ERROR_STATS(hcdi) = kstat_create("usba", instance,
3110Sstevel@tonic-gate 		    kstatname, "usb_errors", KSTAT_TYPE_NAMED,
3120Sstevel@tonic-gate 		    sizeof (hcdi_error_stats_t) / sizeof (kstat_named_t),
3130Sstevel@tonic-gate 		    KSTAT_FLAG_PERSISTENT);
3140Sstevel@tonic-gate 
3150Sstevel@tonic-gate 		if (HCDI_ERROR_STATS(hcdi) == NULL) {
3160Sstevel@tonic-gate 
3170Sstevel@tonic-gate 			return;
3180Sstevel@tonic-gate 		}
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate 		esp = HCDI_ERROR_STATS_DATA(hcdi);
3210Sstevel@tonic-gate 		kstat_named_init(&esp->cc_crc, "CRC Errors", KSTAT_DATA_UINT64);
3220Sstevel@tonic-gate 		kstat_named_init(&esp->cc_bitstuffing,
3230Sstevel@tonic-gate 		    "Bit Stuffing Violations", KSTAT_DATA_UINT64);
3240Sstevel@tonic-gate 		kstat_named_init(&esp->cc_data_toggle_mm,
3250Sstevel@tonic-gate 		    "Data Toggle PID Errors", KSTAT_DATA_UINT64);
3260Sstevel@tonic-gate 		kstat_named_init(&esp->cc_stall,
3270Sstevel@tonic-gate 		    "Endpoint Stalls", KSTAT_DATA_UINT64);
3280Sstevel@tonic-gate 		kstat_named_init(&esp->cc_dev_not_resp,
3290Sstevel@tonic-gate 		    "Device Not Responding", KSTAT_DATA_UINT64);
3300Sstevel@tonic-gate 		kstat_named_init(&esp->cc_pid_checkfailure,
3310Sstevel@tonic-gate 		    "PID Check Bit Errors", KSTAT_DATA_UINT64);
3320Sstevel@tonic-gate 		kstat_named_init(&esp->cc_unexp_pid,
3330Sstevel@tonic-gate 		    "Invalid PID Errors", KSTAT_DATA_UINT64);
3340Sstevel@tonic-gate 		kstat_named_init(&esp->cc_data_overrun,
3350Sstevel@tonic-gate 		    "Data Overruns", KSTAT_DATA_UINT64);
3360Sstevel@tonic-gate 		kstat_named_init(&esp->cc_data_underrun,
3370Sstevel@tonic-gate 		    "Data Underruns", KSTAT_DATA_UINT64);
3380Sstevel@tonic-gate 		kstat_named_init(&esp->cc_buffer_overrun,
3390Sstevel@tonic-gate 		    "Buffer Overruns", KSTAT_DATA_UINT64);
3400Sstevel@tonic-gate 		kstat_named_init(&esp->cc_buffer_underrun,
3410Sstevel@tonic-gate 		    "Buffer Underruns", KSTAT_DATA_UINT64);
3420Sstevel@tonic-gate 		kstat_named_init(&esp->cc_timeout,
3430Sstevel@tonic-gate 		    "Command Timed Out", KSTAT_DATA_UINT64);
3440Sstevel@tonic-gate 		kstat_named_init(&esp->cc_not_accessed,
3450Sstevel@tonic-gate 		    "Not Accessed By Hardware", KSTAT_DATA_UINT64);
3460Sstevel@tonic-gate 		kstat_named_init(&esp->cc_unspecified_err,
3470Sstevel@tonic-gate 		    "Unspecified Error", KSTAT_DATA_UINT64);
3480Sstevel@tonic-gate #ifdef	NOTYETNEEDED
3490Sstevel@tonic-gate 		kstat_named_init(&esp->hcdi_usb_failure,
3500Sstevel@tonic-gate 		    "USB Failure", KSTAT_DATA_UINT64);
3510Sstevel@tonic-gate 		kstat_named_init(&esp->hcdi_usb_no_resources,
3520Sstevel@tonic-gate 		    "No Resources", KSTAT_DATA_UINT64);
3530Sstevel@tonic-gate 		kstat_named_init(&esp->hcdi_usb_no_bandwidth,
3540Sstevel@tonic-gate 		    "No Bandwidth", KSTAT_DATA_UINT64);
3550Sstevel@tonic-gate 		kstat_named_init(&esp->hcdi_usb_pipe_reserved,
3560Sstevel@tonic-gate 		    "Pipe Reserved", KSTAT_DATA_UINT64);
3570Sstevel@tonic-gate 		kstat_named_init(&esp->hcdi_usb_pipe_unshareable,
3580Sstevel@tonic-gate 		    "Pipe Unshareable", KSTAT_DATA_UINT64);
3590Sstevel@tonic-gate 		kstat_named_init(&esp->hcdi_usb_not_supported,
3600Sstevel@tonic-gate 		    "Function Not Supported", KSTAT_DATA_UINT64);
3610Sstevel@tonic-gate 		kstat_named_init(&esp->hcdi_usb_pipe_error,
3620Sstevel@tonic-gate 		    "Pipe Error", KSTAT_DATA_UINT64);
3630Sstevel@tonic-gate 		kstat_named_init(&esp->hcdi_usb_pipe_busy,
3640Sstevel@tonic-gate 		    "Pipe Busy", KSTAT_DATA_UINT64);
3650Sstevel@tonic-gate #endif
3660Sstevel@tonic-gate 
3670Sstevel@tonic-gate 		HCDI_ERROR_STATS(hcdi)->ks_private = hcdi;
3680Sstevel@tonic-gate 		HCDI_ERROR_STATS(hcdi)->ks_update = nulldev;
3690Sstevel@tonic-gate 		kstat_install(HCDI_ERROR_STATS(hcdi));
3700Sstevel@tonic-gate 	}
3710Sstevel@tonic-gate }
3720Sstevel@tonic-gate 
3730Sstevel@tonic-gate 
3740Sstevel@tonic-gate /*
3750Sstevel@tonic-gate  * Do actual error stats
3760Sstevel@tonic-gate  */
3770Sstevel@tonic-gate void
usba_hcdi_update_error_stats(usba_hcdi_t * hcdi,usb_cr_t completion_reason)3780Sstevel@tonic-gate usba_hcdi_update_error_stats(usba_hcdi_t *hcdi, usb_cr_t completion_reason)
3790Sstevel@tonic-gate {
3800Sstevel@tonic-gate 	if (HCDI_ERROR_STATS(hcdi) == NULL) {
3810Sstevel@tonic-gate 
3820Sstevel@tonic-gate 		return;
3830Sstevel@tonic-gate 	}
3840Sstevel@tonic-gate 
3850Sstevel@tonic-gate 	switch (completion_reason) {
3860Sstevel@tonic-gate 	case USB_CR_OK:
3870Sstevel@tonic-gate 		break;
3880Sstevel@tonic-gate 	case USB_CR_CRC:
3890Sstevel@tonic-gate 		HCDI_ERROR_STATS_DATA(hcdi)->cc_crc.value.ui64++;
3900Sstevel@tonic-gate 		break;
3910Sstevel@tonic-gate 	case USB_CR_BITSTUFFING:
3920Sstevel@tonic-gate 		HCDI_ERROR_STATS_DATA(hcdi)->cc_bitstuffing.value.ui64++;
3930Sstevel@tonic-gate 		break;
3940Sstevel@tonic-gate 	case USB_CR_DATA_TOGGLE_MM:
3950Sstevel@tonic-gate 		HCDI_ERROR_STATS_DATA(hcdi)->cc_data_toggle_mm.value.ui64++;
3960Sstevel@tonic-gate 		break;
3970Sstevel@tonic-gate 	case USB_CR_STALL:
3980Sstevel@tonic-gate 		HCDI_ERROR_STATS_DATA(hcdi)->cc_stall.value.ui64++;
3990Sstevel@tonic-gate 		break;
4000Sstevel@tonic-gate 	case USB_CR_DEV_NOT_RESP:
4010Sstevel@tonic-gate 		HCDI_ERROR_STATS_DATA(hcdi)->cc_dev_not_resp.value.ui64++;
4020Sstevel@tonic-gate 		break;
4030Sstevel@tonic-gate 	case USB_CR_PID_CHECKFAILURE:
4040Sstevel@tonic-gate 		HCDI_ERROR_STATS_DATA(hcdi)->cc_pid_checkfailure.value.ui64++;
4050Sstevel@tonic-gate 		break;
4060Sstevel@tonic-gate 	case USB_CR_UNEXP_PID:
4070Sstevel@tonic-gate 		HCDI_ERROR_STATS_DATA(hcdi)->cc_unexp_pid.value.ui64++;
4080Sstevel@tonic-gate 		break;
4090Sstevel@tonic-gate 	case USB_CR_DATA_OVERRUN:
4100Sstevel@tonic-gate 		HCDI_ERROR_STATS_DATA(hcdi)->cc_data_overrun.value.ui64++;
4110Sstevel@tonic-gate 		break;
4120Sstevel@tonic-gate 	case USB_CR_DATA_UNDERRUN:
4130Sstevel@tonic-gate 		HCDI_ERROR_STATS_DATA(hcdi)->cc_data_underrun.value.ui64++;
4140Sstevel@tonic-gate 		break;
4150Sstevel@tonic-gate 	case USB_CR_BUFFER_OVERRUN:
4160Sstevel@tonic-gate 		HCDI_ERROR_STATS_DATA(hcdi)->cc_buffer_overrun.value.ui64++;
4170Sstevel@tonic-gate 		break;
4180Sstevel@tonic-gate 	case USB_CR_BUFFER_UNDERRUN:
4190Sstevel@tonic-gate 		HCDI_ERROR_STATS_DATA(hcdi)->cc_buffer_underrun.value.ui64++;
4200Sstevel@tonic-gate 		break;
4210Sstevel@tonic-gate 	case USB_CR_TIMEOUT:
4220Sstevel@tonic-gate 		HCDI_ERROR_STATS_DATA(hcdi)->cc_timeout.value.ui64++;
4230Sstevel@tonic-gate 		break;
4240Sstevel@tonic-gate 	case USB_CR_NOT_ACCESSED:
4250Sstevel@tonic-gate 		HCDI_ERROR_STATS_DATA(hcdi)->cc_not_accessed.value.ui64++;
4260Sstevel@tonic-gate 		break;
4270Sstevel@tonic-gate 	case USB_CR_NO_RESOURCES:
4280Sstevel@tonic-gate 		HCDI_ERROR_STATS_DATA(hcdi)->cc_no_resources.value.ui64++;
4290Sstevel@tonic-gate 		break;
4300Sstevel@tonic-gate 	case USB_CR_UNSPECIFIED_ERR:
4310Sstevel@tonic-gate 		HCDI_ERROR_STATS_DATA(hcdi)->cc_unspecified_err.value.ui64++;
4320Sstevel@tonic-gate 		break;
4330Sstevel@tonic-gate 	case USB_CR_STOPPED_POLLING:
4340Sstevel@tonic-gate 		HCDI_ERROR_STATS_DATA(hcdi)->cc_stopped_polling.value.ui64++;
4350Sstevel@tonic-gate 		break;
4360Sstevel@tonic-gate 	case USB_CR_PIPE_CLOSING:
4370Sstevel@tonic-gate 		HCDI_ERROR_STATS_DATA(hcdi)->cc_pipe_closing.value.ui64++;
4380Sstevel@tonic-gate 		break;
4390Sstevel@tonic-gate 	case USB_CR_PIPE_RESET:
4400Sstevel@tonic-gate 		HCDI_ERROR_STATS_DATA(hcdi)->cc_pipe_reset.value.ui64++;
4410Sstevel@tonic-gate 		break;
4420Sstevel@tonic-gate 	case USB_CR_NOT_SUPPORTED:
4430Sstevel@tonic-gate 		HCDI_ERROR_STATS_DATA(hcdi)->cc_not_supported.value.ui64++;
4440Sstevel@tonic-gate 		break;
4450Sstevel@tonic-gate 	case USB_CR_FLUSHED:
4460Sstevel@tonic-gate 		HCDI_ERROR_STATS_DATA(hcdi)->cc_flushed.value.ui64++;
4470Sstevel@tonic-gate 		break;
4480Sstevel@tonic-gate 	default:
4490Sstevel@tonic-gate 		break;
4500Sstevel@tonic-gate 	}
4510Sstevel@tonic-gate }
4520Sstevel@tonic-gate 
4530Sstevel@tonic-gate 
4540Sstevel@tonic-gate /*
4550Sstevel@tonic-gate  * Destroy the hotplug kstats structure
4560Sstevel@tonic-gate  */
4570Sstevel@tonic-gate static void
usba_hcdi_destroy_stats(usba_hcdi_t * hcdi)4580Sstevel@tonic-gate usba_hcdi_destroy_stats(usba_hcdi_t *hcdi)
4590Sstevel@tonic-gate {
4600Sstevel@tonic-gate 	if (HCDI_HOTPLUG_STATS(hcdi)) {
4610Sstevel@tonic-gate 		kstat_delete(HCDI_HOTPLUG_STATS(hcdi));
4620Sstevel@tonic-gate 		HCDI_HOTPLUG_STATS(hcdi) = NULL;
4630Sstevel@tonic-gate 	}
4640Sstevel@tonic-gate 
4650Sstevel@tonic-gate 	if (HCDI_ERROR_STATS(hcdi)) {
4660Sstevel@tonic-gate 		kstat_delete(HCDI_ERROR_STATS(hcdi));
4670Sstevel@tonic-gate 		HCDI_ERROR_STATS(hcdi) = NULL;
4680Sstevel@tonic-gate 	}
4690Sstevel@tonic-gate }
4700Sstevel@tonic-gate 
4710Sstevel@tonic-gate 
4720Sstevel@tonic-gate /*
4730Sstevel@tonic-gate  * HCD callback handling
4740Sstevel@tonic-gate  */
4750Sstevel@tonic-gate void
usba_hcdi_cb(usba_pipe_handle_data_t * ph_data,usb_opaque_t req,usb_cr_t completion_reason)4760Sstevel@tonic-gate usba_hcdi_cb(usba_pipe_handle_data_t *ph_data,
4770Sstevel@tonic-gate 	usb_opaque_t	req,
4780Sstevel@tonic-gate 	usb_cr_t	completion_reason)
4790Sstevel@tonic-gate {
4800Sstevel@tonic-gate 
4810Sstevel@tonic-gate 	usba_device_t		*usba_device = ph_data->p_usba_device;
4820Sstevel@tonic-gate 	usba_hcdi_t		*hcdi =	usba_hcdi_get_hcdi(
4836898Sfb209375 	    usba_device->usb_root_hub_dip);
4840Sstevel@tonic-gate 	usba_req_wrapper_t	*req_wrp = USBA_REQ2WRP(req);
4850Sstevel@tonic-gate 	usb_ep_descr_t		*eptd = &ph_data->p_ep;
4860Sstevel@tonic-gate 
4870Sstevel@tonic-gate 	mutex_enter(&ph_data->p_mutex);
4880Sstevel@tonic-gate 
4890Sstevel@tonic-gate #ifdef DEBUG
4900Sstevel@tonic-gate 	mutex_enter(&ph_data->p_ph_impl->usba_ph_mutex);
4910Sstevel@tonic-gate 
4920Sstevel@tonic-gate 	USB_DPRINTF_L4(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
4930Sstevel@tonic-gate 	    "usba_hcdi_cb: "
4940Sstevel@tonic-gate 	    "ph_data=0x%p req=0x%p state=%d ref=%d cnt=%d cr=%d",
4956898Sfb209375 	    (void *)ph_data, (void *)req, ph_data->p_ph_impl->usba_ph_state,
4960Sstevel@tonic-gate 	    ph_data->p_ph_impl->usba_ph_ref_count, ph_data->p_req_count,
4970Sstevel@tonic-gate 	    completion_reason);
4980Sstevel@tonic-gate 
4990Sstevel@tonic-gate 	mutex_exit(&ph_data->p_ph_impl->usba_ph_mutex);
5000Sstevel@tonic-gate #endif
5010Sstevel@tonic-gate 
5020Sstevel@tonic-gate 	/* Set the completion reason */
5030Sstevel@tonic-gate 	switch (eptd->bmAttributes & USB_EP_ATTR_MASK) {
5040Sstevel@tonic-gate 	case USB_EP_ATTR_CONTROL:
5050Sstevel@tonic-gate 		((usb_ctrl_req_t *)req)->
5060Sstevel@tonic-gate 		    ctrl_completion_reason = completion_reason;
5070Sstevel@tonic-gate 		break;
5080Sstevel@tonic-gate 	case USB_EP_ATTR_BULK:
5090Sstevel@tonic-gate 		((usb_bulk_req_t *)req)->
5100Sstevel@tonic-gate 		    bulk_completion_reason = completion_reason;
5110Sstevel@tonic-gate 		break;
5120Sstevel@tonic-gate 	case USB_EP_ATTR_INTR:
5130Sstevel@tonic-gate 		((usb_intr_req_t *)req)->
5140Sstevel@tonic-gate 		    intr_completion_reason = completion_reason;
5150Sstevel@tonic-gate 		break;
5160Sstevel@tonic-gate 	case USB_EP_ATTR_ISOCH:
5170Sstevel@tonic-gate 		((usb_isoc_req_t *)req)->
5180Sstevel@tonic-gate 		    isoc_completion_reason = completion_reason;
5190Sstevel@tonic-gate 		break;
5200Sstevel@tonic-gate 	}
5210Sstevel@tonic-gate 
5220Sstevel@tonic-gate 	/*
5230Sstevel@tonic-gate 	 * exception callbacks will still go thru a taskq thread
5240Sstevel@tonic-gate 	 * but should occur after the soft interrupt callback
5250Sstevel@tonic-gate 	 * By design of periodic pipes, polling will stop on any
5260Sstevel@tonic-gate 	 * exception
5270Sstevel@tonic-gate 	 */
5280Sstevel@tonic-gate 	if ((ph_data->p_spec_flag & USBA_PH_FLAG_USE_SOFT_INTR) &&
5290Sstevel@tonic-gate 	    (completion_reason == USB_CR_OK)) {
5300Sstevel@tonic-gate 		ph_data->p_soft_intr++;
5310Sstevel@tonic-gate 		mutex_exit(&ph_data->p_mutex);
5320Sstevel@tonic-gate 
5330Sstevel@tonic-gate 		usba_add_to_list(&hcdi->hcdi_cb_queue, &req_wrp->wr_queue);
5340Sstevel@tonic-gate 
5350Sstevel@tonic-gate 		if (ddi_intr_trigger_softint(hcdi->hcdi_softint_hdl, NULL) !=
5360Sstevel@tonic-gate 		    DDI_SUCCESS)
5370Sstevel@tonic-gate 			USB_DPRINTF_L2(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
5380Sstevel@tonic-gate 			    "usba_hcdi_cb: ddi_intr_trigger_softint  failed");
5390Sstevel@tonic-gate 
5400Sstevel@tonic-gate 		return;
5410Sstevel@tonic-gate 	}
5420Sstevel@tonic-gate 
5430Sstevel@tonic-gate 	/*
5440Sstevel@tonic-gate 	 * USBA_PH_FLAG_TQ_SHARE is for bulk and intr requests,
5450Sstevel@tonic-gate 	 * USBA_PH_FLAG_USE_SOFT_INTR is only for isoch,
5460Sstevel@tonic-gate 	 * so there are no conflicts.
5470Sstevel@tonic-gate 	 */
5480Sstevel@tonic-gate 	if (ph_data->p_spec_flag & USBA_PH_FLAG_TQ_SHARE) {
5490Sstevel@tonic-gate 		int iface;
5500Sstevel@tonic-gate 
5510Sstevel@tonic-gate 		mutex_exit(&ph_data->p_mutex);
5520Sstevel@tonic-gate 		iface = usb_get_if_number(ph_data->p_dip);
5530Sstevel@tonic-gate 		if (iface < 0) {
5540Sstevel@tonic-gate 			/* we own the device, use the first taskq */
5550Sstevel@tonic-gate 			iface = 0;
5560Sstevel@tonic-gate 		}
5570Sstevel@tonic-gate 		if (taskq_dispatch(usba_device->usb_shared_taskq[iface],
5580Sstevel@tonic-gate 		    hcdi_shared_cb_thread, req_wrp, TQ_NOSLEEP) ==
5590Sstevel@tonic-gate 		    NULL) {
5600Sstevel@tonic-gate 			usba_req_exc_cb(req_wrp,
5610Sstevel@tonic-gate 			    USB_CR_NO_RESOURCES, USB_CB_ASYNC_REQ_FAILED);
5620Sstevel@tonic-gate 		}
5630Sstevel@tonic-gate 
5640Sstevel@tonic-gate 		return;
5650Sstevel@tonic-gate 	}
5660Sstevel@tonic-gate 
5670Sstevel@tonic-gate 	/* Add the callback to the pipehandles callback list */
5680Sstevel@tonic-gate 	usba_add_to_list(&ph_data->p_cb_queue, &req_wrp->wr_queue);
5690Sstevel@tonic-gate 
5700Sstevel@tonic-gate 	/* only dispatch if there is no thread running */
5710Sstevel@tonic-gate 	if (ph_data->p_thread_id == 0) {
5720Sstevel@tonic-gate 		if (usba_async_ph_req(ph_data, hcdi_cb_thread,
5730Sstevel@tonic-gate 		    ph_data, USB_FLAGS_NOSLEEP) != USB_SUCCESS) {
5740Sstevel@tonic-gate 			USB_DPRINTF_L2(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
5750Sstevel@tonic-gate 			    "usba_hcdi_cb: taskq_dispatch failed");
5760Sstevel@tonic-gate 			if (usba_rm_from_list(&ph_data->p_cb_queue,
5770Sstevel@tonic-gate 			    &req_wrp->wr_queue) == USB_SUCCESS) {
5780Sstevel@tonic-gate 				mutex_exit(&ph_data->p_mutex);
5790Sstevel@tonic-gate 				usba_req_exc_cb(req_wrp,
5800Sstevel@tonic-gate 				    USB_CR_NO_RESOURCES,
5810Sstevel@tonic-gate 				    USB_CB_ASYNC_REQ_FAILED);
5820Sstevel@tonic-gate 
5830Sstevel@tonic-gate 				return;
5840Sstevel@tonic-gate 			}
5850Sstevel@tonic-gate 		} else {
5860Sstevel@tonic-gate 			ph_data->p_thread_id = (kthread_t *)1;
5870Sstevel@tonic-gate 		}
5880Sstevel@tonic-gate 	}
5890Sstevel@tonic-gate 	mutex_exit(&ph_data->p_mutex);
5900Sstevel@tonic-gate }
5910Sstevel@tonic-gate 
5920Sstevel@tonic-gate 
5930Sstevel@tonic-gate /*
5940Sstevel@tonic-gate  * thread to perform the callbacks
5950Sstevel@tonic-gate  */
5960Sstevel@tonic-gate static void
hcdi_cb_thread(void * arg)5970Sstevel@tonic-gate hcdi_cb_thread(void *arg)
5980Sstevel@tonic-gate {
5990Sstevel@tonic-gate 	usba_pipe_handle_data_t	*ph_data =
6006898Sfb209375 	    (usba_pipe_handle_data_t *)arg;
6010Sstevel@tonic-gate 	usba_ph_impl_t		*ph_impl = ph_data->p_ph_impl;
6020Sstevel@tonic-gate 	usba_hcdi_t		*hcdi = usba_hcdi_get_hcdi(ph_data->
6036898Sfb209375 	    p_usba_device->usb_root_hub_dip);
6040Sstevel@tonic-gate 	usba_req_wrapper_t	*req_wrp;
6050Sstevel@tonic-gate 
6060Sstevel@tonic-gate 	mutex_enter(&ph_data->p_mutex);
6070Sstevel@tonic-gate 	ASSERT(ph_data->p_thread_id == (kthread_t *)1);
6080Sstevel@tonic-gate 	ph_data->p_thread_id = curthread;
6090Sstevel@tonic-gate 
6100Sstevel@tonic-gate 	/*
6110Sstevel@tonic-gate 	 * hold the ph_data. we can't use usba_hold_ph_data() since
6120Sstevel@tonic-gate 	 * it will return NULL if we are closing the pipe which would
6130Sstevel@tonic-gate 	 * then leave all requests stuck in the cb_queue
6140Sstevel@tonic-gate 	 */
6150Sstevel@tonic-gate 	mutex_enter(&ph_impl->usba_ph_mutex);
6160Sstevel@tonic-gate 	ph_impl->usba_ph_ref_count++;
6170Sstevel@tonic-gate 
6180Sstevel@tonic-gate 	USB_DPRINTF_L4(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
6196898Sfb209375 	    "hcdi_cb_thread: ph_data=0x%p ref=%d", (void *)ph_data,
6200Sstevel@tonic-gate 	    ph_impl->usba_ph_ref_count);
6210Sstevel@tonic-gate 
6220Sstevel@tonic-gate 	mutex_exit(&ph_impl->usba_ph_mutex);
6230Sstevel@tonic-gate 
6240Sstevel@tonic-gate 	/*
6250Sstevel@tonic-gate 	 * wait till soft interrupt callbacks are taken care of
6260Sstevel@tonic-gate 	 */
6270Sstevel@tonic-gate 	while (ph_data->p_soft_intr) {
6280Sstevel@tonic-gate 		mutex_exit(&ph_data->p_mutex);
6290Sstevel@tonic-gate 		delay(1);
6300Sstevel@tonic-gate 		mutex_enter(&ph_data->p_mutex);
6310Sstevel@tonic-gate 	}
6320Sstevel@tonic-gate 
6330Sstevel@tonic-gate 	while ((req_wrp = (usba_req_wrapper_t *)
6340Sstevel@tonic-gate 	    usba_rm_first_pvt_from_list(&ph_data->p_cb_queue)) != NULL) {
6350Sstevel@tonic-gate 		hcdi_do_cb(ph_data, req_wrp, hcdi);
6360Sstevel@tonic-gate 	}
6370Sstevel@tonic-gate 
6380Sstevel@tonic-gate 	ph_data->p_thread_id = 0;
6390Sstevel@tonic-gate 	mutex_exit(&ph_data->p_mutex);
6400Sstevel@tonic-gate 
6410Sstevel@tonic-gate 	USB_DPRINTF_L4(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
6426898Sfb209375 	    "hcdi_cb_thread done: ph_data=0x%p", (void *)ph_data);
6430Sstevel@tonic-gate 
6440Sstevel@tonic-gate 	usba_release_ph_data(ph_impl);
6450Sstevel@tonic-gate }
6460Sstevel@tonic-gate 
6470Sstevel@tonic-gate 
6480Sstevel@tonic-gate static void
hcdi_do_cb(usba_pipe_handle_data_t * ph_data,usba_req_wrapper_t * req_wrp,usba_hcdi_t * hcdi)6490Sstevel@tonic-gate hcdi_do_cb(usba_pipe_handle_data_t *ph_data, usba_req_wrapper_t *req_wrp,
6500Sstevel@tonic-gate     usba_hcdi_t *hcdi)
6510Sstevel@tonic-gate {
6520Sstevel@tonic-gate 	usb_cr_t		completion_reason;
6530Sstevel@tonic-gate 	usb_req_attrs_t		attrs = req_wrp->wr_attrs;
6540Sstevel@tonic-gate 
6550Sstevel@tonic-gate 	switch (req_wrp->wr_ph_data->p_ep.bmAttributes &
6560Sstevel@tonic-gate 	    USB_EP_ATTR_MASK) {
6570Sstevel@tonic-gate 	case USB_EP_ATTR_CONTROL:
6580Sstevel@tonic-gate 		completion_reason =
6590Sstevel@tonic-gate 		    USBA_WRP2CTRL_REQ(req_wrp)->ctrl_completion_reason;
6600Sstevel@tonic-gate 		break;
6610Sstevel@tonic-gate 	case USB_EP_ATTR_INTR:
6620Sstevel@tonic-gate 		completion_reason =
6630Sstevel@tonic-gate 		    USBA_WRP2INTR_REQ(req_wrp)->intr_completion_reason;
6640Sstevel@tonic-gate 		break;
6650Sstevel@tonic-gate 	case USB_EP_ATTR_BULK:
6660Sstevel@tonic-gate 		completion_reason =
6670Sstevel@tonic-gate 		    USBA_WRP2BULK_REQ(req_wrp)->bulk_completion_reason;
6680Sstevel@tonic-gate 		break;
6690Sstevel@tonic-gate 	case USB_EP_ATTR_ISOCH:
6700Sstevel@tonic-gate 		completion_reason =
6710Sstevel@tonic-gate 		    USBA_WRP2ISOC_REQ(req_wrp)->isoc_completion_reason;
6720Sstevel@tonic-gate 		break;
6730Sstevel@tonic-gate 	}
6740Sstevel@tonic-gate 	req_wrp->wr_cr = completion_reason;
6750Sstevel@tonic-gate 
6760Sstevel@tonic-gate 	USB_DPRINTF_L4(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
6776898Sfb209375 	    "hcdi_do_cb: wrp=0x%p cr=0x%x", (void *)req_wrp, completion_reason);
6780Sstevel@tonic-gate 
6790Sstevel@tonic-gate 	/*
6800Sstevel@tonic-gate 	 * Normal callbacks:
6810Sstevel@tonic-gate 	 */
6820Sstevel@tonic-gate 	if (completion_reason == USB_CR_OK) {
6830Sstevel@tonic-gate 		mutex_exit(&ph_data->p_mutex);
6840Sstevel@tonic-gate 		usba_req_normal_cb(req_wrp);
6850Sstevel@tonic-gate 		mutex_enter(&ph_data->p_mutex);
6860Sstevel@tonic-gate 	} else {
6870Sstevel@tonic-gate 		usb_pipe_state_t pipe_state;
6880Sstevel@tonic-gate 
6890Sstevel@tonic-gate 		USB_DPRINTF_L4(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
6900Sstevel@tonic-gate 		    "exception callback handling: attrs=0x%x", attrs);
6910Sstevel@tonic-gate 
6920Sstevel@tonic-gate 		/*
6930Sstevel@tonic-gate 		 * In exception callback handling, if we were
6940Sstevel@tonic-gate 		 * not able to clear stall, we need to modify
6950Sstevel@tonic-gate 		 * pipe state. Also if auto-clearing is not set
6960Sstevel@tonic-gate 		 * pipe state needs to be modified.
6970Sstevel@tonic-gate 		 */
6980Sstevel@tonic-gate 		pipe_state = usba_get_ph_state(ph_data);
6990Sstevel@tonic-gate 
7000Sstevel@tonic-gate 		if (!USBA_PIPE_CLOSING(pipe_state)) {
7010Sstevel@tonic-gate 			switch (completion_reason) {
7020Sstevel@tonic-gate 			case USB_CR_STOPPED_POLLING:
7030Sstevel@tonic-gate 				if (pipe_state ==
7040Sstevel@tonic-gate 				    USB_PIPE_STATE_ACTIVE) {
7050Sstevel@tonic-gate 					usba_pipe_new_state(ph_data,
7060Sstevel@tonic-gate 					    USB_PIPE_STATE_IDLE);
7070Sstevel@tonic-gate 				}
7080Sstevel@tonic-gate 				break;
7090Sstevel@tonic-gate 			case USB_CR_NOT_SUPPORTED:
7100Sstevel@tonic-gate 				usba_pipe_new_state(ph_data,
7110Sstevel@tonic-gate 				    USB_PIPE_STATE_IDLE);
7120Sstevel@tonic-gate 				break;
7130Sstevel@tonic-gate 			case USB_CR_PIPE_RESET:
7140Sstevel@tonic-gate 			case USB_CR_FLUSHED:
7150Sstevel@tonic-gate 				break;
7160Sstevel@tonic-gate 			default:
7170Sstevel@tonic-gate 				usba_pipe_new_state(ph_data,
7180Sstevel@tonic-gate 				    USB_PIPE_STATE_ERROR);
7190Sstevel@tonic-gate 				break;
7200Sstevel@tonic-gate 			}
7210Sstevel@tonic-gate 		}
7220Sstevel@tonic-gate 
7230Sstevel@tonic-gate 		pipe_state = usba_get_ph_state(ph_data);
7240Sstevel@tonic-gate 
7250Sstevel@tonic-gate 		mutex_exit(&ph_data->p_mutex);
7260Sstevel@tonic-gate 		if (attrs & USB_ATTRS_PIPE_RESET) {
7270Sstevel@tonic-gate 			if ((completion_reason != USB_CR_PIPE_RESET) &&
7280Sstevel@tonic-gate 			    (pipe_state == USB_PIPE_STATE_ERROR)) {
7290Sstevel@tonic-gate 
7300Sstevel@tonic-gate 				hcdi_autoclearing(req_wrp);
7310Sstevel@tonic-gate 			}
7320Sstevel@tonic-gate 		}
7330Sstevel@tonic-gate 
7340Sstevel@tonic-gate 		usba_req_exc_cb(req_wrp, 0, 0);
7350Sstevel@tonic-gate 		mutex_enter(&ph_data->p_mutex);
7360Sstevel@tonic-gate 	}
7370Sstevel@tonic-gate 
7380Sstevel@tonic-gate 	/* Update the hcdi error kstats */
7390Sstevel@tonic-gate 	if (completion_reason) {
7400Sstevel@tonic-gate 		mutex_enter(&hcdi->hcdi_mutex);
7410Sstevel@tonic-gate 		usba_hcdi_update_error_stats(hcdi, completion_reason);
7420Sstevel@tonic-gate 		mutex_exit(&hcdi->hcdi_mutex);
7430Sstevel@tonic-gate 	}
7440Sstevel@tonic-gate 
7450Sstevel@tonic-gate 	/*
7460Sstevel@tonic-gate 	 * Once the callback is finished, release the pipe handle
7470Sstevel@tonic-gate 	 * we start the next request first to avoid that the
7480Sstevel@tonic-gate 	 * pipe gets closed while starting the next request
7490Sstevel@tonic-gate 	 */
7500Sstevel@tonic-gate 	mutex_exit(&ph_data->p_mutex);
7510Sstevel@tonic-gate 	usba_start_next_req(ph_data);
7520Sstevel@tonic-gate 
7530Sstevel@tonic-gate 	mutex_enter(&ph_data->p_mutex);
7540Sstevel@tonic-gate }
7550Sstevel@tonic-gate 
7560Sstevel@tonic-gate 
7570Sstevel@tonic-gate /*
7580Sstevel@tonic-gate  * thread to perform callbacks on the shared queue
7590Sstevel@tonic-gate  */
7600Sstevel@tonic-gate static void
hcdi_shared_cb_thread(void * arg)7610Sstevel@tonic-gate hcdi_shared_cb_thread(void *arg)
7620Sstevel@tonic-gate {
7630Sstevel@tonic-gate 	usba_req_wrapper_t *req_wrp = (usba_req_wrapper_t *)arg;
7640Sstevel@tonic-gate 	usba_pipe_handle_data_t	*ph_data = req_wrp->wr_ph_data;
7650Sstevel@tonic-gate 	usba_ph_impl_t		*ph_impl = ph_data->p_ph_impl;
7660Sstevel@tonic-gate 	usba_hcdi_t		*hcdi = usba_hcdi_get_hcdi(ph_data->
7676898Sfb209375 	    p_usba_device->usb_root_hub_dip);
7680Sstevel@tonic-gate 	/*
7690Sstevel@tonic-gate 	 * hold the ph_data. we can't use usba_hold_ph_data() since
7700Sstevel@tonic-gate 	 * it will return NULL if we are closing the pipe which would
7710Sstevel@tonic-gate 	 * then leave all requests stuck in the cb_queue
7720Sstevel@tonic-gate 	 */
7730Sstevel@tonic-gate 	mutex_enter(&ph_impl->usba_ph_mutex);
7740Sstevel@tonic-gate 	ph_impl->usba_ph_ref_count++;
7750Sstevel@tonic-gate 
7760Sstevel@tonic-gate 	USB_DPRINTF_L4(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
7770Sstevel@tonic-gate 	    "hcdi_shared_cb_thread: ph_data=0x%p ref=%d req=0x%p",
7786898Sfb209375 	    (void *)ph_data, ph_impl->usba_ph_ref_count, (void *)req_wrp);
7790Sstevel@tonic-gate 	mutex_exit(&ph_impl->usba_ph_mutex);
7800Sstevel@tonic-gate 
7810Sstevel@tonic-gate 	/* do the callback */
7820Sstevel@tonic-gate 	mutex_enter(&ph_data->p_mutex);
7830Sstevel@tonic-gate 	hcdi_do_cb(ph_data, req_wrp, hcdi);
7840Sstevel@tonic-gate 	mutex_exit(&ph_data->p_mutex);
7850Sstevel@tonic-gate 
7860Sstevel@tonic-gate 	USB_DPRINTF_L4(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
7876898Sfb209375 	    "hcdi_cb_thread done: ph_data=0x%p", (void *)ph_data);
7880Sstevel@tonic-gate 
7890Sstevel@tonic-gate 	usba_release_ph_data(ph_impl);
7900Sstevel@tonic-gate }
7910Sstevel@tonic-gate 
7920Sstevel@tonic-gate 
7930Sstevel@tonic-gate /*
7940Sstevel@tonic-gate  * soft interrupt handler
7950Sstevel@tonic-gate  */
7960Sstevel@tonic-gate /*ARGSUSED*/
7970Sstevel@tonic-gate static uint_t
hcdi_soft_intr(caddr_t arg1,caddr_t arg2)7980Sstevel@tonic-gate hcdi_soft_intr(caddr_t arg1, caddr_t arg2)
7990Sstevel@tonic-gate {
800*7492SZhigang.Lu@Sun.COM 	usba_hcdi_t		*hcdi = (void *)arg1;
8010Sstevel@tonic-gate 	usba_req_wrapper_t	*req_wrp;
8020Sstevel@tonic-gate 	int			count = 0;
8030Sstevel@tonic-gate 
8040Sstevel@tonic-gate 	while ((req_wrp = (usba_req_wrapper_t *)
8050Sstevel@tonic-gate 	    usba_rm_first_pvt_from_list(&hcdi->hcdi_cb_queue)) != NULL) {
8060Sstevel@tonic-gate 		usba_pipe_handle_data_t *ph_data = req_wrp->wr_ph_data;
8070Sstevel@tonic-gate 		usba_ph_impl_t		*ph_impl = ph_data->p_ph_impl;
8080Sstevel@tonic-gate 
8090Sstevel@tonic-gate 		/* hold the pipe */
8100Sstevel@tonic-gate 		mutex_enter(&ph_impl->usba_ph_mutex);
8110Sstevel@tonic-gate 		ph_impl->usba_ph_ref_count++;
8120Sstevel@tonic-gate 		mutex_exit(&ph_impl->usba_ph_mutex);
8130Sstevel@tonic-gate 
8140Sstevel@tonic-gate 		/* do the callback */
8150Sstevel@tonic-gate 		usba_req_normal_cb(req_wrp);
8160Sstevel@tonic-gate 
8170Sstevel@tonic-gate 		/* decrement the soft interrupt count */
8180Sstevel@tonic-gate 		mutex_enter(&ph_data->p_mutex);
8190Sstevel@tonic-gate 		ph_data->p_soft_intr--;
8200Sstevel@tonic-gate 		mutex_exit(&ph_data->p_mutex);
8210Sstevel@tonic-gate 
8220Sstevel@tonic-gate 		/* release the pipe */
8230Sstevel@tonic-gate 		mutex_enter(&ph_impl->usba_ph_mutex);
8240Sstevel@tonic-gate 		ph_impl->usba_ph_ref_count--;
8250Sstevel@tonic-gate 		mutex_exit(&ph_impl->usba_ph_mutex);
8260Sstevel@tonic-gate 
8270Sstevel@tonic-gate 		count++;
8280Sstevel@tonic-gate 	}
8290Sstevel@tonic-gate 
8300Sstevel@tonic-gate 	return (count == 0 ? DDI_INTR_UNCLAIMED : DDI_INTR_CLAIMED);
8310Sstevel@tonic-gate }
8320Sstevel@tonic-gate 
8330Sstevel@tonic-gate 
8340Sstevel@tonic-gate /*
8350Sstevel@tonic-gate  * hcdi_autoclearing:
8360Sstevel@tonic-gate  *	This function is called under the taskq context. It
8370Sstevel@tonic-gate  *	resets the pipe, and clears the stall, if necessary
8380Sstevel@tonic-gate  */
8390Sstevel@tonic-gate static void
hcdi_autoclearing(usba_req_wrapper_t * req_wrp)8400Sstevel@tonic-gate hcdi_autoclearing(usba_req_wrapper_t *req_wrp)
8410Sstevel@tonic-gate {
8420Sstevel@tonic-gate 	usb_cr_t		cr = req_wrp->wr_cr;
8430Sstevel@tonic-gate 	usb_pipe_handle_t	pipe_handle, def_pipe_handle;
8440Sstevel@tonic-gate 	usb_cr_t		completion_reason;
8450Sstevel@tonic-gate 	usb_cb_flags_t		cb_flags;
8460Sstevel@tonic-gate 	int			rval;
8470Sstevel@tonic-gate 	usba_device_t		*usba_device =
8486898Sfb209375 	    req_wrp->wr_ph_data->p_usba_device;
8490Sstevel@tonic-gate 	usba_hcdi_t		*hcdi = usba_hcdi_get_hcdi(
8506898Sfb209375 	    usba_device->usb_root_hub_dip);
8510Sstevel@tonic-gate 	usb_req_attrs_t		attrs = req_wrp->wr_attrs;
8520Sstevel@tonic-gate 
8530Sstevel@tonic-gate 	USB_DPRINTF_L4(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
8546898Sfb209375 	    "hcdi_autoclearing: wrp=0x%p", (void *)req_wrp);
8550Sstevel@tonic-gate 
8560Sstevel@tonic-gate 	pipe_handle = usba_get_pipe_handle(req_wrp->wr_ph_data);
8570Sstevel@tonic-gate 	def_pipe_handle = usba_get_dflt_pipe_handle(req_wrp->wr_ph_data->p_dip);
8580Sstevel@tonic-gate 
8590Sstevel@tonic-gate 	/*
8600Sstevel@tonic-gate 	 * first reset the pipe synchronously
8610Sstevel@tonic-gate 	 */
8620Sstevel@tonic-gate 	if ((attrs & USB_ATTRS_PIPE_RESET) == USB_ATTRS_PIPE_RESET) {
8630Sstevel@tonic-gate 		usba_pipe_clear(pipe_handle);
8640Sstevel@tonic-gate 		usba_req_set_cb_flags(req_wrp, USB_CB_RESET_PIPE);
8650Sstevel@tonic-gate 	}
8660Sstevel@tonic-gate 
8670Sstevel@tonic-gate 	ASSERT(def_pipe_handle);
8680Sstevel@tonic-gate 
8690Sstevel@tonic-gate 	/* Do not clear if this request was a usb_get_status request */
8700Sstevel@tonic-gate 	if ((pipe_handle == def_pipe_handle) &&
8710Sstevel@tonic-gate 	    (USBA_WRP2CTRL_REQ(req_wrp)->ctrl_bRequest ==
8720Sstevel@tonic-gate 	    USB_REQ_GET_STATUS)) {
8730Sstevel@tonic-gate 		USB_DPRINTF_L2(DPRINT_MASK_USBAI, hcdi->hcdi_log_handle,
8740Sstevel@tonic-gate 		    "hcdi_autoclearing: usb_get_status failed, no clearing");
8750Sstevel@tonic-gate 
8760Sstevel@tonic-gate 	/* if default pipe and stall no auto clearing */
8770Sstevel@tonic-gate 	} else if ((pipe_handle == def_pipe_handle) && (cr == USB_CR_STALL)) {
8780Sstevel@tonic-gate 		USB_DPRINTF_L2(DPRINT_MASK_USBAI, hcdi->hcdi_log_handle,
8790Sstevel@tonic-gate 		    "hcdi_autoclearing: default pipe stalled, no clearing");
8800Sstevel@tonic-gate 
8810Sstevel@tonic-gate 		usba_req_set_cb_flags(req_wrp, USB_CB_PROTOCOL_STALL);
8820Sstevel@tonic-gate 
8830Sstevel@tonic-gate 	/* else do auto clearing */
8840Sstevel@tonic-gate 	} else if (((attrs & USB_ATTRS_AUTOCLEARING) ==
8850Sstevel@tonic-gate 	    USB_ATTRS_AUTOCLEARING) && (cr == USB_CR_STALL)) {
8860Sstevel@tonic-gate 		ushort_t status = 0;
8870Sstevel@tonic-gate 
8880Sstevel@tonic-gate 		rval = usb_get_status(req_wrp->wr_dip, def_pipe_handle,
8890Sstevel@tonic-gate 		    USB_DEV_REQ_DEV_TO_HOST | USB_DEV_REQ_RCPT_EP,
8900Sstevel@tonic-gate 		    req_wrp->wr_ph_data->p_ep.bEndpointAddress,
8910Sstevel@tonic-gate 		    &status, USB_FLAGS_SLEEP);
8920Sstevel@tonic-gate 		if (rval != USB_SUCCESS) {
8930Sstevel@tonic-gate 			USB_DPRINTF_L2(DPRINT_MASK_USBAI, hcdi->hcdi_log_handle,
8940Sstevel@tonic-gate 			    "get status (STALL) failed: rval=%d", rval);
8950Sstevel@tonic-gate 
8960Sstevel@tonic-gate 			usba_pipe_clear(def_pipe_handle);
8970Sstevel@tonic-gate 		}
8980Sstevel@tonic-gate 
8990Sstevel@tonic-gate 		if ((rval != USB_SUCCESS) ||
9000Sstevel@tonic-gate 		    (status & USB_EP_HALT_STATUS)) {
9010Sstevel@tonic-gate 			usba_req_set_cb_flags(req_wrp, USB_CB_FUNCTIONAL_STALL);
9020Sstevel@tonic-gate 
9030Sstevel@tonic-gate 			if ((rval = usb_pipe_sync_ctrl_xfer(
9040Sstevel@tonic-gate 			    req_wrp->wr_dip, def_pipe_handle,
9050Sstevel@tonic-gate 			    USB_DEV_REQ_HOST_TO_DEV |
9060Sstevel@tonic-gate 			    USB_DEV_REQ_RCPT_EP,
9070Sstevel@tonic-gate 			    USB_REQ_CLEAR_FEATURE,
9080Sstevel@tonic-gate 			    0,
9090Sstevel@tonic-gate 			    req_wrp->wr_ph_data->p_ep.bEndpointAddress,
9100Sstevel@tonic-gate 			    0,
9110Sstevel@tonic-gate 			    NULL, 0,
9120Sstevel@tonic-gate 			    &completion_reason,
9130Sstevel@tonic-gate 			    &cb_flags, USB_FLAGS_SLEEP)) != USB_SUCCESS) {
9140Sstevel@tonic-gate 				USB_DPRINTF_L2(DPRINT_MASK_USBAI,
9150Sstevel@tonic-gate 				    hcdi->hcdi_log_handle,
9160Sstevel@tonic-gate 				    "auto clearing (STALL) failed: "
9170Sstevel@tonic-gate 				    "rval=%d, cr=0x%x cb=0x%x",
9180Sstevel@tonic-gate 				    rval, completion_reason, cb_flags);
9190Sstevel@tonic-gate 
9200Sstevel@tonic-gate 				usba_pipe_clear(def_pipe_handle);
9210Sstevel@tonic-gate 			} else {
9220Sstevel@tonic-gate 				usba_req_set_cb_flags(req_wrp,
9236898Sfb209375 				    USB_CB_STALL_CLEARED);
9240Sstevel@tonic-gate 			}
9250Sstevel@tonic-gate 		} else {
9260Sstevel@tonic-gate 			usba_req_set_cb_flags(req_wrp, USB_CB_PROTOCOL_STALL);
9270Sstevel@tonic-gate 		}
9280Sstevel@tonic-gate 	}
9290Sstevel@tonic-gate }
9300Sstevel@tonic-gate 
9310Sstevel@tonic-gate 
9320Sstevel@tonic-gate /*
9330Sstevel@tonic-gate  * usba_hcdi_get_req_private:
9340Sstevel@tonic-gate  *	This function is used to get the HCD private field
9350Sstevel@tonic-gate  *	maintained by USBA. HCD calls this function.
9360Sstevel@tonic-gate  *
9370Sstevel@tonic-gate  * Arguments:
9380Sstevel@tonic-gate  *	req		- pointer to usb_*_req_t
9390Sstevel@tonic-gate  *
9400Sstevel@tonic-gate  * Return Values:
9410Sstevel@tonic-gate  *	wr_hcd_private field from wrapper
9420Sstevel@tonic-gate  */
9430Sstevel@tonic-gate usb_opaque_t
usba_hcdi_get_req_private(usb_opaque_t req)9440Sstevel@tonic-gate usba_hcdi_get_req_private(usb_opaque_t req)
9450Sstevel@tonic-gate {
9460Sstevel@tonic-gate 	usba_req_wrapper_t *wrp = USBA_REQ2WRP(req);
9470Sstevel@tonic-gate 
9480Sstevel@tonic-gate 	return (wrp->wr_hcd_private);
9490Sstevel@tonic-gate }
9500Sstevel@tonic-gate 
9510Sstevel@tonic-gate 
9520Sstevel@tonic-gate /*
9530Sstevel@tonic-gate  * usba_hcdi_set_req_private:
9540Sstevel@tonic-gate  *	This function is used to set the HCD private field
9550Sstevel@tonic-gate  *	maintained by USBA. HCD calls this function.
9560Sstevel@tonic-gate  *
9570Sstevel@tonic-gate  * Arguments:
9580Sstevel@tonic-gate  *	req		- pointer to usb_*_req_t
9590Sstevel@tonic-gate  *	hcd_private	- wr_hcd_private field from wrapper
9600Sstevel@tonic-gate  */
9610Sstevel@tonic-gate void
usba_hcdi_set_req_private(usb_opaque_t req,usb_opaque_t hcd_private)9620Sstevel@tonic-gate usba_hcdi_set_req_private(usb_opaque_t req,
9630Sstevel@tonic-gate 			usb_opaque_t	hcd_private)
9640Sstevel@tonic-gate {
9650Sstevel@tonic-gate 	usba_req_wrapper_t *wrp = USBA_REQ2WRP(req);
9660Sstevel@tonic-gate 
9670Sstevel@tonic-gate 	wrp->wr_hcd_private = hcd_private;
9680Sstevel@tonic-gate }
9690Sstevel@tonic-gate 
9700Sstevel@tonic-gate 
9710Sstevel@tonic-gate /* get data toggle information for this endpoint */
9720Sstevel@tonic-gate uchar_t
usba_hcdi_get_data_toggle(usba_device_t * usba_device,uint8_t ep_addr)9730Sstevel@tonic-gate usba_hcdi_get_data_toggle(usba_device_t *usba_device, uint8_t ep_addr)
9740Sstevel@tonic-gate {
9750Sstevel@tonic-gate 	uchar_t		toggle;
9760Sstevel@tonic-gate 	usba_ph_impl_t	*ph_impl;
9770Sstevel@tonic-gate 	int		ep_index;
9780Sstevel@tonic-gate 
9790Sstevel@tonic-gate 	ep_index = usb_get_ep_index(ep_addr);
9800Sstevel@tonic-gate 	mutex_enter(&usba_device->usb_mutex);
9810Sstevel@tonic-gate 	ph_impl = &usba_device->usb_ph_list[ep_index];
9820Sstevel@tonic-gate 	mutex_enter(&ph_impl->usba_ph_mutex);
9830Sstevel@tonic-gate 	toggle = (uchar_t)(ph_impl->usba_ph_flags & USBA_PH_DATA_TOGGLE);
9840Sstevel@tonic-gate 	mutex_exit(&ph_impl->usba_ph_mutex);
9850Sstevel@tonic-gate 	mutex_exit(&usba_device->usb_mutex);
9860Sstevel@tonic-gate 
9870Sstevel@tonic-gate 	return (toggle);
9880Sstevel@tonic-gate }
9890Sstevel@tonic-gate 
9900Sstevel@tonic-gate 
9910Sstevel@tonic-gate /* set data toggle information for this endpoint */
9920Sstevel@tonic-gate void
usba_hcdi_set_data_toggle(usba_device_t * usba_device,uint8_t ep_addr,uchar_t toggle)9930Sstevel@tonic-gate usba_hcdi_set_data_toggle(usba_device_t *usba_device, uint8_t ep_addr,
9940Sstevel@tonic-gate     uchar_t toggle)
9950Sstevel@tonic-gate {
9960Sstevel@tonic-gate 	usba_ph_impl_t	*ph_impl;
9970Sstevel@tonic-gate 	int		ep_index;
9980Sstevel@tonic-gate 
9990Sstevel@tonic-gate 	ep_index = usb_get_ep_index(ep_addr);
10000Sstevel@tonic-gate 	mutex_enter(&usba_device->usb_mutex);
10010Sstevel@tonic-gate 	ph_impl = &usba_device->usb_ph_list[ep_index];
10020Sstevel@tonic-gate 	mutex_enter(&ph_impl->usba_ph_mutex);
10030Sstevel@tonic-gate 	ph_impl->usba_ph_flags &= ~USBA_PH_DATA_TOGGLE;
10040Sstevel@tonic-gate 	ph_impl->usba_ph_flags |= (USBA_PH_DATA_TOGGLE & toggle);
10050Sstevel@tonic-gate 	mutex_exit(&ph_impl->usba_ph_mutex);
10060Sstevel@tonic-gate 	mutex_exit(&usba_device->usb_mutex);
10070Sstevel@tonic-gate }
10080Sstevel@tonic-gate 
10090Sstevel@tonic-gate 
10100Sstevel@tonic-gate /* get pipe_handle_impl ptr for this ep */
10110Sstevel@tonic-gate usba_pipe_handle_data_t *
usba_hcdi_get_ph_data(usba_device_t * usba_device,uint8_t ep_addr)10120Sstevel@tonic-gate usba_hcdi_get_ph_data(usba_device_t *usba_device, uint8_t ep_addr)
10130Sstevel@tonic-gate {
10140Sstevel@tonic-gate 	return (usba_device->usb_ph_list[usb_get_ep_index(ep_addr)].
10156898Sfb209375 	    usba_ph_data);
10160Sstevel@tonic-gate }
1017