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