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 (strict_strtoul(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
91 static ssize_t read_file_tx_chainmask(struct file *file, char __user *user_buf,
92 size_t count, loff_t *ppos)
94 struct ath_softc *sc = file->private_data;
95 struct ath_hw *ah = sc->sc_ah;
99 len = sprintf(buf, "0x%08x\n", ah->txchainmask);
100 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
103 static ssize_t write_file_tx_chainmask(struct file *file, const char __user *user_buf,
104 size_t count, loff_t *ppos)
106 struct ath_softc *sc = file->private_data;
107 struct ath_hw *ah = sc->sc_ah;
112 len = min(count, sizeof(buf) - 1);
113 if (copy_from_user(buf, user_buf, len))
117 if (strict_strtoul(buf, 0, &mask))
120 ah->txchainmask = mask;
121 ah->caps.tx_chainmask = mask;
125 static const struct file_operations fops_tx_chainmask = {
126 .read = read_file_tx_chainmask,
127 .write = write_file_tx_chainmask,
129 .owner = THIS_MODULE,
130 .llseek = default_llseek,
134 static ssize_t read_file_rx_chainmask(struct file *file, char __user *user_buf,
135 size_t count, loff_t *ppos)
137 struct ath_softc *sc = file->private_data;
138 struct ath_hw *ah = sc->sc_ah;
142 len = sprintf(buf, "0x%08x\n", ah->rxchainmask);
143 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
146 static ssize_t write_file_rx_chainmask(struct file *file, const char __user *user_buf,
147 size_t count, loff_t *ppos)
149 struct ath_softc *sc = file->private_data;
150 struct ath_hw *ah = sc->sc_ah;
155 len = min(count, sizeof(buf) - 1);
156 if (copy_from_user(buf, user_buf, len))
160 if (strict_strtoul(buf, 0, &mask))
163 ah->rxchainmask = mask;
164 ah->caps.rx_chainmask = mask;
168 static const struct file_operations fops_rx_chainmask = {
169 .read = read_file_rx_chainmask,
170 .write = write_file_rx_chainmask,
172 .owner = THIS_MODULE,
173 .llseek = default_llseek,
176 static ssize_t read_file_disable_ani(struct file *file, char __user *user_buf,
177 size_t count, loff_t *ppos)
179 struct ath_softc *sc = file->private_data;
180 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
184 len = sprintf(buf, "%d\n", common->disable_ani);
185 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
188 static ssize_t write_file_disable_ani(struct file *file,
189 const char __user *user_buf,
190 size_t count, loff_t *ppos)
192 struct ath_softc *sc = file->private_data;
193 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
194 unsigned long disable_ani;
198 len = min(count, sizeof(buf) - 1);
199 if (copy_from_user(buf, user_buf, len))
203 if (strict_strtoul(buf, 0, &disable_ani))
206 common->disable_ani = !!disable_ani;
209 clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
218 static const struct file_operations fops_disable_ani = {
219 .read = read_file_disable_ani,
220 .write = write_file_disable_ani,
222 .owner = THIS_MODULE,
223 .llseek = default_llseek,
226 static ssize_t read_file_ant_diversity(struct file *file, char __user *user_buf,
227 size_t count, loff_t *ppos)
229 struct ath_softc *sc = file->private_data;
230 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
234 len = sprintf(buf, "%d\n", common->antenna_diversity);
235 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
238 static ssize_t write_file_ant_diversity(struct file *file,
239 const char __user *user_buf,
240 size_t count, loff_t *ppos)
242 struct ath_softc *sc = file->private_data;
243 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
244 unsigned long antenna_diversity;
248 len = min(count, sizeof(buf) - 1);
249 if (copy_from_user(buf, user_buf, len))
252 if (!AR_SREV_9565(sc->sc_ah))
256 if (strict_strtoul(buf, 0, &antenna_diversity))
259 common->antenna_diversity = !!antenna_diversity;
261 ath_ant_comb_update(sc);
262 ath_dbg(common, CONFIG, "Antenna diversity: %d\n",
263 common->antenna_diversity);
264 ath9k_ps_restore(sc);
269 static const struct file_operations fops_ant_diversity = {
270 .read = read_file_ant_diversity,
271 .write = write_file_ant_diversity,
273 .owner = THIS_MODULE,
274 .llseek = default_llseek,
277 static ssize_t read_file_dma(struct file *file, char __user *user_buf,
278 size_t count, loff_t *ppos)
280 struct ath_softc *sc = file->private_data;
281 struct ath_hw *ah = sc->sc_ah;
284 unsigned int len = 0;
285 u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
286 int i, qcuOffset = 0, dcuOffset = 0;
287 u32 *qcuBase = &val[0], *dcuBase = &val[4];
289 buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
295 REG_WRITE_D(ah, AR_MACMISC,
296 ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
297 (AR_MACMISC_MISC_OBS_BUS_1 <<
298 AR_MACMISC_MISC_OBS_BUS_MSB_S)));
300 len += snprintf(buf + len, DMA_BUF_LEN - len,
301 "Raw DMA Debug values:\n");
303 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
305 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
307 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
308 len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
312 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
313 len += snprintf(buf + len, DMA_BUF_LEN - len,
314 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
316 for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
327 len += snprintf(buf + len, DMA_BUF_LEN - len,
328 "%2d %2x %1x %2x %2x\n",
329 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
330 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
331 val[2] & (0x7 << (i * 3)) >> (i * 3),
332 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
335 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
337 len += snprintf(buf + len, DMA_BUF_LEN - len,
338 "qcu_stitch state: %2x qcu_fetch state: %2x\n",
339 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
340 len += snprintf(buf + len, DMA_BUF_LEN - len,
341 "qcu_complete state: %2x dcu_complete state: %2x\n",
342 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
343 len += snprintf(buf + len, DMA_BUF_LEN - len,
344 "dcu_arb state: %2x dcu_fp state: %2x\n",
345 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
346 len += snprintf(buf + len, DMA_BUF_LEN - len,
347 "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
348 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
349 len += snprintf(buf + len, DMA_BUF_LEN - len,
350 "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
351 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
352 len += snprintf(buf + len, DMA_BUF_LEN - len,
353 "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
354 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
356 len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
357 REG_READ_D(ah, AR_OBS_BUS_1));
358 len += snprintf(buf + len, DMA_BUF_LEN - len,
359 "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
361 ath9k_ps_restore(sc);
363 if (len > DMA_BUF_LEN)
366 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
371 static const struct file_operations fops_dma = {
372 .read = read_file_dma,
374 .owner = THIS_MODULE,
375 .llseek = default_llseek,
379 void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
382 sc->debug.stats.istats.total++;
383 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
384 if (status & ATH9K_INT_RXLP)
385 sc->debug.stats.istats.rxlp++;
386 if (status & ATH9K_INT_RXHP)
387 sc->debug.stats.istats.rxhp++;
388 if (status & ATH9K_INT_BB_WATCHDOG)
389 sc->debug.stats.istats.bb_watchdog++;
391 if (status & ATH9K_INT_RX)
392 sc->debug.stats.istats.rxok++;
394 if (status & ATH9K_INT_RXEOL)
395 sc->debug.stats.istats.rxeol++;
396 if (status & ATH9K_INT_RXORN)
397 sc->debug.stats.istats.rxorn++;
398 if (status & ATH9K_INT_TX)
399 sc->debug.stats.istats.txok++;
400 if (status & ATH9K_INT_TXURN)
401 sc->debug.stats.istats.txurn++;
402 if (status & ATH9K_INT_RXPHY)
403 sc->debug.stats.istats.rxphyerr++;
404 if (status & ATH9K_INT_RXKCM)
405 sc->debug.stats.istats.rx_keycache_miss++;
406 if (status & ATH9K_INT_SWBA)
407 sc->debug.stats.istats.swba++;
408 if (status & ATH9K_INT_BMISS)
409 sc->debug.stats.istats.bmiss++;
410 if (status & ATH9K_INT_BNR)
411 sc->debug.stats.istats.bnr++;
412 if (status & ATH9K_INT_CST)
413 sc->debug.stats.istats.cst++;
414 if (status & ATH9K_INT_GTT)
415 sc->debug.stats.istats.gtt++;
416 if (status & ATH9K_INT_TIM)
417 sc->debug.stats.istats.tim++;
418 if (status & ATH9K_INT_CABEND)
419 sc->debug.stats.istats.cabend++;
420 if (status & ATH9K_INT_DTIMSYNC)
421 sc->debug.stats.istats.dtimsync++;
422 if (status & ATH9K_INT_DTIM)
423 sc->debug.stats.istats.dtim++;
424 if (status & ATH9K_INT_TSFOOR)
425 sc->debug.stats.istats.tsfoor++;
426 if (status & ATH9K_INT_MCI)
427 sc->debug.stats.istats.mci++;
428 if (status & ATH9K_INT_GENTIMER)
429 sc->debug.stats.istats.gen_timer++;
432 static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
433 size_t count, loff_t *ppos)
435 struct ath_softc *sc = file->private_data;
436 unsigned int len = 0;
439 char *buf = kmalloc(mxlen, GFP_KERNEL);
443 #define PR_IS(a, s) \
445 len += snprintf(buf + len, mxlen - len, \
447 sc->debug.stats.istats.s); \
450 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
453 PR_IS("WATHDOG", bb_watchdog);
457 PR_IS("RXEOL", rxeol);
458 PR_IS("RXORN", rxorn);
460 PR_IS("TXURN", txurn);
462 PR_IS("RXPHY", rxphyerr);
463 PR_IS("RXKCM", rx_keycache_miss);
465 PR_IS("BMISS", bmiss);
470 PR_IS("CABEND", cabend);
471 PR_IS("DTIMSYNC", dtimsync);
473 PR_IS("TSFOOR", tsfoor);
475 PR_IS("GENTIMER", gen_timer);
476 PR_IS("TOTAL", total);
478 len += snprintf(buf + len, mxlen - len,
479 "SYNC_CAUSE stats:\n");
481 PR_IS("Sync-All", sync_cause_all);
482 PR_IS("RTC-IRQ", sync_rtc_irq);
483 PR_IS("MAC-IRQ", sync_mac_irq);
484 PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
485 PR_IS("APB-Timeout", apb_timeout);
486 PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
487 PR_IS("HOST1-Fatal", host1_fatal);
488 PR_IS("HOST1-Perr", host1_perr);
489 PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
490 PR_IS("RADM-CPL-EP", radm_cpl_ep);
491 PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
492 PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
493 PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
494 PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
495 PR_IS("Local-Bus-Timeout", local_timeout);
496 PR_IS("PM-Access", pm_access);
497 PR_IS("MAC-Awake", mac_awake);
498 PR_IS("MAC-Asleep", mac_asleep);
499 PR_IS("MAC-Sleep-Access", mac_sleep_access);
504 rv = simple_read_from_buffer(user_buf, count, ppos, buf, len);
509 static const struct file_operations fops_interrupt = {
510 .read = read_file_interrupt,
512 .owner = THIS_MODULE,
513 .llseek = default_llseek,
516 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
517 size_t count, loff_t *ppos)
519 struct ath_softc *sc = file->private_data;
521 unsigned int len = 0, size = 2048;
524 buf = kzalloc(size, GFP_KERNEL);
528 len += sprintf(buf, "%30s %10s%10s%10s\n\n",
529 "BE", "BK", "VI", "VO");
531 PR("MPDUs Queued: ", queued);
532 PR("MPDUs Completed: ", completed);
533 PR("MPDUs XRetried: ", xretries);
534 PR("Aggregates: ", a_aggr);
535 PR("AMPDUs Queued HW:", a_queued_hw);
536 PR("AMPDUs Queued SW:", a_queued_sw);
537 PR("AMPDUs Completed:", a_completed);
538 PR("AMPDUs Retried: ", a_retries);
539 PR("AMPDUs XRetried: ", a_xretries);
540 PR("TXERR Filtered: ", txerr_filtered);
541 PR("FIFO Underrun: ", fifo_underrun);
542 PR("TXOP Exceeded: ", xtxop);
543 PR("TXTIMER Expiry: ", timer_exp);
544 PR("DESC CFG Error: ", desc_cfg_err);
545 PR("DATA Underrun: ", data_underrun);
546 PR("DELIM Underrun: ", delim_underrun);
547 PR("TX-Pkts-All: ", tx_pkts_all);
548 PR("TX-Bytes-All: ", tx_bytes_all);
549 PR("HW-put-tx-buf: ", puttxbuf);
550 PR("HW-tx-start: ", txstart);
551 PR("HW-tx-proc-desc: ", txprocdesc);
552 PR("TX-Failed: ", txfailed);
557 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
563 static ssize_t read_file_queues(struct file *file, char __user *user_buf,
564 size_t count, loff_t *ppos)
566 struct ath_softc *sc = file->private_data;
569 unsigned int len = 0, size = 1024;
572 char *qname[4] = {"VO", "VI", "BE", "BK"};
574 buf = kzalloc(size, GFP_KERNEL);
578 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
579 txq = sc->tx.txq_map[i];
580 len += snprintf(buf + len, size - len, "(%s): ", qname[i]);
582 ath_txq_lock(sc, txq);
584 len += snprintf(buf + len, size - len, "%s: %d ",
585 "qnum", txq->axq_qnum);
586 len += snprintf(buf + len, size - len, "%s: %2d ",
587 "qdepth", txq->axq_depth);
588 len += snprintf(buf + len, size - len, "%s: %2d ",
589 "ampdu-depth", txq->axq_ampdu_depth);
590 len += snprintf(buf + len, size - len, "%s: %3d ",
591 "pending", txq->pending_frames);
592 len += snprintf(buf + len, size - len, "%s: %d\n",
593 "stopped", txq->stopped);
595 ath_txq_unlock(sc, txq);
601 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
607 static ssize_t read_file_misc(struct file *file, char __user *user_buf,
608 size_t count, loff_t *ppos)
610 struct ath_softc *sc = file->private_data;
611 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
612 struct ieee80211_hw *hw = sc->hw;
613 struct ath9k_vif_iter_data iter_data;
615 unsigned int len = 0;
620 len += snprintf(buf + len, sizeof(buf) - len,
621 "BSSID: %pM\n", common->curbssid);
622 len += snprintf(buf + len, sizeof(buf) - len,
623 "BSSID-MASK: %pM\n", common->bssidmask);
624 len += snprintf(buf + len, sizeof(buf) - len,
625 "OPMODE: %s\n", ath_opmode_to_string(sc->sc_ah->opmode));
628 rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
629 ath9k_ps_restore(sc);
631 len += snprintf(buf + len, sizeof(buf) - len,
632 "RXFILTER: 0x%x", rxfilter);
634 if (rxfilter & ATH9K_RX_FILTER_UCAST)
635 len += snprintf(buf + len, sizeof(buf) - len, " UCAST");
636 if (rxfilter & ATH9K_RX_FILTER_MCAST)
637 len += snprintf(buf + len, sizeof(buf) - len, " MCAST");
638 if (rxfilter & ATH9K_RX_FILTER_BCAST)
639 len += snprintf(buf + len, sizeof(buf) - len, " BCAST");
640 if (rxfilter & ATH9K_RX_FILTER_CONTROL)
641 len += snprintf(buf + len, sizeof(buf) - len, " CONTROL");
642 if (rxfilter & ATH9K_RX_FILTER_BEACON)
643 len += snprintf(buf + len, sizeof(buf) - len, " BEACON");
644 if (rxfilter & ATH9K_RX_FILTER_PROM)
645 len += snprintf(buf + len, sizeof(buf) - len, " PROM");
646 if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
647 len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
648 if (rxfilter & ATH9K_RX_FILTER_PHYERR)
649 len += snprintf(buf + len, sizeof(buf) - len, " PHYERR");
650 if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
651 len += snprintf(buf + len, sizeof(buf) - len, " MYBEACON");
652 if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
653 len += snprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
654 if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
655 len += snprintf(buf + len, sizeof(buf) - len, " PSPOLL");
656 if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
657 len += snprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
658 if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
659 len += snprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL");
660 if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
661 len += snprintf(buf + len, sizeof(buf) - len, " CONTROL_WRAPPER");
663 len += snprintf(buf + len, sizeof(buf) - len, "\n");
665 reg = sc->sc_ah->imask;
667 len += snprintf(buf + len, sizeof(buf) - len, "INTERRUPT-MASK: 0x%x", reg);
669 if (reg & ATH9K_INT_SWBA)
670 len += snprintf(buf + len, sizeof(buf) - len, " SWBA");
671 if (reg & ATH9K_INT_BMISS)
672 len += snprintf(buf + len, sizeof(buf) - len, " BMISS");
673 if (reg & ATH9K_INT_CST)
674 len += snprintf(buf + len, sizeof(buf) - len, " CST");
675 if (reg & ATH9K_INT_RX)
676 len += snprintf(buf + len, sizeof(buf) - len, " RX");
677 if (reg & ATH9K_INT_RXHP)
678 len += snprintf(buf + len, sizeof(buf) - len, " RXHP");
679 if (reg & ATH9K_INT_RXLP)
680 len += snprintf(buf + len, sizeof(buf) - len, " RXLP");
681 if (reg & ATH9K_INT_BB_WATCHDOG)
682 len += snprintf(buf + len, sizeof(buf) - len, " BB_WATCHDOG");
684 len += snprintf(buf + len, sizeof(buf) - len, "\n");
686 ath9k_calculate_iter_data(hw, NULL, &iter_data);
688 len += snprintf(buf + len, sizeof(buf) - len,
689 "VIF-COUNTS: AP: %i STA: %i MESH: %i WDS: %i"
690 " ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n",
691 iter_data.naps, iter_data.nstations, iter_data.nmeshes,
692 iter_data.nwds, iter_data.nadhocs,
693 sc->nvifs, sc->nbcnvifs);
695 if (len > sizeof(buf))
698 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
702 static ssize_t read_file_reset(struct file *file, char __user *user_buf,
703 size_t count, loff_t *ppos)
705 struct ath_softc *sc = file->private_data;
707 unsigned int len = 0;
709 len += snprintf(buf + len, sizeof(buf) - len,
710 "%17s: %2d\n", "Baseband Hang",
711 sc->debug.stats.reset[RESET_TYPE_BB_HANG]);
712 len += snprintf(buf + len, sizeof(buf) - len,
713 "%17s: %2d\n", "Baseband Watchdog",
714 sc->debug.stats.reset[RESET_TYPE_BB_WATCHDOG]);
715 len += snprintf(buf + len, sizeof(buf) - len,
716 "%17s: %2d\n", "Fatal HW Error",
717 sc->debug.stats.reset[RESET_TYPE_FATAL_INT]);
718 len += snprintf(buf + len, sizeof(buf) - len,
719 "%17s: %2d\n", "TX HW error",
720 sc->debug.stats.reset[RESET_TYPE_TX_ERROR]);
721 len += snprintf(buf + len, sizeof(buf) - len,
722 "%17s: %2d\n", "TX Path Hang",
723 sc->debug.stats.reset[RESET_TYPE_TX_HANG]);
724 len += snprintf(buf + len, sizeof(buf) - len,
725 "%17s: %2d\n", "PLL RX Hang",
726 sc->debug.stats.reset[RESET_TYPE_PLL_HANG]);
727 len += snprintf(buf + len, sizeof(buf) - len,
728 "%17s: %2d\n", "MCI Reset",
729 sc->debug.stats.reset[RESET_TYPE_MCI]);
731 if (len > sizeof(buf))
734 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
737 void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
738 struct ath_tx_status *ts, struct ath_txq *txq,
741 int qnum = txq->axq_qnum;
743 TX_STAT_INC(qnum, tx_pkts_all);
744 sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
746 if (bf_isampdu(bf)) {
747 if (flags & ATH_TX_ERROR)
748 TX_STAT_INC(qnum, a_xretries);
750 TX_STAT_INC(qnum, a_completed);
752 if (ts->ts_status & ATH9K_TXERR_XRETRY)
753 TX_STAT_INC(qnum, xretries);
755 TX_STAT_INC(qnum, completed);
758 if (ts->ts_status & ATH9K_TXERR_FILT)
759 TX_STAT_INC(qnum, txerr_filtered);
760 if (ts->ts_status & ATH9K_TXERR_FIFO)
761 TX_STAT_INC(qnum, fifo_underrun);
762 if (ts->ts_status & ATH9K_TXERR_XTXOP)
763 TX_STAT_INC(qnum, xtxop);
764 if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
765 TX_STAT_INC(qnum, timer_exp);
766 if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
767 TX_STAT_INC(qnum, desc_cfg_err);
768 if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
769 TX_STAT_INC(qnum, data_underrun);
770 if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
771 TX_STAT_INC(qnum, delim_underrun);
774 static const struct file_operations fops_xmit = {
775 .read = read_file_xmit,
777 .owner = THIS_MODULE,
778 .llseek = default_llseek,
781 static const struct file_operations fops_queues = {
782 .read = read_file_queues,
784 .owner = THIS_MODULE,
785 .llseek = default_llseek,
788 static const struct file_operations fops_misc = {
789 .read = read_file_misc,
791 .owner = THIS_MODULE,
792 .llseek = default_llseek,
795 static const struct file_operations fops_reset = {
796 .read = read_file_reset,
798 .owner = THIS_MODULE,
799 .llseek = default_llseek,
802 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
803 size_t count, loff_t *ppos)
805 #define PHY_ERR(s, p) \
806 len += snprintf(buf + len, size - len, "%22s : %10u\n", s, \
807 sc->debug.stats.rxstats.phy_err_stats[p]);
809 #define RXS_ERR(s, e) \
811 len += snprintf(buf + len, size - len, \
812 "%22s : %10u\n", s, \
813 sc->debug.stats.rxstats.e); \
816 struct ath_softc *sc = file->private_data;
818 unsigned int len = 0, size = 1600;
821 buf = kzalloc(size, GFP_KERNEL);
825 RXS_ERR("CRC ERR", crc_err);
826 RXS_ERR("DECRYPT CRC ERR", decrypt_crc_err);
827 RXS_ERR("PHY ERR", phy_err);
828 RXS_ERR("MIC ERR", mic_err);
829 RXS_ERR("PRE-DELIM CRC ERR", pre_delim_crc_err);
830 RXS_ERR("POST-DELIM CRC ERR", post_delim_crc_err);
831 RXS_ERR("DECRYPT BUSY ERR", decrypt_busy_err);
832 RXS_ERR("RX-LENGTH-ERR", rx_len_err);
833 RXS_ERR("RX-OOM-ERR", rx_oom_err);
834 RXS_ERR("RX-RATE-ERR", rx_rate_err);
835 RXS_ERR("RX-TOO-MANY-FRAGS", rx_too_many_frags_err);
837 PHY_ERR("UNDERRUN ERR", ATH9K_PHYERR_UNDERRUN);
838 PHY_ERR("TIMING ERR", ATH9K_PHYERR_TIMING);
839 PHY_ERR("PARITY ERR", ATH9K_PHYERR_PARITY);
840 PHY_ERR("RATE ERR", ATH9K_PHYERR_RATE);
841 PHY_ERR("LENGTH ERR", ATH9K_PHYERR_LENGTH);
842 PHY_ERR("RADAR ERR", ATH9K_PHYERR_RADAR);
843 PHY_ERR("SERVICE ERR", ATH9K_PHYERR_SERVICE);
844 PHY_ERR("TOR ERR", ATH9K_PHYERR_TOR);
845 PHY_ERR("OFDM-TIMING ERR", ATH9K_PHYERR_OFDM_TIMING);
846 PHY_ERR("OFDM-SIGNAL-PARITY ERR", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
847 PHY_ERR("OFDM-RATE ERR", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
848 PHY_ERR("OFDM-LENGTH ERR", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
849 PHY_ERR("OFDM-POWER-DROP ERR", ATH9K_PHYERR_OFDM_POWER_DROP);
850 PHY_ERR("OFDM-SERVICE ERR", ATH9K_PHYERR_OFDM_SERVICE);
851 PHY_ERR("OFDM-RESTART ERR", ATH9K_PHYERR_OFDM_RESTART);
852 PHY_ERR("FALSE-RADAR-EXT ERR", ATH9K_PHYERR_FALSE_RADAR_EXT);
853 PHY_ERR("CCK-TIMING ERR", ATH9K_PHYERR_CCK_TIMING);
854 PHY_ERR("CCK-HEADER-CRC ERR", ATH9K_PHYERR_CCK_HEADER_CRC);
855 PHY_ERR("CCK-RATE ERR", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
856 PHY_ERR("CCK-SERVICE ERR", ATH9K_PHYERR_CCK_SERVICE);
857 PHY_ERR("CCK-RESTART ERR", ATH9K_PHYERR_CCK_RESTART);
858 PHY_ERR("CCK-LENGTH ERR", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
859 PHY_ERR("CCK-POWER-DROP ERR", ATH9K_PHYERR_CCK_POWER_DROP);
860 PHY_ERR("HT-CRC ERR", ATH9K_PHYERR_HT_CRC_ERROR);
861 PHY_ERR("HT-LENGTH ERR", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
862 PHY_ERR("HT-RATE ERR", ATH9K_PHYERR_HT_RATE_ILLEGAL);
864 RXS_ERR("RX-Pkts-All", rx_pkts_all);
865 RXS_ERR("RX-Bytes-All", rx_bytes_all);
866 RXS_ERR("RX-Beacons", rx_beacons);
867 RXS_ERR("RX-Frags", rx_frags);
868 RXS_ERR("RX-Spectral", rx_spectral);
873 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
882 void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
884 #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
886 RX_STAT_INC(rx_pkts_all);
887 sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
889 if (rs->rs_status & ATH9K_RXERR_CRC)
890 RX_STAT_INC(crc_err);
891 if (rs->rs_status & ATH9K_RXERR_DECRYPT)
892 RX_STAT_INC(decrypt_crc_err);
893 if (rs->rs_status & ATH9K_RXERR_MIC)
894 RX_STAT_INC(mic_err);
895 if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
896 RX_STAT_INC(pre_delim_crc_err);
897 if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
898 RX_STAT_INC(post_delim_crc_err);
899 if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
900 RX_STAT_INC(decrypt_busy_err);
902 if (rs->rs_status & ATH9K_RXERR_PHY) {
903 RX_STAT_INC(phy_err);
904 if (rs->rs_phyerr < ATH9K_PHYERR_MAX)
905 RX_PHY_ERR_INC(rs->rs_phyerr);
908 #undef RX_PHY_ERR_INC
911 static const struct file_operations fops_recv = {
912 .read = read_file_recv,
914 .owner = THIS_MODULE,
915 .llseek = default_llseek,
918 static ssize_t read_file_spec_scan_ctl(struct file *file, char __user *user_buf,
919 size_t count, loff_t *ppos)
921 struct ath_softc *sc = file->private_data;
925 switch (sc->spectral_mode) {
926 case SPECTRAL_DISABLED:
929 case SPECTRAL_BACKGROUND:
932 case SPECTRAL_CHANSCAN:
935 case SPECTRAL_MANUAL:
940 return simple_read_from_buffer(user_buf, count, ppos, mode, len);
943 static ssize_t write_file_spec_scan_ctl(struct file *file,
944 const char __user *user_buf,
945 size_t count, loff_t *ppos)
947 struct ath_softc *sc = file->private_data;
948 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
952 len = min(count, sizeof(buf) - 1);
953 if (copy_from_user(buf, user_buf, len))
958 if (strncmp("trigger", buf, 7) == 0) {
959 ath9k_spectral_scan_trigger(sc->hw);
960 } else if (strncmp("background", buf, 9) == 0) {
961 ath9k_spectral_scan_config(sc->hw, SPECTRAL_BACKGROUND);
962 ath_dbg(common, CONFIG, "spectral scan: background mode enabled\n");
963 } else if (strncmp("chanscan", buf, 8) == 0) {
964 ath9k_spectral_scan_config(sc->hw, SPECTRAL_CHANSCAN);
965 ath_dbg(common, CONFIG, "spectral scan: channel scan mode enabled\n");
966 } else if (strncmp("manual", buf, 6) == 0) {
967 ath9k_spectral_scan_config(sc->hw, SPECTRAL_MANUAL);
968 ath_dbg(common, CONFIG, "spectral scan: manual mode enabled\n");
969 } else if (strncmp("disable", buf, 7) == 0) {
970 ath9k_spectral_scan_config(sc->hw, SPECTRAL_DISABLED);
971 ath_dbg(common, CONFIG, "spectral scan: disabled\n");
979 static const struct file_operations fops_spec_scan_ctl = {
980 .read = read_file_spec_scan_ctl,
981 .write = write_file_spec_scan_ctl,
983 .owner = THIS_MODULE,
984 .llseek = default_llseek,
987 static ssize_t read_file_spectral_short_repeat(struct file *file,
988 char __user *user_buf,
989 size_t count, loff_t *ppos)
991 struct ath_softc *sc = file->private_data;
995 len = sprintf(buf, "%d\n", sc->spec_config.short_repeat);
996 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
999 static ssize_t write_file_spectral_short_repeat(struct file *file,
1000 const char __user *user_buf,
1001 size_t count, loff_t *ppos)
1003 struct ath_softc *sc = file->private_data;
1008 len = min(count, sizeof(buf) - 1);
1009 if (copy_from_user(buf, user_buf, len))
1013 if (kstrtoul(buf, 0, &val))
1016 if (val < 0 || val > 1)
1019 sc->spec_config.short_repeat = val;
1023 static const struct file_operations fops_spectral_short_repeat = {
1024 .read = read_file_spectral_short_repeat,
1025 .write = write_file_spectral_short_repeat,
1026 .open = simple_open,
1027 .owner = THIS_MODULE,
1028 .llseek = default_llseek,
1031 static ssize_t read_file_spectral_count(struct file *file,
1032 char __user *user_buf,
1033 size_t count, loff_t *ppos)
1035 struct ath_softc *sc = file->private_data;
1039 len = sprintf(buf, "%d\n", sc->spec_config.count);
1040 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1043 static ssize_t write_file_spectral_count(struct file *file,
1044 const char __user *user_buf,
1045 size_t count, loff_t *ppos)
1047 struct ath_softc *sc = file->private_data;
1052 len = min(count, sizeof(buf) - 1);
1053 if (copy_from_user(buf, user_buf, len))
1057 if (kstrtoul(buf, 0, &val))
1060 if (val < 0 || val > 255)
1063 sc->spec_config.count = val;
1067 static const struct file_operations fops_spectral_count = {
1068 .read = read_file_spectral_count,
1069 .write = write_file_spectral_count,
1070 .open = simple_open,
1071 .owner = THIS_MODULE,
1072 .llseek = default_llseek,
1075 static ssize_t read_file_spectral_period(struct file *file,
1076 char __user *user_buf,
1077 size_t count, loff_t *ppos)
1079 struct ath_softc *sc = file->private_data;
1083 len = sprintf(buf, "%d\n", sc->spec_config.period);
1084 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1087 static ssize_t write_file_spectral_period(struct file *file,
1088 const char __user *user_buf,
1089 size_t count, loff_t *ppos)
1091 struct ath_softc *sc = file->private_data;
1096 len = min(count, sizeof(buf) - 1);
1097 if (copy_from_user(buf, user_buf, len))
1101 if (kstrtoul(buf, 0, &val))
1104 if (val < 0 || val > 255)
1107 sc->spec_config.period = val;
1111 static const struct file_operations fops_spectral_period = {
1112 .read = read_file_spectral_period,
1113 .write = write_file_spectral_period,
1114 .open = simple_open,
1115 .owner = THIS_MODULE,
1116 .llseek = default_llseek,
1119 static ssize_t read_file_spectral_fft_period(struct file *file,
1120 char __user *user_buf,
1121 size_t count, loff_t *ppos)
1123 struct ath_softc *sc = file->private_data;
1127 len = sprintf(buf, "%d\n", sc->spec_config.fft_period);
1128 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1131 static ssize_t write_file_spectral_fft_period(struct file *file,
1132 const char __user *user_buf,
1133 size_t count, loff_t *ppos)
1135 struct ath_softc *sc = file->private_data;
1140 len = min(count, sizeof(buf) - 1);
1141 if (copy_from_user(buf, user_buf, len))
1145 if (kstrtoul(buf, 0, &val))
1148 if (val < 0 || val > 15)
1151 sc->spec_config.fft_period = val;
1155 static const struct file_operations fops_spectral_fft_period = {
1156 .read = read_file_spectral_fft_period,
1157 .write = write_file_spectral_fft_period,
1158 .open = simple_open,
1159 .owner = THIS_MODULE,
1160 .llseek = default_llseek,
1163 static struct dentry *create_buf_file_handler(const char *filename,
1164 struct dentry *parent,
1166 struct rchan_buf *buf,
1169 struct dentry *buf_file;
1171 buf_file = debugfs_create_file(filename, mode, parent, buf,
1172 &relay_file_operations);
1177 static int remove_buf_file_handler(struct dentry *dentry)
1179 debugfs_remove(dentry);
1184 void ath_debug_send_fft_sample(struct ath_softc *sc,
1185 struct fft_sample_tlv *fft_sample_tlv)
1188 if (!sc->rfs_chan_spec_scan)
1191 length = __be16_to_cpu(fft_sample_tlv->length) +
1192 sizeof(*fft_sample_tlv);
1193 relay_write(sc->rfs_chan_spec_scan, fft_sample_tlv, length);
1196 static struct rchan_callbacks rfs_spec_scan_cb = {
1197 .create_buf_file = create_buf_file_handler,
1198 .remove_buf_file = remove_buf_file_handler,
1202 static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
1203 size_t count, loff_t *ppos)
1205 struct ath_softc *sc = file->private_data;
1209 len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
1210 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1213 static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
1214 size_t count, loff_t *ppos)
1216 struct ath_softc *sc = file->private_data;
1217 unsigned long regidx;
1221 len = min(count, sizeof(buf) - 1);
1222 if (copy_from_user(buf, user_buf, len))
1226 if (strict_strtoul(buf, 0, ®idx))
1229 sc->debug.regidx = regidx;
1233 static const struct file_operations fops_regidx = {
1234 .read = read_file_regidx,
1235 .write = write_file_regidx,
1236 .open = simple_open,
1237 .owner = THIS_MODULE,
1238 .llseek = default_llseek,
1241 static ssize_t read_file_regval(struct file *file, char __user *user_buf,
1242 size_t count, loff_t *ppos)
1244 struct ath_softc *sc = file->private_data;
1245 struct ath_hw *ah = sc->sc_ah;
1250 ath9k_ps_wakeup(sc);
1251 regval = REG_READ_D(ah, sc->debug.regidx);
1252 ath9k_ps_restore(sc);
1253 len = sprintf(buf, "0x%08x\n", regval);
1254 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1257 static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
1258 size_t count, loff_t *ppos)
1260 struct ath_softc *sc = file->private_data;
1261 struct ath_hw *ah = sc->sc_ah;
1262 unsigned long regval;
1266 len = min(count, sizeof(buf) - 1);
1267 if (copy_from_user(buf, user_buf, len))
1271 if (strict_strtoul(buf, 0, ®val))
1274 ath9k_ps_wakeup(sc);
1275 REG_WRITE_D(ah, sc->debug.regidx, regval);
1276 ath9k_ps_restore(sc);
1280 static const struct file_operations fops_regval = {
1281 .read = read_file_regval,
1282 .write = write_file_regval,
1283 .open = simple_open,
1284 .owner = THIS_MODULE,
1285 .llseek = default_llseek,
1288 #define REGDUMP_LINE_SIZE 20
1290 static int open_file_regdump(struct inode *inode, struct file *file)
1292 struct ath_softc *sc = inode->i_private;
1293 unsigned int len = 0;
1296 unsigned long num_regs, regdump_len, max_reg_offset;
1298 max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
1299 num_regs = max_reg_offset / 4 + 1;
1300 regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
1301 buf = vmalloc(regdump_len);
1305 ath9k_ps_wakeup(sc);
1306 for (i = 0; i < num_regs; i++)
1307 len += scnprintf(buf + len, regdump_len - len,
1308 "0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
1309 ath9k_ps_restore(sc);
1311 file->private_data = buf;
1316 static const struct file_operations fops_regdump = {
1317 .open = open_file_regdump,
1318 .read = ath9k_debugfs_read_buf,
1319 .release = ath9k_debugfs_release_buf,
1320 .owner = THIS_MODULE,
1321 .llseek = default_llseek,/* read accesses f_pos */
1324 static ssize_t read_file_dump_nfcal(struct file *file, char __user *user_buf,
1325 size_t count, loff_t *ppos)
1327 struct ath_softc *sc = file->private_data;
1328 struct ath_hw *ah = sc->sc_ah;
1329 struct ath9k_nfcal_hist *h = sc->caldata.nfCalHist;
1330 struct ath_common *common = ath9k_hw_common(ah);
1331 struct ieee80211_conf *conf = &common->hw->conf;
1332 u32 len = 0, size = 1500;
1336 u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1339 buf = kzalloc(size, GFP_KERNEL);
1343 len += snprintf(buf + len, size - len,
1344 "Channel Noise Floor : %d\n", ah->noise);
1345 len += snprintf(buf + len, size - len,
1346 "Chain | privNF | # Readings | NF Readings\n");
1347 for (i = 0; i < NUM_NF_READINGS; i++) {
1348 if (!(chainmask & (1 << i)) ||
1349 ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1352 nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
1353 len += snprintf(buf + len, size - len, " %d\t %d\t %d\t\t",
1354 i, h[i].privNF, nread);
1355 for (j = 0; j < nread; j++)
1356 len += snprintf(buf + len, size - len,
1357 " %d", h[i].nfCalBuffer[j]);
1358 len += snprintf(buf + len, size - len, "\n");
1364 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1370 static const struct file_operations fops_dump_nfcal = {
1371 .read = read_file_dump_nfcal,
1372 .open = simple_open,
1373 .owner = THIS_MODULE,
1374 .llseek = default_llseek,
1377 static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf,
1378 size_t count, loff_t *ppos)
1380 struct ath_softc *sc = file->private_data;
1381 struct ath_hw *ah = sc->sc_ah;
1382 u32 len = 0, size = 1500;
1386 buf = kzalloc(size, GFP_KERNEL);
1390 len = ah->eep_ops->dump_eeprom(ah, true, buf, len, size);
1392 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1398 static const struct file_operations fops_base_eeprom = {
1399 .read = read_file_base_eeprom,
1400 .open = simple_open,
1401 .owner = THIS_MODULE,
1402 .llseek = default_llseek,
1405 static ssize_t read_file_modal_eeprom(struct file *file, char __user *user_buf,
1406 size_t count, loff_t *ppos)
1408 struct ath_softc *sc = file->private_data;
1409 struct ath_hw *ah = sc->sc_ah;
1410 u32 len = 0, size = 6000;
1414 buf = kzalloc(size, GFP_KERNEL);
1418 len = ah->eep_ops->dump_eeprom(ah, false, buf, len, size);
1420 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1426 static const struct file_operations fops_modal_eeprom = {
1427 .read = read_file_modal_eeprom,
1428 .open = simple_open,
1429 .owner = THIS_MODULE,
1430 .llseek = default_llseek,
1433 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
1434 static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
1435 size_t count, loff_t *ppos)
1437 struct ath_softc *sc = file->private_data;
1438 u32 len = 0, size = 1500;
1442 buf = kzalloc(size, GFP_KERNEL);
1446 if (!sc->sc_ah->common.btcoex_enabled) {
1447 len = snprintf(buf, size, "%s\n",
1448 "BTCOEX is disabled");
1452 len = ath9k_dump_btcoex(sc, buf, size);
1454 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1460 static const struct file_operations fops_btcoex = {
1461 .read = read_file_btcoex,
1462 .open = simple_open,
1463 .owner = THIS_MODULE,
1464 .llseek = default_llseek,
1468 static ssize_t read_file_node_stat(struct file *file, char __user *user_buf,
1469 size_t count, loff_t *ppos)
1471 struct ath_node *an = file->private_data;
1472 struct ath_softc *sc = an->sc;
1473 struct ath_atx_tid *tid;
1474 struct ath_atx_ac *ac;
1475 struct ath_txq *txq;
1476 u32 len = 0, size = 4096;
1481 buf = kzalloc(size, GFP_KERNEL);
1485 if (!an->sta->ht_cap.ht_supported) {
1486 len = snprintf(buf, size, "%s\n",
1487 "HT not supported");
1491 len = snprintf(buf, size, "Max-AMPDU: %d\n",
1493 len += snprintf(buf + len, size - len, "MPDU Density: %d\n\n",
1496 len += snprintf(buf + len, size - len,
1497 "%2s%7s\n", "AC", "SCHED");
1499 for (acno = 0, ac = &an->ac[acno];
1500 acno < IEEE80211_NUM_ACS; acno++, ac++) {
1502 ath_txq_lock(sc, txq);
1503 len += snprintf(buf + len, size - len,
1506 ath_txq_unlock(sc, txq);
1509 len += snprintf(buf + len, size - len,
1510 "\n%3s%11s%10s%10s%10s%10s%9s%6s%8s\n",
1511 "TID", "SEQ_START", "SEQ_NEXT", "BAW_SIZE",
1512 "BAW_HEAD", "BAW_TAIL", "BAR_IDX", "SCHED", "PAUSED");
1514 for (tidno = 0, tid = &an->tid[tidno];
1515 tidno < IEEE80211_NUM_TIDS; tidno++, tid++) {
1517 ath_txq_lock(sc, txq);
1518 len += snprintf(buf + len, size - len,
1519 "%3d%11d%10d%10d%10d%10d%9d%6d%8d\n",
1520 tid->tidno, tid->seq_start, tid->seq_next,
1521 tid->baw_size, tid->baw_head, tid->baw_tail,
1522 tid->bar_index, tid->sched, tid->paused);
1523 ath_txq_unlock(sc, txq);
1526 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1532 static const struct file_operations fops_node_stat = {
1533 .read = read_file_node_stat,
1534 .open = simple_open,
1535 .owner = THIS_MODULE,
1536 .llseek = default_llseek,
1539 void ath9k_sta_add_debugfs(struct ieee80211_hw *hw,
1540 struct ieee80211_vif *vif,
1541 struct ieee80211_sta *sta,
1544 struct ath_node *an = (struct ath_node *)sta->drv_priv;
1545 an->node_stat = debugfs_create_file("node_stat", S_IRUGO,
1546 dir, an, &fops_node_stat);
1549 void ath9k_sta_remove_debugfs(struct ieee80211_hw *hw,
1550 struct ieee80211_vif *vif,
1551 struct ieee80211_sta *sta,
1554 struct ath_node *an = (struct ath_node *)sta->drv_priv;
1555 debugfs_remove(an->node_stat);
1558 /* Ethtool support for get-stats */
1560 #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1561 static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1568 AMKSTR(d_tx_mpdus_queued),
1569 AMKSTR(d_tx_mpdus_completed),
1570 AMKSTR(d_tx_mpdu_xretries),
1571 AMKSTR(d_tx_aggregates),
1572 AMKSTR(d_tx_ampdus_queued_hw),
1573 AMKSTR(d_tx_ampdus_queued_sw),
1574 AMKSTR(d_tx_ampdus_completed),
1575 AMKSTR(d_tx_ampdu_retries),
1576 AMKSTR(d_tx_ampdu_xretries),
1577 AMKSTR(d_tx_fifo_underrun),
1578 AMKSTR(d_tx_op_exceeded),
1579 AMKSTR(d_tx_timer_expiry),
1580 AMKSTR(d_tx_desc_cfg_err),
1581 AMKSTR(d_tx_data_underrun),
1582 AMKSTR(d_tx_delim_underrun),
1584 "d_rx_decrypt_crc_err",
1587 "d_rx_pre_delim_crc_err",
1588 "d_rx_post_delim_crc_err",
1589 "d_rx_decrypt_busy_err",
1591 "d_rx_phyerr_radar",
1592 "d_rx_phyerr_ofdm_timing",
1593 "d_rx_phyerr_cck_timing",
1596 #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1598 void ath9k_get_et_strings(struct ieee80211_hw *hw,
1599 struct ieee80211_vif *vif,
1602 if (sset == ETH_SS_STATS)
1603 memcpy(data, *ath9k_gstrings_stats,
1604 sizeof(ath9k_gstrings_stats));
1607 int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
1608 struct ieee80211_vif *vif, int sset)
1610 if (sset == ETH_SS_STATS)
1611 return ATH9K_SSTATS_LEN;
1615 #define AWDATA(elem) \
1617 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
1618 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
1619 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
1620 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
1623 #define AWDATA_RX(elem) \
1625 data[i++] = sc->debug.stats.rxstats.elem; \
1628 void ath9k_get_et_stats(struct ieee80211_hw *hw,
1629 struct ieee80211_vif *vif,
1630 struct ethtool_stats *stats, u64 *data)
1632 struct ath_softc *sc = hw->priv;
1635 data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
1636 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
1637 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
1638 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
1639 data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
1640 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
1641 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
1642 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
1643 AWDATA_RX(rx_pkts_all);
1644 AWDATA_RX(rx_bytes_all);
1646 AWDATA(tx_pkts_all);
1647 AWDATA(tx_bytes_all);
1652 AWDATA(a_queued_hw);
1653 AWDATA(a_queued_sw);
1654 AWDATA(a_completed);
1657 AWDATA(fifo_underrun);
1660 AWDATA(desc_cfg_err);
1661 AWDATA(data_underrun);
1662 AWDATA(delim_underrun);
1665 AWDATA_RX(decrypt_crc_err);
1668 AWDATA_RX(pre_delim_crc_err);
1669 AWDATA_RX(post_delim_crc_err);
1670 AWDATA_RX(decrypt_busy_err);
1672 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
1673 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
1674 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
1676 WARN_ON(i != ATH9K_SSTATS_LEN);
1679 int ath9k_init_debug(struct ath_hw *ah)
1681 struct ath_common *common = ath9k_hw_common(ah);
1682 struct ath_softc *sc = (struct ath_softc *) common->priv;
1684 sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1685 sc->hw->wiphy->debugfsdir);
1686 if (!sc->debug.debugfs_phy)
1689 #ifdef CONFIG_ATH_DEBUG
1690 debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1694 ath9k_dfs_init_debug(sc);
1696 debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
1698 debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
1700 debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc,
1702 debugfs_create_file("queues", S_IRUSR, sc->debug.debugfs_phy, sc,
1704 debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1705 &sc->tx.txq_max_pending[IEEE80211_AC_BK]);
1706 debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1707 &sc->tx.txq_max_pending[IEEE80211_AC_BE]);
1708 debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1709 &sc->tx.txq_max_pending[IEEE80211_AC_VI]);
1710 debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1711 &sc->tx.txq_max_pending[IEEE80211_AC_VO]);
1712 debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy, sc,
1714 debugfs_create_file("reset", S_IRUSR, sc->debug.debugfs_phy, sc,
1716 debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy, sc,
1718 debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
1719 sc->debug.debugfs_phy, sc, &fops_rx_chainmask);
1720 debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
1721 sc->debug.debugfs_phy, sc, &fops_tx_chainmask);
1722 debugfs_create_file("disable_ani", S_IRUSR | S_IWUSR,
1723 sc->debug.debugfs_phy, sc, &fops_disable_ani);
1724 debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1725 &sc->sc_ah->config.enable_paprd);
1726 debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1728 debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1730 debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1731 sc->debug.debugfs_phy,
1732 &ah->config.cwm_ignore_extcca);
1733 debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
1735 debugfs_create_file("dump_nfcal", S_IRUSR, sc->debug.debugfs_phy, sc,
1737 debugfs_create_file("base_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
1739 debugfs_create_file("modal_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
1740 &fops_modal_eeprom);
1741 sc->rfs_chan_spec_scan = relay_open("spectral_scan",
1742 sc->debug.debugfs_phy,
1743 1024, 256, &rfs_spec_scan_cb,
1745 debugfs_create_file("spectral_scan_ctl", S_IRUSR | S_IWUSR,
1746 sc->debug.debugfs_phy, sc,
1747 &fops_spec_scan_ctl);
1748 debugfs_create_file("spectral_short_repeat", S_IRUSR | S_IWUSR,
1749 sc->debug.debugfs_phy, sc,
1750 &fops_spectral_short_repeat);
1751 debugfs_create_file("spectral_count", S_IRUSR | S_IWUSR,
1752 sc->debug.debugfs_phy, sc, &fops_spectral_count);
1753 debugfs_create_file("spectral_period", S_IRUSR | S_IWUSR,
1754 sc->debug.debugfs_phy, sc, &fops_spectral_period);
1755 debugfs_create_file("spectral_fft_period", S_IRUSR | S_IWUSR,
1756 sc->debug.debugfs_phy, sc,
1757 &fops_spectral_fft_period);
1758 debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
1759 sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
1760 debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
1761 sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
1762 debugfs_create_file("diversity", S_IRUSR | S_IWUSR,
1763 sc->debug.debugfs_phy, sc, &fops_ant_diversity);
1764 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
1765 debugfs_create_file("btcoex", S_IRUSR, sc->debug.debugfs_phy, sc,