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