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>
19 /* Handle REALLY large printk's so we don't overflow buffers */
20 static void inline lprintk(char *buf)
24 /* Just write one line at a time */
26 p = strchr(buf, '\n');
36 static int inline uhci_is_skeleton_td(struct uhci *uhci, struct uhci_td *td)
40 for (i = 0; i < UHCI_NUM_SKELTD; i++)
41 if (td == uhci->skeltd[i])
47 static int inline uhci_is_skeleton_qh(struct uhci *uhci, struct uhci_qh *qh)
51 for (i = 0; i < UHCI_NUM_SKELQH; i++)
52 if (qh == uhci->skelqh[i])
58 static int uhci_show_td(struct uhci_td *td, char *buf, int len, int space)
63 /* Try to make sure there's enough memory */
67 out += sprintf(out, "%*s[%p] link (%08x) ", space, "", td, td->link);
68 out += sprintf(out, "e%d %s%s%s%s%s%s%s%s%s%sLength=%x ",
69 ((td->status >> 27) & 3),
70 (td->status & TD_CTRL_SPD) ? "SPD " : "",
71 (td->status & TD_CTRL_LS) ? "LS " : "",
72 (td->status & TD_CTRL_IOC) ? "IOC " : "",
73 (td->status & TD_CTRL_ACTIVE) ? "Active " : "",
74 (td->status & TD_CTRL_STALLED) ? "Stalled " : "",
75 (td->status & TD_CTRL_DBUFERR) ? "DataBufErr " : "",
76 (td->status & TD_CTRL_BABBLE) ? "Babble " : "",
77 (td->status & TD_CTRL_NAK) ? "NAK " : "",
78 (td->status & TD_CTRL_CRCTIMEO) ? "CRC/Timeo " : "",
79 (td->status & TD_CTRL_BITSTUFF) ? "BitStuff " : "",
82 switch (td->info & 0xff) {
97 out += sprintf(out, "MaxLen=%x DT%d EndPt=%x Dev=%x, PID=%x(%s) ",
99 ((td->info >> 19) & 1),
100 (td->info >> 15) & 15,
101 (td->info >> 8) & 127,
104 out += sprintf(out, "(buf=%08x)\n", td->buffer);
109 static int uhci_show_sc(int port, unsigned short status, char *buf, int len)
113 /* Try to make sure there's enough memory */
117 out += sprintf(out, " stat%d = %04x %s%s%s%s%s%s%s%s\n",
120 (status & USBPORTSC_SUSP) ? "PortSuspend " : "",
121 (status & USBPORTSC_PR) ? "PortReset " : "",
122 (status & USBPORTSC_LSDA) ? "LowSpeed " : "",
123 (status & USBPORTSC_RD) ? "ResumeDetect " : "",
124 (status & USBPORTSC_PEC) ? "EnableChange " : "",
125 (status & USBPORTSC_PE) ? "PortEnabled " : "",
126 (status & USBPORTSC_CSC) ? "ConnectChange " : "",
127 (status & USBPORTSC_CCS) ? "PortConnected " : "");
132 static int uhci_show_status(struct uhci *uhci, char *buf, int len)
135 unsigned int io_addr = uhci->io_addr;
136 unsigned short usbcmd, usbstat, usbint, usbfrnum;
137 unsigned int flbaseadd;
139 unsigned short portsc1, portsc2;
141 /* Try to make sure there's enough memory */
145 usbcmd = inw(io_addr + 0);
146 usbstat = inw(io_addr + 2);
147 usbint = inw(io_addr + 4);
148 usbfrnum = inw(io_addr + 6);
149 flbaseadd = inl(io_addr + 8);
150 sof = inb(io_addr + 12);
151 portsc1 = inw(io_addr + 16);
152 portsc2 = inw(io_addr + 18);
154 out += sprintf(out, " usbcmd = %04x %s%s%s%s%s%s%s%s\n",
156 (usbcmd & USBCMD_MAXP) ? "Maxp64 " : "Maxp32 ",
157 (usbcmd & USBCMD_CF) ? "CF " : "",
158 (usbcmd & USBCMD_SWDBG) ? "SWDBG " : "",
159 (usbcmd & USBCMD_FGR) ? "FGR " : "",
160 (usbcmd & USBCMD_EGSM) ? "EGSM " : "",
161 (usbcmd & USBCMD_GRESET) ? "GRESET " : "",
162 (usbcmd & USBCMD_HCRESET) ? "HCRESET " : "",
163 (usbcmd & USBCMD_RS) ? "RS " : "");
165 out += sprintf(out, " usbstat = %04x %s%s%s%s%s%s\n",
167 (usbstat & USBSTS_HCH) ? "HCHalted " : "",
168 (usbstat & USBSTS_HCPE) ? "HostControllerProcessError " : "",
169 (usbstat & USBSTS_HSE) ? "HostSystemError " : "",
170 (usbstat & USBSTS_RD) ? "ResumeDetect " : "",
171 (usbstat & USBSTS_ERROR) ? "USBError " : "",
172 (usbstat & USBSTS_USBINT) ? "USBINT " : "");
174 out += sprintf(out, " usbint = %04x\n", usbint);
175 out += sprintf(out, " usbfrnum = (%d)%03x\n", (usbfrnum >> 10) & 1,
176 0xfff & (4*(unsigned int)usbfrnum));
177 out += sprintf(out, " flbaseadd = %08x\n", flbaseadd);
178 out += sprintf(out, " sof = %02x\n", sof);
179 out += uhci_show_sc(1, portsc1, out, len - (out - buf));
180 out += uhci_show_sc(2, portsc2, out, len - (out - buf));
185 static int uhci_show_qh(struct uhci_qh *qh, char *buf, int len, int space)
188 struct urb_priv *urbp;
189 struct list_head *head, *tmp;
191 int i = 0, checked = 0, prevactive = 0;
193 /* Try to make sure there's enough memory */
197 out += sprintf(out, "%*s[%p] link (%08x) element (%08x)\n", space, "",
198 qh, qh->link, qh->element);
200 if (qh->element & UHCI_PTR_QH)
201 out += sprintf(out, "%*s Element points to QH (bug?)\n", space, "");
203 if (qh->element & UHCI_PTR_DEPTH)
204 out += sprintf(out, "%*s Depth traverse\n", space, "");
207 out += sprintf(out, "%*s Bit 3 set (bug?)\n", space, "");
209 if (!(qh->element & ~(UHCI_PTR_QH | UHCI_PTR_DEPTH)))
210 out += sprintf(out, "%*s Element is NULL (bug?)\n", space, "");
213 out += sprintf(out, "%*s urbp == NULL\n", space, "");
219 head = &urbp->td_list;
222 td = list_entry(tmp, struct uhci_td, list);
224 if (td->dma_handle != (qh->element & ~UHCI_PTR_BITS))
225 out += sprintf(out, "%*s Element != First TD\n", space, "");
227 while (tmp != head) {
228 struct uhci_td *td = list_entry(tmp, struct uhci_td, list);
232 out += sprintf(out, "%*s%d: ", space + 2, "", i++);
233 out += uhci_show_td(td, out, len - (out - buf), 0);
235 if (i > 10 && !checked && prevactive && tmp != head &&
237 struct list_head *ntmp = tmp;
238 struct uhci_td *ntd = td;
239 int active = 1, ni = i;
243 while (ntmp != head && ntmp->next != head && active) {
244 ntd = list_entry(ntmp, struct uhci_td, list);
248 active = ntd->status & TD_CTRL_ACTIVE;
253 if (active && ni > i) {
254 out += sprintf(out, "%*s[skipped %d active TD's]\n", space, "", ni - i);
261 prevactive = td->status & TD_CTRL_ACTIVE;
264 if (list_empty(&urbp->queue_list) || urbp->queued)
267 out += sprintf(out, "%*sQueued QH's:\n", -space, "--");
269 head = &urbp->queue_list;
272 while (tmp != head) {
273 struct urb_priv *nurbp = list_entry(tmp, struct urb_priv,
277 out += uhci_show_qh(nurbp->qh, out, len - (out - buf), space);
284 static const char *td_names[] = {"skel_int1_td", "skel_int2_td",
285 "skel_int4_td", "skel_int8_td",
286 "skel_int16_td", "skel_int32_td",
287 "skel_int64_td", "skel_int128_td",
288 "skel_int256_td", "skel_term_td" };
289 static const char *qh_names[] = { "skel_ls_control_qh", "skel_hs_control_qh",
290 "skel_bulk_qh", "skel_term_qh" };
292 #define show_frame_num() \
295 out += sprintf(out, "- Frame %d\n", i); \
298 #define show_td_name() \
301 out += sprintf(out, "- %s\n", td_names[i]); \
304 #define show_qh_name() \
307 out += sprintf(out, "- %s\n", qh_names[i]); \
310 static int uhci_sprint_schedule(struct uhci *uhci, char *buf, int len)
316 struct list_head *tmp, *head;
318 out += sprintf(out, "HC status\n");
319 out += uhci_show_status(uhci, out, len - (out - buf));
321 out += sprintf(out, "Frame List\n");
322 for (i = 0; i < UHCI_NUMFRAMES; ++i) {
324 td = uhci->fl->frame_cpu[i];
328 if (td->dma_handle != (dma_addr_t)uhci->fl->frame[i]) {
330 out += sprintf(out, " frame list does not match td->dma_handle!\n");
332 if (uhci_is_skeleton_td(uhci, td))
339 td = list_entry(tmp, struct uhci_td, fl_list);
341 out += uhci_show_td(td, out, len - (out - buf), 4);
342 } while (tmp != head);
345 out += sprintf(out, "Skeleton TD's\n");
346 for (i = UHCI_NUM_SKELTD - 1; i >= 0; i--) {
349 td = uhci->skeltd[i];
353 out += uhci_show_td(td, out, len - (out - buf), 4);
356 if (list_empty(&td->fl_list)) {
357 /* TD 0 is the int1 TD and links to control_ls_qh */
360 (uhci->skel_ls_control_qh->dma_handle | UHCI_PTR_QH)) {
362 out += sprintf(out, " skeleton TD not linked to ls_control QH!\n");
365 if (td->link != uhci->skeltd[i - 1]->dma_handle) {
367 out += sprintf(out, " skeleton TD not linked to next skeleton TD!\n");
372 if (td->link != td->dma_handle)
373 out += sprintf(out, " skel_term_td does not link to self\n");
375 /* Don't show it twice */
377 out += uhci_show_td(td, out, len - (out - buf), 4);
388 while (tmp != head) {
389 td = list_entry(tmp, struct uhci_td, fl_list);
393 out += uhci_show_td(td, out, len - (out - buf), 4);
398 (uhci->skel_ls_control_qh->dma_handle | UHCI_PTR_QH))
399 out += sprintf(out, " last TD not linked to ls_control QH!\n");
401 if (td->link != uhci->skeltd[i - 1]->dma_handle)
402 out += sprintf(out, " last TD not linked to next skeleton!\n");
406 out += sprintf(out, "Skeleton QH's\n");
408 for (i = 0; i < UHCI_NUM_SKELQH; ++i) {
411 qh = uhci->skelqh[i];
415 out += uhci_show_qh(qh, out, len - (out - buf), 4);
418 /* QH 3 is the Terminating QH, it's different */
420 if (qh->link != UHCI_PTR_TERM) {
422 out += sprintf(out, " bandwidth reclamation on!\n");
425 if (qh->element != uhci->skel_term_td->dma_handle) {
427 out += sprintf(out, " skel_term_qh element is not set to skel_term_td\n");
431 if (list_empty(&qh->list)) {
434 (uhci->skelqh[i + 1]->dma_handle | UHCI_PTR_QH)) {
436 out += sprintf(out, " skeleton QH not linked to next skeleton QH!\n");
448 while (tmp != head) {
449 qh = list_entry(tmp, struct uhci_qh, list);
453 out += uhci_show_qh(qh, out, len - (out - buf), 4);
458 (uhci->skelqh[i + 1]->dma_handle | UHCI_PTR_QH))
459 out += sprintf(out, " last QH not linked to next skeleton!\n");
466 #ifdef CONFIG_PROC_FS
467 #define MAX_OUTPUT (64 * 1024)
469 static struct proc_dir_entry *uhci_proc_root = NULL;
477 static int uhci_proc_open(struct inode *inode, struct file *file)
479 const struct proc_dir_entry *dp = inode->u.generic_ip;
480 struct uhci *uhci = dp->data;
481 struct uhci_proc *up;
486 up = kmalloc(sizeof(*up), GFP_KERNEL);
490 up->data = kmalloc(MAX_OUTPUT, GFP_KERNEL);
496 spin_lock_irqsave(&uhci->frame_list_lock, flags);
497 up->size = uhci_sprint_schedule(uhci, up->data, MAX_OUTPUT);
498 spin_unlock_irqrestore(&uhci->frame_list_lock, flags);
500 file->private_data = up;
508 static loff_t uhci_proc_lseek(struct file *file, loff_t off, int whence)
510 struct uhci_proc *up = file->private_data;
518 new = file->f_pos + off;
524 if (new < 0 || new > up->size)
526 return (file->f_pos = new);
529 static ssize_t uhci_proc_read(struct file *file, char *buf, size_t nbytes,
532 struct uhci_proc *up = file->private_data;
534 unsigned int pos = n;
538 if (pos != n || pos >= size)
540 if (nbytes > size - pos)
543 if (!access_ok(VERIFY_WRITE, buf, nbytes))
546 if (copy_to_user(buf, up->data + pos, nbytes))
549 *ppos = pos + nbytes;
554 static int uhci_proc_release(struct inode *inode, struct file *file)
556 struct uhci_proc *up = file->private_data;
564 static struct file_operations uhci_proc_operations = {
565 open: uhci_proc_open,
566 llseek: uhci_proc_lseek,
567 read: uhci_proc_read,
568 // write: uhci_proc_write,
569 release: uhci_proc_release,