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 reclaim;
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
65struct ehci_hcd {
66
67 struct ehci_caps __iomem *caps;
68 struct ehci_regs __iomem *regs;
69 struct ehci_dbg_port __iomem *debug;
70
71 __u32 hcs_params;
72 spinlock_t lock;
73
74
75 struct ehci_qh *async;
76 struct ehci_qh *reclaim;
77 unsigned reclaim_ready : 1;
78 unsigned scanning : 1;
79
80
81#define DEFAULT_I_TDPS 1024
82 unsigned periodic_size;
83 __hc32 *periodic;
84 dma_addr_t periodic_dma;
85 unsigned i_thresh;
86
87 union ehci_shadow *pshadow;
88 int next_uframe;
89 unsigned periodic_sched;
90
91
92 unsigned long reset_done [EHCI_MAX_ROOT_PORTS];
93
94
95 unsigned long bus_suspended;
96
97 unsigned long companion_ports;
98
99 unsigned long owned_ports;
100
101
102
103 struct dma_pool *qh_pool;
104 struct dma_pool *qtd_pool;
105 struct dma_pool *itd_pool;
106 struct dma_pool *sitd_pool;
107
108 struct timer_list watchdog;
109 unsigned long actions;
110 unsigned stamp;
111 unsigned long next_statechange;
112 u32 command;
113
114
115 unsigned is_tdi_rh_tt:1;
116 unsigned no_selective_suspend:1;
117 unsigned has_fsl_port_bug:1;
118 unsigned big_endian_mmio:1;
119 unsigned big_endian_desc:1;
120
121 u8 sbrn;
122
123
124#ifdef EHCI_STATS
125 struct ehci_stats stats;
126# define COUNT(x) do { (x)++; } while (0)
127#else
128# define COUNT(x) do {} while (0)
129#endif
130};
131
132
133static inline struct ehci_hcd *hcd_to_ehci (struct usb_hcd *hcd)
134{
135 return (struct ehci_hcd *) (hcd->hcd_priv);
136}
137static inline struct usb_hcd *ehci_to_hcd (struct ehci_hcd *ehci)
138{
139 return container_of ((void *) ehci, struct usb_hcd, hcd_priv);
140}
141
142
143enum ehci_timer_action {
144 TIMER_IO_WATCHDOG,
145 TIMER_IAA_WATCHDOG,
146 TIMER_ASYNC_SHRINK,
147 TIMER_ASYNC_OFF,
148};
149
150static inline void
151timer_action_done (struct ehci_hcd *ehci, enum ehci_timer_action action)
152{
153 clear_bit (action, &ehci->actions);
154}
155
156static inline void
157timer_action (struct ehci_hcd *ehci, enum ehci_timer_action action)
158{
159 if (!test_and_set_bit (action, &ehci->actions)) {
160 unsigned long t;
161
162 switch (action) {
163 case TIMER_IAA_WATCHDOG:
164 t = EHCI_IAA_JIFFIES;
165 break;
166 case TIMER_IO_WATCHDOG:
167 t = EHCI_IO_JIFFIES;
168 break;
169 case TIMER_ASYNC_OFF:
170 t = EHCI_ASYNC_JIFFIES;
171 break;
172
173 default:
174 t = EHCI_SHRINK_JIFFIES;
175 break;
176 }
177 t += jiffies;
178
179
180
181
182 if (action != TIMER_IAA_WATCHDOG
183 && t > ehci->watchdog.expires
184 && timer_pending (&ehci->watchdog))
185 return;
186 mod_timer (&ehci->watchdog, t);
187 }
188}
189
190
191
192
193
194
195struct ehci_caps {
196
197
198
199 u32 hc_capbase;
200#define HC_LENGTH(p) (((p)>>00)&0x00ff)
201#define HC_VERSION(p) (((p)>>16)&0xffff)
202 u32 hcs_params;
203#define HCS_DEBUG_PORT(p) (((p)>>20)&0xf)
204#define HCS_INDICATOR(p) ((p)&(1 << 16))
205#define HCS_N_CC(p) (((p)>>12)&0xf)
206#define HCS_N_PCC(p) (((p)>>8)&0xf)
207#define HCS_PORTROUTED(p) ((p)&(1 << 7))
208#define HCS_PPC(p) ((p)&(1 << 4))
209#define HCS_N_PORTS(p) (((p)>>0)&0xf)
210
211 u32 hcc_params;
212#define HCC_EXT_CAPS(p) (((p)>>8)&0xff)
213#define HCC_ISOC_CACHE(p) ((p)&(1 << 7))
214#define HCC_ISOC_THRES(p) (((p)>>4)&0x7)
215#define HCC_CANPARK(p) ((p)&(1 << 2))
216#define HCC_PGM_FRAMELISTLEN(p) ((p)&(1 << 1))
217#define HCC_64BIT_ADDR(p) ((p)&(1))
218 u8 portroute [8];
219} __attribute__ ((packed));
220
221
222
223struct ehci_regs {
224
225
226 u32 command;
227
228#define CMD_PARK (1<<11)
229#define CMD_PARK_CNT(c) (((c)>>8)&3)
230#define CMD_LRESET (1<<7)
231#define CMD_IAAD (1<<6)
232#define CMD_ASE (1<<5)
233#define CMD_PSE (1<<4)
234
235#define CMD_RESET (1<<1)
236#define CMD_RUN (1<<0)
237
238
239 u32 status;
240#define STS_ASS (1<<15)
241#define STS_PSS (1<<14)
242#define STS_RECL (1<<13)
243#define STS_HALT (1<<12)
244
245
246#define STS_IAA (1<<5)
247#define STS_FATAL (1<<4)
248#define STS_FLR (1<<3)
249#define STS_PCD (1<<2)
250#define STS_ERR (1<<1)
251#define STS_INT (1<<0)
252
253
254 u32 intr_enable;
255
256
257 u32 frame_index;
258
259 u32 segment;
260
261 u32 frame_list;
262
263 u32 async_next;
264
265 u32 reserved [9];
266
267
268 u32 configured_flag;
269#define FLAG_CF (1<<0)
270
271
272 u32 port_status [0];
273
274#define PORT_WKOC_E (1<<22)
275#define PORT_WKDISC_E (1<<21)
276#define PORT_WKCONN_E (1<<20)
277
278#define PORT_LED_OFF (0<<14)
279#define PORT_LED_AMBER (1<<14)
280#define PORT_LED_GREEN (2<<14)
281#define PORT_LED_MASK (3<<14)
282#define PORT_OWNER (1<<13)
283#define PORT_POWER (1<<12)
284#define PORT_USB11(x) (((x)&(3<<10))==(1<<10))
285
286
287#define PORT_RESET (1<<8)
288#define PORT_SUSPEND (1<<7)
289#define PORT_RESUME (1<<6)
290#define PORT_OCC (1<<5)
291#define PORT_OC (1<<4)
292#define PORT_PEC (1<<3)
293#define PORT_PE (1<<2)
294#define PORT_CSC (1<<1)
295#define PORT_CONNECT (1<<0)
296#define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC)
297} __attribute__ ((packed));
298
299#define USBMODE 0x68
300#define USBMODE_SDIS (1<<3)
301#define USBMODE_BE (1<<2)
302#define USBMODE_CM_HC (3<<0)
303#define USBMODE_CM_IDLE (0<<0)
304
305
306
307
308struct ehci_dbg_port {
309 u32 control;
310#define DBGP_OWNER (1<<30)
311#define DBGP_ENABLED (1<<28)
312#define DBGP_DONE (1<<16)
313#define DBGP_INUSE (1<<10)
314#define DBGP_ERRCODE(x) (((x)>>7)&0x07)
315# define DBGP_ERR_BAD 1
316# define DBGP_ERR_SIGNAL 2
317#define DBGP_ERROR (1<<6)
318#define DBGP_GO (1<<5)
319#define DBGP_OUT (1<<4)
320#define DBGP_LEN(x) (((x)>>0)&0x0f)
321 u32 pids;
322#define DBGP_PID_GET(x) (((x)>>16)&0xff)
323#define DBGP_PID_SET(data,tok) (((data)<<8)|(tok))
324 u32 data03;
325 u32 data47;
326 u32 address;
327#define DBGP_EPADDR(dev,ep) (((dev)<<8)|(ep))
328} __attribute__ ((packed));
329
330
331
332#define QTD_NEXT(ehci, dma) cpu_to_hc32(ehci, (u32)dma)
333
334
335
336
337
338
339
340
341
342struct ehci_qtd {
343
344 __hc32 hw_next;
345 __hc32 hw_alt_next;
346 __hc32 hw_token;
347#define QTD_TOGGLE (1 << 31)
348#define QTD_LENGTH(tok) (((tok)>>16) & 0x7fff)
349#define QTD_IOC (1 << 15)
350#define QTD_CERR(tok) (((tok)>>10) & 0x3)
351#define QTD_PID(tok) (((tok)>>8) & 0x3)
352#define QTD_STS_ACTIVE (1 << 7)
353#define QTD_STS_HALT (1 << 6)
354#define QTD_STS_DBE (1 << 5)
355#define QTD_STS_BABBLE (1 << 4)
356#define QTD_STS_XACT (1 << 3)
357#define QTD_STS_MMF (1 << 2)
358#define QTD_STS_STS (1 << 1)
359#define QTD_STS_PING (1 << 0)
360
361#define ACTIVE_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_ACTIVE)
362#define HALT_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_HALT)
363#define STATUS_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_STS)
364
365 __hc32 hw_buf [5];
366 __hc32 hw_buf_hi [5];
367
368
369 dma_addr_t qtd_dma;
370 struct list_head qtd_list;
371 struct urb *urb;
372 size_t length;
373} __attribute__ ((aligned (32)));
374
375
376#define QTD_MASK(ehci) cpu_to_hc32 (ehci, ~0x1f)
377
378#define IS_SHORT_READ(token) (QTD_LENGTH (token) != 0 && QTD_PID (token) == 1)
379
380
381
382
383#define Q_NEXT_TYPE(ehci,dma) ((dma) & cpu_to_hc32(ehci, 3 << 1))
384
385
386
387
388
389
390
391
392
393#define Q_TYPE_ITD (0 << 1)
394#define Q_TYPE_QH (1 << 1)
395#define Q_TYPE_SITD (2 << 1)
396#define Q_TYPE_FSTN (3 << 1)
397
398
399#define QH_NEXT(ehci,dma) (cpu_to_hc32(ehci, (((u32)dma)&~0x01f)|Q_TYPE_QH))
400
401
402#define EHCI_LIST_END(ehci) cpu_to_hc32(ehci, 1)
403
404
405
406
407
408
409
410
411
412union ehci_shadow {
413 struct ehci_qh *qh;
414 struct ehci_itd *itd;
415 struct ehci_sitd *sitd;
416 struct ehci_fstn *fstn;
417 __hc32 *hw_next;
418 void *ptr;
419};
420
421
422
423
424
425
426
427
428
429
430
431struct ehci_qh {
432
433 __hc32 hw_next;
434 __hc32 hw_info1;
435#define QH_HEAD 0x00008000
436 __hc32 hw_info2;
437#define QH_SMASK 0x000000ff
438#define QH_CMASK 0x0000ff00
439#define QH_HUBADDR 0x007f0000
440#define QH_HUBPORT 0x3f800000
441#define QH_MULT 0xc0000000
442 __hc32 hw_current;
443
444
445 __hc32 hw_qtd_next;
446 __hc32 hw_alt_next;
447 __hc32 hw_token;
448 __hc32 hw_buf [5];
449 __hc32 hw_buf_hi [5];
450
451
452 dma_addr_t qh_dma;
453 union ehci_shadow qh_next;
454 struct list_head qtd_list;
455 struct ehci_qtd *dummy;
456 struct ehci_qh *reclaim;
457
458 struct ehci_hcd *ehci;
459
460
461
462
463
464
465
466 u32 refcount;
467 unsigned stamp;
468
469 u8 qh_state;
470#define QH_STATE_LINKED 1
471#define QH_STATE_UNLINK 2
472#define QH_STATE_IDLE 3
473#define QH_STATE_UNLINK_WAIT 4
474#define QH_STATE_COMPLETING 5
475
476
477 u8 usecs;
478 u8 gap_uf;
479 u8 c_usecs;
480 u16 tt_usecs;
481 unsigned short period;
482 unsigned short start;
483#define NO_FRAME ((unsigned short)~0)
484 struct usb_device *dev;
485} __attribute__ ((aligned (32)));
486
487
488
489
490struct ehci_iso_packet {
491
492 u64 bufp;
493 __hc32 transaction;
494 u8 cross;
495
496 u32 buf1;
497};
498
499
500
501
502
503struct ehci_iso_sched {
504 struct list_head td_list;
505 unsigned span;
506 struct ehci_iso_packet packet [0];
507};
508
509
510
511
512
513struct ehci_iso_stream {
514
515 __hc32 hw_next;
516 __hc32 hw_info1;
517
518 u32 refcount;
519 u8 bEndpointAddress;
520 u8 highspeed;
521 u16 depth;
522 struct list_head td_list;
523 struct list_head free_list;
524 struct usb_device *udev;
525 struct usb_host_endpoint *ep;
526
527
528 unsigned long start;
529 unsigned long rescheduled;
530 int next_uframe;
531 __hc32 splits;
532
533
534
535
536
537 u8 interval;
538 u8 usecs, c_usecs;
539 u16 tt_usecs;
540 u16 maxp;
541 u16 raw_mask;
542 unsigned bandwidth;
543
544
545 __hc32 buf0;
546 __hc32 buf1;
547 __hc32 buf2;
548
549
550 __hc32 address;
551};
552
553
554
555
556
557
558
559
560
561struct ehci_itd {
562
563 __hc32 hw_next;
564 __hc32 hw_transaction [8];
565#define EHCI_ISOC_ACTIVE (1<<31)
566#define EHCI_ISOC_BUF_ERR (1<<30)
567#define EHCI_ISOC_BABBLE (1<<29)
568#define EHCI_ISOC_XACTERR (1<<28)
569#define EHCI_ITD_LENGTH(tok) (((tok)>>16) & 0x0fff)
570#define EHCI_ITD_IOC (1 << 15)
571
572#define ITD_ACTIVE(ehci) cpu_to_hc32(ehci, EHCI_ISOC_ACTIVE)
573
574 __hc32 hw_bufp [7];
575 __hc32 hw_bufp_hi [7];
576
577
578 dma_addr_t itd_dma;
579 union ehci_shadow itd_next;
580
581 struct urb *urb;
582 struct ehci_iso_stream *stream;
583 struct list_head itd_list;
584
585
586 unsigned frame;
587 unsigned pg;
588 unsigned index[8];
589 u8 usecs[8];
590} __attribute__ ((aligned (32)));
591
592
593
594
595
596
597
598
599
600struct ehci_sitd {
601
602 __hc32 hw_next;
603
604 __hc32 hw_fullspeed_ep;
605 __hc32 hw_uframe;
606 __hc32 hw_results;
607#define SITD_IOC (1 << 31)
608#define SITD_PAGE (1 << 30)
609#define SITD_LENGTH(x) (0x3ff & ((x)>>16))
610#define SITD_STS_ACTIVE (1 << 7)
611#define SITD_STS_ERR (1 << 6)
612#define SITD_STS_DBE (1 << 5)
613#define SITD_STS_BABBLE (1 << 4)
614#define SITD_STS_XACT (1 << 3)
615#define SITD_STS_MMF (1 << 2)
616#define SITD_STS_STS (1 << 1)
617
618#define SITD_ACTIVE(ehci) cpu_to_hc32(ehci, SITD_STS_ACTIVE)
619
620 __hc32 hw_buf [2];
621 __hc32 hw_backpointer;
622 __hc32 hw_buf_hi [2];
623
624
625 dma_addr_t sitd_dma;
626 union ehci_shadow sitd_next;
627
628 struct urb *urb;
629 struct ehci_iso_stream *stream;
630 struct list_head sitd_list;
631 unsigned frame;
632 unsigned index;
633} __attribute__ ((aligned (32)));
634
635
636
637
638
639
640
641
642
643
644
645
646struct ehci_fstn {
647 __hc32 hw_next;
648 __hc32 hw_prev;
649
650
651 dma_addr_t fstn_dma;
652 union ehci_shadow fstn_next;
653} __attribute__ ((aligned (32)));
654
655
656
657#ifdef CONFIG_USB_EHCI_ROOT_HUB_TT
658
659
660
661
662
663
664
665
666#define ehci_is_TDI(e) ((e)->is_tdi_rh_tt)
667
668
669static inline unsigned int
670ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc)
671{
672 if (ehci_is_TDI(ehci)) {
673 switch ((portsc>>26)&3) {
674 case 0:
675 return 0;
676 case 1:
677 return (1<<USB_PORT_FEAT_LOWSPEED);
678 case 2:
679 default:
680 return (1<<USB_PORT_FEAT_HIGHSPEED);
681 }
682 }
683 return (1<<USB_PORT_FEAT_HIGHSPEED);
684}
685
686#else
687
688#define ehci_is_TDI(e) (0)
689
690#define ehci_port_speed(ehci, portsc) (1<<USB_PORT_FEAT_HIGHSPEED)
691#endif
692
693
694
695#ifdef CONFIG_PPC_83xx
696
697
698
699#define ehci_has_fsl_portno_bug(e) ((e)->has_fsl_port_bug)
700#else
701#define ehci_has_fsl_portno_bug(e) (0)
702#endif
703
704
705
706
707
708
709
710
711
712
713
714#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
715#define ehci_big_endian_mmio(e) ((e)->big_endian_mmio)
716#else
717#define ehci_big_endian_mmio(e) 0
718#endif
719
720
721
722
723
724
725
726
727
728#if defined(CONFIG_PPC)
729#define readl_be(addr) in_be32((__force unsigned *)addr)
730#define writel_be(val, addr) out_be32((__force unsigned *)addr, val)
731#endif
732
733static inline unsigned int ehci_readl(const struct ehci_hcd *ehci,
734 __u32 __iomem * regs)
735{
736#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
737 return ehci_big_endian_mmio(ehci) ?
738 readl_be(regs) :
739 readl(regs);
740#else
741 return readl(regs);
742#endif
743}
744
745static inline void ehci_writel(const struct ehci_hcd *ehci,
746 const unsigned int val, __u32 __iomem *regs)
747{
748#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
749 ehci_big_endian_mmio(ehci) ?
750 writel_be(val, regs) :
751 writel(val, regs);
752#else
753 writel(val, regs);
754#endif
755}
756
757
758
759
760
761
762
763
764
765
766#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_DESC
767#define ehci_big_endian_desc(e) ((e)->big_endian_desc)
768
769
770static inline __hc32 cpu_to_hc32 (const struct ehci_hcd *ehci, const u32 x)
771{
772 return ehci_big_endian_desc(ehci)
773 ? (__force __hc32)cpu_to_be32(x)
774 : (__force __hc32)cpu_to_le32(x);
775}
776
777
778static inline u32 hc32_to_cpu (const struct ehci_hcd *ehci, const __hc32 x)
779{
780 return ehci_big_endian_desc(ehci)
781 ? be32_to_cpu((__force __be32)x)
782 : le32_to_cpu((__force __le32)x);
783}
784
785static inline u32 hc32_to_cpup (const struct ehci_hcd *ehci, const __hc32 *x)
786{
787 return ehci_big_endian_desc(ehci)
788 ? be32_to_cpup((__force __be32 *)x)
789 : le32_to_cpup((__force __le32 *)x);
790}
791
792#else
793
794
795static inline __hc32 cpu_to_hc32 (const struct ehci_hcd *ehci, const u32 x)
796{
797 return cpu_to_le32(x);
798}
799
800
801static inline u32 hc32_to_cpu (const struct ehci_hcd *ehci, const __hc32 x)
802{
803 return le32_to_cpu(x);
804}
805
806static inline u32 hc32_to_cpup (const struct ehci_hcd *ehci, const __hc32 *x)
807{
808 return le32_to_cpup(x);
809}
810
811#endif
812
813
814
815#ifndef DEBUG
816#define STUB_DEBUG_FILES
817#endif
818
819
820
821#endif
822