17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5d73ae94eSgc161489 * Common Development and Distribution License (the "License").
6d73ae94eSgc161489 * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22112116d8Sfb209375 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate * USBA: Solaris USB Architecture support
287c478bd9Sstevel@tonic-gate *
297c478bd9Sstevel@tonic-gate * hcdi.c contains the code for client driver callbacks. A host controller
307c478bd9Sstevel@tonic-gate * driver registers/unregisters with usba through usba_hcdi_register/unregister.
317c478bd9Sstevel@tonic-gate *
327c478bd9Sstevel@tonic-gate * When the transfer has finished, the host controller driver will call into
337c478bd9Sstevel@tonic-gate * usba with the result. The call is usba_hcdi_cb().
347c478bd9Sstevel@tonic-gate *
357c478bd9Sstevel@tonic-gate * The callback queue is maintained in FIFO order. usba_hcdi_cb
367c478bd9Sstevel@tonic-gate * adds to the queue, and hcdi_cb_thread takes the callbacks off the queue
377c478bd9Sstevel@tonic-gate * and executes them.
387c478bd9Sstevel@tonic-gate */
397c478bd9Sstevel@tonic-gate #define USBA_FRAMEWORK
407c478bd9Sstevel@tonic-gate #include <sys/usb/usba/usba_impl.h>
417c478bd9Sstevel@tonic-gate #include <sys/usb/usba/hcdi_impl.h>
427c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
437c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate /* function prototypes, XXXX use hcdi_ prefix? */
467c478bd9Sstevel@tonic-gate static void usba_hcdi_create_stats(usba_hcdi_t *, int);
477c478bd9Sstevel@tonic-gate static void usba_hcdi_update_error_stats(usba_hcdi_t *, usb_cr_t);
487c478bd9Sstevel@tonic-gate static void usba_hcdi_destroy_stats(usba_hcdi_t *);
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate /* internal functions */
517c478bd9Sstevel@tonic-gate static uint_t hcdi_soft_intr(caddr_t arg1, caddr_t arg2);
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate static void hcdi_cb_thread(void *);
547c478bd9Sstevel@tonic-gate static void hcdi_shared_cb_thread(void *);
557c478bd9Sstevel@tonic-gate static void hcdi_do_cb(usba_pipe_handle_data_t *, usba_req_wrapper_t *,
567c478bd9Sstevel@tonic-gate usba_hcdi_t *);
577c478bd9Sstevel@tonic-gate static void hcdi_autoclearing(usba_req_wrapper_t *);
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate /* private function from USBAI */
607c478bd9Sstevel@tonic-gate void usba_pipe_clear(usb_pipe_handle_t);
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate /* for debug messages */
634610e4a0Sfrits uint_t hcdi_errmask = (uint_t)DPRINT_MASK_ALL;
644610e4a0Sfrits uint_t hcdi_errlevel = USB_LOG_L4;
654610e4a0Sfrits uint_t hcdi_instance_debug = (uint_t)-1;
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate void
usba_hcdi_initialization()687c478bd9Sstevel@tonic-gate usba_hcdi_initialization()
697c478bd9Sstevel@tonic-gate {
707c478bd9Sstevel@tonic-gate }
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate void
usba_hcdi_destroy()747c478bd9Sstevel@tonic-gate usba_hcdi_destroy()
757c478bd9Sstevel@tonic-gate {
767c478bd9Sstevel@tonic-gate }
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate /*
807c478bd9Sstevel@tonic-gate * store hcdi structure in the dip
817c478bd9Sstevel@tonic-gate */
827c478bd9Sstevel@tonic-gate void
usba_hcdi_set_hcdi(dev_info_t * dip,usba_hcdi_t * hcdi)837c478bd9Sstevel@tonic-gate usba_hcdi_set_hcdi(dev_info_t *dip, usba_hcdi_t *hcdi)
847c478bd9Sstevel@tonic-gate {
857c478bd9Sstevel@tonic-gate ddi_set_driver_private(dip, hcdi);
867c478bd9Sstevel@tonic-gate }
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate /*
907c478bd9Sstevel@tonic-gate * retrieve hcdi structure from the dip
917c478bd9Sstevel@tonic-gate */
927c478bd9Sstevel@tonic-gate usba_hcdi_t *
usba_hcdi_get_hcdi(dev_info_t * dip)937c478bd9Sstevel@tonic-gate usba_hcdi_get_hcdi(dev_info_t *dip)
947c478bd9Sstevel@tonic-gate {
957c478bd9Sstevel@tonic-gate return (ddi_get_driver_private(dip));
967c478bd9Sstevel@tonic-gate }
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate /*
997c478bd9Sstevel@tonic-gate * Called by an HCD to attach an instance of the driver
1007c478bd9Sstevel@tonic-gate * make this instance known to USBA
1017c478bd9Sstevel@tonic-gate * the HCD should initialize usba_hcdi structure prior
1027c478bd9Sstevel@tonic-gate * to calling this interface
1037c478bd9Sstevel@tonic-gate */
1047c478bd9Sstevel@tonic-gate int
usba_hcdi_register(usba_hcdi_register_args_t * args,uint_t flags)1057c478bd9Sstevel@tonic-gate usba_hcdi_register(usba_hcdi_register_args_t *args, uint_t flags)
1067c478bd9Sstevel@tonic-gate {
1077c478bd9Sstevel@tonic-gate char *datap;
1087c478bd9Sstevel@tonic-gate uint_t soft_prip;
1097c478bd9Sstevel@tonic-gate usba_hcdi_t *hcdi = kmem_zalloc(sizeof (usba_hcdi_t), KM_SLEEP);
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate if (args->usba_hcdi_register_version != HCDI_REGISTER_VERS_0) {
1127c478bd9Sstevel@tonic-gate kmem_free(hcdi, sizeof (usba_hcdi_t));
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate return (USB_FAILURE);
1157c478bd9Sstevel@tonic-gate }
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate hcdi->hcdi_dip = args->usba_hcdi_register_dip;
1187c478bd9Sstevel@tonic-gate
1197c478bd9Sstevel@tonic-gate /*
1207c478bd9Sstevel@tonic-gate * Create a log_handle
1217c478bd9Sstevel@tonic-gate */
1227c478bd9Sstevel@tonic-gate hcdi->hcdi_log_handle = usb_alloc_log_hdl(hcdi->hcdi_dip, NULL,
1237c478bd9Sstevel@tonic-gate &hcdi_errlevel, &hcdi_errmask, &hcdi_instance_debug,
1247c478bd9Sstevel@tonic-gate 0);
1257c478bd9Sstevel@tonic-gate
1267c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
1277c478bd9Sstevel@tonic-gate "usba_hcdi_register: %s", ddi_node_name(hcdi->hcdi_dip));
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate /*
1307c478bd9Sstevel@tonic-gate * Initialize the mutex. Use the iblock cookie passed in
1317c478bd9Sstevel@tonic-gate * by the host controller driver.
1327c478bd9Sstevel@tonic-gate */
1337c478bd9Sstevel@tonic-gate mutex_init(&hcdi->hcdi_mutex, NULL, MUTEX_DRIVER,
1347c478bd9Sstevel@tonic-gate args->usba_hcdi_register_iblock_cookie);
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate /* add soft interrupt */
1377c478bd9Sstevel@tonic-gate if (ddi_intr_add_softint(hcdi->hcdi_dip, &hcdi->hcdi_softint_hdl,
1387c478bd9Sstevel@tonic-gate DDI_INTR_SOFTPRI_MAX, hcdi_soft_intr, (caddr_t)hcdi) !=
1397c478bd9Sstevel@tonic-gate DDI_SUCCESS) {
1407c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
1417c478bd9Sstevel@tonic-gate "usba_hcd_register: add soft interrupt failed");
1427c478bd9Sstevel@tonic-gate mutex_destroy(&hcdi->hcdi_mutex);
1437c478bd9Sstevel@tonic-gate usb_free_log_hdl(hcdi->hcdi_log_handle);
1447c478bd9Sstevel@tonic-gate kmem_free(hcdi, sizeof (usba_hcdi_t));
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate return (USB_FAILURE);
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate if (ddi_intr_get_softint_pri(hcdi->hcdi_softint_hdl, &soft_prip) !=
1507c478bd9Sstevel@tonic-gate DDI_SUCCESS) {
1517c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
1527c478bd9Sstevel@tonic-gate "usba_hcd_register: get soft interrupt priority failed");
1537c478bd9Sstevel@tonic-gate (void) ddi_intr_remove_softint(hcdi->hcdi_softint_hdl);
1547c478bd9Sstevel@tonic-gate mutex_destroy(&hcdi->hcdi_mutex);
1557c478bd9Sstevel@tonic-gate usb_free_log_hdl(hcdi->hcdi_log_handle);
1567c478bd9Sstevel@tonic-gate kmem_free(hcdi, sizeof (usba_hcdi_t));
1577c478bd9Sstevel@tonic-gate
1587c478bd9Sstevel@tonic-gate return (USB_FAILURE);
1597c478bd9Sstevel@tonic-gate }
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate /*
1627c478bd9Sstevel@tonic-gate * Priority and iblock_cookie are one and the same
1637c478bd9Sstevel@tonic-gate * (However, retaining hcdi_soft_iblock_cookie for now
1647c478bd9Sstevel@tonic-gate * assigning it w/ priority. In future all iblock_cookie
1657c478bd9Sstevel@tonic-gate * could just go)
1667c478bd9Sstevel@tonic-gate */
1677c478bd9Sstevel@tonic-gate hcdi->hcdi_soft_iblock_cookie =
168abdbd06dSagiri (ddi_iblock_cookie_t)(uintptr_t)soft_prip;
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gate usba_init_list(&hcdi->hcdi_cb_queue, NULL, NULL);
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate hcdi->hcdi_dma_attr = args->usba_hcdi_register_dma_attr;
1737c478bd9Sstevel@tonic-gate hcdi->hcdi_flags = flags;
1747c478bd9Sstevel@tonic-gate hcdi->hcdi_ops = args->usba_hcdi_register_ops;
1757c478bd9Sstevel@tonic-gate hcdi->hcdi_iblock_cookie = args->usba_hcdi_register_iblock_cookie;
1767c478bd9Sstevel@tonic-gate usba_hcdi_create_stats(hcdi, ddi_get_instance(hcdi->hcdi_dip));
1777c478bd9Sstevel@tonic-gate
1787c478bd9Sstevel@tonic-gate hcdi->hcdi_min_xfer = hcdi->hcdi_dma_attr->dma_attr_minxfer;
1797c478bd9Sstevel@tonic-gate hcdi->hcdi_min_burst_size =
1807c478bd9Sstevel@tonic-gate (1<<(ddi_ffs(hcdi->hcdi_dma_attr->dma_attr_burstsizes)-1));
1817c478bd9Sstevel@tonic-gate hcdi->hcdi_max_burst_size =
1827c478bd9Sstevel@tonic-gate (1<<(ddi_fls(hcdi->hcdi_dma_attr->dma_attr_burstsizes)-1));
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate usba_hcdi_set_hcdi(hcdi->hcdi_dip, hcdi);
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY,
1877c478bd9Sstevel@tonic-gate hcdi->hcdi_dip,
1887c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "ugen-default-binding", &datap) ==
1897c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS) {
1907c478bd9Sstevel@tonic-gate if (strcmp(datap, "device") == 0) {
1917c478bd9Sstevel@tonic-gate hcdi->hcdi_ugen_default_binding =
1927c478bd9Sstevel@tonic-gate USBA_UGEN_DEVICE_BINDING;
1937c478bd9Sstevel@tonic-gate } else if (strcmp(datap, "interface") == 0) {
1947c478bd9Sstevel@tonic-gate hcdi->hcdi_ugen_default_binding =
1957c478bd9Sstevel@tonic-gate USBA_UGEN_INTERFACE_BINDING;
196d73ae94eSgc161489 } else if (strcmp(datap, "interface-association") == 0) {
197d73ae94eSgc161489 hcdi->hcdi_ugen_default_binding =
198d73ae94eSgc161489 USBA_UGEN_INTERFACE_ASSOCIATION_BINDING;
1997c478bd9Sstevel@tonic-gate } else {
200d291d9f2Sfrits USB_DPRINTF_L2(DPRINT_MASK_HCDI,
2017c478bd9Sstevel@tonic-gate hcdi->hcdi_log_handle,
2027c478bd9Sstevel@tonic-gate "illegal value (%s) for "
2037c478bd9Sstevel@tonic-gate "ugen_default_binding property",
2047c478bd9Sstevel@tonic-gate datap);
2057c478bd9Sstevel@tonic-gate }
2067c478bd9Sstevel@tonic-gate ddi_prop_free(datap);
2077c478bd9Sstevel@tonic-gate }
2087c478bd9Sstevel@tonic-gate
2097c478bd9Sstevel@tonic-gate return (USB_SUCCESS);
2107c478bd9Sstevel@tonic-gate }
2117c478bd9Sstevel@tonic-gate
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate /*
2147c478bd9Sstevel@tonic-gate * Called by an HCD to detach an instance of the driver
2157c478bd9Sstevel@tonic-gate */
2167c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2177c478bd9Sstevel@tonic-gate void
usba_hcdi_unregister(dev_info_t * dip)2187c478bd9Sstevel@tonic-gate usba_hcdi_unregister(dev_info_t *dip)
2197c478bd9Sstevel@tonic-gate {
2207c478bd9Sstevel@tonic-gate usba_hcdi_t *hcdi = usba_hcdi_get_hcdi(dip);
2217c478bd9Sstevel@tonic-gate
2227c478bd9Sstevel@tonic-gate if (hcdi) {
2237c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
2247c478bd9Sstevel@tonic-gate "usba_hcdi_unregister: %s", ddi_node_name(dip));
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate usba_hcdi_set_hcdi(dip, NULL);
2277c478bd9Sstevel@tonic-gate
2287c478bd9Sstevel@tonic-gate mutex_destroy(&hcdi->hcdi_mutex);
2297c478bd9Sstevel@tonic-gate usba_hcdi_destroy_stats(hcdi);
2307c478bd9Sstevel@tonic-gate usb_free_log_hdl(hcdi->hcdi_log_handle);
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate /* Destroy the soft interrupt */
2337c478bd9Sstevel@tonic-gate (void) ddi_intr_remove_softint(hcdi->hcdi_softint_hdl);
2347c478bd9Sstevel@tonic-gate kmem_free(hcdi, sizeof (usba_hcdi_t));
2357c478bd9Sstevel@tonic-gate }
2367c478bd9Sstevel@tonic-gate }
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate /*
2407c478bd9Sstevel@tonic-gate * alloc usba_hcdi_ops structure
2417c478bd9Sstevel@tonic-gate * called from the HCD attach routine
2427c478bd9Sstevel@tonic-gate */
2437c478bd9Sstevel@tonic-gate usba_hcdi_ops_t *
usba_alloc_hcdi_ops()2447c478bd9Sstevel@tonic-gate usba_alloc_hcdi_ops()
2457c478bd9Sstevel@tonic-gate {
2467c478bd9Sstevel@tonic-gate usba_hcdi_ops_t *usba_hcdi_ops;
2477c478bd9Sstevel@tonic-gate
2487c478bd9Sstevel@tonic-gate usba_hcdi_ops = kmem_zalloc(sizeof (usba_hcdi_ops_t), KM_SLEEP);
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate return (usba_hcdi_ops);
2517c478bd9Sstevel@tonic-gate }
2527c478bd9Sstevel@tonic-gate
2537c478bd9Sstevel@tonic-gate
2547c478bd9Sstevel@tonic-gate /*
2557c478bd9Sstevel@tonic-gate * dealloc usba_hcdi_ops structure
2567c478bd9Sstevel@tonic-gate */
2577c478bd9Sstevel@tonic-gate void
usba_free_hcdi_ops(usba_hcdi_ops_t * hcdi_ops)2587c478bd9Sstevel@tonic-gate usba_free_hcdi_ops(usba_hcdi_ops_t *hcdi_ops)
2597c478bd9Sstevel@tonic-gate {
2607c478bd9Sstevel@tonic-gate if (hcdi_ops) {
2617c478bd9Sstevel@tonic-gate kmem_free(hcdi_ops, sizeof (usba_hcdi_ops_t));
2627c478bd9Sstevel@tonic-gate }
2637c478bd9Sstevel@tonic-gate }
2647c478bd9Sstevel@tonic-gate
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gate /*
2677c478bd9Sstevel@tonic-gate * Allocate the hotplug kstats structure
2687c478bd9Sstevel@tonic-gate */
2697c478bd9Sstevel@tonic-gate void
usba_hcdi_create_stats(usba_hcdi_t * hcdi,int instance)2707c478bd9Sstevel@tonic-gate usba_hcdi_create_stats(usba_hcdi_t *hcdi, int instance)
2717c478bd9Sstevel@tonic-gate {
2727c478bd9Sstevel@tonic-gate char kstatname[KSTAT_STRLEN];
2737c478bd9Sstevel@tonic-gate const char *dname = ddi_driver_name(hcdi->hcdi_dip);
2747c478bd9Sstevel@tonic-gate hcdi_hotplug_stats_t *hsp;
2757c478bd9Sstevel@tonic-gate hcdi_error_stats_t *esp;
2767c478bd9Sstevel@tonic-gate
2777c478bd9Sstevel@tonic-gate if (HCDI_HOTPLUG_STATS(hcdi) == NULL) {
2787c478bd9Sstevel@tonic-gate (void) snprintf(kstatname, KSTAT_STRLEN, "%s%d,hotplug",
2797c478bd9Sstevel@tonic-gate dname, instance);
2807c478bd9Sstevel@tonic-gate HCDI_HOTPLUG_STATS(hcdi) = kstat_create("usba", instance,
2817c478bd9Sstevel@tonic-gate kstatname, "usb_hotplug", KSTAT_TYPE_NAMED,
2827c478bd9Sstevel@tonic-gate sizeof (hcdi_hotplug_stats_t) / sizeof (kstat_named_t),
2837c478bd9Sstevel@tonic-gate KSTAT_FLAG_PERSISTENT);
2847c478bd9Sstevel@tonic-gate
2857c478bd9Sstevel@tonic-gate if (HCDI_HOTPLUG_STATS(hcdi) == NULL) {
2867c478bd9Sstevel@tonic-gate
2877c478bd9Sstevel@tonic-gate return;
2887c478bd9Sstevel@tonic-gate }
2897c478bd9Sstevel@tonic-gate
2907c478bd9Sstevel@tonic-gate hsp = HCDI_HOTPLUG_STATS_DATA(hcdi);
2917c478bd9Sstevel@tonic-gate kstat_named_init(&hsp->hcdi_hotplug_total_success,
2927c478bd9Sstevel@tonic-gate "Total Hotplug Successes", KSTAT_DATA_UINT64);
2937c478bd9Sstevel@tonic-gate kstat_named_init(&hsp->hcdi_hotplug_success,
2947c478bd9Sstevel@tonic-gate "Hotplug Successes", KSTAT_DATA_UINT64);
2957c478bd9Sstevel@tonic-gate kstat_named_init(&hsp->hcdi_hotplug_total_failure,
2967c478bd9Sstevel@tonic-gate "Hotplug Total Failures", KSTAT_DATA_UINT64);
2977c478bd9Sstevel@tonic-gate kstat_named_init(&hsp->hcdi_hotplug_failure,
2987c478bd9Sstevel@tonic-gate "Hotplug Failures", KSTAT_DATA_UINT64);
2997c478bd9Sstevel@tonic-gate kstat_named_init(&hsp->hcdi_device_count,
3007c478bd9Sstevel@tonic-gate "Device Count", KSTAT_DATA_UINT64);
3017c478bd9Sstevel@tonic-gate
3027c478bd9Sstevel@tonic-gate HCDI_HOTPLUG_STATS(hcdi)->ks_private = hcdi;
3037c478bd9Sstevel@tonic-gate HCDI_HOTPLUG_STATS(hcdi)->ks_update = nulldev;
3047c478bd9Sstevel@tonic-gate kstat_install(HCDI_HOTPLUG_STATS(hcdi));
3057c478bd9Sstevel@tonic-gate }
3067c478bd9Sstevel@tonic-gate
3077c478bd9Sstevel@tonic-gate if (HCDI_ERROR_STATS(hcdi) == NULL) {
3087c478bd9Sstevel@tonic-gate (void) snprintf(kstatname, KSTAT_STRLEN, "%s%d,error",
3097c478bd9Sstevel@tonic-gate dname, instance);
3107c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS(hcdi) = kstat_create("usba", instance,
3117c478bd9Sstevel@tonic-gate kstatname, "usb_errors", KSTAT_TYPE_NAMED,
3127c478bd9Sstevel@tonic-gate sizeof (hcdi_error_stats_t) / sizeof (kstat_named_t),
3137c478bd9Sstevel@tonic-gate KSTAT_FLAG_PERSISTENT);
3147c478bd9Sstevel@tonic-gate
3157c478bd9Sstevel@tonic-gate if (HCDI_ERROR_STATS(hcdi) == NULL) {
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gate return;
3187c478bd9Sstevel@tonic-gate }
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gate esp = HCDI_ERROR_STATS_DATA(hcdi);
3217c478bd9Sstevel@tonic-gate kstat_named_init(&esp->cc_crc, "CRC Errors", KSTAT_DATA_UINT64);
3227c478bd9Sstevel@tonic-gate kstat_named_init(&esp->cc_bitstuffing,
3237c478bd9Sstevel@tonic-gate "Bit Stuffing Violations", KSTAT_DATA_UINT64);
3247c478bd9Sstevel@tonic-gate kstat_named_init(&esp->cc_data_toggle_mm,
3257c478bd9Sstevel@tonic-gate "Data Toggle PID Errors", KSTAT_DATA_UINT64);
3267c478bd9Sstevel@tonic-gate kstat_named_init(&esp->cc_stall,
3277c478bd9Sstevel@tonic-gate "Endpoint Stalls", KSTAT_DATA_UINT64);
3287c478bd9Sstevel@tonic-gate kstat_named_init(&esp->cc_dev_not_resp,
3297c478bd9Sstevel@tonic-gate "Device Not Responding", KSTAT_DATA_UINT64);
3307c478bd9Sstevel@tonic-gate kstat_named_init(&esp->cc_pid_checkfailure,
3317c478bd9Sstevel@tonic-gate "PID Check Bit Errors", KSTAT_DATA_UINT64);
3327c478bd9Sstevel@tonic-gate kstat_named_init(&esp->cc_unexp_pid,
3337c478bd9Sstevel@tonic-gate "Invalid PID Errors", KSTAT_DATA_UINT64);
3347c478bd9Sstevel@tonic-gate kstat_named_init(&esp->cc_data_overrun,
3357c478bd9Sstevel@tonic-gate "Data Overruns", KSTAT_DATA_UINT64);
3367c478bd9Sstevel@tonic-gate kstat_named_init(&esp->cc_data_underrun,
3377c478bd9Sstevel@tonic-gate "Data Underruns", KSTAT_DATA_UINT64);
3387c478bd9Sstevel@tonic-gate kstat_named_init(&esp->cc_buffer_overrun,
3397c478bd9Sstevel@tonic-gate "Buffer Overruns", KSTAT_DATA_UINT64);
3407c478bd9Sstevel@tonic-gate kstat_named_init(&esp->cc_buffer_underrun,
3417c478bd9Sstevel@tonic-gate "Buffer Underruns", KSTAT_DATA_UINT64);
3427c478bd9Sstevel@tonic-gate kstat_named_init(&esp->cc_timeout,
3437c478bd9Sstevel@tonic-gate "Command Timed Out", KSTAT_DATA_UINT64);
3447c478bd9Sstevel@tonic-gate kstat_named_init(&esp->cc_not_accessed,
3457c478bd9Sstevel@tonic-gate "Not Accessed By Hardware", KSTAT_DATA_UINT64);
346*7535ae19SDavid Höppner kstat_named_init(&esp->cc_no_resources,
347*7535ae19SDavid Höppner "No Resources", KSTAT_DATA_UINT64);
3487c478bd9Sstevel@tonic-gate kstat_named_init(&esp->cc_unspecified_err,
3497c478bd9Sstevel@tonic-gate "Unspecified Error", KSTAT_DATA_UINT64);
350*7535ae19SDavid Höppner kstat_named_init(&esp->cc_stopped_polling,
351*7535ae19SDavid Höppner "Stopped Polling", KSTAT_DATA_UINT64);
352*7535ae19SDavid Höppner kstat_named_init(&esp->cc_pipe_closing,
353*7535ae19SDavid Höppner "Pipe Closing", KSTAT_DATA_UINT64);
354*7535ae19SDavid Höppner kstat_named_init(&esp->cc_pipe_reset,
355*7535ae19SDavid Höppner "Pipe Reset", KSTAT_DATA_UINT64);
356*7535ae19SDavid Höppner kstat_named_init(&esp->cc_not_supported,
357*7535ae19SDavid Höppner "Command Not Supported", KSTAT_DATA_UINT64);
358*7535ae19SDavid Höppner kstat_named_init(&esp->cc_flushed,
359*7535ae19SDavid Höppner "Request Flushed", KSTAT_DATA_UINT64);
3607c478bd9Sstevel@tonic-gate
3617c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS(hcdi)->ks_private = hcdi;
3627c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS(hcdi)->ks_update = nulldev;
3637c478bd9Sstevel@tonic-gate kstat_install(HCDI_ERROR_STATS(hcdi));
3647c478bd9Sstevel@tonic-gate }
3657c478bd9Sstevel@tonic-gate }
3667c478bd9Sstevel@tonic-gate
3677c478bd9Sstevel@tonic-gate
3687c478bd9Sstevel@tonic-gate /*
3697c478bd9Sstevel@tonic-gate * Do actual error stats
3707c478bd9Sstevel@tonic-gate */
3717c478bd9Sstevel@tonic-gate void
usba_hcdi_update_error_stats(usba_hcdi_t * hcdi,usb_cr_t completion_reason)3727c478bd9Sstevel@tonic-gate usba_hcdi_update_error_stats(usba_hcdi_t *hcdi, usb_cr_t completion_reason)
3737c478bd9Sstevel@tonic-gate {
3747c478bd9Sstevel@tonic-gate if (HCDI_ERROR_STATS(hcdi) == NULL) {
3757c478bd9Sstevel@tonic-gate
3767c478bd9Sstevel@tonic-gate return;
3777c478bd9Sstevel@tonic-gate }
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gate switch (completion_reason) {
3807c478bd9Sstevel@tonic-gate case USB_CR_OK:
3817c478bd9Sstevel@tonic-gate break;
3827c478bd9Sstevel@tonic-gate case USB_CR_CRC:
3837c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS_DATA(hcdi)->cc_crc.value.ui64++;
3847c478bd9Sstevel@tonic-gate break;
3857c478bd9Sstevel@tonic-gate case USB_CR_BITSTUFFING:
3867c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS_DATA(hcdi)->cc_bitstuffing.value.ui64++;
3877c478bd9Sstevel@tonic-gate break;
3887c478bd9Sstevel@tonic-gate case USB_CR_DATA_TOGGLE_MM:
3897c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS_DATA(hcdi)->cc_data_toggle_mm.value.ui64++;
3907c478bd9Sstevel@tonic-gate break;
3917c478bd9Sstevel@tonic-gate case USB_CR_STALL:
3927c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS_DATA(hcdi)->cc_stall.value.ui64++;
3937c478bd9Sstevel@tonic-gate break;
3947c478bd9Sstevel@tonic-gate case USB_CR_DEV_NOT_RESP:
3957c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS_DATA(hcdi)->cc_dev_not_resp.value.ui64++;
3967c478bd9Sstevel@tonic-gate break;
3977c478bd9Sstevel@tonic-gate case USB_CR_PID_CHECKFAILURE:
3987c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS_DATA(hcdi)->cc_pid_checkfailure.value.ui64++;
3997c478bd9Sstevel@tonic-gate break;
4007c478bd9Sstevel@tonic-gate case USB_CR_UNEXP_PID:
4017c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS_DATA(hcdi)->cc_unexp_pid.value.ui64++;
4027c478bd9Sstevel@tonic-gate break;
4037c478bd9Sstevel@tonic-gate case USB_CR_DATA_OVERRUN:
4047c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS_DATA(hcdi)->cc_data_overrun.value.ui64++;
4057c478bd9Sstevel@tonic-gate break;
4067c478bd9Sstevel@tonic-gate case USB_CR_DATA_UNDERRUN:
4077c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS_DATA(hcdi)->cc_data_underrun.value.ui64++;
4087c478bd9Sstevel@tonic-gate break;
4097c478bd9Sstevel@tonic-gate case USB_CR_BUFFER_OVERRUN:
4107c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS_DATA(hcdi)->cc_buffer_overrun.value.ui64++;
4117c478bd9Sstevel@tonic-gate break;
4127c478bd9Sstevel@tonic-gate case USB_CR_BUFFER_UNDERRUN:
4137c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS_DATA(hcdi)->cc_buffer_underrun.value.ui64++;
4147c478bd9Sstevel@tonic-gate break;
4157c478bd9Sstevel@tonic-gate case USB_CR_TIMEOUT:
4167c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS_DATA(hcdi)->cc_timeout.value.ui64++;
4177c478bd9Sstevel@tonic-gate break;
4187c478bd9Sstevel@tonic-gate case USB_CR_NOT_ACCESSED:
4197c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS_DATA(hcdi)->cc_not_accessed.value.ui64++;
4207c478bd9Sstevel@tonic-gate break;
4217c478bd9Sstevel@tonic-gate case USB_CR_NO_RESOURCES:
4227c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS_DATA(hcdi)->cc_no_resources.value.ui64++;
4237c478bd9Sstevel@tonic-gate break;
4247c478bd9Sstevel@tonic-gate case USB_CR_UNSPECIFIED_ERR:
4257c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS_DATA(hcdi)->cc_unspecified_err.value.ui64++;
4267c478bd9Sstevel@tonic-gate break;
4277c478bd9Sstevel@tonic-gate case USB_CR_STOPPED_POLLING:
4287c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS_DATA(hcdi)->cc_stopped_polling.value.ui64++;
4297c478bd9Sstevel@tonic-gate break;
4307c478bd9Sstevel@tonic-gate case USB_CR_PIPE_CLOSING:
4317c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS_DATA(hcdi)->cc_pipe_closing.value.ui64++;
4327c478bd9Sstevel@tonic-gate break;
4337c478bd9Sstevel@tonic-gate case USB_CR_PIPE_RESET:
4347c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS_DATA(hcdi)->cc_pipe_reset.value.ui64++;
4357c478bd9Sstevel@tonic-gate break;
4367c478bd9Sstevel@tonic-gate case USB_CR_NOT_SUPPORTED:
4377c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS_DATA(hcdi)->cc_not_supported.value.ui64++;
4387c478bd9Sstevel@tonic-gate break;
4397c478bd9Sstevel@tonic-gate case USB_CR_FLUSHED:
4407c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS_DATA(hcdi)->cc_flushed.value.ui64++;
4417c478bd9Sstevel@tonic-gate break;
4427c478bd9Sstevel@tonic-gate default:
4437c478bd9Sstevel@tonic-gate break;
4447c478bd9Sstevel@tonic-gate }
4457c478bd9Sstevel@tonic-gate }
4467c478bd9Sstevel@tonic-gate
4477c478bd9Sstevel@tonic-gate
4487c478bd9Sstevel@tonic-gate /*
4497c478bd9Sstevel@tonic-gate * Destroy the hotplug kstats structure
4507c478bd9Sstevel@tonic-gate */
4517c478bd9Sstevel@tonic-gate static void
usba_hcdi_destroy_stats(usba_hcdi_t * hcdi)4527c478bd9Sstevel@tonic-gate usba_hcdi_destroy_stats(usba_hcdi_t *hcdi)
4537c478bd9Sstevel@tonic-gate {
4547c478bd9Sstevel@tonic-gate if (HCDI_HOTPLUG_STATS(hcdi)) {
4557c478bd9Sstevel@tonic-gate kstat_delete(HCDI_HOTPLUG_STATS(hcdi));
4567c478bd9Sstevel@tonic-gate HCDI_HOTPLUG_STATS(hcdi) = NULL;
4577c478bd9Sstevel@tonic-gate }
4587c478bd9Sstevel@tonic-gate
4597c478bd9Sstevel@tonic-gate if (HCDI_ERROR_STATS(hcdi)) {
4607c478bd9Sstevel@tonic-gate kstat_delete(HCDI_ERROR_STATS(hcdi));
4617c478bd9Sstevel@tonic-gate HCDI_ERROR_STATS(hcdi) = NULL;
4627c478bd9Sstevel@tonic-gate }
4637c478bd9Sstevel@tonic-gate }
4647c478bd9Sstevel@tonic-gate
4657c478bd9Sstevel@tonic-gate
4667c478bd9Sstevel@tonic-gate /*
4677c478bd9Sstevel@tonic-gate * HCD callback handling
4687c478bd9Sstevel@tonic-gate */
4697c478bd9Sstevel@tonic-gate void
usba_hcdi_cb(usba_pipe_handle_data_t * ph_data,usb_opaque_t req,usb_cr_t completion_reason)4707c478bd9Sstevel@tonic-gate usba_hcdi_cb(usba_pipe_handle_data_t *ph_data,
4717c478bd9Sstevel@tonic-gate usb_opaque_t req,
4727c478bd9Sstevel@tonic-gate usb_cr_t completion_reason)
4737c478bd9Sstevel@tonic-gate {
4747c478bd9Sstevel@tonic-gate
4757c478bd9Sstevel@tonic-gate usba_device_t *usba_device = ph_data->p_usba_device;
4767c478bd9Sstevel@tonic-gate usba_hcdi_t *hcdi = usba_hcdi_get_hcdi(
4777c478bd9Sstevel@tonic-gate usba_device->usb_root_hub_dip);
4787c478bd9Sstevel@tonic-gate usba_req_wrapper_t *req_wrp = USBA_REQ2WRP(req);
4797c478bd9Sstevel@tonic-gate usb_ep_descr_t *eptd = &ph_data->p_ep;
4807c478bd9Sstevel@tonic-gate
4817c478bd9Sstevel@tonic-gate mutex_enter(&ph_data->p_mutex);
4827c478bd9Sstevel@tonic-gate
4837c478bd9Sstevel@tonic-gate #ifdef DEBUG
4847c478bd9Sstevel@tonic-gate mutex_enter(&ph_data->p_ph_impl->usba_ph_mutex);
4857c478bd9Sstevel@tonic-gate
4867c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
4877c478bd9Sstevel@tonic-gate "usba_hcdi_cb: "
4887c478bd9Sstevel@tonic-gate "ph_data=0x%p req=0x%p state=%d ref=%d cnt=%d cr=%d",
489112116d8Sfb209375 (void *)ph_data, (void *)req, ph_data->p_ph_impl->usba_ph_state,
4907c478bd9Sstevel@tonic-gate ph_data->p_ph_impl->usba_ph_ref_count, ph_data->p_req_count,
4917c478bd9Sstevel@tonic-gate completion_reason);
4927c478bd9Sstevel@tonic-gate
4937c478bd9Sstevel@tonic-gate mutex_exit(&ph_data->p_ph_impl->usba_ph_mutex);
4947c478bd9Sstevel@tonic-gate #endif
4957c478bd9Sstevel@tonic-gate
4967c478bd9Sstevel@tonic-gate /* Set the completion reason */
4977c478bd9Sstevel@tonic-gate switch (eptd->bmAttributes & USB_EP_ATTR_MASK) {
4987c478bd9Sstevel@tonic-gate case USB_EP_ATTR_CONTROL:
4997c478bd9Sstevel@tonic-gate ((usb_ctrl_req_t *)req)->
5007c478bd9Sstevel@tonic-gate ctrl_completion_reason = completion_reason;
5017c478bd9Sstevel@tonic-gate break;
5027c478bd9Sstevel@tonic-gate case USB_EP_ATTR_BULK:
5037c478bd9Sstevel@tonic-gate ((usb_bulk_req_t *)req)->
5047c478bd9Sstevel@tonic-gate bulk_completion_reason = completion_reason;
5057c478bd9Sstevel@tonic-gate break;
5067c478bd9Sstevel@tonic-gate case USB_EP_ATTR_INTR:
5077c478bd9Sstevel@tonic-gate ((usb_intr_req_t *)req)->
5087c478bd9Sstevel@tonic-gate intr_completion_reason = completion_reason;
5097c478bd9Sstevel@tonic-gate break;
5107c478bd9Sstevel@tonic-gate case USB_EP_ATTR_ISOCH:
5117c478bd9Sstevel@tonic-gate ((usb_isoc_req_t *)req)->
5127c478bd9Sstevel@tonic-gate isoc_completion_reason = completion_reason;
5137c478bd9Sstevel@tonic-gate break;
5147c478bd9Sstevel@tonic-gate }
5157c478bd9Sstevel@tonic-gate
5167c478bd9Sstevel@tonic-gate /*
5177c478bd9Sstevel@tonic-gate * exception callbacks will still go thru a taskq thread
5187c478bd9Sstevel@tonic-gate * but should occur after the soft interrupt callback
5197c478bd9Sstevel@tonic-gate * By design of periodic pipes, polling will stop on any
5207c478bd9Sstevel@tonic-gate * exception
5217c478bd9Sstevel@tonic-gate */
5227c478bd9Sstevel@tonic-gate if ((ph_data->p_spec_flag & USBA_PH_FLAG_USE_SOFT_INTR) &&
5237c478bd9Sstevel@tonic-gate (completion_reason == USB_CR_OK)) {
5247c478bd9Sstevel@tonic-gate ph_data->p_soft_intr++;
5257c478bd9Sstevel@tonic-gate mutex_exit(&ph_data->p_mutex);
5267c478bd9Sstevel@tonic-gate
5277c478bd9Sstevel@tonic-gate usba_add_to_list(&hcdi->hcdi_cb_queue, &req_wrp->wr_queue);
5287c478bd9Sstevel@tonic-gate
5297c478bd9Sstevel@tonic-gate if (ddi_intr_trigger_softint(hcdi->hcdi_softint_hdl, NULL) !=
5307c478bd9Sstevel@tonic-gate DDI_SUCCESS)
5317c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
5327c478bd9Sstevel@tonic-gate "usba_hcdi_cb: ddi_intr_trigger_softint failed");
5337c478bd9Sstevel@tonic-gate
5347c478bd9Sstevel@tonic-gate return;
5357c478bd9Sstevel@tonic-gate }
5367c478bd9Sstevel@tonic-gate
5377c478bd9Sstevel@tonic-gate /*
5387c478bd9Sstevel@tonic-gate * USBA_PH_FLAG_TQ_SHARE is for bulk and intr requests,
5397c478bd9Sstevel@tonic-gate * USBA_PH_FLAG_USE_SOFT_INTR is only for isoch,
5407c478bd9Sstevel@tonic-gate * so there are no conflicts.
5417c478bd9Sstevel@tonic-gate */
5427c478bd9Sstevel@tonic-gate if (ph_data->p_spec_flag & USBA_PH_FLAG_TQ_SHARE) {
5437c478bd9Sstevel@tonic-gate int iface;
5447c478bd9Sstevel@tonic-gate
5457c478bd9Sstevel@tonic-gate mutex_exit(&ph_data->p_mutex);
5467c478bd9Sstevel@tonic-gate iface = usb_get_if_number(ph_data->p_dip);
5477c478bd9Sstevel@tonic-gate if (iface < 0) {
5487c478bd9Sstevel@tonic-gate /* we own the device, use the first taskq */
5497c478bd9Sstevel@tonic-gate iface = 0;
5507c478bd9Sstevel@tonic-gate }
5517c478bd9Sstevel@tonic-gate if (taskq_dispatch(usba_device->usb_shared_taskq[iface],
5527c478bd9Sstevel@tonic-gate hcdi_shared_cb_thread, req_wrp, TQ_NOSLEEP) ==
5537c478bd9Sstevel@tonic-gate NULL) {
5547c478bd9Sstevel@tonic-gate usba_req_exc_cb(req_wrp,
5557c478bd9Sstevel@tonic-gate USB_CR_NO_RESOURCES, USB_CB_ASYNC_REQ_FAILED);
5567c478bd9Sstevel@tonic-gate }
5577c478bd9Sstevel@tonic-gate
5587c478bd9Sstevel@tonic-gate return;
5597c478bd9Sstevel@tonic-gate }
5607c478bd9Sstevel@tonic-gate
5617c478bd9Sstevel@tonic-gate /* Add the callback to the pipehandles callback list */
5627c478bd9Sstevel@tonic-gate usba_add_to_list(&ph_data->p_cb_queue, &req_wrp->wr_queue);
5637c478bd9Sstevel@tonic-gate
5647c478bd9Sstevel@tonic-gate /* only dispatch if there is no thread running */
5657c478bd9Sstevel@tonic-gate if (ph_data->p_thread_id == 0) {
5667c478bd9Sstevel@tonic-gate if (usba_async_ph_req(ph_data, hcdi_cb_thread,
5677c478bd9Sstevel@tonic-gate ph_data, USB_FLAGS_NOSLEEP) != USB_SUCCESS) {
5687c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
5697c478bd9Sstevel@tonic-gate "usba_hcdi_cb: taskq_dispatch failed");
5707c478bd9Sstevel@tonic-gate if (usba_rm_from_list(&ph_data->p_cb_queue,
5717c478bd9Sstevel@tonic-gate &req_wrp->wr_queue) == USB_SUCCESS) {
5727c478bd9Sstevel@tonic-gate mutex_exit(&ph_data->p_mutex);
5737c478bd9Sstevel@tonic-gate usba_req_exc_cb(req_wrp,
5747c478bd9Sstevel@tonic-gate USB_CR_NO_RESOURCES,
5757c478bd9Sstevel@tonic-gate USB_CB_ASYNC_REQ_FAILED);
5767c478bd9Sstevel@tonic-gate
5777c478bd9Sstevel@tonic-gate return;
5787c478bd9Sstevel@tonic-gate }
5797c478bd9Sstevel@tonic-gate } else {
5807c478bd9Sstevel@tonic-gate ph_data->p_thread_id = (kthread_t *)1;
5817c478bd9Sstevel@tonic-gate }
5827c478bd9Sstevel@tonic-gate }
5837c478bd9Sstevel@tonic-gate mutex_exit(&ph_data->p_mutex);
5847c478bd9Sstevel@tonic-gate }
5857c478bd9Sstevel@tonic-gate
5867c478bd9Sstevel@tonic-gate
5877c478bd9Sstevel@tonic-gate /*
5887c478bd9Sstevel@tonic-gate * thread to perform the callbacks
5897c478bd9Sstevel@tonic-gate */
5907c478bd9Sstevel@tonic-gate static void
hcdi_cb_thread(void * arg)5917c478bd9Sstevel@tonic-gate hcdi_cb_thread(void *arg)
5927c478bd9Sstevel@tonic-gate {
5937c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph_data =
5947c478bd9Sstevel@tonic-gate (usba_pipe_handle_data_t *)arg;
5957c478bd9Sstevel@tonic-gate usba_ph_impl_t *ph_impl = ph_data->p_ph_impl;
5967c478bd9Sstevel@tonic-gate usba_hcdi_t *hcdi = usba_hcdi_get_hcdi(ph_data->
5977c478bd9Sstevel@tonic-gate p_usba_device->usb_root_hub_dip);
5987c478bd9Sstevel@tonic-gate usba_req_wrapper_t *req_wrp;
5997c478bd9Sstevel@tonic-gate
6007c478bd9Sstevel@tonic-gate mutex_enter(&ph_data->p_mutex);
6017c478bd9Sstevel@tonic-gate ASSERT(ph_data->p_thread_id == (kthread_t *)1);
6027c478bd9Sstevel@tonic-gate ph_data->p_thread_id = curthread;
6037c478bd9Sstevel@tonic-gate
6047c478bd9Sstevel@tonic-gate /*
6057c478bd9Sstevel@tonic-gate * hold the ph_data. we can't use usba_hold_ph_data() since
6067c478bd9Sstevel@tonic-gate * it will return NULL if we are closing the pipe which would
6077c478bd9Sstevel@tonic-gate * then leave all requests stuck in the cb_queue
6087c478bd9Sstevel@tonic-gate */
6097c478bd9Sstevel@tonic-gate mutex_enter(&ph_impl->usba_ph_mutex);
6107c478bd9Sstevel@tonic-gate ph_impl->usba_ph_ref_count++;
6117c478bd9Sstevel@tonic-gate
6127c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
613112116d8Sfb209375 "hcdi_cb_thread: ph_data=0x%p ref=%d", (void *)ph_data,
6147c478bd9Sstevel@tonic-gate ph_impl->usba_ph_ref_count);
6157c478bd9Sstevel@tonic-gate
6167c478bd9Sstevel@tonic-gate mutex_exit(&ph_impl->usba_ph_mutex);
6177c478bd9Sstevel@tonic-gate
6187c478bd9Sstevel@tonic-gate /*
6197c478bd9Sstevel@tonic-gate * wait till soft interrupt callbacks are taken care of
6207c478bd9Sstevel@tonic-gate */
6217c478bd9Sstevel@tonic-gate while (ph_data->p_soft_intr) {
6227c478bd9Sstevel@tonic-gate mutex_exit(&ph_data->p_mutex);
6237c478bd9Sstevel@tonic-gate delay(1);
6247c478bd9Sstevel@tonic-gate mutex_enter(&ph_data->p_mutex);
6257c478bd9Sstevel@tonic-gate }
6267c478bd9Sstevel@tonic-gate
6277c478bd9Sstevel@tonic-gate while ((req_wrp = (usba_req_wrapper_t *)
6287c478bd9Sstevel@tonic-gate usba_rm_first_pvt_from_list(&ph_data->p_cb_queue)) != NULL) {
6297c478bd9Sstevel@tonic-gate hcdi_do_cb(ph_data, req_wrp, hcdi);
6307c478bd9Sstevel@tonic-gate }
6317c478bd9Sstevel@tonic-gate
6327c478bd9Sstevel@tonic-gate ph_data->p_thread_id = 0;
6337c478bd9Sstevel@tonic-gate mutex_exit(&ph_data->p_mutex);
6347c478bd9Sstevel@tonic-gate
6357c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
636112116d8Sfb209375 "hcdi_cb_thread done: ph_data=0x%p", (void *)ph_data);
6377c478bd9Sstevel@tonic-gate
6387c478bd9Sstevel@tonic-gate usba_release_ph_data(ph_impl);
6397c478bd9Sstevel@tonic-gate }
6407c478bd9Sstevel@tonic-gate
6417c478bd9Sstevel@tonic-gate
6427c478bd9Sstevel@tonic-gate static void
hcdi_do_cb(usba_pipe_handle_data_t * ph_data,usba_req_wrapper_t * req_wrp,usba_hcdi_t * hcdi)6437c478bd9Sstevel@tonic-gate hcdi_do_cb(usba_pipe_handle_data_t *ph_data, usba_req_wrapper_t *req_wrp,
6447c478bd9Sstevel@tonic-gate usba_hcdi_t *hcdi)
6457c478bd9Sstevel@tonic-gate {
6467c478bd9Sstevel@tonic-gate usb_cr_t completion_reason;
6477c478bd9Sstevel@tonic-gate usb_req_attrs_t attrs = req_wrp->wr_attrs;
6487c478bd9Sstevel@tonic-gate
6497c478bd9Sstevel@tonic-gate switch (req_wrp->wr_ph_data->p_ep.bmAttributes &
6507c478bd9Sstevel@tonic-gate USB_EP_ATTR_MASK) {
6517c478bd9Sstevel@tonic-gate case USB_EP_ATTR_CONTROL:
6527c478bd9Sstevel@tonic-gate completion_reason =
6537c478bd9Sstevel@tonic-gate USBA_WRP2CTRL_REQ(req_wrp)->ctrl_completion_reason;
6547c478bd9Sstevel@tonic-gate break;
6557c478bd9Sstevel@tonic-gate case USB_EP_ATTR_INTR:
6567c478bd9Sstevel@tonic-gate completion_reason =
6577c478bd9Sstevel@tonic-gate USBA_WRP2INTR_REQ(req_wrp)->intr_completion_reason;
6587c478bd9Sstevel@tonic-gate break;
6597c478bd9Sstevel@tonic-gate case USB_EP_ATTR_BULK:
6607c478bd9Sstevel@tonic-gate completion_reason =
6617c478bd9Sstevel@tonic-gate USBA_WRP2BULK_REQ(req_wrp)->bulk_completion_reason;
6627c478bd9Sstevel@tonic-gate break;
6637c478bd9Sstevel@tonic-gate case USB_EP_ATTR_ISOCH:
6647c478bd9Sstevel@tonic-gate completion_reason =
6657c478bd9Sstevel@tonic-gate USBA_WRP2ISOC_REQ(req_wrp)->isoc_completion_reason;
6667c478bd9Sstevel@tonic-gate break;
6677c478bd9Sstevel@tonic-gate }
6687c478bd9Sstevel@tonic-gate req_wrp->wr_cr = completion_reason;
6697c478bd9Sstevel@tonic-gate
6707c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
671112116d8Sfb209375 "hcdi_do_cb: wrp=0x%p cr=0x%x", (void *)req_wrp, completion_reason);
6727c478bd9Sstevel@tonic-gate
6737c478bd9Sstevel@tonic-gate /*
6747c478bd9Sstevel@tonic-gate * Normal callbacks:
6757c478bd9Sstevel@tonic-gate */
6767c478bd9Sstevel@tonic-gate if (completion_reason == USB_CR_OK) {
6777c478bd9Sstevel@tonic-gate mutex_exit(&ph_data->p_mutex);
6787c478bd9Sstevel@tonic-gate usba_req_normal_cb(req_wrp);
6797c478bd9Sstevel@tonic-gate mutex_enter(&ph_data->p_mutex);
6807c478bd9Sstevel@tonic-gate } else {
6817c478bd9Sstevel@tonic-gate usb_pipe_state_t pipe_state;
6827c478bd9Sstevel@tonic-gate
6837c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
6847c478bd9Sstevel@tonic-gate "exception callback handling: attrs=0x%x", attrs);
6857c478bd9Sstevel@tonic-gate
6867c478bd9Sstevel@tonic-gate /*
6877c478bd9Sstevel@tonic-gate * In exception callback handling, if we were
6887c478bd9Sstevel@tonic-gate * not able to clear stall, we need to modify
6897c478bd9Sstevel@tonic-gate * pipe state. Also if auto-clearing is not set
6907c478bd9Sstevel@tonic-gate * pipe state needs to be modified.
6917c478bd9Sstevel@tonic-gate */
6927c478bd9Sstevel@tonic-gate pipe_state = usba_get_ph_state(ph_data);
6937c478bd9Sstevel@tonic-gate
6947c478bd9Sstevel@tonic-gate if (!USBA_PIPE_CLOSING(pipe_state)) {
6957c478bd9Sstevel@tonic-gate switch (completion_reason) {
6967c478bd9Sstevel@tonic-gate case USB_CR_STOPPED_POLLING:
6977c478bd9Sstevel@tonic-gate if (pipe_state ==
6987c478bd9Sstevel@tonic-gate USB_PIPE_STATE_ACTIVE) {
6997c478bd9Sstevel@tonic-gate usba_pipe_new_state(ph_data,
7007c478bd9Sstevel@tonic-gate USB_PIPE_STATE_IDLE);
7017c478bd9Sstevel@tonic-gate }
7027c478bd9Sstevel@tonic-gate break;
7037c478bd9Sstevel@tonic-gate case USB_CR_NOT_SUPPORTED:
7047c478bd9Sstevel@tonic-gate usba_pipe_new_state(ph_data,
7057c478bd9Sstevel@tonic-gate USB_PIPE_STATE_IDLE);
7067c478bd9Sstevel@tonic-gate break;
7077c478bd9Sstevel@tonic-gate case USB_CR_PIPE_RESET:
7087c478bd9Sstevel@tonic-gate case USB_CR_FLUSHED:
7097c478bd9Sstevel@tonic-gate break;
7107c478bd9Sstevel@tonic-gate default:
7117c478bd9Sstevel@tonic-gate usba_pipe_new_state(ph_data,
7127c478bd9Sstevel@tonic-gate USB_PIPE_STATE_ERROR);
7137c478bd9Sstevel@tonic-gate break;
7147c478bd9Sstevel@tonic-gate }
7157c478bd9Sstevel@tonic-gate }
7167c478bd9Sstevel@tonic-gate
7177c478bd9Sstevel@tonic-gate pipe_state = usba_get_ph_state(ph_data);
7187c478bd9Sstevel@tonic-gate
7197c478bd9Sstevel@tonic-gate mutex_exit(&ph_data->p_mutex);
7207c478bd9Sstevel@tonic-gate if (attrs & USB_ATTRS_PIPE_RESET) {
7217c478bd9Sstevel@tonic-gate if ((completion_reason != USB_CR_PIPE_RESET) &&
7227c478bd9Sstevel@tonic-gate (pipe_state == USB_PIPE_STATE_ERROR)) {
7237c478bd9Sstevel@tonic-gate
7247c478bd9Sstevel@tonic-gate hcdi_autoclearing(req_wrp);
7257c478bd9Sstevel@tonic-gate }
7267c478bd9Sstevel@tonic-gate }
7277c478bd9Sstevel@tonic-gate
7287c478bd9Sstevel@tonic-gate usba_req_exc_cb(req_wrp, 0, 0);
7297c478bd9Sstevel@tonic-gate mutex_enter(&ph_data->p_mutex);
7307c478bd9Sstevel@tonic-gate }
7317c478bd9Sstevel@tonic-gate
7327c478bd9Sstevel@tonic-gate /* Update the hcdi error kstats */
7337c478bd9Sstevel@tonic-gate if (completion_reason) {
7347c478bd9Sstevel@tonic-gate mutex_enter(&hcdi->hcdi_mutex);
7357c478bd9Sstevel@tonic-gate usba_hcdi_update_error_stats(hcdi, completion_reason);
7367c478bd9Sstevel@tonic-gate mutex_exit(&hcdi->hcdi_mutex);
7377c478bd9Sstevel@tonic-gate }
7387c478bd9Sstevel@tonic-gate
7397c478bd9Sstevel@tonic-gate /*
7407c478bd9Sstevel@tonic-gate * Once the callback is finished, release the pipe handle
7417c478bd9Sstevel@tonic-gate * we start the next request first to avoid that the
7427c478bd9Sstevel@tonic-gate * pipe gets closed while starting the next request
7437c478bd9Sstevel@tonic-gate */
7447c478bd9Sstevel@tonic-gate mutex_exit(&ph_data->p_mutex);
7457c478bd9Sstevel@tonic-gate usba_start_next_req(ph_data);
7467c478bd9Sstevel@tonic-gate
7477c478bd9Sstevel@tonic-gate mutex_enter(&ph_data->p_mutex);
7487c478bd9Sstevel@tonic-gate }
7497c478bd9Sstevel@tonic-gate
7507c478bd9Sstevel@tonic-gate
7517c478bd9Sstevel@tonic-gate /*
7527c478bd9Sstevel@tonic-gate * thread to perform callbacks on the shared queue
7537c478bd9Sstevel@tonic-gate */
7547c478bd9Sstevel@tonic-gate static void
hcdi_shared_cb_thread(void * arg)7557c478bd9Sstevel@tonic-gate hcdi_shared_cb_thread(void *arg)
7567c478bd9Sstevel@tonic-gate {
7577c478bd9Sstevel@tonic-gate usba_req_wrapper_t *req_wrp = (usba_req_wrapper_t *)arg;
7587c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph_data = req_wrp->wr_ph_data;
7597c478bd9Sstevel@tonic-gate usba_ph_impl_t *ph_impl = ph_data->p_ph_impl;
7607c478bd9Sstevel@tonic-gate usba_hcdi_t *hcdi = usba_hcdi_get_hcdi(ph_data->
7617c478bd9Sstevel@tonic-gate p_usba_device->usb_root_hub_dip);
7627c478bd9Sstevel@tonic-gate /*
7637c478bd9Sstevel@tonic-gate * hold the ph_data. we can't use usba_hold_ph_data() since
7647c478bd9Sstevel@tonic-gate * it will return NULL if we are closing the pipe which would
7657c478bd9Sstevel@tonic-gate * then leave all requests stuck in the cb_queue
7667c478bd9Sstevel@tonic-gate */
7677c478bd9Sstevel@tonic-gate mutex_enter(&ph_impl->usba_ph_mutex);
7687c478bd9Sstevel@tonic-gate ph_impl->usba_ph_ref_count++;
7697c478bd9Sstevel@tonic-gate
7707c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
7717c478bd9Sstevel@tonic-gate "hcdi_shared_cb_thread: ph_data=0x%p ref=%d req=0x%p",
772112116d8Sfb209375 (void *)ph_data, ph_impl->usba_ph_ref_count, (void *)req_wrp);
7737c478bd9Sstevel@tonic-gate mutex_exit(&ph_impl->usba_ph_mutex);
7747c478bd9Sstevel@tonic-gate
7757c478bd9Sstevel@tonic-gate /* do the callback */
7767c478bd9Sstevel@tonic-gate mutex_enter(&ph_data->p_mutex);
7777c478bd9Sstevel@tonic-gate hcdi_do_cb(ph_data, req_wrp, hcdi);
7787c478bd9Sstevel@tonic-gate mutex_exit(&ph_data->p_mutex);
7797c478bd9Sstevel@tonic-gate
7807c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
781112116d8Sfb209375 "hcdi_cb_thread done: ph_data=0x%p", (void *)ph_data);
7827c478bd9Sstevel@tonic-gate
7837c478bd9Sstevel@tonic-gate usba_release_ph_data(ph_impl);
7847c478bd9Sstevel@tonic-gate }
7857c478bd9Sstevel@tonic-gate
7867c478bd9Sstevel@tonic-gate
7877c478bd9Sstevel@tonic-gate /*
7887c478bd9Sstevel@tonic-gate * soft interrupt handler
7897c478bd9Sstevel@tonic-gate */
7907c478bd9Sstevel@tonic-gate /*ARGSUSED*/
7917c478bd9Sstevel@tonic-gate static uint_t
hcdi_soft_intr(caddr_t arg1,caddr_t arg2)7927c478bd9Sstevel@tonic-gate hcdi_soft_intr(caddr_t arg1, caddr_t arg2)
7937c478bd9Sstevel@tonic-gate {
794d29f5a71Szhigang lu - Sun Microsystems - Beijing China usba_hcdi_t *hcdi = (void *)arg1;
7957c478bd9Sstevel@tonic-gate usba_req_wrapper_t *req_wrp;
7967c478bd9Sstevel@tonic-gate int count = 0;
7977c478bd9Sstevel@tonic-gate
7987c478bd9Sstevel@tonic-gate while ((req_wrp = (usba_req_wrapper_t *)
7997c478bd9Sstevel@tonic-gate usba_rm_first_pvt_from_list(&hcdi->hcdi_cb_queue)) != NULL) {
8007c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph_data = req_wrp->wr_ph_data;
8017c478bd9Sstevel@tonic-gate usba_ph_impl_t *ph_impl = ph_data->p_ph_impl;
8027c478bd9Sstevel@tonic-gate
8037c478bd9Sstevel@tonic-gate /* hold the pipe */
8047c478bd9Sstevel@tonic-gate mutex_enter(&ph_impl->usba_ph_mutex);
8057c478bd9Sstevel@tonic-gate ph_impl->usba_ph_ref_count++;
8067c478bd9Sstevel@tonic-gate mutex_exit(&ph_impl->usba_ph_mutex);
8077c478bd9Sstevel@tonic-gate
8087c478bd9Sstevel@tonic-gate /* do the callback */
8097c478bd9Sstevel@tonic-gate usba_req_normal_cb(req_wrp);
8107c478bd9Sstevel@tonic-gate
8117c478bd9Sstevel@tonic-gate /* decrement the soft interrupt count */
8127c478bd9Sstevel@tonic-gate mutex_enter(&ph_data->p_mutex);
8137c478bd9Sstevel@tonic-gate ph_data->p_soft_intr--;
8147c478bd9Sstevel@tonic-gate mutex_exit(&ph_data->p_mutex);
8157c478bd9Sstevel@tonic-gate
8167c478bd9Sstevel@tonic-gate /* release the pipe */
8177c478bd9Sstevel@tonic-gate mutex_enter(&ph_impl->usba_ph_mutex);
8187c478bd9Sstevel@tonic-gate ph_impl->usba_ph_ref_count--;
8197c478bd9Sstevel@tonic-gate mutex_exit(&ph_impl->usba_ph_mutex);
8207c478bd9Sstevel@tonic-gate
8217c478bd9Sstevel@tonic-gate count++;
8227c478bd9Sstevel@tonic-gate }
8237c478bd9Sstevel@tonic-gate
8247c478bd9Sstevel@tonic-gate return (count == 0 ? DDI_INTR_UNCLAIMED : DDI_INTR_CLAIMED);
8257c478bd9Sstevel@tonic-gate }
8267c478bd9Sstevel@tonic-gate
8277c478bd9Sstevel@tonic-gate
8287c478bd9Sstevel@tonic-gate /*
8297c478bd9Sstevel@tonic-gate * hcdi_autoclearing:
8307c478bd9Sstevel@tonic-gate * This function is called under the taskq context. It
8317c478bd9Sstevel@tonic-gate * resets the pipe, and clears the stall, if necessary
8327c478bd9Sstevel@tonic-gate */
8337c478bd9Sstevel@tonic-gate static void
hcdi_autoclearing(usba_req_wrapper_t * req_wrp)8347c478bd9Sstevel@tonic-gate hcdi_autoclearing(usba_req_wrapper_t *req_wrp)
8357c478bd9Sstevel@tonic-gate {
8367c478bd9Sstevel@tonic-gate usb_cr_t cr = req_wrp->wr_cr;
8377c478bd9Sstevel@tonic-gate usb_pipe_handle_t pipe_handle, def_pipe_handle;
8387c478bd9Sstevel@tonic-gate usb_cr_t completion_reason;
8397c478bd9Sstevel@tonic-gate usb_cb_flags_t cb_flags;
8407c478bd9Sstevel@tonic-gate int rval;
8417c478bd9Sstevel@tonic-gate usba_device_t *usba_device =
8427c478bd9Sstevel@tonic-gate req_wrp->wr_ph_data->p_usba_device;
8437c478bd9Sstevel@tonic-gate usba_hcdi_t *hcdi = usba_hcdi_get_hcdi(
8447c478bd9Sstevel@tonic-gate usba_device->usb_root_hub_dip);
8457c478bd9Sstevel@tonic-gate usb_req_attrs_t attrs = req_wrp->wr_attrs;
8467c478bd9Sstevel@tonic-gate
8477c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(DPRINT_MASK_HCDI, hcdi->hcdi_log_handle,
848112116d8Sfb209375 "hcdi_autoclearing: wrp=0x%p", (void *)req_wrp);
8497c478bd9Sstevel@tonic-gate
8507c478bd9Sstevel@tonic-gate pipe_handle = usba_get_pipe_handle(req_wrp->wr_ph_data);
8517c478bd9Sstevel@tonic-gate def_pipe_handle = usba_get_dflt_pipe_handle(req_wrp->wr_ph_data->p_dip);
8527c478bd9Sstevel@tonic-gate
8537c478bd9Sstevel@tonic-gate /*
8547c478bd9Sstevel@tonic-gate * first reset the pipe synchronously
8557c478bd9Sstevel@tonic-gate */
8567c478bd9Sstevel@tonic-gate if ((attrs & USB_ATTRS_PIPE_RESET) == USB_ATTRS_PIPE_RESET) {
8577c478bd9Sstevel@tonic-gate usba_pipe_clear(pipe_handle);
8587c478bd9Sstevel@tonic-gate usba_req_set_cb_flags(req_wrp, USB_CB_RESET_PIPE);
8597c478bd9Sstevel@tonic-gate }
8607c478bd9Sstevel@tonic-gate
8617c478bd9Sstevel@tonic-gate ASSERT(def_pipe_handle);
8627c478bd9Sstevel@tonic-gate
8637c478bd9Sstevel@tonic-gate /* Do not clear if this request was a usb_get_status request */
8647c478bd9Sstevel@tonic-gate if ((pipe_handle == def_pipe_handle) &&
8657c478bd9Sstevel@tonic-gate (USBA_WRP2CTRL_REQ(req_wrp)->ctrl_bRequest ==
8667c478bd9Sstevel@tonic-gate USB_REQ_GET_STATUS)) {
8677c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(DPRINT_MASK_USBAI, hcdi->hcdi_log_handle,
8687c478bd9Sstevel@tonic-gate "hcdi_autoclearing: usb_get_status failed, no clearing");
8697c478bd9Sstevel@tonic-gate
8707c478bd9Sstevel@tonic-gate /* if default pipe and stall no auto clearing */
8717c478bd9Sstevel@tonic-gate } else if ((pipe_handle == def_pipe_handle) && (cr == USB_CR_STALL)) {
8727c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(DPRINT_MASK_USBAI, hcdi->hcdi_log_handle,
8737c478bd9Sstevel@tonic-gate "hcdi_autoclearing: default pipe stalled, no clearing");
8747c478bd9Sstevel@tonic-gate
8757c478bd9Sstevel@tonic-gate usba_req_set_cb_flags(req_wrp, USB_CB_PROTOCOL_STALL);
8767c478bd9Sstevel@tonic-gate
8777c478bd9Sstevel@tonic-gate /* else do auto clearing */
8787c478bd9Sstevel@tonic-gate } else if (((attrs & USB_ATTRS_AUTOCLEARING) ==
8797c478bd9Sstevel@tonic-gate USB_ATTRS_AUTOCLEARING) && (cr == USB_CR_STALL)) {
8807c478bd9Sstevel@tonic-gate ushort_t status = 0;
8817c478bd9Sstevel@tonic-gate
8827c478bd9Sstevel@tonic-gate rval = usb_get_status(req_wrp->wr_dip, def_pipe_handle,
8837c478bd9Sstevel@tonic-gate USB_DEV_REQ_DEV_TO_HOST | USB_DEV_REQ_RCPT_EP,
8847c478bd9Sstevel@tonic-gate req_wrp->wr_ph_data->p_ep.bEndpointAddress,
8857c478bd9Sstevel@tonic-gate &status, USB_FLAGS_SLEEP);
8867c478bd9Sstevel@tonic-gate if (rval != USB_SUCCESS) {
8877c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(DPRINT_MASK_USBAI, hcdi->hcdi_log_handle,
8887c478bd9Sstevel@tonic-gate "get status (STALL) failed: rval=%d", rval);
8897c478bd9Sstevel@tonic-gate
8907c478bd9Sstevel@tonic-gate usba_pipe_clear(def_pipe_handle);
8917c478bd9Sstevel@tonic-gate }
8927c478bd9Sstevel@tonic-gate
8937c478bd9Sstevel@tonic-gate if ((rval != USB_SUCCESS) ||
8947c478bd9Sstevel@tonic-gate (status & USB_EP_HALT_STATUS)) {
8957c478bd9Sstevel@tonic-gate usba_req_set_cb_flags(req_wrp, USB_CB_FUNCTIONAL_STALL);
8967c478bd9Sstevel@tonic-gate
8977c478bd9Sstevel@tonic-gate if ((rval = usb_pipe_sync_ctrl_xfer(
8987c478bd9Sstevel@tonic-gate req_wrp->wr_dip, def_pipe_handle,
8997c478bd9Sstevel@tonic-gate USB_DEV_REQ_HOST_TO_DEV |
9007c478bd9Sstevel@tonic-gate USB_DEV_REQ_RCPT_EP,
9017c478bd9Sstevel@tonic-gate USB_REQ_CLEAR_FEATURE,
9027c478bd9Sstevel@tonic-gate 0,
9037c478bd9Sstevel@tonic-gate req_wrp->wr_ph_data->p_ep.bEndpointAddress,
9047c478bd9Sstevel@tonic-gate 0,
9057c478bd9Sstevel@tonic-gate NULL, 0,
9067c478bd9Sstevel@tonic-gate &completion_reason,
9077c478bd9Sstevel@tonic-gate &cb_flags, USB_FLAGS_SLEEP)) != USB_SUCCESS) {
9087c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(DPRINT_MASK_USBAI,
9097c478bd9Sstevel@tonic-gate hcdi->hcdi_log_handle,
9107c478bd9Sstevel@tonic-gate "auto clearing (STALL) failed: "
9117c478bd9Sstevel@tonic-gate "rval=%d, cr=0x%x cb=0x%x",
9127c478bd9Sstevel@tonic-gate rval, completion_reason, cb_flags);
9137c478bd9Sstevel@tonic-gate
9147c478bd9Sstevel@tonic-gate usba_pipe_clear(def_pipe_handle);
9157c478bd9Sstevel@tonic-gate } else {
9167c478bd9Sstevel@tonic-gate usba_req_set_cb_flags(req_wrp,
9177c478bd9Sstevel@tonic-gate USB_CB_STALL_CLEARED);
9187c478bd9Sstevel@tonic-gate }
9197c478bd9Sstevel@tonic-gate } else {
9207c478bd9Sstevel@tonic-gate usba_req_set_cb_flags(req_wrp, USB_CB_PROTOCOL_STALL);
9217c478bd9Sstevel@tonic-gate }
9227c478bd9Sstevel@tonic-gate }
9237c478bd9Sstevel@tonic-gate }
9247c478bd9Sstevel@tonic-gate
9257c478bd9Sstevel@tonic-gate
9267c478bd9Sstevel@tonic-gate /*
9277c478bd9Sstevel@tonic-gate * usba_hcdi_get_req_private:
9287c478bd9Sstevel@tonic-gate * This function is used to get the HCD private field
9297c478bd9Sstevel@tonic-gate * maintained by USBA. HCD calls this function.
9307c478bd9Sstevel@tonic-gate *
9317c478bd9Sstevel@tonic-gate * Arguments:
9327c478bd9Sstevel@tonic-gate * req - pointer to usb_*_req_t
9337c478bd9Sstevel@tonic-gate *
9347c478bd9Sstevel@tonic-gate * Return Values:
9357c478bd9Sstevel@tonic-gate * wr_hcd_private field from wrapper
9367c478bd9Sstevel@tonic-gate */
9377c478bd9Sstevel@tonic-gate usb_opaque_t
usba_hcdi_get_req_private(usb_opaque_t req)9387c478bd9Sstevel@tonic-gate usba_hcdi_get_req_private(usb_opaque_t req)
9397c478bd9Sstevel@tonic-gate {
9407c478bd9Sstevel@tonic-gate usba_req_wrapper_t *wrp = USBA_REQ2WRP(req);
9417c478bd9Sstevel@tonic-gate
9427c478bd9Sstevel@tonic-gate return (wrp->wr_hcd_private);
9437c478bd9Sstevel@tonic-gate }
9447c478bd9Sstevel@tonic-gate
9457c478bd9Sstevel@tonic-gate
9467c478bd9Sstevel@tonic-gate /*
9477c478bd9Sstevel@tonic-gate * usba_hcdi_set_req_private:
9487c478bd9Sstevel@tonic-gate * This function is used to set the HCD private field
9497c478bd9Sstevel@tonic-gate * maintained by USBA. HCD calls this function.
9507c478bd9Sstevel@tonic-gate *
9517c478bd9Sstevel@tonic-gate * Arguments:
9527c478bd9Sstevel@tonic-gate * req - pointer to usb_*_req_t
9537c478bd9Sstevel@tonic-gate * hcd_private - wr_hcd_private field from wrapper
9547c478bd9Sstevel@tonic-gate */
9557c478bd9Sstevel@tonic-gate void
usba_hcdi_set_req_private(usb_opaque_t req,usb_opaque_t hcd_private)9567c478bd9Sstevel@tonic-gate usba_hcdi_set_req_private(usb_opaque_t req,
9577c478bd9Sstevel@tonic-gate usb_opaque_t hcd_private)
9587c478bd9Sstevel@tonic-gate {
9597c478bd9Sstevel@tonic-gate usba_req_wrapper_t *wrp = USBA_REQ2WRP(req);
9607c478bd9Sstevel@tonic-gate
9617c478bd9Sstevel@tonic-gate wrp->wr_hcd_private = hcd_private;
9627c478bd9Sstevel@tonic-gate }
9637c478bd9Sstevel@tonic-gate
9647c478bd9Sstevel@tonic-gate
9657c478bd9Sstevel@tonic-gate /* get data toggle information for this endpoint */
9667c478bd9Sstevel@tonic-gate uchar_t
usba_hcdi_get_data_toggle(usba_device_t * usba_device,uint8_t ep_addr)9677c478bd9Sstevel@tonic-gate usba_hcdi_get_data_toggle(usba_device_t *usba_device, uint8_t ep_addr)
9687c478bd9Sstevel@tonic-gate {
9697c478bd9Sstevel@tonic-gate uchar_t toggle;
9707c478bd9Sstevel@tonic-gate usba_ph_impl_t *ph_impl;
9717c478bd9Sstevel@tonic-gate int ep_index;
9727c478bd9Sstevel@tonic-gate
9737c478bd9Sstevel@tonic-gate ep_index = usb_get_ep_index(ep_addr);
9747c478bd9Sstevel@tonic-gate mutex_enter(&usba_device->usb_mutex);
9757c478bd9Sstevel@tonic-gate ph_impl = &usba_device->usb_ph_list[ep_index];
9767c478bd9Sstevel@tonic-gate mutex_enter(&ph_impl->usba_ph_mutex);
9777c478bd9Sstevel@tonic-gate toggle = (uchar_t)(ph_impl->usba_ph_flags & USBA_PH_DATA_TOGGLE);
9787c478bd9Sstevel@tonic-gate mutex_exit(&ph_impl->usba_ph_mutex);
9797c478bd9Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex);
9807c478bd9Sstevel@tonic-gate
9817c478bd9Sstevel@tonic-gate return (toggle);
9827c478bd9Sstevel@tonic-gate }
9837c478bd9Sstevel@tonic-gate
9847c478bd9Sstevel@tonic-gate
9857c478bd9Sstevel@tonic-gate /* set data toggle information for this endpoint */
9867c478bd9Sstevel@tonic-gate void
usba_hcdi_set_data_toggle(usba_device_t * usba_device,uint8_t ep_addr,uchar_t toggle)9877c478bd9Sstevel@tonic-gate usba_hcdi_set_data_toggle(usba_device_t *usba_device, uint8_t ep_addr,
9887c478bd9Sstevel@tonic-gate uchar_t toggle)
9897c478bd9Sstevel@tonic-gate {
9907c478bd9Sstevel@tonic-gate usba_ph_impl_t *ph_impl;
9917c478bd9Sstevel@tonic-gate int ep_index;
9927c478bd9Sstevel@tonic-gate
9937c478bd9Sstevel@tonic-gate ep_index = usb_get_ep_index(ep_addr);
9947c478bd9Sstevel@tonic-gate mutex_enter(&usba_device->usb_mutex);
9957c478bd9Sstevel@tonic-gate ph_impl = &usba_device->usb_ph_list[ep_index];
9967c478bd9Sstevel@tonic-gate mutex_enter(&ph_impl->usba_ph_mutex);
9977c478bd9Sstevel@tonic-gate ph_impl->usba_ph_flags &= ~USBA_PH_DATA_TOGGLE;
9987c478bd9Sstevel@tonic-gate ph_impl->usba_ph_flags |= (USBA_PH_DATA_TOGGLE & toggle);
9997c478bd9Sstevel@tonic-gate mutex_exit(&ph_impl->usba_ph_mutex);
10007c478bd9Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex);
10017c478bd9Sstevel@tonic-gate }
10027c478bd9Sstevel@tonic-gate
10037c478bd9Sstevel@tonic-gate
10047c478bd9Sstevel@tonic-gate /* get pipe_handle_impl ptr for this ep */
10057c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *
usba_hcdi_get_ph_data(usba_device_t * usba_device,uint8_t ep_addr)10067c478bd9Sstevel@tonic-gate usba_hcdi_get_ph_data(usba_device_t *usba_device, uint8_t ep_addr)
10077c478bd9Sstevel@tonic-gate {
10087c478bd9Sstevel@tonic-gate return (usba_device->usb_ph_list[usb_get_ep_index(ep_addr)].
10097c478bd9Sstevel@tonic-gate usba_ph_data);
10107c478bd9Sstevel@tonic-gate }
1011