[PATCH] janitor: mark __init/__exit static drivers/net/ppp_deflate
[linux-2.6/history.git] / drivers / usb / host / uhci-debug.c
bloba0721d06059eb48d6bc61cd006348f3190f0b076
1 /*
2 * UHCI-specific debugging code. Invaluable when something
3 * goes wrong, but don't get in my face.
5 * Kernel visible pointers are surrounded in []'s and bus
6 * visible pointers are surrounded in ()'s
8 * (C) Copyright 1999 Linus Torvalds
9 * (C) Copyright 1999-2001 Johannes Erdfelt
12 #include <linux/config.h>
13 #include <linux/kernel.h>
14 #include <linux/proc_fs.h>
15 #include <linux/smp_lock.h>
16 #include <asm/io.h>
18 #include "uhci-hcd.h"
20 /* Handle REALLY large printk's so we don't overflow buffers */
21 static inline void lprintk(char *buf)
23 char *p;
25 /* Just write one line at a time */
26 while (buf) {
27 p = strchr(buf, '\n');
28 if (p)
29 *p = 0;
30 printk(KERN_DEBUG "%s\n", buf);
31 buf = p;
32 if (buf)
33 buf++;
37 static inline int uhci_is_skeleton_qh(struct uhci_hcd *uhci, struct uhci_qh *qh)
39 int i;
41 for (i = 0; i < UHCI_NUM_SKELQH; i++)
42 if (qh == uhci->skelqh[i])
43 return 1;
45 return 0;
48 static int uhci_show_td(struct uhci_td *td, char *buf, int len, int space)
50 char *out = buf;
51 char *spid;
52 u32 status, token;
54 /* Try to make sure there's enough memory */
55 if (len < 160)
56 return 0;
58 status = td_status(td);
59 out += sprintf(out, "%*s[%p] link (%08x) ", space, "", td, le32_to_cpu(td->link));
60 out += sprintf(out, "e%d %s%s%s%s%s%s%s%s%s%sLength=%x ",
61 ((status >> 27) & 3),
62 (status & TD_CTRL_SPD) ? "SPD " : "",
63 (status & TD_CTRL_LS) ? "LS " : "",
64 (status & TD_CTRL_IOC) ? "IOC " : "",
65 (status & TD_CTRL_ACTIVE) ? "Active " : "",
66 (status & TD_CTRL_STALLED) ? "Stalled " : "",
67 (status & TD_CTRL_DBUFERR) ? "DataBufErr " : "",
68 (status & TD_CTRL_BABBLE) ? "Babble " : "",
69 (status & TD_CTRL_NAK) ? "NAK " : "",
70 (status & TD_CTRL_CRCTIMEO) ? "CRC/Timeo " : "",
71 (status & TD_CTRL_BITSTUFF) ? "BitStuff " : "",
72 status & 0x7ff);
74 token = td_token(td);
75 switch (uhci_packetid(token)) {
76 case USB_PID_SETUP:
77 spid = "SETUP";
78 break;
79 case USB_PID_OUT:
80 spid = "OUT";
81 break;
82 case USB_PID_IN:
83 spid = "IN";
84 break;
85 default:
86 spid = "?";
87 break;
90 out += sprintf(out, "MaxLen=%x DT%d EndPt=%x Dev=%x, PID=%x(%s) ",
91 token >> 21,
92 ((token >> 19) & 1),
93 (token >> 15) & 15,
94 (token >> 8) & 127,
95 (token & 0xff),
96 spid);
97 out += sprintf(out, "(buf=%08x)\n", le32_to_cpu(td->buffer));
99 return out - buf;
102 static int uhci_show_qh(struct uhci_qh *qh, char *buf, int len, int space)
104 char *out = buf;
105 struct urb_priv *urbp;
106 struct list_head *head, *tmp;
107 struct uhci_td *td;
108 int i = 0, checked = 0, prevactive = 0;
110 /* Try to make sure there's enough memory */
111 if (len < 80 * 6)
112 return 0;
114 out += sprintf(out, "%*s[%p] link (%08x) element (%08x)\n", space, "",
115 qh, le32_to_cpu(qh->link), le32_to_cpu(qh->element));
117 if (qh->element & UHCI_PTR_QH)
118 out += sprintf(out, "%*s Element points to QH (bug?)\n", space, "");
120 if (qh->element & UHCI_PTR_DEPTH)
121 out += sprintf(out, "%*s Depth traverse\n", space, "");
123 if (qh->element & cpu_to_le32(8))
124 out += sprintf(out, "%*s Bit 3 set (bug?)\n", space, "");
126 if (!(qh->element & ~(UHCI_PTR_QH | UHCI_PTR_DEPTH)))
127 out += sprintf(out, "%*s Element is NULL (bug?)\n", space, "");
129 if (!qh->urbp) {
130 out += sprintf(out, "%*s urbp == NULL\n", space, "");
131 goto out;
134 urbp = qh->urbp;
136 head = &urbp->td_list;
137 tmp = head->next;
139 td = list_entry(tmp, struct uhci_td, list);
141 if (cpu_to_le32(td->dma_handle) != (qh->element & ~UHCI_PTR_BITS))
142 out += sprintf(out, "%*s Element != First TD\n", space, "");
144 while (tmp != head) {
145 struct uhci_td *td = list_entry(tmp, struct uhci_td, list);
147 tmp = tmp->next;
149 out += sprintf(out, "%*s%d: ", space + 2, "", i++);
150 out += uhci_show_td(td, out, len - (out - buf), 0);
152 if (i > 10 && !checked && prevactive && tmp != head &&
153 debug <= 2) {
154 struct list_head *ntmp = tmp;
155 struct uhci_td *ntd = td;
156 int active = 1, ni = i;
158 checked = 1;
160 while (ntmp != head && ntmp->next != head && active) {
161 ntd = list_entry(ntmp, struct uhci_td, list);
163 ntmp = ntmp->next;
165 active = td_status(ntd) & TD_CTRL_ACTIVE;
167 ni++;
170 if (active && ni > i) {
171 out += sprintf(out, "%*s[skipped %d active TD's]\n", space, "", ni - i);
172 tmp = ntmp;
173 td = ntd;
174 i = ni;
178 prevactive = td_status(td) & TD_CTRL_ACTIVE;
181 if (list_empty(&urbp->queue_list) || urbp->queued)
182 goto out;
184 out += sprintf(out, "%*sQueued QH's:\n", -space, "--");
186 head = &urbp->queue_list;
187 tmp = head->next;
189 while (tmp != head) {
190 struct urb_priv *nurbp = list_entry(tmp, struct urb_priv,
191 queue_list);
192 tmp = tmp->next;
194 out += uhci_show_qh(nurbp->qh, out, len - (out - buf), space);
197 out:
198 return out - buf;
201 #define show_frame_num() \
202 if (!shown) { \
203 shown = 1; \
204 out += sprintf(out, "- Frame %d\n", i); \
207 #ifdef CONFIG_PROC_FS
208 static const char *qh_names[] = {
209 "skel_int128_qh", "skel_int64_qh",
210 "skel_int32_qh", "skel_int16_qh",
211 "skel_int8_qh", "skel_int4_qh",
212 "skel_int2_qh", "skel_int1_qh",
213 "skel_ls_control_qh", "skel_fs_control_qh",
214 "skel_bulk_qh", "skel_term_qh"
217 #define show_qh_name() \
218 if (!shown) { \
219 shown = 1; \
220 out += sprintf(out, "- %s\n", qh_names[i]); \
223 static int uhci_show_sc(int port, unsigned short status, char *buf, int len)
225 char *out = buf;
227 /* Try to make sure there's enough memory */
228 if (len < 160)
229 return 0;
231 out += sprintf(out, " stat%d = %04x %s%s%s%s%s%s%s%s%s%s\n",
232 port,
233 status,
234 (status & USBPORTSC_SUSP) ? " Suspend" : "",
235 (status & USBPORTSC_OCC) ? " OverCurrentChange" : "",
236 (status & USBPORTSC_OC) ? " OverCurrent" : "",
237 (status & USBPORTSC_PR) ? " Reset" : "",
238 (status & USBPORTSC_LSDA) ? " LowSpeed" : "",
239 (status & USBPORTSC_RD) ? " ResumeDetect" : "",
240 (status & USBPORTSC_PEC) ? " EnableChange" : "",
241 (status & USBPORTSC_PE) ? " Enabled" : "",
242 (status & USBPORTSC_CSC) ? " ConnectChange" : "",
243 (status & USBPORTSC_CCS) ? " Connected" : "");
245 return out - buf;
248 static int uhci_show_status(struct uhci_hcd *uhci, char *buf, int len)
250 char *out = buf;
251 unsigned long io_addr = uhci->io_addr;
252 unsigned short usbcmd, usbstat, usbint, usbfrnum;
253 unsigned int flbaseadd;
254 unsigned char sof;
255 unsigned short portsc1, portsc2;
257 /* Try to make sure there's enough memory */
258 if (len < 80 * 6)
259 return 0;
261 usbcmd = inw(io_addr + 0);
262 usbstat = inw(io_addr + 2);
263 usbint = inw(io_addr + 4);
264 usbfrnum = inw(io_addr + 6);
265 flbaseadd = inl(io_addr + 8);
266 sof = inb(io_addr + 12);
267 portsc1 = inw(io_addr + 16);
268 portsc2 = inw(io_addr + 18);
270 out += sprintf(out, " usbcmd = %04x %s%s%s%s%s%s%s%s\n",
271 usbcmd,
272 (usbcmd & USBCMD_MAXP) ? "Maxp64 " : "Maxp32 ",
273 (usbcmd & USBCMD_CF) ? "CF " : "",
274 (usbcmd & USBCMD_SWDBG) ? "SWDBG " : "",
275 (usbcmd & USBCMD_FGR) ? "FGR " : "",
276 (usbcmd & USBCMD_EGSM) ? "EGSM " : "",
277 (usbcmd & USBCMD_GRESET) ? "GRESET " : "",
278 (usbcmd & USBCMD_HCRESET) ? "HCRESET " : "",
279 (usbcmd & USBCMD_RS) ? "RS " : "");
281 out += sprintf(out, " usbstat = %04x %s%s%s%s%s%s\n",
282 usbstat,
283 (usbstat & USBSTS_HCH) ? "HCHalted " : "",
284 (usbstat & USBSTS_HCPE) ? "HostControllerProcessError " : "",
285 (usbstat & USBSTS_HSE) ? "HostSystemError " : "",
286 (usbstat & USBSTS_RD) ? "ResumeDetect " : "",
287 (usbstat & USBSTS_ERROR) ? "USBError " : "",
288 (usbstat & USBSTS_USBINT) ? "USBINT " : "");
290 out += sprintf(out, " usbint = %04x\n", usbint);
291 out += sprintf(out, " usbfrnum = (%d)%03x\n", (usbfrnum >> 10) & 1,
292 0xfff & (4*(unsigned int)usbfrnum));
293 out += sprintf(out, " flbaseadd = %08x\n", flbaseadd);
294 out += sprintf(out, " sof = %02x\n", sof);
295 out += uhci_show_sc(1, portsc1, out, len - (out - buf));
296 out += uhci_show_sc(2, portsc2, out, len - (out - buf));
298 return out - buf;
301 static int uhci_show_urbp(struct uhci_hcd *uhci, struct urb_priv *urbp, char *buf, int len)
303 struct list_head *tmp;
304 char *out = buf;
305 int count = 0;
307 if (len < 200)
308 return 0;
310 out += sprintf(out, "urb_priv [%p] ", urbp);
311 out += sprintf(out, "urb [%p] ", urbp->urb);
312 out += sprintf(out, "qh [%p] ", urbp->qh);
313 out += sprintf(out, "Dev=%d ", usb_pipedevice(urbp->urb->pipe));
314 out += sprintf(out, "EP=%x(%s) ", usb_pipeendpoint(urbp->urb->pipe), (usb_pipein(urbp->urb->pipe) ? "IN" : "OUT"));
316 switch (usb_pipetype(urbp->urb->pipe)) {
317 case PIPE_ISOCHRONOUS: out += sprintf(out, "ISO "); break;
318 case PIPE_INTERRUPT: out += sprintf(out, "INT "); break;
319 case PIPE_BULK: out += sprintf(out, "BLK "); break;
320 case PIPE_CONTROL: out += sprintf(out, "CTL "); break;
323 out += sprintf(out, "%s", (urbp->fsbr ? "FSBR " : ""));
324 out += sprintf(out, "%s", (urbp->fsbr_timeout ? "FSBR_TO " : ""));
326 if (urbp->urb->status != -EINPROGRESS)
327 out += sprintf(out, "Status=%d ", urbp->urb->status);
328 //out += sprintf(out, "Inserttime=%lx ",urbp->inserttime);
329 //out += sprintf(out, "FSBRtime=%lx ",urbp->fsbrtime);
331 count = 0;
332 list_for_each(tmp, &urbp->td_list)
333 count++;
334 out += sprintf(out, "TDs=%d ",count);
336 if (urbp->queued)
337 out += sprintf(out, "queued\n");
338 else {
339 count = 0;
340 list_for_each(tmp, &urbp->queue_list)
341 count++;
342 out += sprintf(out, "queued URBs=%d\n", count);
345 return out - buf;
348 static int uhci_show_lists(struct uhci_hcd *uhci, char *buf, int len)
350 char *out = buf;
351 struct list_head *head, *tmp;
352 int count;
354 out += sprintf(out, "Main list URBs:");
355 if (list_empty(&uhci->urb_list))
356 out += sprintf(out, " Empty\n");
357 else {
358 out += sprintf(out, "\n");
359 count = 0;
360 head = &uhci->urb_list;
361 tmp = head->next;
362 while (tmp != head) {
363 struct urb_priv *urbp = list_entry(tmp, struct urb_priv, urb_list);
365 out += sprintf(out, " %d: ", ++count);
366 out += uhci_show_urbp(uhci, urbp, out, len - (out - buf));
367 tmp = tmp->next;
371 out += sprintf(out, "Remove list URBs:");
372 if (list_empty(&uhci->urb_remove_list))
373 out += sprintf(out, " Empty\n");
374 else {
375 out += sprintf(out, "\n");
376 count = 0;
377 head = &uhci->urb_remove_list;
378 tmp = head->next;
379 while (tmp != head) {
380 struct urb_priv *urbp = list_entry(tmp, struct urb_priv, urb_list);
382 out += sprintf(out, " %d: ", ++count);
383 out += uhci_show_urbp(uhci, urbp, out, len - (out - buf));
384 tmp = tmp->next;
388 out += sprintf(out, "Complete list URBs:");
389 if (list_empty(&uhci->complete_list))
390 out += sprintf(out, " Empty\n");
391 else {
392 out += sprintf(out, "\n");
393 count = 0;
394 head = &uhci->complete_list;
395 tmp = head->next;
396 while (tmp != head) {
397 struct urb_priv *urbp = list_entry(tmp, struct urb_priv, urb_list);
399 out += sprintf(out, " %d: ", ++count);
400 out += uhci_show_urbp(uhci, urbp, out, len - (out - buf));
401 tmp = tmp->next;
405 return out - buf;
408 static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len)
410 unsigned long flags;
411 char *out = buf;
412 int i, j;
413 struct uhci_qh *qh;
414 struct uhci_td *td;
415 struct list_head *tmp, *head;
417 spin_lock_irqsave(&uhci->schedule_lock, flags);
419 out += sprintf(out, "HC status\n");
420 out += uhci_show_status(uhci, out, len - (out - buf));
422 out += sprintf(out, "Frame List\n");
423 for (i = 0; i < UHCI_NUMFRAMES; ++i) {
424 int shown = 0;
425 td = uhci->fl->frame_cpu[i];
426 if (!td)
427 continue;
429 if (td->dma_handle != (dma_addr_t)uhci->fl->frame[i]) {
430 show_frame_num();
431 out += sprintf(out, " frame list does not match td->dma_handle!\n");
433 show_frame_num();
435 head = &td->fl_list;
436 tmp = head;
437 do {
438 td = list_entry(tmp, struct uhci_td, fl_list);
439 tmp = tmp->next;
440 out += uhci_show_td(td, out, len - (out - buf), 4);
441 } while (tmp != head);
444 out += sprintf(out, "Skeleton QH's\n");
446 for (i = 0; i < UHCI_NUM_SKELQH; ++i) {
447 int shown = 0;
449 qh = uhci->skelqh[i];
451 if (debug > 1) {
452 show_qh_name();
453 out += uhci_show_qh(qh, out, len - (out - buf), 4);
456 /* Last QH is the Terminating QH, it's different */
457 if (i == UHCI_NUM_SKELQH - 1) {
458 if (qh->link != UHCI_PTR_TERM)
459 out += sprintf(out, " bandwidth reclamation on!\n");
461 if (qh->element != cpu_to_le32(uhci->term_td->dma_handle))
462 out += sprintf(out, " skel_term_qh element is not set to term_td!\n");
464 continue;
467 j = (i < 7) ? 7 : i+1; /* Next skeleton */
468 if (list_empty(&qh->list)) {
469 if (i < UHCI_NUM_SKELQH - 1) {
470 if (qh->link !=
471 (cpu_to_le32(uhci->skelqh[j]->dma_handle) | UHCI_PTR_QH)) {
472 show_qh_name();
473 out += sprintf(out, " skeleton QH not linked to next skeleton QH!\n");
477 continue;
480 show_qh_name();
482 head = &qh->list;
483 tmp = head->next;
485 while (tmp != head) {
486 qh = list_entry(tmp, struct uhci_qh, list);
488 tmp = tmp->next;
490 out += uhci_show_qh(qh, out, len - (out - buf), 4);
493 if (i < UHCI_NUM_SKELQH - 1) {
494 if (qh->link !=
495 (cpu_to_le32(uhci->skelqh[j]->dma_handle) | UHCI_PTR_QH))
496 out += sprintf(out, " last QH not linked to next skeleton!\n");
500 if (debug > 2)
501 out += uhci_show_lists(uhci, out, len - (out - buf));
503 spin_unlock_irqrestore(&uhci->schedule_lock, flags);
505 return out - buf;
508 #define MAX_OUTPUT (64 * 1024)
510 static struct proc_dir_entry *uhci_proc_root = NULL;
512 struct uhci_proc {
513 int size;
514 char *data;
515 struct uhci_hcd *uhci;
518 static int uhci_proc_open(struct inode *inode, struct file *file)
520 const struct proc_dir_entry *dp = PDE(inode);
521 struct uhci_hcd *uhci = dp->data;
522 struct uhci_proc *up;
523 int ret = -ENOMEM;
525 lock_kernel();
526 up = kmalloc(sizeof(*up), GFP_KERNEL);
527 if (!up)
528 goto out;
530 up->data = kmalloc(MAX_OUTPUT, GFP_KERNEL);
531 if (!up->data) {
532 kfree(up);
533 goto out;
536 up->size = uhci_sprint_schedule(uhci, up->data, MAX_OUTPUT);
538 file->private_data = up;
540 ret = 0;
541 out:
542 unlock_kernel();
543 return ret;
546 static loff_t uhci_proc_lseek(struct file *file, loff_t off, int whence)
548 struct uhci_proc *up;
549 loff_t new = -1;
551 lock_kernel();
552 up = file->private_data;
554 switch (whence) {
555 case 0:
556 new = off;
557 break;
558 case 1:
559 new = file->f_pos + off;
560 break;
562 if (new < 0 || new > up->size) {
563 unlock_kernel();
564 return -EINVAL;
566 unlock_kernel();
567 return (file->f_pos = new);
570 static ssize_t uhci_proc_read(struct file *file, char __user *buf,
571 size_t nbytes, loff_t *ppos)
573 struct uhci_proc *up = file->private_data;
574 return simple_read_from_buffer(buf, nbytes, ppos, up->data, up->size);
577 static int uhci_proc_release(struct inode *inode, struct file *file)
579 struct uhci_proc *up = file->private_data;
581 kfree(up->data);
582 kfree(up);
584 return 0;
587 static struct file_operations uhci_proc_operations = {
588 .open = uhci_proc_open,
589 .llseek = uhci_proc_lseek,
590 .read = uhci_proc_read,
591 // write: uhci_proc_write,
592 .release = uhci_proc_release,
594 #endif