Import 2.3.4pre3
[davej-history.git] / drivers / usb / uhci-debug.c
blob7c577a58f7b93c670b0fc11c14bd96fff9f1e2af
1 /*
2 * UHCI-specific debugging code. Invaluable when something
3 * goes wrong, but don't get in my face.
5 * (C) Copyright 1999 Linus Torvalds
6 */
8 #include <linux/kernel.h>
9 #include <asm/io.h>
11 #include "uhci.h"
13 void show_td(struct uhci_td * td)
15 char *spid;
17 printk("%08x ", td->link);
18 printk("%se%d %s%s%s%s%s%s%s%s%s%sLength=%x ",
19 ((td->status >> 29) & 1) ? "SPD " : "",
20 ((td->status >> 27) & 3),
21 ((td->status >> 26) & 1) ? "LS " : "",
22 ((td->status >> 25) & 1) ? "IOS " : "",
23 ((td->status >> 24) & 1) ? "IOC " : "",
24 ((td->status >> 23) & 1) ? "Active " : "",
25 ((td->status >> 22) & 1) ? "Stalled " : "",
26 ((td->status >> 21) & 1) ? "DataBufErr " : "",
27 ((td->status >> 20) & 1) ? "Babble " : "",
28 ((td->status >> 19) & 1) ? "NAK " : "",
29 ((td->status >> 18) & 1) ? "CRC/Timeo " : "",
30 ((td->status >> 17) & 1) ? "BitStuff " : "",
31 td->status & 0x7ff);
32 switch (td->info & 0xff) {
33 case 0x2d:
34 spid = "SETUP";
35 break;
36 case 0xe1:
37 spid = "OUT";
38 break;
39 case 0x69:
40 spid = "IN";
41 break;
42 default:
43 spid = "?";
44 break;
46 printk("MaxLen=%x %sEndPt=%x Dev=%x, PID=%x(%s) ",
47 td->info >> 21,
48 ((td->info >> 19) & 1) ? "DT " : "",
49 (td->info >> 15) & 15,
50 (td->info >> 8) & 127,
51 (td->info & 0xff),
52 spid);
53 printk("(buf=%08x)\n", td->buffer);
56 static void show_sc(int port, unsigned short status)
58 printk(" stat%d = %04x %s%s%s%s%s%s%s%s\n",
59 port,
60 status,
61 (status & (1 << 12)) ? " PortSuspend" : "",
62 (status & (1 << 9)) ? " PortReset" : "",
63 (status & (1 << 8)) ? " LowSpeed" : "",
64 (status & 0x40) ? " ResumeDetect" : "",
65 (status & 0x08) ? " EnableChange" : "",
66 (status & 0x04) ? " PortEnabled" : "",
67 (status & 0x02) ? " ConnectChange" : "",
68 (status & 0x01) ? " PortConnected" : "");
71 void show_status(struct uhci *uhci)
73 unsigned int io_addr = uhci->io_addr;
74 unsigned short usbcmd, usbstat, usbint, usbfrnum;
75 unsigned int flbaseadd;
76 unsigned char sof;
77 unsigned short portsc1, portsc2;
79 usbcmd = inw(io_addr + 0);
80 usbstat = inw(io_addr + 2);
81 usbint = inw(io_addr + 4);
82 usbfrnum = inw(io_addr + 6);
83 flbaseadd = inl(io_addr + 8);
84 sof = inb(io_addr + 12);
85 portsc1 = inw(io_addr + 16);
86 portsc2 = inw(io_addr + 18);
88 printk(" usbcmd = %04x %s%s%s%s%s%s%s%s\n",
89 usbcmd,
90 (usbcmd & 0x80) ? " Maxp64" : " Maxp32",
91 (usbcmd & 0x40) ? " CF" : "",
92 (usbcmd & 0x20) ? " SWDBG" : "",
93 (usbcmd & 0x10) ? " FGR" : "",
94 (usbcmd & 0x08) ? " EGSM" : "",
95 (usbcmd & 0x04) ? " GRESET" : "",
96 (usbcmd & 0x02) ? " HCRESET" : "",
97 (usbcmd & 0x01) ? " RS" : "");
99 printk(" usbstat = %04x %s%s%s%s%s%s\n",
100 usbstat,
101 (usbstat & 0x20) ? " HCHalted" : "",
102 (usbstat & 0x10) ? " HostControllerProcessError" : "",
103 (usbstat & 0x08) ? " HostSystemError" : "",
104 (usbstat & 0x04) ? " ResumeDetect" : "",
105 (usbstat & 0x02) ? " USBError" : "",
106 (usbstat & 0x01) ? " USBINT" : "");
108 printk(" usbint = %04x\n", usbint);
109 printk(" usbfrnum = (%d)%03x\n", (usbfrnum >> 10) & 1, 0xfff & (4*(unsigned int)usbfrnum));
110 printk(" flbaseadd = %08x\n", flbaseadd);
111 printk(" sof = %02x\n", sof);
112 show_sc(1, portsc1);
113 show_sc(2, portsc2);
116 #define uhci_link_to_qh(x) ((struct uhci_qh *) uhci_link_to_td(x))
118 struct uhci_td * uhci_link_to_td(unsigned int link)
120 if (link & 1)
121 return NULL;
123 return bus_to_virt(link & ~15);
126 void show_queue(struct uhci_qh *qh)
128 struct uhci_td *td;
129 int i = 0;
131 #if 0
132 printk(" link = %p, element = %p\n", qh->link, qh->element);
133 #endif
134 if(!qh->element) {
135 printk(" td 0 = NULL\n");
136 return;
139 for(td = uhci_link_to_td(qh->element); td;
140 td = uhci_link_to_td(td->link)) {
141 printk(" td %d = %p\n", i++, td);
142 printk(" ");
143 show_td(td);
147 int is_skeleton_qh(struct uhci *uhci, struct uhci_qh *qh)
149 int j;
150 struct uhci_device * root_hub=usb_to_uhci(uhci->bus->root_hub);
151 for (j = 0; j < UHCI_MAXQH; j++)
152 if (qh == root_hub->qh + j)
153 return 1;
155 return 0;
158 static const char *qh_names[] = {"isochronous", "interrupt2", "interrupt4",
159 "interrupt8", "interrupt16", "interrupt32",
160 "interrupt64", "interrupt128", "interrupt256",
161 "control", "bulk0", "bulk1", "bulk2", "bulk3",
162 "unused", "unused"};
164 void show_queues(struct uhci *uhci)
166 int i;
167 struct uhci_qh *qh;
168 struct uhci_device * root_hub=usb_to_uhci(uhci->bus->root_hub);
170 for (i = 0; i < UHCI_MAXQH; ++i) {
171 printk(" %s:\n", qh_names[i]);
172 #if 0
173 printk(" qh #%d, %p\n", i, virt_to_bus(root_hub->qh + i));
174 show_queue(uhci->root_hub->qh + i);
175 #endif
177 qh = uhci_link_to_qh(root_hub->qh[i].link);
178 for (; qh; qh = uhci_link_to_qh(qh->link)) {
179 if (is_skeleton_qh(uhci, qh))
180 break;
182 show_queue(qh);