xref: /openbmc/linux/drivers/net/wireless/ath/ath9k/debug.c (revision 053f9852b95e7721cf3b615539d701bae3e17ddb)
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 },
151d0480d43SAndrea Greco 		{ "SPUR DOWN", ah->stats.ast_ani_spurdown },
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 
2053f557202SAndrey Utkin 	if (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 
404631bee25SArend van Spriel static int read_file_dma(struct seq_file *file, void *data)
405203c4805SLuis R. Rodriguez {
4064447d815SArend van Spriel 	struct ieee80211_hw *hw = dev_get_drvdata(file->private);
4074447d815SArend van Spriel 	struct ath_softc *sc = hw->priv;
408203c4805SLuis R. Rodriguez 	struct ath_hw *ah = sc->sc_ah;
409203c4805SLuis R. Rodriguez 	u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
410203c4805SLuis R. Rodriguez 	int i, qcuOffset = 0, dcuOffset = 0;
411203c4805SLuis R. Rodriguez 	u32 *qcuBase = &val[0], *dcuBase = &val[4];
412203c4805SLuis R. Rodriguez 
4137cf4a2e7SSujith 	ath9k_ps_wakeup(sc);
4147cf4a2e7SSujith 
415475a6e4dSLuis R. Rodriguez 	REG_WRITE_D(ah, AR_MACMISC,
416203c4805SLuis R. Rodriguez 		  ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
417203c4805SLuis R. Rodriguez 		   (AR_MACMISC_MISC_OBS_BUS_1 <<
418203c4805SLuis R. Rodriguez 		    AR_MACMISC_MISC_OBS_BUS_MSB_S)));
419203c4805SLuis R. Rodriguez 
420631bee25SArend van Spriel 	seq_puts(file, "Raw DMA Debug values:\n");
421203c4805SLuis R. Rodriguez 
422203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
423203c4805SLuis R. Rodriguez 		if (i % 4 == 0)
424631bee25SArend van Spriel 			seq_puts(file, "\n");
425203c4805SLuis R. Rodriguez 
426475a6e4dSLuis R. Rodriguez 		val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
427631bee25SArend van Spriel 		seq_printf(file, "%d: %08x ", i, val[i]);
428203c4805SLuis R. Rodriguez 	}
429203c4805SLuis R. Rodriguez 
430631bee25SArend van Spriel 	seq_puts(file, "\n\n");
431631bee25SArend van Spriel 	seq_puts(file, "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
432203c4805SLuis R. Rodriguez 
433203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
434203c4805SLuis R. Rodriguez 		if (i == 8) {
435203c4805SLuis R. Rodriguez 			qcuOffset = 0;
436203c4805SLuis R. Rodriguez 			qcuBase++;
437203c4805SLuis R. Rodriguez 		}
438203c4805SLuis R. Rodriguez 
439203c4805SLuis R. Rodriguez 		if (i == 6) {
440203c4805SLuis R. Rodriguez 			dcuOffset = 0;
441203c4805SLuis R. Rodriguez 			dcuBase++;
442203c4805SLuis R. Rodriguez 		}
443203c4805SLuis R. Rodriguez 
444631bee25SArend van Spriel 		seq_printf(file, "%2d          %2x      %1x     %2x           %2x\n",
445203c4805SLuis R. Rodriguez 			   i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
446203c4805SLuis R. Rodriguez 			   (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
447a017ff75SDan Carpenter 			   (val[2] & (0x7 << (i * 3))) >> (i * 3),
448203c4805SLuis R. Rodriguez 			   (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
449203c4805SLuis R. Rodriguez 	}
450203c4805SLuis R. Rodriguez 
451631bee25SArend van Spriel 	seq_puts(file, "\n");
452203c4805SLuis R. Rodriguez 
453631bee25SArend van Spriel 	seq_printf(file, "qcu_stitch state:   %2x    qcu_fetch state:        %2x\n",
454203c4805SLuis R. Rodriguez 		   (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
455631bee25SArend van Spriel 	seq_printf(file, "qcu_complete state: %2x    dcu_complete state:     %2x\n",
456203c4805SLuis R. Rodriguez 		   (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
457631bee25SArend van Spriel 	seq_printf(file, "dcu_arb state:      %2x    dcu_fp state:           %2x\n",
458203c4805SLuis R. Rodriguez 		   (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
459631bee25SArend van Spriel 	seq_printf(file, "chan_idle_dur:     %3d    chan_idle_dur_valid:     %1d\n",
460203c4805SLuis R. Rodriguez 		   (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
461631bee25SArend van Spriel 	seq_printf(file, "txfifo_valid_0:      %1d    txfifo_valid_1:          %1d\n",
462203c4805SLuis R. Rodriguez 		   (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
463631bee25SArend van Spriel 	seq_printf(file, "txfifo_dcu_num_0:   %2d    txfifo_dcu_num_1:       %2d\n",
464203c4805SLuis R. Rodriguez 		   (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
465203c4805SLuis R. Rodriguez 
466631bee25SArend van Spriel 	seq_printf(file, "pcu observe: 0x%x\n", REG_READ_D(ah, AR_OBS_BUS_1));
467631bee25SArend van Spriel 	seq_printf(file, "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
468203c4805SLuis R. Rodriguez 
4697cf4a2e7SSujith 	ath9k_ps_restore(sc);
4707cf4a2e7SSujith 
471631bee25SArend van Spriel 	return 0;
472631bee25SArend van Spriel }
4732b87f3aaSDan Carpenter 
474203c4805SLuis R. Rodriguez void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
475203c4805SLuis R. Rodriguez {
476203c4805SLuis R. Rodriguez 	if (status)
477203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.total++;
478a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
479a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXLP)
480a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxlp++;
481a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXHP)
482a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxhp++;
48308578b8fSLuis R. Rodriguez 		if (status & ATH9K_INT_BB_WATCHDOG)
48408578b8fSLuis R. Rodriguez 			sc->debug.stats.istats.bb_watchdog++;
485a9616f41SLuis R. Rodriguez 	} else {
486203c4805SLuis R. Rodriguez 		if (status & ATH9K_INT_RX)
487203c4805SLuis R. Rodriguez 			sc->debug.stats.istats.rxok++;
488a9616f41SLuis R. Rodriguez 	}
489203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXEOL)
490203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxeol++;
491203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXORN)
492203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxorn++;
493203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TX)
494203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txok++;
495203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TXURN)
496203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txurn++;
497203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXPHY)
498203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxphyerr++;
499203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXKCM)
500203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rx_keycache_miss++;
501203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_SWBA)
502203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.swba++;
503203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BMISS)
504203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bmiss++;
505203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BNR)
506203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bnr++;
507203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CST)
508203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cst++;
509203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_GTT)
510203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.gtt++;
511203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TIM)
512203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.tim++;
513203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CABEND)
514203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cabend++;
515203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIMSYNC)
516203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtimsync++;
517203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIM)
518203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtim++;
5196dde1aabSMohammed Shafi Shajakhan 	if (status & ATH9K_INT_TSFOOR)
5206dde1aabSMohammed Shafi Shajakhan 		sc->debug.stats.istats.tsfoor++;
52197ba515aSSujith Manoharan 	if (status & ATH9K_INT_MCI)
52297ba515aSSujith Manoharan 		sc->debug.stats.istats.mci++;
523c9e6e980SMohammed Shafi Shajakhan 	if (status & ATH9K_INT_GENTIMER)
524c9e6e980SMohammed Shafi Shajakhan 		sc->debug.stats.istats.gen_timer++;
525203c4805SLuis R. Rodriguez }
526203c4805SLuis R. Rodriguez 
527631bee25SArend van Spriel static int read_file_interrupt(struct seq_file *file, void *data)
528203c4805SLuis R. Rodriguez {
5294447d815SArend van Spriel 	struct ieee80211_hw *hw = dev_get_drvdata(file->private);
5304447d815SArend van Spriel 	struct ath_softc *sc = hw->priv;
531462e58f2SBen Greear 
532462e58f2SBen Greear #define PR_IS(a, s)						\
533462e58f2SBen Greear 	do {							\
534631bee25SArend van Spriel 		seq_printf(file, "%21s: %10u\n", a,		\
535462e58f2SBen Greear 			   sc->debug.stats.istats.s);		\
536462e58f2SBen Greear 	} while (0)
537203c4805SLuis R. Rodriguez 
538a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
539462e58f2SBen Greear 		PR_IS("RXLP", rxlp);
540462e58f2SBen Greear 		PR_IS("RXHP", rxhp);
541d5e5f685SColin Ian King 		PR_IS("WATCHDOG", bb_watchdog);
542a9616f41SLuis R. Rodriguez 	} else {
543462e58f2SBen Greear 		PR_IS("RX", rxok);
544a9616f41SLuis R. Rodriguez 	}
545462e58f2SBen Greear 	PR_IS("RXEOL", rxeol);
546462e58f2SBen Greear 	PR_IS("RXORN", rxorn);
547462e58f2SBen Greear 	PR_IS("TX", txok);
548462e58f2SBen Greear 	PR_IS("TXURN", txurn);
549462e58f2SBen Greear 	PR_IS("MIB", mib);
550462e58f2SBen Greear 	PR_IS("RXPHY", rxphyerr);
551462e58f2SBen Greear 	PR_IS("RXKCM", rx_keycache_miss);
552462e58f2SBen Greear 	PR_IS("SWBA", swba);
553462e58f2SBen Greear 	PR_IS("BMISS", bmiss);
554462e58f2SBen Greear 	PR_IS("BNR", bnr);
555462e58f2SBen Greear 	PR_IS("CST", cst);
556462e58f2SBen Greear 	PR_IS("GTT", gtt);
557462e58f2SBen Greear 	PR_IS("TIM", tim);
558462e58f2SBen Greear 	PR_IS("CABEND", cabend);
559462e58f2SBen Greear 	PR_IS("DTIMSYNC", dtimsync);
560462e58f2SBen Greear 	PR_IS("DTIM", dtim);
561462e58f2SBen Greear 	PR_IS("TSFOOR", tsfoor);
56297ba515aSSujith Manoharan 	PR_IS("MCI", mci);
563c9e6e980SMohammed Shafi Shajakhan 	PR_IS("GENTIMER", gen_timer);
564462e58f2SBen Greear 	PR_IS("TOTAL", total);
565203c4805SLuis R. Rodriguez 
566631bee25SArend van Spriel 	seq_puts(file, "SYNC_CAUSE stats:\n");
5676dde1aabSMohammed Shafi Shajakhan 
568462e58f2SBen Greear 	PR_IS("Sync-All", sync_cause_all);
569462e58f2SBen Greear 	PR_IS("RTC-IRQ", sync_rtc_irq);
570462e58f2SBen Greear 	PR_IS("MAC-IRQ", sync_mac_irq);
571462e58f2SBen Greear 	PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
572462e58f2SBen Greear 	PR_IS("APB-Timeout", apb_timeout);
573462e58f2SBen Greear 	PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
574462e58f2SBen Greear 	PR_IS("HOST1-Fatal", host1_fatal);
575462e58f2SBen Greear 	PR_IS("HOST1-Perr", host1_perr);
576462e58f2SBen Greear 	PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
577462e58f2SBen Greear 	PR_IS("RADM-CPL-EP", radm_cpl_ep);
578462e58f2SBen Greear 	PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
579462e58f2SBen Greear 	PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
580462e58f2SBen Greear 	PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
581462e58f2SBen Greear 	PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
582462e58f2SBen Greear 	PR_IS("Local-Bus-Timeout", local_timeout);
583462e58f2SBen Greear 	PR_IS("PM-Access", pm_access);
584462e58f2SBen Greear 	PR_IS("MAC-Awake", mac_awake);
585462e58f2SBen Greear 	PR_IS("MAC-Asleep", mac_asleep);
586462e58f2SBen Greear 	PR_IS("MAC-Sleep-Access", mac_sleep_access);
5872b87f3aaSDan Carpenter 
588631bee25SArend van Spriel 	return 0;
589631bee25SArend van Spriel }
590462e58f2SBen Greear 
591631bee25SArend van Spriel static int read_file_xmit(struct seq_file *file, void *data)
592fec247c0SSujith {
5934447d815SArend van Spriel 	struct ieee80211_hw *hw = dev_get_drvdata(file->private);
5944447d815SArend van Spriel 	struct ath_softc *sc = hw->priv;
595fec247c0SSujith 
596631bee25SArend van Spriel 	seq_printf(file, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
597fec247c0SSujith 
598fec247c0SSujith 	PR("MPDUs Queued:    ", queued);
599fec247c0SSujith 	PR("MPDUs Completed: ", completed);
6005a6f78afSFelix Fietkau 	PR("MPDUs XRetried:  ", xretries);
601fec247c0SSujith 	PR("Aggregates:      ", a_aggr);
602bda8addaSBen Greear 	PR("AMPDUs Queued HW:", a_queued_hw);
603fec247c0SSujith 	PR("AMPDUs Completed:", a_completed);
604fec247c0SSujith 	PR("AMPDUs Retried:  ", a_retries);
605fec247c0SSujith 	PR("AMPDUs XRetried: ", a_xretries);
6064d900389SBen Greear 	PR("TXERR Filtered:  ", txerr_filtered);
607fec247c0SSujith 	PR("FIFO Underrun:   ", fifo_underrun);
608fec247c0SSujith 	PR("TXOP Exceeded:   ", xtxop);
609fec247c0SSujith 	PR("TXTIMER Expiry:  ", timer_exp);
610fec247c0SSujith 	PR("DESC CFG Error:  ", desc_cfg_err);
611fec247c0SSujith 	PR("DATA Underrun:   ", data_underrun);
612fec247c0SSujith 	PR("DELIM Underrun:  ", delim_underrun);
61399c15bf5SBen Greear 	PR("TX-Pkts-All:     ", tx_pkts_all);
61499c15bf5SBen Greear 	PR("TX-Bytes-All:    ", tx_bytes_all);
61578ef731cSSujith Manoharan 	PR("HW-put-tx-buf:   ", puttxbuf);
61678ef731cSSujith Manoharan 	PR("HW-tx-start:     ", txstart);
61778ef731cSSujith Manoharan 	PR("HW-tx-proc-desc: ", txprocdesc);
618a5a0bca1SBen Greear 	PR("TX-Failed:       ", txfailed);
619fec247c0SSujith 
620631bee25SArend van Spriel 	return 0;
6217f010c93SBen Greear }
6227f010c93SBen Greear 
623631bee25SArend van Spriel static void print_queue(struct ath_softc *sc, struct ath_txq *txq,
624631bee25SArend van Spriel 			struct seq_file *file)
62518fcf1c6SFelix Fietkau {
62618fcf1c6SFelix Fietkau 	ath_txq_lock(sc, txq);
62718fcf1c6SFelix Fietkau 
628631bee25SArend van Spriel 	seq_printf(file, "%s: %d ", "qnum", txq->axq_qnum);
629631bee25SArend van Spriel 	seq_printf(file, "%s: %2d ", "qdepth", txq->axq_depth);
630631bee25SArend van Spriel 	seq_printf(file, "%s: %2d ", "ampdu-depth", txq->axq_ampdu_depth);
63150f08edfSToke Høiland-Jørgensen 	seq_printf(file, "%s: %3d\n", "pending", txq->pending_frames);
63218fcf1c6SFelix Fietkau 
63318fcf1c6SFelix Fietkau 	ath_txq_unlock(sc, txq);
63418fcf1c6SFelix Fietkau }
63518fcf1c6SFelix Fietkau 
636631bee25SArend van Spriel static int read_file_queues(struct seq_file *file, void *data)
637c0b74876SSujith Manoharan {
6384447d815SArend van Spriel 	struct ieee80211_hw *hw = dev_get_drvdata(file->private);
6394447d815SArend van Spriel 	struct ath_softc *sc = hw->priv;
640c0b74876SSujith Manoharan 	struct ath_txq *txq;
641c0b74876SSujith Manoharan 	int i;
6422120ac96SJoe Perches 	static const char *qname[4] = {
6432120ac96SJoe Perches 		"VO", "VI", "BE", "BK"
6442120ac96SJoe Perches 	};
645c0b74876SSujith Manoharan 
646c0b74876SSujith Manoharan 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
647c0b74876SSujith Manoharan 		txq = sc->tx.txq_map[i];
648631bee25SArend van Spriel 		seq_printf(file, "(%s):  ", qname[i]);
649631bee25SArend van Spriel 		print_queue(sc, txq, file);
650c0b74876SSujith Manoharan 	}
651c0b74876SSujith Manoharan 
652631bee25SArend van Spriel 	seq_puts(file, "(CAB): ");
653631bee25SArend van Spriel 	print_queue(sc, sc->beacon.cabq, file);
65418fcf1c6SFelix Fietkau 
655631bee25SArend van Spriel 	return 0;
656c0b74876SSujith Manoharan }
657c0b74876SSujith Manoharan 
658631bee25SArend van Spriel static int read_file_misc(struct seq_file *file, void *data)
65955f6d0ffSBen Greear {
6604447d815SArend van Spriel 	struct ieee80211_hw *hw = dev_get_drvdata(file->private);
6614447d815SArend van Spriel 	struct ath_softc *sc = hw->priv;
66255f6d0ffSBen Greear 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
6636bcf6f64SSujith Manoharan 	struct ath9k_vif_iter_data iter_data;
6649a9c4fbcSRajkumar Manoharan 	struct ath_chanctx *ctx;
66555f6d0ffSBen Greear 	unsigned int reg;
6669a9c4fbcSRajkumar Manoharan 	u32 rxfilter, i;
6676bcf6f64SSujith Manoharan 
668631bee25SArend van Spriel 	seq_printf(file, "BSSID: %pM\n", common->curbssid);
669631bee25SArend van Spriel 	seq_printf(file, "BSSID-MASK: %pM\n", common->bssidmask);
670631bee25SArend van Spriel 	seq_printf(file, "OPMODE: %s\n",
6715e88ba62SZefir Kurtisi 		   ath_opmode_to_string(sc->sc_ah->opmode));
6726bcf6f64SSujith Manoharan 
6736bcf6f64SSujith Manoharan 	ath9k_ps_wakeup(sc);
6746bcf6f64SSujith Manoharan 	rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
6756bcf6f64SSujith Manoharan 	ath9k_ps_restore(sc);
6766bcf6f64SSujith Manoharan 
677631bee25SArend van Spriel 	seq_printf(file, "RXFILTER: 0x%x", rxfilter);
6786bcf6f64SSujith Manoharan 
6796bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_UCAST)
680631bee25SArend van Spriel 		seq_puts(file, " UCAST");
6816bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MCAST)
682631bee25SArend van Spriel 		seq_puts(file, " MCAST");
6836bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_BCAST)
684631bee25SArend van Spriel 		seq_puts(file, " BCAST");
6856bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_CONTROL)
686631bee25SArend van Spriel 		seq_puts(file, " CONTROL");
6876bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_BEACON)
688631bee25SArend van Spriel 		seq_puts(file, " BEACON");
6896bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PROM)
690631bee25SArend van Spriel 		seq_puts(file, " PROM");
6916bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
692631bee25SArend van Spriel 		seq_puts(file, " PROBEREQ");
6936bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PHYERR)
694631bee25SArend van Spriel 		seq_puts(file, " PHYERR");
6956bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
696631bee25SArend van Spriel 		seq_puts(file, " MYBEACON");
6976bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
698631bee25SArend van Spriel 		seq_puts(file, " COMP_BAR");
6996bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
700631bee25SArend van Spriel 		seq_puts(file, " PSPOLL");
7016bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
702631bee25SArend van Spriel 		seq_puts(file, " PHYRADAR");
7036bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
704631bee25SArend van Spriel 		seq_puts(file, " MCAST_BCAST_ALL");
7056bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
706631bee25SArend van Spriel 		seq_puts(file, " CONTROL_WRAPPER");
7076bcf6f64SSujith Manoharan 
708631bee25SArend van Spriel 	seq_puts(file, "\n");
7096bcf6f64SSujith Manoharan 
7106bcf6f64SSujith Manoharan 	reg = sc->sc_ah->imask;
7116bcf6f64SSujith Manoharan 
712631bee25SArend van Spriel 	seq_printf(file, "INTERRUPT-MASK: 0x%x", reg);
7136bcf6f64SSujith Manoharan 
7146bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_SWBA)
715631bee25SArend van Spriel 		seq_puts(file, " SWBA");
7166bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_BMISS)
717631bee25SArend van Spriel 		seq_puts(file, " BMISS");
7186bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_CST)
719631bee25SArend van Spriel 		seq_puts(file, " CST");
7206bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RX)
721631bee25SArend van Spriel 		seq_puts(file, " RX");
7226bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RXHP)
723631bee25SArend van Spriel 		seq_puts(file, " RXHP");
7246bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RXLP)
725631bee25SArend van Spriel 		seq_puts(file, " RXLP");
7266bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_BB_WATCHDOG)
727631bee25SArend van Spriel 		seq_puts(file, " BB_WATCHDOG");
7286bcf6f64SSujith Manoharan 
729631bee25SArend van Spriel 	seq_puts(file, "\n");
73055f6d0ffSBen Greear 
7319a9c4fbcSRajkumar Manoharan 	i = 0;
7329a9c4fbcSRajkumar Manoharan 	ath_for_each_chanctx(sc, ctx) {
733325e1881SBen Greear 		if (list_empty(&ctx->vifs))
7349a9c4fbcSRajkumar Manoharan 			continue;
7359a9c4fbcSRajkumar Manoharan 		ath9k_calculate_iter_data(sc, ctx, &iter_data);
73655f6d0ffSBen Greear 
737631bee25SArend van Spriel 		seq_printf(file,
738f4899218SJohannes Berg 			   "VIFS: CTX %i(%i) AP: %i STA: %i MESH: %i",
739325e1881SBen Greear 			   i++, (int)(ctx->assigned), iter_data.naps,
740325e1881SBen Greear 			   iter_data.nstations,
741f4899218SJohannes Berg 			   iter_data.nmeshes);
742862a336cSJan Kaisrlik 		seq_printf(file, " ADHOC: %i OCB: %i TOTAL: %hi BEACON-VIF: %hi\n",
743862a336cSJan Kaisrlik 			   iter_data.nadhocs, iter_data.nocbs, sc->cur_chan->nvifs,
744631bee25SArend van Spriel 			   sc->nbcnvifs);
7459a9c4fbcSRajkumar Manoharan 	}
74655f6d0ffSBen Greear 
747631bee25SArend van Spriel 	return 0;
74855f6d0ffSBen Greear }
74955f6d0ffSBen Greear 
750631bee25SArend van Spriel static int read_file_reset(struct seq_file *file, void *data)
751f8b815dcSSujith Manoharan {
752*053f9852SLinus Lüssing 	struct ath_softc *sc = file->private;
75370e535edSFelix Fietkau 	static const char * const reset_cause[__RESET_TYPE_MAX] = {
754*053f9852SLinus Lüssing 		[RESET_TYPE_USER] = "User reset",
75570e535edSFelix Fietkau 		[RESET_TYPE_BB_HANG] = "Baseband Hang",
75670e535edSFelix Fietkau 		[RESET_TYPE_BB_WATCHDOG] = "Baseband Watchdog",
75770e535edSFelix Fietkau 		[RESET_TYPE_FATAL_INT] = "Fatal HW Error",
75870e535edSFelix Fietkau 		[RESET_TYPE_TX_ERROR] = "TX HW error",
75970e535edSFelix Fietkau 		[RESET_TYPE_TX_GTT] = "Transmit timeout",
76070e535edSFelix Fietkau 		[RESET_TYPE_TX_HANG] = "TX Path Hang",
76170e535edSFelix Fietkau 		[RESET_TYPE_PLL_HANG] = "PLL RX Hang",
76270e535edSFelix Fietkau 		[RESET_TYPE_MAC_HANG] = "MAC Hang",
76370e535edSFelix Fietkau 		[RESET_TYPE_BEACON_STUCK] = "Stuck Beacon",
76470e535edSFelix Fietkau 		[RESET_TYPE_MCI] = "MCI Reset",
7657b8aaeadSFelix Fietkau 		[RESET_TYPE_CALIBRATION] = "Calibration error",
766e60ac9c7SFelix Fietkau 		[RESET_TX_DMA_ERROR] = "Tx DMA stop error",
767e60ac9c7SFelix Fietkau 		[RESET_RX_DMA_ERROR] = "Rx DMA stop error",
76870e535edSFelix Fietkau 	};
76970e535edSFelix Fietkau 	int i;
77070e535edSFelix Fietkau 
77170e535edSFelix Fietkau 	for (i = 0; i < ARRAY_SIZE(reset_cause); i++) {
77270e535edSFelix Fietkau 		if (!reset_cause[i])
77370e535edSFelix Fietkau 		    continue;
774f8b815dcSSujith Manoharan 
775e6b5be2bSLinus Torvalds 		seq_printf(file, "%17s: %2d\n", reset_cause[i],
77670e535edSFelix Fietkau 			   sc->debug.stats.reset[i]);
77770e535edSFelix Fietkau 	}
778f8b815dcSSujith Manoharan 
779631bee25SArend van Spriel 	return 0;
780f8b815dcSSujith Manoharan }
781f8b815dcSSujith Manoharan 
782*053f9852SLinus Lüssing static int open_file_reset(struct inode *inode, struct file *f)
783*053f9852SLinus Lüssing {
784*053f9852SLinus Lüssing 	return single_open(f, read_file_reset, inode->i_private);
785*053f9852SLinus Lüssing }
786*053f9852SLinus Lüssing 
787*053f9852SLinus Lüssing static ssize_t write_file_reset(struct file *file,
788*053f9852SLinus Lüssing 				const char __user *user_buf,
789*053f9852SLinus Lüssing 				size_t count, loff_t *ppos)
790*053f9852SLinus Lüssing {
791*053f9852SLinus Lüssing 	struct ath_softc *sc = file_inode(file)->i_private;
792*053f9852SLinus Lüssing 	struct ath_hw *ah = sc->sc_ah;
793*053f9852SLinus Lüssing 	struct ath_common *common = ath9k_hw_common(ah);
794*053f9852SLinus Lüssing 	unsigned long val;
795*053f9852SLinus Lüssing 	char buf[32];
796*053f9852SLinus Lüssing 	ssize_t len;
797*053f9852SLinus Lüssing 
798*053f9852SLinus Lüssing 	len = min(count, sizeof(buf) - 1);
799*053f9852SLinus Lüssing 	if (copy_from_user(buf, user_buf, len))
800*053f9852SLinus Lüssing 		return -EFAULT;
801*053f9852SLinus Lüssing 
802*053f9852SLinus Lüssing 	buf[len] = '\0';
803*053f9852SLinus Lüssing 	if (kstrtoul(buf, 0, &val))
804*053f9852SLinus Lüssing 		return -EINVAL;
805*053f9852SLinus Lüssing 
806*053f9852SLinus Lüssing 	if (val != 1)
807*053f9852SLinus Lüssing 		return -EINVAL;
808*053f9852SLinus Lüssing 
809*053f9852SLinus Lüssing 	/* avoid rearming hw_reset_work on shutdown */
810*053f9852SLinus Lüssing 	mutex_lock(&sc->mutex);
811*053f9852SLinus Lüssing 	if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
812*053f9852SLinus Lüssing 		mutex_unlock(&sc->mutex);
813*053f9852SLinus Lüssing 		return -EBUSY;
814*053f9852SLinus Lüssing 	}
815*053f9852SLinus Lüssing 
816*053f9852SLinus Lüssing 	ath9k_queue_reset(sc, RESET_TYPE_USER);
817*053f9852SLinus Lüssing 	mutex_unlock(&sc->mutex);
818*053f9852SLinus Lüssing 
819*053f9852SLinus Lüssing 	return count;
820*053f9852SLinus Lüssing }
821*053f9852SLinus Lüssing 
822*053f9852SLinus Lüssing static const struct file_operations fops_reset = {
823*053f9852SLinus Lüssing 	.read = seq_read,
824*053f9852SLinus Lüssing 	.write = write_file_reset,
825*053f9852SLinus Lüssing 	.open = open_file_reset,
826*053f9852SLinus Lüssing 	.owner = THIS_MODULE,
827*053f9852SLinus Lüssing 	.llseek = seq_lseek,
828*053f9852SLinus Lüssing 	.release = single_release,
829*053f9852SLinus Lüssing };
830*053f9852SLinus Lüssing 
831066dae93SFelix Fietkau void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
83255797b1aSFelix Fietkau 		       struct ath_tx_status *ts, struct ath_txq *txq,
83355797b1aSFelix Fietkau 		       unsigned int flags)
834fec247c0SSujith {
8355bec3e5aSFelix Fietkau 	int qnum = txq->axq_qnum;
836066dae93SFelix Fietkau 
83772569b7bSArnd Bergmann 	TX_STAT_INC(sc, qnum, tx_pkts_all);
838066dae93SFelix Fietkau 	sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
83999c15bf5SBen Greear 
840fec247c0SSujith 	if (bf_isampdu(bf)) {
841156369faSFelix Fietkau 		if (flags & ATH_TX_ERROR)
84272569b7bSArnd Bergmann 			TX_STAT_INC(sc, qnum, a_xretries);
843fec247c0SSujith 		else
84472569b7bSArnd Bergmann 			TX_STAT_INC(sc, qnum, a_completed);
845fec247c0SSujith 	} else {
84655797b1aSFelix Fietkau 		if (ts->ts_status & ATH9K_TXERR_XRETRY)
84772569b7bSArnd Bergmann 			TX_STAT_INC(sc, qnum, xretries);
8485a6f78afSFelix Fietkau 		else
84972569b7bSArnd Bergmann 			TX_STAT_INC(sc, qnum, completed);
850fec247c0SSujith 	}
851fec247c0SSujith 
8524d900389SBen Greear 	if (ts->ts_status & ATH9K_TXERR_FILT)
85372569b7bSArnd Bergmann 		TX_STAT_INC(sc, qnum, txerr_filtered);
854db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_FIFO)
85572569b7bSArnd Bergmann 		TX_STAT_INC(sc, qnum, fifo_underrun);
856db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_XTXOP)
85772569b7bSArnd Bergmann 		TX_STAT_INC(sc, qnum, xtxop);
858db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
85972569b7bSArnd Bergmann 		TX_STAT_INC(sc, qnum, timer_exp);
860db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
86172569b7bSArnd Bergmann 		TX_STAT_INC(sc, qnum, desc_cfg_err);
862db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
86372569b7bSArnd Bergmann 		TX_STAT_INC(sc, qnum, data_underrun);
864db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
86572569b7bSArnd Bergmann 		TX_STAT_INC(sc, qnum, delim_underrun);
866fec247c0SSujith }
867fec247c0SSujith 
8688e6f5aa2SFelix Fietkau void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
8691395d3f0SSujith {
870b5a0c86aSOleksij Rempel 	ath9k_cmn_debug_stat_rx(&sc->debug.stats.rxstats, rs);
8711395d3f0SSujith }
8721395d3f0SSujith 
8739bff0bc4SFelix Fietkau static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
8749bff0bc4SFelix Fietkau 				size_t count, loff_t *ppos)
8759bff0bc4SFelix Fietkau {
8769bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
8779bff0bc4SFelix Fietkau 	char buf[32];
8789bff0bc4SFelix Fietkau 	unsigned int len;
8799bff0bc4SFelix Fietkau 
8802b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
8819bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
8829bff0bc4SFelix Fietkau }
8839bff0bc4SFelix Fietkau 
8849bff0bc4SFelix Fietkau static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
8859bff0bc4SFelix Fietkau 				 size_t count, loff_t *ppos)
8869bff0bc4SFelix Fietkau {
8879bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
8889bff0bc4SFelix Fietkau 	unsigned long regidx;
8899bff0bc4SFelix Fietkau 	char buf[32];
8909bff0bc4SFelix Fietkau 	ssize_t len;
8919bff0bc4SFelix Fietkau 
8929bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
8939bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
89404236066SDan Carpenter 		return -EFAULT;
8959bff0bc4SFelix Fietkau 
8969bff0bc4SFelix Fietkau 	buf[len] = '\0';
89727d7f477SJingoo Han 	if (kstrtoul(buf, 0, &regidx))
8989bff0bc4SFelix Fietkau 		return -EINVAL;
8999bff0bc4SFelix Fietkau 
9009bff0bc4SFelix Fietkau 	sc->debug.regidx = regidx;
9019bff0bc4SFelix Fietkau 	return count;
9029bff0bc4SFelix Fietkau }
9039bff0bc4SFelix Fietkau 
9049bff0bc4SFelix Fietkau static const struct file_operations fops_regidx = {
9059bff0bc4SFelix Fietkau 	.read = read_file_regidx,
9069bff0bc4SFelix Fietkau 	.write = write_file_regidx,
907234e3405SStephen Boyd 	.open = simple_open,
9086038f373SArnd Bergmann 	.owner = THIS_MODULE,
9096038f373SArnd Bergmann 	.llseek = default_llseek,
9109bff0bc4SFelix Fietkau };
9119bff0bc4SFelix Fietkau 
9129bff0bc4SFelix Fietkau static ssize_t read_file_regval(struct file *file, char __user *user_buf,
9139bff0bc4SFelix Fietkau 				size_t count, loff_t *ppos)
9149bff0bc4SFelix Fietkau {
9159bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
9169bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
9179bff0bc4SFelix Fietkau 	char buf[32];
9189bff0bc4SFelix Fietkau 	unsigned int len;
9199bff0bc4SFelix Fietkau 	u32 regval;
9209bff0bc4SFelix Fietkau 
92179d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
9229bff0bc4SFelix Fietkau 	regval = REG_READ_D(ah, sc->debug.regidx);
92379d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
9242b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", regval);
9259bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
9269bff0bc4SFelix Fietkau }
9279bff0bc4SFelix Fietkau 
9289bff0bc4SFelix Fietkau static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
9299bff0bc4SFelix Fietkau 				 size_t count, loff_t *ppos)
9309bff0bc4SFelix Fietkau {
9319bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
9329bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
9339bff0bc4SFelix Fietkau 	unsigned long regval;
9349bff0bc4SFelix Fietkau 	char buf[32];
9359bff0bc4SFelix Fietkau 	ssize_t len;
9369bff0bc4SFelix Fietkau 
9379bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
9389bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
93904236066SDan Carpenter 		return -EFAULT;
9409bff0bc4SFelix Fietkau 
9419bff0bc4SFelix Fietkau 	buf[len] = '\0';
94227d7f477SJingoo Han 	if (kstrtoul(buf, 0, &regval))
9439bff0bc4SFelix Fietkau 		return -EINVAL;
9449bff0bc4SFelix Fietkau 
94579d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
9469bff0bc4SFelix Fietkau 	REG_WRITE_D(ah, sc->debug.regidx, regval);
94779d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
9489bff0bc4SFelix Fietkau 	return count;
9499bff0bc4SFelix Fietkau }
9509bff0bc4SFelix Fietkau 
9519bff0bc4SFelix Fietkau static const struct file_operations fops_regval = {
9529bff0bc4SFelix Fietkau 	.read = read_file_regval,
9539bff0bc4SFelix Fietkau 	.write = write_file_regval,
954234e3405SStephen Boyd 	.open = simple_open,
9556038f373SArnd Bergmann 	.owner = THIS_MODULE,
9566038f373SArnd Bergmann 	.llseek = default_llseek,
9579bff0bc4SFelix Fietkau };
9589bff0bc4SFelix Fietkau 
959582d0064SVasanthakumar Thiagarajan #define REGDUMP_LINE_SIZE	20
960582d0064SVasanthakumar Thiagarajan 
961582d0064SVasanthakumar Thiagarajan static int open_file_regdump(struct inode *inode, struct file *file)
962582d0064SVasanthakumar Thiagarajan {
963582d0064SVasanthakumar Thiagarajan 	struct ath_softc *sc = inode->i_private;
964582d0064SVasanthakumar Thiagarajan 	unsigned int len = 0;
965582d0064SVasanthakumar Thiagarajan 	u8 *buf;
966181c007dSMiaoqing Pan 	int i, j = 0;
967582d0064SVasanthakumar Thiagarajan 	unsigned long num_regs, regdump_len, max_reg_offset;
968eba0f284SColin Ian King 	static const struct reg_hole {
969181c007dSMiaoqing Pan 		u32 start;
970181c007dSMiaoqing Pan 		u32 end;
971181c007dSMiaoqing Pan 	} reg_hole_list[] = {
972181c007dSMiaoqing Pan 		{0x0200, 0x07fc},
973181c007dSMiaoqing Pan 		{0x0c00, 0x0ffc},
974181c007dSMiaoqing Pan 		{0x2000, 0x3ffc},
975181c007dSMiaoqing Pan 		{0x4100, 0x6ffc},
976181c007dSMiaoqing Pan 		{0x705c, 0x7ffc},
977181c007dSMiaoqing Pan 		{0x0000, 0x0000}
978181c007dSMiaoqing Pan 	};
979582d0064SVasanthakumar Thiagarajan 
980181c007dSMiaoqing Pan 	max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x8800 : 0xb500;
981582d0064SVasanthakumar Thiagarajan 	num_regs = max_reg_offset / 4 + 1;
982582d0064SVasanthakumar Thiagarajan 	regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
983582d0064SVasanthakumar Thiagarajan 	buf = vmalloc(regdump_len);
984582d0064SVasanthakumar Thiagarajan 	if (!buf)
985582d0064SVasanthakumar Thiagarajan 		return -ENOMEM;
986582d0064SVasanthakumar Thiagarajan 
987582d0064SVasanthakumar Thiagarajan 	ath9k_ps_wakeup(sc);
988181c007dSMiaoqing Pan 	for (i = 0; i < num_regs; i++) {
989181c007dSMiaoqing Pan 		if (reg_hole_list[j].start == i << 2) {
990181c007dSMiaoqing Pan 			i = reg_hole_list[j].end >> 2;
991181c007dSMiaoqing Pan 			j++;
992181c007dSMiaoqing Pan 			continue;
993181c007dSMiaoqing Pan 		}
994181c007dSMiaoqing Pan 
995582d0064SVasanthakumar Thiagarajan 		len += scnprintf(buf + len, regdump_len - len,
996582d0064SVasanthakumar Thiagarajan 			"0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
997181c007dSMiaoqing Pan 	}
998582d0064SVasanthakumar Thiagarajan 	ath9k_ps_restore(sc);
999582d0064SVasanthakumar Thiagarajan 
1000582d0064SVasanthakumar Thiagarajan 	file->private_data = buf;
1001582d0064SVasanthakumar Thiagarajan 
1002582d0064SVasanthakumar Thiagarajan 	return 0;
1003582d0064SVasanthakumar Thiagarajan }
1004582d0064SVasanthakumar Thiagarajan 
1005582d0064SVasanthakumar Thiagarajan static const struct file_operations fops_regdump = {
1006582d0064SVasanthakumar Thiagarajan 	.open = open_file_regdump,
1007582d0064SVasanthakumar Thiagarajan 	.read = ath9k_debugfs_read_buf,
1008582d0064SVasanthakumar Thiagarajan 	.release = ath9k_debugfs_release_buf,
1009582d0064SVasanthakumar Thiagarajan 	.owner = THIS_MODULE,
1010582d0064SVasanthakumar Thiagarajan 	.llseek = default_llseek,/* read accesses f_pos */
1011582d0064SVasanthakumar Thiagarajan };
1012582d0064SVasanthakumar Thiagarajan 
1013631bee25SArend van Spriel static int read_file_dump_nfcal(struct seq_file *file, void *data)
1014d069a46bSRajkumar Manoharan {
10154447d815SArend van Spriel 	struct ieee80211_hw *hw = dev_get_drvdata(file->private);
10164447d815SArend van Spriel 	struct ath_softc *sc = hw->priv;
1017d069a46bSRajkumar Manoharan 	struct ath_hw *ah = sc->sc_ah;
1018b01459e8SFelix Fietkau 	struct ath9k_nfcal_hist *h = sc->cur_chan->caldata.nfCalHist;
1019d069a46bSRajkumar Manoharan 	struct ath_common *common = ath9k_hw_common(ah);
1020d069a46bSRajkumar Manoharan 	struct ieee80211_conf *conf = &common->hw->conf;
1021d069a46bSRajkumar Manoharan 	u32 i, j;
1022d069a46bSRajkumar Manoharan 	u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1023d069a46bSRajkumar Manoharan 	u8 nread;
1024d069a46bSRajkumar Manoharan 
1025631bee25SArend van Spriel 	seq_printf(file, "Channel Noise Floor : %d\n", ah->noise);
1026631bee25SArend van Spriel 	seq_puts(file, "Chain | privNF | # Readings | NF Readings\n");
1027d069a46bSRajkumar Manoharan 	for (i = 0; i < NUM_NF_READINGS; i++) {
1028d069a46bSRajkumar Manoharan 		if (!(chainmask & (1 << i)) ||
1029d069a46bSRajkumar Manoharan 		    ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1030d069a46bSRajkumar Manoharan 			continue;
1031d069a46bSRajkumar Manoharan 
1032d069a46bSRajkumar Manoharan 		nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
1033631bee25SArend van Spriel 		seq_printf(file, " %d\t %d\t %d\t\t", i, h[i].privNF, nread);
1034d069a46bSRajkumar Manoharan 		for (j = 0; j < nread; j++)
1035631bee25SArend van Spriel 			seq_printf(file, " %d", h[i].nfCalBuffer[j]);
1036631bee25SArend van Spriel 		seq_puts(file, "\n");
1037d069a46bSRajkumar Manoharan 	}
1038d069a46bSRajkumar Manoharan 
1039631bee25SArend van Spriel 	return 0;
1040631bee25SArend van Spriel }
1041d069a46bSRajkumar Manoharan 
10424df50ca8SRajkumar Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
10434df50ca8SRajkumar Manoharan static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
10444df50ca8SRajkumar Manoharan 				size_t count, loff_t *ppos)
10454df50ca8SRajkumar Manoharan {
10464df50ca8SRajkumar Manoharan 	struct ath_softc *sc = file->private_data;
10474df50ca8SRajkumar Manoharan 	u32 len = 0, size = 1500;
10484df50ca8SRajkumar Manoharan 	char *buf;
10494df50ca8SRajkumar Manoharan 	size_t retval;
10504df50ca8SRajkumar Manoharan 
10514df50ca8SRajkumar Manoharan 	buf = kzalloc(size, GFP_KERNEL);
10524df50ca8SRajkumar Manoharan 	if (buf == NULL)
10534df50ca8SRajkumar Manoharan 		return -ENOMEM;
10544df50ca8SRajkumar Manoharan 
1055ac46ba43SSujith Manoharan 	if (!sc->sc_ah->common.btcoex_enabled) {
10565e88ba62SZefir Kurtisi 		len = scnprintf(buf, size, "%s\n",
1057ac46ba43SSujith Manoharan 				"BTCOEX is disabled");
1058ac46ba43SSujith Manoharan 		goto exit;
1059ac46ba43SSujith Manoharan 	}
10604df50ca8SRajkumar Manoharan 
1061ac46ba43SSujith Manoharan 	len = ath9k_dump_btcoex(sc, buf, size);
1062ac46ba43SSujith Manoharan exit:
10634df50ca8SRajkumar Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
10644df50ca8SRajkumar Manoharan 	kfree(buf);
10654df50ca8SRajkumar Manoharan 
10664df50ca8SRajkumar Manoharan 	return retval;
10674df50ca8SRajkumar Manoharan }
10684df50ca8SRajkumar Manoharan 
10694df50ca8SRajkumar Manoharan static const struct file_operations fops_btcoex = {
10704df50ca8SRajkumar Manoharan 	.read = read_file_btcoex,
10714df50ca8SRajkumar Manoharan 	.open = simple_open,
10724df50ca8SRajkumar Manoharan 	.owner = THIS_MODULE,
10734df50ca8SRajkumar Manoharan 	.llseek = default_llseek,
10744df50ca8SRajkumar Manoharan };
10754df50ca8SRajkumar Manoharan #endif
10764df50ca8SRajkumar Manoharan 
10777a90744cSLorenzo Bianconi #ifdef CONFIG_ATH9K_DYNACK
10787a90744cSLorenzo Bianconi static ssize_t read_file_ackto(struct file *file, char __user *user_buf,
10797a90744cSLorenzo Bianconi 			       size_t count, loff_t *ppos)
10807a90744cSLorenzo Bianconi {
10817a90744cSLorenzo Bianconi 	struct ath_softc *sc = file->private_data;
10827a90744cSLorenzo Bianconi 	struct ath_hw *ah = sc->sc_ah;
10837a90744cSLorenzo Bianconi 	char buf[32];
10847a90744cSLorenzo Bianconi 	unsigned int len;
10857a90744cSLorenzo Bianconi 
10867a90744cSLorenzo Bianconi 	len = sprintf(buf, "%u %c\n", ah->dynack.ackto,
10877a90744cSLorenzo Bianconi 		      (ah->dynack.enabled) ? 'A' : 'S');
10887a90744cSLorenzo Bianconi 
10897a90744cSLorenzo Bianconi 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
10907a90744cSLorenzo Bianconi }
10917a90744cSLorenzo Bianconi 
10927a90744cSLorenzo Bianconi static const struct file_operations fops_ackto = {
10937a90744cSLorenzo Bianconi 	.read = read_file_ackto,
10947a90744cSLorenzo Bianconi 	.open = simple_open,
10957a90744cSLorenzo Bianconi 	.owner = THIS_MODULE,
10967a90744cSLorenzo Bianconi 	.llseek = default_llseek,
10977a90744cSLorenzo Bianconi };
10987a90744cSLorenzo Bianconi #endif
10997a90744cSLorenzo Bianconi 
11008b861715SSujith Manoharan #ifdef CONFIG_ATH9K_WOW
11018b861715SSujith Manoharan 
11028b861715SSujith Manoharan static ssize_t read_file_wow(struct file *file, char __user *user_buf,
11038b861715SSujith Manoharan 			     size_t count, loff_t *ppos)
11048b861715SSujith Manoharan {
11058b861715SSujith Manoharan 	struct ath_softc *sc = file->private_data;
11068b861715SSujith Manoharan 	unsigned int len = 0, size = 32;
11078b861715SSujith Manoharan 	ssize_t retval;
11088b861715SSujith Manoharan 	char *buf;
11098b861715SSujith Manoharan 
11108b861715SSujith Manoharan 	buf = kzalloc(size, GFP_KERNEL);
11118b861715SSujith Manoharan 	if (!buf)
11128b861715SSujith Manoharan 		return -ENOMEM;
11138b861715SSujith Manoharan 
11148b861715SSujith Manoharan 	len += scnprintf(buf + len, size - len, "WOW: %s\n",
11158b861715SSujith Manoharan 			 sc->force_wow ? "ENABLED" : "DISABLED");
11168b861715SSujith Manoharan 
11178b861715SSujith Manoharan 	if (len > size)
11188b861715SSujith Manoharan 		len = size;
11198b861715SSujith Manoharan 
11208b861715SSujith Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
11218b861715SSujith Manoharan 	kfree(buf);
11228b861715SSujith Manoharan 
11238b861715SSujith Manoharan 	return retval;
11248b861715SSujith Manoharan }
11258b861715SSujith Manoharan 
11268b861715SSujith Manoharan static ssize_t write_file_wow(struct file *file, const char __user *user_buf,
11278b861715SSujith Manoharan 			      size_t count, loff_t *ppos)
11288b861715SSujith Manoharan {
11298b861715SSujith Manoharan 	struct ath_softc *sc = file->private_data;
11308b861715SSujith Manoharan 	unsigned long val;
11318b861715SSujith Manoharan 	char buf[32];
11328b861715SSujith Manoharan 	ssize_t len;
11338b861715SSujith Manoharan 
11348b861715SSujith Manoharan 	len = min(count, sizeof(buf) - 1);
11358b861715SSujith Manoharan 	if (copy_from_user(buf, user_buf, len))
11368b861715SSujith Manoharan 		return -EFAULT;
11378b861715SSujith Manoharan 
11388b861715SSujith Manoharan 	buf[len] = '\0';
11398b861715SSujith Manoharan 	if (kstrtoul(buf, 0, &val))
11408b861715SSujith Manoharan 		return -EINVAL;
11418b861715SSujith Manoharan 
11428b861715SSujith Manoharan 	if (val != 1)
11438b861715SSujith Manoharan 		return -EINVAL;
11448b861715SSujith Manoharan 
11458b861715SSujith Manoharan 	if (!sc->force_wow) {
11468b861715SSujith Manoharan 		sc->force_wow = true;
11478b861715SSujith Manoharan 		ath9k_init_wow(sc->hw);
11488b861715SSujith Manoharan 	}
11498b861715SSujith Manoharan 
11508b861715SSujith Manoharan 	return count;
11518b861715SSujith Manoharan }
11528b861715SSujith Manoharan 
11538b861715SSujith Manoharan static const struct file_operations fops_wow = {
11548b861715SSujith Manoharan 	.read = read_file_wow,
11558b861715SSujith Manoharan 	.write = write_file_wow,
11568b861715SSujith Manoharan 	.open = simple_open,
11578b861715SSujith Manoharan 	.owner = THIS_MODULE,
11588b861715SSujith Manoharan 	.llseek = default_llseek,
11598b861715SSujith Manoharan };
11608b861715SSujith Manoharan 
11618b861715SSujith Manoharan #endif
11628b861715SSujith Manoharan 
11638718389bSLorenzo Bianconi static ssize_t read_file_tpc(struct file *file, char __user *user_buf,
11648718389bSLorenzo Bianconi 			     size_t count, loff_t *ppos)
11658718389bSLorenzo Bianconi {
11668718389bSLorenzo Bianconi 	struct ath_softc *sc = file->private_data;
11678718389bSLorenzo Bianconi 	struct ath_hw *ah = sc->sc_ah;
11688718389bSLorenzo Bianconi 	unsigned int len = 0, size = 32;
11698718389bSLorenzo Bianconi 	ssize_t retval;
11708718389bSLorenzo Bianconi 	char *buf;
11718718389bSLorenzo Bianconi 
11728718389bSLorenzo Bianconi 	buf = kzalloc(size, GFP_KERNEL);
11738718389bSLorenzo Bianconi 	if (!buf)
11748718389bSLorenzo Bianconi 		return -ENOMEM;
11758718389bSLorenzo Bianconi 
11768718389bSLorenzo Bianconi 	len += scnprintf(buf + len, size - len, "%s\n",
11778718389bSLorenzo Bianconi 			 ah->tpc_enabled ? "ENABLED" : "DISABLED");
11788718389bSLorenzo Bianconi 
11798718389bSLorenzo Bianconi 	if (len > size)
11808718389bSLorenzo Bianconi 		len = size;
11818718389bSLorenzo Bianconi 
11828718389bSLorenzo Bianconi 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
11838718389bSLorenzo Bianconi 	kfree(buf);
11848718389bSLorenzo Bianconi 
11858718389bSLorenzo Bianconi 	return retval;
11868718389bSLorenzo Bianconi }
11878718389bSLorenzo Bianconi 
11888718389bSLorenzo Bianconi static ssize_t write_file_tpc(struct file *file, const char __user *user_buf,
11898718389bSLorenzo Bianconi 			      size_t count, loff_t *ppos)
11908718389bSLorenzo Bianconi {
11918718389bSLorenzo Bianconi 	struct ath_softc *sc = file->private_data;
11928718389bSLorenzo Bianconi 	struct ath_hw *ah = sc->sc_ah;
11938718389bSLorenzo Bianconi 	unsigned long val;
11948718389bSLorenzo Bianconi 	char buf[32];
11958718389bSLorenzo Bianconi 	ssize_t len;
11968718389bSLorenzo Bianconi 	bool tpc_enabled;
11978718389bSLorenzo Bianconi 
11988718389bSLorenzo Bianconi 	len = min(count, sizeof(buf) - 1);
11998718389bSLorenzo Bianconi 	if (copy_from_user(buf, user_buf, len))
12008718389bSLorenzo Bianconi 		return -EFAULT;
12018718389bSLorenzo Bianconi 
12028718389bSLorenzo Bianconi 	buf[len] = '\0';
12038718389bSLorenzo Bianconi 	if (kstrtoul(buf, 0, &val))
12048718389bSLorenzo Bianconi 		return -EINVAL;
12058718389bSLorenzo Bianconi 
12069d414949SChristos Gkekas 	if (val > 1)
12078718389bSLorenzo Bianconi 		return -EINVAL;
12088718389bSLorenzo Bianconi 
12098718389bSLorenzo Bianconi 	tpc_enabled = !!val;
12108718389bSLorenzo Bianconi 
12118718389bSLorenzo Bianconi 	if (tpc_enabled != ah->tpc_enabled) {
12128718389bSLorenzo Bianconi 		ah->tpc_enabled = tpc_enabled;
1213283dd119SLorenzo Bianconi 
1214283dd119SLorenzo Bianconi 		mutex_lock(&sc->mutex);
1215283dd119SLorenzo Bianconi 		ath9k_set_txpower(sc, NULL);
1216283dd119SLorenzo Bianconi 		mutex_unlock(&sc->mutex);
12178718389bSLorenzo Bianconi 	}
12188718389bSLorenzo Bianconi 
12198718389bSLorenzo Bianconi 	return count;
12208718389bSLorenzo Bianconi }
12218718389bSLorenzo Bianconi 
12228718389bSLorenzo Bianconi static const struct file_operations fops_tpc = {
12238718389bSLorenzo Bianconi 	.read = read_file_tpc,
12248718389bSLorenzo Bianconi 	.write = write_file_tpc,
12258718389bSLorenzo Bianconi 	.open = simple_open,
12268718389bSLorenzo Bianconi 	.owner = THIS_MODULE,
12278718389bSLorenzo Bianconi 	.llseek = default_llseek,
12288718389bSLorenzo Bianconi };
12298718389bSLorenzo Bianconi 
1230b9018975SSimon Wunderlich static ssize_t read_file_nf_override(struct file *file,
1231b9018975SSimon Wunderlich 				     char __user *user_buf,
1232b9018975SSimon Wunderlich 				     size_t count, loff_t *ppos)
1233b9018975SSimon Wunderlich {
1234b9018975SSimon Wunderlich 	struct ath_softc *sc = file->private_data;
1235b9018975SSimon Wunderlich 	struct ath_hw *ah = sc->sc_ah;
1236b9018975SSimon Wunderlich 	char buf[32];
1237b9018975SSimon Wunderlich 	unsigned int len;
1238b9018975SSimon Wunderlich 
1239b9018975SSimon Wunderlich 	if (ah->nf_override == 0)
1240b9018975SSimon Wunderlich 		len = sprintf(buf, "off\n");
1241b9018975SSimon Wunderlich 	else
1242b9018975SSimon Wunderlich 		len = sprintf(buf, "%d\n", ah->nf_override);
1243b9018975SSimon Wunderlich 
1244b9018975SSimon Wunderlich 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1245b9018975SSimon Wunderlich }
1246b9018975SSimon Wunderlich 
1247b9018975SSimon Wunderlich static ssize_t write_file_nf_override(struct file *file,
1248b9018975SSimon Wunderlich 				      const char __user *user_buf,
1249b9018975SSimon Wunderlich 				      size_t count, loff_t *ppos)
1250b9018975SSimon Wunderlich {
1251b9018975SSimon Wunderlich 	struct ath_softc *sc = file->private_data;
1252b9018975SSimon Wunderlich 	struct ath_hw *ah = sc->sc_ah;
1253b9018975SSimon Wunderlich 	long val;
1254b9018975SSimon Wunderlich 	char buf[32];
1255b9018975SSimon Wunderlich 	ssize_t len;
1256b9018975SSimon Wunderlich 
1257b9018975SSimon Wunderlich 	len = min(count, sizeof(buf) - 1);
1258b9018975SSimon Wunderlich 	if (copy_from_user(buf, user_buf, len))
1259b9018975SSimon Wunderlich 		return -EFAULT;
1260b9018975SSimon Wunderlich 
1261b9018975SSimon Wunderlich 	buf[len] = '\0';
1262b9018975SSimon Wunderlich 	if (strncmp("off", buf, 3) == 0)
1263b9018975SSimon Wunderlich 		val = 0;
1264b9018975SSimon Wunderlich 	else if (kstrtol(buf, 0, &val))
1265b9018975SSimon Wunderlich 		return -EINVAL;
1266b9018975SSimon Wunderlich 
1267b9018975SSimon Wunderlich 	if (val > 0)
1268b9018975SSimon Wunderlich 		return -EINVAL;
1269b9018975SSimon Wunderlich 
1270b9018975SSimon Wunderlich 	if (val < -120)
1271b9018975SSimon Wunderlich 		return -EINVAL;
1272b9018975SSimon Wunderlich 
1273b9018975SSimon Wunderlich 	ah->nf_override = val;
1274b9018975SSimon Wunderlich 
127512c8f3d1SLinus Lüssing 	if (ah->curchan) {
127612c8f3d1SLinus Lüssing 		ath9k_ps_wakeup(sc);
1277b9018975SSimon Wunderlich 		ath9k_hw_loadnf(ah, ah->curchan);
127812c8f3d1SLinus Lüssing 		ath9k_ps_restore(sc);
127912c8f3d1SLinus Lüssing 	}
1280b9018975SSimon Wunderlich 
1281b9018975SSimon Wunderlich 	return count;
1282b9018975SSimon Wunderlich }
1283b9018975SSimon Wunderlich 
1284b9018975SSimon Wunderlich static const struct file_operations fops_nf_override = {
1285b9018975SSimon Wunderlich 	.read = read_file_nf_override,
1286b9018975SSimon Wunderlich 	.write = write_file_nf_override,
1287b9018975SSimon Wunderlich 	.open = simple_open,
1288b9018975SSimon Wunderlich 	.owner = THIS_MODULE,
1289b9018975SSimon Wunderlich 	.llseek = default_llseek,
1290b9018975SSimon Wunderlich };
1291b9018975SSimon Wunderlich 
1292c175db87SSujith Manoharan /* Ethtool support for get-stats */
1293c175db87SSujith Manoharan 
1294c175db87SSujith Manoharan #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1295c175db87SSujith Manoharan static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1296c175db87SSujith Manoharan 	"tx_pkts_nic",
1297c175db87SSujith Manoharan 	"tx_bytes_nic",
1298c175db87SSujith Manoharan 	"rx_pkts_nic",
1299c175db87SSujith Manoharan 	"rx_bytes_nic",
1300c175db87SSujith Manoharan 	AMKSTR(d_tx_pkts),
1301c175db87SSujith Manoharan 	AMKSTR(d_tx_bytes),
1302c175db87SSujith Manoharan 	AMKSTR(d_tx_mpdus_queued),
1303c175db87SSujith Manoharan 	AMKSTR(d_tx_mpdus_completed),
1304c175db87SSujith Manoharan 	AMKSTR(d_tx_mpdu_xretries),
1305c175db87SSujith Manoharan 	AMKSTR(d_tx_aggregates),
1306c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdus_queued_hw),
1307c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdus_completed),
1308c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdu_retries),
1309c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdu_xretries),
1310c175db87SSujith Manoharan 	AMKSTR(d_tx_fifo_underrun),
1311c175db87SSujith Manoharan 	AMKSTR(d_tx_op_exceeded),
1312c175db87SSujith Manoharan 	AMKSTR(d_tx_timer_expiry),
1313c175db87SSujith Manoharan 	AMKSTR(d_tx_desc_cfg_err),
1314c175db87SSujith Manoharan 	AMKSTR(d_tx_data_underrun),
1315c175db87SSujith Manoharan 	AMKSTR(d_tx_delim_underrun),
131618c45b10SBen Greear 	"d_rx_crc_err",
1317c175db87SSujith Manoharan 	"d_rx_decrypt_crc_err",
1318c175db87SSujith Manoharan 	"d_rx_phy_err",
1319c175db87SSujith Manoharan 	"d_rx_mic_err",
1320c175db87SSujith Manoharan 	"d_rx_pre_delim_crc_err",
1321c175db87SSujith Manoharan 	"d_rx_post_delim_crc_err",
1322c175db87SSujith Manoharan 	"d_rx_decrypt_busy_err",
1323c175db87SSujith Manoharan 
1324c175db87SSujith Manoharan 	"d_rx_phyerr_radar",
1325c175db87SSujith Manoharan 	"d_rx_phyerr_ofdm_timing",
1326c175db87SSujith Manoharan 	"d_rx_phyerr_cck_timing",
1327c175db87SSujith Manoharan 
1328c175db87SSujith Manoharan };
1329c175db87SSujith Manoharan #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1330c175db87SSujith Manoharan 
1331c175db87SSujith Manoharan void ath9k_get_et_strings(struct ieee80211_hw *hw,
1332c175db87SSujith Manoharan 			  struct ieee80211_vif *vif,
1333c175db87SSujith Manoharan 			  u32 sset, u8 *data)
1334c175db87SSujith Manoharan {
1335c175db87SSujith Manoharan 	if (sset == ETH_SS_STATS)
1336c175db87SSujith Manoharan 		memcpy(data, *ath9k_gstrings_stats,
1337c175db87SSujith Manoharan 		       sizeof(ath9k_gstrings_stats));
1338c175db87SSujith Manoharan }
1339c175db87SSujith Manoharan 
1340c175db87SSujith Manoharan int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
1341c175db87SSujith Manoharan 			    struct ieee80211_vif *vif, int sset)
1342c175db87SSujith Manoharan {
1343c175db87SSujith Manoharan 	if (sset == ETH_SS_STATS)
1344c175db87SSujith Manoharan 		return ATH9K_SSTATS_LEN;
1345c175db87SSujith Manoharan 	return 0;
1346c175db87SSujith Manoharan }
1347c175db87SSujith Manoharan 
1348c175db87SSujith Manoharan #define AWDATA(elem)							\
1349c175db87SSujith Manoharan 	do {								\
1350c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
1351c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
1352c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
1353c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
1354c175db87SSujith Manoharan 	} while (0)
1355c175db87SSujith Manoharan 
1356c175db87SSujith Manoharan #define AWDATA_RX(elem)						\
1357c175db87SSujith Manoharan 	do {							\
1358c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.rxstats.elem;	\
1359c175db87SSujith Manoharan 	} while (0)
1360c175db87SSujith Manoharan 
1361c175db87SSujith Manoharan void ath9k_get_et_stats(struct ieee80211_hw *hw,
1362c175db87SSujith Manoharan 			struct ieee80211_vif *vif,
1363c175db87SSujith Manoharan 			struct ethtool_stats *stats, u64 *data)
1364c175db87SSujith Manoharan {
1365c175db87SSujith Manoharan 	struct ath_softc *sc = hw->priv;
1366c175db87SSujith Manoharan 	int i = 0;
1367c175db87SSujith Manoharan 
1368c175db87SSujith Manoharan 	data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
1369c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
1370c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
1371c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
1372c175db87SSujith Manoharan 	data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
1373c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
1374c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
1375c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
1376c175db87SSujith Manoharan 	AWDATA_RX(rx_pkts_all);
1377c175db87SSujith Manoharan 	AWDATA_RX(rx_bytes_all);
1378c175db87SSujith Manoharan 
1379c175db87SSujith Manoharan 	AWDATA(tx_pkts_all);
1380c175db87SSujith Manoharan 	AWDATA(tx_bytes_all);
1381c175db87SSujith Manoharan 	AWDATA(queued);
1382c175db87SSujith Manoharan 	AWDATA(completed);
1383c175db87SSujith Manoharan 	AWDATA(xretries);
1384c175db87SSujith Manoharan 	AWDATA(a_aggr);
1385c175db87SSujith Manoharan 	AWDATA(a_queued_hw);
1386c175db87SSujith Manoharan 	AWDATA(a_completed);
1387c175db87SSujith Manoharan 	AWDATA(a_retries);
1388c175db87SSujith Manoharan 	AWDATA(a_xretries);
1389c175db87SSujith Manoharan 	AWDATA(fifo_underrun);
1390c175db87SSujith Manoharan 	AWDATA(xtxop);
1391c175db87SSujith Manoharan 	AWDATA(timer_exp);
1392c175db87SSujith Manoharan 	AWDATA(desc_cfg_err);
1393c175db87SSujith Manoharan 	AWDATA(data_underrun);
1394c175db87SSujith Manoharan 	AWDATA(delim_underrun);
1395c175db87SSujith Manoharan 
139618c45b10SBen Greear 	AWDATA_RX(crc_err);
1397c175db87SSujith Manoharan 	AWDATA_RX(decrypt_crc_err);
1398c175db87SSujith Manoharan 	AWDATA_RX(phy_err);
1399c175db87SSujith Manoharan 	AWDATA_RX(mic_err);
1400c175db87SSujith Manoharan 	AWDATA_RX(pre_delim_crc_err);
1401c175db87SSujith Manoharan 	AWDATA_RX(post_delim_crc_err);
1402c175db87SSujith Manoharan 	AWDATA_RX(decrypt_busy_err);
1403c175db87SSujith Manoharan 
1404c175db87SSujith Manoharan 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
1405c175db87SSujith Manoharan 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
1406c175db87SSujith Manoharan 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
1407c175db87SSujith Manoharan 
1408c175db87SSujith Manoharan 	WARN_ON(i != ATH9K_SSTATS_LEN);
1409c175db87SSujith Manoharan }
1410c175db87SSujith Manoharan 
1411af690092SSujith Manoharan void ath9k_deinit_debug(struct ath_softc *sc)
1412af690092SSujith Manoharan {
141367dc74f1SOleksij Rempel 	ath9k_cmn_spectral_deinit_debug(&sc->spec_priv);
1414af690092SSujith Manoharan }
1415af690092SSujith Manoharan 
14164d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah)
1417203c4805SLuis R. Rodriguez {
1418bc974f4aSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(ah);
1419bc974f4aSLuis R. Rodriguez 	struct ath_softc *sc = (struct ath_softc *) common->priv;
14204d6b228dSLuis R. Rodriguez 
1421eb272441SBen Greear 	sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1422eb272441SBen Greear 						   sc->hw->wiphy->debugfsdir);
1423203c4805SLuis R. Rodriguez 	if (!sc->debug.debugfs_phy)
1424c8a72c00SFelix Fietkau 		return -ENOMEM;
1425203c4805SLuis R. Rodriguez 
1426a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
14272ef00c53SJoe Perches 	debugfs_create_file("debug", 0600, sc->debug.debugfs_phy,
1428c70cab1aSFelix Fietkau 			    sc, &fops_debug);
1429a830df07SFelix Fietkau #endif
143029942bc1SZefir Kurtisi 
143129942bc1SZefir Kurtisi 	ath9k_dfs_init_debug(sc);
1432ef6b19e4SSujith Manoharan 	ath9k_tx99_init_debug(sc);
143367dc74f1SOleksij Rempel 	ath9k_cmn_spectral_init_debug(&sc->spec_priv, sc->debug.debugfs_phy);
143429942bc1SZefir Kurtisi 
14354447d815SArend van Spriel 	debugfs_create_devm_seqfile(sc->dev, "dma", sc->debug.debugfs_phy,
14364447d815SArend van Spriel 				    read_file_dma);
14374447d815SArend van Spriel 	debugfs_create_devm_seqfile(sc->dev, "interrupt", sc->debug.debugfs_phy,
14384447d815SArend van Spriel 				    read_file_interrupt);
14394447d815SArend van Spriel 	debugfs_create_devm_seqfile(sc->dev, "xmit", sc->debug.debugfs_phy,
14404447d815SArend van Spriel 				    read_file_xmit);
14414447d815SArend van Spriel 	debugfs_create_devm_seqfile(sc->dev, "queues", sc->debug.debugfs_phy,
14424447d815SArend van Spriel 				    read_file_queues);
14434447d815SArend van Spriel 	debugfs_create_devm_seqfile(sc->dev, "misc", sc->debug.debugfs_phy,
14444447d815SArend van Spriel 				    read_file_misc);
1445*053f9852SLinus Lüssing 	debugfs_create_file("reset", 0600, sc->debug.debugfs_phy,
1446*053f9852SLinus Lüssing 			    sc, &fops_reset);
144787ea9b0bSOleksij Rempel 
144887ea9b0bSOleksij Rempel 	ath9k_cmn_debug_recv(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
1449e02912cdSOleksij Rempel 	ath9k_cmn_debug_phy_err(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
145087ea9b0bSOleksij Rempel 
14512ef00c53SJoe Perches 	debugfs_create_u8("rx_chainmask", 0400, sc->debug.debugfs_phy,
1452ca6d4a74SFelix Fietkau 			  &ah->rxchainmask);
14532ef00c53SJoe Perches 	debugfs_create_u8("tx_chainmask", 0400, sc->debug.debugfs_phy,
1454ca6d4a74SFelix Fietkau 			  &ah->txchainmask);
14552ef00c53SJoe Perches 	debugfs_create_file("ani", 0600,
14566e4d291eSSujith Manoharan 			    sc->debug.debugfs_phy, sc, &fops_ani);
14572ef00c53SJoe Perches 	debugfs_create_bool("paprd", 0600, sc->debug.debugfs_phy,
145874673db9SFelix Fietkau 			    &sc->sc_ah->config.enable_paprd);
14592ef00c53SJoe Perches 	debugfs_create_file("regidx", 0600, sc->debug.debugfs_phy,
1460c70cab1aSFelix Fietkau 			    sc, &fops_regidx);
14612ef00c53SJoe Perches 	debugfs_create_file("regval", 0600, sc->debug.debugfs_phy,
1462c70cab1aSFelix Fietkau 			    sc, &fops_regval);
14632ef00c53SJoe Perches 	debugfs_create_bool("ignore_extcca", 0600,
1464c70cab1aSFelix Fietkau 			    sc->debug.debugfs_phy,
1465c70cab1aSFelix Fietkau 			    &ah->config.cwm_ignore_extcca);
14662ef00c53SJoe Perches 	debugfs_create_file("regdump", 0400, sc->debug.debugfs_phy, sc,
1467c70cab1aSFelix Fietkau 			    &fops_regdump);
14684447d815SArend van Spriel 	debugfs_create_devm_seqfile(sc->dev, "dump_nfcal",
14694447d815SArend van Spriel 				    sc->debug.debugfs_phy,
14704447d815SArend van Spriel 				    read_file_dump_nfcal);
1471f2c3c952SOleksij Rempel 
147229bf801eSOleksij Rempel 	ath9k_cmn_debug_base_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
1473f2c3c952SOleksij Rempel 	ath9k_cmn_debug_modal_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
1474f2c3c952SOleksij Rempel 
14752ef00c53SJoe Perches 	debugfs_create_u32("gpio_mask", 0600,
1476691680b8SFelix Fietkau 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
14772ef00c53SJoe Perches 	debugfs_create_u32("gpio_val", 0600,
1478691680b8SFelix Fietkau 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
14792ef00c53SJoe Perches 	debugfs_create_file("antenna_diversity", 0400,
14804eba10ccSSujith Manoharan 			    sc->debug.debugfs_phy, sc, &fops_antenna_diversity);
14814df50ca8SRajkumar Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
14822ef00c53SJoe Perches 	debugfs_create_file("bt_ant_diversity", 0600,
148336e8825eSSujith Manoharan 			    sc->debug.debugfs_phy, sc, &fops_bt_ant_diversity);
14842ef00c53SJoe Perches 	debugfs_create_file("btcoex", 0400, sc->debug.debugfs_phy, sc,
14854df50ca8SRajkumar Manoharan 			    &fops_btcoex);
14864df50ca8SRajkumar Manoharan #endif
148789f927afSLuis R. Rodriguez 
14888b861715SSujith Manoharan #ifdef CONFIG_ATH9K_WOW
14892ef00c53SJoe Perches 	debugfs_create_file("wow", 0600, sc->debug.debugfs_phy, sc, &fops_wow);
14908b861715SSujith Manoharan #endif
14918b861715SSujith Manoharan 
14927a90744cSLorenzo Bianconi #ifdef CONFIG_ATH9K_DYNACK
14932ef00c53SJoe Perches 	debugfs_create_file("ack_to", 0400, sc->debug.debugfs_phy,
14947a90744cSLorenzo Bianconi 			    sc, &fops_ackto);
14957a90744cSLorenzo Bianconi #endif
14962ef00c53SJoe Perches 	debugfs_create_file("tpc", 0600, sc->debug.debugfs_phy, sc, &fops_tpc);
14977a90744cSLorenzo Bianconi 
14982ef00c53SJoe Perches 	debugfs_create_file("nf_override", 0600,
1499b9018975SSimon Wunderlich 			    sc->debug.debugfs_phy, sc, &fops_nf_override);
1500b9018975SSimon Wunderlich 
1501203c4805SLuis R. Rodriguez 	return 0;
1502203c4805SLuis R. Rodriguez }
1503