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