0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include <linux/slab.h>
0018 #include <linux/vmalloc.h>
0019 #include <linux/export.h>
0020 #include <asm/unaligned.h>
0021
0022 #include "ath9k.h"
0023
0024 #define REG_WRITE_D(_ah, _reg, _val) \
0025 ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg))
0026 #define REG_READ_D(_ah, _reg) \
0027 ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
0028
0029 void ath9k_debug_sync_cause(struct ath_softc *sc, u32 sync_cause)
0030 {
0031 if (sync_cause)
0032 sc->debug.stats.istats.sync_cause_all++;
0033 if (sync_cause & AR_INTR_SYNC_RTC_IRQ)
0034 sc->debug.stats.istats.sync_rtc_irq++;
0035 if (sync_cause & AR_INTR_SYNC_MAC_IRQ)
0036 sc->debug.stats.istats.sync_mac_irq++;
0037 if (sync_cause & AR_INTR_SYNC_EEPROM_ILLEGAL_ACCESS)
0038 sc->debug.stats.istats.eeprom_illegal_access++;
0039 if (sync_cause & AR_INTR_SYNC_APB_TIMEOUT)
0040 sc->debug.stats.istats.apb_timeout++;
0041 if (sync_cause & AR_INTR_SYNC_PCI_MODE_CONFLICT)
0042 sc->debug.stats.istats.pci_mode_conflict++;
0043 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL)
0044 sc->debug.stats.istats.host1_fatal++;
0045 if (sync_cause & AR_INTR_SYNC_HOST1_PERR)
0046 sc->debug.stats.istats.host1_perr++;
0047 if (sync_cause & AR_INTR_SYNC_TRCV_FIFO_PERR)
0048 sc->debug.stats.istats.trcv_fifo_perr++;
0049 if (sync_cause & AR_INTR_SYNC_RADM_CPL_EP)
0050 sc->debug.stats.istats.radm_cpl_ep++;
0051 if (sync_cause & AR_INTR_SYNC_RADM_CPL_DLLP_ABORT)
0052 sc->debug.stats.istats.radm_cpl_dllp_abort++;
0053 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TLP_ABORT)
0054 sc->debug.stats.istats.radm_cpl_tlp_abort++;
0055 if (sync_cause & AR_INTR_SYNC_RADM_CPL_ECRC_ERR)
0056 sc->debug.stats.istats.radm_cpl_ecrc_err++;
0057 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT)
0058 sc->debug.stats.istats.radm_cpl_timeout++;
0059 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT)
0060 sc->debug.stats.istats.local_timeout++;
0061 if (sync_cause & AR_INTR_SYNC_PM_ACCESS)
0062 sc->debug.stats.istats.pm_access++;
0063 if (sync_cause & AR_INTR_SYNC_MAC_AWAKE)
0064 sc->debug.stats.istats.mac_awake++;
0065 if (sync_cause & AR_INTR_SYNC_MAC_ASLEEP)
0066 sc->debug.stats.istats.mac_asleep++;
0067 if (sync_cause & AR_INTR_SYNC_MAC_SLEEP_ACCESS)
0068 sc->debug.stats.istats.mac_sleep_access++;
0069 }
0070
0071 static ssize_t ath9k_debugfs_read_buf(struct file *file, char __user *user_buf,
0072 size_t count, loff_t *ppos)
0073 {
0074 u8 *buf = file->private_data;
0075 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
0076 }
0077
0078 static int ath9k_debugfs_release_buf(struct inode *inode, struct file *file)
0079 {
0080 vfree(file->private_data);
0081 return 0;
0082 }
0083
0084 #ifdef CONFIG_ATH_DEBUG
0085
0086 static ssize_t read_file_debug(struct file *file, char __user *user_buf,
0087 size_t count, loff_t *ppos)
0088 {
0089 struct ath_softc *sc = file->private_data;
0090 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
0091 char buf[32];
0092 unsigned int len;
0093
0094 len = sprintf(buf, "0x%08x\n", common->debug_mask);
0095 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
0096 }
0097
0098 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
0099 size_t count, loff_t *ppos)
0100 {
0101 struct ath_softc *sc = file->private_data;
0102 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
0103 unsigned long mask;
0104 char buf[32];
0105 ssize_t len;
0106
0107 len = min(count, sizeof(buf) - 1);
0108 if (copy_from_user(buf, user_buf, len))
0109 return -EFAULT;
0110
0111 buf[len] = '\0';
0112 if (kstrtoul(buf, 0, &mask))
0113 return -EINVAL;
0114
0115 common->debug_mask = mask;
0116 return count;
0117 }
0118
0119 static const struct file_operations fops_debug = {
0120 .read = read_file_debug,
0121 .write = write_file_debug,
0122 .open = simple_open,
0123 .owner = THIS_MODULE,
0124 .llseek = default_llseek,
0125 };
0126
0127 #endif
0128
0129 #define DMA_BUF_LEN 1024
0130
0131
0132 static ssize_t read_file_ani(struct file *file, char __user *user_buf,
0133 size_t count, loff_t *ppos)
0134 {
0135 struct ath_softc *sc = file->private_data;
0136 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
0137 struct ath_hw *ah = sc->sc_ah;
0138 unsigned int len = 0;
0139 const unsigned int size = 1024;
0140 ssize_t retval = 0;
0141 char *buf;
0142 int i;
0143 struct {
0144 const char *name;
0145 unsigned int val;
0146 } ani_info[] = {
0147 { "ANI RESET", ah->stats.ast_ani_reset },
0148 { "OFDM LEVEL", ah->ani.ofdmNoiseImmunityLevel },
0149 { "CCK LEVEL", ah->ani.cckNoiseImmunityLevel },
0150 { "SPUR UP", ah->stats.ast_ani_spurup },
0151 { "SPUR DOWN", ah->stats.ast_ani_spurdown },
0152 { "OFDM WS-DET ON", ah->stats.ast_ani_ofdmon },
0153 { "OFDM WS-DET OFF", ah->stats.ast_ani_ofdmoff },
0154 { "MRC-CCK ON", ah->stats.ast_ani_ccklow },
0155 { "MRC-CCK OFF", ah->stats.ast_ani_cckhigh },
0156 { "FIR-STEP UP", ah->stats.ast_ani_stepup },
0157 { "FIR-STEP DOWN", ah->stats.ast_ani_stepdown },
0158 { "INV LISTENTIME", ah->stats.ast_ani_lneg_or_lzero },
0159 { "OFDM ERRORS", ah->stats.ast_ani_ofdmerrs },
0160 { "CCK ERRORS", ah->stats.ast_ani_cckerrs },
0161 };
0162
0163 buf = kzalloc(size, GFP_KERNEL);
0164 if (buf == NULL)
0165 return -ENOMEM;
0166
0167 len += scnprintf(buf + len, size - len, "%15s: %s\n", "ANI",
0168 common->disable_ani ? "DISABLED" : "ENABLED");
0169
0170 if (common->disable_ani)
0171 goto exit;
0172
0173 for (i = 0; i < ARRAY_SIZE(ani_info); i++)
0174 len += scnprintf(buf + len, size - len, "%15s: %u\n",
0175 ani_info[i].name, ani_info[i].val);
0176
0177 exit:
0178 if (len > size)
0179 len = size;
0180
0181 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
0182 kfree(buf);
0183
0184 return retval;
0185 }
0186
0187 static ssize_t write_file_ani(struct file *file,
0188 const char __user *user_buf,
0189 size_t count, loff_t *ppos)
0190 {
0191 struct ath_softc *sc = file->private_data;
0192 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
0193 unsigned long ani;
0194 char buf[32];
0195 ssize_t len;
0196
0197 len = min(count, sizeof(buf) - 1);
0198 if (copy_from_user(buf, user_buf, len))
0199 return -EFAULT;
0200
0201 buf[len] = '\0';
0202 if (kstrtoul(buf, 0, &ani))
0203 return -EINVAL;
0204
0205 if (ani > 1)
0206 return -EINVAL;
0207
0208 common->disable_ani = !ani;
0209
0210 if (common->disable_ani) {
0211 clear_bit(ATH_OP_ANI_RUN, &common->op_flags);
0212 ath_stop_ani(sc);
0213 } else {
0214 ath_check_ani(sc);
0215 }
0216
0217 return count;
0218 }
0219
0220 static const struct file_operations fops_ani = {
0221 .read = read_file_ani,
0222 .write = write_file_ani,
0223 .open = simple_open,
0224 .owner = THIS_MODULE,
0225 .llseek = default_llseek,
0226 };
0227
0228 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
0229
0230 static ssize_t read_file_bt_ant_diversity(struct file *file,
0231 char __user *user_buf,
0232 size_t count, loff_t *ppos)
0233 {
0234 struct ath_softc *sc = file->private_data;
0235 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
0236 char buf[32];
0237 unsigned int len;
0238
0239 len = sprintf(buf, "%d\n", common->bt_ant_diversity);
0240 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
0241 }
0242
0243 static ssize_t write_file_bt_ant_diversity(struct file *file,
0244 const char __user *user_buf,
0245 size_t count, loff_t *ppos)
0246 {
0247 struct ath_softc *sc = file->private_data;
0248 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
0249 struct ath9k_hw_capabilities *pCap = &sc->sc_ah->caps;
0250 unsigned long bt_ant_diversity;
0251 char buf[32];
0252 ssize_t len;
0253
0254 len = min(count, sizeof(buf) - 1);
0255 if (copy_from_user(buf, user_buf, len))
0256 return -EFAULT;
0257
0258 if (!(pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
0259 goto exit;
0260
0261 buf[len] = '\0';
0262 if (kstrtoul(buf, 0, &bt_ant_diversity))
0263 return -EINVAL;
0264
0265 common->bt_ant_diversity = !!bt_ant_diversity;
0266 ath9k_ps_wakeup(sc);
0267 ath9k_hw_set_bt_ant_diversity(sc->sc_ah, common->bt_ant_diversity);
0268 ath_dbg(common, CONFIG, "Enable WLAN/BT RX Antenna diversity: %d\n",
0269 common->bt_ant_diversity);
0270 ath9k_ps_restore(sc);
0271 exit:
0272 return count;
0273 }
0274
0275 static const struct file_operations fops_bt_ant_diversity = {
0276 .read = read_file_bt_ant_diversity,
0277 .write = write_file_bt_ant_diversity,
0278 .open = simple_open,
0279 .owner = THIS_MODULE,
0280 .llseek = default_llseek,
0281 };
0282
0283 #endif
0284
0285 void ath9k_debug_stat_ant(struct ath_softc *sc,
0286 struct ath_hw_antcomb_conf *div_ant_conf,
0287 int main_rssi_avg, int alt_rssi_avg)
0288 {
0289 struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
0290 struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
0291
0292 as_main->lna_attempt_cnt[div_ant_conf->main_lna_conf]++;
0293 as_alt->lna_attempt_cnt[div_ant_conf->alt_lna_conf]++;
0294
0295 as_main->rssi_avg = main_rssi_avg;
0296 as_alt->rssi_avg = alt_rssi_avg;
0297 }
0298
0299 static ssize_t read_file_antenna_diversity(struct file *file,
0300 char __user *user_buf,
0301 size_t count, loff_t *ppos)
0302 {
0303 struct ath_softc *sc = file->private_data;
0304 struct ath_hw *ah = sc->sc_ah;
0305 struct ath9k_hw_capabilities *pCap = &ah->caps;
0306 struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
0307 struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
0308 struct ath_hw_antcomb_conf div_ant_conf;
0309 unsigned int len = 0;
0310 const unsigned int size = 1024;
0311 ssize_t retval = 0;
0312 char *buf;
0313 static const char *lna_conf_str[4] = {
0314 "LNA1_MINUS_LNA2", "LNA2", "LNA1", "LNA1_PLUS_LNA2"
0315 };
0316
0317 buf = kzalloc(size, GFP_KERNEL);
0318 if (buf == NULL)
0319 return -ENOMEM;
0320
0321 if (!(pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)) {
0322 len += scnprintf(buf + len, size - len, "%s\n",
0323 "Antenna Diversity Combining is disabled");
0324 goto exit;
0325 }
0326
0327 ath9k_ps_wakeup(sc);
0328 ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
0329 len += scnprintf(buf + len, size - len, "Current MAIN config : %s\n",
0330 lna_conf_str[div_ant_conf.main_lna_conf]);
0331 len += scnprintf(buf + len, size - len, "Current ALT config : %s\n",
0332 lna_conf_str[div_ant_conf.alt_lna_conf]);
0333 len += scnprintf(buf + len, size - len, "Average MAIN RSSI : %d\n",
0334 as_main->rssi_avg);
0335 len += scnprintf(buf + len, size - len, "Average ALT RSSI : %d\n\n",
0336 as_alt->rssi_avg);
0337 ath9k_ps_restore(sc);
0338
0339 len += scnprintf(buf + len, size - len, "Packet Receive Cnt:\n");
0340 len += scnprintf(buf + len, size - len, "-------------------\n");
0341
0342 len += scnprintf(buf + len, size - len, "%30s%15s\n",
0343 "MAIN", "ALT");
0344 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
0345 "TOTAL COUNT",
0346 as_main->recv_cnt,
0347 as_alt->recv_cnt);
0348 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
0349 "LNA1",
0350 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1],
0351 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1]);
0352 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
0353 "LNA2",
0354 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2],
0355 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2]);
0356 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
0357 "LNA1 + LNA2",
0358 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
0359 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
0360 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
0361 "LNA1 - LNA2",
0362 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
0363 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
0364
0365 len += scnprintf(buf + len, size - len, "\nLNA Config Attempts:\n");
0366 len += scnprintf(buf + len, size - len, "--------------------\n");
0367
0368 len += scnprintf(buf + len, size - len, "%30s%15s\n",
0369 "MAIN", "ALT");
0370 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
0371 "LNA1",
0372 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1],
0373 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1]);
0374 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
0375 "LNA2",
0376 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2],
0377 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2]);
0378 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
0379 "LNA1 + LNA2",
0380 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
0381 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
0382 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
0383 "LNA1 - LNA2",
0384 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
0385 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
0386
0387 exit:
0388 if (len > size)
0389 len = size;
0390
0391 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
0392 kfree(buf);
0393
0394 return retval;
0395 }
0396
0397 static const struct file_operations fops_antenna_diversity = {
0398 .read = read_file_antenna_diversity,
0399 .open = simple_open,
0400 .owner = THIS_MODULE,
0401 .llseek = default_llseek,
0402 };
0403
0404 static int read_file_dma(struct seq_file *file, void *data)
0405 {
0406 struct ieee80211_hw *hw = dev_get_drvdata(file->private);
0407 struct ath_softc *sc = hw->priv;
0408 struct ath_hw *ah = sc->sc_ah;
0409 u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
0410 int i, qcuOffset = 0, dcuOffset = 0;
0411 u32 *qcuBase = &val[0], *dcuBase = &val[4];
0412
0413 ath9k_ps_wakeup(sc);
0414
0415 REG_WRITE_D(ah, AR_MACMISC,
0416 ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
0417 (AR_MACMISC_MISC_OBS_BUS_1 <<
0418 AR_MACMISC_MISC_OBS_BUS_MSB_S)));
0419
0420 seq_puts(file, "Raw DMA Debug values:\n");
0421
0422 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
0423 if (i % 4 == 0)
0424 seq_puts(file, "\n");
0425
0426 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
0427 seq_printf(file, "%d: %08x ", i, val[i]);
0428 }
0429
0430 seq_puts(file, "\n\n");
0431 seq_puts(file, "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
0432
0433 for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
0434 if (i == 8) {
0435 qcuOffset = 0;
0436 qcuBase++;
0437 }
0438
0439 if (i == 6) {
0440 dcuOffset = 0;
0441 dcuBase++;
0442 }
0443
0444 seq_printf(file, "%2d %2x %1x %2x %2x\n",
0445 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
0446 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
0447 (val[2] & (0x7 << (i * 3))) >> (i * 3),
0448 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
0449 }
0450
0451 seq_puts(file, "\n");
0452
0453 seq_printf(file, "qcu_stitch state: %2x qcu_fetch state: %2x\n",
0454 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
0455 seq_printf(file, "qcu_complete state: %2x dcu_complete state: %2x\n",
0456 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
0457 seq_printf(file, "dcu_arb state: %2x dcu_fp state: %2x\n",
0458 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
0459 seq_printf(file, "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
0460 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
0461 seq_printf(file, "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
0462 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
0463 seq_printf(file, "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
0464 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
0465
0466 seq_printf(file, "pcu observe: 0x%x\n", REG_READ_D(ah, AR_OBS_BUS_1));
0467 seq_printf(file, "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
0468
0469 ath9k_ps_restore(sc);
0470
0471 return 0;
0472 }
0473
0474 void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
0475 {
0476 if (status)
0477 sc->debug.stats.istats.total++;
0478 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
0479 if (status & ATH9K_INT_RXLP)
0480 sc->debug.stats.istats.rxlp++;
0481 if (status & ATH9K_INT_RXHP)
0482 sc->debug.stats.istats.rxhp++;
0483 if (status & ATH9K_INT_BB_WATCHDOG)
0484 sc->debug.stats.istats.bb_watchdog++;
0485 } else {
0486 if (status & ATH9K_INT_RX)
0487 sc->debug.stats.istats.rxok++;
0488 }
0489 if (status & ATH9K_INT_RXEOL)
0490 sc->debug.stats.istats.rxeol++;
0491 if (status & ATH9K_INT_RXORN)
0492 sc->debug.stats.istats.rxorn++;
0493 if (status & ATH9K_INT_TX)
0494 sc->debug.stats.istats.txok++;
0495 if (status & ATH9K_INT_TXURN)
0496 sc->debug.stats.istats.txurn++;
0497 if (status & ATH9K_INT_RXPHY)
0498 sc->debug.stats.istats.rxphyerr++;
0499 if (status & ATH9K_INT_RXKCM)
0500 sc->debug.stats.istats.rx_keycache_miss++;
0501 if (status & ATH9K_INT_SWBA)
0502 sc->debug.stats.istats.swba++;
0503 if (status & ATH9K_INT_BMISS)
0504 sc->debug.stats.istats.bmiss++;
0505 if (status & ATH9K_INT_BNR)
0506 sc->debug.stats.istats.bnr++;
0507 if (status & ATH9K_INT_CST)
0508 sc->debug.stats.istats.cst++;
0509 if (status & ATH9K_INT_GTT)
0510 sc->debug.stats.istats.gtt++;
0511 if (status & ATH9K_INT_TIM)
0512 sc->debug.stats.istats.tim++;
0513 if (status & ATH9K_INT_CABEND)
0514 sc->debug.stats.istats.cabend++;
0515 if (status & ATH9K_INT_DTIMSYNC)
0516 sc->debug.stats.istats.dtimsync++;
0517 if (status & ATH9K_INT_DTIM)
0518 sc->debug.stats.istats.dtim++;
0519 if (status & ATH9K_INT_TSFOOR)
0520 sc->debug.stats.istats.tsfoor++;
0521 if (status & ATH9K_INT_MCI)
0522 sc->debug.stats.istats.mci++;
0523 if (status & ATH9K_INT_GENTIMER)
0524 sc->debug.stats.istats.gen_timer++;
0525 }
0526
0527 static int read_file_interrupt(struct seq_file *file, void *data)
0528 {
0529 struct ieee80211_hw *hw = dev_get_drvdata(file->private);
0530 struct ath_softc *sc = hw->priv;
0531
0532 #define PR_IS(a, s) \
0533 do { \
0534 seq_printf(file, "%21s: %10u\n", a, \
0535 sc->debug.stats.istats.s); \
0536 } while (0)
0537
0538 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
0539 PR_IS("RXLP", rxlp);
0540 PR_IS("RXHP", rxhp);
0541 PR_IS("WATCHDOG", bb_watchdog);
0542 } else {
0543 PR_IS("RX", rxok);
0544 }
0545 PR_IS("RXEOL", rxeol);
0546 PR_IS("RXORN", rxorn);
0547 PR_IS("TX", txok);
0548 PR_IS("TXURN", txurn);
0549 PR_IS("MIB", mib);
0550 PR_IS("RXPHY", rxphyerr);
0551 PR_IS("RXKCM", rx_keycache_miss);
0552 PR_IS("SWBA", swba);
0553 PR_IS("BMISS", bmiss);
0554 PR_IS("BNR", bnr);
0555 PR_IS("CST", cst);
0556 PR_IS("GTT", gtt);
0557 PR_IS("TIM", tim);
0558 PR_IS("CABEND", cabend);
0559 PR_IS("DTIMSYNC", dtimsync);
0560 PR_IS("DTIM", dtim);
0561 PR_IS("TSFOOR", tsfoor);
0562 PR_IS("MCI", mci);
0563 PR_IS("GENTIMER", gen_timer);
0564 PR_IS("TOTAL", total);
0565
0566 seq_puts(file, "SYNC_CAUSE stats:\n");
0567
0568 PR_IS("Sync-All", sync_cause_all);
0569 PR_IS("RTC-IRQ", sync_rtc_irq);
0570 PR_IS("MAC-IRQ", sync_mac_irq);
0571 PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
0572 PR_IS("APB-Timeout", apb_timeout);
0573 PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
0574 PR_IS("HOST1-Fatal", host1_fatal);
0575 PR_IS("HOST1-Perr", host1_perr);
0576 PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
0577 PR_IS("RADM-CPL-EP", radm_cpl_ep);
0578 PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
0579 PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
0580 PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
0581 PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
0582 PR_IS("Local-Bus-Timeout", local_timeout);
0583 PR_IS("PM-Access", pm_access);
0584 PR_IS("MAC-Awake", mac_awake);
0585 PR_IS("MAC-Asleep", mac_asleep);
0586 PR_IS("MAC-Sleep-Access", mac_sleep_access);
0587
0588 return 0;
0589 }
0590
0591 static int read_file_xmit(struct seq_file *file, void *data)
0592 {
0593 struct ieee80211_hw *hw = dev_get_drvdata(file->private);
0594 struct ath_softc *sc = hw->priv;
0595
0596 seq_printf(file, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
0597
0598 PR("MPDUs Queued: ", queued);
0599 PR("MPDUs Completed: ", completed);
0600 PR("MPDUs XRetried: ", xretries);
0601 PR("Aggregates: ", a_aggr);
0602 PR("AMPDUs Queued HW:", a_queued_hw);
0603 PR("AMPDUs Completed:", a_completed);
0604 PR("AMPDUs Retried: ", a_retries);
0605 PR("AMPDUs XRetried: ", a_xretries);
0606 PR("TXERR Filtered: ", txerr_filtered);
0607 PR("FIFO Underrun: ", fifo_underrun);
0608 PR("TXOP Exceeded: ", xtxop);
0609 PR("TXTIMER Expiry: ", timer_exp);
0610 PR("DESC CFG Error: ", desc_cfg_err);
0611 PR("DATA Underrun: ", data_underrun);
0612 PR("DELIM Underrun: ", delim_underrun);
0613 PR("TX-Pkts-All: ", tx_pkts_all);
0614 PR("TX-Bytes-All: ", tx_bytes_all);
0615 PR("HW-put-tx-buf: ", puttxbuf);
0616 PR("HW-tx-start: ", txstart);
0617 PR("HW-tx-proc-desc: ", txprocdesc);
0618 PR("TX-Failed: ", txfailed);
0619
0620 return 0;
0621 }
0622
0623 static void print_queue(struct ath_softc *sc, struct ath_txq *txq,
0624 struct seq_file *file)
0625 {
0626 ath_txq_lock(sc, txq);
0627
0628 seq_printf(file, "%s: %d ", "qnum", txq->axq_qnum);
0629 seq_printf(file, "%s: %2d ", "qdepth", txq->axq_depth);
0630 seq_printf(file, "%s: %2d ", "ampdu-depth", txq->axq_ampdu_depth);
0631 seq_printf(file, "%s: %3d\n", "pending", txq->pending_frames);
0632
0633 ath_txq_unlock(sc, txq);
0634 }
0635
0636 static int read_file_queues(struct seq_file *file, void *data)
0637 {
0638 struct ieee80211_hw *hw = dev_get_drvdata(file->private);
0639 struct ath_softc *sc = hw->priv;
0640 struct ath_txq *txq;
0641 int i;
0642 static const char *qname[4] = {
0643 "VO", "VI", "BE", "BK"
0644 };
0645
0646 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
0647 txq = sc->tx.txq_map[i];
0648 seq_printf(file, "(%s): ", qname[i]);
0649 print_queue(sc, txq, file);
0650 }
0651
0652 seq_puts(file, "(CAB): ");
0653 print_queue(sc, sc->beacon.cabq, file);
0654
0655 return 0;
0656 }
0657
0658 static int read_file_misc(struct seq_file *file, void *data)
0659 {
0660 struct ieee80211_hw *hw = dev_get_drvdata(file->private);
0661 struct ath_softc *sc = hw->priv;
0662 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
0663 struct ath9k_vif_iter_data iter_data;
0664 struct ath_chanctx *ctx;
0665 unsigned int reg;
0666 u32 rxfilter, i;
0667
0668 seq_printf(file, "BSSID: %pM\n", common->curbssid);
0669 seq_printf(file, "BSSID-MASK: %pM\n", common->bssidmask);
0670 seq_printf(file, "OPMODE: %s\n",
0671 ath_opmode_to_string(sc->sc_ah->opmode));
0672
0673 ath9k_ps_wakeup(sc);
0674 rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
0675 ath9k_ps_restore(sc);
0676
0677 seq_printf(file, "RXFILTER: 0x%x", rxfilter);
0678
0679 if (rxfilter & ATH9K_RX_FILTER_UCAST)
0680 seq_puts(file, " UCAST");
0681 if (rxfilter & ATH9K_RX_FILTER_MCAST)
0682 seq_puts(file, " MCAST");
0683 if (rxfilter & ATH9K_RX_FILTER_BCAST)
0684 seq_puts(file, " BCAST");
0685 if (rxfilter & ATH9K_RX_FILTER_CONTROL)
0686 seq_puts(file, " CONTROL");
0687 if (rxfilter & ATH9K_RX_FILTER_BEACON)
0688 seq_puts(file, " BEACON");
0689 if (rxfilter & ATH9K_RX_FILTER_PROM)
0690 seq_puts(file, " PROM");
0691 if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
0692 seq_puts(file, " PROBEREQ");
0693 if (rxfilter & ATH9K_RX_FILTER_PHYERR)
0694 seq_puts(file, " PHYERR");
0695 if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
0696 seq_puts(file, " MYBEACON");
0697 if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
0698 seq_puts(file, " COMP_BAR");
0699 if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
0700 seq_puts(file, " PSPOLL");
0701 if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
0702 seq_puts(file, " PHYRADAR");
0703 if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
0704 seq_puts(file, " MCAST_BCAST_ALL");
0705 if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
0706 seq_puts(file, " CONTROL_WRAPPER");
0707
0708 seq_puts(file, "\n");
0709
0710 reg = sc->sc_ah->imask;
0711
0712 seq_printf(file, "INTERRUPT-MASK: 0x%x", reg);
0713
0714 if (reg & ATH9K_INT_SWBA)
0715 seq_puts(file, " SWBA");
0716 if (reg & ATH9K_INT_BMISS)
0717 seq_puts(file, " BMISS");
0718 if (reg & ATH9K_INT_CST)
0719 seq_puts(file, " CST");
0720 if (reg & ATH9K_INT_RX)
0721 seq_puts(file, " RX");
0722 if (reg & ATH9K_INT_RXHP)
0723 seq_puts(file, " RXHP");
0724 if (reg & ATH9K_INT_RXLP)
0725 seq_puts(file, " RXLP");
0726 if (reg & ATH9K_INT_BB_WATCHDOG)
0727 seq_puts(file, " BB_WATCHDOG");
0728
0729 seq_puts(file, "\n");
0730
0731 i = 0;
0732 ath_for_each_chanctx(sc, ctx) {
0733 if (list_empty(&ctx->vifs))
0734 continue;
0735 ath9k_calculate_iter_data(sc, ctx, &iter_data);
0736
0737 seq_printf(file,
0738 "VIFS: CTX %i(%i) AP: %i STA: %i MESH: %i",
0739 i++, (int)(ctx->assigned), iter_data.naps,
0740 iter_data.nstations,
0741 iter_data.nmeshes);
0742 seq_printf(file, " ADHOC: %i OCB: %i TOTAL: %hi BEACON-VIF: %hi\n",
0743 iter_data.nadhocs, iter_data.nocbs, sc->cur_chan->nvifs,
0744 sc->nbcnvifs);
0745 }
0746
0747 return 0;
0748 }
0749
0750 static int read_file_reset(struct seq_file *file, void *data)
0751 {
0752 struct ath_softc *sc = file->private;
0753 static const char * const reset_cause[__RESET_TYPE_MAX] = {
0754 [RESET_TYPE_USER] = "User reset",
0755 [RESET_TYPE_BB_HANG] = "Baseband Hang",
0756 [RESET_TYPE_BB_WATCHDOG] = "Baseband Watchdog",
0757 [RESET_TYPE_FATAL_INT] = "Fatal HW Error",
0758 [RESET_TYPE_TX_ERROR] = "TX HW error",
0759 [RESET_TYPE_TX_GTT] = "Transmit timeout",
0760 [RESET_TYPE_TX_HANG] = "TX Path Hang",
0761 [RESET_TYPE_PLL_HANG] = "PLL RX Hang",
0762 [RESET_TYPE_MAC_HANG] = "MAC Hang",
0763 [RESET_TYPE_BEACON_STUCK] = "Stuck Beacon",
0764 [RESET_TYPE_MCI] = "MCI Reset",
0765 [RESET_TYPE_CALIBRATION] = "Calibration error",
0766 [RESET_TX_DMA_ERROR] = "Tx DMA stop error",
0767 [RESET_RX_DMA_ERROR] = "Rx DMA stop error",
0768 };
0769 int i;
0770
0771 for (i = 0; i < ARRAY_SIZE(reset_cause); i++) {
0772 if (!reset_cause[i])
0773 continue;
0774
0775 seq_printf(file, "%17s: %2d\n", reset_cause[i],
0776 sc->debug.stats.reset[i]);
0777 }
0778
0779 return 0;
0780 }
0781
0782 static int open_file_reset(struct inode *inode, struct file *f)
0783 {
0784 return single_open(f, read_file_reset, inode->i_private);
0785 }
0786
0787 static ssize_t write_file_reset(struct file *file,
0788 const char __user *user_buf,
0789 size_t count, loff_t *ppos)
0790 {
0791 struct ath_softc *sc = file_inode(file)->i_private;
0792 struct ath_hw *ah = sc->sc_ah;
0793 struct ath_common *common = ath9k_hw_common(ah);
0794 unsigned long val;
0795 char buf[32];
0796 ssize_t len;
0797
0798 len = min(count, sizeof(buf) - 1);
0799 if (copy_from_user(buf, user_buf, len))
0800 return -EFAULT;
0801
0802 buf[len] = '\0';
0803 if (kstrtoul(buf, 0, &val))
0804 return -EINVAL;
0805
0806 if (val != 1)
0807 return -EINVAL;
0808
0809
0810 mutex_lock(&sc->mutex);
0811 if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
0812 mutex_unlock(&sc->mutex);
0813 return -EBUSY;
0814 }
0815
0816 ath9k_queue_reset(sc, RESET_TYPE_USER);
0817 mutex_unlock(&sc->mutex);
0818
0819 return count;
0820 }
0821
0822 static const struct file_operations fops_reset = {
0823 .read = seq_read,
0824 .write = write_file_reset,
0825 .open = open_file_reset,
0826 .owner = THIS_MODULE,
0827 .llseek = seq_lseek,
0828 .release = single_release,
0829 };
0830
0831 void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
0832 struct ath_tx_status *ts, struct ath_txq *txq,
0833 unsigned int flags)
0834 {
0835 int qnum = txq->axq_qnum;
0836
0837 TX_STAT_INC(sc, qnum, tx_pkts_all);
0838 sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
0839
0840 if (bf_isampdu(bf)) {
0841 if (flags & ATH_TX_ERROR)
0842 TX_STAT_INC(sc, qnum, a_xretries);
0843 else
0844 TX_STAT_INC(sc, qnum, a_completed);
0845 } else {
0846 if (ts->ts_status & ATH9K_TXERR_XRETRY)
0847 TX_STAT_INC(sc, qnum, xretries);
0848 else
0849 TX_STAT_INC(sc, qnum, completed);
0850 }
0851
0852 if (ts->ts_status & ATH9K_TXERR_FILT)
0853 TX_STAT_INC(sc, qnum, txerr_filtered);
0854 if (ts->ts_status & ATH9K_TXERR_FIFO)
0855 TX_STAT_INC(sc, qnum, fifo_underrun);
0856 if (ts->ts_status & ATH9K_TXERR_XTXOP)
0857 TX_STAT_INC(sc, qnum, xtxop);
0858 if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
0859 TX_STAT_INC(sc, qnum, timer_exp);
0860 if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
0861 TX_STAT_INC(sc, qnum, desc_cfg_err);
0862 if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
0863 TX_STAT_INC(sc, qnum, data_underrun);
0864 if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
0865 TX_STAT_INC(sc, qnum, delim_underrun);
0866 }
0867
0868 void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
0869 {
0870 ath9k_cmn_debug_stat_rx(&sc->debug.stats.rxstats, rs);
0871 }
0872
0873 static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
0874 size_t count, loff_t *ppos)
0875 {
0876 struct ath_softc *sc = file->private_data;
0877 char buf[32];
0878 unsigned int len;
0879
0880 len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
0881 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
0882 }
0883
0884 static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
0885 size_t count, loff_t *ppos)
0886 {
0887 struct ath_softc *sc = file->private_data;
0888 unsigned long regidx;
0889 char buf[32];
0890 ssize_t len;
0891
0892 len = min(count, sizeof(buf) - 1);
0893 if (copy_from_user(buf, user_buf, len))
0894 return -EFAULT;
0895
0896 buf[len] = '\0';
0897 if (kstrtoul(buf, 0, ®idx))
0898 return -EINVAL;
0899
0900 sc->debug.regidx = regidx;
0901 return count;
0902 }
0903
0904 static const struct file_operations fops_regidx = {
0905 .read = read_file_regidx,
0906 .write = write_file_regidx,
0907 .open = simple_open,
0908 .owner = THIS_MODULE,
0909 .llseek = default_llseek,
0910 };
0911
0912 static ssize_t read_file_regval(struct file *file, char __user *user_buf,
0913 size_t count, loff_t *ppos)
0914 {
0915 struct ath_softc *sc = file->private_data;
0916 struct ath_hw *ah = sc->sc_ah;
0917 char buf[32];
0918 unsigned int len;
0919 u32 regval;
0920
0921 ath9k_ps_wakeup(sc);
0922 regval = REG_READ_D(ah, sc->debug.regidx);
0923 ath9k_ps_restore(sc);
0924 len = sprintf(buf, "0x%08x\n", regval);
0925 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
0926 }
0927
0928 static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
0929 size_t count, loff_t *ppos)
0930 {
0931 struct ath_softc *sc = file->private_data;
0932 struct ath_hw *ah = sc->sc_ah;
0933 unsigned long regval;
0934 char buf[32];
0935 ssize_t len;
0936
0937 len = min(count, sizeof(buf) - 1);
0938 if (copy_from_user(buf, user_buf, len))
0939 return -EFAULT;
0940
0941 buf[len] = '\0';
0942 if (kstrtoul(buf, 0, ®val))
0943 return -EINVAL;
0944
0945 ath9k_ps_wakeup(sc);
0946 REG_WRITE_D(ah, sc->debug.regidx, regval);
0947 ath9k_ps_restore(sc);
0948 return count;
0949 }
0950
0951 static const struct file_operations fops_regval = {
0952 .read = read_file_regval,
0953 .write = write_file_regval,
0954 .open = simple_open,
0955 .owner = THIS_MODULE,
0956 .llseek = default_llseek,
0957 };
0958
0959 #define REGDUMP_LINE_SIZE 20
0960
0961 static int open_file_regdump(struct inode *inode, struct file *file)
0962 {
0963 struct ath_softc *sc = inode->i_private;
0964 unsigned int len = 0;
0965 u8 *buf;
0966 int i, j = 0;
0967 unsigned long num_regs, regdump_len, max_reg_offset;
0968 static const struct reg_hole {
0969 u32 start;
0970 u32 end;
0971 } reg_hole_list[] = {
0972 {0x0200, 0x07fc},
0973 {0x0c00, 0x0ffc},
0974 {0x2000, 0x3ffc},
0975 {0x4100, 0x6ffc},
0976 {0x705c, 0x7ffc},
0977 {0x0000, 0x0000}
0978 };
0979
0980 max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x8800 : 0xb500;
0981 num_regs = max_reg_offset / 4 + 1;
0982 regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
0983 buf = vmalloc(regdump_len);
0984 if (!buf)
0985 return -ENOMEM;
0986
0987 ath9k_ps_wakeup(sc);
0988 for (i = 0; i < num_regs; i++) {
0989 if (reg_hole_list[j].start == i << 2) {
0990 i = reg_hole_list[j].end >> 2;
0991 j++;
0992 continue;
0993 }
0994
0995 len += scnprintf(buf + len, regdump_len - len,
0996 "0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
0997 }
0998 ath9k_ps_restore(sc);
0999
1000 file->private_data = buf;
1001
1002 return 0;
1003 }
1004
1005 static const struct file_operations fops_regdump = {
1006 .open = open_file_regdump,
1007 .read = ath9k_debugfs_read_buf,
1008 .release = ath9k_debugfs_release_buf,
1009 .owner = THIS_MODULE,
1010 .llseek = default_llseek,
1011 };
1012
1013 static int read_file_dump_nfcal(struct seq_file *file, void *data)
1014 {
1015 struct ieee80211_hw *hw = dev_get_drvdata(file->private);
1016 struct ath_softc *sc = hw->priv;
1017 struct ath_hw *ah = sc->sc_ah;
1018 struct ath9k_nfcal_hist *h = sc->cur_chan->caldata.nfCalHist;
1019 struct ath_common *common = ath9k_hw_common(ah);
1020 struct ieee80211_conf *conf = &common->hw->conf;
1021 u32 i, j;
1022 u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1023 u8 nread;
1024
1025 seq_printf(file, "Channel Noise Floor : %d\n", ah->noise);
1026 seq_puts(file, "Chain | privNF | # Readings | NF Readings\n");
1027 for (i = 0; i < NUM_NF_READINGS; i++) {
1028 if (!(chainmask & (1 << i)) ||
1029 ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1030 continue;
1031
1032 nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
1033 seq_printf(file, " %d\t %d\t %d\t\t", i, h[i].privNF, nread);
1034 for (j = 0; j < nread; j++)
1035 seq_printf(file, " %d", h[i].nfCalBuffer[j]);
1036 seq_puts(file, "\n");
1037 }
1038
1039 return 0;
1040 }
1041
1042 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
1043 static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
1044 size_t count, loff_t *ppos)
1045 {
1046 struct ath_softc *sc = file->private_data;
1047 u32 len = 0, size = 1500;
1048 char *buf;
1049 size_t retval;
1050
1051 buf = kzalloc(size, GFP_KERNEL);
1052 if (buf == NULL)
1053 return -ENOMEM;
1054
1055 if (!sc->sc_ah->common.btcoex_enabled) {
1056 len = scnprintf(buf, size, "%s\n",
1057 "BTCOEX is disabled");
1058 goto exit;
1059 }
1060
1061 len = ath9k_dump_btcoex(sc, buf, size);
1062 exit:
1063 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1064 kfree(buf);
1065
1066 return retval;
1067 }
1068
1069 static const struct file_operations fops_btcoex = {
1070 .read = read_file_btcoex,
1071 .open = simple_open,
1072 .owner = THIS_MODULE,
1073 .llseek = default_llseek,
1074 };
1075 #endif
1076
1077 #ifdef CONFIG_ATH9K_DYNACK
1078 static ssize_t read_file_ackto(struct file *file, char __user *user_buf,
1079 size_t count, loff_t *ppos)
1080 {
1081 struct ath_softc *sc = file->private_data;
1082 struct ath_hw *ah = sc->sc_ah;
1083 char buf[32];
1084 unsigned int len;
1085
1086 len = sprintf(buf, "%u %c\n", ah->dynack.ackto,
1087 (ah->dynack.enabled) ? 'A' : 'S');
1088
1089 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1090 }
1091
1092 static const struct file_operations fops_ackto = {
1093 .read = read_file_ackto,
1094 .open = simple_open,
1095 .owner = THIS_MODULE,
1096 .llseek = default_llseek,
1097 };
1098 #endif
1099
1100 #ifdef CONFIG_ATH9K_WOW
1101
1102 static ssize_t read_file_wow(struct file *file, char __user *user_buf,
1103 size_t count, loff_t *ppos)
1104 {
1105 struct ath_softc *sc = file->private_data;
1106 unsigned int len = 0, size = 32;
1107 ssize_t retval;
1108 char *buf;
1109
1110 buf = kzalloc(size, GFP_KERNEL);
1111 if (!buf)
1112 return -ENOMEM;
1113
1114 len += scnprintf(buf + len, size - len, "WOW: %s\n",
1115 sc->force_wow ? "ENABLED" : "DISABLED");
1116
1117 if (len > size)
1118 len = size;
1119
1120 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1121 kfree(buf);
1122
1123 return retval;
1124 }
1125
1126 static ssize_t write_file_wow(struct file *file, const char __user *user_buf,
1127 size_t count, loff_t *ppos)
1128 {
1129 struct ath_softc *sc = file->private_data;
1130 unsigned long val;
1131 char buf[32];
1132 ssize_t len;
1133
1134 len = min(count, sizeof(buf) - 1);
1135 if (copy_from_user(buf, user_buf, len))
1136 return -EFAULT;
1137
1138 buf[len] = '\0';
1139 if (kstrtoul(buf, 0, &val))
1140 return -EINVAL;
1141
1142 if (val != 1)
1143 return -EINVAL;
1144
1145 if (!sc->force_wow) {
1146 sc->force_wow = true;
1147 ath9k_init_wow(sc->hw);
1148 }
1149
1150 return count;
1151 }
1152
1153 static const struct file_operations fops_wow = {
1154 .read = read_file_wow,
1155 .write = write_file_wow,
1156 .open = simple_open,
1157 .owner = THIS_MODULE,
1158 .llseek = default_llseek,
1159 };
1160
1161 #endif
1162
1163 static ssize_t read_file_tpc(struct file *file, char __user *user_buf,
1164 size_t count, loff_t *ppos)
1165 {
1166 struct ath_softc *sc = file->private_data;
1167 struct ath_hw *ah = sc->sc_ah;
1168 unsigned int len = 0, size = 32;
1169 ssize_t retval;
1170 char *buf;
1171
1172 buf = kzalloc(size, GFP_KERNEL);
1173 if (!buf)
1174 return -ENOMEM;
1175
1176 len += scnprintf(buf + len, size - len, "%s\n",
1177 ah->tpc_enabled ? "ENABLED" : "DISABLED");
1178
1179 if (len > size)
1180 len = size;
1181
1182 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1183 kfree(buf);
1184
1185 return retval;
1186 }
1187
1188 static ssize_t write_file_tpc(struct file *file, const char __user *user_buf,
1189 size_t count, loff_t *ppos)
1190 {
1191 struct ath_softc *sc = file->private_data;
1192 struct ath_hw *ah = sc->sc_ah;
1193 unsigned long val;
1194 char buf[32];
1195 ssize_t len;
1196 bool tpc_enabled;
1197
1198 len = min(count, sizeof(buf) - 1);
1199 if (copy_from_user(buf, user_buf, len))
1200 return -EFAULT;
1201
1202 buf[len] = '\0';
1203 if (kstrtoul(buf, 0, &val))
1204 return -EINVAL;
1205
1206 if (val > 1)
1207 return -EINVAL;
1208
1209 tpc_enabled = !!val;
1210
1211 if (tpc_enabled != ah->tpc_enabled) {
1212 ah->tpc_enabled = tpc_enabled;
1213
1214 mutex_lock(&sc->mutex);
1215 ath9k_set_txpower(sc, NULL);
1216 mutex_unlock(&sc->mutex);
1217 }
1218
1219 return count;
1220 }
1221
1222 static const struct file_operations fops_tpc = {
1223 .read = read_file_tpc,
1224 .write = write_file_tpc,
1225 .open = simple_open,
1226 .owner = THIS_MODULE,
1227 .llseek = default_llseek,
1228 };
1229
1230 static ssize_t read_file_nf_override(struct file *file,
1231 char __user *user_buf,
1232 size_t count, loff_t *ppos)
1233 {
1234 struct ath_softc *sc = file->private_data;
1235 struct ath_hw *ah = sc->sc_ah;
1236 char buf[32];
1237 unsigned int len;
1238
1239 if (ah->nf_override == 0)
1240 len = sprintf(buf, "off\n");
1241 else
1242 len = sprintf(buf, "%d\n", ah->nf_override);
1243
1244 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1245 }
1246
1247 static ssize_t write_file_nf_override(struct file *file,
1248 const char __user *user_buf,
1249 size_t count, loff_t *ppos)
1250 {
1251 struct ath_softc *sc = file->private_data;
1252 struct ath_hw *ah = sc->sc_ah;
1253 long val;
1254 char buf[32];
1255 ssize_t len;
1256
1257 len = min(count, sizeof(buf) - 1);
1258 if (copy_from_user(buf, user_buf, len))
1259 return -EFAULT;
1260
1261 buf[len] = '\0';
1262 if (strncmp("off", buf, 3) == 0)
1263 val = 0;
1264 else if (kstrtol(buf, 0, &val))
1265 return -EINVAL;
1266
1267 if (val > 0)
1268 return -EINVAL;
1269
1270 if (val < -120)
1271 return -EINVAL;
1272
1273 ah->nf_override = val;
1274
1275 if (ah->curchan) {
1276 ath9k_ps_wakeup(sc);
1277 ath9k_hw_loadnf(ah, ah->curchan);
1278 ath9k_ps_restore(sc);
1279 }
1280
1281 return count;
1282 }
1283
1284 static const struct file_operations fops_nf_override = {
1285 .read = read_file_nf_override,
1286 .write = write_file_nf_override,
1287 .open = simple_open,
1288 .owner = THIS_MODULE,
1289 .llseek = default_llseek,
1290 };
1291
1292
1293
1294 #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1295 static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1296 "tx_pkts_nic",
1297 "tx_bytes_nic",
1298 "rx_pkts_nic",
1299 "rx_bytes_nic",
1300 AMKSTR(d_tx_pkts),
1301 AMKSTR(d_tx_bytes),
1302 AMKSTR(d_tx_mpdus_queued),
1303 AMKSTR(d_tx_mpdus_completed),
1304 AMKSTR(d_tx_mpdu_xretries),
1305 AMKSTR(d_tx_aggregates),
1306 AMKSTR(d_tx_ampdus_queued_hw),
1307 AMKSTR(d_tx_ampdus_completed),
1308 AMKSTR(d_tx_ampdu_retries),
1309 AMKSTR(d_tx_ampdu_xretries),
1310 AMKSTR(d_tx_fifo_underrun),
1311 AMKSTR(d_tx_op_exceeded),
1312 AMKSTR(d_tx_timer_expiry),
1313 AMKSTR(d_tx_desc_cfg_err),
1314 AMKSTR(d_tx_data_underrun),
1315 AMKSTR(d_tx_delim_underrun),
1316 "d_rx_crc_err",
1317 "d_rx_decrypt_crc_err",
1318 "d_rx_phy_err",
1319 "d_rx_mic_err",
1320 "d_rx_pre_delim_crc_err",
1321 "d_rx_post_delim_crc_err",
1322 "d_rx_decrypt_busy_err",
1323
1324 "d_rx_phyerr_radar",
1325 "d_rx_phyerr_ofdm_timing",
1326 "d_rx_phyerr_cck_timing",
1327
1328 };
1329 #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1330
1331 void ath9k_get_et_strings(struct ieee80211_hw *hw,
1332 struct ieee80211_vif *vif,
1333 u32 sset, u8 *data)
1334 {
1335 if (sset == ETH_SS_STATS)
1336 memcpy(data, *ath9k_gstrings_stats,
1337 sizeof(ath9k_gstrings_stats));
1338 }
1339
1340 int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
1341 struct ieee80211_vif *vif, int sset)
1342 {
1343 if (sset == ETH_SS_STATS)
1344 return ATH9K_SSTATS_LEN;
1345 return 0;
1346 }
1347
1348 #define AWDATA(elem) \
1349 do { \
1350 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
1351 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
1352 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
1353 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
1354 } while (0)
1355
1356 #define AWDATA_RX(elem) \
1357 do { \
1358 data[i++] = sc->debug.stats.rxstats.elem; \
1359 } while (0)
1360
1361 void ath9k_get_et_stats(struct ieee80211_hw *hw,
1362 struct ieee80211_vif *vif,
1363 struct ethtool_stats *stats, u64 *data)
1364 {
1365 struct ath_softc *sc = hw->priv;
1366 int i = 0;
1367
1368 data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
1369 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
1370 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
1371 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
1372 data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
1373 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
1374 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
1375 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
1376 AWDATA_RX(rx_pkts_all);
1377 AWDATA_RX(rx_bytes_all);
1378
1379 AWDATA(tx_pkts_all);
1380 AWDATA(tx_bytes_all);
1381 AWDATA(queued);
1382 AWDATA(completed);
1383 AWDATA(xretries);
1384 AWDATA(a_aggr);
1385 AWDATA(a_queued_hw);
1386 AWDATA(a_completed);
1387 AWDATA(a_retries);
1388 AWDATA(a_xretries);
1389 AWDATA(fifo_underrun);
1390 AWDATA(xtxop);
1391 AWDATA(timer_exp);
1392 AWDATA(desc_cfg_err);
1393 AWDATA(data_underrun);
1394 AWDATA(delim_underrun);
1395
1396 AWDATA_RX(crc_err);
1397 AWDATA_RX(decrypt_crc_err);
1398 AWDATA_RX(phy_err);
1399 AWDATA_RX(mic_err);
1400 AWDATA_RX(pre_delim_crc_err);
1401 AWDATA_RX(post_delim_crc_err);
1402 AWDATA_RX(decrypt_busy_err);
1403
1404 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
1405 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
1406 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
1407
1408 WARN_ON(i != ATH9K_SSTATS_LEN);
1409 }
1410
1411 void ath9k_deinit_debug(struct ath_softc *sc)
1412 {
1413 ath9k_cmn_spectral_deinit_debug(&sc->spec_priv);
1414 }
1415
1416 int ath9k_init_debug(struct ath_hw *ah)
1417 {
1418 struct ath_common *common = ath9k_hw_common(ah);
1419 struct ath_softc *sc = (struct ath_softc *) common->priv;
1420
1421 sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1422 sc->hw->wiphy->debugfsdir);
1423 if (!sc->debug.debugfs_phy)
1424 return -ENOMEM;
1425
1426 #ifdef CONFIG_ATH_DEBUG
1427 debugfs_create_file("debug", 0600, sc->debug.debugfs_phy,
1428 sc, &fops_debug);
1429 #endif
1430
1431 ath9k_dfs_init_debug(sc);
1432 ath9k_tx99_init_debug(sc);
1433 ath9k_cmn_spectral_init_debug(&sc->spec_priv, sc->debug.debugfs_phy);
1434
1435 debugfs_create_devm_seqfile(sc->dev, "dma", sc->debug.debugfs_phy,
1436 read_file_dma);
1437 debugfs_create_devm_seqfile(sc->dev, "interrupt", sc->debug.debugfs_phy,
1438 read_file_interrupt);
1439 debugfs_create_devm_seqfile(sc->dev, "xmit", sc->debug.debugfs_phy,
1440 read_file_xmit);
1441 debugfs_create_devm_seqfile(sc->dev, "queues", sc->debug.debugfs_phy,
1442 read_file_queues);
1443 debugfs_create_devm_seqfile(sc->dev, "misc", sc->debug.debugfs_phy,
1444 read_file_misc);
1445 debugfs_create_file("reset", 0600, sc->debug.debugfs_phy,
1446 sc, &fops_reset);
1447
1448 ath9k_cmn_debug_recv(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
1449 ath9k_cmn_debug_phy_err(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
1450
1451 debugfs_create_u8("rx_chainmask", 0400, sc->debug.debugfs_phy,
1452 &ah->rxchainmask);
1453 debugfs_create_u8("tx_chainmask", 0400, sc->debug.debugfs_phy,
1454 &ah->txchainmask);
1455 debugfs_create_file("ani", 0600,
1456 sc->debug.debugfs_phy, sc, &fops_ani);
1457 debugfs_create_bool("paprd", 0600, sc->debug.debugfs_phy,
1458 &sc->sc_ah->config.enable_paprd);
1459 debugfs_create_file("regidx", 0600, sc->debug.debugfs_phy,
1460 sc, &fops_regidx);
1461 debugfs_create_file("regval", 0600, sc->debug.debugfs_phy,
1462 sc, &fops_regval);
1463 debugfs_create_bool("ignore_extcca", 0600,
1464 sc->debug.debugfs_phy,
1465 &ah->config.cwm_ignore_extcca);
1466 debugfs_create_file("regdump", 0400, sc->debug.debugfs_phy, sc,
1467 &fops_regdump);
1468 debugfs_create_devm_seqfile(sc->dev, "dump_nfcal",
1469 sc->debug.debugfs_phy,
1470 read_file_dump_nfcal);
1471
1472 ath9k_cmn_debug_base_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
1473 ath9k_cmn_debug_modal_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
1474
1475 debugfs_create_u32("gpio_mask", 0600,
1476 sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
1477 debugfs_create_u32("gpio_val", 0600,
1478 sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
1479 debugfs_create_file("antenna_diversity", 0400,
1480 sc->debug.debugfs_phy, sc, &fops_antenna_diversity);
1481 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
1482 debugfs_create_file("bt_ant_diversity", 0600,
1483 sc->debug.debugfs_phy, sc, &fops_bt_ant_diversity);
1484 debugfs_create_file("btcoex", 0400, sc->debug.debugfs_phy, sc,
1485 &fops_btcoex);
1486 #endif
1487
1488 #ifdef CONFIG_ATH9K_WOW
1489 debugfs_create_file("wow", 0600, sc->debug.debugfs_phy, sc, &fops_wow);
1490 #endif
1491
1492 #ifdef CONFIG_ATH9K_DYNACK
1493 debugfs_create_file("ack_to", 0400, sc->debug.debugfs_phy,
1494 sc, &fops_ackto);
1495 #endif
1496 debugfs_create_file("tpc", 0600, sc->debug.debugfs_phy, sc, &fops_tpc);
1497
1498 debugfs_create_file("nf_override", 0600,
1499 sc->debug.debugfs_phy, sc, &fops_nf_override);
1500
1501 return 0;
1502 }