2 * OHCI HCD (Host Controller Driver) for USB.
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
7 * This file is licenced under the GPL.
10 /*-------------------------------------------------------------------------*/
14 #define edstring(ed_type) ({ char *temp; \
16 case PIPE_CONTROL: temp = "ctrl"; break; \
17 case PIPE_BULK: temp = "bulk"; break; \
18 case PIPE_INTERRUPT: temp = "intr"; break; \
19 default: temp = "isoc"; break; \
21 #define pipestring(pipe) edstring(usb_pipetype(pipe))
23 /* debug| print the main components of an URB
24 * small: 0) header + data packets 1) just header
26 static void __attribute__((unused
))
27 urb_print (struct urb
* urb
, char * str
, int small
)
29 unsigned int pipe
= urb
->pipe
;
31 if (!urb
->dev
|| !urb
->dev
->bus
) {
32 dbg("%s URB: no dev", str
);
36 #ifndef OHCI_VERBOSE_DEBUG
39 dbg("%s %p dev=%d ep=%d%s-%s flags=%x len=%d/%d stat=%d",
42 usb_pipedevice (pipe
),
43 usb_pipeendpoint (pipe
),
44 usb_pipeout (pipe
)? "out" : "in",
48 urb
->transfer_buffer_length
,
51 #ifdef OHCI_VERBOSE_DEBUG
55 if (usb_pipecontrol (pipe
)) {
56 printk (KERN_DEBUG __FILE__
": setup(8):");
57 for (i
= 0; i
< 8 ; i
++)
58 printk (" %02x", ((__u8
*) urb
->setup_packet
) [i
]);
61 if (urb
->transfer_buffer_length
> 0 && urb
->transfer_buffer
) {
62 printk (KERN_DEBUG __FILE__
": data(%d/%d):",
64 urb
->transfer_buffer_length
);
65 len
= usb_pipeout (pipe
)?
66 urb
->transfer_buffer_length
: urb
->actual_length
;
67 for (i
= 0; i
< 16 && i
< len
; i
++)
68 printk (" %02x", ((__u8
*) urb
->transfer_buffer
) [i
]);
69 printk ("%s stat:%d\n", i
< len
? "...": "", urb
->status
);
75 #define ohci_dbg_sw(ohci, next, size, format, arg...) \
79 s_len = scnprintf (*next, *size, format, ## arg ); \
80 *size -= s_len; *next += s_len; \
82 ohci_dbg(ohci,format, ## arg ); \
86 static void ohci_dump_intr_mask (
87 struct ohci_hcd
*ohci
,
93 ohci_dbg_sw (ohci
, next
, size
, "%s 0x%08x%s%s%s%s%s%s%s%s%s\n",
96 (mask
& OHCI_INTR_MIE
) ? " MIE" : "",
97 (mask
& OHCI_INTR_OC
) ? " OC" : "",
98 (mask
& OHCI_INTR_RHSC
) ? " RHSC" : "",
99 (mask
& OHCI_INTR_FNO
) ? " FNO" : "",
100 (mask
& OHCI_INTR_UE
) ? " UE" : "",
101 (mask
& OHCI_INTR_RD
) ? " RD" : "",
102 (mask
& OHCI_INTR_SF
) ? " SF" : "",
103 (mask
& OHCI_INTR_WDH
) ? " WDH" : "",
104 (mask
& OHCI_INTR_SO
) ? " SO" : ""
108 static void maybe_print_eds (
109 struct ohci_hcd
*ohci
,
116 ohci_dbg_sw (ohci
, next
, size
, "%s %08x\n", label
, value
);
119 static char *hcfs2string (int state
)
122 case OHCI_USB_RESET
: return "reset";
123 case OHCI_USB_RESUME
: return "resume";
124 case OHCI_USB_OPER
: return "operational";
125 case OHCI_USB_SUSPEND
: return "suspend";
130 // dump control and status registers
132 ohci_dump_status (struct ohci_hcd
*controller
, char **next
, unsigned *size
)
134 struct ohci_regs __iomem
*regs
= controller
->regs
;
137 temp
= ohci_readl (controller
, ®s
->revision
) & 0xff;
138 ohci_dbg_sw (controller
, next
, size
,
139 "OHCI %d.%d, %s legacy support registers\n",
140 0x03 & (temp
>> 4), (temp
& 0x0f),
141 (temp
& 0x0100) ? "with" : "NO");
143 temp
= ohci_readl (controller
, ®s
->control
);
144 ohci_dbg_sw (controller
, next
, size
,
145 "control 0x%03x%s%s%s HCFS=%s%s%s%s%s CBSR=%d\n",
147 (temp
& OHCI_CTRL_RWE
) ? " RWE" : "",
148 (temp
& OHCI_CTRL_RWC
) ? " RWC" : "",
149 (temp
& OHCI_CTRL_IR
) ? " IR" : "",
150 hcfs2string (temp
& OHCI_CTRL_HCFS
),
151 (temp
& OHCI_CTRL_BLE
) ? " BLE" : "",
152 (temp
& OHCI_CTRL_CLE
) ? " CLE" : "",
153 (temp
& OHCI_CTRL_IE
) ? " IE" : "",
154 (temp
& OHCI_CTRL_PLE
) ? " PLE" : "",
155 temp
& OHCI_CTRL_CBSR
158 temp
= ohci_readl (controller
, ®s
->cmdstatus
);
159 ohci_dbg_sw (controller
, next
, size
,
160 "cmdstatus 0x%05x SOC=%d%s%s%s%s\n", temp
,
161 (temp
& OHCI_SOC
) >> 16,
162 (temp
& OHCI_OCR
) ? " OCR" : "",
163 (temp
& OHCI_BLF
) ? " BLF" : "",
164 (temp
& OHCI_CLF
) ? " CLF" : "",
165 (temp
& OHCI_HCR
) ? " HCR" : ""
168 ohci_dump_intr_mask (controller
, "intrstatus",
169 ohci_readl (controller
, ®s
->intrstatus
),
171 ohci_dump_intr_mask (controller
, "intrenable",
172 ohci_readl (controller
, ®s
->intrenable
),
174 // intrdisable always same as intrenable
176 maybe_print_eds (controller
, "ed_periodcurrent",
177 ohci_readl (controller
, ®s
->ed_periodcurrent
),
180 maybe_print_eds (controller
, "ed_controlhead",
181 ohci_readl (controller
, ®s
->ed_controlhead
),
183 maybe_print_eds (controller
, "ed_controlcurrent",
184 ohci_readl (controller
, ®s
->ed_controlcurrent
),
187 maybe_print_eds (controller
, "ed_bulkhead",
188 ohci_readl (controller
, ®s
->ed_bulkhead
),
190 maybe_print_eds (controller
, "ed_bulkcurrent",
191 ohci_readl (controller
, ®s
->ed_bulkcurrent
),
194 maybe_print_eds (controller
, "donehead",
195 ohci_readl (controller
, ®s
->donehead
), next
, size
);
197 /* broken fminterval means traffic won't flow! */
198 ohci_dbg (controller
, "fminterval %08x\n",
199 ohci_readl (controller
, ®s
->fminterval
));
202 #define dbg_port_sw(hc,num,value,next,size) \
203 ohci_dbg_sw (hc, next, size, \
204 "roothub.portstatus [%d] " \
205 "0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n", \
207 (temp & RH_PS_PRSC) ? " PRSC" : "", \
208 (temp & RH_PS_OCIC) ? " OCIC" : "", \
209 (temp & RH_PS_PSSC) ? " PSSC" : "", \
210 (temp & RH_PS_PESC) ? " PESC" : "", \
211 (temp & RH_PS_CSC) ? " CSC" : "", \
213 (temp & RH_PS_LSDA) ? " LSDA" : "", \
214 (temp & RH_PS_PPS) ? " PPS" : "", \
215 (temp & RH_PS_PRS) ? " PRS" : "", \
216 (temp & RH_PS_POCI) ? " POCI" : "", \
217 (temp & RH_PS_PSS) ? " PSS" : "", \
219 (temp & RH_PS_PES) ? " PES" : "", \
220 (temp & RH_PS_CCS) ? " CCS" : "" \
226 struct ohci_hcd
*controller
,
233 temp
= roothub_a (controller
);
238 ohci_dbg_sw (controller
, next
, size
,
239 "roothub.a %08x POTPGT=%d%s%s%s%s%s NDP=%d(%d)\n", temp
,
240 ((temp
& RH_A_POTPGT
) >> 24) & 0xff,
241 (temp
& RH_A_NOCP
) ? " NOCP" : "",
242 (temp
& RH_A_OCPM
) ? " OCPM" : "",
243 (temp
& RH_A_DT
) ? " DT" : "",
244 (temp
& RH_A_NPS
) ? " NPS" : "",
245 (temp
& RH_A_PSM
) ? " PSM" : "",
246 (temp
& RH_A_NDP
), controller
->num_ports
248 temp
= roothub_b (controller
);
249 ohci_dbg_sw (controller
, next
, size
,
250 "roothub.b %08x PPCM=%04x DR=%04x\n",
252 (temp
& RH_B_PPCM
) >> 16,
255 temp
= roothub_status (controller
);
256 ohci_dbg_sw (controller
, next
, size
,
257 "roothub.status %08x%s%s%s%s%s%s\n",
259 (temp
& RH_HS_CRWE
) ? " CRWE" : "",
260 (temp
& RH_HS_OCIC
) ? " OCIC" : "",
261 (temp
& RH_HS_LPSC
) ? " LPSC" : "",
262 (temp
& RH_HS_DRWE
) ? " DRWE" : "",
263 (temp
& RH_HS_OCI
) ? " OCI" : "",
264 (temp
& RH_HS_LPS
) ? " LPS" : ""
268 for (i
= 0; i
< controller
->num_ports
; i
++) {
269 temp
= roothub_portstatus (controller
, i
);
270 dbg_port_sw (controller
, i
, temp
, next
, size
);
274 static void ohci_dump (struct ohci_hcd
*controller
, int verbose
)
276 ohci_dbg (controller
, "OHCI controller state\n");
278 // dumps some of the state we know about
279 ohci_dump_status (controller
, NULL
, NULL
);
280 if (controller
->hcca
)
281 ohci_dbg (controller
,
282 "hcca frame #%04x\n", ohci_frame_no(controller
));
283 ohci_dump_roothub (controller
, 1, NULL
, NULL
);
286 static const char data0
[] = "DATA0";
287 static const char data1
[] = "DATA1";
289 static void ohci_dump_td (const struct ohci_hcd
*ohci
, const char *label
,
292 u32 tmp
= hc32_to_cpup (ohci
, &td
->hwINFO
);
294 ohci_dbg (ohci
, "%s td %p%s; urb %p index %d; hw next td %08x\n",
296 (tmp
& TD_DONE
) ? " (DONE)" : "",
298 hc32_to_cpup (ohci
, &td
->hwNextTD
));
299 if ((tmp
& TD_ISO
) == 0) {
300 const char *toggle
, *pid
;
303 switch (tmp
& TD_T
) {
304 case TD_T_DATA0
: toggle
= data0
; break;
305 case TD_T_DATA1
: toggle
= data1
; break;
306 case TD_T_TOGGLE
: toggle
= "(CARRY)"; break;
307 default: toggle
= "(?)"; break;
309 switch (tmp
& TD_DP
) {
310 case TD_DP_SETUP
: pid
= "SETUP"; break;
311 case TD_DP_IN
: pid
= "IN"; break;
312 case TD_DP_OUT
: pid
= "OUT"; break;
313 default: pid
= "(bad pid)"; break;
315 ohci_dbg (ohci
, " info %08x CC=%x %s DI=%d %s %s\n", tmp
,
316 TD_CC_GET(tmp
), /* EC, */ toggle
,
317 (tmp
& TD_DI
) >> 21, pid
,
318 (tmp
& TD_R
) ? "R" : "");
319 cbp
= hc32_to_cpup (ohci
, &td
->hwCBP
);
320 be
= hc32_to_cpup (ohci
, &td
->hwBE
);
321 ohci_dbg (ohci
, " cbp %08x be %08x (len %d)\n", cbp
, be
,
322 cbp
? (be
+ 1 - cbp
) : 0);
325 ohci_dbg (ohci
, " info %08x CC=%x FC=%d DI=%d SF=%04x\n", tmp
,
330 ohci_dbg (ohci
, " bp0 %08x be %08x\n",
331 hc32_to_cpup (ohci
, &td
->hwCBP
) & ~0x0fff,
332 hc32_to_cpup (ohci
, &td
->hwBE
));
333 for (i
= 0; i
< MAXPSW
; i
++) {
334 u16 psw
= ohci_hwPSW (ohci
, td
, i
);
335 int cc
= (psw
>> 12) & 0x0f;
336 ohci_dbg (ohci
, " psw [%d] = %2x, CC=%x %s=%d\n", i
,
338 (cc
>= 0x0e) ? "OFFSET" : "SIZE",
344 /* caller MUST own hcd spinlock if verbose is set! */
345 static void __attribute__((unused
))
346 ohci_dump_ed (const struct ohci_hcd
*ohci
, const char *label
,
347 const struct ed
*ed
, int verbose
)
349 u32 tmp
= hc32_to_cpu (ohci
, ed
->hwINFO
);
352 ohci_dbg (ohci
, "%s, ed %p state 0x%x type %s; next ed %08x\n",
354 ed
, ed
->state
, edstring (ed
->type
),
355 hc32_to_cpup (ohci
, &ed
->hwNextED
));
356 switch (tmp
& (ED_IN
|ED_OUT
)) {
357 case ED_OUT
: type
= "-OUT"; break;
358 case ED_IN
: type
= "-IN"; break;
359 /* else from TDs ... control */
362 " info %08x MAX=%d%s%s%s%s EP=%d%s DEV=%d\n", tmp
,
363 0x03ff & (tmp
>> 16),
364 (tmp
& ED_DEQUEUE
) ? " DQ" : "",
365 (tmp
& ED_ISO
) ? " ISO" : "",
366 (tmp
& ED_SKIP
) ? " SKIP" : "",
367 (tmp
& ED_LOWSPEED
) ? " LOW" : "",
371 tmp
= hc32_to_cpup (ohci
, &ed
->hwHeadP
);
372 ohci_dbg (ohci
, " tds: head %08x %s%s tail %08x%s\n",
374 (tmp
& ED_C
) ? data1
: data0
,
375 (tmp
& ED_H
) ? " HALT" : "",
376 hc32_to_cpup (ohci
, &ed
->hwTailP
),
377 verbose
? "" : " (not listing)");
379 struct list_head
*tmp
;
381 /* use ed->td_list because HC concurrently modifies
382 * hwNextTD as it accumulates ed_donelist.
384 list_for_each (tmp
, &ed
->td_list
) {
386 td
= list_entry (tmp
, struct td
, td_list
);
387 ohci_dump_td (ohci
, " ->", td
);
393 static inline void ohci_dump (struct ohci_hcd
*controller
, int verbose
) {}
395 #undef OHCI_VERBOSE_DEBUG
399 /*-------------------------------------------------------------------------*/
401 #ifdef STUB_DEBUG_FILES
403 static inline void create_debug_files (struct ohci_hcd
*bus
) { }
404 static inline void remove_debug_files (struct ohci_hcd
*bus
) { }
409 show_list (struct ohci_hcd
*ohci
, char *buf
, size_t count
, struct ed
*ed
)
411 unsigned temp
, size
= count
;
416 /* print first --> last */
420 /* dump a snapshot of the bulk or control schedule */
422 u32 info
= hc32_to_cpu (ohci
, ed
->hwINFO
);
423 u32 headp
= hc32_to_cpu (ohci
, ed
->hwHeadP
);
424 struct list_head
*entry
;
427 temp
= scnprintf (buf
, size
,
428 "ed/%p %cs dev%d ep%d%s max %d %08x%s%s %s",
430 (info
& ED_LOWSPEED
) ? 'l' : 'f',
433 (info
& ED_IN
) ? "in" : "out",
434 0x03ff & (info
>> 16),
436 (info
& ED_SKIP
) ? " s" : "",
437 (headp
& ED_H
) ? " H" : "",
438 (headp
& ED_C
) ? data1
: data0
);
442 list_for_each (entry
, &ed
->td_list
) {
445 td
= list_entry (entry
, struct td
, td_list
);
446 info
= hc32_to_cpup (ohci
, &td
->hwINFO
);
447 cbp
= hc32_to_cpup (ohci
, &td
->hwCBP
);
448 be
= hc32_to_cpup (ohci
, &td
->hwBE
);
449 temp
= scnprintf (buf
, size
,
450 "\n\ttd %p %s %d cc=%x urb %p (%08x)",
453 switch (info
& TD_DP
) {
454 case TD_DP_SETUP
: pid
= "setup"; break;
455 case TD_DP_IN
: pid
= "in"; break;
456 case TD_DP_OUT
: pid
= "out"; break;
457 default: pid
= "(?)"; break;
459 cbp
? (be
+ 1 - cbp
) : 0,
460 TD_CC_GET (info
), td
->urb
, info
);
465 temp
= scnprintf (buf
, size
, "\n");
475 show_async (struct class_device
*class_dev
, char *buf
)
479 struct ohci_hcd
*ohci
;
483 bus
= class_get_devdata(class_dev
);
485 ohci
= hcd_to_ohci(hcd
);
487 /* display control and bulk lists together, for simplicity */
488 spin_lock_irqsave (&ohci
->lock
, flags
);
489 temp
= show_list (ohci
, buf
, PAGE_SIZE
, ohci
->ed_controltail
);
490 temp
+= show_list (ohci
, buf
+ temp
, PAGE_SIZE
- temp
, ohci
->ed_bulktail
);
491 spin_unlock_irqrestore (&ohci
->lock
, flags
);
495 static CLASS_DEVICE_ATTR (async
, S_IRUGO
, show_async
, NULL
);
498 #define DBG_SCHED_LIMIT 64
501 show_periodic (struct class_device
*class_dev
, char *buf
)
505 struct ohci_hcd
*ohci
;
506 struct ed
**seen
, *ed
;
508 unsigned temp
, size
, seen_count
;
512 if (!(seen
= kmalloc (DBG_SCHED_LIMIT
* sizeof *seen
, SLAB_ATOMIC
)))
516 bus
= class_get_devdata(class_dev
);
518 ohci
= hcd_to_ohci(hcd
);
522 temp
= scnprintf (next
, size
, "size = %d\n", NUM_INTS
);
526 /* dump a snapshot of the periodic schedule (and load) */
527 spin_lock_irqsave (&ohci
->lock
, flags
);
528 for (i
= 0; i
< NUM_INTS
; i
++) {
529 if (!(ed
= ohci
->periodic
[i
]))
532 temp
= scnprintf (next
, size
, "%2d [%3d]:", i
, ohci
->load
[i
]);
537 temp
= scnprintf (next
, size
, " ed%d/%p",
541 for (temp
= 0; temp
< seen_count
; temp
++) {
542 if (seen
[temp
] == ed
)
546 /* show more info the first time around */
547 if (temp
== seen_count
) {
548 u32 info
= hc32_to_cpu (ohci
, ed
->hwINFO
);
549 struct list_head
*entry
;
552 /* qlen measured here in TDs, not urbs */
553 list_for_each (entry
, &ed
->td_list
)
556 temp
= scnprintf (next
, size
,
557 " (%cs dev%d ep%d%s-%s qlen %u"
559 (info
& ED_LOWSPEED
) ? 'l' : 'f',
562 (info
& ED_IN
) ? "in" : "out",
563 (info
& ED_ISO
) ? "iso" : "int",
565 0x03ff & (info
>> 16),
567 (info
& ED_SKIP
) ? " K" : "",
569 cpu_to_hc32(ohci
, ED_H
)) ?
574 if (seen_count
< DBG_SCHED_LIMIT
)
575 seen
[seen_count
++] = ed
;
580 /* we've seen it and what's after */
587 temp
= scnprintf (next
, size
, "\n");
591 spin_unlock_irqrestore (&ohci
->lock
, flags
);
594 return PAGE_SIZE
- size
;
596 static CLASS_DEVICE_ATTR (periodic
, S_IRUGO
, show_periodic
, NULL
);
599 #undef DBG_SCHED_LIMIT
602 show_registers (struct class_device
*class_dev
, char *buf
)
606 struct ohci_hcd
*ohci
;
607 struct ohci_regs __iomem
*regs
;
613 bus
= class_get_devdata(class_dev
);
615 ohci
= hcd_to_ohci(hcd
);
620 spin_lock_irqsave (&ohci
->lock
, flags
);
622 /* dump driver info, then registers in spec order */
624 ohci_dbg_sw (ohci
, &next
, &size
,
625 "bus %s, device %s\n"
627 "%s version " DRIVER_VERSION
"\n",
628 hcd
->self
.controller
->bus
->name
,
629 hcd
->self
.controller
->bus_id
,
633 if (bus
->controller
->power
.power_state
.event
) {
634 size
-= scnprintf (next
, size
,
635 "SUSPENDED (no register access)\n");
639 ohci_dump_status(ohci
, &next
, &size
);
643 ohci_dbg_sw (ohci
, &next
, &size
,
644 "hcca frame 0x%04x\n", ohci_frame_no(ohci
));
646 /* other registers mostly affect frame timings */
647 rdata
= ohci_readl (ohci
, ®s
->fminterval
);
648 temp
= scnprintf (next
, size
,
649 "fmintvl 0x%08x %sFSMPS=0x%04x FI=0x%04x\n",
650 rdata
, (rdata
>> 31) ? "FIT " : "",
651 (rdata
>> 16) & 0xefff, rdata
& 0xffff);
655 rdata
= ohci_readl (ohci
, ®s
->fmremaining
);
656 temp
= scnprintf (next
, size
, "fmremaining 0x%08x %sFR=0x%04x\n",
657 rdata
, (rdata
>> 31) ? "FRT " : "",
662 rdata
= ohci_readl (ohci
, ®s
->periodicstart
);
663 temp
= scnprintf (next
, size
, "periodicstart 0x%04x\n",
668 rdata
= ohci_readl (ohci
, ®s
->lsthresh
);
669 temp
= scnprintf (next
, size
, "lsthresh 0x%04x\n",
675 ohci_dump_roothub (ohci
, 1, &next
, &size
);
678 spin_unlock_irqrestore (&ohci
->lock
, flags
);
679 return PAGE_SIZE
- size
;
681 static CLASS_DEVICE_ATTR (registers
, S_IRUGO
, show_registers
, NULL
);
684 static inline void create_debug_files (struct ohci_hcd
*ohci
)
686 struct class_device
*cldev
= ohci_to_hcd(ohci
)->self
.class_dev
;
688 class_device_create_file(cldev
, &class_device_attr_async
);
689 class_device_create_file(cldev
, &class_device_attr_periodic
);
690 class_device_create_file(cldev
, &class_device_attr_registers
);
691 ohci_dbg (ohci
, "created debug files\n");
694 static inline void remove_debug_files (struct ohci_hcd
*ohci
)
696 struct class_device
*cldev
= ohci_to_hcd(ohci
)->self
.class_dev
;
698 class_device_remove_file(cldev
, &class_device_attr_async
);
699 class_device_remove_file(cldev
, &class_device_attr_periodic
);
700 class_device_remove_file(cldev
, &class_device_attr_registers
);
705 /*-------------------------------------------------------------------------*/