xref: /openbmc/linux/drivers/net/wireless/ath/ath9k/debug.c (revision 2ef00c53049b6a8758d118188992da01d75f3628)
1203c4805SLuis R. Rodriguez /*
25b68138eSSujith Manoharan  * Copyright (c) 2008-2011 Atheros Communications Inc.
3203c4805SLuis R. Rodriguez  *
4203c4805SLuis R. Rodriguez  * Permission to use, copy, modify, and/or distribute this software for any
5203c4805SLuis R. Rodriguez  * purpose with or without fee is hereby granted, provided that the above
6203c4805SLuis R. Rodriguez  * copyright notice and this permission notice appear in all copies.
7203c4805SLuis R. Rodriguez  *
8203c4805SLuis R. Rodriguez  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9203c4805SLuis R. Rodriguez  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10203c4805SLuis R. Rodriguez  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11203c4805SLuis R. Rodriguez  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12203c4805SLuis R. Rodriguez  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13203c4805SLuis R. Rodriguez  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14203c4805SLuis R. Rodriguez  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15203c4805SLuis R. Rodriguez  */
16203c4805SLuis R. Rodriguez 
175a0e3ad6STejun Heo #include <linux/slab.h>
18582d0064SVasanthakumar Thiagarajan #include <linux/vmalloc.h>
19ee40fa06SPaul Gortmaker #include <linux/export.h>
20203c4805SLuis R. Rodriguez #include <asm/unaligned.h>
21203c4805SLuis R. Rodriguez 
22203c4805SLuis R. Rodriguez #include "ath9k.h"
23203c4805SLuis R. Rodriguez 
24475a6e4dSLuis R. Rodriguez #define REG_WRITE_D(_ah, _reg, _val) \
25475a6e4dSLuis R. Rodriguez 	ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg))
26475a6e4dSLuis R. Rodriguez #define REG_READ_D(_ah, _reg) \
27475a6e4dSLuis R. Rodriguez 	ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
28475a6e4dSLuis R. Rodriguez 
296a4d05dcSFelix Fietkau void ath9k_debug_sync_cause(struct ath_softc *sc, u32 sync_cause)
306a4d05dcSFelix Fietkau {
316a4d05dcSFelix Fietkau 	if (sync_cause)
326a4d05dcSFelix Fietkau 		sc->debug.stats.istats.sync_cause_all++;
336a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_RTC_IRQ)
346a4d05dcSFelix Fietkau 		sc->debug.stats.istats.sync_rtc_irq++;
356a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_MAC_IRQ)
366a4d05dcSFelix Fietkau 		sc->debug.stats.istats.sync_mac_irq++;
376a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_EEPROM_ILLEGAL_ACCESS)
386a4d05dcSFelix Fietkau 		sc->debug.stats.istats.eeprom_illegal_access++;
396a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_APB_TIMEOUT)
406a4d05dcSFelix Fietkau 		sc->debug.stats.istats.apb_timeout++;
416a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_PCI_MODE_CONFLICT)
426a4d05dcSFelix Fietkau 		sc->debug.stats.istats.pci_mode_conflict++;
436a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_HOST1_FATAL)
446a4d05dcSFelix Fietkau 		sc->debug.stats.istats.host1_fatal++;
456a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_HOST1_PERR)
466a4d05dcSFelix Fietkau 		sc->debug.stats.istats.host1_perr++;
476a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_TRCV_FIFO_PERR)
486a4d05dcSFelix Fietkau 		sc->debug.stats.istats.trcv_fifo_perr++;
496a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_RADM_CPL_EP)
506a4d05dcSFelix Fietkau 		sc->debug.stats.istats.radm_cpl_ep++;
516a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_RADM_CPL_DLLP_ABORT)
526a4d05dcSFelix Fietkau 		sc->debug.stats.istats.radm_cpl_dllp_abort++;
536a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_RADM_CPL_TLP_ABORT)
546a4d05dcSFelix Fietkau 		sc->debug.stats.istats.radm_cpl_tlp_abort++;
556a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_RADM_CPL_ECRC_ERR)
566a4d05dcSFelix Fietkau 		sc->debug.stats.istats.radm_cpl_ecrc_err++;
576a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT)
586a4d05dcSFelix Fietkau 		sc->debug.stats.istats.radm_cpl_timeout++;
596a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT)
606a4d05dcSFelix Fietkau 		sc->debug.stats.istats.local_timeout++;
616a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_PM_ACCESS)
626a4d05dcSFelix Fietkau 		sc->debug.stats.istats.pm_access++;
636a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_MAC_AWAKE)
646a4d05dcSFelix Fietkau 		sc->debug.stats.istats.mac_awake++;
656a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_MAC_ASLEEP)
666a4d05dcSFelix Fietkau 		sc->debug.stats.istats.mac_asleep++;
676a4d05dcSFelix Fietkau 	if (sync_cause & AR_INTR_SYNC_MAC_SLEEP_ACCESS)
686a4d05dcSFelix Fietkau 		sc->debug.stats.istats.mac_sleep_access++;
696a4d05dcSFelix Fietkau }
70203c4805SLuis R. Rodriguez 
71582d0064SVasanthakumar Thiagarajan static ssize_t ath9k_debugfs_read_buf(struct file *file, char __user *user_buf,
72582d0064SVasanthakumar Thiagarajan 				      size_t count, loff_t *ppos)
73582d0064SVasanthakumar Thiagarajan {
74582d0064SVasanthakumar Thiagarajan 	u8 *buf = file->private_data;
75582d0064SVasanthakumar Thiagarajan 	return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
76582d0064SVasanthakumar Thiagarajan }
77582d0064SVasanthakumar Thiagarajan 
78582d0064SVasanthakumar Thiagarajan static int ath9k_debugfs_release_buf(struct inode *inode, struct file *file)
79582d0064SVasanthakumar Thiagarajan {
80582d0064SVasanthakumar Thiagarajan 	vfree(file->private_data);
81582d0064SVasanthakumar Thiagarajan 	return 0;
82582d0064SVasanthakumar Thiagarajan }
83582d0064SVasanthakumar Thiagarajan 
84a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
85a830df07SFelix Fietkau 
862493928eSJeff Hansen static ssize_t read_file_debug(struct file *file, char __user *user_buf,
872493928eSJeff Hansen 			     size_t count, loff_t *ppos)
882493928eSJeff Hansen {
892493928eSJeff Hansen 	struct ath_softc *sc = file->private_data;
90c46917bbSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
912493928eSJeff Hansen 	char buf[32];
92581f725cSVasanthakumar Thiagarajan 	unsigned int len;
93581f725cSVasanthakumar Thiagarajan 
942b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", common->debug_mask);
952493928eSJeff Hansen 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
962493928eSJeff Hansen }
972493928eSJeff Hansen 
982493928eSJeff Hansen static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
992493928eSJeff Hansen 			     size_t count, loff_t *ppos)
1002493928eSJeff Hansen {
1012493928eSJeff Hansen 	struct ath_softc *sc = file->private_data;
102c46917bbSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1032493928eSJeff Hansen 	unsigned long mask;
1042493928eSJeff Hansen 	char buf[32];
105581f725cSVasanthakumar Thiagarajan 	ssize_t len;
106581f725cSVasanthakumar Thiagarajan 
107581f725cSVasanthakumar Thiagarajan 	len = min(count, sizeof(buf) - 1);
108581f725cSVasanthakumar Thiagarajan 	if (copy_from_user(buf, user_buf, len))
10904236066SDan Carpenter 		return -EFAULT;
110581f725cSVasanthakumar Thiagarajan 
111581f725cSVasanthakumar Thiagarajan 	buf[len] = '\0';
11227d7f477SJingoo Han 	if (kstrtoul(buf, 0, &mask))
113581f725cSVasanthakumar Thiagarajan 		return -EINVAL;
114581f725cSVasanthakumar Thiagarajan 
115c46917bbSLuis R. Rodriguez 	common->debug_mask = mask;
1162493928eSJeff Hansen 	return count;
1172493928eSJeff Hansen }
1182493928eSJeff Hansen 
1192493928eSJeff Hansen static const struct file_operations fops_debug = {
1202493928eSJeff Hansen 	.read = read_file_debug,
1212493928eSJeff Hansen 	.write = write_file_debug,
122234e3405SStephen Boyd 	.open = simple_open,
1236038f373SArnd Bergmann 	.owner = THIS_MODULE,
1246038f373SArnd Bergmann 	.llseek = default_llseek,
1252493928eSJeff Hansen };
1262493928eSJeff Hansen 
127a830df07SFelix Fietkau #endif
128a830df07SFelix Fietkau 
129991a0987SPavel Roskin #define DMA_BUF_LEN 1024
130991a0987SPavel Roskin 
13115340694SFelix Fietkau 
1326e4d291eSSujith Manoharan static ssize_t read_file_ani(struct file *file, char __user *user_buf,
13305c0be2fSMohammed Shafi Shajakhan 			     size_t count, loff_t *ppos)
13405c0be2fSMohammed Shafi Shajakhan {
13505c0be2fSMohammed Shafi Shajakhan 	struct ath_softc *sc = file->private_data;
13605c0be2fSMohammed Shafi Shajakhan 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1376e4d291eSSujith Manoharan 	struct ath_hw *ah = sc->sc_ah;
1382120ac96SJoe Perches 	unsigned int len = 0;
1392120ac96SJoe Perches 	const unsigned int size = 1024;
1406e4d291eSSujith Manoharan 	ssize_t retval = 0;
1416e4d291eSSujith Manoharan 	char *buf;
142abee4c84SFelix Fietkau 	int i;
143abee4c84SFelix Fietkau 	struct {
144abee4c84SFelix Fietkau 		const char *name;
145abee4c84SFelix Fietkau 		unsigned int val;
146abee4c84SFelix Fietkau 	} ani_info[] = {
147abee4c84SFelix Fietkau 		{ "ANI RESET", ah->stats.ast_ani_reset },
148abee4c84SFelix Fietkau 		{ "OFDM LEVEL", ah->ani.ofdmNoiseImmunityLevel },
149abee4c84SFelix Fietkau 		{ "CCK LEVEL", ah->ani.cckNoiseImmunityLevel },
150abee4c84SFelix Fietkau 		{ "SPUR UP", ah->stats.ast_ani_spurup },
151abee4c84SFelix Fietkau 		{ "SPUR DOWN", ah->stats.ast_ani_spurup },
152abee4c84SFelix Fietkau 		{ "OFDM WS-DET ON", ah->stats.ast_ani_ofdmon },
153abee4c84SFelix Fietkau 		{ "OFDM WS-DET OFF", ah->stats.ast_ani_ofdmoff },
154abee4c84SFelix Fietkau 		{ "MRC-CCK ON", ah->stats.ast_ani_ccklow },
155abee4c84SFelix Fietkau 		{ "MRC-CCK OFF", ah->stats.ast_ani_cckhigh },
156abee4c84SFelix Fietkau 		{ "FIR-STEP UP", ah->stats.ast_ani_stepup },
157abee4c84SFelix Fietkau 		{ "FIR-STEP DOWN", ah->stats.ast_ani_stepdown },
158abee4c84SFelix Fietkau 		{ "INV LISTENTIME", ah->stats.ast_ani_lneg_or_lzero },
159abee4c84SFelix Fietkau 		{ "OFDM ERRORS", ah->stats.ast_ani_ofdmerrs },
160abee4c84SFelix Fietkau 		{ "CCK ERRORS", ah->stats.ast_ani_cckerrs },
161abee4c84SFelix Fietkau 	};
16205c0be2fSMohammed Shafi Shajakhan 
1636e4d291eSSujith Manoharan 	buf = kzalloc(size, GFP_KERNEL);
1646e4d291eSSujith Manoharan 	if (buf == NULL)
1656e4d291eSSujith Manoharan 		return -ENOMEM;
1666e4d291eSSujith Manoharan 
167abee4c84SFelix Fietkau 	len += scnprintf(buf + len, size - len, "%15s: %s\n", "ANI",
168abee4c84SFelix Fietkau 			 common->disable_ani ? "DISABLED" : "ENABLED");
16905c0be2fSMohammed Shafi Shajakhan 
170abee4c84SFelix Fietkau 	if (common->disable_ani)
171abee4c84SFelix Fietkau 		goto exit;
172abee4c84SFelix Fietkau 
173abee4c84SFelix Fietkau 	for (i = 0; i < ARRAY_SIZE(ani_info); i++)
1745e88ba62SZefir Kurtisi 		len += scnprintf(buf + len, size - len, "%15s: %u\n",
175abee4c84SFelix Fietkau 				 ani_info[i].name, ani_info[i].val);
176abee4c84SFelix Fietkau 
1776e4d291eSSujith Manoharan exit:
1786e4d291eSSujith Manoharan 	if (len > size)
1796e4d291eSSujith Manoharan 		len = size;
1806e4d291eSSujith Manoharan 
1816e4d291eSSujith Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1826e4d291eSSujith Manoharan 	kfree(buf);
1836e4d291eSSujith Manoharan 
1846e4d291eSSujith Manoharan 	return retval;
1856e4d291eSSujith Manoharan }
1866e4d291eSSujith Manoharan 
1876e4d291eSSujith Manoharan static ssize_t write_file_ani(struct file *file,
18805c0be2fSMohammed Shafi Shajakhan 			      const char __user *user_buf,
18905c0be2fSMohammed Shafi Shajakhan 			      size_t count, loff_t *ppos)
19005c0be2fSMohammed Shafi Shajakhan {
19105c0be2fSMohammed Shafi Shajakhan 	struct ath_softc *sc = file->private_data;
19205c0be2fSMohammed Shafi Shajakhan 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1936e4d291eSSujith Manoharan 	unsigned long ani;
19405c0be2fSMohammed Shafi Shajakhan 	char buf[32];
19505c0be2fSMohammed Shafi Shajakhan 	ssize_t len;
19605c0be2fSMohammed Shafi Shajakhan 
19705c0be2fSMohammed Shafi Shajakhan 	len = min(count, sizeof(buf) - 1);
19805c0be2fSMohammed Shafi Shajakhan 	if (copy_from_user(buf, user_buf, len))
19905c0be2fSMohammed Shafi Shajakhan 		return -EFAULT;
20005c0be2fSMohammed Shafi Shajakhan 
20105c0be2fSMohammed Shafi Shajakhan 	buf[len] = '\0';
2023899ba90SJohn W. Linville 	if (kstrtoul(buf, 0, &ani))
20305c0be2fSMohammed Shafi Shajakhan 		return -EINVAL;
20405c0be2fSMohammed Shafi Shajakhan 
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);
541462e58f2SBen Greear 		PR_IS("WATHDOG", 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,
738325e1881SBen Greear 			   "VIFS: CTX %i(%i) AP: %i STA: %i MESH: %i WDS: %i",
739325e1881SBen Greear 			   i++, (int)(ctx->assigned), iter_data.naps,
740325e1881SBen Greear 			   iter_data.nstations,
7419a9c4fbcSRajkumar Manoharan 			   iter_data.nmeshes, iter_data.nwds);
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 {
7524447d815SArend van Spriel 	struct ieee80211_hw *hw = dev_get_drvdata(file->private);
7534447d815SArend van Spriel 	struct ath_softc *sc = hw->priv;
75470e535edSFelix Fietkau 	static const char * const reset_cause[__RESET_TYPE_MAX] = {
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 
782066dae93SFelix Fietkau void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
78355797b1aSFelix Fietkau 		       struct ath_tx_status *ts, struct ath_txq *txq,
78455797b1aSFelix Fietkau 		       unsigned int flags)
785fec247c0SSujith {
7865bec3e5aSFelix Fietkau 	int qnum = txq->axq_qnum;
787066dae93SFelix Fietkau 
788066dae93SFelix Fietkau 	TX_STAT_INC(qnum, tx_pkts_all);
789066dae93SFelix Fietkau 	sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
79099c15bf5SBen Greear 
791fec247c0SSujith 	if (bf_isampdu(bf)) {
792156369faSFelix Fietkau 		if (flags & ATH_TX_ERROR)
793066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_xretries);
794fec247c0SSujith 		else
795066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_completed);
796fec247c0SSujith 	} else {
79755797b1aSFelix Fietkau 		if (ts->ts_status & ATH9K_TXERR_XRETRY)
7985a6f78afSFelix Fietkau 			TX_STAT_INC(qnum, xretries);
7995a6f78afSFelix Fietkau 		else
800066dae93SFelix Fietkau 			TX_STAT_INC(qnum, completed);
801fec247c0SSujith 	}
802fec247c0SSujith 
8034d900389SBen Greear 	if (ts->ts_status & ATH9K_TXERR_FILT)
8044d900389SBen Greear 		TX_STAT_INC(qnum, txerr_filtered);
805db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_FIFO)
806066dae93SFelix Fietkau 		TX_STAT_INC(qnum, fifo_underrun);
807db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_XTXOP)
808066dae93SFelix Fietkau 		TX_STAT_INC(qnum, xtxop);
809db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
810066dae93SFelix Fietkau 		TX_STAT_INC(qnum, timer_exp);
811db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
812066dae93SFelix Fietkau 		TX_STAT_INC(qnum, desc_cfg_err);
813db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
814066dae93SFelix Fietkau 		TX_STAT_INC(qnum, data_underrun);
815db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
816066dae93SFelix Fietkau 		TX_STAT_INC(qnum, delim_underrun);
817fec247c0SSujith }
818fec247c0SSujith 
8198e6f5aa2SFelix Fietkau void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
8201395d3f0SSujith {
821b5a0c86aSOleksij Rempel 	ath9k_cmn_debug_stat_rx(&sc->debug.stats.rxstats, rs);
8221395d3f0SSujith }
8231395d3f0SSujith 
8249bff0bc4SFelix Fietkau static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
8259bff0bc4SFelix Fietkau 				size_t count, loff_t *ppos)
8269bff0bc4SFelix Fietkau {
8279bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
8289bff0bc4SFelix Fietkau 	char buf[32];
8299bff0bc4SFelix Fietkau 	unsigned int len;
8309bff0bc4SFelix Fietkau 
8312b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
8329bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
8339bff0bc4SFelix Fietkau }
8349bff0bc4SFelix Fietkau 
8359bff0bc4SFelix Fietkau static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
8369bff0bc4SFelix Fietkau 				 size_t count, loff_t *ppos)
8379bff0bc4SFelix Fietkau {
8389bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
8399bff0bc4SFelix Fietkau 	unsigned long regidx;
8409bff0bc4SFelix Fietkau 	char buf[32];
8419bff0bc4SFelix Fietkau 	ssize_t len;
8429bff0bc4SFelix Fietkau 
8439bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
8449bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
84504236066SDan Carpenter 		return -EFAULT;
8469bff0bc4SFelix Fietkau 
8479bff0bc4SFelix Fietkau 	buf[len] = '\0';
84827d7f477SJingoo Han 	if (kstrtoul(buf, 0, &regidx))
8499bff0bc4SFelix Fietkau 		return -EINVAL;
8509bff0bc4SFelix Fietkau 
8519bff0bc4SFelix Fietkau 	sc->debug.regidx = regidx;
8529bff0bc4SFelix Fietkau 	return count;
8539bff0bc4SFelix Fietkau }
8549bff0bc4SFelix Fietkau 
8559bff0bc4SFelix Fietkau static const struct file_operations fops_regidx = {
8569bff0bc4SFelix Fietkau 	.read = read_file_regidx,
8579bff0bc4SFelix Fietkau 	.write = write_file_regidx,
858234e3405SStephen Boyd 	.open = simple_open,
8596038f373SArnd Bergmann 	.owner = THIS_MODULE,
8606038f373SArnd Bergmann 	.llseek = default_llseek,
8619bff0bc4SFelix Fietkau };
8629bff0bc4SFelix Fietkau 
8639bff0bc4SFelix Fietkau static ssize_t read_file_regval(struct file *file, char __user *user_buf,
8649bff0bc4SFelix Fietkau 				size_t count, loff_t *ppos)
8659bff0bc4SFelix Fietkau {
8669bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
8679bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
8689bff0bc4SFelix Fietkau 	char buf[32];
8699bff0bc4SFelix Fietkau 	unsigned int len;
8709bff0bc4SFelix Fietkau 	u32 regval;
8719bff0bc4SFelix Fietkau 
87279d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
8739bff0bc4SFelix Fietkau 	regval = REG_READ_D(ah, sc->debug.regidx);
87479d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
8752b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", regval);
8769bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
8779bff0bc4SFelix Fietkau }
8789bff0bc4SFelix Fietkau 
8799bff0bc4SFelix Fietkau static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
8809bff0bc4SFelix Fietkau 				 size_t count, loff_t *ppos)
8819bff0bc4SFelix Fietkau {
8829bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
8839bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
8849bff0bc4SFelix Fietkau 	unsigned long regval;
8859bff0bc4SFelix Fietkau 	char buf[32];
8869bff0bc4SFelix Fietkau 	ssize_t len;
8879bff0bc4SFelix Fietkau 
8889bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
8899bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
89004236066SDan Carpenter 		return -EFAULT;
8919bff0bc4SFelix Fietkau 
8929bff0bc4SFelix Fietkau 	buf[len] = '\0';
89327d7f477SJingoo Han 	if (kstrtoul(buf, 0, &regval))
8949bff0bc4SFelix Fietkau 		return -EINVAL;
8959bff0bc4SFelix Fietkau 
89679d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
8979bff0bc4SFelix Fietkau 	REG_WRITE_D(ah, sc->debug.regidx, regval);
89879d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
8999bff0bc4SFelix Fietkau 	return count;
9009bff0bc4SFelix Fietkau }
9019bff0bc4SFelix Fietkau 
9029bff0bc4SFelix Fietkau static const struct file_operations fops_regval = {
9039bff0bc4SFelix Fietkau 	.read = read_file_regval,
9049bff0bc4SFelix Fietkau 	.write = write_file_regval,
905234e3405SStephen Boyd 	.open = simple_open,
9066038f373SArnd Bergmann 	.owner = THIS_MODULE,
9076038f373SArnd Bergmann 	.llseek = default_llseek,
9089bff0bc4SFelix Fietkau };
9099bff0bc4SFelix Fietkau 
910582d0064SVasanthakumar Thiagarajan #define REGDUMP_LINE_SIZE	20
911582d0064SVasanthakumar Thiagarajan 
912582d0064SVasanthakumar Thiagarajan static int open_file_regdump(struct inode *inode, struct file *file)
913582d0064SVasanthakumar Thiagarajan {
914582d0064SVasanthakumar Thiagarajan 	struct ath_softc *sc = inode->i_private;
915582d0064SVasanthakumar Thiagarajan 	unsigned int len = 0;
916582d0064SVasanthakumar Thiagarajan 	u8 *buf;
917181c007dSMiaoqing Pan 	int i, j = 0;
918582d0064SVasanthakumar Thiagarajan 	unsigned long num_regs, regdump_len, max_reg_offset;
919eba0f284SColin Ian King 	static const struct reg_hole {
920181c007dSMiaoqing Pan 		u32 start;
921181c007dSMiaoqing Pan 		u32 end;
922181c007dSMiaoqing Pan 	} reg_hole_list[] = {
923181c007dSMiaoqing Pan 		{0x0200, 0x07fc},
924181c007dSMiaoqing Pan 		{0x0c00, 0x0ffc},
925181c007dSMiaoqing Pan 		{0x2000, 0x3ffc},
926181c007dSMiaoqing Pan 		{0x4100, 0x6ffc},
927181c007dSMiaoqing Pan 		{0x705c, 0x7ffc},
928181c007dSMiaoqing Pan 		{0x0000, 0x0000}
929181c007dSMiaoqing Pan 	};
930582d0064SVasanthakumar Thiagarajan 
931181c007dSMiaoqing Pan 	max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x8800 : 0xb500;
932582d0064SVasanthakumar Thiagarajan 	num_regs = max_reg_offset / 4 + 1;
933582d0064SVasanthakumar Thiagarajan 	regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
934582d0064SVasanthakumar Thiagarajan 	buf = vmalloc(regdump_len);
935582d0064SVasanthakumar Thiagarajan 	if (!buf)
936582d0064SVasanthakumar Thiagarajan 		return -ENOMEM;
937582d0064SVasanthakumar Thiagarajan 
938582d0064SVasanthakumar Thiagarajan 	ath9k_ps_wakeup(sc);
939181c007dSMiaoqing Pan 	for (i = 0; i < num_regs; i++) {
940181c007dSMiaoqing Pan 		if (reg_hole_list[j].start == i << 2) {
941181c007dSMiaoqing Pan 			i = reg_hole_list[j].end >> 2;
942181c007dSMiaoqing Pan 			j++;
943181c007dSMiaoqing Pan 			continue;
944181c007dSMiaoqing Pan 		}
945181c007dSMiaoqing Pan 
946582d0064SVasanthakumar Thiagarajan 		len += scnprintf(buf + len, regdump_len - len,
947582d0064SVasanthakumar Thiagarajan 			"0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
948181c007dSMiaoqing Pan 	}
949582d0064SVasanthakumar Thiagarajan 	ath9k_ps_restore(sc);
950582d0064SVasanthakumar Thiagarajan 
951582d0064SVasanthakumar Thiagarajan 	file->private_data = buf;
952582d0064SVasanthakumar Thiagarajan 
953582d0064SVasanthakumar Thiagarajan 	return 0;
954582d0064SVasanthakumar Thiagarajan }
955582d0064SVasanthakumar Thiagarajan 
956582d0064SVasanthakumar Thiagarajan static const struct file_operations fops_regdump = {
957582d0064SVasanthakumar Thiagarajan 	.open = open_file_regdump,
958582d0064SVasanthakumar Thiagarajan 	.read = ath9k_debugfs_read_buf,
959582d0064SVasanthakumar Thiagarajan 	.release = ath9k_debugfs_release_buf,
960582d0064SVasanthakumar Thiagarajan 	.owner = THIS_MODULE,
961582d0064SVasanthakumar Thiagarajan 	.llseek = default_llseek,/* read accesses f_pos */
962582d0064SVasanthakumar Thiagarajan };
963582d0064SVasanthakumar Thiagarajan 
964631bee25SArend van Spriel static int read_file_dump_nfcal(struct seq_file *file, void *data)
965d069a46bSRajkumar Manoharan {
9664447d815SArend van Spriel 	struct ieee80211_hw *hw = dev_get_drvdata(file->private);
9674447d815SArend van Spriel 	struct ath_softc *sc = hw->priv;
968d069a46bSRajkumar Manoharan 	struct ath_hw *ah = sc->sc_ah;
969b01459e8SFelix Fietkau 	struct ath9k_nfcal_hist *h = sc->cur_chan->caldata.nfCalHist;
970d069a46bSRajkumar Manoharan 	struct ath_common *common = ath9k_hw_common(ah);
971d069a46bSRajkumar Manoharan 	struct ieee80211_conf *conf = &common->hw->conf;
972d069a46bSRajkumar Manoharan 	u32 i, j;
973d069a46bSRajkumar Manoharan 	u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
974d069a46bSRajkumar Manoharan 	u8 nread;
975d069a46bSRajkumar Manoharan 
976631bee25SArend van Spriel 	seq_printf(file, "Channel Noise Floor : %d\n", ah->noise);
977631bee25SArend van Spriel 	seq_puts(file, "Chain | privNF | # Readings | NF Readings\n");
978d069a46bSRajkumar Manoharan 	for (i = 0; i < NUM_NF_READINGS; i++) {
979d069a46bSRajkumar Manoharan 		if (!(chainmask & (1 << i)) ||
980d069a46bSRajkumar Manoharan 		    ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
981d069a46bSRajkumar Manoharan 			continue;
982d069a46bSRajkumar Manoharan 
983d069a46bSRajkumar Manoharan 		nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
984631bee25SArend van Spriel 		seq_printf(file, " %d\t %d\t %d\t\t", i, h[i].privNF, nread);
985d069a46bSRajkumar Manoharan 		for (j = 0; j < nread; j++)
986631bee25SArend van Spriel 			seq_printf(file, " %d", h[i].nfCalBuffer[j]);
987631bee25SArend van Spriel 		seq_puts(file, "\n");
988d069a46bSRajkumar Manoharan 	}
989d069a46bSRajkumar Manoharan 
990631bee25SArend van Spriel 	return 0;
991631bee25SArend van Spriel }
992d069a46bSRajkumar Manoharan 
993631bee25SArend van Spriel static int open_file_dump_nfcal(struct inode *inode, struct file *f)
994631bee25SArend van Spriel {
995631bee25SArend van Spriel 	return single_open(f, read_file_dump_nfcal, inode->i_private);
996d069a46bSRajkumar Manoharan }
997d069a46bSRajkumar Manoharan 
998d069a46bSRajkumar Manoharan static const struct file_operations fops_dump_nfcal = {
999631bee25SArend van Spriel 	.read = seq_read,
1000631bee25SArend van Spriel 	.open = open_file_dump_nfcal,
1001d069a46bSRajkumar Manoharan 	.owner = THIS_MODULE,
1002631bee25SArend van Spriel 	.llseek = seq_lseek,
1003631bee25SArend van Spriel 	.release = single_release,
1004d069a46bSRajkumar Manoharan };
1005d069a46bSRajkumar Manoharan 
10064df50ca8SRajkumar Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
10074df50ca8SRajkumar Manoharan static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
10084df50ca8SRajkumar Manoharan 				size_t count, loff_t *ppos)
10094df50ca8SRajkumar Manoharan {
10104df50ca8SRajkumar Manoharan 	struct ath_softc *sc = file->private_data;
10114df50ca8SRajkumar Manoharan 	u32 len = 0, size = 1500;
10124df50ca8SRajkumar Manoharan 	char *buf;
10134df50ca8SRajkumar Manoharan 	size_t retval;
10144df50ca8SRajkumar Manoharan 
10154df50ca8SRajkumar Manoharan 	buf = kzalloc(size, GFP_KERNEL);
10164df50ca8SRajkumar Manoharan 	if (buf == NULL)
10174df50ca8SRajkumar Manoharan 		return -ENOMEM;
10184df50ca8SRajkumar Manoharan 
1019ac46ba43SSujith Manoharan 	if (!sc->sc_ah->common.btcoex_enabled) {
10205e88ba62SZefir Kurtisi 		len = scnprintf(buf, size, "%s\n",
1021ac46ba43SSujith Manoharan 				"BTCOEX is disabled");
1022ac46ba43SSujith Manoharan 		goto exit;
1023ac46ba43SSujith Manoharan 	}
10244df50ca8SRajkumar Manoharan 
1025ac46ba43SSujith Manoharan 	len = ath9k_dump_btcoex(sc, buf, size);
1026ac46ba43SSujith Manoharan exit:
10274df50ca8SRajkumar Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
10284df50ca8SRajkumar Manoharan 	kfree(buf);
10294df50ca8SRajkumar Manoharan 
10304df50ca8SRajkumar Manoharan 	return retval;
10314df50ca8SRajkumar Manoharan }
10324df50ca8SRajkumar Manoharan 
10334df50ca8SRajkumar Manoharan static const struct file_operations fops_btcoex = {
10344df50ca8SRajkumar Manoharan 	.read = read_file_btcoex,
10354df50ca8SRajkumar Manoharan 	.open = simple_open,
10364df50ca8SRajkumar Manoharan 	.owner = THIS_MODULE,
10374df50ca8SRajkumar Manoharan 	.llseek = default_llseek,
10384df50ca8SRajkumar Manoharan };
10394df50ca8SRajkumar Manoharan #endif
10404df50ca8SRajkumar Manoharan 
10417a90744cSLorenzo Bianconi #ifdef CONFIG_ATH9K_DYNACK
10427a90744cSLorenzo Bianconi static ssize_t read_file_ackto(struct file *file, char __user *user_buf,
10437a90744cSLorenzo Bianconi 			       size_t count, loff_t *ppos)
10447a90744cSLorenzo Bianconi {
10457a90744cSLorenzo Bianconi 	struct ath_softc *sc = file->private_data;
10467a90744cSLorenzo Bianconi 	struct ath_hw *ah = sc->sc_ah;
10477a90744cSLorenzo Bianconi 	char buf[32];
10487a90744cSLorenzo Bianconi 	unsigned int len;
10497a90744cSLorenzo Bianconi 
10507a90744cSLorenzo Bianconi 	len = sprintf(buf, "%u %c\n", ah->dynack.ackto,
10517a90744cSLorenzo Bianconi 		      (ah->dynack.enabled) ? 'A' : 'S');
10527a90744cSLorenzo Bianconi 
10537a90744cSLorenzo Bianconi 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
10547a90744cSLorenzo Bianconi }
10557a90744cSLorenzo Bianconi 
10567a90744cSLorenzo Bianconi static const struct file_operations fops_ackto = {
10577a90744cSLorenzo Bianconi 	.read = read_file_ackto,
10587a90744cSLorenzo Bianconi 	.open = simple_open,
10597a90744cSLorenzo Bianconi 	.owner = THIS_MODULE,
10607a90744cSLorenzo Bianconi 	.llseek = default_llseek,
10617a90744cSLorenzo Bianconi };
10627a90744cSLorenzo Bianconi #endif
10637a90744cSLorenzo Bianconi 
10648b861715SSujith Manoharan #ifdef CONFIG_ATH9K_WOW
10658b861715SSujith Manoharan 
10668b861715SSujith Manoharan static ssize_t read_file_wow(struct file *file, char __user *user_buf,
10678b861715SSujith Manoharan 			     size_t count, loff_t *ppos)
10688b861715SSujith Manoharan {
10698b861715SSujith Manoharan 	struct ath_softc *sc = file->private_data;
10708b861715SSujith Manoharan 	unsigned int len = 0, size = 32;
10718b861715SSujith Manoharan 	ssize_t retval;
10728b861715SSujith Manoharan 	char *buf;
10738b861715SSujith Manoharan 
10748b861715SSujith Manoharan 	buf = kzalloc(size, GFP_KERNEL);
10758b861715SSujith Manoharan 	if (!buf)
10768b861715SSujith Manoharan 		return -ENOMEM;
10778b861715SSujith Manoharan 
10788b861715SSujith Manoharan 	len += scnprintf(buf + len, size - len, "WOW: %s\n",
10798b861715SSujith Manoharan 			 sc->force_wow ? "ENABLED" : "DISABLED");
10808b861715SSujith Manoharan 
10818b861715SSujith Manoharan 	if (len > size)
10828b861715SSujith Manoharan 		len = size;
10838b861715SSujith Manoharan 
10848b861715SSujith Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
10858b861715SSujith Manoharan 	kfree(buf);
10868b861715SSujith Manoharan 
10878b861715SSujith Manoharan 	return retval;
10888b861715SSujith Manoharan }
10898b861715SSujith Manoharan 
10908b861715SSujith Manoharan static ssize_t write_file_wow(struct file *file, const char __user *user_buf,
10918b861715SSujith Manoharan 			      size_t count, loff_t *ppos)
10928b861715SSujith Manoharan {
10938b861715SSujith Manoharan 	struct ath_softc *sc = file->private_data;
10948b861715SSujith Manoharan 	unsigned long val;
10958b861715SSujith Manoharan 	char buf[32];
10968b861715SSujith Manoharan 	ssize_t len;
10978b861715SSujith Manoharan 
10988b861715SSujith Manoharan 	len = min(count, sizeof(buf) - 1);
10998b861715SSujith Manoharan 	if (copy_from_user(buf, user_buf, len))
11008b861715SSujith Manoharan 		return -EFAULT;
11018b861715SSujith Manoharan 
11028b861715SSujith Manoharan 	buf[len] = '\0';
11038b861715SSujith Manoharan 	if (kstrtoul(buf, 0, &val))
11048b861715SSujith Manoharan 		return -EINVAL;
11058b861715SSujith Manoharan 
11068b861715SSujith Manoharan 	if (val != 1)
11078b861715SSujith Manoharan 		return -EINVAL;
11088b861715SSujith Manoharan 
11098b861715SSujith Manoharan 	if (!sc->force_wow) {
11108b861715SSujith Manoharan 		sc->force_wow = true;
11118b861715SSujith Manoharan 		ath9k_init_wow(sc->hw);
11128b861715SSujith Manoharan 	}
11138b861715SSujith Manoharan 
11148b861715SSujith Manoharan 	return count;
11158b861715SSujith Manoharan }
11168b861715SSujith Manoharan 
11178b861715SSujith Manoharan static const struct file_operations fops_wow = {
11188b861715SSujith Manoharan 	.read = read_file_wow,
11198b861715SSujith Manoharan 	.write = write_file_wow,
11208b861715SSujith Manoharan 	.open = simple_open,
11218b861715SSujith Manoharan 	.owner = THIS_MODULE,
11228b861715SSujith Manoharan 	.llseek = default_llseek,
11238b861715SSujith Manoharan };
11248b861715SSujith Manoharan 
11258b861715SSujith Manoharan #endif
11268b861715SSujith Manoharan 
11278718389bSLorenzo Bianconi static ssize_t read_file_tpc(struct file *file, char __user *user_buf,
11288718389bSLorenzo Bianconi 			     size_t count, loff_t *ppos)
11298718389bSLorenzo Bianconi {
11308718389bSLorenzo Bianconi 	struct ath_softc *sc = file->private_data;
11318718389bSLorenzo Bianconi 	struct ath_hw *ah = sc->sc_ah;
11328718389bSLorenzo Bianconi 	unsigned int len = 0, size = 32;
11338718389bSLorenzo Bianconi 	ssize_t retval;
11348718389bSLorenzo Bianconi 	char *buf;
11358718389bSLorenzo Bianconi 
11368718389bSLorenzo Bianconi 	buf = kzalloc(size, GFP_KERNEL);
11378718389bSLorenzo Bianconi 	if (!buf)
11388718389bSLorenzo Bianconi 		return -ENOMEM;
11398718389bSLorenzo Bianconi 
11408718389bSLorenzo Bianconi 	len += scnprintf(buf + len, size - len, "%s\n",
11418718389bSLorenzo Bianconi 			 ah->tpc_enabled ? "ENABLED" : "DISABLED");
11428718389bSLorenzo Bianconi 
11438718389bSLorenzo Bianconi 	if (len > size)
11448718389bSLorenzo Bianconi 		len = size;
11458718389bSLorenzo Bianconi 
11468718389bSLorenzo Bianconi 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
11478718389bSLorenzo Bianconi 	kfree(buf);
11488718389bSLorenzo Bianconi 
11498718389bSLorenzo Bianconi 	return retval;
11508718389bSLorenzo Bianconi }
11518718389bSLorenzo Bianconi 
11528718389bSLorenzo Bianconi static ssize_t write_file_tpc(struct file *file, const char __user *user_buf,
11538718389bSLorenzo Bianconi 			      size_t count, loff_t *ppos)
11548718389bSLorenzo Bianconi {
11558718389bSLorenzo Bianconi 	struct ath_softc *sc = file->private_data;
11568718389bSLorenzo Bianconi 	struct ath_hw *ah = sc->sc_ah;
11578718389bSLorenzo Bianconi 	unsigned long val;
11588718389bSLorenzo Bianconi 	char buf[32];
11598718389bSLorenzo Bianconi 	ssize_t len;
11608718389bSLorenzo Bianconi 	bool tpc_enabled;
11618718389bSLorenzo Bianconi 
11628718389bSLorenzo Bianconi 	len = min(count, sizeof(buf) - 1);
11638718389bSLorenzo Bianconi 	if (copy_from_user(buf, user_buf, len))
11648718389bSLorenzo Bianconi 		return -EFAULT;
11658718389bSLorenzo Bianconi 
11668718389bSLorenzo Bianconi 	buf[len] = '\0';
11678718389bSLorenzo Bianconi 	if (kstrtoul(buf, 0, &val))
11688718389bSLorenzo Bianconi 		return -EINVAL;
11698718389bSLorenzo Bianconi 
11709d414949SChristos Gkekas 	if (val > 1)
11718718389bSLorenzo Bianconi 		return -EINVAL;
11728718389bSLorenzo Bianconi 
11738718389bSLorenzo Bianconi 	tpc_enabled = !!val;
11748718389bSLorenzo Bianconi 
11758718389bSLorenzo Bianconi 	if (tpc_enabled != ah->tpc_enabled) {
11768718389bSLorenzo Bianconi 		ah->tpc_enabled = tpc_enabled;
1177283dd119SLorenzo Bianconi 
1178283dd119SLorenzo Bianconi 		mutex_lock(&sc->mutex);
1179283dd119SLorenzo Bianconi 		ath9k_set_txpower(sc, NULL);
1180283dd119SLorenzo Bianconi 		mutex_unlock(&sc->mutex);
11818718389bSLorenzo Bianconi 	}
11828718389bSLorenzo Bianconi 
11838718389bSLorenzo Bianconi 	return count;
11848718389bSLorenzo Bianconi }
11858718389bSLorenzo Bianconi 
11868718389bSLorenzo Bianconi static const struct file_operations fops_tpc = {
11878718389bSLorenzo Bianconi 	.read = read_file_tpc,
11888718389bSLorenzo Bianconi 	.write = write_file_tpc,
11898718389bSLorenzo Bianconi 	.open = simple_open,
11908718389bSLorenzo Bianconi 	.owner = THIS_MODULE,
11918718389bSLorenzo Bianconi 	.llseek = default_llseek,
11928718389bSLorenzo Bianconi };
11938718389bSLorenzo Bianconi 
1194b9018975SSimon Wunderlich static ssize_t read_file_nf_override(struct file *file,
1195b9018975SSimon Wunderlich 				     char __user *user_buf,
1196b9018975SSimon Wunderlich 				     size_t count, loff_t *ppos)
1197b9018975SSimon Wunderlich {
1198b9018975SSimon Wunderlich 	struct ath_softc *sc = file->private_data;
1199b9018975SSimon Wunderlich 	struct ath_hw *ah = sc->sc_ah;
1200b9018975SSimon Wunderlich 	char buf[32];
1201b9018975SSimon Wunderlich 	unsigned int len;
1202b9018975SSimon Wunderlich 
1203b9018975SSimon Wunderlich 	if (ah->nf_override == 0)
1204b9018975SSimon Wunderlich 		len = sprintf(buf, "off\n");
1205b9018975SSimon Wunderlich 	else
1206b9018975SSimon Wunderlich 		len = sprintf(buf, "%d\n", ah->nf_override);
1207b9018975SSimon Wunderlich 
1208b9018975SSimon Wunderlich 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1209b9018975SSimon Wunderlich }
1210b9018975SSimon Wunderlich 
1211b9018975SSimon Wunderlich static ssize_t write_file_nf_override(struct file *file,
1212b9018975SSimon Wunderlich 				      const char __user *user_buf,
1213b9018975SSimon Wunderlich 				      size_t count, loff_t *ppos)
1214b9018975SSimon Wunderlich {
1215b9018975SSimon Wunderlich 	struct ath_softc *sc = file->private_data;
1216b9018975SSimon Wunderlich 	struct ath_hw *ah = sc->sc_ah;
1217b9018975SSimon Wunderlich 	long val;
1218b9018975SSimon Wunderlich 	char buf[32];
1219b9018975SSimon Wunderlich 	ssize_t len;
1220b9018975SSimon Wunderlich 
1221b9018975SSimon Wunderlich 	len = min(count, sizeof(buf) - 1);
1222b9018975SSimon Wunderlich 	if (copy_from_user(buf, user_buf, len))
1223b9018975SSimon Wunderlich 		return -EFAULT;
1224b9018975SSimon Wunderlich 
1225b9018975SSimon Wunderlich 	buf[len] = '\0';
1226b9018975SSimon Wunderlich 	if (strncmp("off", buf, 3) == 0)
1227b9018975SSimon Wunderlich 		val = 0;
1228b9018975SSimon Wunderlich 	else if (kstrtol(buf, 0, &val))
1229b9018975SSimon Wunderlich 		return -EINVAL;
1230b9018975SSimon Wunderlich 
1231b9018975SSimon Wunderlich 	if (val > 0)
1232b9018975SSimon Wunderlich 		return -EINVAL;
1233b9018975SSimon Wunderlich 
1234b9018975SSimon Wunderlich 	if (val < -120)
1235b9018975SSimon Wunderlich 		return -EINVAL;
1236b9018975SSimon Wunderlich 
1237b9018975SSimon Wunderlich 	ah->nf_override = val;
1238b9018975SSimon Wunderlich 
1239b9018975SSimon Wunderlich 	if (ah->curchan)
1240b9018975SSimon Wunderlich 		ath9k_hw_loadnf(ah, ah->curchan);
1241b9018975SSimon Wunderlich 
1242b9018975SSimon Wunderlich 	return count;
1243b9018975SSimon Wunderlich }
1244b9018975SSimon Wunderlich 
1245b9018975SSimon Wunderlich static const struct file_operations fops_nf_override = {
1246b9018975SSimon Wunderlich 	.read = read_file_nf_override,
1247b9018975SSimon Wunderlich 	.write = write_file_nf_override,
1248b9018975SSimon Wunderlich 	.open = simple_open,
1249b9018975SSimon Wunderlich 	.owner = THIS_MODULE,
1250b9018975SSimon Wunderlich 	.llseek = default_llseek,
1251b9018975SSimon Wunderlich };
1252b9018975SSimon Wunderlich 
1253c175db87SSujith Manoharan /* Ethtool support for get-stats */
1254c175db87SSujith Manoharan 
1255c175db87SSujith Manoharan #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1256c175db87SSujith Manoharan static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1257c175db87SSujith Manoharan 	"tx_pkts_nic",
1258c175db87SSujith Manoharan 	"tx_bytes_nic",
1259c175db87SSujith Manoharan 	"rx_pkts_nic",
1260c175db87SSujith Manoharan 	"rx_bytes_nic",
1261c175db87SSujith Manoharan 	AMKSTR(d_tx_pkts),
1262c175db87SSujith Manoharan 	AMKSTR(d_tx_bytes),
1263c175db87SSujith Manoharan 	AMKSTR(d_tx_mpdus_queued),
1264c175db87SSujith Manoharan 	AMKSTR(d_tx_mpdus_completed),
1265c175db87SSujith Manoharan 	AMKSTR(d_tx_mpdu_xretries),
1266c175db87SSujith Manoharan 	AMKSTR(d_tx_aggregates),
1267c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdus_queued_hw),
1268c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdus_completed),
1269c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdu_retries),
1270c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdu_xretries),
1271c175db87SSujith Manoharan 	AMKSTR(d_tx_fifo_underrun),
1272c175db87SSujith Manoharan 	AMKSTR(d_tx_op_exceeded),
1273c175db87SSujith Manoharan 	AMKSTR(d_tx_timer_expiry),
1274c175db87SSujith Manoharan 	AMKSTR(d_tx_desc_cfg_err),
1275c175db87SSujith Manoharan 	AMKSTR(d_tx_data_underrun),
1276c175db87SSujith Manoharan 	AMKSTR(d_tx_delim_underrun),
127718c45b10SBen Greear 	"d_rx_crc_err",
1278c175db87SSujith Manoharan 	"d_rx_decrypt_crc_err",
1279c175db87SSujith Manoharan 	"d_rx_phy_err",
1280c175db87SSujith Manoharan 	"d_rx_mic_err",
1281c175db87SSujith Manoharan 	"d_rx_pre_delim_crc_err",
1282c175db87SSujith Manoharan 	"d_rx_post_delim_crc_err",
1283c175db87SSujith Manoharan 	"d_rx_decrypt_busy_err",
1284c175db87SSujith Manoharan 
1285c175db87SSujith Manoharan 	"d_rx_phyerr_radar",
1286c175db87SSujith Manoharan 	"d_rx_phyerr_ofdm_timing",
1287c175db87SSujith Manoharan 	"d_rx_phyerr_cck_timing",
1288c175db87SSujith Manoharan 
1289c175db87SSujith Manoharan };
1290c175db87SSujith Manoharan #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1291c175db87SSujith Manoharan 
1292c175db87SSujith Manoharan void ath9k_get_et_strings(struct ieee80211_hw *hw,
1293c175db87SSujith Manoharan 			  struct ieee80211_vif *vif,
1294c175db87SSujith Manoharan 			  u32 sset, u8 *data)
1295c175db87SSujith Manoharan {
1296c175db87SSujith Manoharan 	if (sset == ETH_SS_STATS)
1297c175db87SSujith Manoharan 		memcpy(data, *ath9k_gstrings_stats,
1298c175db87SSujith Manoharan 		       sizeof(ath9k_gstrings_stats));
1299c175db87SSujith Manoharan }
1300c175db87SSujith Manoharan 
1301c175db87SSujith Manoharan int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
1302c175db87SSujith Manoharan 			    struct ieee80211_vif *vif, int sset)
1303c175db87SSujith Manoharan {
1304c175db87SSujith Manoharan 	if (sset == ETH_SS_STATS)
1305c175db87SSujith Manoharan 		return ATH9K_SSTATS_LEN;
1306c175db87SSujith Manoharan 	return 0;
1307c175db87SSujith Manoharan }
1308c175db87SSujith Manoharan 
1309c175db87SSujith Manoharan #define AWDATA(elem)							\
1310c175db87SSujith Manoharan 	do {								\
1311c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
1312c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
1313c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
1314c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
1315c175db87SSujith Manoharan 	} while (0)
1316c175db87SSujith Manoharan 
1317c175db87SSujith Manoharan #define AWDATA_RX(elem)						\
1318c175db87SSujith Manoharan 	do {							\
1319c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.rxstats.elem;	\
1320c175db87SSujith Manoharan 	} while (0)
1321c175db87SSujith Manoharan 
1322c175db87SSujith Manoharan void ath9k_get_et_stats(struct ieee80211_hw *hw,
1323c175db87SSujith Manoharan 			struct ieee80211_vif *vif,
1324c175db87SSujith Manoharan 			struct ethtool_stats *stats, u64 *data)
1325c175db87SSujith Manoharan {
1326c175db87SSujith Manoharan 	struct ath_softc *sc = hw->priv;
1327c175db87SSujith Manoharan 	int i = 0;
1328c175db87SSujith Manoharan 
1329c175db87SSujith Manoharan 	data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
1330c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
1331c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
1332c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
1333c175db87SSujith Manoharan 	data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
1334c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
1335c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
1336c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
1337c175db87SSujith Manoharan 	AWDATA_RX(rx_pkts_all);
1338c175db87SSujith Manoharan 	AWDATA_RX(rx_bytes_all);
1339c175db87SSujith Manoharan 
1340c175db87SSujith Manoharan 	AWDATA(tx_pkts_all);
1341c175db87SSujith Manoharan 	AWDATA(tx_bytes_all);
1342c175db87SSujith Manoharan 	AWDATA(queued);
1343c175db87SSujith Manoharan 	AWDATA(completed);
1344c175db87SSujith Manoharan 	AWDATA(xretries);
1345c175db87SSujith Manoharan 	AWDATA(a_aggr);
1346c175db87SSujith Manoharan 	AWDATA(a_queued_hw);
1347c175db87SSujith Manoharan 	AWDATA(a_completed);
1348c175db87SSujith Manoharan 	AWDATA(a_retries);
1349c175db87SSujith Manoharan 	AWDATA(a_xretries);
1350c175db87SSujith Manoharan 	AWDATA(fifo_underrun);
1351c175db87SSujith Manoharan 	AWDATA(xtxop);
1352c175db87SSujith Manoharan 	AWDATA(timer_exp);
1353c175db87SSujith Manoharan 	AWDATA(desc_cfg_err);
1354c175db87SSujith Manoharan 	AWDATA(data_underrun);
1355c175db87SSujith Manoharan 	AWDATA(delim_underrun);
1356c175db87SSujith Manoharan 
135718c45b10SBen Greear 	AWDATA_RX(crc_err);
1358c175db87SSujith Manoharan 	AWDATA_RX(decrypt_crc_err);
1359c175db87SSujith Manoharan 	AWDATA_RX(phy_err);
1360c175db87SSujith Manoharan 	AWDATA_RX(mic_err);
1361c175db87SSujith Manoharan 	AWDATA_RX(pre_delim_crc_err);
1362c175db87SSujith Manoharan 	AWDATA_RX(post_delim_crc_err);
1363c175db87SSujith Manoharan 	AWDATA_RX(decrypt_busy_err);
1364c175db87SSujith Manoharan 
1365c175db87SSujith Manoharan 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
1366c175db87SSujith Manoharan 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
1367c175db87SSujith Manoharan 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
1368c175db87SSujith Manoharan 
1369c175db87SSujith Manoharan 	WARN_ON(i != ATH9K_SSTATS_LEN);
1370c175db87SSujith Manoharan }
1371c175db87SSujith Manoharan 
1372af690092SSujith Manoharan void ath9k_deinit_debug(struct ath_softc *sc)
1373af690092SSujith Manoharan {
137467dc74f1SOleksij Rempel 	ath9k_cmn_spectral_deinit_debug(&sc->spec_priv);
1375af690092SSujith Manoharan }
1376af690092SSujith Manoharan 
13774d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah)
1378203c4805SLuis R. Rodriguez {
1379bc974f4aSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(ah);
1380bc974f4aSLuis R. Rodriguez 	struct ath_softc *sc = (struct ath_softc *) common->priv;
13814d6b228dSLuis R. Rodriguez 
1382eb272441SBen Greear 	sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1383eb272441SBen Greear 						   sc->hw->wiphy->debugfsdir);
1384203c4805SLuis R. Rodriguez 	if (!sc->debug.debugfs_phy)
1385c8a72c00SFelix Fietkau 		return -ENOMEM;
1386203c4805SLuis R. Rodriguez 
1387a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
1388*2ef00c53SJoe Perches 	debugfs_create_file("debug", 0600, sc->debug.debugfs_phy,
1389c70cab1aSFelix Fietkau 			    sc, &fops_debug);
1390a830df07SFelix Fietkau #endif
139129942bc1SZefir Kurtisi 
139229942bc1SZefir Kurtisi 	ath9k_dfs_init_debug(sc);
1393ef6b19e4SSujith Manoharan 	ath9k_tx99_init_debug(sc);
139467dc74f1SOleksij Rempel 	ath9k_cmn_spectral_init_debug(&sc->spec_priv, sc->debug.debugfs_phy);
139529942bc1SZefir Kurtisi 
13964447d815SArend van Spriel 	debugfs_create_devm_seqfile(sc->dev, "dma", sc->debug.debugfs_phy,
13974447d815SArend van Spriel 				    read_file_dma);
13984447d815SArend van Spriel 	debugfs_create_devm_seqfile(sc->dev, "interrupt", sc->debug.debugfs_phy,
13994447d815SArend van Spriel 				    read_file_interrupt);
14004447d815SArend van Spriel 	debugfs_create_devm_seqfile(sc->dev, "xmit", sc->debug.debugfs_phy,
14014447d815SArend van Spriel 				    read_file_xmit);
14024447d815SArend van Spriel 	debugfs_create_devm_seqfile(sc->dev, "queues", sc->debug.debugfs_phy,
14034447d815SArend van Spriel 				    read_file_queues);
14044447d815SArend van Spriel 	debugfs_create_devm_seqfile(sc->dev, "misc", sc->debug.debugfs_phy,
14054447d815SArend van Spriel 				    read_file_misc);
14064447d815SArend van Spriel 	debugfs_create_devm_seqfile(sc->dev, "reset", sc->debug.debugfs_phy,
14074447d815SArend van Spriel 				    read_file_reset);
140887ea9b0bSOleksij Rempel 
140987ea9b0bSOleksij Rempel 	ath9k_cmn_debug_recv(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
1410e02912cdSOleksij Rempel 	ath9k_cmn_debug_phy_err(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
141187ea9b0bSOleksij Rempel 
1412*2ef00c53SJoe Perches 	debugfs_create_u8("rx_chainmask", 0400, sc->debug.debugfs_phy,
1413ca6d4a74SFelix Fietkau 			  &ah->rxchainmask);
1414*2ef00c53SJoe Perches 	debugfs_create_u8("tx_chainmask", 0400, sc->debug.debugfs_phy,
1415ca6d4a74SFelix Fietkau 			  &ah->txchainmask);
1416*2ef00c53SJoe Perches 	debugfs_create_file("ani", 0600,
14176e4d291eSSujith Manoharan 			    sc->debug.debugfs_phy, sc, &fops_ani);
1418*2ef00c53SJoe Perches 	debugfs_create_bool("paprd", 0600, sc->debug.debugfs_phy,
141974673db9SFelix Fietkau 			    &sc->sc_ah->config.enable_paprd);
1420*2ef00c53SJoe Perches 	debugfs_create_file("regidx", 0600, sc->debug.debugfs_phy,
1421c70cab1aSFelix Fietkau 			    sc, &fops_regidx);
1422*2ef00c53SJoe Perches 	debugfs_create_file("regval", 0600, sc->debug.debugfs_phy,
1423c70cab1aSFelix Fietkau 			    sc, &fops_regval);
1424*2ef00c53SJoe Perches 	debugfs_create_bool("ignore_extcca", 0600,
1425c70cab1aSFelix Fietkau 			    sc->debug.debugfs_phy,
1426c70cab1aSFelix Fietkau 			    &ah->config.cwm_ignore_extcca);
1427*2ef00c53SJoe Perches 	debugfs_create_file("regdump", 0400, sc->debug.debugfs_phy, sc,
1428c70cab1aSFelix Fietkau 			    &fops_regdump);
14294447d815SArend van Spriel 	debugfs_create_devm_seqfile(sc->dev, "dump_nfcal",
14304447d815SArend van Spriel 				    sc->debug.debugfs_phy,
14314447d815SArend van Spriel 				    read_file_dump_nfcal);
1432f2c3c952SOleksij Rempel 
143329bf801eSOleksij Rempel 	ath9k_cmn_debug_base_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
1434f2c3c952SOleksij Rempel 	ath9k_cmn_debug_modal_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
1435f2c3c952SOleksij Rempel 
1436*2ef00c53SJoe Perches 	debugfs_create_u32("gpio_mask", 0600,
1437691680b8SFelix Fietkau 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
1438*2ef00c53SJoe Perches 	debugfs_create_u32("gpio_val", 0600,
1439691680b8SFelix Fietkau 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
1440*2ef00c53SJoe Perches 	debugfs_create_file("antenna_diversity", 0400,
14414eba10ccSSujith Manoharan 			    sc->debug.debugfs_phy, sc, &fops_antenna_diversity);
14424df50ca8SRajkumar Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
1443*2ef00c53SJoe Perches 	debugfs_create_file("bt_ant_diversity", 0600,
144436e8825eSSujith Manoharan 			    sc->debug.debugfs_phy, sc, &fops_bt_ant_diversity);
1445*2ef00c53SJoe Perches 	debugfs_create_file("btcoex", 0400, sc->debug.debugfs_phy, sc,
14464df50ca8SRajkumar Manoharan 			    &fops_btcoex);
14474df50ca8SRajkumar Manoharan #endif
144889f927afSLuis R. Rodriguez 
14498b861715SSujith Manoharan #ifdef CONFIG_ATH9K_WOW
1450*2ef00c53SJoe Perches 	debugfs_create_file("wow", 0600, sc->debug.debugfs_phy, sc, &fops_wow);
14518b861715SSujith Manoharan #endif
14528b861715SSujith Manoharan 
14537a90744cSLorenzo Bianconi #ifdef CONFIG_ATH9K_DYNACK
1454*2ef00c53SJoe Perches 	debugfs_create_file("ack_to", 0400, sc->debug.debugfs_phy,
14557a90744cSLorenzo Bianconi 			    sc, &fops_ackto);
14567a90744cSLorenzo Bianconi #endif
1457*2ef00c53SJoe Perches 	debugfs_create_file("tpc", 0600, sc->debug.debugfs_phy, sc, &fops_tpc);
14587a90744cSLorenzo Bianconi 
1459*2ef00c53SJoe Perches 	debugfs_create_u16("airtime_flags", 0600,
146063fefa05SToke Høiland-Jørgensen 			   sc->debug.debugfs_phy, &sc->airtime_flags);
146163fefa05SToke Høiland-Jørgensen 
1462*2ef00c53SJoe Perches 	debugfs_create_file("nf_override", 0600,
1463b9018975SSimon Wunderlich 			    sc->debug.debugfs_phy, sc, &fops_nf_override);
1464b9018975SSimon Wunderlich 
1465203c4805SLuis R. Rodriguez 	return 0;
1466203c4805SLuis R. Rodriguez }
1467