9 #include <sys/kernel.h>
10 #include <sys/endian.h>
13 #include <sys/lockmgr.h>
15 #include <machine/bus.h>
16 #include <machine/endian.h>
18 #include <dev/usb/usb.h>
19 #include <dev/usb/usbdi.h>
20 #include <dev/usb/usbdivar.h>
22 #include <dev/usb/ehcireg.h>
23 #include <dev/usb/ehcivar.h>
27 #include <ddb/db_sym.h>
29 #define db_printf printf
32 extern ehci_softc_t *theehci; /* XXX */
35 ehci_dump_regs(ehci_softc_t *sc)
38 db_printf("cmd=0x%08x, sts=0x%08x, ien=0x%08x\n",
39 EOREAD4(sc, EHCI_USBCMD),
40 EOREAD4(sc, EHCI_USBSTS),
41 EOREAD4(sc, EHCI_USBINTR));
42 db_printf("frindex=0x%08x ctrdsegm=0x%08x periodic=0x%08x async=0x%08x\n",
43 EOREAD4(sc, EHCI_FRINDEX),
44 EOREAD4(sc, EHCI_CTRLDSSEGMENT),
45 EOREAD4(sc, EHCI_PERIODICLISTBASE),
46 EOREAD4(sc, EHCI_ASYNCLISTADDR));
47 for (i = 1; i <= sc->sc_noport; i++)
48 db_printf("port %d status=0x%08x\n", i,
49 EOREAD4(sc, EHCI_PORTSC(i)));
53 ehci_dump_link(ehci_softc_t *sc, ehci_link_t link, int type)
55 link = hc32toh(sc, link);
56 db_printf("0x%08x", link);
57 if (link & EHCI_LINK_TERMINATE)
62 switch (EHCI_LINK_TYPE(link)) {
63 case EHCI_LINK_ITD: db_printf("ITD"); break;
64 case EHCI_LINK_QH: db_printf("QH"); break;
65 case EHCI_LINK_SITD: db_printf("SITD"); break;
66 case EHCI_LINK_FSTN: db_printf("FSTN"); break;
74 ehci_dump_sqtds(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd)
80 for (i = 0; sqtd && i < 20 && !stop; sqtd = sqtd->nextqtd, i++) {
81 ehci_dump_sqtd(sc, sqtd);
82 stop = sqtd->qtd.qtd_next & htohc32(sc, EHCI_LINK_TERMINATE);
85 db_printf("dump aborted, too many TDs\n");
89 ehci_dump_qtd(ehci_softc_t *sc, ehci_qtd_t *qtd)
93 db_printf(" next="); ehci_dump_link(sc, qtd->qtd_next, 0);
94 db_printf(" altnext="); ehci_dump_link(sc, qtd->qtd_altnext, 0);
96 s = hc32toh(sc, qtd->qtd_status);
97 db_printf(" status=0x%08x: toggle=%d bytes=0x%x ioc=%d c_page=0x%x\n",
98 s, EHCI_QTD_GET_TOGGLE(s), EHCI_QTD_GET_BYTES(s),
99 EHCI_QTD_GET_IOC(s), EHCI_QTD_GET_C_PAGE(s));
100 db_printf(" cerr=%d pid=%d stat=%b\n", EHCI_QTD_GET_CERR(s),
102 EHCI_QTD_GET_STATUS(s), EHCI_QTD_STATUS_BITS);
103 for (s = 0; s < 5; s++)
104 db_printf(" buffer[%d]=0x%08x\n", s, hc32toh(sc, qtd->qtd_buffer[s]));
108 ehci_dump_sqtd(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd)
110 db_printf("QTD(%p) at 0x%08x:\n", sqtd, sqtd->physaddr);
111 ehci_dump_qtd(sc, &sqtd->qtd);
115 ehci_dump_sqh(ehci_softc_t *sc, ehci_soft_qh_t *sqh)
117 ehci_qh_t *qh = &sqh->qh;
118 u_int32_t endp, endphub;
120 db_printf("QH(%p) at 0x%08x:\n", sqh, sqh->physaddr);
121 db_printf(" sqtd=%p inactivesqtd=%p\n", sqh->sqtd, sqh->inactivesqtd);
122 db_printf(" link="); ehci_dump_link(sc, qh->qh_link, 1); db_printf("\n");
123 endp = hc32toh(sc, qh->qh_endp);
124 db_printf(" endp=0x%08x\n", endp);
125 db_printf(" addr=0x%02x inact=%d endpt=%d eps=%d dtc=%d hrecl=%d\n",
126 EHCI_QH_GET_ADDR(endp), EHCI_QH_GET_INACT(endp),
127 EHCI_QH_GET_ENDPT(endp), EHCI_QH_GET_EPS(endp),
128 EHCI_QH_GET_DTC(endp), EHCI_QH_GET_HRECL(endp));
129 db_printf(" mpl=0x%x ctl=%d nrl=%d\n",
130 EHCI_QH_GET_MPL(endp), EHCI_QH_GET_CTL(endp),
131 EHCI_QH_GET_NRL(endp));
132 endphub = hc32toh(sc, qh->qh_endphub);
133 db_printf(" endphub=0x%08x\n", endphub);
134 db_printf(" smask=0x%02x cmask=0x%02x huba=0x%02x port=%d mult=%d\n",
135 EHCI_QH_GET_SMASK(endphub), EHCI_QH_GET_CMASK(endphub),
136 EHCI_QH_GET_HUBA(endphub), EHCI_QH_GET_PORT(endphub),
137 EHCI_QH_GET_MULT(endphub));
138 db_printf(" curqtd="); ehci_dump_link(sc, qh->qh_curqtd, 0); db_printf("\n");
139 db_printf("Overlay qTD:\n");
140 ehci_dump_qtd(sc, &qh->qh_qtd);
144 ehci_dump_itd(ehci_softc_t *sc, struct ehci_soft_itd *itd)
147 ehci_isoc_bufr_ptr_t b, b2, b3;
150 db_printf("ITD: next phys=%X\n", itd->itd.itd_next);
152 for (i = 0; i < 8;i++) {
153 t = hc32toh(sc, itd->itd.itd_ctl[i]);
154 db_printf("ITDctl %d: stat=%X len=%X ioc=%X pg=%X offs=%X\n", i,
155 EHCI_ITD_GET_STATUS(t), EHCI_ITD_GET_LEN(t),
156 EHCI_ITD_GET_IOC(t), EHCI_ITD_GET_PG(t),
157 EHCI_ITD_GET_OFFS(t));
159 db_printf("ITDbufr: ");
160 for (i = 0; i < 7; i++)
161 db_printf("%X,", EHCI_ITD_GET_BPTR(hc32toh(sc, itd->itd.itd_bufr[i])));
163 b = hc32toh(sc, itd->itd.itd_bufr[0]);
164 b2 = hc32toh(sc, itd->itd.itd_bufr[1]);
165 b3 = hc32toh(sc, itd->itd.itd_bufr[2]);
166 db_printf("\nep=%X daddr=%X dir=%d maxpkt=%X multi=%X\n",
167 EHCI_ITD_GET_EP(b), EHCI_ITD_GET_DADDR(b), EHCI_ITD_GET_DIR(b2),
168 EHCI_ITD_GET_MAXPKT(b2), EHCI_ITD_GET_MULTI(b3));
172 ehci_dump_sitd(ehci_softc_t *sc, struct ehci_soft_itd *itd)
174 db_printf("SITD %p next=%p prev=%p xfernext=%p physaddr=%X slot=%d\n",
175 itd, itd->u.frame_list.next, itd->u.frame_list.prev,
176 itd->xfer_next, itd->physaddr, itd->slot);
180 ehci_dump_exfer(struct ehci_xfer *ex)
183 db_printf("%p: sqtdstart %p end %p itdstart %p end %p isdone %d\n",
184 ex, ex->sqtdstart, ex->sqtdend, ex->itdstart,
185 ex->itdend, ex->isdone);
187 db_printf("%p: sqtdstart %p end %p itdstart %p end %p\n",
188 ex, ex->sqtdstart, ex->sqtdend, ex->itdstart, ex->itdend);
193 DB_SHOW_COMMAND(ehci, db_show_ehci)
196 db_printf("usage: show ehci <addr>\n");
199 ehci_dump_regs((ehci_softc_t *) addr);
202 DB_SHOW_COMMAND(ehci_sqtds, db_show_ehci_sqtds)
205 db_printf("usage: show ehci_sqtds <addr>\n");
208 ehci_dump_sqtds(theehci, (ehci_soft_qtd_t *) addr);
211 DB_SHOW_COMMAND(ehci_qtd, db_show_ehci_qtd)
214 db_printf("usage: show ehci_qtd <addr>\n");
217 ehci_dump_qtd(theehci, (ehci_qtd_t *) addr);
220 DB_SHOW_COMMAND(ehci_sqh, db_show_ehci_sqh)
223 db_printf("usage: show ehci_sqh <addr>\n");
226 ehci_dump_sqh(theehci, (ehci_soft_qh_t *) addr);
229 DB_SHOW_COMMAND(ehci_itd, db_show_ehci_itd)
232 db_printf("usage: show ehci_itd <addr>\n");
235 ehci_dump_itd(theehci, (struct ehci_soft_itd *) addr);
238 DB_SHOW_COMMAND(ehci_sitd, db_show_ehci_sitd)
241 db_printf("usage: show ehci_sitd <addr>\n");
244 ehci_dump_itd(theehci, (struct ehci_soft_itd *) addr);
247 DB_SHOW_COMMAND(ehci_xfer, db_show_ehci_xfer)
250 db_printf("usage: show ehci_xfer <addr>\n");
253 ehci_dump_exfer((struct ehci_xfer *) addr);