xref: /linux/drivers/net/wireless/ath/ath9k/debug.c (revision e6b5be2be4e30037eb551e0ed09dd97bd00d85d3)
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 {
406f1c488a7SGreg Kroah-Hartman 	struct ath_softc *sc = file->private;
407203c4805SLuis R. Rodriguez 	struct ath_hw *ah = sc->sc_ah;
408203c4805SLuis R. Rodriguez 	u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
409203c4805SLuis R. Rodriguez 	int i, qcuOffset = 0, dcuOffset = 0;
410203c4805SLuis R. Rodriguez 	u32 *qcuBase = &val[0], *dcuBase = &val[4];
411203c4805SLuis R. Rodriguez 
4127cf4a2e7SSujith 	ath9k_ps_wakeup(sc);
4137cf4a2e7SSujith 
414475a6e4dSLuis R. Rodriguez 	REG_WRITE_D(ah, AR_MACMISC,
415203c4805SLuis R. Rodriguez 		  ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
416203c4805SLuis R. Rodriguez 		   (AR_MACMISC_MISC_OBS_BUS_1 <<
417203c4805SLuis R. Rodriguez 		    AR_MACMISC_MISC_OBS_BUS_MSB_S)));
418203c4805SLuis R. Rodriguez 
419631bee25SArend van Spriel 	seq_puts(file, "Raw DMA Debug values:\n");
420203c4805SLuis R. Rodriguez 
421203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
422203c4805SLuis R. Rodriguez 		if (i % 4 == 0)
423631bee25SArend van Spriel 			seq_puts(file, "\n");
424203c4805SLuis R. Rodriguez 
425475a6e4dSLuis R. Rodriguez 		val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
426631bee25SArend van Spriel 		seq_printf(file, "%d: %08x ", i, val[i]);
427203c4805SLuis R. Rodriguez 	}
428203c4805SLuis R. Rodriguez 
429631bee25SArend van Spriel 	seq_puts(file, "\n\n");
430631bee25SArend van Spriel 	seq_puts(file, "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
431203c4805SLuis R. Rodriguez 
432203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
433203c4805SLuis R. Rodriguez 		if (i == 8) {
434203c4805SLuis R. Rodriguez 			qcuOffset = 0;
435203c4805SLuis R. Rodriguez 			qcuBase++;
436203c4805SLuis R. Rodriguez 		}
437203c4805SLuis R. Rodriguez 
438203c4805SLuis R. Rodriguez 		if (i == 6) {
439203c4805SLuis R. Rodriguez 			dcuOffset = 0;
440203c4805SLuis R. Rodriguez 			dcuBase++;
441203c4805SLuis R. Rodriguez 		}
442203c4805SLuis R. Rodriguez 
443631bee25SArend van Spriel 		seq_printf(file, "%2d          %2x      %1x     %2x           %2x\n",
444203c4805SLuis R. Rodriguez 			   i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
445203c4805SLuis R. Rodriguez 			   (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
446a017ff75SDan Carpenter 			   (val[2] & (0x7 << (i * 3))) >> (i * 3),
447203c4805SLuis R. Rodriguez 			   (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
448203c4805SLuis R. Rodriguez 	}
449203c4805SLuis R. Rodriguez 
450631bee25SArend van Spriel 	seq_puts(file, "\n");
451203c4805SLuis R. Rodriguez 
452631bee25SArend van Spriel 	seq_printf(file, "qcu_stitch state:   %2x    qcu_fetch state:        %2x\n",
453203c4805SLuis R. Rodriguez 		   (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
454631bee25SArend van Spriel 	seq_printf(file, "qcu_complete state: %2x    dcu_complete state:     %2x\n",
455203c4805SLuis R. Rodriguez 		   (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
456631bee25SArend van Spriel 	seq_printf(file, "dcu_arb state:      %2x    dcu_fp state:           %2x\n",
457203c4805SLuis R. Rodriguez 		   (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
458631bee25SArend van Spriel 	seq_printf(file, "chan_idle_dur:     %3d    chan_idle_dur_valid:     %1d\n",
459203c4805SLuis R. Rodriguez 		   (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
460631bee25SArend van Spriel 	seq_printf(file, "txfifo_valid_0:      %1d    txfifo_valid_1:          %1d\n",
461203c4805SLuis R. Rodriguez 		   (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
462631bee25SArend van Spriel 	seq_printf(file, "txfifo_dcu_num_0:   %2d    txfifo_dcu_num_1:       %2d\n",
463203c4805SLuis R. Rodriguez 		   (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
464203c4805SLuis R. Rodriguez 
465631bee25SArend van Spriel 	seq_printf(file, "pcu observe: 0x%x\n", REG_READ_D(ah, AR_OBS_BUS_1));
466631bee25SArend van Spriel 	seq_printf(file, "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
467203c4805SLuis R. Rodriguez 
4687cf4a2e7SSujith 	ath9k_ps_restore(sc);
4697cf4a2e7SSujith 
470631bee25SArend van Spriel 	return 0;
471631bee25SArend van Spriel }
4722b87f3aaSDan Carpenter 
473f1c488a7SGreg Kroah-Hartman static int open_file_dma(struct inode *inode, struct file *f)
474f1c488a7SGreg Kroah-Hartman {
475f1c488a7SGreg Kroah-Hartman 	return single_open(f, read_file_dma, inode->i_private);
476203c4805SLuis R. Rodriguez }
477203c4805SLuis R. Rodriguez 
478203c4805SLuis R. Rodriguez static const struct file_operations fops_dma = {
479f1c488a7SGreg Kroah-Hartman 	.open = open_file_dma,
480f1c488a7SGreg Kroah-Hartman 	.read = seq_read,
4816038f373SArnd Bergmann 	.owner = THIS_MODULE,
482f1c488a7SGreg Kroah-Hartman 	.llseek = seq_lseek,
483f1c488a7SGreg Kroah-Hartman 	.release = single_release,
484203c4805SLuis R. Rodriguez };
485203c4805SLuis R. Rodriguez 
486203c4805SLuis R. Rodriguez 
487203c4805SLuis R. Rodriguez void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
488203c4805SLuis R. Rodriguez {
489203c4805SLuis R. Rodriguez 	if (status)
490203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.total++;
491a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
492a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXLP)
493a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxlp++;
494a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXHP)
495a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxhp++;
49608578b8fSLuis R. Rodriguez 		if (status & ATH9K_INT_BB_WATCHDOG)
49708578b8fSLuis R. Rodriguez 			sc->debug.stats.istats.bb_watchdog++;
498a9616f41SLuis R. Rodriguez 	} else {
499203c4805SLuis R. Rodriguez 		if (status & ATH9K_INT_RX)
500203c4805SLuis R. Rodriguez 			sc->debug.stats.istats.rxok++;
501a9616f41SLuis R. Rodriguez 	}
502203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXEOL)
503203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxeol++;
504203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXORN)
505203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxorn++;
506203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TX)
507203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txok++;
508203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TXURN)
509203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txurn++;
510203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXPHY)
511203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxphyerr++;
512203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXKCM)
513203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rx_keycache_miss++;
514203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_SWBA)
515203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.swba++;
516203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BMISS)
517203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bmiss++;
518203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BNR)
519203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bnr++;
520203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CST)
521203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cst++;
522203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_GTT)
523203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.gtt++;
524203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TIM)
525203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.tim++;
526203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CABEND)
527203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cabend++;
528203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIMSYNC)
529203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtimsync++;
530203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIM)
531203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtim++;
5326dde1aabSMohammed Shafi Shajakhan 	if (status & ATH9K_INT_TSFOOR)
5336dde1aabSMohammed Shafi Shajakhan 		sc->debug.stats.istats.tsfoor++;
53497ba515aSSujith Manoharan 	if (status & ATH9K_INT_MCI)
53597ba515aSSujith Manoharan 		sc->debug.stats.istats.mci++;
536c9e6e980SMohammed Shafi Shajakhan 	if (status & ATH9K_INT_GENTIMER)
537c9e6e980SMohammed Shafi Shajakhan 		sc->debug.stats.istats.gen_timer++;
538203c4805SLuis R. Rodriguez }
539203c4805SLuis R. Rodriguez 
540631bee25SArend van Spriel static int read_file_interrupt(struct seq_file *file, void *data)
541203c4805SLuis R. Rodriguez {
542f1c488a7SGreg Kroah-Hartman 	struct ath_softc *sc = file->private;
543462e58f2SBen Greear 
544462e58f2SBen Greear #define PR_IS(a, s)						\
545462e58f2SBen Greear 	do {							\
546631bee25SArend van Spriel 		seq_printf(file, "%21s: %10u\n", a,		\
547462e58f2SBen Greear 			   sc->debug.stats.istats.s);		\
548462e58f2SBen Greear 	} while (0)
549203c4805SLuis R. Rodriguez 
550a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
551462e58f2SBen Greear 		PR_IS("RXLP", rxlp);
552462e58f2SBen Greear 		PR_IS("RXHP", rxhp);
553462e58f2SBen Greear 		PR_IS("WATHDOG", bb_watchdog);
554a9616f41SLuis R. Rodriguez 	} else {
555462e58f2SBen Greear 		PR_IS("RX", rxok);
556a9616f41SLuis R. Rodriguez 	}
557462e58f2SBen Greear 	PR_IS("RXEOL", rxeol);
558462e58f2SBen Greear 	PR_IS("RXORN", rxorn);
559462e58f2SBen Greear 	PR_IS("TX", txok);
560462e58f2SBen Greear 	PR_IS("TXURN", txurn);
561462e58f2SBen Greear 	PR_IS("MIB", mib);
562462e58f2SBen Greear 	PR_IS("RXPHY", rxphyerr);
563462e58f2SBen Greear 	PR_IS("RXKCM", rx_keycache_miss);
564462e58f2SBen Greear 	PR_IS("SWBA", swba);
565462e58f2SBen Greear 	PR_IS("BMISS", bmiss);
566462e58f2SBen Greear 	PR_IS("BNR", bnr);
567462e58f2SBen Greear 	PR_IS("CST", cst);
568462e58f2SBen Greear 	PR_IS("GTT", gtt);
569462e58f2SBen Greear 	PR_IS("TIM", tim);
570462e58f2SBen Greear 	PR_IS("CABEND", cabend);
571462e58f2SBen Greear 	PR_IS("DTIMSYNC", dtimsync);
572462e58f2SBen Greear 	PR_IS("DTIM", dtim);
573462e58f2SBen Greear 	PR_IS("TSFOOR", tsfoor);
57497ba515aSSujith Manoharan 	PR_IS("MCI", mci);
575c9e6e980SMohammed Shafi Shajakhan 	PR_IS("GENTIMER", gen_timer);
576462e58f2SBen Greear 	PR_IS("TOTAL", total);
577203c4805SLuis R. Rodriguez 
578631bee25SArend van Spriel 	seq_puts(file, "SYNC_CAUSE stats:\n");
5796dde1aabSMohammed Shafi Shajakhan 
580462e58f2SBen Greear 	PR_IS("Sync-All", sync_cause_all);
581462e58f2SBen Greear 	PR_IS("RTC-IRQ", sync_rtc_irq);
582462e58f2SBen Greear 	PR_IS("MAC-IRQ", sync_mac_irq);
583462e58f2SBen Greear 	PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
584462e58f2SBen Greear 	PR_IS("APB-Timeout", apb_timeout);
585462e58f2SBen Greear 	PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
586462e58f2SBen Greear 	PR_IS("HOST1-Fatal", host1_fatal);
587462e58f2SBen Greear 	PR_IS("HOST1-Perr", host1_perr);
588462e58f2SBen Greear 	PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
589462e58f2SBen Greear 	PR_IS("RADM-CPL-EP", radm_cpl_ep);
590462e58f2SBen Greear 	PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
591462e58f2SBen Greear 	PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
592462e58f2SBen Greear 	PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
593462e58f2SBen Greear 	PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
594462e58f2SBen Greear 	PR_IS("Local-Bus-Timeout", local_timeout);
595462e58f2SBen Greear 	PR_IS("PM-Access", pm_access);
596462e58f2SBen Greear 	PR_IS("MAC-Awake", mac_awake);
597462e58f2SBen Greear 	PR_IS("MAC-Asleep", mac_asleep);
598462e58f2SBen Greear 	PR_IS("MAC-Sleep-Access", mac_sleep_access);
5992b87f3aaSDan Carpenter 
600631bee25SArend van Spriel 	return 0;
601631bee25SArend van Spriel }
602462e58f2SBen Greear 
603f1c488a7SGreg Kroah-Hartman static int open_file_interrupt(struct inode *inode, struct file *f)
604f1c488a7SGreg Kroah-Hartman {
605f1c488a7SGreg Kroah-Hartman 	return single_open(f, read_file_interrupt, inode->i_private);
606203c4805SLuis R. Rodriguez }
607203c4805SLuis R. Rodriguez 
608203c4805SLuis R. Rodriguez static const struct file_operations fops_interrupt = {
609f1c488a7SGreg Kroah-Hartman 	.read = seq_read,
610f1c488a7SGreg Kroah-Hartman 	.open = open_file_interrupt,
6116038f373SArnd Bergmann 	.owner = THIS_MODULE,
612f1c488a7SGreg Kroah-Hartman 	.llseek = seq_lseek,
613f1c488a7SGreg Kroah-Hartman 	.release = single_release,
614203c4805SLuis R. Rodriguez };
615203c4805SLuis R. Rodriguez 
616631bee25SArend van Spriel static int read_file_xmit(struct seq_file *file, void *data)
617fec247c0SSujith {
618f1c488a7SGreg Kroah-Hartman 	struct ath_softc *sc = file->private;
619fec247c0SSujith 
620631bee25SArend van Spriel 	seq_printf(file, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
621fec247c0SSujith 
622fec247c0SSujith 	PR("MPDUs Queued:    ", queued);
623fec247c0SSujith 	PR("MPDUs Completed: ", completed);
6245a6f78afSFelix Fietkau 	PR("MPDUs XRetried:  ", xretries);
625fec247c0SSujith 	PR("Aggregates:      ", a_aggr);
626bda8addaSBen Greear 	PR("AMPDUs Queued HW:", a_queued_hw);
627bda8addaSBen Greear 	PR("AMPDUs Queued SW:", a_queued_sw);
628fec247c0SSujith 	PR("AMPDUs Completed:", a_completed);
629fec247c0SSujith 	PR("AMPDUs Retried:  ", a_retries);
630fec247c0SSujith 	PR("AMPDUs XRetried: ", a_xretries);
6314d900389SBen Greear 	PR("TXERR Filtered:  ", txerr_filtered);
632fec247c0SSujith 	PR("FIFO Underrun:   ", fifo_underrun);
633fec247c0SSujith 	PR("TXOP Exceeded:   ", xtxop);
634fec247c0SSujith 	PR("TXTIMER Expiry:  ", timer_exp);
635fec247c0SSujith 	PR("DESC CFG Error:  ", desc_cfg_err);
636fec247c0SSujith 	PR("DATA Underrun:   ", data_underrun);
637fec247c0SSujith 	PR("DELIM Underrun:  ", delim_underrun);
63899c15bf5SBen Greear 	PR("TX-Pkts-All:     ", tx_pkts_all);
63999c15bf5SBen Greear 	PR("TX-Bytes-All:    ", tx_bytes_all);
64078ef731cSSujith Manoharan 	PR("HW-put-tx-buf:   ", puttxbuf);
64178ef731cSSujith Manoharan 	PR("HW-tx-start:     ", txstart);
64278ef731cSSujith Manoharan 	PR("HW-tx-proc-desc: ", txprocdesc);
643a5a0bca1SBen Greear 	PR("TX-Failed:       ", txfailed);
644fec247c0SSujith 
645631bee25SArend van Spriel 	return 0;
6467f010c93SBen Greear }
6477f010c93SBen Greear 
648631bee25SArend van Spriel static void print_queue(struct ath_softc *sc, struct ath_txq *txq,
649631bee25SArend van Spriel 			struct seq_file *file)
65018fcf1c6SFelix Fietkau {
65118fcf1c6SFelix Fietkau 	ath_txq_lock(sc, txq);
65218fcf1c6SFelix Fietkau 
653631bee25SArend van Spriel 	seq_printf(file, "%s: %d ", "qnum", txq->axq_qnum);
654631bee25SArend van Spriel 	seq_printf(file, "%s: %2d ", "qdepth", txq->axq_depth);
655631bee25SArend van Spriel 	seq_printf(file, "%s: %2d ", "ampdu-depth", txq->axq_ampdu_depth);
656631bee25SArend van Spriel 	seq_printf(file, "%s: %3d ", "pending", txq->pending_frames);
657631bee25SArend van Spriel 	seq_printf(file, "%s: %d\n", "stopped", txq->stopped);
65818fcf1c6SFelix Fietkau 
65918fcf1c6SFelix Fietkau 	ath_txq_unlock(sc, txq);
66018fcf1c6SFelix Fietkau }
66118fcf1c6SFelix Fietkau 
662631bee25SArend van Spriel static int read_file_queues(struct seq_file *file, void *data)
663c0b74876SSujith Manoharan {
664f1c488a7SGreg Kroah-Hartman 	struct ath_softc *sc = file->private;
665c0b74876SSujith Manoharan 	struct ath_txq *txq;
666c0b74876SSujith Manoharan 	int i;
6672120ac96SJoe Perches 	static const char *qname[4] = {
6682120ac96SJoe Perches 		"VO", "VI", "BE", "BK"
6692120ac96SJoe Perches 	};
670c0b74876SSujith Manoharan 
671c0b74876SSujith Manoharan 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
672c0b74876SSujith Manoharan 		txq = sc->tx.txq_map[i];
673631bee25SArend van Spriel 		seq_printf(file, "(%s):  ", qname[i]);
674631bee25SArend van Spriel 		print_queue(sc, txq, file);
675c0b74876SSujith Manoharan 	}
676c0b74876SSujith Manoharan 
677631bee25SArend van Spriel 	seq_puts(file, "(CAB): ");
678631bee25SArend van Spriel 	print_queue(sc, sc->beacon.cabq, file);
67918fcf1c6SFelix Fietkau 
680631bee25SArend van Spriel 	return 0;
681c0b74876SSujith Manoharan }
682c0b74876SSujith Manoharan 
683631bee25SArend van Spriel static int read_file_misc(struct seq_file *file, void *data)
68455f6d0ffSBen Greear {
685f1c488a7SGreg Kroah-Hartman 	struct ath_softc *sc = file->private;
68655f6d0ffSBen Greear 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
6876bcf6f64SSujith Manoharan 	struct ath9k_vif_iter_data iter_data;
6889a9c4fbcSRajkumar Manoharan 	struct ath_chanctx *ctx;
68955f6d0ffSBen Greear 	unsigned int reg;
6909a9c4fbcSRajkumar Manoharan 	u32 rxfilter, i;
6916bcf6f64SSujith Manoharan 
692631bee25SArend van Spriel 	seq_printf(file, "BSSID: %pM\n", common->curbssid);
693631bee25SArend van Spriel 	seq_printf(file, "BSSID-MASK: %pM\n", common->bssidmask);
694631bee25SArend van Spriel 	seq_printf(file, "OPMODE: %s\n",
6955e88ba62SZefir Kurtisi 		   ath_opmode_to_string(sc->sc_ah->opmode));
6966bcf6f64SSujith Manoharan 
6976bcf6f64SSujith Manoharan 	ath9k_ps_wakeup(sc);
6986bcf6f64SSujith Manoharan 	rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
6996bcf6f64SSujith Manoharan 	ath9k_ps_restore(sc);
7006bcf6f64SSujith Manoharan 
701631bee25SArend van Spriel 	seq_printf(file, "RXFILTER: 0x%x", rxfilter);
7026bcf6f64SSujith Manoharan 
7036bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_UCAST)
704631bee25SArend van Spriel 		seq_puts(file, " UCAST");
7056bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MCAST)
706631bee25SArend van Spriel 		seq_puts(file, " MCAST");
7076bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_BCAST)
708631bee25SArend van Spriel 		seq_puts(file, " BCAST");
7096bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_CONTROL)
710631bee25SArend van Spriel 		seq_puts(file, " CONTROL");
7116bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_BEACON)
712631bee25SArend van Spriel 		seq_puts(file, " BEACON");
7136bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PROM)
714631bee25SArend van Spriel 		seq_puts(file, " PROM");
7156bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
716631bee25SArend van Spriel 		seq_puts(file, " PROBEREQ");
7176bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PHYERR)
718631bee25SArend van Spriel 		seq_puts(file, " PHYERR");
7196bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
720631bee25SArend van Spriel 		seq_puts(file, " MYBEACON");
7216bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
722631bee25SArend van Spriel 		seq_puts(file, " COMP_BAR");
7236bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
724631bee25SArend van Spriel 		seq_puts(file, " PSPOLL");
7256bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
726631bee25SArend van Spriel 		seq_puts(file, " PHYRADAR");
7276bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
728631bee25SArend van Spriel 		seq_puts(file, " MCAST_BCAST_ALL");
7296bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
730631bee25SArend van Spriel 		seq_puts(file, " CONTROL_WRAPPER");
7316bcf6f64SSujith Manoharan 
732631bee25SArend van Spriel 	seq_puts(file, "\n");
7336bcf6f64SSujith Manoharan 
7346bcf6f64SSujith Manoharan 	reg = sc->sc_ah->imask;
7356bcf6f64SSujith Manoharan 
736631bee25SArend van Spriel 	seq_printf(file, "INTERRUPT-MASK: 0x%x", reg);
7376bcf6f64SSujith Manoharan 
7386bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_SWBA)
739631bee25SArend van Spriel 		seq_puts(file, " SWBA");
7406bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_BMISS)
741631bee25SArend van Spriel 		seq_puts(file, " BMISS");
7426bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_CST)
743631bee25SArend van Spriel 		seq_puts(file, " CST");
7446bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RX)
745631bee25SArend van Spriel 		seq_puts(file, " RX");
7466bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RXHP)
747631bee25SArend van Spriel 		seq_puts(file, " RXHP");
7486bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RXLP)
749631bee25SArend van Spriel 		seq_puts(file, " RXLP");
7506bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_BB_WATCHDOG)
751631bee25SArend van Spriel 		seq_puts(file, " BB_WATCHDOG");
7526bcf6f64SSujith Manoharan 
753631bee25SArend van Spriel 	seq_puts(file, "\n");
75455f6d0ffSBen Greear 
7559a9c4fbcSRajkumar Manoharan 	i = 0;
7569a9c4fbcSRajkumar Manoharan 	ath_for_each_chanctx(sc, ctx) {
757325e1881SBen Greear 		if (list_empty(&ctx->vifs))
7589a9c4fbcSRajkumar Manoharan 			continue;
7599a9c4fbcSRajkumar Manoharan 		ath9k_calculate_iter_data(sc, ctx, &iter_data);
76055f6d0ffSBen Greear 
761631bee25SArend van Spriel 		seq_printf(file,
762325e1881SBen Greear 			   "VIFS: CTX %i(%i) AP: %i STA: %i MESH: %i WDS: %i",
763325e1881SBen Greear 			   i++, (int)(ctx->assigned), iter_data.naps,
764325e1881SBen Greear 			   iter_data.nstations,
7659a9c4fbcSRajkumar Manoharan 			   iter_data.nmeshes, iter_data.nwds);
766631bee25SArend van Spriel 		seq_printf(file, " ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n",
767631bee25SArend van Spriel 			   iter_data.nadhocs, sc->cur_chan->nvifs,
768631bee25SArend van Spriel 			   sc->nbcnvifs);
7699a9c4fbcSRajkumar Manoharan 	}
77055f6d0ffSBen Greear 
771631bee25SArend van Spriel 	return 0;
77255f6d0ffSBen Greear }
77355f6d0ffSBen Greear 
774631bee25SArend van Spriel static int read_file_reset(struct seq_file *file, void *data)
775f8b815dcSSujith Manoharan {
776f1c488a7SGreg Kroah-Hartman 	struct ath_softc *sc = file->private;
77770e535edSFelix Fietkau 	static const char * const reset_cause[__RESET_TYPE_MAX] = {
77870e535edSFelix Fietkau 		[RESET_TYPE_BB_HANG] = "Baseband Hang",
77970e535edSFelix Fietkau 		[RESET_TYPE_BB_WATCHDOG] = "Baseband Watchdog",
78070e535edSFelix Fietkau 		[RESET_TYPE_FATAL_INT] = "Fatal HW Error",
78170e535edSFelix Fietkau 		[RESET_TYPE_TX_ERROR] = "TX HW error",
78270e535edSFelix Fietkau 		[RESET_TYPE_TX_GTT] = "Transmit timeout",
78370e535edSFelix Fietkau 		[RESET_TYPE_TX_HANG] = "TX Path Hang",
78470e535edSFelix Fietkau 		[RESET_TYPE_PLL_HANG] = "PLL RX Hang",
78570e535edSFelix Fietkau 		[RESET_TYPE_MAC_HANG] = "MAC Hang",
78670e535edSFelix Fietkau 		[RESET_TYPE_BEACON_STUCK] = "Stuck Beacon",
78770e535edSFelix Fietkau 		[RESET_TYPE_MCI] = "MCI Reset",
7887b8aaeadSFelix Fietkau 		[RESET_TYPE_CALIBRATION] = "Calibration error",
78970e535edSFelix Fietkau 	};
79070e535edSFelix Fietkau 	int i;
79170e535edSFelix Fietkau 
79270e535edSFelix Fietkau 	for (i = 0; i < ARRAY_SIZE(reset_cause); i++) {
79370e535edSFelix Fietkau 		if (!reset_cause[i])
79470e535edSFelix Fietkau 		    continue;
795f8b815dcSSujith Manoharan 
796*e6b5be2bSLinus Torvalds 		seq_printf(file, "%17s: %2d\n", reset_cause[i],
79770e535edSFelix Fietkau 			   sc->debug.stats.reset[i]);
79870e535edSFelix Fietkau 	}
799f8b815dcSSujith Manoharan 
800631bee25SArend van Spriel 	return 0;
801f8b815dcSSujith Manoharan }
802f8b815dcSSujith Manoharan 
803066dae93SFelix Fietkau void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
80455797b1aSFelix Fietkau 		       struct ath_tx_status *ts, struct ath_txq *txq,
80555797b1aSFelix Fietkau 		       unsigned int flags)
806fec247c0SSujith {
8075bec3e5aSFelix Fietkau 	int qnum = txq->axq_qnum;
808066dae93SFelix Fietkau 
809066dae93SFelix Fietkau 	TX_STAT_INC(qnum, tx_pkts_all);
810066dae93SFelix Fietkau 	sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
81199c15bf5SBen Greear 
812fec247c0SSujith 	if (bf_isampdu(bf)) {
813156369faSFelix Fietkau 		if (flags & ATH_TX_ERROR)
814066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_xretries);
815fec247c0SSujith 		else
816066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_completed);
817fec247c0SSujith 	} else {
81855797b1aSFelix Fietkau 		if (ts->ts_status & ATH9K_TXERR_XRETRY)
8195a6f78afSFelix Fietkau 			TX_STAT_INC(qnum, xretries);
8205a6f78afSFelix Fietkau 		else
821066dae93SFelix Fietkau 			TX_STAT_INC(qnum, completed);
822fec247c0SSujith 	}
823fec247c0SSujith 
8244d900389SBen Greear 	if (ts->ts_status & ATH9K_TXERR_FILT)
8254d900389SBen Greear 		TX_STAT_INC(qnum, txerr_filtered);
826db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_FIFO)
827066dae93SFelix Fietkau 		TX_STAT_INC(qnum, fifo_underrun);
828db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_XTXOP)
829066dae93SFelix Fietkau 		TX_STAT_INC(qnum, xtxop);
830db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
831066dae93SFelix Fietkau 		TX_STAT_INC(qnum, timer_exp);
832db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
833066dae93SFelix Fietkau 		TX_STAT_INC(qnum, desc_cfg_err);
834db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
835066dae93SFelix Fietkau 		TX_STAT_INC(qnum, data_underrun);
836db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
837066dae93SFelix Fietkau 		TX_STAT_INC(qnum, delim_underrun);
838fec247c0SSujith }
839fec247c0SSujith 
840f1c488a7SGreg Kroah-Hartman static int open_file_xmit(struct inode *inode, struct file *f)
841f1c488a7SGreg Kroah-Hartman {
842f1c488a7SGreg Kroah-Hartman 	return single_open(f, read_file_xmit, inode->i_private);
843f1c488a7SGreg Kroah-Hartman }
844f1c488a7SGreg Kroah-Hartman 
845fec247c0SSujith static const struct file_operations fops_xmit = {
846f1c488a7SGreg Kroah-Hartman 	.read = seq_read,
847f1c488a7SGreg Kroah-Hartman 	.open = open_file_xmit,
8486038f373SArnd Bergmann 	.owner = THIS_MODULE,
849f1c488a7SGreg Kroah-Hartman 	.llseek = seq_lseek,
850f1c488a7SGreg Kroah-Hartman 	.release = single_release,
851fec247c0SSujith };
852203c4805SLuis R. Rodriguez 
853f1c488a7SGreg Kroah-Hartman static int open_file_queues(struct inode *inode, struct file *f)
854f1c488a7SGreg Kroah-Hartman {
855f1c488a7SGreg Kroah-Hartman 	return single_open(f, read_file_queues, inode->i_private);
856f1c488a7SGreg Kroah-Hartman }
857f1c488a7SGreg Kroah-Hartman 
858c0b74876SSujith Manoharan static const struct file_operations fops_queues = {
859f1c488a7SGreg Kroah-Hartman 	.read = seq_read,
860f1c488a7SGreg Kroah-Hartman 	.open = open_file_queues,
861c0b74876SSujith Manoharan 	.owner = THIS_MODULE,
862f1c488a7SGreg Kroah-Hartman 	.llseek = seq_lseek,
863f1c488a7SGreg Kroah-Hartman 	.release = single_release,
864c0b74876SSujith Manoharan };
865c0b74876SSujith Manoharan 
866f1c488a7SGreg Kroah-Hartman static int open_file_misc(struct inode *inode, struct file *f)
867f1c488a7SGreg Kroah-Hartman {
868f1c488a7SGreg Kroah-Hartman 	return single_open(f, read_file_misc, inode->i_private);
869f1c488a7SGreg Kroah-Hartman }
870f1c488a7SGreg Kroah-Hartman 
87155f6d0ffSBen Greear static const struct file_operations fops_misc = {
872f1c488a7SGreg Kroah-Hartman 	.read = seq_read,
873f1c488a7SGreg Kroah-Hartman 	.open = open_file_misc,
87455f6d0ffSBen Greear 	.owner = THIS_MODULE,
875f1c488a7SGreg Kroah-Hartman 	.llseek = seq_lseek,
876f1c488a7SGreg Kroah-Hartman 	.release = single_release,
87755f6d0ffSBen Greear };
87855f6d0ffSBen Greear 
879f1c488a7SGreg Kroah-Hartman static int open_file_reset(struct inode *inode, struct file *f)
880f1c488a7SGreg Kroah-Hartman {
881f1c488a7SGreg Kroah-Hartman 	return single_open(f, read_file_reset, inode->i_private);
882f1c488a7SGreg Kroah-Hartman }
883f1c488a7SGreg Kroah-Hartman 
884f8b815dcSSujith Manoharan static const struct file_operations fops_reset = {
885f1c488a7SGreg Kroah-Hartman 	.read = seq_read,
886f1c488a7SGreg Kroah-Hartman 	.open = open_file_reset,
887f8b815dcSSujith Manoharan 	.owner = THIS_MODULE,
888f1c488a7SGreg Kroah-Hartman 	.llseek = seq_lseek,
889f1c488a7SGreg Kroah-Hartman 	.release = single_release,
890f8b815dcSSujith Manoharan };
891f8b815dcSSujith Manoharan 
8928e6f5aa2SFelix Fietkau void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
8931395d3f0SSujith {
894b5a0c86aSOleksij Rempel 	ath9k_cmn_debug_stat_rx(&sc->debug.stats.rxstats, rs);
8951395d3f0SSujith }
8961395d3f0SSujith 
8979bff0bc4SFelix Fietkau static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
8989bff0bc4SFelix Fietkau 				size_t count, loff_t *ppos)
8999bff0bc4SFelix Fietkau {
9009bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
9019bff0bc4SFelix Fietkau 	char buf[32];
9029bff0bc4SFelix Fietkau 	unsigned int len;
9039bff0bc4SFelix Fietkau 
9042b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
9059bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
9069bff0bc4SFelix Fietkau }
9079bff0bc4SFelix Fietkau 
9089bff0bc4SFelix Fietkau static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
9099bff0bc4SFelix Fietkau 				 size_t count, loff_t *ppos)
9109bff0bc4SFelix Fietkau {
9119bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
9129bff0bc4SFelix Fietkau 	unsigned long regidx;
9139bff0bc4SFelix Fietkau 	char buf[32];
9149bff0bc4SFelix Fietkau 	ssize_t len;
9159bff0bc4SFelix Fietkau 
9169bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
9179bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
91804236066SDan Carpenter 		return -EFAULT;
9199bff0bc4SFelix Fietkau 
9209bff0bc4SFelix Fietkau 	buf[len] = '\0';
92127d7f477SJingoo Han 	if (kstrtoul(buf, 0, &regidx))
9229bff0bc4SFelix Fietkau 		return -EINVAL;
9239bff0bc4SFelix Fietkau 
9249bff0bc4SFelix Fietkau 	sc->debug.regidx = regidx;
9259bff0bc4SFelix Fietkau 	return count;
9269bff0bc4SFelix Fietkau }
9279bff0bc4SFelix Fietkau 
9289bff0bc4SFelix Fietkau static const struct file_operations fops_regidx = {
9299bff0bc4SFelix Fietkau 	.read = read_file_regidx,
9309bff0bc4SFelix Fietkau 	.write = write_file_regidx,
931234e3405SStephen Boyd 	.open = simple_open,
9326038f373SArnd Bergmann 	.owner = THIS_MODULE,
9336038f373SArnd Bergmann 	.llseek = default_llseek,
9349bff0bc4SFelix Fietkau };
9359bff0bc4SFelix Fietkau 
9369bff0bc4SFelix Fietkau static ssize_t read_file_regval(struct file *file, char __user *user_buf,
9379bff0bc4SFelix Fietkau 				size_t count, loff_t *ppos)
9389bff0bc4SFelix Fietkau {
9399bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
9409bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
9419bff0bc4SFelix Fietkau 	char buf[32];
9429bff0bc4SFelix Fietkau 	unsigned int len;
9439bff0bc4SFelix Fietkau 	u32 regval;
9449bff0bc4SFelix Fietkau 
94579d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
9469bff0bc4SFelix Fietkau 	regval = REG_READ_D(ah, sc->debug.regidx);
94779d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
9482b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", regval);
9499bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
9509bff0bc4SFelix Fietkau }
9519bff0bc4SFelix Fietkau 
9529bff0bc4SFelix Fietkau static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
9539bff0bc4SFelix Fietkau 				 size_t count, loff_t *ppos)
9549bff0bc4SFelix Fietkau {
9559bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
9569bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
9579bff0bc4SFelix Fietkau 	unsigned long regval;
9589bff0bc4SFelix Fietkau 	char buf[32];
9599bff0bc4SFelix Fietkau 	ssize_t len;
9609bff0bc4SFelix Fietkau 
9619bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
9629bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
96304236066SDan Carpenter 		return -EFAULT;
9649bff0bc4SFelix Fietkau 
9659bff0bc4SFelix Fietkau 	buf[len] = '\0';
96627d7f477SJingoo Han 	if (kstrtoul(buf, 0, &regval))
9679bff0bc4SFelix Fietkau 		return -EINVAL;
9689bff0bc4SFelix Fietkau 
96979d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
9709bff0bc4SFelix Fietkau 	REG_WRITE_D(ah, sc->debug.regidx, regval);
97179d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
9729bff0bc4SFelix Fietkau 	return count;
9739bff0bc4SFelix Fietkau }
9749bff0bc4SFelix Fietkau 
9759bff0bc4SFelix Fietkau static const struct file_operations fops_regval = {
9769bff0bc4SFelix Fietkau 	.read = read_file_regval,
9779bff0bc4SFelix Fietkau 	.write = write_file_regval,
978234e3405SStephen Boyd 	.open = simple_open,
9796038f373SArnd Bergmann 	.owner = THIS_MODULE,
9806038f373SArnd Bergmann 	.llseek = default_llseek,
9819bff0bc4SFelix Fietkau };
9829bff0bc4SFelix Fietkau 
983582d0064SVasanthakumar Thiagarajan #define REGDUMP_LINE_SIZE	20
984582d0064SVasanthakumar Thiagarajan 
985582d0064SVasanthakumar Thiagarajan static int open_file_regdump(struct inode *inode, struct file *file)
986582d0064SVasanthakumar Thiagarajan {
987582d0064SVasanthakumar Thiagarajan 	struct ath_softc *sc = inode->i_private;
988582d0064SVasanthakumar Thiagarajan 	unsigned int len = 0;
989582d0064SVasanthakumar Thiagarajan 	u8 *buf;
990582d0064SVasanthakumar Thiagarajan 	int i;
991582d0064SVasanthakumar Thiagarajan 	unsigned long num_regs, regdump_len, max_reg_offset;
992582d0064SVasanthakumar Thiagarajan 
993582d0064SVasanthakumar Thiagarajan 	max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
994582d0064SVasanthakumar Thiagarajan 	num_regs = max_reg_offset / 4 + 1;
995582d0064SVasanthakumar Thiagarajan 	regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
996582d0064SVasanthakumar Thiagarajan 	buf = vmalloc(regdump_len);
997582d0064SVasanthakumar Thiagarajan 	if (!buf)
998582d0064SVasanthakumar Thiagarajan 		return -ENOMEM;
999582d0064SVasanthakumar Thiagarajan 
1000582d0064SVasanthakumar Thiagarajan 	ath9k_ps_wakeup(sc);
1001582d0064SVasanthakumar Thiagarajan 	for (i = 0; i < num_regs; i++)
1002582d0064SVasanthakumar Thiagarajan 		len += scnprintf(buf + len, regdump_len - len,
1003582d0064SVasanthakumar Thiagarajan 			"0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
1004582d0064SVasanthakumar Thiagarajan 	ath9k_ps_restore(sc);
1005582d0064SVasanthakumar Thiagarajan 
1006582d0064SVasanthakumar Thiagarajan 	file->private_data = buf;
1007582d0064SVasanthakumar Thiagarajan 
1008582d0064SVasanthakumar Thiagarajan 	return 0;
1009582d0064SVasanthakumar Thiagarajan }
1010582d0064SVasanthakumar Thiagarajan 
1011582d0064SVasanthakumar Thiagarajan static const struct file_operations fops_regdump = {
1012582d0064SVasanthakumar Thiagarajan 	.open = open_file_regdump,
1013582d0064SVasanthakumar Thiagarajan 	.read = ath9k_debugfs_read_buf,
1014582d0064SVasanthakumar Thiagarajan 	.release = ath9k_debugfs_release_buf,
1015582d0064SVasanthakumar Thiagarajan 	.owner = THIS_MODULE,
1016582d0064SVasanthakumar Thiagarajan 	.llseek = default_llseek,/* read accesses f_pos */
1017582d0064SVasanthakumar Thiagarajan };
1018582d0064SVasanthakumar Thiagarajan 
1019631bee25SArend van Spriel static int read_file_dump_nfcal(struct seq_file *file, void *data)
1020d069a46bSRajkumar Manoharan {
1021f1c488a7SGreg Kroah-Hartman 	struct ath_softc *sc = file->private;
1022d069a46bSRajkumar Manoharan 	struct ath_hw *ah = sc->sc_ah;
1023b01459e8SFelix Fietkau 	struct ath9k_nfcal_hist *h = sc->cur_chan->caldata.nfCalHist;
1024d069a46bSRajkumar Manoharan 	struct ath_common *common = ath9k_hw_common(ah);
1025d069a46bSRajkumar Manoharan 	struct ieee80211_conf *conf = &common->hw->conf;
1026d069a46bSRajkumar Manoharan 	u32 i, j;
1027d069a46bSRajkumar Manoharan 	u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1028d069a46bSRajkumar Manoharan 	u8 nread;
1029d069a46bSRajkumar Manoharan 
1030631bee25SArend van Spriel 	seq_printf(file, "Channel Noise Floor : %d\n", ah->noise);
1031631bee25SArend van Spriel 	seq_puts(file, "Chain | privNF | # Readings | NF Readings\n");
1032d069a46bSRajkumar Manoharan 	for (i = 0; i < NUM_NF_READINGS; i++) {
1033d069a46bSRajkumar Manoharan 		if (!(chainmask & (1 << i)) ||
1034d069a46bSRajkumar Manoharan 		    ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1035d069a46bSRajkumar Manoharan 			continue;
1036d069a46bSRajkumar Manoharan 
1037d069a46bSRajkumar Manoharan 		nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
1038631bee25SArend van Spriel 		seq_printf(file, " %d\t %d\t %d\t\t", i, h[i].privNF, nread);
1039d069a46bSRajkumar Manoharan 		for (j = 0; j < nread; j++)
1040631bee25SArend van Spriel 			seq_printf(file, " %d", h[i].nfCalBuffer[j]);
1041631bee25SArend van Spriel 		seq_puts(file, "\n");
1042d069a46bSRajkumar Manoharan 	}
1043d069a46bSRajkumar Manoharan 
1044631bee25SArend van Spriel 	return 0;
1045631bee25SArend van Spriel }
1046d069a46bSRajkumar Manoharan 
1047631bee25SArend van Spriel static int open_file_dump_nfcal(struct inode *inode, struct file *f)
1048631bee25SArend van Spriel {
1049631bee25SArend van Spriel 	return single_open(f, read_file_dump_nfcal, inode->i_private);
1050d069a46bSRajkumar Manoharan }
1051d069a46bSRajkumar Manoharan 
1052d069a46bSRajkumar Manoharan static const struct file_operations fops_dump_nfcal = {
1053631bee25SArend van Spriel 	.read = seq_read,
1054631bee25SArend van Spriel 	.open = open_file_dump_nfcal,
1055d069a46bSRajkumar Manoharan 	.owner = THIS_MODULE,
1056631bee25SArend van Spriel 	.llseek = seq_lseek,
1057631bee25SArend van Spriel 	.release = single_release,
1058d069a46bSRajkumar Manoharan };
1059d069a46bSRajkumar Manoharan 
10604df50ca8SRajkumar Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
10614df50ca8SRajkumar Manoharan static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
10624df50ca8SRajkumar Manoharan 				size_t count, loff_t *ppos)
10634df50ca8SRajkumar Manoharan {
10644df50ca8SRajkumar Manoharan 	struct ath_softc *sc = file->private_data;
10654df50ca8SRajkumar Manoharan 	u32 len = 0, size = 1500;
10664df50ca8SRajkumar Manoharan 	char *buf;
10674df50ca8SRajkumar Manoharan 	size_t retval;
10684df50ca8SRajkumar Manoharan 
10694df50ca8SRajkumar Manoharan 	buf = kzalloc(size, GFP_KERNEL);
10704df50ca8SRajkumar Manoharan 	if (buf == NULL)
10714df50ca8SRajkumar Manoharan 		return -ENOMEM;
10724df50ca8SRajkumar Manoharan 
1073ac46ba43SSujith Manoharan 	if (!sc->sc_ah->common.btcoex_enabled) {
10745e88ba62SZefir Kurtisi 		len = scnprintf(buf, size, "%s\n",
1075ac46ba43SSujith Manoharan 				"BTCOEX is disabled");
1076ac46ba43SSujith Manoharan 		goto exit;
1077ac46ba43SSujith Manoharan 	}
10784df50ca8SRajkumar Manoharan 
1079ac46ba43SSujith Manoharan 	len = ath9k_dump_btcoex(sc, buf, size);
1080ac46ba43SSujith Manoharan exit:
10814df50ca8SRajkumar Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
10824df50ca8SRajkumar Manoharan 	kfree(buf);
10834df50ca8SRajkumar Manoharan 
10844df50ca8SRajkumar Manoharan 	return retval;
10854df50ca8SRajkumar Manoharan }
10864df50ca8SRajkumar Manoharan 
10874df50ca8SRajkumar Manoharan static const struct file_operations fops_btcoex = {
10884df50ca8SRajkumar Manoharan 	.read = read_file_btcoex,
10894df50ca8SRajkumar Manoharan 	.open = simple_open,
10904df50ca8SRajkumar Manoharan 	.owner = THIS_MODULE,
10914df50ca8SRajkumar Manoharan 	.llseek = default_llseek,
10924df50ca8SRajkumar Manoharan };
10934df50ca8SRajkumar Manoharan #endif
10944df50ca8SRajkumar Manoharan 
10957a90744cSLorenzo Bianconi #ifdef CONFIG_ATH9K_DYNACK
10967a90744cSLorenzo Bianconi static ssize_t read_file_ackto(struct file *file, char __user *user_buf,
10977a90744cSLorenzo Bianconi 			       size_t count, loff_t *ppos)
10987a90744cSLorenzo Bianconi {
10997a90744cSLorenzo Bianconi 	struct ath_softc *sc = file->private_data;
11007a90744cSLorenzo Bianconi 	struct ath_hw *ah = sc->sc_ah;
11017a90744cSLorenzo Bianconi 	char buf[32];
11027a90744cSLorenzo Bianconi 	unsigned int len;
11037a90744cSLorenzo Bianconi 
11047a90744cSLorenzo Bianconi 	len = sprintf(buf, "%u %c\n", ah->dynack.ackto,
11057a90744cSLorenzo Bianconi 		      (ah->dynack.enabled) ? 'A' : 'S');
11067a90744cSLorenzo Bianconi 
11077a90744cSLorenzo Bianconi 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
11087a90744cSLorenzo Bianconi }
11097a90744cSLorenzo Bianconi 
11107a90744cSLorenzo Bianconi static const struct file_operations fops_ackto = {
11117a90744cSLorenzo Bianconi 	.read = read_file_ackto,
11127a90744cSLorenzo Bianconi 	.open = simple_open,
11137a90744cSLorenzo Bianconi 	.owner = THIS_MODULE,
11147a90744cSLorenzo Bianconi 	.llseek = default_llseek,
11157a90744cSLorenzo Bianconi };
11167a90744cSLorenzo Bianconi #endif
11177a90744cSLorenzo Bianconi 
1118c175db87SSujith Manoharan /* Ethtool support for get-stats */
1119c175db87SSujith Manoharan 
1120c175db87SSujith Manoharan #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1121c175db87SSujith Manoharan static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1122c175db87SSujith Manoharan 	"tx_pkts_nic",
1123c175db87SSujith Manoharan 	"tx_bytes_nic",
1124c175db87SSujith Manoharan 	"rx_pkts_nic",
1125c175db87SSujith Manoharan 	"rx_bytes_nic",
1126c175db87SSujith Manoharan 	AMKSTR(d_tx_pkts),
1127c175db87SSujith Manoharan 	AMKSTR(d_tx_bytes),
1128c175db87SSujith Manoharan 	AMKSTR(d_tx_mpdus_queued),
1129c175db87SSujith Manoharan 	AMKSTR(d_tx_mpdus_completed),
1130c175db87SSujith Manoharan 	AMKSTR(d_tx_mpdu_xretries),
1131c175db87SSujith Manoharan 	AMKSTR(d_tx_aggregates),
1132c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdus_queued_hw),
1133c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdus_queued_sw),
1134c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdus_completed),
1135c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdu_retries),
1136c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdu_xretries),
1137c175db87SSujith Manoharan 	AMKSTR(d_tx_fifo_underrun),
1138c175db87SSujith Manoharan 	AMKSTR(d_tx_op_exceeded),
1139c175db87SSujith Manoharan 	AMKSTR(d_tx_timer_expiry),
1140c175db87SSujith Manoharan 	AMKSTR(d_tx_desc_cfg_err),
1141c175db87SSujith Manoharan 	AMKSTR(d_tx_data_underrun),
1142c175db87SSujith Manoharan 	AMKSTR(d_tx_delim_underrun),
114318c45b10SBen Greear 	"d_rx_crc_err",
1144c175db87SSujith Manoharan 	"d_rx_decrypt_crc_err",
1145c175db87SSujith Manoharan 	"d_rx_phy_err",
1146c175db87SSujith Manoharan 	"d_rx_mic_err",
1147c175db87SSujith Manoharan 	"d_rx_pre_delim_crc_err",
1148c175db87SSujith Manoharan 	"d_rx_post_delim_crc_err",
1149c175db87SSujith Manoharan 	"d_rx_decrypt_busy_err",
1150c175db87SSujith Manoharan 
1151c175db87SSujith Manoharan 	"d_rx_phyerr_radar",
1152c175db87SSujith Manoharan 	"d_rx_phyerr_ofdm_timing",
1153c175db87SSujith Manoharan 	"d_rx_phyerr_cck_timing",
1154c175db87SSujith Manoharan 
1155c175db87SSujith Manoharan };
1156c175db87SSujith Manoharan #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1157c175db87SSujith Manoharan 
1158c175db87SSujith Manoharan void ath9k_get_et_strings(struct ieee80211_hw *hw,
1159c175db87SSujith Manoharan 			  struct ieee80211_vif *vif,
1160c175db87SSujith Manoharan 			  u32 sset, u8 *data)
1161c175db87SSujith Manoharan {
1162c175db87SSujith Manoharan 	if (sset == ETH_SS_STATS)
1163c175db87SSujith Manoharan 		memcpy(data, *ath9k_gstrings_stats,
1164c175db87SSujith Manoharan 		       sizeof(ath9k_gstrings_stats));
1165c175db87SSujith Manoharan }
1166c175db87SSujith Manoharan 
1167c175db87SSujith Manoharan int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
1168c175db87SSujith Manoharan 			    struct ieee80211_vif *vif, int sset)
1169c175db87SSujith Manoharan {
1170c175db87SSujith Manoharan 	if (sset == ETH_SS_STATS)
1171c175db87SSujith Manoharan 		return ATH9K_SSTATS_LEN;
1172c175db87SSujith Manoharan 	return 0;
1173c175db87SSujith Manoharan }
1174c175db87SSujith Manoharan 
1175c175db87SSujith Manoharan #define AWDATA(elem)							\
1176c175db87SSujith Manoharan 	do {								\
1177c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
1178c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
1179c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
1180c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
1181c175db87SSujith Manoharan 	} while (0)
1182c175db87SSujith Manoharan 
1183c175db87SSujith Manoharan #define AWDATA_RX(elem)						\
1184c175db87SSujith Manoharan 	do {							\
1185c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.rxstats.elem;	\
1186c175db87SSujith Manoharan 	} while (0)
1187c175db87SSujith Manoharan 
1188c175db87SSujith Manoharan void ath9k_get_et_stats(struct ieee80211_hw *hw,
1189c175db87SSujith Manoharan 			struct ieee80211_vif *vif,
1190c175db87SSujith Manoharan 			struct ethtool_stats *stats, u64 *data)
1191c175db87SSujith Manoharan {
1192c175db87SSujith Manoharan 	struct ath_softc *sc = hw->priv;
1193c175db87SSujith Manoharan 	int i = 0;
1194c175db87SSujith Manoharan 
1195c175db87SSujith Manoharan 	data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
1196c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
1197c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
1198c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
1199c175db87SSujith Manoharan 	data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
1200c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
1201c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
1202c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
1203c175db87SSujith Manoharan 	AWDATA_RX(rx_pkts_all);
1204c175db87SSujith Manoharan 	AWDATA_RX(rx_bytes_all);
1205c175db87SSujith Manoharan 
1206c175db87SSujith Manoharan 	AWDATA(tx_pkts_all);
1207c175db87SSujith Manoharan 	AWDATA(tx_bytes_all);
1208c175db87SSujith Manoharan 	AWDATA(queued);
1209c175db87SSujith Manoharan 	AWDATA(completed);
1210c175db87SSujith Manoharan 	AWDATA(xretries);
1211c175db87SSujith Manoharan 	AWDATA(a_aggr);
1212c175db87SSujith Manoharan 	AWDATA(a_queued_hw);
1213c175db87SSujith Manoharan 	AWDATA(a_queued_sw);
1214c175db87SSujith Manoharan 	AWDATA(a_completed);
1215c175db87SSujith Manoharan 	AWDATA(a_retries);
1216c175db87SSujith Manoharan 	AWDATA(a_xretries);
1217c175db87SSujith Manoharan 	AWDATA(fifo_underrun);
1218c175db87SSujith Manoharan 	AWDATA(xtxop);
1219c175db87SSujith Manoharan 	AWDATA(timer_exp);
1220c175db87SSujith Manoharan 	AWDATA(desc_cfg_err);
1221c175db87SSujith Manoharan 	AWDATA(data_underrun);
1222c175db87SSujith Manoharan 	AWDATA(delim_underrun);
1223c175db87SSujith Manoharan 
122418c45b10SBen Greear 	AWDATA_RX(crc_err);
1225c175db87SSujith Manoharan 	AWDATA_RX(decrypt_crc_err);
1226c175db87SSujith Manoharan 	AWDATA_RX(phy_err);
1227c175db87SSujith Manoharan 	AWDATA_RX(mic_err);
1228c175db87SSujith Manoharan 	AWDATA_RX(pre_delim_crc_err);
1229c175db87SSujith Manoharan 	AWDATA_RX(post_delim_crc_err);
1230c175db87SSujith Manoharan 	AWDATA_RX(decrypt_busy_err);
1231c175db87SSujith Manoharan 
1232c175db87SSujith Manoharan 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
1233c175db87SSujith Manoharan 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
1234c175db87SSujith Manoharan 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
1235c175db87SSujith Manoharan 
1236c175db87SSujith Manoharan 	WARN_ON(i != ATH9K_SSTATS_LEN);
1237c175db87SSujith Manoharan }
1238c175db87SSujith Manoharan 
1239af690092SSujith Manoharan void ath9k_deinit_debug(struct ath_softc *sc)
1240af690092SSujith Manoharan {
124167dc74f1SOleksij Rempel 	ath9k_cmn_spectral_deinit_debug(&sc->spec_priv);
1242af690092SSujith Manoharan }
1243af690092SSujith Manoharan 
12444d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah)
1245203c4805SLuis R. Rodriguez {
1246bc974f4aSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(ah);
1247bc974f4aSLuis R. Rodriguez 	struct ath_softc *sc = (struct ath_softc *) common->priv;
12484d6b228dSLuis R. Rodriguez 
1249eb272441SBen Greear 	sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1250eb272441SBen Greear 						   sc->hw->wiphy->debugfsdir);
1251203c4805SLuis R. Rodriguez 	if (!sc->debug.debugfs_phy)
1252c8a72c00SFelix Fietkau 		return -ENOMEM;
1253203c4805SLuis R. Rodriguez 
1254a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
1255c70cab1aSFelix Fietkau 	debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1256c70cab1aSFelix Fietkau 			    sc, &fops_debug);
1257a830df07SFelix Fietkau #endif
125829942bc1SZefir Kurtisi 
125929942bc1SZefir Kurtisi 	ath9k_dfs_init_debug(sc);
1260ef6b19e4SSujith Manoharan 	ath9k_tx99_init_debug(sc);
126167dc74f1SOleksij Rempel 	ath9k_cmn_spectral_init_debug(&sc->spec_priv, sc->debug.debugfs_phy);
126229942bc1SZefir Kurtisi 
1263c70cab1aSFelix Fietkau 	debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
1264c70cab1aSFelix Fietkau 			    &fops_dma);
1265c70cab1aSFelix Fietkau 	debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
1266c70cab1aSFelix Fietkau 			    &fops_interrupt);
1267c70cab1aSFelix Fietkau 	debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc,
1268c70cab1aSFelix Fietkau 			    &fops_xmit);
1269c0b74876SSujith Manoharan 	debugfs_create_file("queues", S_IRUSR, sc->debug.debugfs_phy, sc,
1270c0b74876SSujith Manoharan 			    &fops_queues);
12717702e788SFelix Fietkau 	debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1272bea843c7SSujith Manoharan 			   &sc->tx.txq_max_pending[IEEE80211_AC_BK]);
12737702e788SFelix Fietkau 	debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1274bea843c7SSujith Manoharan 			   &sc->tx.txq_max_pending[IEEE80211_AC_BE]);
12757702e788SFelix Fietkau 	debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1276bea843c7SSujith Manoharan 			   &sc->tx.txq_max_pending[IEEE80211_AC_VI]);
12777702e788SFelix Fietkau 	debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1278bea843c7SSujith Manoharan 			   &sc->tx.txq_max_pending[IEEE80211_AC_VO]);
1279c70cab1aSFelix Fietkau 	debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy, sc,
1280c70cab1aSFelix Fietkau 			    &fops_misc);
1281f8b815dcSSujith Manoharan 	debugfs_create_file("reset", S_IRUSR, sc->debug.debugfs_phy, sc,
1282f8b815dcSSujith Manoharan 			    &fops_reset);
128387ea9b0bSOleksij Rempel 
128487ea9b0bSOleksij Rempel 	ath9k_cmn_debug_recv(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
1285e02912cdSOleksij Rempel 	ath9k_cmn_debug_phy_err(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
128687ea9b0bSOleksij Rempel 
1287ca6d4a74SFelix Fietkau 	debugfs_create_u8("rx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
1288ca6d4a74SFelix Fietkau 			  &ah->rxchainmask);
1289ca6d4a74SFelix Fietkau 	debugfs_create_u8("tx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
1290ca6d4a74SFelix Fietkau 			  &ah->txchainmask);
12916e4d291eSSujith Manoharan 	debugfs_create_file("ani", S_IRUSR | S_IWUSR,
12926e4d291eSSujith Manoharan 			    sc->debug.debugfs_phy, sc, &fops_ani);
129374673db9SFelix Fietkau 	debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
129474673db9SFelix Fietkau 			    &sc->sc_ah->config.enable_paprd);
1295c70cab1aSFelix Fietkau 	debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1296c70cab1aSFelix Fietkau 			    sc, &fops_regidx);
1297c70cab1aSFelix Fietkau 	debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1298c70cab1aSFelix Fietkau 			    sc, &fops_regval);
1299c70cab1aSFelix Fietkau 	debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1300c70cab1aSFelix Fietkau 			    sc->debug.debugfs_phy,
1301c70cab1aSFelix Fietkau 			    &ah->config.cwm_ignore_extcca);
1302c70cab1aSFelix Fietkau 	debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
1303c70cab1aSFelix Fietkau 			    &fops_regdump);
1304d069a46bSRajkumar Manoharan 	debugfs_create_file("dump_nfcal", S_IRUSR, sc->debug.debugfs_phy, sc,
1305d069a46bSRajkumar Manoharan 			    &fops_dump_nfcal);
1306f2c3c952SOleksij Rempel 
130729bf801eSOleksij Rempel 	ath9k_cmn_debug_base_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
1308f2c3c952SOleksij Rempel 	ath9k_cmn_debug_modal_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
1309f2c3c952SOleksij Rempel 
1310691680b8SFelix Fietkau 	debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
1311691680b8SFelix Fietkau 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
1312691680b8SFelix Fietkau 	debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
1313691680b8SFelix Fietkau 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
13144eba10ccSSujith Manoharan 	debugfs_create_file("antenna_diversity", S_IRUSR,
13154eba10ccSSujith Manoharan 			    sc->debug.debugfs_phy, sc, &fops_antenna_diversity);
13164df50ca8SRajkumar Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
131736e8825eSSujith Manoharan 	debugfs_create_file("bt_ant_diversity", S_IRUSR | S_IWUSR,
131836e8825eSSujith Manoharan 			    sc->debug.debugfs_phy, sc, &fops_bt_ant_diversity);
13194df50ca8SRajkumar Manoharan 	debugfs_create_file("btcoex", S_IRUSR, sc->debug.debugfs_phy, sc,
13204df50ca8SRajkumar Manoharan 			    &fops_btcoex);
13214df50ca8SRajkumar Manoharan #endif
132289f927afSLuis R. Rodriguez 
13237a90744cSLorenzo Bianconi #ifdef CONFIG_ATH9K_DYNACK
13247a90744cSLorenzo Bianconi 	debugfs_create_file("ack_to", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
13257a90744cSLorenzo Bianconi 			    sc, &fops_ackto);
13267a90744cSLorenzo Bianconi #endif
13277a90744cSLorenzo Bianconi 
1328203c4805SLuis R. Rodriguez 	return 0;
1329203c4805SLuis R. Rodriguez }
1330