17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 54c8a46c1Syq * Common Development and Distribution License (the "License"). 64c8a46c1Syq * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*269552cdSguoqing zhu - Sun Microsystems - Beijing China * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* 287c478bd9Sstevel@tonic-gate * Universal Host Controller Driver (UHCI) 297c478bd9Sstevel@tonic-gate * 307c478bd9Sstevel@tonic-gate * The UHCI driver is a driver which interfaces to the Universal 317c478bd9Sstevel@tonic-gate * Serial Bus Driver (USBA) and the Host Controller (HC). The interface to 327c478bd9Sstevel@tonic-gate * the Host Controller is defined by the Universal Host Controller Interface. 337c478bd9Sstevel@tonic-gate * This file contains the code for HCDI entry points. 347c478bd9Sstevel@tonic-gate */ 357c478bd9Sstevel@tonic-gate #include <sys/usb/hcd/uhci/uhcid.h> 367c478bd9Sstevel@tonic-gate #include <sys/usb/hcd/uhci/uhcitgt.h> 377c478bd9Sstevel@tonic-gate #include <sys/usb/hcd/uhci/uhciutil.h> 3822eb7cb5Sgd #include <sys/strsun.h> 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate /* function prototypes */ 417c478bd9Sstevel@tonic-gate static int uhci_pipe_send_isoc_data(uhci_state_t *uhcip, 427c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, usb_isoc_req_t *isoc_req, 437c478bd9Sstevel@tonic-gate usb_flags_t usb_flags); 447c478bd9Sstevel@tonic-gate static int uhci_send_intr_data(uhci_state_t *uhcip, 457c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *pipe_handle, 467c478bd9Sstevel@tonic-gate usb_intr_req_t *req, 477c478bd9Sstevel@tonic-gate usb_flags_t flags); 487c478bd9Sstevel@tonic-gate static int uhci_start_periodic_pipe_polling(uhci_state_t *uhcip, 497c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 507c478bd9Sstevel@tonic-gate usb_opaque_t reqp, 517c478bd9Sstevel@tonic-gate usb_flags_t flags); 527c478bd9Sstevel@tonic-gate static int uhci_stop_periodic_pipe_polling(uhci_state_t *uhcip, 537c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 547c478bd9Sstevel@tonic-gate usb_flags_t flags); 557c478bd9Sstevel@tonic-gate static void uhci_update_intr_td_data_toggle(uhci_state_t *uhcip, 567c478bd9Sstevel@tonic-gate uhci_pipe_private_t *pp); 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate /* Maximum bulk transfer size */ 604610e4a0Sfrits int uhci_bulk_transfer_size = UHCI_BULK_MAX_XFER_SIZE; 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate /* 637c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_open: 647c478bd9Sstevel@tonic-gate * Member of HCD Ops structure and called during client specific pipe open 657c478bd9Sstevel@tonic-gate * Add the pipe to the data structure representing the device and allocate 667c478bd9Sstevel@tonic-gate * bandwidth for the pipe if it is a interrupt or isochronous endpoint. 677c478bd9Sstevel@tonic-gate */ 687c478bd9Sstevel@tonic-gate int 697c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_open(usba_pipe_handle_data_t *ph, usb_flags_t flags) 707c478bd9Sstevel@tonic-gate { 717c478bd9Sstevel@tonic-gate uint_t node = 0; 727c478bd9Sstevel@tonic-gate usb_addr_t usb_addr; 737c478bd9Sstevel@tonic-gate uhci_state_t *uhcip; 747c478bd9Sstevel@tonic-gate uhci_pipe_private_t *pp; 75fffe0b30Sqz int rval, error = USB_SUCCESS; 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate ASSERT(ph); 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate usb_addr = ph->p_usba_device->usb_addr; 807c478bd9Sstevel@tonic-gate uhcip = uhci_obtain_state(ph->p_usba_device->usb_root_hub_dip); 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 837c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_open: addr = 0x%x, ep%d", usb_addr, 847c478bd9Sstevel@tonic-gate ph->p_ep.bEndpointAddress & USB_EP_NUM_MASK); 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate sema_p(&uhcip->uhci_ocsem); 877c478bd9Sstevel@tonic-gate 88fffe0b30Sqz mutex_enter(&uhcip->uhci_int_mutex); 89fffe0b30Sqz rval = uhci_state_is_operational(uhcip); 90fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 91fffe0b30Sqz 92fffe0b30Sqz if (rval != USB_SUCCESS) { 93fffe0b30Sqz sema_v(&uhcip->uhci_ocsem); 94fffe0b30Sqz 95fffe0b30Sqz return (rval); 96fffe0b30Sqz } 97fffe0b30Sqz 987c478bd9Sstevel@tonic-gate /* 997c478bd9Sstevel@tonic-gate * Return failure immediately for any other pipe open on the root hub 1007c478bd9Sstevel@tonic-gate * except control or interrupt pipe. 1017c478bd9Sstevel@tonic-gate */ 1027c478bd9Sstevel@tonic-gate if (usb_addr == ROOT_HUB_ADDR) { 1037c478bd9Sstevel@tonic-gate switch (UHCI_XFER_TYPE(&ph->p_ep)) { 1047c478bd9Sstevel@tonic-gate case USB_EP_ATTR_CONTROL: 1057c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 1067c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_open: Root hub control pipe"); 1077c478bd9Sstevel@tonic-gate break; 1087c478bd9Sstevel@tonic-gate case USB_EP_ATTR_INTR: 1097c478bd9Sstevel@tonic-gate ASSERT(UHCI_XFER_DIR(&ph->p_ep) == USB_EP_DIR_IN); 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 1127c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_intr_pipe_handle = ph; 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate /* 1157c478bd9Sstevel@tonic-gate * Set the state of the root hub interrupt 1167c478bd9Sstevel@tonic-gate * pipe as IDLE. 1177c478bd9Sstevel@tonic-gate */ 1187c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_pipe_state = 119fffe0b30Sqz UHCI_PIPE_STATE_IDLE; 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate ASSERT(uhcip->uhci_root_hub.rh_client_intr_req == NULL); 1227c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_client_intr_req = NULL; 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate ASSERT(uhcip->uhci_root_hub.rh_curr_intr_reqp == NULL); 1257c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_curr_intr_reqp = NULL; 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 1287c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_open: Root hub interrupt " 1297c478bd9Sstevel@tonic-gate "pipe open succeeded"); 1307c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 1317c478bd9Sstevel@tonic-gate sema_v(&uhcip->uhci_ocsem); 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 1347c478bd9Sstevel@tonic-gate default: 1357c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 1367c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_open: Root hub pipe open failed"); 1377c478bd9Sstevel@tonic-gate sema_v(&uhcip->uhci_ocsem); 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate return (USB_FAILURE); 1407c478bd9Sstevel@tonic-gate } 1417c478bd9Sstevel@tonic-gate } 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate /* 1447c478bd9Sstevel@tonic-gate * A portion of the bandwidth is reserved for the non-periodic 1457c478bd9Sstevel@tonic-gate * transfers i.e control and bulk transfers in each of one 1467c478bd9Sstevel@tonic-gate * mill second frame period & usually it will be 10% of frame 1477c478bd9Sstevel@tonic-gate * period. Hence there is no need to check for the available 1487c478bd9Sstevel@tonic-gate * bandwidth before adding the control or bulk endpoints. 1497c478bd9Sstevel@tonic-gate * 1507c478bd9Sstevel@tonic-gate * There is a need to check for the available bandwidth before 1517c478bd9Sstevel@tonic-gate * adding the periodic transfers i.e interrupt & isochronous, since 1527c478bd9Sstevel@tonic-gate * all these periodic transfers are guaranteed transfers. Usually, 1537c478bd9Sstevel@tonic-gate * 90% of the total frame time is reserved for periodic transfers. 1547c478bd9Sstevel@tonic-gate */ 1557c478bd9Sstevel@tonic-gate if (UHCI_PERIODIC_ENDPOINT(&ph->p_ep)) { 1567c478bd9Sstevel@tonic-gate /* Zero Max Packet size endpoints are not supported */ 1577c478bd9Sstevel@tonic-gate if (ph->p_ep.wMaxPacketSize == 0) { 1587c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 1597c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_open: Zero length packet"); 1607c478bd9Sstevel@tonic-gate sema_v(&uhcip->uhci_ocsem); 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate return (USB_FAILURE); 1637c478bd9Sstevel@tonic-gate } 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 1667c478bd9Sstevel@tonic-gate mutex_enter(&ph->p_mutex); 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate error = uhci_allocate_bandwidth(uhcip, ph, &node); 1697c478bd9Sstevel@tonic-gate if (error != USB_SUCCESS) { 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 1727c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_open: Bandwidth allocation failed"); 1737c478bd9Sstevel@tonic-gate mutex_exit(&ph->p_mutex); 1747c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 1757c478bd9Sstevel@tonic-gate sema_v(&uhcip->uhci_ocsem); 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate return (error); 1787c478bd9Sstevel@tonic-gate } 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate mutex_exit(&ph->p_mutex); 1817c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 1827c478bd9Sstevel@tonic-gate } 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate /* Create the HCD pipe private structure */ 1857c478bd9Sstevel@tonic-gate pp = kmem_zalloc(sizeof (uhci_pipe_private_t), 1867c478bd9Sstevel@tonic-gate (flags & USB_FLAGS_SLEEP) ? KM_SLEEP : KM_NOSLEEP); 1877c478bd9Sstevel@tonic-gate if (pp == NULL) { 1887c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 1897c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_open: pp allocation failure"); 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate if (UHCI_PERIODIC_ENDPOINT(&ph->p_ep)) { 1927c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 1937c478bd9Sstevel@tonic-gate uhci_deallocate_bandwidth(uhcip, ph); 1947c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 1957c478bd9Sstevel@tonic-gate } 1967c478bd9Sstevel@tonic-gate sema_v(&uhcip->uhci_ocsem); 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate return (USB_NO_RESOURCES); 1997c478bd9Sstevel@tonic-gate } 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 202fffe0b30Sqz rval = uhci_state_is_operational(uhcip); 203fffe0b30Sqz 204fffe0b30Sqz if (rval != USB_SUCCESS) { 205fffe0b30Sqz kmem_free(ph, sizeof (uhci_pipe_private_t)); 206fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 207fffe0b30Sqz sema_v(&uhcip->uhci_ocsem); 208fffe0b30Sqz 209fffe0b30Sqz return (rval); 210fffe0b30Sqz } 2117c478bd9Sstevel@tonic-gate pp->pp_node = node; /* Store the node in the interrupt lattice */ 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate /* Initialize frame number */ 2147c478bd9Sstevel@tonic-gate pp->pp_frame_num = INVALID_FRNUM; 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate /* Set the state of pipe as IDLE */ 2177c478bd9Sstevel@tonic-gate pp->pp_state = UHCI_PIPE_STATE_IDLE; 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate /* Store a pointer to the pipe handle */ 2207c478bd9Sstevel@tonic-gate pp->pp_pipe_handle = ph; 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate /* Store the pointer in the pipe handle */ 2237c478bd9Sstevel@tonic-gate mutex_enter(&ph->p_mutex); 2247c478bd9Sstevel@tonic-gate ph->p_hcd_private = (usb_opaque_t)pp; 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate /* Store a copy of the pipe policy */ 2277c478bd9Sstevel@tonic-gate bcopy(&ph->p_policy, &pp->pp_policy, sizeof (usb_pipe_policy_t)); 2287c478bd9Sstevel@tonic-gate mutex_exit(&ph->p_mutex); 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate /* don't check for ROOT_HUB here anymore */ 2317c478bd9Sstevel@tonic-gate if (UHCI_XFER_TYPE(&ph->p_ep) != USB_EP_ATTR_ISOCH) { 2327c478bd9Sstevel@tonic-gate /* Allocate the host controller endpoint descriptor */ 2337c478bd9Sstevel@tonic-gate pp->pp_qh = uhci_alloc_queue_head(uhcip); 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate if (pp->pp_qh == NULL) { 2367c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, uhcip->uhci_log_hdl, 2377c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_open: QH allocation failed"); 2387c478bd9Sstevel@tonic-gate 2394c8a46c1Syq if (UHCI_PERIODIC_ENDPOINT(&ph->p_ep)) { 2404c8a46c1Syq uhci_deallocate_bandwidth(uhcip, ph); 2414c8a46c1Syq } 2424c8a46c1Syq 2437c478bd9Sstevel@tonic-gate mutex_enter(&ph->p_mutex); 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate /* 2467c478bd9Sstevel@tonic-gate * Deallocate the hcd private portion 2477c478bd9Sstevel@tonic-gate * of the pipe handle. 2487c478bd9Sstevel@tonic-gate */ 2497c478bd9Sstevel@tonic-gate kmem_free(ph->p_hcd_private, 250fffe0b30Sqz sizeof (uhci_pipe_private_t)); 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate /* 2537c478bd9Sstevel@tonic-gate * Set the private structure in the 2547c478bd9Sstevel@tonic-gate * pipe handle equal to NULL. 2557c478bd9Sstevel@tonic-gate */ 2567c478bd9Sstevel@tonic-gate ph->p_hcd_private = NULL; 2577c478bd9Sstevel@tonic-gate mutex_exit(&ph->p_mutex); 2587c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate sema_v(&uhcip->uhci_ocsem); 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate return (USB_NO_RESOURCES); 2637c478bd9Sstevel@tonic-gate } 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate /* 2667c478bd9Sstevel@tonic-gate * Insert the endpoint onto the host controller's 2677c478bd9Sstevel@tonic-gate * appropriate endpoint list. The host controller 2687c478bd9Sstevel@tonic-gate * will not schedule this endpoint until there are 2697c478bd9Sstevel@tonic-gate * any TD's to process. 2707c478bd9Sstevel@tonic-gate */ 2717c478bd9Sstevel@tonic-gate uhci_insert_qh(uhcip, ph); 2727c478bd9Sstevel@tonic-gate } 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate /* 2757c478bd9Sstevel@tonic-gate * Restore the data toggle from usb device structure. 2767c478bd9Sstevel@tonic-gate */ 2774c8a46c1Syq if (((ph->p_ep.bmAttributes) & USB_EP_ATTR_MASK) == USB_EP_ATTR_INTR || 2784c8a46c1Syq ((ph->p_ep.bmAttributes) & USB_EP_ATTR_MASK) == USB_EP_ATTR_BULK) { 2797c478bd9Sstevel@tonic-gate mutex_enter(&ph->p_mutex); 2807c478bd9Sstevel@tonic-gate 2817c478bd9Sstevel@tonic-gate pp->pp_data_toggle = usba_hcdi_get_data_toggle( 282fffe0b30Sqz ph->p_usba_device, ph->p_ep.bEndpointAddress); 2837c478bd9Sstevel@tonic-gate mutex_exit(&ph->p_mutex); 2847c478bd9Sstevel@tonic-gate } 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 2877c478bd9Sstevel@tonic-gate sema_v(&uhcip->uhci_ocsem); 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 290112116d8Sfb "uhci_hcdi_pipe_open: ph = 0x%p", (void *)ph); 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 2937c478bd9Sstevel@tonic-gate } 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate 2967c478bd9Sstevel@tonic-gate /* 2977c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_close: 2987c478bd9Sstevel@tonic-gate * Member of HCD Ops structure and called during the client specific pipe 2997c478bd9Sstevel@tonic-gate * close. Remove the pipe to the data structure representing the device 3007c478bd9Sstevel@tonic-gate * deallocate bandwidth for the pipe if it is an intr or isoch endpoint. 3017c478bd9Sstevel@tonic-gate */ 3027c478bd9Sstevel@tonic-gate int 3037c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_close(usba_pipe_handle_data_t *ph, usb_flags_t usb_flags) 3047c478bd9Sstevel@tonic-gate { 3057c478bd9Sstevel@tonic-gate usb_addr_t usb_addr; 3067c478bd9Sstevel@tonic-gate uhci_state_t *uhcip; 3077c478bd9Sstevel@tonic-gate usb_ep_descr_t *eptd = &ph->p_ep; 3087c478bd9Sstevel@tonic-gate uhci_pipe_private_t *pp; 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate uhcip = uhci_obtain_state(ph->p_usba_device->usb_root_hub_dip); 3117c478bd9Sstevel@tonic-gate pp = (uhci_pipe_private_t *)ph->p_hcd_private; 3127c478bd9Sstevel@tonic-gate usb_addr = ph->p_usba_device->usb_addr; 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 3157c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_close: addr = 0x%x, ep%d, flags = 0x%x", usb_addr, 3167c478bd9Sstevel@tonic-gate eptd->bEndpointAddress, usb_flags); 3177c478bd9Sstevel@tonic-gate 3187c478bd9Sstevel@tonic-gate sema_p(&uhcip->uhci_ocsem); 3197c478bd9Sstevel@tonic-gate 3207c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 3217c478bd9Sstevel@tonic-gate 3227c478bd9Sstevel@tonic-gate /* 3237c478bd9Sstevel@tonic-gate * Check whether the pipe is a root hub 3247c478bd9Sstevel@tonic-gate */ 3257c478bd9Sstevel@tonic-gate if (usb_addr == ROOT_HUB_ADDR) { 3267c478bd9Sstevel@tonic-gate switch (UHCI_XFER_TYPE(eptd)) { 3277c478bd9Sstevel@tonic-gate case USB_EP_ATTR_CONTROL: 3287c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 3297c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_close: Root hub control pipe " 3307c478bd9Sstevel@tonic-gate "close succeeded"); 3317c478bd9Sstevel@tonic-gate 3327c478bd9Sstevel@tonic-gate break; 3337c478bd9Sstevel@tonic-gate case USB_EP_ATTR_INTR: 3347c478bd9Sstevel@tonic-gate ASSERT((eptd->bEndpointAddress & 335fffe0b30Sqz USB_EP_NUM_MASK) == 1); 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate /* Do interrupt pipe cleanup */ 3387c478bd9Sstevel@tonic-gate uhci_root_hub_intr_pipe_cleanup(uhcip, 339fffe0b30Sqz USB_CR_PIPE_CLOSING); 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gate ASSERT(uhcip->uhci_root_hub.rh_pipe_state == 342fffe0b30Sqz UHCI_PIPE_STATE_IDLE); 3437c478bd9Sstevel@tonic-gate 3447c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_intr_pipe_handle = NULL; 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 3477c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_close: Root hub interrupt " 3487c478bd9Sstevel@tonic-gate "pipe close succeeded"); 3497c478bd9Sstevel@tonic-gate 3507c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_pipe_state = 351fffe0b30Sqz UHCI_PIPE_STATE_IDLE; 3527c478bd9Sstevel@tonic-gate 3537c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 3547c478bd9Sstevel@tonic-gate sema_v(&uhcip->uhci_ocsem); 3557c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 3567c478bd9Sstevel@tonic-gate } 3577c478bd9Sstevel@tonic-gate } else { 3587c478bd9Sstevel@tonic-gate /* 3597c478bd9Sstevel@tonic-gate * Stop all the transactions if it is not the root hub. 3607c478bd9Sstevel@tonic-gate */ 3617c478bd9Sstevel@tonic-gate if (UHCI_XFER_TYPE(eptd) == USB_EP_ATTR_INTR) { 3627c478bd9Sstevel@tonic-gate /* 3637c478bd9Sstevel@tonic-gate * Stop polling on the pipe to prevent any subsequently 3647c478bd9Sstevel@tonic-gate * queued tds (while we're waiting for SOF, below) 3657c478bd9Sstevel@tonic-gate * from being executed 3667c478bd9Sstevel@tonic-gate */ 3677c478bd9Sstevel@tonic-gate pp->pp_state = UHCI_PIPE_STATE_IDLE; 3687c478bd9Sstevel@tonic-gate } 3697c478bd9Sstevel@tonic-gate 3707c478bd9Sstevel@tonic-gate /* Disable all outstanding tds */ 3717c478bd9Sstevel@tonic-gate uhci_modify_td_active_bits(uhcip, pp); 3727c478bd9Sstevel@tonic-gate 3737c478bd9Sstevel@tonic-gate /* Prevent this queue from being executed */ 3747c478bd9Sstevel@tonic-gate if (UHCI_XFER_TYPE(eptd) != USB_EP_ATTR_ISOCH) { 3757c478bd9Sstevel@tonic-gate UHCI_SET_TERMINATE_BIT(pp->pp_qh->element_ptr); 3767c478bd9Sstevel@tonic-gate } 3777c478bd9Sstevel@tonic-gate 3787c478bd9Sstevel@tonic-gate /* Wait for the next start of frame */ 3797c478bd9Sstevel@tonic-gate (void) uhci_wait_for_sof(uhcip); 3807c478bd9Sstevel@tonic-gate 3817c478bd9Sstevel@tonic-gate ASSERT(eptd != NULL); 3827c478bd9Sstevel@tonic-gate 3837c478bd9Sstevel@tonic-gate switch (UHCI_XFER_TYPE(eptd)) { 3847c478bd9Sstevel@tonic-gate case USB_EP_ATTR_INTR: 3857c478bd9Sstevel@tonic-gate uhci_update_intr_td_data_toggle(uhcip, pp); 3867c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 3877c478bd9Sstevel@tonic-gate case USB_EP_ATTR_CONTROL: 3887c478bd9Sstevel@tonic-gate uhci_remove_tds_tws(uhcip, ph); 3897c478bd9Sstevel@tonic-gate break; 3907c478bd9Sstevel@tonic-gate case USB_EP_ATTR_BULK: 3917c478bd9Sstevel@tonic-gate SetQH32(uhcip, pp->pp_qh->element_ptr, 3927c478bd9Sstevel@tonic-gate TD_PADDR(pp->pp_qh->td_tailp)); 3937c478bd9Sstevel@tonic-gate uhci_remove_bulk_tds_tws(uhcip, pp, UHCI_IN_CLOSE); 3947c478bd9Sstevel@tonic-gate uhci_save_data_toggle(pp); 3957c478bd9Sstevel@tonic-gate break; 3967c478bd9Sstevel@tonic-gate case USB_EP_ATTR_ISOCH: 3977c478bd9Sstevel@tonic-gate uhci_remove_isoc_tds_tws(uhcip, pp); 3987c478bd9Sstevel@tonic-gate break; 3997c478bd9Sstevel@tonic-gate default: 4007c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 4017c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_close: Unknown xfer type"); 4027c478bd9Sstevel@tonic-gate break; 4037c478bd9Sstevel@tonic-gate } 4047c478bd9Sstevel@tonic-gate 4057c478bd9Sstevel@tonic-gate /* 4067c478bd9Sstevel@tonic-gate * Remove the endoint descriptor from Host Controller's 4077c478bd9Sstevel@tonic-gate * appropriate endpoint list. Isochronous pipes dont have 4087c478bd9Sstevel@tonic-gate * any queue heads attached to it. 4097c478bd9Sstevel@tonic-gate */ 4107c478bd9Sstevel@tonic-gate if (UHCI_XFER_TYPE(eptd) != USB_EP_ATTR_ISOCH) { 4117c478bd9Sstevel@tonic-gate uhci_remove_qh(uhcip, pp); 4127c478bd9Sstevel@tonic-gate } 4137c478bd9Sstevel@tonic-gate 4147c478bd9Sstevel@tonic-gate /* 4157c478bd9Sstevel@tonic-gate * Do the callback for the original client 4167c478bd9Sstevel@tonic-gate * periodic IN request. 4177c478bd9Sstevel@tonic-gate */ 4187c478bd9Sstevel@tonic-gate if (pp->pp_client_periodic_in_reqp) { 4197c478bd9Sstevel@tonic-gate uhci_hcdi_callback(uhcip, pp, ph, NULL, 4207c478bd9Sstevel@tonic-gate USB_CR_PIPE_CLOSING); 4217c478bd9Sstevel@tonic-gate } 4227c478bd9Sstevel@tonic-gate 4237c478bd9Sstevel@tonic-gate /* Deallocate bandwidth */ 4247c478bd9Sstevel@tonic-gate if (UHCI_PERIODIC_ENDPOINT(eptd)) { 4257c478bd9Sstevel@tonic-gate mutex_enter(&ph->p_mutex); 4267c478bd9Sstevel@tonic-gate uhci_deallocate_bandwidth(uhcip, ph); 4277c478bd9Sstevel@tonic-gate mutex_exit(&ph->p_mutex); 4287c478bd9Sstevel@tonic-gate } 4297c478bd9Sstevel@tonic-gate } 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate /* Deallocate the hcd private portion of the pipe handle. */ 4327c478bd9Sstevel@tonic-gate 4337c478bd9Sstevel@tonic-gate mutex_enter(&ph->p_mutex); 4347c478bd9Sstevel@tonic-gate kmem_free(ph->p_hcd_private, sizeof (uhci_pipe_private_t)); 4357c478bd9Sstevel@tonic-gate ph->p_hcd_private = NULL; 4367c478bd9Sstevel@tonic-gate mutex_exit(&ph->p_mutex); 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 439112116d8Sfb "uhci_hcdi_pipe_close: ph = 0x%p", (void *)ph); 4407c478bd9Sstevel@tonic-gate 4417c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 4427c478bd9Sstevel@tonic-gate sema_v(&uhcip->uhci_ocsem); 4437c478bd9Sstevel@tonic-gate 4447c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 4457c478bd9Sstevel@tonic-gate } 4467c478bd9Sstevel@tonic-gate 4477c478bd9Sstevel@tonic-gate 4487c478bd9Sstevel@tonic-gate /* 4497c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_reset: 4507c478bd9Sstevel@tonic-gate */ 4517c478bd9Sstevel@tonic-gate int 4527c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_reset(usba_pipe_handle_data_t *ph, usb_flags_t usb_flags) 4537c478bd9Sstevel@tonic-gate { 4547c478bd9Sstevel@tonic-gate uhci_state_t *uhcip = uhci_obtain_state( 455fffe0b30Sqz ph->p_usba_device->usb_root_hub_dip); 4567c478bd9Sstevel@tonic-gate uhci_pipe_private_t *pp = (uhci_pipe_private_t *)ph->p_hcd_private; 4577c478bd9Sstevel@tonic-gate usb_ep_descr_t *eptd = &ph->p_ep; 4587c478bd9Sstevel@tonic-gate 4597c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 4607c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_reset: usb_flags = 0x%x", usb_flags); 4617c478bd9Sstevel@tonic-gate 4627c478bd9Sstevel@tonic-gate /* 4637c478bd9Sstevel@tonic-gate * Return failure immediately for any other pipe reset on the root 4647c478bd9Sstevel@tonic-gate * hub except control or interrupt pipe. 4657c478bd9Sstevel@tonic-gate */ 4667c478bd9Sstevel@tonic-gate if (ph->p_usba_device->usb_addr == ROOT_HUB_ADDR) { 4677c478bd9Sstevel@tonic-gate switch (UHCI_XFER_TYPE(&ph->p_ep)) { 4687c478bd9Sstevel@tonic-gate case USB_EP_ATTR_CONTROL: 4697c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 4707c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_reset: Pipe reset for root" 4717c478bd9Sstevel@tonic-gate "hub control pipe successful"); 4727c478bd9Sstevel@tonic-gate 4737c478bd9Sstevel@tonic-gate break; 4747c478bd9Sstevel@tonic-gate case USB_EP_ATTR_INTR: 4757c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 4767c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_pipe_state = 477fffe0b30Sqz UHCI_PIPE_STATE_IDLE; 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate /* Do interrupt pipe cleanup */ 4807c478bd9Sstevel@tonic-gate uhci_root_hub_intr_pipe_cleanup(uhcip, 481fffe0b30Sqz USB_CR_PIPE_RESET); 4827c478bd9Sstevel@tonic-gate 4837c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 4847c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_reset: Pipe reset for " 4857c478bd9Sstevel@tonic-gate "root hub interrupt pipe successful"); 4867c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 4877c478bd9Sstevel@tonic-gate 4887c478bd9Sstevel@tonic-gate break; 4897c478bd9Sstevel@tonic-gate default: 4907c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 491fffe0b30Sqz "uhci_hcdi_pipe_reset: Root hub pipe reset failed"); 4927c478bd9Sstevel@tonic-gate 4937c478bd9Sstevel@tonic-gate return (USB_FAILURE); 4947c478bd9Sstevel@tonic-gate } 4957c478bd9Sstevel@tonic-gate 4967c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 4977c478bd9Sstevel@tonic-gate } 4987c478bd9Sstevel@tonic-gate 4997c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 5007c478bd9Sstevel@tonic-gate 5017c478bd9Sstevel@tonic-gate /* 5027c478bd9Sstevel@tonic-gate * Set the active bit in to INACTIVE for all the remaining TD's of 5037c478bd9Sstevel@tonic-gate * this end point. Set the active bit for the dummy td. This will 5047c478bd9Sstevel@tonic-gate * generate an interrupt at the end of the frame. After receiving 5057c478bd9Sstevel@tonic-gate * the interrupt, it is safe to to manipulate the lattice. 5067c478bd9Sstevel@tonic-gate */ 5077c478bd9Sstevel@tonic-gate uhci_modify_td_active_bits(uhcip, pp); 5087c478bd9Sstevel@tonic-gate 5097c478bd9Sstevel@tonic-gate /* Initialize the element pointer */ 5107c478bd9Sstevel@tonic-gate if (UHCI_XFER_TYPE(eptd) != USB_EP_ATTR_ISOCH) { 5117c478bd9Sstevel@tonic-gate UHCI_SET_TERMINATE_BIT(pp->pp_qh->element_ptr); 5127c478bd9Sstevel@tonic-gate SetQH32(uhcip, pp->pp_qh->element_ptr, 5137c478bd9Sstevel@tonic-gate TD_PADDR(pp->pp_qh->td_tailp)); 5147c478bd9Sstevel@tonic-gate } 5157c478bd9Sstevel@tonic-gate 5167c478bd9Sstevel@tonic-gate (void) uhci_wait_for_sof(uhcip); 5177c478bd9Sstevel@tonic-gate 5187c478bd9Sstevel@tonic-gate /* 5197c478bd9Sstevel@tonic-gate * Save the data toggle and clear the pipe. 5207c478bd9Sstevel@tonic-gate */ 5217c478bd9Sstevel@tonic-gate switch (UHCI_XFER_TYPE(eptd)) { 5227c478bd9Sstevel@tonic-gate case USB_EP_ATTR_CONTROL: 5237c478bd9Sstevel@tonic-gate case USB_EP_ATTR_INTR: 5247c478bd9Sstevel@tonic-gate uhci_remove_tds_tws(uhcip, ph); 5257c478bd9Sstevel@tonic-gate break; 5267c478bd9Sstevel@tonic-gate case USB_EP_ATTR_BULK: 5277c478bd9Sstevel@tonic-gate SetQH32(uhcip, pp->pp_qh->element_ptr, 5287c478bd9Sstevel@tonic-gate TD_PADDR(pp->pp_qh->td_tailp)); 5297c478bd9Sstevel@tonic-gate uhci_remove_bulk_tds_tws(uhcip, pp, UHCI_IN_RESET); 5307c478bd9Sstevel@tonic-gate break; 5317c478bd9Sstevel@tonic-gate case USB_EP_ATTR_ISOCH: 5327c478bd9Sstevel@tonic-gate uhci_remove_isoc_tds_tws(uhcip, pp); 5337c478bd9Sstevel@tonic-gate break; 5347c478bd9Sstevel@tonic-gate default: 5357c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 5367c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_reset: Unknown xfer type"); 5377c478bd9Sstevel@tonic-gate break; 5387c478bd9Sstevel@tonic-gate } 5397c478bd9Sstevel@tonic-gate 5407c478bd9Sstevel@tonic-gate /* 5417c478bd9Sstevel@tonic-gate * Do the callback for the original client 5427c478bd9Sstevel@tonic-gate * periodic IN request. 5437c478bd9Sstevel@tonic-gate */ 5447c478bd9Sstevel@tonic-gate if (pp->pp_client_periodic_in_reqp) { 5457c478bd9Sstevel@tonic-gate uhci_hcdi_callback(uhcip, pp, ph, NULL, USB_CR_PIPE_RESET); 5467c478bd9Sstevel@tonic-gate } 5477c478bd9Sstevel@tonic-gate 5487c478bd9Sstevel@tonic-gate /* 5497c478bd9Sstevel@tonic-gate * Since the endpoint is stripped of Transfer Descriptors (TD), 5507c478bd9Sstevel@tonic-gate * reset the state of the periodic pipe to IDLE. 5517c478bd9Sstevel@tonic-gate */ 5527c478bd9Sstevel@tonic-gate pp->pp_state = UHCI_PIPE_STATE_IDLE; 5537c478bd9Sstevel@tonic-gate 5547c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 5557c478bd9Sstevel@tonic-gate 5567c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 5577c478bd9Sstevel@tonic-gate } 5587c478bd9Sstevel@tonic-gate 559*269552cdSguoqing zhu - Sun Microsystems - Beijing China /* 560*269552cdSguoqing zhu - Sun Microsystems - Beijing China * uhci_hcdi_pipe_reset_data_toggle: 561*269552cdSguoqing zhu - Sun Microsystems - Beijing China */ 562*269552cdSguoqing zhu - Sun Microsystems - Beijing China void 563*269552cdSguoqing zhu - Sun Microsystems - Beijing China uhci_hcdi_pipe_reset_data_toggle( 564*269552cdSguoqing zhu - Sun Microsystems - Beijing China usba_pipe_handle_data_t *ph) 565*269552cdSguoqing zhu - Sun Microsystems - Beijing China { 566*269552cdSguoqing zhu - Sun Microsystems - Beijing China uhci_state_t *uhcip = uhci_obtain_state( 567*269552cdSguoqing zhu - Sun Microsystems - Beijing China ph->p_usba_device->usb_root_hub_dip); 568*269552cdSguoqing zhu - Sun Microsystems - Beijing China uhci_pipe_private_t *pp = (uhci_pipe_private_t *)ph->p_hcd_private; 569*269552cdSguoqing zhu - Sun Microsystems - Beijing China 570*269552cdSguoqing zhu - Sun Microsystems - Beijing China USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 571*269552cdSguoqing zhu - Sun Microsystems - Beijing China "uhci_hcdi_pipe_reset_data_toggle:"); 572*269552cdSguoqing zhu - Sun Microsystems - Beijing China 573*269552cdSguoqing zhu - Sun Microsystems - Beijing China mutex_enter(&uhcip->uhci_int_mutex); 574*269552cdSguoqing zhu - Sun Microsystems - Beijing China 575*269552cdSguoqing zhu - Sun Microsystems - Beijing China mutex_enter(&ph->p_mutex); 576*269552cdSguoqing zhu - Sun Microsystems - Beijing China pp->pp_data_toggle = 0; 577*269552cdSguoqing zhu - Sun Microsystems - Beijing China usba_hcdi_set_data_toggle(ph->p_usba_device, ph->p_ep.bEndpointAddress, 578*269552cdSguoqing zhu - Sun Microsystems - Beijing China pp->pp_data_toggle); 579*269552cdSguoqing zhu - Sun Microsystems - Beijing China mutex_exit(&ph->p_mutex); 580*269552cdSguoqing zhu - Sun Microsystems - Beijing China 581*269552cdSguoqing zhu - Sun Microsystems - Beijing China mutex_exit(&uhcip->uhci_int_mutex); 582*269552cdSguoqing zhu - Sun Microsystems - Beijing China 583*269552cdSguoqing zhu - Sun Microsystems - Beijing China } 5847c478bd9Sstevel@tonic-gate 5857c478bd9Sstevel@tonic-gate /* 5867c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_ctrl_xfer: 5877c478bd9Sstevel@tonic-gate */ 5887c478bd9Sstevel@tonic-gate int 5897c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_ctrl_xfer( 5907c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 5917c478bd9Sstevel@tonic-gate usb_ctrl_req_t *ctrl_reqp, 5927c478bd9Sstevel@tonic-gate usb_flags_t flags) 5937c478bd9Sstevel@tonic-gate { 5947c478bd9Sstevel@tonic-gate uhci_state_t *uhcip = uhci_obtain_state( 595fffe0b30Sqz ph->p_usba_device->usb_root_hub_dip); 5967c478bd9Sstevel@tonic-gate uhci_pipe_private_t *pp = (uhci_pipe_private_t *)ph->p_hcd_private; 597fffe0b30Sqz int error; 5987c478bd9Sstevel@tonic-gate 5997c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 6007c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_ctrl_xfer: req=0x%p, ph=0x%p, flags=0x%x", 601112116d8Sfb (void *)ctrl_reqp, (void *)ph, flags); 6027c478bd9Sstevel@tonic-gate 6037c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 604fffe0b30Sqz error = uhci_state_is_operational(uhcip); 605fffe0b30Sqz 606fffe0b30Sqz if (error != USB_SUCCESS) { 607fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 608fffe0b30Sqz 609fffe0b30Sqz return (error); 610fffe0b30Sqz } 6117c478bd9Sstevel@tonic-gate 6127c478bd9Sstevel@tonic-gate ASSERT(pp->pp_state == UHCI_PIPE_STATE_IDLE); 6137c478bd9Sstevel@tonic-gate 6147c478bd9Sstevel@tonic-gate /* 6157c478bd9Sstevel@tonic-gate * Check and handle root hub control request. 6167c478bd9Sstevel@tonic-gate */ 6177c478bd9Sstevel@tonic-gate if (ph->p_usba_device->usb_addr == ROOT_HUB_ADDR) { 6187c478bd9Sstevel@tonic-gate error = uhci_handle_root_hub_request(uhcip, ph, ctrl_reqp); 6197c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 6207c478bd9Sstevel@tonic-gate 6217c478bd9Sstevel@tonic-gate return (error); 6227c478bd9Sstevel@tonic-gate } 6237c478bd9Sstevel@tonic-gate 6247c478bd9Sstevel@tonic-gate /* Insert the td's on the endpoint */ 6257c478bd9Sstevel@tonic-gate if ((error = uhci_insert_ctrl_td(uhcip, ph, ctrl_reqp, flags)) != 6267c478bd9Sstevel@tonic-gate USB_SUCCESS) { 6277c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 6287c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_ctrl_xfer: No resources"); 6297c478bd9Sstevel@tonic-gate } 6307c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 6317c478bd9Sstevel@tonic-gate 6327c478bd9Sstevel@tonic-gate return (error); 6337c478bd9Sstevel@tonic-gate } 6347c478bd9Sstevel@tonic-gate 6357c478bd9Sstevel@tonic-gate 6367c478bd9Sstevel@tonic-gate /* 6377c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_bulk_xfer: 6387c478bd9Sstevel@tonic-gate */ 6397c478bd9Sstevel@tonic-gate int 6407c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_bulk_xfer(usba_pipe_handle_data_t *pipe_handle, 6417c478bd9Sstevel@tonic-gate usb_bulk_req_t *bulk_reqp, usb_flags_t usb_flags) 6427c478bd9Sstevel@tonic-gate { 6437c478bd9Sstevel@tonic-gate int error; 6447c478bd9Sstevel@tonic-gate uhci_state_t *uhcip; 6457c478bd9Sstevel@tonic-gate 6467c478bd9Sstevel@tonic-gate uhcip = uhci_obtain_state(pipe_handle->p_usba_device->usb_root_hub_dip); 6477c478bd9Sstevel@tonic-gate 6487c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 6497c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_bulk_xfer: Flags = 0x%x", usb_flags); 6507c478bd9Sstevel@tonic-gate 6517c478bd9Sstevel@tonic-gate /* Check the size of bulk request */ 6527c478bd9Sstevel@tonic-gate if (bulk_reqp->bulk_len > UHCI_BULK_MAX_XFER_SIZE) { 6537c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 6547c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_bulk_xfer: req size 0x%x is more than 0x%x", 6557c478bd9Sstevel@tonic-gate bulk_reqp->bulk_len, UHCI_BULK_MAX_XFER_SIZE); 6567c478bd9Sstevel@tonic-gate 6577c478bd9Sstevel@tonic-gate return (USB_FAILURE); 6587c478bd9Sstevel@tonic-gate } 6597c478bd9Sstevel@tonic-gate 6607c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 6617c478bd9Sstevel@tonic-gate 662fffe0b30Sqz error = uhci_state_is_operational(uhcip); 663fffe0b30Sqz 664fffe0b30Sqz if (error != USB_SUCCESS) { 665fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 666fffe0b30Sqz 667fffe0b30Sqz return (error); 668fffe0b30Sqz } 6697c478bd9Sstevel@tonic-gate /* Add the TD into the Host Controller's bulk list */ 6707c478bd9Sstevel@tonic-gate if ((error = uhci_insert_bulk_td(uhcip, pipe_handle, bulk_reqp, 6717c478bd9Sstevel@tonic-gate usb_flags)) != USB_SUCCESS) { 6727c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 6737c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_bulk_xfer: uhci_insert_bulk_td failed"); 6747c478bd9Sstevel@tonic-gate } 6757c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 6767c478bd9Sstevel@tonic-gate 6777c478bd9Sstevel@tonic-gate return (error); 6787c478bd9Sstevel@tonic-gate } 6797c478bd9Sstevel@tonic-gate 6807c478bd9Sstevel@tonic-gate 6817c478bd9Sstevel@tonic-gate /* 6827c478bd9Sstevel@tonic-gate * uhci_hcdi_bulk_transfer_size: 6837c478bd9Sstevel@tonic-gate * Return maximum bulk transfer size 6847c478bd9Sstevel@tonic-gate */ 6857c478bd9Sstevel@tonic-gate int 6867c478bd9Sstevel@tonic-gate uhci_hcdi_bulk_transfer_size( 6877c478bd9Sstevel@tonic-gate usba_device_t *usba_device, 6887c478bd9Sstevel@tonic-gate size_t *size) 6897c478bd9Sstevel@tonic-gate { 690fffe0b30Sqz uhci_state_t *uhcip = uhci_obtain_state( 691fffe0b30Sqz usba_device->usb_root_hub_dip); 692fffe0b30Sqz int rval; 6937c478bd9Sstevel@tonic-gate 6947c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 6957c478bd9Sstevel@tonic-gate "uhci_hcdi_bulk_transfer_size:"); 6967c478bd9Sstevel@tonic-gate 697fffe0b30Sqz mutex_enter(&uhcip->uhci_int_mutex); 698fffe0b30Sqz rval = uhci_state_is_operational(uhcip); 699fffe0b30Sqz 700fffe0b30Sqz if (rval != USB_SUCCESS) { 701fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 702fffe0b30Sqz 703fffe0b30Sqz return (rval); 704fffe0b30Sqz } 705fffe0b30Sqz 7067c478bd9Sstevel@tonic-gate *size = uhci_bulk_transfer_size; 707fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 7087c478bd9Sstevel@tonic-gate 7097c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 7107c478bd9Sstevel@tonic-gate } 7117c478bd9Sstevel@tonic-gate 7127c478bd9Sstevel@tonic-gate 7137c478bd9Sstevel@tonic-gate /* 7147c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_intr_xfer: 7157c478bd9Sstevel@tonic-gate */ 7167c478bd9Sstevel@tonic-gate int 7177c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_intr_xfer( 7187c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 7197c478bd9Sstevel@tonic-gate usb_intr_req_t *req, 7207c478bd9Sstevel@tonic-gate usb_flags_t flags) 7217c478bd9Sstevel@tonic-gate { 7227c478bd9Sstevel@tonic-gate uhci_state_t *uhcip = uhci_obtain_state( 723fffe0b30Sqz ph->p_usba_device->usb_root_hub_dip); 7247c478bd9Sstevel@tonic-gate 7257c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 726112116d8Sfb "uhci_hcdi_pipe_intr_xfer: req=0x%p, uf=0x%x", (void *)req, flags); 7277c478bd9Sstevel@tonic-gate 7287c478bd9Sstevel@tonic-gate if (UHCI_XFER_DIR(&ph->p_ep) == USB_EP_DIR_IN) { 7297c478bd9Sstevel@tonic-gate 7307c478bd9Sstevel@tonic-gate return (uhci_start_periodic_pipe_polling(uhcip, ph, 731fffe0b30Sqz (usb_opaque_t)req, flags)); 7327c478bd9Sstevel@tonic-gate } else { 7337c478bd9Sstevel@tonic-gate 7347c478bd9Sstevel@tonic-gate return (uhci_send_intr_data(uhcip, ph, req, flags)); 7357c478bd9Sstevel@tonic-gate } 7367c478bd9Sstevel@tonic-gate } 7377c478bd9Sstevel@tonic-gate 7387c478bd9Sstevel@tonic-gate 7397c478bd9Sstevel@tonic-gate /* 7407c478bd9Sstevel@tonic-gate * uhci_send_intr_data(): 7417c478bd9Sstevel@tonic-gate * send data to interrupt out pipe 7427c478bd9Sstevel@tonic-gate */ 7437c478bd9Sstevel@tonic-gate static int 7447c478bd9Sstevel@tonic-gate uhci_send_intr_data( 7457c478bd9Sstevel@tonic-gate uhci_state_t *uhcip, 7467c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *pipe_handle, 7477c478bd9Sstevel@tonic-gate usb_intr_req_t *req, 7487c478bd9Sstevel@tonic-gate usb_flags_t flags) 7497c478bd9Sstevel@tonic-gate { 750fffe0b30Sqz int rval; 7517c478bd9Sstevel@tonic-gate 7527c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_LISTS, uhcip->uhci_log_hdl, 7537c478bd9Sstevel@tonic-gate "uhci_send_intr_data:"); 7547c478bd9Sstevel@tonic-gate 7557c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 7567c478bd9Sstevel@tonic-gate 757fffe0b30Sqz rval = uhci_state_is_operational(uhcip); 758fffe0b30Sqz 759fffe0b30Sqz if (rval != USB_SUCCESS) { 760fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 761fffe0b30Sqz 762fffe0b30Sqz return (rval); 763fffe0b30Sqz } 764fffe0b30Sqz 7657c478bd9Sstevel@tonic-gate /* Add the TD into the Host Controller's interrupt list */ 7667c478bd9Sstevel@tonic-gate if ((rval = uhci_insert_intr_td(uhcip, pipe_handle, req, flags)) != 7677c478bd9Sstevel@tonic-gate USB_SUCCESS) { 7687c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 7697c478bd9Sstevel@tonic-gate "uhci_send_intr_data: No resources"); 7707c478bd9Sstevel@tonic-gate } 7717c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 7727c478bd9Sstevel@tonic-gate 7737c478bd9Sstevel@tonic-gate return (rval); 7747c478bd9Sstevel@tonic-gate } 7757c478bd9Sstevel@tonic-gate 7767c478bd9Sstevel@tonic-gate 7777c478bd9Sstevel@tonic-gate /* 7787c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_stop_intr_polling() 7797c478bd9Sstevel@tonic-gate */ 7807c478bd9Sstevel@tonic-gate int 7817c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_stop_intr_polling( 7827c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *pipe_handle, 7837c478bd9Sstevel@tonic-gate usb_flags_t flags) 7847c478bd9Sstevel@tonic-gate { 7857c478bd9Sstevel@tonic-gate uhci_state_t *uhcip = 786fffe0b30Sqz uhci_obtain_state(pipe_handle->p_usba_device->usb_root_hub_dip); 787fffe0b30Sqz int rval; 7887c478bd9Sstevel@tonic-gate 7897c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_LISTS, uhcip->uhci_log_hdl, 7907c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_stop_intr_polling: ph = 0x%p fl = 0x%x", 7917c478bd9Sstevel@tonic-gate (void *)pipe_handle, flags); 792fffe0b30Sqz mutex_enter(&uhcip->uhci_int_mutex); 7937c478bd9Sstevel@tonic-gate 794fffe0b30Sqz rval = uhci_stop_periodic_pipe_polling(uhcip, pipe_handle, flags); 795fffe0b30Sqz 796fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 797fffe0b30Sqz 798fffe0b30Sqz return (rval); 7997c478bd9Sstevel@tonic-gate } 8007c478bd9Sstevel@tonic-gate 8017c478bd9Sstevel@tonic-gate 8027c478bd9Sstevel@tonic-gate /* 8037c478bd9Sstevel@tonic-gate * uhci_hcdi_get_current_frame_number 804fffe0b30Sqz * Get the current frame number. 805fffe0b30Sqz * Return whether the request is handled successfully. 8067c478bd9Sstevel@tonic-gate */ 807fffe0b30Sqz int 808fffe0b30Sqz uhci_hcdi_get_current_frame_number( 809fffe0b30Sqz usba_device_t *usba_device, 810fffe0b30Sqz usb_frame_number_t *frame_number) 8117c478bd9Sstevel@tonic-gate { 8127c478bd9Sstevel@tonic-gate uhci_state_t *uhcip = uhci_obtain_state(usba_device->usb_root_hub_dip); 813fffe0b30Sqz int rval; 8147c478bd9Sstevel@tonic-gate 8157c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 816fffe0b30Sqz rval = uhci_state_is_operational(uhcip); 817fffe0b30Sqz 818fffe0b30Sqz if (rval != USB_SUCCESS) { 819fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 820fffe0b30Sqz 821fffe0b30Sqz return (rval); 822fffe0b30Sqz } 823fffe0b30Sqz 824fffe0b30Sqz *frame_number = uhci_get_sw_frame_number(uhcip); 8257c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 8267c478bd9Sstevel@tonic-gate 8277c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 828112116d8Sfb "uhci_hcdi_get_current_frame_number: %llx", 829112116d8Sfb (unsigned long long)(*frame_number)); 8307c478bd9Sstevel@tonic-gate 831fffe0b30Sqz return (rval); 8327c478bd9Sstevel@tonic-gate } 8337c478bd9Sstevel@tonic-gate 8347c478bd9Sstevel@tonic-gate 8357c478bd9Sstevel@tonic-gate /* 8367c478bd9Sstevel@tonic-gate * uhci_hcdi_get_max_isoc_pkts 837fffe0b30Sqz * Get the maximum number of isoc packets per USB Isoch request. 838fffe0b30Sqz * Return whether the request is handled successfully. 8397c478bd9Sstevel@tonic-gate */ 840fffe0b30Sqz int 841fffe0b30Sqz uhci_hcdi_get_max_isoc_pkts( 842fffe0b30Sqz usba_device_t *usba_device, 843fffe0b30Sqz uint_t *max_isoc_pkts_per_request) 8447c478bd9Sstevel@tonic-gate { 8457c478bd9Sstevel@tonic-gate uhci_state_t *uhcip = uhci_obtain_state(usba_device->usb_root_hub_dip); 846fffe0b30Sqz int rval; 847fffe0b30Sqz 848fffe0b30Sqz mutex_enter(&uhcip->uhci_int_mutex); 849fffe0b30Sqz rval = uhci_state_is_operational(uhcip); 850fffe0b30Sqz 851fffe0b30Sqz if (rval != USB_SUCCESS) { 852fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 853fffe0b30Sqz 854fffe0b30Sqz return (rval); 855fffe0b30Sqz } 856fffe0b30Sqz 857fffe0b30Sqz *max_isoc_pkts_per_request = UHCI_MAX_ISOC_PKTS; 858fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 8597c478bd9Sstevel@tonic-gate 8607c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 8617c478bd9Sstevel@tonic-gate "uhci_hcdi_get_max_isoc_pkts: 0x%x", UHCI_MAX_ISOC_PKTS); 8627c478bd9Sstevel@tonic-gate 863fffe0b30Sqz return (rval); 8647c478bd9Sstevel@tonic-gate } 8657c478bd9Sstevel@tonic-gate 8667c478bd9Sstevel@tonic-gate 8677c478bd9Sstevel@tonic-gate /* 8687c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_isoc_xfer: 8697c478bd9Sstevel@tonic-gate */ 8707c478bd9Sstevel@tonic-gate int 8717c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_isoc_xfer( 8727c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 8737c478bd9Sstevel@tonic-gate usb_isoc_req_t *isoc_reqp, 8747c478bd9Sstevel@tonic-gate usb_flags_t flags) 8757c478bd9Sstevel@tonic-gate { 8767c478bd9Sstevel@tonic-gate uhci_state_t *uhcip; 8777c478bd9Sstevel@tonic-gate 8787c478bd9Sstevel@tonic-gate uhcip = uhci_obtain_state(ph->p_usba_device->usb_root_hub_dip); 8797c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 880112116d8Sfb "uhci_hcdi_pipe_isoc_xfer: req=0x%p, uf=0x%x", 881112116d8Sfb (void *)isoc_reqp, flags); 8827c478bd9Sstevel@tonic-gate 8837c478bd9Sstevel@tonic-gate if (UHCI_XFER_DIR(&ph->p_ep) == USB_EP_DIR_IN) { 8847c478bd9Sstevel@tonic-gate 8857c478bd9Sstevel@tonic-gate return (uhci_start_periodic_pipe_polling(uhcip, ph, 886fffe0b30Sqz (usb_opaque_t)isoc_reqp, flags)); 8877c478bd9Sstevel@tonic-gate } else { 8887c478bd9Sstevel@tonic-gate 8897c478bd9Sstevel@tonic-gate return (uhci_pipe_send_isoc_data(uhcip, ph, isoc_reqp, flags)); 8907c478bd9Sstevel@tonic-gate } 8917c478bd9Sstevel@tonic-gate } 8927c478bd9Sstevel@tonic-gate 8937c478bd9Sstevel@tonic-gate 8947c478bd9Sstevel@tonic-gate /* 8957c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_stop_isoc_polling() 8967c478bd9Sstevel@tonic-gate */ 8977c478bd9Sstevel@tonic-gate int 8987c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_stop_isoc_polling( 8997c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 9007c478bd9Sstevel@tonic-gate usb_flags_t flags) 9017c478bd9Sstevel@tonic-gate { 9027c478bd9Sstevel@tonic-gate uhci_state_t *uhcip = 903fffe0b30Sqz uhci_obtain_state(ph->p_usba_device->usb_root_hub_dip); 904fffe0b30Sqz int rval; 9057c478bd9Sstevel@tonic-gate 9067c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_LISTS, uhcip->uhci_log_hdl, 9077c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_stop_isoc_polling: ph = 0x%p fl = 0x%x", 9087c478bd9Sstevel@tonic-gate (void *)ph, flags); 9097c478bd9Sstevel@tonic-gate 910fffe0b30Sqz mutex_enter(&uhcip->uhci_int_mutex); 911fffe0b30Sqz rval = uhci_state_is_operational(uhcip); 912fffe0b30Sqz 913fffe0b30Sqz if (rval != USB_SUCCESS) { 914fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 915fffe0b30Sqz 916fffe0b30Sqz return (rval); 917fffe0b30Sqz } 918fffe0b30Sqz 919fffe0b30Sqz rval = uhci_stop_periodic_pipe_polling(uhcip, ph, flags); 920fffe0b30Sqz 921fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 922fffe0b30Sqz 923fffe0b30Sqz return (rval); 9247c478bd9Sstevel@tonic-gate } 9257c478bd9Sstevel@tonic-gate 9267c478bd9Sstevel@tonic-gate 9277c478bd9Sstevel@tonic-gate /* 9287c478bd9Sstevel@tonic-gate * uhci_start_periodic_pipe_polling: 9297c478bd9Sstevel@tonic-gate */ 9307c478bd9Sstevel@tonic-gate static int 9317c478bd9Sstevel@tonic-gate uhci_start_periodic_pipe_polling( 9327c478bd9Sstevel@tonic-gate uhci_state_t *uhcip, 9337c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 9347c478bd9Sstevel@tonic-gate usb_opaque_t in_reqp, 9357c478bd9Sstevel@tonic-gate usb_flags_t flags) 9367c478bd9Sstevel@tonic-gate { 9377c478bd9Sstevel@tonic-gate int n, num_tds; 938fffe0b30Sqz int error; 9397c478bd9Sstevel@tonic-gate usb_intr_req_t *intr_reqp = (usb_intr_req_t *)in_reqp; 9407c478bd9Sstevel@tonic-gate usb_ep_descr_t *eptd = &ph->p_ep; 9417c478bd9Sstevel@tonic-gate uhci_pipe_private_t *pp = (uhci_pipe_private_t *)ph->p_hcd_private; 9427c478bd9Sstevel@tonic-gate 9437c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 9447c478bd9Sstevel@tonic-gate "uhci_start_periodic_pipe_polling: flags: 0x%x, ep%d", 9457c478bd9Sstevel@tonic-gate flags, eptd->bEndpointAddress); 9467c478bd9Sstevel@tonic-gate 9477c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 9487c478bd9Sstevel@tonic-gate 949fffe0b30Sqz error = uhci_state_is_operational(uhcip); 950fffe0b30Sqz 951fffe0b30Sqz if (error != USB_SUCCESS) { 952fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 953fffe0b30Sqz 954fffe0b30Sqz return (error); 955fffe0b30Sqz } 956fffe0b30Sqz 9577c478bd9Sstevel@tonic-gate if (ph->p_usba_device->usb_addr == ROOT_HUB_ADDR) { 9587c478bd9Sstevel@tonic-gate uint_t pipe_state = uhcip->uhci_root_hub.rh_pipe_state; 9597c478bd9Sstevel@tonic-gate 9607c478bd9Sstevel@tonic-gate ASSERT(pipe_state == UHCI_PIPE_STATE_IDLE); 9617c478bd9Sstevel@tonic-gate ASSERT(UHCI_XFER_DIR(eptd) == USB_EP_DIR_IN); 9627c478bd9Sstevel@tonic-gate 9637c478bd9Sstevel@tonic-gate /* ONE_XFER not supported */ 9647c478bd9Sstevel@tonic-gate ASSERT((intr_reqp->intr_attributes & 9657c478bd9Sstevel@tonic-gate USB_ATTRS_ONE_XFER) == 0); 9667c478bd9Sstevel@tonic-gate ASSERT(uhcip->uhci_root_hub.rh_client_intr_req == NULL); 9677c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_client_intr_req = intr_reqp; 9687c478bd9Sstevel@tonic-gate 9697c478bd9Sstevel@tonic-gate if ((error = uhci_root_hub_allocate_intr_pipe_resource( 9707c478bd9Sstevel@tonic-gate uhcip, flags)) != USB_SUCCESS) { 9717c478bd9Sstevel@tonic-gate /* reset the client interrupt request pointer */ 9727c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_client_intr_req = NULL; 9737c478bd9Sstevel@tonic-gate 9747c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 9757c478bd9Sstevel@tonic-gate 9767c478bd9Sstevel@tonic-gate return (error); 9777c478bd9Sstevel@tonic-gate } 9787c478bd9Sstevel@tonic-gate 9797c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_pipe_state = USB_PIPE_STATE_ACTIVE; 9807c478bd9Sstevel@tonic-gate 9817c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 9827c478bd9Sstevel@tonic-gate "uhci_start_periodic_pipe_polling: " 9837c478bd9Sstevel@tonic-gate "Start intr polling for root hub successful"); 9847c478bd9Sstevel@tonic-gate 9857c478bd9Sstevel@tonic-gate /* check if we need to send the reset data up? */ 9867c478bd9Sstevel@tonic-gate if (uhcip->uhci_root_hub.rh_status) { 9877c478bd9Sstevel@tonic-gate uhci_root_hub_reset_occurred(uhcip, 9887c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_status - 1); 9897c478bd9Sstevel@tonic-gate 9907c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_status = 0; 9917c478bd9Sstevel@tonic-gate } 9927c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 9937c478bd9Sstevel@tonic-gate 9947c478bd9Sstevel@tonic-gate return (error); 9957c478bd9Sstevel@tonic-gate } 9967c478bd9Sstevel@tonic-gate 9977c478bd9Sstevel@tonic-gate /* save the original client's periodic IN request */ 9987c478bd9Sstevel@tonic-gate pp->pp_client_periodic_in_reqp = in_reqp; 9997c478bd9Sstevel@tonic-gate 10007c478bd9Sstevel@tonic-gate ASSERT(pp->pp_state != UHCI_PIPE_STATE_ACTIVE); 10017c478bd9Sstevel@tonic-gate /* 10027c478bd9Sstevel@tonic-gate * 10037c478bd9Sstevel@tonic-gate * This pipe is uninitialized. If it is an isoc 10047c478bd9Sstevel@tonic-gate * receive request, insert four times the same 10057c478bd9Sstevel@tonic-gate * request so that we do not lose any frames. 10067c478bd9Sstevel@tonic-gate */ 10077c478bd9Sstevel@tonic-gate if (UHCI_XFER_TYPE(eptd) == USB_EP_ATTR_ISOCH) { 10087c478bd9Sstevel@tonic-gate for (n = 0; n < 5; n++) { 10097c478bd9Sstevel@tonic-gate if ((error = uhci_start_isoc_receive_polling( 10107c478bd9Sstevel@tonic-gate uhcip, ph, NULL, flags)) != USB_SUCCESS) { 10117c478bd9Sstevel@tonic-gate 10127c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_INTR, 10137c478bd9Sstevel@tonic-gate uhcip->uhci_log_hdl, 10147c478bd9Sstevel@tonic-gate "uhci_start_periodic_pipe_polling: " 10157c478bd9Sstevel@tonic-gate "Start isoc polling failed %d", n); 10167c478bd9Sstevel@tonic-gate 10177c478bd9Sstevel@tonic-gate pp->pp_client_periodic_in_reqp = NULL; 10187c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 10197c478bd9Sstevel@tonic-gate 10207c478bd9Sstevel@tonic-gate return (error); 10217c478bd9Sstevel@tonic-gate } 10227c478bd9Sstevel@tonic-gate } 10237c478bd9Sstevel@tonic-gate } 10247c478bd9Sstevel@tonic-gate 10257c478bd9Sstevel@tonic-gate if (UHCI_XFER_TYPE(eptd) == USB_EP_ATTR_INTR) { 10267c478bd9Sstevel@tonic-gate if ((pp->pp_node < POLLING_FREQ_7MS) && 10277c478bd9Sstevel@tonic-gate (!(intr_reqp->intr_attributes & USB_ATTRS_ONE_XFER))) { 10287c478bd9Sstevel@tonic-gate num_tds = 5; 10297c478bd9Sstevel@tonic-gate } else { 10307c478bd9Sstevel@tonic-gate num_tds = 1; 10317c478bd9Sstevel@tonic-gate } 10327c478bd9Sstevel@tonic-gate 10337c478bd9Sstevel@tonic-gate /* 10347c478bd9Sstevel@tonic-gate * This pipe is uninitialized. 10357c478bd9Sstevel@tonic-gate * Insert a TD on the interrupt ED. 10367c478bd9Sstevel@tonic-gate */ 10377c478bd9Sstevel@tonic-gate for (n = 0; n < num_tds; n++) { 10387c478bd9Sstevel@tonic-gate if ((error = uhci_insert_intr_td(uhcip, ph, NULL, 10397c478bd9Sstevel@tonic-gate flags)) != USB_SUCCESS) { 10407c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_INTR, 10417c478bd9Sstevel@tonic-gate uhcip->uhci_log_hdl, 10427c478bd9Sstevel@tonic-gate "uhci_start_periodic_pipe_polling: " 10437c478bd9Sstevel@tonic-gate "Start polling failed"); 10447c478bd9Sstevel@tonic-gate 10457c478bd9Sstevel@tonic-gate pp->pp_client_periodic_in_reqp = NULL; 10467c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 10477c478bd9Sstevel@tonic-gate 10487c478bd9Sstevel@tonic-gate return (error); 10497c478bd9Sstevel@tonic-gate } 10507c478bd9Sstevel@tonic-gate } 10517c478bd9Sstevel@tonic-gate } 10527c478bd9Sstevel@tonic-gate 10537c478bd9Sstevel@tonic-gate pp->pp_state = UHCI_PIPE_STATE_ACTIVE; 10547c478bd9Sstevel@tonic-gate 10557c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 10567c478bd9Sstevel@tonic-gate 10577c478bd9Sstevel@tonic-gate return (error); 10587c478bd9Sstevel@tonic-gate } 10597c478bd9Sstevel@tonic-gate 10607c478bd9Sstevel@tonic-gate 10617c478bd9Sstevel@tonic-gate /* 10627c478bd9Sstevel@tonic-gate * uhci_hcdi_periodic_pipe_stop_polling: 10637c478bd9Sstevel@tonic-gate */ 10647c478bd9Sstevel@tonic-gate static int 10657c478bd9Sstevel@tonic-gate uhci_stop_periodic_pipe_polling(uhci_state_t *uhcip, 10667c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, usb_flags_t flags) 10677c478bd9Sstevel@tonic-gate { 10687c478bd9Sstevel@tonic-gate uhci_pipe_private_t *pp = (uhci_pipe_private_t *)ph->p_hcd_private; 10697c478bd9Sstevel@tonic-gate usb_ep_descr_t *eptd = &ph->p_ep; 10707c478bd9Sstevel@tonic-gate 10717c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 10727c478bd9Sstevel@tonic-gate "uhci_stop_periodic_pipe_polling: flags = 0x%x", flags); 10737c478bd9Sstevel@tonic-gate 1074fffe0b30Sqz ASSERT(mutex_owned(&uhcip->uhci_int_mutex)); 10757c478bd9Sstevel@tonic-gate if (ph->p_usba_device->usb_addr == ROOT_HUB_ADDR) { 10767c478bd9Sstevel@tonic-gate ASSERT(UHCI_XFER_DIR(eptd) == USB_EP_DIR_IN); 10777c478bd9Sstevel@tonic-gate 10787c478bd9Sstevel@tonic-gate if (uhcip->uhci_root_hub.rh_pipe_state == 10797c478bd9Sstevel@tonic-gate UHCI_PIPE_STATE_ACTIVE) { 10807c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_pipe_state = 1081fffe0b30Sqz UHCI_PIPE_STATE_IDLE; 10827c478bd9Sstevel@tonic-gate 10837c478bd9Sstevel@tonic-gate /* Do interrupt pipe cleanup */ 10847c478bd9Sstevel@tonic-gate uhci_root_hub_intr_pipe_cleanup(uhcip, 1085fffe0b30Sqz USB_CR_STOPPED_POLLING); 10867c478bd9Sstevel@tonic-gate 10877c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 10887c478bd9Sstevel@tonic-gate "uhci_stop_periodic_pipe_polling: Stop intr " 10897c478bd9Sstevel@tonic-gate "polling for root hub successful"); 10907c478bd9Sstevel@tonic-gate 10917c478bd9Sstevel@tonic-gate } else { 10927c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_INTR, uhcip->uhci_log_hdl, 10937c478bd9Sstevel@tonic-gate "uhci_stop_periodic_pipe_polling: " 10947c478bd9Sstevel@tonic-gate "Intr polling for root hub is already stopped"); 10957c478bd9Sstevel@tonic-gate } 10967c478bd9Sstevel@tonic-gate 10977c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 10987c478bd9Sstevel@tonic-gate } 10997c478bd9Sstevel@tonic-gate 11007c478bd9Sstevel@tonic-gate if (pp->pp_state != UHCI_PIPE_STATE_ACTIVE) { 11017c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_INTR, uhcip->uhci_log_hdl, 11027c478bd9Sstevel@tonic-gate "uhci_stop_periodic_pipe_polling: Polling already stopped"); 11037c478bd9Sstevel@tonic-gate 11047c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 11057c478bd9Sstevel@tonic-gate } 11067c478bd9Sstevel@tonic-gate 11077c478bd9Sstevel@tonic-gate /* 11087c478bd9Sstevel@tonic-gate * Set the terminate bits in all the tds in the queue and 11097c478bd9Sstevel@tonic-gate * in the element_ptr. 11107c478bd9Sstevel@tonic-gate * Do not deallocate the bandwidth or tear down the DMA 11117c478bd9Sstevel@tonic-gate */ 11127c478bd9Sstevel@tonic-gate uhci_modify_td_active_bits(uhcip, pp); 11137c478bd9Sstevel@tonic-gate (void) uhci_wait_for_sof(uhcip); 11147c478bd9Sstevel@tonic-gate 11157c478bd9Sstevel@tonic-gate if (UHCI_XFER_TYPE(eptd) == USB_EP_ATTR_ISOCH) { 11167c478bd9Sstevel@tonic-gate uhci_remove_isoc_tds_tws(uhcip, pp); 11177c478bd9Sstevel@tonic-gate pp->pp_state = UHCI_PIPE_STATE_IDLE; 11187c478bd9Sstevel@tonic-gate } else { 11197c478bd9Sstevel@tonic-gate UHCI_SET_TERMINATE_BIT(pp->pp_qh->element_ptr); 11207c478bd9Sstevel@tonic-gate uhci_update_intr_td_data_toggle(uhcip, pp); 11217c478bd9Sstevel@tonic-gate SetQH32(uhcip, pp->pp_qh->element_ptr, 11227c478bd9Sstevel@tonic-gate TD_PADDR(pp->pp_qh->td_tailp)); 11237c478bd9Sstevel@tonic-gate uhci_remove_tds_tws(uhcip, ph); 11247c478bd9Sstevel@tonic-gate } 11257c478bd9Sstevel@tonic-gate 11267c478bd9Sstevel@tonic-gate pp->pp_state = UHCI_PIPE_STATE_IDLE; 11277c478bd9Sstevel@tonic-gate 11287c478bd9Sstevel@tonic-gate if (pp->pp_client_periodic_in_reqp) { 11297c478bd9Sstevel@tonic-gate uhci_hcdi_callback(uhcip, pp, ph, NULL, USB_CR_STOPPED_POLLING); 11307c478bd9Sstevel@tonic-gate } 11317c478bd9Sstevel@tonic-gate 11327c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 11337c478bd9Sstevel@tonic-gate } 11347c478bd9Sstevel@tonic-gate 11357c478bd9Sstevel@tonic-gate 11367c478bd9Sstevel@tonic-gate /* 11377c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_send_isoc_data: 11387c478bd9Sstevel@tonic-gate * Handles the isoc write request. 11397c478bd9Sstevel@tonic-gate */ 11407c478bd9Sstevel@tonic-gate static int 11417c478bd9Sstevel@tonic-gate uhci_pipe_send_isoc_data( 11427c478bd9Sstevel@tonic-gate uhci_state_t *uhcip, 11437c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 11447c478bd9Sstevel@tonic-gate usb_isoc_req_t *isoc_req, 11457c478bd9Sstevel@tonic-gate usb_flags_t usb_flags) 11467c478bd9Sstevel@tonic-gate { 11477c478bd9Sstevel@tonic-gate int error; 11487c478bd9Sstevel@tonic-gate size_t max_isoc_xfer_sz, length; 11497c478bd9Sstevel@tonic-gate 11507c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 11517c478bd9Sstevel@tonic-gate "uhci_pipe_send_isoc_data: isoc_req = %p flags = %x", 1152112116d8Sfb (void *)isoc_req, usb_flags); 11537c478bd9Sstevel@tonic-gate 11547c478bd9Sstevel@tonic-gate ASSERT(isoc_req->isoc_pkts_count < UHCI_MAX_ISOC_PKTS); 11557c478bd9Sstevel@tonic-gate 11567c478bd9Sstevel@tonic-gate /* Calculate the maximum isochronous transfer size */ 11577c478bd9Sstevel@tonic-gate max_isoc_xfer_sz = UHCI_MAX_ISOC_PKTS * ph->p_ep.wMaxPacketSize; 11587c478bd9Sstevel@tonic-gate 11597c478bd9Sstevel@tonic-gate /* Check the size of isochronous request */ 11607c478bd9Sstevel@tonic-gate ASSERT(isoc_req->isoc_data != NULL); 116122eb7cb5Sgd length = MBLKL(isoc_req->isoc_data); 11627c478bd9Sstevel@tonic-gate 11637c478bd9Sstevel@tonic-gate if (length > max_isoc_xfer_sz) { 11647c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 11657c478bd9Sstevel@tonic-gate "uhci_pipe_send_isoc_data: Maximum isoc request size %lx " 11667c478bd9Sstevel@tonic-gate "Given isoc request size %lx", max_isoc_xfer_sz, length); 11677c478bd9Sstevel@tonic-gate 11687c478bd9Sstevel@tonic-gate return (USB_INVALID_REQUEST); 11697c478bd9Sstevel@tonic-gate } 11707c478bd9Sstevel@tonic-gate 11717c478bd9Sstevel@tonic-gate 11727c478bd9Sstevel@tonic-gate /* 11737c478bd9Sstevel@tonic-gate * Check whether we can insert these tds? 11747c478bd9Sstevel@tonic-gate * At any point of time, we can insert maximum of 1024 isoc td's, 11757c478bd9Sstevel@tonic-gate * size of frame list table. 11767c478bd9Sstevel@tonic-gate */ 11777c478bd9Sstevel@tonic-gate if (isoc_req->isoc_pkts_count > UHCI_MAX_ISOC_PKTS) { 11787c478bd9Sstevel@tonic-gate 11797c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_ISOC, uhcip->uhci_log_hdl, 11807c478bd9Sstevel@tonic-gate "uhci_pipe_send_isoc_data: request too big"); 11817c478bd9Sstevel@tonic-gate 11827c478bd9Sstevel@tonic-gate return (USB_INVALID_REQUEST); 11837c478bd9Sstevel@tonic-gate } 11847c478bd9Sstevel@tonic-gate 11857c478bd9Sstevel@tonic-gate /* Add the TD into the Host Controller's isoc list */ 11867c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 11877c478bd9Sstevel@tonic-gate 1188fffe0b30Sqz error = uhci_state_is_operational(uhcip); 1189fffe0b30Sqz 1190fffe0b30Sqz if (error != USB_SUCCESS) { 1191fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 1192fffe0b30Sqz 1193fffe0b30Sqz return (error); 1194fffe0b30Sqz } 1195fffe0b30Sqz 11967c478bd9Sstevel@tonic-gate if ((error = uhci_insert_isoc_td(uhcip, ph, isoc_req, 11977c478bd9Sstevel@tonic-gate length, usb_flags)) != USB_SUCCESS) { 11987c478bd9Sstevel@tonic-gate 11997c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_ISOC, uhcip->uhci_log_hdl, 12007c478bd9Sstevel@tonic-gate "uhci_pipe_send_isoc_data: Unable to insert the isoc_req," 12017c478bd9Sstevel@tonic-gate "Error = %d", error); 12027c478bd9Sstevel@tonic-gate } 12037c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 12047c478bd9Sstevel@tonic-gate 12057c478bd9Sstevel@tonic-gate return (error); 12067c478bd9Sstevel@tonic-gate } 12077c478bd9Sstevel@tonic-gate 12087c478bd9Sstevel@tonic-gate 12097c478bd9Sstevel@tonic-gate /* 12107c478bd9Sstevel@tonic-gate * uhci_update_intr_td_data_toggle 12117c478bd9Sstevel@tonic-gate * Update the data toggle and save in the usba_device structure 12127c478bd9Sstevel@tonic-gate */ 12137c478bd9Sstevel@tonic-gate static void 12147c478bd9Sstevel@tonic-gate uhci_update_intr_td_data_toggle(uhci_state_t *uhcip, uhci_pipe_private_t *pp) 12157c478bd9Sstevel@tonic-gate { 12167c478bd9Sstevel@tonic-gate uint32_t paddr_tail, element_ptr; 12177c478bd9Sstevel@tonic-gate uhci_td_t *next_td; 12187c478bd9Sstevel@tonic-gate 12197c478bd9Sstevel@tonic-gate /* Find the next td that would have been executed */ 12207c478bd9Sstevel@tonic-gate element_ptr = GetQH32(uhcip, pp->pp_qh->element_ptr) & 1221fffe0b30Sqz QH_ELEMENT_PTR_MASK; 12227c478bd9Sstevel@tonic-gate next_td = TD_VADDR(element_ptr); 12237c478bd9Sstevel@tonic-gate paddr_tail = TD_PADDR(pp->pp_qh->td_tailp); 12247c478bd9Sstevel@tonic-gate 12257c478bd9Sstevel@tonic-gate /* 12267c478bd9Sstevel@tonic-gate * If element_ptr points to the dummy td, then the data toggle in 12277c478bd9Sstevel@tonic-gate * pp_data_toggle is correct. Otherwise update the data toggle in 12287c478bd9Sstevel@tonic-gate * the pipe private 12297c478bd9Sstevel@tonic-gate */ 12307c478bd9Sstevel@tonic-gate if (element_ptr != paddr_tail) { 12317c478bd9Sstevel@tonic-gate pp->pp_data_toggle = GetTD_dtogg(uhcip, next_td); 12327c478bd9Sstevel@tonic-gate } 12337c478bd9Sstevel@tonic-gate 12347c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 12357c478bd9Sstevel@tonic-gate "uhci_update_intr_td_data_toggle: " 12367c478bd9Sstevel@tonic-gate "pp %p toggle %x element ptr %x ptail %x", 1237112116d8Sfb (void *)pp, pp->pp_data_toggle, element_ptr, paddr_tail); 12387c478bd9Sstevel@tonic-gate 12397c478bd9Sstevel@tonic-gate uhci_save_data_toggle(pp); 12407c478bd9Sstevel@tonic-gate } 1241