18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2001-2002 by David Brownell 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef __LINUX_EHCI_HCD_H 78c2ecf20Sopenharmony_ci#define __LINUX_EHCI_HCD_H 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci/* definitions used for the EHCI driver */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci/* 128c2ecf20Sopenharmony_ci * __hc32 and __hc16 are "Host Controller" types, they may be equivalent to 138c2ecf20Sopenharmony_ci * __leXX (normally) or __beXX (given EHCI_BIG_ENDIAN_DESC), depending on 148c2ecf20Sopenharmony_ci * the host controller implementation. 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * To facilitate the strongest possible byte-order checking from "sparse" 178c2ecf20Sopenharmony_ci * and so on, we use __leXX unless that's not practical. 188c2ecf20Sopenharmony_ci */ 198c2ecf20Sopenharmony_ci#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_DESC 208c2ecf20Sopenharmony_citypedef __u32 __bitwise __hc32; 218c2ecf20Sopenharmony_citypedef __u16 __bitwise __hc16; 228c2ecf20Sopenharmony_ci#else 238c2ecf20Sopenharmony_ci#define __hc32 __le32 248c2ecf20Sopenharmony_ci#define __hc16 __le16 258c2ecf20Sopenharmony_ci#endif 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci/* statistics can be kept for tuning/monitoring */ 288c2ecf20Sopenharmony_ci#ifdef CONFIG_DYNAMIC_DEBUG 298c2ecf20Sopenharmony_ci#define EHCI_STATS 308c2ecf20Sopenharmony_ci#endif 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_cistruct ehci_stats { 338c2ecf20Sopenharmony_ci /* irq usage */ 348c2ecf20Sopenharmony_ci unsigned long normal; 358c2ecf20Sopenharmony_ci unsigned long error; 368c2ecf20Sopenharmony_ci unsigned long iaa; 378c2ecf20Sopenharmony_ci unsigned long lost_iaa; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci /* termination of urbs from core */ 408c2ecf20Sopenharmony_ci unsigned long complete; 418c2ecf20Sopenharmony_ci unsigned long unlink; 428c2ecf20Sopenharmony_ci}; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci/* 458c2ecf20Sopenharmony_ci * Scheduling and budgeting information for periodic transfers, for both 468c2ecf20Sopenharmony_ci * high-speed devices and full/low-speed devices lying behind a TT. 478c2ecf20Sopenharmony_ci */ 488c2ecf20Sopenharmony_cistruct ehci_per_sched { 498c2ecf20Sopenharmony_ci struct usb_device *udev; /* access to the TT */ 508c2ecf20Sopenharmony_ci struct usb_host_endpoint *ep; 518c2ecf20Sopenharmony_ci struct list_head ps_list; /* node on ehci_tt's ps_list */ 528c2ecf20Sopenharmony_ci u16 tt_usecs; /* time on the FS/LS bus */ 538c2ecf20Sopenharmony_ci u16 cs_mask; /* C-mask and S-mask bytes */ 548c2ecf20Sopenharmony_ci u16 period; /* actual period in frames */ 558c2ecf20Sopenharmony_ci u16 phase; /* actual phase, frame part */ 568c2ecf20Sopenharmony_ci u8 bw_phase; /* same, for bandwidth 578c2ecf20Sopenharmony_ci reservation */ 588c2ecf20Sopenharmony_ci u8 phase_uf; /* uframe part of the phase */ 598c2ecf20Sopenharmony_ci u8 usecs, c_usecs; /* times on the HS bus */ 608c2ecf20Sopenharmony_ci u8 bw_uperiod; /* period in microframes, for 618c2ecf20Sopenharmony_ci bandwidth reservation */ 628c2ecf20Sopenharmony_ci u8 bw_period; /* same, in frames */ 638c2ecf20Sopenharmony_ci}; 648c2ecf20Sopenharmony_ci#define NO_FRAME 29999 /* frame not assigned yet */ 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci/* ehci_hcd->lock guards shared data against other CPUs: 678c2ecf20Sopenharmony_ci * ehci_hcd: async, unlink, periodic (and shadow), ... 688c2ecf20Sopenharmony_ci * usb_host_endpoint: hcpriv 698c2ecf20Sopenharmony_ci * ehci_qh: qh_next, qtd_list 708c2ecf20Sopenharmony_ci * ehci_qtd: qtd_list 718c2ecf20Sopenharmony_ci * 728c2ecf20Sopenharmony_ci * Also, hold this lock when talking to HC registers or 738c2ecf20Sopenharmony_ci * when updating hw_* fields in shared qh/qtd/... structures. 748c2ecf20Sopenharmony_ci */ 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci#define EHCI_MAX_ROOT_PORTS 15 /* see HCS_N_PORTS */ 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci/* 798c2ecf20Sopenharmony_ci * ehci_rh_state values of EHCI_RH_RUNNING or above mean that the 808c2ecf20Sopenharmony_ci * controller may be doing DMA. Lower values mean there's no DMA. 818c2ecf20Sopenharmony_ci */ 828c2ecf20Sopenharmony_cienum ehci_rh_state { 838c2ecf20Sopenharmony_ci EHCI_RH_HALTED, 848c2ecf20Sopenharmony_ci EHCI_RH_SUSPENDED, 858c2ecf20Sopenharmony_ci EHCI_RH_RUNNING, 868c2ecf20Sopenharmony_ci EHCI_RH_STOPPING 878c2ecf20Sopenharmony_ci}; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci/* 908c2ecf20Sopenharmony_ci * Timer events, ordered by increasing delay length. 918c2ecf20Sopenharmony_ci * Always update event_delays_ns[] and event_handlers[] (defined in 928c2ecf20Sopenharmony_ci * ehci-timer.c) in parallel with this list. 938c2ecf20Sopenharmony_ci */ 948c2ecf20Sopenharmony_cienum ehci_hrtimer_event { 958c2ecf20Sopenharmony_ci EHCI_HRTIMER_POLL_ASS, /* Poll for async schedule off */ 968c2ecf20Sopenharmony_ci EHCI_HRTIMER_POLL_PSS, /* Poll for periodic schedule off */ 978c2ecf20Sopenharmony_ci EHCI_HRTIMER_POLL_DEAD, /* Wait for dead controller to stop */ 988c2ecf20Sopenharmony_ci EHCI_HRTIMER_UNLINK_INTR, /* Wait for interrupt QH unlink */ 998c2ecf20Sopenharmony_ci EHCI_HRTIMER_FREE_ITDS, /* Wait for unused iTDs and siTDs */ 1008c2ecf20Sopenharmony_ci EHCI_HRTIMER_ACTIVE_UNLINK, /* Wait while unlinking an active QH */ 1018c2ecf20Sopenharmony_ci EHCI_HRTIMER_START_UNLINK_INTR, /* Unlink empty interrupt QHs */ 1028c2ecf20Sopenharmony_ci EHCI_HRTIMER_ASYNC_UNLINKS, /* Unlink empty async QHs */ 1038c2ecf20Sopenharmony_ci EHCI_HRTIMER_IAA_WATCHDOG, /* Handle lost IAA interrupts */ 1048c2ecf20Sopenharmony_ci EHCI_HRTIMER_DISABLE_PERIODIC, /* Wait to disable periodic sched */ 1058c2ecf20Sopenharmony_ci EHCI_HRTIMER_DISABLE_ASYNC, /* Wait to disable async sched */ 1068c2ecf20Sopenharmony_ci EHCI_HRTIMER_IO_WATCHDOG, /* Check for missing IRQs */ 1078c2ecf20Sopenharmony_ci EHCI_HRTIMER_NUM_EVENTS /* Must come last */ 1088c2ecf20Sopenharmony_ci}; 1098c2ecf20Sopenharmony_ci#define EHCI_HRTIMER_NO_EVENT 99 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_cistruct ehci_hcd { /* one per controller */ 1128c2ecf20Sopenharmony_ci /* timing support */ 1138c2ecf20Sopenharmony_ci enum ehci_hrtimer_event next_hrtimer_event; 1148c2ecf20Sopenharmony_ci unsigned enabled_hrtimer_events; 1158c2ecf20Sopenharmony_ci ktime_t hr_timeouts[EHCI_HRTIMER_NUM_EVENTS]; 1168c2ecf20Sopenharmony_ci struct hrtimer hrtimer; 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci int PSS_poll_count; 1198c2ecf20Sopenharmony_ci int ASS_poll_count; 1208c2ecf20Sopenharmony_ci int died_poll_count; 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci /* glue to PCI and HCD framework */ 1238c2ecf20Sopenharmony_ci struct ehci_caps __iomem *caps; 1248c2ecf20Sopenharmony_ci struct ehci_regs __iomem *regs; 1258c2ecf20Sopenharmony_ci struct ehci_dbg_port __iomem *debug; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci __u32 hcs_params; /* cached register copy */ 1288c2ecf20Sopenharmony_ci spinlock_t lock; 1298c2ecf20Sopenharmony_ci enum ehci_rh_state rh_state; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci /* general schedule support */ 1328c2ecf20Sopenharmony_ci bool scanning:1; 1338c2ecf20Sopenharmony_ci bool need_rescan:1; 1348c2ecf20Sopenharmony_ci bool intr_unlinking:1; 1358c2ecf20Sopenharmony_ci bool iaa_in_progress:1; 1368c2ecf20Sopenharmony_ci bool async_unlinking:1; 1378c2ecf20Sopenharmony_ci bool shutdown:1; 1388c2ecf20Sopenharmony_ci struct ehci_qh *qh_scan_next; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci /* async schedule support */ 1418c2ecf20Sopenharmony_ci struct ehci_qh *async; 1428c2ecf20Sopenharmony_ci struct ehci_qh *dummy; /* For AMD quirk use */ 1438c2ecf20Sopenharmony_ci struct list_head async_unlink; 1448c2ecf20Sopenharmony_ci struct list_head async_idle; 1458c2ecf20Sopenharmony_ci unsigned async_unlink_cycle; 1468c2ecf20Sopenharmony_ci unsigned async_count; /* async activity count */ 1478c2ecf20Sopenharmony_ci __hc32 old_current; /* Test for QH becoming */ 1488c2ecf20Sopenharmony_ci __hc32 old_token; /* inactive during unlink */ 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci /* periodic schedule support */ 1518c2ecf20Sopenharmony_ci#define DEFAULT_I_TDPS 1024 /* some HCs can do less */ 1528c2ecf20Sopenharmony_ci unsigned periodic_size; 1538c2ecf20Sopenharmony_ci __hc32 *periodic; /* hw periodic table */ 1548c2ecf20Sopenharmony_ci dma_addr_t periodic_dma; 1558c2ecf20Sopenharmony_ci struct list_head intr_qh_list; 1568c2ecf20Sopenharmony_ci unsigned i_thresh; /* uframes HC might cache */ 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci union ehci_shadow *pshadow; /* mirror hw periodic table */ 1598c2ecf20Sopenharmony_ci struct list_head intr_unlink_wait; 1608c2ecf20Sopenharmony_ci struct list_head intr_unlink; 1618c2ecf20Sopenharmony_ci unsigned intr_unlink_wait_cycle; 1628c2ecf20Sopenharmony_ci unsigned intr_unlink_cycle; 1638c2ecf20Sopenharmony_ci unsigned now_frame; /* frame from HC hardware */ 1648c2ecf20Sopenharmony_ci unsigned last_iso_frame; /* last frame scanned for iso */ 1658c2ecf20Sopenharmony_ci unsigned intr_count; /* intr activity count */ 1668c2ecf20Sopenharmony_ci unsigned isoc_count; /* isoc activity count */ 1678c2ecf20Sopenharmony_ci unsigned periodic_count; /* periodic activity count */ 1688c2ecf20Sopenharmony_ci unsigned uframe_periodic_max; /* max periodic time per uframe */ 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci /* list of itds & sitds completed while now_frame was still active */ 1728c2ecf20Sopenharmony_ci struct list_head cached_itd_list; 1738c2ecf20Sopenharmony_ci struct ehci_itd *last_itd_to_free; 1748c2ecf20Sopenharmony_ci struct list_head cached_sitd_list; 1758c2ecf20Sopenharmony_ci struct ehci_sitd *last_sitd_to_free; 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci /* per root hub port */ 1788c2ecf20Sopenharmony_ci unsigned long reset_done[EHCI_MAX_ROOT_PORTS]; 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci /* bit vectors (one bit per port) */ 1818c2ecf20Sopenharmony_ci unsigned long bus_suspended; /* which ports were 1828c2ecf20Sopenharmony_ci already suspended at the start of a bus suspend */ 1838c2ecf20Sopenharmony_ci unsigned long companion_ports; /* which ports are 1848c2ecf20Sopenharmony_ci dedicated to the companion controller */ 1858c2ecf20Sopenharmony_ci unsigned long owned_ports; /* which ports are 1868c2ecf20Sopenharmony_ci owned by the companion during a bus suspend */ 1878c2ecf20Sopenharmony_ci unsigned long port_c_suspend; /* which ports have 1888c2ecf20Sopenharmony_ci the change-suspend feature turned on */ 1898c2ecf20Sopenharmony_ci unsigned long suspended_ports; /* which ports are 1908c2ecf20Sopenharmony_ci suspended */ 1918c2ecf20Sopenharmony_ci unsigned long resuming_ports; /* which ports have 1928c2ecf20Sopenharmony_ci started to resume */ 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci /* per-HC memory pools (could be per-bus, but ...) */ 1958c2ecf20Sopenharmony_ci struct dma_pool *qh_pool; /* qh per active urb */ 1968c2ecf20Sopenharmony_ci struct dma_pool *qtd_pool; /* one or more per qh */ 1978c2ecf20Sopenharmony_ci struct dma_pool *itd_pool; /* itd per iso urb */ 1988c2ecf20Sopenharmony_ci struct dma_pool *sitd_pool; /* sitd per split iso urb */ 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci unsigned random_frame; 2018c2ecf20Sopenharmony_ci unsigned long next_statechange; 2028c2ecf20Sopenharmony_ci ktime_t last_periodic_enable; 2038c2ecf20Sopenharmony_ci u32 command; 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci /* SILICON QUIRKS */ 2068c2ecf20Sopenharmony_ci unsigned no_selective_suspend:1; 2078c2ecf20Sopenharmony_ci unsigned has_fsl_port_bug:1; /* FreeScale */ 2088c2ecf20Sopenharmony_ci unsigned has_fsl_hs_errata:1; /* Freescale HS quirk */ 2098c2ecf20Sopenharmony_ci unsigned has_fsl_susp_errata:1; /* NXP SUSP quirk */ 2108c2ecf20Sopenharmony_ci unsigned big_endian_mmio:1; 2118c2ecf20Sopenharmony_ci unsigned big_endian_desc:1; 2128c2ecf20Sopenharmony_ci unsigned big_endian_capbase:1; 2138c2ecf20Sopenharmony_ci unsigned has_amcc_usb23:1; 2148c2ecf20Sopenharmony_ci unsigned need_io_watchdog:1; 2158c2ecf20Sopenharmony_ci unsigned amd_pll_fix:1; 2168c2ecf20Sopenharmony_ci unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/ 2178c2ecf20Sopenharmony_ci unsigned has_synopsys_hc_bug:1; /* Synopsys HC */ 2188c2ecf20Sopenharmony_ci unsigned frame_index_bug:1; /* MosChip (AKA NetMos) */ 2198c2ecf20Sopenharmony_ci unsigned need_oc_pp_cycle:1; /* MPC834X port power */ 2208c2ecf20Sopenharmony_ci unsigned imx28_write_fix:1; /* For Freescale i.MX28 */ 2218c2ecf20Sopenharmony_ci unsigned is_aspeed:1; 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci /* required for usb32 quirk */ 2248c2ecf20Sopenharmony_ci #define OHCI_CTRL_HCFS (3 << 6) 2258c2ecf20Sopenharmony_ci #define OHCI_USB_OPER (2 << 6) 2268c2ecf20Sopenharmony_ci #define OHCI_USB_SUSPEND (3 << 6) 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci #define OHCI_HCCTRL_OFFSET 0x4 2298c2ecf20Sopenharmony_ci #define OHCI_HCCTRL_LEN 0x4 2308c2ecf20Sopenharmony_ci __hc32 *ohci_hcctrl_reg; 2318c2ecf20Sopenharmony_ci unsigned has_hostpc:1; 2328c2ecf20Sopenharmony_ci unsigned has_tdi_phy_lpm:1; 2338c2ecf20Sopenharmony_ci unsigned has_ppcd:1; /* support per-port change bits */ 2348c2ecf20Sopenharmony_ci u8 sbrn; /* packed release number */ 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci /* irq statistics */ 2378c2ecf20Sopenharmony_ci#ifdef EHCI_STATS 2388c2ecf20Sopenharmony_ci struct ehci_stats stats; 2398c2ecf20Sopenharmony_ci# define INCR(x) ((x)++) 2408c2ecf20Sopenharmony_ci#else 2418c2ecf20Sopenharmony_ci# define INCR(x) do {} while (0) 2428c2ecf20Sopenharmony_ci#endif 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci /* debug files */ 2458c2ecf20Sopenharmony_ci#ifdef CONFIG_DYNAMIC_DEBUG 2468c2ecf20Sopenharmony_ci struct dentry *debug_dir; 2478c2ecf20Sopenharmony_ci#endif 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci /* bandwidth usage */ 2508c2ecf20Sopenharmony_ci#define EHCI_BANDWIDTH_SIZE 64 2518c2ecf20Sopenharmony_ci#define EHCI_BANDWIDTH_FRAMES (EHCI_BANDWIDTH_SIZE >> 3) 2528c2ecf20Sopenharmony_ci u8 bandwidth[EHCI_BANDWIDTH_SIZE]; 2538c2ecf20Sopenharmony_ci /* us allocated per uframe */ 2548c2ecf20Sopenharmony_ci u8 tt_budget[EHCI_BANDWIDTH_SIZE]; 2558c2ecf20Sopenharmony_ci /* us budgeted per uframe */ 2568c2ecf20Sopenharmony_ci struct list_head tt_list; 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci /* platform-specific data -- must come last */ 2598c2ecf20Sopenharmony_ci unsigned long priv[] __aligned(sizeof(s64)); 2608c2ecf20Sopenharmony_ci}; 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_ci/* convert between an HCD pointer and the corresponding EHCI_HCD */ 2638c2ecf20Sopenharmony_cistatic inline struct ehci_hcd *hcd_to_ehci(struct usb_hcd *hcd) 2648c2ecf20Sopenharmony_ci{ 2658c2ecf20Sopenharmony_ci return (struct ehci_hcd *) (hcd->hcd_priv); 2668c2ecf20Sopenharmony_ci} 2678c2ecf20Sopenharmony_cistatic inline struct usb_hcd *ehci_to_hcd(struct ehci_hcd *ehci) 2688c2ecf20Sopenharmony_ci{ 2698c2ecf20Sopenharmony_ci return container_of((void *) ehci, struct usb_hcd, hcd_priv); 2708c2ecf20Sopenharmony_ci} 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci/*-------------------------------------------------------------------------*/ 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci#include <linux/usb/ehci_def.h> 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci/*-------------------------------------------------------------------------*/ 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci#define QTD_NEXT(ehci, dma) cpu_to_hc32(ehci, (u32)dma) 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci/* 2818c2ecf20Sopenharmony_ci * EHCI Specification 0.95 Section 3.5 2828c2ecf20Sopenharmony_ci * QTD: describe data transfer components (buffer, direction, ...) 2838c2ecf20Sopenharmony_ci * See Fig 3-6 "Queue Element Transfer Descriptor Block Diagram". 2848c2ecf20Sopenharmony_ci * 2858c2ecf20Sopenharmony_ci * These are associated only with "QH" (Queue Head) structures, 2868c2ecf20Sopenharmony_ci * used with control, bulk, and interrupt transfers. 2878c2ecf20Sopenharmony_ci */ 2888c2ecf20Sopenharmony_cistruct ehci_qtd { 2898c2ecf20Sopenharmony_ci /* first part defined by EHCI spec */ 2908c2ecf20Sopenharmony_ci __hc32 hw_next; /* see EHCI 3.5.1 */ 2918c2ecf20Sopenharmony_ci __hc32 hw_alt_next; /* see EHCI 3.5.2 */ 2928c2ecf20Sopenharmony_ci __hc32 hw_token; /* see EHCI 3.5.3 */ 2938c2ecf20Sopenharmony_ci#define QTD_TOGGLE (1 << 31) /* data toggle */ 2948c2ecf20Sopenharmony_ci#define QTD_LENGTH(tok) (((tok)>>16) & 0x7fff) 2958c2ecf20Sopenharmony_ci#define QTD_IOC (1 << 15) /* interrupt on complete */ 2968c2ecf20Sopenharmony_ci#define QTD_CERR(tok) (((tok)>>10) & 0x3) 2978c2ecf20Sopenharmony_ci#define QTD_PID(tok) (((tok)>>8) & 0x3) 2988c2ecf20Sopenharmony_ci#define QTD_STS_ACTIVE (1 << 7) /* HC may execute this */ 2998c2ecf20Sopenharmony_ci#define QTD_STS_HALT (1 << 6) /* halted on error */ 3008c2ecf20Sopenharmony_ci#define QTD_STS_DBE (1 << 5) /* data buffer error (in HC) */ 3018c2ecf20Sopenharmony_ci#define QTD_STS_BABBLE (1 << 4) /* device was babbling (qtd halted) */ 3028c2ecf20Sopenharmony_ci#define QTD_STS_XACT (1 << 3) /* device gave illegal response */ 3038c2ecf20Sopenharmony_ci#define QTD_STS_MMF (1 << 2) /* incomplete split transaction */ 3048c2ecf20Sopenharmony_ci#define QTD_STS_STS (1 << 1) /* split transaction state */ 3058c2ecf20Sopenharmony_ci#define QTD_STS_PING (1 << 0) /* issue PING? */ 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_ci#define ACTIVE_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_ACTIVE) 3088c2ecf20Sopenharmony_ci#define HALT_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_HALT) 3098c2ecf20Sopenharmony_ci#define STATUS_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_STS) 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci __hc32 hw_buf[5]; /* see EHCI 3.5.4 */ 3128c2ecf20Sopenharmony_ci __hc32 hw_buf_hi[5]; /* Appendix B */ 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci /* the rest is HCD-private */ 3158c2ecf20Sopenharmony_ci dma_addr_t qtd_dma; /* qtd address */ 3168c2ecf20Sopenharmony_ci struct list_head qtd_list; /* sw qtd list */ 3178c2ecf20Sopenharmony_ci struct urb *urb; /* qtd's urb */ 3188c2ecf20Sopenharmony_ci size_t length; /* length of buffer */ 3198c2ecf20Sopenharmony_ci} __aligned(32); 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci/* mask NakCnt+T in qh->hw_alt_next */ 3228c2ecf20Sopenharmony_ci#define QTD_MASK(ehci) cpu_to_hc32(ehci, ~0x1f) 3238c2ecf20Sopenharmony_ci 3248c2ecf20Sopenharmony_ci#define IS_SHORT_READ(token) (QTD_LENGTH(token) != 0 && QTD_PID(token) == 1) 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci/*-------------------------------------------------------------------------*/ 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci/* type tag from {qh,itd,sitd,fstn}->hw_next */ 3298c2ecf20Sopenharmony_ci#define Q_NEXT_TYPE(ehci, dma) ((dma) & cpu_to_hc32(ehci, 3 << 1)) 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci/* 3328c2ecf20Sopenharmony_ci * Now the following defines are not converted using the 3338c2ecf20Sopenharmony_ci * cpu_to_le32() macro anymore, since we have to support 3348c2ecf20Sopenharmony_ci * "dynamic" switching between be and le support, so that the driver 3358c2ecf20Sopenharmony_ci * can be used on one system with SoC EHCI controller using big-endian 3368c2ecf20Sopenharmony_ci * descriptors as well as a normal little-endian PCI EHCI controller. 3378c2ecf20Sopenharmony_ci */ 3388c2ecf20Sopenharmony_ci/* values for that type tag */ 3398c2ecf20Sopenharmony_ci#define Q_TYPE_ITD (0 << 1) 3408c2ecf20Sopenharmony_ci#define Q_TYPE_QH (1 << 1) 3418c2ecf20Sopenharmony_ci#define Q_TYPE_SITD (2 << 1) 3428c2ecf20Sopenharmony_ci#define Q_TYPE_FSTN (3 << 1) 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_ci/* next async queue entry, or pointer to interrupt/periodic QH */ 3458c2ecf20Sopenharmony_ci#define QH_NEXT(ehci, dma) \ 3468c2ecf20Sopenharmony_ci (cpu_to_hc32(ehci, (((u32) dma) & ~0x01f) | Q_TYPE_QH)) 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci/* for periodic/async schedules and qtd lists, mark end of list */ 3498c2ecf20Sopenharmony_ci#define EHCI_LIST_END(ehci) cpu_to_hc32(ehci, 1) /* "null pointer" to hw */ 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci/* 3528c2ecf20Sopenharmony_ci * Entries in periodic shadow table are pointers to one of four kinds 3538c2ecf20Sopenharmony_ci * of data structure. That's dictated by the hardware; a type tag is 3548c2ecf20Sopenharmony_ci * encoded in the low bits of the hardware's periodic schedule. Use 3558c2ecf20Sopenharmony_ci * Q_NEXT_TYPE to get the tag. 3568c2ecf20Sopenharmony_ci * 3578c2ecf20Sopenharmony_ci * For entries in the async schedule, the type tag always says "qh". 3588c2ecf20Sopenharmony_ci */ 3598c2ecf20Sopenharmony_ciunion ehci_shadow { 3608c2ecf20Sopenharmony_ci struct ehci_qh *qh; /* Q_TYPE_QH */ 3618c2ecf20Sopenharmony_ci struct ehci_itd *itd; /* Q_TYPE_ITD */ 3628c2ecf20Sopenharmony_ci struct ehci_sitd *sitd; /* Q_TYPE_SITD */ 3638c2ecf20Sopenharmony_ci struct ehci_fstn *fstn; /* Q_TYPE_FSTN */ 3648c2ecf20Sopenharmony_ci __hc32 *hw_next; /* (all types) */ 3658c2ecf20Sopenharmony_ci void *ptr; 3668c2ecf20Sopenharmony_ci}; 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci/*-------------------------------------------------------------------------*/ 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci/* 3718c2ecf20Sopenharmony_ci * EHCI Specification 0.95 Section 3.6 3728c2ecf20Sopenharmony_ci * QH: describes control/bulk/interrupt endpoints 3738c2ecf20Sopenharmony_ci * See Fig 3-7 "Queue Head Structure Layout". 3748c2ecf20Sopenharmony_ci * 3758c2ecf20Sopenharmony_ci * These appear in both the async and (for interrupt) periodic schedules. 3768c2ecf20Sopenharmony_ci */ 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_ci/* first part defined by EHCI spec */ 3798c2ecf20Sopenharmony_cistruct ehci_qh_hw { 3808c2ecf20Sopenharmony_ci __hc32 hw_next; /* see EHCI 3.6.1 */ 3818c2ecf20Sopenharmony_ci __hc32 hw_info1; /* see EHCI 3.6.2 */ 3828c2ecf20Sopenharmony_ci#define QH_CONTROL_EP (1 << 27) /* FS/LS control endpoint */ 3838c2ecf20Sopenharmony_ci#define QH_HEAD (1 << 15) /* Head of async reclamation list */ 3848c2ecf20Sopenharmony_ci#define QH_TOGGLE_CTL (1 << 14) /* Data toggle control */ 3858c2ecf20Sopenharmony_ci#define QH_HIGH_SPEED (2 << 12) /* Endpoint speed */ 3868c2ecf20Sopenharmony_ci#define QH_LOW_SPEED (1 << 12) 3878c2ecf20Sopenharmony_ci#define QH_FULL_SPEED (0 << 12) 3888c2ecf20Sopenharmony_ci#define QH_INACTIVATE (1 << 7) /* Inactivate on next transaction */ 3898c2ecf20Sopenharmony_ci __hc32 hw_info2; /* see EHCI 3.6.2 */ 3908c2ecf20Sopenharmony_ci#define QH_SMASK 0x000000ff 3918c2ecf20Sopenharmony_ci#define QH_CMASK 0x0000ff00 3928c2ecf20Sopenharmony_ci#define QH_HUBADDR 0x007f0000 3938c2ecf20Sopenharmony_ci#define QH_HUBPORT 0x3f800000 3948c2ecf20Sopenharmony_ci#define QH_MULT 0xc0000000 3958c2ecf20Sopenharmony_ci __hc32 hw_current; /* qtd list - see EHCI 3.6.4 */ 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_ci /* qtd overlay (hardware parts of a struct ehci_qtd) */ 3988c2ecf20Sopenharmony_ci __hc32 hw_qtd_next; 3998c2ecf20Sopenharmony_ci __hc32 hw_alt_next; 4008c2ecf20Sopenharmony_ci __hc32 hw_token; 4018c2ecf20Sopenharmony_ci __hc32 hw_buf[5]; 4028c2ecf20Sopenharmony_ci __hc32 hw_buf_hi[5]; 4038c2ecf20Sopenharmony_ci} __aligned(32); 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_cistruct ehci_qh { 4068c2ecf20Sopenharmony_ci struct ehci_qh_hw *hw; /* Must come first */ 4078c2ecf20Sopenharmony_ci /* the rest is HCD-private */ 4088c2ecf20Sopenharmony_ci dma_addr_t qh_dma; /* address of qh */ 4098c2ecf20Sopenharmony_ci union ehci_shadow qh_next; /* ptr to qh; or periodic */ 4108c2ecf20Sopenharmony_ci struct list_head qtd_list; /* sw qtd list */ 4118c2ecf20Sopenharmony_ci struct list_head intr_node; /* list of intr QHs */ 4128c2ecf20Sopenharmony_ci struct ehci_qtd *dummy; 4138c2ecf20Sopenharmony_ci struct list_head unlink_node; 4148c2ecf20Sopenharmony_ci struct ehci_per_sched ps; /* scheduling info */ 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci unsigned unlink_cycle; 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_ci u8 qh_state; 4198c2ecf20Sopenharmony_ci#define QH_STATE_LINKED 1 /* HC sees this */ 4208c2ecf20Sopenharmony_ci#define QH_STATE_UNLINK 2 /* HC may still see this */ 4218c2ecf20Sopenharmony_ci#define QH_STATE_IDLE 3 /* HC doesn't see this */ 4228c2ecf20Sopenharmony_ci#define QH_STATE_UNLINK_WAIT 4 /* LINKED and on unlink q */ 4238c2ecf20Sopenharmony_ci#define QH_STATE_COMPLETING 5 /* don't touch token.HALT */ 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ci u8 xacterrs; /* XactErr retry counter */ 4268c2ecf20Sopenharmony_ci#define QH_XACTERR_MAX 32 /* XactErr retry limit */ 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci u8 unlink_reason; 4298c2ecf20Sopenharmony_ci#define QH_UNLINK_HALTED 0x01 /* Halt flag is set */ 4308c2ecf20Sopenharmony_ci#define QH_UNLINK_SHORT_READ 0x02 /* Recover from a short read */ 4318c2ecf20Sopenharmony_ci#define QH_UNLINK_DUMMY_OVERLAY 0x04 /* QH overlayed the dummy TD */ 4328c2ecf20Sopenharmony_ci#define QH_UNLINK_SHUTDOWN 0x08 /* The HC isn't running */ 4338c2ecf20Sopenharmony_ci#define QH_UNLINK_QUEUE_EMPTY 0x10 /* Reached end of the queue */ 4348c2ecf20Sopenharmony_ci#define QH_UNLINK_REQUESTED 0x20 /* Disable, reset, or dequeue */ 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci u8 gap_uf; /* uframes split/csplit gap */ 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci unsigned is_out:1; /* bulk or intr OUT */ 4398c2ecf20Sopenharmony_ci unsigned clearing_tt:1; /* Clear-TT-Buf in progress */ 4408c2ecf20Sopenharmony_ci unsigned dequeue_during_giveback:1; 4418c2ecf20Sopenharmony_ci unsigned should_be_inactive:1; 4428c2ecf20Sopenharmony_ci}; 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ci/*-------------------------------------------------------------------------*/ 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci/* description of one iso transaction (up to 3 KB data if highspeed) */ 4478c2ecf20Sopenharmony_cistruct ehci_iso_packet { 4488c2ecf20Sopenharmony_ci /* These will be copied to iTD when scheduling */ 4498c2ecf20Sopenharmony_ci u64 bufp; /* itd->hw_bufp{,_hi}[pg] |= */ 4508c2ecf20Sopenharmony_ci __hc32 transaction; /* itd->hw_transaction[i] |= */ 4518c2ecf20Sopenharmony_ci u8 cross; /* buf crosses pages */ 4528c2ecf20Sopenharmony_ci /* for full speed OUT splits */ 4538c2ecf20Sopenharmony_ci u32 buf1; 4548c2ecf20Sopenharmony_ci}; 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci/* temporary schedule data for packets from iso urbs (both speeds) 4578c2ecf20Sopenharmony_ci * each packet is one logical usb transaction to the device (not TT), 4588c2ecf20Sopenharmony_ci * beginning at stream->next_uframe 4598c2ecf20Sopenharmony_ci */ 4608c2ecf20Sopenharmony_cistruct ehci_iso_sched { 4618c2ecf20Sopenharmony_ci struct list_head td_list; 4628c2ecf20Sopenharmony_ci unsigned span; 4638c2ecf20Sopenharmony_ci unsigned first_packet; 4648c2ecf20Sopenharmony_ci struct ehci_iso_packet packet[]; 4658c2ecf20Sopenharmony_ci}; 4668c2ecf20Sopenharmony_ci 4678c2ecf20Sopenharmony_ci/* 4688c2ecf20Sopenharmony_ci * ehci_iso_stream - groups all (s)itds for this endpoint. 4698c2ecf20Sopenharmony_ci * acts like a qh would, if EHCI had them for ISO. 4708c2ecf20Sopenharmony_ci */ 4718c2ecf20Sopenharmony_cistruct ehci_iso_stream { 4728c2ecf20Sopenharmony_ci /* first field matches ehci_hq, but is NULL */ 4738c2ecf20Sopenharmony_ci struct ehci_qh_hw *hw; 4748c2ecf20Sopenharmony_ci 4758c2ecf20Sopenharmony_ci u8 bEndpointAddress; 4768c2ecf20Sopenharmony_ci u8 highspeed; 4778c2ecf20Sopenharmony_ci struct list_head td_list; /* queued itds/sitds */ 4788c2ecf20Sopenharmony_ci struct list_head free_list; /* list of unused itds/sitds */ 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ci /* output of (re)scheduling */ 4818c2ecf20Sopenharmony_ci struct ehci_per_sched ps; /* scheduling info */ 4828c2ecf20Sopenharmony_ci unsigned next_uframe; 4838c2ecf20Sopenharmony_ci __hc32 splits; 4848c2ecf20Sopenharmony_ci 4858c2ecf20Sopenharmony_ci /* the rest is derived from the endpoint descriptor, 4868c2ecf20Sopenharmony_ci * including the extra info for hw_bufp[0..2] 4878c2ecf20Sopenharmony_ci */ 4888c2ecf20Sopenharmony_ci u16 uperiod; /* period in uframes */ 4898c2ecf20Sopenharmony_ci u16 maxp; 4908c2ecf20Sopenharmony_ci unsigned bandwidth; 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_ci /* This is used to initialize iTD's hw_bufp fields */ 4938c2ecf20Sopenharmony_ci __hc32 buf0; 4948c2ecf20Sopenharmony_ci __hc32 buf1; 4958c2ecf20Sopenharmony_ci __hc32 buf2; 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci /* this is used to initialize sITD's tt info */ 4988c2ecf20Sopenharmony_ci __hc32 address; 4998c2ecf20Sopenharmony_ci}; 5008c2ecf20Sopenharmony_ci 5018c2ecf20Sopenharmony_ci/*-------------------------------------------------------------------------*/ 5028c2ecf20Sopenharmony_ci 5038c2ecf20Sopenharmony_ci/* 5048c2ecf20Sopenharmony_ci * EHCI Specification 0.95 Section 3.3 5058c2ecf20Sopenharmony_ci * Fig 3-4 "Isochronous Transaction Descriptor (iTD)" 5068c2ecf20Sopenharmony_ci * 5078c2ecf20Sopenharmony_ci * Schedule records for high speed iso xfers 5088c2ecf20Sopenharmony_ci */ 5098c2ecf20Sopenharmony_cistruct ehci_itd { 5108c2ecf20Sopenharmony_ci /* first part defined by EHCI spec */ 5118c2ecf20Sopenharmony_ci __hc32 hw_next; /* see EHCI 3.3.1 */ 5128c2ecf20Sopenharmony_ci __hc32 hw_transaction[8]; /* see EHCI 3.3.2 */ 5138c2ecf20Sopenharmony_ci#define EHCI_ISOC_ACTIVE (1<<31) /* activate transfer this slot */ 5148c2ecf20Sopenharmony_ci#define EHCI_ISOC_BUF_ERR (1<<30) /* Data buffer error */ 5158c2ecf20Sopenharmony_ci#define EHCI_ISOC_BABBLE (1<<29) /* babble detected */ 5168c2ecf20Sopenharmony_ci#define EHCI_ISOC_XACTERR (1<<28) /* XactErr - transaction error */ 5178c2ecf20Sopenharmony_ci#define EHCI_ITD_LENGTH(tok) (((tok)>>16) & 0x0fff) 5188c2ecf20Sopenharmony_ci#define EHCI_ITD_IOC (1 << 15) /* interrupt on complete */ 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_ci#define ITD_ACTIVE(ehci) cpu_to_hc32(ehci, EHCI_ISOC_ACTIVE) 5218c2ecf20Sopenharmony_ci 5228c2ecf20Sopenharmony_ci __hc32 hw_bufp[7]; /* see EHCI 3.3.3 */ 5238c2ecf20Sopenharmony_ci __hc32 hw_bufp_hi[7]; /* Appendix B */ 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_ci /* the rest is HCD-private */ 5268c2ecf20Sopenharmony_ci dma_addr_t itd_dma; /* for this itd */ 5278c2ecf20Sopenharmony_ci union ehci_shadow itd_next; /* ptr to periodic q entry */ 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_ci struct urb *urb; 5308c2ecf20Sopenharmony_ci struct ehci_iso_stream *stream; /* endpoint's queue */ 5318c2ecf20Sopenharmony_ci struct list_head itd_list; /* list of stream's itds */ 5328c2ecf20Sopenharmony_ci 5338c2ecf20Sopenharmony_ci /* any/all hw_transactions here may be used by that urb */ 5348c2ecf20Sopenharmony_ci unsigned frame; /* where scheduled */ 5358c2ecf20Sopenharmony_ci unsigned pg; 5368c2ecf20Sopenharmony_ci unsigned index[8]; /* in urb->iso_frame_desc */ 5378c2ecf20Sopenharmony_ci} __aligned(32); 5388c2ecf20Sopenharmony_ci 5398c2ecf20Sopenharmony_ci/*-------------------------------------------------------------------------*/ 5408c2ecf20Sopenharmony_ci 5418c2ecf20Sopenharmony_ci/* 5428c2ecf20Sopenharmony_ci * EHCI Specification 0.95 Section 3.4 5438c2ecf20Sopenharmony_ci * siTD, aka split-transaction isochronous Transfer Descriptor 5448c2ecf20Sopenharmony_ci * ... describe full speed iso xfers through TT in hubs 5458c2ecf20Sopenharmony_ci * see Figure 3-5 "Split-transaction Isochronous Transaction Descriptor (siTD) 5468c2ecf20Sopenharmony_ci */ 5478c2ecf20Sopenharmony_cistruct ehci_sitd { 5488c2ecf20Sopenharmony_ci /* first part defined by EHCI spec */ 5498c2ecf20Sopenharmony_ci __hc32 hw_next; 5508c2ecf20Sopenharmony_ci/* uses bit field macros above - see EHCI 0.95 Table 3-8 */ 5518c2ecf20Sopenharmony_ci __hc32 hw_fullspeed_ep; /* EHCI table 3-9 */ 5528c2ecf20Sopenharmony_ci __hc32 hw_uframe; /* EHCI table 3-10 */ 5538c2ecf20Sopenharmony_ci __hc32 hw_results; /* EHCI table 3-11 */ 5548c2ecf20Sopenharmony_ci#define SITD_IOC (1 << 31) /* interrupt on completion */ 5558c2ecf20Sopenharmony_ci#define SITD_PAGE (1 << 30) /* buffer 0/1 */ 5568c2ecf20Sopenharmony_ci#define SITD_LENGTH(x) (((x) >> 16) & 0x3ff) 5578c2ecf20Sopenharmony_ci#define SITD_STS_ACTIVE (1 << 7) /* HC may execute this */ 5588c2ecf20Sopenharmony_ci#define SITD_STS_ERR (1 << 6) /* error from TT */ 5598c2ecf20Sopenharmony_ci#define SITD_STS_DBE (1 << 5) /* data buffer error (in HC) */ 5608c2ecf20Sopenharmony_ci#define SITD_STS_BABBLE (1 << 4) /* device was babbling */ 5618c2ecf20Sopenharmony_ci#define SITD_STS_XACT (1 << 3) /* illegal IN response */ 5628c2ecf20Sopenharmony_ci#define SITD_STS_MMF (1 << 2) /* incomplete split transaction */ 5638c2ecf20Sopenharmony_ci#define SITD_STS_STS (1 << 1) /* split transaction state */ 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ci#define SITD_ACTIVE(ehci) cpu_to_hc32(ehci, SITD_STS_ACTIVE) 5668c2ecf20Sopenharmony_ci 5678c2ecf20Sopenharmony_ci __hc32 hw_buf[2]; /* EHCI table 3-12 */ 5688c2ecf20Sopenharmony_ci __hc32 hw_backpointer; /* EHCI table 3-13 */ 5698c2ecf20Sopenharmony_ci __hc32 hw_buf_hi[2]; /* Appendix B */ 5708c2ecf20Sopenharmony_ci 5718c2ecf20Sopenharmony_ci /* the rest is HCD-private */ 5728c2ecf20Sopenharmony_ci dma_addr_t sitd_dma; 5738c2ecf20Sopenharmony_ci union ehci_shadow sitd_next; /* ptr to periodic q entry */ 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_ci struct urb *urb; 5768c2ecf20Sopenharmony_ci struct ehci_iso_stream *stream; /* endpoint's queue */ 5778c2ecf20Sopenharmony_ci struct list_head sitd_list; /* list of stream's sitds */ 5788c2ecf20Sopenharmony_ci unsigned frame; 5798c2ecf20Sopenharmony_ci unsigned index; 5808c2ecf20Sopenharmony_ci} __aligned(32); 5818c2ecf20Sopenharmony_ci 5828c2ecf20Sopenharmony_ci/*-------------------------------------------------------------------------*/ 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci/* 5858c2ecf20Sopenharmony_ci * EHCI Specification 0.96 Section 3.7 5868c2ecf20Sopenharmony_ci * Periodic Frame Span Traversal Node (FSTN) 5878c2ecf20Sopenharmony_ci * 5888c2ecf20Sopenharmony_ci * Manages split interrupt transactions (using TT) that span frame boundaries 5898c2ecf20Sopenharmony_ci * into uframes 0/1; see 4.12.2.2. In those uframes, a "save place" FSTN 5908c2ecf20Sopenharmony_ci * makes the HC jump (back) to a QH to scan for fs/ls QH completions until 5918c2ecf20Sopenharmony_ci * it hits a "restore" FSTN; then it returns to finish other uframe 0/1 work. 5928c2ecf20Sopenharmony_ci */ 5938c2ecf20Sopenharmony_cistruct ehci_fstn { 5948c2ecf20Sopenharmony_ci __hc32 hw_next; /* any periodic q entry */ 5958c2ecf20Sopenharmony_ci __hc32 hw_prev; /* qh or EHCI_LIST_END */ 5968c2ecf20Sopenharmony_ci 5978c2ecf20Sopenharmony_ci /* the rest is HCD-private */ 5988c2ecf20Sopenharmony_ci dma_addr_t fstn_dma; 5998c2ecf20Sopenharmony_ci union ehci_shadow fstn_next; /* ptr to periodic q entry */ 6008c2ecf20Sopenharmony_ci} __aligned(32); 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_ci/*-------------------------------------------------------------------------*/ 6038c2ecf20Sopenharmony_ci 6048c2ecf20Sopenharmony_ci/* 6058c2ecf20Sopenharmony_ci * USB-2.0 Specification Sections 11.14 and 11.18 6068c2ecf20Sopenharmony_ci * Scheduling and budgeting split transactions using TTs 6078c2ecf20Sopenharmony_ci * 6088c2ecf20Sopenharmony_ci * A hub can have a single TT for all its ports, or multiple TTs (one for each 6098c2ecf20Sopenharmony_ci * port). The bandwidth and budgeting information for the full/low-speed bus 6108c2ecf20Sopenharmony_ci * below each TT is self-contained and independent of the other TTs or the 6118c2ecf20Sopenharmony_ci * high-speed bus. 6128c2ecf20Sopenharmony_ci * 6138c2ecf20Sopenharmony_ci * "Bandwidth" refers to the number of microseconds on the FS/LS bus allocated 6148c2ecf20Sopenharmony_ci * to an interrupt or isochronous endpoint for each frame. "Budget" refers to 6158c2ecf20Sopenharmony_ci * the best-case estimate of the number of full-speed bytes allocated to an 6168c2ecf20Sopenharmony_ci * endpoint for each microframe within an allocated frame. 6178c2ecf20Sopenharmony_ci * 6188c2ecf20Sopenharmony_ci * Removal of an endpoint invalidates a TT's budget. Instead of trying to 6198c2ecf20Sopenharmony_ci * keep an up-to-date record, we recompute the budget when it is needed. 6208c2ecf20Sopenharmony_ci */ 6218c2ecf20Sopenharmony_ci 6228c2ecf20Sopenharmony_cistruct ehci_tt { 6238c2ecf20Sopenharmony_ci u16 bandwidth[EHCI_BANDWIDTH_FRAMES]; 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_ci struct list_head tt_list; /* List of all ehci_tt's */ 6268c2ecf20Sopenharmony_ci struct list_head ps_list; /* Items using this TT */ 6278c2ecf20Sopenharmony_ci struct usb_tt *usb_tt; 6288c2ecf20Sopenharmony_ci int tt_port; /* TT port number */ 6298c2ecf20Sopenharmony_ci}; 6308c2ecf20Sopenharmony_ci 6318c2ecf20Sopenharmony_ci/*-------------------------------------------------------------------------*/ 6328c2ecf20Sopenharmony_ci 6338c2ecf20Sopenharmony_ci/* Prepare the PORTSC wakeup flags during controller suspend/resume */ 6348c2ecf20Sopenharmony_ci 6358c2ecf20Sopenharmony_ci#define ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup) \ 6368c2ecf20Sopenharmony_ci ehci_adjust_port_wakeup_flags(ehci, true, do_wakeup) 6378c2ecf20Sopenharmony_ci 6388c2ecf20Sopenharmony_ci#define ehci_prepare_ports_for_controller_resume(ehci) \ 6398c2ecf20Sopenharmony_ci ehci_adjust_port_wakeup_flags(ehci, false, false) 6408c2ecf20Sopenharmony_ci 6418c2ecf20Sopenharmony_ci/*-------------------------------------------------------------------------*/ 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ci#ifdef CONFIG_USB_EHCI_ROOT_HUB_TT 6448c2ecf20Sopenharmony_ci 6458c2ecf20Sopenharmony_ci/* 6468c2ecf20Sopenharmony_ci * Some EHCI controllers have a Transaction Translator built into the 6478c2ecf20Sopenharmony_ci * root hub. This is a non-standard feature. Each controller will need 6488c2ecf20Sopenharmony_ci * to add code to the following inline functions, and call them as 6498c2ecf20Sopenharmony_ci * needed (mostly in root hub code). 6508c2ecf20Sopenharmony_ci */ 6518c2ecf20Sopenharmony_ci 6528c2ecf20Sopenharmony_ci#define ehci_is_TDI(e) (ehci_to_hcd(e)->has_tt) 6538c2ecf20Sopenharmony_ci 6548c2ecf20Sopenharmony_ci/* Returns the speed of a device attached to a port on the root hub. */ 6558c2ecf20Sopenharmony_cistatic inline unsigned int 6568c2ecf20Sopenharmony_ciehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc) 6578c2ecf20Sopenharmony_ci{ 6588c2ecf20Sopenharmony_ci if (ehci_is_TDI(ehci)) { 6598c2ecf20Sopenharmony_ci switch ((portsc >> (ehci->has_hostpc ? 25 : 26)) & 3) { 6608c2ecf20Sopenharmony_ci case 0: 6618c2ecf20Sopenharmony_ci return 0; 6628c2ecf20Sopenharmony_ci case 1: 6638c2ecf20Sopenharmony_ci return USB_PORT_STAT_LOW_SPEED; 6648c2ecf20Sopenharmony_ci case 2: 6658c2ecf20Sopenharmony_ci default: 6668c2ecf20Sopenharmony_ci return USB_PORT_STAT_HIGH_SPEED; 6678c2ecf20Sopenharmony_ci } 6688c2ecf20Sopenharmony_ci } 6698c2ecf20Sopenharmony_ci return USB_PORT_STAT_HIGH_SPEED; 6708c2ecf20Sopenharmony_ci} 6718c2ecf20Sopenharmony_ci 6728c2ecf20Sopenharmony_ci#else 6738c2ecf20Sopenharmony_ci 6748c2ecf20Sopenharmony_ci#define ehci_is_TDI(e) (0) 6758c2ecf20Sopenharmony_ci 6768c2ecf20Sopenharmony_ci#define ehci_port_speed(ehci, portsc) USB_PORT_STAT_HIGH_SPEED 6778c2ecf20Sopenharmony_ci#endif 6788c2ecf20Sopenharmony_ci 6798c2ecf20Sopenharmony_ci/*-------------------------------------------------------------------------*/ 6808c2ecf20Sopenharmony_ci 6818c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_83xx 6828c2ecf20Sopenharmony_ci/* Some Freescale processors have an erratum in which the TT 6838c2ecf20Sopenharmony_ci * port number in the queue head was 0..N-1 instead of 1..N. 6848c2ecf20Sopenharmony_ci */ 6858c2ecf20Sopenharmony_ci#define ehci_has_fsl_portno_bug(e) ((e)->has_fsl_port_bug) 6868c2ecf20Sopenharmony_ci#else 6878c2ecf20Sopenharmony_ci#define ehci_has_fsl_portno_bug(e) (0) 6888c2ecf20Sopenharmony_ci#endif 6898c2ecf20Sopenharmony_ci 6908c2ecf20Sopenharmony_ci#define PORTSC_FSL_PFSC 24 /* Port Force Full-Speed Connect */ 6918c2ecf20Sopenharmony_ci 6928c2ecf20Sopenharmony_ci#if defined(CONFIG_PPC_85xx) 6938c2ecf20Sopenharmony_ci/* Some Freescale processors have an erratum (USB A-005275) in which 6948c2ecf20Sopenharmony_ci * incoming packets get corrupted in HS mode 6958c2ecf20Sopenharmony_ci */ 6968c2ecf20Sopenharmony_ci#define ehci_has_fsl_hs_errata(e) ((e)->has_fsl_hs_errata) 6978c2ecf20Sopenharmony_ci#else 6988c2ecf20Sopenharmony_ci#define ehci_has_fsl_hs_errata(e) (0) 6998c2ecf20Sopenharmony_ci#endif 7008c2ecf20Sopenharmony_ci 7018c2ecf20Sopenharmony_ci/* 7028c2ecf20Sopenharmony_ci * Some Freescale/NXP processors have an erratum (USB A-005697) 7038c2ecf20Sopenharmony_ci * in which we need to wait for 10ms for bus to enter suspend mode 7048c2ecf20Sopenharmony_ci * after setting SUSP bit. 7058c2ecf20Sopenharmony_ci */ 7068c2ecf20Sopenharmony_ci#define ehci_has_fsl_susp_errata(e) ((e)->has_fsl_susp_errata) 7078c2ecf20Sopenharmony_ci 7088c2ecf20Sopenharmony_ci/* 7098c2ecf20Sopenharmony_ci * While most USB host controllers implement their registers in 7108c2ecf20Sopenharmony_ci * little-endian format, a minority (celleb companion chip) implement 7118c2ecf20Sopenharmony_ci * them in big endian format. 7128c2ecf20Sopenharmony_ci * 7138c2ecf20Sopenharmony_ci * This attempts to support either format at compile time without a 7148c2ecf20Sopenharmony_ci * runtime penalty, or both formats with the additional overhead 7158c2ecf20Sopenharmony_ci * of checking a flag bit. 7168c2ecf20Sopenharmony_ci * 7178c2ecf20Sopenharmony_ci * ehci_big_endian_capbase is a special quirk for controllers that 7188c2ecf20Sopenharmony_ci * implement the HC capability registers as separate registers and not 7198c2ecf20Sopenharmony_ci * as fields of a 32-bit register. 7208c2ecf20Sopenharmony_ci */ 7218c2ecf20Sopenharmony_ci 7228c2ecf20Sopenharmony_ci#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO 7238c2ecf20Sopenharmony_ci#define ehci_big_endian_mmio(e) ((e)->big_endian_mmio) 7248c2ecf20Sopenharmony_ci#define ehci_big_endian_capbase(e) ((e)->big_endian_capbase) 7258c2ecf20Sopenharmony_ci#else 7268c2ecf20Sopenharmony_ci#define ehci_big_endian_mmio(e) 0 7278c2ecf20Sopenharmony_ci#define ehci_big_endian_capbase(e) 0 7288c2ecf20Sopenharmony_ci#endif 7298c2ecf20Sopenharmony_ci 7308c2ecf20Sopenharmony_ci/* 7318c2ecf20Sopenharmony_ci * Big-endian read/write functions are arch-specific. 7328c2ecf20Sopenharmony_ci * Other arches can be added if/when they're needed. 7338c2ecf20Sopenharmony_ci */ 7348c2ecf20Sopenharmony_ci#if defined(CONFIG_ARM) && defined(CONFIG_ARCH_IXP4XX) 7358c2ecf20Sopenharmony_ci#define readl_be(addr) __raw_readl((__force unsigned *)addr) 7368c2ecf20Sopenharmony_ci#define writel_be(val, addr) __raw_writel(val, (__force unsigned *)addr) 7378c2ecf20Sopenharmony_ci#endif 7388c2ecf20Sopenharmony_ci 7398c2ecf20Sopenharmony_cistatic inline unsigned int ehci_readl(const struct ehci_hcd *ehci, 7408c2ecf20Sopenharmony_ci __u32 __iomem *regs) 7418c2ecf20Sopenharmony_ci{ 7428c2ecf20Sopenharmony_ci#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO 7438c2ecf20Sopenharmony_ci return ehci_big_endian_mmio(ehci) ? 7448c2ecf20Sopenharmony_ci readl_be(regs) : 7458c2ecf20Sopenharmony_ci readl(regs); 7468c2ecf20Sopenharmony_ci#else 7478c2ecf20Sopenharmony_ci return readl(regs); 7488c2ecf20Sopenharmony_ci#endif 7498c2ecf20Sopenharmony_ci} 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_ci#ifdef CONFIG_SOC_IMX28 7528c2ecf20Sopenharmony_cistatic inline void imx28_ehci_writel(const unsigned int val, 7538c2ecf20Sopenharmony_ci volatile __u32 __iomem *addr) 7548c2ecf20Sopenharmony_ci{ 7558c2ecf20Sopenharmony_ci __asm__ ("swp %0, %0, [%1]" : : "r"(val), "r"(addr)); 7568c2ecf20Sopenharmony_ci} 7578c2ecf20Sopenharmony_ci#else 7588c2ecf20Sopenharmony_cistatic inline void imx28_ehci_writel(const unsigned int val, 7598c2ecf20Sopenharmony_ci volatile __u32 __iomem *addr) 7608c2ecf20Sopenharmony_ci{ 7618c2ecf20Sopenharmony_ci} 7628c2ecf20Sopenharmony_ci#endif 7638c2ecf20Sopenharmony_cistatic inline void ehci_writel(const struct ehci_hcd *ehci, 7648c2ecf20Sopenharmony_ci const unsigned int val, __u32 __iomem *regs) 7658c2ecf20Sopenharmony_ci{ 7668c2ecf20Sopenharmony_ci#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO 7678c2ecf20Sopenharmony_ci ehci_big_endian_mmio(ehci) ? 7688c2ecf20Sopenharmony_ci writel_be(val, regs) : 7698c2ecf20Sopenharmony_ci writel(val, regs); 7708c2ecf20Sopenharmony_ci#else 7718c2ecf20Sopenharmony_ci if (ehci->imx28_write_fix) 7728c2ecf20Sopenharmony_ci imx28_ehci_writel(val, regs); 7738c2ecf20Sopenharmony_ci else 7748c2ecf20Sopenharmony_ci writel(val, regs); 7758c2ecf20Sopenharmony_ci#endif 7768c2ecf20Sopenharmony_ci} 7778c2ecf20Sopenharmony_ci 7788c2ecf20Sopenharmony_ci/* 7798c2ecf20Sopenharmony_ci * On certain ppc-44x SoC there is a HW issue, that could only worked around with 7808c2ecf20Sopenharmony_ci * explicit suspend/operate of OHCI. This function hereby makes sense only on that arch. 7818c2ecf20Sopenharmony_ci * Other common bits are dependent on has_amcc_usb23 quirk flag. 7828c2ecf20Sopenharmony_ci */ 7838c2ecf20Sopenharmony_ci#ifdef CONFIG_44x 7848c2ecf20Sopenharmony_cistatic inline void set_ohci_hcfs(struct ehci_hcd *ehci, int operational) 7858c2ecf20Sopenharmony_ci{ 7868c2ecf20Sopenharmony_ci u32 hc_control; 7878c2ecf20Sopenharmony_ci 7888c2ecf20Sopenharmony_ci hc_control = (readl_be(ehci->ohci_hcctrl_reg) & ~OHCI_CTRL_HCFS); 7898c2ecf20Sopenharmony_ci if (operational) 7908c2ecf20Sopenharmony_ci hc_control |= OHCI_USB_OPER; 7918c2ecf20Sopenharmony_ci else 7928c2ecf20Sopenharmony_ci hc_control |= OHCI_USB_SUSPEND; 7938c2ecf20Sopenharmony_ci 7948c2ecf20Sopenharmony_ci writel_be(hc_control, ehci->ohci_hcctrl_reg); 7958c2ecf20Sopenharmony_ci (void) readl_be(ehci->ohci_hcctrl_reg); 7968c2ecf20Sopenharmony_ci} 7978c2ecf20Sopenharmony_ci#else 7988c2ecf20Sopenharmony_cistatic inline void set_ohci_hcfs(struct ehci_hcd *ehci, int operational) 7998c2ecf20Sopenharmony_ci{ } 8008c2ecf20Sopenharmony_ci#endif 8018c2ecf20Sopenharmony_ci 8028c2ecf20Sopenharmony_ci/*-------------------------------------------------------------------------*/ 8038c2ecf20Sopenharmony_ci 8048c2ecf20Sopenharmony_ci/* 8058c2ecf20Sopenharmony_ci * The AMCC 440EPx not only implements its EHCI registers in big-endian 8068c2ecf20Sopenharmony_ci * format, but also its DMA data structures (descriptors). 8078c2ecf20Sopenharmony_ci * 8088c2ecf20Sopenharmony_ci * EHCI controllers accessed through PCI work normally (little-endian 8098c2ecf20Sopenharmony_ci * everywhere), so we won't bother supporting a BE-only mode for now. 8108c2ecf20Sopenharmony_ci */ 8118c2ecf20Sopenharmony_ci#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_DESC 8128c2ecf20Sopenharmony_ci#define ehci_big_endian_desc(e) ((e)->big_endian_desc) 8138c2ecf20Sopenharmony_ci 8148c2ecf20Sopenharmony_ci/* cpu to ehci */ 8158c2ecf20Sopenharmony_cistatic inline __hc32 cpu_to_hc32(const struct ehci_hcd *ehci, const u32 x) 8168c2ecf20Sopenharmony_ci{ 8178c2ecf20Sopenharmony_ci return ehci_big_endian_desc(ehci) 8188c2ecf20Sopenharmony_ci ? (__force __hc32)cpu_to_be32(x) 8198c2ecf20Sopenharmony_ci : (__force __hc32)cpu_to_le32(x); 8208c2ecf20Sopenharmony_ci} 8218c2ecf20Sopenharmony_ci 8228c2ecf20Sopenharmony_ci/* ehci to cpu */ 8238c2ecf20Sopenharmony_cistatic inline u32 hc32_to_cpu(const struct ehci_hcd *ehci, const __hc32 x) 8248c2ecf20Sopenharmony_ci{ 8258c2ecf20Sopenharmony_ci return ehci_big_endian_desc(ehci) 8268c2ecf20Sopenharmony_ci ? be32_to_cpu((__force __be32)x) 8278c2ecf20Sopenharmony_ci : le32_to_cpu((__force __le32)x); 8288c2ecf20Sopenharmony_ci} 8298c2ecf20Sopenharmony_ci 8308c2ecf20Sopenharmony_cistatic inline u32 hc32_to_cpup(const struct ehci_hcd *ehci, const __hc32 *x) 8318c2ecf20Sopenharmony_ci{ 8328c2ecf20Sopenharmony_ci return ehci_big_endian_desc(ehci) 8338c2ecf20Sopenharmony_ci ? be32_to_cpup((__force __be32 *)x) 8348c2ecf20Sopenharmony_ci : le32_to_cpup((__force __le32 *)x); 8358c2ecf20Sopenharmony_ci} 8368c2ecf20Sopenharmony_ci 8378c2ecf20Sopenharmony_ci#else 8388c2ecf20Sopenharmony_ci 8398c2ecf20Sopenharmony_ci/* cpu to ehci */ 8408c2ecf20Sopenharmony_cistatic inline __hc32 cpu_to_hc32(const struct ehci_hcd *ehci, const u32 x) 8418c2ecf20Sopenharmony_ci{ 8428c2ecf20Sopenharmony_ci return cpu_to_le32(x); 8438c2ecf20Sopenharmony_ci} 8448c2ecf20Sopenharmony_ci 8458c2ecf20Sopenharmony_ci/* ehci to cpu */ 8468c2ecf20Sopenharmony_cistatic inline u32 hc32_to_cpu(const struct ehci_hcd *ehci, const __hc32 x) 8478c2ecf20Sopenharmony_ci{ 8488c2ecf20Sopenharmony_ci return le32_to_cpu(x); 8498c2ecf20Sopenharmony_ci} 8508c2ecf20Sopenharmony_ci 8518c2ecf20Sopenharmony_cistatic inline u32 hc32_to_cpup(const struct ehci_hcd *ehci, const __hc32 *x) 8528c2ecf20Sopenharmony_ci{ 8538c2ecf20Sopenharmony_ci return le32_to_cpup(x); 8548c2ecf20Sopenharmony_ci} 8558c2ecf20Sopenharmony_ci 8568c2ecf20Sopenharmony_ci#endif 8578c2ecf20Sopenharmony_ci 8588c2ecf20Sopenharmony_ci/*-------------------------------------------------------------------------*/ 8598c2ecf20Sopenharmony_ci 8608c2ecf20Sopenharmony_ci#define ehci_dbg(ehci, fmt, args...) \ 8618c2ecf20Sopenharmony_ci dev_dbg(ehci_to_hcd(ehci)->self.controller, fmt, ## args) 8628c2ecf20Sopenharmony_ci#define ehci_err(ehci, fmt, args...) \ 8638c2ecf20Sopenharmony_ci dev_err(ehci_to_hcd(ehci)->self.controller, fmt, ## args) 8648c2ecf20Sopenharmony_ci#define ehci_info(ehci, fmt, args...) \ 8658c2ecf20Sopenharmony_ci dev_info(ehci_to_hcd(ehci)->self.controller, fmt, ## args) 8668c2ecf20Sopenharmony_ci#define ehci_warn(ehci, fmt, args...) \ 8678c2ecf20Sopenharmony_ci dev_warn(ehci_to_hcd(ehci)->self.controller, fmt, ## args) 8688c2ecf20Sopenharmony_ci 8698c2ecf20Sopenharmony_ci/*-------------------------------------------------------------------------*/ 8708c2ecf20Sopenharmony_ci 8718c2ecf20Sopenharmony_ci/* Declarations of things exported for use by ehci platform drivers */ 8728c2ecf20Sopenharmony_ci 8738c2ecf20Sopenharmony_cistruct ehci_driver_overrides { 8748c2ecf20Sopenharmony_ci size_t extra_priv_size; 8758c2ecf20Sopenharmony_ci int (*reset)(struct usb_hcd *hcd); 8768c2ecf20Sopenharmony_ci int (*port_power)(struct usb_hcd *hcd, 8778c2ecf20Sopenharmony_ci int portnum, bool enable); 8788c2ecf20Sopenharmony_ci}; 8798c2ecf20Sopenharmony_ci 8808c2ecf20Sopenharmony_ciextern void ehci_init_driver(struct hc_driver *drv, 8818c2ecf20Sopenharmony_ci const struct ehci_driver_overrides *over); 8828c2ecf20Sopenharmony_ciextern int ehci_setup(struct usb_hcd *hcd); 8838c2ecf20Sopenharmony_ciextern int ehci_handshake(struct ehci_hcd *ehci, void __iomem *ptr, 8848c2ecf20Sopenharmony_ci u32 mask, u32 done, int usec); 8858c2ecf20Sopenharmony_ciextern int ehci_reset(struct ehci_hcd *ehci); 8868c2ecf20Sopenharmony_ci 8878c2ecf20Sopenharmony_ciextern int ehci_suspend(struct usb_hcd *hcd, bool do_wakeup); 8888c2ecf20Sopenharmony_ciextern int ehci_resume(struct usb_hcd *hcd, bool force_reset); 8898c2ecf20Sopenharmony_ciextern void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci, 8908c2ecf20Sopenharmony_ci bool suspending, bool do_wakeup); 8918c2ecf20Sopenharmony_ci 8928c2ecf20Sopenharmony_ciextern int ehci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, 8938c2ecf20Sopenharmony_ci u16 wIndex, char *buf, u16 wLength); 8948c2ecf20Sopenharmony_ci 8958c2ecf20Sopenharmony_ci#endif /* __LINUX_EHCI_HCD_H */ 896