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