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)->hcd.self.controller , fmt , ## args )
23 #define ehci_err(ehci, fmt, args...) \
24 dev_err ((ehci)->hcd.self.controller , fmt , ## args )
25 #define ehci_info(ehci, fmt, args...) \
26 dev_info ((ehci)->hcd.self.controller , fmt , ## args )
27 #define ehci_warn(ehci, fmt, args...) \
28 dev_warn ((ehci)->hcd.self.controller , fmt , ## args )
30 #ifdef EHCI_VERBOSE_DEBUG
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 = readl (&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 = readl (&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 __attribute__((__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 le32_to_cpup (&qtd->hw_next),
123 le32_to_cpup (&qtd->hw_alt_next),
124 le32_to_cpup (&qtd->hw_token),
125 le32_to_cpup (&qtd->hw_buf [0]));
127 ehci_dbg (ehci, " p1=%08x p2=%08x p3=%08x p4=%08x\n",
128 le32_to_cpup (&qtd->hw_buf [1]),
129 le32_to_cpup (&qtd->hw_buf [2]),
130 le32_to_cpup (&qtd->hw_buf [3]),
131 le32_to_cpup (&qtd->hw_buf [4]));
134 static void __attribute__((__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 __attribute__((__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, le32_to_cpu(itd->hw_next), itd->urb);
149 " trans: %08x %08x %08x %08x %08x %08x %08x %08x\n",
150 le32_to_cpu(itd->hw_transaction[0]),
151 le32_to_cpu(itd->hw_transaction[1]),
152 le32_to_cpu(itd->hw_transaction[2]),
153 le32_to_cpu(itd->hw_transaction[3]),
154 le32_to_cpu(itd->hw_transaction[4]),
155 le32_to_cpu(itd->hw_transaction[5]),
156 le32_to_cpu(itd->hw_transaction[6]),
157 le32_to_cpu(itd->hw_transaction[7]));
159 " buf: %08x %08x %08x %08x %08x %08x %08x\n",
160 le32_to_cpu(itd->hw_bufp[0]),
161 le32_to_cpu(itd->hw_bufp[1]),
162 le32_to_cpu(itd->hw_bufp[2]),
163 le32_to_cpu(itd->hw_bufp[3]),
164 le32_to_cpu(itd->hw_bufp[4]),
165 le32_to_cpu(itd->hw_bufp[5]),
166 le32_to_cpu(itd->hw_bufp[6]));
167 ehci_dbg (ehci, " index: %d %d %d %d %d %d %d %d\n",
168 itd->index[0], itd->index[1], itd->index[2],
169 itd->index[3], itd->index[4], itd->index[5],
170 itd->index[6], itd->index[7]);
173 static void __attribute__((__unused__))
174 dbg_sitd (const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd)
176 ehci_dbg (ehci, "%s [%d] sitd %p, next %08x, urb %p\n",
177 label, sitd->frame, sitd, le32_to_cpu(sitd->hw_next), sitd->urb);
179 " addr %08x sched %04x result %08x buf %08x %08x\n",
180 le32_to_cpu(sitd->hw_fullspeed_ep),
181 le32_to_cpu(sitd->hw_uframe),
182 le32_to_cpu(sitd->hw_results),
183 le32_to_cpu(sitd->hw_buf [0]),
184 le32_to_cpu(sitd->hw_buf [1]));
187 static int __attribute__((__unused__))
188 dbg_status_buf (char *buf, unsigned len, char *label, u32 status)
190 return scnprintf (buf, len,
191 "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s",
192 label, label [0] ? " " : "", status,
193 (status & STS_ASS) ? " Async" : "",
194 (status & STS_PSS) ? " Periodic" : "",
195 (status & STS_RECL) ? " Recl" : "",
196 (status & STS_HALT) ? " Halt" : "",
197 (status & STS_IAA) ? " IAA" : "",
198 (status & STS_FATAL) ? " FATAL" : "",
199 (status & STS_FLR) ? " FLR" : "",
200 (status & STS_PCD) ? " PCD" : "",
201 (status & STS_ERR) ? " ERR" : "",
202 (status & STS_INT) ? " INT" : ""
206 static int __attribute__((__unused__))
207 dbg_intr_buf (char *buf, unsigned len, char *label, u32 enable)
209 return scnprintf (buf, len,
210 "%s%sintrenable %02x%s%s%s%s%s%s",
211 label, label [0] ? " " : "", enable,
212 (enable & STS_IAA) ? " IAA" : "",
213 (enable & STS_FATAL) ? " FATAL" : "",
214 (enable & STS_FLR) ? " FLR" : "",
215 (enable & STS_PCD) ? " PCD" : "",
216 (enable & STS_ERR) ? " ERR" : "",
217 (enable & STS_INT) ? " INT" : ""
221 static const char *const fls_strings [] =
222 { "1024", "512", "256", "??" };
224 static int dbg_command_buf (char *buf, unsigned len, char *label, u32 command)
226 return scnprintf (buf, len,
227 "%s%scommand %06x %s=%d ithresh=%d%s%s%s%s period=%s%s %s",
228 label, label [0] ? " " : "", command,
229 (command & CMD_PARK) ? "park" : "(park)",
230 CMD_PARK_CNT (command),
231 (command >> 16) & 0x3f,
232 (command & CMD_LRESET) ? " LReset" : "",
233 (command & CMD_IAAD) ? " IAAD" : "",
234 (command & CMD_ASE) ? " Async" : "",
235 (command & CMD_PSE) ? " Periodic" : "",
236 fls_strings [(command >> 2) & 0x3],
237 (command & CMD_RESET) ? " Reset" : "",
238 (command & CMD_RUN) ? "RUN" : "HALT"
243 dbg_port_buf (char *buf, unsigned len, char *label, int port, u32 status)
247 /* signaling state */
248 switch (status & (3 << 10)) {
249 case 0 << 10: sig = "se0"; break;
250 case 1 << 10: sig = "k"; break; /* low speed */
251 case 2 << 10: sig = "j"; break;
252 default: sig = "?"; break;
255 return scnprintf (buf, len,
256 "%s%sport %d status %06x%s%s sig=%s %s%s%s%s%s%s%s%s%s",
257 label, label [0] ? " " : "", port, status,
258 (status & PORT_POWER) ? " POWER" : "",
259 (status & PORT_OWNER) ? " OWNER" : "",
261 (status & PORT_RESET) ? " RESET" : "",
262 (status & PORT_SUSPEND) ? " SUSPEND" : "",
263 (status & PORT_RESUME) ? " RESUME" : "",
264 (status & PORT_OCC) ? " OCC" : "",
265 (status & PORT_OC) ? " OC" : "",
266 (status & PORT_PEC) ? " PEC" : "",
267 (status & PORT_PE) ? " PE" : "",
268 (status & PORT_CSC) ? " CSC" : "",
269 (status & PORT_CONNECT) ? " CONNECT" : ""
274 static inline void __attribute__((__unused__))
275 dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
278 static inline int __attribute__((__unused__))
279 dbg_status_buf (char *buf, unsigned len, char *label, u32 status)
282 static inline int __attribute__((__unused__))
283 dbg_command_buf (char *buf, unsigned len, char *label, u32 command)
286 static inline int __attribute__((__unused__))
287 dbg_intr_buf (char *buf, unsigned len, char *label, u32 enable)
290 static inline int __attribute__((__unused__))
291 dbg_port_buf (char *buf, unsigned len, char *label, int port, u32 status)
296 /* functions have the "wrong" filename when they're output... */
297 #define dbg_status(ehci, label, status) { \
299 dbg_status_buf (_buf, sizeof _buf, label, status); \
300 ehci_dbg (ehci, "%s\n", _buf); \
303 #define dbg_cmd(ehci, label, command) { \
305 dbg_command_buf (_buf, sizeof _buf, label, command); \
306 ehci_dbg (ehci, "%s\n", _buf); \
309 #define dbg_port(ehci, label, port, status) { \
311 dbg_port_buf (_buf, sizeof _buf, label, port, status); \
312 ehci_dbg (ehci, "%s\n", _buf); \
315 /*-------------------------------------------------------------------------*/
317 #ifdef STUB_DEBUG_FILES
319 static inline void create_debug_files (struct ehci_hcd *bus) { }
320 static inline void remove_debug_files (struct ehci_hcd *bus) { }
324 /* troubleshooting help: expose state in driverfs */
326 #define speed_char(info1) ({ char tmp; \
327 switch (info1 & (3 << 12)) { \
328 case 0 << 12: tmp = 'f'; break; \
329 case 1 << 12: tmp = 'l'; break; \
330 case 2 << 12: tmp = 'h'; break; \
331 default: tmp = '?'; break; \
334 static inline char token_mark (__le32 token)
336 __u32 v = le32_to_cpu (token);
337 if (v & QTD_STS_ACTIVE)
339 if (v & QTD_STS_HALT)
341 if (!IS_SHORT_READ (v))
343 /* tries to advance through hw_alt_next */
347 static void qh_lines (
348 struct ehci_hcd *ehci,
356 struct list_head *entry;
359 unsigned size = *sizep;
363 if (qh->hw_qtd_next == EHCI_LIST_END) /* NEC does this */
366 mark = token_mark (qh->hw_token);
367 if (mark == '/') { /* qh_alt_next controls qh advance? */
368 if ((qh->hw_alt_next & QTD_MASK) == ehci->async->hw_alt_next)
369 mark = '#'; /* blocked */
370 else if (qh->hw_alt_next == EHCI_LIST_END)
371 mark = '.'; /* use hw_qtd_next */
372 /* else alt_next points to some other qtd */
374 scratch = le32_to_cpup (&qh->hw_info1);
375 hw_curr = (mark == '*') ? le32_to_cpup (&qh->hw_current) : 0;
376 temp = scnprintf (next, size,
377 "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)",
378 qh, scratch & 0x007f,
379 speed_char (scratch),
380 (scratch >> 8) & 0x000f,
381 scratch, le32_to_cpup (&qh->hw_info2),
382 le32_to_cpup (&qh->hw_token), mark,
383 (__constant_cpu_to_le32 (QTD_TOGGLE) & qh->hw_token)
385 (le32_to_cpup (&qh->hw_alt_next) >> 1) & 0x0f);
389 /* hc may be modifying the list as we read it ... */
390 list_for_each (entry, &qh->qtd_list) {
391 td = list_entry (entry, struct ehci_qtd, qtd_list);
392 scratch = le32_to_cpup (&td->hw_token);
394 if (hw_curr == td->qtd_dma)
396 else if (qh->hw_qtd_next == td->qtd_dma)
398 else if (QTD_LENGTH (scratch)) {
399 if (td->hw_alt_next == ehci->async->hw_alt_next)
401 else if (td->hw_alt_next != EHCI_LIST_END)
404 temp = snprintf (next, size,
405 "\n\t%p%c%s len=%d %08x urb %p",
406 td, mark, ({ char *tmp;
407 switch ((scratch>>8)&0x03) {
408 case 0: tmp = "out"; break;
409 case 1: tmp = "in"; break;
410 case 2: tmp = "setup"; break;
411 default: tmp = "?"; break;
413 (scratch >> 16) & 0x7fff,
418 else if (size < temp)
426 temp = snprintf (next, size, "\n");
429 else if (size < temp)
440 show_async (struct class_device *class_dev, char *buf)
444 struct ehci_hcd *ehci;
452 bus = to_usb_bus(class_dev);
454 ehci = hcd_to_ehci (hcd);
458 /* dumps a snapshot of the async schedule.
459 * usually empty except for long-term bulk reads, or head.
460 * one QH per line, and TDs we know about
462 spin_lock_irqsave (&ehci->lock, flags);
463 for (qh = ehci->async->qh_next.qh; size > 0 && qh; qh = qh->qh_next.qh)
464 qh_lines (ehci, qh, &next, &size);
465 if (ehci->reclaim && size > 0) {
466 temp = scnprintf (next, size, "\nreclaim =\n");
470 for (qh = ehci->reclaim; size > 0 && qh; qh = qh->reclaim)
471 qh_lines (ehci, qh, &next, &size);
473 spin_unlock_irqrestore (&ehci->lock, flags);
477 static CLASS_DEVICE_ATTR (async, S_IRUGO, show_async, NULL);
479 #define DBG_SCHED_LIMIT 64
482 show_periodic (struct class_device *class_dev, char *buf)
486 struct ehci_hcd *ehci;
488 union ehci_shadow p, *seen;
489 unsigned temp, size, seen_count;
494 if (!(seen = kmalloc (DBG_SCHED_LIMIT * sizeof *seen, SLAB_ATOMIC)))
498 bus = to_usb_bus(class_dev);
500 ehci = hcd_to_ehci (hcd);
504 temp = scnprintf (next, size, "size = %d\n", ehci->periodic_size);
508 /* dump a snapshot of the periodic schedule.
509 * iso changes, interrupt usually doesn't.
511 spin_lock_irqsave (&ehci->lock, flags);
512 for (i = 0; i < ehci->periodic_size; i++) {
513 p = ehci->pshadow [i];
516 tag = Q_NEXT_TYPE (ehci->periodic [i]);
518 temp = scnprintf (next, size, "%4d: ", i);
525 temp = scnprintf (next, size, " qh%d-%04x/%p",
527 le32_to_cpup (&p.qh->hw_info2)
533 /* don't repeat what follows this qh */
534 for (temp = 0; temp < seen_count; temp++) {
535 if (seen [temp].ptr != p.ptr)
537 if (p.qh->qh_next.ptr)
538 temp = scnprintf (next, size,
543 /* show more info the first time around */
544 if (temp == seen_count && p.ptr) {
545 u32 scratch = le32_to_cpup (
547 struct ehci_qtd *qtd;
550 /* count tds, get ep direction */
552 list_for_each_entry (qtd,
556 switch (0x03 & (le32_to_cpu (
557 qtd->hw_token) >> 8)) {
558 case 0: type = "out"; continue;
559 case 1: type = "in"; continue;
563 temp = scnprintf (next, size,
566 speed_char (scratch),
568 (scratch >> 8) & 0x000f, type,
569 p.qh->usecs, p.qh->c_usecs,
571 0x7ff & (scratch >> 16));
573 if (seen_count < DBG_SCHED_LIMIT)
574 seen [seen_count++].qh = p.qh;
578 tag = Q_NEXT_TYPE (p.qh->hw_next);
583 temp = scnprintf (next, size,
584 " fstn-%8x/%p", p.fstn->hw_prev,
586 tag = Q_NEXT_TYPE (p.fstn->hw_next);
587 p = p.fstn->fstn_next;
590 temp = scnprintf (next, size,
592 tag = Q_NEXT_TYPE (p.itd->hw_next);
596 temp = scnprintf (next, size,
598 p.sitd->stream->interval,
599 le32_to_cpup (&p.sitd->hw_uframe)
602 tag = Q_NEXT_TYPE (p.sitd->hw_next);
603 p = p.sitd->sitd_next;
610 temp = scnprintf (next, size, "\n");
614 spin_unlock_irqrestore (&ehci->lock, flags);
617 return PAGE_SIZE - size;
619 static CLASS_DEVICE_ATTR (periodic, S_IRUGO, show_periodic, NULL);
621 #undef DBG_SCHED_LIMIT
624 show_registers (struct class_device *class_dev, char *buf)
628 struct ehci_hcd *ehci;
630 unsigned temp, size, i;
631 char *next, scratch [80];
632 static char fmt [] = "%*s\n";
633 static char label [] = "";
635 bus = to_usb_bus(class_dev);
637 ehci = hcd_to_ehci (hcd);
641 spin_lock_irqsave (&ehci->lock, flags);
643 if (bus->controller->power.power_state) {
644 size = scnprintf (next, size,
645 "bus %s, device %s (driver " DRIVER_VERSION ")\n"
646 "SUSPENDED (no register access)\n",
647 hcd->self.controller->bus->name,
648 hcd->self.controller->bus_id);
652 /* Capability Registers */
653 i = HC_VERSION(readl (&ehci->caps->hc_capbase));
654 temp = scnprintf (next, size,
655 "bus %s, device %s (driver " DRIVER_VERSION ")\n"
656 "EHCI %x.%02x, hcd state %d\n",
657 hcd->self.controller->bus->name,
658 hcd->self.controller->bus_id,
659 i >> 8, i & 0x0ff, ehci->hcd.state);
663 // FIXME interpret both types of params
664 i = readl (&ehci->caps->hcs_params);
665 temp = scnprintf (next, size, "structural params 0x%08x\n", i);
669 i = readl (&ehci->caps->hcc_params);
670 temp = scnprintf (next, size, "capability params 0x%08x\n", i);
674 /* Operational Registers */
675 temp = dbg_status_buf (scratch, sizeof scratch, label,
676 readl (&ehci->regs->status));
677 temp = scnprintf (next, size, fmt, temp, scratch);
681 temp = dbg_command_buf (scratch, sizeof scratch, label,
682 readl (&ehci->regs->command));
683 temp = scnprintf (next, size, fmt, temp, scratch);
687 temp = dbg_intr_buf (scratch, sizeof scratch, label,
688 readl (&ehci->regs->intr_enable));
689 temp = scnprintf (next, size, fmt, temp, scratch);
693 temp = scnprintf (next, size, "uframe %04x\n",
694 readl (&ehci->regs->frame_index));
698 for (i = 0; i < HCS_N_PORTS (ehci->hcs_params); i++) {
699 temp = dbg_port_buf (scratch, sizeof scratch, label, i + 1,
700 readl (&ehci->regs->port_status [i]));
701 temp = scnprintf (next, size, fmt, temp, scratch);
707 temp = scnprintf (next, size, "reclaim qh %p%s\n",
709 ehci->reclaim_ready ? " ready" : "");
715 temp = scnprintf (next, size,
716 "irq normal %ld err %ld reclaim %ld (lost %ld)\n",
717 ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim,
718 ehci->stats.lost_iaa);
722 temp = scnprintf (next, size, "complete %ld unlink %ld\n",
723 ehci->stats.complete, ehci->stats.unlink);
729 spin_unlock_irqrestore (&ehci->lock, flags);
731 return PAGE_SIZE - size;
733 static CLASS_DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL);
735 static inline void create_debug_files (struct ehci_hcd *bus)
737 class_device_create_file(&bus->hcd.self.class_dev, &class_device_attr_async);
738 class_device_create_file(&bus->hcd.self.class_dev, &class_device_attr_periodic);
739 class_device_create_file(&bus->hcd.self.class_dev, &class_device_attr_registers);
742 static inline void remove_debug_files (struct ehci_hcd *bus)
744 class_device_remove_file(&bus->hcd.self.class_dev, &class_device_attr_async);
745 class_device_remove_file(&bus->hcd.self.class_dev, &class_device_attr_periodic);
746 class_device_remove_file(&bus->hcd.self.class_dev, &class_device_attr_registers);
749 #endif /* STUB_DEBUG_FILES */