xref: /linux/drivers/net/wireless/ath/ath9k/debug.c (revision 9410645520e9b820069761f3450ef6661418e279)
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 
ath9k_debug_sync_cause(struct ath_softc * sc,u32 sync_cause)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 
ath9k_debugfs_read_buf(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)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 
ath9k_debugfs_release_buf(struct inode * inode,struct file * file)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 
read_file_debug(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)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 
write_file_debug(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)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;
1048b804643SDmitry Antipov 	ssize_t ret;
105581f725cSVasanthakumar Thiagarajan 
1068b804643SDmitry Antipov 	ret = kstrtoul_from_user(user_buf, count, 0, &mask);
1078b804643SDmitry Antipov 	if (ret)
1088b804643SDmitry Antipov 		return ret;
109581f725cSVasanthakumar Thiagarajan 
110c46917bbSLuis R. Rodriguez 	common->debug_mask = mask;
1112493928eSJeff Hansen 	return count;
1122493928eSJeff Hansen }
1132493928eSJeff Hansen 
1142493928eSJeff Hansen static const struct file_operations fops_debug = {
1152493928eSJeff Hansen 	.read = read_file_debug,
1162493928eSJeff Hansen 	.write = write_file_debug,
117234e3405SStephen Boyd 	.open = simple_open,
1186038f373SArnd Bergmann 	.owner = THIS_MODULE,
1196038f373SArnd Bergmann 	.llseek = default_llseek,
1202493928eSJeff Hansen };
1212493928eSJeff Hansen 
122a830df07SFelix Fietkau #endif
123a830df07SFelix Fietkau 
124991a0987SPavel Roskin #define DMA_BUF_LEN 1024
125991a0987SPavel Roskin 
12615340694SFelix Fietkau 
read_file_ani(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)1276e4d291eSSujith Manoharan static ssize_t read_file_ani(struct file *file, char __user *user_buf,
12805c0be2fSMohammed Shafi Shajakhan 			     size_t count, loff_t *ppos)
12905c0be2fSMohammed Shafi Shajakhan {
13005c0be2fSMohammed Shafi Shajakhan 	struct ath_softc *sc = file->private_data;
13105c0be2fSMohammed Shafi Shajakhan 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1326e4d291eSSujith Manoharan 	struct ath_hw *ah = sc->sc_ah;
1332120ac96SJoe Perches 	unsigned int len = 0;
1342120ac96SJoe Perches 	const unsigned int size = 1024;
1356e4d291eSSujith Manoharan 	ssize_t retval = 0;
1366e4d291eSSujith Manoharan 	char *buf;
137abee4c84SFelix Fietkau 	int i;
138abee4c84SFelix Fietkau 	struct {
139abee4c84SFelix Fietkau 		const char *name;
140abee4c84SFelix Fietkau 		unsigned int val;
141abee4c84SFelix Fietkau 	} ani_info[] = {
142abee4c84SFelix Fietkau 		{ "ANI RESET", ah->stats.ast_ani_reset },
143abee4c84SFelix Fietkau 		{ "OFDM LEVEL", ah->ani.ofdmNoiseImmunityLevel },
144abee4c84SFelix Fietkau 		{ "CCK LEVEL", ah->ani.cckNoiseImmunityLevel },
145abee4c84SFelix Fietkau 		{ "SPUR UP", ah->stats.ast_ani_spurup },
146d0480d43SAndrea Greco 		{ "SPUR DOWN", ah->stats.ast_ani_spurdown },
147abee4c84SFelix Fietkau 		{ "OFDM WS-DET ON", ah->stats.ast_ani_ofdmon },
148abee4c84SFelix Fietkau 		{ "OFDM WS-DET OFF", ah->stats.ast_ani_ofdmoff },
149abee4c84SFelix Fietkau 		{ "MRC-CCK ON", ah->stats.ast_ani_ccklow },
150abee4c84SFelix Fietkau 		{ "MRC-CCK OFF", ah->stats.ast_ani_cckhigh },
151abee4c84SFelix Fietkau 		{ "FIR-STEP UP", ah->stats.ast_ani_stepup },
152abee4c84SFelix Fietkau 		{ "FIR-STEP DOWN", ah->stats.ast_ani_stepdown },
153abee4c84SFelix Fietkau 		{ "INV LISTENTIME", ah->stats.ast_ani_lneg_or_lzero },
154abee4c84SFelix Fietkau 		{ "OFDM ERRORS", ah->stats.ast_ani_ofdmerrs },
155abee4c84SFelix Fietkau 		{ "CCK ERRORS", ah->stats.ast_ani_cckerrs },
156abee4c84SFelix Fietkau 	};
15705c0be2fSMohammed Shafi Shajakhan 
1586e4d291eSSujith Manoharan 	buf = kzalloc(size, GFP_KERNEL);
1596e4d291eSSujith Manoharan 	if (buf == NULL)
1606e4d291eSSujith Manoharan 		return -ENOMEM;
1616e4d291eSSujith Manoharan 
162abee4c84SFelix Fietkau 	len += scnprintf(buf + len, size - len, "%15s: %s\n", "ANI",
163abee4c84SFelix Fietkau 			 common->disable_ani ? "DISABLED" : "ENABLED");
16405c0be2fSMohammed Shafi Shajakhan 
165abee4c84SFelix Fietkau 	if (common->disable_ani)
166abee4c84SFelix Fietkau 		goto exit;
167abee4c84SFelix Fietkau 
168abee4c84SFelix Fietkau 	for (i = 0; i < ARRAY_SIZE(ani_info); i++)
1695e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, size - len, "%15s: %u\n",
170abee4c84SFelix Fietkau 				 ani_info[i].name, ani_info[i].val);
171abee4c84SFelix Fietkau 
1726e4d291eSSujith Manoharan exit:
1736e4d291eSSujith Manoharan 	if (len > size)
1746e4d291eSSujith Manoharan 		len = size;
1756e4d291eSSujith Manoharan 
1766e4d291eSSujith Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1776e4d291eSSujith Manoharan 	kfree(buf);
1786e4d291eSSujith Manoharan 
1796e4d291eSSujith Manoharan 	return retval;
1806e4d291eSSujith Manoharan }
1816e4d291eSSujith Manoharan 
write_file_ani(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)1826e4d291eSSujith Manoharan static ssize_t write_file_ani(struct file *file,
18305c0be2fSMohammed Shafi Shajakhan 			      const char __user *user_buf,
18405c0be2fSMohammed Shafi Shajakhan 			      size_t count, loff_t *ppos)
18505c0be2fSMohammed Shafi Shajakhan {
18605c0be2fSMohammed Shafi Shajakhan 	struct ath_softc *sc = file->private_data;
18705c0be2fSMohammed Shafi Shajakhan 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1886e4d291eSSujith Manoharan 	unsigned long ani;
1898b804643SDmitry Antipov 	ssize_t ret;
19005c0be2fSMohammed Shafi Shajakhan 
1918b804643SDmitry Antipov 	ret = kstrtoul_from_user(user_buf, count, 0, &ani);
1928b804643SDmitry Antipov 	if (ret)
1938b804643SDmitry Antipov 		return ret;
19405c0be2fSMohammed Shafi Shajakhan 
1953f557202SAndrey Utkin 	if (ani > 1)
1966e4d291eSSujith Manoharan 		return -EINVAL;
19705c0be2fSMohammed Shafi Shajakhan 
1986e4d291eSSujith Manoharan 	common->disable_ani = !ani;
1996e4d291eSSujith Manoharan 
2006e4d291eSSujith Manoharan 	if (common->disable_ani) {
201eefa01ddSOleksij Rempel 		clear_bit(ATH_OP_ANI_RUN, &common->op_flags);
202da0d45f7SSujith Manoharan 		ath_stop_ani(sc);
20305c0be2fSMohammed Shafi Shajakhan 	} else {
204da0d45f7SSujith Manoharan 		ath_check_ani(sc);
20505c0be2fSMohammed Shafi Shajakhan 	}
20605c0be2fSMohammed Shafi Shajakhan 
20705c0be2fSMohammed Shafi Shajakhan 	return count;
20805c0be2fSMohammed Shafi Shajakhan }
20905c0be2fSMohammed Shafi Shajakhan 
2106e4d291eSSujith Manoharan static const struct file_operations fops_ani = {
2116e4d291eSSujith Manoharan 	.read = read_file_ani,
2126e4d291eSSujith Manoharan 	.write = write_file_ani,
213234e3405SStephen Boyd 	.open = simple_open,
21405c0be2fSMohammed Shafi Shajakhan 	.owner = THIS_MODULE,
21505c0be2fSMohammed Shafi Shajakhan 	.llseek = default_llseek,
21605c0be2fSMohammed Shafi Shajakhan };
21715340694SFelix Fietkau 
21836e8825eSSujith Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
21936e8825eSSujith Manoharan 
read_file_bt_ant_diversity(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)22063081305SSujith Manoharan static ssize_t read_file_bt_ant_diversity(struct file *file,
22163081305SSujith Manoharan 					  char __user *user_buf,
222302a3c3aSSujith Manoharan 					  size_t count, loff_t *ppos)
223302a3c3aSSujith Manoharan {
224302a3c3aSSujith Manoharan 	struct ath_softc *sc = file->private_data;
225302a3c3aSSujith Manoharan 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
226302a3c3aSSujith Manoharan 	char buf[32];
227302a3c3aSSujith Manoharan 	unsigned int len;
228302a3c3aSSujith Manoharan 
22963081305SSujith Manoharan 	len = sprintf(buf, "%d\n", common->bt_ant_diversity);
230302a3c3aSSujith Manoharan 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
231302a3c3aSSujith Manoharan }
232302a3c3aSSujith Manoharan 
write_file_bt_ant_diversity(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)23363081305SSujith Manoharan static ssize_t write_file_bt_ant_diversity(struct file *file,
234302a3c3aSSujith Manoharan 					   const char __user *user_buf,
235302a3c3aSSujith Manoharan 					   size_t count, loff_t *ppos)
236302a3c3aSSujith Manoharan {
237302a3c3aSSujith Manoharan 	struct ath_softc *sc = file->private_data;
238302a3c3aSSujith Manoharan 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2393f2da955SSujith Manoharan 	struct ath9k_hw_capabilities *pCap = &sc->sc_ah->caps;
24063081305SSujith Manoharan 	unsigned long bt_ant_diversity;
2418b804643SDmitry Antipov 	ssize_t ret;
242302a3c3aSSujith Manoharan 
2438b804643SDmitry Antipov 	ret = kstrtoul_from_user(user_buf, count, 0, &bt_ant_diversity);
2448b804643SDmitry Antipov 	if (ret)
2458b804643SDmitry Antipov 		return ret;
246302a3c3aSSujith Manoharan 
2473f2da955SSujith Manoharan 	if (!(pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
2483f2da955SSujith Manoharan 		goto exit;
2493f2da955SSujith Manoharan 
25063081305SSujith Manoharan 	common->bt_ant_diversity = !!bt_ant_diversity;
251302a3c3aSSujith Manoharan 	ath9k_ps_wakeup(sc);
252047dc3acSSujith Manoharan 	ath9k_hw_set_bt_ant_diversity(sc->sc_ah, common->bt_ant_diversity);
25363081305SSujith Manoharan 	ath_dbg(common, CONFIG, "Enable WLAN/BT RX Antenna diversity: %d\n",
25463081305SSujith Manoharan 		common->bt_ant_diversity);
255302a3c3aSSujith Manoharan 	ath9k_ps_restore(sc);
2563f2da955SSujith Manoharan exit:
257302a3c3aSSujith Manoharan 	return count;
258302a3c3aSSujith Manoharan }
259302a3c3aSSujith Manoharan 
26063081305SSujith Manoharan static const struct file_operations fops_bt_ant_diversity = {
26163081305SSujith Manoharan 	.read = read_file_bt_ant_diversity,
26263081305SSujith Manoharan 	.write = write_file_bt_ant_diversity,
263302a3c3aSSujith Manoharan 	.open = simple_open,
264302a3c3aSSujith Manoharan 	.owner = THIS_MODULE,
265302a3c3aSSujith Manoharan 	.llseek = default_llseek,
266302a3c3aSSujith Manoharan };
267302a3c3aSSujith Manoharan 
26836e8825eSSujith Manoharan #endif
26936e8825eSSujith Manoharan 
ath9k_debug_stat_ant(struct ath_softc * sc,struct ath_hw_antcomb_conf * div_ant_conf,int main_rssi_avg,int alt_rssi_avg)270e3d52914SSujith Manoharan void ath9k_debug_stat_ant(struct ath_softc *sc,
271e3d52914SSujith Manoharan 			  struct ath_hw_antcomb_conf *div_ant_conf,
272e3d52914SSujith Manoharan 			  int main_rssi_avg, int alt_rssi_avg)
273e3d52914SSujith Manoharan {
274e3d52914SSujith Manoharan 	struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
275e3d52914SSujith Manoharan 	struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
276e3d52914SSujith Manoharan 
277e3d52914SSujith Manoharan 	as_main->lna_attempt_cnt[div_ant_conf->main_lna_conf]++;
278e3d52914SSujith Manoharan 	as_alt->lna_attempt_cnt[div_ant_conf->alt_lna_conf]++;
279e3d52914SSujith Manoharan 
280e3d52914SSujith Manoharan 	as_main->rssi_avg = main_rssi_avg;
281e3d52914SSujith Manoharan 	as_alt->rssi_avg = alt_rssi_avg;
282e3d52914SSujith Manoharan }
283e3d52914SSujith Manoharan 
read_file_antenna_diversity(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)2844eba10ccSSujith Manoharan static ssize_t read_file_antenna_diversity(struct file *file,
2854eba10ccSSujith Manoharan 					   char __user *user_buf,
2864eba10ccSSujith Manoharan 					   size_t count, loff_t *ppos)
2874eba10ccSSujith Manoharan {
2884eba10ccSSujith Manoharan 	struct ath_softc *sc = file->private_data;
2894eba10ccSSujith Manoharan 	struct ath_hw *ah = sc->sc_ah;
2904eba10ccSSujith Manoharan 	struct ath9k_hw_capabilities *pCap = &ah->caps;
2914eba10ccSSujith Manoharan 	struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
2924eba10ccSSujith Manoharan 	struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
293e3d52914SSujith Manoharan 	struct ath_hw_antcomb_conf div_ant_conf;
2942120ac96SJoe Perches 	unsigned int len = 0;
2952120ac96SJoe Perches 	const unsigned int size = 1024;
2964eba10ccSSujith Manoharan 	ssize_t retval = 0;
2974eba10ccSSujith Manoharan 	char *buf;
2982120ac96SJoe Perches 	static const char *lna_conf_str[4] = {
2992120ac96SJoe Perches 		"LNA1_MINUS_LNA2", "LNA2", "LNA1", "LNA1_PLUS_LNA2"
3002120ac96SJoe Perches 	};
3014eba10ccSSujith Manoharan 
3024eba10ccSSujith Manoharan 	buf = kzalloc(size, GFP_KERNEL);
3034eba10ccSSujith Manoharan 	if (buf == NULL)
3044eba10ccSSujith Manoharan 		return -ENOMEM;
3054eba10ccSSujith Manoharan 
3064eba10ccSSujith Manoharan 	if (!(pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)) {
3075e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, size - len, "%s\n",
3084eba10ccSSujith Manoharan 				 "Antenna Diversity Combining is disabled");
3094eba10ccSSujith Manoharan 		goto exit;
3104eba10ccSSujith Manoharan 	}
3114eba10ccSSujith Manoharan 
312e3d52914SSujith Manoharan 	ath9k_ps_wakeup(sc);
313e3d52914SSujith Manoharan 	ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
3145e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "Current MAIN config : %s\n",
315e3d52914SSujith Manoharan 			 lna_conf_str[div_ant_conf.main_lna_conf]);
3165e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "Current ALT config  : %s\n",
317e3d52914SSujith Manoharan 			 lna_conf_str[div_ant_conf.alt_lna_conf]);
3185e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "Average MAIN RSSI   : %d\n",
319e3d52914SSujith Manoharan 			 as_main->rssi_avg);
3205e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "Average ALT RSSI    : %d\n\n",
321e3d52914SSujith Manoharan 			 as_alt->rssi_avg);
322e3d52914SSujith Manoharan 	ath9k_ps_restore(sc);
323e3d52914SSujith Manoharan 
3245e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "Packet Receive Cnt:\n");
3255e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "-------------------\n");
326e3d52914SSujith Manoharan 
3275e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%30s%15s\n",
3284eba10ccSSujith Manoharan 			 "MAIN", "ALT");
3295e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
330e3d52914SSujith Manoharan 			 "TOTAL COUNT",
3314eba10ccSSujith Manoharan 			 as_main->recv_cnt,
3324eba10ccSSujith Manoharan 			 as_alt->recv_cnt);
3335e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3344eba10ccSSujith Manoharan 			 "LNA1",
335e3d52914SSujith Manoharan 			 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1],
336e3d52914SSujith Manoharan 			 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1]);
3375e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3384eba10ccSSujith Manoharan 			 "LNA2",
339e3d52914SSujith Manoharan 			 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2],
340e3d52914SSujith Manoharan 			 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2]);
3415e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3424eba10ccSSujith Manoharan 			 "LNA1 + LNA2",
343e3d52914SSujith Manoharan 			 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
344e3d52914SSujith Manoharan 			 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
3455e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3464eba10ccSSujith Manoharan 			 "LNA1 - LNA2",
347e3d52914SSujith Manoharan 			 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
348e3d52914SSujith Manoharan 			 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
349e3d52914SSujith Manoharan 
3505e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "\nLNA Config Attempts:\n");
3515e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "--------------------\n");
352e3d52914SSujith Manoharan 
3535e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%30s%15s\n",
354e3d52914SSujith Manoharan 			 "MAIN", "ALT");
3555e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
356e3d52914SSujith Manoharan 			 "LNA1",
357e3d52914SSujith Manoharan 			 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1],
358e3d52914SSujith Manoharan 			 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1]);
3595e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
360e3d52914SSujith Manoharan 			 "LNA2",
361e3d52914SSujith Manoharan 			 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2],
362e3d52914SSujith Manoharan 			 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2]);
3635e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
364e3d52914SSujith Manoharan 			 "LNA1 + LNA2",
365e3d52914SSujith Manoharan 			 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
366e3d52914SSujith Manoharan 			 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
3675e88ba62SZefir Kurtisi 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
368e3d52914SSujith Manoharan 			 "LNA1 - LNA2",
369e3d52914SSujith Manoharan 			 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
370e3d52914SSujith Manoharan 			 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
371e3d52914SSujith Manoharan 
3724eba10ccSSujith Manoharan exit:
3734eba10ccSSujith Manoharan 	if (len > size)
3744eba10ccSSujith Manoharan 		len = size;
3754eba10ccSSujith Manoharan 
3764eba10ccSSujith Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
3774eba10ccSSujith Manoharan 	kfree(buf);
3784eba10ccSSujith Manoharan 
3794eba10ccSSujith Manoharan 	return retval;
3804eba10ccSSujith Manoharan }
3814eba10ccSSujith Manoharan 
3824eba10ccSSujith Manoharan static const struct file_operations fops_antenna_diversity = {
3834eba10ccSSujith Manoharan 	.read = read_file_antenna_diversity,
3844eba10ccSSujith Manoharan 	.open = simple_open,
3854eba10ccSSujith Manoharan 	.owner = THIS_MODULE,
3864eba10ccSSujith Manoharan 	.llseek = default_llseek,
3874eba10ccSSujith Manoharan };
3884eba10ccSSujith Manoharan 
read_file_dma(struct seq_file * file,void * data)389631bee25SArend van Spriel static int read_file_dma(struct seq_file *file, void *data)
390203c4805SLuis R. Rodriguez {
3914447d815SArend van Spriel 	struct ieee80211_hw *hw = dev_get_drvdata(file->private);
3924447d815SArend van Spriel 	struct ath_softc *sc = hw->priv;
393203c4805SLuis R. Rodriguez 	struct ath_hw *ah = sc->sc_ah;
394203c4805SLuis R. Rodriguez 	u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
395203c4805SLuis R. Rodriguez 	int i, qcuOffset = 0, dcuOffset = 0;
396203c4805SLuis R. Rodriguez 	u32 *qcuBase = &val[0], *dcuBase = &val[4];
397203c4805SLuis R. Rodriguez 
3987cf4a2e7SSujith 	ath9k_ps_wakeup(sc);
3997cf4a2e7SSujith 
400475a6e4dSLuis R. Rodriguez 	REG_WRITE_D(ah, AR_MACMISC,
401203c4805SLuis R. Rodriguez 		  ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
402203c4805SLuis R. Rodriguez 		   (AR_MACMISC_MISC_OBS_BUS_1 <<
403203c4805SLuis R. Rodriguez 		    AR_MACMISC_MISC_OBS_BUS_MSB_S)));
404203c4805SLuis R. Rodriguez 
405631bee25SArend van Spriel 	seq_puts(file, "Raw DMA Debug values:\n");
406203c4805SLuis R. Rodriguez 
407203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
408203c4805SLuis R. Rodriguez 		if (i % 4 == 0)
409631bee25SArend van Spriel 			seq_puts(file, "\n");
410203c4805SLuis R. Rodriguez 
411475a6e4dSLuis R. Rodriguez 		val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
412631bee25SArend van Spriel 		seq_printf(file, "%d: %08x ", i, val[i]);
413203c4805SLuis R. Rodriguez 	}
414203c4805SLuis R. Rodriguez 
415631bee25SArend van Spriel 	seq_puts(file, "\n\n");
416631bee25SArend van Spriel 	seq_puts(file, "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
417203c4805SLuis R. Rodriguez 
418203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
419203c4805SLuis R. Rodriguez 		if (i == 8) {
420203c4805SLuis R. Rodriguez 			qcuOffset = 0;
421203c4805SLuis R. Rodriguez 			qcuBase++;
422203c4805SLuis R. Rodriguez 		}
423203c4805SLuis R. Rodriguez 
424203c4805SLuis R. Rodriguez 		if (i == 6) {
425203c4805SLuis R. Rodriguez 			dcuOffset = 0;
426203c4805SLuis R. Rodriguez 			dcuBase++;
427203c4805SLuis R. Rodriguez 		}
428203c4805SLuis R. Rodriguez 
429631bee25SArend van Spriel 		seq_printf(file, "%2d          %2x      %1x     %2x           %2x\n",
430203c4805SLuis R. Rodriguez 			   i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
431203c4805SLuis R. Rodriguez 			   (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
432a017ff75SDan Carpenter 			   (val[2] & (0x7 << (i * 3))) >> (i * 3),
433203c4805SLuis R. Rodriguez 			   (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
434203c4805SLuis R. Rodriguez 	}
435203c4805SLuis R. Rodriguez 
436631bee25SArend van Spriel 	seq_puts(file, "\n");
437203c4805SLuis R. Rodriguez 
438631bee25SArend van Spriel 	seq_printf(file, "qcu_stitch state:   %2x    qcu_fetch state:        %2x\n",
439203c4805SLuis R. Rodriguez 		   (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
440631bee25SArend van Spriel 	seq_printf(file, "qcu_complete state: %2x    dcu_complete state:     %2x\n",
441203c4805SLuis R. Rodriguez 		   (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
442631bee25SArend van Spriel 	seq_printf(file, "dcu_arb state:      %2x    dcu_fp state:           %2x\n",
443203c4805SLuis R. Rodriguez 		   (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
444631bee25SArend van Spriel 	seq_printf(file, "chan_idle_dur:     %3d    chan_idle_dur_valid:     %1d\n",
445203c4805SLuis R. Rodriguez 		   (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
446631bee25SArend van Spriel 	seq_printf(file, "txfifo_valid_0:      %1d    txfifo_valid_1:          %1d\n",
447203c4805SLuis R. Rodriguez 		   (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
448631bee25SArend van Spriel 	seq_printf(file, "txfifo_dcu_num_0:   %2d    txfifo_dcu_num_1:       %2d\n",
449203c4805SLuis R. Rodriguez 		   (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
450203c4805SLuis R. Rodriguez 
451631bee25SArend van Spriel 	seq_printf(file, "pcu observe: 0x%x\n", REG_READ_D(ah, AR_OBS_BUS_1));
452631bee25SArend van Spriel 	seq_printf(file, "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
453203c4805SLuis R. Rodriguez 
4547cf4a2e7SSujith 	ath9k_ps_restore(sc);
4557cf4a2e7SSujith 
456631bee25SArend van Spriel 	return 0;
457631bee25SArend van Spriel }
4582b87f3aaSDan Carpenter 
ath_debug_stat_interrupt(struct ath_softc * sc,enum ath9k_int status)459203c4805SLuis R. Rodriguez void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
460203c4805SLuis R. Rodriguez {
461203c4805SLuis R. Rodriguez 	if (status)
462203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.total++;
463a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
464a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXLP)
465a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxlp++;
466a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXHP)
467a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxhp++;
46808578b8fSLuis R. Rodriguez 		if (status & ATH9K_INT_BB_WATCHDOG)
46908578b8fSLuis R. Rodriguez 			sc->debug.stats.istats.bb_watchdog++;
470a9616f41SLuis R. Rodriguez 	} else {
471203c4805SLuis R. Rodriguez 		if (status & ATH9K_INT_RX)
472203c4805SLuis R. Rodriguez 			sc->debug.stats.istats.rxok++;
473a9616f41SLuis R. Rodriguez 	}
474203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXEOL)
475203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxeol++;
476203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXORN)
477203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxorn++;
478203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TX)
479203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txok++;
480203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TXURN)
481203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txurn++;
482203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXPHY)
483203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxphyerr++;
484203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXKCM)
485203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rx_keycache_miss++;
486203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_SWBA)
487203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.swba++;
488203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BMISS)
489203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bmiss++;
490203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BNR)
491203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bnr++;
492203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CST)
493203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cst++;
494203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_GTT)
495203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.gtt++;
496203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TIM)
497203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.tim++;
498203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CABEND)
499203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cabend++;
500203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIMSYNC)
501203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtimsync++;
502203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIM)
503203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtim++;
5046dde1aabSMohammed Shafi Shajakhan 	if (status & ATH9K_INT_TSFOOR)
5056dde1aabSMohammed Shafi Shajakhan 		sc->debug.stats.istats.tsfoor++;
50697ba515aSSujith Manoharan 	if (status & ATH9K_INT_MCI)
50797ba515aSSujith Manoharan 		sc->debug.stats.istats.mci++;
508c9e6e980SMohammed Shafi Shajakhan 	if (status & ATH9K_INT_GENTIMER)
509c9e6e980SMohammed Shafi Shajakhan 		sc->debug.stats.istats.gen_timer++;
510203c4805SLuis R. Rodriguez }
511203c4805SLuis R. Rodriguez 
read_file_interrupt(struct seq_file * file,void * data)512631bee25SArend van Spriel static int read_file_interrupt(struct seq_file *file, void *data)
513203c4805SLuis R. Rodriguez {
5144447d815SArend van Spriel 	struct ieee80211_hw *hw = dev_get_drvdata(file->private);
5154447d815SArend van Spriel 	struct ath_softc *sc = hw->priv;
516462e58f2SBen Greear 
517462e58f2SBen Greear #define PR_IS(a, s)						\
518462e58f2SBen Greear 	do {							\
519631bee25SArend van Spriel 		seq_printf(file, "%21s: %10u\n", a,		\
520462e58f2SBen Greear 			   sc->debug.stats.istats.s);		\
521462e58f2SBen Greear 	} while (0)
522203c4805SLuis R. Rodriguez 
523a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
524462e58f2SBen Greear 		PR_IS("RXLP", rxlp);
525462e58f2SBen Greear 		PR_IS("RXHP", rxhp);
526d5e5f685SColin Ian King 		PR_IS("WATCHDOG", bb_watchdog);
527a9616f41SLuis R. Rodriguez 	} else {
528462e58f2SBen Greear 		PR_IS("RX", rxok);
529a9616f41SLuis R. Rodriguez 	}
530462e58f2SBen Greear 	PR_IS("RXEOL", rxeol);
531462e58f2SBen Greear 	PR_IS("RXORN", rxorn);
532462e58f2SBen Greear 	PR_IS("TX", txok);
533462e58f2SBen Greear 	PR_IS("TXURN", txurn);
534462e58f2SBen Greear 	PR_IS("MIB", mib);
535462e58f2SBen Greear 	PR_IS("RXPHY", rxphyerr);
536462e58f2SBen Greear 	PR_IS("RXKCM", rx_keycache_miss);
537462e58f2SBen Greear 	PR_IS("SWBA", swba);
538462e58f2SBen Greear 	PR_IS("BMISS", bmiss);
539462e58f2SBen Greear 	PR_IS("BNR", bnr);
540462e58f2SBen Greear 	PR_IS("CST", cst);
541462e58f2SBen Greear 	PR_IS("GTT", gtt);
542462e58f2SBen Greear 	PR_IS("TIM", tim);
543462e58f2SBen Greear 	PR_IS("CABEND", cabend);
544462e58f2SBen Greear 	PR_IS("DTIMSYNC", dtimsync);
545462e58f2SBen Greear 	PR_IS("DTIM", dtim);
546462e58f2SBen Greear 	PR_IS("TSFOOR", tsfoor);
54797ba515aSSujith Manoharan 	PR_IS("MCI", mci);
548c9e6e980SMohammed Shafi Shajakhan 	PR_IS("GENTIMER", gen_timer);
549462e58f2SBen Greear 	PR_IS("TOTAL", total);
550203c4805SLuis R. Rodriguez 
551631bee25SArend van Spriel 	seq_puts(file, "SYNC_CAUSE stats:\n");
5526dde1aabSMohammed Shafi Shajakhan 
553462e58f2SBen Greear 	PR_IS("Sync-All", sync_cause_all);
554462e58f2SBen Greear 	PR_IS("RTC-IRQ", sync_rtc_irq);
555462e58f2SBen Greear 	PR_IS("MAC-IRQ", sync_mac_irq);
556462e58f2SBen Greear 	PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
557462e58f2SBen Greear 	PR_IS("APB-Timeout", apb_timeout);
558462e58f2SBen Greear 	PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
559462e58f2SBen Greear 	PR_IS("HOST1-Fatal", host1_fatal);
560462e58f2SBen Greear 	PR_IS("HOST1-Perr", host1_perr);
561462e58f2SBen Greear 	PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
562462e58f2SBen Greear 	PR_IS("RADM-CPL-EP", radm_cpl_ep);
563462e58f2SBen Greear 	PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
564462e58f2SBen Greear 	PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
565462e58f2SBen Greear 	PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
566462e58f2SBen Greear 	PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
567462e58f2SBen Greear 	PR_IS("Local-Bus-Timeout", local_timeout);
568462e58f2SBen Greear 	PR_IS("PM-Access", pm_access);
569462e58f2SBen Greear 	PR_IS("MAC-Awake", mac_awake);
570462e58f2SBen Greear 	PR_IS("MAC-Asleep", mac_asleep);
571462e58f2SBen Greear 	PR_IS("MAC-Sleep-Access", mac_sleep_access);
5722b87f3aaSDan Carpenter 
573631bee25SArend van Spriel 	return 0;
574631bee25SArend van Spriel }
575462e58f2SBen Greear 
read_file_xmit(struct seq_file * file,void * data)576631bee25SArend van Spriel static int read_file_xmit(struct seq_file *file, void *data)
577fec247c0SSujith {
5784447d815SArend van Spriel 	struct ieee80211_hw *hw = dev_get_drvdata(file->private);
5794447d815SArend van Spriel 	struct ath_softc *sc = hw->priv;
580fec247c0SSujith 
581631bee25SArend van Spriel 	seq_printf(file, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
582fec247c0SSujith 
583fec247c0SSujith 	PR("MPDUs Queued:    ", queued);
584fec247c0SSujith 	PR("MPDUs Completed: ", completed);
5855a6f78afSFelix Fietkau 	PR("MPDUs XRetried:  ", xretries);
586fec247c0SSujith 	PR("Aggregates:      ", a_aggr);
587bda8addaSBen Greear 	PR("AMPDUs Queued HW:", a_queued_hw);
588fec247c0SSujith 	PR("AMPDUs Completed:", a_completed);
589fec247c0SSujith 	PR("AMPDUs Retried:  ", a_retries);
590fec247c0SSujith 	PR("AMPDUs XRetried: ", a_xretries);
5914d900389SBen Greear 	PR("TXERR Filtered:  ", txerr_filtered);
592fec247c0SSujith 	PR("FIFO Underrun:   ", fifo_underrun);
593fec247c0SSujith 	PR("TXOP Exceeded:   ", xtxop);
594fec247c0SSujith 	PR("TXTIMER Expiry:  ", timer_exp);
595fec247c0SSujith 	PR("DESC CFG Error:  ", desc_cfg_err);
596fec247c0SSujith 	PR("DATA Underrun:   ", data_underrun);
597fec247c0SSujith 	PR("DELIM Underrun:  ", delim_underrun);
59899c15bf5SBen Greear 	PR("TX-Pkts-All:     ", tx_pkts_all);
59999c15bf5SBen Greear 	PR("TX-Bytes-All:    ", tx_bytes_all);
60078ef731cSSujith Manoharan 	PR("HW-put-tx-buf:   ", puttxbuf);
60178ef731cSSujith Manoharan 	PR("HW-tx-start:     ", txstart);
60278ef731cSSujith Manoharan 	PR("HW-tx-proc-desc: ", txprocdesc);
603a5a0bca1SBen Greear 	PR("TX-Failed:       ", txfailed);
604fec247c0SSujith 
605631bee25SArend van Spriel 	return 0;
6067f010c93SBen Greear }
6077f010c93SBen Greear 
print_queue(struct ath_softc * sc,struct ath_txq * txq,struct seq_file * file)608631bee25SArend van Spriel static void print_queue(struct ath_softc *sc, struct ath_txq *txq,
609631bee25SArend van Spriel 			struct seq_file *file)
61018fcf1c6SFelix Fietkau {
61118fcf1c6SFelix Fietkau 	ath_txq_lock(sc, txq);
61218fcf1c6SFelix Fietkau 
613631bee25SArend van Spriel 	seq_printf(file, "%s: %d ", "qnum", txq->axq_qnum);
614631bee25SArend van Spriel 	seq_printf(file, "%s: %2d ", "qdepth", txq->axq_depth);
615631bee25SArend van Spriel 	seq_printf(file, "%s: %2d ", "ampdu-depth", txq->axq_ampdu_depth);
61650f08edfSToke Høiland-Jørgensen 	seq_printf(file, "%s: %3d\n", "pending", txq->pending_frames);
61718fcf1c6SFelix Fietkau 
61818fcf1c6SFelix Fietkau 	ath_txq_unlock(sc, txq);
61918fcf1c6SFelix Fietkau }
62018fcf1c6SFelix Fietkau 
read_file_queues(struct seq_file * file,void * data)621631bee25SArend van Spriel static int read_file_queues(struct seq_file *file, void *data)
622c0b74876SSujith Manoharan {
6234447d815SArend van Spriel 	struct ieee80211_hw *hw = dev_get_drvdata(file->private);
6244447d815SArend van Spriel 	struct ath_softc *sc = hw->priv;
625c0b74876SSujith Manoharan 	struct ath_txq *txq;
626c0b74876SSujith Manoharan 	int i;
6272120ac96SJoe Perches 	static const char *qname[4] = {
6282120ac96SJoe Perches 		"VO", "VI", "BE", "BK"
6292120ac96SJoe Perches 	};
630c0b74876SSujith Manoharan 
631c0b74876SSujith Manoharan 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
632c0b74876SSujith Manoharan 		txq = sc->tx.txq_map[i];
633631bee25SArend van Spriel 		seq_printf(file, "(%s):  ", qname[i]);
634631bee25SArend van Spriel 		print_queue(sc, txq, file);
635c0b74876SSujith Manoharan 	}
636c0b74876SSujith Manoharan 
637631bee25SArend van Spriel 	seq_puts(file, "(CAB): ");
638631bee25SArend van Spriel 	print_queue(sc, sc->beacon.cabq, file);
63918fcf1c6SFelix Fietkau 
640631bee25SArend van Spriel 	return 0;
641c0b74876SSujith Manoharan }
642c0b74876SSujith Manoharan 
read_file_misc(struct seq_file * file,void * data)643631bee25SArend van Spriel static int read_file_misc(struct seq_file *file, void *data)
64455f6d0ffSBen Greear {
6454447d815SArend van Spriel 	struct ieee80211_hw *hw = dev_get_drvdata(file->private);
6464447d815SArend van Spriel 	struct ath_softc *sc = hw->priv;
64755f6d0ffSBen Greear 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
6486bcf6f64SSujith Manoharan 	struct ath9k_vif_iter_data iter_data;
6499a9c4fbcSRajkumar Manoharan 	struct ath_chanctx *ctx;
65055f6d0ffSBen Greear 	unsigned int reg;
6519a9c4fbcSRajkumar Manoharan 	u32 rxfilter, i;
6526bcf6f64SSujith Manoharan 
653631bee25SArend van Spriel 	seq_printf(file, "BSSID: %pM\n", common->curbssid);
654631bee25SArend van Spriel 	seq_printf(file, "BSSID-MASK: %pM\n", common->bssidmask);
655631bee25SArend van Spriel 	seq_printf(file, "OPMODE: %s\n",
6565e88ba62SZefir Kurtisi 		   ath_opmode_to_string(sc->sc_ah->opmode));
6576bcf6f64SSujith Manoharan 
6586bcf6f64SSujith Manoharan 	ath9k_ps_wakeup(sc);
6596bcf6f64SSujith Manoharan 	rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
6606bcf6f64SSujith Manoharan 	ath9k_ps_restore(sc);
6616bcf6f64SSujith Manoharan 
662631bee25SArend van Spriel 	seq_printf(file, "RXFILTER: 0x%x", rxfilter);
6636bcf6f64SSujith Manoharan 
6646bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_UCAST)
665631bee25SArend van Spriel 		seq_puts(file, " UCAST");
6666bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MCAST)
667631bee25SArend van Spriel 		seq_puts(file, " MCAST");
6686bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_BCAST)
669631bee25SArend van Spriel 		seq_puts(file, " BCAST");
6706bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_CONTROL)
671631bee25SArend van Spriel 		seq_puts(file, " CONTROL");
6726bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_BEACON)
673631bee25SArend van Spriel 		seq_puts(file, " BEACON");
6746bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PROM)
675631bee25SArend van Spriel 		seq_puts(file, " PROM");
6766bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
677631bee25SArend van Spriel 		seq_puts(file, " PROBEREQ");
6786bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PHYERR)
679631bee25SArend van Spriel 		seq_puts(file, " PHYERR");
6806bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
681631bee25SArend van Spriel 		seq_puts(file, " MYBEACON");
6826bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
683631bee25SArend van Spriel 		seq_puts(file, " COMP_BAR");
6846bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
685631bee25SArend van Spriel 		seq_puts(file, " PSPOLL");
6866bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
687631bee25SArend van Spriel 		seq_puts(file, " PHYRADAR");
6886bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
689631bee25SArend van Spriel 		seq_puts(file, " MCAST_BCAST_ALL");
6906bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
691631bee25SArend van Spriel 		seq_puts(file, " CONTROL_WRAPPER");
6926bcf6f64SSujith Manoharan 
693631bee25SArend van Spriel 	seq_puts(file, "\n");
6946bcf6f64SSujith Manoharan 
6956bcf6f64SSujith Manoharan 	reg = sc->sc_ah->imask;
6966bcf6f64SSujith Manoharan 
697631bee25SArend van Spriel 	seq_printf(file, "INTERRUPT-MASK: 0x%x", reg);
6986bcf6f64SSujith Manoharan 
6996bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_SWBA)
700631bee25SArend van Spriel 		seq_puts(file, " SWBA");
7016bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_BMISS)
702631bee25SArend van Spriel 		seq_puts(file, " BMISS");
7036bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_CST)
704631bee25SArend van Spriel 		seq_puts(file, " CST");
7056bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RX)
706631bee25SArend van Spriel 		seq_puts(file, " RX");
7076bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RXHP)
708631bee25SArend van Spriel 		seq_puts(file, " RXHP");
7096bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RXLP)
710631bee25SArend van Spriel 		seq_puts(file, " RXLP");
7116bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_BB_WATCHDOG)
712631bee25SArend van Spriel 		seq_puts(file, " BB_WATCHDOG");
7136bcf6f64SSujith Manoharan 
714631bee25SArend van Spriel 	seq_puts(file, "\n");
71555f6d0ffSBen Greear 
7169a9c4fbcSRajkumar Manoharan 	i = 0;
7179a9c4fbcSRajkumar Manoharan 	ath_for_each_chanctx(sc, ctx) {
718325e1881SBen Greear 		if (list_empty(&ctx->vifs))
7199a9c4fbcSRajkumar Manoharan 			continue;
7209a9c4fbcSRajkumar Manoharan 		ath9k_calculate_iter_data(sc, ctx, &iter_data);
72155f6d0ffSBen Greear 
722631bee25SArend van Spriel 		seq_printf(file,
723f4899218SJohannes Berg 			   "VIFS: CTX %i(%i) AP: %i STA: %i MESH: %i",
724325e1881SBen Greear 			   i++, (int)(ctx->assigned), iter_data.naps,
725325e1881SBen Greear 			   iter_data.nstations,
726f4899218SJohannes Berg 			   iter_data.nmeshes);
727862a336cSJan Kaisrlik 		seq_printf(file, " ADHOC: %i OCB: %i TOTAL: %hi BEACON-VIF: %hi\n",
728862a336cSJan Kaisrlik 			   iter_data.nadhocs, iter_data.nocbs, sc->cur_chan->nvifs,
729631bee25SArend van Spriel 			   sc->nbcnvifs);
7309a9c4fbcSRajkumar Manoharan 	}
73155f6d0ffSBen Greear 
732631bee25SArend van Spriel 	return 0;
73355f6d0ffSBen Greear }
73455f6d0ffSBen Greear 
read_file_reset(struct seq_file * file,void * data)735631bee25SArend van Spriel static int read_file_reset(struct seq_file *file, void *data)
736f8b815dcSSujith Manoharan {
737053f9852SLinus Lüssing 	struct ath_softc *sc = file->private;
73870e535edSFelix Fietkau 	static const char * const reset_cause[__RESET_TYPE_MAX] = {
739053f9852SLinus Lüssing 		[RESET_TYPE_USER] = "User reset",
74070e535edSFelix Fietkau 		[RESET_TYPE_BB_HANG] = "Baseband Hang",
74170e535edSFelix Fietkau 		[RESET_TYPE_BB_WATCHDOG] = "Baseband Watchdog",
74270e535edSFelix Fietkau 		[RESET_TYPE_FATAL_INT] = "Fatal HW Error",
74370e535edSFelix Fietkau 		[RESET_TYPE_TX_ERROR] = "TX HW error",
74470e535edSFelix Fietkau 		[RESET_TYPE_TX_GTT] = "Transmit timeout",
74570e535edSFelix Fietkau 		[RESET_TYPE_TX_HANG] = "TX Path Hang",
74670e535edSFelix Fietkau 		[RESET_TYPE_PLL_HANG] = "PLL RX Hang",
74770e535edSFelix Fietkau 		[RESET_TYPE_MAC_HANG] = "MAC Hang",
74870e535edSFelix Fietkau 		[RESET_TYPE_BEACON_STUCK] = "Stuck Beacon",
74970e535edSFelix Fietkau 		[RESET_TYPE_MCI] = "MCI Reset",
7507b8aaeadSFelix Fietkau 		[RESET_TYPE_CALIBRATION] = "Calibration error",
751e60ac9c7SFelix Fietkau 		[RESET_TX_DMA_ERROR] = "Tx DMA stop error",
752e60ac9c7SFelix Fietkau 		[RESET_RX_DMA_ERROR] = "Rx DMA stop error",
75370e535edSFelix Fietkau 	};
75470e535edSFelix Fietkau 	int i;
75570e535edSFelix Fietkau 
75670e535edSFelix Fietkau 	for (i = 0; i < ARRAY_SIZE(reset_cause); i++) {
75770e535edSFelix Fietkau 		if (!reset_cause[i])
75870e535edSFelix Fietkau 		    continue;
759f8b815dcSSujith Manoharan 
760e6b5be2bSLinus Torvalds 		seq_printf(file, "%17s: %2d\n", reset_cause[i],
76170e535edSFelix Fietkau 			   sc->debug.stats.reset[i]);
76270e535edSFelix Fietkau 	}
763f8b815dcSSujith Manoharan 
764631bee25SArend van Spriel 	return 0;
765f8b815dcSSujith Manoharan }
766f8b815dcSSujith Manoharan 
open_file_reset(struct inode * inode,struct file * f)767053f9852SLinus Lüssing static int open_file_reset(struct inode *inode, struct file *f)
768053f9852SLinus Lüssing {
769053f9852SLinus Lüssing 	return single_open(f, read_file_reset, inode->i_private);
770053f9852SLinus Lüssing }
771053f9852SLinus Lüssing 
write_file_reset(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)772053f9852SLinus Lüssing static ssize_t write_file_reset(struct file *file,
773053f9852SLinus Lüssing 				const char __user *user_buf,
774053f9852SLinus Lüssing 				size_t count, loff_t *ppos)
775053f9852SLinus Lüssing {
776053f9852SLinus Lüssing 	struct ath_softc *sc = file_inode(file)->i_private;
777053f9852SLinus Lüssing 	struct ath_hw *ah = sc->sc_ah;
778053f9852SLinus Lüssing 	struct ath_common *common = ath9k_hw_common(ah);
779053f9852SLinus Lüssing 	unsigned long val;
7808b804643SDmitry Antipov 	ssize_t ret;
781053f9852SLinus Lüssing 
7828b804643SDmitry Antipov 	ret = kstrtoul_from_user(user_buf, count, 0, &val);
7838b804643SDmitry Antipov 	if (ret)
7848b804643SDmitry Antipov 		return ret;
785053f9852SLinus Lüssing 
786053f9852SLinus Lüssing 	if (val != 1)
787053f9852SLinus Lüssing 		return -EINVAL;
788053f9852SLinus Lüssing 
789053f9852SLinus Lüssing 	/* avoid rearming hw_reset_work on shutdown */
790053f9852SLinus Lüssing 	mutex_lock(&sc->mutex);
791053f9852SLinus Lüssing 	if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
792053f9852SLinus Lüssing 		mutex_unlock(&sc->mutex);
793053f9852SLinus Lüssing 		return -EBUSY;
794053f9852SLinus Lüssing 	}
795053f9852SLinus Lüssing 
796053f9852SLinus Lüssing 	ath9k_queue_reset(sc, RESET_TYPE_USER);
797053f9852SLinus Lüssing 	mutex_unlock(&sc->mutex);
798053f9852SLinus Lüssing 
799053f9852SLinus Lüssing 	return count;
800053f9852SLinus Lüssing }
801053f9852SLinus Lüssing 
802053f9852SLinus Lüssing static const struct file_operations fops_reset = {
803053f9852SLinus Lüssing 	.read = seq_read,
804053f9852SLinus Lüssing 	.write = write_file_reset,
805053f9852SLinus Lüssing 	.open = open_file_reset,
806053f9852SLinus Lüssing 	.owner = THIS_MODULE,
807053f9852SLinus Lüssing 	.llseek = seq_lseek,
808053f9852SLinus Lüssing 	.release = single_release,
809053f9852SLinus Lüssing };
810053f9852SLinus Lüssing 
ath_debug_stat_tx(struct ath_softc * sc,struct ath_buf * bf,struct ath_tx_status * ts,struct ath_txq * txq,unsigned int flags)811066dae93SFelix Fietkau void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
81255797b1aSFelix Fietkau 		       struct ath_tx_status *ts, struct ath_txq *txq,
81355797b1aSFelix Fietkau 		       unsigned int flags)
814fec247c0SSujith {
8155bec3e5aSFelix Fietkau 	int qnum = txq->axq_qnum;
816066dae93SFelix Fietkau 
81772569b7bSArnd Bergmann 	TX_STAT_INC(sc, qnum, tx_pkts_all);
818066dae93SFelix Fietkau 	sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
81999c15bf5SBen Greear 
820fec247c0SSujith 	if (bf_isampdu(bf)) {
821156369faSFelix Fietkau 		if (flags & ATH_TX_ERROR)
82272569b7bSArnd Bergmann 			TX_STAT_INC(sc, qnum, a_xretries);
823fec247c0SSujith 		else
82472569b7bSArnd Bergmann 			TX_STAT_INC(sc, qnum, a_completed);
825fec247c0SSujith 	} else {
82655797b1aSFelix Fietkau 		if (ts->ts_status & ATH9K_TXERR_XRETRY)
82772569b7bSArnd Bergmann 			TX_STAT_INC(sc, qnum, xretries);
8285a6f78afSFelix Fietkau 		else
82972569b7bSArnd Bergmann 			TX_STAT_INC(sc, qnum, completed);
830fec247c0SSujith 	}
831fec247c0SSujith 
8324d900389SBen Greear 	if (ts->ts_status & ATH9K_TXERR_FILT)
83372569b7bSArnd Bergmann 		TX_STAT_INC(sc, qnum, txerr_filtered);
834db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_FIFO)
83572569b7bSArnd Bergmann 		TX_STAT_INC(sc, qnum, fifo_underrun);
836db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_XTXOP)
83772569b7bSArnd Bergmann 		TX_STAT_INC(sc, qnum, xtxop);
838db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
83972569b7bSArnd Bergmann 		TX_STAT_INC(sc, qnum, timer_exp);
840db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
84172569b7bSArnd Bergmann 		TX_STAT_INC(sc, qnum, desc_cfg_err);
842db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
84372569b7bSArnd Bergmann 		TX_STAT_INC(sc, qnum, data_underrun);
844db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
84572569b7bSArnd Bergmann 		TX_STAT_INC(sc, qnum, delim_underrun);
846fec247c0SSujith }
847fec247c0SSujith 
ath_debug_stat_rx(struct ath_softc * sc,struct ath_rx_status * rs)8488e6f5aa2SFelix Fietkau void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
8491395d3f0SSujith {
850b5a0c86aSOleksij Rempel 	ath9k_cmn_debug_stat_rx(&sc->debug.stats.rxstats, rs);
8511395d3f0SSujith }
8521395d3f0SSujith 
read_file_regidx(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)8539bff0bc4SFelix Fietkau static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
8549bff0bc4SFelix Fietkau 				size_t count, loff_t *ppos)
8559bff0bc4SFelix Fietkau {
8569bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
8579bff0bc4SFelix Fietkau 	char buf[32];
8589bff0bc4SFelix Fietkau 	unsigned int len;
8599bff0bc4SFelix Fietkau 
8602b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
8619bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
8629bff0bc4SFelix Fietkau }
8639bff0bc4SFelix Fietkau 
write_file_regidx(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)8649bff0bc4SFelix Fietkau static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
8659bff0bc4SFelix Fietkau 				 size_t count, loff_t *ppos)
8669bff0bc4SFelix Fietkau {
8679bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
8689bff0bc4SFelix Fietkau 	unsigned long regidx;
8698b804643SDmitry Antipov 	ssize_t ret;
8709bff0bc4SFelix Fietkau 
8718b804643SDmitry Antipov 	ret = kstrtoul_from_user(user_buf, count, 0, &regidx);
8728b804643SDmitry Antipov 	if (ret)
8738b804643SDmitry Antipov 		return ret;
8749bff0bc4SFelix Fietkau 
8759bff0bc4SFelix Fietkau 	sc->debug.regidx = regidx;
8769bff0bc4SFelix Fietkau 	return count;
8779bff0bc4SFelix Fietkau }
8789bff0bc4SFelix Fietkau 
8799bff0bc4SFelix Fietkau static const struct file_operations fops_regidx = {
8809bff0bc4SFelix Fietkau 	.read = read_file_regidx,
8819bff0bc4SFelix Fietkau 	.write = write_file_regidx,
882234e3405SStephen Boyd 	.open = simple_open,
8836038f373SArnd Bergmann 	.owner = THIS_MODULE,
8846038f373SArnd Bergmann 	.llseek = default_llseek,
8859bff0bc4SFelix Fietkau };
8869bff0bc4SFelix Fietkau 
read_file_regval(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)8879bff0bc4SFelix Fietkau static ssize_t read_file_regval(struct file *file, char __user *user_buf,
8889bff0bc4SFelix Fietkau 				size_t count, loff_t *ppos)
8899bff0bc4SFelix Fietkau {
8909bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
8919bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
8929bff0bc4SFelix Fietkau 	char buf[32];
8939bff0bc4SFelix Fietkau 	unsigned int len;
8949bff0bc4SFelix Fietkau 	u32 regval;
8959bff0bc4SFelix Fietkau 
89679d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
8979bff0bc4SFelix Fietkau 	regval = REG_READ_D(ah, sc->debug.regidx);
89879d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
8992b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", regval);
9009bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
9019bff0bc4SFelix Fietkau }
9029bff0bc4SFelix Fietkau 
write_file_regval(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)9039bff0bc4SFelix Fietkau static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
9049bff0bc4SFelix Fietkau 				 size_t count, loff_t *ppos)
9059bff0bc4SFelix Fietkau {
9069bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
9079bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
9089bff0bc4SFelix Fietkau 	unsigned long regval;
9098b804643SDmitry Antipov 	ssize_t ret;
9109bff0bc4SFelix Fietkau 
9118b804643SDmitry Antipov 	ret = kstrtoul_from_user(user_buf, count, 0, &regval);
9128b804643SDmitry Antipov 	if (ret)
9138b804643SDmitry Antipov 		return ret;
9149bff0bc4SFelix Fietkau 
91579d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
9169bff0bc4SFelix Fietkau 	REG_WRITE_D(ah, sc->debug.regidx, regval);
91779d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
9189bff0bc4SFelix Fietkau 	return count;
9199bff0bc4SFelix Fietkau }
9209bff0bc4SFelix Fietkau 
9219bff0bc4SFelix Fietkau static const struct file_operations fops_regval = {
9229bff0bc4SFelix Fietkau 	.read = read_file_regval,
9239bff0bc4SFelix Fietkau 	.write = write_file_regval,
924234e3405SStephen Boyd 	.open = simple_open,
9256038f373SArnd Bergmann 	.owner = THIS_MODULE,
9266038f373SArnd Bergmann 	.llseek = default_llseek,
9279bff0bc4SFelix Fietkau };
9289bff0bc4SFelix Fietkau 
929582d0064SVasanthakumar Thiagarajan #define REGDUMP_LINE_SIZE	20
930582d0064SVasanthakumar Thiagarajan 
open_file_regdump(struct inode * inode,struct file * file)931582d0064SVasanthakumar Thiagarajan static int open_file_regdump(struct inode *inode, struct file *file)
932582d0064SVasanthakumar Thiagarajan {
933582d0064SVasanthakumar Thiagarajan 	struct ath_softc *sc = inode->i_private;
934582d0064SVasanthakumar Thiagarajan 	unsigned int len = 0;
935582d0064SVasanthakumar Thiagarajan 	u8 *buf;
936181c007dSMiaoqing Pan 	int i, j = 0;
937582d0064SVasanthakumar Thiagarajan 	unsigned long num_regs, regdump_len, max_reg_offset;
938eba0f284SColin Ian King 	static const struct reg_hole {
939181c007dSMiaoqing Pan 		u32 start;
940181c007dSMiaoqing Pan 		u32 end;
941181c007dSMiaoqing Pan 	} reg_hole_list[] = {
942181c007dSMiaoqing Pan 		{0x0200, 0x07fc},
943181c007dSMiaoqing Pan 		{0x0c00, 0x0ffc},
944181c007dSMiaoqing Pan 		{0x2000, 0x3ffc},
945181c007dSMiaoqing Pan 		{0x4100, 0x6ffc},
946181c007dSMiaoqing Pan 		{0x705c, 0x7ffc},
947181c007dSMiaoqing Pan 		{0x0000, 0x0000}
948181c007dSMiaoqing Pan 	};
949582d0064SVasanthakumar Thiagarajan 
950181c007dSMiaoqing Pan 	max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x8800 : 0xb500;
951582d0064SVasanthakumar Thiagarajan 	num_regs = max_reg_offset / 4 + 1;
952582d0064SVasanthakumar Thiagarajan 	regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
953582d0064SVasanthakumar Thiagarajan 	buf = vmalloc(regdump_len);
954582d0064SVasanthakumar Thiagarajan 	if (!buf)
955582d0064SVasanthakumar Thiagarajan 		return -ENOMEM;
956582d0064SVasanthakumar Thiagarajan 
957582d0064SVasanthakumar Thiagarajan 	ath9k_ps_wakeup(sc);
958181c007dSMiaoqing Pan 	for (i = 0; i < num_regs; i++) {
959181c007dSMiaoqing Pan 		if (reg_hole_list[j].start == i << 2) {
960181c007dSMiaoqing Pan 			i = reg_hole_list[j].end >> 2;
961181c007dSMiaoqing Pan 			j++;
962181c007dSMiaoqing Pan 			continue;
963181c007dSMiaoqing Pan 		}
964181c007dSMiaoqing Pan 
965582d0064SVasanthakumar Thiagarajan 		len += scnprintf(buf + len, regdump_len - len,
966582d0064SVasanthakumar Thiagarajan 			"0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
967181c007dSMiaoqing Pan 	}
968582d0064SVasanthakumar Thiagarajan 	ath9k_ps_restore(sc);
969582d0064SVasanthakumar Thiagarajan 
970582d0064SVasanthakumar Thiagarajan 	file->private_data = buf;
971582d0064SVasanthakumar Thiagarajan 
972582d0064SVasanthakumar Thiagarajan 	return 0;
973582d0064SVasanthakumar Thiagarajan }
974582d0064SVasanthakumar Thiagarajan 
975582d0064SVasanthakumar Thiagarajan static const struct file_operations fops_regdump = {
976582d0064SVasanthakumar Thiagarajan 	.open = open_file_regdump,
977582d0064SVasanthakumar Thiagarajan 	.read = ath9k_debugfs_read_buf,
978582d0064SVasanthakumar Thiagarajan 	.release = ath9k_debugfs_release_buf,
979582d0064SVasanthakumar Thiagarajan 	.owner = THIS_MODULE,
980582d0064SVasanthakumar Thiagarajan 	.llseek = default_llseek,/* read accesses f_pos */
981582d0064SVasanthakumar Thiagarajan };
982582d0064SVasanthakumar Thiagarajan 
read_file_dump_nfcal(struct seq_file * file,void * data)983631bee25SArend van Spriel static int read_file_dump_nfcal(struct seq_file *file, void *data)
984d069a46bSRajkumar Manoharan {
9854447d815SArend van Spriel 	struct ieee80211_hw *hw = dev_get_drvdata(file->private);
9864447d815SArend van Spriel 	struct ath_softc *sc = hw->priv;
987d069a46bSRajkumar Manoharan 	struct ath_hw *ah = sc->sc_ah;
988b01459e8SFelix Fietkau 	struct ath9k_nfcal_hist *h = sc->cur_chan->caldata.nfCalHist;
989d069a46bSRajkumar Manoharan 	struct ath_common *common = ath9k_hw_common(ah);
990d069a46bSRajkumar Manoharan 	struct ieee80211_conf *conf = &common->hw->conf;
991d069a46bSRajkumar Manoharan 	u32 i, j;
992d069a46bSRajkumar Manoharan 	u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
993d069a46bSRajkumar Manoharan 	u8 nread;
994d069a46bSRajkumar Manoharan 
995631bee25SArend van Spriel 	seq_printf(file, "Channel Noise Floor : %d\n", ah->noise);
996631bee25SArend van Spriel 	seq_puts(file, "Chain | privNF | # Readings | NF Readings\n");
997d069a46bSRajkumar Manoharan 	for (i = 0; i < NUM_NF_READINGS; i++) {
998d069a46bSRajkumar Manoharan 		if (!(chainmask & (1 << i)) ||
999d069a46bSRajkumar Manoharan 		    ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1000d069a46bSRajkumar Manoharan 			continue;
1001d069a46bSRajkumar Manoharan 
1002d069a46bSRajkumar Manoharan 		nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
1003631bee25SArend van Spriel 		seq_printf(file, " %d\t %d\t %d\t\t", i, h[i].privNF, nread);
1004d069a46bSRajkumar Manoharan 		for (j = 0; j < nread; j++)
1005631bee25SArend van Spriel 			seq_printf(file, " %d", h[i].nfCalBuffer[j]);
1006631bee25SArend van Spriel 		seq_puts(file, "\n");
1007d069a46bSRajkumar Manoharan 	}
1008d069a46bSRajkumar Manoharan 
1009631bee25SArend van Spriel 	return 0;
1010631bee25SArend van Spriel }
1011d069a46bSRajkumar Manoharan 
10124df50ca8SRajkumar Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
read_file_btcoex(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)10134df50ca8SRajkumar Manoharan static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
10144df50ca8SRajkumar Manoharan 				size_t count, loff_t *ppos)
10154df50ca8SRajkumar Manoharan {
10164df50ca8SRajkumar Manoharan 	struct ath_softc *sc = file->private_data;
10174df50ca8SRajkumar Manoharan 	u32 len = 0, size = 1500;
10184df50ca8SRajkumar Manoharan 	char *buf;
10194df50ca8SRajkumar Manoharan 	size_t retval;
10204df50ca8SRajkumar Manoharan 
10214df50ca8SRajkumar Manoharan 	buf = kzalloc(size, GFP_KERNEL);
10224df50ca8SRajkumar Manoharan 	if (buf == NULL)
10234df50ca8SRajkumar Manoharan 		return -ENOMEM;
10244df50ca8SRajkumar Manoharan 
1025ac46ba43SSujith Manoharan 	if (!sc->sc_ah->common.btcoex_enabled) {
10265e88ba62SZefir Kurtisi 		len = scnprintf(buf, size, "%s\n",
1027ac46ba43SSujith Manoharan 				"BTCOEX is disabled");
1028ac46ba43SSujith Manoharan 		goto exit;
1029ac46ba43SSujith Manoharan 	}
10304df50ca8SRajkumar Manoharan 
1031ac46ba43SSujith Manoharan 	len = ath9k_dump_btcoex(sc, buf, size);
1032ac46ba43SSujith Manoharan exit:
10334df50ca8SRajkumar Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
10344df50ca8SRajkumar Manoharan 	kfree(buf);
10354df50ca8SRajkumar Manoharan 
10364df50ca8SRajkumar Manoharan 	return retval;
10374df50ca8SRajkumar Manoharan }
10384df50ca8SRajkumar Manoharan 
10394df50ca8SRajkumar Manoharan static const struct file_operations fops_btcoex = {
10404df50ca8SRajkumar Manoharan 	.read = read_file_btcoex,
10414df50ca8SRajkumar Manoharan 	.open = simple_open,
10424df50ca8SRajkumar Manoharan 	.owner = THIS_MODULE,
10434df50ca8SRajkumar Manoharan 	.llseek = default_llseek,
10444df50ca8SRajkumar Manoharan };
10454df50ca8SRajkumar Manoharan #endif
10464df50ca8SRajkumar Manoharan 
10477a90744cSLorenzo Bianconi #ifdef CONFIG_ATH9K_DYNACK
read_file_ackto(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)10487a90744cSLorenzo Bianconi static ssize_t read_file_ackto(struct file *file, char __user *user_buf,
10497a90744cSLorenzo Bianconi 			       size_t count, loff_t *ppos)
10507a90744cSLorenzo Bianconi {
10517a90744cSLorenzo Bianconi 	struct ath_softc *sc = file->private_data;
10527a90744cSLorenzo Bianconi 	struct ath_hw *ah = sc->sc_ah;
10537a90744cSLorenzo Bianconi 	char buf[32];
10547a90744cSLorenzo Bianconi 	unsigned int len;
10557a90744cSLorenzo Bianconi 
10567a90744cSLorenzo Bianconi 	len = sprintf(buf, "%u %c\n", ah->dynack.ackto,
10577a90744cSLorenzo Bianconi 		      (ah->dynack.enabled) ? 'A' : 'S');
10587a90744cSLorenzo Bianconi 
10597a90744cSLorenzo Bianconi 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
10607a90744cSLorenzo Bianconi }
10617a90744cSLorenzo Bianconi 
10627a90744cSLorenzo Bianconi static const struct file_operations fops_ackto = {
10637a90744cSLorenzo Bianconi 	.read = read_file_ackto,
10647a90744cSLorenzo Bianconi 	.open = simple_open,
10657a90744cSLorenzo Bianconi 	.owner = THIS_MODULE,
10667a90744cSLorenzo Bianconi 	.llseek = default_llseek,
10677a90744cSLorenzo Bianconi };
10687a90744cSLorenzo Bianconi #endif
10697a90744cSLorenzo Bianconi 
10708b861715SSujith Manoharan #ifdef CONFIG_ATH9K_WOW
10718b861715SSujith Manoharan 
read_file_wow(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)10728b861715SSujith Manoharan static ssize_t read_file_wow(struct file *file, char __user *user_buf,
10738b861715SSujith Manoharan 			     size_t count, loff_t *ppos)
10748b861715SSujith Manoharan {
10758b861715SSujith Manoharan 	struct ath_softc *sc = file->private_data;
10768b861715SSujith Manoharan 	unsigned int len = 0, size = 32;
10778b861715SSujith Manoharan 	ssize_t retval;
10788b861715SSujith Manoharan 	char *buf;
10798b861715SSujith Manoharan 
10808b861715SSujith Manoharan 	buf = kzalloc(size, GFP_KERNEL);
10818b861715SSujith Manoharan 	if (!buf)
10828b861715SSujith Manoharan 		return -ENOMEM;
10838b861715SSujith Manoharan 
10848b861715SSujith Manoharan 	len += scnprintf(buf + len, size - len, "WOW: %s\n",
10858b861715SSujith Manoharan 			 sc->force_wow ? "ENABLED" : "DISABLED");
10868b861715SSujith Manoharan 
10878b861715SSujith Manoharan 	if (len > size)
10888b861715SSujith Manoharan 		len = size;
10898b861715SSujith Manoharan 
10908b861715SSujith Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
10918b861715SSujith Manoharan 	kfree(buf);
10928b861715SSujith Manoharan 
10938b861715SSujith Manoharan 	return retval;
10948b861715SSujith Manoharan }
10958b861715SSujith Manoharan 
write_file_wow(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)10968b861715SSujith Manoharan static ssize_t write_file_wow(struct file *file, const char __user *user_buf,
10978b861715SSujith Manoharan 			      size_t count, loff_t *ppos)
10988b861715SSujith Manoharan {
10998b861715SSujith Manoharan 	struct ath_softc *sc = file->private_data;
11008b861715SSujith Manoharan 	unsigned long val;
11018b804643SDmitry Antipov 	ssize_t ret;
11028b861715SSujith Manoharan 
11038b804643SDmitry Antipov 	ret = kstrtoul_from_user(user_buf, count, 0, &val);
11048b804643SDmitry Antipov 	if (ret)
11058b804643SDmitry Antipov 		return ret;
11068b861715SSujith Manoharan 
11078b861715SSujith Manoharan 	if (val != 1)
11088b861715SSujith Manoharan 		return -EINVAL;
11098b861715SSujith Manoharan 
11108b861715SSujith Manoharan 	if (!sc->force_wow) {
11118b861715SSujith Manoharan 		sc->force_wow = true;
11128b861715SSujith Manoharan 		ath9k_init_wow(sc->hw);
11138b861715SSujith Manoharan 	}
11148b861715SSujith Manoharan 
11158b861715SSujith Manoharan 	return count;
11168b861715SSujith Manoharan }
11178b861715SSujith Manoharan 
11188b861715SSujith Manoharan static const struct file_operations fops_wow = {
11198b861715SSujith Manoharan 	.read = read_file_wow,
11208b861715SSujith Manoharan 	.write = write_file_wow,
11218b861715SSujith Manoharan 	.open = simple_open,
11228b861715SSujith Manoharan 	.owner = THIS_MODULE,
11238b861715SSujith Manoharan 	.llseek = default_llseek,
11248b861715SSujith Manoharan };
11258b861715SSujith Manoharan 
11268b861715SSujith Manoharan #endif
11278b861715SSujith Manoharan 
read_file_tpc(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)11288718389bSLorenzo Bianconi static ssize_t read_file_tpc(struct file *file, char __user *user_buf,
11298718389bSLorenzo Bianconi 			     size_t count, loff_t *ppos)
11308718389bSLorenzo Bianconi {
11318718389bSLorenzo Bianconi 	struct ath_softc *sc = file->private_data;
11328718389bSLorenzo Bianconi 	struct ath_hw *ah = sc->sc_ah;
11338718389bSLorenzo Bianconi 	unsigned int len = 0, size = 32;
11348718389bSLorenzo Bianconi 	ssize_t retval;
11358718389bSLorenzo Bianconi 	char *buf;
11368718389bSLorenzo Bianconi 
11378718389bSLorenzo Bianconi 	buf = kzalloc(size, GFP_KERNEL);
11388718389bSLorenzo Bianconi 	if (!buf)
11398718389bSLorenzo Bianconi 		return -ENOMEM;
11408718389bSLorenzo Bianconi 
11418718389bSLorenzo Bianconi 	len += scnprintf(buf + len, size - len, "%s\n",
11428718389bSLorenzo Bianconi 			 ah->tpc_enabled ? "ENABLED" : "DISABLED");
11438718389bSLorenzo Bianconi 
11448718389bSLorenzo Bianconi 	if (len > size)
11458718389bSLorenzo Bianconi 		len = size;
11468718389bSLorenzo Bianconi 
11478718389bSLorenzo Bianconi 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
11488718389bSLorenzo Bianconi 	kfree(buf);
11498718389bSLorenzo Bianconi 
11508718389bSLorenzo Bianconi 	return retval;
11518718389bSLorenzo Bianconi }
11528718389bSLorenzo Bianconi 
write_file_tpc(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)11538718389bSLorenzo Bianconi static ssize_t write_file_tpc(struct file *file, const char __user *user_buf,
11548718389bSLorenzo Bianconi 			      size_t count, loff_t *ppos)
11558718389bSLorenzo Bianconi {
11568718389bSLorenzo Bianconi 	struct ath_softc *sc = file->private_data;
11578718389bSLorenzo Bianconi 	struct ath_hw *ah = sc->sc_ah;
11588718389bSLorenzo Bianconi 	unsigned long val;
11598b804643SDmitry Antipov 	ssize_t ret;
11608718389bSLorenzo Bianconi 	bool tpc_enabled;
11618718389bSLorenzo Bianconi 
11628b804643SDmitry Antipov 	ret = kstrtoul_from_user(user_buf, count, 0, &val);
11638b804643SDmitry Antipov 	if (ret)
11648b804643SDmitry Antipov 		return ret;
11658718389bSLorenzo Bianconi 
11669d414949SChristos Gkekas 	if (val > 1)
11678718389bSLorenzo Bianconi 		return -EINVAL;
11688718389bSLorenzo Bianconi 
11698718389bSLorenzo Bianconi 	tpc_enabled = !!val;
11708718389bSLorenzo Bianconi 
11718718389bSLorenzo Bianconi 	if (tpc_enabled != ah->tpc_enabled) {
11728718389bSLorenzo Bianconi 		ah->tpc_enabled = tpc_enabled;
1173283dd119SLorenzo Bianconi 
1174283dd119SLorenzo Bianconi 		mutex_lock(&sc->mutex);
1175283dd119SLorenzo Bianconi 		ath9k_set_txpower(sc, NULL);
1176283dd119SLorenzo Bianconi 		mutex_unlock(&sc->mutex);
11778718389bSLorenzo Bianconi 	}
11788718389bSLorenzo Bianconi 
11798718389bSLorenzo Bianconi 	return count;
11808718389bSLorenzo Bianconi }
11818718389bSLorenzo Bianconi 
11828718389bSLorenzo Bianconi static const struct file_operations fops_tpc = {
11838718389bSLorenzo Bianconi 	.read = read_file_tpc,
11848718389bSLorenzo Bianconi 	.write = write_file_tpc,
11858718389bSLorenzo Bianconi 	.open = simple_open,
11868718389bSLorenzo Bianconi 	.owner = THIS_MODULE,
11878718389bSLorenzo Bianconi 	.llseek = default_llseek,
11888718389bSLorenzo Bianconi };
11898718389bSLorenzo Bianconi 
read_file_nf_override(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)1190b9018975SSimon Wunderlich static ssize_t read_file_nf_override(struct file *file,
1191b9018975SSimon Wunderlich 				     char __user *user_buf,
1192b9018975SSimon Wunderlich 				     size_t count, loff_t *ppos)
1193b9018975SSimon Wunderlich {
1194b9018975SSimon Wunderlich 	struct ath_softc *sc = file->private_data;
1195b9018975SSimon Wunderlich 	struct ath_hw *ah = sc->sc_ah;
1196b9018975SSimon Wunderlich 	char buf[32];
1197b9018975SSimon Wunderlich 	unsigned int len;
1198b9018975SSimon Wunderlich 
1199b9018975SSimon Wunderlich 	if (ah->nf_override == 0)
1200b9018975SSimon Wunderlich 		len = sprintf(buf, "off\n");
1201b9018975SSimon Wunderlich 	else
1202b9018975SSimon Wunderlich 		len = sprintf(buf, "%d\n", ah->nf_override);
1203b9018975SSimon Wunderlich 
1204b9018975SSimon Wunderlich 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1205b9018975SSimon Wunderlich }
1206b9018975SSimon Wunderlich 
write_file_nf_override(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)1207b9018975SSimon Wunderlich static ssize_t write_file_nf_override(struct file *file,
1208b9018975SSimon Wunderlich 				      const char __user *user_buf,
1209b9018975SSimon Wunderlich 				      size_t count, loff_t *ppos)
1210b9018975SSimon Wunderlich {
1211b9018975SSimon Wunderlich 	struct ath_softc *sc = file->private_data;
1212b9018975SSimon Wunderlich 	struct ath_hw *ah = sc->sc_ah;
1213b9018975SSimon Wunderlich 	long val;
1214b9018975SSimon Wunderlich 	char buf[32];
1215b9018975SSimon Wunderlich 	ssize_t len;
1216b9018975SSimon Wunderlich 
1217b9018975SSimon Wunderlich 	len = min(count, sizeof(buf) - 1);
1218b9018975SSimon Wunderlich 	if (copy_from_user(buf, user_buf, len))
1219b9018975SSimon Wunderlich 		return -EFAULT;
1220b9018975SSimon Wunderlich 
1221b9018975SSimon Wunderlich 	buf[len] = '\0';
1222b9018975SSimon Wunderlich 	if (strncmp("off", buf, 3) == 0)
1223b9018975SSimon Wunderlich 		val = 0;
1224b9018975SSimon Wunderlich 	else if (kstrtol(buf, 0, &val))
1225b9018975SSimon Wunderlich 		return -EINVAL;
1226b9018975SSimon Wunderlich 
1227b9018975SSimon Wunderlich 	if (val > 0)
1228b9018975SSimon Wunderlich 		return -EINVAL;
1229b9018975SSimon Wunderlich 
1230b9018975SSimon Wunderlich 	if (val < -120)
1231b9018975SSimon Wunderlich 		return -EINVAL;
1232b9018975SSimon Wunderlich 
1233b9018975SSimon Wunderlich 	ah->nf_override = val;
1234b9018975SSimon Wunderlich 
123512c8f3d1SLinus Lüssing 	if (ah->curchan) {
123612c8f3d1SLinus Lüssing 		ath9k_ps_wakeup(sc);
1237b9018975SSimon Wunderlich 		ath9k_hw_loadnf(ah, ah->curchan);
123812c8f3d1SLinus Lüssing 		ath9k_ps_restore(sc);
123912c8f3d1SLinus Lüssing 	}
1240b9018975SSimon Wunderlich 
1241b9018975SSimon Wunderlich 	return count;
1242b9018975SSimon Wunderlich }
1243b9018975SSimon Wunderlich 
1244b9018975SSimon Wunderlich static const struct file_operations fops_nf_override = {
1245b9018975SSimon Wunderlich 	.read = read_file_nf_override,
1246b9018975SSimon Wunderlich 	.write = write_file_nf_override,
1247b9018975SSimon Wunderlich 	.open = simple_open,
1248b9018975SSimon Wunderlich 	.owner = THIS_MODULE,
1249b9018975SSimon Wunderlich 	.llseek = default_llseek,
1250b9018975SSimon Wunderlich };
1251b9018975SSimon Wunderlich 
1252c175db87SSujith Manoharan /* Ethtool support for get-stats */
1253c175db87SSujith Manoharan 
1254c175db87SSujith Manoharan #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1255c175db87SSujith Manoharan static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1256c175db87SSujith Manoharan 	"tx_pkts_nic",
1257c175db87SSujith Manoharan 	"tx_bytes_nic",
1258c175db87SSujith Manoharan 	"rx_pkts_nic",
1259c175db87SSujith Manoharan 	"rx_bytes_nic",
1260c175db87SSujith Manoharan 	AMKSTR(d_tx_pkts),
1261c175db87SSujith Manoharan 	AMKSTR(d_tx_bytes),
1262c175db87SSujith Manoharan 	AMKSTR(d_tx_mpdus_queued),
1263c175db87SSujith Manoharan 	AMKSTR(d_tx_mpdus_completed),
1264c175db87SSujith Manoharan 	AMKSTR(d_tx_mpdu_xretries),
1265c175db87SSujith Manoharan 	AMKSTR(d_tx_aggregates),
1266c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdus_queued_hw),
1267c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdus_completed),
1268c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdu_retries),
1269c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdu_xretries),
1270c175db87SSujith Manoharan 	AMKSTR(d_tx_fifo_underrun),
1271c175db87SSujith Manoharan 	AMKSTR(d_tx_op_exceeded),
1272c175db87SSujith Manoharan 	AMKSTR(d_tx_timer_expiry),
1273c175db87SSujith Manoharan 	AMKSTR(d_tx_desc_cfg_err),
1274c175db87SSujith Manoharan 	AMKSTR(d_tx_data_underrun),
1275c175db87SSujith Manoharan 	AMKSTR(d_tx_delim_underrun),
127618c45b10SBen Greear 	"d_rx_crc_err",
1277c175db87SSujith Manoharan 	"d_rx_decrypt_crc_err",
1278c175db87SSujith Manoharan 	"d_rx_phy_err",
1279c175db87SSujith Manoharan 	"d_rx_mic_err",
1280c175db87SSujith Manoharan 	"d_rx_pre_delim_crc_err",
1281c175db87SSujith Manoharan 	"d_rx_post_delim_crc_err",
1282c175db87SSujith Manoharan 	"d_rx_decrypt_busy_err",
1283c175db87SSujith Manoharan 
1284c175db87SSujith Manoharan 	"d_rx_phyerr_radar",
1285c175db87SSujith Manoharan 	"d_rx_phyerr_ofdm_timing",
1286c175db87SSujith Manoharan 	"d_rx_phyerr_cck_timing",
1287c175db87SSujith Manoharan 
1288c175db87SSujith Manoharan };
1289c175db87SSujith Manoharan #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1290c175db87SSujith Manoharan 
ath9k_get_et_strings(struct ieee80211_hw * hw,struct ieee80211_vif * vif,u32 sset,u8 * data)1291c175db87SSujith Manoharan void ath9k_get_et_strings(struct ieee80211_hw *hw,
1292c175db87SSujith Manoharan 			  struct ieee80211_vif *vif,
1293c175db87SSujith Manoharan 			  u32 sset, u8 *data)
1294c175db87SSujith Manoharan {
1295c175db87SSujith Manoharan 	if (sset == ETH_SS_STATS)
129695f97fe0SDmitry Antipov 		memcpy(data, ath9k_gstrings_stats,
1297c175db87SSujith Manoharan 		       sizeof(ath9k_gstrings_stats));
1298c175db87SSujith Manoharan }
1299c175db87SSujith Manoharan 
ath9k_get_et_sset_count(struct ieee80211_hw * hw,struct ieee80211_vif * vif,int sset)1300c175db87SSujith Manoharan int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
1301c175db87SSujith Manoharan 			    struct ieee80211_vif *vif, int sset)
1302c175db87SSujith Manoharan {
1303c175db87SSujith Manoharan 	if (sset == ETH_SS_STATS)
1304c175db87SSujith Manoharan 		return ATH9K_SSTATS_LEN;
1305c175db87SSujith Manoharan 	return 0;
1306c175db87SSujith Manoharan }
1307c175db87SSujith Manoharan 
1308c175db87SSujith Manoharan #define AWDATA(elem)							\
1309c175db87SSujith Manoharan 	do {								\
1310c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
1311c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
1312c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
1313c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
1314c175db87SSujith Manoharan 	} while (0)
1315c175db87SSujith Manoharan 
1316c175db87SSujith Manoharan #define AWDATA_RX(elem)						\
1317c175db87SSujith Manoharan 	do {							\
1318c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.rxstats.elem;	\
1319c175db87SSujith Manoharan 	} while (0)
1320c175db87SSujith Manoharan 
ath9k_get_et_stats(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ethtool_stats * stats,u64 * data)1321c175db87SSujith Manoharan void ath9k_get_et_stats(struct ieee80211_hw *hw,
1322c175db87SSujith Manoharan 			struct ieee80211_vif *vif,
1323c175db87SSujith Manoharan 			struct ethtool_stats *stats, u64 *data)
1324c175db87SSujith Manoharan {
1325c175db87SSujith Manoharan 	struct ath_softc *sc = hw->priv;
1326c175db87SSujith Manoharan 	int i = 0;
1327c175db87SSujith Manoharan 
1328*3f66f267SDmitry Kandybka 	data[i++] = ((u64)sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
1329c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
1330c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
1331c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
1332*3f66f267SDmitry Kandybka 	data[i++] = ((u64)sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
1333c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
1334c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
1335c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
1336c175db87SSujith Manoharan 	AWDATA_RX(rx_pkts_all);
1337c175db87SSujith Manoharan 	AWDATA_RX(rx_bytes_all);
1338c175db87SSujith Manoharan 
1339c175db87SSujith Manoharan 	AWDATA(tx_pkts_all);
1340c175db87SSujith Manoharan 	AWDATA(tx_bytes_all);
1341c175db87SSujith Manoharan 	AWDATA(queued);
1342c175db87SSujith Manoharan 	AWDATA(completed);
1343c175db87SSujith Manoharan 	AWDATA(xretries);
1344c175db87SSujith Manoharan 	AWDATA(a_aggr);
1345c175db87SSujith Manoharan 	AWDATA(a_queued_hw);
1346c175db87SSujith Manoharan 	AWDATA(a_completed);
1347c175db87SSujith Manoharan 	AWDATA(a_retries);
1348c175db87SSujith Manoharan 	AWDATA(a_xretries);
1349c175db87SSujith Manoharan 	AWDATA(fifo_underrun);
1350c175db87SSujith Manoharan 	AWDATA(xtxop);
1351c175db87SSujith Manoharan 	AWDATA(timer_exp);
1352c175db87SSujith Manoharan 	AWDATA(desc_cfg_err);
1353c175db87SSujith Manoharan 	AWDATA(data_underrun);
1354c175db87SSujith Manoharan 	AWDATA(delim_underrun);
1355c175db87SSujith Manoharan 
135618c45b10SBen Greear 	AWDATA_RX(crc_err);
1357c175db87SSujith Manoharan 	AWDATA_RX(decrypt_crc_err);
1358c175db87SSujith Manoharan 	AWDATA_RX(phy_err);
1359c175db87SSujith Manoharan 	AWDATA_RX(mic_err);
1360c175db87SSujith Manoharan 	AWDATA_RX(pre_delim_crc_err);
1361c175db87SSujith Manoharan 	AWDATA_RX(post_delim_crc_err);
1362c175db87SSujith Manoharan 	AWDATA_RX(decrypt_busy_err);
1363c175db87SSujith Manoharan 
1364c175db87SSujith Manoharan 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
1365c175db87SSujith Manoharan 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
1366c175db87SSujith Manoharan 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
1367c175db87SSujith Manoharan 
1368c175db87SSujith Manoharan 	WARN_ON(i != ATH9K_SSTATS_LEN);
1369c175db87SSujith Manoharan }
1370c175db87SSujith Manoharan 
ath9k_deinit_debug(struct ath_softc * sc)1371af690092SSujith Manoharan void ath9k_deinit_debug(struct ath_softc *sc)
1372af690092SSujith Manoharan {
137367dc74f1SOleksij Rempel 	ath9k_cmn_spectral_deinit_debug(&sc->spec_priv);
1374af690092SSujith Manoharan }
1375af690092SSujith Manoharan 
ath9k_init_debug(struct ath_hw * ah)13764d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah)
1377203c4805SLuis R. Rodriguez {
1378bc974f4aSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(ah);
1379d6e71dd1SWu Yunchuan 	struct ath_softc *sc = common->priv;
13804d6b228dSLuis R. Rodriguez 
1381eb272441SBen Greear 	sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1382eb272441SBen Greear 						   sc->hw->wiphy->debugfsdir);
1383203c4805SLuis R. Rodriguez 
1384a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
13852ef00c53SJoe Perches 	debugfs_create_file("debug", 0600, sc->debug.debugfs_phy,
1386c70cab1aSFelix Fietkau 			    sc, &fops_debug);
1387a830df07SFelix Fietkau #endif
138829942bc1SZefir Kurtisi 
138929942bc1SZefir Kurtisi 	ath9k_dfs_init_debug(sc);
1390ef6b19e4SSujith Manoharan 	ath9k_tx99_init_debug(sc);
139167dc74f1SOleksij Rempel 	ath9k_cmn_spectral_init_debug(&sc->spec_priv, sc->debug.debugfs_phy);
139229942bc1SZefir Kurtisi 
13934447d815SArend van Spriel 	debugfs_create_devm_seqfile(sc->dev, "dma", sc->debug.debugfs_phy,
13944447d815SArend van Spriel 				    read_file_dma);
13954447d815SArend van Spriel 	debugfs_create_devm_seqfile(sc->dev, "interrupt", sc->debug.debugfs_phy,
13964447d815SArend van Spriel 				    read_file_interrupt);
13974447d815SArend van Spriel 	debugfs_create_devm_seqfile(sc->dev, "xmit", sc->debug.debugfs_phy,
13984447d815SArend van Spriel 				    read_file_xmit);
13994447d815SArend van Spriel 	debugfs_create_devm_seqfile(sc->dev, "queues", sc->debug.debugfs_phy,
14004447d815SArend van Spriel 				    read_file_queues);
14014447d815SArend van Spriel 	debugfs_create_devm_seqfile(sc->dev, "misc", sc->debug.debugfs_phy,
14024447d815SArend van Spriel 				    read_file_misc);
1403053f9852SLinus Lüssing 	debugfs_create_file("reset", 0600, sc->debug.debugfs_phy,
1404053f9852SLinus Lüssing 			    sc, &fops_reset);
140587ea9b0bSOleksij Rempel 
140687ea9b0bSOleksij Rempel 	ath9k_cmn_debug_recv(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
1407e02912cdSOleksij Rempel 	ath9k_cmn_debug_phy_err(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
140887ea9b0bSOleksij Rempel 
14092ef00c53SJoe Perches 	debugfs_create_u8("rx_chainmask", 0400, sc->debug.debugfs_phy,
1410ca6d4a74SFelix Fietkau 			  &ah->rxchainmask);
14112ef00c53SJoe Perches 	debugfs_create_u8("tx_chainmask", 0400, sc->debug.debugfs_phy,
1412ca6d4a74SFelix Fietkau 			  &ah->txchainmask);
14132ef00c53SJoe Perches 	debugfs_create_file("ani", 0600,
14146e4d291eSSujith Manoharan 			    sc->debug.debugfs_phy, sc, &fops_ani);
14152ef00c53SJoe Perches 	debugfs_create_bool("paprd", 0600, sc->debug.debugfs_phy,
141674673db9SFelix Fietkau 			    &sc->sc_ah->config.enable_paprd);
14172ef00c53SJoe Perches 	debugfs_create_file("regidx", 0600, sc->debug.debugfs_phy,
1418c70cab1aSFelix Fietkau 			    sc, &fops_regidx);
14192ef00c53SJoe Perches 	debugfs_create_file("regval", 0600, sc->debug.debugfs_phy,
1420c70cab1aSFelix Fietkau 			    sc, &fops_regval);
14212ef00c53SJoe Perches 	debugfs_create_bool("ignore_extcca", 0600,
1422c70cab1aSFelix Fietkau 			    sc->debug.debugfs_phy,
1423c70cab1aSFelix Fietkau 			    &ah->config.cwm_ignore_extcca);
14242ef00c53SJoe Perches 	debugfs_create_file("regdump", 0400, sc->debug.debugfs_phy, sc,
1425c70cab1aSFelix Fietkau 			    &fops_regdump);
14264447d815SArend van Spriel 	debugfs_create_devm_seqfile(sc->dev, "dump_nfcal",
14274447d815SArend van Spriel 				    sc->debug.debugfs_phy,
14284447d815SArend van Spriel 				    read_file_dump_nfcal);
1429f2c3c952SOleksij Rempel 
143029bf801eSOleksij Rempel 	ath9k_cmn_debug_base_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
1431f2c3c952SOleksij Rempel 	ath9k_cmn_debug_modal_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
1432f2c3c952SOleksij Rempel 
14332ef00c53SJoe Perches 	debugfs_create_u32("gpio_mask", 0600,
1434691680b8SFelix Fietkau 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
14352ef00c53SJoe Perches 	debugfs_create_u32("gpio_val", 0600,
1436691680b8SFelix Fietkau 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
14372ef00c53SJoe Perches 	debugfs_create_file("antenna_diversity", 0400,
14384eba10ccSSujith Manoharan 			    sc->debug.debugfs_phy, sc, &fops_antenna_diversity);
14394df50ca8SRajkumar Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
14402ef00c53SJoe Perches 	debugfs_create_file("bt_ant_diversity", 0600,
144136e8825eSSujith Manoharan 			    sc->debug.debugfs_phy, sc, &fops_bt_ant_diversity);
14422ef00c53SJoe Perches 	debugfs_create_file("btcoex", 0400, sc->debug.debugfs_phy, sc,
14434df50ca8SRajkumar Manoharan 			    &fops_btcoex);
14444df50ca8SRajkumar Manoharan #endif
144589f927afSLuis R. Rodriguez 
14468b861715SSujith Manoharan #ifdef CONFIG_ATH9K_WOW
14472ef00c53SJoe Perches 	debugfs_create_file("wow", 0600, sc->debug.debugfs_phy, sc, &fops_wow);
14488b861715SSujith Manoharan #endif
14498b861715SSujith Manoharan 
14507a90744cSLorenzo Bianconi #ifdef CONFIG_ATH9K_DYNACK
14512ef00c53SJoe Perches 	debugfs_create_file("ack_to", 0400, sc->debug.debugfs_phy,
14527a90744cSLorenzo Bianconi 			    sc, &fops_ackto);
14537a90744cSLorenzo Bianconi #endif
14542ef00c53SJoe Perches 	debugfs_create_file("tpc", 0600, sc->debug.debugfs_phy, sc, &fops_tpc);
14557a90744cSLorenzo Bianconi 
14562ef00c53SJoe Perches 	debugfs_create_file("nf_override", 0600,
1457b9018975SSimon Wunderlich 			    sc->debug.debugfs_phy, sc, &fops_nf_override);
1458b9018975SSimon Wunderlich 
1459203c4805SLuis R. Rodriguez 	return 0;
1460203c4805SLuis R. Rodriguez }
1461