1 /* 2 * Copyright (c) 2008-2011 Atheros Communications Inc. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #include <linux/slab.h> 18 #include <linux/vmalloc.h> 19 #include <linux/export.h> 20 #include <linux/relay.h> 21 #include <asm/unaligned.h> 22 23 #include "ath9k.h" 24 25 #define REG_WRITE_D(_ah, _reg, _val) \ 26 ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg)) 27 #define REG_READ_D(_ah, _reg) \ 28 ath9k_hw_common(_ah)->ops->read((_ah), (_reg)) 29 30 31 static ssize_t ath9k_debugfs_read_buf(struct file *file, char __user *user_buf, 32 size_t count, loff_t *ppos) 33 { 34 u8 *buf = file->private_data; 35 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf)); 36 } 37 38 static int ath9k_debugfs_release_buf(struct inode *inode, struct file *file) 39 { 40 vfree(file->private_data); 41 return 0; 42 } 43 44 #ifdef CONFIG_ATH_DEBUG 45 46 static ssize_t read_file_debug(struct file *file, char __user *user_buf, 47 size_t count, loff_t *ppos) 48 { 49 struct ath_softc *sc = file->private_data; 50 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 51 char buf[32]; 52 unsigned int len; 53 54 len = sprintf(buf, "0x%08x\n", common->debug_mask); 55 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 56 } 57 58 static ssize_t write_file_debug(struct file *file, const char __user *user_buf, 59 size_t count, loff_t *ppos) 60 { 61 struct ath_softc *sc = file->private_data; 62 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 63 unsigned long mask; 64 char buf[32]; 65 ssize_t len; 66 67 len = min(count, sizeof(buf) - 1); 68 if (copy_from_user(buf, user_buf, len)) 69 return -EFAULT; 70 71 buf[len] = '\0'; 72 if (kstrtoul(buf, 0, &mask)) 73 return -EINVAL; 74 75 common->debug_mask = mask; 76 return count; 77 } 78 79 static const struct file_operations fops_debug = { 80 .read = read_file_debug, 81 .write = write_file_debug, 82 .open = simple_open, 83 .owner = THIS_MODULE, 84 .llseek = default_llseek, 85 }; 86 87 #endif 88 89 #define DMA_BUF_LEN 1024 90 91 92 static ssize_t read_file_ani(struct file *file, char __user *user_buf, 93 size_t count, loff_t *ppos) 94 { 95 struct ath_softc *sc = file->private_data; 96 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 97 struct ath_hw *ah = sc->sc_ah; 98 unsigned int len = 0, size = 1024; 99 ssize_t retval = 0; 100 char *buf; 101 102 buf = kzalloc(size, GFP_KERNEL); 103 if (buf == NULL) 104 return -ENOMEM; 105 106 if (common->disable_ani) { 107 len += scnprintf(buf + len, size - len, "%s: %s\n", 108 "ANI", "DISABLED"); 109 goto exit; 110 } 111 112 len += scnprintf(buf + len, size - len, "%15s: %s\n", 113 "ANI", "ENABLED"); 114 len += scnprintf(buf + len, size - len, "%15s: %u\n", 115 "ANI RESET", ah->stats.ast_ani_reset); 116 len += scnprintf(buf + len, size - len, "%15s: %u\n", 117 "SPUR UP", ah->stats.ast_ani_spurup); 118 len += scnprintf(buf + len, size - len, "%15s: %u\n", 119 "SPUR DOWN", ah->stats.ast_ani_spurup); 120 len += scnprintf(buf + len, size - len, "%15s: %u\n", 121 "OFDM WS-DET ON", ah->stats.ast_ani_ofdmon); 122 len += scnprintf(buf + len, size - len, "%15s: %u\n", 123 "OFDM WS-DET OFF", ah->stats.ast_ani_ofdmoff); 124 len += scnprintf(buf + len, size - len, "%15s: %u\n", 125 "MRC-CCK ON", ah->stats.ast_ani_ccklow); 126 len += scnprintf(buf + len, size - len, "%15s: %u\n", 127 "MRC-CCK OFF", ah->stats.ast_ani_cckhigh); 128 len += scnprintf(buf + len, size - len, "%15s: %u\n", 129 "FIR-STEP UP", ah->stats.ast_ani_stepup); 130 len += scnprintf(buf + len, size - len, "%15s: %u\n", 131 "FIR-STEP DOWN", ah->stats.ast_ani_stepdown); 132 len += scnprintf(buf + len, size - len, "%15s: %u\n", 133 "INV LISTENTIME", ah->stats.ast_ani_lneg_or_lzero); 134 len += scnprintf(buf + len, size - len, "%15s: %u\n", 135 "OFDM ERRORS", ah->stats.ast_ani_ofdmerrs); 136 len += scnprintf(buf + len, size - len, "%15s: %u\n", 137 "CCK ERRORS", ah->stats.ast_ani_cckerrs); 138 exit: 139 if (len > size) 140 len = size; 141 142 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 143 kfree(buf); 144 145 return retval; 146 } 147 148 static ssize_t write_file_ani(struct file *file, 149 const char __user *user_buf, 150 size_t count, loff_t *ppos) 151 { 152 struct ath_softc *sc = file->private_data; 153 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 154 unsigned long ani; 155 char buf[32]; 156 ssize_t len; 157 158 len = min(count, sizeof(buf) - 1); 159 if (copy_from_user(buf, user_buf, len)) 160 return -EFAULT; 161 162 buf[len] = '\0'; 163 if (kstrtoul(buf, 0, &ani)) 164 return -EINVAL; 165 166 if (ani < 0 || ani > 1) 167 return -EINVAL; 168 169 common->disable_ani = !ani; 170 171 if (common->disable_ani) { 172 clear_bit(SC_OP_ANI_RUN, &sc->sc_flags); 173 ath_stop_ani(sc); 174 } else { 175 ath_check_ani(sc); 176 } 177 178 return count; 179 } 180 181 static const struct file_operations fops_ani = { 182 .read = read_file_ani, 183 .write = write_file_ani, 184 .open = simple_open, 185 .owner = THIS_MODULE, 186 .llseek = default_llseek, 187 }; 188 189 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT 190 191 static ssize_t read_file_bt_ant_diversity(struct file *file, 192 char __user *user_buf, 193 size_t count, loff_t *ppos) 194 { 195 struct ath_softc *sc = file->private_data; 196 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 197 char buf[32]; 198 unsigned int len; 199 200 len = sprintf(buf, "%d\n", common->bt_ant_diversity); 201 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 202 } 203 204 static ssize_t write_file_bt_ant_diversity(struct file *file, 205 const char __user *user_buf, 206 size_t count, loff_t *ppos) 207 { 208 struct ath_softc *sc = file->private_data; 209 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 210 struct ath9k_hw_capabilities *pCap = &sc->sc_ah->caps; 211 unsigned long bt_ant_diversity; 212 char buf[32]; 213 ssize_t len; 214 215 len = min(count, sizeof(buf) - 1); 216 if (copy_from_user(buf, user_buf, len)) 217 return -EFAULT; 218 219 if (!(pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV)) 220 goto exit; 221 222 buf[len] = '\0'; 223 if (kstrtoul(buf, 0, &bt_ant_diversity)) 224 return -EINVAL; 225 226 common->bt_ant_diversity = !!bt_ant_diversity; 227 ath9k_ps_wakeup(sc); 228 ath9k_hw_set_bt_ant_diversity(sc->sc_ah, common->bt_ant_diversity); 229 ath_dbg(common, CONFIG, "Enable WLAN/BT RX Antenna diversity: %d\n", 230 common->bt_ant_diversity); 231 ath9k_ps_restore(sc); 232 exit: 233 return count; 234 } 235 236 static const struct file_operations fops_bt_ant_diversity = { 237 .read = read_file_bt_ant_diversity, 238 .write = write_file_bt_ant_diversity, 239 .open = simple_open, 240 .owner = THIS_MODULE, 241 .llseek = default_llseek, 242 }; 243 244 #endif 245 246 void ath9k_debug_stat_ant(struct ath_softc *sc, 247 struct ath_hw_antcomb_conf *div_ant_conf, 248 int main_rssi_avg, int alt_rssi_avg) 249 { 250 struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN]; 251 struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT]; 252 253 as_main->lna_attempt_cnt[div_ant_conf->main_lna_conf]++; 254 as_alt->lna_attempt_cnt[div_ant_conf->alt_lna_conf]++; 255 256 as_main->rssi_avg = main_rssi_avg; 257 as_alt->rssi_avg = alt_rssi_avg; 258 } 259 260 static ssize_t read_file_antenna_diversity(struct file *file, 261 char __user *user_buf, 262 size_t count, loff_t *ppos) 263 { 264 struct ath_softc *sc = file->private_data; 265 struct ath_hw *ah = sc->sc_ah; 266 struct ath9k_hw_capabilities *pCap = &ah->caps; 267 struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN]; 268 struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT]; 269 struct ath_hw_antcomb_conf div_ant_conf; 270 unsigned int len = 0, size = 1024; 271 ssize_t retval = 0; 272 char *buf; 273 char *lna_conf_str[4] = {"LNA1_MINUS_LNA2", 274 "LNA2", 275 "LNA1", 276 "LNA1_PLUS_LNA2"}; 277 278 buf = kzalloc(size, GFP_KERNEL); 279 if (buf == NULL) 280 return -ENOMEM; 281 282 if (!(pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)) { 283 len += scnprintf(buf + len, size - len, "%s\n", 284 "Antenna Diversity Combining is disabled"); 285 goto exit; 286 } 287 288 ath9k_ps_wakeup(sc); 289 ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf); 290 len += scnprintf(buf + len, size - len, "Current MAIN config : %s\n", 291 lna_conf_str[div_ant_conf.main_lna_conf]); 292 len += scnprintf(buf + len, size - len, "Current ALT config : %s\n", 293 lna_conf_str[div_ant_conf.alt_lna_conf]); 294 len += scnprintf(buf + len, size - len, "Average MAIN RSSI : %d\n", 295 as_main->rssi_avg); 296 len += scnprintf(buf + len, size - len, "Average ALT RSSI : %d\n\n", 297 as_alt->rssi_avg); 298 ath9k_ps_restore(sc); 299 300 len += scnprintf(buf + len, size - len, "Packet Receive Cnt:\n"); 301 len += scnprintf(buf + len, size - len, "-------------------\n"); 302 303 len += scnprintf(buf + len, size - len, "%30s%15s\n", 304 "MAIN", "ALT"); 305 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n", 306 "TOTAL COUNT", 307 as_main->recv_cnt, 308 as_alt->recv_cnt); 309 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n", 310 "LNA1", 311 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1], 312 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1]); 313 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n", 314 "LNA2", 315 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2], 316 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2]); 317 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n", 318 "LNA1 + LNA2", 319 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2], 320 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]); 321 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n", 322 "LNA1 - LNA2", 323 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2], 324 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]); 325 326 len += scnprintf(buf + len, size - len, "\nLNA Config Attempts:\n"); 327 len += scnprintf(buf + len, size - len, "--------------------\n"); 328 329 len += scnprintf(buf + len, size - len, "%30s%15s\n", 330 "MAIN", "ALT"); 331 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n", 332 "LNA1", 333 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1], 334 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1]); 335 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n", 336 "LNA2", 337 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2], 338 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2]); 339 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n", 340 "LNA1 + LNA2", 341 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2], 342 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]); 343 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n", 344 "LNA1 - LNA2", 345 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2], 346 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]); 347 348 exit: 349 if (len > size) 350 len = size; 351 352 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 353 kfree(buf); 354 355 return retval; 356 } 357 358 static const struct file_operations fops_antenna_diversity = { 359 .read = read_file_antenna_diversity, 360 .open = simple_open, 361 .owner = THIS_MODULE, 362 .llseek = default_llseek, 363 }; 364 365 static ssize_t read_file_dma(struct file *file, char __user *user_buf, 366 size_t count, loff_t *ppos) 367 { 368 struct ath_softc *sc = file->private_data; 369 struct ath_hw *ah = sc->sc_ah; 370 char *buf; 371 int retval; 372 unsigned int len = 0; 373 u32 val[ATH9K_NUM_DMA_DEBUG_REGS]; 374 int i, qcuOffset = 0, dcuOffset = 0; 375 u32 *qcuBase = &val[0], *dcuBase = &val[4]; 376 377 buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL); 378 if (!buf) 379 return -ENOMEM; 380 381 ath9k_ps_wakeup(sc); 382 383 REG_WRITE_D(ah, AR_MACMISC, 384 ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) | 385 (AR_MACMISC_MISC_OBS_BUS_1 << 386 AR_MACMISC_MISC_OBS_BUS_MSB_S))); 387 388 len += scnprintf(buf + len, DMA_BUF_LEN - len, 389 "Raw DMA Debug values:\n"); 390 391 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) { 392 if (i % 4 == 0) 393 len += scnprintf(buf + len, DMA_BUF_LEN - len, "\n"); 394 395 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32))); 396 len += scnprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ", 397 i, val[i]); 398 } 399 400 len += scnprintf(buf + len, DMA_BUF_LEN - len, "\n\n"); 401 len += scnprintf(buf + len, DMA_BUF_LEN - len, 402 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n"); 403 404 for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) { 405 if (i == 8) { 406 qcuOffset = 0; 407 qcuBase++; 408 } 409 410 if (i == 6) { 411 dcuOffset = 0; 412 dcuBase++; 413 } 414 415 len += scnprintf(buf + len, DMA_BUF_LEN - len, 416 "%2d %2x %1x %2x %2x\n", 417 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset, 418 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3), 419 val[2] & (0x7 << (i * 3)) >> (i * 3), 420 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset); 421 } 422 423 len += scnprintf(buf + len, DMA_BUF_LEN - len, "\n"); 424 425 len += scnprintf(buf + len, DMA_BUF_LEN - len, 426 "qcu_stitch state: %2x qcu_fetch state: %2x\n", 427 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22); 428 len += scnprintf(buf + len, DMA_BUF_LEN - len, 429 "qcu_complete state: %2x dcu_complete state: %2x\n", 430 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3)); 431 len += scnprintf(buf + len, DMA_BUF_LEN - len, 432 "dcu_arb state: %2x dcu_fp state: %2x\n", 433 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27); 434 len += scnprintf(buf + len, DMA_BUF_LEN - len, 435 "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n", 436 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10); 437 len += scnprintf(buf + len, DMA_BUF_LEN - len, 438 "txfifo_valid_0: %1d txfifo_valid_1: %1d\n", 439 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12); 440 len += scnprintf(buf + len, DMA_BUF_LEN - len, 441 "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n", 442 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17); 443 444 len += scnprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n", 445 REG_READ_D(ah, AR_OBS_BUS_1)); 446 len += scnprintf(buf + len, DMA_BUF_LEN - len, 447 "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR)); 448 449 ath9k_ps_restore(sc); 450 451 if (len > DMA_BUF_LEN) 452 len = DMA_BUF_LEN; 453 454 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 455 kfree(buf); 456 return retval; 457 } 458 459 static const struct file_operations fops_dma = { 460 .read = read_file_dma, 461 .open = simple_open, 462 .owner = THIS_MODULE, 463 .llseek = default_llseek, 464 }; 465 466 467 void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status) 468 { 469 if (status) 470 sc->debug.stats.istats.total++; 471 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { 472 if (status & ATH9K_INT_RXLP) 473 sc->debug.stats.istats.rxlp++; 474 if (status & ATH9K_INT_RXHP) 475 sc->debug.stats.istats.rxhp++; 476 if (status & ATH9K_INT_BB_WATCHDOG) 477 sc->debug.stats.istats.bb_watchdog++; 478 } else { 479 if (status & ATH9K_INT_RX) 480 sc->debug.stats.istats.rxok++; 481 } 482 if (status & ATH9K_INT_RXEOL) 483 sc->debug.stats.istats.rxeol++; 484 if (status & ATH9K_INT_RXORN) 485 sc->debug.stats.istats.rxorn++; 486 if (status & ATH9K_INT_TX) 487 sc->debug.stats.istats.txok++; 488 if (status & ATH9K_INT_TXURN) 489 sc->debug.stats.istats.txurn++; 490 if (status & ATH9K_INT_RXPHY) 491 sc->debug.stats.istats.rxphyerr++; 492 if (status & ATH9K_INT_RXKCM) 493 sc->debug.stats.istats.rx_keycache_miss++; 494 if (status & ATH9K_INT_SWBA) 495 sc->debug.stats.istats.swba++; 496 if (status & ATH9K_INT_BMISS) 497 sc->debug.stats.istats.bmiss++; 498 if (status & ATH9K_INT_BNR) 499 sc->debug.stats.istats.bnr++; 500 if (status & ATH9K_INT_CST) 501 sc->debug.stats.istats.cst++; 502 if (status & ATH9K_INT_GTT) 503 sc->debug.stats.istats.gtt++; 504 if (status & ATH9K_INT_TIM) 505 sc->debug.stats.istats.tim++; 506 if (status & ATH9K_INT_CABEND) 507 sc->debug.stats.istats.cabend++; 508 if (status & ATH9K_INT_DTIMSYNC) 509 sc->debug.stats.istats.dtimsync++; 510 if (status & ATH9K_INT_DTIM) 511 sc->debug.stats.istats.dtim++; 512 if (status & ATH9K_INT_TSFOOR) 513 sc->debug.stats.istats.tsfoor++; 514 if (status & ATH9K_INT_MCI) 515 sc->debug.stats.istats.mci++; 516 if (status & ATH9K_INT_GENTIMER) 517 sc->debug.stats.istats.gen_timer++; 518 } 519 520 static ssize_t read_file_interrupt(struct file *file, char __user *user_buf, 521 size_t count, loff_t *ppos) 522 { 523 struct ath_softc *sc = file->private_data; 524 unsigned int len = 0; 525 int rv; 526 int mxlen = 4000; 527 char *buf = kmalloc(mxlen, GFP_KERNEL); 528 if (!buf) 529 return -ENOMEM; 530 531 #define PR_IS(a, s) \ 532 do { \ 533 len += scnprintf(buf + len, mxlen - len, \ 534 "%21s: %10u\n", a, \ 535 sc->debug.stats.istats.s); \ 536 } while (0) 537 538 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { 539 PR_IS("RXLP", rxlp); 540 PR_IS("RXHP", rxhp); 541 PR_IS("WATHDOG", bb_watchdog); 542 } else { 543 PR_IS("RX", rxok); 544 } 545 PR_IS("RXEOL", rxeol); 546 PR_IS("RXORN", rxorn); 547 PR_IS("TX", txok); 548 PR_IS("TXURN", txurn); 549 PR_IS("MIB", mib); 550 PR_IS("RXPHY", rxphyerr); 551 PR_IS("RXKCM", rx_keycache_miss); 552 PR_IS("SWBA", swba); 553 PR_IS("BMISS", bmiss); 554 PR_IS("BNR", bnr); 555 PR_IS("CST", cst); 556 PR_IS("GTT", gtt); 557 PR_IS("TIM", tim); 558 PR_IS("CABEND", cabend); 559 PR_IS("DTIMSYNC", dtimsync); 560 PR_IS("DTIM", dtim); 561 PR_IS("TSFOOR", tsfoor); 562 PR_IS("MCI", mci); 563 PR_IS("GENTIMER", gen_timer); 564 PR_IS("TOTAL", total); 565 566 len += scnprintf(buf + len, mxlen - len, 567 "SYNC_CAUSE stats:\n"); 568 569 PR_IS("Sync-All", sync_cause_all); 570 PR_IS("RTC-IRQ", sync_rtc_irq); 571 PR_IS("MAC-IRQ", sync_mac_irq); 572 PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access); 573 PR_IS("APB-Timeout", apb_timeout); 574 PR_IS("PCI-Mode-Conflict", pci_mode_conflict); 575 PR_IS("HOST1-Fatal", host1_fatal); 576 PR_IS("HOST1-Perr", host1_perr); 577 PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr); 578 PR_IS("RADM-CPL-EP", radm_cpl_ep); 579 PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort); 580 PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort); 581 PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err); 582 PR_IS("RADM-CPL-Timeout", radm_cpl_timeout); 583 PR_IS("Local-Bus-Timeout", local_timeout); 584 PR_IS("PM-Access", pm_access); 585 PR_IS("MAC-Awake", mac_awake); 586 PR_IS("MAC-Asleep", mac_asleep); 587 PR_IS("MAC-Sleep-Access", mac_sleep_access); 588 589 if (len > mxlen) 590 len = mxlen; 591 592 rv = simple_read_from_buffer(user_buf, count, ppos, buf, len); 593 kfree(buf); 594 return rv; 595 } 596 597 static const struct file_operations fops_interrupt = { 598 .read = read_file_interrupt, 599 .open = simple_open, 600 .owner = THIS_MODULE, 601 .llseek = default_llseek, 602 }; 603 604 static ssize_t read_file_xmit(struct file *file, char __user *user_buf, 605 size_t count, loff_t *ppos) 606 { 607 struct ath_softc *sc = file->private_data; 608 char *buf; 609 unsigned int len = 0, size = 2048; 610 ssize_t retval = 0; 611 612 buf = kzalloc(size, GFP_KERNEL); 613 if (buf == NULL) 614 return -ENOMEM; 615 616 len += sprintf(buf, "%30s %10s%10s%10s\n\n", 617 "BE", "BK", "VI", "VO"); 618 619 PR("MPDUs Queued: ", queued); 620 PR("MPDUs Completed: ", completed); 621 PR("MPDUs XRetried: ", xretries); 622 PR("Aggregates: ", a_aggr); 623 PR("AMPDUs Queued HW:", a_queued_hw); 624 PR("AMPDUs Queued SW:", a_queued_sw); 625 PR("AMPDUs Completed:", a_completed); 626 PR("AMPDUs Retried: ", a_retries); 627 PR("AMPDUs XRetried: ", a_xretries); 628 PR("TXERR Filtered: ", txerr_filtered); 629 PR("FIFO Underrun: ", fifo_underrun); 630 PR("TXOP Exceeded: ", xtxop); 631 PR("TXTIMER Expiry: ", timer_exp); 632 PR("DESC CFG Error: ", desc_cfg_err); 633 PR("DATA Underrun: ", data_underrun); 634 PR("DELIM Underrun: ", delim_underrun); 635 PR("TX-Pkts-All: ", tx_pkts_all); 636 PR("TX-Bytes-All: ", tx_bytes_all); 637 PR("HW-put-tx-buf: ", puttxbuf); 638 PR("HW-tx-start: ", txstart); 639 PR("HW-tx-proc-desc: ", txprocdesc); 640 PR("TX-Failed: ", txfailed); 641 642 if (len > size) 643 len = size; 644 645 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 646 kfree(buf); 647 648 return retval; 649 } 650 651 static ssize_t print_queue(struct ath_softc *sc, struct ath_txq *txq, 652 char *buf, ssize_t size) 653 { 654 ssize_t len = 0; 655 656 ath_txq_lock(sc, txq); 657 658 len += scnprintf(buf + len, size - len, "%s: %d ", 659 "qnum", txq->axq_qnum); 660 len += scnprintf(buf + len, size - len, "%s: %2d ", 661 "qdepth", txq->axq_depth); 662 len += scnprintf(buf + len, size - len, "%s: %2d ", 663 "ampdu-depth", txq->axq_ampdu_depth); 664 len += scnprintf(buf + len, size - len, "%s: %3d ", 665 "pending", txq->pending_frames); 666 len += scnprintf(buf + len, size - len, "%s: %d\n", 667 "stopped", txq->stopped); 668 669 ath_txq_unlock(sc, txq); 670 return len; 671 } 672 673 static ssize_t read_file_queues(struct file *file, char __user *user_buf, 674 size_t count, loff_t *ppos) 675 { 676 struct ath_softc *sc = file->private_data; 677 struct ath_txq *txq; 678 char *buf; 679 unsigned int len = 0, size = 1024; 680 ssize_t retval = 0; 681 int i; 682 char *qname[4] = {"VO", "VI", "BE", "BK"}; 683 684 buf = kzalloc(size, GFP_KERNEL); 685 if (buf == NULL) 686 return -ENOMEM; 687 688 for (i = 0; i < IEEE80211_NUM_ACS; i++) { 689 txq = sc->tx.txq_map[i]; 690 len += scnprintf(buf + len, size - len, "(%s): ", qname[i]); 691 len += print_queue(sc, txq, buf + len, size - len); 692 } 693 694 len += scnprintf(buf + len, size - len, "(CAB): "); 695 len += print_queue(sc, sc->beacon.cabq, buf + len, size - len); 696 697 if (len > size) 698 len = size; 699 700 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 701 kfree(buf); 702 703 return retval; 704 } 705 706 static ssize_t read_file_misc(struct file *file, char __user *user_buf, 707 size_t count, loff_t *ppos) 708 { 709 struct ath_softc *sc = file->private_data; 710 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 711 struct ieee80211_hw *hw = sc->hw; 712 struct ath9k_vif_iter_data iter_data; 713 char buf[512]; 714 unsigned int len = 0; 715 ssize_t retval = 0; 716 unsigned int reg; 717 u32 rxfilter; 718 719 len += scnprintf(buf + len, sizeof(buf) - len, 720 "BSSID: %pM\n", common->curbssid); 721 len += scnprintf(buf + len, sizeof(buf) - len, 722 "BSSID-MASK: %pM\n", common->bssidmask); 723 len += scnprintf(buf + len, sizeof(buf) - len, 724 "OPMODE: %s\n", 725 ath_opmode_to_string(sc->sc_ah->opmode)); 726 727 ath9k_ps_wakeup(sc); 728 rxfilter = ath9k_hw_getrxfilter(sc->sc_ah); 729 ath9k_ps_restore(sc); 730 731 len += scnprintf(buf + len, sizeof(buf) - len, 732 "RXFILTER: 0x%x", rxfilter); 733 734 if (rxfilter & ATH9K_RX_FILTER_UCAST) 735 len += scnprintf(buf + len, sizeof(buf) - len, " UCAST"); 736 if (rxfilter & ATH9K_RX_FILTER_MCAST) 737 len += scnprintf(buf + len, sizeof(buf) - len, " MCAST"); 738 if (rxfilter & ATH9K_RX_FILTER_BCAST) 739 len += scnprintf(buf + len, sizeof(buf) - len, " BCAST"); 740 if (rxfilter & ATH9K_RX_FILTER_CONTROL) 741 len += scnprintf(buf + len, sizeof(buf) - len, " CONTROL"); 742 if (rxfilter & ATH9K_RX_FILTER_BEACON) 743 len += scnprintf(buf + len, sizeof(buf) - len, " BEACON"); 744 if (rxfilter & ATH9K_RX_FILTER_PROM) 745 len += scnprintf(buf + len, sizeof(buf) - len, " PROM"); 746 if (rxfilter & ATH9K_RX_FILTER_PROBEREQ) 747 len += scnprintf(buf + len, sizeof(buf) - len, " PROBEREQ"); 748 if (rxfilter & ATH9K_RX_FILTER_PHYERR) 749 len += scnprintf(buf + len, sizeof(buf) - len, " PHYERR"); 750 if (rxfilter & ATH9K_RX_FILTER_MYBEACON) 751 len += scnprintf(buf + len, sizeof(buf) - len, " MYBEACON"); 752 if (rxfilter & ATH9K_RX_FILTER_COMP_BAR) 753 len += scnprintf(buf + len, sizeof(buf) - len, " COMP_BAR"); 754 if (rxfilter & ATH9K_RX_FILTER_PSPOLL) 755 len += scnprintf(buf + len, sizeof(buf) - len, " PSPOLL"); 756 if (rxfilter & ATH9K_RX_FILTER_PHYRADAR) 757 len += scnprintf(buf + len, sizeof(buf) - len, " PHYRADAR"); 758 if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL) 759 len += scnprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL"); 760 if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER) 761 len += scnprintf(buf + len, sizeof(buf) - len, " CONTROL_WRAPPER"); 762 763 len += scnprintf(buf + len, sizeof(buf) - len, "\n"); 764 765 reg = sc->sc_ah->imask; 766 767 len += scnprintf(buf + len, sizeof(buf) - len, 768 "INTERRUPT-MASK: 0x%x", reg); 769 770 if (reg & ATH9K_INT_SWBA) 771 len += scnprintf(buf + len, sizeof(buf) - len, " SWBA"); 772 if (reg & ATH9K_INT_BMISS) 773 len += scnprintf(buf + len, sizeof(buf) - len, " BMISS"); 774 if (reg & ATH9K_INT_CST) 775 len += scnprintf(buf + len, sizeof(buf) - len, " CST"); 776 if (reg & ATH9K_INT_RX) 777 len += scnprintf(buf + len, sizeof(buf) - len, " RX"); 778 if (reg & ATH9K_INT_RXHP) 779 len += scnprintf(buf + len, sizeof(buf) - len, " RXHP"); 780 if (reg & ATH9K_INT_RXLP) 781 len += scnprintf(buf + len, sizeof(buf) - len, " RXLP"); 782 if (reg & ATH9K_INT_BB_WATCHDOG) 783 len += scnprintf(buf + len, sizeof(buf) - len, " BB_WATCHDOG"); 784 785 len += scnprintf(buf + len, sizeof(buf) - len, "\n"); 786 787 ath9k_calculate_iter_data(hw, NULL, &iter_data); 788 789 len += scnprintf(buf + len, sizeof(buf) - len, 790 "VIF-COUNTS: AP: %i STA: %i MESH: %i WDS: %i" 791 " ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n", 792 iter_data.naps, iter_data.nstations, iter_data.nmeshes, 793 iter_data.nwds, iter_data.nadhocs, 794 sc->nvifs, sc->nbcnvifs); 795 796 if (len > sizeof(buf)) 797 len = sizeof(buf); 798 799 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 800 return retval; 801 } 802 803 static ssize_t read_file_reset(struct file *file, char __user *user_buf, 804 size_t count, loff_t *ppos) 805 { 806 struct ath_softc *sc = file->private_data; 807 char buf[512]; 808 unsigned int len = 0; 809 810 len += scnprintf(buf + len, sizeof(buf) - len, 811 "%17s: %2d\n", "Baseband Hang", 812 sc->debug.stats.reset[RESET_TYPE_BB_HANG]); 813 len += scnprintf(buf + len, sizeof(buf) - len, 814 "%17s: %2d\n", "Baseband Watchdog", 815 sc->debug.stats.reset[RESET_TYPE_BB_WATCHDOG]); 816 len += scnprintf(buf + len, sizeof(buf) - len, 817 "%17s: %2d\n", "Fatal HW Error", 818 sc->debug.stats.reset[RESET_TYPE_FATAL_INT]); 819 len += scnprintf(buf + len, sizeof(buf) - len, 820 "%17s: %2d\n", "TX HW error", 821 sc->debug.stats.reset[RESET_TYPE_TX_ERROR]); 822 len += scnprintf(buf + len, sizeof(buf) - len, 823 "%17s: %2d\n", "TX Path Hang", 824 sc->debug.stats.reset[RESET_TYPE_TX_HANG]); 825 len += scnprintf(buf + len, sizeof(buf) - len, 826 "%17s: %2d\n", "PLL RX Hang", 827 sc->debug.stats.reset[RESET_TYPE_PLL_HANG]); 828 len += scnprintf(buf + len, sizeof(buf) - len, 829 "%17s: %2d\n", "MCI Reset", 830 sc->debug.stats.reset[RESET_TYPE_MCI]); 831 832 if (len > sizeof(buf)) 833 len = sizeof(buf); 834 835 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 836 } 837 838 void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf, 839 struct ath_tx_status *ts, struct ath_txq *txq, 840 unsigned int flags) 841 { 842 int qnum = txq->axq_qnum; 843 844 TX_STAT_INC(qnum, tx_pkts_all); 845 sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len; 846 847 if (bf_isampdu(bf)) { 848 if (flags & ATH_TX_ERROR) 849 TX_STAT_INC(qnum, a_xretries); 850 else 851 TX_STAT_INC(qnum, a_completed); 852 } else { 853 if (ts->ts_status & ATH9K_TXERR_XRETRY) 854 TX_STAT_INC(qnum, xretries); 855 else 856 TX_STAT_INC(qnum, completed); 857 } 858 859 if (ts->ts_status & ATH9K_TXERR_FILT) 860 TX_STAT_INC(qnum, txerr_filtered); 861 if (ts->ts_status & ATH9K_TXERR_FIFO) 862 TX_STAT_INC(qnum, fifo_underrun); 863 if (ts->ts_status & ATH9K_TXERR_XTXOP) 864 TX_STAT_INC(qnum, xtxop); 865 if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED) 866 TX_STAT_INC(qnum, timer_exp); 867 if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR) 868 TX_STAT_INC(qnum, desc_cfg_err); 869 if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN) 870 TX_STAT_INC(qnum, data_underrun); 871 if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN) 872 TX_STAT_INC(qnum, delim_underrun); 873 } 874 875 static const struct file_operations fops_xmit = { 876 .read = read_file_xmit, 877 .open = simple_open, 878 .owner = THIS_MODULE, 879 .llseek = default_llseek, 880 }; 881 882 static const struct file_operations fops_queues = { 883 .read = read_file_queues, 884 .open = simple_open, 885 .owner = THIS_MODULE, 886 .llseek = default_llseek, 887 }; 888 889 static const struct file_operations fops_misc = { 890 .read = read_file_misc, 891 .open = simple_open, 892 .owner = THIS_MODULE, 893 .llseek = default_llseek, 894 }; 895 896 static const struct file_operations fops_reset = { 897 .read = read_file_reset, 898 .open = simple_open, 899 .owner = THIS_MODULE, 900 .llseek = default_llseek, 901 }; 902 903 static ssize_t read_file_recv(struct file *file, char __user *user_buf, 904 size_t count, loff_t *ppos) 905 { 906 #define PHY_ERR(s, p) \ 907 len += scnprintf(buf + len, size - len, "%22s : %10u\n", s, \ 908 sc->debug.stats.rxstats.phy_err_stats[p]); 909 910 #define RXS_ERR(s, e) \ 911 do { \ 912 len += scnprintf(buf + len, size - len, \ 913 "%22s : %10u\n", s, \ 914 sc->debug.stats.rxstats.e);\ 915 } while (0) 916 917 struct ath_softc *sc = file->private_data; 918 char *buf; 919 unsigned int len = 0, size = 1600; 920 ssize_t retval = 0; 921 922 buf = kzalloc(size, GFP_KERNEL); 923 if (buf == NULL) 924 return -ENOMEM; 925 926 RXS_ERR("CRC ERR", crc_err); 927 RXS_ERR("DECRYPT CRC ERR", decrypt_crc_err); 928 RXS_ERR("PHY ERR", phy_err); 929 RXS_ERR("MIC ERR", mic_err); 930 RXS_ERR("PRE-DELIM CRC ERR", pre_delim_crc_err); 931 RXS_ERR("POST-DELIM CRC ERR", post_delim_crc_err); 932 RXS_ERR("DECRYPT BUSY ERR", decrypt_busy_err); 933 RXS_ERR("RX-LENGTH-ERR", rx_len_err); 934 RXS_ERR("RX-OOM-ERR", rx_oom_err); 935 RXS_ERR("RX-RATE-ERR", rx_rate_err); 936 RXS_ERR("RX-TOO-MANY-FRAGS", rx_too_many_frags_err); 937 938 PHY_ERR("UNDERRUN ERR", ATH9K_PHYERR_UNDERRUN); 939 PHY_ERR("TIMING ERR", ATH9K_PHYERR_TIMING); 940 PHY_ERR("PARITY ERR", ATH9K_PHYERR_PARITY); 941 PHY_ERR("RATE ERR", ATH9K_PHYERR_RATE); 942 PHY_ERR("LENGTH ERR", ATH9K_PHYERR_LENGTH); 943 PHY_ERR("RADAR ERR", ATH9K_PHYERR_RADAR); 944 PHY_ERR("SERVICE ERR", ATH9K_PHYERR_SERVICE); 945 PHY_ERR("TOR ERR", ATH9K_PHYERR_TOR); 946 PHY_ERR("OFDM-TIMING ERR", ATH9K_PHYERR_OFDM_TIMING); 947 PHY_ERR("OFDM-SIGNAL-PARITY ERR", ATH9K_PHYERR_OFDM_SIGNAL_PARITY); 948 PHY_ERR("OFDM-RATE ERR", ATH9K_PHYERR_OFDM_RATE_ILLEGAL); 949 PHY_ERR("OFDM-LENGTH ERR", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL); 950 PHY_ERR("OFDM-POWER-DROP ERR", ATH9K_PHYERR_OFDM_POWER_DROP); 951 PHY_ERR("OFDM-SERVICE ERR", ATH9K_PHYERR_OFDM_SERVICE); 952 PHY_ERR("OFDM-RESTART ERR", ATH9K_PHYERR_OFDM_RESTART); 953 PHY_ERR("FALSE-RADAR-EXT ERR", ATH9K_PHYERR_FALSE_RADAR_EXT); 954 PHY_ERR("CCK-TIMING ERR", ATH9K_PHYERR_CCK_TIMING); 955 PHY_ERR("CCK-HEADER-CRC ERR", ATH9K_PHYERR_CCK_HEADER_CRC); 956 PHY_ERR("CCK-RATE ERR", ATH9K_PHYERR_CCK_RATE_ILLEGAL); 957 PHY_ERR("CCK-SERVICE ERR", ATH9K_PHYERR_CCK_SERVICE); 958 PHY_ERR("CCK-RESTART ERR", ATH9K_PHYERR_CCK_RESTART); 959 PHY_ERR("CCK-LENGTH ERR", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL); 960 PHY_ERR("CCK-POWER-DROP ERR", ATH9K_PHYERR_CCK_POWER_DROP); 961 PHY_ERR("HT-CRC ERR", ATH9K_PHYERR_HT_CRC_ERROR); 962 PHY_ERR("HT-LENGTH ERR", ATH9K_PHYERR_HT_LENGTH_ILLEGAL); 963 PHY_ERR("HT-RATE ERR", ATH9K_PHYERR_HT_RATE_ILLEGAL); 964 965 RXS_ERR("RX-Pkts-All", rx_pkts_all); 966 RXS_ERR("RX-Bytes-All", rx_bytes_all); 967 RXS_ERR("RX-Beacons", rx_beacons); 968 RXS_ERR("RX-Frags", rx_frags); 969 RXS_ERR("RX-Spectral", rx_spectral); 970 971 if (len > size) 972 len = size; 973 974 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 975 kfree(buf); 976 977 return retval; 978 979 #undef RXS_ERR 980 #undef PHY_ERR 981 } 982 983 void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs) 984 { 985 #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++ 986 987 RX_STAT_INC(rx_pkts_all); 988 sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen; 989 990 if (rs->rs_status & ATH9K_RXERR_CRC) 991 RX_STAT_INC(crc_err); 992 if (rs->rs_status & ATH9K_RXERR_DECRYPT) 993 RX_STAT_INC(decrypt_crc_err); 994 if (rs->rs_status & ATH9K_RXERR_MIC) 995 RX_STAT_INC(mic_err); 996 if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE) 997 RX_STAT_INC(pre_delim_crc_err); 998 if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST) 999 RX_STAT_INC(post_delim_crc_err); 1000 if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY) 1001 RX_STAT_INC(decrypt_busy_err); 1002 1003 if (rs->rs_status & ATH9K_RXERR_PHY) { 1004 RX_STAT_INC(phy_err); 1005 if (rs->rs_phyerr < ATH9K_PHYERR_MAX) 1006 RX_PHY_ERR_INC(rs->rs_phyerr); 1007 } 1008 1009 #undef RX_PHY_ERR_INC 1010 } 1011 1012 static const struct file_operations fops_recv = { 1013 .read = read_file_recv, 1014 .open = simple_open, 1015 .owner = THIS_MODULE, 1016 .llseek = default_llseek, 1017 }; 1018 1019 static ssize_t read_file_spec_scan_ctl(struct file *file, char __user *user_buf, 1020 size_t count, loff_t *ppos) 1021 { 1022 struct ath_softc *sc = file->private_data; 1023 char *mode = ""; 1024 unsigned int len; 1025 1026 switch (sc->spectral_mode) { 1027 case SPECTRAL_DISABLED: 1028 mode = "disable"; 1029 break; 1030 case SPECTRAL_BACKGROUND: 1031 mode = "background"; 1032 break; 1033 case SPECTRAL_CHANSCAN: 1034 mode = "chanscan"; 1035 break; 1036 case SPECTRAL_MANUAL: 1037 mode = "manual"; 1038 break; 1039 } 1040 len = strlen(mode); 1041 return simple_read_from_buffer(user_buf, count, ppos, mode, len); 1042 } 1043 1044 static ssize_t write_file_spec_scan_ctl(struct file *file, 1045 const char __user *user_buf, 1046 size_t count, loff_t *ppos) 1047 { 1048 struct ath_softc *sc = file->private_data; 1049 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 1050 char buf[32]; 1051 ssize_t len; 1052 1053 if (config_enabled(CONFIG_ATH9K_TX99)) 1054 return -EOPNOTSUPP; 1055 1056 len = min(count, sizeof(buf) - 1); 1057 if (copy_from_user(buf, user_buf, len)) 1058 return -EFAULT; 1059 1060 buf[len] = '\0'; 1061 1062 if (strncmp("trigger", buf, 7) == 0) { 1063 ath9k_spectral_scan_trigger(sc->hw); 1064 } else if (strncmp("background", buf, 9) == 0) { 1065 ath9k_spectral_scan_config(sc->hw, SPECTRAL_BACKGROUND); 1066 ath_dbg(common, CONFIG, "spectral scan: background mode enabled\n"); 1067 } else if (strncmp("chanscan", buf, 8) == 0) { 1068 ath9k_spectral_scan_config(sc->hw, SPECTRAL_CHANSCAN); 1069 ath_dbg(common, CONFIG, "spectral scan: channel scan mode enabled\n"); 1070 } else if (strncmp("manual", buf, 6) == 0) { 1071 ath9k_spectral_scan_config(sc->hw, SPECTRAL_MANUAL); 1072 ath_dbg(common, CONFIG, "spectral scan: manual mode enabled\n"); 1073 } else if (strncmp("disable", buf, 7) == 0) { 1074 ath9k_spectral_scan_config(sc->hw, SPECTRAL_DISABLED); 1075 ath_dbg(common, CONFIG, "spectral scan: disabled\n"); 1076 } else { 1077 return -EINVAL; 1078 } 1079 1080 return count; 1081 } 1082 1083 static const struct file_operations fops_spec_scan_ctl = { 1084 .read = read_file_spec_scan_ctl, 1085 .write = write_file_spec_scan_ctl, 1086 .open = simple_open, 1087 .owner = THIS_MODULE, 1088 .llseek = default_llseek, 1089 }; 1090 1091 static ssize_t read_file_spectral_short_repeat(struct file *file, 1092 char __user *user_buf, 1093 size_t count, loff_t *ppos) 1094 { 1095 struct ath_softc *sc = file->private_data; 1096 char buf[32]; 1097 unsigned int len; 1098 1099 len = sprintf(buf, "%d\n", sc->spec_config.short_repeat); 1100 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 1101 } 1102 1103 static ssize_t write_file_spectral_short_repeat(struct file *file, 1104 const char __user *user_buf, 1105 size_t count, loff_t *ppos) 1106 { 1107 struct ath_softc *sc = file->private_data; 1108 unsigned long val; 1109 char buf[32]; 1110 ssize_t len; 1111 1112 len = min(count, sizeof(buf) - 1); 1113 if (copy_from_user(buf, user_buf, len)) 1114 return -EFAULT; 1115 1116 buf[len] = '\0'; 1117 if (kstrtoul(buf, 0, &val)) 1118 return -EINVAL; 1119 1120 if (val < 0 || val > 1) 1121 return -EINVAL; 1122 1123 sc->spec_config.short_repeat = val; 1124 return count; 1125 } 1126 1127 static const struct file_operations fops_spectral_short_repeat = { 1128 .read = read_file_spectral_short_repeat, 1129 .write = write_file_spectral_short_repeat, 1130 .open = simple_open, 1131 .owner = THIS_MODULE, 1132 .llseek = default_llseek, 1133 }; 1134 1135 static ssize_t read_file_spectral_count(struct file *file, 1136 char __user *user_buf, 1137 size_t count, loff_t *ppos) 1138 { 1139 struct ath_softc *sc = file->private_data; 1140 char buf[32]; 1141 unsigned int len; 1142 1143 len = sprintf(buf, "%d\n", sc->spec_config.count); 1144 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 1145 } 1146 1147 static ssize_t write_file_spectral_count(struct file *file, 1148 const char __user *user_buf, 1149 size_t count, loff_t *ppos) 1150 { 1151 struct ath_softc *sc = file->private_data; 1152 unsigned long val; 1153 char buf[32]; 1154 ssize_t len; 1155 1156 len = min(count, sizeof(buf) - 1); 1157 if (copy_from_user(buf, user_buf, len)) 1158 return -EFAULT; 1159 1160 buf[len] = '\0'; 1161 if (kstrtoul(buf, 0, &val)) 1162 return -EINVAL; 1163 1164 if (val < 0 || val > 255) 1165 return -EINVAL; 1166 1167 sc->spec_config.count = val; 1168 return count; 1169 } 1170 1171 static const struct file_operations fops_spectral_count = { 1172 .read = read_file_spectral_count, 1173 .write = write_file_spectral_count, 1174 .open = simple_open, 1175 .owner = THIS_MODULE, 1176 .llseek = default_llseek, 1177 }; 1178 1179 static ssize_t read_file_spectral_period(struct file *file, 1180 char __user *user_buf, 1181 size_t count, loff_t *ppos) 1182 { 1183 struct ath_softc *sc = file->private_data; 1184 char buf[32]; 1185 unsigned int len; 1186 1187 len = sprintf(buf, "%d\n", sc->spec_config.period); 1188 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 1189 } 1190 1191 static ssize_t write_file_spectral_period(struct file *file, 1192 const char __user *user_buf, 1193 size_t count, loff_t *ppos) 1194 { 1195 struct ath_softc *sc = file->private_data; 1196 unsigned long val; 1197 char buf[32]; 1198 ssize_t len; 1199 1200 len = min(count, sizeof(buf) - 1); 1201 if (copy_from_user(buf, user_buf, len)) 1202 return -EFAULT; 1203 1204 buf[len] = '\0'; 1205 if (kstrtoul(buf, 0, &val)) 1206 return -EINVAL; 1207 1208 if (val < 0 || val > 255) 1209 return -EINVAL; 1210 1211 sc->spec_config.period = val; 1212 return count; 1213 } 1214 1215 static const struct file_operations fops_spectral_period = { 1216 .read = read_file_spectral_period, 1217 .write = write_file_spectral_period, 1218 .open = simple_open, 1219 .owner = THIS_MODULE, 1220 .llseek = default_llseek, 1221 }; 1222 1223 static ssize_t read_file_spectral_fft_period(struct file *file, 1224 char __user *user_buf, 1225 size_t count, loff_t *ppos) 1226 { 1227 struct ath_softc *sc = file->private_data; 1228 char buf[32]; 1229 unsigned int len; 1230 1231 len = sprintf(buf, "%d\n", sc->spec_config.fft_period); 1232 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 1233 } 1234 1235 static ssize_t write_file_spectral_fft_period(struct file *file, 1236 const char __user *user_buf, 1237 size_t count, loff_t *ppos) 1238 { 1239 struct ath_softc *sc = file->private_data; 1240 unsigned long val; 1241 char buf[32]; 1242 ssize_t len; 1243 1244 len = min(count, sizeof(buf) - 1); 1245 if (copy_from_user(buf, user_buf, len)) 1246 return -EFAULT; 1247 1248 buf[len] = '\0'; 1249 if (kstrtoul(buf, 0, &val)) 1250 return -EINVAL; 1251 1252 if (val < 0 || val > 15) 1253 return -EINVAL; 1254 1255 sc->spec_config.fft_period = val; 1256 return count; 1257 } 1258 1259 static const struct file_operations fops_spectral_fft_period = { 1260 .read = read_file_spectral_fft_period, 1261 .write = write_file_spectral_fft_period, 1262 .open = simple_open, 1263 .owner = THIS_MODULE, 1264 .llseek = default_llseek, 1265 }; 1266 1267 static struct dentry *create_buf_file_handler(const char *filename, 1268 struct dentry *parent, 1269 umode_t mode, 1270 struct rchan_buf *buf, 1271 int *is_global) 1272 { 1273 struct dentry *buf_file; 1274 1275 buf_file = debugfs_create_file(filename, mode, parent, buf, 1276 &relay_file_operations); 1277 *is_global = 1; 1278 return buf_file; 1279 } 1280 1281 static int remove_buf_file_handler(struct dentry *dentry) 1282 { 1283 debugfs_remove(dentry); 1284 1285 return 0; 1286 } 1287 1288 void ath_debug_send_fft_sample(struct ath_softc *sc, 1289 struct fft_sample_tlv *fft_sample_tlv) 1290 { 1291 int length; 1292 if (!sc->rfs_chan_spec_scan) 1293 return; 1294 1295 length = __be16_to_cpu(fft_sample_tlv->length) + 1296 sizeof(*fft_sample_tlv); 1297 relay_write(sc->rfs_chan_spec_scan, fft_sample_tlv, length); 1298 } 1299 1300 static struct rchan_callbacks rfs_spec_scan_cb = { 1301 .create_buf_file = create_buf_file_handler, 1302 .remove_buf_file = remove_buf_file_handler, 1303 }; 1304 1305 1306 static ssize_t read_file_regidx(struct file *file, char __user *user_buf, 1307 size_t count, loff_t *ppos) 1308 { 1309 struct ath_softc *sc = file->private_data; 1310 char buf[32]; 1311 unsigned int len; 1312 1313 len = sprintf(buf, "0x%08x\n", sc->debug.regidx); 1314 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 1315 } 1316 1317 static ssize_t write_file_regidx(struct file *file, const char __user *user_buf, 1318 size_t count, loff_t *ppos) 1319 { 1320 struct ath_softc *sc = file->private_data; 1321 unsigned long regidx; 1322 char buf[32]; 1323 ssize_t len; 1324 1325 len = min(count, sizeof(buf) - 1); 1326 if (copy_from_user(buf, user_buf, len)) 1327 return -EFAULT; 1328 1329 buf[len] = '\0'; 1330 if (kstrtoul(buf, 0, ®idx)) 1331 return -EINVAL; 1332 1333 sc->debug.regidx = regidx; 1334 return count; 1335 } 1336 1337 static const struct file_operations fops_regidx = { 1338 .read = read_file_regidx, 1339 .write = write_file_regidx, 1340 .open = simple_open, 1341 .owner = THIS_MODULE, 1342 .llseek = default_llseek, 1343 }; 1344 1345 static ssize_t read_file_regval(struct file *file, char __user *user_buf, 1346 size_t count, loff_t *ppos) 1347 { 1348 struct ath_softc *sc = file->private_data; 1349 struct ath_hw *ah = sc->sc_ah; 1350 char buf[32]; 1351 unsigned int len; 1352 u32 regval; 1353 1354 ath9k_ps_wakeup(sc); 1355 regval = REG_READ_D(ah, sc->debug.regidx); 1356 ath9k_ps_restore(sc); 1357 len = sprintf(buf, "0x%08x\n", regval); 1358 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 1359 } 1360 1361 static ssize_t write_file_regval(struct file *file, const char __user *user_buf, 1362 size_t count, loff_t *ppos) 1363 { 1364 struct ath_softc *sc = file->private_data; 1365 struct ath_hw *ah = sc->sc_ah; 1366 unsigned long regval; 1367 char buf[32]; 1368 ssize_t len; 1369 1370 len = min(count, sizeof(buf) - 1); 1371 if (copy_from_user(buf, user_buf, len)) 1372 return -EFAULT; 1373 1374 buf[len] = '\0'; 1375 if (kstrtoul(buf, 0, ®val)) 1376 return -EINVAL; 1377 1378 ath9k_ps_wakeup(sc); 1379 REG_WRITE_D(ah, sc->debug.regidx, regval); 1380 ath9k_ps_restore(sc); 1381 return count; 1382 } 1383 1384 static const struct file_operations fops_regval = { 1385 .read = read_file_regval, 1386 .write = write_file_regval, 1387 .open = simple_open, 1388 .owner = THIS_MODULE, 1389 .llseek = default_llseek, 1390 }; 1391 1392 #define REGDUMP_LINE_SIZE 20 1393 1394 static int open_file_regdump(struct inode *inode, struct file *file) 1395 { 1396 struct ath_softc *sc = inode->i_private; 1397 unsigned int len = 0; 1398 u8 *buf; 1399 int i; 1400 unsigned long num_regs, regdump_len, max_reg_offset; 1401 1402 max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500; 1403 num_regs = max_reg_offset / 4 + 1; 1404 regdump_len = num_regs * REGDUMP_LINE_SIZE + 1; 1405 buf = vmalloc(regdump_len); 1406 if (!buf) 1407 return -ENOMEM; 1408 1409 ath9k_ps_wakeup(sc); 1410 for (i = 0; i < num_regs; i++) 1411 len += scnprintf(buf + len, regdump_len - len, 1412 "0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2)); 1413 ath9k_ps_restore(sc); 1414 1415 file->private_data = buf; 1416 1417 return 0; 1418 } 1419 1420 static const struct file_operations fops_regdump = { 1421 .open = open_file_regdump, 1422 .read = ath9k_debugfs_read_buf, 1423 .release = ath9k_debugfs_release_buf, 1424 .owner = THIS_MODULE, 1425 .llseek = default_llseek,/* read accesses f_pos */ 1426 }; 1427 1428 static ssize_t read_file_dump_nfcal(struct file *file, char __user *user_buf, 1429 size_t count, loff_t *ppos) 1430 { 1431 struct ath_softc *sc = file->private_data; 1432 struct ath_hw *ah = sc->sc_ah; 1433 struct ath9k_nfcal_hist *h = sc->caldata.nfCalHist; 1434 struct ath_common *common = ath9k_hw_common(ah); 1435 struct ieee80211_conf *conf = &common->hw->conf; 1436 u32 len = 0, size = 1500; 1437 u32 i, j; 1438 ssize_t retval = 0; 1439 char *buf; 1440 u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask; 1441 u8 nread; 1442 1443 buf = kzalloc(size, GFP_KERNEL); 1444 if (!buf) 1445 return -ENOMEM; 1446 1447 len += scnprintf(buf + len, size - len, 1448 "Channel Noise Floor : %d\n", ah->noise); 1449 len += scnprintf(buf + len, size - len, 1450 "Chain | privNF | # Readings | NF Readings\n"); 1451 for (i = 0; i < NUM_NF_READINGS; i++) { 1452 if (!(chainmask & (1 << i)) || 1453 ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf))) 1454 continue; 1455 1456 nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount; 1457 len += scnprintf(buf + len, size - len, " %d\t %d\t %d\t\t", 1458 i, h[i].privNF, nread); 1459 for (j = 0; j < nread; j++) 1460 len += scnprintf(buf + len, size - len, 1461 " %d", h[i].nfCalBuffer[j]); 1462 len += scnprintf(buf + len, size - len, "\n"); 1463 } 1464 1465 if (len > size) 1466 len = size; 1467 1468 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 1469 kfree(buf); 1470 1471 return retval; 1472 } 1473 1474 static const struct file_operations fops_dump_nfcal = { 1475 .read = read_file_dump_nfcal, 1476 .open = simple_open, 1477 .owner = THIS_MODULE, 1478 .llseek = default_llseek, 1479 }; 1480 1481 static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf, 1482 size_t count, loff_t *ppos) 1483 { 1484 struct ath_softc *sc = file->private_data; 1485 struct ath_hw *ah = sc->sc_ah; 1486 u32 len = 0, size = 1500; 1487 ssize_t retval = 0; 1488 char *buf; 1489 1490 buf = kzalloc(size, GFP_KERNEL); 1491 if (!buf) 1492 return -ENOMEM; 1493 1494 len = ah->eep_ops->dump_eeprom(ah, true, buf, len, size); 1495 1496 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 1497 kfree(buf); 1498 1499 return retval; 1500 } 1501 1502 static const struct file_operations fops_base_eeprom = { 1503 .read = read_file_base_eeprom, 1504 .open = simple_open, 1505 .owner = THIS_MODULE, 1506 .llseek = default_llseek, 1507 }; 1508 1509 static ssize_t read_file_modal_eeprom(struct file *file, char __user *user_buf, 1510 size_t count, loff_t *ppos) 1511 { 1512 struct ath_softc *sc = file->private_data; 1513 struct ath_hw *ah = sc->sc_ah; 1514 u32 len = 0, size = 6000; 1515 char *buf; 1516 size_t retval; 1517 1518 buf = kzalloc(size, GFP_KERNEL); 1519 if (buf == NULL) 1520 return -ENOMEM; 1521 1522 len = ah->eep_ops->dump_eeprom(ah, false, buf, len, size); 1523 1524 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 1525 kfree(buf); 1526 1527 return retval; 1528 } 1529 1530 static const struct file_operations fops_modal_eeprom = { 1531 .read = read_file_modal_eeprom, 1532 .open = simple_open, 1533 .owner = THIS_MODULE, 1534 .llseek = default_llseek, 1535 }; 1536 1537 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT 1538 static ssize_t read_file_btcoex(struct file *file, char __user *user_buf, 1539 size_t count, loff_t *ppos) 1540 { 1541 struct ath_softc *sc = file->private_data; 1542 u32 len = 0, size = 1500; 1543 char *buf; 1544 size_t retval; 1545 1546 buf = kzalloc(size, GFP_KERNEL); 1547 if (buf == NULL) 1548 return -ENOMEM; 1549 1550 if (!sc->sc_ah->common.btcoex_enabled) { 1551 len = scnprintf(buf, size, "%s\n", 1552 "BTCOEX is disabled"); 1553 goto exit; 1554 } 1555 1556 len = ath9k_dump_btcoex(sc, buf, size); 1557 exit: 1558 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 1559 kfree(buf); 1560 1561 return retval; 1562 } 1563 1564 static const struct file_operations fops_btcoex = { 1565 .read = read_file_btcoex, 1566 .open = simple_open, 1567 .owner = THIS_MODULE, 1568 .llseek = default_llseek, 1569 }; 1570 #endif 1571 1572 static ssize_t read_file_node_stat(struct file *file, char __user *user_buf, 1573 size_t count, loff_t *ppos) 1574 { 1575 struct ath_node *an = file->private_data; 1576 struct ath_softc *sc = an->sc; 1577 struct ath_atx_tid *tid; 1578 struct ath_atx_ac *ac; 1579 struct ath_txq *txq; 1580 u32 len = 0, size = 4096; 1581 char *buf; 1582 size_t retval; 1583 int tidno, acno; 1584 1585 buf = kzalloc(size, GFP_KERNEL); 1586 if (buf == NULL) 1587 return -ENOMEM; 1588 1589 if (!an->sta->ht_cap.ht_supported) { 1590 len = scnprintf(buf, size, "%s\n", 1591 "HT not supported"); 1592 goto exit; 1593 } 1594 1595 len = scnprintf(buf, size, "Max-AMPDU: %d\n", 1596 an->maxampdu); 1597 len += scnprintf(buf + len, size - len, "MPDU Density: %d\n\n", 1598 an->mpdudensity); 1599 1600 len += scnprintf(buf + len, size - len, 1601 "%2s%7s\n", "AC", "SCHED"); 1602 1603 for (acno = 0, ac = &an->ac[acno]; 1604 acno < IEEE80211_NUM_ACS; acno++, ac++) { 1605 txq = ac->txq; 1606 ath_txq_lock(sc, txq); 1607 len += scnprintf(buf + len, size - len, 1608 "%2d%7d\n", 1609 acno, ac->sched); 1610 ath_txq_unlock(sc, txq); 1611 } 1612 1613 len += scnprintf(buf + len, size - len, 1614 "\n%3s%11s%10s%10s%10s%10s%9s%6s%8s\n", 1615 "TID", "SEQ_START", "SEQ_NEXT", "BAW_SIZE", 1616 "BAW_HEAD", "BAW_TAIL", "BAR_IDX", "SCHED", "PAUSED"); 1617 1618 for (tidno = 0, tid = &an->tid[tidno]; 1619 tidno < IEEE80211_NUM_TIDS; tidno++, tid++) { 1620 txq = tid->ac->txq; 1621 ath_txq_lock(sc, txq); 1622 len += scnprintf(buf + len, size - len, 1623 "%3d%11d%10d%10d%10d%10d%9d%6d%8d\n", 1624 tid->tidno, tid->seq_start, tid->seq_next, 1625 tid->baw_size, tid->baw_head, tid->baw_tail, 1626 tid->bar_index, tid->sched, tid->paused); 1627 ath_txq_unlock(sc, txq); 1628 } 1629 exit: 1630 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 1631 kfree(buf); 1632 1633 return retval; 1634 } 1635 1636 static const struct file_operations fops_node_stat = { 1637 .read = read_file_node_stat, 1638 .open = simple_open, 1639 .owner = THIS_MODULE, 1640 .llseek = default_llseek, 1641 }; 1642 1643 void ath9k_sta_add_debugfs(struct ieee80211_hw *hw, 1644 struct ieee80211_vif *vif, 1645 struct ieee80211_sta *sta, 1646 struct dentry *dir) 1647 { 1648 struct ath_node *an = (struct ath_node *)sta->drv_priv; 1649 debugfs_create_file("node_stat", S_IRUGO, dir, an, &fops_node_stat); 1650 } 1651 1652 /* Ethtool support for get-stats */ 1653 1654 #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO" 1655 static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = { 1656 "tx_pkts_nic", 1657 "tx_bytes_nic", 1658 "rx_pkts_nic", 1659 "rx_bytes_nic", 1660 AMKSTR(d_tx_pkts), 1661 AMKSTR(d_tx_bytes), 1662 AMKSTR(d_tx_mpdus_queued), 1663 AMKSTR(d_tx_mpdus_completed), 1664 AMKSTR(d_tx_mpdu_xretries), 1665 AMKSTR(d_tx_aggregates), 1666 AMKSTR(d_tx_ampdus_queued_hw), 1667 AMKSTR(d_tx_ampdus_queued_sw), 1668 AMKSTR(d_tx_ampdus_completed), 1669 AMKSTR(d_tx_ampdu_retries), 1670 AMKSTR(d_tx_ampdu_xretries), 1671 AMKSTR(d_tx_fifo_underrun), 1672 AMKSTR(d_tx_op_exceeded), 1673 AMKSTR(d_tx_timer_expiry), 1674 AMKSTR(d_tx_desc_cfg_err), 1675 AMKSTR(d_tx_data_underrun), 1676 AMKSTR(d_tx_delim_underrun), 1677 "d_rx_crc_err", 1678 "d_rx_decrypt_crc_err", 1679 "d_rx_phy_err", 1680 "d_rx_mic_err", 1681 "d_rx_pre_delim_crc_err", 1682 "d_rx_post_delim_crc_err", 1683 "d_rx_decrypt_busy_err", 1684 1685 "d_rx_phyerr_radar", 1686 "d_rx_phyerr_ofdm_timing", 1687 "d_rx_phyerr_cck_timing", 1688 1689 }; 1690 #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats) 1691 1692 void ath9k_get_et_strings(struct ieee80211_hw *hw, 1693 struct ieee80211_vif *vif, 1694 u32 sset, u8 *data) 1695 { 1696 if (sset == ETH_SS_STATS) 1697 memcpy(data, *ath9k_gstrings_stats, 1698 sizeof(ath9k_gstrings_stats)); 1699 } 1700 1701 int ath9k_get_et_sset_count(struct ieee80211_hw *hw, 1702 struct ieee80211_vif *vif, int sset) 1703 { 1704 if (sset == ETH_SS_STATS) 1705 return ATH9K_SSTATS_LEN; 1706 return 0; 1707 } 1708 1709 #define AWDATA(elem) \ 1710 do { \ 1711 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \ 1712 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \ 1713 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \ 1714 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \ 1715 } while (0) 1716 1717 #define AWDATA_RX(elem) \ 1718 do { \ 1719 data[i++] = sc->debug.stats.rxstats.elem; \ 1720 } while (0) 1721 1722 void ath9k_get_et_stats(struct ieee80211_hw *hw, 1723 struct ieee80211_vif *vif, 1724 struct ethtool_stats *stats, u64 *data) 1725 { 1726 struct ath_softc *sc = hw->priv; 1727 int i = 0; 1728 1729 data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all + 1730 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all + 1731 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all + 1732 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all); 1733 data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all + 1734 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all + 1735 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all + 1736 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all); 1737 AWDATA_RX(rx_pkts_all); 1738 AWDATA_RX(rx_bytes_all); 1739 1740 AWDATA(tx_pkts_all); 1741 AWDATA(tx_bytes_all); 1742 AWDATA(queued); 1743 AWDATA(completed); 1744 AWDATA(xretries); 1745 AWDATA(a_aggr); 1746 AWDATA(a_queued_hw); 1747 AWDATA(a_queued_sw); 1748 AWDATA(a_completed); 1749 AWDATA(a_retries); 1750 AWDATA(a_xretries); 1751 AWDATA(fifo_underrun); 1752 AWDATA(xtxop); 1753 AWDATA(timer_exp); 1754 AWDATA(desc_cfg_err); 1755 AWDATA(data_underrun); 1756 AWDATA(delim_underrun); 1757 1758 AWDATA_RX(crc_err); 1759 AWDATA_RX(decrypt_crc_err); 1760 AWDATA_RX(phy_err); 1761 AWDATA_RX(mic_err); 1762 AWDATA_RX(pre_delim_crc_err); 1763 AWDATA_RX(post_delim_crc_err); 1764 AWDATA_RX(decrypt_busy_err); 1765 1766 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]); 1767 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]); 1768 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]); 1769 1770 WARN_ON(i != ATH9K_SSTATS_LEN); 1771 } 1772 1773 void ath9k_deinit_debug(struct ath_softc *sc) 1774 { 1775 if (config_enabled(CONFIG_ATH9K_DEBUGFS) && sc->rfs_chan_spec_scan) { 1776 relay_close(sc->rfs_chan_spec_scan); 1777 sc->rfs_chan_spec_scan = NULL; 1778 } 1779 } 1780 1781 static ssize_t read_file_tx99(struct file *file, char __user *user_buf, 1782 size_t count, loff_t *ppos) 1783 { 1784 struct ath_softc *sc = file->private_data; 1785 char buf[3]; 1786 unsigned int len; 1787 1788 len = sprintf(buf, "%d\n", sc->tx99_state); 1789 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 1790 } 1791 1792 static ssize_t write_file_tx99(struct file *file, const char __user *user_buf, 1793 size_t count, loff_t *ppos) 1794 { 1795 struct ath_softc *sc = file->private_data; 1796 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 1797 char buf[32]; 1798 bool start; 1799 ssize_t len; 1800 int r; 1801 1802 if (sc->nvifs > 1) 1803 return -EOPNOTSUPP; 1804 1805 len = min(count, sizeof(buf) - 1); 1806 if (copy_from_user(buf, user_buf, len)) 1807 return -EFAULT; 1808 1809 if (strtobool(buf, &start)) 1810 return -EINVAL; 1811 1812 if (start == sc->tx99_state) { 1813 if (!start) 1814 return count; 1815 ath_dbg(common, XMIT, "Resetting TX99\n"); 1816 ath9k_tx99_deinit(sc); 1817 } 1818 1819 if (!start) { 1820 ath9k_tx99_deinit(sc); 1821 return count; 1822 } 1823 1824 r = ath9k_tx99_init(sc); 1825 if (r) 1826 return r; 1827 1828 return count; 1829 } 1830 1831 static const struct file_operations fops_tx99 = { 1832 .read = read_file_tx99, 1833 .write = write_file_tx99, 1834 .open = simple_open, 1835 .owner = THIS_MODULE, 1836 .llseek = default_llseek, 1837 }; 1838 1839 static ssize_t read_file_tx99_power(struct file *file, 1840 char __user *user_buf, 1841 size_t count, loff_t *ppos) 1842 { 1843 struct ath_softc *sc = file->private_data; 1844 char buf[32]; 1845 unsigned int len; 1846 1847 len = sprintf(buf, "%d (%d dBm)\n", 1848 sc->tx99_power, 1849 sc->tx99_power / 2); 1850 1851 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 1852 } 1853 1854 static ssize_t write_file_tx99_power(struct file *file, 1855 const char __user *user_buf, 1856 size_t count, loff_t *ppos) 1857 { 1858 struct ath_softc *sc = file->private_data; 1859 int r; 1860 u8 tx_power; 1861 1862 r = kstrtou8_from_user(user_buf, count, 0, &tx_power); 1863 if (r) 1864 return r; 1865 1866 if (tx_power > MAX_RATE_POWER) 1867 return -EINVAL; 1868 1869 sc->tx99_power = tx_power; 1870 1871 ath9k_ps_wakeup(sc); 1872 ath9k_hw_tx99_set_txpower(sc->sc_ah, sc->tx99_power); 1873 ath9k_ps_restore(sc); 1874 1875 return count; 1876 } 1877 1878 static const struct file_operations fops_tx99_power = { 1879 .read = read_file_tx99_power, 1880 .write = write_file_tx99_power, 1881 .open = simple_open, 1882 .owner = THIS_MODULE, 1883 .llseek = default_llseek, 1884 }; 1885 1886 int ath9k_init_debug(struct ath_hw *ah) 1887 { 1888 struct ath_common *common = ath9k_hw_common(ah); 1889 struct ath_softc *sc = (struct ath_softc *) common->priv; 1890 1891 sc->debug.debugfs_phy = debugfs_create_dir("ath9k", 1892 sc->hw->wiphy->debugfsdir); 1893 if (!sc->debug.debugfs_phy) 1894 return -ENOMEM; 1895 1896 #ifdef CONFIG_ATH_DEBUG 1897 debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, 1898 sc, &fops_debug); 1899 #endif 1900 1901 ath9k_dfs_init_debug(sc); 1902 1903 debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc, 1904 &fops_dma); 1905 debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc, 1906 &fops_interrupt); 1907 debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc, 1908 &fops_xmit); 1909 debugfs_create_file("queues", S_IRUSR, sc->debug.debugfs_phy, sc, 1910 &fops_queues); 1911 debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, 1912 &sc->tx.txq_max_pending[IEEE80211_AC_BK]); 1913 debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, 1914 &sc->tx.txq_max_pending[IEEE80211_AC_BE]); 1915 debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, 1916 &sc->tx.txq_max_pending[IEEE80211_AC_VI]); 1917 debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, 1918 &sc->tx.txq_max_pending[IEEE80211_AC_VO]); 1919 debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy, sc, 1920 &fops_misc); 1921 debugfs_create_file("reset", S_IRUSR, sc->debug.debugfs_phy, sc, 1922 &fops_reset); 1923 debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy, sc, 1924 &fops_recv); 1925 debugfs_create_u8("rx_chainmask", S_IRUSR, sc->debug.debugfs_phy, 1926 &ah->rxchainmask); 1927 debugfs_create_u8("tx_chainmask", S_IRUSR, sc->debug.debugfs_phy, 1928 &ah->txchainmask); 1929 debugfs_create_file("ani", S_IRUSR | S_IWUSR, 1930 sc->debug.debugfs_phy, sc, &fops_ani); 1931 debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, 1932 &sc->sc_ah->config.enable_paprd); 1933 debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, 1934 sc, &fops_regidx); 1935 debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, 1936 sc, &fops_regval); 1937 debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR, 1938 sc->debug.debugfs_phy, 1939 &ah->config.cwm_ignore_extcca); 1940 debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc, 1941 &fops_regdump); 1942 debugfs_create_file("dump_nfcal", S_IRUSR, sc->debug.debugfs_phy, sc, 1943 &fops_dump_nfcal); 1944 debugfs_create_file("base_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc, 1945 &fops_base_eeprom); 1946 debugfs_create_file("modal_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc, 1947 &fops_modal_eeprom); 1948 sc->rfs_chan_spec_scan = relay_open("spectral_scan", 1949 sc->debug.debugfs_phy, 1950 1024, 256, &rfs_spec_scan_cb, 1951 NULL); 1952 debugfs_create_file("spectral_scan_ctl", S_IRUSR | S_IWUSR, 1953 sc->debug.debugfs_phy, sc, 1954 &fops_spec_scan_ctl); 1955 debugfs_create_file("spectral_short_repeat", S_IRUSR | S_IWUSR, 1956 sc->debug.debugfs_phy, sc, 1957 &fops_spectral_short_repeat); 1958 debugfs_create_file("spectral_count", S_IRUSR | S_IWUSR, 1959 sc->debug.debugfs_phy, sc, &fops_spectral_count); 1960 debugfs_create_file("spectral_period", S_IRUSR | S_IWUSR, 1961 sc->debug.debugfs_phy, sc, &fops_spectral_period); 1962 debugfs_create_file("spectral_fft_period", S_IRUSR | S_IWUSR, 1963 sc->debug.debugfs_phy, sc, 1964 &fops_spectral_fft_period); 1965 debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR, 1966 sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask); 1967 debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR, 1968 sc->debug.debugfs_phy, &sc->sc_ah->gpio_val); 1969 debugfs_create_file("antenna_diversity", S_IRUSR, 1970 sc->debug.debugfs_phy, sc, &fops_antenna_diversity); 1971 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT 1972 debugfs_create_file("bt_ant_diversity", S_IRUSR | S_IWUSR, 1973 sc->debug.debugfs_phy, sc, &fops_bt_ant_diversity); 1974 debugfs_create_file("btcoex", S_IRUSR, sc->debug.debugfs_phy, sc, 1975 &fops_btcoex); 1976 #endif 1977 if (config_enabled(CONFIG_ATH9K_TX99) && 1978 AR_SREV_9300_20_OR_LATER(ah)) { 1979 debugfs_create_file("tx99", S_IRUSR | S_IWUSR, 1980 sc->debug.debugfs_phy, sc, 1981 &fops_tx99); 1982 debugfs_create_file("tx99_power", S_IRUSR | S_IWUSR, 1983 sc->debug.debugfs_phy, sc, 1984 &fops_tx99_power); 1985 } 1986 1987 return 0; 1988 } 1989