xref: /openbmc/linux/drivers/net/wireless/ath/ath9k/debug.c (revision 6a4d05dc0c0178b0c30dbda6e9bb79b5dd9662f5)
1203c4805SLuis R. Rodriguez /*
25b68138eSSujith Manoharan  * Copyright (c) 2008-2011 Atheros Communications Inc.
3203c4805SLuis R. Rodriguez  *
4203c4805SLuis R. Rodriguez  * Permission to use, copy, modify, and/or distribute this software for any
5203c4805SLuis R. Rodriguez  * purpose with or without fee is hereby granted, provided that the above
6203c4805SLuis R. Rodriguez  * copyright notice and this permission notice appear in all copies.
7203c4805SLuis R. Rodriguez  *
8203c4805SLuis R. Rodriguez  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9203c4805SLuis R. Rodriguez  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10203c4805SLuis R. Rodriguez  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11203c4805SLuis R. Rodriguez  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12203c4805SLuis R. Rodriguez  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13203c4805SLuis R. Rodriguez  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14203c4805SLuis R. Rodriguez  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15203c4805SLuis R. Rodriguez  */
16203c4805SLuis R. Rodriguez 
175a0e3ad6STejun Heo #include <linux/slab.h>
18582d0064SVasanthakumar Thiagarajan #include <linux/vmalloc.h>
19ee40fa06SPaul Gortmaker #include <linux/export.h>
20203c4805SLuis R. Rodriguez #include <asm/unaligned.h>
21203c4805SLuis R. Rodriguez 
22203c4805SLuis R. Rodriguez #include "ath9k.h"
23203c4805SLuis R. Rodriguez 
24475a6e4dSLuis R. Rodriguez #define REG_WRITE_D(_ah, _reg, _val) \
25475a6e4dSLuis R. Rodriguez 	ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg))
26475a6e4dSLuis R. Rodriguez #define REG_READ_D(_ah, _reg) \
27475a6e4dSLuis R. Rodriguez 	ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
28475a6e4dSLuis R. Rodriguez 
29*6a4d05dcSFelix Fietkau void ath9k_debug_sync_cause(struct ath_softc *sc, u32 sync_cause)
30*6a4d05dcSFelix Fietkau {
31*6a4d05dcSFelix Fietkau 	if (sync_cause)
32*6a4d05dcSFelix Fietkau 		sc->debug.stats.istats.sync_cause_all++;
33*6a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_RTC_IRQ)
34*6a4d05dcSFelix Fietkau 		sc->debug.stats.istats.sync_rtc_irq++;
35*6a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_MAC_IRQ)
36*6a4d05dcSFelix Fietkau 		sc->debug.stats.istats.sync_mac_irq++;
37*6a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_EEPROM_ILLEGAL_ACCESS)
38*6a4d05dcSFelix Fietkau 		sc->debug.stats.istats.eeprom_illegal_access++;
39*6a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_APB_TIMEOUT)
40*6a4d05dcSFelix Fietkau 		sc->debug.stats.istats.apb_timeout++;
41*6a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_PCI_MODE_CONFLICT)
42*6a4d05dcSFelix Fietkau 		sc->debug.stats.istats.pci_mode_conflict++;
43*6a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_HOST1_FATAL)
44*6a4d05dcSFelix Fietkau 		sc->debug.stats.istats.host1_fatal++;
45*6a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_HOST1_PERR)
46*6a4d05dcSFelix Fietkau 		sc->debug.stats.istats.host1_perr++;
47*6a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_TRCV_FIFO_PERR)
48*6a4d05dcSFelix Fietkau 		sc->debug.stats.istats.trcv_fifo_perr++;
49*6a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_RADM_CPL_EP)
50*6a4d05dcSFelix Fietkau 		sc->debug.stats.istats.radm_cpl_ep++;
51*6a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_RADM_CPL_DLLP_ABORT)
52*6a4d05dcSFelix Fietkau 		sc->debug.stats.istats.radm_cpl_dllp_abort++;
53*6a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_RADM_CPL_TLP_ABORT)
54*6a4d05dcSFelix Fietkau 		sc->debug.stats.istats.radm_cpl_tlp_abort++;
55*6a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_RADM_CPL_ECRC_ERR)
56*6a4d05dcSFelix Fietkau 		sc->debug.stats.istats.radm_cpl_ecrc_err++;
57*6a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT)
58*6a4d05dcSFelix Fietkau 		sc->debug.stats.istats.radm_cpl_timeout++;
59*6a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT)
60*6a4d05dcSFelix Fietkau 		sc->debug.stats.istats.local_timeout++;
61*6a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_PM_ACCESS)
62*6a4d05dcSFelix Fietkau 		sc->debug.stats.istats.pm_access++;
63*6a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_MAC_AWAKE)
64*6a4d05dcSFelix Fietkau 		sc->debug.stats.istats.mac_awake++;
65*6a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_MAC_ASLEEP)
66*6a4d05dcSFelix Fietkau 		sc->debug.stats.istats.mac_asleep++;
67*6a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_MAC_SLEEP_ACCESS)
68*6a4d05dcSFelix Fietkau 		sc->debug.stats.istats.mac_sleep_access++;
69*6a4d05dcSFelix Fietkau }
70203c4805SLuis R. Rodriguez 
71582d0064SVasanthakumar Thiagarajan static ssize_t ath9k_debugfs_read_buf(struct file *file, char __user *user_buf,
72582d0064SVasanthakumar Thiagarajan 				      size_t count, loff_t *ppos)
73582d0064SVasanthakumar Thiagarajan {
74582d0064SVasanthakumar Thiagarajan 	u8 *buf = file->private_data;
75582d0064SVasanthakumar Thiagarajan 	return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
76582d0064SVasanthakumar Thiagarajan }
77582d0064SVasanthakumar Thiagarajan 
78582d0064SVasanthakumar Thiagarajan static int ath9k_debugfs_release_buf(struct inode *inode, struct file *file)
79582d0064SVasanthakumar Thiagarajan {
80582d0064SVasanthakumar Thiagarajan 	vfree(file->private_data);
81582d0064SVasanthakumar Thiagarajan 	return 0;
82582d0064SVasanthakumar Thiagarajan }
83582d0064SVasanthakumar Thiagarajan 
84a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
85a830df07SFelix Fietkau 
862493928eSJeff Hansen static ssize_t read_file_debug(struct file *file, char __user *user_buf,
872493928eSJeff Hansen 			     size_t count, loff_t *ppos)
882493928eSJeff Hansen {
892493928eSJeff Hansen 	struct ath_softc *sc = file->private_data;
90c46917bbSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
912493928eSJeff Hansen 	char buf[32];
92581f725cSVasanthakumar Thiagarajan 	unsigned int len;
93581f725cSVasanthakumar Thiagarajan 
942b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", common->debug_mask);
952493928eSJeff Hansen 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
962493928eSJeff Hansen }
972493928eSJeff Hansen 
982493928eSJeff Hansen static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
992493928eSJeff Hansen 			     size_t count, loff_t *ppos)
1002493928eSJeff Hansen {
1012493928eSJeff Hansen 	struct ath_softc *sc = file->private_data;
102c46917bbSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1032493928eSJeff Hansen 	unsigned long mask;
1042493928eSJeff Hansen 	char buf[32];
105581f725cSVasanthakumar Thiagarajan 	ssize_t len;
106581f725cSVasanthakumar Thiagarajan 
107581f725cSVasanthakumar Thiagarajan 	len = min(count, sizeof(buf) - 1);
108581f725cSVasanthakumar Thiagarajan 	if (copy_from_user(buf, user_buf, len))
10904236066SDan Carpenter 		return -EFAULT;
110581f725cSVasanthakumar Thiagarajan 
111581f725cSVasanthakumar Thiagarajan 	buf[len] = '\0';
11227d7f477SJingoo Han 	if (kstrtoul(buf, 0, &mask))
113581f725cSVasanthakumar Thiagarajan 		return -EINVAL;
114581f725cSVasanthakumar Thiagarajan 
115c46917bbSLuis R. Rodriguez 	common->debug_mask = mask;
1162493928eSJeff Hansen 	return count;
1172493928eSJeff Hansen }
1182493928eSJeff Hansen 
1192493928eSJeff Hansen static const struct file_operations fops_debug = {
1202493928eSJeff Hansen 	.read = read_file_debug,
1212493928eSJeff Hansen 	.write = write_file_debug,
122234e3405SStephen Boyd 	.open = simple_open,
1236038f373SArnd Bergmann 	.owner = THIS_MODULE,
1246038f373SArnd Bergmann 	.llseek = default_llseek,
1252493928eSJeff Hansen };
1262493928eSJeff Hansen 
127a830df07SFelix Fietkau #endif
128a830df07SFelix Fietkau 
129991a0987SPavel Roskin #define DMA_BUF_LEN 1024
130991a0987SPavel Roskin 
13115340694SFelix Fietkau 
1326e4d291eSSujith Manoharan static ssize_t read_file_ani(struct file *file, char __user *user_buf,
13305c0be2fSMohammed Shafi Shajakhan 			     size_t count, loff_t *ppos)
13405c0be2fSMohammed Shafi Shajakhan {
13505c0be2fSMohammed Shafi Shajakhan 	struct ath_softc *sc = file->private_data;
13605c0be2fSMohammed Shafi Shajakhan 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1376e4d291eSSujith Manoharan 	struct ath_hw *ah = sc->sc_ah;
1386e4d291eSSujith Manoharan 	unsigned int len = 0, size = 1024;
1396e4d291eSSujith Manoharan 	ssize_t retval = 0;
1406e4d291eSSujith Manoharan 	char *buf;
14105c0be2fSMohammed Shafi Shajakhan 
1426e4d291eSSujith Manoharan 	buf = kzalloc(size, GFP_KERNEL);
1436e4d291eSSujith Manoharan 	if (buf == NULL)
1446e4d291eSSujith Manoharan 		return -ENOMEM;
1456e4d291eSSujith Manoharan 
1466e4d291eSSujith Manoharan 	if (common->disable_ani) {
1475e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, size - len, "%s: %s\n",
1486e4d291eSSujith Manoharan 				 "ANI", "DISABLED");
1496e4d291eSSujith Manoharan 		goto exit;
15005c0be2fSMohammed Shafi Shajakhan 	}
15105c0be2fSMohammed Shafi Shajakhan 
1525e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%15s: %s\n",
1536e4d291eSSujith Manoharan 			 "ANI", "ENABLED");
1545e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%15s: %u\n",
1556e4d291eSSujith Manoharan 			 "ANI RESET", ah->stats.ast_ani_reset);
1565e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%15s: %u\n",
1576e4d291eSSujith Manoharan 			 "SPUR UP", ah->stats.ast_ani_spurup);
1585e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%15s: %u\n",
1596e4d291eSSujith Manoharan 			 "SPUR DOWN", ah->stats.ast_ani_spurup);
1605e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%15s: %u\n",
1616e4d291eSSujith Manoharan 			 "OFDM WS-DET ON", ah->stats.ast_ani_ofdmon);
1625e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%15s: %u\n",
1636e4d291eSSujith Manoharan 			 "OFDM WS-DET OFF", ah->stats.ast_ani_ofdmoff);
1645e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%15s: %u\n",
1656e4d291eSSujith Manoharan 			 "MRC-CCK ON", ah->stats.ast_ani_ccklow);
1665e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%15s: %u\n",
1676e4d291eSSujith Manoharan 			 "MRC-CCK OFF", ah->stats.ast_ani_cckhigh);
1685e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%15s: %u\n",
1696e4d291eSSujith Manoharan 			 "FIR-STEP UP", ah->stats.ast_ani_stepup);
1705e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%15s: %u\n",
1716e4d291eSSujith Manoharan 			 "FIR-STEP DOWN", ah->stats.ast_ani_stepdown);
1725e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%15s: %u\n",
1736e4d291eSSujith Manoharan 			 "INV LISTENTIME", ah->stats.ast_ani_lneg_or_lzero);
1745e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%15s: %u\n",
1756e4d291eSSujith Manoharan 			 "OFDM ERRORS", ah->stats.ast_ani_ofdmerrs);
1765e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%15s: %u\n",
1776e4d291eSSujith Manoharan 			 "CCK ERRORS", ah->stats.ast_ani_cckerrs);
1786e4d291eSSujith Manoharan exit:
1796e4d291eSSujith Manoharan 	if (len > size)
1806e4d291eSSujith Manoharan 		len = size;
1816e4d291eSSujith Manoharan 
1826e4d291eSSujith Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1836e4d291eSSujith Manoharan 	kfree(buf);
1846e4d291eSSujith Manoharan 
1856e4d291eSSujith Manoharan 	return retval;
1866e4d291eSSujith Manoharan }
1876e4d291eSSujith Manoharan 
1886e4d291eSSujith Manoharan static ssize_t write_file_ani(struct file *file,
18905c0be2fSMohammed Shafi Shajakhan 			      const char __user *user_buf,
19005c0be2fSMohammed Shafi Shajakhan 			      size_t count, loff_t *ppos)
19105c0be2fSMohammed Shafi Shajakhan {
19205c0be2fSMohammed Shafi Shajakhan 	struct ath_softc *sc = file->private_data;
19305c0be2fSMohammed Shafi Shajakhan 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1946e4d291eSSujith Manoharan 	unsigned long ani;
19505c0be2fSMohammed Shafi Shajakhan 	char buf[32];
19605c0be2fSMohammed Shafi Shajakhan 	ssize_t len;
19705c0be2fSMohammed Shafi Shajakhan 
19805c0be2fSMohammed Shafi Shajakhan 	len = min(count, sizeof(buf) - 1);
19905c0be2fSMohammed Shafi Shajakhan 	if (copy_from_user(buf, user_buf, len))
20005c0be2fSMohammed Shafi Shajakhan 		return -EFAULT;
20105c0be2fSMohammed Shafi Shajakhan 
20205c0be2fSMohammed Shafi Shajakhan 	buf[len] = '\0';
2033899ba90SJohn W. Linville 	if (kstrtoul(buf, 0, &ani))
20405c0be2fSMohammed Shafi Shajakhan 		return -EINVAL;
20505c0be2fSMohammed Shafi Shajakhan 
2066e4d291eSSujith Manoharan 	if (ani < 0 || ani > 1)
2076e4d291eSSujith Manoharan 		return -EINVAL;
20805c0be2fSMohammed Shafi Shajakhan 
2096e4d291eSSujith Manoharan 	common->disable_ani = !ani;
2106e4d291eSSujith Manoharan 
2116e4d291eSSujith Manoharan 	if (common->disable_ani) {
212781b14a3SSujith Manoharan 		clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
213da0d45f7SSujith Manoharan 		ath_stop_ani(sc);
21405c0be2fSMohammed Shafi Shajakhan 	} else {
215da0d45f7SSujith Manoharan 		ath_check_ani(sc);
21605c0be2fSMohammed Shafi Shajakhan 	}
21705c0be2fSMohammed Shafi Shajakhan 
21805c0be2fSMohammed Shafi Shajakhan 	return count;
21905c0be2fSMohammed Shafi Shajakhan }
22005c0be2fSMohammed Shafi Shajakhan 
2216e4d291eSSujith Manoharan static const struct file_operations fops_ani = {
2226e4d291eSSujith Manoharan 	.read = read_file_ani,
2236e4d291eSSujith Manoharan 	.write = write_file_ani,
224234e3405SStephen Boyd 	.open = simple_open,
22505c0be2fSMohammed Shafi Shajakhan 	.owner = THIS_MODULE,
22605c0be2fSMohammed Shafi Shajakhan 	.llseek = default_llseek,
22705c0be2fSMohammed Shafi Shajakhan };
22815340694SFelix Fietkau 
22936e8825eSSujith Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
23036e8825eSSujith Manoharan 
23163081305SSujith Manoharan static ssize_t read_file_bt_ant_diversity(struct file *file,
23263081305SSujith Manoharan 					  char __user *user_buf,
233302a3c3aSSujith Manoharan 					  size_t count, loff_t *ppos)
234302a3c3aSSujith Manoharan {
235302a3c3aSSujith Manoharan 	struct ath_softc *sc = file->private_data;
236302a3c3aSSujith Manoharan 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
237302a3c3aSSujith Manoharan 	char buf[32];
238302a3c3aSSujith Manoharan 	unsigned int len;
239302a3c3aSSujith Manoharan 
24063081305SSujith Manoharan 	len = sprintf(buf, "%d\n", common->bt_ant_diversity);
241302a3c3aSSujith Manoharan 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
242302a3c3aSSujith Manoharan }
243302a3c3aSSujith Manoharan 
24463081305SSujith Manoharan static ssize_t write_file_bt_ant_diversity(struct file *file,
245302a3c3aSSujith Manoharan 					   const char __user *user_buf,
246302a3c3aSSujith Manoharan 					   size_t count, loff_t *ppos)
247302a3c3aSSujith Manoharan {
248302a3c3aSSujith Manoharan 	struct ath_softc *sc = file->private_data;
249302a3c3aSSujith Manoharan 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2503f2da955SSujith Manoharan 	struct ath9k_hw_capabilities *pCap = &sc->sc_ah->caps;
25163081305SSujith Manoharan 	unsigned long bt_ant_diversity;
252302a3c3aSSujith Manoharan 	char buf[32];
253302a3c3aSSujith Manoharan 	ssize_t len;
254302a3c3aSSujith Manoharan 
255302a3c3aSSujith Manoharan 	len = min(count, sizeof(buf) - 1);
256302a3c3aSSujith Manoharan 	if (copy_from_user(buf, user_buf, len))
257302a3c3aSSujith Manoharan 		return -EFAULT;
258302a3c3aSSujith Manoharan 
2593f2da955SSujith Manoharan 	if (!(pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
2603f2da955SSujith Manoharan 		goto exit;
2613f2da955SSujith Manoharan 
262302a3c3aSSujith Manoharan 	buf[len] = '\0';
26363081305SSujith Manoharan 	if (kstrtoul(buf, 0, &bt_ant_diversity))
264302a3c3aSSujith Manoharan 		return -EINVAL;
265302a3c3aSSujith Manoharan 
26663081305SSujith Manoharan 	common->bt_ant_diversity = !!bt_ant_diversity;
267302a3c3aSSujith Manoharan 	ath9k_ps_wakeup(sc);
268047dc3acSSujith Manoharan 	ath9k_hw_set_bt_ant_diversity(sc->sc_ah, common->bt_ant_diversity);
26963081305SSujith Manoharan 	ath_dbg(common, CONFIG, "Enable WLAN/BT RX Antenna diversity: %d\n",
27063081305SSujith Manoharan 		common->bt_ant_diversity);
271302a3c3aSSujith Manoharan 	ath9k_ps_restore(sc);
2723f2da955SSujith Manoharan exit:
273302a3c3aSSujith Manoharan 	return count;
274302a3c3aSSujith Manoharan }
275302a3c3aSSujith Manoharan 
27663081305SSujith Manoharan static const struct file_operations fops_bt_ant_diversity = {
27763081305SSujith Manoharan 	.read = read_file_bt_ant_diversity,
27863081305SSujith Manoharan 	.write = write_file_bt_ant_diversity,
279302a3c3aSSujith Manoharan 	.open = simple_open,
280302a3c3aSSujith Manoharan 	.owner = THIS_MODULE,
281302a3c3aSSujith Manoharan 	.llseek = default_llseek,
282302a3c3aSSujith Manoharan };
283302a3c3aSSujith Manoharan 
28436e8825eSSujith Manoharan #endif
28536e8825eSSujith Manoharan 
286e3d52914SSujith Manoharan void ath9k_debug_stat_ant(struct ath_softc *sc,
287e3d52914SSujith Manoharan 			  struct ath_hw_antcomb_conf *div_ant_conf,
288e3d52914SSujith Manoharan 			  int main_rssi_avg, int alt_rssi_avg)
289e3d52914SSujith Manoharan {
290e3d52914SSujith Manoharan 	struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
291e3d52914SSujith Manoharan 	struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
292e3d52914SSujith Manoharan 
293e3d52914SSujith Manoharan 	as_main->lna_attempt_cnt[div_ant_conf->main_lna_conf]++;
294e3d52914SSujith Manoharan 	as_alt->lna_attempt_cnt[div_ant_conf->alt_lna_conf]++;
295e3d52914SSujith Manoharan 
296e3d52914SSujith Manoharan 	as_main->rssi_avg = main_rssi_avg;
297e3d52914SSujith Manoharan 	as_alt->rssi_avg = alt_rssi_avg;
298e3d52914SSujith Manoharan }
299e3d52914SSujith Manoharan 
3004eba10ccSSujith Manoharan static ssize_t read_file_antenna_diversity(struct file *file,
3014eba10ccSSujith Manoharan 					   char __user *user_buf,
3024eba10ccSSujith Manoharan 					   size_t count, loff_t *ppos)
3034eba10ccSSujith Manoharan {
3044eba10ccSSujith Manoharan 	struct ath_softc *sc = file->private_data;
3054eba10ccSSujith Manoharan 	struct ath_hw *ah = sc->sc_ah;
3064eba10ccSSujith Manoharan 	struct ath9k_hw_capabilities *pCap = &ah->caps;
3074eba10ccSSujith Manoharan 	struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
3084eba10ccSSujith Manoharan 	struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
309e3d52914SSujith Manoharan 	struct ath_hw_antcomb_conf div_ant_conf;
3104eba10ccSSujith Manoharan 	unsigned int len = 0, size = 1024;
3114eba10ccSSujith Manoharan 	ssize_t retval = 0;
3124eba10ccSSujith Manoharan 	char *buf;
313e3d52914SSujith Manoharan 	char *lna_conf_str[4] = {"LNA1_MINUS_LNA2",
314e3d52914SSujith Manoharan 				 "LNA2",
315e3d52914SSujith Manoharan 				 "LNA1",
316e3d52914SSujith Manoharan 				 "LNA1_PLUS_LNA2"};
3174eba10ccSSujith Manoharan 
3184eba10ccSSujith Manoharan 	buf = kzalloc(size, GFP_KERNEL);
3194eba10ccSSujith Manoharan 	if (buf == NULL)
3204eba10ccSSujith Manoharan 		return -ENOMEM;
3214eba10ccSSujith Manoharan 
3224eba10ccSSujith Manoharan 	if (!(pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)) {
3235e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, size - len, "%s\n",
3244eba10ccSSujith Manoharan 				 "Antenna Diversity Combining is disabled");
3254eba10ccSSujith Manoharan 		goto exit;
3264eba10ccSSujith Manoharan 	}
3274eba10ccSSujith Manoharan 
328e3d52914SSujith Manoharan 	ath9k_ps_wakeup(sc);
329e3d52914SSujith Manoharan 	ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
3305e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "Current MAIN config : %s\n",
331e3d52914SSujith Manoharan 			 lna_conf_str[div_ant_conf.main_lna_conf]);
3325e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "Current ALT config  : %s\n",
333e3d52914SSujith Manoharan 			 lna_conf_str[div_ant_conf.alt_lna_conf]);
3345e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "Average MAIN RSSI   : %d\n",
335e3d52914SSujith Manoharan 			 as_main->rssi_avg);
3365e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "Average ALT RSSI    : %d\n\n",
337e3d52914SSujith Manoharan 			 as_alt->rssi_avg);
338e3d52914SSujith Manoharan 	ath9k_ps_restore(sc);
339e3d52914SSujith Manoharan 
3405e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "Packet Receive Cnt:\n");
3415e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "-------------------\n");
342e3d52914SSujith Manoharan 
3435e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%30s%15s\n",
3444eba10ccSSujith Manoharan 			 "MAIN", "ALT");
3455e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
346e3d52914SSujith Manoharan 			 "TOTAL COUNT",
3474eba10ccSSujith Manoharan 			 as_main->recv_cnt,
3484eba10ccSSujith Manoharan 			 as_alt->recv_cnt);
3495e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3504eba10ccSSujith Manoharan 			 "LNA1",
351e3d52914SSujith Manoharan 			 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1],
352e3d52914SSujith Manoharan 			 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1]);
3535e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3544eba10ccSSujith Manoharan 			 "LNA2",
355e3d52914SSujith Manoharan 			 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2],
356e3d52914SSujith Manoharan 			 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2]);
3575e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3584eba10ccSSujith Manoharan 			 "LNA1 + LNA2",
359e3d52914SSujith Manoharan 			 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
360e3d52914SSujith Manoharan 			 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
3615e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3624eba10ccSSujith Manoharan 			 "LNA1 - LNA2",
363e3d52914SSujith Manoharan 			 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
364e3d52914SSujith Manoharan 			 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
365e3d52914SSujith Manoharan 
3665e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "\nLNA Config Attempts:\n");
3675e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "--------------------\n");
368e3d52914SSujith Manoharan 
3695e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%30s%15s\n",
370e3d52914SSujith Manoharan 			 "MAIN", "ALT");
3715e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
372e3d52914SSujith Manoharan 			 "LNA1",
373e3d52914SSujith Manoharan 			 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1],
374e3d52914SSujith Manoharan 			 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1]);
3755e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
376e3d52914SSujith Manoharan 			 "LNA2",
377e3d52914SSujith Manoharan 			 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2],
378e3d52914SSujith Manoharan 			 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2]);
3795e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
380e3d52914SSujith Manoharan 			 "LNA1 + LNA2",
381e3d52914SSujith Manoharan 			 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
382e3d52914SSujith Manoharan 			 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
3835e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
384e3d52914SSujith Manoharan 			 "LNA1 - LNA2",
385e3d52914SSujith Manoharan 			 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
386e3d52914SSujith Manoharan 			 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
387e3d52914SSujith Manoharan 
3884eba10ccSSujith Manoharan exit:
3894eba10ccSSujith Manoharan 	if (len > size)
3904eba10ccSSujith Manoharan 		len = size;
3914eba10ccSSujith Manoharan 
3924eba10ccSSujith Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
3934eba10ccSSujith Manoharan 	kfree(buf);
3944eba10ccSSujith Manoharan 
3954eba10ccSSujith Manoharan 	return retval;
3964eba10ccSSujith Manoharan }
3974eba10ccSSujith Manoharan 
3984eba10ccSSujith Manoharan static const struct file_operations fops_antenna_diversity = {
3994eba10ccSSujith Manoharan 	.read = read_file_antenna_diversity,
4004eba10ccSSujith Manoharan 	.open = simple_open,
4014eba10ccSSujith Manoharan 	.owner = THIS_MODULE,
4024eba10ccSSujith Manoharan 	.llseek = default_llseek,
4034eba10ccSSujith Manoharan };
4044eba10ccSSujith Manoharan 
405203c4805SLuis R. Rodriguez static ssize_t read_file_dma(struct file *file, char __user *user_buf,
406203c4805SLuis R. Rodriguez 			     size_t count, loff_t *ppos)
407203c4805SLuis R. Rodriguez {
408203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
409203c4805SLuis R. Rodriguez 	struct ath_hw *ah = sc->sc_ah;
410991a0987SPavel Roskin 	char *buf;
411991a0987SPavel Roskin 	int retval;
412203c4805SLuis R. Rodriguez 	unsigned int len = 0;
413203c4805SLuis R. Rodriguez 	u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
414203c4805SLuis R. Rodriguez 	int i, qcuOffset = 0, dcuOffset = 0;
415203c4805SLuis R. Rodriguez 	u32 *qcuBase = &val[0], *dcuBase = &val[4];
416203c4805SLuis R. Rodriguez 
417991a0987SPavel Roskin 	buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
418991a0987SPavel Roskin 	if (!buf)
41904236066SDan Carpenter 		return -ENOMEM;
420991a0987SPavel Roskin 
4217cf4a2e7SSujith 	ath9k_ps_wakeup(sc);
4227cf4a2e7SSujith 
423475a6e4dSLuis R. Rodriguez 	REG_WRITE_D(ah, AR_MACMISC,
424203c4805SLuis R. Rodriguez 		  ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
425203c4805SLuis R. Rodriguez 		   (AR_MACMISC_MISC_OBS_BUS_1 <<
426203c4805SLuis R. Rodriguez 		    AR_MACMISC_MISC_OBS_BUS_MSB_S)));
427203c4805SLuis R. Rodriguez 
4285e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len,
429203c4805SLuis R. Rodriguez 			 "Raw DMA Debug values:\n");
430203c4805SLuis R. Rodriguez 
431203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
432203c4805SLuis R. Rodriguez 		if (i % 4 == 0)
4335e88ba62SZefir Kurtisi 			len += scnprintf(buf + len, DMA_BUF_LEN - len, "\n");
434203c4805SLuis R. Rodriguez 
435475a6e4dSLuis R. Rodriguez 		val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
4365e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
437203c4805SLuis R. Rodriguez 				 i, val[i]);
438203c4805SLuis R. Rodriguez 	}
439203c4805SLuis R. Rodriguez 
4405e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
4415e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len,
442203c4805SLuis R. Rodriguez 			 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
443203c4805SLuis R. Rodriguez 
444203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
445203c4805SLuis R. Rodriguez 		if (i == 8) {
446203c4805SLuis R. Rodriguez 			qcuOffset = 0;
447203c4805SLuis R. Rodriguez 			qcuBase++;
448203c4805SLuis R. Rodriguez 		}
449203c4805SLuis R. Rodriguez 
450203c4805SLuis R. Rodriguez 		if (i == 6) {
451203c4805SLuis R. Rodriguez 			dcuOffset = 0;
452203c4805SLuis R. Rodriguez 			dcuBase++;
453203c4805SLuis R. Rodriguez 		}
454203c4805SLuis R. Rodriguez 
4555e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, DMA_BUF_LEN - len,
456203c4805SLuis R. Rodriguez 			 "%2d          %2x      %1x     %2x           %2x\n",
457203c4805SLuis R. Rodriguez 			 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
458203c4805SLuis R. Rodriguez 			 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
459203c4805SLuis R. Rodriguez 			 val[2] & (0x7 << (i * 3)) >> (i * 3),
460203c4805SLuis R. Rodriguez 			 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
461203c4805SLuis R. Rodriguez 	}
462203c4805SLuis R. Rodriguez 
4635e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len, "\n");
464203c4805SLuis R. Rodriguez 
4655e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len,
466203c4805SLuis R. Rodriguez 		"qcu_stitch state:   %2x    qcu_fetch state:        %2x\n",
467203c4805SLuis R. Rodriguez 		(val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
4685e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len,
469203c4805SLuis R. Rodriguez 		"qcu_complete state: %2x    dcu_complete state:     %2x\n",
470203c4805SLuis R. Rodriguez 		(val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
4715e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len,
472203c4805SLuis R. Rodriguez 		"dcu_arb state:      %2x    dcu_fp state:           %2x\n",
473203c4805SLuis R. Rodriguez 		(val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
4745e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len,
475203c4805SLuis R. Rodriguez 		"chan_idle_dur:     %3d    chan_idle_dur_valid:     %1d\n",
476203c4805SLuis R. Rodriguez 		(val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
4775e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len,
478203c4805SLuis R. Rodriguez 		"txfifo_valid_0:      %1d    txfifo_valid_1:          %1d\n",
479203c4805SLuis R. Rodriguez 		(val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
4805e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len,
481203c4805SLuis R. Rodriguez 		"txfifo_dcu_num_0:   %2d    txfifo_dcu_num_1:       %2d\n",
482203c4805SLuis R. Rodriguez 		(val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
483203c4805SLuis R. Rodriguez 
4845e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
485475a6e4dSLuis R. Rodriguez 			 REG_READ_D(ah, AR_OBS_BUS_1));
4865e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len,
487475a6e4dSLuis R. Rodriguez 			 "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
488203c4805SLuis R. Rodriguez 
4897cf4a2e7SSujith 	ath9k_ps_restore(sc);
4907cf4a2e7SSujith 
4912b87f3aaSDan Carpenter 	if (len > DMA_BUF_LEN)
4922b87f3aaSDan Carpenter 		len = DMA_BUF_LEN;
4932b87f3aaSDan Carpenter 
494991a0987SPavel Roskin 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
495991a0987SPavel Roskin 	kfree(buf);
496991a0987SPavel Roskin 	return retval;
497203c4805SLuis R. Rodriguez }
498203c4805SLuis R. Rodriguez 
499203c4805SLuis R. Rodriguez static const struct file_operations fops_dma = {
500203c4805SLuis R. Rodriguez 	.read = read_file_dma,
501234e3405SStephen Boyd 	.open = simple_open,
5026038f373SArnd Bergmann 	.owner = THIS_MODULE,
5036038f373SArnd Bergmann 	.llseek = default_llseek,
504203c4805SLuis R. Rodriguez };
505203c4805SLuis R. Rodriguez 
506203c4805SLuis R. Rodriguez 
507203c4805SLuis R. Rodriguez void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
508203c4805SLuis R. Rodriguez {
509203c4805SLuis R. Rodriguez 	if (status)
510203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.total++;
511a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
512a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXLP)
513a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxlp++;
514a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXHP)
515a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxhp++;
51608578b8fSLuis R. Rodriguez 		if (status & ATH9K_INT_BB_WATCHDOG)
51708578b8fSLuis R. Rodriguez 			sc->debug.stats.istats.bb_watchdog++;
518a9616f41SLuis R. Rodriguez 	} else {
519203c4805SLuis R. Rodriguez 		if (status & ATH9K_INT_RX)
520203c4805SLuis R. Rodriguez 			sc->debug.stats.istats.rxok++;
521a9616f41SLuis R. Rodriguez 	}
522203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXEOL)
523203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxeol++;
524203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXORN)
525203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxorn++;
526203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TX)
527203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txok++;
528203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TXURN)
529203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txurn++;
530203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXPHY)
531203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxphyerr++;
532203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXKCM)
533203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rx_keycache_miss++;
534203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_SWBA)
535203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.swba++;
536203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BMISS)
537203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bmiss++;
538203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BNR)
539203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bnr++;
540203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CST)
541203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cst++;
542203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_GTT)
543203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.gtt++;
544203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TIM)
545203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.tim++;
546203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CABEND)
547203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cabend++;
548203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIMSYNC)
549203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtimsync++;
550203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIM)
551203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtim++;
5526dde1aabSMohammed Shafi Shajakhan 	if (status & ATH9K_INT_TSFOOR)
5536dde1aabSMohammed Shafi Shajakhan 		sc->debug.stats.istats.tsfoor++;
55497ba515aSSujith Manoharan 	if (status & ATH9K_INT_MCI)
55597ba515aSSujith Manoharan 		sc->debug.stats.istats.mci++;
556c9e6e980SMohammed Shafi Shajakhan 	if (status & ATH9K_INT_GENTIMER)
557c9e6e980SMohammed Shafi Shajakhan 		sc->debug.stats.istats.gen_timer++;
558203c4805SLuis R. Rodriguez }
559203c4805SLuis R. Rodriguez 
560203c4805SLuis R. Rodriguez static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
561203c4805SLuis R. Rodriguez 				   size_t count, loff_t *ppos)
562203c4805SLuis R. Rodriguez {
563203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
564203c4805SLuis R. Rodriguez 	unsigned int len = 0;
565462e58f2SBen Greear 	int rv;
566462e58f2SBen Greear 	int mxlen = 4000;
567462e58f2SBen Greear 	char *buf = kmalloc(mxlen, GFP_KERNEL);
568462e58f2SBen Greear 	if (!buf)
569462e58f2SBen Greear 		return -ENOMEM;
570462e58f2SBen Greear 
571462e58f2SBen Greear #define PR_IS(a, s)						\
572462e58f2SBen Greear 	do {							\
5735e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, mxlen - len,	\
574462e58f2SBen Greear 				 "%21s: %10u\n", a,		\
575462e58f2SBen Greear 				 sc->debug.stats.istats.s);	\
576462e58f2SBen Greear 	} while (0)
577203c4805SLuis R. Rodriguez 
578a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
579462e58f2SBen Greear 		PR_IS("RXLP", rxlp);
580462e58f2SBen Greear 		PR_IS("RXHP", rxhp);
581462e58f2SBen Greear 		PR_IS("WATHDOG", bb_watchdog);
582a9616f41SLuis R. Rodriguez 	} else {
583462e58f2SBen Greear 		PR_IS("RX", rxok);
584a9616f41SLuis R. Rodriguez 	}
585462e58f2SBen Greear 	PR_IS("RXEOL", rxeol);
586462e58f2SBen Greear 	PR_IS("RXORN", rxorn);
587462e58f2SBen Greear 	PR_IS("TX", txok);
588462e58f2SBen Greear 	PR_IS("TXURN", txurn);
589462e58f2SBen Greear 	PR_IS("MIB", mib);
590462e58f2SBen Greear 	PR_IS("RXPHY", rxphyerr);
591462e58f2SBen Greear 	PR_IS("RXKCM", rx_keycache_miss);
592462e58f2SBen Greear 	PR_IS("SWBA", swba);
593462e58f2SBen Greear 	PR_IS("BMISS", bmiss);
594462e58f2SBen Greear 	PR_IS("BNR", bnr);
595462e58f2SBen Greear 	PR_IS("CST", cst);
596462e58f2SBen Greear 	PR_IS("GTT", gtt);
597462e58f2SBen Greear 	PR_IS("TIM", tim);
598462e58f2SBen Greear 	PR_IS("CABEND", cabend);
599462e58f2SBen Greear 	PR_IS("DTIMSYNC", dtimsync);
600462e58f2SBen Greear 	PR_IS("DTIM", dtim);
601462e58f2SBen Greear 	PR_IS("TSFOOR", tsfoor);
60297ba515aSSujith Manoharan 	PR_IS("MCI", mci);
603c9e6e980SMohammed Shafi Shajakhan 	PR_IS("GENTIMER", gen_timer);
604462e58f2SBen Greear 	PR_IS("TOTAL", total);
605203c4805SLuis R. Rodriguez 
6065e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, mxlen - len,
607462e58f2SBen Greear 			 "SYNC_CAUSE stats:\n");
6086dde1aabSMohammed Shafi Shajakhan 
609462e58f2SBen Greear 	PR_IS("Sync-All", sync_cause_all);
610462e58f2SBen Greear 	PR_IS("RTC-IRQ", sync_rtc_irq);
611462e58f2SBen Greear 	PR_IS("MAC-IRQ", sync_mac_irq);
612462e58f2SBen Greear 	PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
613462e58f2SBen Greear 	PR_IS("APB-Timeout", apb_timeout);
614462e58f2SBen Greear 	PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
615462e58f2SBen Greear 	PR_IS("HOST1-Fatal", host1_fatal);
616462e58f2SBen Greear 	PR_IS("HOST1-Perr", host1_perr);
617462e58f2SBen Greear 	PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
618462e58f2SBen Greear 	PR_IS("RADM-CPL-EP", radm_cpl_ep);
619462e58f2SBen Greear 	PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
620462e58f2SBen Greear 	PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
621462e58f2SBen Greear 	PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
622462e58f2SBen Greear 	PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
623462e58f2SBen Greear 	PR_IS("Local-Bus-Timeout", local_timeout);
624462e58f2SBen Greear 	PR_IS("PM-Access", pm_access);
625462e58f2SBen Greear 	PR_IS("MAC-Awake", mac_awake);
626462e58f2SBen Greear 	PR_IS("MAC-Asleep", mac_asleep);
627462e58f2SBen Greear 	PR_IS("MAC-Sleep-Access", mac_sleep_access);
6282b87f3aaSDan Carpenter 
629462e58f2SBen Greear 	if (len > mxlen)
630462e58f2SBen Greear 		len = mxlen;
631462e58f2SBen Greear 
632462e58f2SBen Greear 	rv = simple_read_from_buffer(user_buf, count, ppos, buf, len);
633462e58f2SBen Greear 	kfree(buf);
634462e58f2SBen Greear 	return rv;
635203c4805SLuis R. Rodriguez }
636203c4805SLuis R. Rodriguez 
637203c4805SLuis R. Rodriguez static const struct file_operations fops_interrupt = {
638203c4805SLuis R. Rodriguez 	.read = read_file_interrupt,
639234e3405SStephen Boyd 	.open = simple_open,
6406038f373SArnd Bergmann 	.owner = THIS_MODULE,
6416038f373SArnd Bergmann 	.llseek = default_llseek,
642203c4805SLuis R. Rodriguez };
643203c4805SLuis R. Rodriguez 
644fec247c0SSujith static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
645fec247c0SSujith 			      size_t count, loff_t *ppos)
646fec247c0SSujith {
647fec247c0SSujith 	struct ath_softc *sc = file->private_data;
648fec247c0SSujith 	char *buf;
64978ef731cSSujith Manoharan 	unsigned int len = 0, size = 2048;
650fec247c0SSujith 	ssize_t retval = 0;
651fec247c0SSujith 
652fec247c0SSujith 	buf = kzalloc(size, GFP_KERNEL);
653fec247c0SSujith 	if (buf == NULL)
65404236066SDan Carpenter 		return -ENOMEM;
655fec247c0SSujith 
65678ef731cSSujith Manoharan 	len += sprintf(buf, "%30s %10s%10s%10s\n\n",
6577f010c93SBen Greear 		       "BE", "BK", "VI", "VO");
658fec247c0SSujith 
659fec247c0SSujith 	PR("MPDUs Queued:    ", queued);
660fec247c0SSujith 	PR("MPDUs Completed: ", completed);
6615a6f78afSFelix Fietkau 	PR("MPDUs XRetried:  ", xretries);
662fec247c0SSujith 	PR("Aggregates:      ", a_aggr);
663bda8addaSBen Greear 	PR("AMPDUs Queued HW:", a_queued_hw);
664bda8addaSBen Greear 	PR("AMPDUs Queued SW:", a_queued_sw);
665fec247c0SSujith 	PR("AMPDUs Completed:", a_completed);
666fec247c0SSujith 	PR("AMPDUs Retried:  ", a_retries);
667fec247c0SSujith 	PR("AMPDUs XRetried: ", a_xretries);
6684d900389SBen Greear 	PR("TXERR Filtered:  ", txerr_filtered);
669fec247c0SSujith 	PR("FIFO Underrun:   ", fifo_underrun);
670fec247c0SSujith 	PR("TXOP Exceeded:   ", xtxop);
671fec247c0SSujith 	PR("TXTIMER Expiry:  ", timer_exp);
672fec247c0SSujith 	PR("DESC CFG Error:  ", desc_cfg_err);
673fec247c0SSujith 	PR("DATA Underrun:   ", data_underrun);
674fec247c0SSujith 	PR("DELIM Underrun:  ", delim_underrun);
67599c15bf5SBen Greear 	PR("TX-Pkts-All:     ", tx_pkts_all);
67699c15bf5SBen Greear 	PR("TX-Bytes-All:    ", tx_bytes_all);
67778ef731cSSujith Manoharan 	PR("HW-put-tx-buf:   ", puttxbuf);
67878ef731cSSujith Manoharan 	PR("HW-tx-start:     ", txstart);
67978ef731cSSujith Manoharan 	PR("HW-tx-proc-desc: ", txprocdesc);
680a5a0bca1SBen Greear 	PR("TX-Failed:       ", txfailed);
681fec247c0SSujith 
6827f010c93SBen Greear 	if (len > size)
6837f010c93SBen Greear 		len = size;
6847f010c93SBen Greear 
6857f010c93SBen Greear 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
6867f010c93SBen Greear 	kfree(buf);
6877f010c93SBen Greear 
6887f010c93SBen Greear 	return retval;
6897f010c93SBen Greear }
6907f010c93SBen Greear 
69118fcf1c6SFelix Fietkau static ssize_t print_queue(struct ath_softc *sc, struct ath_txq *txq,
69218fcf1c6SFelix Fietkau 			   char *buf, ssize_t size)
69318fcf1c6SFelix Fietkau {
69418fcf1c6SFelix Fietkau 	ssize_t len = 0;
69518fcf1c6SFelix Fietkau 
69618fcf1c6SFelix Fietkau 	ath_txq_lock(sc, txq);
69718fcf1c6SFelix Fietkau 
6985e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%s: %d ",
69918fcf1c6SFelix Fietkau 			 "qnum", txq->axq_qnum);
7005e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%s: %2d ",
70118fcf1c6SFelix Fietkau 			 "qdepth", txq->axq_depth);
7025e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%s: %2d ",
70318fcf1c6SFelix Fietkau 			 "ampdu-depth", txq->axq_ampdu_depth);
7045e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%s: %3d ",
70518fcf1c6SFelix Fietkau 			 "pending", txq->pending_frames);
7065e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%s: %d\n",
70718fcf1c6SFelix Fietkau 			 "stopped", txq->stopped);
70818fcf1c6SFelix Fietkau 
70918fcf1c6SFelix Fietkau 	ath_txq_unlock(sc, txq);
71018fcf1c6SFelix Fietkau 	return len;
71118fcf1c6SFelix Fietkau }
71218fcf1c6SFelix Fietkau 
713c0b74876SSujith Manoharan static ssize_t read_file_queues(struct file *file, char __user *user_buf,
714c0b74876SSujith Manoharan 				size_t count, loff_t *ppos)
715c0b74876SSujith Manoharan {
716c0b74876SSujith Manoharan 	struct ath_softc *sc = file->private_data;
717c0b74876SSujith Manoharan 	struct ath_txq *txq;
718c0b74876SSujith Manoharan 	char *buf;
719c0b74876SSujith Manoharan 	unsigned int len = 0, size = 1024;
720c0b74876SSujith Manoharan 	ssize_t retval = 0;
721c0b74876SSujith Manoharan 	int i;
722c0b74876SSujith Manoharan 	char *qname[4] = {"VO", "VI", "BE", "BK"};
723c0b74876SSujith Manoharan 
724c0b74876SSujith Manoharan 	buf = kzalloc(size, GFP_KERNEL);
725c0b74876SSujith Manoharan 	if (buf == NULL)
726c0b74876SSujith Manoharan 		return -ENOMEM;
727c0b74876SSujith Manoharan 
728c0b74876SSujith Manoharan 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
729c0b74876SSujith Manoharan 		txq = sc->tx.txq_map[i];
7305e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, size - len, "(%s):  ", qname[i]);
73118fcf1c6SFelix Fietkau 		len += print_queue(sc, txq, buf + len, size - len);
732c0b74876SSujith Manoharan 	}
733c0b74876SSujith Manoharan 
7345e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "(CAB): ");
73518fcf1c6SFelix Fietkau 	len += print_queue(sc, sc->beacon.cabq, buf + len, size - len);
73618fcf1c6SFelix Fietkau 
737c0b74876SSujith Manoharan 	if (len > size)
738c0b74876SSujith Manoharan 		len = size;
739c0b74876SSujith Manoharan 
740c0b74876SSujith Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
741c0b74876SSujith Manoharan 	kfree(buf);
742c0b74876SSujith Manoharan 
743c0b74876SSujith Manoharan 	return retval;
744c0b74876SSujith Manoharan }
745c0b74876SSujith Manoharan 
74655f6d0ffSBen Greear static ssize_t read_file_misc(struct file *file, char __user *user_buf,
74755f6d0ffSBen Greear 			      size_t count, loff_t *ppos)
74855f6d0ffSBen Greear {
74955f6d0ffSBen Greear 	struct ath_softc *sc = file->private_data;
75055f6d0ffSBen Greear 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
75155f6d0ffSBen Greear 	struct ieee80211_hw *hw = sc->hw;
7526bcf6f64SSujith Manoharan 	struct ath9k_vif_iter_data iter_data;
7536bcf6f64SSujith Manoharan 	char buf[512];
7546bcf6f64SSujith Manoharan 	unsigned int len = 0;
75555f6d0ffSBen Greear 	ssize_t retval = 0;
75655f6d0ffSBen Greear 	unsigned int reg;
7576bcf6f64SSujith Manoharan 	u32 rxfilter;
7586bcf6f64SSujith Manoharan 
7595e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
7606bcf6f64SSujith Manoharan 			 "BSSID: %pM\n", common->curbssid);
7615e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
7626bcf6f64SSujith Manoharan 			 "BSSID-MASK: %pM\n", common->bssidmask);
7635e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
7645e88ba62SZefir Kurtisi 			 "OPMODE: %s\n",
7655e88ba62SZefir Kurtisi 			 ath_opmode_to_string(sc->sc_ah->opmode));
7666bcf6f64SSujith Manoharan 
7676bcf6f64SSujith Manoharan 	ath9k_ps_wakeup(sc);
7686bcf6f64SSujith Manoharan 	rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
7696bcf6f64SSujith Manoharan 	ath9k_ps_restore(sc);
7706bcf6f64SSujith Manoharan 
7715e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
7726bcf6f64SSujith Manoharan 			 "RXFILTER: 0x%x", rxfilter);
7736bcf6f64SSujith Manoharan 
7746bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_UCAST)
7755e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " UCAST");
7766bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MCAST)
7775e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " MCAST");
7786bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_BCAST)
7795e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " BCAST");
7806bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_CONTROL)
7815e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " CONTROL");
7826bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_BEACON)
7835e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " BEACON");
7846bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PROM)
7855e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " PROM");
7866bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
7875e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
7886bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PHYERR)
7895e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " PHYERR");
7906bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
7915e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " MYBEACON");
7926bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
7935e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
7946bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
7955e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " PSPOLL");
7966bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
7975e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
7986bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
7995e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL");
8006bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
8015e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " CONTROL_WRAPPER");
8026bcf6f64SSujith Manoharan 
8035e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len, "\n");
8046bcf6f64SSujith Manoharan 
8056bcf6f64SSujith Manoharan 	reg = sc->sc_ah->imask;
8066bcf6f64SSujith Manoharan 
8075e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
8085e88ba62SZefir Kurtisi 			 "INTERRUPT-MASK: 0x%x", reg);
8096bcf6f64SSujith Manoharan 
8106bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_SWBA)
8115e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " SWBA");
8126bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_BMISS)
8135e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " BMISS");
8146bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_CST)
8155e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " CST");
8166bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RX)
8175e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " RX");
8186bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RXHP)
8195e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " RXHP");
8206bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RXLP)
8215e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " RXLP");
8226bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_BB_WATCHDOG)
8235e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " BB_WATCHDOG");
8246bcf6f64SSujith Manoharan 
8255e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len, "\n");
82655f6d0ffSBen Greear 
82755f6d0ffSBen Greear 	ath9k_calculate_iter_data(hw, NULL, &iter_data);
82855f6d0ffSBen Greear 
8295e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
8306bcf6f64SSujith Manoharan 			 "VIF-COUNTS: AP: %i STA: %i MESH: %i WDS: %i"
831bcf6f96eSSujith Manoharan 			 " ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n",
83255f6d0ffSBen Greear 			 iter_data.naps, iter_data.nstations, iter_data.nmeshes,
833bcf6f96eSSujith Manoharan 			 iter_data.nwds, iter_data.nadhocs,
83455f6d0ffSBen Greear 			 sc->nvifs, sc->nbcnvifs);
83555f6d0ffSBen Greear 
8366bcf6f64SSujith Manoharan 	if (len > sizeof(buf))
8376bcf6f64SSujith Manoharan 		len = sizeof(buf);
83855f6d0ffSBen Greear 
83955f6d0ffSBen Greear 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
84055f6d0ffSBen Greear 	return retval;
84155f6d0ffSBen Greear }
84255f6d0ffSBen Greear 
843f8b815dcSSujith Manoharan static ssize_t read_file_reset(struct file *file, char __user *user_buf,
844f8b815dcSSujith Manoharan 			       size_t count, loff_t *ppos)
845f8b815dcSSujith Manoharan {
846f8b815dcSSujith Manoharan 	struct ath_softc *sc = file->private_data;
847f8b815dcSSujith Manoharan 	char buf[512];
848f8b815dcSSujith Manoharan 	unsigned int len = 0;
849f8b815dcSSujith Manoharan 
8505e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
851f8b815dcSSujith Manoharan 			 "%17s: %2d\n", "Baseband Hang",
852f8b815dcSSujith Manoharan 			 sc->debug.stats.reset[RESET_TYPE_BB_HANG]);
8535e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
854f8b815dcSSujith Manoharan 			 "%17s: %2d\n", "Baseband Watchdog",
855f8b815dcSSujith Manoharan 			 sc->debug.stats.reset[RESET_TYPE_BB_WATCHDOG]);
8565e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
857f8b815dcSSujith Manoharan 			 "%17s: %2d\n", "Fatal HW Error",
858f8b815dcSSujith Manoharan 			 sc->debug.stats.reset[RESET_TYPE_FATAL_INT]);
8595e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
860f8b815dcSSujith Manoharan 			 "%17s: %2d\n", "TX HW error",
861f8b815dcSSujith Manoharan 			 sc->debug.stats.reset[RESET_TYPE_TX_ERROR]);
8625e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
863f8b815dcSSujith Manoharan 			 "%17s: %2d\n", "TX Path Hang",
864f8b815dcSSujith Manoharan 			 sc->debug.stats.reset[RESET_TYPE_TX_HANG]);
8655e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
866f8b815dcSSujith Manoharan 			 "%17s: %2d\n", "PLL RX Hang",
867f8b815dcSSujith Manoharan 			 sc->debug.stats.reset[RESET_TYPE_PLL_HANG]);
8685e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
869b88083bfSRajkumar Manoharan 			 "%17s: %2d\n", "MCI Reset",
870b88083bfSRajkumar Manoharan 			 sc->debug.stats.reset[RESET_TYPE_MCI]);
871f8b815dcSSujith Manoharan 
872f8b815dcSSujith Manoharan 	if (len > sizeof(buf))
873f8b815dcSSujith Manoharan 		len = sizeof(buf);
874f8b815dcSSujith Manoharan 
875f8b815dcSSujith Manoharan 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
876f8b815dcSSujith Manoharan }
877f8b815dcSSujith Manoharan 
878066dae93SFelix Fietkau void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
87955797b1aSFelix Fietkau 		       struct ath_tx_status *ts, struct ath_txq *txq,
88055797b1aSFelix Fietkau 		       unsigned int flags)
881fec247c0SSujith {
8825bec3e5aSFelix Fietkau 	int qnum = txq->axq_qnum;
883066dae93SFelix Fietkau 
884066dae93SFelix Fietkau 	TX_STAT_INC(qnum, tx_pkts_all);
885066dae93SFelix Fietkau 	sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
88699c15bf5SBen Greear 
887fec247c0SSujith 	if (bf_isampdu(bf)) {
888156369faSFelix Fietkau 		if (flags & ATH_TX_ERROR)
889066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_xretries);
890fec247c0SSujith 		else
891066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_completed);
892fec247c0SSujith 	} else {
89355797b1aSFelix Fietkau 		if (ts->ts_status & ATH9K_TXERR_XRETRY)
8945a6f78afSFelix Fietkau 			TX_STAT_INC(qnum, xretries);
8955a6f78afSFelix Fietkau 		else
896066dae93SFelix Fietkau 			TX_STAT_INC(qnum, completed);
897fec247c0SSujith 	}
898fec247c0SSujith 
8994d900389SBen Greear 	if (ts->ts_status & ATH9K_TXERR_FILT)
9004d900389SBen Greear 		TX_STAT_INC(qnum, txerr_filtered);
901db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_FIFO)
902066dae93SFelix Fietkau 		TX_STAT_INC(qnum, fifo_underrun);
903db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_XTXOP)
904066dae93SFelix Fietkau 		TX_STAT_INC(qnum, xtxop);
905db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
906066dae93SFelix Fietkau 		TX_STAT_INC(qnum, timer_exp);
907db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
908066dae93SFelix Fietkau 		TX_STAT_INC(qnum, desc_cfg_err);
909db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
910066dae93SFelix Fietkau 		TX_STAT_INC(qnum, data_underrun);
911db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
912066dae93SFelix Fietkau 		TX_STAT_INC(qnum, delim_underrun);
913fec247c0SSujith }
914fec247c0SSujith 
915fec247c0SSujith static const struct file_operations fops_xmit = {
916fec247c0SSujith 	.read = read_file_xmit,
917234e3405SStephen Boyd 	.open = simple_open,
9186038f373SArnd Bergmann 	.owner = THIS_MODULE,
9196038f373SArnd Bergmann 	.llseek = default_llseek,
920fec247c0SSujith };
921203c4805SLuis R. Rodriguez 
922c0b74876SSujith Manoharan static const struct file_operations fops_queues = {
923c0b74876SSujith Manoharan 	.read = read_file_queues,
924c0b74876SSujith Manoharan 	.open = simple_open,
925c0b74876SSujith Manoharan 	.owner = THIS_MODULE,
926c0b74876SSujith Manoharan 	.llseek = default_llseek,
927c0b74876SSujith Manoharan };
928c0b74876SSujith Manoharan 
92955f6d0ffSBen Greear static const struct file_operations fops_misc = {
93055f6d0ffSBen Greear 	.read = read_file_misc,
931234e3405SStephen Boyd 	.open = simple_open,
93255f6d0ffSBen Greear 	.owner = THIS_MODULE,
93355f6d0ffSBen Greear 	.llseek = default_llseek,
93455f6d0ffSBen Greear };
93555f6d0ffSBen Greear 
936f8b815dcSSujith Manoharan static const struct file_operations fops_reset = {
937f8b815dcSSujith Manoharan 	.read = read_file_reset,
938234e3405SStephen Boyd 	.open = simple_open,
939f8b815dcSSujith Manoharan 	.owner = THIS_MODULE,
940f8b815dcSSujith Manoharan 	.llseek = default_llseek,
941f8b815dcSSujith Manoharan };
942f8b815dcSSujith Manoharan 
9431395d3f0SSujith static ssize_t read_file_recv(struct file *file, char __user *user_buf,
9441395d3f0SSujith 			      size_t count, loff_t *ppos)
9451395d3f0SSujith {
9461395d3f0SSujith #define PHY_ERR(s, p) \
9475e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%22s : %10u\n", s, \
9481395d3f0SSujith 			 sc->debug.stats.rxstats.phy_err_stats[p]);
9491395d3f0SSujith 
95024a0731eSBen Greear #define RXS_ERR(s, e)					    \
95124a0731eSBen Greear 	do {						    \
9525e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, size - len,	    \
95324a0731eSBen Greear 				 "%22s : %10u\n", s,	    \
95424a0731eSBen Greear 				 sc->debug.stats.rxstats.e);\
95524a0731eSBen Greear 	} while (0)
95624a0731eSBen Greear 
9571395d3f0SSujith 	struct ath_softc *sc = file->private_data;
9581395d3f0SSujith 	char *buf;
9594203214eSSujith Manoharan 	unsigned int len = 0, size = 1600;
9601395d3f0SSujith 	ssize_t retval = 0;
9611395d3f0SSujith 
9621395d3f0SSujith 	buf = kzalloc(size, GFP_KERNEL);
9631395d3f0SSujith 	if (buf == NULL)
96404236066SDan Carpenter 		return -ENOMEM;
9651395d3f0SSujith 
96624a0731eSBen Greear 	RXS_ERR("CRC ERR", crc_err);
96724a0731eSBen Greear 	RXS_ERR("DECRYPT CRC ERR", decrypt_crc_err);
96824a0731eSBen Greear 	RXS_ERR("PHY ERR", phy_err);
96924a0731eSBen Greear 	RXS_ERR("MIC ERR", mic_err);
97024a0731eSBen Greear 	RXS_ERR("PRE-DELIM CRC ERR", pre_delim_crc_err);
97124a0731eSBen Greear 	RXS_ERR("POST-DELIM CRC ERR", post_delim_crc_err);
97224a0731eSBen Greear 	RXS_ERR("DECRYPT BUSY ERR", decrypt_busy_err);
97324a0731eSBen Greear 	RXS_ERR("RX-LENGTH-ERR", rx_len_err);
97424a0731eSBen Greear 	RXS_ERR("RX-OOM-ERR", rx_oom_err);
97524a0731eSBen Greear 	RXS_ERR("RX-RATE-ERR", rx_rate_err);
97624a0731eSBen Greear 	RXS_ERR("RX-TOO-MANY-FRAGS", rx_too_many_frags_err);
9771395d3f0SSujith 
9784203214eSSujith Manoharan 	PHY_ERR("UNDERRUN ERR", ATH9K_PHYERR_UNDERRUN);
9794203214eSSujith Manoharan 	PHY_ERR("TIMING ERR", ATH9K_PHYERR_TIMING);
9804203214eSSujith Manoharan 	PHY_ERR("PARITY ERR", ATH9K_PHYERR_PARITY);
9814203214eSSujith Manoharan 	PHY_ERR("RATE ERR", ATH9K_PHYERR_RATE);
9824203214eSSujith Manoharan 	PHY_ERR("LENGTH ERR", ATH9K_PHYERR_LENGTH);
9834203214eSSujith Manoharan 	PHY_ERR("RADAR ERR", ATH9K_PHYERR_RADAR);
9844203214eSSujith Manoharan 	PHY_ERR("SERVICE ERR", ATH9K_PHYERR_SERVICE);
9854203214eSSujith Manoharan 	PHY_ERR("TOR ERR", ATH9K_PHYERR_TOR);
9864203214eSSujith Manoharan 	PHY_ERR("OFDM-TIMING ERR", ATH9K_PHYERR_OFDM_TIMING);
9874203214eSSujith Manoharan 	PHY_ERR("OFDM-SIGNAL-PARITY ERR", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
9884203214eSSujith Manoharan 	PHY_ERR("OFDM-RATE ERR", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
9894203214eSSujith Manoharan 	PHY_ERR("OFDM-LENGTH ERR", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
9904203214eSSujith Manoharan 	PHY_ERR("OFDM-POWER-DROP ERR", ATH9K_PHYERR_OFDM_POWER_DROP);
9914203214eSSujith Manoharan 	PHY_ERR("OFDM-SERVICE ERR", ATH9K_PHYERR_OFDM_SERVICE);
9924203214eSSujith Manoharan 	PHY_ERR("OFDM-RESTART ERR", ATH9K_PHYERR_OFDM_RESTART);
9934203214eSSujith Manoharan 	PHY_ERR("FALSE-RADAR-EXT ERR", ATH9K_PHYERR_FALSE_RADAR_EXT);
9944203214eSSujith Manoharan 	PHY_ERR("CCK-TIMING ERR", ATH9K_PHYERR_CCK_TIMING);
9954203214eSSujith Manoharan 	PHY_ERR("CCK-HEADER-CRC ERR", ATH9K_PHYERR_CCK_HEADER_CRC);
9964203214eSSujith Manoharan 	PHY_ERR("CCK-RATE ERR", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
9974203214eSSujith Manoharan 	PHY_ERR("CCK-SERVICE ERR", ATH9K_PHYERR_CCK_SERVICE);
9984203214eSSujith Manoharan 	PHY_ERR("CCK-RESTART ERR", ATH9K_PHYERR_CCK_RESTART);
9994203214eSSujith Manoharan 	PHY_ERR("CCK-LENGTH ERR", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
10004203214eSSujith Manoharan 	PHY_ERR("CCK-POWER-DROP ERR", ATH9K_PHYERR_CCK_POWER_DROP);
10014203214eSSujith Manoharan 	PHY_ERR("HT-CRC ERR", ATH9K_PHYERR_HT_CRC_ERROR);
10024203214eSSujith Manoharan 	PHY_ERR("HT-LENGTH ERR", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
10034203214eSSujith Manoharan 	PHY_ERR("HT-RATE ERR", ATH9K_PHYERR_HT_RATE_ILLEGAL);
10044203214eSSujith Manoharan 
100524a0731eSBen Greear 	RXS_ERR("RX-Pkts-All", rx_pkts_all);
100624a0731eSBen Greear 	RXS_ERR("RX-Bytes-All", rx_bytes_all);
100724a0731eSBen Greear 	RXS_ERR("RX-Beacons", rx_beacons);
100824a0731eSBen Greear 	RXS_ERR("RX-Frags", rx_frags);
10099b99e665SSimon Wunderlich 	RXS_ERR("RX-Spectral", rx_spectral);
101099c15bf5SBen Greear 
10112b87f3aaSDan Carpenter 	if (len > size)
10122b87f3aaSDan Carpenter 		len = size;
10132b87f3aaSDan Carpenter 
10141395d3f0SSujith 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
10151395d3f0SSujith 	kfree(buf);
10161395d3f0SSujith 
10171395d3f0SSujith 	return retval;
10181395d3f0SSujith 
101924a0731eSBen Greear #undef RXS_ERR
10201395d3f0SSujith #undef PHY_ERR
10211395d3f0SSujith }
10221395d3f0SSujith 
10238e6f5aa2SFelix Fietkau void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
10241395d3f0SSujith {
10251395d3f0SSujith #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
10261395d3f0SSujith 
102799c15bf5SBen Greear 	RX_STAT_INC(rx_pkts_all);
102899c15bf5SBen Greear 	sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
102999c15bf5SBen Greear 
10308e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_CRC)
10311395d3f0SSujith 		RX_STAT_INC(crc_err);
10328e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_DECRYPT)
10331395d3f0SSujith 		RX_STAT_INC(decrypt_crc_err);
10348e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_MIC)
10351395d3f0SSujith 		RX_STAT_INC(mic_err);
10368e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
10371395d3f0SSujith 		RX_STAT_INC(pre_delim_crc_err);
10388e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
10391395d3f0SSujith 		RX_STAT_INC(post_delim_crc_err);
10408e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
10411395d3f0SSujith 		RX_STAT_INC(decrypt_busy_err);
10421395d3f0SSujith 
10438e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_PHY) {
10441395d3f0SSujith 		RX_STAT_INC(phy_err);
1045dbb07f00SSujith Manoharan 		if (rs->rs_phyerr < ATH9K_PHYERR_MAX)
1046dbb07f00SSujith Manoharan 			RX_PHY_ERR_INC(rs->rs_phyerr);
10471395d3f0SSujith 	}
10481395d3f0SSujith 
10491395d3f0SSujith #undef RX_PHY_ERR_INC
10501395d3f0SSujith }
10511395d3f0SSujith 
10521395d3f0SSujith static const struct file_operations fops_recv = {
10531395d3f0SSujith 	.read = read_file_recv,
1054234e3405SStephen Boyd 	.open = simple_open,
10556038f373SArnd Bergmann 	.owner = THIS_MODULE,
10566038f373SArnd Bergmann 	.llseek = default_llseek,
10571395d3f0SSujith };
10581395d3f0SSujith 
10599bff0bc4SFelix Fietkau static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
10609bff0bc4SFelix Fietkau                                 size_t count, loff_t *ppos)
10619bff0bc4SFelix Fietkau {
10629bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
10639bff0bc4SFelix Fietkau 	char buf[32];
10649bff0bc4SFelix Fietkau 	unsigned int len;
10659bff0bc4SFelix Fietkau 
10662b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
10679bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
10689bff0bc4SFelix Fietkau }
10699bff0bc4SFelix Fietkau 
10709bff0bc4SFelix Fietkau static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
10719bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
10729bff0bc4SFelix Fietkau {
10739bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
10749bff0bc4SFelix Fietkau 	unsigned long regidx;
10759bff0bc4SFelix Fietkau 	char buf[32];
10769bff0bc4SFelix Fietkau 	ssize_t len;
10779bff0bc4SFelix Fietkau 
10789bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
10799bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
108004236066SDan Carpenter 		return -EFAULT;
10819bff0bc4SFelix Fietkau 
10829bff0bc4SFelix Fietkau 	buf[len] = '\0';
108327d7f477SJingoo Han 	if (kstrtoul(buf, 0, &regidx))
10849bff0bc4SFelix Fietkau 		return -EINVAL;
10859bff0bc4SFelix Fietkau 
10869bff0bc4SFelix Fietkau 	sc->debug.regidx = regidx;
10879bff0bc4SFelix Fietkau 	return count;
10889bff0bc4SFelix Fietkau }
10899bff0bc4SFelix Fietkau 
10909bff0bc4SFelix Fietkau static const struct file_operations fops_regidx = {
10919bff0bc4SFelix Fietkau 	.read = read_file_regidx,
10929bff0bc4SFelix Fietkau 	.write = write_file_regidx,
1093234e3405SStephen Boyd 	.open = simple_open,
10946038f373SArnd Bergmann 	.owner = THIS_MODULE,
10956038f373SArnd Bergmann 	.llseek = default_llseek,
10969bff0bc4SFelix Fietkau };
10979bff0bc4SFelix Fietkau 
10989bff0bc4SFelix Fietkau static ssize_t read_file_regval(struct file *file, char __user *user_buf,
10999bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
11009bff0bc4SFelix Fietkau {
11019bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
11029bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
11039bff0bc4SFelix Fietkau 	char buf[32];
11049bff0bc4SFelix Fietkau 	unsigned int len;
11059bff0bc4SFelix Fietkau 	u32 regval;
11069bff0bc4SFelix Fietkau 
110779d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
11089bff0bc4SFelix Fietkau 	regval = REG_READ_D(ah, sc->debug.regidx);
110979d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
11102b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", regval);
11119bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
11129bff0bc4SFelix Fietkau }
11139bff0bc4SFelix Fietkau 
11149bff0bc4SFelix Fietkau static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
11159bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
11169bff0bc4SFelix Fietkau {
11179bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
11189bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
11199bff0bc4SFelix Fietkau 	unsigned long regval;
11209bff0bc4SFelix Fietkau 	char buf[32];
11219bff0bc4SFelix Fietkau 	ssize_t len;
11229bff0bc4SFelix Fietkau 
11239bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
11249bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
112504236066SDan Carpenter 		return -EFAULT;
11269bff0bc4SFelix Fietkau 
11279bff0bc4SFelix Fietkau 	buf[len] = '\0';
112827d7f477SJingoo Han 	if (kstrtoul(buf, 0, &regval))
11299bff0bc4SFelix Fietkau 		return -EINVAL;
11309bff0bc4SFelix Fietkau 
113179d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
11329bff0bc4SFelix Fietkau 	REG_WRITE_D(ah, sc->debug.regidx, regval);
113379d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
11349bff0bc4SFelix Fietkau 	return count;
11359bff0bc4SFelix Fietkau }
11369bff0bc4SFelix Fietkau 
11379bff0bc4SFelix Fietkau static const struct file_operations fops_regval = {
11389bff0bc4SFelix Fietkau 	.read = read_file_regval,
11399bff0bc4SFelix Fietkau 	.write = write_file_regval,
1140234e3405SStephen Boyd 	.open = simple_open,
11416038f373SArnd Bergmann 	.owner = THIS_MODULE,
11426038f373SArnd Bergmann 	.llseek = default_llseek,
11439bff0bc4SFelix Fietkau };
11449bff0bc4SFelix Fietkau 
1145582d0064SVasanthakumar Thiagarajan #define REGDUMP_LINE_SIZE	20
1146582d0064SVasanthakumar Thiagarajan 
1147582d0064SVasanthakumar Thiagarajan static int open_file_regdump(struct inode *inode, struct file *file)
1148582d0064SVasanthakumar Thiagarajan {
1149582d0064SVasanthakumar Thiagarajan 	struct ath_softc *sc = inode->i_private;
1150582d0064SVasanthakumar Thiagarajan 	unsigned int len = 0;
1151582d0064SVasanthakumar Thiagarajan 	u8 *buf;
1152582d0064SVasanthakumar Thiagarajan 	int i;
1153582d0064SVasanthakumar Thiagarajan 	unsigned long num_regs, regdump_len, max_reg_offset;
1154582d0064SVasanthakumar Thiagarajan 
1155582d0064SVasanthakumar Thiagarajan 	max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
1156582d0064SVasanthakumar Thiagarajan 	num_regs = max_reg_offset / 4 + 1;
1157582d0064SVasanthakumar Thiagarajan 	regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
1158582d0064SVasanthakumar Thiagarajan 	buf = vmalloc(regdump_len);
1159582d0064SVasanthakumar Thiagarajan 	if (!buf)
1160582d0064SVasanthakumar Thiagarajan 		return -ENOMEM;
1161582d0064SVasanthakumar Thiagarajan 
1162582d0064SVasanthakumar Thiagarajan 	ath9k_ps_wakeup(sc);
1163582d0064SVasanthakumar Thiagarajan 	for (i = 0; i < num_regs; i++)
1164582d0064SVasanthakumar Thiagarajan 		len += scnprintf(buf + len, regdump_len - len,
1165582d0064SVasanthakumar Thiagarajan 			"0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
1166582d0064SVasanthakumar Thiagarajan 	ath9k_ps_restore(sc);
1167582d0064SVasanthakumar Thiagarajan 
1168582d0064SVasanthakumar Thiagarajan 	file->private_data = buf;
1169582d0064SVasanthakumar Thiagarajan 
1170582d0064SVasanthakumar Thiagarajan 	return 0;
1171582d0064SVasanthakumar Thiagarajan }
1172582d0064SVasanthakumar Thiagarajan 
1173582d0064SVasanthakumar Thiagarajan static const struct file_operations fops_regdump = {
1174582d0064SVasanthakumar Thiagarajan 	.open = open_file_regdump,
1175582d0064SVasanthakumar Thiagarajan 	.read = ath9k_debugfs_read_buf,
1176582d0064SVasanthakumar Thiagarajan 	.release = ath9k_debugfs_release_buf,
1177582d0064SVasanthakumar Thiagarajan 	.owner = THIS_MODULE,
1178582d0064SVasanthakumar Thiagarajan 	.llseek = default_llseek,/* read accesses f_pos */
1179582d0064SVasanthakumar Thiagarajan };
1180582d0064SVasanthakumar Thiagarajan 
1181d069a46bSRajkumar Manoharan static ssize_t read_file_dump_nfcal(struct file *file, char __user *user_buf,
1182d069a46bSRajkumar Manoharan 				    size_t count, loff_t *ppos)
1183d069a46bSRajkumar Manoharan {
1184d069a46bSRajkumar Manoharan 	struct ath_softc *sc = file->private_data;
1185d069a46bSRajkumar Manoharan 	struct ath_hw *ah = sc->sc_ah;
1186d069a46bSRajkumar Manoharan 	struct ath9k_nfcal_hist *h = sc->caldata.nfCalHist;
1187d069a46bSRajkumar Manoharan 	struct ath_common *common = ath9k_hw_common(ah);
1188d069a46bSRajkumar Manoharan 	struct ieee80211_conf *conf = &common->hw->conf;
1189d069a46bSRajkumar Manoharan 	u32 len = 0, size = 1500;
1190d069a46bSRajkumar Manoharan 	u32 i, j;
1191d069a46bSRajkumar Manoharan 	ssize_t retval = 0;
1192d069a46bSRajkumar Manoharan 	char *buf;
1193d069a46bSRajkumar Manoharan 	u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1194d069a46bSRajkumar Manoharan 	u8 nread;
1195d069a46bSRajkumar Manoharan 
1196d069a46bSRajkumar Manoharan 	buf = kzalloc(size, GFP_KERNEL);
1197d069a46bSRajkumar Manoharan 	if (!buf)
1198d069a46bSRajkumar Manoharan 		return -ENOMEM;
1199d069a46bSRajkumar Manoharan 
12005e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len,
1201d069a46bSRajkumar Manoharan 			 "Channel Noise Floor : %d\n", ah->noise);
12025e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len,
1203d069a46bSRajkumar Manoharan 			 "Chain | privNF | # Readings | NF Readings\n");
1204d069a46bSRajkumar Manoharan 	for (i = 0; i < NUM_NF_READINGS; i++) {
1205d069a46bSRajkumar Manoharan 		if (!(chainmask & (1 << i)) ||
1206d069a46bSRajkumar Manoharan 		    ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1207d069a46bSRajkumar Manoharan 			continue;
1208d069a46bSRajkumar Manoharan 
1209d069a46bSRajkumar Manoharan 		nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
12105e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, size - len, " %d\t %d\t %d\t\t",
1211d069a46bSRajkumar Manoharan 				 i, h[i].privNF, nread);
1212d069a46bSRajkumar Manoharan 		for (j = 0; j < nread; j++)
12135e88ba62SZefir Kurtisi 			len += scnprintf(buf + len, size - len,
1214d069a46bSRajkumar Manoharan 					 " %d", h[i].nfCalBuffer[j]);
12155e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, size - len, "\n");
1216d069a46bSRajkumar Manoharan 	}
1217d069a46bSRajkumar Manoharan 
1218d069a46bSRajkumar Manoharan 	if (len > size)
1219d069a46bSRajkumar Manoharan 		len = size;
1220d069a46bSRajkumar Manoharan 
1221d069a46bSRajkumar Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1222d069a46bSRajkumar Manoharan 	kfree(buf);
1223d069a46bSRajkumar Manoharan 
1224d069a46bSRajkumar Manoharan 	return retval;
1225d069a46bSRajkumar Manoharan }
1226d069a46bSRajkumar Manoharan 
1227d069a46bSRajkumar Manoharan static const struct file_operations fops_dump_nfcal = {
1228d069a46bSRajkumar Manoharan 	.read = read_file_dump_nfcal,
1229234e3405SStephen Boyd 	.open = simple_open,
1230d069a46bSRajkumar Manoharan 	.owner = THIS_MODULE,
1231d069a46bSRajkumar Manoharan 	.llseek = default_llseek,
1232d069a46bSRajkumar Manoharan };
1233d069a46bSRajkumar Manoharan 
1234580f010fSRajkumar Manoharan static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf,
1235580f010fSRajkumar Manoharan 				     size_t count, loff_t *ppos)
1236580f010fSRajkumar Manoharan {
1237580f010fSRajkumar Manoharan 	struct ath_softc *sc = file->private_data;
1238580f010fSRajkumar Manoharan 	struct ath_hw *ah = sc->sc_ah;
1239580f010fSRajkumar Manoharan 	u32 len = 0, size = 1500;
1240580f010fSRajkumar Manoharan 	ssize_t retval = 0;
1241580f010fSRajkumar Manoharan 	char *buf;
1242580f010fSRajkumar Manoharan 
1243580f010fSRajkumar Manoharan 	buf = kzalloc(size, GFP_KERNEL);
1244580f010fSRajkumar Manoharan 	if (!buf)
1245580f010fSRajkumar Manoharan 		return -ENOMEM;
1246580f010fSRajkumar Manoharan 
1247580f010fSRajkumar Manoharan 	len = ah->eep_ops->dump_eeprom(ah, true, buf, len, size);
1248580f010fSRajkumar Manoharan 
1249580f010fSRajkumar Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1250580f010fSRajkumar Manoharan 	kfree(buf);
1251580f010fSRajkumar Manoharan 
1252580f010fSRajkumar Manoharan 	return retval;
1253580f010fSRajkumar Manoharan }
1254580f010fSRajkumar Manoharan 
1255580f010fSRajkumar Manoharan static const struct file_operations fops_base_eeprom = {
1256580f010fSRajkumar Manoharan 	.read = read_file_base_eeprom,
1257234e3405SStephen Boyd 	.open = simple_open,
1258580f010fSRajkumar Manoharan 	.owner = THIS_MODULE,
1259580f010fSRajkumar Manoharan 	.llseek = default_llseek,
1260580f010fSRajkumar Manoharan };
1261580f010fSRajkumar Manoharan 
12623f4c4bddSRajkumar Manoharan static ssize_t read_file_modal_eeprom(struct file *file, char __user *user_buf,
12633f4c4bddSRajkumar Manoharan 				      size_t count, loff_t *ppos)
12643f4c4bddSRajkumar Manoharan {
12653f4c4bddSRajkumar Manoharan 	struct ath_softc *sc = file->private_data;
12663f4c4bddSRajkumar Manoharan 	struct ath_hw *ah = sc->sc_ah;
12673f4c4bddSRajkumar Manoharan 	u32 len = 0, size = 6000;
12683f4c4bddSRajkumar Manoharan 	char *buf;
12693f4c4bddSRajkumar Manoharan 	size_t retval;
12703f4c4bddSRajkumar Manoharan 
12713f4c4bddSRajkumar Manoharan 	buf = kzalloc(size, GFP_KERNEL);
12723f4c4bddSRajkumar Manoharan 	if (buf == NULL)
12733f4c4bddSRajkumar Manoharan 		return -ENOMEM;
12743f4c4bddSRajkumar Manoharan 
12753f4c4bddSRajkumar Manoharan 	len = ah->eep_ops->dump_eeprom(ah, false, buf, len, size);
12763f4c4bddSRajkumar Manoharan 
12773f4c4bddSRajkumar Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
12783f4c4bddSRajkumar Manoharan 	kfree(buf);
12793f4c4bddSRajkumar Manoharan 
12803f4c4bddSRajkumar Manoharan 	return retval;
12813f4c4bddSRajkumar Manoharan }
12823f4c4bddSRajkumar Manoharan 
12833f4c4bddSRajkumar Manoharan static const struct file_operations fops_modal_eeprom = {
12843f4c4bddSRajkumar Manoharan 	.read = read_file_modal_eeprom,
1285234e3405SStephen Boyd 	.open = simple_open,
12863f4c4bddSRajkumar Manoharan 	.owner = THIS_MODULE,
12873f4c4bddSRajkumar Manoharan 	.llseek = default_llseek,
12883f4c4bddSRajkumar Manoharan };
12893f4c4bddSRajkumar Manoharan 
12904df50ca8SRajkumar Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
12914df50ca8SRajkumar Manoharan static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
12924df50ca8SRajkumar Manoharan 				size_t count, loff_t *ppos)
12934df50ca8SRajkumar Manoharan {
12944df50ca8SRajkumar Manoharan 	struct ath_softc *sc = file->private_data;
12954df50ca8SRajkumar Manoharan 	u32 len = 0, size = 1500;
12964df50ca8SRajkumar Manoharan 	char *buf;
12974df50ca8SRajkumar Manoharan 	size_t retval;
12984df50ca8SRajkumar Manoharan 
12994df50ca8SRajkumar Manoharan 	buf = kzalloc(size, GFP_KERNEL);
13004df50ca8SRajkumar Manoharan 	if (buf == NULL)
13014df50ca8SRajkumar Manoharan 		return -ENOMEM;
13024df50ca8SRajkumar Manoharan 
1303ac46ba43SSujith Manoharan 	if (!sc->sc_ah->common.btcoex_enabled) {
13045e88ba62SZefir Kurtisi 		len = scnprintf(buf, size, "%s\n",
1305ac46ba43SSujith Manoharan 				"BTCOEX is disabled");
1306ac46ba43SSujith Manoharan 		goto exit;
1307ac46ba43SSujith Manoharan 	}
13084df50ca8SRajkumar Manoharan 
1309ac46ba43SSujith Manoharan 	len = ath9k_dump_btcoex(sc, buf, size);
1310ac46ba43SSujith Manoharan exit:
13114df50ca8SRajkumar Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
13124df50ca8SRajkumar Manoharan 	kfree(buf);
13134df50ca8SRajkumar Manoharan 
13144df50ca8SRajkumar Manoharan 	return retval;
13154df50ca8SRajkumar Manoharan }
13164df50ca8SRajkumar Manoharan 
13174df50ca8SRajkumar Manoharan static const struct file_operations fops_btcoex = {
13184df50ca8SRajkumar Manoharan 	.read = read_file_btcoex,
13194df50ca8SRajkumar Manoharan 	.open = simple_open,
13204df50ca8SRajkumar Manoharan 	.owner = THIS_MODULE,
13214df50ca8SRajkumar Manoharan 	.llseek = default_llseek,
13224df50ca8SRajkumar Manoharan };
13234df50ca8SRajkumar Manoharan #endif
13244df50ca8SRajkumar Manoharan 
1325a145daf7SSujith Manoharan static ssize_t read_file_node_stat(struct file *file, char __user *user_buf,
1326a145daf7SSujith Manoharan 				   size_t count, loff_t *ppos)
1327a145daf7SSujith Manoharan {
1328a145daf7SSujith Manoharan 	struct ath_node *an = file->private_data;
1329a145daf7SSujith Manoharan 	struct ath_softc *sc = an->sc;
1330a145daf7SSujith Manoharan 	struct ath_atx_tid *tid;
1331a145daf7SSujith Manoharan 	struct ath_atx_ac *ac;
1332a145daf7SSujith Manoharan 	struct ath_txq *txq;
1333a145daf7SSujith Manoharan 	u32 len = 0, size = 4096;
1334a145daf7SSujith Manoharan 	char *buf;
1335a145daf7SSujith Manoharan 	size_t retval;
1336a145daf7SSujith Manoharan 	int tidno, acno;
1337a145daf7SSujith Manoharan 
1338a145daf7SSujith Manoharan 	buf = kzalloc(size, GFP_KERNEL);
1339a145daf7SSujith Manoharan 	if (buf == NULL)
1340a145daf7SSujith Manoharan 		return -ENOMEM;
1341a145daf7SSujith Manoharan 
1342a145daf7SSujith Manoharan 	if (!an->sta->ht_cap.ht_supported) {
13435e88ba62SZefir Kurtisi 		len = scnprintf(buf, size, "%s\n",
1344a145daf7SSujith Manoharan 				"HT not supported");
1345a145daf7SSujith Manoharan 		goto exit;
1346a145daf7SSujith Manoharan 	}
1347a145daf7SSujith Manoharan 
13485e88ba62SZefir Kurtisi 	len = scnprintf(buf, size, "Max-AMPDU: %d\n",
1349a145daf7SSujith Manoharan 			an->maxampdu);
13505e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "MPDU Density: %d\n\n",
1351a145daf7SSujith Manoharan 			 an->mpdudensity);
1352a145daf7SSujith Manoharan 
13535e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len,
1354a145daf7SSujith Manoharan 			 "%2s%7s\n", "AC", "SCHED");
1355a145daf7SSujith Manoharan 
1356a145daf7SSujith Manoharan 	for (acno = 0, ac = &an->ac[acno];
1357a145daf7SSujith Manoharan 	     acno < IEEE80211_NUM_ACS; acno++, ac++) {
1358a145daf7SSujith Manoharan 		txq = ac->txq;
1359a145daf7SSujith Manoharan 		ath_txq_lock(sc, txq);
13605e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, size - len,
1361a145daf7SSujith Manoharan 				 "%2d%7d\n",
1362a145daf7SSujith Manoharan 				 acno, ac->sched);
1363a145daf7SSujith Manoharan 		ath_txq_unlock(sc, txq);
1364a145daf7SSujith Manoharan 	}
1365a145daf7SSujith Manoharan 
13665e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len,
1367a145daf7SSujith Manoharan 			 "\n%3s%11s%10s%10s%10s%10s%9s%6s%8s\n",
1368a145daf7SSujith Manoharan 			 "TID", "SEQ_START", "SEQ_NEXT", "BAW_SIZE",
1369a145daf7SSujith Manoharan 			 "BAW_HEAD", "BAW_TAIL", "BAR_IDX", "SCHED", "PAUSED");
1370a145daf7SSujith Manoharan 
1371a145daf7SSujith Manoharan 	for (tidno = 0, tid = &an->tid[tidno];
1372a145daf7SSujith Manoharan 	     tidno < IEEE80211_NUM_TIDS; tidno++, tid++) {
1373a145daf7SSujith Manoharan 		txq = tid->ac->txq;
1374a145daf7SSujith Manoharan 		ath_txq_lock(sc, txq);
13755e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, size - len,
1376a145daf7SSujith Manoharan 				 "%3d%11d%10d%10d%10d%10d%9d%6d%8d\n",
1377a145daf7SSujith Manoharan 				 tid->tidno, tid->seq_start, tid->seq_next,
1378a145daf7SSujith Manoharan 				 tid->baw_size, tid->baw_head, tid->baw_tail,
1379a145daf7SSujith Manoharan 				 tid->bar_index, tid->sched, tid->paused);
1380a145daf7SSujith Manoharan 		ath_txq_unlock(sc, txq);
1381a145daf7SSujith Manoharan 	}
1382a145daf7SSujith Manoharan exit:
1383a145daf7SSujith Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1384a145daf7SSujith Manoharan 	kfree(buf);
1385a145daf7SSujith Manoharan 
1386a145daf7SSujith Manoharan 	return retval;
1387a145daf7SSujith Manoharan }
1388a145daf7SSujith Manoharan 
1389a145daf7SSujith Manoharan static const struct file_operations fops_node_stat = {
1390a145daf7SSujith Manoharan 	.read = read_file_node_stat,
1391a145daf7SSujith Manoharan 	.open = simple_open,
1392a145daf7SSujith Manoharan 	.owner = THIS_MODULE,
1393a145daf7SSujith Manoharan 	.llseek = default_llseek,
1394a145daf7SSujith Manoharan };
1395a145daf7SSujith Manoharan 
1396a145daf7SSujith Manoharan void ath9k_sta_add_debugfs(struct ieee80211_hw *hw,
1397a145daf7SSujith Manoharan 			   struct ieee80211_vif *vif,
1398a145daf7SSujith Manoharan 			   struct ieee80211_sta *sta,
1399a145daf7SSujith Manoharan 			   struct dentry *dir)
1400a145daf7SSujith Manoharan {
1401a145daf7SSujith Manoharan 	struct ath_node *an = (struct ath_node *)sta->drv_priv;
1402f5bde5b8SFelix Fietkau 	debugfs_create_file("node_stat", S_IRUGO, dir, an, &fops_node_stat);
1403a145daf7SSujith Manoharan }
1404a145daf7SSujith Manoharan 
1405c175db87SSujith Manoharan /* Ethtool support for get-stats */
1406c175db87SSujith Manoharan 
1407c175db87SSujith Manoharan #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1408c175db87SSujith Manoharan static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1409c175db87SSujith Manoharan 	"tx_pkts_nic",
1410c175db87SSujith Manoharan 	"tx_bytes_nic",
1411c175db87SSujith Manoharan 	"rx_pkts_nic",
1412c175db87SSujith Manoharan 	"rx_bytes_nic",
1413c175db87SSujith Manoharan 	AMKSTR(d_tx_pkts),
1414c175db87SSujith Manoharan 	AMKSTR(d_tx_bytes),
1415c175db87SSujith Manoharan 	AMKSTR(d_tx_mpdus_queued),
1416c175db87SSujith Manoharan 	AMKSTR(d_tx_mpdus_completed),
1417c175db87SSujith Manoharan 	AMKSTR(d_tx_mpdu_xretries),
1418c175db87SSujith Manoharan 	AMKSTR(d_tx_aggregates),
1419c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdus_queued_hw),
1420c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdus_queued_sw),
1421c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdus_completed),
1422c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdu_retries),
1423c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdu_xretries),
1424c175db87SSujith Manoharan 	AMKSTR(d_tx_fifo_underrun),
1425c175db87SSujith Manoharan 	AMKSTR(d_tx_op_exceeded),
1426c175db87SSujith Manoharan 	AMKSTR(d_tx_timer_expiry),
1427c175db87SSujith Manoharan 	AMKSTR(d_tx_desc_cfg_err),
1428c175db87SSujith Manoharan 	AMKSTR(d_tx_data_underrun),
1429c175db87SSujith Manoharan 	AMKSTR(d_tx_delim_underrun),
143018c45b10SBen Greear 	"d_rx_crc_err",
1431c175db87SSujith Manoharan 	"d_rx_decrypt_crc_err",
1432c175db87SSujith Manoharan 	"d_rx_phy_err",
1433c175db87SSujith Manoharan 	"d_rx_mic_err",
1434c175db87SSujith Manoharan 	"d_rx_pre_delim_crc_err",
1435c175db87SSujith Manoharan 	"d_rx_post_delim_crc_err",
1436c175db87SSujith Manoharan 	"d_rx_decrypt_busy_err",
1437c175db87SSujith Manoharan 
1438c175db87SSujith Manoharan 	"d_rx_phyerr_radar",
1439c175db87SSujith Manoharan 	"d_rx_phyerr_ofdm_timing",
1440c175db87SSujith Manoharan 	"d_rx_phyerr_cck_timing",
1441c175db87SSujith Manoharan 
1442c175db87SSujith Manoharan };
1443c175db87SSujith Manoharan #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1444c175db87SSujith Manoharan 
1445c175db87SSujith Manoharan void ath9k_get_et_strings(struct ieee80211_hw *hw,
1446c175db87SSujith Manoharan 			  struct ieee80211_vif *vif,
1447c175db87SSujith Manoharan 			  u32 sset, u8 *data)
1448c175db87SSujith Manoharan {
1449c175db87SSujith Manoharan 	if (sset == ETH_SS_STATS)
1450c175db87SSujith Manoharan 		memcpy(data, *ath9k_gstrings_stats,
1451c175db87SSujith Manoharan 		       sizeof(ath9k_gstrings_stats));
1452c175db87SSujith Manoharan }
1453c175db87SSujith Manoharan 
1454c175db87SSujith Manoharan int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
1455c175db87SSujith Manoharan 			    struct ieee80211_vif *vif, int sset)
1456c175db87SSujith Manoharan {
1457c175db87SSujith Manoharan 	if (sset == ETH_SS_STATS)
1458c175db87SSujith Manoharan 		return ATH9K_SSTATS_LEN;
1459c175db87SSujith Manoharan 	return 0;
1460c175db87SSujith Manoharan }
1461c175db87SSujith Manoharan 
1462c175db87SSujith Manoharan #define AWDATA(elem)							\
1463c175db87SSujith Manoharan 	do {								\
1464c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
1465c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
1466c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
1467c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
1468c175db87SSujith Manoharan 	} while (0)
1469c175db87SSujith Manoharan 
1470c175db87SSujith Manoharan #define AWDATA_RX(elem)						\
1471c175db87SSujith Manoharan 	do {							\
1472c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.rxstats.elem;	\
1473c175db87SSujith Manoharan 	} while (0)
1474c175db87SSujith Manoharan 
1475c175db87SSujith Manoharan void ath9k_get_et_stats(struct ieee80211_hw *hw,
1476c175db87SSujith Manoharan 			struct ieee80211_vif *vif,
1477c175db87SSujith Manoharan 			struct ethtool_stats *stats, u64 *data)
1478c175db87SSujith Manoharan {
1479c175db87SSujith Manoharan 	struct ath_softc *sc = hw->priv;
1480c175db87SSujith Manoharan 	int i = 0;
1481c175db87SSujith Manoharan 
1482c175db87SSujith Manoharan 	data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
1483c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
1484c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
1485c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
1486c175db87SSujith Manoharan 	data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
1487c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
1488c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
1489c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
1490c175db87SSujith Manoharan 	AWDATA_RX(rx_pkts_all);
1491c175db87SSujith Manoharan 	AWDATA_RX(rx_bytes_all);
1492c175db87SSujith Manoharan 
1493c175db87SSujith Manoharan 	AWDATA(tx_pkts_all);
1494c175db87SSujith Manoharan 	AWDATA(tx_bytes_all);
1495c175db87SSujith Manoharan 	AWDATA(queued);
1496c175db87SSujith Manoharan 	AWDATA(completed);
1497c175db87SSujith Manoharan 	AWDATA(xretries);
1498c175db87SSujith Manoharan 	AWDATA(a_aggr);
1499c175db87SSujith Manoharan 	AWDATA(a_queued_hw);
1500c175db87SSujith Manoharan 	AWDATA(a_queued_sw);
1501c175db87SSujith Manoharan 	AWDATA(a_completed);
1502c175db87SSujith Manoharan 	AWDATA(a_retries);
1503c175db87SSujith Manoharan 	AWDATA(a_xretries);
1504c175db87SSujith Manoharan 	AWDATA(fifo_underrun);
1505c175db87SSujith Manoharan 	AWDATA(xtxop);
1506c175db87SSujith Manoharan 	AWDATA(timer_exp);
1507c175db87SSujith Manoharan 	AWDATA(desc_cfg_err);
1508c175db87SSujith Manoharan 	AWDATA(data_underrun);
1509c175db87SSujith Manoharan 	AWDATA(delim_underrun);
1510c175db87SSujith Manoharan 
151118c45b10SBen Greear 	AWDATA_RX(crc_err);
1512c175db87SSujith Manoharan 	AWDATA_RX(decrypt_crc_err);
1513c175db87SSujith Manoharan 	AWDATA_RX(phy_err);
1514c175db87SSujith Manoharan 	AWDATA_RX(mic_err);
1515c175db87SSujith Manoharan 	AWDATA_RX(pre_delim_crc_err);
1516c175db87SSujith Manoharan 	AWDATA_RX(post_delim_crc_err);
1517c175db87SSujith Manoharan 	AWDATA_RX(decrypt_busy_err);
1518c175db87SSujith Manoharan 
1519c175db87SSujith Manoharan 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
1520c175db87SSujith Manoharan 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
1521c175db87SSujith Manoharan 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
1522c175db87SSujith Manoharan 
1523c175db87SSujith Manoharan 	WARN_ON(i != ATH9K_SSTATS_LEN);
1524c175db87SSujith Manoharan }
1525c175db87SSujith Manoharan 
1526af690092SSujith Manoharan void ath9k_deinit_debug(struct ath_softc *sc)
1527af690092SSujith Manoharan {
1528f65c0825SSujith Manoharan 	ath9k_spectral_deinit_debug(sc);
1529af690092SSujith Manoharan }
1530af690092SSujith Manoharan 
15314d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah)
1532203c4805SLuis R. Rodriguez {
1533bc974f4aSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(ah);
1534bc974f4aSLuis R. Rodriguez 	struct ath_softc *sc = (struct ath_softc *) common->priv;
15354d6b228dSLuis R. Rodriguez 
1536eb272441SBen Greear 	sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1537eb272441SBen Greear 						   sc->hw->wiphy->debugfsdir);
1538203c4805SLuis R. Rodriguez 	if (!sc->debug.debugfs_phy)
1539c8a72c00SFelix Fietkau 		return -ENOMEM;
1540203c4805SLuis R. Rodriguez 
1541a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
1542c70cab1aSFelix Fietkau 	debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1543c70cab1aSFelix Fietkau 			    sc, &fops_debug);
1544a830df07SFelix Fietkau #endif
154529942bc1SZefir Kurtisi 
154629942bc1SZefir Kurtisi 	ath9k_dfs_init_debug(sc);
1547ef6b19e4SSujith Manoharan 	ath9k_tx99_init_debug(sc);
1548f65c0825SSujith Manoharan 	ath9k_spectral_init_debug(sc);
154929942bc1SZefir Kurtisi 
1550c70cab1aSFelix Fietkau 	debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
1551c70cab1aSFelix Fietkau 			    &fops_dma);
1552c70cab1aSFelix Fietkau 	debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
1553c70cab1aSFelix Fietkau 			    &fops_interrupt);
1554c70cab1aSFelix Fietkau 	debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc,
1555c70cab1aSFelix Fietkau 			    &fops_xmit);
1556c0b74876SSujith Manoharan 	debugfs_create_file("queues", S_IRUSR, sc->debug.debugfs_phy, sc,
1557c0b74876SSujith Manoharan 			    &fops_queues);
15587702e788SFelix Fietkau 	debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1559bea843c7SSujith Manoharan 			   &sc->tx.txq_max_pending[IEEE80211_AC_BK]);
15607702e788SFelix Fietkau 	debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1561bea843c7SSujith Manoharan 			   &sc->tx.txq_max_pending[IEEE80211_AC_BE]);
15627702e788SFelix Fietkau 	debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1563bea843c7SSujith Manoharan 			   &sc->tx.txq_max_pending[IEEE80211_AC_VI]);
15647702e788SFelix Fietkau 	debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1565bea843c7SSujith Manoharan 			   &sc->tx.txq_max_pending[IEEE80211_AC_VO]);
1566c70cab1aSFelix Fietkau 	debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy, sc,
1567c70cab1aSFelix Fietkau 			    &fops_misc);
1568f8b815dcSSujith Manoharan 	debugfs_create_file("reset", S_IRUSR, sc->debug.debugfs_phy, sc,
1569f8b815dcSSujith Manoharan 			    &fops_reset);
1570c70cab1aSFelix Fietkau 	debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy, sc,
1571c70cab1aSFelix Fietkau 			    &fops_recv);
1572ca6d4a74SFelix Fietkau 	debugfs_create_u8("rx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
1573ca6d4a74SFelix Fietkau 			  &ah->rxchainmask);
1574ca6d4a74SFelix Fietkau 	debugfs_create_u8("tx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
1575ca6d4a74SFelix Fietkau 			  &ah->txchainmask);
15766e4d291eSSujith Manoharan 	debugfs_create_file("ani", S_IRUSR | S_IWUSR,
15776e4d291eSSujith Manoharan 			    sc->debug.debugfs_phy, sc, &fops_ani);
157874673db9SFelix Fietkau 	debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
157974673db9SFelix Fietkau 			    &sc->sc_ah->config.enable_paprd);
1580c70cab1aSFelix Fietkau 	debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1581c70cab1aSFelix Fietkau 			    sc, &fops_regidx);
1582c70cab1aSFelix Fietkau 	debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1583c70cab1aSFelix Fietkau 			    sc, &fops_regval);
1584c70cab1aSFelix Fietkau 	debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1585c70cab1aSFelix Fietkau 			    sc->debug.debugfs_phy,
1586c70cab1aSFelix Fietkau 			    &ah->config.cwm_ignore_extcca);
1587c70cab1aSFelix Fietkau 	debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
1588c70cab1aSFelix Fietkau 			    &fops_regdump);
1589d069a46bSRajkumar Manoharan 	debugfs_create_file("dump_nfcal", S_IRUSR, sc->debug.debugfs_phy, sc,
1590d069a46bSRajkumar Manoharan 			    &fops_dump_nfcal);
1591580f010fSRajkumar Manoharan 	debugfs_create_file("base_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
1592580f010fSRajkumar Manoharan 			    &fops_base_eeprom);
15933f4c4bddSRajkumar Manoharan 	debugfs_create_file("modal_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
15943f4c4bddSRajkumar Manoharan 			    &fops_modal_eeprom);
1595691680b8SFelix Fietkau 	debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
1596691680b8SFelix Fietkau 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
1597691680b8SFelix Fietkau 	debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
1598691680b8SFelix Fietkau 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
15994eba10ccSSujith Manoharan 	debugfs_create_file("antenna_diversity", S_IRUSR,
16004eba10ccSSujith Manoharan 			    sc->debug.debugfs_phy, sc, &fops_antenna_diversity);
16014df50ca8SRajkumar Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
160236e8825eSSujith Manoharan 	debugfs_create_file("bt_ant_diversity", S_IRUSR | S_IWUSR,
160336e8825eSSujith Manoharan 			    sc->debug.debugfs_phy, sc, &fops_bt_ant_diversity);
16044df50ca8SRajkumar Manoharan 	debugfs_create_file("btcoex", S_IRUSR, sc->debug.debugfs_phy, sc,
16054df50ca8SRajkumar Manoharan 			    &fops_btcoex);
16064df50ca8SRajkumar Manoharan #endif
160789f927afSLuis R. Rodriguez 
1608203c4805SLuis R. Rodriguez 	return 0;
1609203c4805SLuis R. Rodriguez }
1610