ehci.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. /*
  2. * Copyright (c) 2001-2002 by David Brownell
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation; either version 2 of the License, or (at your
  7. * option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #ifndef __LINUX_EHCI_HCD_H
  19. #define __LINUX_EHCI_HCD_H
  20. /* definitions used for the EHCI driver */
  21. /*
  22. * __hc32 and __hc16 are "Host Controller" types, they may be equivalent to
  23. * __leXX (normally) or __beXX (given EHCI_BIG_ENDIAN_DESC), depending on
  24. * the host controller implementation.
  25. *
  26. * To facilitate the strongest possible byte-order checking from "sparse"
  27. * and so on, we use __leXX unless that's not practical.
  28. */
  29. #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_DESC
  30. typedef __u32 __bitwise __hc32;
  31. typedef __u16 __bitwise __hc16;
  32. #else
  33. #define __hc32 __le32
  34. #define __hc16 __le16
  35. #endif
  36. /* statistics can be kept for for tuning/monitoring */
  37. struct ehci_stats {
  38. /* irq usage */
  39. unsigned long normal;
  40. unsigned long error;
  41. unsigned long reclaim;
  42. unsigned long lost_iaa;
  43. /* termination of urbs from core */
  44. unsigned long complete;
  45. unsigned long unlink;
  46. };
  47. /* ehci_hcd->lock guards shared data against other CPUs:
  48. * ehci_hcd: async, reclaim, periodic (and shadow), ...
  49. * usb_host_endpoint: hcpriv
  50. * ehci_qh: qh_next, qtd_list
  51. * ehci_qtd: qtd_list
  52. *
  53. * Also, hold this lock when talking to HC registers or
  54. * when updating hw_* fields in shared qh/qtd/... structures.
  55. */
  56. #define EHCI_MAX_ROOT_PORTS 15 /* see HCS_N_PORTS */
  57. struct ehci_hcd { /* one per controller */
  58. /* glue to PCI and HCD framework */
  59. struct ehci_caps __iomem *caps;
  60. struct ehci_regs __iomem *regs;
  61. struct ehci_dbg_port __iomem *debug;
  62. __u32 hcs_params; /* cached register copy */
  63. spinlock_t lock;
  64. /* async schedule support */
  65. struct ehci_qh *async;
  66. struct ehci_qh *reclaim;
  67. unsigned scanning : 1;
  68. /* periodic schedule support */
  69. #define DEFAULT_I_TDPS 1024 /* some HCs can do less */
  70. unsigned periodic_size;
  71. __hc32 *periodic; /* hw periodic table */
  72. dma_addr_t periodic_dma;
  73. unsigned i_thresh; /* uframes HC might cache */
  74. union ehci_shadow *pshadow; /* mirror hw periodic table */
  75. int next_uframe; /* scan periodic, start here */
  76. unsigned periodic_sched; /* periodic activity count */
  77. /* per root hub port */
  78. unsigned long reset_done [EHCI_MAX_ROOT_PORTS];
  79. /* bit vectors (one bit per port) */
  80. unsigned long bus_suspended; /* which ports were
  81. already suspended at the start of a bus suspend */
  82. unsigned long companion_ports; /* which ports are
  83. dedicated to the companion controller */
  84. unsigned long owned_ports; /* which ports are
  85. owned by the companion during a bus suspend */
  86. unsigned long port_c_suspend; /* which ports have
  87. the change-suspend feature turned on */
  88. unsigned long suspended_ports; /* which ports are
  89. suspended */
  90. /* per-HC memory pools (could be per-bus, but ...) */
  91. struct dma_pool *qh_pool; /* qh per active urb */
  92. struct dma_pool *qtd_pool; /* one or more per qh */
  93. struct dma_pool *itd_pool; /* itd per iso urb */
  94. struct dma_pool *sitd_pool; /* sitd per split iso urb */
  95. struct timer_list iaa_watchdog;
  96. struct timer_list watchdog;
  97. unsigned long actions;
  98. unsigned stamp;
  99. unsigned long next_statechange;
  100. u32 command;
  101. /* SILICON QUIRKS */
  102. unsigned no_selective_suspend:1;
  103. unsigned has_fsl_port_bug:1; /* FreeScale */
  104. unsigned big_endian_mmio:1;
  105. unsigned big_endian_desc:1;
  106. unsigned has_amcc_usb23:1;
  107. /* required for usb32 quirk */
  108. #define OHCI_CTRL_HCFS (3 << 6)
  109. #define OHCI_USB_OPER (2 << 6)
  110. #define OHCI_USB_SUSPEND (3 << 6)
  111. #define OHCI_HCCTRL_OFFSET 0x4
  112. #define OHCI_HCCTRL_LEN 0x4
  113. __hc32 *ohci_hcctrl_reg;
  114. u8 sbrn; /* packed release number */
  115. /* irq statistics */
  116. #ifdef EHCI_STATS
  117. struct ehci_stats stats;
  118. # define COUNT(x) do { (x)++; } while (0)
  119. #else
  120. # define COUNT(x) do {} while (0)
  121. #endif
  122. /* debug files */
  123. #ifdef DEBUG
  124. struct dentry *debug_dir;
  125. struct dentry *debug_async;
  126. struct dentry *debug_periodic;
  127. struct dentry *debug_registers;
  128. #endif
  129. };
  130. /* convert between an HCD pointer and the corresponding EHCI_HCD */
  131. static inline struct ehci_hcd *hcd_to_ehci (struct usb_hcd *hcd)
  132. {
  133. return (struct ehci_hcd *) (hcd->hcd_priv);
  134. }
  135. static inline struct usb_hcd *ehci_to_hcd (struct ehci_hcd *ehci)
  136. {
  137. return container_of ((void *) ehci, struct usb_hcd, hcd_priv);
  138. }
  139. static inline void
  140. iaa_watchdog_start(struct ehci_hcd *ehci)
  141. {
  142. WARN_ON(timer_pending(&ehci->iaa_watchdog));
  143. mod_timer(&ehci->iaa_watchdog,
  144. jiffies + msecs_to_jiffies(EHCI_IAA_MSECS));
  145. }
  146. static inline void iaa_watchdog_done(struct ehci_hcd *ehci)
  147. {
  148. del_timer(&ehci->iaa_watchdog);
  149. }
  150. enum ehci_timer_action {
  151. TIMER_IO_WATCHDOG,
  152. TIMER_ASYNC_SHRINK,
  153. TIMER_ASYNC_OFF,
  154. };
  155. static inline void
  156. timer_action_done (struct ehci_hcd *ehci, enum ehci_timer_action action)
  157. {
  158. clear_bit (action, &ehci->actions);
  159. }
  160. static inline void
  161. timer_action (struct ehci_hcd *ehci, enum ehci_timer_action action)
  162. {
  163. /* Don't override timeouts which shrink or (later) disable
  164. * the async ring; just the I/O watchdog. Note that if a
  165. * SHRINK were pending, OFF would never be requested.
  166. */
  167. if (timer_pending(&ehci->watchdog)
  168. && ((BIT(TIMER_ASYNC_SHRINK) | BIT(TIMER_ASYNC_OFF))
  169. & ehci->actions))
  170. return;
  171. if (!test_and_set_bit (action, &ehci->actions)) {
  172. unsigned long t;
  173. switch (action) {
  174. case TIMER_IO_WATCHDOG:
  175. t = EHCI_IO_JIFFIES;
  176. break;
  177. case TIMER_ASYNC_OFF:
  178. t = EHCI_ASYNC_JIFFIES;
  179. break;
  180. // case TIMER_ASYNC_SHRINK:
  181. default:
  182. /* add a jiffie since we synch against the
  183. * 8 KHz uframe counter.
  184. */
  185. t = DIV_ROUND_UP(EHCI_SHRINK_FRAMES * HZ, 1000) + 1;
  186. break;
  187. }
  188. mod_timer(&ehci->watchdog, t + jiffies);
  189. }
  190. }
  191. /*-------------------------------------------------------------------------*/
  192. #include <linux/usb/ehci_def.h>
  193. /*-------------------------------------------------------------------------*/
  194. #define QTD_NEXT(ehci, dma) cpu_to_hc32(ehci, (u32)dma)
  195. /*
  196. * EHCI Specification 0.95 Section 3.5
  197. * QTD: describe data transfer components (buffer, direction, ...)
  198. * See Fig 3-6 "Queue Element Transfer Descriptor Block Diagram".
  199. *
  200. * These are associated only with "QH" (Queue Head) structures,
  201. * used with control, bulk, and interrupt transfers.
  202. */
  203. struct ehci_qtd {
  204. /* first part defined by EHCI spec */
  205. __hc32 hw_next; /* see EHCI 3.5.1 */
  206. __hc32 hw_alt_next; /* see EHCI 3.5.2 */
  207. __hc32 hw_token; /* see EHCI 3.5.3 */
  208. #define QTD_TOGGLE (1 << 31) /* data toggle */
  209. #define QTD_LENGTH(tok) (((tok)>>16) & 0x7fff)
  210. #define QTD_IOC (1 << 15) /* interrupt on complete */
  211. #define QTD_CERR(tok) (((tok)>>10) & 0x3)
  212. #define QTD_PID(tok) (((tok)>>8) & 0x3)
  213. #define QTD_STS_ACTIVE (1 << 7) /* HC may execute this */
  214. #define QTD_STS_HALT (1 << 6) /* halted on error */
  215. #define QTD_STS_DBE (1 << 5) /* data buffer error (in HC) */
  216. #define QTD_STS_BABBLE (1 << 4) /* device was babbling (qtd halted) */
  217. #define QTD_STS_XACT (1 << 3) /* device gave illegal response */
  218. #define QTD_STS_MMF (1 << 2) /* incomplete split transaction */
  219. #define QTD_STS_STS (1 << 1) /* split transaction state */
  220. #define QTD_STS_PING (1 << 0) /* issue PING? */
  221. #define ACTIVE_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_ACTIVE)
  222. #define HALT_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_HALT)
  223. #define STATUS_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_STS)
  224. __hc32 hw_buf [5]; /* see EHCI 3.5.4 */
  225. __hc32 hw_buf_hi [5]; /* Appendix B */
  226. /* the rest is HCD-private */
  227. dma_addr_t qtd_dma; /* qtd address */
  228. struct list_head qtd_list; /* sw qtd list */
  229. struct urb *urb; /* qtd's urb */
  230. size_t length; /* length of buffer */
  231. } __attribute__ ((aligned (32)));
  232. /* mask NakCnt+T in qh->hw_alt_next */
  233. #define QTD_MASK(ehci) cpu_to_hc32 (ehci, ~0x1f)
  234. #define IS_SHORT_READ(token) (QTD_LENGTH (token) != 0 && QTD_PID (token) == 1)
  235. /*-------------------------------------------------------------------------*/
  236. /* type tag from {qh,itd,sitd,fstn}->hw_next */
  237. #define Q_NEXT_TYPE(ehci,dma) ((dma) & cpu_to_hc32(ehci, 3 << 1))
  238. /*
  239. * Now the following defines are not converted using the
  240. * __constant_cpu_to_le32() macro anymore, since we have to support
  241. * "dynamic" switching between be and le support, so that the driver
  242. * can be used on one system with SoC EHCI controller using big-endian
  243. * descriptors as well as a normal little-endian PCI EHCI controller.
  244. */
  245. /* values for that type tag */
  246. #define Q_TYPE_ITD (0 << 1)
  247. #define Q_TYPE_QH (1 << 1)
  248. #define Q_TYPE_SITD (2 << 1)
  249. #define Q_TYPE_FSTN (3 << 1)
  250. /* next async queue entry, or pointer to interrupt/periodic QH */
  251. #define QH_NEXT(ehci,dma) (cpu_to_hc32(ehci, (((u32)dma)&~0x01f)|Q_TYPE_QH))
  252. /* for periodic/async schedules and qtd lists, mark end of list */
  253. #define EHCI_LIST_END(ehci) cpu_to_hc32(ehci, 1) /* "null pointer" to hw */
  254. /*
  255. * Entries in periodic shadow table are pointers to one of four kinds
  256. * of data structure. That's dictated by the hardware; a type tag is
  257. * encoded in the low bits of the hardware's periodic schedule. Use
  258. * Q_NEXT_TYPE to get the tag.
  259. *
  260. * For entries in the async schedule, the type tag always says "qh".
  261. */
  262. union ehci_shadow {
  263. struct ehci_qh *qh; /* Q_TYPE_QH */
  264. struct ehci_itd *itd; /* Q_TYPE_ITD */
  265. struct ehci_sitd *sitd; /* Q_TYPE_SITD */
  266. struct ehci_fstn *fstn; /* Q_TYPE_FSTN */
  267. __hc32 *hw_next; /* (all types) */
  268. void *ptr;
  269. };
  270. /*-------------------------------------------------------------------------*/
  271. /*
  272. * EHCI Specification 0.95 Section 3.6
  273. * QH: describes control/bulk/interrupt endpoints
  274. * See Fig 3-7 "Queue Head Structure Layout".
  275. *
  276. * These appear in both the async and (for interrupt) periodic schedules.
  277. */
  278. struct ehci_qh {
  279. /* first part defined by EHCI spec */
  280. __hc32 hw_next; /* see EHCI 3.6.1 */
  281. __hc32 hw_info1; /* see EHCI 3.6.2 */
  282. #define QH_HEAD 0x00008000
  283. __hc32 hw_info2; /* see EHCI 3.6.2 */
  284. #define QH_SMASK 0x000000ff
  285. #define QH_CMASK 0x0000ff00
  286. #define QH_HUBADDR 0x007f0000
  287. #define QH_HUBPORT 0x3f800000
  288. #define QH_MULT 0xc0000000
  289. __hc32 hw_current; /* qtd list - see EHCI 3.6.4 */
  290. /* qtd overlay (hardware parts of a struct ehci_qtd) */
  291. __hc32 hw_qtd_next;
  292. __hc32 hw_alt_next;
  293. __hc32 hw_token;
  294. __hc32 hw_buf [5];
  295. __hc32 hw_buf_hi [5];
  296. /* the rest is HCD-private */
  297. dma_addr_t qh_dma; /* address of qh */
  298. union ehci_shadow qh_next; /* ptr to qh; or periodic */
  299. struct list_head qtd_list; /* sw qtd list */
  300. struct ehci_qtd *dummy;
  301. struct ehci_qh *reclaim; /* next to reclaim */
  302. struct ehci_hcd *ehci;
  303. /*
  304. * Do NOT use atomic operations for QH refcounting. On some CPUs
  305. * (PPC7448 for example), atomic operations cannot be performed on
  306. * memory that is cache-inhibited (i.e. being used for DMA).
  307. * Spinlocks are used to protect all QH fields.
  308. */
  309. u32 refcount;
  310. unsigned stamp;
  311. u8 qh_state;
  312. #define QH_STATE_LINKED 1 /* HC sees this */
  313. #define QH_STATE_UNLINK 2 /* HC may still see this */
  314. #define QH_STATE_IDLE 3 /* HC doesn't see this */
  315. #define QH_STATE_UNLINK_WAIT 4 /* LINKED and on reclaim q */
  316. #define QH_STATE_COMPLETING 5 /* don't touch token.HALT */
  317. /* periodic schedule info */
  318. u8 usecs; /* intr bandwidth */
  319. u8 gap_uf; /* uframes split/csplit gap */
  320. u8 c_usecs; /* ... split completion bw */
  321. u16 tt_usecs; /* tt downstream bandwidth */
  322. unsigned short period; /* polling interval */
  323. unsigned short start; /* where polling starts */
  324. #define NO_FRAME ((unsigned short)~0) /* pick new start */
  325. struct usb_device *dev; /* access to TT */
  326. } __attribute__ ((aligned (32)));
  327. /*-------------------------------------------------------------------------*/
  328. /* description of one iso transaction (up to 3 KB data if highspeed) */
  329. struct ehci_iso_packet {
  330. /* These will be copied to iTD when scheduling */
  331. u64 bufp; /* itd->hw_bufp{,_hi}[pg] |= */
  332. __hc32 transaction; /* itd->hw_transaction[i] |= */
  333. u8 cross; /* buf crosses pages */
  334. /* for full speed OUT splits */
  335. u32 buf1;
  336. };
  337. /* temporary schedule data for packets from iso urbs (both speeds)
  338. * each packet is one logical usb transaction to the device (not TT),
  339. * beginning at stream->next_uframe
  340. */
  341. struct ehci_iso_sched {
  342. struct list_head td_list;
  343. unsigned span;
  344. struct ehci_iso_packet packet [0];
  345. };
  346. /*
  347. * ehci_iso_stream - groups all (s)itds for this endpoint.
  348. * acts like a qh would, if EHCI had them for ISO.
  349. */
  350. struct ehci_iso_stream {
  351. /* first two fields match QH, but info1 == 0 */
  352. __hc32 hw_next;
  353. __hc32 hw_info1;
  354. u32 refcount;
  355. u8 bEndpointAddress;
  356. u8 highspeed;
  357. u16 depth; /* depth in uframes */
  358. struct list_head td_list; /* queued itds/sitds */
  359. struct list_head free_list; /* list of unused itds/sitds */
  360. struct usb_device *udev;
  361. struct usb_host_endpoint *ep;
  362. /* output of (re)scheduling */
  363. unsigned long start; /* jiffies */
  364. unsigned long rescheduled;
  365. int next_uframe;
  366. __hc32 splits;
  367. /* the rest is derived from the endpoint descriptor,
  368. * trusting urb->interval == f(epdesc->bInterval) and
  369. * including the extra info for hw_bufp[0..2]
  370. */
  371. u8 usecs, c_usecs;
  372. u16 interval;
  373. u16 tt_usecs;
  374. u16 maxp;
  375. u16 raw_mask;
  376. unsigned bandwidth;
  377. /* This is used to initialize iTD's hw_bufp fields */
  378. __hc32 buf0;
  379. __hc32 buf1;
  380. __hc32 buf2;
  381. /* this is used to initialize sITD's tt info */
  382. __hc32 address;
  383. };
  384. /*-------------------------------------------------------------------------*/
  385. /*
  386. * EHCI Specification 0.95 Section 3.3
  387. * Fig 3-4 "Isochronous Transaction Descriptor (iTD)"
  388. *
  389. * Schedule records for high speed iso xfers
  390. */
  391. struct ehci_itd {
  392. /* first part defined by EHCI spec */
  393. __hc32 hw_next; /* see EHCI 3.3.1 */
  394. __hc32 hw_transaction [8]; /* see EHCI 3.3.2 */
  395. #define EHCI_ISOC_ACTIVE (1<<31) /* activate transfer this slot */
  396. #define EHCI_ISOC_BUF_ERR (1<<30) /* Data buffer error */
  397. #define EHCI_ISOC_BABBLE (1<<29) /* babble detected */
  398. #define EHCI_ISOC_XACTERR (1<<28) /* XactErr - transaction error */
  399. #define EHCI_ITD_LENGTH(tok) (((tok)>>16) & 0x0fff)
  400. #define EHCI_ITD_IOC (1 << 15) /* interrupt on complete */
  401. #define ITD_ACTIVE(ehci) cpu_to_hc32(ehci, EHCI_ISOC_ACTIVE)
  402. __hc32 hw_bufp [7]; /* see EHCI 3.3.3 */
  403. __hc32 hw_bufp_hi [7]; /* Appendix B */
  404. /* the rest is HCD-private */
  405. dma_addr_t itd_dma; /* for this itd */
  406. union ehci_shadow itd_next; /* ptr to periodic q entry */
  407. struct urb *urb;
  408. struct ehci_iso_stream *stream; /* endpoint's queue */
  409. struct list_head itd_list; /* list of stream's itds */
  410. /* any/all hw_transactions here may be used by that urb */
  411. unsigned frame; /* where scheduled */
  412. unsigned pg;
  413. unsigned index[8]; /* in urb->iso_frame_desc */
  414. } __attribute__ ((aligned (32)));
  415. /*-------------------------------------------------------------------------*/
  416. /*
  417. * EHCI Specification 0.95 Section 3.4
  418. * siTD, aka split-transaction isochronous Transfer Descriptor
  419. * ... describe full speed iso xfers through TT in hubs
  420. * see Figure 3-5 "Split-transaction Isochronous Transaction Descriptor (siTD)
  421. */
  422. struct ehci_sitd {
  423. /* first part defined by EHCI spec */
  424. __hc32 hw_next;
  425. /* uses bit field macros above - see EHCI 0.95 Table 3-8 */
  426. __hc32 hw_fullspeed_ep; /* EHCI table 3-9 */
  427. __hc32 hw_uframe; /* EHCI table 3-10 */
  428. __hc32 hw_results; /* EHCI table 3-11 */
  429. #define SITD_IOC (1 << 31) /* interrupt on completion */
  430. #define SITD_PAGE (1 << 30) /* buffer 0/1 */
  431. #define SITD_LENGTH(x) (0x3ff & ((x)>>16))
  432. #define SITD_STS_ACTIVE (1 << 7) /* HC may execute this */
  433. #define SITD_STS_ERR (1 << 6) /* error from TT */
  434. #define SITD_STS_DBE (1 << 5) /* data buffer error (in HC) */
  435. #define SITD_STS_BABBLE (1 << 4) /* device was babbling */
  436. #define SITD_STS_XACT (1 << 3) /* illegal IN response */
  437. #define SITD_STS_MMF (1 << 2) /* incomplete split transaction */
  438. #define SITD_STS_STS (1 << 1) /* split transaction state */
  439. #define SITD_ACTIVE(ehci) cpu_to_hc32(ehci, SITD_STS_ACTIVE)
  440. __hc32 hw_buf [2]; /* EHCI table 3-12 */
  441. __hc32 hw_backpointer; /* EHCI table 3-13 */
  442. __hc32 hw_buf_hi [2]; /* Appendix B */
  443. /* the rest is HCD-private */
  444. dma_addr_t sitd_dma;
  445. union ehci_shadow sitd_next; /* ptr to periodic q entry */
  446. struct urb *urb;
  447. struct ehci_iso_stream *stream; /* endpoint's queue */
  448. struct list_head sitd_list; /* list of stream's sitds */
  449. unsigned frame;
  450. unsigned index;
  451. } __attribute__ ((aligned (32)));
  452. /*-------------------------------------------------------------------------*/
  453. /*
  454. * EHCI Specification 0.96 Section 3.7
  455. * Periodic Frame Span Traversal Node (FSTN)
  456. *
  457. * Manages split interrupt transactions (using TT) that span frame boundaries
  458. * into uframes 0/1; see 4.12.2.2. In those uframes, a "save place" FSTN
  459. * makes the HC jump (back) to a QH to scan for fs/ls QH completions until
  460. * it hits a "restore" FSTN; then it returns to finish other uframe 0/1 work.
  461. */
  462. struct ehci_fstn {
  463. __hc32 hw_next; /* any periodic q entry */
  464. __hc32 hw_prev; /* qh or EHCI_LIST_END */
  465. /* the rest is HCD-private */
  466. dma_addr_t fstn_dma;
  467. union ehci_shadow fstn_next; /* ptr to periodic q entry */
  468. } __attribute__ ((aligned (32)));
  469. /*-------------------------------------------------------------------------*/
  470. #ifdef CONFIG_USB_EHCI_ROOT_HUB_TT
  471. /*
  472. * Some EHCI controllers have a Transaction Translator built into the
  473. * root hub. This is a non-standard feature. Each controller will need
  474. * to add code to the following inline functions, and call them as
  475. * needed (mostly in root hub code).
  476. */
  477. #define ehci_is_TDI(e) (ehci_to_hcd(e)->has_tt)
  478. /* Returns the speed of a device attached to a port on the root hub. */
  479. static inline unsigned int
  480. ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc)
  481. {
  482. if (ehci_is_TDI(ehci)) {
  483. switch ((portsc>>26)&3) {
  484. case 0:
  485. return 0;
  486. case 1:
  487. return (1<<USB_PORT_FEAT_LOWSPEED);
  488. case 2:
  489. default:
  490. return (1<<USB_PORT_FEAT_HIGHSPEED);
  491. }
  492. }
  493. return (1<<USB_PORT_FEAT_HIGHSPEED);
  494. }
  495. #else
  496. #define ehci_is_TDI(e) (0)
  497. #define ehci_port_speed(ehci, portsc) (1<<USB_PORT_FEAT_HIGHSPEED)
  498. #endif
  499. /*-------------------------------------------------------------------------*/
  500. #ifdef CONFIG_PPC_83xx
  501. /* Some Freescale processors have an erratum in which the TT
  502. * port number in the queue head was 0..N-1 instead of 1..N.
  503. */
  504. #define ehci_has_fsl_portno_bug(e) ((e)->has_fsl_port_bug)
  505. #else
  506. #define ehci_has_fsl_portno_bug(e) (0)
  507. #endif
  508. /*
  509. * While most USB host controllers implement their registers in
  510. * little-endian format, a minority (celleb companion chip) implement
  511. * them in big endian format.
  512. *
  513. * This attempts to support either format at compile time without a
  514. * runtime penalty, or both formats with the additional overhead
  515. * of checking a flag bit.
  516. */
  517. #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
  518. #define ehci_big_endian_mmio(e) ((e)->big_endian_mmio)
  519. #else
  520. #define ehci_big_endian_mmio(e) 0
  521. #endif
  522. /*
  523. * Big-endian read/write functions are arch-specific.
  524. * Other arches can be added if/when they're needed.
  525. */
  526. #if defined(CONFIG_ARM) && defined(CONFIG_ARCH_IXP4XX)
  527. #define readl_be(addr) __raw_readl((__force unsigned *)addr)
  528. #define writel_be(val, addr) __raw_writel(val, (__force unsigned *)addr)
  529. #endif
  530. static inline unsigned int ehci_readl(const struct ehci_hcd *ehci,
  531. __u32 __iomem * regs)
  532. {
  533. #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
  534. return ehci_big_endian_mmio(ehci) ?
  535. readl_be(regs) :
  536. readl(regs);
  537. #else
  538. return readl(regs);
  539. #endif
  540. }
  541. static inline void ehci_writel(const struct ehci_hcd *ehci,
  542. const unsigned int val, __u32 __iomem *regs)
  543. {
  544. #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
  545. ehci_big_endian_mmio(ehci) ?
  546. writel_be(val, regs) :
  547. writel(val, regs);
  548. #else
  549. writel(val, regs);
  550. #endif
  551. }
  552. /*
  553. * On certain ppc-44x SoC there is a HW issue, that could only worked around with
  554. * explicit suspend/operate of OHCI. This function hereby makes sense only on that arch.
  555. * Other common bits are dependant on has_amcc_usb23 quirk flag.
  556. */
  557. #ifdef CONFIG_44x
  558. static inline void set_ohci_hcfs(struct ehci_hcd *ehci, int operational)
  559. {
  560. u32 hc_control;
  561. hc_control = (readl_be(ehci->ohci_hcctrl_reg) & ~OHCI_CTRL_HCFS);
  562. if (operational)
  563. hc_control |= OHCI_USB_OPER;
  564. else
  565. hc_control |= OHCI_USB_SUSPEND;
  566. writel_be(hc_control, ehci->ohci_hcctrl_reg);
  567. (void) readl_be(ehci->ohci_hcctrl_reg);
  568. }
  569. #else
  570. static inline void set_ohci_hcfs(struct ehci_hcd *ehci, int operational)
  571. { }
  572. #endif
  573. /*-------------------------------------------------------------------------*/
  574. /*
  575. * The AMCC 440EPx not only implements its EHCI registers in big-endian
  576. * format, but also its DMA data structures (descriptors).
  577. *
  578. * EHCI controllers accessed through PCI work normally (little-endian
  579. * everywhere), so we won't bother supporting a BE-only mode for now.
  580. */
  581. #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_DESC
  582. #define ehci_big_endian_desc(e) ((e)->big_endian_desc)
  583. /* cpu to ehci */
  584. static inline __hc32 cpu_to_hc32 (const struct ehci_hcd *ehci, const u32 x)
  585. {
  586. return ehci_big_endian_desc(ehci)
  587. ? (__force __hc32)cpu_to_be32(x)
  588. : (__force __hc32)cpu_to_le32(x);
  589. }
  590. /* ehci to cpu */
  591. static inline u32 hc32_to_cpu (const struct ehci_hcd *ehci, const __hc32 x)
  592. {
  593. return ehci_big_endian_desc(ehci)
  594. ? be32_to_cpu((__force __be32)x)
  595. : le32_to_cpu((__force __le32)x);
  596. }
  597. static inline u32 hc32_to_cpup (const struct ehci_hcd *ehci, const __hc32 *x)
  598. {
  599. return ehci_big_endian_desc(ehci)
  600. ? be32_to_cpup((__force __be32 *)x)
  601. : le32_to_cpup((__force __le32 *)x);
  602. }
  603. #else
  604. /* cpu to ehci */
  605. static inline __hc32 cpu_to_hc32 (const struct ehci_hcd *ehci, const u32 x)
  606. {
  607. return cpu_to_le32(x);
  608. }
  609. /* ehci to cpu */
  610. static inline u32 hc32_to_cpu (const struct ehci_hcd *ehci, const __hc32 x)
  611. {
  612. return le32_to_cpu(x);
  613. }
  614. static inline u32 hc32_to_cpup (const struct ehci_hcd *ehci, const __hc32 *x)
  615. {
  616. return le32_to_cpup(x);
  617. }
  618. #endif
  619. /*-------------------------------------------------------------------------*/
  620. #ifndef DEBUG
  621. #define STUB_DEBUG_FILES
  622. #endif /* DEBUG */
  623. /*-------------------------------------------------------------------------*/
  624. #endif /* __LINUX_EHCI_HCD_H */