10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51458Syq193411 * Common Development and Distribution License (the "License"). 61458Syq193411 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*12733SRaymond.Chen@Sun.COM * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate */ 240Sstevel@tonic-gate 250Sstevel@tonic-gate #ifndef _SYS_USB_EHCID_H 260Sstevel@tonic-gate #define _SYS_USB_EHCID_H 270Sstevel@tonic-gate 280Sstevel@tonic-gate 290Sstevel@tonic-gate #ifdef __cplusplus 300Sstevel@tonic-gate extern "C" { 310Sstevel@tonic-gate #endif 320Sstevel@tonic-gate 330Sstevel@tonic-gate /* 340Sstevel@tonic-gate * Enchanced Host Controller Driver (EHCI) 350Sstevel@tonic-gate * 360Sstevel@tonic-gate * The EHCI driver is a software driver which interfaces to the Universal 370Sstevel@tonic-gate * Serial Bus layer (USBA) and the Host Controller (HC). The interface to 380Sstevel@tonic-gate * the Host Controller is defined by the EHCI Host Controller Interface. 390Sstevel@tonic-gate * 400Sstevel@tonic-gate * This header file describes the data structures and function prototypes 410Sstevel@tonic-gate * required for the EHCI Driver to maintain state of Host Controller (HC), 420Sstevel@tonic-gate * to perform different USB transfers and for the bandwidth allocations. 430Sstevel@tonic-gate */ 440Sstevel@tonic-gate 450Sstevel@tonic-gate #include <sys/usb/hcd/ehci/ehci.h> 460Sstevel@tonic-gate #include <sys/usb/hcd/ehci/ehci_hub.h> 470Sstevel@tonic-gate 480Sstevel@tonic-gate 490Sstevel@tonic-gate /* 500Sstevel@tonic-gate * EHCI Bandwidth Maintainence Structure. 510Sstevel@tonic-gate * 520Sstevel@tonic-gate * The ehci_bandwidth array keeps track of allocated bandwidth for ehci 530Sstevel@tonic-gate * host controller. There are 32 bandwidth lists corresponding to 32 ms 540Sstevel@tonic-gate * periodic frame lists. Each bandwidth list inturn will contain eight 550Sstevel@tonic-gate * micro frame bandwidth lists. 560Sstevel@tonic-gate */ 570Sstevel@tonic-gate #define EHCI_MAX_UFRAMES 8 /* Max uframes 125us per frame */ 580Sstevel@tonic-gate 590Sstevel@tonic-gate typedef struct ehci_frame_bandwidth { 600Sstevel@tonic-gate uint_t ehci_allocated_frame_bandwidth; 610Sstevel@tonic-gate uint_t ehci_micro_frame_bandwidth[EHCI_MAX_UFRAMES]; 620Sstevel@tonic-gate } ehci_frame_bandwidth_t; 630Sstevel@tonic-gate 640Sstevel@tonic-gate 650Sstevel@tonic-gate /* 660Sstevel@tonic-gate * EHCI Host Controller state structure 670Sstevel@tonic-gate * 680Sstevel@tonic-gate * The Host Controller Driver (HCD) maintains the state of Host Controller 690Sstevel@tonic-gate * (HC). There is an ehci_state structure per instance of the EHCI 700Sstevel@tonic-gate * host controller. 710Sstevel@tonic-gate */ 720Sstevel@tonic-gate typedef struct ehci_state { 730Sstevel@tonic-gate dev_info_t *ehci_dip; /* Dip of HC */ 740Sstevel@tonic-gate uint_t ehci_instance; 750Sstevel@tonic-gate usba_hcdi_ops_t *ehci_hcdi_ops; /* HCDI structure */ 760Sstevel@tonic-gate uint_t ehci_flags; /* Used for cleanup */ 770Sstevel@tonic-gate uint16_t ehci_vendor_id; /* chip vendor */ 780Sstevel@tonic-gate uint16_t ehci_device_id; /* chip device */ 790Sstevel@tonic-gate uint8_t ehci_rev_id; /* chip revison */ 800Sstevel@tonic-gate 810Sstevel@tonic-gate ddi_acc_handle_t ehci_caps_handle; /* Caps Reg Handle */ 820Sstevel@tonic-gate ehci_caps_t *ehci_capsp; /* Capability Regs */ 830Sstevel@tonic-gate ehci_regs_t *ehci_regsp; /* Operational Regs */ 840Sstevel@tonic-gate 850Sstevel@tonic-gate ddi_acc_handle_t ehci_config_handle; /* Config space hndle */ 860Sstevel@tonic-gate uint_t ehci_frame_interval; /* Frme inter reg */ 870Sstevel@tonic-gate ddi_dma_attr_t ehci_dma_attr; /* DMA attributes */ 880Sstevel@tonic-gate 890Sstevel@tonic-gate ddi_intr_handle_t *ehci_htable; /* intr handle */ 90965Sgovinda int ehci_intr_type; /* intr type used */ 91965Sgovinda int ehci_intr_cnt; /* # of intrs inuse */ 920Sstevel@tonic-gate uint_t ehci_intr_pri; /* intr priority */ 93965Sgovinda int ehci_intr_cap; /* intr capabilities */ 94965Sgovinda boolean_t ehci_msi_enabled; /* default to true */ 950Sstevel@tonic-gate kmutex_t ehci_int_mutex; /* Global EHCI mutex */ 960Sstevel@tonic-gate 970Sstevel@tonic-gate /* Periodic Frame List area */ 980Sstevel@tonic-gate ehci_periodic_frame_list_t *ehci_periodic_frame_list_tablep; 990Sstevel@tonic-gate /* Virtual Periodic Frame List ptr */ 1000Sstevel@tonic-gate ddi_dma_cookie_t ehci_pflt_cookie; /* DMA cookie */ 1010Sstevel@tonic-gate ddi_dma_handle_t ehci_pflt_dma_handle; /* DMA handle */ 1020Sstevel@tonic-gate ddi_acc_handle_t ehci_pflt_mem_handle; /* Memory handle */ 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate /* 1050Sstevel@tonic-gate * There are two pools of memory. One pool contains the memory for 1060Sstevel@tonic-gate * the transfer descriptors and other pool contains the memory for 1070Sstevel@tonic-gate * the endpoint descriptors. The advantage of the pools is that it's 1080Sstevel@tonic-gate * easy to go back and forth between the iommu and the cpu addresses. 1090Sstevel@tonic-gate * 1100Sstevel@tonic-gate * The pools are protected by the ehci_int_mutex because the memory 1110Sstevel@tonic-gate * in the pools may be accessed by either the host controller or the 1120Sstevel@tonic-gate * host controller driver. 1130Sstevel@tonic-gate */ 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate /* Endpoint descriptor pool */ 1160Sstevel@tonic-gate ehci_qh_t *ehci_qh_pool_addr; /* Start of the pool */ 1170Sstevel@tonic-gate ddi_dma_cookie_t ehci_qh_pool_cookie; /* DMA cookie */ 1180Sstevel@tonic-gate ddi_dma_handle_t ehci_qh_pool_dma_handle; /* DMA handle */ 1190Sstevel@tonic-gate ddi_acc_handle_t ehci_qh_pool_mem_handle; /* Mem handle */ 1200Sstevel@tonic-gate uint_t ehci_dma_addr_bind_flag; /* DMA flag */ 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate /* General transfer descriptor pool */ 1230Sstevel@tonic-gate ehci_qtd_t *ehci_qtd_pool_addr; /* Start of the pool */ 1240Sstevel@tonic-gate ddi_dma_cookie_t ehci_qtd_pool_cookie; /* DMA cookie */ 1250Sstevel@tonic-gate ddi_dma_handle_t ehci_qtd_pool_dma_handle; /* DMA hndle */ 1260Sstevel@tonic-gate ddi_acc_handle_t ehci_qtd_pool_mem_handle; /* Mem hndle */ 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate /* Isochronous transfer descriptor pool */ 1290Sstevel@tonic-gate ehci_itd_t *ehci_itd_pool_addr; /* Start of the pool */ 1300Sstevel@tonic-gate ddi_dma_cookie_t ehci_itd_pool_cookie; /* DMA cookie */ 1310Sstevel@tonic-gate ddi_dma_handle_t ehci_itd_pool_dma_handle; /* DMA hndle */ 1320Sstevel@tonic-gate ddi_acc_handle_t ehci_itd_pool_mem_handle; /* Mem hndle */ 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate /* Condition variable for advance on Asynchronous Schedule */ 1350Sstevel@tonic-gate kcondvar_t ehci_async_schedule_advance_cv; 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate /* Head of Asynchronous Schedule List */ 1380Sstevel@tonic-gate ehci_qh_t *ehci_head_of_async_sched_list; 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate /* 1410Sstevel@tonic-gate * List of QTD inserted either into Asynchronous or Periodic 1420Sstevel@tonic-gate * Schedule lists. 1430Sstevel@tonic-gate */ 1440Sstevel@tonic-gate ehci_qtd_t *ehci_active_qtd_list; 1450Sstevel@tonic-gate /* 1460Sstevel@tonic-gate * List of ITD active itd list. 1470Sstevel@tonic-gate */ 1480Sstevel@tonic-gate ehci_itd_t *ehci_active_itd_list; 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate /* 1510Sstevel@tonic-gate * Bandwidth fields 1520Sstevel@tonic-gate * 1530Sstevel@tonic-gate * The ehci_bandwidth array keeps track of allocated bandwidth for 1540Sstevel@tonic-gate * ehci host controller. There are 32 bandwidth lists corresponding 1550Sstevel@tonic-gate * to 32 ms periodic frame lists. Each bandwidth list in turn will 1560Sstevel@tonic-gate * contain eight micro frame bandwidth lists. 1570Sstevel@tonic-gate * 1580Sstevel@tonic-gate * ehci_min_frame_bandwidth field indicates least allocated milli 1590Sstevel@tonic-gate * second bandwidth list. 1600Sstevel@tonic-gate */ 1610Sstevel@tonic-gate ehci_frame_bandwidth_t ehci_frame_bandwidth[EHCI_NUM_INTR_QH_LISTS]; 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate /* No. of open pipes, async qh, and periodic qh */ 1640Sstevel@tonic-gate uint_t ehci_open_pipe_count; 1650Sstevel@tonic-gate uint_t ehci_open_async_count; 1660Sstevel@tonic-gate uint_t ehci_open_periodic_count; 1670Sstevel@tonic-gate 168*12733SRaymond.Chen@Sun.COM /* No. of async and periodic requests */ 169*12733SRaymond.Chen@Sun.COM uint_t ehci_async_req_count; 170*12733SRaymond.Chen@Sun.COM uint_t ehci_periodic_req_count; 171*12733SRaymond.Chen@Sun.COM 1720Sstevel@tonic-gate /* 1730Sstevel@tonic-gate * Endpoint Reclamation List 1740Sstevel@tonic-gate * 1750Sstevel@tonic-gate * The interrupt list processing cannot be stopped when a periodic 1760Sstevel@tonic-gate * endpoint is removed from the list. The endpoints are detached 1770Sstevel@tonic-gate * from the interrupt lattice tree and put on to the reclaimation 1780Sstevel@tonic-gate * list. On next SOF interrupt all those endpoints, which are on 1790Sstevel@tonic-gate * the reclaimation list will be deallocated. 1800Sstevel@tonic-gate */ 1810Sstevel@tonic-gate ehci_qh_t *ehci_reclaim_list; /* Reclaimation list */ 1820Sstevel@tonic-gate 1830Sstevel@tonic-gate ehci_root_hub_t ehci_root_hub; /* Root hub info */ 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate /* Frame number overflow information */ 1860Sstevel@tonic-gate usb_frame_number_t ehci_fno; 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate /* For host controller error counter */ 1890Sstevel@tonic-gate uint_t ehci_hc_error; 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate /* 1920Sstevel@tonic-gate * ehci_missed_intr_sts is used to save the normal mode interrupt 1930Sstevel@tonic-gate * status information if an interrupt is pending for normal mode 1940Sstevel@tonic-gate * when polled code is entered. 1950Sstevel@tonic-gate */ 1960Sstevel@tonic-gate uint_t ehci_missed_intr_sts; 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate /* 1990Sstevel@tonic-gate * Saved copy of the ehci registers of the normal mode & change 2000Sstevel@tonic-gate * required ehci registers values for the polled mode operation. 2010Sstevel@tonic-gate * Before returning from the polled mode to normal mode replace 2020Sstevel@tonic-gate * the required current registers with this saved ehci registers 2030Sstevel@tonic-gate * copy. 2040Sstevel@tonic-gate */ 2050Sstevel@tonic-gate ehci_regs_t ehci_polled_save_regs; 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate /* 2080Sstevel@tonic-gate * Saved copy of the interrupt table used in normal ehci mode and 2090Sstevel@tonic-gate * replace this table by another interrupt table that used in the 2100Sstevel@tonic-gate * POLLED mode. 2110Sstevel@tonic-gate */ 2120Sstevel@tonic-gate ehci_qh_t *ehci_polled_frame_list_table[EHCI_NUM_PERIODIC_FRAME_LISTS]; 2130Sstevel@tonic-gate 2140Sstevel@tonic-gate /* ehci polled mode enter counter */ 2150Sstevel@tonic-gate uint_t ehci_polled_enter_count; 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate /* 2180Sstevel@tonic-gate * counter for polled mode and used in suspend mode to see if 2190Sstevel@tonic-gate * there is a keyboard connected. 2200Sstevel@tonic-gate */ 2210Sstevel@tonic-gate uint_t ehci_polled_kbd_count; 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate /* counter for polled read and use it to clean the interrupt status */ 2240Sstevel@tonic-gate uint_t ehci_polled_read_count; 2250Sstevel@tonic-gate 2261458Syq193411 #if defined(__x86) 2271458Syq193411 /* counter for polled root hub status */ 2281458Syq193411 uint_t ehci_polled_root_hub_count; 2291458Syq193411 #endif /* __x86 */ 2301458Syq193411 2310Sstevel@tonic-gate /* EHCI Host Controller Software State information */ 2320Sstevel@tonic-gate uint_t ehci_hc_soft_state; 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate /* Log handle for debug, console, log messages */ 2350Sstevel@tonic-gate usb_log_handle_t ehci_log_hdl; 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate /* Kstat structures */ 2380Sstevel@tonic-gate kstat_t *ehci_intrs_stats; 2390Sstevel@tonic-gate kstat_t *ehci_total_stats; 2400Sstevel@tonic-gate kstat_t *ehci_count_stats[USB_N_COUNT_KSTATS]; 2410Sstevel@tonic-gate } ehci_state_t; 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate typedef struct ehci_intrs_stats { 2440Sstevel@tonic-gate struct kstat_named ehci_sts_async_sched_status; 2450Sstevel@tonic-gate struct kstat_named ehci_sts_periodic_sched_status; 2460Sstevel@tonic-gate struct kstat_named ehci_sts_empty_async_schedule; 2470Sstevel@tonic-gate struct kstat_named ehci_sts_host_ctrl_halted; 2480Sstevel@tonic-gate struct kstat_named ehci_sts_async_advance_intr; 2490Sstevel@tonic-gate struct kstat_named ehci_sts_host_system_error_intr; 2500Sstevel@tonic-gate struct kstat_named ehci_sts_frm_list_rollover_intr; 2510Sstevel@tonic-gate struct kstat_named ehci_sts_rh_port_change_intr; 2520Sstevel@tonic-gate struct kstat_named ehci_sts_usb_error_intr; 2530Sstevel@tonic-gate struct kstat_named ehci_sts_usb_intr; 2540Sstevel@tonic-gate struct kstat_named ehci_sts_not_claimed; 2550Sstevel@tonic-gate struct kstat_named ehci_sts_total; 2560Sstevel@tonic-gate } ehci_intrs_stats_t; 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate /* 2590Sstevel@tonic-gate * ehci kstat defines 2600Sstevel@tonic-gate */ 2610Sstevel@tonic-gate #define EHCI_INTRS_STATS(ehci) ((ehci)->ehci_intrs_stats) 2620Sstevel@tonic-gate #define EHCI_INTRS_STATS_DATA(ehci) \ 2630Sstevel@tonic-gate ((ehci_intrs_stats_t *)EHCI_INTRS_STATS((ehci))->ks_data) 2640Sstevel@tonic-gate 2650Sstevel@tonic-gate #define EHCI_TOTAL_STATS(ehci) ((ehci)->ehci_total_stats) 2660Sstevel@tonic-gate #define EHCI_TOTAL_STATS_DATA(ehci) (KSTAT_IO_PTR((ehci)->ehci_total_stats)) 2670Sstevel@tonic-gate #define EHCI_CTRL_STATS(ehci) \ 2680Sstevel@tonic-gate (KSTAT_IO_PTR((ehci)->ehci_count_stats[USB_EP_ATTR_CONTROL])) 2690Sstevel@tonic-gate #define EHCI_BULK_STATS(ehci) \ 2700Sstevel@tonic-gate (KSTAT_IO_PTR((ehci)->ehci_count_stats[USB_EP_ATTR_BULK])) 2710Sstevel@tonic-gate #define EHCI_INTR_STATS(ehci) \ 2720Sstevel@tonic-gate (KSTAT_IO_PTR((ehci)->ehci_count_stats[USB_EP_ATTR_INTR])) 2730Sstevel@tonic-gate #define EHCI_ISOC_STATS(ehci) \ 2740Sstevel@tonic-gate (KSTAT_IO_PTR((ehci)->ehci_count_stats[USB_EP_ATTR_ISOCH])) 2750Sstevel@tonic-gate 2760Sstevel@tonic-gate /* warlock directives, stable data */ 2770Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ehci_state_t::ehci_int_mutex, ehci_state_t)) 2780Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ehci_state_t::ehci_intr_pri)) 2790Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ehci_state_t::ehci_dip)) 2800Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ehci_state_t::ehci_regsp)) 2810Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ehci_state_t::ehci_instance)) 2820Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ehci_state_t::ehci_vendor_id)) 2830Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ehci_state_t::ehci_device_id)) 2840Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ehci_state_t::ehci_rev_id)) 2850Sstevel@tonic-gate 2860Sstevel@tonic-gate /* this may not be stable data in the future */ 2870Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ehci_state_t::ehci_qtd_pool_addr)) 2880Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ehci_state_t::ehci_qtd_pool_mem_handle)) 2890Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ehci_state_t::ehci_qtd_pool_cookie)) 2900Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ehci_state_t::ehci_qh_pool_addr)) 2910Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ehci_state_t::ehci_qh_pool_mem_handle)) 2920Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ehci_state_t::ehci_qh_pool_cookie)) 2930Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ehci_state_t::ehci_itd_pool_addr)) 2940Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ehci_state_t::ehci_itd_pool_mem_handle)) 2950Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ehci_state_t::ehci_itd_pool_cookie)) 2960Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ehci_state_t::ehci_dma_addr_bind_flag)) 2970Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ehci_state_t::ehci_log_hdl)) 2980Sstevel@tonic-gate 2990Sstevel@tonic-gate _NOTE(LOCK_ORDER(ehci_state::ehci_int_mutex \ 3000Sstevel@tonic-gate usba_pipe_handle_data::p_mutex \ 3010Sstevel@tonic-gate usba_device::usb_mutex \ 3020Sstevel@tonic-gate usba_ph_impl::usba_ph_mutex)) 3030Sstevel@tonic-gate 3040Sstevel@tonic-gate /* 3050Sstevel@tonic-gate * Host Contoller Software States 3060Sstevel@tonic-gate * 3070Sstevel@tonic-gate * EHCI_CTLR_INIT_STATE: 3080Sstevel@tonic-gate * The host controller soft state will be set to this during the 3090Sstevel@tonic-gate * ehci_attach. 3100Sstevel@tonic-gate * 3110Sstevel@tonic-gate * EHCI_CTLR_SUSPEND_STATE: 3120Sstevel@tonic-gate * The host controller soft state will be set to this during the 3130Sstevel@tonic-gate * ehci_cpr_suspend. 3140Sstevel@tonic-gate * 3150Sstevel@tonic-gate * EHCI_CTLR_OPERATIONAL_STATE: 3160Sstevel@tonic-gate * The host controller soft state will be set to this after moving 3170Sstevel@tonic-gate * host controller to operational state and host controller start 3180Sstevel@tonic-gate * generating SOF successfully. 3190Sstevel@tonic-gate * 3200Sstevel@tonic-gate * EHCI_CTLR_ERROR_STATE: 3210Sstevel@tonic-gate * The host controller soft state will be set to this during the 3220Sstevel@tonic-gate * no SOF or UE error conditions. 3230Sstevel@tonic-gate * 3240Sstevel@tonic-gate * Under this state or condition, only pipe stop polling, pipe reset 3250Sstevel@tonic-gate * and pipe close are allowed. But all other entry points like pipe 3260Sstevel@tonic-gate * open, get/set pipe policy, cotrol send/receive, bulk send/receive 3270Sstevel@tonic-gate * isoch send/receive, start polling etc. will fail. 3280Sstevel@tonic-gate * 3290Sstevel@tonic-gate * State Diagram for the host controller software state 3300Sstevel@tonic-gate * 3310Sstevel@tonic-gate * 3320Sstevel@tonic-gate * ehci_attach->[INIT_STATE] 3330Sstevel@tonic-gate * | 3340Sstevel@tonic-gate * | -------->----[ERROR_STATE]--<-----------<--- 3350Sstevel@tonic-gate * | | Failure (UE/no SOF condition) | 3360Sstevel@tonic-gate * | ^ ^ 3370Sstevel@tonic-gate * V | Success | 3380Sstevel@tonic-gate * ehci_init_ctlr--->--------[OPERATIONAL_STATE]------>-ehci_send/recv/polling 3390Sstevel@tonic-gate * ^ | 3400Sstevel@tonic-gate * | | 3410Sstevel@tonic-gate * | V 3420Sstevel@tonic-gate * -<-ehci_cpr_resume--[SUSPEND_STATE]-<-ehci_cpr_suspend 3430Sstevel@tonic-gate */ 3440Sstevel@tonic-gate #define EHCI_CTLR_INIT_STATE 0 /* Initilization state */ 3450Sstevel@tonic-gate #define EHCI_CTLR_SUSPEND_STATE 1 /* Suspend state */ 3460Sstevel@tonic-gate #define EHCI_CTLR_OPERATIONAL_STATE 2 /* Operational state */ 3470Sstevel@tonic-gate #define EHCI_CTLR_ERROR_STATE 3 /* Ue error or no sof state */ 3480Sstevel@tonic-gate 3490Sstevel@tonic-gate /* 3501458Syq193411 * Flags for initializatoin of host controller 3511458Syq193411 */ 3521458Syq193411 #define EHCI_NORMAL_INITIALIZATION 0 /* Normal initialization */ 3531458Syq193411 #define EHCI_REINITIALIZATION 1 /* Re-initialization */ 3541458Syq193411 3551458Syq193411 /* 3560Sstevel@tonic-gate * Periodic and non-periodic macros 3570Sstevel@tonic-gate */ 3580Sstevel@tonic-gate #define EHCI_PERIODIC_ENDPOINT(endpoint) (((endpoint->bmAttributes &\ 3590Sstevel@tonic-gate USB_EP_ATTR_MASK) == USB_EP_ATTR_INTR) ||\ 3600Sstevel@tonic-gate ((endpoint->bmAttributes &\ 3610Sstevel@tonic-gate USB_EP_ATTR_MASK) == USB_EP_ATTR_ISOCH)) 3620Sstevel@tonic-gate 3630Sstevel@tonic-gate #define EHCI_NON_PERIODIC_ENDPOINT(endpoint) (((endpoint->bmAttributes &\ 3640Sstevel@tonic-gate USB_EP_ATTR_MASK) == USB_EP_ATTR_CONTROL) ||\ 3650Sstevel@tonic-gate ((endpoint->bmAttributes &\ 3660Sstevel@tonic-gate USB_EP_ATTR_MASK) == USB_EP_ATTR_BULK)) 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate #define EHCI_ISOC_ENDPOINT(endpoint) (((endpoint->bmAttributes &\ 3690Sstevel@tonic-gate USB_EP_ATTR_MASK) == USB_EP_ATTR_ISOCH)) 3700Sstevel@tonic-gate 3710Sstevel@tonic-gate #define EHCI_INTR_ENDPOINT(endpoint) (((endpoint->bmAttributes &\ 3720Sstevel@tonic-gate USB_EP_ATTR_MASK) == USB_EP_ATTR_INTR)) 3730Sstevel@tonic-gate 3740Sstevel@tonic-gate 3750Sstevel@tonic-gate /* 3760Sstevel@tonic-gate * EHCI QH and QTD Pool sizes. 3770Sstevel@tonic-gate */ 3780Sstevel@tonic-gate #define EHCI_QH_POOL_SIZE 100 3790Sstevel@tonic-gate #define EHCI_QTD_POOL_SIZE 200 3800Sstevel@tonic-gate #define EHCI_ITD_POOL_SIZE 200 3810Sstevel@tonic-gate 3820Sstevel@tonic-gate /* 3830Sstevel@tonic-gate * ehci_dma_addr_bind_flag values 3840Sstevel@tonic-gate * 3850Sstevel@tonic-gate * This flag indicates if the various DMA addresses allocated by the EHCI 3860Sstevel@tonic-gate * have been bound to their respective handles. This is needed to recover 3870Sstevel@tonic-gate * without errors from ehci_cleanup when it calls ddi_dma_unbind_handle() 3880Sstevel@tonic-gate */ 3890Sstevel@tonic-gate #define EHCI_QTD_POOL_BOUND 0x01 /* For QTD pools */ 3900Sstevel@tonic-gate #define EHCI_QH_POOL_BOUND 0x02 /* For QH pools */ 3910Sstevel@tonic-gate #define EHCI_PFLT_DMA_BOUND 0x04 /* For Periodic Frame List area */ 3920Sstevel@tonic-gate #define EHCI_ITD_POOL_BOUND 0x08 /* For QTD pools */ 3930Sstevel@tonic-gate 3940Sstevel@tonic-gate /* 3950Sstevel@tonic-gate * Maximum SOF wait count 3960Sstevel@tonic-gate */ 3970Sstevel@tonic-gate #define MAX_SOF_WAIT_COUNT 2 /* Wait for maximum SOF frames */ 3980Sstevel@tonic-gate 3990Sstevel@tonic-gate /* 4000Sstevel@tonic-gate * One uFrame 125 micro seconds 4010Sstevel@tonic-gate * One Frame 1 milli second or 8 uFrames 4020Sstevel@tonic-gate */ 4030Sstevel@tonic-gate #define EHCI_uFRAMES_PER_USB_FRAME 8 4040Sstevel@tonic-gate #define EHCI_uFRAMES_PER_USB_FRAME_SHIFT 3 4050Sstevel@tonic-gate 4060Sstevel@tonic-gate 4070Sstevel@tonic-gate /* 4080Sstevel@tonic-gate * Pipe private structure 4090Sstevel@tonic-gate * 4100Sstevel@tonic-gate * There is an instance of this structure per pipe. This structure holds 4110Sstevel@tonic-gate * HCD specific pipe information. A pointer to this structure is kept in 4120Sstevel@tonic-gate * the USBA pipe handle (usba_pipe_handle_data_t). 4130Sstevel@tonic-gate */ 4140Sstevel@tonic-gate typedef struct ehci_pipe_private { 4150Sstevel@tonic-gate usba_pipe_handle_data_t *pp_pipe_handle; /* Back ptr to handle */ 4160Sstevel@tonic-gate ehci_qh_t *pp_qh; /* Pipe's qh */ 4170Sstevel@tonic-gate 4180Sstevel@tonic-gate /* State of the pipe */ 4190Sstevel@tonic-gate uint_t pp_state; /* See below */ 4200Sstevel@tonic-gate 4210Sstevel@tonic-gate /* Local copy of the pipe policy */ 4220Sstevel@tonic-gate usb_pipe_policy_t pp_policy; 4230Sstevel@tonic-gate 4240Sstevel@tonic-gate /* For Periodic Pipes Only */ 4250Sstevel@tonic-gate uint_t pp_pnode; /* periodic node */ 4260Sstevel@tonic-gate uchar_t pp_smask; /* Start split mask */ 4270Sstevel@tonic-gate uchar_t pp_cmask; /* Comp split mask */ 4280Sstevel@tonic-gate uint_t pp_cur_periodic_req_cnt; /* Curr req count */ 4290Sstevel@tonic-gate uint_t pp_max_periodic_req_cnt; /* Max req count */ 4300Sstevel@tonic-gate 4310Sstevel@tonic-gate /* For Isochronous pipes only */ 4320Sstevel@tonic-gate usb_frame_number_t pp_next_frame_number; /* Next frame no */ 4330Sstevel@tonic-gate 4340Sstevel@tonic-gate /* 4350Sstevel@tonic-gate * Each pipe may have multiple transfer wrappers. Each transfer 4360Sstevel@tonic-gate * wrapper represents a USB transfer on the bus. A transfer is 4370Sstevel@tonic-gate * made up of one or more transactions. 4380Sstevel@tonic-gate */ 4390Sstevel@tonic-gate struct ehci_trans_wrapper *pp_tw_head; /* Head of the list */ 4400Sstevel@tonic-gate struct ehci_trans_wrapper *pp_tw_tail; /* Tail of the list */ 4410Sstevel@tonic-gate 4420Sstevel@tonic-gate struct ehci_isoc_xwrapper *pp_itw_head; /* Head of the list */ 4430Sstevel@tonic-gate struct ehci_isoc_xwrapper *pp_itw_tail; /* Tail of the list */ 4440Sstevel@tonic-gate 4450Sstevel@tonic-gate /* 4460Sstevel@tonic-gate * Pipe's transfer timeout handling & this transfer timeout handling 4470Sstevel@tonic-gate * will be per pipe. 4480Sstevel@tonic-gate */ 4490Sstevel@tonic-gate struct ehci_trans_wrapper *pp_timeout_list; /* Timeout list */ 4500Sstevel@tonic-gate timeout_id_t pp_timer_id; /* Timer id */ 4510Sstevel@tonic-gate 4520Sstevel@tonic-gate /* Done td count */ 4530Sstevel@tonic-gate uint_t pp_count_done_qtds; /* Done td count */ 4540Sstevel@tonic-gate 4550Sstevel@tonic-gate /* Errors */ 4560Sstevel@tonic-gate usb_cr_t pp_error; /* Pipe error */ 4570Sstevel@tonic-gate 4580Sstevel@tonic-gate /* Condition variable for transfers completion event */ 4590Sstevel@tonic-gate kcondvar_t pp_xfer_cmpl_cv; /* Xfer completion */ 4600Sstevel@tonic-gate 4610Sstevel@tonic-gate /* Pipe flag */ 4620Sstevel@tonic-gate uint_t pp_flag; /* For polled mode */ 4630Sstevel@tonic-gate 4640Sstevel@tonic-gate /* Halting States */ 4650Sstevel@tonic-gate uint_t pp_halt_state; /* Is it halting */ 4660Sstevel@tonic-gate 4670Sstevel@tonic-gate /* Condition variable for halt completion event */ 4680Sstevel@tonic-gate kcondvar_t pp_halt_cmpl_cv; /* Xfer completion */ 4690Sstevel@tonic-gate 4700Sstevel@tonic-gate /* 4710Sstevel@tonic-gate * HCD gets Interrupt/Isochronous IN polling request only once and 4720Sstevel@tonic-gate * it has to insert next polling requests after completion of first 4730Sstevel@tonic-gate * request until either stop polling/pipe close is called. So HCD 4740Sstevel@tonic-gate * has to take copy of the original Interrupt/Isochronous IN request. 4750Sstevel@tonic-gate */ 4760Sstevel@tonic-gate usb_opaque_t pp_client_periodic_in_reqp; 4770Sstevel@tonic-gate } ehci_pipe_private_t; 4780Sstevel@tonic-gate 4790Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ehci_state_t::ehci_int_mutex, ehci_pipe_private_t)) 4800Sstevel@tonic-gate 4810Sstevel@tonic-gate /* 4820Sstevel@tonic-gate * Pipe states 4830Sstevel@tonic-gate * 4840Sstevel@tonic-gate * ehci pipe states will be similar to usba. Refer usbai.h. 4850Sstevel@tonic-gate */ 4860Sstevel@tonic-gate #define EHCI_PIPE_STATE_IDLE 1 /* Pipe is in ready state */ 4870Sstevel@tonic-gate #define EHCI_PIPE_STATE_ACTIVE 2 /* Pipe is in busy state */ 4880Sstevel@tonic-gate #define EHCI_PIPE_STATE_ERROR 3 /* Pipe is in error state */ 4890Sstevel@tonic-gate 4900Sstevel@tonic-gate /* Additional ehci pipe states for the ehci_pipe_cleanup */ 4910Sstevel@tonic-gate #define EHCI_PIPE_STATE_CLOSE 4 /* Pipe close */ 4920Sstevel@tonic-gate #define EHCI_PIPE_STATE_RESET 5 /* Pipe reset */ 4930Sstevel@tonic-gate #define EHCI_PIPE_STATE_STOP_POLLING 6 /* Pipe stop polling */ 4940Sstevel@tonic-gate 4950Sstevel@tonic-gate /* 4960Sstevel@tonic-gate * Pipe flag 4970Sstevel@tonic-gate * 4980Sstevel@tonic-gate * For polled mode flag. 4990Sstevel@tonic-gate */ 5000Sstevel@tonic-gate #define EHCI_POLLED_MODE_FLAG 1 /* Polled mode flag */ 5010Sstevel@tonic-gate 5020Sstevel@tonic-gate /* Pipe specific flags */ 5030Sstevel@tonic-gate #define EHCI_ISOC_XFER_CONTINUE 1 /* For isoc transfers */ 5040Sstevel@tonic-gate 5050Sstevel@tonic-gate /* 5060Sstevel@tonic-gate * Halting States 5070Sstevel@tonic-gate * prevent halting from interleaving. 5080Sstevel@tonic-gate */ 5090Sstevel@tonic-gate #define EHCI_HALT_STATE_FREE 0 /* Pipe free to accept reqs */ 5100Sstevel@tonic-gate #define EHCI_HALT_STATE_HALTING 1 /* Currently Halting */ 5110Sstevel@tonic-gate 5120Sstevel@tonic-gate /* 5130Sstevel@tonic-gate * Request values for Clear_TT_Buffer 5140Sstevel@tonic-gate */ 5150Sstevel@tonic-gate #define EHCI_CLEAR_TT_BUFFER_REQTYPE (USB_DEV_REQ_TYPE_CLASS | \ 5160Sstevel@tonic-gate USB_DEV_REQ_RCPT_OTHER) 5170Sstevel@tonic-gate #define EHCI_CLEAR_TT_BUFFER_BREQ 8 5180Sstevel@tonic-gate 5190Sstevel@tonic-gate /* 5200Sstevel@tonic-gate * USB frame offset 5210Sstevel@tonic-gate * 5220Sstevel@tonic-gate * Add appropriate frame offset to the current usb frame number and use it 5230Sstevel@tonic-gate * as a starting frame number for a given usb isochronous request. 5240Sstevel@tonic-gate */ 5250Sstevel@tonic-gate #define EHCI_FRAME_OFFSET 2 /* Frame offset */ 5260Sstevel@tonic-gate 5270Sstevel@tonic-gate /* 5280Sstevel@tonic-gate * Different interrupt polling intervals supported for high speed 5290Sstevel@tonic-gate * devices and its range must be from 1 to 16 units. This value is 5300Sstevel@tonic-gate * used as th exponent for a 2 ^ (bInterval - 1). Ex: a Binterval 5310Sstevel@tonic-gate * of 4 means a period of 8us (2 ^ (4-1)). 5320Sstevel@tonic-gate * 5330Sstevel@tonic-gate * The following values are defined after above convertion in terms 5340Sstevel@tonic-gate * 125us units. 5350Sstevel@tonic-gate */ 5360Sstevel@tonic-gate #define EHCI_INTR_1US_POLL 1 /* 1us poll interval */ 5370Sstevel@tonic-gate #define EHCI_INTR_2US_POLL 2 /* 2us poll interval */ 5380Sstevel@tonic-gate #define EHCI_INTR_4US_POLL 4 /* 4us poll interval */ 5390Sstevel@tonic-gate #define EHCI_INTR_XUS_POLL 8 /* 8us and above */ 5400Sstevel@tonic-gate 5410Sstevel@tonic-gate /* 5420Sstevel@tonic-gate * The following indecies are are used to calculate Start and complete 5430Sstevel@tonic-gate * masks as per the polling interval. 5440Sstevel@tonic-gate */ 5450Sstevel@tonic-gate #define EHCI_1US_MASK_INDEX 14 /* 1us mask index */ 5460Sstevel@tonic-gate #define EHCI_2US_MASK_INDEX 12 /* 2us mask index */ 5470Sstevel@tonic-gate #define EHCI_4US_MASK_INDEX 8 /* 4us mask index */ 5480Sstevel@tonic-gate #define EHCI_XUS_MASK_INDEX 0 /* 8us and above */ 5490Sstevel@tonic-gate 5500Sstevel@tonic-gate /* 5510Sstevel@tonic-gate * Different interrupt polling intervals supported for low/full/high 5520Sstevel@tonic-gate * speed devices. For high speed devices, the following values are 5530Sstevel@tonic-gate * applicable after convertion. 5540Sstevel@tonic-gate */ 5550Sstevel@tonic-gate #define EHCI_INTR_1MS_POLL 1 /* 1ms poll interval */ 5560Sstevel@tonic-gate #define EHCI_INTR_2MS_POLL 2 /* 2ms poll interval */ 5570Sstevel@tonic-gate #define EHCI_INTR_4MS_POLL 4 /* 4ms poll interval */ 5580Sstevel@tonic-gate #define EHCI_INTR_8MS_POLL 8 /* 8ms poll interval */ 5590Sstevel@tonic-gate #define EHCI_INTR_16MS_POLL 16 /* 16ms poll interval */ 5600Sstevel@tonic-gate #define EHCI_INTR_32MS_POLL 32 /* 32ms poll interval */ 5610Sstevel@tonic-gate 5620Sstevel@tonic-gate /* 5630Sstevel@tonic-gate * Number of interrupt transfer requests that should be maintained on 5640Sstevel@tonic-gate * the interrupt endpoint corresponding to different polling intervals 5650Sstevel@tonic-gate * supported. 5660Sstevel@tonic-gate */ 5670Sstevel@tonic-gate #define EHCI_INTR_1MS_REQS 4 /* 1ms polling interval */ 5680Sstevel@tonic-gate #define EHCI_INTR_2MS_REQS 2 /* 2ms polling interval */ 5690Sstevel@tonic-gate #define EHCI_INTR_XMS_REQS 1 /* Between 4ms and 32ms */ 5700Sstevel@tonic-gate 5710Sstevel@tonic-gate /* Function prototype */ 5720Sstevel@tonic-gate typedef void (*ehci_handler_function_t)( 5730Sstevel@tonic-gate ehci_state_t *ehcip, 5740Sstevel@tonic-gate ehci_pipe_private_t *pp, 5750Sstevel@tonic-gate struct ehci_trans_wrapper *tw, 5760Sstevel@tonic-gate ehci_qtd_t *qtd, 5770Sstevel@tonic-gate void *ehci_handle_callback_value); 5780Sstevel@tonic-gate 5790Sstevel@tonic-gate 5800Sstevel@tonic-gate /* 5810Sstevel@tonic-gate * Transfer wrapper 5820Sstevel@tonic-gate * 5830Sstevel@tonic-gate * The transfer wrapper represents a USB transfer on the bus and there 5840Sstevel@tonic-gate * is one instance per USB transfer. A transfer is made up of one or 5851500Ssl147100 * more transactions. EHCI uses one QTD for one transaction. So one 5861500Ssl147100 * transfer wrapper may have one or more QTDs associated. 5871500Ssl147100 * 5881500Ssl147100 * The data to be transferred are contained in the TW buffer which is 5891500Ssl147100 * virtually contiguous but physically discontiguous. When preparing 5901500Ssl147100 * the QTDs for a USB transfer, the DMA cookies corresponding to the 5911500Ssl147100 * TW buffer need to be walked through to retrieve the DMA addresses. 5920Sstevel@tonic-gate * 5930Sstevel@tonic-gate * Control and bulk pipes will have one transfer wrapper per transfer 5940Sstevel@tonic-gate * and where as Isochronous and Interrupt pipes will only have one 5950Sstevel@tonic-gate * transfer wrapper. The transfers wrapper are continually reused for 5960Sstevel@tonic-gate * the Interrupt and Isochronous pipes as those pipes are polled. 5970Sstevel@tonic-gate */ 5980Sstevel@tonic-gate typedef struct ehci_trans_wrapper { 5990Sstevel@tonic-gate struct ehci_trans_wrapper *tw_next; /* Next wrapper */ 6000Sstevel@tonic-gate ehci_pipe_private_t *tw_pipe_private; /* Back ptr */ 6010Sstevel@tonic-gate ddi_dma_handle_t tw_dmahandle; /* DMA handle */ 6020Sstevel@tonic-gate ddi_acc_handle_t tw_accesshandle; /* Acc hndle */ 6030Sstevel@tonic-gate ddi_dma_cookie_t tw_cookie; /* DMA cookie */ 6041500Ssl147100 uint_t tw_ncookies; /* DMA cookie count */ 6051500Ssl147100 uint_t tw_cookie_idx; /* DMA cookie index */ 6061500Ssl147100 size_t tw_dma_offs; /* DMA buffer offset */ 6070Sstevel@tonic-gate uint32_t tw_id; /* 32bit ID */ 6080Sstevel@tonic-gate size_t tw_length; /* Txfer length */ 6090Sstevel@tonic-gate char *tw_buf; /* Buffer for Xfer */ 6100Sstevel@tonic-gate usb_flags_t tw_flags; /* Flags */ 6110Sstevel@tonic-gate uint_t tw_num_qtds; /* Number of QTDs */ 6120Sstevel@tonic-gate ehci_qtd_t *tw_qtd_head; /* Head QTD */ 6130Sstevel@tonic-gate ehci_qtd_t *tw_qtd_tail; /* Tail QTD */ 6140Sstevel@tonic-gate uint_t tw_direction; /* Direction of QTD */ 6150Sstevel@tonic-gate 6160Sstevel@tonic-gate /* Current transfer request pointer */ 6170Sstevel@tonic-gate usb_opaque_t tw_curr_xfer_reqp; 6180Sstevel@tonic-gate 6190Sstevel@tonic-gate /* Transfer timeout information */ 6200Sstevel@tonic-gate int tw_timeout; /* Timeout value */ 6210Sstevel@tonic-gate struct ehci_trans_wrapper *tw_timeout_next; /* Xfer Timeout Q */ 6220Sstevel@tonic-gate 6230Sstevel@tonic-gate /* 6240Sstevel@tonic-gate * This is the function to call when this td is done. This way 6250Sstevel@tonic-gate * we don't have to look in the td to figure out what kind it is. 6260Sstevel@tonic-gate */ 6270Sstevel@tonic-gate ehci_handler_function_t tw_handle_qtd; 6280Sstevel@tonic-gate 6290Sstevel@tonic-gate /* 6300Sstevel@tonic-gate * This is the callback value used when processing a done td. 6310Sstevel@tonic-gate */ 6320Sstevel@tonic-gate usb_opaque_t tw_handle_callback_value; 6330Sstevel@tonic-gate 6340Sstevel@tonic-gate /* We preallocate all the td's for each tw and place them here */ 6350Sstevel@tonic-gate ehci_qtd_t *tw_qtd_free_list; 6360Sstevel@tonic-gate ehci_qtd_t *tw_alt_qtd; 6370Sstevel@tonic-gate } ehci_trans_wrapper_t; 6380Sstevel@tonic-gate 6390Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ehci_state_t::ehci_int_mutex, ehci_trans_wrapper)) 6400Sstevel@tonic-gate 6410Sstevel@tonic-gate /* 6420Sstevel@tonic-gate * Isochronous Transfer Wrapper 6430Sstevel@tonic-gate * 6440Sstevel@tonic-gate * This transfer wrapper is built specifically for the LOW/FULL/HIGH speed 6450Sstevel@tonic-gate * isochronous transfers. A transfer wrapper consists of one or more 6460Sstevel@tonic-gate * transactionsl, but there is one one instance per USB transfer request. 6470Sstevel@tonic-gate * 6480Sstevel@tonic-gate * The isochrnous transfer wrapper are continiously reused because these 6490Sstevel@tonic-gate * pipes are polled. 6500Sstevel@tonic-gate */ 6510Sstevel@tonic-gate typedef struct ehci_isoc_xwrapper { 6520Sstevel@tonic-gate struct ehci_isoc_xwrapper *itw_next; /* Next wrapper in pp */ 6530Sstevel@tonic-gate ehci_pipe_private_t *itw_pipe_private; 6540Sstevel@tonic-gate 6550Sstevel@tonic-gate /* DMA and memory pointers */ 6560Sstevel@tonic-gate ddi_dma_handle_t itw_dmahandle; /* DMA handle ETT */ 6570Sstevel@tonic-gate ddi_acc_handle_t itw_accesshandle; /* Acc hndle */ 6580Sstevel@tonic-gate ddi_dma_cookie_t itw_cookie; /* DMA cookie */ 6590Sstevel@tonic-gate 6600Sstevel@tonic-gate /* Transfer information */ 6610Sstevel@tonic-gate char *itw_buf; /* Buffer for Xfer */ 6620Sstevel@tonic-gate size_t itw_length; /* Txfer length */ 6630Sstevel@tonic-gate usb_flags_t itw_flags; /* Flags */ 6640Sstevel@tonic-gate usb_port_status_t itw_port_status; /* Port Speed */ 6650Sstevel@tonic-gate uint_t itw_direction; /* Direction of ITD */ 6660Sstevel@tonic-gate 6670Sstevel@tonic-gate /* ITD information */ 6680Sstevel@tonic-gate uint_t itw_num_itds; /* Number of ITDs */ 6690Sstevel@tonic-gate ehci_itd_t *itw_itd_head; /* Head ITD */ 6700Sstevel@tonic-gate ehci_itd_t *itw_itd_tail; /* Tail ITD */ 6710Sstevel@tonic-gate usb_isoc_req_t *itw_curr_xfer_reqp; 6720Sstevel@tonic-gate usb_isoc_pkt_descr_t *itw_curr_isoc_pktp; 6730Sstevel@tonic-gate 6740Sstevel@tonic-gate /* We preallocate all the td's for each tw and place them here */ 6750Sstevel@tonic-gate ehci_itd_t *itw_itd_free_list; 6760Sstevel@tonic-gate 6770Sstevel@tonic-gate /* Device and hub information needed by every iTD */ 6780Sstevel@tonic-gate uint_t itw_hub_addr; 6790Sstevel@tonic-gate uint_t itw_hub_port; 6800Sstevel@tonic-gate uint_t itw_endpoint_num; 6810Sstevel@tonic-gate uint_t itw_device_addr; 6820Sstevel@tonic-gate 6830Sstevel@tonic-gate /* 6840Sstevel@tonic-gate * Callback handling function and arguement. Called when an iTD is 6850Sstevel@tonic-gate * is done. 6860Sstevel@tonic-gate */ 6870Sstevel@tonic-gate usb_opaque_t itw_handle_callback_value; 6880Sstevel@tonic-gate 6890Sstevel@tonic-gate /* 32bit ID */ 6900Sstevel@tonic-gate uint32_t itw_id; 6910Sstevel@tonic-gate } ehci_isoc_xwrapper_t; 6920Sstevel@tonic-gate 6930Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ehci_state_t::ehci_int_mutex, ehci_isoc_xwrapper_t)) 6940Sstevel@tonic-gate 6950Sstevel@tonic-gate /* 6960Sstevel@tonic-gate * Time waits for the different EHCI specific operations. 6970Sstevel@tonic-gate * These timeout values are specified in terms of microseconds. 6980Sstevel@tonic-gate */ 6990Sstevel@tonic-gate #define EHCI_RESET_TIMEWAIT 10000 /* HC reset waiting time */ 7000Sstevel@tonic-gate #define EHCI_TIMEWAIT 10000 /* HC any other waiting time */ 7010Sstevel@tonic-gate #define EHCI_SOF_TIMEWAIT 20000 /* SOF Wait time */ 7020Sstevel@tonic-gate #define EHCI_TAKEOVER_DELAY 10000 /* HC take over waiting time */ 7030Sstevel@tonic-gate #define EHCI_TAKEOVER_WAIT_COUNT 25 /* HC take over waiting count */ 7040Sstevel@tonic-gate 7050Sstevel@tonic-gate /* These timeout values are specified in seconds */ 7060Sstevel@tonic-gate #define EHCI_DEFAULT_XFER_TIMEOUT 5 /* Default transfer timeout */ 7070Sstevel@tonic-gate #define EHCI_XFER_CMPL_TIMEWAIT 3 /* Xfers completion timewait */ 7080Sstevel@tonic-gate 7090Sstevel@tonic-gate /* EHCI flags for general use */ 7100Sstevel@tonic-gate #define EHCI_FLAGS_NOSLEEP 0x000 /* Don't wait for SOF */ 7110Sstevel@tonic-gate #define EHCI_FLAGS_SLEEP 0x100 /* Wait for SOF */ 7120Sstevel@tonic-gate #define EHCI_FLAGS_DMA_SYNC 0x200 /* Call ddi_dma_sync */ 7130Sstevel@tonic-gate 7140Sstevel@tonic-gate /* 7150Sstevel@tonic-gate * Maximum allowable data transfer size per transaction as supported 7160Sstevel@tonic-gate * by EHCI is 20k. (See EHCI Host Controller Interface Spec Rev 0.96) 7170Sstevel@tonic-gate * 7180Sstevel@tonic-gate * Also within QTD, there will be five buffer pointers abd each buffer 7190Sstevel@tonic-gate * pointer can transfer upto 4k bytes of data. 7200Sstevel@tonic-gate */ 7210Sstevel@tonic-gate #define EHCI_MAX_QTD_XFER_SIZE 0x5000 /* Maxmum data per transaction */ 7220Sstevel@tonic-gate #define EHCI_MAX_QTD_BUF_SIZE 0x1000 /* Maxmum data per buffer */ 7230Sstevel@tonic-gate 7240Sstevel@tonic-gate /* 7250Sstevel@tonic-gate * The maximum allowable bulk data transfer size. It can be different 7260Sstevel@tonic-gate * from EHCI_MAX_QTD_XFER_SIZE and if it is more then ehci driver will 7270Sstevel@tonic-gate * take care of breaking a bulk data request into multiples of ehci 7280Sstevel@tonic-gate * EHCI_MAX_QTD_XFER_SIZE until request is satisfied. Currently this 7290Sstevel@tonic-gate * value is set to 640k bytes. 7300Sstevel@tonic-gate */ 7310Sstevel@tonic-gate #define EHCI_MAX_BULK_XFER_SIZE 0xA0000 /* Maximum bulk transfer size */ 7320Sstevel@tonic-gate 7330Sstevel@tonic-gate /* 7340Sstevel@tonic-gate * Timeout flags 7350Sstevel@tonic-gate * 7360Sstevel@tonic-gate * These flags will be used to stop the timer before timeout handler 7370Sstevel@tonic-gate * gets executed. 7380Sstevel@tonic-gate */ 7390Sstevel@tonic-gate #define EHCI_REMOVE_XFER_IFLAST 1 /* Stop the timer if it is last QTD */ 7400Sstevel@tonic-gate #define EHCI_REMOVE_XFER_ALWAYS 2 /* Stop the timer without condition */ 7410Sstevel@tonic-gate 7420Sstevel@tonic-gate 7430Sstevel@tonic-gate /* 7440Sstevel@tonic-gate * High speed bandwidth allocation 7450Sstevel@tonic-gate * 7460Sstevel@tonic-gate * The following definitions are used during bandwidth calculations 7470Sstevel@tonic-gate * for a given high speed endpoint or high speed split transactions. 7480Sstevel@tonic-gate */ 7490Sstevel@tonic-gate #define HS_BUS_BANDWIDTH 7500 /* Up to 7500 bytes per 125us */ 7500Sstevel@tonic-gate #define HS_MAX_POLL_INTERVAL 16 /* Max high speed polling interval */ 7510Sstevel@tonic-gate #define HS_MIN_POLL_INTERVAL 1 /* Min high speed polling interval */ 7520Sstevel@tonic-gate #define HS_SOF 12 /* Length in bytes of High speed SOF */ 7530Sstevel@tonic-gate #define HS_EOF 70 /* Length in bytes of High speed EOF */ 7540Sstevel@tonic-gate #define TREE_HEIGHT 5 /* Log base 2 of 32 */ 7550Sstevel@tonic-gate 7560Sstevel@tonic-gate /* 7570Sstevel@tonic-gate * As per USB 2.0 specification section 5.5.4, 20% of bus time is reserved 7580Sstevel@tonic-gate * for the non-periodic high-speed transfers. Where as peridoic high-speed 7590Sstevel@tonic-gate * transfers will get 80% of the bus time. In one micro-frame or 125us, we 7600Sstevel@tonic-gate * can transfer 7500 bytes or 60,000 bits. 7610Sstevel@tonic-gate */ 7620Sstevel@tonic-gate #define HS_NON_PERIODIC_BANDWIDTH 1500 7630Sstevel@tonic-gate #define HS_PERIODIC_BANDWIDTH (HS_BUS_BANDWIDTH - HS_SOF - \ 7640Sstevel@tonic-gate HS_EOF - HS_NON_PERIODIC_BANDWIDTH) 7650Sstevel@tonic-gate 7660Sstevel@tonic-gate /* 7670Sstevel@tonic-gate * High speed periodic frame bandwidth will be eight times the micro frame 7680Sstevel@tonic-gate * high speed periodic bandwidth. 7690Sstevel@tonic-gate */ 7700Sstevel@tonic-gate #define HS_PERIODIC_FRAME_BANDWIDTH HS_PERIODIC_BANDWIDTH * EHCI_MAX_UFRAMES 7710Sstevel@tonic-gate 7720Sstevel@tonic-gate /* 7730Sstevel@tonic-gate * The following are the protocol overheads in terms of Bytes for the 7740Sstevel@tonic-gate * different transfer types. All these protocol overhead values are 7750Sstevel@tonic-gate * derived from the 5.11.3 section of USB 2.0 Specification. 7760Sstevel@tonic-gate */ 7770Sstevel@tonic-gate #define HS_NON_ISOC_PROTO_OVERHEAD 55 7780Sstevel@tonic-gate #define HS_ISOC_PROTO_OVERHEAD 38 7790Sstevel@tonic-gate 7800Sstevel@tonic-gate /* 7810Sstevel@tonic-gate * The following are THE protocol overheads in terms of Bytes for the 7820Sstevel@tonic-gate * start and complete split transactions tokens overheads. All these 7830Sstevel@tonic-gate * protocol overhead values are derived from the 8.4.2.2 and 8.4.2.3 7840Sstevel@tonic-gate * of USB2.0 Specification. 7850Sstevel@tonic-gate */ 7860Sstevel@tonic-gate #define START_SPLIT_OVERHEAD 04 7870Sstevel@tonic-gate #define COMPLETE_SPLIT_OVERHEAD 04 7880Sstevel@tonic-gate 7890Sstevel@tonic-gate /* 7900Sstevel@tonic-gate * The Host Controller (HC) delays are the USB host controller specific 7910Sstevel@tonic-gate * delays. The value shown below is the host controller delay for the 7920Sstevel@tonic-gate * given EHCI host controller. 7930Sstevel@tonic-gate */ 7940Sstevel@tonic-gate #define EHCI_HOST_CONTROLLER_DELAY 18 7950Sstevel@tonic-gate 7960Sstevel@tonic-gate /* 7970Sstevel@tonic-gate * Low/Full speed bandwidth allocation 7980Sstevel@tonic-gate * 7990Sstevel@tonic-gate * The following definitions are used during bandwidth calculations for 8000Sstevel@tonic-gate * a given high speed hub or a transaction translator (TT) and for a 8010Sstevel@tonic-gate * given low/full speed device connected to high speed hub or TT using 8020Sstevel@tonic-gate * split transactions 8030Sstevel@tonic-gate */ 8040Sstevel@tonic-gate #define FS_BUS_BANDWIDTH 1500 /* Up to 1500 bytes per 1ms */ 8050Sstevel@tonic-gate #define FS_MAX_POLL_INTERVAL 255 /* Max full speed poll interval */ 8060Sstevel@tonic-gate #define FS_MIN_POLL_INTERVAL 1 /* Min full speed polling interval */ 8070Sstevel@tonic-gate #define FS_SOF 6 /* Length in bytes of Full speed SOF */ 8080Sstevel@tonic-gate #define FS_EOF 4 /* Length in bytes of Full speed EOF */ 8090Sstevel@tonic-gate 8100Sstevel@tonic-gate /* 8110Sstevel@tonic-gate * Minimum polling interval for low speed endpoint 8120Sstevel@tonic-gate * 8130Sstevel@tonic-gate * According USB 2.0 Specification, a full-speed endpoint can specify 8140Sstevel@tonic-gate * a desired polling interval 1ms to 255ms and a low speed endpoints 8150Sstevel@tonic-gate * are limited to specifying only 10ms to 255ms. But some old keyboards 8160Sstevel@tonic-gate * and mice uses polling interval of 8ms. For compatibility purpose, 8170Sstevel@tonic-gate * we are using polling interval between 8ms and 255ms for low speed 8180Sstevel@tonic-gate * endpoints. The ehci driver will use 8ms polling interval if a low 8190Sstevel@tonic-gate * speed device reports a polling interval that is less than 8ms. 8200Sstevel@tonic-gate */ 8210Sstevel@tonic-gate #define LS_MAX_POLL_INTERVAL 255 /* Max low speed poll interval */ 8220Sstevel@tonic-gate #define LS_MIN_POLL_INTERVAL 8 /* Min low speed polling interval */ 8230Sstevel@tonic-gate 8240Sstevel@tonic-gate /* 8250Sstevel@tonic-gate * For non-periodic transfers, reserve atleast for one low-speed device 8260Sstevel@tonic-gate * transaction. According to USB Bandwidth Analysis white paper and also 8270Sstevel@tonic-gate * as per OHCI Specification 1.0a, section 7.3.5, page 123, one low-speed 8280Sstevel@tonic-gate * transaction takes 0x628h full speed bits (197 bytes), which comes to 8290Sstevel@tonic-gate * around 13% of USB frame time. 8300Sstevel@tonic-gate * 8310Sstevel@tonic-gate * The periodic transfers will get around 87% of USB frame time. 8320Sstevel@tonic-gate */ 8330Sstevel@tonic-gate #define FS_NON_PERIODIC_BANDWIDTH 197 8340Sstevel@tonic-gate #define FS_PERIODIC_BANDWIDTH (FS_BUS_BANDWIDTH - FS_SOF - \ 8350Sstevel@tonic-gate FS_EOF - FS_NON_PERIODIC_BANDWIDTH) 8360Sstevel@tonic-gate 8370Sstevel@tonic-gate /* 8380Sstevel@tonic-gate * The following are the protocol overheads in terms of Bytes for the 8390Sstevel@tonic-gate * different transfer types. All these protocol overhead values are 8400Sstevel@tonic-gate * derived from the 5.11.3 section of USB Specification and with the 8410Sstevel@tonic-gate * help of Bandwidth Analysis white paper which is posted on the USB 8420Sstevel@tonic-gate * developer forum. 8430Sstevel@tonic-gate */ 8440Sstevel@tonic-gate #define FS_NON_ISOC_PROTO_OVERHEAD 14 8450Sstevel@tonic-gate #define FS_ISOC_INPUT_PROTO_OVERHEAD 11 8460Sstevel@tonic-gate #define FS_ISOC_OUTPUT_PROTO_OVERHEAD 10 8470Sstevel@tonic-gate #define LOW_SPEED_PROTO_OVERHEAD 97 8480Sstevel@tonic-gate #define HUB_LOW_SPEED_PROTO_OVERHEAD 01 8490Sstevel@tonic-gate 8500Sstevel@tonic-gate /* The maximum amount of isoch data that can be transferred in one uFrame */ 8510Sstevel@tonic-gate #define MAX_UFRAME_SITD_XFER 188 8520Sstevel@tonic-gate 8530Sstevel@tonic-gate /* 8540Sstevel@tonic-gate * The low speed clock below represents that to transmit one low-speed 8550Sstevel@tonic-gate * bit takes eight times more than one full speed bit time. 8560Sstevel@tonic-gate */ 8570Sstevel@tonic-gate #define LOW_SPEED_CLOCK 8 8580Sstevel@tonic-gate 8590Sstevel@tonic-gate /* 8600Sstevel@tonic-gate * The Transaction Translator (TT) delay is the additional time needed 8610Sstevel@tonic-gate * to execute low/full speed transaction from high speed split transaction 8620Sstevel@tonic-gate * for the low/full device connected to the high speed extrenal hub. 8630Sstevel@tonic-gate */ 8640Sstevel@tonic-gate #define TT_DELAY 18 8650Sstevel@tonic-gate 8660Sstevel@tonic-gate 8670Sstevel@tonic-gate /* 8680Sstevel@tonic-gate * Macros for setting/getting information 8690Sstevel@tonic-gate */ 8700Sstevel@tonic-gate #define Get_QH(addr) ddi_get32(ehcip->ehci_qh_pool_mem_handle, \ 8710Sstevel@tonic-gate (uint32_t *)&addr) 8720Sstevel@tonic-gate 8730Sstevel@tonic-gate #define Set_QH(addr, val) ddi_put32(ehcip->ehci_qh_pool_mem_handle, \ 8740Sstevel@tonic-gate ((uint32_t *)&addr), \ 8750Sstevel@tonic-gate ((int32_t)(val))) 8760Sstevel@tonic-gate 8770Sstevel@tonic-gate #define Get_QTD(addr) ddi_get32(ehcip->ehci_qtd_pool_mem_handle, \ 8780Sstevel@tonic-gate (uint32_t *)&addr) 8790Sstevel@tonic-gate 8800Sstevel@tonic-gate #define Set_QTD(addr, val) ddi_put32(ehcip->ehci_qtd_pool_mem_handle, \ 8810Sstevel@tonic-gate ((uint32_t *)&addr), \ 8820Sstevel@tonic-gate ((int32_t)(val))) 8830Sstevel@tonic-gate 8840Sstevel@tonic-gate #define Get_ITD(addr) ddi_get32(ehcip->ehci_itd_pool_mem_handle, \ 8850Sstevel@tonic-gate (uint32_t *)&addr) 8860Sstevel@tonic-gate 8870Sstevel@tonic-gate #define Set_ITD(addr, val) ddi_put32(ehcip->ehci_itd_pool_mem_handle, \ 8880Sstevel@tonic-gate ((uint32_t *)&addr), \ 8890Sstevel@tonic-gate ((int32_t)(val))) 8900Sstevel@tonic-gate 8910Sstevel@tonic-gate #define Get_ITD_BODY(ptr, addr) ddi_get32( \ 8920Sstevel@tonic-gate ehcip->ehci_itd_pool_mem_handle, \ 8930Sstevel@tonic-gate (uint32_t *)&ptr->itd_body[addr]) 8940Sstevel@tonic-gate 8950Sstevel@tonic-gate #define Set_ITD_BODY(ptr, addr, val) ddi_put32( \ 8960Sstevel@tonic-gate ehcip->ehci_itd_pool_mem_handle, \ 8970Sstevel@tonic-gate ((uint32_t *)&ptr->itd_body[addr]),\ 8980Sstevel@tonic-gate ((int32_t)(val))) 8990Sstevel@tonic-gate 9003255Slg150142 #define Get_ITD_INDEX(ptr, pos) ddi_get32( \ 9013255Slg150142 ehcip->ehci_itd_pool_mem_handle, \ 9023255Slg150142 (uint32_t *)&ptr->itd_index[pos]) 9033255Slg150142 9043255Slg150142 #define Set_ITD_INDEX(ptr, pos, val) ddi_put32( \ 9053255Slg150142 ehcip->ehci_itd_pool_mem_handle, \ 9063255Slg150142 ((uint32_t *)&ptr->itd_index[pos]),\ 9073255Slg150142 ((uint32_t)(val))) 9083255Slg150142 9090Sstevel@tonic-gate #define Get_ITD_FRAME(addr) ddi_get64( \ 9100Sstevel@tonic-gate ehcip->ehci_itd_pool_mem_handle, \ 9110Sstevel@tonic-gate (uint64_t *)&addr) 9120Sstevel@tonic-gate 9130Sstevel@tonic-gate #define Set_ITD_FRAME(addr, val) ddi_put64( \ 9140Sstevel@tonic-gate ehcip->ehci_itd_pool_mem_handle, \ 9150Sstevel@tonic-gate ((uint64_t *)&addr), \ 9160Sstevel@tonic-gate (val)) 9170Sstevel@tonic-gate 9180Sstevel@tonic-gate #define Get_PFLT(addr) ddi_get32(ehcip->ehci_pflt_mem_handle, \ 9190Sstevel@tonic-gate (uint32_t *)&addr) 9200Sstevel@tonic-gate 9210Sstevel@tonic-gate #define Set_PFLT(addr, val) ddi_put32(ehcip->ehci_pflt_mem_handle, \ 9220Sstevel@tonic-gate ((uint32_t *)&addr), \ 9230Sstevel@tonic-gate ((int32_t)(uintptr_t)(val))) 9240Sstevel@tonic-gate 9250Sstevel@tonic-gate #define Get_8Cap(addr) ddi_get8(ehcip->ehci_caps_handle, \ 9260Sstevel@tonic-gate (uint8_t *)&ehcip->ehci_capsp->addr) 9270Sstevel@tonic-gate 9280Sstevel@tonic-gate #define Get_16Cap(addr) ddi_get16(ehcip->ehci_caps_handle, \ 9290Sstevel@tonic-gate (uint16_t *)&ehcip->ehci_capsp->addr) 9300Sstevel@tonic-gate 9310Sstevel@tonic-gate #define Get_Cap(addr) ddi_get32(ehcip->ehci_caps_handle, \ 9320Sstevel@tonic-gate (uint32_t *)&ehcip->ehci_capsp->addr) 9330Sstevel@tonic-gate 9340Sstevel@tonic-gate #define Get_OpReg(addr) ddi_get32(ehcip->ehci_caps_handle, \ 9350Sstevel@tonic-gate (uint32_t *)&ehcip->ehci_regsp->addr) 9360Sstevel@tonic-gate 9370Sstevel@tonic-gate #define Set_OpReg(addr, val) ddi_put32(ehcip->ehci_caps_handle, \ 9380Sstevel@tonic-gate ((uint32_t *)&ehcip->ehci_regsp->addr), \ 9390Sstevel@tonic-gate ((int32_t)(val))) 9400Sstevel@tonic-gate 9413255Slg150142 #define CalculateITDMultiField(pkgSize) (1 + (((pkgSize)>>11) & 0x03)) 9423255Slg150142 9432225Sgk73471 #define EHCI_MAX_RETRY 10 9442225Sgk73471 9452225Sgk73471 #define Set_OpRegRetry(addr, val, r) \ 9462225Sgk73471 while (Get_OpReg(addr) != val) { \ 9472225Sgk73471 if (r >= EHCI_MAX_RETRY) \ 9482225Sgk73471 break; \ 9492225Sgk73471 r++; \ 9502225Sgk73471 Set_OpReg(addr, val); \ 9512225Sgk73471 } 9522225Sgk73471 9530Sstevel@tonic-gate #define Sync_QH_QTD_Pool(ehcip) (void) ddi_dma_sync( \ 9540Sstevel@tonic-gate ehcip->ehci_qh_pool_dma_handle, \ 9550Sstevel@tonic-gate 0, EHCI_QH_POOL_SIZE * sizeof (ehci_qh_t), \ 9560Sstevel@tonic-gate DDI_DMA_SYNC_FORCPU); \ 9570Sstevel@tonic-gate (void) ddi_dma_sync( \ 9580Sstevel@tonic-gate ehcip->ehci_qtd_pool_dma_handle, \ 9590Sstevel@tonic-gate 0, EHCI_QTD_POOL_SIZE * sizeof (ehci_qtd_t), \ 9600Sstevel@tonic-gate DDI_DMA_SYNC_FORCPU); 9610Sstevel@tonic-gate 9620Sstevel@tonic-gate #define Sync_ITD_Pool(ehcip) (void) ddi_dma_sync( \ 9630Sstevel@tonic-gate ehcip->ehci_itd_pool_dma_handle, \ 9640Sstevel@tonic-gate 0, EHCI_ITD_POOL_SIZE * sizeof (ehci_itd_t), \ 9650Sstevel@tonic-gate DDI_DMA_SYNC_FORCPU); 9660Sstevel@tonic-gate 9670Sstevel@tonic-gate #define Sync_IO_Buffer(dma_handle, length) \ 9680Sstevel@tonic-gate (void) ddi_dma_sync(dma_handle, \ 9690Sstevel@tonic-gate 0, length, DDI_DMA_SYNC_FORCPU); 9700Sstevel@tonic-gate 9710Sstevel@tonic-gate #define Sync_IO_Buffer_for_device(dma_handle, length) \ 9720Sstevel@tonic-gate (void) ddi_dma_sync(dma_handle, \ 9730Sstevel@tonic-gate 0, length, DDI_DMA_SYNC_FORDEV); 9740Sstevel@tonic-gate 9750Sstevel@tonic-gate /* 9760Sstevel@tonic-gate * Macros to speed handling of 32bit IDs 9770Sstevel@tonic-gate */ 9780Sstevel@tonic-gate #define EHCI_GET_ID(x) id32_alloc((void *)(x), KM_SLEEP) 9790Sstevel@tonic-gate #define EHCI_LOOKUP_ID(x) id32_lookup((x)) 9800Sstevel@tonic-gate #define EHCI_FREE_ID(x) id32_free((x)) 9810Sstevel@tonic-gate 9820Sstevel@tonic-gate 9830Sstevel@tonic-gate /* 9840Sstevel@tonic-gate * Miscellaneous definitions. 9850Sstevel@tonic-gate */ 9860Sstevel@tonic-gate 9870Sstevel@tonic-gate /* Data toggle bits */ 9880Sstevel@tonic-gate #define DATA0 0 9890Sstevel@tonic-gate #define DATA1 1 9900Sstevel@tonic-gate 9910Sstevel@tonic-gate /* Halt bit actions */ 9920Sstevel@tonic-gate #define CLEAR_HALT 0 9930Sstevel@tonic-gate #define SET_HALT 1 9940Sstevel@tonic-gate 9950Sstevel@tonic-gate typedef uint_t halt_bit_t; 9960Sstevel@tonic-gate 9970Sstevel@tonic-gate /* 9980Sstevel@tonic-gate * Setup Packet 9990Sstevel@tonic-gate */ 10000Sstevel@tonic-gate typedef struct setup_pkt { 10010Sstevel@tonic-gate uchar_t bmRequestType; 10020Sstevel@tonic-gate uchar_t bRequest; 10030Sstevel@tonic-gate ushort_t wValue; 10040Sstevel@tonic-gate ushort_t wIndex; 10050Sstevel@tonic-gate ushort_t wLength; 10060Sstevel@tonic-gate }setup_pkt_t; 10070Sstevel@tonic-gate 10080Sstevel@tonic-gate #define SETUP_SIZE 8 /* Setup packet is always 8 bytes */ 10090Sstevel@tonic-gate 10100Sstevel@tonic-gate #define REQUEST_TYPE_OFFSET 0 10110Sstevel@tonic-gate #define REQUEST_OFFSET 1 10120Sstevel@tonic-gate #define VALUE_OFFSET 2 10130Sstevel@tonic-gate #define INDEX_OFFSET 4 10140Sstevel@tonic-gate #define LENGTH_OFFSET 6 10150Sstevel@tonic-gate 10160Sstevel@tonic-gate #define TYPE_DEV_TO_HOST 0x80000000 10170Sstevel@tonic-gate #define DEVICE 0x00000001 10180Sstevel@tonic-gate #define CONFIGURATION 0x00000002 10190Sstevel@tonic-gate 10200Sstevel@tonic-gate /* 10210Sstevel@tonic-gate * The following are used in attach to indicate 10220Sstevel@tonic-gate * what has been succesfully allocated, so detach 10230Sstevel@tonic-gate * can remove them. 10240Sstevel@tonic-gate */ 10250Sstevel@tonic-gate #define EHCI_ATTACH 0x01 /* ehci driver initilization */ 10260Sstevel@tonic-gate #define EHCI_ZALLOC 0x02 /* Memory for ehci state structure */ 10270Sstevel@tonic-gate #define EHCI_INTR 0x04 /* Interrupt handler registered */ 10280Sstevel@tonic-gate #define EHCI_USBAREG 0x08 /* USBA registered */ 10290Sstevel@tonic-gate #define EHCI_RHREG 0x10 /* Root hub driver loaded */ 10300Sstevel@tonic-gate 10310Sstevel@tonic-gate /* 10320Sstevel@tonic-gate * This variable is used in the EHCI_FLAGS to tell the ISR to broadcase 10330Sstevel@tonic-gate * the ehci_async_schedule_advance_cv when an intr occurs. It is used to 10340Sstevel@tonic-gate * make sure that EHCI is receiving interrupts. 10350Sstevel@tonic-gate */ 10360Sstevel@tonic-gate #define EHCI_CV_INTR 0x20 /* Ask INTR to broadcast cv */ 10370Sstevel@tonic-gate 10380Sstevel@tonic-gate #define EHCI_UNIT(dev) (getminor((dev)) & ~HUBD_IS_ROOT_HUB) 10390Sstevel@tonic-gate 10400Sstevel@tonic-gate /* 10410Sstevel@tonic-gate * Debug printing 10420Sstevel@tonic-gate * Masks 10430Sstevel@tonic-gate */ 10440Sstevel@tonic-gate #define PRINT_MASK_ATTA 0x00000001 /* Attach time */ 10450Sstevel@tonic-gate #define PRINT_MASK_LISTS 0x00000002 /* List management */ 10460Sstevel@tonic-gate #define PRINT_MASK_ROOT_HUB 0x00000004 /* Root hub stuff */ 10470Sstevel@tonic-gate #define PRINT_MASK_ALLOC 0x00000008 /* Alloc/dealloc descr */ 10480Sstevel@tonic-gate #define PRINT_MASK_INTR 0x00000010 /* Interrupt handling */ 10490Sstevel@tonic-gate #define PRINT_MASK_BW 0x00000020 /* Bandwidth */ 10500Sstevel@tonic-gate #define PRINT_MASK_CBOPS 0x00000040 /* CB-OPS */ 10510Sstevel@tonic-gate #define PRINT_MASK_HCDI 0x00000080 /* HCDI entry points */ 10520Sstevel@tonic-gate #define PRINT_MASK_DUMPING 0x00000100 /* Dump ehci info */ 10530Sstevel@tonic-gate #define PRINT_MASK_ALL 0xFFFFFFFF 10540Sstevel@tonic-gate 10557293Sbc224572 #define PCI_VENDOR_NVIDIA 0x10de /* PCI Vendor-id NVIDIA */ 10567293Sbc224572 #define PCI_DEVICE_NVIDIA_CK804 0x5b 10577669SBinzi.Cao@Sun.COM #define PCI_DEVICE_NVIDIA_MCP04 0x3c 10580Sstevel@tonic-gate /* 10590Sstevel@tonic-gate * workaround for ALI chips 10600Sstevel@tonic-gate */ 10610Sstevel@tonic-gate #define PCI_VENDOR_ALI 0x10b9 /* PCI Vendor-id Acer */ 1062122Shx149380 1063122Shx149380 /* 1064880Sfrits * NEC on COMBO and Uli M1575 can support PM 1065880Sfrits */ 1066880Sfrits #define PCI_VENDOR_NEC_COMBO 0x1033 1067880Sfrits #define PCI_DEVICE_NEC_COMBO 0xe0 1068880Sfrits #define PCI_VENDOR_ULi_M1575 0x10b9 1069880Sfrits #define PCI_DEVICE_ULi_M1575 0x5239 1070880Sfrits 1071880Sfrits /* 1072122Shx149380 * VIA chips have some problems, the workaround can ensure those chips 1073122Shx149380 * work reliably. Revisions >= 0x80 are part of a southbridge and appear 1074122Shx149380 * to be reliable. 1075122Shx149380 */ 10760Sstevel@tonic-gate #define PCI_VENDOR_VIA 0x1106 /* PCI Vendor-id VIA */ 1077122Shx149380 #define PCI_VIA_REVISION_6212 0x80 /* VIA 6212 revision ID */ 10780Sstevel@tonic-gate 10790Sstevel@tonic-gate #define EHCI_VIA_LOST_INTERRUPTS 0x01 10800Sstevel@tonic-gate #define EHCI_VIA_ASYNC_SCHEDULE 0x02 10810Sstevel@tonic-gate #define EHCI_VIA_REDUCED_MAX_BULK_XFER_SIZE 0x04 10820Sstevel@tonic-gate 10830Sstevel@tonic-gate #define EHCI_VIA_WORKAROUNDS \ 10840Sstevel@tonic-gate (EHCI_VIA_LOST_INTERRUPTS | \ 10850Sstevel@tonic-gate EHCI_VIA_ASYNC_SCHEDULE | \ 10860Sstevel@tonic-gate EHCI_VIA_REDUCED_MAX_BULK_XFER_SIZE) 10870Sstevel@tonic-gate 10880Sstevel@tonic-gate #define EHCI_VIA_MAX_BULK_XFER_SIZE 0x8000 /* Maximum bulk transfer size */ 10890Sstevel@tonic-gate 10900Sstevel@tonic-gate 10910Sstevel@tonic-gate /* 10920Sstevel@tonic-gate * EHCI HCDI entry points 10930Sstevel@tonic-gate * 10940Sstevel@tonic-gate * The Host Controller Driver Interfaces (HCDI) are the software interfaces 10950Sstevel@tonic-gate * between the Universal Serial Bus Driver (USBA) and the Host Controller 10960Sstevel@tonic-gate * Driver (HCD). The HCDI interfaces or entry points are subject to change. 10970Sstevel@tonic-gate */ 10980Sstevel@tonic-gate int ehci_hcdi_pipe_open( 10990Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 11000Sstevel@tonic-gate usb_flags_t usb_flags); 11010Sstevel@tonic-gate int ehci_hcdi_pipe_close( 11020Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 11030Sstevel@tonic-gate usb_flags_t usb_flags); 11040Sstevel@tonic-gate int ehci_hcdi_pipe_reset( 11050Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 11060Sstevel@tonic-gate usb_flags_t usb_flags); 11078945SGuoqing.Zhu@Sun.COM void ehci_hcdi_pipe_reset_data_toggle( 11088945SGuoqing.Zhu@Sun.COM usba_pipe_handle_data_t *ph); 11090Sstevel@tonic-gate int ehci_hcdi_pipe_ctrl_xfer( 11100Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 11110Sstevel@tonic-gate usb_ctrl_req_t *ctrl_reqp, 11120Sstevel@tonic-gate usb_flags_t usb_flags); 11130Sstevel@tonic-gate int ehci_hcdi_bulk_transfer_size( 11140Sstevel@tonic-gate usba_device_t *usba_device, 11150Sstevel@tonic-gate size_t *size); 11160Sstevel@tonic-gate int ehci_hcdi_pipe_bulk_xfer( 11170Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 11180Sstevel@tonic-gate usb_bulk_req_t *bulk_reqp, 11190Sstevel@tonic-gate usb_flags_t usb_flags); 11200Sstevel@tonic-gate int ehci_hcdi_pipe_intr_xfer( 11210Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 11220Sstevel@tonic-gate usb_intr_req_t *intr_req, 11230Sstevel@tonic-gate usb_flags_t usb_flags); 11240Sstevel@tonic-gate int ehci_hcdi_pipe_stop_intr_polling( 11250Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 11260Sstevel@tonic-gate usb_flags_t usb_flags); 11275773Sqz150045 int ehci_hcdi_get_current_frame_number( 11285773Sqz150045 usba_device_t *usba_device, 11295773Sqz150045 usb_frame_number_t *frame_number); 11305773Sqz150045 int ehci_hcdi_get_max_isoc_pkts( 11315773Sqz150045 usba_device_t *usba_device, 11325773Sqz150045 uint_t *max_isoc_pkts_per_request); 11330Sstevel@tonic-gate int ehci_hcdi_pipe_isoc_xfer( 11340Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 11350Sstevel@tonic-gate usb_isoc_req_t *isoc_reqp, 11360Sstevel@tonic-gate usb_flags_t usb_flags); 11370Sstevel@tonic-gate int ehci_hcdi_pipe_stop_isoc_polling( 11380Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 11390Sstevel@tonic-gate usb_flags_t usb_flags); 11400Sstevel@tonic-gate 11410Sstevel@tonic-gate /* 11420Sstevel@tonic-gate * EHCI Polled entry points function prototypes. 11430Sstevel@tonic-gate */ 11440Sstevel@tonic-gate int ehci_hcdi_polled_input_init( 11450Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 11460Sstevel@tonic-gate uchar_t **polled_buf, 11470Sstevel@tonic-gate usb_console_info_impl_t *info); 11480Sstevel@tonic-gate int ehci_hcdi_polled_input_enter( 11490Sstevel@tonic-gate usb_console_info_impl_t *info); 11500Sstevel@tonic-gate int ehci_hcdi_polled_read( 11510Sstevel@tonic-gate usb_console_info_impl_t *info, 11520Sstevel@tonic-gate uint_t *num_characters); 11530Sstevel@tonic-gate int ehci_hcdi_polled_input_exit( 11540Sstevel@tonic-gate usb_console_info_impl_t *info); 11550Sstevel@tonic-gate int ehci_hcdi_polled_input_fini( 11560Sstevel@tonic-gate usb_console_info_impl_t *info); 11579095SZhigang.Lu@Sun.COM int ehci_hcdi_polled_output_init( 11589095SZhigang.Lu@Sun.COM usba_pipe_handle_data_t *ph, 11599095SZhigang.Lu@Sun.COM usb_console_info_impl_t *console_output_info); 11609095SZhigang.Lu@Sun.COM int ehci_hcdi_polled_output_enter( 11619095SZhigang.Lu@Sun.COM usb_console_info_impl_t *info); 11629095SZhigang.Lu@Sun.COM int ehci_hcdi_polled_write( 11639095SZhigang.Lu@Sun.COM usb_console_info_impl_t *info, 11649095SZhigang.Lu@Sun.COM uchar_t *buf, 11659095SZhigang.Lu@Sun.COM uint_t num_characters, 11669095SZhigang.Lu@Sun.COM uint_t *num_characters_written); 11679095SZhigang.Lu@Sun.COM int ehci_hcdi_polled_output_exit( 11689095SZhigang.Lu@Sun.COM usb_console_info_impl_t *info); 11699095SZhigang.Lu@Sun.COM int ehci_hcdi_polled_output_fini( 11709095SZhigang.Lu@Sun.COM usb_console_info_impl_t *info); 11710Sstevel@tonic-gate /* 11720Sstevel@tonic-gate * EHCI Root Hub entry points function prototypes. 11730Sstevel@tonic-gate */ 11740Sstevel@tonic-gate int ehci_init_root_hub( 11750Sstevel@tonic-gate ehci_state_t *ehcip); 11760Sstevel@tonic-gate int ehci_load_root_hub_driver( 11770Sstevel@tonic-gate ehci_state_t *ehcip); 11780Sstevel@tonic-gate int ehci_unload_root_hub_driver( 11790Sstevel@tonic-gate ehci_state_t *ehcip); 11800Sstevel@tonic-gate int ehci_handle_root_hub_pipe_open( 11810Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 11820Sstevel@tonic-gate usb_flags_t flags); 11830Sstevel@tonic-gate int ehci_handle_root_hub_pipe_close( 11840Sstevel@tonic-gate usba_pipe_handle_data_t *ph); 11850Sstevel@tonic-gate int ehci_handle_root_hub_pipe_reset( 11860Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 11870Sstevel@tonic-gate usb_flags_t flags); 11880Sstevel@tonic-gate int ehci_handle_root_hub_request( 11890Sstevel@tonic-gate ehci_state_t *ehcip, 11900Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 11910Sstevel@tonic-gate usb_ctrl_req_t *ctrl_reqp); 11920Sstevel@tonic-gate int ehci_handle_root_hub_pipe_start_intr_polling( 11930Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 11940Sstevel@tonic-gate usb_intr_req_t *intr_reqp, 11950Sstevel@tonic-gate usb_flags_t flags); 11960Sstevel@tonic-gate void ehci_handle_root_hub_pipe_stop_intr_polling( 11970Sstevel@tonic-gate usba_pipe_handle_data_t *ph, 11980Sstevel@tonic-gate usb_flags_t flags); 11990Sstevel@tonic-gate 12000Sstevel@tonic-gate /* 12010Sstevel@tonic-gate * EHCI Interrupt Handler entry point. 12020Sstevel@tonic-gate */ 1203965Sgovinda uint_t ehci_intr(caddr_t arg1, 1204965Sgovinda caddr_t arg2); 12050Sstevel@tonic-gate 12060Sstevel@tonic-gate #ifdef __cplusplus 12070Sstevel@tonic-gate } 12080Sstevel@tonic-gate #endif 12090Sstevel@tonic-gate 12100Sstevel@tonic-gate #endif /* _SYS_USB_EHCID_H */ 1211