1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#ifndef __LINUX_EHCI_HCD_H
20#define __LINUX_EHCI_HCD_H
21
22
23
24
25
26
27
28
29
30
31
32#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_DESC
33typedef __u32 __bitwise __hc32;
34typedef __u16 __bitwise __hc16;
35#else
36#define __hc32 __le32
37#define __hc16 __le16
38#endif
39
40
41struct ehci_stats {
42
43 unsigned long normal;
44 unsigned long error;
45 unsigned long iaa;
46 unsigned long lost_iaa;
47
48
49 unsigned long complete;
50 unsigned long unlink;
51};
52
53
54
55
56
57
58
59
60
61
62
63#define EHCI_MAX_ROOT_PORTS 15
64
65
66
67
68
69enum ehci_rh_state {
70 EHCI_RH_HALTED,
71 EHCI_RH_SUSPENDED,
72 EHCI_RH_RUNNING,
73 EHCI_RH_STOPPING
74};
75
76
77
78
79
80
81enum ehci_hrtimer_event {
82 EHCI_HRTIMER_POLL_ASS,
83 EHCI_HRTIMER_POLL_PSS,
84 EHCI_HRTIMER_POLL_DEAD,
85 EHCI_HRTIMER_UNLINK_INTR,
86 EHCI_HRTIMER_FREE_ITDS,
87 EHCI_HRTIMER_ASYNC_UNLINKS,
88 EHCI_HRTIMER_IAA_WATCHDOG,
89 EHCI_HRTIMER_DISABLE_PERIODIC,
90 EHCI_HRTIMER_DISABLE_ASYNC,
91 EHCI_HRTIMER_IO_WATCHDOG,
92 EHCI_HRTIMER_NUM_EVENTS
93};
94#define EHCI_HRTIMER_NO_EVENT 99
95
96struct ehci_hcd {
97
98 enum ehci_hrtimer_event next_hrtimer_event;
99 unsigned enabled_hrtimer_events;
100 ktime_t hr_timeouts[EHCI_HRTIMER_NUM_EVENTS];
101 struct hrtimer hrtimer;
102
103 int PSS_poll_count;
104 int ASS_poll_count;
105 int died_poll_count;
106
107
108 struct ehci_caps __iomem *caps;
109 struct ehci_regs __iomem *regs;
110 struct ehci_dbg_port __iomem *debug;
111
112 __u32 hcs_params;
113 spinlock_t lock;
114 enum ehci_rh_state rh_state;
115
116
117 bool scanning:1;
118 bool need_rescan:1;
119 bool intr_unlinking:1;
120 bool async_unlinking:1;
121 bool shutdown:1;
122 struct ehci_qh *qh_scan_next;
123
124
125 struct ehci_qh *async;
126 struct ehci_qh *dummy;
127 struct ehci_qh *async_unlink;
128 struct ehci_qh *async_unlink_last;
129 struct ehci_qh *async_iaa;
130 unsigned async_unlink_cycle;
131 unsigned async_count;
132
133
134#define DEFAULT_I_TDPS 1024
135 unsigned periodic_size;
136 __hc32 *periodic;
137 dma_addr_t periodic_dma;
138 struct list_head intr_qh_list;
139 unsigned i_thresh;
140
141 union ehci_shadow *pshadow;
142 struct ehci_qh *intr_unlink;
143 struct ehci_qh *intr_unlink_last;
144 unsigned intr_unlink_cycle;
145 unsigned now_frame;
146 unsigned next_frame;
147 unsigned intr_count;
148 unsigned isoc_count;
149 unsigned periodic_count;
150 unsigned uframe_periodic_max;
151
152
153
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
159
160 unsigned long reset_done [EHCI_MAX_ROOT_PORTS];
161
162
163 unsigned long bus_suspended;
164
165 unsigned long companion_ports;
166
167 unsigned long owned_ports;
168
169 unsigned long port_c_suspend;
170
171 unsigned long suspended_ports;
172
173 unsigned long resuming_ports;
174
175
176
177 struct dma_pool *qh_pool;
178 struct dma_pool *qtd_pool;
179 struct dma_pool *itd_pool;
180 struct dma_pool *sitd_pool;
181
182 unsigned random_frame;
183 unsigned long next_statechange;
184 ktime_t last_periodic_enable;
185 u32 command;
186
187
188 unsigned no_selective_suspend:1;
189 unsigned has_fsl_port_bug:1;
190 unsigned big_endian_mmio:1;
191 unsigned big_endian_desc:1;
192 unsigned big_endian_capbase:1;
193 unsigned has_amcc_usb23:1;
194 unsigned need_io_watchdog:1;
195 unsigned amd_pll_fix:1;
196 unsigned fs_i_thresh:1;
197 unsigned use_dummy_qh:1;
198 unsigned has_synopsys_hc_bug:1;
199 unsigned frame_index_bug:1;
200
201
202 #define OHCI_CTRL_HCFS (3 << 6)
203 #define OHCI_USB_OPER (2 << 6)
204 #define OHCI_USB_SUSPEND (3 << 6)
205
206 #define OHCI_HCCTRL_OFFSET 0x4
207 #define OHCI_HCCTRL_LEN 0x4
208 __hc32 *ohci_hcctrl_reg;
209 unsigned has_hostpc:1;
210 unsigned has_lpm:1;
211 unsigned has_ppcd:1;
212 u8 sbrn;
213
214
215#ifdef EHCI_STATS
216 struct ehci_stats stats;
217# define COUNT(x) do { (x)++; } while (0)
218#else
219# define COUNT(x) do {} while (0)
220#endif
221
222
223#ifdef DEBUG
224 struct dentry *debug_dir;
225#endif
226};
227
228
229static inline struct ehci_hcd *hcd_to_ehci (struct usb_hcd *hcd)
230{
231 return (struct ehci_hcd *) (hcd->hcd_priv);
232}
233static inline struct usb_hcd *ehci_to_hcd (struct ehci_hcd *ehci)
234{
235 return container_of ((void *) ehci, struct usb_hcd, hcd_priv);
236}
237
238
239
240#include <linux/usb/ehci_def.h>
241
242
243
244#define QTD_NEXT(ehci, dma) cpu_to_hc32(ehci, (u32)dma)
245
246
247
248
249
250
251
252
253
254struct ehci_qtd {
255
256 __hc32 hw_next;
257 __hc32 hw_alt_next;
258 __hc32 hw_token;
259#define QTD_TOGGLE (1 << 31)
260#define QTD_LENGTH(tok) (((tok)>>16) & 0x7fff)
261#define QTD_IOC (1 << 15)
262#define QTD_CERR(tok) (((tok)>>10) & 0x3)
263#define QTD_PID(tok) (((tok)>>8) & 0x3)
264#define QTD_STS_ACTIVE (1 << 7)
265#define QTD_STS_HALT (1 << 6)
266#define QTD_STS_DBE (1 << 5)
267#define QTD_STS_BABBLE (1 << 4)
268#define QTD_STS_XACT (1 << 3)
269#define QTD_STS_MMF (1 << 2)
270#define QTD_STS_STS (1 << 1)
271#define QTD_STS_PING (1 << 0)
272
273#define ACTIVE_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_ACTIVE)
274#define HALT_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_HALT)
275#define STATUS_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_STS)
276
277 __hc32 hw_buf [5];
278 __hc32 hw_buf_hi [5];
279
280
281 dma_addr_t qtd_dma;
282 struct list_head qtd_list;
283 struct urb *urb;
284 size_t length;
285} __attribute__ ((aligned (32)));
286
287
288#define QTD_MASK(ehci) cpu_to_hc32 (ehci, ~0x1f)
289
290#define IS_SHORT_READ(token) (QTD_LENGTH (token) != 0 && QTD_PID (token) == 1)
291
292
293
294
295#define Q_NEXT_TYPE(ehci,dma) ((dma) & cpu_to_hc32(ehci, 3 << 1))
296
297
298
299
300
301
302
303
304
305#define Q_TYPE_ITD (0 << 1)
306#define Q_TYPE_QH (1 << 1)
307#define Q_TYPE_SITD (2 << 1)
308#define Q_TYPE_FSTN (3 << 1)
309
310
311#define QH_NEXT(ehci,dma) (cpu_to_hc32(ehci, (((u32)dma)&~0x01f)|Q_TYPE_QH))
312
313
314#define EHCI_LIST_END(ehci) cpu_to_hc32(ehci, 1)
315
316
317
318
319
320
321
322
323
324union ehci_shadow {
325 struct ehci_qh *qh;
326 struct ehci_itd *itd;
327 struct ehci_sitd *sitd;
328 struct ehci_fstn *fstn;
329 __hc32 *hw_next;
330 void *ptr;
331};
332
333
334
335
336
337
338
339
340
341
342
343
344struct ehci_qh_hw {
345 __hc32 hw_next;
346 __hc32 hw_info1;
347#define QH_CONTROL_EP (1 << 27)
348#define QH_HEAD (1 << 15)
349#define QH_TOGGLE_CTL (1 << 14)
350#define QH_HIGH_SPEED (2 << 12)
351#define QH_LOW_SPEED (1 << 12)
352#define QH_FULL_SPEED (0 << 12)
353#define QH_INACTIVATE (1 << 7)
354 __hc32 hw_info2;
355#define QH_SMASK 0x000000ff
356#define QH_CMASK 0x0000ff00
357#define QH_HUBADDR 0x007f0000
358#define QH_HUBPORT 0x3f800000
359#define QH_MULT 0xc0000000
360 __hc32 hw_current;
361
362
363 __hc32 hw_qtd_next;
364 __hc32 hw_alt_next;
365 __hc32 hw_token;
366 __hc32 hw_buf [5];
367 __hc32 hw_buf_hi [5];
368} __attribute__ ((aligned(32)));
369
370struct ehci_qh {
371 struct ehci_qh_hw *hw;
372
373 dma_addr_t qh_dma;
374 union ehci_shadow qh_next;
375 struct list_head qtd_list;
376 struct list_head intr_node;
377 struct ehci_qtd *dummy;
378 struct ehci_qh *unlink_next;
379
380 unsigned unlink_cycle;
381
382 u8 needs_rescan;
383 u8 qh_state;
384#define QH_STATE_LINKED 1
385#define QH_STATE_UNLINK 2
386#define QH_STATE_IDLE 3
387#define QH_STATE_UNLINK_WAIT 4
388#define QH_STATE_COMPLETING 5
389
390 u8 xacterrs;
391#define QH_XACTERR_MAX 32
392
393
394 u8 usecs;
395 u8 gap_uf;
396 u8 c_usecs;
397 u16 tt_usecs;
398 unsigned short period;
399 unsigned short start;
400#define NO_FRAME ((unsigned short)~0)
401
402 struct usb_device *dev;
403 unsigned is_out:1;
404 unsigned clearing_tt:1;
405};
406
407
408
409
410struct ehci_iso_packet {
411
412 u64 bufp;
413 __hc32 transaction;
414 u8 cross;
415
416 u32 buf1;
417};
418
419
420
421
422
423struct ehci_iso_sched {
424 struct list_head td_list;
425 unsigned span;
426 struct ehci_iso_packet packet [0];
427};
428
429
430
431
432
433struct ehci_iso_stream {
434
435 struct ehci_qh_hw *hw;
436
437 u8 bEndpointAddress;
438 u8 highspeed;
439 struct list_head td_list;
440 struct list_head free_list;
441 struct usb_device *udev;
442 struct usb_host_endpoint *ep;
443
444
445 int next_uframe;
446 __hc32 splits;
447
448
449
450
451
452 u8 usecs, c_usecs;
453 u16 interval;
454 u16 tt_usecs;
455 u16 maxp;
456 u16 raw_mask;
457 unsigned bandwidth;
458
459
460 __hc32 buf0;
461 __hc32 buf1;
462 __hc32 buf2;
463
464
465 __hc32 address;
466};
467
468
469
470
471
472
473
474
475
476struct ehci_itd {
477
478 __hc32 hw_next;
479 __hc32 hw_transaction [8];
480#define EHCI_ISOC_ACTIVE (1<<31)
481#define EHCI_ISOC_BUF_ERR (1<<30)
482#define EHCI_ISOC_BABBLE (1<<29)
483#define EHCI_ISOC_XACTERR (1<<28)
484#define EHCI_ITD_LENGTH(tok) (((tok)>>16) & 0x0fff)
485#define EHCI_ITD_IOC (1 << 15)
486
487#define ITD_ACTIVE(ehci) cpu_to_hc32(ehci, EHCI_ISOC_ACTIVE)
488
489 __hc32 hw_bufp [7];
490 __hc32 hw_bufp_hi [7];
491
492
493 dma_addr_t itd_dma;
494 union ehci_shadow itd_next;
495
496 struct urb *urb;
497 struct ehci_iso_stream *stream;
498 struct list_head itd_list;
499
500
501 unsigned frame;
502 unsigned pg;
503 unsigned index[8];
504} __attribute__ ((aligned (32)));
505
506
507
508
509
510
511
512
513
514struct ehci_sitd {
515
516 __hc32 hw_next;
517
518 __hc32 hw_fullspeed_ep;
519 __hc32 hw_uframe;
520 __hc32 hw_results;
521#define SITD_IOC (1 << 31)
522#define SITD_PAGE (1 << 30)
523#define SITD_LENGTH(x) (0x3ff & ((x)>>16))
524#define SITD_STS_ACTIVE (1 << 7)
525#define SITD_STS_ERR (1 << 6)
526#define SITD_STS_DBE (1 << 5)
527#define SITD_STS_BABBLE (1 << 4)
528#define SITD_STS_XACT (1 << 3)
529#define SITD_STS_MMF (1 << 2)
530#define SITD_STS_STS (1 << 1)
531
532#define SITD_ACTIVE(ehci) cpu_to_hc32(ehci, SITD_STS_ACTIVE)
533
534 __hc32 hw_buf [2];
535 __hc32 hw_backpointer;
536 __hc32 hw_buf_hi [2];
537
538
539 dma_addr_t sitd_dma;
540 union ehci_shadow sitd_next;
541
542 struct urb *urb;
543 struct ehci_iso_stream *stream;
544 struct list_head sitd_list;
545 unsigned frame;
546 unsigned index;
547} __attribute__ ((aligned (32)));
548
549
550
551
552
553
554
555
556
557
558
559
560struct ehci_fstn {
561 __hc32 hw_next;
562 __hc32 hw_prev;
563
564
565 dma_addr_t fstn_dma;
566 union ehci_shadow fstn_next;
567} __attribute__ ((aligned (32)));
568
569
570
571
572
573#define ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup) \
574 ehci_adjust_port_wakeup_flags(ehci, true, do_wakeup);
575
576#define ehci_prepare_ports_for_controller_resume(ehci) \
577 ehci_adjust_port_wakeup_flags(ehci, false, false);
578
579
580
581#ifdef CONFIG_USB_EHCI_ROOT_HUB_TT
582
583
584
585
586
587
588
589
590#define ehci_is_TDI(e) (ehci_to_hcd(e)->has_tt)
591
592
593static inline unsigned int
594ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc)
595{
596 if (ehci_is_TDI(ehci)) {
597 switch ((portsc >> (ehci->has_hostpc ? 25 : 26)) & 3) {
598 case 0:
599 return 0;
600 case 1:
601 return USB_PORT_STAT_LOW_SPEED;
602 case 2:
603 default:
604 return USB_PORT_STAT_HIGH_SPEED;
605 }
606 }
607 return USB_PORT_STAT_HIGH_SPEED;
608}
609
610#else
611
612#define ehci_is_TDI(e) (0)
613
614#define ehci_port_speed(ehci, portsc) USB_PORT_STAT_HIGH_SPEED
615#endif
616
617
618
619#ifdef CONFIG_PPC_83xx
620
621
622
623#define ehci_has_fsl_portno_bug(e) ((e)->has_fsl_port_bug)
624#else
625#define ehci_has_fsl_portno_bug(e) (0)
626#endif
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
643#define ehci_big_endian_mmio(e) ((e)->big_endian_mmio)
644#define ehci_big_endian_capbase(e) ((e)->big_endian_capbase)
645#else
646#define ehci_big_endian_mmio(e) 0
647#define ehci_big_endian_capbase(e) 0
648#endif
649
650
651
652
653
654#if defined(CONFIG_ARM) && defined(CONFIG_ARCH_IXP4XX)
655#define readl_be(addr) __raw_readl((__force unsigned *)addr)
656#define writel_be(val, addr) __raw_writel(val, (__force unsigned *)addr)
657#endif
658
659static inline unsigned int ehci_readl(const struct ehci_hcd *ehci,
660 __u32 __iomem * regs)
661{
662#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
663 return ehci_big_endian_mmio(ehci) ?
664 readl_be(regs) :
665 readl(regs);
666#else
667 return readl(regs);
668#endif
669}
670
671static inline void ehci_writel(const struct ehci_hcd *ehci,
672 const unsigned int val, __u32 __iomem *regs)
673{
674#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
675 ehci_big_endian_mmio(ehci) ?
676 writel_be(val, regs) :
677 writel(val, regs);
678#else
679 writel(val, regs);
680#endif
681}
682
683
684
685
686
687
688#ifdef CONFIG_44x
689static inline void set_ohci_hcfs(struct ehci_hcd *ehci, int operational)
690{
691 u32 hc_control;
692
693 hc_control = (readl_be(ehci->ohci_hcctrl_reg) & ~OHCI_CTRL_HCFS);
694 if (operational)
695 hc_control |= OHCI_USB_OPER;
696 else
697 hc_control |= OHCI_USB_SUSPEND;
698
699 writel_be(hc_control, ehci->ohci_hcctrl_reg);
700 (void) readl_be(ehci->ohci_hcctrl_reg);
701}
702#else
703static inline void set_ohci_hcfs(struct ehci_hcd *ehci, int operational)
704{ }
705#endif
706
707
708
709
710
711
712
713
714
715
716#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_DESC
717#define ehci_big_endian_desc(e) ((e)->big_endian_desc)
718
719
720static inline __hc32 cpu_to_hc32 (const struct ehci_hcd *ehci, const u32 x)
721{
722 return ehci_big_endian_desc(ehci)
723 ? (__force __hc32)cpu_to_be32(x)
724 : (__force __hc32)cpu_to_le32(x);
725}
726
727
728static inline u32 hc32_to_cpu (const struct ehci_hcd *ehci, const __hc32 x)
729{
730 return ehci_big_endian_desc(ehci)
731 ? be32_to_cpu((__force __be32)x)
732 : le32_to_cpu((__force __le32)x);
733}
734
735static inline u32 hc32_to_cpup (const struct ehci_hcd *ehci, const __hc32 *x)
736{
737 return ehci_big_endian_desc(ehci)
738 ? be32_to_cpup((__force __be32 *)x)
739 : le32_to_cpup((__force __le32 *)x);
740}
741
742#else
743
744
745static inline __hc32 cpu_to_hc32 (const struct ehci_hcd *ehci, const u32 x)
746{
747 return cpu_to_le32(x);
748}
749
750
751static inline u32 hc32_to_cpu (const struct ehci_hcd *ehci, const __hc32 x)
752{
753 return le32_to_cpu(x);
754}
755
756static inline u32 hc32_to_cpup (const struct ehci_hcd *ehci, const __hc32 *x)
757{
758 return le32_to_cpup(x);
759}
760
761#endif
762
763
764
765#ifdef CONFIG_PCI
766
767
768static unsigned ehci_read_frame_index(struct ehci_hcd *ehci);
769
770#else
771
772static inline unsigned ehci_read_frame_index(struct ehci_hcd *ehci)
773{
774 return ehci_readl(ehci, &ehci->regs->frame_index);
775}
776
777#endif
778
779
780
781#ifndef DEBUG
782#define STUB_DEBUG_FILES
783#endif
784
785
786
787#endif
788