xref: /freebsd/tools/tools/ath/athstats/athstats.c (revision 04fc88d50aa58bd779f734408782520b97cb1c70)
112f961f4SSam Leffler /*-
27a314dffSSam Leffler  * Copyright (c) 2002-2007 Sam Leffler, Errno Consulting
312f961f4SSam Leffler  * All rights reserved.
412f961f4SSam Leffler  *
512f961f4SSam Leffler  * Redistribution and use in source and binary forms, with or without
612f961f4SSam Leffler  * modification, are permitted provided that the following conditions
712f961f4SSam Leffler  * are met:
812f961f4SSam Leffler  * 1. Redistributions of source code must retain the above copyright
912f961f4SSam Leffler  *    notice, this list of conditions and the following disclaimer,
1012f961f4SSam Leffler  *    without modification.
1112f961f4SSam Leffler  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1212f961f4SSam Leffler  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
1312f961f4SSam Leffler  *    redistribution must be conditioned upon including a substantially
1412f961f4SSam Leffler  *    similar Disclaimer requirement for further binary redistribution.
1512f961f4SSam Leffler  *
1612f961f4SSam Leffler  * NO WARRANTY
1712f961f4SSam Leffler  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1812f961f4SSam Leffler  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1912f961f4SSam Leffler  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
2012f961f4SSam Leffler  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
2112f961f4SSam Leffler  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
2212f961f4SSam Leffler  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2312f961f4SSam Leffler  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2412f961f4SSam Leffler  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
2512f961f4SSam Leffler  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2612f961f4SSam Leffler  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2712f961f4SSam Leffler  * THE POSSIBILITY OF SUCH DAMAGES.
2812f961f4SSam Leffler  *
2912f961f4SSam Leffler  * $FreeBSD$
3012f961f4SSam Leffler  */
3112f961f4SSam Leffler 
3212f961f4SSam Leffler /*
332f549d72SSam Leffler  * ath statistics class.
3412f961f4SSam Leffler  */
3512f961f4SSam Leffler #include <sys/types.h>
3612f961f4SSam Leffler #include <sys/file.h>
3712f961f4SSam Leffler #include <sys/sockio.h>
3812f961f4SSam Leffler #include <sys/socket.h>
3912f961f4SSam Leffler #include <net/if.h>
4012f961f4SSam Leffler #include <net/if_media.h>
4112f961f4SSam Leffler #include <net/if_var.h>
4212f961f4SSam Leffler 
4312f961f4SSam Leffler #include <stdio.h>
44207ae002SSam Leffler #include <stdlib.h>
4512f961f4SSam Leffler #include <signal.h>
462f549d72SSam Leffler #include <string.h>
472f549d72SSam Leffler #include <unistd.h>
482f549d72SSam Leffler #include <err.h>
4912f961f4SSam Leffler 
50207ae002SSam Leffler #include "ah.h"
51207ae002SSam Leffler #include "ah_desc.h"
52207ae002SSam Leffler #include "ieee80211_ioctl.h"
53207ae002SSam Leffler #include "ieee80211_radiotap.h"
54207ae002SSam Leffler #include "if_athioctl.h"
5512f961f4SSam Leffler 
562f549d72SSam Leffler #include "athstats.h"
572f549d72SSam Leffler 
584d490647SSam Leffler #ifdef ATH_SUPPORT_ANI
594d490647SSam Leffler #define HAL_EP_RND(x,mul) \
604d490647SSam Leffler 	((((x)%(mul)) >= ((mul)/2)) ? ((x) + ((mul) - 1)) / (mul) : (x)/(mul))
614d490647SSam Leffler #define HAL_RSSI(x)     HAL_EP_RND(x, HAL_RSSI_EP_MULTIPLIER)
624d490647SSam Leffler #endif
634d490647SSam Leffler 
642f549d72SSam Leffler #define	NOTPRESENT	{ 0, "", "" }
652f549d72SSam Leffler 
66207ae002SSam Leffler #define	AFTER(prev)	((prev)+1)
67207ae002SSam Leffler 
682f549d72SSam Leffler static const struct fmt athstats[] = {
692f549d72SSam Leffler #define	S_INPUT		0
702f549d72SSam Leffler 	{ 8,	"input",	"input",	"data frames received" },
71207ae002SSam Leffler #define	S_OUTPUT	AFTER(S_INPUT)
722f549d72SSam Leffler 	{ 8,	"output",	"output",	"data frames transmit" },
73207ae002SSam Leffler #define	S_TX_ALTRATE	AFTER(S_OUTPUT)
742f549d72SSam Leffler 	{ 7,	"altrate",	"altrate",	"tx frames with an alternate rate" },
75207ae002SSam Leffler #define	S_TX_SHORTRETRY	AFTER(S_TX_ALTRATE)
762f549d72SSam Leffler 	{ 7,	"short",	"short",	"short on-chip tx retries" },
77207ae002SSam Leffler #define	S_TX_LONGRETRY	AFTER(S_TX_SHORTRETRY)
782f549d72SSam Leffler 	{ 7,	"long",		"long",		"long on-chip tx retries" },
79207ae002SSam Leffler #define	S_TX_XRETRIES	AFTER(S_TX_LONGRETRY)
802f549d72SSam Leffler 	{ 6,	"xretry",	"xretry",	"tx failed 'cuz too many retries" },
81207ae002SSam Leffler #define	S_MIB		AFTER(S_TX_XRETRIES)
822f549d72SSam Leffler 	{ 5,	"mib",		"mib",		"mib overflow interrupts" },
832f549d72SSam Leffler #ifndef __linux__
84207ae002SSam Leffler #define	S_TX_LINEAR	AFTER(S_MIB)
852f549d72SSam Leffler 	{ 5,	"txlinear",	"txlinear",	"tx linearized to cluster" },
86207ae002SSam Leffler #define	S_BSTUCK	AFTER(S_TX_LINEAR)
872f549d72SSam Leffler 	{ 5,	"bstuck",	"bstuck",	"stuck beacon conditions" },
88207ae002SSam Leffler #define	S_INTRCOAL	AFTER(S_BSTUCK)
892f549d72SSam Leffler 	{ 5,	"intrcoal",	"intrcoal",	"interrupts coalesced" },
90207ae002SSam Leffler #define	S_RATE		AFTER(S_INTRCOAL)
912f549d72SSam Leffler #else
92207ae002SSam Leffler #define	S_RATE		AFTER(S_MIB)
932f549d72SSam Leffler #endif
944d490647SSam Leffler 	{ 5,	"rate",		"rate",		"current transmit rate" },
95207ae002SSam Leffler #define	S_WATCHDOG	AFTER(S_RATE)
962f549d72SSam Leffler 	{ 5,	"wdog",		"wdog",		"watchdog timeouts" },
97207ae002SSam Leffler #define	S_FATAL		AFTER(S_WATCHDOG)
982f549d72SSam Leffler 	{ 5,	"fatal",	"fatal",	"hardware error interrupts" },
99207ae002SSam Leffler #define	S_BMISS		AFTER(S_FATAL)
1002f549d72SSam Leffler 	{ 5,	"bmiss",	"bmiss",	"beacon miss interrupts" },
101207ae002SSam Leffler #define	S_RXORN		AFTER(S_BMISS)
1022f549d72SSam Leffler 	{ 5,	"rxorn",	"rxorn",	"recv overrun interrupts" },
103207ae002SSam Leffler #define	S_RXEOL		AFTER(S_RXORN)
1042f549d72SSam Leffler 	{ 5,	"rxeol",	"rxeol",	"recv eol interrupts" },
105207ae002SSam Leffler #define	S_TXURN		AFTER(S_RXEOL)
1062f549d72SSam Leffler 	{ 5,	"txurn",	"txurn",	"txmit underrun interrupts" },
107207ae002SSam Leffler #define	S_TX_MGMT	AFTER(S_TXURN)
1082f549d72SSam Leffler 	{ 5,	"txmgt",	"txmgt",	"tx management frames" },
109207ae002SSam Leffler #define	S_TX_DISCARD	AFTER(S_TX_MGMT)
1102f549d72SSam Leffler 	{ 5,	"txdisc",	"txdisc",	"tx frames discarded prior to association" },
111207ae002SSam Leffler #define	S_TX_INVALID	AFTER(S_TX_DISCARD)
1122f549d72SSam Leffler 	{ 5,	"txinv",	"txinv",	"tx invalid (19)" },
113207ae002SSam Leffler #define	S_TX_QSTOP	AFTER(S_TX_INVALID)
1142f549d72SSam Leffler 	{ 5,	"qstop",	"qstop",	"tx stopped 'cuz no xmit buffer" },
115207ae002SSam Leffler #define	S_TX_ENCAP	AFTER(S_TX_QSTOP)
1162f549d72SSam Leffler 	{ 5,	"txencode",	"txencode",	"tx encapsulation failed" },
117207ae002SSam Leffler #define	S_TX_NONODE	AFTER(S_TX_ENCAP)
1182f549d72SSam Leffler 	{ 5,	"txnonode",	"txnonode",	"tx failed 'cuz no node" },
119207ae002SSam Leffler #define	S_TX_NOMBUF	AFTER(S_TX_NONODE)
1202f549d72SSam Leffler 	{ 5,	"txnombuf",	"txnombuf",	"tx failed 'cuz mbuf allocation failed" },
1212f549d72SSam Leffler #ifndef __linux__
122207ae002SSam Leffler #define	S_TX_NOMCL	AFTER(S_TX_NOMBUF)
1232f549d72SSam Leffler 	{ 5,	"txnomcl",	"txnomcl",	"tx failed 'cuz cluster allocation failed" },
124207ae002SSam Leffler #define	S_TX_FIFOERR	AFTER(S_TX_NOMCL)
1252f549d72SSam Leffler #else
126207ae002SSam Leffler #define	S_TX_FIFOERR	AFTER(S_TX_NOMBUF)
1272f549d72SSam Leffler #endif
1282f549d72SSam Leffler 	{ 5,	"efifo",	"efifo",	"tx failed 'cuz FIFO underrun" },
129207ae002SSam Leffler #define	S_TX_FILTERED	AFTER(S_TX_FIFOERR)
1302f549d72SSam Leffler 	{ 5,	"efilt",	"efilt",	"tx failed 'cuz destination filtered" },
131207ae002SSam Leffler #define	S_TX_BADRATE	AFTER(S_TX_FILTERED)
1322f549d72SSam Leffler 	{ 5,	"txbadrate",	"txbadrate",	"tx failed 'cuz bogus xmit rate" },
133207ae002SSam Leffler #define	S_TX_NOACK	AFTER(S_TX_BADRATE)
1342f549d72SSam Leffler 	{ 5,	"noack",	"noack",	"tx frames with no ack marked" },
135207ae002SSam Leffler #define	S_TX_RTS	AFTER(S_TX_NOACK)
1362f549d72SSam Leffler 	{ 5,	"rts",		"rts",		"tx frames with rts enabled" },
137207ae002SSam Leffler #define	S_TX_CTS	AFTER(S_TX_RTS)
1382f549d72SSam Leffler 	{ 5,	"cts",		"cts",		"tx frames with cts enabled" },
139207ae002SSam Leffler #define	S_TX_SHORTPRE	AFTER(S_TX_CTS)
1402f549d72SSam Leffler 	{ 5,	"shpre",	"shpre",	"tx frames with short preamble" },
141207ae002SSam Leffler #define	S_TX_PROTECT	AFTER(S_TX_SHORTPRE)
1422f549d72SSam Leffler 	{ 5,	"protect",	"protect",	"tx frames with 11g protection" },
143207ae002SSam Leffler #define	S_RX_ORN	AFTER(S_TX_PROTECT)
1442f549d72SSam Leffler 	{ 5,	"rxorn",	"rxorn",	"rx failed 'cuz of desc overrun" },
145207ae002SSam Leffler #define	S_RX_CRC_ERR	AFTER(S_RX_ORN)
1462f549d72SSam Leffler 	{ 6,	"crcerr",	"crcerr",	"rx failed 'cuz of bad CRC" },
147207ae002SSam Leffler #define	S_RX_FIFO_ERR	AFTER(S_RX_CRC_ERR)
1482f549d72SSam Leffler 	{ 5,	"rxfifo",	"rxfifo",	"rx failed 'cuz of FIFO overrun" },
149207ae002SSam Leffler #define	S_RX_CRYPTO_ERR	AFTER(S_RX_FIFO_ERR)
1502f549d72SSam Leffler 	{ 5,	"crypt",	"crypt",	"rx failed 'cuz decryption" },
151207ae002SSam Leffler #define	S_RX_MIC_ERR	AFTER(S_RX_CRYPTO_ERR)
1522f549d72SSam Leffler 	{ 4,	"mic",		"mic",		"rx failed 'cuz MIC failure" },
153207ae002SSam Leffler #define	S_RX_TOOSHORT	AFTER(S_RX_MIC_ERR)
1542f549d72SSam Leffler 	{ 5,	"rxshort",	"rxshort",	"rx failed 'cuz frame too short" },
155207ae002SSam Leffler #define	S_RX_NOMBUF	AFTER(S_RX_TOOSHORT)
1562f549d72SSam Leffler 	{ 5,	"rxnombuf",	"rxnombuf",	"rx setup failed 'cuz no mbuf" },
157207ae002SSam Leffler #define	S_RX_MGT	AFTER(S_RX_NOMBUF)
1582f549d72SSam Leffler 	{ 5,	"rxmgt",	"rxmgt",	"rx management frames" },
159207ae002SSam Leffler #define	S_RX_CTL	AFTER(S_RX_MGT)
1602f549d72SSam Leffler 	{ 5,	"rxctl",	"rxctl",	"rx control frames" },
161207ae002SSam Leffler #define	S_RX_PHY_ERR	AFTER(S_RX_CTL)
1622f549d72SSam Leffler 	{ 7,	"phyerr",	"phyerr",	"rx failed 'cuz of PHY err" },
163207ae002SSam Leffler #define	S_RX_PHY_UNDERRUN		AFTER(S_RX_PHY_ERR)
1644d490647SSam Leffler 	{ 4,	"phyund",	"TUnd",	"transmit underrun" },
165207ae002SSam Leffler #define	S_RX_PHY_TIMING			AFTER(S_RX_PHY_UNDERRUN)
1664d490647SSam Leffler 	{ 4,	"phytim",	"Tim",	"timing error" },
167207ae002SSam Leffler #define	S_RX_PHY_PARITY			AFTER(S_RX_PHY_TIMING)
1684d490647SSam Leffler 	{ 4,	"phypar",	"IPar",	"illegal parity" },
169207ae002SSam Leffler #define	S_RX_PHY_RATE			AFTER(S_RX_PHY_PARITY)
1704d490647SSam Leffler 	{ 4,	"phyrate",	"IRate",	"illegal rate" },
171207ae002SSam Leffler #define	S_RX_PHY_LENGTH			AFTER(S_RX_PHY_RATE)
1724d490647SSam Leffler 	{ 4,	"phylen",	"ILen",		"illegal length" },
173207ae002SSam Leffler #define	S_RX_PHY_RADAR			AFTER(S_RX_PHY_LENGTH)
1744d490647SSam Leffler 	{ 4,	"phyradar",	"Radar",	"radar detect" },
175207ae002SSam Leffler #define	S_RX_PHY_SERVICE		AFTER(S_RX_PHY_RADAR)
1764d490647SSam Leffler 	{ 4,	"physervice",	"Service",	"illegal service" },
177207ae002SSam Leffler #define	S_RX_PHY_TOR			AFTER(S_RX_PHY_SERVICE)
1784d490647SSam Leffler 	{ 4,	"phytor",	"TOR",		"transmit override receive" },
179207ae002SSam Leffler #define	S_RX_PHY_OFDM_TIMING		AFTER(S_RX_PHY_TOR)
1802f549d72SSam Leffler 	{ 6,	"ofdmtim",	"ofdmtim",	"OFDM timing" },
181207ae002SSam Leffler #define	S_RX_PHY_OFDM_SIGNAL_PARITY	AFTER(S_RX_PHY_OFDM_TIMING)
1822f549d72SSam Leffler 	{ 6,	"ofdmsig",	"ofdmsig",	"OFDM illegal parity" },
183207ae002SSam Leffler #define	S_RX_PHY_OFDM_RATE_ILLEGAL	AFTER(S_RX_PHY_OFDM_SIGNAL_PARITY)
1842f549d72SSam Leffler 	{ 6,	"ofdmrate",	"ofdmrate",	"OFDM illegal rate" },
185207ae002SSam Leffler #define	S_RX_PHY_OFDM_POWER_DROP	AFTER(S_RX_PHY_OFDM_RATE_ILLEGAL)
1862f549d72SSam Leffler 	{ 6,	"ofdmpow",	"ofdmpow",	"OFDM power drop" },
187207ae002SSam Leffler #define	S_RX_PHY_OFDM_SERVICE		AFTER(S_RX_PHY_OFDM_POWER_DROP)
1882f549d72SSam Leffler 	{ 6,	"ofdmservice",	"ofdmservice",	"OFDM illegal service" },
189207ae002SSam Leffler #define	S_RX_PHY_OFDM_RESTART		AFTER(S_RX_PHY_OFDM_SERVICE)
1902f549d72SSam Leffler 	{ 6,	"ofdmrestart",	"ofdmrestart",	"OFDM restart" },
191207ae002SSam Leffler #define	S_RX_PHY_CCK_TIMING		AFTER(S_RX_PHY_OFDM_RESTART)
1922f549d72SSam Leffler 	{ 6,	"ccktim",	"ccktim",	"CCK timing" },
193207ae002SSam Leffler #define	S_RX_PHY_CCK_HEADER_CRC		AFTER(S_RX_PHY_CCK_TIMING)
1942f549d72SSam Leffler 	{ 6,	"cckhead",	"cckhead",	"CCK header crc" },
195207ae002SSam Leffler #define	S_RX_PHY_CCK_RATE_ILLEGAL	AFTER(S_RX_PHY_CCK_HEADER_CRC)
1962f549d72SSam Leffler 	{ 6,	"cckrate",	"cckrate",	"CCK illegal rate" },
197207ae002SSam Leffler #define	S_RX_PHY_CCK_SERVICE		AFTER(S_RX_PHY_CCK_RATE_ILLEGAL)
1982f549d72SSam Leffler 	{ 6,	"cckservice",	"cckservice",	"CCK illegal service" },
199207ae002SSam Leffler #define	S_RX_PHY_CCK_RESTART		AFTER(S_RX_PHY_CCK_SERVICE)
2002f549d72SSam Leffler 	{ 6,	"cckrestar",	"cckrestar",	"CCK restart" },
201207ae002SSam Leffler #define	S_BE_NOMBUF	AFTER(S_RX_PHY_CCK_RESTART)
2022f549d72SSam Leffler 	{ 4,	"benombuf",	"benombuf",	"beacon setup failed 'cuz no mbuf" },
203207ae002SSam Leffler #define	S_BE_XMIT	AFTER(S_BE_NOMBUF)
2042f549d72SSam Leffler 	{ 7,	"bexmit",	"bexmit",	"beacons transmitted" },
205207ae002SSam Leffler #define	S_PER_CAL	AFTER(S_BE_XMIT)
2062f549d72SSam Leffler 	{ 4,	"pcal",		"pcal",		"periodic calibrations" },
207207ae002SSam Leffler #define	S_PER_CALFAIL	AFTER(S_PER_CAL)
2082f549d72SSam Leffler 	{ 4,	"pcalf",	"pcalf",	"periodic calibration failures" },
209207ae002SSam Leffler #define	S_PER_RFGAIN	AFTER(S_PER_CALFAIL)
2102f549d72SSam Leffler 	{ 4,	"prfga",	"prfga",	"rfgain value change" },
211207ae002SSam Leffler #if ATH_SUPPORT_TDMA
212207ae002SSam Leffler #define	S_TDMA_UPDATE	AFTER(S_PER_RFGAIN)
2132f549d72SSam Leffler 	{ 5,	"tdmau",	"tdmau",	"TDMA slot timing updates" },
214207ae002SSam Leffler #define	S_TDMA_TIMERS	AFTER(S_TDMA_UPDATE)
2152f549d72SSam Leffler 	{ 5,	"tdmab",	"tdmab",	"TDMA slot update set beacon timers" },
216207ae002SSam Leffler #define	S_TDMA_TSF	AFTER(S_TDMA_TIMERS)
2172f549d72SSam Leffler 	{ 5,	"tdmat",	"tdmat",	"TDMA slot update set TSF" },
218207ae002SSam Leffler #define	S_RATE_CALLS	AFTER(S_TDMA_TSF)
2192f549d72SSam Leffler #else
220207ae002SSam Leffler #define	S_RATE_CALLS	AFTER(S_PER_RFGAIN)
2212f549d72SSam Leffler #endif
2222f549d72SSam Leffler 	{ 5,	"ratec",	"ratec",	"rate control checks" },
223207ae002SSam Leffler #define	S_RATE_RAISE	AFTER(S_RATE_CALLS)
2242f549d72SSam Leffler 	{ 5,	"rate+",	"rate+",	"rate control raised xmit rate" },
225207ae002SSam Leffler #define	S_RATE_DROP	AFTER(S_RATE_RAISE)
2262f549d72SSam Leffler 	{ 5,	"rate-",	"rate-",	"rate control dropped xmit rate" },
227207ae002SSam Leffler #define	S_TX_RSSI	AFTER(S_RATE_DROP)
2282f549d72SSam Leffler 	{ 4,	"arssi",	"arssi",	"rssi of last ack" },
229207ae002SSam Leffler #define	S_RX_RSSI	AFTER(S_TX_RSSI)
2302f549d72SSam Leffler 	{ 4,	"rssi",		"rssi",		"avg recv rssi" },
231207ae002SSam Leffler #define	S_RX_NOISE	AFTER(S_RX_RSSI)
2322f549d72SSam Leffler 	{ 5,	"noise",	"noise",	"rx noise floor" },
233207ae002SSam Leffler #define	S_BMISS_PHANTOM	AFTER(S_RX_NOISE)
2342f549d72SSam Leffler 	{ 5,	"bmissphantom",	"bmissphantom",	"phantom beacon misses" },
235207ae002SSam Leffler #define	S_TX_RAW	AFTER(S_BMISS_PHANTOM)
2362f549d72SSam Leffler 	{ 5,	"txraw",	"txraw",	"tx frames through raw api" },
237207ae002SSam Leffler #define	S_RX_TOOBIG	AFTER(S_TX_RAW)
2382f549d72SSam Leffler 	{ 5,	"rx2big",	"rx2big",	"rx failed 'cuz frame too large"  },
2392f549d72SSam Leffler #ifndef __linux__
240207ae002SSam Leffler #define	S_CABQ_XMIT	AFTER(S_RX_TOOBIG)
2412f549d72SSam Leffler 	{ 5,	"cabxmit",	"cabxmit",	"cabq frames transmitted" },
242207ae002SSam Leffler #define	S_CABQ_BUSY	AFTER(S_CABQ_XMIT)
2432f549d72SSam Leffler 	{ 5,	"cabqbusy",	"cabqbusy",	"cabq xmit overflowed beacon interval" },
244207ae002SSam Leffler #define	S_TX_NODATA	AFTER(S_CABQ_BUSY)
2452f549d72SSam Leffler 	{ 5,	"txnodata",	"txnodata",	"tx discarded empty frame" },
246207ae002SSam Leffler #define	S_TX_BUSDMA	AFTER(S_TX_NODATA)
2472f549d72SSam Leffler 	{ 5,	"txbusdma",	"txbusdma",	"tx failed for dma resrcs" },
248207ae002SSam Leffler #define	S_RX_BUSDMA	AFTER(S_TX_BUSDMA)
2492f549d72SSam Leffler 	{ 5,	"rxbusdma",	"rxbusdma",	"rx setup failed for dma resrcs" },
250207ae002SSam Leffler #define	S_FF_TXOK	AFTER(S_RX_BUSDMA)
2512f549d72SSam Leffler #else
252207ae002SSam Leffler #define	S_FF_TXOK	AFTER(S_RX_PHY_UNDERRUN)
2532f549d72SSam Leffler #endif
2542f549d72SSam Leffler 	{ 5,	"fftxok",	"fftxok",	"fast frames xmit successfully" },
255207ae002SSam Leffler #define	S_FF_TXERR	AFTER(S_FF_TXOK)
2562f549d72SSam Leffler 	{ 5,	"fftxerr",	"fftxerr",	"fast frames not xmit due to error" },
257207ae002SSam Leffler #define	S_FF_RX		AFTER(S_FF_TXERR)
2582f549d72SSam Leffler 	{ 5,	"ffrx",		"ffrx",		"fast frames received" },
259207ae002SSam Leffler #define	S_FF_FLUSH	AFTER(S_FF_RX)
2602f549d72SSam Leffler 	{ 5,	"ffflush",	"ffflush",	"fast frames flushed from staging q" },
261207ae002SSam Leffler #define	S_TX_QFULL	AFTER(S_FF_FLUSH)
262207ae002SSam Leffler 	{ 5,	"txqfull",	"txqfull",	"tx discarded 'cuz queue is full" },
263207ae002SSam Leffler #define	S_ANT_DEFSWITCH	AFTER(S_TX_QFULL)
2642f549d72SSam Leffler 	{ 5,	"defsw",	"defsw",	"switched default/rx antenna" },
265207ae002SSam Leffler #define	S_ANT_TXSWITCH	AFTER(S_ANT_DEFSWITCH)
2662f549d72SSam Leffler 	{ 5,	"txsw",		"txsw",		"tx used alternate antenna" },
2674d490647SSam Leffler #ifdef ATH_SUPPORT_ANI
2684d490647SSam Leffler #define	S_ANI_NOISE	AFTER(S_ANT_TXSWITCH)
2694d490647SSam Leffler 	{ 2,	"ni",	"NI",		"noise immunity level" },
2704d490647SSam Leffler #define	S_ANI_SPUR	AFTER(S_ANI_NOISE)
2714d490647SSam Leffler 	{ 2,	"si",	"SI",		"spur immunity level" },
2724d490647SSam Leffler #define	S_ANI_STEP	AFTER(S_ANI_SPUR)
2734d490647SSam Leffler 	{ 2,	"step",	"ST",		"first step level" },
2744d490647SSam Leffler #define	S_ANI_OFDM	AFTER(S_ANI_STEP)
2754d490647SSam Leffler 	{ 4,	"owsd",	"OWSD",		"OFDM weak signal detect" },
2764d490647SSam Leffler #define	S_ANI_CCK	AFTER(S_ANI_OFDM)
2774d490647SSam Leffler 	{ 4,	"cwst",	"CWST",		"CCK weak signal threshold" },
2784d490647SSam Leffler #define	S_ANI_MAXSPUR	AFTER(S_ANI_CCK)
2794d490647SSam Leffler 	{ 3,	"maxsi","MSI",		"max spur immunity level" },
2804d490647SSam Leffler #define	S_ANI_LISTEN	AFTER(S_ANI_MAXSPUR)
2814d490647SSam Leffler 	{ 6,	"listen","LISTEN",	"listen time" },
2824d490647SSam Leffler #define	S_ANI_NIUP	AFTER(S_ANI_LISTEN)
2834d490647SSam Leffler 	{ 4,	"ni+",	"NI-",		"ANI increased noise immunity" },
2844d490647SSam Leffler #define	S_ANI_NIDOWN	AFTER(S_ANI_NIUP)
2854d490647SSam Leffler 	{ 4,	"ni-",	"NI-",		"ANI decrease noise immunity" },
2864d490647SSam Leffler #define	S_ANI_SIUP	AFTER(S_ANI_NIDOWN)
2874d490647SSam Leffler 	{ 4,	"si+",	"SI+",		"ANI increased spur immunity" },
2884d490647SSam Leffler #define	S_ANI_SIDOWN	AFTER(S_ANI_SIUP)
2894d490647SSam Leffler 	{ 4,	"si-",	"SI-",		"ANI decrease spur immunity" },
2904d490647SSam Leffler #define	S_ANI_OFDMON	AFTER(S_ANI_SIDOWN)
2914d490647SSam Leffler 	{ 5,	"ofdm+","OFDM+",	"ANI enabled OFDM weak signal detect" },
2924d490647SSam Leffler #define	S_ANI_OFDMOFF	AFTER(S_ANI_OFDMON)
2934d490647SSam Leffler 	{ 5,	"ofdm-","OFDM-",	"ANI disabled OFDM weak signal detect" },
2944d490647SSam Leffler #define	S_ANI_CCKHI	AFTER(S_ANI_OFDMOFF)
2954d490647SSam Leffler 	{ 5,	"cck+",	"CCK+",		"ANI enabled CCK weak signal threshold" },
2964d490647SSam Leffler #define	S_ANI_CCKLO	AFTER(S_ANI_CCKHI)
2974d490647SSam Leffler 	{ 5,	"cck-",	"CCK-",		"ANI disabled CCK weak signal threshold" },
2984d490647SSam Leffler #define	S_ANI_STEPUP	AFTER(S_ANI_CCKLO)
2994d490647SSam Leffler 	{ 5,	"step+","STEP+",	"ANI increased first step level" },
3004d490647SSam Leffler #define	S_ANI_STEPDOWN	AFTER(S_ANI_STEPUP)
3014d490647SSam Leffler 	{ 5,	"step-","STEP-",	"ANI decreased first step level" },
3024d490647SSam Leffler #define	S_ANI_OFDMERRS	AFTER(S_ANI_STEPDOWN)
30304fc88d5SSam Leffler 	{ 8,	"ofdm",	"OFDM",		"cumulative OFDM phy error count" },
3044d490647SSam Leffler #define	S_ANI_CCKERRS	AFTER(S_ANI_OFDMERRS)
30504fc88d5SSam Leffler 	{ 8,	"cck",	"CCK",		"cumulative CCK phy error count" },
3064d490647SSam Leffler #define	S_ANI_RESET	AFTER(S_ANI_CCKERRS)
3074d490647SSam Leffler 	{ 5,	"reset","RESET",	"ANI parameters zero'd for non-STA operation" },
3084d490647SSam Leffler #define	S_ANI_LZERO	AFTER(S_ANI_RESET)
3094d490647SSam Leffler 	{ 5,	"lzero","LZERO",	"ANI forced listen time to zero" },
3104d490647SSam Leffler #define	S_ANI_LNEG	AFTER(S_ANI_LZERO)
3114d490647SSam Leffler 	{ 5,	"lneg",	"LNEG",		"ANI calculated listen time < 0" },
3124d490647SSam Leffler #define	S_MIB_ACKBAD	AFTER(S_ANI_LNEG)
31304fc88d5SSam Leffler 	{ 5,	"ackbad","ACKBAD",	"missing ACK's" },
3144d490647SSam Leffler #define	S_MIB_RTSBAD	AFTER(S_MIB_ACKBAD)
31504fc88d5SSam Leffler 	{ 5,	"rtsbad","RTSBAD",	"RTS without CTS" },
3164d490647SSam Leffler #define	S_MIB_RTSGOOD	AFTER(S_MIB_RTSBAD)
31704fc88d5SSam Leffler 	{ 5,	"rtsgood","RTSGOOD",	"successful RTS" },
3184d490647SSam Leffler #define	S_MIB_FCSBAD	AFTER(S_MIB_RTSGOOD)
3194d490647SSam Leffler 	{ 5,	"fcsbad","FCSBAD",	"bad FCS" },
3204d490647SSam Leffler #define	S_MIB_BEACONS	AFTER(S_MIB_FCSBAD)
3214d490647SSam Leffler 	{ 5,	"beacons","beacons",	"beacons received" },
3224d490647SSam Leffler #define	S_NODE_AVGBRSSI	AFTER(S_MIB_BEACONS)
3234d490647SSam Leffler 	{ 3,	"avgbrssi","BSI",	"average rssi (beacons only)" },
3244d490647SSam Leffler #define	S_NODE_AVGRSSI	AFTER(S_NODE_AVGBRSSI)
3254d490647SSam Leffler 	{ 3,	"avgrssi","DSI",	"average rssi (all rx'd frames)" },
3264d490647SSam Leffler #define	S_NODE_AVGARSSI	AFTER(S_NODE_AVGRSSI)
3274d490647SSam Leffler 	{ 3,	"avgtxrssi","TSI",	"average rssi (ACKs only)" },
3284d490647SSam Leffler #define	S_ANT_TX0	AFTER(S_NODE_AVGARSSI)
3294d490647SSam Leffler #else
330207ae002SSam Leffler #define	S_ANT_TX0	AFTER(S_ANT_TXSWITCH)
3314d490647SSam Leffler #endif /* ATH_SUPPORT_ANI */
3322f549d72SSam Leffler 	{ 8,	"tx0",	"ant0(tx)",	"frames tx on antenna 0" },
333207ae002SSam Leffler #define	S_ANT_TX1	AFTER(S_ANT_TX0)
3342f549d72SSam Leffler 	{ 8,	"tx1",	"ant1(tx)",	"frames tx on antenna 1"  },
335207ae002SSam Leffler #define	S_ANT_TX2	AFTER(S_ANT_TX1)
3362f549d72SSam Leffler 	{ 8,	"tx2",	"ant2(tx)",	"frames tx on antenna 2"  },
337207ae002SSam Leffler #define	S_ANT_TX3	AFTER(S_ANT_TX2)
3382f549d72SSam Leffler 	{ 8,	"tx3",	"ant3(tx)",	"frames tx on antenna 3"  },
339207ae002SSam Leffler #define	S_ANT_TX4	AFTER(S_ANT_TX3)
3402f549d72SSam Leffler 	{ 8,	"tx4",	"ant4(tx)",	"frames tx on antenna 4"  },
341207ae002SSam Leffler #define	S_ANT_TX5	AFTER(S_ANT_TX4)
3422f549d72SSam Leffler 	{ 8,	"tx5",	"ant5(tx)",	"frames tx on antenna 5"  },
343207ae002SSam Leffler #define	S_ANT_TX6	AFTER(S_ANT_TX5)
3442f549d72SSam Leffler 	{ 8,	"tx6",	"ant6(tx)",	"frames tx on antenna 6"  },
345207ae002SSam Leffler #define	S_ANT_TX7	AFTER(S_ANT_TX6)
3462f549d72SSam Leffler 	{ 8,	"tx7",	"ant7(tx)",	"frames tx on antenna 7"  },
347207ae002SSam Leffler #define	S_ANT_RX0	AFTER(S_ANT_TX7)
3482f549d72SSam Leffler 	{ 8,	"rx0",	"ant0(rx)",	"frames rx on antenna 0"  },
349207ae002SSam Leffler #define	S_ANT_RX1	AFTER(S_ANT_RX0)
3502f549d72SSam Leffler 	{ 8,	"rx1",	"ant1(rx)",	"frames rx on antenna 1"   },
351207ae002SSam Leffler #define	S_ANT_RX2	AFTER(S_ANT_RX1)
3522f549d72SSam Leffler 	{ 8,	"rx2",	"ant2(rx)",	"frames rx on antenna 2"   },
353207ae002SSam Leffler #define	S_ANT_RX3	AFTER(S_ANT_RX2)
3542f549d72SSam Leffler 	{ 8,	"rx3",	"ant3(rx)",	"frames rx on antenna 3"   },
355207ae002SSam Leffler #define	S_ANT_RX4	AFTER(S_ANT_RX3)
3562f549d72SSam Leffler 	{ 8,	"rx4",	"ant4(rx)",	"frames rx on antenna 4"   },
357207ae002SSam Leffler #define	S_ANT_RX5	AFTER(S_ANT_RX4)
3582f549d72SSam Leffler 	{ 8,	"rx5",	"ant5(rx)",	"frames rx on antenna 5"   },
359207ae002SSam Leffler #define	S_ANT_RX6	AFTER(S_ANT_RX5)
3602f549d72SSam Leffler 	{ 8,	"rx6",	"ant6(rx)",	"frames rx on antenna 6"   },
361207ae002SSam Leffler #define	S_ANT_RX7	AFTER(S_ANT_RX6)
3622f549d72SSam Leffler 	{ 8,	"rx7",	"ant7(rx)",	"frames rx on antenna 7"   },
363207ae002SSam Leffler #define	S_TX_SIGNAL	AFTER(S_ANT_RX7)
3642f549d72SSam Leffler 	{ 4,	"asignal",	"asig",	"signal of last ack (dBm)" },
365207ae002SSam Leffler #define	S_RX_SIGNAL	AFTER(S_TX_SIGNAL)
3662f549d72SSam Leffler 	{ 4,	"signal",	"sig",	"avg recv signal (dBm)" },
36712f961f4SSam Leffler };
3682f549d72SSam Leffler #define	S_PHY_MIN	S_RX_PHY_UNDERRUN
3692f549d72SSam Leffler #define	S_PHY_MAX	S_RX_PHY_CCK_RESTART
3702f549d72SSam Leffler #define	S_LAST		S_ANT_TX0
3712f549d72SSam Leffler #define	S_MAX	S_ANT_RX7+1
37212f961f4SSam Leffler 
373207ae002SSam Leffler struct _athstats {
374207ae002SSam Leffler 	struct ath_stats ath;
3754d490647SSam Leffler #ifdef ATH_SUPPORT_ANI
3764d490647SSam Leffler 	struct {
3774d490647SSam Leffler 		uint32_t ast_ani_niup;		/* increased noise immunity */
3784d490647SSam Leffler 		uint32_t ast_ani_nidown;	/* decreased noise immunity */
3794d490647SSam Leffler 		uint32_t ast_ani_spurup;	/* increased spur immunity */
3804d490647SSam Leffler 		uint32_t ast_ani_spurdown;	/* descreased spur immunity */
3814d490647SSam Leffler 		uint32_t ast_ani_ofdmon;	/* OFDM weak signal detect on */
3824d490647SSam Leffler 		uint32_t ast_ani_ofdmoff;	/* OFDM weak signal detect off*/
3834d490647SSam Leffler 		uint32_t ast_ani_cckhigh;	/* CCK weak signal thr high */
3844d490647SSam Leffler 		uint32_t ast_ani_ccklow;	/* CCK weak signal thr low */
3854d490647SSam Leffler 		uint32_t ast_ani_stepup;	/* increased first step level */
3864d490647SSam Leffler 		uint32_t ast_ani_stepdown;	/* decreased first step level */
3874d490647SSam Leffler 		uint32_t ast_ani_ofdmerrs;	/* cumulative ofdm phy err cnt*/
3884d490647SSam Leffler 		uint32_t ast_ani_cckerrs;	/* cumulative cck phy err cnt */
3894d490647SSam Leffler 		uint32_t ast_ani_reset;	/* params zero'd for non-STA */
3904d490647SSam Leffler 		uint32_t ast_ani_lzero;	/* listen time forced to zero */
3914d490647SSam Leffler 		uint32_t ast_ani_lneg;		/* listen time calculated < 0 */
3924d490647SSam Leffler 		HAL_MIB_STATS ast_mibstats;	/* MIB counter stats */
3934d490647SSam Leffler 		HAL_NODE_STATS ast_nodestats;	/* latest rssi stats */
3944d490647SSam Leffler 	} ani_stats;
3954d490647SSam Leffler 	struct {
3964d490647SSam Leffler 		uint8_t	noiseImmunityLevel;
3974d490647SSam Leffler 		uint8_t	spurImmunityLevel;
3984d490647SSam Leffler 		uint8_t	firstepLevel;
3994d490647SSam Leffler 		uint8_t	ofdmWeakSigDetectOff;
40004fc88d5SSam Leffler 		uint8_t	cckWeakSigThreshold;
4014d490647SSam Leffler 		uint32_t listenTime;
4024d490647SSam Leffler 	} ani_state;
4034d490647SSam Leffler #endif
404207ae002SSam Leffler };
405207ae002SSam Leffler 
4062f549d72SSam Leffler struct athstatfoo_p {
4072f549d72SSam Leffler 	struct athstatfoo base;
40812f961f4SSam Leffler 	int s;
409207ae002SSam Leffler 	int optstats;
4104d490647SSam Leffler #define	ATHSTATS_ANI	0x0001
41112f961f4SSam Leffler 	struct ifreq ifr;
412207ae002SSam Leffler 	struct ath_diag atd;
413207ae002SSam Leffler 	struct _athstats cur;
414207ae002SSam Leffler 	struct _athstats total;
4152f549d72SSam Leffler };
41612f961f4SSam Leffler 
4172f549d72SSam Leffler static void
4182f549d72SSam Leffler ath_setifname(struct athstatfoo *wf0, const char *ifname)
4192f549d72SSam Leffler {
4202f549d72SSam Leffler 	struct athstatfoo_p *wf = (struct athstatfoo_p *) wf0;
42112f961f4SSam Leffler 
4222f549d72SSam Leffler 	strncpy(wf->ifr.ifr_name, ifname, sizeof (wf->ifr.ifr_name));
4234d490647SSam Leffler #ifdef ATH_SUPPORT_ANI
4244d490647SSam Leffler 	strncpy(wf->atd.ad_name, ifname, sizeof (wf->atd.ad_name));
4254d490647SSam Leffler 	wf->optstats |= ATHSTATS_ANI;
4264d490647SSam Leffler #endif
42712f961f4SSam Leffler }
42812f961f4SSam Leffler 
4292f549d72SSam Leffler static void
430207ae002SSam Leffler ath_collect(struct athstatfoo_p *wf, struct _athstats *stats)
4312f549d72SSam Leffler {
432207ae002SSam Leffler 	wf->ifr.ifr_data = (caddr_t) &stats->ath;
4332f549d72SSam Leffler 	if (ioctl(wf->s, SIOCGATHSTATS, &wf->ifr) < 0)
4342f549d72SSam Leffler 		err(1, wf->ifr.ifr_name);
4354d490647SSam Leffler #ifdef ATH_SUPPORT_ANI
4364d490647SSam Leffler 	if (wf->optstats & ATHSTATS_ANI) {
4374d490647SSam Leffler 		wf->atd.ad_id = 5;
4384d490647SSam Leffler 		wf->atd.ad_out_data = (caddr_t) &stats->ani_state;
4394d490647SSam Leffler 		wf->atd.ad_out_size = sizeof(stats->ani_state);
4404d490647SSam Leffler 		if (ioctl(wf->s, SIOCGATHDIAG, &wf->atd) < 0) {
4414d490647SSam Leffler 			warn(wf->atd.ad_name);
4424d490647SSam Leffler 			wf->optstats &= ~ATHSTATS_ANI;
4434d490647SSam Leffler 		}
4444d490647SSam Leffler 		wf->atd.ad_id = 8;
4454d490647SSam Leffler 		wf->atd.ad_out_data = (caddr_t) &stats->ani_stats;
4464d490647SSam Leffler 		wf->atd.ad_out_size = sizeof(stats->ani_stats);
4474d490647SSam Leffler 		if (ioctl(wf->s, SIOCGATHDIAG, &wf->atd) < 0)
4484d490647SSam Leffler 			warn(wf->atd.ad_name);
4494d490647SSam Leffler 	}
4504d490647SSam Leffler #endif /* ATH_SUPPORT_ANI */
45112f961f4SSam Leffler }
4522f549d72SSam Leffler 
4532f549d72SSam Leffler static void
4542f549d72SSam Leffler ath_collect_cur(struct statfoo *sf)
4552f549d72SSam Leffler {
4562f549d72SSam Leffler 	struct athstatfoo_p *wf = (struct athstatfoo_p *) sf;
4572f549d72SSam Leffler 
4582f549d72SSam Leffler 	ath_collect(wf, &wf->cur);
4592f549d72SSam Leffler }
4602f549d72SSam Leffler 
4612f549d72SSam Leffler static void
4622f549d72SSam Leffler ath_collect_tot(struct statfoo *sf)
4632f549d72SSam Leffler {
4642f549d72SSam Leffler 	struct athstatfoo_p *wf = (struct athstatfoo_p *) sf;
4652f549d72SSam Leffler 
4662f549d72SSam Leffler 	ath_collect(wf, &wf->total);
4672f549d72SSam Leffler }
4682f549d72SSam Leffler 
4692f549d72SSam Leffler static void
4702f549d72SSam Leffler ath_update_tot(struct statfoo *sf)
4712f549d72SSam Leffler {
4722f549d72SSam Leffler 	struct athstatfoo_p *wf = (struct athstatfoo_p *) sf;
4732f549d72SSam Leffler 
4742f549d72SSam Leffler 	wf->total = wf->cur;
4752f549d72SSam Leffler }
4762f549d72SSam Leffler 
4774d490647SSam Leffler static void
4784d490647SSam Leffler snprintrate(char b[], size_t bs, int rate)
4794d490647SSam Leffler {
4804d490647SSam Leffler 	if (rate & IEEE80211_RATE_MCS)
4814d490647SSam Leffler 		snprintf(b, bs, "MCS%u", rate &~ IEEE80211_RATE_MCS);
4824d490647SSam Leffler 	else if (rate & 1)
4834d490647SSam Leffler 		snprintf(b, bs, "%u.5M", rate / 2);
4844d490647SSam Leffler 	else
4854d490647SSam Leffler 		snprintf(b, bs, "%uM", rate / 2);
4864d490647SSam Leffler }
4874d490647SSam Leffler 
4882f549d72SSam Leffler static int
4892f549d72SSam Leffler ath_get_curstat(struct statfoo *sf, int s, char b[], size_t bs)
4902f549d72SSam Leffler {
4912f549d72SSam Leffler 	struct athstatfoo_p *wf = (struct athstatfoo_p *) sf;
4922f549d72SSam Leffler #define	STAT(x) \
493207ae002SSam Leffler 	snprintf(b, bs, "%u", wf->cur.ath.ast_##x - wf->total.ath.ast_##x); return 1
4942f549d72SSam Leffler #define	PHY(x) \
495207ae002SSam Leffler 	snprintf(b, bs, "%u", wf->cur.ath.ast_rx_phy[x] - wf->total.ath.ast_rx_phy[x]); return 1
4964d490647SSam Leffler #define	ANI(x) \
4974d490647SSam Leffler 	snprintf(b, bs, "%u", wf->cur.ani_state.x); return 1
4984d490647SSam Leffler #define	ANISTAT(x) \
4994d490647SSam Leffler 	snprintf(b, bs, "%u", wf->cur.ani_stats.ast_ani_##x - wf->total.ani_stats.ast_ani_##x); return 1
5004d490647SSam Leffler #define	MIBSTAT(x) \
5014d490647SSam Leffler 	snprintf(b, bs, "%u", wf->cur.ani_stats.ast_mibstats.x - wf->total.ani_stats.ast_mibstats.x); return 1
5022f549d72SSam Leffler #define	TXANT(x) \
503207ae002SSam Leffler 	snprintf(b, bs, "%u", wf->cur.ath.ast_ant_tx[x] - wf->total.ath.ast_ant_tx[x]); return 1
5042f549d72SSam Leffler #define	RXANT(x) \
505207ae002SSam Leffler 	snprintf(b, bs, "%u", wf->cur.ath.ast_ant_rx[x] - wf->total.ath.ast_ant_rx[x]); return 1
5062f549d72SSam Leffler 
5072f549d72SSam Leffler 	switch (s) {
5082f549d72SSam Leffler 	case S_INPUT:
5092f549d72SSam Leffler 		snprintf(b, bs, "%lu",
510207ae002SSam Leffler 		    (wf->cur.ath.ast_rx_packets - wf->total.ath.ast_rx_packets) -
511207ae002SSam Leffler 		    (wf->cur.ath.ast_rx_mgt - wf->total.ath.ast_rx_mgt));
5122f549d72SSam Leffler 		return 1;
5132f549d72SSam Leffler 	case S_OUTPUT:
5142f549d72SSam Leffler 		snprintf(b, bs, "%lu",
515207ae002SSam Leffler 		    wf->cur.ath.ast_tx_packets - wf->total.ath.ast_tx_packets);
5162f549d72SSam Leffler 		return 1;
5172f549d72SSam Leffler 	case S_RATE:
5184d490647SSam Leffler 		snprintrate(b, bs, wf->cur.ath.ast_tx_rate);
5192f549d72SSam Leffler 		return 1;
5202f549d72SSam Leffler 	case S_WATCHDOG:	STAT(watchdog);
5212f549d72SSam Leffler 	case S_FATAL:		STAT(hardware);
5222f549d72SSam Leffler 	case S_BMISS:		STAT(bmiss);
5232f549d72SSam Leffler 	case S_BMISS_PHANTOM:	STAT(bmiss_phantom);
5242f549d72SSam Leffler #ifdef S_BSTUCK
5252f549d72SSam Leffler 	case S_BSTUCK:		STAT(bstuck);
5262f549d72SSam Leffler #endif
5272f549d72SSam Leffler 	case S_RXORN:		STAT(rxorn);
5282f549d72SSam Leffler 	case S_RXEOL:		STAT(rxeol);
5292f549d72SSam Leffler 	case S_TXURN:		STAT(txurn);
5302f549d72SSam Leffler 	case S_MIB:		STAT(mib);
5312f549d72SSam Leffler #ifdef S_INTRCOAL
5322f549d72SSam Leffler 	case S_INTRCOAL:	STAT(intrcoal);
5332f549d72SSam Leffler #endif
5342f549d72SSam Leffler 	case S_TX_MGMT:		STAT(tx_mgmt);
5352f549d72SSam Leffler 	case S_TX_DISCARD:	STAT(tx_discard);
5362f549d72SSam Leffler 	case S_TX_QSTOP:	STAT(tx_qstop);
5372f549d72SSam Leffler 	case S_TX_ENCAP:	STAT(tx_encap);
5382f549d72SSam Leffler 	case S_TX_NONODE:	STAT(tx_nonode);
5392f549d72SSam Leffler 	case S_TX_NOMBUF:	STAT(tx_nombuf);
5402f549d72SSam Leffler #ifdef S_TX_NOMCL
5412f549d72SSam Leffler 	case S_TX_NOMCL:	STAT(tx_nomcl);
5422f549d72SSam Leffler 	case S_TX_LINEAR:	STAT(tx_linear);
5432f549d72SSam Leffler 	case S_TX_NODATA:	STAT(tx_nodata);
5442f549d72SSam Leffler 	case S_TX_BUSDMA:	STAT(tx_busdma);
5452f549d72SSam Leffler #endif
5462f549d72SSam Leffler 	case S_TX_XRETRIES:	STAT(tx_xretries);
5472f549d72SSam Leffler 	case S_TX_FIFOERR:	STAT(tx_fifoerr);
5482f549d72SSam Leffler 	case S_TX_FILTERED:	STAT(tx_filtered);
5492f549d72SSam Leffler 	case S_TX_SHORTRETRY:	STAT(tx_shortretry);
5502f549d72SSam Leffler 	case S_TX_LONGRETRY:	STAT(tx_longretry);
5512f549d72SSam Leffler 	case S_TX_BADRATE:	STAT(tx_badrate);
5522f549d72SSam Leffler 	case S_TX_NOACK:	STAT(tx_noack);
5532f549d72SSam Leffler 	case S_TX_RTS:		STAT(tx_rts);
5542f549d72SSam Leffler 	case S_TX_CTS:		STAT(tx_cts);
5552f549d72SSam Leffler 	case S_TX_SHORTPRE:	STAT(tx_shortpre);
5562f549d72SSam Leffler 	case S_TX_ALTRATE:	STAT(tx_altrate);
5572f549d72SSam Leffler 	case S_TX_PROTECT:	STAT(tx_protect);
5582f549d72SSam Leffler 	case S_RX_NOMBUF:	STAT(rx_nombuf);
5592f549d72SSam Leffler #ifdef S_RX_BUSDMA
5602f549d72SSam Leffler 	case S_RX_BUSDMA:	STAT(rx_busdma);
5612f549d72SSam Leffler #endif
5622f549d72SSam Leffler 	case S_RX_ORN:		STAT(rx_orn);
5632f549d72SSam Leffler 	case S_RX_CRC_ERR:	STAT(rx_crcerr);
5642f549d72SSam Leffler 	case S_RX_FIFO_ERR: 	STAT(rx_fifoerr);
5652f549d72SSam Leffler 	case S_RX_CRYPTO_ERR: 	STAT(rx_badcrypt);
5662f549d72SSam Leffler 	case S_RX_MIC_ERR:	STAT(rx_badmic);
5672f549d72SSam Leffler 	case S_RX_PHY_ERR:	STAT(rx_phyerr);
5682f549d72SSam Leffler 	case S_RX_PHY_UNDERRUN:	PHY(HAL_PHYERR_UNDERRUN);
5692f549d72SSam Leffler 	case S_RX_PHY_TIMING:	PHY(HAL_PHYERR_TIMING);
5702f549d72SSam Leffler 	case S_RX_PHY_PARITY:	PHY(HAL_PHYERR_PARITY);
5712f549d72SSam Leffler 	case S_RX_PHY_RATE:	PHY(HAL_PHYERR_RATE);
5722f549d72SSam Leffler 	case S_RX_PHY_LENGTH:	PHY(HAL_PHYERR_LENGTH);
5732f549d72SSam Leffler 	case S_RX_PHY_RADAR:	PHY(HAL_PHYERR_RADAR);
5742f549d72SSam Leffler 	case S_RX_PHY_SERVICE:	PHY(HAL_PHYERR_SERVICE);
5752f549d72SSam Leffler 	case S_RX_PHY_TOR:	PHY(HAL_PHYERR_TOR);
5762f549d72SSam Leffler 	case S_RX_PHY_OFDM_TIMING:	  PHY(HAL_PHYERR_OFDM_TIMING);
5772f549d72SSam Leffler 	case S_RX_PHY_OFDM_SIGNAL_PARITY: PHY(HAL_PHYERR_OFDM_SIGNAL_PARITY);
5782f549d72SSam Leffler 	case S_RX_PHY_OFDM_RATE_ILLEGAL:  PHY(HAL_PHYERR_OFDM_RATE_ILLEGAL);
5792f549d72SSam Leffler 	case S_RX_PHY_OFDM_POWER_DROP:	  PHY(HAL_PHYERR_OFDM_POWER_DROP);
5802f549d72SSam Leffler 	case S_RX_PHY_OFDM_SERVICE:	  PHY(HAL_PHYERR_OFDM_SERVICE);
5812f549d72SSam Leffler 	case S_RX_PHY_OFDM_RESTART:	  PHY(HAL_PHYERR_OFDM_RESTART);
5822f549d72SSam Leffler 	case S_RX_PHY_CCK_TIMING:	  PHY(HAL_PHYERR_CCK_TIMING);
5832f549d72SSam Leffler 	case S_RX_PHY_CCK_HEADER_CRC:	  PHY(HAL_PHYERR_CCK_HEADER_CRC);
5842f549d72SSam Leffler 	case S_RX_PHY_CCK_RATE_ILLEGAL:	  PHY(HAL_PHYERR_CCK_RATE_ILLEGAL);
5852f549d72SSam Leffler 	case S_RX_PHY_CCK_SERVICE:	  PHY(HAL_PHYERR_CCK_SERVICE);
5862f549d72SSam Leffler 	case S_RX_PHY_CCK_RESTART:	  PHY(HAL_PHYERR_CCK_RESTART);
5872f549d72SSam Leffler 	case S_RX_TOOSHORT:	STAT(rx_tooshort);
5882f549d72SSam Leffler 	case S_RX_TOOBIG:	STAT(rx_toobig);
5892f549d72SSam Leffler 	case S_RX_MGT:		STAT(rx_mgt);
5902f549d72SSam Leffler 	case S_RX_CTL:		STAT(rx_ctl);
5912f549d72SSam Leffler 	case S_TX_RSSI:
592207ae002SSam Leffler 		snprintf(b, bs, "%d", wf->cur.ath.ast_tx_rssi);
5932f549d72SSam Leffler 		return 1;
5942f549d72SSam Leffler 	case S_RX_RSSI:
595207ae002SSam Leffler 		snprintf(b, bs, "%d", wf->cur.ath.ast_rx_rssi);
5962f549d72SSam Leffler 		return 1;
5972f549d72SSam Leffler 	case S_BE_XMIT:		STAT(be_xmit);
5982f549d72SSam Leffler 	case S_BE_NOMBUF:	STAT(be_nombuf);
5992f549d72SSam Leffler 	case S_PER_CAL:		STAT(per_cal);
6002f549d72SSam Leffler 	case S_PER_CALFAIL:	STAT(per_calfail);
6012f549d72SSam Leffler 	case S_PER_RFGAIN:	STAT(per_rfgain);
6022f549d72SSam Leffler #ifdef S_TDMA_UPDATE
6032f549d72SSam Leffler 	case S_TDMA_UPDATE:	STAT(tdma_update);
6042f549d72SSam Leffler 	case S_TDMA_TIMERS:	STAT(tdma_timers);
6052f549d72SSam Leffler 	case S_TDMA_TSF:	STAT(tdma_tsf);
6062f549d72SSam Leffler #endif
6072f549d72SSam Leffler 	case S_RATE_CALLS:	STAT(rate_calls);
6082f549d72SSam Leffler 	case S_RATE_RAISE:	STAT(rate_raise);
6092f549d72SSam Leffler 	case S_RATE_DROP:	STAT(rate_drop);
6102f549d72SSam Leffler 	case S_ANT_DEFSWITCH:	STAT(ant_defswitch);
6112f549d72SSam Leffler 	case S_ANT_TXSWITCH:	STAT(ant_txswitch);
6124d490647SSam Leffler #ifdef S_ANI_NOISE
6134d490647SSam Leffler 	case S_ANI_NOISE:	ANI(noiseImmunityLevel);
6144d490647SSam Leffler 	case S_ANI_SPUR:	ANI(spurImmunityLevel);
6154d490647SSam Leffler 	case S_ANI_STEP:	ANI(firstepLevel);
6164d490647SSam Leffler 	case S_ANI_OFDM:	ANI(ofdmWeakSigDetectOff);
61704fc88d5SSam Leffler 	case S_ANI_CCK:		ANI(cckWeakSigThreshold);
6184d490647SSam Leffler 	case S_ANI_LISTEN:	ANI(listenTime);
6194d490647SSam Leffler 	case S_ANI_NIUP:	ANISTAT(niup);
6204d490647SSam Leffler 	case S_ANI_NIDOWN:	ANISTAT(nidown);
6214d490647SSam Leffler 	case S_ANI_SIUP:	ANISTAT(spurup);
6224d490647SSam Leffler 	case S_ANI_SIDOWN:	ANISTAT(spurdown);
6234d490647SSam Leffler 	case S_ANI_OFDMON:	ANISTAT(ofdmon);
6244d490647SSam Leffler 	case S_ANI_OFDMOFF:	ANISTAT(ofdmoff);
6254d490647SSam Leffler 	case S_ANI_CCKHI:	ANISTAT(cckhigh);
6264d490647SSam Leffler 	case S_ANI_CCKLO:	ANISTAT(ccklow);
6274d490647SSam Leffler 	case S_ANI_STEPUP:	ANISTAT(stepup);
6284d490647SSam Leffler 	case S_ANI_STEPDOWN:	ANISTAT(stepdown);
6294d490647SSam Leffler 	case S_ANI_OFDMERRS:	ANISTAT(ofdmerrs);
6304d490647SSam Leffler 	case S_ANI_CCKERRS:	ANISTAT(cckerrs);
6314d490647SSam Leffler 	case S_ANI_RESET:	ANISTAT(reset);
6324d490647SSam Leffler 	case S_ANI_LZERO:	ANISTAT(lzero);
6334d490647SSam Leffler 	case S_ANI_LNEG:	ANISTAT(lneg);
6344d490647SSam Leffler 	case S_MIB_ACKBAD:	MIBSTAT(ackrcv_bad);
6354d490647SSam Leffler 	case S_MIB_RTSBAD:	MIBSTAT(rts_bad);
6364d490647SSam Leffler 	case S_MIB_RTSGOOD:	MIBSTAT(rts_good);
6374d490647SSam Leffler 	case S_MIB_FCSBAD:	MIBSTAT(fcs_bad);
6384d490647SSam Leffler 	case S_MIB_BEACONS:	MIBSTAT(beacons);
6394d490647SSam Leffler 	case S_NODE_AVGBRSSI:
6404d490647SSam Leffler 		snprintf(b, bs, "%u",
6414d490647SSam Leffler 		    HAL_RSSI(wf->cur.ani_stats.ast_nodestats.ns_avgbrssi));
6424d490647SSam Leffler 		return 1;
6434d490647SSam Leffler 	case S_NODE_AVGRSSI:
6444d490647SSam Leffler 		snprintf(b, bs, "%u",
6454d490647SSam Leffler 		    HAL_RSSI(wf->cur.ani_stats.ast_nodestats.ns_avgrssi));
6464d490647SSam Leffler 		return 1;
6474d490647SSam Leffler 	case S_NODE_AVGARSSI:
6484d490647SSam Leffler 		snprintf(b, bs, "%u",
6494d490647SSam Leffler 		    HAL_RSSI(wf->cur.ani_stats.ast_nodestats.ns_avgtxrssi));
6504d490647SSam Leffler 		return 1;
6514d490647SSam Leffler #endif
6522f549d72SSam Leffler 	case S_ANT_TX0:		TXANT(0);
6532f549d72SSam Leffler 	case S_ANT_TX1:		TXANT(1);
6542f549d72SSam Leffler 	case S_ANT_TX2:		TXANT(2);
6552f549d72SSam Leffler 	case S_ANT_TX3:		TXANT(3);
6562f549d72SSam Leffler 	case S_ANT_TX4:		TXANT(4);
6572f549d72SSam Leffler 	case S_ANT_TX5:		TXANT(5);
6582f549d72SSam Leffler 	case S_ANT_TX6:		TXANT(6);
6592f549d72SSam Leffler 	case S_ANT_TX7:		TXANT(7);
6602f549d72SSam Leffler 	case S_ANT_RX0:		RXANT(0);
6612f549d72SSam Leffler 	case S_ANT_RX1:		RXANT(1);
6622f549d72SSam Leffler 	case S_ANT_RX2:		RXANT(2);
6632f549d72SSam Leffler 	case S_ANT_RX3:		RXANT(3);
6642f549d72SSam Leffler 	case S_ANT_RX4:		RXANT(4);
6652f549d72SSam Leffler 	case S_ANT_RX5:		RXANT(5);
6662f549d72SSam Leffler 	case S_ANT_RX6:		RXANT(6);
6672f549d72SSam Leffler 	case S_ANT_RX7:		RXANT(7);
6682f549d72SSam Leffler #ifdef S_CABQ_XMIT
6692f549d72SSam Leffler 	case S_CABQ_XMIT:	STAT(cabq_xmit);
6702f549d72SSam Leffler 	case S_CABQ_BUSY:	STAT(cabq_busy);
6712f549d72SSam Leffler #endif
6722f549d72SSam Leffler 	case S_FF_TXOK:		STAT(ff_txok);
6732f549d72SSam Leffler 	case S_FF_TXERR:	STAT(ff_txerr);
674207ae002SSam Leffler 	case S_FF_RX:		STAT(ff_rx);
6752f549d72SSam Leffler 	case S_FF_FLUSH:	STAT(ff_flush);
676207ae002SSam Leffler 	case S_TX_QFULL:	STAT(tx_qfull);
6772f549d72SSam Leffler 	case S_RX_NOISE:
678207ae002SSam Leffler 		snprintf(b, bs, "%d", wf->cur.ath.ast_rx_noise);
6792f549d72SSam Leffler 		return 1;
6802f549d72SSam Leffler 	case S_TX_SIGNAL:
6812f549d72SSam Leffler 		snprintf(b, bs, "%d",
682207ae002SSam Leffler 			wf->cur.ath.ast_tx_rssi + wf->cur.ath.ast_rx_noise);
6832f549d72SSam Leffler 		return 1;
6842f549d72SSam Leffler 	case S_RX_SIGNAL:
6852f549d72SSam Leffler 		snprintf(b, bs, "%d",
686207ae002SSam Leffler 			wf->cur.ath.ast_rx_rssi + wf->cur.ath.ast_rx_noise);
6872f549d72SSam Leffler 		return 1;
6882f549d72SSam Leffler 	}
6892f549d72SSam Leffler 	b[0] = '\0';
69012f961f4SSam Leffler 	return 0;
6912f549d72SSam Leffler #undef RXANT
6922f549d72SSam Leffler #undef TXANT
6934d490647SSam Leffler #undef ANI
6944d490647SSam Leffler #undef ANISTAT
6954d490647SSam Leffler #undef MIBSTAT
6962f549d72SSam Leffler #undef PHY
6972f549d72SSam Leffler #undef STAT
6982f549d72SSam Leffler }
6992f549d72SSam Leffler 
7002f549d72SSam Leffler static int
7012f549d72SSam Leffler ath_get_totstat(struct statfoo *sf, int s, char b[], size_t bs)
7022f549d72SSam Leffler {
7032f549d72SSam Leffler 	struct athstatfoo_p *wf = (struct athstatfoo_p *) sf;
7042f549d72SSam Leffler #define	STAT(x) \
705207ae002SSam Leffler 	snprintf(b, bs, "%u", wf->total.ath.ast_##x); return 1
7062f549d72SSam Leffler #define	PHY(x) \
707207ae002SSam Leffler 	snprintf(b, bs, "%u", wf->total.ath.ast_rx_phy[x]); return 1
7084d490647SSam Leffler #define	ANI(x) \
7094d490647SSam Leffler 	snprintf(b, bs, "%u", wf->total.ani_state.x); return 1
7104d490647SSam Leffler #define	ANISTAT(x) \
7114d490647SSam Leffler 	snprintf(b, bs, "%u", wf->total.ani_stats.ast_ani_##x); return 1
7124d490647SSam Leffler #define	MIBSTAT(x) \
7134d490647SSam Leffler 	snprintf(b, bs, "%u", wf->total.ani_stats.ast_mibstats.x); return 1
7142f549d72SSam Leffler #define	TXANT(x) \
715207ae002SSam Leffler 	snprintf(b, bs, "%u", wf->total.ath.ast_ant_tx[x]); return 1
7162f549d72SSam Leffler #define	RXANT(x) \
717207ae002SSam Leffler 	snprintf(b, bs, "%u", wf->total.ath.ast_ant_rx[x]); return 1
7182f549d72SSam Leffler 
7192f549d72SSam Leffler 	switch (s) {
7202f549d72SSam Leffler 	case S_INPUT:
7212f549d72SSam Leffler 		snprintf(b, bs, "%lu",
722207ae002SSam Leffler 		    wf->total.ath.ast_rx_packets - wf->total.ath.ast_rx_mgt);
7232f549d72SSam Leffler 		return 1;
7242f549d72SSam Leffler 	case S_OUTPUT:
725207ae002SSam Leffler 		snprintf(b, bs, "%lu", wf->total.ath.ast_tx_packets);
7262f549d72SSam Leffler 		return 1;
7272f549d72SSam Leffler 	case S_RATE:
7284d490647SSam Leffler 		snprintrate(b, bs, wf->total.ath.ast_tx_rate);
7292f549d72SSam Leffler 		return 1;
7302f549d72SSam Leffler 	case S_WATCHDOG:	STAT(watchdog);
7312f549d72SSam Leffler 	case S_FATAL:		STAT(hardware);
7322f549d72SSam Leffler 	case S_BMISS:		STAT(bmiss);
7332f549d72SSam Leffler 	case S_BMISS_PHANTOM:	STAT(bmiss_phantom);
7342f549d72SSam Leffler #ifdef S_BSTUCK
7352f549d72SSam Leffler 	case S_BSTUCK:		STAT(bstuck);
7362f549d72SSam Leffler #endif
7372f549d72SSam Leffler 	case S_RXORN:		STAT(rxorn);
7382f549d72SSam Leffler 	case S_RXEOL:		STAT(rxeol);
7392f549d72SSam Leffler 	case S_TXURN:		STAT(txurn);
7402f549d72SSam Leffler 	case S_MIB:		STAT(mib);
7412f549d72SSam Leffler #ifdef S_INTRCOAL
7422f549d72SSam Leffler 	case S_INTRCOAL:	STAT(intrcoal);
7432f549d72SSam Leffler #endif
7442f549d72SSam Leffler 	case S_TX_MGMT:		STAT(tx_mgmt);
7452f549d72SSam Leffler 	case S_TX_DISCARD:	STAT(tx_discard);
7462f549d72SSam Leffler 	case S_TX_QSTOP:	STAT(tx_qstop);
7472f549d72SSam Leffler 	case S_TX_ENCAP:	STAT(tx_encap);
7482f549d72SSam Leffler 	case S_TX_NONODE:	STAT(tx_nonode);
7492f549d72SSam Leffler 	case S_TX_NOMBUF:	STAT(tx_nombuf);
7502f549d72SSam Leffler #ifdef S_TX_NOMCL
7512f549d72SSam Leffler 	case S_TX_NOMCL:	STAT(tx_nomcl);
7522f549d72SSam Leffler 	case S_TX_LINEAR:	STAT(tx_linear);
7532f549d72SSam Leffler 	case S_TX_NODATA:	STAT(tx_nodata);
7542f549d72SSam Leffler 	case S_TX_BUSDMA:	STAT(tx_busdma);
7552f549d72SSam Leffler #endif
7562f549d72SSam Leffler 	case S_TX_XRETRIES:	STAT(tx_xretries);
7572f549d72SSam Leffler 	case S_TX_FIFOERR:	STAT(tx_fifoerr);
7582f549d72SSam Leffler 	case S_TX_FILTERED:	STAT(tx_filtered);
7592f549d72SSam Leffler 	case S_TX_SHORTRETRY:	STAT(tx_shortretry);
7602f549d72SSam Leffler 	case S_TX_LONGRETRY:	STAT(tx_longretry);
7612f549d72SSam Leffler 	case S_TX_BADRATE:	STAT(tx_badrate);
7622f549d72SSam Leffler 	case S_TX_NOACK:	STAT(tx_noack);
7632f549d72SSam Leffler 	case S_TX_RTS:		STAT(tx_rts);
7642f549d72SSam Leffler 	case S_TX_CTS:		STAT(tx_cts);
7652f549d72SSam Leffler 	case S_TX_SHORTPRE:	STAT(tx_shortpre);
7662f549d72SSam Leffler 	case S_TX_ALTRATE:	STAT(tx_altrate);
7672f549d72SSam Leffler 	case S_TX_PROTECT:	STAT(tx_protect);
7682f549d72SSam Leffler 	case S_RX_NOMBUF:	STAT(rx_nombuf);
7692f549d72SSam Leffler #ifdef S_RX_BUSDMA
7702f549d72SSam Leffler 	case S_RX_BUSDMA:	STAT(rx_busdma);
7712f549d72SSam Leffler #endif
7722f549d72SSam Leffler 	case S_RX_ORN:		STAT(rx_orn);
7732f549d72SSam Leffler 	case S_RX_CRC_ERR:	STAT(rx_crcerr);
7742f549d72SSam Leffler 	case S_RX_FIFO_ERR: 	STAT(rx_fifoerr);
7752f549d72SSam Leffler 	case S_RX_CRYPTO_ERR: 	STAT(rx_badcrypt);
7762f549d72SSam Leffler 	case S_RX_MIC_ERR:	STAT(rx_badmic);
7772f549d72SSam Leffler 	case S_RX_PHY_ERR:	STAT(rx_phyerr);
7782f549d72SSam Leffler 	case S_RX_PHY_UNDERRUN:	PHY(HAL_PHYERR_UNDERRUN);
7792f549d72SSam Leffler 	case S_RX_PHY_TIMING:	PHY(HAL_PHYERR_TIMING);
7802f549d72SSam Leffler 	case S_RX_PHY_PARITY:	PHY(HAL_PHYERR_PARITY);
7812f549d72SSam Leffler 	case S_RX_PHY_RATE:	PHY(HAL_PHYERR_RATE);
7822f549d72SSam Leffler 	case S_RX_PHY_LENGTH:	PHY(HAL_PHYERR_LENGTH);
7832f549d72SSam Leffler 	case S_RX_PHY_RADAR:	PHY(HAL_PHYERR_RADAR);
7842f549d72SSam Leffler 	case S_RX_PHY_SERVICE:	PHY(HAL_PHYERR_SERVICE);
7852f549d72SSam Leffler 	case S_RX_PHY_TOR:	PHY(HAL_PHYERR_TOR);
7862f549d72SSam Leffler 	case S_RX_PHY_OFDM_TIMING:	  PHY(HAL_PHYERR_OFDM_TIMING);
7872f549d72SSam Leffler 	case S_RX_PHY_OFDM_SIGNAL_PARITY: PHY(HAL_PHYERR_OFDM_SIGNAL_PARITY);
7882f549d72SSam Leffler 	case S_RX_PHY_OFDM_RATE_ILLEGAL:  PHY(HAL_PHYERR_OFDM_RATE_ILLEGAL);
7892f549d72SSam Leffler 	case S_RX_PHY_OFDM_POWER_DROP:	  PHY(HAL_PHYERR_OFDM_POWER_DROP);
7902f549d72SSam Leffler 	case S_RX_PHY_OFDM_SERVICE:	  PHY(HAL_PHYERR_OFDM_SERVICE);
7912f549d72SSam Leffler 	case S_RX_PHY_OFDM_RESTART:	  PHY(HAL_PHYERR_OFDM_RESTART);
7922f549d72SSam Leffler 	case S_RX_PHY_CCK_TIMING:	  PHY(HAL_PHYERR_CCK_TIMING);
7932f549d72SSam Leffler 	case S_RX_PHY_CCK_HEADER_CRC:	  PHY(HAL_PHYERR_CCK_HEADER_CRC);
7942f549d72SSam Leffler 	case S_RX_PHY_CCK_RATE_ILLEGAL:	  PHY(HAL_PHYERR_CCK_RATE_ILLEGAL);
7952f549d72SSam Leffler 	case S_RX_PHY_CCK_SERVICE:	  PHY(HAL_PHYERR_CCK_SERVICE);
7962f549d72SSam Leffler 	case S_RX_PHY_CCK_RESTART:	  PHY(HAL_PHYERR_CCK_RESTART);
7972f549d72SSam Leffler 	case S_RX_TOOSHORT:	STAT(rx_tooshort);
7982f549d72SSam Leffler 	case S_RX_TOOBIG:	STAT(rx_toobig);
7992f549d72SSam Leffler 	case S_RX_MGT:		STAT(rx_mgt);
8002f549d72SSam Leffler 	case S_RX_CTL:		STAT(rx_ctl);
8012f549d72SSam Leffler 	case S_TX_RSSI:
802207ae002SSam Leffler 		snprintf(b, bs, "%d", wf->total.ath.ast_tx_rssi);
8032f549d72SSam Leffler 		return 1;
8042f549d72SSam Leffler 	case S_RX_RSSI:
805207ae002SSam Leffler 		snprintf(b, bs, "%d", wf->total.ath.ast_rx_rssi);
8062f549d72SSam Leffler 		return 1;
8072f549d72SSam Leffler 	case S_BE_XMIT:		STAT(be_xmit);
8082f549d72SSam Leffler 	case S_BE_NOMBUF:	STAT(be_nombuf);
8092f549d72SSam Leffler 	case S_PER_CAL:		STAT(per_cal);
8102f549d72SSam Leffler 	case S_PER_CALFAIL:	STAT(per_calfail);
8112f549d72SSam Leffler 	case S_PER_RFGAIN:	STAT(per_rfgain);
8122f549d72SSam Leffler #ifdef S_TDMA_UPDATE
8132f549d72SSam Leffler 	case S_TDMA_UPDATE:	STAT(tdma_update);
8142f549d72SSam Leffler 	case S_TDMA_TIMERS:	STAT(tdma_timers);
8152f549d72SSam Leffler 	case S_TDMA_TSF:	STAT(tdma_tsf);
8162f549d72SSam Leffler #endif
8172f549d72SSam Leffler 	case S_RATE_CALLS:	STAT(rate_calls);
8182f549d72SSam Leffler 	case S_RATE_RAISE:	STAT(rate_raise);
8192f549d72SSam Leffler 	case S_RATE_DROP:	STAT(rate_drop);
8202f549d72SSam Leffler 	case S_ANT_DEFSWITCH:	STAT(ant_defswitch);
8212f549d72SSam Leffler 	case S_ANT_TXSWITCH:	STAT(ant_txswitch);
8224d490647SSam Leffler #ifdef S_ANI_NOISE
8234d490647SSam Leffler 	case S_ANI_NOISE:	ANI(noiseImmunityLevel);
8244d490647SSam Leffler 	case S_ANI_SPUR:	ANI(spurImmunityLevel);
8254d490647SSam Leffler 	case S_ANI_STEP:	ANI(firstepLevel);
82604fc88d5SSam Leffler 	case S_ANI_OFDM:	ANI(ofdmWeakSigDetectOff);
82704fc88d5SSam Leffler 	case S_ANI_CCK:		ANI(cckWeakSigThreshold);
8284d490647SSam Leffler 	case S_ANI_LISTEN:	ANI(listenTime);
8294d490647SSam Leffler 	case S_ANI_NIUP:	ANISTAT(niup);
8304d490647SSam Leffler 	case S_ANI_NIDOWN:	ANISTAT(nidown);
8314d490647SSam Leffler 	case S_ANI_SIUP:	ANISTAT(spurup);
8324d490647SSam Leffler 	case S_ANI_SIDOWN:	ANISTAT(spurdown);
8334d490647SSam Leffler 	case S_ANI_OFDMON:	ANISTAT(ofdmon);
8344d490647SSam Leffler 	case S_ANI_OFDMOFF:	ANISTAT(ofdmoff);
8354d490647SSam Leffler 	case S_ANI_CCKHI:	ANISTAT(cckhigh);
8364d490647SSam Leffler 	case S_ANI_CCKLO:	ANISTAT(ccklow);
8374d490647SSam Leffler 	case S_ANI_STEPUP:	ANISTAT(stepup);
8384d490647SSam Leffler 	case S_ANI_STEPDOWN:	ANISTAT(stepdown);
8394d490647SSam Leffler 	case S_ANI_OFDMERRS:	ANISTAT(ofdmerrs);
8404d490647SSam Leffler 	case S_ANI_CCKERRS:	ANISTAT(cckerrs);
8414d490647SSam Leffler 	case S_ANI_RESET:	ANISTAT(reset);
8424d490647SSam Leffler 	case S_ANI_LZERO:	ANISTAT(lzero);
8434d490647SSam Leffler 	case S_ANI_LNEG:	ANISTAT(lneg);
8444d490647SSam Leffler 	case S_MIB_ACKBAD:	MIBSTAT(ackrcv_bad);
8454d490647SSam Leffler 	case S_MIB_RTSBAD:	MIBSTAT(rts_bad);
8464d490647SSam Leffler 	case S_MIB_RTSGOOD:	MIBSTAT(rts_good);
8474d490647SSam Leffler 	case S_MIB_FCSBAD:	MIBSTAT(fcs_bad);
8484d490647SSam Leffler 	case S_MIB_BEACONS:	MIBSTAT(beacons);
8494d490647SSam Leffler 	case S_NODE_AVGBRSSI:
8504d490647SSam Leffler 		snprintf(b, bs, "%u",
8514d490647SSam Leffler 		    HAL_RSSI(wf->total.ani_stats.ast_nodestats.ns_avgbrssi));
8524d490647SSam Leffler 		return 1;
8534d490647SSam Leffler 	case S_NODE_AVGRSSI:
8544d490647SSam Leffler 		snprintf(b, bs, "%u",
8554d490647SSam Leffler 		    HAL_RSSI(wf->total.ani_stats.ast_nodestats.ns_avgrssi));
8564d490647SSam Leffler 		return 1;
8574d490647SSam Leffler 	case S_NODE_AVGARSSI:
8584d490647SSam Leffler 		snprintf(b, bs, "%u",
8594d490647SSam Leffler 		    HAL_RSSI(wf->total.ani_stats.ast_nodestats.ns_avgtxrssi));
8604d490647SSam Leffler 		return 1;
8614d490647SSam Leffler #endif
8622f549d72SSam Leffler 	case S_ANT_TX0:		TXANT(0);
8632f549d72SSam Leffler 	case S_ANT_TX1:		TXANT(1);
8642f549d72SSam Leffler 	case S_ANT_TX2:		TXANT(2);
8652f549d72SSam Leffler 	case S_ANT_TX3:		TXANT(3);
8662f549d72SSam Leffler 	case S_ANT_TX4:		TXANT(4);
8672f549d72SSam Leffler 	case S_ANT_TX5:		TXANT(5);
8682f549d72SSam Leffler 	case S_ANT_TX6:		TXANT(6);
8692f549d72SSam Leffler 	case S_ANT_TX7:		TXANT(7);
8702f549d72SSam Leffler 	case S_ANT_RX0:		RXANT(0);
8712f549d72SSam Leffler 	case S_ANT_RX1:		RXANT(1);
8722f549d72SSam Leffler 	case S_ANT_RX2:		RXANT(2);
8732f549d72SSam Leffler 	case S_ANT_RX3:		RXANT(3);
8742f549d72SSam Leffler 	case S_ANT_RX4:		RXANT(4);
8752f549d72SSam Leffler 	case S_ANT_RX5:		RXANT(5);
8762f549d72SSam Leffler 	case S_ANT_RX6:		RXANT(6);
8772f549d72SSam Leffler 	case S_ANT_RX7:		RXANT(7);
8782f549d72SSam Leffler #ifdef S_CABQ_XMIT
8792f549d72SSam Leffler 	case S_CABQ_XMIT:	STAT(cabq_xmit);
8802f549d72SSam Leffler 	case S_CABQ_BUSY:	STAT(cabq_busy);
8812f549d72SSam Leffler #endif
8822f549d72SSam Leffler 	case S_FF_TXOK:		STAT(ff_txok);
8832f549d72SSam Leffler 	case S_FF_TXERR:	STAT(ff_txerr);
884207ae002SSam Leffler 	case S_FF_RX:		STAT(ff_rx);
8852f549d72SSam Leffler 	case S_FF_FLUSH:	STAT(ff_flush);
886207ae002SSam Leffler 	case S_TX_QFULL:	STAT(tx_qfull);
8872f549d72SSam Leffler 	case S_RX_NOISE:
888207ae002SSam Leffler 		snprintf(b, bs, "%d", wf->total.ath.ast_rx_noise);
8892f549d72SSam Leffler 		return 1;
8902f549d72SSam Leffler 	case S_TX_SIGNAL:
8912f549d72SSam Leffler 		snprintf(b, bs, "%d",
892207ae002SSam Leffler 			wf->total.ath.ast_tx_rssi + wf->total.ath.ast_rx_noise);
8932f549d72SSam Leffler 		return 1;
8942f549d72SSam Leffler 	case S_RX_SIGNAL:
8952f549d72SSam Leffler 		snprintf(b, bs, "%d",
896207ae002SSam Leffler 			wf->total.ath.ast_rx_rssi + wf->total.ath.ast_rx_noise);
8972f549d72SSam Leffler 		return 1;
8982f549d72SSam Leffler 	}
8992f549d72SSam Leffler 	b[0] = '\0';
9002f549d72SSam Leffler 	return 0;
9012f549d72SSam Leffler #undef RXANT
9022f549d72SSam Leffler #undef TXANT
9034d490647SSam Leffler #undef ANI
9044d490647SSam Leffler #undef ANISTAT
9054d490647SSam Leffler #undef MIBSTAT
9062f549d72SSam Leffler #undef PHY
9072f549d72SSam Leffler #undef STAT
9082f549d72SSam Leffler }
9092f549d72SSam Leffler 
9102f549d72SSam Leffler static void
9112f549d72SSam Leffler ath_print_verbose(struct statfoo *sf, FILE *fd)
9122f549d72SSam Leffler {
9132f549d72SSam Leffler 	struct athstatfoo_p *wf = (struct athstatfoo_p *) sf;
9142f549d72SSam Leffler #define	isphyerr(i)	(S_PHY_MIN <= i && i <= S_PHY_MAX)
915207ae002SSam Leffler 	const struct fmt *f;
9162f549d72SSam Leffler 	char s[32];
9172f549d72SSam Leffler 	const char *indent;
918207ae002SSam Leffler 	int i, width;
9192f549d72SSam Leffler 
920207ae002SSam Leffler 	width = 0;
921207ae002SSam Leffler 	for (i = 0; i < S_LAST; i++) {
922207ae002SSam Leffler 		f = &sf->stats[i];
923207ae002SSam Leffler 		if (!isphyerr(i) && f->width > width)
924207ae002SSam Leffler 			width = f->width;
925207ae002SSam Leffler 	}
9262f549d72SSam Leffler 	for (i = 0; i < S_LAST; i++) {
9272f549d72SSam Leffler 		if (ath_get_totstat(sf, i, s, sizeof(s)) && strcmp(s, "0")) {
9282f549d72SSam Leffler 			if (isphyerr(i))
9292f549d72SSam Leffler 				indent = "    ";
9302f549d72SSam Leffler 			else
9312f549d72SSam Leffler 				indent = "";
932207ae002SSam Leffler 			fprintf(fd, "%s%-*s %s\n", indent, width, s, athstats[i].desc);
9332f549d72SSam Leffler 		}
9342f549d72SSam Leffler 	}
9352f549d72SSam Leffler 	fprintf(fd, "Antenna profile:\n");
9362f549d72SSam Leffler 	for (i = 0; i < 8; i++)
937207ae002SSam Leffler 		if (wf->total.ath.ast_ant_rx[i] || wf->total.ath.ast_ant_tx[i])
9382f549d72SSam Leffler 			fprintf(fd, "[%u] tx %8u rx %8u\n", i,
939207ae002SSam Leffler 				wf->total.ath.ast_ant_tx[i],
940207ae002SSam Leffler 				wf->total.ath.ast_ant_rx[i]);
9412f549d72SSam Leffler #undef isphyerr
9422f549d72SSam Leffler }
9432f549d72SSam Leffler 
9442f549d72SSam Leffler STATFOO_DEFINE_BOUNCE(athstatfoo)
9452f549d72SSam Leffler 
9462f549d72SSam Leffler struct athstatfoo *
9472f549d72SSam Leffler athstats_new(const char *ifname, const char *fmtstring)
9482f549d72SSam Leffler {
9492f549d72SSam Leffler #define	N(a)	(sizeof(a) / sizeof(a[0]))
9502f549d72SSam Leffler 	struct athstatfoo_p *wf;
9512f549d72SSam Leffler 
9522f549d72SSam Leffler 	wf = calloc(1, sizeof(struct athstatfoo_p));
9532f549d72SSam Leffler 	if (wf != NULL) {
9542f549d72SSam Leffler 		statfoo_init(&wf->base.base, "athstats", athstats, N(athstats));
9552f549d72SSam Leffler 		/* override base methods */
9562f549d72SSam Leffler 		wf->base.base.collect_cur = ath_collect_cur;
9572f549d72SSam Leffler 		wf->base.base.collect_tot = ath_collect_tot;
9582f549d72SSam Leffler 		wf->base.base.get_curstat = ath_get_curstat;
9592f549d72SSam Leffler 		wf->base.base.get_totstat = ath_get_totstat;
9602f549d72SSam Leffler 		wf->base.base.update_tot = ath_update_tot;
9612f549d72SSam Leffler 		wf->base.base.print_verbose = ath_print_verbose;
9622f549d72SSam Leffler 
9632f549d72SSam Leffler 		/* setup bounce functions for public methods */
9642f549d72SSam Leffler 		STATFOO_BOUNCE(wf, athstatfoo);
9652f549d72SSam Leffler 
9662f549d72SSam Leffler 		/* setup our public methods */
9672f549d72SSam Leffler 		wf->base.setifname = ath_setifname;
9682f549d72SSam Leffler #if 0
9692f549d72SSam Leffler 		wf->base.setstamac = wlan_setstamac;
9702f549d72SSam Leffler #endif
9712f549d72SSam Leffler 		wf->s = socket(AF_INET, SOCK_DGRAM, 0);
9722f549d72SSam Leffler 		if (wf->s < 0)
9732f549d72SSam Leffler 			err(1, "socket");
9742f549d72SSam Leffler 
9752f549d72SSam Leffler 		ath_setifname(&wf->base, ifname);
9762f549d72SSam Leffler 		wf->base.setfmt(&wf->base, fmtstring);
9772f549d72SSam Leffler 	}
9782f549d72SSam Leffler 	return &wf->base;
9792f549d72SSam Leffler #undef N
98012f961f4SSam Leffler }
981