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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  * EHCI Host Controller Driver (EHCI)
307c478bd9Sstevel@tonic-gate  *
317c478bd9Sstevel@tonic-gate  * The EHCI driver is a software driver which interfaces to the Universal
327c478bd9Sstevel@tonic-gate  * Serial Bus layer (USBA) and the Host Controller (HC). The interface to
337c478bd9Sstevel@tonic-gate  * the Host Controller is defined by the EHCI Host Controller Interface.
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * This module contains the specific EHCI code used in POLLED mode. This
367c478bd9Sstevel@tonic-gate  * code is in a separate file since it will never become part of the EHCI
377c478bd9Sstevel@tonic-gate  * driver.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #include <sys/usb/usba/usbai_version.h>
417c478bd9Sstevel@tonic-gate #include <sys/usb/hcd/ehci/ehcid.h>
427c478bd9Sstevel@tonic-gate #include <sys/usb/hcd/ehci/ehci_xfer.h>
437c478bd9Sstevel@tonic-gate #include <sys/usb/hcd/ehci/ehci_intr.h>
447c478bd9Sstevel@tonic-gate #include <sys/usb/hcd/ehci/ehci_util.h>
457c478bd9Sstevel@tonic-gate #include <sys/usb/hcd/ehci/ehci_polled.h>
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * Internal Function Prototypes
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /* Polled initialization routines */
527c478bd9Sstevel@tonic-gate static int	ehci_polled_init(
537c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph,
547c478bd9Sstevel@tonic-gate 				ehci_state_t		*ehcip,
557c478bd9Sstevel@tonic-gate 				usb_console_info_impl_t	*console_input_info);
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate /* Polled deinitialization routines */
587c478bd9Sstevel@tonic-gate static int	ehci_polled_fini(ehci_polled_t		*ehci_polledp);
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /* Polled save state routines */
617c478bd9Sstevel@tonic-gate static void	ehci_polled_save_state(ehci_polled_t	*ehci_polledp);
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate /* Polled restore state routines */
647c478bd9Sstevel@tonic-gate static void	ehci_polled_restore_state(ehci_polled_t	*ehci_polledp);
657c478bd9Sstevel@tonic-gate static void	ehci_polled_stop_processing(
667c478bd9Sstevel@tonic-gate 				ehci_polled_t		*ehci_polledp);
677c478bd9Sstevel@tonic-gate static void	ehci_polled_start_processing(
687c478bd9Sstevel@tonic-gate 				ehci_polled_t		*ehci_polledp);
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate /* Polled read routines */
717c478bd9Sstevel@tonic-gate static int	ehci_polled_process_active_intr_qtd_list(
727c478bd9Sstevel@tonic-gate 				ehci_polled_t		*ehci_polledp);
737c478bd9Sstevel@tonic-gate static int	ehci_polled_handle_normal_qtd(
747c478bd9Sstevel@tonic-gate 				ehci_polled_t		*ehci_polledp,
757c478bd9Sstevel@tonic-gate 				ehci_qtd_t		*qtd);
767c478bd9Sstevel@tonic-gate static void	ehci_polled_insert_qtd(
777c478bd9Sstevel@tonic-gate 				ehci_polled_t		*ehci_polledp,
787c478bd9Sstevel@tonic-gate 				ehci_qtd_t		*qtd);
797c478bd9Sstevel@tonic-gate static void	ehci_polled_fill_in_qtd(
807c478bd9Sstevel@tonic-gate 				ehci_state_t		*ehcip,
817c478bd9Sstevel@tonic-gate 				ehci_qtd_t		*qtd,
827c478bd9Sstevel@tonic-gate 				uint_t			qtd_ctrl,
837c478bd9Sstevel@tonic-gate 				uint32_t		qtd_iommu_cbp,
847c478bd9Sstevel@tonic-gate 				size_t			qtd_length,
857c478bd9Sstevel@tonic-gate 				ehci_trans_wrapper_t	*tw);
867c478bd9Sstevel@tonic-gate static void	ehci_polled_insert_qtd_on_tw(
877c478bd9Sstevel@tonic-gate 				ehci_state_t		*ehcip,
887c478bd9Sstevel@tonic-gate 				ehci_trans_wrapper_t	*tw,
897c478bd9Sstevel@tonic-gate 				ehci_qtd_t		*qtd);
907c478bd9Sstevel@tonic-gate static ehci_qtd_t *ehci_polled_create_done_qtd_list(
917c478bd9Sstevel@tonic-gate 				ehci_polled_t		*ehci_polledp);
927c478bd9Sstevel@tonic-gate static void	ehci_polled_insert_qtd_into_active_intr_qtd_list(
937c478bd9Sstevel@tonic-gate 				ehci_polled_t		*ehci_polledp,
947c478bd9Sstevel@tonic-gate 				ehci_qtd_t		*curr_qtd);
957c478bd9Sstevel@tonic-gate static void	ehci_polled_remove_qtd_from_active_intr_qtd_list(
967c478bd9Sstevel@tonic-gate 				ehci_polled_t		*ehci_polledp,
977c478bd9Sstevel@tonic-gate 				ehci_qtd_t		*curr_qtd);
987c478bd9Sstevel@tonic-gate static void	ehci_polled_traverse_qtds(
997c478bd9Sstevel@tonic-gate 				ehci_polled_t		*ehci_polledp,
1007c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph);
1017c478bd9Sstevel@tonic-gate static void	ehci_polled_finish_interrupt(
1027c478bd9Sstevel@tonic-gate 				ehci_state_t		*ehcip,
1037c478bd9Sstevel@tonic-gate 				uint_t			intr);
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate /*
1067c478bd9Sstevel@tonic-gate  * POLLED entry points
1077c478bd9Sstevel@tonic-gate  *
1087c478bd9Sstevel@tonic-gate  * These functions are entry points into the POLLED code.
1097c478bd9Sstevel@tonic-gate  */
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate /*
1127c478bd9Sstevel@tonic-gate  * ehci_hcdi_polled_input_init:
1137c478bd9Sstevel@tonic-gate  *
1147c478bd9Sstevel@tonic-gate  * This is the initialization routine for handling the USB keyboard
1157c478bd9Sstevel@tonic-gate  * in POLLED mode.  This routine is not called from POLLED mode, so
1167c478bd9Sstevel@tonic-gate  * it is OK to acquire mutexes.
1177c478bd9Sstevel@tonic-gate  */
1187c478bd9Sstevel@tonic-gate int
1197c478bd9Sstevel@tonic-gate ehci_hcdi_polled_input_init(
1207c478bd9Sstevel@tonic-gate 	usba_pipe_handle_data_t	*ph,
1217c478bd9Sstevel@tonic-gate 	uchar_t			**polled_buf,
1227c478bd9Sstevel@tonic-gate 	usb_console_info_impl_t	*console_input_info)
1237c478bd9Sstevel@tonic-gate {
1247c478bd9Sstevel@tonic-gate 	ehci_polled_t		*ehci_polledp;
1257c478bd9Sstevel@tonic-gate 	ehci_state_t		*ehcip;
1267c478bd9Sstevel@tonic-gate 	int			ret;
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 	ehcip = ehci_obtain_state(ph->p_usba_device->usb_root_hub_dip);
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	/*
1317c478bd9Sstevel@tonic-gate 	 * Grab the ehci_int_mutex so that things don't change on us
1327c478bd9Sstevel@tonic-gate 	 * if an interrupt comes in.
1337c478bd9Sstevel@tonic-gate 	 */
1347c478bd9Sstevel@tonic-gate 	mutex_enter(&ehcip->ehci_int_mutex);
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate 	ret = ehci_polled_init(ph, ehcip, console_input_info);
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 	if (ret != USB_SUCCESS) {
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate 		/* Allow interrupts to continue */
1417c478bd9Sstevel@tonic-gate 		mutex_exit(&ehcip->ehci_int_mutex);
1427c478bd9Sstevel@tonic-gate 		return (ret);
1437c478bd9Sstevel@tonic-gate 	}
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 	ehci_polledp = (ehci_polled_t *)console_input_info->uci_private;
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 	/*
1487c478bd9Sstevel@tonic-gate 	 * Mark the structure so that if we are using it, we don't free
1497c478bd9Sstevel@tonic-gate 	 * the structures if one of them is unplugged.
1507c478bd9Sstevel@tonic-gate 	 */
1517c478bd9Sstevel@tonic-gate 	ehci_polledp->ehci_polled_flags |= POLLED_INPUT_MODE;
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate 	/* increase the counter for keyboard connected */
1547c478bd9Sstevel@tonic-gate 	ehcip->ehci_polled_kbd_count ++;
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 	/*
1577c478bd9Sstevel@tonic-gate 	 * This is the buffer we will copy characters into. It will be
1587c478bd9Sstevel@tonic-gate 	 * copied into at this layer, so we need to keep track of it.
1597c478bd9Sstevel@tonic-gate 	 */
1607c478bd9Sstevel@tonic-gate 	ehci_polledp->ehci_polled_buf =
1617c478bd9Sstevel@tonic-gate 	    (uchar_t *)kmem_zalloc(POLLED_RAW_BUF_SIZE, KM_SLEEP);
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 	*polled_buf = ehci_polledp->ehci_polled_buf;
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 	/*
1667c478bd9Sstevel@tonic-gate 	 * This is a software workaround to fix schizo hardware bug.
1677c478bd9Sstevel@tonic-gate 	 * Existence of "no-prom-cdma-sync"  property means consistent
1687c478bd9Sstevel@tonic-gate 	 * dma sync should not be done while in prom or polled mode.
1697c478bd9Sstevel@tonic-gate 	 */
1707c478bd9Sstevel@tonic-gate 	if (ddi_prop_exists(DDI_DEV_T_ANY, ehcip->ehci_dip,
1717c478bd9Sstevel@tonic-gate 	    DDI_PROP_NOTPROM, "no-prom-cdma-sync")) {
1727c478bd9Sstevel@tonic-gate 		ehci_polledp->ehci_polled_no_sync_flag = B_TRUE;
1737c478bd9Sstevel@tonic-gate 	}
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 	/* Allow interrupts to continue */
1767c478bd9Sstevel@tonic-gate 	mutex_exit(&ehcip->ehci_int_mutex);
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 	return (USB_SUCCESS);
1797c478bd9Sstevel@tonic-gate }
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate /*
1837c478bd9Sstevel@tonic-gate  * ehci_hcdi_polled_input_fini:
1847c478bd9Sstevel@tonic-gate  */
1857c478bd9Sstevel@tonic-gate int
1867c478bd9Sstevel@tonic-gate ehci_hcdi_polled_input_fini(usb_console_info_impl_t *info)
1877c478bd9Sstevel@tonic-gate {
1887c478bd9Sstevel@tonic-gate 	ehci_polled_t		*ehci_polledp;
1897c478bd9Sstevel@tonic-gate 	ehci_state_t		*ehcip;
1907c478bd9Sstevel@tonic-gate 	int			ret;
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 	ehci_polledp = (ehci_polled_t *)info->uci_private;
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 	ehcip = ehci_polledp->ehci_polled_ehcip;
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate 	mutex_enter(&ehcip->ehci_int_mutex);
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 	/*
1997c478bd9Sstevel@tonic-gate 	 * Reset the POLLED_INPUT_MODE flag so that we can tell if
2007c478bd9Sstevel@tonic-gate 	 * this structure is in use in the ehci_polled_fini routine.
2017c478bd9Sstevel@tonic-gate 	 */
2027c478bd9Sstevel@tonic-gate 	ehci_polledp->ehci_polled_flags &= ~POLLED_INPUT_MODE;
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate 	/* decrease the counter for keyboard disconnected */
2057c478bd9Sstevel@tonic-gate 	ehcip->ehci_polled_kbd_count --;
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate 	/* Free the buffer that we copied data into */
2087c478bd9Sstevel@tonic-gate 	kmem_free(ehci_polledp->ehci_polled_buf, POLLED_RAW_BUF_SIZE);
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 	ret = ehci_polled_fini(ehci_polledp);
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 	mutex_exit(&ehcip->ehci_int_mutex);
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate 	return (ret);
2157c478bd9Sstevel@tonic-gate }
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate /*
2197c478bd9Sstevel@tonic-gate  * ehci_hcdi_polled_input_enter:
2207c478bd9Sstevel@tonic-gate  *
2217c478bd9Sstevel@tonic-gate  * This is where we enter into POLLED mode.  This routine sets up
2227c478bd9Sstevel@tonic-gate  * everything so that calls to	ehci_hcdi_polled_read will return
2237c478bd9Sstevel@tonic-gate  * characters.
2247c478bd9Sstevel@tonic-gate  */
2257c478bd9Sstevel@tonic-gate int
2267c478bd9Sstevel@tonic-gate ehci_hcdi_polled_input_enter(usb_console_info_impl_t *info)
2277c478bd9Sstevel@tonic-gate {
2287c478bd9Sstevel@tonic-gate 	ehci_polled_t		*ehci_polledp;
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate 	ehci_polledp = (ehci_polled_t *)info->uci_private;
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate 	ehci_polledp->ehci_polled_entry++;
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate 	/*
2357c478bd9Sstevel@tonic-gate 	 * If the controller is already switched over, just return
2367c478bd9Sstevel@tonic-gate 	 */
2377c478bd9Sstevel@tonic-gate 	if (ehci_polledp->ehci_polled_entry > 1) {
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 		return (USB_SUCCESS);
2407c478bd9Sstevel@tonic-gate 	}
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 	ehci_polled_save_state(ehci_polledp);
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 	ehci_polledp->ehci_polled_flags |= POLLED_INPUT_MODE_INUSE;
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate 	return (USB_SUCCESS);
2477c478bd9Sstevel@tonic-gate }
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate /*
2517c478bd9Sstevel@tonic-gate  * ehci_hcdi_polled_input_exit:
2527c478bd9Sstevel@tonic-gate  *
2537c478bd9Sstevel@tonic-gate  * This is where we exit POLLED mode. This routine restores
2547c478bd9Sstevel@tonic-gate  * everything that is needed to continue operation.
2557c478bd9Sstevel@tonic-gate  */
2567c478bd9Sstevel@tonic-gate int
2577c478bd9Sstevel@tonic-gate ehci_hcdi_polled_input_exit(usb_console_info_impl_t *info)
2587c478bd9Sstevel@tonic-gate {
2597c478bd9Sstevel@tonic-gate 	ehci_polled_t		*ehci_polledp;
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate 	ehci_polledp = (ehci_polled_t *)info->uci_private;
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate 	ehci_polledp->ehci_polled_entry--;
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate 	/*
2667c478bd9Sstevel@tonic-gate 	 * If there are still outstanding "enters", just return
2677c478bd9Sstevel@tonic-gate 	 */
2687c478bd9Sstevel@tonic-gate 	if (ehci_polledp->ehci_polled_entry > 0) {
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate 		return (USB_SUCCESS);
2717c478bd9Sstevel@tonic-gate 	}
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate 	ehci_polledp->ehci_polled_flags &= ~POLLED_INPUT_MODE_INUSE;
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 	ehci_polled_restore_state(ehci_polledp);
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 	return (USB_SUCCESS);
2787c478bd9Sstevel@tonic-gate }
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate /*
2827c478bd9Sstevel@tonic-gate  * ehci_hcdi_polled_read:
2837c478bd9Sstevel@tonic-gate  *
2847c478bd9Sstevel@tonic-gate  * Get a key character
2857c478bd9Sstevel@tonic-gate  */
2867c478bd9Sstevel@tonic-gate int
2877c478bd9Sstevel@tonic-gate ehci_hcdi_polled_read(
2887c478bd9Sstevel@tonic-gate 	usb_console_info_impl_t	*info,
2897c478bd9Sstevel@tonic-gate 	uint_t			*num_characters)
2907c478bd9Sstevel@tonic-gate {
2917c478bd9Sstevel@tonic-gate 	ehci_state_t		*ehcip;
2927c478bd9Sstevel@tonic-gate 	ehci_polled_t		*ehci_polledp;
2937c478bd9Sstevel@tonic-gate 	uint_t			intr;
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate 	ehci_polledp = (ehci_polled_t *)info->uci_private;
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate 	ehcip = ehci_polledp->ehci_polled_ehcip;
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate #ifndef lint
3007c478bd9Sstevel@tonic-gate 	_NOTE(NO_COMPETING_THREADS_NOW);
3017c478bd9Sstevel@tonic-gate #endif
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 	*num_characters = 0;
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate 	intr = ((Get_OpReg(ehci_status) & Get_OpReg(ehci_interrupt)) &
3067c478bd9Sstevel@tonic-gate 	    (EHCI_INTR_FRAME_LIST_ROLLOVER |
3077c478bd9Sstevel@tonic-gate 	    EHCI_INTR_USB | EHCI_INTR_USB_ERROR));
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate 	/*
3107c478bd9Sstevel@tonic-gate 	 * Check whether any frame list rollover interrupt is pending
3117c478bd9Sstevel@tonic-gate 	 * and if it is pending, process this interrupt.
3127c478bd9Sstevel@tonic-gate 	 */
3137c478bd9Sstevel@tonic-gate 	if (intr & EHCI_INTR_FRAME_LIST_ROLLOVER) {
3147c478bd9Sstevel@tonic-gate 		/* Check any frame list rollover interrupt is pending */
3157c478bd9Sstevel@tonic-gate 		ehci_handle_frame_list_rollover(ehcip);
3167c478bd9Sstevel@tonic-gate 		ehci_polled_finish_interrupt(ehcip,
3177c478bd9Sstevel@tonic-gate 		    EHCI_INTR_FRAME_LIST_ROLLOVER);
3187c478bd9Sstevel@tonic-gate 	}
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 	/* Check for any USB transaction completion notification */
3217c478bd9Sstevel@tonic-gate 	if (intr & (EHCI_INTR_USB | EHCI_INTR_USB_ERROR)) {
3227c478bd9Sstevel@tonic-gate 		ehcip->ehci_polled_read_count ++;
3237c478bd9Sstevel@tonic-gate 		/* Process any QTD's on the active interrupt qtd list */
3247c478bd9Sstevel@tonic-gate 		*num_characters =
3257c478bd9Sstevel@tonic-gate 		    ehci_polled_process_active_intr_qtd_list(ehci_polledp);
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate 		if (ehcip->ehci_polled_read_count ==
3287c478bd9Sstevel@tonic-gate 		    ehcip->ehci_polled_enter_count) {
3297c478bd9Sstevel@tonic-gate 			/* Acknowledge the frame list rollover interrupt */
3307c478bd9Sstevel@tonic-gate 			ehci_polled_finish_interrupt(ehcip,
3317c478bd9Sstevel@tonic-gate 			    intr & (EHCI_INTR_USB | EHCI_INTR_USB_ERROR));
3327c478bd9Sstevel@tonic-gate 			ehcip->ehci_polled_read_count = 0;
3337c478bd9Sstevel@tonic-gate 		}
3347c478bd9Sstevel@tonic-gate 	}
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate #ifndef lint
3377c478bd9Sstevel@tonic-gate 	_NOTE(COMPETING_THREADS_NOW);
3387c478bd9Sstevel@tonic-gate #endif
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate 	return (USB_SUCCESS);
3417c478bd9Sstevel@tonic-gate }
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate /*
3457c478bd9Sstevel@tonic-gate  * Internal Functions
3467c478bd9Sstevel@tonic-gate  */
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate /*
3497c478bd9Sstevel@tonic-gate  * Polled initialization routines
3507c478bd9Sstevel@tonic-gate  */
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate /*
3547c478bd9Sstevel@tonic-gate  * ehci_polled_init:
3557c478bd9Sstevel@tonic-gate  *
3567c478bd9Sstevel@tonic-gate  * Initialize generic information Uthat is needed to provide USB/POLLED
3577c478bd9Sstevel@tonic-gate  * support.
3587c478bd9Sstevel@tonic-gate  */
3597c478bd9Sstevel@tonic-gate static int
3607c478bd9Sstevel@tonic-gate ehci_polled_init(
3617c478bd9Sstevel@tonic-gate 	usba_pipe_handle_data_t	*ph,
3627c478bd9Sstevel@tonic-gate 	ehci_state_t		*ehcip,
3637c478bd9Sstevel@tonic-gate 	usb_console_info_impl_t	*console_info)
3647c478bd9Sstevel@tonic-gate {
3657c478bd9Sstevel@tonic-gate 	ehci_polled_t		*ehci_polledp;
3667c478bd9Sstevel@tonic-gate 	ehci_pipe_private_t	*pp;
3677c478bd9Sstevel@tonic-gate 	ehci_qtd_t		*qtd;
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate 	ASSERT(mutex_owned(&ehcip->ehci_int_mutex));
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate 	/*
3727c478bd9Sstevel@tonic-gate 	 * We have already initialized this structure. If the structure
3737c478bd9Sstevel@tonic-gate 	 * has already been initialized, then we don't need to redo it.
3747c478bd9Sstevel@tonic-gate 	 */
3757c478bd9Sstevel@tonic-gate 	if (console_info->uci_private) {
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate 		return (USB_SUCCESS);
3787c478bd9Sstevel@tonic-gate 	}
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate 	/* Allocate and intitialize a state structure */
3817c478bd9Sstevel@tonic-gate 	ehci_polledp = (ehci_polled_t *)
3827c478bd9Sstevel@tonic-gate 	    kmem_zalloc(sizeof (ehci_polled_t), KM_SLEEP);
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate 	console_info->uci_private = (usb_console_info_private_t)ehci_polledp;
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate 	/*
3877c478bd9Sstevel@tonic-gate 	 * Store away the ehcip so that we can get to it when we are in
3887c478bd9Sstevel@tonic-gate 	 * POLLED mode. We don't want to have to call ehci_obtain_state
3897c478bd9Sstevel@tonic-gate 	 * every time we want to access this structure.
3907c478bd9Sstevel@tonic-gate 	 */
3917c478bd9Sstevel@tonic-gate 	ehci_polledp->ehci_polled_ehcip = ehcip;
3927c478bd9Sstevel@tonic-gate 	/*
3937c478bd9Sstevel@tonic-gate 	 * Save usb device and endpoint number information from the usb
3947c478bd9Sstevel@tonic-gate 	 * pipe handle.
3957c478bd9Sstevel@tonic-gate 	 */
3967c478bd9Sstevel@tonic-gate 	mutex_enter(&ph->p_mutex);
3977c478bd9Sstevel@tonic-gate 	ehci_polledp->ehci_polled_usb_dev = ph->p_usba_device;
3987c478bd9Sstevel@tonic-gate 	ehci_polledp->ehci_polled_ep_addr = ph->p_ep.bEndpointAddress;
3997c478bd9Sstevel@tonic-gate 	mutex_exit(&ph->p_mutex);
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate 	/*
4027c478bd9Sstevel@tonic-gate 	 * Allocate memory to make duplicate of original usb pipe handle.
4037c478bd9Sstevel@tonic-gate 	 */
4047c478bd9Sstevel@tonic-gate 	ehci_polledp->ehci_polled_input_pipe_handle =
4057c478bd9Sstevel@tonic-gate 	    kmem_zalloc(sizeof (usba_pipe_handle_data_t), KM_SLEEP);
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate 	/*
4087c478bd9Sstevel@tonic-gate 	 * Copy the USB handle into the new pipe handle. Also
4097c478bd9Sstevel@tonic-gate 	 * create new lock for the new pipe handle.
4107c478bd9Sstevel@tonic-gate 	 */
4117c478bd9Sstevel@tonic-gate 	bcopy((void *)ph,
4127c478bd9Sstevel@tonic-gate 	    (void *)ehci_polledp->ehci_polled_input_pipe_handle,
4137c478bd9Sstevel@tonic-gate 	    sizeof (usba_pipe_handle_data_t));
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate 	/*
4167c478bd9Sstevel@tonic-gate 	 * uint64_t typecast to make sure amd64 can compile
4177c478bd9Sstevel@tonic-gate 	 */
4187c478bd9Sstevel@tonic-gate 	mutex_init(&ehci_polledp->ehci_polled_input_pipe_handle->p_mutex,
419*a195726fSgovinda 	    NULL, MUTEX_DRIVER, DDI_INTR_PRI(ehcip->ehci_intr_pri));
4207c478bd9Sstevel@tonic-gate 
4217c478bd9Sstevel@tonic-gate 	/*
4227c478bd9Sstevel@tonic-gate 	 * Create a new ehci pipe private structure
4237c478bd9Sstevel@tonic-gate 	 */
4247c478bd9Sstevel@tonic-gate 	pp = (ehci_pipe_private_t *)
4257c478bd9Sstevel@tonic-gate 	    kmem_zalloc(sizeof (ehci_pipe_private_t), KM_SLEEP);
4267c478bd9Sstevel@tonic-gate 
4277c478bd9Sstevel@tonic-gate 	/*
4287c478bd9Sstevel@tonic-gate 	 * Store the pointer in the pipe handle. This structure was also
4297c478bd9Sstevel@tonic-gate 	 * just allocated.
4307c478bd9Sstevel@tonic-gate 	 */
4317c478bd9Sstevel@tonic-gate 	mutex_enter(&ehci_polledp->ehci_polled_input_pipe_handle->p_mutex);
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate 	ehci_polledp->ehci_polled_input_pipe_handle->
4347c478bd9Sstevel@tonic-gate 	    p_hcd_private = (usb_opaque_t)pp;
4357c478bd9Sstevel@tonic-gate 
4367c478bd9Sstevel@tonic-gate 	mutex_exit(&ehci_polledp->ehci_polled_input_pipe_handle->p_mutex);
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate 	/*
4397c478bd9Sstevel@tonic-gate 	 * Store a pointer to the pipe handle. This structure was  just
4407c478bd9Sstevel@tonic-gate 	 * allocated and it is not in use yet.	The locking is there to
4417c478bd9Sstevel@tonic-gate 	 * satisfy warlock.
4427c478bd9Sstevel@tonic-gate 	 */
4437c478bd9Sstevel@tonic-gate 	mutex_enter(&ph->p_mutex);
4447c478bd9Sstevel@tonic-gate 
4457c478bd9Sstevel@tonic-gate 	bcopy(&ph->p_policy, &pp->pp_policy, sizeof (usb_pipe_policy_t));
4467c478bd9Sstevel@tonic-gate 
4477c478bd9Sstevel@tonic-gate 	mutex_exit(&ph->p_mutex);
4487c478bd9Sstevel@tonic-gate 
4497c478bd9Sstevel@tonic-gate 	pp->pp_pipe_handle = ehci_polledp->ehci_polled_input_pipe_handle;
4507c478bd9Sstevel@tonic-gate 
4517c478bd9Sstevel@tonic-gate 	/*
4527c478bd9Sstevel@tonic-gate 	 * Allocate a dummy for the interrupt table. This dummy will be
4537c478bd9Sstevel@tonic-gate 	 * put into the action when we	switch interrupt  tables during
4547c478bd9Sstevel@tonic-gate 	 * ehci_hcdi_polled_enter. Dummy is placed on the unused lattice
4557c478bd9Sstevel@tonic-gate 	 * entries. When the QH is allocated we will replace dummy QH by
4567c478bd9Sstevel@tonic-gate 	 * valid interrupt QH in one or more locations in the interrupt
4577c478bd9Sstevel@tonic-gate 	 * lattice depending on the requested polling interval. Also we
4587c478bd9Sstevel@tonic-gate 	 * will hang a dummy QTD to the QH & dummy QTD is used to indicate
4597c478bd9Sstevel@tonic-gate 	 * the end of the QTD chain.
4607c478bd9Sstevel@tonic-gate 	 */
4617c478bd9Sstevel@tonic-gate 	ehci_polledp->ehci_polled_dummy_qh =
4627c478bd9Sstevel@tonic-gate 	    ehci_alloc_qh(ehcip, NULL, EHCI_POLLED_MODE_FLAG);
4637c478bd9Sstevel@tonic-gate 
4647c478bd9Sstevel@tonic-gate 	if (ehci_polledp->ehci_polled_dummy_qh == NULL) {
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate 		return (USB_NO_RESOURCES);
4677c478bd9Sstevel@tonic-gate 	}
4687c478bd9Sstevel@tonic-gate 
4697c478bd9Sstevel@tonic-gate 	/*
4707c478bd9Sstevel@tonic-gate 	 * Allocate the interrupt endpoint. This QH will be inserted in
4717c478bd9Sstevel@tonic-gate 	 * to the lattice chain for the  keyboard device. This endpoint
4727c478bd9Sstevel@tonic-gate 	 * will have the QTDs hanging off of it for the processing.
4737c478bd9Sstevel@tonic-gate 	 */
4747c478bd9Sstevel@tonic-gate 	ehci_polledp->ehci_polled_qh = ehci_alloc_qh(
4757c478bd9Sstevel@tonic-gate 	    ehcip, ph, EHCI_POLLED_MODE_FLAG);
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate 	if (ehci_polledp->ehci_polled_qh == NULL) {
4787c478bd9Sstevel@tonic-gate 
4797c478bd9Sstevel@tonic-gate 		return (USB_NO_RESOURCES);
4807c478bd9Sstevel@tonic-gate 	}
4817c478bd9Sstevel@tonic-gate 
4827c478bd9Sstevel@tonic-gate 	/* Set the state of pipe as idle */
4837c478bd9Sstevel@tonic-gate 	pp->pp_state = EHCI_PIPE_STATE_IDLE;
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate 	/* Set polled mode flag */
4867c478bd9Sstevel@tonic-gate 	pp->pp_flag = EHCI_POLLED_MODE_FLAG;
4877c478bd9Sstevel@tonic-gate 
4887c478bd9Sstevel@tonic-gate 	/* Insert the endpoint onto the pipe handle */
4897c478bd9Sstevel@tonic-gate 	pp->pp_qh = ehci_polledp->ehci_polled_qh;
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate 	/*
4927c478bd9Sstevel@tonic-gate 	 * Set soft interrupt handler flag in the normal mode usb
4937c478bd9Sstevel@tonic-gate 	 * pipe handle.
4947c478bd9Sstevel@tonic-gate 	 */
4957c478bd9Sstevel@tonic-gate 	mutex_enter(&ph->p_mutex);
4967c478bd9Sstevel@tonic-gate 	ph->p_spec_flag |= USBA_PH_FLAG_USE_SOFT_INTR;
4977c478bd9Sstevel@tonic-gate 	mutex_exit(&ph->p_mutex);
4987c478bd9Sstevel@tonic-gate 
4997c478bd9Sstevel@tonic-gate 	/*
5007c478bd9Sstevel@tonic-gate 	 * Insert a Interrupt polling request onto the endpoint.
5017c478bd9Sstevel@tonic-gate 	 *
5027c478bd9Sstevel@tonic-gate 	 * There will now be two QTDs on the QH, one is the dummy QTD that
5037c478bd9Sstevel@tonic-gate 	 * was allocated above in the  ehci_alloc_qh and this new one.
5047c478bd9Sstevel@tonic-gate 	 */
5057c478bd9Sstevel@tonic-gate 	if ((ehci_start_periodic_pipe_polling(ehcip,
5067c478bd9Sstevel@tonic-gate 	    ehci_polledp->ehci_polled_input_pipe_handle,
5077c478bd9Sstevel@tonic-gate 	    NULL, USB_FLAGS_SLEEP)) != USB_SUCCESS) {
5087c478bd9Sstevel@tonic-gate 
5097c478bd9Sstevel@tonic-gate 		return (USB_NO_RESOURCES);
5107c478bd9Sstevel@tonic-gate 	}
5117c478bd9Sstevel@tonic-gate 
5127c478bd9Sstevel@tonic-gate 	/* Get the given new interrupt qtd */
5137c478bd9Sstevel@tonic-gate 	qtd = (ehci_qtd_t *)(ehci_qtd_iommu_to_cpu(ehcip,
5147c478bd9Sstevel@tonic-gate 	    (Get_QH(pp->pp_qh->qh_next_qtd) & EHCI_QH_NEXT_QTD_PTR)));
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate 	/* Insert this qtd into active interrupt QTD list */
5177c478bd9Sstevel@tonic-gate 	ehci_polled_insert_qtd_into_active_intr_qtd_list(ehci_polledp, qtd);
5187c478bd9Sstevel@tonic-gate 
5197c478bd9Sstevel@tonic-gate 	return (USB_SUCCESS);
5207c478bd9Sstevel@tonic-gate }
5217c478bd9Sstevel@tonic-gate 
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate /*
5247c478bd9Sstevel@tonic-gate  * Polled deinitialization routines
5257c478bd9Sstevel@tonic-gate  */
5267c478bd9Sstevel@tonic-gate 
5277c478bd9Sstevel@tonic-gate 
5287c478bd9Sstevel@tonic-gate /*
5297c478bd9Sstevel@tonic-gate  * ehci_polled_fini:
5307c478bd9Sstevel@tonic-gate  */
5317c478bd9Sstevel@tonic-gate static int
5327c478bd9Sstevel@tonic-gate ehci_polled_fini(ehci_polled_t	*ehci_polledp)
5337c478bd9Sstevel@tonic-gate {
5347c478bd9Sstevel@tonic-gate 	ehci_state_t		*ehcip = ehci_polledp->ehci_polled_ehcip;
5357c478bd9Sstevel@tonic-gate 	ehci_pipe_private_t	*pp;
5367c478bd9Sstevel@tonic-gate 
5377c478bd9Sstevel@tonic-gate 	ASSERT(mutex_owned(&ehcip->ehci_int_mutex));
5387c478bd9Sstevel@tonic-gate 
5397c478bd9Sstevel@tonic-gate 	/* If the structure is already in use, then don't free it */
5407c478bd9Sstevel@tonic-gate 	if (ehci_polledp->ehci_polled_flags & POLLED_INPUT_MODE) {
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate 		return (USB_SUCCESS);
5437c478bd9Sstevel@tonic-gate 	}
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate 	pp = (ehci_pipe_private_t *)
5467c478bd9Sstevel@tonic-gate 	    ehci_polledp->ehci_polled_input_pipe_handle->p_hcd_private;
5477c478bd9Sstevel@tonic-gate 
5487c478bd9Sstevel@tonic-gate 	/* Deallocate all the pre-allocated interrupt requests */
5497c478bd9Sstevel@tonic-gate 	ehci_handle_outstanding_requests(ehcip, pp);
5507c478bd9Sstevel@tonic-gate 
5517c478bd9Sstevel@tonic-gate 	/*
5527c478bd9Sstevel@tonic-gate 	 * Traverse the list of QTD's on this endpoint and these QTD's
5537c478bd9Sstevel@tonic-gate 	 * have outstanding transfer requests. Since list processing
5547c478bd9Sstevel@tonic-gate 	 * is stopped, these QTDs can be deallocated.
5557c478bd9Sstevel@tonic-gate 	 */
5567c478bd9Sstevel@tonic-gate 	ehci_polled_traverse_qtds(ehci_polledp, pp->pp_pipe_handle);
5577c478bd9Sstevel@tonic-gate 
5587c478bd9Sstevel@tonic-gate 	/* Free DMA resources */
5597c478bd9Sstevel@tonic-gate 	ehci_free_dma_resources(ehcip, pp->pp_pipe_handle);
5607c478bd9Sstevel@tonic-gate 
5617c478bd9Sstevel@tonic-gate 	/*
5627c478bd9Sstevel@tonic-gate 	 * Deallocate the endpoint descriptors that we allocated
5637c478bd9Sstevel@tonic-gate 	 * with ehci_alloc_qh.
5647c478bd9Sstevel@tonic-gate 	 */
5657c478bd9Sstevel@tonic-gate 	if (ehci_polledp->ehci_polled_dummy_qh) {
5667c478bd9Sstevel@tonic-gate 		ehci_deallocate_qh(ehcip, ehci_polledp->ehci_polled_dummy_qh);
5677c478bd9Sstevel@tonic-gate 	}
5687c478bd9Sstevel@tonic-gate 
5697c478bd9Sstevel@tonic-gate 	if (ehci_polledp->ehci_polled_qh) {
5707c478bd9Sstevel@tonic-gate 		ehci_deallocate_qh(ehcip, ehci_polledp->ehci_polled_qh);
5717c478bd9Sstevel@tonic-gate 	}
5727c478bd9Sstevel@tonic-gate 
5737c478bd9Sstevel@tonic-gate 	mutex_destroy(&ehci_polledp->ehci_polled_input_pipe_handle->p_mutex);
5747c478bd9Sstevel@tonic-gate 
5757c478bd9Sstevel@tonic-gate 	/*
5767c478bd9Sstevel@tonic-gate 	 * Destroy everything about the pipe that we allocated in
5777c478bd9Sstevel@tonic-gate 	 * ehci_polled_duplicate_pipe_handle
5787c478bd9Sstevel@tonic-gate 	 */
5797c478bd9Sstevel@tonic-gate 	kmem_free(pp, sizeof (ehci_pipe_private_t));
5807c478bd9Sstevel@tonic-gate 
5817c478bd9Sstevel@tonic-gate 	kmem_free(ehci_polledp->ehci_polled_input_pipe_handle,
5827c478bd9Sstevel@tonic-gate 	    sizeof (usba_pipe_handle_data_t));
5837c478bd9Sstevel@tonic-gate 
5847c478bd9Sstevel@tonic-gate 	/*
5857c478bd9Sstevel@tonic-gate 	 * We use this field to determine if a QTD is for input or not,
5867c478bd9Sstevel@tonic-gate 	 * so NULL the pointer so we don't check deallocated data.
5877c478bd9Sstevel@tonic-gate 	 */
5887c478bd9Sstevel@tonic-gate 	ehci_polledp->ehci_polled_input_pipe_handle = NULL;
5897c478bd9Sstevel@tonic-gate 
5907c478bd9Sstevel@tonic-gate 	/*
5917c478bd9Sstevel@tonic-gate 	 * Finally, free off the structure that we use to keep track
5927c478bd9Sstevel@tonic-gate 	 * of all this.
5937c478bd9Sstevel@tonic-gate 	 */
5947c478bd9Sstevel@tonic-gate 	kmem_free(ehci_polledp, sizeof (ehci_polled_t));
5957c478bd9Sstevel@tonic-gate 
5967c478bd9Sstevel@tonic-gate 	return (USB_SUCCESS);
5977c478bd9Sstevel@tonic-gate }
5987c478bd9Sstevel@tonic-gate 
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate /*
6017c478bd9Sstevel@tonic-gate  * Polled save state routines
6027c478bd9Sstevel@tonic-gate  */
6037c478bd9Sstevel@tonic-gate 
6047c478bd9Sstevel@tonic-gate 
6057c478bd9Sstevel@tonic-gate /*
6067c478bd9Sstevel@tonic-gate  * ehci_polled_save_state:
6077c478bd9Sstevel@tonic-gate  */
6087c478bd9Sstevel@tonic-gate static void
6097c478bd9Sstevel@tonic-gate ehci_polled_save_state(ehci_polled_t	*ehci_polledp)
6107c478bd9Sstevel@tonic-gate {
6117c478bd9Sstevel@tonic-gate 	int				i;
6127c478bd9Sstevel@tonic-gate 	ehci_state_t			*ehcip;
6137c478bd9Sstevel@tonic-gate 	uint_t				polled_toggle;
6147c478bd9Sstevel@tonic-gate 	uint_t				real_toggle;
6157c478bd9Sstevel@tonic-gate 	ehci_pipe_private_t		*pp = NULL; /* Normal mode Pipe */
6167c478bd9Sstevel@tonic-gate 	ehci_pipe_private_t		*polled_pp; /* Polled mode Pipe */
6177c478bd9Sstevel@tonic-gate 	usba_pipe_handle_data_t		*ph;
6187c478bd9Sstevel@tonic-gate 	uint8_t				ep_addr;
6197c478bd9Sstevel@tonic-gate 	ehci_regs_t			*ehci_polled_regsp;
6207c478bd9Sstevel@tonic-gate 	ehci_qh_t			*qh;
6217c478bd9Sstevel@tonic-gate 
6227c478bd9Sstevel@tonic-gate #ifndef lint
6237c478bd9Sstevel@tonic-gate 	_NOTE(NO_COMPETING_THREADS_NOW);
6247c478bd9Sstevel@tonic-gate #endif
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate 	/*
6277c478bd9Sstevel@tonic-gate 	 * If either of these two flags are set, then we have already
6287c478bd9Sstevel@tonic-gate 	 * saved off the state information and setup the controller.
6297c478bd9Sstevel@tonic-gate 	 */
6307c478bd9Sstevel@tonic-gate 	if (ehci_polledp->ehci_polled_flags & POLLED_INPUT_MODE_INUSE) {
6317c478bd9Sstevel@tonic-gate #ifndef lint
6327c478bd9Sstevel@tonic-gate 		_NOTE(COMPETING_THREADS_NOW);
6337c478bd9Sstevel@tonic-gate #endif
6347c478bd9Sstevel@tonic-gate 		return;
6357c478bd9Sstevel@tonic-gate 	}
6367c478bd9Sstevel@tonic-gate 
6377c478bd9Sstevel@tonic-gate 	ehcip = ehci_polledp->ehci_polled_ehcip;
6387c478bd9Sstevel@tonic-gate 
6397c478bd9Sstevel@tonic-gate 	/*
6407c478bd9Sstevel@tonic-gate 	 * Check if the number of keyboard reach the max number we can
6417c478bd9Sstevel@tonic-gate 	 * support in polled mode
6427c478bd9Sstevel@tonic-gate 	 */
6437c478bd9Sstevel@tonic-gate 	if (++ ehcip->ehci_polled_enter_count > MAX_NUM_FOR_KEYBOARD) {
6447c478bd9Sstevel@tonic-gate #ifndef lint
6457c478bd9Sstevel@tonic-gate 		_NOTE(COMPETING_THREADS_NOW);
6467c478bd9Sstevel@tonic-gate #endif
6477c478bd9Sstevel@tonic-gate 		return;
6487c478bd9Sstevel@tonic-gate 	}
6497c478bd9Sstevel@tonic-gate 	ehci_polled_regsp = &ehcip->ehci_polled_save_regs;
6507c478bd9Sstevel@tonic-gate 
6517c478bd9Sstevel@tonic-gate 	/* Get the endpoint addr. */
6527c478bd9Sstevel@tonic-gate 	ep_addr = ehci_polledp->ehci_polled_ep_addr;
6537c478bd9Sstevel@tonic-gate 
6547c478bd9Sstevel@tonic-gate 	/* Get the normal mode usb pipe handle */
6557c478bd9Sstevel@tonic-gate 	ph = usba_hcdi_get_ph_data(ehci_polledp->ehci_polled_usb_dev, ep_addr);
6567c478bd9Sstevel@tonic-gate 
6577c478bd9Sstevel@tonic-gate 	/*
6587c478bd9Sstevel@tonic-gate 	 * The first enter keyboard entry should save info of the normal mode,
6597c478bd9Sstevel@tonic-gate 	 * disable all list processing and interrupt, initialize the
6607c478bd9Sstevel@tonic-gate 	 * frame list table with dummy QHs.
6617c478bd9Sstevel@tonic-gate 	 */
6627c478bd9Sstevel@tonic-gate 	if (ehcip->ehci_polled_enter_count == 1) {
6637c478bd9Sstevel@tonic-gate 		/*
6647c478bd9Sstevel@tonic-gate 		 * Save the current normal mode ehci registers	and later this
6657c478bd9Sstevel@tonic-gate 		 * saved register copy is used to replace some of required ehci
6667c478bd9Sstevel@tonic-gate 		 * registers before switching from polled mode to normal mode.
6677c478bd9Sstevel@tonic-gate 		 */
6687c478bd9Sstevel@tonic-gate 
6697c478bd9Sstevel@tonic-gate 		bzero((void *)ehci_polled_regsp, sizeof (ehci_regs_t));
6707c478bd9Sstevel@tonic-gate 
6717c478bd9Sstevel@tonic-gate 		/* Save current ehci registers */
6727c478bd9Sstevel@tonic-gate 		ehci_polled_regsp->ehci_command = Get_OpReg(ehci_command);
6737c478bd9Sstevel@tonic-gate 		ehci_polled_regsp->ehci_interrupt = Get_OpReg(ehci_interrupt);
6747c478bd9Sstevel@tonic-gate 		ehci_polled_regsp->ehci_ctrl_segment =
6757c478bd9Sstevel@tonic-gate 		    Get_OpReg(ehci_ctrl_segment);
6767c478bd9Sstevel@tonic-gate 		ehci_polled_regsp->
6777c478bd9Sstevel@tonic-gate 		    ehci_async_list_addr = Get_OpReg(ehci_async_list_addr);
6787c478bd9Sstevel@tonic-gate 		ehci_polled_regsp->ehci_config_flag =
6797c478bd9Sstevel@tonic-gate 		    Get_OpReg(ehci_config_flag);
6807c478bd9Sstevel@tonic-gate 		ehci_polled_regsp->ehci_periodic_list_base =
6817c478bd9Sstevel@tonic-gate 		    Get_OpReg(ehci_periodic_list_base);
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate 		/* Disable all list processing and interrupts */
6847c478bd9Sstevel@tonic-gate 		Set_OpReg(ehci_command, Get_OpReg(ehci_command) &
6857c478bd9Sstevel@tonic-gate 		    ~(EHCI_CMD_ASYNC_SCHED_ENABLE |
6867c478bd9Sstevel@tonic-gate 		    EHCI_CMD_PERIODIC_SCHED_ENABLE));
6877c478bd9Sstevel@tonic-gate 
6887c478bd9Sstevel@tonic-gate 		/* Wait for few milliseconds */
6897c478bd9Sstevel@tonic-gate 		drv_usecwait(EHCI_POLLED_TIMEWAIT);
6907c478bd9Sstevel@tonic-gate 
6917c478bd9Sstevel@tonic-gate 		/* Save any unprocessed normal mode ehci interrupts */
6927c478bd9Sstevel@tonic-gate 		ehcip->ehci_missed_intr_sts = EHCI_INTR_USB;
6937c478bd9Sstevel@tonic-gate 
6947c478bd9Sstevel@tonic-gate 		/*
6957c478bd9Sstevel@tonic-gate 		 * Save the current interrupt lattice and  replace this lattice
6967c478bd9Sstevel@tonic-gate 		 * with an lattice used in POLLED mode. We will restore lattice
6977c478bd9Sstevel@tonic-gate 		 * back when we exit from the POLLED mode.
6987c478bd9Sstevel@tonic-gate 		 */
6997c478bd9Sstevel@tonic-gate 		for (i = 0; i < EHCI_NUM_PERIODIC_FRAME_LISTS; i++) {
7007c478bd9Sstevel@tonic-gate 			ehcip->ehci_polled_frame_list_table[i] =
7017c478bd9Sstevel@tonic-gate 			    (ehci_qh_t *)(uintptr_t)Get_PFLT(ehcip->
7027c478bd9Sstevel@tonic-gate 			    ehci_periodic_frame_list_tablep->
7037c478bd9Sstevel@tonic-gate 			    ehci_periodic_frame_list_table[i]);
7047c478bd9Sstevel@tonic-gate 		}
7057c478bd9Sstevel@tonic-gate 
7067c478bd9Sstevel@tonic-gate 		/*
7077c478bd9Sstevel@tonic-gate 		 * Fill in the lattice with dummy QHs. These QHs are used so the
7087c478bd9Sstevel@tonic-gate 		 * controller can tell that it is at the end of the QH list.
7097c478bd9Sstevel@tonic-gate 		 */
7107c478bd9Sstevel@tonic-gate 		for (i = 0; i < EHCI_NUM_PERIODIC_FRAME_LISTS; i++) {
7117c478bd9Sstevel@tonic-gate 			Set_PFLT(ehcip->ehci_periodic_frame_list_tablep->
7127c478bd9Sstevel@tonic-gate 			    ehci_periodic_frame_list_table[i],
7137c478bd9Sstevel@tonic-gate 			    ehci_qh_cpu_to_iommu(ehcip,
7147c478bd9Sstevel@tonic-gate 			    ehci_polledp->ehci_polled_dummy_qh) |
7157c478bd9Sstevel@tonic-gate 			    (EHCI_QH_LINK_REF_QH | EHCI_QH_LINK_PTR_VALID));
7167c478bd9Sstevel@tonic-gate 		}
7177c478bd9Sstevel@tonic-gate 
7187c478bd9Sstevel@tonic-gate 	}
7197c478bd9Sstevel@tonic-gate 
7207c478bd9Sstevel@tonic-gate 	/* Get the polled mode ehci pipe private structure */
7217c478bd9Sstevel@tonic-gate 	polled_pp = (ehci_pipe_private_t *)
7227c478bd9Sstevel@tonic-gate 	    ehci_polledp->ehci_polled_input_pipe_handle->p_hcd_private;
7237c478bd9Sstevel@tonic-gate 
7247c478bd9Sstevel@tonic-gate 	/*
7257c478bd9Sstevel@tonic-gate 	 * Before replacing the lattice, adjust the data togggle on the
7267c478bd9Sstevel@tonic-gate 	 * on the ehci's interrupt ed
7277c478bd9Sstevel@tonic-gate 	 */
7287c478bd9Sstevel@tonic-gate 	polled_toggle = (Get_QH(polled_pp->pp_qh->qh_status) &
7297c478bd9Sstevel@tonic-gate 	    EHCI_QH_STS_DATA_TOGGLE) ? DATA1:DATA0;
7307c478bd9Sstevel@tonic-gate 
7317c478bd9Sstevel@tonic-gate 	/*
7327c478bd9Sstevel@tonic-gate 	 * If normal mode interrupt pipe endpoint is active, get the data
7337c478bd9Sstevel@tonic-gate 	 * toggle from the this interrupt endpoint through the corresponding
7347c478bd9Sstevel@tonic-gate 	 * interrupt pipe handle. Else get the data toggle information from
7357c478bd9Sstevel@tonic-gate 	 * the usb device structure and this information is saved during the
7367c478bd9Sstevel@tonic-gate 	 * normal mode interrupt pipe close. Use this data toggle information
7377c478bd9Sstevel@tonic-gate 	 * to fix the data toggle of polled mode interrupt endpoint.
7387c478bd9Sstevel@tonic-gate 	 */
7397c478bd9Sstevel@tonic-gate 	if (ph) {
7407c478bd9Sstevel@tonic-gate 		/* Get the normal mode ehci pipe private structure */
7417c478bd9Sstevel@tonic-gate 		pp = (ehci_pipe_private_t *)ph->p_hcd_private;
7427c478bd9Sstevel@tonic-gate 
7437c478bd9Sstevel@tonic-gate 		real_toggle = (Get_QH(pp->pp_qh->qh_status) &
7447c478bd9Sstevel@tonic-gate 		    EHCI_QH_STS_DATA_TOGGLE) ? DATA1:DATA0;
7457c478bd9Sstevel@tonic-gate 	} else {
7467c478bd9Sstevel@tonic-gate 		real_toggle = usba_hcdi_get_data_toggle(
7477c478bd9Sstevel@tonic-gate 		    ehci_polledp->ehci_polled_usb_dev, ep_addr);
7487c478bd9Sstevel@tonic-gate 	}
7497c478bd9Sstevel@tonic-gate 
7507c478bd9Sstevel@tonic-gate 	if (polled_toggle != real_toggle) {
7517c478bd9Sstevel@tonic-gate 		if (real_toggle == DATA0) {
7527c478bd9Sstevel@tonic-gate 			Set_QH(polled_pp->pp_qh->qh_status,
7537c478bd9Sstevel@tonic-gate 			    Get_QH(polled_pp->pp_qh->qh_status) &
7547c478bd9Sstevel@tonic-gate 			    ~EHCI_QH_STS_DATA_TOGGLE);
7557c478bd9Sstevel@tonic-gate 		} else {
7567c478bd9Sstevel@tonic-gate 			Set_QH(polled_pp->pp_qh->qh_status,
7577c478bd9Sstevel@tonic-gate 			    Get_QH(polled_pp->pp_qh->qh_status) |
7587c478bd9Sstevel@tonic-gate 			    EHCI_QH_STS_DATA_TOGGLE);
7597c478bd9Sstevel@tonic-gate 		}
7607c478bd9Sstevel@tonic-gate 	}
7617c478bd9Sstevel@tonic-gate 
7627c478bd9Sstevel@tonic-gate 	/*
7637c478bd9Sstevel@tonic-gate 	 * Check whether Halt bit is set in the QH and if so  clear the
7647c478bd9Sstevel@tonic-gate 	 * halt bit.
7657c478bd9Sstevel@tonic-gate 	 */
7667c478bd9Sstevel@tonic-gate 	if (polled_pp->pp_qh->qh_status & EHCI_QH_STS_HALTED) {
7677c478bd9Sstevel@tonic-gate 
7687c478bd9Sstevel@tonic-gate 		/* Clear the halt bit */
7697c478bd9Sstevel@tonic-gate 		Set_QH(polled_pp->pp_qh->qh_status,
7707c478bd9Sstevel@tonic-gate 		    (Get_QH(polled_pp->pp_qh->qh_status) &
7717c478bd9Sstevel@tonic-gate 		    ~EHCI_QH_STS_HALTED));
7727c478bd9Sstevel@tonic-gate 	}
7737c478bd9Sstevel@tonic-gate 
7747c478bd9Sstevel@tonic-gate 	/*
7757c478bd9Sstevel@tonic-gate 	 * Initialize the qh overlay area
7767c478bd9Sstevel@tonic-gate 	 */
7777c478bd9Sstevel@tonic-gate 	qh = ehci_polledp->ehci_polled_qh;
7787c478bd9Sstevel@tonic-gate 	for (i = 0; i < 5; i++) {
7797c478bd9Sstevel@tonic-gate 		Set_QH(qh->qh_buf[i], NULL);
7807c478bd9Sstevel@tonic-gate 		Set_QH(qh->qh_buf_high[i], NULL);
7817c478bd9Sstevel@tonic-gate 	}
7827c478bd9Sstevel@tonic-gate 	Set_QH(qh->qh_next_qtd, ehci_qtd_cpu_to_iommu(ehcip,
7837c478bd9Sstevel@tonic-gate 	    ehci_polledp->ehci_polled_active_intr_qtd_list));
7847c478bd9Sstevel@tonic-gate 
7857c478bd9Sstevel@tonic-gate 	/*
7867c478bd9Sstevel@tonic-gate 	 * Now, add the endpoint to the lattice that we will  hang  our
7877c478bd9Sstevel@tonic-gate 	 * QTD's off of.  We need to poll this device at  every 8 ms and
7887c478bd9Sstevel@tonic-gate 	 * hence add this QH needs 4 entries in interrupt lattice.
7897c478bd9Sstevel@tonic-gate 	 */
7907c478bd9Sstevel@tonic-gate 	for (i = ehcip->ehci_polled_enter_count - 1;
7917c478bd9Sstevel@tonic-gate 	    i < EHCI_NUM_PERIODIC_FRAME_LISTS;
7927c478bd9Sstevel@tonic-gate 	    i = i + LS_MIN_POLL_INTERVAL) {
7937c478bd9Sstevel@tonic-gate 		Set_PFLT(ehcip->ehci_periodic_frame_list_tablep->
7947c478bd9Sstevel@tonic-gate 		    ehci_periodic_frame_list_table[i],
7957c478bd9Sstevel@tonic-gate 		    ehci_qh_cpu_to_iommu(ehcip,
7967c478bd9Sstevel@tonic-gate 		    ehci_polledp->ehci_polled_qh) | EHCI_QH_LINK_REF_QH);
7977c478bd9Sstevel@tonic-gate 	}
7987c478bd9Sstevel@tonic-gate 	/* The first enter keyboard entry enable interrupts and periodic list */
7997c478bd9Sstevel@tonic-gate 	if (ehcip->ehci_polled_enter_count == 1) {
8007c478bd9Sstevel@tonic-gate 		/* Enable USB and Frame list rollover interrupts */
8017c478bd9Sstevel@tonic-gate 		Set_OpReg(ehci_interrupt, (EHCI_INTR_USB |
8027c478bd9Sstevel@tonic-gate 		    EHCI_INTR_USB_ERROR | EHCI_INTR_FRAME_LIST_ROLLOVER));
8037c478bd9Sstevel@tonic-gate 
8047c478bd9Sstevel@tonic-gate 		/* Enable the periodic list */
8057c478bd9Sstevel@tonic-gate 		Set_OpReg(ehci_command,
8067c478bd9Sstevel@tonic-gate 		    (Get_OpReg(ehci_command) | EHCI_CMD_PERIODIC_SCHED_ENABLE));
8077c478bd9Sstevel@tonic-gate 
8087c478bd9Sstevel@tonic-gate 		/* Wait for few milliseconds */
8097c478bd9Sstevel@tonic-gate 		drv_usecwait(EHCI_POLLED_TIMEWAIT);
8107c478bd9Sstevel@tonic-gate 	}
8117c478bd9Sstevel@tonic-gate #ifndef lint
8127c478bd9Sstevel@tonic-gate 	_NOTE(COMPETING_THREADS_NOW);
8137c478bd9Sstevel@tonic-gate #endif
8147c478bd9Sstevel@tonic-gate }
8157c478bd9Sstevel@tonic-gate 
8167c478bd9Sstevel@tonic-gate 
8177c478bd9Sstevel@tonic-gate /*
8187c478bd9Sstevel@tonic-gate  * Polled restore state routines
8197c478bd9Sstevel@tonic-gate  */
8207c478bd9Sstevel@tonic-gate 
8217c478bd9Sstevel@tonic-gate 
8227c478bd9Sstevel@tonic-gate /*
8237c478bd9Sstevel@tonic-gate  * ehci_polled_restore_state:
8247c478bd9Sstevel@tonic-gate  */
8257c478bd9Sstevel@tonic-gate static void
8267c478bd9Sstevel@tonic-gate ehci_polled_restore_state(ehci_polled_t	*ehci_polledp)
8277c478bd9Sstevel@tonic-gate {
8287c478bd9Sstevel@tonic-gate 	ehci_state_t			*ehcip;
8297c478bd9Sstevel@tonic-gate 	int				i;
8307c478bd9Sstevel@tonic-gate 	uint_t				polled_toggle;
8317c478bd9Sstevel@tonic-gate 	uint_t				real_toggle;
8327c478bd9Sstevel@tonic-gate 	ehci_pipe_private_t		*pp = NULL; /* Normal mode Pipe */
8337c478bd9Sstevel@tonic-gate 	ehci_pipe_private_t		*polled_pp; /* Polled mode Pipe */
8347c478bd9Sstevel@tonic-gate 	usba_pipe_handle_data_t		*ph;
8357c478bd9Sstevel@tonic-gate 	uint8_t				ep_addr;
8367c478bd9Sstevel@tonic-gate 
8377c478bd9Sstevel@tonic-gate #ifndef lint
8387c478bd9Sstevel@tonic-gate 	_NOTE(NO_COMPETING_THREADS_NOW);
8397c478bd9Sstevel@tonic-gate #endif
8407c478bd9Sstevel@tonic-gate 
8417c478bd9Sstevel@tonic-gate 	/*
8427c478bd9Sstevel@tonic-gate 	 * If this flag is set, then we are still using this structure,
8437c478bd9Sstevel@tonic-gate 	 * so don't restore any controller state information yet.
8447c478bd9Sstevel@tonic-gate 	 */
8457c478bd9Sstevel@tonic-gate 	if (ehci_polledp->ehci_polled_flags & POLLED_INPUT_MODE_INUSE) {
8467c478bd9Sstevel@tonic-gate 
8477c478bd9Sstevel@tonic-gate #ifndef lint
8487c478bd9Sstevel@tonic-gate 		_NOTE(COMPETING_THREADS_NOW);
8497c478bd9Sstevel@tonic-gate #endif
8507c478bd9Sstevel@tonic-gate 
8517c478bd9Sstevel@tonic-gate 		return;
8527c478bd9Sstevel@tonic-gate 	}
8537c478bd9Sstevel@tonic-gate 
8547c478bd9Sstevel@tonic-gate 	ehcip = ehci_polledp->ehci_polled_ehcip;
8557c478bd9Sstevel@tonic-gate 	ehcip->ehci_polled_enter_count --;
8567c478bd9Sstevel@tonic-gate 
8577c478bd9Sstevel@tonic-gate 	/* Get the endpoint addr */
8587c478bd9Sstevel@tonic-gate 	ep_addr = ehci_polledp->ehci_polled_ep_addr;
8597c478bd9Sstevel@tonic-gate 
8607c478bd9Sstevel@tonic-gate 	/* Get the normal mode usb pipe handle */
8617c478bd9Sstevel@tonic-gate 	ph = usba_hcdi_get_ph_data(ehci_polledp->ehci_polled_usb_dev, ep_addr);
8627c478bd9Sstevel@tonic-gate 
8637c478bd9Sstevel@tonic-gate 	/* Disable list processing and other things */
8647c478bd9Sstevel@tonic-gate 	ehci_polled_stop_processing(ehci_polledp);
8657c478bd9Sstevel@tonic-gate 
8667c478bd9Sstevel@tonic-gate 	/* Get the polled mode ehci pipe private structure */
8677c478bd9Sstevel@tonic-gate 	polled_pp = (ehci_pipe_private_t *)
8687c478bd9Sstevel@tonic-gate 	    ehci_polledp->ehci_polled_input_pipe_handle->p_hcd_private;
8697c478bd9Sstevel@tonic-gate 
8707c478bd9Sstevel@tonic-gate 	/*
8717c478bd9Sstevel@tonic-gate 	 * Before replacing the lattice, adjust the data togggle
8727c478bd9Sstevel@tonic-gate 	 * on the on the ehci's interrupt ed
8737c478bd9Sstevel@tonic-gate 	 */
8747c478bd9Sstevel@tonic-gate 	polled_toggle = (Get_QH(polled_pp->pp_qh->qh_status) &
8757c478bd9Sstevel@tonic-gate 	    EHCI_QH_STS_DATA_TOGGLE) ? DATA1:DATA0;
8767c478bd9Sstevel@tonic-gate 
8777c478bd9Sstevel@tonic-gate 	/*
8787c478bd9Sstevel@tonic-gate 	 * If normal mode interrupt pipe endpoint is active, fix the
8797c478bd9Sstevel@tonic-gate 	 * data toggle for this interrupt endpoint by getting the data
8807c478bd9Sstevel@tonic-gate 	 * toggle information from the polled interrupt endpoint. Else
8817c478bd9Sstevel@tonic-gate 	 * save the data toggle information in usb device structure.
8827c478bd9Sstevel@tonic-gate 	 */
8837c478bd9Sstevel@tonic-gate 	if (ph) {
8847c478bd9Sstevel@tonic-gate 		/* Get the normal mode ehci pipe private structure */
8857c478bd9Sstevel@tonic-gate 		pp = (ehci_pipe_private_t *)ph->p_hcd_private;
8867c478bd9Sstevel@tonic-gate 
8877c478bd9Sstevel@tonic-gate 		real_toggle = (Get_QH(pp->pp_qh->qh_status) &
8887c478bd9Sstevel@tonic-gate 		    EHCI_QH_STS_DATA_TOGGLE) ? DATA1:DATA0;
8897c478bd9Sstevel@tonic-gate 
8907c478bd9Sstevel@tonic-gate 		if (polled_toggle != real_toggle) {
8917c478bd9Sstevel@tonic-gate 			if (polled_toggle == DATA0) {
8927c478bd9Sstevel@tonic-gate 				Set_QH(pp->pp_qh->qh_status,
8937c478bd9Sstevel@tonic-gate 				    Get_QH(pp->pp_qh->qh_status) &
8947c478bd9Sstevel@tonic-gate 				    ~EHCI_QH_STS_DATA_TOGGLE);
8957c478bd9Sstevel@tonic-gate 			} else {
8967c478bd9Sstevel@tonic-gate 				Set_QH(pp->pp_qh->qh_status,
8977c478bd9Sstevel@tonic-gate 				    Get_QH(pp->pp_qh->qh_status) |
8987c478bd9Sstevel@tonic-gate 				    EHCI_QH_STS_DATA_TOGGLE);
8997c478bd9Sstevel@tonic-gate 			}
9007c478bd9Sstevel@tonic-gate 		}
9017c478bd9Sstevel@tonic-gate 	} else {
9027c478bd9Sstevel@tonic-gate 		usba_hcdi_set_data_toggle(ehci_polledp->ehci_polled_usb_dev,
9037c478bd9Sstevel@tonic-gate 		    ep_addr, polled_toggle);
9047c478bd9Sstevel@tonic-gate 	}
9057c478bd9Sstevel@tonic-gate 
9067c478bd9Sstevel@tonic-gate 	/*
9077c478bd9Sstevel@tonic-gate 	 * Only the last leave keyboard entry restore the save frame
9087c478bd9Sstevel@tonic-gate 	 * list table and start processing.
9097c478bd9Sstevel@tonic-gate 	 */
9107c478bd9Sstevel@tonic-gate 	if (ehcip->ehci_polled_enter_count == 0) {
9117c478bd9Sstevel@tonic-gate 
9127c478bd9Sstevel@tonic-gate 		/* Replace the lattice */
9137c478bd9Sstevel@tonic-gate 		for (i = 0; i < EHCI_NUM_PERIODIC_FRAME_LISTS; i++) {
9147c478bd9Sstevel@tonic-gate 			Set_PFLT(ehcip->ehci_periodic_frame_list_tablep->
9157c478bd9Sstevel@tonic-gate 			    ehci_periodic_frame_list_table[i],
9167c478bd9Sstevel@tonic-gate 			    ehcip->ehci_polled_frame_list_table[i]);
9177c478bd9Sstevel@tonic-gate 		}
9187c478bd9Sstevel@tonic-gate 		ehci_polled_start_processing(ehci_polledp);
9197c478bd9Sstevel@tonic-gate 	}
9207c478bd9Sstevel@tonic-gate 
9217c478bd9Sstevel@tonic-gate #ifndef lint
9227c478bd9Sstevel@tonic-gate 	_NOTE(COMPETING_THREADS_NOW);
9237c478bd9Sstevel@tonic-gate #endif
9247c478bd9Sstevel@tonic-gate }
9257c478bd9Sstevel@tonic-gate 
9267c478bd9Sstevel@tonic-gate 
9277c478bd9Sstevel@tonic-gate /*
9287c478bd9Sstevel@tonic-gate  * ehci_polled_stop_processing:
9297c478bd9Sstevel@tonic-gate  */
9307c478bd9Sstevel@tonic-gate static void
9317c478bd9Sstevel@tonic-gate ehci_polled_stop_processing(ehci_polled_t	*ehci_polledp)
9327c478bd9Sstevel@tonic-gate {
9337c478bd9Sstevel@tonic-gate 	ehci_state_t		*ehcip;
9347c478bd9Sstevel@tonic-gate 	ehci_qh_t		*qh = ehci_polledp->ehci_polled_qh;
9357c478bd9Sstevel@tonic-gate 
9367c478bd9Sstevel@tonic-gate 	ehcip = ehci_polledp->ehci_polled_ehcip;
9377c478bd9Sstevel@tonic-gate 
9387c478bd9Sstevel@tonic-gate 	/* First inactive this QH */
9397c478bd9Sstevel@tonic-gate 	Set_QH(qh->qh_ctrl,
9407c478bd9Sstevel@tonic-gate 	    Get_QH(qh->qh_ctrl) | EHCI_QH_CTRL_ED_INACTIVATE);
9417c478bd9Sstevel@tonic-gate 
9427c478bd9Sstevel@tonic-gate 	/* Only first leave keyboard entry turn off periodic list processing */
9437c478bd9Sstevel@tonic-gate 	if (Get_OpReg(ehci_command) & EHCI_CMD_PERIODIC_SCHED_ENABLE) {
9447c478bd9Sstevel@tonic-gate 		Set_OpReg(ehci_command, (Get_OpReg(ehci_command) &
9457c478bd9Sstevel@tonic-gate 			~EHCI_CMD_PERIODIC_SCHED_ENABLE));
9467c478bd9Sstevel@tonic-gate 
9477c478bd9Sstevel@tonic-gate 		/* Wait for few milliseconds */
9487c478bd9Sstevel@tonic-gate 		drv_usecwait(EHCI_POLLED_TIMEWAIT);
9497c478bd9Sstevel@tonic-gate 	}
9507c478bd9Sstevel@tonic-gate 	/*
9517c478bd9Sstevel@tonic-gate 	 * Now clear all required fields of QH
9527c478bd9Sstevel@tonic-gate 	 * including inactive bit.
9537c478bd9Sstevel@tonic-gate 	 */
9547c478bd9Sstevel@tonic-gate 	Set_QH(qh->qh_ctrl,
9557c478bd9Sstevel@tonic-gate 	    Get_QH(qh->qh_ctrl) & ~(EHCI_QH_CTRL_ED_INACTIVATE));
9567c478bd9Sstevel@tonic-gate 	Set_QH(qh->qh_status,
9577c478bd9Sstevel@tonic-gate 	    Get_QH(qh->qh_status) & ~(EHCI_QH_STS_XACT_STATUS));
9587c478bd9Sstevel@tonic-gate 	Set_QH(qh->qh_curr_qtd, NULL);
9597c478bd9Sstevel@tonic-gate 	Set_QH(qh->qh_alt_next_qtd, EHCI_QH_ALT_NEXT_QTD_PTR_VALID);
9607c478bd9Sstevel@tonic-gate 
9617c478bd9Sstevel@tonic-gate 	/*
9627c478bd9Sstevel@tonic-gate 	 * Now look up at the QTD's that are in the active qtd list &
9637c478bd9Sstevel@tonic-gate 	 * re-insert them back into the QH's QTD list.
9647c478bd9Sstevel@tonic-gate 	 */
9657c478bd9Sstevel@tonic-gate 	(void) ehci_polled_process_active_intr_qtd_list(ehci_polledp);
9667c478bd9Sstevel@tonic-gate }
9677c478bd9Sstevel@tonic-gate 
9687c478bd9Sstevel@tonic-gate 
9697c478bd9Sstevel@tonic-gate /*
9707c478bd9Sstevel@tonic-gate  * ehci_polled_start_processing:
9717c478bd9Sstevel@tonic-gate  */
9727c478bd9Sstevel@tonic-gate static void
9737c478bd9Sstevel@tonic-gate ehci_polled_start_processing(ehci_polled_t	*ehci_polledp)
9747c478bd9Sstevel@tonic-gate {
9757c478bd9Sstevel@tonic-gate 	ehci_state_t		*ehcip;
9767c478bd9Sstevel@tonic-gate 	uint32_t		mask;
9777c478bd9Sstevel@tonic-gate 	ehci_regs_t		*ehci_polled_regsp;
9787c478bd9Sstevel@tonic-gate 
9797c478bd9Sstevel@tonic-gate 	ehcip = ehci_polledp->ehci_polled_ehcip;
9807c478bd9Sstevel@tonic-gate 	ehci_polled_regsp = &ehcip->ehci_polled_save_regs;
9817c478bd9Sstevel@tonic-gate 
9827c478bd9Sstevel@tonic-gate 	mask = ((uint32_t)ehci_polled_regsp->ehci_interrupt &
9837c478bd9Sstevel@tonic-gate 	    (EHCI_INTR_HOST_SYSTEM_ERROR | EHCI_INTR_FRAME_LIST_ROLLOVER |
9847c478bd9Sstevel@tonic-gate 	    EHCI_INTR_USB_ERROR | EHCI_INTR_USB | EHCI_INTR_ASYNC_ADVANCE));
9857c478bd9Sstevel@tonic-gate 
9867c478bd9Sstevel@tonic-gate 	/* Enable all required EHCI interrupts */
9877c478bd9Sstevel@tonic-gate 	Set_OpReg(ehci_interrupt, mask);
9887c478bd9Sstevel@tonic-gate 
9897c478bd9Sstevel@tonic-gate 	mask = ((uint32_t)ehci_polled_regsp->ehci_command &
9907c478bd9Sstevel@tonic-gate 	    (EHCI_CMD_ASYNC_SCHED_ENABLE | EHCI_CMD_PERIODIC_SCHED_ENABLE));
9917c478bd9Sstevel@tonic-gate 
9927c478bd9Sstevel@tonic-gate 	/* Enable all reuired list processing */
9937c478bd9Sstevel@tonic-gate 	Set_OpReg(ehci_command, (Get_OpReg(ehci_command) | mask));
9947c478bd9Sstevel@tonic-gate 
9957c478bd9Sstevel@tonic-gate 	/* Wait for few milliseconds */
9967c478bd9Sstevel@tonic-gate 	drv_usecwait(EHCI_POLLED_TIMEWAIT);
9977c478bd9Sstevel@tonic-gate }
9987c478bd9Sstevel@tonic-gate 
9997c478bd9Sstevel@tonic-gate 
10007c478bd9Sstevel@tonic-gate /*
10017c478bd9Sstevel@tonic-gate  * Polled read routines
10027c478bd9Sstevel@tonic-gate  */
10037c478bd9Sstevel@tonic-gate 
10047c478bd9Sstevel@tonic-gate 
10057c478bd9Sstevel@tonic-gate /*
10067c478bd9Sstevel@tonic-gate  * ehci_polled_process_active_intr_qtd_list:
10077c478bd9Sstevel@tonic-gate  *
10087c478bd9Sstevel@tonic-gate  * This routine takes the QTD's off of the input done head and processes
10097c478bd9Sstevel@tonic-gate  * them.  It returns the number of characters that have been copied for
10107c478bd9Sstevel@tonic-gate  * input.
10117c478bd9Sstevel@tonic-gate  */
10127c478bd9Sstevel@tonic-gate static int
10137c478bd9Sstevel@tonic-gate ehci_polled_process_active_intr_qtd_list(ehci_polled_t	*ehci_polledp)
10147c478bd9Sstevel@tonic-gate {
10157c478bd9Sstevel@tonic-gate 	ehci_state_t		*ehcip = ehci_polledp->ehci_polled_ehcip;
10167c478bd9Sstevel@tonic-gate 	ehci_qtd_t		*qtd, *next_qtd;
10177c478bd9Sstevel@tonic-gate 	uint_t			num_characters = 0;
10187c478bd9Sstevel@tonic-gate 	uint_t			ctrl;
10197c478bd9Sstevel@tonic-gate 	ehci_trans_wrapper_t	*tw;
10207c478bd9Sstevel@tonic-gate 	ehci_pipe_private_t	*pp;
10217c478bd9Sstevel@tonic-gate 	usb_cr_t 		error;
10227c478bd9Sstevel@tonic-gate 
10237c478bd9Sstevel@tonic-gate 	/* Sync QH and QTD pool */
10247c478bd9Sstevel@tonic-gate 	if (ehci_polledp->ehci_polled_no_sync_flag == B_FALSE) {
10257c478bd9Sstevel@tonic-gate 		Sync_QH_QTD_Pool(ehcip);
10267c478bd9Sstevel@tonic-gate 	}
10277c478bd9Sstevel@tonic-gate 
10287c478bd9Sstevel@tonic-gate 	/* Create done qtd list */
10297c478bd9Sstevel@tonic-gate 	qtd = ehci_polled_create_done_qtd_list(ehci_polledp);
10307c478bd9Sstevel@tonic-gate 
10317c478bd9Sstevel@tonic-gate 	/*
10327c478bd9Sstevel@tonic-gate 	 * Traverse the list of transfer descriptors.  We can't destroy
10337c478bd9Sstevel@tonic-gate 	 * the qtd_next pointers of these QTDs because we are using it
10347c478bd9Sstevel@tonic-gate 	 * to traverse the done list.  Therefore, we can not put these
10357c478bd9Sstevel@tonic-gate 	 * QTD's back on the QH until we are done processing all of them.
10367c478bd9Sstevel@tonic-gate 	 */
10377c478bd9Sstevel@tonic-gate 	while (qtd) {
10387c478bd9Sstevel@tonic-gate 		/* Get next active QTD from the active QTD list */
10397c478bd9Sstevel@tonic-gate 		next_qtd = ehci_qtd_iommu_to_cpu(ehcip,
10407c478bd9Sstevel@tonic-gate 		    Get_QTD(qtd->qtd_active_qtd_next));
10417c478bd9Sstevel@tonic-gate 
10427c478bd9Sstevel@tonic-gate 		/* Obtain the transfer wrapper from the QTD */
10437c478bd9Sstevel@tonic-gate 		tw = (ehci_trans_wrapper_t *)EHCI_LOOKUP_ID(
10447c478bd9Sstevel@tonic-gate 		    (uint32_t)Get_QTD(qtd->qtd_trans_wrapper));
10457c478bd9Sstevel@tonic-gate 
10467c478bd9Sstevel@tonic-gate 		/* Get ohci pipe from transfer wrapper */
10477c478bd9Sstevel@tonic-gate 		pp = tw->tw_pipe_private;
10487c478bd9Sstevel@tonic-gate 
10497c478bd9Sstevel@tonic-gate 		/* Look at the status */
10507c478bd9Sstevel@tonic-gate 		ctrl = (uint_t)Get_QTD(qtd->qtd_ctrl) &
10517c478bd9Sstevel@tonic-gate 		    (uint32_t)EHCI_QTD_CTRL_XACT_STATUS;
10527c478bd9Sstevel@tonic-gate 
10537c478bd9Sstevel@tonic-gate 		error = ehci_check_for_error(ehcip, pp, tw, qtd, ctrl);
10547c478bd9Sstevel@tonic-gate 
10557c478bd9Sstevel@tonic-gate 		/*
10567c478bd9Sstevel@tonic-gate 		 * Check to see if there is an error. If there is error
10577c478bd9Sstevel@tonic-gate 		 * clear the halt condition in the Endpoint  Descriptor
10587c478bd9Sstevel@tonic-gate 		 * (QH) associated with this Transfer  Descriptor (QTD).
10597c478bd9Sstevel@tonic-gate 		 */
10607c478bd9Sstevel@tonic-gate 		if (error == USB_CR_OK) {
10617c478bd9Sstevel@tonic-gate 			num_characters +=
10627c478bd9Sstevel@tonic-gate 			    ehci_polled_handle_normal_qtd(ehci_polledp, qtd);
10637c478bd9Sstevel@tonic-gate 		} else {
10647c478bd9Sstevel@tonic-gate 			/* Clear the halt bit */
10657c478bd9Sstevel@tonic-gate 			Set_QH(pp->pp_qh->qh_status,
10667c478bd9Sstevel@tonic-gate 			    Get_QH(pp->pp_qh->qh_status) &
10677c478bd9Sstevel@tonic-gate 			    ~(EHCI_QH_STS_XACT_STATUS));
10687c478bd9Sstevel@tonic-gate 		}
10697c478bd9Sstevel@tonic-gate 
10707c478bd9Sstevel@tonic-gate 		/* Insert this qtd back into QH's qtd list */
10717c478bd9Sstevel@tonic-gate 		ehci_polled_insert_qtd(ehci_polledp, qtd);
10727c478bd9Sstevel@tonic-gate 
10737c478bd9Sstevel@tonic-gate 		qtd = next_qtd;
10747c478bd9Sstevel@tonic-gate 	}
10757c478bd9Sstevel@tonic-gate 
10767c478bd9Sstevel@tonic-gate 	return (num_characters);
10777c478bd9Sstevel@tonic-gate }
10787c478bd9Sstevel@tonic-gate 
10797c478bd9Sstevel@tonic-gate 
10807c478bd9Sstevel@tonic-gate /*
10817c478bd9Sstevel@tonic-gate  * ehci_polled_handle_normal_qtd:
10827c478bd9Sstevel@tonic-gate  */
10837c478bd9Sstevel@tonic-gate static int
10847c478bd9Sstevel@tonic-gate ehci_polled_handle_normal_qtd(
10857c478bd9Sstevel@tonic-gate 	ehci_polled_t		*ehci_polledp,
10867c478bd9Sstevel@tonic-gate 	ehci_qtd_t		*qtd)
10877c478bd9Sstevel@tonic-gate {
10887c478bd9Sstevel@tonic-gate 	ehci_state_t		*ehcip = ehci_polledp->ehci_polled_ehcip;
10897c478bd9Sstevel@tonic-gate 	uchar_t			*buf;
10907c478bd9Sstevel@tonic-gate 	ehci_trans_wrapper_t	*tw;
10917c478bd9Sstevel@tonic-gate 	size_t			length;
10927c478bd9Sstevel@tonic-gate 	uint32_t		residue;
10937c478bd9Sstevel@tonic-gate 
10947c478bd9Sstevel@tonic-gate 	/* Obtain the transfer wrapper from the QTD */
10957c478bd9Sstevel@tonic-gate 	tw = (ehci_trans_wrapper_t *)EHCI_LOOKUP_ID((uint32_t)
10967c478bd9Sstevel@tonic-gate 		Get_QTD(qtd->qtd_trans_wrapper));
10977c478bd9Sstevel@tonic-gate 
10987c478bd9Sstevel@tonic-gate 	ASSERT(tw != NULL);
10997c478bd9Sstevel@tonic-gate 
11007c478bd9Sstevel@tonic-gate 	buf = (uchar_t *)tw->tw_buf;
11017c478bd9Sstevel@tonic-gate 
11027c478bd9Sstevel@tonic-gate 	length = tw->tw_length;
11037c478bd9Sstevel@tonic-gate 
11047c478bd9Sstevel@tonic-gate 	/*
11057c478bd9Sstevel@tonic-gate 	 * If "Total bytes of xfer" in control field of qtd is not equal to 0,
11067c478bd9Sstevel@tonic-gate 	 * then we received less data from the usb device than requested by us.
11077c478bd9Sstevel@tonic-gate 	 * In that case, get the actual received data size.
11087c478bd9Sstevel@tonic-gate 	 */
11097c478bd9Sstevel@tonic-gate 	residue = ((Get_QTD(qtd->qtd_ctrl) &
11107c478bd9Sstevel@tonic-gate 	    EHCI_QTD_CTRL_BYTES_TO_XFER) >> EHCI_QTD_CTRL_BYTES_TO_XFER_SHIFT);
11117c478bd9Sstevel@tonic-gate 
11127c478bd9Sstevel@tonic-gate 	if (residue) {
11137c478bd9Sstevel@tonic-gate 
11147c478bd9Sstevel@tonic-gate 		length = (Get_QTD(qtd->qtd_xfer_addr) +
11157c478bd9Sstevel@tonic-gate 		    Get_QTD(qtd->qtd_xfer_len) - residue) -
11167c478bd9Sstevel@tonic-gate 		    tw->tw_cookie.dmac_address;
11177c478bd9Sstevel@tonic-gate 	}
11187c478bd9Sstevel@tonic-gate 
11197c478bd9Sstevel@tonic-gate 	/* Sync IO buffer */
11207c478bd9Sstevel@tonic-gate 	if (ehci_polledp->ehci_polled_no_sync_flag == B_FALSE) {
11217c478bd9Sstevel@tonic-gate 		Sync_IO_Buffer(tw->tw_dmahandle, length);
11227c478bd9Sstevel@tonic-gate 	}
11237c478bd9Sstevel@tonic-gate 
11247c478bd9Sstevel@tonic-gate 	/* Copy the data into the message */
11257c478bd9Sstevel@tonic-gate 	bcopy(buf, ehci_polledp->ehci_polled_buf, length);
11267c478bd9Sstevel@tonic-gate 
11277c478bd9Sstevel@tonic-gate 	return (length);
11287c478bd9Sstevel@tonic-gate }
11297c478bd9Sstevel@tonic-gate 
11307c478bd9Sstevel@tonic-gate 
11317c478bd9Sstevel@tonic-gate /*
11327c478bd9Sstevel@tonic-gate  * ehci_polled_insert_qtd:
11337c478bd9Sstevel@tonic-gate  *
11347c478bd9Sstevel@tonic-gate  * Insert a Transfer Descriptor (QTD) on an Endpoint Descriptor (QH).
11357c478bd9Sstevel@tonic-gate  */
11367c478bd9Sstevel@tonic-gate static void
11377c478bd9Sstevel@tonic-gate ehci_polled_insert_qtd(
11387c478bd9Sstevel@tonic-gate 	ehci_polled_t		*ehci_polledp,
11397c478bd9Sstevel@tonic-gate 	ehci_qtd_t		*qtd)
11407c478bd9Sstevel@tonic-gate {
11417c478bd9Sstevel@tonic-gate 	ehci_state_t		*ehcip = ehci_polledp->ehci_polled_ehcip;
11427c478bd9Sstevel@tonic-gate 	ehci_qtd_t		*curr_dummy_qtd, *next_dummy_qtd;
11437c478bd9Sstevel@tonic-gate 	ehci_qtd_t		*new_dummy_qtd;
11447c478bd9Sstevel@tonic-gate 	uint_t			qtd_control;
11457c478bd9Sstevel@tonic-gate 	ehci_pipe_private_t	*pp;
11467c478bd9Sstevel@tonic-gate 	ehci_qh_t		*qh;
11477c478bd9Sstevel@tonic-gate 	ehci_trans_wrapper_t	*tw;
11487c478bd9Sstevel@tonic-gate 
11497c478bd9Sstevel@tonic-gate 	/* Obtain the transfer wrapper from the QTD */
11507c478bd9Sstevel@tonic-gate 	tw = (ehci_trans_wrapper_t *)EHCI_LOOKUP_ID(
11517c478bd9Sstevel@tonic-gate 	    (uint32_t)Get_QTD(qtd->qtd_trans_wrapper));
11527c478bd9Sstevel@tonic-gate 
11537c478bd9Sstevel@tonic-gate 	pp = tw->tw_pipe_private;
11547c478bd9Sstevel@tonic-gate 
11557c478bd9Sstevel@tonic-gate 	/* Obtain the endpoint and interrupt request */
11567c478bd9Sstevel@tonic-gate 	qh = pp->pp_qh;
11577c478bd9Sstevel@tonic-gate 
11587c478bd9Sstevel@tonic-gate 	/*
11597c478bd9Sstevel@tonic-gate 	 * Take this QTD off the transfer wrapper's list since
11607c478bd9Sstevel@tonic-gate 	 * the pipe is FIFO, this must be the first QTD on the
11617c478bd9Sstevel@tonic-gate 	 * list.
11627c478bd9Sstevel@tonic-gate 	 */
11637c478bd9Sstevel@tonic-gate 	ASSERT((ehci_qtd_t *)tw->tw_qtd_head == qtd);
11647c478bd9Sstevel@tonic-gate 
11657c478bd9Sstevel@tonic-gate 	tw->tw_qtd_head = (ehci_qtd_t *)
11667c478bd9Sstevel@tonic-gate 	    ehci_qtd_iommu_to_cpu(ehcip, Get_QTD(qtd->qtd_tw_next_qtd));
11677c478bd9Sstevel@tonic-gate 
11687c478bd9Sstevel@tonic-gate 	/*
11697c478bd9Sstevel@tonic-gate 	 * If the head becomes NULL, then there are no more
11707c478bd9Sstevel@tonic-gate 	 * active QTD's for this transfer wrapper. Also	set
11717c478bd9Sstevel@tonic-gate 	 * the tail to NULL.
11727c478bd9Sstevel@tonic-gate 	 */
11737c478bd9Sstevel@tonic-gate 	if (tw->tw_qtd_head == NULL) {
11747c478bd9Sstevel@tonic-gate 		tw->tw_qtd_tail = NULL;
11757c478bd9Sstevel@tonic-gate 	}
11767c478bd9Sstevel@tonic-gate 
11777c478bd9Sstevel@tonic-gate 	/* Convert current valid QTD as new dummy QTD */
11787c478bd9Sstevel@tonic-gate 	bzero((char *)qtd, sizeof (ehci_qtd_t));
11797c478bd9Sstevel@tonic-gate 	Set_QTD(qtd->qtd_state, EHCI_QTD_DUMMY);
11807c478bd9Sstevel@tonic-gate 
11817c478bd9Sstevel@tonic-gate 	/* Rename qtd as new_dummy_qtd */
11827c478bd9Sstevel@tonic-gate 	new_dummy_qtd = qtd;
11837c478bd9Sstevel@tonic-gate 
11847c478bd9Sstevel@tonic-gate 	/* Get the current and next dummy QTDs */
11857c478bd9Sstevel@tonic-gate 	curr_dummy_qtd = ehci_qtd_iommu_to_cpu(ehcip,
11867c478bd9Sstevel@tonic-gate 	    Get_QH(qh->qh_dummy_qtd));
11877c478bd9Sstevel@tonic-gate 	next_dummy_qtd = ehci_qtd_iommu_to_cpu(ehcip,
11887c478bd9Sstevel@tonic-gate 	    Get_QTD(curr_dummy_qtd->qtd_next_qtd));
11897c478bd9Sstevel@tonic-gate 
11907c478bd9Sstevel@tonic-gate 	/* Update QH's dummy qtd field */
11917c478bd9Sstevel@tonic-gate 	Set_QH(qh->qh_dummy_qtd, ehci_qtd_cpu_to_iommu(ehcip, next_dummy_qtd));
11927c478bd9Sstevel@tonic-gate 
11937c478bd9Sstevel@tonic-gate 	/* Update next dummy's next qtd pointer */
11947c478bd9Sstevel@tonic-gate 	Set_QTD(next_dummy_qtd->qtd_next_qtd,
11957c478bd9Sstevel@tonic-gate 	    ehci_qtd_cpu_to_iommu(ehcip, new_dummy_qtd));
11967c478bd9Sstevel@tonic-gate 
11977c478bd9Sstevel@tonic-gate 	qtd_control = (tw->tw_direction | EHCI_QTD_CTRL_INTR_ON_COMPLETE);
11987c478bd9Sstevel@tonic-gate 
11997c478bd9Sstevel@tonic-gate 	/*
12007c478bd9Sstevel@tonic-gate 	 * Fill in the current dummy qtd and
12017c478bd9Sstevel@tonic-gate 	 * add the new dummy to the end.
12027c478bd9Sstevel@tonic-gate 	 */
12037c478bd9Sstevel@tonic-gate 	ehci_polled_fill_in_qtd(ehcip, curr_dummy_qtd, qtd_control,
12047c478bd9Sstevel@tonic-gate 	    tw->tw_cookie.dmac_address, tw->tw_length, tw);
12057c478bd9Sstevel@tonic-gate 
12067c478bd9Sstevel@tonic-gate 	/* Insert this qtd onto the tw */
12077c478bd9Sstevel@tonic-gate 	ehci_polled_insert_qtd_on_tw(ehcip, tw, curr_dummy_qtd);
12087c478bd9Sstevel@tonic-gate 
12097c478bd9Sstevel@tonic-gate 	/* Insert this qtd into active interrupt QTD list */
12107c478bd9Sstevel@tonic-gate 	ehci_polled_insert_qtd_into_active_intr_qtd_list(
12117c478bd9Sstevel@tonic-gate 	    ehci_polledp, curr_dummy_qtd);
12127c478bd9Sstevel@tonic-gate }
12137c478bd9Sstevel@tonic-gate 
12147c478bd9Sstevel@tonic-gate 
12157c478bd9Sstevel@tonic-gate /*
12167c478bd9Sstevel@tonic-gate  * ehci_polled_fill_in_qtd:
12177c478bd9Sstevel@tonic-gate  *
12187c478bd9Sstevel@tonic-gate  * Fill in the fields of a Transfer Descriptor (QTD).
12197c478bd9Sstevel@tonic-gate  *
12207c478bd9Sstevel@tonic-gate  * Unlike the it's ehci_fill_in_qtd counterpart, we do not
12217c478bd9Sstevel@tonic-gate  * set the alternative ptr in polled mode.  There is not need
12227c478bd9Sstevel@tonic-gate  * for it in polled mode, because it doesn't need to cleanup
12237c478bd9Sstevel@tonic-gate  * short xfer conditions.
12247c478bd9Sstevel@tonic-gate  */
12257c478bd9Sstevel@tonic-gate static void
12267c478bd9Sstevel@tonic-gate ehci_polled_fill_in_qtd(
12277c478bd9Sstevel@tonic-gate 	ehci_state_t		*ehcip,
12287c478bd9Sstevel@tonic-gate 	ehci_qtd_t		*qtd,
12297c478bd9Sstevel@tonic-gate 	uint_t			qtd_ctrl,
12307c478bd9Sstevel@tonic-gate 	uint32_t		qtd_iommu_cbp,
12317c478bd9Sstevel@tonic-gate 	size_t			qtd_length,
12327c478bd9Sstevel@tonic-gate 	ehci_trans_wrapper_t	*tw)
12337c478bd9Sstevel@tonic-gate {
12347c478bd9Sstevel@tonic-gate 	uint32_t		buf_addr = qtd_iommu_cbp;
12357c478bd9Sstevel@tonic-gate 	size_t			buf_len = qtd_length;
12367c478bd9Sstevel@tonic-gate 	uint32_t		ctrl = qtd_ctrl;
12377c478bd9Sstevel@tonic-gate 	uint_t			i = 0;
12387c478bd9Sstevel@tonic-gate 
12397c478bd9Sstevel@tonic-gate 	/* Assert that the qtd to be filled in is a dummy */
12407c478bd9Sstevel@tonic-gate 	ASSERT(Get_QTD(qtd->qtd_state) == EHCI_QTD_DUMMY);
12417c478bd9Sstevel@tonic-gate 
12427c478bd9Sstevel@tonic-gate 	/* Change QTD's state Active */
12437c478bd9Sstevel@tonic-gate 	Set_QTD(qtd->qtd_state, EHCI_QTD_ACTIVE);
12447c478bd9Sstevel@tonic-gate 
12457c478bd9Sstevel@tonic-gate 	/* Set the total length data tarnsfer */
12467c478bd9Sstevel@tonic-gate 	ctrl |= (((qtd_length << EHCI_QTD_CTRL_BYTES_TO_XFER_SHIFT)
12477c478bd9Sstevel@tonic-gate 	    & EHCI_QTD_CTRL_BYTES_TO_XFER) | EHCI_QTD_CTRL_MAX_ERR_COUNTS);
12487c478bd9Sstevel@tonic-gate 
12497c478bd9Sstevel@tonic-gate 	/*
12507c478bd9Sstevel@tonic-gate 	 * Save the starting buffer address used and
12517c478bd9Sstevel@tonic-gate 	 * length of data that will be transfered in
12527c478bd9Sstevel@tonic-gate 	 * the current QTD.
12537c478bd9Sstevel@tonic-gate 	 */
12547c478bd9Sstevel@tonic-gate 	Set_QTD(qtd->qtd_xfer_addr, buf_addr);
12557c478bd9Sstevel@tonic-gate 	Set_QTD(qtd->qtd_xfer_len, buf_len);
12567c478bd9Sstevel@tonic-gate 
12577c478bd9Sstevel@tonic-gate 	while (buf_len) {
12587c478bd9Sstevel@tonic-gate 		/* Update the beginning of the buffer */
12597c478bd9Sstevel@tonic-gate 		Set_QTD(qtd->qtd_buf[i], buf_addr);
12607c478bd9Sstevel@tonic-gate 
12617c478bd9Sstevel@tonic-gate 		if (buf_len <= EHCI_MAX_QTD_BUF_SIZE) {
12627c478bd9Sstevel@tonic-gate 			break;
12637c478bd9Sstevel@tonic-gate 		} else {
12647c478bd9Sstevel@tonic-gate 			buf_len -= EHCI_MAX_QTD_BUF_SIZE;
12657c478bd9Sstevel@tonic-gate 			buf_addr += EHCI_MAX_QTD_BUF_SIZE;
12667c478bd9Sstevel@tonic-gate 		}
12677c478bd9Sstevel@tonic-gate 
12687c478bd9Sstevel@tonic-gate 		i++;
12697c478bd9Sstevel@tonic-gate 	}
12707c478bd9Sstevel@tonic-gate 
12717c478bd9Sstevel@tonic-gate 	/*
12727c478bd9Sstevel@tonic-gate 	 * For control, bulk and interrupt QTD, now
12737c478bd9Sstevel@tonic-gate 	 * enable current QTD by setting active bit.
12747c478bd9Sstevel@tonic-gate 	 */
12757c478bd9Sstevel@tonic-gate 	Set_QTD(qtd->qtd_ctrl, (ctrl | EHCI_QTD_CTRL_ACTIVE_XACT));
12767c478bd9Sstevel@tonic-gate 
12777c478bd9Sstevel@tonic-gate 	Set_QTD(qtd->qtd_trans_wrapper, (uint32_t)tw->tw_id);
12787c478bd9Sstevel@tonic-gate }
12797c478bd9Sstevel@tonic-gate 
12807c478bd9Sstevel@tonic-gate 
12817c478bd9Sstevel@tonic-gate /*
12827c478bd9Sstevel@tonic-gate  * ehci_polled_insert_qtd_on_tw:
12837c478bd9Sstevel@tonic-gate  *
12847c478bd9Sstevel@tonic-gate  * The transfer wrapper keeps a list of all Transfer Descriptors (QTD) that
12857c478bd9Sstevel@tonic-gate  * are allocated for this transfer. Insert a QTD  onto this list. The  list
12867c478bd9Sstevel@tonic-gate  * of QTD's does not include the dummy QTD that is at the end of the list of
12877c478bd9Sstevel@tonic-gate  * QTD's for the endpoint.
12887c478bd9Sstevel@tonic-gate  */
12897c478bd9Sstevel@tonic-gate static void
12907c478bd9Sstevel@tonic-gate ehci_polled_insert_qtd_on_tw(
12917c478bd9Sstevel@tonic-gate 	ehci_state_t		*ehcip,
12927c478bd9Sstevel@tonic-gate 	ehci_trans_wrapper_t	*tw,
12937c478bd9Sstevel@tonic-gate 	ehci_qtd_t		*qtd)
12947c478bd9Sstevel@tonic-gate {
12957c478bd9Sstevel@tonic-gate 	/*
12967c478bd9Sstevel@tonic-gate 	 * Set the next pointer to NULL because
12977c478bd9Sstevel@tonic-gate 	 * this is the last QTD on list.
12987c478bd9Sstevel@tonic-gate 	 */
12997c478bd9Sstevel@tonic-gate 	Set_QTD(qtd->qtd_tw_next_qtd, NULL);
13007c478bd9Sstevel@tonic-gate 
13017c478bd9Sstevel@tonic-gate 	if (tw->tw_qtd_head == NULL) {
13027c478bd9Sstevel@tonic-gate 		ASSERT(tw->tw_qtd_tail == NULL);
13037c478bd9Sstevel@tonic-gate 		tw->tw_qtd_head = qtd;
13047c478bd9Sstevel@tonic-gate 		tw->tw_qtd_tail = qtd;
13057c478bd9Sstevel@tonic-gate 	} else {
13067c478bd9Sstevel@tonic-gate 		ehci_qtd_t *dummy = (ehci_qtd_t *)tw->tw_qtd_tail;
13077c478bd9Sstevel@tonic-gate 
13087c478bd9Sstevel@tonic-gate 		ASSERT(dummy != NULL);
13097c478bd9Sstevel@tonic-gate 		ASSERT(dummy != qtd);
13107c478bd9Sstevel@tonic-gate 		ASSERT(Get_QTD(qtd->qtd_state) != EHCI_QTD_DUMMY);
13117c478bd9Sstevel@tonic-gate 
13127c478bd9Sstevel@tonic-gate 		/* Add the qtd to the end of the list */
13137c478bd9Sstevel@tonic-gate 		Set_QTD(dummy->qtd_tw_next_qtd,
13147c478bd9Sstevel@tonic-gate 		    ehci_qtd_cpu_to_iommu(ehcip, qtd));
13157c478bd9Sstevel@tonic-gate 
13167c478bd9Sstevel@tonic-gate 		tw->tw_qtd_tail = qtd;
13177c478bd9Sstevel@tonic-gate 
13187c478bd9Sstevel@tonic-gate 		ASSERT(Get_QTD(qtd->qtd_tw_next_qtd) == NULL);
13197c478bd9Sstevel@tonic-gate 	}
13207c478bd9Sstevel@tonic-gate }
13217c478bd9Sstevel@tonic-gate 
13227c478bd9Sstevel@tonic-gate 
13237c478bd9Sstevel@tonic-gate /*
13247c478bd9Sstevel@tonic-gate  * ehci_polled_create_done_qtd_list:
13257c478bd9Sstevel@tonic-gate  *
13267c478bd9Sstevel@tonic-gate  * Create done qtd list from active qtd list.
13277c478bd9Sstevel@tonic-gate  */
13287c478bd9Sstevel@tonic-gate static ehci_qtd_t *
13297c478bd9Sstevel@tonic-gate ehci_polled_create_done_qtd_list(
13307c478bd9Sstevel@tonic-gate 	ehci_polled_t		*ehci_polledp)
13317c478bd9Sstevel@tonic-gate {
13327c478bd9Sstevel@tonic-gate 	ehci_state_t		*ehcip = ehci_polledp->ehci_polled_ehcip;
13337c478bd9Sstevel@tonic-gate 	ehci_qtd_t		*curr_qtd = NULL, *next_qtd = NULL;
13347c478bd9Sstevel@tonic-gate 	ehci_qtd_t		*done_qtd_list = NULL, *last_done_qtd = NULL;
13357c478bd9Sstevel@tonic-gate 
13367c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_INTR, ehcip->ehci_log_hdl,
13377c478bd9Sstevel@tonic-gate 	    "ehci_polled_create_done_qtd_list:");
13387c478bd9Sstevel@tonic-gate 
13397c478bd9Sstevel@tonic-gate 	curr_qtd = ehci_polledp->ehci_polled_active_intr_qtd_list;
13407c478bd9Sstevel@tonic-gate 
13417c478bd9Sstevel@tonic-gate 	while (curr_qtd) {
13427c478bd9Sstevel@tonic-gate 
13437c478bd9Sstevel@tonic-gate 		/* Get next qtd from the active qtd list */
13447c478bd9Sstevel@tonic-gate 		next_qtd = ehci_qtd_iommu_to_cpu(ehcip,
13457c478bd9Sstevel@tonic-gate 		    Get_QTD(curr_qtd->qtd_active_qtd_next));
13467c478bd9Sstevel@tonic-gate 
13477c478bd9Sstevel@tonic-gate 		/* Check this QTD has been processed by Host Controller */
13487c478bd9Sstevel@tonic-gate 		if (!(Get_QTD(curr_qtd->qtd_ctrl) &
13497c478bd9Sstevel@tonic-gate 		    EHCI_QTD_CTRL_ACTIVE_XACT)) {
13507c478bd9Sstevel@tonic-gate 
13517c478bd9Sstevel@tonic-gate 			/* Remove this QTD from active QTD list */
13527c478bd9Sstevel@tonic-gate 			ehci_polled_remove_qtd_from_active_intr_qtd_list(
13537c478bd9Sstevel@tonic-gate 			    ehci_polledp, curr_qtd);
13547c478bd9Sstevel@tonic-gate 
13557c478bd9Sstevel@tonic-gate 			Set_QTD(curr_qtd->qtd_active_qtd_next, NULL);
13567c478bd9Sstevel@tonic-gate 
13577c478bd9Sstevel@tonic-gate 			if (done_qtd_list) {
13587c478bd9Sstevel@tonic-gate 				Set_QTD(last_done_qtd->qtd_active_qtd_next,
13597c478bd9Sstevel@tonic-gate 				    ehci_qtd_cpu_to_iommu(ehcip, curr_qtd));
13607c478bd9Sstevel@tonic-gate 
13617c478bd9Sstevel@tonic-gate 				last_done_qtd = curr_qtd;
13627c478bd9Sstevel@tonic-gate 			} else {
13637c478bd9Sstevel@tonic-gate 				done_qtd_list = curr_qtd;
13647c478bd9Sstevel@tonic-gate 				last_done_qtd = curr_qtd;
13657c478bd9Sstevel@tonic-gate 			}
13667c478bd9Sstevel@tonic-gate 		}
13677c478bd9Sstevel@tonic-gate 
13687c478bd9Sstevel@tonic-gate 		curr_qtd = next_qtd;
13697c478bd9Sstevel@tonic-gate 	}
13707c478bd9Sstevel@tonic-gate 
13717c478bd9Sstevel@tonic-gate 	return (done_qtd_list);
13727c478bd9Sstevel@tonic-gate }
13737c478bd9Sstevel@tonic-gate 
13747c478bd9Sstevel@tonic-gate 
13757c478bd9Sstevel@tonic-gate /*
13767c478bd9Sstevel@tonic-gate  * ehci_polled_insert_qtd_into_active_intr_qtd_list:
13777c478bd9Sstevel@tonic-gate  *
13787c478bd9Sstevel@tonic-gate  * Insert current QTD into active interrupt QTD list.
13797c478bd9Sstevel@tonic-gate  */
13807c478bd9Sstevel@tonic-gate static void
13817c478bd9Sstevel@tonic-gate ehci_polled_insert_qtd_into_active_intr_qtd_list(
13827c478bd9Sstevel@tonic-gate 	ehci_polled_t		*ehci_polledp,
13837c478bd9Sstevel@tonic-gate 	ehci_qtd_t		*qtd)
13847c478bd9Sstevel@tonic-gate {
13857c478bd9Sstevel@tonic-gate 	ehci_state_t		*ehcip = ehci_polledp->ehci_polled_ehcip;
13867c478bd9Sstevel@tonic-gate 	ehci_qtd_t		*curr_qtd, *next_qtd;
13877c478bd9Sstevel@tonic-gate 
13887c478bd9Sstevel@tonic-gate 	curr_qtd = ehci_polledp->ehci_polled_active_intr_qtd_list;
13897c478bd9Sstevel@tonic-gate 
13907c478bd9Sstevel@tonic-gate 	/* Insert this qtd into active intr qtd list */
13917c478bd9Sstevel@tonic-gate 	if (curr_qtd) {
13927c478bd9Sstevel@tonic-gate 		next_qtd = ehci_qtd_iommu_to_cpu(ehcip,
13937c478bd9Sstevel@tonic-gate 		    Get_QTD(curr_qtd->qtd_active_qtd_next));
13947c478bd9Sstevel@tonic-gate 
13957c478bd9Sstevel@tonic-gate 		while (next_qtd) {
13967c478bd9Sstevel@tonic-gate 			curr_qtd = next_qtd;
13977c478bd9Sstevel@tonic-gate 			next_qtd = ehci_qtd_iommu_to_cpu(ehcip,
13987c478bd9Sstevel@tonic-gate 			    Get_QTD(curr_qtd->qtd_active_qtd_next));
13997c478bd9Sstevel@tonic-gate 		}
14007c478bd9Sstevel@tonic-gate 
14017c478bd9Sstevel@tonic-gate 		Set_QTD(qtd->qtd_active_qtd_prev,
14027c478bd9Sstevel@tonic-gate 		    ehci_qtd_cpu_to_iommu(ehcip, curr_qtd));
14037c478bd9Sstevel@tonic-gate 
14047c478bd9Sstevel@tonic-gate 		Set_QTD(curr_qtd->qtd_active_qtd_next,
14057c478bd9Sstevel@tonic-gate 		    ehci_qtd_cpu_to_iommu(ehcip, qtd));
14067c478bd9Sstevel@tonic-gate 	} else {
14077c478bd9Sstevel@tonic-gate 		ehci_polledp->ehci_polled_active_intr_qtd_list = qtd;
14087c478bd9Sstevel@tonic-gate 		Set_QTD(qtd->qtd_active_qtd_next, NULL);
14097c478bd9Sstevel@tonic-gate 		Set_QTD(qtd->qtd_active_qtd_prev, NULL);
14107c478bd9Sstevel@tonic-gate 	}
14117c478bd9Sstevel@tonic-gate }
14127c478bd9Sstevel@tonic-gate 
14137c478bd9Sstevel@tonic-gate 
14147c478bd9Sstevel@tonic-gate /*
14157c478bd9Sstevel@tonic-gate  * ehci_polled_remove_qtd_from_active_intr_qtd_list:
14167c478bd9Sstevel@tonic-gate  *
14177c478bd9Sstevel@tonic-gate  * Remove current QTD from the active QTD list.
14187c478bd9Sstevel@tonic-gate  */
14197c478bd9Sstevel@tonic-gate void
14207c478bd9Sstevel@tonic-gate ehci_polled_remove_qtd_from_active_intr_qtd_list(
14217c478bd9Sstevel@tonic-gate 	ehci_polled_t		*ehci_polledp,
14227c478bd9Sstevel@tonic-gate 	ehci_qtd_t		*qtd)
14237c478bd9Sstevel@tonic-gate {
14247c478bd9Sstevel@tonic-gate 	ehci_state_t		*ehcip = ehci_polledp->ehci_polled_ehcip;
14257c478bd9Sstevel@tonic-gate 	ehci_qtd_t		*curr_qtd, *prev_qtd, *next_qtd;
14267c478bd9Sstevel@tonic-gate 
14277c478bd9Sstevel@tonic-gate 	ASSERT(qtd != NULL);
14287c478bd9Sstevel@tonic-gate 
14297c478bd9Sstevel@tonic-gate 	curr_qtd = ehci_polledp->ehci_polled_active_intr_qtd_list;
14307c478bd9Sstevel@tonic-gate 
14317c478bd9Sstevel@tonic-gate 	while ((curr_qtd) && (curr_qtd != qtd)) {
14327c478bd9Sstevel@tonic-gate 		curr_qtd = ehci_qtd_iommu_to_cpu(ehcip,
14337c478bd9Sstevel@tonic-gate 		    Get_QTD(curr_qtd->qtd_active_qtd_next));
14347c478bd9Sstevel@tonic-gate 	}
14357c478bd9Sstevel@tonic-gate 
14367c478bd9Sstevel@tonic-gate 	if ((curr_qtd) && (curr_qtd == qtd)) {
14377c478bd9Sstevel@tonic-gate 		prev_qtd = ehci_qtd_iommu_to_cpu(ehcip,
14387c478bd9Sstevel@tonic-gate 		    Get_QTD(curr_qtd->qtd_active_qtd_prev));
14397c478bd9Sstevel@tonic-gate 		next_qtd = ehci_qtd_iommu_to_cpu(ehcip,
14407c478bd9Sstevel@tonic-gate 		    Get_QTD(curr_qtd->qtd_active_qtd_next));
14417c478bd9Sstevel@tonic-gate 
14427c478bd9Sstevel@tonic-gate 		if (prev_qtd) {
14437c478bd9Sstevel@tonic-gate 			Set_QTD(prev_qtd->qtd_active_qtd_next,
14447c478bd9Sstevel@tonic-gate 			    Get_QTD(curr_qtd->qtd_active_qtd_next));
14457c478bd9Sstevel@tonic-gate 		} else {
14467c478bd9Sstevel@tonic-gate 			ehci_polledp->
14477c478bd9Sstevel@tonic-gate 			    ehci_polled_active_intr_qtd_list = next_qtd;
14487c478bd9Sstevel@tonic-gate 		}
14497c478bd9Sstevel@tonic-gate 
14507c478bd9Sstevel@tonic-gate 		if (next_qtd) {
14517c478bd9Sstevel@tonic-gate 			Set_QTD(next_qtd->qtd_active_qtd_prev,
14527c478bd9Sstevel@tonic-gate 			    Get_QTD(curr_qtd->qtd_active_qtd_prev));
14537c478bd9Sstevel@tonic-gate 		}
14547c478bd9Sstevel@tonic-gate 	}
14557c478bd9Sstevel@tonic-gate }
14567c478bd9Sstevel@tonic-gate 
14577c478bd9Sstevel@tonic-gate 
14587c478bd9Sstevel@tonic-gate /*
14597c478bd9Sstevel@tonic-gate  * ehci_polled_traverse_qtds:
14607c478bd9Sstevel@tonic-gate  *
14617c478bd9Sstevel@tonic-gate  * Traverse the list of QTDs for given pipe using transfer wrapper.  Since
14627c478bd9Sstevel@tonic-gate  * the endpoint is marked as Halted, the Host Controller (HC) is no longer
14637c478bd9Sstevel@tonic-gate  * accessing these QTDs. Remove all the QTDs that are attached to endpoint.
14647c478bd9Sstevel@tonic-gate  */
14657c478bd9Sstevel@tonic-gate static void
14667c478bd9Sstevel@tonic-gate ehci_polled_traverse_qtds(
14677c478bd9Sstevel@tonic-gate 	ehci_polled_t		*ehci_polledp,
14687c478bd9Sstevel@tonic-gate 	usba_pipe_handle_data_t	*ph)
14697c478bd9Sstevel@tonic-gate {
14707c478bd9Sstevel@tonic-gate 	ehci_state_t		*ehcip = ehci_polledp->ehci_polled_ehcip;
14717c478bd9Sstevel@tonic-gate 	ehci_pipe_private_t	*pp = (ehci_pipe_private_t *)ph->p_hcd_private;
14727c478bd9Sstevel@tonic-gate 	ehci_trans_wrapper_t	*next_tw;
14737c478bd9Sstevel@tonic-gate 	ehci_qtd_t		*qtd;
14747c478bd9Sstevel@tonic-gate 	ehci_qtd_t		*next_qtd;
14757c478bd9Sstevel@tonic-gate 
14767c478bd9Sstevel@tonic-gate 	/* Process the transfer wrappers for this pipe */
14777c478bd9Sstevel@tonic-gate 	next_tw = pp->pp_tw_head;
14787c478bd9Sstevel@tonic-gate 
14797c478bd9Sstevel@tonic-gate 	while (next_tw) {
14807c478bd9Sstevel@tonic-gate 		qtd = (ehci_qtd_t *)next_tw->tw_qtd_head;
14817c478bd9Sstevel@tonic-gate 
14827c478bd9Sstevel@tonic-gate 		/* Walk through each QTD for this transfer wrapper */
14837c478bd9Sstevel@tonic-gate 		while (qtd) {
14847c478bd9Sstevel@tonic-gate 			/* Remove this QTD from active QTD list */
14857c478bd9Sstevel@tonic-gate 			ehci_polled_remove_qtd_from_active_intr_qtd_list(
14867c478bd9Sstevel@tonic-gate 			    ehci_polledp, qtd);
14877c478bd9Sstevel@tonic-gate 
14887c478bd9Sstevel@tonic-gate 			next_qtd = ehci_qtd_iommu_to_cpu(ehcip,
14897c478bd9Sstevel@tonic-gate 			    Get_QTD(qtd->qtd_tw_next_qtd));
14907c478bd9Sstevel@tonic-gate 
14917c478bd9Sstevel@tonic-gate 			/* Deallocate this QTD */
14927c478bd9Sstevel@tonic-gate 			ehci_deallocate_qtd(ehcip, qtd);
14937c478bd9Sstevel@tonic-gate 
14947c478bd9Sstevel@tonic-gate 			qtd = next_qtd;
14957c478bd9Sstevel@tonic-gate 		}
14967c478bd9Sstevel@tonic-gate 
14977c478bd9Sstevel@tonic-gate 		next_tw = next_tw->tw_next;
14987c478bd9Sstevel@tonic-gate 	}
14997c478bd9Sstevel@tonic-gate 
15007c478bd9Sstevel@tonic-gate 	/* Clear current qtd pointer */
15017c478bd9Sstevel@tonic-gate 	Set_QH(pp->pp_qh->qh_curr_qtd, (uint32_t)0x00000000);
15027c478bd9Sstevel@tonic-gate 
15037c478bd9Sstevel@tonic-gate 	/* Update the next qtd pointer in the QH */
15047c478bd9Sstevel@tonic-gate 	Set_QH(pp->pp_qh->qh_next_qtd, Get_QH(pp->pp_qh->qh_dummy_qtd));
15057c478bd9Sstevel@tonic-gate }
15067c478bd9Sstevel@tonic-gate 
15077c478bd9Sstevel@tonic-gate 
15087c478bd9Sstevel@tonic-gate /*
15097c478bd9Sstevel@tonic-gate  * ehci_polled_finish_interrupt:
15107c478bd9Sstevel@tonic-gate  */
15117c478bd9Sstevel@tonic-gate static void
15127c478bd9Sstevel@tonic-gate ehci_polled_finish_interrupt(
15137c478bd9Sstevel@tonic-gate 	ehci_state_t	*ehcip,
15147c478bd9Sstevel@tonic-gate 	uint_t		intr)
15157c478bd9Sstevel@tonic-gate {
15167c478bd9Sstevel@tonic-gate 	/* Acknowledge the interrupt */
15177c478bd9Sstevel@tonic-gate 	Set_OpReg(ehci_status, intr);
15187c478bd9Sstevel@tonic-gate 
15197c478bd9Sstevel@tonic-gate 	/*
15207c478bd9Sstevel@tonic-gate 	 * Read interrupt status register to make sure that any PIO
15217c478bd9Sstevel@tonic-gate 	 * store to clear the ISR has made it on the PCI bus before
15227c478bd9Sstevel@tonic-gate 	 * returning from its interrupt handler.
15237c478bd9Sstevel@tonic-gate 	 */
15247c478bd9Sstevel@tonic-gate 	(void) Get_OpReg(ehci_status);
15257c478bd9Sstevel@tonic-gate }
1526