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
13 #include <linux/config.h>
14 #include <linux/kernel.h>
15 #include <linux/proc_fs.h>
16 #include <linux/smp_lock.h>
22 /* Handle REALLY large printk's 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 inline int uhci_is_skeleton_qh(struct uhci_hcd
*uhci
, struct uhci_qh
*qh
)
43 for (i
= 0; i
< UHCI_NUM_SKELQH
; i
++)
44 if (qh
== uhci
->skelqh
[i
])
50 static int uhci_show_td(struct uhci_td
*td
, char *buf
, int len
, int space
)
56 /* Try to make sure there's enough memory */
60 status
= td_status(td
);
61 out
+= sprintf(out
, "%*s[%p] link (%08x) ", space
, "", td
, le32_to_cpu(td
->link
));
62 out
+= sprintf(out
, "e%d %s%s%s%s%s%s%s%s%s%sLength=%x ",
64 (status
& TD_CTRL_SPD
) ? "SPD " : "",
65 (status
& TD_CTRL_LS
) ? "LS " : "",
66 (status
& TD_CTRL_IOC
) ? "IOC " : "",
67 (status
& TD_CTRL_ACTIVE
) ? "Active " : "",
68 (status
& TD_CTRL_STALLED
) ? "Stalled " : "",
69 (status
& TD_CTRL_DBUFERR
) ? "DataBufErr " : "",
70 (status
& TD_CTRL_BABBLE
) ? "Babble " : "",
71 (status
& TD_CTRL_NAK
) ? "NAK " : "",
72 (status
& TD_CTRL_CRCTIMEO
) ? "CRC/Timeo " : "",
73 (status
& TD_CTRL_BITSTUFF
) ? "BitStuff " : "",
77 switch (uhci_packetid(token
)) {
92 out
+= sprintf(out
, "MaxLen=%x DT%d EndPt=%x Dev=%x, PID=%x(%s) ",
99 out
+= sprintf(out
, "(buf=%08x)\n", le32_to_cpu(td
->buffer
));
104 static int uhci_show_qh(struct uhci_qh
*qh
, char *buf
, int len
, int space
)
107 struct urb_priv
*urbp
;
108 struct list_head
*head
, *tmp
;
110 int i
= 0, checked
= 0, prevactive
= 0;
112 /* Try to make sure there's enough memory */
116 out
+= sprintf(out
, "%*s[%p] link (%08x) element (%08x)\n", space
, "",
117 qh
, le32_to_cpu(qh
->link
), le32_to_cpu(qh
->element
));
119 if (qh
->element
& UHCI_PTR_QH
)
120 out
+= sprintf(out
, "%*s Element points to QH (bug?)\n", space
, "");
122 if (qh
->element
& UHCI_PTR_DEPTH
)
123 out
+= sprintf(out
, "%*s Depth traverse\n", space
, "");
125 if (qh
->element
& cpu_to_le32(8))
126 out
+= sprintf(out
, "%*s Bit 3 set (bug?)\n", space
, "");
128 if (!(qh
->element
& ~(UHCI_PTR_QH
| UHCI_PTR_DEPTH
)))
129 out
+= sprintf(out
, "%*s Element is NULL (bug?)\n", space
, "");
132 out
+= sprintf(out
, "%*s urbp == NULL\n", space
, "");
138 head
= &urbp
->td_list
;
141 td
= list_entry(tmp
, struct uhci_td
, list
);
143 if (cpu_to_le32(td
->dma_handle
) != (qh
->element
& ~UHCI_PTR_BITS
))
144 out
+= sprintf(out
, "%*s Element != First TD\n", space
, "");
146 while (tmp
!= head
) {
147 struct uhci_td
*td
= list_entry(tmp
, struct uhci_td
, list
);
151 out
+= sprintf(out
, "%*s%d: ", space
+ 2, "", i
++);
152 out
+= uhci_show_td(td
, out
, len
- (out
- buf
), 0);
154 if (i
> 10 && !checked
&& prevactive
&& tmp
!= head
&&
156 struct list_head
*ntmp
= tmp
;
157 struct uhci_td
*ntd
= td
;
158 int active
= 1, ni
= i
;
162 while (ntmp
!= head
&& ntmp
->next
!= head
&& active
) {
163 ntd
= list_entry(ntmp
, struct uhci_td
, list
);
167 active
= td_status(ntd
) & TD_CTRL_ACTIVE
;
172 if (active
&& ni
> i
) {
173 out
+= sprintf(out
, "%*s[skipped %d active TD's]\n", space
, "", ni
- i
);
180 prevactive
= td_status(td
) & TD_CTRL_ACTIVE
;
183 if (list_empty(&urbp
->queue_list
) || urbp
->queued
)
186 out
+= sprintf(out
, "%*sQueued QH's:\n", -space
, "--");
188 head
= &urbp
->queue_list
;
191 while (tmp
!= head
) {
192 struct urb_priv
*nurbp
= list_entry(tmp
, struct urb_priv
,
196 out
+= uhci_show_qh(nurbp
->qh
, out
, len
- (out
- buf
), space
);
203 #define show_frame_num() \
206 out += sprintf(out, "- Frame %d\n", i); \
209 #ifdef CONFIG_PROC_FS
210 static const char *qh_names
[] = {
211 "skel_int128_qh", "skel_int64_qh",
212 "skel_int32_qh", "skel_int16_qh",
213 "skel_int8_qh", "skel_int4_qh",
214 "skel_int2_qh", "skel_int1_qh",
215 "skel_ls_control_qh", "skel_fs_control_qh",
216 "skel_bulk_qh", "skel_term_qh"
219 #define show_qh_name() \
222 out += sprintf(out, "- %s\n", qh_names[i]); \
225 static int uhci_show_sc(int port
, unsigned short status
, char *buf
, int len
)
229 /* Try to make sure there's enough memory */
233 out
+= sprintf(out
, " stat%d = %04x %s%s%s%s%s%s%s%s%s%s\n",
236 (status
& USBPORTSC_SUSP
) ? " Suspend" : "",
237 (status
& USBPORTSC_OCC
) ? " OverCurrentChange" : "",
238 (status
& USBPORTSC_OC
) ? " OverCurrent" : "",
239 (status
& USBPORTSC_PR
) ? " Reset" : "",
240 (status
& USBPORTSC_LSDA
) ? " LowSpeed" : "",
241 (status
& USBPORTSC_RD
) ? " ResumeDetect" : "",
242 (status
& USBPORTSC_PEC
) ? " EnableChange" : "",
243 (status
& USBPORTSC_PE
) ? " Enabled" : "",
244 (status
& USBPORTSC_CSC
) ? " ConnectChange" : "",
245 (status
& USBPORTSC_CCS
) ? " Connected" : "");
250 static int uhci_show_status(struct uhci_hcd
*uhci
, char *buf
, int len
)
253 unsigned int io_addr
= uhci
->io_addr
;
254 unsigned short usbcmd
, usbstat
, usbint
, usbfrnum
;
255 unsigned int flbaseadd
;
257 unsigned short portsc1
, portsc2
;
259 /* Try to make sure there's enough memory */
263 usbcmd
= inw(io_addr
+ 0);
264 usbstat
= inw(io_addr
+ 2);
265 usbint
= inw(io_addr
+ 4);
266 usbfrnum
= inw(io_addr
+ 6);
267 flbaseadd
= inl(io_addr
+ 8);
268 sof
= inb(io_addr
+ 12);
269 portsc1
= inw(io_addr
+ 16);
270 portsc2
= inw(io_addr
+ 18);
272 out
+= sprintf(out
, " usbcmd = %04x %s%s%s%s%s%s%s%s\n",
274 (usbcmd
& USBCMD_MAXP
) ? "Maxp64 " : "Maxp32 ",
275 (usbcmd
& USBCMD_CF
) ? "CF " : "",
276 (usbcmd
& USBCMD_SWDBG
) ? "SWDBG " : "",
277 (usbcmd
& USBCMD_FGR
) ? "FGR " : "",
278 (usbcmd
& USBCMD_EGSM
) ? "EGSM " : "",
279 (usbcmd
& USBCMD_GRESET
) ? "GRESET " : "",
280 (usbcmd
& USBCMD_HCRESET
) ? "HCRESET " : "",
281 (usbcmd
& USBCMD_RS
) ? "RS " : "");
283 out
+= sprintf(out
, " usbstat = %04x %s%s%s%s%s%s\n",
285 (usbstat
& USBSTS_HCH
) ? "HCHalted " : "",
286 (usbstat
& USBSTS_HCPE
) ? "HostControllerProcessError " : "",
287 (usbstat
& USBSTS_HSE
) ? "HostSystemError " : "",
288 (usbstat
& USBSTS_RD
) ? "ResumeDetect " : "",
289 (usbstat
& USBSTS_ERROR
) ? "USBError " : "",
290 (usbstat
& USBSTS_USBINT
) ? "USBINT " : "");
292 out
+= sprintf(out
, " usbint = %04x\n", usbint
);
293 out
+= sprintf(out
, " usbfrnum = (%d)%03x\n", (usbfrnum
>> 10) & 1,
294 0xfff & (4*(unsigned int)usbfrnum
));
295 out
+= sprintf(out
, " flbaseadd = %08x\n", flbaseadd
);
296 out
+= sprintf(out
, " sof = %02x\n", sof
);
297 out
+= uhci_show_sc(1, portsc1
, out
, len
- (out
- buf
));
298 out
+= uhci_show_sc(2, portsc2
, out
, len
- (out
- buf
));
303 static int uhci_show_urbp(struct uhci_hcd
*uhci
, struct urb_priv
*urbp
, char *buf
, int len
)
305 struct list_head
*tmp
;
312 out
+= sprintf(out
, "urb_priv [%p] ", urbp
);
313 out
+= sprintf(out
, "urb [%p] ", urbp
->urb
);
314 out
+= sprintf(out
, "qh [%p] ", urbp
->qh
);
315 out
+= sprintf(out
, "Dev=%d ", usb_pipedevice(urbp
->urb
->pipe
));
316 out
+= sprintf(out
, "EP=%x(%s) ", usb_pipeendpoint(urbp
->urb
->pipe
), (usb_pipein(urbp
->urb
->pipe
) ? "IN" : "OUT"));
318 switch (usb_pipetype(urbp
->urb
->pipe
)) {
319 case PIPE_ISOCHRONOUS
: out
+= sprintf(out
, "ISO "); break;
320 case PIPE_INTERRUPT
: out
+= sprintf(out
, "INT "); break;
321 case PIPE_BULK
: out
+= sprintf(out
, "BLK "); break;
322 case PIPE_CONTROL
: out
+= sprintf(out
, "CTL "); break;
325 out
+= sprintf(out
, "%s", (urbp
->fsbr
? "FSBR " : ""));
326 out
+= sprintf(out
, "%s", (urbp
->fsbr_timeout
? "FSBR_TO " : ""));
328 if (urbp
->urb
->status
!= -EINPROGRESS
)
329 out
+= sprintf(out
, "Status=%d ", urbp
->urb
->status
);
330 //out += sprintf(out, "Inserttime=%lx ",urbp->inserttime);
331 //out += sprintf(out, "FSBRtime=%lx ",urbp->fsbrtime);
334 list_for_each(tmp
, &urbp
->td_list
)
336 out
+= sprintf(out
, "TDs=%d ",count
);
339 out
+= sprintf(out
, "queued\n");
342 list_for_each(tmp
, &urbp
->queue_list
)
344 out
+= sprintf(out
, "queued URBs=%d\n", count
);
350 static int uhci_show_lists(struct uhci_hcd
*uhci
, char *buf
, int len
)
353 struct list_head
*head
, *tmp
;
356 out
+= sprintf(out
, "Main list URBs:");
357 if (list_empty(&uhci
->urb_list
))
358 out
+= sprintf(out
, " Empty\n");
360 out
+= sprintf(out
, "\n");
362 head
= &uhci
->urb_list
;
364 while (tmp
!= head
) {
365 struct urb_priv
*urbp
= list_entry(tmp
, struct urb_priv
, urb_list
);
367 out
+= sprintf(out
, " %d: ", ++count
);
368 out
+= uhci_show_urbp(uhci
, urbp
, out
, len
- (out
- buf
));
373 out
+= sprintf(out
, "Remove list URBs:");
374 if (list_empty(&uhci
->urb_remove_list
))
375 out
+= sprintf(out
, " Empty\n");
377 out
+= sprintf(out
, "\n");
379 head
= &uhci
->urb_remove_list
;
381 while (tmp
!= head
) {
382 struct urb_priv
*urbp
= list_entry(tmp
, struct urb_priv
, urb_list
);
384 out
+= sprintf(out
, " %d: ", ++count
);
385 out
+= uhci_show_urbp(uhci
, urbp
, out
, len
- (out
- buf
));
390 out
+= sprintf(out
, "Complete list URBs:");
391 if (list_empty(&uhci
->complete_list
))
392 out
+= sprintf(out
, " Empty\n");
394 out
+= sprintf(out
, "\n");
396 head
= &uhci
->complete_list
;
398 while (tmp
!= head
) {
399 struct urb_priv
*urbp
= list_entry(tmp
, struct urb_priv
, urb_list
);
401 out
+= sprintf(out
, " %d: ", ++count
);
402 out
+= uhci_show_urbp(uhci
, urbp
, out
, len
- (out
- buf
));
410 static int uhci_sprint_schedule(struct uhci_hcd
*uhci
, char *buf
, int len
)
417 struct list_head
*tmp
, *head
;
419 spin_lock_irqsave(&uhci
->schedule_lock
, flags
);
421 out
+= sprintf(out
, "HC status\n");
422 out
+= uhci_show_status(uhci
, out
, len
- (out
- buf
));
424 out
+= sprintf(out
, "Frame List\n");
425 for (i
= 0; i
< UHCI_NUMFRAMES
; ++i
) {
427 td
= uhci
->fl
->frame_cpu
[i
];
431 if (td
->dma_handle
!= (dma_addr_t
)uhci
->fl
->frame
[i
]) {
433 out
+= sprintf(out
, " frame list does not match td->dma_handle!\n");
440 td
= list_entry(tmp
, struct uhci_td
, fl_list
);
442 out
+= uhci_show_td(td
, out
, len
- (out
- buf
), 4);
443 } while (tmp
!= head
);
446 out
+= sprintf(out
, "Skeleton QH's\n");
448 for (i
= 0; i
< UHCI_NUM_SKELQH
; ++i
) {
451 qh
= uhci
->skelqh
[i
];
455 out
+= uhci_show_qh(qh
, out
, len
- (out
- buf
), 4);
458 /* Last QH is the Terminating QH, it's different */
459 if (i
== UHCI_NUM_SKELQH
- 1) {
460 if (qh
->link
!= UHCI_PTR_TERM
)
461 out
+= sprintf(out
, " bandwidth reclamation on!\n");
463 if (qh
->element
!= cpu_to_le32(uhci
->term_td
->dma_handle
))
464 out
+= sprintf(out
, " skel_term_qh element is not set to term_td!\n");
469 j
= (i
< 7) ? 7 : i
+1; /* Next skeleton */
470 if (list_empty(&qh
->list
)) {
471 if (i
< UHCI_NUM_SKELQH
- 1) {
473 (cpu_to_le32(uhci
->skelqh
[j
]->dma_handle
) | UHCI_PTR_QH
)) {
475 out
+= sprintf(out
, " skeleton QH not linked to next skeleton QH!\n");
487 while (tmp
!= head
) {
488 qh
= list_entry(tmp
, struct uhci_qh
, list
);
492 out
+= uhci_show_qh(qh
, out
, len
- (out
- buf
), 4);
495 if (i
< UHCI_NUM_SKELQH
- 1) {
497 (cpu_to_le32(uhci
->skelqh
[j
]->dma_handle
) | UHCI_PTR_QH
))
498 out
+= sprintf(out
, " last QH not linked to next skeleton!\n");
503 out
+= uhci_show_lists(uhci
, out
, len
- (out
- buf
));
505 spin_unlock_irqrestore(&uhci
->schedule_lock
, flags
);
510 #define MAX_OUTPUT (64 * 1024)
512 static struct proc_dir_entry
*uhci_proc_root
= NULL
;
517 struct uhci_hcd
*uhci
;
520 static int uhci_proc_open(struct inode
*inode
, struct file
*file
)
522 const struct proc_dir_entry
*dp
= PDE(inode
);
523 struct uhci_hcd
*uhci
= dp
->data
;
524 struct uhci_proc
*up
;
528 up
= kmalloc(sizeof(*up
), GFP_KERNEL
);
532 up
->data
= kmalloc(MAX_OUTPUT
, GFP_KERNEL
);
538 up
->size
= uhci_sprint_schedule(uhci
, up
->data
, MAX_OUTPUT
);
540 file
->private_data
= up
;
548 static loff_t
uhci_proc_lseek(struct file
*file
, loff_t off
, int whence
)
550 struct uhci_proc
*up
;
554 up
= file
->private_data
;
561 new = file
->f_pos
+ off
;
564 if (new < 0 || new > up
->size
) {
569 return (file
->f_pos
= new);
572 static ssize_t
uhci_proc_read(struct file
*file
, char *buf
, size_t nbytes
,
575 struct uhci_proc
*up
= file
->private_data
;
585 if (pos
+ nbytes
> size
)
588 if (!access_ok(VERIFY_WRITE
, buf
, nbytes
))
591 if (copy_to_user(buf
, up
->data
+ pos
, nbytes
))
599 static int uhci_proc_release(struct inode
*inode
, struct file
*file
)
601 struct uhci_proc
*up
= file
->private_data
;
609 static struct file_operations uhci_proc_operations
= {
610 .open
= uhci_proc_open
,
611 .llseek
= uhci_proc_lseek
,
612 .read
= uhci_proc_read
,
613 // write: uhci_proc_write,
614 .release
= uhci_proc_release
,