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