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 #define uhci_debug_operations (* (struct file_operations *) NULL)
21 static struct dentry *uhci_debugfs_root;
25 /* Handle REALLY large printks so we don't overflow buffers */
26 static void lprintk(char *buf)
30 /* Just write one line at a time */
32 p = strchr(buf, '\n');
35 printk(KERN_DEBUG "%s\n", buf);
42 static int uhci_show_td(struct uhci_td *td, char *buf, int len, int space)
48 /* Try to make sure there's enough memory */
52 status = td_status(td);
53 out += sprintf(out, "%*s[%p] link (%08x) ", space, "", td, le32_to_cpu(td->link));
54 out += sprintf(out, "e%d %s%s%s%s%s%s%s%s%s%sLength=%x ",
56 (status & TD_CTRL_SPD) ? "SPD " : "",
57 (status & TD_CTRL_LS) ? "LS " : "",
58 (status & TD_CTRL_IOC) ? "IOC " : "",
59 (status & TD_CTRL_ACTIVE) ? "Active " : "",
60 (status & TD_CTRL_STALLED) ? "Stalled " : "",
61 (status & TD_CTRL_DBUFERR) ? "DataBufErr " : "",
62 (status & TD_CTRL_BABBLE) ? "Babble " : "",
63 (status & TD_CTRL_NAK) ? "NAK " : "",
64 (status & TD_CTRL_CRCTIMEO) ? "CRC/Timeo " : "",
65 (status & TD_CTRL_BITSTUFF) ? "BitStuff " : "",
69 switch (uhci_packetid(token)) {
84 out += sprintf(out, "MaxLen=%x DT%d EndPt=%x Dev=%x, PID=%x(%s) ",
91 out += sprintf(out, "(buf=%08x)\n", le32_to_cpu(td->buffer));
96 static int uhci_show_urbp(struct urb_priv *urbp, char *buf, int len, int space)
100 int i, nactive, ninactive;
105 out += sprintf(out, "urb_priv [%p] ", urbp);
106 out += sprintf(out, "urb [%p] ", urbp->urb);
107 out += sprintf(out, "qh [%p] ", urbp->qh);
108 out += sprintf(out, "Dev=%d ", usb_pipedevice(urbp->urb->pipe));
109 out += sprintf(out, "EP=%x(%s) ", usb_pipeendpoint(urbp->urb->pipe),
110 (usb_pipein(urbp->urb->pipe) ? "IN" : "OUT"));
112 switch (usb_pipetype(urbp->urb->pipe)) {
113 case PIPE_ISOCHRONOUS: out += sprintf(out, "ISO"); break;
114 case PIPE_INTERRUPT: out += sprintf(out, "INT"); break;
115 case PIPE_BULK: out += sprintf(out, "BLK"); break;
116 case PIPE_CONTROL: out += sprintf(out, "CTL"); break;
119 out += sprintf(out, "%s", (urbp->fsbr ? " FSBR" : ""));
121 if (urbp->urb->status != -EINPROGRESS)
122 out += sprintf(out, " Status=%d", urbp->urb->status);
123 out += sprintf(out, "\n");
125 i = nactive = ninactive = 0;
126 list_for_each_entry(td, &urbp->td_list, list) {
127 if (++i <= 10 || debug > 2) {
128 out += sprintf(out, "%*s%d: ", space + 2, "", i);
129 out += uhci_show_td(td, out, len - (out - buf), 0);
131 if (td_status(td) & TD_CTRL_ACTIVE)
137 if (nactive + ninactive > 0)
138 out += sprintf(out, "%*s[skipped %d inactive and %d active "
140 space, "", ninactive, nactive);
145 static int uhci_show_qh(struct uhci_qh *qh, char *buf, int len, int space)
149 __le32 element = qh_element(qh);
151 /* Try to make sure there's enough memory */
155 out += sprintf(out, "%*s[%p] link (%08x) element (%08x)\n", space, "",
156 qh, le32_to_cpu(qh->link), le32_to_cpu(element));
158 if (element & UHCI_PTR_QH)
159 out += sprintf(out, "%*s Element points to QH (bug?)\n", space, "");
161 if (element & UHCI_PTR_DEPTH)
162 out += sprintf(out, "%*s Depth traverse\n", space, "");
164 if (element & cpu_to_le32(8))
165 out += sprintf(out, "%*s Bit 3 set (bug?)\n", space, "");
167 if (!(element & ~(UHCI_PTR_QH | UHCI_PTR_DEPTH)))
168 out += sprintf(out, "%*s Element is NULL (bug?)\n", space, "");
170 if (list_empty(&qh->queue)) {
171 out += sprintf(out, "%*s queue is empty\n", space, "");
173 struct urb_priv *urbp = list_entry(qh->queue.next,
174 struct urb_priv, node);
175 struct uhci_td *td = list_entry(urbp->td_list.next,
176 struct uhci_td, list);
178 if (cpu_to_le32(td->dma_handle) != (element & ~UHCI_PTR_BITS))
179 out += sprintf(out, "%*s Element != First TD\n",
182 list_for_each_entry(urbp, &qh->queue, node) {
184 out += uhci_show_urbp(urbp, out,
185 len - (out - buf), space + 2);
190 out += sprintf(out, "%*s Skipped %d URBs\n",
195 out += sprintf(out, "%*s Dummy TD\n", space, "");
196 out += uhci_show_td(qh->dummy_td, out, len - (out - buf), 0);
202 static const char * const qh_names[] = {
203 "skel_unlink_qh", "skel_iso_qh",
204 "skel_int128_qh", "skel_int64_qh",
205 "skel_int32_qh", "skel_int16_qh",
206 "skel_int8_qh", "skel_int4_qh",
207 "skel_int2_qh", "skel_int1_qh",
208 "skel_ls_control_qh", "skel_fs_control_qh",
209 "skel_bulk_qh", "skel_term_qh"
212 static int uhci_show_sc(int port, unsigned short status, char *buf, int len)
216 /* Try to make sure there's enough memory */
220 out += sprintf(out, " stat%d = %04x %s%s%s%s%s%s%s%s%s%s\n",
223 (status & USBPORTSC_SUSP) ? " Suspend" : "",
224 (status & USBPORTSC_OCC) ? " OverCurrentChange" : "",
225 (status & USBPORTSC_OC) ? " OverCurrent" : "",
226 (status & USBPORTSC_PR) ? " Reset" : "",
227 (status & USBPORTSC_LSDA) ? " LowSpeed" : "",
228 (status & USBPORTSC_RD) ? " ResumeDetect" : "",
229 (status & USBPORTSC_PEC) ? " EnableChange" : "",
230 (status & USBPORTSC_PE) ? " Enabled" : "",
231 (status & USBPORTSC_CSC) ? " ConnectChange" : "",
232 (status & USBPORTSC_CCS) ? " Connected" : "");
237 static int uhci_show_root_hub_state(struct uhci_hcd *uhci, char *buf, int len)
242 /* Try to make sure there's enough memory */
246 switch (uhci->rh_state) {
248 rh_state = "reset"; break;
249 case UHCI_RH_SUSPENDED:
250 rh_state = "suspended"; break;
251 case UHCI_RH_AUTO_STOPPED:
252 rh_state = "auto-stopped"; break;
253 case UHCI_RH_RESUMING:
254 rh_state = "resuming"; break;
255 case UHCI_RH_SUSPENDING:
256 rh_state = "suspending"; break;
257 case UHCI_RH_RUNNING:
258 rh_state = "running"; break;
259 case UHCI_RH_RUNNING_NODEVS:
260 rh_state = "running, no devs"; break;
262 rh_state = "?"; break;
264 out += sprintf(out, "Root-hub state: %s\n", rh_state);
268 static int uhci_show_status(struct uhci_hcd *uhci, char *buf, int len)
271 unsigned long io_addr = uhci->io_addr;
272 unsigned short usbcmd, usbstat, usbint, usbfrnum;
273 unsigned int flbaseadd;
275 unsigned short portsc1, portsc2;
277 /* Try to make sure there's enough memory */
281 usbcmd = inw(io_addr + 0);
282 usbstat = inw(io_addr + 2);
283 usbint = inw(io_addr + 4);
284 usbfrnum = inw(io_addr + 6);
285 flbaseadd = inl(io_addr + 8);
286 sof = inb(io_addr + 12);
287 portsc1 = inw(io_addr + 16);
288 portsc2 = inw(io_addr + 18);
290 out += sprintf(out, " usbcmd = %04x %s%s%s%s%s%s%s%s\n",
292 (usbcmd & USBCMD_MAXP) ? "Maxp64 " : "Maxp32 ",
293 (usbcmd & USBCMD_CF) ? "CF " : "",
294 (usbcmd & USBCMD_SWDBG) ? "SWDBG " : "",
295 (usbcmd & USBCMD_FGR) ? "FGR " : "",
296 (usbcmd & USBCMD_EGSM) ? "EGSM " : "",
297 (usbcmd & USBCMD_GRESET) ? "GRESET " : "",
298 (usbcmd & USBCMD_HCRESET) ? "HCRESET " : "",
299 (usbcmd & USBCMD_RS) ? "RS " : "");
301 out += sprintf(out, " usbstat = %04x %s%s%s%s%s%s\n",
303 (usbstat & USBSTS_HCH) ? "HCHalted " : "",
304 (usbstat & USBSTS_HCPE) ? "HostControllerProcessError " : "",
305 (usbstat & USBSTS_HSE) ? "HostSystemError " : "",
306 (usbstat & USBSTS_RD) ? "ResumeDetect " : "",
307 (usbstat & USBSTS_ERROR) ? "USBError " : "",
308 (usbstat & USBSTS_USBINT) ? "USBINT " : "");
310 out += sprintf(out, " usbint = %04x\n", usbint);
311 out += sprintf(out, " usbfrnum = (%d)%03x\n", (usbfrnum >> 10) & 1,
312 0xfff & (4*(unsigned int)usbfrnum));
313 out += sprintf(out, " flbaseadd = %08x\n", flbaseadd);
314 out += sprintf(out, " sof = %02x\n", sof);
315 out += uhci_show_sc(1, portsc1, out, len - (out - buf));
316 out += uhci_show_sc(2, portsc2, out, len - (out - buf));
321 static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len)
327 struct list_head *tmp, *head;
329 out += uhci_show_root_hub_state(uhci, out, len - (out - buf));
330 out += sprintf(out, "HC status\n");
331 out += uhci_show_status(uhci, out, len - (out - buf));
335 out += sprintf(out, "Frame List\n");
336 for (i = 0; i < UHCI_NUMFRAMES; ++i) {
337 td = uhci->frame_cpu[i];
341 out += sprintf(out, "- Frame %d\n", i); \
342 if (td->dma_handle != (dma_addr_t)uhci->frame[i])
343 out += sprintf(out, " frame list does not match td->dma_handle!\n");
348 td = list_entry(tmp, struct uhci_td, fl_list);
350 out += uhci_show_td(td, out, len - (out - buf), 4);
351 } while (tmp != head);
354 out += sprintf(out, "Skeleton QHs\n");
356 for (i = 0; i < UHCI_NUM_SKELQH; ++i) {
359 qh = uhci->skelqh[i];
360 out += sprintf(out, "- %s\n", qh_names[i]); \
361 out += uhci_show_qh(qh, out, len - (out - buf), 4);
363 /* Last QH is the Terminating QH, it's different */
364 if (i == UHCI_NUM_SKELQH - 1) {
365 if (qh->link != UHCI_PTR_TERM)
366 out += sprintf(out, " bandwidth reclamation on!\n");
368 if (qh_element(qh) != cpu_to_le32(uhci->term_td->dma_handle))
369 out += sprintf(out, " skel_term_qh element is not set to term_td!\n");
374 j = (i < 9) ? 9 : i+1; /* Next skeleton */
378 while (tmp != head) {
379 qh = list_entry(tmp, struct uhci_qh, node);
382 out += uhci_show_qh(qh, out,
383 len - (out - buf), 4);
386 out += sprintf(out, " Skipped %d QHs\n", cnt);
388 if (i > 1 && i < UHCI_NUM_SKELQH - 1) {
390 (cpu_to_le32(uhci->skelqh[j]->dma_handle) | UHCI_PTR_QH))
391 out += sprintf(out, " last QH not linked to next skeleton!\n");
398 #ifdef CONFIG_DEBUG_FS
400 #define MAX_OUTPUT (64 * 1024)
407 static int uhci_debug_open(struct inode *inode, struct file *file)
409 struct uhci_hcd *uhci = inode->u.generic_ip;
410 struct uhci_debug *up;
415 up = kmalloc(sizeof(*up), GFP_KERNEL);
419 up->data = kmalloc(MAX_OUTPUT, GFP_KERNEL);
426 spin_lock_irqsave(&uhci->lock, flags);
427 if (uhci->is_initialized)
428 up->size = uhci_sprint_schedule(uhci, up->data, MAX_OUTPUT);
429 spin_unlock_irqrestore(&uhci->lock, flags);
431 file->private_data = up;
439 static loff_t uhci_debug_lseek(struct file *file, loff_t off, int whence)
441 struct uhci_debug *up;
445 up = file->private_data;
452 new = file->f_pos + off;
455 if (new < 0 || new > up->size) {
460 return (file->f_pos = new);
463 static ssize_t uhci_debug_read(struct file *file, char __user *buf,
464 size_t nbytes, loff_t *ppos)
466 struct uhci_debug *up = file->private_data;
467 return simple_read_from_buffer(buf, nbytes, ppos, up->data, up->size);
470 static int uhci_debug_release(struct inode *inode, struct file *file)
472 struct uhci_debug *up = file->private_data;
480 #undef uhci_debug_operations
481 static struct file_operations uhci_debug_operations = {
482 .owner = THIS_MODULE,
483 .open = uhci_debug_open,
484 .llseek = uhci_debug_lseek,
485 .read = uhci_debug_read,
486 .release = uhci_debug_release,
489 #endif /* CONFIG_DEBUG_FS */
493 static inline void lprintk(char *buf)
496 static inline int uhci_show_qh(struct uhci_qh *qh, char *buf,
502 static inline int uhci_sprint_schedule(struct uhci_hcd *uhci,