162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2001-2002 by David Brownell 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#ifndef __LINUX_EHCI_HCD_H 762306a36Sopenharmony_ci#define __LINUX_EHCI_HCD_H 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci/* definitions used for the EHCI driver */ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci/* 1262306a36Sopenharmony_ci * __hc32 and __hc16 are "Host Controller" types, they may be equivalent to 1362306a36Sopenharmony_ci * __leXX (normally) or __beXX (given EHCI_BIG_ENDIAN_DESC), depending on 1462306a36Sopenharmony_ci * the host controller implementation. 1562306a36Sopenharmony_ci * 1662306a36Sopenharmony_ci * To facilitate the strongest possible byte-order checking from "sparse" 1762306a36Sopenharmony_ci * and so on, we use __leXX unless that's not practical. 1862306a36Sopenharmony_ci */ 1962306a36Sopenharmony_ci#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_DESC 2062306a36Sopenharmony_citypedef __u32 __bitwise __hc32; 2162306a36Sopenharmony_citypedef __u16 __bitwise __hc16; 2262306a36Sopenharmony_ci#else 2362306a36Sopenharmony_ci#define __hc32 __le32 2462306a36Sopenharmony_ci#define __hc16 __le16 2562306a36Sopenharmony_ci#endif 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci/* statistics can be kept for tuning/monitoring */ 2862306a36Sopenharmony_ci#ifdef CONFIG_DYNAMIC_DEBUG 2962306a36Sopenharmony_ci#define EHCI_STATS 3062306a36Sopenharmony_ci#endif 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_cistruct ehci_stats { 3362306a36Sopenharmony_ci /* irq usage */ 3462306a36Sopenharmony_ci unsigned long normal; 3562306a36Sopenharmony_ci unsigned long error; 3662306a36Sopenharmony_ci unsigned long iaa; 3762306a36Sopenharmony_ci unsigned long lost_iaa; 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci /* termination of urbs from core */ 4062306a36Sopenharmony_ci unsigned long complete; 4162306a36Sopenharmony_ci unsigned long unlink; 4262306a36Sopenharmony_ci}; 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci/* 4562306a36Sopenharmony_ci * Scheduling and budgeting information for periodic transfers, for both 4662306a36Sopenharmony_ci * high-speed devices and full/low-speed devices lying behind a TT. 4762306a36Sopenharmony_ci */ 4862306a36Sopenharmony_cistruct ehci_per_sched { 4962306a36Sopenharmony_ci struct usb_device *udev; /* access to the TT */ 5062306a36Sopenharmony_ci struct usb_host_endpoint *ep; 5162306a36Sopenharmony_ci struct list_head ps_list; /* node on ehci_tt's ps_list */ 5262306a36Sopenharmony_ci u16 tt_usecs; /* time on the FS/LS bus */ 5362306a36Sopenharmony_ci u16 cs_mask; /* C-mask and S-mask bytes */ 5462306a36Sopenharmony_ci u16 period; /* actual period in frames */ 5562306a36Sopenharmony_ci u16 phase; /* actual phase, frame part */ 5662306a36Sopenharmony_ci u8 bw_phase; /* same, for bandwidth 5762306a36Sopenharmony_ci reservation */ 5862306a36Sopenharmony_ci u8 phase_uf; /* uframe part of the phase */ 5962306a36Sopenharmony_ci u8 usecs, c_usecs; /* times on the HS bus */ 6062306a36Sopenharmony_ci u8 bw_uperiod; /* period in microframes, for 6162306a36Sopenharmony_ci bandwidth reservation */ 6262306a36Sopenharmony_ci u8 bw_period; /* same, in frames */ 6362306a36Sopenharmony_ci}; 6462306a36Sopenharmony_ci#define NO_FRAME 29999 /* frame not assigned yet */ 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci/* ehci_hcd->lock guards shared data against other CPUs: 6762306a36Sopenharmony_ci * ehci_hcd: async, unlink, periodic (and shadow), ... 6862306a36Sopenharmony_ci * usb_host_endpoint: hcpriv 6962306a36Sopenharmony_ci * ehci_qh: qh_next, qtd_list 7062306a36Sopenharmony_ci * ehci_qtd: qtd_list 7162306a36Sopenharmony_ci * 7262306a36Sopenharmony_ci * Also, hold this lock when talking to HC registers or 7362306a36Sopenharmony_ci * when updating hw_* fields in shared qh/qtd/... structures. 7462306a36Sopenharmony_ci */ 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci#define EHCI_MAX_ROOT_PORTS 15 /* see HCS_N_PORTS */ 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci/* 7962306a36Sopenharmony_ci * ehci_rh_state values of EHCI_RH_RUNNING or above mean that the 8062306a36Sopenharmony_ci * controller may be doing DMA. Lower values mean there's no DMA. 8162306a36Sopenharmony_ci */ 8262306a36Sopenharmony_cienum ehci_rh_state { 8362306a36Sopenharmony_ci EHCI_RH_HALTED, 8462306a36Sopenharmony_ci EHCI_RH_SUSPENDED, 8562306a36Sopenharmony_ci EHCI_RH_RUNNING, 8662306a36Sopenharmony_ci EHCI_RH_STOPPING 8762306a36Sopenharmony_ci}; 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci/* 9062306a36Sopenharmony_ci * Timer events, ordered by increasing delay length. 9162306a36Sopenharmony_ci * Always update event_delays_ns[] and event_handlers[] (defined in 9262306a36Sopenharmony_ci * ehci-timer.c) in parallel with this list. 9362306a36Sopenharmony_ci */ 9462306a36Sopenharmony_cienum ehci_hrtimer_event { 9562306a36Sopenharmony_ci EHCI_HRTIMER_POLL_ASS, /* Poll for async schedule off */ 9662306a36Sopenharmony_ci EHCI_HRTIMER_POLL_PSS, /* Poll for periodic schedule off */ 9762306a36Sopenharmony_ci EHCI_HRTIMER_POLL_DEAD, /* Wait for dead controller to stop */ 9862306a36Sopenharmony_ci EHCI_HRTIMER_UNLINK_INTR, /* Wait for interrupt QH unlink */ 9962306a36Sopenharmony_ci EHCI_HRTIMER_FREE_ITDS, /* Wait for unused iTDs and siTDs */ 10062306a36Sopenharmony_ci EHCI_HRTIMER_ACTIVE_UNLINK, /* Wait while unlinking an active QH */ 10162306a36Sopenharmony_ci EHCI_HRTIMER_START_UNLINK_INTR, /* Unlink empty interrupt QHs */ 10262306a36Sopenharmony_ci EHCI_HRTIMER_ASYNC_UNLINKS, /* Unlink empty async QHs */ 10362306a36Sopenharmony_ci EHCI_HRTIMER_IAA_WATCHDOG, /* Handle lost IAA interrupts */ 10462306a36Sopenharmony_ci EHCI_HRTIMER_DISABLE_PERIODIC, /* Wait to disable periodic sched */ 10562306a36Sopenharmony_ci EHCI_HRTIMER_DISABLE_ASYNC, /* Wait to disable async sched */ 10662306a36Sopenharmony_ci EHCI_HRTIMER_IO_WATCHDOG, /* Check for missing IRQs */ 10762306a36Sopenharmony_ci EHCI_HRTIMER_NUM_EVENTS /* Must come last */ 10862306a36Sopenharmony_ci}; 10962306a36Sopenharmony_ci#define EHCI_HRTIMER_NO_EVENT 99 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_cistruct ehci_hcd { /* one per controller */ 11262306a36Sopenharmony_ci /* timing support */ 11362306a36Sopenharmony_ci enum ehci_hrtimer_event next_hrtimer_event; 11462306a36Sopenharmony_ci unsigned enabled_hrtimer_events; 11562306a36Sopenharmony_ci ktime_t hr_timeouts[EHCI_HRTIMER_NUM_EVENTS]; 11662306a36Sopenharmony_ci struct hrtimer hrtimer; 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci int PSS_poll_count; 11962306a36Sopenharmony_ci int ASS_poll_count; 12062306a36Sopenharmony_ci int died_poll_count; 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci /* glue to PCI and HCD framework */ 12362306a36Sopenharmony_ci struct ehci_caps __iomem *caps; 12462306a36Sopenharmony_ci struct ehci_regs __iomem *regs; 12562306a36Sopenharmony_ci struct ehci_dbg_port __iomem *debug; 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci __u32 hcs_params; /* cached register copy */ 12862306a36Sopenharmony_ci spinlock_t lock; 12962306a36Sopenharmony_ci enum ehci_rh_state rh_state; 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci /* general schedule support */ 13262306a36Sopenharmony_ci bool scanning:1; 13362306a36Sopenharmony_ci bool need_rescan:1; 13462306a36Sopenharmony_ci bool intr_unlinking:1; 13562306a36Sopenharmony_ci bool iaa_in_progress:1; 13662306a36Sopenharmony_ci bool async_unlinking:1; 13762306a36Sopenharmony_ci bool shutdown:1; 13862306a36Sopenharmony_ci struct ehci_qh *qh_scan_next; 13962306a36Sopenharmony_ci 14062306a36Sopenharmony_ci /* async schedule support */ 14162306a36Sopenharmony_ci struct ehci_qh *async; 14262306a36Sopenharmony_ci struct ehci_qh *dummy; /* For AMD quirk use */ 14362306a36Sopenharmony_ci struct list_head async_unlink; 14462306a36Sopenharmony_ci struct list_head async_idle; 14562306a36Sopenharmony_ci unsigned async_unlink_cycle; 14662306a36Sopenharmony_ci unsigned async_count; /* async activity count */ 14762306a36Sopenharmony_ci __hc32 old_current; /* Test for QH becoming */ 14862306a36Sopenharmony_ci __hc32 old_token; /* inactive during unlink */ 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_ci /* periodic schedule support */ 15162306a36Sopenharmony_ci#define DEFAULT_I_TDPS 1024 /* some HCs can do less */ 15262306a36Sopenharmony_ci unsigned periodic_size; 15362306a36Sopenharmony_ci __hc32 *periodic; /* hw periodic table */ 15462306a36Sopenharmony_ci dma_addr_t periodic_dma; 15562306a36Sopenharmony_ci struct list_head intr_qh_list; 15662306a36Sopenharmony_ci unsigned i_thresh; /* uframes HC might cache */ 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_ci union ehci_shadow *pshadow; /* mirror hw periodic table */ 15962306a36Sopenharmony_ci struct list_head intr_unlink_wait; 16062306a36Sopenharmony_ci struct list_head intr_unlink; 16162306a36Sopenharmony_ci unsigned intr_unlink_wait_cycle; 16262306a36Sopenharmony_ci unsigned intr_unlink_cycle; 16362306a36Sopenharmony_ci unsigned now_frame; /* frame from HC hardware */ 16462306a36Sopenharmony_ci unsigned last_iso_frame; /* last frame scanned for iso */ 16562306a36Sopenharmony_ci unsigned intr_count; /* intr activity count */ 16662306a36Sopenharmony_ci unsigned isoc_count; /* isoc activity count */ 16762306a36Sopenharmony_ci unsigned periodic_count; /* periodic activity count */ 16862306a36Sopenharmony_ci unsigned uframe_periodic_max; /* max periodic time per uframe */ 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ci 17162306a36Sopenharmony_ci /* list of itds & sitds completed while now_frame was still active */ 17262306a36Sopenharmony_ci struct list_head cached_itd_list; 17362306a36Sopenharmony_ci struct ehci_itd *last_itd_to_free; 17462306a36Sopenharmony_ci struct list_head cached_sitd_list; 17562306a36Sopenharmony_ci struct ehci_sitd *last_sitd_to_free; 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ci /* per root hub port */ 17862306a36Sopenharmony_ci unsigned long reset_done[EHCI_MAX_ROOT_PORTS]; 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_ci /* bit vectors (one bit per port) */ 18162306a36Sopenharmony_ci unsigned long bus_suspended; /* which ports were 18262306a36Sopenharmony_ci already suspended at the start of a bus suspend */ 18362306a36Sopenharmony_ci unsigned long companion_ports; /* which ports are 18462306a36Sopenharmony_ci dedicated to the companion controller */ 18562306a36Sopenharmony_ci unsigned long owned_ports; /* which ports are 18662306a36Sopenharmony_ci owned by the companion during a bus suspend */ 18762306a36Sopenharmony_ci unsigned long port_c_suspend; /* which ports have 18862306a36Sopenharmony_ci the change-suspend feature turned on */ 18962306a36Sopenharmony_ci unsigned long suspended_ports; /* which ports are 19062306a36Sopenharmony_ci suspended */ 19162306a36Sopenharmony_ci unsigned long resuming_ports; /* which ports have 19262306a36Sopenharmony_ci started to resume */ 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ci /* per-HC memory pools (could be per-bus, but ...) */ 19562306a36Sopenharmony_ci struct dma_pool *qh_pool; /* qh per active urb */ 19662306a36Sopenharmony_ci struct dma_pool *qtd_pool; /* one or more per qh */ 19762306a36Sopenharmony_ci struct dma_pool *itd_pool; /* itd per iso urb */ 19862306a36Sopenharmony_ci struct dma_pool *sitd_pool; /* sitd per split iso urb */ 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ci unsigned random_frame; 20162306a36Sopenharmony_ci unsigned long next_statechange; 20262306a36Sopenharmony_ci ktime_t last_periodic_enable; 20362306a36Sopenharmony_ci u32 command; 20462306a36Sopenharmony_ci 20562306a36Sopenharmony_ci /* SILICON QUIRKS */ 20662306a36Sopenharmony_ci unsigned no_selective_suspend:1; 20762306a36Sopenharmony_ci unsigned has_fsl_port_bug:1; /* FreeScale */ 20862306a36Sopenharmony_ci unsigned has_fsl_hs_errata:1; /* Freescale HS quirk */ 20962306a36Sopenharmony_ci unsigned has_fsl_susp_errata:1; /* NXP SUSP quirk */ 21062306a36Sopenharmony_ci unsigned has_ci_pec_bug:1; /* ChipIdea PEC bug */ 21162306a36Sopenharmony_ci unsigned big_endian_mmio:1; 21262306a36Sopenharmony_ci unsigned big_endian_desc:1; 21362306a36Sopenharmony_ci unsigned big_endian_capbase:1; 21462306a36Sopenharmony_ci unsigned has_amcc_usb23:1; 21562306a36Sopenharmony_ci unsigned need_io_watchdog:1; 21662306a36Sopenharmony_ci unsigned amd_pll_fix:1; 21762306a36Sopenharmony_ci unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/ 21862306a36Sopenharmony_ci unsigned has_synopsys_hc_bug:1; /* Synopsys HC */ 21962306a36Sopenharmony_ci unsigned frame_index_bug:1; /* MosChip (AKA NetMos) */ 22062306a36Sopenharmony_ci unsigned need_oc_pp_cycle:1; /* MPC834X port power */ 22162306a36Sopenharmony_ci unsigned imx28_write_fix:1; /* For Freescale i.MX28 */ 22262306a36Sopenharmony_ci unsigned spurious_oc:1; 22362306a36Sopenharmony_ci unsigned is_aspeed:1; 22462306a36Sopenharmony_ci unsigned zx_wakeup_clear_needed:1; 22562306a36Sopenharmony_ci 22662306a36Sopenharmony_ci /* required for usb32 quirk */ 22762306a36Sopenharmony_ci #define OHCI_CTRL_HCFS (3 << 6) 22862306a36Sopenharmony_ci #define OHCI_USB_OPER (2 << 6) 22962306a36Sopenharmony_ci #define OHCI_USB_SUSPEND (3 << 6) 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_ci #define OHCI_HCCTRL_OFFSET 0x4 23262306a36Sopenharmony_ci #define OHCI_HCCTRL_LEN 0x4 23362306a36Sopenharmony_ci __hc32 *ohci_hcctrl_reg; 23462306a36Sopenharmony_ci unsigned has_hostpc:1; 23562306a36Sopenharmony_ci unsigned has_tdi_phy_lpm:1; 23662306a36Sopenharmony_ci unsigned has_ppcd:1; /* support per-port change bits */ 23762306a36Sopenharmony_ci u8 sbrn; /* packed release number */ 23862306a36Sopenharmony_ci 23962306a36Sopenharmony_ci /* irq statistics */ 24062306a36Sopenharmony_ci#ifdef EHCI_STATS 24162306a36Sopenharmony_ci struct ehci_stats stats; 24262306a36Sopenharmony_ci# define INCR(x) ((x)++) 24362306a36Sopenharmony_ci#else 24462306a36Sopenharmony_ci# define INCR(x) do {} while (0) 24562306a36Sopenharmony_ci#endif 24662306a36Sopenharmony_ci 24762306a36Sopenharmony_ci /* debug files */ 24862306a36Sopenharmony_ci#ifdef CONFIG_DYNAMIC_DEBUG 24962306a36Sopenharmony_ci struct dentry *debug_dir; 25062306a36Sopenharmony_ci#endif 25162306a36Sopenharmony_ci 25262306a36Sopenharmony_ci /* bandwidth usage */ 25362306a36Sopenharmony_ci#define EHCI_BANDWIDTH_SIZE 64 25462306a36Sopenharmony_ci#define EHCI_BANDWIDTH_FRAMES (EHCI_BANDWIDTH_SIZE >> 3) 25562306a36Sopenharmony_ci u8 bandwidth[EHCI_BANDWIDTH_SIZE]; 25662306a36Sopenharmony_ci /* us allocated per uframe */ 25762306a36Sopenharmony_ci u8 tt_budget[EHCI_BANDWIDTH_SIZE]; 25862306a36Sopenharmony_ci /* us budgeted per uframe */ 25962306a36Sopenharmony_ci struct list_head tt_list; 26062306a36Sopenharmony_ci 26162306a36Sopenharmony_ci /* platform-specific data -- must come last */ 26262306a36Sopenharmony_ci unsigned long priv[] __aligned(sizeof(s64)); 26362306a36Sopenharmony_ci}; 26462306a36Sopenharmony_ci 26562306a36Sopenharmony_ci/* convert between an HCD pointer and the corresponding EHCI_HCD */ 26662306a36Sopenharmony_cistatic inline struct ehci_hcd *hcd_to_ehci(struct usb_hcd *hcd) 26762306a36Sopenharmony_ci{ 26862306a36Sopenharmony_ci return (struct ehci_hcd *) (hcd->hcd_priv); 26962306a36Sopenharmony_ci} 27062306a36Sopenharmony_cistatic inline struct usb_hcd *ehci_to_hcd(struct ehci_hcd *ehci) 27162306a36Sopenharmony_ci{ 27262306a36Sopenharmony_ci return container_of((void *) ehci, struct usb_hcd, hcd_priv); 27362306a36Sopenharmony_ci} 27462306a36Sopenharmony_ci 27562306a36Sopenharmony_ci/*-------------------------------------------------------------------------*/ 27662306a36Sopenharmony_ci 27762306a36Sopenharmony_ci#include <linux/usb/ehci_def.h> 27862306a36Sopenharmony_ci 27962306a36Sopenharmony_ci/*-------------------------------------------------------------------------*/ 28062306a36Sopenharmony_ci 28162306a36Sopenharmony_ci#define QTD_NEXT(ehci, dma) cpu_to_hc32(ehci, (u32)dma) 28262306a36Sopenharmony_ci 28362306a36Sopenharmony_ci/* 28462306a36Sopenharmony_ci * EHCI Specification 0.95 Section 3.5 28562306a36Sopenharmony_ci * QTD: describe data transfer components (buffer, direction, ...) 28662306a36Sopenharmony_ci * See Fig 3-6 "Queue Element Transfer Descriptor Block Diagram". 28762306a36Sopenharmony_ci * 28862306a36Sopenharmony_ci * These are associated only with "QH" (Queue Head) structures, 28962306a36Sopenharmony_ci * used with control, bulk, and interrupt transfers. 29062306a36Sopenharmony_ci */ 29162306a36Sopenharmony_cistruct ehci_qtd { 29262306a36Sopenharmony_ci /* first part defined by EHCI spec */ 29362306a36Sopenharmony_ci __hc32 hw_next; /* see EHCI 3.5.1 */ 29462306a36Sopenharmony_ci __hc32 hw_alt_next; /* see EHCI 3.5.2 */ 29562306a36Sopenharmony_ci __hc32 hw_token; /* see EHCI 3.5.3 */ 29662306a36Sopenharmony_ci#define QTD_TOGGLE (1 << 31) /* data toggle */ 29762306a36Sopenharmony_ci#define QTD_LENGTH(tok) (((tok)>>16) & 0x7fff) 29862306a36Sopenharmony_ci#define QTD_IOC (1 << 15) /* interrupt on complete */ 29962306a36Sopenharmony_ci#define QTD_CERR(tok) (((tok)>>10) & 0x3) 30062306a36Sopenharmony_ci#define QTD_PID(tok) (((tok)>>8) & 0x3) 30162306a36Sopenharmony_ci#define QTD_STS_ACTIVE (1 << 7) /* HC may execute this */ 30262306a36Sopenharmony_ci#define QTD_STS_HALT (1 << 6) /* halted on error */ 30362306a36Sopenharmony_ci#define QTD_STS_DBE (1 << 5) /* data buffer error (in HC) */ 30462306a36Sopenharmony_ci#define QTD_STS_BABBLE (1 << 4) /* device was babbling (qtd halted) */ 30562306a36Sopenharmony_ci#define QTD_STS_XACT (1 << 3) /* device gave illegal response */ 30662306a36Sopenharmony_ci#define QTD_STS_MMF (1 << 2) /* incomplete split transaction */ 30762306a36Sopenharmony_ci#define QTD_STS_STS (1 << 1) /* split transaction state */ 30862306a36Sopenharmony_ci#define QTD_STS_PING (1 << 0) /* issue PING? */ 30962306a36Sopenharmony_ci 31062306a36Sopenharmony_ci#define ACTIVE_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_ACTIVE) 31162306a36Sopenharmony_ci#define HALT_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_HALT) 31262306a36Sopenharmony_ci#define STATUS_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_STS) 31362306a36Sopenharmony_ci 31462306a36Sopenharmony_ci __hc32 hw_buf[5]; /* see EHCI 3.5.4 */ 31562306a36Sopenharmony_ci __hc32 hw_buf_hi[5]; /* Appendix B */ 31662306a36Sopenharmony_ci 31762306a36Sopenharmony_ci /* the rest is HCD-private */ 31862306a36Sopenharmony_ci dma_addr_t qtd_dma; /* qtd address */ 31962306a36Sopenharmony_ci struct list_head qtd_list; /* sw qtd list */ 32062306a36Sopenharmony_ci struct urb *urb; /* qtd's urb */ 32162306a36Sopenharmony_ci size_t length; /* length of buffer */ 32262306a36Sopenharmony_ci} __aligned(32); 32362306a36Sopenharmony_ci 32462306a36Sopenharmony_ci/* mask NakCnt+T in qh->hw_alt_next */ 32562306a36Sopenharmony_ci#define QTD_MASK(ehci) cpu_to_hc32(ehci, ~0x1f) 32662306a36Sopenharmony_ci 32762306a36Sopenharmony_ci#define IS_SHORT_READ(token) (QTD_LENGTH(token) != 0 && QTD_PID(token) == 1) 32862306a36Sopenharmony_ci 32962306a36Sopenharmony_ci/*-------------------------------------------------------------------------*/ 33062306a36Sopenharmony_ci 33162306a36Sopenharmony_ci/* type tag from {qh,itd,sitd,fstn}->hw_next */ 33262306a36Sopenharmony_ci#define Q_NEXT_TYPE(ehci, dma) ((dma) & cpu_to_hc32(ehci, 3 << 1)) 33362306a36Sopenharmony_ci 33462306a36Sopenharmony_ci/* 33562306a36Sopenharmony_ci * Now the following defines are not converted using the 33662306a36Sopenharmony_ci * cpu_to_le32() macro anymore, since we have to support 33762306a36Sopenharmony_ci * "dynamic" switching between be and le support, so that the driver 33862306a36Sopenharmony_ci * can be used on one system with SoC EHCI controller using big-endian 33962306a36Sopenharmony_ci * descriptors as well as a normal little-endian PCI EHCI controller. 34062306a36Sopenharmony_ci */ 34162306a36Sopenharmony_ci/* values for that type tag */ 34262306a36Sopenharmony_ci#define Q_TYPE_ITD (0 << 1) 34362306a36Sopenharmony_ci#define Q_TYPE_QH (1 << 1) 34462306a36Sopenharmony_ci#define Q_TYPE_SITD (2 << 1) 34562306a36Sopenharmony_ci#define Q_TYPE_FSTN (3 << 1) 34662306a36Sopenharmony_ci 34762306a36Sopenharmony_ci/* next async queue entry, or pointer to interrupt/periodic QH */ 34862306a36Sopenharmony_ci#define QH_NEXT(ehci, dma) \ 34962306a36Sopenharmony_ci (cpu_to_hc32(ehci, (((u32) dma) & ~0x01f) | Q_TYPE_QH)) 35062306a36Sopenharmony_ci 35162306a36Sopenharmony_ci/* for periodic/async schedules and qtd lists, mark end of list */ 35262306a36Sopenharmony_ci#define EHCI_LIST_END(ehci) cpu_to_hc32(ehci, 1) /* "null pointer" to hw */ 35362306a36Sopenharmony_ci 35462306a36Sopenharmony_ci/* 35562306a36Sopenharmony_ci * Entries in periodic shadow table are pointers to one of four kinds 35662306a36Sopenharmony_ci * of data structure. That's dictated by the hardware; a type tag is 35762306a36Sopenharmony_ci * encoded in the low bits of the hardware's periodic schedule. Use 35862306a36Sopenharmony_ci * Q_NEXT_TYPE to get the tag. 35962306a36Sopenharmony_ci * 36062306a36Sopenharmony_ci * For entries in the async schedule, the type tag always says "qh". 36162306a36Sopenharmony_ci */ 36262306a36Sopenharmony_ciunion ehci_shadow { 36362306a36Sopenharmony_ci struct ehci_qh *qh; /* Q_TYPE_QH */ 36462306a36Sopenharmony_ci struct ehci_itd *itd; /* Q_TYPE_ITD */ 36562306a36Sopenharmony_ci struct ehci_sitd *sitd; /* Q_TYPE_SITD */ 36662306a36Sopenharmony_ci struct ehci_fstn *fstn; /* Q_TYPE_FSTN */ 36762306a36Sopenharmony_ci __hc32 *hw_next; /* (all types) */ 36862306a36Sopenharmony_ci void *ptr; 36962306a36Sopenharmony_ci}; 37062306a36Sopenharmony_ci 37162306a36Sopenharmony_ci/*-------------------------------------------------------------------------*/ 37262306a36Sopenharmony_ci 37362306a36Sopenharmony_ci/* 37462306a36Sopenharmony_ci * EHCI Specification 0.95 Section 3.6 37562306a36Sopenharmony_ci * QH: describes control/bulk/interrupt endpoints 37662306a36Sopenharmony_ci * See Fig 3-7 "Queue Head Structure Layout". 37762306a36Sopenharmony_ci * 37862306a36Sopenharmony_ci * These appear in both the async and (for interrupt) periodic schedules. 37962306a36Sopenharmony_ci */ 38062306a36Sopenharmony_ci 38162306a36Sopenharmony_ci/* first part defined by EHCI spec */ 38262306a36Sopenharmony_cistruct ehci_qh_hw { 38362306a36Sopenharmony_ci __hc32 hw_next; /* see EHCI 3.6.1 */ 38462306a36Sopenharmony_ci __hc32 hw_info1; /* see EHCI 3.6.2 */ 38562306a36Sopenharmony_ci#define QH_CONTROL_EP (1 << 27) /* FS/LS control endpoint */ 38662306a36Sopenharmony_ci#define QH_HEAD (1 << 15) /* Head of async reclamation list */ 38762306a36Sopenharmony_ci#define QH_TOGGLE_CTL (1 << 14) /* Data toggle control */ 38862306a36Sopenharmony_ci#define QH_HIGH_SPEED (2 << 12) /* Endpoint speed */ 38962306a36Sopenharmony_ci#define QH_LOW_SPEED (1 << 12) 39062306a36Sopenharmony_ci#define QH_FULL_SPEED (0 << 12) 39162306a36Sopenharmony_ci#define QH_INACTIVATE (1 << 7) /* Inactivate on next transaction */ 39262306a36Sopenharmony_ci __hc32 hw_info2; /* see EHCI 3.6.2 */ 39362306a36Sopenharmony_ci#define QH_SMASK 0x000000ff 39462306a36Sopenharmony_ci#define QH_CMASK 0x0000ff00 39562306a36Sopenharmony_ci#define QH_HUBADDR 0x007f0000 39662306a36Sopenharmony_ci#define QH_HUBPORT 0x3f800000 39762306a36Sopenharmony_ci#define QH_MULT 0xc0000000 39862306a36Sopenharmony_ci __hc32 hw_current; /* qtd list - see EHCI 3.6.4 */ 39962306a36Sopenharmony_ci 40062306a36Sopenharmony_ci /* qtd overlay (hardware parts of a struct ehci_qtd) */ 40162306a36Sopenharmony_ci __hc32 hw_qtd_next; 40262306a36Sopenharmony_ci __hc32 hw_alt_next; 40362306a36Sopenharmony_ci __hc32 hw_token; 40462306a36Sopenharmony_ci __hc32 hw_buf[5]; 40562306a36Sopenharmony_ci __hc32 hw_buf_hi[5]; 40662306a36Sopenharmony_ci} __aligned(32); 40762306a36Sopenharmony_ci 40862306a36Sopenharmony_cistruct ehci_qh { 40962306a36Sopenharmony_ci struct ehci_qh_hw *hw; /* Must come first */ 41062306a36Sopenharmony_ci /* the rest is HCD-private */ 41162306a36Sopenharmony_ci dma_addr_t qh_dma; /* address of qh */ 41262306a36Sopenharmony_ci union ehci_shadow qh_next; /* ptr to qh; or periodic */ 41362306a36Sopenharmony_ci struct list_head qtd_list; /* sw qtd list */ 41462306a36Sopenharmony_ci struct list_head intr_node; /* list of intr QHs */ 41562306a36Sopenharmony_ci struct ehci_qtd *dummy; 41662306a36Sopenharmony_ci struct list_head unlink_node; 41762306a36Sopenharmony_ci struct ehci_per_sched ps; /* scheduling info */ 41862306a36Sopenharmony_ci 41962306a36Sopenharmony_ci unsigned unlink_cycle; 42062306a36Sopenharmony_ci 42162306a36Sopenharmony_ci u8 qh_state; 42262306a36Sopenharmony_ci#define QH_STATE_LINKED 1 /* HC sees this */ 42362306a36Sopenharmony_ci#define QH_STATE_UNLINK 2 /* HC may still see this */ 42462306a36Sopenharmony_ci#define QH_STATE_IDLE 3 /* HC doesn't see this */ 42562306a36Sopenharmony_ci#define QH_STATE_UNLINK_WAIT 4 /* LINKED and on unlink q */ 42662306a36Sopenharmony_ci#define QH_STATE_COMPLETING 5 /* don't touch token.HALT */ 42762306a36Sopenharmony_ci 42862306a36Sopenharmony_ci u8 xacterrs; /* XactErr retry counter */ 42962306a36Sopenharmony_ci#define QH_XACTERR_MAX 32 /* XactErr retry limit */ 43062306a36Sopenharmony_ci 43162306a36Sopenharmony_ci u8 unlink_reason; 43262306a36Sopenharmony_ci#define QH_UNLINK_HALTED 0x01 /* Halt flag is set */ 43362306a36Sopenharmony_ci#define QH_UNLINK_SHORT_READ 0x02 /* Recover from a short read */ 43462306a36Sopenharmony_ci#define QH_UNLINK_DUMMY_OVERLAY 0x04 /* QH overlayed the dummy TD */ 43562306a36Sopenharmony_ci#define QH_UNLINK_SHUTDOWN 0x08 /* The HC isn't running */ 43662306a36Sopenharmony_ci#define QH_UNLINK_QUEUE_EMPTY 0x10 /* Reached end of the queue */ 43762306a36Sopenharmony_ci#define QH_UNLINK_REQUESTED 0x20 /* Disable, reset, or dequeue */ 43862306a36Sopenharmony_ci 43962306a36Sopenharmony_ci u8 gap_uf; /* uframes split/csplit gap */ 44062306a36Sopenharmony_ci 44162306a36Sopenharmony_ci unsigned is_out:1; /* bulk or intr OUT */ 44262306a36Sopenharmony_ci unsigned clearing_tt:1; /* Clear-TT-Buf in progress */ 44362306a36Sopenharmony_ci unsigned dequeue_during_giveback:1; 44462306a36Sopenharmony_ci unsigned should_be_inactive:1; 44562306a36Sopenharmony_ci}; 44662306a36Sopenharmony_ci 44762306a36Sopenharmony_ci/*-------------------------------------------------------------------------*/ 44862306a36Sopenharmony_ci 44962306a36Sopenharmony_ci/* description of one iso transaction (up to 3 KB data if highspeed) */ 45062306a36Sopenharmony_cistruct ehci_iso_packet { 45162306a36Sopenharmony_ci /* These will be copied to iTD when scheduling */ 45262306a36Sopenharmony_ci u64 bufp; /* itd->hw_bufp{,_hi}[pg] |= */ 45362306a36Sopenharmony_ci __hc32 transaction; /* itd->hw_transaction[i] |= */ 45462306a36Sopenharmony_ci u8 cross; /* buf crosses pages */ 45562306a36Sopenharmony_ci /* for full speed OUT splits */ 45662306a36Sopenharmony_ci u32 buf1; 45762306a36Sopenharmony_ci}; 45862306a36Sopenharmony_ci 45962306a36Sopenharmony_ci/* temporary schedule data for packets from iso urbs (both speeds) 46062306a36Sopenharmony_ci * each packet is one logical usb transaction to the device (not TT), 46162306a36Sopenharmony_ci * beginning at stream->next_uframe 46262306a36Sopenharmony_ci */ 46362306a36Sopenharmony_cistruct ehci_iso_sched { 46462306a36Sopenharmony_ci struct list_head td_list; 46562306a36Sopenharmony_ci unsigned span; 46662306a36Sopenharmony_ci unsigned first_packet; 46762306a36Sopenharmony_ci struct ehci_iso_packet packet[]; 46862306a36Sopenharmony_ci}; 46962306a36Sopenharmony_ci 47062306a36Sopenharmony_ci/* 47162306a36Sopenharmony_ci * ehci_iso_stream - groups all (s)itds for this endpoint. 47262306a36Sopenharmony_ci * acts like a qh would, if EHCI had them for ISO. 47362306a36Sopenharmony_ci */ 47462306a36Sopenharmony_cistruct ehci_iso_stream { 47562306a36Sopenharmony_ci /* first field matches ehci_qh, but is NULL */ 47662306a36Sopenharmony_ci struct ehci_qh_hw *hw; 47762306a36Sopenharmony_ci 47862306a36Sopenharmony_ci u8 bEndpointAddress; 47962306a36Sopenharmony_ci u8 highspeed; 48062306a36Sopenharmony_ci struct list_head td_list; /* queued itds/sitds */ 48162306a36Sopenharmony_ci struct list_head free_list; /* list of unused itds/sitds */ 48262306a36Sopenharmony_ci 48362306a36Sopenharmony_ci /* output of (re)scheduling */ 48462306a36Sopenharmony_ci struct ehci_per_sched ps; /* scheduling info */ 48562306a36Sopenharmony_ci unsigned next_uframe; 48662306a36Sopenharmony_ci __hc32 splits; 48762306a36Sopenharmony_ci 48862306a36Sopenharmony_ci /* the rest is derived from the endpoint descriptor, 48962306a36Sopenharmony_ci * including the extra info for hw_bufp[0..2] 49062306a36Sopenharmony_ci */ 49162306a36Sopenharmony_ci u16 uperiod; /* period in uframes */ 49262306a36Sopenharmony_ci u16 maxp; 49362306a36Sopenharmony_ci unsigned bandwidth; 49462306a36Sopenharmony_ci 49562306a36Sopenharmony_ci /* This is used to initialize iTD's hw_bufp fields */ 49662306a36Sopenharmony_ci __hc32 buf0; 49762306a36Sopenharmony_ci __hc32 buf1; 49862306a36Sopenharmony_ci __hc32 buf2; 49962306a36Sopenharmony_ci 50062306a36Sopenharmony_ci /* this is used to initialize sITD's tt info */ 50162306a36Sopenharmony_ci __hc32 address; 50262306a36Sopenharmony_ci}; 50362306a36Sopenharmony_ci 50462306a36Sopenharmony_ci/*-------------------------------------------------------------------------*/ 50562306a36Sopenharmony_ci 50662306a36Sopenharmony_ci/* 50762306a36Sopenharmony_ci * EHCI Specification 0.95 Section 3.3 50862306a36Sopenharmony_ci * Fig 3-4 "Isochronous Transaction Descriptor (iTD)" 50962306a36Sopenharmony_ci * 51062306a36Sopenharmony_ci * Schedule records for high speed iso xfers 51162306a36Sopenharmony_ci */ 51262306a36Sopenharmony_cistruct ehci_itd { 51362306a36Sopenharmony_ci /* first part defined by EHCI spec */ 51462306a36Sopenharmony_ci __hc32 hw_next; /* see EHCI 3.3.1 */ 51562306a36Sopenharmony_ci __hc32 hw_transaction[8]; /* see EHCI 3.3.2 */ 51662306a36Sopenharmony_ci#define EHCI_ISOC_ACTIVE (1<<31) /* activate transfer this slot */ 51762306a36Sopenharmony_ci#define EHCI_ISOC_BUF_ERR (1<<30) /* Data buffer error */ 51862306a36Sopenharmony_ci#define EHCI_ISOC_BABBLE (1<<29) /* babble detected */ 51962306a36Sopenharmony_ci#define EHCI_ISOC_XACTERR (1<<28) /* XactErr - transaction error */ 52062306a36Sopenharmony_ci#define EHCI_ITD_LENGTH(tok) (((tok)>>16) & 0x0fff) 52162306a36Sopenharmony_ci#define EHCI_ITD_IOC (1 << 15) /* interrupt on complete */ 52262306a36Sopenharmony_ci 52362306a36Sopenharmony_ci#define ITD_ACTIVE(ehci) cpu_to_hc32(ehci, EHCI_ISOC_ACTIVE) 52462306a36Sopenharmony_ci 52562306a36Sopenharmony_ci __hc32 hw_bufp[7]; /* see EHCI 3.3.3 */ 52662306a36Sopenharmony_ci __hc32 hw_bufp_hi[7]; /* Appendix B */ 52762306a36Sopenharmony_ci 52862306a36Sopenharmony_ci /* the rest is HCD-private */ 52962306a36Sopenharmony_ci dma_addr_t itd_dma; /* for this itd */ 53062306a36Sopenharmony_ci union ehci_shadow itd_next; /* ptr to periodic q entry */ 53162306a36Sopenharmony_ci 53262306a36Sopenharmony_ci struct urb *urb; 53362306a36Sopenharmony_ci struct ehci_iso_stream *stream; /* endpoint's queue */ 53462306a36Sopenharmony_ci struct list_head itd_list; /* list of stream's itds */ 53562306a36Sopenharmony_ci 53662306a36Sopenharmony_ci /* any/all hw_transactions here may be used by that urb */ 53762306a36Sopenharmony_ci unsigned frame; /* where scheduled */ 53862306a36Sopenharmony_ci unsigned pg; 53962306a36Sopenharmony_ci unsigned index[8]; /* in urb->iso_frame_desc */ 54062306a36Sopenharmony_ci} __aligned(32); 54162306a36Sopenharmony_ci 54262306a36Sopenharmony_ci/*-------------------------------------------------------------------------*/ 54362306a36Sopenharmony_ci 54462306a36Sopenharmony_ci/* 54562306a36Sopenharmony_ci * EHCI Specification 0.95 Section 3.4 54662306a36Sopenharmony_ci * siTD, aka split-transaction isochronous Transfer Descriptor 54762306a36Sopenharmony_ci * ... describe full speed iso xfers through TT in hubs 54862306a36Sopenharmony_ci * see Figure 3-5 "Split-transaction Isochronous Transaction Descriptor (siTD) 54962306a36Sopenharmony_ci */ 55062306a36Sopenharmony_cistruct ehci_sitd { 55162306a36Sopenharmony_ci /* first part defined by EHCI spec */ 55262306a36Sopenharmony_ci __hc32 hw_next; 55362306a36Sopenharmony_ci/* uses bit field macros above - see EHCI 0.95 Table 3-8 */ 55462306a36Sopenharmony_ci __hc32 hw_fullspeed_ep; /* EHCI table 3-9 */ 55562306a36Sopenharmony_ci __hc32 hw_uframe; /* EHCI table 3-10 */ 55662306a36Sopenharmony_ci __hc32 hw_results; /* EHCI table 3-11 */ 55762306a36Sopenharmony_ci#define SITD_IOC (1 << 31) /* interrupt on completion */ 55862306a36Sopenharmony_ci#define SITD_PAGE (1 << 30) /* buffer 0/1 */ 55962306a36Sopenharmony_ci#define SITD_LENGTH(x) (((x) >> 16) & 0x3ff) 56062306a36Sopenharmony_ci#define SITD_STS_ACTIVE (1 << 7) /* HC may execute this */ 56162306a36Sopenharmony_ci#define SITD_STS_ERR (1 << 6) /* error from TT */ 56262306a36Sopenharmony_ci#define SITD_STS_DBE (1 << 5) /* data buffer error (in HC) */ 56362306a36Sopenharmony_ci#define SITD_STS_BABBLE (1 << 4) /* device was babbling */ 56462306a36Sopenharmony_ci#define SITD_STS_XACT (1 << 3) /* illegal IN response */ 56562306a36Sopenharmony_ci#define SITD_STS_MMF (1 << 2) /* incomplete split transaction */ 56662306a36Sopenharmony_ci#define SITD_STS_STS (1 << 1) /* split transaction state */ 56762306a36Sopenharmony_ci 56862306a36Sopenharmony_ci#define SITD_ACTIVE(ehci) cpu_to_hc32(ehci, SITD_STS_ACTIVE) 56962306a36Sopenharmony_ci 57062306a36Sopenharmony_ci __hc32 hw_buf[2]; /* EHCI table 3-12 */ 57162306a36Sopenharmony_ci __hc32 hw_backpointer; /* EHCI table 3-13 */ 57262306a36Sopenharmony_ci __hc32 hw_buf_hi[2]; /* Appendix B */ 57362306a36Sopenharmony_ci 57462306a36Sopenharmony_ci /* the rest is HCD-private */ 57562306a36Sopenharmony_ci dma_addr_t sitd_dma; 57662306a36Sopenharmony_ci union ehci_shadow sitd_next; /* ptr to periodic q entry */ 57762306a36Sopenharmony_ci 57862306a36Sopenharmony_ci struct urb *urb; 57962306a36Sopenharmony_ci struct ehci_iso_stream *stream; /* endpoint's queue */ 58062306a36Sopenharmony_ci struct list_head sitd_list; /* list of stream's sitds */ 58162306a36Sopenharmony_ci unsigned frame; 58262306a36Sopenharmony_ci unsigned index; 58362306a36Sopenharmony_ci} __aligned(32); 58462306a36Sopenharmony_ci 58562306a36Sopenharmony_ci/*-------------------------------------------------------------------------*/ 58662306a36Sopenharmony_ci 58762306a36Sopenharmony_ci/* 58862306a36Sopenharmony_ci * EHCI Specification 0.96 Section 3.7 58962306a36Sopenharmony_ci * Periodic Frame Span Traversal Node (FSTN) 59062306a36Sopenharmony_ci * 59162306a36Sopenharmony_ci * Manages split interrupt transactions (using TT) that span frame boundaries 59262306a36Sopenharmony_ci * into uframes 0/1; see 4.12.2.2. In those uframes, a "save place" FSTN 59362306a36Sopenharmony_ci * makes the HC jump (back) to a QH to scan for fs/ls QH completions until 59462306a36Sopenharmony_ci * it hits a "restore" FSTN; then it returns to finish other uframe 0/1 work. 59562306a36Sopenharmony_ci */ 59662306a36Sopenharmony_cistruct ehci_fstn { 59762306a36Sopenharmony_ci __hc32 hw_next; /* any periodic q entry */ 59862306a36Sopenharmony_ci __hc32 hw_prev; /* qh or EHCI_LIST_END */ 59962306a36Sopenharmony_ci 60062306a36Sopenharmony_ci /* the rest is HCD-private */ 60162306a36Sopenharmony_ci dma_addr_t fstn_dma; 60262306a36Sopenharmony_ci union ehci_shadow fstn_next; /* ptr to periodic q entry */ 60362306a36Sopenharmony_ci} __aligned(32); 60462306a36Sopenharmony_ci 60562306a36Sopenharmony_ci/*-------------------------------------------------------------------------*/ 60662306a36Sopenharmony_ci 60762306a36Sopenharmony_ci/* 60862306a36Sopenharmony_ci * USB-2.0 Specification Sections 11.14 and 11.18 60962306a36Sopenharmony_ci * Scheduling and budgeting split transactions using TTs 61062306a36Sopenharmony_ci * 61162306a36Sopenharmony_ci * A hub can have a single TT for all its ports, or multiple TTs (one for each 61262306a36Sopenharmony_ci * port). The bandwidth and budgeting information for the full/low-speed bus 61362306a36Sopenharmony_ci * below each TT is self-contained and independent of the other TTs or the 61462306a36Sopenharmony_ci * high-speed bus. 61562306a36Sopenharmony_ci * 61662306a36Sopenharmony_ci * "Bandwidth" refers to the number of microseconds on the FS/LS bus allocated 61762306a36Sopenharmony_ci * to an interrupt or isochronous endpoint for each frame. "Budget" refers to 61862306a36Sopenharmony_ci * the best-case estimate of the number of full-speed bytes allocated to an 61962306a36Sopenharmony_ci * endpoint for each microframe within an allocated frame. 62062306a36Sopenharmony_ci * 62162306a36Sopenharmony_ci * Removal of an endpoint invalidates a TT's budget. Instead of trying to 62262306a36Sopenharmony_ci * keep an up-to-date record, we recompute the budget when it is needed. 62362306a36Sopenharmony_ci */ 62462306a36Sopenharmony_ci 62562306a36Sopenharmony_cistruct ehci_tt { 62662306a36Sopenharmony_ci u16 bandwidth[EHCI_BANDWIDTH_FRAMES]; 62762306a36Sopenharmony_ci 62862306a36Sopenharmony_ci struct list_head tt_list; /* List of all ehci_tt's */ 62962306a36Sopenharmony_ci struct list_head ps_list; /* Items using this TT */ 63062306a36Sopenharmony_ci struct usb_tt *usb_tt; 63162306a36Sopenharmony_ci int tt_port; /* TT port number */ 63262306a36Sopenharmony_ci}; 63362306a36Sopenharmony_ci 63462306a36Sopenharmony_ci/*-------------------------------------------------------------------------*/ 63562306a36Sopenharmony_ci 63662306a36Sopenharmony_ci/* Prepare the PORTSC wakeup flags during controller suspend/resume */ 63762306a36Sopenharmony_ci 63862306a36Sopenharmony_ci#define ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup) \ 63962306a36Sopenharmony_ci ehci_adjust_port_wakeup_flags(ehci, true, do_wakeup) 64062306a36Sopenharmony_ci 64162306a36Sopenharmony_ci#define ehci_prepare_ports_for_controller_resume(ehci) \ 64262306a36Sopenharmony_ci ehci_adjust_port_wakeup_flags(ehci, false, false) 64362306a36Sopenharmony_ci 64462306a36Sopenharmony_ci/*-------------------------------------------------------------------------*/ 64562306a36Sopenharmony_ci 64662306a36Sopenharmony_ci#ifdef CONFIG_USB_EHCI_ROOT_HUB_TT 64762306a36Sopenharmony_ci 64862306a36Sopenharmony_ci/* 64962306a36Sopenharmony_ci * Some EHCI controllers have a Transaction Translator built into the 65062306a36Sopenharmony_ci * root hub. This is a non-standard feature. Each controller will need 65162306a36Sopenharmony_ci * to add code to the following inline functions, and call them as 65262306a36Sopenharmony_ci * needed (mostly in root hub code). 65362306a36Sopenharmony_ci */ 65462306a36Sopenharmony_ci 65562306a36Sopenharmony_ci#define ehci_is_TDI(e) (ehci_to_hcd(e)->has_tt) 65662306a36Sopenharmony_ci 65762306a36Sopenharmony_ci/* Returns the speed of a device attached to a port on the root hub. */ 65862306a36Sopenharmony_cistatic inline unsigned int 65962306a36Sopenharmony_ciehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc) 66062306a36Sopenharmony_ci{ 66162306a36Sopenharmony_ci if (ehci_is_TDI(ehci)) { 66262306a36Sopenharmony_ci switch ((portsc >> (ehci->has_hostpc ? 25 : 26)) & 3) { 66362306a36Sopenharmony_ci case 0: 66462306a36Sopenharmony_ci return 0; 66562306a36Sopenharmony_ci case 1: 66662306a36Sopenharmony_ci return USB_PORT_STAT_LOW_SPEED; 66762306a36Sopenharmony_ci case 2: 66862306a36Sopenharmony_ci default: 66962306a36Sopenharmony_ci return USB_PORT_STAT_HIGH_SPEED; 67062306a36Sopenharmony_ci } 67162306a36Sopenharmony_ci } 67262306a36Sopenharmony_ci return USB_PORT_STAT_HIGH_SPEED; 67362306a36Sopenharmony_ci} 67462306a36Sopenharmony_ci 67562306a36Sopenharmony_ci#else 67662306a36Sopenharmony_ci 67762306a36Sopenharmony_ci#define ehci_is_TDI(e) (0) 67862306a36Sopenharmony_ci 67962306a36Sopenharmony_ci#define ehci_port_speed(ehci, portsc) USB_PORT_STAT_HIGH_SPEED 68062306a36Sopenharmony_ci#endif 68162306a36Sopenharmony_ci 68262306a36Sopenharmony_ci/*-------------------------------------------------------------------------*/ 68362306a36Sopenharmony_ci 68462306a36Sopenharmony_ci#ifdef CONFIG_PPC_83xx 68562306a36Sopenharmony_ci/* Some Freescale processors have an erratum in which the TT 68662306a36Sopenharmony_ci * port number in the queue head was 0..N-1 instead of 1..N. 68762306a36Sopenharmony_ci */ 68862306a36Sopenharmony_ci#define ehci_has_fsl_portno_bug(e) ((e)->has_fsl_port_bug) 68962306a36Sopenharmony_ci#else 69062306a36Sopenharmony_ci#define ehci_has_fsl_portno_bug(e) (0) 69162306a36Sopenharmony_ci#endif 69262306a36Sopenharmony_ci 69362306a36Sopenharmony_ci#define PORTSC_FSL_PFSC 24 /* Port Force Full-Speed Connect */ 69462306a36Sopenharmony_ci 69562306a36Sopenharmony_ci#if defined(CONFIG_PPC_85xx) 69662306a36Sopenharmony_ci/* Some Freescale processors have an erratum (USB A-005275) in which 69762306a36Sopenharmony_ci * incoming packets get corrupted in HS mode 69862306a36Sopenharmony_ci */ 69962306a36Sopenharmony_ci#define ehci_has_fsl_hs_errata(e) ((e)->has_fsl_hs_errata) 70062306a36Sopenharmony_ci#else 70162306a36Sopenharmony_ci#define ehci_has_fsl_hs_errata(e) (0) 70262306a36Sopenharmony_ci#endif 70362306a36Sopenharmony_ci 70462306a36Sopenharmony_ci/* 70562306a36Sopenharmony_ci * Some Freescale/NXP processors have an erratum (USB A-005697) 70662306a36Sopenharmony_ci * in which we need to wait for 10ms for bus to enter suspend mode 70762306a36Sopenharmony_ci * after setting SUSP bit. 70862306a36Sopenharmony_ci */ 70962306a36Sopenharmony_ci#define ehci_has_fsl_susp_errata(e) ((e)->has_fsl_susp_errata) 71062306a36Sopenharmony_ci 71162306a36Sopenharmony_ci/* 71262306a36Sopenharmony_ci * Some Freescale/NXP processors using ChipIdea IP have a bug in which 71362306a36Sopenharmony_ci * disabling the port (PE is cleared) does not cause PEC to be asserted 71462306a36Sopenharmony_ci * when frame babble is detected. 71562306a36Sopenharmony_ci */ 71662306a36Sopenharmony_ci#define ehci_has_ci_pec_bug(e, portsc) \ 71762306a36Sopenharmony_ci ((e)->has_ci_pec_bug && ((e)->command & CMD_PSE) \ 71862306a36Sopenharmony_ci && !(portsc & PORT_PEC) && !(portsc & PORT_PE)) 71962306a36Sopenharmony_ci 72062306a36Sopenharmony_ci/* 72162306a36Sopenharmony_ci * While most USB host controllers implement their registers in 72262306a36Sopenharmony_ci * little-endian format, a minority (celleb companion chip) implement 72362306a36Sopenharmony_ci * them in big endian format. 72462306a36Sopenharmony_ci * 72562306a36Sopenharmony_ci * This attempts to support either format at compile time without a 72662306a36Sopenharmony_ci * runtime penalty, or both formats with the additional overhead 72762306a36Sopenharmony_ci * of checking a flag bit. 72862306a36Sopenharmony_ci * 72962306a36Sopenharmony_ci * ehci_big_endian_capbase is a special quirk for controllers that 73062306a36Sopenharmony_ci * implement the HC capability registers as separate registers and not 73162306a36Sopenharmony_ci * as fields of a 32-bit register. 73262306a36Sopenharmony_ci */ 73362306a36Sopenharmony_ci 73462306a36Sopenharmony_ci#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO 73562306a36Sopenharmony_ci#define ehci_big_endian_mmio(e) ((e)->big_endian_mmio) 73662306a36Sopenharmony_ci#define ehci_big_endian_capbase(e) ((e)->big_endian_capbase) 73762306a36Sopenharmony_ci#else 73862306a36Sopenharmony_ci#define ehci_big_endian_mmio(e) 0 73962306a36Sopenharmony_ci#define ehci_big_endian_capbase(e) 0 74062306a36Sopenharmony_ci#endif 74162306a36Sopenharmony_ci 74262306a36Sopenharmony_ci/* 74362306a36Sopenharmony_ci * Big-endian read/write functions are arch-specific. 74462306a36Sopenharmony_ci * Other arches can be added if/when they're needed. 74562306a36Sopenharmony_ci */ 74662306a36Sopenharmony_ci#if defined(CONFIG_ARM) && defined(CONFIG_ARCH_IXP4XX) 74762306a36Sopenharmony_ci#define readl_be(addr) __raw_readl((__force unsigned *)addr) 74862306a36Sopenharmony_ci#define writel_be(val, addr) __raw_writel(val, (__force unsigned *)addr) 74962306a36Sopenharmony_ci#endif 75062306a36Sopenharmony_ci 75162306a36Sopenharmony_cistatic inline unsigned int ehci_readl(const struct ehci_hcd *ehci, 75262306a36Sopenharmony_ci __u32 __iomem *regs) 75362306a36Sopenharmony_ci{ 75462306a36Sopenharmony_ci#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO 75562306a36Sopenharmony_ci return ehci_big_endian_mmio(ehci) ? 75662306a36Sopenharmony_ci readl_be(regs) : 75762306a36Sopenharmony_ci readl(regs); 75862306a36Sopenharmony_ci#else 75962306a36Sopenharmony_ci return readl(regs); 76062306a36Sopenharmony_ci#endif 76162306a36Sopenharmony_ci} 76262306a36Sopenharmony_ci 76362306a36Sopenharmony_ci#ifdef CONFIG_SOC_IMX28 76462306a36Sopenharmony_cistatic inline void imx28_ehci_writel(const unsigned int val, 76562306a36Sopenharmony_ci volatile __u32 __iomem *addr) 76662306a36Sopenharmony_ci{ 76762306a36Sopenharmony_ci __asm__ ("swp %0, %0, [%1]" : : "r"(val), "r"(addr)); 76862306a36Sopenharmony_ci} 76962306a36Sopenharmony_ci#else 77062306a36Sopenharmony_cistatic inline void imx28_ehci_writel(const unsigned int val, 77162306a36Sopenharmony_ci volatile __u32 __iomem *addr) 77262306a36Sopenharmony_ci{ 77362306a36Sopenharmony_ci} 77462306a36Sopenharmony_ci#endif 77562306a36Sopenharmony_cistatic inline void ehci_writel(const struct ehci_hcd *ehci, 77662306a36Sopenharmony_ci const unsigned int val, __u32 __iomem *regs) 77762306a36Sopenharmony_ci{ 77862306a36Sopenharmony_ci#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO 77962306a36Sopenharmony_ci ehci_big_endian_mmio(ehci) ? 78062306a36Sopenharmony_ci writel_be(val, regs) : 78162306a36Sopenharmony_ci writel(val, regs); 78262306a36Sopenharmony_ci#else 78362306a36Sopenharmony_ci if (ehci->imx28_write_fix) 78462306a36Sopenharmony_ci imx28_ehci_writel(val, regs); 78562306a36Sopenharmony_ci else 78662306a36Sopenharmony_ci writel(val, regs); 78762306a36Sopenharmony_ci#endif 78862306a36Sopenharmony_ci} 78962306a36Sopenharmony_ci 79062306a36Sopenharmony_ci/* 79162306a36Sopenharmony_ci * On certain ppc-44x SoC there is a HW issue, that could only worked around with 79262306a36Sopenharmony_ci * explicit suspend/operate of OHCI. This function hereby makes sense only on that arch. 79362306a36Sopenharmony_ci * Other common bits are dependent on has_amcc_usb23 quirk flag. 79462306a36Sopenharmony_ci */ 79562306a36Sopenharmony_ci#ifdef CONFIG_44x 79662306a36Sopenharmony_cistatic inline void set_ohci_hcfs(struct ehci_hcd *ehci, int operational) 79762306a36Sopenharmony_ci{ 79862306a36Sopenharmony_ci u32 hc_control; 79962306a36Sopenharmony_ci 80062306a36Sopenharmony_ci hc_control = (readl_be(ehci->ohci_hcctrl_reg) & ~OHCI_CTRL_HCFS); 80162306a36Sopenharmony_ci if (operational) 80262306a36Sopenharmony_ci hc_control |= OHCI_USB_OPER; 80362306a36Sopenharmony_ci else 80462306a36Sopenharmony_ci hc_control |= OHCI_USB_SUSPEND; 80562306a36Sopenharmony_ci 80662306a36Sopenharmony_ci writel_be(hc_control, ehci->ohci_hcctrl_reg); 80762306a36Sopenharmony_ci (void) readl_be(ehci->ohci_hcctrl_reg); 80862306a36Sopenharmony_ci} 80962306a36Sopenharmony_ci#else 81062306a36Sopenharmony_cistatic inline void set_ohci_hcfs(struct ehci_hcd *ehci, int operational) 81162306a36Sopenharmony_ci{ } 81262306a36Sopenharmony_ci#endif 81362306a36Sopenharmony_ci 81462306a36Sopenharmony_ci/*-------------------------------------------------------------------------*/ 81562306a36Sopenharmony_ci 81662306a36Sopenharmony_ci/* 81762306a36Sopenharmony_ci * The AMCC 440EPx not only implements its EHCI registers in big-endian 81862306a36Sopenharmony_ci * format, but also its DMA data structures (descriptors). 81962306a36Sopenharmony_ci * 82062306a36Sopenharmony_ci * EHCI controllers accessed through PCI work normally (little-endian 82162306a36Sopenharmony_ci * everywhere), so we won't bother supporting a BE-only mode for now. 82262306a36Sopenharmony_ci */ 82362306a36Sopenharmony_ci#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_DESC 82462306a36Sopenharmony_ci#define ehci_big_endian_desc(e) ((e)->big_endian_desc) 82562306a36Sopenharmony_ci 82662306a36Sopenharmony_ci/* cpu to ehci */ 82762306a36Sopenharmony_cistatic inline __hc32 cpu_to_hc32(const struct ehci_hcd *ehci, const u32 x) 82862306a36Sopenharmony_ci{ 82962306a36Sopenharmony_ci return ehci_big_endian_desc(ehci) 83062306a36Sopenharmony_ci ? (__force __hc32)cpu_to_be32(x) 83162306a36Sopenharmony_ci : (__force __hc32)cpu_to_le32(x); 83262306a36Sopenharmony_ci} 83362306a36Sopenharmony_ci 83462306a36Sopenharmony_ci/* ehci to cpu */ 83562306a36Sopenharmony_cistatic inline u32 hc32_to_cpu(const struct ehci_hcd *ehci, const __hc32 x) 83662306a36Sopenharmony_ci{ 83762306a36Sopenharmony_ci return ehci_big_endian_desc(ehci) 83862306a36Sopenharmony_ci ? be32_to_cpu((__force __be32)x) 83962306a36Sopenharmony_ci : le32_to_cpu((__force __le32)x); 84062306a36Sopenharmony_ci} 84162306a36Sopenharmony_ci 84262306a36Sopenharmony_cistatic inline u32 hc32_to_cpup(const struct ehci_hcd *ehci, const __hc32 *x) 84362306a36Sopenharmony_ci{ 84462306a36Sopenharmony_ci return ehci_big_endian_desc(ehci) 84562306a36Sopenharmony_ci ? be32_to_cpup((__force __be32 *)x) 84662306a36Sopenharmony_ci : le32_to_cpup((__force __le32 *)x); 84762306a36Sopenharmony_ci} 84862306a36Sopenharmony_ci 84962306a36Sopenharmony_ci#else 85062306a36Sopenharmony_ci 85162306a36Sopenharmony_ci/* cpu to ehci */ 85262306a36Sopenharmony_cistatic inline __hc32 cpu_to_hc32(const struct ehci_hcd *ehci, const u32 x) 85362306a36Sopenharmony_ci{ 85462306a36Sopenharmony_ci return cpu_to_le32(x); 85562306a36Sopenharmony_ci} 85662306a36Sopenharmony_ci 85762306a36Sopenharmony_ci/* ehci to cpu */ 85862306a36Sopenharmony_cistatic inline u32 hc32_to_cpu(const struct ehci_hcd *ehci, const __hc32 x) 85962306a36Sopenharmony_ci{ 86062306a36Sopenharmony_ci return le32_to_cpu(x); 86162306a36Sopenharmony_ci} 86262306a36Sopenharmony_ci 86362306a36Sopenharmony_cistatic inline u32 hc32_to_cpup(const struct ehci_hcd *ehci, const __hc32 *x) 86462306a36Sopenharmony_ci{ 86562306a36Sopenharmony_ci return le32_to_cpup(x); 86662306a36Sopenharmony_ci} 86762306a36Sopenharmony_ci 86862306a36Sopenharmony_ci#endif 86962306a36Sopenharmony_ci 87062306a36Sopenharmony_ci/*-------------------------------------------------------------------------*/ 87162306a36Sopenharmony_ci 87262306a36Sopenharmony_ci#define ehci_dbg(ehci, fmt, args...) \ 87362306a36Sopenharmony_ci dev_dbg(ehci_to_hcd(ehci)->self.controller, fmt, ## args) 87462306a36Sopenharmony_ci#define ehci_err(ehci, fmt, args...) \ 87562306a36Sopenharmony_ci dev_err(ehci_to_hcd(ehci)->self.controller, fmt, ## args) 87662306a36Sopenharmony_ci#define ehci_info(ehci, fmt, args...) \ 87762306a36Sopenharmony_ci dev_info(ehci_to_hcd(ehci)->self.controller, fmt, ## args) 87862306a36Sopenharmony_ci#define ehci_warn(ehci, fmt, args...) \ 87962306a36Sopenharmony_ci dev_warn(ehci_to_hcd(ehci)->self.controller, fmt, ## args) 88062306a36Sopenharmony_ci 88162306a36Sopenharmony_ci/*-------------------------------------------------------------------------*/ 88262306a36Sopenharmony_ci 88362306a36Sopenharmony_ci/* Declarations of things exported for use by ehci platform drivers */ 88462306a36Sopenharmony_ci 88562306a36Sopenharmony_cistruct ehci_driver_overrides { 88662306a36Sopenharmony_ci size_t extra_priv_size; 88762306a36Sopenharmony_ci int (*reset)(struct usb_hcd *hcd); 88862306a36Sopenharmony_ci int (*port_power)(struct usb_hcd *hcd, 88962306a36Sopenharmony_ci int portnum, bool enable); 89062306a36Sopenharmony_ci}; 89162306a36Sopenharmony_ci 89262306a36Sopenharmony_ciextern void ehci_init_driver(struct hc_driver *drv, 89362306a36Sopenharmony_ci const struct ehci_driver_overrides *over); 89462306a36Sopenharmony_ciextern int ehci_setup(struct usb_hcd *hcd); 89562306a36Sopenharmony_ciextern int ehci_handshake(struct ehci_hcd *ehci, void __iomem *ptr, 89662306a36Sopenharmony_ci u32 mask, u32 done, int usec); 89762306a36Sopenharmony_ciextern int ehci_reset(struct ehci_hcd *ehci); 89862306a36Sopenharmony_ci 89962306a36Sopenharmony_ciextern int ehci_suspend(struct usb_hcd *hcd, bool do_wakeup); 90062306a36Sopenharmony_ciextern int ehci_resume(struct usb_hcd *hcd, bool force_reset); 90162306a36Sopenharmony_ciextern void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci, 90262306a36Sopenharmony_ci bool suspending, bool do_wakeup); 90362306a36Sopenharmony_ci 90462306a36Sopenharmony_ciextern int ehci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, 90562306a36Sopenharmony_ci u16 wIndex, char *buf, u16 wLength); 90662306a36Sopenharmony_ci 90762306a36Sopenharmony_ci#endif /* __LINUX_EHCI_HCD_H */ 908