xref: /openbmc/linux/drivers/net/wireless/ath/ath9k/debug.c (revision 18fcf1c6a6ff4b00fe06e1d0ef05ff76ed2fe86c)
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>
20e93d083fSSimon Wunderlich #include <linux/relay.h>
21203c4805SLuis R. Rodriguez #include <asm/unaligned.h>
22203c4805SLuis R. Rodriguez 
23203c4805SLuis R. Rodriguez #include "ath9k.h"
24203c4805SLuis R. Rodriguez 
25475a6e4dSLuis R. Rodriguez #define REG_WRITE_D(_ah, _reg, _val) \
26475a6e4dSLuis R. Rodriguez 	ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg))
27475a6e4dSLuis R. Rodriguez #define REG_READ_D(_ah, _reg) \
28475a6e4dSLuis R. Rodriguez 	ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
29475a6e4dSLuis R. Rodriguez 
30203c4805SLuis R. Rodriguez 
31582d0064SVasanthakumar Thiagarajan static ssize_t ath9k_debugfs_read_buf(struct file *file, char __user *user_buf,
32582d0064SVasanthakumar Thiagarajan 				      size_t count, loff_t *ppos)
33582d0064SVasanthakumar Thiagarajan {
34582d0064SVasanthakumar Thiagarajan 	u8 *buf = file->private_data;
35582d0064SVasanthakumar Thiagarajan 	return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
36582d0064SVasanthakumar Thiagarajan }
37582d0064SVasanthakumar Thiagarajan 
38582d0064SVasanthakumar Thiagarajan static int ath9k_debugfs_release_buf(struct inode *inode, struct file *file)
39582d0064SVasanthakumar Thiagarajan {
40582d0064SVasanthakumar Thiagarajan 	vfree(file->private_data);
41582d0064SVasanthakumar Thiagarajan 	return 0;
42582d0064SVasanthakumar Thiagarajan }
43582d0064SVasanthakumar Thiagarajan 
44a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
45a830df07SFelix Fietkau 
462493928eSJeff Hansen static ssize_t read_file_debug(struct file *file, char __user *user_buf,
472493928eSJeff Hansen 			     size_t count, loff_t *ppos)
482493928eSJeff Hansen {
492493928eSJeff Hansen 	struct ath_softc *sc = file->private_data;
50c46917bbSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
512493928eSJeff Hansen 	char buf[32];
52581f725cSVasanthakumar Thiagarajan 	unsigned int len;
53581f725cSVasanthakumar Thiagarajan 
542b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", common->debug_mask);
552493928eSJeff Hansen 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
562493928eSJeff Hansen }
572493928eSJeff Hansen 
582493928eSJeff Hansen static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
592493928eSJeff Hansen 			     size_t count, loff_t *ppos)
602493928eSJeff Hansen {
612493928eSJeff Hansen 	struct ath_softc *sc = file->private_data;
62c46917bbSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
632493928eSJeff Hansen 	unsigned long mask;
642493928eSJeff Hansen 	char buf[32];
65581f725cSVasanthakumar Thiagarajan 	ssize_t len;
66581f725cSVasanthakumar Thiagarajan 
67581f725cSVasanthakumar Thiagarajan 	len = min(count, sizeof(buf) - 1);
68581f725cSVasanthakumar Thiagarajan 	if (copy_from_user(buf, user_buf, len))
6904236066SDan Carpenter 		return -EFAULT;
70581f725cSVasanthakumar Thiagarajan 
71581f725cSVasanthakumar Thiagarajan 	buf[len] = '\0';
7227d7f477SJingoo Han 	if (kstrtoul(buf, 0, &mask))
73581f725cSVasanthakumar Thiagarajan 		return -EINVAL;
74581f725cSVasanthakumar Thiagarajan 
75c46917bbSLuis R. Rodriguez 	common->debug_mask = mask;
762493928eSJeff Hansen 	return count;
772493928eSJeff Hansen }
782493928eSJeff Hansen 
792493928eSJeff Hansen static const struct file_operations fops_debug = {
802493928eSJeff Hansen 	.read = read_file_debug,
812493928eSJeff Hansen 	.write = write_file_debug,
82234e3405SStephen Boyd 	.open = simple_open,
836038f373SArnd Bergmann 	.owner = THIS_MODULE,
846038f373SArnd Bergmann 	.llseek = default_llseek,
852493928eSJeff Hansen };
862493928eSJeff Hansen 
87a830df07SFelix Fietkau #endif
88a830df07SFelix Fietkau 
89991a0987SPavel Roskin #define DMA_BUF_LEN 1024
90991a0987SPavel Roskin 
9115340694SFelix Fietkau static ssize_t read_file_tx_chainmask(struct file *file, char __user *user_buf,
9215340694SFelix Fietkau 			     size_t count, loff_t *ppos)
9315340694SFelix Fietkau {
9415340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
9582b2d334SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
9615340694SFelix Fietkau 	char buf[32];
9715340694SFelix Fietkau 	unsigned int len;
9815340694SFelix Fietkau 
9982b2d334SFelix Fietkau 	len = sprintf(buf, "0x%08x\n", ah->txchainmask);
10015340694SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
10115340694SFelix Fietkau }
10215340694SFelix Fietkau 
10315340694SFelix Fietkau static ssize_t write_file_tx_chainmask(struct file *file, const char __user *user_buf,
10415340694SFelix Fietkau 			     size_t count, loff_t *ppos)
10515340694SFelix Fietkau {
10615340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
10782b2d334SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
10815340694SFelix Fietkau 	unsigned long mask;
10915340694SFelix Fietkau 	char buf[32];
11015340694SFelix Fietkau 	ssize_t len;
11115340694SFelix Fietkau 
11215340694SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
11315340694SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
11404236066SDan Carpenter 		return -EFAULT;
11515340694SFelix Fietkau 
11615340694SFelix Fietkau 	buf[len] = '\0';
11727d7f477SJingoo Han 	if (kstrtoul(buf, 0, &mask))
11815340694SFelix Fietkau 		return -EINVAL;
11915340694SFelix Fietkau 
12082b2d334SFelix Fietkau 	ah->txchainmask = mask;
12182b2d334SFelix Fietkau 	ah->caps.tx_chainmask = mask;
12215340694SFelix Fietkau 	return count;
12315340694SFelix Fietkau }
12415340694SFelix Fietkau 
12515340694SFelix Fietkau static const struct file_operations fops_tx_chainmask = {
12615340694SFelix Fietkau 	.read = read_file_tx_chainmask,
12715340694SFelix Fietkau 	.write = write_file_tx_chainmask,
128234e3405SStephen Boyd 	.open = simple_open,
1296038f373SArnd Bergmann 	.owner = THIS_MODULE,
1306038f373SArnd Bergmann 	.llseek = default_llseek,
13115340694SFelix Fietkau };
13215340694SFelix Fietkau 
13315340694SFelix Fietkau 
13415340694SFelix Fietkau static ssize_t read_file_rx_chainmask(struct file *file, char __user *user_buf,
13515340694SFelix Fietkau 			     size_t count, loff_t *ppos)
13615340694SFelix Fietkau {
13715340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
13882b2d334SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
13915340694SFelix Fietkau 	char buf[32];
14015340694SFelix Fietkau 	unsigned int len;
14115340694SFelix Fietkau 
14282b2d334SFelix Fietkau 	len = sprintf(buf, "0x%08x\n", ah->rxchainmask);
14315340694SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
14415340694SFelix Fietkau }
14515340694SFelix Fietkau 
14615340694SFelix Fietkau static ssize_t write_file_rx_chainmask(struct file *file, const char __user *user_buf,
14715340694SFelix Fietkau 			     size_t count, loff_t *ppos)
14815340694SFelix Fietkau {
14915340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
15082b2d334SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
15115340694SFelix Fietkau 	unsigned long mask;
15215340694SFelix Fietkau 	char buf[32];
15315340694SFelix Fietkau 	ssize_t len;
15415340694SFelix Fietkau 
15515340694SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
15615340694SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
15704236066SDan Carpenter 		return -EFAULT;
15815340694SFelix Fietkau 
15915340694SFelix Fietkau 	buf[len] = '\0';
16027d7f477SJingoo Han 	if (kstrtoul(buf, 0, &mask))
16115340694SFelix Fietkau 		return -EINVAL;
16215340694SFelix Fietkau 
16382b2d334SFelix Fietkau 	ah->rxchainmask = mask;
16482b2d334SFelix Fietkau 	ah->caps.rx_chainmask = mask;
16515340694SFelix Fietkau 	return count;
16615340694SFelix Fietkau }
16715340694SFelix Fietkau 
16815340694SFelix Fietkau static const struct file_operations fops_rx_chainmask = {
16915340694SFelix Fietkau 	.read = read_file_rx_chainmask,
17015340694SFelix Fietkau 	.write = write_file_rx_chainmask,
171234e3405SStephen Boyd 	.open = simple_open,
1726038f373SArnd Bergmann 	.owner = THIS_MODULE,
1736038f373SArnd Bergmann 	.llseek = default_llseek,
17415340694SFelix Fietkau };
17515340694SFelix Fietkau 
1766e4d291eSSujith Manoharan static ssize_t read_file_ani(struct file *file, char __user *user_buf,
17705c0be2fSMohammed Shafi Shajakhan 			     size_t count, loff_t *ppos)
17805c0be2fSMohammed Shafi Shajakhan {
17905c0be2fSMohammed Shafi Shajakhan 	struct ath_softc *sc = file->private_data;
18005c0be2fSMohammed Shafi Shajakhan 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1816e4d291eSSujith Manoharan 	struct ath_hw *ah = sc->sc_ah;
1826e4d291eSSujith Manoharan 	unsigned int len = 0, size = 1024;
1836e4d291eSSujith Manoharan 	ssize_t retval = 0;
1846e4d291eSSujith Manoharan 	char *buf;
18505c0be2fSMohammed Shafi Shajakhan 
1866e4d291eSSujith Manoharan 	buf = kzalloc(size, GFP_KERNEL);
1876e4d291eSSujith Manoharan 	if (buf == NULL)
1886e4d291eSSujith Manoharan 		return -ENOMEM;
1896e4d291eSSujith Manoharan 
1906e4d291eSSujith Manoharan 	if (common->disable_ani) {
1916e4d291eSSujith Manoharan 		len += snprintf(buf + len, size - len, "%s: %s\n",
1926e4d291eSSujith Manoharan 				"ANI", "DISABLED");
1936e4d291eSSujith Manoharan 		goto exit;
19405c0be2fSMohammed Shafi Shajakhan 	}
19505c0be2fSMohammed Shafi Shajakhan 
1966e4d291eSSujith Manoharan 	len += snprintf(buf + len, size - len, "%15s: %s\n",
1976e4d291eSSujith Manoharan 			"ANI", "ENABLED");
1986e4d291eSSujith Manoharan 	len += snprintf(buf + len, size - len, "%15s: %u\n",
1996e4d291eSSujith Manoharan 			"ANI RESET", ah->stats.ast_ani_reset);
2006e4d291eSSujith Manoharan 	len += snprintf(buf + len, size - len, "%15s: %u\n",
2016e4d291eSSujith Manoharan 			"SPUR UP", ah->stats.ast_ani_spurup);
2026e4d291eSSujith Manoharan 	len += snprintf(buf + len, size - len, "%15s: %u\n",
2036e4d291eSSujith Manoharan 			"SPUR DOWN", ah->stats.ast_ani_spurup);
2046e4d291eSSujith Manoharan 	len += snprintf(buf + len, size - len, "%15s: %u\n",
2056e4d291eSSujith Manoharan 			"OFDM WS-DET ON", ah->stats.ast_ani_ofdmon);
2066e4d291eSSujith Manoharan 	len += snprintf(buf + len, size - len, "%15s: %u\n",
2076e4d291eSSujith Manoharan 			"OFDM WS-DET OFF", ah->stats.ast_ani_ofdmoff);
2086e4d291eSSujith Manoharan 	len += snprintf(buf + len, size - len, "%15s: %u\n",
2096e4d291eSSujith Manoharan 			"MRC-CCK ON", ah->stats.ast_ani_ccklow);
2106e4d291eSSujith Manoharan 	len += snprintf(buf + len, size - len, "%15s: %u\n",
2116e4d291eSSujith Manoharan 			"MRC-CCK OFF", ah->stats.ast_ani_cckhigh);
2126e4d291eSSujith Manoharan 	len += snprintf(buf + len, size - len, "%15s: %u\n",
2136e4d291eSSujith Manoharan 			"FIR-STEP UP", ah->stats.ast_ani_stepup);
2146e4d291eSSujith Manoharan 	len += snprintf(buf + len, size - len, "%15s: %u\n",
2156e4d291eSSujith Manoharan 			"FIR-STEP DOWN", ah->stats.ast_ani_stepdown);
2166e4d291eSSujith Manoharan 	len += snprintf(buf + len, size - len, "%15s: %u\n",
2176e4d291eSSujith Manoharan 			"INV LISTENTIME", ah->stats.ast_ani_lneg_or_lzero);
2186e4d291eSSujith Manoharan 	len += snprintf(buf + len, size - len, "%15s: %u\n",
2196e4d291eSSujith Manoharan 			"OFDM ERRORS", ah->stats.ast_ani_ofdmerrs);
2206e4d291eSSujith Manoharan 	len += snprintf(buf + len, size - len, "%15s: %u\n",
2216e4d291eSSujith Manoharan 			"CCK ERRORS", ah->stats.ast_ani_cckerrs);
2226e4d291eSSujith Manoharan exit:
2236e4d291eSSujith Manoharan 	if (len > size)
2246e4d291eSSujith Manoharan 		len = size;
2256e4d291eSSujith Manoharan 
2266e4d291eSSujith Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
2276e4d291eSSujith Manoharan 	kfree(buf);
2286e4d291eSSujith Manoharan 
2296e4d291eSSujith Manoharan 	return retval;
2306e4d291eSSujith Manoharan }
2316e4d291eSSujith Manoharan 
2326e4d291eSSujith Manoharan static ssize_t write_file_ani(struct file *file,
23305c0be2fSMohammed Shafi Shajakhan 			      const char __user *user_buf,
23405c0be2fSMohammed Shafi Shajakhan 			      size_t count, loff_t *ppos)
23505c0be2fSMohammed Shafi Shajakhan {
23605c0be2fSMohammed Shafi Shajakhan 	struct ath_softc *sc = file->private_data;
23705c0be2fSMohammed Shafi Shajakhan 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2386e4d291eSSujith Manoharan 	unsigned long ani;
23905c0be2fSMohammed Shafi Shajakhan 	char buf[32];
24005c0be2fSMohammed Shafi Shajakhan 	ssize_t len;
24105c0be2fSMohammed Shafi Shajakhan 
24205c0be2fSMohammed Shafi Shajakhan 	len = min(count, sizeof(buf) - 1);
24305c0be2fSMohammed Shafi Shajakhan 	if (copy_from_user(buf, user_buf, len))
24405c0be2fSMohammed Shafi Shajakhan 		return -EFAULT;
24505c0be2fSMohammed Shafi Shajakhan 
24605c0be2fSMohammed Shafi Shajakhan 	buf[len] = '\0';
2473899ba90SJohn W. Linville 	if (kstrtoul(buf, 0, &ani))
24805c0be2fSMohammed Shafi Shajakhan 		return -EINVAL;
24905c0be2fSMohammed Shafi Shajakhan 
2506e4d291eSSujith Manoharan 	if (ani < 0 || ani > 1)
2516e4d291eSSujith Manoharan 		return -EINVAL;
25205c0be2fSMohammed Shafi Shajakhan 
2536e4d291eSSujith Manoharan 	common->disable_ani = !ani;
2546e4d291eSSujith Manoharan 
2556e4d291eSSujith Manoharan 	if (common->disable_ani) {
256781b14a3SSujith Manoharan 		clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
257da0d45f7SSujith Manoharan 		ath_stop_ani(sc);
25805c0be2fSMohammed Shafi Shajakhan 	} else {
259da0d45f7SSujith Manoharan 		ath_check_ani(sc);
26005c0be2fSMohammed Shafi Shajakhan 	}
26105c0be2fSMohammed Shafi Shajakhan 
26205c0be2fSMohammed Shafi Shajakhan 	return count;
26305c0be2fSMohammed Shafi Shajakhan }
26405c0be2fSMohammed Shafi Shajakhan 
2656e4d291eSSujith Manoharan static const struct file_operations fops_ani = {
2666e4d291eSSujith Manoharan 	.read = read_file_ani,
2676e4d291eSSujith Manoharan 	.write = write_file_ani,
268234e3405SStephen Boyd 	.open = simple_open,
26905c0be2fSMohammed Shafi Shajakhan 	.owner = THIS_MODULE,
27005c0be2fSMohammed Shafi Shajakhan 	.llseek = default_llseek,
27105c0be2fSMohammed Shafi Shajakhan };
27215340694SFelix Fietkau 
27336e8825eSSujith Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
27436e8825eSSujith Manoharan 
27563081305SSujith Manoharan static ssize_t read_file_bt_ant_diversity(struct file *file,
27663081305SSujith Manoharan 					  char __user *user_buf,
277302a3c3aSSujith Manoharan 					  size_t count, loff_t *ppos)
278302a3c3aSSujith Manoharan {
279302a3c3aSSujith Manoharan 	struct ath_softc *sc = file->private_data;
280302a3c3aSSujith Manoharan 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
281302a3c3aSSujith Manoharan 	char buf[32];
282302a3c3aSSujith Manoharan 	unsigned int len;
283302a3c3aSSujith Manoharan 
28463081305SSujith Manoharan 	len = sprintf(buf, "%d\n", common->bt_ant_diversity);
285302a3c3aSSujith Manoharan 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
286302a3c3aSSujith Manoharan }
287302a3c3aSSujith Manoharan 
28863081305SSujith Manoharan static ssize_t write_file_bt_ant_diversity(struct file *file,
289302a3c3aSSujith Manoharan 					   const char __user *user_buf,
290302a3c3aSSujith Manoharan 					   size_t count, loff_t *ppos)
291302a3c3aSSujith Manoharan {
292302a3c3aSSujith Manoharan 	struct ath_softc *sc = file->private_data;
293302a3c3aSSujith Manoharan 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2943f2da955SSujith Manoharan 	struct ath9k_hw_capabilities *pCap = &sc->sc_ah->caps;
29563081305SSujith Manoharan 	unsigned long bt_ant_diversity;
296302a3c3aSSujith Manoharan 	char buf[32];
297302a3c3aSSujith Manoharan 	ssize_t len;
298302a3c3aSSujith Manoharan 
299302a3c3aSSujith Manoharan 	len = min(count, sizeof(buf) - 1);
300302a3c3aSSujith Manoharan 	if (copy_from_user(buf, user_buf, len))
301302a3c3aSSujith Manoharan 		return -EFAULT;
302302a3c3aSSujith Manoharan 
3033f2da955SSujith Manoharan 	if (!(pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
3043f2da955SSujith Manoharan 		goto exit;
3053f2da955SSujith Manoharan 
306302a3c3aSSujith Manoharan 	buf[len] = '\0';
30763081305SSujith Manoharan 	if (kstrtoul(buf, 0, &bt_ant_diversity))
308302a3c3aSSujith Manoharan 		return -EINVAL;
309302a3c3aSSujith Manoharan 
31063081305SSujith Manoharan 	common->bt_ant_diversity = !!bt_ant_diversity;
311302a3c3aSSujith Manoharan 	ath9k_ps_wakeup(sc);
312047dc3acSSujith Manoharan 	ath9k_hw_set_bt_ant_diversity(sc->sc_ah, common->bt_ant_diversity);
31363081305SSujith Manoharan 	ath_dbg(common, CONFIG, "Enable WLAN/BT RX Antenna diversity: %d\n",
31463081305SSujith Manoharan 		common->bt_ant_diversity);
315302a3c3aSSujith Manoharan 	ath9k_ps_restore(sc);
3163f2da955SSujith Manoharan exit:
317302a3c3aSSujith Manoharan 	return count;
318302a3c3aSSujith Manoharan }
319302a3c3aSSujith Manoharan 
32063081305SSujith Manoharan static const struct file_operations fops_bt_ant_diversity = {
32163081305SSujith Manoharan 	.read = read_file_bt_ant_diversity,
32263081305SSujith Manoharan 	.write = write_file_bt_ant_diversity,
323302a3c3aSSujith Manoharan 	.open = simple_open,
324302a3c3aSSujith Manoharan 	.owner = THIS_MODULE,
325302a3c3aSSujith Manoharan 	.llseek = default_llseek,
326302a3c3aSSujith Manoharan };
327302a3c3aSSujith Manoharan 
32836e8825eSSujith Manoharan #endif
32936e8825eSSujith Manoharan 
330e3d52914SSujith Manoharan void ath9k_debug_stat_ant(struct ath_softc *sc,
331e3d52914SSujith Manoharan 			  struct ath_hw_antcomb_conf *div_ant_conf,
332e3d52914SSujith Manoharan 			  int main_rssi_avg, int alt_rssi_avg)
333e3d52914SSujith Manoharan {
334e3d52914SSujith Manoharan 	struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
335e3d52914SSujith Manoharan 	struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
336e3d52914SSujith Manoharan 
337e3d52914SSujith Manoharan 	as_main->lna_attempt_cnt[div_ant_conf->main_lna_conf]++;
338e3d52914SSujith Manoharan 	as_alt->lna_attempt_cnt[div_ant_conf->alt_lna_conf]++;
339e3d52914SSujith Manoharan 
340e3d52914SSujith Manoharan 	as_main->rssi_avg = main_rssi_avg;
341e3d52914SSujith Manoharan 	as_alt->rssi_avg = alt_rssi_avg;
342e3d52914SSujith Manoharan }
343e3d52914SSujith Manoharan 
3444eba10ccSSujith Manoharan static ssize_t read_file_antenna_diversity(struct file *file,
3454eba10ccSSujith Manoharan 					   char __user *user_buf,
3464eba10ccSSujith Manoharan 					   size_t count, loff_t *ppos)
3474eba10ccSSujith Manoharan {
3484eba10ccSSujith Manoharan 	struct ath_softc *sc = file->private_data;
3494eba10ccSSujith Manoharan 	struct ath_hw *ah = sc->sc_ah;
3504eba10ccSSujith Manoharan 	struct ath9k_hw_capabilities *pCap = &ah->caps;
3514eba10ccSSujith Manoharan 	struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
3524eba10ccSSujith Manoharan 	struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
353e3d52914SSujith Manoharan 	struct ath_hw_antcomb_conf div_ant_conf;
3544eba10ccSSujith Manoharan 	unsigned int len = 0, size = 1024;
3554eba10ccSSujith Manoharan 	ssize_t retval = 0;
3564eba10ccSSujith Manoharan 	char *buf;
357e3d52914SSujith Manoharan 	char *lna_conf_str[4] = {"LNA1_MINUS_LNA2",
358e3d52914SSujith Manoharan 				 "LNA2",
359e3d52914SSujith Manoharan 				 "LNA1",
360e3d52914SSujith Manoharan 				 "LNA1_PLUS_LNA2"};
3614eba10ccSSujith Manoharan 
3624eba10ccSSujith Manoharan 	buf = kzalloc(size, GFP_KERNEL);
3634eba10ccSSujith Manoharan 	if (buf == NULL)
3644eba10ccSSujith Manoharan 		return -ENOMEM;
3654eba10ccSSujith Manoharan 
3664eba10ccSSujith Manoharan 	if (!(pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)) {
3674eba10ccSSujith Manoharan 		len += snprintf(buf + len, size - len, "%s\n",
3684eba10ccSSujith Manoharan 				"Antenna Diversity Combining is disabled");
3694eba10ccSSujith Manoharan 		goto exit;
3704eba10ccSSujith Manoharan 	}
3714eba10ccSSujith Manoharan 
372e3d52914SSujith Manoharan 	ath9k_ps_wakeup(sc);
373e3d52914SSujith Manoharan 	ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
374e3d52914SSujith Manoharan 	len += snprintf(buf + len, size - len, "Current MAIN config : %s\n",
375e3d52914SSujith Manoharan 			lna_conf_str[div_ant_conf.main_lna_conf]);
376e3d52914SSujith Manoharan 	len += snprintf(buf + len, size - len, "Current ALT config  : %s\n",
377e3d52914SSujith Manoharan 			lna_conf_str[div_ant_conf.alt_lna_conf]);
378e3d52914SSujith Manoharan 	len += snprintf(buf + len, size - len, "Average MAIN RSSI   : %d\n",
379e3d52914SSujith Manoharan 			as_main->rssi_avg);
380e3d52914SSujith Manoharan 	len += snprintf(buf + len, size - len, "Average ALT RSSI    : %d\n\n",
381e3d52914SSujith Manoharan 			as_alt->rssi_avg);
382e3d52914SSujith Manoharan 	ath9k_ps_restore(sc);
383e3d52914SSujith Manoharan 
384e3d52914SSujith Manoharan 	len += snprintf(buf + len, size - len, "Packet Receive Cnt:\n");
385e3d52914SSujith Manoharan 	len += snprintf(buf + len, size - len, "-------------------\n");
386e3d52914SSujith Manoharan 
3874eba10ccSSujith Manoharan 	len += snprintf(buf + len, size - len, "%30s%15s\n",
3884eba10ccSSujith Manoharan 			"MAIN", "ALT");
389e3d52914SSujith Manoharan 	len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
390e3d52914SSujith Manoharan 			"TOTAL COUNT",
3914eba10ccSSujith Manoharan 			as_main->recv_cnt,
3924eba10ccSSujith Manoharan 			as_alt->recv_cnt);
393e3d52914SSujith Manoharan 	len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3944eba10ccSSujith Manoharan 			"LNA1",
395e3d52914SSujith Manoharan 			as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1],
396e3d52914SSujith Manoharan 			as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1]);
397e3d52914SSujith Manoharan 	len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3984eba10ccSSujith Manoharan 			"LNA2",
399e3d52914SSujith Manoharan 			as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2],
400e3d52914SSujith Manoharan 			as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2]);
401e3d52914SSujith Manoharan 	len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
4024eba10ccSSujith Manoharan 			"LNA1 + LNA2",
403e3d52914SSujith Manoharan 			as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
404e3d52914SSujith Manoharan 			as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
405e3d52914SSujith Manoharan 	len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
4064eba10ccSSujith Manoharan 			"LNA1 - LNA2",
407e3d52914SSujith Manoharan 			as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
408e3d52914SSujith Manoharan 			as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
409e3d52914SSujith Manoharan 
410e3d52914SSujith Manoharan 	len += snprintf(buf + len, size - len, "\nLNA Config Attempts:\n");
411e3d52914SSujith Manoharan 	len += snprintf(buf + len, size - len, "--------------------\n");
412e3d52914SSujith Manoharan 
413e3d52914SSujith Manoharan 	len += snprintf(buf + len, size - len, "%30s%15s\n",
414e3d52914SSujith Manoharan 			"MAIN", "ALT");
415e3d52914SSujith Manoharan 	len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
416e3d52914SSujith Manoharan 			"LNA1",
417e3d52914SSujith Manoharan 			as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1],
418e3d52914SSujith Manoharan 			as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1]);
419e3d52914SSujith Manoharan 	len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
420e3d52914SSujith Manoharan 			"LNA2",
421e3d52914SSujith Manoharan 			as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2],
422e3d52914SSujith Manoharan 			as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2]);
423e3d52914SSujith Manoharan 	len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
424e3d52914SSujith Manoharan 			"LNA1 + LNA2",
425e3d52914SSujith Manoharan 			as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
426e3d52914SSujith Manoharan 			as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
427e3d52914SSujith Manoharan 	len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
428e3d52914SSujith Manoharan 			"LNA1 - LNA2",
429e3d52914SSujith Manoharan 			as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
430e3d52914SSujith Manoharan 			as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
431e3d52914SSujith Manoharan 
4324eba10ccSSujith Manoharan exit:
4334eba10ccSSujith Manoharan 	if (len > size)
4344eba10ccSSujith Manoharan 		len = size;
4354eba10ccSSujith Manoharan 
4364eba10ccSSujith Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
4374eba10ccSSujith Manoharan 	kfree(buf);
4384eba10ccSSujith Manoharan 
4394eba10ccSSujith Manoharan 	return retval;
4404eba10ccSSujith Manoharan }
4414eba10ccSSujith Manoharan 
4424eba10ccSSujith Manoharan static const struct file_operations fops_antenna_diversity = {
4434eba10ccSSujith Manoharan 	.read = read_file_antenna_diversity,
4444eba10ccSSujith Manoharan 	.open = simple_open,
4454eba10ccSSujith Manoharan 	.owner = THIS_MODULE,
4464eba10ccSSujith Manoharan 	.llseek = default_llseek,
4474eba10ccSSujith Manoharan };
4484eba10ccSSujith Manoharan 
449203c4805SLuis R. Rodriguez static ssize_t read_file_dma(struct file *file, char __user *user_buf,
450203c4805SLuis R. Rodriguez 			     size_t count, loff_t *ppos)
451203c4805SLuis R. Rodriguez {
452203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
453203c4805SLuis R. Rodriguez 	struct ath_hw *ah = sc->sc_ah;
454991a0987SPavel Roskin 	char *buf;
455991a0987SPavel Roskin 	int retval;
456203c4805SLuis R. Rodriguez 	unsigned int len = 0;
457203c4805SLuis R. Rodriguez 	u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
458203c4805SLuis R. Rodriguez 	int i, qcuOffset = 0, dcuOffset = 0;
459203c4805SLuis R. Rodriguez 	u32 *qcuBase = &val[0], *dcuBase = &val[4];
460203c4805SLuis R. Rodriguez 
461991a0987SPavel Roskin 	buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
462991a0987SPavel Roskin 	if (!buf)
46304236066SDan Carpenter 		return -ENOMEM;
464991a0987SPavel Roskin 
4657cf4a2e7SSujith 	ath9k_ps_wakeup(sc);
4667cf4a2e7SSujith 
467475a6e4dSLuis R. Rodriguez 	REG_WRITE_D(ah, AR_MACMISC,
468203c4805SLuis R. Rodriguez 		  ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
469203c4805SLuis R. Rodriguez 		   (AR_MACMISC_MISC_OBS_BUS_1 <<
470203c4805SLuis R. Rodriguez 		    AR_MACMISC_MISC_OBS_BUS_MSB_S)));
471203c4805SLuis R. Rodriguez 
472991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
473203c4805SLuis R. Rodriguez 			"Raw DMA Debug values:\n");
474203c4805SLuis R. Rodriguez 
475203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
476203c4805SLuis R. Rodriguez 		if (i % 4 == 0)
477991a0987SPavel Roskin 			len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
478203c4805SLuis R. Rodriguez 
479475a6e4dSLuis R. Rodriguez 		val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
480991a0987SPavel Roskin 		len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
481203c4805SLuis R. Rodriguez 				i, val[i]);
482203c4805SLuis R. Rodriguez 	}
483203c4805SLuis R. Rodriguez 
484991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
485991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
486203c4805SLuis R. Rodriguez 			"Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
487203c4805SLuis R. Rodriguez 
488203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
489203c4805SLuis R. Rodriguez 		if (i == 8) {
490203c4805SLuis R. Rodriguez 			qcuOffset = 0;
491203c4805SLuis R. Rodriguez 			qcuBase++;
492203c4805SLuis R. Rodriguez 		}
493203c4805SLuis R. Rodriguez 
494203c4805SLuis R. Rodriguez 		if (i == 6) {
495203c4805SLuis R. Rodriguez 			dcuOffset = 0;
496203c4805SLuis R. Rodriguez 			dcuBase++;
497203c4805SLuis R. Rodriguez 		}
498203c4805SLuis R. Rodriguez 
499991a0987SPavel Roskin 		len += snprintf(buf + len, DMA_BUF_LEN - len,
500203c4805SLuis R. Rodriguez 			"%2d          %2x      %1x     %2x           %2x\n",
501203c4805SLuis R. Rodriguez 			i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
502203c4805SLuis R. Rodriguez 			(*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
503203c4805SLuis R. Rodriguez 			val[2] & (0x7 << (i * 3)) >> (i * 3),
504203c4805SLuis R. Rodriguez 			(*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
505203c4805SLuis R. Rodriguez 	}
506203c4805SLuis R. Rodriguez 
507991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
508203c4805SLuis R. Rodriguez 
509991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
510203c4805SLuis R. Rodriguez 		"qcu_stitch state:   %2x    qcu_fetch state:        %2x\n",
511203c4805SLuis R. Rodriguez 		(val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
512991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
513203c4805SLuis R. Rodriguez 		"qcu_complete state: %2x    dcu_complete state:     %2x\n",
514203c4805SLuis R. Rodriguez 		(val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
515991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
516203c4805SLuis R. Rodriguez 		"dcu_arb state:      %2x    dcu_fp state:           %2x\n",
517203c4805SLuis R. Rodriguez 		(val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
518991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
519203c4805SLuis R. Rodriguez 		"chan_idle_dur:     %3d    chan_idle_dur_valid:     %1d\n",
520203c4805SLuis R. Rodriguez 		(val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
521991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
522203c4805SLuis R. Rodriguez 		"txfifo_valid_0:      %1d    txfifo_valid_1:          %1d\n",
523203c4805SLuis R. Rodriguez 		(val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
524991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
525203c4805SLuis R. Rodriguez 		"txfifo_dcu_num_0:   %2d    txfifo_dcu_num_1:       %2d\n",
526203c4805SLuis R. Rodriguez 		(val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
527203c4805SLuis R. Rodriguez 
528991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
529475a6e4dSLuis R. Rodriguez 			REG_READ_D(ah, AR_OBS_BUS_1));
530991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
531475a6e4dSLuis R. Rodriguez 			"AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
532203c4805SLuis R. Rodriguez 
5337cf4a2e7SSujith 	ath9k_ps_restore(sc);
5347cf4a2e7SSujith 
5352b87f3aaSDan Carpenter 	if (len > DMA_BUF_LEN)
5362b87f3aaSDan Carpenter 		len = DMA_BUF_LEN;
5372b87f3aaSDan Carpenter 
538991a0987SPavel Roskin 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
539991a0987SPavel Roskin 	kfree(buf);
540991a0987SPavel Roskin 	return retval;
541203c4805SLuis R. Rodriguez }
542203c4805SLuis R. Rodriguez 
543203c4805SLuis R. Rodriguez static const struct file_operations fops_dma = {
544203c4805SLuis R. Rodriguez 	.read = read_file_dma,
545234e3405SStephen Boyd 	.open = simple_open,
5466038f373SArnd Bergmann 	.owner = THIS_MODULE,
5476038f373SArnd Bergmann 	.llseek = default_llseek,
548203c4805SLuis R. Rodriguez };
549203c4805SLuis R. Rodriguez 
550203c4805SLuis R. Rodriguez 
551203c4805SLuis R. Rodriguez void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
552203c4805SLuis R. Rodriguez {
553203c4805SLuis R. Rodriguez 	if (status)
554203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.total++;
555a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
556a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXLP)
557a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxlp++;
558a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXHP)
559a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxhp++;
56008578b8fSLuis R. Rodriguez 		if (status & ATH9K_INT_BB_WATCHDOG)
56108578b8fSLuis R. Rodriguez 			sc->debug.stats.istats.bb_watchdog++;
562a9616f41SLuis R. Rodriguez 	} else {
563203c4805SLuis R. Rodriguez 		if (status & ATH9K_INT_RX)
564203c4805SLuis R. Rodriguez 			sc->debug.stats.istats.rxok++;
565a9616f41SLuis R. Rodriguez 	}
566203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXEOL)
567203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxeol++;
568203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXORN)
569203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxorn++;
570203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TX)
571203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txok++;
572203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TXURN)
573203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txurn++;
574203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXPHY)
575203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxphyerr++;
576203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXKCM)
577203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rx_keycache_miss++;
578203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_SWBA)
579203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.swba++;
580203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BMISS)
581203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bmiss++;
582203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BNR)
583203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bnr++;
584203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CST)
585203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cst++;
586203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_GTT)
587203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.gtt++;
588203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TIM)
589203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.tim++;
590203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CABEND)
591203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cabend++;
592203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIMSYNC)
593203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtimsync++;
594203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIM)
595203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtim++;
5966dde1aabSMohammed Shafi Shajakhan 	if (status & ATH9K_INT_TSFOOR)
5976dde1aabSMohammed Shafi Shajakhan 		sc->debug.stats.istats.tsfoor++;
59897ba515aSSujith Manoharan 	if (status & ATH9K_INT_MCI)
59997ba515aSSujith Manoharan 		sc->debug.stats.istats.mci++;
600c9e6e980SMohammed Shafi Shajakhan 	if (status & ATH9K_INT_GENTIMER)
601c9e6e980SMohammed Shafi Shajakhan 		sc->debug.stats.istats.gen_timer++;
602203c4805SLuis R. Rodriguez }
603203c4805SLuis R. Rodriguez 
604203c4805SLuis R. Rodriguez static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
605203c4805SLuis R. Rodriguez 				   size_t count, loff_t *ppos)
606203c4805SLuis R. Rodriguez {
607203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
608203c4805SLuis R. Rodriguez 	unsigned int len = 0;
609462e58f2SBen Greear 	int rv;
610462e58f2SBen Greear 	int mxlen = 4000;
611462e58f2SBen Greear 	char *buf = kmalloc(mxlen, GFP_KERNEL);
612462e58f2SBen Greear 	if (!buf)
613462e58f2SBen Greear 		return -ENOMEM;
614462e58f2SBen Greear 
615462e58f2SBen Greear #define PR_IS(a, s)						\
616462e58f2SBen Greear 	do {							\
617462e58f2SBen Greear 		len += snprintf(buf + len, mxlen - len,		\
618462e58f2SBen Greear 				"%21s: %10u\n", a,		\
619462e58f2SBen Greear 				sc->debug.stats.istats.s);	\
620462e58f2SBen Greear 	} while (0)
621203c4805SLuis R. Rodriguez 
622a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
623462e58f2SBen Greear 		PR_IS("RXLP", rxlp);
624462e58f2SBen Greear 		PR_IS("RXHP", rxhp);
625462e58f2SBen Greear 		PR_IS("WATHDOG", bb_watchdog);
626a9616f41SLuis R. Rodriguez 	} else {
627462e58f2SBen Greear 		PR_IS("RX", rxok);
628a9616f41SLuis R. Rodriguez 	}
629462e58f2SBen Greear 	PR_IS("RXEOL", rxeol);
630462e58f2SBen Greear 	PR_IS("RXORN", rxorn);
631462e58f2SBen Greear 	PR_IS("TX", txok);
632462e58f2SBen Greear 	PR_IS("TXURN", txurn);
633462e58f2SBen Greear 	PR_IS("MIB", mib);
634462e58f2SBen Greear 	PR_IS("RXPHY", rxphyerr);
635462e58f2SBen Greear 	PR_IS("RXKCM", rx_keycache_miss);
636462e58f2SBen Greear 	PR_IS("SWBA", swba);
637462e58f2SBen Greear 	PR_IS("BMISS", bmiss);
638462e58f2SBen Greear 	PR_IS("BNR", bnr);
639462e58f2SBen Greear 	PR_IS("CST", cst);
640462e58f2SBen Greear 	PR_IS("GTT", gtt);
641462e58f2SBen Greear 	PR_IS("TIM", tim);
642462e58f2SBen Greear 	PR_IS("CABEND", cabend);
643462e58f2SBen Greear 	PR_IS("DTIMSYNC", dtimsync);
644462e58f2SBen Greear 	PR_IS("DTIM", dtim);
645462e58f2SBen Greear 	PR_IS("TSFOOR", tsfoor);
64697ba515aSSujith Manoharan 	PR_IS("MCI", mci);
647c9e6e980SMohammed Shafi Shajakhan 	PR_IS("GENTIMER", gen_timer);
648462e58f2SBen Greear 	PR_IS("TOTAL", total);
649203c4805SLuis R. Rodriguez 
650462e58f2SBen Greear 	len += snprintf(buf + len, mxlen - len,
651462e58f2SBen Greear 			"SYNC_CAUSE stats:\n");
6526dde1aabSMohammed Shafi Shajakhan 
653462e58f2SBen Greear 	PR_IS("Sync-All", sync_cause_all);
654462e58f2SBen Greear 	PR_IS("RTC-IRQ", sync_rtc_irq);
655462e58f2SBen Greear 	PR_IS("MAC-IRQ", sync_mac_irq);
656462e58f2SBen Greear 	PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
657462e58f2SBen Greear 	PR_IS("APB-Timeout", apb_timeout);
658462e58f2SBen Greear 	PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
659462e58f2SBen Greear 	PR_IS("HOST1-Fatal", host1_fatal);
660462e58f2SBen Greear 	PR_IS("HOST1-Perr", host1_perr);
661462e58f2SBen Greear 	PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
662462e58f2SBen Greear 	PR_IS("RADM-CPL-EP", radm_cpl_ep);
663462e58f2SBen Greear 	PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
664462e58f2SBen Greear 	PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
665462e58f2SBen Greear 	PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
666462e58f2SBen Greear 	PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
667462e58f2SBen Greear 	PR_IS("Local-Bus-Timeout", local_timeout);
668462e58f2SBen Greear 	PR_IS("PM-Access", pm_access);
669462e58f2SBen Greear 	PR_IS("MAC-Awake", mac_awake);
670462e58f2SBen Greear 	PR_IS("MAC-Asleep", mac_asleep);
671462e58f2SBen Greear 	PR_IS("MAC-Sleep-Access", mac_sleep_access);
6722b87f3aaSDan Carpenter 
673462e58f2SBen Greear 	if (len > mxlen)
674462e58f2SBen Greear 		len = mxlen;
675462e58f2SBen Greear 
676462e58f2SBen Greear 	rv = simple_read_from_buffer(user_buf, count, ppos, buf, len);
677462e58f2SBen Greear 	kfree(buf);
678462e58f2SBen Greear 	return rv;
679203c4805SLuis R. Rodriguez }
680203c4805SLuis R. Rodriguez 
681203c4805SLuis R. Rodriguez static const struct file_operations fops_interrupt = {
682203c4805SLuis R. Rodriguez 	.read = read_file_interrupt,
683234e3405SStephen Boyd 	.open = simple_open,
6846038f373SArnd Bergmann 	.owner = THIS_MODULE,
6856038f373SArnd Bergmann 	.llseek = default_llseek,
686203c4805SLuis R. Rodriguez };
687203c4805SLuis R. Rodriguez 
688fec247c0SSujith static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
689fec247c0SSujith 			      size_t count, loff_t *ppos)
690fec247c0SSujith {
691fec247c0SSujith 	struct ath_softc *sc = file->private_data;
692fec247c0SSujith 	char *buf;
69378ef731cSSujith Manoharan 	unsigned int len = 0, size = 2048;
694fec247c0SSujith 	ssize_t retval = 0;
695fec247c0SSujith 
696fec247c0SSujith 	buf = kzalloc(size, GFP_KERNEL);
697fec247c0SSujith 	if (buf == NULL)
69804236066SDan Carpenter 		return -ENOMEM;
699fec247c0SSujith 
70078ef731cSSujith Manoharan 	len += sprintf(buf, "%30s %10s%10s%10s\n\n",
7017f010c93SBen Greear 		       "BE", "BK", "VI", "VO");
702fec247c0SSujith 
703fec247c0SSujith 	PR("MPDUs Queued:    ", queued);
704fec247c0SSujith 	PR("MPDUs Completed: ", completed);
7055a6f78afSFelix Fietkau 	PR("MPDUs XRetried:  ", xretries);
706fec247c0SSujith 	PR("Aggregates:      ", a_aggr);
707bda8addaSBen Greear 	PR("AMPDUs Queued HW:", a_queued_hw);
708bda8addaSBen Greear 	PR("AMPDUs Queued SW:", a_queued_sw);
709fec247c0SSujith 	PR("AMPDUs Completed:", a_completed);
710fec247c0SSujith 	PR("AMPDUs Retried:  ", a_retries);
711fec247c0SSujith 	PR("AMPDUs XRetried: ", a_xretries);
7124d900389SBen Greear 	PR("TXERR Filtered:  ", txerr_filtered);
713fec247c0SSujith 	PR("FIFO Underrun:   ", fifo_underrun);
714fec247c0SSujith 	PR("TXOP Exceeded:   ", xtxop);
715fec247c0SSujith 	PR("TXTIMER Expiry:  ", timer_exp);
716fec247c0SSujith 	PR("DESC CFG Error:  ", desc_cfg_err);
717fec247c0SSujith 	PR("DATA Underrun:   ", data_underrun);
718fec247c0SSujith 	PR("DELIM Underrun:  ", delim_underrun);
71999c15bf5SBen Greear 	PR("TX-Pkts-All:     ", tx_pkts_all);
72099c15bf5SBen Greear 	PR("TX-Bytes-All:    ", tx_bytes_all);
72178ef731cSSujith Manoharan 	PR("HW-put-tx-buf:   ", puttxbuf);
72278ef731cSSujith Manoharan 	PR("HW-tx-start:     ", txstart);
72378ef731cSSujith Manoharan 	PR("HW-tx-proc-desc: ", txprocdesc);
724a5a0bca1SBen Greear 	PR("TX-Failed:       ", txfailed);
725fec247c0SSujith 
7267f010c93SBen Greear 	if (len > size)
7277f010c93SBen Greear 		len = size;
7287f010c93SBen Greear 
7297f010c93SBen Greear 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
7307f010c93SBen Greear 	kfree(buf);
7317f010c93SBen Greear 
7327f010c93SBen Greear 	return retval;
7337f010c93SBen Greear }
7347f010c93SBen Greear 
735*18fcf1c6SFelix Fietkau static ssize_t print_queue(struct ath_softc *sc, struct ath_txq *txq,
736*18fcf1c6SFelix Fietkau 			   char *buf, ssize_t size)
737*18fcf1c6SFelix Fietkau {
738*18fcf1c6SFelix Fietkau 	ssize_t len = 0;
739*18fcf1c6SFelix Fietkau 
740*18fcf1c6SFelix Fietkau 	ath_txq_lock(sc, txq);
741*18fcf1c6SFelix Fietkau 
742*18fcf1c6SFelix Fietkau 	len += snprintf(buf + len, size - len, "%s: %d ",
743*18fcf1c6SFelix Fietkau 			"qnum", txq->axq_qnum);
744*18fcf1c6SFelix Fietkau 	len += snprintf(buf + len, size - len, "%s: %2d ",
745*18fcf1c6SFelix Fietkau 			"qdepth", txq->axq_depth);
746*18fcf1c6SFelix Fietkau 	len += snprintf(buf + len, size - len, "%s: %2d ",
747*18fcf1c6SFelix Fietkau 			"ampdu-depth", txq->axq_ampdu_depth);
748*18fcf1c6SFelix Fietkau 	len += snprintf(buf + len, size - len, "%s: %3d ",
749*18fcf1c6SFelix Fietkau 			"pending", txq->pending_frames);
750*18fcf1c6SFelix Fietkau 	len += snprintf(buf + len, size - len, "%s: %d\n",
751*18fcf1c6SFelix Fietkau 			"stopped", txq->stopped);
752*18fcf1c6SFelix Fietkau 
753*18fcf1c6SFelix Fietkau 	ath_txq_unlock(sc, txq);
754*18fcf1c6SFelix Fietkau 	return len;
755*18fcf1c6SFelix Fietkau }
756*18fcf1c6SFelix Fietkau 
757c0b74876SSujith Manoharan static ssize_t read_file_queues(struct file *file, char __user *user_buf,
758c0b74876SSujith Manoharan 				size_t count, loff_t *ppos)
759c0b74876SSujith Manoharan {
760c0b74876SSujith Manoharan 	struct ath_softc *sc = file->private_data;
761c0b74876SSujith Manoharan 	struct ath_txq *txq;
762c0b74876SSujith Manoharan 	char *buf;
763c0b74876SSujith Manoharan 	unsigned int len = 0, size = 1024;
764c0b74876SSujith Manoharan 	ssize_t retval = 0;
765c0b74876SSujith Manoharan 	int i;
766c0b74876SSujith Manoharan 	char *qname[4] = {"VO", "VI", "BE", "BK"};
767c0b74876SSujith Manoharan 
768c0b74876SSujith Manoharan 	buf = kzalloc(size, GFP_KERNEL);
769c0b74876SSujith Manoharan 	if (buf == NULL)
770c0b74876SSujith Manoharan 		return -ENOMEM;
771c0b74876SSujith Manoharan 
772c0b74876SSujith Manoharan 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
773c0b74876SSujith Manoharan 		txq = sc->tx.txq_map[i];
774c0b74876SSujith Manoharan 		len += snprintf(buf + len, size - len, "(%s):  ", qname[i]);
775*18fcf1c6SFelix Fietkau 		len += print_queue(sc, txq, buf + len, size - len);
776c0b74876SSujith Manoharan 	}
777c0b74876SSujith Manoharan 
778*18fcf1c6SFelix Fietkau 	len += snprintf(buf + len, size - len, "(CAB): ");
779*18fcf1c6SFelix Fietkau 	len += print_queue(sc, sc->beacon.cabq, buf + len, size - len);
780*18fcf1c6SFelix Fietkau 
781c0b74876SSujith Manoharan 	if (len > size)
782c0b74876SSujith Manoharan 		len = size;
783c0b74876SSujith Manoharan 
784c0b74876SSujith Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
785c0b74876SSujith Manoharan 	kfree(buf);
786c0b74876SSujith Manoharan 
787c0b74876SSujith Manoharan 	return retval;
788c0b74876SSujith Manoharan }
789c0b74876SSujith Manoharan 
79055f6d0ffSBen Greear static ssize_t read_file_misc(struct file *file, char __user *user_buf,
79155f6d0ffSBen Greear 			      size_t count, loff_t *ppos)
79255f6d0ffSBen Greear {
79355f6d0ffSBen Greear 	struct ath_softc *sc = file->private_data;
79455f6d0ffSBen Greear 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
79555f6d0ffSBen Greear 	struct ieee80211_hw *hw = sc->hw;
7966bcf6f64SSujith Manoharan 	struct ath9k_vif_iter_data iter_data;
7976bcf6f64SSujith Manoharan 	char buf[512];
7986bcf6f64SSujith Manoharan 	unsigned int len = 0;
79955f6d0ffSBen Greear 	ssize_t retval = 0;
80055f6d0ffSBen Greear 	unsigned int reg;
8016bcf6f64SSujith Manoharan 	u32 rxfilter;
8026bcf6f64SSujith Manoharan 
8036bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
8046bcf6f64SSujith Manoharan 			"BSSID: %pM\n", common->curbssid);
8056bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
8066bcf6f64SSujith Manoharan 			"BSSID-MASK: %pM\n", common->bssidmask);
8076bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
8086bcf6f64SSujith Manoharan 			"OPMODE: %s\n", ath_opmode_to_string(sc->sc_ah->opmode));
8096bcf6f64SSujith Manoharan 
8106bcf6f64SSujith Manoharan 	ath9k_ps_wakeup(sc);
8116bcf6f64SSujith Manoharan 	rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
8126bcf6f64SSujith Manoharan 	ath9k_ps_restore(sc);
8136bcf6f64SSujith Manoharan 
8146bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
8156bcf6f64SSujith Manoharan 			"RXFILTER: 0x%x", rxfilter);
8166bcf6f64SSujith Manoharan 
8176bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_UCAST)
8186bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " UCAST");
8196bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MCAST)
8206bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " MCAST");
8216bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_BCAST)
8226bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " BCAST");
8236bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_CONTROL)
8246bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " CONTROL");
8256bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_BEACON)
8266bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " BEACON");
8276bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PROM)
8286bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " PROM");
8296bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
8306bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
8316bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PHYERR)
8326bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " PHYERR");
8336bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
8346bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " MYBEACON");
8356bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
8366bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
8376bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
8386bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " PSPOLL");
8396bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
8406bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
8416bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
8426bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL");
8436bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
8446bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " CONTROL_WRAPPER");
8456bcf6f64SSujith Manoharan 
8466bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len, "\n");
8476bcf6f64SSujith Manoharan 
8486bcf6f64SSujith Manoharan 	reg = sc->sc_ah->imask;
8496bcf6f64SSujith Manoharan 
8506bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len, "INTERRUPT-MASK: 0x%x", reg);
8516bcf6f64SSujith Manoharan 
8526bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_SWBA)
8536bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " SWBA");
8546bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_BMISS)
8556bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " BMISS");
8566bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_CST)
8576bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " CST");
8586bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RX)
8596bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " RX");
8606bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RXHP)
8616bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " RXHP");
8626bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RXLP)
8636bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " RXLP");
8646bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_BB_WATCHDOG)
8656bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " BB_WATCHDOG");
8666bcf6f64SSujith Manoharan 
8676bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len, "\n");
86855f6d0ffSBen Greear 
86955f6d0ffSBen Greear 	ath9k_calculate_iter_data(hw, NULL, &iter_data);
87055f6d0ffSBen Greear 
8716bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
8726bcf6f64SSujith Manoharan 			"VIF-COUNTS: AP: %i STA: %i MESH: %i WDS: %i"
873bcf6f96eSSujith Manoharan 			" ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n",
87455f6d0ffSBen Greear 			iter_data.naps, iter_data.nstations, iter_data.nmeshes,
875bcf6f96eSSujith Manoharan 			iter_data.nwds, iter_data.nadhocs,
87655f6d0ffSBen Greear 			sc->nvifs, sc->nbcnvifs);
87755f6d0ffSBen Greear 
8786bcf6f64SSujith Manoharan 	if (len > sizeof(buf))
8796bcf6f64SSujith Manoharan 		len = sizeof(buf);
88055f6d0ffSBen Greear 
88155f6d0ffSBen Greear 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
88255f6d0ffSBen Greear 	return retval;
88355f6d0ffSBen Greear }
88455f6d0ffSBen Greear 
885f8b815dcSSujith Manoharan static ssize_t read_file_reset(struct file *file, char __user *user_buf,
886f8b815dcSSujith Manoharan 			       size_t count, loff_t *ppos)
887f8b815dcSSujith Manoharan {
888f8b815dcSSujith Manoharan 	struct ath_softc *sc = file->private_data;
889f8b815dcSSujith Manoharan 	char buf[512];
890f8b815dcSSujith Manoharan 	unsigned int len = 0;
891f8b815dcSSujith Manoharan 
892f8b815dcSSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
893f8b815dcSSujith Manoharan 			"%17s: %2d\n", "Baseband Hang",
894f8b815dcSSujith Manoharan 			sc->debug.stats.reset[RESET_TYPE_BB_HANG]);
895f8b815dcSSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
896f8b815dcSSujith Manoharan 			"%17s: %2d\n", "Baseband Watchdog",
897f8b815dcSSujith Manoharan 			sc->debug.stats.reset[RESET_TYPE_BB_WATCHDOG]);
898f8b815dcSSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
899f8b815dcSSujith Manoharan 			"%17s: %2d\n", "Fatal HW Error",
900f8b815dcSSujith Manoharan 			sc->debug.stats.reset[RESET_TYPE_FATAL_INT]);
901f8b815dcSSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
902f8b815dcSSujith Manoharan 			"%17s: %2d\n", "TX HW error",
903f8b815dcSSujith Manoharan 			sc->debug.stats.reset[RESET_TYPE_TX_ERROR]);
904f8b815dcSSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
905f8b815dcSSujith Manoharan 			"%17s: %2d\n", "TX Path Hang",
906f8b815dcSSujith Manoharan 			sc->debug.stats.reset[RESET_TYPE_TX_HANG]);
907f8b815dcSSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
908f8b815dcSSujith Manoharan 			"%17s: %2d\n", "PLL RX Hang",
909f8b815dcSSujith Manoharan 			sc->debug.stats.reset[RESET_TYPE_PLL_HANG]);
910b88083bfSRajkumar Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
911b88083bfSRajkumar Manoharan 			"%17s: %2d\n", "MCI Reset",
912b88083bfSRajkumar Manoharan 			sc->debug.stats.reset[RESET_TYPE_MCI]);
913f8b815dcSSujith Manoharan 
914f8b815dcSSujith Manoharan 	if (len > sizeof(buf))
915f8b815dcSSujith Manoharan 		len = sizeof(buf);
916f8b815dcSSujith Manoharan 
917f8b815dcSSujith Manoharan 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
918f8b815dcSSujith Manoharan }
919f8b815dcSSujith Manoharan 
920066dae93SFelix Fietkau void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
92155797b1aSFelix Fietkau 		       struct ath_tx_status *ts, struct ath_txq *txq,
92255797b1aSFelix Fietkau 		       unsigned int flags)
923fec247c0SSujith {
9245bec3e5aSFelix Fietkau 	int qnum = txq->axq_qnum;
925066dae93SFelix Fietkau 
926066dae93SFelix Fietkau 	TX_STAT_INC(qnum, tx_pkts_all);
927066dae93SFelix Fietkau 	sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
92899c15bf5SBen Greear 
929fec247c0SSujith 	if (bf_isampdu(bf)) {
930156369faSFelix Fietkau 		if (flags & ATH_TX_ERROR)
931066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_xretries);
932fec247c0SSujith 		else
933066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_completed);
934fec247c0SSujith 	} else {
93555797b1aSFelix Fietkau 		if (ts->ts_status & ATH9K_TXERR_XRETRY)
9365a6f78afSFelix Fietkau 			TX_STAT_INC(qnum, xretries);
9375a6f78afSFelix Fietkau 		else
938066dae93SFelix Fietkau 			TX_STAT_INC(qnum, completed);
939fec247c0SSujith 	}
940fec247c0SSujith 
9414d900389SBen Greear 	if (ts->ts_status & ATH9K_TXERR_FILT)
9424d900389SBen Greear 		TX_STAT_INC(qnum, txerr_filtered);
943db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_FIFO)
944066dae93SFelix Fietkau 		TX_STAT_INC(qnum, fifo_underrun);
945db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_XTXOP)
946066dae93SFelix Fietkau 		TX_STAT_INC(qnum, xtxop);
947db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
948066dae93SFelix Fietkau 		TX_STAT_INC(qnum, timer_exp);
949db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
950066dae93SFelix Fietkau 		TX_STAT_INC(qnum, desc_cfg_err);
951db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
952066dae93SFelix Fietkau 		TX_STAT_INC(qnum, data_underrun);
953db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
954066dae93SFelix Fietkau 		TX_STAT_INC(qnum, delim_underrun);
955fec247c0SSujith }
956fec247c0SSujith 
957fec247c0SSujith static const struct file_operations fops_xmit = {
958fec247c0SSujith 	.read = read_file_xmit,
959234e3405SStephen Boyd 	.open = simple_open,
9606038f373SArnd Bergmann 	.owner = THIS_MODULE,
9616038f373SArnd Bergmann 	.llseek = default_llseek,
962fec247c0SSujith };
963203c4805SLuis R. Rodriguez 
964c0b74876SSujith Manoharan static const struct file_operations fops_queues = {
965c0b74876SSujith Manoharan 	.read = read_file_queues,
966c0b74876SSujith Manoharan 	.open = simple_open,
967c0b74876SSujith Manoharan 	.owner = THIS_MODULE,
968c0b74876SSujith Manoharan 	.llseek = default_llseek,
969c0b74876SSujith Manoharan };
970c0b74876SSujith Manoharan 
97155f6d0ffSBen Greear static const struct file_operations fops_misc = {
97255f6d0ffSBen Greear 	.read = read_file_misc,
973234e3405SStephen Boyd 	.open = simple_open,
97455f6d0ffSBen Greear 	.owner = THIS_MODULE,
97555f6d0ffSBen Greear 	.llseek = default_llseek,
97655f6d0ffSBen Greear };
97755f6d0ffSBen Greear 
978f8b815dcSSujith Manoharan static const struct file_operations fops_reset = {
979f8b815dcSSujith Manoharan 	.read = read_file_reset,
980234e3405SStephen Boyd 	.open = simple_open,
981f8b815dcSSujith Manoharan 	.owner = THIS_MODULE,
982f8b815dcSSujith Manoharan 	.llseek = default_llseek,
983f8b815dcSSujith Manoharan };
984f8b815dcSSujith Manoharan 
9851395d3f0SSujith static ssize_t read_file_recv(struct file *file, char __user *user_buf,
9861395d3f0SSujith 			      size_t count, loff_t *ppos)
9871395d3f0SSujith {
9881395d3f0SSujith #define PHY_ERR(s, p) \
9894203214eSSujith Manoharan 	len += snprintf(buf + len, size - len, "%22s : %10u\n", s, \
9901395d3f0SSujith 			sc->debug.stats.rxstats.phy_err_stats[p]);
9911395d3f0SSujith 
99224a0731eSBen Greear #define RXS_ERR(s, e)					    \
99324a0731eSBen Greear 	do {						    \
99424a0731eSBen Greear 		len += snprintf(buf + len, size - len,	    \
99524a0731eSBen Greear 				"%22s : %10u\n", s,	    \
99624a0731eSBen Greear 				sc->debug.stats.rxstats.e); \
99724a0731eSBen Greear 	} while (0)
99824a0731eSBen Greear 
9991395d3f0SSujith 	struct ath_softc *sc = file->private_data;
10001395d3f0SSujith 	char *buf;
10014203214eSSujith Manoharan 	unsigned int len = 0, size = 1600;
10021395d3f0SSujith 	ssize_t retval = 0;
10031395d3f0SSujith 
10041395d3f0SSujith 	buf = kzalloc(size, GFP_KERNEL);
10051395d3f0SSujith 	if (buf == NULL)
100604236066SDan Carpenter 		return -ENOMEM;
10071395d3f0SSujith 
100824a0731eSBen Greear 	RXS_ERR("CRC ERR", crc_err);
100924a0731eSBen Greear 	RXS_ERR("DECRYPT CRC ERR", decrypt_crc_err);
101024a0731eSBen Greear 	RXS_ERR("PHY ERR", phy_err);
101124a0731eSBen Greear 	RXS_ERR("MIC ERR", mic_err);
101224a0731eSBen Greear 	RXS_ERR("PRE-DELIM CRC ERR", pre_delim_crc_err);
101324a0731eSBen Greear 	RXS_ERR("POST-DELIM CRC ERR", post_delim_crc_err);
101424a0731eSBen Greear 	RXS_ERR("DECRYPT BUSY ERR", decrypt_busy_err);
101524a0731eSBen Greear 	RXS_ERR("RX-LENGTH-ERR", rx_len_err);
101624a0731eSBen Greear 	RXS_ERR("RX-OOM-ERR", rx_oom_err);
101724a0731eSBen Greear 	RXS_ERR("RX-RATE-ERR", rx_rate_err);
101824a0731eSBen Greear 	RXS_ERR("RX-TOO-MANY-FRAGS", rx_too_many_frags_err);
10191395d3f0SSujith 
10204203214eSSujith Manoharan 	PHY_ERR("UNDERRUN ERR", ATH9K_PHYERR_UNDERRUN);
10214203214eSSujith Manoharan 	PHY_ERR("TIMING ERR", ATH9K_PHYERR_TIMING);
10224203214eSSujith Manoharan 	PHY_ERR("PARITY ERR", ATH9K_PHYERR_PARITY);
10234203214eSSujith Manoharan 	PHY_ERR("RATE ERR", ATH9K_PHYERR_RATE);
10244203214eSSujith Manoharan 	PHY_ERR("LENGTH ERR", ATH9K_PHYERR_LENGTH);
10254203214eSSujith Manoharan 	PHY_ERR("RADAR ERR", ATH9K_PHYERR_RADAR);
10264203214eSSujith Manoharan 	PHY_ERR("SERVICE ERR", ATH9K_PHYERR_SERVICE);
10274203214eSSujith Manoharan 	PHY_ERR("TOR ERR", ATH9K_PHYERR_TOR);
10284203214eSSujith Manoharan 	PHY_ERR("OFDM-TIMING ERR", ATH9K_PHYERR_OFDM_TIMING);
10294203214eSSujith Manoharan 	PHY_ERR("OFDM-SIGNAL-PARITY ERR", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
10304203214eSSujith Manoharan 	PHY_ERR("OFDM-RATE ERR", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
10314203214eSSujith Manoharan 	PHY_ERR("OFDM-LENGTH ERR", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
10324203214eSSujith Manoharan 	PHY_ERR("OFDM-POWER-DROP ERR", ATH9K_PHYERR_OFDM_POWER_DROP);
10334203214eSSujith Manoharan 	PHY_ERR("OFDM-SERVICE ERR", ATH9K_PHYERR_OFDM_SERVICE);
10344203214eSSujith Manoharan 	PHY_ERR("OFDM-RESTART ERR", ATH9K_PHYERR_OFDM_RESTART);
10354203214eSSujith Manoharan 	PHY_ERR("FALSE-RADAR-EXT ERR", ATH9K_PHYERR_FALSE_RADAR_EXT);
10364203214eSSujith Manoharan 	PHY_ERR("CCK-TIMING ERR", ATH9K_PHYERR_CCK_TIMING);
10374203214eSSujith Manoharan 	PHY_ERR("CCK-HEADER-CRC ERR", ATH9K_PHYERR_CCK_HEADER_CRC);
10384203214eSSujith Manoharan 	PHY_ERR("CCK-RATE ERR", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
10394203214eSSujith Manoharan 	PHY_ERR("CCK-SERVICE ERR", ATH9K_PHYERR_CCK_SERVICE);
10404203214eSSujith Manoharan 	PHY_ERR("CCK-RESTART ERR", ATH9K_PHYERR_CCK_RESTART);
10414203214eSSujith Manoharan 	PHY_ERR("CCK-LENGTH ERR", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
10424203214eSSujith Manoharan 	PHY_ERR("CCK-POWER-DROP ERR", ATH9K_PHYERR_CCK_POWER_DROP);
10434203214eSSujith Manoharan 	PHY_ERR("HT-CRC ERR", ATH9K_PHYERR_HT_CRC_ERROR);
10444203214eSSujith Manoharan 	PHY_ERR("HT-LENGTH ERR", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
10454203214eSSujith Manoharan 	PHY_ERR("HT-RATE ERR", ATH9K_PHYERR_HT_RATE_ILLEGAL);
10464203214eSSujith Manoharan 
104724a0731eSBen Greear 	RXS_ERR("RX-Pkts-All", rx_pkts_all);
104824a0731eSBen Greear 	RXS_ERR("RX-Bytes-All", rx_bytes_all);
104924a0731eSBen Greear 	RXS_ERR("RX-Beacons", rx_beacons);
105024a0731eSBen Greear 	RXS_ERR("RX-Frags", rx_frags);
10519b99e665SSimon Wunderlich 	RXS_ERR("RX-Spectral", rx_spectral);
105299c15bf5SBen Greear 
10532b87f3aaSDan Carpenter 	if (len > size)
10542b87f3aaSDan Carpenter 		len = size;
10552b87f3aaSDan Carpenter 
10561395d3f0SSujith 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
10571395d3f0SSujith 	kfree(buf);
10581395d3f0SSujith 
10591395d3f0SSujith 	return retval;
10601395d3f0SSujith 
106124a0731eSBen Greear #undef RXS_ERR
10621395d3f0SSujith #undef PHY_ERR
10631395d3f0SSujith }
10641395d3f0SSujith 
10658e6f5aa2SFelix Fietkau void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
10661395d3f0SSujith {
10671395d3f0SSujith #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
10681395d3f0SSujith 
106999c15bf5SBen Greear 	RX_STAT_INC(rx_pkts_all);
107099c15bf5SBen Greear 	sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
107199c15bf5SBen Greear 
10728e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_CRC)
10731395d3f0SSujith 		RX_STAT_INC(crc_err);
10748e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_DECRYPT)
10751395d3f0SSujith 		RX_STAT_INC(decrypt_crc_err);
10768e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_MIC)
10771395d3f0SSujith 		RX_STAT_INC(mic_err);
10788e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
10791395d3f0SSujith 		RX_STAT_INC(pre_delim_crc_err);
10808e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
10811395d3f0SSujith 		RX_STAT_INC(post_delim_crc_err);
10828e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
10831395d3f0SSujith 		RX_STAT_INC(decrypt_busy_err);
10841395d3f0SSujith 
10858e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_PHY) {
10861395d3f0SSujith 		RX_STAT_INC(phy_err);
1087dbb07f00SSujith Manoharan 		if (rs->rs_phyerr < ATH9K_PHYERR_MAX)
1088dbb07f00SSujith Manoharan 			RX_PHY_ERR_INC(rs->rs_phyerr);
10891395d3f0SSujith 	}
10901395d3f0SSujith 
10911395d3f0SSujith #undef RX_PHY_ERR_INC
10921395d3f0SSujith }
10931395d3f0SSujith 
10941395d3f0SSujith static const struct file_operations fops_recv = {
10951395d3f0SSujith 	.read = read_file_recv,
1096234e3405SStephen Boyd 	.open = simple_open,
10976038f373SArnd Bergmann 	.owner = THIS_MODULE,
10986038f373SArnd Bergmann 	.llseek = default_llseek,
10991395d3f0SSujith };
11001395d3f0SSujith 
1101e93d083fSSimon Wunderlich static ssize_t read_file_spec_scan_ctl(struct file *file, char __user *user_buf,
1102e93d083fSSimon Wunderlich 				       size_t count, loff_t *ppos)
1103e93d083fSSimon Wunderlich {
1104e93d083fSSimon Wunderlich 	struct ath_softc *sc = file->private_data;
1105e93d083fSSimon Wunderlich 	char *mode = "";
1106e93d083fSSimon Wunderlich 	unsigned int len;
1107e93d083fSSimon Wunderlich 
1108e93d083fSSimon Wunderlich 	switch (sc->spectral_mode) {
1109e93d083fSSimon Wunderlich 	case SPECTRAL_DISABLED:
1110e93d083fSSimon Wunderlich 		mode = "disable";
1111e93d083fSSimon Wunderlich 		break;
1112e93d083fSSimon Wunderlich 	case SPECTRAL_BACKGROUND:
1113e93d083fSSimon Wunderlich 		mode = "background";
1114e93d083fSSimon Wunderlich 		break;
1115e93d083fSSimon Wunderlich 	case SPECTRAL_CHANSCAN:
1116e93d083fSSimon Wunderlich 		mode = "chanscan";
1117e93d083fSSimon Wunderlich 		break;
1118e93d083fSSimon Wunderlich 	case SPECTRAL_MANUAL:
1119e93d083fSSimon Wunderlich 		mode = "manual";
1120e93d083fSSimon Wunderlich 		break;
1121e93d083fSSimon Wunderlich 	}
1122e93d083fSSimon Wunderlich 	len = strlen(mode);
1123e93d083fSSimon Wunderlich 	return simple_read_from_buffer(user_buf, count, ppos, mode, len);
1124e93d083fSSimon Wunderlich }
1125e93d083fSSimon Wunderlich 
1126e93d083fSSimon Wunderlich static ssize_t write_file_spec_scan_ctl(struct file *file,
1127e93d083fSSimon Wunderlich 					const char __user *user_buf,
1128e93d083fSSimon Wunderlich 					size_t count, loff_t *ppos)
1129e93d083fSSimon Wunderlich {
1130e93d083fSSimon Wunderlich 	struct ath_softc *sc = file->private_data;
1131e93d083fSSimon Wunderlich 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1132e93d083fSSimon Wunderlich 	char buf[32];
1133e93d083fSSimon Wunderlich 	ssize_t len;
1134e93d083fSSimon Wunderlich 
1135e93d083fSSimon Wunderlich 	len = min(count, sizeof(buf) - 1);
1136e93d083fSSimon Wunderlich 	if (copy_from_user(buf, user_buf, len))
1137e93d083fSSimon Wunderlich 		return -EFAULT;
1138e93d083fSSimon Wunderlich 
1139e93d083fSSimon Wunderlich 	buf[len] = '\0';
1140e93d083fSSimon Wunderlich 
1141e93d083fSSimon Wunderlich 	if (strncmp("trigger", buf, 7) == 0) {
1142e93d083fSSimon Wunderlich 		ath9k_spectral_scan_trigger(sc->hw);
1143e93d083fSSimon Wunderlich 	} else if (strncmp("background", buf, 9) == 0) {
1144e93d083fSSimon Wunderlich 		ath9k_spectral_scan_config(sc->hw, SPECTRAL_BACKGROUND);
1145e93d083fSSimon Wunderlich 		ath_dbg(common, CONFIG, "spectral scan: background mode enabled\n");
1146e93d083fSSimon Wunderlich 	} else if (strncmp("chanscan", buf, 8) == 0) {
1147e93d083fSSimon Wunderlich 		ath9k_spectral_scan_config(sc->hw, SPECTRAL_CHANSCAN);
1148e93d083fSSimon Wunderlich 		ath_dbg(common, CONFIG, "spectral scan: channel scan mode enabled\n");
1149e93d083fSSimon Wunderlich 	} else if (strncmp("manual", buf, 6) == 0) {
1150e93d083fSSimon Wunderlich 		ath9k_spectral_scan_config(sc->hw, SPECTRAL_MANUAL);
1151e93d083fSSimon Wunderlich 		ath_dbg(common, CONFIG, "spectral scan: manual mode enabled\n");
1152e93d083fSSimon Wunderlich 	} else if (strncmp("disable", buf, 7) == 0) {
1153e93d083fSSimon Wunderlich 		ath9k_spectral_scan_config(sc->hw, SPECTRAL_DISABLED);
1154e93d083fSSimon Wunderlich 		ath_dbg(common, CONFIG, "spectral scan: disabled\n");
1155e93d083fSSimon Wunderlich 	} else {
1156e93d083fSSimon Wunderlich 		return -EINVAL;
1157e93d083fSSimon Wunderlich 	}
1158e93d083fSSimon Wunderlich 
1159e93d083fSSimon Wunderlich 	return count;
1160e93d083fSSimon Wunderlich }
1161e93d083fSSimon Wunderlich 
1162e93d083fSSimon Wunderlich static const struct file_operations fops_spec_scan_ctl = {
1163e93d083fSSimon Wunderlich 	.read = read_file_spec_scan_ctl,
1164e93d083fSSimon Wunderlich 	.write = write_file_spec_scan_ctl,
1165e93d083fSSimon Wunderlich 	.open = simple_open,
1166e93d083fSSimon Wunderlich 	.owner = THIS_MODULE,
1167e93d083fSSimon Wunderlich 	.llseek = default_llseek,
1168e93d083fSSimon Wunderlich };
1169e93d083fSSimon Wunderlich 
117004ccd4a1SSimon Wunderlich static ssize_t read_file_spectral_short_repeat(struct file *file,
117104ccd4a1SSimon Wunderlich 					       char __user *user_buf,
117204ccd4a1SSimon Wunderlich 					       size_t count, loff_t *ppos)
117304ccd4a1SSimon Wunderlich {
117404ccd4a1SSimon Wunderlich 	struct ath_softc *sc = file->private_data;
117504ccd4a1SSimon Wunderlich 	char buf[32];
117604ccd4a1SSimon Wunderlich 	unsigned int len;
117704ccd4a1SSimon Wunderlich 
117804ccd4a1SSimon Wunderlich 	len = sprintf(buf, "%d\n", sc->spec_config.short_repeat);
117904ccd4a1SSimon Wunderlich 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
118004ccd4a1SSimon Wunderlich }
118104ccd4a1SSimon Wunderlich 
118204ccd4a1SSimon Wunderlich static ssize_t write_file_spectral_short_repeat(struct file *file,
118304ccd4a1SSimon Wunderlich 						const char __user *user_buf,
118404ccd4a1SSimon Wunderlich 						size_t count, loff_t *ppos)
118504ccd4a1SSimon Wunderlich {
118604ccd4a1SSimon Wunderlich 	struct ath_softc *sc = file->private_data;
118704ccd4a1SSimon Wunderlich 	unsigned long val;
118804ccd4a1SSimon Wunderlich 	char buf[32];
118904ccd4a1SSimon Wunderlich 	ssize_t len;
119004ccd4a1SSimon Wunderlich 
119104ccd4a1SSimon Wunderlich 	len = min(count, sizeof(buf) - 1);
119204ccd4a1SSimon Wunderlich 	if (copy_from_user(buf, user_buf, len))
119304ccd4a1SSimon Wunderlich 		return -EFAULT;
119404ccd4a1SSimon Wunderlich 
119504ccd4a1SSimon Wunderlich 	buf[len] = '\0';
119604ccd4a1SSimon Wunderlich 	if (kstrtoul(buf, 0, &val))
119704ccd4a1SSimon Wunderlich 		return -EINVAL;
119804ccd4a1SSimon Wunderlich 
119904ccd4a1SSimon Wunderlich 	if (val < 0 || val > 1)
120004ccd4a1SSimon Wunderlich 		return -EINVAL;
120104ccd4a1SSimon Wunderlich 
120204ccd4a1SSimon Wunderlich 	sc->spec_config.short_repeat = val;
120304ccd4a1SSimon Wunderlich 	return count;
120404ccd4a1SSimon Wunderlich }
120504ccd4a1SSimon Wunderlich 
120604ccd4a1SSimon Wunderlich static const struct file_operations fops_spectral_short_repeat = {
120704ccd4a1SSimon Wunderlich 	.read = read_file_spectral_short_repeat,
120804ccd4a1SSimon Wunderlich 	.write = write_file_spectral_short_repeat,
120904ccd4a1SSimon Wunderlich 	.open = simple_open,
121004ccd4a1SSimon Wunderlich 	.owner = THIS_MODULE,
121104ccd4a1SSimon Wunderlich 	.llseek = default_llseek,
121204ccd4a1SSimon Wunderlich };
121304ccd4a1SSimon Wunderlich 
121404ccd4a1SSimon Wunderlich static ssize_t read_file_spectral_count(struct file *file,
121504ccd4a1SSimon Wunderlich 					char __user *user_buf,
121604ccd4a1SSimon Wunderlich 					size_t count, loff_t *ppos)
121704ccd4a1SSimon Wunderlich {
121804ccd4a1SSimon Wunderlich 	struct ath_softc *sc = file->private_data;
121904ccd4a1SSimon Wunderlich 	char buf[32];
122004ccd4a1SSimon Wunderlich 	unsigned int len;
122104ccd4a1SSimon Wunderlich 
122204ccd4a1SSimon Wunderlich 	len = sprintf(buf, "%d\n", sc->spec_config.count);
122304ccd4a1SSimon Wunderlich 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
122404ccd4a1SSimon Wunderlich }
122504ccd4a1SSimon Wunderlich 
122604ccd4a1SSimon Wunderlich static ssize_t write_file_spectral_count(struct file *file,
122704ccd4a1SSimon Wunderlich 					 const char __user *user_buf,
122804ccd4a1SSimon Wunderlich 					 size_t count, loff_t *ppos)
122904ccd4a1SSimon Wunderlich {
123004ccd4a1SSimon Wunderlich 	struct ath_softc *sc = file->private_data;
123104ccd4a1SSimon Wunderlich 	unsigned long val;
123204ccd4a1SSimon Wunderlich 	char buf[32];
123304ccd4a1SSimon Wunderlich 	ssize_t len;
123404ccd4a1SSimon Wunderlich 
123504ccd4a1SSimon Wunderlich 	len = min(count, sizeof(buf) - 1);
123604ccd4a1SSimon Wunderlich 	if (copy_from_user(buf, user_buf, len))
123704ccd4a1SSimon Wunderlich 		return -EFAULT;
123804ccd4a1SSimon Wunderlich 
123904ccd4a1SSimon Wunderlich 	buf[len] = '\0';
124004ccd4a1SSimon Wunderlich 	if (kstrtoul(buf, 0, &val))
124104ccd4a1SSimon Wunderlich 		return -EINVAL;
124204ccd4a1SSimon Wunderlich 
124304ccd4a1SSimon Wunderlich 	if (val < 0 || val > 255)
124404ccd4a1SSimon Wunderlich 		return -EINVAL;
124504ccd4a1SSimon Wunderlich 
124604ccd4a1SSimon Wunderlich 	sc->spec_config.count = val;
124704ccd4a1SSimon Wunderlich 	return count;
124804ccd4a1SSimon Wunderlich }
124904ccd4a1SSimon Wunderlich 
125004ccd4a1SSimon Wunderlich static const struct file_operations fops_spectral_count = {
125104ccd4a1SSimon Wunderlich 	.read = read_file_spectral_count,
125204ccd4a1SSimon Wunderlich 	.write = write_file_spectral_count,
125304ccd4a1SSimon Wunderlich 	.open = simple_open,
125404ccd4a1SSimon Wunderlich 	.owner = THIS_MODULE,
125504ccd4a1SSimon Wunderlich 	.llseek = default_llseek,
125604ccd4a1SSimon Wunderlich };
125704ccd4a1SSimon Wunderlich 
125804ccd4a1SSimon Wunderlich static ssize_t read_file_spectral_period(struct file *file,
125904ccd4a1SSimon Wunderlich 					 char __user *user_buf,
126004ccd4a1SSimon Wunderlich 					 size_t count, loff_t *ppos)
126104ccd4a1SSimon Wunderlich {
126204ccd4a1SSimon Wunderlich 	struct ath_softc *sc = file->private_data;
126304ccd4a1SSimon Wunderlich 	char buf[32];
126404ccd4a1SSimon Wunderlich 	unsigned int len;
126504ccd4a1SSimon Wunderlich 
126604ccd4a1SSimon Wunderlich 	len = sprintf(buf, "%d\n", sc->spec_config.period);
126704ccd4a1SSimon Wunderlich 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
126804ccd4a1SSimon Wunderlich }
126904ccd4a1SSimon Wunderlich 
127004ccd4a1SSimon Wunderlich static ssize_t write_file_spectral_period(struct file *file,
127104ccd4a1SSimon Wunderlich 					  const char __user *user_buf,
127204ccd4a1SSimon Wunderlich 					  size_t count, loff_t *ppos)
127304ccd4a1SSimon Wunderlich {
127404ccd4a1SSimon Wunderlich 	struct ath_softc *sc = file->private_data;
127504ccd4a1SSimon Wunderlich 	unsigned long val;
127604ccd4a1SSimon Wunderlich 	char buf[32];
127704ccd4a1SSimon Wunderlich 	ssize_t len;
127804ccd4a1SSimon Wunderlich 
127904ccd4a1SSimon Wunderlich 	len = min(count, sizeof(buf) - 1);
128004ccd4a1SSimon Wunderlich 	if (copy_from_user(buf, user_buf, len))
128104ccd4a1SSimon Wunderlich 		return -EFAULT;
128204ccd4a1SSimon Wunderlich 
128304ccd4a1SSimon Wunderlich 	buf[len] = '\0';
128404ccd4a1SSimon Wunderlich 	if (kstrtoul(buf, 0, &val))
128504ccd4a1SSimon Wunderlich 		return -EINVAL;
128604ccd4a1SSimon Wunderlich 
128704ccd4a1SSimon Wunderlich 	if (val < 0 || val > 255)
128804ccd4a1SSimon Wunderlich 		return -EINVAL;
128904ccd4a1SSimon Wunderlich 
129004ccd4a1SSimon Wunderlich 	sc->spec_config.period = val;
129104ccd4a1SSimon Wunderlich 	return count;
129204ccd4a1SSimon Wunderlich }
129304ccd4a1SSimon Wunderlich 
129404ccd4a1SSimon Wunderlich static const struct file_operations fops_spectral_period = {
129504ccd4a1SSimon Wunderlich 	.read = read_file_spectral_period,
129604ccd4a1SSimon Wunderlich 	.write = write_file_spectral_period,
129704ccd4a1SSimon Wunderlich 	.open = simple_open,
129804ccd4a1SSimon Wunderlich 	.owner = THIS_MODULE,
129904ccd4a1SSimon Wunderlich 	.llseek = default_llseek,
130004ccd4a1SSimon Wunderlich };
130104ccd4a1SSimon Wunderlich 
130204ccd4a1SSimon Wunderlich static ssize_t read_file_spectral_fft_period(struct file *file,
130304ccd4a1SSimon Wunderlich 					     char __user *user_buf,
130404ccd4a1SSimon Wunderlich 					     size_t count, loff_t *ppos)
130504ccd4a1SSimon Wunderlich {
130604ccd4a1SSimon Wunderlich 	struct ath_softc *sc = file->private_data;
130704ccd4a1SSimon Wunderlich 	char buf[32];
130804ccd4a1SSimon Wunderlich 	unsigned int len;
130904ccd4a1SSimon Wunderlich 
131004ccd4a1SSimon Wunderlich 	len = sprintf(buf, "%d\n", sc->spec_config.fft_period);
131104ccd4a1SSimon Wunderlich 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
131204ccd4a1SSimon Wunderlich }
131304ccd4a1SSimon Wunderlich 
131404ccd4a1SSimon Wunderlich static ssize_t write_file_spectral_fft_period(struct file *file,
131504ccd4a1SSimon Wunderlich 					      const char __user *user_buf,
131604ccd4a1SSimon Wunderlich 					      size_t count, loff_t *ppos)
131704ccd4a1SSimon Wunderlich {
131804ccd4a1SSimon Wunderlich 	struct ath_softc *sc = file->private_data;
131904ccd4a1SSimon Wunderlich 	unsigned long val;
132004ccd4a1SSimon Wunderlich 	char buf[32];
132104ccd4a1SSimon Wunderlich 	ssize_t len;
132204ccd4a1SSimon Wunderlich 
132304ccd4a1SSimon Wunderlich 	len = min(count, sizeof(buf) - 1);
132404ccd4a1SSimon Wunderlich 	if (copy_from_user(buf, user_buf, len))
132504ccd4a1SSimon Wunderlich 		return -EFAULT;
132604ccd4a1SSimon Wunderlich 
132704ccd4a1SSimon Wunderlich 	buf[len] = '\0';
132804ccd4a1SSimon Wunderlich 	if (kstrtoul(buf, 0, &val))
132904ccd4a1SSimon Wunderlich 		return -EINVAL;
133004ccd4a1SSimon Wunderlich 
133104ccd4a1SSimon Wunderlich 	if (val < 0 || val > 15)
133204ccd4a1SSimon Wunderlich 		return -EINVAL;
133304ccd4a1SSimon Wunderlich 
133404ccd4a1SSimon Wunderlich 	sc->spec_config.fft_period = val;
133504ccd4a1SSimon Wunderlich 	return count;
133604ccd4a1SSimon Wunderlich }
133704ccd4a1SSimon Wunderlich 
133804ccd4a1SSimon Wunderlich static const struct file_operations fops_spectral_fft_period = {
133904ccd4a1SSimon Wunderlich 	.read = read_file_spectral_fft_period,
134004ccd4a1SSimon Wunderlich 	.write = write_file_spectral_fft_period,
134104ccd4a1SSimon Wunderlich 	.open = simple_open,
134204ccd4a1SSimon Wunderlich 	.owner = THIS_MODULE,
134304ccd4a1SSimon Wunderlich 	.llseek = default_llseek,
134404ccd4a1SSimon Wunderlich };
134504ccd4a1SSimon Wunderlich 
1346e93d083fSSimon Wunderlich static struct dentry *create_buf_file_handler(const char *filename,
1347e93d083fSSimon Wunderlich 					      struct dentry *parent,
1348e93d083fSSimon Wunderlich 					      umode_t mode,
1349e93d083fSSimon Wunderlich 					      struct rchan_buf *buf,
1350e93d083fSSimon Wunderlich 					      int *is_global)
1351e93d083fSSimon Wunderlich {
1352e93d083fSSimon Wunderlich 	struct dentry *buf_file;
1353e93d083fSSimon Wunderlich 
1354e93d083fSSimon Wunderlich 	buf_file = debugfs_create_file(filename, mode, parent, buf,
1355e93d083fSSimon Wunderlich 				       &relay_file_operations);
1356e93d083fSSimon Wunderlich 	*is_global = 1;
1357e93d083fSSimon Wunderlich 	return buf_file;
1358e93d083fSSimon Wunderlich }
1359e93d083fSSimon Wunderlich 
1360e93d083fSSimon Wunderlich static int remove_buf_file_handler(struct dentry *dentry)
1361e93d083fSSimon Wunderlich {
1362e93d083fSSimon Wunderlich 	debugfs_remove(dentry);
1363e93d083fSSimon Wunderlich 
1364e93d083fSSimon Wunderlich 	return 0;
1365e93d083fSSimon Wunderlich }
1366e93d083fSSimon Wunderlich 
1367e93d083fSSimon Wunderlich void ath_debug_send_fft_sample(struct ath_softc *sc,
1368e93d083fSSimon Wunderlich 			       struct fft_sample_tlv *fft_sample_tlv)
1369e93d083fSSimon Wunderlich {
13704ab0b0aaSSven Eckelmann 	int length;
1371e93d083fSSimon Wunderlich 	if (!sc->rfs_chan_spec_scan)
1372e93d083fSSimon Wunderlich 		return;
1373e93d083fSSimon Wunderlich 
13744ab0b0aaSSven Eckelmann 	length = __be16_to_cpu(fft_sample_tlv->length) +
13754ab0b0aaSSven Eckelmann 		 sizeof(*fft_sample_tlv);
13764ab0b0aaSSven Eckelmann 	relay_write(sc->rfs_chan_spec_scan, fft_sample_tlv, length);
1377e93d083fSSimon Wunderlich }
1378e93d083fSSimon Wunderlich 
1379e93d083fSSimon Wunderlich static struct rchan_callbacks rfs_spec_scan_cb = {
1380e93d083fSSimon Wunderlich 	.create_buf_file = create_buf_file_handler,
1381e93d083fSSimon Wunderlich 	.remove_buf_file = remove_buf_file_handler,
1382e93d083fSSimon Wunderlich };
1383e93d083fSSimon Wunderlich 
1384e93d083fSSimon Wunderlich 
13859bff0bc4SFelix Fietkau static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
13869bff0bc4SFelix Fietkau                                 size_t count, loff_t *ppos)
13879bff0bc4SFelix Fietkau {
13889bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
13899bff0bc4SFelix Fietkau 	char buf[32];
13909bff0bc4SFelix Fietkau 	unsigned int len;
13919bff0bc4SFelix Fietkau 
13922b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
13939bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
13949bff0bc4SFelix Fietkau }
13959bff0bc4SFelix Fietkau 
13969bff0bc4SFelix Fietkau static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
13979bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
13989bff0bc4SFelix Fietkau {
13999bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
14009bff0bc4SFelix Fietkau 	unsigned long regidx;
14019bff0bc4SFelix Fietkau 	char buf[32];
14029bff0bc4SFelix Fietkau 	ssize_t len;
14039bff0bc4SFelix Fietkau 
14049bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
14059bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
140604236066SDan Carpenter 		return -EFAULT;
14079bff0bc4SFelix Fietkau 
14089bff0bc4SFelix Fietkau 	buf[len] = '\0';
140927d7f477SJingoo Han 	if (kstrtoul(buf, 0, &regidx))
14109bff0bc4SFelix Fietkau 		return -EINVAL;
14119bff0bc4SFelix Fietkau 
14129bff0bc4SFelix Fietkau 	sc->debug.regidx = regidx;
14139bff0bc4SFelix Fietkau 	return count;
14149bff0bc4SFelix Fietkau }
14159bff0bc4SFelix Fietkau 
14169bff0bc4SFelix Fietkau static const struct file_operations fops_regidx = {
14179bff0bc4SFelix Fietkau 	.read = read_file_regidx,
14189bff0bc4SFelix Fietkau 	.write = write_file_regidx,
1419234e3405SStephen Boyd 	.open = simple_open,
14206038f373SArnd Bergmann 	.owner = THIS_MODULE,
14216038f373SArnd Bergmann 	.llseek = default_llseek,
14229bff0bc4SFelix Fietkau };
14239bff0bc4SFelix Fietkau 
14249bff0bc4SFelix Fietkau static ssize_t read_file_regval(struct file *file, char __user *user_buf,
14259bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
14269bff0bc4SFelix Fietkau {
14279bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
14289bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
14299bff0bc4SFelix Fietkau 	char buf[32];
14309bff0bc4SFelix Fietkau 	unsigned int len;
14319bff0bc4SFelix Fietkau 	u32 regval;
14329bff0bc4SFelix Fietkau 
143379d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
14349bff0bc4SFelix Fietkau 	regval = REG_READ_D(ah, sc->debug.regidx);
143579d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
14362b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", regval);
14379bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
14389bff0bc4SFelix Fietkau }
14399bff0bc4SFelix Fietkau 
14409bff0bc4SFelix Fietkau static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
14419bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
14429bff0bc4SFelix Fietkau {
14439bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
14449bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
14459bff0bc4SFelix Fietkau 	unsigned long regval;
14469bff0bc4SFelix Fietkau 	char buf[32];
14479bff0bc4SFelix Fietkau 	ssize_t len;
14489bff0bc4SFelix Fietkau 
14499bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
14509bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
145104236066SDan Carpenter 		return -EFAULT;
14529bff0bc4SFelix Fietkau 
14539bff0bc4SFelix Fietkau 	buf[len] = '\0';
145427d7f477SJingoo Han 	if (kstrtoul(buf, 0, &regval))
14559bff0bc4SFelix Fietkau 		return -EINVAL;
14569bff0bc4SFelix Fietkau 
145779d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
14589bff0bc4SFelix Fietkau 	REG_WRITE_D(ah, sc->debug.regidx, regval);
145979d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
14609bff0bc4SFelix Fietkau 	return count;
14619bff0bc4SFelix Fietkau }
14629bff0bc4SFelix Fietkau 
14639bff0bc4SFelix Fietkau static const struct file_operations fops_regval = {
14649bff0bc4SFelix Fietkau 	.read = read_file_regval,
14659bff0bc4SFelix Fietkau 	.write = write_file_regval,
1466234e3405SStephen Boyd 	.open = simple_open,
14676038f373SArnd Bergmann 	.owner = THIS_MODULE,
14686038f373SArnd Bergmann 	.llseek = default_llseek,
14699bff0bc4SFelix Fietkau };
14709bff0bc4SFelix Fietkau 
1471582d0064SVasanthakumar Thiagarajan #define REGDUMP_LINE_SIZE	20
1472582d0064SVasanthakumar Thiagarajan 
1473582d0064SVasanthakumar Thiagarajan static int open_file_regdump(struct inode *inode, struct file *file)
1474582d0064SVasanthakumar Thiagarajan {
1475582d0064SVasanthakumar Thiagarajan 	struct ath_softc *sc = inode->i_private;
1476582d0064SVasanthakumar Thiagarajan 	unsigned int len = 0;
1477582d0064SVasanthakumar Thiagarajan 	u8 *buf;
1478582d0064SVasanthakumar Thiagarajan 	int i;
1479582d0064SVasanthakumar Thiagarajan 	unsigned long num_regs, regdump_len, max_reg_offset;
1480582d0064SVasanthakumar Thiagarajan 
1481582d0064SVasanthakumar Thiagarajan 	max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
1482582d0064SVasanthakumar Thiagarajan 	num_regs = max_reg_offset / 4 + 1;
1483582d0064SVasanthakumar Thiagarajan 	regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
1484582d0064SVasanthakumar Thiagarajan 	buf = vmalloc(regdump_len);
1485582d0064SVasanthakumar Thiagarajan 	if (!buf)
1486582d0064SVasanthakumar Thiagarajan 		return -ENOMEM;
1487582d0064SVasanthakumar Thiagarajan 
1488582d0064SVasanthakumar Thiagarajan 	ath9k_ps_wakeup(sc);
1489582d0064SVasanthakumar Thiagarajan 	for (i = 0; i < num_regs; i++)
1490582d0064SVasanthakumar Thiagarajan 		len += scnprintf(buf + len, regdump_len - len,
1491582d0064SVasanthakumar Thiagarajan 			"0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
1492582d0064SVasanthakumar Thiagarajan 	ath9k_ps_restore(sc);
1493582d0064SVasanthakumar Thiagarajan 
1494582d0064SVasanthakumar Thiagarajan 	file->private_data = buf;
1495582d0064SVasanthakumar Thiagarajan 
1496582d0064SVasanthakumar Thiagarajan 	return 0;
1497582d0064SVasanthakumar Thiagarajan }
1498582d0064SVasanthakumar Thiagarajan 
1499582d0064SVasanthakumar Thiagarajan static const struct file_operations fops_regdump = {
1500582d0064SVasanthakumar Thiagarajan 	.open = open_file_regdump,
1501582d0064SVasanthakumar Thiagarajan 	.read = ath9k_debugfs_read_buf,
1502582d0064SVasanthakumar Thiagarajan 	.release = ath9k_debugfs_release_buf,
1503582d0064SVasanthakumar Thiagarajan 	.owner = THIS_MODULE,
1504582d0064SVasanthakumar Thiagarajan 	.llseek = default_llseek,/* read accesses f_pos */
1505582d0064SVasanthakumar Thiagarajan };
1506582d0064SVasanthakumar Thiagarajan 
1507d069a46bSRajkumar Manoharan static ssize_t read_file_dump_nfcal(struct file *file, char __user *user_buf,
1508d069a46bSRajkumar Manoharan 				    size_t count, loff_t *ppos)
1509d069a46bSRajkumar Manoharan {
1510d069a46bSRajkumar Manoharan 	struct ath_softc *sc = file->private_data;
1511d069a46bSRajkumar Manoharan 	struct ath_hw *ah = sc->sc_ah;
1512d069a46bSRajkumar Manoharan 	struct ath9k_nfcal_hist *h = sc->caldata.nfCalHist;
1513d069a46bSRajkumar Manoharan 	struct ath_common *common = ath9k_hw_common(ah);
1514d069a46bSRajkumar Manoharan 	struct ieee80211_conf *conf = &common->hw->conf;
1515d069a46bSRajkumar Manoharan 	u32 len = 0, size = 1500;
1516d069a46bSRajkumar Manoharan 	u32 i, j;
1517d069a46bSRajkumar Manoharan 	ssize_t retval = 0;
1518d069a46bSRajkumar Manoharan 	char *buf;
1519d069a46bSRajkumar Manoharan 	u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1520d069a46bSRajkumar Manoharan 	u8 nread;
1521d069a46bSRajkumar Manoharan 
1522d069a46bSRajkumar Manoharan 	buf = kzalloc(size, GFP_KERNEL);
1523d069a46bSRajkumar Manoharan 	if (!buf)
1524d069a46bSRajkumar Manoharan 		return -ENOMEM;
1525d069a46bSRajkumar Manoharan 
1526d069a46bSRajkumar Manoharan 	len += snprintf(buf + len, size - len,
1527d069a46bSRajkumar Manoharan 			"Channel Noise Floor : %d\n", ah->noise);
1528d069a46bSRajkumar Manoharan 	len += snprintf(buf + len, size - len,
1529d069a46bSRajkumar Manoharan 			"Chain | privNF | # Readings | NF Readings\n");
1530d069a46bSRajkumar Manoharan 	for (i = 0; i < NUM_NF_READINGS; i++) {
1531d069a46bSRajkumar Manoharan 		if (!(chainmask & (1 << i)) ||
1532d069a46bSRajkumar Manoharan 		    ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1533d069a46bSRajkumar Manoharan 			continue;
1534d069a46bSRajkumar Manoharan 
1535d069a46bSRajkumar Manoharan 		nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
1536d069a46bSRajkumar Manoharan 		len += snprintf(buf + len, size - len, " %d\t %d\t %d\t\t",
1537d069a46bSRajkumar Manoharan 				i, h[i].privNF, nread);
1538d069a46bSRajkumar Manoharan 		for (j = 0; j < nread; j++)
1539d069a46bSRajkumar Manoharan 			len += snprintf(buf + len, size - len,
1540d069a46bSRajkumar Manoharan 					" %d", h[i].nfCalBuffer[j]);
1541d069a46bSRajkumar Manoharan 		len += snprintf(buf + len, size - len, "\n");
1542d069a46bSRajkumar Manoharan 	}
1543d069a46bSRajkumar Manoharan 
1544d069a46bSRajkumar Manoharan 	if (len > size)
1545d069a46bSRajkumar Manoharan 		len = size;
1546d069a46bSRajkumar Manoharan 
1547d069a46bSRajkumar Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1548d069a46bSRajkumar Manoharan 	kfree(buf);
1549d069a46bSRajkumar Manoharan 
1550d069a46bSRajkumar Manoharan 	return retval;
1551d069a46bSRajkumar Manoharan }
1552d069a46bSRajkumar Manoharan 
1553d069a46bSRajkumar Manoharan static const struct file_operations fops_dump_nfcal = {
1554d069a46bSRajkumar Manoharan 	.read = read_file_dump_nfcal,
1555234e3405SStephen Boyd 	.open = simple_open,
1556d069a46bSRajkumar Manoharan 	.owner = THIS_MODULE,
1557d069a46bSRajkumar Manoharan 	.llseek = default_llseek,
1558d069a46bSRajkumar Manoharan };
1559d069a46bSRajkumar Manoharan 
1560580f010fSRajkumar Manoharan static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf,
1561580f010fSRajkumar Manoharan 				     size_t count, loff_t *ppos)
1562580f010fSRajkumar Manoharan {
1563580f010fSRajkumar Manoharan 	struct ath_softc *sc = file->private_data;
1564580f010fSRajkumar Manoharan 	struct ath_hw *ah = sc->sc_ah;
1565580f010fSRajkumar Manoharan 	u32 len = 0, size = 1500;
1566580f010fSRajkumar Manoharan 	ssize_t retval = 0;
1567580f010fSRajkumar Manoharan 	char *buf;
1568580f010fSRajkumar Manoharan 
1569580f010fSRajkumar Manoharan 	buf = kzalloc(size, GFP_KERNEL);
1570580f010fSRajkumar Manoharan 	if (!buf)
1571580f010fSRajkumar Manoharan 		return -ENOMEM;
1572580f010fSRajkumar Manoharan 
1573580f010fSRajkumar Manoharan 	len = ah->eep_ops->dump_eeprom(ah, true, buf, len, size);
1574580f010fSRajkumar Manoharan 
1575580f010fSRajkumar Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1576580f010fSRajkumar Manoharan 	kfree(buf);
1577580f010fSRajkumar Manoharan 
1578580f010fSRajkumar Manoharan 	return retval;
1579580f010fSRajkumar Manoharan }
1580580f010fSRajkumar Manoharan 
1581580f010fSRajkumar Manoharan static const struct file_operations fops_base_eeprom = {
1582580f010fSRajkumar Manoharan 	.read = read_file_base_eeprom,
1583234e3405SStephen Boyd 	.open = simple_open,
1584580f010fSRajkumar Manoharan 	.owner = THIS_MODULE,
1585580f010fSRajkumar Manoharan 	.llseek = default_llseek,
1586580f010fSRajkumar Manoharan };
1587580f010fSRajkumar Manoharan 
15883f4c4bddSRajkumar Manoharan static ssize_t read_file_modal_eeprom(struct file *file, char __user *user_buf,
15893f4c4bddSRajkumar Manoharan 				      size_t count, loff_t *ppos)
15903f4c4bddSRajkumar Manoharan {
15913f4c4bddSRajkumar Manoharan 	struct ath_softc *sc = file->private_data;
15923f4c4bddSRajkumar Manoharan 	struct ath_hw *ah = sc->sc_ah;
15933f4c4bddSRajkumar Manoharan 	u32 len = 0, size = 6000;
15943f4c4bddSRajkumar Manoharan 	char *buf;
15953f4c4bddSRajkumar Manoharan 	size_t retval;
15963f4c4bddSRajkumar Manoharan 
15973f4c4bddSRajkumar Manoharan 	buf = kzalloc(size, GFP_KERNEL);
15983f4c4bddSRajkumar Manoharan 	if (buf == NULL)
15993f4c4bddSRajkumar Manoharan 		return -ENOMEM;
16003f4c4bddSRajkumar Manoharan 
16013f4c4bddSRajkumar Manoharan 	len = ah->eep_ops->dump_eeprom(ah, false, buf, len, size);
16023f4c4bddSRajkumar Manoharan 
16033f4c4bddSRajkumar Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
16043f4c4bddSRajkumar Manoharan 	kfree(buf);
16053f4c4bddSRajkumar Manoharan 
16063f4c4bddSRajkumar Manoharan 	return retval;
16073f4c4bddSRajkumar Manoharan }
16083f4c4bddSRajkumar Manoharan 
16093f4c4bddSRajkumar Manoharan static const struct file_operations fops_modal_eeprom = {
16103f4c4bddSRajkumar Manoharan 	.read = read_file_modal_eeprom,
1611234e3405SStephen Boyd 	.open = simple_open,
16123f4c4bddSRajkumar Manoharan 	.owner = THIS_MODULE,
16133f4c4bddSRajkumar Manoharan 	.llseek = default_llseek,
16143f4c4bddSRajkumar Manoharan };
16153f4c4bddSRajkumar Manoharan 
16164df50ca8SRajkumar Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
16174df50ca8SRajkumar Manoharan static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
16184df50ca8SRajkumar Manoharan 				size_t count, loff_t *ppos)
16194df50ca8SRajkumar Manoharan {
16204df50ca8SRajkumar Manoharan 	struct ath_softc *sc = file->private_data;
16214df50ca8SRajkumar Manoharan 	u32 len = 0, size = 1500;
16224df50ca8SRajkumar Manoharan 	char *buf;
16234df50ca8SRajkumar Manoharan 	size_t retval;
16244df50ca8SRajkumar Manoharan 
16254df50ca8SRajkumar Manoharan 	buf = kzalloc(size, GFP_KERNEL);
16264df50ca8SRajkumar Manoharan 	if (buf == NULL)
16274df50ca8SRajkumar Manoharan 		return -ENOMEM;
16284df50ca8SRajkumar Manoharan 
1629ac46ba43SSujith Manoharan 	if (!sc->sc_ah->common.btcoex_enabled) {
1630ac46ba43SSujith Manoharan 		len = snprintf(buf, size, "%s\n",
1631ac46ba43SSujith Manoharan 			       "BTCOEX is disabled");
1632ac46ba43SSujith Manoharan 		goto exit;
1633ac46ba43SSujith Manoharan 	}
16344df50ca8SRajkumar Manoharan 
1635ac46ba43SSujith Manoharan 	len = ath9k_dump_btcoex(sc, buf, size);
1636ac46ba43SSujith Manoharan exit:
16374df50ca8SRajkumar Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
16384df50ca8SRajkumar Manoharan 	kfree(buf);
16394df50ca8SRajkumar Manoharan 
16404df50ca8SRajkumar Manoharan 	return retval;
16414df50ca8SRajkumar Manoharan }
16424df50ca8SRajkumar Manoharan 
16434df50ca8SRajkumar Manoharan static const struct file_operations fops_btcoex = {
16444df50ca8SRajkumar Manoharan 	.read = read_file_btcoex,
16454df50ca8SRajkumar Manoharan 	.open = simple_open,
16464df50ca8SRajkumar Manoharan 	.owner = THIS_MODULE,
16474df50ca8SRajkumar Manoharan 	.llseek = default_llseek,
16484df50ca8SRajkumar Manoharan };
16494df50ca8SRajkumar Manoharan #endif
16504df50ca8SRajkumar Manoharan 
1651a145daf7SSujith Manoharan static ssize_t read_file_node_stat(struct file *file, char __user *user_buf,
1652a145daf7SSujith Manoharan 				   size_t count, loff_t *ppos)
1653a145daf7SSujith Manoharan {
1654a145daf7SSujith Manoharan 	struct ath_node *an = file->private_data;
1655a145daf7SSujith Manoharan 	struct ath_softc *sc = an->sc;
1656a145daf7SSujith Manoharan 	struct ath_atx_tid *tid;
1657a145daf7SSujith Manoharan 	struct ath_atx_ac *ac;
1658a145daf7SSujith Manoharan 	struct ath_txq *txq;
1659a145daf7SSujith Manoharan 	u32 len = 0, size = 4096;
1660a145daf7SSujith Manoharan 	char *buf;
1661a145daf7SSujith Manoharan 	size_t retval;
1662a145daf7SSujith Manoharan 	int tidno, acno;
1663a145daf7SSujith Manoharan 
1664a145daf7SSujith Manoharan 	buf = kzalloc(size, GFP_KERNEL);
1665a145daf7SSujith Manoharan 	if (buf == NULL)
1666a145daf7SSujith Manoharan 		return -ENOMEM;
1667a145daf7SSujith Manoharan 
1668a145daf7SSujith Manoharan 	if (!an->sta->ht_cap.ht_supported) {
1669a145daf7SSujith Manoharan 		len = snprintf(buf, size, "%s\n",
1670a145daf7SSujith Manoharan 			       "HT not supported");
1671a145daf7SSujith Manoharan 		goto exit;
1672a145daf7SSujith Manoharan 	}
1673a145daf7SSujith Manoharan 
1674a145daf7SSujith Manoharan 	len = snprintf(buf, size, "Max-AMPDU: %d\n",
1675a145daf7SSujith Manoharan 		       an->maxampdu);
1676a145daf7SSujith Manoharan 	len += snprintf(buf + len, size - len, "MPDU Density: %d\n\n",
1677a145daf7SSujith Manoharan 			an->mpdudensity);
1678a145daf7SSujith Manoharan 
1679a145daf7SSujith Manoharan 	len += snprintf(buf + len, size - len,
1680a145daf7SSujith Manoharan 			"%2s%7s\n", "AC", "SCHED");
1681a145daf7SSujith Manoharan 
1682a145daf7SSujith Manoharan 	for (acno = 0, ac = &an->ac[acno];
1683a145daf7SSujith Manoharan 	     acno < IEEE80211_NUM_ACS; acno++, ac++) {
1684a145daf7SSujith Manoharan 		txq = ac->txq;
1685a145daf7SSujith Manoharan 		ath_txq_lock(sc, txq);
1686a145daf7SSujith Manoharan 		len += snprintf(buf + len, size - len,
1687a145daf7SSujith Manoharan 				"%2d%7d\n",
1688a145daf7SSujith Manoharan 				acno, ac->sched);
1689a145daf7SSujith Manoharan 		ath_txq_unlock(sc, txq);
1690a145daf7SSujith Manoharan 	}
1691a145daf7SSujith Manoharan 
1692a145daf7SSujith Manoharan 	len += snprintf(buf + len, size - len,
1693a145daf7SSujith Manoharan 			"\n%3s%11s%10s%10s%10s%10s%9s%6s%8s\n",
1694a145daf7SSujith Manoharan 			"TID", "SEQ_START", "SEQ_NEXT", "BAW_SIZE",
1695a145daf7SSujith Manoharan 			"BAW_HEAD", "BAW_TAIL", "BAR_IDX", "SCHED", "PAUSED");
1696a145daf7SSujith Manoharan 
1697a145daf7SSujith Manoharan 	for (tidno = 0, tid = &an->tid[tidno];
1698a145daf7SSujith Manoharan 	     tidno < IEEE80211_NUM_TIDS; tidno++, tid++) {
1699a145daf7SSujith Manoharan 		txq = tid->ac->txq;
1700a145daf7SSujith Manoharan 		ath_txq_lock(sc, txq);
1701a145daf7SSujith Manoharan 		len += snprintf(buf + len, size - len,
1702a145daf7SSujith Manoharan 				"%3d%11d%10d%10d%10d%10d%9d%6d%8d\n",
1703a145daf7SSujith Manoharan 				tid->tidno, tid->seq_start, tid->seq_next,
1704a145daf7SSujith Manoharan 				tid->baw_size, tid->baw_head, tid->baw_tail,
1705a145daf7SSujith Manoharan 				tid->bar_index, tid->sched, tid->paused);
1706a145daf7SSujith Manoharan 		ath_txq_unlock(sc, txq);
1707a145daf7SSujith Manoharan 	}
1708a145daf7SSujith Manoharan exit:
1709a145daf7SSujith Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1710a145daf7SSujith Manoharan 	kfree(buf);
1711a145daf7SSujith Manoharan 
1712a145daf7SSujith Manoharan 	return retval;
1713a145daf7SSujith Manoharan }
1714a145daf7SSujith Manoharan 
1715a145daf7SSujith Manoharan static const struct file_operations fops_node_stat = {
1716a145daf7SSujith Manoharan 	.read = read_file_node_stat,
1717a145daf7SSujith Manoharan 	.open = simple_open,
1718a145daf7SSujith Manoharan 	.owner = THIS_MODULE,
1719a145daf7SSujith Manoharan 	.llseek = default_llseek,
1720a145daf7SSujith Manoharan };
1721a145daf7SSujith Manoharan 
1722a145daf7SSujith Manoharan void ath9k_sta_add_debugfs(struct ieee80211_hw *hw,
1723a145daf7SSujith Manoharan 			   struct ieee80211_vif *vif,
1724a145daf7SSujith Manoharan 			   struct ieee80211_sta *sta,
1725a145daf7SSujith Manoharan 			   struct dentry *dir)
1726a145daf7SSujith Manoharan {
1727a145daf7SSujith Manoharan 	struct ath_node *an = (struct ath_node *)sta->drv_priv;
1728a145daf7SSujith Manoharan 	an->node_stat = debugfs_create_file("node_stat", S_IRUGO,
1729a145daf7SSujith Manoharan 					    dir, an, &fops_node_stat);
1730a145daf7SSujith Manoharan }
1731a145daf7SSujith Manoharan 
1732a145daf7SSujith Manoharan void ath9k_sta_remove_debugfs(struct ieee80211_hw *hw,
1733a145daf7SSujith Manoharan 			      struct ieee80211_vif *vif,
1734a145daf7SSujith Manoharan 			      struct ieee80211_sta *sta,
1735a145daf7SSujith Manoharan 			      struct dentry *dir)
1736a145daf7SSujith Manoharan {
1737a145daf7SSujith Manoharan 	struct ath_node *an = (struct ath_node *)sta->drv_priv;
1738a145daf7SSujith Manoharan 	debugfs_remove(an->node_stat);
1739a145daf7SSujith Manoharan }
1740a145daf7SSujith Manoharan 
1741c175db87SSujith Manoharan /* Ethtool support for get-stats */
1742c175db87SSujith Manoharan 
1743c175db87SSujith Manoharan #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1744c175db87SSujith Manoharan static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1745c175db87SSujith Manoharan 	"tx_pkts_nic",
1746c175db87SSujith Manoharan 	"tx_bytes_nic",
1747c175db87SSujith Manoharan 	"rx_pkts_nic",
1748c175db87SSujith Manoharan 	"rx_bytes_nic",
1749c175db87SSujith Manoharan 	AMKSTR(d_tx_pkts),
1750c175db87SSujith Manoharan 	AMKSTR(d_tx_bytes),
1751c175db87SSujith Manoharan 	AMKSTR(d_tx_mpdus_queued),
1752c175db87SSujith Manoharan 	AMKSTR(d_tx_mpdus_completed),
1753c175db87SSujith Manoharan 	AMKSTR(d_tx_mpdu_xretries),
1754c175db87SSujith Manoharan 	AMKSTR(d_tx_aggregates),
1755c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdus_queued_hw),
1756c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdus_queued_sw),
1757c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdus_completed),
1758c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdu_retries),
1759c175db87SSujith Manoharan 	AMKSTR(d_tx_ampdu_xretries),
1760c175db87SSujith Manoharan 	AMKSTR(d_tx_fifo_underrun),
1761c175db87SSujith Manoharan 	AMKSTR(d_tx_op_exceeded),
1762c175db87SSujith Manoharan 	AMKSTR(d_tx_timer_expiry),
1763c175db87SSujith Manoharan 	AMKSTR(d_tx_desc_cfg_err),
1764c175db87SSujith Manoharan 	AMKSTR(d_tx_data_underrun),
1765c175db87SSujith Manoharan 	AMKSTR(d_tx_delim_underrun),
176618c45b10SBen Greear 	"d_rx_crc_err",
1767c175db87SSujith Manoharan 	"d_rx_decrypt_crc_err",
1768c175db87SSujith Manoharan 	"d_rx_phy_err",
1769c175db87SSujith Manoharan 	"d_rx_mic_err",
1770c175db87SSujith Manoharan 	"d_rx_pre_delim_crc_err",
1771c175db87SSujith Manoharan 	"d_rx_post_delim_crc_err",
1772c175db87SSujith Manoharan 	"d_rx_decrypt_busy_err",
1773c175db87SSujith Manoharan 
1774c175db87SSujith Manoharan 	"d_rx_phyerr_radar",
1775c175db87SSujith Manoharan 	"d_rx_phyerr_ofdm_timing",
1776c175db87SSujith Manoharan 	"d_rx_phyerr_cck_timing",
1777c175db87SSujith Manoharan 
1778c175db87SSujith Manoharan };
1779c175db87SSujith Manoharan #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1780c175db87SSujith Manoharan 
1781c175db87SSujith Manoharan void ath9k_get_et_strings(struct ieee80211_hw *hw,
1782c175db87SSujith Manoharan 			  struct ieee80211_vif *vif,
1783c175db87SSujith Manoharan 			  u32 sset, u8 *data)
1784c175db87SSujith Manoharan {
1785c175db87SSujith Manoharan 	if (sset == ETH_SS_STATS)
1786c175db87SSujith Manoharan 		memcpy(data, *ath9k_gstrings_stats,
1787c175db87SSujith Manoharan 		       sizeof(ath9k_gstrings_stats));
1788c175db87SSujith Manoharan }
1789c175db87SSujith Manoharan 
1790c175db87SSujith Manoharan int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
1791c175db87SSujith Manoharan 			    struct ieee80211_vif *vif, int sset)
1792c175db87SSujith Manoharan {
1793c175db87SSujith Manoharan 	if (sset == ETH_SS_STATS)
1794c175db87SSujith Manoharan 		return ATH9K_SSTATS_LEN;
1795c175db87SSujith Manoharan 	return 0;
1796c175db87SSujith Manoharan }
1797c175db87SSujith Manoharan 
1798c175db87SSujith Manoharan #define AWDATA(elem)							\
1799c175db87SSujith Manoharan 	do {								\
1800c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
1801c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
1802c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
1803c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
1804c175db87SSujith Manoharan 	} while (0)
1805c175db87SSujith Manoharan 
1806c175db87SSujith Manoharan #define AWDATA_RX(elem)						\
1807c175db87SSujith Manoharan 	do {							\
1808c175db87SSujith Manoharan 		data[i++] = sc->debug.stats.rxstats.elem;	\
1809c175db87SSujith Manoharan 	} while (0)
1810c175db87SSujith Manoharan 
1811c175db87SSujith Manoharan void ath9k_get_et_stats(struct ieee80211_hw *hw,
1812c175db87SSujith Manoharan 			struct ieee80211_vif *vif,
1813c175db87SSujith Manoharan 			struct ethtool_stats *stats, u64 *data)
1814c175db87SSujith Manoharan {
1815c175db87SSujith Manoharan 	struct ath_softc *sc = hw->priv;
1816c175db87SSujith Manoharan 	int i = 0;
1817c175db87SSujith Manoharan 
1818c175db87SSujith Manoharan 	data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
1819c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
1820c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
1821c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
1822c175db87SSujith Manoharan 	data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
1823c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
1824c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
1825c175db87SSujith Manoharan 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
1826c175db87SSujith Manoharan 	AWDATA_RX(rx_pkts_all);
1827c175db87SSujith Manoharan 	AWDATA_RX(rx_bytes_all);
1828c175db87SSujith Manoharan 
1829c175db87SSujith Manoharan 	AWDATA(tx_pkts_all);
1830c175db87SSujith Manoharan 	AWDATA(tx_bytes_all);
1831c175db87SSujith Manoharan 	AWDATA(queued);
1832c175db87SSujith Manoharan 	AWDATA(completed);
1833c175db87SSujith Manoharan 	AWDATA(xretries);
1834c175db87SSujith Manoharan 	AWDATA(a_aggr);
1835c175db87SSujith Manoharan 	AWDATA(a_queued_hw);
1836c175db87SSujith Manoharan 	AWDATA(a_queued_sw);
1837c175db87SSujith Manoharan 	AWDATA(a_completed);
1838c175db87SSujith Manoharan 	AWDATA(a_retries);
1839c175db87SSujith Manoharan 	AWDATA(a_xretries);
1840c175db87SSujith Manoharan 	AWDATA(fifo_underrun);
1841c175db87SSujith Manoharan 	AWDATA(xtxop);
1842c175db87SSujith Manoharan 	AWDATA(timer_exp);
1843c175db87SSujith Manoharan 	AWDATA(desc_cfg_err);
1844c175db87SSujith Manoharan 	AWDATA(data_underrun);
1845c175db87SSujith Manoharan 	AWDATA(delim_underrun);
1846c175db87SSujith Manoharan 
184718c45b10SBen Greear 	AWDATA_RX(crc_err);
1848c175db87SSujith Manoharan 	AWDATA_RX(decrypt_crc_err);
1849c175db87SSujith Manoharan 	AWDATA_RX(phy_err);
1850c175db87SSujith Manoharan 	AWDATA_RX(mic_err);
1851c175db87SSujith Manoharan 	AWDATA_RX(pre_delim_crc_err);
1852c175db87SSujith Manoharan 	AWDATA_RX(post_delim_crc_err);
1853c175db87SSujith Manoharan 	AWDATA_RX(decrypt_busy_err);
1854c175db87SSujith Manoharan 
1855c175db87SSujith Manoharan 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
1856c175db87SSujith Manoharan 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
1857c175db87SSujith Manoharan 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
1858c175db87SSujith Manoharan 
1859c175db87SSujith Manoharan 	WARN_ON(i != ATH9K_SSTATS_LEN);
1860c175db87SSujith Manoharan }
1861c175db87SSujith Manoharan 
1862af690092SSujith Manoharan void ath9k_deinit_debug(struct ath_softc *sc)
1863af690092SSujith Manoharan {
1864af690092SSujith Manoharan 	if (config_enabled(CONFIG_ATH9K_DEBUGFS) && sc->rfs_chan_spec_scan) {
1865af690092SSujith Manoharan 		relay_close(sc->rfs_chan_spec_scan);
1866af690092SSujith Manoharan 		sc->rfs_chan_spec_scan = NULL;
1867af690092SSujith Manoharan 	}
1868af690092SSujith Manoharan }
1869af690092SSujith Manoharan 
18704d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah)
1871203c4805SLuis R. Rodriguez {
1872bc974f4aSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(ah);
1873bc974f4aSLuis R. Rodriguez 	struct ath_softc *sc = (struct ath_softc *) common->priv;
18744d6b228dSLuis R. Rodriguez 
1875eb272441SBen Greear 	sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1876eb272441SBen Greear 						   sc->hw->wiphy->debugfsdir);
1877203c4805SLuis R. Rodriguez 	if (!sc->debug.debugfs_phy)
1878c8a72c00SFelix Fietkau 		return -ENOMEM;
1879203c4805SLuis R. Rodriguez 
1880a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
1881c70cab1aSFelix Fietkau 	debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1882c70cab1aSFelix Fietkau 			    sc, &fops_debug);
1883a830df07SFelix Fietkau #endif
188429942bc1SZefir Kurtisi 
188529942bc1SZefir Kurtisi 	ath9k_dfs_init_debug(sc);
188629942bc1SZefir Kurtisi 
1887c70cab1aSFelix Fietkau 	debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
1888c70cab1aSFelix Fietkau 			    &fops_dma);
1889c70cab1aSFelix Fietkau 	debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
1890c70cab1aSFelix Fietkau 			    &fops_interrupt);
1891c70cab1aSFelix Fietkau 	debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc,
1892c70cab1aSFelix Fietkau 			    &fops_xmit);
1893c0b74876SSujith Manoharan 	debugfs_create_file("queues", S_IRUSR, sc->debug.debugfs_phy, sc,
1894c0b74876SSujith Manoharan 			    &fops_queues);
18957702e788SFelix Fietkau 	debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1896bea843c7SSujith Manoharan 			   &sc->tx.txq_max_pending[IEEE80211_AC_BK]);
18977702e788SFelix Fietkau 	debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1898bea843c7SSujith Manoharan 			   &sc->tx.txq_max_pending[IEEE80211_AC_BE]);
18997702e788SFelix Fietkau 	debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1900bea843c7SSujith Manoharan 			   &sc->tx.txq_max_pending[IEEE80211_AC_VI]);
19017702e788SFelix Fietkau 	debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1902bea843c7SSujith Manoharan 			   &sc->tx.txq_max_pending[IEEE80211_AC_VO]);
1903c70cab1aSFelix Fietkau 	debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy, sc,
1904c70cab1aSFelix Fietkau 			    &fops_misc);
1905f8b815dcSSujith Manoharan 	debugfs_create_file("reset", S_IRUSR, sc->debug.debugfs_phy, sc,
1906f8b815dcSSujith Manoharan 			    &fops_reset);
1907c70cab1aSFelix Fietkau 	debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy, sc,
1908c70cab1aSFelix Fietkau 			    &fops_recv);
1909c70cab1aSFelix Fietkau 	debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
1910c70cab1aSFelix Fietkau 			    sc->debug.debugfs_phy, sc, &fops_rx_chainmask);
1911c70cab1aSFelix Fietkau 	debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
1912c70cab1aSFelix Fietkau 			    sc->debug.debugfs_phy, sc, &fops_tx_chainmask);
19136e4d291eSSujith Manoharan 	debugfs_create_file("ani", S_IRUSR | S_IWUSR,
19146e4d291eSSujith Manoharan 			    sc->debug.debugfs_phy, sc, &fops_ani);
191574673db9SFelix Fietkau 	debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
191674673db9SFelix Fietkau 			    &sc->sc_ah->config.enable_paprd);
1917c70cab1aSFelix Fietkau 	debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1918c70cab1aSFelix Fietkau 			    sc, &fops_regidx);
1919c70cab1aSFelix Fietkau 	debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1920c70cab1aSFelix Fietkau 			    sc, &fops_regval);
1921c70cab1aSFelix Fietkau 	debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1922c70cab1aSFelix Fietkau 			    sc->debug.debugfs_phy,
1923c70cab1aSFelix Fietkau 			    &ah->config.cwm_ignore_extcca);
1924c70cab1aSFelix Fietkau 	debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
1925c70cab1aSFelix Fietkau 			    &fops_regdump);
1926d069a46bSRajkumar Manoharan 	debugfs_create_file("dump_nfcal", S_IRUSR, sc->debug.debugfs_phy, sc,
1927d069a46bSRajkumar Manoharan 			    &fops_dump_nfcal);
1928580f010fSRajkumar Manoharan 	debugfs_create_file("base_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
1929580f010fSRajkumar Manoharan 			    &fops_base_eeprom);
19303f4c4bddSRajkumar Manoharan 	debugfs_create_file("modal_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
19313f4c4bddSRajkumar Manoharan 			    &fops_modal_eeprom);
1932e93d083fSSimon Wunderlich 	sc->rfs_chan_spec_scan = relay_open("spectral_scan",
1933e93d083fSSimon Wunderlich 					    sc->debug.debugfs_phy,
193455f39e67SZefir Kurtisi 					    1024, 256, &rfs_spec_scan_cb,
1935e93d083fSSimon Wunderlich 					    NULL);
1936e93d083fSSimon Wunderlich 	debugfs_create_file("spectral_scan_ctl", S_IRUSR | S_IWUSR,
1937e93d083fSSimon Wunderlich 			    sc->debug.debugfs_phy, sc,
1938e93d083fSSimon Wunderlich 			    &fops_spec_scan_ctl);
193904ccd4a1SSimon Wunderlich 	debugfs_create_file("spectral_short_repeat", S_IRUSR | S_IWUSR,
194004ccd4a1SSimon Wunderlich 			    sc->debug.debugfs_phy, sc,
194104ccd4a1SSimon Wunderlich 			    &fops_spectral_short_repeat);
194204ccd4a1SSimon Wunderlich 	debugfs_create_file("spectral_count", S_IRUSR | S_IWUSR,
194304ccd4a1SSimon Wunderlich 			    sc->debug.debugfs_phy, sc, &fops_spectral_count);
194404ccd4a1SSimon Wunderlich 	debugfs_create_file("spectral_period", S_IRUSR | S_IWUSR,
194504ccd4a1SSimon Wunderlich 			    sc->debug.debugfs_phy, sc, &fops_spectral_period);
194604ccd4a1SSimon Wunderlich 	debugfs_create_file("spectral_fft_period", S_IRUSR | S_IWUSR,
194704ccd4a1SSimon Wunderlich 			    sc->debug.debugfs_phy, sc,
194804ccd4a1SSimon Wunderlich 			    &fops_spectral_fft_period);
1949691680b8SFelix Fietkau 	debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
1950691680b8SFelix Fietkau 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
1951691680b8SFelix Fietkau 	debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
1952691680b8SFelix Fietkau 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
19534eba10ccSSujith Manoharan 	debugfs_create_file("antenna_diversity", S_IRUSR,
19544eba10ccSSujith Manoharan 			    sc->debug.debugfs_phy, sc, &fops_antenna_diversity);
19554df50ca8SRajkumar Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
195636e8825eSSujith Manoharan 	debugfs_create_file("bt_ant_diversity", S_IRUSR | S_IWUSR,
195736e8825eSSujith Manoharan 			    sc->debug.debugfs_phy, sc, &fops_bt_ant_diversity);
19584df50ca8SRajkumar Manoharan 	debugfs_create_file("btcoex", S_IRUSR, sc->debug.debugfs_phy, sc,
19594df50ca8SRajkumar Manoharan 			    &fops_btcoex);
19604df50ca8SRajkumar Manoharan #endif
1961203c4805SLuis R. Rodriguez 	return 0;
1962203c4805SLuis R. Rodriguez }
1963