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