1 /*- 2 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer, 10 * without modification. 11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 13 * redistribution must be conditioned upon including a substantially 14 * similar Disclaimer requirement for further binary redistribution. 15 * 16 * NO WARRANTY 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 * THE POSSIBILITY OF SUCH DAMAGES. 28 * 29 * $FreeBSD$ 30 */ 31 32 #include "opt_ah.h" 33 34 /* 35 * ath statistics class. 36 */ 37 #include <sys/types.h> 38 #include <sys/file.h> 39 #include <sys/sockio.h> 40 #include <sys/socket.h> 41 #include <net/if.h> 42 #include <net/if_media.h> 43 #include <net/if_var.h> 44 45 #include <stdio.h> 46 #include <stdlib.h> 47 #include <signal.h> 48 #include <string.h> 49 #include <unistd.h> 50 #include <err.h> 51 52 #include "ah.h" 53 #include "ah_desc.h" 54 #include "ah_diagcodes.h" 55 #include "net80211/ieee80211_ioctl.h" 56 #include "net80211/ieee80211_radiotap.h" 57 #include "if_athioctl.h" 58 59 #include "athstats.h" 60 61 #ifdef ATH_SUPPORT_ANI 62 #define HAL_EP_RND(x,mul) \ 63 ((((x)%(mul)) >= ((mul)/2)) ? ((x) + ((mul) - 1)) / (mul) : (x)/(mul)) 64 #define HAL_RSSI(x) HAL_EP_RND(x, HAL_RSSI_EP_MULTIPLIER) 65 #endif 66 67 #define NOTPRESENT { 0, "", "" } 68 69 #define AFTER(prev) ((prev)+1) 70 71 static const struct fmt athstats[] = { 72 #define S_INPUT 0 73 { 8, "input", "input", "data frames received" }, 74 #define S_OUTPUT AFTER(S_INPUT) 75 { 8, "output", "output", "data frames transmit" }, 76 #define S_TX_ALTRATE AFTER(S_OUTPUT) 77 { 7, "altrate", "altrate", "tx frames with an alternate rate" }, 78 #define S_TX_SHORTRETRY AFTER(S_TX_ALTRATE) 79 { 7, "short", "short", "short on-chip tx retries" }, 80 #define S_TX_LONGRETRY AFTER(S_TX_SHORTRETRY) 81 { 7, "long", "long", "long on-chip tx retries" }, 82 #define S_TX_XRETRIES AFTER(S_TX_LONGRETRY) 83 { 6, "xretry", "xretry", "tx failed 'cuz too many retries" }, 84 #define S_MIB AFTER(S_TX_XRETRIES) 85 { 5, "mib", "mib", "mib overflow interrupts" }, 86 #ifndef __linux__ 87 #define S_TX_LINEAR AFTER(S_MIB) 88 { 5, "txlinear", "txlinear", "tx linearized to cluster" }, 89 #define S_BSTUCK AFTER(S_TX_LINEAR) 90 { 6, "bstuck", "bstuck", "stuck beacon conditions" }, 91 #define S_INTRCOAL AFTER(S_BSTUCK) 92 { 5, "intrcoal", "intrcoal", "interrupts coalesced" }, 93 #define S_RATE AFTER(S_INTRCOAL) 94 #else 95 #define S_RATE AFTER(S_MIB) 96 #endif 97 { 5, "rate", "rate", "current transmit rate" }, 98 #define S_WATCHDOG AFTER(S_RATE) 99 { 5, "wdog", "wdog", "watchdog timeouts" }, 100 #define S_FATAL AFTER(S_WATCHDOG) 101 { 5, "fatal", "fatal", "hardware error interrupts" }, 102 #define S_BMISS AFTER(S_FATAL) 103 { 5, "bmiss", "bmiss", "beacon miss interrupts" }, 104 #define S_RXORN AFTER(S_BMISS) 105 { 5, "rxorn", "rxorn", "recv overrun interrupts" }, 106 #define S_RXEOL AFTER(S_RXORN) 107 { 5, "rxeol", "rxeol", "recv eol interrupts" }, 108 #define S_TXURN AFTER(S_RXEOL) 109 { 5, "txurn", "txurn", "txmit underrun interrupts" }, 110 #define S_TX_MGMT AFTER(S_TXURN) 111 { 5, "txmgt", "txmgt", "tx management frames" }, 112 #define S_TX_DISCARD AFTER(S_TX_MGMT) 113 { 5, "txdisc", "txdisc", "tx frames discarded prior to association" }, 114 #define S_TX_INVALID AFTER(S_TX_DISCARD) 115 { 5, "txinv", "txinv", "tx invalid (19)" }, 116 #define S_TX_QSTOP AFTER(S_TX_INVALID) 117 { 5, "qstop", "qstop", "tx stopped 'cuz no xmit buffer" }, 118 #define S_TX_ENCAP AFTER(S_TX_QSTOP) 119 { 5, "txencode", "txencode", "tx encapsulation failed" }, 120 #define S_TX_NONODE AFTER(S_TX_ENCAP) 121 { 5, "txnonode", "txnonode", "tx failed 'cuz no node" }, 122 #define S_TX_NOBUF AFTER(S_TX_NONODE) 123 { 5, "txnobuf", "txnobuf", "tx failed 'cuz dma buffer allocation failed" }, 124 #define S_TX_NOFRAG AFTER(S_TX_NOBUF) 125 { 5, "txnofrag", "txnofrag", "tx failed 'cuz frag buffer allocation(s) failed" }, 126 #define S_TX_NOMBUF AFTER(S_TX_NOFRAG) 127 { 5, "txnombuf", "txnombuf", "tx failed 'cuz mbuf allocation failed" }, 128 #ifndef __linux__ 129 #define S_TX_NOMCL AFTER(S_TX_NOMBUF) 130 { 5, "txnomcl", "txnomcl", "tx failed 'cuz cluster allocation failed" }, 131 #define S_TX_FIFOERR AFTER(S_TX_NOMCL) 132 #else 133 #define S_TX_FIFOERR AFTER(S_TX_NOMBUF) 134 #endif 135 { 5, "efifo", "efifo", "tx failed 'cuz FIFO underrun" }, 136 #define S_TX_FILTERED AFTER(S_TX_FIFOERR) 137 { 5, "efilt", "efilt", "tx failed 'cuz destination filtered" }, 138 #define S_TX_BADRATE AFTER(S_TX_FILTERED) 139 { 5, "txbadrate", "txbadrate", "tx failed 'cuz bogus xmit rate" }, 140 #define S_TX_NOACK AFTER(S_TX_BADRATE) 141 { 5, "noack", "noack", "tx frames with no ack marked" }, 142 #define S_TX_RTS AFTER(S_TX_NOACK) 143 { 5, "rts", "rts", "tx frames with rts enabled" }, 144 #define S_TX_CTS AFTER(S_TX_RTS) 145 { 5, "cts", "cts", "tx frames with cts enabled" }, 146 #define S_TX_SHORTPRE AFTER(S_TX_CTS) 147 { 5, "shpre", "shpre", "tx frames with short preamble" }, 148 #define S_TX_PROTECT AFTER(S_TX_SHORTPRE) 149 { 5, "protect", "protect", "tx frames with 11g protection" }, 150 #define S_RX_ORN AFTER(S_TX_PROTECT) 151 { 5, "rxorn", "rxorn", "rx failed 'cuz of desc overrun" }, 152 #define S_RX_CRC_ERR AFTER(S_RX_ORN) 153 { 6, "crcerr", "crcerr", "rx failed 'cuz of bad CRC" }, 154 #define S_RX_FIFO_ERR AFTER(S_RX_CRC_ERR) 155 { 5, "rxfifo", "rxfifo", "rx failed 'cuz of FIFO overrun" }, 156 #define S_RX_CRYPTO_ERR AFTER(S_RX_FIFO_ERR) 157 { 5, "crypt", "crypt", "rx failed 'cuz decryption" }, 158 #define S_RX_MIC_ERR AFTER(S_RX_CRYPTO_ERR) 159 { 4, "mic", "mic", "rx failed 'cuz MIC failure" }, 160 #define S_RX_TOOSHORT AFTER(S_RX_MIC_ERR) 161 { 5, "rxshort", "rxshort", "rx failed 'cuz frame too short" }, 162 #define S_RX_NOMBUF AFTER(S_RX_TOOSHORT) 163 { 5, "rxnombuf", "rxnombuf", "rx setup failed 'cuz no mbuf" }, 164 #define S_RX_MGT AFTER(S_RX_NOMBUF) 165 { 5, "rxmgt", "rxmgt", "rx management frames" }, 166 #define S_RX_CTL AFTER(S_RX_MGT) 167 { 5, "rxctl", "rxctl", "rx control frames" }, 168 #define S_RX_PHY_ERR AFTER(S_RX_CTL) 169 { 7, "phyerr", "phyerr", "rx failed 'cuz of PHY err" }, 170 #define S_RX_PHY_UNDERRUN AFTER(S_RX_PHY_ERR) 171 { 4, "phyund", "TUnd", "transmit underrun" }, 172 #define S_RX_PHY_TIMING AFTER(S_RX_PHY_UNDERRUN) 173 { 4, "phytim", "Tim", "timing error" }, 174 #define S_RX_PHY_PARITY AFTER(S_RX_PHY_TIMING) 175 { 4, "phypar", "IPar", "illegal parity" }, 176 #define S_RX_PHY_RATE AFTER(S_RX_PHY_PARITY) 177 { 4, "phyrate", "IRate", "illegal rate" }, 178 #define S_RX_PHY_LENGTH AFTER(S_RX_PHY_RATE) 179 { 4, "phylen", "ILen", "illegal length" }, 180 #define S_RX_PHY_RADAR AFTER(S_RX_PHY_LENGTH) 181 { 4, "phyradar", "Radar", "radar detect" }, 182 #define S_RX_PHY_SERVICE AFTER(S_RX_PHY_RADAR) 183 { 4, "physervice", "Service", "illegal service" }, 184 #define S_RX_PHY_TOR AFTER(S_RX_PHY_SERVICE) 185 { 4, "phytor", "TOR", "transmit override receive" }, 186 #define S_RX_PHY_OFDM_TIMING AFTER(S_RX_PHY_TOR) 187 { 6, "ofdmtim", "ofdmtim", "OFDM timing" }, 188 #define S_RX_PHY_OFDM_SIGNAL_PARITY AFTER(S_RX_PHY_OFDM_TIMING) 189 { 6, "ofdmsig", "ofdmsig", "OFDM illegal parity" }, 190 #define S_RX_PHY_OFDM_RATE_ILLEGAL AFTER(S_RX_PHY_OFDM_SIGNAL_PARITY) 191 { 6, "ofdmrate", "ofdmrate", "OFDM illegal rate" }, 192 #define S_RX_PHY_OFDM_POWER_DROP AFTER(S_RX_PHY_OFDM_RATE_ILLEGAL) 193 { 6, "ofdmpow", "ofdmpow", "OFDM power drop" }, 194 #define S_RX_PHY_OFDM_SERVICE AFTER(S_RX_PHY_OFDM_POWER_DROP) 195 { 6, "ofdmservice", "ofdmservice", "OFDM illegal service" }, 196 #define S_RX_PHY_OFDM_RESTART AFTER(S_RX_PHY_OFDM_SERVICE) 197 { 6, "ofdmrestart", "ofdmrestart", "OFDM restart" }, 198 #define S_RX_PHY_CCK_TIMING AFTER(S_RX_PHY_OFDM_RESTART) 199 { 6, "ccktim", "ccktim", "CCK timing" }, 200 #define S_RX_PHY_CCK_HEADER_CRC AFTER(S_RX_PHY_CCK_TIMING) 201 { 6, "cckhead", "cckhead", "CCK header crc" }, 202 #define S_RX_PHY_CCK_RATE_ILLEGAL AFTER(S_RX_PHY_CCK_HEADER_CRC) 203 { 6, "cckrate", "cckrate", "CCK illegal rate" }, 204 #define S_RX_PHY_CCK_SERVICE AFTER(S_RX_PHY_CCK_RATE_ILLEGAL) 205 { 6, "cckservice", "cckservice", "CCK illegal service" }, 206 #define S_RX_PHY_CCK_RESTART AFTER(S_RX_PHY_CCK_SERVICE) 207 { 6, "cckrestar", "cckrestar", "CCK restart" }, 208 #define S_BE_NOMBUF AFTER(S_RX_PHY_CCK_RESTART) 209 { 4, "benombuf", "benombuf", "beacon setup failed 'cuz no mbuf" }, 210 #define S_BE_XMIT AFTER(S_BE_NOMBUF) 211 { 7, "bexmit", "bexmit", "beacons transmitted" }, 212 #define S_PER_CAL AFTER(S_BE_XMIT) 213 { 4, "pcal", "pcal", "periodic calibrations" }, 214 #define S_PER_CALFAIL AFTER(S_PER_CAL) 215 { 4, "pcalf", "pcalf", "periodic calibration failures" }, 216 #define S_PER_RFGAIN AFTER(S_PER_CALFAIL) 217 { 4, "prfga", "prfga", "rfgain value change" }, 218 #if ATH_SUPPORT_TDMA 219 #define S_TDMA_UPDATE AFTER(S_PER_RFGAIN) 220 { 5, "tdmau", "tdmau", "TDMA slot timing updates" }, 221 #define S_TDMA_TIMERS AFTER(S_TDMA_UPDATE) 222 { 5, "tdmab", "tdmab", "TDMA slot update set beacon timers" }, 223 #define S_TDMA_TSF AFTER(S_TDMA_TIMERS) 224 { 5, "tdmat", "tdmat", "TDMA slot update set TSF" }, 225 #define S_TDMA_TSFADJ AFTER(S_TDMA_TSF) 226 { 8, "tdmadj", "tdmadj", "TDMA slot adjust (usecs, smoothed)" }, 227 #define S_TDMA_ACK AFTER(S_TDMA_TSFADJ) 228 { 5, "tdmack", "tdmack", "TDMA tx failed 'cuz ACK required" }, 229 #define S_RATE_CALLS AFTER(S_TDMA_ACK) 230 #else 231 #define S_RATE_CALLS AFTER(S_PER_RFGAIN) 232 #endif 233 { 5, "ratec", "ratec", "rate control checks" }, 234 #define S_RATE_RAISE AFTER(S_RATE_CALLS) 235 { 5, "rate+", "rate+", "rate control raised xmit rate" }, 236 #define S_RATE_DROP AFTER(S_RATE_RAISE) 237 { 5, "rate-", "rate-", "rate control dropped xmit rate" }, 238 #define S_TX_RSSI AFTER(S_RATE_DROP) 239 { 4, "arssi", "arssi", "rssi of last ack" }, 240 #define S_RX_RSSI AFTER(S_TX_RSSI) 241 { 4, "rssi", "rssi", "avg recv rssi" }, 242 #define S_RX_NOISE AFTER(S_RX_RSSI) 243 { 5, "noise", "noise", "rx noise floor" }, 244 #define S_BMISS_PHANTOM AFTER(S_RX_NOISE) 245 { 5, "bmissphantom", "bmissphantom", "phantom beacon misses" }, 246 #define S_TX_RAW AFTER(S_BMISS_PHANTOM) 247 { 5, "txraw", "txraw", "tx frames through raw api" }, 248 #define S_TX_RAW_FAIL AFTER(S_TX_RAW) 249 { 5, "txrawfail", "txrawfail", "raw tx failed 'cuz interface/hw down" }, 250 #define S_RX_TOOBIG AFTER(S_TX_RAW_FAIL) 251 { 5, "rx2big", "rx2big", "rx failed 'cuz frame too large" }, 252 #define S_RX_AGG AFTER(S_RX_TOOBIG) 253 { 5, "rxagg", "rxagg", "A-MPDU sub-frames received" }, 254 #define S_RX_HALFGI AFTER(S_RX_AGG) 255 { 5, "rxhalfgi", "rxhgi", "Half-GI frames received" }, 256 #define S_RX_2040 AFTER(S_RX_HALFGI) 257 { 6, "rx2040", "rx2040", "40MHz frames received" }, 258 #define S_RX_PRE_CRC_ERR AFTER(S_RX_2040) 259 { 11, "rxprecrcerr", "rxprecrcerr", "CRC errors for non-last A-MPDU subframes" }, 260 #define S_RX_POST_CRC_ERR AFTER(S_RX_PRE_CRC_ERR) 261 { 12, "rxpostcrcerr", "rxpostcrcerr", "CRC errors for last subframe in an A-MPDU" }, 262 #define S_RX_DECRYPT_BUSY_ERR AFTER(S_RX_POST_CRC_ERR) 263 { 10, "rxdescbusy", "rxdescbusy", "Decryption engine busy" }, 264 #define S_RX_HI_CHAIN AFTER(S_RX_DECRYPT_BUSY_ERR) 265 { 4, "rxhi", "rxhi", "Frames received with RX chain in high power mode" }, 266 #define S_RX_STBC AFTER(S_RX_HI_CHAIN) 267 { 6, "rxstbc", "rxstbc", "Frames received w/ STBC encoding" }, 268 #define S_TX_HTPROTECT AFTER(S_RX_STBC) 269 { 7, "txhtprot", "txhtprot", "Frames transmitted with HT Protection" }, 270 #define S_RX_QEND AFTER(S_TX_HTPROTECT) 271 { 7, "rxquend", "rxquend", "Hit end of RX descriptor queue" }, 272 #define S_TX_TIMEOUT AFTER(S_RX_QEND) 273 { 4, "txtimeout", "TXTX", "TX Timeout" }, 274 #define S_TX_CSTIMEOUT AFTER(S_TX_TIMEOUT) 275 { 4, "csttimeout", "CSTX", "Carrier Sense Timeout" }, 276 #define S_TX_XTXOP_ERR AFTER(S_TX_CSTIMEOUT) 277 { 5, "xtxoperr", "TXOPX", "TXOP exceed" }, 278 #define S_TX_TIMEREXPIRED_ERR AFTER(S_TX_XTXOP_ERR) 279 { 7, "texperr", "texperr", "TX Timer expired" }, 280 #define S_TX_DESCCFG_ERR AFTER(S_TX_TIMEREXPIRED_ERR) 281 { 10, "desccfgerr", "desccfgerr", "TX descriptor error" }, 282 #define S_TX_SWRETRIES AFTER(S_TX_DESCCFG_ERR) 283 { 9, "txswretry", "txswretry", "Number of frames retransmitted in software" }, 284 #define S_TX_SWRETRIES_MAX AFTER(S_TX_SWRETRIES) 285 { 7, "txswmax", "txswmax", "Number of frames exceeding software retry" }, 286 #define S_TX_DATA_UNDERRUN AFTER(S_TX_SWRETRIES_MAX) 287 { 5, "txdataunderrun", "TXDAU", "A-MPDU TX FIFO data underrun" }, 288 #define S_TX_DELIM_UNDERRUN AFTER(S_TX_DATA_UNDERRUN) 289 { 5, "txdelimunderrun", "TXDEU", "A-MPDU TX Delimiter underrun" }, 290 #define S_TX_AGGR_OK AFTER(S_TX_DELIM_UNDERRUN) 291 { 5, "txaggrok", "TXAOK", "A-MPDU sub-frame TX attempt success" }, 292 #define S_TX_AGGR_FAIL AFTER(S_TX_AGGR_OK) 293 { 4, "txaggrfail", "TXAF", "A-MPDU sub-frame TX attempt failures" }, 294 #define S_TX_AGGR_FAILALL AFTER(S_TX_AGGR_FAIL) 295 { 7, "txaggrfailall", "TXAFALL", "A-MPDU TX frame failures" }, 296 #ifndef __linux__ 297 #define S_CABQ_XMIT AFTER(S_TX_AGGR_FAILALL) 298 { 7, "cabxmit", "cabxmit", "cabq frames transmitted" }, 299 #define S_CABQ_BUSY AFTER(S_CABQ_XMIT) 300 { 8, "cabqbusy", "cabqbusy", "cabq xmit overflowed beacon interval" }, 301 #define S_TX_NODATA AFTER(S_CABQ_BUSY) 302 { 8, "txnodata", "txnodata", "tx discarded empty frame" }, 303 #define S_TX_BUSDMA AFTER(S_TX_NODATA) 304 { 8, "txbusdma", "txbusdma", "tx failed for dma resrcs" }, 305 #define S_RX_BUSDMA AFTER(S_TX_BUSDMA) 306 { 8, "rxbusdma", "rxbusdma", "rx setup failed for dma resrcs" }, 307 #define S_FF_TXOK AFTER(S_RX_BUSDMA) 308 #else 309 #define S_FF_TXOK AFTER(S_TX_AGGR_FAILALL) 310 #endif 311 { 5, "fftxok", "fftxok", "fast frames xmit successfully" }, 312 #define S_FF_TXERR AFTER(S_FF_TXOK) 313 { 5, "fftxerr", "fftxerr", "fast frames not xmit due to error" }, 314 #define S_FF_RX AFTER(S_FF_TXERR) 315 { 5, "ffrx", "ffrx", "fast frames received" }, 316 #define S_FF_FLUSH AFTER(S_FF_RX) 317 { 5, "ffflush", "ffflush", "fast frames flushed from staging q" }, 318 #define S_TX_QFULL AFTER(S_FF_FLUSH) 319 { 5, "txqfull", "txqfull", "tx discarded 'cuz queue is full" }, 320 #define S_ANT_DEFSWITCH AFTER(S_TX_QFULL) 321 { 5, "defsw", "defsw", "switched default/rx antenna" }, 322 #define S_ANT_TXSWITCH AFTER(S_ANT_DEFSWITCH) 323 { 5, "txsw", "txsw", "tx used alternate antenna" }, 324 #ifdef ATH_SUPPORT_ANI 325 #define S_ANI_NOISE AFTER(S_ANT_TXSWITCH) 326 { 2, "ni", "NI", "noise immunity level" }, 327 #define S_ANI_SPUR AFTER(S_ANI_NOISE) 328 { 2, "si", "SI", "spur immunity level" }, 329 #define S_ANI_STEP AFTER(S_ANI_SPUR) 330 { 2, "step", "ST", "first step level" }, 331 #define S_ANI_OFDM AFTER(S_ANI_STEP) 332 { 4, "owsd", "OWSD", "OFDM weak signal detect" }, 333 #define S_ANI_CCK AFTER(S_ANI_OFDM) 334 { 4, "cwst", "CWST", "CCK weak signal threshold" }, 335 #define S_ANI_MAXSPUR AFTER(S_ANI_CCK) 336 { 3, "maxsi","MSI", "max spur immunity level" }, 337 #define S_ANI_LISTEN AFTER(S_ANI_MAXSPUR) 338 { 6, "listen","LISTEN", "listen time" }, 339 #define S_ANI_NIUP AFTER(S_ANI_LISTEN) 340 { 4, "ni+", "NI+", "ANI increased noise immunity" }, 341 #define S_ANI_NIDOWN AFTER(S_ANI_NIUP) 342 { 4, "ni-", "NI-", "ANI decrease noise immunity" }, 343 #define S_ANI_SIUP AFTER(S_ANI_NIDOWN) 344 { 4, "si+", "SI+", "ANI increased spur immunity" }, 345 #define S_ANI_SIDOWN AFTER(S_ANI_SIUP) 346 { 4, "si-", "SI-", "ANI decrease spur immunity" }, 347 #define S_ANI_OFDMON AFTER(S_ANI_SIDOWN) 348 { 5, "ofdm+","OFDM+", "ANI enabled OFDM weak signal detect" }, 349 #define S_ANI_OFDMOFF AFTER(S_ANI_OFDMON) 350 { 5, "ofdm-","OFDM-", "ANI disabled OFDM weak signal detect" }, 351 #define S_ANI_CCKHI AFTER(S_ANI_OFDMOFF) 352 { 5, "cck+", "CCK+", "ANI enabled CCK weak signal threshold" }, 353 #define S_ANI_CCKLO AFTER(S_ANI_CCKHI) 354 { 5, "cck-", "CCK-", "ANI disabled CCK weak signal threshold" }, 355 #define S_ANI_STEPUP AFTER(S_ANI_CCKLO) 356 { 5, "step+","STEP+", "ANI increased first step level" }, 357 #define S_ANI_STEPDOWN AFTER(S_ANI_STEPUP) 358 { 5, "step-","STEP-", "ANI decreased first step level" }, 359 #define S_ANI_OFDMERRS AFTER(S_ANI_STEPDOWN) 360 { 8, "ofdm", "OFDM", "cumulative OFDM phy error count" }, 361 #define S_ANI_CCKERRS AFTER(S_ANI_OFDMERRS) 362 { 8, "cck", "CCK", "cumulative CCK phy error count" }, 363 #define S_ANI_RESET AFTER(S_ANI_CCKERRS) 364 { 5, "reset","RESET", "ANI parameters zero'd for non-STA operation" }, 365 #define S_ANI_LZERO AFTER(S_ANI_RESET) 366 { 5, "lzero","LZERO", "ANI forced listen time to zero" }, 367 #define S_ANI_LNEG AFTER(S_ANI_LZERO) 368 { 5, "lneg", "LNEG", "ANI calculated listen time < 0" }, 369 #define S_MIB_ACKBAD AFTER(S_ANI_LNEG) 370 { 5, "ackbad","ACKBAD", "missing ACK's" }, 371 #define S_MIB_RTSBAD AFTER(S_MIB_ACKBAD) 372 { 5, "rtsbad","RTSBAD", "RTS without CTS" }, 373 #define S_MIB_RTSGOOD AFTER(S_MIB_RTSBAD) 374 { 5, "rtsgood","RTSGOOD", "successful RTS" }, 375 #define S_MIB_FCSBAD AFTER(S_MIB_RTSGOOD) 376 { 5, "fcsbad","FCSBAD", "bad FCS" }, 377 #define S_MIB_BEACONS AFTER(S_MIB_FCSBAD) 378 { 5, "beacons","beacons", "beacons received" }, 379 #define S_NODE_AVGBRSSI AFTER(S_MIB_BEACONS) 380 { 3, "avgbrssi","BSI", "average rssi (beacons only)" }, 381 #define S_NODE_AVGRSSI AFTER(S_NODE_AVGBRSSI) 382 { 3, "avgrssi","DSI", "average rssi (all rx'd frames)" }, 383 #define S_NODE_AVGARSSI AFTER(S_NODE_AVGRSSI) 384 { 3, "avgtxrssi","TSI", "average rssi (ACKs only)" }, 385 #define S_ANT_TX0 AFTER(S_NODE_AVGARSSI) 386 #else 387 #define S_ANT_TX0 AFTER(S_ANT_TXSWITCH) 388 #endif /* ATH_SUPPORT_ANI */ 389 { 8, "tx0", "ant0(tx)", "frames tx on antenna 0" }, 390 #define S_ANT_TX1 AFTER(S_ANT_TX0) 391 { 8, "tx1", "ant1(tx)", "frames tx on antenna 1" }, 392 #define S_ANT_TX2 AFTER(S_ANT_TX1) 393 { 8, "tx2", "ant2(tx)", "frames tx on antenna 2" }, 394 #define S_ANT_TX3 AFTER(S_ANT_TX2) 395 { 8, "tx3", "ant3(tx)", "frames tx on antenna 3" }, 396 #define S_ANT_TX4 AFTER(S_ANT_TX3) 397 { 8, "tx4", "ant4(tx)", "frames tx on antenna 4" }, 398 #define S_ANT_TX5 AFTER(S_ANT_TX4) 399 { 8, "tx5", "ant5(tx)", "frames tx on antenna 5" }, 400 #define S_ANT_TX6 AFTER(S_ANT_TX5) 401 { 8, "tx6", "ant6(tx)", "frames tx on antenna 6" }, 402 #define S_ANT_TX7 AFTER(S_ANT_TX6) 403 { 8, "tx7", "ant7(tx)", "frames tx on antenna 7" }, 404 #define S_ANT_RX0 AFTER(S_ANT_TX7) 405 { 8, "rx0", "ant0(rx)", "frames rx on antenna 0" }, 406 #define S_ANT_RX1 AFTER(S_ANT_RX0) 407 { 8, "rx1", "ant1(rx)", "frames rx on antenna 1" }, 408 #define S_ANT_RX2 AFTER(S_ANT_RX1) 409 { 8, "rx2", "ant2(rx)", "frames rx on antenna 2" }, 410 #define S_ANT_RX3 AFTER(S_ANT_RX2) 411 { 8, "rx3", "ant3(rx)", "frames rx on antenna 3" }, 412 #define S_ANT_RX4 AFTER(S_ANT_RX3) 413 { 8, "rx4", "ant4(rx)", "frames rx on antenna 4" }, 414 #define S_ANT_RX5 AFTER(S_ANT_RX4) 415 { 8, "rx5", "ant5(rx)", "frames rx on antenna 5" }, 416 #define S_ANT_RX6 AFTER(S_ANT_RX5) 417 { 8, "rx6", "ant6(rx)", "frames rx on antenna 6" }, 418 #define S_ANT_RX7 AFTER(S_ANT_RX6) 419 { 8, "rx7", "ant7(rx)", "frames rx on antenna 7" }, 420 #define S_TX_SIGNAL AFTER(S_ANT_RX7) 421 { 4, "asignal", "asig", "signal of last ack (dBm)" }, 422 #define S_RX_SIGNAL AFTER(S_TX_SIGNAL) 423 { 4, "signal", "sig", "avg recv signal (dBm)" }, 424 #define S_BMISSCOUNT AFTER(S_RX_SIGNAL) 425 { 8, "bmisscount", "bmisscnt", "beacon miss count" }, 426 }; 427 #define S_PHY_MIN S_RX_PHY_UNDERRUN 428 #define S_PHY_MAX S_RX_PHY_CCK_RESTART 429 #define S_LAST S_ANT_TX0 430 #define S_MAX S_BMISSCOUNT+1 431 432 struct _athstats { 433 struct ath_stats ath; 434 #ifdef ATH_SUPPORT_ANI 435 HAL_ANI_STATS ani_stats; 436 HAL_ANI_STATE ani_state; 437 #endif 438 }; 439 440 struct athstatfoo_p { 441 struct athstatfoo base; 442 int s; 443 int optstats; 444 #define ATHSTATS_ANI 0x0001 445 struct ifreq ifr; 446 struct ath_diag atd; 447 struct _athstats cur; 448 struct _athstats total; 449 }; 450 451 static void 452 ath_setifname(struct athstatfoo *wf0, const char *ifname) 453 { 454 struct athstatfoo_p *wf = (struct athstatfoo_p *) wf0; 455 456 strncpy(wf->ifr.ifr_name, ifname, sizeof (wf->ifr.ifr_name)); 457 #ifdef ATH_SUPPORT_ANI 458 strncpy(wf->atd.ad_name, ifname, sizeof (wf->atd.ad_name)); 459 wf->optstats |= ATHSTATS_ANI; 460 #endif 461 } 462 463 static void 464 ath_zerostats(struct athstatfoo *wf0) 465 { 466 struct athstatfoo_p *wf = (struct athstatfoo_p *) wf0; 467 468 if (ioctl(wf->s, SIOCZATHSTATS, &wf->ifr) < 0) 469 err(-1, "ioctl: %s", wf->ifr.ifr_name); 470 } 471 472 static void 473 ath_collect(struct athstatfoo_p *wf, struct _athstats *stats) 474 { 475 wf->ifr.ifr_data = (caddr_t) &stats->ath; 476 if (ioctl(wf->s, SIOCGATHSTATS, &wf->ifr) < 0) 477 err(1, "ioctl: %s", wf->ifr.ifr_name); 478 #ifdef ATH_SUPPORT_ANI 479 if (wf->optstats & ATHSTATS_ANI) { 480 wf->atd.ad_id = HAL_DIAG_ANI_CURRENT; /* HAL_DIAG_ANI_CURRENT */ 481 wf->atd.ad_out_data = (caddr_t) &stats->ani_state; 482 wf->atd.ad_out_size = sizeof(stats->ani_state); 483 if (ioctl(wf->s, SIOCGATHDIAG, &wf->atd) < 0) { 484 warn("ioctl: %s", wf->atd.ad_name); 485 wf->optstats &= ~ATHSTATS_ANI; 486 } 487 wf->atd.ad_id = HAL_DIAG_ANI_STATS; /* HAL_DIAG_ANI_STATS */ 488 wf->atd.ad_out_data = (caddr_t) &stats->ani_stats; 489 wf->atd.ad_out_size = sizeof(stats->ani_stats); 490 if (ioctl(wf->s, SIOCGATHDIAG, &wf->atd) < 0) 491 warn("ioctl: %s", wf->atd.ad_name); 492 } 493 #endif /* ATH_SUPPORT_ANI */ 494 } 495 496 static void 497 ath_collect_cur(struct bsdstat *sf) 498 { 499 struct athstatfoo_p *wf = (struct athstatfoo_p *) sf; 500 501 ath_collect(wf, &wf->cur); 502 } 503 504 static void 505 ath_collect_tot(struct bsdstat *sf) 506 { 507 struct athstatfoo_p *wf = (struct athstatfoo_p *) sf; 508 509 ath_collect(wf, &wf->total); 510 } 511 512 static void 513 ath_update_tot(struct bsdstat *sf) 514 { 515 struct athstatfoo_p *wf = (struct athstatfoo_p *) sf; 516 517 wf->total = wf->cur; 518 } 519 520 static void 521 snprintrate(char b[], size_t bs, int rate) 522 { 523 if (rate & IEEE80211_RATE_MCS) 524 snprintf(b, bs, "MCS%u", rate &~ IEEE80211_RATE_MCS); 525 else if (rate & 1) 526 snprintf(b, bs, "%u.5M", rate / 2); 527 else 528 snprintf(b, bs, "%uM", rate / 2); 529 } 530 531 static int 532 ath_get_curstat(struct bsdstat *sf, int s, char b[], size_t bs) 533 { 534 struct athstatfoo_p *wf = (struct athstatfoo_p *) sf; 535 #define STAT(x) \ 536 snprintf(b, bs, "%u", wf->cur.ath.ast_##x - wf->total.ath.ast_##x); return 1 537 #define PHY(x) \ 538 snprintf(b, bs, "%u", wf->cur.ath.ast_rx_phy[x] - wf->total.ath.ast_rx_phy[x]); return 1 539 #define ANI(x) \ 540 snprintf(b, bs, "%u", wf->cur.ani_state.x); return 1 541 #define ANISTAT(x) \ 542 snprintf(b, bs, "%u", wf->cur.ani_stats.ast_ani_##x - wf->total.ani_stats.ast_ani_##x); return 1 543 #define MIBSTAT(x) \ 544 snprintf(b, bs, "%u", wf->cur.ani_stats.ast_mibstats.x - wf->total.ani_stats.ast_mibstats.x); return 1 545 #define TXANT(x) \ 546 snprintf(b, bs, "%u", wf->cur.ath.ast_ant_tx[x] - wf->total.ath.ast_ant_tx[x]); return 1 547 #define RXANT(x) \ 548 snprintf(b, bs, "%u", wf->cur.ath.ast_ant_rx[x] - wf->total.ath.ast_ant_rx[x]); return 1 549 550 switch (s) { 551 case S_INPUT: 552 snprintf(b, bs, "%lu", 553 (unsigned long) 554 ((wf->cur.ath.ast_rx_packets - wf->total.ath.ast_rx_packets) - 555 (wf->cur.ath.ast_rx_mgt - wf->total.ath.ast_rx_mgt))); 556 return 1; 557 case S_OUTPUT: 558 snprintf(b, bs, "%lu", 559 (unsigned long) 560 (wf->cur.ath.ast_tx_packets - wf->total.ath.ast_tx_packets)); 561 return 1; 562 case S_RATE: 563 snprintrate(b, bs, wf->cur.ath.ast_tx_rate); 564 return 1; 565 case S_WATCHDOG: STAT(watchdog); 566 case S_FATAL: STAT(hardware); 567 case S_BMISS: STAT(bmiss); 568 case S_BMISS_PHANTOM: STAT(bmiss_phantom); 569 #ifdef S_BSTUCK 570 case S_BSTUCK: STAT(bstuck); 571 #endif 572 case S_RXORN: STAT(rxorn); 573 case S_RXEOL: STAT(rxeol); 574 case S_TXURN: STAT(txurn); 575 case S_MIB: STAT(mib); 576 #ifdef S_INTRCOAL 577 case S_INTRCOAL: STAT(intrcoal); 578 #endif 579 case S_TX_MGMT: STAT(tx_mgmt); 580 case S_TX_DISCARD: STAT(tx_discard); 581 case S_TX_QSTOP: STAT(tx_qstop); 582 case S_TX_ENCAP: STAT(tx_encap); 583 case S_TX_NONODE: STAT(tx_nonode); 584 case S_TX_NOBUF: STAT(tx_nobuf); 585 case S_TX_NOFRAG: STAT(tx_nofrag); 586 case S_TX_NOMBUF: STAT(tx_nombuf); 587 #ifdef S_TX_NOMCL 588 case S_TX_NOMCL: STAT(tx_nomcl); 589 case S_TX_LINEAR: STAT(tx_linear); 590 case S_TX_NODATA: STAT(tx_nodata); 591 case S_TX_BUSDMA: STAT(tx_busdma); 592 #endif 593 case S_TX_XRETRIES: STAT(tx_xretries); 594 case S_TX_FIFOERR: STAT(tx_fifoerr); 595 case S_TX_FILTERED: STAT(tx_filtered); 596 case S_TX_SHORTRETRY: STAT(tx_shortretry); 597 case S_TX_LONGRETRY: STAT(tx_longretry); 598 case S_TX_BADRATE: STAT(tx_badrate); 599 case S_TX_NOACK: STAT(tx_noack); 600 case S_TX_RTS: STAT(tx_rts); 601 case S_TX_CTS: STAT(tx_cts); 602 case S_TX_SHORTPRE: STAT(tx_shortpre); 603 case S_TX_ALTRATE: STAT(tx_altrate); 604 case S_TX_PROTECT: STAT(tx_protect); 605 case S_TX_RAW: STAT(tx_raw); 606 case S_TX_RAW_FAIL: STAT(tx_raw_fail); 607 case S_RX_NOMBUF: STAT(rx_nombuf); 608 #ifdef S_RX_BUSDMA 609 case S_RX_BUSDMA: STAT(rx_busdma); 610 #endif 611 case S_RX_ORN: STAT(rx_orn); 612 case S_RX_CRC_ERR: STAT(rx_crcerr); 613 case S_RX_FIFO_ERR: STAT(rx_fifoerr); 614 case S_RX_CRYPTO_ERR: STAT(rx_badcrypt); 615 case S_RX_MIC_ERR: STAT(rx_badmic); 616 case S_RX_PHY_ERR: STAT(rx_phyerr); 617 case S_RX_PHY_UNDERRUN: PHY(HAL_PHYERR_UNDERRUN); 618 case S_RX_PHY_TIMING: PHY(HAL_PHYERR_TIMING); 619 case S_RX_PHY_PARITY: PHY(HAL_PHYERR_PARITY); 620 case S_RX_PHY_RATE: PHY(HAL_PHYERR_RATE); 621 case S_RX_PHY_LENGTH: PHY(HAL_PHYERR_LENGTH); 622 case S_RX_PHY_RADAR: PHY(HAL_PHYERR_RADAR); 623 case S_RX_PHY_SERVICE: PHY(HAL_PHYERR_SERVICE); 624 case S_RX_PHY_TOR: PHY(HAL_PHYERR_TOR); 625 case S_RX_PHY_OFDM_TIMING: PHY(HAL_PHYERR_OFDM_TIMING); 626 case S_RX_PHY_OFDM_SIGNAL_PARITY: PHY(HAL_PHYERR_OFDM_SIGNAL_PARITY); 627 case S_RX_PHY_OFDM_RATE_ILLEGAL: PHY(HAL_PHYERR_OFDM_RATE_ILLEGAL); 628 case S_RX_PHY_OFDM_POWER_DROP: PHY(HAL_PHYERR_OFDM_POWER_DROP); 629 case S_RX_PHY_OFDM_SERVICE: PHY(HAL_PHYERR_OFDM_SERVICE); 630 case S_RX_PHY_OFDM_RESTART: PHY(HAL_PHYERR_OFDM_RESTART); 631 case S_RX_PHY_CCK_TIMING: PHY(HAL_PHYERR_CCK_TIMING); 632 case S_RX_PHY_CCK_HEADER_CRC: PHY(HAL_PHYERR_CCK_HEADER_CRC); 633 case S_RX_PHY_CCK_RATE_ILLEGAL: PHY(HAL_PHYERR_CCK_RATE_ILLEGAL); 634 case S_RX_PHY_CCK_SERVICE: PHY(HAL_PHYERR_CCK_SERVICE); 635 case S_RX_PHY_CCK_RESTART: PHY(HAL_PHYERR_CCK_RESTART); 636 case S_RX_TOOSHORT: STAT(rx_tooshort); 637 case S_RX_TOOBIG: STAT(rx_toobig); 638 case S_RX_MGT: STAT(rx_mgt); 639 case S_RX_CTL: STAT(rx_ctl); 640 case S_TX_RSSI: 641 snprintf(b, bs, "%d", wf->cur.ath.ast_tx_rssi); 642 return 1; 643 case S_RX_RSSI: 644 snprintf(b, bs, "%d", wf->cur.ath.ast_rx_rssi); 645 return 1; 646 case S_BE_XMIT: STAT(be_xmit); 647 case S_BE_NOMBUF: STAT(be_nombuf); 648 case S_PER_CAL: STAT(per_cal); 649 case S_PER_CALFAIL: STAT(per_calfail); 650 case S_PER_RFGAIN: STAT(per_rfgain); 651 #ifdef S_TDMA_UPDATE 652 case S_TDMA_UPDATE: STAT(tdma_update); 653 case S_TDMA_TIMERS: STAT(tdma_timers); 654 case S_TDMA_TSF: STAT(tdma_tsf); 655 case S_TDMA_TSFADJ: 656 snprintf(b, bs, "-%d/+%d", 657 wf->cur.ath.ast_tdma_tsfadjm, wf->cur.ath.ast_tdma_tsfadjp); 658 return 1; 659 case S_TDMA_ACK: STAT(tdma_ack); 660 #endif 661 case S_RATE_CALLS: STAT(rate_calls); 662 case S_RATE_RAISE: STAT(rate_raise); 663 case S_RATE_DROP: STAT(rate_drop); 664 case S_ANT_DEFSWITCH: STAT(ant_defswitch); 665 case S_ANT_TXSWITCH: STAT(ant_txswitch); 666 #ifdef S_ANI_NOISE 667 case S_ANI_NOISE: ANI(noiseImmunityLevel); 668 case S_ANI_SPUR: ANI(spurImmunityLevel); 669 case S_ANI_STEP: ANI(firstepLevel); 670 case S_ANI_OFDM: ANI(ofdmWeakSigDetectOff); 671 case S_ANI_CCK: ANI(cckWeakSigThreshold); 672 case S_ANI_LISTEN: ANI(listenTime); 673 case S_ANI_NIUP: ANISTAT(niup); 674 case S_ANI_NIDOWN: ANISTAT(nidown); 675 case S_ANI_SIUP: ANISTAT(spurup); 676 case S_ANI_SIDOWN: ANISTAT(spurdown); 677 case S_ANI_OFDMON: ANISTAT(ofdmon); 678 case S_ANI_OFDMOFF: ANISTAT(ofdmoff); 679 case S_ANI_CCKHI: ANISTAT(cckhigh); 680 case S_ANI_CCKLO: ANISTAT(ccklow); 681 case S_ANI_STEPUP: ANISTAT(stepup); 682 case S_ANI_STEPDOWN: ANISTAT(stepdown); 683 case S_ANI_OFDMERRS: ANISTAT(ofdmerrs); 684 case S_ANI_CCKERRS: ANISTAT(cckerrs); 685 case S_ANI_RESET: ANISTAT(reset); 686 case S_ANI_LZERO: ANISTAT(lzero); 687 case S_ANI_LNEG: ANISTAT(lneg); 688 case S_MIB_ACKBAD: MIBSTAT(ackrcv_bad); 689 case S_MIB_RTSBAD: MIBSTAT(rts_bad); 690 case S_MIB_RTSGOOD: MIBSTAT(rts_good); 691 case S_MIB_FCSBAD: MIBSTAT(fcs_bad); 692 case S_MIB_BEACONS: MIBSTAT(beacons); 693 case S_NODE_AVGBRSSI: 694 snprintf(b, bs, "%u", 695 HAL_RSSI(wf->cur.ani_stats.ast_nodestats.ns_avgbrssi)); 696 return 1; 697 case S_NODE_AVGRSSI: 698 snprintf(b, bs, "%u", 699 HAL_RSSI(wf->cur.ani_stats.ast_nodestats.ns_avgrssi)); 700 return 1; 701 case S_NODE_AVGARSSI: 702 snprintf(b, bs, "%u", 703 HAL_RSSI(wf->cur.ani_stats.ast_nodestats.ns_avgtxrssi)); 704 return 1; 705 #endif 706 case S_ANT_TX0: TXANT(0); 707 case S_ANT_TX1: TXANT(1); 708 case S_ANT_TX2: TXANT(2); 709 case S_ANT_TX3: TXANT(3); 710 case S_ANT_TX4: TXANT(4); 711 case S_ANT_TX5: TXANT(5); 712 case S_ANT_TX6: TXANT(6); 713 case S_ANT_TX7: TXANT(7); 714 case S_ANT_RX0: RXANT(0); 715 case S_ANT_RX1: RXANT(1); 716 case S_ANT_RX2: RXANT(2); 717 case S_ANT_RX3: RXANT(3); 718 case S_ANT_RX4: RXANT(4); 719 case S_ANT_RX5: RXANT(5); 720 case S_ANT_RX6: RXANT(6); 721 case S_ANT_RX7: RXANT(7); 722 #ifdef S_CABQ_XMIT 723 case S_CABQ_XMIT: STAT(cabq_xmit); 724 case S_CABQ_BUSY: STAT(cabq_busy); 725 #endif 726 case S_FF_TXOK: STAT(ff_txok); 727 case S_FF_TXERR: STAT(ff_txerr); 728 case S_FF_RX: STAT(ff_rx); 729 case S_FF_FLUSH: STAT(ff_flush); 730 case S_TX_QFULL: STAT(tx_qfull); 731 case S_BMISSCOUNT: STAT(be_missed); 732 case S_RX_NOISE: 733 snprintf(b, bs, "%d", wf->cur.ath.ast_rx_noise); 734 return 1; 735 case S_TX_SIGNAL: 736 snprintf(b, bs, "%d", 737 wf->cur.ath.ast_tx_rssi + wf->cur.ath.ast_rx_noise); 738 return 1; 739 case S_RX_SIGNAL: 740 snprintf(b, bs, "%d", 741 wf->cur.ath.ast_rx_rssi + wf->cur.ath.ast_rx_noise); 742 return 1; 743 case S_RX_AGG: STAT(rx_agg); 744 case S_RX_HALFGI: STAT(rx_halfgi); 745 case S_RX_2040: STAT(rx_2040); 746 case S_RX_PRE_CRC_ERR: STAT(rx_pre_crc_err); 747 case S_RX_POST_CRC_ERR: STAT(rx_post_crc_err); 748 case S_RX_DECRYPT_BUSY_ERR: STAT(rx_decrypt_busy_err); 749 case S_RX_HI_CHAIN: STAT(rx_hi_rx_chain); 750 case S_RX_STBC: STAT(rx_stbc); 751 case S_TX_HTPROTECT: STAT(tx_htprotect); 752 case S_RX_QEND: STAT(rx_hitqueueend); 753 case S_TX_TIMEOUT: STAT(tx_timeout); 754 case S_TX_CSTIMEOUT: STAT(tx_cst); 755 case S_TX_XTXOP_ERR: STAT(tx_xtxop); 756 case S_TX_TIMEREXPIRED_ERR: STAT(tx_timerexpired); 757 case S_TX_DESCCFG_ERR: STAT(tx_desccfgerr); 758 case S_TX_SWRETRIES: STAT(tx_swretries); 759 case S_TX_SWRETRIES_MAX: STAT(tx_swretrymax); 760 case S_TX_DATA_UNDERRUN: STAT(tx_data_underrun); 761 case S_TX_DELIM_UNDERRUN: STAT(tx_delim_underrun); 762 case S_TX_AGGR_OK: STAT(tx_aggr_ok); 763 case S_TX_AGGR_FAIL: STAT(tx_aggr_fail); 764 case S_TX_AGGR_FAILALL: STAT(tx_aggr_failall); 765 } 766 b[0] = '\0'; 767 return 0; 768 #undef RXANT 769 #undef TXANT 770 #undef ANI 771 #undef ANISTAT 772 #undef MIBSTAT 773 #undef PHY 774 #undef STAT 775 } 776 777 static int 778 ath_get_totstat(struct bsdstat *sf, int s, char b[], size_t bs) 779 { 780 struct athstatfoo_p *wf = (struct athstatfoo_p *) sf; 781 #define STAT(x) \ 782 snprintf(b, bs, "%u", wf->total.ath.ast_##x); return 1 783 #define PHY(x) \ 784 snprintf(b, bs, "%u", wf->total.ath.ast_rx_phy[x]); return 1 785 #define ANI(x) \ 786 snprintf(b, bs, "%u", wf->total.ani_state.x); return 1 787 #define ANISTAT(x) \ 788 snprintf(b, bs, "%u", wf->total.ani_stats.ast_ani_##x); return 1 789 #define MIBSTAT(x) \ 790 snprintf(b, bs, "%u", wf->total.ani_stats.ast_mibstats.x); return 1 791 #define TXANT(x) \ 792 snprintf(b, bs, "%u", wf->total.ath.ast_ant_tx[x]); return 1 793 #define RXANT(x) \ 794 snprintf(b, bs, "%u", wf->total.ath.ast_ant_rx[x]); return 1 795 796 switch (s) { 797 case S_INPUT: 798 snprintf(b, bs, "%lu", 799 (unsigned long) wf->total.ath.ast_rx_packets - 800 (unsigned long) wf->total.ath.ast_rx_mgt); 801 return 1; 802 case S_OUTPUT: 803 snprintf(b, bs, "%lu", 804 (unsigned long) wf->total.ath.ast_tx_packets); 805 return 1; 806 case S_RATE: 807 snprintrate(b, bs, wf->total.ath.ast_tx_rate); 808 return 1; 809 case S_WATCHDOG: STAT(watchdog); 810 case S_FATAL: STAT(hardware); 811 case S_BMISS: STAT(bmiss); 812 case S_BMISS_PHANTOM: STAT(bmiss_phantom); 813 #ifdef S_BSTUCK 814 case S_BSTUCK: STAT(bstuck); 815 #endif 816 case S_RXORN: STAT(rxorn); 817 case S_RXEOL: STAT(rxeol); 818 case S_TXURN: STAT(txurn); 819 case S_MIB: STAT(mib); 820 #ifdef S_INTRCOAL 821 case S_INTRCOAL: STAT(intrcoal); 822 #endif 823 case S_TX_MGMT: STAT(tx_mgmt); 824 case S_TX_DISCARD: STAT(tx_discard); 825 case S_TX_QSTOP: STAT(tx_qstop); 826 case S_TX_ENCAP: STAT(tx_encap); 827 case S_TX_NONODE: STAT(tx_nonode); 828 case S_TX_NOBUF: STAT(tx_nobuf); 829 case S_TX_NOFRAG: STAT(tx_nofrag); 830 case S_TX_NOMBUF: STAT(tx_nombuf); 831 #ifdef S_TX_NOMCL 832 case S_TX_NOMCL: STAT(tx_nomcl); 833 case S_TX_LINEAR: STAT(tx_linear); 834 case S_TX_NODATA: STAT(tx_nodata); 835 case S_TX_BUSDMA: STAT(tx_busdma); 836 #endif 837 case S_TX_XRETRIES: STAT(tx_xretries); 838 case S_TX_FIFOERR: STAT(tx_fifoerr); 839 case S_TX_FILTERED: STAT(tx_filtered); 840 case S_TX_SHORTRETRY: STAT(tx_shortretry); 841 case S_TX_LONGRETRY: STAT(tx_longretry); 842 case S_TX_BADRATE: STAT(tx_badrate); 843 case S_TX_NOACK: STAT(tx_noack); 844 case S_TX_RTS: STAT(tx_rts); 845 case S_TX_CTS: STAT(tx_cts); 846 case S_TX_SHORTPRE: STAT(tx_shortpre); 847 case S_TX_ALTRATE: STAT(tx_altrate); 848 case S_TX_PROTECT: STAT(tx_protect); 849 case S_TX_RAW: STAT(tx_raw); 850 case S_TX_RAW_FAIL: STAT(tx_raw_fail); 851 case S_RX_NOMBUF: STAT(rx_nombuf); 852 #ifdef S_RX_BUSDMA 853 case S_RX_BUSDMA: STAT(rx_busdma); 854 #endif 855 case S_RX_ORN: STAT(rx_orn); 856 case S_RX_CRC_ERR: STAT(rx_crcerr); 857 case S_RX_FIFO_ERR: STAT(rx_fifoerr); 858 case S_RX_CRYPTO_ERR: STAT(rx_badcrypt); 859 case S_RX_MIC_ERR: STAT(rx_badmic); 860 case S_RX_PHY_ERR: STAT(rx_phyerr); 861 case S_RX_PHY_UNDERRUN: PHY(HAL_PHYERR_UNDERRUN); 862 case S_RX_PHY_TIMING: PHY(HAL_PHYERR_TIMING); 863 case S_RX_PHY_PARITY: PHY(HAL_PHYERR_PARITY); 864 case S_RX_PHY_RATE: PHY(HAL_PHYERR_RATE); 865 case S_RX_PHY_LENGTH: PHY(HAL_PHYERR_LENGTH); 866 case S_RX_PHY_RADAR: PHY(HAL_PHYERR_RADAR); 867 case S_RX_PHY_SERVICE: PHY(HAL_PHYERR_SERVICE); 868 case S_RX_PHY_TOR: PHY(HAL_PHYERR_TOR); 869 case S_RX_PHY_OFDM_TIMING: PHY(HAL_PHYERR_OFDM_TIMING); 870 case S_RX_PHY_OFDM_SIGNAL_PARITY: PHY(HAL_PHYERR_OFDM_SIGNAL_PARITY); 871 case S_RX_PHY_OFDM_RATE_ILLEGAL: PHY(HAL_PHYERR_OFDM_RATE_ILLEGAL); 872 case S_RX_PHY_OFDM_POWER_DROP: PHY(HAL_PHYERR_OFDM_POWER_DROP); 873 case S_RX_PHY_OFDM_SERVICE: PHY(HAL_PHYERR_OFDM_SERVICE); 874 case S_RX_PHY_OFDM_RESTART: PHY(HAL_PHYERR_OFDM_RESTART); 875 case S_RX_PHY_CCK_TIMING: PHY(HAL_PHYERR_CCK_TIMING); 876 case S_RX_PHY_CCK_HEADER_CRC: PHY(HAL_PHYERR_CCK_HEADER_CRC); 877 case S_RX_PHY_CCK_RATE_ILLEGAL: PHY(HAL_PHYERR_CCK_RATE_ILLEGAL); 878 case S_RX_PHY_CCK_SERVICE: PHY(HAL_PHYERR_CCK_SERVICE); 879 case S_RX_PHY_CCK_RESTART: PHY(HAL_PHYERR_CCK_RESTART); 880 case S_RX_TOOSHORT: STAT(rx_tooshort); 881 case S_RX_TOOBIG: STAT(rx_toobig); 882 case S_RX_MGT: STAT(rx_mgt); 883 case S_RX_CTL: STAT(rx_ctl); 884 case S_TX_RSSI: 885 snprintf(b, bs, "%d", wf->total.ath.ast_tx_rssi); 886 return 1; 887 case S_RX_RSSI: 888 snprintf(b, bs, "%d", wf->total.ath.ast_rx_rssi); 889 return 1; 890 case S_BE_XMIT: STAT(be_xmit); 891 case S_BE_NOMBUF: STAT(be_nombuf); 892 case S_PER_CAL: STAT(per_cal); 893 case S_PER_CALFAIL: STAT(per_calfail); 894 case S_PER_RFGAIN: STAT(per_rfgain); 895 #ifdef S_TDMA_UPDATE 896 case S_TDMA_UPDATE: STAT(tdma_update); 897 case S_TDMA_TIMERS: STAT(tdma_timers); 898 case S_TDMA_TSF: STAT(tdma_tsf); 899 case S_TDMA_TSFADJ: 900 snprintf(b, bs, "-%d/+%d", 901 wf->total.ath.ast_tdma_tsfadjm, 902 wf->total.ath.ast_tdma_tsfadjp); 903 return 1; 904 case S_TDMA_ACK: STAT(tdma_ack); 905 #endif 906 case S_RATE_CALLS: STAT(rate_calls); 907 case S_RATE_RAISE: STAT(rate_raise); 908 case S_RATE_DROP: STAT(rate_drop); 909 case S_ANT_DEFSWITCH: STAT(ant_defswitch); 910 case S_ANT_TXSWITCH: STAT(ant_txswitch); 911 #ifdef S_ANI_NOISE 912 case S_ANI_NOISE: ANI(noiseImmunityLevel); 913 case S_ANI_SPUR: ANI(spurImmunityLevel); 914 case S_ANI_STEP: ANI(firstepLevel); 915 case S_ANI_OFDM: ANI(ofdmWeakSigDetectOff); 916 case S_ANI_CCK: ANI(cckWeakSigThreshold); 917 case S_ANI_LISTEN: ANI(listenTime); 918 case S_ANI_NIUP: ANISTAT(niup); 919 case S_ANI_NIDOWN: ANISTAT(nidown); 920 case S_ANI_SIUP: ANISTAT(spurup); 921 case S_ANI_SIDOWN: ANISTAT(spurdown); 922 case S_ANI_OFDMON: ANISTAT(ofdmon); 923 case S_ANI_OFDMOFF: ANISTAT(ofdmoff); 924 case S_ANI_CCKHI: ANISTAT(cckhigh); 925 case S_ANI_CCKLO: ANISTAT(ccklow); 926 case S_ANI_STEPUP: ANISTAT(stepup); 927 case S_ANI_STEPDOWN: ANISTAT(stepdown); 928 case S_ANI_OFDMERRS: ANISTAT(ofdmerrs); 929 case S_ANI_CCKERRS: ANISTAT(cckerrs); 930 case S_ANI_RESET: ANISTAT(reset); 931 case S_ANI_LZERO: ANISTAT(lzero); 932 case S_ANI_LNEG: ANISTAT(lneg); 933 case S_MIB_ACKBAD: MIBSTAT(ackrcv_bad); 934 case S_MIB_RTSBAD: MIBSTAT(rts_bad); 935 case S_MIB_RTSGOOD: MIBSTAT(rts_good); 936 case S_MIB_FCSBAD: MIBSTAT(fcs_bad); 937 case S_MIB_BEACONS: MIBSTAT(beacons); 938 case S_NODE_AVGBRSSI: 939 snprintf(b, bs, "%u", 940 HAL_RSSI(wf->total.ani_stats.ast_nodestats.ns_avgbrssi)); 941 return 1; 942 case S_NODE_AVGRSSI: 943 snprintf(b, bs, "%u", 944 HAL_RSSI(wf->total.ani_stats.ast_nodestats.ns_avgrssi)); 945 return 1; 946 case S_NODE_AVGARSSI: 947 snprintf(b, bs, "%u", 948 HAL_RSSI(wf->total.ani_stats.ast_nodestats.ns_avgtxrssi)); 949 return 1; 950 #endif 951 case S_ANT_TX0: TXANT(0); 952 case S_ANT_TX1: TXANT(1); 953 case S_ANT_TX2: TXANT(2); 954 case S_ANT_TX3: TXANT(3); 955 case S_ANT_TX4: TXANT(4); 956 case S_ANT_TX5: TXANT(5); 957 case S_ANT_TX6: TXANT(6); 958 case S_ANT_TX7: TXANT(7); 959 case S_ANT_RX0: RXANT(0); 960 case S_ANT_RX1: RXANT(1); 961 case S_ANT_RX2: RXANT(2); 962 case S_ANT_RX3: RXANT(3); 963 case S_ANT_RX4: RXANT(4); 964 case S_ANT_RX5: RXANT(5); 965 case S_ANT_RX6: RXANT(6); 966 case S_ANT_RX7: RXANT(7); 967 #ifdef S_CABQ_XMIT 968 case S_CABQ_XMIT: STAT(cabq_xmit); 969 case S_CABQ_BUSY: STAT(cabq_busy); 970 #endif 971 case S_FF_TXOK: STAT(ff_txok); 972 case S_FF_TXERR: STAT(ff_txerr); 973 case S_FF_RX: STAT(ff_rx); 974 case S_FF_FLUSH: STAT(ff_flush); 975 case S_TX_QFULL: STAT(tx_qfull); 976 case S_BMISSCOUNT: STAT(be_missed); 977 case S_RX_NOISE: 978 snprintf(b, bs, "%d", wf->total.ath.ast_rx_noise); 979 return 1; 980 case S_TX_SIGNAL: 981 snprintf(b, bs, "%d", 982 wf->total.ath.ast_tx_rssi + wf->total.ath.ast_rx_noise); 983 return 1; 984 case S_RX_SIGNAL: 985 snprintf(b, bs, "%d", 986 wf->total.ath.ast_rx_rssi + wf->total.ath.ast_rx_noise); 987 return 1; 988 case S_RX_AGG: STAT(rx_agg); 989 case S_RX_HALFGI: STAT(rx_halfgi); 990 case S_RX_2040: STAT(rx_2040); 991 case S_RX_PRE_CRC_ERR: STAT(rx_pre_crc_err); 992 case S_RX_POST_CRC_ERR: STAT(rx_post_crc_err); 993 case S_RX_DECRYPT_BUSY_ERR: STAT(rx_decrypt_busy_err); 994 case S_RX_HI_CHAIN: STAT(rx_hi_rx_chain); 995 case S_RX_STBC: STAT(rx_stbc); 996 case S_TX_HTPROTECT: STAT(tx_htprotect); 997 case S_RX_QEND: STAT(rx_hitqueueend); 998 case S_TX_TIMEOUT: STAT(tx_timeout); 999 case S_TX_CSTIMEOUT: STAT(tx_cst); 1000 case S_TX_XTXOP_ERR: STAT(tx_xtxop); 1001 case S_TX_TIMEREXPIRED_ERR: STAT(tx_timerexpired); 1002 case S_TX_DESCCFG_ERR: STAT(tx_desccfgerr); 1003 case S_TX_SWRETRIES: STAT(tx_swretries); 1004 case S_TX_SWRETRIES_MAX: STAT(tx_swretrymax); 1005 case S_TX_DATA_UNDERRUN: STAT(tx_data_underrun); 1006 case S_TX_DELIM_UNDERRUN: STAT(tx_delim_underrun); 1007 case S_TX_AGGR_OK: STAT(tx_aggr_ok); 1008 case S_TX_AGGR_FAIL: STAT(tx_aggr_fail); 1009 case S_TX_AGGR_FAILALL: STAT(tx_aggr_failall); 1010 } 1011 b[0] = '\0'; 1012 return 0; 1013 #undef RXANT 1014 #undef TXANT 1015 #undef ANI 1016 #undef ANISTAT 1017 #undef MIBSTAT 1018 #undef PHY 1019 #undef STAT 1020 } 1021 1022 static void 1023 ath_print_verbose(struct bsdstat *sf, FILE *fd) 1024 { 1025 struct athstatfoo_p *wf = (struct athstatfoo_p *) sf; 1026 #define isphyerr(i) (S_PHY_MIN <= i && i <= S_PHY_MAX) 1027 const struct fmt *f; 1028 char s[32]; 1029 const char *indent; 1030 int i, width; 1031 1032 width = 0; 1033 for (i = 0; i < S_LAST; i++) { 1034 f = &sf->stats[i]; 1035 if (!isphyerr(i) && f->width > width) 1036 width = f->width; 1037 } 1038 for (i = 0; i < S_LAST; i++) { 1039 if (ath_get_totstat(sf, i, s, sizeof(s)) && strcmp(s, "0")) { 1040 if (isphyerr(i)) 1041 indent = " "; 1042 else 1043 indent = ""; 1044 fprintf(fd, "%s%-*s %s\n", indent, width, s, athstats[i].desc); 1045 } 1046 } 1047 fprintf(fd, "Antenna profile:\n"); 1048 for (i = 0; i < 8; i++) 1049 if (wf->total.ath.ast_ant_rx[i] || wf->total.ath.ast_ant_tx[i]) 1050 fprintf(fd, "[%u] tx %8u rx %8u\n", i, 1051 wf->total.ath.ast_ant_tx[i], 1052 wf->total.ath.ast_ant_rx[i]); 1053 #undef isphyerr 1054 } 1055 1056 BSDSTAT_DEFINE_BOUNCE(athstatfoo) 1057 1058 struct athstatfoo * 1059 athstats_new(const char *ifname, const char *fmtstring) 1060 { 1061 #define N(a) (sizeof(a) / sizeof(a[0])) 1062 struct athstatfoo_p *wf; 1063 1064 wf = calloc(1, sizeof(struct athstatfoo_p)); 1065 if (wf != NULL) { 1066 bsdstat_init(&wf->base.base, "athstats", athstats, N(athstats)); 1067 /* override base methods */ 1068 wf->base.base.collect_cur = ath_collect_cur; 1069 wf->base.base.collect_tot = ath_collect_tot; 1070 wf->base.base.get_curstat = ath_get_curstat; 1071 wf->base.base.get_totstat = ath_get_totstat; 1072 wf->base.base.update_tot = ath_update_tot; 1073 wf->base.base.print_verbose = ath_print_verbose; 1074 1075 /* setup bounce functions for public methods */ 1076 BSDSTAT_BOUNCE(wf, athstatfoo); 1077 1078 /* setup our public methods */ 1079 wf->base.setifname = ath_setifname; 1080 #if 0 1081 wf->base.setstamac = wlan_setstamac; 1082 #endif 1083 wf->base.zerostats = ath_zerostats; 1084 wf->s = socket(AF_INET, SOCK_DGRAM, 0); 1085 if (wf->s < 0) 1086 err(1, "socket"); 1087 1088 ath_setifname(&wf->base, ifname); 1089 wf->base.setfmt(&wf->base, fmtstring); 1090 } 1091 return &wf->base; 1092 #undef N 1093 } 1094