xref: /dragonfly/sys/dev/netif/ath/ath/if_ath_debug.c (revision 6ab64ab6)
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 #if defined(__DragonFly__)
34 #define CTLFLAG_RWTUN	CTLFLAG_RW
35 #endif
36 
37 #include "opt_inet.h"
38 #include "opt_ath.h"
39 #include "opt_wlan.h"
40 
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/sysctl.h>
44 #include <sys/mbuf.h>
45 #include <sys/malloc.h>
46 #include <sys/lock.h>
47 #include <sys/mutex.h>
48 #include <sys/kernel.h>
49 #include <sys/socket.h>
50 #include <sys/sockio.h>
51 #include <sys/errno.h>
52 #include <sys/callout.h>
53 #include <sys/bus.h>
54 #include <sys/endian.h>
55 #include <sys/kthread.h>
56 #include <sys/taskqueue.h>
57 #include <sys/priv.h>
58 
59 #if defined(__DragonFly__)
60 #else
61 #include <machine/bus.h>
62 #endif
63 
64 #include <net/if.h>
65 #include <net/if_dl.h>
66 #include <net/if_media.h>
67 #include <net/if_types.h>
68 #include <net/if_arp.h>
69 #include <net/ethernet.h>
70 #include <net/if_llc.h>
71 
72 #include <netproto/802_11/ieee80211_var.h>
73 #include <netproto/802_11/ieee80211_regdomain.h>
74 #ifdef IEEE80211_SUPPORT_SUPERG
75 #include <netproto/802_11/ieee80211_superg.h>
76 #endif
77 #ifdef IEEE80211_SUPPORT_TDMA
78 #include <netproto/802_11/ieee80211_tdma.h>
79 #endif
80 
81 #include <net/bpf.h>
82 
83 #ifdef INET
84 #include <netinet/in.h>
85 #include <netinet/if_ether.h>
86 #endif
87 
88 #include <dev/netif/ath/ath/if_athvar.h>
89 #include <dev/netif/ath/ath_hal/ah_devid.h>		/* XXX for softled */
90 #include <dev/netif/ath/ath_hal/ah_diagcodes.h>
91 
92 #ifdef ATH_TX99_DIAG
93 #include <dev/netif/ath/ath/ath_tx99/ath_tx99.h>
94 #endif
95 
96 #ifdef ATH_DEBUG
97 #include <dev/netif/ath/ath/if_ath_debug.h>
98 
99 uint64_t ath_debug = 0;
100 
101 SYSCTL_DECL(_hw_ath);
102 SYSCTL_QUAD(_hw_ath, OID_AUTO, debug, CTLFLAG_RWTUN, &ath_debug,
103 	    0, "control debugging printfs");
104 
105 void
106 ath_printrxbuf(struct ath_softc *sc, const struct ath_buf *bf,
107 	u_int ix, int done)
108 {
109 	const struct ath_rx_status *rs = &bf->bf_status.ds_rxstat;
110 	struct ath_hal *ah = sc->sc_ah;
111 	const struct ath_desc *ds;
112 	int i;
113 
114 	for (i = 0, ds = bf->bf_desc; i < bf->bf_nseg; i++, ds++) {
115 		kprintf("R[%2u] (DS.V:%p DS.P:%p) L:%08x D:%08x%s\n"
116 		       "      %08x %08x %08x %08x\n",
117 		    ix, ds, (const struct ath_desc *)bf->bf_daddr + i,
118 		    ds->ds_link, ds->ds_data,
119 		    !done ? "" : (rs->rs_status == 0) ? " *" : " !",
120 		    ds->ds_ctl0, ds->ds_ctl1,
121 		    ds->ds_hw[0], ds->ds_hw[1]);
122 		if (ah->ah_magic == 0x20065416) {
123 			kprintf("        %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 		} else if (ah->ah_magic == 0x19741014) {
128 			kprintf("        %08x %08x %08x %08x %08x %08x %08x\n",
129 			    ds->ds_hw[2], ds->ds_hw[3], ds->ds_hw[4],
130 			    ds->ds_hw[5], ds->ds_hw[6], ds->ds_hw[7],
131 			    ds->ds_hw[8]);
132 
133 			kprintf("        %08x %08x %08x %08x %08x %08x %08x\n",
134 			    ds->ds_hw[9], ds->ds_hw[10], ds->ds_hw[11],
135 			    ds->ds_hw[12], ds->ds_hw[13], ds->ds_hw[14],
136 			    ds->ds_hw[15]);
137 		}
138 	}
139 }
140 
141 static void
142 ath_printtxbuf_edma(struct ath_softc *sc, const struct ath_buf *first_bf,
143 	u_int qnum, u_int ix, int done)
144 {
145 	const struct ath_tx_status *ts =
146 	    &first_bf->bf_last->bf_status.ds_txstat;
147 	const struct ath_buf *bf = first_bf;
148 	const char *ds;
149 	const struct ath_desc_txedma *eds;
150 	int i, n;
151 
152 	kprintf("Q%u[%3u] (nseg=%d)", qnum, ix, bf->bf_nseg);
153 	while (bf != NULL) {
154 		/*
155 		 * XXX For now, assume the txmap size is 4.
156 		 */
157 
158 		/*
159 		 * Assume the TX map size is 4 for now and only walk
160 		 * the appropriate number of segments.
161 		 */
162 		n = ((bf->bf_nseg - 1) / 4) + 1;
163 
164 		for (i = 0, ds = (const char *) bf->bf_desc;
165 		    i < n;
166 		    i ++, ds += sc->sc_tx_desclen) {
167 			eds = (const struct ath_desc_txedma *) ds;
168 			kprintf(" (DS.V:%p DS.P:%p) I: %08x L:%08x F:%04x%s\n",
169 			    eds, (const struct ath_desc *)bf->bf_daddr + i,
170 			    eds->ds_info, eds->ds_link,
171 			    bf->bf_state.bfs_txflags,
172 			    !done ? "" : (ts->ts_status == 0) ? " *" : " !");
173 			kprintf(" (D[0] = %08x(%08x), D[1] = %08x(%08x)\n",
174 			    eds->ds_hw[0], eds->ds_hw[1],
175 			    eds->ds_hw[2], eds->ds_hw[3]);
176 			kprintf(" (D[2] = %08x(%08x), D[3] = %08x(%08x)\n",
177 			    eds->ds_hw[4], eds->ds_hw[5],
178 			    eds->ds_hw[6], eds->ds_hw[7]);
179 			kprintf("        Seq: %d swtry: %d ADDBAW?: %d DOBAW?: %d\n",
180 			    bf->bf_state.bfs_seqno,
181 			    bf->bf_state.bfs_retries,
182 			    bf->bf_state.bfs_addedbaw,
183 			    bf->bf_state.bfs_dobaw);
184 			kprintf("        %08x %08x %08x %08x %08x %08x\n",
185 			    eds->ds_hw[8], eds->ds_hw[9],
186 			    eds->ds_hw[10], eds->ds_hw[11],
187 			    eds->ds_hw[12], eds->ds_hw[13]);
188 			kprintf("        %08x %08x %08x %08x %08x %08x %08x\n",
189 			    eds->ds_hw[14], eds->ds_hw[15], eds->ds_hw[16],
190 			    eds->ds_hw[17], eds->ds_hw[18], eds->ds_hw[19],
191 			    eds->ds_hw[20]);
192 #if 0
193 			kprintf("        %08x %08x %08x %08x %08x %08x %08x %08x\n",
194 			    ds->ds_hw[22],ds->ds_hw[23],ds->ds_hw[24],
195 			    ds->ds_hw[25],ds->ds_hw[26],ds->ds_hw[27],
196 			    ds->ds_hw[28], ds->ds_hw[29]);
197 #endif
198 		}
199 		kprintf("  [end]\n");
200 		bf = bf->bf_next;
201 	}
202 }
203 
204 static void
205 ath_printtxbuf_legacy(struct ath_softc *sc, const struct ath_buf *first_bf,
206 	u_int qnum, u_int ix, int done)
207 {
208 	const struct ath_tx_status *ts = &first_bf->bf_status.ds_txstat;
209 	const struct ath_buf *bf = first_bf;
210 	struct ath_hal *ah = sc->sc_ah;
211 	const struct ath_desc *ds;
212 	int i;
213 
214 	kprintf("Q%u[%3u]", qnum, ix);
215 	while (bf != NULL) {
216 		kprintf("    (bf=%p, lastds=%p)\n", bf, first_bf->bf_lastds);
217 		kprintf("        Seq: %d swtry: %d ADDBAW?: %d DOBAW?: %d\n",
218 		    bf->bf_state.bfs_seqno,
219 		    bf->bf_state.bfs_retries,
220 		    bf->bf_state.bfs_addedbaw,
221 		    bf->bf_state.bfs_dobaw);
222 		for (i = 0, ds = bf->bf_desc; i < bf->bf_nseg; i++, ds++) {
223 			kprintf(" (DS.V:%p DS.P:%p) L:%08x D:%08x F:%04x%s\n",
224 			    ds, (const struct ath_desc *)bf->bf_daddr + i,
225 			    ds->ds_link, ds->ds_data, bf->bf_state.bfs_txflags,
226 			    !done ? "" : (ts->ts_status == 0) ? " *" : " !");
227 			kprintf("        %08x %08x %08x %08x %08x %08x\n",
228 			    ds->ds_ctl0, ds->ds_ctl1,
229 			    ds->ds_hw[0], ds->ds_hw[1],
230 			    ds->ds_hw[2], ds->ds_hw[3]);
231 			if (ah->ah_magic == 0x20065416) {
232 				kprintf("        %08x %08x %08x %08x %08x %08x %08x %08x\n",
233 				    ds->ds_hw[4], ds->ds_hw[5], ds->ds_hw[6],
234 				    ds->ds_hw[7], ds->ds_hw[8], ds->ds_hw[9],
235 				    ds->ds_hw[10],ds->ds_hw[11]);
236 				kprintf("        %08x %08x %08x %08x %08x %08x %08x %08x\n",
237 				    ds->ds_hw[12],ds->ds_hw[13],ds->ds_hw[14],
238 				    ds->ds_hw[15],ds->ds_hw[16],ds->ds_hw[17],
239 				    ds->ds_hw[18], ds->ds_hw[19]);
240 			}
241 		}
242 		kprintf("  [end]\n");
243 		bf = bf->bf_next;
244 	}
245 }
246 
247 void
248 ath_printtxbuf(struct ath_softc *sc, const struct ath_buf *first_bf,
249 	u_int qnum, u_int ix, int done)
250 {
251 	if (sc->sc_ah->ah_magic == 0x19741014)
252 		ath_printtxbuf_edma(sc, first_bf, qnum, ix, done);
253 	else
254 		ath_printtxbuf_legacy(sc, first_bf, qnum, ix, done);
255 }
256 
257 void
258 ath_printtxstatbuf(struct ath_softc *sc, const struct ath_buf *first_bf,
259 	const uint32_t *ds, u_int qnum, u_int ix, int done)
260 {
261 
262 	kprintf("Q%u[%3u] ", qnum, ix);
263 	kprintf("        %08x %08x %08x %08x %08x %08x\n",
264 	    ds[0], ds[1], ds[2], ds[3], ds[4], ds[5]);
265 	kprintf("        %08x %08x %08x %08x %08x\n",
266 	    ds[6], ds[7], ds[8], ds[9], ds[10]);
267 }
268 
269 #endif	/* ATH_DEBUG */
270