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 cpu_to_le32p (&qtd->hw_next),
123 cpu_to_le32p (&qtd->hw_alt_next),
124 cpu_to_le32p (&qtd->hw_token),
125 cpu_to_le32p (&qtd->hw_buf [0]));
127 ehci_dbg (ehci, " p1=%08x p2=%08x p3=%08x p4=%08x\n",
128 cpu_to_le32p (&qtd->hw_buf [1]),
129 cpu_to_le32p (&qtd->hw_buf [2]),
130 cpu_to_le32p (&qtd->hw_buf [3]),
131 cpu_to_le32p (&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 int __attribute__((__unused__))
174 dbg_status_buf (char *buf, unsigned len, char *label, u32 status)
176 return scnprintf (buf, len,
177 "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s",
178 label, label [0] ? " " : "", status,
179 (status & STS_ASS) ? " Async" : "",
180 (status & STS_PSS) ? " Periodic" : "",
181 (status & STS_RECL) ? " Recl" : "",
182 (status & STS_HALT) ? " Halt" : "",
183 (status & STS_IAA) ? " IAA" : "",
184 (status & STS_FATAL) ? " FATAL" : "",
185 (status & STS_FLR) ? " FLR" : "",
186 (status & STS_PCD) ? " PCD" : "",
187 (status & STS_ERR) ? " ERR" : "",
188 (status & STS_INT) ? " INT" : ""
192 static int __attribute__((__unused__))
193 dbg_intr_buf (char *buf, unsigned len, char *label, u32 enable)
195 return scnprintf (buf, len,
196 "%s%sintrenable %02x%s%s%s%s%s%s",
197 label, label [0] ? " " : "", enable,
198 (enable & STS_IAA) ? " IAA" : "",
199 (enable & STS_FATAL) ? " FATAL" : "",
200 (enable & STS_FLR) ? " FLR" : "",
201 (enable & STS_PCD) ? " PCD" : "",
202 (enable & STS_ERR) ? " ERR" : "",
203 (enable & STS_INT) ? " INT" : ""
207 static const char *const fls_strings [] =
208 { "1024", "512", "256", "??" };
210 static int dbg_command_buf (char *buf, unsigned len, char *label, u32 command)
212 return scnprintf (buf, len,
213 "%s%scommand %06x %s=%d ithresh=%d%s%s%s%s period=%s%s %s",
214 label, label [0] ? " " : "", command,
215 (command & CMD_PARK) ? "park" : "(park)",
216 CMD_PARK_CNT (command),
217 (command >> 16) & 0x3f,
218 (command & CMD_LRESET) ? " LReset" : "",
219 (command & CMD_IAAD) ? " IAAD" : "",
220 (command & CMD_ASE) ? " Async" : "",
221 (command & CMD_PSE) ? " Periodic" : "",
222 fls_strings [(command >> 2) & 0x3],
223 (command & CMD_RESET) ? " Reset" : "",
224 (command & CMD_RUN) ? "RUN" : "HALT"
229 dbg_port_buf (char *buf, unsigned len, char *label, int port, u32 status)
233 /* signaling state */
234 switch (status & (3 << 10)) {
235 case 0 << 10: sig = "se0"; break;
236 case 1 << 10: sig = "k"; break; /* low speed */
237 case 2 << 10: sig = "j"; break;
238 default: sig = "?"; break;
241 return scnprintf (buf, len,
242 "%s%sport %d status %06x%s%s sig=%s %s%s%s%s%s%s%s%s%s",
243 label, label [0] ? " " : "", port, status,
244 (status & PORT_POWER) ? " POWER" : "",
245 (status & PORT_OWNER) ? " OWNER" : "",
247 (status & PORT_RESET) ? " RESET" : "",
248 (status & PORT_SUSPEND) ? " SUSPEND" : "",
249 (status & PORT_RESUME) ? " RESUME" : "",
250 (status & PORT_OCC) ? " OCC" : "",
251 (status & PORT_OC) ? " OC" : "",
252 (status & PORT_PEC) ? " PEC" : "",
253 (status & PORT_PE) ? " PE" : "",
254 (status & PORT_CSC) ? " CSC" : "",
255 (status & PORT_CONNECT) ? " CONNECT" : ""
260 static inline void __attribute__((__unused__))
261 dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
264 static inline int __attribute__((__unused__))
265 dbg_status_buf (char *buf, unsigned len, char *label, u32 status)
268 static inline int __attribute__((__unused__))
269 dbg_command_buf (char *buf, unsigned len, char *label, u32 command)
272 static inline int __attribute__((__unused__))
273 dbg_intr_buf (char *buf, unsigned len, char *label, u32 enable)
276 static inline int __attribute__((__unused__))
277 dbg_port_buf (char *buf, unsigned len, char *label, int port, u32 status)
282 /* functions have the "wrong" filename when they're output... */
283 #define dbg_status(ehci, label, status) { \
285 dbg_status_buf (_buf, sizeof _buf, label, status); \
286 ehci_dbg (ehci, "%s\n", _buf); \
289 #define dbg_cmd(ehci, label, command) { \
291 dbg_command_buf (_buf, sizeof _buf, label, command); \
292 ehci_dbg (ehci, "%s\n", _buf); \
295 #define dbg_port(ehci, label, port, status) { \
297 dbg_port_buf (_buf, sizeof _buf, label, port, status); \
298 ehci_dbg (ehci, "%s\n", _buf); \
301 /*-------------------------------------------------------------------------*/
303 #ifdef STUB_DEBUG_FILES
305 static inline void create_debug_files (struct ehci_hcd *bus) { }
306 static inline void remove_debug_files (struct ehci_hcd *bus) { }
310 /* troubleshooting help: expose state in driverfs */
312 #define speed_char(info1) ({ char tmp; \
313 switch (info1 & (3 << 12)) { \
314 case 0 << 12: tmp = 'f'; break; \
315 case 1 << 12: tmp = 'l'; break; \
316 case 2 << 12: tmp = 'h'; break; \
317 default: tmp = '?'; break; \
320 static inline char token_mark (u32 token)
322 token = le32_to_cpu (token);
323 if (token & QTD_STS_ACTIVE)
325 if (token & QTD_STS_HALT)
327 if (!IS_SHORT_READ (token))
329 /* tries to advance through hw_alt_next */
333 static void qh_lines (
334 struct ehci_hcd *ehci,
342 struct list_head *entry;
345 unsigned size = *sizep;
349 if (qh->hw_qtd_next == EHCI_LIST_END) /* NEC does this */
352 mark = token_mark (qh->hw_token);
353 if (mark == '/') { /* qh_alt_next controls qh advance? */
354 if ((qh->hw_alt_next & QTD_MASK) == ehci->async->hw_alt_next)
355 mark = '#'; /* blocked */
356 else if (qh->hw_alt_next == EHCI_LIST_END)
357 mark = '.'; /* use hw_qtd_next */
358 /* else alt_next points to some other qtd */
360 scratch = cpu_to_le32p (&qh->hw_info1);
361 hw_curr = (mark == '*') ? cpu_to_le32p (&qh->hw_current) : 0;
362 temp = scnprintf (next, size,
363 "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)",
364 qh, scratch & 0x007f,
365 speed_char (scratch),
366 (scratch >> 8) & 0x000f,
367 scratch, cpu_to_le32p (&qh->hw_info2),
368 cpu_to_le32p (&qh->hw_token), mark,
369 (__constant_cpu_to_le32 (QTD_TOGGLE) & qh->hw_token)
371 (cpu_to_le32p (&qh->hw_alt_next) >> 1) & 0x0f);
375 /* hc may be modifying the list as we read it ... */
376 list_for_each (entry, &qh->qtd_list) {
377 td = list_entry (entry, struct ehci_qtd, qtd_list);
378 scratch = cpu_to_le32p (&td->hw_token);
380 if (hw_curr == td->qtd_dma)
382 else if (qh->hw_qtd_next == td->qtd_dma)
384 else if (QTD_LENGTH (scratch)) {
385 if (td->hw_alt_next == ehci->async->hw_alt_next)
387 else if (td->hw_alt_next != EHCI_LIST_END)
390 temp = snprintf (next, size,
391 "\n\t%p%c%s len=%d %08x urb %p",
392 td, mark, ({ char *tmp;
393 switch ((scratch>>8)&0x03) {
394 case 0: tmp = "out"; break;
395 case 1: tmp = "in"; break;
396 case 2: tmp = "setup"; break;
397 default: tmp = "?"; break;
399 (scratch >> 16) & 0x7fff,
404 else if (size < temp)
412 temp = snprintf (next, size, "\n");
415 else if (size < temp)
426 show_async (struct class_device *class_dev, char *buf)
430 struct ehci_hcd *ehci;
438 bus = to_usb_bus(class_dev);
440 ehci = hcd_to_ehci (hcd);
444 /* dumps a snapshot of the async schedule.
445 * usually empty except for long-term bulk reads, or head.
446 * one QH per line, and TDs we know about
448 spin_lock_irqsave (&ehci->lock, flags);
449 for (qh = ehci->async->qh_next.qh; size > 0 && qh; qh = qh->qh_next.qh)
450 qh_lines (ehci, qh, &next, &size);
451 if (ehci->reclaim && size > 0) {
452 temp = scnprintf (next, size, "\nreclaim =\n");
456 for (qh = ehci->reclaim; size > 0 && qh; qh = qh->reclaim)
457 qh_lines (ehci, qh, &next, &size);
459 spin_unlock_irqrestore (&ehci->lock, flags);
463 static CLASS_DEVICE_ATTR (async, S_IRUGO, show_async, NULL);
465 #define DBG_SCHED_LIMIT 64
468 show_periodic (struct class_device *class_dev, char *buf)
472 struct ehci_hcd *ehci;
474 union ehci_shadow p, *seen;
475 unsigned temp, size, seen_count;
479 if (!(seen = kmalloc (DBG_SCHED_LIMIT * sizeof *seen, SLAB_ATOMIC)))
483 bus = to_usb_bus(class_dev);
485 ehci = hcd_to_ehci (hcd);
489 temp = scnprintf (next, size, "size = %d\n", ehci->periodic_size);
493 /* dump a snapshot of the periodic schedule.
494 * iso changes, interrupt usually doesn't.
496 spin_lock_irqsave (&ehci->lock, flags);
497 for (i = 0; i < ehci->periodic_size; i++) {
498 p = ehci->pshadow [i];
501 tag = Q_NEXT_TYPE (ehci->periodic [i]);
503 temp = scnprintf (next, size, "%4d: ", i);
510 temp = scnprintf (next, size, " qh%d-%04x/%p",
512 le32_to_cpup (&p.qh->hw_info2)
518 /* don't repeat what follows this qh */
519 for (temp = 0; temp < seen_count; temp++) {
520 if (seen [temp].ptr != p.ptr)
522 if (p.qh->qh_next.ptr)
523 temp = scnprintf (next, size,
528 /* show more info the first time around */
529 if (temp == seen_count && p.ptr) {
530 u32 scratch = cpu_to_le32p (
532 struct ehci_qtd *qtd;
535 /* count tds, get ep direction */
537 list_for_each_entry (qtd,
541 switch (0x03 & (le32_to_cpu (
542 qtd->hw_token) >> 8)) {
543 case 0: type = "out"; continue;
544 case 1: type = "in"; continue;
548 temp = scnprintf (next, size,
551 speed_char (scratch),
553 (scratch >> 8) & 0x000f, type,
554 p.qh->usecs, p.qh->c_usecs,
556 0x7ff & (scratch >> 16));
558 if (seen_count < DBG_SCHED_LIMIT)
559 seen [seen_count++].qh = p.qh;
563 tag = Q_NEXT_TYPE (p.qh->hw_next);
568 temp = scnprintf (next, size,
569 " fstn-%8x/%p", p.fstn->hw_prev,
571 tag = Q_NEXT_TYPE (p.fstn->hw_next);
572 p = p.fstn->fstn_next;
575 temp = scnprintf (next, size,
577 tag = Q_NEXT_TYPE (p.itd->hw_next);
581 temp = scnprintf (next, size,
583 p.sitd->stream->interval,
584 le32_to_cpup (&p.sitd->hw_uframe)
587 tag = Q_NEXT_TYPE (p.sitd->hw_next);
588 p = p.sitd->sitd_next;
595 temp = scnprintf (next, size, "\n");
599 spin_unlock_irqrestore (&ehci->lock, flags);
602 return PAGE_SIZE - size;
604 static CLASS_DEVICE_ATTR (periodic, S_IRUGO, show_periodic, NULL);
606 #undef DBG_SCHED_LIMIT
609 show_registers (struct class_device *class_dev, char *buf)
613 struct ehci_hcd *ehci;
615 unsigned temp, size, i;
616 char *next, scratch [80];
617 static char fmt [] = "%*s\n";
618 static char label [] = "";
620 bus = to_usb_bus(class_dev);
622 ehci = hcd_to_ehci (hcd);
626 spin_lock_irqsave (&ehci->lock, flags);
628 /* Capability Registers */
629 i = HC_VERSION(readl (&ehci->caps->hc_capbase));
630 temp = scnprintf (next, size,
632 "EHCI %x.%02x, hcd state %d (driver " DRIVER_VERSION ")\n",
633 hcd->self.controller->bus->name,
634 hcd->self.controller->bus_id,
635 i >> 8, i & 0x0ff, ehci->hcd.state);
639 // FIXME interpret both types of params
640 i = readl (&ehci->caps->hcs_params);
641 temp = scnprintf (next, size, "structural params 0x%08x\n", i);
645 i = readl (&ehci->caps->hcc_params);
646 temp = scnprintf (next, size, "capability params 0x%08x\n", i);
650 /* Operational Registers */
651 temp = dbg_status_buf (scratch, sizeof scratch, label,
652 readl (&ehci->regs->status));
653 temp = scnprintf (next, size, fmt, temp, scratch);
657 temp = dbg_command_buf (scratch, sizeof scratch, label,
658 readl (&ehci->regs->command));
659 temp = scnprintf (next, size, fmt, temp, scratch);
663 temp = dbg_intr_buf (scratch, sizeof scratch, label,
664 readl (&ehci->regs->intr_enable));
665 temp = scnprintf (next, size, fmt, temp, scratch);
669 temp = scnprintf (next, size, "uframe %04x\n",
670 readl (&ehci->regs->frame_index));
674 for (i = 0; i < HCS_N_PORTS (ehci->hcs_params); i++) {
675 temp = dbg_port_buf (scratch, sizeof scratch, label, i,
676 readl (&ehci->regs->port_status [i]));
677 temp = scnprintf (next, size, fmt, temp, scratch);
683 temp = scnprintf (next, size, "reclaim qh %p%s\n",
685 ehci->reclaim_ready ? " ready" : "");
691 temp = scnprintf (next, size,
692 "irq normal %ld err %ld reclaim %ld (lost %ld)\n",
693 ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim,
694 ehci->stats.lost_iaa);
698 temp = scnprintf (next, size, "complete %ld unlink %ld\n",
699 ehci->stats.complete, ehci->stats.unlink);
704 spin_unlock_irqrestore (&ehci->lock, flags);
706 return PAGE_SIZE - size;
708 static CLASS_DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL);
710 static inline void create_debug_files (struct ehci_hcd *bus)
712 class_device_create_file(&bus->hcd.self.class_dev, &class_device_attr_async);
713 class_device_create_file(&bus->hcd.self.class_dev, &class_device_attr_periodic);
714 class_device_create_file(&bus->hcd.self.class_dev, &class_device_attr_registers);
717 static inline void remove_debug_files (struct ehci_hcd *bus)
719 class_device_remove_file(&bus->hcd.self.class_dev, &class_device_attr_async);
720 class_device_remove_file(&bus->hcd.self.class_dev, &class_device_attr_periodic);
721 class_device_remove_file(&bus->hcd.self.class_dev, &class_device_attr_registers);
724 #endif /* STUB_DEBUG_FILES */