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/debugfs.h>
15 #include <linux/smp_lock.h>
20 /* Handle REALLY large printk's so we don't overflow buffers */
21 static inline void lprintk(char *buf)
25 /* Just write one line at a time */
27 p = strchr(buf, '\n');
30 printk(KERN_DEBUG "%s\n", buf);
37 static int uhci_show_td(struct uhci_td *td, char *buf, int len, int space)
43 /* Try to make sure there's enough memory */
47 status = td_status(td);
48 out += sprintf(out, "%*s[%p] link (%08x) ", space, "", td, le32_to_cpu(td->link));
49 out += sprintf(out, "e%d %s%s%s%s%s%s%s%s%s%sLength=%x ",
51 (status & TD_CTRL_SPD) ? "SPD " : "",
52 (status & TD_CTRL_LS) ? "LS " : "",
53 (status & TD_CTRL_IOC) ? "IOC " : "",
54 (status & TD_CTRL_ACTIVE) ? "Active " : "",
55 (status & TD_CTRL_STALLED) ? "Stalled " : "",
56 (status & TD_CTRL_DBUFERR) ? "DataBufErr " : "",
57 (status & TD_CTRL_BABBLE) ? "Babble " : "",
58 (status & TD_CTRL_NAK) ? "NAK " : "",
59 (status & TD_CTRL_CRCTIMEO) ? "CRC/Timeo " : "",
60 (status & TD_CTRL_BITSTUFF) ? "BitStuff " : "",
64 switch (uhci_packetid(token)) {
79 out += sprintf(out, "MaxLen=%x DT%d EndPt=%x Dev=%x, PID=%x(%s) ",
86 out += sprintf(out, "(buf=%08x)\n", le32_to_cpu(td->buffer));
91 static int uhci_show_qh(struct uhci_qh *qh, char *buf, int len, int space)
94 struct urb_priv *urbp;
95 struct list_head *head, *tmp;
97 int i = 0, checked = 0, prevactive = 0;
98 __le32 element = qh_element(qh);
100 /* Try to make sure there's enough memory */
104 out += sprintf(out, "%*s[%p] link (%08x) element (%08x)\n", space, "",
105 qh, le32_to_cpu(qh->link), le32_to_cpu(element));
107 if (element & UHCI_PTR_QH)
108 out += sprintf(out, "%*s Element points to QH (bug?)\n", space, "");
110 if (element & UHCI_PTR_DEPTH)
111 out += sprintf(out, "%*s Depth traverse\n", space, "");
113 if (element & cpu_to_le32(8))
114 out += sprintf(out, "%*s Bit 3 set (bug?)\n", space, "");
116 if (!(element & ~(UHCI_PTR_QH | UHCI_PTR_DEPTH)))
117 out += sprintf(out, "%*s Element is NULL (bug?)\n", space, "");
120 out += sprintf(out, "%*s urbp == NULL\n", space, "");
126 head = &urbp->td_list;
129 td = list_entry(tmp, struct uhci_td, list);
131 if (cpu_to_le32(td->dma_handle) != (element & ~UHCI_PTR_BITS))
132 out += sprintf(out, "%*s Element != First TD\n", space, "");
134 while (tmp != head) {
135 struct uhci_td *td = list_entry(tmp, struct uhci_td, list);
139 out += sprintf(out, "%*s%d: ", space + 2, "", i++);
140 out += uhci_show_td(td, out, len - (out - buf), 0);
142 if (i > 10 && !checked && prevactive && tmp != head &&
144 struct list_head *ntmp = tmp;
145 struct uhci_td *ntd = td;
146 int active = 1, ni = i;
150 while (ntmp != head && ntmp->next != head && active) {
151 ntd = list_entry(ntmp, struct uhci_td, list);
155 active = td_status(ntd) & TD_CTRL_ACTIVE;
160 if (active && ni > i) {
161 out += sprintf(out, "%*s[skipped %d active TD's]\n", space, "", ni - i);
168 prevactive = td_status(td) & TD_CTRL_ACTIVE;
171 if (list_empty(&urbp->queue_list) || urbp->queued)
174 out += sprintf(out, "%*sQueued QH's:\n", -space, "--");
176 head = &urbp->queue_list;
179 while (tmp != head) {
180 struct urb_priv *nurbp = list_entry(tmp, struct urb_priv,
184 out += uhci_show_qh(nurbp->qh, out, len - (out - buf), space);
191 #define show_frame_num() \
194 out += sprintf(out, "- Frame %d\n", i); \
197 #ifdef CONFIG_PROC_FS
198 static const char *qh_names[] = {
199 "skel_int128_qh", "skel_int64_qh",
200 "skel_int32_qh", "skel_int16_qh",
201 "skel_int8_qh", "skel_int4_qh",
202 "skel_int2_qh", "skel_int1_qh",
203 "skel_ls_control_qh", "skel_fs_control_qh",
204 "skel_bulk_qh", "skel_term_qh"
207 #define show_qh_name() \
210 out += sprintf(out, "- %s\n", qh_names[i]); \
213 static int uhci_show_sc(int port, unsigned short status, char *buf, int len)
217 /* Try to make sure there's enough memory */
221 out += sprintf(out, " stat%d = %04x %s%s%s%s%s%s%s%s%s%s\n",
224 (status & USBPORTSC_SUSP) ? " Suspend" : "",
225 (status & USBPORTSC_OCC) ? " OverCurrentChange" : "",
226 (status & USBPORTSC_OC) ? " OverCurrent" : "",
227 (status & USBPORTSC_PR) ? " Reset" : "",
228 (status & USBPORTSC_LSDA) ? " LowSpeed" : "",
229 (status & USBPORTSC_RD) ? " ResumeDetect" : "",
230 (status & USBPORTSC_PEC) ? " EnableChange" : "",
231 (status & USBPORTSC_PE) ? " Enabled" : "",
232 (status & USBPORTSC_CSC) ? " ConnectChange" : "",
233 (status & USBPORTSC_CCS) ? " Connected" : "");
238 static int uhci_show_status(struct uhci_hcd *uhci, char *buf, int len)
241 unsigned long io_addr = uhci->io_addr;
242 unsigned short usbcmd, usbstat, usbint, usbfrnum;
243 unsigned int flbaseadd;
245 unsigned short portsc1, portsc2;
247 /* Try to make sure there's enough memory */
251 usbcmd = inw(io_addr + 0);
252 usbstat = inw(io_addr + 2);
253 usbint = inw(io_addr + 4);
254 usbfrnum = inw(io_addr + 6);
255 flbaseadd = inl(io_addr + 8);
256 sof = inb(io_addr + 12);
257 portsc1 = inw(io_addr + 16);
258 portsc2 = inw(io_addr + 18);
260 out += sprintf(out, " usbcmd = %04x %s%s%s%s%s%s%s%s\n",
262 (usbcmd & USBCMD_MAXP) ? "Maxp64 " : "Maxp32 ",
263 (usbcmd & USBCMD_CF) ? "CF " : "",
264 (usbcmd & USBCMD_SWDBG) ? "SWDBG " : "",
265 (usbcmd & USBCMD_FGR) ? "FGR " : "",
266 (usbcmd & USBCMD_EGSM) ? "EGSM " : "",
267 (usbcmd & USBCMD_GRESET) ? "GRESET " : "",
268 (usbcmd & USBCMD_HCRESET) ? "HCRESET " : "",
269 (usbcmd & USBCMD_RS) ? "RS " : "");
271 out += sprintf(out, " usbstat = %04x %s%s%s%s%s%s\n",
273 (usbstat & USBSTS_HCH) ? "HCHalted " : "",
274 (usbstat & USBSTS_HCPE) ? "HostControllerProcessError " : "",
275 (usbstat & USBSTS_HSE) ? "HostSystemError " : "",
276 (usbstat & USBSTS_RD) ? "ResumeDetect " : "",
277 (usbstat & USBSTS_ERROR) ? "USBError " : "",
278 (usbstat & USBSTS_USBINT) ? "USBINT " : "");
280 out += sprintf(out, " usbint = %04x\n", usbint);
281 out += sprintf(out, " usbfrnum = (%d)%03x\n", (usbfrnum >> 10) & 1,
282 0xfff & (4*(unsigned int)usbfrnum));
283 out += sprintf(out, " flbaseadd = %08x\n", flbaseadd);
284 out += sprintf(out, " sof = %02x\n", sof);
285 out += uhci_show_sc(1, portsc1, out, len - (out - buf));
286 out += uhci_show_sc(2, portsc2, out, len - (out - buf));
291 static int uhci_show_urbp(struct uhci_hcd *uhci, struct urb_priv *urbp, char *buf, int len)
293 struct list_head *tmp;
300 out += sprintf(out, "urb_priv [%p] ", urbp);
301 out += sprintf(out, "urb [%p] ", urbp->urb);
302 out += sprintf(out, "qh [%p] ", urbp->qh);
303 out += sprintf(out, "Dev=%d ", usb_pipedevice(urbp->urb->pipe));
304 out += sprintf(out, "EP=%x(%s) ", usb_pipeendpoint(urbp->urb->pipe), (usb_pipein(urbp->urb->pipe) ? "IN" : "OUT"));
306 switch (usb_pipetype(urbp->urb->pipe)) {
307 case PIPE_ISOCHRONOUS: out += sprintf(out, "ISO "); break;
308 case PIPE_INTERRUPT: out += sprintf(out, "INT "); break;
309 case PIPE_BULK: out += sprintf(out, "BLK "); break;
310 case PIPE_CONTROL: out += sprintf(out, "CTL "); break;
313 out += sprintf(out, "%s", (urbp->fsbr ? "FSBR " : ""));
314 out += sprintf(out, "%s", (urbp->fsbr_timeout ? "FSBR_TO " : ""));
316 if (urbp->urb->status != -EINPROGRESS)
317 out += sprintf(out, "Status=%d ", urbp->urb->status);
318 //out += sprintf(out, "Inserttime=%lx ",urbp->inserttime);
319 //out += sprintf(out, "FSBRtime=%lx ",urbp->fsbrtime);
322 list_for_each(tmp, &urbp->td_list)
324 out += sprintf(out, "TDs=%d ",count);
327 out += sprintf(out, "queued\n");
330 list_for_each(tmp, &urbp->queue_list)
332 out += sprintf(out, "queued URBs=%d\n", count);
338 static int uhci_show_lists(struct uhci_hcd *uhci, char *buf, int len)
341 struct list_head *head, *tmp;
344 out += sprintf(out, "Main list URBs:");
345 if (list_empty(&uhci->urb_list))
346 out += sprintf(out, " Empty\n");
348 out += sprintf(out, "\n");
350 head = &uhci->urb_list;
352 while (tmp != head) {
353 struct urb_priv *urbp = list_entry(tmp, struct urb_priv, urb_list);
355 out += sprintf(out, " %d: ", ++count);
356 out += uhci_show_urbp(uhci, urbp, out, len - (out - buf));
361 out += sprintf(out, "Remove list URBs:");
362 if (list_empty(&uhci->urb_remove_list))
363 out += sprintf(out, " Empty\n");
365 out += sprintf(out, "\n");
367 head = &uhci->urb_remove_list;
369 while (tmp != head) {
370 struct urb_priv *urbp = list_entry(tmp, struct urb_priv, urb_list);
372 out += sprintf(out, " %d: ", ++count);
373 out += uhci_show_urbp(uhci, urbp, out, len - (out - buf));
378 out += sprintf(out, "Complete list URBs:");
379 if (list_empty(&uhci->complete_list))
380 out += sprintf(out, " Empty\n");
382 out += sprintf(out, "\n");
384 head = &uhci->complete_list;
386 while (tmp != head) {
387 struct urb_priv *urbp = list_entry(tmp, struct urb_priv, urb_list);
389 out += sprintf(out, " %d: ", ++count);
390 out += uhci_show_urbp(uhci, urbp, out, len - (out - buf));
398 static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len)
405 struct list_head *tmp, *head;
407 spin_lock_irqsave(&uhci->schedule_lock, flags);
409 out += sprintf(out, "HC status\n");
410 out += uhci_show_status(uhci, out, len - (out - buf));
412 out += sprintf(out, "Frame List\n");
413 for (i = 0; i < UHCI_NUMFRAMES; ++i) {
415 td = uhci->fl->frame_cpu[i];
419 if (td->dma_handle != (dma_addr_t)uhci->fl->frame[i]) {
421 out += sprintf(out, " frame list does not match td->dma_handle!\n");
428 td = list_entry(tmp, struct uhci_td, fl_list);
430 out += uhci_show_td(td, out, len - (out - buf), 4);
431 } while (tmp != head);
434 out += sprintf(out, "Skeleton QH's\n");
436 for (i = 0; i < UHCI_NUM_SKELQH; ++i) {
439 qh = uhci->skelqh[i];
443 out += uhci_show_qh(qh, out, len - (out - buf), 4);
446 /* Last QH is the Terminating QH, it's different */
447 if (i == UHCI_NUM_SKELQH - 1) {
448 if (qh->link != UHCI_PTR_TERM)
449 out += sprintf(out, " bandwidth reclamation on!\n");
451 if (qh_element(qh) != cpu_to_le32(uhci->term_td->dma_handle))
452 out += sprintf(out, " skel_term_qh element is not set to term_td!\n");
457 j = (i < 7) ? 7 : i+1; /* Next skeleton */
458 if (list_empty(&qh->list)) {
459 if (i < UHCI_NUM_SKELQH - 1) {
461 (cpu_to_le32(uhci->skelqh[j]->dma_handle) | UHCI_PTR_QH)) {
463 out += sprintf(out, " skeleton QH not linked to next skeleton QH!\n");
475 while (tmp != head) {
476 qh = list_entry(tmp, struct uhci_qh, list);
480 out += uhci_show_qh(qh, out, len - (out - buf), 4);
483 if (i < UHCI_NUM_SKELQH - 1) {
485 (cpu_to_le32(uhci->skelqh[j]->dma_handle) | UHCI_PTR_QH))
486 out += sprintf(out, " last QH not linked to next skeleton!\n");
491 out += uhci_show_lists(uhci, out, len - (out - buf));
493 spin_unlock_irqrestore(&uhci->schedule_lock, flags);
498 #define MAX_OUTPUT (64 * 1024)
500 static struct dentry *uhci_debugfs_root = NULL;
505 struct uhci_hcd *uhci;
508 static int uhci_debug_open(struct inode *inode, struct file *file)
510 struct uhci_hcd *uhci = inode->u.generic_ip;
511 struct uhci_debug *up;
515 up = kmalloc(sizeof(*up), GFP_KERNEL);
519 up->data = kmalloc(MAX_OUTPUT, GFP_KERNEL);
525 up->size = uhci_sprint_schedule(uhci, up->data, MAX_OUTPUT);
527 file->private_data = up;
535 static loff_t uhci_debug_lseek(struct file *file, loff_t off, int whence)
537 struct uhci_debug *up;
541 up = file->private_data;
548 new = file->f_pos + off;
551 if (new < 0 || new > up->size) {
556 return (file->f_pos = new);
559 static ssize_t uhci_debug_read(struct file *file, char __user *buf,
560 size_t nbytes, loff_t *ppos)
562 struct uhci_debug *up = file->private_data;
563 return simple_read_from_buffer(buf, nbytes, ppos, up->data, up->size);
566 static int uhci_debug_release(struct inode *inode, struct file *file)
568 struct uhci_debug *up = file->private_data;
576 static struct file_operations uhci_debug_operations = {
577 .open = uhci_debug_open,
578 .llseek = uhci_debug_lseek,
579 .read = uhci_debug_read,
580 .release = uhci_debug_release,