]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/legacy/dev/usb/ehci_ddb.c
Some whitespace and style fixes.
[FreeBSD/FreeBSD.git] / sys / legacy / dev / usb / ehci_ddb.c
1
2 #include <sys/cdefs.h>
3 __FBSDID("$FreeBSD$");
4
5 #include "opt_ddb.h"
6
7 #include <sys/param.h>
8 #include <sys/systm.h>
9 #include <sys/kernel.h>
10 #include <sys/endian.h>
11 #include <sys/bus.h>
12 #include <sys/lock.h>
13 #include <sys/lockmgr.h>
14
15 #include <machine/bus.h>
16 #include <machine/endian.h>
17
18 #include <dev/usb/usb.h>
19 #include <dev/usb/usbdi.h>
20 #include <dev/usb/usbdivar.h>
21
22 #include <dev/usb/ehcireg.h>
23 #include <dev/usb/ehcivar.h>
24
25 #ifdef DDB
26 #include <ddb/ddb.h>
27 #include <ddb/db_sym.h>
28 #else
29 #define db_printf       printf
30 #endif
31
32 extern  ehci_softc_t *theehci;          /* XXX */
33
34 void
35 ehci_dump_regs(ehci_softc_t *sc)
36 {
37         int i;
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)));
50 }
51
52 static void
53 ehci_dump_link(ehci_softc_t *sc, ehci_link_t link, int type)
54 {
55         link = hc32toh(sc, link);
56         db_printf("0x%08x", link);
57         if (link & EHCI_LINK_TERMINATE)
58                 db_printf("<T>");
59         else {
60                 db_printf("<");
61                 if (type) {
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;
67                         }
68                 }
69                 db_printf(">");
70         }
71 }
72
73 void
74 ehci_dump_sqtds(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd)
75 {
76         int i;
77         u_int32_t stop;
78
79         stop = 0;
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);
83         }
84         if (sqtd)
85                 db_printf("dump aborted, too many TDs\n");
86 }
87
88 void
89 ehci_dump_qtd(ehci_softc_t *sc, ehci_qtd_t *qtd)
90 {
91         u_int32_t s;
92
93         db_printf("  next="); ehci_dump_link(sc, qtd->qtd_next, 0);
94         db_printf(" altnext="); ehci_dump_link(sc, qtd->qtd_altnext, 0);
95         db_printf("\n");
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),
101                EHCI_QTD_GET_PID(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]));
105 }
106
107 void
108 ehci_dump_sqtd(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd)
109 {
110         db_printf("QTD(%p) at 0x%08x:\n", sqtd, sqtd->physaddr);
111         ehci_dump_qtd(sc, &sqtd->qtd);
112 }
113
114 void
115 ehci_dump_sqh(ehci_softc_t *sc, ehci_soft_qh_t *sqh)
116 {
117         ehci_qh_t *qh = &sqh->qh;
118         u_int32_t endp, endphub;
119
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);
141 }
142
143 void
144 ehci_dump_itd(ehci_softc_t *sc, struct ehci_soft_itd *itd)
145 {
146         ehci_isoc_trans_t t;
147         ehci_isoc_bufr_ptr_t b, b2, b3;
148         int i;
149
150         db_printf("ITD: next phys=%X\n", itd->itd.itd_next);
151
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));
158         }
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])));
162
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));
169 }
170
171 void
172 ehci_dump_sitd(ehci_softc_t *sc, struct ehci_soft_itd *itd)
173 {
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);
177 }
178
179 void
180 ehci_dump_exfer(struct ehci_xfer *ex)
181 {
182 #ifdef DIAGNOSTIC
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);
186 #else
187         db_printf("%p: sqtdstart %p end %p itdstart %p end %p\n",
188             ex, ex->sqtdstart, ex->sqtdend, ex->itdstart, ex->itdend);
189 #endif
190 }
191
192 #ifdef DDB
193 DB_SHOW_COMMAND(ehci, db_show_ehci)
194 {
195         if (!have_addr) {
196                 db_printf("usage: show ehci <addr>\n");
197                 return;
198         }
199         ehci_dump_regs((ehci_softc_t *) addr);
200 }
201
202 DB_SHOW_COMMAND(ehci_sqtds, db_show_ehci_sqtds)
203 {
204         if (!have_addr) {
205                 db_printf("usage: show ehci_sqtds <addr>\n");
206                 return;
207         }
208         ehci_dump_sqtds(theehci, (ehci_soft_qtd_t *) addr);
209 }
210
211 DB_SHOW_COMMAND(ehci_qtd, db_show_ehci_qtd)
212 {
213         if (!have_addr) {
214                 db_printf("usage: show ehci_qtd <addr>\n");
215                 return;
216         }
217         ehci_dump_qtd(theehci, (ehci_qtd_t *) addr);
218 }
219
220 DB_SHOW_COMMAND(ehci_sqh, db_show_ehci_sqh)
221 {
222         if (!have_addr) {
223                 db_printf("usage: show ehci_sqh <addr>\n");
224                 return;
225         }
226         ehci_dump_sqh(theehci, (ehci_soft_qh_t *) addr);
227 }
228
229 DB_SHOW_COMMAND(ehci_itd, db_show_ehci_itd)
230 {
231         if (!have_addr) {
232                 db_printf("usage: show ehci_itd <addr>\n");
233                 return;
234         }
235         ehci_dump_itd(theehci, (struct ehci_soft_itd *) addr);
236 }
237
238 DB_SHOW_COMMAND(ehci_sitd, db_show_ehci_sitd)
239 {
240         if (!have_addr) {
241                 db_printf("usage: show ehci_sitd <addr>\n");
242                 return;
243         }
244         ehci_dump_itd(theehci, (struct ehci_soft_itd *) addr);
245 }
246
247 DB_SHOW_COMMAND(ehci_xfer, db_show_ehci_xfer)
248 {
249         if (!have_addr) {
250                 db_printf("usage: show ehci_xfer <addr>\n");
251                 return;
252         }
253         ehci_dump_exfer((struct ehci_xfer *) addr);
254 }
255 #endif /* DDB */