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
5b3001defSlg * Common Development and Distribution License (the "License").
6b3001defSlg * 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 */
21dfbb3a42SRaymond Chen
227c478bd9Sstevel@tonic-gate /*
23dfbb3a42SRaymond Chen * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
2448bbca81SDaniel Hoffman * Copyright (c) 2016 by Delphix. All rights reserved.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate * EHCI Host Controller Driver (EHCI)
297c478bd9Sstevel@tonic-gate *
307c478bd9Sstevel@tonic-gate * The EHCI driver is a software driver which interfaces to the Universal
317c478bd9Sstevel@tonic-gate * Serial Bus layer (USBA) and the Host Controller (HC). The interface to
327c478bd9Sstevel@tonic-gate * the Host Controller is defined by the EHCI Host Controller Interface.
337c478bd9Sstevel@tonic-gate *
347c478bd9Sstevel@tonic-gate * This module contains the EHCI driver isochronous code, which handles all
357c478bd9Sstevel@tonic-gate * Checking of status of USB transfers, error recovery and callbacks.
367c478bd9Sstevel@tonic-gate */
377c478bd9Sstevel@tonic-gate #include <sys/usb/hcd/ehci/ehcid.h>
387c478bd9Sstevel@tonic-gate #include <sys/usb/hcd/ehci/ehci_xfer.h>
397c478bd9Sstevel@tonic-gate #include <sys/usb/hcd/ehci/ehci_util.h>
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate /* Adjustable variables for the size of isoc pools */
427c478bd9Sstevel@tonic-gate int ehci_itd_pool_size = EHCI_ITD_POOL_SIZE;
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate * pool functions
467c478bd9Sstevel@tonic-gate */
477c478bd9Sstevel@tonic-gate int ehci_allocate_isoc_pools(
487c478bd9Sstevel@tonic-gate ehci_state_t *ehcip);
497c478bd9Sstevel@tonic-gate int ehci_get_itd_pool_size();
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate * Isochronous Transfer Wrapper Functions
537c478bd9Sstevel@tonic-gate */
547c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *ehci_allocate_itw_resources(
550a05e705Slc ehci_state_t *ehcip,
567c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp,
577c478bd9Sstevel@tonic-gate size_t itw_length,
587c478bd9Sstevel@tonic-gate usb_flags_t usb_flags,
590a05e705Slc size_t pkt_count);
607c478bd9Sstevel@tonic-gate static ehci_isoc_xwrapper_t *ehci_allocate_itw(
617c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
627c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp,
637c478bd9Sstevel@tonic-gate size_t length,
647c478bd9Sstevel@tonic-gate usb_flags_t usb_flags);
657c478bd9Sstevel@tonic-gate void ehci_deallocate_itw(
667c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
677c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp,
687c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw);
697c478bd9Sstevel@tonic-gate static void ehci_free_itw_dma(
707c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
717c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp,
727c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw);
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate /*
757c478bd9Sstevel@tonic-gate * transfer descriptor functions
767c478bd9Sstevel@tonic-gate */
777c478bd9Sstevel@tonic-gate static ehci_itd_t *ehci_allocate_itd(
787c478bd9Sstevel@tonic-gate ehci_state_t *ehcip);
797c478bd9Sstevel@tonic-gate void ehci_deallocate_itd(
807c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
817c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw,
827c478bd9Sstevel@tonic-gate ehci_itd_t *old_itd);
837c478bd9Sstevel@tonic-gate uint_t ehci_calc_num_itds(
847c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw,
850a05e705Slc size_t pkt_count);
867c478bd9Sstevel@tonic-gate int ehci_allocate_itds_for_itw(
877c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
887c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw,
897c478bd9Sstevel@tonic-gate uint_t itd_count);
907c478bd9Sstevel@tonic-gate static void ehci_deallocate_itds_for_itw(
917c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
927c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw);
937c478bd9Sstevel@tonic-gate void ehci_insert_itd_on_itw(
947c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
957c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw,
967c478bd9Sstevel@tonic-gate ehci_itd_t *itd);
977c478bd9Sstevel@tonic-gate void ehci_insert_itd_into_active_list(
987c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
997c478bd9Sstevel@tonic-gate ehci_itd_t *itd);
1007c478bd9Sstevel@tonic-gate void ehci_remove_itd_from_active_list(
1017c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
1027c478bd9Sstevel@tonic-gate ehci_itd_t *itd);
1037c478bd9Sstevel@tonic-gate ehci_itd_t *ehci_create_done_itd_list(
1047c478bd9Sstevel@tonic-gate ehci_state_t *ehcip);
1057c478bd9Sstevel@tonic-gate int ehci_insert_isoc_to_pfl(
1067c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
1077c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp,
1087c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw);
1097c478bd9Sstevel@tonic-gate void ehci_remove_isoc_from_pfl(
1107c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
1117c478bd9Sstevel@tonic-gate ehci_itd_t *curr_itd);
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate /*
1157c478bd9Sstevel@tonic-gate * Isochronous in resource functions
1167c478bd9Sstevel@tonic-gate */
1177c478bd9Sstevel@tonic-gate int ehci_allocate_isoc_in_resource(
1187c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
1197c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp,
1207c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *tw,
1217c478bd9Sstevel@tonic-gate usb_flags_t flags);
1227c478bd9Sstevel@tonic-gate void ehci_deallocate_isoc_in_resource(
1237c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
1247c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp,
1257c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw);
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate /*
1287c478bd9Sstevel@tonic-gate * memory addr functions
1297c478bd9Sstevel@tonic-gate */
1307c478bd9Sstevel@tonic-gate uint32_t ehci_itd_cpu_to_iommu(
1317c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
1327c478bd9Sstevel@tonic-gate ehci_itd_t *addr);
1337c478bd9Sstevel@tonic-gate ehci_itd_t *ehci_itd_iommu_to_cpu(
1347c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
1357c478bd9Sstevel@tonic-gate uintptr_t addr);
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate /*
1387c478bd9Sstevel@tonic-gate * Error parsing functions
1397c478bd9Sstevel@tonic-gate */
1407c478bd9Sstevel@tonic-gate void ehci_parse_isoc_error(
1417c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
1427c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw,
1437c478bd9Sstevel@tonic-gate ehci_itd_t *itd);
1447c478bd9Sstevel@tonic-gate static usb_cr_t ehci_parse_itd_error(
1457c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
1467c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw,
1477c478bd9Sstevel@tonic-gate ehci_itd_t *itd);
1487c478bd9Sstevel@tonic-gate static usb_cr_t ehci_parse_sitd_error(
1497c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
1507c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw,
1517c478bd9Sstevel@tonic-gate ehci_itd_t *itd);
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate /*
1547c478bd9Sstevel@tonic-gate * print functions
1557c478bd9Sstevel@tonic-gate */
1567c478bd9Sstevel@tonic-gate void ehci_print_itd(
1577c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
1587c478bd9Sstevel@tonic-gate ehci_itd_t *itd);
159b3001defSlg void ehci_print_sitd(
160b3001defSlg ehci_state_t *ehcip,
161b3001defSlg ehci_itd_t *itd);
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate /*
1657c478bd9Sstevel@tonic-gate * ehci_allocate_isoc_pools:
1667c478bd9Sstevel@tonic-gate *
1677c478bd9Sstevel@tonic-gate * Allocate the system memory for itd which are for low/full/high speed
1687c478bd9Sstevel@tonic-gate * Transfer Descriptors. Must be aligned to a 32 byte boundary.
1697c478bd9Sstevel@tonic-gate */
1707c478bd9Sstevel@tonic-gate int
ehci_allocate_isoc_pools(ehci_state_t * ehcip)1717c478bd9Sstevel@tonic-gate ehci_allocate_isoc_pools(ehci_state_t *ehcip)
1727c478bd9Sstevel@tonic-gate {
1737c478bd9Sstevel@tonic-gate ddi_device_acc_attr_t dev_attr;
1747c478bd9Sstevel@tonic-gate size_t real_length;
1757c478bd9Sstevel@tonic-gate int result;
1767c478bd9Sstevel@tonic-gate uint_t ccount;
1777c478bd9Sstevel@tonic-gate int i;
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_ATTA, ehcip->ehci_log_hdl,
1807c478bd9Sstevel@tonic-gate "ehci_allocate_isoc_pools:");
1817c478bd9Sstevel@tonic-gate
1827c478bd9Sstevel@tonic-gate /* Byte alignment */
1837c478bd9Sstevel@tonic-gate ehcip->ehci_dma_attr.dma_attr_align = EHCI_DMA_ATTR_TD_QH_ALIGNMENT;
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate /* Allocate the itd pool DMA handle */
1867c478bd9Sstevel@tonic-gate result = ddi_dma_alloc_handle(ehcip->ehci_dip,
1877c478bd9Sstevel@tonic-gate &ehcip->ehci_dma_attr,
1887c478bd9Sstevel@tonic-gate DDI_DMA_SLEEP,
1897c478bd9Sstevel@tonic-gate 0,
1907c478bd9Sstevel@tonic-gate &ehcip->ehci_itd_pool_dma_handle);
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
1937c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1947c478bd9Sstevel@tonic-gate "ehci_allocate_isoc_pools: Alloc handle failed");
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
1977c478bd9Sstevel@tonic-gate }
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate /* The host controller will be little endian */
2007c478bd9Sstevel@tonic-gate dev_attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
2017c478bd9Sstevel@tonic-gate dev_attr.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC;
2027c478bd9Sstevel@tonic-gate dev_attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gate /* Allocate the memory */
2057c478bd9Sstevel@tonic-gate result = ddi_dma_mem_alloc(ehcip->ehci_itd_pool_dma_handle,
2067c478bd9Sstevel@tonic-gate ehci_itd_pool_size * sizeof (ehci_itd_t),
2077c478bd9Sstevel@tonic-gate &dev_attr,
2087c478bd9Sstevel@tonic-gate DDI_DMA_CONSISTENT,
2097c478bd9Sstevel@tonic-gate DDI_DMA_SLEEP,
2107c478bd9Sstevel@tonic-gate 0,
2117c478bd9Sstevel@tonic-gate (caddr_t *)&ehcip->ehci_itd_pool_addr,
2127c478bd9Sstevel@tonic-gate &real_length,
2137c478bd9Sstevel@tonic-gate &ehcip->ehci_itd_pool_mem_handle);
2147c478bd9Sstevel@tonic-gate
2157c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
2167c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
2177c478bd9Sstevel@tonic-gate "ehci_allocate_isoc_pools: Alloc memory failed");
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
2207c478bd9Sstevel@tonic-gate }
2217c478bd9Sstevel@tonic-gate
2227c478bd9Sstevel@tonic-gate /* Map the ITD pool into the I/O address space */
2237c478bd9Sstevel@tonic-gate result = ddi_dma_addr_bind_handle(
2240a05e705Slc ehcip->ehci_itd_pool_dma_handle,
2250a05e705Slc NULL,
2260a05e705Slc (caddr_t)ehcip->ehci_itd_pool_addr,
2270a05e705Slc real_length,
2280a05e705Slc DDI_DMA_RDWR | DDI_DMA_CONSISTENT,
2290a05e705Slc DDI_DMA_SLEEP,
2300a05e705Slc NULL,
2310a05e705Slc &ehcip->ehci_itd_pool_cookie,
2320a05e705Slc &ccount);
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate bzero((void *)ehcip->ehci_itd_pool_addr,
2350a05e705Slc ehci_itd_pool_size * sizeof (ehci_itd_t));
2367c478bd9Sstevel@tonic-gate
2377c478bd9Sstevel@tonic-gate /* Process the result */
2387c478bd9Sstevel@tonic-gate if (result == DDI_DMA_MAPPED) {
2397c478bd9Sstevel@tonic-gate /* The cookie count should be 1 */
2407c478bd9Sstevel@tonic-gate if (ccount != 1) {
2417c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_ATTA, ehcip->ehci_log_hdl,
2427c478bd9Sstevel@tonic-gate "ehci_allocate_isoc_pools: More than 1 cookie");
2437c478bd9Sstevel@tonic-gate
2447c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
2457c478bd9Sstevel@tonic-gate }
2467c478bd9Sstevel@tonic-gate } else {
2477c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_ATTA, ehcip->ehci_log_hdl,
2487c478bd9Sstevel@tonic-gate "ehci_allocate_isoc_pools: Result = %d", result);
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate ehci_decode_ddi_dma_addr_bind_handle_result(ehcip, result);
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
2537c478bd9Sstevel@tonic-gate }
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gate /*
2567c478bd9Sstevel@tonic-gate * DMA addresses for ITD pools are bound
2577c478bd9Sstevel@tonic-gate */
2587c478bd9Sstevel@tonic-gate ehcip->ehci_dma_addr_bind_flag |= EHCI_ITD_POOL_BOUND;
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gate /* Initialize the ITD pool */
2617c478bd9Sstevel@tonic-gate for (i = 0; i < ehci_itd_pool_size; i++) {
2627c478bd9Sstevel@tonic-gate Set_ITD(ehcip->ehci_itd_pool_addr[i].itd_state,
2637c478bd9Sstevel@tonic-gate EHCI_ITD_FREE);
2647c478bd9Sstevel@tonic-gate }
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
2677c478bd9Sstevel@tonic-gate }
2687c478bd9Sstevel@tonic-gate
2697c478bd9Sstevel@tonic-gate
2707c478bd9Sstevel@tonic-gate int
ehci_get_itd_pool_size()2717c478bd9Sstevel@tonic-gate ehci_get_itd_pool_size()
2727c478bd9Sstevel@tonic-gate {
2737c478bd9Sstevel@tonic-gate return (ehci_itd_pool_size);
2747c478bd9Sstevel@tonic-gate }
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate
2777c478bd9Sstevel@tonic-gate /*
2787c478bd9Sstevel@tonic-gate * Isochronous Transfer Wrapper Functions
2797c478bd9Sstevel@tonic-gate */
2807c478bd9Sstevel@tonic-gate /*
281b3001defSlg * ehci_allocate_itw_resources:
2827c478bd9Sstevel@tonic-gate *
2837c478bd9Sstevel@tonic-gate * Allocate an iTW and n iTD from the iTD buffer pool and places it into the
2847c478bd9Sstevel@tonic-gate * ITW. It does an all or nothing transaction.
2857c478bd9Sstevel@tonic-gate *
2867c478bd9Sstevel@tonic-gate * Calculates the number of iTD needed based on pipe speed.
2877c478bd9Sstevel@tonic-gate * For LOW/FULL speed devices, 1 iTD is needed for each packet.
2887c478bd9Sstevel@tonic-gate * For HIGH speed device, 1 iTD is needed for 8 to 24 packets, depending on
2897c478bd9Sstevel@tonic-gate * the multiplier for "HIGH BANDWIDTH" transfers look at 4.7 in EHCI spec.
2907c478bd9Sstevel@tonic-gate *
2917c478bd9Sstevel@tonic-gate * Returns NULL if there is insufficient resources otherwise ITW.
2927c478bd9Sstevel@tonic-gate */
2937c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *
ehci_allocate_itw_resources(ehci_state_t * ehcip,ehci_pipe_private_t * pp,size_t itw_length,usb_flags_t usb_flags,size_t pkt_count)2947c478bd9Sstevel@tonic-gate ehci_allocate_itw_resources(
2950a05e705Slc ehci_state_t *ehcip,
2967c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp,
2977c478bd9Sstevel@tonic-gate size_t itw_length,
2987c478bd9Sstevel@tonic-gate usb_flags_t usb_flags,
2990a05e705Slc size_t pkt_count)
3007c478bd9Sstevel@tonic-gate {
3017c478bd9Sstevel@tonic-gate uint_t itd_count;
3027c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw;
3037c478bd9Sstevel@tonic-gate
3047c478bd9Sstevel@tonic-gate itw = ehci_allocate_itw(ehcip, pp, itw_length, usb_flags);
3057c478bd9Sstevel@tonic-gate
3067c478bd9Sstevel@tonic-gate if (itw == NULL) {
3077c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
3087c478bd9Sstevel@tonic-gate "ehci_allocate_itw_resources: Unable to allocate ITW");
3097c478bd9Sstevel@tonic-gate } else {
3107c478bd9Sstevel@tonic-gate itd_count = ehci_calc_num_itds(itw, pkt_count);
311b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
312b3001defSlg "ehci_allocate_itw_resources: itd_count = 0x%d", itd_count);
3137c478bd9Sstevel@tonic-gate
3147c478bd9Sstevel@tonic-gate if (ehci_allocate_itds_for_itw(ehcip, itw, itd_count) ==
3157c478bd9Sstevel@tonic-gate USB_SUCCESS) {
3167c478bd9Sstevel@tonic-gate itw->itw_num_itds = itd_count;
3177c478bd9Sstevel@tonic-gate } else {
3187c478bd9Sstevel@tonic-gate ehci_deallocate_itw(ehcip, pp, itw);
3197c478bd9Sstevel@tonic-gate itw = NULL;
3207c478bd9Sstevel@tonic-gate }
3217c478bd9Sstevel@tonic-gate }
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gate return (itw);
3247c478bd9Sstevel@tonic-gate }
3257c478bd9Sstevel@tonic-gate
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate /*
3287c478bd9Sstevel@tonic-gate * ehci_allocate_itw:
3297c478bd9Sstevel@tonic-gate *
3307c478bd9Sstevel@tonic-gate * Creates a Isochronous Transfer Wrapper (itw) and populate it with this
3317c478bd9Sstevel@tonic-gate * endpoint's data. This involves the allocation of DMA resources.
3327c478bd9Sstevel@tonic-gate *
3337c478bd9Sstevel@tonic-gate * ITW Fields not set by this function:
3347c478bd9Sstevel@tonic-gate * - will be populated itds are allocated
3357c478bd9Sstevel@tonic-gate * num_ids
3367c478bd9Sstevel@tonic-gate * itd_head
3377c478bd9Sstevel@tonic-gate * itd_tail
3387c478bd9Sstevel@tonic-gate * curr_xfer_reqp
3397c478bd9Sstevel@tonic-gate * curr_isoc_pktp
3407c478bd9Sstevel@tonic-gate * itw_itd_free_list
3417c478bd9Sstevel@tonic-gate * - Should be set by the calling function
3427c478bd9Sstevel@tonic-gate * itw_handle_callback_value
3437c478bd9Sstevel@tonic-gate */
3447c478bd9Sstevel@tonic-gate static ehci_isoc_xwrapper_t *
ehci_allocate_itw(ehci_state_t * ehcip,ehci_pipe_private_t * pp,size_t length,usb_flags_t usb_flags)3457c478bd9Sstevel@tonic-gate ehci_allocate_itw(
3467c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
3477c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp,
3487c478bd9Sstevel@tonic-gate size_t length,
3497c478bd9Sstevel@tonic-gate usb_flags_t usb_flags)
3507c478bd9Sstevel@tonic-gate {
3517c478bd9Sstevel@tonic-gate ddi_device_acc_attr_t dev_attr;
3527c478bd9Sstevel@tonic-gate int result;
3537c478bd9Sstevel@tonic-gate size_t real_length;
3547c478bd9Sstevel@tonic-gate uint_t ccount; /* Cookie count */
3557c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph = pp->pp_pipe_handle;
3567c478bd9Sstevel@tonic-gate usba_device_t *usba_device = ph->p_usba_device;
3577c478bd9Sstevel@tonic-gate usb_ep_descr_t *endpoint = &ph->p_ep;
3587c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw;
3597c478bd9Sstevel@tonic-gate
3607c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
361112116d8Sfb "ehci_allocate_itw: length = 0x%lx flags = 0x%x",
3627c478bd9Sstevel@tonic-gate length, usb_flags);
3637c478bd9Sstevel@tonic-gate
3647c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex));
3657c478bd9Sstevel@tonic-gate
3667c478bd9Sstevel@tonic-gate /* Allocate space for the transfer wrapper */
3677c478bd9Sstevel@tonic-gate itw = kmem_zalloc(sizeof (ehci_isoc_xwrapper_t), KM_NOSLEEP);
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate if (itw == NULL) {
3707c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
3717c478bd9Sstevel@tonic-gate "ehci_allocate_itw: kmem_zalloc failed");
3727c478bd9Sstevel@tonic-gate
3737c478bd9Sstevel@tonic-gate return (NULL);
3747c478bd9Sstevel@tonic-gate }
3757c478bd9Sstevel@tonic-gate
3767c478bd9Sstevel@tonic-gate ehcip->ehci_dma_attr.dma_attr_align = EHCI_DMA_ATTR_ALIGNMENT;
3777c478bd9Sstevel@tonic-gate
3787c478bd9Sstevel@tonic-gate /* Allocate the DMA handle */
3797c478bd9Sstevel@tonic-gate result = ddi_dma_alloc_handle(ehcip->ehci_dip,
3807c478bd9Sstevel@tonic-gate &ehcip->ehci_dma_attr,
3817c478bd9Sstevel@tonic-gate DDI_DMA_DONTWAIT,
3827c478bd9Sstevel@tonic-gate 0,
3837c478bd9Sstevel@tonic-gate &itw->itw_dmahandle);
3847c478bd9Sstevel@tonic-gate
3857c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
3867c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
3877c478bd9Sstevel@tonic-gate "ehci_create_transfer_wrapper: Alloc handle failed");
3887c478bd9Sstevel@tonic-gate
3897c478bd9Sstevel@tonic-gate kmem_free(itw, sizeof (ehci_isoc_xwrapper_t));
3907c478bd9Sstevel@tonic-gate
3917c478bd9Sstevel@tonic-gate return (NULL);
3927c478bd9Sstevel@tonic-gate }
3937c478bd9Sstevel@tonic-gate
3947c478bd9Sstevel@tonic-gate /* no need for swapping the raw data in the buffers */
3957c478bd9Sstevel@tonic-gate dev_attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
3967c478bd9Sstevel@tonic-gate dev_attr.devacc_attr_endian_flags = DDI_NEVERSWAP_ACC;
3977c478bd9Sstevel@tonic-gate dev_attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
3987c478bd9Sstevel@tonic-gate
3997c478bd9Sstevel@tonic-gate /* Allocate the memory */
4007c478bd9Sstevel@tonic-gate result = ddi_dma_mem_alloc(itw->itw_dmahandle,
4017c478bd9Sstevel@tonic-gate length,
4027c478bd9Sstevel@tonic-gate &dev_attr,
4037c478bd9Sstevel@tonic-gate DDI_DMA_CONSISTENT,
4047c478bd9Sstevel@tonic-gate DDI_DMA_DONTWAIT,
4057c478bd9Sstevel@tonic-gate NULL,
4067c478bd9Sstevel@tonic-gate (caddr_t *)&itw->itw_buf,
4077c478bd9Sstevel@tonic-gate &real_length,
4087c478bd9Sstevel@tonic-gate &itw->itw_accesshandle);
4097c478bd9Sstevel@tonic-gate
4107c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
4117c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
4127c478bd9Sstevel@tonic-gate "ehci_create_transfer_wrapper: dma_mem_alloc fail");
4137c478bd9Sstevel@tonic-gate
4147c478bd9Sstevel@tonic-gate ddi_dma_free_handle(&itw->itw_dmahandle);
4157c478bd9Sstevel@tonic-gate kmem_free(itw, sizeof (ehci_isoc_xwrapper_t));
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gate return (NULL);
4187c478bd9Sstevel@tonic-gate }
4197c478bd9Sstevel@tonic-gate
4207c478bd9Sstevel@tonic-gate ASSERT(real_length >= length);
4217c478bd9Sstevel@tonic-gate
4227c478bd9Sstevel@tonic-gate /* Bind the handle */
4237c478bd9Sstevel@tonic-gate result = ddi_dma_addr_bind_handle(itw->itw_dmahandle,
4247c478bd9Sstevel@tonic-gate NULL,
4257c478bd9Sstevel@tonic-gate (caddr_t)itw->itw_buf,
4267c478bd9Sstevel@tonic-gate real_length,
4277c478bd9Sstevel@tonic-gate DDI_DMA_RDWR|DDI_DMA_CONSISTENT,
4287c478bd9Sstevel@tonic-gate DDI_DMA_DONTWAIT,
4297c478bd9Sstevel@tonic-gate NULL,
4307c478bd9Sstevel@tonic-gate &itw->itw_cookie,
4317c478bd9Sstevel@tonic-gate &ccount);
4327c478bd9Sstevel@tonic-gate
4337c478bd9Sstevel@tonic-gate if (result == DDI_DMA_MAPPED) {
4347c478bd9Sstevel@tonic-gate /* The cookie count should be 1 */
4357c478bd9Sstevel@tonic-gate if (ccount != 1) {
4367c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
4377c478bd9Sstevel@tonic-gate "ehci_create_transfer_wrapper: More than 1 cookie");
4387c478bd9Sstevel@tonic-gate
4397c478bd9Sstevel@tonic-gate result = ddi_dma_unbind_handle(itw->itw_dmahandle);
4407c478bd9Sstevel@tonic-gate ASSERT(result == DDI_SUCCESS);
4417c478bd9Sstevel@tonic-gate
4427c478bd9Sstevel@tonic-gate ddi_dma_mem_free(&itw->itw_accesshandle);
4437c478bd9Sstevel@tonic-gate ddi_dma_free_handle(&itw->itw_dmahandle);
4447c478bd9Sstevel@tonic-gate kmem_free(itw, sizeof (ehci_isoc_xwrapper_t));
4457c478bd9Sstevel@tonic-gate
4467c478bd9Sstevel@tonic-gate return (NULL);
4477c478bd9Sstevel@tonic-gate }
4487c478bd9Sstevel@tonic-gate } else {
4497c478bd9Sstevel@tonic-gate ehci_decode_ddi_dma_addr_bind_handle_result(ehcip, result);
4507c478bd9Sstevel@tonic-gate
4517c478bd9Sstevel@tonic-gate ddi_dma_mem_free(&itw->itw_accesshandle);
4527c478bd9Sstevel@tonic-gate ddi_dma_free_handle(&itw->itw_dmahandle);
4537c478bd9Sstevel@tonic-gate kmem_free(itw, sizeof (ehci_isoc_xwrapper_t));
4547c478bd9Sstevel@tonic-gate
4557c478bd9Sstevel@tonic-gate return (NULL);
4567c478bd9Sstevel@tonic-gate }
4577c478bd9Sstevel@tonic-gate
4587c478bd9Sstevel@tonic-gate /* Store a back pointer to the pipe private structure */
4597c478bd9Sstevel@tonic-gate itw->itw_pipe_private = pp;
4607c478bd9Sstevel@tonic-gate if (pp->pp_itw_head == NULL) {
4617c478bd9Sstevel@tonic-gate pp->pp_itw_head = itw;
4627c478bd9Sstevel@tonic-gate pp->pp_itw_tail = itw;
4637c478bd9Sstevel@tonic-gate } else {
4647c478bd9Sstevel@tonic-gate pp->pp_itw_tail->itw_next = itw;
4657c478bd9Sstevel@tonic-gate pp->pp_itw_tail = itw;
4667c478bd9Sstevel@tonic-gate }
4677c478bd9Sstevel@tonic-gate
4687c478bd9Sstevel@tonic-gate /*
4697c478bd9Sstevel@tonic-gate * Store transfer information
4707c478bd9Sstevel@tonic-gate * itw_buf has been allocated and will be set later
4717c478bd9Sstevel@tonic-gate */
4727c478bd9Sstevel@tonic-gate itw->itw_length = length;
4737c478bd9Sstevel@tonic-gate itw->itw_flags = usb_flags;
4747c478bd9Sstevel@tonic-gate itw->itw_port_status = usba_device->usb_port_status;
4757c478bd9Sstevel@tonic-gate itw->itw_direction = endpoint->bEndpointAddress & USB_EP_DIR_MASK;
4767c478bd9Sstevel@tonic-gate
4777c478bd9Sstevel@tonic-gate /*
4787c478bd9Sstevel@tonic-gate * Store the endpoint information that will be used by the
4797c478bd9Sstevel@tonic-gate * transfer descriptors later.
4807c478bd9Sstevel@tonic-gate */
4817c478bd9Sstevel@tonic-gate mutex_enter(&usba_device->usb_mutex);
4827c478bd9Sstevel@tonic-gate itw->itw_hub_addr = usba_device->usb_hs_hub_addr;
4837c478bd9Sstevel@tonic-gate itw->itw_hub_port = usba_device->usb_hs_hub_port;
4847c478bd9Sstevel@tonic-gate itw->itw_endpoint_num = endpoint->bEndpointAddress & USB_EP_NUM_MASK;
4857c478bd9Sstevel@tonic-gate itw->itw_device_addr = usba_device->usb_addr;
4867c478bd9Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex);
4877c478bd9Sstevel@tonic-gate
4887c478bd9Sstevel@tonic-gate /* Get and Store 32bit ID */
4897c478bd9Sstevel@tonic-gate itw->itw_id = EHCI_GET_ID((void *)itw);
490*0a1044f1SToomas Soome ASSERT(itw->itw_id != 0);
4917c478bd9Sstevel@tonic-gate
492b3001defSlg USB_DPRINTF_L3(PRINT_MASK_ALLOC, ehcip->ehci_log_hdl,
493112116d8Sfb "ehci_create_itw: itw = 0x%p real_length = 0x%lx",
494112116d8Sfb (void *)itw, real_length);
4957c478bd9Sstevel@tonic-gate
496dfbb3a42SRaymond Chen ehcip->ehci_periodic_req_count++;
497dfbb3a42SRaymond Chen ehci_toggle_scheduler(ehcip);
498dfbb3a42SRaymond Chen
4997c478bd9Sstevel@tonic-gate return (itw);
5007c478bd9Sstevel@tonic-gate }
5017c478bd9Sstevel@tonic-gate
5027c478bd9Sstevel@tonic-gate
5037c478bd9Sstevel@tonic-gate /*
5047c478bd9Sstevel@tonic-gate * ehci_deallocate_itw:
5057c478bd9Sstevel@tonic-gate *
5067c478bd9Sstevel@tonic-gate * Deallocate of a Isochronous Transaction Wrapper (TW) and this involves the
5077c478bd9Sstevel@tonic-gate * freeing of DMA resources.
5087c478bd9Sstevel@tonic-gate */
5097c478bd9Sstevel@tonic-gate void
ehci_deallocate_itw(ehci_state_t * ehcip,ehci_pipe_private_t * pp,ehci_isoc_xwrapper_t * itw)5107c478bd9Sstevel@tonic-gate ehci_deallocate_itw(
5117c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
5127c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp,
5137c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw)
5147c478bd9Sstevel@tonic-gate {
5157c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *prev, *next;
5167c478bd9Sstevel@tonic-gate
5177c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_ALLOC, ehcip->ehci_log_hdl,
518112116d8Sfb "ehci_deallocate_itw: itw = 0x%p", (void *)itw);
5197c478bd9Sstevel@tonic-gate
5207c478bd9Sstevel@tonic-gate /*
5217c478bd9Sstevel@tonic-gate * If the transfer wrapper has no Host Controller (HC)
5227c478bd9Sstevel@tonic-gate * Transfer Descriptors (ITD) associated with it, then
5237c478bd9Sstevel@tonic-gate * remove the transfer wrapper.
5247c478bd9Sstevel@tonic-gate */
5257c478bd9Sstevel@tonic-gate if (itw->itw_itd_head) {
5267c478bd9Sstevel@tonic-gate ASSERT(itw->itw_itd_tail != NULL);
5277c478bd9Sstevel@tonic-gate
5287c478bd9Sstevel@tonic-gate return;
5297c478bd9Sstevel@tonic-gate }
5307c478bd9Sstevel@tonic-gate
5317c478bd9Sstevel@tonic-gate ASSERT(itw->itw_itd_tail == NULL);
5327c478bd9Sstevel@tonic-gate
5337c478bd9Sstevel@tonic-gate /* Make sure we return all the unused itd's to the pool as well */
5347c478bd9Sstevel@tonic-gate ehci_deallocate_itds_for_itw(ehcip, itw);
5357c478bd9Sstevel@tonic-gate
5367c478bd9Sstevel@tonic-gate /*
5377c478bd9Sstevel@tonic-gate * If pp->pp_tw_head and pp->pp_tw_tail are pointing to
5387c478bd9Sstevel@tonic-gate * given TW then set the head and tail equal to NULL.
5397c478bd9Sstevel@tonic-gate * Otherwise search for this TW in the linked TW's list
5407c478bd9Sstevel@tonic-gate * and then remove this TW from the list.
5417c478bd9Sstevel@tonic-gate */
5427c478bd9Sstevel@tonic-gate if (pp->pp_itw_head == itw) {
5437c478bd9Sstevel@tonic-gate if (pp->pp_itw_tail == itw) {
5447c478bd9Sstevel@tonic-gate pp->pp_itw_head = NULL;
5457c478bd9Sstevel@tonic-gate pp->pp_itw_tail = NULL;
5467c478bd9Sstevel@tonic-gate } else {
5477c478bd9Sstevel@tonic-gate pp->pp_itw_head = itw->itw_next;
5487c478bd9Sstevel@tonic-gate }
5497c478bd9Sstevel@tonic-gate } else {
5507c478bd9Sstevel@tonic-gate prev = pp->pp_itw_head;
5517c478bd9Sstevel@tonic-gate next = prev->itw_next;
5527c478bd9Sstevel@tonic-gate
5537c478bd9Sstevel@tonic-gate while (next && (next != itw)) {
5547c478bd9Sstevel@tonic-gate prev = next;
5557c478bd9Sstevel@tonic-gate next = next->itw_next;
5567c478bd9Sstevel@tonic-gate }
5577c478bd9Sstevel@tonic-gate
5587c478bd9Sstevel@tonic-gate if (next == itw) {
5597c478bd9Sstevel@tonic-gate prev->itw_next = next->itw_next;
5607c478bd9Sstevel@tonic-gate
5617c478bd9Sstevel@tonic-gate if (pp->pp_itw_tail == itw) {
5627c478bd9Sstevel@tonic-gate pp->pp_itw_tail = prev;
5637c478bd9Sstevel@tonic-gate }
5647c478bd9Sstevel@tonic-gate }
5657c478bd9Sstevel@tonic-gate }
5667c478bd9Sstevel@tonic-gate
5677c478bd9Sstevel@tonic-gate /* Free this iTWs dma resources */
5687c478bd9Sstevel@tonic-gate ehci_free_itw_dma(ehcip, pp, itw);
569dfbb3a42SRaymond Chen
570dfbb3a42SRaymond Chen ehcip->ehci_periodic_req_count--;
571dfbb3a42SRaymond Chen ehci_toggle_scheduler(ehcip);
5727c478bd9Sstevel@tonic-gate }
5737c478bd9Sstevel@tonic-gate
5747c478bd9Sstevel@tonic-gate
5757c478bd9Sstevel@tonic-gate /*
5767c478bd9Sstevel@tonic-gate * ehci_free_itw_dma:
5777c478bd9Sstevel@tonic-gate *
5787c478bd9Sstevel@tonic-gate * Free the Isochronous Transfer Wrapper dma resources.
5797c478bd9Sstevel@tonic-gate */
5807c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5817c478bd9Sstevel@tonic-gate static void
ehci_free_itw_dma(ehci_state_t * ehcip,ehci_pipe_private_t * pp,ehci_isoc_xwrapper_t * itw)5827c478bd9Sstevel@tonic-gate ehci_free_itw_dma(
5837c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
5847c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp,
5857c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw)
5867c478bd9Sstevel@tonic-gate {
5877c478bd9Sstevel@tonic-gate int rval;
5887c478bd9Sstevel@tonic-gate
5897c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_ALLOC, ehcip->ehci_log_hdl,
590112116d8Sfb "ehci_free_itw_dma: itw = 0x%p", (void *)itw);
5917c478bd9Sstevel@tonic-gate
5927c478bd9Sstevel@tonic-gate ASSERT(itw != NULL);
593*0a1044f1SToomas Soome ASSERT(itw->itw_id != 0);
5947c478bd9Sstevel@tonic-gate
5957c478bd9Sstevel@tonic-gate /* Free 32bit ID */
5967c478bd9Sstevel@tonic-gate EHCI_FREE_ID((uint32_t)itw->itw_id);
5977c478bd9Sstevel@tonic-gate
5987c478bd9Sstevel@tonic-gate rval = ddi_dma_unbind_handle(itw->itw_dmahandle);
5997c478bd9Sstevel@tonic-gate ASSERT(rval == DDI_SUCCESS);
6007c478bd9Sstevel@tonic-gate
6017c478bd9Sstevel@tonic-gate ddi_dma_mem_free(&itw->itw_accesshandle);
6027c478bd9Sstevel@tonic-gate ddi_dma_free_handle(&itw->itw_dmahandle);
6037c478bd9Sstevel@tonic-gate
6047c478bd9Sstevel@tonic-gate /* Free transfer wrapper */
6057c478bd9Sstevel@tonic-gate kmem_free(itw, sizeof (ehci_isoc_xwrapper_t));
6067c478bd9Sstevel@tonic-gate }
6077c478bd9Sstevel@tonic-gate
6087c478bd9Sstevel@tonic-gate
6097c478bd9Sstevel@tonic-gate /*
6107c478bd9Sstevel@tonic-gate * transfer descriptor functions
6117c478bd9Sstevel@tonic-gate */
6127c478bd9Sstevel@tonic-gate /*
6137c478bd9Sstevel@tonic-gate * ehci_allocate_itd:
6147c478bd9Sstevel@tonic-gate *
6157c478bd9Sstevel@tonic-gate * Allocate a Transfer Descriptor (iTD) from the iTD buffer pool.
6167c478bd9Sstevel@tonic-gate */
6177c478bd9Sstevel@tonic-gate static ehci_itd_t *
ehci_allocate_itd(ehci_state_t * ehcip)6187c478bd9Sstevel@tonic-gate ehci_allocate_itd(ehci_state_t *ehcip)
6197c478bd9Sstevel@tonic-gate {
6207c478bd9Sstevel@tonic-gate int i, state;
6217c478bd9Sstevel@tonic-gate ehci_itd_t *itd;
6227c478bd9Sstevel@tonic-gate
6237c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex));
6247c478bd9Sstevel@tonic-gate
6257c478bd9Sstevel@tonic-gate /*
6267c478bd9Sstevel@tonic-gate * Search for a blank Transfer Descriptor (iTD)
6277c478bd9Sstevel@tonic-gate * in the iTD buffer pool.
6287c478bd9Sstevel@tonic-gate */
6297c478bd9Sstevel@tonic-gate for (i = 0; i < ehci_itd_pool_size; i ++) {
6307c478bd9Sstevel@tonic-gate state = Get_ITD(ehcip->ehci_itd_pool_addr[i].itd_state);
6317c478bd9Sstevel@tonic-gate if (state == EHCI_ITD_FREE) {
6327c478bd9Sstevel@tonic-gate break;
6337c478bd9Sstevel@tonic-gate }
6347c478bd9Sstevel@tonic-gate }
6357c478bd9Sstevel@tonic-gate
6367c478bd9Sstevel@tonic-gate if (i >= ehci_itd_pool_size) {
6377c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_ALLOC, ehcip->ehci_log_hdl,
6387c478bd9Sstevel@tonic-gate "ehci_allocate_itd: ITD exhausted");
6397c478bd9Sstevel@tonic-gate
6407c478bd9Sstevel@tonic-gate return (NULL);
6417c478bd9Sstevel@tonic-gate }
6427c478bd9Sstevel@tonic-gate
6437c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_ALLOC, ehcip->ehci_log_hdl,
6447c478bd9Sstevel@tonic-gate "ehci_allocate_itd: Allocated %d", i);
6457c478bd9Sstevel@tonic-gate
6467c478bd9Sstevel@tonic-gate /* Create a new dummy for the end of the ITD list */
6477c478bd9Sstevel@tonic-gate itd = &ehcip->ehci_itd_pool_addr[i];
6487c478bd9Sstevel@tonic-gate
6497c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
6507c478bd9Sstevel@tonic-gate "ehci_allocate_itd: itd 0x%p", (void *)itd);
6517c478bd9Sstevel@tonic-gate
6527c478bd9Sstevel@tonic-gate /* Mark the newly allocated ITD as a empty */
6537c478bd9Sstevel@tonic-gate Set_ITD(itd->itd_state, EHCI_ITD_DUMMY);
6547c478bd9Sstevel@tonic-gate
6557c478bd9Sstevel@tonic-gate return (itd);
6567c478bd9Sstevel@tonic-gate }
6577c478bd9Sstevel@tonic-gate
6587c478bd9Sstevel@tonic-gate
6597c478bd9Sstevel@tonic-gate /*
6607c478bd9Sstevel@tonic-gate * ehci_deallocate_itd:
6617c478bd9Sstevel@tonic-gate *
6627c478bd9Sstevel@tonic-gate * Deallocate a Host Controller's (HC) Transfer Descriptor (ITD).
6637c478bd9Sstevel@tonic-gate *
6647c478bd9Sstevel@tonic-gate */
6657c478bd9Sstevel@tonic-gate void
ehci_deallocate_itd(ehci_state_t * ehcip,ehci_isoc_xwrapper_t * itw,ehci_itd_t * old_itd)6667c478bd9Sstevel@tonic-gate ehci_deallocate_itd(
6677c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
6687c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw,
6697c478bd9Sstevel@tonic-gate ehci_itd_t *old_itd)
6707c478bd9Sstevel@tonic-gate {
6717c478bd9Sstevel@tonic-gate ehci_itd_t *itd, *next_itd;
6727c478bd9Sstevel@tonic-gate
6737c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_ALLOC, ehcip->ehci_log_hdl,
6747c478bd9Sstevel@tonic-gate "ehci_deallocate_itd: old_itd = 0x%p", (void *)old_itd);
6757c478bd9Sstevel@tonic-gate
6767c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex));
6777c478bd9Sstevel@tonic-gate
6787c478bd9Sstevel@tonic-gate /* If it has been marked RECLAIM it has already been removed */
6797c478bd9Sstevel@tonic-gate if (Get_ITD(old_itd->itd_state) != EHCI_ITD_RECLAIM) {
6807c478bd9Sstevel@tonic-gate ehci_remove_isoc_from_pfl(ehcip, old_itd);
6817c478bd9Sstevel@tonic-gate }
6827c478bd9Sstevel@tonic-gate
6837c478bd9Sstevel@tonic-gate /* Make sure the ITD is not in the PFL */
6847c478bd9Sstevel@tonic-gate ASSERT(Get_ITD_FRAME(old_itd->itd_frame_number) == 0);
6857c478bd9Sstevel@tonic-gate
6867c478bd9Sstevel@tonic-gate /* Remove the itd from the itw */
6877c478bd9Sstevel@tonic-gate itd = itw->itw_itd_head;
6887c478bd9Sstevel@tonic-gate if (old_itd != itd) {
6897c478bd9Sstevel@tonic-gate next_itd = ehci_itd_iommu_to_cpu(ehcip,
6907c478bd9Sstevel@tonic-gate Get_ITD(itd->itd_itw_next_itd));
6917c478bd9Sstevel@tonic-gate
6927c478bd9Sstevel@tonic-gate while (next_itd != old_itd) {
6937c478bd9Sstevel@tonic-gate itd = next_itd;
6947c478bd9Sstevel@tonic-gate next_itd = ehci_itd_iommu_to_cpu(ehcip,
6957c478bd9Sstevel@tonic-gate Get_ITD(itd->itd_itw_next_itd));
6967c478bd9Sstevel@tonic-gate }
6977c478bd9Sstevel@tonic-gate
6987c478bd9Sstevel@tonic-gate Set_ITD(itd->itd_itw_next_itd, old_itd->itd_itw_next_itd);
6997c478bd9Sstevel@tonic-gate
7006aef9e11SToomas Soome if (itd->itd_itw_next_itd == 0) {
7017c478bd9Sstevel@tonic-gate itw->itw_itd_tail = itd;
7027c478bd9Sstevel@tonic-gate }
7037c478bd9Sstevel@tonic-gate } else {
7047c478bd9Sstevel@tonic-gate itw->itw_itd_head = ehci_itd_iommu_to_cpu(
7050a05e705Slc ehcip, Get_ITD(old_itd->itd_itw_next_itd));
7067c478bd9Sstevel@tonic-gate
7077c478bd9Sstevel@tonic-gate if (itw->itw_itd_head == NULL) {
7087c478bd9Sstevel@tonic-gate itw->itw_itd_tail = NULL;
7097c478bd9Sstevel@tonic-gate }
7107c478bd9Sstevel@tonic-gate }
7117c478bd9Sstevel@tonic-gate
7127c478bd9Sstevel@tonic-gate bzero((char *)old_itd, sizeof (ehci_itd_t));
7137c478bd9Sstevel@tonic-gate Set_ITD(old_itd->itd_state, EHCI_ITD_FREE);
7147c478bd9Sstevel@tonic-gate
7157c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
7167c478bd9Sstevel@tonic-gate "Dealloc_itd: itd 0x%p", (void *)old_itd);
7177c478bd9Sstevel@tonic-gate }
7187c478bd9Sstevel@tonic-gate
7197c478bd9Sstevel@tonic-gate
7207c478bd9Sstevel@tonic-gate /*
7217c478bd9Sstevel@tonic-gate * ehci_calc_num_itds:
7227c478bd9Sstevel@tonic-gate *
7237c478bd9Sstevel@tonic-gate * Calculates how many ITDs are needed for this request.
7247c478bd9Sstevel@tonic-gate * The calculation is based on weather it is an HIGH speed
7257c478bd9Sstevel@tonic-gate * transaction of a FULL/LOW transaction.
7267c478bd9Sstevel@tonic-gate *
7277c478bd9Sstevel@tonic-gate * For FULL/LOW transaction more itds are necessary if it
7287c478bd9Sstevel@tonic-gate * spans frames.
7297c478bd9Sstevel@tonic-gate */
7307c478bd9Sstevel@tonic-gate uint_t
ehci_calc_num_itds(ehci_isoc_xwrapper_t * itw,size_t pkt_count)7317c478bd9Sstevel@tonic-gate ehci_calc_num_itds(
7327c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw,
7330a05e705Slc size_t pkt_count)
7347c478bd9Sstevel@tonic-gate {
7357c478bd9Sstevel@tonic-gate uint_t multiplier, itd_count;
7367c478bd9Sstevel@tonic-gate
7377c478bd9Sstevel@tonic-gate /* Allocate the appropriate isoc resources */
7387c478bd9Sstevel@tonic-gate if (itw->itw_port_status == USBA_HIGH_SPEED_DEV) {
7397c478bd9Sstevel@tonic-gate /* Multiplier needs to be passed in somehow */
7407c478bd9Sstevel@tonic-gate multiplier = 1 * 8;
7417c478bd9Sstevel@tonic-gate itd_count = pkt_count / multiplier;
7427c478bd9Sstevel@tonic-gate if (pkt_count % multiplier) {
7437c478bd9Sstevel@tonic-gate itd_count++;
7447c478bd9Sstevel@tonic-gate }
7457c478bd9Sstevel@tonic-gate } else {
746d29f5a71Szhigang lu - Sun Microsystems - Beijing China itd_count = (uint_t)pkt_count;
7477c478bd9Sstevel@tonic-gate }
7487c478bd9Sstevel@tonic-gate
749b3001defSlg return (itd_count);
7507c478bd9Sstevel@tonic-gate }
7517c478bd9Sstevel@tonic-gate
7527c478bd9Sstevel@tonic-gate /*
7537c478bd9Sstevel@tonic-gate * ehci_allocate_itds_for_itw:
7547c478bd9Sstevel@tonic-gate *
7557c478bd9Sstevel@tonic-gate * Allocate n Transfer Descriptors (TD) from the TD buffer pool and places it
7567c478bd9Sstevel@tonic-gate * into the TW.
7577c478bd9Sstevel@tonic-gate *
7587c478bd9Sstevel@tonic-gate * Returns USB_NO_RESOURCES if it was not able to allocate all the requested TD
7597c478bd9Sstevel@tonic-gate * otherwise USB_SUCCESS.
7607c478bd9Sstevel@tonic-gate */
7617c478bd9Sstevel@tonic-gate int
ehci_allocate_itds_for_itw(ehci_state_t * ehcip,ehci_isoc_xwrapper_t * itw,uint_t itd_count)7627c478bd9Sstevel@tonic-gate ehci_allocate_itds_for_itw(
7637c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
7647c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw,
7657c478bd9Sstevel@tonic-gate uint_t itd_count)
7667c478bd9Sstevel@tonic-gate {
7677c478bd9Sstevel@tonic-gate ehci_itd_t *itd;
7687c478bd9Sstevel@tonic-gate uint32_t itd_addr;
7697c478bd9Sstevel@tonic-gate int i;
7707c478bd9Sstevel@tonic-gate int error = USB_SUCCESS;
7717c478bd9Sstevel@tonic-gate
7727c478bd9Sstevel@tonic-gate for (i = 0; i < itd_count; i += 1) {
7737c478bd9Sstevel@tonic-gate itd = ehci_allocate_itd(ehcip);
7747c478bd9Sstevel@tonic-gate if (itd == NULL) {
7757c478bd9Sstevel@tonic-gate error = USB_NO_RESOURCES;
7767c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
7777c478bd9Sstevel@tonic-gate "ehci_allocate_itds_for_itw: "
7787c478bd9Sstevel@tonic-gate "Unable to allocate %d ITDs",
7797c478bd9Sstevel@tonic-gate itd_count);
7807c478bd9Sstevel@tonic-gate break;
7817c478bd9Sstevel@tonic-gate }
7827c478bd9Sstevel@tonic-gate if (i > 0) {
7837c478bd9Sstevel@tonic-gate itd_addr = ehci_itd_cpu_to_iommu(ehcip,
7847c478bd9Sstevel@tonic-gate itw->itw_itd_free_list);
7857c478bd9Sstevel@tonic-gate Set_ITD(itd->itd_link_ptr, itd_addr);
7867c478bd9Sstevel@tonic-gate }
787b3001defSlg Set_ITD_INDEX(itd, 0, EHCI_ITD_UNUSED_INDEX);
788b3001defSlg Set_ITD_INDEX(itd, 1, EHCI_ITD_UNUSED_INDEX);
789b3001defSlg Set_ITD_INDEX(itd, 2, EHCI_ITD_UNUSED_INDEX);
790b3001defSlg Set_ITD_INDEX(itd, 3, EHCI_ITD_UNUSED_INDEX);
791b3001defSlg Set_ITD_INDEX(itd, 4, EHCI_ITD_UNUSED_INDEX);
792b3001defSlg Set_ITD_INDEX(itd, 5, EHCI_ITD_UNUSED_INDEX);
793b3001defSlg Set_ITD_INDEX(itd, 6, EHCI_ITD_UNUSED_INDEX);
794b3001defSlg Set_ITD_INDEX(itd, 7, EHCI_ITD_UNUSED_INDEX);
7957c478bd9Sstevel@tonic-gate itw->itw_itd_free_list = itd;
7967c478bd9Sstevel@tonic-gate }
7977c478bd9Sstevel@tonic-gate
7987c478bd9Sstevel@tonic-gate return (error);
7997c478bd9Sstevel@tonic-gate }
8007c478bd9Sstevel@tonic-gate
8017c478bd9Sstevel@tonic-gate
8027c478bd9Sstevel@tonic-gate /*
8037c478bd9Sstevel@tonic-gate * ehci_deallocate_itds_for_itw:
8047c478bd9Sstevel@tonic-gate *
8057c478bd9Sstevel@tonic-gate * Free all allocated resources for Transaction Wrapper (TW).
8067c478bd9Sstevel@tonic-gate * Does not free the iTW itself.
8077c478bd9Sstevel@tonic-gate */
8087c478bd9Sstevel@tonic-gate static void
ehci_deallocate_itds_for_itw(ehci_state_t * ehcip,ehci_isoc_xwrapper_t * itw)8097c478bd9Sstevel@tonic-gate ehci_deallocate_itds_for_itw(
8107c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
8117c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw)
8127c478bd9Sstevel@tonic-gate {
8137c478bd9Sstevel@tonic-gate ehci_itd_t *itd = NULL;
8147c478bd9Sstevel@tonic-gate ehci_itd_t *temp_itd = NULL;
8157c478bd9Sstevel@tonic-gate
8167c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_ALLOC, ehcip->ehci_log_hdl,
817112116d8Sfb "ehci_free_itw_itd_resources: itw = 0x%p", (void *)itw);
8187c478bd9Sstevel@tonic-gate
8197c478bd9Sstevel@tonic-gate itd = itw->itw_itd_free_list;
8207c478bd9Sstevel@tonic-gate while (itd != NULL) {
8217c478bd9Sstevel@tonic-gate /* Save the pointer to the next itd before destroying it */
8227c478bd9Sstevel@tonic-gate temp_itd = ehci_itd_iommu_to_cpu(ehcip,
8237c478bd9Sstevel@tonic-gate Get_ITD(itd->itd_link_ptr));
8247c478bd9Sstevel@tonic-gate ehci_deallocate_itd(ehcip, itw, itd);
8257c478bd9Sstevel@tonic-gate itd = temp_itd;
8267c478bd9Sstevel@tonic-gate }
8277c478bd9Sstevel@tonic-gate itw->itw_itd_free_list = NULL;
8287c478bd9Sstevel@tonic-gate }
8297c478bd9Sstevel@tonic-gate
8307c478bd9Sstevel@tonic-gate
8317c478bd9Sstevel@tonic-gate /*
8327c478bd9Sstevel@tonic-gate * ehci_insert_itd_on_itw:
8337c478bd9Sstevel@tonic-gate *
8347c478bd9Sstevel@tonic-gate * The transfer wrapper keeps a list of all Transfer Descriptors (iTD) that
8357c478bd9Sstevel@tonic-gate * are allocated for this transfer. Insert a iTD onto this list.
8367c478bd9Sstevel@tonic-gate */
ehci_insert_itd_on_itw(ehci_state_t * ehcip,ehci_isoc_xwrapper_t * itw,ehci_itd_t * itd)8377c478bd9Sstevel@tonic-gate void ehci_insert_itd_on_itw(
8387c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
8397c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw,
8407c478bd9Sstevel@tonic-gate ehci_itd_t *itd)
8417c478bd9Sstevel@tonic-gate {
8427c478bd9Sstevel@tonic-gate /*
8437c478bd9Sstevel@tonic-gate * Set the next pointer to NULL because
8447c478bd9Sstevel@tonic-gate * this is the last ITD on list.
8457c478bd9Sstevel@tonic-gate */
8466aef9e11SToomas Soome Set_ITD(itd->itd_itw_next_itd, 0);
8477c478bd9Sstevel@tonic-gate
8487c478bd9Sstevel@tonic-gate if (itw->itw_itd_head == NULL) {
8497c478bd9Sstevel@tonic-gate ASSERT(itw->itw_itd_tail == NULL);
8507c478bd9Sstevel@tonic-gate itw->itw_itd_head = itd;
8517c478bd9Sstevel@tonic-gate itw->itw_itd_tail = itd;
8527c478bd9Sstevel@tonic-gate } else {
8537c478bd9Sstevel@tonic-gate ehci_itd_t *dummy = (ehci_itd_t *)itw->itw_itd_tail;
8547c478bd9Sstevel@tonic-gate
8557c478bd9Sstevel@tonic-gate ASSERT(dummy != NULL);
8567c478bd9Sstevel@tonic-gate ASSERT(Get_ITD(itd->itd_state) == EHCI_ITD_ACTIVE);
8577c478bd9Sstevel@tonic-gate
8587c478bd9Sstevel@tonic-gate /* Add the itd to the end of the list */
8597c478bd9Sstevel@tonic-gate Set_ITD(dummy->itd_itw_next_itd,
8607c478bd9Sstevel@tonic-gate ehci_itd_cpu_to_iommu(ehcip, itd));
8617c478bd9Sstevel@tonic-gate
8627c478bd9Sstevel@tonic-gate itw->itw_itd_tail = itd;
8637c478bd9Sstevel@tonic-gate }
8647c478bd9Sstevel@tonic-gate
8657c478bd9Sstevel@tonic-gate Set_ITD(itd->itd_trans_wrapper, (uint32_t)itw->itw_id);
8667c478bd9Sstevel@tonic-gate }
8677c478bd9Sstevel@tonic-gate
8687c478bd9Sstevel@tonic-gate
8697c478bd9Sstevel@tonic-gate /*
8707c478bd9Sstevel@tonic-gate * ehci_insert_itd_into_active_list:
8717c478bd9Sstevel@tonic-gate *
8727c478bd9Sstevel@tonic-gate * Add current ITD into the active ITD list in reverse order.
87348bbca81SDaniel Hoffman * When the done list is created, remove it in the reverse order.
8747c478bd9Sstevel@tonic-gate */
8757c478bd9Sstevel@tonic-gate void
ehci_insert_itd_into_active_list(ehci_state_t * ehcip,ehci_itd_t * itd)8767c478bd9Sstevel@tonic-gate ehci_insert_itd_into_active_list(
8777c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
8787c478bd9Sstevel@tonic-gate ehci_itd_t *itd)
8797c478bd9Sstevel@tonic-gate {
8807c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex));
8817c478bd9Sstevel@tonic-gate ASSERT(itd != NULL);
8827c478bd9Sstevel@tonic-gate
8837c478bd9Sstevel@tonic-gate Set_ITD(itd->itd_next_active_itd,
8847c478bd9Sstevel@tonic-gate ehci_itd_cpu_to_iommu(ehcip, ehcip->ehci_active_itd_list));
8857c478bd9Sstevel@tonic-gate ehcip->ehci_active_itd_list = itd;
8867c478bd9Sstevel@tonic-gate }
8877c478bd9Sstevel@tonic-gate
8887c478bd9Sstevel@tonic-gate
8897c478bd9Sstevel@tonic-gate /*
8907c478bd9Sstevel@tonic-gate * ehci_remove_itd_from_active_list:
8917c478bd9Sstevel@tonic-gate *
8927c478bd9Sstevel@tonic-gate * Remove current ITD from the active ITD list.
8937c478bd9Sstevel@tonic-gate */
8947c478bd9Sstevel@tonic-gate void
ehci_remove_itd_from_active_list(ehci_state_t * ehcip,ehci_itd_t * itd)8957c478bd9Sstevel@tonic-gate ehci_remove_itd_from_active_list(
8967c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
8977c478bd9Sstevel@tonic-gate ehci_itd_t *itd)
8987c478bd9Sstevel@tonic-gate {
8997c478bd9Sstevel@tonic-gate ehci_itd_t *curr_itd, *next_itd;
9007c478bd9Sstevel@tonic-gate
9017c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex));
9027c478bd9Sstevel@tonic-gate ASSERT(itd != NULL);
9037c478bd9Sstevel@tonic-gate
904b3001defSlg USB_DPRINTF_L4(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
905b3001defSlg "ehci_remove_itd_from_active_list: "
906b3001defSlg "ehci_active_itd_list = 0x%p itd = 0x%p",
907112116d8Sfb (void *)ehcip->ehci_active_itd_list, (void *)itd);
908b3001defSlg
9097c478bd9Sstevel@tonic-gate curr_itd = ehcip->ehci_active_itd_list;
9107c478bd9Sstevel@tonic-gate
9117c478bd9Sstevel@tonic-gate if (curr_itd == itd) {
9127c478bd9Sstevel@tonic-gate ehcip->ehci_active_itd_list =
9137c478bd9Sstevel@tonic-gate ehci_itd_iommu_to_cpu(ehcip, itd->itd_next_active_itd);
9146aef9e11SToomas Soome itd->itd_next_active_itd = 0;
9157c478bd9Sstevel@tonic-gate
9167c478bd9Sstevel@tonic-gate return;
9177c478bd9Sstevel@tonic-gate }
9187c478bd9Sstevel@tonic-gate
9197c478bd9Sstevel@tonic-gate next_itd = ehci_itd_iommu_to_cpu(ehcip, curr_itd->itd_next_active_itd);
9207c478bd9Sstevel@tonic-gate while (next_itd != itd) {
9217c478bd9Sstevel@tonic-gate curr_itd = next_itd;
9227c478bd9Sstevel@tonic-gate if (curr_itd) {
9237c478bd9Sstevel@tonic-gate next_itd = ehci_itd_iommu_to_cpu(ehcip,
9247c478bd9Sstevel@tonic-gate curr_itd->itd_next_active_itd);
9257c478bd9Sstevel@tonic-gate } else {
9267c478bd9Sstevel@tonic-gate break;
9277c478bd9Sstevel@tonic-gate }
9287c478bd9Sstevel@tonic-gate }
9297c478bd9Sstevel@tonic-gate
9307c478bd9Sstevel@tonic-gate if ((curr_itd) && (next_itd == itd)) {
9317c478bd9Sstevel@tonic-gate Set_ITD(curr_itd->itd_next_active_itd,
9327c478bd9Sstevel@tonic-gate Get_ITD(itd->itd_next_active_itd));
9336aef9e11SToomas Soome Set_ITD(itd->itd_next_active_itd, 0);
9347c478bd9Sstevel@tonic-gate } else {
9357c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
9367c478bd9Sstevel@tonic-gate "ehci_remove_itd_from_active_list: "
9370a05e705Slc "Unable to find ITD in active_itd_list");
9387c478bd9Sstevel@tonic-gate }
9397c478bd9Sstevel@tonic-gate }
9407c478bd9Sstevel@tonic-gate
9417c478bd9Sstevel@tonic-gate
9427c478bd9Sstevel@tonic-gate /*
9437c478bd9Sstevel@tonic-gate * ehci_create_done_itd_list:
9447c478bd9Sstevel@tonic-gate *
9457c478bd9Sstevel@tonic-gate * Traverse the active list and create a done list and remove them
9467c478bd9Sstevel@tonic-gate * from the active list.
9477c478bd9Sstevel@tonic-gate */
9487c478bd9Sstevel@tonic-gate ehci_itd_t *
ehci_create_done_itd_list(ehci_state_t * ehcip)9497c478bd9Sstevel@tonic-gate ehci_create_done_itd_list(
9507c478bd9Sstevel@tonic-gate ehci_state_t *ehcip)
9517c478bd9Sstevel@tonic-gate {
9527c478bd9Sstevel@tonic-gate usb_frame_number_t current_frame_number;
9537c478bd9Sstevel@tonic-gate usb_frame_number_t itd_frame_number, itd_reclaim_number;
9547c478bd9Sstevel@tonic-gate ehci_itd_t *curr_itd = NULL, *next_itd = NULL;
9557c478bd9Sstevel@tonic-gate ehci_itd_t *done_itd_list = NULL;
9567c478bd9Sstevel@tonic-gate uint_t state;
9577c478bd9Sstevel@tonic-gate
9587c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_INTR, ehcip->ehci_log_hdl,
9597c478bd9Sstevel@tonic-gate "ehci_create_done_itd_list:");
9607c478bd9Sstevel@tonic-gate
9617c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex));
9627c478bd9Sstevel@tonic-gate
9637c478bd9Sstevel@tonic-gate /*
9647c478bd9Sstevel@tonic-gate * Get the current frame number.
9657c478bd9Sstevel@tonic-gate * Only process itd that were inserted before the current
9667c478bd9Sstevel@tonic-gate * frame number.
9677c478bd9Sstevel@tonic-gate */
9687c478bd9Sstevel@tonic-gate current_frame_number = ehci_get_current_frame_number(ehcip);
9697c478bd9Sstevel@tonic-gate
9707c478bd9Sstevel@tonic-gate curr_itd = ehcip->ehci_active_itd_list;
9717c478bd9Sstevel@tonic-gate
9727c478bd9Sstevel@tonic-gate while (curr_itd) {
9737c478bd9Sstevel@tonic-gate /* Get next itd from the active itd list */
9747c478bd9Sstevel@tonic-gate next_itd = ehci_itd_iommu_to_cpu(ehcip,
9757c478bd9Sstevel@tonic-gate Get_ITD(curr_itd->itd_next_active_itd));
9767c478bd9Sstevel@tonic-gate
9777c478bd9Sstevel@tonic-gate /*
9787c478bd9Sstevel@tonic-gate * If haven't past the frame number that the ITD was
9797c478bd9Sstevel@tonic-gate * suppose to be executed, don't touch it. Just in
9807c478bd9Sstevel@tonic-gate * case it is being processed by the HCD and cause
9817c478bd9Sstevel@tonic-gate * a race condition.
9827c478bd9Sstevel@tonic-gate */
9837c478bd9Sstevel@tonic-gate itd_frame_number = Get_ITD_FRAME(curr_itd->itd_frame_number);
9847c478bd9Sstevel@tonic-gate itd_reclaim_number =
9857c478bd9Sstevel@tonic-gate Get_ITD_FRAME(curr_itd->itd_reclaim_number);
9867c478bd9Sstevel@tonic-gate
9877c478bd9Sstevel@tonic-gate /* Get the ITD state */
9887c478bd9Sstevel@tonic-gate state = Get_ITD(curr_itd->itd_state);
9897c478bd9Sstevel@tonic-gate
9907c478bd9Sstevel@tonic-gate if (((state == EHCI_ITD_ACTIVE) &&
9910a05e705Slc (itd_frame_number < current_frame_number)) ||
9927c478bd9Sstevel@tonic-gate ((state == EHCI_ITD_RECLAIM) &&
9930a05e705Slc (itd_reclaim_number < current_frame_number))) {
9947c478bd9Sstevel@tonic-gate
9957c478bd9Sstevel@tonic-gate /* Remove this ITD from active ITD list */
9967c478bd9Sstevel@tonic-gate ehci_remove_itd_from_active_list(ehcip, curr_itd);
9977c478bd9Sstevel@tonic-gate
9987c478bd9Sstevel@tonic-gate /*
9997c478bd9Sstevel@tonic-gate * Create the done list in reverse order, since the
10007c478bd9Sstevel@tonic-gate * active list was also created in reverse order.
10017c478bd9Sstevel@tonic-gate */
10027c478bd9Sstevel@tonic-gate Set_ITD(curr_itd->itd_next_active_itd,
10037c478bd9Sstevel@tonic-gate ehci_itd_cpu_to_iommu(ehcip, done_itd_list));
10047c478bd9Sstevel@tonic-gate done_itd_list = curr_itd;
10057c478bd9Sstevel@tonic-gate }
10067c478bd9Sstevel@tonic-gate
10077c478bd9Sstevel@tonic-gate curr_itd = next_itd;
10087c478bd9Sstevel@tonic-gate }
10097c478bd9Sstevel@tonic-gate
10107c478bd9Sstevel@tonic-gate return (done_itd_list);
10117c478bd9Sstevel@tonic-gate }
10127c478bd9Sstevel@tonic-gate
10137c478bd9Sstevel@tonic-gate
10147c478bd9Sstevel@tonic-gate /*
10157c478bd9Sstevel@tonic-gate * ehci_insert_isoc_to_pfl:
10167c478bd9Sstevel@tonic-gate *
10177c478bd9Sstevel@tonic-gate * Insert a ITD request into the Host Controller's isochronous list.
10187c478bd9Sstevel@tonic-gate * All the ITDs in the ITW will be added the PFL at once. Either all
10197c478bd9Sstevel@tonic-gate * of them will make it or none of them will.
10207c478bd9Sstevel@tonic-gate */
10217c478bd9Sstevel@tonic-gate int
ehci_insert_isoc_to_pfl(ehci_state_t * ehcip,ehci_pipe_private_t * pp,ehci_isoc_xwrapper_t * itw)10227c478bd9Sstevel@tonic-gate ehci_insert_isoc_to_pfl(
10237c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
10247c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp,
10257c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw)
10267c478bd9Sstevel@tonic-gate {
10277c478bd9Sstevel@tonic-gate usb_isoc_req_t *isoc_reqp = itw->itw_curr_xfer_reqp;
10287c478bd9Sstevel@tonic-gate usb_frame_number_t current_frame_number, start_frame_number;
10297c478bd9Sstevel@tonic-gate uint_t ddic, pfl_number;
10307c478bd9Sstevel@tonic-gate ehci_periodic_frame_list_t *periodic_frame_list =
10317c478bd9Sstevel@tonic-gate ehcip->ehci_periodic_frame_list_tablep;
10327c478bd9Sstevel@tonic-gate uint32_t addr, port_status;
10337c478bd9Sstevel@tonic-gate ehci_itd_t *itd;
10347c478bd9Sstevel@tonic-gate
10357c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
10367c478bd9Sstevel@tonic-gate "ehci_insert_isoc_to_pfl: "
1037b3001defSlg "isoc flags 0x%x itw = 0x%p",
1038112116d8Sfb isoc_reqp->isoc_attributes, (void *)itw);
10397c478bd9Sstevel@tonic-gate
10407c478bd9Sstevel@tonic-gate /*
10417c478bd9Sstevel@tonic-gate * Enter critical, while programming the usb frame number
10427c478bd9Sstevel@tonic-gate * and inserting current isochronous TD into the ED's list.
10437c478bd9Sstevel@tonic-gate */
10447c478bd9Sstevel@tonic-gate ddic = ddi_enter_critical();
10457c478bd9Sstevel@tonic-gate
10467c478bd9Sstevel@tonic-gate /* Get the current frame number */
10477c478bd9Sstevel@tonic-gate current_frame_number = ehci_get_current_frame_number(ehcip);
10487c478bd9Sstevel@tonic-gate
10497c478bd9Sstevel@tonic-gate /*
10507c478bd9Sstevel@tonic-gate * Check the given isochronous flags and get the frame number
10517c478bd9Sstevel@tonic-gate * to insert the itd into.
10527c478bd9Sstevel@tonic-gate */
10537c478bd9Sstevel@tonic-gate switch (isoc_reqp->isoc_attributes &
10547c478bd9Sstevel@tonic-gate (USB_ATTRS_ISOC_START_FRAME | USB_ATTRS_ISOC_XFER_ASAP)) {
10557c478bd9Sstevel@tonic-gate case USB_ATTRS_ISOC_START_FRAME:
10567c478bd9Sstevel@tonic-gate
10577c478bd9Sstevel@tonic-gate /* Starting frame number is specified */
10587c478bd9Sstevel@tonic-gate if (pp->pp_flag & EHCI_ISOC_XFER_CONTINUE) {
10597c478bd9Sstevel@tonic-gate /* Get the starting usb frame number */
10607c478bd9Sstevel@tonic-gate start_frame_number = pp->pp_next_frame_number;
10617c478bd9Sstevel@tonic-gate } else {
10627c478bd9Sstevel@tonic-gate /* Check for the Starting usb frame number */
10637c478bd9Sstevel@tonic-gate if ((isoc_reqp->isoc_frame_no == 0) ||
10647c478bd9Sstevel@tonic-gate ((isoc_reqp->isoc_frame_no +
10650a05e705Slc isoc_reqp->isoc_pkts_count) <
10660a05e705Slc current_frame_number)) {
10677c478bd9Sstevel@tonic-gate
10687c478bd9Sstevel@tonic-gate /* Exit the critical */
10697c478bd9Sstevel@tonic-gate ddi_exit_critical(ddic);
10707c478bd9Sstevel@tonic-gate
10717c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS,
10727c478bd9Sstevel@tonic-gate ehcip->ehci_log_hdl,
10737c478bd9Sstevel@tonic-gate "ehci_insert_isoc_to_pfl:"
10747c478bd9Sstevel@tonic-gate "Invalid starting frame number");
10757c478bd9Sstevel@tonic-gate
10767c478bd9Sstevel@tonic-gate return (USB_INVALID_START_FRAME);
10777c478bd9Sstevel@tonic-gate }
10787c478bd9Sstevel@tonic-gate
10797c478bd9Sstevel@tonic-gate /* Get the starting usb frame number */
10807c478bd9Sstevel@tonic-gate start_frame_number = isoc_reqp->isoc_frame_no;
10817c478bd9Sstevel@tonic-gate
10827c478bd9Sstevel@tonic-gate pp->pp_next_frame_number = 0;
10837c478bd9Sstevel@tonic-gate }
10847c478bd9Sstevel@tonic-gate break;
10857c478bd9Sstevel@tonic-gate case USB_ATTRS_ISOC_XFER_ASAP:
10867c478bd9Sstevel@tonic-gate /* ehci has to specify starting frame number */
10877c478bd9Sstevel@tonic-gate if ((pp->pp_next_frame_number) &&
10887c478bd9Sstevel@tonic-gate (pp->pp_next_frame_number > current_frame_number)) {
10897c478bd9Sstevel@tonic-gate /*
10907c478bd9Sstevel@tonic-gate * Get the next usb frame number.
10917c478bd9Sstevel@tonic-gate */
10927c478bd9Sstevel@tonic-gate start_frame_number = pp->pp_next_frame_number;
10937c478bd9Sstevel@tonic-gate } else {
10947c478bd9Sstevel@tonic-gate /*
10957c478bd9Sstevel@tonic-gate * Add appropriate offset to the current usb
10967c478bd9Sstevel@tonic-gate * frame number and use it as a starting frame
10977c478bd9Sstevel@tonic-gate * number.
10987c478bd9Sstevel@tonic-gate */
10997c478bd9Sstevel@tonic-gate start_frame_number =
11007c478bd9Sstevel@tonic-gate current_frame_number + EHCI_FRAME_OFFSET;
11017c478bd9Sstevel@tonic-gate }
11027c478bd9Sstevel@tonic-gate
11037c478bd9Sstevel@tonic-gate if (!(pp->pp_flag & EHCI_ISOC_XFER_CONTINUE)) {
11047c478bd9Sstevel@tonic-gate isoc_reqp->isoc_frame_no = start_frame_number;
11057c478bd9Sstevel@tonic-gate }
11067c478bd9Sstevel@tonic-gate break;
11077c478bd9Sstevel@tonic-gate default:
11087c478bd9Sstevel@tonic-gate /* Exit the critical */
11097c478bd9Sstevel@tonic-gate ddi_exit_critical(ddic);
11107c478bd9Sstevel@tonic-gate
11117c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
11127c478bd9Sstevel@tonic-gate "ehci_insert_isoc_to_pfl: Either starting "
11137c478bd9Sstevel@tonic-gate "frame number or ASAP flags are not set, attrs = 0x%x",
11147c478bd9Sstevel@tonic-gate isoc_reqp->isoc_attributes);
11157c478bd9Sstevel@tonic-gate
11167c478bd9Sstevel@tonic-gate return (USB_NO_FRAME_NUMBER);
11177c478bd9Sstevel@tonic-gate }
11187c478bd9Sstevel@tonic-gate
11197c478bd9Sstevel@tonic-gate if (itw->itw_port_status == USBA_HIGH_SPEED_DEV) {
1120b3001defSlg port_status = EHCI_ITD_LINK_REF_ITD;
11217c478bd9Sstevel@tonic-gate } else {
11227c478bd9Sstevel@tonic-gate port_status = EHCI_ITD_LINK_REF_SITD;
11237c478bd9Sstevel@tonic-gate }
11247c478bd9Sstevel@tonic-gate
11257c478bd9Sstevel@tonic-gate itd = itw->itw_itd_head;
11267c478bd9Sstevel@tonic-gate while (itd) {
11277c478bd9Sstevel@tonic-gate /* Find the appropriate frame list to put the itd into */
11287c478bd9Sstevel@tonic-gate pfl_number = start_frame_number % EHCI_NUM_PERIODIC_FRAME_LISTS;
11297c478bd9Sstevel@tonic-gate
11307c478bd9Sstevel@tonic-gate addr = Get_PFLT(periodic_frame_list->
11317c478bd9Sstevel@tonic-gate ehci_periodic_frame_list_table[pfl_number]);
11327c478bd9Sstevel@tonic-gate Set_ITD(itd->itd_link_ptr, addr);
11337c478bd9Sstevel@tonic-gate
11347c478bd9Sstevel@tonic-gate /* Set the link_ref correctly as ITD or SITD. */
11357c478bd9Sstevel@tonic-gate addr = ehci_itd_cpu_to_iommu(ehcip, itd) & EHCI_ITD_LINK_PTR;
11367c478bd9Sstevel@tonic-gate addr |= port_status;
11377c478bd9Sstevel@tonic-gate
11387c478bd9Sstevel@tonic-gate Set_PFLT(periodic_frame_list->
11397c478bd9Sstevel@tonic-gate ehci_periodic_frame_list_table[pfl_number], addr);
11407c478bd9Sstevel@tonic-gate
11417c478bd9Sstevel@tonic-gate /* Save which frame the ITD was inserted into */
11427c478bd9Sstevel@tonic-gate Set_ITD_FRAME(itd->itd_frame_number, start_frame_number);
11437c478bd9Sstevel@tonic-gate
11447c478bd9Sstevel@tonic-gate ehci_insert_itd_into_active_list(ehcip, itd);
11457c478bd9Sstevel@tonic-gate
11467c478bd9Sstevel@tonic-gate /* Get the next ITD in the ITW */
11477c478bd9Sstevel@tonic-gate itd = ehci_itd_iommu_to_cpu(ehcip,
11487c478bd9Sstevel@tonic-gate Get_ITD(itd->itd_itw_next_itd));
11497c478bd9Sstevel@tonic-gate
11507c478bd9Sstevel@tonic-gate start_frame_number++;
11517c478bd9Sstevel@tonic-gate }
11527c478bd9Sstevel@tonic-gate
11537c478bd9Sstevel@tonic-gate /* Exit the critical */
11547c478bd9Sstevel@tonic-gate ddi_exit_critical(ddic);
11557c478bd9Sstevel@tonic-gate
11567c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1157b3001defSlg "ehci_insert_isoc_to_pfl: "
11587c478bd9Sstevel@tonic-gate "current frame number 0x%llx start frame number 0x%llx num itds %d",
1159112116d8Sfb (unsigned long long)current_frame_number,
1160112116d8Sfb (unsigned long long)start_frame_number, itw->itw_num_itds);
11617c478bd9Sstevel@tonic-gate
11627c478bd9Sstevel@tonic-gate /*
11637c478bd9Sstevel@tonic-gate * Increment this saved frame number by current number
11647c478bd9Sstevel@tonic-gate * of data packets needs to be transfer.
11657c478bd9Sstevel@tonic-gate */
11667c478bd9Sstevel@tonic-gate pp->pp_next_frame_number = start_frame_number;
11677c478bd9Sstevel@tonic-gate
11687c478bd9Sstevel@tonic-gate /*
11697c478bd9Sstevel@tonic-gate * Set EHCI_ISOC_XFER_CONTINUE flag in order to send other
11707c478bd9Sstevel@tonic-gate * isochronous packets, part of the current isoch request
11717c478bd9Sstevel@tonic-gate * in the subsequent frames.
11727c478bd9Sstevel@tonic-gate */
11737c478bd9Sstevel@tonic-gate pp->pp_flag |= EHCI_ISOC_XFER_CONTINUE;
11747c478bd9Sstevel@tonic-gate
11757c478bd9Sstevel@tonic-gate return (USB_SUCCESS);
11767c478bd9Sstevel@tonic-gate }
11777c478bd9Sstevel@tonic-gate
11787c478bd9Sstevel@tonic-gate
11797c478bd9Sstevel@tonic-gate /*
11807c478bd9Sstevel@tonic-gate * ehci_remove_isoc_to_pfl:
11817c478bd9Sstevel@tonic-gate *
11827c478bd9Sstevel@tonic-gate * Remove an ITD request from the Host Controller's isochronous list.
11837c478bd9Sstevel@tonic-gate * If we can't find it, something has gone wrong.
11847c478bd9Sstevel@tonic-gate */
11857c478bd9Sstevel@tonic-gate void
ehci_remove_isoc_from_pfl(ehci_state_t * ehcip,ehci_itd_t * curr_itd)11867c478bd9Sstevel@tonic-gate ehci_remove_isoc_from_pfl(
11877c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
11887c478bd9Sstevel@tonic-gate ehci_itd_t *curr_itd)
11897c478bd9Sstevel@tonic-gate {
11907c478bd9Sstevel@tonic-gate ehci_periodic_frame_list_t *periodic_frame_list;
11917c478bd9Sstevel@tonic-gate uint_t pfl_number;
11927c478bd9Sstevel@tonic-gate uint32_t next_addr, curr_itd_addr;
11937c478bd9Sstevel@tonic-gate uint32_t link_ref;
11947c478bd9Sstevel@tonic-gate ehci_itd_t *prev_itd = NULL;
11957c478bd9Sstevel@tonic-gate
11967c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_ALLOC, ehcip->ehci_log_hdl,
11977c478bd9Sstevel@tonic-gate "ehci_remove_isoc_from_pfl:");
11987c478bd9Sstevel@tonic-gate
11997c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex));
12007c478bd9Sstevel@tonic-gate
12017c478bd9Sstevel@tonic-gate /* Get the address of the current itd */
12027c478bd9Sstevel@tonic-gate curr_itd_addr = ehci_itd_cpu_to_iommu(ehcip, curr_itd);
12037c478bd9Sstevel@tonic-gate
12047c478bd9Sstevel@tonic-gate /*
12057c478bd9Sstevel@tonic-gate * Remove this ITD from the PFL
12067c478bd9Sstevel@tonic-gate * But first we need to find it in the PFL
12077c478bd9Sstevel@tonic-gate */
12087c478bd9Sstevel@tonic-gate periodic_frame_list = ehcip->ehci_periodic_frame_list_tablep;
12097c478bd9Sstevel@tonic-gate pfl_number = Get_ITD_FRAME(curr_itd->itd_frame_number) %
12107c478bd9Sstevel@tonic-gate EHCI_NUM_PERIODIC_FRAME_LISTS;
12117c478bd9Sstevel@tonic-gate
12127c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_ALLOC, ehcip->ehci_log_hdl,
12137c478bd9Sstevel@tonic-gate "ehci_remove_isoc_from_pfl: itd = 0x%p pfl number 0x%x",
1214112116d8Sfb (void *)curr_itd, pfl_number);
12157c478bd9Sstevel@tonic-gate
12167c478bd9Sstevel@tonic-gate next_addr = Get_PFLT(periodic_frame_list->
12177c478bd9Sstevel@tonic-gate ehci_periodic_frame_list_table[pfl_number]);
12187c478bd9Sstevel@tonic-gate while ((next_addr & EHCI_ITD_LINK_PTR) !=
12197c478bd9Sstevel@tonic-gate (curr_itd_addr & EHCI_ITD_LINK_PTR)) {
12207c478bd9Sstevel@tonic-gate
12217c478bd9Sstevel@tonic-gate link_ref = next_addr & EHCI_ITD_LINK_REF;
12227c478bd9Sstevel@tonic-gate
12237c478bd9Sstevel@tonic-gate if ((link_ref == EHCI_ITD_LINK_REF_ITD) ||
12247c478bd9Sstevel@tonic-gate (link_ref == EHCI_ITD_LINK_REF_SITD)) {
12257c478bd9Sstevel@tonic-gate
12267c478bd9Sstevel@tonic-gate prev_itd = ehci_itd_iommu_to_cpu(ehcip,
12277c478bd9Sstevel@tonic-gate (next_addr & EHCI_ITD_LINK_PTR));
12287c478bd9Sstevel@tonic-gate next_addr = Get_ITD(prev_itd->itd_link_ptr);
12297c478bd9Sstevel@tonic-gate } else {
12307c478bd9Sstevel@tonic-gate
12317c478bd9Sstevel@tonic-gate break;
12327c478bd9Sstevel@tonic-gate }
12337c478bd9Sstevel@tonic-gate }
12347c478bd9Sstevel@tonic-gate
12357c478bd9Sstevel@tonic-gate /*
12367c478bd9Sstevel@tonic-gate * If the next itd is the current itd, that means we found it.
12377c478bd9Sstevel@tonic-gate * Set the previous's ITD link ptr to the Curr_ITD's link ptr.
12387c478bd9Sstevel@tonic-gate * But do not touch the Curr_ITD's link ptr.
12397c478bd9Sstevel@tonic-gate */
12407c478bd9Sstevel@tonic-gate if ((next_addr & EHCI_ITD_LINK_PTR) ==
12417c478bd9Sstevel@tonic-gate (curr_itd_addr & EHCI_ITD_LINK_PTR)) {
12427c478bd9Sstevel@tonic-gate
12437c478bd9Sstevel@tonic-gate next_addr = Get_ITD(curr_itd->itd_link_ptr);
12447c478bd9Sstevel@tonic-gate
12457c478bd9Sstevel@tonic-gate if (prev_itd == NULL) {
12467c478bd9Sstevel@tonic-gate /* This means PFL points to this ITD */
12477c478bd9Sstevel@tonic-gate Set_PFLT(periodic_frame_list->
12487c478bd9Sstevel@tonic-gate ehci_periodic_frame_list_table[pfl_number],
12497c478bd9Sstevel@tonic-gate next_addr);
12507c478bd9Sstevel@tonic-gate } else {
12517c478bd9Sstevel@tonic-gate /* Set the previous ITD's itd_link_ptr */
12527c478bd9Sstevel@tonic-gate Set_ITD(prev_itd->itd_link_ptr, next_addr);
12537c478bd9Sstevel@tonic-gate }
12547c478bd9Sstevel@tonic-gate
12557c478bd9Sstevel@tonic-gate Set_ITD_FRAME(curr_itd->itd_frame_number, 0);
12567c478bd9Sstevel@tonic-gate } else {
12577c478bd9Sstevel@tonic-gate ASSERT((next_addr & EHCI_ITD_LINK_PTR) ==
12587c478bd9Sstevel@tonic-gate (curr_itd_addr & EHCI_ITD_LINK_PTR));
12597c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_ALLOC, ehcip->ehci_log_hdl,
12607c478bd9Sstevel@tonic-gate "ehci_remove_isoc_from_pfl: Unable to find ITD in PFL");
12617c478bd9Sstevel@tonic-gate }
12627c478bd9Sstevel@tonic-gate }
12637c478bd9Sstevel@tonic-gate
12647c478bd9Sstevel@tonic-gate
12657c478bd9Sstevel@tonic-gate /*
12667c478bd9Sstevel@tonic-gate * Isochronous in resource functions
12677c478bd9Sstevel@tonic-gate */
12687c478bd9Sstevel@tonic-gate /*
12697c478bd9Sstevel@tonic-gate * ehci_allocate_periodic_in_resource
12707c478bd9Sstevel@tonic-gate *
12717c478bd9Sstevel@tonic-gate * Allocate interrupt request structure for the interrupt IN transfer.
12727c478bd9Sstevel@tonic-gate */
12737c478bd9Sstevel@tonic-gate int
ehci_allocate_isoc_in_resource(ehci_state_t * ehcip,ehci_pipe_private_t * pp,ehci_isoc_xwrapper_t * itw,usb_flags_t flags)12747c478bd9Sstevel@tonic-gate ehci_allocate_isoc_in_resource(
12757c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
12767c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp,
12777c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw,
12787c478bd9Sstevel@tonic-gate usb_flags_t flags)
12797c478bd9Sstevel@tonic-gate {
12807c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph = pp->pp_pipe_handle;
12817c478bd9Sstevel@tonic-gate usb_isoc_req_t *orig_isoc_reqp, *clone_isoc_reqp;
12827c478bd9Sstevel@tonic-gate
12837c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
12847c478bd9Sstevel@tonic-gate "ehci_allocate_isoc_in_resource:"
1285112116d8Sfb "pp = 0x%p itw = 0x%p flags = 0x%x", (void *)pp, (void *)itw,
1286112116d8Sfb flags);
12877c478bd9Sstevel@tonic-gate
12887c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex));
12897c478bd9Sstevel@tonic-gate ASSERT(itw->itw_curr_xfer_reqp == NULL);
12907c478bd9Sstevel@tonic-gate
12917c478bd9Sstevel@tonic-gate /* Get the client periodic in request pointer */
12927c478bd9Sstevel@tonic-gate orig_isoc_reqp = (usb_isoc_req_t *)(pp->pp_client_periodic_in_reqp);
12937c478bd9Sstevel@tonic-gate
12947c478bd9Sstevel@tonic-gate ASSERT(orig_isoc_reqp != NULL);
12957c478bd9Sstevel@tonic-gate
12967c478bd9Sstevel@tonic-gate clone_isoc_reqp = usba_hcdi_dup_isoc_req(ph->p_dip,
12977c478bd9Sstevel@tonic-gate orig_isoc_reqp, flags);
12987c478bd9Sstevel@tonic-gate
12997c478bd9Sstevel@tonic-gate if (clone_isoc_reqp == NULL) {
13007c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
13017c478bd9Sstevel@tonic-gate "ehci_allocate_isoc_in_resource: Isochronous"
13027c478bd9Sstevel@tonic-gate "request structure allocation failed");
13037c478bd9Sstevel@tonic-gate
13047c478bd9Sstevel@tonic-gate return (USB_NO_RESOURCES);
13057c478bd9Sstevel@tonic-gate }
13067c478bd9Sstevel@tonic-gate
13077c478bd9Sstevel@tonic-gate /*
13087c478bd9Sstevel@tonic-gate * Save the client's isochronous request pointer and
13097c478bd9Sstevel@tonic-gate * length of isochronous transfer in transfer wrapper.
13107c478bd9Sstevel@tonic-gate * The dup'ed request is saved in pp_client_periodic_in_reqp
13117c478bd9Sstevel@tonic-gate */
13127c478bd9Sstevel@tonic-gate itw->itw_curr_xfer_reqp = orig_isoc_reqp;
1313b3001defSlg
13147c478bd9Sstevel@tonic-gate pp->pp_client_periodic_in_reqp = (usb_opaque_t)clone_isoc_reqp;
13157c478bd9Sstevel@tonic-gate
13167c478bd9Sstevel@tonic-gate mutex_enter(&ph->p_mutex);
13177c478bd9Sstevel@tonic-gate ph->p_req_count++;
13187c478bd9Sstevel@tonic-gate mutex_exit(&ph->p_mutex);
13197c478bd9Sstevel@tonic-gate
13207c478bd9Sstevel@tonic-gate pp->pp_state = EHCI_PIPE_STATE_ACTIVE;
13217c478bd9Sstevel@tonic-gate
13227c478bd9Sstevel@tonic-gate return (USB_SUCCESS);
13237c478bd9Sstevel@tonic-gate }
13247c478bd9Sstevel@tonic-gate
13257c478bd9Sstevel@tonic-gate
13267c478bd9Sstevel@tonic-gate /*
13277c478bd9Sstevel@tonic-gate * ehci_deallocate_isoc_in_resource
13287c478bd9Sstevel@tonic-gate *
13297c478bd9Sstevel@tonic-gate * Deallocate interrupt request structure for the interrupt IN transfer.
13307c478bd9Sstevel@tonic-gate */
13317c478bd9Sstevel@tonic-gate void
ehci_deallocate_isoc_in_resource(ehci_state_t * ehcip,ehci_pipe_private_t * pp,ehci_isoc_xwrapper_t * itw)13327c478bd9Sstevel@tonic-gate ehci_deallocate_isoc_in_resource(
13337c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
13347c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp,
13357c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw)
13367c478bd9Sstevel@tonic-gate {
13377c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph = pp->pp_pipe_handle;
13387c478bd9Sstevel@tonic-gate uchar_t ep_attr = ph->p_ep.bmAttributes;
13397c478bd9Sstevel@tonic-gate usb_isoc_req_t *isoc_reqp;
13407c478bd9Sstevel@tonic-gate
13417c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_LISTS,
13427c478bd9Sstevel@tonic-gate ehcip->ehci_log_hdl,
13437c478bd9Sstevel@tonic-gate "ehci_deallocate_isoc_in_resource: "
1344112116d8Sfb "pp = 0x%p itw = 0x%p", (void *)pp, (void *)itw);
13457c478bd9Sstevel@tonic-gate
13467c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex));
13477c478bd9Sstevel@tonic-gate ASSERT((ep_attr & USB_EP_ATTR_MASK) == USB_EP_ATTR_ISOCH);
13487c478bd9Sstevel@tonic-gate
13497c478bd9Sstevel@tonic-gate isoc_reqp = itw->itw_curr_xfer_reqp;
13507c478bd9Sstevel@tonic-gate
13517c478bd9Sstevel@tonic-gate /* Check the current periodic in request pointer */
13527c478bd9Sstevel@tonic-gate if (isoc_reqp) {
13537c478bd9Sstevel@tonic-gate itw->itw_curr_xfer_reqp = NULL;
13547c478bd9Sstevel@tonic-gate itw->itw_curr_isoc_pktp = NULL;
13557c478bd9Sstevel@tonic-gate
13567c478bd9Sstevel@tonic-gate mutex_enter(&ph->p_mutex);
13577c478bd9Sstevel@tonic-gate ph->p_req_count--;
13587c478bd9Sstevel@tonic-gate mutex_exit(&ph->p_mutex);
13597c478bd9Sstevel@tonic-gate
13607c478bd9Sstevel@tonic-gate usb_free_isoc_req(isoc_reqp);
13617c478bd9Sstevel@tonic-gate
13627c478bd9Sstevel@tonic-gate /* Set periodic in pipe state to idle */
13637c478bd9Sstevel@tonic-gate pp->pp_state = EHCI_PIPE_STATE_IDLE;
13647c478bd9Sstevel@tonic-gate }
13657c478bd9Sstevel@tonic-gate }
13667c478bd9Sstevel@tonic-gate
13677c478bd9Sstevel@tonic-gate
13687c478bd9Sstevel@tonic-gate /*
13697c478bd9Sstevel@tonic-gate * ehci_itd_cpu_to_iommu:
13707c478bd9Sstevel@tonic-gate *
13717c478bd9Sstevel@tonic-gate * This function converts for the given Transfer Descriptor (ITD) CPU address
13727c478bd9Sstevel@tonic-gate * to IO address.
13737c478bd9Sstevel@tonic-gate */
13747c478bd9Sstevel@tonic-gate uint32_t
ehci_itd_cpu_to_iommu(ehci_state_t * ehcip,ehci_itd_t * addr)13757c478bd9Sstevel@tonic-gate ehci_itd_cpu_to_iommu(
13767c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
13777c478bd9Sstevel@tonic-gate ehci_itd_t *addr)
13787c478bd9Sstevel@tonic-gate {
13797c478bd9Sstevel@tonic-gate uint32_t td;
13807c478bd9Sstevel@tonic-gate
13817c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex));
13827c478bd9Sstevel@tonic-gate
13836aef9e11SToomas Soome if (addr == NULL)
13846aef9e11SToomas Soome return (0);
13857c478bd9Sstevel@tonic-gate
13867c478bd9Sstevel@tonic-gate td = (uint32_t)ehcip->ehci_itd_pool_cookie.dmac_address +
13877c478bd9Sstevel@tonic-gate (uint32_t)((uintptr_t)addr -
13880a05e705Slc (uintptr_t)(ehcip->ehci_itd_pool_addr));
13897c478bd9Sstevel@tonic-gate
13907c478bd9Sstevel@tonic-gate ASSERT(((uint32_t) (sizeof (ehci_itd_t) *
13910a05e705Slc (addr - ehcip->ehci_itd_pool_addr))) ==
13927c478bd9Sstevel@tonic-gate ((uint32_t)((uintptr_t)addr - (uintptr_t)
13930a05e705Slc (ehcip->ehci_itd_pool_addr))));
13947c478bd9Sstevel@tonic-gate
13957c478bd9Sstevel@tonic-gate ASSERT(td >= ehcip->ehci_itd_pool_cookie.dmac_address);
13967c478bd9Sstevel@tonic-gate ASSERT(td <= ehcip->ehci_itd_pool_cookie.dmac_address +
13977c478bd9Sstevel@tonic-gate sizeof (ehci_itd_t) * ehci_itd_pool_size);
13987c478bd9Sstevel@tonic-gate
13997c478bd9Sstevel@tonic-gate return (td);
14007c478bd9Sstevel@tonic-gate }
14017c478bd9Sstevel@tonic-gate
14027c478bd9Sstevel@tonic-gate
14037c478bd9Sstevel@tonic-gate /*
14047c478bd9Sstevel@tonic-gate * ehci_itd_iommu_to_cpu:
14057c478bd9Sstevel@tonic-gate *
14067c478bd9Sstevel@tonic-gate * This function converts for the given Transfer Descriptor (ITD) IO address
14077c478bd9Sstevel@tonic-gate * to CPU address.
14087c478bd9Sstevel@tonic-gate */
14097c478bd9Sstevel@tonic-gate ehci_itd_t *
ehci_itd_iommu_to_cpu(ehci_state_t * ehcip,uintptr_t addr)14107c478bd9Sstevel@tonic-gate ehci_itd_iommu_to_cpu(
14117c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
14127c478bd9Sstevel@tonic-gate uintptr_t addr)
14137c478bd9Sstevel@tonic-gate {
14147c478bd9Sstevel@tonic-gate ehci_itd_t *itd;
14157c478bd9Sstevel@tonic-gate
14167c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex));
14177c478bd9Sstevel@tonic-gate
14186aef9e11SToomas Soome if (addr == 0)
14197c478bd9Sstevel@tonic-gate return (NULL);
14207c478bd9Sstevel@tonic-gate
14217c478bd9Sstevel@tonic-gate itd = (ehci_itd_t *)((uintptr_t)
14227c478bd9Sstevel@tonic-gate (addr - ehcip->ehci_itd_pool_cookie.dmac_address) +
14237c478bd9Sstevel@tonic-gate (uintptr_t)ehcip->ehci_itd_pool_addr);
14247c478bd9Sstevel@tonic-gate
14257c478bd9Sstevel@tonic-gate ASSERT(itd >= ehcip->ehci_itd_pool_addr);
14267c478bd9Sstevel@tonic-gate ASSERT((uintptr_t)itd <= (uintptr_t)ehcip->ehci_itd_pool_addr +
14277c478bd9Sstevel@tonic-gate (uintptr_t)(sizeof (ehci_itd_t) * ehci_itd_pool_size));
14287c478bd9Sstevel@tonic-gate
14297c478bd9Sstevel@tonic-gate return (itd);
14307c478bd9Sstevel@tonic-gate }
14317c478bd9Sstevel@tonic-gate
14327c478bd9Sstevel@tonic-gate
14337c478bd9Sstevel@tonic-gate /*
14347c478bd9Sstevel@tonic-gate * Error parsing functions
14357c478bd9Sstevel@tonic-gate */
ehci_parse_isoc_error(ehci_state_t * ehcip,ehci_isoc_xwrapper_t * itw,ehci_itd_t * itd)14367c478bd9Sstevel@tonic-gate void ehci_parse_isoc_error(
14377c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
14387c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw,
1439b3001defSlg ehci_itd_t *itd)
1440b3001defSlg {
14417c478bd9Sstevel@tonic-gate usb_isoc_req_t *isoc_reqp;
14420a05e705Slc usb_cr_t error;
14437c478bd9Sstevel@tonic-gate
14447c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex));
14457c478bd9Sstevel@tonic-gate
14467c478bd9Sstevel@tonic-gate isoc_reqp = itw->itw_curr_xfer_reqp;
14477c478bd9Sstevel@tonic-gate
14487c478bd9Sstevel@tonic-gate if (itw->itw_port_status == USBA_HIGH_SPEED_DEV) {
14497c478bd9Sstevel@tonic-gate error = ehci_parse_itd_error(ehcip, itw, itd);
14507c478bd9Sstevel@tonic-gate } else {
14517c478bd9Sstevel@tonic-gate error = ehci_parse_sitd_error(ehcip, itw, itd);
14527c478bd9Sstevel@tonic-gate
14530a05e705Slc if (error != USB_CR_OK) {
14540a05e705Slc isoc_reqp->isoc_error_count++;
14550a05e705Slc
14560a05e705Slc USB_DPRINTF_L2(PRINT_MASK_INTR, ehcip->ehci_log_hdl,
14570a05e705Slc "ehci_parse_sitd_error: Error %d Device Address %d"
14580a05e705Slc " Endpoint number %d", error, itw->itw_device_addr,
14590a05e705Slc itw->itw_endpoint_num);
14600a05e705Slc }
14617c478bd9Sstevel@tonic-gate
14627c478bd9Sstevel@tonic-gate }
14637c478bd9Sstevel@tonic-gate }
14647c478bd9Sstevel@tonic-gate
14657c478bd9Sstevel@tonic-gate
14667c478bd9Sstevel@tonic-gate /* ARGSUSED */
ehci_parse_itd_error(ehci_state_t * ehcip,ehci_isoc_xwrapper_t * itw,ehci_itd_t * itd)14677c478bd9Sstevel@tonic-gate static usb_cr_t ehci_parse_itd_error(
14687c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
14697c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw,
1470b3001defSlg ehci_itd_t *itd)
1471b3001defSlg {
1472b3001defSlg uint32_t status, index;
14730a05e705Slc usb_cr_t error = USB_CR_OK;
1474b3001defSlg uint32_t i;
14750a05e705Slc usb_isoc_req_t *isoc_reqp;
14760a05e705Slc
14770a05e705Slc isoc_reqp = itw->itw_curr_xfer_reqp;
1478b3001defSlg
1479b3001defSlg for (i = 0; i < EHCI_ITD_CTRL_LIST_SIZE; i++) {
1480b3001defSlg index = Get_ITD_INDEX(itd, i);
1481b3001defSlg if (index == 0xffffffff) {
1482b3001defSlg
1483b3001defSlg continue;
1484b3001defSlg }
1485b3001defSlg
14860a05e705Slc error = USB_CR_OK;
14870a05e705Slc
1488b3001defSlg status = Get_ITD_BODY(itd, EHCI_ITD_CTRL0 + i) &
1489b3001defSlg EHCI_ITD_XFER_STATUS_MASK;
1490b3001defSlg
1491b3001defSlg if (status & EHCI_ITD_XFER_DATA_BUFFER_ERR) {
1492b3001defSlg if (itw->itw_direction == USB_EP_DIR_OUT) {
14930a05e705Slc USB_DPRINTF_L3(PRINT_MASK_INTR,
14940a05e705Slc ehcip->ehci_log_hdl,
14950a05e705Slc "ehci_parse_itd_error: BUFFER Underrun");
1496b3001defSlg
14970a05e705Slc error = USB_CR_BUFFER_UNDERRUN;
1498b3001defSlg } else {
14990a05e705Slc USB_DPRINTF_L3(PRINT_MASK_INTR,
15000a05e705Slc ehcip->ehci_log_hdl,
15010a05e705Slc "ehci_parse_itd_error: BUFFER Overrun");
1502b3001defSlg
15030a05e705Slc error = USB_CR_BUFFER_OVERRUN;
1504b3001defSlg }
1505b3001defSlg }
1506b3001defSlg
1507b3001defSlg if (status & EHCI_ITD_XFER_BABBLE) {
1508b3001defSlg USB_DPRINTF_L3(PRINT_MASK_INTR, ehcip->ehci_log_hdl,
1509b3001defSlg "ehci_parse_itd_error: BABBLE DETECTED");
1510b3001defSlg
1511b3001defSlg error = USB_CR_DATA_OVERRUN;
1512b3001defSlg }
15137c478bd9Sstevel@tonic-gate
1514b3001defSlg if (status & EHCI_ITD_XFER_ERROR) {
1515b3001defSlg USB_DPRINTF_L3(PRINT_MASK_INTR, ehcip->ehci_log_hdl,
1516b3001defSlg "ehci_parse_itd_error: XACT ERROR");
1517b3001defSlg
1518b3001defSlg error = USB_CR_DEV_NOT_RESP;
1519b3001defSlg }
1520b3001defSlg
1521b3001defSlg if (status & EHCI_ITD_XFER_ACTIVE) {
1522b3001defSlg USB_DPRINTF_L3(PRINT_MASK_INTR, ehcip->ehci_log_hdl,
1523b3001defSlg "ehci_parse_itd_error: NOT ACCESSED");
1524b3001defSlg
1525b3001defSlg error = USB_CR_NOT_ACCESSED;
1526b3001defSlg }
1527b3001defSlg
1528b3001defSlg itw->itw_curr_isoc_pktp->isoc_pkt_actual_length = 0;
1529b3001defSlg
1530b3001defSlg /* Write the status of isoc data packet */
1531b3001defSlg itw->itw_curr_isoc_pktp->isoc_pkt_status = error;
1532b3001defSlg
15330a05e705Slc /* counts total number of error packets in this req */
15340a05e705Slc if (error != USB_CR_OK) {
15350a05e705Slc isoc_reqp->isoc_error_count++;
15360a05e705Slc USB_DPRINTF_L3(PRINT_MASK_INTR, ehcip->ehci_log_hdl,
15370a05e705Slc "ehci_parse_itd_error: Error %d Device Address %d "
15380a05e705Slc "Endpoint number %d", error, itw->itw_device_addr,
15390a05e705Slc itw->itw_endpoint_num);
15400a05e705Slc }
15410a05e705Slc
1542b3001defSlg itw->itw_curr_isoc_pktp++;
1543b3001defSlg }
15440a05e705Slc
1545b3001defSlg return (error);
15467c478bd9Sstevel@tonic-gate }
15477c478bd9Sstevel@tonic-gate
ehci_parse_sitd_error(ehci_state_t * ehcip,ehci_isoc_xwrapper_t * itw,ehci_itd_t * itd)15487c478bd9Sstevel@tonic-gate static usb_cr_t ehci_parse_sitd_error(
15497c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
15507c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw,
1551b3001defSlg ehci_itd_t *itd)
1552b3001defSlg {
15537c478bd9Sstevel@tonic-gate uint32_t status;
15540a05e705Slc usb_cr_t error;
15557c478bd9Sstevel@tonic-gate usb_isoc_pkt_descr_t *isoc_pkt_descr;
15567c478bd9Sstevel@tonic-gate uint32_t residue;
15577c478bd9Sstevel@tonic-gate
15587c478bd9Sstevel@tonic-gate isoc_pkt_descr = itw->itw_curr_isoc_pktp;
15597c478bd9Sstevel@tonic-gate
15607c478bd9Sstevel@tonic-gate status = Get_ITD_BODY(itd, EHCI_SITD_XFER_STATE) &
15617c478bd9Sstevel@tonic-gate EHCI_SITD_XFER_STATUS_MASK;
15627c478bd9Sstevel@tonic-gate
15637c478bd9Sstevel@tonic-gate switch (status) {
15647c478bd9Sstevel@tonic-gate case EHCI_SITD_XFER_ACTIVE:
15657c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_INTR, ehcip->ehci_log_hdl,
15667c478bd9Sstevel@tonic-gate "ehci_check_for_sitd_error: NOT ACCESSED");
15677c478bd9Sstevel@tonic-gate error = USB_CR_NOT_ACCESSED;
15687c478bd9Sstevel@tonic-gate
15697c478bd9Sstevel@tonic-gate break;
15707c478bd9Sstevel@tonic-gate case EHCI_SITD_XFER_ERROR:
15717c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_INTR, ehcip->ehci_log_hdl,
15727c478bd9Sstevel@tonic-gate "ehci_check_for_sitd_error: TT ERROR");
15737c478bd9Sstevel@tonic-gate
15747c478bd9Sstevel@tonic-gate error = USB_CR_UNSPECIFIED_ERR;
15757c478bd9Sstevel@tonic-gate
15767c478bd9Sstevel@tonic-gate break;
15777c478bd9Sstevel@tonic-gate case EHCI_SITD_XFER_DATA_BUFFER_ERR:
15787c478bd9Sstevel@tonic-gate if (itw->itw_direction == USB_EP_DIR_OUT) {
15797c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_INTR, ehcip->ehci_log_hdl,
15807c478bd9Sstevel@tonic-gate "ehci_check_for_sitd_error: BUFFER Underrun");
15817c478bd9Sstevel@tonic-gate error = USB_CR_BUFFER_UNDERRUN;
15827c478bd9Sstevel@tonic-gate } else {
15837c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_INTR, ehcip->ehci_log_hdl,
15847c478bd9Sstevel@tonic-gate "ehci_check_for_sitd_error: BUFFER Overrun");
15857c478bd9Sstevel@tonic-gate error = USB_CR_BUFFER_OVERRUN;
15867c478bd9Sstevel@tonic-gate }
15877c478bd9Sstevel@tonic-gate
15887c478bd9Sstevel@tonic-gate break;
15897c478bd9Sstevel@tonic-gate case EHCI_SITD_XFER_BABBLE:
15907c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_INTR, ehcip->ehci_log_hdl,
15917c478bd9Sstevel@tonic-gate "ehci_check_for_sitd_error: BABBLE");
15927c478bd9Sstevel@tonic-gate error = USB_CR_DATA_OVERRUN;
15937c478bd9Sstevel@tonic-gate
15947c478bd9Sstevel@tonic-gate break;
15957c478bd9Sstevel@tonic-gate case EHCI_SITD_XFER_XACT_ERROR:
15967c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_INTR, ehcip->ehci_log_hdl,
15977c478bd9Sstevel@tonic-gate "ehci_check_for_sitd_error: XACT ERROR");
15987c478bd9Sstevel@tonic-gate
15997c478bd9Sstevel@tonic-gate error = USB_CR_DEV_NOT_RESP;
16007c478bd9Sstevel@tonic-gate break;
16017c478bd9Sstevel@tonic-gate case EHCI_SITD_XFER_MISSED_UFRAME:
16027c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_INTR, ehcip->ehci_log_hdl,
16037c478bd9Sstevel@tonic-gate "ehci_check_for_sitd_error: MISSED UFRAME");
16047c478bd9Sstevel@tonic-gate
16057c478bd9Sstevel@tonic-gate error = USB_CR_NOT_ACCESSED;
16067c478bd9Sstevel@tonic-gate break;
16077c478bd9Sstevel@tonic-gate default:
16087c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_INTR, ehcip->ehci_log_hdl,
16097c478bd9Sstevel@tonic-gate "ehci_check_for_sitd_error: NO ERROR");
16107c478bd9Sstevel@tonic-gate error = USB_CR_OK;
16117c478bd9Sstevel@tonic-gate
16127c478bd9Sstevel@tonic-gate break;
16137c478bd9Sstevel@tonic-gate }
16147c478bd9Sstevel@tonic-gate
16157c478bd9Sstevel@tonic-gate /* This is HCD specific and may not have this information */
16167c478bd9Sstevel@tonic-gate residue =
16177c478bd9Sstevel@tonic-gate (Get_ITD_BODY(itd, EHCI_SITD_XFER_STATE) &
16180a05e705Slc EHCI_SITD_XFER_TOTAL_MASK) >>
16197c478bd9Sstevel@tonic-gate EHCI_SITD_XFER_TOTAL_SHIFT;
16207c478bd9Sstevel@tonic-gate
16217c478bd9Sstevel@tonic-gate /*
16227c478bd9Sstevel@tonic-gate * Subtract the residue from the isoc_pkt_descr that
16237c478bd9Sstevel@tonic-gate * was set when this ITD was inserted.
16247c478bd9Sstevel@tonic-gate */
16257c478bd9Sstevel@tonic-gate isoc_pkt_descr->isoc_pkt_actual_length -= residue;
16267c478bd9Sstevel@tonic-gate
1627b3001defSlg /* Write the status of isoc data packet */
1628b3001defSlg isoc_pkt_descr->isoc_pkt_status = error;
1629b3001defSlg
1630b3001defSlg itw->itw_curr_isoc_pktp++;
1631b3001defSlg
16327c478bd9Sstevel@tonic-gate return (error);
16337c478bd9Sstevel@tonic-gate }
16347c478bd9Sstevel@tonic-gate
16357c478bd9Sstevel@tonic-gate
16367c478bd9Sstevel@tonic-gate /*
16377c478bd9Sstevel@tonic-gate * debug print functions
16387c478bd9Sstevel@tonic-gate */
16397c478bd9Sstevel@tonic-gate void
ehci_print_itd(ehci_state_t * ehcip,ehci_itd_t * itd)16407c478bd9Sstevel@tonic-gate ehci_print_itd(
16417c478bd9Sstevel@tonic-gate ehci_state_t *ehcip,
16427c478bd9Sstevel@tonic-gate ehci_itd_t *itd)
16437c478bd9Sstevel@tonic-gate {
16447c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
16457c478bd9Sstevel@tonic-gate "ehci_print_itd: itd = 0x%p", (void *)itd);
16467c478bd9Sstevel@tonic-gate
16477c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
16487c478bd9Sstevel@tonic-gate "\titd_link_ptr: 0x%x ", Get_ITD(itd->itd_link_ptr));
16497c478bd9Sstevel@tonic-gate
1650b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1651b3001defSlg "\titd_ctrl0: 0x%x ",
1652b3001defSlg Get_ITD(itd->itd_body[EHCI_ITD_CTRL0]));
1653b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1654b3001defSlg "\titd_ctrl1: 0x%x ",
1655b3001defSlg Get_ITD(itd->itd_body[EHCI_ITD_CTRL1]));
1656b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1657b3001defSlg "\titd_ctrl2: 0x%x ",
1658b3001defSlg Get_ITD(itd->itd_body[EHCI_ITD_CTRL2]));
1659b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1660b3001defSlg "\titd_ctrl3: 0x%x ",
1661b3001defSlg Get_ITD(itd->itd_body[EHCI_ITD_CTRL3]));
1662b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1663b3001defSlg "\titd_ctrl4: 0x%x ",
1664b3001defSlg Get_ITD(itd->itd_body[EHCI_ITD_CTRL4]));
1665b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1666b3001defSlg "\titd_ctrl5: 0x%x ",
1667b3001defSlg Get_ITD(itd->itd_body[EHCI_ITD_CTRL5]));
1668b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1669b3001defSlg "\titd_ctrl6: 0x%x ",
1670b3001defSlg Get_ITD(itd->itd_body[EHCI_ITD_CTRL6]));
1671b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1672b3001defSlg "\titd_ctrl7: 0x%x ",
1673b3001defSlg Get_ITD(itd->itd_body[EHCI_ITD_CTRL7]));
1674b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1675b3001defSlg "\titd_buffer0: 0x%x ",
1676b3001defSlg Get_ITD(itd->itd_body[EHCI_ITD_BUFFER0]));
1677b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1678b3001defSlg "\titd_buffer1: 0x%x ",
1679b3001defSlg Get_ITD(itd->itd_body[EHCI_ITD_BUFFER1]));
1680b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1681b3001defSlg "\titd_buffer2: 0x%x ",
1682b3001defSlg Get_ITD(itd->itd_body[EHCI_ITD_BUFFER2]));
1683b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1684b3001defSlg "\titd_buffer3: 0x%x ",
1685b3001defSlg Get_ITD(itd->itd_body[EHCI_ITD_BUFFER3]));
1686b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1687b3001defSlg "\titd_buffer4: 0x%x ",
1688b3001defSlg Get_ITD(itd->itd_body[EHCI_ITD_BUFFER4]));
1689b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1690b3001defSlg "\titd_buffer5: 0x%x ",
1691b3001defSlg Get_ITD(itd->itd_body[EHCI_ITD_BUFFER5]));
1692b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1693b3001defSlg "\titd_buffer6: 0x%x ",
1694b3001defSlg Get_ITD(itd->itd_body[EHCI_ITD_BUFFER6]));
1695b3001defSlg
1696b3001defSlg /* HCD private fields */
1697b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1698b3001defSlg "\titd_trans_wrapper: 0x%x ",
1699b3001defSlg Get_ITD(itd->itd_trans_wrapper));
1700b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1701b3001defSlg "\titd_itw_next_itd: 0x%x ",
1702b3001defSlg Get_ITD(itd->itd_itw_next_itd));
1703b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1704b3001defSlg "\titd_state: 0x%x ",
1705b3001defSlg Get_ITD(itd->itd_state));
1706b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1707b3001defSlg "\titd_index: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x ",
1708b3001defSlg Get_ITD_INDEX(itd, 0), Get_ITD_INDEX(itd, 1),
1709b3001defSlg Get_ITD_INDEX(itd, 2), Get_ITD_INDEX(itd, 3),
1710b3001defSlg Get_ITD_INDEX(itd, 4), Get_ITD_INDEX(itd, 5),
1711b3001defSlg Get_ITD_INDEX(itd, 6), Get_ITD_INDEX(itd, 7));
1712b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1713b3001defSlg "\titd_frame_number: 0x%x ",
1714b3001defSlg Get_ITD(itd->itd_frame_number));
1715b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1716b3001defSlg "\titd_reclaim_number: 0x%x ",
1717b3001defSlg Get_ITD(itd->itd_reclaim_number));
1718b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1719b3001defSlg "\titd_next_active_itd: 0x%x ",
1720b3001defSlg Get_ITD(itd->itd_next_active_itd));
1721b3001defSlg }
1722b3001defSlg
1723b3001defSlg
1724b3001defSlg void
ehci_print_sitd(ehci_state_t * ehcip,ehci_itd_t * itd)1725b3001defSlg ehci_print_sitd(
1726b3001defSlg ehci_state_t *ehcip,
1727b3001defSlg ehci_itd_t *itd)
1728b3001defSlg {
1729b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1730b3001defSlg "ehci_print_itd: itd = 0x%p", (void *)itd);
1731b3001defSlg
1732b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1733b3001defSlg "\titd_link_ptr: 0x%x ", Get_ITD(itd->itd_link_ptr));
1734b3001defSlg
1735b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1736b3001defSlg "\tsitd_ctrl: 0x%x ",
1737b3001defSlg Get_ITD(itd->itd_body[EHCI_SITD_CTRL]));
1738b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1739b3001defSlg "\tsitd_uframe_sched: 0x%x ",
1740b3001defSlg Get_ITD(itd->itd_body[EHCI_SITD_UFRAME_SCHED]));
1741b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1742b3001defSlg "\tsitd_xfer_state: 0x%x ",
1743b3001defSlg Get_ITD(itd->itd_body[EHCI_SITD_XFER_STATE]));
1744b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1745b3001defSlg "\tsitd_buffer0: 0x%x ",
1746b3001defSlg Get_ITD(itd->itd_body[EHCI_SITD_BUFFER0]));
1747b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1748b3001defSlg "\tsitd_buffer1: 0x%x ",
1749b3001defSlg Get_ITD(itd->itd_body[EHCI_SITD_BUFFER1]));
1750b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
1751b3001defSlg "\tsitd_prev_sitd: 0x%x ",
1752b3001defSlg Get_ITD(itd->itd_body[EHCI_SITD_PREV_SITD]));
17537c478bd9Sstevel@tonic-gate
17547c478bd9Sstevel@tonic-gate /* HCD private fields */
17557c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
17567c478bd9Sstevel@tonic-gate "\titd_trans_wrapper: 0x%x ",
17577c478bd9Sstevel@tonic-gate Get_ITD(itd->itd_trans_wrapper));
17587c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
17597c478bd9Sstevel@tonic-gate "\titd_itw_next_itd: 0x%x ",
17607c478bd9Sstevel@tonic-gate Get_ITD(itd->itd_itw_next_itd));
17617c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
17627c478bd9Sstevel@tonic-gate "\titd_state: 0x%x ",
17637c478bd9Sstevel@tonic-gate Get_ITD(itd->itd_state));
17647c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
17657c478bd9Sstevel@tonic-gate "\titd_frame_number: 0x%x ",
17667c478bd9Sstevel@tonic-gate Get_ITD(itd->itd_frame_number));
17677c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
17687c478bd9Sstevel@tonic-gate "\titd_reclaim_number: 0x%x ",
17697c478bd9Sstevel@tonic-gate Get_ITD(itd->itd_reclaim_number));
17707c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
17717c478bd9Sstevel@tonic-gate "\titd_next_active_itd: 0x%x ",
17727c478bd9Sstevel@tonic-gate Get_ITD(itd->itd_next_active_itd));
17737c478bd9Sstevel@tonic-gate }
1774