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
54c8a46c1Syq  * Common Development and Distribution License (the "License").
64c8a46c1Syq  * 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 /*
22*09af7b17SRaymond Chen  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * Universal Host Controller Driver (UHCI)
287c478bd9Sstevel@tonic-gate  *
297c478bd9Sstevel@tonic-gate  * The UHCI driver is a driver which interfaces to the Universal
307c478bd9Sstevel@tonic-gate  * Serial Bus Driver (USBA) and the Host Controller (HC). The interface to
317c478bd9Sstevel@tonic-gate  * the Host Controller is defined by the Universal Host Controller Interface.
327c478bd9Sstevel@tonic-gate  * This file contains the code for HCDI entry points.
337c478bd9Sstevel@tonic-gate  */
347c478bd9Sstevel@tonic-gate #include <sys/usb/hcd/uhci/uhcid.h>
357c478bd9Sstevel@tonic-gate #include <sys/usb/hcd/uhci/uhcitgt.h>
367c478bd9Sstevel@tonic-gate #include <sys/usb/hcd/uhci/uhciutil.h>
3722eb7cb5Sgd #include <sys/strsun.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /* function prototypes */
407c478bd9Sstevel@tonic-gate static int	uhci_pipe_send_isoc_data(uhci_state_t *uhcip,
417c478bd9Sstevel@tonic-gate 			usba_pipe_handle_data_t *ph, usb_isoc_req_t *isoc_req,
427c478bd9Sstevel@tonic-gate 			usb_flags_t usb_flags);
437c478bd9Sstevel@tonic-gate static int	uhci_send_intr_data(uhci_state_t *uhcip,
447c478bd9Sstevel@tonic-gate 			usba_pipe_handle_data_t	*pipe_handle,
457c478bd9Sstevel@tonic-gate 			usb_intr_req_t		*req,
467c478bd9Sstevel@tonic-gate 			usb_flags_t		flags);
477c478bd9Sstevel@tonic-gate static int	uhci_start_periodic_pipe_polling(uhci_state_t *uhcip,
487c478bd9Sstevel@tonic-gate 			usba_pipe_handle_data_t	*ph,
497c478bd9Sstevel@tonic-gate 			usb_opaque_t		reqp,
507c478bd9Sstevel@tonic-gate 			usb_flags_t		flags);
517c478bd9Sstevel@tonic-gate static int	uhci_stop_periodic_pipe_polling(uhci_state_t *uhcip,
527c478bd9Sstevel@tonic-gate 			usba_pipe_handle_data_t	*ph,
537c478bd9Sstevel@tonic-gate 			usb_flags_t		flags);
547c478bd9Sstevel@tonic-gate static void	uhci_update_intr_td_data_toggle(uhci_state_t *uhcip,
557c478bd9Sstevel@tonic-gate 			uhci_pipe_private_t *pp);
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate /* Maximum bulk transfer size */
594610e4a0Sfrits int uhci_bulk_transfer_size = UHCI_BULK_MAX_XFER_SIZE;
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate /*
627c478bd9Sstevel@tonic-gate  * uhci_hcdi_pipe_open:
637c478bd9Sstevel@tonic-gate  *	Member of HCD Ops structure and called during client specific pipe open
647c478bd9Sstevel@tonic-gate  *	Add the pipe to the data structure representing the device and allocate
657c478bd9Sstevel@tonic-gate  *	bandwidth for the pipe if it is a interrupt or isochronous endpoint.
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate int
687c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_open(usba_pipe_handle_data_t *ph, usb_flags_t flags)
697c478bd9Sstevel@tonic-gate {
707c478bd9Sstevel@tonic-gate 	uint_t			node = 0;
717c478bd9Sstevel@tonic-gate 	usb_addr_t		usb_addr;
727c478bd9Sstevel@tonic-gate 	uhci_state_t		*uhcip;
737c478bd9Sstevel@tonic-gate 	uhci_pipe_private_t	*pp;
74fffe0b30Sqz 	int			rval, error = USB_SUCCESS;
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 	ASSERT(ph);
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 	usb_addr = ph->p_usba_device->usb_addr;
797c478bd9Sstevel@tonic-gate 	uhcip = uhci_obtain_state(ph->p_usba_device->usb_root_hub_dip);
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
827c478bd9Sstevel@tonic-gate 	    "uhci_hcdi_pipe_open: addr = 0x%x, ep%d", usb_addr,
837c478bd9Sstevel@tonic-gate 	    ph->p_ep.bEndpointAddress & USB_EP_NUM_MASK);
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate 	sema_p(&uhcip->uhci_ocsem);
867c478bd9Sstevel@tonic-gate 
87fffe0b30Sqz 	mutex_enter(&uhcip->uhci_int_mutex);
88fffe0b30Sqz 	rval = uhci_state_is_operational(uhcip);
89fffe0b30Sqz 	mutex_exit(&uhcip->uhci_int_mutex);
90fffe0b30Sqz 
91fffe0b30Sqz 	if (rval != USB_SUCCESS) {
92fffe0b30Sqz 		sema_v(&uhcip->uhci_ocsem);
93fffe0b30Sqz 
94fffe0b30Sqz 		return (rval);
95fffe0b30Sqz 	}
96fffe0b30Sqz 
977c478bd9Sstevel@tonic-gate 	/*
987c478bd9Sstevel@tonic-gate 	 * Return failure immediately for any other pipe open on the root hub
997c478bd9Sstevel@tonic-gate 	 * except control or interrupt pipe.
1007c478bd9Sstevel@tonic-gate 	 */
1017c478bd9Sstevel@tonic-gate 	if (usb_addr == ROOT_HUB_ADDR) {
1027c478bd9Sstevel@tonic-gate 		switch (UHCI_XFER_TYPE(&ph->p_ep)) {
1037c478bd9Sstevel@tonic-gate 		case USB_EP_ATTR_CONTROL:
1047c478bd9Sstevel@tonic-gate 			USB_DPRINTF_L3(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
1057c478bd9Sstevel@tonic-gate 			    "uhci_hcdi_pipe_open: Root hub control pipe");
1067c478bd9Sstevel@tonic-gate 			break;
1077c478bd9Sstevel@tonic-gate 		case USB_EP_ATTR_INTR:
1087c478bd9Sstevel@tonic-gate 			ASSERT(UHCI_XFER_DIR(&ph->p_ep) == USB_EP_DIR_IN);
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 			mutex_enter(&uhcip->uhci_int_mutex);
1117c478bd9Sstevel@tonic-gate 			uhcip->uhci_root_hub.rh_intr_pipe_handle = ph;
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 			/*
1147c478bd9Sstevel@tonic-gate 			 * Set the state of the root hub interrupt
1157c478bd9Sstevel@tonic-gate 			 * pipe as IDLE.
1167c478bd9Sstevel@tonic-gate 			 */
1177c478bd9Sstevel@tonic-gate 			uhcip->uhci_root_hub.rh_pipe_state =
118fffe0b30Sqz 			    UHCI_PIPE_STATE_IDLE;
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 			ASSERT(uhcip->uhci_root_hub.rh_client_intr_req == NULL);
1217c478bd9Sstevel@tonic-gate 			uhcip->uhci_root_hub.rh_client_intr_req = NULL;
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 			ASSERT(uhcip->uhci_root_hub.rh_curr_intr_reqp == NULL);
1247c478bd9Sstevel@tonic-gate 			uhcip->uhci_root_hub.rh_curr_intr_reqp = NULL;
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate 			USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
1277c478bd9Sstevel@tonic-gate 			    "uhci_hcdi_pipe_open: Root hub interrupt "
1287c478bd9Sstevel@tonic-gate 			    "pipe open succeeded");
1297c478bd9Sstevel@tonic-gate 			mutex_exit(&uhcip->uhci_int_mutex);
1307c478bd9Sstevel@tonic-gate 			sema_v(&uhcip->uhci_ocsem);
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 			return (USB_SUCCESS);
1337c478bd9Sstevel@tonic-gate 		default:
1347c478bd9Sstevel@tonic-gate 			USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
1357c478bd9Sstevel@tonic-gate 			    "uhci_hcdi_pipe_open: Root hub pipe open failed");
1367c478bd9Sstevel@tonic-gate 			sema_v(&uhcip->uhci_ocsem);
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 			return (USB_FAILURE);
1397c478bd9Sstevel@tonic-gate 		}
1407c478bd9Sstevel@tonic-gate 	}
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	/*
1437c478bd9Sstevel@tonic-gate 	 * A portion of the bandwidth is reserved for the non-periodic
1447c478bd9Sstevel@tonic-gate 	 * transfers  i.e control and bulk transfers in each  of one
1457c478bd9Sstevel@tonic-gate 	 * mill second frame period & usually it will be 10% of frame
1467c478bd9Sstevel@tonic-gate 	 * period. Hence there is no need to check for the available
1477c478bd9Sstevel@tonic-gate 	 * bandwidth before adding the control or bulk endpoints.
1487c478bd9Sstevel@tonic-gate 	 *
1497c478bd9Sstevel@tonic-gate 	 * There is a need to check for the available bandwidth before
1507c478bd9Sstevel@tonic-gate 	 * adding the periodic transfers i.e interrupt & isochronous, since
1517c478bd9Sstevel@tonic-gate 	 * all these periodic transfers are guaranteed transfers. Usually,
1527c478bd9Sstevel@tonic-gate 	 * 90% of the total frame time is reserved for periodic transfers.
1537c478bd9Sstevel@tonic-gate 	 */
1547c478bd9Sstevel@tonic-gate 	if (UHCI_PERIODIC_ENDPOINT(&ph->p_ep)) {
1557c478bd9Sstevel@tonic-gate 		/* Zero Max Packet size endpoints are not supported */
1567c478bd9Sstevel@tonic-gate 		if (ph->p_ep.wMaxPacketSize == 0) {
1577c478bd9Sstevel@tonic-gate 			USB_DPRINTF_L3(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
1587c478bd9Sstevel@tonic-gate 			    "uhci_hcdi_pipe_open: Zero length packet");
1597c478bd9Sstevel@tonic-gate 			sema_v(&uhcip->uhci_ocsem);
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 			return (USB_FAILURE);
1627c478bd9Sstevel@tonic-gate 		}
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 		mutex_enter(&uhcip->uhci_int_mutex);
1657c478bd9Sstevel@tonic-gate 		mutex_enter(&ph->p_mutex);
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 		error = uhci_allocate_bandwidth(uhcip, ph, &node);
1687c478bd9Sstevel@tonic-gate 		if (error != USB_SUCCESS) {
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 			USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
1717c478bd9Sstevel@tonic-gate 			    "uhci_hcdi_pipe_open: Bandwidth allocation failed");
1727c478bd9Sstevel@tonic-gate 			mutex_exit(&ph->p_mutex);
1737c478bd9Sstevel@tonic-gate 			mutex_exit(&uhcip->uhci_int_mutex);
1747c478bd9Sstevel@tonic-gate 			sema_v(&uhcip->uhci_ocsem);
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 			return (error);
1777c478bd9Sstevel@tonic-gate 		}
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 		mutex_exit(&ph->p_mutex);
1807c478bd9Sstevel@tonic-gate 		mutex_exit(&uhcip->uhci_int_mutex);
1817c478bd9Sstevel@tonic-gate 	}
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate 	/* Create the HCD pipe private structure */
1847c478bd9Sstevel@tonic-gate 	pp = kmem_zalloc(sizeof (uhci_pipe_private_t),
1857c478bd9Sstevel@tonic-gate 	    (flags & USB_FLAGS_SLEEP) ? KM_SLEEP : KM_NOSLEEP);
1867c478bd9Sstevel@tonic-gate 	if (pp == NULL) {
1877c478bd9Sstevel@tonic-gate 		USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
1887c478bd9Sstevel@tonic-gate 		    "uhci_hcdi_pipe_open: pp allocation failure");
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 		if (UHCI_PERIODIC_ENDPOINT(&ph->p_ep)) {
1917c478bd9Sstevel@tonic-gate 			mutex_enter(&uhcip->uhci_int_mutex);
1927c478bd9Sstevel@tonic-gate 			uhci_deallocate_bandwidth(uhcip, ph);
1937c478bd9Sstevel@tonic-gate 			mutex_exit(&uhcip->uhci_int_mutex);
1947c478bd9Sstevel@tonic-gate 		}
1957c478bd9Sstevel@tonic-gate 		sema_v(&uhcip->uhci_ocsem);
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 		return (USB_NO_RESOURCES);
1987c478bd9Sstevel@tonic-gate 	}
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 	mutex_enter(&uhcip->uhci_int_mutex);
201fffe0b30Sqz 	rval = uhci_state_is_operational(uhcip);
202fffe0b30Sqz 
203fffe0b30Sqz 	if (rval != USB_SUCCESS) {
204fffe0b30Sqz 		kmem_free(ph, sizeof (uhci_pipe_private_t));
205fffe0b30Sqz 		mutex_exit(&uhcip->uhci_int_mutex);
206fffe0b30Sqz 		sema_v(&uhcip->uhci_ocsem);
207fffe0b30Sqz 
208fffe0b30Sqz 		return (rval);
209fffe0b30Sqz 	}
2107c478bd9Sstevel@tonic-gate 	pp->pp_node = node;	/* Store the node in the interrupt lattice */
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 	/* Initialize frame number */
2137c478bd9Sstevel@tonic-gate 	pp->pp_frame_num = INVALID_FRNUM;
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 	/* Set the state of pipe as IDLE */
2167c478bd9Sstevel@tonic-gate 	pp->pp_state = UHCI_PIPE_STATE_IDLE;
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	/* Store a pointer to the pipe handle */
2197c478bd9Sstevel@tonic-gate 	pp->pp_pipe_handle = ph;
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate 	/* Store the pointer in the pipe handle */
2227c478bd9Sstevel@tonic-gate 	mutex_enter(&ph->p_mutex);
2237c478bd9Sstevel@tonic-gate 	ph->p_hcd_private = (usb_opaque_t)pp;
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 	/* Store a copy of the pipe policy */
2267c478bd9Sstevel@tonic-gate 	bcopy(&ph->p_policy, &pp->pp_policy, sizeof (usb_pipe_policy_t));
2277c478bd9Sstevel@tonic-gate 	mutex_exit(&ph->p_mutex);
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	/* don't check for ROOT_HUB here anymore */
2307c478bd9Sstevel@tonic-gate 	if (UHCI_XFER_TYPE(&ph->p_ep) != USB_EP_ATTR_ISOCH) {
2317c478bd9Sstevel@tonic-gate 		/* Allocate the host controller endpoint descriptor */
2327c478bd9Sstevel@tonic-gate 		pp->pp_qh = uhci_alloc_queue_head(uhcip);
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate 		if (pp->pp_qh == NULL) {
2357c478bd9Sstevel@tonic-gate 			USB_DPRINTF_L2(PRINT_MASK_LISTS, uhcip->uhci_log_hdl,
2367c478bd9Sstevel@tonic-gate 			    "uhci_hcdi_pipe_open: QH allocation failed");
2377c478bd9Sstevel@tonic-gate 
2384c8a46c1Syq 			if (UHCI_PERIODIC_ENDPOINT(&ph->p_ep)) {
2394c8a46c1Syq 				uhci_deallocate_bandwidth(uhcip, ph);
2404c8a46c1Syq 			}
2414c8a46c1Syq 
2427c478bd9Sstevel@tonic-gate 			mutex_enter(&ph->p_mutex);
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 			/*
2457c478bd9Sstevel@tonic-gate 			 * Deallocate the hcd private portion
2467c478bd9Sstevel@tonic-gate 			 * of the pipe handle.
2477c478bd9Sstevel@tonic-gate 			 */
2487c478bd9Sstevel@tonic-gate 			kmem_free(ph->p_hcd_private,
249fffe0b30Sqz 			    sizeof (uhci_pipe_private_t));
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 			/*
2527c478bd9Sstevel@tonic-gate 			 * Set the private structure in the
2537c478bd9Sstevel@tonic-gate 			 * pipe handle equal to NULL.
2547c478bd9Sstevel@tonic-gate 			 */
2557c478bd9Sstevel@tonic-gate 			ph->p_hcd_private = NULL;
2567c478bd9Sstevel@tonic-gate 			mutex_exit(&ph->p_mutex);
2577c478bd9Sstevel@tonic-gate 			mutex_exit(&uhcip->uhci_int_mutex);
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 			sema_v(&uhcip->uhci_ocsem);
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate 			return (USB_NO_RESOURCES);
2627c478bd9Sstevel@tonic-gate 		}
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 		/*
2657c478bd9Sstevel@tonic-gate 		 * Insert the endpoint onto the host controller's
2667c478bd9Sstevel@tonic-gate 		 * appropriate endpoint list. The host controller
2677c478bd9Sstevel@tonic-gate 		 * will not schedule this endpoint until there are
2687c478bd9Sstevel@tonic-gate 		 * any TD's to process.
2697c478bd9Sstevel@tonic-gate 		 */
2707c478bd9Sstevel@tonic-gate 		uhci_insert_qh(uhcip, ph);
2717c478bd9Sstevel@tonic-gate 	}
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate 	/*
2747c478bd9Sstevel@tonic-gate 	 * Restore the data toggle from usb device structure.
2757c478bd9Sstevel@tonic-gate 	 */
2764c8a46c1Syq 	if (((ph->p_ep.bmAttributes) & USB_EP_ATTR_MASK) == USB_EP_ATTR_INTR ||
2774c8a46c1Syq 	    ((ph->p_ep.bmAttributes) & USB_EP_ATTR_MASK) == USB_EP_ATTR_BULK) {
2787c478bd9Sstevel@tonic-gate 		mutex_enter(&ph->p_mutex);
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 		pp->pp_data_toggle = usba_hcdi_get_data_toggle(
281fffe0b30Sqz 		    ph->p_usba_device, ph->p_ep.bEndpointAddress);
2827c478bd9Sstevel@tonic-gate 		mutex_exit(&ph->p_mutex);
2837c478bd9Sstevel@tonic-gate 	}
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate 	mutex_exit(&uhcip->uhci_int_mutex);
2867c478bd9Sstevel@tonic-gate 	sema_v(&uhcip->uhci_ocsem);
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
289112116d8Sfb 	    "uhci_hcdi_pipe_open: ph = 0x%p", (void *)ph);
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate 	return (USB_SUCCESS);
2927c478bd9Sstevel@tonic-gate }
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate /*
2967c478bd9Sstevel@tonic-gate  * uhci_hcdi_pipe_close:
2977c478bd9Sstevel@tonic-gate  *	Member of HCD Ops structure and called during the client specific pipe
2987c478bd9Sstevel@tonic-gate  *	close. Remove the pipe to the data structure representing the device
2997c478bd9Sstevel@tonic-gate  *	deallocate bandwidth for the pipe if it is an intr or isoch endpoint.
3007c478bd9Sstevel@tonic-gate  */
3017c478bd9Sstevel@tonic-gate int
3027c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_close(usba_pipe_handle_data_t *ph, usb_flags_t usb_flags)
3037c478bd9Sstevel@tonic-gate {
3047c478bd9Sstevel@tonic-gate 	usb_addr_t		usb_addr;
3057c478bd9Sstevel@tonic-gate 	uhci_state_t		*uhcip;
3067c478bd9Sstevel@tonic-gate 	usb_ep_descr_t		*eptd = &ph->p_ep;
3077c478bd9Sstevel@tonic-gate 	uhci_pipe_private_t	*pp;
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate 	uhcip = uhci_obtain_state(ph->p_usba_device->usb_root_hub_dip);
3107c478bd9Sstevel@tonic-gate 	pp = (uhci_pipe_private_t *)ph->p_hcd_private;
3117c478bd9Sstevel@tonic-gate 	usb_addr = ph->p_usba_device->usb_addr;
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
3147c478bd9Sstevel@tonic-gate 	    "uhci_hcdi_pipe_close: addr = 0x%x, ep%d, flags = 0x%x", usb_addr,
3157c478bd9Sstevel@tonic-gate 	    eptd->bEndpointAddress, usb_flags);
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate 	sema_p(&uhcip->uhci_ocsem);
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate 	mutex_enter(&uhcip->uhci_int_mutex);
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate 	/*
3227c478bd9Sstevel@tonic-gate 	 * Check whether the pipe is a root hub
3237c478bd9Sstevel@tonic-gate 	 */
3247c478bd9Sstevel@tonic-gate 	if (usb_addr == ROOT_HUB_ADDR) {
3257c478bd9Sstevel@tonic-gate 		switch (UHCI_XFER_TYPE(eptd)) {
3267c478bd9Sstevel@tonic-gate 		case USB_EP_ATTR_CONTROL:
3277c478bd9Sstevel@tonic-gate 			USB_DPRINTF_L3(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
3287c478bd9Sstevel@tonic-gate 			    "uhci_hcdi_pipe_close: Root hub control pipe "
3297c478bd9Sstevel@tonic-gate 			    "close succeeded");
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 			break;
3327c478bd9Sstevel@tonic-gate 		case USB_EP_ATTR_INTR:
3337c478bd9Sstevel@tonic-gate 			ASSERT((eptd->bEndpointAddress &
334fffe0b30Sqz 			    USB_EP_NUM_MASK) == 1);
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate 			/* Do interrupt pipe cleanup */
3377c478bd9Sstevel@tonic-gate 			uhci_root_hub_intr_pipe_cleanup(uhcip,
338fffe0b30Sqz 			    USB_CR_PIPE_CLOSING);
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate 			ASSERT(uhcip->uhci_root_hub.rh_pipe_state ==
341fffe0b30Sqz 			    UHCI_PIPE_STATE_IDLE);
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate 			uhcip->uhci_root_hub.rh_intr_pipe_handle = NULL;
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 			USB_DPRINTF_L3(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
3467c478bd9Sstevel@tonic-gate 			    "uhci_hcdi_pipe_close: Root hub interrupt "
3477c478bd9Sstevel@tonic-gate 			    "pipe close succeeded");
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate 			uhcip->uhci_root_hub.rh_pipe_state =
350fffe0b30Sqz 			    UHCI_PIPE_STATE_IDLE;
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 			mutex_exit(&uhcip->uhci_int_mutex);
3537c478bd9Sstevel@tonic-gate 			sema_v(&uhcip->uhci_ocsem);
3547c478bd9Sstevel@tonic-gate 			return (USB_SUCCESS);
3557c478bd9Sstevel@tonic-gate 		}
3567c478bd9Sstevel@tonic-gate 	} else {
3577c478bd9Sstevel@tonic-gate 		/*
3587c478bd9Sstevel@tonic-gate 		 * Stop all the transactions if it is not the root hub.
3597c478bd9Sstevel@tonic-gate 		 */
3607c478bd9Sstevel@tonic-gate 		if (UHCI_XFER_TYPE(eptd) == USB_EP_ATTR_INTR) {
3617c478bd9Sstevel@tonic-gate 			/*
3627c478bd9Sstevel@tonic-gate 			 * Stop polling on the pipe to prevent any subsequently
3637c478bd9Sstevel@tonic-gate 			 * queued tds (while we're waiting for SOF, below)
3647c478bd9Sstevel@tonic-gate 			 * from being executed
3657c478bd9Sstevel@tonic-gate 			 */
3667c478bd9Sstevel@tonic-gate 			pp->pp_state = UHCI_PIPE_STATE_IDLE;
3677c478bd9Sstevel@tonic-gate 		}
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate 		/* Disable all outstanding tds */
3707c478bd9Sstevel@tonic-gate 		uhci_modify_td_active_bits(uhcip, pp);
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate 		/* Prevent this queue from being executed */
3737c478bd9Sstevel@tonic-gate 		if (UHCI_XFER_TYPE(eptd) != USB_EP_ATTR_ISOCH) {
3747c478bd9Sstevel@tonic-gate 			UHCI_SET_TERMINATE_BIT(pp->pp_qh->element_ptr);
3757c478bd9Sstevel@tonic-gate 		}
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate 		/* Wait for the next start of frame */
3787c478bd9Sstevel@tonic-gate 		(void) uhci_wait_for_sof(uhcip);
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate 		ASSERT(eptd != NULL);
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate 		switch (UHCI_XFER_TYPE(eptd)) {
3837c478bd9Sstevel@tonic-gate 		case USB_EP_ATTR_INTR:
3847c478bd9Sstevel@tonic-gate 			uhci_update_intr_td_data_toggle(uhcip, pp);
3857c478bd9Sstevel@tonic-gate 			/* FALLTHROUGH */
3867c478bd9Sstevel@tonic-gate 		case USB_EP_ATTR_CONTROL:
3877c478bd9Sstevel@tonic-gate 			uhci_remove_tds_tws(uhcip, ph);
3887c478bd9Sstevel@tonic-gate 			break;
3897c478bd9Sstevel@tonic-gate 		case USB_EP_ATTR_BULK:
3907c478bd9Sstevel@tonic-gate 			SetQH32(uhcip, pp->pp_qh->element_ptr,
3917c478bd9Sstevel@tonic-gate 			    TD_PADDR(pp->pp_qh->td_tailp));
3927c478bd9Sstevel@tonic-gate 			uhci_remove_bulk_tds_tws(uhcip, pp, UHCI_IN_CLOSE);
3937c478bd9Sstevel@tonic-gate 			uhci_save_data_toggle(pp);
3947c478bd9Sstevel@tonic-gate 			break;
3957c478bd9Sstevel@tonic-gate 		case USB_EP_ATTR_ISOCH:
3967c478bd9Sstevel@tonic-gate 			uhci_remove_isoc_tds_tws(uhcip, pp);
3977c478bd9Sstevel@tonic-gate 			break;
3987c478bd9Sstevel@tonic-gate 		default:
3997c478bd9Sstevel@tonic-gate 			USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
4007c478bd9Sstevel@tonic-gate 			    "uhci_hcdi_pipe_close: Unknown xfer type");
4017c478bd9Sstevel@tonic-gate 			break;
4027c478bd9Sstevel@tonic-gate 		}
4037c478bd9Sstevel@tonic-gate 
4047c478bd9Sstevel@tonic-gate 		/*
4057c478bd9Sstevel@tonic-gate 		 * Remove the endoint descriptor from Host Controller's
4067c478bd9Sstevel@tonic-gate 		 * appropriate endpoint list. Isochronous pipes dont have
4077c478bd9Sstevel@tonic-gate 		 * any queue heads attached to it.
4087c478bd9Sstevel@tonic-gate 		 */
4097c478bd9Sstevel@tonic-gate 		if (UHCI_XFER_TYPE(eptd) != USB_EP_ATTR_ISOCH) {
4107c478bd9Sstevel@tonic-gate 			uhci_remove_qh(uhcip, pp);
4117c478bd9Sstevel@tonic-gate 		}
4127c478bd9Sstevel@tonic-gate 
4137c478bd9Sstevel@tonic-gate 		/*
4147c478bd9Sstevel@tonic-gate 		 * Do the callback for the original client
4157c478bd9Sstevel@tonic-gate 		 * periodic IN request.
4167c478bd9Sstevel@tonic-gate 		 */
4177c478bd9Sstevel@tonic-gate 		if (pp->pp_client_periodic_in_reqp) {
4187c478bd9Sstevel@tonic-gate 			uhci_hcdi_callback(uhcip, pp, ph, NULL,
4197c478bd9Sstevel@tonic-gate 			    USB_CR_PIPE_CLOSING);
4207c478bd9Sstevel@tonic-gate 		}
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate 		/* Deallocate bandwidth */
4237c478bd9Sstevel@tonic-gate 		if (UHCI_PERIODIC_ENDPOINT(eptd)) {
4247c478bd9Sstevel@tonic-gate 			mutex_enter(&ph->p_mutex);
4257c478bd9Sstevel@tonic-gate 			uhci_deallocate_bandwidth(uhcip, ph);
4267c478bd9Sstevel@tonic-gate 			mutex_exit(&ph->p_mutex);
4277c478bd9Sstevel@tonic-gate 		}
4287c478bd9Sstevel@tonic-gate 	}
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate 	/* Deallocate the hcd private portion of the pipe handle.  */
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate 	mutex_enter(&ph->p_mutex);
4337c478bd9Sstevel@tonic-gate 	kmem_free(ph->p_hcd_private, sizeof (uhci_pipe_private_t));
4347c478bd9Sstevel@tonic-gate 	ph->p_hcd_private = NULL;
4357c478bd9Sstevel@tonic-gate 	mutex_exit(&ph->p_mutex);
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
438112116d8Sfb 	    "uhci_hcdi_pipe_close: ph = 0x%p", (void *)ph);
4397c478bd9Sstevel@tonic-gate 
4407c478bd9Sstevel@tonic-gate 	mutex_exit(&uhcip->uhci_int_mutex);
4417c478bd9Sstevel@tonic-gate 	sema_v(&uhcip->uhci_ocsem);
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate 	return (USB_SUCCESS);
4447c478bd9Sstevel@tonic-gate }
4457c478bd9Sstevel@tonic-gate 
4467c478bd9Sstevel@tonic-gate 
4477c478bd9Sstevel@tonic-gate /*
4487c478bd9Sstevel@tonic-gate  * uhci_hcdi_pipe_reset:
4497c478bd9Sstevel@tonic-gate  */
4507c478bd9Sstevel@tonic-gate int
4517c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_reset(usba_pipe_handle_data_t *ph, usb_flags_t usb_flags)
4527c478bd9Sstevel@tonic-gate {
4537c478bd9Sstevel@tonic-gate 	uhci_state_t		*uhcip = uhci_obtain_state(
454fffe0b30Sqz 	    ph->p_usba_device->usb_root_hub_dip);
4557c478bd9Sstevel@tonic-gate 	uhci_pipe_private_t	*pp = (uhci_pipe_private_t *)ph->p_hcd_private;
4567c478bd9Sstevel@tonic-gate 	usb_ep_descr_t		*eptd = &ph->p_ep;
457*09af7b17SRaymond Chen 	int i = 0;
458*09af7b17SRaymond Chen 	uint_t new_port_status = 0, old_port_status = 0;
4597c478bd9Sstevel@tonic-gate 
4607c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
4617c478bd9Sstevel@tonic-gate 	    "uhci_hcdi_pipe_reset: usb_flags = 0x%x", usb_flags);
4627c478bd9Sstevel@tonic-gate 
463*09af7b17SRaymond Chen 	/*
464*09af7b17SRaymond Chen 	 * Under some circumstances, uhci internal hub's port
465*09af7b17SRaymond Chen 	 * may become disabled because of some errors(see UHCI HCD Spec)
466*09af7b17SRaymond Chen 	 * to make the UHCI driver robust enough, we should try to
467*09af7b17SRaymond Chen 	 * re-enable it again here because HCD has already know something
468*09af7b17SRaymond Chen 	 * bad happened.
469*09af7b17SRaymond Chen 	 */
470*09af7b17SRaymond Chen 	USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
471*09af7b17SRaymond Chen 	    "uhci_hcdi_pipe_reset: try "
472*09af7b17SRaymond Chen 	    "to enable disabled ports if necessary.");
473*09af7b17SRaymond Chen 	for (i = 0; i < uhcip->uhci_root_hub.rh_num_ports; i++) {
474*09af7b17SRaymond Chen 		old_port_status = Get_OpReg16(PORTSC[i]);
475*09af7b17SRaymond Chen 		if (!(old_port_status & HCR_PORT_ENABLE)) {
476*09af7b17SRaymond Chen 			Set_OpReg16(PORTSC[i],
477*09af7b17SRaymond Chen 			    (old_port_status | HCR_PORT_ENABLE));
478*09af7b17SRaymond Chen 			drv_usecwait(UHCI_ONE_MS * 2);
479*09af7b17SRaymond Chen 			new_port_status = Get_OpReg16(PORTSC[i]);
480*09af7b17SRaymond Chen 			/*
481*09af7b17SRaymond Chen 			 * Refresh Root Hub port status
482*09af7b17SRaymond Chen 			 */
483*09af7b17SRaymond Chen 			uhcip->uhci_root_hub.rh_port_status[i] =
484*09af7b17SRaymond Chen 			    new_port_status;
485*09af7b17SRaymond Chen 			uhcip->uhci_root_hub.rh_port_changes[i] |=
486*09af7b17SRaymond Chen 			    ((old_port_status ^ new_port_status) & 0xff);
487*09af7b17SRaymond Chen 		}
488*09af7b17SRaymond Chen 	}
489*09af7b17SRaymond Chen 
4907c478bd9Sstevel@tonic-gate 	/*
4917c478bd9Sstevel@tonic-gate 	 * Return failure immediately for any other pipe reset on the root
4927c478bd9Sstevel@tonic-gate 	 * hub except control or interrupt pipe.
4937c478bd9Sstevel@tonic-gate 	 */
4947c478bd9Sstevel@tonic-gate 	if (ph->p_usba_device->usb_addr == ROOT_HUB_ADDR) {
4957c478bd9Sstevel@tonic-gate 		switch (UHCI_XFER_TYPE(&ph->p_ep)) {
4967c478bd9Sstevel@tonic-gate 		case USB_EP_ATTR_CONTROL:
4977c478bd9Sstevel@tonic-gate 			USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
4987c478bd9Sstevel@tonic-gate 			    "uhci_hcdi_pipe_reset: Pipe reset for root"
4997c478bd9Sstevel@tonic-gate 			    "hub control pipe successful");
5007c478bd9Sstevel@tonic-gate 
5017c478bd9Sstevel@tonic-gate 			break;
5027c478bd9Sstevel@tonic-gate 		case USB_EP_ATTR_INTR:
5037c478bd9Sstevel@tonic-gate 			mutex_enter(&uhcip->uhci_int_mutex);
5047c478bd9Sstevel@tonic-gate 			uhcip->uhci_root_hub.rh_pipe_state =
505fffe0b30Sqz 			    UHCI_PIPE_STATE_IDLE;
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate 			/* Do interrupt pipe cleanup */
5087c478bd9Sstevel@tonic-gate 			uhci_root_hub_intr_pipe_cleanup(uhcip,
509fffe0b30Sqz 			    USB_CR_PIPE_RESET);
5107c478bd9Sstevel@tonic-gate 
5117c478bd9Sstevel@tonic-gate 			USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
5127c478bd9Sstevel@tonic-gate 			    "uhci_hcdi_pipe_reset: Pipe reset for "
5137c478bd9Sstevel@tonic-gate 			    "root hub interrupt pipe successful");
5147c478bd9Sstevel@tonic-gate 			mutex_exit(&uhcip->uhci_int_mutex);
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate 			break;
5177c478bd9Sstevel@tonic-gate 		default:
5187c478bd9Sstevel@tonic-gate 			USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
519fffe0b30Sqz 			    "uhci_hcdi_pipe_reset: Root hub pipe reset failed");
5207c478bd9Sstevel@tonic-gate 
5217c478bd9Sstevel@tonic-gate 			return (USB_FAILURE);
5227c478bd9Sstevel@tonic-gate 		}
5237c478bd9Sstevel@tonic-gate 
5247c478bd9Sstevel@tonic-gate 		return (USB_SUCCESS);
5257c478bd9Sstevel@tonic-gate 	}
5267c478bd9Sstevel@tonic-gate 
5277c478bd9Sstevel@tonic-gate 	mutex_enter(&uhcip->uhci_int_mutex);
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate 	/*
5307c478bd9Sstevel@tonic-gate 	 * Set the active bit in to INACTIVE for all the remaining TD's of
5317c478bd9Sstevel@tonic-gate 	 * this end point.  Set the active bit for the dummy td. This will
5327c478bd9Sstevel@tonic-gate 	 * generate an interrupt at the end of the frame.  After receiving
5337c478bd9Sstevel@tonic-gate 	 * the interrupt, it is safe to to manipulate the lattice.
5347c478bd9Sstevel@tonic-gate 	 */
5357c478bd9Sstevel@tonic-gate 	uhci_modify_td_active_bits(uhcip, pp);
5367c478bd9Sstevel@tonic-gate 
5377c478bd9Sstevel@tonic-gate 	/* Initialize the element pointer */
5387c478bd9Sstevel@tonic-gate 	if (UHCI_XFER_TYPE(eptd) != USB_EP_ATTR_ISOCH) {
5397c478bd9Sstevel@tonic-gate 		UHCI_SET_TERMINATE_BIT(pp->pp_qh->element_ptr);
5407c478bd9Sstevel@tonic-gate 		SetQH32(uhcip, pp->pp_qh->element_ptr,
5417c478bd9Sstevel@tonic-gate 		    TD_PADDR(pp->pp_qh->td_tailp));
5427c478bd9Sstevel@tonic-gate 	}
5437c478bd9Sstevel@tonic-gate 
5447c478bd9Sstevel@tonic-gate 	(void) uhci_wait_for_sof(uhcip);
5457c478bd9Sstevel@tonic-gate 
5467c478bd9Sstevel@tonic-gate 	/*
5477c478bd9Sstevel@tonic-gate 	 * Save the data toggle and clear the pipe.
5487c478bd9Sstevel@tonic-gate 	 */
5497c478bd9Sstevel@tonic-gate 	switch (UHCI_XFER_TYPE(eptd)) {
5507c478bd9Sstevel@tonic-gate 	case USB_EP_ATTR_CONTROL:
5517c478bd9Sstevel@tonic-gate 	case USB_EP_ATTR_INTR:
5527c478bd9Sstevel@tonic-gate 		uhci_remove_tds_tws(uhcip, ph);
5537c478bd9Sstevel@tonic-gate 		break;
5547c478bd9Sstevel@tonic-gate 	case USB_EP_ATTR_BULK:
5557c478bd9Sstevel@tonic-gate 		SetQH32(uhcip, pp->pp_qh->element_ptr,
5567c478bd9Sstevel@tonic-gate 		    TD_PADDR(pp->pp_qh->td_tailp));
5577c478bd9Sstevel@tonic-gate 		uhci_remove_bulk_tds_tws(uhcip, pp, UHCI_IN_RESET);
5587c478bd9Sstevel@tonic-gate 		break;
5597c478bd9Sstevel@tonic-gate 	case USB_EP_ATTR_ISOCH:
5607c478bd9Sstevel@tonic-gate 		uhci_remove_isoc_tds_tws(uhcip, pp);
5617c478bd9Sstevel@tonic-gate 		break;
5627c478bd9Sstevel@tonic-gate 	default:
5637c478bd9Sstevel@tonic-gate 		USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
5647c478bd9Sstevel@tonic-gate 		    "uhci_hcdi_pipe_reset: Unknown xfer type");
5657c478bd9Sstevel@tonic-gate 		break;
5667c478bd9Sstevel@tonic-gate 	}
5677c478bd9Sstevel@tonic-gate 
5687c478bd9Sstevel@tonic-gate 	/*
5697c478bd9Sstevel@tonic-gate 	 * Do the callback for the original client
5707c478bd9Sstevel@tonic-gate 	 * periodic IN request.
5717c478bd9Sstevel@tonic-gate 	 */
5727c478bd9Sstevel@tonic-gate 	if (pp->pp_client_periodic_in_reqp) {
5737c478bd9Sstevel@tonic-gate 		uhci_hcdi_callback(uhcip, pp, ph, NULL, USB_CR_PIPE_RESET);
5747c478bd9Sstevel@tonic-gate 	}
5757c478bd9Sstevel@tonic-gate 
5767c478bd9Sstevel@tonic-gate 	/*
5777c478bd9Sstevel@tonic-gate 	 * Since the endpoint is stripped of Transfer Descriptors (TD),
5787c478bd9Sstevel@tonic-gate 	 * reset the state of the periodic pipe to IDLE.
5797c478bd9Sstevel@tonic-gate 	 */
5807c478bd9Sstevel@tonic-gate 	pp->pp_state = UHCI_PIPE_STATE_IDLE;
5817c478bd9Sstevel@tonic-gate 
5827c478bd9Sstevel@tonic-gate 	mutex_exit(&uhcip->uhci_int_mutex);
5837c478bd9Sstevel@tonic-gate 
5847c478bd9Sstevel@tonic-gate 	return (USB_SUCCESS);
5857c478bd9Sstevel@tonic-gate }
5867c478bd9Sstevel@tonic-gate 
587269552cdSguoqing zhu - Sun Microsystems - Beijing China /*
588269552cdSguoqing zhu - Sun Microsystems - Beijing China  * uhci_hcdi_pipe_reset_data_toggle:
589269552cdSguoqing zhu - Sun Microsystems - Beijing China  */
590269552cdSguoqing zhu - Sun Microsystems - Beijing China void
591269552cdSguoqing zhu - Sun Microsystems - Beijing China uhci_hcdi_pipe_reset_data_toggle(
592269552cdSguoqing zhu - Sun Microsystems - Beijing China 	usba_pipe_handle_data_t	*ph)
593269552cdSguoqing zhu - Sun Microsystems - Beijing China {
594269552cdSguoqing zhu - Sun Microsystems - Beijing China 	uhci_state_t		*uhcip = uhci_obtain_state(
595269552cdSguoqing zhu - Sun Microsystems - Beijing China 	    ph->p_usba_device->usb_root_hub_dip);
596269552cdSguoqing zhu - Sun Microsystems - Beijing China 	uhci_pipe_private_t	*pp = (uhci_pipe_private_t *)ph->p_hcd_private;
597269552cdSguoqing zhu - Sun Microsystems - Beijing China 
598269552cdSguoqing zhu - Sun Microsystems - Beijing China 	USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
599269552cdSguoqing zhu - Sun Microsystems - Beijing China 	    "uhci_hcdi_pipe_reset_data_toggle:");
600269552cdSguoqing zhu - Sun Microsystems - Beijing China 
601269552cdSguoqing zhu - Sun Microsystems - Beijing China 	mutex_enter(&uhcip->uhci_int_mutex);
602269552cdSguoqing zhu - Sun Microsystems - Beijing China 
603269552cdSguoqing zhu - Sun Microsystems - Beijing China 	mutex_enter(&ph->p_mutex);
604269552cdSguoqing zhu - Sun Microsystems - Beijing China 	pp->pp_data_toggle = 0;
605269552cdSguoqing zhu - Sun Microsystems - Beijing China 	usba_hcdi_set_data_toggle(ph->p_usba_device, ph->p_ep.bEndpointAddress,
606269552cdSguoqing zhu - Sun Microsystems - Beijing China 	    pp->pp_data_toggle);
607269552cdSguoqing zhu - Sun Microsystems - Beijing China 	mutex_exit(&ph->p_mutex);
608269552cdSguoqing zhu - Sun Microsystems - Beijing China 
609269552cdSguoqing zhu - Sun Microsystems - Beijing China 	mutex_exit(&uhcip->uhci_int_mutex);
610269552cdSguoqing zhu - Sun Microsystems - Beijing China 
611269552cdSguoqing zhu - Sun Microsystems - Beijing China }
6127c478bd9Sstevel@tonic-gate 
6137c478bd9Sstevel@tonic-gate /*
6147c478bd9Sstevel@tonic-gate  * uhci_hcdi_pipe_ctrl_xfer:
6157c478bd9Sstevel@tonic-gate  */
6167c478bd9Sstevel@tonic-gate int
6177c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_ctrl_xfer(
6187c478bd9Sstevel@tonic-gate 	usba_pipe_handle_data_t	*ph,
6197c478bd9Sstevel@tonic-gate 	usb_ctrl_req_t		*ctrl_reqp,
6207c478bd9Sstevel@tonic-gate 	usb_flags_t		flags)
6217c478bd9Sstevel@tonic-gate {
6227c478bd9Sstevel@tonic-gate 	uhci_state_t *uhcip = uhci_obtain_state(
623fffe0b30Sqz 	    ph->p_usba_device->usb_root_hub_dip);
6247c478bd9Sstevel@tonic-gate 	uhci_pipe_private_t *pp = (uhci_pipe_private_t *)ph->p_hcd_private;
625fffe0b30Sqz 	int error;
6267c478bd9Sstevel@tonic-gate 
6277c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
6287c478bd9Sstevel@tonic-gate 	    "uhci_hcdi_pipe_ctrl_xfer: req=0x%p, ph=0x%p, flags=0x%x",
629112116d8Sfb 	    (void *)ctrl_reqp, (void *)ph, flags);
6307c478bd9Sstevel@tonic-gate 
6317c478bd9Sstevel@tonic-gate 	mutex_enter(&uhcip->uhci_int_mutex);
632fffe0b30Sqz 	error = uhci_state_is_operational(uhcip);
633fffe0b30Sqz 
634fffe0b30Sqz 	if (error != USB_SUCCESS) {
635fffe0b30Sqz 		mutex_exit(&uhcip->uhci_int_mutex);
636fffe0b30Sqz 
637fffe0b30Sqz 		return (error);
638fffe0b30Sqz 	}
6397c478bd9Sstevel@tonic-gate 
6407c478bd9Sstevel@tonic-gate 	ASSERT(pp->pp_state == UHCI_PIPE_STATE_IDLE);
6417c478bd9Sstevel@tonic-gate 
6427c478bd9Sstevel@tonic-gate 	/*
6437c478bd9Sstevel@tonic-gate 	 * Check and handle root hub control request.
6447c478bd9Sstevel@tonic-gate 	 */
6457c478bd9Sstevel@tonic-gate 	if (ph->p_usba_device->usb_addr == ROOT_HUB_ADDR) {
6467c478bd9Sstevel@tonic-gate 		error = uhci_handle_root_hub_request(uhcip, ph, ctrl_reqp);
6477c478bd9Sstevel@tonic-gate 		mutex_exit(&uhcip->uhci_int_mutex);
6487c478bd9Sstevel@tonic-gate 
6497c478bd9Sstevel@tonic-gate 		return (error);
6507c478bd9Sstevel@tonic-gate 	}
6517c478bd9Sstevel@tonic-gate 
6527c478bd9Sstevel@tonic-gate 	/* Insert the td's on the endpoint */
6537c478bd9Sstevel@tonic-gate 	if ((error = uhci_insert_ctrl_td(uhcip, ph, ctrl_reqp, flags)) !=
6547c478bd9Sstevel@tonic-gate 	    USB_SUCCESS) {
6557c478bd9Sstevel@tonic-gate 		USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
6567c478bd9Sstevel@tonic-gate 		    "uhci_hcdi_pipe_ctrl_xfer: No resources");
6577c478bd9Sstevel@tonic-gate 	}
6587c478bd9Sstevel@tonic-gate 	mutex_exit(&uhcip->uhci_int_mutex);
6597c478bd9Sstevel@tonic-gate 
6607c478bd9Sstevel@tonic-gate 	return (error);
6617c478bd9Sstevel@tonic-gate }
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate 
6647c478bd9Sstevel@tonic-gate /*
6657c478bd9Sstevel@tonic-gate  * uhci_hcdi_pipe_bulk_xfer:
6667c478bd9Sstevel@tonic-gate  */
6677c478bd9Sstevel@tonic-gate int
6687c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_bulk_xfer(usba_pipe_handle_data_t *pipe_handle,
6697c478bd9Sstevel@tonic-gate     usb_bulk_req_t *bulk_reqp, usb_flags_t usb_flags)
6707c478bd9Sstevel@tonic-gate {
6717c478bd9Sstevel@tonic-gate 	int		error;
6727c478bd9Sstevel@tonic-gate 	uhci_state_t	*uhcip;
6737c478bd9Sstevel@tonic-gate 
6747c478bd9Sstevel@tonic-gate 	uhcip = uhci_obtain_state(pipe_handle->p_usba_device->usb_root_hub_dip);
6757c478bd9Sstevel@tonic-gate 
6767c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
6777c478bd9Sstevel@tonic-gate 	    "uhci_hcdi_pipe_bulk_xfer: Flags = 0x%x", usb_flags);
6787c478bd9Sstevel@tonic-gate 
6797c478bd9Sstevel@tonic-gate 	/* Check the size of bulk request */
6807c478bd9Sstevel@tonic-gate 	if (bulk_reqp->bulk_len > UHCI_BULK_MAX_XFER_SIZE) {
6817c478bd9Sstevel@tonic-gate 		USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
6827c478bd9Sstevel@tonic-gate 		    "uhci_hcdi_pipe_bulk_xfer: req size 0x%x is more than 0x%x",
6837c478bd9Sstevel@tonic-gate 		    bulk_reqp->bulk_len, UHCI_BULK_MAX_XFER_SIZE);
6847c478bd9Sstevel@tonic-gate 
6857c478bd9Sstevel@tonic-gate 		return (USB_FAILURE);
6867c478bd9Sstevel@tonic-gate 	}
6877c478bd9Sstevel@tonic-gate 
6887c478bd9Sstevel@tonic-gate 	mutex_enter(&uhcip->uhci_int_mutex);
6897c478bd9Sstevel@tonic-gate 
690fffe0b30Sqz 	error = uhci_state_is_operational(uhcip);
691fffe0b30Sqz 
692fffe0b30Sqz 	if (error != USB_SUCCESS) {
693fffe0b30Sqz 		mutex_exit(&uhcip->uhci_int_mutex);
694fffe0b30Sqz 
695fffe0b30Sqz 		return (error);
696fffe0b30Sqz 	}
6977c478bd9Sstevel@tonic-gate 	/* Add the TD into the Host Controller's bulk list */
6987c478bd9Sstevel@tonic-gate 	if ((error = uhci_insert_bulk_td(uhcip, pipe_handle, bulk_reqp,
6997c478bd9Sstevel@tonic-gate 	    usb_flags)) != USB_SUCCESS) {
7007c478bd9Sstevel@tonic-gate 		USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
7017c478bd9Sstevel@tonic-gate 		    "uhci_hcdi_pipe_bulk_xfer: uhci_insert_bulk_td failed");
7027c478bd9Sstevel@tonic-gate 	}
7037c478bd9Sstevel@tonic-gate 	mutex_exit(&uhcip->uhci_int_mutex);
7047c478bd9Sstevel@tonic-gate 
7057c478bd9Sstevel@tonic-gate 	return (error);
7067c478bd9Sstevel@tonic-gate }
7077c478bd9Sstevel@tonic-gate 
7087c478bd9Sstevel@tonic-gate 
7097c478bd9Sstevel@tonic-gate /*
7107c478bd9Sstevel@tonic-gate  * uhci_hcdi_bulk_transfer_size:
7117c478bd9Sstevel@tonic-gate  *	Return maximum bulk transfer size
7127c478bd9Sstevel@tonic-gate  */
7137c478bd9Sstevel@tonic-gate int
7147c478bd9Sstevel@tonic-gate uhci_hcdi_bulk_transfer_size(
7157c478bd9Sstevel@tonic-gate 	usba_device_t	*usba_device,
7167c478bd9Sstevel@tonic-gate 	size_t		*size)
7177c478bd9Sstevel@tonic-gate {
718fffe0b30Sqz 	uhci_state_t	*uhcip = uhci_obtain_state(
719fffe0b30Sqz 	    usba_device->usb_root_hub_dip);
720fffe0b30Sqz 	int		rval;
7217c478bd9Sstevel@tonic-gate 
7227c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
7237c478bd9Sstevel@tonic-gate 	    "uhci_hcdi_bulk_transfer_size:");
7247c478bd9Sstevel@tonic-gate 
725fffe0b30Sqz 	mutex_enter(&uhcip->uhci_int_mutex);
726fffe0b30Sqz 	rval = uhci_state_is_operational(uhcip);
727fffe0b30Sqz 
728fffe0b30Sqz 	if (rval != USB_SUCCESS) {
729fffe0b30Sqz 		mutex_exit(&uhcip->uhci_int_mutex);
730fffe0b30Sqz 
731fffe0b30Sqz 		return (rval);
732fffe0b30Sqz 	}
733fffe0b30Sqz 
7347c478bd9Sstevel@tonic-gate 	*size = uhci_bulk_transfer_size;
735fffe0b30Sqz 	mutex_exit(&uhcip->uhci_int_mutex);
7367c478bd9Sstevel@tonic-gate 
7377c478bd9Sstevel@tonic-gate 	return (USB_SUCCESS);
7387c478bd9Sstevel@tonic-gate }
7397c478bd9Sstevel@tonic-gate 
7407c478bd9Sstevel@tonic-gate 
7417c478bd9Sstevel@tonic-gate /*
7427c478bd9Sstevel@tonic-gate  * uhci_hcdi_pipe_intr_xfer:
7437c478bd9Sstevel@tonic-gate  */
7447c478bd9Sstevel@tonic-gate int
7457c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_intr_xfer(
7467c478bd9Sstevel@tonic-gate 	usba_pipe_handle_data_t	*ph,
7477c478bd9Sstevel@tonic-gate 	usb_intr_req_t		*req,
7487c478bd9Sstevel@tonic-gate 	usb_flags_t		flags)
7497c478bd9Sstevel@tonic-gate {
7507c478bd9Sstevel@tonic-gate 	uhci_state_t	*uhcip = uhci_obtain_state(
751fffe0b30Sqz 	    ph->p_usba_device->usb_root_hub_dip);
7527c478bd9Sstevel@tonic-gate 
7537c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
754112116d8Sfb 	    "uhci_hcdi_pipe_intr_xfer: req=0x%p, uf=0x%x", (void *)req, flags);
7557c478bd9Sstevel@tonic-gate 
7567c478bd9Sstevel@tonic-gate 	if (UHCI_XFER_DIR(&ph->p_ep) == USB_EP_DIR_IN) {
7577c478bd9Sstevel@tonic-gate 
7587c478bd9Sstevel@tonic-gate 		return (uhci_start_periodic_pipe_polling(uhcip, ph,
759fffe0b30Sqz 		    (usb_opaque_t)req, flags));
7607c478bd9Sstevel@tonic-gate 	} else {
7617c478bd9Sstevel@tonic-gate 
7627c478bd9Sstevel@tonic-gate 		return (uhci_send_intr_data(uhcip, ph, req, flags));
7637c478bd9Sstevel@tonic-gate 	}
7647c478bd9Sstevel@tonic-gate }
7657c478bd9Sstevel@tonic-gate 
7667c478bd9Sstevel@tonic-gate 
7677c478bd9Sstevel@tonic-gate /*
7687c478bd9Sstevel@tonic-gate  * uhci_send_intr_data():
7697c478bd9Sstevel@tonic-gate  *	send data to interrupt out pipe
7707c478bd9Sstevel@tonic-gate  */
7717c478bd9Sstevel@tonic-gate static int
7727c478bd9Sstevel@tonic-gate uhci_send_intr_data(
7737c478bd9Sstevel@tonic-gate 	uhci_state_t		*uhcip,
7747c478bd9Sstevel@tonic-gate 	usba_pipe_handle_data_t	*pipe_handle,
7757c478bd9Sstevel@tonic-gate 	usb_intr_req_t		*req,
7767c478bd9Sstevel@tonic-gate 	usb_flags_t		flags)
7777c478bd9Sstevel@tonic-gate {
778fffe0b30Sqz 	int	rval;
7797c478bd9Sstevel@tonic-gate 
7807c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_LISTS, uhcip->uhci_log_hdl,
7817c478bd9Sstevel@tonic-gate 	    "uhci_send_intr_data:");
7827c478bd9Sstevel@tonic-gate 
7837c478bd9Sstevel@tonic-gate 	mutex_enter(&uhcip->uhci_int_mutex);
7847c478bd9Sstevel@tonic-gate 
785fffe0b30Sqz 	rval = uhci_state_is_operational(uhcip);
786fffe0b30Sqz 
787fffe0b30Sqz 	if (rval != USB_SUCCESS) {
788fffe0b30Sqz 		mutex_exit(&uhcip->uhci_int_mutex);
789fffe0b30Sqz 
790fffe0b30Sqz 		return (rval);
791fffe0b30Sqz 	}
792fffe0b30Sqz 
7937c478bd9Sstevel@tonic-gate 	/* Add the TD into the Host Controller's interrupt list */
7947c478bd9Sstevel@tonic-gate 	if ((rval = uhci_insert_intr_td(uhcip, pipe_handle, req, flags)) !=
7957c478bd9Sstevel@tonic-gate 	    USB_SUCCESS) {
7967c478bd9Sstevel@tonic-gate 		USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
7977c478bd9Sstevel@tonic-gate 		    "uhci_send_intr_data: No resources");
7987c478bd9Sstevel@tonic-gate 	}
7997c478bd9Sstevel@tonic-gate 	mutex_exit(&uhcip->uhci_int_mutex);
8007c478bd9Sstevel@tonic-gate 
8017c478bd9Sstevel@tonic-gate 	return (rval);
8027c478bd9Sstevel@tonic-gate }
8037c478bd9Sstevel@tonic-gate 
8047c478bd9Sstevel@tonic-gate 
8057c478bd9Sstevel@tonic-gate /*
8067c478bd9Sstevel@tonic-gate  * uhci_hcdi_pipe_stop_intr_polling()
8077c478bd9Sstevel@tonic-gate  */
8087c478bd9Sstevel@tonic-gate int
8097c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_stop_intr_polling(
8107c478bd9Sstevel@tonic-gate 	usba_pipe_handle_data_t *pipe_handle,
8117c478bd9Sstevel@tonic-gate 	usb_flags_t		flags)
8127c478bd9Sstevel@tonic-gate {
8137c478bd9Sstevel@tonic-gate 	uhci_state_t *uhcip =
814fffe0b30Sqz 	    uhci_obtain_state(pipe_handle->p_usba_device->usb_root_hub_dip);
815fffe0b30Sqz 	int		rval;
8167c478bd9Sstevel@tonic-gate 
8177c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_LISTS, uhcip->uhci_log_hdl,
8187c478bd9Sstevel@tonic-gate 	    "uhci_hcdi_pipe_stop_intr_polling: ph = 0x%p fl = 0x%x",
8197c478bd9Sstevel@tonic-gate 	    (void *)pipe_handle, flags);
820fffe0b30Sqz 	mutex_enter(&uhcip->uhci_int_mutex);
8217c478bd9Sstevel@tonic-gate 
822fffe0b30Sqz 	rval = uhci_stop_periodic_pipe_polling(uhcip, pipe_handle, flags);
823fffe0b30Sqz 
824fffe0b30Sqz 	mutex_exit(&uhcip->uhci_int_mutex);
825fffe0b30Sqz 
826fffe0b30Sqz 	return (rval);
8277c478bd9Sstevel@tonic-gate }
8287c478bd9Sstevel@tonic-gate 
8297c478bd9Sstevel@tonic-gate 
8307c478bd9Sstevel@tonic-gate /*
8317c478bd9Sstevel@tonic-gate  * uhci_hcdi_get_current_frame_number
832fffe0b30Sqz  *	Get the current frame number.
833fffe0b30Sqz  *	Return whether the request is handled successfully.
8347c478bd9Sstevel@tonic-gate  */
835fffe0b30Sqz int
836fffe0b30Sqz uhci_hcdi_get_current_frame_number(
837fffe0b30Sqz 	usba_device_t		*usba_device,
838fffe0b30Sqz 	usb_frame_number_t	*frame_number)
8397c478bd9Sstevel@tonic-gate {
8407c478bd9Sstevel@tonic-gate 	uhci_state_t *uhcip = uhci_obtain_state(usba_device->usb_root_hub_dip);
841fffe0b30Sqz 	int		rval;
8427c478bd9Sstevel@tonic-gate 
8437c478bd9Sstevel@tonic-gate 	mutex_enter(&uhcip->uhci_int_mutex);
844fffe0b30Sqz 	rval = uhci_state_is_operational(uhcip);
845fffe0b30Sqz 
846fffe0b30Sqz 	if (rval != USB_SUCCESS) {
847fffe0b30Sqz 		mutex_exit(&uhcip->uhci_int_mutex);
848fffe0b30Sqz 
849fffe0b30Sqz 		return (rval);
850fffe0b30Sqz 	}
851fffe0b30Sqz 
852fffe0b30Sqz 	*frame_number = uhci_get_sw_frame_number(uhcip);
8537c478bd9Sstevel@tonic-gate 	mutex_exit(&uhcip->uhci_int_mutex);
8547c478bd9Sstevel@tonic-gate 
8557c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
856112116d8Sfb 	    "uhci_hcdi_get_current_frame_number: %llx",
857112116d8Sfb 	    (unsigned long long)(*frame_number));
8587c478bd9Sstevel@tonic-gate 
859fffe0b30Sqz 	return (rval);
8607c478bd9Sstevel@tonic-gate }
8617c478bd9Sstevel@tonic-gate 
8627c478bd9Sstevel@tonic-gate 
8637c478bd9Sstevel@tonic-gate /*
8647c478bd9Sstevel@tonic-gate  * uhci_hcdi_get_max_isoc_pkts
865fffe0b30Sqz  *	Get the maximum number of isoc packets per USB Isoch request.
866fffe0b30Sqz  *	Return whether the request is handled successfully.
8677c478bd9Sstevel@tonic-gate  */
868fffe0b30Sqz int
869fffe0b30Sqz uhci_hcdi_get_max_isoc_pkts(
870fffe0b30Sqz 	usba_device_t	*usba_device,
871fffe0b30Sqz 	uint_t		*max_isoc_pkts_per_request)
8727c478bd9Sstevel@tonic-gate {
8737c478bd9Sstevel@tonic-gate 	uhci_state_t *uhcip = uhci_obtain_state(usba_device->usb_root_hub_dip);
874fffe0b30Sqz 	int		rval;
875fffe0b30Sqz 
876fffe0b30Sqz 	mutex_enter(&uhcip->uhci_int_mutex);
877fffe0b30Sqz 	rval = uhci_state_is_operational(uhcip);
878fffe0b30Sqz 
879fffe0b30Sqz 	if (rval != USB_SUCCESS) {
880fffe0b30Sqz 		mutex_exit(&uhcip->uhci_int_mutex);
881fffe0b30Sqz 
882fffe0b30Sqz 		return (rval);
883fffe0b30Sqz 	}
884fffe0b30Sqz 
885fffe0b30Sqz 	*max_isoc_pkts_per_request = UHCI_MAX_ISOC_PKTS;
886fffe0b30Sqz 	mutex_exit(&uhcip->uhci_int_mutex);
8877c478bd9Sstevel@tonic-gate 
8887c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
8897c478bd9Sstevel@tonic-gate 	    "uhci_hcdi_get_max_isoc_pkts: 0x%x", UHCI_MAX_ISOC_PKTS);
8907c478bd9Sstevel@tonic-gate 
891fffe0b30Sqz 	return (rval);
8927c478bd9Sstevel@tonic-gate }
8937c478bd9Sstevel@tonic-gate 
8947c478bd9Sstevel@tonic-gate 
8957c478bd9Sstevel@tonic-gate /*
8967c478bd9Sstevel@tonic-gate  * uhci_hcdi_pipe_isoc_xfer:
8977c478bd9Sstevel@tonic-gate  */
8987c478bd9Sstevel@tonic-gate int
8997c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_isoc_xfer(
9007c478bd9Sstevel@tonic-gate 	usba_pipe_handle_data_t	*ph,
9017c478bd9Sstevel@tonic-gate 	usb_isoc_req_t		*isoc_reqp,
9027c478bd9Sstevel@tonic-gate 	usb_flags_t		flags)
9037c478bd9Sstevel@tonic-gate {
9047c478bd9Sstevel@tonic-gate 	uhci_state_t	*uhcip;
9057c478bd9Sstevel@tonic-gate 
9067c478bd9Sstevel@tonic-gate 	uhcip = uhci_obtain_state(ph->p_usba_device->usb_root_hub_dip);
9077c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
908112116d8Sfb 	    "uhci_hcdi_pipe_isoc_xfer: req=0x%p, uf=0x%x",
909112116d8Sfb 	    (void *)isoc_reqp, flags);
9107c478bd9Sstevel@tonic-gate 
9117c478bd9Sstevel@tonic-gate 	if (UHCI_XFER_DIR(&ph->p_ep) == USB_EP_DIR_IN) {
9127c478bd9Sstevel@tonic-gate 
9137c478bd9Sstevel@tonic-gate 		return (uhci_start_periodic_pipe_polling(uhcip, ph,
914fffe0b30Sqz 		    (usb_opaque_t)isoc_reqp, flags));
9157c478bd9Sstevel@tonic-gate 	} else {
9167c478bd9Sstevel@tonic-gate 
9177c478bd9Sstevel@tonic-gate 		return (uhci_pipe_send_isoc_data(uhcip, ph, isoc_reqp, flags));
9187c478bd9Sstevel@tonic-gate 	}
9197c478bd9Sstevel@tonic-gate }
9207c478bd9Sstevel@tonic-gate 
9217c478bd9Sstevel@tonic-gate 
9227c478bd9Sstevel@tonic-gate /*
9237c478bd9Sstevel@tonic-gate  * uhci_hcdi_pipe_stop_isoc_polling()
9247c478bd9Sstevel@tonic-gate  */
9257c478bd9Sstevel@tonic-gate int
9267c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_stop_isoc_polling(
9277c478bd9Sstevel@tonic-gate 	usba_pipe_handle_data_t	*ph,
9287c478bd9Sstevel@tonic-gate 	usb_flags_t		flags)
9297c478bd9Sstevel@tonic-gate {
9307c478bd9Sstevel@tonic-gate 	uhci_state_t *uhcip =
931fffe0b30Sqz 	    uhci_obtain_state(ph->p_usba_device->usb_root_hub_dip);
932fffe0b30Sqz 	int		rval;
9337c478bd9Sstevel@tonic-gate 
9347c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_LISTS, uhcip->uhci_log_hdl,
9357c478bd9Sstevel@tonic-gate 	    "uhci_hcdi_pipe_stop_isoc_polling: ph = 0x%p fl = 0x%x",
9367c478bd9Sstevel@tonic-gate 	    (void *)ph, flags);
9377c478bd9Sstevel@tonic-gate 
938fffe0b30Sqz 	mutex_enter(&uhcip->uhci_int_mutex);
939fffe0b30Sqz 	rval = uhci_state_is_operational(uhcip);
940fffe0b30Sqz 
941fffe0b30Sqz 	if (rval != USB_SUCCESS) {
942fffe0b30Sqz 		mutex_exit(&uhcip->uhci_int_mutex);
943fffe0b30Sqz 
944fffe0b30Sqz 		return (rval);
945fffe0b30Sqz 	}
946fffe0b30Sqz 
947fffe0b30Sqz 	rval = uhci_stop_periodic_pipe_polling(uhcip, ph, flags);
948fffe0b30Sqz 
949fffe0b30Sqz 	mutex_exit(&uhcip->uhci_int_mutex);
950fffe0b30Sqz 
951fffe0b30Sqz 	return (rval);
9527c478bd9Sstevel@tonic-gate }
9537c478bd9Sstevel@tonic-gate 
9547c478bd9Sstevel@tonic-gate 
9557c478bd9Sstevel@tonic-gate /*
9567c478bd9Sstevel@tonic-gate  * uhci_start_periodic_pipe_polling:
9577c478bd9Sstevel@tonic-gate  */
9587c478bd9Sstevel@tonic-gate static int
9597c478bd9Sstevel@tonic-gate uhci_start_periodic_pipe_polling(
9607c478bd9Sstevel@tonic-gate 	uhci_state_t		*uhcip,
9617c478bd9Sstevel@tonic-gate 	usba_pipe_handle_data_t	*ph,
9627c478bd9Sstevel@tonic-gate 	usb_opaque_t		in_reqp,
9637c478bd9Sstevel@tonic-gate 	usb_flags_t		flags)
9647c478bd9Sstevel@tonic-gate {
9657c478bd9Sstevel@tonic-gate 	int			n, num_tds;
966fffe0b30Sqz 	int			error;
9677c478bd9Sstevel@tonic-gate 	usb_intr_req_t		*intr_reqp = (usb_intr_req_t *)in_reqp;
9687c478bd9Sstevel@tonic-gate 	usb_ep_descr_t		*eptd = &ph->p_ep;
9697c478bd9Sstevel@tonic-gate 	uhci_pipe_private_t	*pp = (uhci_pipe_private_t *)ph->p_hcd_private;
9707c478bd9Sstevel@tonic-gate 
9717c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
9727c478bd9Sstevel@tonic-gate 	    "uhci_start_periodic_pipe_polling: flags: 0x%x, ep%d",
9737c478bd9Sstevel@tonic-gate 	    flags, eptd->bEndpointAddress);
9747c478bd9Sstevel@tonic-gate 
9757c478bd9Sstevel@tonic-gate 	mutex_enter(&uhcip->uhci_int_mutex);
9767c478bd9Sstevel@tonic-gate 
977fffe0b30Sqz 	error = uhci_state_is_operational(uhcip);
978fffe0b30Sqz 
979fffe0b30Sqz 	if (error != USB_SUCCESS) {
980fffe0b30Sqz 		mutex_exit(&uhcip->uhci_int_mutex);
981fffe0b30Sqz 
982fffe0b30Sqz 		return (error);
983fffe0b30Sqz 	}
984fffe0b30Sqz 
9857c478bd9Sstevel@tonic-gate 	if (ph->p_usba_device->usb_addr == ROOT_HUB_ADDR) {
9867c478bd9Sstevel@tonic-gate 		uint_t	pipe_state = uhcip->uhci_root_hub.rh_pipe_state;
9877c478bd9Sstevel@tonic-gate 
9887c478bd9Sstevel@tonic-gate 		ASSERT(pipe_state == UHCI_PIPE_STATE_IDLE);
9897c478bd9Sstevel@tonic-gate 		ASSERT(UHCI_XFER_DIR(eptd) == USB_EP_DIR_IN);
9907c478bd9Sstevel@tonic-gate 
9917c478bd9Sstevel@tonic-gate 		/* ONE_XFER not supported */
9927c478bd9Sstevel@tonic-gate 		ASSERT((intr_reqp->intr_attributes &
9937c478bd9Sstevel@tonic-gate 		    USB_ATTRS_ONE_XFER) == 0);
9947c478bd9Sstevel@tonic-gate 		ASSERT(uhcip->uhci_root_hub.rh_client_intr_req == NULL);
9957c478bd9Sstevel@tonic-gate 		uhcip->uhci_root_hub.rh_client_intr_req = intr_reqp;
9967c478bd9Sstevel@tonic-gate 
9977c478bd9Sstevel@tonic-gate 		if ((error = uhci_root_hub_allocate_intr_pipe_resource(
9987c478bd9Sstevel@tonic-gate 		    uhcip, flags)) != USB_SUCCESS) {
9997c478bd9Sstevel@tonic-gate 			/* reset the client interrupt request pointer */
10007c478bd9Sstevel@tonic-gate 			uhcip->uhci_root_hub.rh_client_intr_req = NULL;
10017c478bd9Sstevel@tonic-gate 
10027c478bd9Sstevel@tonic-gate 			mutex_exit(&uhcip->uhci_int_mutex);
10037c478bd9Sstevel@tonic-gate 
10047c478bd9Sstevel@tonic-gate 			return (error);
10057c478bd9Sstevel@tonic-gate 		}
10067c478bd9Sstevel@tonic-gate 
10077c478bd9Sstevel@tonic-gate 		uhcip->uhci_root_hub.rh_pipe_state = USB_PIPE_STATE_ACTIVE;
10087c478bd9Sstevel@tonic-gate 
10097c478bd9Sstevel@tonic-gate 		USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
10107c478bd9Sstevel@tonic-gate 		    "uhci_start_periodic_pipe_polling: "
10117c478bd9Sstevel@tonic-gate 		    "Start intr polling for root hub successful");
10127c478bd9Sstevel@tonic-gate 
10137c478bd9Sstevel@tonic-gate 		/* check if we need to send the reset data up? */
10147c478bd9Sstevel@tonic-gate 		if (uhcip->uhci_root_hub.rh_status) {
10157c478bd9Sstevel@tonic-gate 			uhci_root_hub_reset_occurred(uhcip,
10167c478bd9Sstevel@tonic-gate 			    uhcip->uhci_root_hub.rh_status - 1);
10177c478bd9Sstevel@tonic-gate 
10187c478bd9Sstevel@tonic-gate 			uhcip->uhci_root_hub.rh_status = 0;
10197c478bd9Sstevel@tonic-gate 		}
10207c478bd9Sstevel@tonic-gate 		mutex_exit(&uhcip->uhci_int_mutex);
10217c478bd9Sstevel@tonic-gate 
10227c478bd9Sstevel@tonic-gate 		return (error);
10237c478bd9Sstevel@tonic-gate 	}
10247c478bd9Sstevel@tonic-gate 
10257c478bd9Sstevel@tonic-gate 	/* save the original client's periodic IN request */
10267c478bd9Sstevel@tonic-gate 	pp->pp_client_periodic_in_reqp = in_reqp;
10277c478bd9Sstevel@tonic-gate 
10287c478bd9Sstevel@tonic-gate 	ASSERT(pp->pp_state != UHCI_PIPE_STATE_ACTIVE);
10297c478bd9Sstevel@tonic-gate 	/*
10307c478bd9Sstevel@tonic-gate 	 *
10317c478bd9Sstevel@tonic-gate 	 * This pipe is uninitialized. If it is an isoc
10327c478bd9Sstevel@tonic-gate 	 * receive request, insert four times the same
10337c478bd9Sstevel@tonic-gate 	 * request so that we do not lose any frames.
10347c478bd9Sstevel@tonic-gate 	 */
10357c478bd9Sstevel@tonic-gate 	if (UHCI_XFER_TYPE(eptd) == USB_EP_ATTR_ISOCH) {
10367c478bd9Sstevel@tonic-gate 		for (n = 0; n < 5; n++) {
10377c478bd9Sstevel@tonic-gate 			if ((error = uhci_start_isoc_receive_polling(
10387c478bd9Sstevel@tonic-gate 			    uhcip, ph, NULL, flags)) != USB_SUCCESS) {
10397c478bd9Sstevel@tonic-gate 
10407c478bd9Sstevel@tonic-gate 				USB_DPRINTF_L2(PRINT_MASK_INTR,
10417c478bd9Sstevel@tonic-gate 				    uhcip->uhci_log_hdl,
10427c478bd9Sstevel@tonic-gate 				    "uhci_start_periodic_pipe_polling: "
10437c478bd9Sstevel@tonic-gate 				    "Start isoc polling failed %d", n);
10447c478bd9Sstevel@tonic-gate 
10457c478bd9Sstevel@tonic-gate 				pp->pp_client_periodic_in_reqp = NULL;
10467c478bd9Sstevel@tonic-gate 				mutex_exit(&uhcip->uhci_int_mutex);
10477c478bd9Sstevel@tonic-gate 
10487c478bd9Sstevel@tonic-gate 				return (error);
10497c478bd9Sstevel@tonic-gate 			}
10507c478bd9Sstevel@tonic-gate 		}
10517c478bd9Sstevel@tonic-gate 	}
10527c478bd9Sstevel@tonic-gate 
10537c478bd9Sstevel@tonic-gate 	if (UHCI_XFER_TYPE(eptd) == USB_EP_ATTR_INTR) {
10547c478bd9Sstevel@tonic-gate 		if ((pp->pp_node < POLLING_FREQ_7MS) &&
10557c478bd9Sstevel@tonic-gate 		    (!(intr_reqp->intr_attributes & USB_ATTRS_ONE_XFER))) {
10567c478bd9Sstevel@tonic-gate 			num_tds = 5;
10577c478bd9Sstevel@tonic-gate 		} else {
10587c478bd9Sstevel@tonic-gate 			num_tds = 1;
10597c478bd9Sstevel@tonic-gate 		}
10607c478bd9Sstevel@tonic-gate 
10617c478bd9Sstevel@tonic-gate 		/*
10627c478bd9Sstevel@tonic-gate 		 * This pipe is uninitialized.
10637c478bd9Sstevel@tonic-gate 		 * Insert a TD on the interrupt ED.
10647c478bd9Sstevel@tonic-gate 		 */
10657c478bd9Sstevel@tonic-gate 		for (n = 0; n < num_tds; n++) {
10667c478bd9Sstevel@tonic-gate 			if ((error = uhci_insert_intr_td(uhcip, ph, NULL,
10677c478bd9Sstevel@tonic-gate 			    flags)) != USB_SUCCESS) {
10687c478bd9Sstevel@tonic-gate 				USB_DPRINTF_L2(PRINT_MASK_INTR,
10697c478bd9Sstevel@tonic-gate 				    uhcip->uhci_log_hdl,
10707c478bd9Sstevel@tonic-gate 				    "uhci_start_periodic_pipe_polling: "
10717c478bd9Sstevel@tonic-gate 				    "Start polling failed");
10727c478bd9Sstevel@tonic-gate 
10737c478bd9Sstevel@tonic-gate 				pp->pp_client_periodic_in_reqp = NULL;
10747c478bd9Sstevel@tonic-gate 				mutex_exit(&uhcip->uhci_int_mutex);
10757c478bd9Sstevel@tonic-gate 
10767c478bd9Sstevel@tonic-gate 				return (error);
10777c478bd9Sstevel@tonic-gate 			}
10787c478bd9Sstevel@tonic-gate 		}
10797c478bd9Sstevel@tonic-gate 	}
10807c478bd9Sstevel@tonic-gate 
10817c478bd9Sstevel@tonic-gate 	pp->pp_state = UHCI_PIPE_STATE_ACTIVE;
10827c478bd9Sstevel@tonic-gate 
10837c478bd9Sstevel@tonic-gate 	mutex_exit(&uhcip->uhci_int_mutex);
10847c478bd9Sstevel@tonic-gate 
10857c478bd9Sstevel@tonic-gate 	return (error);
10867c478bd9Sstevel@tonic-gate }
10877c478bd9Sstevel@tonic-gate 
10887c478bd9Sstevel@tonic-gate 
10897c478bd9Sstevel@tonic-gate /*
10907c478bd9Sstevel@tonic-gate  * uhci_hcdi_periodic_pipe_stop_polling:
10917c478bd9Sstevel@tonic-gate  */
10927c478bd9Sstevel@tonic-gate static int
10937c478bd9Sstevel@tonic-gate uhci_stop_periodic_pipe_polling(uhci_state_t *uhcip,
10947c478bd9Sstevel@tonic-gate 	usba_pipe_handle_data_t  *ph, usb_flags_t flags)
10957c478bd9Sstevel@tonic-gate {
10967c478bd9Sstevel@tonic-gate 	uhci_pipe_private_t	*pp = (uhci_pipe_private_t *)ph->p_hcd_private;
10977c478bd9Sstevel@tonic-gate 	usb_ep_descr_t		*eptd = &ph->p_ep;
10987c478bd9Sstevel@tonic-gate 
10997c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
11007c478bd9Sstevel@tonic-gate 	    "uhci_stop_periodic_pipe_polling: flags = 0x%x", flags);
11017c478bd9Sstevel@tonic-gate 
1102fffe0b30Sqz 	ASSERT(mutex_owned(&uhcip->uhci_int_mutex));
11037c478bd9Sstevel@tonic-gate 	if (ph->p_usba_device->usb_addr == ROOT_HUB_ADDR) {
11047c478bd9Sstevel@tonic-gate 		ASSERT(UHCI_XFER_DIR(eptd) == USB_EP_DIR_IN);
11057c478bd9Sstevel@tonic-gate 
11067c478bd9Sstevel@tonic-gate 		if (uhcip->uhci_root_hub.rh_pipe_state ==
11077c478bd9Sstevel@tonic-gate 		    UHCI_PIPE_STATE_ACTIVE) {
11087c478bd9Sstevel@tonic-gate 			uhcip->uhci_root_hub.rh_pipe_state =
1109fffe0b30Sqz 			    UHCI_PIPE_STATE_IDLE;
11107c478bd9Sstevel@tonic-gate 
11117c478bd9Sstevel@tonic-gate 			/* Do interrupt pipe cleanup */
11127c478bd9Sstevel@tonic-gate 			uhci_root_hub_intr_pipe_cleanup(uhcip,
1113fffe0b30Sqz 			    USB_CR_STOPPED_POLLING);
11147c478bd9Sstevel@tonic-gate 
11157c478bd9Sstevel@tonic-gate 			USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
11167c478bd9Sstevel@tonic-gate 			    "uhci_stop_periodic_pipe_polling: Stop intr "
11177c478bd9Sstevel@tonic-gate 			    "polling for root hub successful");
11187c478bd9Sstevel@tonic-gate 
11197c478bd9Sstevel@tonic-gate 		} else {
11207c478bd9Sstevel@tonic-gate 			USB_DPRINTF_L2(PRINT_MASK_INTR, uhcip->uhci_log_hdl,
11217c478bd9Sstevel@tonic-gate 			    "uhci_stop_periodic_pipe_polling: "
11227c478bd9Sstevel@tonic-gate 			    "Intr polling for root hub is already stopped");
11237c478bd9Sstevel@tonic-gate 		}
11247c478bd9Sstevel@tonic-gate 
11257c478bd9Sstevel@tonic-gate 		return (USB_SUCCESS);
11267c478bd9Sstevel@tonic-gate 	}
11277c478bd9Sstevel@tonic-gate 
11287c478bd9Sstevel@tonic-gate 	if (pp->pp_state != UHCI_PIPE_STATE_ACTIVE) {
11297c478bd9Sstevel@tonic-gate 		USB_DPRINTF_L2(PRINT_MASK_INTR, uhcip->uhci_log_hdl,
11307c478bd9Sstevel@tonic-gate 		    "uhci_stop_periodic_pipe_polling: Polling already stopped");
11317c478bd9Sstevel@tonic-gate 
11327c478bd9Sstevel@tonic-gate 		return (USB_SUCCESS);
11337c478bd9Sstevel@tonic-gate 	}
11347c478bd9Sstevel@tonic-gate 
11357c478bd9Sstevel@tonic-gate 	/*
11367c478bd9Sstevel@tonic-gate 	 * Set the terminate bits in all the tds in the queue and
11377c478bd9Sstevel@tonic-gate 	 * in the element_ptr.
11387c478bd9Sstevel@tonic-gate 	 * Do not deallocate the bandwidth or tear down the DMA
11397c478bd9Sstevel@tonic-gate 	 */
11407c478bd9Sstevel@tonic-gate 	uhci_modify_td_active_bits(uhcip, pp);
11417c478bd9Sstevel@tonic-gate 	(void) uhci_wait_for_sof(uhcip);
11427c478bd9Sstevel@tonic-gate 
11437c478bd9Sstevel@tonic-gate 	if (UHCI_XFER_TYPE(eptd) == USB_EP_ATTR_ISOCH) {
11447c478bd9Sstevel@tonic-gate 		uhci_remove_isoc_tds_tws(uhcip, pp);
11457c478bd9Sstevel@tonic-gate 		pp->pp_state = UHCI_PIPE_STATE_IDLE;
11467c478bd9Sstevel@tonic-gate 	} else {
11477c478bd9Sstevel@tonic-gate 		UHCI_SET_TERMINATE_BIT(pp->pp_qh->element_ptr);
11487c478bd9Sstevel@tonic-gate 		uhci_update_intr_td_data_toggle(uhcip, pp);
11497c478bd9Sstevel@tonic-gate 		SetQH32(uhcip, pp->pp_qh->element_ptr,
11507c478bd9Sstevel@tonic-gate 		    TD_PADDR(pp->pp_qh->td_tailp));
11517c478bd9Sstevel@tonic-gate 		uhci_remove_tds_tws(uhcip, ph);
11527c478bd9Sstevel@tonic-gate 	}
11537c478bd9Sstevel@tonic-gate 
11547c478bd9Sstevel@tonic-gate 	pp->pp_state = UHCI_PIPE_STATE_IDLE;
11557c478bd9Sstevel@tonic-gate 
11567c478bd9Sstevel@tonic-gate 	if (pp->pp_client_periodic_in_reqp) {
11577c478bd9Sstevel@tonic-gate 		uhci_hcdi_callback(uhcip, pp, ph, NULL, USB_CR_STOPPED_POLLING);
11587c478bd9Sstevel@tonic-gate 	}
11597c478bd9Sstevel@tonic-gate 
11607c478bd9Sstevel@tonic-gate 	return (USB_SUCCESS);
11617c478bd9Sstevel@tonic-gate }
11627c478bd9Sstevel@tonic-gate 
11637c478bd9Sstevel@tonic-gate 
11647c478bd9Sstevel@tonic-gate /*
11657c478bd9Sstevel@tonic-gate  * uhci_hcdi_pipe_send_isoc_data:
11667c478bd9Sstevel@tonic-gate  *	Handles the isoc write request.
11677c478bd9Sstevel@tonic-gate  */
11687c478bd9Sstevel@tonic-gate static int
11697c478bd9Sstevel@tonic-gate uhci_pipe_send_isoc_data(
11707c478bd9Sstevel@tonic-gate 	uhci_state_t		*uhcip,
11717c478bd9Sstevel@tonic-gate 	usba_pipe_handle_data_t	*ph,
11727c478bd9Sstevel@tonic-gate 	usb_isoc_req_t		*isoc_req,
11737c478bd9Sstevel@tonic-gate 	usb_flags_t		usb_flags)
11747c478bd9Sstevel@tonic-gate {
11757c478bd9Sstevel@tonic-gate 	int			error;
11767c478bd9Sstevel@tonic-gate 	size_t			max_isoc_xfer_sz, length;
11777c478bd9Sstevel@tonic-gate 
11787c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
11797c478bd9Sstevel@tonic-gate 	    "uhci_pipe_send_isoc_data: isoc_req = %p flags = %x",
1180112116d8Sfb 	    (void *)isoc_req, usb_flags);
11817c478bd9Sstevel@tonic-gate 
11827c478bd9Sstevel@tonic-gate 	ASSERT(isoc_req->isoc_pkts_count < UHCI_MAX_ISOC_PKTS);
11837c478bd9Sstevel@tonic-gate 
11847c478bd9Sstevel@tonic-gate 	/* Calculate the maximum isochronous transfer size */
11857c478bd9Sstevel@tonic-gate 	max_isoc_xfer_sz = UHCI_MAX_ISOC_PKTS * ph->p_ep.wMaxPacketSize;
11867c478bd9Sstevel@tonic-gate 
11877c478bd9Sstevel@tonic-gate 	/* Check the size of isochronous request */
11887c478bd9Sstevel@tonic-gate 	ASSERT(isoc_req->isoc_data != NULL);
118922eb7cb5Sgd 	length = MBLKL(isoc_req->isoc_data);
11907c478bd9Sstevel@tonic-gate 
11917c478bd9Sstevel@tonic-gate 	if (length > max_isoc_xfer_sz) {
11927c478bd9Sstevel@tonic-gate 		USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
11937c478bd9Sstevel@tonic-gate 		    "uhci_pipe_send_isoc_data: Maximum isoc request size %lx "
11947c478bd9Sstevel@tonic-gate 		    "Given isoc request size %lx", max_isoc_xfer_sz, length);
11957c478bd9Sstevel@tonic-gate 
11967c478bd9Sstevel@tonic-gate 		return (USB_INVALID_REQUEST);
11977c478bd9Sstevel@tonic-gate 	}
11987c478bd9Sstevel@tonic-gate 
11997c478bd9Sstevel@tonic-gate 
12007c478bd9Sstevel@tonic-gate 	/*
12017c478bd9Sstevel@tonic-gate 	 * Check whether we can insert these tds?
12027c478bd9Sstevel@tonic-gate 	 * At any point of time, we can insert maximum of 1024 isoc td's,
12037c478bd9Sstevel@tonic-gate 	 * size of frame list table.
12047c478bd9Sstevel@tonic-gate 	 */
12057c478bd9Sstevel@tonic-gate 	if (isoc_req->isoc_pkts_count > UHCI_MAX_ISOC_PKTS) {
12067c478bd9Sstevel@tonic-gate 
12077c478bd9Sstevel@tonic-gate 		USB_DPRINTF_L2(PRINT_MASK_ISOC, uhcip->uhci_log_hdl,
12087c478bd9Sstevel@tonic-gate 		    "uhci_pipe_send_isoc_data: request too big");
12097c478bd9Sstevel@tonic-gate 
12107c478bd9Sstevel@tonic-gate 		return (USB_INVALID_REQUEST);
12117c478bd9Sstevel@tonic-gate 	}
12127c478bd9Sstevel@tonic-gate 
12137c478bd9Sstevel@tonic-gate 	/* Add the TD into the Host Controller's isoc list */
12147c478bd9Sstevel@tonic-gate 	mutex_enter(&uhcip->uhci_int_mutex);
12157c478bd9Sstevel@tonic-gate 
1216fffe0b30Sqz 	error = uhci_state_is_operational(uhcip);
1217fffe0b30Sqz 
1218fffe0b30Sqz 	if (error != USB_SUCCESS) {
1219fffe0b30Sqz 		mutex_exit(&uhcip->uhci_int_mutex);
1220fffe0b30Sqz 
1221fffe0b30Sqz 		return (error);
1222fffe0b30Sqz 	}
1223fffe0b30Sqz 
12247c478bd9Sstevel@tonic-gate 	if ((error = uhci_insert_isoc_td(uhcip, ph, isoc_req,
12257c478bd9Sstevel@tonic-gate 	    length, usb_flags)) != USB_SUCCESS) {
12267c478bd9Sstevel@tonic-gate 
12277c478bd9Sstevel@tonic-gate 		USB_DPRINTF_L2(PRINT_MASK_ISOC, uhcip->uhci_log_hdl,
12287c478bd9Sstevel@tonic-gate 		    "uhci_pipe_send_isoc_data: Unable to insert the isoc_req,"
12297c478bd9Sstevel@tonic-gate 		    "Error = %d", error);
12307c478bd9Sstevel@tonic-gate 	}
12317c478bd9Sstevel@tonic-gate 	mutex_exit(&uhcip->uhci_int_mutex);
12327c478bd9Sstevel@tonic-gate 
12337c478bd9Sstevel@tonic-gate 	return (error);
12347c478bd9Sstevel@tonic-gate }
12357c478bd9Sstevel@tonic-gate 
12367c478bd9Sstevel@tonic-gate 
12377c478bd9Sstevel@tonic-gate /*
12387c478bd9Sstevel@tonic-gate  * uhci_update_intr_td_data_toggle
12397c478bd9Sstevel@tonic-gate  *	Update the data toggle and save in the usba_device structure
12407c478bd9Sstevel@tonic-gate  */
12417c478bd9Sstevel@tonic-gate static void
12427c478bd9Sstevel@tonic-gate uhci_update_intr_td_data_toggle(uhci_state_t *uhcip, uhci_pipe_private_t *pp)
12437c478bd9Sstevel@tonic-gate {
12447c478bd9Sstevel@tonic-gate 	uint32_t	paddr_tail, element_ptr;
12457c478bd9Sstevel@tonic-gate 	uhci_td_t	*next_td;
12467c478bd9Sstevel@tonic-gate 
12477c478bd9Sstevel@tonic-gate 	/* Find the next td that would have been executed */
12487c478bd9Sstevel@tonic-gate 	element_ptr = GetQH32(uhcip, pp->pp_qh->element_ptr) &
1249fffe0b30Sqz 	    QH_ELEMENT_PTR_MASK;
12507c478bd9Sstevel@tonic-gate 	next_td = TD_VADDR(element_ptr);
12517c478bd9Sstevel@tonic-gate 	paddr_tail = TD_PADDR(pp->pp_qh->td_tailp);
12527c478bd9Sstevel@tonic-gate 
12537c478bd9Sstevel@tonic-gate 	/*
12547c478bd9Sstevel@tonic-gate 	 * If element_ptr points to the dummy td, then the data toggle in
12557c478bd9Sstevel@tonic-gate 	 * pp_data_toggle is correct. Otherwise update the data toggle in
12567c478bd9Sstevel@tonic-gate 	 * the pipe private
12577c478bd9Sstevel@tonic-gate 	 */
12587c478bd9Sstevel@tonic-gate 	if (element_ptr != paddr_tail) {
12597c478bd9Sstevel@tonic-gate 		pp->pp_data_toggle = GetTD_dtogg(uhcip, next_td);
12607c478bd9Sstevel@tonic-gate 	}
12617c478bd9Sstevel@tonic-gate 
12627c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl,
12637c478bd9Sstevel@tonic-gate 	    "uhci_update_intr_td_data_toggle: "
12647c478bd9Sstevel@tonic-gate 	    "pp %p toggle %x element ptr %x ptail %x",
1265112116d8Sfb 	    (void *)pp, pp->pp_data_toggle, element_ptr, paddr_tail);
12667c478bd9Sstevel@tonic-gate 
12677c478bd9Sstevel@tonic-gate 	uhci_save_data_toggle(pp);
12687c478bd9Sstevel@tonic-gate }
1269