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 /* 22fffe0b30Sqz * 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 * Universal Host Controller Driver (UHCI) 307c478bd9Sstevel@tonic-gate * 317c478bd9Sstevel@tonic-gate * The UHCI driver is a driver which interfaces to the Universal 327c478bd9Sstevel@tonic-gate * Serial Bus Driver (USBA) and the Host Controller (HC). The interface to 337c478bd9Sstevel@tonic-gate * the Host Controller is defined by the Universal Host Controller Interface. 347c478bd9Sstevel@tonic-gate * This file contains the code for HCDI entry points. 357c478bd9Sstevel@tonic-gate */ 367c478bd9Sstevel@tonic-gate #include <sys/usb/hcd/uhci/uhcid.h> 377c478bd9Sstevel@tonic-gate #include <sys/usb/hcd/uhci/uhcitgt.h> 387c478bd9Sstevel@tonic-gate #include <sys/usb/hcd/uhci/uhciutil.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, 290*112116d8Sfb "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, 439*112116d8Sfb "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 5597c478bd9Sstevel@tonic-gate 5607c478bd9Sstevel@tonic-gate /* 5617c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_ctrl_xfer: 5627c478bd9Sstevel@tonic-gate */ 5637c478bd9Sstevel@tonic-gate int 5647c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_ctrl_xfer( 5657c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 5667c478bd9Sstevel@tonic-gate usb_ctrl_req_t *ctrl_reqp, 5677c478bd9Sstevel@tonic-gate usb_flags_t flags) 5687c478bd9Sstevel@tonic-gate { 5697c478bd9Sstevel@tonic-gate uhci_state_t *uhcip = uhci_obtain_state( 570fffe0b30Sqz ph->p_usba_device->usb_root_hub_dip); 5717c478bd9Sstevel@tonic-gate uhci_pipe_private_t *pp = (uhci_pipe_private_t *)ph->p_hcd_private; 572fffe0b30Sqz int error; 5737c478bd9Sstevel@tonic-gate 5747c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 5757c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_ctrl_xfer: req=0x%p, ph=0x%p, flags=0x%x", 576*112116d8Sfb (void *)ctrl_reqp, (void *)ph, flags); 5777c478bd9Sstevel@tonic-gate 5787c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 579fffe0b30Sqz error = uhci_state_is_operational(uhcip); 580fffe0b30Sqz 581fffe0b30Sqz if (error != USB_SUCCESS) { 582fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 583fffe0b30Sqz 584fffe0b30Sqz return (error); 585fffe0b30Sqz } 5867c478bd9Sstevel@tonic-gate 5877c478bd9Sstevel@tonic-gate ASSERT(pp->pp_state == UHCI_PIPE_STATE_IDLE); 5887c478bd9Sstevel@tonic-gate 5897c478bd9Sstevel@tonic-gate /* 5907c478bd9Sstevel@tonic-gate * Check and handle root hub control request. 5917c478bd9Sstevel@tonic-gate */ 5927c478bd9Sstevel@tonic-gate if (ph->p_usba_device->usb_addr == ROOT_HUB_ADDR) { 5937c478bd9Sstevel@tonic-gate error = uhci_handle_root_hub_request(uhcip, ph, ctrl_reqp); 5947c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 5957c478bd9Sstevel@tonic-gate 5967c478bd9Sstevel@tonic-gate return (error); 5977c478bd9Sstevel@tonic-gate } 5987c478bd9Sstevel@tonic-gate 5997c478bd9Sstevel@tonic-gate /* Insert the td's on the endpoint */ 6007c478bd9Sstevel@tonic-gate if ((error = uhci_insert_ctrl_td(uhcip, ph, ctrl_reqp, flags)) != 6017c478bd9Sstevel@tonic-gate USB_SUCCESS) { 6027c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 6037c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_ctrl_xfer: No resources"); 6047c478bd9Sstevel@tonic-gate } 6057c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 6067c478bd9Sstevel@tonic-gate 6077c478bd9Sstevel@tonic-gate return (error); 6087c478bd9Sstevel@tonic-gate } 6097c478bd9Sstevel@tonic-gate 6107c478bd9Sstevel@tonic-gate 6117c478bd9Sstevel@tonic-gate /* 6127c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_bulk_xfer: 6137c478bd9Sstevel@tonic-gate */ 6147c478bd9Sstevel@tonic-gate int 6157c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_bulk_xfer(usba_pipe_handle_data_t *pipe_handle, 6167c478bd9Sstevel@tonic-gate usb_bulk_req_t *bulk_reqp, usb_flags_t usb_flags) 6177c478bd9Sstevel@tonic-gate { 6187c478bd9Sstevel@tonic-gate int error; 6197c478bd9Sstevel@tonic-gate uhci_state_t *uhcip; 6207c478bd9Sstevel@tonic-gate 6217c478bd9Sstevel@tonic-gate uhcip = uhci_obtain_state(pipe_handle->p_usba_device->usb_root_hub_dip); 6227c478bd9Sstevel@tonic-gate 6237c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 6247c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_bulk_xfer: Flags = 0x%x", usb_flags); 6257c478bd9Sstevel@tonic-gate 6267c478bd9Sstevel@tonic-gate /* Check the size of bulk request */ 6277c478bd9Sstevel@tonic-gate if (bulk_reqp->bulk_len > UHCI_BULK_MAX_XFER_SIZE) { 6287c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 6297c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_bulk_xfer: req size 0x%x is more than 0x%x", 6307c478bd9Sstevel@tonic-gate bulk_reqp->bulk_len, UHCI_BULK_MAX_XFER_SIZE); 6317c478bd9Sstevel@tonic-gate 6327c478bd9Sstevel@tonic-gate return (USB_FAILURE); 6337c478bd9Sstevel@tonic-gate } 6347c478bd9Sstevel@tonic-gate 6357c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 6367c478bd9Sstevel@tonic-gate 637fffe0b30Sqz error = uhci_state_is_operational(uhcip); 638fffe0b30Sqz 639fffe0b30Sqz if (error != USB_SUCCESS) { 640fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 641fffe0b30Sqz 642fffe0b30Sqz return (error); 643fffe0b30Sqz } 6447c478bd9Sstevel@tonic-gate /* Add the TD into the Host Controller's bulk list */ 6457c478bd9Sstevel@tonic-gate if ((error = uhci_insert_bulk_td(uhcip, pipe_handle, bulk_reqp, 6467c478bd9Sstevel@tonic-gate usb_flags)) != USB_SUCCESS) { 6477c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 6487c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_bulk_xfer: uhci_insert_bulk_td failed"); 6497c478bd9Sstevel@tonic-gate } 6507c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 6517c478bd9Sstevel@tonic-gate 6527c478bd9Sstevel@tonic-gate return (error); 6537c478bd9Sstevel@tonic-gate } 6547c478bd9Sstevel@tonic-gate 6557c478bd9Sstevel@tonic-gate 6567c478bd9Sstevel@tonic-gate /* 6577c478bd9Sstevel@tonic-gate * uhci_hcdi_bulk_transfer_size: 6587c478bd9Sstevel@tonic-gate * Return maximum bulk transfer size 6597c478bd9Sstevel@tonic-gate */ 6607c478bd9Sstevel@tonic-gate int 6617c478bd9Sstevel@tonic-gate uhci_hcdi_bulk_transfer_size( 6627c478bd9Sstevel@tonic-gate usba_device_t *usba_device, 6637c478bd9Sstevel@tonic-gate size_t *size) 6647c478bd9Sstevel@tonic-gate { 665fffe0b30Sqz uhci_state_t *uhcip = uhci_obtain_state( 666fffe0b30Sqz usba_device->usb_root_hub_dip); 667fffe0b30Sqz int rval; 6687c478bd9Sstevel@tonic-gate 6697c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 6707c478bd9Sstevel@tonic-gate "uhci_hcdi_bulk_transfer_size:"); 6717c478bd9Sstevel@tonic-gate 672fffe0b30Sqz mutex_enter(&uhcip->uhci_int_mutex); 673fffe0b30Sqz rval = uhci_state_is_operational(uhcip); 674fffe0b30Sqz 675fffe0b30Sqz if (rval != USB_SUCCESS) { 676fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 677fffe0b30Sqz 678fffe0b30Sqz return (rval); 679fffe0b30Sqz } 680fffe0b30Sqz 6817c478bd9Sstevel@tonic-gate *size = uhci_bulk_transfer_size; 682fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 6837c478bd9Sstevel@tonic-gate 6847c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 6857c478bd9Sstevel@tonic-gate } 6867c478bd9Sstevel@tonic-gate 6877c478bd9Sstevel@tonic-gate 6887c478bd9Sstevel@tonic-gate /* 6897c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_intr_xfer: 6907c478bd9Sstevel@tonic-gate */ 6917c478bd9Sstevel@tonic-gate int 6927c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_intr_xfer( 6937c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 6947c478bd9Sstevel@tonic-gate usb_intr_req_t *req, 6957c478bd9Sstevel@tonic-gate usb_flags_t flags) 6967c478bd9Sstevel@tonic-gate { 6977c478bd9Sstevel@tonic-gate uhci_state_t *uhcip = uhci_obtain_state( 698fffe0b30Sqz ph->p_usba_device->usb_root_hub_dip); 6997c478bd9Sstevel@tonic-gate 7007c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 701*112116d8Sfb "uhci_hcdi_pipe_intr_xfer: req=0x%p, uf=0x%x", (void *)req, flags); 7027c478bd9Sstevel@tonic-gate 7037c478bd9Sstevel@tonic-gate if (UHCI_XFER_DIR(&ph->p_ep) == USB_EP_DIR_IN) { 7047c478bd9Sstevel@tonic-gate 7057c478bd9Sstevel@tonic-gate return (uhci_start_periodic_pipe_polling(uhcip, ph, 706fffe0b30Sqz (usb_opaque_t)req, flags)); 7077c478bd9Sstevel@tonic-gate } else { 7087c478bd9Sstevel@tonic-gate 7097c478bd9Sstevel@tonic-gate return (uhci_send_intr_data(uhcip, ph, req, flags)); 7107c478bd9Sstevel@tonic-gate } 7117c478bd9Sstevel@tonic-gate } 7127c478bd9Sstevel@tonic-gate 7137c478bd9Sstevel@tonic-gate 7147c478bd9Sstevel@tonic-gate /* 7157c478bd9Sstevel@tonic-gate * uhci_send_intr_data(): 7167c478bd9Sstevel@tonic-gate * send data to interrupt out pipe 7177c478bd9Sstevel@tonic-gate */ 7187c478bd9Sstevel@tonic-gate static int 7197c478bd9Sstevel@tonic-gate uhci_send_intr_data( 7207c478bd9Sstevel@tonic-gate uhci_state_t *uhcip, 7217c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *pipe_handle, 7227c478bd9Sstevel@tonic-gate usb_intr_req_t *req, 7237c478bd9Sstevel@tonic-gate usb_flags_t flags) 7247c478bd9Sstevel@tonic-gate { 725fffe0b30Sqz int rval; 7267c478bd9Sstevel@tonic-gate 7277c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_LISTS, uhcip->uhci_log_hdl, 7287c478bd9Sstevel@tonic-gate "uhci_send_intr_data:"); 7297c478bd9Sstevel@tonic-gate 7307c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 7317c478bd9Sstevel@tonic-gate 732fffe0b30Sqz rval = uhci_state_is_operational(uhcip); 733fffe0b30Sqz 734fffe0b30Sqz if (rval != USB_SUCCESS) { 735fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 736fffe0b30Sqz 737fffe0b30Sqz return (rval); 738fffe0b30Sqz } 739fffe0b30Sqz 7407c478bd9Sstevel@tonic-gate /* Add the TD into the Host Controller's interrupt list */ 7417c478bd9Sstevel@tonic-gate if ((rval = uhci_insert_intr_td(uhcip, pipe_handle, req, flags)) != 7427c478bd9Sstevel@tonic-gate USB_SUCCESS) { 7437c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 7447c478bd9Sstevel@tonic-gate "uhci_send_intr_data: No resources"); 7457c478bd9Sstevel@tonic-gate } 7467c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 7477c478bd9Sstevel@tonic-gate 7487c478bd9Sstevel@tonic-gate return (rval); 7497c478bd9Sstevel@tonic-gate } 7507c478bd9Sstevel@tonic-gate 7517c478bd9Sstevel@tonic-gate 7527c478bd9Sstevel@tonic-gate /* 7537c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_stop_intr_polling() 7547c478bd9Sstevel@tonic-gate */ 7557c478bd9Sstevel@tonic-gate int 7567c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_stop_intr_polling( 7577c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *pipe_handle, 7587c478bd9Sstevel@tonic-gate usb_flags_t flags) 7597c478bd9Sstevel@tonic-gate { 7607c478bd9Sstevel@tonic-gate uhci_state_t *uhcip = 761fffe0b30Sqz uhci_obtain_state(pipe_handle->p_usba_device->usb_root_hub_dip); 762fffe0b30Sqz int rval; 7637c478bd9Sstevel@tonic-gate 7647c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_LISTS, uhcip->uhci_log_hdl, 7657c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_stop_intr_polling: ph = 0x%p fl = 0x%x", 7667c478bd9Sstevel@tonic-gate (void *)pipe_handle, flags); 767fffe0b30Sqz mutex_enter(&uhcip->uhci_int_mutex); 7687c478bd9Sstevel@tonic-gate 769fffe0b30Sqz rval = uhci_stop_periodic_pipe_polling(uhcip, pipe_handle, flags); 770fffe0b30Sqz 771fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 772fffe0b30Sqz 773fffe0b30Sqz return (rval); 7747c478bd9Sstevel@tonic-gate } 7757c478bd9Sstevel@tonic-gate 7767c478bd9Sstevel@tonic-gate 7777c478bd9Sstevel@tonic-gate /* 7787c478bd9Sstevel@tonic-gate * uhci_hcdi_get_current_frame_number 779fffe0b30Sqz * Get the current frame number. 780fffe0b30Sqz * Return whether the request is handled successfully. 7817c478bd9Sstevel@tonic-gate */ 782fffe0b30Sqz int 783fffe0b30Sqz uhci_hcdi_get_current_frame_number( 784fffe0b30Sqz usba_device_t *usba_device, 785fffe0b30Sqz usb_frame_number_t *frame_number) 7867c478bd9Sstevel@tonic-gate { 7877c478bd9Sstevel@tonic-gate uhci_state_t *uhcip = uhci_obtain_state(usba_device->usb_root_hub_dip); 788fffe0b30Sqz int rval; 7897c478bd9Sstevel@tonic-gate 7907c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 791fffe0b30Sqz rval = uhci_state_is_operational(uhcip); 792fffe0b30Sqz 793fffe0b30Sqz if (rval != USB_SUCCESS) { 794fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 795fffe0b30Sqz 796fffe0b30Sqz return (rval); 797fffe0b30Sqz } 798fffe0b30Sqz 799fffe0b30Sqz *frame_number = uhci_get_sw_frame_number(uhcip); 8007c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 8017c478bd9Sstevel@tonic-gate 8027c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 803*112116d8Sfb "uhci_hcdi_get_current_frame_number: %llx", 804*112116d8Sfb (unsigned long long)(*frame_number)); 8057c478bd9Sstevel@tonic-gate 806fffe0b30Sqz return (rval); 8077c478bd9Sstevel@tonic-gate } 8087c478bd9Sstevel@tonic-gate 8097c478bd9Sstevel@tonic-gate 8107c478bd9Sstevel@tonic-gate /* 8117c478bd9Sstevel@tonic-gate * uhci_hcdi_get_max_isoc_pkts 812fffe0b30Sqz * Get the maximum number of isoc packets per USB Isoch request. 813fffe0b30Sqz * Return whether the request is handled successfully. 8147c478bd9Sstevel@tonic-gate */ 815fffe0b30Sqz int 816fffe0b30Sqz uhci_hcdi_get_max_isoc_pkts( 817fffe0b30Sqz usba_device_t *usba_device, 818fffe0b30Sqz uint_t *max_isoc_pkts_per_request) 8197c478bd9Sstevel@tonic-gate { 8207c478bd9Sstevel@tonic-gate uhci_state_t *uhcip = uhci_obtain_state(usba_device->usb_root_hub_dip); 821fffe0b30Sqz int rval; 822fffe0b30Sqz 823fffe0b30Sqz mutex_enter(&uhcip->uhci_int_mutex); 824fffe0b30Sqz rval = uhci_state_is_operational(uhcip); 825fffe0b30Sqz 826fffe0b30Sqz if (rval != USB_SUCCESS) { 827fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 828fffe0b30Sqz 829fffe0b30Sqz return (rval); 830fffe0b30Sqz } 831fffe0b30Sqz 832fffe0b30Sqz *max_isoc_pkts_per_request = UHCI_MAX_ISOC_PKTS; 833fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 8347c478bd9Sstevel@tonic-gate 8357c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 8367c478bd9Sstevel@tonic-gate "uhci_hcdi_get_max_isoc_pkts: 0x%x", UHCI_MAX_ISOC_PKTS); 8377c478bd9Sstevel@tonic-gate 838fffe0b30Sqz return (rval); 8397c478bd9Sstevel@tonic-gate } 8407c478bd9Sstevel@tonic-gate 8417c478bd9Sstevel@tonic-gate 8427c478bd9Sstevel@tonic-gate /* 8437c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_isoc_xfer: 8447c478bd9Sstevel@tonic-gate */ 8457c478bd9Sstevel@tonic-gate int 8467c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_isoc_xfer( 8477c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 8487c478bd9Sstevel@tonic-gate usb_isoc_req_t *isoc_reqp, 8497c478bd9Sstevel@tonic-gate usb_flags_t flags) 8507c478bd9Sstevel@tonic-gate { 8517c478bd9Sstevel@tonic-gate uhci_state_t *uhcip; 8527c478bd9Sstevel@tonic-gate 8537c478bd9Sstevel@tonic-gate uhcip = uhci_obtain_state(ph->p_usba_device->usb_root_hub_dip); 8547c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 855*112116d8Sfb "uhci_hcdi_pipe_isoc_xfer: req=0x%p, uf=0x%x", 856*112116d8Sfb (void *)isoc_reqp, flags); 8577c478bd9Sstevel@tonic-gate 8587c478bd9Sstevel@tonic-gate if (UHCI_XFER_DIR(&ph->p_ep) == USB_EP_DIR_IN) { 8597c478bd9Sstevel@tonic-gate 8607c478bd9Sstevel@tonic-gate return (uhci_start_periodic_pipe_polling(uhcip, ph, 861fffe0b30Sqz (usb_opaque_t)isoc_reqp, flags)); 8627c478bd9Sstevel@tonic-gate } else { 8637c478bd9Sstevel@tonic-gate 8647c478bd9Sstevel@tonic-gate return (uhci_pipe_send_isoc_data(uhcip, ph, isoc_reqp, flags)); 8657c478bd9Sstevel@tonic-gate } 8667c478bd9Sstevel@tonic-gate } 8677c478bd9Sstevel@tonic-gate 8687c478bd9Sstevel@tonic-gate 8697c478bd9Sstevel@tonic-gate /* 8707c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_stop_isoc_polling() 8717c478bd9Sstevel@tonic-gate */ 8727c478bd9Sstevel@tonic-gate int 8737c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_stop_isoc_polling( 8747c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 8757c478bd9Sstevel@tonic-gate usb_flags_t flags) 8767c478bd9Sstevel@tonic-gate { 8777c478bd9Sstevel@tonic-gate uhci_state_t *uhcip = 878fffe0b30Sqz uhci_obtain_state(ph->p_usba_device->usb_root_hub_dip); 879fffe0b30Sqz int rval; 8807c478bd9Sstevel@tonic-gate 8817c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_LISTS, uhcip->uhci_log_hdl, 8827c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_stop_isoc_polling: ph = 0x%p fl = 0x%x", 8837c478bd9Sstevel@tonic-gate (void *)ph, flags); 8847c478bd9Sstevel@tonic-gate 885fffe0b30Sqz mutex_enter(&uhcip->uhci_int_mutex); 886fffe0b30Sqz rval = uhci_state_is_operational(uhcip); 887fffe0b30Sqz 888fffe0b30Sqz if (rval != USB_SUCCESS) { 889fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 890fffe0b30Sqz 891fffe0b30Sqz return (rval); 892fffe0b30Sqz } 893fffe0b30Sqz 894fffe0b30Sqz rval = uhci_stop_periodic_pipe_polling(uhcip, ph, flags); 895fffe0b30Sqz 896fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 897fffe0b30Sqz 898fffe0b30Sqz return (rval); 8997c478bd9Sstevel@tonic-gate } 9007c478bd9Sstevel@tonic-gate 9017c478bd9Sstevel@tonic-gate 9027c478bd9Sstevel@tonic-gate /* 9037c478bd9Sstevel@tonic-gate * uhci_start_periodic_pipe_polling: 9047c478bd9Sstevel@tonic-gate */ 9057c478bd9Sstevel@tonic-gate static int 9067c478bd9Sstevel@tonic-gate uhci_start_periodic_pipe_polling( 9077c478bd9Sstevel@tonic-gate uhci_state_t *uhcip, 9087c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 9097c478bd9Sstevel@tonic-gate usb_opaque_t in_reqp, 9107c478bd9Sstevel@tonic-gate usb_flags_t flags) 9117c478bd9Sstevel@tonic-gate { 9127c478bd9Sstevel@tonic-gate int n, num_tds; 913fffe0b30Sqz int error; 9147c478bd9Sstevel@tonic-gate usb_intr_req_t *intr_reqp = (usb_intr_req_t *)in_reqp; 9157c478bd9Sstevel@tonic-gate usb_ep_descr_t *eptd = &ph->p_ep; 9167c478bd9Sstevel@tonic-gate uhci_pipe_private_t *pp = (uhci_pipe_private_t *)ph->p_hcd_private; 9177c478bd9Sstevel@tonic-gate 9187c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 9197c478bd9Sstevel@tonic-gate "uhci_start_periodic_pipe_polling: flags: 0x%x, ep%d", 9207c478bd9Sstevel@tonic-gate flags, eptd->bEndpointAddress); 9217c478bd9Sstevel@tonic-gate 9227c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 9237c478bd9Sstevel@tonic-gate 924fffe0b30Sqz error = uhci_state_is_operational(uhcip); 925fffe0b30Sqz 926fffe0b30Sqz if (error != USB_SUCCESS) { 927fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 928fffe0b30Sqz 929fffe0b30Sqz return (error); 930fffe0b30Sqz } 931fffe0b30Sqz 9327c478bd9Sstevel@tonic-gate if (ph->p_usba_device->usb_addr == ROOT_HUB_ADDR) { 9337c478bd9Sstevel@tonic-gate uint_t pipe_state = uhcip->uhci_root_hub.rh_pipe_state; 9347c478bd9Sstevel@tonic-gate 9357c478bd9Sstevel@tonic-gate ASSERT(pipe_state == UHCI_PIPE_STATE_IDLE); 9367c478bd9Sstevel@tonic-gate ASSERT(UHCI_XFER_DIR(eptd) == USB_EP_DIR_IN); 9377c478bd9Sstevel@tonic-gate 9387c478bd9Sstevel@tonic-gate /* ONE_XFER not supported */ 9397c478bd9Sstevel@tonic-gate ASSERT((intr_reqp->intr_attributes & 9407c478bd9Sstevel@tonic-gate USB_ATTRS_ONE_XFER) == 0); 9417c478bd9Sstevel@tonic-gate ASSERT(uhcip->uhci_root_hub.rh_client_intr_req == NULL); 9427c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_client_intr_req = intr_reqp; 9437c478bd9Sstevel@tonic-gate 9447c478bd9Sstevel@tonic-gate if ((error = uhci_root_hub_allocate_intr_pipe_resource( 9457c478bd9Sstevel@tonic-gate uhcip, flags)) != USB_SUCCESS) { 9467c478bd9Sstevel@tonic-gate /* reset the client interrupt request pointer */ 9477c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_client_intr_req = NULL; 9487c478bd9Sstevel@tonic-gate 9497c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 9507c478bd9Sstevel@tonic-gate 9517c478bd9Sstevel@tonic-gate return (error); 9527c478bd9Sstevel@tonic-gate } 9537c478bd9Sstevel@tonic-gate 9547c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_pipe_state = USB_PIPE_STATE_ACTIVE; 9557c478bd9Sstevel@tonic-gate 9567c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 9577c478bd9Sstevel@tonic-gate "uhci_start_periodic_pipe_polling: " 9587c478bd9Sstevel@tonic-gate "Start intr polling for root hub successful"); 9597c478bd9Sstevel@tonic-gate 9607c478bd9Sstevel@tonic-gate /* check if we need to send the reset data up? */ 9617c478bd9Sstevel@tonic-gate if (uhcip->uhci_root_hub.rh_status) { 9627c478bd9Sstevel@tonic-gate uhci_root_hub_reset_occurred(uhcip, 9637c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_status - 1); 9647c478bd9Sstevel@tonic-gate 9657c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_status = 0; 9667c478bd9Sstevel@tonic-gate } 9677c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 9687c478bd9Sstevel@tonic-gate 9697c478bd9Sstevel@tonic-gate return (error); 9707c478bd9Sstevel@tonic-gate } 9717c478bd9Sstevel@tonic-gate 9727c478bd9Sstevel@tonic-gate /* save the original client's periodic IN request */ 9737c478bd9Sstevel@tonic-gate pp->pp_client_periodic_in_reqp = in_reqp; 9747c478bd9Sstevel@tonic-gate 9757c478bd9Sstevel@tonic-gate ASSERT(pp->pp_state != UHCI_PIPE_STATE_ACTIVE); 9767c478bd9Sstevel@tonic-gate /* 9777c478bd9Sstevel@tonic-gate * 9787c478bd9Sstevel@tonic-gate * This pipe is uninitialized. If it is an isoc 9797c478bd9Sstevel@tonic-gate * receive request, insert four times the same 9807c478bd9Sstevel@tonic-gate * request so that we do not lose any frames. 9817c478bd9Sstevel@tonic-gate */ 9827c478bd9Sstevel@tonic-gate if (UHCI_XFER_TYPE(eptd) == USB_EP_ATTR_ISOCH) { 9837c478bd9Sstevel@tonic-gate for (n = 0; n < 5; n++) { 9847c478bd9Sstevel@tonic-gate if ((error = uhci_start_isoc_receive_polling( 9857c478bd9Sstevel@tonic-gate uhcip, ph, NULL, flags)) != USB_SUCCESS) { 9867c478bd9Sstevel@tonic-gate 9877c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_INTR, 9887c478bd9Sstevel@tonic-gate uhcip->uhci_log_hdl, 9897c478bd9Sstevel@tonic-gate "uhci_start_periodic_pipe_polling: " 9907c478bd9Sstevel@tonic-gate "Start isoc polling failed %d", n); 9917c478bd9Sstevel@tonic-gate 9927c478bd9Sstevel@tonic-gate pp->pp_client_periodic_in_reqp = NULL; 9937c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 9947c478bd9Sstevel@tonic-gate 9957c478bd9Sstevel@tonic-gate return (error); 9967c478bd9Sstevel@tonic-gate } 9977c478bd9Sstevel@tonic-gate } 9987c478bd9Sstevel@tonic-gate } 9997c478bd9Sstevel@tonic-gate 10007c478bd9Sstevel@tonic-gate if (UHCI_XFER_TYPE(eptd) == USB_EP_ATTR_INTR) { 10017c478bd9Sstevel@tonic-gate if ((pp->pp_node < POLLING_FREQ_7MS) && 10027c478bd9Sstevel@tonic-gate (!(intr_reqp->intr_attributes & USB_ATTRS_ONE_XFER))) { 10037c478bd9Sstevel@tonic-gate num_tds = 5; 10047c478bd9Sstevel@tonic-gate } else { 10057c478bd9Sstevel@tonic-gate num_tds = 1; 10067c478bd9Sstevel@tonic-gate } 10077c478bd9Sstevel@tonic-gate 10087c478bd9Sstevel@tonic-gate /* 10097c478bd9Sstevel@tonic-gate * This pipe is uninitialized. 10107c478bd9Sstevel@tonic-gate * Insert a TD on the interrupt ED. 10117c478bd9Sstevel@tonic-gate */ 10127c478bd9Sstevel@tonic-gate for (n = 0; n < num_tds; n++) { 10137c478bd9Sstevel@tonic-gate if ((error = uhci_insert_intr_td(uhcip, ph, NULL, 10147c478bd9Sstevel@tonic-gate flags)) != USB_SUCCESS) { 10157c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_INTR, 10167c478bd9Sstevel@tonic-gate uhcip->uhci_log_hdl, 10177c478bd9Sstevel@tonic-gate "uhci_start_periodic_pipe_polling: " 10187c478bd9Sstevel@tonic-gate "Start polling failed"); 10197c478bd9Sstevel@tonic-gate 10207c478bd9Sstevel@tonic-gate pp->pp_client_periodic_in_reqp = NULL; 10217c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 10227c478bd9Sstevel@tonic-gate 10237c478bd9Sstevel@tonic-gate return (error); 10247c478bd9Sstevel@tonic-gate } 10257c478bd9Sstevel@tonic-gate } 10267c478bd9Sstevel@tonic-gate } 10277c478bd9Sstevel@tonic-gate 10287c478bd9Sstevel@tonic-gate pp->pp_state = UHCI_PIPE_STATE_ACTIVE; 10297c478bd9Sstevel@tonic-gate 10307c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 10317c478bd9Sstevel@tonic-gate 10327c478bd9Sstevel@tonic-gate return (error); 10337c478bd9Sstevel@tonic-gate } 10347c478bd9Sstevel@tonic-gate 10357c478bd9Sstevel@tonic-gate 10367c478bd9Sstevel@tonic-gate /* 10377c478bd9Sstevel@tonic-gate * uhci_hcdi_periodic_pipe_stop_polling: 10387c478bd9Sstevel@tonic-gate */ 10397c478bd9Sstevel@tonic-gate static int 10407c478bd9Sstevel@tonic-gate uhci_stop_periodic_pipe_polling(uhci_state_t *uhcip, 10417c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, usb_flags_t flags) 10427c478bd9Sstevel@tonic-gate { 10437c478bd9Sstevel@tonic-gate uhci_pipe_private_t *pp = (uhci_pipe_private_t *)ph->p_hcd_private; 10447c478bd9Sstevel@tonic-gate usb_ep_descr_t *eptd = &ph->p_ep; 10457c478bd9Sstevel@tonic-gate 10467c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 10477c478bd9Sstevel@tonic-gate "uhci_stop_periodic_pipe_polling: flags = 0x%x", flags); 10487c478bd9Sstevel@tonic-gate 1049fffe0b30Sqz ASSERT(mutex_owned(&uhcip->uhci_int_mutex)); 10507c478bd9Sstevel@tonic-gate if (ph->p_usba_device->usb_addr == ROOT_HUB_ADDR) { 10517c478bd9Sstevel@tonic-gate ASSERT(UHCI_XFER_DIR(eptd) == USB_EP_DIR_IN); 10527c478bd9Sstevel@tonic-gate 10537c478bd9Sstevel@tonic-gate if (uhcip->uhci_root_hub.rh_pipe_state == 10547c478bd9Sstevel@tonic-gate UHCI_PIPE_STATE_ACTIVE) { 10557c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_pipe_state = 1056fffe0b30Sqz UHCI_PIPE_STATE_IDLE; 10577c478bd9Sstevel@tonic-gate 10587c478bd9Sstevel@tonic-gate /* Do interrupt pipe cleanup */ 10597c478bd9Sstevel@tonic-gate uhci_root_hub_intr_pipe_cleanup(uhcip, 1060fffe0b30Sqz USB_CR_STOPPED_POLLING); 10617c478bd9Sstevel@tonic-gate 10627c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 10637c478bd9Sstevel@tonic-gate "uhci_stop_periodic_pipe_polling: Stop intr " 10647c478bd9Sstevel@tonic-gate "polling for root hub successful"); 10657c478bd9Sstevel@tonic-gate 10667c478bd9Sstevel@tonic-gate } else { 10677c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_INTR, uhcip->uhci_log_hdl, 10687c478bd9Sstevel@tonic-gate "uhci_stop_periodic_pipe_polling: " 10697c478bd9Sstevel@tonic-gate "Intr polling for root hub is already stopped"); 10707c478bd9Sstevel@tonic-gate } 10717c478bd9Sstevel@tonic-gate 10727c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 10737c478bd9Sstevel@tonic-gate } 10747c478bd9Sstevel@tonic-gate 10757c478bd9Sstevel@tonic-gate if (pp->pp_state != UHCI_PIPE_STATE_ACTIVE) { 10767c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_INTR, uhcip->uhci_log_hdl, 10777c478bd9Sstevel@tonic-gate "uhci_stop_periodic_pipe_polling: Polling already stopped"); 10787c478bd9Sstevel@tonic-gate 10797c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 10807c478bd9Sstevel@tonic-gate } 10817c478bd9Sstevel@tonic-gate 10827c478bd9Sstevel@tonic-gate /* 10837c478bd9Sstevel@tonic-gate * Set the terminate bits in all the tds in the queue and 10847c478bd9Sstevel@tonic-gate * in the element_ptr. 10857c478bd9Sstevel@tonic-gate * Do not deallocate the bandwidth or tear down the DMA 10867c478bd9Sstevel@tonic-gate */ 10877c478bd9Sstevel@tonic-gate uhci_modify_td_active_bits(uhcip, pp); 10887c478bd9Sstevel@tonic-gate (void) uhci_wait_for_sof(uhcip); 10897c478bd9Sstevel@tonic-gate 10907c478bd9Sstevel@tonic-gate if (UHCI_XFER_TYPE(eptd) == USB_EP_ATTR_ISOCH) { 10917c478bd9Sstevel@tonic-gate uhci_remove_isoc_tds_tws(uhcip, pp); 10927c478bd9Sstevel@tonic-gate pp->pp_state = UHCI_PIPE_STATE_IDLE; 10937c478bd9Sstevel@tonic-gate } else { 10947c478bd9Sstevel@tonic-gate UHCI_SET_TERMINATE_BIT(pp->pp_qh->element_ptr); 10957c478bd9Sstevel@tonic-gate uhci_update_intr_td_data_toggle(uhcip, pp); 10967c478bd9Sstevel@tonic-gate SetQH32(uhcip, pp->pp_qh->element_ptr, 10977c478bd9Sstevel@tonic-gate TD_PADDR(pp->pp_qh->td_tailp)); 10987c478bd9Sstevel@tonic-gate uhci_remove_tds_tws(uhcip, ph); 10997c478bd9Sstevel@tonic-gate } 11007c478bd9Sstevel@tonic-gate 11017c478bd9Sstevel@tonic-gate pp->pp_state = UHCI_PIPE_STATE_IDLE; 11027c478bd9Sstevel@tonic-gate 11037c478bd9Sstevel@tonic-gate if (pp->pp_client_periodic_in_reqp) { 11047c478bd9Sstevel@tonic-gate uhci_hcdi_callback(uhcip, pp, ph, NULL, USB_CR_STOPPED_POLLING); 11057c478bd9Sstevel@tonic-gate } 11067c478bd9Sstevel@tonic-gate 11077c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 11087c478bd9Sstevel@tonic-gate } 11097c478bd9Sstevel@tonic-gate 11107c478bd9Sstevel@tonic-gate 11117c478bd9Sstevel@tonic-gate /* 11127c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_send_isoc_data: 11137c478bd9Sstevel@tonic-gate * Handles the isoc write request. 11147c478bd9Sstevel@tonic-gate */ 11157c478bd9Sstevel@tonic-gate static int 11167c478bd9Sstevel@tonic-gate uhci_pipe_send_isoc_data( 11177c478bd9Sstevel@tonic-gate uhci_state_t *uhcip, 11187c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 11197c478bd9Sstevel@tonic-gate usb_isoc_req_t *isoc_req, 11207c478bd9Sstevel@tonic-gate usb_flags_t usb_flags) 11217c478bd9Sstevel@tonic-gate { 11227c478bd9Sstevel@tonic-gate int error; 11237c478bd9Sstevel@tonic-gate size_t max_isoc_xfer_sz, length; 11247c478bd9Sstevel@tonic-gate 11257c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 11267c478bd9Sstevel@tonic-gate "uhci_pipe_send_isoc_data: isoc_req = %p flags = %x", 1127*112116d8Sfb (void *)isoc_req, usb_flags); 11287c478bd9Sstevel@tonic-gate 11297c478bd9Sstevel@tonic-gate ASSERT(isoc_req->isoc_pkts_count < UHCI_MAX_ISOC_PKTS); 11307c478bd9Sstevel@tonic-gate 11317c478bd9Sstevel@tonic-gate /* Calculate the maximum isochronous transfer size */ 11327c478bd9Sstevel@tonic-gate max_isoc_xfer_sz = UHCI_MAX_ISOC_PKTS * ph->p_ep.wMaxPacketSize; 11337c478bd9Sstevel@tonic-gate 11347c478bd9Sstevel@tonic-gate /* Check the size of isochronous request */ 11357c478bd9Sstevel@tonic-gate ASSERT(isoc_req->isoc_data != NULL); 11367c478bd9Sstevel@tonic-gate length = isoc_req->isoc_data->b_wptr - isoc_req->isoc_data->b_rptr; 11377c478bd9Sstevel@tonic-gate 11387c478bd9Sstevel@tonic-gate if (length > max_isoc_xfer_sz) { 11397c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 11407c478bd9Sstevel@tonic-gate "uhci_pipe_send_isoc_data: Maximum isoc request size %lx " 11417c478bd9Sstevel@tonic-gate "Given isoc request size %lx", max_isoc_xfer_sz, length); 11427c478bd9Sstevel@tonic-gate 11437c478bd9Sstevel@tonic-gate return (USB_INVALID_REQUEST); 11447c478bd9Sstevel@tonic-gate } 11457c478bd9Sstevel@tonic-gate 11467c478bd9Sstevel@tonic-gate 11477c478bd9Sstevel@tonic-gate /* 11487c478bd9Sstevel@tonic-gate * Check whether we can insert these tds? 11497c478bd9Sstevel@tonic-gate * At any point of time, we can insert maximum of 1024 isoc td's, 11507c478bd9Sstevel@tonic-gate * size of frame list table. 11517c478bd9Sstevel@tonic-gate */ 11527c478bd9Sstevel@tonic-gate if (isoc_req->isoc_pkts_count > UHCI_MAX_ISOC_PKTS) { 11537c478bd9Sstevel@tonic-gate 11547c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_ISOC, uhcip->uhci_log_hdl, 11557c478bd9Sstevel@tonic-gate "uhci_pipe_send_isoc_data: request too big"); 11567c478bd9Sstevel@tonic-gate 11577c478bd9Sstevel@tonic-gate return (USB_INVALID_REQUEST); 11587c478bd9Sstevel@tonic-gate } 11597c478bd9Sstevel@tonic-gate 11607c478bd9Sstevel@tonic-gate /* Add the TD into the Host Controller's isoc list */ 11617c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 11627c478bd9Sstevel@tonic-gate 1163fffe0b30Sqz error = uhci_state_is_operational(uhcip); 1164fffe0b30Sqz 1165fffe0b30Sqz if (error != USB_SUCCESS) { 1166fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 1167fffe0b30Sqz 1168fffe0b30Sqz return (error); 1169fffe0b30Sqz } 1170fffe0b30Sqz 11717c478bd9Sstevel@tonic-gate if ((error = uhci_insert_isoc_td(uhcip, ph, isoc_req, 11727c478bd9Sstevel@tonic-gate length, usb_flags)) != USB_SUCCESS) { 11737c478bd9Sstevel@tonic-gate 11747c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_ISOC, uhcip->uhci_log_hdl, 11757c478bd9Sstevel@tonic-gate "uhci_pipe_send_isoc_data: Unable to insert the isoc_req," 11767c478bd9Sstevel@tonic-gate "Error = %d", error); 11777c478bd9Sstevel@tonic-gate } 11787c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 11797c478bd9Sstevel@tonic-gate 11807c478bd9Sstevel@tonic-gate return (error); 11817c478bd9Sstevel@tonic-gate } 11827c478bd9Sstevel@tonic-gate 11837c478bd9Sstevel@tonic-gate 11847c478bd9Sstevel@tonic-gate /* 11857c478bd9Sstevel@tonic-gate * uhci_update_intr_td_data_toggle 11867c478bd9Sstevel@tonic-gate * Update the data toggle and save in the usba_device structure 11877c478bd9Sstevel@tonic-gate */ 11887c478bd9Sstevel@tonic-gate static void 11897c478bd9Sstevel@tonic-gate uhci_update_intr_td_data_toggle(uhci_state_t *uhcip, uhci_pipe_private_t *pp) 11907c478bd9Sstevel@tonic-gate { 11917c478bd9Sstevel@tonic-gate uint32_t paddr_tail, element_ptr; 11927c478bd9Sstevel@tonic-gate uhci_td_t *next_td; 11937c478bd9Sstevel@tonic-gate 11947c478bd9Sstevel@tonic-gate /* Find the next td that would have been executed */ 11957c478bd9Sstevel@tonic-gate element_ptr = GetQH32(uhcip, pp->pp_qh->element_ptr) & 1196fffe0b30Sqz QH_ELEMENT_PTR_MASK; 11977c478bd9Sstevel@tonic-gate next_td = TD_VADDR(element_ptr); 11987c478bd9Sstevel@tonic-gate paddr_tail = TD_PADDR(pp->pp_qh->td_tailp); 11997c478bd9Sstevel@tonic-gate 12007c478bd9Sstevel@tonic-gate /* 12017c478bd9Sstevel@tonic-gate * If element_ptr points to the dummy td, then the data toggle in 12027c478bd9Sstevel@tonic-gate * pp_data_toggle is correct. Otherwise update the data toggle in 12037c478bd9Sstevel@tonic-gate * the pipe private 12047c478bd9Sstevel@tonic-gate */ 12057c478bd9Sstevel@tonic-gate if (element_ptr != paddr_tail) { 12067c478bd9Sstevel@tonic-gate pp->pp_data_toggle = GetTD_dtogg(uhcip, next_td); 12077c478bd9Sstevel@tonic-gate } 12087c478bd9Sstevel@tonic-gate 12097c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 12107c478bd9Sstevel@tonic-gate "uhci_update_intr_td_data_toggle: " 12117c478bd9Sstevel@tonic-gate "pp %p toggle %x element ptr %x ptail %x", 1212*112116d8Sfb (void *)pp, pp->pp_data_toggle, element_ptr, paddr_tail); 12137c478bd9Sstevel@tonic-gate 12147c478bd9Sstevel@tonic-gate uhci_save_data_toggle(pp); 12157c478bd9Sstevel@tonic-gate } 1216