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 */
22 #define ehci_dbg(ehci, fmt, args...) \
23 printk(KERN_DEBUG "%s %s: " fmt , hcd_name , \
24 (ehci)->hcd.pdev->slot_name , ## args )
26 #define ehci_dbg(ehci, fmt, args...) do { } while (0)
29 #define ehci_err(ehci, fmt, args...) \
30 printk(KERN_ERR "%s %s: " fmt , hcd_name , \
31 (ehci)->hcd.pdev->slot_name , ## args )
32 #define ehci_info(ehci, fmt, args...) \
33 printk(KERN_INFO "%s %s: " fmt , hcd_name , \
34 (ehci)->hcd.pdev->slot_name , ## args )
35 #define ehci_warn(ehci, fmt, args...) \
36 printk(KERN_WARNING "%s %s: " fmt , hcd_name , \
37 (ehci)->hcd.pdev->slot_name , ## args )
40 #ifdef EHCI_VERBOSE_DEBUG
42 # define ehci_vdbg ehci_dbg
44 # define vdbg(fmt,args...) do { } while (0)
45 # define ehci_vdbg(ehci, fmt, args...) do { } while (0)
50 /* check the values in the HCSPARAMS register
51 * (host controller _Structural_ parameters)
52 * see EHCI spec, Table 2-4 for each value
54 static void dbg_hcs_params (struct ehci_hcd *ehci, char *label)
56 u32 params = readl (&ehci->caps->hcs_params);
59 "%s hcs_params 0x%x dbg=%d%s cc=%d pcc=%d%s%s ports=%d\n",
61 HCS_DEBUG_PORT (params),
62 HCS_INDICATOR (params) ? " ind" : "",
65 HCS_PORTROUTED (params) ? "" : " ordered",
66 HCS_PPC (params) ? "" : " !ppc",
69 /* Port routing, per EHCI 0.95 Spec, Section 2.2.5 */
70 if (HCS_PORTROUTED (params)) {
72 char buf [46], tmp [7], byte;
75 for (i = 0; i < HCS_N_PORTS (params); i++) {
76 // FIXME MIPS won't readb() ...
77 byte = readb (&ehci->caps->portroute[(i>>1)]);
79 ((i & 0x1) ? ((byte)&0xf) : ((byte>>4)&0xf)));
82 ehci_dbg (ehci, "%s portroute %s\n",
88 static inline void dbg_hcs_params (struct ehci_hcd *ehci, char *label) {}
94 /* check the values in the HCCPARAMS register
95 * (host controller _Capability_ parameters)
96 * see EHCI Spec, Table 2-5 for each value
98 static void dbg_hcc_params (struct ehci_hcd *ehci, char *label)
100 u32 params = readl (&ehci->caps->hcc_params);
102 if (HCC_ISOC_CACHE (params)) {
104 "%s hcc_params %04x caching frame %s%s%s\n",
106 HCC_PGM_FRAMELISTLEN (params) ? "256/512/1024" : "1024",
107 HCC_CANPARK (params) ? " park" : "",
108 HCC_64BIT_ADDR (params) ? " 64 bit addr" : "");
111 "%s hcc_params %04x thresh %d uframes %s%s%s\n",
114 HCC_ISOC_THRES (params),
115 HCC_PGM_FRAMELISTLEN (params) ? "256/512/1024" : "1024",
116 HCC_CANPARK (params) ? " park" : "",
117 HCC_64BIT_ADDR (params) ? " 64 bit addr" : "");
122 static inline void dbg_hcc_params (struct ehci_hcd *ehci, char *label) {}
128 static void __attribute__((__unused__))
129 dbg_qtd (const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd)
131 ehci_dbg (ehci, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd,
132 cpu_to_le32p (&qtd->hw_next),
133 cpu_to_le32p (&qtd->hw_alt_next),
134 cpu_to_le32p (&qtd->hw_token),
135 cpu_to_le32p (&qtd->hw_buf [0]));
137 ehci_dbg (ehci, " p1=%08x p2=%08x p3=%08x p4=%08x\n",
138 cpu_to_le32p (&qtd->hw_buf [1]),
139 cpu_to_le32p (&qtd->hw_buf [2]),
140 cpu_to_le32p (&qtd->hw_buf [3]),
141 cpu_to_le32p (&qtd->hw_buf [4]));
144 static void __attribute__((__unused__))
145 dbg_qh (const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
147 ehci_dbg (ehci, "%s qh %p n%08x info %x %x qtd %x\n", label,
148 qh, qh->hw_next, qh->hw_info1, qh->hw_info2,
150 dbg_qtd ("overlay", ehci, (struct ehci_qtd *) &qh->hw_qtd_next);
153 static void __attribute__((__unused__))
154 dbg_itd (const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd)
156 ehci_dbg (ehci, "%s [%d] itd %p, next %08x, urb %p\n",
157 label, itd->frame, itd, le32_to_cpu(itd->hw_next), itd->urb);
159 " trans: %08x %08x %08x %08x %08x %08x %08x %08x\n",
160 le32_to_cpu(itd->hw_transaction[0]),
161 le32_to_cpu(itd->hw_transaction[1]),
162 le32_to_cpu(itd->hw_transaction[2]),
163 le32_to_cpu(itd->hw_transaction[3]),
164 le32_to_cpu(itd->hw_transaction[4]),
165 le32_to_cpu(itd->hw_transaction[5]),
166 le32_to_cpu(itd->hw_transaction[6]),
167 le32_to_cpu(itd->hw_transaction[7]));
169 " buf: %08x %08x %08x %08x %08x %08x %08x\n",
170 le32_to_cpu(itd->hw_bufp[0]),
171 le32_to_cpu(itd->hw_bufp[1]),
172 le32_to_cpu(itd->hw_bufp[2]),
173 le32_to_cpu(itd->hw_bufp[3]),
174 le32_to_cpu(itd->hw_bufp[4]),
175 le32_to_cpu(itd->hw_bufp[5]),
176 le32_to_cpu(itd->hw_bufp[6]));
177 ehci_dbg (ehci, " index: %d %d %d %d %d %d %d %d\n",
178 itd->index[0], itd->index[1], itd->index[2],
179 itd->index[3], itd->index[4], itd->index[5],
180 itd->index[6], itd->index[7]);
183 static int __attribute__((__unused__))
184 dbg_status_buf (char *buf, unsigned len, char *label, u32 status)
186 return snprintf (buf, len,
187 "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s",
188 label, label [0] ? " " : "", status,
189 (status & STS_ASS) ? " Async" : "",
190 (status & STS_PSS) ? " Periodic" : "",
191 (status & STS_RECL) ? " Recl" : "",
192 (status & STS_HALT) ? " Halt" : "",
193 (status & STS_IAA) ? " IAA" : "",
194 (status & STS_FATAL) ? " FATAL" : "",
195 (status & STS_FLR) ? " FLR" : "",
196 (status & STS_PCD) ? " PCD" : "",
197 (status & STS_ERR) ? " ERR" : "",
198 (status & STS_INT) ? " INT" : ""
202 static int __attribute__((__unused__))
203 dbg_intr_buf (char *buf, unsigned len, char *label, u32 enable)
205 return snprintf (buf, len,
206 "%s%sintrenable %02x%s%s%s%s%s%s",
207 label, label [0] ? " " : "", enable,
208 (enable & STS_IAA) ? " IAA" : "",
209 (enable & STS_FATAL) ? " FATAL" : "",
210 (enable & STS_FLR) ? " FLR" : "",
211 (enable & STS_PCD) ? " PCD" : "",
212 (enable & STS_ERR) ? " ERR" : "",
213 (enable & STS_INT) ? " INT" : ""
217 static const char *const fls_strings [] =
218 { "1024", "512", "256", "??" };
220 static int dbg_command_buf (char *buf, unsigned len, char *label, u32 command)
222 return snprintf (buf, len,
223 "%s%scommand %06x %s=%d ithresh=%d%s%s%s%s period=%s%s %s",
224 label, label [0] ? " " : "", command,
225 (command & CMD_PARK) ? "park" : "(park)",
226 CMD_PARK_CNT (command),
227 (command >> 16) & 0x3f,
228 (command & CMD_LRESET) ? " LReset" : "",
229 (command & CMD_IAAD) ? " IAAD" : "",
230 (command & CMD_ASE) ? " Async" : "",
231 (command & CMD_PSE) ? " Periodic" : "",
232 fls_strings [(command >> 2) & 0x3],
233 (command & CMD_RESET) ? " Reset" : "",
234 (command & CMD_RUN) ? "RUN" : "HALT"
239 dbg_port_buf (char *buf, unsigned len, char *label, int port, u32 status)
243 /* signaling state */
244 switch (status & (3 << 10)) {
245 case 0 << 10: sig = "se0"; break;
246 case 1 << 10: sig = "k"; break; /* low speed */
247 case 2 << 10: sig = "j"; break;
248 default: sig = "?"; break;
251 return snprintf (buf, len,
252 "%s%sport %d status %06x%s%s sig=%s %s%s%s%s%s%s%s%s%s",
253 label, label [0] ? " " : "", port, status,
254 (status & PORT_POWER) ? " POWER" : "",
255 (status & PORT_OWNER) ? " OWNER" : "",
257 (status & PORT_RESET) ? " RESET" : "",
258 (status & PORT_SUSPEND) ? " SUSPEND" : "",
259 (status & PORT_RESUME) ? " RESUME" : "",
260 (status & PORT_OCC) ? " OCC" : "",
261 (status & PORT_OC) ? " OC" : "",
262 (status & PORT_PEC) ? " PEC" : "",
263 (status & PORT_PE) ? " PE" : "",
264 (status & PORT_CSC) ? " CSC" : "",
265 (status & PORT_CONNECT) ? " CONNECT" : ""
270 static inline void __attribute__((__unused__))
271 dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
274 static inline int __attribute__((__unused__))
275 dbg_status_buf (char *buf, unsigned len, char *label, u32 status)
278 static inline int __attribute__((__unused__))
279 dbg_command_buf (char *buf, unsigned len, char *label, u32 command)
282 static inline int __attribute__((__unused__))
283 dbg_intr_buf (char *buf, unsigned len, char *label, u32 enable)
286 static inline int __attribute__((__unused__))
287 dbg_port_buf (char *buf, unsigned len, char *label, int port, u32 status)
292 /* functions have the "wrong" filename when they're output... */
293 #define dbg_status(ehci, label, status) { \
295 dbg_status_buf (_buf, sizeof _buf, label, status); \
296 ehci_dbg (ehci, "%s\n", _buf); \
299 #define dbg_cmd(ehci, label, command) { \
301 dbg_command_buf (_buf, sizeof _buf, label, command); \
302 ehci_dbg (ehci, "%s\n", _buf); \
305 #define dbg_port(ehci, label, port, status) { \
307 dbg_port_buf (_buf, sizeof _buf, label, port, status); \
308 ehci_dbg (ehci, "%s\n", _buf); \
311 /*-------------------------------------------------------------------------*/
313 #ifdef STUB_DEBUG_FILES
315 static inline void create_debug_files (struct ehci_hcd *bus) { }
316 static inline void remove_debug_files (struct ehci_hcd *bus) { }
320 /* troubleshooting help: expose state in driverfs */
322 #define speed_char(info1) ({ char tmp; \
323 switch (info1 & (3 << 12)) { \
324 case 0 << 12: tmp = 'f'; break; \
325 case 1 << 12: tmp = 'l'; break; \
326 case 2 << 12: tmp = 'h'; break; \
327 default: tmp = '?'; break; \
330 static inline char token_mark (u32 token)
332 token = le32_to_cpu (token);
333 if (token & QTD_STS_ACTIVE)
335 if (token & QTD_STS_HALT)
337 if (!IS_SHORT_READ (token))
339 /* tries to advance through hw_alt_next */
343 static void qh_lines (
344 struct ehci_hcd *ehci,
352 struct list_head *entry;
355 unsigned size = *sizep;
359 if (qh->hw_qtd_next == EHCI_LIST_END) /* NEC does this */
362 mark = token_mark (qh->hw_token);
363 if (mark == '/') { /* qh_alt_next controls qh advance? */
364 if ((qh->hw_alt_next & QTD_MASK) == ehci->async->hw_alt_next)
365 mark = '#'; /* blocked */
366 else if (qh->hw_alt_next == EHCI_LIST_END)
367 mark = '.'; /* use hw_qtd_next */
368 /* else alt_next points to some other qtd */
370 scratch = cpu_to_le32p (&qh->hw_info1);
371 hw_curr = (mark == '*') ? cpu_to_le32p (&qh->hw_current) : 0;
372 temp = snprintf (next, size,
373 "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)",
374 qh, scratch & 0x007f,
375 speed_char (scratch),
376 (scratch >> 8) & 0x000f,
377 scratch, cpu_to_le32p (&qh->hw_info2),
378 cpu_to_le32p (&qh->hw_token), mark,
379 (__constant_cpu_to_le32 (QTD_TOGGLE) & qh->hw_token)
381 (cpu_to_le32p (&qh->hw_alt_next) >> 1) & 0x0f);
385 /* hc may be modifying the list as we read it ... */
386 list_for_each (entry, &qh->qtd_list) {
387 td = list_entry (entry, struct ehci_qtd, qtd_list);
388 scratch = cpu_to_le32p (&td->hw_token);
390 if (hw_curr == td->qtd_dma)
392 else if (qh->hw_qtd_next == td->qtd_dma)
394 else if (QTD_LENGTH (scratch)) {
395 if (td->hw_alt_next == ehci->async->hw_alt_next)
397 else if (td->hw_alt_next != EHCI_LIST_END)
400 temp = snprintf (next, size,
401 "\n\t%p%c%s len=%d %08x urb %p",
402 td, mark, ({ char *tmp;
403 switch ((scratch>>8)&0x03) {
404 case 0: tmp = "out"; break;
405 case 1: tmp = "in"; break;
406 case 2: tmp = "setup"; break;
407 default: tmp = "?"; break;
409 (scratch >> 16) & 0x7fff,
414 else if (size < temp)
422 temp = snprintf (next, size, "\n");
425 else if (size < temp)
436 show_async (struct device *dev, char *buf)
438 struct pci_dev *pdev;
439 struct ehci_hcd *ehci;
447 pdev = container_of (dev, struct pci_dev, dev);
448 ehci = container_of (pci_get_drvdata (pdev), struct ehci_hcd, hcd);
452 /* dumps a snapshot of the async schedule.
453 * usually empty except for long-term bulk reads, or head.
454 * one QH per line, and TDs we know about
456 spin_lock_irqsave (&ehci->lock, flags);
457 for (qh = ehci->async->qh_next.qh; size > 0 && qh; qh = qh->qh_next.qh)
458 qh_lines (ehci, qh, &next, &size);
459 if (ehci->reclaim && size > 0) {
460 temp = snprintf (next, size, "\nreclaim =\n");
464 for (qh = ehci->reclaim; size > 0 && qh; qh = qh->reclaim)
465 qh_lines (ehci, qh, &next, &size);
467 spin_unlock_irqrestore (&ehci->lock, flags);
471 static DEVICE_ATTR (async, S_IRUGO, show_async, NULL);
473 #define DBG_SCHED_LIMIT 64
476 show_periodic (struct device *dev, char *buf)
478 struct pci_dev *pdev;
479 struct ehci_hcd *ehci;
481 union ehci_shadow p, *seen;
482 unsigned temp, size, seen_count;
486 if (!(seen = kmalloc (DBG_SCHED_LIMIT * sizeof *seen, SLAB_ATOMIC)))
490 pdev = container_of (dev, struct pci_dev, dev);
491 ehci = container_of (pci_get_drvdata (pdev), struct ehci_hcd, hcd);
495 temp = snprintf (next, size, "size = %d\n", ehci->periodic_size);
499 /* dump a snapshot of the periodic schedule.
500 * iso changes, interrupt usually doesn't.
502 spin_lock_irqsave (&ehci->lock, flags);
503 for (i = 0; i < ehci->periodic_size; i++) {
504 p = ehci->pshadow [i];
507 tag = Q_NEXT_TYPE (ehci->periodic [i]);
509 temp = snprintf (next, size, "%4d: ", i);
516 temp = snprintf (next, size, " qh%d/%p",
520 for (temp = 0; temp < seen_count; temp++) {
521 if (seen [temp].ptr == p.ptr)
524 /* show more info the first time around */
525 if (temp == seen_count && p.ptr) {
526 u32 scratch = cpu_to_le32p (
529 temp = snprintf (next, size,
530 " (%cs dev%d ep%d [%d/%d] %d)",
531 speed_char (scratch),
533 (scratch >> 8) & 0x000f,
534 p.qh->usecs, p.qh->c_usecs,
535 0x7ff & (scratch >> 16));
537 /* FIXME TD info too */
539 if (seen_count < DBG_SCHED_LIMIT)
540 seen [seen_count++].qh = p.qh;
544 tag = Q_NEXT_TYPE (p.qh->hw_next);
549 temp = snprintf (next, size,
550 " fstn-%8x/%p", p.fstn->hw_prev,
552 tag = Q_NEXT_TYPE (p.fstn->hw_next);
553 p = p.fstn->fstn_next;
556 temp = snprintf (next, size,
558 tag = Q_NEXT_TYPE (p.itd->hw_next);
562 temp = snprintf (next, size,
564 tag = Q_NEXT_TYPE (p.sitd->hw_next);
565 p = p.sitd->sitd_next;
572 temp = snprintf (next, size, "\n");
576 spin_unlock_irqrestore (&ehci->lock, flags);
579 return PAGE_SIZE - size;
581 static DEVICE_ATTR (periodic, S_IRUGO, show_periodic, NULL);
583 #undef DBG_SCHED_LIMIT
586 show_registers (struct device *dev, char *buf)
588 struct pci_dev *pdev;
589 struct ehci_hcd *ehci;
591 unsigned temp, size, i;
592 char *next, scratch [80];
593 static char fmt [] = "%*s\n";
594 static char label [] = "";
596 pdev = container_of (dev, struct pci_dev, dev);
597 ehci = container_of (pci_get_drvdata (pdev), struct ehci_hcd, hcd);
602 spin_lock_irqsave (&ehci->lock, flags);
604 /* Capability Registers */
605 i = HC_VERSION(readl (&ehci->caps->hc_capbase));
606 temp = snprintf (next, size,
607 "%s\nEHCI %x.%02x, hcd state %d (driver " DRIVER_VERSION ")\n",
609 i >> 8, i & 0x0ff, ehci->hcd.state);
613 // FIXME interpret both types of params
614 i = readl (&ehci->caps->hcs_params);
615 temp = snprintf (next, size, "structural params 0x%08x\n", i);
619 i = readl (&ehci->caps->hcc_params);
620 temp = snprintf (next, size, "capability params 0x%08x\n", i);
624 /* Operational Registers */
625 temp = dbg_status_buf (scratch, sizeof scratch, label,
626 readl (&ehci->regs->status));
627 temp = snprintf (next, size, fmt, temp, scratch);
631 temp = dbg_command_buf (scratch, sizeof scratch, label,
632 readl (&ehci->regs->command));
633 temp = snprintf (next, size, fmt, temp, scratch);
637 temp = dbg_intr_buf (scratch, sizeof scratch, label,
638 readl (&ehci->regs->intr_enable));
639 temp = snprintf (next, size, fmt, temp, scratch);
643 temp = snprintf (next, size, "uframe %04x\n",
644 readl (&ehci->regs->frame_index));
648 for (i = 0; i < HCS_N_PORTS (ehci->hcs_params); i++) {
649 temp = dbg_port_buf (scratch, sizeof scratch, label, i,
650 readl (&ehci->regs->port_status [i]));
651 temp = snprintf (next, size, fmt, temp, scratch);
657 temp = snprintf (next, size, "reclaim qh %p%s\n",
659 ehci->reclaim_ready ? " ready" : "");
665 temp = snprintf (next, size,
666 "irq normal %ld err %ld reclaim %ld (lost %ld)\n",
667 ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim,
668 ehci->stats.lost_iaa);
672 temp = snprintf (next, size, "complete %ld unlink %ld\n",
673 ehci->stats.complete, ehci->stats.unlink);
678 spin_unlock_irqrestore (&ehci->lock, flags);
680 return PAGE_SIZE - size;
682 static DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL);
684 static inline void create_debug_files (struct ehci_hcd *bus)
686 device_create_file (&bus->hcd.pdev->dev, &dev_attr_async);
687 device_create_file (&bus->hcd.pdev->dev, &dev_attr_periodic);
688 device_create_file (&bus->hcd.pdev->dev, &dev_attr_registers);
691 static inline void remove_debug_files (struct ehci_hcd *bus)
693 device_remove_file (&bus->hcd.pdev->dev, &dev_attr_async);
694 device_remove_file (&bus->hcd.pdev->dev, &dev_attr_periodic);
695 device_remove_file (&bus->hcd.pdev->dev, &dev_attr_registers);
698 #endif /* STUB_DEBUG_FILES */