blob: 5179fcd73d8a391b165abaf1327dd944916dce1a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 *
7 * This file is licenced under the GPL.
8 */
9
10/*-------------------------------------------------------------------------*/
11
12#ifdef DEBUG
13
14#define edstring(ed_type) ({ char *temp; \
15 switch (ed_type) { \
16 case PIPE_CONTROL: temp = "ctrl"; break; \
17 case PIPE_BULK: temp = "bulk"; break; \
18 case PIPE_INTERRUPT: temp = "intr"; break; \
David Brownelldd9048a2006-12-05 03:18:31 -080019 default: temp = "isoc"; break; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 }; temp;})
21#define pipestring(pipe) edstring(usb_pipetype(pipe))
22
23/* debug| print the main components of an URB
24 * small: 0) header + data packets 1) just header
25 */
David Rientjes82345092007-05-11 14:39:44 -070026static void __maybe_unused
Alan Stern55d84962007-08-24 15:40:34 -040027urb_print(struct urb * urb, char * str, int small, int status)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028{
29 unsigned int pipe= urb->pipe;
30
31 if (!urb->dev || !urb->dev->bus) {
32 dbg("%s URB: no dev", str);
33 return;
34 }
35
36#ifndef OHCI_VERBOSE_DEBUG
Alan Stern55d84962007-08-24 15:40:34 -040037 if (status != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#endif
39 dbg("%s %p dev=%d ep=%d%s-%s flags=%x len=%d/%d stat=%d",
40 str,
41 urb,
42 usb_pipedevice (pipe),
43 usb_pipeendpoint (pipe),
44 usb_pipeout (pipe)? "out" : "in",
45 pipestring (pipe),
46 urb->transfer_flags,
47 urb->actual_length,
48 urb->transfer_buffer_length,
Alan Stern55d84962007-08-24 15:40:34 -040049 status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51#ifdef OHCI_VERBOSE_DEBUG
52 if (!small) {
53 int i, len;
54
55 if (usb_pipecontrol (pipe)) {
Joe Perchesf45ba772010-02-05 17:51:13 -080056 printk (KERN_DEBUG "%s: setup(8):", __FILE__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 for (i = 0; i < 8 ; i++)
58 printk (" %02x", ((__u8 *) urb->setup_packet) [i]);
59 printk ("\n");
60 }
61 if (urb->transfer_buffer_length > 0 && urb->transfer_buffer) {
Joe Perchesf45ba772010-02-05 17:51:13 -080062 printk (KERN_DEBUG "%s: data(%d/%d):", __FILE__,
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 urb->actual_length,
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]);
Alan Stern55d84962007-08-24 15:40:34 -040069 printk ("%s stat:%d\n", i < len? "...": "", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 }
71 }
72#endif
73}
74
75#define ohci_dbg_sw(ohci, next, size, format, arg...) \
76 do { \
David Brownellbdd203a2007-08-17 22:19:59 -070077 if (next != NULL) { \
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 unsigned s_len; \
79 s_len = scnprintf (*next, *size, format, ## arg ); \
80 *size -= s_len; *next += s_len; \
81 } else \
82 ohci_dbg(ohci,format, ## arg ); \
83 } while (0);
84
85
86static void ohci_dump_intr_mask (
87 struct ohci_hcd *ohci,
88 char *label,
89 u32 mask,
90 char **next,
91 unsigned *size)
92{
93 ohci_dbg_sw (ohci, next, size, "%s 0x%08x%s%s%s%s%s%s%s%s%s\n",
94 label,
95 mask,
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" : ""
105 );
106}
107
108static void maybe_print_eds (
109 struct ohci_hcd *ohci,
110 char *label,
111 u32 value,
112 char **next,
113 unsigned *size)
114{
115 if (value)
116 ohci_dbg_sw (ohci, next, size, "%s %08x\n", label, value);
117}
118
119static char *hcfs2string (int state)
120{
121 switch (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";
126 }
127 return "?";
128}
129
Alan Sternb7463c72011-11-17 16:41:56 -0500130static const char *rh_state_string(struct ohci_hcd *ohci)
131{
132 switch (ohci->rh_state) {
133 case OHCI_RH_HALTED:
134 return "halted";
135 case OHCI_RH_SUSPENDED:
136 return "suspended";
137 case OHCI_RH_RUNNING:
138 return "running";
139 }
140 return "?";
141}
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143// dump control and status registers
144static void
145ohci_dump_status (struct ohci_hcd *controller, char **next, unsigned *size)
146{
147 struct ohci_regs __iomem *regs = controller->regs;
148 u32 temp;
149
150 temp = ohci_readl (controller, &regs->revision) & 0xff;
151 ohci_dbg_sw (controller, next, size,
Alan Sternb7463c72011-11-17 16:41:56 -0500152 "OHCI %d.%d, %s legacy support registers, rh state %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 0x03 & (temp >> 4), (temp & 0x0f),
Alan Sternb7463c72011-11-17 16:41:56 -0500154 (temp & 0x0100) ? "with" : "NO",
155 rh_state_string(controller));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
157 temp = ohci_readl (controller, &regs->control);
158 ohci_dbg_sw (controller, next, size,
159 "control 0x%03x%s%s%s HCFS=%s%s%s%s%s CBSR=%d\n",
160 temp,
161 (temp & OHCI_CTRL_RWE) ? " RWE" : "",
162 (temp & OHCI_CTRL_RWC) ? " RWC" : "",
163 (temp & OHCI_CTRL_IR) ? " IR" : "",
164 hcfs2string (temp & OHCI_CTRL_HCFS),
165 (temp & OHCI_CTRL_BLE) ? " BLE" : "",
166 (temp & OHCI_CTRL_CLE) ? " CLE" : "",
167 (temp & OHCI_CTRL_IE) ? " IE" : "",
168 (temp & OHCI_CTRL_PLE) ? " PLE" : "",
169 temp & OHCI_CTRL_CBSR
170 );
171
172 temp = ohci_readl (controller, &regs->cmdstatus);
173 ohci_dbg_sw (controller, next, size,
174 "cmdstatus 0x%05x SOC=%d%s%s%s%s\n", temp,
175 (temp & OHCI_SOC) >> 16,
176 (temp & OHCI_OCR) ? " OCR" : "",
177 (temp & OHCI_BLF) ? " BLF" : "",
178 (temp & OHCI_CLF) ? " CLF" : "",
179 (temp & OHCI_HCR) ? " HCR" : ""
180 );
181
182 ohci_dump_intr_mask (controller, "intrstatus",
183 ohci_readl (controller, &regs->intrstatus),
184 next, size);
185 ohci_dump_intr_mask (controller, "intrenable",
186 ohci_readl (controller, &regs->intrenable),
187 next, size);
188 // intrdisable always same as intrenable
189
190 maybe_print_eds (controller, "ed_periodcurrent",
191 ohci_readl (controller, &regs->ed_periodcurrent),
192 next, size);
193
194 maybe_print_eds (controller, "ed_controlhead",
195 ohci_readl (controller, &regs->ed_controlhead),
196 next, size);
197 maybe_print_eds (controller, "ed_controlcurrent",
198 ohci_readl (controller, &regs->ed_controlcurrent),
199 next, size);
200
201 maybe_print_eds (controller, "ed_bulkhead",
202 ohci_readl (controller, &regs->ed_bulkhead),
203 next, size);
204 maybe_print_eds (controller, "ed_bulkcurrent",
205 ohci_readl (controller, &regs->ed_bulkcurrent),
206 next, size);
207
208 maybe_print_eds (controller, "donehead",
209 ohci_readl (controller, &regs->donehead), next, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210}
211
212#define dbg_port_sw(hc,num,value,next,size) \
213 ohci_dbg_sw (hc, next, size, \
214 "roothub.portstatus [%d] " \
215 "0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n", \
216 num, temp, \
217 (temp & RH_PS_PRSC) ? " PRSC" : "", \
218 (temp & RH_PS_OCIC) ? " OCIC" : "", \
219 (temp & RH_PS_PSSC) ? " PSSC" : "", \
220 (temp & RH_PS_PESC) ? " PESC" : "", \
221 (temp & RH_PS_CSC) ? " CSC" : "", \
David Brownelldd9048a2006-12-05 03:18:31 -0800222 \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 (temp & RH_PS_LSDA) ? " LSDA" : "", \
224 (temp & RH_PS_PPS) ? " PPS" : "", \
225 (temp & RH_PS_PRS) ? " PRS" : "", \
226 (temp & RH_PS_POCI) ? " POCI" : "", \
227 (temp & RH_PS_PSS) ? " PSS" : "", \
David Brownelldd9048a2006-12-05 03:18:31 -0800228 \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 (temp & RH_PS_PES) ? " PES" : "", \
230 (temp & RH_PS_CCS) ? " CCS" : "" \
231 );
232
233
234static void
235ohci_dump_roothub (
236 struct ohci_hcd *controller,
237 int verbose,
238 char **next,
239 unsigned *size)
240{
David Brownellfdd13b32005-08-31 11:52:57 -0700241 u32 temp, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
243 temp = roothub_a (controller);
244 if (temp == ~(u32)0)
245 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
247 if (verbose) {
248 ohci_dbg_sw (controller, next, size,
David Brownellfdd13b32005-08-31 11:52:57 -0700249 "roothub.a %08x POTPGT=%d%s%s%s%s%s NDP=%d(%d)\n", temp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 ((temp & RH_A_POTPGT) >> 24) & 0xff,
251 (temp & RH_A_NOCP) ? " NOCP" : "",
252 (temp & RH_A_OCPM) ? " OCPM" : "",
253 (temp & RH_A_DT) ? " DT" : "",
254 (temp & RH_A_NPS) ? " NPS" : "",
255 (temp & RH_A_PSM) ? " PSM" : "",
David Brownellfdd13b32005-08-31 11:52:57 -0700256 (temp & RH_A_NDP), controller->num_ports
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 );
258 temp = roothub_b (controller);
259 ohci_dbg_sw (controller, next, size,
260 "roothub.b %08x PPCM=%04x DR=%04x\n",
261 temp,
262 (temp & RH_B_PPCM) >> 16,
263 (temp & RH_B_DR)
264 );
265 temp = roothub_status (controller);
266 ohci_dbg_sw (controller, next, size,
267 "roothub.status %08x%s%s%s%s%s%s\n",
268 temp,
269 (temp & RH_HS_CRWE) ? " CRWE" : "",
270 (temp & RH_HS_OCIC) ? " OCIC" : "",
271 (temp & RH_HS_LPSC) ? " LPSC" : "",
272 (temp & RH_HS_DRWE) ? " DRWE" : "",
273 (temp & RH_HS_OCI) ? " OCI" : "",
274 (temp & RH_HS_LPS) ? " LPS" : ""
275 );
276 }
277
David Brownellfdd13b32005-08-31 11:52:57 -0700278 for (i = 0; i < controller->num_ports; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 temp = roothub_portstatus (controller, i);
280 dbg_port_sw (controller, i, temp, next, size);
281 }
282}
283
284static void ohci_dump (struct ohci_hcd *controller, int verbose)
285{
286 ohci_dbg (controller, "OHCI controller state\n");
287
288 // dumps some of the state we know about
289 ohci_dump_status (controller, NULL, NULL);
290 if (controller->hcca)
291 ohci_dbg (controller,
292 "hcca frame #%04x\n", ohci_frame_no(controller));
293 ohci_dump_roothub (controller, 1, NULL, NULL);
294}
295
296static const char data0 [] = "DATA0";
297static const char data1 [] = "DATA1";
298
299static void ohci_dump_td (const struct ohci_hcd *ohci, const char *label,
300 const struct td *td)
301{
302 u32 tmp = hc32_to_cpup (ohci, &td->hwINFO);
303
304 ohci_dbg (ohci, "%s td %p%s; urb %p index %d; hw next td %08x\n",
305 label, td,
306 (tmp & TD_DONE) ? " (DONE)" : "",
307 td->urb, td->index,
308 hc32_to_cpup (ohci, &td->hwNextTD));
309 if ((tmp & TD_ISO) == 0) {
310 const char *toggle, *pid;
311 u32 cbp, be;
312
313 switch (tmp & TD_T) {
314 case TD_T_DATA0: toggle = data0; break;
315 case TD_T_DATA1: toggle = data1; break;
316 case TD_T_TOGGLE: toggle = "(CARRY)"; break;
317 default: toggle = "(?)"; break;
318 }
319 switch (tmp & TD_DP) {
320 case TD_DP_SETUP: pid = "SETUP"; break;
321 case TD_DP_IN: pid = "IN"; break;
322 case TD_DP_OUT: pid = "OUT"; break;
323 default: pid = "(bad pid)"; break;
324 }
325 ohci_dbg (ohci, " info %08x CC=%x %s DI=%d %s %s\n", tmp,
326 TD_CC_GET(tmp), /* EC, */ toggle,
327 (tmp & TD_DI) >> 21, pid,
328 (tmp & TD_R) ? "R" : "");
329 cbp = hc32_to_cpup (ohci, &td->hwCBP);
330 be = hc32_to_cpup (ohci, &td->hwBE);
331 ohci_dbg (ohci, " cbp %08x be %08x (len %d)\n", cbp, be,
332 cbp ? (be + 1 - cbp) : 0);
333 } else {
334 unsigned i;
335 ohci_dbg (ohci, " info %08x CC=%x FC=%d DI=%d SF=%04x\n", tmp,
336 TD_CC_GET(tmp),
337 (tmp >> 24) & 0x07,
338 (tmp & TD_DI) >> 21,
339 tmp & 0x0000ffff);
340 ohci_dbg (ohci, " bp0 %08x be %08x\n",
341 hc32_to_cpup (ohci, &td->hwCBP) & ~0x0fff,
342 hc32_to_cpup (ohci, &td->hwBE));
343 for (i = 0; i < MAXPSW; i++) {
344 u16 psw = ohci_hwPSW (ohci, td, i);
345 int cc = (psw >> 12) & 0x0f;
346 ohci_dbg (ohci, " psw [%d] = %2x, CC=%x %s=%d\n", i,
347 psw, cc,
348 (cc >= 0x0e) ? "OFFSET" : "SIZE",
349 psw & 0x0fff);
350 }
351 }
352}
353
354/* caller MUST own hcd spinlock if verbose is set! */
David Rientjes82345092007-05-11 14:39:44 -0700355static void __maybe_unused
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356ohci_dump_ed (const struct ohci_hcd *ohci, const char *label,
357 const struct ed *ed, int verbose)
358{
359 u32 tmp = hc32_to_cpu (ohci, ed->hwINFO);
360 char *type = "";
361
362 ohci_dbg (ohci, "%s, ed %p state 0x%x type %s; next ed %08x\n",
363 label,
364 ed, ed->state, edstring (ed->type),
365 hc32_to_cpup (ohci, &ed->hwNextED));
366 switch (tmp & (ED_IN|ED_OUT)) {
367 case ED_OUT: type = "-OUT"; break;
368 case ED_IN: type = "-IN"; break;
369 /* else from TDs ... control */
370 }
371 ohci_dbg (ohci,
372 " info %08x MAX=%d%s%s%s%s EP=%d%s DEV=%d\n", tmp,
373 0x03ff & (tmp >> 16),
374 (tmp & ED_DEQUEUE) ? " DQ" : "",
375 (tmp & ED_ISO) ? " ISO" : "",
376 (tmp & ED_SKIP) ? " SKIP" : "",
377 (tmp & ED_LOWSPEED) ? " LOW" : "",
378 0x000f & (tmp >> 7),
379 type,
380 0x007f & tmp);
381 tmp = hc32_to_cpup (ohci, &ed->hwHeadP);
382 ohci_dbg (ohci, " tds: head %08x %s%s tail %08x%s\n",
383 tmp,
384 (tmp & ED_C) ? data1 : data0,
385 (tmp & ED_H) ? " HALT" : "",
386 hc32_to_cpup (ohci, &ed->hwTailP),
387 verbose ? "" : " (not listing)");
388 if (verbose) {
389 struct list_head *tmp;
390
391 /* use ed->td_list because HC concurrently modifies
392 * hwNextTD as it accumulates ed_donelist.
393 */
394 list_for_each (tmp, &ed->td_list) {
395 struct td *td;
396 td = list_entry (tmp, struct td, td_list);
397 ohci_dump_td (ohci, " ->", td);
398 }
399 }
400}
401
402#else
403static inline void ohci_dump (struct ohci_hcd *controller, int verbose) {}
404
405#undef OHCI_VERBOSE_DEBUG
406
407#endif /* DEBUG */
408
409/*-------------------------------------------------------------------------*/
410
411#ifdef STUB_DEBUG_FILES
412
413static inline void create_debug_files (struct ohci_hcd *bus) { }
414static inline void remove_debug_files (struct ohci_hcd *bus) { }
415
416#else
417
Tony Jones684c19e2007-09-11 14:07:31 -0700418static int debug_async_open(struct inode *, struct file *);
419static int debug_periodic_open(struct inode *, struct file *);
420static int debug_registers_open(struct inode *, struct file *);
421static int debug_async_open(struct inode *, struct file *);
422static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
423static int debug_close(struct inode *, struct file *);
424
425static const struct file_operations debug_async_fops = {
426 .owner = THIS_MODULE,
427 .open = debug_async_open,
428 .read = debug_output,
429 .release = debug_close,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200430 .llseek = default_llseek,
Tony Jones684c19e2007-09-11 14:07:31 -0700431};
432static const struct file_operations debug_periodic_fops = {
433 .owner = THIS_MODULE,
434 .open = debug_periodic_open,
435 .read = debug_output,
436 .release = debug_close,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200437 .llseek = default_llseek,
Tony Jones684c19e2007-09-11 14:07:31 -0700438};
439static const struct file_operations debug_registers_fops = {
440 .owner = THIS_MODULE,
441 .open = debug_registers_open,
442 .read = debug_output,
443 .release = debug_close,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200444 .llseek = default_llseek,
Tony Jones684c19e2007-09-11 14:07:31 -0700445};
446
447static struct dentry *ohci_debug_root;
448
449struct debug_buffer {
450 ssize_t (*fill_func)(struct debug_buffer *); /* fill method */
Greg Kroah-Hartman10983342009-04-27 13:12:58 -0700451 struct ohci_hcd *ohci;
Tony Jones684c19e2007-09-11 14:07:31 -0700452 struct mutex mutex; /* protect filling of buffer */
453 size_t count; /* number of characters filled into buffer */
454 char *page;
455};
456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457static ssize_t
458show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed)
459{
460 unsigned temp, size = count;
461
462 if (!ed)
463 return 0;
464
465 /* print first --> last */
466 while (ed->ed_prev)
467 ed = ed->ed_prev;
468
469 /* dump a snapshot of the bulk or control schedule */
470 while (ed) {
471 u32 info = hc32_to_cpu (ohci, ed->hwINFO);
472 u32 headp = hc32_to_cpu (ohci, ed->hwHeadP);
473 struct list_head *entry;
474 struct td *td;
475
476 temp = scnprintf (buf, size,
477 "ed/%p %cs dev%d ep%d%s max %d %08x%s%s %s",
478 ed,
479 (info & ED_LOWSPEED) ? 'l' : 'f',
480 info & 0x7f,
481 (info >> 7) & 0xf,
482 (info & ED_IN) ? "in" : "out",
483 0x03ff & (info >> 16),
484 info,
485 (info & ED_SKIP) ? " s" : "",
486 (headp & ED_H) ? " H" : "",
487 (headp & ED_C) ? data1 : data0);
488 size -= temp;
489 buf += temp;
490
491 list_for_each (entry, &ed->td_list) {
492 u32 cbp, be;
493
494 td = list_entry (entry, struct td, td_list);
495 info = hc32_to_cpup (ohci, &td->hwINFO);
496 cbp = hc32_to_cpup (ohci, &td->hwCBP);
497 be = hc32_to_cpup (ohci, &td->hwBE);
498 temp = scnprintf (buf, size,
499 "\n\ttd %p %s %d cc=%x urb %p (%08x)",
500 td,
501 ({ char *pid;
502 switch (info & TD_DP) {
503 case TD_DP_SETUP: pid = "setup"; break;
504 case TD_DP_IN: pid = "in"; break;
505 case TD_DP_OUT: pid = "out"; break;
506 default: pid = "(?)"; break;
507 } pid;}),
508 cbp ? (be + 1 - cbp) : 0,
509 TD_CC_GET (info), td->urb, info);
510 size -= temp;
511 buf += temp;
512 }
513
514 temp = scnprintf (buf, size, "\n");
515 size -= temp;
516 buf += temp;
517
518 ed = ed->ed_next;
519 }
520 return count - size;
521}
522
Tony Jones684c19e2007-09-11 14:07:31 -0700523static ssize_t fill_async_buffer(struct debug_buffer *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 struct ohci_hcd *ohci;
526 size_t temp;
527 unsigned long flags;
528
Greg Kroah-Hartman10983342009-04-27 13:12:58 -0700529 ohci = buf->ohci;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
531 /* display control and bulk lists together, for simplicity */
532 spin_lock_irqsave (&ohci->lock, flags);
Tony Jones684c19e2007-09-11 14:07:31 -0700533 temp = show_list(ohci, buf->page, buf->count, ohci->ed_controltail);
534 temp += show_list(ohci, buf->page + temp, buf->count - temp,
535 ohci->ed_bulktail);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 spin_unlock_irqrestore (&ohci->lock, flags);
537
538 return temp;
539}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
541#define DBG_SCHED_LIMIT 64
542
Tony Jones684c19e2007-09-11 14:07:31 -0700543static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 struct ohci_hcd *ohci;
546 struct ed **seen, *ed;
547 unsigned long flags;
548 unsigned temp, size, seen_count;
549 char *next;
550 unsigned i;
551
Christoph Lameter54e6ecb2006-12-06 20:33:16 -0800552 if (!(seen = kmalloc (DBG_SCHED_LIMIT * sizeof *seen, GFP_ATOMIC)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 return 0;
554 seen_count = 0;
555
Greg Kroah-Hartman10983342009-04-27 13:12:58 -0700556 ohci = buf->ohci;
Tony Jones684c19e2007-09-11 14:07:31 -0700557 next = buf->page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 size = PAGE_SIZE;
559
560 temp = scnprintf (next, size, "size = %d\n", NUM_INTS);
561 size -= temp;
562 next += temp;
563
564 /* dump a snapshot of the periodic schedule (and load) */
565 spin_lock_irqsave (&ohci->lock, flags);
566 for (i = 0; i < NUM_INTS; i++) {
567 if (!(ed = ohci->periodic [i]))
568 continue;
569
570 temp = scnprintf (next, size, "%2d [%3d]:", i, ohci->load [i]);
571 size -= temp;
572 next += temp;
573
574 do {
575 temp = scnprintf (next, size, " ed%d/%p",
576 ed->interval, ed);
577 size -= temp;
578 next += temp;
579 for (temp = 0; temp < seen_count; temp++) {
580 if (seen [temp] == ed)
581 break;
582 }
583
584 /* show more info the first time around */
585 if (temp == seen_count) {
586 u32 info = hc32_to_cpu (ohci, ed->hwINFO);
587 struct list_head *entry;
588 unsigned qlen = 0;
589
590 /* qlen measured here in TDs, not urbs */
591 list_for_each (entry, &ed->td_list)
592 qlen++;
593
594 temp = scnprintf (next, size,
595 " (%cs dev%d ep%d%s-%s qlen %u"
596 " max %d %08x%s%s)",
597 (info & ED_LOWSPEED) ? 'l' : 'f',
598 info & 0x7f,
599 (info >> 7) & 0xf,
600 (info & ED_IN) ? "in" : "out",
601 (info & ED_ISO) ? "iso" : "int",
602 qlen,
603 0x03ff & (info >> 16),
604 info,
605 (info & ED_SKIP) ? " K" : "",
606 (ed->hwHeadP &
607 cpu_to_hc32(ohci, ED_H)) ?
David Brownelldd9048a2006-12-05 03:18:31 -0800608 " H" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 size -= temp;
610 next += temp;
611
612 if (seen_count < DBG_SCHED_LIMIT)
613 seen [seen_count++] = ed;
614
615 ed = ed->ed_next;
616
617 } else {
618 /* we've seen it and what's after */
619 temp = 0;
620 ed = NULL;
621 }
622
623 } while (ed);
624
625 temp = scnprintf (next, size, "\n");
626 size -= temp;
627 next += temp;
628 }
629 spin_unlock_irqrestore (&ohci->lock, flags);
630 kfree (seen);
631
632 return PAGE_SIZE - size;
633}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634#undef DBG_SCHED_LIMIT
635
Tony Jones684c19e2007-09-11 14:07:31 -0700636static ssize_t fill_registers_buffer(struct debug_buffer *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 struct usb_hcd *hcd;
639 struct ohci_hcd *ohci;
640 struct ohci_regs __iomem *regs;
641 unsigned long flags;
642 unsigned temp, size;
643 char *next;
644 u32 rdata;
645
Greg Kroah-Hartman10983342009-04-27 13:12:58 -0700646 ohci = buf->ohci;
647 hcd = ohci_to_hcd(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 regs = ohci->regs;
Tony Jones684c19e2007-09-11 14:07:31 -0700649 next = buf->page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 size = PAGE_SIZE;
651
652 spin_lock_irqsave (&ohci->lock, flags);
653
654 /* dump driver info, then registers in spec order */
655
656 ohci_dbg_sw (ohci, &next, &size,
657 "bus %s, device %s\n"
658 "%s\n"
Alan Stern2b70f072008-10-02 11:47:15 -0400659 "%s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 hcd->self.controller->bus->name,
Kay Sievers7071a3c2008-05-02 06:02:41 +0200661 dev_name(hcd->self.controller),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 hcd->product_desc,
663 hcd_name);
664
Alan Stern541c7d42010-06-22 16:39:10 -0400665 if (!HCD_HW_ACCESSIBLE(hcd)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 size -= scnprintf (next, size,
667 "SUSPENDED (no register access)\n");
668 goto done;
669 }
670
671 ohci_dump_status(ohci, &next, &size);
672
673 /* hcca */
674 if (ohci->hcca)
675 ohci_dbg_sw (ohci, &next, &size,
676 "hcca frame 0x%04x\n", ohci_frame_no(ohci));
677
678 /* other registers mostly affect frame timings */
679 rdata = ohci_readl (ohci, &regs->fminterval);
680 temp = scnprintf (next, size,
681 "fmintvl 0x%08x %sFSMPS=0x%04x FI=0x%04x\n",
682 rdata, (rdata >> 31) ? "FIT " : "",
683 (rdata >> 16) & 0xefff, rdata & 0xffff);
684 size -= temp;
685 next += temp;
686
687 rdata = ohci_readl (ohci, &regs->fmremaining);
688 temp = scnprintf (next, size, "fmremaining 0x%08x %sFR=0x%04x\n",
689 rdata, (rdata >> 31) ? "FRT " : "",
690 rdata & 0x3fff);
691 size -= temp;
692 next += temp;
693
694 rdata = ohci_readl (ohci, &regs->periodicstart);
695 temp = scnprintf (next, size, "periodicstart 0x%04x\n",
696 rdata & 0x3fff);
697 size -= temp;
698 next += temp;
699
700 rdata = ohci_readl (ohci, &regs->lsthresh);
701 temp = scnprintf (next, size, "lsthresh 0x%04x\n",
702 rdata & 0x3fff);
703 size -= temp;
704 next += temp;
705
David Brownelld4139842006-08-04 11:31:55 -0700706 temp = scnprintf (next, size, "hub poll timer %s\n",
Alan Stern541c7d42010-06-22 16:39:10 -0400707 HCD_POLL_RH(ohci_to_hcd(ohci)) ? "ON" : "off");
David Brownelld4139842006-08-04 11:31:55 -0700708 size -= temp;
709 next += temp;
710
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 /* roothub */
712 ohci_dump_roothub (ohci, 1, &next, &size);
713
714done:
715 spin_unlock_irqrestore (&ohci->lock, flags);
Tony Jones684c19e2007-09-11 14:07:31 -0700716
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 return PAGE_SIZE - size;
718}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Greg Kroah-Hartman10983342009-04-27 13:12:58 -0700720static struct debug_buffer *alloc_buffer(struct ohci_hcd *ohci,
Tony Jones684c19e2007-09-11 14:07:31 -0700721 ssize_t (*fill_func)(struct debug_buffer *))
722{
723 struct debug_buffer *buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
Tony Jones684c19e2007-09-11 14:07:31 -0700725 buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
726
727 if (buf) {
Greg Kroah-Hartman10983342009-04-27 13:12:58 -0700728 buf->ohci = ohci;
Tony Jones684c19e2007-09-11 14:07:31 -0700729 buf->fill_func = fill_func;
730 mutex_init(&buf->mutex);
731 }
732
733 return buf;
734}
735
736static int fill_buffer(struct debug_buffer *buf)
737{
738 int ret = 0;
739
740 if (!buf->page)
741 buf->page = (char *)get_zeroed_page(GFP_KERNEL);
742
743 if (!buf->page) {
744 ret = -ENOMEM;
745 goto out;
746 }
747
748 ret = buf->fill_func(buf);
749
750 if (ret >= 0) {
751 buf->count = ret;
752 ret = 0;
753 }
754
755out:
756 return ret;
757}
758
759static ssize_t debug_output(struct file *file, char __user *user_buf,
760 size_t len, loff_t *offset)
761{
762 struct debug_buffer *buf = file->private_data;
763 int ret = 0;
764
765 mutex_lock(&buf->mutex);
766 if (buf->count == 0) {
767 ret = fill_buffer(buf);
768 if (ret != 0) {
769 mutex_unlock(&buf->mutex);
770 goto out;
771 }
772 }
773 mutex_unlock(&buf->mutex);
774
775 ret = simple_read_from_buffer(user_buf, len, offset,
776 buf->page, buf->count);
777
778out:
779 return ret;
780
781}
782
783static int debug_close(struct inode *inode, struct file *file)
784{
785 struct debug_buffer *buf = file->private_data;
786
787 if (buf) {
788 if (buf->page)
789 free_page((unsigned long)buf->page);
790 kfree(buf);
791 }
792
793 return 0;
794}
795static int debug_async_open(struct inode *inode, struct file *file)
796{
797 file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
798
799 return file->private_data ? 0 : -ENOMEM;
800}
801
802static int debug_periodic_open(struct inode *inode, struct file *file)
803{
804 file->private_data = alloc_buffer(inode->i_private,
805 fill_periodic_buffer);
806
807 return file->private_data ? 0 : -ENOMEM;
808}
809
810static int debug_registers_open(struct inode *inode, struct file *file)
811{
812 file->private_data = alloc_buffer(inode->i_private,
813 fill_registers_buffer);
814
815 return file->private_data ? 0 : -ENOMEM;
816}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817static inline void create_debug_files (struct ohci_hcd *ohci)
818{
Tony Jones684c19e2007-09-11 14:07:31 -0700819 struct usb_bus *bus = &ohci_to_hcd(ohci)->self;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
Tony Jones684c19e2007-09-11 14:07:31 -0700821 ohci->debug_dir = debugfs_create_dir(bus->bus_name, ohci_debug_root);
822 if (!ohci->debug_dir)
823 goto dir_error;
824
825 ohci->debug_async = debugfs_create_file("async", S_IRUGO,
Greg Kroah-Hartman10983342009-04-27 13:12:58 -0700826 ohci->debug_dir, ohci,
Tony Jones684c19e2007-09-11 14:07:31 -0700827 &debug_async_fops);
828 if (!ohci->debug_async)
829 goto async_error;
830
831 ohci->debug_periodic = debugfs_create_file("periodic", S_IRUGO,
Greg Kroah-Hartman10983342009-04-27 13:12:58 -0700832 ohci->debug_dir, ohci,
Tony Jones684c19e2007-09-11 14:07:31 -0700833 &debug_periodic_fops);
834 if (!ohci->debug_periodic)
835 goto periodic_error;
836
837 ohci->debug_registers = debugfs_create_file("registers", S_IRUGO,
Greg Kroah-Hartman10983342009-04-27 13:12:58 -0700838 ohci->debug_dir, ohci,
Tony Jones684c19e2007-09-11 14:07:31 -0700839 &debug_registers_fops);
840 if (!ohci->debug_registers)
841 goto registers_error;
842
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 ohci_dbg (ohci, "created debug files\n");
Tony Jones684c19e2007-09-11 14:07:31 -0700844 return;
845
846registers_error:
847 debugfs_remove(ohci->debug_periodic);
848periodic_error:
849 debugfs_remove(ohci->debug_async);
850async_error:
851 debugfs_remove(ohci->debug_dir);
852dir_error:
853 ohci->debug_periodic = NULL;
854 ohci->debug_async = NULL;
855 ohci->debug_dir = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856}
857
858static inline void remove_debug_files (struct ohci_hcd *ohci)
859{
Tony Jones684c19e2007-09-11 14:07:31 -0700860 debugfs_remove(ohci->debug_registers);
861 debugfs_remove(ohci->debug_periodic);
862 debugfs_remove(ohci->debug_async);
863 debugfs_remove(ohci->debug_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864}
865
866#endif
867
868/*-------------------------------------------------------------------------*/
869