xref: /openbmc/linux/drivers/net/wireless/ath/ath9k/debug.c (revision c9e6e980433a0399c02061a59175bbc819eb8507)
1203c4805SLuis R. Rodriguez /*
25b68138eSSujith Manoharan  * Copyright (c) 2008-2011 Atheros Communications Inc.
3203c4805SLuis R. Rodriguez  *
4203c4805SLuis R. Rodriguez  * Permission to use, copy, modify, and/or distribute this software for any
5203c4805SLuis R. Rodriguez  * purpose with or without fee is hereby granted, provided that the above
6203c4805SLuis R. Rodriguez  * copyright notice and this permission notice appear in all copies.
7203c4805SLuis R. Rodriguez  *
8203c4805SLuis R. Rodriguez  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9203c4805SLuis R. Rodriguez  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10203c4805SLuis R. Rodriguez  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11203c4805SLuis R. Rodriguez  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12203c4805SLuis R. Rodriguez  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13203c4805SLuis R. Rodriguez  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14203c4805SLuis R. Rodriguez  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15203c4805SLuis R. Rodriguez  */
16203c4805SLuis R. Rodriguez 
175a0e3ad6STejun Heo #include <linux/slab.h>
18582d0064SVasanthakumar Thiagarajan #include <linux/vmalloc.h>
19ee40fa06SPaul Gortmaker #include <linux/export.h>
20203c4805SLuis R. Rodriguez #include <asm/unaligned.h>
21203c4805SLuis R. Rodriguez 
22203c4805SLuis R. Rodriguez #include "ath9k.h"
23203c4805SLuis R. Rodriguez 
24475a6e4dSLuis R. Rodriguez #define REG_WRITE_D(_ah, _reg, _val) \
25475a6e4dSLuis R. Rodriguez 	ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg))
26475a6e4dSLuis R. Rodriguez #define REG_READ_D(_ah, _reg) \
27475a6e4dSLuis R. Rodriguez 	ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
28475a6e4dSLuis R. Rodriguez 
29203c4805SLuis R. Rodriguez 
30582d0064SVasanthakumar Thiagarajan static ssize_t ath9k_debugfs_read_buf(struct file *file, char __user *user_buf,
31582d0064SVasanthakumar Thiagarajan 				      size_t count, loff_t *ppos)
32582d0064SVasanthakumar Thiagarajan {
33582d0064SVasanthakumar Thiagarajan 	u8 *buf = file->private_data;
34582d0064SVasanthakumar Thiagarajan 	return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
35582d0064SVasanthakumar Thiagarajan }
36582d0064SVasanthakumar Thiagarajan 
37582d0064SVasanthakumar Thiagarajan static int ath9k_debugfs_release_buf(struct inode *inode, struct file *file)
38582d0064SVasanthakumar Thiagarajan {
39582d0064SVasanthakumar Thiagarajan 	vfree(file->private_data);
40582d0064SVasanthakumar Thiagarajan 	return 0;
41582d0064SVasanthakumar Thiagarajan }
42582d0064SVasanthakumar Thiagarajan 
43a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
44a830df07SFelix Fietkau 
452493928eSJeff Hansen static ssize_t read_file_debug(struct file *file, char __user *user_buf,
462493928eSJeff Hansen 			     size_t count, loff_t *ppos)
472493928eSJeff Hansen {
482493928eSJeff Hansen 	struct ath_softc *sc = file->private_data;
49c46917bbSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
502493928eSJeff Hansen 	char buf[32];
51581f725cSVasanthakumar Thiagarajan 	unsigned int len;
52581f725cSVasanthakumar Thiagarajan 
532b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", common->debug_mask);
542493928eSJeff Hansen 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
552493928eSJeff Hansen }
562493928eSJeff Hansen 
572493928eSJeff Hansen static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
582493928eSJeff Hansen 			     size_t count, loff_t *ppos)
592493928eSJeff Hansen {
602493928eSJeff Hansen 	struct ath_softc *sc = file->private_data;
61c46917bbSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
622493928eSJeff Hansen 	unsigned long mask;
632493928eSJeff Hansen 	char buf[32];
64581f725cSVasanthakumar Thiagarajan 	ssize_t len;
65581f725cSVasanthakumar Thiagarajan 
66581f725cSVasanthakumar Thiagarajan 	len = min(count, sizeof(buf) - 1);
67581f725cSVasanthakumar Thiagarajan 	if (copy_from_user(buf, user_buf, len))
6804236066SDan Carpenter 		return -EFAULT;
69581f725cSVasanthakumar Thiagarajan 
70581f725cSVasanthakumar Thiagarajan 	buf[len] = '\0';
71581f725cSVasanthakumar Thiagarajan 	if (strict_strtoul(buf, 0, &mask))
72581f725cSVasanthakumar Thiagarajan 		return -EINVAL;
73581f725cSVasanthakumar Thiagarajan 
74c46917bbSLuis R. Rodriguez 	common->debug_mask = mask;
752493928eSJeff Hansen 	return count;
762493928eSJeff Hansen }
772493928eSJeff Hansen 
782493928eSJeff Hansen static const struct file_operations fops_debug = {
792493928eSJeff Hansen 	.read = read_file_debug,
802493928eSJeff Hansen 	.write = write_file_debug,
81234e3405SStephen Boyd 	.open = simple_open,
826038f373SArnd Bergmann 	.owner = THIS_MODULE,
836038f373SArnd Bergmann 	.llseek = default_llseek,
842493928eSJeff Hansen };
852493928eSJeff Hansen 
86a830df07SFelix Fietkau #endif
87a830df07SFelix Fietkau 
88991a0987SPavel Roskin #define DMA_BUF_LEN 1024
89991a0987SPavel Roskin 
9015340694SFelix Fietkau static ssize_t read_file_tx_chainmask(struct file *file, char __user *user_buf,
9115340694SFelix Fietkau 			     size_t count, loff_t *ppos)
9215340694SFelix Fietkau {
9315340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
9482b2d334SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
9515340694SFelix Fietkau 	char buf[32];
9615340694SFelix Fietkau 	unsigned int len;
9715340694SFelix Fietkau 
9882b2d334SFelix Fietkau 	len = sprintf(buf, "0x%08x\n", ah->txchainmask);
9915340694SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
10015340694SFelix Fietkau }
10115340694SFelix Fietkau 
10215340694SFelix Fietkau static ssize_t write_file_tx_chainmask(struct file *file, const char __user *user_buf,
10315340694SFelix Fietkau 			     size_t count, loff_t *ppos)
10415340694SFelix Fietkau {
10515340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
10682b2d334SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
10715340694SFelix Fietkau 	unsigned long mask;
10815340694SFelix Fietkau 	char buf[32];
10915340694SFelix Fietkau 	ssize_t len;
11015340694SFelix Fietkau 
11115340694SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
11215340694SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
11304236066SDan Carpenter 		return -EFAULT;
11415340694SFelix Fietkau 
11515340694SFelix Fietkau 	buf[len] = '\0';
11615340694SFelix Fietkau 	if (strict_strtoul(buf, 0, &mask))
11715340694SFelix Fietkau 		return -EINVAL;
11815340694SFelix Fietkau 
11982b2d334SFelix Fietkau 	ah->txchainmask = mask;
12082b2d334SFelix Fietkau 	ah->caps.tx_chainmask = mask;
12115340694SFelix Fietkau 	return count;
12215340694SFelix Fietkau }
12315340694SFelix Fietkau 
12415340694SFelix Fietkau static const struct file_operations fops_tx_chainmask = {
12515340694SFelix Fietkau 	.read = read_file_tx_chainmask,
12615340694SFelix Fietkau 	.write = write_file_tx_chainmask,
127234e3405SStephen Boyd 	.open = simple_open,
1286038f373SArnd Bergmann 	.owner = THIS_MODULE,
1296038f373SArnd Bergmann 	.llseek = default_llseek,
13015340694SFelix Fietkau };
13115340694SFelix Fietkau 
13215340694SFelix Fietkau 
13315340694SFelix Fietkau static ssize_t read_file_rx_chainmask(struct file *file, char __user *user_buf,
13415340694SFelix Fietkau 			     size_t count, loff_t *ppos)
13515340694SFelix Fietkau {
13615340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
13782b2d334SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
13815340694SFelix Fietkau 	char buf[32];
13915340694SFelix Fietkau 	unsigned int len;
14015340694SFelix Fietkau 
14182b2d334SFelix Fietkau 	len = sprintf(buf, "0x%08x\n", ah->rxchainmask);
14215340694SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
14315340694SFelix Fietkau }
14415340694SFelix Fietkau 
14515340694SFelix Fietkau static ssize_t write_file_rx_chainmask(struct file *file, const char __user *user_buf,
14615340694SFelix Fietkau 			     size_t count, loff_t *ppos)
14715340694SFelix Fietkau {
14815340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
14982b2d334SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
15015340694SFelix Fietkau 	unsigned long mask;
15115340694SFelix Fietkau 	char buf[32];
15215340694SFelix Fietkau 	ssize_t len;
15315340694SFelix Fietkau 
15415340694SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
15515340694SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
15604236066SDan Carpenter 		return -EFAULT;
15715340694SFelix Fietkau 
15815340694SFelix Fietkau 	buf[len] = '\0';
15915340694SFelix Fietkau 	if (strict_strtoul(buf, 0, &mask))
16015340694SFelix Fietkau 		return -EINVAL;
16115340694SFelix Fietkau 
16282b2d334SFelix Fietkau 	ah->rxchainmask = mask;
16382b2d334SFelix Fietkau 	ah->caps.rx_chainmask = mask;
16415340694SFelix Fietkau 	return count;
16515340694SFelix Fietkau }
16615340694SFelix Fietkau 
16715340694SFelix Fietkau static const struct file_operations fops_rx_chainmask = {
16815340694SFelix Fietkau 	.read = read_file_rx_chainmask,
16915340694SFelix Fietkau 	.write = write_file_rx_chainmask,
170234e3405SStephen Boyd 	.open = simple_open,
1716038f373SArnd Bergmann 	.owner = THIS_MODULE,
1726038f373SArnd Bergmann 	.llseek = default_llseek,
17315340694SFelix Fietkau };
17415340694SFelix Fietkau 
17505c0be2fSMohammed Shafi Shajakhan static ssize_t read_file_disable_ani(struct file *file, char __user *user_buf,
17605c0be2fSMohammed Shafi Shajakhan 			     size_t count, loff_t *ppos)
17705c0be2fSMohammed Shafi Shajakhan {
17805c0be2fSMohammed Shafi Shajakhan 	struct ath_softc *sc = file->private_data;
17905c0be2fSMohammed Shafi Shajakhan 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
18005c0be2fSMohammed Shafi Shajakhan 	char buf[32];
18105c0be2fSMohammed Shafi Shajakhan 	unsigned int len;
18205c0be2fSMohammed Shafi Shajakhan 
18305c0be2fSMohammed Shafi Shajakhan 	len = sprintf(buf, "%d\n", common->disable_ani);
18405c0be2fSMohammed Shafi Shajakhan 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
18505c0be2fSMohammed Shafi Shajakhan }
18605c0be2fSMohammed Shafi Shajakhan 
18705c0be2fSMohammed Shafi Shajakhan static ssize_t write_file_disable_ani(struct file *file,
18805c0be2fSMohammed Shafi Shajakhan 				      const char __user *user_buf,
18905c0be2fSMohammed Shafi Shajakhan 				      size_t count, loff_t *ppos)
19005c0be2fSMohammed Shafi Shajakhan {
19105c0be2fSMohammed Shafi Shajakhan 	struct ath_softc *sc = file->private_data;
19205c0be2fSMohammed Shafi Shajakhan 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
19305c0be2fSMohammed Shafi Shajakhan 	unsigned long disable_ani;
19405c0be2fSMohammed Shafi Shajakhan 	char buf[32];
19505c0be2fSMohammed Shafi Shajakhan 	ssize_t len;
19605c0be2fSMohammed Shafi Shajakhan 
19705c0be2fSMohammed Shafi Shajakhan 	len = min(count, sizeof(buf) - 1);
19805c0be2fSMohammed Shafi Shajakhan 	if (copy_from_user(buf, user_buf, len))
19905c0be2fSMohammed Shafi Shajakhan 		return -EFAULT;
20005c0be2fSMohammed Shafi Shajakhan 
20105c0be2fSMohammed Shafi Shajakhan 	buf[len] = '\0';
20205c0be2fSMohammed Shafi Shajakhan 	if (strict_strtoul(buf, 0, &disable_ani))
20305c0be2fSMohammed Shafi Shajakhan 		return -EINVAL;
20405c0be2fSMohammed Shafi Shajakhan 
20505c0be2fSMohammed Shafi Shajakhan 	common->disable_ani = !!disable_ani;
20605c0be2fSMohammed Shafi Shajakhan 
20705c0be2fSMohammed Shafi Shajakhan 	if (disable_ani) {
208781b14a3SSujith Manoharan 		clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
209da0d45f7SSujith Manoharan 		ath_stop_ani(sc);
21005c0be2fSMohammed Shafi Shajakhan 	} else {
211da0d45f7SSujith Manoharan 		ath_check_ani(sc);
21205c0be2fSMohammed Shafi Shajakhan 	}
21305c0be2fSMohammed Shafi Shajakhan 
21405c0be2fSMohammed Shafi Shajakhan 	return count;
21505c0be2fSMohammed Shafi Shajakhan }
21605c0be2fSMohammed Shafi Shajakhan 
21705c0be2fSMohammed Shafi Shajakhan static const struct file_operations fops_disable_ani = {
21805c0be2fSMohammed Shafi Shajakhan 	.read = read_file_disable_ani,
21905c0be2fSMohammed Shafi Shajakhan 	.write = write_file_disable_ani,
220234e3405SStephen Boyd 	.open = simple_open,
22105c0be2fSMohammed Shafi Shajakhan 	.owner = THIS_MODULE,
22205c0be2fSMohammed Shafi Shajakhan 	.llseek = default_llseek,
22305c0be2fSMohammed Shafi Shajakhan };
22415340694SFelix Fietkau 
225203c4805SLuis R. Rodriguez static ssize_t read_file_dma(struct file *file, char __user *user_buf,
226203c4805SLuis R. Rodriguez 			     size_t count, loff_t *ppos)
227203c4805SLuis R. Rodriguez {
228203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
229203c4805SLuis R. Rodriguez 	struct ath_hw *ah = sc->sc_ah;
230991a0987SPavel Roskin 	char *buf;
231991a0987SPavel Roskin 	int retval;
232203c4805SLuis R. Rodriguez 	unsigned int len = 0;
233203c4805SLuis R. Rodriguez 	u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
234203c4805SLuis R. Rodriguez 	int i, qcuOffset = 0, dcuOffset = 0;
235203c4805SLuis R. Rodriguez 	u32 *qcuBase = &val[0], *dcuBase = &val[4];
236203c4805SLuis R. Rodriguez 
237991a0987SPavel Roskin 	buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
238991a0987SPavel Roskin 	if (!buf)
23904236066SDan Carpenter 		return -ENOMEM;
240991a0987SPavel Roskin 
2417cf4a2e7SSujith 	ath9k_ps_wakeup(sc);
2427cf4a2e7SSujith 
243475a6e4dSLuis R. Rodriguez 	REG_WRITE_D(ah, AR_MACMISC,
244203c4805SLuis R. Rodriguez 		  ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
245203c4805SLuis R. Rodriguez 		   (AR_MACMISC_MISC_OBS_BUS_1 <<
246203c4805SLuis R. Rodriguez 		    AR_MACMISC_MISC_OBS_BUS_MSB_S)));
247203c4805SLuis R. Rodriguez 
248991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
249203c4805SLuis R. Rodriguez 			"Raw DMA Debug values:\n");
250203c4805SLuis R. Rodriguez 
251203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
252203c4805SLuis R. Rodriguez 		if (i % 4 == 0)
253991a0987SPavel Roskin 			len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
254203c4805SLuis R. Rodriguez 
255475a6e4dSLuis R. Rodriguez 		val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
256991a0987SPavel Roskin 		len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
257203c4805SLuis R. Rodriguez 				i, val[i]);
258203c4805SLuis R. Rodriguez 	}
259203c4805SLuis R. Rodriguez 
260991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
261991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
262203c4805SLuis R. Rodriguez 			"Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
263203c4805SLuis R. Rodriguez 
264203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
265203c4805SLuis R. Rodriguez 		if (i == 8) {
266203c4805SLuis R. Rodriguez 			qcuOffset = 0;
267203c4805SLuis R. Rodriguez 			qcuBase++;
268203c4805SLuis R. Rodriguez 		}
269203c4805SLuis R. Rodriguez 
270203c4805SLuis R. Rodriguez 		if (i == 6) {
271203c4805SLuis R. Rodriguez 			dcuOffset = 0;
272203c4805SLuis R. Rodriguez 			dcuBase++;
273203c4805SLuis R. Rodriguez 		}
274203c4805SLuis R. Rodriguez 
275991a0987SPavel Roskin 		len += snprintf(buf + len, DMA_BUF_LEN - len,
276203c4805SLuis R. Rodriguez 			"%2d          %2x      %1x     %2x           %2x\n",
277203c4805SLuis R. Rodriguez 			i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
278203c4805SLuis R. Rodriguez 			(*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
279203c4805SLuis R. Rodriguez 			val[2] & (0x7 << (i * 3)) >> (i * 3),
280203c4805SLuis R. Rodriguez 			(*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
281203c4805SLuis R. Rodriguez 	}
282203c4805SLuis R. Rodriguez 
283991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
284203c4805SLuis R. Rodriguez 
285991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
286203c4805SLuis R. Rodriguez 		"qcu_stitch state:   %2x    qcu_fetch state:        %2x\n",
287203c4805SLuis R. Rodriguez 		(val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
288991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
289203c4805SLuis R. Rodriguez 		"qcu_complete state: %2x    dcu_complete state:     %2x\n",
290203c4805SLuis R. Rodriguez 		(val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
291991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
292203c4805SLuis R. Rodriguez 		"dcu_arb state:      %2x    dcu_fp state:           %2x\n",
293203c4805SLuis R. Rodriguez 		(val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
294991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
295203c4805SLuis R. Rodriguez 		"chan_idle_dur:     %3d    chan_idle_dur_valid:     %1d\n",
296203c4805SLuis R. Rodriguez 		(val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
297991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
298203c4805SLuis R. Rodriguez 		"txfifo_valid_0:      %1d    txfifo_valid_1:          %1d\n",
299203c4805SLuis R. Rodriguez 		(val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
300991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
301203c4805SLuis R. Rodriguez 		"txfifo_dcu_num_0:   %2d    txfifo_dcu_num_1:       %2d\n",
302203c4805SLuis R. Rodriguez 		(val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
303203c4805SLuis R. Rodriguez 
304991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
305475a6e4dSLuis R. Rodriguez 			REG_READ_D(ah, AR_OBS_BUS_1));
306991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
307475a6e4dSLuis R. Rodriguez 			"AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
308203c4805SLuis R. Rodriguez 
3097cf4a2e7SSujith 	ath9k_ps_restore(sc);
3107cf4a2e7SSujith 
3112b87f3aaSDan Carpenter 	if (len > DMA_BUF_LEN)
3122b87f3aaSDan Carpenter 		len = DMA_BUF_LEN;
3132b87f3aaSDan Carpenter 
314991a0987SPavel Roskin 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
315991a0987SPavel Roskin 	kfree(buf);
316991a0987SPavel Roskin 	return retval;
317203c4805SLuis R. Rodriguez }
318203c4805SLuis R. Rodriguez 
319203c4805SLuis R. Rodriguez static const struct file_operations fops_dma = {
320203c4805SLuis R. Rodriguez 	.read = read_file_dma,
321234e3405SStephen Boyd 	.open = simple_open,
3226038f373SArnd Bergmann 	.owner = THIS_MODULE,
3236038f373SArnd Bergmann 	.llseek = default_llseek,
324203c4805SLuis R. Rodriguez };
325203c4805SLuis R. Rodriguez 
326203c4805SLuis R. Rodriguez 
327203c4805SLuis R. Rodriguez void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
328203c4805SLuis R. Rodriguez {
329203c4805SLuis R. Rodriguez 	if (status)
330203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.total++;
331a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
332a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXLP)
333a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxlp++;
334a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXHP)
335a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxhp++;
33608578b8fSLuis R. Rodriguez 		if (status & ATH9K_INT_BB_WATCHDOG)
33708578b8fSLuis R. Rodriguez 			sc->debug.stats.istats.bb_watchdog++;
338a9616f41SLuis R. Rodriguez 	} else {
339203c4805SLuis R. Rodriguez 		if (status & ATH9K_INT_RX)
340203c4805SLuis R. Rodriguez 			sc->debug.stats.istats.rxok++;
341a9616f41SLuis R. Rodriguez 	}
342203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXEOL)
343203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxeol++;
344203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXORN)
345203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxorn++;
346203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TX)
347203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txok++;
348203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TXURN)
349203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txurn++;
350203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXPHY)
351203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxphyerr++;
352203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXKCM)
353203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rx_keycache_miss++;
354203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_SWBA)
355203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.swba++;
356203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BMISS)
357203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bmiss++;
358203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BNR)
359203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bnr++;
360203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CST)
361203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cst++;
362203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_GTT)
363203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.gtt++;
364203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TIM)
365203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.tim++;
366203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CABEND)
367203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cabend++;
368203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIMSYNC)
369203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtimsync++;
370203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIM)
371203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtim++;
3726dde1aabSMohammed Shafi Shajakhan 	if (status & ATH9K_INT_TSFOOR)
3736dde1aabSMohammed Shafi Shajakhan 		sc->debug.stats.istats.tsfoor++;
37497ba515aSSujith Manoharan 	if (status & ATH9K_INT_MCI)
37597ba515aSSujith Manoharan 		sc->debug.stats.istats.mci++;
376*c9e6e980SMohammed Shafi Shajakhan 	if (status & ATH9K_INT_GENTIMER)
377*c9e6e980SMohammed Shafi Shajakhan 		sc->debug.stats.istats.gen_timer++;
378203c4805SLuis R. Rodriguez }
379203c4805SLuis R. Rodriguez 
380203c4805SLuis R. Rodriguez static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
381203c4805SLuis R. Rodriguez 				   size_t count, loff_t *ppos)
382203c4805SLuis R. Rodriguez {
383203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
384203c4805SLuis R. Rodriguez 	unsigned int len = 0;
385462e58f2SBen Greear 	int rv;
386462e58f2SBen Greear 	int mxlen = 4000;
387462e58f2SBen Greear 	char *buf = kmalloc(mxlen, GFP_KERNEL);
388462e58f2SBen Greear 	if (!buf)
389462e58f2SBen Greear 		return -ENOMEM;
390462e58f2SBen Greear 
391462e58f2SBen Greear #define PR_IS(a, s)						\
392462e58f2SBen Greear 	do {							\
393462e58f2SBen Greear 		len += snprintf(buf + len, mxlen - len,		\
394462e58f2SBen Greear 				"%21s: %10u\n", a,		\
395462e58f2SBen Greear 				sc->debug.stats.istats.s);	\
396462e58f2SBen Greear 	} while (0)
397203c4805SLuis R. Rodriguez 
398a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
399462e58f2SBen Greear 		PR_IS("RXLP", rxlp);
400462e58f2SBen Greear 		PR_IS("RXHP", rxhp);
401462e58f2SBen Greear 		PR_IS("WATHDOG", bb_watchdog);
402a9616f41SLuis R. Rodriguez 	} else {
403462e58f2SBen Greear 		PR_IS("RX", rxok);
404a9616f41SLuis R. Rodriguez 	}
405462e58f2SBen Greear 	PR_IS("RXEOL", rxeol);
406462e58f2SBen Greear 	PR_IS("RXORN", rxorn);
407462e58f2SBen Greear 	PR_IS("TX", txok);
408462e58f2SBen Greear 	PR_IS("TXURN", txurn);
409462e58f2SBen Greear 	PR_IS("MIB", mib);
410462e58f2SBen Greear 	PR_IS("RXPHY", rxphyerr);
411462e58f2SBen Greear 	PR_IS("RXKCM", rx_keycache_miss);
412462e58f2SBen Greear 	PR_IS("SWBA", swba);
413462e58f2SBen Greear 	PR_IS("BMISS", bmiss);
414462e58f2SBen Greear 	PR_IS("BNR", bnr);
415462e58f2SBen Greear 	PR_IS("CST", cst);
416462e58f2SBen Greear 	PR_IS("GTT", gtt);
417462e58f2SBen Greear 	PR_IS("TIM", tim);
418462e58f2SBen Greear 	PR_IS("CABEND", cabend);
419462e58f2SBen Greear 	PR_IS("DTIMSYNC", dtimsync);
420462e58f2SBen Greear 	PR_IS("DTIM", dtim);
421462e58f2SBen Greear 	PR_IS("TSFOOR", tsfoor);
42297ba515aSSujith Manoharan 	PR_IS("MCI", mci);
423*c9e6e980SMohammed Shafi Shajakhan 	PR_IS("GENTIMER", gen_timer);
424462e58f2SBen Greear 	PR_IS("TOTAL", total);
425203c4805SLuis R. Rodriguez 
426462e58f2SBen Greear 	len += snprintf(buf + len, mxlen - len,
427462e58f2SBen Greear 			"SYNC_CAUSE stats:\n");
4286dde1aabSMohammed Shafi Shajakhan 
429462e58f2SBen Greear 	PR_IS("Sync-All", sync_cause_all);
430462e58f2SBen Greear 	PR_IS("RTC-IRQ", sync_rtc_irq);
431462e58f2SBen Greear 	PR_IS("MAC-IRQ", sync_mac_irq);
432462e58f2SBen Greear 	PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
433462e58f2SBen Greear 	PR_IS("APB-Timeout", apb_timeout);
434462e58f2SBen Greear 	PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
435462e58f2SBen Greear 	PR_IS("HOST1-Fatal", host1_fatal);
436462e58f2SBen Greear 	PR_IS("HOST1-Perr", host1_perr);
437462e58f2SBen Greear 	PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
438462e58f2SBen Greear 	PR_IS("RADM-CPL-EP", radm_cpl_ep);
439462e58f2SBen Greear 	PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
440462e58f2SBen Greear 	PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
441462e58f2SBen Greear 	PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
442462e58f2SBen Greear 	PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
443462e58f2SBen Greear 	PR_IS("Local-Bus-Timeout", local_timeout);
444462e58f2SBen Greear 	PR_IS("PM-Access", pm_access);
445462e58f2SBen Greear 	PR_IS("MAC-Awake", mac_awake);
446462e58f2SBen Greear 	PR_IS("MAC-Asleep", mac_asleep);
447462e58f2SBen Greear 	PR_IS("MAC-Sleep-Access", mac_sleep_access);
4482b87f3aaSDan Carpenter 
449462e58f2SBen Greear 	if (len > mxlen)
450462e58f2SBen Greear 		len = mxlen;
451462e58f2SBen Greear 
452462e58f2SBen Greear 	rv = simple_read_from_buffer(user_buf, count, ppos, buf, len);
453462e58f2SBen Greear 	kfree(buf);
454462e58f2SBen Greear 	return rv;
455203c4805SLuis R. Rodriguez }
456203c4805SLuis R. Rodriguez 
457203c4805SLuis R. Rodriguez static const struct file_operations fops_interrupt = {
458203c4805SLuis R. Rodriguez 	.read = read_file_interrupt,
459234e3405SStephen Boyd 	.open = simple_open,
4606038f373SArnd Bergmann 	.owner = THIS_MODULE,
4616038f373SArnd Bergmann 	.llseek = default_llseek,
462203c4805SLuis R. Rodriguez };
463203c4805SLuis R. Rodriguez 
4645bec3e5aSFelix Fietkau #define PR_QNUM(_n) sc->tx.txq_map[_n]->axq_qnum
465fec247c0SSujith #define PR(str, elem)							\
466fec247c0SSujith 	do {								\
467fec247c0SSujith 		len += snprintf(buf + len, size - len,			\
468fec247c0SSujith 				"%s%13u%11u%10u%10u\n", str,		\
4695bec3e5aSFelix Fietkau 		sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].elem, \
4705bec3e5aSFelix Fietkau 		sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].elem, \
4715bec3e5aSFelix Fietkau 		sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].elem, \
4725bec3e5aSFelix Fietkau 		sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].elem); \
4737f010c93SBen Greear 		if (len >= size)			  \
4747f010c93SBen Greear 			goto done;			  \
475fec247c0SSujith } while(0)
476fec247c0SSujith 
4771f427dd9SBen Greear #define PRX(str, elem)							\
4781f427dd9SBen Greear do {									\
4791f427dd9SBen Greear 	len += snprintf(buf + len, size - len,				\
4801f427dd9SBen Greear 			"%s%13u%11u%10u%10u\n", str,			\
4815bec3e5aSFelix Fietkau 			(unsigned int)(sc->tx.txq_map[WME_AC_BE]->elem),	\
4825bec3e5aSFelix Fietkau 			(unsigned int)(sc->tx.txq_map[WME_AC_BK]->elem),	\
4835bec3e5aSFelix Fietkau 			(unsigned int)(sc->tx.txq_map[WME_AC_VI]->elem),	\
4845bec3e5aSFelix Fietkau 			(unsigned int)(sc->tx.txq_map[WME_AC_VO]->elem));	\
4857f010c93SBen Greear 	if (len >= size)						\
4867f010c93SBen Greear 		goto done;						\
4871f427dd9SBen Greear } while(0)
4881f427dd9SBen Greear 
4892dac4fb9SBen Greear #define PRQLE(str, elem)						\
4902dac4fb9SBen Greear do {									\
4912dac4fb9SBen Greear 	len += snprintf(buf + len, size - len,				\
4922dac4fb9SBen Greear 			"%s%13i%11i%10i%10i\n", str,			\
4935bec3e5aSFelix Fietkau 			list_empty(&sc->tx.txq_map[WME_AC_BE]->elem),	\
4945bec3e5aSFelix Fietkau 			list_empty(&sc->tx.txq_map[WME_AC_BK]->elem),	\
4955bec3e5aSFelix Fietkau 			list_empty(&sc->tx.txq_map[WME_AC_VI]->elem),	\
4965bec3e5aSFelix Fietkau 			list_empty(&sc->tx.txq_map[WME_AC_VO]->elem));	\
4977f010c93SBen Greear 	if (len >= size)						\
4987f010c93SBen Greear 		goto done;						\
4992dac4fb9SBen Greear } while (0)
5002dac4fb9SBen Greear 
501fec247c0SSujith static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
502fec247c0SSujith 			      size_t count, loff_t *ppos)
503fec247c0SSujith {
504fec247c0SSujith 	struct ath_softc *sc = file->private_data;
505fec247c0SSujith 	char *buf;
5067f010c93SBen Greear 	unsigned int len = 0, size = 8000;
5072dac4fb9SBen Greear 	int i;
508fec247c0SSujith 	ssize_t retval = 0;
5092dac4fb9SBen Greear 	char tmp[32];
510fec247c0SSujith 
511fec247c0SSujith 	buf = kzalloc(size, GFP_KERNEL);
512fec247c0SSujith 	if (buf == NULL)
51304236066SDan Carpenter 		return -ENOMEM;
514fec247c0SSujith 
51560f2d1d5SBen Greear 	len += sprintf(buf, "Num-Tx-Queues: %i  tx-queues-setup: 0x%x"
51660f2d1d5SBen Greear 		       " poll-work-seen: %u\n"
5177f010c93SBen Greear 		       "%30s %10s%10s%10s\n\n",
5187f010c93SBen Greear 		       ATH9K_NUM_TX_QUEUES, sc->tx.txqsetup,
51960f2d1d5SBen Greear 		       sc->tx_complete_poll_work_seen,
5207f010c93SBen Greear 		       "BE", "BK", "VI", "VO");
521fec247c0SSujith 
522fec247c0SSujith 	PR("MPDUs Queued:    ", queued);
523fec247c0SSujith 	PR("MPDUs Completed: ", completed);
5245a6f78afSFelix Fietkau 	PR("MPDUs XRetried:  ", xretries);
525fec247c0SSujith 	PR("Aggregates:      ", a_aggr);
526bda8addaSBen Greear 	PR("AMPDUs Queued HW:", a_queued_hw);
527bda8addaSBen Greear 	PR("AMPDUs Queued SW:", a_queued_sw);
528fec247c0SSujith 	PR("AMPDUs Completed:", a_completed);
529fec247c0SSujith 	PR("AMPDUs Retried:  ", a_retries);
530fec247c0SSujith 	PR("AMPDUs XRetried: ", a_xretries);
531fec247c0SSujith 	PR("FIFO Underrun:   ", fifo_underrun);
532fec247c0SSujith 	PR("TXOP Exceeded:   ", xtxop);
533fec247c0SSujith 	PR("TXTIMER Expiry:  ", timer_exp);
534fec247c0SSujith 	PR("DESC CFG Error:  ", desc_cfg_err);
535fec247c0SSujith 	PR("DATA Underrun:   ", data_underrun);
536fec247c0SSujith 	PR("DELIM Underrun:  ", delim_underrun);
53799c15bf5SBen Greear 	PR("TX-Pkts-All:     ", tx_pkts_all);
53899c15bf5SBen Greear 	PR("TX-Bytes-All:    ", tx_bytes_all);
5392dac4fb9SBen Greear 	PR("hw-put-tx-buf:   ", puttxbuf);
5402dac4fb9SBen Greear 	PR("hw-tx-start:     ", txstart);
5412dac4fb9SBen Greear 	PR("hw-tx-proc-desc: ", txprocdesc);
542a5a0bca1SBen Greear 	PR("TX-Failed:       ", txfailed);
5437f010c93SBen Greear 	len += snprintf(buf + len, size - len,
5447f010c93SBen Greear 			"%s%11p%11p%10p%10p\n", "txq-memory-address:",
545db7889cdSBen Greear 			sc->tx.txq_map[WME_AC_BE],
546db7889cdSBen Greear 			sc->tx.txq_map[WME_AC_BK],
547db7889cdSBen Greear 			sc->tx.txq_map[WME_AC_VI],
548db7889cdSBen Greear 			sc->tx.txq_map[WME_AC_VO]);
5497f010c93SBen Greear 	if (len >= size)
5507f010c93SBen Greear 		goto done;
551fec247c0SSujith 
5521f427dd9SBen Greear 	PRX("axq-qnum:        ", axq_qnum);
5531f427dd9SBen Greear 	PRX("axq-depth:       ", axq_depth);
5542dac4fb9SBen Greear 	PRX("axq-ampdu_depth: ", axq_ampdu_depth);
5551f427dd9SBen Greear 	PRX("axq-stopped      ", stopped);
5561f427dd9SBen Greear 	PRX("tx-in-progress   ", axq_tx_inprogress);
5571f427dd9SBen Greear 	PRX("pending-frames   ", pending_frames);
5582dac4fb9SBen Greear 	PRX("txq_headidx:     ", txq_headidx);
5592dac4fb9SBen Greear 	PRX("txq_tailidx:     ", txq_headidx);
5601f427dd9SBen Greear 
5612dac4fb9SBen Greear 	PRQLE("axq_q empty:       ", axq_q);
5622dac4fb9SBen Greear 	PRQLE("axq_acq empty:     ", axq_acq);
5632dac4fb9SBen Greear 	for (i = 0; i < ATH_TXFIFO_DEPTH; i++) {
5642dac4fb9SBen Greear 		snprintf(tmp, sizeof(tmp) - 1, "txq_fifo[%i] empty: ", i);
5652dac4fb9SBen Greear 		PRQLE(tmp, txq_fifo[i]);
5662dac4fb9SBen Greear 	}
5677f010c93SBen Greear 
56871e025a5SBen Greear 	/* Print out more detailed queue-info */
56971e025a5SBen Greear 	for (i = 0; i <= WME_AC_BK; i++) {
57071e025a5SBen Greear 		struct ath_txq *txq = &(sc->tx.txq[i]);
57171e025a5SBen Greear 		struct ath_atx_ac *ac;
57271e025a5SBen Greear 		struct ath_atx_tid *tid;
57371e025a5SBen Greear 		if (len >= size)
57471e025a5SBen Greear 			goto done;
57571e025a5SBen Greear 		spin_lock_bh(&txq->axq_lock);
57671e025a5SBen Greear 		if (!list_empty(&txq->axq_acq)) {
57771e025a5SBen Greear 			ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac,
57871e025a5SBen Greear 					      list);
57971e025a5SBen Greear 			len += snprintf(buf + len, size - len,
58071e025a5SBen Greear 					"txq[%i] first-ac: %p sched: %i\n",
58171e025a5SBen Greear 					i, ac, ac->sched);
58271e025a5SBen Greear 			if (list_empty(&ac->tid_q) || (len >= size))
58371e025a5SBen Greear 				goto done_for;
58471e025a5SBen Greear 			tid = list_first_entry(&ac->tid_q, struct ath_atx_tid,
58571e025a5SBen Greear 					       list);
58671e025a5SBen Greear 			len += snprintf(buf + len, size - len,
58771e025a5SBen Greear 					" first-tid: %p sched: %i paused: %i\n",
58871e025a5SBen Greear 					tid, tid->sched, tid->paused);
58971e025a5SBen Greear 		}
59071e025a5SBen Greear 	done_for:
59171e025a5SBen Greear 		spin_unlock_bh(&txq->axq_lock);
59271e025a5SBen Greear 	}
59371e025a5SBen Greear 
5947f010c93SBen Greear done:
5957f010c93SBen Greear 	if (len > size)
5967f010c93SBen Greear 		len = size;
5977f010c93SBen Greear 
5987f010c93SBen Greear 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
5997f010c93SBen Greear 	kfree(buf);
6007f010c93SBen Greear 
6017f010c93SBen Greear 	return retval;
6027f010c93SBen Greear }
6037f010c93SBen Greear 
6047f010c93SBen Greear static ssize_t read_file_stations(struct file *file, char __user *user_buf,
6057f010c93SBen Greear 				  size_t count, loff_t *ppos)
6067f010c93SBen Greear {
6077f010c93SBen Greear 	struct ath_softc *sc = file->private_data;
6087f010c93SBen Greear 	char *buf;
6097f010c93SBen Greear 	unsigned int len = 0, size = 64000;
6107f010c93SBen Greear 	struct ath_node *an = NULL;
6117f010c93SBen Greear 	ssize_t retval = 0;
6127f010c93SBen Greear 	int q;
6137f010c93SBen Greear 
6147f010c93SBen Greear 	buf = kzalloc(size, GFP_KERNEL);
6157f010c93SBen Greear 	if (buf == NULL)
6167f010c93SBen Greear 		return -ENOMEM;
6177f010c93SBen Greear 
6187f010c93SBen Greear 	len += snprintf(buf + len, size - len,
6197f010c93SBen Greear 			"Stations:\n"
6207e1e3864SBen Greear 			" tid: addr sched paused buf_q-empty an ac baw\n"
6217f010c93SBen Greear 			" ac: addr sched tid_q-empty txq\n");
6227f010c93SBen Greear 
6237f010c93SBen Greear 	spin_lock(&sc->nodes_lock);
6247f010c93SBen Greear 	list_for_each_entry(an, &sc->nodes, list) {
6257e1e3864SBen Greear 		unsigned short ma = an->maxampdu;
6267e1e3864SBen Greear 		if (ma == 0)
6277e1e3864SBen Greear 			ma = 65535; /* see ath_lookup_rate */
6287f010c93SBen Greear 		len += snprintf(buf + len, size - len,
6297e1e3864SBen Greear 				"iface: %pM  sta: %pM max-ampdu: %hu mpdu-density: %uus\n",
6307e1e3864SBen Greear 				an->vif->addr, an->sta->addr, ma,
6317e1e3864SBen Greear 				(unsigned int)(an->mpdudensity));
6327f010c93SBen Greear 		if (len >= size)
6337f010c93SBen Greear 			goto done;
6347f010c93SBen Greear 
6357f010c93SBen Greear 		for (q = 0; q < WME_NUM_TID; q++) {
6367f010c93SBen Greear 			struct ath_atx_tid *tid = &(an->tid[q]);
6377f010c93SBen Greear 			len += snprintf(buf + len, size - len,
6387e1e3864SBen Greear 					" tid: %p %s %s %i %p %p %hu\n",
6397f010c93SBen Greear 					tid, tid->sched ? "sched" : "idle",
6407f010c93SBen Greear 					tid->paused ? "paused" : "running",
64156dc6336SFelix Fietkau 					skb_queue_empty(&tid->buf_q),
6427e1e3864SBen Greear 					tid->an, tid->ac, tid->baw_size);
6437f010c93SBen Greear 			if (len >= size)
6447f010c93SBen Greear 				goto done;
6457f010c93SBen Greear 		}
6467f010c93SBen Greear 
6477f010c93SBen Greear 		for (q = 0; q < WME_NUM_AC; q++) {
6487f010c93SBen Greear 			struct ath_atx_ac *ac = &(an->ac[q]);
6497f010c93SBen Greear 			len += snprintf(buf + len, size - len,
6507f010c93SBen Greear 					" ac: %p %s %i %p\n",
6517f010c93SBen Greear 					ac, ac->sched ? "sched" : "idle",
6527f010c93SBen Greear 					list_empty(&ac->tid_q), ac->txq);
6537f010c93SBen Greear 			if (len >= size)
6547f010c93SBen Greear 				goto done;
6557f010c93SBen Greear 		}
6567f010c93SBen Greear 	}
6577f010c93SBen Greear 
6587f010c93SBen Greear done:
6597f010c93SBen Greear 	spin_unlock(&sc->nodes_lock);
6602b87f3aaSDan Carpenter 	if (len > size)
6612b87f3aaSDan Carpenter 		len = size;
6622b87f3aaSDan Carpenter 
663fec247c0SSujith 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
664fec247c0SSujith 	kfree(buf);
665fec247c0SSujith 
666fec247c0SSujith 	return retval;
667fec247c0SSujith }
668fec247c0SSujith 
66955f6d0ffSBen Greear static ssize_t read_file_misc(struct file *file, char __user *user_buf,
67055f6d0ffSBen Greear 			      size_t count, loff_t *ppos)
67155f6d0ffSBen Greear {
67255f6d0ffSBen Greear 	struct ath_softc *sc = file->private_data;
67355f6d0ffSBen Greear 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
67455f6d0ffSBen Greear 	struct ieee80211_hw *hw = sc->hw;
6756bcf6f64SSujith Manoharan 	struct ath9k_vif_iter_data iter_data;
6766bcf6f64SSujith Manoharan 	char buf[512];
6776bcf6f64SSujith Manoharan 	unsigned int len = 0;
67855f6d0ffSBen Greear 	ssize_t retval = 0;
67955f6d0ffSBen Greear 	unsigned int reg;
6806bcf6f64SSujith Manoharan 	u32 rxfilter;
6816bcf6f64SSujith Manoharan 
6826bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
6836bcf6f64SSujith Manoharan 			"BSSID: %pM\n", common->curbssid);
6846bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
6856bcf6f64SSujith Manoharan 			"BSSID-MASK: %pM\n", common->bssidmask);
6866bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
6876bcf6f64SSujith Manoharan 			"OPMODE: %s\n", ath_opmode_to_string(sc->sc_ah->opmode));
6886bcf6f64SSujith Manoharan 
6896bcf6f64SSujith Manoharan 	ath9k_ps_wakeup(sc);
6906bcf6f64SSujith Manoharan 	rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
6916bcf6f64SSujith Manoharan 	ath9k_ps_restore(sc);
6926bcf6f64SSujith Manoharan 
6936bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
6946bcf6f64SSujith Manoharan 			"RXFILTER: 0x%x", rxfilter);
6956bcf6f64SSujith Manoharan 
6966bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_UCAST)
6976bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " UCAST");
6986bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MCAST)
6996bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " MCAST");
7006bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_BCAST)
7016bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " BCAST");
7026bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_CONTROL)
7036bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " CONTROL");
7046bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_BEACON)
7056bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " BEACON");
7066bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PROM)
7076bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " PROM");
7086bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
7096bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
7106bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PHYERR)
7116bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " PHYERR");
7126bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
7136bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " MYBEACON");
7146bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
7156bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
7166bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
7176bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " PSPOLL");
7186bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
7196bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
7206bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
7216bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL");
7226bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
7236bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " CONTROL_WRAPPER");
7246bcf6f64SSujith Manoharan 
7256bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len, "\n");
7266bcf6f64SSujith Manoharan 
7276bcf6f64SSujith Manoharan 	reg = sc->sc_ah->imask;
7286bcf6f64SSujith Manoharan 
7296bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len, "INTERRUPT-MASK: 0x%x", reg);
7306bcf6f64SSujith Manoharan 
7316bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_SWBA)
7326bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " SWBA");
7336bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_BMISS)
7346bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " BMISS");
7356bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_CST)
7366bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " CST");
7376bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RX)
7386bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " RX");
7396bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RXHP)
7406bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " RXHP");
7416bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RXLP)
7426bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " RXLP");
7436bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_BB_WATCHDOG)
7446bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " BB_WATCHDOG");
7456bcf6f64SSujith Manoharan 
7466bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len, "\n");
74755f6d0ffSBen Greear 
74855f6d0ffSBen Greear 	ath9k_calculate_iter_data(hw, NULL, &iter_data);
74955f6d0ffSBen Greear 
7506bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
7516bcf6f64SSujith Manoharan 			"VIF-COUNTS: AP: %i STA: %i MESH: %i WDS: %i"
752bcf6f96eSSujith Manoharan 			" ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n",
75355f6d0ffSBen Greear 			iter_data.naps, iter_data.nstations, iter_data.nmeshes,
754bcf6f96eSSujith Manoharan 			iter_data.nwds, iter_data.nadhocs,
75555f6d0ffSBen Greear 			sc->nvifs, sc->nbcnvifs);
75655f6d0ffSBen Greear 
7576bcf6f64SSujith Manoharan 	if (len > sizeof(buf))
7586bcf6f64SSujith Manoharan 		len = sizeof(buf);
75955f6d0ffSBen Greear 
76055f6d0ffSBen Greear 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
76155f6d0ffSBen Greear 	return retval;
76255f6d0ffSBen Greear }
76355f6d0ffSBen Greear 
764f8b815dcSSujith Manoharan static ssize_t read_file_reset(struct file *file, char __user *user_buf,
765f8b815dcSSujith Manoharan 			       size_t count, loff_t *ppos)
766f8b815dcSSujith Manoharan {
767f8b815dcSSujith Manoharan 	struct ath_softc *sc = file->private_data;
768f8b815dcSSujith Manoharan 	char buf[512];
769f8b815dcSSujith Manoharan 	unsigned int len = 0;
770f8b815dcSSujith Manoharan 
771f8b815dcSSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
772f8b815dcSSujith Manoharan 			"%17s: %2d\n", "Baseband Hang",
773f8b815dcSSujith Manoharan 			sc->debug.stats.reset[RESET_TYPE_BB_HANG]);
774f8b815dcSSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
775f8b815dcSSujith Manoharan 			"%17s: %2d\n", "Baseband Watchdog",
776f8b815dcSSujith Manoharan 			sc->debug.stats.reset[RESET_TYPE_BB_WATCHDOG]);
777f8b815dcSSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
778f8b815dcSSujith Manoharan 			"%17s: %2d\n", "Fatal HW Error",
779f8b815dcSSujith Manoharan 			sc->debug.stats.reset[RESET_TYPE_FATAL_INT]);
780f8b815dcSSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
781f8b815dcSSujith Manoharan 			"%17s: %2d\n", "TX HW error",
782f8b815dcSSujith Manoharan 			sc->debug.stats.reset[RESET_TYPE_TX_ERROR]);
783f8b815dcSSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
784f8b815dcSSujith Manoharan 			"%17s: %2d\n", "TX Path Hang",
785f8b815dcSSujith Manoharan 			sc->debug.stats.reset[RESET_TYPE_TX_HANG]);
786f8b815dcSSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
787f8b815dcSSujith Manoharan 			"%17s: %2d\n", "PLL RX Hang",
788f8b815dcSSujith Manoharan 			sc->debug.stats.reset[RESET_TYPE_PLL_HANG]);
789f8b815dcSSujith Manoharan 
790f8b815dcSSujith Manoharan 	if (len > sizeof(buf))
791f8b815dcSSujith Manoharan 		len = sizeof(buf);
792f8b815dcSSujith Manoharan 
793f8b815dcSSujith Manoharan 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
794f8b815dcSSujith Manoharan }
795f8b815dcSSujith Manoharan 
796066dae93SFelix Fietkau void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
79755797b1aSFelix Fietkau 		       struct ath_tx_status *ts, struct ath_txq *txq,
79855797b1aSFelix Fietkau 		       unsigned int flags)
799fec247c0SSujith {
800cf3af748SRajkumar Manoharan #define TX_SAMP_DBG(c) (sc->debug.bb_mac_samp[sc->debug.sampidx].ts\
801cf3af748SRajkumar Manoharan 			[sc->debug.tsidx].c)
8025bec3e5aSFelix Fietkau 	int qnum = txq->axq_qnum;
803066dae93SFelix Fietkau 
804066dae93SFelix Fietkau 	TX_STAT_INC(qnum, tx_pkts_all);
805066dae93SFelix Fietkau 	sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
80699c15bf5SBen Greear 
807fec247c0SSujith 	if (bf_isampdu(bf)) {
808156369faSFelix Fietkau 		if (flags & ATH_TX_ERROR)
809066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_xretries);
810fec247c0SSujith 		else
811066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_completed);
812fec247c0SSujith 	} else {
81355797b1aSFelix Fietkau 		if (ts->ts_status & ATH9K_TXERR_XRETRY)
8145a6f78afSFelix Fietkau 			TX_STAT_INC(qnum, xretries);
8155a6f78afSFelix Fietkau 		else
816066dae93SFelix Fietkau 			TX_STAT_INC(qnum, completed);
817fec247c0SSujith 	}
818fec247c0SSujith 
819db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_FIFO)
820066dae93SFelix Fietkau 		TX_STAT_INC(qnum, fifo_underrun);
821db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_XTXOP)
822066dae93SFelix Fietkau 		TX_STAT_INC(qnum, xtxop);
823db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
824066dae93SFelix Fietkau 		TX_STAT_INC(qnum, timer_exp);
825db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
826066dae93SFelix Fietkau 		TX_STAT_INC(qnum, desc_cfg_err);
827db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
828066dae93SFelix Fietkau 		TX_STAT_INC(qnum, data_underrun);
829db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
830066dae93SFelix Fietkau 		TX_STAT_INC(qnum, delim_underrun);
831cf3af748SRajkumar Manoharan 
8325baec742SFelix Fietkau #ifdef CONFIG_ATH9K_MAC_DEBUG
833cf3af748SRajkumar Manoharan 	spin_lock(&sc->debug.samp_lock);
834cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(jiffies) = jiffies;
835cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(rssi_ctl0) = ts->ts_rssi_ctl0;
836cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(rssi_ctl1) = ts->ts_rssi_ctl1;
837cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(rssi_ctl2) = ts->ts_rssi_ctl2;
838cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(rssi_ext0) = ts->ts_rssi_ext0;
839cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(rssi_ext1) = ts->ts_rssi_ext1;
840cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(rssi_ext2) = ts->ts_rssi_ext2;
841cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(rateindex) = ts->ts_rateindex;
842cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(isok) = !!(ts->ts_status & ATH9K_TXERR_MASK);
843cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(rts_fail_cnt) = ts->ts_shortretry;
844cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(data_fail_cnt) = ts->ts_longretry;
845cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(rssi) = ts->ts_rssi;
846cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(tid) = ts->tid;
847cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(qid) = ts->qid;
84812932180SMohammed Shafi Shajakhan 
84912932180SMohammed Shafi Shajakhan 	if (ts->ts_flags & ATH9K_TX_BA) {
85012932180SMohammed Shafi Shajakhan 		TX_SAMP_DBG(ba_low) = ts->ba_low;
85112932180SMohammed Shafi Shajakhan 		TX_SAMP_DBG(ba_high) = ts->ba_high;
85212932180SMohammed Shafi Shajakhan 	} else {
85312932180SMohammed Shafi Shajakhan 		TX_SAMP_DBG(ba_low) = 0;
85412932180SMohammed Shafi Shajakhan 		TX_SAMP_DBG(ba_high) = 0;
85512932180SMohammed Shafi Shajakhan 	}
85612932180SMohammed Shafi Shajakhan 
857cf3af748SRajkumar Manoharan 	sc->debug.tsidx = (sc->debug.tsidx + 1) % ATH_DBG_MAX_SAMPLES;
858cf3af748SRajkumar Manoharan 	spin_unlock(&sc->debug.samp_lock);
8595baec742SFelix Fietkau #endif
860cf3af748SRajkumar Manoharan 
861cf3af748SRajkumar Manoharan #undef TX_SAMP_DBG
862fec247c0SSujith }
863fec247c0SSujith 
864fec247c0SSujith static const struct file_operations fops_xmit = {
865fec247c0SSujith 	.read = read_file_xmit,
866234e3405SStephen Boyd 	.open = simple_open,
8676038f373SArnd Bergmann 	.owner = THIS_MODULE,
8686038f373SArnd Bergmann 	.llseek = default_llseek,
869fec247c0SSujith };
870203c4805SLuis R. Rodriguez 
8717f010c93SBen Greear static const struct file_operations fops_stations = {
8727f010c93SBen Greear 	.read = read_file_stations,
873234e3405SStephen Boyd 	.open = simple_open,
8747f010c93SBen Greear 	.owner = THIS_MODULE,
8757f010c93SBen Greear 	.llseek = default_llseek,
8767f010c93SBen Greear };
8777f010c93SBen Greear 
87855f6d0ffSBen Greear static const struct file_operations fops_misc = {
87955f6d0ffSBen Greear 	.read = read_file_misc,
880234e3405SStephen Boyd 	.open = simple_open,
88155f6d0ffSBen Greear 	.owner = THIS_MODULE,
88255f6d0ffSBen Greear 	.llseek = default_llseek,
88355f6d0ffSBen Greear };
88455f6d0ffSBen Greear 
885f8b815dcSSujith Manoharan static const struct file_operations fops_reset = {
886f8b815dcSSujith Manoharan 	.read = read_file_reset,
887234e3405SStephen Boyd 	.open = simple_open,
888f8b815dcSSujith Manoharan 	.owner = THIS_MODULE,
889f8b815dcSSujith Manoharan 	.llseek = default_llseek,
890f8b815dcSSujith Manoharan };
891f8b815dcSSujith Manoharan 
8921395d3f0SSujith static ssize_t read_file_recv(struct file *file, char __user *user_buf,
8931395d3f0SSujith 			      size_t count, loff_t *ppos)
8941395d3f0SSujith {
8951395d3f0SSujith #define PHY_ERR(s, p) \
8964203214eSSujith Manoharan 	len += snprintf(buf + len, size - len, "%22s : %10u\n", s, \
8971395d3f0SSujith 			sc->debug.stats.rxstats.phy_err_stats[p]);
8981395d3f0SSujith 
89924a0731eSBen Greear #define RXS_ERR(s, e)					    \
90024a0731eSBen Greear 	do {						    \
90124a0731eSBen Greear 		len += snprintf(buf + len, size - len,	    \
90224a0731eSBen Greear 				"%22s : %10u\n", s,	    \
90324a0731eSBen Greear 				sc->debug.stats.rxstats.e); \
90424a0731eSBen Greear 	} while (0)
90524a0731eSBen Greear 
9061395d3f0SSujith 	struct ath_softc *sc = file->private_data;
9071395d3f0SSujith 	char *buf;
9084203214eSSujith Manoharan 	unsigned int len = 0, size = 1600;
9091395d3f0SSujith 	ssize_t retval = 0;
9101395d3f0SSujith 
9111395d3f0SSujith 	buf = kzalloc(size, GFP_KERNEL);
9121395d3f0SSujith 	if (buf == NULL)
91304236066SDan Carpenter 		return -ENOMEM;
9141395d3f0SSujith 
91524a0731eSBen Greear 	RXS_ERR("CRC ERR", crc_err);
91624a0731eSBen Greear 	RXS_ERR("DECRYPT CRC ERR", decrypt_crc_err);
91724a0731eSBen Greear 	RXS_ERR("PHY ERR", phy_err);
91824a0731eSBen Greear 	RXS_ERR("MIC ERR", mic_err);
91924a0731eSBen Greear 	RXS_ERR("PRE-DELIM CRC ERR", pre_delim_crc_err);
92024a0731eSBen Greear 	RXS_ERR("POST-DELIM CRC ERR", post_delim_crc_err);
92124a0731eSBen Greear 	RXS_ERR("DECRYPT BUSY ERR", decrypt_busy_err);
92224a0731eSBen Greear 	RXS_ERR("RX-LENGTH-ERR", rx_len_err);
92324a0731eSBen Greear 	RXS_ERR("RX-OOM-ERR", rx_oom_err);
92424a0731eSBen Greear 	RXS_ERR("RX-RATE-ERR", rx_rate_err);
92524a0731eSBen Greear 	RXS_ERR("RX-DROP-RXFLUSH", rx_drop_rxflush);
92624a0731eSBen Greear 	RXS_ERR("RX-TOO-MANY-FRAGS", rx_too_many_frags_err);
9271395d3f0SSujith 
9284203214eSSujith Manoharan 	PHY_ERR("UNDERRUN ERR", ATH9K_PHYERR_UNDERRUN);
9294203214eSSujith Manoharan 	PHY_ERR("TIMING ERR", ATH9K_PHYERR_TIMING);
9304203214eSSujith Manoharan 	PHY_ERR("PARITY ERR", ATH9K_PHYERR_PARITY);
9314203214eSSujith Manoharan 	PHY_ERR("RATE ERR", ATH9K_PHYERR_RATE);
9324203214eSSujith Manoharan 	PHY_ERR("LENGTH ERR", ATH9K_PHYERR_LENGTH);
9334203214eSSujith Manoharan 	PHY_ERR("RADAR ERR", ATH9K_PHYERR_RADAR);
9344203214eSSujith Manoharan 	PHY_ERR("SERVICE ERR", ATH9K_PHYERR_SERVICE);
9354203214eSSujith Manoharan 	PHY_ERR("TOR ERR", ATH9K_PHYERR_TOR);
9364203214eSSujith Manoharan 	PHY_ERR("OFDM-TIMING ERR", ATH9K_PHYERR_OFDM_TIMING);
9374203214eSSujith Manoharan 	PHY_ERR("OFDM-SIGNAL-PARITY ERR", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
9384203214eSSujith Manoharan 	PHY_ERR("OFDM-RATE ERR", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
9394203214eSSujith Manoharan 	PHY_ERR("OFDM-LENGTH ERR", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
9404203214eSSujith Manoharan 	PHY_ERR("OFDM-POWER-DROP ERR", ATH9K_PHYERR_OFDM_POWER_DROP);
9414203214eSSujith Manoharan 	PHY_ERR("OFDM-SERVICE ERR", ATH9K_PHYERR_OFDM_SERVICE);
9424203214eSSujith Manoharan 	PHY_ERR("OFDM-RESTART ERR", ATH9K_PHYERR_OFDM_RESTART);
9434203214eSSujith Manoharan 	PHY_ERR("FALSE-RADAR-EXT ERR", ATH9K_PHYERR_FALSE_RADAR_EXT);
9444203214eSSujith Manoharan 	PHY_ERR("CCK-TIMING ERR", ATH9K_PHYERR_CCK_TIMING);
9454203214eSSujith Manoharan 	PHY_ERR("CCK-HEADER-CRC ERR", ATH9K_PHYERR_CCK_HEADER_CRC);
9464203214eSSujith Manoharan 	PHY_ERR("CCK-RATE ERR", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
9474203214eSSujith Manoharan 	PHY_ERR("CCK-SERVICE ERR", ATH9K_PHYERR_CCK_SERVICE);
9484203214eSSujith Manoharan 	PHY_ERR("CCK-RESTART ERR", ATH9K_PHYERR_CCK_RESTART);
9494203214eSSujith Manoharan 	PHY_ERR("CCK-LENGTH ERR", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
9504203214eSSujith Manoharan 	PHY_ERR("CCK-POWER-DROP ERR", ATH9K_PHYERR_CCK_POWER_DROP);
9514203214eSSujith Manoharan 	PHY_ERR("HT-CRC ERR", ATH9K_PHYERR_HT_CRC_ERROR);
9524203214eSSujith Manoharan 	PHY_ERR("HT-LENGTH ERR", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
9534203214eSSujith Manoharan 	PHY_ERR("HT-RATE ERR", ATH9K_PHYERR_HT_RATE_ILLEGAL);
9544203214eSSujith Manoharan 
95524a0731eSBen Greear 	RXS_ERR("RX-Pkts-All", rx_pkts_all);
95624a0731eSBen Greear 	RXS_ERR("RX-Bytes-All", rx_bytes_all);
95724a0731eSBen Greear 	RXS_ERR("RX-Beacons", rx_beacons);
95824a0731eSBen Greear 	RXS_ERR("RX-Frags", rx_frags);
95999c15bf5SBen Greear 
9602b87f3aaSDan Carpenter 	if (len > size)
9612b87f3aaSDan Carpenter 		len = size;
9622b87f3aaSDan Carpenter 
9631395d3f0SSujith 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
9641395d3f0SSujith 	kfree(buf);
9651395d3f0SSujith 
9661395d3f0SSujith 	return retval;
9671395d3f0SSujith 
96824a0731eSBen Greear #undef RXS_ERR
9691395d3f0SSujith #undef PHY_ERR
9701395d3f0SSujith }
9711395d3f0SSujith 
9728e6f5aa2SFelix Fietkau void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
9731395d3f0SSujith {
9741395d3f0SSujith #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
975cf3af748SRajkumar Manoharan #define RX_SAMP_DBG(c) (sc->debug.bb_mac_samp[sc->debug.sampidx].rs\
976cf3af748SRajkumar Manoharan 			[sc->debug.rsidx].c)
9771395d3f0SSujith 
97899c15bf5SBen Greear 	RX_STAT_INC(rx_pkts_all);
97999c15bf5SBen Greear 	sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
98099c15bf5SBen Greear 
9818e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_CRC)
9821395d3f0SSujith 		RX_STAT_INC(crc_err);
9838e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_DECRYPT)
9841395d3f0SSujith 		RX_STAT_INC(decrypt_crc_err);
9858e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_MIC)
9861395d3f0SSujith 		RX_STAT_INC(mic_err);
9878e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
9881395d3f0SSujith 		RX_STAT_INC(pre_delim_crc_err);
9898e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
9901395d3f0SSujith 		RX_STAT_INC(post_delim_crc_err);
9918e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
9921395d3f0SSujith 		RX_STAT_INC(decrypt_busy_err);
9931395d3f0SSujith 
9948e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_PHY) {
9951395d3f0SSujith 		RX_STAT_INC(phy_err);
996dbb07f00SSujith Manoharan 		if (rs->rs_phyerr < ATH9K_PHYERR_MAX)
997dbb07f00SSujith Manoharan 			RX_PHY_ERR_INC(rs->rs_phyerr);
9981395d3f0SSujith 	}
9991395d3f0SSujith 
10005baec742SFelix Fietkau #ifdef CONFIG_ATH9K_MAC_DEBUG
1001cf3af748SRajkumar Manoharan 	spin_lock(&sc->debug.samp_lock);
1002cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(jiffies) = jiffies;
1003cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(rssi_ctl0) = rs->rs_rssi_ctl0;
1004cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(rssi_ctl1) = rs->rs_rssi_ctl1;
1005cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(rssi_ctl2) = rs->rs_rssi_ctl2;
1006cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(rssi_ext0) = rs->rs_rssi_ext0;
1007cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(rssi_ext1) = rs->rs_rssi_ext1;
1008cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(rssi_ext2) = rs->rs_rssi_ext2;
1009cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(antenna) = rs->rs_antenna;
1010cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(rssi) = rs->rs_rssi;
1011cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(rate) = rs->rs_rate;
1012cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(is_mybeacon) = rs->is_mybeacon;
1013cf3af748SRajkumar Manoharan 
1014cf3af748SRajkumar Manoharan 	sc->debug.rsidx = (sc->debug.rsidx + 1) % ATH_DBG_MAX_SAMPLES;
1015cf3af748SRajkumar Manoharan 	spin_unlock(&sc->debug.samp_lock);
1016cf3af748SRajkumar Manoharan 
10175baec742SFelix Fietkau #endif
10185baec742SFelix Fietkau 
10191395d3f0SSujith #undef RX_PHY_ERR_INC
1020cf3af748SRajkumar Manoharan #undef RX_SAMP_DBG
10211395d3f0SSujith }
10221395d3f0SSujith 
10231395d3f0SSujith static const struct file_operations fops_recv = {
10241395d3f0SSujith 	.read = read_file_recv,
1025234e3405SStephen Boyd 	.open = simple_open,
10266038f373SArnd Bergmann 	.owner = THIS_MODULE,
10276038f373SArnd Bergmann 	.llseek = default_llseek,
10281395d3f0SSujith };
10291395d3f0SSujith 
10309bff0bc4SFelix Fietkau static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
10319bff0bc4SFelix Fietkau                                 size_t count, loff_t *ppos)
10329bff0bc4SFelix Fietkau {
10339bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
10349bff0bc4SFelix Fietkau 	char buf[32];
10359bff0bc4SFelix Fietkau 	unsigned int len;
10369bff0bc4SFelix Fietkau 
10372b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
10389bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
10399bff0bc4SFelix Fietkau }
10409bff0bc4SFelix Fietkau 
10419bff0bc4SFelix Fietkau static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
10429bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
10439bff0bc4SFelix Fietkau {
10449bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
10459bff0bc4SFelix Fietkau 	unsigned long regidx;
10469bff0bc4SFelix Fietkau 	char buf[32];
10479bff0bc4SFelix Fietkau 	ssize_t len;
10489bff0bc4SFelix Fietkau 
10499bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
10509bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
105104236066SDan Carpenter 		return -EFAULT;
10529bff0bc4SFelix Fietkau 
10539bff0bc4SFelix Fietkau 	buf[len] = '\0';
10549bff0bc4SFelix Fietkau 	if (strict_strtoul(buf, 0, &regidx))
10559bff0bc4SFelix Fietkau 		return -EINVAL;
10569bff0bc4SFelix Fietkau 
10579bff0bc4SFelix Fietkau 	sc->debug.regidx = regidx;
10589bff0bc4SFelix Fietkau 	return count;
10599bff0bc4SFelix Fietkau }
10609bff0bc4SFelix Fietkau 
10619bff0bc4SFelix Fietkau static const struct file_operations fops_regidx = {
10629bff0bc4SFelix Fietkau 	.read = read_file_regidx,
10639bff0bc4SFelix Fietkau 	.write = write_file_regidx,
1064234e3405SStephen Boyd 	.open = simple_open,
10656038f373SArnd Bergmann 	.owner = THIS_MODULE,
10666038f373SArnd Bergmann 	.llseek = default_llseek,
10679bff0bc4SFelix Fietkau };
10689bff0bc4SFelix Fietkau 
10699bff0bc4SFelix Fietkau static ssize_t read_file_regval(struct file *file, char __user *user_buf,
10709bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
10719bff0bc4SFelix Fietkau {
10729bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
10739bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
10749bff0bc4SFelix Fietkau 	char buf[32];
10759bff0bc4SFelix Fietkau 	unsigned int len;
10769bff0bc4SFelix Fietkau 	u32 regval;
10779bff0bc4SFelix Fietkau 
107879d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
10799bff0bc4SFelix Fietkau 	regval = REG_READ_D(ah, sc->debug.regidx);
108079d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
10812b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", regval);
10829bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
10839bff0bc4SFelix Fietkau }
10849bff0bc4SFelix Fietkau 
10859bff0bc4SFelix Fietkau static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
10869bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
10879bff0bc4SFelix Fietkau {
10889bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
10899bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
10909bff0bc4SFelix Fietkau 	unsigned long regval;
10919bff0bc4SFelix Fietkau 	char buf[32];
10929bff0bc4SFelix Fietkau 	ssize_t len;
10939bff0bc4SFelix Fietkau 
10949bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
10959bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
109604236066SDan Carpenter 		return -EFAULT;
10979bff0bc4SFelix Fietkau 
10989bff0bc4SFelix Fietkau 	buf[len] = '\0';
10999bff0bc4SFelix Fietkau 	if (strict_strtoul(buf, 0, &regval))
11009bff0bc4SFelix Fietkau 		return -EINVAL;
11019bff0bc4SFelix Fietkau 
110279d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
11039bff0bc4SFelix Fietkau 	REG_WRITE_D(ah, sc->debug.regidx, regval);
110479d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
11059bff0bc4SFelix Fietkau 	return count;
11069bff0bc4SFelix Fietkau }
11079bff0bc4SFelix Fietkau 
11089bff0bc4SFelix Fietkau static const struct file_operations fops_regval = {
11099bff0bc4SFelix Fietkau 	.read = read_file_regval,
11109bff0bc4SFelix Fietkau 	.write = write_file_regval,
1111234e3405SStephen Boyd 	.open = simple_open,
11126038f373SArnd Bergmann 	.owner = THIS_MODULE,
11136038f373SArnd Bergmann 	.llseek = default_llseek,
11149bff0bc4SFelix Fietkau };
11159bff0bc4SFelix Fietkau 
1116582d0064SVasanthakumar Thiagarajan #define REGDUMP_LINE_SIZE	20
1117582d0064SVasanthakumar Thiagarajan 
1118582d0064SVasanthakumar Thiagarajan static int open_file_regdump(struct inode *inode, struct file *file)
1119582d0064SVasanthakumar Thiagarajan {
1120582d0064SVasanthakumar Thiagarajan 	struct ath_softc *sc = inode->i_private;
1121582d0064SVasanthakumar Thiagarajan 	unsigned int len = 0;
1122582d0064SVasanthakumar Thiagarajan 	u8 *buf;
1123582d0064SVasanthakumar Thiagarajan 	int i;
1124582d0064SVasanthakumar Thiagarajan 	unsigned long num_regs, regdump_len, max_reg_offset;
1125582d0064SVasanthakumar Thiagarajan 
1126582d0064SVasanthakumar Thiagarajan 	max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
1127582d0064SVasanthakumar Thiagarajan 	num_regs = max_reg_offset / 4 + 1;
1128582d0064SVasanthakumar Thiagarajan 	regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
1129582d0064SVasanthakumar Thiagarajan 	buf = vmalloc(regdump_len);
1130582d0064SVasanthakumar Thiagarajan 	if (!buf)
1131582d0064SVasanthakumar Thiagarajan 		return -ENOMEM;
1132582d0064SVasanthakumar Thiagarajan 
1133582d0064SVasanthakumar Thiagarajan 	ath9k_ps_wakeup(sc);
1134582d0064SVasanthakumar Thiagarajan 	for (i = 0; i < num_regs; i++)
1135582d0064SVasanthakumar Thiagarajan 		len += scnprintf(buf + len, regdump_len - len,
1136582d0064SVasanthakumar Thiagarajan 			"0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
1137582d0064SVasanthakumar Thiagarajan 	ath9k_ps_restore(sc);
1138582d0064SVasanthakumar Thiagarajan 
1139582d0064SVasanthakumar Thiagarajan 	file->private_data = buf;
1140582d0064SVasanthakumar Thiagarajan 
1141582d0064SVasanthakumar Thiagarajan 	return 0;
1142582d0064SVasanthakumar Thiagarajan }
1143582d0064SVasanthakumar Thiagarajan 
1144582d0064SVasanthakumar Thiagarajan static const struct file_operations fops_regdump = {
1145582d0064SVasanthakumar Thiagarajan 	.open = open_file_regdump,
1146582d0064SVasanthakumar Thiagarajan 	.read = ath9k_debugfs_read_buf,
1147582d0064SVasanthakumar Thiagarajan 	.release = ath9k_debugfs_release_buf,
1148582d0064SVasanthakumar Thiagarajan 	.owner = THIS_MODULE,
1149582d0064SVasanthakumar Thiagarajan 	.llseek = default_llseek,/* read accesses f_pos */
1150582d0064SVasanthakumar Thiagarajan };
1151582d0064SVasanthakumar Thiagarajan 
1152d069a46bSRajkumar Manoharan static ssize_t read_file_dump_nfcal(struct file *file, char __user *user_buf,
1153d069a46bSRajkumar Manoharan 				    size_t count, loff_t *ppos)
1154d069a46bSRajkumar Manoharan {
1155d069a46bSRajkumar Manoharan 	struct ath_softc *sc = file->private_data;
1156d069a46bSRajkumar Manoharan 	struct ath_hw *ah = sc->sc_ah;
1157d069a46bSRajkumar Manoharan 	struct ath9k_nfcal_hist *h = sc->caldata.nfCalHist;
1158d069a46bSRajkumar Manoharan 	struct ath_common *common = ath9k_hw_common(ah);
1159d069a46bSRajkumar Manoharan 	struct ieee80211_conf *conf = &common->hw->conf;
1160d069a46bSRajkumar Manoharan 	u32 len = 0, size = 1500;
1161d069a46bSRajkumar Manoharan 	u32 i, j;
1162d069a46bSRajkumar Manoharan 	ssize_t retval = 0;
1163d069a46bSRajkumar Manoharan 	char *buf;
1164d069a46bSRajkumar Manoharan 	u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1165d069a46bSRajkumar Manoharan 	u8 nread;
1166d069a46bSRajkumar Manoharan 
1167d069a46bSRajkumar Manoharan 	buf = kzalloc(size, GFP_KERNEL);
1168d069a46bSRajkumar Manoharan 	if (!buf)
1169d069a46bSRajkumar Manoharan 		return -ENOMEM;
1170d069a46bSRajkumar Manoharan 
1171d069a46bSRajkumar Manoharan 	len += snprintf(buf + len, size - len,
1172d069a46bSRajkumar Manoharan 			"Channel Noise Floor : %d\n", ah->noise);
1173d069a46bSRajkumar Manoharan 	len += snprintf(buf + len, size - len,
1174d069a46bSRajkumar Manoharan 			"Chain | privNF | # Readings | NF Readings\n");
1175d069a46bSRajkumar Manoharan 	for (i = 0; i < NUM_NF_READINGS; i++) {
1176d069a46bSRajkumar Manoharan 		if (!(chainmask & (1 << i)) ||
1177d069a46bSRajkumar Manoharan 		    ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1178d069a46bSRajkumar Manoharan 			continue;
1179d069a46bSRajkumar Manoharan 
1180d069a46bSRajkumar Manoharan 		nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
1181d069a46bSRajkumar Manoharan 		len += snprintf(buf + len, size - len, " %d\t %d\t %d\t\t",
1182d069a46bSRajkumar Manoharan 				i, h[i].privNF, nread);
1183d069a46bSRajkumar Manoharan 		for (j = 0; j < nread; j++)
1184d069a46bSRajkumar Manoharan 			len += snprintf(buf + len, size - len,
1185d069a46bSRajkumar Manoharan 					" %d", h[i].nfCalBuffer[j]);
1186d069a46bSRajkumar Manoharan 		len += snprintf(buf + len, size - len, "\n");
1187d069a46bSRajkumar Manoharan 	}
1188d069a46bSRajkumar Manoharan 
1189d069a46bSRajkumar Manoharan 	if (len > size)
1190d069a46bSRajkumar Manoharan 		len = size;
1191d069a46bSRajkumar Manoharan 
1192d069a46bSRajkumar Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1193d069a46bSRajkumar Manoharan 	kfree(buf);
1194d069a46bSRajkumar Manoharan 
1195d069a46bSRajkumar Manoharan 	return retval;
1196d069a46bSRajkumar Manoharan }
1197d069a46bSRajkumar Manoharan 
1198d069a46bSRajkumar Manoharan static const struct file_operations fops_dump_nfcal = {
1199d069a46bSRajkumar Manoharan 	.read = read_file_dump_nfcal,
1200234e3405SStephen Boyd 	.open = simple_open,
1201d069a46bSRajkumar Manoharan 	.owner = THIS_MODULE,
1202d069a46bSRajkumar Manoharan 	.llseek = default_llseek,
1203d069a46bSRajkumar Manoharan };
1204d069a46bSRajkumar Manoharan 
1205580f010fSRajkumar Manoharan static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf,
1206580f010fSRajkumar Manoharan 				     size_t count, loff_t *ppos)
1207580f010fSRajkumar Manoharan {
1208580f010fSRajkumar Manoharan 	struct ath_softc *sc = file->private_data;
1209580f010fSRajkumar Manoharan 	struct ath_hw *ah = sc->sc_ah;
1210580f010fSRajkumar Manoharan 	u32 len = 0, size = 1500;
1211580f010fSRajkumar Manoharan 	ssize_t retval = 0;
1212580f010fSRajkumar Manoharan 	char *buf;
1213580f010fSRajkumar Manoharan 
1214580f010fSRajkumar Manoharan 	buf = kzalloc(size, GFP_KERNEL);
1215580f010fSRajkumar Manoharan 	if (!buf)
1216580f010fSRajkumar Manoharan 		return -ENOMEM;
1217580f010fSRajkumar Manoharan 
1218580f010fSRajkumar Manoharan 	len = ah->eep_ops->dump_eeprom(ah, true, buf, len, size);
1219580f010fSRajkumar Manoharan 
1220580f010fSRajkumar Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1221580f010fSRajkumar Manoharan 	kfree(buf);
1222580f010fSRajkumar Manoharan 
1223580f010fSRajkumar Manoharan 	return retval;
1224580f010fSRajkumar Manoharan }
1225580f010fSRajkumar Manoharan 
1226580f010fSRajkumar Manoharan static const struct file_operations fops_base_eeprom = {
1227580f010fSRajkumar Manoharan 	.read = read_file_base_eeprom,
1228234e3405SStephen Boyd 	.open = simple_open,
1229580f010fSRajkumar Manoharan 	.owner = THIS_MODULE,
1230580f010fSRajkumar Manoharan 	.llseek = default_llseek,
1231580f010fSRajkumar Manoharan };
1232580f010fSRajkumar Manoharan 
12333f4c4bddSRajkumar Manoharan static ssize_t read_file_modal_eeprom(struct file *file, char __user *user_buf,
12343f4c4bddSRajkumar Manoharan 				      size_t count, loff_t *ppos)
12353f4c4bddSRajkumar Manoharan {
12363f4c4bddSRajkumar Manoharan 	struct ath_softc *sc = file->private_data;
12373f4c4bddSRajkumar Manoharan 	struct ath_hw *ah = sc->sc_ah;
12383f4c4bddSRajkumar Manoharan 	u32 len = 0, size = 6000;
12393f4c4bddSRajkumar Manoharan 	char *buf;
12403f4c4bddSRajkumar Manoharan 	size_t retval;
12413f4c4bddSRajkumar Manoharan 
12423f4c4bddSRajkumar Manoharan 	buf = kzalloc(size, GFP_KERNEL);
12433f4c4bddSRajkumar Manoharan 	if (buf == NULL)
12443f4c4bddSRajkumar Manoharan 		return -ENOMEM;
12453f4c4bddSRajkumar Manoharan 
12463f4c4bddSRajkumar Manoharan 	len = ah->eep_ops->dump_eeprom(ah, false, buf, len, size);
12473f4c4bddSRajkumar Manoharan 
12483f4c4bddSRajkumar Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
12493f4c4bddSRajkumar Manoharan 	kfree(buf);
12503f4c4bddSRajkumar Manoharan 
12513f4c4bddSRajkumar Manoharan 	return retval;
12523f4c4bddSRajkumar Manoharan }
12533f4c4bddSRajkumar Manoharan 
12543f4c4bddSRajkumar Manoharan static const struct file_operations fops_modal_eeprom = {
12553f4c4bddSRajkumar Manoharan 	.read = read_file_modal_eeprom,
1256234e3405SStephen Boyd 	.open = simple_open,
12573f4c4bddSRajkumar Manoharan 	.owner = THIS_MODULE,
12583f4c4bddSRajkumar Manoharan 	.llseek = default_llseek,
12593f4c4bddSRajkumar Manoharan };
12603f4c4bddSRajkumar Manoharan 
12615baec742SFelix Fietkau #ifdef CONFIG_ATH9K_MAC_DEBUG
12625baec742SFelix Fietkau 
1263cf3af748SRajkumar Manoharan void ath9k_debug_samp_bb_mac(struct ath_softc *sc)
1264cf3af748SRajkumar Manoharan {
1265cf3af748SRajkumar Manoharan #define ATH_SAMP_DBG(c) (sc->debug.bb_mac_samp[sc->debug.sampidx].c)
1266cf3af748SRajkumar Manoharan 	struct ath_hw *ah = sc->sc_ah;
1267cf3af748SRajkumar Manoharan 	struct ath_common *common = ath9k_hw_common(ah);
1268cf3af748SRajkumar Manoharan 	unsigned long flags;
1269cf3af748SRajkumar Manoharan 	int i;
1270cf3af748SRajkumar Manoharan 
1271cf3af748SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
1272cf3af748SRajkumar Manoharan 
12736bc05a95SRajkumar Manoharan 	spin_lock_bh(&sc->debug.samp_lock);
12746bc05a95SRajkumar Manoharan 
1275cf3af748SRajkumar Manoharan 	spin_lock_irqsave(&common->cc_lock, flags);
1276cf3af748SRajkumar Manoharan 	ath_hw_cycle_counters_update(common);
1277cf3af748SRajkumar Manoharan 
1278cf3af748SRajkumar Manoharan 	ATH_SAMP_DBG(cc.cycles) = common->cc_ani.cycles;
1279cf3af748SRajkumar Manoharan 	ATH_SAMP_DBG(cc.rx_busy) = common->cc_ani.rx_busy;
1280cf3af748SRajkumar Manoharan 	ATH_SAMP_DBG(cc.rx_frame) = common->cc_ani.rx_frame;
1281cf3af748SRajkumar Manoharan 	ATH_SAMP_DBG(cc.tx_frame) = common->cc_ani.tx_frame;
12826bc05a95SRajkumar Manoharan 	spin_unlock_irqrestore(&common->cc_lock, flags);
12836bc05a95SRajkumar Manoharan 
1284cf3af748SRajkumar Manoharan 	ATH_SAMP_DBG(noise) = ah->noise;
1285cf3af748SRajkumar Manoharan 
1286cf3af748SRajkumar Manoharan 	REG_WRITE_D(ah, AR_MACMISC,
1287cf3af748SRajkumar Manoharan 		  ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
1288cf3af748SRajkumar Manoharan 		   (AR_MACMISC_MISC_OBS_BUS_1 <<
1289cf3af748SRajkumar Manoharan 		    AR_MACMISC_MISC_OBS_BUS_MSB_S)));
1290cf3af748SRajkumar Manoharan 
1291cf3af748SRajkumar Manoharan 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++)
1292cf3af748SRajkumar Manoharan 		ATH_SAMP_DBG(dma_dbg_reg_vals[i]) = REG_READ_D(ah,
1293cf3af748SRajkumar Manoharan 				AR_DMADBG_0 + (i * sizeof(u32)));
1294cf3af748SRajkumar Manoharan 
1295cf3af748SRajkumar Manoharan 	ATH_SAMP_DBG(pcu_obs) = REG_READ_D(ah, AR_OBS_BUS_1);
1296cf3af748SRajkumar Manoharan 	ATH_SAMP_DBG(pcu_cr) = REG_READ_D(ah, AR_CR);
1297cf3af748SRajkumar Manoharan 
1298cf3af748SRajkumar Manoharan 	memcpy(ATH_SAMP_DBG(nfCalHist), sc->caldata.nfCalHist,
1299cf3af748SRajkumar Manoharan 			sizeof(ATH_SAMP_DBG(nfCalHist)));
1300cf3af748SRajkumar Manoharan 
1301cf3af748SRajkumar Manoharan 	sc->debug.sampidx = (sc->debug.sampidx + 1) % ATH_DBG_MAX_SAMPLES;
1302cf3af748SRajkumar Manoharan 	spin_unlock_bh(&sc->debug.samp_lock);
1303cf3af748SRajkumar Manoharan 	ath9k_ps_restore(sc);
1304cf3af748SRajkumar Manoharan 
1305cf3af748SRajkumar Manoharan #undef ATH_SAMP_DBG
1306cf3af748SRajkumar Manoharan }
1307cf3af748SRajkumar Manoharan 
1308cf3af748SRajkumar Manoharan static int open_file_bb_mac_samps(struct inode *inode, struct file *file)
1309cf3af748SRajkumar Manoharan {
1310cf3af748SRajkumar Manoharan #define ATH_SAMP_DBG(c) bb_mac_samp[sampidx].c
1311cf3af748SRajkumar Manoharan 	struct ath_softc *sc = inode->i_private;
1312cf3af748SRajkumar Manoharan 	struct ath_hw *ah = sc->sc_ah;
1313cf3af748SRajkumar Manoharan 	struct ath_common *common = ath9k_hw_common(ah);
1314cf3af748SRajkumar Manoharan 	struct ieee80211_conf *conf = &common->hw->conf;
1315cf3af748SRajkumar Manoharan 	struct ath_dbg_bb_mac_samp *bb_mac_samp;
1316cf3af748SRajkumar Manoharan 	struct ath9k_nfcal_hist *h;
1317cf3af748SRajkumar Manoharan 	int i, j, qcuOffset = 0, dcuOffset = 0;
1318cf3af748SRajkumar Manoharan 	u32 *qcuBase, *dcuBase, size = 30000, len = 0;
1319cf3af748SRajkumar Manoharan 	u32 sampidx = 0;
1320cf3af748SRajkumar Manoharan 	u8 *buf;
1321cf3af748SRajkumar Manoharan 	u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1322cf3af748SRajkumar Manoharan 	u8 nread;
1323cf3af748SRajkumar Manoharan 
1324781b14a3SSujith Manoharan 	if (test_bit(SC_OP_INVALID, &sc->sc_flags))
1325f7e014daSRajkumar Manoharan 		return -EAGAIN;
1326f7e014daSRajkumar Manoharan 
1327cf3af748SRajkumar Manoharan 	buf = vmalloc(size);
1328cf3af748SRajkumar Manoharan 	if (!buf)
1329cf3af748SRajkumar Manoharan 		return -ENOMEM;
1330cf3af748SRajkumar Manoharan 	bb_mac_samp = vmalloc(sizeof(*bb_mac_samp) * ATH_DBG_MAX_SAMPLES);
1331cf3af748SRajkumar Manoharan 	if (!bb_mac_samp) {
1332cf3af748SRajkumar Manoharan 		vfree(buf);
1333cf3af748SRajkumar Manoharan 		return -ENOMEM;
1334cf3af748SRajkumar Manoharan 	}
1335f7e014daSRajkumar Manoharan 	/* Account the current state too */
1336f7e014daSRajkumar Manoharan 	ath9k_debug_samp_bb_mac(sc);
1337cf3af748SRajkumar Manoharan 
1338cf3af748SRajkumar Manoharan 	spin_lock_bh(&sc->debug.samp_lock);
1339cf3af748SRajkumar Manoharan 	memcpy(bb_mac_samp, sc->debug.bb_mac_samp,
1340cf3af748SRajkumar Manoharan 			sizeof(*bb_mac_samp) * ATH_DBG_MAX_SAMPLES);
13416bc05a95SRajkumar Manoharan 	len += snprintf(buf + len, size - len,
13426bc05a95SRajkumar Manoharan 			"Current Sample Index: %d\n", sc->debug.sampidx);
1343cf3af748SRajkumar Manoharan 	spin_unlock_bh(&sc->debug.samp_lock);
1344cf3af748SRajkumar Manoharan 
1345cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len,
1346cf3af748SRajkumar Manoharan 			"Raw DMA Debug Dump:\n");
1347cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len, "Sample |\t");
1348cf3af748SRajkumar Manoharan 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++)
1349cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, " DMA Reg%d |\t", i);
1350cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len, "\n");
1351cf3af748SRajkumar Manoharan 
1352cf3af748SRajkumar Manoharan 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1353cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, "%d\t", sampidx);
1354cf3af748SRajkumar Manoharan 
1355cf3af748SRajkumar Manoharan 		for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++)
1356cf3af748SRajkumar Manoharan 			len += snprintf(buf + len, size - len, " %08x\t",
1357cf3af748SRajkumar Manoharan 					ATH_SAMP_DBG(dma_dbg_reg_vals[i]));
1358cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, "\n");
1359cf3af748SRajkumar Manoharan 	}
1360cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len, "\n");
1361cf3af748SRajkumar Manoharan 
1362cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len,
1363cf3af748SRajkumar Manoharan 			"Sample Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
1364cf3af748SRajkumar Manoharan 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1365cf3af748SRajkumar Manoharan 		qcuBase = &ATH_SAMP_DBG(dma_dbg_reg_vals[0]);
1366cf3af748SRajkumar Manoharan 		dcuBase = &ATH_SAMP_DBG(dma_dbg_reg_vals[4]);
1367cf3af748SRajkumar Manoharan 
1368cf3af748SRajkumar Manoharan 		for (i = 0; i < ATH9K_NUM_QUEUES; i++,
1369cf3af748SRajkumar Manoharan 				qcuOffset += 4, dcuOffset += 5) {
1370cf3af748SRajkumar Manoharan 			if (i == 8) {
1371cf3af748SRajkumar Manoharan 				qcuOffset = 0;
1372cf3af748SRajkumar Manoharan 				qcuBase++;
1373cf3af748SRajkumar Manoharan 			}
1374cf3af748SRajkumar Manoharan 
1375cf3af748SRajkumar Manoharan 			if (i == 6) {
1376cf3af748SRajkumar Manoharan 				dcuOffset = 0;
1377cf3af748SRajkumar Manoharan 				dcuBase++;
1378cf3af748SRajkumar Manoharan 			}
1379cf3af748SRajkumar Manoharan 			if (!sc->debug.stats.txstats[i].queued)
1380cf3af748SRajkumar Manoharan 				continue;
1381cf3af748SRajkumar Manoharan 
1382cf3af748SRajkumar Manoharan 			len += snprintf(buf + len, size - len,
1383cf3af748SRajkumar Manoharan 				"%4d %7d    %2x      %1x     %2x         %2x\n",
1384cf3af748SRajkumar Manoharan 				sampidx, i,
1385cf3af748SRajkumar Manoharan 				(*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
1386cf3af748SRajkumar Manoharan 				(*qcuBase & (0x8 << qcuOffset)) >>
1387cf3af748SRajkumar Manoharan 				(qcuOffset + 3),
1388cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(dma_dbg_reg_vals[2]) &
1389cf3af748SRajkumar Manoharan 				(0x7 << (i * 3)) >> (i * 3),
1390cf3af748SRajkumar Manoharan 				(*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
1391cf3af748SRajkumar Manoharan 		}
1392cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, "\n");
1393cf3af748SRajkumar Manoharan 	}
1394cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len,
1395cf3af748SRajkumar Manoharan 			"samp qcu_sh qcu_fh qcu_comp dcu_comp dcu_arb dcu_fp "
1396cf3af748SRajkumar Manoharan 			"ch_idle_dur ch_idle_dur_val txfifo_val0 txfifo_val1 "
1397cf3af748SRajkumar Manoharan 			"txfifo_dcu0 txfifo_dcu1 pcu_obs AR_CR\n");
1398cf3af748SRajkumar Manoharan 
1399cf3af748SRajkumar Manoharan 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1400cf3af748SRajkumar Manoharan 		qcuBase = &ATH_SAMP_DBG(dma_dbg_reg_vals[0]);
1401cf3af748SRajkumar Manoharan 		dcuBase = &ATH_SAMP_DBG(dma_dbg_reg_vals[4]);
1402cf3af748SRajkumar Manoharan 
1403cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, "%4d %5x %5x ", sampidx,
1404cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[3]) & 0x003c0000) >> 18,
1405cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[3]) & 0x03c00000) >> 22);
1406cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, "%7x %8x ",
1407cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[3]) & 0x1c000000) >> 26,
1408cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x3));
1409cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, "%7x %7x ",
1410cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[5]) & 0x06000000) >> 25,
1411cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[5]) & 0x38000000) >> 27);
1412cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, "%7d %12d ",
1413cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x000003fc) >> 2,
1414cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x00000400) >> 10);
1415cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, "%12d %12d ",
1416cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x00000800) >> 11,
1417cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x00001000) >> 12);
1418cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, "%12d %12d ",
1419cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x0001e000) >> 13,
1420cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x001e0000) >> 17);
1421cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, "0x%07x 0x%07x\n",
1422cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(pcu_obs), ATH_SAMP_DBG(pcu_cr));
1423cf3af748SRajkumar Manoharan 	}
1424cf3af748SRajkumar Manoharan 
1425cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len,
1426cf3af748SRajkumar Manoharan 			"Sample ChNoise Chain privNF #Reading Readings\n");
1427cf3af748SRajkumar Manoharan 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1428cf3af748SRajkumar Manoharan 		h = ATH_SAMP_DBG(nfCalHist);
1429cf3af748SRajkumar Manoharan 		if (!ATH_SAMP_DBG(noise))
1430cf3af748SRajkumar Manoharan 			continue;
1431cf3af748SRajkumar Manoharan 
1432cf3af748SRajkumar Manoharan 		for (i = 0; i < NUM_NF_READINGS; i++) {
1433cf3af748SRajkumar Manoharan 			if (!(chainmask & (1 << i)) ||
1434cf3af748SRajkumar Manoharan 			    ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1435cf3af748SRajkumar Manoharan 				continue;
1436cf3af748SRajkumar Manoharan 
1437cf3af748SRajkumar Manoharan 			nread = AR_PHY_CCA_FILTERWINDOW_LENGTH -
1438cf3af748SRajkumar Manoharan 				h[i].invalidNFcount;
1439cf3af748SRajkumar Manoharan 			len += snprintf(buf + len, size - len,
1440cf3af748SRajkumar Manoharan 					"%4d %5d %4d\t   %d\t %d\t",
1441cf3af748SRajkumar Manoharan 					sampidx, ATH_SAMP_DBG(noise),
1442cf3af748SRajkumar Manoharan 					i, h[i].privNF, nread);
1443cf3af748SRajkumar Manoharan 			for (j = 0; j < nread; j++)
1444cf3af748SRajkumar Manoharan 				len += snprintf(buf + len, size - len,
1445cf3af748SRajkumar Manoharan 					" %d", h[i].nfCalBuffer[j]);
1446cf3af748SRajkumar Manoharan 			len += snprintf(buf + len, size - len, "\n");
1447cf3af748SRajkumar Manoharan 		}
1448cf3af748SRajkumar Manoharan 	}
1449cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len, "\nCycle counters:\n"
1450cf3af748SRajkumar Manoharan 			"Sample Total    Rxbusy   Rxframes Txframes\n");
1451cf3af748SRajkumar Manoharan 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1452cf3af748SRajkumar Manoharan 		if (!ATH_SAMP_DBG(cc.cycles))
1453cf3af748SRajkumar Manoharan 			continue;
1454cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len,
1455cf3af748SRajkumar Manoharan 				"%4d %08x %08x %08x %08x\n",
1456cf3af748SRajkumar Manoharan 				sampidx, ATH_SAMP_DBG(cc.cycles),
1457cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(cc.rx_busy),
1458cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(cc.rx_frame),
1459cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(cc.tx_frame));
1460cf3af748SRajkumar Manoharan 	}
1461cf3af748SRajkumar Manoharan 
1462cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len, "Tx status Dump :\n");
1463cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len,
1464cf3af748SRajkumar Manoharan 			"Sample rssi:- ctl0 ctl1 ctl2 ext0 ext1 ext2 comb "
146512932180SMohammed Shafi Shajakhan 			"isok rts_fail data_fail rate tid qid "
146612932180SMohammed Shafi Shajakhan 					"ba_low  ba_high tx_before(ms)\n");
1467cf3af748SRajkumar Manoharan 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1468cf3af748SRajkumar Manoharan 		for (i = 0; i < ATH_DBG_MAX_SAMPLES; i++) {
1469cf3af748SRajkumar Manoharan 			if (!ATH_SAMP_DBG(ts[i].jiffies))
1470cf3af748SRajkumar Manoharan 				continue;
147112932180SMohammed Shafi Shajakhan 			len += snprintf(buf + len, size - len, "%-14d"
147212932180SMohammed Shafi Shajakhan 				"%-4d %-4d %-4d %-4d %-4d %-4d %-4d %-4d %-8d "
147312932180SMohammed Shafi Shajakhan 				"%-9d %-4d %-3d %-3d %08x %08x %-11d\n",
1474cf3af748SRajkumar Manoharan 				sampidx,
1475cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].rssi_ctl0),
1476cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].rssi_ctl1),
1477cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].rssi_ctl2),
1478cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].rssi_ext0),
1479cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].rssi_ext1),
1480cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].rssi_ext2),
1481cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].rssi),
1482cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].isok),
1483cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].rts_fail_cnt),
1484cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].data_fail_cnt),
1485cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].rateindex),
1486cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].tid),
1487cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].qid),
148812932180SMohammed Shafi Shajakhan 				ATH_SAMP_DBG(ts[i].ba_low),
148912932180SMohammed Shafi Shajakhan 				ATH_SAMP_DBG(ts[i].ba_high),
1490cf3af748SRajkumar Manoharan 				jiffies_to_msecs(jiffies -
1491cf3af748SRajkumar Manoharan 					ATH_SAMP_DBG(ts[i].jiffies)));
1492cf3af748SRajkumar Manoharan 		}
1493cf3af748SRajkumar Manoharan 	}
1494cf3af748SRajkumar Manoharan 
1495cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len, "Rx status Dump :\n");
1496cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len, "Sample rssi:- ctl0 ctl1 ctl2 "
1497cf3af748SRajkumar Manoharan 			"ext0 ext1 ext2 comb beacon ant rate rx_before(ms)\n");
1498cf3af748SRajkumar Manoharan 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1499cf3af748SRajkumar Manoharan 		for (i = 0; i < ATH_DBG_MAX_SAMPLES; i++) {
1500cf3af748SRajkumar Manoharan 			if (!ATH_SAMP_DBG(rs[i].jiffies))
1501cf3af748SRajkumar Manoharan 				continue;
150212932180SMohammed Shafi Shajakhan 			len += snprintf(buf + len, size - len, "%-14d"
150312932180SMohammed Shafi Shajakhan 				"%-4d %-4d %-4d %-4d %-4d %-4d %-4d %-9s %-2d %02x %-13d\n",
1504cf3af748SRajkumar Manoharan 				sampidx,
1505cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(rs[i].rssi_ctl0),
1506cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(rs[i].rssi_ctl1),
1507cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(rs[i].rssi_ctl2),
1508cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(rs[i].rssi_ext0),
1509cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(rs[i].rssi_ext1),
1510cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(rs[i].rssi_ext2),
1511cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(rs[i].rssi),
1512cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(rs[i].is_mybeacon) ?
1513cf3af748SRajkumar Manoharan 				"True" : "False",
1514cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(rs[i].antenna),
1515cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(rs[i].rate),
1516cf3af748SRajkumar Manoharan 				jiffies_to_msecs(jiffies -
1517cf3af748SRajkumar Manoharan 					ATH_SAMP_DBG(rs[i].jiffies)));
1518cf3af748SRajkumar Manoharan 		}
1519cf3af748SRajkumar Manoharan 	}
1520cf3af748SRajkumar Manoharan 
1521cf3af748SRajkumar Manoharan 	vfree(bb_mac_samp);
1522cf3af748SRajkumar Manoharan 	file->private_data = buf;
1523cf3af748SRajkumar Manoharan 
1524cf3af748SRajkumar Manoharan 	return 0;
1525cf3af748SRajkumar Manoharan #undef ATH_SAMP_DBG
1526cf3af748SRajkumar Manoharan }
1527cf3af748SRajkumar Manoharan 
1528cf3af748SRajkumar Manoharan static const struct file_operations fops_samps = {
1529cf3af748SRajkumar Manoharan 	.open = open_file_bb_mac_samps,
1530cf3af748SRajkumar Manoharan 	.read = ath9k_debugfs_read_buf,
1531cf3af748SRajkumar Manoharan 	.release = ath9k_debugfs_release_buf,
1532cf3af748SRajkumar Manoharan 	.owner = THIS_MODULE,
1533cf3af748SRajkumar Manoharan 	.llseek = default_llseek,
1534cf3af748SRajkumar Manoharan };
1535cf3af748SRajkumar Manoharan 
15365baec742SFelix Fietkau #endif
1537cf3af748SRajkumar Manoharan 
15384d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah)
1539203c4805SLuis R. Rodriguez {
1540bc974f4aSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(ah);
1541bc974f4aSLuis R. Rodriguez 	struct ath_softc *sc = (struct ath_softc *) common->priv;
15424d6b228dSLuis R. Rodriguez 
1543eb272441SBen Greear 	sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1544eb272441SBen Greear 						   sc->hw->wiphy->debugfsdir);
1545203c4805SLuis R. Rodriguez 	if (!sc->debug.debugfs_phy)
1546c8a72c00SFelix Fietkau 		return -ENOMEM;
1547203c4805SLuis R. Rodriguez 
1548a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
1549c70cab1aSFelix Fietkau 	debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1550c70cab1aSFelix Fietkau 			    sc, &fops_debug);
1551a830df07SFelix Fietkau #endif
155229942bc1SZefir Kurtisi 
155329942bc1SZefir Kurtisi 	ath9k_dfs_init_debug(sc);
155429942bc1SZefir Kurtisi 
1555c70cab1aSFelix Fietkau 	debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
1556c70cab1aSFelix Fietkau 			    &fops_dma);
1557c70cab1aSFelix Fietkau 	debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
1558c70cab1aSFelix Fietkau 			    &fops_interrupt);
1559c70cab1aSFelix Fietkau 	debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc,
1560c70cab1aSFelix Fietkau 			    &fops_xmit);
15617702e788SFelix Fietkau 	debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
15627702e788SFelix Fietkau 			   &sc->tx.txq_max_pending[WME_AC_BK]);
15637702e788SFelix Fietkau 	debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
15647702e788SFelix Fietkau 			   &sc->tx.txq_max_pending[WME_AC_BE]);
15657702e788SFelix Fietkau 	debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
15667702e788SFelix Fietkau 			   &sc->tx.txq_max_pending[WME_AC_VI]);
15677702e788SFelix Fietkau 	debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
15687702e788SFelix Fietkau 			   &sc->tx.txq_max_pending[WME_AC_VO]);
1569c70cab1aSFelix Fietkau 	debugfs_create_file("stations", S_IRUSR, sc->debug.debugfs_phy, sc,
1570c70cab1aSFelix Fietkau 			    &fops_stations);
1571c70cab1aSFelix Fietkau 	debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy, sc,
1572c70cab1aSFelix Fietkau 			    &fops_misc);
1573f8b815dcSSujith Manoharan 	debugfs_create_file("reset", S_IRUSR, sc->debug.debugfs_phy, sc,
1574f8b815dcSSujith Manoharan 			    &fops_reset);
1575c70cab1aSFelix Fietkau 	debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy, sc,
1576c70cab1aSFelix Fietkau 			    &fops_recv);
1577c70cab1aSFelix Fietkau 	debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
1578c70cab1aSFelix Fietkau 			    sc->debug.debugfs_phy, sc, &fops_rx_chainmask);
1579c70cab1aSFelix Fietkau 	debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
1580c70cab1aSFelix Fietkau 			    sc->debug.debugfs_phy, sc, &fops_tx_chainmask);
158105c0be2fSMohammed Shafi Shajakhan 	debugfs_create_file("disable_ani", S_IRUSR | S_IWUSR,
158205c0be2fSMohammed Shafi Shajakhan 			    sc->debug.debugfs_phy, sc, &fops_disable_ani);
1583c70cab1aSFelix Fietkau 	debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1584c70cab1aSFelix Fietkau 			    sc, &fops_regidx);
1585c70cab1aSFelix Fietkau 	debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1586c70cab1aSFelix Fietkau 			    sc, &fops_regval);
1587c70cab1aSFelix Fietkau 	debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1588c70cab1aSFelix Fietkau 			    sc->debug.debugfs_phy,
1589c70cab1aSFelix Fietkau 			    &ah->config.cwm_ignore_extcca);
1590c70cab1aSFelix Fietkau 	debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
1591c70cab1aSFelix Fietkau 			    &fops_regdump);
1592d069a46bSRajkumar Manoharan 	debugfs_create_file("dump_nfcal", S_IRUSR, sc->debug.debugfs_phy, sc,
1593d069a46bSRajkumar Manoharan 			    &fops_dump_nfcal);
1594580f010fSRajkumar Manoharan 	debugfs_create_file("base_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
1595580f010fSRajkumar Manoharan 			    &fops_base_eeprom);
15963f4c4bddSRajkumar Manoharan 	debugfs_create_file("modal_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
15973f4c4bddSRajkumar Manoharan 			    &fops_modal_eeprom);
15985baec742SFelix Fietkau #ifdef CONFIG_ATH9K_MAC_DEBUG
1599cf3af748SRajkumar Manoharan 	debugfs_create_file("samples", S_IRUSR, sc->debug.debugfs_phy, sc,
1600cf3af748SRajkumar Manoharan 			    &fops_samps);
16015baec742SFelix Fietkau #endif
1602582d0064SVasanthakumar Thiagarajan 
1603691680b8SFelix Fietkau 	debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
1604691680b8SFelix Fietkau 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
1605691680b8SFelix Fietkau 
1606691680b8SFelix Fietkau 	debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
1607691680b8SFelix Fietkau 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
1608691680b8SFelix Fietkau 
1609203c4805SLuis R. Rodriguez 	return 0;
1610203c4805SLuis R. Rodriguez }
1611