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>
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 inline int uhci_is_skeleton_qh(struct uhci_hcd
*uhci
, struct uhci_qh
*qh
)
41 for (i
= 0; i
< UHCI_NUM_SKELQH
; i
++)
42 if (qh
== uhci
->skelqh
[i
])
48 static int uhci_show_td(struct uhci_td
*td
, char *buf
, int len
, int space
)
54 /* Try to make sure there's enough memory */
58 status
= td_status(td
);
59 out
+= sprintf(out
, "%*s[%p] link (%08x) ", space
, "", td
, le32_to_cpu(td
->link
));
60 out
+= sprintf(out
, "e%d %s%s%s%s%s%s%s%s%s%sLength=%x ",
62 (status
& TD_CTRL_SPD
) ? "SPD " : "",
63 (status
& TD_CTRL_LS
) ? "LS " : "",
64 (status
& TD_CTRL_IOC
) ? "IOC " : "",
65 (status
& TD_CTRL_ACTIVE
) ? "Active " : "",
66 (status
& TD_CTRL_STALLED
) ? "Stalled " : "",
67 (status
& TD_CTRL_DBUFERR
) ? "DataBufErr " : "",
68 (status
& TD_CTRL_BABBLE
) ? "Babble " : "",
69 (status
& TD_CTRL_NAK
) ? "NAK " : "",
70 (status
& TD_CTRL_CRCTIMEO
) ? "CRC/Timeo " : "",
71 (status
& TD_CTRL_BITSTUFF
) ? "BitStuff " : "",
75 switch (uhci_packetid(token
)) {
90 out
+= sprintf(out
, "MaxLen=%x DT%d EndPt=%x Dev=%x, PID=%x(%s) ",
97 out
+= sprintf(out
, "(buf=%08x)\n", le32_to_cpu(td
->buffer
));
102 static int uhci_show_qh(struct uhci_qh
*qh
, char *buf
, int len
, int space
)
105 struct urb_priv
*urbp
;
106 struct list_head
*head
, *tmp
;
108 int i
= 0, checked
= 0, prevactive
= 0;
110 /* Try to make sure there's enough memory */
114 out
+= sprintf(out
, "%*s[%p] link (%08x) element (%08x)\n", space
, "",
115 qh
, le32_to_cpu(qh
->link
), le32_to_cpu(qh
->element
));
117 if (qh
->element
& UHCI_PTR_QH
)
118 out
+= sprintf(out
, "%*s Element points to QH (bug?)\n", space
, "");
120 if (qh
->element
& UHCI_PTR_DEPTH
)
121 out
+= sprintf(out
, "%*s Depth traverse\n", space
, "");
123 if (qh
->element
& cpu_to_le32(8))
124 out
+= sprintf(out
, "%*s Bit 3 set (bug?)\n", space
, "");
126 if (!(qh
->element
& ~(UHCI_PTR_QH
| UHCI_PTR_DEPTH
)))
127 out
+= sprintf(out
, "%*s Element is NULL (bug?)\n", space
, "");
130 out
+= sprintf(out
, "%*s urbp == NULL\n", space
, "");
136 head
= &urbp
->td_list
;
139 td
= list_entry(tmp
, struct uhci_td
, list
);
141 if (cpu_to_le32(td
->dma_handle
) != (qh
->element
& ~UHCI_PTR_BITS
))
142 out
+= sprintf(out
, "%*s Element != First TD\n", space
, "");
144 while (tmp
!= head
) {
145 struct uhci_td
*td
= list_entry(tmp
, struct uhci_td
, list
);
149 out
+= sprintf(out
, "%*s%d: ", space
+ 2, "", i
++);
150 out
+= uhci_show_td(td
, out
, len
- (out
- buf
), 0);
152 if (i
> 10 && !checked
&& prevactive
&& tmp
!= head
&&
154 struct list_head
*ntmp
= tmp
;
155 struct uhci_td
*ntd
= td
;
156 int active
= 1, ni
= i
;
160 while (ntmp
!= head
&& ntmp
->next
!= head
&& active
) {
161 ntd
= list_entry(ntmp
, struct uhci_td
, list
);
165 active
= td_status(ntd
) & TD_CTRL_ACTIVE
;
170 if (active
&& ni
> i
) {
171 out
+= sprintf(out
, "%*s[skipped %d active TD's]\n", space
, "", ni
- i
);
178 prevactive
= td_status(td
) & TD_CTRL_ACTIVE
;
181 if (list_empty(&urbp
->queue_list
) || urbp
->queued
)
184 out
+= sprintf(out
, "%*sQueued QH's:\n", -space
, "--");
186 head
= &urbp
->queue_list
;
189 while (tmp
!= head
) {
190 struct urb_priv
*nurbp
= list_entry(tmp
, struct urb_priv
,
194 out
+= uhci_show_qh(nurbp
->qh
, out
, len
- (out
- buf
), space
);
201 #define show_frame_num() \
204 out += sprintf(out, "- Frame %d\n", i); \
207 #ifdef CONFIG_PROC_FS
208 static const char *qh_names
[] = {
209 "skel_int128_qh", "skel_int64_qh",
210 "skel_int32_qh", "skel_int16_qh",
211 "skel_int8_qh", "skel_int4_qh",
212 "skel_int2_qh", "skel_int1_qh",
213 "skel_ls_control_qh", "skel_fs_control_qh",
214 "skel_bulk_qh", "skel_term_qh"
217 #define show_qh_name() \
220 out += sprintf(out, "- %s\n", qh_names[i]); \
223 static int uhci_show_sc(int port
, unsigned short status
, char *buf
, int len
)
227 /* Try to make sure there's enough memory */
231 out
+= sprintf(out
, " stat%d = %04x %s%s%s%s%s%s%s%s%s%s\n",
234 (status
& USBPORTSC_SUSP
) ? " Suspend" : "",
235 (status
& USBPORTSC_OCC
) ? " OverCurrentChange" : "",
236 (status
& USBPORTSC_OC
) ? " OverCurrent" : "",
237 (status
& USBPORTSC_PR
) ? " Reset" : "",
238 (status
& USBPORTSC_LSDA
) ? " LowSpeed" : "",
239 (status
& USBPORTSC_RD
) ? " ResumeDetect" : "",
240 (status
& USBPORTSC_PEC
) ? " EnableChange" : "",
241 (status
& USBPORTSC_PE
) ? " Enabled" : "",
242 (status
& USBPORTSC_CSC
) ? " ConnectChange" : "",
243 (status
& USBPORTSC_CCS
) ? " Connected" : "");
248 static int uhci_show_status(struct uhci_hcd
*uhci
, char *buf
, int len
)
251 unsigned long io_addr
= uhci
->io_addr
;
252 unsigned short usbcmd
, usbstat
, usbint
, usbfrnum
;
253 unsigned int flbaseadd
;
255 unsigned short portsc1
, portsc2
;
257 /* Try to make sure there's enough memory */
261 usbcmd
= inw(io_addr
+ 0);
262 usbstat
= inw(io_addr
+ 2);
263 usbint
= inw(io_addr
+ 4);
264 usbfrnum
= inw(io_addr
+ 6);
265 flbaseadd
= inl(io_addr
+ 8);
266 sof
= inb(io_addr
+ 12);
267 portsc1
= inw(io_addr
+ 16);
268 portsc2
= inw(io_addr
+ 18);
270 out
+= sprintf(out
, " usbcmd = %04x %s%s%s%s%s%s%s%s\n",
272 (usbcmd
& USBCMD_MAXP
) ? "Maxp64 " : "Maxp32 ",
273 (usbcmd
& USBCMD_CF
) ? "CF " : "",
274 (usbcmd
& USBCMD_SWDBG
) ? "SWDBG " : "",
275 (usbcmd
& USBCMD_FGR
) ? "FGR " : "",
276 (usbcmd
& USBCMD_EGSM
) ? "EGSM " : "",
277 (usbcmd
& USBCMD_GRESET
) ? "GRESET " : "",
278 (usbcmd
& USBCMD_HCRESET
) ? "HCRESET " : "",
279 (usbcmd
& USBCMD_RS
) ? "RS " : "");
281 out
+= sprintf(out
, " usbstat = %04x %s%s%s%s%s%s\n",
283 (usbstat
& USBSTS_HCH
) ? "HCHalted " : "",
284 (usbstat
& USBSTS_HCPE
) ? "HostControllerProcessError " : "",
285 (usbstat
& USBSTS_HSE
) ? "HostSystemError " : "",
286 (usbstat
& USBSTS_RD
) ? "ResumeDetect " : "",
287 (usbstat
& USBSTS_ERROR
) ? "USBError " : "",
288 (usbstat
& USBSTS_USBINT
) ? "USBINT " : "");
290 out
+= sprintf(out
, " usbint = %04x\n", usbint
);
291 out
+= sprintf(out
, " usbfrnum = (%d)%03x\n", (usbfrnum
>> 10) & 1,
292 0xfff & (4*(unsigned int)usbfrnum
));
293 out
+= sprintf(out
, " flbaseadd = %08x\n", flbaseadd
);
294 out
+= sprintf(out
, " sof = %02x\n", sof
);
295 out
+= uhci_show_sc(1, portsc1
, out
, len
- (out
- buf
));
296 out
+= uhci_show_sc(2, portsc2
, out
, len
- (out
- buf
));
301 static int uhci_show_urbp(struct uhci_hcd
*uhci
, struct urb_priv
*urbp
, char *buf
, int len
)
303 struct list_head
*tmp
;
310 out
+= sprintf(out
, "urb_priv [%p] ", urbp
);
311 out
+= sprintf(out
, "urb [%p] ", urbp
->urb
);
312 out
+= sprintf(out
, "qh [%p] ", urbp
->qh
);
313 out
+= sprintf(out
, "Dev=%d ", usb_pipedevice(urbp
->urb
->pipe
));
314 out
+= sprintf(out
, "EP=%x(%s) ", usb_pipeendpoint(urbp
->urb
->pipe
), (usb_pipein(urbp
->urb
->pipe
) ? "IN" : "OUT"));
316 switch (usb_pipetype(urbp
->urb
->pipe
)) {
317 case PIPE_ISOCHRONOUS
: out
+= sprintf(out
, "ISO "); break;
318 case PIPE_INTERRUPT
: out
+= sprintf(out
, "INT "); break;
319 case PIPE_BULK
: out
+= sprintf(out
, "BLK "); break;
320 case PIPE_CONTROL
: out
+= sprintf(out
, "CTL "); break;
323 out
+= sprintf(out
, "%s", (urbp
->fsbr
? "FSBR " : ""));
324 out
+= sprintf(out
, "%s", (urbp
->fsbr_timeout
? "FSBR_TO " : ""));
326 if (urbp
->urb
->status
!= -EINPROGRESS
)
327 out
+= sprintf(out
, "Status=%d ", urbp
->urb
->status
);
328 //out += sprintf(out, "Inserttime=%lx ",urbp->inserttime);
329 //out += sprintf(out, "FSBRtime=%lx ",urbp->fsbrtime);
332 list_for_each(tmp
, &urbp
->td_list
)
334 out
+= sprintf(out
, "TDs=%d ",count
);
337 out
+= sprintf(out
, "queued\n");
340 list_for_each(tmp
, &urbp
->queue_list
)
342 out
+= sprintf(out
, "queued URBs=%d\n", count
);
348 static int uhci_show_lists(struct uhci_hcd
*uhci
, char *buf
, int len
)
351 struct list_head
*head
, *tmp
;
354 out
+= sprintf(out
, "Main list URBs:");
355 if (list_empty(&uhci
->urb_list
))
356 out
+= sprintf(out
, " Empty\n");
358 out
+= sprintf(out
, "\n");
360 head
= &uhci
->urb_list
;
362 while (tmp
!= head
) {
363 struct urb_priv
*urbp
= list_entry(tmp
, struct urb_priv
, urb_list
);
365 out
+= sprintf(out
, " %d: ", ++count
);
366 out
+= uhci_show_urbp(uhci
, urbp
, out
, len
- (out
- buf
));
371 out
+= sprintf(out
, "Remove list URBs:");
372 if (list_empty(&uhci
->urb_remove_list
))
373 out
+= sprintf(out
, " Empty\n");
375 out
+= sprintf(out
, "\n");
377 head
= &uhci
->urb_remove_list
;
379 while (tmp
!= head
) {
380 struct urb_priv
*urbp
= list_entry(tmp
, struct urb_priv
, urb_list
);
382 out
+= sprintf(out
, " %d: ", ++count
);
383 out
+= uhci_show_urbp(uhci
, urbp
, out
, len
- (out
- buf
));
388 out
+= sprintf(out
, "Complete list URBs:");
389 if (list_empty(&uhci
->complete_list
))
390 out
+= sprintf(out
, " Empty\n");
392 out
+= sprintf(out
, "\n");
394 head
= &uhci
->complete_list
;
396 while (tmp
!= head
) {
397 struct urb_priv
*urbp
= list_entry(tmp
, struct urb_priv
, urb_list
);
399 out
+= sprintf(out
, " %d: ", ++count
);
400 out
+= uhci_show_urbp(uhci
, urbp
, out
, len
- (out
- buf
));
408 static int uhci_sprint_schedule(struct uhci_hcd
*uhci
, char *buf
, int len
)
415 struct list_head
*tmp
, *head
;
417 spin_lock_irqsave(&uhci
->schedule_lock
, flags
);
419 out
+= sprintf(out
, "HC status\n");
420 out
+= uhci_show_status(uhci
, out
, len
- (out
- buf
));
422 out
+= sprintf(out
, "Frame List\n");
423 for (i
= 0; i
< UHCI_NUMFRAMES
; ++i
) {
425 td
= uhci
->fl
->frame_cpu
[i
];
429 if (td
->dma_handle
!= (dma_addr_t
)uhci
->fl
->frame
[i
]) {
431 out
+= sprintf(out
, " frame list does not match td->dma_handle!\n");
438 td
= list_entry(tmp
, struct uhci_td
, fl_list
);
440 out
+= uhci_show_td(td
, out
, len
- (out
- buf
), 4);
441 } while (tmp
!= head
);
444 out
+= sprintf(out
, "Skeleton QH's\n");
446 for (i
= 0; i
< UHCI_NUM_SKELQH
; ++i
) {
449 qh
= uhci
->skelqh
[i
];
453 out
+= uhci_show_qh(qh
, out
, len
- (out
- buf
), 4);
456 /* Last QH is the Terminating QH, it's different */
457 if (i
== UHCI_NUM_SKELQH
- 1) {
458 if (qh
->link
!= UHCI_PTR_TERM
)
459 out
+= sprintf(out
, " bandwidth reclamation on!\n");
461 if (qh
->element
!= cpu_to_le32(uhci
->term_td
->dma_handle
))
462 out
+= sprintf(out
, " skel_term_qh element is not set to term_td!\n");
467 j
= (i
< 7) ? 7 : i
+1; /* Next skeleton */
468 if (list_empty(&qh
->list
)) {
469 if (i
< UHCI_NUM_SKELQH
- 1) {
471 (cpu_to_le32(uhci
->skelqh
[j
]->dma_handle
) | UHCI_PTR_QH
)) {
473 out
+= sprintf(out
, " skeleton QH not linked to next skeleton QH!\n");
485 while (tmp
!= head
) {
486 qh
= list_entry(tmp
, struct uhci_qh
, list
);
490 out
+= uhci_show_qh(qh
, out
, len
- (out
- buf
), 4);
493 if (i
< UHCI_NUM_SKELQH
- 1) {
495 (cpu_to_le32(uhci
->skelqh
[j
]->dma_handle
) | UHCI_PTR_QH
))
496 out
+= sprintf(out
, " last QH not linked to next skeleton!\n");
501 out
+= uhci_show_lists(uhci
, out
, len
- (out
- buf
));
503 spin_unlock_irqrestore(&uhci
->schedule_lock
, flags
);
508 #define MAX_OUTPUT (64 * 1024)
510 static struct proc_dir_entry
*uhci_proc_root
= NULL
;
515 struct uhci_hcd
*uhci
;
518 static int uhci_proc_open(struct inode
*inode
, struct file
*file
)
520 const struct proc_dir_entry
*dp
= PDE(inode
);
521 struct uhci_hcd
*uhci
= dp
->data
;
522 struct uhci_proc
*up
;
526 up
= kmalloc(sizeof(*up
), GFP_KERNEL
);
530 up
->data
= kmalloc(MAX_OUTPUT
, GFP_KERNEL
);
536 up
->size
= uhci_sprint_schedule(uhci
, up
->data
, MAX_OUTPUT
);
538 file
->private_data
= up
;
546 static loff_t
uhci_proc_lseek(struct file
*file
, loff_t off
, int whence
)
548 struct uhci_proc
*up
;
552 up
= file
->private_data
;
559 new = file
->f_pos
+ off
;
562 if (new < 0 || new > up
->size
) {
567 return (file
->f_pos
= new);
570 static ssize_t
uhci_proc_read(struct file
*file
, char __user
*buf
,
571 size_t nbytes
, loff_t
*ppos
)
573 struct uhci_proc
*up
= file
->private_data
;
574 return simple_read_from_buffer(buf
, nbytes
, ppos
, up
->data
, up
->size
);
577 static int uhci_proc_release(struct inode
*inode
, struct file
*file
)
579 struct uhci_proc
*up
= file
->private_data
;
587 static struct file_operations uhci_proc_operations
= {
588 .open
= uhci_proc_open
,
589 .llseek
= uhci_proc_lseek
,
590 .read
= uhci_proc_read
,
591 // write: uhci_proc_write,
592 .release
= uhci_proc_release
,