13e45ed3cSNishad Kamdar /* SPDX-License-Identifier: GPL-2.0+ */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * Copyright (c) 2001-2002 by David Brownell
41da177e4SLinus Torvalds */
51da177e4SLinus Torvalds
61da177e4SLinus Torvalds #ifndef __LINUX_EHCI_HCD_H
71da177e4SLinus Torvalds #define __LINUX_EHCI_HCD_H
81da177e4SLinus Torvalds
91da177e4SLinus Torvalds /* definitions used for the EHCI driver */
101da177e4SLinus Torvalds
116dbd682bSStefan Roese /*
126dbd682bSStefan Roese * __hc32 and __hc16 are "Host Controller" types, they may be equivalent to
136dbd682bSStefan Roese * __leXX (normally) or __beXX (given EHCI_BIG_ENDIAN_DESC), depending on
146dbd682bSStefan Roese * the host controller implementation.
156dbd682bSStefan Roese *
166dbd682bSStefan Roese * To facilitate the strongest possible byte-order checking from "sparse"
176dbd682bSStefan Roese * and so on, we use __leXX unless that's not practical.
186dbd682bSStefan Roese */
196dbd682bSStefan Roese #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_DESC
206dbd682bSStefan Roese typedef __u32 __bitwise __hc32;
216dbd682bSStefan Roese typedef __u16 __bitwise __hc16;
226dbd682bSStefan Roese #else
236dbd682bSStefan Roese #define __hc32 __le32
246dbd682bSStefan Roese #define __hc16 __le16
256dbd682bSStefan Roese #endif
266dbd682bSStefan Roese
27411c9403SAnand Gadiyar /* statistics can be kept for tuning/monitoring */
281c20163dSOliver Neukum #ifdef CONFIG_DYNAMIC_DEBUG
299ec6e9d3SRoger Quadros #define EHCI_STATS
309ec6e9d3SRoger Quadros #endif
319ec6e9d3SRoger Quadros
321da177e4SLinus Torvalds struct ehci_stats {
331da177e4SLinus Torvalds /* irq usage */
341da177e4SLinus Torvalds unsigned long normal;
351da177e4SLinus Torvalds unsigned long error;
3699ac5b1eSAlan Stern unsigned long iaa;
371da177e4SLinus Torvalds unsigned long lost_iaa;
381da177e4SLinus Torvalds
391da177e4SLinus Torvalds /* termination of urbs from core */
401da177e4SLinus Torvalds unsigned long complete;
411da177e4SLinus Torvalds unsigned long unlink;
421da177e4SLinus Torvalds };
431da177e4SLinus Torvalds
44ffa0248eSAlan Stern /*
45ffa0248eSAlan Stern * Scheduling and budgeting information for periodic transfers, for both
46ffa0248eSAlan Stern * high-speed devices and full/low-speed devices lying behind a TT.
47ffa0248eSAlan Stern */
48ffa0248eSAlan Stern struct ehci_per_sched {
49ffa0248eSAlan Stern struct usb_device *udev; /* access to the TT */
50ffa0248eSAlan Stern struct usb_host_endpoint *ep;
51b35c5009SAlan Stern struct list_head ps_list; /* node on ehci_tt's ps_list */
52ffa0248eSAlan Stern u16 tt_usecs; /* time on the FS/LS bus */
53d0ce5c6bSAlan Stern u16 cs_mask; /* C-mask and S-mask bytes */
54ffa0248eSAlan Stern u16 period; /* actual period in frames */
55ffa0248eSAlan Stern u16 phase; /* actual phase, frame part */
56d0ce5c6bSAlan Stern u8 bw_phase; /* same, for bandwidth
57d0ce5c6bSAlan Stern reservation */
58ffa0248eSAlan Stern u8 phase_uf; /* uframe part of the phase */
59ffa0248eSAlan Stern u8 usecs, c_usecs; /* times on the HS bus */
60d0ce5c6bSAlan Stern u8 bw_uperiod; /* period in microframes, for
61d0ce5c6bSAlan Stern bandwidth reservation */
62d0ce5c6bSAlan Stern u8 bw_period; /* same, in frames */
63ffa0248eSAlan Stern };
6491a99b5eSAlan Stern #define NO_FRAME 29999 /* frame not assigned yet */
6591a99b5eSAlan Stern
661da177e4SLinus Torvalds /* ehci_hcd->lock guards shared data against other CPUs:
6799ac5b1eSAlan Stern * ehci_hcd: async, unlink, periodic (and shadow), ...
681da177e4SLinus Torvalds * usb_host_endpoint: hcpriv
691da177e4SLinus Torvalds * ehci_qh: qh_next, qtd_list
701da177e4SLinus Torvalds * ehci_qtd: qtd_list
711da177e4SLinus Torvalds *
721da177e4SLinus Torvalds * Also, hold this lock when talking to HC registers or
731da177e4SLinus Torvalds * when updating hw_* fields in shared qh/qtd/... structures.
741da177e4SLinus Torvalds */
751da177e4SLinus Torvalds
761da177e4SLinus Torvalds #define EHCI_MAX_ROOT_PORTS 15 /* see HCS_N_PORTS */
771da177e4SLinus Torvalds
78c0c53dbcSAlan Stern /*
79c0c53dbcSAlan Stern * ehci_rh_state values of EHCI_RH_RUNNING or above mean that the
80c0c53dbcSAlan Stern * controller may be doing DMA. Lower values mean there's no DMA.
81c0c53dbcSAlan Stern */
82e8799906SAlan Stern enum ehci_rh_state {
83e8799906SAlan Stern EHCI_RH_HALTED,
84e8799906SAlan Stern EHCI_RH_SUSPENDED,
85c0c53dbcSAlan Stern EHCI_RH_RUNNING,
86c0c53dbcSAlan Stern EHCI_RH_STOPPING
87e8799906SAlan Stern };
88e8799906SAlan Stern
89d58b4bccSAlan Stern /*
90d58b4bccSAlan Stern * Timer events, ordered by increasing delay length.
91d58b4bccSAlan Stern * Always update event_delays_ns[] and event_handlers[] (defined in
92d58b4bccSAlan Stern * ehci-timer.c) in parallel with this list.
93d58b4bccSAlan Stern */
94d58b4bccSAlan Stern enum ehci_hrtimer_event {
9531446610SAlan Stern EHCI_HRTIMER_POLL_ASS, /* Poll for async schedule off */
963ca9aebaSAlan Stern EHCI_HRTIMER_POLL_PSS, /* Poll for periodic schedule off */
97bf6387bcSAlan Stern EHCI_HRTIMER_POLL_DEAD, /* Wait for dead controller to stop */
98df202255SAlan Stern EHCI_HRTIMER_UNLINK_INTR, /* Wait for interrupt QH unlink */
9955934eb3SAlan Stern EHCI_HRTIMER_FREE_ITDS, /* Wait for unused iTDs and siTDs */
10087d61912SAlan Stern EHCI_HRTIMER_ACTIVE_UNLINK, /* Wait while unlinking an active QH */
1019118f9ebSMing Lei EHCI_HRTIMER_START_UNLINK_INTR, /* Unlink empty interrupt QHs */
10232830f20SAlan Stern EHCI_HRTIMER_ASYNC_UNLINKS, /* Unlink empty async QHs */
1039d938747SAlan Stern EHCI_HRTIMER_IAA_WATCHDOG, /* Handle lost IAA interrupts */
1043ca9aebaSAlan Stern EHCI_HRTIMER_DISABLE_PERIODIC, /* Wait to disable periodic sched */
10531446610SAlan Stern EHCI_HRTIMER_DISABLE_ASYNC, /* Wait to disable async sched */
10618aafe64SAlan Stern EHCI_HRTIMER_IO_WATCHDOG, /* Check for missing IRQs */
107d58b4bccSAlan Stern EHCI_HRTIMER_NUM_EVENTS /* Must come last */
108d58b4bccSAlan Stern };
109d58b4bccSAlan Stern #define EHCI_HRTIMER_NO_EVENT 99
110d58b4bccSAlan Stern
1111da177e4SLinus Torvalds struct ehci_hcd { /* one per controller */
112d58b4bccSAlan Stern /* timing support */
113d58b4bccSAlan Stern enum ehci_hrtimer_event next_hrtimer_event;
114d58b4bccSAlan Stern unsigned enabled_hrtimer_events;
115d58b4bccSAlan Stern ktime_t hr_timeouts[EHCI_HRTIMER_NUM_EVENTS];
116d58b4bccSAlan Stern struct hrtimer hrtimer;
117d58b4bccSAlan Stern
1183ca9aebaSAlan Stern int PSS_poll_count;
11931446610SAlan Stern int ASS_poll_count;
120bf6387bcSAlan Stern int died_poll_count;
1213ca9aebaSAlan Stern
12256c1e26dSDavid Brownell /* glue to PCI and HCD framework */
12356c1e26dSDavid Brownell struct ehci_caps __iomem *caps;
12456c1e26dSDavid Brownell struct ehci_regs __iomem *regs;
12556c1e26dSDavid Brownell struct ehci_dbg_port __iomem *debug;
12656c1e26dSDavid Brownell
12756c1e26dSDavid Brownell __u32 hcs_params; /* cached register copy */
1281da177e4SLinus Torvalds spinlock_t lock;
129e8799906SAlan Stern enum ehci_rh_state rh_state;
1301da177e4SLinus Torvalds
131df202255SAlan Stern /* general schedule support */
132361aabf3SAlan Stern bool scanning:1;
133361aabf3SAlan Stern bool need_rescan:1;
134df202255SAlan Stern bool intr_unlinking:1;
135214ac7a0SAlan Stern bool iaa_in_progress:1;
1363c273a05SAlan Stern bool async_unlinking:1;
13743fe3a99SAlan Stern bool shutdown:1;
138569b394fSAlan Stern struct ehci_qh *qh_scan_next;
139df202255SAlan Stern
1401da177e4SLinus Torvalds /* async schedule support */
1411da177e4SLinus Torvalds struct ehci_qh *async;
1423d091a6fSAndiry Xu struct ehci_qh *dummy; /* For AMD quirk use */
1436e018751SAlan Stern struct list_head async_unlink;
144214ac7a0SAlan Stern struct list_head async_idle;
14532830f20SAlan Stern unsigned async_unlink_cycle;
14631446610SAlan Stern unsigned async_count; /* async activity count */
14787d61912SAlan Stern __hc32 old_current; /* Test for QH becoming */
14887d61912SAlan Stern __hc32 old_token; /* inactive during unlink */
1491da177e4SLinus Torvalds
1501da177e4SLinus Torvalds /* periodic schedule support */
1511da177e4SLinus Torvalds #define DEFAULT_I_TDPS 1024 /* some HCs can do less */
1521da177e4SLinus Torvalds unsigned periodic_size;
1536dbd682bSStefan Roese __hc32 *periodic; /* hw periodic table */
1541da177e4SLinus Torvalds dma_addr_t periodic_dma;
155569b394fSAlan Stern struct list_head intr_qh_list;
1561da177e4SLinus Torvalds unsigned i_thresh; /* uframes HC might cache */
1571da177e4SLinus Torvalds
1581da177e4SLinus Torvalds union ehci_shadow *pshadow; /* mirror hw periodic table */
1599118f9ebSMing Lei struct list_head intr_unlink_wait;
1606e018751SAlan Stern struct list_head intr_unlink;
1619118f9ebSMing Lei unsigned intr_unlink_wait_cycle;
162df202255SAlan Stern unsigned intr_unlink_cycle;
163f4289078SAlan Stern unsigned now_frame; /* frame from HC hardware */
164c3ee9b76SAlan Stern unsigned last_iso_frame; /* last frame scanned for iso */
165569b394fSAlan Stern unsigned intr_count; /* intr activity count */
166569b394fSAlan Stern unsigned isoc_count; /* isoc activity count */
1673ca9aebaSAlan Stern unsigned periodic_count; /* periodic activity count */
168cc62a7ebSKirill Smelkov unsigned uframe_periodic_max; /* max periodic time per uframe */
169cc62a7ebSKirill Smelkov
1701da177e4SLinus Torvalds
171f4289078SAlan Stern /* list of itds & sitds completed while now_frame was still active */
1729aa09d2fSKarsten Wiese struct list_head cached_itd_list;
17355934eb3SAlan Stern struct ehci_itd *last_itd_to_free;
1740e5f231bSAlan Stern struct list_head cached_sitd_list;
17555934eb3SAlan Stern struct ehci_sitd *last_sitd_to_free;
1769aa09d2fSKarsten Wiese
1771da177e4SLinus Torvalds /* per root hub port */
1781da177e4SLinus Torvalds unsigned long reset_done[EHCI_MAX_ROOT_PORTS];
179383975d7SAlan Stern
18057e06c11SAlan Stern /* bit vectors (one bit per port) */
18157e06c11SAlan Stern unsigned long bus_suspended; /* which ports were
18257e06c11SAlan Stern already suspended at the start of a bus suspend */
18357e06c11SAlan Stern unsigned long companion_ports; /* which ports are
18457e06c11SAlan Stern dedicated to the companion controller */
185383975d7SAlan Stern unsigned long owned_ports; /* which ports are
186383975d7SAlan Stern owned by the companion during a bus suspend */
187d1f114d1SAlan Stern unsigned long port_c_suspend; /* which ports have
188d1f114d1SAlan Stern the change-suspend feature turned on */
189eafe5b99SAlan Stern unsigned long suspended_ports; /* which ports are
190eafe5b99SAlan Stern suspended */
191a448e4dcSAlan Stern unsigned long resuming_ports; /* which ports have
192a448e4dcSAlan Stern started to resume */
1931da177e4SLinus Torvalds
1941da177e4SLinus Torvalds /* per-HC memory pools (could be per-bus, but ...) */
1951da177e4SLinus Torvalds struct dma_pool *qh_pool; /* qh per active urb */
1961da177e4SLinus Torvalds struct dma_pool *qtd_pool; /* one or more per qh */
1971da177e4SLinus Torvalds struct dma_pool *itd_pool; /* itd per iso urb */
1981da177e4SLinus Torvalds struct dma_pool *sitd_pool; /* sitd per split iso urb */
1991da177e4SLinus Torvalds
20068335e81SAlan Stern unsigned random_frame;
2011da177e4SLinus Torvalds unsigned long next_statechange;
202ee4ecb8aSOliver Neukum ktime_t last_periodic_enable;
2031da177e4SLinus Torvalds u32 command;
2041da177e4SLinus Torvalds
2058cd42e97SKumar Gala /* SILICON QUIRKS */
206f8aeb3bbSDavid Brownell unsigned no_selective_suspend:1;
2078cd42e97SKumar Gala unsigned has_fsl_port_bug:1; /* FreeScale */
208f8786a91SNikhil Badola unsigned has_fsl_hs_errata:1; /* Freescale HS quirk */
2099d4b8270SChangming Huang unsigned has_fsl_susp_errata:1; /* NXP SUSP quirk */
210*dda4b60eSXu Yang unsigned has_ci_pec_bug:1; /* ChipIdea PEC bug */
211083522d7SBenjamin Herrenschmidt unsigned big_endian_mmio:1;
2126dbd682bSStefan Roese unsigned big_endian_desc:1;
213c430131aSJan Andersson unsigned big_endian_capbase:1;
214796bcae7SVitaly Bordug unsigned has_amcc_usb23:1;
215403dbd36SAlek Du unsigned need_io_watchdog:1;
216ad93562bSAndiry Xu unsigned amd_pll_fix:1;
2173d091a6fSAndiry Xu unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/
2182f7ac6c1SGabor Juhos unsigned has_synopsys_hc_bug:1; /* Synopsys HC */
21968aa95d5SAlan Stern unsigned frame_index_bug:1; /* MosChip (AKA NetMos) */
220e6604a7fSChristian Engelmayer unsigned need_oc_pp_cycle:1; /* MPC834X port power */
221feffe09fSPeter Chen unsigned imx28_write_fix:1; /* For Freescale i.MX28 */
2222d5ba374SFlorian Fainelli unsigned spurious_oc:1;
2237f2d7378SNeal Liu unsigned is_aspeed:1;
224f085bd4bSWeitao Wango unsigned zx_wakeup_clear_needed:1;
225796bcae7SVitaly Bordug
226796bcae7SVitaly Bordug /* required for usb32 quirk */
227796bcae7SVitaly Bordug #define OHCI_CTRL_HCFS (3 << 6)
228796bcae7SVitaly Bordug #define OHCI_USB_OPER (2 << 6)
229796bcae7SVitaly Bordug #define OHCI_USB_SUSPEND (3 << 6)
230796bcae7SVitaly Bordug
231796bcae7SVitaly Bordug #define OHCI_HCCTRL_OFFSET 0x4
232796bcae7SVitaly Bordug #define OHCI_HCCTRL_LEN 0x4
233796bcae7SVitaly Bordug __hc32 *ohci_hcctrl_reg;
234331ac6b2SAlek Du unsigned has_hostpc:1;
2352cdcec4fSTuomas Tynkkynen unsigned has_tdi_phy_lpm:1;
2365a9cdf33SAlek Du unsigned has_ppcd:1; /* support per-port change bits */
237f8aeb3bbSDavid Brownell u8 sbrn; /* packed release number */
2381da177e4SLinus Torvalds
2391da177e4SLinus Torvalds /* irq statistics */
2401da177e4SLinus Torvalds #ifdef EHCI_STATS
2411da177e4SLinus Torvalds struct ehci_stats stats;
242a0ef2bdfSCorentin Labbe # define INCR(x) ((x)++)
2431da177e4SLinus Torvalds #else
244a0ef2bdfSCorentin Labbe # define INCR(x) do {} while (0)
2451da177e4SLinus Torvalds #endif
246694cc208STony Jones
247694cc208STony Jones /* debug files */
2481c20163dSOliver Neukum #ifdef CONFIG_DYNAMIC_DEBUG
249694cc208STony Jones struct dentry *debug_dir;
250694cc208STony Jones #endif
2519debc179SAlan Stern
252d0ce5c6bSAlan Stern /* bandwidth usage */
253d0ce5c6bSAlan Stern #define EHCI_BANDWIDTH_SIZE 64
254d0ce5c6bSAlan Stern #define EHCI_BANDWIDTH_FRAMES (EHCI_BANDWIDTH_SIZE >> 3)
255d0ce5c6bSAlan Stern u8 bandwidth[EHCI_BANDWIDTH_SIZE];
256d0ce5c6bSAlan Stern /* us allocated per uframe */
257b35c5009SAlan Stern u8 tt_budget[EHCI_BANDWIDTH_SIZE];
258b35c5009SAlan Stern /* us budgeted per uframe */
259b35c5009SAlan Stern struct list_head tt_list;
260d0ce5c6bSAlan Stern
2619debc179SAlan Stern /* platform-specific data -- must come last */
2626bc3f397SGustavo A. R. Silva unsigned long priv[] __aligned(sizeof(s64));
2631da177e4SLinus Torvalds };
2641da177e4SLinus Torvalds
2651da177e4SLinus Torvalds /* convert between an HCD pointer and the corresponding EHCI_HCD */
hcd_to_ehci(struct usb_hcd * hcd)2661da177e4SLinus Torvalds static inline struct ehci_hcd *hcd_to_ehci(struct usb_hcd *hcd)
2671da177e4SLinus Torvalds {
2681da177e4SLinus Torvalds return (struct ehci_hcd *) (hcd->hcd_priv);
2691da177e4SLinus Torvalds }
ehci_to_hcd(struct ehci_hcd * ehci)2701da177e4SLinus Torvalds static inline struct usb_hcd *ehci_to_hcd(struct ehci_hcd *ehci)
2711da177e4SLinus Torvalds {
2721da177e4SLinus Torvalds return container_of((void *) ehci, struct usb_hcd, hcd_priv);
2731da177e4SLinus Torvalds }
2741da177e4SLinus Torvalds
2751da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
2761da177e4SLinus Torvalds
2770af36739SYinghai Lu #include <linux/usb/ehci_def.h>
2781da177e4SLinus Torvalds
2791da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
2801da177e4SLinus Torvalds
2816dbd682bSStefan Roese #define QTD_NEXT(ehci, dma) cpu_to_hc32(ehci, (u32)dma)
2821da177e4SLinus Torvalds
2831da177e4SLinus Torvalds /*
2841da177e4SLinus Torvalds * EHCI Specification 0.95 Section 3.5
2851da177e4SLinus Torvalds * QTD: describe data transfer components (buffer, direction, ...)
2861da177e4SLinus Torvalds * See Fig 3-6 "Queue Element Transfer Descriptor Block Diagram".
2871da177e4SLinus Torvalds *
2881da177e4SLinus Torvalds * These are associated only with "QH" (Queue Head) structures,
2891da177e4SLinus Torvalds * used with control, bulk, and interrupt transfers.
2901da177e4SLinus Torvalds */
2911da177e4SLinus Torvalds struct ehci_qtd {
2921da177e4SLinus Torvalds /* first part defined by EHCI spec */
2936dbd682bSStefan Roese __hc32 hw_next; /* see EHCI 3.5.1 */
2946dbd682bSStefan Roese __hc32 hw_alt_next; /* see EHCI 3.5.2 */
2956dbd682bSStefan Roese __hc32 hw_token; /* see EHCI 3.5.3 */
2961da177e4SLinus Torvalds #define QTD_TOGGLE (1 << 31) /* data toggle */
2971da177e4SLinus Torvalds #define QTD_LENGTH(tok) (((tok)>>16) & 0x7fff)
2981da177e4SLinus Torvalds #define QTD_IOC (1 << 15) /* interrupt on complete */
2991da177e4SLinus Torvalds #define QTD_CERR(tok) (((tok)>>10) & 0x3)
3001da177e4SLinus Torvalds #define QTD_PID(tok) (((tok)>>8) & 0x3)
3011da177e4SLinus Torvalds #define QTD_STS_ACTIVE (1 << 7) /* HC may execute this */
3021da177e4SLinus Torvalds #define QTD_STS_HALT (1 << 6) /* halted on error */
3031da177e4SLinus Torvalds #define QTD_STS_DBE (1 << 5) /* data buffer error (in HC) */
3041da177e4SLinus Torvalds #define QTD_STS_BABBLE (1 << 4) /* device was babbling (qtd halted) */
3051da177e4SLinus Torvalds #define QTD_STS_XACT (1 << 3) /* device gave illegal response */
3061da177e4SLinus Torvalds #define QTD_STS_MMF (1 << 2) /* incomplete split transaction */
3071da177e4SLinus Torvalds #define QTD_STS_STS (1 << 1) /* split transaction state */
3081da177e4SLinus Torvalds #define QTD_STS_PING (1 << 0) /* issue PING? */
3096dbd682bSStefan Roese
3106dbd682bSStefan Roese #define ACTIVE_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_ACTIVE)
3116dbd682bSStefan Roese #define HALT_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_HALT)
3126dbd682bSStefan Roese #define STATUS_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_STS)
3136dbd682bSStefan Roese
3146dbd682bSStefan Roese __hc32 hw_buf[5]; /* see EHCI 3.5.4 */
3156dbd682bSStefan Roese __hc32 hw_buf_hi[5]; /* Appendix B */
3161da177e4SLinus Torvalds
3171da177e4SLinus Torvalds /* the rest is HCD-private */
3181da177e4SLinus Torvalds dma_addr_t qtd_dma; /* qtd address */
3191da177e4SLinus Torvalds struct list_head qtd_list; /* sw qtd list */
3201da177e4SLinus Torvalds struct urb *urb; /* qtd's urb */
3211da177e4SLinus Torvalds size_t length; /* length of buffer */
3223a9e742fSGeyslan G. Bem } __aligned(32);
3231da177e4SLinus Torvalds
3241da177e4SLinus Torvalds /* mask NakCnt+T in qh->hw_alt_next */
3256dbd682bSStefan Roese #define QTD_MASK(ehci) cpu_to_hc32(ehci, ~0x1f)
3261da177e4SLinus Torvalds
3271da177e4SLinus Torvalds #define IS_SHORT_READ(token) (QTD_LENGTH(token) != 0 && QTD_PID(token) == 1)
3281da177e4SLinus Torvalds
3291da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
3301da177e4SLinus Torvalds
3311da177e4SLinus Torvalds /* type tag from {qh,itd,sitd,fstn}->hw_next */
3326dbd682bSStefan Roese #define Q_NEXT_TYPE(ehci, dma) ((dma) & cpu_to_hc32(ehci, 3 << 1))
3331da177e4SLinus Torvalds
3346dbd682bSStefan Roese /*
3356dbd682bSStefan Roese * Now the following defines are not converted using the
336551509d2SHarvey Harrison * cpu_to_le32() macro anymore, since we have to support
3376dbd682bSStefan Roese * "dynamic" switching between be and le support, so that the driver
3386dbd682bSStefan Roese * can be used on one system with SoC EHCI controller using big-endian
3396dbd682bSStefan Roese * descriptors as well as a normal little-endian PCI EHCI controller.
3406dbd682bSStefan Roese */
3411da177e4SLinus Torvalds /* values for that type tag */
3426dbd682bSStefan Roese #define Q_TYPE_ITD (0 << 1)
3436dbd682bSStefan Roese #define Q_TYPE_QH (1 << 1)
3446dbd682bSStefan Roese #define Q_TYPE_SITD (2 << 1)
3456dbd682bSStefan Roese #define Q_TYPE_FSTN (3 << 1)
3461da177e4SLinus Torvalds
3471da177e4SLinus Torvalds /* next async queue entry, or pointer to interrupt/periodic QH */
34810f2b962SGeyslan G. Bem #define QH_NEXT(ehci, dma) \
34910f2b962SGeyslan G. Bem (cpu_to_hc32(ehci, (((u32) dma) & ~0x01f) | Q_TYPE_QH))
3501da177e4SLinus Torvalds
3511da177e4SLinus Torvalds /* for periodic/async schedules and qtd lists, mark end of list */
3526dbd682bSStefan Roese #define EHCI_LIST_END(ehci) cpu_to_hc32(ehci, 1) /* "null pointer" to hw */
3531da177e4SLinus Torvalds
3541da177e4SLinus Torvalds /*
3551da177e4SLinus Torvalds * Entries in periodic shadow table are pointers to one of four kinds
3561da177e4SLinus Torvalds * of data structure. That's dictated by the hardware; a type tag is
3571da177e4SLinus Torvalds * encoded in the low bits of the hardware's periodic schedule. Use
3581da177e4SLinus Torvalds * Q_NEXT_TYPE to get the tag.
3591da177e4SLinus Torvalds *
3601da177e4SLinus Torvalds * For entries in the async schedule, the type tag always says "qh".
3611da177e4SLinus Torvalds */
3621da177e4SLinus Torvalds union ehci_shadow {
3631da177e4SLinus Torvalds struct ehci_qh *qh; /* Q_TYPE_QH */
3641da177e4SLinus Torvalds struct ehci_itd *itd; /* Q_TYPE_ITD */
3651da177e4SLinus Torvalds struct ehci_sitd *sitd; /* Q_TYPE_SITD */
3661da177e4SLinus Torvalds struct ehci_fstn *fstn; /* Q_TYPE_FSTN */
3676dbd682bSStefan Roese __hc32 *hw_next; /* (all types) */
3681da177e4SLinus Torvalds void *ptr;
3691da177e4SLinus Torvalds };
3701da177e4SLinus Torvalds
3711da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
3721da177e4SLinus Torvalds
3731da177e4SLinus Torvalds /*
3741da177e4SLinus Torvalds * EHCI Specification 0.95 Section 3.6
3751da177e4SLinus Torvalds * QH: describes control/bulk/interrupt endpoints
3761da177e4SLinus Torvalds * See Fig 3-7 "Queue Head Structure Layout".
3771da177e4SLinus Torvalds *
3781da177e4SLinus Torvalds * These appear in both the async and (for interrupt) periodic schedules.
3791da177e4SLinus Torvalds */
3801da177e4SLinus Torvalds
3811da177e4SLinus Torvalds /* first part defined by EHCI spec */
3823807e26dSAlek Du struct ehci_qh_hw {
3836dbd682bSStefan Roese __hc32 hw_next; /* see EHCI 3.6.1 */
3846dbd682bSStefan Roese __hc32 hw_info1; /* see EHCI 3.6.2 */
3854c53de72SAlan Stern #define QH_CONTROL_EP (1 << 27) /* FS/LS control endpoint */
3864c53de72SAlan Stern #define QH_HEAD (1 << 15) /* Head of async reclamation list */
3874c53de72SAlan Stern #define QH_TOGGLE_CTL (1 << 14) /* Data toggle control */
3884c53de72SAlan Stern #define QH_HIGH_SPEED (2 << 12) /* Endpoint speed */
3894c53de72SAlan Stern #define QH_LOW_SPEED (1 << 12)
3904c53de72SAlan Stern #define QH_FULL_SPEED (0 << 12)
3914c53de72SAlan Stern #define QH_INACTIVATE (1 << 7) /* Inactivate on next transaction */
3926dbd682bSStefan Roese __hc32 hw_info2; /* see EHCI 3.6.2 */
3937dedacf4SDavid Brownell #define QH_SMASK 0x000000ff
3947dedacf4SDavid Brownell #define QH_CMASK 0x0000ff00
3957dedacf4SDavid Brownell #define QH_HUBADDR 0x007f0000
3967dedacf4SDavid Brownell #define QH_HUBPORT 0x3f800000
3977dedacf4SDavid Brownell #define QH_MULT 0xc0000000
3986dbd682bSStefan Roese __hc32 hw_current; /* qtd list - see EHCI 3.6.4 */
3991da177e4SLinus Torvalds
4001da177e4SLinus Torvalds /* qtd overlay (hardware parts of a struct ehci_qtd) */
4016dbd682bSStefan Roese __hc32 hw_qtd_next;
4026dbd682bSStefan Roese __hc32 hw_alt_next;
4036dbd682bSStefan Roese __hc32 hw_token;
4046dbd682bSStefan Roese __hc32 hw_buf[5];
4056dbd682bSStefan Roese __hc32 hw_buf_hi[5];
4063a9e742fSGeyslan G. Bem } __aligned(32);
4071da177e4SLinus Torvalds
4083807e26dSAlek Du struct ehci_qh {
4098c5bf7beSAlan Stern struct ehci_qh_hw *hw; /* Must come first */
4101da177e4SLinus Torvalds /* the rest is HCD-private */
4111da177e4SLinus Torvalds dma_addr_t qh_dma; /* address of qh */
4121da177e4SLinus Torvalds union ehci_shadow qh_next; /* ptr to qh; or periodic */
4131da177e4SLinus Torvalds struct list_head qtd_list; /* sw qtd list */
414569b394fSAlan Stern struct list_head intr_node; /* list of intr QHs */
4151da177e4SLinus Torvalds struct ehci_qtd *dummy;
4166e018751SAlan Stern struct list_head unlink_node;
417ffa0248eSAlan Stern struct ehci_per_sched ps; /* scheduling info */
4181da177e4SLinus Torvalds
419df202255SAlan Stern unsigned unlink_cycle;
4201da177e4SLinus Torvalds
4211da177e4SLinus Torvalds u8 qh_state;
4221da177e4SLinus Torvalds #define QH_STATE_LINKED 1 /* HC sees this */
4231da177e4SLinus Torvalds #define QH_STATE_UNLINK 2 /* HC may still see this */
4241da177e4SLinus Torvalds #define QH_STATE_IDLE 3 /* HC doesn't see this */
42599ac5b1eSAlan Stern #define QH_STATE_UNLINK_WAIT 4 /* LINKED and on unlink q */
4261da177e4SLinus Torvalds #define QH_STATE_COMPLETING 5 /* don't touch token.HALT */
4271da177e4SLinus Torvalds
428a2c2706eSAlan Stern u8 xacterrs; /* XactErr retry counter */
429a2c2706eSAlan Stern #define QH_XACTERR_MAX 32 /* XactErr retry limit */
430a2c2706eSAlan Stern
431fcc5184eSAlan Stern u8 unlink_reason;
432fcc5184eSAlan Stern #define QH_UNLINK_HALTED 0x01 /* Halt flag is set */
433fcc5184eSAlan Stern #define QH_UNLINK_SHORT_READ 0x02 /* Recover from a short read */
434fcc5184eSAlan Stern #define QH_UNLINK_DUMMY_OVERLAY 0x04 /* QH overlayed the dummy TD */
435fcc5184eSAlan Stern #define QH_UNLINK_SHUTDOWN 0x08 /* The HC isn't running */
436fcc5184eSAlan Stern #define QH_UNLINK_QUEUE_EMPTY 0x10 /* Reached end of the queue */
437fcc5184eSAlan Stern #define QH_UNLINK_REQUESTED 0x20 /* Disable, reset, or dequeue */
438fcc5184eSAlan Stern
4391da177e4SLinus Torvalds u8 gap_uf; /* uframes split/csplit gap */
440914b7012SAlan Stern
441e04f5f7eSAlan Stern unsigned is_out:1; /* bulk or intr OUT */
442914b7012SAlan Stern unsigned clearing_tt:1; /* Clear-TT-Buf in progress */
4437bc782d7SAlan Stern unsigned dequeue_during_giveback:1;
444fc0855f2SAlan Stern unsigned should_be_inactive:1;
4453807e26dSAlek Du };
4461da177e4SLinus Torvalds
4471da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
4481da177e4SLinus Torvalds
4491da177e4SLinus Torvalds /* description of one iso transaction (up to 3 KB data if highspeed) */
4501da177e4SLinus Torvalds struct ehci_iso_packet {
4511da177e4SLinus Torvalds /* These will be copied to iTD when scheduling */
4521da177e4SLinus Torvalds u64 bufp; /* itd->hw_bufp{,_hi}[pg] |= */
4536dbd682bSStefan Roese __hc32 transaction; /* itd->hw_transaction[i] |= */
4541da177e4SLinus Torvalds u8 cross; /* buf crosses pages */
4551da177e4SLinus Torvalds /* for full speed OUT splits */
4561da177e4SLinus Torvalds u32 buf1;
4571da177e4SLinus Torvalds };
4581da177e4SLinus Torvalds
4591da177e4SLinus Torvalds /* temporary schedule data for packets from iso urbs (both speeds)
4601da177e4SLinus Torvalds * each packet is one logical usb transaction to the device (not TT),
4611da177e4SLinus Torvalds * beginning at stream->next_uframe
4621da177e4SLinus Torvalds */
4631da177e4SLinus Torvalds struct ehci_iso_sched {
4641da177e4SLinus Torvalds struct list_head td_list;
4651da177e4SLinus Torvalds unsigned span;
46646c73d1dSAlan Stern unsigned first_packet;
4676bc3f397SGustavo A. R. Silva struct ehci_iso_packet packet[];
4681da177e4SLinus Torvalds };
4691da177e4SLinus Torvalds
4701da177e4SLinus Torvalds /*
4711da177e4SLinus Torvalds * ehci_iso_stream - groups all (s)itds for this endpoint.
4721da177e4SLinus Torvalds * acts like a qh would, if EHCI had them for ISO.
4731da177e4SLinus Torvalds */
4741da177e4SLinus Torvalds struct ehci_iso_stream {
47501792c60SXu Yang /* first field matches ehci_qh, but is NULL */
4761082f57aSClemens Ladisch struct ehci_qh_hw *hw;
4771da177e4SLinus Torvalds
4781da177e4SLinus Torvalds u8 bEndpointAddress;
4791da177e4SLinus Torvalds u8 highspeed;
4801da177e4SLinus Torvalds struct list_head td_list; /* queued itds/sitds */
4811da177e4SLinus Torvalds struct list_head free_list; /* list of unused itds/sitds */
4821da177e4SLinus Torvalds
4831da177e4SLinus Torvalds /* output of (re)scheduling */
484ffa0248eSAlan Stern struct ehci_per_sched ps; /* scheduling info */
48591a99b5eSAlan Stern unsigned next_uframe;
4866dbd682bSStefan Roese __hc32 splits;
4871da177e4SLinus Torvalds
4881da177e4SLinus Torvalds /* the rest is derived from the endpoint descriptor,
4891da177e4SLinus Torvalds * including the extra info for hw_bufp[0..2]
4901da177e4SLinus Torvalds */
491ffa0248eSAlan Stern u16 uperiod; /* period in uframes */
4921da177e4SLinus Torvalds u16 maxp;
4931da177e4SLinus Torvalds unsigned bandwidth;
4941da177e4SLinus Torvalds
4951da177e4SLinus Torvalds /* This is used to initialize iTD's hw_bufp fields */
4966dbd682bSStefan Roese __hc32 buf0;
4976dbd682bSStefan Roese __hc32 buf1;
4986dbd682bSStefan Roese __hc32 buf2;
4991da177e4SLinus Torvalds
5001da177e4SLinus Torvalds /* this is used to initialize sITD's tt info */
5016dbd682bSStefan Roese __hc32 address;
5021da177e4SLinus Torvalds };
5031da177e4SLinus Torvalds
5041da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
5051da177e4SLinus Torvalds
5061da177e4SLinus Torvalds /*
5071da177e4SLinus Torvalds * EHCI Specification 0.95 Section 3.3
5081da177e4SLinus Torvalds * Fig 3-4 "Isochronous Transaction Descriptor (iTD)"
5091da177e4SLinus Torvalds *
5101da177e4SLinus Torvalds * Schedule records for high speed iso xfers
5111da177e4SLinus Torvalds */
5121da177e4SLinus Torvalds struct ehci_itd {
5131da177e4SLinus Torvalds /* first part defined by EHCI spec */
5146dbd682bSStefan Roese __hc32 hw_next; /* see EHCI 3.3.1 */
5156dbd682bSStefan Roese __hc32 hw_transaction[8]; /* see EHCI 3.3.2 */
5161da177e4SLinus Torvalds #define EHCI_ISOC_ACTIVE (1<<31) /* activate transfer this slot */
5171da177e4SLinus Torvalds #define EHCI_ISOC_BUF_ERR (1<<30) /* Data buffer error */
5181da177e4SLinus Torvalds #define EHCI_ISOC_BABBLE (1<<29) /* babble detected */
5191da177e4SLinus Torvalds #define EHCI_ISOC_XACTERR (1<<28) /* XactErr - transaction error */
5201da177e4SLinus Torvalds #define EHCI_ITD_LENGTH(tok) (((tok)>>16) & 0x0fff)
5211da177e4SLinus Torvalds #define EHCI_ITD_IOC (1 << 15) /* interrupt on complete */
5221da177e4SLinus Torvalds
5236dbd682bSStefan Roese #define ITD_ACTIVE(ehci) cpu_to_hc32(ehci, EHCI_ISOC_ACTIVE)
5241da177e4SLinus Torvalds
5256dbd682bSStefan Roese __hc32 hw_bufp[7]; /* see EHCI 3.3.3 */
5266dbd682bSStefan Roese __hc32 hw_bufp_hi[7]; /* Appendix B */
5271da177e4SLinus Torvalds
5281da177e4SLinus Torvalds /* the rest is HCD-private */
5291da177e4SLinus Torvalds dma_addr_t itd_dma; /* for this itd */
5301da177e4SLinus Torvalds union ehci_shadow itd_next; /* ptr to periodic q entry */
5311da177e4SLinus Torvalds
5321da177e4SLinus Torvalds struct urb *urb;
5331da177e4SLinus Torvalds struct ehci_iso_stream *stream; /* endpoint's queue */
5341da177e4SLinus Torvalds struct list_head itd_list; /* list of stream's itds */
5351da177e4SLinus Torvalds
5361da177e4SLinus Torvalds /* any/all hw_transactions here may be used by that urb */
5371da177e4SLinus Torvalds unsigned frame; /* where scheduled */
5381da177e4SLinus Torvalds unsigned pg;
5391da177e4SLinus Torvalds unsigned index[8]; /* in urb->iso_frame_desc */
5403a9e742fSGeyslan G. Bem } __aligned(32);
5411da177e4SLinus Torvalds
5421da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
5431da177e4SLinus Torvalds
5441da177e4SLinus Torvalds /*
5451da177e4SLinus Torvalds * EHCI Specification 0.95 Section 3.4
5461da177e4SLinus Torvalds * siTD, aka split-transaction isochronous Transfer Descriptor
5471da177e4SLinus Torvalds * ... describe full speed iso xfers through TT in hubs
5481da177e4SLinus Torvalds * see Figure 3-5 "Split-transaction Isochronous Transaction Descriptor (siTD)
5491da177e4SLinus Torvalds */
5501da177e4SLinus Torvalds struct ehci_sitd {
5511da177e4SLinus Torvalds /* first part defined by EHCI spec */
5526dbd682bSStefan Roese __hc32 hw_next;
5531da177e4SLinus Torvalds /* uses bit field macros above - see EHCI 0.95 Table 3-8 */
5546dbd682bSStefan Roese __hc32 hw_fullspeed_ep; /* EHCI table 3-9 */
5556dbd682bSStefan Roese __hc32 hw_uframe; /* EHCI table 3-10 */
5566dbd682bSStefan Roese __hc32 hw_results; /* EHCI table 3-11 */
5571da177e4SLinus Torvalds #define SITD_IOC (1 << 31) /* interrupt on completion */
5581da177e4SLinus Torvalds #define SITD_PAGE (1 << 30) /* buffer 0/1 */
5594510a072SGeyslan G. Bem #define SITD_LENGTH(x) (((x) >> 16) & 0x3ff)
5601da177e4SLinus Torvalds #define SITD_STS_ACTIVE (1 << 7) /* HC may execute this */
5611da177e4SLinus Torvalds #define SITD_STS_ERR (1 << 6) /* error from TT */
5621da177e4SLinus Torvalds #define SITD_STS_DBE (1 << 5) /* data buffer error (in HC) */
5631da177e4SLinus Torvalds #define SITD_STS_BABBLE (1 << 4) /* device was babbling */
5641da177e4SLinus Torvalds #define SITD_STS_XACT (1 << 3) /* illegal IN response */
5651da177e4SLinus Torvalds #define SITD_STS_MMF (1 << 2) /* incomplete split transaction */
5661da177e4SLinus Torvalds #define SITD_STS_STS (1 << 1) /* split transaction state */
5671da177e4SLinus Torvalds
5686dbd682bSStefan Roese #define SITD_ACTIVE(ehci) cpu_to_hc32(ehci, SITD_STS_ACTIVE)
5691da177e4SLinus Torvalds
5706dbd682bSStefan Roese __hc32 hw_buf[2]; /* EHCI table 3-12 */
5716dbd682bSStefan Roese __hc32 hw_backpointer; /* EHCI table 3-13 */
5726dbd682bSStefan Roese __hc32 hw_buf_hi[2]; /* Appendix B */
5731da177e4SLinus Torvalds
5741da177e4SLinus Torvalds /* the rest is HCD-private */
5751da177e4SLinus Torvalds dma_addr_t sitd_dma;
5761da177e4SLinus Torvalds union ehci_shadow sitd_next; /* ptr to periodic q entry */
5771da177e4SLinus Torvalds
5781da177e4SLinus Torvalds struct urb *urb;
5791da177e4SLinus Torvalds struct ehci_iso_stream *stream; /* endpoint's queue */
5801da177e4SLinus Torvalds struct list_head sitd_list; /* list of stream's sitds */
5811da177e4SLinus Torvalds unsigned frame;
5821da177e4SLinus Torvalds unsigned index;
5833a9e742fSGeyslan G. Bem } __aligned(32);
5841da177e4SLinus Torvalds
5851da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
5861da177e4SLinus Torvalds
5871da177e4SLinus Torvalds /*
5881da177e4SLinus Torvalds * EHCI Specification 0.96 Section 3.7
5891da177e4SLinus Torvalds * Periodic Frame Span Traversal Node (FSTN)
5901da177e4SLinus Torvalds *
5911da177e4SLinus Torvalds * Manages split interrupt transactions (using TT) that span frame boundaries
5921da177e4SLinus Torvalds * into uframes 0/1; see 4.12.2.2. In those uframes, a "save place" FSTN
5931da177e4SLinus Torvalds * makes the HC jump (back) to a QH to scan for fs/ls QH completions until
5941da177e4SLinus Torvalds * it hits a "restore" FSTN; then it returns to finish other uframe 0/1 work.
5951da177e4SLinus Torvalds */
5961da177e4SLinus Torvalds struct ehci_fstn {
5976dbd682bSStefan Roese __hc32 hw_next; /* any periodic q entry */
5986dbd682bSStefan Roese __hc32 hw_prev; /* qh or EHCI_LIST_END */
5991da177e4SLinus Torvalds
6001da177e4SLinus Torvalds /* the rest is HCD-private */
6011da177e4SLinus Torvalds dma_addr_t fstn_dma;
6021da177e4SLinus Torvalds union ehci_shadow fstn_next; /* ptr to periodic q entry */
6033a9e742fSGeyslan G. Bem } __aligned(32);
6041da177e4SLinus Torvalds
6051da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
6061da177e4SLinus Torvalds
607b35c5009SAlan Stern /*
608b35c5009SAlan Stern * USB-2.0 Specification Sections 11.14 and 11.18
609b35c5009SAlan Stern * Scheduling and budgeting split transactions using TTs
610b35c5009SAlan Stern *
611b35c5009SAlan Stern * A hub can have a single TT for all its ports, or multiple TTs (one for each
612b35c5009SAlan Stern * port). The bandwidth and budgeting information for the full/low-speed bus
613b35c5009SAlan Stern * below each TT is self-contained and independent of the other TTs or the
614b35c5009SAlan Stern * high-speed bus.
615b35c5009SAlan Stern *
616b35c5009SAlan Stern * "Bandwidth" refers to the number of microseconds on the FS/LS bus allocated
617b35c5009SAlan Stern * to an interrupt or isochronous endpoint for each frame. "Budget" refers to
618b35c5009SAlan Stern * the best-case estimate of the number of full-speed bytes allocated to an
619b35c5009SAlan Stern * endpoint for each microframe within an allocated frame.
620b35c5009SAlan Stern *
621b35c5009SAlan Stern * Removal of an endpoint invalidates a TT's budget. Instead of trying to
622b35c5009SAlan Stern * keep an up-to-date record, we recompute the budget when it is needed.
623b35c5009SAlan Stern */
624b35c5009SAlan Stern
625b35c5009SAlan Stern struct ehci_tt {
626b35c5009SAlan Stern u16 bandwidth[EHCI_BANDWIDTH_FRAMES];
627b35c5009SAlan Stern
628b35c5009SAlan Stern struct list_head tt_list; /* List of all ehci_tt's */
629b35c5009SAlan Stern struct list_head ps_list; /* Items using this TT */
630b35c5009SAlan Stern struct usb_tt *usb_tt;
631b35c5009SAlan Stern int tt_port; /* TT port number */
632b35c5009SAlan Stern };
633b35c5009SAlan Stern
634b35c5009SAlan Stern /*-------------------------------------------------------------------------*/
635b35c5009SAlan Stern
63616032c4fSAlan Stern /* Prepare the PORTSC wakeup flags during controller suspend/resume */
63716032c4fSAlan Stern
6384147200dSAlan Stern #define ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup) \
6398af0219eSGeyslan G. Bem ehci_adjust_port_wakeup_flags(ehci, true, do_wakeup)
64016032c4fSAlan Stern
64116032c4fSAlan Stern #define ehci_prepare_ports_for_controller_resume(ehci) \
6428af0219eSGeyslan G. Bem ehci_adjust_port_wakeup_flags(ehci, false, false)
64316032c4fSAlan Stern
64416032c4fSAlan Stern /*-------------------------------------------------------------------------*/
64516032c4fSAlan Stern
6461da177e4SLinus Torvalds #ifdef CONFIG_USB_EHCI_ROOT_HUB_TT
6471da177e4SLinus Torvalds
6481da177e4SLinus Torvalds /*
6491da177e4SLinus Torvalds * Some EHCI controllers have a Transaction Translator built into the
6501da177e4SLinus Torvalds * root hub. This is a non-standard feature. Each controller will need
6511da177e4SLinus Torvalds * to add code to the following inline functions, and call them as
6521da177e4SLinus Torvalds * needed (mostly in root hub code).
6531da177e4SLinus Torvalds */
6541da177e4SLinus Torvalds
655a8e51775SAlan Stern #define ehci_is_TDI(e) (ehci_to_hcd(e)->has_tt)
6561da177e4SLinus Torvalds
6571da177e4SLinus Torvalds /* Returns the speed of a device attached to a port on the root hub. */
6581da177e4SLinus Torvalds static inline unsigned int
ehci_port_speed(struct ehci_hcd * ehci,unsigned int portsc)6591da177e4SLinus Torvalds ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc)
6601da177e4SLinus Torvalds {
6611da177e4SLinus Torvalds if (ehci_is_TDI(ehci)) {
662331ac6b2SAlek Du switch ((portsc >> (ehci->has_hostpc ? 25 : 26)) & 3) {
6631da177e4SLinus Torvalds case 0:
6641da177e4SLinus Torvalds return 0;
6651da177e4SLinus Torvalds case 1:
666288ead45SAlan Stern return USB_PORT_STAT_LOW_SPEED;
6671da177e4SLinus Torvalds case 2:
6681da177e4SLinus Torvalds default:
669288ead45SAlan Stern return USB_PORT_STAT_HIGH_SPEED;
6701da177e4SLinus Torvalds }
6711da177e4SLinus Torvalds }
672288ead45SAlan Stern return USB_PORT_STAT_HIGH_SPEED;
6731da177e4SLinus Torvalds }
6741da177e4SLinus Torvalds
6751da177e4SLinus Torvalds #else
6761da177e4SLinus Torvalds
6771da177e4SLinus Torvalds #define ehci_is_TDI(e) (0)
6781da177e4SLinus Torvalds
679288ead45SAlan Stern #define ehci_port_speed(ehci, portsc) USB_PORT_STAT_HIGH_SPEED
6801da177e4SLinus Torvalds #endif
6811da177e4SLinus Torvalds
6821da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
6831da177e4SLinus Torvalds
6848cd42e97SKumar Gala #ifdef CONFIG_PPC_83xx
6858cd42e97SKumar Gala /* Some Freescale processors have an erratum in which the TT
6868cd42e97SKumar Gala * port number in the queue head was 0..N-1 instead of 1..N.
6878cd42e97SKumar Gala */
6888cd42e97SKumar Gala #define ehci_has_fsl_portno_bug(e) ((e)->has_fsl_port_bug)
6898cd42e97SKumar Gala #else
6908cd42e97SKumar Gala #define ehci_has_fsl_portno_bug(e) (0)
6918cd42e97SKumar Gala #endif
6928cd42e97SKumar Gala
693f8786a91SNikhil Badola #define PORTSC_FSL_PFSC 24 /* Port Force Full-Speed Connect */
694f8786a91SNikhil Badola
695f8786a91SNikhil Badola #if defined(CONFIG_PPC_85xx)
696f8786a91SNikhil Badola /* Some Freescale processors have an erratum (USB A-005275) in which
697f8786a91SNikhil Badola * incoming packets get corrupted in HS mode
698f8786a91SNikhil Badola */
699f8786a91SNikhil Badola #define ehci_has_fsl_hs_errata(e) ((e)->has_fsl_hs_errata)
700f8786a91SNikhil Badola #else
701f8786a91SNikhil Badola #define ehci_has_fsl_hs_errata(e) (0)
702f8786a91SNikhil Badola #endif
703f8786a91SNikhil Badola
704083522d7SBenjamin Herrenschmidt /*
7059d4b8270SChangming Huang * Some Freescale/NXP processors have an erratum (USB A-005697)
7069d4b8270SChangming Huang * in which we need to wait for 10ms for bus to enter suspend mode
7079d4b8270SChangming Huang * after setting SUSP bit.
7089d4b8270SChangming Huang */
7099d4b8270SChangming Huang #define ehci_has_fsl_susp_errata(e) ((e)->has_fsl_susp_errata)
7109d4b8270SChangming Huang
7119d4b8270SChangming Huang /*
712*dda4b60eSXu Yang * Some Freescale/NXP processors using ChipIdea IP have a bug in which
713*dda4b60eSXu Yang * disabling the port (PE is cleared) does not cause PEC to be asserted
714*dda4b60eSXu Yang * when frame babble is detected.
715*dda4b60eSXu Yang */
716*dda4b60eSXu Yang #define ehci_has_ci_pec_bug(e, portsc) \
717*dda4b60eSXu Yang ((e)->has_ci_pec_bug && ((e)->command & CMD_PSE) \
718*dda4b60eSXu Yang && !(portsc & PORT_PEC) && !(portsc & PORT_PE))
719*dda4b60eSXu Yang
720*dda4b60eSXu Yang /*
721083522d7SBenjamin Herrenschmidt * While most USB host controllers implement their registers in
722083522d7SBenjamin Herrenschmidt * little-endian format, a minority (celleb companion chip) implement
723083522d7SBenjamin Herrenschmidt * them in big endian format.
724083522d7SBenjamin Herrenschmidt *
725083522d7SBenjamin Herrenschmidt * This attempts to support either format at compile time without a
726083522d7SBenjamin Herrenschmidt * runtime penalty, or both formats with the additional overhead
727083522d7SBenjamin Herrenschmidt * of checking a flag bit.
728c430131aSJan Andersson *
729c430131aSJan Andersson * ehci_big_endian_capbase is a special quirk for controllers that
730c430131aSJan Andersson * implement the HC capability registers as separate registers and not
731c430131aSJan Andersson * as fields of a 32-bit register.
732083522d7SBenjamin Herrenschmidt */
733083522d7SBenjamin Herrenschmidt
734083522d7SBenjamin Herrenschmidt #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
735083522d7SBenjamin Herrenschmidt #define ehci_big_endian_mmio(e) ((e)->big_endian_mmio)
736c430131aSJan Andersson #define ehci_big_endian_capbase(e) ((e)->big_endian_capbase)
737083522d7SBenjamin Herrenschmidt #else
738083522d7SBenjamin Herrenschmidt #define ehci_big_endian_mmio(e) 0
739c430131aSJan Andersson #define ehci_big_endian_capbase(e) 0
740083522d7SBenjamin Herrenschmidt #endif
741083522d7SBenjamin Herrenschmidt
7426dbd682bSStefan Roese /*
7436dbd682bSStefan Roese * Big-endian read/write functions are arch-specific.
7446dbd682bSStefan Roese * Other arches can be added if/when they're needed.
7456dbd682bSStefan Roese */
74691bc4d31SVladimir Barinov #if defined(CONFIG_ARM) && defined(CONFIG_ARCH_IXP4XX)
74791bc4d31SVladimir Barinov #define readl_be(addr) __raw_readl((__force unsigned *)addr)
74891bc4d31SVladimir Barinov #define writel_be(val, addr) __raw_writel(val, (__force unsigned *)addr)
74991bc4d31SVladimir Barinov #endif
75091bc4d31SVladimir Barinov
ehci_readl(const struct ehci_hcd * ehci,__u32 __iomem * regs)751083522d7SBenjamin Herrenschmidt static inline unsigned int ehci_readl(const struct ehci_hcd *ehci,
752083522d7SBenjamin Herrenschmidt __u32 __iomem *regs)
753083522d7SBenjamin Herrenschmidt {
754d728e327SBenjamin Herrenschmidt #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
755083522d7SBenjamin Herrenschmidt return ehci_big_endian_mmio(ehci) ?
75668f50e52SAl Viro readl_be(regs) :
75768f50e52SAl Viro readl(regs);
758d728e327SBenjamin Herrenschmidt #else
75968f50e52SAl Viro return readl(regs);
760d728e327SBenjamin Herrenschmidt #endif
761083522d7SBenjamin Herrenschmidt }
762083522d7SBenjamin Herrenschmidt
763feffe09fSPeter Chen #ifdef CONFIG_SOC_IMX28
imx28_ehci_writel(const unsigned int val,volatile __u32 __iomem * addr)764feffe09fSPeter Chen static inline void imx28_ehci_writel(const unsigned int val,
765feffe09fSPeter Chen volatile __u32 __iomem *addr)
766feffe09fSPeter Chen {
767feffe09fSPeter Chen __asm__ ("swp %0, %0, [%1]" : : "r"(val), "r"(addr));
768feffe09fSPeter Chen }
769feffe09fSPeter Chen #else
imx28_ehci_writel(const unsigned int val,volatile __u32 __iomem * addr)770feffe09fSPeter Chen static inline void imx28_ehci_writel(const unsigned int val,
771feffe09fSPeter Chen volatile __u32 __iomem *addr)
772feffe09fSPeter Chen {
773feffe09fSPeter Chen }
774feffe09fSPeter Chen #endif
ehci_writel(const struct ehci_hcd * ehci,const unsigned int val,__u32 __iomem * regs)775083522d7SBenjamin Herrenschmidt static inline void ehci_writel(const struct ehci_hcd *ehci,
776083522d7SBenjamin Herrenschmidt const unsigned int val, __u32 __iomem *regs)
777083522d7SBenjamin Herrenschmidt {
778d728e327SBenjamin Herrenschmidt #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
779083522d7SBenjamin Herrenschmidt ehci_big_endian_mmio(ehci) ?
78068f50e52SAl Viro writel_be(val, regs) :
78168f50e52SAl Viro writel(val, regs);
782d728e327SBenjamin Herrenschmidt #else
783feffe09fSPeter Chen if (ehci->imx28_write_fix)
784feffe09fSPeter Chen imx28_ehci_writel(val, regs);
785feffe09fSPeter Chen else
78668f50e52SAl Viro writel(val, regs);
787d728e327SBenjamin Herrenschmidt #endif
788083522d7SBenjamin Herrenschmidt }
7898cd42e97SKumar Gala
790796bcae7SVitaly Bordug /*
791796bcae7SVitaly Bordug * On certain ppc-44x SoC there is a HW issue, that could only worked around with
792796bcae7SVitaly Bordug * explicit suspend/operate of OHCI. This function hereby makes sense only on that arch.
79325985edcSLucas De Marchi * Other common bits are dependent on has_amcc_usb23 quirk flag.
794796bcae7SVitaly Bordug */
795796bcae7SVitaly Bordug #ifdef CONFIG_44x
set_ohci_hcfs(struct ehci_hcd * ehci,int operational)796796bcae7SVitaly Bordug static inline void set_ohci_hcfs(struct ehci_hcd *ehci, int operational)
797796bcae7SVitaly Bordug {
798796bcae7SVitaly Bordug u32 hc_control;
799796bcae7SVitaly Bordug
800796bcae7SVitaly Bordug hc_control = (readl_be(ehci->ohci_hcctrl_reg) & ~OHCI_CTRL_HCFS);
801796bcae7SVitaly Bordug if (operational)
802796bcae7SVitaly Bordug hc_control |= OHCI_USB_OPER;
803796bcae7SVitaly Bordug else
804796bcae7SVitaly Bordug hc_control |= OHCI_USB_SUSPEND;
805796bcae7SVitaly Bordug
806796bcae7SVitaly Bordug writel_be(hc_control, ehci->ohci_hcctrl_reg);
807796bcae7SVitaly Bordug (void) readl_be(ehci->ohci_hcctrl_reg);
808796bcae7SVitaly Bordug }
809796bcae7SVitaly Bordug #else
set_ohci_hcfs(struct ehci_hcd * ehci,int operational)810796bcae7SVitaly Bordug static inline void set_ohci_hcfs(struct ehci_hcd *ehci, int operational)
811796bcae7SVitaly Bordug { }
812796bcae7SVitaly Bordug #endif
813796bcae7SVitaly Bordug
8148cd42e97SKumar Gala /*-------------------------------------------------------------------------*/
8158cd42e97SKumar Gala
8166dbd682bSStefan Roese /*
8176dbd682bSStefan Roese * The AMCC 440EPx not only implements its EHCI registers in big-endian
8186dbd682bSStefan Roese * format, but also its DMA data structures (descriptors).
8196dbd682bSStefan Roese *
8206dbd682bSStefan Roese * EHCI controllers accessed through PCI work normally (little-endian
8216dbd682bSStefan Roese * everywhere), so we won't bother supporting a BE-only mode for now.
8226dbd682bSStefan Roese */
8236dbd682bSStefan Roese #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_DESC
8246dbd682bSStefan Roese #define ehci_big_endian_desc(e) ((e)->big_endian_desc)
8256dbd682bSStefan Roese
8266dbd682bSStefan Roese /* cpu to ehci */
cpu_to_hc32(const struct ehci_hcd * ehci,const u32 x)8276dbd682bSStefan Roese static inline __hc32 cpu_to_hc32(const struct ehci_hcd *ehci, const u32 x)
8286dbd682bSStefan Roese {
8296dbd682bSStefan Roese return ehci_big_endian_desc(ehci)
8306dbd682bSStefan Roese ? (__force __hc32)cpu_to_be32(x)
8316dbd682bSStefan Roese : (__force __hc32)cpu_to_le32(x);
8326dbd682bSStefan Roese }
8336dbd682bSStefan Roese
8346dbd682bSStefan Roese /* ehci to cpu */
hc32_to_cpu(const struct ehci_hcd * ehci,const __hc32 x)8356dbd682bSStefan Roese static inline u32 hc32_to_cpu(const struct ehci_hcd *ehci, const __hc32 x)
8366dbd682bSStefan Roese {
8376dbd682bSStefan Roese return ehci_big_endian_desc(ehci)
8386dbd682bSStefan Roese ? be32_to_cpu((__force __be32)x)
8396dbd682bSStefan Roese : le32_to_cpu((__force __le32)x);
8406dbd682bSStefan Roese }
8416dbd682bSStefan Roese
hc32_to_cpup(const struct ehci_hcd * ehci,const __hc32 * x)8426dbd682bSStefan Roese static inline u32 hc32_to_cpup(const struct ehci_hcd *ehci, const __hc32 *x)
8436dbd682bSStefan Roese {
8446dbd682bSStefan Roese return ehci_big_endian_desc(ehci)
8456dbd682bSStefan Roese ? be32_to_cpup((__force __be32 *)x)
8466dbd682bSStefan Roese : le32_to_cpup((__force __le32 *)x);
8476dbd682bSStefan Roese }
8486dbd682bSStefan Roese
8496dbd682bSStefan Roese #else
8506dbd682bSStefan Roese
8516dbd682bSStefan Roese /* cpu to ehci */
cpu_to_hc32(const struct ehci_hcd * ehci,const u32 x)8526dbd682bSStefan Roese static inline __hc32 cpu_to_hc32(const struct ehci_hcd *ehci, const u32 x)
8536dbd682bSStefan Roese {
8546dbd682bSStefan Roese return cpu_to_le32(x);
8556dbd682bSStefan Roese }
8566dbd682bSStefan Roese
8576dbd682bSStefan Roese /* ehci to cpu */
hc32_to_cpu(const struct ehci_hcd * ehci,const __hc32 x)8586dbd682bSStefan Roese static inline u32 hc32_to_cpu(const struct ehci_hcd *ehci, const __hc32 x)
8596dbd682bSStefan Roese {
8606dbd682bSStefan Roese return le32_to_cpu(x);
8616dbd682bSStefan Roese }
8626dbd682bSStefan Roese
hc32_to_cpup(const struct ehci_hcd * ehci,const __hc32 * x)8636dbd682bSStefan Roese static inline u32 hc32_to_cpup(const struct ehci_hcd *ehci, const __hc32 *x)
8646dbd682bSStefan Roese {
8656dbd682bSStefan Roese return le32_to_cpup(x);
8666dbd682bSStefan Roese }
8676dbd682bSStefan Roese
8686dbd682bSStefan Roese #endif
8696dbd682bSStefan Roese
8706dbd682bSStefan Roese /*-------------------------------------------------------------------------*/
8716dbd682bSStefan Roese
872d6064acaSAlan Stern #define ehci_dbg(ehci, fmt, args...) \
873d6064acaSAlan Stern dev_dbg(ehci_to_hcd(ehci)->self.controller, fmt, ## args)
874d6064acaSAlan Stern #define ehci_err(ehci, fmt, args...) \
875d6064acaSAlan Stern dev_err(ehci_to_hcd(ehci)->self.controller, fmt, ## args)
876d6064acaSAlan Stern #define ehci_info(ehci, fmt, args...) \
877d6064acaSAlan Stern dev_info(ehci_to_hcd(ehci)->self.controller, fmt, ## args)
878d6064acaSAlan Stern #define ehci_warn(ehci, fmt, args...) \
879d6064acaSAlan Stern dev_warn(ehci_to_hcd(ehci)->self.controller, fmt, ## args)
880d6064acaSAlan Stern
8811da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
8821da177e4SLinus Torvalds
8833e023203SAlan Stern /* Declarations of things exported for use by ehci platform drivers */
8843e023203SAlan Stern
8853e023203SAlan Stern struct ehci_driver_overrides {
8863e023203SAlan Stern size_t extra_priv_size;
8873e023203SAlan Stern int (*reset)(struct usb_hcd *hcd);
88811a7e594SMichael Grzeschik int (*port_power)(struct usb_hcd *hcd,
88911a7e594SMichael Grzeschik int portnum, bool enable);
8903e023203SAlan Stern };
8913e023203SAlan Stern
8923e023203SAlan Stern extern void ehci_init_driver(struct hc_driver *drv,
8933e023203SAlan Stern const struct ehci_driver_overrides *over);
8943e023203SAlan Stern extern int ehci_setup(struct usb_hcd *hcd);
8952f3a6b86SManjunath Goudar extern int ehci_handshake(struct ehci_hcd *ehci, void __iomem *ptr,
8962f3a6b86SManjunath Goudar u32 mask, u32 done, int usec);
89774db22cbSRamneek Mehresh extern int ehci_reset(struct ehci_hcd *ehci);
8983e023203SAlan Stern
8993e023203SAlan Stern extern int ehci_suspend(struct usb_hcd *hcd, bool do_wakeup);
900314b41b1SWu Liang feng extern int ehci_resume(struct usb_hcd *hcd, bool force_reset);
90174db22cbSRamneek Mehresh extern void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
90274db22cbSRamneek Mehresh bool suspending, bool do_wakeup);
9033e023203SAlan Stern
90437769939SLaurent Pinchart extern int ehci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
90537769939SLaurent Pinchart u16 wIndex, char *buf, u16 wLength);
90637769939SLaurent Pinchart
9071da177e4SLinus Torvalds #endif /* __LINUX_EHCI_HCD_H */
908