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> 39*22eb7cb5Sgd #include <sys/strsun.h> 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate /* function prototypes */ 427c478bd9Sstevel@tonic-gate static int uhci_pipe_send_isoc_data(uhci_state_t *uhcip, 437c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, usb_isoc_req_t *isoc_req, 447c478bd9Sstevel@tonic-gate usb_flags_t usb_flags); 457c478bd9Sstevel@tonic-gate static int uhci_send_intr_data(uhci_state_t *uhcip, 467c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *pipe_handle, 477c478bd9Sstevel@tonic-gate usb_intr_req_t *req, 487c478bd9Sstevel@tonic-gate usb_flags_t flags); 497c478bd9Sstevel@tonic-gate static int uhci_start_periodic_pipe_polling(uhci_state_t *uhcip, 507c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 517c478bd9Sstevel@tonic-gate usb_opaque_t reqp, 527c478bd9Sstevel@tonic-gate usb_flags_t flags); 537c478bd9Sstevel@tonic-gate static int uhci_stop_periodic_pipe_polling(uhci_state_t *uhcip, 547c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 557c478bd9Sstevel@tonic-gate usb_flags_t flags); 567c478bd9Sstevel@tonic-gate static void uhci_update_intr_td_data_toggle(uhci_state_t *uhcip, 577c478bd9Sstevel@tonic-gate uhci_pipe_private_t *pp); 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate /* Maximum bulk transfer size */ 614610e4a0Sfrits int uhci_bulk_transfer_size = UHCI_BULK_MAX_XFER_SIZE; 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate /* 647c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_open: 657c478bd9Sstevel@tonic-gate * Member of HCD Ops structure and called during client specific pipe open 667c478bd9Sstevel@tonic-gate * Add the pipe to the data structure representing the device and allocate 677c478bd9Sstevel@tonic-gate * bandwidth for the pipe if it is a interrupt or isochronous endpoint. 687c478bd9Sstevel@tonic-gate */ 697c478bd9Sstevel@tonic-gate int 707c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_open(usba_pipe_handle_data_t *ph, usb_flags_t flags) 717c478bd9Sstevel@tonic-gate { 727c478bd9Sstevel@tonic-gate uint_t node = 0; 737c478bd9Sstevel@tonic-gate usb_addr_t usb_addr; 747c478bd9Sstevel@tonic-gate uhci_state_t *uhcip; 757c478bd9Sstevel@tonic-gate uhci_pipe_private_t *pp; 76fffe0b30Sqz int rval, error = USB_SUCCESS; 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate ASSERT(ph); 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate usb_addr = ph->p_usba_device->usb_addr; 817c478bd9Sstevel@tonic-gate uhcip = uhci_obtain_state(ph->p_usba_device->usb_root_hub_dip); 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 847c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_open: addr = 0x%x, ep%d", usb_addr, 857c478bd9Sstevel@tonic-gate ph->p_ep.bEndpointAddress & USB_EP_NUM_MASK); 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate sema_p(&uhcip->uhci_ocsem); 887c478bd9Sstevel@tonic-gate 89fffe0b30Sqz mutex_enter(&uhcip->uhci_int_mutex); 90fffe0b30Sqz rval = uhci_state_is_operational(uhcip); 91fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 92fffe0b30Sqz 93fffe0b30Sqz if (rval != USB_SUCCESS) { 94fffe0b30Sqz sema_v(&uhcip->uhci_ocsem); 95fffe0b30Sqz 96fffe0b30Sqz return (rval); 97fffe0b30Sqz } 98fffe0b30Sqz 997c478bd9Sstevel@tonic-gate /* 1007c478bd9Sstevel@tonic-gate * Return failure immediately for any other pipe open on the root hub 1017c478bd9Sstevel@tonic-gate * except control or interrupt pipe. 1027c478bd9Sstevel@tonic-gate */ 1037c478bd9Sstevel@tonic-gate if (usb_addr == ROOT_HUB_ADDR) { 1047c478bd9Sstevel@tonic-gate switch (UHCI_XFER_TYPE(&ph->p_ep)) { 1057c478bd9Sstevel@tonic-gate case USB_EP_ATTR_CONTROL: 1067c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 1077c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_open: Root hub control pipe"); 1087c478bd9Sstevel@tonic-gate break; 1097c478bd9Sstevel@tonic-gate case USB_EP_ATTR_INTR: 1107c478bd9Sstevel@tonic-gate ASSERT(UHCI_XFER_DIR(&ph->p_ep) == USB_EP_DIR_IN); 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 1137c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_intr_pipe_handle = ph; 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate /* 1167c478bd9Sstevel@tonic-gate * Set the state of the root hub interrupt 1177c478bd9Sstevel@tonic-gate * pipe as IDLE. 1187c478bd9Sstevel@tonic-gate */ 1197c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_pipe_state = 120fffe0b30Sqz UHCI_PIPE_STATE_IDLE; 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate ASSERT(uhcip->uhci_root_hub.rh_client_intr_req == NULL); 1237c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_client_intr_req = NULL; 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate ASSERT(uhcip->uhci_root_hub.rh_curr_intr_reqp == NULL); 1267c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_curr_intr_reqp = NULL; 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 1297c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_open: Root hub interrupt " 1307c478bd9Sstevel@tonic-gate "pipe open succeeded"); 1317c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 1327c478bd9Sstevel@tonic-gate sema_v(&uhcip->uhci_ocsem); 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 1357c478bd9Sstevel@tonic-gate default: 1367c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 1377c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_open: Root hub pipe open failed"); 1387c478bd9Sstevel@tonic-gate sema_v(&uhcip->uhci_ocsem); 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate return (USB_FAILURE); 1417c478bd9Sstevel@tonic-gate } 1427c478bd9Sstevel@tonic-gate } 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate /* 1457c478bd9Sstevel@tonic-gate * A portion of the bandwidth is reserved for the non-periodic 1467c478bd9Sstevel@tonic-gate * transfers i.e control and bulk transfers in each of one 1477c478bd9Sstevel@tonic-gate * mill second frame period & usually it will be 10% of frame 1487c478bd9Sstevel@tonic-gate * period. Hence there is no need to check for the available 1497c478bd9Sstevel@tonic-gate * bandwidth before adding the control or bulk endpoints. 1507c478bd9Sstevel@tonic-gate * 1517c478bd9Sstevel@tonic-gate * There is a need to check for the available bandwidth before 1527c478bd9Sstevel@tonic-gate * adding the periodic transfers i.e interrupt & isochronous, since 1537c478bd9Sstevel@tonic-gate * all these periodic transfers are guaranteed transfers. Usually, 1547c478bd9Sstevel@tonic-gate * 90% of the total frame time is reserved for periodic transfers. 1557c478bd9Sstevel@tonic-gate */ 1567c478bd9Sstevel@tonic-gate if (UHCI_PERIODIC_ENDPOINT(&ph->p_ep)) { 1577c478bd9Sstevel@tonic-gate /* Zero Max Packet size endpoints are not supported */ 1587c478bd9Sstevel@tonic-gate if (ph->p_ep.wMaxPacketSize == 0) { 1597c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 1607c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_open: Zero length packet"); 1617c478bd9Sstevel@tonic-gate sema_v(&uhcip->uhci_ocsem); 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate return (USB_FAILURE); 1647c478bd9Sstevel@tonic-gate } 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 1677c478bd9Sstevel@tonic-gate mutex_enter(&ph->p_mutex); 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate error = uhci_allocate_bandwidth(uhcip, ph, &node); 1707c478bd9Sstevel@tonic-gate if (error != USB_SUCCESS) { 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 1737c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_open: Bandwidth allocation failed"); 1747c478bd9Sstevel@tonic-gate mutex_exit(&ph->p_mutex); 1757c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 1767c478bd9Sstevel@tonic-gate sema_v(&uhcip->uhci_ocsem); 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate return (error); 1797c478bd9Sstevel@tonic-gate } 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate mutex_exit(&ph->p_mutex); 1827c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 1837c478bd9Sstevel@tonic-gate } 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate /* Create the HCD pipe private structure */ 1867c478bd9Sstevel@tonic-gate pp = kmem_zalloc(sizeof (uhci_pipe_private_t), 1877c478bd9Sstevel@tonic-gate (flags & USB_FLAGS_SLEEP) ? KM_SLEEP : KM_NOSLEEP); 1887c478bd9Sstevel@tonic-gate if (pp == NULL) { 1897c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 1907c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_open: pp allocation failure"); 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate if (UHCI_PERIODIC_ENDPOINT(&ph->p_ep)) { 1937c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 1947c478bd9Sstevel@tonic-gate uhci_deallocate_bandwidth(uhcip, ph); 1957c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 1967c478bd9Sstevel@tonic-gate } 1977c478bd9Sstevel@tonic-gate sema_v(&uhcip->uhci_ocsem); 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate return (USB_NO_RESOURCES); 2007c478bd9Sstevel@tonic-gate } 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 203fffe0b30Sqz rval = uhci_state_is_operational(uhcip); 204fffe0b30Sqz 205fffe0b30Sqz if (rval != USB_SUCCESS) { 206fffe0b30Sqz kmem_free(ph, sizeof (uhci_pipe_private_t)); 207fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 208fffe0b30Sqz sema_v(&uhcip->uhci_ocsem); 209fffe0b30Sqz 210fffe0b30Sqz return (rval); 211fffe0b30Sqz } 2127c478bd9Sstevel@tonic-gate pp->pp_node = node; /* Store the node in the interrupt lattice */ 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate /* Initialize frame number */ 2157c478bd9Sstevel@tonic-gate pp->pp_frame_num = INVALID_FRNUM; 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate /* Set the state of pipe as IDLE */ 2187c478bd9Sstevel@tonic-gate pp->pp_state = UHCI_PIPE_STATE_IDLE; 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate /* Store a pointer to the pipe handle */ 2217c478bd9Sstevel@tonic-gate pp->pp_pipe_handle = ph; 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate /* Store the pointer in the pipe handle */ 2247c478bd9Sstevel@tonic-gate mutex_enter(&ph->p_mutex); 2257c478bd9Sstevel@tonic-gate ph->p_hcd_private = (usb_opaque_t)pp; 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate /* Store a copy of the pipe policy */ 2287c478bd9Sstevel@tonic-gate bcopy(&ph->p_policy, &pp->pp_policy, sizeof (usb_pipe_policy_t)); 2297c478bd9Sstevel@tonic-gate mutex_exit(&ph->p_mutex); 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate /* don't check for ROOT_HUB here anymore */ 2327c478bd9Sstevel@tonic-gate if (UHCI_XFER_TYPE(&ph->p_ep) != USB_EP_ATTR_ISOCH) { 2337c478bd9Sstevel@tonic-gate /* Allocate the host controller endpoint descriptor */ 2347c478bd9Sstevel@tonic-gate pp->pp_qh = uhci_alloc_queue_head(uhcip); 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate if (pp->pp_qh == NULL) { 2377c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_LISTS, uhcip->uhci_log_hdl, 2387c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_open: QH allocation failed"); 2397c478bd9Sstevel@tonic-gate 2404c8a46c1Syq if (UHCI_PERIODIC_ENDPOINT(&ph->p_ep)) { 2414c8a46c1Syq uhci_deallocate_bandwidth(uhcip, ph); 2424c8a46c1Syq } 2434c8a46c1Syq 2447c478bd9Sstevel@tonic-gate mutex_enter(&ph->p_mutex); 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate /* 2477c478bd9Sstevel@tonic-gate * Deallocate the hcd private portion 2487c478bd9Sstevel@tonic-gate * of the pipe handle. 2497c478bd9Sstevel@tonic-gate */ 2507c478bd9Sstevel@tonic-gate kmem_free(ph->p_hcd_private, 251fffe0b30Sqz sizeof (uhci_pipe_private_t)); 2527c478bd9Sstevel@tonic-gate 2537c478bd9Sstevel@tonic-gate /* 2547c478bd9Sstevel@tonic-gate * Set the private structure in the 2557c478bd9Sstevel@tonic-gate * pipe handle equal to NULL. 2567c478bd9Sstevel@tonic-gate */ 2577c478bd9Sstevel@tonic-gate ph->p_hcd_private = NULL; 2587c478bd9Sstevel@tonic-gate mutex_exit(&ph->p_mutex); 2597c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate sema_v(&uhcip->uhci_ocsem); 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate return (USB_NO_RESOURCES); 2647c478bd9Sstevel@tonic-gate } 2657c478bd9Sstevel@tonic-gate 2667c478bd9Sstevel@tonic-gate /* 2677c478bd9Sstevel@tonic-gate * Insert the endpoint onto the host controller's 2687c478bd9Sstevel@tonic-gate * appropriate endpoint list. The host controller 2697c478bd9Sstevel@tonic-gate * will not schedule this endpoint until there are 2707c478bd9Sstevel@tonic-gate * any TD's to process. 2717c478bd9Sstevel@tonic-gate */ 2727c478bd9Sstevel@tonic-gate uhci_insert_qh(uhcip, ph); 2737c478bd9Sstevel@tonic-gate } 2747c478bd9Sstevel@tonic-gate 2757c478bd9Sstevel@tonic-gate /* 2767c478bd9Sstevel@tonic-gate * Restore the data toggle from usb device structure. 2777c478bd9Sstevel@tonic-gate */ 2784c8a46c1Syq if (((ph->p_ep.bmAttributes) & USB_EP_ATTR_MASK) == USB_EP_ATTR_INTR || 2794c8a46c1Syq ((ph->p_ep.bmAttributes) & USB_EP_ATTR_MASK) == USB_EP_ATTR_BULK) { 2807c478bd9Sstevel@tonic-gate mutex_enter(&ph->p_mutex); 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate pp->pp_data_toggle = usba_hcdi_get_data_toggle( 283fffe0b30Sqz ph->p_usba_device, ph->p_ep.bEndpointAddress); 2847c478bd9Sstevel@tonic-gate mutex_exit(&ph->p_mutex); 2857c478bd9Sstevel@tonic-gate } 2867c478bd9Sstevel@tonic-gate 2877c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 2887c478bd9Sstevel@tonic-gate sema_v(&uhcip->uhci_ocsem); 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 291112116d8Sfb "uhci_hcdi_pipe_open: ph = 0x%p", (void *)ph); 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 2947c478bd9Sstevel@tonic-gate } 2957c478bd9Sstevel@tonic-gate 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate /* 2987c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_close: 2997c478bd9Sstevel@tonic-gate * Member of HCD Ops structure and called during the client specific pipe 3007c478bd9Sstevel@tonic-gate * close. Remove the pipe to the data structure representing the device 3017c478bd9Sstevel@tonic-gate * deallocate bandwidth for the pipe if it is an intr or isoch endpoint. 3027c478bd9Sstevel@tonic-gate */ 3037c478bd9Sstevel@tonic-gate int 3047c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_close(usba_pipe_handle_data_t *ph, usb_flags_t usb_flags) 3057c478bd9Sstevel@tonic-gate { 3067c478bd9Sstevel@tonic-gate usb_addr_t usb_addr; 3077c478bd9Sstevel@tonic-gate uhci_state_t *uhcip; 3087c478bd9Sstevel@tonic-gate usb_ep_descr_t *eptd = &ph->p_ep; 3097c478bd9Sstevel@tonic-gate uhci_pipe_private_t *pp; 3107c478bd9Sstevel@tonic-gate 3117c478bd9Sstevel@tonic-gate uhcip = uhci_obtain_state(ph->p_usba_device->usb_root_hub_dip); 3127c478bd9Sstevel@tonic-gate pp = (uhci_pipe_private_t *)ph->p_hcd_private; 3137c478bd9Sstevel@tonic-gate usb_addr = ph->p_usba_device->usb_addr; 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 3167c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_close: addr = 0x%x, ep%d, flags = 0x%x", usb_addr, 3177c478bd9Sstevel@tonic-gate eptd->bEndpointAddress, usb_flags); 3187c478bd9Sstevel@tonic-gate 3197c478bd9Sstevel@tonic-gate sema_p(&uhcip->uhci_ocsem); 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 3227c478bd9Sstevel@tonic-gate 3237c478bd9Sstevel@tonic-gate /* 3247c478bd9Sstevel@tonic-gate * Check whether the pipe is a root hub 3257c478bd9Sstevel@tonic-gate */ 3267c478bd9Sstevel@tonic-gate if (usb_addr == ROOT_HUB_ADDR) { 3277c478bd9Sstevel@tonic-gate switch (UHCI_XFER_TYPE(eptd)) { 3287c478bd9Sstevel@tonic-gate case USB_EP_ATTR_CONTROL: 3297c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 3307c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_close: Root hub control pipe " 3317c478bd9Sstevel@tonic-gate "close succeeded"); 3327c478bd9Sstevel@tonic-gate 3337c478bd9Sstevel@tonic-gate break; 3347c478bd9Sstevel@tonic-gate case USB_EP_ATTR_INTR: 3357c478bd9Sstevel@tonic-gate ASSERT((eptd->bEndpointAddress & 336fffe0b30Sqz USB_EP_NUM_MASK) == 1); 3377c478bd9Sstevel@tonic-gate 3387c478bd9Sstevel@tonic-gate /* Do interrupt pipe cleanup */ 3397c478bd9Sstevel@tonic-gate uhci_root_hub_intr_pipe_cleanup(uhcip, 340fffe0b30Sqz USB_CR_PIPE_CLOSING); 3417c478bd9Sstevel@tonic-gate 3427c478bd9Sstevel@tonic-gate ASSERT(uhcip->uhci_root_hub.rh_pipe_state == 343fffe0b30Sqz UHCI_PIPE_STATE_IDLE); 3447c478bd9Sstevel@tonic-gate 3457c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_intr_pipe_handle = NULL; 3467c478bd9Sstevel@tonic-gate 3477c478bd9Sstevel@tonic-gate USB_DPRINTF_L3(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 3487c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_close: Root hub interrupt " 3497c478bd9Sstevel@tonic-gate "pipe close succeeded"); 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_pipe_state = 352fffe0b30Sqz UHCI_PIPE_STATE_IDLE; 3537c478bd9Sstevel@tonic-gate 3547c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 3557c478bd9Sstevel@tonic-gate sema_v(&uhcip->uhci_ocsem); 3567c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 3577c478bd9Sstevel@tonic-gate } 3587c478bd9Sstevel@tonic-gate } else { 3597c478bd9Sstevel@tonic-gate /* 3607c478bd9Sstevel@tonic-gate * Stop all the transactions if it is not the root hub. 3617c478bd9Sstevel@tonic-gate */ 3627c478bd9Sstevel@tonic-gate if (UHCI_XFER_TYPE(eptd) == USB_EP_ATTR_INTR) { 3637c478bd9Sstevel@tonic-gate /* 3647c478bd9Sstevel@tonic-gate * Stop polling on the pipe to prevent any subsequently 3657c478bd9Sstevel@tonic-gate * queued tds (while we're waiting for SOF, below) 3667c478bd9Sstevel@tonic-gate * from being executed 3677c478bd9Sstevel@tonic-gate */ 3687c478bd9Sstevel@tonic-gate pp->pp_state = UHCI_PIPE_STATE_IDLE; 3697c478bd9Sstevel@tonic-gate } 3707c478bd9Sstevel@tonic-gate 3717c478bd9Sstevel@tonic-gate /* Disable all outstanding tds */ 3727c478bd9Sstevel@tonic-gate uhci_modify_td_active_bits(uhcip, pp); 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate /* Prevent this queue from being executed */ 3757c478bd9Sstevel@tonic-gate if (UHCI_XFER_TYPE(eptd) != USB_EP_ATTR_ISOCH) { 3767c478bd9Sstevel@tonic-gate UHCI_SET_TERMINATE_BIT(pp->pp_qh->element_ptr); 3777c478bd9Sstevel@tonic-gate } 3787c478bd9Sstevel@tonic-gate 3797c478bd9Sstevel@tonic-gate /* Wait for the next start of frame */ 3807c478bd9Sstevel@tonic-gate (void) uhci_wait_for_sof(uhcip); 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate ASSERT(eptd != NULL); 3837c478bd9Sstevel@tonic-gate 3847c478bd9Sstevel@tonic-gate switch (UHCI_XFER_TYPE(eptd)) { 3857c478bd9Sstevel@tonic-gate case USB_EP_ATTR_INTR: 3867c478bd9Sstevel@tonic-gate uhci_update_intr_td_data_toggle(uhcip, pp); 3877c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 3887c478bd9Sstevel@tonic-gate case USB_EP_ATTR_CONTROL: 3897c478bd9Sstevel@tonic-gate uhci_remove_tds_tws(uhcip, ph); 3907c478bd9Sstevel@tonic-gate break; 3917c478bd9Sstevel@tonic-gate case USB_EP_ATTR_BULK: 3927c478bd9Sstevel@tonic-gate SetQH32(uhcip, pp->pp_qh->element_ptr, 3937c478bd9Sstevel@tonic-gate TD_PADDR(pp->pp_qh->td_tailp)); 3947c478bd9Sstevel@tonic-gate uhci_remove_bulk_tds_tws(uhcip, pp, UHCI_IN_CLOSE); 3957c478bd9Sstevel@tonic-gate uhci_save_data_toggle(pp); 3967c478bd9Sstevel@tonic-gate break; 3977c478bd9Sstevel@tonic-gate case USB_EP_ATTR_ISOCH: 3987c478bd9Sstevel@tonic-gate uhci_remove_isoc_tds_tws(uhcip, pp); 3997c478bd9Sstevel@tonic-gate break; 4007c478bd9Sstevel@tonic-gate default: 4017c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 4027c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_close: Unknown xfer type"); 4037c478bd9Sstevel@tonic-gate break; 4047c478bd9Sstevel@tonic-gate } 4057c478bd9Sstevel@tonic-gate 4067c478bd9Sstevel@tonic-gate /* 4077c478bd9Sstevel@tonic-gate * Remove the endoint descriptor from Host Controller's 4087c478bd9Sstevel@tonic-gate * appropriate endpoint list. Isochronous pipes dont have 4097c478bd9Sstevel@tonic-gate * any queue heads attached to it. 4107c478bd9Sstevel@tonic-gate */ 4117c478bd9Sstevel@tonic-gate if (UHCI_XFER_TYPE(eptd) != USB_EP_ATTR_ISOCH) { 4127c478bd9Sstevel@tonic-gate uhci_remove_qh(uhcip, pp); 4137c478bd9Sstevel@tonic-gate } 4147c478bd9Sstevel@tonic-gate 4157c478bd9Sstevel@tonic-gate /* 4167c478bd9Sstevel@tonic-gate * Do the callback for the original client 4177c478bd9Sstevel@tonic-gate * periodic IN request. 4187c478bd9Sstevel@tonic-gate */ 4197c478bd9Sstevel@tonic-gate if (pp->pp_client_periodic_in_reqp) { 4207c478bd9Sstevel@tonic-gate uhci_hcdi_callback(uhcip, pp, ph, NULL, 4217c478bd9Sstevel@tonic-gate USB_CR_PIPE_CLOSING); 4227c478bd9Sstevel@tonic-gate } 4237c478bd9Sstevel@tonic-gate 4247c478bd9Sstevel@tonic-gate /* Deallocate bandwidth */ 4257c478bd9Sstevel@tonic-gate if (UHCI_PERIODIC_ENDPOINT(eptd)) { 4267c478bd9Sstevel@tonic-gate mutex_enter(&ph->p_mutex); 4277c478bd9Sstevel@tonic-gate uhci_deallocate_bandwidth(uhcip, ph); 4287c478bd9Sstevel@tonic-gate mutex_exit(&ph->p_mutex); 4297c478bd9Sstevel@tonic-gate } 4307c478bd9Sstevel@tonic-gate } 4317c478bd9Sstevel@tonic-gate 4327c478bd9Sstevel@tonic-gate /* Deallocate the hcd private portion of the pipe handle. */ 4337c478bd9Sstevel@tonic-gate 4347c478bd9Sstevel@tonic-gate mutex_enter(&ph->p_mutex); 4357c478bd9Sstevel@tonic-gate kmem_free(ph->p_hcd_private, sizeof (uhci_pipe_private_t)); 4367c478bd9Sstevel@tonic-gate ph->p_hcd_private = NULL; 4377c478bd9Sstevel@tonic-gate mutex_exit(&ph->p_mutex); 4387c478bd9Sstevel@tonic-gate 4397c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 440112116d8Sfb "uhci_hcdi_pipe_close: ph = 0x%p", (void *)ph); 4417c478bd9Sstevel@tonic-gate 4427c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 4437c478bd9Sstevel@tonic-gate sema_v(&uhcip->uhci_ocsem); 4447c478bd9Sstevel@tonic-gate 4457c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 4467c478bd9Sstevel@tonic-gate } 4477c478bd9Sstevel@tonic-gate 4487c478bd9Sstevel@tonic-gate 4497c478bd9Sstevel@tonic-gate /* 4507c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_reset: 4517c478bd9Sstevel@tonic-gate */ 4527c478bd9Sstevel@tonic-gate int 4537c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_reset(usba_pipe_handle_data_t *ph, usb_flags_t usb_flags) 4547c478bd9Sstevel@tonic-gate { 4557c478bd9Sstevel@tonic-gate uhci_state_t *uhcip = uhci_obtain_state( 456fffe0b30Sqz ph->p_usba_device->usb_root_hub_dip); 4577c478bd9Sstevel@tonic-gate uhci_pipe_private_t *pp = (uhci_pipe_private_t *)ph->p_hcd_private; 4587c478bd9Sstevel@tonic-gate usb_ep_descr_t *eptd = &ph->p_ep; 4597c478bd9Sstevel@tonic-gate 4607c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 4617c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_reset: usb_flags = 0x%x", usb_flags); 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate /* 4647c478bd9Sstevel@tonic-gate * Return failure immediately for any other pipe reset on the root 4657c478bd9Sstevel@tonic-gate * hub except control or interrupt pipe. 4667c478bd9Sstevel@tonic-gate */ 4677c478bd9Sstevel@tonic-gate if (ph->p_usba_device->usb_addr == ROOT_HUB_ADDR) { 4687c478bd9Sstevel@tonic-gate switch (UHCI_XFER_TYPE(&ph->p_ep)) { 4697c478bd9Sstevel@tonic-gate case USB_EP_ATTR_CONTROL: 4707c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 4717c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_reset: Pipe reset for root" 4727c478bd9Sstevel@tonic-gate "hub control pipe successful"); 4737c478bd9Sstevel@tonic-gate 4747c478bd9Sstevel@tonic-gate break; 4757c478bd9Sstevel@tonic-gate case USB_EP_ATTR_INTR: 4767c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 4777c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_pipe_state = 478fffe0b30Sqz UHCI_PIPE_STATE_IDLE; 4797c478bd9Sstevel@tonic-gate 4807c478bd9Sstevel@tonic-gate /* Do interrupt pipe cleanup */ 4817c478bd9Sstevel@tonic-gate uhci_root_hub_intr_pipe_cleanup(uhcip, 482fffe0b30Sqz USB_CR_PIPE_RESET); 4837c478bd9Sstevel@tonic-gate 4847c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 4857c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_reset: Pipe reset for " 4867c478bd9Sstevel@tonic-gate "root hub interrupt pipe successful"); 4877c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 4887c478bd9Sstevel@tonic-gate 4897c478bd9Sstevel@tonic-gate break; 4907c478bd9Sstevel@tonic-gate default: 4917c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 492fffe0b30Sqz "uhci_hcdi_pipe_reset: Root hub pipe reset failed"); 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate return (USB_FAILURE); 4957c478bd9Sstevel@tonic-gate } 4967c478bd9Sstevel@tonic-gate 4977c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 4987c478bd9Sstevel@tonic-gate } 4997c478bd9Sstevel@tonic-gate 5007c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 5017c478bd9Sstevel@tonic-gate 5027c478bd9Sstevel@tonic-gate /* 5037c478bd9Sstevel@tonic-gate * Set the active bit in to INACTIVE for all the remaining TD's of 5047c478bd9Sstevel@tonic-gate * this end point. Set the active bit for the dummy td. This will 5057c478bd9Sstevel@tonic-gate * generate an interrupt at the end of the frame. After receiving 5067c478bd9Sstevel@tonic-gate * the interrupt, it is safe to to manipulate the lattice. 5077c478bd9Sstevel@tonic-gate */ 5087c478bd9Sstevel@tonic-gate uhci_modify_td_active_bits(uhcip, pp); 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate /* Initialize the element pointer */ 5117c478bd9Sstevel@tonic-gate if (UHCI_XFER_TYPE(eptd) != USB_EP_ATTR_ISOCH) { 5127c478bd9Sstevel@tonic-gate UHCI_SET_TERMINATE_BIT(pp->pp_qh->element_ptr); 5137c478bd9Sstevel@tonic-gate SetQH32(uhcip, pp->pp_qh->element_ptr, 5147c478bd9Sstevel@tonic-gate TD_PADDR(pp->pp_qh->td_tailp)); 5157c478bd9Sstevel@tonic-gate } 5167c478bd9Sstevel@tonic-gate 5177c478bd9Sstevel@tonic-gate (void) uhci_wait_for_sof(uhcip); 5187c478bd9Sstevel@tonic-gate 5197c478bd9Sstevel@tonic-gate /* 5207c478bd9Sstevel@tonic-gate * Save the data toggle and clear the pipe. 5217c478bd9Sstevel@tonic-gate */ 5227c478bd9Sstevel@tonic-gate switch (UHCI_XFER_TYPE(eptd)) { 5237c478bd9Sstevel@tonic-gate case USB_EP_ATTR_CONTROL: 5247c478bd9Sstevel@tonic-gate case USB_EP_ATTR_INTR: 5257c478bd9Sstevel@tonic-gate uhci_remove_tds_tws(uhcip, ph); 5267c478bd9Sstevel@tonic-gate break; 5277c478bd9Sstevel@tonic-gate case USB_EP_ATTR_BULK: 5287c478bd9Sstevel@tonic-gate SetQH32(uhcip, pp->pp_qh->element_ptr, 5297c478bd9Sstevel@tonic-gate TD_PADDR(pp->pp_qh->td_tailp)); 5307c478bd9Sstevel@tonic-gate uhci_remove_bulk_tds_tws(uhcip, pp, UHCI_IN_RESET); 5317c478bd9Sstevel@tonic-gate break; 5327c478bd9Sstevel@tonic-gate case USB_EP_ATTR_ISOCH: 5337c478bd9Sstevel@tonic-gate uhci_remove_isoc_tds_tws(uhcip, pp); 5347c478bd9Sstevel@tonic-gate break; 5357c478bd9Sstevel@tonic-gate default: 5367c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 5377c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_reset: Unknown xfer type"); 5387c478bd9Sstevel@tonic-gate break; 5397c478bd9Sstevel@tonic-gate } 5407c478bd9Sstevel@tonic-gate 5417c478bd9Sstevel@tonic-gate /* 5427c478bd9Sstevel@tonic-gate * Do the callback for the original client 5437c478bd9Sstevel@tonic-gate * periodic IN request. 5447c478bd9Sstevel@tonic-gate */ 5457c478bd9Sstevel@tonic-gate if (pp->pp_client_periodic_in_reqp) { 5467c478bd9Sstevel@tonic-gate uhci_hcdi_callback(uhcip, pp, ph, NULL, USB_CR_PIPE_RESET); 5477c478bd9Sstevel@tonic-gate } 5487c478bd9Sstevel@tonic-gate 5497c478bd9Sstevel@tonic-gate /* 5507c478bd9Sstevel@tonic-gate * Since the endpoint is stripped of Transfer Descriptors (TD), 5517c478bd9Sstevel@tonic-gate * reset the state of the periodic pipe to IDLE. 5527c478bd9Sstevel@tonic-gate */ 5537c478bd9Sstevel@tonic-gate pp->pp_state = UHCI_PIPE_STATE_IDLE; 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 5567c478bd9Sstevel@tonic-gate 5577c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 5587c478bd9Sstevel@tonic-gate } 5597c478bd9Sstevel@tonic-gate 5607c478bd9Sstevel@tonic-gate 5617c478bd9Sstevel@tonic-gate /* 5627c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_ctrl_xfer: 5637c478bd9Sstevel@tonic-gate */ 5647c478bd9Sstevel@tonic-gate int 5657c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_ctrl_xfer( 5667c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 5677c478bd9Sstevel@tonic-gate usb_ctrl_req_t *ctrl_reqp, 5687c478bd9Sstevel@tonic-gate usb_flags_t flags) 5697c478bd9Sstevel@tonic-gate { 5707c478bd9Sstevel@tonic-gate uhci_state_t *uhcip = uhci_obtain_state( 571fffe0b30Sqz ph->p_usba_device->usb_root_hub_dip); 5727c478bd9Sstevel@tonic-gate uhci_pipe_private_t *pp = (uhci_pipe_private_t *)ph->p_hcd_private; 573fffe0b30Sqz int error; 5747c478bd9Sstevel@tonic-gate 5757c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 5767c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_ctrl_xfer: req=0x%p, ph=0x%p, flags=0x%x", 577112116d8Sfb (void *)ctrl_reqp, (void *)ph, flags); 5787c478bd9Sstevel@tonic-gate 5797c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 580fffe0b30Sqz error = uhci_state_is_operational(uhcip); 581fffe0b30Sqz 582fffe0b30Sqz if (error != USB_SUCCESS) { 583fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 584fffe0b30Sqz 585fffe0b30Sqz return (error); 586fffe0b30Sqz } 5877c478bd9Sstevel@tonic-gate 5887c478bd9Sstevel@tonic-gate ASSERT(pp->pp_state == UHCI_PIPE_STATE_IDLE); 5897c478bd9Sstevel@tonic-gate 5907c478bd9Sstevel@tonic-gate /* 5917c478bd9Sstevel@tonic-gate * Check and handle root hub control request. 5927c478bd9Sstevel@tonic-gate */ 5937c478bd9Sstevel@tonic-gate if (ph->p_usba_device->usb_addr == ROOT_HUB_ADDR) { 5947c478bd9Sstevel@tonic-gate error = uhci_handle_root_hub_request(uhcip, ph, ctrl_reqp); 5957c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 5967c478bd9Sstevel@tonic-gate 5977c478bd9Sstevel@tonic-gate return (error); 5987c478bd9Sstevel@tonic-gate } 5997c478bd9Sstevel@tonic-gate 6007c478bd9Sstevel@tonic-gate /* Insert the td's on the endpoint */ 6017c478bd9Sstevel@tonic-gate if ((error = uhci_insert_ctrl_td(uhcip, ph, ctrl_reqp, flags)) != 6027c478bd9Sstevel@tonic-gate USB_SUCCESS) { 6037c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 6047c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_ctrl_xfer: No resources"); 6057c478bd9Sstevel@tonic-gate } 6067c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 6077c478bd9Sstevel@tonic-gate 6087c478bd9Sstevel@tonic-gate return (error); 6097c478bd9Sstevel@tonic-gate } 6107c478bd9Sstevel@tonic-gate 6117c478bd9Sstevel@tonic-gate 6127c478bd9Sstevel@tonic-gate /* 6137c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_bulk_xfer: 6147c478bd9Sstevel@tonic-gate */ 6157c478bd9Sstevel@tonic-gate int 6167c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_bulk_xfer(usba_pipe_handle_data_t *pipe_handle, 6177c478bd9Sstevel@tonic-gate usb_bulk_req_t *bulk_reqp, usb_flags_t usb_flags) 6187c478bd9Sstevel@tonic-gate { 6197c478bd9Sstevel@tonic-gate int error; 6207c478bd9Sstevel@tonic-gate uhci_state_t *uhcip; 6217c478bd9Sstevel@tonic-gate 6227c478bd9Sstevel@tonic-gate uhcip = uhci_obtain_state(pipe_handle->p_usba_device->usb_root_hub_dip); 6237c478bd9Sstevel@tonic-gate 6247c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 6257c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_bulk_xfer: Flags = 0x%x", usb_flags); 6267c478bd9Sstevel@tonic-gate 6277c478bd9Sstevel@tonic-gate /* Check the size of bulk request */ 6287c478bd9Sstevel@tonic-gate if (bulk_reqp->bulk_len > UHCI_BULK_MAX_XFER_SIZE) { 6297c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 6307c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_bulk_xfer: req size 0x%x is more than 0x%x", 6317c478bd9Sstevel@tonic-gate bulk_reqp->bulk_len, UHCI_BULK_MAX_XFER_SIZE); 6327c478bd9Sstevel@tonic-gate 6337c478bd9Sstevel@tonic-gate return (USB_FAILURE); 6347c478bd9Sstevel@tonic-gate } 6357c478bd9Sstevel@tonic-gate 6367c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 6377c478bd9Sstevel@tonic-gate 638fffe0b30Sqz error = uhci_state_is_operational(uhcip); 639fffe0b30Sqz 640fffe0b30Sqz if (error != USB_SUCCESS) { 641fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 642fffe0b30Sqz 643fffe0b30Sqz return (error); 644fffe0b30Sqz } 6457c478bd9Sstevel@tonic-gate /* Add the TD into the Host Controller's bulk list */ 6467c478bd9Sstevel@tonic-gate if ((error = uhci_insert_bulk_td(uhcip, pipe_handle, bulk_reqp, 6477c478bd9Sstevel@tonic-gate usb_flags)) != USB_SUCCESS) { 6487c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 6497c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_bulk_xfer: uhci_insert_bulk_td failed"); 6507c478bd9Sstevel@tonic-gate } 6517c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 6527c478bd9Sstevel@tonic-gate 6537c478bd9Sstevel@tonic-gate return (error); 6547c478bd9Sstevel@tonic-gate } 6557c478bd9Sstevel@tonic-gate 6567c478bd9Sstevel@tonic-gate 6577c478bd9Sstevel@tonic-gate /* 6587c478bd9Sstevel@tonic-gate * uhci_hcdi_bulk_transfer_size: 6597c478bd9Sstevel@tonic-gate * Return maximum bulk transfer size 6607c478bd9Sstevel@tonic-gate */ 6617c478bd9Sstevel@tonic-gate int 6627c478bd9Sstevel@tonic-gate uhci_hcdi_bulk_transfer_size( 6637c478bd9Sstevel@tonic-gate usba_device_t *usba_device, 6647c478bd9Sstevel@tonic-gate size_t *size) 6657c478bd9Sstevel@tonic-gate { 666fffe0b30Sqz uhci_state_t *uhcip = uhci_obtain_state( 667fffe0b30Sqz usba_device->usb_root_hub_dip); 668fffe0b30Sqz int rval; 6697c478bd9Sstevel@tonic-gate 6707c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 6717c478bd9Sstevel@tonic-gate "uhci_hcdi_bulk_transfer_size:"); 6727c478bd9Sstevel@tonic-gate 673fffe0b30Sqz mutex_enter(&uhcip->uhci_int_mutex); 674fffe0b30Sqz rval = uhci_state_is_operational(uhcip); 675fffe0b30Sqz 676fffe0b30Sqz if (rval != USB_SUCCESS) { 677fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 678fffe0b30Sqz 679fffe0b30Sqz return (rval); 680fffe0b30Sqz } 681fffe0b30Sqz 6827c478bd9Sstevel@tonic-gate *size = uhci_bulk_transfer_size; 683fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 6847c478bd9Sstevel@tonic-gate 6857c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 6867c478bd9Sstevel@tonic-gate } 6877c478bd9Sstevel@tonic-gate 6887c478bd9Sstevel@tonic-gate 6897c478bd9Sstevel@tonic-gate /* 6907c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_intr_xfer: 6917c478bd9Sstevel@tonic-gate */ 6927c478bd9Sstevel@tonic-gate int 6937c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_intr_xfer( 6947c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 6957c478bd9Sstevel@tonic-gate usb_intr_req_t *req, 6967c478bd9Sstevel@tonic-gate usb_flags_t flags) 6977c478bd9Sstevel@tonic-gate { 6987c478bd9Sstevel@tonic-gate uhci_state_t *uhcip = uhci_obtain_state( 699fffe0b30Sqz ph->p_usba_device->usb_root_hub_dip); 7007c478bd9Sstevel@tonic-gate 7017c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 702112116d8Sfb "uhci_hcdi_pipe_intr_xfer: req=0x%p, uf=0x%x", (void *)req, flags); 7037c478bd9Sstevel@tonic-gate 7047c478bd9Sstevel@tonic-gate if (UHCI_XFER_DIR(&ph->p_ep) == USB_EP_DIR_IN) { 7057c478bd9Sstevel@tonic-gate 7067c478bd9Sstevel@tonic-gate return (uhci_start_periodic_pipe_polling(uhcip, ph, 707fffe0b30Sqz (usb_opaque_t)req, flags)); 7087c478bd9Sstevel@tonic-gate } else { 7097c478bd9Sstevel@tonic-gate 7107c478bd9Sstevel@tonic-gate return (uhci_send_intr_data(uhcip, ph, req, flags)); 7117c478bd9Sstevel@tonic-gate } 7127c478bd9Sstevel@tonic-gate } 7137c478bd9Sstevel@tonic-gate 7147c478bd9Sstevel@tonic-gate 7157c478bd9Sstevel@tonic-gate /* 7167c478bd9Sstevel@tonic-gate * uhci_send_intr_data(): 7177c478bd9Sstevel@tonic-gate * send data to interrupt out pipe 7187c478bd9Sstevel@tonic-gate */ 7197c478bd9Sstevel@tonic-gate static int 7207c478bd9Sstevel@tonic-gate uhci_send_intr_data( 7217c478bd9Sstevel@tonic-gate uhci_state_t *uhcip, 7227c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *pipe_handle, 7237c478bd9Sstevel@tonic-gate usb_intr_req_t *req, 7247c478bd9Sstevel@tonic-gate usb_flags_t flags) 7257c478bd9Sstevel@tonic-gate { 726fffe0b30Sqz int rval; 7277c478bd9Sstevel@tonic-gate 7287c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_LISTS, uhcip->uhci_log_hdl, 7297c478bd9Sstevel@tonic-gate "uhci_send_intr_data:"); 7307c478bd9Sstevel@tonic-gate 7317c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 7327c478bd9Sstevel@tonic-gate 733fffe0b30Sqz rval = uhci_state_is_operational(uhcip); 734fffe0b30Sqz 735fffe0b30Sqz if (rval != USB_SUCCESS) { 736fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 737fffe0b30Sqz 738fffe0b30Sqz return (rval); 739fffe0b30Sqz } 740fffe0b30Sqz 7417c478bd9Sstevel@tonic-gate /* Add the TD into the Host Controller's interrupt list */ 7427c478bd9Sstevel@tonic-gate if ((rval = uhci_insert_intr_td(uhcip, pipe_handle, req, flags)) != 7437c478bd9Sstevel@tonic-gate USB_SUCCESS) { 7447c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 7457c478bd9Sstevel@tonic-gate "uhci_send_intr_data: No resources"); 7467c478bd9Sstevel@tonic-gate } 7477c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 7487c478bd9Sstevel@tonic-gate 7497c478bd9Sstevel@tonic-gate return (rval); 7507c478bd9Sstevel@tonic-gate } 7517c478bd9Sstevel@tonic-gate 7527c478bd9Sstevel@tonic-gate 7537c478bd9Sstevel@tonic-gate /* 7547c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_stop_intr_polling() 7557c478bd9Sstevel@tonic-gate */ 7567c478bd9Sstevel@tonic-gate int 7577c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_stop_intr_polling( 7587c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *pipe_handle, 7597c478bd9Sstevel@tonic-gate usb_flags_t flags) 7607c478bd9Sstevel@tonic-gate { 7617c478bd9Sstevel@tonic-gate uhci_state_t *uhcip = 762fffe0b30Sqz uhci_obtain_state(pipe_handle->p_usba_device->usb_root_hub_dip); 763fffe0b30Sqz int rval; 7647c478bd9Sstevel@tonic-gate 7657c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_LISTS, uhcip->uhci_log_hdl, 7667c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_stop_intr_polling: ph = 0x%p fl = 0x%x", 7677c478bd9Sstevel@tonic-gate (void *)pipe_handle, flags); 768fffe0b30Sqz mutex_enter(&uhcip->uhci_int_mutex); 7697c478bd9Sstevel@tonic-gate 770fffe0b30Sqz rval = uhci_stop_periodic_pipe_polling(uhcip, pipe_handle, flags); 771fffe0b30Sqz 772fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 773fffe0b30Sqz 774fffe0b30Sqz return (rval); 7757c478bd9Sstevel@tonic-gate } 7767c478bd9Sstevel@tonic-gate 7777c478bd9Sstevel@tonic-gate 7787c478bd9Sstevel@tonic-gate /* 7797c478bd9Sstevel@tonic-gate * uhci_hcdi_get_current_frame_number 780fffe0b30Sqz * Get the current frame number. 781fffe0b30Sqz * Return whether the request is handled successfully. 7827c478bd9Sstevel@tonic-gate */ 783fffe0b30Sqz int 784fffe0b30Sqz uhci_hcdi_get_current_frame_number( 785fffe0b30Sqz usba_device_t *usba_device, 786fffe0b30Sqz usb_frame_number_t *frame_number) 7877c478bd9Sstevel@tonic-gate { 7887c478bd9Sstevel@tonic-gate uhci_state_t *uhcip = uhci_obtain_state(usba_device->usb_root_hub_dip); 789fffe0b30Sqz int rval; 7907c478bd9Sstevel@tonic-gate 7917c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 792fffe0b30Sqz rval = uhci_state_is_operational(uhcip); 793fffe0b30Sqz 794fffe0b30Sqz if (rval != USB_SUCCESS) { 795fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 796fffe0b30Sqz 797fffe0b30Sqz return (rval); 798fffe0b30Sqz } 799fffe0b30Sqz 800fffe0b30Sqz *frame_number = uhci_get_sw_frame_number(uhcip); 8017c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 8027c478bd9Sstevel@tonic-gate 8037c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 804112116d8Sfb "uhci_hcdi_get_current_frame_number: %llx", 805112116d8Sfb (unsigned long long)(*frame_number)); 8067c478bd9Sstevel@tonic-gate 807fffe0b30Sqz return (rval); 8087c478bd9Sstevel@tonic-gate } 8097c478bd9Sstevel@tonic-gate 8107c478bd9Sstevel@tonic-gate 8117c478bd9Sstevel@tonic-gate /* 8127c478bd9Sstevel@tonic-gate * uhci_hcdi_get_max_isoc_pkts 813fffe0b30Sqz * Get the maximum number of isoc packets per USB Isoch request. 814fffe0b30Sqz * Return whether the request is handled successfully. 8157c478bd9Sstevel@tonic-gate */ 816fffe0b30Sqz int 817fffe0b30Sqz uhci_hcdi_get_max_isoc_pkts( 818fffe0b30Sqz usba_device_t *usba_device, 819fffe0b30Sqz uint_t *max_isoc_pkts_per_request) 8207c478bd9Sstevel@tonic-gate { 8217c478bd9Sstevel@tonic-gate uhci_state_t *uhcip = uhci_obtain_state(usba_device->usb_root_hub_dip); 822fffe0b30Sqz int rval; 823fffe0b30Sqz 824fffe0b30Sqz mutex_enter(&uhcip->uhci_int_mutex); 825fffe0b30Sqz rval = uhci_state_is_operational(uhcip); 826fffe0b30Sqz 827fffe0b30Sqz if (rval != USB_SUCCESS) { 828fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 829fffe0b30Sqz 830fffe0b30Sqz return (rval); 831fffe0b30Sqz } 832fffe0b30Sqz 833fffe0b30Sqz *max_isoc_pkts_per_request = UHCI_MAX_ISOC_PKTS; 834fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 8357c478bd9Sstevel@tonic-gate 8367c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 8377c478bd9Sstevel@tonic-gate "uhci_hcdi_get_max_isoc_pkts: 0x%x", UHCI_MAX_ISOC_PKTS); 8387c478bd9Sstevel@tonic-gate 839fffe0b30Sqz return (rval); 8407c478bd9Sstevel@tonic-gate } 8417c478bd9Sstevel@tonic-gate 8427c478bd9Sstevel@tonic-gate 8437c478bd9Sstevel@tonic-gate /* 8447c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_isoc_xfer: 8457c478bd9Sstevel@tonic-gate */ 8467c478bd9Sstevel@tonic-gate int 8477c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_isoc_xfer( 8487c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 8497c478bd9Sstevel@tonic-gate usb_isoc_req_t *isoc_reqp, 8507c478bd9Sstevel@tonic-gate usb_flags_t flags) 8517c478bd9Sstevel@tonic-gate { 8527c478bd9Sstevel@tonic-gate uhci_state_t *uhcip; 8537c478bd9Sstevel@tonic-gate 8547c478bd9Sstevel@tonic-gate uhcip = uhci_obtain_state(ph->p_usba_device->usb_root_hub_dip); 8557c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 856112116d8Sfb "uhci_hcdi_pipe_isoc_xfer: req=0x%p, uf=0x%x", 857112116d8Sfb (void *)isoc_reqp, flags); 8587c478bd9Sstevel@tonic-gate 8597c478bd9Sstevel@tonic-gate if (UHCI_XFER_DIR(&ph->p_ep) == USB_EP_DIR_IN) { 8607c478bd9Sstevel@tonic-gate 8617c478bd9Sstevel@tonic-gate return (uhci_start_periodic_pipe_polling(uhcip, ph, 862fffe0b30Sqz (usb_opaque_t)isoc_reqp, flags)); 8637c478bd9Sstevel@tonic-gate } else { 8647c478bd9Sstevel@tonic-gate 8657c478bd9Sstevel@tonic-gate return (uhci_pipe_send_isoc_data(uhcip, ph, isoc_reqp, flags)); 8667c478bd9Sstevel@tonic-gate } 8677c478bd9Sstevel@tonic-gate } 8687c478bd9Sstevel@tonic-gate 8697c478bd9Sstevel@tonic-gate 8707c478bd9Sstevel@tonic-gate /* 8717c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_stop_isoc_polling() 8727c478bd9Sstevel@tonic-gate */ 8737c478bd9Sstevel@tonic-gate int 8747c478bd9Sstevel@tonic-gate uhci_hcdi_pipe_stop_isoc_polling( 8757c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 8767c478bd9Sstevel@tonic-gate usb_flags_t flags) 8777c478bd9Sstevel@tonic-gate { 8787c478bd9Sstevel@tonic-gate uhci_state_t *uhcip = 879fffe0b30Sqz uhci_obtain_state(ph->p_usba_device->usb_root_hub_dip); 880fffe0b30Sqz int rval; 8817c478bd9Sstevel@tonic-gate 8827c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_LISTS, uhcip->uhci_log_hdl, 8837c478bd9Sstevel@tonic-gate "uhci_hcdi_pipe_stop_isoc_polling: ph = 0x%p fl = 0x%x", 8847c478bd9Sstevel@tonic-gate (void *)ph, flags); 8857c478bd9Sstevel@tonic-gate 886fffe0b30Sqz mutex_enter(&uhcip->uhci_int_mutex); 887fffe0b30Sqz rval = uhci_state_is_operational(uhcip); 888fffe0b30Sqz 889fffe0b30Sqz if (rval != USB_SUCCESS) { 890fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 891fffe0b30Sqz 892fffe0b30Sqz return (rval); 893fffe0b30Sqz } 894fffe0b30Sqz 895fffe0b30Sqz rval = uhci_stop_periodic_pipe_polling(uhcip, ph, flags); 896fffe0b30Sqz 897fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 898fffe0b30Sqz 899fffe0b30Sqz return (rval); 9007c478bd9Sstevel@tonic-gate } 9017c478bd9Sstevel@tonic-gate 9027c478bd9Sstevel@tonic-gate 9037c478bd9Sstevel@tonic-gate /* 9047c478bd9Sstevel@tonic-gate * uhci_start_periodic_pipe_polling: 9057c478bd9Sstevel@tonic-gate */ 9067c478bd9Sstevel@tonic-gate static int 9077c478bd9Sstevel@tonic-gate uhci_start_periodic_pipe_polling( 9087c478bd9Sstevel@tonic-gate uhci_state_t *uhcip, 9097c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 9107c478bd9Sstevel@tonic-gate usb_opaque_t in_reqp, 9117c478bd9Sstevel@tonic-gate usb_flags_t flags) 9127c478bd9Sstevel@tonic-gate { 9137c478bd9Sstevel@tonic-gate int n, num_tds; 914fffe0b30Sqz int error; 9157c478bd9Sstevel@tonic-gate usb_intr_req_t *intr_reqp = (usb_intr_req_t *)in_reqp; 9167c478bd9Sstevel@tonic-gate usb_ep_descr_t *eptd = &ph->p_ep; 9177c478bd9Sstevel@tonic-gate uhci_pipe_private_t *pp = (uhci_pipe_private_t *)ph->p_hcd_private; 9187c478bd9Sstevel@tonic-gate 9197c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 9207c478bd9Sstevel@tonic-gate "uhci_start_periodic_pipe_polling: flags: 0x%x, ep%d", 9217c478bd9Sstevel@tonic-gate flags, eptd->bEndpointAddress); 9227c478bd9Sstevel@tonic-gate 9237c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 9247c478bd9Sstevel@tonic-gate 925fffe0b30Sqz error = uhci_state_is_operational(uhcip); 926fffe0b30Sqz 927fffe0b30Sqz if (error != USB_SUCCESS) { 928fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 929fffe0b30Sqz 930fffe0b30Sqz return (error); 931fffe0b30Sqz } 932fffe0b30Sqz 9337c478bd9Sstevel@tonic-gate if (ph->p_usba_device->usb_addr == ROOT_HUB_ADDR) { 9347c478bd9Sstevel@tonic-gate uint_t pipe_state = uhcip->uhci_root_hub.rh_pipe_state; 9357c478bd9Sstevel@tonic-gate 9367c478bd9Sstevel@tonic-gate ASSERT(pipe_state == UHCI_PIPE_STATE_IDLE); 9377c478bd9Sstevel@tonic-gate ASSERT(UHCI_XFER_DIR(eptd) == USB_EP_DIR_IN); 9387c478bd9Sstevel@tonic-gate 9397c478bd9Sstevel@tonic-gate /* ONE_XFER not supported */ 9407c478bd9Sstevel@tonic-gate ASSERT((intr_reqp->intr_attributes & 9417c478bd9Sstevel@tonic-gate USB_ATTRS_ONE_XFER) == 0); 9427c478bd9Sstevel@tonic-gate ASSERT(uhcip->uhci_root_hub.rh_client_intr_req == NULL); 9437c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_client_intr_req = intr_reqp; 9447c478bd9Sstevel@tonic-gate 9457c478bd9Sstevel@tonic-gate if ((error = uhci_root_hub_allocate_intr_pipe_resource( 9467c478bd9Sstevel@tonic-gate uhcip, flags)) != USB_SUCCESS) { 9477c478bd9Sstevel@tonic-gate /* reset the client interrupt request pointer */ 9487c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_client_intr_req = NULL; 9497c478bd9Sstevel@tonic-gate 9507c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 9517c478bd9Sstevel@tonic-gate 9527c478bd9Sstevel@tonic-gate return (error); 9537c478bd9Sstevel@tonic-gate } 9547c478bd9Sstevel@tonic-gate 9557c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_pipe_state = USB_PIPE_STATE_ACTIVE; 9567c478bd9Sstevel@tonic-gate 9577c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 9587c478bd9Sstevel@tonic-gate "uhci_start_periodic_pipe_polling: " 9597c478bd9Sstevel@tonic-gate "Start intr polling for root hub successful"); 9607c478bd9Sstevel@tonic-gate 9617c478bd9Sstevel@tonic-gate /* check if we need to send the reset data up? */ 9627c478bd9Sstevel@tonic-gate if (uhcip->uhci_root_hub.rh_status) { 9637c478bd9Sstevel@tonic-gate uhci_root_hub_reset_occurred(uhcip, 9647c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_status - 1); 9657c478bd9Sstevel@tonic-gate 9667c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_status = 0; 9677c478bd9Sstevel@tonic-gate } 9687c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 9697c478bd9Sstevel@tonic-gate 9707c478bd9Sstevel@tonic-gate return (error); 9717c478bd9Sstevel@tonic-gate } 9727c478bd9Sstevel@tonic-gate 9737c478bd9Sstevel@tonic-gate /* save the original client's periodic IN request */ 9747c478bd9Sstevel@tonic-gate pp->pp_client_periodic_in_reqp = in_reqp; 9757c478bd9Sstevel@tonic-gate 9767c478bd9Sstevel@tonic-gate ASSERT(pp->pp_state != UHCI_PIPE_STATE_ACTIVE); 9777c478bd9Sstevel@tonic-gate /* 9787c478bd9Sstevel@tonic-gate * 9797c478bd9Sstevel@tonic-gate * This pipe is uninitialized. If it is an isoc 9807c478bd9Sstevel@tonic-gate * receive request, insert four times the same 9817c478bd9Sstevel@tonic-gate * request so that we do not lose any frames. 9827c478bd9Sstevel@tonic-gate */ 9837c478bd9Sstevel@tonic-gate if (UHCI_XFER_TYPE(eptd) == USB_EP_ATTR_ISOCH) { 9847c478bd9Sstevel@tonic-gate for (n = 0; n < 5; n++) { 9857c478bd9Sstevel@tonic-gate if ((error = uhci_start_isoc_receive_polling( 9867c478bd9Sstevel@tonic-gate uhcip, ph, NULL, flags)) != USB_SUCCESS) { 9877c478bd9Sstevel@tonic-gate 9887c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_INTR, 9897c478bd9Sstevel@tonic-gate uhcip->uhci_log_hdl, 9907c478bd9Sstevel@tonic-gate "uhci_start_periodic_pipe_polling: " 9917c478bd9Sstevel@tonic-gate "Start isoc polling failed %d", n); 9927c478bd9Sstevel@tonic-gate 9937c478bd9Sstevel@tonic-gate pp->pp_client_periodic_in_reqp = NULL; 9947c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 9957c478bd9Sstevel@tonic-gate 9967c478bd9Sstevel@tonic-gate return (error); 9977c478bd9Sstevel@tonic-gate } 9987c478bd9Sstevel@tonic-gate } 9997c478bd9Sstevel@tonic-gate } 10007c478bd9Sstevel@tonic-gate 10017c478bd9Sstevel@tonic-gate if (UHCI_XFER_TYPE(eptd) == USB_EP_ATTR_INTR) { 10027c478bd9Sstevel@tonic-gate if ((pp->pp_node < POLLING_FREQ_7MS) && 10037c478bd9Sstevel@tonic-gate (!(intr_reqp->intr_attributes & USB_ATTRS_ONE_XFER))) { 10047c478bd9Sstevel@tonic-gate num_tds = 5; 10057c478bd9Sstevel@tonic-gate } else { 10067c478bd9Sstevel@tonic-gate num_tds = 1; 10077c478bd9Sstevel@tonic-gate } 10087c478bd9Sstevel@tonic-gate 10097c478bd9Sstevel@tonic-gate /* 10107c478bd9Sstevel@tonic-gate * This pipe is uninitialized. 10117c478bd9Sstevel@tonic-gate * Insert a TD on the interrupt ED. 10127c478bd9Sstevel@tonic-gate */ 10137c478bd9Sstevel@tonic-gate for (n = 0; n < num_tds; n++) { 10147c478bd9Sstevel@tonic-gate if ((error = uhci_insert_intr_td(uhcip, ph, NULL, 10157c478bd9Sstevel@tonic-gate flags)) != USB_SUCCESS) { 10167c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_INTR, 10177c478bd9Sstevel@tonic-gate uhcip->uhci_log_hdl, 10187c478bd9Sstevel@tonic-gate "uhci_start_periodic_pipe_polling: " 10197c478bd9Sstevel@tonic-gate "Start polling failed"); 10207c478bd9Sstevel@tonic-gate 10217c478bd9Sstevel@tonic-gate pp->pp_client_periodic_in_reqp = NULL; 10227c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 10237c478bd9Sstevel@tonic-gate 10247c478bd9Sstevel@tonic-gate return (error); 10257c478bd9Sstevel@tonic-gate } 10267c478bd9Sstevel@tonic-gate } 10277c478bd9Sstevel@tonic-gate } 10287c478bd9Sstevel@tonic-gate 10297c478bd9Sstevel@tonic-gate pp->pp_state = UHCI_PIPE_STATE_ACTIVE; 10307c478bd9Sstevel@tonic-gate 10317c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 10327c478bd9Sstevel@tonic-gate 10337c478bd9Sstevel@tonic-gate return (error); 10347c478bd9Sstevel@tonic-gate } 10357c478bd9Sstevel@tonic-gate 10367c478bd9Sstevel@tonic-gate 10377c478bd9Sstevel@tonic-gate /* 10387c478bd9Sstevel@tonic-gate * uhci_hcdi_periodic_pipe_stop_polling: 10397c478bd9Sstevel@tonic-gate */ 10407c478bd9Sstevel@tonic-gate static int 10417c478bd9Sstevel@tonic-gate uhci_stop_periodic_pipe_polling(uhci_state_t *uhcip, 10427c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, usb_flags_t flags) 10437c478bd9Sstevel@tonic-gate { 10447c478bd9Sstevel@tonic-gate uhci_pipe_private_t *pp = (uhci_pipe_private_t *)ph->p_hcd_private; 10457c478bd9Sstevel@tonic-gate usb_ep_descr_t *eptd = &ph->p_ep; 10467c478bd9Sstevel@tonic-gate 10477c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 10487c478bd9Sstevel@tonic-gate "uhci_stop_periodic_pipe_polling: flags = 0x%x", flags); 10497c478bd9Sstevel@tonic-gate 1050fffe0b30Sqz ASSERT(mutex_owned(&uhcip->uhci_int_mutex)); 10517c478bd9Sstevel@tonic-gate if (ph->p_usba_device->usb_addr == ROOT_HUB_ADDR) { 10527c478bd9Sstevel@tonic-gate ASSERT(UHCI_XFER_DIR(eptd) == USB_EP_DIR_IN); 10537c478bd9Sstevel@tonic-gate 10547c478bd9Sstevel@tonic-gate if (uhcip->uhci_root_hub.rh_pipe_state == 10557c478bd9Sstevel@tonic-gate UHCI_PIPE_STATE_ACTIVE) { 10567c478bd9Sstevel@tonic-gate uhcip->uhci_root_hub.rh_pipe_state = 1057fffe0b30Sqz UHCI_PIPE_STATE_IDLE; 10587c478bd9Sstevel@tonic-gate 10597c478bd9Sstevel@tonic-gate /* Do interrupt pipe cleanup */ 10607c478bd9Sstevel@tonic-gate uhci_root_hub_intr_pipe_cleanup(uhcip, 1061fffe0b30Sqz USB_CR_STOPPED_POLLING); 10627c478bd9Sstevel@tonic-gate 10637c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 10647c478bd9Sstevel@tonic-gate "uhci_stop_periodic_pipe_polling: Stop intr " 10657c478bd9Sstevel@tonic-gate "polling for root hub successful"); 10667c478bd9Sstevel@tonic-gate 10677c478bd9Sstevel@tonic-gate } else { 10687c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_INTR, uhcip->uhci_log_hdl, 10697c478bd9Sstevel@tonic-gate "uhci_stop_periodic_pipe_polling: " 10707c478bd9Sstevel@tonic-gate "Intr polling for root hub is already stopped"); 10717c478bd9Sstevel@tonic-gate } 10727c478bd9Sstevel@tonic-gate 10737c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 10747c478bd9Sstevel@tonic-gate } 10757c478bd9Sstevel@tonic-gate 10767c478bd9Sstevel@tonic-gate if (pp->pp_state != UHCI_PIPE_STATE_ACTIVE) { 10777c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_INTR, uhcip->uhci_log_hdl, 10787c478bd9Sstevel@tonic-gate "uhci_stop_periodic_pipe_polling: Polling already stopped"); 10797c478bd9Sstevel@tonic-gate 10807c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 10817c478bd9Sstevel@tonic-gate } 10827c478bd9Sstevel@tonic-gate 10837c478bd9Sstevel@tonic-gate /* 10847c478bd9Sstevel@tonic-gate * Set the terminate bits in all the tds in the queue and 10857c478bd9Sstevel@tonic-gate * in the element_ptr. 10867c478bd9Sstevel@tonic-gate * Do not deallocate the bandwidth or tear down the DMA 10877c478bd9Sstevel@tonic-gate */ 10887c478bd9Sstevel@tonic-gate uhci_modify_td_active_bits(uhcip, pp); 10897c478bd9Sstevel@tonic-gate (void) uhci_wait_for_sof(uhcip); 10907c478bd9Sstevel@tonic-gate 10917c478bd9Sstevel@tonic-gate if (UHCI_XFER_TYPE(eptd) == USB_EP_ATTR_ISOCH) { 10927c478bd9Sstevel@tonic-gate uhci_remove_isoc_tds_tws(uhcip, pp); 10937c478bd9Sstevel@tonic-gate pp->pp_state = UHCI_PIPE_STATE_IDLE; 10947c478bd9Sstevel@tonic-gate } else { 10957c478bd9Sstevel@tonic-gate UHCI_SET_TERMINATE_BIT(pp->pp_qh->element_ptr); 10967c478bd9Sstevel@tonic-gate uhci_update_intr_td_data_toggle(uhcip, pp); 10977c478bd9Sstevel@tonic-gate SetQH32(uhcip, pp->pp_qh->element_ptr, 10987c478bd9Sstevel@tonic-gate TD_PADDR(pp->pp_qh->td_tailp)); 10997c478bd9Sstevel@tonic-gate uhci_remove_tds_tws(uhcip, ph); 11007c478bd9Sstevel@tonic-gate } 11017c478bd9Sstevel@tonic-gate 11027c478bd9Sstevel@tonic-gate pp->pp_state = UHCI_PIPE_STATE_IDLE; 11037c478bd9Sstevel@tonic-gate 11047c478bd9Sstevel@tonic-gate if (pp->pp_client_periodic_in_reqp) { 11057c478bd9Sstevel@tonic-gate uhci_hcdi_callback(uhcip, pp, ph, NULL, USB_CR_STOPPED_POLLING); 11067c478bd9Sstevel@tonic-gate } 11077c478bd9Sstevel@tonic-gate 11087c478bd9Sstevel@tonic-gate return (USB_SUCCESS); 11097c478bd9Sstevel@tonic-gate } 11107c478bd9Sstevel@tonic-gate 11117c478bd9Sstevel@tonic-gate 11127c478bd9Sstevel@tonic-gate /* 11137c478bd9Sstevel@tonic-gate * uhci_hcdi_pipe_send_isoc_data: 11147c478bd9Sstevel@tonic-gate * Handles the isoc write request. 11157c478bd9Sstevel@tonic-gate */ 11167c478bd9Sstevel@tonic-gate static int 11177c478bd9Sstevel@tonic-gate uhci_pipe_send_isoc_data( 11187c478bd9Sstevel@tonic-gate uhci_state_t *uhcip, 11197c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 11207c478bd9Sstevel@tonic-gate usb_isoc_req_t *isoc_req, 11217c478bd9Sstevel@tonic-gate usb_flags_t usb_flags) 11227c478bd9Sstevel@tonic-gate { 11237c478bd9Sstevel@tonic-gate int error; 11247c478bd9Sstevel@tonic-gate size_t max_isoc_xfer_sz, length; 11257c478bd9Sstevel@tonic-gate 11267c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 11277c478bd9Sstevel@tonic-gate "uhci_pipe_send_isoc_data: isoc_req = %p flags = %x", 1128112116d8Sfb (void *)isoc_req, usb_flags); 11297c478bd9Sstevel@tonic-gate 11307c478bd9Sstevel@tonic-gate ASSERT(isoc_req->isoc_pkts_count < UHCI_MAX_ISOC_PKTS); 11317c478bd9Sstevel@tonic-gate 11327c478bd9Sstevel@tonic-gate /* Calculate the maximum isochronous transfer size */ 11337c478bd9Sstevel@tonic-gate max_isoc_xfer_sz = UHCI_MAX_ISOC_PKTS * ph->p_ep.wMaxPacketSize; 11347c478bd9Sstevel@tonic-gate 11357c478bd9Sstevel@tonic-gate /* Check the size of isochronous request */ 11367c478bd9Sstevel@tonic-gate ASSERT(isoc_req->isoc_data != NULL); 1137*22eb7cb5Sgd length = MBLKL(isoc_req->isoc_data); 11387c478bd9Sstevel@tonic-gate 11397c478bd9Sstevel@tonic-gate if (length > max_isoc_xfer_sz) { 11407c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 11417c478bd9Sstevel@tonic-gate "uhci_pipe_send_isoc_data: Maximum isoc request size %lx " 11427c478bd9Sstevel@tonic-gate "Given isoc request size %lx", max_isoc_xfer_sz, length); 11437c478bd9Sstevel@tonic-gate 11447c478bd9Sstevel@tonic-gate return (USB_INVALID_REQUEST); 11457c478bd9Sstevel@tonic-gate } 11467c478bd9Sstevel@tonic-gate 11477c478bd9Sstevel@tonic-gate 11487c478bd9Sstevel@tonic-gate /* 11497c478bd9Sstevel@tonic-gate * Check whether we can insert these tds? 11507c478bd9Sstevel@tonic-gate * At any point of time, we can insert maximum of 1024 isoc td's, 11517c478bd9Sstevel@tonic-gate * size of frame list table. 11527c478bd9Sstevel@tonic-gate */ 11537c478bd9Sstevel@tonic-gate if (isoc_req->isoc_pkts_count > UHCI_MAX_ISOC_PKTS) { 11547c478bd9Sstevel@tonic-gate 11557c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_ISOC, uhcip->uhci_log_hdl, 11567c478bd9Sstevel@tonic-gate "uhci_pipe_send_isoc_data: request too big"); 11577c478bd9Sstevel@tonic-gate 11587c478bd9Sstevel@tonic-gate return (USB_INVALID_REQUEST); 11597c478bd9Sstevel@tonic-gate } 11607c478bd9Sstevel@tonic-gate 11617c478bd9Sstevel@tonic-gate /* Add the TD into the Host Controller's isoc list */ 11627c478bd9Sstevel@tonic-gate mutex_enter(&uhcip->uhci_int_mutex); 11637c478bd9Sstevel@tonic-gate 1164fffe0b30Sqz error = uhci_state_is_operational(uhcip); 1165fffe0b30Sqz 1166fffe0b30Sqz if (error != USB_SUCCESS) { 1167fffe0b30Sqz mutex_exit(&uhcip->uhci_int_mutex); 1168fffe0b30Sqz 1169fffe0b30Sqz return (error); 1170fffe0b30Sqz } 1171fffe0b30Sqz 11727c478bd9Sstevel@tonic-gate if ((error = uhci_insert_isoc_td(uhcip, ph, isoc_req, 11737c478bd9Sstevel@tonic-gate length, usb_flags)) != USB_SUCCESS) { 11747c478bd9Sstevel@tonic-gate 11757c478bd9Sstevel@tonic-gate USB_DPRINTF_L2(PRINT_MASK_ISOC, uhcip->uhci_log_hdl, 11767c478bd9Sstevel@tonic-gate "uhci_pipe_send_isoc_data: Unable to insert the isoc_req," 11777c478bd9Sstevel@tonic-gate "Error = %d", error); 11787c478bd9Sstevel@tonic-gate } 11797c478bd9Sstevel@tonic-gate mutex_exit(&uhcip->uhci_int_mutex); 11807c478bd9Sstevel@tonic-gate 11817c478bd9Sstevel@tonic-gate return (error); 11827c478bd9Sstevel@tonic-gate } 11837c478bd9Sstevel@tonic-gate 11847c478bd9Sstevel@tonic-gate 11857c478bd9Sstevel@tonic-gate /* 11867c478bd9Sstevel@tonic-gate * uhci_update_intr_td_data_toggle 11877c478bd9Sstevel@tonic-gate * Update the data toggle and save in the usba_device structure 11887c478bd9Sstevel@tonic-gate */ 11897c478bd9Sstevel@tonic-gate static void 11907c478bd9Sstevel@tonic-gate uhci_update_intr_td_data_toggle(uhci_state_t *uhcip, uhci_pipe_private_t *pp) 11917c478bd9Sstevel@tonic-gate { 11927c478bd9Sstevel@tonic-gate uint32_t paddr_tail, element_ptr; 11937c478bd9Sstevel@tonic-gate uhci_td_t *next_td; 11947c478bd9Sstevel@tonic-gate 11957c478bd9Sstevel@tonic-gate /* Find the next td that would have been executed */ 11967c478bd9Sstevel@tonic-gate element_ptr = GetQH32(uhcip, pp->pp_qh->element_ptr) & 1197fffe0b30Sqz QH_ELEMENT_PTR_MASK; 11987c478bd9Sstevel@tonic-gate next_td = TD_VADDR(element_ptr); 11997c478bd9Sstevel@tonic-gate paddr_tail = TD_PADDR(pp->pp_qh->td_tailp); 12007c478bd9Sstevel@tonic-gate 12017c478bd9Sstevel@tonic-gate /* 12027c478bd9Sstevel@tonic-gate * If element_ptr points to the dummy td, then the data toggle in 12037c478bd9Sstevel@tonic-gate * pp_data_toggle is correct. Otherwise update the data toggle in 12047c478bd9Sstevel@tonic-gate * the pipe private 12057c478bd9Sstevel@tonic-gate */ 12067c478bd9Sstevel@tonic-gate if (element_ptr != paddr_tail) { 12077c478bd9Sstevel@tonic-gate pp->pp_data_toggle = GetTD_dtogg(uhcip, next_td); 12087c478bd9Sstevel@tonic-gate } 12097c478bd9Sstevel@tonic-gate 12107c478bd9Sstevel@tonic-gate USB_DPRINTF_L4(PRINT_MASK_HCDI, uhcip->uhci_log_hdl, 12117c478bd9Sstevel@tonic-gate "uhci_update_intr_td_data_toggle: " 12127c478bd9Sstevel@tonic-gate "pp %p toggle %x element ptr %x ptail %x", 1213112116d8Sfb (void *)pp, pp->pp_data_toggle, element_ptr, paddr_tail); 12147c478bd9Sstevel@tonic-gate 12157c478bd9Sstevel@tonic-gate uhci_save_data_toggle(pp); 12167c478bd9Sstevel@tonic-gate } 1217