xref: /freebsd/sys/dev/ath/if_ath_debug.c (revision 685dc743)
15bc8125aSAdrian Chadd /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
45bc8125aSAdrian Chadd  * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
55bc8125aSAdrian Chadd  * All rights reserved.
65bc8125aSAdrian Chadd  *
75bc8125aSAdrian Chadd  * Redistribution and use in source and binary forms, with or without
85bc8125aSAdrian Chadd  * modification, are permitted provided that the following conditions
95bc8125aSAdrian Chadd  * are met:
105bc8125aSAdrian Chadd  * 1. Redistributions of source code must retain the above copyright
115bc8125aSAdrian Chadd  *    notice, this list of conditions and the following disclaimer,
125bc8125aSAdrian Chadd  *    without modification.
135bc8125aSAdrian Chadd  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
145bc8125aSAdrian Chadd  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
155bc8125aSAdrian Chadd  *    redistribution must be conditioned upon including a substantially
165bc8125aSAdrian Chadd  *    similar Disclaimer requirement for further binary redistribution.
175bc8125aSAdrian Chadd  *
185bc8125aSAdrian Chadd  * NO WARRANTY
195bc8125aSAdrian Chadd  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
205bc8125aSAdrian Chadd  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
215bc8125aSAdrian Chadd  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
225bc8125aSAdrian Chadd  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
235bc8125aSAdrian Chadd  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
245bc8125aSAdrian Chadd  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
255bc8125aSAdrian Chadd  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
265bc8125aSAdrian Chadd  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
275bc8125aSAdrian Chadd  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
285bc8125aSAdrian Chadd  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
295bc8125aSAdrian Chadd  * THE POSSIBILITY OF SUCH DAMAGES.
305bc8125aSAdrian Chadd  */
315bc8125aSAdrian Chadd 
325bc8125aSAdrian Chadd #include <sys/cdefs.h>
335bc8125aSAdrian Chadd #include "opt_inet.h"
345bc8125aSAdrian Chadd #include "opt_ath.h"
355bc8125aSAdrian Chadd #include "opt_wlan.h"
365bc8125aSAdrian Chadd 
375bc8125aSAdrian Chadd #include <sys/param.h>
385bc8125aSAdrian Chadd #include <sys/systm.h>
395bc8125aSAdrian Chadd #include <sys/sysctl.h>
405bc8125aSAdrian Chadd #include <sys/mbuf.h>
415bc8125aSAdrian Chadd #include <sys/malloc.h>
425bc8125aSAdrian Chadd #include <sys/lock.h>
435bc8125aSAdrian Chadd #include <sys/mutex.h>
445bc8125aSAdrian Chadd #include <sys/kernel.h>
455bc8125aSAdrian Chadd #include <sys/socket.h>
465bc8125aSAdrian Chadd #include <sys/sockio.h>
475bc8125aSAdrian Chadd #include <sys/errno.h>
485bc8125aSAdrian Chadd #include <sys/callout.h>
495bc8125aSAdrian Chadd #include <sys/bus.h>
505bc8125aSAdrian Chadd #include <sys/endian.h>
515bc8125aSAdrian Chadd #include <sys/kthread.h>
525bc8125aSAdrian Chadd #include <sys/taskqueue.h>
535bc8125aSAdrian Chadd #include <sys/priv.h>
545bc8125aSAdrian Chadd 
555bc8125aSAdrian Chadd #include <machine/bus.h>
565bc8125aSAdrian Chadd 
575bc8125aSAdrian Chadd #include <net/if.h>
585bc8125aSAdrian Chadd #include <net/if_dl.h>
595bc8125aSAdrian Chadd #include <net/if_media.h>
605bc8125aSAdrian Chadd #include <net/if_types.h>
615bc8125aSAdrian Chadd #include <net/if_arp.h>
625bc8125aSAdrian Chadd #include <net/ethernet.h>
635bc8125aSAdrian Chadd #include <net/if_llc.h>
645bc8125aSAdrian Chadd 
655bc8125aSAdrian Chadd #include <net80211/ieee80211_var.h>
665bc8125aSAdrian Chadd #include <net80211/ieee80211_regdomain.h>
675bc8125aSAdrian Chadd #ifdef IEEE80211_SUPPORT_SUPERG
685bc8125aSAdrian Chadd #include <net80211/ieee80211_superg.h>
695bc8125aSAdrian Chadd #endif
705bc8125aSAdrian Chadd #ifdef IEEE80211_SUPPORT_TDMA
715bc8125aSAdrian Chadd #include <net80211/ieee80211_tdma.h>
725bc8125aSAdrian Chadd #endif
735bc8125aSAdrian Chadd 
745bc8125aSAdrian Chadd #include <net/bpf.h>
755bc8125aSAdrian Chadd 
765bc8125aSAdrian Chadd #ifdef INET
775bc8125aSAdrian Chadd #include <netinet/in.h>
785bc8125aSAdrian Chadd #include <netinet/if_ether.h>
795bc8125aSAdrian Chadd #endif
805bc8125aSAdrian Chadd 
815bc8125aSAdrian Chadd #include <dev/ath/if_athvar.h>
825bc8125aSAdrian Chadd #include <dev/ath/ath_hal/ah_devid.h>		/* XXX for softled */
835bc8125aSAdrian Chadd #include <dev/ath/ath_hal/ah_diagcodes.h>
845bc8125aSAdrian Chadd 
855bc8125aSAdrian Chadd #ifdef ATH_TX99_DIAG
865bc8125aSAdrian Chadd #include <dev/ath/ath_tx99/ath_tx99.h>
875bc8125aSAdrian Chadd #endif
885bc8125aSAdrian Chadd 
895bc8125aSAdrian Chadd #ifdef ATH_DEBUG
905bc8125aSAdrian Chadd #include <dev/ath/if_ath_debug.h>
915bc8125aSAdrian Chadd 
920e22ed0eSAdrian Chadd uint64_t ath_debug = 0;
935bc8125aSAdrian Chadd 
945bc8125aSAdrian Chadd SYSCTL_DECL(_hw_ath);
95af3b2549SHans Petter Selasky SYSCTL_QUAD(_hw_ath, OID_AUTO, debug, CTLFLAG_RWTUN, &ath_debug,
965bc8125aSAdrian Chadd 	    0, "control debugging printfs");
975bc8125aSAdrian Chadd 
985bc8125aSAdrian Chadd void
ath_printrxbuf(struct ath_softc * sc,const struct ath_buf * bf,u_int ix,int done)995bc8125aSAdrian Chadd ath_printrxbuf(struct ath_softc *sc, const struct ath_buf *bf,
1005bc8125aSAdrian Chadd 	u_int ix, int done)
1015bc8125aSAdrian Chadd {
1025bc8125aSAdrian Chadd 	const struct ath_rx_status *rs = &bf->bf_status.ds_rxstat;
1035bc8125aSAdrian Chadd 	struct ath_hal *ah = sc->sc_ah;
1045bc8125aSAdrian Chadd 	const struct ath_desc *ds;
1055bc8125aSAdrian Chadd 	int i;
1065bc8125aSAdrian Chadd 
1075bc8125aSAdrian Chadd 	for (i = 0, ds = bf->bf_desc; i < bf->bf_nseg; i++, ds++) {
1085bc8125aSAdrian Chadd 		printf("R[%2u] (DS.V:%p DS.P:%p) L:%08x D:%08x%s\n"
1095bc8125aSAdrian Chadd 		       "      %08x %08x %08x %08x\n",
1105bc8125aSAdrian Chadd 		    ix, ds, (const struct ath_desc *)bf->bf_daddr + i,
1115bc8125aSAdrian Chadd 		    ds->ds_link, ds->ds_data,
1125bc8125aSAdrian Chadd 		    !done ? "" : (rs->rs_status == 0) ? " *" : " !",
1135bc8125aSAdrian Chadd 		    ds->ds_ctl0, ds->ds_ctl1,
1145bc8125aSAdrian Chadd 		    ds->ds_hw[0], ds->ds_hw[1]);
1155bc8125aSAdrian Chadd 		if (ah->ah_magic == 0x20065416) {
1165bc8125aSAdrian Chadd 			printf("        %08x %08x %08x %08x %08x %08x %08x\n",
1175bc8125aSAdrian Chadd 			    ds->ds_hw[2], ds->ds_hw[3], ds->ds_hw[4],
1185bc8125aSAdrian Chadd 			    ds->ds_hw[5], ds->ds_hw[6], ds->ds_hw[7],
1195bc8125aSAdrian Chadd 			    ds->ds_hw[8]);
12074732ec4SAdrian Chadd 		} else if (ah->ah_magic == 0x19741014) {
12174732ec4SAdrian Chadd 			printf("        %08x %08x %08x %08x %08x %08x %08x\n",
12274732ec4SAdrian Chadd 			    ds->ds_hw[2], ds->ds_hw[3], ds->ds_hw[4],
12374732ec4SAdrian Chadd 			    ds->ds_hw[5], ds->ds_hw[6], ds->ds_hw[7],
12474732ec4SAdrian Chadd 			    ds->ds_hw[8]);
12574732ec4SAdrian Chadd 
12674732ec4SAdrian Chadd 			printf("        %08x %08x %08x %08x %08x %08x %08x\n",
12774732ec4SAdrian Chadd 			    ds->ds_hw[9], ds->ds_hw[10], ds->ds_hw[11],
12874732ec4SAdrian Chadd 			    ds->ds_hw[12], ds->ds_hw[13], ds->ds_hw[14],
12974732ec4SAdrian Chadd 			    ds->ds_hw[15]);
1305bc8125aSAdrian Chadd 		}
1315bc8125aSAdrian Chadd 	}
1325bc8125aSAdrian Chadd }
1335bc8125aSAdrian Chadd 
134e913fcdaSAdrian Chadd static void
ath_printtxbuf_edma(struct ath_softc * sc,const struct ath_buf * first_bf,u_int qnum,u_int ix,int done)135e913fcdaSAdrian Chadd ath_printtxbuf_edma(struct ath_softc *sc, const struct ath_buf *first_bf,
136e913fcdaSAdrian Chadd 	u_int qnum, u_int ix, int done)
137e913fcdaSAdrian Chadd {
138e913fcdaSAdrian Chadd 	const struct ath_tx_status *ts =
139e913fcdaSAdrian Chadd 	    &first_bf->bf_last->bf_status.ds_txstat;
140e913fcdaSAdrian Chadd 	const struct ath_buf *bf = first_bf;
141e913fcdaSAdrian Chadd 	const char *ds;
142e913fcdaSAdrian Chadd 	const struct ath_desc_txedma *eds;
143e913fcdaSAdrian Chadd 	int i, n;
144e913fcdaSAdrian Chadd 
145bd68600cSAdrian Chadd 	printf("Q%u[%3u] (nseg=%d)", qnum, ix, bf->bf_nseg);
146e913fcdaSAdrian Chadd 	while (bf != NULL) {
147e913fcdaSAdrian Chadd 		/*
148e913fcdaSAdrian Chadd 		 * XXX For now, assume the txmap size is 4.
149e913fcdaSAdrian Chadd 		 */
150bc919a54SAdrian Chadd 
151bc919a54SAdrian Chadd 		/*
152bc919a54SAdrian Chadd 		 * Assume the TX map size is 4 for now and only walk
153bc919a54SAdrian Chadd 		 * the appropriate number of segments.
154bc919a54SAdrian Chadd 		 */
155bc919a54SAdrian Chadd 		n = ((bf->bf_nseg - 1) / 4) + 1;
156bc919a54SAdrian Chadd 
157e913fcdaSAdrian Chadd 		for (i = 0, ds = (const char *) bf->bf_desc;
158e913fcdaSAdrian Chadd 		    i < n;
159e913fcdaSAdrian Chadd 		    i ++, ds += sc->sc_tx_desclen) {
160e913fcdaSAdrian Chadd 			eds = (const struct ath_desc_txedma *) ds;
161e913fcdaSAdrian Chadd 			printf(" (DS.V:%p DS.P:%p) I: %08x L:%08x F:%04x%s\n",
162e913fcdaSAdrian Chadd 			    eds, (const struct ath_desc *)bf->bf_daddr + i,
163e913fcdaSAdrian Chadd 			    eds->ds_info, eds->ds_link,
164e913fcdaSAdrian Chadd 			    bf->bf_state.bfs_txflags,
165e913fcdaSAdrian Chadd 			    !done ? "" : (ts->ts_status == 0) ? " *" : " !");
166e913fcdaSAdrian Chadd 			printf(" (D[0] = %08x(%08x), D[1] = %08x(%08x)\n",
167e913fcdaSAdrian Chadd 			    eds->ds_hw[0], eds->ds_hw[1],
168e913fcdaSAdrian Chadd 			    eds->ds_hw[2], eds->ds_hw[3]);
169e913fcdaSAdrian Chadd 			printf(" (D[2] = %08x(%08x), D[3] = %08x(%08x)\n",
170e913fcdaSAdrian Chadd 			    eds->ds_hw[4], eds->ds_hw[5],
171e913fcdaSAdrian Chadd 			    eds->ds_hw[6], eds->ds_hw[7]);
172e913fcdaSAdrian Chadd 			printf("        Seq: %d swtry: %d ADDBAW?: %d DOBAW?: %d\n",
173e913fcdaSAdrian Chadd 			    bf->bf_state.bfs_seqno,
174e913fcdaSAdrian Chadd 			    bf->bf_state.bfs_retries,
175e913fcdaSAdrian Chadd 			    bf->bf_state.bfs_addedbaw,
176e913fcdaSAdrian Chadd 			    bf->bf_state.bfs_dobaw);
177e913fcdaSAdrian Chadd 			printf("        %08x %08x %08x %08x %08x %08x\n",
178e913fcdaSAdrian Chadd 			    eds->ds_hw[8], eds->ds_hw[9],
179e913fcdaSAdrian Chadd 			    eds->ds_hw[10], eds->ds_hw[11],
180e913fcdaSAdrian Chadd 			    eds->ds_hw[12], eds->ds_hw[13]);
181bb1bf7edSAdrian Chadd 			printf("        %08x %08x %08x %08x %08x %08x %08x\n",
182e913fcdaSAdrian Chadd 			    eds->ds_hw[14], eds->ds_hw[15], eds->ds_hw[16],
183e913fcdaSAdrian Chadd 			    eds->ds_hw[17], eds->ds_hw[18], eds->ds_hw[19],
184bb1bf7edSAdrian Chadd 			    eds->ds_hw[20]);
185e913fcdaSAdrian Chadd #if 0
186e913fcdaSAdrian Chadd 			printf("        %08x %08x %08x %08x %08x %08x %08x %08x\n",
187e913fcdaSAdrian Chadd 			    ds->ds_hw[22],ds->ds_hw[23],ds->ds_hw[24],
188e913fcdaSAdrian Chadd 			    ds->ds_hw[25],ds->ds_hw[26],ds->ds_hw[27],
189e913fcdaSAdrian Chadd 			    ds->ds_hw[28], ds->ds_hw[29]);
190e913fcdaSAdrian Chadd #endif
191e913fcdaSAdrian Chadd 		}
192e913fcdaSAdrian Chadd 		printf("  [end]\n");
193e913fcdaSAdrian Chadd 		bf = bf->bf_next;
194e913fcdaSAdrian Chadd 	}
195e913fcdaSAdrian Chadd }
196e913fcdaSAdrian Chadd 
197e913fcdaSAdrian Chadd static void
ath_printtxbuf_legacy(struct ath_softc * sc,const struct ath_buf * first_bf,u_int qnum,u_int ix,int done)198e913fcdaSAdrian Chadd ath_printtxbuf_legacy(struct ath_softc *sc, const struct ath_buf *first_bf,
1995bc8125aSAdrian Chadd 	u_int qnum, u_int ix, int done)
2005bc8125aSAdrian Chadd {
2016d24c7dbSAdrian Chadd 	const struct ath_tx_status *ts = &first_bf->bf_status.ds_txstat;
2020d5f2f26SAdrian Chadd 	const struct ath_buf *bf = first_bf;
2035bc8125aSAdrian Chadd 	struct ath_hal *ah = sc->sc_ah;
2045bc8125aSAdrian Chadd 	const struct ath_desc *ds;
2055bc8125aSAdrian Chadd 	int i;
2065bc8125aSAdrian Chadd 
2075bc8125aSAdrian Chadd 	printf("Q%u[%3u]", qnum, ix);
2080d5f2f26SAdrian Chadd 	while (bf != NULL) {
2096d24c7dbSAdrian Chadd 		printf("    (bf=%p, lastds=%p)\n", bf, first_bf->bf_lastds);
210875a9451SAdrian Chadd 		printf("        Seq: %d swtry: %d ADDBAW?: %d DOBAW?: %d\n",
2110d5f2f26SAdrian Chadd 		    bf->bf_state.bfs_seqno,
2120d5f2f26SAdrian Chadd 		    bf->bf_state.bfs_retries,
2130d5f2f26SAdrian Chadd 		    bf->bf_state.bfs_addedbaw,
2140b96ef63SAdrian Chadd 		    bf->bf_state.bfs_dobaw);
2156d24c7dbSAdrian Chadd 		for (i = 0, ds = bf->bf_desc; i < bf->bf_nseg; i++, ds++) {
2166d24c7dbSAdrian Chadd 			printf(" (DS.V:%p DS.P:%p) L:%08x D:%08x F:%04x%s\n",
2176d24c7dbSAdrian Chadd 			    ds, (const struct ath_desc *)bf->bf_daddr + i,
2186d24c7dbSAdrian Chadd 			    ds->ds_link, ds->ds_data, bf->bf_state.bfs_txflags,
2196d24c7dbSAdrian Chadd 			    !done ? "" : (ts->ts_status == 0) ? " *" : " !");
2200b96ef63SAdrian Chadd 			printf("        %08x %08x %08x %08x %08x %08x\n",
2215bc8125aSAdrian Chadd 			    ds->ds_ctl0, ds->ds_ctl1,
2220b96ef63SAdrian Chadd 			    ds->ds_hw[0], ds->ds_hw[1],
2230b96ef63SAdrian Chadd 			    ds->ds_hw[2], ds->ds_hw[3]);
224e913fcdaSAdrian Chadd 			if (ah->ah_magic == 0x20065416) {
2255bc8125aSAdrian Chadd 				printf("        %08x %08x %08x %08x %08x %08x %08x %08x\n",
2265bc8125aSAdrian Chadd 				    ds->ds_hw[4], ds->ds_hw[5], ds->ds_hw[6],
2275bc8125aSAdrian Chadd 				    ds->ds_hw[7], ds->ds_hw[8], ds->ds_hw[9],
2285bc8125aSAdrian Chadd 				    ds->ds_hw[10],ds->ds_hw[11]);
2295bc8125aSAdrian Chadd 				printf("        %08x %08x %08x %08x %08x %08x %08x %08x\n",
2305bc8125aSAdrian Chadd 				    ds->ds_hw[12],ds->ds_hw[13],ds->ds_hw[14],
2315bc8125aSAdrian Chadd 				    ds->ds_hw[15],ds->ds_hw[16],ds->ds_hw[17],
2325bc8125aSAdrian Chadd 				    ds->ds_hw[18], ds->ds_hw[19]);
2335bc8125aSAdrian Chadd 			}
2345bc8125aSAdrian Chadd 		}
2350d5f2f26SAdrian Chadd 		printf("  [end]\n");
2360d5f2f26SAdrian Chadd 		bf = bf->bf_next;
2370d5f2f26SAdrian Chadd 	}
2385bc8125aSAdrian Chadd }
2395bc8125aSAdrian Chadd 
240e913fcdaSAdrian Chadd void
ath_printtxbuf(struct ath_softc * sc,const struct ath_buf * first_bf,u_int qnum,u_int ix,int done)241e913fcdaSAdrian Chadd ath_printtxbuf(struct ath_softc *sc, const struct ath_buf *first_bf,
242e913fcdaSAdrian Chadd 	u_int qnum, u_int ix, int done)
243e913fcdaSAdrian Chadd {
244e913fcdaSAdrian Chadd 	if (sc->sc_ah->ah_magic == 0x19741014)
245e913fcdaSAdrian Chadd 		ath_printtxbuf_edma(sc, first_bf, qnum, ix, done);
246e913fcdaSAdrian Chadd 	else
247e913fcdaSAdrian Chadd 		ath_printtxbuf_legacy(sc, first_bf, qnum, ix, done);
248e913fcdaSAdrian Chadd }
249e913fcdaSAdrian Chadd 
25070ee9029SAdrian Chadd 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)25170ee9029SAdrian Chadd ath_printtxstatbuf(struct ath_softc *sc, const struct ath_buf *first_bf,
25270ee9029SAdrian Chadd 	const uint32_t *ds, u_int qnum, u_int ix, int done)
25370ee9029SAdrian Chadd {
25470ee9029SAdrian Chadd 
25570ee9029SAdrian Chadd 	printf("Q%u[%3u] ", qnum, ix);
25670ee9029SAdrian Chadd 	printf("        %08x %08x %08x %08x %08x %08x\n",
25770ee9029SAdrian Chadd 	    ds[0], ds[1], ds[2], ds[3], ds[4], ds[5]);
25870ee9029SAdrian Chadd 	printf("        %08x %08x %08x %08x %08x\n",
25970ee9029SAdrian Chadd 	    ds[6], ds[7], ds[8], ds[9], ds[10]);
26070ee9029SAdrian Chadd }
26170ee9029SAdrian Chadd 
2625bc8125aSAdrian Chadd #endif	/* ATH_DEBUG */
263