xref: /linux/drivers/net/wireless/ath/ath9k/debug.c (revision 29bf801e04514929aeec768d237c62ae37564041)
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 
296a4d05dcSFelix Fietkau void ath9k_debug_sync_cause(struct ath_softc *sc, u32 sync_cause)
306a4d05dcSFelix Fietkau {
316a4d05dcSFelix Fietkau 	if (sync_cause)
326a4d05dcSFelix Fietkau 		sc->debug.stats.istats.sync_cause_all++;
336a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_RTC_IRQ)
346a4d05dcSFelix Fietkau 		sc->debug.stats.istats.sync_rtc_irq++;
356a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_MAC_IRQ)
366a4d05dcSFelix Fietkau 		sc->debug.stats.istats.sync_mac_irq++;
376a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_EEPROM_ILLEGAL_ACCESS)
386a4d05dcSFelix Fietkau 		sc->debug.stats.istats.eeprom_illegal_access++;
396a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_APB_TIMEOUT)
406a4d05dcSFelix Fietkau 		sc->debug.stats.istats.apb_timeout++;
416a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_PCI_MODE_CONFLICT)
426a4d05dcSFelix Fietkau 		sc->debug.stats.istats.pci_mode_conflict++;
436a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_HOST1_FATAL)
446a4d05dcSFelix Fietkau 		sc->debug.stats.istats.host1_fatal++;
456a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_HOST1_PERR)
466a4d05dcSFelix Fietkau 		sc->debug.stats.istats.host1_perr++;
476a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_TRCV_FIFO_PERR)
486a4d05dcSFelix Fietkau 		sc->debug.stats.istats.trcv_fifo_perr++;
496a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_RADM_CPL_EP)
506a4d05dcSFelix Fietkau 		sc->debug.stats.istats.radm_cpl_ep++;
516a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_RADM_CPL_DLLP_ABORT)
526a4d05dcSFelix Fietkau 		sc->debug.stats.istats.radm_cpl_dllp_abort++;
536a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_RADM_CPL_TLP_ABORT)
546a4d05dcSFelix Fietkau 		sc->debug.stats.istats.radm_cpl_tlp_abort++;
556a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_RADM_CPL_ECRC_ERR)
566a4d05dcSFelix Fietkau 		sc->debug.stats.istats.radm_cpl_ecrc_err++;
576a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT)
586a4d05dcSFelix Fietkau 		sc->debug.stats.istats.radm_cpl_timeout++;
596a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT)
606a4d05dcSFelix Fietkau 		sc->debug.stats.istats.local_timeout++;
616a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_PM_ACCESS)
626a4d05dcSFelix Fietkau 		sc->debug.stats.istats.pm_access++;
636a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_MAC_AWAKE)
646a4d05dcSFelix Fietkau 		sc->debug.stats.istats.mac_awake++;
656a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_MAC_ASLEEP)
666a4d05dcSFelix Fietkau 		sc->debug.stats.istats.mac_asleep++;
676a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_MAC_SLEEP_ACCESS)
686a4d05dcSFelix Fietkau 		sc->debug.stats.istats.mac_sleep_access++;
696a4d05dcSFelix 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;
1382120ac96SJoe Perches 	unsigned int len = 0;
1392120ac96SJoe Perches 	const unsigned int size = 1024;
1406e4d291eSSujith Manoharan 	ssize_t retval = 0;
1416e4d291eSSujith Manoharan 	char *buf;
142abee4c84SFelix Fietkau 	int i;
143abee4c84SFelix Fietkau 	struct {
144abee4c84SFelix Fietkau 		const char *name;
145abee4c84SFelix Fietkau 		unsigned int val;
146abee4c84SFelix Fietkau 	} ani_info[] = {
147abee4c84SFelix Fietkau 		{ "ANI RESET", ah->stats.ast_ani_reset },
148abee4c84SFelix Fietkau 		{ "OFDM LEVEL", ah->ani.ofdmNoiseImmunityLevel },
149abee4c84SFelix Fietkau 		{ "CCK LEVEL", ah->ani.cckNoiseImmunityLevel },
150abee4c84SFelix Fietkau 		{ "SPUR UP", ah->stats.ast_ani_spurup },
151abee4c84SFelix Fietkau 		{ "SPUR DOWN", ah->stats.ast_ani_spurup },
152abee4c84SFelix Fietkau 		{ "OFDM WS-DET ON", ah->stats.ast_ani_ofdmon },
153abee4c84SFelix Fietkau 		{ "OFDM WS-DET OFF", ah->stats.ast_ani_ofdmoff },
154abee4c84SFelix Fietkau 		{ "MRC-CCK ON", ah->stats.ast_ani_ccklow },
155abee4c84SFelix Fietkau 		{ "MRC-CCK OFF", ah->stats.ast_ani_cckhigh },
156abee4c84SFelix Fietkau 		{ "FIR-STEP UP", ah->stats.ast_ani_stepup },
157abee4c84SFelix Fietkau 		{ "FIR-STEP DOWN", ah->stats.ast_ani_stepdown },
158abee4c84SFelix Fietkau 		{ "INV LISTENTIME", ah->stats.ast_ani_lneg_or_lzero },
159abee4c84SFelix Fietkau 		{ "OFDM ERRORS", ah->stats.ast_ani_ofdmerrs },
160abee4c84SFelix Fietkau 		{ "CCK ERRORS", ah->stats.ast_ani_cckerrs },
161abee4c84SFelix Fietkau 	};
16205c0be2fSMohammed Shafi Shajakhan 
1636e4d291eSSujith Manoharan 	buf = kzalloc(size, GFP_KERNEL);
1646e4d291eSSujith Manoharan 	if (buf == NULL)
1656e4d291eSSujith Manoharan 		return -ENOMEM;
1666e4d291eSSujith Manoharan 
167abee4c84SFelix Fietkau 	len += scnprintf(buf + len, size - len, "%15s: %s\n", "ANI",
168abee4c84SFelix Fietkau 			 common->disable_ani ? "DISABLED" : "ENABLED");
16905c0be2fSMohammed Shafi Shajakhan 
170abee4c84SFelix Fietkau 	if (common->disable_ani)
171abee4c84SFelix Fietkau 		goto exit;
172abee4c84SFelix Fietkau 
173abee4c84SFelix Fietkau 	for (i = 0; i < ARRAY_SIZE(ani_info); i++)
1745e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, size - len, "%15s: %u\n",
175abee4c84SFelix Fietkau 				 ani_info[i].name, ani_info[i].val);
176abee4c84SFelix Fietkau 
1776e4d291eSSujith Manoharan exit:
1786e4d291eSSujith Manoharan 	if (len > size)
1796e4d291eSSujith Manoharan 		len = size;
1806e4d291eSSujith Manoharan 
1816e4d291eSSujith Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1826e4d291eSSujith Manoharan 	kfree(buf);
1836e4d291eSSujith Manoharan 
1846e4d291eSSujith Manoharan 	return retval;
1856e4d291eSSujith Manoharan }
1866e4d291eSSujith Manoharan 
1876e4d291eSSujith Manoharan static ssize_t write_file_ani(struct file *file,
18805c0be2fSMohammed Shafi Shajakhan 			      const char __user *user_buf,
18905c0be2fSMohammed Shafi Shajakhan 			      size_t count, loff_t *ppos)
19005c0be2fSMohammed Shafi Shajakhan {
19105c0be2fSMohammed Shafi Shajakhan 	struct ath_softc *sc = file->private_data;
19205c0be2fSMohammed Shafi Shajakhan 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1936e4d291eSSujith Manoharan 	unsigned long ani;
19405c0be2fSMohammed Shafi Shajakhan 	char buf[32];
19505c0be2fSMohammed Shafi Shajakhan 	ssize_t len;
19605c0be2fSMohammed Shafi Shajakhan 
19705c0be2fSMohammed Shafi Shajakhan 	len = min(count, sizeof(buf) - 1);
19805c0be2fSMohammed Shafi Shajakhan 	if (copy_from_user(buf, user_buf, len))
19905c0be2fSMohammed Shafi Shajakhan 		return -EFAULT;
20005c0be2fSMohammed Shafi Shajakhan 
20105c0be2fSMohammed Shafi Shajakhan 	buf[len] = '\0';
2023899ba90SJohn W. Linville 	if (kstrtoul(buf, 0, &ani))
20305c0be2fSMohammed Shafi Shajakhan 		return -EINVAL;
20405c0be2fSMohammed Shafi Shajakhan 
2056e4d291eSSujith Manoharan 	if (ani < 0 || ani > 1)
2066e4d291eSSujith Manoharan 		return -EINVAL;
20705c0be2fSMohammed Shafi Shajakhan 
2086e4d291eSSujith Manoharan 	common->disable_ani = !ani;
2096e4d291eSSujith Manoharan 
2106e4d291eSSujith Manoharan 	if (common->disable_ani) {
211eefa01ddSOleksij Rempel 		clear_bit(ATH_OP_ANI_RUN, &common->op_flags);
212da0d45f7SSujith Manoharan 		ath_stop_ani(sc);
21305c0be2fSMohammed Shafi Shajakhan 	} else {
214da0d45f7SSujith Manoharan 		ath_check_ani(sc);
21505c0be2fSMohammed Shafi Shajakhan 	}
21605c0be2fSMohammed Shafi Shajakhan 
21705c0be2fSMohammed Shafi Shajakhan 	return count;
21805c0be2fSMohammed Shafi Shajakhan }
21905c0be2fSMohammed Shafi Shajakhan 
2206e4d291eSSujith Manoharan static const struct file_operations fops_ani = {
2216e4d291eSSujith Manoharan 	.read = read_file_ani,
2226e4d291eSSujith Manoharan 	.write = write_file_ani,
223234e3405SStephen Boyd 	.open = simple_open,
22405c0be2fSMohammed Shafi Shajakhan 	.owner = THIS_MODULE,
22505c0be2fSMohammed Shafi Shajakhan 	.llseek = default_llseek,
22605c0be2fSMohammed Shafi Shajakhan };
22715340694SFelix Fietkau 
22836e8825eSSujith Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
22936e8825eSSujith Manoharan 
23063081305SSujith Manoharan static ssize_t read_file_bt_ant_diversity(struct file *file,
23163081305SSujith Manoharan 					  char __user *user_buf,
232302a3c3aSSujith Manoharan 					  size_t count, loff_t *ppos)
233302a3c3aSSujith Manoharan {
234302a3c3aSSujith Manoharan 	struct ath_softc *sc = file->private_data;
235302a3c3aSSujith Manoharan 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
236302a3c3aSSujith Manoharan 	char buf[32];
237302a3c3aSSujith Manoharan 	unsigned int len;
238302a3c3aSSujith Manoharan 
23963081305SSujith Manoharan 	len = sprintf(buf, "%d\n", common->bt_ant_diversity);
240302a3c3aSSujith Manoharan 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
241302a3c3aSSujith Manoharan }
242302a3c3aSSujith Manoharan 
24363081305SSujith Manoharan static ssize_t write_file_bt_ant_diversity(struct file *file,
244302a3c3aSSujith Manoharan 					   const char __user *user_buf,
245302a3c3aSSujith Manoharan 					   size_t count, loff_t *ppos)
246302a3c3aSSujith Manoharan {
247302a3c3aSSujith Manoharan 	struct ath_softc *sc = file->private_data;
248302a3c3aSSujith Manoharan 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2493f2da955SSujith Manoharan 	struct ath9k_hw_capabilities *pCap = &sc->sc_ah->caps;
25063081305SSujith Manoharan 	unsigned long bt_ant_diversity;
251302a3c3aSSujith Manoharan 	char buf[32];
252302a3c3aSSujith Manoharan 	ssize_t len;
253302a3c3aSSujith Manoharan 
254302a3c3aSSujith Manoharan 	len = min(count, sizeof(buf) - 1);
255302a3c3aSSujith Manoharan 	if (copy_from_user(buf, user_buf, len))
256302a3c3aSSujith Manoharan 		return -EFAULT;
257302a3c3aSSujith Manoharan 
2583f2da955SSujith Manoharan 	if (!(pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
2593f2da955SSujith Manoharan 		goto exit;
2603f2da955SSujith Manoharan 
261302a3c3aSSujith Manoharan 	buf[len] = '\0';
26263081305SSujith Manoharan 	if (kstrtoul(buf, 0, &bt_ant_diversity))
263302a3c3aSSujith Manoharan 		return -EINVAL;
264302a3c3aSSujith Manoharan 
26563081305SSujith Manoharan 	common->bt_ant_diversity = !!bt_ant_diversity;
266302a3c3aSSujith Manoharan 	ath9k_ps_wakeup(sc);
267047dc3acSSujith Manoharan 	ath9k_hw_set_bt_ant_diversity(sc->sc_ah, common->bt_ant_diversity);
26863081305SSujith Manoharan 	ath_dbg(common, CONFIG, "Enable WLAN/BT RX Antenna diversity: %d\n",
26963081305SSujith Manoharan 		common->bt_ant_diversity);
270302a3c3aSSujith Manoharan 	ath9k_ps_restore(sc);
2713f2da955SSujith Manoharan exit:
272302a3c3aSSujith Manoharan 	return count;
273302a3c3aSSujith Manoharan }
274302a3c3aSSujith Manoharan 
27563081305SSujith Manoharan static const struct file_operations fops_bt_ant_diversity = {
27663081305SSujith Manoharan 	.read = read_file_bt_ant_diversity,
27763081305SSujith Manoharan 	.write = write_file_bt_ant_diversity,
278302a3c3aSSujith Manoharan 	.open = simple_open,
279302a3c3aSSujith Manoharan 	.owner = THIS_MODULE,
280302a3c3aSSujith Manoharan 	.llseek = default_llseek,
281302a3c3aSSujith Manoharan };
282302a3c3aSSujith Manoharan 
28336e8825eSSujith Manoharan #endif
28436e8825eSSujith Manoharan 
285e3d52914SSujith Manoharan void ath9k_debug_stat_ant(struct ath_softc *sc,
286e3d52914SSujith Manoharan 			  struct ath_hw_antcomb_conf *div_ant_conf,
287e3d52914SSujith Manoharan 			  int main_rssi_avg, int alt_rssi_avg)
288e3d52914SSujith Manoharan {
289e3d52914SSujith Manoharan 	struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
290e3d52914SSujith Manoharan 	struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
291e3d52914SSujith Manoharan 
292e3d52914SSujith Manoharan 	as_main->lna_attempt_cnt[div_ant_conf->main_lna_conf]++;
293e3d52914SSujith Manoharan 	as_alt->lna_attempt_cnt[div_ant_conf->alt_lna_conf]++;
294e3d52914SSujith Manoharan 
295e3d52914SSujith Manoharan 	as_main->rssi_avg = main_rssi_avg;
296e3d52914SSujith Manoharan 	as_alt->rssi_avg = alt_rssi_avg;
297e3d52914SSujith Manoharan }
298e3d52914SSujith Manoharan 
2994eba10ccSSujith Manoharan static ssize_t read_file_antenna_diversity(struct file *file,
3004eba10ccSSujith Manoharan 					   char __user *user_buf,
3014eba10ccSSujith Manoharan 					   size_t count, loff_t *ppos)
3024eba10ccSSujith Manoharan {
3034eba10ccSSujith Manoharan 	struct ath_softc *sc = file->private_data;
3044eba10ccSSujith Manoharan 	struct ath_hw *ah = sc->sc_ah;
3054eba10ccSSujith Manoharan 	struct ath9k_hw_capabilities *pCap = &ah->caps;
3064eba10ccSSujith Manoharan 	struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
3074eba10ccSSujith Manoharan 	struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
308e3d52914SSujith Manoharan 	struct ath_hw_antcomb_conf div_ant_conf;
3092120ac96SJoe Perches 	unsigned int len = 0;
3102120ac96SJoe Perches 	const unsigned int size = 1024;
3114eba10ccSSujith Manoharan 	ssize_t retval = 0;
3124eba10ccSSujith Manoharan 	char *buf;
3132120ac96SJoe Perches 	static const char *lna_conf_str[4] = {
3142120ac96SJoe Perches 		"LNA1_MINUS_LNA2", "LNA2", "LNA1", "LNA1_PLUS_LNA2"
3152120ac96SJoe Perches 	};
3164eba10ccSSujith Manoharan 
3174eba10ccSSujith Manoharan 	buf = kzalloc(size, GFP_KERNEL);
3184eba10ccSSujith Manoharan 	if (buf == NULL)
3194eba10ccSSujith Manoharan 		return -ENOMEM;
3204eba10ccSSujith Manoharan 
3214eba10ccSSujith Manoharan 	if (!(pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)) {
3225e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, size - len, "%s\n",
3234eba10ccSSujith Manoharan 				 "Antenna Diversity Combining is disabled");
3244eba10ccSSujith Manoharan 		goto exit;
3254eba10ccSSujith Manoharan 	}
3264eba10ccSSujith Manoharan 
327e3d52914SSujith Manoharan 	ath9k_ps_wakeup(sc);
328e3d52914SSujith Manoharan 	ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
3295e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "Current MAIN config : %s\n",
330e3d52914SSujith Manoharan 			 lna_conf_str[div_ant_conf.main_lna_conf]);
3315e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "Current ALT config  : %s\n",
332e3d52914SSujith Manoharan 			 lna_conf_str[div_ant_conf.alt_lna_conf]);
3335e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "Average MAIN RSSI   : %d\n",
334e3d52914SSujith Manoharan 			 as_main->rssi_avg);
3355e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "Average ALT RSSI    : %d\n\n",
336e3d52914SSujith Manoharan 			 as_alt->rssi_avg);
337e3d52914SSujith Manoharan 	ath9k_ps_restore(sc);
338e3d52914SSujith Manoharan 
3395e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "Packet Receive Cnt:\n");
3405e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "-------------------\n");
341e3d52914SSujith Manoharan 
3425e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%30s%15s\n",
3434eba10ccSSujith Manoharan 			 "MAIN", "ALT");
3445e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
345e3d52914SSujith Manoharan 			 "TOTAL COUNT",
3464eba10ccSSujith Manoharan 			 as_main->recv_cnt,
3474eba10ccSSujith Manoharan 			 as_alt->recv_cnt);
3485e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3494eba10ccSSujith Manoharan 			 "LNA1",
350e3d52914SSujith Manoharan 			 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1],
351e3d52914SSujith Manoharan 			 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1]);
3525e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3534eba10ccSSujith Manoharan 			 "LNA2",
354e3d52914SSujith Manoharan 			 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2],
355e3d52914SSujith Manoharan 			 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2]);
3565e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3574eba10ccSSujith Manoharan 			 "LNA1 + LNA2",
358e3d52914SSujith Manoharan 			 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
359e3d52914SSujith Manoharan 			 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
3605e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3614eba10ccSSujith Manoharan 			 "LNA1 - LNA2",
362e3d52914SSujith Manoharan 			 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
363e3d52914SSujith Manoharan 			 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
364e3d52914SSujith Manoharan 
3655e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "\nLNA Config Attempts:\n");
3665e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "--------------------\n");
367e3d52914SSujith Manoharan 
3685e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%30s%15s\n",
369e3d52914SSujith Manoharan 			 "MAIN", "ALT");
3705e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
371e3d52914SSujith Manoharan 			 "LNA1",
372e3d52914SSujith Manoharan 			 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1],
373e3d52914SSujith Manoharan 			 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1]);
3745e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
375e3d52914SSujith Manoharan 			 "LNA2",
376e3d52914SSujith Manoharan 			 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2],
377e3d52914SSujith Manoharan 			 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2]);
3785e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
379e3d52914SSujith Manoharan 			 "LNA1 + LNA2",
380e3d52914SSujith Manoharan 			 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
381e3d52914SSujith Manoharan 			 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
3825e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
383e3d52914SSujith Manoharan 			 "LNA1 - LNA2",
384e3d52914SSujith Manoharan 			 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
385e3d52914SSujith Manoharan 			 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
386e3d52914SSujith Manoharan 
3874eba10ccSSujith Manoharan exit:
3884eba10ccSSujith Manoharan 	if (len > size)
3894eba10ccSSujith Manoharan 		len = size;
3904eba10ccSSujith Manoharan 
3914eba10ccSSujith Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
3924eba10ccSSujith Manoharan 	kfree(buf);
3934eba10ccSSujith Manoharan 
3944eba10ccSSujith Manoharan 	return retval;
3954eba10ccSSujith Manoharan }
3964eba10ccSSujith Manoharan 
3974eba10ccSSujith Manoharan static const struct file_operations fops_antenna_diversity = {
3984eba10ccSSujith Manoharan 	.read = read_file_antenna_diversity,
3994eba10ccSSujith Manoharan 	.open = simple_open,
4004eba10ccSSujith Manoharan 	.owner = THIS_MODULE,
4014eba10ccSSujith Manoharan 	.llseek = default_llseek,
4024eba10ccSSujith Manoharan };
4034eba10ccSSujith Manoharan 
404203c4805SLuis R. Rodriguez static ssize_t read_file_dma(struct file *file, char __user *user_buf,
405203c4805SLuis R. Rodriguez 			     size_t count, loff_t *ppos)
406203c4805SLuis R. Rodriguez {
407203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
408203c4805SLuis R. Rodriguez 	struct ath_hw *ah = sc->sc_ah;
409991a0987SPavel Roskin 	char *buf;
410991a0987SPavel Roskin 	int retval;
411203c4805SLuis R. Rodriguez 	unsigned int len = 0;
412203c4805SLuis R. Rodriguez 	u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
413203c4805SLuis R. Rodriguez 	int i, qcuOffset = 0, dcuOffset = 0;
414203c4805SLuis R. Rodriguez 	u32 *qcuBase = &val[0], *dcuBase = &val[4];
415203c4805SLuis R. Rodriguez 
416991a0987SPavel Roskin 	buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
417991a0987SPavel Roskin 	if (!buf)
41804236066SDan Carpenter 		return -ENOMEM;
419991a0987SPavel Roskin 
4207cf4a2e7SSujith 	ath9k_ps_wakeup(sc);
4217cf4a2e7SSujith 
422475a6e4dSLuis R. Rodriguez 	REG_WRITE_D(ah, AR_MACMISC,
423203c4805SLuis R. Rodriguez 		  ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
424203c4805SLuis R. Rodriguez 		   (AR_MACMISC_MISC_OBS_BUS_1 <<
425203c4805SLuis R. Rodriguez 		    AR_MACMISC_MISC_OBS_BUS_MSB_S)));
426203c4805SLuis R. Rodriguez 
4275e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len,
428203c4805SLuis R. Rodriguez 			 "Raw DMA Debug values:\n");
429203c4805SLuis R. Rodriguez 
430203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
431203c4805SLuis R. Rodriguez 		if (i % 4 == 0)
4325e88ba62SZefir Kurtisi 			len += scnprintf(buf + len, DMA_BUF_LEN - len, "\n");
433203c4805SLuis R. Rodriguez 
434475a6e4dSLuis R. Rodriguez 		val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
4355e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
436203c4805SLuis R. Rodriguez 				 i, val[i]);
437203c4805SLuis R. Rodriguez 	}
438203c4805SLuis R. Rodriguez 
4395e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
4405e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len,
441203c4805SLuis R. Rodriguez 			 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
442203c4805SLuis R. Rodriguez 
443203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
444203c4805SLuis R. Rodriguez 		if (i == 8) {
445203c4805SLuis R. Rodriguez 			qcuOffset = 0;
446203c4805SLuis R. Rodriguez 			qcuBase++;
447203c4805SLuis R. Rodriguez 		}
448203c4805SLuis R. Rodriguez 
449203c4805SLuis R. Rodriguez 		if (i == 6) {
450203c4805SLuis R. Rodriguez 			dcuOffset = 0;
451203c4805SLuis R. Rodriguez 			dcuBase++;
452203c4805SLuis R. Rodriguez 		}
453203c4805SLuis R. Rodriguez 
4545e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, DMA_BUF_LEN - len,
455203c4805SLuis R. Rodriguez 			 "%2d          %2x      %1x     %2x           %2x\n",
456203c4805SLuis R. Rodriguez 			 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
457203c4805SLuis R. Rodriguez 			 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
458203c4805SLuis R. Rodriguez 			 val[2] & (0x7 << (i * 3)) >> (i * 3),
459203c4805SLuis R. Rodriguez 			 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
460203c4805SLuis R. Rodriguez 	}
461203c4805SLuis R. Rodriguez 
4625e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len, "\n");
463203c4805SLuis R. Rodriguez 
4645e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len,
465203c4805SLuis R. Rodriguez 		"qcu_stitch state:   %2x    qcu_fetch state:        %2x\n",
466203c4805SLuis R. Rodriguez 		(val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
4675e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len,
468203c4805SLuis R. Rodriguez 		"qcu_complete state: %2x    dcu_complete state:     %2x\n",
469203c4805SLuis R. Rodriguez 		(val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
4705e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len,
471203c4805SLuis R. Rodriguez 		"dcu_arb state:      %2x    dcu_fp state:           %2x\n",
472203c4805SLuis R. Rodriguez 		(val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
4735e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len,
474203c4805SLuis R. Rodriguez 		"chan_idle_dur:     %3d    chan_idle_dur_valid:     %1d\n",
475203c4805SLuis R. Rodriguez 		(val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
4765e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len,
477203c4805SLuis R. Rodriguez 		"txfifo_valid_0:      %1d    txfifo_valid_1:          %1d\n",
478203c4805SLuis R. Rodriguez 		(val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
4795e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len,
480203c4805SLuis R. Rodriguez 		"txfifo_dcu_num_0:   %2d    txfifo_dcu_num_1:       %2d\n",
481203c4805SLuis R. Rodriguez 		(val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
482203c4805SLuis R. Rodriguez 
4835e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
484475a6e4dSLuis R. Rodriguez 			 REG_READ_D(ah, AR_OBS_BUS_1));
4855e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, DMA_BUF_LEN - len,
486475a6e4dSLuis R. Rodriguez 			 "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
487203c4805SLuis R. Rodriguez 
4887cf4a2e7SSujith 	ath9k_ps_restore(sc);
4897cf4a2e7SSujith 
4902b87f3aaSDan Carpenter 	if (len > DMA_BUF_LEN)
4912b87f3aaSDan Carpenter 		len = DMA_BUF_LEN;
4922b87f3aaSDan Carpenter 
493991a0987SPavel Roskin 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
494991a0987SPavel Roskin 	kfree(buf);
495991a0987SPavel Roskin 	return retval;
496203c4805SLuis R. Rodriguez }
497203c4805SLuis R. Rodriguez 
498203c4805SLuis R. Rodriguez static const struct file_operations fops_dma = {
499203c4805SLuis R. Rodriguez 	.read = read_file_dma,
500234e3405SStephen Boyd 	.open = simple_open,
5016038f373SArnd Bergmann 	.owner = THIS_MODULE,
5026038f373SArnd Bergmann 	.llseek = default_llseek,
503203c4805SLuis R. Rodriguez };
504203c4805SLuis R. Rodriguez 
505203c4805SLuis R. Rodriguez 
506203c4805SLuis R. Rodriguez void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
507203c4805SLuis R. Rodriguez {
508203c4805SLuis R. Rodriguez 	if (status)
509203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.total++;
510a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
511a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXLP)
512a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxlp++;
513a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXHP)
514a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxhp++;
51508578b8fSLuis R. Rodriguez 		if (status & ATH9K_INT_BB_WATCHDOG)
51608578b8fSLuis R. Rodriguez 			sc->debug.stats.istats.bb_watchdog++;
517a9616f41SLuis R. Rodriguez 	} else {
518203c4805SLuis R. Rodriguez 		if (status & ATH9K_INT_RX)
519203c4805SLuis R. Rodriguez 			sc->debug.stats.istats.rxok++;
520a9616f41SLuis R. Rodriguez 	}
521203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXEOL)
522203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxeol++;
523203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXORN)
524203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxorn++;
525203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TX)
526203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txok++;
527203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TXURN)
528203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txurn++;
529203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXPHY)
530203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxphyerr++;
531203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXKCM)
532203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rx_keycache_miss++;
533203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_SWBA)
534203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.swba++;
535203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BMISS)
536203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bmiss++;
537203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BNR)
538203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bnr++;
539203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CST)
540203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cst++;
541203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_GTT)
542203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.gtt++;
543203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TIM)
544203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.tim++;
545203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CABEND)
546203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cabend++;
547203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIMSYNC)
548203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtimsync++;
549203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIM)
550203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtim++;
5516dde1aabSMohammed Shafi Shajakhan 	if (status & ATH9K_INT_TSFOOR)
5526dde1aabSMohammed Shafi Shajakhan 		sc->debug.stats.istats.tsfoor++;
55397ba515aSSujith Manoharan 	if (status & ATH9K_INT_MCI)
55497ba515aSSujith Manoharan 		sc->debug.stats.istats.mci++;
555c9e6e980SMohammed Shafi Shajakhan 	if (status & ATH9K_INT_GENTIMER)
556c9e6e980SMohammed Shafi Shajakhan 		sc->debug.stats.istats.gen_timer++;
557203c4805SLuis R. Rodriguez }
558203c4805SLuis R. Rodriguez 
559203c4805SLuis R. Rodriguez static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
560203c4805SLuis R. Rodriguez 				   size_t count, loff_t *ppos)
561203c4805SLuis R. Rodriguez {
562203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
563203c4805SLuis R. Rodriguez 	unsigned int len = 0;
564462e58f2SBen Greear 	int rv;
565462e58f2SBen Greear 	int mxlen = 4000;
566462e58f2SBen Greear 	char *buf = kmalloc(mxlen, GFP_KERNEL);
567462e58f2SBen Greear 	if (!buf)
568462e58f2SBen Greear 		return -ENOMEM;
569462e58f2SBen Greear 
570462e58f2SBen Greear #define PR_IS(a, s)						\
571462e58f2SBen Greear 	do {							\
5725e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, mxlen - len,	\
573462e58f2SBen Greear 				 "%21s: %10u\n", a,		\
574462e58f2SBen Greear 				 sc->debug.stats.istats.s);	\
575462e58f2SBen Greear 	} while (0)
576203c4805SLuis R. Rodriguez 
577a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
578462e58f2SBen Greear 		PR_IS("RXLP", rxlp);
579462e58f2SBen Greear 		PR_IS("RXHP", rxhp);
580462e58f2SBen Greear 		PR_IS("WATHDOG", bb_watchdog);
581a9616f41SLuis R. Rodriguez 	} else {
582462e58f2SBen Greear 		PR_IS("RX", rxok);
583a9616f41SLuis R. Rodriguez 	}
584462e58f2SBen Greear 	PR_IS("RXEOL", rxeol);
585462e58f2SBen Greear 	PR_IS("RXORN", rxorn);
586462e58f2SBen Greear 	PR_IS("TX", txok);
587462e58f2SBen Greear 	PR_IS("TXURN", txurn);
588462e58f2SBen Greear 	PR_IS("MIB", mib);
589462e58f2SBen Greear 	PR_IS("RXPHY", rxphyerr);
590462e58f2SBen Greear 	PR_IS("RXKCM", rx_keycache_miss);
591462e58f2SBen Greear 	PR_IS("SWBA", swba);
592462e58f2SBen Greear 	PR_IS("BMISS", bmiss);
593462e58f2SBen Greear 	PR_IS("BNR", bnr);
594462e58f2SBen Greear 	PR_IS("CST", cst);
595462e58f2SBen Greear 	PR_IS("GTT", gtt);
596462e58f2SBen Greear 	PR_IS("TIM", tim);
597462e58f2SBen Greear 	PR_IS("CABEND", cabend);
598462e58f2SBen Greear 	PR_IS("DTIMSYNC", dtimsync);
599462e58f2SBen Greear 	PR_IS("DTIM", dtim);
600462e58f2SBen Greear 	PR_IS("TSFOOR", tsfoor);
60197ba515aSSujith Manoharan 	PR_IS("MCI", mci);
602c9e6e980SMohammed Shafi Shajakhan 	PR_IS("GENTIMER", gen_timer);
603462e58f2SBen Greear 	PR_IS("TOTAL", total);
604203c4805SLuis R. Rodriguez 
6055e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, mxlen - len,
606462e58f2SBen Greear 			 "SYNC_CAUSE stats:\n");
6076dde1aabSMohammed Shafi Shajakhan 
608462e58f2SBen Greear 	PR_IS("Sync-All", sync_cause_all);
609462e58f2SBen Greear 	PR_IS("RTC-IRQ", sync_rtc_irq);
610462e58f2SBen Greear 	PR_IS("MAC-IRQ", sync_mac_irq);
611462e58f2SBen Greear 	PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
612462e58f2SBen Greear 	PR_IS("APB-Timeout", apb_timeout);
613462e58f2SBen Greear 	PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
614462e58f2SBen Greear 	PR_IS("HOST1-Fatal", host1_fatal);
615462e58f2SBen Greear 	PR_IS("HOST1-Perr", host1_perr);
616462e58f2SBen Greear 	PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
617462e58f2SBen Greear 	PR_IS("RADM-CPL-EP", radm_cpl_ep);
618462e58f2SBen Greear 	PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
619462e58f2SBen Greear 	PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
620462e58f2SBen Greear 	PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
621462e58f2SBen Greear 	PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
622462e58f2SBen Greear 	PR_IS("Local-Bus-Timeout", local_timeout);
623462e58f2SBen Greear 	PR_IS("PM-Access", pm_access);
624462e58f2SBen Greear 	PR_IS("MAC-Awake", mac_awake);
625462e58f2SBen Greear 	PR_IS("MAC-Asleep", mac_asleep);
626462e58f2SBen Greear 	PR_IS("MAC-Sleep-Access", mac_sleep_access);
6272b87f3aaSDan Carpenter 
628462e58f2SBen Greear 	if (len > mxlen)
629462e58f2SBen Greear 		len = mxlen;
630462e58f2SBen Greear 
631462e58f2SBen Greear 	rv = simple_read_from_buffer(user_buf, count, ppos, buf, len);
632462e58f2SBen Greear 	kfree(buf);
633462e58f2SBen Greear 	return rv;
634203c4805SLuis R. Rodriguez }
635203c4805SLuis R. Rodriguez 
636203c4805SLuis R. Rodriguez static const struct file_operations fops_interrupt = {
637203c4805SLuis R. Rodriguez 	.read = read_file_interrupt,
638234e3405SStephen Boyd 	.open = simple_open,
6396038f373SArnd Bergmann 	.owner = THIS_MODULE,
6406038f373SArnd Bergmann 	.llseek = default_llseek,
641203c4805SLuis R. Rodriguez };
642203c4805SLuis R. Rodriguez 
643fec247c0SSujith static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
644fec247c0SSujith 			      size_t count, loff_t *ppos)
645fec247c0SSujith {
646fec247c0SSujith 	struct ath_softc *sc = file->private_data;
647fec247c0SSujith 	char *buf;
64878ef731cSSujith Manoharan 	unsigned int len = 0, size = 2048;
649fec247c0SSujith 	ssize_t retval = 0;
650fec247c0SSujith 
651fec247c0SSujith 	buf = kzalloc(size, GFP_KERNEL);
652fec247c0SSujith 	if (buf == NULL)
65304236066SDan Carpenter 		return -ENOMEM;
654fec247c0SSujith 
65578ef731cSSujith Manoharan 	len += sprintf(buf, "%30s %10s%10s%10s\n\n",
6567f010c93SBen Greear 		       "BE", "BK", "VI", "VO");
657fec247c0SSujith 
658fec247c0SSujith 	PR("MPDUs Queued:    ", queued);
659fec247c0SSujith 	PR("MPDUs Completed: ", completed);
6605a6f78afSFelix Fietkau 	PR("MPDUs XRetried:  ", xretries);
661fec247c0SSujith 	PR("Aggregates:      ", a_aggr);
662bda8addaSBen Greear 	PR("AMPDUs Queued HW:", a_queued_hw);
663bda8addaSBen Greear 	PR("AMPDUs Queued SW:", a_queued_sw);
664fec247c0SSujith 	PR("AMPDUs Completed:", a_completed);
665fec247c0SSujith 	PR("AMPDUs Retried:  ", a_retries);
666fec247c0SSujith 	PR("AMPDUs XRetried: ", a_xretries);
6674d900389SBen Greear 	PR("TXERR Filtered:  ", txerr_filtered);
668fec247c0SSujith 	PR("FIFO Underrun:   ", fifo_underrun);
669fec247c0SSujith 	PR("TXOP Exceeded:   ", xtxop);
670fec247c0SSujith 	PR("TXTIMER Expiry:  ", timer_exp);
671fec247c0SSujith 	PR("DESC CFG Error:  ", desc_cfg_err);
672fec247c0SSujith 	PR("DATA Underrun:   ", data_underrun);
673fec247c0SSujith 	PR("DELIM Underrun:  ", delim_underrun);
67499c15bf5SBen Greear 	PR("TX-Pkts-All:     ", tx_pkts_all);
67599c15bf5SBen Greear 	PR("TX-Bytes-All:    ", tx_bytes_all);
67678ef731cSSujith Manoharan 	PR("HW-put-tx-buf:   ", puttxbuf);
67778ef731cSSujith Manoharan 	PR("HW-tx-start:     ", txstart);
67878ef731cSSujith Manoharan 	PR("HW-tx-proc-desc: ", txprocdesc);
679a5a0bca1SBen Greear 	PR("TX-Failed:       ", txfailed);
680fec247c0SSujith 
6817f010c93SBen Greear 	if (len > size)
6827f010c93SBen Greear 		len = size;
6837f010c93SBen Greear 
6847f010c93SBen Greear 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
6857f010c93SBen Greear 	kfree(buf);
6867f010c93SBen Greear 
6877f010c93SBen Greear 	return retval;
6887f010c93SBen Greear }
6897f010c93SBen Greear 
69018fcf1c6SFelix Fietkau static ssize_t print_queue(struct ath_softc *sc, struct ath_txq *txq,
69118fcf1c6SFelix Fietkau 			   char *buf, ssize_t size)
69218fcf1c6SFelix Fietkau {
69318fcf1c6SFelix Fietkau 	ssize_t len = 0;
69418fcf1c6SFelix Fietkau 
69518fcf1c6SFelix Fietkau 	ath_txq_lock(sc, txq);
69618fcf1c6SFelix Fietkau 
6975e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%s: %d ",
69818fcf1c6SFelix Fietkau 			 "qnum", txq->axq_qnum);
6995e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%s: %2d ",
70018fcf1c6SFelix Fietkau 			 "qdepth", txq->axq_depth);
7015e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%s: %2d ",
70218fcf1c6SFelix Fietkau 			 "ampdu-depth", txq->axq_ampdu_depth);
7035e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%s: %3d ",
70418fcf1c6SFelix Fietkau 			 "pending", txq->pending_frames);
7055e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%s: %d\n",
70618fcf1c6SFelix Fietkau 			 "stopped", txq->stopped);
70718fcf1c6SFelix Fietkau 
70818fcf1c6SFelix Fietkau 	ath_txq_unlock(sc, txq);
70918fcf1c6SFelix Fietkau 	return len;
71018fcf1c6SFelix Fietkau }
71118fcf1c6SFelix Fietkau 
712c0b74876SSujith Manoharan static ssize_t read_file_queues(struct file *file, char __user *user_buf,
713c0b74876SSujith Manoharan 				size_t count, loff_t *ppos)
714c0b74876SSujith Manoharan {
715c0b74876SSujith Manoharan 	struct ath_softc *sc = file->private_data;
716c0b74876SSujith Manoharan 	struct ath_txq *txq;
717c0b74876SSujith Manoharan 	char *buf;
7182120ac96SJoe Perches 	unsigned int len = 0;
7192120ac96SJoe Perches 	const unsigned int size = 1024;
720c0b74876SSujith Manoharan 	ssize_t retval = 0;
721c0b74876SSujith Manoharan 	int i;
7222120ac96SJoe Perches 	static const char *qname[4] = {
7232120ac96SJoe Perches 		"VO", "VI", "BE", "BK"
7242120ac96SJoe Perches 	};
725c0b74876SSujith Manoharan 
726c0b74876SSujith Manoharan 	buf = kzalloc(size, GFP_KERNEL);
727c0b74876SSujith Manoharan 	if (buf == NULL)
728c0b74876SSujith Manoharan 		return -ENOMEM;
729c0b74876SSujith Manoharan 
730c0b74876SSujith Manoharan 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
731c0b74876SSujith Manoharan 		txq = sc->tx.txq_map[i];
7325e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, size - len, "(%s):  ", qname[i]);
73318fcf1c6SFelix Fietkau 		len += print_queue(sc, txq, buf + len, size - len);
734c0b74876SSujith Manoharan 	}
735c0b74876SSujith Manoharan 
7365e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "(CAB): ");
73718fcf1c6SFelix Fietkau 	len += print_queue(sc, sc->beacon.cabq, buf + len, size - len);
73818fcf1c6SFelix Fietkau 
739c0b74876SSujith Manoharan 	if (len > size)
740c0b74876SSujith Manoharan 		len = size;
741c0b74876SSujith Manoharan 
742c0b74876SSujith Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
743c0b74876SSujith Manoharan 	kfree(buf);
744c0b74876SSujith Manoharan 
745c0b74876SSujith Manoharan 	return retval;
746c0b74876SSujith Manoharan }
747c0b74876SSujith Manoharan 
74855f6d0ffSBen Greear static ssize_t read_file_misc(struct file *file, char __user *user_buf,
74955f6d0ffSBen Greear 			      size_t count, loff_t *ppos)
75055f6d0ffSBen Greear {
75155f6d0ffSBen Greear 	struct ath_softc *sc = file->private_data;
75255f6d0ffSBen Greear 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
75355f6d0ffSBen Greear 	struct ieee80211_hw *hw = sc->hw;
7546bcf6f64SSujith Manoharan 	struct ath9k_vif_iter_data iter_data;
7556bcf6f64SSujith Manoharan 	char buf[512];
7566bcf6f64SSujith Manoharan 	unsigned int len = 0;
75755f6d0ffSBen Greear 	ssize_t retval = 0;
75855f6d0ffSBen Greear 	unsigned int reg;
7596bcf6f64SSujith Manoharan 	u32 rxfilter;
7606bcf6f64SSujith Manoharan 
7615e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
7626bcf6f64SSujith Manoharan 			 "BSSID: %pM\n", common->curbssid);
7635e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
7646bcf6f64SSujith Manoharan 			 "BSSID-MASK: %pM\n", common->bssidmask);
7655e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
7665e88ba62SZefir Kurtisi 			 "OPMODE: %s\n",
7675e88ba62SZefir Kurtisi 			 ath_opmode_to_string(sc->sc_ah->opmode));
7686bcf6f64SSujith Manoharan 
7696bcf6f64SSujith Manoharan 	ath9k_ps_wakeup(sc);
7706bcf6f64SSujith Manoharan 	rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
7716bcf6f64SSujith Manoharan 	ath9k_ps_restore(sc);
7726bcf6f64SSujith Manoharan 
7735e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
7746bcf6f64SSujith Manoharan 			 "RXFILTER: 0x%x", rxfilter);
7756bcf6f64SSujith Manoharan 
7766bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_UCAST)
7775e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " UCAST");
7786bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MCAST)
7795e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " MCAST");
7806bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_BCAST)
7815e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " BCAST");
7826bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_CONTROL)
7835e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " CONTROL");
7846bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_BEACON)
7855e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " BEACON");
7866bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PROM)
7875e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " PROM");
7886bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
7895e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
7906bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PHYERR)
7915e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " PHYERR");
7926bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
7935e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " MYBEACON");
7946bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
7955e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
7966bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
7975e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " PSPOLL");
7986bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
7995e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
8006bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
8015e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL");
8026bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
8035e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " CONTROL_WRAPPER");
8046bcf6f64SSujith Manoharan 
8055e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len, "\n");
8066bcf6f64SSujith Manoharan 
8076bcf6f64SSujith Manoharan 	reg = sc->sc_ah->imask;
8086bcf6f64SSujith Manoharan 
8095e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
8105e88ba62SZefir Kurtisi 			 "INTERRUPT-MASK: 0x%x", reg);
8116bcf6f64SSujith Manoharan 
8126bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_SWBA)
8135e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " SWBA");
8146bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_BMISS)
8155e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " BMISS");
8166bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_CST)
8175e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " CST");
8186bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RX)
8195e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " RX");
8206bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RXHP)
8215e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " RXHP");
8226bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RXLP)
8235e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " RXLP");
8246bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_BB_WATCHDOG)
8255e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, sizeof(buf) - len, " BB_WATCHDOG");
8266bcf6f64SSujith Manoharan 
8275e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len, "\n");
82855f6d0ffSBen Greear 
82955f6d0ffSBen Greear 	ath9k_calculate_iter_data(hw, NULL, &iter_data);
83055f6d0ffSBen Greear 
8315e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
8326bcf6f64SSujith Manoharan 			 "VIF-COUNTS: AP: %i STA: %i MESH: %i WDS: %i"
833bcf6f96eSSujith Manoharan 			 " ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n",
83455f6d0ffSBen Greear 			 iter_data.naps, iter_data.nstations, iter_data.nmeshes,
835bcf6f96eSSujith Manoharan 			 iter_data.nwds, iter_data.nadhocs,
83655f6d0ffSBen Greear 			 sc->nvifs, sc->nbcnvifs);
83755f6d0ffSBen Greear 
8386bcf6f64SSujith Manoharan 	if (len > sizeof(buf))
8396bcf6f64SSujith Manoharan 		len = sizeof(buf);
84055f6d0ffSBen Greear 
84155f6d0ffSBen Greear 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
84255f6d0ffSBen Greear 	return retval;
84355f6d0ffSBen Greear }
84455f6d0ffSBen Greear 
845f8b815dcSSujith Manoharan static ssize_t read_file_reset(struct file *file, char __user *user_buf,
846f8b815dcSSujith Manoharan 			       size_t count, loff_t *ppos)
847f8b815dcSSujith Manoharan {
848f8b815dcSSujith Manoharan 	struct ath_softc *sc = file->private_data;
849f8b815dcSSujith Manoharan 	char buf[512];
850f8b815dcSSujith Manoharan 	unsigned int len = 0;
851f8b815dcSSujith Manoharan 
8525e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
853f8b815dcSSujith Manoharan 			 "%17s: %2d\n", "Baseband Hang",
854f8b815dcSSujith Manoharan 			 sc->debug.stats.reset[RESET_TYPE_BB_HANG]);
8555e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
856f8b815dcSSujith Manoharan 			 "%17s: %2d\n", "Baseband Watchdog",
857f8b815dcSSujith Manoharan 			 sc->debug.stats.reset[RESET_TYPE_BB_WATCHDOG]);
8585e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
859f8b815dcSSujith Manoharan 			 "%17s: %2d\n", "Fatal HW Error",
860f8b815dcSSujith Manoharan 			 sc->debug.stats.reset[RESET_TYPE_FATAL_INT]);
8615e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
862f8b815dcSSujith Manoharan 			 "%17s: %2d\n", "TX HW error",
863f8b815dcSSujith Manoharan 			 sc->debug.stats.reset[RESET_TYPE_TX_ERROR]);
8645e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
865f8b815dcSSujith Manoharan 			 "%17s: %2d\n", "TX Path Hang",
866f8b815dcSSujith Manoharan 			 sc->debug.stats.reset[RESET_TYPE_TX_HANG]);
8675e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
868f8b815dcSSujith Manoharan 			 "%17s: %2d\n", "PLL RX Hang",
869f8b815dcSSujith Manoharan 			 sc->debug.stats.reset[RESET_TYPE_PLL_HANG]);
8705e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, sizeof(buf) - len,
871443626e5SFelix Fietkau 			 "%17s: %2d\n", "MAC Hang",
872443626e5SFelix Fietkau 			 sc->debug.stats.reset[RESET_TYPE_MAC_HANG]);
873443626e5SFelix Fietkau 	len += scnprintf(buf + len, sizeof(buf) - len,
874443626e5SFelix Fietkau 			 "%17s: %2d\n", "Stuck Beacon",
875443626e5SFelix Fietkau 			 sc->debug.stats.reset[RESET_TYPE_BEACON_STUCK]);
876443626e5SFelix Fietkau 	len += scnprintf(buf + len, sizeof(buf) - len,
877b88083bfSRajkumar Manoharan 			 "%17s: %2d\n", "MCI Reset",
878b88083bfSRajkumar Manoharan 			 sc->debug.stats.reset[RESET_TYPE_MCI]);
879f8b815dcSSujith Manoharan 
880f8b815dcSSujith Manoharan 	if (len > sizeof(buf))
881f8b815dcSSujith Manoharan 		len = sizeof(buf);
882f8b815dcSSujith Manoharan 
883f8b815dcSSujith Manoharan 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
884f8b815dcSSujith Manoharan }
885f8b815dcSSujith Manoharan 
886066dae93SFelix Fietkau void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
88755797b1aSFelix Fietkau 		       struct ath_tx_status *ts, struct ath_txq *txq,
88855797b1aSFelix Fietkau 		       unsigned int flags)
889fec247c0SSujith {
8905bec3e5aSFelix Fietkau 	int qnum = txq->axq_qnum;
891066dae93SFelix Fietkau 
892066dae93SFelix Fietkau 	TX_STAT_INC(qnum, tx_pkts_all);
893066dae93SFelix Fietkau 	sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
89499c15bf5SBen Greear 
895fec247c0SSujith 	if (bf_isampdu(bf)) {
896156369faSFelix Fietkau 		if (flags & ATH_TX_ERROR)
897066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_xretries);
898fec247c0SSujith 		else
899066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_completed);
900fec247c0SSujith 	} else {
90155797b1aSFelix Fietkau 		if (ts->ts_status & ATH9K_TXERR_XRETRY)
9025a6f78afSFelix Fietkau 			TX_STAT_INC(qnum, xretries);
9035a6f78afSFelix Fietkau 		else
904066dae93SFelix Fietkau 			TX_STAT_INC(qnum, completed);
905fec247c0SSujith 	}
906fec247c0SSujith 
9074d900389SBen Greear 	if (ts->ts_status & ATH9K_TXERR_FILT)
9084d900389SBen Greear 		TX_STAT_INC(qnum, txerr_filtered);
909db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_FIFO)
910066dae93SFelix Fietkau 		TX_STAT_INC(qnum, fifo_underrun);
911db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_XTXOP)
912066dae93SFelix Fietkau 		TX_STAT_INC(qnum, xtxop);
913db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
914066dae93SFelix Fietkau 		TX_STAT_INC(qnum, timer_exp);
915db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
916066dae93SFelix Fietkau 		TX_STAT_INC(qnum, desc_cfg_err);
917db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
918066dae93SFelix Fietkau 		TX_STAT_INC(qnum, data_underrun);
919db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
920066dae93SFelix Fietkau 		TX_STAT_INC(qnum, delim_underrun);
921fec247c0SSujith }
922fec247c0SSujith 
923fec247c0SSujith static const struct file_operations fops_xmit = {
924fec247c0SSujith 	.read = read_file_xmit,
925234e3405SStephen Boyd 	.open = simple_open,
9266038f373SArnd Bergmann 	.owner = THIS_MODULE,
9276038f373SArnd Bergmann 	.llseek = default_llseek,
928fec247c0SSujith };
929203c4805SLuis R. Rodriguez 
930c0b74876SSujith Manoharan static const struct file_operations fops_queues = {
931c0b74876SSujith Manoharan 	.read = read_file_queues,
932c0b74876SSujith Manoharan 	.open = simple_open,
933c0b74876SSujith Manoharan 	.owner = THIS_MODULE,
934c0b74876SSujith Manoharan 	.llseek = default_llseek,
935c0b74876SSujith Manoharan };
936c0b74876SSujith Manoharan 
93755f6d0ffSBen Greear static const struct file_operations fops_misc = {
93855f6d0ffSBen Greear 	.read = read_file_misc,
939234e3405SStephen Boyd 	.open = simple_open,
94055f6d0ffSBen Greear 	.owner = THIS_MODULE,
94155f6d0ffSBen Greear 	.llseek = default_llseek,
94255f6d0ffSBen Greear };
94355f6d0ffSBen Greear 
944f8b815dcSSujith Manoharan static const struct file_operations fops_reset = {
945f8b815dcSSujith Manoharan 	.read = read_file_reset,
946234e3405SStephen Boyd 	.open = simple_open,
947f8b815dcSSujith Manoharan 	.owner = THIS_MODULE,
948f8b815dcSSujith Manoharan 	.llseek = default_llseek,
949f8b815dcSSujith Manoharan };
950f8b815dcSSujith Manoharan 
9511395d3f0SSujith static ssize_t read_file_recv(struct file *file, char __user *user_buf,
9521395d3f0SSujith 			      size_t count, loff_t *ppos)
9531395d3f0SSujith {
95424a0731eSBen Greear #define RXS_ERR(s, e)					    \
95524a0731eSBen Greear 	do {						    \
9565e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, size - len,	    \
957c3b9f9e8SSujith Manoharan 				 "%18s : %10u\n", s,	    \
95824a0731eSBen Greear 				 sc->debug.stats.rxstats.e);\
95924a0731eSBen Greear 	} while (0)
96024a0731eSBen Greear 
9611395d3f0SSujith 	struct ath_softc *sc = file->private_data;
9621395d3f0SSujith 	char *buf;
9634203214eSSujith Manoharan 	unsigned int len = 0, size = 1600;
9641395d3f0SSujith 	ssize_t retval = 0;
9651395d3f0SSujith 
9661395d3f0SSujith 	buf = kzalloc(size, GFP_KERNEL);
9671395d3f0SSujith 	if (buf == NULL)
96804236066SDan Carpenter 		return -ENOMEM;
9691395d3f0SSujith 
970c3b9f9e8SSujith Manoharan 	RXS_ERR("PKTS-ALL", rx_pkts_all);
971c3b9f9e8SSujith Manoharan 	RXS_ERR("BYTES-ALL", rx_bytes_all);
972c3b9f9e8SSujith Manoharan 	RXS_ERR("BEACONS", rx_beacons);
973c3b9f9e8SSujith Manoharan 	RXS_ERR("FRAGS", rx_frags);
974c3b9f9e8SSujith Manoharan 	RXS_ERR("SPECTRAL", rx_spectral);
975c3b9f9e8SSujith Manoharan 
97624a0731eSBen Greear 	RXS_ERR("CRC ERR", crc_err);
97724a0731eSBen Greear 	RXS_ERR("DECRYPT CRC ERR", decrypt_crc_err);
97824a0731eSBen Greear 	RXS_ERR("PHY ERR", phy_err);
97924a0731eSBen Greear 	RXS_ERR("MIC ERR", mic_err);
98024a0731eSBen Greear 	RXS_ERR("PRE-DELIM CRC ERR", pre_delim_crc_err);
98124a0731eSBen Greear 	RXS_ERR("POST-DELIM CRC ERR", post_delim_crc_err);
98224a0731eSBen Greear 	RXS_ERR("DECRYPT BUSY ERR", decrypt_busy_err);
983c3b9f9e8SSujith Manoharan 	RXS_ERR("LENGTH-ERR", rx_len_err);
984c3b9f9e8SSujith Manoharan 	RXS_ERR("OOM-ERR", rx_oom_err);
985c3b9f9e8SSujith Manoharan 	RXS_ERR("RATE-ERR", rx_rate_err);
986c3b9f9e8SSujith Manoharan 	RXS_ERR("TOO-MANY-FRAGS", rx_too_many_frags_err);
98799c15bf5SBen Greear 
9882b87f3aaSDan Carpenter 	if (len > size)
9892b87f3aaSDan Carpenter 		len = size;
9902b87f3aaSDan Carpenter 
9911395d3f0SSujith 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
9921395d3f0SSujith 	kfree(buf);
9931395d3f0SSujith 
9941395d3f0SSujith 	return retval;
9951395d3f0SSujith 
99624a0731eSBen Greear #undef RXS_ERR
9971395d3f0SSujith }
9981395d3f0SSujith 
9998e6f5aa2SFelix Fietkau void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
10001395d3f0SSujith {
10011395d3f0SSujith #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
10021395d3f0SSujith 
100399c15bf5SBen Greear 	RX_STAT_INC(rx_pkts_all);
100499c15bf5SBen Greear 	sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
100599c15bf5SBen Greear 
10068e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_CRC)
10071395d3f0SSujith 		RX_STAT_INC(crc_err);
10088e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_DECRYPT)
10091395d3f0SSujith 		RX_STAT_INC(decrypt_crc_err);
10108e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_MIC)
10111395d3f0SSujith 		RX_STAT_INC(mic_err);
10128e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
10131395d3f0SSujith 		RX_STAT_INC(pre_delim_crc_err);
10148e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
10151395d3f0SSujith 		RX_STAT_INC(post_delim_crc_err);
10168e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
10171395d3f0SSujith 		RX_STAT_INC(decrypt_busy_err);
10181395d3f0SSujith 
10198e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_PHY) {
10201395d3f0SSujith 		RX_STAT_INC(phy_err);
1021dbb07f00SSujith Manoharan 		if (rs->rs_phyerr < ATH9K_PHYERR_MAX)
1022dbb07f00SSujith Manoharan 			RX_PHY_ERR_INC(rs->rs_phyerr);
10231395d3f0SSujith 	}
10241395d3f0SSujith 
10251395d3f0SSujith #undef RX_PHY_ERR_INC
10261395d3f0SSujith }
10271395d3f0SSujith 
10281395d3f0SSujith static const struct file_operations fops_recv = {
10291395d3f0SSujith 	.read = read_file_recv,
1030234e3405SStephen Boyd 	.open = simple_open,
10316038f373SArnd Bergmann 	.owner = THIS_MODULE,
10326038f373SArnd Bergmann 	.llseek = default_llseek,
10331395d3f0SSujith };
10341395d3f0SSujith 
1035c3b9f9e8SSujith Manoharan static ssize_t read_file_phy_err(struct file *file, char __user *user_buf,
1036c3b9f9e8SSujith Manoharan 				 size_t count, loff_t *ppos)
1037c3b9f9e8SSujith Manoharan {
1038c3b9f9e8SSujith Manoharan #define PHY_ERR(s, p) \
1039c3b9f9e8SSujith Manoharan 	len += scnprintf(buf + len, size - len, "%22s : %10u\n", s, \
1040c3b9f9e8SSujith Manoharan 			 sc->debug.stats.rxstats.phy_err_stats[p]);
1041c3b9f9e8SSujith Manoharan 
1042c3b9f9e8SSujith Manoharan 	struct ath_softc *sc = file->private_data;
1043c3b9f9e8SSujith Manoharan 	char *buf;
1044c3b9f9e8SSujith Manoharan 	unsigned int len = 0, size = 1600;
1045c3b9f9e8SSujith Manoharan 	ssize_t retval = 0;
1046c3b9f9e8SSujith Manoharan 
1047c3b9f9e8SSujith Manoharan 	buf = kzalloc(size, GFP_KERNEL);
1048c3b9f9e8SSujith Manoharan 	if (buf == NULL)
1049c3b9f9e8SSujith Manoharan 		return -ENOMEM;
1050c3b9f9e8SSujith Manoharan 
1051c3b9f9e8SSujith Manoharan 	PHY_ERR("UNDERRUN ERR", ATH9K_PHYERR_UNDERRUN);
1052c3b9f9e8SSujith Manoharan 	PHY_ERR("TIMING ERR", ATH9K_PHYERR_TIMING);
1053c3b9f9e8SSujith Manoharan 	PHY_ERR("PARITY ERR", ATH9K_PHYERR_PARITY);
1054c3b9f9e8SSujith Manoharan 	PHY_ERR("RATE ERR", ATH9K_PHYERR_RATE);
1055c3b9f9e8SSujith Manoharan 	PHY_ERR("LENGTH ERR", ATH9K_PHYERR_LENGTH);
1056c3b9f9e8SSujith Manoharan 	PHY_ERR("RADAR ERR", ATH9K_PHYERR_RADAR);
1057c3b9f9e8SSujith Manoharan 	PHY_ERR("SERVICE ERR", ATH9K_PHYERR_SERVICE);
1058c3b9f9e8SSujith Manoharan 	PHY_ERR("TOR ERR", ATH9K_PHYERR_TOR);
1059c3b9f9e8SSujith Manoharan 	PHY_ERR("OFDM-TIMING ERR", ATH9K_PHYERR_OFDM_TIMING);
1060c3b9f9e8SSujith Manoharan 	PHY_ERR("OFDM-SIGNAL-PARITY ERR", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
1061c3b9f9e8SSujith Manoharan 	PHY_ERR("OFDM-RATE ERR", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
1062c3b9f9e8SSujith Manoharan 	PHY_ERR("OFDM-LENGTH ERR", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
1063c3b9f9e8SSujith Manoharan 	PHY_ERR("OFDM-POWER-DROP ERR", ATH9K_PHYERR_OFDM_POWER_DROP);
1064c3b9f9e8SSujith Manoharan 	PHY_ERR("OFDM-SERVICE ERR", ATH9K_PHYERR_OFDM_SERVICE);
1065c3b9f9e8SSujith Manoharan 	PHY_ERR("OFDM-RESTART ERR", ATH9K_PHYERR_OFDM_RESTART);
1066c3b9f9e8SSujith Manoharan 	PHY_ERR("FALSE-RADAR-EXT ERR", ATH9K_PHYERR_FALSE_RADAR_EXT);
1067c3b9f9e8SSujith Manoharan 	PHY_ERR("CCK-TIMING ERR", ATH9K_PHYERR_CCK_TIMING);
1068c3b9f9e8SSujith Manoharan 	PHY_ERR("CCK-HEADER-CRC ERR", ATH9K_PHYERR_CCK_HEADER_CRC);
1069c3b9f9e8SSujith Manoharan 	PHY_ERR("CCK-RATE ERR", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
1070c3b9f9e8SSujith Manoharan 	PHY_ERR("CCK-SERVICE ERR", ATH9K_PHYERR_CCK_SERVICE);
1071c3b9f9e8SSujith Manoharan 	PHY_ERR("CCK-RESTART ERR", ATH9K_PHYERR_CCK_RESTART);
1072c3b9f9e8SSujith Manoharan 	PHY_ERR("CCK-LENGTH ERR", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
1073c3b9f9e8SSujith Manoharan 	PHY_ERR("CCK-POWER-DROP ERR", ATH9K_PHYERR_CCK_POWER_DROP);
1074c3b9f9e8SSujith Manoharan 	PHY_ERR("HT-CRC ERR", ATH9K_PHYERR_HT_CRC_ERROR);
1075c3b9f9e8SSujith Manoharan 	PHY_ERR("HT-LENGTH ERR", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
1076c3b9f9e8SSujith Manoharan 	PHY_ERR("HT-RATE ERR", ATH9K_PHYERR_HT_RATE_ILLEGAL);
1077c3b9f9e8SSujith Manoharan 
1078c3b9f9e8SSujith Manoharan 	if (len > size)
1079c3b9f9e8SSujith Manoharan 		len = size;
1080c3b9f9e8SSujith Manoharan 
1081c3b9f9e8SSujith Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1082c3b9f9e8SSujith Manoharan 	kfree(buf);
1083c3b9f9e8SSujith Manoharan 
1084c3b9f9e8SSujith Manoharan 	return retval;
1085c3b9f9e8SSujith Manoharan 
1086c3b9f9e8SSujith Manoharan #undef PHY_ERR
1087c3b9f9e8SSujith Manoharan }
1088c3b9f9e8SSujith Manoharan 
1089c3b9f9e8SSujith Manoharan static const struct file_operations fops_phy_err = {
1090c3b9f9e8SSujith Manoharan 	.read = read_file_phy_err,
1091c3b9f9e8SSujith Manoharan 	.open = simple_open,
1092c3b9f9e8SSujith Manoharan 	.owner = THIS_MODULE,
1093c3b9f9e8SSujith Manoharan 	.llseek = default_llseek,
1094c3b9f9e8SSujith Manoharan };
1095c3b9f9e8SSujith Manoharan 
10969bff0bc4SFelix Fietkau static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
10979bff0bc4SFelix Fietkau                                 size_t count, loff_t *ppos)
10989bff0bc4SFelix Fietkau {
10999bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
11009bff0bc4SFelix Fietkau 	char buf[32];
11019bff0bc4SFelix Fietkau 	unsigned int len;
11029bff0bc4SFelix Fietkau 
11032b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
11049bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
11059bff0bc4SFelix Fietkau }
11069bff0bc4SFelix Fietkau 
11079bff0bc4SFelix Fietkau static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
11089bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
11099bff0bc4SFelix Fietkau {
11109bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
11119bff0bc4SFelix Fietkau 	unsigned long regidx;
11129bff0bc4SFelix Fietkau 	char buf[32];
11139bff0bc4SFelix Fietkau 	ssize_t len;
11149bff0bc4SFelix Fietkau 
11159bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
11169bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
111704236066SDan Carpenter 		return -EFAULT;
11189bff0bc4SFelix Fietkau 
11199bff0bc4SFelix Fietkau 	buf[len] = '\0';
112027d7f477SJingoo Han 	if (kstrtoul(buf, 0, &regidx))
11219bff0bc4SFelix Fietkau 		return -EINVAL;
11229bff0bc4SFelix Fietkau 
11239bff0bc4SFelix Fietkau 	sc->debug.regidx = regidx;
11249bff0bc4SFelix Fietkau 	return count;
11259bff0bc4SFelix Fietkau }
11269bff0bc4SFelix Fietkau 
11279bff0bc4SFelix Fietkau static const struct file_operations fops_regidx = {
11289bff0bc4SFelix Fietkau 	.read = read_file_regidx,
11299bff0bc4SFelix Fietkau 	.write = write_file_regidx,
1130234e3405SStephen Boyd 	.open = simple_open,
11316038f373SArnd Bergmann 	.owner = THIS_MODULE,
11326038f373SArnd Bergmann 	.llseek = default_llseek,
11339bff0bc4SFelix Fietkau };
11349bff0bc4SFelix Fietkau 
11359bff0bc4SFelix Fietkau static ssize_t read_file_regval(struct file *file, char __user *user_buf,
11369bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
11379bff0bc4SFelix Fietkau {
11389bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
11399bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
11409bff0bc4SFelix Fietkau 	char buf[32];
11419bff0bc4SFelix Fietkau 	unsigned int len;
11429bff0bc4SFelix Fietkau 	u32 regval;
11439bff0bc4SFelix Fietkau 
114479d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
11459bff0bc4SFelix Fietkau 	regval = REG_READ_D(ah, sc->debug.regidx);
114679d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
11472b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", regval);
11489bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
11499bff0bc4SFelix Fietkau }
11509bff0bc4SFelix Fietkau 
11519bff0bc4SFelix Fietkau static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
11529bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
11539bff0bc4SFelix Fietkau {
11549bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
11559bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
11569bff0bc4SFelix Fietkau 	unsigned long regval;
11579bff0bc4SFelix Fietkau 	char buf[32];
11589bff0bc4SFelix Fietkau 	ssize_t len;
11599bff0bc4SFelix Fietkau 
11609bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
11619bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
116204236066SDan Carpenter 		return -EFAULT;
11639bff0bc4SFelix Fietkau 
11649bff0bc4SFelix Fietkau 	buf[len] = '\0';
116527d7f477SJingoo Han 	if (kstrtoul(buf, 0, &regval))
11669bff0bc4SFelix Fietkau 		return -EINVAL;
11679bff0bc4SFelix Fietkau 
116879d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
11699bff0bc4SFelix Fietkau 	REG_WRITE_D(ah, sc->debug.regidx, regval);
117079d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
11719bff0bc4SFelix Fietkau 	return count;
11729bff0bc4SFelix Fietkau }
11739bff0bc4SFelix Fietkau 
11749bff0bc4SFelix Fietkau static const struct file_operations fops_regval = {
11759bff0bc4SFelix Fietkau 	.read = read_file_regval,
11769bff0bc4SFelix Fietkau 	.write = write_file_regval,
1177234e3405SStephen Boyd 	.open = simple_open,
11786038f373SArnd Bergmann 	.owner = THIS_MODULE,
11796038f373SArnd Bergmann 	.llseek = default_llseek,
11809bff0bc4SFelix Fietkau };
11819bff0bc4SFelix Fietkau 
1182582d0064SVasanthakumar Thiagarajan #define REGDUMP_LINE_SIZE	20
1183582d0064SVasanthakumar Thiagarajan 
1184582d0064SVasanthakumar Thiagarajan static int open_file_regdump(struct inode *inode, struct file *file)
1185582d0064SVasanthakumar Thiagarajan {
1186582d0064SVasanthakumar Thiagarajan 	struct ath_softc *sc = inode->i_private;
1187582d0064SVasanthakumar Thiagarajan 	unsigned int len = 0;
1188582d0064SVasanthakumar Thiagarajan 	u8 *buf;
1189582d0064SVasanthakumar Thiagarajan 	int i;
1190582d0064SVasanthakumar Thiagarajan 	unsigned long num_regs, regdump_len, max_reg_offset;
1191582d0064SVasanthakumar Thiagarajan 
1192582d0064SVasanthakumar Thiagarajan 	max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
1193582d0064SVasanthakumar Thiagarajan 	num_regs = max_reg_offset / 4 + 1;
1194582d0064SVasanthakumar Thiagarajan 	regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
1195582d0064SVasanthakumar Thiagarajan 	buf = vmalloc(regdump_len);
1196582d0064SVasanthakumar Thiagarajan 	if (!buf)
1197582d0064SVasanthakumar Thiagarajan 		return -ENOMEM;
1198582d0064SVasanthakumar Thiagarajan 
1199582d0064SVasanthakumar Thiagarajan 	ath9k_ps_wakeup(sc);
1200582d0064SVasanthakumar Thiagarajan 	for (i = 0; i < num_regs; i++)
1201582d0064SVasanthakumar Thiagarajan 		len += scnprintf(buf + len, regdump_len - len,
1202582d0064SVasanthakumar Thiagarajan 			"0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
1203582d0064SVasanthakumar Thiagarajan 	ath9k_ps_restore(sc);
1204582d0064SVasanthakumar Thiagarajan 
1205582d0064SVasanthakumar Thiagarajan 	file->private_data = buf;
1206582d0064SVasanthakumar Thiagarajan 
1207582d0064SVasanthakumar Thiagarajan 	return 0;
1208582d0064SVasanthakumar Thiagarajan }
1209582d0064SVasanthakumar Thiagarajan 
1210582d0064SVasanthakumar Thiagarajan static const struct file_operations fops_regdump = {
1211582d0064SVasanthakumar Thiagarajan 	.open = open_file_regdump,
1212582d0064SVasanthakumar Thiagarajan 	.read = ath9k_debugfs_read_buf,
1213582d0064SVasanthakumar Thiagarajan 	.release = ath9k_debugfs_release_buf,
1214582d0064SVasanthakumar Thiagarajan 	.owner = THIS_MODULE,
1215582d0064SVasanthakumar Thiagarajan 	.llseek = default_llseek,/* read accesses f_pos */
1216582d0064SVasanthakumar Thiagarajan };
1217582d0064SVasanthakumar Thiagarajan 
1218d069a46bSRajkumar Manoharan static ssize_t read_file_dump_nfcal(struct file *file, char __user *user_buf,
1219d069a46bSRajkumar Manoharan 				    size_t count, loff_t *ppos)
1220d069a46bSRajkumar Manoharan {
1221d069a46bSRajkumar Manoharan 	struct ath_softc *sc = file->private_data;
1222d069a46bSRajkumar Manoharan 	struct ath_hw *ah = sc->sc_ah;
1223d069a46bSRajkumar Manoharan 	struct ath9k_nfcal_hist *h = sc->caldata.nfCalHist;
1224d069a46bSRajkumar Manoharan 	struct ath_common *common = ath9k_hw_common(ah);
1225d069a46bSRajkumar Manoharan 	struct ieee80211_conf *conf = &common->hw->conf;
1226d069a46bSRajkumar Manoharan 	u32 len = 0, size = 1500;
1227d069a46bSRajkumar Manoharan 	u32 i, j;
1228d069a46bSRajkumar Manoharan 	ssize_t retval = 0;
1229d069a46bSRajkumar Manoharan 	char *buf;
1230d069a46bSRajkumar Manoharan 	u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1231d069a46bSRajkumar Manoharan 	u8 nread;
1232d069a46bSRajkumar Manoharan 
1233d069a46bSRajkumar Manoharan 	buf = kzalloc(size, GFP_KERNEL);
1234d069a46bSRajkumar Manoharan 	if (!buf)
1235d069a46bSRajkumar Manoharan 		return -ENOMEM;
1236d069a46bSRajkumar Manoharan 
12375e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len,
1238d069a46bSRajkumar Manoharan 			 "Channel Noise Floor : %d\n", ah->noise);
12395e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len,
1240d069a46bSRajkumar Manoharan 			 "Chain | privNF | # Readings | NF Readings\n");
1241d069a46bSRajkumar Manoharan 	for (i = 0; i < NUM_NF_READINGS; i++) {
1242d069a46bSRajkumar Manoharan 		if (!(chainmask & (1 << i)) ||
1243d069a46bSRajkumar Manoharan 		    ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1244d069a46bSRajkumar Manoharan 			continue;
1245d069a46bSRajkumar Manoharan 
1246d069a46bSRajkumar Manoharan 		nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
12475e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, size - len, " %d\t %d\t %d\t\t",
1248d069a46bSRajkumar Manoharan 				 i, h[i].privNF, nread);
1249d069a46bSRajkumar Manoharan 		for (j = 0; j < nread; j++)
12505e88ba62SZefir Kurtisi 			len += scnprintf(buf + len, size - len,
1251d069a46bSRajkumar Manoharan 					 " %d", h[i].nfCalBuffer[j]);
12525e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, size - len, "\n");
1253d069a46bSRajkumar Manoharan 	}
1254d069a46bSRajkumar Manoharan 
1255d069a46bSRajkumar Manoharan 	if (len > size)
1256d069a46bSRajkumar Manoharan 		len = size;
1257d069a46bSRajkumar Manoharan 
1258d069a46bSRajkumar Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1259d069a46bSRajkumar Manoharan 	kfree(buf);
1260d069a46bSRajkumar Manoharan 
1261d069a46bSRajkumar Manoharan 	return retval;
1262d069a46bSRajkumar Manoharan }
1263d069a46bSRajkumar Manoharan 
1264d069a46bSRajkumar Manoharan static const struct file_operations fops_dump_nfcal = {
1265d069a46bSRajkumar Manoharan 	.read = read_file_dump_nfcal,
1266234e3405SStephen Boyd 	.open = simple_open,
1267d069a46bSRajkumar Manoharan 	.owner = THIS_MODULE,
1268d069a46bSRajkumar Manoharan 	.llseek = default_llseek,
1269d069a46bSRajkumar Manoharan };
1270d069a46bSRajkumar Manoharan 
12714df50ca8SRajkumar Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
12724df50ca8SRajkumar Manoharan static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
12734df50ca8SRajkumar Manoharan 				size_t count, loff_t *ppos)
12744df50ca8SRajkumar Manoharan {
12754df50ca8SRajkumar Manoharan 	struct ath_softc *sc = file->private_data;
12764df50ca8SRajkumar Manoharan 	u32 len = 0, size = 1500;
12774df50ca8SRajkumar Manoharan 	char *buf;
12784df50ca8SRajkumar Manoharan 	size_t retval;
12794df50ca8SRajkumar Manoharan 
12804df50ca8SRajkumar Manoharan 	buf = kzalloc(size, GFP_KERNEL);
12814df50ca8SRajkumar Manoharan 	if (buf == NULL)
12824df50ca8SRajkumar Manoharan 		return -ENOMEM;
12834df50ca8SRajkumar Manoharan 
1284ac46ba43SSujith Manoharan 	if (!sc->sc_ah->common.btcoex_enabled) {
12855e88ba62SZefir Kurtisi 		len = scnprintf(buf, size, "%s\n",
1286ac46ba43SSujith Manoharan 				"BTCOEX is disabled");
1287ac46ba43SSujith Manoharan 		goto exit;
1288ac46ba43SSujith Manoharan 	}
12894df50ca8SRajkumar Manoharan 
1290ac46ba43SSujith Manoharan 	len = ath9k_dump_btcoex(sc, buf, size);
1291ac46ba43SSujith Manoharan exit:
12924df50ca8SRajkumar Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
12934df50ca8SRajkumar Manoharan 	kfree(buf);
12944df50ca8SRajkumar Manoharan 
12954df50ca8SRajkumar Manoharan 	return retval;
12964df50ca8SRajkumar Manoharan }
12974df50ca8SRajkumar Manoharan 
12984df50ca8SRajkumar Manoharan static const struct file_operations fops_btcoex = {
12994df50ca8SRajkumar Manoharan 	.read = read_file_btcoex,
13004df50ca8SRajkumar Manoharan 	.open = simple_open,
13014df50ca8SRajkumar Manoharan 	.owner = THIS_MODULE,
13024df50ca8SRajkumar Manoharan 	.llseek = default_llseek,
13034df50ca8SRajkumar Manoharan };
13044df50ca8SRajkumar Manoharan #endif
13054df50ca8SRajkumar Manoharan 
1306c175db87SSujith Manoharan /* Ethtool support for get-stats */
1307c175db87SSujith Manoharan 
1308c175db87SSujith Manoharan #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1309c175db87SSujith Manoharan static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1310c175db87SSujith Manoharan 	"tx_pkts_nic",
1311c175db87SSujith Manoharan 	"tx_bytes_nic",
1312c175db87SSujith Manoharan 	"rx_pkts_nic",
1313c175db87SSujith Manoharan 	"rx_bytes_nic",
1314c175db87SSujith Manoharan 	AMKSTR(d_tx_pkts),
1315c175db87SSujith Manoharan 	AMKSTR(d_tx_bytes),
1316c175db87SSujith Manoharan 	AMKSTR(d_tx_mpdus_queued),
1317c175db87SSujith Manoharan 	AMKSTR(d_tx_mpdus_completed),
1318c175db87SSujith Manoharan 	AMKSTR(d_tx_mpdu_xretries),
1319c175db87SSujith Manoharan 	AMKSTR(d_tx_aggregates),
1320c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdus_queued_hw),
1321c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdus_queued_sw),
1322c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdus_completed),
1323c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdu_retries),
1324c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdu_xretries),
1325c175db87SSujith Manoharan 	AMKSTR(d_tx_fifo_underrun),
1326c175db87SSujith Manoharan 	AMKSTR(d_tx_op_exceeded),
1327c175db87SSujith Manoharan 	AMKSTR(d_tx_timer_expiry),
1328c175db87SSujith Manoharan 	AMKSTR(d_tx_desc_cfg_err),
1329c175db87SSujith Manoharan 	AMKSTR(d_tx_data_underrun),
1330c175db87SSujith Manoharan 	AMKSTR(d_tx_delim_underrun),
133118c45b10SBen Greear 	"d_rx_crc_err",
1332c175db87SSujith Manoharan 	"d_rx_decrypt_crc_err",
1333c175db87SSujith Manoharan 	"d_rx_phy_err",
1334c175db87SSujith Manoharan 	"d_rx_mic_err",
1335c175db87SSujith Manoharan 	"d_rx_pre_delim_crc_err",
1336c175db87SSujith Manoharan 	"d_rx_post_delim_crc_err",
1337c175db87SSujith Manoharan 	"d_rx_decrypt_busy_err",
1338c175db87SSujith Manoharan 
1339c175db87SSujith Manoharan 	"d_rx_phyerr_radar",
1340c175db87SSujith Manoharan 	"d_rx_phyerr_ofdm_timing",
1341c175db87SSujith Manoharan 	"d_rx_phyerr_cck_timing",
1342c175db87SSujith Manoharan 
1343c175db87SSujith Manoharan };
1344c175db87SSujith Manoharan #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1345c175db87SSujith Manoharan 
1346c175db87SSujith Manoharan void ath9k_get_et_strings(struct ieee80211_hw *hw,
1347c175db87SSujith Manoharan 			  struct ieee80211_vif *vif,
1348c175db87SSujith Manoharan 			  u32 sset, u8 *data)
1349c175db87SSujith Manoharan {
1350c175db87SSujith Manoharan 	if (sset == ETH_SS_STATS)
1351c175db87SSujith Manoharan 		memcpy(data, *ath9k_gstrings_stats,
1352c175db87SSujith Manoharan 		       sizeof(ath9k_gstrings_stats));
1353c175db87SSujith Manoharan }
1354c175db87SSujith Manoharan 
1355c175db87SSujith Manoharan int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
1356c175db87SSujith Manoharan 			    struct ieee80211_vif *vif, int sset)
1357c175db87SSujith Manoharan {
1358c175db87SSujith Manoharan 	if (sset == ETH_SS_STATS)
1359c175db87SSujith Manoharan 		return ATH9K_SSTATS_LEN;
1360c175db87SSujith Manoharan 	return 0;
1361c175db87SSujith Manoharan }
1362c175db87SSujith Manoharan 
1363c175db87SSujith Manoharan #define AWDATA(elem)							\
1364c175db87SSujith Manoharan 	do {								\
1365c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
1366c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
1367c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
1368c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
1369c175db87SSujith Manoharan 	} while (0)
1370c175db87SSujith Manoharan 
1371c175db87SSujith Manoharan #define AWDATA_RX(elem)						\
1372c175db87SSujith Manoharan 	do {							\
1373c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.rxstats.elem;	\
1374c175db87SSujith Manoharan 	} while (0)
1375c175db87SSujith Manoharan 
1376c175db87SSujith Manoharan void ath9k_get_et_stats(struct ieee80211_hw *hw,
1377c175db87SSujith Manoharan 			struct ieee80211_vif *vif,
1378c175db87SSujith Manoharan 			struct ethtool_stats *stats, u64 *data)
1379c175db87SSujith Manoharan {
1380c175db87SSujith Manoharan 	struct ath_softc *sc = hw->priv;
1381c175db87SSujith Manoharan 	int i = 0;
1382c175db87SSujith Manoharan 
1383c175db87SSujith Manoharan 	data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
1384c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
1385c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
1386c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
1387c175db87SSujith Manoharan 	data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
1388c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
1389c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
1390c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
1391c175db87SSujith Manoharan 	AWDATA_RX(rx_pkts_all);
1392c175db87SSujith Manoharan 	AWDATA_RX(rx_bytes_all);
1393c175db87SSujith Manoharan 
1394c175db87SSujith Manoharan 	AWDATA(tx_pkts_all);
1395c175db87SSujith Manoharan 	AWDATA(tx_bytes_all);
1396c175db87SSujith Manoharan 	AWDATA(queued);
1397c175db87SSujith Manoharan 	AWDATA(completed);
1398c175db87SSujith Manoharan 	AWDATA(xretries);
1399c175db87SSujith Manoharan 	AWDATA(a_aggr);
1400c175db87SSujith Manoharan 	AWDATA(a_queued_hw);
1401c175db87SSujith Manoharan 	AWDATA(a_queued_sw);
1402c175db87SSujith Manoharan 	AWDATA(a_completed);
1403c175db87SSujith Manoharan 	AWDATA(a_retries);
1404c175db87SSujith Manoharan 	AWDATA(a_xretries);
1405c175db87SSujith Manoharan 	AWDATA(fifo_underrun);
1406c175db87SSujith Manoharan 	AWDATA(xtxop);
1407c175db87SSujith Manoharan 	AWDATA(timer_exp);
1408c175db87SSujith Manoharan 	AWDATA(desc_cfg_err);
1409c175db87SSujith Manoharan 	AWDATA(data_underrun);
1410c175db87SSujith Manoharan 	AWDATA(delim_underrun);
1411c175db87SSujith Manoharan 
141218c45b10SBen Greear 	AWDATA_RX(crc_err);
1413c175db87SSujith Manoharan 	AWDATA_RX(decrypt_crc_err);
1414c175db87SSujith Manoharan 	AWDATA_RX(phy_err);
1415c175db87SSujith Manoharan 	AWDATA_RX(mic_err);
1416c175db87SSujith Manoharan 	AWDATA_RX(pre_delim_crc_err);
1417c175db87SSujith Manoharan 	AWDATA_RX(post_delim_crc_err);
1418c175db87SSujith Manoharan 	AWDATA_RX(decrypt_busy_err);
1419c175db87SSujith Manoharan 
1420c175db87SSujith Manoharan 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
1421c175db87SSujith Manoharan 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
1422c175db87SSujith Manoharan 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
1423c175db87SSujith Manoharan 
1424c175db87SSujith Manoharan 	WARN_ON(i != ATH9K_SSTATS_LEN);
1425c175db87SSujith Manoharan }
1426c175db87SSujith Manoharan 
1427af690092SSujith Manoharan void ath9k_deinit_debug(struct ath_softc *sc)
1428af690092SSujith Manoharan {
1429f65c0825SSujith Manoharan 	ath9k_spectral_deinit_debug(sc);
1430af690092SSujith Manoharan }
1431af690092SSujith Manoharan 
14324d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah)
1433203c4805SLuis R. Rodriguez {
1434bc974f4aSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(ah);
1435bc974f4aSLuis R. Rodriguez 	struct ath_softc *sc = (struct ath_softc *) common->priv;
14364d6b228dSLuis R. Rodriguez 
1437eb272441SBen Greear 	sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1438eb272441SBen Greear 						   sc->hw->wiphy->debugfsdir);
1439203c4805SLuis R. Rodriguez 	if (!sc->debug.debugfs_phy)
1440c8a72c00SFelix Fietkau 		return -ENOMEM;
1441203c4805SLuis R. Rodriguez 
1442a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
1443c70cab1aSFelix Fietkau 	debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1444c70cab1aSFelix Fietkau 			    sc, &fops_debug);
1445a830df07SFelix Fietkau #endif
144629942bc1SZefir Kurtisi 
144729942bc1SZefir Kurtisi 	ath9k_dfs_init_debug(sc);
1448ef6b19e4SSujith Manoharan 	ath9k_tx99_init_debug(sc);
1449f65c0825SSujith Manoharan 	ath9k_spectral_init_debug(sc);
145029942bc1SZefir Kurtisi 
1451c70cab1aSFelix Fietkau 	debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
1452c70cab1aSFelix Fietkau 			    &fops_dma);
1453c70cab1aSFelix Fietkau 	debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
1454c70cab1aSFelix Fietkau 			    &fops_interrupt);
1455c70cab1aSFelix Fietkau 	debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc,
1456c70cab1aSFelix Fietkau 			    &fops_xmit);
1457c0b74876SSujith Manoharan 	debugfs_create_file("queues", S_IRUSR, sc->debug.debugfs_phy, sc,
1458c0b74876SSujith Manoharan 			    &fops_queues);
14597702e788SFelix Fietkau 	debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1460bea843c7SSujith Manoharan 			   &sc->tx.txq_max_pending[IEEE80211_AC_BK]);
14617702e788SFelix Fietkau 	debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1462bea843c7SSujith Manoharan 			   &sc->tx.txq_max_pending[IEEE80211_AC_BE]);
14637702e788SFelix Fietkau 	debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1464bea843c7SSujith Manoharan 			   &sc->tx.txq_max_pending[IEEE80211_AC_VI]);
14657702e788SFelix Fietkau 	debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1466bea843c7SSujith Manoharan 			   &sc->tx.txq_max_pending[IEEE80211_AC_VO]);
1467c70cab1aSFelix Fietkau 	debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy, sc,
1468c70cab1aSFelix Fietkau 			    &fops_misc);
1469f8b815dcSSujith Manoharan 	debugfs_create_file("reset", S_IRUSR, sc->debug.debugfs_phy, sc,
1470f8b815dcSSujith Manoharan 			    &fops_reset);
1471c70cab1aSFelix Fietkau 	debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy, sc,
1472c70cab1aSFelix Fietkau 			    &fops_recv);
1473c3b9f9e8SSujith Manoharan 	debugfs_create_file("phy_err", S_IRUSR, sc->debug.debugfs_phy, sc,
1474c3b9f9e8SSujith Manoharan 			    &fops_phy_err);
1475ca6d4a74SFelix Fietkau 	debugfs_create_u8("rx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
1476ca6d4a74SFelix Fietkau 			  &ah->rxchainmask);
1477ca6d4a74SFelix Fietkau 	debugfs_create_u8("tx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
1478ca6d4a74SFelix Fietkau 			  &ah->txchainmask);
14796e4d291eSSujith Manoharan 	debugfs_create_file("ani", S_IRUSR | S_IWUSR,
14806e4d291eSSujith Manoharan 			    sc->debug.debugfs_phy, sc, &fops_ani);
148174673db9SFelix Fietkau 	debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
148274673db9SFelix Fietkau 			    &sc->sc_ah->config.enable_paprd);
1483c70cab1aSFelix Fietkau 	debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1484c70cab1aSFelix Fietkau 			    sc, &fops_regidx);
1485c70cab1aSFelix Fietkau 	debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1486c70cab1aSFelix Fietkau 			    sc, &fops_regval);
1487c70cab1aSFelix Fietkau 	debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1488c70cab1aSFelix Fietkau 			    sc->debug.debugfs_phy,
1489c70cab1aSFelix Fietkau 			    &ah->config.cwm_ignore_extcca);
1490c70cab1aSFelix Fietkau 	debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
1491c70cab1aSFelix Fietkau 			    &fops_regdump);
1492d069a46bSRajkumar Manoharan 	debugfs_create_file("dump_nfcal", S_IRUSR, sc->debug.debugfs_phy, sc,
1493d069a46bSRajkumar Manoharan 			    &fops_dump_nfcal);
1494f2c3c952SOleksij Rempel 
1495*29bf801eSOleksij Rempel 	ath9k_cmn_debug_base_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
1496f2c3c952SOleksij Rempel 	ath9k_cmn_debug_modal_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
1497f2c3c952SOleksij Rempel 
1498691680b8SFelix Fietkau 	debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
1499691680b8SFelix Fietkau 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
1500691680b8SFelix Fietkau 	debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
1501691680b8SFelix Fietkau 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
15024eba10ccSSujith Manoharan 	debugfs_create_file("antenna_diversity", S_IRUSR,
15034eba10ccSSujith Manoharan 			    sc->debug.debugfs_phy, sc, &fops_antenna_diversity);
15044df50ca8SRajkumar Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
150536e8825eSSujith Manoharan 	debugfs_create_file("bt_ant_diversity", S_IRUSR | S_IWUSR,
150636e8825eSSujith Manoharan 			    sc->debug.debugfs_phy, sc, &fops_bt_ant_diversity);
15074df50ca8SRajkumar Manoharan 	debugfs_create_file("btcoex", S_IRUSR, sc->debug.debugfs_phy, sc,
15084df50ca8SRajkumar Manoharan 			    &fops_btcoex);
15094df50ca8SRajkumar Manoharan #endif
151089f927afSLuis R. Rodriguez 
1511203c4805SLuis R. Rodriguez 	return 0;
1512203c4805SLuis R. Rodriguez }
1513