patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / usb / host / ehci-dbg.c
1 /*
2  * Copyright (c) 2001-2002 by David Brownell
3  * 
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.
8  *
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
12  * for more details.
13  *
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.
17  */
18
19 /* this file is part of ehci-hcd.c */
20
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 )
29
30 #ifdef EHCI_VERBOSE_DEBUG
31 #       define vdbg dbg
32 #       define ehci_vdbg ehci_dbg
33 #else
34 #       define vdbg(fmt,args...) do { } while (0)
35 #       define ehci_vdbg(ehci, fmt, args...) do { } while (0)
36 #endif
37
38 #ifdef  DEBUG
39
40 /* check the values in the HCSPARAMS register
41  * (host controller _Structural_ parameters)
42  * see EHCI spec, Table 2-4 for each value
43  */
44 static void dbg_hcs_params (struct ehci_hcd *ehci, char *label)
45 {
46         u32     params = readl (&ehci->caps->hcs_params);
47
48         ehci_dbg (ehci,
49                 "%s hcs_params 0x%x dbg=%d%s cc=%d pcc=%d%s%s ports=%d\n",
50                 label, params,
51                 HCS_DEBUG_PORT (params),
52                 HCS_INDICATOR (params) ? " ind" : "",
53                 HCS_N_CC (params),
54                 HCS_N_PCC (params),
55                 HCS_PORTROUTED (params) ? "" : " ordered",
56                 HCS_PPC (params) ? "" : " !ppc",
57                 HCS_N_PORTS (params)
58                 );
59         /* Port routing, per EHCI 0.95 Spec, Section 2.2.5 */
60         if (HCS_PORTROUTED (params)) {
61                 int i;
62                 char buf [46], tmp [7], byte;
63
64                 buf[0] = 0;
65                 for (i = 0; i < HCS_N_PORTS (params); i++) {
66                         // FIXME MIPS won't readb() ...
67                         byte = readb (&ehci->caps->portroute[(i>>1)]);
68                         sprintf(tmp, "%d ", 
69                                 ((i & 0x1) ? ((byte)&0xf) : ((byte>>4)&0xf)));
70                         strcat(buf, tmp);
71                 }
72                 ehci_dbg (ehci, "%s portroute %s\n",
73                                 label, buf);
74         }
75 }
76 #else
77
78 static inline void dbg_hcs_params (struct ehci_hcd *ehci, char *label) {}
79
80 #endif
81
82 #ifdef  DEBUG
83
84 /* check the values in the HCCPARAMS register
85  * (host controller _Capability_ parameters)
86  * see EHCI Spec, Table 2-5 for each value
87  * */
88 static void dbg_hcc_params (struct ehci_hcd *ehci, char *label)
89 {
90         u32     params = readl (&ehci->caps->hcc_params);
91
92         if (HCC_ISOC_CACHE (params)) {
93                 ehci_dbg (ehci,
94                      "%s hcc_params %04x caching frame %s%s%s\n",
95                      label, params,
96                      HCC_PGM_FRAMELISTLEN (params) ? "256/512/1024" : "1024",
97                      HCC_CANPARK (params) ? " park" : "",
98                      HCC_64BIT_ADDR (params) ? " 64 bit addr" : "");
99         } else {
100                 ehci_dbg (ehci,
101                      "%s hcc_params %04x thresh %d uframes %s%s%s\n",
102                      label,
103                      params,
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" : "");
108         }
109 }
110 #else
111
112 static inline void dbg_hcc_params (struct ehci_hcd *ehci, char *label) {}
113
114 #endif
115
116 #ifdef  DEBUG
117
118 static void __attribute__((__unused__))
119 dbg_qtd (const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd)
120 {
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]));
126         if (qtd->hw_buf [1])
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]));
132 }
133
134 static void __attribute__((__unused__))
135 dbg_qh (const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
136 {
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,
139                 qh->hw_current);
140         dbg_qtd ("overlay", ehci, (struct ehci_qtd *) &qh->hw_qtd_next);
141 }
142
143 static void __attribute__((__unused__))
144 dbg_itd (const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd) 
145 {
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);
148         ehci_dbg (ehci,
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]));
158         ehci_dbg (ehci,
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]);
171 }
172
173 static void __attribute__((__unused__))
174 dbg_sitd (const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd) 
175 {
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);
178         ehci_dbg (ehci,
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]));
185 }
186
187 static int __attribute__((__unused__))
188 dbg_status_buf (char *buf, unsigned len, char *label, u32 status)
189 {
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" : ""
203                 );
204 }
205
206 static int __attribute__((__unused__))
207 dbg_intr_buf (char *buf, unsigned len, char *label, u32 enable)
208 {
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" : ""
218                 );
219 }
220
221 static const char *const fls_strings [] =
222     { "1024", "512", "256", "??" };
223
224 static int dbg_command_buf (char *buf, unsigned len, char *label, u32 command)
225 {
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"
239                 );
240 }
241
242 static int
243 dbg_port_buf (char *buf, unsigned len, char *label, int port, u32 status)
244 {
245         char    *sig;
246
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;
253         }
254
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" : "",
260                 sig,
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" : ""
270             );
271 }
272
273 #else
274 static inline void __attribute__((__unused__))
275 dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
276 {}
277
278 static inline int __attribute__((__unused__))
279 dbg_status_buf (char *buf, unsigned len, char *label, u32 status)
280 { return 0; }
281
282 static inline int __attribute__((__unused__))
283 dbg_command_buf (char *buf, unsigned len, char *label, u32 command)
284 { return 0; }
285
286 static inline int __attribute__((__unused__))
287 dbg_intr_buf (char *buf, unsigned len, char *label, u32 enable)
288 { return 0; }
289
290 static inline int __attribute__((__unused__))
291 dbg_port_buf (char *buf, unsigned len, char *label, int port, u32 status)
292 { return 0; }
293
294 #endif  /* DEBUG */
295
296 /* functions have the "wrong" filename when they're output... */
297 #define dbg_status(ehci, label, status) { \
298         char _buf [80]; \
299         dbg_status_buf (_buf, sizeof _buf, label, status); \
300         ehci_dbg (ehci, "%s\n", _buf); \
301 }
302
303 #define dbg_cmd(ehci, label, command) { \
304         char _buf [80]; \
305         dbg_command_buf (_buf, sizeof _buf, label, command); \
306         ehci_dbg (ehci, "%s\n", _buf); \
307 }
308
309 #define dbg_port(ehci, label, port, status) { \
310         char _buf [80]; \
311         dbg_port_buf (_buf, sizeof _buf, label, port, status); \
312         ehci_dbg (ehci, "%s\n", _buf); \
313 }
314
315 /*-------------------------------------------------------------------------*/
316
317 #ifdef STUB_DEBUG_FILES
318
319 static inline void create_debug_files (struct ehci_hcd *bus) { }
320 static inline void remove_debug_files (struct ehci_hcd *bus) { }
321
322 #else
323
324 /* troubleshooting help: expose state in driverfs */
325
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; \
332                 }; tmp; })
333
334 static inline char token_mark (u32 token)
335 {
336         token = le32_to_cpu (token);
337         if (token & QTD_STS_ACTIVE)
338                 return '*';
339         if (token & QTD_STS_HALT)
340                 return '-';
341         if (!IS_SHORT_READ (token))
342                 return ' ';
343         /* tries to advance through hw_alt_next */
344         return '/';
345 }
346
347 static void qh_lines (
348         struct ehci_hcd *ehci,
349         struct ehci_qh *qh,
350         char **nextp,
351         unsigned *sizep
352 )
353 {
354         u32                     scratch;
355         u32                     hw_curr;
356         struct list_head        *entry;
357         struct ehci_qtd         *td;
358         unsigned                temp;
359         unsigned                size = *sizep;
360         char                    *next = *nextp;
361         char                    mark;
362
363         if (qh->hw_qtd_next == EHCI_LIST_END)   /* NEC does this */
364                 mark = '@';
365         else
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 */
373         }
374         scratch = cpu_to_le32p (&qh->hw_info1);
375         hw_curr = (mark == '*') ? cpu_to_le32p (&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, cpu_to_le32p (&qh->hw_info2),
382                         cpu_to_le32p (&qh->hw_token), mark,
383                         (__constant_cpu_to_le32 (QTD_TOGGLE) & qh->hw_token)
384                                 ? "data1" : "data0",
385                         (cpu_to_le32p (&qh->hw_alt_next) >> 1) & 0x0f);
386         size -= temp;
387         next += temp;
388
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 = cpu_to_le32p (&td->hw_token);
393                 mark = ' ';
394                 if (hw_curr == td->qtd_dma)
395                         mark = '*';
396                 else if (qh->hw_qtd_next == td->qtd_dma)
397                         mark = '+';
398                 else if (QTD_LENGTH (scratch)) {
399                         if (td->hw_alt_next == ehci->async->hw_alt_next)
400                                 mark = '#';
401                         else if (td->hw_alt_next != EHCI_LIST_END)
402                                 mark = '/';
403                 }
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;
412                                  } tmp;}),
413                                 (scratch >> 16) & 0x7fff,
414                                 scratch,
415                                 td->urb);
416                 if (temp < 0)
417                         temp = 0;
418                 else if (size < temp)
419                         temp = size;
420                 size -= temp;
421                 next += temp;
422                 if (temp == size)
423                         goto done;
424         }
425
426         temp = snprintf (next, size, "\n");
427         if (temp < 0)
428                 temp = 0;
429         else if (size < temp)
430                 temp = size;
431         size -= temp;
432         next += temp;
433
434 done:
435         *sizep = size;
436         *nextp = next;
437 }
438
439 static ssize_t
440 show_async (struct class_device *class_dev, char *buf)
441 {
442         struct usb_bus          *bus;
443         struct usb_hcd          *hcd;
444         struct ehci_hcd         *ehci;
445         unsigned long           flags;
446         unsigned                temp, size;
447         char                    *next;
448         struct ehci_qh          *qh;
449
450         *buf = 0;
451
452         bus = to_usb_bus(class_dev);
453         hcd = bus->hcpriv;
454         ehci = hcd_to_ehci (hcd);
455         next = buf;
456         size = PAGE_SIZE;
457
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
461          */
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");
467                 size -= temp;
468                 next += temp;
469
470                 for (qh = ehci->reclaim; size > 0 && qh; qh = qh->reclaim)
471                         qh_lines (ehci, qh, &next, &size);
472         }
473         spin_unlock_irqrestore (&ehci->lock, flags);
474
475         return strlen (buf);
476 }
477 static CLASS_DEVICE_ATTR (async, S_IRUGO, show_async, NULL);
478
479 #define DBG_SCHED_LIMIT 64
480
481 static ssize_t
482 show_periodic (struct class_device *class_dev, char *buf)
483 {
484         struct usb_bus          *bus;
485         struct usb_hcd          *hcd;
486         struct ehci_hcd         *ehci;
487         unsigned long           flags;
488         union ehci_shadow       p, *seen;
489         unsigned                temp, size, seen_count;
490         char                    *next;
491         unsigned                i, tag;
492
493         if (!(seen = kmalloc (DBG_SCHED_LIMIT * sizeof *seen, SLAB_ATOMIC)))
494                 return 0;
495         seen_count = 0;
496
497         bus = to_usb_bus(class_dev);
498         hcd = bus->hcpriv;
499         ehci = hcd_to_ehci (hcd);
500         next = buf;
501         size = PAGE_SIZE;
502
503         temp = scnprintf (next, size, "size = %d\n", ehci->periodic_size);
504         size -= temp;
505         next += temp;
506
507         /* dump a snapshot of the periodic schedule.
508          * iso changes, interrupt usually doesn't.
509          */
510         spin_lock_irqsave (&ehci->lock, flags);
511         for (i = 0; i < ehci->periodic_size; i++) {
512                 p = ehci->pshadow [i];
513                 if (likely (!p.ptr))
514                         continue;
515                 tag = Q_NEXT_TYPE (ehci->periodic [i]);
516
517                 temp = scnprintf (next, size, "%4d: ", i);
518                 size -= temp;
519                 next += temp;
520
521                 do {
522                         switch (tag) {
523                         case Q_TYPE_QH:
524                                 temp = scnprintf (next, size, " qh%d-%04x/%p",
525                                                 p.qh->period,
526                                                 le32_to_cpup (&p.qh->hw_info2)
527                                                         /* uframe masks */
528                                                         & 0xffff,
529                                                 p.qh);
530                                 size -= temp;
531                                 next += temp;
532                                 /* don't repeat what follows this qh */
533                                 for (temp = 0; temp < seen_count; temp++) {
534                                         if (seen [temp].ptr != p.ptr)
535                                                 continue;
536                                         if (p.qh->qh_next.ptr)
537                                                 temp = scnprintf (next, size,
538                                                         " ...");
539                                         p.ptr = 0;
540                                         break;
541                                 }
542                                 /* show more info the first time around */
543                                 if (temp == seen_count && p.ptr) {
544                                         u32     scratch = cpu_to_le32p (
545                                                         &p.qh->hw_info1);
546                                         struct ehci_qtd *qtd;
547                                         char            *type = "";
548
549                                         /* count tds, get ep direction */
550                                         temp = 0;
551                                         list_for_each_entry (qtd,
552                                                         &p.qh->qtd_list,
553                                                         qtd_list) {
554                                                 temp++;
555                                                 switch (0x03 & (le32_to_cpu (
556                                                         qtd->hw_token) >> 8)) {
557                                                 case 0: type = "out"; continue;
558                                                 case 1: type = "in"; continue;
559                                                 }
560                                         }
561
562                                         temp = scnprintf (next, size,
563                                                 " (%c%d ep%d%s "
564                                                 "[%d/%d] q%d p%d)",
565                                                 speed_char (scratch),
566                                                 scratch & 0x007f,
567                                                 (scratch >> 8) & 0x000f, type,
568                                                 p.qh->usecs, p.qh->c_usecs,
569                                                 temp,
570                                                 0x7ff & (scratch >> 16));
571
572                                         if (seen_count < DBG_SCHED_LIMIT)
573                                                 seen [seen_count++].qh = p.qh;
574                                 } else
575                                         temp = 0;
576                                 if (p.qh) {
577                                         tag = Q_NEXT_TYPE (p.qh->hw_next);
578                                         p = p.qh->qh_next;
579                                 }
580                                 break;
581                         case Q_TYPE_FSTN:
582                                 temp = scnprintf (next, size,
583                                         " fstn-%8x/%p", p.fstn->hw_prev,
584                                         p.fstn);
585                                 tag = Q_NEXT_TYPE (p.fstn->hw_next);
586                                 p = p.fstn->fstn_next;
587                                 break;
588                         case Q_TYPE_ITD:
589                                 temp = scnprintf (next, size,
590                                         " itd/%p", p.itd);
591                                 tag = Q_NEXT_TYPE (p.itd->hw_next);
592                                 p = p.itd->itd_next;
593                                 break;
594                         case Q_TYPE_SITD:
595                                 temp = scnprintf (next, size,
596                                         " sitd%d-%04x/%p",
597                                         p.sitd->stream->interval,
598                                         le32_to_cpup (&p.sitd->hw_uframe)
599                                                 & 0x0000ffff,
600                                         p.sitd);
601                                 tag = Q_NEXT_TYPE (p.sitd->hw_next);
602                                 p = p.sitd->sitd_next;
603                                 break;
604                         }
605                         size -= temp;
606                         next += temp;
607                 } while (p.ptr);
608
609                 temp = scnprintf (next, size, "\n");
610                 size -= temp;
611                 next += temp;
612         }
613         spin_unlock_irqrestore (&ehci->lock, flags);
614         kfree (seen);
615
616         return PAGE_SIZE - size;
617 }
618 static CLASS_DEVICE_ATTR (periodic, S_IRUGO, show_periodic, NULL);
619
620 #undef DBG_SCHED_LIMIT
621
622 static ssize_t
623 show_registers (struct class_device *class_dev, char *buf)
624 {
625         struct usb_bus          *bus;
626         struct usb_hcd          *hcd;
627         struct ehci_hcd         *ehci;
628         unsigned long           flags;
629         unsigned                temp, size, i;
630         char                    *next, scratch [80];
631         static char             fmt [] = "%*s\n";
632         static char             label [] = "";
633
634         bus = to_usb_bus(class_dev);
635         hcd = bus->hcpriv;
636         ehci = hcd_to_ehci (hcd);
637         next = buf;
638         size = PAGE_SIZE;
639
640         spin_lock_irqsave (&ehci->lock, flags);
641
642         if (bus->controller->power.power_state) {
643                 size = scnprintf (next, size,
644                         "bus %s, device %s (driver " DRIVER_VERSION ")\n"
645                         "SUSPENDED (no register access)\n",
646                         hcd->self.controller->bus->name,
647                         hcd->self.controller->bus_id);
648                 goto done;
649         }
650
651         /* Capability Registers */
652         i = HC_VERSION(readl (&ehci->caps->hc_capbase));
653         temp = scnprintf (next, size,
654                 "bus %s, device %s (driver " DRIVER_VERSION ")\n"
655                 "EHCI %x.%02x, hcd state %d\n",
656                 hcd->self.controller->bus->name,
657                 hcd->self.controller->bus_id,
658                 i >> 8, i & 0x0ff, ehci->hcd.state);
659         size -= temp;
660         next += temp;
661
662         // FIXME interpret both types of params
663         i = readl (&ehci->caps->hcs_params);
664         temp = scnprintf (next, size, "structural params 0x%08x\n", i);
665         size -= temp;
666         next += temp;
667
668         i = readl (&ehci->caps->hcc_params);
669         temp = scnprintf (next, size, "capability params 0x%08x\n", i);
670         size -= temp;
671         next += temp;
672
673         /* Operational Registers */
674         temp = dbg_status_buf (scratch, sizeof scratch, label,
675                         readl (&ehci->regs->status));
676         temp = scnprintf (next, size, fmt, temp, scratch);
677         size -= temp;
678         next += temp;
679
680         temp = dbg_command_buf (scratch, sizeof scratch, label,
681                         readl (&ehci->regs->command));
682         temp = scnprintf (next, size, fmt, temp, scratch);
683         size -= temp;
684         next += temp;
685
686         temp = dbg_intr_buf (scratch, sizeof scratch, label,
687                         readl (&ehci->regs->intr_enable));
688         temp = scnprintf (next, size, fmt, temp, scratch);
689         size -= temp;
690         next += temp;
691
692         temp = scnprintf (next, size, "uframe %04x\n",
693                         readl (&ehci->regs->frame_index));
694         size -= temp;
695         next += temp;
696
697         for (i = 0; i < HCS_N_PORTS (ehci->hcs_params); i++) {
698                 temp = dbg_port_buf (scratch, sizeof scratch, label, i + 1,
699                                 readl (&ehci->regs->port_status [i]));
700                 temp = scnprintf (next, size, fmt, temp, scratch);
701                 size -= temp;
702                 next += temp;
703         }
704
705         if (ehci->reclaim) {
706                 temp = scnprintf (next, size, "reclaim qh %p%s\n",
707                                 ehci->reclaim,
708                                 ehci->reclaim_ready ? " ready" : "");
709                 size -= temp;
710                 next += temp;
711         }
712
713 #ifdef EHCI_STATS
714         temp = scnprintf (next, size,
715                 "irq normal %ld err %ld reclaim %ld (lost %ld)\n",
716                 ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim,
717                 ehci->stats.lost_iaa);
718         size -= temp;
719         next += temp;
720
721         temp = scnprintf (next, size, "complete %ld unlink %ld\n",
722                 ehci->stats.complete, ehci->stats.unlink);
723         size -= temp;
724         next += temp;
725 #endif
726
727 done:
728         spin_unlock_irqrestore (&ehci->lock, flags);
729
730         return PAGE_SIZE - size;
731 }
732 static CLASS_DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL);
733
734 static inline void create_debug_files (struct ehci_hcd *bus)
735 {
736         class_device_create_file(&bus->hcd.self.class_dev, &class_device_attr_async);
737         class_device_create_file(&bus->hcd.self.class_dev, &class_device_attr_periodic);
738         class_device_create_file(&bus->hcd.self.class_dev, &class_device_attr_registers);
739 }
740
741 static inline void remove_debug_files (struct ehci_hcd *bus)
742 {
743         class_device_remove_file(&bus->hcd.self.class_dev, &class_device_attr_async);
744         class_device_remove_file(&bus->hcd.self.class_dev, &class_device_attr_periodic);
745         class_device_remove_file(&bus->hcd.self.class_dev, &class_device_attr_registers);
746 }
747
748 #endif /* STUB_DEBUG_FILES */
749