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 */ 217c478bd9Sstevel@tonic-gate /* 22*112116d8Sfb * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate /* 297c478bd9Sstevel@tonic-gate * EHCI Host Controller Driver (EHCI) 307c478bd9Sstevel@tonic-gate * 317c478bd9Sstevel@tonic-gate * The EHCI driver is a software driver which interfaces to the Universal 327c478bd9Sstevel@tonic-gate * Serial Bus layer (USBA) and the Host Controller (HC). The interface to 337c478bd9Sstevel@tonic-gate * the Host Controller is defined by the EHCI Host Controller Interface. 347c478bd9Sstevel@tonic-gate * 357c478bd9Sstevel@tonic-gate * This module contains the EHCI driver isochronous code, which handles all 367c478bd9Sstevel@tonic-gate * Checking of status of USB transfers, error recovery and callbacks. 377c478bd9Sstevel@tonic-gate */ 387c478bd9Sstevel@tonic-gate #include <sys/usb/hcd/ehci/ehcid.h> 397c478bd9Sstevel@tonic-gate #include <sys/usb/hcd/ehci/ehci_xfer.h> 407c478bd9Sstevel@tonic-gate #include <sys/usb/hcd/ehci/ehci_util.h> 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate /* Adjustable variables for the size of isoc pools */ 437c478bd9Sstevel@tonic-gate int ehci_itd_pool_size = EHCI_ITD_POOL_SIZE; 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate /* 467c478bd9Sstevel@tonic-gate * pool functions 477c478bd9Sstevel@tonic-gate */ 487c478bd9Sstevel@tonic-gate int ehci_allocate_isoc_pools( 497c478bd9Sstevel@tonic-gate ehci_state_t *ehcip); 507c478bd9Sstevel@tonic-gate int ehci_get_itd_pool_size(); 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate /* 537c478bd9Sstevel@tonic-gate * Isochronous Transfer Wrapper Functions 547c478bd9Sstevel@tonic-gate */ 557c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *ehci_allocate_itw_resources( 560a05e705Slc ehci_state_t *ehcip, 577c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp, 587c478bd9Sstevel@tonic-gate size_t itw_length, 597c478bd9Sstevel@tonic-gate usb_flags_t usb_flags, 600a05e705Slc size_t pkt_count); 617c478bd9Sstevel@tonic-gate static ehci_isoc_xwrapper_t *ehci_allocate_itw( 627c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 637c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp, 647c478bd9Sstevel@tonic-gate size_t length, 657c478bd9Sstevel@tonic-gate usb_flags_t usb_flags); 667c478bd9Sstevel@tonic-gate void ehci_deallocate_itw( 677c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 687c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp, 697c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw); 707c478bd9Sstevel@tonic-gate static void ehci_free_itw_dma( 717c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 727c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp, 737c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw); 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate /* 767c478bd9Sstevel@tonic-gate * transfer descriptor functions 777c478bd9Sstevel@tonic-gate */ 787c478bd9Sstevel@tonic-gate static ehci_itd_t *ehci_allocate_itd( 797c478bd9Sstevel@tonic-gate ehci_state_t *ehcip); 807c478bd9Sstevel@tonic-gate void ehci_deallocate_itd( 817c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 827c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw, 837c478bd9Sstevel@tonic-gate ehci_itd_t *old_itd); 847c478bd9Sstevel@tonic-gate uint_t ehci_calc_num_itds( 857c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw, 860a05e705Slc size_t pkt_count); 877c478bd9Sstevel@tonic-gate int ehci_allocate_itds_for_itw( 887c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 897c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw, 907c478bd9Sstevel@tonic-gate uint_t itd_count); 917c478bd9Sstevel@tonic-gate static void ehci_deallocate_itds_for_itw( 927c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 937c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw); 947c478bd9Sstevel@tonic-gate void ehci_insert_itd_on_itw( 957c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 967c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw, 977c478bd9Sstevel@tonic-gate ehci_itd_t *itd); 987c478bd9Sstevel@tonic-gate void ehci_insert_itd_into_active_list( 997c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 1007c478bd9Sstevel@tonic-gate ehci_itd_t *itd); 1017c478bd9Sstevel@tonic-gate void ehci_remove_itd_from_active_list( 1027c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 1037c478bd9Sstevel@tonic-gate ehci_itd_t *itd); 1047c478bd9Sstevel@tonic-gate ehci_itd_t *ehci_create_done_itd_list( 1057c478bd9Sstevel@tonic-gate ehci_state_t *ehcip); 1067c478bd9Sstevel@tonic-gate int ehci_insert_isoc_to_pfl( 1077c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 1087c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp, 1097c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw); 1107c478bd9Sstevel@tonic-gate void ehci_remove_isoc_from_pfl( 1117c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 1127c478bd9Sstevel@tonic-gate ehci_itd_t *curr_itd); 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate /* 1167c478bd9Sstevel@tonic-gate * Isochronous in resource functions 1177c478bd9Sstevel@tonic-gate */ 1187c478bd9Sstevel@tonic-gate int ehci_allocate_isoc_in_resource( 1197c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 1207c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp, 1217c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *tw, 1227c478bd9Sstevel@tonic-gate usb_flags_t flags); 1237c478bd9Sstevel@tonic-gate void ehci_deallocate_isoc_in_resource( 1247c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 1257c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp, 1267c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw); 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate /* 1297c478bd9Sstevel@tonic-gate * memory addr functions 1307c478bd9Sstevel@tonic-gate */ 1317c478bd9Sstevel@tonic-gate uint32_t ehci_itd_cpu_to_iommu( 1327c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 1337c478bd9Sstevel@tonic-gate ehci_itd_t *addr); 1347c478bd9Sstevel@tonic-gate ehci_itd_t *ehci_itd_iommu_to_cpu( 1357c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 1367c478bd9Sstevel@tonic-gate uintptr_t addr); 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate /* 1397c478bd9Sstevel@tonic-gate * Error parsing functions 1407c478bd9Sstevel@tonic-gate */ 1417c478bd9Sstevel@tonic-gate void ehci_parse_isoc_error( 1427c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 1437c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw, 1447c478bd9Sstevel@tonic-gate ehci_itd_t *itd); 1457c478bd9Sstevel@tonic-gate static usb_cr_t ehci_parse_itd_error( 1467c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 1477c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw, 1487c478bd9Sstevel@tonic-gate ehci_itd_t *itd); 1497c478bd9Sstevel@tonic-gate static usb_cr_t ehci_parse_sitd_error( 1507c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 1517c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw, 1527c478bd9Sstevel@tonic-gate ehci_itd_t *itd); 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate /* 1557c478bd9Sstevel@tonic-gate * print functions 1567c478bd9Sstevel@tonic-gate */ 1577c478bd9Sstevel@tonic-gate void ehci_print_itd( 1587c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 1597c478bd9Sstevel@tonic-gate ehci_itd_t *itd); 160b3001defSlg void ehci_print_sitd( 161b3001defSlg ehci_state_t *ehcip, 162b3001defSlg ehci_itd_t *itd); 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate /* 1667c478bd9Sstevel@tonic-gate * ehci_allocate_isoc_pools: 1677c478bd9Sstevel@tonic-gate * 1687c478bd9Sstevel@tonic-gate * Allocate the system memory for itd which are for low/full/high speed 1697c478bd9Sstevel@tonic-gate * Transfer Descriptors. Must be aligned to a 32 byte boundary. 1707c478bd9Sstevel@tonic-gate */ 1717c478bd9Sstevel@tonic-gate int 1727c478bd9Sstevel@tonic-gate ehci_allocate_isoc_pools(ehci_state_t *ehcip) 1737c478bd9Sstevel@tonic-gate { 1747c478bd9Sstevel@tonic-gate ddi_device_acc_attr_t dev_attr; 1757c478bd9Sstevel@tonic-gate size_t real_length; 1767c478bd9Sstevel@tonic-gate int result; 1777c478bd9Sstevel@tonic-gate uint_t ccount; 1787c478bd9Sstevel@tonic-gate int i; 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_ATTA, ehcip->ehci_log_hdl, 1817c478bd9Sstevel@tonic-gate "ehci_allocate_isoc_pools:"); 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate /* Byte alignment */ 1847c478bd9Sstevel@tonic-gate ehcip->ehci_dma_attr.dma_attr_align = EHCI_DMA_ATTR_TD_QH_ALIGNMENT; 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate /* Allocate the itd pool DMA handle */ 1877c478bd9Sstevel@tonic-gate result = ddi_dma_alloc_handle(ehcip->ehci_dip, 1887c478bd9Sstevel@tonic-gate &ehcip->ehci_dma_attr, 1897c478bd9Sstevel@tonic-gate DDI_DMA_SLEEP, 1907c478bd9Sstevel@tonic-gate 0, 1917c478bd9Sstevel@tonic-gate &ehcip->ehci_itd_pool_dma_handle); 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) { 1947c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, ehcip->ehci_log_hdl, 1957c478bd9Sstevel@tonic-gate "ehci_allocate_isoc_pools: Alloc handle failed"); 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 1987c478bd9Sstevel@tonic-gate } 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate /* The host controller will be little endian */ 2017c478bd9Sstevel@tonic-gate dev_attr.devacc_attr_version = DDI_DEVICE_ATTR_V0; 2027c478bd9Sstevel@tonic-gate dev_attr.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC; 2037c478bd9Sstevel@tonic-gate dev_attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC; 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate /* Allocate the memory */ 2067c478bd9Sstevel@tonic-gate result = ddi_dma_mem_alloc(ehcip->ehci_itd_pool_dma_handle, 2077c478bd9Sstevel@tonic-gate ehci_itd_pool_size * sizeof (ehci_itd_t), 2087c478bd9Sstevel@tonic-gate &dev_attr, 2097c478bd9Sstevel@tonic-gate DDI_DMA_CONSISTENT, 2107c478bd9Sstevel@tonic-gate DDI_DMA_SLEEP, 2117c478bd9Sstevel@tonic-gate 0, 2127c478bd9Sstevel@tonic-gate (caddr_t *)&ehcip->ehci_itd_pool_addr, 2137c478bd9Sstevel@tonic-gate &real_length, 2147c478bd9Sstevel@tonic-gate &ehcip->ehci_itd_pool_mem_handle); 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) { 2177c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, ehcip->ehci_log_hdl, 2187c478bd9Sstevel@tonic-gate "ehci_allocate_isoc_pools: Alloc memory failed"); 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2217c478bd9Sstevel@tonic-gate } 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate /* Map the ITD pool into the I/O address space */ 2247c478bd9Sstevel@tonic-gate result = ddi_dma_addr_bind_handle( 2250a05e705Slc ehcip->ehci_itd_pool_dma_handle, 2260a05e705Slc NULL, 2270a05e705Slc (caddr_t)ehcip->ehci_itd_pool_addr, 2280a05e705Slc real_length, 2290a05e705Slc DDI_DMA_RDWR | DDI_DMA_CONSISTENT, 2300a05e705Slc DDI_DMA_SLEEP, 2310a05e705Slc NULL, 2320a05e705Slc &ehcip->ehci_itd_pool_cookie, 2330a05e705Slc &ccount); 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate bzero((void *)ehcip->ehci_itd_pool_addr, 2360a05e705Slc ehci_itd_pool_size * sizeof (ehci_itd_t)); 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate /* Process the result */ 2397c478bd9Sstevel@tonic-gate if (result == DDI_DMA_MAPPED) { 2407c478bd9Sstevel@tonic-gate /* The cookie count should be 1 */ 2417c478bd9Sstevel@tonic-gate if (ccount != 1) { 2427c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_ATTA, ehcip->ehci_log_hdl, 2437c478bd9Sstevel@tonic-gate "ehci_allocate_isoc_pools: More than 1 cookie"); 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2467c478bd9Sstevel@tonic-gate } 2477c478bd9Sstevel@tonic-gate } else { 2487c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_ATTA, ehcip->ehci_log_hdl, 2497c478bd9Sstevel@tonic-gate "ehci_allocate_isoc_pools: Result = %d", result); 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate ehci_decode_ddi_dma_addr_bind_handle_result(ehcip, result); 2527c478bd9Sstevel@tonic-gate 2537c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2547c478bd9Sstevel@tonic-gate } 2557c478bd9Sstevel@tonic-gate 2567c478bd9Sstevel@tonic-gate /* 2577c478bd9Sstevel@tonic-gate * DMA addresses for ITD pools are bound 2587c478bd9Sstevel@tonic-gate */ 2597c478bd9Sstevel@tonic-gate ehcip->ehci_dma_addr_bind_flag |= EHCI_ITD_POOL_BOUND; 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate /* Initialize the ITD pool */ 2627c478bd9Sstevel@tonic-gate for (i = 0; i < ehci_itd_pool_size; i++) { 2637c478bd9Sstevel@tonic-gate Set_ITD(ehcip->ehci_itd_pool_addr[i].itd_state, 2647c478bd9Sstevel@tonic-gate EHCI_ITD_FREE); 2657c478bd9Sstevel@tonic-gate } 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 2687c478bd9Sstevel@tonic-gate } 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate int 2727c478bd9Sstevel@tonic-gate ehci_get_itd_pool_size() 2737c478bd9Sstevel@tonic-gate { 2747c478bd9Sstevel@tonic-gate return (ehci_itd_pool_size); 2757c478bd9Sstevel@tonic-gate } 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate /* 2797c478bd9Sstevel@tonic-gate * Isochronous Transfer Wrapper Functions 2807c478bd9Sstevel@tonic-gate */ 2817c478bd9Sstevel@tonic-gate /* 282b3001defSlg * ehci_allocate_itw_resources: 2837c478bd9Sstevel@tonic-gate * 2847c478bd9Sstevel@tonic-gate * Allocate an iTW and n iTD from the iTD buffer pool and places it into the 2857c478bd9Sstevel@tonic-gate * ITW. It does an all or nothing transaction. 2867c478bd9Sstevel@tonic-gate * 2877c478bd9Sstevel@tonic-gate * Calculates the number of iTD needed based on pipe speed. 2887c478bd9Sstevel@tonic-gate * For LOW/FULL speed devices, 1 iTD is needed for each packet. 2897c478bd9Sstevel@tonic-gate * For HIGH speed device, 1 iTD is needed for 8 to 24 packets, depending on 2907c478bd9Sstevel@tonic-gate * the multiplier for "HIGH BANDWIDTH" transfers look at 4.7 in EHCI spec. 2917c478bd9Sstevel@tonic-gate * 2927c478bd9Sstevel@tonic-gate * Returns NULL if there is insufficient resources otherwise ITW. 2937c478bd9Sstevel@tonic-gate */ 2947c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t * 2957c478bd9Sstevel@tonic-gate ehci_allocate_itw_resources( 2960a05e705Slc ehci_state_t *ehcip, 2977c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp, 2987c478bd9Sstevel@tonic-gate size_t itw_length, 2997c478bd9Sstevel@tonic-gate usb_flags_t usb_flags, 3000a05e705Slc size_t pkt_count) 3017c478bd9Sstevel@tonic-gate { 3027c478bd9Sstevel@tonic-gate uint_t itd_count; 3037c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw; 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate itw = ehci_allocate_itw(ehcip, pp, itw_length, usb_flags); 3067c478bd9Sstevel@tonic-gate 3077c478bd9Sstevel@tonic-gate if (itw == NULL) { 3087c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, ehcip->ehci_log_hdl, 3097c478bd9Sstevel@tonic-gate "ehci_allocate_itw_resources: Unable to allocate ITW"); 3107c478bd9Sstevel@tonic-gate } else { 3117c478bd9Sstevel@tonic-gate itd_count = ehci_calc_num_itds(itw, pkt_count); 312b3001defSlg USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl, 313b3001defSlg "ehci_allocate_itw_resources: itd_count = 0x%d", itd_count); 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate if (ehci_allocate_itds_for_itw(ehcip, itw, itd_count) == 3167c478bd9Sstevel@tonic-gate USB_SUCCESS) { 3177c478bd9Sstevel@tonic-gate itw->itw_num_itds = itd_count; 3187c478bd9Sstevel@tonic-gate } else { 3197c478bd9Sstevel@tonic-gate ehci_deallocate_itw(ehcip, pp, itw); 3207c478bd9Sstevel@tonic-gate itw = NULL; 3217c478bd9Sstevel@tonic-gate } 3227c478bd9Sstevel@tonic-gate } 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate return (itw); 3257c478bd9Sstevel@tonic-gate } 3267c478bd9Sstevel@tonic-gate 3277c478bd9Sstevel@tonic-gate 3287c478bd9Sstevel@tonic-gate /* 3297c478bd9Sstevel@tonic-gate * ehci_allocate_itw: 3307c478bd9Sstevel@tonic-gate * 3317c478bd9Sstevel@tonic-gate * Creates a Isochronous Transfer Wrapper (itw) and populate it with this 3327c478bd9Sstevel@tonic-gate * endpoint's data. This involves the allocation of DMA resources. 3337c478bd9Sstevel@tonic-gate * 3347c478bd9Sstevel@tonic-gate * ITW Fields not set by this function: 3357c478bd9Sstevel@tonic-gate * - will be populated itds are allocated 3367c478bd9Sstevel@tonic-gate * num_ids 3377c478bd9Sstevel@tonic-gate * itd_head 3387c478bd9Sstevel@tonic-gate * itd_tail 3397c478bd9Sstevel@tonic-gate * curr_xfer_reqp 3407c478bd9Sstevel@tonic-gate * curr_isoc_pktp 3417c478bd9Sstevel@tonic-gate * itw_itd_free_list 3427c478bd9Sstevel@tonic-gate * - Should be set by the calling function 3437c478bd9Sstevel@tonic-gate * itw_handle_callback_value 3447c478bd9Sstevel@tonic-gate */ 3457c478bd9Sstevel@tonic-gate static ehci_isoc_xwrapper_t * 3467c478bd9Sstevel@tonic-gate ehci_allocate_itw( 3477c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 3487c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp, 3497c478bd9Sstevel@tonic-gate size_t length, 3507c478bd9Sstevel@tonic-gate usb_flags_t usb_flags) 3517c478bd9Sstevel@tonic-gate { 3527c478bd9Sstevel@tonic-gate ddi_device_acc_attr_t dev_attr; 3537c478bd9Sstevel@tonic-gate int result; 3547c478bd9Sstevel@tonic-gate size_t real_length; 3557c478bd9Sstevel@tonic-gate uint_t ccount; /* Cookie count */ 3567c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph = pp->pp_pipe_handle; 3577c478bd9Sstevel@tonic-gate usba_device_t *usba_device = ph->p_usba_device; 3587c478bd9Sstevel@tonic-gate usb_ep_descr_t *endpoint = &ph->p_ep; 3597c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw; 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_LISTS, ehcip->ehci_log_hdl, 362*112116d8Sfb "ehci_allocate_itw: length = 0x%lx flags = 0x%x", 3637c478bd9Sstevel@tonic-gate length, usb_flags); 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex)); 3667c478bd9Sstevel@tonic-gate 3677c478bd9Sstevel@tonic-gate /* Allocate space for the transfer wrapper */ 3687c478bd9Sstevel@tonic-gate itw = kmem_zalloc(sizeof (ehci_isoc_xwrapper_t), KM_NOSLEEP); 3697c478bd9Sstevel@tonic-gate 3707c478bd9Sstevel@tonic-gate if (itw == NULL) { 3717c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, ehcip->ehci_log_hdl, 3727c478bd9Sstevel@tonic-gate "ehci_allocate_itw: kmem_zalloc failed"); 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate return (NULL); 3757c478bd9Sstevel@tonic-gate } 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate ehcip->ehci_dma_attr.dma_attr_align = EHCI_DMA_ATTR_ALIGNMENT; 3787c478bd9Sstevel@tonic-gate 3797c478bd9Sstevel@tonic-gate /* Allocate the DMA handle */ 3807c478bd9Sstevel@tonic-gate result = ddi_dma_alloc_handle(ehcip->ehci_dip, 3817c478bd9Sstevel@tonic-gate &ehcip->ehci_dma_attr, 3827c478bd9Sstevel@tonic-gate DDI_DMA_DONTWAIT, 3837c478bd9Sstevel@tonic-gate 0, 3847c478bd9Sstevel@tonic-gate &itw->itw_dmahandle); 3857c478bd9Sstevel@tonic-gate 3867c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) { 3877c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, ehcip->ehci_log_hdl, 3887c478bd9Sstevel@tonic-gate "ehci_create_transfer_wrapper: Alloc handle failed"); 3897c478bd9Sstevel@tonic-gate 3907c478bd9Sstevel@tonic-gate kmem_free(itw, sizeof (ehci_isoc_xwrapper_t)); 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate return (NULL); 3937c478bd9Sstevel@tonic-gate } 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate /* no need for swapping the raw data in the buffers */ 3967c478bd9Sstevel@tonic-gate dev_attr.devacc_attr_version = DDI_DEVICE_ATTR_V0; 3977c478bd9Sstevel@tonic-gate dev_attr.devacc_attr_endian_flags = DDI_NEVERSWAP_ACC; 3987c478bd9Sstevel@tonic-gate dev_attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC; 3997c478bd9Sstevel@tonic-gate 4007c478bd9Sstevel@tonic-gate /* Allocate the memory */ 4017c478bd9Sstevel@tonic-gate result = ddi_dma_mem_alloc(itw->itw_dmahandle, 4027c478bd9Sstevel@tonic-gate length, 4037c478bd9Sstevel@tonic-gate &dev_attr, 4047c478bd9Sstevel@tonic-gate DDI_DMA_CONSISTENT, 4057c478bd9Sstevel@tonic-gate DDI_DMA_DONTWAIT, 4067c478bd9Sstevel@tonic-gate NULL, 4077c478bd9Sstevel@tonic-gate (caddr_t *)&itw->itw_buf, 4087c478bd9Sstevel@tonic-gate &real_length, 4097c478bd9Sstevel@tonic-gate &itw->itw_accesshandle); 4107c478bd9Sstevel@tonic-gate 4117c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) { 4127c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, ehcip->ehci_log_hdl, 4137c478bd9Sstevel@tonic-gate "ehci_create_transfer_wrapper: dma_mem_alloc fail"); 4147c478bd9Sstevel@tonic-gate 4157c478bd9Sstevel@tonic-gate ddi_dma_free_handle(&itw->itw_dmahandle); 4167c478bd9Sstevel@tonic-gate kmem_free(itw, sizeof (ehci_isoc_xwrapper_t)); 4177c478bd9Sstevel@tonic-gate 4187c478bd9Sstevel@tonic-gate return (NULL); 4197c478bd9Sstevel@tonic-gate } 4207c478bd9Sstevel@tonic-gate 4217c478bd9Sstevel@tonic-gate ASSERT(real_length >= length); 4227c478bd9Sstevel@tonic-gate 4237c478bd9Sstevel@tonic-gate /* Bind the handle */ 4247c478bd9Sstevel@tonic-gate result = ddi_dma_addr_bind_handle(itw->itw_dmahandle, 4257c478bd9Sstevel@tonic-gate NULL, 4267c478bd9Sstevel@tonic-gate (caddr_t)itw->itw_buf, 4277c478bd9Sstevel@tonic-gate real_length, 4287c478bd9Sstevel@tonic-gate DDI_DMA_RDWR|DDI_DMA_CONSISTENT, 4297c478bd9Sstevel@tonic-gate DDI_DMA_DONTWAIT, 4307c478bd9Sstevel@tonic-gate NULL, 4317c478bd9Sstevel@tonic-gate &itw->itw_cookie, 4327c478bd9Sstevel@tonic-gate &ccount); 4337c478bd9Sstevel@tonic-gate 4347c478bd9Sstevel@tonic-gate if (result == DDI_DMA_MAPPED) { 4357c478bd9Sstevel@tonic-gate /* The cookie count should be 1 */ 4367c478bd9Sstevel@tonic-gate if (ccount != 1) { 4377c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, ehcip->ehci_log_hdl, 4387c478bd9Sstevel@tonic-gate "ehci_create_transfer_wrapper: More than 1 cookie"); 4397c478bd9Sstevel@tonic-gate 4407c478bd9Sstevel@tonic-gate result = ddi_dma_unbind_handle(itw->itw_dmahandle); 4417c478bd9Sstevel@tonic-gate ASSERT(result == DDI_SUCCESS); 4427c478bd9Sstevel@tonic-gate 4437c478bd9Sstevel@tonic-gate ddi_dma_mem_free(&itw->itw_accesshandle); 4447c478bd9Sstevel@tonic-gate ddi_dma_free_handle(&itw->itw_dmahandle); 4457c478bd9Sstevel@tonic-gate kmem_free(itw, sizeof (ehci_isoc_xwrapper_t)); 4467c478bd9Sstevel@tonic-gate 4477c478bd9Sstevel@tonic-gate return (NULL); 4487c478bd9Sstevel@tonic-gate } 4497c478bd9Sstevel@tonic-gate } else { 4507c478bd9Sstevel@tonic-gate ehci_decode_ddi_dma_addr_bind_handle_result(ehcip, result); 4517c478bd9Sstevel@tonic-gate 4527c478bd9Sstevel@tonic-gate ddi_dma_mem_free(&itw->itw_accesshandle); 4537c478bd9Sstevel@tonic-gate ddi_dma_free_handle(&itw->itw_dmahandle); 4547c478bd9Sstevel@tonic-gate kmem_free(itw, sizeof (ehci_isoc_xwrapper_t)); 4557c478bd9Sstevel@tonic-gate 4567c478bd9Sstevel@tonic-gate return (NULL); 4577c478bd9Sstevel@tonic-gate } 4587c478bd9Sstevel@tonic-gate 4597c478bd9Sstevel@tonic-gate /* Store a back pointer to the pipe private structure */ 4607c478bd9Sstevel@tonic-gate itw->itw_pipe_private = pp; 4617c478bd9Sstevel@tonic-gate if (pp->pp_itw_head == NULL) { 4627c478bd9Sstevel@tonic-gate pp->pp_itw_head = itw; 4637c478bd9Sstevel@tonic-gate pp->pp_itw_tail = itw; 4647c478bd9Sstevel@tonic-gate } else { 4657c478bd9Sstevel@tonic-gate pp->pp_itw_tail->itw_next = itw; 4667c478bd9Sstevel@tonic-gate pp->pp_itw_tail = itw; 4677c478bd9Sstevel@tonic-gate } 4687c478bd9Sstevel@tonic-gate 4697c478bd9Sstevel@tonic-gate /* 4707c478bd9Sstevel@tonic-gate * Store transfer information 4717c478bd9Sstevel@tonic-gate * itw_buf has been allocated and will be set later 4727c478bd9Sstevel@tonic-gate */ 4737c478bd9Sstevel@tonic-gate itw->itw_length = length; 4747c478bd9Sstevel@tonic-gate itw->itw_flags = usb_flags; 4757c478bd9Sstevel@tonic-gate itw->itw_port_status = usba_device->usb_port_status; 4767c478bd9Sstevel@tonic-gate itw->itw_direction = endpoint->bEndpointAddress & USB_EP_DIR_MASK; 4777c478bd9Sstevel@tonic-gate 4787c478bd9Sstevel@tonic-gate /* 4797c478bd9Sstevel@tonic-gate * Store the endpoint information that will be used by the 4807c478bd9Sstevel@tonic-gate * transfer descriptors later. 4817c478bd9Sstevel@tonic-gate */ 4827c478bd9Sstevel@tonic-gate mutex_enter(&usba_device->usb_mutex); 4837c478bd9Sstevel@tonic-gate itw->itw_hub_addr = usba_device->usb_hs_hub_addr; 4847c478bd9Sstevel@tonic-gate itw->itw_hub_port = usba_device->usb_hs_hub_port; 4857c478bd9Sstevel@tonic-gate itw->itw_endpoint_num = endpoint->bEndpointAddress & USB_EP_NUM_MASK; 4867c478bd9Sstevel@tonic-gate itw->itw_device_addr = usba_device->usb_addr; 4877c478bd9Sstevel@tonic-gate mutex_exit(&usba_device->usb_mutex); 4887c478bd9Sstevel@tonic-gate 4897c478bd9Sstevel@tonic-gate /* Get and Store 32bit ID */ 4907c478bd9Sstevel@tonic-gate itw->itw_id = EHCI_GET_ID((void *)itw); 4917c478bd9Sstevel@tonic-gate ASSERT(itw->itw_id != NULL); 4927c478bd9Sstevel@tonic-gate 493b3001defSlg USB_DPRINTF_L3(PRINT_MASK_ALLOC, ehcip->ehci_log_hdl, 494*112116d8Sfb "ehci_create_itw: itw = 0x%p real_length = 0x%lx", 495*112116d8Sfb (void *)itw, real_length); 4967c478bd9Sstevel@tonic-gate 4977c478bd9Sstevel@tonic-gate return (itw); 4987c478bd9Sstevel@tonic-gate } 4997c478bd9Sstevel@tonic-gate 5007c478bd9Sstevel@tonic-gate 5017c478bd9Sstevel@tonic-gate /* 5027c478bd9Sstevel@tonic-gate * ehci_deallocate_itw: 5037c478bd9Sstevel@tonic-gate * 5047c478bd9Sstevel@tonic-gate * Deallocate of a Isochronous Transaction Wrapper (TW) and this involves the 5057c478bd9Sstevel@tonic-gate * freeing of DMA resources. 5067c478bd9Sstevel@tonic-gate */ 5077c478bd9Sstevel@tonic-gate void 5087c478bd9Sstevel@tonic-gate ehci_deallocate_itw( 5097c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 5107c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp, 5117c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw) 5127c478bd9Sstevel@tonic-gate { 5137c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *prev, *next; 5147c478bd9Sstevel@tonic-gate 5157c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_ALLOC, ehcip->ehci_log_hdl, 516*112116d8Sfb "ehci_deallocate_itw: itw = 0x%p", (void *)itw); 5177c478bd9Sstevel@tonic-gate 5187c478bd9Sstevel@tonic-gate /* 5197c478bd9Sstevel@tonic-gate * If the transfer wrapper has no Host Controller (HC) 5207c478bd9Sstevel@tonic-gate * Transfer Descriptors (ITD) associated with it, then 5217c478bd9Sstevel@tonic-gate * remove the transfer wrapper. 5227c478bd9Sstevel@tonic-gate */ 5237c478bd9Sstevel@tonic-gate if (itw->itw_itd_head) { 5247c478bd9Sstevel@tonic-gate ASSERT(itw->itw_itd_tail != NULL); 5257c478bd9Sstevel@tonic-gate 5267c478bd9Sstevel@tonic-gate return; 5277c478bd9Sstevel@tonic-gate } 5287c478bd9Sstevel@tonic-gate 5297c478bd9Sstevel@tonic-gate ASSERT(itw->itw_itd_tail == NULL); 5307c478bd9Sstevel@tonic-gate 5317c478bd9Sstevel@tonic-gate /* Make sure we return all the unused itd's to the pool as well */ 5327c478bd9Sstevel@tonic-gate ehci_deallocate_itds_for_itw(ehcip, itw); 5337c478bd9Sstevel@tonic-gate 5347c478bd9Sstevel@tonic-gate /* 5357c478bd9Sstevel@tonic-gate * If pp->pp_tw_head and pp->pp_tw_tail are pointing to 5367c478bd9Sstevel@tonic-gate * given TW then set the head and tail equal to NULL. 5377c478bd9Sstevel@tonic-gate * Otherwise search for this TW in the linked TW's list 5387c478bd9Sstevel@tonic-gate * and then remove this TW from the list. 5397c478bd9Sstevel@tonic-gate */ 5407c478bd9Sstevel@tonic-gate if (pp->pp_itw_head == itw) { 5417c478bd9Sstevel@tonic-gate if (pp->pp_itw_tail == itw) { 5427c478bd9Sstevel@tonic-gate pp->pp_itw_head = NULL; 5437c478bd9Sstevel@tonic-gate pp->pp_itw_tail = NULL; 5447c478bd9Sstevel@tonic-gate } else { 5457c478bd9Sstevel@tonic-gate pp->pp_itw_head = itw->itw_next; 5467c478bd9Sstevel@tonic-gate } 5477c478bd9Sstevel@tonic-gate } else { 5487c478bd9Sstevel@tonic-gate prev = pp->pp_itw_head; 5497c478bd9Sstevel@tonic-gate next = prev->itw_next; 5507c478bd9Sstevel@tonic-gate 5517c478bd9Sstevel@tonic-gate while (next && (next != itw)) { 5527c478bd9Sstevel@tonic-gate prev = next; 5537c478bd9Sstevel@tonic-gate next = next->itw_next; 5547c478bd9Sstevel@tonic-gate } 5557c478bd9Sstevel@tonic-gate 5567c478bd9Sstevel@tonic-gate if (next == itw) { 5577c478bd9Sstevel@tonic-gate prev->itw_next = next->itw_next; 5587c478bd9Sstevel@tonic-gate 5597c478bd9Sstevel@tonic-gate if (pp->pp_itw_tail == itw) { 5607c478bd9Sstevel@tonic-gate pp->pp_itw_tail = prev; 5617c478bd9Sstevel@tonic-gate } 5627c478bd9Sstevel@tonic-gate } 5637c478bd9Sstevel@tonic-gate } 5647c478bd9Sstevel@tonic-gate 5657c478bd9Sstevel@tonic-gate /* Free this iTWs dma resources */ 5667c478bd9Sstevel@tonic-gate ehci_free_itw_dma(ehcip, pp, itw); 5677c478bd9Sstevel@tonic-gate } 5687c478bd9Sstevel@tonic-gate 5697c478bd9Sstevel@tonic-gate 5707c478bd9Sstevel@tonic-gate /* 5717c478bd9Sstevel@tonic-gate * ehci_free_itw_dma: 5727c478bd9Sstevel@tonic-gate * 5737c478bd9Sstevel@tonic-gate * Free the Isochronous Transfer Wrapper dma resources. 5747c478bd9Sstevel@tonic-gate */ 5757c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 5767c478bd9Sstevel@tonic-gate static void 5777c478bd9Sstevel@tonic-gate ehci_free_itw_dma( 5787c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 5797c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp, 5807c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw) 5817c478bd9Sstevel@tonic-gate { 5827c478bd9Sstevel@tonic-gate int rval; 5837c478bd9Sstevel@tonic-gate 5847c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_ALLOC, ehcip->ehci_log_hdl, 585*112116d8Sfb "ehci_free_itw_dma: itw = 0x%p", (void *)itw); 5867c478bd9Sstevel@tonic-gate 5877c478bd9Sstevel@tonic-gate ASSERT(itw != NULL); 5887c478bd9Sstevel@tonic-gate ASSERT(itw->itw_id != NULL); 5897c478bd9Sstevel@tonic-gate 5907c478bd9Sstevel@tonic-gate /* Free 32bit ID */ 5917c478bd9Sstevel@tonic-gate EHCI_FREE_ID((uint32_t)itw->itw_id); 5927c478bd9Sstevel@tonic-gate 5937c478bd9Sstevel@tonic-gate rval = ddi_dma_unbind_handle(itw->itw_dmahandle); 5947c478bd9Sstevel@tonic-gate ASSERT(rval == DDI_SUCCESS); 5957c478bd9Sstevel@tonic-gate 5967c478bd9Sstevel@tonic-gate ddi_dma_mem_free(&itw->itw_accesshandle); 5977c478bd9Sstevel@tonic-gate ddi_dma_free_handle(&itw->itw_dmahandle); 5987c478bd9Sstevel@tonic-gate 5997c478bd9Sstevel@tonic-gate /* Free transfer wrapper */ 6007c478bd9Sstevel@tonic-gate kmem_free(itw, sizeof (ehci_isoc_xwrapper_t)); 6017c478bd9Sstevel@tonic-gate } 6027c478bd9Sstevel@tonic-gate 6037c478bd9Sstevel@tonic-gate 6047c478bd9Sstevel@tonic-gate /* 6057c478bd9Sstevel@tonic-gate * transfer descriptor functions 6067c478bd9Sstevel@tonic-gate */ 6077c478bd9Sstevel@tonic-gate /* 6087c478bd9Sstevel@tonic-gate * ehci_allocate_itd: 6097c478bd9Sstevel@tonic-gate * 6107c478bd9Sstevel@tonic-gate * Allocate a Transfer Descriptor (iTD) from the iTD buffer pool. 6117c478bd9Sstevel@tonic-gate */ 6127c478bd9Sstevel@tonic-gate static ehci_itd_t * 6137c478bd9Sstevel@tonic-gate ehci_allocate_itd(ehci_state_t *ehcip) 6147c478bd9Sstevel@tonic-gate { 6157c478bd9Sstevel@tonic-gate int i, state; 6167c478bd9Sstevel@tonic-gate ehci_itd_t *itd; 6177c478bd9Sstevel@tonic-gate 6187c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex)); 6197c478bd9Sstevel@tonic-gate 6207c478bd9Sstevel@tonic-gate /* 6217c478bd9Sstevel@tonic-gate * Search for a blank Transfer Descriptor (iTD) 6227c478bd9Sstevel@tonic-gate * in the iTD buffer pool. 6237c478bd9Sstevel@tonic-gate */ 6247c478bd9Sstevel@tonic-gate for (i = 0; i < ehci_itd_pool_size; i ++) { 6257c478bd9Sstevel@tonic-gate state = Get_ITD(ehcip->ehci_itd_pool_addr[i].itd_state); 6267c478bd9Sstevel@tonic-gate if (state == EHCI_ITD_FREE) { 6277c478bd9Sstevel@tonic-gate break; 6287c478bd9Sstevel@tonic-gate } 6297c478bd9Sstevel@tonic-gate } 6307c478bd9Sstevel@tonic-gate 6317c478bd9Sstevel@tonic-gate if (i >= ehci_itd_pool_size) { 6327c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_ALLOC, ehcip->ehci_log_hdl, 6337c478bd9Sstevel@tonic-gate "ehci_allocate_itd: ITD exhausted"); 6347c478bd9Sstevel@tonic-gate 6357c478bd9Sstevel@tonic-gate return (NULL); 6367c478bd9Sstevel@tonic-gate } 6377c478bd9Sstevel@tonic-gate 6387c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_ALLOC, ehcip->ehci_log_hdl, 6397c478bd9Sstevel@tonic-gate "ehci_allocate_itd: Allocated %d", i); 6407c478bd9Sstevel@tonic-gate 6417c478bd9Sstevel@tonic-gate /* Create a new dummy for the end of the ITD list */ 6427c478bd9Sstevel@tonic-gate itd = &ehcip->ehci_itd_pool_addr[i]; 6437c478bd9Sstevel@tonic-gate 6447c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl, 6457c478bd9Sstevel@tonic-gate "ehci_allocate_itd: itd 0x%p", (void *)itd); 6467c478bd9Sstevel@tonic-gate 6477c478bd9Sstevel@tonic-gate /* Mark the newly allocated ITD as a empty */ 6487c478bd9Sstevel@tonic-gate Set_ITD(itd->itd_state, EHCI_ITD_DUMMY); 6497c478bd9Sstevel@tonic-gate 6507c478bd9Sstevel@tonic-gate return (itd); 6517c478bd9Sstevel@tonic-gate } 6527c478bd9Sstevel@tonic-gate 6537c478bd9Sstevel@tonic-gate 6547c478bd9Sstevel@tonic-gate /* 6557c478bd9Sstevel@tonic-gate * ehci_deallocate_itd: 6567c478bd9Sstevel@tonic-gate * 6577c478bd9Sstevel@tonic-gate * Deallocate a Host Controller's (HC) Transfer Descriptor (ITD). 6587c478bd9Sstevel@tonic-gate * 6597c478bd9Sstevel@tonic-gate */ 6607c478bd9Sstevel@tonic-gate void 6617c478bd9Sstevel@tonic-gate ehci_deallocate_itd( 6627c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 6637c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw, 6647c478bd9Sstevel@tonic-gate ehci_itd_t *old_itd) 6657c478bd9Sstevel@tonic-gate { 6667c478bd9Sstevel@tonic-gate ehci_itd_t *itd, *next_itd; 6677c478bd9Sstevel@tonic-gate 6687c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_ALLOC, ehcip->ehci_log_hdl, 6697c478bd9Sstevel@tonic-gate "ehci_deallocate_itd: old_itd = 0x%p", (void *)old_itd); 6707c478bd9Sstevel@tonic-gate 6717c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex)); 6727c478bd9Sstevel@tonic-gate ASSERT(Get_ITD(old_itd->itd_trans_wrapper) == itw->itw_id); 6737c478bd9Sstevel@tonic-gate 6747c478bd9Sstevel@tonic-gate /* If it has been marked RECLAIM it has already been removed */ 6757c478bd9Sstevel@tonic-gate if (Get_ITD(old_itd->itd_state) != EHCI_ITD_RECLAIM) { 6767c478bd9Sstevel@tonic-gate ehci_remove_isoc_from_pfl(ehcip, old_itd); 6777c478bd9Sstevel@tonic-gate } 6787c478bd9Sstevel@tonic-gate 6797c478bd9Sstevel@tonic-gate /* Make sure the ITD is not in the PFL */ 6807c478bd9Sstevel@tonic-gate ASSERT(Get_ITD_FRAME(old_itd->itd_frame_number) == 0); 6817c478bd9Sstevel@tonic-gate 6827c478bd9Sstevel@tonic-gate /* Remove the itd from the itw */ 6837c478bd9Sstevel@tonic-gate itd = itw->itw_itd_head; 6847c478bd9Sstevel@tonic-gate if (old_itd != itd) { 6857c478bd9Sstevel@tonic-gate next_itd = ehci_itd_iommu_to_cpu(ehcip, 6867c478bd9Sstevel@tonic-gate Get_ITD(itd->itd_itw_next_itd)); 6877c478bd9Sstevel@tonic-gate 6887c478bd9Sstevel@tonic-gate while (next_itd != old_itd) { 6897c478bd9Sstevel@tonic-gate itd = next_itd; 6907c478bd9Sstevel@tonic-gate next_itd = ehci_itd_iommu_to_cpu(ehcip, 6917c478bd9Sstevel@tonic-gate Get_ITD(itd->itd_itw_next_itd)); 6927c478bd9Sstevel@tonic-gate } 6937c478bd9Sstevel@tonic-gate 6947c478bd9Sstevel@tonic-gate Set_ITD(itd->itd_itw_next_itd, old_itd->itd_itw_next_itd); 6957c478bd9Sstevel@tonic-gate 6967c478bd9Sstevel@tonic-gate if (itd->itd_itw_next_itd == NULL) { 6977c478bd9Sstevel@tonic-gate itw->itw_itd_tail = itd; 6987c478bd9Sstevel@tonic-gate } 6997c478bd9Sstevel@tonic-gate } else { 7007c478bd9Sstevel@tonic-gate itw->itw_itd_head = ehci_itd_iommu_to_cpu( 7010a05e705Slc ehcip, Get_ITD(old_itd->itd_itw_next_itd)); 7027c478bd9Sstevel@tonic-gate 7037c478bd9Sstevel@tonic-gate if (itw->itw_itd_head == NULL) { 7047c478bd9Sstevel@tonic-gate itw->itw_itd_tail = NULL; 7057c478bd9Sstevel@tonic-gate } 7067c478bd9Sstevel@tonic-gate } 7077c478bd9Sstevel@tonic-gate 7087c478bd9Sstevel@tonic-gate bzero((char *)old_itd, sizeof (ehci_itd_t)); 7097c478bd9Sstevel@tonic-gate Set_ITD(old_itd->itd_state, EHCI_ITD_FREE); 7107c478bd9Sstevel@tonic-gate 7117c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl, 7127c478bd9Sstevel@tonic-gate "Dealloc_itd: itd 0x%p", (void *)old_itd); 7137c478bd9Sstevel@tonic-gate } 7147c478bd9Sstevel@tonic-gate 7157c478bd9Sstevel@tonic-gate 7167c478bd9Sstevel@tonic-gate /* 7177c478bd9Sstevel@tonic-gate * ehci_calc_num_itds: 7187c478bd9Sstevel@tonic-gate * 7197c478bd9Sstevel@tonic-gate * Calculates how many ITDs are needed for this request. 7207c478bd9Sstevel@tonic-gate * The calculation is based on weather it is an HIGH speed 7217c478bd9Sstevel@tonic-gate * transaction of a FULL/LOW transaction. 7227c478bd9Sstevel@tonic-gate * 7237c478bd9Sstevel@tonic-gate * For FULL/LOW transaction more itds are necessary if it 7247c478bd9Sstevel@tonic-gate * spans frames. 7257c478bd9Sstevel@tonic-gate */ 7267c478bd9Sstevel@tonic-gate uint_t 7277c478bd9Sstevel@tonic-gate ehci_calc_num_itds( 7287c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw, 7290a05e705Slc size_t pkt_count) 7307c478bd9Sstevel@tonic-gate { 7317c478bd9Sstevel@tonic-gate uint_t multiplier, itd_count; 7327c478bd9Sstevel@tonic-gate 7337c478bd9Sstevel@tonic-gate /* Allocate the appropriate isoc resources */ 7347c478bd9Sstevel@tonic-gate if (itw->itw_port_status == USBA_HIGH_SPEED_DEV) { 7357c478bd9Sstevel@tonic-gate /* Multiplier needs to be passed in somehow */ 7367c478bd9Sstevel@tonic-gate multiplier = 1 * 8; 7377c478bd9Sstevel@tonic-gate itd_count = pkt_count / multiplier; 7387c478bd9Sstevel@tonic-gate if (pkt_count % multiplier) { 7397c478bd9Sstevel@tonic-gate itd_count++; 7407c478bd9Sstevel@tonic-gate } 7417c478bd9Sstevel@tonic-gate } else { 7427c478bd9Sstevel@tonic-gate itd_count = pkt_count; 7437c478bd9Sstevel@tonic-gate } 7447c478bd9Sstevel@tonic-gate 745b3001defSlg return (itd_count); 7467c478bd9Sstevel@tonic-gate } 7477c478bd9Sstevel@tonic-gate 7487c478bd9Sstevel@tonic-gate /* 7497c478bd9Sstevel@tonic-gate * ehci_allocate_itds_for_itw: 7507c478bd9Sstevel@tonic-gate * 7517c478bd9Sstevel@tonic-gate * Allocate n Transfer Descriptors (TD) from the TD buffer pool and places it 7527c478bd9Sstevel@tonic-gate * into the TW. 7537c478bd9Sstevel@tonic-gate * 7547c478bd9Sstevel@tonic-gate * Returns USB_NO_RESOURCES if it was not able to allocate all the requested TD 7557c478bd9Sstevel@tonic-gate * otherwise USB_SUCCESS. 7567c478bd9Sstevel@tonic-gate */ 7577c478bd9Sstevel@tonic-gate int 7587c478bd9Sstevel@tonic-gate ehci_allocate_itds_for_itw( 7597c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 7607c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw, 7617c478bd9Sstevel@tonic-gate uint_t itd_count) 7627c478bd9Sstevel@tonic-gate { 7637c478bd9Sstevel@tonic-gate ehci_itd_t *itd; 7647c478bd9Sstevel@tonic-gate uint32_t itd_addr; 7657c478bd9Sstevel@tonic-gate int i; 7667c478bd9Sstevel@tonic-gate int error = USB_SUCCESS; 7677c478bd9Sstevel@tonic-gate 7687c478bd9Sstevel@tonic-gate for (i = 0; i < itd_count; i += 1) { 7697c478bd9Sstevel@tonic-gate itd = ehci_allocate_itd(ehcip); 7707c478bd9Sstevel@tonic-gate if (itd == NULL) { 7717c478bd9Sstevel@tonic-gate error = USB_NO_RESOURCES; 7727c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, ehcip->ehci_log_hdl, 7737c478bd9Sstevel@tonic-gate "ehci_allocate_itds_for_itw: " 7747c478bd9Sstevel@tonic-gate "Unable to allocate %d ITDs", 7757c478bd9Sstevel@tonic-gate itd_count); 7767c478bd9Sstevel@tonic-gate break; 7777c478bd9Sstevel@tonic-gate } 7787c478bd9Sstevel@tonic-gate if (i > 0) { 7797c478bd9Sstevel@tonic-gate itd_addr = ehci_itd_cpu_to_iommu(ehcip, 7807c478bd9Sstevel@tonic-gate itw->itw_itd_free_list); 7817c478bd9Sstevel@tonic-gate Set_ITD(itd->itd_link_ptr, itd_addr); 7827c478bd9Sstevel@tonic-gate } 783b3001defSlg Set_ITD_INDEX(itd, 0, EHCI_ITD_UNUSED_INDEX); 784b3001defSlg Set_ITD_INDEX(itd, 1, EHCI_ITD_UNUSED_INDEX); 785b3001defSlg Set_ITD_INDEX(itd, 2, EHCI_ITD_UNUSED_INDEX); 786b3001defSlg Set_ITD_INDEX(itd, 3, EHCI_ITD_UNUSED_INDEX); 787b3001defSlg Set_ITD_INDEX(itd, 4, EHCI_ITD_UNUSED_INDEX); 788b3001defSlg Set_ITD_INDEX(itd, 5, EHCI_ITD_UNUSED_INDEX); 789b3001defSlg Set_ITD_INDEX(itd, 6, EHCI_ITD_UNUSED_INDEX); 790b3001defSlg Set_ITD_INDEX(itd, 7, EHCI_ITD_UNUSED_INDEX); 7917c478bd9Sstevel@tonic-gate itw->itw_itd_free_list = itd; 7927c478bd9Sstevel@tonic-gate } 7937c478bd9Sstevel@tonic-gate 7947c478bd9Sstevel@tonic-gate return (error); 7957c478bd9Sstevel@tonic-gate } 7967c478bd9Sstevel@tonic-gate 7977c478bd9Sstevel@tonic-gate 7987c478bd9Sstevel@tonic-gate /* 7997c478bd9Sstevel@tonic-gate * ehci_deallocate_itds_for_itw: 8007c478bd9Sstevel@tonic-gate * 8017c478bd9Sstevel@tonic-gate * Free all allocated resources for Transaction Wrapper (TW). 8027c478bd9Sstevel@tonic-gate * Does not free the iTW itself. 8037c478bd9Sstevel@tonic-gate */ 8047c478bd9Sstevel@tonic-gate static void 8057c478bd9Sstevel@tonic-gate ehci_deallocate_itds_for_itw( 8067c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 8077c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw) 8087c478bd9Sstevel@tonic-gate { 8097c478bd9Sstevel@tonic-gate ehci_itd_t *itd = NULL; 8107c478bd9Sstevel@tonic-gate ehci_itd_t *temp_itd = NULL; 8117c478bd9Sstevel@tonic-gate 8127c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_ALLOC, ehcip->ehci_log_hdl, 813*112116d8Sfb "ehci_free_itw_itd_resources: itw = 0x%p", (void *)itw); 8147c478bd9Sstevel@tonic-gate 8157c478bd9Sstevel@tonic-gate itd = itw->itw_itd_free_list; 8167c478bd9Sstevel@tonic-gate while (itd != NULL) { 8177c478bd9Sstevel@tonic-gate /* Save the pointer to the next itd before destroying it */ 8187c478bd9Sstevel@tonic-gate temp_itd = ehci_itd_iommu_to_cpu(ehcip, 8197c478bd9Sstevel@tonic-gate Get_ITD(itd->itd_link_ptr)); 8207c478bd9Sstevel@tonic-gate ehci_deallocate_itd(ehcip, itw, itd); 8217c478bd9Sstevel@tonic-gate itd = temp_itd; 8227c478bd9Sstevel@tonic-gate } 8237c478bd9Sstevel@tonic-gate itw->itw_itd_free_list = NULL; 8247c478bd9Sstevel@tonic-gate } 8257c478bd9Sstevel@tonic-gate 8267c478bd9Sstevel@tonic-gate 8277c478bd9Sstevel@tonic-gate /* 8287c478bd9Sstevel@tonic-gate * ehci_insert_itd_on_itw: 8297c478bd9Sstevel@tonic-gate * 8307c478bd9Sstevel@tonic-gate * The transfer wrapper keeps a list of all Transfer Descriptors (iTD) that 8317c478bd9Sstevel@tonic-gate * are allocated for this transfer. Insert a iTD onto this list. 8327c478bd9Sstevel@tonic-gate */ 8337c478bd9Sstevel@tonic-gate void ehci_insert_itd_on_itw( 8347c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 8357c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw, 8367c478bd9Sstevel@tonic-gate ehci_itd_t *itd) 8377c478bd9Sstevel@tonic-gate { 8387c478bd9Sstevel@tonic-gate /* 8397c478bd9Sstevel@tonic-gate * Set the next pointer to NULL because 8407c478bd9Sstevel@tonic-gate * this is the last ITD on list. 8417c478bd9Sstevel@tonic-gate */ 8427c478bd9Sstevel@tonic-gate Set_ITD(itd->itd_itw_next_itd, NULL); 8437c478bd9Sstevel@tonic-gate 8447c478bd9Sstevel@tonic-gate if (itw->itw_itd_head == NULL) { 8457c478bd9Sstevel@tonic-gate ASSERT(itw->itw_itd_tail == NULL); 8467c478bd9Sstevel@tonic-gate itw->itw_itd_head = itd; 8477c478bd9Sstevel@tonic-gate itw->itw_itd_tail = itd; 8487c478bd9Sstevel@tonic-gate } else { 8497c478bd9Sstevel@tonic-gate ehci_itd_t *dummy = (ehci_itd_t *)itw->itw_itd_tail; 8507c478bd9Sstevel@tonic-gate 8517c478bd9Sstevel@tonic-gate ASSERT(dummy != NULL); 8527c478bd9Sstevel@tonic-gate ASSERT(Get_ITD(itd->itd_state) == EHCI_ITD_ACTIVE); 8537c478bd9Sstevel@tonic-gate 8547c478bd9Sstevel@tonic-gate /* Add the itd to the end of the list */ 8557c478bd9Sstevel@tonic-gate Set_ITD(dummy->itd_itw_next_itd, 8567c478bd9Sstevel@tonic-gate ehci_itd_cpu_to_iommu(ehcip, itd)); 8577c478bd9Sstevel@tonic-gate 8587c478bd9Sstevel@tonic-gate itw->itw_itd_tail = itd; 8597c478bd9Sstevel@tonic-gate } 8607c478bd9Sstevel@tonic-gate 8617c478bd9Sstevel@tonic-gate Set_ITD(itd->itd_trans_wrapper, (uint32_t)itw->itw_id); 8627c478bd9Sstevel@tonic-gate } 8637c478bd9Sstevel@tonic-gate 8647c478bd9Sstevel@tonic-gate 8657c478bd9Sstevel@tonic-gate /* 8667c478bd9Sstevel@tonic-gate * ehci_insert_itd_into_active_list: 8677c478bd9Sstevel@tonic-gate * 8687c478bd9Sstevel@tonic-gate * Add current ITD into the active ITD list in reverse order. 8697c478bd9Sstevel@tonic-gate * When he done list is created, remove it in the reverse order. 8707c478bd9Sstevel@tonic-gate */ 8717c478bd9Sstevel@tonic-gate void 8727c478bd9Sstevel@tonic-gate ehci_insert_itd_into_active_list( 8737c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 8747c478bd9Sstevel@tonic-gate ehci_itd_t *itd) 8757c478bd9Sstevel@tonic-gate { 8767c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex)); 8777c478bd9Sstevel@tonic-gate ASSERT(itd != NULL); 8787c478bd9Sstevel@tonic-gate 8797c478bd9Sstevel@tonic-gate Set_ITD(itd->itd_next_active_itd, 8807c478bd9Sstevel@tonic-gate ehci_itd_cpu_to_iommu(ehcip, ehcip->ehci_active_itd_list)); 8817c478bd9Sstevel@tonic-gate ehcip->ehci_active_itd_list = itd; 8827c478bd9Sstevel@tonic-gate } 8837c478bd9Sstevel@tonic-gate 8847c478bd9Sstevel@tonic-gate 8857c478bd9Sstevel@tonic-gate /* 8867c478bd9Sstevel@tonic-gate * ehci_remove_itd_from_active_list: 8877c478bd9Sstevel@tonic-gate * 8887c478bd9Sstevel@tonic-gate * Remove current ITD from the active ITD list. 8897c478bd9Sstevel@tonic-gate */ 8907c478bd9Sstevel@tonic-gate void 8917c478bd9Sstevel@tonic-gate ehci_remove_itd_from_active_list( 8927c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 8937c478bd9Sstevel@tonic-gate ehci_itd_t *itd) 8947c478bd9Sstevel@tonic-gate { 8957c478bd9Sstevel@tonic-gate ehci_itd_t *curr_itd, *next_itd; 8967c478bd9Sstevel@tonic-gate 8977c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex)); 8987c478bd9Sstevel@tonic-gate ASSERT(itd != NULL); 8997c478bd9Sstevel@tonic-gate 900b3001defSlg USB_DPRINTF_L4(PRINT_MASK_LISTS, ehcip->ehci_log_hdl, 901b3001defSlg "ehci_remove_itd_from_active_list: " 902b3001defSlg "ehci_active_itd_list = 0x%p itd = 0x%p", 903*112116d8Sfb (void *)ehcip->ehci_active_itd_list, (void *)itd); 904b3001defSlg 9057c478bd9Sstevel@tonic-gate curr_itd = ehcip->ehci_active_itd_list; 9067c478bd9Sstevel@tonic-gate 9077c478bd9Sstevel@tonic-gate if (curr_itd == itd) { 9087c478bd9Sstevel@tonic-gate ehcip->ehci_active_itd_list = 9097c478bd9Sstevel@tonic-gate ehci_itd_iommu_to_cpu(ehcip, itd->itd_next_active_itd); 9107c478bd9Sstevel@tonic-gate itd->itd_next_active_itd = NULL; 9117c478bd9Sstevel@tonic-gate 9127c478bd9Sstevel@tonic-gate return; 9137c478bd9Sstevel@tonic-gate } 9147c478bd9Sstevel@tonic-gate 9157c478bd9Sstevel@tonic-gate next_itd = ehci_itd_iommu_to_cpu(ehcip, curr_itd->itd_next_active_itd); 9167c478bd9Sstevel@tonic-gate while (next_itd != itd) { 9177c478bd9Sstevel@tonic-gate curr_itd = next_itd; 9187c478bd9Sstevel@tonic-gate if (curr_itd) { 9197c478bd9Sstevel@tonic-gate next_itd = ehci_itd_iommu_to_cpu(ehcip, 9207c478bd9Sstevel@tonic-gate curr_itd->itd_next_active_itd); 9217c478bd9Sstevel@tonic-gate } else { 9227c478bd9Sstevel@tonic-gate break; 9237c478bd9Sstevel@tonic-gate } 9247c478bd9Sstevel@tonic-gate } 9257c478bd9Sstevel@tonic-gate 9267c478bd9Sstevel@tonic-gate if ((curr_itd) && (next_itd == itd)) { 9277c478bd9Sstevel@tonic-gate Set_ITD(curr_itd->itd_next_active_itd, 9287c478bd9Sstevel@tonic-gate Get_ITD(itd->itd_next_active_itd)); 9297c478bd9Sstevel@tonic-gate Set_ITD(itd->itd_next_active_itd, NULL); 9307c478bd9Sstevel@tonic-gate } else { 9317c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl, 9327c478bd9Sstevel@tonic-gate "ehci_remove_itd_from_active_list: " 9330a05e705Slc "Unable to find ITD in active_itd_list"); 9347c478bd9Sstevel@tonic-gate } 9357c478bd9Sstevel@tonic-gate } 9367c478bd9Sstevel@tonic-gate 9377c478bd9Sstevel@tonic-gate 9387c478bd9Sstevel@tonic-gate /* 9397c478bd9Sstevel@tonic-gate * ehci_create_done_itd_list: 9407c478bd9Sstevel@tonic-gate * 9417c478bd9Sstevel@tonic-gate * Traverse the active list and create a done list and remove them 9427c478bd9Sstevel@tonic-gate * from the active list. 9437c478bd9Sstevel@tonic-gate */ 9447c478bd9Sstevel@tonic-gate ehci_itd_t * 9457c478bd9Sstevel@tonic-gate ehci_create_done_itd_list( 9467c478bd9Sstevel@tonic-gate ehci_state_t *ehcip) 9477c478bd9Sstevel@tonic-gate { 9487c478bd9Sstevel@tonic-gate usb_frame_number_t current_frame_number; 9497c478bd9Sstevel@tonic-gate usb_frame_number_t itd_frame_number, itd_reclaim_number; 9507c478bd9Sstevel@tonic-gate ehci_itd_t *curr_itd = NULL, *next_itd = NULL; 9517c478bd9Sstevel@tonic-gate ehci_itd_t *done_itd_list = NULL; 9527c478bd9Sstevel@tonic-gate uint_t state; 9537c478bd9Sstevel@tonic-gate 9547c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_INTR, ehcip->ehci_log_hdl, 9557c478bd9Sstevel@tonic-gate "ehci_create_done_itd_list:"); 9567c478bd9Sstevel@tonic-gate 9577c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex)); 9587c478bd9Sstevel@tonic-gate 9597c478bd9Sstevel@tonic-gate /* 9607c478bd9Sstevel@tonic-gate * Get the current frame number. 9617c478bd9Sstevel@tonic-gate * Only process itd that were inserted before the current 9627c478bd9Sstevel@tonic-gate * frame number. 9637c478bd9Sstevel@tonic-gate */ 9647c478bd9Sstevel@tonic-gate current_frame_number = ehci_get_current_frame_number(ehcip); 9657c478bd9Sstevel@tonic-gate 9667c478bd9Sstevel@tonic-gate curr_itd = ehcip->ehci_active_itd_list; 9677c478bd9Sstevel@tonic-gate 9687c478bd9Sstevel@tonic-gate while (curr_itd) { 9697c478bd9Sstevel@tonic-gate /* Get next itd from the active itd list */ 9707c478bd9Sstevel@tonic-gate next_itd = ehci_itd_iommu_to_cpu(ehcip, 9717c478bd9Sstevel@tonic-gate Get_ITD(curr_itd->itd_next_active_itd)); 9727c478bd9Sstevel@tonic-gate 9737c478bd9Sstevel@tonic-gate /* 9747c478bd9Sstevel@tonic-gate * If haven't past the frame number that the ITD was 9757c478bd9Sstevel@tonic-gate * suppose to be executed, don't touch it. Just in 9767c478bd9Sstevel@tonic-gate * case it is being processed by the HCD and cause 9777c478bd9Sstevel@tonic-gate * a race condition. 9787c478bd9Sstevel@tonic-gate */ 9797c478bd9Sstevel@tonic-gate itd_frame_number = Get_ITD_FRAME(curr_itd->itd_frame_number); 9807c478bd9Sstevel@tonic-gate itd_reclaim_number = 9817c478bd9Sstevel@tonic-gate Get_ITD_FRAME(curr_itd->itd_reclaim_number); 9827c478bd9Sstevel@tonic-gate 9837c478bd9Sstevel@tonic-gate /* Get the ITD state */ 9847c478bd9Sstevel@tonic-gate state = Get_ITD(curr_itd->itd_state); 9857c478bd9Sstevel@tonic-gate 9867c478bd9Sstevel@tonic-gate if (((state == EHCI_ITD_ACTIVE) && 9870a05e705Slc (itd_frame_number < current_frame_number)) || 9887c478bd9Sstevel@tonic-gate ((state == EHCI_ITD_RECLAIM) && 9890a05e705Slc (itd_reclaim_number < current_frame_number))) { 9907c478bd9Sstevel@tonic-gate 9917c478bd9Sstevel@tonic-gate /* Remove this ITD from active ITD list */ 9927c478bd9Sstevel@tonic-gate ehci_remove_itd_from_active_list(ehcip, curr_itd); 9937c478bd9Sstevel@tonic-gate 9947c478bd9Sstevel@tonic-gate /* 9957c478bd9Sstevel@tonic-gate * Create the done list in reverse order, since the 9967c478bd9Sstevel@tonic-gate * active list was also created in reverse order. 9977c478bd9Sstevel@tonic-gate */ 9987c478bd9Sstevel@tonic-gate Set_ITD(curr_itd->itd_next_active_itd, 9997c478bd9Sstevel@tonic-gate ehci_itd_cpu_to_iommu(ehcip, done_itd_list)); 10007c478bd9Sstevel@tonic-gate done_itd_list = curr_itd; 10017c478bd9Sstevel@tonic-gate } 10027c478bd9Sstevel@tonic-gate 10037c478bd9Sstevel@tonic-gate curr_itd = next_itd; 10047c478bd9Sstevel@tonic-gate } 10057c478bd9Sstevel@tonic-gate 10067c478bd9Sstevel@tonic-gate return (done_itd_list); 10077c478bd9Sstevel@tonic-gate } 10087c478bd9Sstevel@tonic-gate 10097c478bd9Sstevel@tonic-gate 10107c478bd9Sstevel@tonic-gate /* 10117c478bd9Sstevel@tonic-gate * ehci_insert_isoc_to_pfl: 10127c478bd9Sstevel@tonic-gate * 10137c478bd9Sstevel@tonic-gate * Insert a ITD request into the Host Controller's isochronous list. 10147c478bd9Sstevel@tonic-gate * All the ITDs in the ITW will be added the PFL at once. Either all 10157c478bd9Sstevel@tonic-gate * of them will make it or none of them will. 10167c478bd9Sstevel@tonic-gate */ 10177c478bd9Sstevel@tonic-gate int 10187c478bd9Sstevel@tonic-gate ehci_insert_isoc_to_pfl( 10197c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 10207c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp, 10217c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw) 10227c478bd9Sstevel@tonic-gate { 10237c478bd9Sstevel@tonic-gate usb_isoc_req_t *isoc_reqp = itw->itw_curr_xfer_reqp; 10247c478bd9Sstevel@tonic-gate usb_frame_number_t current_frame_number, start_frame_number; 10257c478bd9Sstevel@tonic-gate uint_t ddic, pfl_number; 10267c478bd9Sstevel@tonic-gate ehci_periodic_frame_list_t *periodic_frame_list = 10277c478bd9Sstevel@tonic-gate ehcip->ehci_periodic_frame_list_tablep; 10287c478bd9Sstevel@tonic-gate uint32_t addr, port_status; 10297c478bd9Sstevel@tonic-gate ehci_itd_t *itd; 10307c478bd9Sstevel@tonic-gate 10317c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_LISTS, ehcip->ehci_log_hdl, 10327c478bd9Sstevel@tonic-gate "ehci_insert_isoc_to_pfl: " 1033b3001defSlg "isoc flags 0x%x itw = 0x%p", 1034*112116d8Sfb isoc_reqp->isoc_attributes, (void *)itw); 10357c478bd9Sstevel@tonic-gate 10367c478bd9Sstevel@tonic-gate /* 10377c478bd9Sstevel@tonic-gate * Enter critical, while programming the usb frame number 10387c478bd9Sstevel@tonic-gate * and inserting current isochronous TD into the ED's list. 10397c478bd9Sstevel@tonic-gate */ 10407c478bd9Sstevel@tonic-gate ddic = ddi_enter_critical(); 10417c478bd9Sstevel@tonic-gate 10427c478bd9Sstevel@tonic-gate /* Get the current frame number */ 10437c478bd9Sstevel@tonic-gate current_frame_number = ehci_get_current_frame_number(ehcip); 10447c478bd9Sstevel@tonic-gate 10457c478bd9Sstevel@tonic-gate /* 10467c478bd9Sstevel@tonic-gate * Check the given isochronous flags and get the frame number 10477c478bd9Sstevel@tonic-gate * to insert the itd into. 10487c478bd9Sstevel@tonic-gate */ 10497c478bd9Sstevel@tonic-gate switch (isoc_reqp->isoc_attributes & 10507c478bd9Sstevel@tonic-gate (USB_ATTRS_ISOC_START_FRAME | USB_ATTRS_ISOC_XFER_ASAP)) { 10517c478bd9Sstevel@tonic-gate case USB_ATTRS_ISOC_START_FRAME: 10527c478bd9Sstevel@tonic-gate 10537c478bd9Sstevel@tonic-gate /* Starting frame number is specified */ 10547c478bd9Sstevel@tonic-gate if (pp->pp_flag & EHCI_ISOC_XFER_CONTINUE) { 10557c478bd9Sstevel@tonic-gate /* Get the starting usb frame number */ 10567c478bd9Sstevel@tonic-gate start_frame_number = pp->pp_next_frame_number; 10577c478bd9Sstevel@tonic-gate } else { 10587c478bd9Sstevel@tonic-gate /* Check for the Starting usb frame number */ 10597c478bd9Sstevel@tonic-gate if ((isoc_reqp->isoc_frame_no == 0) || 10607c478bd9Sstevel@tonic-gate ((isoc_reqp->isoc_frame_no + 10610a05e705Slc isoc_reqp->isoc_pkts_count) < 10620a05e705Slc current_frame_number)) { 10637c478bd9Sstevel@tonic-gate 10647c478bd9Sstevel@tonic-gate /* Exit the critical */ 10657c478bd9Sstevel@tonic-gate ddi_exit_critical(ddic); 10667c478bd9Sstevel@tonic-gate 10677c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, 10687c478bd9Sstevel@tonic-gate ehcip->ehci_log_hdl, 10697c478bd9Sstevel@tonic-gate "ehci_insert_isoc_to_pfl:" 10707c478bd9Sstevel@tonic-gate "Invalid starting frame number"); 10717c478bd9Sstevel@tonic-gate 10727c478bd9Sstevel@tonic-gate return (USB_INVALID_START_FRAME); 10737c478bd9Sstevel@tonic-gate } 10747c478bd9Sstevel@tonic-gate 10757c478bd9Sstevel@tonic-gate /* Get the starting usb frame number */ 10767c478bd9Sstevel@tonic-gate start_frame_number = isoc_reqp->isoc_frame_no; 10777c478bd9Sstevel@tonic-gate 10787c478bd9Sstevel@tonic-gate pp->pp_next_frame_number = 0; 10797c478bd9Sstevel@tonic-gate } 10807c478bd9Sstevel@tonic-gate break; 10817c478bd9Sstevel@tonic-gate case USB_ATTRS_ISOC_XFER_ASAP: 10827c478bd9Sstevel@tonic-gate /* ehci has to specify starting frame number */ 10837c478bd9Sstevel@tonic-gate if ((pp->pp_next_frame_number) && 10847c478bd9Sstevel@tonic-gate (pp->pp_next_frame_number > current_frame_number)) { 10857c478bd9Sstevel@tonic-gate /* 10867c478bd9Sstevel@tonic-gate * Get the next usb frame number. 10877c478bd9Sstevel@tonic-gate */ 10887c478bd9Sstevel@tonic-gate start_frame_number = pp->pp_next_frame_number; 10897c478bd9Sstevel@tonic-gate } else { 10907c478bd9Sstevel@tonic-gate /* 10917c478bd9Sstevel@tonic-gate * Add appropriate offset to the current usb 10927c478bd9Sstevel@tonic-gate * frame number and use it as a starting frame 10937c478bd9Sstevel@tonic-gate * number. 10947c478bd9Sstevel@tonic-gate */ 10957c478bd9Sstevel@tonic-gate start_frame_number = 10967c478bd9Sstevel@tonic-gate current_frame_number + EHCI_FRAME_OFFSET; 10977c478bd9Sstevel@tonic-gate } 10987c478bd9Sstevel@tonic-gate 10997c478bd9Sstevel@tonic-gate if (!(pp->pp_flag & EHCI_ISOC_XFER_CONTINUE)) { 11007c478bd9Sstevel@tonic-gate isoc_reqp->isoc_frame_no = start_frame_number; 11017c478bd9Sstevel@tonic-gate } 11027c478bd9Sstevel@tonic-gate break; 11037c478bd9Sstevel@tonic-gate default: 11047c478bd9Sstevel@tonic-gate /* Exit the critical */ 11057c478bd9Sstevel@tonic-gate ddi_exit_critical(ddic); 11067c478bd9Sstevel@tonic-gate 11077c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, ehcip->ehci_log_hdl, 11087c478bd9Sstevel@tonic-gate "ehci_insert_isoc_to_pfl: Either starting " 11097c478bd9Sstevel@tonic-gate "frame number or ASAP flags are not set, attrs = 0x%x", 11107c478bd9Sstevel@tonic-gate isoc_reqp->isoc_attributes); 11117c478bd9Sstevel@tonic-gate 11127c478bd9Sstevel@tonic-gate return (USB_NO_FRAME_NUMBER); 11137c478bd9Sstevel@tonic-gate } 11147c478bd9Sstevel@tonic-gate 11157c478bd9Sstevel@tonic-gate if (itw->itw_port_status == USBA_HIGH_SPEED_DEV) { 1116b3001defSlg port_status = EHCI_ITD_LINK_REF_ITD; 11177c478bd9Sstevel@tonic-gate } else { 11187c478bd9Sstevel@tonic-gate port_status = EHCI_ITD_LINK_REF_SITD; 11197c478bd9Sstevel@tonic-gate } 11207c478bd9Sstevel@tonic-gate 11217c478bd9Sstevel@tonic-gate itd = itw->itw_itd_head; 11227c478bd9Sstevel@tonic-gate while (itd) { 11237c478bd9Sstevel@tonic-gate /* Find the appropriate frame list to put the itd into */ 11247c478bd9Sstevel@tonic-gate pfl_number = start_frame_number % EHCI_NUM_PERIODIC_FRAME_LISTS; 11257c478bd9Sstevel@tonic-gate 11267c478bd9Sstevel@tonic-gate addr = Get_PFLT(periodic_frame_list-> 11277c478bd9Sstevel@tonic-gate ehci_periodic_frame_list_table[pfl_number]); 11287c478bd9Sstevel@tonic-gate Set_ITD(itd->itd_link_ptr, addr); 11297c478bd9Sstevel@tonic-gate 11307c478bd9Sstevel@tonic-gate /* Set the link_ref correctly as ITD or SITD. */ 11317c478bd9Sstevel@tonic-gate addr = ehci_itd_cpu_to_iommu(ehcip, itd) & EHCI_ITD_LINK_PTR; 11327c478bd9Sstevel@tonic-gate addr |= port_status; 11337c478bd9Sstevel@tonic-gate 11347c478bd9Sstevel@tonic-gate Set_PFLT(periodic_frame_list-> 11357c478bd9Sstevel@tonic-gate ehci_periodic_frame_list_table[pfl_number], addr); 11367c478bd9Sstevel@tonic-gate 11377c478bd9Sstevel@tonic-gate /* Save which frame the ITD was inserted into */ 11387c478bd9Sstevel@tonic-gate Set_ITD_FRAME(itd->itd_frame_number, start_frame_number); 11397c478bd9Sstevel@tonic-gate 11407c478bd9Sstevel@tonic-gate ehci_insert_itd_into_active_list(ehcip, itd); 11417c478bd9Sstevel@tonic-gate 11427c478bd9Sstevel@tonic-gate /* Get the next ITD in the ITW */ 11437c478bd9Sstevel@tonic-gate itd = ehci_itd_iommu_to_cpu(ehcip, 11447c478bd9Sstevel@tonic-gate Get_ITD(itd->itd_itw_next_itd)); 11457c478bd9Sstevel@tonic-gate 11467c478bd9Sstevel@tonic-gate start_frame_number++; 11477c478bd9Sstevel@tonic-gate } 11487c478bd9Sstevel@tonic-gate 11497c478bd9Sstevel@tonic-gate /* Exit the critical */ 11507c478bd9Sstevel@tonic-gate ddi_exit_critical(ddic); 11517c478bd9Sstevel@tonic-gate 11527c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_LISTS, ehcip->ehci_log_hdl, 1153b3001defSlg "ehci_insert_isoc_to_pfl: " 11547c478bd9Sstevel@tonic-gate "current frame number 0x%llx start frame number 0x%llx num itds %d", 1155*112116d8Sfb (unsigned long long)current_frame_number, 1156*112116d8Sfb (unsigned long long)start_frame_number, itw->itw_num_itds); 11577c478bd9Sstevel@tonic-gate 11587c478bd9Sstevel@tonic-gate /* 11597c478bd9Sstevel@tonic-gate * Increment this saved frame number by current number 11607c478bd9Sstevel@tonic-gate * of data packets needs to be transfer. 11617c478bd9Sstevel@tonic-gate */ 11627c478bd9Sstevel@tonic-gate pp->pp_next_frame_number = start_frame_number; 11637c478bd9Sstevel@tonic-gate 11647c478bd9Sstevel@tonic-gate /* 11657c478bd9Sstevel@tonic-gate * Set EHCI_ISOC_XFER_CONTINUE flag in order to send other 11667c478bd9Sstevel@tonic-gate * isochronous packets, part of the current isoch request 11677c478bd9Sstevel@tonic-gate * in the subsequent frames. 11687c478bd9Sstevel@tonic-gate */ 11697c478bd9Sstevel@tonic-gate pp->pp_flag |= EHCI_ISOC_XFER_CONTINUE; 11707c478bd9Sstevel@tonic-gate 11717c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 11727c478bd9Sstevel@tonic-gate } 11737c478bd9Sstevel@tonic-gate 11747c478bd9Sstevel@tonic-gate 11757c478bd9Sstevel@tonic-gate /* 11767c478bd9Sstevel@tonic-gate * ehci_remove_isoc_to_pfl: 11777c478bd9Sstevel@tonic-gate * 11787c478bd9Sstevel@tonic-gate * Remove an ITD request from the Host Controller's isochronous list. 11797c478bd9Sstevel@tonic-gate * If we can't find it, something has gone wrong. 11807c478bd9Sstevel@tonic-gate */ 11817c478bd9Sstevel@tonic-gate void 11827c478bd9Sstevel@tonic-gate ehci_remove_isoc_from_pfl( 11837c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 11847c478bd9Sstevel@tonic-gate ehci_itd_t *curr_itd) 11857c478bd9Sstevel@tonic-gate { 11867c478bd9Sstevel@tonic-gate ehci_periodic_frame_list_t *periodic_frame_list; 11877c478bd9Sstevel@tonic-gate uint_t pfl_number; 11887c478bd9Sstevel@tonic-gate uint32_t next_addr, curr_itd_addr; 11897c478bd9Sstevel@tonic-gate uint32_t link_ref; 11907c478bd9Sstevel@tonic-gate ehci_itd_t *prev_itd = NULL; 11917c478bd9Sstevel@tonic-gate 11927c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_ALLOC, ehcip->ehci_log_hdl, 11937c478bd9Sstevel@tonic-gate "ehci_remove_isoc_from_pfl:"); 11947c478bd9Sstevel@tonic-gate 11957c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex)); 11967c478bd9Sstevel@tonic-gate 11977c478bd9Sstevel@tonic-gate /* Get the address of the current itd */ 11987c478bd9Sstevel@tonic-gate curr_itd_addr = ehci_itd_cpu_to_iommu(ehcip, curr_itd); 11997c478bd9Sstevel@tonic-gate 12007c478bd9Sstevel@tonic-gate /* 12017c478bd9Sstevel@tonic-gate * Remove this ITD from the PFL 12027c478bd9Sstevel@tonic-gate * But first we need to find it in the PFL 12037c478bd9Sstevel@tonic-gate */ 12047c478bd9Sstevel@tonic-gate periodic_frame_list = ehcip->ehci_periodic_frame_list_tablep; 12057c478bd9Sstevel@tonic-gate pfl_number = Get_ITD_FRAME(curr_itd->itd_frame_number) % 12067c478bd9Sstevel@tonic-gate EHCI_NUM_PERIODIC_FRAME_LISTS; 12077c478bd9Sstevel@tonic-gate 12087c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_ALLOC, ehcip->ehci_log_hdl, 12097c478bd9Sstevel@tonic-gate "ehci_remove_isoc_from_pfl: itd = 0x%p pfl number 0x%x", 1210*112116d8Sfb (void *)curr_itd, pfl_number); 12117c478bd9Sstevel@tonic-gate 12127c478bd9Sstevel@tonic-gate next_addr = Get_PFLT(periodic_frame_list-> 12137c478bd9Sstevel@tonic-gate ehci_periodic_frame_list_table[pfl_number]); 12147c478bd9Sstevel@tonic-gate while ((next_addr & EHCI_ITD_LINK_PTR) != 12157c478bd9Sstevel@tonic-gate (curr_itd_addr & EHCI_ITD_LINK_PTR)) { 12167c478bd9Sstevel@tonic-gate 12177c478bd9Sstevel@tonic-gate link_ref = next_addr & EHCI_ITD_LINK_REF; 12187c478bd9Sstevel@tonic-gate 12197c478bd9Sstevel@tonic-gate if ((link_ref == EHCI_ITD_LINK_REF_ITD) || 12207c478bd9Sstevel@tonic-gate (link_ref == EHCI_ITD_LINK_REF_SITD)) { 12217c478bd9Sstevel@tonic-gate 12227c478bd9Sstevel@tonic-gate prev_itd = ehci_itd_iommu_to_cpu(ehcip, 12237c478bd9Sstevel@tonic-gate (next_addr & EHCI_ITD_LINK_PTR)); 12247c478bd9Sstevel@tonic-gate next_addr = Get_ITD(prev_itd->itd_link_ptr); 12257c478bd9Sstevel@tonic-gate } else { 12267c478bd9Sstevel@tonic-gate 12277c478bd9Sstevel@tonic-gate break; 12287c478bd9Sstevel@tonic-gate } 12297c478bd9Sstevel@tonic-gate } 12307c478bd9Sstevel@tonic-gate 12317c478bd9Sstevel@tonic-gate /* 12327c478bd9Sstevel@tonic-gate * If the next itd is the current itd, that means we found it. 12337c478bd9Sstevel@tonic-gate * Set the previous's ITD link ptr to the Curr_ITD's link ptr. 12347c478bd9Sstevel@tonic-gate * But do not touch the Curr_ITD's link ptr. 12357c478bd9Sstevel@tonic-gate */ 12367c478bd9Sstevel@tonic-gate if ((next_addr & EHCI_ITD_LINK_PTR) == 12377c478bd9Sstevel@tonic-gate (curr_itd_addr & EHCI_ITD_LINK_PTR)) { 12387c478bd9Sstevel@tonic-gate 12397c478bd9Sstevel@tonic-gate next_addr = Get_ITD(curr_itd->itd_link_ptr); 12407c478bd9Sstevel@tonic-gate 12417c478bd9Sstevel@tonic-gate if (prev_itd == NULL) { 12427c478bd9Sstevel@tonic-gate /* This means PFL points to this ITD */ 12437c478bd9Sstevel@tonic-gate Set_PFLT(periodic_frame_list-> 12447c478bd9Sstevel@tonic-gate ehci_periodic_frame_list_table[pfl_number], 12457c478bd9Sstevel@tonic-gate next_addr); 12467c478bd9Sstevel@tonic-gate } else { 12477c478bd9Sstevel@tonic-gate /* Set the previous ITD's itd_link_ptr */ 12487c478bd9Sstevel@tonic-gate Set_ITD(prev_itd->itd_link_ptr, next_addr); 12497c478bd9Sstevel@tonic-gate } 12507c478bd9Sstevel@tonic-gate 12517c478bd9Sstevel@tonic-gate Set_ITD_FRAME(curr_itd->itd_frame_number, 0); 12527c478bd9Sstevel@tonic-gate } else { 12537c478bd9Sstevel@tonic-gate ASSERT((next_addr & EHCI_ITD_LINK_PTR) == 12547c478bd9Sstevel@tonic-gate (curr_itd_addr & EHCI_ITD_LINK_PTR)); 12557c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_ALLOC, ehcip->ehci_log_hdl, 12567c478bd9Sstevel@tonic-gate "ehci_remove_isoc_from_pfl: Unable to find ITD in PFL"); 12577c478bd9Sstevel@tonic-gate } 12587c478bd9Sstevel@tonic-gate } 12597c478bd9Sstevel@tonic-gate 12607c478bd9Sstevel@tonic-gate 12617c478bd9Sstevel@tonic-gate /* 12627c478bd9Sstevel@tonic-gate * Isochronous in resource functions 12637c478bd9Sstevel@tonic-gate */ 12647c478bd9Sstevel@tonic-gate /* 12657c478bd9Sstevel@tonic-gate * ehci_allocate_periodic_in_resource 12667c478bd9Sstevel@tonic-gate * 12677c478bd9Sstevel@tonic-gate * Allocate interrupt request structure for the interrupt IN transfer. 12687c478bd9Sstevel@tonic-gate */ 12697c478bd9Sstevel@tonic-gate int 12707c478bd9Sstevel@tonic-gate ehci_allocate_isoc_in_resource( 12717c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 12727c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp, 12737c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw, 12747c478bd9Sstevel@tonic-gate usb_flags_t flags) 12757c478bd9Sstevel@tonic-gate { 12767c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph = pp->pp_pipe_handle; 12777c478bd9Sstevel@tonic-gate usb_isoc_req_t *orig_isoc_reqp, *clone_isoc_reqp; 12787c478bd9Sstevel@tonic-gate 12797c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_LISTS, ehcip->ehci_log_hdl, 12807c478bd9Sstevel@tonic-gate "ehci_allocate_isoc_in_resource:" 1281*112116d8Sfb "pp = 0x%p itw = 0x%p flags = 0x%x", (void *)pp, (void *)itw, 1282*112116d8Sfb flags); 12837c478bd9Sstevel@tonic-gate 12847c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex)); 12857c478bd9Sstevel@tonic-gate ASSERT(itw->itw_curr_xfer_reqp == NULL); 12867c478bd9Sstevel@tonic-gate 12877c478bd9Sstevel@tonic-gate /* Get the client periodic in request pointer */ 12887c478bd9Sstevel@tonic-gate orig_isoc_reqp = (usb_isoc_req_t *)(pp->pp_client_periodic_in_reqp); 12897c478bd9Sstevel@tonic-gate 12907c478bd9Sstevel@tonic-gate ASSERT(orig_isoc_reqp != NULL); 12917c478bd9Sstevel@tonic-gate 12927c478bd9Sstevel@tonic-gate clone_isoc_reqp = usba_hcdi_dup_isoc_req(ph->p_dip, 12937c478bd9Sstevel@tonic-gate orig_isoc_reqp, flags); 12947c478bd9Sstevel@tonic-gate 12957c478bd9Sstevel@tonic-gate if (clone_isoc_reqp == NULL) { 12967c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, ehcip->ehci_log_hdl, 12977c478bd9Sstevel@tonic-gate "ehci_allocate_isoc_in_resource: Isochronous" 12987c478bd9Sstevel@tonic-gate "request structure allocation failed"); 12997c478bd9Sstevel@tonic-gate 13007c478bd9Sstevel@tonic-gate return (USB_NO_RESOURCES); 13017c478bd9Sstevel@tonic-gate } 13027c478bd9Sstevel@tonic-gate 13037c478bd9Sstevel@tonic-gate /* 13047c478bd9Sstevel@tonic-gate * Save the client's isochronous request pointer and 13057c478bd9Sstevel@tonic-gate * length of isochronous transfer in transfer wrapper. 13067c478bd9Sstevel@tonic-gate * The dup'ed request is saved in pp_client_periodic_in_reqp 13077c478bd9Sstevel@tonic-gate */ 13087c478bd9Sstevel@tonic-gate itw->itw_curr_xfer_reqp = orig_isoc_reqp; 1309b3001defSlg 13107c478bd9Sstevel@tonic-gate pp->pp_client_periodic_in_reqp = (usb_opaque_t)clone_isoc_reqp; 13117c478bd9Sstevel@tonic-gate 13127c478bd9Sstevel@tonic-gate mutex_enter(&ph->p_mutex); 13137c478bd9Sstevel@tonic-gate ph->p_req_count++; 13147c478bd9Sstevel@tonic-gate mutex_exit(&ph->p_mutex); 13157c478bd9Sstevel@tonic-gate 13167c478bd9Sstevel@tonic-gate pp->pp_state = EHCI_PIPE_STATE_ACTIVE; 13177c478bd9Sstevel@tonic-gate 13187c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 13197c478bd9Sstevel@tonic-gate } 13207c478bd9Sstevel@tonic-gate 13217c478bd9Sstevel@tonic-gate 13227c478bd9Sstevel@tonic-gate /* 13237c478bd9Sstevel@tonic-gate * ehci_deallocate_isoc_in_resource 13247c478bd9Sstevel@tonic-gate * 13257c478bd9Sstevel@tonic-gate * Deallocate interrupt request structure for the interrupt IN transfer. 13267c478bd9Sstevel@tonic-gate */ 13277c478bd9Sstevel@tonic-gate void 13287c478bd9Sstevel@tonic-gate ehci_deallocate_isoc_in_resource( 13297c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 13307c478bd9Sstevel@tonic-gate ehci_pipe_private_t *pp, 13317c478bd9Sstevel@tonic-gate ehci_isoc_xwrapper_t *itw) 13327c478bd9Sstevel@tonic-gate { 13337c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph = pp->pp_pipe_handle; 13347c478bd9Sstevel@tonic-gate uchar_t ep_attr = ph->p_ep.bmAttributes; 13357c478bd9Sstevel@tonic-gate usb_isoc_req_t *isoc_reqp; 13367c478bd9Sstevel@tonic-gate 13377c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_LISTS, 13387c478bd9Sstevel@tonic-gate ehcip->ehci_log_hdl, 13397c478bd9Sstevel@tonic-gate "ehci_deallocate_isoc_in_resource: " 1340*112116d8Sfb "pp = 0x%p itw = 0x%p", (void *)pp, (void *)itw); 13417c478bd9Sstevel@tonic-gate 13427c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex)); 13437c478bd9Sstevel@tonic-gate ASSERT((ep_attr & USB_EP_ATTR_MASK) == USB_EP_ATTR_ISOCH); 13447c478bd9Sstevel@tonic-gate 13457c478bd9Sstevel@tonic-gate isoc_reqp = itw->itw_curr_xfer_reqp; 13467c478bd9Sstevel@tonic-gate 13477c478bd9Sstevel@tonic-gate /* Check the current periodic in request pointer */ 13487c478bd9Sstevel@tonic-gate if (isoc_reqp) { 13497c478bd9Sstevel@tonic-gate itw->itw_curr_xfer_reqp = NULL; 13507c478bd9Sstevel@tonic-gate itw->itw_curr_isoc_pktp = NULL; 13517c478bd9Sstevel@tonic-gate 13527c478bd9Sstevel@tonic-gate mutex_enter(&ph->p_mutex); 13537c478bd9Sstevel@tonic-gate ph->p_req_count--; 13547c478bd9Sstevel@tonic-gate mutex_exit(&ph->p_mutex); 13557c478bd9Sstevel@tonic-gate 13567c478bd9Sstevel@tonic-gate usb_free_isoc_req(isoc_reqp); 13577c478bd9Sstevel@tonic-gate 13587c478bd9Sstevel@tonic-gate /* Set periodic in pipe state to idle */ 13597c478bd9Sstevel@tonic-gate pp->pp_state = EHCI_PIPE_STATE_IDLE; 13607c478bd9Sstevel@tonic-gate } 13617c478bd9Sstevel@tonic-gate } 13627c478bd9Sstevel@tonic-gate 13637c478bd9Sstevel@tonic-gate 13647c478bd9Sstevel@tonic-gate /* 13657c478bd9Sstevel@tonic-gate * ehci_itd_cpu_to_iommu: 13667c478bd9Sstevel@tonic-gate * 13677c478bd9Sstevel@tonic-gate * This function converts for the given Transfer Descriptor (ITD) CPU address 13687c478bd9Sstevel@tonic-gate * to IO address. 13697c478bd9Sstevel@tonic-gate */ 13707c478bd9Sstevel@tonic-gate uint32_t 13717c478bd9Sstevel@tonic-gate ehci_itd_cpu_to_iommu( 13727c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 13737c478bd9Sstevel@tonic-gate ehci_itd_t *addr) 13747c478bd9Sstevel@tonic-gate { 13757c478bd9Sstevel@tonic-gate uint32_t td; 13767c478bd9Sstevel@tonic-gate 13777c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex)); 13787c478bd9Sstevel@tonic-gate 13797c478bd9Sstevel@tonic-gate if (addr == NULL) { 13807c478bd9Sstevel@tonic-gate 13817c478bd9Sstevel@tonic-gate return (NULL); 13827c478bd9Sstevel@tonic-gate } 13837c478bd9Sstevel@tonic-gate 13847c478bd9Sstevel@tonic-gate td = (uint32_t)ehcip->ehci_itd_pool_cookie.dmac_address + 13857c478bd9Sstevel@tonic-gate (uint32_t)((uintptr_t)addr - 13860a05e705Slc (uintptr_t)(ehcip->ehci_itd_pool_addr)); 13877c478bd9Sstevel@tonic-gate 13887c478bd9Sstevel@tonic-gate ASSERT(((uint32_t) (sizeof (ehci_itd_t) * 13890a05e705Slc (addr - ehcip->ehci_itd_pool_addr))) == 13907c478bd9Sstevel@tonic-gate ((uint32_t)((uintptr_t)addr - (uintptr_t) 13910a05e705Slc (ehcip->ehci_itd_pool_addr)))); 13927c478bd9Sstevel@tonic-gate 13937c478bd9Sstevel@tonic-gate ASSERT(td >= ehcip->ehci_itd_pool_cookie.dmac_address); 13947c478bd9Sstevel@tonic-gate ASSERT(td <= ehcip->ehci_itd_pool_cookie.dmac_address + 13957c478bd9Sstevel@tonic-gate sizeof (ehci_itd_t) * ehci_itd_pool_size); 13967c478bd9Sstevel@tonic-gate 13977c478bd9Sstevel@tonic-gate return (td); 13987c478bd9Sstevel@tonic-gate } 13997c478bd9Sstevel@tonic-gate 14007c478bd9Sstevel@tonic-gate 14017c478bd9Sstevel@tonic-gate /* 14027c478bd9Sstevel@tonic-gate * ehci_itd_iommu_to_cpu: 14037c478bd9Sstevel@tonic-gate * 14047c478bd9Sstevel@tonic-gate * This function converts for the given Transfer Descriptor (ITD) IO address 14057c478bd9Sstevel@tonic-gate * to CPU address. 14067c478bd9Sstevel@tonic-gate */ 14077c478bd9Sstevel@tonic-gate ehci_itd_t * 14087c478bd9Sstevel@tonic-gate ehci_itd_iommu_to_cpu( 14097c478bd9Sstevel@tonic-gate ehci_state_t *ehcip, 14107c478bd9Sstevel@tonic-gate uintptr_t addr) 14117c478bd9Sstevel@tonic-gate { 14127c478bd9Sstevel@tonic-gate ehci_itd_t *itd; 14137c478bd9Sstevel@tonic-gate 14147c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&ehcip->ehci_int_mutex)); 14157c478bd9Sstevel@tonic-gate 14167c478bd9Sstevel@tonic-gate if (addr == NULL) { 14177c478bd9Sstevel@tonic-gate 14187c478bd9Sstevel@tonic-gate return (NULL); 14197c478bd9Sstevel@tonic-gate } 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 */ 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 */ 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 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 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 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