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 static struct dentry *uhci_debugfs_root = NULL;
22 /* Handle REALLY large printks so we don't overflow buffers */
23 static inline void lprintk(char *buf)
27 /* Just write one line at a time */
29 p = strchr(buf, '\n');
32 printk(KERN_DEBUG "%s\n", buf);
39 static int uhci_show_td(struct uhci_td *td, char *buf, int len, int space)
45 /* Try to make sure there's enough memory */
49 status = td_status(td);
50 out += sprintf(out, "%*s[%p] link (%08x) ", space, "", td, le32_to_cpu(td->link));
51 out += sprintf(out, "e%d %s%s%s%s%s%s%s%s%s%sLength=%x ",
53 (status & TD_CTRL_SPD) ? "SPD " : "",
54 (status & TD_CTRL_LS) ? "LS " : "",
55 (status & TD_CTRL_IOC) ? "IOC " : "",
56 (status & TD_CTRL_ACTIVE) ? "Active " : "",
57 (status & TD_CTRL_STALLED) ? "Stalled " : "",
58 (status & TD_CTRL_DBUFERR) ? "DataBufErr " : "",
59 (status & TD_CTRL_BABBLE) ? "Babble " : "",
60 (status & TD_CTRL_NAK) ? "NAK " : "",
61 (status & TD_CTRL_CRCTIMEO) ? "CRC/Timeo " : "",
62 (status & TD_CTRL_BITSTUFF) ? "BitStuff " : "",
66 switch (uhci_packetid(token)) {
81 out += sprintf(out, "MaxLen=%x DT%d EndPt=%x Dev=%x, PID=%x(%s) ",
88 out += sprintf(out, "(buf=%08x)\n", le32_to_cpu(td->buffer));
93 static int uhci_show_urbp(struct urb_priv *urbp, char *buf, int len, int space)
97 int i, nactive, ninactive;
102 out += sprintf(out, "urb_priv [%p] ", urbp);
103 out += sprintf(out, "urb [%p] ", urbp->urb);
104 out += sprintf(out, "qh [%p] ", urbp->qh);
105 out += sprintf(out, "Dev=%d ", usb_pipedevice(urbp->urb->pipe));
106 out += sprintf(out, "EP=%x(%s) ", usb_pipeendpoint(urbp->urb->pipe),
107 (usb_pipein(urbp->urb->pipe) ? "IN" : "OUT"));
109 switch (usb_pipetype(urbp->urb->pipe)) {
110 case PIPE_ISOCHRONOUS: out += sprintf(out, "ISO"); break;
111 case PIPE_INTERRUPT: out += sprintf(out, "INT"); break;
112 case PIPE_BULK: out += sprintf(out, "BLK"); break;
113 case PIPE_CONTROL: out += sprintf(out, "CTL"); break;
116 out += sprintf(out, "%s", (urbp->fsbr ? " FSBR" : ""));
117 out += sprintf(out, "%s", (urbp->fsbr_timeout ? " FSBR_TO" : ""));
119 if (urbp->urb->status != -EINPROGRESS)
120 out += sprintf(out, " Status=%d", urbp->urb->status);
121 out += sprintf(out, "\n");
123 i = nactive = ninactive = 0;
124 list_for_each_entry(td, &urbp->td_list, list) {
125 if (++i <= 10 || debug > 2) {
126 out += sprintf(out, "%*s%d: ", space + 2, "", i);
127 out += uhci_show_td(td, out, len - (out - buf), 0);
129 if (td_status(td) & TD_CTRL_ACTIVE)
135 if (nactive + ninactive > 0)
136 out += sprintf(out, "%*s[skipped %d inactive and %d active "
138 space, "", ninactive, nactive);
143 static int uhci_show_qh(struct uhci_qh *qh, char *buf, int len, int space)
147 __le32 element = qh_element(qh);
149 /* Try to make sure there's enough memory */
153 out += sprintf(out, "%*s[%p] link (%08x) element (%08x)\n", space, "",
154 qh, le32_to_cpu(qh->link), le32_to_cpu(element));
156 if (element & UHCI_PTR_QH)
157 out += sprintf(out, "%*s Element points to QH (bug?)\n", space, "");
159 if (element & UHCI_PTR_DEPTH)
160 out += sprintf(out, "%*s Depth traverse\n", space, "");
162 if (element & cpu_to_le32(8))
163 out += sprintf(out, "%*s Bit 3 set (bug?)\n", space, "");
165 if (!(element & ~(UHCI_PTR_QH | UHCI_PTR_DEPTH)))
166 out += sprintf(out, "%*s Element is NULL (bug?)\n", space, "");
168 if (list_empty(&qh->queue)) {
169 out += sprintf(out, "%*s queue is empty\n", space, "");
171 struct urb_priv *urbp = list_entry(qh->queue.next,
172 struct urb_priv, node);
173 struct uhci_td *td = list_entry(urbp->td_list.next,
174 struct uhci_td, list);
176 if (cpu_to_le32(td->dma_handle) != (element & ~UHCI_PTR_BITS))
177 out += sprintf(out, "%*s Element != First TD\n",
180 list_for_each_entry(urbp, &qh->queue, node) {
182 out += uhci_show_urbp(urbp, out,
183 len - (out - buf), space + 2);
188 out += sprintf(out, "%*s Skipped %d URBs\n",
193 out += sprintf(out, "%*s Dummy TD\n", space, "");
194 out += uhci_show_td(qh->dummy_td, out, len - (out - buf), 0);
200 #ifdef CONFIG_PROC_FS
201 static const char * const qh_names[] = {
202 "skel_unlink_qh", "skel_iso_qh",
203 "skel_int128_qh", "skel_int64_qh",
204 "skel_int32_qh", "skel_int16_qh",
205 "skel_int8_qh", "skel_int4_qh",
206 "skel_int2_qh", "skel_int1_qh",
207 "skel_ls_control_qh", "skel_fs_control_qh",
208 "skel_bulk_qh", "skel_term_qh"
211 static int uhci_show_sc(int port, unsigned short status, char *buf, int len)
215 /* Try to make sure there's enough memory */
219 out += sprintf(out, " stat%d = %04x %s%s%s%s%s%s%s%s%s%s\n",
222 (status & USBPORTSC_SUSP) ? " Suspend" : "",
223 (status & USBPORTSC_OCC) ? " OverCurrentChange" : "",
224 (status & USBPORTSC_OC) ? " OverCurrent" : "",
225 (status & USBPORTSC_PR) ? " Reset" : "",
226 (status & USBPORTSC_LSDA) ? " LowSpeed" : "",
227 (status & USBPORTSC_RD) ? " ResumeDetect" : "",
228 (status & USBPORTSC_PEC) ? " EnableChange" : "",
229 (status & USBPORTSC_PE) ? " Enabled" : "",
230 (status & USBPORTSC_CSC) ? " ConnectChange" : "",
231 (status & USBPORTSC_CCS) ? " Connected" : "");
236 static int uhci_show_root_hub_state(struct uhci_hcd *uhci, char *buf, int len)
241 /* Try to make sure there's enough memory */
245 switch (uhci->rh_state) {
247 rh_state = "reset"; break;
248 case UHCI_RH_SUSPENDED:
249 rh_state = "suspended"; break;
250 case UHCI_RH_AUTO_STOPPED:
251 rh_state = "auto-stopped"; break;
252 case UHCI_RH_RESUMING:
253 rh_state = "resuming"; break;
254 case UHCI_RH_SUSPENDING:
255 rh_state = "suspending"; break;
256 case UHCI_RH_RUNNING:
257 rh_state = "running"; break;
258 case UHCI_RH_RUNNING_NODEVS:
259 rh_state = "running, no devs"; break;
261 rh_state = "?"; break;
263 out += sprintf(out, "Root-hub state: %s\n", rh_state);
267 static int uhci_show_status(struct uhci_hcd *uhci, char *buf, int len)
270 unsigned long io_addr = uhci->io_addr;
271 unsigned short usbcmd, usbstat, usbint, usbfrnum;
272 unsigned int flbaseadd;
274 unsigned short portsc1, portsc2;
276 /* Try to make sure there's enough memory */
280 usbcmd = inw(io_addr + 0);
281 usbstat = inw(io_addr + 2);
282 usbint = inw(io_addr + 4);
283 usbfrnum = inw(io_addr + 6);
284 flbaseadd = inl(io_addr + 8);
285 sof = inb(io_addr + 12);
286 portsc1 = inw(io_addr + 16);
287 portsc2 = inw(io_addr + 18);
289 out += sprintf(out, " usbcmd = %04x %s%s%s%s%s%s%s%s\n",
291 (usbcmd & USBCMD_MAXP) ? "Maxp64 " : "Maxp32 ",
292 (usbcmd & USBCMD_CF) ? "CF " : "",
293 (usbcmd & USBCMD_SWDBG) ? "SWDBG " : "",
294 (usbcmd & USBCMD_FGR) ? "FGR " : "",
295 (usbcmd & USBCMD_EGSM) ? "EGSM " : "",
296 (usbcmd & USBCMD_GRESET) ? "GRESET " : "",
297 (usbcmd & USBCMD_HCRESET) ? "HCRESET " : "",
298 (usbcmd & USBCMD_RS) ? "RS " : "");
300 out += sprintf(out, " usbstat = %04x %s%s%s%s%s%s\n",
302 (usbstat & USBSTS_HCH) ? "HCHalted " : "",
303 (usbstat & USBSTS_HCPE) ? "HostControllerProcessError " : "",
304 (usbstat & USBSTS_HSE) ? "HostSystemError " : "",
305 (usbstat & USBSTS_RD) ? "ResumeDetect " : "",
306 (usbstat & USBSTS_ERROR) ? "USBError " : "",
307 (usbstat & USBSTS_USBINT) ? "USBINT " : "");
309 out += sprintf(out, " usbint = %04x\n", usbint);
310 out += sprintf(out, " usbfrnum = (%d)%03x\n", (usbfrnum >> 10) & 1,
311 0xfff & (4*(unsigned int)usbfrnum));
312 out += sprintf(out, " flbaseadd = %08x\n", flbaseadd);
313 out += sprintf(out, " sof = %02x\n", sof);
314 out += uhci_show_sc(1, portsc1, out, len - (out - buf));
315 out += uhci_show_sc(2, portsc2, out, len - (out - buf));
320 static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len)
326 struct list_head *tmp, *head;
328 out += uhci_show_root_hub_state(uhci, out, len - (out - buf));
329 out += sprintf(out, "HC status\n");
330 out += uhci_show_status(uhci, out, len - (out - buf));
334 out += sprintf(out, "Frame List\n");
335 for (i = 0; i < UHCI_NUMFRAMES; ++i) {
336 td = uhci->frame_cpu[i];
340 out += sprintf(out, "- Frame %d\n", i); \
341 if (td->dma_handle != (dma_addr_t)uhci->frame[i])
342 out += sprintf(out, " frame list does not match td->dma_handle!\n");
347 td = list_entry(tmp, struct uhci_td, fl_list);
349 out += uhci_show_td(td, out, len - (out - buf), 4);
350 } while (tmp != head);
353 out += sprintf(out, "Skeleton QHs\n");
355 for (i = 0; i < UHCI_NUM_SKELQH; ++i) {
358 qh = uhci->skelqh[i];
359 out += sprintf(out, "- %s\n", qh_names[i]); \
360 out += uhci_show_qh(qh, out, len - (out - buf), 4);
362 /* Last QH is the Terminating QH, it's different */
363 if (i == UHCI_NUM_SKELQH - 1) {
364 if (qh->link != UHCI_PTR_TERM)
365 out += sprintf(out, " bandwidth reclamation on!\n");
367 if (qh_element(qh) != cpu_to_le32(uhci->term_td->dma_handle))
368 out += sprintf(out, " skel_term_qh element is not set to term_td!\n");
373 j = (i < 9) ? 9 : i+1; /* Next skeleton */
377 while (tmp != head) {
378 qh = list_entry(tmp, struct uhci_qh, node);
381 out += uhci_show_qh(qh, out,
382 len - (out - buf), 4);
385 out += sprintf(out, " Skipped %d QHs\n", cnt);
387 if (i > 1 && i < UHCI_NUM_SKELQH - 1) {
389 (cpu_to_le32(uhci->skelqh[j]->dma_handle) | UHCI_PTR_QH))
390 out += sprintf(out, " last QH not linked to next skeleton!\n");
397 #define MAX_OUTPUT (64 * 1024)
402 struct uhci_hcd *uhci;
405 static int uhci_debug_open(struct inode *inode, struct file *file)
407 struct uhci_hcd *uhci = inode->u.generic_ip;
408 struct uhci_debug *up;
413 up = kmalloc(sizeof(*up), GFP_KERNEL);
417 up->data = kmalloc(MAX_OUTPUT, GFP_KERNEL);
423 spin_lock_irqsave(&uhci->lock, flags);
424 up->size = uhci_sprint_schedule(uhci, up->data, MAX_OUTPUT);
425 spin_unlock_irqrestore(&uhci->lock, flags);
427 file->private_data = up;
435 static loff_t uhci_debug_lseek(struct file *file, loff_t off, int whence)
437 struct uhci_debug *up;
441 up = file->private_data;
448 new = file->f_pos + off;
451 if (new < 0 || new > up->size) {
456 return (file->f_pos = new);
459 static ssize_t uhci_debug_read(struct file *file, char __user *buf,
460 size_t nbytes, loff_t *ppos)
462 struct uhci_debug *up = file->private_data;
463 return simple_read_from_buffer(buf, nbytes, ppos, up->data, up->size);
466 static int uhci_debug_release(struct inode *inode, struct file *file)
468 struct uhci_debug *up = file->private_data;
476 static struct file_operations uhci_debug_operations = {
477 .open = uhci_debug_open,
478 .llseek = uhci_debug_lseek,
479 .read = uhci_debug_read,
480 .release = uhci_debug_release,
483 #else /* CONFIG_DEBUG_FS */
485 #define uhci_debug_operations (* (struct file_operations *) NULL)