ehci.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  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 tuning/monitoring */
  37. #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG)
  38. #define EHCI_STATS
  39. #endif
  40. struct ehci_stats {
  41. /* irq usage */
  42. unsigned long normal;
  43. unsigned long error;
  44. unsigned long iaa;
  45. unsigned long lost_iaa;
  46. /* termination of urbs from core */
  47. unsigned long complete;
  48. unsigned long unlink;
  49. };
  50. /*
  51. * Scheduling and budgeting information for periodic transfers, for both
  52. * high-speed devices and full/low-speed devices lying behind a TT.
  53. */
  54. struct ehci_per_sched {
  55. struct usb_device *udev; /* access to the TT */
  56. struct usb_host_endpoint *ep;
  57. u16 tt_usecs; /* time on the FS/LS bus */
  58. u16 period; /* actual period in frames */
  59. u16 phase; /* actual phase, frame part */
  60. u8 phase_uf; /* uframe part of the phase */
  61. u8 usecs, c_usecs; /* times on the HS bus */
  62. };
  63. #define NO_FRAME 29999 /* frame not assigned yet */
  64. /* ehci_hcd->lock guards shared data against other CPUs:
  65. * ehci_hcd: async, unlink, periodic (and shadow), ...
  66. * usb_host_endpoint: hcpriv
  67. * ehci_qh: qh_next, qtd_list
  68. * ehci_qtd: qtd_list
  69. *
  70. * Also, hold this lock when talking to HC registers or
  71. * when updating hw_* fields in shared qh/qtd/... structures.
  72. */
  73. #define EHCI_MAX_ROOT_PORTS 15 /* see HCS_N_PORTS */
  74. /*
  75. * ehci_rh_state values of EHCI_RH_RUNNING or above mean that the
  76. * controller may be doing DMA. Lower values mean there's no DMA.
  77. */
  78. enum ehci_rh_state {
  79. EHCI_RH_HALTED,
  80. EHCI_RH_SUSPENDED,
  81. EHCI_RH_RUNNING,
  82. EHCI_RH_STOPPING
  83. };
  84. /*
  85. * Timer events, ordered by increasing delay length.
  86. * Always update event_delays_ns[] and event_handlers[] (defined in
  87. * ehci-timer.c) in parallel with this list.
  88. */
  89. enum ehci_hrtimer_event {
  90. EHCI_HRTIMER_POLL_ASS, /* Poll for async schedule off */
  91. EHCI_HRTIMER_POLL_PSS, /* Poll for periodic schedule off */
  92. EHCI_HRTIMER_POLL_DEAD, /* Wait for dead controller to stop */
  93. EHCI_HRTIMER_UNLINK_INTR, /* Wait for interrupt QH unlink */
  94. EHCI_HRTIMER_FREE_ITDS, /* Wait for unused iTDs and siTDs */
  95. EHCI_HRTIMER_START_UNLINK_INTR, /* Unlink empty interrupt QHs */
  96. EHCI_HRTIMER_ASYNC_UNLINKS, /* Unlink empty async QHs */
  97. EHCI_HRTIMER_IAA_WATCHDOG, /* Handle lost IAA interrupts */
  98. EHCI_HRTIMER_DISABLE_PERIODIC, /* Wait to disable periodic sched */
  99. EHCI_HRTIMER_DISABLE_ASYNC, /* Wait to disable async sched */
  100. EHCI_HRTIMER_IO_WATCHDOG, /* Check for missing IRQs */
  101. EHCI_HRTIMER_NUM_EVENTS /* Must come last */
  102. };
  103. #define EHCI_HRTIMER_NO_EVENT 99
  104. struct ehci_hcd { /* one per controller */
  105. /* timing support */
  106. enum ehci_hrtimer_event next_hrtimer_event;
  107. unsigned enabled_hrtimer_events;
  108. ktime_t hr_timeouts[EHCI_HRTIMER_NUM_EVENTS];
  109. struct hrtimer hrtimer;
  110. int PSS_poll_count;
  111. int ASS_poll_count;
  112. int died_poll_count;
  113. /* glue to PCI and HCD framework */
  114. struct ehci_caps __iomem *caps;
  115. struct ehci_regs __iomem *regs;
  116. struct ehci_dbg_port __iomem *debug;
  117. __u32 hcs_params; /* cached register copy */
  118. spinlock_t lock;
  119. enum ehci_rh_state rh_state;
  120. /* general schedule support */
  121. bool scanning:1;
  122. bool need_rescan:1;
  123. bool intr_unlinking:1;
  124. bool iaa_in_progress:1;
  125. bool async_unlinking:1;
  126. bool shutdown:1;
  127. struct ehci_qh *qh_scan_next;
  128. /* async schedule support */
  129. struct ehci_qh *async;
  130. struct ehci_qh *dummy; /* For AMD quirk use */
  131. struct list_head async_unlink;
  132. struct list_head async_idle;
  133. unsigned async_unlink_cycle;
  134. unsigned async_count; /* async activity count */
  135. /* periodic schedule support */
  136. #define DEFAULT_I_TDPS 1024 /* some HCs can do less */
  137. unsigned periodic_size;
  138. __hc32 *periodic; /* hw periodic table */
  139. dma_addr_t periodic_dma;
  140. struct list_head intr_qh_list;
  141. unsigned i_thresh; /* uframes HC might cache */
  142. union ehci_shadow *pshadow; /* mirror hw periodic table */
  143. struct list_head intr_unlink_wait;
  144. struct list_head intr_unlink;
  145. unsigned intr_unlink_wait_cycle;
  146. unsigned intr_unlink_cycle;
  147. unsigned now_frame; /* frame from HC hardware */
  148. unsigned last_iso_frame; /* last frame scanned for iso */
  149. unsigned intr_count; /* intr activity count */
  150. unsigned isoc_count; /* isoc activity count */
  151. unsigned periodic_count; /* periodic activity count */
  152. unsigned uframe_periodic_max; /* max periodic time per uframe */
  153. /* list of itds & sitds completed while now_frame was still active */
  154. struct list_head cached_itd_list;
  155. struct ehci_itd *last_itd_to_free;
  156. struct list_head cached_sitd_list;
  157. struct ehci_sitd *last_sitd_to_free;
  158. /* per root hub port */
  159. unsigned long reset_done [EHCI_MAX_ROOT_PORTS];
  160. /* bit vectors (one bit per port) */
  161. unsigned long bus_suspended; /* which ports were
  162. already suspended at the start of a bus suspend */
  163. unsigned long companion_ports; /* which ports are
  164. dedicated to the companion controller */
  165. unsigned long owned_ports; /* which ports are
  166. owned by the companion during a bus suspend */
  167. unsigned long port_c_suspend; /* which ports have
  168. the change-suspend feature turned on */
  169. unsigned long suspended_ports; /* which ports are
  170. suspended */
  171. unsigned long resuming_ports; /* which ports have
  172. started to resume */
  173. /* per-HC memory pools (could be per-bus, but ...) */
  174. struct dma_pool *qh_pool; /* qh per active urb */
  175. struct dma_pool *qtd_pool; /* one or more per qh */
  176. struct dma_pool *itd_pool; /* itd per iso urb */
  177. struct dma_pool *sitd_pool; /* sitd per split iso urb */
  178. unsigned random_frame;
  179. unsigned long next_statechange;
  180. ktime_t last_periodic_enable;
  181. u32 command;
  182. /* SILICON QUIRKS */
  183. unsigned no_selective_suspend:1;
  184. unsigned has_fsl_port_bug:1; /* FreeScale */
  185. unsigned big_endian_mmio:1;
  186. unsigned big_endian_desc:1;
  187. unsigned big_endian_capbase:1;
  188. unsigned has_amcc_usb23:1;
  189. unsigned need_io_watchdog:1;
  190. unsigned amd_pll_fix:1;
  191. unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/
  192. unsigned has_synopsys_hc_bug:1; /* Synopsys HC */
  193. unsigned frame_index_bug:1; /* MosChip (AKA NetMos) */
  194. unsigned need_oc_pp_cycle:1; /* MPC834X port power */
  195. /* required for usb32 quirk */
  196. #define OHCI_CTRL_HCFS (3 << 6)
  197. #define OHCI_USB_OPER (2 << 6)
  198. #define OHCI_USB_SUSPEND (3 << 6)
  199. #define OHCI_HCCTRL_OFFSET 0x4
  200. #define OHCI_HCCTRL_LEN 0x4
  201. __hc32 *ohci_hcctrl_reg;
  202. unsigned has_hostpc:1;
  203. unsigned has_tdi_phy_lpm:1;
  204. unsigned has_ppcd:1; /* support per-port change bits */
  205. u8 sbrn; /* packed release number */
  206. /* irq statistics */
  207. #ifdef EHCI_STATS
  208. struct ehci_stats stats;
  209. # define COUNT(x) do { (x)++; } while (0)
  210. #else
  211. # define COUNT(x) do {} while (0)
  212. #endif
  213. /* debug files */
  214. #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG)
  215. struct dentry *debug_dir;
  216. #endif
  217. /* platform-specific data -- must come last */
  218. unsigned long priv[0] __aligned(sizeof(s64));
  219. };
  220. /* convert between an HCD pointer and the corresponding EHCI_HCD */
  221. static inline struct ehci_hcd *hcd_to_ehci (struct usb_hcd *hcd)
  222. {
  223. return (struct ehci_hcd *) (hcd->hcd_priv);
  224. }
  225. static inline struct usb_hcd *ehci_to_hcd (struct ehci_hcd *ehci)
  226. {
  227. return container_of ((void *) ehci, struct usb_hcd, hcd_priv);
  228. }
  229. /*-------------------------------------------------------------------------*/
  230. #include <linux/usb/ehci_def.h>
  231. /*-------------------------------------------------------------------------*/
  232. #define QTD_NEXT(ehci, dma) cpu_to_hc32(ehci, (u32)dma)
  233. /*
  234. * EHCI Specification 0.95 Section 3.5
  235. * QTD: describe data transfer components (buffer, direction, ...)
  236. * See Fig 3-6 "Queue Element Transfer Descriptor Block Diagram".
  237. *
  238. * These are associated only with "QH" (Queue Head) structures,
  239. * used with control, bulk, and interrupt transfers.
  240. */
  241. struct ehci_qtd {
  242. /* first part defined by EHCI spec */
  243. __hc32 hw_next; /* see EHCI 3.5.1 */
  244. __hc32 hw_alt_next; /* see EHCI 3.5.2 */
  245. __hc32 hw_token; /* see EHCI 3.5.3 */
  246. #define QTD_TOGGLE (1 << 31) /* data toggle */
  247. #define QTD_LENGTH(tok) (((tok)>>16) & 0x7fff)
  248. #define QTD_IOC (1 << 15) /* interrupt on complete */
  249. #define QTD_CERR(tok) (((tok)>>10) & 0x3)
  250. #define QTD_PID(tok) (((tok)>>8) & 0x3)
  251. #define QTD_STS_ACTIVE (1 << 7) /* HC may execute this */
  252. #define QTD_STS_HALT (1 << 6) /* halted on error */
  253. #define QTD_STS_DBE (1 << 5) /* data buffer error (in HC) */
  254. #define QTD_STS_BABBLE (1 << 4) /* device was babbling (qtd halted) */
  255. #define QTD_STS_XACT (1 << 3) /* device gave illegal response */
  256. #define QTD_STS_MMF (1 << 2) /* incomplete split transaction */
  257. #define QTD_STS_STS (1 << 1) /* split transaction state */
  258. #define QTD_STS_PING (1 << 0) /* issue PING? */
  259. #define ACTIVE_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_ACTIVE)
  260. #define HALT_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_HALT)
  261. #define STATUS_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_STS)
  262. __hc32 hw_buf [5]; /* see EHCI 3.5.4 */
  263. __hc32 hw_buf_hi [5]; /* Appendix B */
  264. /* the rest is HCD-private */
  265. dma_addr_t qtd_dma; /* qtd address */
  266. struct list_head qtd_list; /* sw qtd list */
  267. struct urb *urb; /* qtd's urb */
  268. size_t length; /* length of buffer */
  269. } __attribute__ ((aligned (32)));
  270. /* mask NakCnt+T in qh->hw_alt_next */
  271. #define QTD_MASK(ehci) cpu_to_hc32 (ehci, ~0x1f)
  272. #define IS_SHORT_READ(token) (QTD_LENGTH (token) != 0 && QTD_PID (token) == 1)
  273. /*-------------------------------------------------------------------------*/
  274. /* type tag from {qh,itd,sitd,fstn}->hw_next */
  275. #define Q_NEXT_TYPE(ehci,dma) ((dma) & cpu_to_hc32(ehci, 3 << 1))
  276. /*
  277. * Now the following defines are not converted using the
  278. * cpu_to_le32() macro anymore, since we have to support
  279. * "dynamic" switching between be and le support, so that the driver
  280. * can be used on one system with SoC EHCI controller using big-endian
  281. * descriptors as well as a normal little-endian PCI EHCI controller.
  282. */
  283. /* values for that type tag */
  284. #define Q_TYPE_ITD (0 << 1)
  285. #define Q_TYPE_QH (1 << 1)
  286. #define Q_TYPE_SITD (2 << 1)
  287. #define Q_TYPE_FSTN (3 << 1)
  288. /* next async queue entry, or pointer to interrupt/periodic QH */
  289. #define QH_NEXT(ehci,dma) (cpu_to_hc32(ehci, (((u32)dma)&~0x01f)|Q_TYPE_QH))
  290. /* for periodic/async schedules and qtd lists, mark end of list */
  291. #define EHCI_LIST_END(ehci) cpu_to_hc32(ehci, 1) /* "null pointer" to hw */
  292. /*
  293. * Entries in periodic shadow table are pointers to one of four kinds
  294. * of data structure. That's dictated by the hardware; a type tag is
  295. * encoded in the low bits of the hardware's periodic schedule. Use
  296. * Q_NEXT_TYPE to get the tag.
  297. *
  298. * For entries in the async schedule, the type tag always says "qh".
  299. */
  300. union ehci_shadow {
  301. struct ehci_qh *qh; /* Q_TYPE_QH */
  302. struct ehci_itd *itd; /* Q_TYPE_ITD */
  303. struct ehci_sitd *sitd; /* Q_TYPE_SITD */
  304. struct ehci_fstn *fstn; /* Q_TYPE_FSTN */
  305. __hc32 *hw_next; /* (all types) */
  306. void *ptr;
  307. };
  308. /*-------------------------------------------------------------------------*/
  309. /*
  310. * EHCI Specification 0.95 Section 3.6
  311. * QH: describes control/bulk/interrupt endpoints
  312. * See Fig 3-7 "Queue Head Structure Layout".
  313. *
  314. * These appear in both the async and (for interrupt) periodic schedules.
  315. */
  316. /* first part defined by EHCI spec */
  317. struct ehci_qh_hw {
  318. __hc32 hw_next; /* see EHCI 3.6.1 */
  319. __hc32 hw_info1; /* see EHCI 3.6.2 */
  320. #define QH_CONTROL_EP (1 << 27) /* FS/LS control endpoint */
  321. #define QH_HEAD (1 << 15) /* Head of async reclamation list */
  322. #define QH_TOGGLE_CTL (1 << 14) /* Data toggle control */
  323. #define QH_HIGH_SPEED (2 << 12) /* Endpoint speed */
  324. #define QH_LOW_SPEED (1 << 12)
  325. #define QH_FULL_SPEED (0 << 12)
  326. #define QH_INACTIVATE (1 << 7) /* Inactivate on next transaction */
  327. __hc32 hw_info2; /* see EHCI 3.6.2 */
  328. #define QH_SMASK 0x000000ff
  329. #define QH_CMASK 0x0000ff00
  330. #define QH_HUBADDR 0x007f0000
  331. #define QH_HUBPORT 0x3f800000
  332. #define QH_MULT 0xc0000000
  333. __hc32 hw_current; /* qtd list - see EHCI 3.6.4 */
  334. /* qtd overlay (hardware parts of a struct ehci_qtd) */
  335. __hc32 hw_qtd_next;
  336. __hc32 hw_alt_next;
  337. __hc32 hw_token;
  338. __hc32 hw_buf [5];
  339. __hc32 hw_buf_hi [5];
  340. } __attribute__ ((aligned(32)));
  341. struct ehci_qh {
  342. struct ehci_qh_hw *hw; /* Must come first */
  343. /* the rest is HCD-private */
  344. dma_addr_t qh_dma; /* address of qh */
  345. union ehci_shadow qh_next; /* ptr to qh; or periodic */
  346. struct list_head qtd_list; /* sw qtd list */
  347. struct list_head intr_node; /* list of intr QHs */
  348. struct ehci_qtd *dummy;
  349. struct list_head unlink_node;
  350. struct ehci_per_sched ps; /* scheduling info */
  351. unsigned unlink_cycle;
  352. u8 qh_state;
  353. #define QH_STATE_LINKED 1 /* HC sees this */
  354. #define QH_STATE_UNLINK 2 /* HC may still see this */
  355. #define QH_STATE_IDLE 3 /* HC doesn't see this */
  356. #define QH_STATE_UNLINK_WAIT 4 /* LINKED and on unlink q */
  357. #define QH_STATE_COMPLETING 5 /* don't touch token.HALT */
  358. u8 xacterrs; /* XactErr retry counter */
  359. #define QH_XACTERR_MAX 32 /* XactErr retry limit */
  360. u8 gap_uf; /* uframes split/csplit gap */
  361. unsigned is_out:1; /* bulk or intr OUT */
  362. unsigned clearing_tt:1; /* Clear-TT-Buf in progress */
  363. unsigned dequeue_during_giveback:1;
  364. unsigned exception:1; /* got a fault, or an unlink
  365. was requested */
  366. };
  367. /*-------------------------------------------------------------------------*/
  368. /* description of one iso transaction (up to 3 KB data if highspeed) */
  369. struct ehci_iso_packet {
  370. /* These will be copied to iTD when scheduling */
  371. u64 bufp; /* itd->hw_bufp{,_hi}[pg] |= */
  372. __hc32 transaction; /* itd->hw_transaction[i] |= */
  373. u8 cross; /* buf crosses pages */
  374. /* for full speed OUT splits */
  375. u32 buf1;
  376. };
  377. /* temporary schedule data for packets from iso urbs (both speeds)
  378. * each packet is one logical usb transaction to the device (not TT),
  379. * beginning at stream->next_uframe
  380. */
  381. struct ehci_iso_sched {
  382. struct list_head td_list;
  383. unsigned span;
  384. unsigned first_packet;
  385. struct ehci_iso_packet packet [0];
  386. };
  387. /*
  388. * ehci_iso_stream - groups all (s)itds for this endpoint.
  389. * acts like a qh would, if EHCI had them for ISO.
  390. */
  391. struct ehci_iso_stream {
  392. /* first field matches ehci_hq, but is NULL */
  393. struct ehci_qh_hw *hw;
  394. u8 bEndpointAddress;
  395. u8 highspeed;
  396. struct list_head td_list; /* queued itds/sitds */
  397. struct list_head free_list; /* list of unused itds/sitds */
  398. /* output of (re)scheduling */
  399. struct ehci_per_sched ps; /* scheduling info */
  400. unsigned next_uframe;
  401. __hc32 splits;
  402. /* the rest is derived from the endpoint descriptor,
  403. * including the extra info for hw_bufp[0..2]
  404. */
  405. u16 uperiod; /* period in uframes */
  406. u16 maxp;
  407. u16 raw_mask;
  408. unsigned bandwidth;
  409. /* This is used to initialize iTD's hw_bufp fields */
  410. __hc32 buf0;
  411. __hc32 buf1;
  412. __hc32 buf2;
  413. /* this is used to initialize sITD's tt info */
  414. __hc32 address;
  415. };
  416. /*-------------------------------------------------------------------------*/
  417. /*
  418. * EHCI Specification 0.95 Section 3.3
  419. * Fig 3-4 "Isochronous Transaction Descriptor (iTD)"
  420. *
  421. * Schedule records for high speed iso xfers
  422. */
  423. struct ehci_itd {
  424. /* first part defined by EHCI spec */
  425. __hc32 hw_next; /* see EHCI 3.3.1 */
  426. __hc32 hw_transaction [8]; /* see EHCI 3.3.2 */
  427. #define EHCI_ISOC_ACTIVE (1<<31) /* activate transfer this slot */
  428. #define EHCI_ISOC_BUF_ERR (1<<30) /* Data buffer error */
  429. #define EHCI_ISOC_BABBLE (1<<29) /* babble detected */
  430. #define EHCI_ISOC_XACTERR (1<<28) /* XactErr - transaction error */
  431. #define EHCI_ITD_LENGTH(tok) (((tok)>>16) & 0x0fff)
  432. #define EHCI_ITD_IOC (1 << 15) /* interrupt on complete */
  433. #define ITD_ACTIVE(ehci) cpu_to_hc32(ehci, EHCI_ISOC_ACTIVE)
  434. __hc32 hw_bufp [7]; /* see EHCI 3.3.3 */
  435. __hc32 hw_bufp_hi [7]; /* Appendix B */
  436. /* the rest is HCD-private */
  437. dma_addr_t itd_dma; /* for this itd */
  438. union ehci_shadow itd_next; /* ptr to periodic q entry */
  439. struct urb *urb;
  440. struct ehci_iso_stream *stream; /* endpoint's queue */
  441. struct list_head itd_list; /* list of stream's itds */
  442. /* any/all hw_transactions here may be used by that urb */
  443. unsigned frame; /* where scheduled */
  444. unsigned pg;
  445. unsigned index[8]; /* in urb->iso_frame_desc */
  446. } __attribute__ ((aligned (32)));
  447. /*-------------------------------------------------------------------------*/
  448. /*
  449. * EHCI Specification 0.95 Section 3.4
  450. * siTD, aka split-transaction isochronous Transfer Descriptor
  451. * ... describe full speed iso xfers through TT in hubs
  452. * see Figure 3-5 "Split-transaction Isochronous Transaction Descriptor (siTD)
  453. */
  454. struct ehci_sitd {
  455. /* first part defined by EHCI spec */
  456. __hc32 hw_next;
  457. /* uses bit field macros above - see EHCI 0.95 Table 3-8 */
  458. __hc32 hw_fullspeed_ep; /* EHCI table 3-9 */
  459. __hc32 hw_uframe; /* EHCI table 3-10 */
  460. __hc32 hw_results; /* EHCI table 3-11 */
  461. #define SITD_IOC (1 << 31) /* interrupt on completion */
  462. #define SITD_PAGE (1 << 30) /* buffer 0/1 */
  463. #define SITD_LENGTH(x) (0x3ff & ((x)>>16))
  464. #define SITD_STS_ACTIVE (1 << 7) /* HC may execute this */
  465. #define SITD_STS_ERR (1 << 6) /* error from TT */
  466. #define SITD_STS_DBE (1 << 5) /* data buffer error (in HC) */
  467. #define SITD_STS_BABBLE (1 << 4) /* device was babbling */
  468. #define SITD_STS_XACT (1 << 3) /* illegal IN response */
  469. #define SITD_STS_MMF (1 << 2) /* incomplete split transaction */
  470. #define SITD_STS_STS (1 << 1) /* split transaction state */
  471. #define SITD_ACTIVE(ehci) cpu_to_hc32(ehci, SITD_STS_ACTIVE)
  472. __hc32 hw_buf [2]; /* EHCI table 3-12 */
  473. __hc32 hw_backpointer; /* EHCI table 3-13 */
  474. __hc32 hw_buf_hi [2]; /* Appendix B */
  475. /* the rest is HCD-private */
  476. dma_addr_t sitd_dma;
  477. union ehci_shadow sitd_next; /* ptr to periodic q entry */
  478. struct urb *urb;
  479. struct ehci_iso_stream *stream; /* endpoint's queue */
  480. struct list_head sitd_list; /* list of stream's sitds */
  481. unsigned frame;
  482. unsigned index;
  483. } __attribute__ ((aligned (32)));
  484. /*-------------------------------------------------------------------------*/
  485. /*
  486. * EHCI Specification 0.96 Section 3.7
  487. * Periodic Frame Span Traversal Node (FSTN)
  488. *
  489. * Manages split interrupt transactions (using TT) that span frame boundaries
  490. * into uframes 0/1; see 4.12.2.2. In those uframes, a "save place" FSTN
  491. * makes the HC jump (back) to a QH to scan for fs/ls QH completions until
  492. * it hits a "restore" FSTN; then it returns to finish other uframe 0/1 work.
  493. */
  494. struct ehci_fstn {
  495. __hc32 hw_next; /* any periodic q entry */
  496. __hc32 hw_prev; /* qh or EHCI_LIST_END */
  497. /* the rest is HCD-private */
  498. dma_addr_t fstn_dma;
  499. union ehci_shadow fstn_next; /* ptr to periodic q entry */
  500. } __attribute__ ((aligned (32)));
  501. /*-------------------------------------------------------------------------*/
  502. /* Prepare the PORTSC wakeup flags during controller suspend/resume */
  503. #define ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup) \
  504. ehci_adjust_port_wakeup_flags(ehci, true, do_wakeup);
  505. #define ehci_prepare_ports_for_controller_resume(ehci) \
  506. ehci_adjust_port_wakeup_flags(ehci, false, false);
  507. /*-------------------------------------------------------------------------*/
  508. #ifdef CONFIG_USB_EHCI_ROOT_HUB_TT
  509. /*
  510. * Some EHCI controllers have a Transaction Translator built into the
  511. * root hub. This is a non-standard feature. Each controller will need
  512. * to add code to the following inline functions, and call them as
  513. * needed (mostly in root hub code).
  514. */
  515. #define ehci_is_TDI(e) (ehci_to_hcd(e)->has_tt)
  516. /* Returns the speed of a device attached to a port on the root hub. */
  517. static inline unsigned int
  518. ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc)
  519. {
  520. if (ehci_is_TDI(ehci)) {
  521. switch ((portsc >> (ehci->has_hostpc ? 25 : 26)) & 3) {
  522. case 0:
  523. return 0;
  524. case 1:
  525. return USB_PORT_STAT_LOW_SPEED;
  526. case 2:
  527. default:
  528. return USB_PORT_STAT_HIGH_SPEED;
  529. }
  530. }
  531. return USB_PORT_STAT_HIGH_SPEED;
  532. }
  533. #else
  534. #define ehci_is_TDI(e) (0)
  535. #define ehci_port_speed(ehci, portsc) USB_PORT_STAT_HIGH_SPEED
  536. #endif
  537. /*-------------------------------------------------------------------------*/
  538. #ifdef CONFIG_PPC_83xx
  539. /* Some Freescale processors have an erratum in which the TT
  540. * port number in the queue head was 0..N-1 instead of 1..N.
  541. */
  542. #define ehci_has_fsl_portno_bug(e) ((e)->has_fsl_port_bug)
  543. #else
  544. #define ehci_has_fsl_portno_bug(e) (0)
  545. #endif
  546. /*
  547. * While most USB host controllers implement their registers in
  548. * little-endian format, a minority (celleb companion chip) implement
  549. * them in big endian format.
  550. *
  551. * This attempts to support either format at compile time without a
  552. * runtime penalty, or both formats with the additional overhead
  553. * of checking a flag bit.
  554. *
  555. * ehci_big_endian_capbase is a special quirk for controllers that
  556. * implement the HC capability registers as separate registers and not
  557. * as fields of a 32-bit register.
  558. */
  559. #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
  560. #define ehci_big_endian_mmio(e) ((e)->big_endian_mmio)
  561. #define ehci_big_endian_capbase(e) ((e)->big_endian_capbase)
  562. #else
  563. #define ehci_big_endian_mmio(e) 0
  564. #define ehci_big_endian_capbase(e) 0
  565. #endif
  566. /*
  567. * Big-endian read/write functions are arch-specific.
  568. * Other arches can be added if/when they're needed.
  569. */
  570. #if defined(CONFIG_ARM) && defined(CONFIG_ARCH_IXP4XX)
  571. #define readl_be(addr) __raw_readl((__force unsigned *)addr)
  572. #define writel_be(val, addr) __raw_writel(val, (__force unsigned *)addr)
  573. #endif
  574. static inline unsigned int ehci_readl(const struct ehci_hcd *ehci,
  575. __u32 __iomem * regs)
  576. {
  577. #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
  578. return ehci_big_endian_mmio(ehci) ?
  579. readl_be(regs) :
  580. readl(regs);
  581. #else
  582. return readl(regs);
  583. #endif
  584. }
  585. static inline void ehci_writel(const struct ehci_hcd *ehci,
  586. const unsigned int val, __u32 __iomem *regs)
  587. {
  588. #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
  589. ehci_big_endian_mmio(ehci) ?
  590. writel_be(val, regs) :
  591. writel(val, regs);
  592. #else
  593. writel(val, regs);
  594. #endif
  595. }
  596. /*
  597. * On certain ppc-44x SoC there is a HW issue, that could only worked around with
  598. * explicit suspend/operate of OHCI. This function hereby makes sense only on that arch.
  599. * Other common bits are dependent on has_amcc_usb23 quirk flag.
  600. */
  601. #ifdef CONFIG_44x
  602. static inline void set_ohci_hcfs(struct ehci_hcd *ehci, int operational)
  603. {
  604. u32 hc_control;
  605. hc_control = (readl_be(ehci->ohci_hcctrl_reg) & ~OHCI_CTRL_HCFS);
  606. if (operational)
  607. hc_control |= OHCI_USB_OPER;
  608. else
  609. hc_control |= OHCI_USB_SUSPEND;
  610. writel_be(hc_control, ehci->ohci_hcctrl_reg);
  611. (void) readl_be(ehci->ohci_hcctrl_reg);
  612. }
  613. #else
  614. static inline void set_ohci_hcfs(struct ehci_hcd *ehci, int operational)
  615. { }
  616. #endif
  617. /*-------------------------------------------------------------------------*/
  618. /*
  619. * The AMCC 440EPx not only implements its EHCI registers in big-endian
  620. * format, but also its DMA data structures (descriptors).
  621. *
  622. * EHCI controllers accessed through PCI work normally (little-endian
  623. * everywhere), so we won't bother supporting a BE-only mode for now.
  624. */
  625. #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_DESC
  626. #define ehci_big_endian_desc(e) ((e)->big_endian_desc)
  627. /* cpu to ehci */
  628. static inline __hc32 cpu_to_hc32 (const struct ehci_hcd *ehci, const u32 x)
  629. {
  630. return ehci_big_endian_desc(ehci)
  631. ? (__force __hc32)cpu_to_be32(x)
  632. : (__force __hc32)cpu_to_le32(x);
  633. }
  634. /* ehci to cpu */
  635. static inline u32 hc32_to_cpu (const struct ehci_hcd *ehci, const __hc32 x)
  636. {
  637. return ehci_big_endian_desc(ehci)
  638. ? be32_to_cpu((__force __be32)x)
  639. : le32_to_cpu((__force __le32)x);
  640. }
  641. static inline u32 hc32_to_cpup (const struct ehci_hcd *ehci, const __hc32 *x)
  642. {
  643. return ehci_big_endian_desc(ehci)
  644. ? be32_to_cpup((__force __be32 *)x)
  645. : le32_to_cpup((__force __le32 *)x);
  646. }
  647. #else
  648. /* cpu to ehci */
  649. static inline __hc32 cpu_to_hc32 (const struct ehci_hcd *ehci, const u32 x)
  650. {
  651. return cpu_to_le32(x);
  652. }
  653. /* ehci to cpu */
  654. static inline u32 hc32_to_cpu (const struct ehci_hcd *ehci, const __hc32 x)
  655. {
  656. return le32_to_cpu(x);
  657. }
  658. static inline u32 hc32_to_cpup (const struct ehci_hcd *ehci, const __hc32 *x)
  659. {
  660. return le32_to_cpup(x);
  661. }
  662. #endif
  663. /*-------------------------------------------------------------------------*/
  664. #define ehci_dbg(ehci, fmt, args...) \
  665. dev_dbg(ehci_to_hcd(ehci)->self.controller , fmt , ## args)
  666. #define ehci_err(ehci, fmt, args...) \
  667. dev_err(ehci_to_hcd(ehci)->self.controller , fmt , ## args)
  668. #define ehci_info(ehci, fmt, args...) \
  669. dev_info(ehci_to_hcd(ehci)->self.controller , fmt , ## args)
  670. #define ehci_warn(ehci, fmt, args...) \
  671. dev_warn(ehci_to_hcd(ehci)->self.controller , fmt , ## args)
  672. #if !defined(DEBUG) && !defined(CONFIG_DYNAMIC_DEBUG)
  673. #define STUB_DEBUG_FILES
  674. #endif /* !DEBUG && !CONFIG_DYNAMIC_DEBUG */
  675. /*-------------------------------------------------------------------------*/
  676. /* Declarations of things exported for use by ehci platform drivers */
  677. struct ehci_driver_overrides {
  678. size_t extra_priv_size;
  679. int (*reset)(struct usb_hcd *hcd);
  680. };
  681. extern void ehci_init_driver(struct hc_driver *drv,
  682. const struct ehci_driver_overrides *over);
  683. extern int ehci_setup(struct usb_hcd *hcd);
  684. extern int ehci_handshake(struct ehci_hcd *ehci, void __iomem *ptr,
  685. u32 mask, u32 done, int usec);
  686. #ifdef CONFIG_PM
  687. extern int ehci_suspend(struct usb_hcd *hcd, bool do_wakeup);
  688. extern int ehci_resume(struct usb_hcd *hcd, bool hibernated);
  689. #endif /* CONFIG_PM */
  690. #endif /* __LINUX_EHCI_HCD_H */