xref: /linux/drivers/net/wireless/ath/ath9k/debug.c (revision 74673db99ca3c09d34ea479f684522ceedb65eb9)
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++;
376203c4805SLuis R. Rodriguez }
377203c4805SLuis R. Rodriguez 
378203c4805SLuis R. Rodriguez static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
379203c4805SLuis R. Rodriguez 				   size_t count, loff_t *ppos)
380203c4805SLuis R. Rodriguez {
381203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
382203c4805SLuis R. Rodriguez 	unsigned int len = 0;
383462e58f2SBen Greear 	int rv;
384462e58f2SBen Greear 	int mxlen = 4000;
385462e58f2SBen Greear 	char *buf = kmalloc(mxlen, GFP_KERNEL);
386462e58f2SBen Greear 	if (!buf)
387462e58f2SBen Greear 		return -ENOMEM;
388462e58f2SBen Greear 
389462e58f2SBen Greear #define PR_IS(a, s)						\
390462e58f2SBen Greear 	do {							\
391462e58f2SBen Greear 		len += snprintf(buf + len, mxlen - len,		\
392462e58f2SBen Greear 				"%21s: %10u\n", a,		\
393462e58f2SBen Greear 				sc->debug.stats.istats.s);	\
394462e58f2SBen Greear 	} while (0)
395203c4805SLuis R. Rodriguez 
396a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
397462e58f2SBen Greear 		PR_IS("RXLP", rxlp);
398462e58f2SBen Greear 		PR_IS("RXHP", rxhp);
399462e58f2SBen Greear 		PR_IS("WATHDOG", bb_watchdog);
400a9616f41SLuis R. Rodriguez 	} else {
401462e58f2SBen Greear 		PR_IS("RX", rxok);
402a9616f41SLuis R. Rodriguez 	}
403462e58f2SBen Greear 	PR_IS("RXEOL", rxeol);
404462e58f2SBen Greear 	PR_IS("RXORN", rxorn);
405462e58f2SBen Greear 	PR_IS("TX", txok);
406462e58f2SBen Greear 	PR_IS("TXURN", txurn);
407462e58f2SBen Greear 	PR_IS("MIB", mib);
408462e58f2SBen Greear 	PR_IS("RXPHY", rxphyerr);
409462e58f2SBen Greear 	PR_IS("RXKCM", rx_keycache_miss);
410462e58f2SBen Greear 	PR_IS("SWBA", swba);
411462e58f2SBen Greear 	PR_IS("BMISS", bmiss);
412462e58f2SBen Greear 	PR_IS("BNR", bnr);
413462e58f2SBen Greear 	PR_IS("CST", cst);
414462e58f2SBen Greear 	PR_IS("GTT", gtt);
415462e58f2SBen Greear 	PR_IS("TIM", tim);
416462e58f2SBen Greear 	PR_IS("CABEND", cabend);
417462e58f2SBen Greear 	PR_IS("DTIMSYNC", dtimsync);
418462e58f2SBen Greear 	PR_IS("DTIM", dtim);
419462e58f2SBen Greear 	PR_IS("TSFOOR", tsfoor);
42097ba515aSSujith Manoharan 	PR_IS("MCI", mci);
421462e58f2SBen Greear 	PR_IS("TOTAL", total);
422203c4805SLuis R. Rodriguez 
423462e58f2SBen Greear 	len += snprintf(buf + len, mxlen - len,
424462e58f2SBen Greear 			"SYNC_CAUSE stats:\n");
4256dde1aabSMohammed Shafi Shajakhan 
426462e58f2SBen Greear 	PR_IS("Sync-All", sync_cause_all);
427462e58f2SBen Greear 	PR_IS("RTC-IRQ", sync_rtc_irq);
428462e58f2SBen Greear 	PR_IS("MAC-IRQ", sync_mac_irq);
429462e58f2SBen Greear 	PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
430462e58f2SBen Greear 	PR_IS("APB-Timeout", apb_timeout);
431462e58f2SBen Greear 	PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
432462e58f2SBen Greear 	PR_IS("HOST1-Fatal", host1_fatal);
433462e58f2SBen Greear 	PR_IS("HOST1-Perr", host1_perr);
434462e58f2SBen Greear 	PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
435462e58f2SBen Greear 	PR_IS("RADM-CPL-EP", radm_cpl_ep);
436462e58f2SBen Greear 	PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
437462e58f2SBen Greear 	PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
438462e58f2SBen Greear 	PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
439462e58f2SBen Greear 	PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
440462e58f2SBen Greear 	PR_IS("Local-Bus-Timeout", local_timeout);
441462e58f2SBen Greear 	PR_IS("PM-Access", pm_access);
442462e58f2SBen Greear 	PR_IS("MAC-Awake", mac_awake);
443462e58f2SBen Greear 	PR_IS("MAC-Asleep", mac_asleep);
444462e58f2SBen Greear 	PR_IS("MAC-Sleep-Access", mac_sleep_access);
4452b87f3aaSDan Carpenter 
446462e58f2SBen Greear 	if (len > mxlen)
447462e58f2SBen Greear 		len = mxlen;
448462e58f2SBen Greear 
449462e58f2SBen Greear 	rv = simple_read_from_buffer(user_buf, count, ppos, buf, len);
450462e58f2SBen Greear 	kfree(buf);
451462e58f2SBen Greear 	return rv;
452203c4805SLuis R. Rodriguez }
453203c4805SLuis R. Rodriguez 
454203c4805SLuis R. Rodriguez static const struct file_operations fops_interrupt = {
455203c4805SLuis R. Rodriguez 	.read = read_file_interrupt,
456234e3405SStephen Boyd 	.open = simple_open,
4576038f373SArnd Bergmann 	.owner = THIS_MODULE,
4586038f373SArnd Bergmann 	.llseek = default_llseek,
459203c4805SLuis R. Rodriguez };
460203c4805SLuis R. Rodriguez 
4615bec3e5aSFelix Fietkau #define PR_QNUM(_n) sc->tx.txq_map[_n]->axq_qnum
462fec247c0SSujith #define PR(str, elem)							\
463fec247c0SSujith 	do {								\
464fec247c0SSujith 		len += snprintf(buf + len, size - len,			\
465fec247c0SSujith 				"%s%13u%11u%10u%10u\n", str,		\
4665bec3e5aSFelix Fietkau 		sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].elem, \
4675bec3e5aSFelix Fietkau 		sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].elem, \
4685bec3e5aSFelix Fietkau 		sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].elem, \
4695bec3e5aSFelix Fietkau 		sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].elem); \
4707f010c93SBen Greear 		if (len >= size)			  \
4717f010c93SBen Greear 			goto done;			  \
472fec247c0SSujith } while(0)
473fec247c0SSujith 
4741f427dd9SBen Greear #define PRX(str, elem)							\
4751f427dd9SBen Greear do {									\
4761f427dd9SBen Greear 	len += snprintf(buf + len, size - len,				\
4771f427dd9SBen Greear 			"%s%13u%11u%10u%10u\n", str,			\
4785bec3e5aSFelix Fietkau 			(unsigned int)(sc->tx.txq_map[WME_AC_BE]->elem),	\
4795bec3e5aSFelix Fietkau 			(unsigned int)(sc->tx.txq_map[WME_AC_BK]->elem),	\
4805bec3e5aSFelix Fietkau 			(unsigned int)(sc->tx.txq_map[WME_AC_VI]->elem),	\
4815bec3e5aSFelix Fietkau 			(unsigned int)(sc->tx.txq_map[WME_AC_VO]->elem));	\
4827f010c93SBen Greear 	if (len >= size)						\
4837f010c93SBen Greear 		goto done;						\
4841f427dd9SBen Greear } while(0)
4851f427dd9SBen Greear 
4862dac4fb9SBen Greear #define PRQLE(str, elem)						\
4872dac4fb9SBen Greear do {									\
4882dac4fb9SBen Greear 	len += snprintf(buf + len, size - len,				\
4892dac4fb9SBen Greear 			"%s%13i%11i%10i%10i\n", str,			\
4905bec3e5aSFelix Fietkau 			list_empty(&sc->tx.txq_map[WME_AC_BE]->elem),	\
4915bec3e5aSFelix Fietkau 			list_empty(&sc->tx.txq_map[WME_AC_BK]->elem),	\
4925bec3e5aSFelix Fietkau 			list_empty(&sc->tx.txq_map[WME_AC_VI]->elem),	\
4935bec3e5aSFelix Fietkau 			list_empty(&sc->tx.txq_map[WME_AC_VO]->elem));	\
4947f010c93SBen Greear 	if (len >= size)						\
4957f010c93SBen Greear 		goto done;						\
4962dac4fb9SBen Greear } while (0)
4972dac4fb9SBen Greear 
498fec247c0SSujith static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
499fec247c0SSujith 			      size_t count, loff_t *ppos)
500fec247c0SSujith {
501fec247c0SSujith 	struct ath_softc *sc = file->private_data;
502fec247c0SSujith 	char *buf;
5037f010c93SBen Greear 	unsigned int len = 0, size = 8000;
5042dac4fb9SBen Greear 	int i;
505fec247c0SSujith 	ssize_t retval = 0;
5062dac4fb9SBen Greear 	char tmp[32];
507fec247c0SSujith 
508fec247c0SSujith 	buf = kzalloc(size, GFP_KERNEL);
509fec247c0SSujith 	if (buf == NULL)
51004236066SDan Carpenter 		return -ENOMEM;
511fec247c0SSujith 
51260f2d1d5SBen Greear 	len += sprintf(buf, "Num-Tx-Queues: %i  tx-queues-setup: 0x%x"
51360f2d1d5SBen Greear 		       " poll-work-seen: %u\n"
5147f010c93SBen Greear 		       "%30s %10s%10s%10s\n\n",
5157f010c93SBen Greear 		       ATH9K_NUM_TX_QUEUES, sc->tx.txqsetup,
51660f2d1d5SBen Greear 		       sc->tx_complete_poll_work_seen,
5177f010c93SBen Greear 		       "BE", "BK", "VI", "VO");
518fec247c0SSujith 
519fec247c0SSujith 	PR("MPDUs Queued:    ", queued);
520fec247c0SSujith 	PR("MPDUs Completed: ", completed);
5215a6f78afSFelix Fietkau 	PR("MPDUs XRetried:  ", xretries);
522fec247c0SSujith 	PR("Aggregates:      ", a_aggr);
523bda8addaSBen Greear 	PR("AMPDUs Queued HW:", a_queued_hw);
524bda8addaSBen Greear 	PR("AMPDUs Queued SW:", a_queued_sw);
525fec247c0SSujith 	PR("AMPDUs Completed:", a_completed);
526fec247c0SSujith 	PR("AMPDUs Retried:  ", a_retries);
527fec247c0SSujith 	PR("AMPDUs XRetried: ", a_xretries);
528fec247c0SSujith 	PR("FIFO Underrun:   ", fifo_underrun);
529fec247c0SSujith 	PR("TXOP Exceeded:   ", xtxop);
530fec247c0SSujith 	PR("TXTIMER Expiry:  ", timer_exp);
531fec247c0SSujith 	PR("DESC CFG Error:  ", desc_cfg_err);
532fec247c0SSujith 	PR("DATA Underrun:   ", data_underrun);
533fec247c0SSujith 	PR("DELIM Underrun:  ", delim_underrun);
53499c15bf5SBen Greear 	PR("TX-Pkts-All:     ", tx_pkts_all);
53599c15bf5SBen Greear 	PR("TX-Bytes-All:    ", tx_bytes_all);
5362dac4fb9SBen Greear 	PR("hw-put-tx-buf:   ", puttxbuf);
5372dac4fb9SBen Greear 	PR("hw-tx-start:     ", txstart);
5382dac4fb9SBen Greear 	PR("hw-tx-proc-desc: ", txprocdesc);
539a5a0bca1SBen Greear 	PR("TX-Failed:       ", txfailed);
5407f010c93SBen Greear 	len += snprintf(buf + len, size - len,
5417f010c93SBen Greear 			"%s%11p%11p%10p%10p\n", "txq-memory-address:",
542db7889cdSBen Greear 			sc->tx.txq_map[WME_AC_BE],
543db7889cdSBen Greear 			sc->tx.txq_map[WME_AC_BK],
544db7889cdSBen Greear 			sc->tx.txq_map[WME_AC_VI],
545db7889cdSBen Greear 			sc->tx.txq_map[WME_AC_VO]);
5467f010c93SBen Greear 	if (len >= size)
5477f010c93SBen Greear 		goto done;
548fec247c0SSujith 
5491f427dd9SBen Greear 	PRX("axq-qnum:        ", axq_qnum);
5501f427dd9SBen Greear 	PRX("axq-depth:       ", axq_depth);
5512dac4fb9SBen Greear 	PRX("axq-ampdu_depth: ", axq_ampdu_depth);
5521f427dd9SBen Greear 	PRX("axq-stopped      ", stopped);
5531f427dd9SBen Greear 	PRX("tx-in-progress   ", axq_tx_inprogress);
5541f427dd9SBen Greear 	PRX("pending-frames   ", pending_frames);
5552dac4fb9SBen Greear 	PRX("txq_headidx:     ", txq_headidx);
5562dac4fb9SBen Greear 	PRX("txq_tailidx:     ", txq_headidx);
5571f427dd9SBen Greear 
5582dac4fb9SBen Greear 	PRQLE("axq_q empty:       ", axq_q);
5592dac4fb9SBen Greear 	PRQLE("axq_acq empty:     ", axq_acq);
5602dac4fb9SBen Greear 	for (i = 0; i < ATH_TXFIFO_DEPTH; i++) {
5612dac4fb9SBen Greear 		snprintf(tmp, sizeof(tmp) - 1, "txq_fifo[%i] empty: ", i);
5622dac4fb9SBen Greear 		PRQLE(tmp, txq_fifo[i]);
5632dac4fb9SBen Greear 	}
5647f010c93SBen Greear 
56571e025a5SBen Greear 	/* Print out more detailed queue-info */
56671e025a5SBen Greear 	for (i = 0; i <= WME_AC_BK; i++) {
56771e025a5SBen Greear 		struct ath_txq *txq = &(sc->tx.txq[i]);
56871e025a5SBen Greear 		struct ath_atx_ac *ac;
56971e025a5SBen Greear 		struct ath_atx_tid *tid;
57071e025a5SBen Greear 		if (len >= size)
57171e025a5SBen Greear 			goto done;
57271e025a5SBen Greear 		spin_lock_bh(&txq->axq_lock);
57371e025a5SBen Greear 		if (!list_empty(&txq->axq_acq)) {
57471e025a5SBen Greear 			ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac,
57571e025a5SBen Greear 					      list);
57671e025a5SBen Greear 			len += snprintf(buf + len, size - len,
57771e025a5SBen Greear 					"txq[%i] first-ac: %p sched: %i\n",
57871e025a5SBen Greear 					i, ac, ac->sched);
57971e025a5SBen Greear 			if (list_empty(&ac->tid_q) || (len >= size))
58071e025a5SBen Greear 				goto done_for;
58171e025a5SBen Greear 			tid = list_first_entry(&ac->tid_q, struct ath_atx_tid,
58271e025a5SBen Greear 					       list);
58371e025a5SBen Greear 			len += snprintf(buf + len, size - len,
58471e025a5SBen Greear 					" first-tid: %p sched: %i paused: %i\n",
58571e025a5SBen Greear 					tid, tid->sched, tid->paused);
58671e025a5SBen Greear 		}
58771e025a5SBen Greear 	done_for:
58871e025a5SBen Greear 		spin_unlock_bh(&txq->axq_lock);
58971e025a5SBen Greear 	}
59071e025a5SBen Greear 
5917f010c93SBen Greear done:
5927f010c93SBen Greear 	if (len > size)
5937f010c93SBen Greear 		len = size;
5947f010c93SBen Greear 
5957f010c93SBen Greear 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
5967f010c93SBen Greear 	kfree(buf);
5977f010c93SBen Greear 
5987f010c93SBen Greear 	return retval;
5997f010c93SBen Greear }
6007f010c93SBen Greear 
6017f010c93SBen Greear static ssize_t read_file_stations(struct file *file, char __user *user_buf,
6027f010c93SBen Greear 				  size_t count, loff_t *ppos)
6037f010c93SBen Greear {
6047f010c93SBen Greear 	struct ath_softc *sc = file->private_data;
6057f010c93SBen Greear 	char *buf;
6067f010c93SBen Greear 	unsigned int len = 0, size = 64000;
6077f010c93SBen Greear 	struct ath_node *an = NULL;
6087f010c93SBen Greear 	ssize_t retval = 0;
6097f010c93SBen Greear 	int q;
6107f010c93SBen Greear 
6117f010c93SBen Greear 	buf = kzalloc(size, GFP_KERNEL);
6127f010c93SBen Greear 	if (buf == NULL)
6137f010c93SBen Greear 		return -ENOMEM;
6147f010c93SBen Greear 
6157f010c93SBen Greear 	len += snprintf(buf + len, size - len,
6167f010c93SBen Greear 			"Stations:\n"
6177e1e3864SBen Greear 			" tid: addr sched paused buf_q-empty an ac baw\n"
6187f010c93SBen Greear 			" ac: addr sched tid_q-empty txq\n");
6197f010c93SBen Greear 
6207f010c93SBen Greear 	spin_lock(&sc->nodes_lock);
6217f010c93SBen Greear 	list_for_each_entry(an, &sc->nodes, list) {
6227e1e3864SBen Greear 		unsigned short ma = an->maxampdu;
6237e1e3864SBen Greear 		if (ma == 0)
6247e1e3864SBen Greear 			ma = 65535; /* see ath_lookup_rate */
6257f010c93SBen Greear 		len += snprintf(buf + len, size - len,
6267e1e3864SBen Greear 				"iface: %pM  sta: %pM max-ampdu: %hu mpdu-density: %uus\n",
6277e1e3864SBen Greear 				an->vif->addr, an->sta->addr, ma,
6287e1e3864SBen Greear 				(unsigned int)(an->mpdudensity));
6297f010c93SBen Greear 		if (len >= size)
6307f010c93SBen Greear 			goto done;
6317f010c93SBen Greear 
6327f010c93SBen Greear 		for (q = 0; q < WME_NUM_TID; q++) {
6337f010c93SBen Greear 			struct ath_atx_tid *tid = &(an->tid[q]);
6347f010c93SBen Greear 			len += snprintf(buf + len, size - len,
6357e1e3864SBen Greear 					" tid: %p %s %s %i %p %p %hu\n",
6367f010c93SBen Greear 					tid, tid->sched ? "sched" : "idle",
6377f010c93SBen Greear 					tid->paused ? "paused" : "running",
63856dc6336SFelix Fietkau 					skb_queue_empty(&tid->buf_q),
6397e1e3864SBen Greear 					tid->an, tid->ac, tid->baw_size);
6407f010c93SBen Greear 			if (len >= size)
6417f010c93SBen Greear 				goto done;
6427f010c93SBen Greear 		}
6437f010c93SBen Greear 
6447f010c93SBen Greear 		for (q = 0; q < WME_NUM_AC; q++) {
6457f010c93SBen Greear 			struct ath_atx_ac *ac = &(an->ac[q]);
6467f010c93SBen Greear 			len += snprintf(buf + len, size - len,
6477f010c93SBen Greear 					" ac: %p %s %i %p\n",
6487f010c93SBen Greear 					ac, ac->sched ? "sched" : "idle",
6497f010c93SBen Greear 					list_empty(&ac->tid_q), ac->txq);
6507f010c93SBen Greear 			if (len >= size)
6517f010c93SBen Greear 				goto done;
6527f010c93SBen Greear 		}
6537f010c93SBen Greear 	}
6547f010c93SBen Greear 
6557f010c93SBen Greear done:
6567f010c93SBen Greear 	spin_unlock(&sc->nodes_lock);
6572b87f3aaSDan Carpenter 	if (len > size)
6582b87f3aaSDan Carpenter 		len = size;
6592b87f3aaSDan Carpenter 
660fec247c0SSujith 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
661fec247c0SSujith 	kfree(buf);
662fec247c0SSujith 
663fec247c0SSujith 	return retval;
664fec247c0SSujith }
665fec247c0SSujith 
66655f6d0ffSBen Greear static ssize_t read_file_misc(struct file *file, char __user *user_buf,
66755f6d0ffSBen Greear 			      size_t count, loff_t *ppos)
66855f6d0ffSBen Greear {
66955f6d0ffSBen Greear 	struct ath_softc *sc = file->private_data;
67055f6d0ffSBen Greear 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
67155f6d0ffSBen Greear 	struct ieee80211_hw *hw = sc->hw;
6726bcf6f64SSujith Manoharan 	struct ath9k_vif_iter_data iter_data;
6736bcf6f64SSujith Manoharan 	char buf[512];
6746bcf6f64SSujith Manoharan 	unsigned int len = 0;
67555f6d0ffSBen Greear 	ssize_t retval = 0;
67655f6d0ffSBen Greear 	unsigned int reg;
6776bcf6f64SSujith Manoharan 	u32 rxfilter;
6786bcf6f64SSujith Manoharan 
6796bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
6806bcf6f64SSujith Manoharan 			"BSSID: %pM\n", common->curbssid);
6816bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
6826bcf6f64SSujith Manoharan 			"BSSID-MASK: %pM\n", common->bssidmask);
6836bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
6846bcf6f64SSujith Manoharan 			"OPMODE: %s\n", ath_opmode_to_string(sc->sc_ah->opmode));
6856bcf6f64SSujith Manoharan 
6866bcf6f64SSujith Manoharan 	ath9k_ps_wakeup(sc);
6876bcf6f64SSujith Manoharan 	rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
6886bcf6f64SSujith Manoharan 	ath9k_ps_restore(sc);
6896bcf6f64SSujith Manoharan 
6906bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
6916bcf6f64SSujith Manoharan 			"RXFILTER: 0x%x", rxfilter);
6926bcf6f64SSujith Manoharan 
6936bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_UCAST)
6946bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " UCAST");
6956bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MCAST)
6966bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " MCAST");
6976bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_BCAST)
6986bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " BCAST");
6996bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_CONTROL)
7006bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " CONTROL");
7016bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_BEACON)
7026bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " BEACON");
7036bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PROM)
7046bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " PROM");
7056bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
7066bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
7076bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PHYERR)
7086bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " PHYERR");
7096bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
7106bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " MYBEACON");
7116bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
7126bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
7136bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
7146bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " PSPOLL");
7156bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
7166bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
7176bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
7186bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL");
7196bcf6f64SSujith Manoharan 	if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
7206bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " CONTROL_WRAPPER");
7216bcf6f64SSujith Manoharan 
7226bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len, "\n");
7236bcf6f64SSujith Manoharan 
7246bcf6f64SSujith Manoharan 	reg = sc->sc_ah->imask;
7256bcf6f64SSujith Manoharan 
7266bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len, "INTERRUPT-MASK: 0x%x", reg);
7276bcf6f64SSujith Manoharan 
7286bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_SWBA)
7296bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " SWBA");
7306bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_BMISS)
7316bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " BMISS");
7326bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_CST)
7336bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " CST");
7346bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RX)
7356bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " RX");
7366bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RXHP)
7376bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " RXHP");
7386bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_RXLP)
7396bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " RXLP");
7406bcf6f64SSujith Manoharan 	if (reg & ATH9K_INT_BB_WATCHDOG)
7416bcf6f64SSujith Manoharan 		len += snprintf(buf + len, sizeof(buf) - len, " BB_WATCHDOG");
7426bcf6f64SSujith Manoharan 
7436bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len, "\n");
74455f6d0ffSBen Greear 
74555f6d0ffSBen Greear 	ath9k_calculate_iter_data(hw, NULL, &iter_data);
74655f6d0ffSBen Greear 
7476bcf6f64SSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
7486bcf6f64SSujith Manoharan 			"VIF-COUNTS: AP: %i STA: %i MESH: %i WDS: %i"
749bcf6f96eSSujith Manoharan 			" ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n",
75055f6d0ffSBen Greear 			iter_data.naps, iter_data.nstations, iter_data.nmeshes,
751bcf6f96eSSujith Manoharan 			iter_data.nwds, iter_data.nadhocs,
75255f6d0ffSBen Greear 			sc->nvifs, sc->nbcnvifs);
75355f6d0ffSBen Greear 
7546bcf6f64SSujith Manoharan 	if (len > sizeof(buf))
7556bcf6f64SSujith Manoharan 		len = sizeof(buf);
75655f6d0ffSBen Greear 
75755f6d0ffSBen Greear 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
75855f6d0ffSBen Greear 	return retval;
75955f6d0ffSBen Greear }
76055f6d0ffSBen Greear 
761f8b815dcSSujith Manoharan static ssize_t read_file_reset(struct file *file, char __user *user_buf,
762f8b815dcSSujith Manoharan 			       size_t count, loff_t *ppos)
763f8b815dcSSujith Manoharan {
764f8b815dcSSujith Manoharan 	struct ath_softc *sc = file->private_data;
765f8b815dcSSujith Manoharan 	char buf[512];
766f8b815dcSSujith Manoharan 	unsigned int len = 0;
767f8b815dcSSujith Manoharan 
768f8b815dcSSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
769f8b815dcSSujith Manoharan 			"%17s: %2d\n", "Baseband Hang",
770f8b815dcSSujith Manoharan 			sc->debug.stats.reset[RESET_TYPE_BB_HANG]);
771f8b815dcSSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
772f8b815dcSSujith Manoharan 			"%17s: %2d\n", "Baseband Watchdog",
773f8b815dcSSujith Manoharan 			sc->debug.stats.reset[RESET_TYPE_BB_WATCHDOG]);
774f8b815dcSSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
775f8b815dcSSujith Manoharan 			"%17s: %2d\n", "Fatal HW Error",
776f8b815dcSSujith Manoharan 			sc->debug.stats.reset[RESET_TYPE_FATAL_INT]);
777f8b815dcSSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
778f8b815dcSSujith Manoharan 			"%17s: %2d\n", "TX HW error",
779f8b815dcSSujith Manoharan 			sc->debug.stats.reset[RESET_TYPE_TX_ERROR]);
780f8b815dcSSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
781f8b815dcSSujith Manoharan 			"%17s: %2d\n", "TX Path Hang",
782f8b815dcSSujith Manoharan 			sc->debug.stats.reset[RESET_TYPE_TX_HANG]);
783f8b815dcSSujith Manoharan 	len += snprintf(buf + len, sizeof(buf) - len,
784f8b815dcSSujith Manoharan 			"%17s: %2d\n", "PLL RX Hang",
785f8b815dcSSujith Manoharan 			sc->debug.stats.reset[RESET_TYPE_PLL_HANG]);
786f8b815dcSSujith Manoharan 
787f8b815dcSSujith Manoharan 	if (len > sizeof(buf))
788f8b815dcSSujith Manoharan 		len = sizeof(buf);
789f8b815dcSSujith Manoharan 
790f8b815dcSSujith Manoharan 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
791f8b815dcSSujith Manoharan }
792f8b815dcSSujith Manoharan 
793066dae93SFelix Fietkau void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
79455797b1aSFelix Fietkau 		       struct ath_tx_status *ts, struct ath_txq *txq,
79555797b1aSFelix Fietkau 		       unsigned int flags)
796fec247c0SSujith {
797cf3af748SRajkumar Manoharan #define TX_SAMP_DBG(c) (sc->debug.bb_mac_samp[sc->debug.sampidx].ts\
798cf3af748SRajkumar Manoharan 			[sc->debug.tsidx].c)
7995bec3e5aSFelix Fietkau 	int qnum = txq->axq_qnum;
800066dae93SFelix Fietkau 
801066dae93SFelix Fietkau 	TX_STAT_INC(qnum, tx_pkts_all);
802066dae93SFelix Fietkau 	sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
80399c15bf5SBen Greear 
804fec247c0SSujith 	if (bf_isampdu(bf)) {
805156369faSFelix Fietkau 		if (flags & ATH_TX_ERROR)
806066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_xretries);
807fec247c0SSujith 		else
808066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_completed);
809fec247c0SSujith 	} else {
81055797b1aSFelix Fietkau 		if (ts->ts_status & ATH9K_TXERR_XRETRY)
8115a6f78afSFelix Fietkau 			TX_STAT_INC(qnum, xretries);
8125a6f78afSFelix Fietkau 		else
813066dae93SFelix Fietkau 			TX_STAT_INC(qnum, completed);
814fec247c0SSujith 	}
815fec247c0SSujith 
816db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_FIFO)
817066dae93SFelix Fietkau 		TX_STAT_INC(qnum, fifo_underrun);
818db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_XTXOP)
819066dae93SFelix Fietkau 		TX_STAT_INC(qnum, xtxop);
820db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
821066dae93SFelix Fietkau 		TX_STAT_INC(qnum, timer_exp);
822db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
823066dae93SFelix Fietkau 		TX_STAT_INC(qnum, desc_cfg_err);
824db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
825066dae93SFelix Fietkau 		TX_STAT_INC(qnum, data_underrun);
826db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
827066dae93SFelix Fietkau 		TX_STAT_INC(qnum, delim_underrun);
828cf3af748SRajkumar Manoharan 
8295baec742SFelix Fietkau #ifdef CONFIG_ATH9K_MAC_DEBUG
830cf3af748SRajkumar Manoharan 	spin_lock(&sc->debug.samp_lock);
831cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(jiffies) = jiffies;
832cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(rssi_ctl0) = ts->ts_rssi_ctl0;
833cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(rssi_ctl1) = ts->ts_rssi_ctl1;
834cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(rssi_ctl2) = ts->ts_rssi_ctl2;
835cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(rssi_ext0) = ts->ts_rssi_ext0;
836cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(rssi_ext1) = ts->ts_rssi_ext1;
837cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(rssi_ext2) = ts->ts_rssi_ext2;
838cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(rateindex) = ts->ts_rateindex;
839cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(isok) = !!(ts->ts_status & ATH9K_TXERR_MASK);
840cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(rts_fail_cnt) = ts->ts_shortretry;
841cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(data_fail_cnt) = ts->ts_longretry;
842cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(rssi) = ts->ts_rssi;
843cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(tid) = ts->tid;
844cf3af748SRajkumar Manoharan 	TX_SAMP_DBG(qid) = ts->qid;
84512932180SMohammed Shafi Shajakhan 
84612932180SMohammed Shafi Shajakhan 	if (ts->ts_flags & ATH9K_TX_BA) {
84712932180SMohammed Shafi Shajakhan 		TX_SAMP_DBG(ba_low) = ts->ba_low;
84812932180SMohammed Shafi Shajakhan 		TX_SAMP_DBG(ba_high) = ts->ba_high;
84912932180SMohammed Shafi Shajakhan 	} else {
85012932180SMohammed Shafi Shajakhan 		TX_SAMP_DBG(ba_low) = 0;
85112932180SMohammed Shafi Shajakhan 		TX_SAMP_DBG(ba_high) = 0;
85212932180SMohammed Shafi Shajakhan 	}
85312932180SMohammed Shafi Shajakhan 
854cf3af748SRajkumar Manoharan 	sc->debug.tsidx = (sc->debug.tsidx + 1) % ATH_DBG_MAX_SAMPLES;
855cf3af748SRajkumar Manoharan 	spin_unlock(&sc->debug.samp_lock);
8565baec742SFelix Fietkau #endif
857cf3af748SRajkumar Manoharan 
858cf3af748SRajkumar Manoharan #undef TX_SAMP_DBG
859fec247c0SSujith }
860fec247c0SSujith 
861fec247c0SSujith static const struct file_operations fops_xmit = {
862fec247c0SSujith 	.read = read_file_xmit,
863234e3405SStephen Boyd 	.open = simple_open,
8646038f373SArnd Bergmann 	.owner = THIS_MODULE,
8656038f373SArnd Bergmann 	.llseek = default_llseek,
866fec247c0SSujith };
867203c4805SLuis R. Rodriguez 
8687f010c93SBen Greear static const struct file_operations fops_stations = {
8697f010c93SBen Greear 	.read = read_file_stations,
870234e3405SStephen Boyd 	.open = simple_open,
8717f010c93SBen Greear 	.owner = THIS_MODULE,
8727f010c93SBen Greear 	.llseek = default_llseek,
8737f010c93SBen Greear };
8747f010c93SBen Greear 
87555f6d0ffSBen Greear static const struct file_operations fops_misc = {
87655f6d0ffSBen Greear 	.read = read_file_misc,
877234e3405SStephen Boyd 	.open = simple_open,
87855f6d0ffSBen Greear 	.owner = THIS_MODULE,
87955f6d0ffSBen Greear 	.llseek = default_llseek,
88055f6d0ffSBen Greear };
88155f6d0ffSBen Greear 
882f8b815dcSSujith Manoharan static const struct file_operations fops_reset = {
883f8b815dcSSujith Manoharan 	.read = read_file_reset,
884234e3405SStephen Boyd 	.open = simple_open,
885f8b815dcSSujith Manoharan 	.owner = THIS_MODULE,
886f8b815dcSSujith Manoharan 	.llseek = default_llseek,
887f8b815dcSSujith Manoharan };
888f8b815dcSSujith Manoharan 
8891395d3f0SSujith static ssize_t read_file_recv(struct file *file, char __user *user_buf,
8901395d3f0SSujith 			      size_t count, loff_t *ppos)
8911395d3f0SSujith {
8921395d3f0SSujith #define PHY_ERR(s, p) \
8934203214eSSujith Manoharan 	len += snprintf(buf + len, size - len, "%22s : %10u\n", s, \
8941395d3f0SSujith 			sc->debug.stats.rxstats.phy_err_stats[p]);
8951395d3f0SSujith 
89624a0731eSBen Greear #define RXS_ERR(s, e)					    \
89724a0731eSBen Greear 	do {						    \
89824a0731eSBen Greear 		len += snprintf(buf + len, size - len,	    \
89924a0731eSBen Greear 				"%22s : %10u\n", s,	    \
90024a0731eSBen Greear 				sc->debug.stats.rxstats.e); \
90124a0731eSBen Greear 	} while (0)
90224a0731eSBen Greear 
9031395d3f0SSujith 	struct ath_softc *sc = file->private_data;
9041395d3f0SSujith 	char *buf;
9054203214eSSujith Manoharan 	unsigned int len = 0, size = 1600;
9061395d3f0SSujith 	ssize_t retval = 0;
9071395d3f0SSujith 
9081395d3f0SSujith 	buf = kzalloc(size, GFP_KERNEL);
9091395d3f0SSujith 	if (buf == NULL)
91004236066SDan Carpenter 		return -ENOMEM;
9111395d3f0SSujith 
91224a0731eSBen Greear 	RXS_ERR("CRC ERR", crc_err);
91324a0731eSBen Greear 	RXS_ERR("DECRYPT CRC ERR", decrypt_crc_err);
91424a0731eSBen Greear 	RXS_ERR("PHY ERR", phy_err);
91524a0731eSBen Greear 	RXS_ERR("MIC ERR", mic_err);
91624a0731eSBen Greear 	RXS_ERR("PRE-DELIM CRC ERR", pre_delim_crc_err);
91724a0731eSBen Greear 	RXS_ERR("POST-DELIM CRC ERR", post_delim_crc_err);
91824a0731eSBen Greear 	RXS_ERR("DECRYPT BUSY ERR", decrypt_busy_err);
91924a0731eSBen Greear 	RXS_ERR("RX-LENGTH-ERR", rx_len_err);
92024a0731eSBen Greear 	RXS_ERR("RX-OOM-ERR", rx_oom_err);
92124a0731eSBen Greear 	RXS_ERR("RX-RATE-ERR", rx_rate_err);
92224a0731eSBen Greear 	RXS_ERR("RX-DROP-RXFLUSH", rx_drop_rxflush);
92324a0731eSBen Greear 	RXS_ERR("RX-TOO-MANY-FRAGS", rx_too_many_frags_err);
9241395d3f0SSujith 
9254203214eSSujith Manoharan 	PHY_ERR("UNDERRUN ERR", ATH9K_PHYERR_UNDERRUN);
9264203214eSSujith Manoharan 	PHY_ERR("TIMING ERR", ATH9K_PHYERR_TIMING);
9274203214eSSujith Manoharan 	PHY_ERR("PARITY ERR", ATH9K_PHYERR_PARITY);
9284203214eSSujith Manoharan 	PHY_ERR("RATE ERR", ATH9K_PHYERR_RATE);
9294203214eSSujith Manoharan 	PHY_ERR("LENGTH ERR", ATH9K_PHYERR_LENGTH);
9304203214eSSujith Manoharan 	PHY_ERR("RADAR ERR", ATH9K_PHYERR_RADAR);
9314203214eSSujith Manoharan 	PHY_ERR("SERVICE ERR", ATH9K_PHYERR_SERVICE);
9324203214eSSujith Manoharan 	PHY_ERR("TOR ERR", ATH9K_PHYERR_TOR);
9334203214eSSujith Manoharan 	PHY_ERR("OFDM-TIMING ERR", ATH9K_PHYERR_OFDM_TIMING);
9344203214eSSujith Manoharan 	PHY_ERR("OFDM-SIGNAL-PARITY ERR", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
9354203214eSSujith Manoharan 	PHY_ERR("OFDM-RATE ERR", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
9364203214eSSujith Manoharan 	PHY_ERR("OFDM-LENGTH ERR", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
9374203214eSSujith Manoharan 	PHY_ERR("OFDM-POWER-DROP ERR", ATH9K_PHYERR_OFDM_POWER_DROP);
9384203214eSSujith Manoharan 	PHY_ERR("OFDM-SERVICE ERR", ATH9K_PHYERR_OFDM_SERVICE);
9394203214eSSujith Manoharan 	PHY_ERR("OFDM-RESTART ERR", ATH9K_PHYERR_OFDM_RESTART);
9404203214eSSujith Manoharan 	PHY_ERR("FALSE-RADAR-EXT ERR", ATH9K_PHYERR_FALSE_RADAR_EXT);
9414203214eSSujith Manoharan 	PHY_ERR("CCK-TIMING ERR", ATH9K_PHYERR_CCK_TIMING);
9424203214eSSujith Manoharan 	PHY_ERR("CCK-HEADER-CRC ERR", ATH9K_PHYERR_CCK_HEADER_CRC);
9434203214eSSujith Manoharan 	PHY_ERR("CCK-RATE ERR", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
9444203214eSSujith Manoharan 	PHY_ERR("CCK-SERVICE ERR", ATH9K_PHYERR_CCK_SERVICE);
9454203214eSSujith Manoharan 	PHY_ERR("CCK-RESTART ERR", ATH9K_PHYERR_CCK_RESTART);
9464203214eSSujith Manoharan 	PHY_ERR("CCK-LENGTH ERR", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
9474203214eSSujith Manoharan 	PHY_ERR("CCK-POWER-DROP ERR", ATH9K_PHYERR_CCK_POWER_DROP);
9484203214eSSujith Manoharan 	PHY_ERR("HT-CRC ERR", ATH9K_PHYERR_HT_CRC_ERROR);
9494203214eSSujith Manoharan 	PHY_ERR("HT-LENGTH ERR", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
9504203214eSSujith Manoharan 	PHY_ERR("HT-RATE ERR", ATH9K_PHYERR_HT_RATE_ILLEGAL);
9514203214eSSujith Manoharan 
95224a0731eSBen Greear 	RXS_ERR("RX-Pkts-All", rx_pkts_all);
95324a0731eSBen Greear 	RXS_ERR("RX-Bytes-All", rx_bytes_all);
95424a0731eSBen Greear 	RXS_ERR("RX-Beacons", rx_beacons);
95524a0731eSBen Greear 	RXS_ERR("RX-Frags", rx_frags);
95699c15bf5SBen Greear 
9572b87f3aaSDan Carpenter 	if (len > size)
9582b87f3aaSDan Carpenter 		len = size;
9592b87f3aaSDan Carpenter 
9601395d3f0SSujith 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
9611395d3f0SSujith 	kfree(buf);
9621395d3f0SSujith 
9631395d3f0SSujith 	return retval;
9641395d3f0SSujith 
96524a0731eSBen Greear #undef RXS_ERR
9661395d3f0SSujith #undef PHY_ERR
9671395d3f0SSujith }
9681395d3f0SSujith 
9698e6f5aa2SFelix Fietkau void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
9701395d3f0SSujith {
9711395d3f0SSujith #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
972cf3af748SRajkumar Manoharan #define RX_SAMP_DBG(c) (sc->debug.bb_mac_samp[sc->debug.sampidx].rs\
973cf3af748SRajkumar Manoharan 			[sc->debug.rsidx].c)
9741395d3f0SSujith 
97599c15bf5SBen Greear 	RX_STAT_INC(rx_pkts_all);
97699c15bf5SBen Greear 	sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
97799c15bf5SBen Greear 
9788e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_CRC)
9791395d3f0SSujith 		RX_STAT_INC(crc_err);
9808e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_DECRYPT)
9811395d3f0SSujith 		RX_STAT_INC(decrypt_crc_err);
9828e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_MIC)
9831395d3f0SSujith 		RX_STAT_INC(mic_err);
9848e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
9851395d3f0SSujith 		RX_STAT_INC(pre_delim_crc_err);
9868e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
9871395d3f0SSujith 		RX_STAT_INC(post_delim_crc_err);
9888e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
9891395d3f0SSujith 		RX_STAT_INC(decrypt_busy_err);
9901395d3f0SSujith 
9918e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_PHY) {
9921395d3f0SSujith 		RX_STAT_INC(phy_err);
993dbb07f00SSujith Manoharan 		if (rs->rs_phyerr < ATH9K_PHYERR_MAX)
994dbb07f00SSujith Manoharan 			RX_PHY_ERR_INC(rs->rs_phyerr);
9951395d3f0SSujith 	}
9961395d3f0SSujith 
9975baec742SFelix Fietkau #ifdef CONFIG_ATH9K_MAC_DEBUG
998cf3af748SRajkumar Manoharan 	spin_lock(&sc->debug.samp_lock);
999cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(jiffies) = jiffies;
1000cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(rssi_ctl0) = rs->rs_rssi_ctl0;
1001cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(rssi_ctl1) = rs->rs_rssi_ctl1;
1002cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(rssi_ctl2) = rs->rs_rssi_ctl2;
1003cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(rssi_ext0) = rs->rs_rssi_ext0;
1004cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(rssi_ext1) = rs->rs_rssi_ext1;
1005cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(rssi_ext2) = rs->rs_rssi_ext2;
1006cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(antenna) = rs->rs_antenna;
1007cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(rssi) = rs->rs_rssi;
1008cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(rate) = rs->rs_rate;
1009cf3af748SRajkumar Manoharan 	RX_SAMP_DBG(is_mybeacon) = rs->is_mybeacon;
1010cf3af748SRajkumar Manoharan 
1011cf3af748SRajkumar Manoharan 	sc->debug.rsidx = (sc->debug.rsidx + 1) % ATH_DBG_MAX_SAMPLES;
1012cf3af748SRajkumar Manoharan 	spin_unlock(&sc->debug.samp_lock);
1013cf3af748SRajkumar Manoharan 
10145baec742SFelix Fietkau #endif
10155baec742SFelix Fietkau 
10161395d3f0SSujith #undef RX_PHY_ERR_INC
1017cf3af748SRajkumar Manoharan #undef RX_SAMP_DBG
10181395d3f0SSujith }
10191395d3f0SSujith 
10201395d3f0SSujith static const struct file_operations fops_recv = {
10211395d3f0SSujith 	.read = read_file_recv,
1022234e3405SStephen Boyd 	.open = simple_open,
10236038f373SArnd Bergmann 	.owner = THIS_MODULE,
10246038f373SArnd Bergmann 	.llseek = default_llseek,
10251395d3f0SSujith };
10261395d3f0SSujith 
10279bff0bc4SFelix Fietkau static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
10289bff0bc4SFelix Fietkau                                 size_t count, loff_t *ppos)
10299bff0bc4SFelix Fietkau {
10309bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
10319bff0bc4SFelix Fietkau 	char buf[32];
10329bff0bc4SFelix Fietkau 	unsigned int len;
10339bff0bc4SFelix Fietkau 
10342b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
10359bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
10369bff0bc4SFelix Fietkau }
10379bff0bc4SFelix Fietkau 
10389bff0bc4SFelix Fietkau static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
10399bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
10409bff0bc4SFelix Fietkau {
10419bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
10429bff0bc4SFelix Fietkau 	unsigned long regidx;
10439bff0bc4SFelix Fietkau 	char buf[32];
10449bff0bc4SFelix Fietkau 	ssize_t len;
10459bff0bc4SFelix Fietkau 
10469bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
10479bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
104804236066SDan Carpenter 		return -EFAULT;
10499bff0bc4SFelix Fietkau 
10509bff0bc4SFelix Fietkau 	buf[len] = '\0';
10519bff0bc4SFelix Fietkau 	if (strict_strtoul(buf, 0, &regidx))
10529bff0bc4SFelix Fietkau 		return -EINVAL;
10539bff0bc4SFelix Fietkau 
10549bff0bc4SFelix Fietkau 	sc->debug.regidx = regidx;
10559bff0bc4SFelix Fietkau 	return count;
10569bff0bc4SFelix Fietkau }
10579bff0bc4SFelix Fietkau 
10589bff0bc4SFelix Fietkau static const struct file_operations fops_regidx = {
10599bff0bc4SFelix Fietkau 	.read = read_file_regidx,
10609bff0bc4SFelix Fietkau 	.write = write_file_regidx,
1061234e3405SStephen Boyd 	.open = simple_open,
10626038f373SArnd Bergmann 	.owner = THIS_MODULE,
10636038f373SArnd Bergmann 	.llseek = default_llseek,
10649bff0bc4SFelix Fietkau };
10659bff0bc4SFelix Fietkau 
10669bff0bc4SFelix Fietkau static ssize_t read_file_regval(struct file *file, char __user *user_buf,
10679bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
10689bff0bc4SFelix Fietkau {
10699bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
10709bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
10719bff0bc4SFelix Fietkau 	char buf[32];
10729bff0bc4SFelix Fietkau 	unsigned int len;
10739bff0bc4SFelix Fietkau 	u32 regval;
10749bff0bc4SFelix Fietkau 
107579d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
10769bff0bc4SFelix Fietkau 	regval = REG_READ_D(ah, sc->debug.regidx);
107779d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
10782b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", regval);
10799bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
10809bff0bc4SFelix Fietkau }
10819bff0bc4SFelix Fietkau 
10829bff0bc4SFelix Fietkau static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
10839bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
10849bff0bc4SFelix Fietkau {
10859bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
10869bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
10879bff0bc4SFelix Fietkau 	unsigned long regval;
10889bff0bc4SFelix Fietkau 	char buf[32];
10899bff0bc4SFelix Fietkau 	ssize_t len;
10909bff0bc4SFelix Fietkau 
10919bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
10929bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
109304236066SDan Carpenter 		return -EFAULT;
10949bff0bc4SFelix Fietkau 
10959bff0bc4SFelix Fietkau 	buf[len] = '\0';
10969bff0bc4SFelix Fietkau 	if (strict_strtoul(buf, 0, &regval))
10979bff0bc4SFelix Fietkau 		return -EINVAL;
10989bff0bc4SFelix Fietkau 
109979d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
11009bff0bc4SFelix Fietkau 	REG_WRITE_D(ah, sc->debug.regidx, regval);
110179d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
11029bff0bc4SFelix Fietkau 	return count;
11039bff0bc4SFelix Fietkau }
11049bff0bc4SFelix Fietkau 
11059bff0bc4SFelix Fietkau static const struct file_operations fops_regval = {
11069bff0bc4SFelix Fietkau 	.read = read_file_regval,
11079bff0bc4SFelix Fietkau 	.write = write_file_regval,
1108234e3405SStephen Boyd 	.open = simple_open,
11096038f373SArnd Bergmann 	.owner = THIS_MODULE,
11106038f373SArnd Bergmann 	.llseek = default_llseek,
11119bff0bc4SFelix Fietkau };
11129bff0bc4SFelix Fietkau 
1113582d0064SVasanthakumar Thiagarajan #define REGDUMP_LINE_SIZE	20
1114582d0064SVasanthakumar Thiagarajan 
1115582d0064SVasanthakumar Thiagarajan static int open_file_regdump(struct inode *inode, struct file *file)
1116582d0064SVasanthakumar Thiagarajan {
1117582d0064SVasanthakumar Thiagarajan 	struct ath_softc *sc = inode->i_private;
1118582d0064SVasanthakumar Thiagarajan 	unsigned int len = 0;
1119582d0064SVasanthakumar Thiagarajan 	u8 *buf;
1120582d0064SVasanthakumar Thiagarajan 	int i;
1121582d0064SVasanthakumar Thiagarajan 	unsigned long num_regs, regdump_len, max_reg_offset;
1122582d0064SVasanthakumar Thiagarajan 
1123582d0064SVasanthakumar Thiagarajan 	max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
1124582d0064SVasanthakumar Thiagarajan 	num_regs = max_reg_offset / 4 + 1;
1125582d0064SVasanthakumar Thiagarajan 	regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
1126582d0064SVasanthakumar Thiagarajan 	buf = vmalloc(regdump_len);
1127582d0064SVasanthakumar Thiagarajan 	if (!buf)
1128582d0064SVasanthakumar Thiagarajan 		return -ENOMEM;
1129582d0064SVasanthakumar Thiagarajan 
1130582d0064SVasanthakumar Thiagarajan 	ath9k_ps_wakeup(sc);
1131582d0064SVasanthakumar Thiagarajan 	for (i = 0; i < num_regs; i++)
1132582d0064SVasanthakumar Thiagarajan 		len += scnprintf(buf + len, regdump_len - len,
1133582d0064SVasanthakumar Thiagarajan 			"0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
1134582d0064SVasanthakumar Thiagarajan 	ath9k_ps_restore(sc);
1135582d0064SVasanthakumar Thiagarajan 
1136582d0064SVasanthakumar Thiagarajan 	file->private_data = buf;
1137582d0064SVasanthakumar Thiagarajan 
1138582d0064SVasanthakumar Thiagarajan 	return 0;
1139582d0064SVasanthakumar Thiagarajan }
1140582d0064SVasanthakumar Thiagarajan 
1141582d0064SVasanthakumar Thiagarajan static const struct file_operations fops_regdump = {
1142582d0064SVasanthakumar Thiagarajan 	.open = open_file_regdump,
1143582d0064SVasanthakumar Thiagarajan 	.read = ath9k_debugfs_read_buf,
1144582d0064SVasanthakumar Thiagarajan 	.release = ath9k_debugfs_release_buf,
1145582d0064SVasanthakumar Thiagarajan 	.owner = THIS_MODULE,
1146582d0064SVasanthakumar Thiagarajan 	.llseek = default_llseek,/* read accesses f_pos */
1147582d0064SVasanthakumar Thiagarajan };
1148582d0064SVasanthakumar Thiagarajan 
1149d069a46bSRajkumar Manoharan static ssize_t read_file_dump_nfcal(struct file *file, char __user *user_buf,
1150d069a46bSRajkumar Manoharan 				    size_t count, loff_t *ppos)
1151d069a46bSRajkumar Manoharan {
1152d069a46bSRajkumar Manoharan 	struct ath_softc *sc = file->private_data;
1153d069a46bSRajkumar Manoharan 	struct ath_hw *ah = sc->sc_ah;
1154d069a46bSRajkumar Manoharan 	struct ath9k_nfcal_hist *h = sc->caldata.nfCalHist;
1155d069a46bSRajkumar Manoharan 	struct ath_common *common = ath9k_hw_common(ah);
1156d069a46bSRajkumar Manoharan 	struct ieee80211_conf *conf = &common->hw->conf;
1157d069a46bSRajkumar Manoharan 	u32 len = 0, size = 1500;
1158d069a46bSRajkumar Manoharan 	u32 i, j;
1159d069a46bSRajkumar Manoharan 	ssize_t retval = 0;
1160d069a46bSRajkumar Manoharan 	char *buf;
1161d069a46bSRajkumar Manoharan 	u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1162d069a46bSRajkumar Manoharan 	u8 nread;
1163d069a46bSRajkumar Manoharan 
1164d069a46bSRajkumar Manoharan 	buf = kzalloc(size, GFP_KERNEL);
1165d069a46bSRajkumar Manoharan 	if (!buf)
1166d069a46bSRajkumar Manoharan 		return -ENOMEM;
1167d069a46bSRajkumar Manoharan 
1168d069a46bSRajkumar Manoharan 	len += snprintf(buf + len, size - len,
1169d069a46bSRajkumar Manoharan 			"Channel Noise Floor : %d\n", ah->noise);
1170d069a46bSRajkumar Manoharan 	len += snprintf(buf + len, size - len,
1171d069a46bSRajkumar Manoharan 			"Chain | privNF | # Readings | NF Readings\n");
1172d069a46bSRajkumar Manoharan 	for (i = 0; i < NUM_NF_READINGS; i++) {
1173d069a46bSRajkumar Manoharan 		if (!(chainmask & (1 << i)) ||
1174d069a46bSRajkumar Manoharan 		    ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1175d069a46bSRajkumar Manoharan 			continue;
1176d069a46bSRajkumar Manoharan 
1177d069a46bSRajkumar Manoharan 		nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
1178d069a46bSRajkumar Manoharan 		len += snprintf(buf + len, size - len, " %d\t %d\t %d\t\t",
1179d069a46bSRajkumar Manoharan 				i, h[i].privNF, nread);
1180d069a46bSRajkumar Manoharan 		for (j = 0; j < nread; j++)
1181d069a46bSRajkumar Manoharan 			len += snprintf(buf + len, size - len,
1182d069a46bSRajkumar Manoharan 					" %d", h[i].nfCalBuffer[j]);
1183d069a46bSRajkumar Manoharan 		len += snprintf(buf + len, size - len, "\n");
1184d069a46bSRajkumar Manoharan 	}
1185d069a46bSRajkumar Manoharan 
1186d069a46bSRajkumar Manoharan 	if (len > size)
1187d069a46bSRajkumar Manoharan 		len = size;
1188d069a46bSRajkumar Manoharan 
1189d069a46bSRajkumar Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1190d069a46bSRajkumar Manoharan 	kfree(buf);
1191d069a46bSRajkumar Manoharan 
1192d069a46bSRajkumar Manoharan 	return retval;
1193d069a46bSRajkumar Manoharan }
1194d069a46bSRajkumar Manoharan 
1195d069a46bSRajkumar Manoharan static const struct file_operations fops_dump_nfcal = {
1196d069a46bSRajkumar Manoharan 	.read = read_file_dump_nfcal,
1197234e3405SStephen Boyd 	.open = simple_open,
1198d069a46bSRajkumar Manoharan 	.owner = THIS_MODULE,
1199d069a46bSRajkumar Manoharan 	.llseek = default_llseek,
1200d069a46bSRajkumar Manoharan };
1201d069a46bSRajkumar Manoharan 
1202580f010fSRajkumar Manoharan static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf,
1203580f010fSRajkumar Manoharan 				     size_t count, loff_t *ppos)
1204580f010fSRajkumar Manoharan {
1205580f010fSRajkumar Manoharan 	struct ath_softc *sc = file->private_data;
1206580f010fSRajkumar Manoharan 	struct ath_hw *ah = sc->sc_ah;
1207580f010fSRajkumar Manoharan 	u32 len = 0, size = 1500;
1208580f010fSRajkumar Manoharan 	ssize_t retval = 0;
1209580f010fSRajkumar Manoharan 	char *buf;
1210580f010fSRajkumar Manoharan 
1211580f010fSRajkumar Manoharan 	buf = kzalloc(size, GFP_KERNEL);
1212580f010fSRajkumar Manoharan 	if (!buf)
1213580f010fSRajkumar Manoharan 		return -ENOMEM;
1214580f010fSRajkumar Manoharan 
1215580f010fSRajkumar Manoharan 	len = ah->eep_ops->dump_eeprom(ah, true, buf, len, size);
1216580f010fSRajkumar Manoharan 
1217580f010fSRajkumar Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1218580f010fSRajkumar Manoharan 	kfree(buf);
1219580f010fSRajkumar Manoharan 
1220580f010fSRajkumar Manoharan 	return retval;
1221580f010fSRajkumar Manoharan }
1222580f010fSRajkumar Manoharan 
1223580f010fSRajkumar Manoharan static const struct file_operations fops_base_eeprom = {
1224580f010fSRajkumar Manoharan 	.read = read_file_base_eeprom,
1225234e3405SStephen Boyd 	.open = simple_open,
1226580f010fSRajkumar Manoharan 	.owner = THIS_MODULE,
1227580f010fSRajkumar Manoharan 	.llseek = default_llseek,
1228580f010fSRajkumar Manoharan };
1229580f010fSRajkumar Manoharan 
12303f4c4bddSRajkumar Manoharan static ssize_t read_file_modal_eeprom(struct file *file, char __user *user_buf,
12313f4c4bddSRajkumar Manoharan 				      size_t count, loff_t *ppos)
12323f4c4bddSRajkumar Manoharan {
12333f4c4bddSRajkumar Manoharan 	struct ath_softc *sc = file->private_data;
12343f4c4bddSRajkumar Manoharan 	struct ath_hw *ah = sc->sc_ah;
12353f4c4bddSRajkumar Manoharan 	u32 len = 0, size = 6000;
12363f4c4bddSRajkumar Manoharan 	char *buf;
12373f4c4bddSRajkumar Manoharan 	size_t retval;
12383f4c4bddSRajkumar Manoharan 
12393f4c4bddSRajkumar Manoharan 	buf = kzalloc(size, GFP_KERNEL);
12403f4c4bddSRajkumar Manoharan 	if (buf == NULL)
12413f4c4bddSRajkumar Manoharan 		return -ENOMEM;
12423f4c4bddSRajkumar Manoharan 
12433f4c4bddSRajkumar Manoharan 	len = ah->eep_ops->dump_eeprom(ah, false, buf, len, size);
12443f4c4bddSRajkumar Manoharan 
12453f4c4bddSRajkumar Manoharan 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
12463f4c4bddSRajkumar Manoharan 	kfree(buf);
12473f4c4bddSRajkumar Manoharan 
12483f4c4bddSRajkumar Manoharan 	return retval;
12493f4c4bddSRajkumar Manoharan }
12503f4c4bddSRajkumar Manoharan 
12513f4c4bddSRajkumar Manoharan static const struct file_operations fops_modal_eeprom = {
12523f4c4bddSRajkumar Manoharan 	.read = read_file_modal_eeprom,
1253234e3405SStephen Boyd 	.open = simple_open,
12543f4c4bddSRajkumar Manoharan 	.owner = THIS_MODULE,
12553f4c4bddSRajkumar Manoharan 	.llseek = default_llseek,
12563f4c4bddSRajkumar Manoharan };
12573f4c4bddSRajkumar Manoharan 
12585baec742SFelix Fietkau #ifdef CONFIG_ATH9K_MAC_DEBUG
12595baec742SFelix Fietkau 
1260cf3af748SRajkumar Manoharan void ath9k_debug_samp_bb_mac(struct ath_softc *sc)
1261cf3af748SRajkumar Manoharan {
1262cf3af748SRajkumar Manoharan #define ATH_SAMP_DBG(c) (sc->debug.bb_mac_samp[sc->debug.sampidx].c)
1263cf3af748SRajkumar Manoharan 	struct ath_hw *ah = sc->sc_ah;
1264cf3af748SRajkumar Manoharan 	struct ath_common *common = ath9k_hw_common(ah);
1265cf3af748SRajkumar Manoharan 	unsigned long flags;
1266cf3af748SRajkumar Manoharan 	int i;
1267cf3af748SRajkumar Manoharan 
1268cf3af748SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
1269cf3af748SRajkumar Manoharan 
12706bc05a95SRajkumar Manoharan 	spin_lock_bh(&sc->debug.samp_lock);
12716bc05a95SRajkumar Manoharan 
1272cf3af748SRajkumar Manoharan 	spin_lock_irqsave(&common->cc_lock, flags);
1273cf3af748SRajkumar Manoharan 	ath_hw_cycle_counters_update(common);
1274cf3af748SRajkumar Manoharan 
1275cf3af748SRajkumar Manoharan 	ATH_SAMP_DBG(cc.cycles) = common->cc_ani.cycles;
1276cf3af748SRajkumar Manoharan 	ATH_SAMP_DBG(cc.rx_busy) = common->cc_ani.rx_busy;
1277cf3af748SRajkumar Manoharan 	ATH_SAMP_DBG(cc.rx_frame) = common->cc_ani.rx_frame;
1278cf3af748SRajkumar Manoharan 	ATH_SAMP_DBG(cc.tx_frame) = common->cc_ani.tx_frame;
12796bc05a95SRajkumar Manoharan 	spin_unlock_irqrestore(&common->cc_lock, flags);
12806bc05a95SRajkumar Manoharan 
1281cf3af748SRajkumar Manoharan 	ATH_SAMP_DBG(noise) = ah->noise;
1282cf3af748SRajkumar Manoharan 
1283cf3af748SRajkumar Manoharan 	REG_WRITE_D(ah, AR_MACMISC,
1284cf3af748SRajkumar Manoharan 		  ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
1285cf3af748SRajkumar Manoharan 		   (AR_MACMISC_MISC_OBS_BUS_1 <<
1286cf3af748SRajkumar Manoharan 		    AR_MACMISC_MISC_OBS_BUS_MSB_S)));
1287cf3af748SRajkumar Manoharan 
1288cf3af748SRajkumar Manoharan 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++)
1289cf3af748SRajkumar Manoharan 		ATH_SAMP_DBG(dma_dbg_reg_vals[i]) = REG_READ_D(ah,
1290cf3af748SRajkumar Manoharan 				AR_DMADBG_0 + (i * sizeof(u32)));
1291cf3af748SRajkumar Manoharan 
1292cf3af748SRajkumar Manoharan 	ATH_SAMP_DBG(pcu_obs) = REG_READ_D(ah, AR_OBS_BUS_1);
1293cf3af748SRajkumar Manoharan 	ATH_SAMP_DBG(pcu_cr) = REG_READ_D(ah, AR_CR);
1294cf3af748SRajkumar Manoharan 
1295cf3af748SRajkumar Manoharan 	memcpy(ATH_SAMP_DBG(nfCalHist), sc->caldata.nfCalHist,
1296cf3af748SRajkumar Manoharan 			sizeof(ATH_SAMP_DBG(nfCalHist)));
1297cf3af748SRajkumar Manoharan 
1298cf3af748SRajkumar Manoharan 	sc->debug.sampidx = (sc->debug.sampidx + 1) % ATH_DBG_MAX_SAMPLES;
1299cf3af748SRajkumar Manoharan 	spin_unlock_bh(&sc->debug.samp_lock);
1300cf3af748SRajkumar Manoharan 	ath9k_ps_restore(sc);
1301cf3af748SRajkumar Manoharan 
1302cf3af748SRajkumar Manoharan #undef ATH_SAMP_DBG
1303cf3af748SRajkumar Manoharan }
1304cf3af748SRajkumar Manoharan 
1305cf3af748SRajkumar Manoharan static int open_file_bb_mac_samps(struct inode *inode, struct file *file)
1306cf3af748SRajkumar Manoharan {
1307cf3af748SRajkumar Manoharan #define ATH_SAMP_DBG(c) bb_mac_samp[sampidx].c
1308cf3af748SRajkumar Manoharan 	struct ath_softc *sc = inode->i_private;
1309cf3af748SRajkumar Manoharan 	struct ath_hw *ah = sc->sc_ah;
1310cf3af748SRajkumar Manoharan 	struct ath_common *common = ath9k_hw_common(ah);
1311cf3af748SRajkumar Manoharan 	struct ieee80211_conf *conf = &common->hw->conf;
1312cf3af748SRajkumar Manoharan 	struct ath_dbg_bb_mac_samp *bb_mac_samp;
1313cf3af748SRajkumar Manoharan 	struct ath9k_nfcal_hist *h;
1314cf3af748SRajkumar Manoharan 	int i, j, qcuOffset = 0, dcuOffset = 0;
1315cf3af748SRajkumar Manoharan 	u32 *qcuBase, *dcuBase, size = 30000, len = 0;
1316cf3af748SRajkumar Manoharan 	u32 sampidx = 0;
1317cf3af748SRajkumar Manoharan 	u8 *buf;
1318cf3af748SRajkumar Manoharan 	u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1319cf3af748SRajkumar Manoharan 	u8 nread;
1320cf3af748SRajkumar Manoharan 
1321781b14a3SSujith Manoharan 	if (test_bit(SC_OP_INVALID, &sc->sc_flags))
1322f7e014daSRajkumar Manoharan 		return -EAGAIN;
1323f7e014daSRajkumar Manoharan 
1324cf3af748SRajkumar Manoharan 	buf = vmalloc(size);
1325cf3af748SRajkumar Manoharan 	if (!buf)
1326cf3af748SRajkumar Manoharan 		return -ENOMEM;
1327cf3af748SRajkumar Manoharan 	bb_mac_samp = vmalloc(sizeof(*bb_mac_samp) * ATH_DBG_MAX_SAMPLES);
1328cf3af748SRajkumar Manoharan 	if (!bb_mac_samp) {
1329cf3af748SRajkumar Manoharan 		vfree(buf);
1330cf3af748SRajkumar Manoharan 		return -ENOMEM;
1331cf3af748SRajkumar Manoharan 	}
1332f7e014daSRajkumar Manoharan 	/* Account the current state too */
1333f7e014daSRajkumar Manoharan 	ath9k_debug_samp_bb_mac(sc);
1334cf3af748SRajkumar Manoharan 
1335cf3af748SRajkumar Manoharan 	spin_lock_bh(&sc->debug.samp_lock);
1336cf3af748SRajkumar Manoharan 	memcpy(bb_mac_samp, sc->debug.bb_mac_samp,
1337cf3af748SRajkumar Manoharan 			sizeof(*bb_mac_samp) * ATH_DBG_MAX_SAMPLES);
13386bc05a95SRajkumar Manoharan 	len += snprintf(buf + len, size - len,
13396bc05a95SRajkumar Manoharan 			"Current Sample Index: %d\n", sc->debug.sampidx);
1340cf3af748SRajkumar Manoharan 	spin_unlock_bh(&sc->debug.samp_lock);
1341cf3af748SRajkumar Manoharan 
1342cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len,
1343cf3af748SRajkumar Manoharan 			"Raw DMA Debug Dump:\n");
1344cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len, "Sample |\t");
1345cf3af748SRajkumar Manoharan 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++)
1346cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, " DMA Reg%d |\t", i);
1347cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len, "\n");
1348cf3af748SRajkumar Manoharan 
1349cf3af748SRajkumar Manoharan 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1350cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, "%d\t", sampidx);
1351cf3af748SRajkumar Manoharan 
1352cf3af748SRajkumar Manoharan 		for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++)
1353cf3af748SRajkumar Manoharan 			len += snprintf(buf + len, size - len, " %08x\t",
1354cf3af748SRajkumar Manoharan 					ATH_SAMP_DBG(dma_dbg_reg_vals[i]));
1355cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, "\n");
1356cf3af748SRajkumar Manoharan 	}
1357cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len, "\n");
1358cf3af748SRajkumar Manoharan 
1359cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len,
1360cf3af748SRajkumar Manoharan 			"Sample Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
1361cf3af748SRajkumar Manoharan 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1362cf3af748SRajkumar Manoharan 		qcuBase = &ATH_SAMP_DBG(dma_dbg_reg_vals[0]);
1363cf3af748SRajkumar Manoharan 		dcuBase = &ATH_SAMP_DBG(dma_dbg_reg_vals[4]);
1364cf3af748SRajkumar Manoharan 
1365cf3af748SRajkumar Manoharan 		for (i = 0; i < ATH9K_NUM_QUEUES; i++,
1366cf3af748SRajkumar Manoharan 				qcuOffset += 4, dcuOffset += 5) {
1367cf3af748SRajkumar Manoharan 			if (i == 8) {
1368cf3af748SRajkumar Manoharan 				qcuOffset = 0;
1369cf3af748SRajkumar Manoharan 				qcuBase++;
1370cf3af748SRajkumar Manoharan 			}
1371cf3af748SRajkumar Manoharan 
1372cf3af748SRajkumar Manoharan 			if (i == 6) {
1373cf3af748SRajkumar Manoharan 				dcuOffset = 0;
1374cf3af748SRajkumar Manoharan 				dcuBase++;
1375cf3af748SRajkumar Manoharan 			}
1376cf3af748SRajkumar Manoharan 			if (!sc->debug.stats.txstats[i].queued)
1377cf3af748SRajkumar Manoharan 				continue;
1378cf3af748SRajkumar Manoharan 
1379cf3af748SRajkumar Manoharan 			len += snprintf(buf + len, size - len,
1380cf3af748SRajkumar Manoharan 				"%4d %7d    %2x      %1x     %2x         %2x\n",
1381cf3af748SRajkumar Manoharan 				sampidx, i,
1382cf3af748SRajkumar Manoharan 				(*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
1383cf3af748SRajkumar Manoharan 				(*qcuBase & (0x8 << qcuOffset)) >>
1384cf3af748SRajkumar Manoharan 				(qcuOffset + 3),
1385cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(dma_dbg_reg_vals[2]) &
1386cf3af748SRajkumar Manoharan 				(0x7 << (i * 3)) >> (i * 3),
1387cf3af748SRajkumar Manoharan 				(*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
1388cf3af748SRajkumar Manoharan 		}
1389cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, "\n");
1390cf3af748SRajkumar Manoharan 	}
1391cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len,
1392cf3af748SRajkumar Manoharan 			"samp qcu_sh qcu_fh qcu_comp dcu_comp dcu_arb dcu_fp "
1393cf3af748SRajkumar Manoharan 			"ch_idle_dur ch_idle_dur_val txfifo_val0 txfifo_val1 "
1394cf3af748SRajkumar Manoharan 			"txfifo_dcu0 txfifo_dcu1 pcu_obs AR_CR\n");
1395cf3af748SRajkumar Manoharan 
1396cf3af748SRajkumar Manoharan 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1397cf3af748SRajkumar Manoharan 		qcuBase = &ATH_SAMP_DBG(dma_dbg_reg_vals[0]);
1398cf3af748SRajkumar Manoharan 		dcuBase = &ATH_SAMP_DBG(dma_dbg_reg_vals[4]);
1399cf3af748SRajkumar Manoharan 
1400cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, "%4d %5x %5x ", sampidx,
1401cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[3]) & 0x003c0000) >> 18,
1402cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[3]) & 0x03c00000) >> 22);
1403cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, "%7x %8x ",
1404cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[3]) & 0x1c000000) >> 26,
1405cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x3));
1406cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, "%7x %7x ",
1407cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[5]) & 0x06000000) >> 25,
1408cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[5]) & 0x38000000) >> 27);
1409cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, "%7d %12d ",
1410cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x000003fc) >> 2,
1411cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x00000400) >> 10);
1412cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, "%12d %12d ",
1413cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x00000800) >> 11,
1414cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x00001000) >> 12);
1415cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, "%12d %12d ",
1416cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x0001e000) >> 13,
1417cf3af748SRajkumar Manoharan 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x001e0000) >> 17);
1418cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len, "0x%07x 0x%07x\n",
1419cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(pcu_obs), ATH_SAMP_DBG(pcu_cr));
1420cf3af748SRajkumar Manoharan 	}
1421cf3af748SRajkumar Manoharan 
1422cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len,
1423cf3af748SRajkumar Manoharan 			"Sample ChNoise Chain privNF #Reading Readings\n");
1424cf3af748SRajkumar Manoharan 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1425cf3af748SRajkumar Manoharan 		h = ATH_SAMP_DBG(nfCalHist);
1426cf3af748SRajkumar Manoharan 		if (!ATH_SAMP_DBG(noise))
1427cf3af748SRajkumar Manoharan 			continue;
1428cf3af748SRajkumar Manoharan 
1429cf3af748SRajkumar Manoharan 		for (i = 0; i < NUM_NF_READINGS; i++) {
1430cf3af748SRajkumar Manoharan 			if (!(chainmask & (1 << i)) ||
1431cf3af748SRajkumar Manoharan 			    ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1432cf3af748SRajkumar Manoharan 				continue;
1433cf3af748SRajkumar Manoharan 
1434cf3af748SRajkumar Manoharan 			nread = AR_PHY_CCA_FILTERWINDOW_LENGTH -
1435cf3af748SRajkumar Manoharan 				h[i].invalidNFcount;
1436cf3af748SRajkumar Manoharan 			len += snprintf(buf + len, size - len,
1437cf3af748SRajkumar Manoharan 					"%4d %5d %4d\t   %d\t %d\t",
1438cf3af748SRajkumar Manoharan 					sampidx, ATH_SAMP_DBG(noise),
1439cf3af748SRajkumar Manoharan 					i, h[i].privNF, nread);
1440cf3af748SRajkumar Manoharan 			for (j = 0; j < nread; j++)
1441cf3af748SRajkumar Manoharan 				len += snprintf(buf + len, size - len,
1442cf3af748SRajkumar Manoharan 					" %d", h[i].nfCalBuffer[j]);
1443cf3af748SRajkumar Manoharan 			len += snprintf(buf + len, size - len, "\n");
1444cf3af748SRajkumar Manoharan 		}
1445cf3af748SRajkumar Manoharan 	}
1446cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len, "\nCycle counters:\n"
1447cf3af748SRajkumar Manoharan 			"Sample Total    Rxbusy   Rxframes Txframes\n");
1448cf3af748SRajkumar Manoharan 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1449cf3af748SRajkumar Manoharan 		if (!ATH_SAMP_DBG(cc.cycles))
1450cf3af748SRajkumar Manoharan 			continue;
1451cf3af748SRajkumar Manoharan 		len += snprintf(buf + len, size - len,
1452cf3af748SRajkumar Manoharan 				"%4d %08x %08x %08x %08x\n",
1453cf3af748SRajkumar Manoharan 				sampidx, ATH_SAMP_DBG(cc.cycles),
1454cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(cc.rx_busy),
1455cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(cc.rx_frame),
1456cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(cc.tx_frame));
1457cf3af748SRajkumar Manoharan 	}
1458cf3af748SRajkumar Manoharan 
1459cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len, "Tx status Dump :\n");
1460cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len,
1461cf3af748SRajkumar Manoharan 			"Sample rssi:- ctl0 ctl1 ctl2 ext0 ext1 ext2 comb "
146212932180SMohammed Shafi Shajakhan 			"isok rts_fail data_fail rate tid qid "
146312932180SMohammed Shafi Shajakhan 					"ba_low  ba_high tx_before(ms)\n");
1464cf3af748SRajkumar Manoharan 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1465cf3af748SRajkumar Manoharan 		for (i = 0; i < ATH_DBG_MAX_SAMPLES; i++) {
1466cf3af748SRajkumar Manoharan 			if (!ATH_SAMP_DBG(ts[i].jiffies))
1467cf3af748SRajkumar Manoharan 				continue;
146812932180SMohammed Shafi Shajakhan 			len += snprintf(buf + len, size - len, "%-14d"
146912932180SMohammed Shafi Shajakhan 				"%-4d %-4d %-4d %-4d %-4d %-4d %-4d %-4d %-8d "
147012932180SMohammed Shafi Shajakhan 				"%-9d %-4d %-3d %-3d %08x %08x %-11d\n",
1471cf3af748SRajkumar Manoharan 				sampidx,
1472cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].rssi_ctl0),
1473cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].rssi_ctl1),
1474cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].rssi_ctl2),
1475cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].rssi_ext0),
1476cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].rssi_ext1),
1477cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].rssi_ext2),
1478cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].rssi),
1479cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].isok),
1480cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].rts_fail_cnt),
1481cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].data_fail_cnt),
1482cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].rateindex),
1483cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].tid),
1484cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(ts[i].qid),
148512932180SMohammed Shafi Shajakhan 				ATH_SAMP_DBG(ts[i].ba_low),
148612932180SMohammed Shafi Shajakhan 				ATH_SAMP_DBG(ts[i].ba_high),
1487cf3af748SRajkumar Manoharan 				jiffies_to_msecs(jiffies -
1488cf3af748SRajkumar Manoharan 					ATH_SAMP_DBG(ts[i].jiffies)));
1489cf3af748SRajkumar Manoharan 		}
1490cf3af748SRajkumar Manoharan 	}
1491cf3af748SRajkumar Manoharan 
1492cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len, "Rx status Dump :\n");
1493cf3af748SRajkumar Manoharan 	len += snprintf(buf + len, size - len, "Sample rssi:- ctl0 ctl1 ctl2 "
1494cf3af748SRajkumar Manoharan 			"ext0 ext1 ext2 comb beacon ant rate rx_before(ms)\n");
1495cf3af748SRajkumar Manoharan 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1496cf3af748SRajkumar Manoharan 		for (i = 0; i < ATH_DBG_MAX_SAMPLES; i++) {
1497cf3af748SRajkumar Manoharan 			if (!ATH_SAMP_DBG(rs[i].jiffies))
1498cf3af748SRajkumar Manoharan 				continue;
149912932180SMohammed Shafi Shajakhan 			len += snprintf(buf + len, size - len, "%-14d"
150012932180SMohammed Shafi Shajakhan 				"%-4d %-4d %-4d %-4d %-4d %-4d %-4d %-9s %-2d %02x %-13d\n",
1501cf3af748SRajkumar Manoharan 				sampidx,
1502cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(rs[i].rssi_ctl0),
1503cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(rs[i].rssi_ctl1),
1504cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(rs[i].rssi_ctl2),
1505cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(rs[i].rssi_ext0),
1506cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(rs[i].rssi_ext1),
1507cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(rs[i].rssi_ext2),
1508cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(rs[i].rssi),
1509cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(rs[i].is_mybeacon) ?
1510cf3af748SRajkumar Manoharan 				"True" : "False",
1511cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(rs[i].antenna),
1512cf3af748SRajkumar Manoharan 				ATH_SAMP_DBG(rs[i].rate),
1513cf3af748SRajkumar Manoharan 				jiffies_to_msecs(jiffies -
1514cf3af748SRajkumar Manoharan 					ATH_SAMP_DBG(rs[i].jiffies)));
1515cf3af748SRajkumar Manoharan 		}
1516cf3af748SRajkumar Manoharan 	}
1517cf3af748SRajkumar Manoharan 
1518cf3af748SRajkumar Manoharan 	vfree(bb_mac_samp);
1519cf3af748SRajkumar Manoharan 	file->private_data = buf;
1520cf3af748SRajkumar Manoharan 
1521cf3af748SRajkumar Manoharan 	return 0;
1522cf3af748SRajkumar Manoharan #undef ATH_SAMP_DBG
1523cf3af748SRajkumar Manoharan }
1524cf3af748SRajkumar Manoharan 
1525cf3af748SRajkumar Manoharan static const struct file_operations fops_samps = {
1526cf3af748SRajkumar Manoharan 	.open = open_file_bb_mac_samps,
1527cf3af748SRajkumar Manoharan 	.read = ath9k_debugfs_read_buf,
1528cf3af748SRajkumar Manoharan 	.release = ath9k_debugfs_release_buf,
1529cf3af748SRajkumar Manoharan 	.owner = THIS_MODULE,
1530cf3af748SRajkumar Manoharan 	.llseek = default_llseek,
1531cf3af748SRajkumar Manoharan };
1532cf3af748SRajkumar Manoharan 
15335baec742SFelix Fietkau #endif
1534cf3af748SRajkumar Manoharan 
15354d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah)
1536203c4805SLuis R. Rodriguez {
1537bc974f4aSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(ah);
1538bc974f4aSLuis R. Rodriguez 	struct ath_softc *sc = (struct ath_softc *) common->priv;
15394d6b228dSLuis R. Rodriguez 
1540eb272441SBen Greear 	sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1541eb272441SBen Greear 						   sc->hw->wiphy->debugfsdir);
1542203c4805SLuis R. Rodriguez 	if (!sc->debug.debugfs_phy)
1543c8a72c00SFelix Fietkau 		return -ENOMEM;
1544203c4805SLuis R. Rodriguez 
1545a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
1546c70cab1aSFelix Fietkau 	debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1547c70cab1aSFelix Fietkau 			    sc, &fops_debug);
1548a830df07SFelix Fietkau #endif
154929942bc1SZefir Kurtisi 
155029942bc1SZefir Kurtisi 	ath9k_dfs_init_debug(sc);
155129942bc1SZefir Kurtisi 
1552c70cab1aSFelix Fietkau 	debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
1553c70cab1aSFelix Fietkau 			    &fops_dma);
1554c70cab1aSFelix Fietkau 	debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
1555c70cab1aSFelix Fietkau 			    &fops_interrupt);
1556c70cab1aSFelix Fietkau 	debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc,
1557c70cab1aSFelix Fietkau 			    &fops_xmit);
15587702e788SFelix Fietkau 	debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
15597702e788SFelix Fietkau 			   &sc->tx.txq_max_pending[WME_AC_BK]);
15607702e788SFelix Fietkau 	debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
15617702e788SFelix Fietkau 			   &sc->tx.txq_max_pending[WME_AC_BE]);
15627702e788SFelix Fietkau 	debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
15637702e788SFelix Fietkau 			   &sc->tx.txq_max_pending[WME_AC_VI]);
15647702e788SFelix Fietkau 	debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
15657702e788SFelix Fietkau 			   &sc->tx.txq_max_pending[WME_AC_VO]);
1566c70cab1aSFelix Fietkau 	debugfs_create_file("stations", S_IRUSR, sc->debug.debugfs_phy, sc,
1567c70cab1aSFelix Fietkau 			    &fops_stations);
1568c70cab1aSFelix Fietkau 	debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy, sc,
1569c70cab1aSFelix Fietkau 			    &fops_misc);
1570f8b815dcSSujith Manoharan 	debugfs_create_file("reset", S_IRUSR, sc->debug.debugfs_phy, sc,
1571f8b815dcSSujith Manoharan 			    &fops_reset);
1572c70cab1aSFelix Fietkau 	debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy, sc,
1573c70cab1aSFelix Fietkau 			    &fops_recv);
1574c70cab1aSFelix Fietkau 	debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
1575c70cab1aSFelix Fietkau 			    sc->debug.debugfs_phy, sc, &fops_rx_chainmask);
1576c70cab1aSFelix Fietkau 	debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
1577c70cab1aSFelix Fietkau 			    sc->debug.debugfs_phy, sc, &fops_tx_chainmask);
157805c0be2fSMohammed Shafi Shajakhan 	debugfs_create_file("disable_ani", S_IRUSR | S_IWUSR,
157905c0be2fSMohammed Shafi Shajakhan 			    sc->debug.debugfs_phy, sc, &fops_disable_ani);
1580*74673db9SFelix Fietkau 	debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1581*74673db9SFelix Fietkau 			    &sc->sc_ah->config.enable_paprd);
1582c70cab1aSFelix Fietkau 	debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1583c70cab1aSFelix Fietkau 			    sc, &fops_regidx);
1584c70cab1aSFelix Fietkau 	debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1585c70cab1aSFelix Fietkau 			    sc, &fops_regval);
1586c70cab1aSFelix Fietkau 	debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1587c70cab1aSFelix Fietkau 			    sc->debug.debugfs_phy,
1588c70cab1aSFelix Fietkau 			    &ah->config.cwm_ignore_extcca);
1589c70cab1aSFelix Fietkau 	debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
1590c70cab1aSFelix Fietkau 			    &fops_regdump);
1591d069a46bSRajkumar Manoharan 	debugfs_create_file("dump_nfcal", S_IRUSR, sc->debug.debugfs_phy, sc,
1592d069a46bSRajkumar Manoharan 			    &fops_dump_nfcal);
1593580f010fSRajkumar Manoharan 	debugfs_create_file("base_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
1594580f010fSRajkumar Manoharan 			    &fops_base_eeprom);
15953f4c4bddSRajkumar Manoharan 	debugfs_create_file("modal_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
15963f4c4bddSRajkumar Manoharan 			    &fops_modal_eeprom);
15975baec742SFelix Fietkau #ifdef CONFIG_ATH9K_MAC_DEBUG
1598cf3af748SRajkumar Manoharan 	debugfs_create_file("samples", S_IRUSR, sc->debug.debugfs_phy, sc,
1599cf3af748SRajkumar Manoharan 			    &fops_samps);
16005baec742SFelix Fietkau #endif
1601582d0064SVasanthakumar Thiagarajan 
1602691680b8SFelix Fietkau 	debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
1603691680b8SFelix Fietkau 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
1604691680b8SFelix Fietkau 
1605691680b8SFelix Fietkau 	debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
1606691680b8SFelix Fietkau 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
1607691680b8SFelix Fietkau 
1608203c4805SLuis R. Rodriguez 	return 0;
1609203c4805SLuis R. Rodriguez }
1610