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