2 * Copyright (c) 2008-2011 Atheros Communications Inc.
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.
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.
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>
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))
31 static ssize_t ath9k_debugfs_read_buf(struct file *file, char __user *user_buf,
32 size_t count, loff_t *ppos)
34 u8 *buf = file->private_data;
35 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
38 static int ath9k_debugfs_release_buf(struct inode *inode, struct file *file)
40 vfree(file->private_data);
44 #ifdef CONFIG_ATH_DEBUG
46 static ssize_t read_file_debug(struct file *file, char __user *user_buf,
47 size_t count, loff_t *ppos)
49 struct ath_softc *sc = file->private_data;
50 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
54 len = sprintf(buf, "0x%08x\n", common->debug_mask);
55 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
58 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
59 size_t count, loff_t *ppos)
61 struct ath_softc *sc = file->private_data;
62 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
67 len = min(count, sizeof(buf) - 1);
68 if (copy_from_user(buf, user_buf, len))
72 if (kstrtoul(buf, 0, &mask))
75 common->debug_mask = mask;
79 static const struct file_operations fops_debug = {
80 .read = read_file_debug,
81 .write = write_file_debug,
84 .llseek = default_llseek,
89 #define DMA_BUF_LEN 1024
92 static ssize_t read_file_ani(struct file *file, char __user *user_buf,
93 size_t count, loff_t *ppos)
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;
102 buf = kzalloc(size, GFP_KERNEL);
106 if (common->disable_ani) {
107 len += scnprintf(buf + len, size - len, "%s: %s\n",
112 len += scnprintf(buf + len, size - len, "%15s: %s\n",
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);
142 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
148 static ssize_t write_file_ani(struct file *file,
149 const char __user *user_buf,
150 size_t count, loff_t *ppos)
152 struct ath_softc *sc = file->private_data;
153 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
158 len = min(count, sizeof(buf) - 1);
159 if (copy_from_user(buf, user_buf, len))
163 if (kstrtoul(buf, 0, &ani))
166 if (ani < 0 || ani > 1)
169 common->disable_ani = !ani;
171 if (common->disable_ani) {
172 clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
181 static const struct file_operations fops_ani = {
182 .read = read_file_ani,
183 .write = write_file_ani,
185 .owner = THIS_MODULE,
186 .llseek = default_llseek,
189 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
191 static ssize_t read_file_bt_ant_diversity(struct file *file,
192 char __user *user_buf,
193 size_t count, loff_t *ppos)
195 struct ath_softc *sc = file->private_data;
196 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
200 len = sprintf(buf, "%d\n", common->bt_ant_diversity);
201 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
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)
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;
215 len = min(count, sizeof(buf) - 1);
216 if (copy_from_user(buf, user_buf, len))
219 if (!(pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
223 if (kstrtoul(buf, 0, &bt_ant_diversity))
226 common->bt_ant_diversity = !!bt_ant_diversity;
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);
236 static const struct file_operations fops_bt_ant_diversity = {
237 .read = read_file_bt_ant_diversity,
238 .write = write_file_bt_ant_diversity,
240 .owner = THIS_MODULE,
241 .llseek = default_llseek,
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)
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];
253 as_main->lna_attempt_cnt[div_ant_conf->main_lna_conf]++;
254 as_alt->lna_attempt_cnt[div_ant_conf->alt_lna_conf]++;
256 as_main->rssi_avg = main_rssi_avg;
257 as_alt->rssi_avg = alt_rssi_avg;
260 static ssize_t read_file_antenna_diversity(struct file *file,
261 char __user *user_buf,
262 size_t count, loff_t *ppos)
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;
273 char *lna_conf_str[4] = {"LNA1_MINUS_LNA2",
278 buf = kzalloc(size, GFP_KERNEL);
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");
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",
296 len += scnprintf(buf + len, size - len, "Average ALT RSSI : %d\n\n",
298 ath9k_ps_restore(sc);
300 len += scnprintf(buf + len, size - len, "Packet Receive Cnt:\n");
301 len += scnprintf(buf + len, size - len, "-------------------\n");
303 len += scnprintf(buf + len, size - len, "%30s%15s\n",
305 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
309 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
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",
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",
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",
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]);
326 len += scnprintf(buf + len, size - len, "\nLNA Config Attempts:\n");
327 len += scnprintf(buf + len, size - len, "--------------------\n");
329 len += scnprintf(buf + len, size - len, "%30s%15s\n",
331 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
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",
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",
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",
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]);
352 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
358 static const struct file_operations fops_antenna_diversity = {
359 .read = read_file_antenna_diversity,
361 .owner = THIS_MODULE,
362 .llseek = default_llseek,
365 static ssize_t read_file_dma(struct file *file, char __user *user_buf,
366 size_t count, loff_t *ppos)
368 struct ath_softc *sc = file->private_data;
369 struct ath_hw *ah = sc->sc_ah;
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];
377 buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
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)));
388 len += scnprintf(buf + len, DMA_BUF_LEN - len,
389 "Raw DMA Debug values:\n");
391 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
393 len += scnprintf(buf + len, DMA_BUF_LEN - len, "\n");
395 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
396 len += scnprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
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");
404 for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
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);
423 len += scnprintf(buf + len, DMA_BUF_LEN - len, "\n");
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);
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));
449 ath9k_ps_restore(sc);
451 if (len > DMA_BUF_LEN)
454 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
459 static const struct file_operations fops_dma = {
460 .read = read_file_dma,
462 .owner = THIS_MODULE,
463 .llseek = default_llseek,
467 void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int 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++;
479 if (status & ATH9K_INT_RX)
480 sc->debug.stats.istats.rxok++;
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++;
520 static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
521 size_t count, loff_t *ppos)
523 struct ath_softc *sc = file->private_data;
524 unsigned int len = 0;
527 char *buf = kmalloc(mxlen, GFP_KERNEL);
531 #define PR_IS(a, s) \
533 len += scnprintf(buf + len, mxlen - len, \
535 sc->debug.stats.istats.s); \
538 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
541 PR_IS("WATHDOG", bb_watchdog);
545 PR_IS("RXEOL", rxeol);
546 PR_IS("RXORN", rxorn);
548 PR_IS("TXURN", txurn);
550 PR_IS("RXPHY", rxphyerr);
551 PR_IS("RXKCM", rx_keycache_miss);
553 PR_IS("BMISS", bmiss);
558 PR_IS("CABEND", cabend);
559 PR_IS("DTIMSYNC", dtimsync);
561 PR_IS("TSFOOR", tsfoor);
563 PR_IS("GENTIMER", gen_timer);
564 PR_IS("TOTAL", total);
566 len += scnprintf(buf + len, mxlen - len,
567 "SYNC_CAUSE stats:\n");
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);
592 rv = simple_read_from_buffer(user_buf, count, ppos, buf, len);
597 static const struct file_operations fops_interrupt = {
598 .read = read_file_interrupt,
600 .owner = THIS_MODULE,
601 .llseek = default_llseek,
604 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
605 size_t count, loff_t *ppos)
607 struct ath_softc *sc = file->private_data;
609 unsigned int len = 0, size = 2048;
612 buf = kzalloc(size, GFP_KERNEL);
616 len += sprintf(buf, "%30s %10s%10s%10s\n\n",
617 "BE", "BK", "VI", "VO");
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);
645 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
651 static ssize_t print_queue(struct ath_softc *sc, struct ath_txq *txq,
652 char *buf, ssize_t size)
656 ath_txq_lock(sc, txq);
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);
669 ath_txq_unlock(sc, txq);
673 static ssize_t read_file_queues(struct file *file, char __user *user_buf,
674 size_t count, loff_t *ppos)
676 struct ath_softc *sc = file->private_data;
679 unsigned int len = 0, size = 1024;
682 char *qname[4] = {"VO", "VI", "BE", "BK"};
684 buf = kzalloc(size, GFP_KERNEL);
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);
694 len += scnprintf(buf + len, size - len, "(CAB): ");
695 len += print_queue(sc, sc->beacon.cabq, buf + len, size - len);
700 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
706 static ssize_t read_file_misc(struct file *file, char __user *user_buf,
707 size_t count, loff_t *ppos)
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;
714 unsigned int len = 0;
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,
725 ath_opmode_to_string(sc->sc_ah->opmode));
728 rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
729 ath9k_ps_restore(sc);
731 len += scnprintf(buf + len, sizeof(buf) - len,
732 "RXFILTER: 0x%x", rxfilter);
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");
763 len += scnprintf(buf + len, sizeof(buf) - len, "\n");
765 reg = sc->sc_ah->imask;
767 len += scnprintf(buf + len, sizeof(buf) - len,
768 "INTERRUPT-MASK: 0x%x", reg);
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");
785 len += scnprintf(buf + len, sizeof(buf) - len, "\n");
787 ath9k_calculate_iter_data(hw, NULL, &iter_data);
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);
796 if (len > sizeof(buf))
799 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
803 static ssize_t read_file_reset(struct file *file, char __user *user_buf,
804 size_t count, loff_t *ppos)
806 struct ath_softc *sc = file->private_data;
808 unsigned int len = 0;
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]);
832 if (len > sizeof(buf))
835 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
838 void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
839 struct ath_tx_status *ts, struct ath_txq *txq,
842 int qnum = txq->axq_qnum;
844 TX_STAT_INC(qnum, tx_pkts_all);
845 sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
847 if (bf_isampdu(bf)) {
848 if (flags & ATH_TX_ERROR)
849 TX_STAT_INC(qnum, a_xretries);
851 TX_STAT_INC(qnum, a_completed);
853 if (ts->ts_status & ATH9K_TXERR_XRETRY)
854 TX_STAT_INC(qnum, xretries);
856 TX_STAT_INC(qnum, completed);
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);
875 static const struct file_operations fops_xmit = {
876 .read = read_file_xmit,
878 .owner = THIS_MODULE,
879 .llseek = default_llseek,
882 static const struct file_operations fops_queues = {
883 .read = read_file_queues,
885 .owner = THIS_MODULE,
886 .llseek = default_llseek,
889 static const struct file_operations fops_misc = {
890 .read = read_file_misc,
892 .owner = THIS_MODULE,
893 .llseek = default_llseek,
896 static const struct file_operations fops_reset = {
897 .read = read_file_reset,
899 .owner = THIS_MODULE,
900 .llseek = default_llseek,
903 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
904 size_t count, loff_t *ppos)
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]);
910 #define RXS_ERR(s, e) \
912 len += scnprintf(buf + len, size - len, \
913 "%22s : %10u\n", s, \
914 sc->debug.stats.rxstats.e);\
917 struct ath_softc *sc = file->private_data;
919 unsigned int len = 0, size = 1600;
922 buf = kzalloc(size, GFP_KERNEL);
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);
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);
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);
974 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
983 void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
985 #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
987 RX_STAT_INC(rx_pkts_all);
988 sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
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);
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);
1009 #undef RX_PHY_ERR_INC
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,
1019 static ssize_t read_file_spec_scan_ctl(struct file *file, char __user *user_buf,
1020 size_t count, loff_t *ppos)
1022 struct ath_softc *sc = file->private_data;
1026 switch (sc->spectral_mode) {
1027 case SPECTRAL_DISABLED:
1030 case SPECTRAL_BACKGROUND:
1031 mode = "background";
1033 case SPECTRAL_CHANSCAN:
1036 case SPECTRAL_MANUAL:
1041 return simple_read_from_buffer(user_buf, count, ppos, mode, len);
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)
1048 struct ath_softc *sc = file->private_data;
1049 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1053 if (config_enabled(CONFIG_ATH9K_TX99))
1056 len = min(count, sizeof(buf) - 1);
1057 if (copy_from_user(buf, user_buf, len))
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");
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,
1091 static ssize_t read_file_spectral_short_repeat(struct file *file,
1092 char __user *user_buf,
1093 size_t count, loff_t *ppos)
1095 struct ath_softc *sc = file->private_data;
1099 len = sprintf(buf, "%d\n", sc->spec_config.short_repeat);
1100 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
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)
1107 struct ath_softc *sc = file->private_data;
1112 len = min(count, sizeof(buf) - 1);
1113 if (copy_from_user(buf, user_buf, len))
1117 if (kstrtoul(buf, 0, &val))
1120 if (val < 0 || val > 1)
1123 sc->spec_config.short_repeat = val;
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,
1135 static ssize_t read_file_spectral_count(struct file *file,
1136 char __user *user_buf,
1137 size_t count, loff_t *ppos)
1139 struct ath_softc *sc = file->private_data;
1143 len = sprintf(buf, "%d\n", sc->spec_config.count);
1144 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1147 static ssize_t write_file_spectral_count(struct file *file,
1148 const char __user *user_buf,
1149 size_t count, loff_t *ppos)
1151 struct ath_softc *sc = file->private_data;
1156 len = min(count, sizeof(buf) - 1);
1157 if (copy_from_user(buf, user_buf, len))
1161 if (kstrtoul(buf, 0, &val))
1164 if (val < 0 || val > 255)
1167 sc->spec_config.count = val;
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,
1179 static ssize_t read_file_spectral_period(struct file *file,
1180 char __user *user_buf,
1181 size_t count, loff_t *ppos)
1183 struct ath_softc *sc = file->private_data;
1187 len = sprintf(buf, "%d\n", sc->spec_config.period);
1188 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1191 static ssize_t write_file_spectral_period(struct file *file,
1192 const char __user *user_buf,
1193 size_t count, loff_t *ppos)
1195 struct ath_softc *sc = file->private_data;
1200 len = min(count, sizeof(buf) - 1);
1201 if (copy_from_user(buf, user_buf, len))
1205 if (kstrtoul(buf, 0, &val))
1208 if (val < 0 || val > 255)
1211 sc->spec_config.period = val;
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,
1223 static ssize_t read_file_spectral_fft_period(struct file *file,
1224 char __user *user_buf,
1225 size_t count, loff_t *ppos)
1227 struct ath_softc *sc = file->private_data;
1231 len = sprintf(buf, "%d\n", sc->spec_config.fft_period);
1232 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
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)
1239 struct ath_softc *sc = file->private_data;
1244 len = min(count, sizeof(buf) - 1);
1245 if (copy_from_user(buf, user_buf, len))
1249 if (kstrtoul(buf, 0, &val))
1252 if (val < 0 || val > 15)
1255 sc->spec_config.fft_period = val;
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,
1267 static struct dentry *create_buf_file_handler(const char *filename,
1268 struct dentry *parent,
1270 struct rchan_buf *buf,
1273 struct dentry *buf_file;
1275 buf_file = debugfs_create_file(filename, mode, parent, buf,
1276 &relay_file_operations);
1281 static int remove_buf_file_handler(struct dentry *dentry)
1283 debugfs_remove(dentry);
1288 void ath_debug_send_fft_sample(struct ath_softc *sc,
1289 struct fft_sample_tlv *fft_sample_tlv)
1292 if (!sc->rfs_chan_spec_scan)
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);
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,
1306 static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
1307 size_t count, loff_t *ppos)
1309 struct ath_softc *sc = file->private_data;
1313 len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
1314 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1317 static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
1318 size_t count, loff_t *ppos)
1320 struct ath_softc *sc = file->private_data;
1321 unsigned long regidx;
1325 len = min(count, sizeof(buf) - 1);
1326 if (copy_from_user(buf, user_buf, len))
1330 if (kstrtoul(buf, 0, ®idx))
1333 sc->debug.regidx = regidx;
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,
1345 static ssize_t read_file_regval(struct file *file, char __user *user_buf,
1346 size_t count, loff_t *ppos)
1348 struct ath_softc *sc = file->private_data;
1349 struct ath_hw *ah = sc->sc_ah;
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);
1361 static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
1362 size_t count, loff_t *ppos)
1364 struct ath_softc *sc = file->private_data;
1365 struct ath_hw *ah = sc->sc_ah;
1366 unsigned long regval;
1370 len = min(count, sizeof(buf) - 1);
1371 if (copy_from_user(buf, user_buf, len))
1375 if (kstrtoul(buf, 0, ®val))
1378 ath9k_ps_wakeup(sc);
1379 REG_WRITE_D(ah, sc->debug.regidx, regval);
1380 ath9k_ps_restore(sc);
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,
1392 #define REGDUMP_LINE_SIZE 20
1394 static int open_file_regdump(struct inode *inode, struct file *file)
1396 struct ath_softc *sc = inode->i_private;
1397 unsigned int len = 0;
1400 unsigned long num_regs, regdump_len, max_reg_offset;
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);
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);
1415 file->private_data = buf;
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 */
1428 static ssize_t read_file_dump_nfcal(struct file *file, char __user *user_buf,
1429 size_t count, loff_t *ppos)
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;
1440 u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1443 buf = kzalloc(size, GFP_KERNEL);
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)))
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");
1468 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
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,
1481 static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf,
1482 size_t count, loff_t *ppos)
1484 struct ath_softc *sc = file->private_data;
1485 struct ath_hw *ah = sc->sc_ah;
1486 u32 len = 0, size = 1500;
1490 buf = kzalloc(size, GFP_KERNEL);
1494 len = ah->eep_ops->dump_eeprom(ah, true, buf, len, size);
1496 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
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,
1509 static ssize_t read_file_modal_eeprom(struct file *file, char __user *user_buf,
1510 size_t count, loff_t *ppos)
1512 struct ath_softc *sc = file->private_data;
1513 struct ath_hw *ah = sc->sc_ah;
1514 u32 len = 0, size = 6000;
1518 buf = kzalloc(size, GFP_KERNEL);
1522 len = ah->eep_ops->dump_eeprom(ah, false, buf, len, size);
1524 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
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,
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)
1541 struct ath_softc *sc = file->private_data;
1542 u32 len = 0, size = 1500;
1546 buf = kzalloc(size, GFP_KERNEL);
1550 if (!sc->sc_ah->common.btcoex_enabled) {
1551 len = scnprintf(buf, size, "%s\n",
1552 "BTCOEX is disabled");
1556 len = ath9k_dump_btcoex(sc, buf, size);
1558 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
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,
1572 static ssize_t read_file_node_stat(struct file *file, char __user *user_buf,
1573 size_t count, loff_t *ppos)
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;
1585 buf = kzalloc(size, GFP_KERNEL);
1589 if (!an->sta->ht_cap.ht_supported) {
1590 len = scnprintf(buf, size, "%s\n",
1591 "HT not supported");
1595 len = scnprintf(buf, size, "Max-AMPDU: %d\n",
1597 len += scnprintf(buf + len, size - len, "MPDU Density: %d\n\n",
1600 len += scnprintf(buf + len, size - len,
1601 "%2s%7s\n", "AC", "SCHED");
1603 for (acno = 0, ac = &an->ac[acno];
1604 acno < IEEE80211_NUM_ACS; acno++, ac++) {
1606 ath_txq_lock(sc, txq);
1607 len += scnprintf(buf + len, size - len,
1610 ath_txq_unlock(sc, txq);
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");
1618 for (tidno = 0, tid = &an->tid[tidno];
1619 tidno < IEEE80211_NUM_TIDS; tidno++, tid++) {
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);
1630 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
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,
1643 void ath9k_sta_add_debugfs(struct ieee80211_hw *hw,
1644 struct ieee80211_vif *vif,
1645 struct ieee80211_sta *sta,
1648 struct ath_node *an = (struct ath_node *)sta->drv_priv;
1649 debugfs_create_file("node_stat", S_IRUGO, dir, an, &fops_node_stat);
1652 /* Ethtool support for get-stats */
1654 #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1655 static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
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),
1678 "d_rx_decrypt_crc_err",
1681 "d_rx_pre_delim_crc_err",
1682 "d_rx_post_delim_crc_err",
1683 "d_rx_decrypt_busy_err",
1685 "d_rx_phyerr_radar",
1686 "d_rx_phyerr_ofdm_timing",
1687 "d_rx_phyerr_cck_timing",
1690 #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1692 void ath9k_get_et_strings(struct ieee80211_hw *hw,
1693 struct ieee80211_vif *vif,
1696 if (sset == ETH_SS_STATS)
1697 memcpy(data, *ath9k_gstrings_stats,
1698 sizeof(ath9k_gstrings_stats));
1701 int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
1702 struct ieee80211_vif *vif, int sset)
1704 if (sset == ETH_SS_STATS)
1705 return ATH9K_SSTATS_LEN;
1709 #define AWDATA(elem) \
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; \
1717 #define AWDATA_RX(elem) \
1719 data[i++] = sc->debug.stats.rxstats.elem; \
1722 void ath9k_get_et_stats(struct ieee80211_hw *hw,
1723 struct ieee80211_vif *vif,
1724 struct ethtool_stats *stats, u64 *data)
1726 struct ath_softc *sc = hw->priv;
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);
1740 AWDATA(tx_pkts_all);
1741 AWDATA(tx_bytes_all);
1746 AWDATA(a_queued_hw);
1747 AWDATA(a_queued_sw);
1748 AWDATA(a_completed);
1751 AWDATA(fifo_underrun);
1754 AWDATA(desc_cfg_err);
1755 AWDATA(data_underrun);
1756 AWDATA(delim_underrun);
1759 AWDATA_RX(decrypt_crc_err);
1762 AWDATA_RX(pre_delim_crc_err);
1763 AWDATA_RX(post_delim_crc_err);
1764 AWDATA_RX(decrypt_busy_err);
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]);
1770 WARN_ON(i != ATH9K_SSTATS_LEN);
1773 void ath9k_deinit_debug(struct ath_softc *sc)
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;
1781 static ssize_t read_file_tx99(struct file *file, char __user *user_buf,
1782 size_t count, loff_t *ppos)
1784 struct ath_softc *sc = file->private_data;
1788 len = sprintf(buf, "%d\n", sc->tx99_state);
1789 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1792 static ssize_t write_file_tx99(struct file *file, const char __user *user_buf,
1793 size_t count, loff_t *ppos)
1795 struct ath_softc *sc = file->private_data;
1796 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1805 len = min(count, sizeof(buf) - 1);
1806 if (copy_from_user(buf, user_buf, len))
1809 if (strtobool(buf, &start))
1812 if (start == sc->tx99_state) {
1815 ath_dbg(common, XMIT, "Resetting TX99\n");
1816 ath9k_tx99_deinit(sc);
1820 ath9k_tx99_deinit(sc);
1824 r = ath9k_tx99_init(sc);
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,
1839 static ssize_t read_file_tx99_power(struct file *file,
1840 char __user *user_buf,
1841 size_t count, loff_t *ppos)
1843 struct ath_softc *sc = file->private_data;
1847 len = sprintf(buf, "%d (%d dBm)\n",
1849 sc->tx99_power / 2);
1851 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1854 static ssize_t write_file_tx99_power(struct file *file,
1855 const char __user *user_buf,
1856 size_t count, loff_t *ppos)
1858 struct ath_softc *sc = file->private_data;
1862 r = kstrtou8_from_user(user_buf, count, 0, &tx_power);
1866 if (tx_power > MAX_RATE_POWER)
1869 sc->tx99_power = tx_power;
1871 ath9k_ps_wakeup(sc);
1872 ath9k_hw_tx99_set_txpower(sc->sc_ah, sc->tx99_power);
1873 ath9k_ps_restore(sc);
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,
1886 int ath9k_init_debug(struct ath_hw *ah)
1888 struct ath_common *common = ath9k_hw_common(ah);
1889 struct ath_softc *sc = (struct ath_softc *) common->priv;
1891 sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1892 sc->hw->wiphy->debugfsdir);
1893 if (!sc->debug.debugfs_phy)
1896 #ifdef CONFIG_ATH_DEBUG
1897 debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1901 ath9k_dfs_init_debug(sc);
1903 debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
1905 debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
1907 debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc,
1909 debugfs_create_file("queues", S_IRUSR, sc->debug.debugfs_phy, sc,
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,
1921 debugfs_create_file("reset", S_IRUSR, sc->debug.debugfs_phy, sc,
1923 debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy, sc,
1925 debugfs_create_u8("rx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
1927 debugfs_create_u8("tx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
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,
1935 debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
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,
1942 debugfs_create_file("dump_nfcal", S_IRUSR, sc->debug.debugfs_phy, sc,
1944 debugfs_create_file("base_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
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,
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,
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,
1982 debugfs_create_file("tx99_power", S_IRUSR | S_IWUSR,
1983 sc->debug.debugfs_phy, sc,