xref: /freebsd/sys/dev/ath/if_ath_debug.c (revision c6ec7d31830ab1c80edae95ad5e4b9dba10c47ac)
1 /*-
2  * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer,
10  *    without modification.
11  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13  *    redistribution must be conditioned upon including a substantially
14  *    similar Disclaimer requirement for further binary redistribution.
15  *
16  * NO WARRANTY
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27  * THE POSSIBILITY OF SUCH DAMAGES.
28  */
29 
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
32 
33 #include "opt_inet.h"
34 #include "opt_ath.h"
35 #include "opt_wlan.h"
36 
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/sysctl.h>
40 #include <sys/mbuf.h>
41 #include <sys/malloc.h>
42 #include <sys/lock.h>
43 #include <sys/mutex.h>
44 #include <sys/kernel.h>
45 #include <sys/socket.h>
46 #include <sys/sockio.h>
47 #include <sys/errno.h>
48 #include <sys/callout.h>
49 #include <sys/bus.h>
50 #include <sys/endian.h>
51 #include <sys/kthread.h>
52 #include <sys/taskqueue.h>
53 #include <sys/priv.h>
54 
55 #include <machine/bus.h>
56 
57 #include <net/if.h>
58 #include <net/if_dl.h>
59 #include <net/if_media.h>
60 #include <net/if_types.h>
61 #include <net/if_arp.h>
62 #include <net/ethernet.h>
63 #include <net/if_llc.h>
64 
65 #include <net80211/ieee80211_var.h>
66 #include <net80211/ieee80211_regdomain.h>
67 #ifdef IEEE80211_SUPPORT_SUPERG
68 #include <net80211/ieee80211_superg.h>
69 #endif
70 #ifdef IEEE80211_SUPPORT_TDMA
71 #include <net80211/ieee80211_tdma.h>
72 #endif
73 
74 #include <net/bpf.h>
75 
76 #ifdef INET
77 #include <netinet/in.h>
78 #include <netinet/if_ether.h>
79 #endif
80 
81 #include <dev/ath/if_athvar.h>
82 #include <dev/ath/ath_hal/ah_devid.h>		/* XXX for softled */
83 #include <dev/ath/ath_hal/ah_diagcodes.h>
84 
85 #ifdef ATH_TX99_DIAG
86 #include <dev/ath/ath_tx99/ath_tx99.h>
87 #endif
88 
89 #ifdef ATH_DEBUG
90 #include <dev/ath/if_ath_debug.h>
91 
92 uint64_t ath_debug = 0;
93 
94 SYSCTL_DECL(_hw_ath);
95 SYSCTL_QUAD(_hw_ath, OID_AUTO, debug, CTLFLAG_RW, &ath_debug,
96 	    0, "control debugging printfs");
97 TUNABLE_QUAD("hw.ath.debug", &ath_debug);
98 
99 void
100 ath_printrxbuf(struct ath_softc *sc, const struct ath_buf *bf,
101 	u_int ix, int done)
102 {
103 	const struct ath_rx_status *rs = &bf->bf_status.ds_rxstat;
104 	struct ath_hal *ah = sc->sc_ah;
105 	const struct ath_desc *ds;
106 	int i;
107 
108 	for (i = 0, ds = bf->bf_desc; i < bf->bf_nseg; i++, ds++) {
109 		printf("R[%2u] (DS.V:%p DS.P:%p) L:%08x D:%08x%s\n"
110 		       "      %08x %08x %08x %08x\n",
111 		    ix, ds, (const struct ath_desc *)bf->bf_daddr + i,
112 		    ds->ds_link, ds->ds_data,
113 		    !done ? "" : (rs->rs_status == 0) ? " *" : " !",
114 		    ds->ds_ctl0, ds->ds_ctl1,
115 		    ds->ds_hw[0], ds->ds_hw[1]);
116 		if (ah->ah_magic == 0x20065416) {
117 			printf("        %08x %08x %08x %08x %08x %08x %08x\n",
118 			    ds->ds_hw[2], ds->ds_hw[3], ds->ds_hw[4],
119 			    ds->ds_hw[5], ds->ds_hw[6], ds->ds_hw[7],
120 			    ds->ds_hw[8]);
121 		} else if (ah->ah_magic == 0x19741014) {
122 			printf("        %08x %08x %08x %08x %08x %08x %08x\n",
123 			    ds->ds_hw[2], ds->ds_hw[3], ds->ds_hw[4],
124 			    ds->ds_hw[5], ds->ds_hw[6], ds->ds_hw[7],
125 			    ds->ds_hw[8]);
126 
127 			printf("        %08x %08x %08x %08x %08x %08x %08x\n",
128 			    ds->ds_hw[9], ds->ds_hw[10], ds->ds_hw[11],
129 			    ds->ds_hw[12], ds->ds_hw[13], ds->ds_hw[14],
130 			    ds->ds_hw[15]);
131 		}
132 	}
133 }
134 
135 static void
136 ath_printtxbuf_edma(struct ath_softc *sc, const struct ath_buf *first_bf,
137 	u_int qnum, u_int ix, int done)
138 {
139 	const struct ath_tx_status *ts =
140 	    &first_bf->bf_last->bf_status.ds_txstat;
141 	const struct ath_buf *bf = first_bf;
142 	const char *ds;
143 	const struct ath_desc_txedma *eds;
144 	int i, n;
145 
146 	printf("Q%u[%3u] (nseg=%d)", qnum, ix, bf->bf_nseg);
147 	while (bf != NULL) {
148 		/*
149 		 * XXX For now, assume the txmap size is 4.
150 		 */
151 
152 		/*
153 		 * Assume the TX map size is 4 for now and only walk
154 		 * the appropriate number of segments.
155 		 */
156 		n = ((bf->bf_nseg - 1) / 4) + 1;
157 
158 		for (i = 0, ds = (const char *) bf->bf_desc;
159 		    i < n;
160 		    i ++, ds += sc->sc_tx_desclen) {
161 			eds = (const struct ath_desc_txedma *) ds;
162 			printf(" (DS.V:%p DS.P:%p) I: %08x L:%08x F:%04x%s\n",
163 			    eds, (const struct ath_desc *)bf->bf_daddr + i,
164 			    eds->ds_info, eds->ds_link,
165 			    bf->bf_state.bfs_txflags,
166 			    !done ? "" : (ts->ts_status == 0) ? " *" : " !");
167 			printf(" (D[0] = %08x(%08x), D[1] = %08x(%08x)\n",
168 			    eds->ds_hw[0], eds->ds_hw[1],
169 			    eds->ds_hw[2], eds->ds_hw[3]);
170 			printf(" (D[2] = %08x(%08x), D[3] = %08x(%08x)\n",
171 			    eds->ds_hw[4], eds->ds_hw[5],
172 			    eds->ds_hw[6], eds->ds_hw[7]);
173 			printf("        Seq: %d swtry: %d ADDBAW?: %d DOBAW?: %d\n",
174 			    bf->bf_state.bfs_seqno,
175 			    bf->bf_state.bfs_retries,
176 			    bf->bf_state.bfs_addedbaw,
177 			    bf->bf_state.bfs_dobaw);
178 			printf("        %08x %08x %08x %08x %08x %08x\n",
179 			    eds->ds_hw[8], eds->ds_hw[9],
180 			    eds->ds_hw[10], eds->ds_hw[11],
181 			    eds->ds_hw[12], eds->ds_hw[13]);
182 			printf("        %08x %08x %08x %08x %08x %08x %08x\n",
183 			    eds->ds_hw[14], eds->ds_hw[15], eds->ds_hw[16],
184 			    eds->ds_hw[17], eds->ds_hw[18], eds->ds_hw[19],
185 			    eds->ds_hw[20]);
186 #if 0
187 			printf("        %08x %08x %08x %08x %08x %08x %08x %08x\n",
188 			    ds->ds_hw[22],ds->ds_hw[23],ds->ds_hw[24],
189 			    ds->ds_hw[25],ds->ds_hw[26],ds->ds_hw[27],
190 			    ds->ds_hw[28], ds->ds_hw[29]);
191 #endif
192 		}
193 		printf("  [end]\n");
194 		bf = bf->bf_next;
195 	}
196 }
197 
198 static void
199 ath_printtxbuf_legacy(struct ath_softc *sc, const struct ath_buf *first_bf,
200 	u_int qnum, u_int ix, int done)
201 {
202 	const struct ath_tx_status *ts = &first_bf->bf_status.ds_txstat;
203 	const struct ath_buf *bf = first_bf;
204 	struct ath_hal *ah = sc->sc_ah;
205 	const struct ath_desc *ds;
206 	int i;
207 
208 	printf("Q%u[%3u]", qnum, ix);
209 	while (bf != NULL) {
210 		printf("    (bf=%p, lastds=%p)\n", bf, first_bf->bf_lastds);
211 		printf("        Seq: %d swtry: %d ADDBAW?: %d DOBAW?: %d\n",
212 		    bf->bf_state.bfs_seqno,
213 		    bf->bf_state.bfs_retries,
214 		    bf->bf_state.bfs_addedbaw,
215 		    bf->bf_state.bfs_dobaw);
216 		for (i = 0, ds = bf->bf_desc; i < bf->bf_nseg; i++, ds++) {
217 			printf(" (DS.V:%p DS.P:%p) L:%08x D:%08x F:%04x%s\n",
218 			    ds, (const struct ath_desc *)bf->bf_daddr + i,
219 			    ds->ds_link, ds->ds_data, bf->bf_state.bfs_txflags,
220 			    !done ? "" : (ts->ts_status == 0) ? " *" : " !");
221 			printf("        %08x %08x %08x %08x %08x %08x\n",
222 			    ds->ds_ctl0, ds->ds_ctl1,
223 			    ds->ds_hw[0], ds->ds_hw[1],
224 			    ds->ds_hw[2], ds->ds_hw[3]);
225 			if (ah->ah_magic == 0x20065416) {
226 				printf("        %08x %08x %08x %08x %08x %08x %08x %08x\n",
227 				    ds->ds_hw[4], ds->ds_hw[5], ds->ds_hw[6],
228 				    ds->ds_hw[7], ds->ds_hw[8], ds->ds_hw[9],
229 				    ds->ds_hw[10],ds->ds_hw[11]);
230 				printf("        %08x %08x %08x %08x %08x %08x %08x %08x\n",
231 				    ds->ds_hw[12],ds->ds_hw[13],ds->ds_hw[14],
232 				    ds->ds_hw[15],ds->ds_hw[16],ds->ds_hw[17],
233 				    ds->ds_hw[18], ds->ds_hw[19]);
234 			}
235 		}
236 		printf("  [end]\n");
237 		bf = bf->bf_next;
238 	}
239 }
240 
241 void
242 ath_printtxbuf(struct ath_softc *sc, const struct ath_buf *first_bf,
243 	u_int qnum, u_int ix, int done)
244 {
245 	if (sc->sc_ah->ah_magic == 0x19741014)
246 		ath_printtxbuf_edma(sc, first_bf, qnum, ix, done);
247 	else
248 		ath_printtxbuf_legacy(sc, first_bf, qnum, ix, done);
249 }
250 
251 void
252 ath_printtxstatbuf(struct ath_softc *sc, const struct ath_buf *first_bf,
253 	const uint32_t *ds, u_int qnum, u_int ix, int done)
254 {
255 
256 	printf("Q%u[%3u] ", qnum, ix);
257 	printf("        %08x %08x %08x %08x %08x %08x\n",
258 	    ds[0], ds[1], ds[2], ds[3], ds[4], ds[5]);
259 	printf("        %08x %08x %08x %08x %08x\n",
260 	    ds[6], ds[7], ds[8], ds[9], ds[10]);
261 }
262 
263 #endif	/* ATH_DEBUG */
264