ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[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 int __attribute__((__unused__))
174 dbg_status_buf (char *buf, unsigned len, char *label, u32 status)
175 {
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" : ""
189                 );
190 }
191
192 static int __attribute__((__unused__))
193 dbg_intr_buf (char *buf, unsigned len, char *label, u32 enable)
194 {
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" : ""
204                 );
205 }
206
207 static const char *const fls_strings [] =
208     { "1024", "512", "256", "??" };
209
210 static int dbg_command_buf (char *buf, unsigned len, char *label, u32 command)
211 {
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"
225                 );
226 }
227
228 static int
229 dbg_port_buf (char *buf, unsigned len, char *label, int port, u32 status)
230 {
231         char    *sig;
232
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;
239         }
240
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" : "",
246                 sig,
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" : ""
256             );
257 }
258
259 #else
260 static inline void __attribute__((__unused__))
261 dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
262 {}
263
264 static inline int __attribute__((__unused__))
265 dbg_status_buf (char *buf, unsigned len, char *label, u32 status)
266 { return 0; }
267
268 static inline int __attribute__((__unused__))
269 dbg_command_buf (char *buf, unsigned len, char *label, u32 command)
270 { return 0; }
271
272 static inline int __attribute__((__unused__))
273 dbg_intr_buf (char *buf, unsigned len, char *label, u32 enable)
274 { return 0; }
275
276 static inline int __attribute__((__unused__))
277 dbg_port_buf (char *buf, unsigned len, char *label, int port, u32 status)
278 { return 0; }
279
280 #endif  /* DEBUG */
281
282 /* functions have the "wrong" filename when they're output... */
283 #define dbg_status(ehci, label, status) { \
284         char _buf [80]; \
285         dbg_status_buf (_buf, sizeof _buf, label, status); \
286         ehci_dbg (ehci, "%s\n", _buf); \
287 }
288
289 #define dbg_cmd(ehci, label, command) { \
290         char _buf [80]; \
291         dbg_command_buf (_buf, sizeof _buf, label, command); \
292         ehci_dbg (ehci, "%s\n", _buf); \
293 }
294
295 #define dbg_port(ehci, label, port, status) { \
296         char _buf [80]; \
297         dbg_port_buf (_buf, sizeof _buf, label, port, status); \
298         ehci_dbg (ehci, "%s\n", _buf); \
299 }
300
301 /*-------------------------------------------------------------------------*/
302
303 #ifdef STUB_DEBUG_FILES
304
305 static inline void create_debug_files (struct ehci_hcd *bus) { }
306 static inline void remove_debug_files (struct ehci_hcd *bus) { }
307
308 #else
309
310 /* troubleshooting help: expose state in driverfs */
311
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; \
318                 }; tmp; })
319
320 static inline char token_mark (u32 token)
321 {
322         token = le32_to_cpu (token);
323         if (token & QTD_STS_ACTIVE)
324                 return '*';
325         if (token & QTD_STS_HALT)
326                 return '-';
327         if (!IS_SHORT_READ (token))
328                 return ' ';
329         /* tries to advance through hw_alt_next */
330         return '/';
331 }
332
333 static void qh_lines (
334         struct ehci_hcd *ehci,
335         struct ehci_qh *qh,
336         char **nextp,
337         unsigned *sizep
338 )
339 {
340         u32                     scratch;
341         u32                     hw_curr;
342         struct list_head        *entry;
343         struct ehci_qtd         *td;
344         unsigned                temp;
345         unsigned                size = *sizep;
346         char                    *next = *nextp;
347         char                    mark;
348
349         if (qh->hw_qtd_next == EHCI_LIST_END)   /* NEC does this */
350                 mark = '@';
351         else
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 */
359         }
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)
370                                 ? "data1" : "data0",
371                         (cpu_to_le32p (&qh->hw_alt_next) >> 1) & 0x0f);
372         size -= temp;
373         next += temp;
374
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);
379                 mark = ' ';
380                 if (hw_curr == td->qtd_dma)
381                         mark = '*';
382                 else if (qh->hw_qtd_next == td->qtd_dma)
383                         mark = '+';
384                 else if (QTD_LENGTH (scratch)) {
385                         if (td->hw_alt_next == ehci->async->hw_alt_next)
386                                 mark = '#';
387                         else if (td->hw_alt_next != EHCI_LIST_END)
388                                 mark = '/';
389                 }
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;
398                                  } tmp;}),
399                                 (scratch >> 16) & 0x7fff,
400                                 scratch,
401                                 td->urb);
402                 if (temp < 0)
403                         temp = 0;
404                 else if (size < temp)
405                         temp = size;
406                 size -= temp;
407                 next += temp;
408                 if (temp == size)
409                         goto done;
410         }
411
412         temp = snprintf (next, size, "\n");
413         if (temp < 0)
414                 temp = 0;
415         else if (size < temp)
416                 temp = size;
417         size -= temp;
418         next += temp;
419
420 done:
421         *sizep = size;
422         *nextp = next;
423 }
424
425 static ssize_t
426 show_async (struct class_device *class_dev, char *buf)
427 {
428         struct usb_bus          *bus;
429         struct usb_hcd          *hcd;
430         struct ehci_hcd         *ehci;
431         unsigned long           flags;
432         unsigned                temp, size;
433         char                    *next;
434         struct ehci_qh          *qh;
435
436         *buf = 0;
437
438         bus = to_usb_bus(class_dev);
439         hcd = bus->hcpriv;
440         ehci = hcd_to_ehci (hcd);
441         next = buf;
442         size = PAGE_SIZE;
443
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
447          */
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");
453                 size -= temp;
454                 next += temp;
455
456                 for (qh = ehci->reclaim; size > 0 && qh; qh = qh->reclaim)
457                         qh_lines (ehci, qh, &next, &size);
458         }
459         spin_unlock_irqrestore (&ehci->lock, flags);
460
461         return strlen (buf);
462 }
463 static CLASS_DEVICE_ATTR (async, S_IRUGO, show_async, NULL);
464
465 #define DBG_SCHED_LIMIT 64
466
467 static ssize_t
468 show_periodic (struct class_device *class_dev, char *buf)
469 {
470         struct usb_bus          *bus;
471         struct usb_hcd          *hcd;
472         struct ehci_hcd         *ehci;
473         unsigned long           flags;
474         union ehci_shadow       p, *seen;
475         unsigned                temp, size, seen_count;
476         char                    *next;
477         unsigned                i, tag;
478
479         if (!(seen = kmalloc (DBG_SCHED_LIMIT * sizeof *seen, SLAB_ATOMIC)))
480                 return 0;
481         seen_count = 0;
482
483         bus = to_usb_bus(class_dev);
484         hcd = bus->hcpriv;
485         ehci = hcd_to_ehci (hcd);
486         next = buf;
487         size = PAGE_SIZE;
488
489         temp = scnprintf (next, size, "size = %d\n", ehci->periodic_size);
490         size -= temp;
491         next += temp;
492
493         /* dump a snapshot of the periodic schedule.
494          * iso changes, interrupt usually doesn't.
495          */
496         spin_lock_irqsave (&ehci->lock, flags);
497         for (i = 0; i < ehci->periodic_size; i++) {
498                 p = ehci->pshadow [i];
499                 if (likely (!p.ptr))
500                         continue;
501                 tag = Q_NEXT_TYPE (ehci->periodic [i]);
502
503                 temp = scnprintf (next, size, "%4d: ", i);
504                 size -= temp;
505                 next += temp;
506
507                 do {
508                         switch (tag) {
509                         case Q_TYPE_QH:
510                                 temp = scnprintf (next, size, " qh%d-%04x/%p",
511                                                 p.qh->period,
512                                                 le32_to_cpup (&p.qh->hw_info2)
513                                                         /* uframe masks */
514                                                         & 0xffff,
515                                                 p.qh);
516                                 size -= temp;
517                                 next += temp;
518                                 /* don't repeat what follows this qh */
519                                 for (temp = 0; temp < seen_count; temp++) {
520                                         if (seen [temp].ptr != p.ptr)
521                                                 continue;
522                                         if (p.qh->qh_next.ptr)
523                                                 temp = scnprintf (next, size,
524                                                         " ...");
525                                         p.ptr = 0;
526                                         break;
527                                 }
528                                 /* show more info the first time around */
529                                 if (temp == seen_count && p.ptr) {
530                                         u32     scratch = cpu_to_le32p (
531                                                         &p.qh->hw_info1);
532                                         struct ehci_qtd *qtd;
533                                         char            *type = "";
534
535                                         /* count tds, get ep direction */
536                                         temp = 0;
537                                         list_for_each_entry (qtd,
538                                                         &p.qh->qtd_list,
539                                                         qtd_list) {
540                                                 temp++;
541                                                 switch (0x03 & (le32_to_cpu (
542                                                         qtd->hw_token) >> 8)) {
543                                                 case 0: type = "out"; continue;
544                                                 case 1: type = "in"; continue;
545                                                 }
546                                         }
547
548                                         temp = scnprintf (next, size,
549                                                 " (%c%d ep%d%s "
550                                                 "[%d/%d] q%d p%d)",
551                                                 speed_char (scratch),
552                                                 scratch & 0x007f,
553                                                 (scratch >> 8) & 0x000f, type,
554                                                 p.qh->usecs, p.qh->c_usecs,
555                                                 temp,
556                                                 0x7ff & (scratch >> 16));
557
558                                         if (seen_count < DBG_SCHED_LIMIT)
559                                                 seen [seen_count++].qh = p.qh;
560                                 } else
561                                         temp = 0;
562                                 if (p.qh) {
563                                         tag = Q_NEXT_TYPE (p.qh->hw_next);
564                                         p = p.qh->qh_next;
565                                 }
566                                 break;
567                         case Q_TYPE_FSTN:
568                                 temp = scnprintf (next, size,
569                                         " fstn-%8x/%p", p.fstn->hw_prev,
570                                         p.fstn);
571                                 tag = Q_NEXT_TYPE (p.fstn->hw_next);
572                                 p = p.fstn->fstn_next;
573                                 break;
574                         case Q_TYPE_ITD:
575                                 temp = scnprintf (next, size,
576                                         " itd/%p", p.itd);
577                                 tag = Q_NEXT_TYPE (p.itd->hw_next);
578                                 p = p.itd->itd_next;
579                                 break;
580                         case Q_TYPE_SITD:
581                                 temp = scnprintf (next, size,
582                                         " sitd%d-%04x/%p",
583                                         p.sitd->stream->interval,
584                                         le32_to_cpup (&p.sitd->hw_uframe)
585                                                 & 0x0000ffff,
586                                         p.sitd);
587                                 tag = Q_NEXT_TYPE (p.sitd->hw_next);
588                                 p = p.sitd->sitd_next;
589                                 break;
590                         }
591                         size -= temp;
592                         next += temp;
593                 } while (p.ptr);
594
595                 temp = scnprintf (next, size, "\n");
596                 size -= temp;
597                 next += temp;
598         }
599         spin_unlock_irqrestore (&ehci->lock, flags);
600         kfree (seen);
601
602         return PAGE_SIZE - size;
603 }
604 static CLASS_DEVICE_ATTR (periodic, S_IRUGO, show_periodic, NULL);
605
606 #undef DBG_SCHED_LIMIT
607
608 static ssize_t
609 show_registers (struct class_device *class_dev, char *buf)
610 {
611         struct usb_bus          *bus;
612         struct usb_hcd          *hcd;
613         struct ehci_hcd         *ehci;
614         unsigned long           flags;
615         unsigned                temp, size, i;
616         char                    *next, scratch [80];
617         static char             fmt [] = "%*s\n";
618         static char             label [] = "";
619
620         bus = to_usb_bus(class_dev);
621         hcd = bus->hcpriv;
622         ehci = hcd_to_ehci (hcd);
623         next = buf;
624         size = PAGE_SIZE;
625
626         spin_lock_irqsave (&ehci->lock, flags);
627
628         /* Capability Registers */
629         i = HC_VERSION(readl (&ehci->caps->hc_capbase));
630         temp = scnprintf (next, size,
631                 "bus %s device %s\n"
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);
636         size -= temp;
637         next += temp;
638
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);
642         size -= temp;
643         next += temp;
644
645         i = readl (&ehci->caps->hcc_params);
646         temp = scnprintf (next, size, "capability params 0x%08x\n", i);
647         size -= temp;
648         next += temp;
649
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);
654         size -= temp;
655         next += temp;
656
657         temp = dbg_command_buf (scratch, sizeof scratch, label,
658                         readl (&ehci->regs->command));
659         temp = scnprintf (next, size, fmt, temp, scratch);
660         size -= temp;
661         next += temp;
662
663         temp = dbg_intr_buf (scratch, sizeof scratch, label,
664                         readl (&ehci->regs->intr_enable));
665         temp = scnprintf (next, size, fmt, temp, scratch);
666         size -= temp;
667         next += temp;
668
669         temp = scnprintf (next, size, "uframe %04x\n",
670                         readl (&ehci->regs->frame_index));
671         size -= temp;
672         next += temp;
673
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);
678                 size -= temp;
679                 next += temp;
680         }
681
682         if (ehci->reclaim) {
683                 temp = scnprintf (next, size, "reclaim qh %p%s\n",
684                                 ehci->reclaim,
685                                 ehci->reclaim_ready ? " ready" : "");
686                 size -= temp;
687                 next += temp;
688         }
689
690 #ifdef EHCI_STATS
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);
695         size -= temp;
696         next += temp;
697
698         temp = scnprintf (next, size, "complete %ld unlink %ld\n",
699                 ehci->stats.complete, ehci->stats.unlink);
700         size -= temp;
701         next += temp;
702 #endif
703
704         spin_unlock_irqrestore (&ehci->lock, flags);
705
706         return PAGE_SIZE - size;
707 }
708 static CLASS_DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL);
709
710 static inline void create_debug_files (struct ehci_hcd *bus)
711 {
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);
715 }
716
717 static inline void remove_debug_files (struct ehci_hcd *bus)
718 {
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);
722 }
723
724 #endif /* STUB_DEBUG_FILES */
725