xref: /freebsd/tools/tools/ath/athstats/athstats.c (revision 2f549d72a2b344e7797ba7b2751ee2b171c739a2)
112f961f4SSam Leffler /*-
22f549d72SSam Leffler  * Copyright (c) 2002-2006 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  * 3. Neither the names of the above-listed copyright holders nor the names
1612f961f4SSam Leffler  *    of any contributors may be used to endorse or promote products derived
1712f961f4SSam Leffler  *    from this software without specific prior written permission.
1812f961f4SSam Leffler  *
1912f961f4SSam Leffler  * Alternatively, this software may be distributed under the terms of the
2012f961f4SSam Leffler  * GNU General Public License ("GPL") version 2 as published by the Free
2112f961f4SSam Leffler  * Software Foundation.
2212f961f4SSam Leffler  *
2312f961f4SSam Leffler  * NO WARRANTY
2412f961f4SSam Leffler  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2512f961f4SSam Leffler  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2612f961f4SSam Leffler  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
2712f961f4SSam Leffler  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
2812f961f4SSam Leffler  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
2912f961f4SSam Leffler  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3012f961f4SSam Leffler  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3112f961f4SSam Leffler  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
3212f961f4SSam Leffler  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3312f961f4SSam Leffler  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3412f961f4SSam Leffler  * THE POSSIBILITY OF SUCH DAMAGES.
3512f961f4SSam Leffler  *
3612f961f4SSam Leffler  * $FreeBSD$
3712f961f4SSam Leffler  */
3812f961f4SSam Leffler 
3912f961f4SSam Leffler /*
402f549d72SSam Leffler  * ath statistics class.
4112f961f4SSam Leffler  */
4212f961f4SSam Leffler #include <sys/types.h>
4312f961f4SSam Leffler #include <sys/file.h>
4412f961f4SSam Leffler #include <sys/sockio.h>
4512f961f4SSam Leffler #include <sys/socket.h>
4612f961f4SSam Leffler #include <net/if.h>
4712f961f4SSam Leffler #include <net/if_media.h>
4812f961f4SSam Leffler #include <net/if_var.h>
4912f961f4SSam Leffler 
5012f961f4SSam Leffler #include <stdio.h>
5112f961f4SSam Leffler #include <signal.h>
522f549d72SSam Leffler #include <string.h>
532f549d72SSam Leffler #include <unistd.h>
542f549d72SSam Leffler #include <err.h>
5512f961f4SSam Leffler 
5644301bc9SSam Leffler #include "../../../../sys/contrib/dev/ath/ah_desc.h"
5744301bc9SSam Leffler #include "../../../../sys/net80211/ieee80211_ioctl.h"
5844301bc9SSam Leffler #include "../../../../sys/net80211/ieee80211_radiotap.h"
5944301bc9SSam Leffler #include "../../../../sys/dev/ath/if_athioctl.h"
6012f961f4SSam Leffler 
612f549d72SSam Leffler #include "athstats.h"
622f549d72SSam Leffler 
632f549d72SSam Leffler #define	NOTPRESENT	{ 0, "", "" }
642f549d72SSam Leffler 
652f549d72SSam Leffler static const struct fmt athstats[] = {
662f549d72SSam Leffler #define	S_INPUT		0
672f549d72SSam Leffler 	{ 8,	"input",	"input",	"data frames received" },
682f549d72SSam Leffler #define	S_OUTPUT	1
692f549d72SSam Leffler 	{ 8,	"output",	"output",	"data frames transmit" },
702f549d72SSam Leffler #define	S_TX_ALTRATE	2
712f549d72SSam Leffler 	{ 7,	"altrate",	"altrate",	"tx frames with an alternate rate" },
722f549d72SSam Leffler #define	S_TX_SHORTRETRY	3
732f549d72SSam Leffler 	{ 7,	"short",	"short",	"short on-chip tx retries" },
742f549d72SSam Leffler #define	S_TX_LONGRETRY	4
752f549d72SSam Leffler 	{ 7,	"long",		"long",		"long on-chip tx retries" },
762f549d72SSam Leffler #define	S_TX_XRETRIES	5
772f549d72SSam Leffler 	{ 6,	"xretry",	"xretry",	"tx failed 'cuz too many retries" },
782f549d72SSam Leffler #define	S_MIB		6
792f549d72SSam Leffler 	{ 5,	"mib",		"mib",		"mib overflow interrupts" },
802f549d72SSam Leffler #ifndef __linux__
812f549d72SSam Leffler #define	S_TX_LINEAR	7
822f549d72SSam Leffler 	{ 5,	"txlinear",	"txlinear",	"tx linearized to cluster" },
832f549d72SSam Leffler #define	S_BSTUCK	8
842f549d72SSam Leffler 	{ 5,	"bstuck",	"bstuck",	"stuck beacon conditions" },
852f549d72SSam Leffler #define	S_INTRCOAL	9
862f549d72SSam Leffler 	{ 5,	"intrcoal",	"intrcoal",	"interrupts coalesced" },
872f549d72SSam Leffler #else
882f549d72SSam Leffler 	NOTPRESENT, NOTPRESENT, NOTPRESENT,
892f549d72SSam Leffler #endif
902f549d72SSam Leffler #define	S_RATE		10
912f549d72SSam Leffler 	{ 4,	"rate",		"rate",		"current transmit rate" },
922f549d72SSam Leffler #define	S_WATCHDOG	11
932f549d72SSam Leffler 	{ 5,	"wdog",		"wdog",		"watchdog timeouts" },
942f549d72SSam Leffler #define	S_FATAL		12
952f549d72SSam Leffler 	{ 5,	"fatal",	"fatal",	"hardware error interrupts" },
962f549d72SSam Leffler #define	S_BMISS		13
972f549d72SSam Leffler 	{ 5,	"bmiss",	"bmiss",	"beacon miss interrupts" },
982f549d72SSam Leffler #define	S_RXORN		14
992f549d72SSam Leffler 	{ 5,	"rxorn",	"rxorn",	"recv overrun interrupts" },
1002f549d72SSam Leffler #define	S_RXEOL		15
1012f549d72SSam Leffler 	{ 5,	"rxeol",	"rxeol",	"recv eol interrupts" },
1022f549d72SSam Leffler #define	S_TXURN		16
1032f549d72SSam Leffler 	{ 5,	"txurn",	"txurn",	"txmit underrun interrupts" },
1042f549d72SSam Leffler #define	S_TX_MGMT	17
1052f549d72SSam Leffler 	{ 5,	"txmgt",	"txmgt",	"tx management frames" },
1062f549d72SSam Leffler #define	S_TX_DISCARD	18
1072f549d72SSam Leffler 	{ 5,	"txdisc",	"txdisc",	"tx frames discarded prior to association" },
1082f549d72SSam Leffler #define	S_TX_INVALID	19
1092f549d72SSam Leffler 	{ 5,	"txinv",	"txinv",	"tx invalid (19)" },
1102f549d72SSam Leffler #define	S_TX_QSTOP	20
1112f549d72SSam Leffler 	{ 5,	"qstop",	"qstop",	"tx stopped 'cuz no xmit buffer" },
1122f549d72SSam Leffler #define	S_TX_ENCAP	21
1132f549d72SSam Leffler 	{ 5,	"txencode",	"txencode",	"tx encapsulation failed" },
1142f549d72SSam Leffler #define	S_TX_NONODE	22
1152f549d72SSam Leffler 	{ 5,	"txnonode",	"txnonode",	"tx failed 'cuz no node" },
1162f549d72SSam Leffler #define	S_TX_NOMBUF	23
1172f549d72SSam Leffler 	{ 5,	"txnombuf",	"txnombuf",	"tx failed 'cuz mbuf allocation failed" },
1182f549d72SSam Leffler #ifndef __linux__
1192f549d72SSam Leffler #define	S_TX_NOMCL	24
1202f549d72SSam Leffler 	{ 5,	"txnomcl",	"txnomcl",	"tx failed 'cuz cluster allocation failed" },
1212f549d72SSam Leffler #else
1222f549d72SSam Leffler 	NOTPRESENT,
1232f549d72SSam Leffler #endif
1242f549d72SSam Leffler #define	S_TX_FIFOERR	25
1252f549d72SSam Leffler 	{ 5,	"efifo",	"efifo",	"tx failed 'cuz FIFO underrun" },
1262f549d72SSam Leffler #define	S_TX_FILTERED	26
1272f549d72SSam Leffler 	{ 5,	"efilt",	"efilt",	"tx failed 'cuz destination filtered" },
1282f549d72SSam Leffler #define	S_TX_BADRATE	27
1292f549d72SSam Leffler 	{ 5,	"txbadrate",	"txbadrate",	"tx failed 'cuz bogus xmit rate" },
1302f549d72SSam Leffler #define	S_TX_NOACK	28
1312f549d72SSam Leffler 	{ 5,	"noack",	"noack",	"tx frames with no ack marked" },
1322f549d72SSam Leffler #define	S_TX_RTS	29
1332f549d72SSam Leffler 	{ 5,	"rts",		"rts",		"tx frames with rts enabled" },
1342f549d72SSam Leffler #define	S_TX_CTS	30
1352f549d72SSam Leffler 	{ 5,	"cts",		"cts",		"tx frames with cts enabled" },
1362f549d72SSam Leffler #define	S_TX_SHORTPRE	31
1372f549d72SSam Leffler 	{ 5,	"shpre",	"shpre",	"tx frames with short preamble" },
1382f549d72SSam Leffler #define	S_TX_PROTECT	32
1392f549d72SSam Leffler 	{ 5,	"protect",	"protect",	"tx frames with 11g protection" },
1402f549d72SSam Leffler #define	S_RX_ORN	33
1412f549d72SSam Leffler 	{ 5,	"rxorn",	"rxorn",	"rx failed 'cuz of desc overrun" },
1422f549d72SSam Leffler #define	S_RX_CRC_ERR	34
1432f549d72SSam Leffler 	{ 6,	"crcerr",	"crcerr",	"rx failed 'cuz of bad CRC" },
1442f549d72SSam Leffler #define	S_RX_FIFO_ERR	35
1452f549d72SSam Leffler 	{ 5,	"rxfifo",	"rxfifo",	"rx failed 'cuz of FIFO overrun" },
1462f549d72SSam Leffler #define	S_RX_CRYPTO_ERR	36
1472f549d72SSam Leffler 	{ 5,	"crypt",	"crypt",	"rx failed 'cuz decryption" },
1482f549d72SSam Leffler #define	S_RX_MIC_ERR	37
1492f549d72SSam Leffler 	{ 4,	"mic",		"mic",		"rx failed 'cuz MIC failure" },
1502f549d72SSam Leffler #define	S_RX_TOOSHORT	38
1512f549d72SSam Leffler 	{ 5,	"rxshort",	"rxshort",	"rx failed 'cuz frame too short" },
1522f549d72SSam Leffler #define	S_RX_NOMBUF	39
1532f549d72SSam Leffler 	{ 5,	"rxnombuf",	"rxnombuf",	"rx setup failed 'cuz no mbuf" },
1542f549d72SSam Leffler #define	S_RX_MGT	40
1552f549d72SSam Leffler 	{ 5,	"rxmgt",	"rxmgt",	"rx management frames" },
1562f549d72SSam Leffler #define	S_RX_CTL	41
1572f549d72SSam Leffler 	{ 5,	"rxctl",	"rxctl",	"rx control frames" },
1582f549d72SSam Leffler #define	S_RX_PHY_ERR	42
1592f549d72SSam Leffler 	{ 7,	"phyerr",	"phyerr",	"rx failed 'cuz of PHY err" },
1602f549d72SSam Leffler #define	S_RX_PHY_UNDERRUN		43
1612f549d72SSam Leffler 	{ 6,	"phyund",	"phyund",	"transmit underrun" },
1622f549d72SSam Leffler #define	S_RX_PHY_TIMING			44
1632f549d72SSam Leffler 	{ 6,	"phytim",	"phytim",	"timing error" },
1642f549d72SSam Leffler #define	S_RX_PHY_PARITY			45
1652f549d72SSam Leffler 	{ 6,	"phypar",	"phypar",	"illegal parity" },
1662f549d72SSam Leffler #define	S_RX_PHY_RATE			46
1672f549d72SSam Leffler 	{ 6,	"phyrate",	"phyrate",	"illegal rate" },
1682f549d72SSam Leffler #define	S_RX_PHY_LENGTH			47
1692f549d72SSam Leffler 	{ 6,	"phylen",	"phylen",	"illegal length" },
1702f549d72SSam Leffler #define	S_RX_PHY_RADAR			48
1712f549d72SSam Leffler 	{ 6,	"phyradar",	"phyradar",	"radar detect" },
1722f549d72SSam Leffler #define	S_RX_PHY_SERVICE		49
1732f549d72SSam Leffler 	{ 6,	"physervice",	"physervice",	"illegal service" },
1742f549d72SSam Leffler #define	S_RX_PHY_TOR			50
1752f549d72SSam Leffler 	{ 6,	"phytor",	"phytor",	"transmit override receive" },
1762f549d72SSam Leffler #define	S_RX_PHY_OFDM_TIMING		51
1772f549d72SSam Leffler 	{ 6,	"ofdmtim",	"ofdmtim",	"OFDM timing" },
1782f549d72SSam Leffler #define	S_RX_PHY_OFDM_SIGNAL_PARITY	52
1792f549d72SSam Leffler 	{ 6,	"ofdmsig",	"ofdmsig",	"OFDM illegal parity" },
1802f549d72SSam Leffler #define	S_RX_PHY_OFDM_RATE_ILLEGAL	53
1812f549d72SSam Leffler 	{ 6,	"ofdmrate",	"ofdmrate",	"OFDM illegal rate" },
1822f549d72SSam Leffler #define	S_RX_PHY_OFDM_POWER_DROP	54
1832f549d72SSam Leffler 	{ 6,	"ofdmpow",	"ofdmpow",	"OFDM power drop" },
1842f549d72SSam Leffler #define	S_RX_PHY_OFDM_SERVICE		55
1852f549d72SSam Leffler 	{ 6,	"ofdmservice",	"ofdmservice",	"OFDM illegal service" },
1862f549d72SSam Leffler #define	S_RX_PHY_OFDM_RESTART		56
1872f549d72SSam Leffler 	{ 6,	"ofdmrestart",	"ofdmrestart",	"OFDM restart" },
1882f549d72SSam Leffler #define	S_RX_PHY_CCK_TIMING		57
1892f549d72SSam Leffler 	{ 6,	"ccktim",	"ccktim",	"CCK timing" },
1902f549d72SSam Leffler #define	S_RX_PHY_CCK_HEADER_CRC		58
1912f549d72SSam Leffler 	{ 6,	"cckhead",	"cckhead",	"CCK header crc" },
1922f549d72SSam Leffler #define	S_RX_PHY_CCK_RATE_ILLEGAL	59
1932f549d72SSam Leffler 	{ 6,	"cckrate",	"cckrate",	"CCK illegal rate" },
1942f549d72SSam Leffler #define	S_RX_PHY_CCK_SERVICE		60
1952f549d72SSam Leffler 	{ 6,	"cckservice",	"cckservice",	"CCK illegal service" },
1962f549d72SSam Leffler #define	S_RX_PHY_CCK_RESTART		61
1972f549d72SSam Leffler 	{ 6,	"cckrestar",	"cckrestar",	"CCK restart" },
1982f549d72SSam Leffler #define	S_BE_NOMBUF	62
1992f549d72SSam Leffler 	{ 4,	"benombuf",	"benombuf",	"beacon setup failed 'cuz no mbuf" },
2002f549d72SSam Leffler #define	S_BE_XMIT	63
2012f549d72SSam Leffler 	{ 7,	"bexmit",	"bexmit",	"beacons transmitted" },
2022f549d72SSam Leffler #define	S_PER_CAL	64
2032f549d72SSam Leffler 	{ 4,	"pcal",		"pcal",		"periodic calibrations" },
2042f549d72SSam Leffler #define	S_PER_CALFAIL	65
2052f549d72SSam Leffler 	{ 4,	"pcalf",	"pcalf",	"periodic calibration failures" },
2062f549d72SSam Leffler #define	S_PER_RFGAIN	66
2072f549d72SSam Leffler 	{ 4,	"prfga",	"prfga",	"rfgain value change" },
2082f549d72SSam Leffler #if 0
2092f549d72SSam Leffler #define	S_TDMA_UPDATE	67
2102f549d72SSam Leffler 	{ 5,	"tdmau",	"tdmau",	"TDMA slot timing updates" },
2112f549d72SSam Leffler #define	S_TDMA_TIMERS	68
2122f549d72SSam Leffler 	{ 5,	"tdmab",	"tdmab",	"TDMA slot update set beacon timers" },
2132f549d72SSam Leffler #define	S_TDMA_TSF	69
2142f549d72SSam Leffler 	{ 5,	"tdmat",	"tdmat",	"TDMA slot update set TSF" },
2152f549d72SSam Leffler #else
2162f549d72SSam Leffler 	NOTPRESENT, NOTPRESENT, NOTPRESENT,
2172f549d72SSam Leffler #endif
2182f549d72SSam Leffler #define	S_RATE_CALLS	70
2192f549d72SSam Leffler 	{ 5,	"ratec",	"ratec",	"rate control checks" },
2202f549d72SSam Leffler #define	S_RATE_RAISE	71
2212f549d72SSam Leffler 	{ 5,	"rate+",	"rate+",	"rate control raised xmit rate" },
2222f549d72SSam Leffler #define	S_RATE_DROP	72
2232f549d72SSam Leffler 	{ 5,	"rate-",	"rate-",	"rate control dropped xmit rate" },
2242f549d72SSam Leffler #define	S_TX_RSSI	73
2252f549d72SSam Leffler 	{ 4,	"arssi",	"arssi",	"rssi of last ack" },
2262f549d72SSam Leffler #define	S_RX_RSSI	74
2272f549d72SSam Leffler 	{ 4,	"rssi",		"rssi",		"avg recv rssi" },
2282f549d72SSam Leffler #define	S_RX_NOISE	75
2292f549d72SSam Leffler 	{ 5,	"noise",	"noise",	"rx noise floor" },
2302f549d72SSam Leffler #define	S_BMISS_PHANTOM	76
2312f549d72SSam Leffler 	{ 5,	"bmissphantom",	"bmissphantom",	"phantom beacon misses" },
2322f549d72SSam Leffler #define	S_TX_RAW	77
2332f549d72SSam Leffler 	{ 5,	"txraw",	"txraw",	"tx frames through raw api" },
2342f549d72SSam Leffler #define	S_RX_TOOBIG	78
2352f549d72SSam Leffler 	{ 5,	"rx2big",	"rx2big",	"rx failed 'cuz frame too large"  },
2362f549d72SSam Leffler #ifndef __linux__
2372f549d72SSam Leffler #define	S_CABQ_XMIT	79
2382f549d72SSam Leffler 	{ 5,	"cabxmit",	"cabxmit",	"cabq frames transmitted" },
2392f549d72SSam Leffler #define	S_CABQ_BUSY	80
2402f549d72SSam Leffler 	{ 5,	"cabqbusy",	"cabqbusy",	"cabq xmit overflowed beacon interval" },
2412f549d72SSam Leffler #define	S_TX_NODATA	81
2422f549d72SSam Leffler 	{ 5,	"txnodata",	"txnodata",	"tx discarded empty frame" },
2432f549d72SSam Leffler #define	S_TX_BUSDMA	82
2442f549d72SSam Leffler 	{ 5,	"txbusdma",	"txbusdma",	"tx failed for dma resrcs" },
2452f549d72SSam Leffler #define	S_RX_BUSDMA	83
2462f549d72SSam Leffler 	{ 5,	"rxbusdma",	"rxbusdma",	"rx setup failed for dma resrcs" },
2472f549d72SSam Leffler #else
2482f549d72SSam Leffler 	NOTPRESENT, NOTPRESENT, NOTPRESENT, NOTPRESENT, NOTPRESENT,
2492f549d72SSam Leffler #endif
2502f549d72SSam Leffler #if 0
2512f549d72SSam Leffler #define	S_FF_TXOK	84
2522f549d72SSam Leffler 	{ 5,	"fftxok",	"fftxok",	"fast frames xmit successfully" },
2532f549d72SSam Leffler #define	S_FF_TXERR	85
2542f549d72SSam Leffler 	{ 5,	"fftxerr",	"fftxerr",	"fast frames not xmit due to error" },
2552f549d72SSam Leffler #define	S_FF_RX		86
2562f549d72SSam Leffler 	{ 5,	"ffrx",		"ffrx",		"fast frames received" },
2572f549d72SSam Leffler #define	S_FF_FLUSH	87
2582f549d72SSam Leffler 	{ 5,	"ffflush",	"ffflush",	"fast frames flushed from staging q" },
2592f549d72SSam Leffler #else
2602f549d72SSam Leffler 	NOTPRESENT, NOTPRESENT, NOTPRESENT, NOTPRESENT,
2612f549d72SSam Leffler #endif
2622f549d72SSam Leffler #define	S_ANT_DEFSWITCH	88
2632f549d72SSam Leffler 	{ 5,	"defsw",	"defsw",	"switched default/rx antenna" },
2642f549d72SSam Leffler #define	S_ANT_TXSWITCH	89
2652f549d72SSam Leffler 	{ 5,	"txsw",		"txsw",		"tx used alternate antenna" },
2662f549d72SSam Leffler #define	S_ANT_TX0	90
2672f549d72SSam Leffler 	{ 8,	"tx0",	"ant0(tx)",	"frames tx on antenna 0" },
2682f549d72SSam Leffler #define	S_ANT_TX1	91
2692f549d72SSam Leffler 	{ 8,	"tx1",	"ant1(tx)",	"frames tx on antenna 1"  },
2702f549d72SSam Leffler #define	S_ANT_TX2	92
2712f549d72SSam Leffler 	{ 8,	"tx2",	"ant2(tx)",	"frames tx on antenna 2"  },
2722f549d72SSam Leffler #define	S_ANT_TX3	93
2732f549d72SSam Leffler 	{ 8,	"tx3",	"ant3(tx)",	"frames tx on antenna 3"  },
2742f549d72SSam Leffler #define	S_ANT_TX4	94
2752f549d72SSam Leffler 	{ 8,	"tx4",	"ant4(tx)",	"frames tx on antenna 4"  },
2762f549d72SSam Leffler #define	S_ANT_TX5	95
2772f549d72SSam Leffler 	{ 8,	"tx5",	"ant5(tx)",	"frames tx on antenna 5"  },
2782f549d72SSam Leffler #define	S_ANT_TX6	96
2792f549d72SSam Leffler 	{ 8,	"tx6",	"ant6(tx)",	"frames tx on antenna 6"  },
2802f549d72SSam Leffler #define	S_ANT_TX7	97
2812f549d72SSam Leffler 	{ 8,	"tx7",	"ant7(tx)",	"frames tx on antenna 7"  },
2822f549d72SSam Leffler #define	S_ANT_RX0	98
2832f549d72SSam Leffler 	{ 8,	"rx0",	"ant0(rx)",	"frames rx on antenna 0"  },
2842f549d72SSam Leffler #define	S_ANT_RX1	99
2852f549d72SSam Leffler 	{ 8,	"rx1",	"ant1(rx)",	"frames rx on antenna 1"   },
2862f549d72SSam Leffler #define	S_ANT_RX2	100
2872f549d72SSam Leffler 	{ 8,	"rx2",	"ant2(rx)",	"frames rx on antenna 2"   },
2882f549d72SSam Leffler #define	S_ANT_RX3	101
2892f549d72SSam Leffler 	{ 8,	"rx3",	"ant3(rx)",	"frames rx on antenna 3"   },
2902f549d72SSam Leffler #define	S_ANT_RX4	102
2912f549d72SSam Leffler 	{ 8,	"rx4",	"ant4(rx)",	"frames rx on antenna 4"   },
2922f549d72SSam Leffler #define	S_ANT_RX5	103
2932f549d72SSam Leffler 	{ 8,	"rx5",	"ant5(rx)",	"frames rx on antenna 5"   },
2942f549d72SSam Leffler #define	S_ANT_RX6	104
2952f549d72SSam Leffler 	{ 8,	"rx6",	"ant6(rx)",	"frames rx on antenna 6"   },
2962f549d72SSam Leffler #define	S_ANT_RX7	105
2972f549d72SSam Leffler 	{ 8,	"rx7",	"ant7(rx)",	"frames rx on antenna 7"   },
2982f549d72SSam Leffler #define	S_TX_SIGNAL	106
2992f549d72SSam Leffler 	{ 4,	"asignal",	"asig",	"signal of last ack (dBm)" },
3002f549d72SSam Leffler #define	S_RX_SIGNAL	107
3012f549d72SSam Leffler 	{ 4,	"signal",	"sig",	"avg recv signal (dBm)" },
30212f961f4SSam Leffler };
3032f549d72SSam Leffler #define	S_PHY_MIN	S_RX_PHY_UNDERRUN
3042f549d72SSam Leffler #define	S_PHY_MAX	S_RX_PHY_CCK_RESTART
3052f549d72SSam Leffler #define	S_LAST		S_ANT_TX0
3062f549d72SSam Leffler #define	S_MAX	S_ANT_RX7+1
30712f961f4SSam Leffler 
3082f549d72SSam Leffler struct athstatfoo_p {
3092f549d72SSam Leffler 	struct athstatfoo base;
31012f961f4SSam Leffler 	int s;
31112f961f4SSam Leffler 	struct ifreq ifr;
3122f549d72SSam Leffler 	struct ath_stats cur;
3132f549d72SSam Leffler 	struct ath_stats total;
3142f549d72SSam Leffler };
31512f961f4SSam Leffler 
3162f549d72SSam Leffler static void
3172f549d72SSam Leffler ath_setifname(struct athstatfoo *wf0, const char *ifname)
3182f549d72SSam Leffler {
3192f549d72SSam Leffler 	struct athstatfoo_p *wf = (struct athstatfoo_p *) wf0;
32012f961f4SSam Leffler 
3212f549d72SSam Leffler 	strncpy(wf->ifr.ifr_name, ifname, sizeof (wf->ifr.ifr_name));
32212f961f4SSam Leffler }
32312f961f4SSam Leffler 
3242f549d72SSam Leffler static void
3252f549d72SSam Leffler ath_collect(struct athstatfoo_p *wf, struct ath_stats *stats)
3262f549d72SSam Leffler {
3272f549d72SSam Leffler 	wf->ifr.ifr_data = (caddr_t) stats;
3282f549d72SSam Leffler 	if (ioctl(wf->s, SIOCGATHSTATS, &wf->ifr) < 0)
3292f549d72SSam Leffler 		err(1, wf->ifr.ifr_name);
33012f961f4SSam Leffler }
3312f549d72SSam Leffler 
3322f549d72SSam Leffler static void
3332f549d72SSam Leffler ath_collect_cur(struct statfoo *sf)
3342f549d72SSam Leffler {
3352f549d72SSam Leffler 	struct athstatfoo_p *wf = (struct athstatfoo_p *) sf;
3362f549d72SSam Leffler 
3372f549d72SSam Leffler 	ath_collect(wf, &wf->cur);
3382f549d72SSam Leffler }
3392f549d72SSam Leffler 
3402f549d72SSam Leffler static void
3412f549d72SSam Leffler ath_collect_tot(struct statfoo *sf)
3422f549d72SSam Leffler {
3432f549d72SSam Leffler 	struct athstatfoo_p *wf = (struct athstatfoo_p *) sf;
3442f549d72SSam Leffler 
3452f549d72SSam Leffler 	ath_collect(wf, &wf->total);
3462f549d72SSam Leffler }
3472f549d72SSam Leffler 
3482f549d72SSam Leffler static void
3492f549d72SSam Leffler ath_update_tot(struct statfoo *sf)
3502f549d72SSam Leffler {
3512f549d72SSam Leffler 	struct athstatfoo_p *wf = (struct athstatfoo_p *) sf;
3522f549d72SSam Leffler 
3532f549d72SSam Leffler 	wf->total = wf->cur;
3542f549d72SSam Leffler }
3552f549d72SSam Leffler 
3562f549d72SSam Leffler static int
3572f549d72SSam Leffler ath_get_curstat(struct statfoo *sf, int s, char b[], size_t bs)
3582f549d72SSam Leffler {
3592f549d72SSam Leffler 	struct athstatfoo_p *wf = (struct athstatfoo_p *) sf;
3602f549d72SSam Leffler #define	STAT(x) \
3612f549d72SSam Leffler 	snprintf(b, bs, "%u", wf->cur.ast_##x - wf->total.ast_##x); return 1
3622f549d72SSam Leffler #define	PHY(x) \
3632f549d72SSam Leffler 	snprintf(b, bs, "%u", wf->cur.ast_rx_phy[x] - wf->total.ast_rx_phy[x]); return 1
3642f549d72SSam Leffler #define	TXANT(x) \
3652f549d72SSam Leffler 	snprintf(b, bs, "%u", wf->cur.ast_ant_tx[x] - wf->total.ast_ant_tx[x]); return 1
3662f549d72SSam Leffler #define	RXANT(x) \
3672f549d72SSam Leffler 	snprintf(b, bs, "%u", wf->cur.ast_ant_rx[x] - wf->total.ast_ant_rx[x]); return 1
3682f549d72SSam Leffler 
3692f549d72SSam Leffler 	switch (s) {
3702f549d72SSam Leffler 	case S_INPUT:
3712f549d72SSam Leffler 		snprintf(b, bs, "%lu",
3722f549d72SSam Leffler 		    (wf->cur.ast_rx_packets - wf->total.ast_rx_packets) -
3732f549d72SSam Leffler 		    (wf->cur.ast_rx_mgt - wf->total.ast_rx_mgt));
3742f549d72SSam Leffler 		return 1;
3752f549d72SSam Leffler 	case S_OUTPUT:
3762f549d72SSam Leffler 		snprintf(b, bs, "%lu",
3772f549d72SSam Leffler 		    wf->cur.ast_tx_packets - wf->total.ast_tx_packets);
3782f549d72SSam Leffler 		return 1;
3792f549d72SSam Leffler 	case S_RATE:
3802f549d72SSam Leffler 		snprintf(b, bs, "%uM", wf->cur.ast_tx_rate / 2);
3812f549d72SSam Leffler 		return 1;
3822f549d72SSam Leffler 	case S_WATCHDOG:	STAT(watchdog);
3832f549d72SSam Leffler 	case S_FATAL:		STAT(hardware);
3842f549d72SSam Leffler 	case S_BMISS:		STAT(bmiss);
3852f549d72SSam Leffler 	case S_BMISS_PHANTOM:	STAT(bmiss_phantom);
3862f549d72SSam Leffler #ifdef S_BSTUCK
3872f549d72SSam Leffler 	case S_BSTUCK:		STAT(bstuck);
3882f549d72SSam Leffler #endif
3892f549d72SSam Leffler 	case S_RXORN:		STAT(rxorn);
3902f549d72SSam Leffler 	case S_RXEOL:		STAT(rxeol);
3912f549d72SSam Leffler 	case S_TXURN:		STAT(txurn);
3922f549d72SSam Leffler 	case S_MIB:		STAT(mib);
3932f549d72SSam Leffler #ifdef S_INTRCOAL
3942f549d72SSam Leffler 	case S_INTRCOAL:	STAT(intrcoal);
3952f549d72SSam Leffler #endif
3962f549d72SSam Leffler 	case S_TX_MGMT:		STAT(tx_mgmt);
3972f549d72SSam Leffler 	case S_TX_DISCARD:	STAT(tx_discard);
3982f549d72SSam Leffler 	case S_TX_QSTOP:	STAT(tx_qstop);
3992f549d72SSam Leffler 	case S_TX_ENCAP:	STAT(tx_encap);
4002f549d72SSam Leffler 	case S_TX_NONODE:	STAT(tx_nonode);
4012f549d72SSam Leffler 	case S_TX_NOMBUF:	STAT(tx_nombuf);
4022f549d72SSam Leffler #ifdef S_TX_NOMCL
4032f549d72SSam Leffler 	case S_TX_NOMCL:	STAT(tx_nomcl);
4042f549d72SSam Leffler 	case S_TX_LINEAR:	STAT(tx_linear);
4052f549d72SSam Leffler 	case S_TX_NODATA:	STAT(tx_nodata);
4062f549d72SSam Leffler 	case S_TX_BUSDMA:	STAT(tx_busdma);
4072f549d72SSam Leffler #endif
4082f549d72SSam Leffler 	case S_TX_XRETRIES:	STAT(tx_xretries);
4092f549d72SSam Leffler 	case S_TX_FIFOERR:	STAT(tx_fifoerr);
4102f549d72SSam Leffler 	case S_TX_FILTERED:	STAT(tx_filtered);
4112f549d72SSam Leffler 	case S_TX_SHORTRETRY:	STAT(tx_shortretry);
4122f549d72SSam Leffler 	case S_TX_LONGRETRY:	STAT(tx_longretry);
4132f549d72SSam Leffler 	case S_TX_BADRATE:	STAT(tx_badrate);
4142f549d72SSam Leffler 	case S_TX_NOACK:	STAT(tx_noack);
4152f549d72SSam Leffler 	case S_TX_RTS:		STAT(tx_rts);
4162f549d72SSam Leffler 	case S_TX_CTS:		STAT(tx_cts);
4172f549d72SSam Leffler 	case S_TX_SHORTPRE:	STAT(tx_shortpre);
4182f549d72SSam Leffler 	case S_TX_ALTRATE:	STAT(tx_altrate);
4192f549d72SSam Leffler 	case S_TX_PROTECT:	STAT(tx_protect);
4202f549d72SSam Leffler 	case S_RX_NOMBUF:	STAT(rx_nombuf);
4212f549d72SSam Leffler #ifdef S_RX_BUSDMA
4222f549d72SSam Leffler 	case S_RX_BUSDMA:	STAT(rx_busdma);
4232f549d72SSam Leffler #endif
4242f549d72SSam Leffler 	case S_RX_ORN:		STAT(rx_orn);
4252f549d72SSam Leffler 	case S_RX_CRC_ERR:	STAT(rx_crcerr);
4262f549d72SSam Leffler 	case S_RX_FIFO_ERR: 	STAT(rx_fifoerr);
4272f549d72SSam Leffler 	case S_RX_CRYPTO_ERR: 	STAT(rx_badcrypt);
4282f549d72SSam Leffler 	case S_RX_MIC_ERR:	STAT(rx_badmic);
4292f549d72SSam Leffler 	case S_RX_PHY_ERR:	STAT(rx_phyerr);
4302f549d72SSam Leffler 	case S_RX_PHY_UNDERRUN:	PHY(HAL_PHYERR_UNDERRUN);
4312f549d72SSam Leffler 	case S_RX_PHY_TIMING:	PHY(HAL_PHYERR_TIMING);
4322f549d72SSam Leffler 	case S_RX_PHY_PARITY:	PHY(HAL_PHYERR_PARITY);
4332f549d72SSam Leffler 	case S_RX_PHY_RATE:	PHY(HAL_PHYERR_RATE);
4342f549d72SSam Leffler 	case S_RX_PHY_LENGTH:	PHY(HAL_PHYERR_LENGTH);
4352f549d72SSam Leffler 	case S_RX_PHY_RADAR:	PHY(HAL_PHYERR_RADAR);
4362f549d72SSam Leffler 	case S_RX_PHY_SERVICE:	PHY(HAL_PHYERR_SERVICE);
4372f549d72SSam Leffler 	case S_RX_PHY_TOR:	PHY(HAL_PHYERR_TOR);
4382f549d72SSam Leffler 	case S_RX_PHY_OFDM_TIMING:	  PHY(HAL_PHYERR_OFDM_TIMING);
4392f549d72SSam Leffler 	case S_RX_PHY_OFDM_SIGNAL_PARITY: PHY(HAL_PHYERR_OFDM_SIGNAL_PARITY);
4402f549d72SSam Leffler 	case S_RX_PHY_OFDM_RATE_ILLEGAL:  PHY(HAL_PHYERR_OFDM_RATE_ILLEGAL);
4412f549d72SSam Leffler 	case S_RX_PHY_OFDM_POWER_DROP:	  PHY(HAL_PHYERR_OFDM_POWER_DROP);
4422f549d72SSam Leffler 	case S_RX_PHY_OFDM_SERVICE:	  PHY(HAL_PHYERR_OFDM_SERVICE);
4432f549d72SSam Leffler 	case S_RX_PHY_OFDM_RESTART:	  PHY(HAL_PHYERR_OFDM_RESTART);
4442f549d72SSam Leffler 	case S_RX_PHY_CCK_TIMING:	  PHY(HAL_PHYERR_CCK_TIMING);
4452f549d72SSam Leffler 	case S_RX_PHY_CCK_HEADER_CRC:	  PHY(HAL_PHYERR_CCK_HEADER_CRC);
4462f549d72SSam Leffler 	case S_RX_PHY_CCK_RATE_ILLEGAL:	  PHY(HAL_PHYERR_CCK_RATE_ILLEGAL);
4472f549d72SSam Leffler 	case S_RX_PHY_CCK_SERVICE:	  PHY(HAL_PHYERR_CCK_SERVICE);
4482f549d72SSam Leffler 	case S_RX_PHY_CCK_RESTART:	  PHY(HAL_PHYERR_CCK_RESTART);
4492f549d72SSam Leffler 	case S_RX_TOOSHORT:	STAT(rx_tooshort);
4502f549d72SSam Leffler 	case S_RX_TOOBIG:	STAT(rx_toobig);
4512f549d72SSam Leffler 	case S_RX_MGT:		STAT(rx_mgt);
4522f549d72SSam Leffler 	case S_RX_CTL:		STAT(rx_ctl);
4532f549d72SSam Leffler 	case S_TX_RSSI:
4542f549d72SSam Leffler 		snprintf(b, bs, "%d", wf->cur.ast_tx_rssi);
4552f549d72SSam Leffler 		return 1;
4562f549d72SSam Leffler 	case S_RX_RSSI:
4572f549d72SSam Leffler 		snprintf(b, bs, "%d", wf->cur.ast_rx_rssi);
4582f549d72SSam Leffler 		return 1;
4592f549d72SSam Leffler 	case S_BE_XMIT:		STAT(be_xmit);
4602f549d72SSam Leffler 	case S_BE_NOMBUF:	STAT(be_nombuf);
4612f549d72SSam Leffler 	case S_PER_CAL:		STAT(per_cal);
4622f549d72SSam Leffler 	case S_PER_CALFAIL:	STAT(per_calfail);
4632f549d72SSam Leffler 	case S_PER_RFGAIN:	STAT(per_rfgain);
4642f549d72SSam Leffler #ifdef S_TDMA_UPDATE
4652f549d72SSam Leffler 	case S_TDMA_UPDATE:	STAT(tdma_update);
4662f549d72SSam Leffler 	case S_TDMA_TIMERS:	STAT(tdma_timers);
4672f549d72SSam Leffler 	case S_TDMA_TSF:	STAT(tdma_tsf);
4682f549d72SSam Leffler #endif
4692f549d72SSam Leffler 	case S_RATE_CALLS:	STAT(rate_calls);
4702f549d72SSam Leffler 	case S_RATE_RAISE:	STAT(rate_raise);
4712f549d72SSam Leffler 	case S_RATE_DROP:	STAT(rate_drop);
4722f549d72SSam Leffler 	case S_ANT_DEFSWITCH:	STAT(ant_defswitch);
4732f549d72SSam Leffler 	case S_ANT_TXSWITCH:	STAT(ant_txswitch);
4742f549d72SSam Leffler 	case S_ANT_TX0:		TXANT(0);
4752f549d72SSam Leffler 	case S_ANT_TX1:		TXANT(1);
4762f549d72SSam Leffler 	case S_ANT_TX2:		TXANT(2);
4772f549d72SSam Leffler 	case S_ANT_TX3:		TXANT(3);
4782f549d72SSam Leffler 	case S_ANT_TX4:		TXANT(4);
4792f549d72SSam Leffler 	case S_ANT_TX5:		TXANT(5);
4802f549d72SSam Leffler 	case S_ANT_TX6:		TXANT(6);
4812f549d72SSam Leffler 	case S_ANT_TX7:		TXANT(7);
4822f549d72SSam Leffler 	case S_ANT_RX0:		RXANT(0);
4832f549d72SSam Leffler 	case S_ANT_RX1:		RXANT(1);
4842f549d72SSam Leffler 	case S_ANT_RX2:		RXANT(2);
4852f549d72SSam Leffler 	case S_ANT_RX3:		RXANT(3);
4862f549d72SSam Leffler 	case S_ANT_RX4:		RXANT(4);
4872f549d72SSam Leffler 	case S_ANT_RX5:		RXANT(5);
4882f549d72SSam Leffler 	case S_ANT_RX6:		RXANT(6);
4892f549d72SSam Leffler 	case S_ANT_RX7:		RXANT(7);
4902f549d72SSam Leffler #ifdef S_CABQ_XMIT
4912f549d72SSam Leffler 	case S_CABQ_XMIT:	STAT(cabq_xmit);
4922f549d72SSam Leffler 	case S_CABQ_BUSY:	STAT(cabq_busy);
4932f549d72SSam Leffler #endif
4942f549d72SSam Leffler #ifdef S_FF_TXOK
4952f549d72SSam Leffler 	case S_FF_TXOK:		STAT(ff_txok);
4962f549d72SSam Leffler 	case S_FF_TXERR:	STAT(ff_txerr);
4972f549d72SSam Leffler 	case S_FF_FLUSH:	STAT(ff_flush);
4982f549d72SSam Leffler 	case S_FF_QFULL:	STAT(ff_qfull);
4992f549d72SSam Leffler #endif
5002f549d72SSam Leffler 	case S_RX_NOISE:
5012f549d72SSam Leffler 		snprintf(b, bs, "%d", wf->cur.ast_rx_noise);
5022f549d72SSam Leffler 		return 1;
5032f549d72SSam Leffler 	case S_TX_SIGNAL:
5042f549d72SSam Leffler 		snprintf(b, bs, "%d",
5052f549d72SSam Leffler 			wf->cur.ast_tx_rssi + wf->cur.ast_rx_noise);
5062f549d72SSam Leffler 		return 1;
5072f549d72SSam Leffler 	case S_RX_SIGNAL:
5082f549d72SSam Leffler 		snprintf(b, bs, "%d",
5092f549d72SSam Leffler 			wf->cur.ast_rx_rssi + wf->cur.ast_rx_noise);
5102f549d72SSam Leffler 		return 1;
5112f549d72SSam Leffler 	}
5122f549d72SSam Leffler 	b[0] = '\0';
51312f961f4SSam Leffler 	return 0;
5142f549d72SSam Leffler #undef RXANT
5152f549d72SSam Leffler #undef TXANT
5162f549d72SSam Leffler #undef PHY
5172f549d72SSam Leffler #undef STAT
5182f549d72SSam Leffler }
5192f549d72SSam Leffler 
5202f549d72SSam Leffler static int
5212f549d72SSam Leffler ath_get_totstat(struct statfoo *sf, int s, char b[], size_t bs)
5222f549d72SSam Leffler {
5232f549d72SSam Leffler 	struct athstatfoo_p *wf = (struct athstatfoo_p *) sf;
5242f549d72SSam Leffler #define	STAT(x) \
5252f549d72SSam Leffler 	snprintf(b, bs, "%u", wf->total.ast_##x); return 1
5262f549d72SSam Leffler #define	PHY(x) \
5272f549d72SSam Leffler 	snprintf(b, bs, "%u", wf->total.ast_rx_phy[x]); return 1
5282f549d72SSam Leffler #define	TXANT(x) \
5292f549d72SSam Leffler 	snprintf(b, bs, "%u", wf->total.ast_ant_tx[x]); return 1
5302f549d72SSam Leffler #define	RXANT(x) \
5312f549d72SSam Leffler 	snprintf(b, bs, "%u", wf->total.ast_ant_rx[x]); return 1
5322f549d72SSam Leffler 
5332f549d72SSam Leffler 	switch (s) {
5342f549d72SSam Leffler 	case S_INPUT:
5352f549d72SSam Leffler 		snprintf(b, bs, "%lu",
5362f549d72SSam Leffler 		    wf->total.ast_rx_packets - wf->total.ast_rx_mgt);
5372f549d72SSam Leffler 		return 1;
5382f549d72SSam Leffler 	case S_OUTPUT:
5392f549d72SSam Leffler 		snprintf(b, bs, "%lu", wf->total.ast_tx_packets);
5402f549d72SSam Leffler 		return 1;
5412f549d72SSam Leffler 	case S_RATE:
5422f549d72SSam Leffler 		snprintf(b, bs, "%uM", wf->total.ast_tx_rate / 2);
5432f549d72SSam Leffler 		return 1;
5442f549d72SSam Leffler 	case S_WATCHDOG:	STAT(watchdog);
5452f549d72SSam Leffler 	case S_FATAL:		STAT(hardware);
5462f549d72SSam Leffler 	case S_BMISS:		STAT(bmiss);
5472f549d72SSam Leffler 	case S_BMISS_PHANTOM:	STAT(bmiss_phantom);
5482f549d72SSam Leffler #ifdef S_BSTUCK
5492f549d72SSam Leffler 	case S_BSTUCK:		STAT(bstuck);
5502f549d72SSam Leffler #endif
5512f549d72SSam Leffler 	case S_RXORN:		STAT(rxorn);
5522f549d72SSam Leffler 	case S_RXEOL:		STAT(rxeol);
5532f549d72SSam Leffler 	case S_TXURN:		STAT(txurn);
5542f549d72SSam Leffler 	case S_MIB:		STAT(mib);
5552f549d72SSam Leffler #ifdef S_INTRCOAL
5562f549d72SSam Leffler 	case S_INTRCOAL:	STAT(intrcoal);
5572f549d72SSam Leffler #endif
5582f549d72SSam Leffler 	case S_TX_MGMT:		STAT(tx_mgmt);
5592f549d72SSam Leffler 	case S_TX_DISCARD:	STAT(tx_discard);
5602f549d72SSam Leffler 	case S_TX_QSTOP:	STAT(tx_qstop);
5612f549d72SSam Leffler 	case S_TX_ENCAP:	STAT(tx_encap);
5622f549d72SSam Leffler 	case S_TX_NONODE:	STAT(tx_nonode);
5632f549d72SSam Leffler 	case S_TX_NOMBUF:	STAT(tx_nombuf);
5642f549d72SSam Leffler #ifdef S_TX_NOMCL
5652f549d72SSam Leffler 	case S_TX_NOMCL:	STAT(tx_nomcl);
5662f549d72SSam Leffler 	case S_TX_LINEAR:	STAT(tx_linear);
5672f549d72SSam Leffler 	case S_TX_NODATA:	STAT(tx_nodata);
5682f549d72SSam Leffler 	case S_TX_BUSDMA:	STAT(tx_busdma);
5692f549d72SSam Leffler #endif
5702f549d72SSam Leffler 	case S_TX_XRETRIES:	STAT(tx_xretries);
5712f549d72SSam Leffler 	case S_TX_FIFOERR:	STAT(tx_fifoerr);
5722f549d72SSam Leffler 	case S_TX_FILTERED:	STAT(tx_filtered);
5732f549d72SSam Leffler 	case S_TX_SHORTRETRY:	STAT(tx_shortretry);
5742f549d72SSam Leffler 	case S_TX_LONGRETRY:	STAT(tx_longretry);
5752f549d72SSam Leffler 	case S_TX_BADRATE:	STAT(tx_badrate);
5762f549d72SSam Leffler 	case S_TX_NOACK:	STAT(tx_noack);
5772f549d72SSam Leffler 	case S_TX_RTS:		STAT(tx_rts);
5782f549d72SSam Leffler 	case S_TX_CTS:		STAT(tx_cts);
5792f549d72SSam Leffler 	case S_TX_SHORTPRE:	STAT(tx_shortpre);
5802f549d72SSam Leffler 	case S_TX_ALTRATE:	STAT(tx_altrate);
5812f549d72SSam Leffler 	case S_TX_PROTECT:	STAT(tx_protect);
5822f549d72SSam Leffler 	case S_RX_NOMBUF:	STAT(rx_nombuf);
5832f549d72SSam Leffler #ifdef S_RX_BUSDMA
5842f549d72SSam Leffler 	case S_RX_BUSDMA:	STAT(rx_busdma);
5852f549d72SSam Leffler #endif
5862f549d72SSam Leffler 	case S_RX_ORN:		STAT(rx_orn);
5872f549d72SSam Leffler 	case S_RX_CRC_ERR:	STAT(rx_crcerr);
5882f549d72SSam Leffler 	case S_RX_FIFO_ERR: 	STAT(rx_fifoerr);
5892f549d72SSam Leffler 	case S_RX_CRYPTO_ERR: 	STAT(rx_badcrypt);
5902f549d72SSam Leffler 	case S_RX_MIC_ERR:	STAT(rx_badmic);
5912f549d72SSam Leffler 	case S_RX_PHY_ERR:	STAT(rx_phyerr);
5922f549d72SSam Leffler 	case S_RX_PHY_UNDERRUN:	PHY(HAL_PHYERR_UNDERRUN);
5932f549d72SSam Leffler 	case S_RX_PHY_TIMING:	PHY(HAL_PHYERR_TIMING);
5942f549d72SSam Leffler 	case S_RX_PHY_PARITY:	PHY(HAL_PHYERR_PARITY);
5952f549d72SSam Leffler 	case S_RX_PHY_RATE:	PHY(HAL_PHYERR_RATE);
5962f549d72SSam Leffler 	case S_RX_PHY_LENGTH:	PHY(HAL_PHYERR_LENGTH);
5972f549d72SSam Leffler 	case S_RX_PHY_RADAR:	PHY(HAL_PHYERR_RADAR);
5982f549d72SSam Leffler 	case S_RX_PHY_SERVICE:	PHY(HAL_PHYERR_SERVICE);
5992f549d72SSam Leffler 	case S_RX_PHY_TOR:	PHY(HAL_PHYERR_TOR);
6002f549d72SSam Leffler 	case S_RX_PHY_OFDM_TIMING:	  PHY(HAL_PHYERR_OFDM_TIMING);
6012f549d72SSam Leffler 	case S_RX_PHY_OFDM_SIGNAL_PARITY: PHY(HAL_PHYERR_OFDM_SIGNAL_PARITY);
6022f549d72SSam Leffler 	case S_RX_PHY_OFDM_RATE_ILLEGAL:  PHY(HAL_PHYERR_OFDM_RATE_ILLEGAL);
6032f549d72SSam Leffler 	case S_RX_PHY_OFDM_POWER_DROP:	  PHY(HAL_PHYERR_OFDM_POWER_DROP);
6042f549d72SSam Leffler 	case S_RX_PHY_OFDM_SERVICE:	  PHY(HAL_PHYERR_OFDM_SERVICE);
6052f549d72SSam Leffler 	case S_RX_PHY_OFDM_RESTART:	  PHY(HAL_PHYERR_OFDM_RESTART);
6062f549d72SSam Leffler 	case S_RX_PHY_CCK_TIMING:	  PHY(HAL_PHYERR_CCK_TIMING);
6072f549d72SSam Leffler 	case S_RX_PHY_CCK_HEADER_CRC:	  PHY(HAL_PHYERR_CCK_HEADER_CRC);
6082f549d72SSam Leffler 	case S_RX_PHY_CCK_RATE_ILLEGAL:	  PHY(HAL_PHYERR_CCK_RATE_ILLEGAL);
6092f549d72SSam Leffler 	case S_RX_PHY_CCK_SERVICE:	  PHY(HAL_PHYERR_CCK_SERVICE);
6102f549d72SSam Leffler 	case S_RX_PHY_CCK_RESTART:	  PHY(HAL_PHYERR_CCK_RESTART);
6112f549d72SSam Leffler 	case S_RX_TOOSHORT:	STAT(rx_tooshort);
6122f549d72SSam Leffler 	case S_RX_TOOBIG:	STAT(rx_toobig);
6132f549d72SSam Leffler 	case S_RX_MGT:		STAT(rx_mgt);
6142f549d72SSam Leffler 	case S_RX_CTL:		STAT(rx_ctl);
6152f549d72SSam Leffler 	case S_TX_RSSI:
6162f549d72SSam Leffler 		snprintf(b, bs, "%d", wf->total.ast_tx_rssi);
6172f549d72SSam Leffler 		return 1;
6182f549d72SSam Leffler 	case S_RX_RSSI:
6192f549d72SSam Leffler 		snprintf(b, bs, "%d", wf->total.ast_rx_rssi);
6202f549d72SSam Leffler 		return 1;
6212f549d72SSam Leffler 	case S_BE_XMIT:		STAT(be_xmit);
6222f549d72SSam Leffler 	case S_BE_NOMBUF:	STAT(be_nombuf);
6232f549d72SSam Leffler 	case S_PER_CAL:		STAT(per_cal);
6242f549d72SSam Leffler 	case S_PER_CALFAIL:	STAT(per_calfail);
6252f549d72SSam Leffler 	case S_PER_RFGAIN:	STAT(per_rfgain);
6262f549d72SSam Leffler #ifdef S_TDMA_UPDATE
6272f549d72SSam Leffler 	case S_TDMA_UPDATE:	STAT(tdma_update);
6282f549d72SSam Leffler 	case S_TDMA_TIMERS:	STAT(tdma_timers);
6292f549d72SSam Leffler 	case S_TDMA_TSF:	STAT(tdma_tsf);
6302f549d72SSam Leffler #endif
6312f549d72SSam Leffler 	case S_RATE_CALLS:	STAT(rate_calls);
6322f549d72SSam Leffler 	case S_RATE_RAISE:	STAT(rate_raise);
6332f549d72SSam Leffler 	case S_RATE_DROP:	STAT(rate_drop);
6342f549d72SSam Leffler 	case S_ANT_DEFSWITCH:	STAT(ant_defswitch);
6352f549d72SSam Leffler 	case S_ANT_TXSWITCH:	STAT(ant_txswitch);
6362f549d72SSam Leffler 	case S_ANT_TX0:		TXANT(0);
6372f549d72SSam Leffler 	case S_ANT_TX1:		TXANT(1);
6382f549d72SSam Leffler 	case S_ANT_TX2:		TXANT(2);
6392f549d72SSam Leffler 	case S_ANT_TX3:		TXANT(3);
6402f549d72SSam Leffler 	case S_ANT_TX4:		TXANT(4);
6412f549d72SSam Leffler 	case S_ANT_TX5:		TXANT(5);
6422f549d72SSam Leffler 	case S_ANT_TX6:		TXANT(6);
6432f549d72SSam Leffler 	case S_ANT_TX7:		TXANT(7);
6442f549d72SSam Leffler 	case S_ANT_RX0:		RXANT(0);
6452f549d72SSam Leffler 	case S_ANT_RX1:		RXANT(1);
6462f549d72SSam Leffler 	case S_ANT_RX2:		RXANT(2);
6472f549d72SSam Leffler 	case S_ANT_RX3:		RXANT(3);
6482f549d72SSam Leffler 	case S_ANT_RX4:		RXANT(4);
6492f549d72SSam Leffler 	case S_ANT_RX5:		RXANT(5);
6502f549d72SSam Leffler 	case S_ANT_RX6:		RXANT(6);
6512f549d72SSam Leffler 	case S_ANT_RX7:		RXANT(7);
6522f549d72SSam Leffler #ifdef S_CABQ_XMIT
6532f549d72SSam Leffler 	case S_CABQ_XMIT:	STAT(cabq_xmit);
6542f549d72SSam Leffler 	case S_CABQ_BUSY:	STAT(cabq_busy);
6552f549d72SSam Leffler #endif
6562f549d72SSam Leffler #ifdef S_FF_TXOK
6572f549d72SSam Leffler 	case S_FF_TXOK:		STAT(ff_txok);
6582f549d72SSam Leffler 	case S_FF_TXERR:	STAT(ff_txerr);
6592f549d72SSam Leffler 	case S_FF_FLUSH:	STAT(ff_flush);
6602f549d72SSam Leffler 	case S_FF_QFULL:	STAT(ff_qfull);
6612f549d72SSam Leffler #endif
6622f549d72SSam Leffler 	case S_RX_NOISE:
6632f549d72SSam Leffler 		snprintf(b, bs, "%d", wf->total.ast_rx_noise);
6642f549d72SSam Leffler 		return 1;
6652f549d72SSam Leffler 	case S_TX_SIGNAL:
6662f549d72SSam Leffler 		snprintf(b, bs, "%d",
6672f549d72SSam Leffler 			wf->total.ast_tx_rssi + wf->total.ast_rx_noise);
6682f549d72SSam Leffler 		return 1;
6692f549d72SSam Leffler 	case S_RX_SIGNAL:
6702f549d72SSam Leffler 		snprintf(b, bs, "%d",
6712f549d72SSam Leffler 			wf->total.ast_rx_rssi + wf->total.ast_rx_noise);
6722f549d72SSam Leffler 		return 1;
6732f549d72SSam Leffler 	}
6742f549d72SSam Leffler 	b[0] = '\0';
6752f549d72SSam Leffler 	return 0;
6762f549d72SSam Leffler #undef RXANT
6772f549d72SSam Leffler #undef TXANT
6782f549d72SSam Leffler #undef PHY
6792f549d72SSam Leffler #undef STAT
6802f549d72SSam Leffler }
6812f549d72SSam Leffler 
6822f549d72SSam Leffler static void
6832f549d72SSam Leffler ath_print_verbose(struct statfoo *sf, FILE *fd)
6842f549d72SSam Leffler {
6852f549d72SSam Leffler 	struct athstatfoo_p *wf = (struct athstatfoo_p *) sf;
6862f549d72SSam Leffler #define	isphyerr(i)	(S_PHY_MIN <= i && i <= S_PHY_MAX)
6872f549d72SSam Leffler 	char s[32];
6882f549d72SSam Leffler 	const char *indent;
6892f549d72SSam Leffler 	int i;
6902f549d72SSam Leffler 
6912f549d72SSam Leffler 	for (i = 0; i < S_LAST; i++) {
6922f549d72SSam Leffler 		if (ath_get_totstat(sf, i, s, sizeof(s)) && strcmp(s, "0")) {
6932f549d72SSam Leffler 			if (isphyerr(i))
6942f549d72SSam Leffler 				indent = "    ";
6952f549d72SSam Leffler 			else
6962f549d72SSam Leffler 				indent = "";
6972f549d72SSam Leffler 			fprintf(fd, "%s%s %s\n", indent, s, athstats[i].desc);
6982f549d72SSam Leffler 		}
6992f549d72SSam Leffler 	}
7002f549d72SSam Leffler 	fprintf(fd, "Antenna profile:\n");
7012f549d72SSam Leffler 	for (i = 0; i < 8; i++)
7022f549d72SSam Leffler 		if (wf->total.ast_ant_rx[i] || wf->total.ast_ant_tx[i])
7032f549d72SSam Leffler 			fprintf(fd, "[%u] tx %8u rx %8u\n", i,
7042f549d72SSam Leffler 				wf->total.ast_ant_tx[i],
7052f549d72SSam Leffler 				wf->total.ast_ant_rx[i]);
7062f549d72SSam Leffler #undef isphyerr
7072f549d72SSam Leffler }
7082f549d72SSam Leffler 
7092f549d72SSam Leffler STATFOO_DEFINE_BOUNCE(athstatfoo)
7102f549d72SSam Leffler 
7112f549d72SSam Leffler struct athstatfoo *
7122f549d72SSam Leffler athstats_new(const char *ifname, const char *fmtstring)
7132f549d72SSam Leffler {
7142f549d72SSam Leffler #define	N(a)	(sizeof(a) / sizeof(a[0]))
7152f549d72SSam Leffler 	struct athstatfoo_p *wf;
7162f549d72SSam Leffler 
7172f549d72SSam Leffler 	wf = calloc(1, sizeof(struct athstatfoo_p));
7182f549d72SSam Leffler 	if (wf != NULL) {
7192f549d72SSam Leffler 		statfoo_init(&wf->base.base, "athstats", athstats, N(athstats));
7202f549d72SSam Leffler 		/* override base methods */
7212f549d72SSam Leffler 		wf->base.base.collect_cur = ath_collect_cur;
7222f549d72SSam Leffler 		wf->base.base.collect_tot = ath_collect_tot;
7232f549d72SSam Leffler 		wf->base.base.get_curstat = ath_get_curstat;
7242f549d72SSam Leffler 		wf->base.base.get_totstat = ath_get_totstat;
7252f549d72SSam Leffler 		wf->base.base.update_tot = ath_update_tot;
7262f549d72SSam Leffler 		wf->base.base.print_verbose = ath_print_verbose;
7272f549d72SSam Leffler 
7282f549d72SSam Leffler 		/* setup bounce functions for public methods */
7292f549d72SSam Leffler 		STATFOO_BOUNCE(wf, athstatfoo);
7302f549d72SSam Leffler 
7312f549d72SSam Leffler 		/* setup our public methods */
7322f549d72SSam Leffler 		wf->base.setifname = ath_setifname;
7332f549d72SSam Leffler #if 0
7342f549d72SSam Leffler 		wf->base.setstamac = wlan_setstamac;
7352f549d72SSam Leffler #endif
7362f549d72SSam Leffler 		wf->s = socket(AF_INET, SOCK_DGRAM, 0);
7372f549d72SSam Leffler 		if (wf->s < 0)
7382f549d72SSam Leffler 			err(1, "socket");
7392f549d72SSam Leffler 
7402f549d72SSam Leffler 		ath_setifname(&wf->base, ifname);
7412f549d72SSam Leffler 		wf->base.setfmt(&wf->base, fmtstring);
7422f549d72SSam Leffler 	}
7432f549d72SSam Leffler 	return &wf->base;
7442f549d72SSam Leffler #undef N
74512f961f4SSam Leffler }
746