2 * Copyright (c) 2001-2002 by David Brownell
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* this file is part of ehci-hcd.c */
21 #define ehci_dbg(ehci, fmt, args...) \
22 dev_dbg (ehci_to_hcd(ehci)->self.controller , fmt , ## args )
23 #define ehci_err(ehci, fmt, args...) \
24 dev_err (ehci_to_hcd(ehci)->self.controller , fmt , ## args )
25 #define ehci_info(ehci, fmt, args...) \
26 dev_info (ehci_to_hcd(ehci)->self.controller , fmt , ## args )
27 #define ehci_warn(ehci, fmt, args...) \
28 dev_warn (ehci_to_hcd(ehci)->self.controller , fmt , ## args )
32 # define ehci_vdbg ehci_dbg
34 # define vdbg(fmt,args...) do { } while (0)
35 # define ehci_vdbg(ehci, fmt, args...) do { } while (0)
40 /* check the values in the HCSPARAMS register
41 * (host controller _Structural_ parameters)
42 * see EHCI spec, Table 2-4 for each value
44 static void dbg_hcs_params (struct ehci_hcd *ehci, char *label)
46 u32 params = ehci_readl(ehci, &ehci->caps->hcs_params);
49 "%s hcs_params 0x%x dbg=%d%s cc=%d pcc=%d%s%s ports=%d\n",
51 HCS_DEBUG_PORT (params),
52 HCS_INDICATOR (params) ? " ind" : "",
55 HCS_PORTROUTED (params) ? "" : " ordered",
56 HCS_PPC (params) ? "" : " !ppc",
59 /* Port routing, per EHCI 0.95 Spec, Section 2.2.5 */
60 if (HCS_PORTROUTED (params)) {
62 char buf [46], tmp [7], byte;
65 for (i = 0; i < HCS_N_PORTS (params); i++) {
66 // FIXME MIPS won't readb() ...
67 byte = readb (&ehci->caps->portroute[(i>>1)]);
69 ((i & 0x1) ? ((byte)&0xf) : ((byte>>4)&0xf)));
72 ehci_dbg (ehci, "%s portroute %s\n",
78 static inline void dbg_hcs_params (struct ehci_hcd *ehci, char *label) {}
84 /* check the values in the HCCPARAMS register
85 * (host controller _Capability_ parameters)
86 * see EHCI Spec, Table 2-5 for each value
88 static void dbg_hcc_params (struct ehci_hcd *ehci, char *label)
90 u32 params = ehci_readl(ehci, &ehci->caps->hcc_params);
92 if (HCC_ISOC_CACHE (params)) {
94 "%s hcc_params %04x caching frame %s%s%s\n",
96 HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
97 HCC_CANPARK(params) ? " park" : "",
98 HCC_64BIT_ADDR(params) ? " 64 bit addr" : "");
101 "%s hcc_params %04x thresh %d uframes %s%s%s\n",
104 HCC_ISOC_THRES(params),
105 HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
106 HCC_CANPARK(params) ? " park" : "",
107 HCC_64BIT_ADDR(params) ? " 64 bit addr" : "");
112 static inline void dbg_hcc_params (struct ehci_hcd *ehci, char *label) {}
118 static void __maybe_unused
119 dbg_qtd (const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd)
121 ehci_dbg(ehci, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd,
122 hc32_to_cpup(ehci, &qtd->hw_next),
123 hc32_to_cpup(ehci, &qtd->hw_alt_next),
124 hc32_to_cpup(ehci, &qtd->hw_token),
125 hc32_to_cpup(ehci, &qtd->hw_buf [0]));
127 ehci_dbg(ehci, " p1=%08x p2=%08x p3=%08x p4=%08x\n",
128 hc32_to_cpup(ehci, &qtd->hw_buf[1]),
129 hc32_to_cpup(ehci, &qtd->hw_buf[2]),
130 hc32_to_cpup(ehci, &qtd->hw_buf[3]),
131 hc32_to_cpup(ehci, &qtd->hw_buf[4]));
134 static void __maybe_unused
135 dbg_qh (const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
137 ehci_dbg (ehci, "%s qh %p n%08x info %x %x qtd %x\n", label,
138 qh, qh->hw_next, qh->hw_info1, qh->hw_info2,
140 dbg_qtd ("overlay", ehci, (struct ehci_qtd *) &qh->hw_qtd_next);
143 static void __maybe_unused
144 dbg_itd (const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd)
146 ehci_dbg (ehci, "%s [%d] itd %p, next %08x, urb %p\n",
147 label, itd->frame, itd, hc32_to_cpu(ehci, itd->hw_next),
150 " trans: %08x %08x %08x %08x %08x %08x %08x %08x\n",
151 hc32_to_cpu(ehci, itd->hw_transaction[0]),
152 hc32_to_cpu(ehci, itd->hw_transaction[1]),
153 hc32_to_cpu(ehci, itd->hw_transaction[2]),
154 hc32_to_cpu(ehci, itd->hw_transaction[3]),
155 hc32_to_cpu(ehci, itd->hw_transaction[4]),
156 hc32_to_cpu(ehci, itd->hw_transaction[5]),
157 hc32_to_cpu(ehci, itd->hw_transaction[6]),
158 hc32_to_cpu(ehci, itd->hw_transaction[7]));
160 " buf: %08x %08x %08x %08x %08x %08x %08x\n",
161 hc32_to_cpu(ehci, itd->hw_bufp[0]),
162 hc32_to_cpu(ehci, itd->hw_bufp[1]),
163 hc32_to_cpu(ehci, itd->hw_bufp[2]),
164 hc32_to_cpu(ehci, itd->hw_bufp[3]),
165 hc32_to_cpu(ehci, itd->hw_bufp[4]),
166 hc32_to_cpu(ehci, itd->hw_bufp[5]),
167 hc32_to_cpu(ehci, itd->hw_bufp[6]));
168 ehci_dbg (ehci, " index: %d %d %d %d %d %d %d %d\n",
169 itd->index[0], itd->index[1], itd->index[2],
170 itd->index[3], itd->index[4], itd->index[5],
171 itd->index[6], itd->index[7]);
174 static void __maybe_unused
175 dbg_sitd (const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd)
177 ehci_dbg (ehci, "%s [%d] sitd %p, next %08x, urb %p\n",
178 label, sitd->frame, sitd, hc32_to_cpu(ehci, sitd->hw_next),
181 " addr %08x sched %04x result %08x buf %08x %08x\n",
182 hc32_to_cpu(ehci, sitd->hw_fullspeed_ep),
183 hc32_to_cpu(ehci, sitd->hw_uframe),
184 hc32_to_cpu(ehci, sitd->hw_results),
185 hc32_to_cpu(ehci, sitd->hw_buf[0]),
186 hc32_to_cpu(ehci, sitd->hw_buf[1]));
189 static int __maybe_unused
190 dbg_status_buf (char *buf, unsigned len, const char *label, u32 status)
192 return scnprintf (buf, len,
193 "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s",
194 label, label [0] ? " " : "", status,
195 (status & STS_ASS) ? " Async" : "",
196 (status & STS_PSS) ? " Periodic" : "",
197 (status & STS_RECL) ? " Recl" : "",
198 (status & STS_HALT) ? " Halt" : "",
199 (status & STS_IAA) ? " IAA" : "",
200 (status & STS_FATAL) ? " FATAL" : "",
201 (status & STS_FLR) ? " FLR" : "",
202 (status & STS_PCD) ? " PCD" : "",
203 (status & STS_ERR) ? " ERR" : "",
204 (status & STS_INT) ? " INT" : ""
208 static int __maybe_unused
209 dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable)
211 return scnprintf (buf, len,
212 "%s%sintrenable %02x%s%s%s%s%s%s",
213 label, label [0] ? " " : "", enable,
214 (enable & STS_IAA) ? " IAA" : "",
215 (enable & STS_FATAL) ? " FATAL" : "",
216 (enable & STS_FLR) ? " FLR" : "",
217 (enable & STS_PCD) ? " PCD" : "",
218 (enable & STS_ERR) ? " ERR" : "",
219 (enable & STS_INT) ? " INT" : ""
223 static const char *const fls_strings [] =
224 { "1024", "512", "256", "??" };
227 dbg_command_buf (char *buf, unsigned len, const char *label, u32 command)
229 return scnprintf (buf, len,
230 "%s%scommand %06x %s=%d ithresh=%d%s%s%s%s period=%s%s %s",
231 label, label [0] ? " " : "", command,
232 (command & CMD_PARK) ? "park" : "(park)",
233 CMD_PARK_CNT (command),
234 (command >> 16) & 0x3f,
235 (command & CMD_LRESET) ? " LReset" : "",
236 (command & CMD_IAAD) ? " IAAD" : "",
237 (command & CMD_ASE) ? " Async" : "",
238 (command & CMD_PSE) ? " Periodic" : "",
239 fls_strings [(command >> 2) & 0x3],
240 (command & CMD_RESET) ? " Reset" : "",
241 (command & CMD_RUN) ? "RUN" : "HALT"
246 dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status)
250 /* signaling state */
251 switch (status & (3 << 10)) {
252 case 0 << 10: sig = "se0"; break;
253 case 1 << 10: sig = "k"; break; /* low speed */
254 case 2 << 10: sig = "j"; break;
255 default: sig = "?"; break;
258 return scnprintf (buf, len,
259 "%s%sport %d status %06x%s%s sig=%s%s%s%s%s%s%s%s%s%s",
260 label, label [0] ? " " : "", port, status,
261 (status & PORT_POWER) ? " POWER" : "",
262 (status & PORT_OWNER) ? " OWNER" : "",
264 (status & PORT_RESET) ? " RESET" : "",
265 (status & PORT_SUSPEND) ? " SUSPEND" : "",
266 (status & PORT_RESUME) ? " RESUME" : "",
267 (status & PORT_OCC) ? " OCC" : "",
268 (status & PORT_OC) ? " OC" : "",
269 (status & PORT_PEC) ? " PEC" : "",
270 (status & PORT_PE) ? " PE" : "",
271 (status & PORT_CSC) ? " CSC" : "",
272 (status & PORT_CONNECT) ? " CONNECT" : "");
276 static inline void __maybe_unused
277 dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
280 static inline int __maybe_unused
281 dbg_status_buf (char *buf, unsigned len, const char *label, u32 status)
284 static inline int __maybe_unused
285 dbg_command_buf (char *buf, unsigned len, const char *label, u32 command)
288 static inline int __maybe_unused
289 dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable)
292 static inline int __maybe_unused
293 dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status)
298 /* functions have the "wrong" filename when they're output... */
299 #define dbg_status(ehci, label, status) { \
301 dbg_status_buf (_buf, sizeof _buf, label, status); \
302 ehci_dbg (ehci, "%s\n", _buf); \
305 #define dbg_cmd(ehci, label, command) { \
307 dbg_command_buf (_buf, sizeof _buf, label, command); \
308 ehci_dbg (ehci, "%s\n", _buf); \
311 #define dbg_port(ehci, label, port, status) { \
313 dbg_port_buf (_buf, sizeof _buf, label, port, status); \
314 ehci_dbg (ehci, "%s\n", _buf); \
317 /*-------------------------------------------------------------------------*/
319 #ifdef STUB_DEBUG_FILES
321 static inline void create_debug_files (struct ehci_hcd *bus) { }
322 static inline void remove_debug_files (struct ehci_hcd *bus) { }
326 /* troubleshooting help: expose state in debugfs */
328 static int debug_async_open(struct inode *, struct file *);
329 static int debug_periodic_open(struct inode *, struct file *);
330 static int debug_registers_open(struct inode *, struct file *);
331 static int debug_async_open(struct inode *, struct file *);
332 static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
333 static int debug_close(struct inode *, struct file *);
335 static const struct file_operations debug_async_fops = {
336 .owner = THIS_MODULE,
337 .open = debug_async_open,
338 .read = debug_output,
339 .release = debug_close,
341 static const struct file_operations debug_periodic_fops = {
342 .owner = THIS_MODULE,
343 .open = debug_periodic_open,
344 .read = debug_output,
345 .release = debug_close,
347 static const struct file_operations debug_registers_fops = {
348 .owner = THIS_MODULE,
349 .open = debug_registers_open,
350 .read = debug_output,
351 .release = debug_close,
354 static struct dentry *ehci_debug_root;
356 struct debug_buffer {
357 ssize_t (*fill_func)(struct debug_buffer *); /* fill method */
359 struct mutex mutex; /* protect filling of buffer */
360 size_t count; /* number of characters filled into buffer */
365 #define speed_char(info1) ({ char tmp; \
366 switch (info1 & (3 << 12)) { \
367 case 0 << 12: tmp = 'f'; break; \
368 case 1 << 12: tmp = 'l'; break; \
369 case 2 << 12: tmp = 'h'; break; \
370 default: tmp = '?'; break; \
373 static inline char token_mark(struct ehci_hcd *ehci, __hc32 token)
375 __u32 v = hc32_to_cpu(ehci, token);
377 if (v & QTD_STS_ACTIVE)
379 if (v & QTD_STS_HALT)
381 if (!IS_SHORT_READ (v))
383 /* tries to advance through hw_alt_next */
387 static void qh_lines (
388 struct ehci_hcd *ehci,
396 struct list_head *entry;
399 unsigned size = *sizep;
402 __le32 list_end = EHCI_LIST_END(ehci);
404 if (qh->hw_qtd_next == list_end) /* NEC does this */
407 mark = token_mark(ehci, qh->hw_token);
408 if (mark == '/') { /* qh_alt_next controls qh advance? */
409 if ((qh->hw_alt_next & QTD_MASK(ehci))
410 == ehci->async->hw_alt_next)
411 mark = '#'; /* blocked */
412 else if (qh->hw_alt_next == list_end)
413 mark = '.'; /* use hw_qtd_next */
414 /* else alt_next points to some other qtd */
416 scratch = hc32_to_cpup(ehci, &qh->hw_info1);
417 hw_curr = (mark == '*') ? hc32_to_cpup(ehci, &qh->hw_current) : 0;
418 temp = scnprintf (next, size,
419 "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)",
420 qh, scratch & 0x007f,
421 speed_char (scratch),
422 (scratch >> 8) & 0x000f,
423 scratch, hc32_to_cpup(ehci, &qh->hw_info2),
424 hc32_to_cpup(ehci, &qh->hw_token), mark,
425 (cpu_to_hc32(ehci, QTD_TOGGLE) & qh->hw_token)
427 (hc32_to_cpup(ehci, &qh->hw_alt_next) >> 1) & 0x0f);
431 /* hc may be modifying the list as we read it ... */
432 list_for_each (entry, &qh->qtd_list) {
433 td = list_entry (entry, struct ehci_qtd, qtd_list);
434 scratch = hc32_to_cpup(ehci, &td->hw_token);
436 if (hw_curr == td->qtd_dma)
438 else if (qh->hw_qtd_next == cpu_to_hc32(ehci, td->qtd_dma))
440 else if (QTD_LENGTH (scratch)) {
441 if (td->hw_alt_next == ehci->async->hw_alt_next)
443 else if (td->hw_alt_next != list_end)
446 temp = snprintf (next, size,
447 "\n\t%p%c%s len=%d %08x urb %p",
448 td, mark, ({ char *tmp;
449 switch ((scratch>>8)&0x03) {
450 case 0: tmp = "out"; break;
451 case 1: tmp = "in"; break;
452 case 2: tmp = "setup"; break;
453 default: tmp = "?"; break;
455 (scratch >> 16) & 0x7fff,
460 else if (size < temp)
468 temp = snprintf (next, size, "\n");
471 else if (size < temp)
481 static ssize_t fill_async_buffer(struct debug_buffer *buf)
484 struct ehci_hcd *ehci;
490 hcd = bus_to_hcd(buf->bus);
491 ehci = hcd_to_ehci (hcd);
492 next = buf->output_buf;
493 size = buf->alloc_size;
497 /* dumps a snapshot of the async schedule.
498 * usually empty except for long-term bulk reads, or head.
499 * one QH per line, and TDs we know about
501 spin_lock_irqsave (&ehci->lock, flags);
502 for (qh = ehci->async->qh_next.qh; size > 0 && qh; qh = qh->qh_next.qh)
503 qh_lines (ehci, qh, &next, &size);
504 if (ehci->reclaim && size > 0) {
505 temp = scnprintf (next, size, "\nreclaim =\n");
509 for (qh = ehci->reclaim; size > 0 && qh; qh = qh->reclaim)
510 qh_lines (ehci, qh, &next, &size);
512 spin_unlock_irqrestore (&ehci->lock, flags);
514 return strlen(buf->output_buf);
517 #define DBG_SCHED_LIMIT 64
518 static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
521 struct ehci_hcd *ehci;
523 union ehci_shadow p, *seen;
524 unsigned temp, size, seen_count;
529 if (!(seen = kmalloc (DBG_SCHED_LIMIT * sizeof *seen, GFP_ATOMIC)))
533 hcd = bus_to_hcd(buf->bus);
534 ehci = hcd_to_ehci (hcd);
535 next = buf->output_buf;
536 size = buf->alloc_size;
538 temp = scnprintf (next, size, "size = %d\n", ehci->periodic_size);
542 /* dump a snapshot of the periodic schedule.
543 * iso changes, interrupt usually doesn't.
545 spin_lock_irqsave (&ehci->lock, flags);
546 for (i = 0; i < ehci->periodic_size; i++) {
547 p = ehci->pshadow [i];
550 tag = Q_NEXT_TYPE(ehci, ehci->periodic [i]);
552 temp = scnprintf (next, size, "%4d: ", i);
557 switch (hc32_to_cpu(ehci, tag)) {
559 temp = scnprintf (next, size, " qh%d-%04x/%p",
564 & (QH_CMASK | QH_SMASK),
568 /* don't repeat what follows this qh */
569 for (temp = 0; temp < seen_count; temp++) {
570 if (seen [temp].ptr != p.ptr)
572 if (p.qh->qh_next.ptr) {
573 temp = scnprintf (next, size,
580 /* show more info the first time around */
581 if (temp == seen_count) {
582 u32 scratch = hc32_to_cpup(ehci,
584 struct ehci_qtd *qtd;
587 /* count tds, get ep direction */
589 list_for_each_entry (qtd,
593 switch (0x03 & (hc32_to_cpu(
595 qtd->hw_token) >> 8)) {
596 case 0: type = "out"; continue;
597 case 1: type = "in"; continue;
601 temp = scnprintf (next, size,
604 speed_char (scratch),
606 (scratch >> 8) & 0x000f, type,
607 p.qh->usecs, p.qh->c_usecs,
609 0x7ff & (scratch >> 16));
611 if (seen_count < DBG_SCHED_LIMIT)
612 seen [seen_count++].qh = p.qh;
616 tag = Q_NEXT_TYPE(ehci, p.qh->hw_next);
621 temp = scnprintf (next, size,
622 " fstn-%8x/%p", p.fstn->hw_prev,
624 tag = Q_NEXT_TYPE(ehci, p.fstn->hw_next);
625 p = p.fstn->fstn_next;
628 temp = scnprintf (next, size,
630 tag = Q_NEXT_TYPE(ehci, p.itd->hw_next);
634 temp = scnprintf (next, size,
636 p.sitd->stream->interval,
637 hc32_to_cpup(ehci, &p.sitd->hw_uframe)
640 tag = Q_NEXT_TYPE(ehci, p.sitd->hw_next);
641 p = p.sitd->sitd_next;
648 temp = scnprintf (next, size, "\n");
652 spin_unlock_irqrestore (&ehci->lock, flags);
655 return buf->alloc_size - size;
657 #undef DBG_SCHED_LIMIT
659 static ssize_t fill_registers_buffer(struct debug_buffer *buf)
662 struct ehci_hcd *ehci;
664 unsigned temp, size, i;
665 char *next, scratch [80];
666 static char fmt [] = "%*s\n";
667 static char label [] = "";
669 hcd = bus_to_hcd(buf->bus);
670 ehci = hcd_to_ehci (hcd);
671 next = buf->output_buf;
672 size = buf->alloc_size;
674 spin_lock_irqsave (&ehci->lock, flags);
676 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
677 size = scnprintf (next, size,
678 "bus %s, device %s\n"
680 "SUSPENDED (no register access)\n",
681 hcd->self.controller->bus->name,
682 dev_name(hcd->self.controller),
687 /* Capability Registers */
688 i = HC_VERSION(ehci_readl(ehci, &ehci->caps->hc_capbase));
689 temp = scnprintf (next, size,
690 "bus %s, device %s\n"
692 "EHCI %x.%02x, hcd state %d\n",
693 hcd->self.controller->bus->name,
694 dev_name(hcd->self.controller),
696 i >> 8, i & 0x0ff, hcd->state);
701 /* EHCI 0.96 and later may have "extended capabilities" */
702 if (hcd->self.controller->bus == &pci_bus_type) {
703 struct pci_dev *pdev;
704 u32 offset, cap, cap2;
705 unsigned count = 256/4;
707 pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller);
708 offset = HCC_EXT_CAPS(ehci_readl(ehci,
709 &ehci->caps->hcc_params));
710 while (offset && count--) {
711 pci_read_config_dword (pdev, offset, &cap);
712 switch (cap & 0xff) {
714 temp = scnprintf (next, size,
715 "ownership %08x%s%s\n", cap,
716 (cap & (1 << 24)) ? " linux" : "",
717 (cap & (1 << 16)) ? " firmware" : "");
722 pci_read_config_dword (pdev, offset, &cap2);
723 temp = scnprintf (next, size,
724 "SMI sts/enable 0x%08x\n", cap2);
728 case 0: /* illegal reserved capability */
731 default: /* unknown */
734 temp = (cap >> 8) & 0xff;
739 // FIXME interpret both types of params
740 i = ehci_readl(ehci, &ehci->caps->hcs_params);
741 temp = scnprintf (next, size, "structural params 0x%08x\n", i);
745 i = ehci_readl(ehci, &ehci->caps->hcc_params);
746 temp = scnprintf (next, size, "capability params 0x%08x\n", i);
750 /* Operational Registers */
751 temp = dbg_status_buf (scratch, sizeof scratch, label,
752 ehci_readl(ehci, &ehci->regs->status));
753 temp = scnprintf (next, size, fmt, temp, scratch);
757 temp = dbg_command_buf (scratch, sizeof scratch, label,
758 ehci_readl(ehci, &ehci->regs->command));
759 temp = scnprintf (next, size, fmt, temp, scratch);
763 temp = dbg_intr_buf (scratch, sizeof scratch, label,
764 ehci_readl(ehci, &ehci->regs->intr_enable));
765 temp = scnprintf (next, size, fmt, temp, scratch);
769 temp = scnprintf (next, size, "uframe %04x\n",
770 ehci_readl(ehci, &ehci->regs->frame_index));
774 for (i = 1; i <= HCS_N_PORTS (ehci->hcs_params); i++) {
775 temp = dbg_port_buf (scratch, sizeof scratch, label, i,
777 &ehci->regs->port_status[i - 1]));
778 temp = scnprintf (next, size, fmt, temp, scratch);
781 if (i == HCS_DEBUG_PORT(ehci->hcs_params) && ehci->debug) {
782 temp = scnprintf (next, size,
783 " debug control %08x\n",
785 &ehci->debug->control));
792 temp = scnprintf(next, size, "reclaim qh %p\n", ehci->reclaim);
798 temp = scnprintf (next, size,
799 "irq normal %ld err %ld reclaim %ld (lost %ld)\n",
800 ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim,
801 ehci->stats.lost_iaa);
805 temp = scnprintf (next, size, "complete %ld unlink %ld\n",
806 ehci->stats.complete, ehci->stats.unlink);
812 spin_unlock_irqrestore (&ehci->lock, flags);
814 return buf->alloc_size - size;
817 static struct debug_buffer *alloc_buffer(struct usb_bus *bus,
818 ssize_t (*fill_func)(struct debug_buffer *))
820 struct debug_buffer *buf;
822 buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
826 buf->fill_func = fill_func;
827 mutex_init(&buf->mutex);
828 buf->alloc_size = PAGE_SIZE;
834 static int fill_buffer(struct debug_buffer *buf)
838 if (!buf->output_buf)
839 buf->output_buf = (char *)vmalloc(buf->alloc_size);
841 if (!buf->output_buf) {
846 ret = buf->fill_func(buf);
857 static ssize_t debug_output(struct file *file, char __user *user_buf,
858 size_t len, loff_t *offset)
860 struct debug_buffer *buf = file->private_data;
863 mutex_lock(&buf->mutex);
864 if (buf->count == 0) {
865 ret = fill_buffer(buf);
867 mutex_unlock(&buf->mutex);
871 mutex_unlock(&buf->mutex);
873 ret = simple_read_from_buffer(user_buf, len, offset,
874 buf->output_buf, buf->count);
881 static int debug_close(struct inode *inode, struct file *file)
883 struct debug_buffer *buf = file->private_data;
887 vfree(buf->output_buf);
893 static int debug_async_open(struct inode *inode, struct file *file)
895 file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
897 return file->private_data ? 0 : -ENOMEM;
900 static int debug_periodic_open(struct inode *inode, struct file *file)
902 struct debug_buffer *buf;
903 buf = alloc_buffer(inode->i_private, fill_periodic_buffer);
907 buf->alloc_size = (sizeof(void *) == 4 ? 6 : 8)*PAGE_SIZE;
908 file->private_data = buf;
912 static int debug_registers_open(struct inode *inode, struct file *file)
914 file->private_data = alloc_buffer(inode->i_private,
915 fill_registers_buffer);
917 return file->private_data ? 0 : -ENOMEM;
920 static inline void create_debug_files (struct ehci_hcd *ehci)
922 struct usb_bus *bus = &ehci_to_hcd(ehci)->self;
924 ehci->debug_dir = debugfs_create_dir(bus->bus_name, ehci_debug_root);
925 if (!ehci->debug_dir)
928 ehci->debug_async = debugfs_create_file("async", S_IRUGO,
929 ehci->debug_dir, bus,
931 if (!ehci->debug_async)
934 ehci->debug_periodic = debugfs_create_file("periodic", S_IRUGO,
935 ehci->debug_dir, bus,
936 &debug_periodic_fops);
937 if (!ehci->debug_periodic)
940 ehci->debug_registers = debugfs_create_file("registers", S_IRUGO,
941 ehci->debug_dir, bus,
942 &debug_registers_fops);
943 if (!ehci->debug_registers)
944 goto registers_error;
948 debugfs_remove(ehci->debug_periodic);
950 debugfs_remove(ehci->debug_async);
952 debugfs_remove(ehci->debug_dir);
954 ehci->debug_periodic = NULL;
955 ehci->debug_async = NULL;
956 ehci->debug_dir = NULL;
959 static inline void remove_debug_files (struct ehci_hcd *ehci)
961 debugfs_remove(ehci->debug_registers);
962 debugfs_remove(ehci->debug_periodic);
963 debugfs_remove(ehci->debug_async);
964 debugfs_remove(ehci->debug_dir);
967 #endif /* STUB_DEBUG_FILES */