1 #ifdef DEBUG
uhci_show_qh(puhci_desc_t qh)2 static void __attribute__((__unused__)) uhci_show_qh (puhci_desc_t qh)
3 {
4 	if (qh->type != QH_TYPE) {
5 		dbg("qh has not QH_TYPE");
6 		return;
7 	}
8 	dbg("QH @ %p/%08llX:", qh, (unsigned long long)qh->dma_addr);
9 
10 	if (qh->hw.qh.head & UHCI_PTR_TERM)
11 		dbg("    Head Terminate");
12 	else
13 		dbg("    Head: %s @ %08X",
14 		    (qh->hw.qh.head & UHCI_PTR_QH?"QH":"TD"),
15 		    qh->hw.qh.head & ~UHCI_PTR_BITS);
16 
17 	if (qh->hw.qh.element & UHCI_PTR_TERM)
18 		dbg("    Element Terminate");
19 	else
20 		dbg("    Element: %s @ %08X",
21 		    (qh->hw.qh.element & UHCI_PTR_QH?"QH":"TD"),
22 		    qh->hw.qh.element & ~UHCI_PTR_BITS);
23 }
24 #endif
25 
26 #if 0
27 static void uhci_show_td (puhci_desc_t td)
28 {
29 	char *spid;
30 
31 	switch (td->hw.td.info & 0xff) {
32 	case USB_PID_SETUP:
33 		spid = "SETUP";
34 		break;
35 	case USB_PID_OUT:
36 		spid = " OUT ";
37 		break;
38 	case USB_PID_IN:
39 		spid = " IN  ";
40 		break;
41 	default:
42 		spid = "  ?  ";
43 		break;
44 	}
45 
46 	warn("  TD @ %p/%08X, MaxLen=%02x DT%d EP=%x Dev=%x PID=(%s) buf=%08x",
47 	     td, td->dma_addr,
48 	     td->hw.td.info >> 21,
49 	     ((td->hw.td.info >> 19) & 1),
50 	     (td->hw.td.info >> 15) & 15,
51 	     (td->hw.td.info >> 8) & 127,
52 	     spid,
53 	     td->hw.td.buffer);
54 
55 	warn("    Len=%02x e%d %s%s%s%s%s%s%s%s%s%s",
56 	     td->hw.td.status & 0x7ff,
57 	     ((td->hw.td.status >> 27) & 3),
58 	     (td->hw.td.status & TD_CTRL_SPD) ? "SPD " : "",
59 	     (td->hw.td.status & TD_CTRL_LS) ? "LS " : "",
60 	     (td->hw.td.status & TD_CTRL_IOC) ? "IOC " : "",
61 	     (td->hw.td.status & TD_CTRL_ACTIVE) ? "Active " : "",
62 	     (td->hw.td.status & TD_CTRL_STALLED) ? "Stalled " : "",
63 	     (td->hw.td.status & TD_CTRL_DBUFERR) ? "DataBufErr " : "",
64 	     (td->hw.td.status & TD_CTRL_BABBLE) ? "Babble " : "",
65 	     (td->hw.td.status & TD_CTRL_NAK) ? "NAK " : "",
66 	     (td->hw.td.status & TD_CTRL_CRCTIMEO) ? "CRC/Timeo " : "",
67 	     (td->hw.td.status & TD_CTRL_BITSTUFF) ? "BitStuff " : ""
68 		);
69 
70 	if (td->hw.td.link & UHCI_PTR_TERM)
71 		warn("   TD Link Terminate");
72 	else
73 		warn("    Link points to %s @ %08x, %s",
74 		     (td->hw.td.link & UHCI_PTR_QH?"QH":"TD"),
75 		     td->hw.td.link & ~UHCI_PTR_BITS,
76 		     (td->hw.td.link & UHCI_PTR_DEPTH ? "Depth first" : "Breadth first"));
77 }
78 #endif
79 
80 #ifdef DEBUG
uhci_show_td_queue(puhci_desc_t td)81 static void __attribute__((__unused__)) uhci_show_td_queue (puhci_desc_t td)
82 {
83 	//dbg("uhci_show_td_queue %p (%08lX):", td, td->dma_addr);
84 #if 1
85 	return;
86 #else
87 	while (1) {
88 		uhci_show_td (td);
89 		if (td->hw.td.link & UHCI_PTR_TERM)
90 			break;
91 		if (td != bus_to_virt (td->hw.td.link & ~UHCI_PTR_BITS))
92 			td = bus_to_virt (td->hw.td.link & ~UHCI_PTR_BITS);
93 		else {
94 			dbg("td points to itself!");
95 			break;
96 		}
97 	}
98 #endif
99 }
100 
uhci_show_queue(puhci_desc_t qh)101 static void __attribute__((__unused__)) uhci_show_queue (puhci_desc_t qh)
102 {
103 #if 0
104 	uhci_desc_t *start_qh=qh;
105 #endif
106 
107 	dbg("uhci_show_queue %p:", qh);
108 #if 1
109 	return;
110 #else
111 	while (1) {
112 		uhci_show_qh (qh);
113 
114 		if (!(qh->hw.qh.element & UHCI_PTR_TERM))
115 			uhci_show_td_queue (bus_to_virt (qh->hw.qh.element & ~UHCI_PTR_BITS));
116 
117 		if (qh->hw.qh.head & UHCI_PTR_TERM)
118 			break;
119 
120 		if (qh != bus_to_virt (qh->hw.qh.head & ~UHCI_PTR_BITS))
121 			qh = bus_to_virt (qh->hw.qh.head & ~UHCI_PTR_BITS);
122 		else {
123 			dbg("qh points to itself!");
124 			break;
125 		}
126 
127 		if (qh==start_qh) { // avoid loop
128 			dbg("Loop detect");
129 			break;
130 		}
131 	}
132 #endif
133 }
134 
uhci_show_sc(int port,unsigned short status)135 static void __attribute__((__unused__)) uhci_show_sc (int port, unsigned short status)
136 {
137 	dbg("  stat%d     =     %04x   %s%s%s%s%s%s%s%s",
138 	     port,
139 	     status,
140 	     (status & USBPORTSC_SUSP) ? "PortSuspend " : "",
141 	     (status & USBPORTSC_PR) ? "PortReset " : "",
142 	     (status & USBPORTSC_LSDA) ? "LowSpeed " : "",
143 	     (status & USBPORTSC_RD) ? "ResumeDetect " : "",
144 	     (status & USBPORTSC_PEC) ? "EnableChange " : "",
145 	     (status & USBPORTSC_PE) ? "PortEnabled " : "",
146 	     (status & USBPORTSC_CSC) ? "ConnectChange " : "",
147 	     (status & USBPORTSC_CCS) ? "PortConnected " : "");
148 }
149 
uhci_show_status(puhci_t s)150 void uhci_show_status (puhci_t s)
151 {
152 	unsigned int io_addr = s->io_addr;
153 	unsigned short usbcmd, usbstat, usbint, usbfrnum;
154 	unsigned int flbaseadd;
155 	unsigned char sof;
156 	unsigned short portsc1, portsc2;
157 
158 	usbcmd = inw (io_addr + 0);
159 	usbstat = inw (io_addr + 2);
160 	usbint = inw (io_addr + 4);
161 	usbfrnum = inw (io_addr + 6);
162 	flbaseadd = inl (io_addr + 8);
163 	sof = inb (io_addr + 12);
164 	portsc1 = inw (io_addr + 16);
165 	portsc2 = inw (io_addr + 18);
166 
167 	dbg("  usbcmd    =     %04x   %s%s%s%s%s%s%s%s",
168 	     usbcmd,
169 	     (usbcmd & USBCMD_MAXP) ? "Maxp64 " : "Maxp32 ",
170 	     (usbcmd & USBCMD_CF) ? "CF " : "",
171 	     (usbcmd & USBCMD_SWDBG) ? "SWDBG " : "",
172 	     (usbcmd & USBCMD_FGR) ? "FGR " : "",
173 	     (usbcmd & USBCMD_EGSM) ? "EGSM " : "",
174 	     (usbcmd & USBCMD_GRESET) ? "GRESET " : "",
175 	     (usbcmd & USBCMD_HCRESET) ? "HCRESET " : "",
176 	     (usbcmd & USBCMD_RS) ? "RS " : "");
177 
178 	dbg("  usbstat   =     %04x   %s%s%s%s%s%s",
179 	     usbstat,
180 	     (usbstat & USBSTS_HCH) ? "HCHalted " : "",
181 	     (usbstat & USBSTS_HCPE) ? "HostControllerProcessError " : "",
182 	     (usbstat & USBSTS_HSE) ? "HostSystemError " : "",
183 	     (usbstat & USBSTS_RD) ? "ResumeDetect " : "",
184 	     (usbstat & USBSTS_ERROR) ? "USBError " : "",
185 	     (usbstat & USBSTS_USBINT) ? "USBINT " : "");
186 
187 	dbg("  usbint    =     %04x", usbint);
188 	dbg("  usbfrnum  =   (%d)%03x", (usbfrnum >> 10) & 1,
189 	     0xfff & (4 * (unsigned int) usbfrnum));
190 	dbg("  flbaseadd = %08x", flbaseadd);
191 	dbg("  sof       =       %02x", sof);
192 	uhci_show_sc (1, portsc1);
193 	uhci_show_sc (2, portsc2);
194 }
195 #endif
196