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