xref: /linux/drivers/net/wireless/ath/ath9k/debug.c (revision db7889cda3571bfd0d3a3fc79ca0cd16bb321ff2)
1203c4805SLuis R. Rodriguez /*
2203c4805SLuis R. Rodriguez  * Copyright (c) 2008-2009 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>
19203c4805SLuis R. Rodriguez #include <asm/unaligned.h>
20203c4805SLuis R. Rodriguez 
21203c4805SLuis R. Rodriguez #include "ath9k.h"
22203c4805SLuis R. Rodriguez 
23475a6e4dSLuis R. Rodriguez #define REG_WRITE_D(_ah, _reg, _val) \
24475a6e4dSLuis R. Rodriguez 	ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg))
25475a6e4dSLuis R. Rodriguez #define REG_READ_D(_ah, _reg) \
26475a6e4dSLuis R. Rodriguez 	ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
27475a6e4dSLuis R. Rodriguez 
28203c4805SLuis R. Rodriguez static int ath9k_debugfs_open(struct inode *inode, struct file *file)
29203c4805SLuis R. Rodriguez {
30203c4805SLuis R. Rodriguez 	file->private_data = inode->i_private;
31203c4805SLuis R. Rodriguez 	return 0;
32203c4805SLuis R. Rodriguez }
33203c4805SLuis R. Rodriguez 
34582d0064SVasanthakumar Thiagarajan static ssize_t ath9k_debugfs_read_buf(struct file *file, char __user *user_buf,
35582d0064SVasanthakumar Thiagarajan 				      size_t count, loff_t *ppos)
36582d0064SVasanthakumar Thiagarajan {
37582d0064SVasanthakumar Thiagarajan 	u8 *buf = file->private_data;
38582d0064SVasanthakumar Thiagarajan 	return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
39582d0064SVasanthakumar Thiagarajan }
40582d0064SVasanthakumar Thiagarajan 
41582d0064SVasanthakumar Thiagarajan static int ath9k_debugfs_release_buf(struct inode *inode, struct file *file)
42582d0064SVasanthakumar Thiagarajan {
43582d0064SVasanthakumar Thiagarajan 	vfree(file->private_data);
44582d0064SVasanthakumar Thiagarajan 	return 0;
45582d0064SVasanthakumar Thiagarajan }
46582d0064SVasanthakumar Thiagarajan 
47a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
48a830df07SFelix Fietkau 
492493928eSJeff Hansen static ssize_t read_file_debug(struct file *file, char __user *user_buf,
502493928eSJeff Hansen 			     size_t count, loff_t *ppos)
512493928eSJeff Hansen {
522493928eSJeff Hansen 	struct ath_softc *sc = file->private_data;
53c46917bbSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
542493928eSJeff Hansen 	char buf[32];
55581f725cSVasanthakumar Thiagarajan 	unsigned int len;
56581f725cSVasanthakumar Thiagarajan 
572b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", common->debug_mask);
582493928eSJeff Hansen 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
592493928eSJeff Hansen }
602493928eSJeff Hansen 
612493928eSJeff Hansen static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
622493928eSJeff Hansen 			     size_t count, loff_t *ppos)
632493928eSJeff Hansen {
642493928eSJeff Hansen 	struct ath_softc *sc = file->private_data;
65c46917bbSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
662493928eSJeff Hansen 	unsigned long mask;
672493928eSJeff Hansen 	char buf[32];
68581f725cSVasanthakumar Thiagarajan 	ssize_t len;
69581f725cSVasanthakumar Thiagarajan 
70581f725cSVasanthakumar Thiagarajan 	len = min(count, sizeof(buf) - 1);
71581f725cSVasanthakumar Thiagarajan 	if (copy_from_user(buf, user_buf, len))
7204236066SDan Carpenter 		return -EFAULT;
73581f725cSVasanthakumar Thiagarajan 
74581f725cSVasanthakumar Thiagarajan 	buf[len] = '\0';
75581f725cSVasanthakumar Thiagarajan 	if (strict_strtoul(buf, 0, &mask))
76581f725cSVasanthakumar Thiagarajan 		return -EINVAL;
77581f725cSVasanthakumar Thiagarajan 
78c46917bbSLuis R. Rodriguez 	common->debug_mask = mask;
792493928eSJeff Hansen 	return count;
802493928eSJeff Hansen }
812493928eSJeff Hansen 
822493928eSJeff Hansen static const struct file_operations fops_debug = {
832493928eSJeff Hansen 	.read = read_file_debug,
842493928eSJeff Hansen 	.write = write_file_debug,
852493928eSJeff Hansen 	.open = ath9k_debugfs_open,
866038f373SArnd Bergmann 	.owner = THIS_MODULE,
876038f373SArnd Bergmann 	.llseek = default_llseek,
882493928eSJeff Hansen };
892493928eSJeff Hansen 
90a830df07SFelix Fietkau #endif
91a830df07SFelix Fietkau 
92991a0987SPavel Roskin #define DMA_BUF_LEN 1024
93991a0987SPavel Roskin 
9415340694SFelix Fietkau static ssize_t read_file_tx_chainmask(struct file *file, char __user *user_buf,
9515340694SFelix Fietkau 			     size_t count, loff_t *ppos)
9615340694SFelix Fietkau {
9715340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
9815340694SFelix Fietkau 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
9915340694SFelix Fietkau 	char buf[32];
10015340694SFelix Fietkau 	unsigned int len;
10115340694SFelix Fietkau 
1022b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", common->tx_chainmask);
10315340694SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
10415340694SFelix Fietkau }
10515340694SFelix Fietkau 
10615340694SFelix Fietkau static ssize_t write_file_tx_chainmask(struct file *file, const char __user *user_buf,
10715340694SFelix Fietkau 			     size_t count, loff_t *ppos)
10815340694SFelix Fietkau {
10915340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
11015340694SFelix Fietkau 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
11115340694SFelix Fietkau 	unsigned long mask;
11215340694SFelix Fietkau 	char buf[32];
11315340694SFelix Fietkau 	ssize_t len;
11415340694SFelix Fietkau 
11515340694SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
11615340694SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
11704236066SDan Carpenter 		return -EFAULT;
11815340694SFelix Fietkau 
11915340694SFelix Fietkau 	buf[len] = '\0';
12015340694SFelix Fietkau 	if (strict_strtoul(buf, 0, &mask))
12115340694SFelix Fietkau 		return -EINVAL;
12215340694SFelix Fietkau 
12315340694SFelix Fietkau 	common->tx_chainmask = mask;
12415340694SFelix Fietkau 	sc->sc_ah->caps.tx_chainmask = mask;
12515340694SFelix Fietkau 	return count;
12615340694SFelix Fietkau }
12715340694SFelix Fietkau 
12815340694SFelix Fietkau static const struct file_operations fops_tx_chainmask = {
12915340694SFelix Fietkau 	.read = read_file_tx_chainmask,
13015340694SFelix Fietkau 	.write = write_file_tx_chainmask,
13115340694SFelix Fietkau 	.open = ath9k_debugfs_open,
1326038f373SArnd Bergmann 	.owner = THIS_MODULE,
1336038f373SArnd Bergmann 	.llseek = default_llseek,
13415340694SFelix Fietkau };
13515340694SFelix Fietkau 
13615340694SFelix Fietkau 
13715340694SFelix Fietkau static ssize_t read_file_rx_chainmask(struct file *file, char __user *user_buf,
13815340694SFelix Fietkau 			     size_t count, loff_t *ppos)
13915340694SFelix Fietkau {
14015340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
14115340694SFelix Fietkau 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
14215340694SFelix Fietkau 	char buf[32];
14315340694SFelix Fietkau 	unsigned int len;
14415340694SFelix Fietkau 
1452b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", common->rx_chainmask);
14615340694SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
14715340694SFelix Fietkau }
14815340694SFelix Fietkau 
14915340694SFelix Fietkau static ssize_t write_file_rx_chainmask(struct file *file, const char __user *user_buf,
15015340694SFelix Fietkau 			     size_t count, loff_t *ppos)
15115340694SFelix Fietkau {
15215340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
15315340694SFelix Fietkau 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
15415340694SFelix Fietkau 	unsigned long mask;
15515340694SFelix Fietkau 	char buf[32];
15615340694SFelix Fietkau 	ssize_t len;
15715340694SFelix Fietkau 
15815340694SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
15915340694SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
16004236066SDan Carpenter 		return -EFAULT;
16115340694SFelix Fietkau 
16215340694SFelix Fietkau 	buf[len] = '\0';
16315340694SFelix Fietkau 	if (strict_strtoul(buf, 0, &mask))
16415340694SFelix Fietkau 		return -EINVAL;
16515340694SFelix Fietkau 
16615340694SFelix Fietkau 	common->rx_chainmask = mask;
16715340694SFelix Fietkau 	sc->sc_ah->caps.rx_chainmask = mask;
16815340694SFelix Fietkau 	return count;
16915340694SFelix Fietkau }
17015340694SFelix Fietkau 
17115340694SFelix Fietkau static const struct file_operations fops_rx_chainmask = {
17215340694SFelix Fietkau 	.read = read_file_rx_chainmask,
17315340694SFelix Fietkau 	.write = write_file_rx_chainmask,
17415340694SFelix Fietkau 	.open = ath9k_debugfs_open,
1756038f373SArnd Bergmann 	.owner = THIS_MODULE,
1766038f373SArnd Bergmann 	.llseek = default_llseek,
17715340694SFelix Fietkau };
17815340694SFelix Fietkau 
17915340694SFelix Fietkau 
180203c4805SLuis R. Rodriguez static ssize_t read_file_dma(struct file *file, char __user *user_buf,
181203c4805SLuis R. Rodriguez 			     size_t count, loff_t *ppos)
182203c4805SLuis R. Rodriguez {
183203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
184203c4805SLuis R. Rodriguez 	struct ath_hw *ah = sc->sc_ah;
185991a0987SPavel Roskin 	char *buf;
186991a0987SPavel Roskin 	int retval;
187203c4805SLuis R. Rodriguez 	unsigned int len = 0;
188203c4805SLuis R. Rodriguez 	u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
189203c4805SLuis R. Rodriguez 	int i, qcuOffset = 0, dcuOffset = 0;
190203c4805SLuis R. Rodriguez 	u32 *qcuBase = &val[0], *dcuBase = &val[4];
191203c4805SLuis R. Rodriguez 
192991a0987SPavel Roskin 	buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
193991a0987SPavel Roskin 	if (!buf)
19404236066SDan Carpenter 		return -ENOMEM;
195991a0987SPavel Roskin 
1967cf4a2e7SSujith 	ath9k_ps_wakeup(sc);
1977cf4a2e7SSujith 
198475a6e4dSLuis R. Rodriguez 	REG_WRITE_D(ah, AR_MACMISC,
199203c4805SLuis R. Rodriguez 		  ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
200203c4805SLuis R. Rodriguez 		   (AR_MACMISC_MISC_OBS_BUS_1 <<
201203c4805SLuis R. Rodriguez 		    AR_MACMISC_MISC_OBS_BUS_MSB_S)));
202203c4805SLuis R. Rodriguez 
203991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
204203c4805SLuis R. Rodriguez 			"Raw DMA Debug values:\n");
205203c4805SLuis R. Rodriguez 
206203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
207203c4805SLuis R. Rodriguez 		if (i % 4 == 0)
208991a0987SPavel Roskin 			len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
209203c4805SLuis R. Rodriguez 
210475a6e4dSLuis R. Rodriguez 		val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
211991a0987SPavel Roskin 		len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
212203c4805SLuis R. Rodriguez 				i, val[i]);
213203c4805SLuis R. Rodriguez 	}
214203c4805SLuis R. Rodriguez 
215991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
216991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
217203c4805SLuis R. Rodriguez 			"Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
218203c4805SLuis R. Rodriguez 
219203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
220203c4805SLuis R. Rodriguez 		if (i == 8) {
221203c4805SLuis R. Rodriguez 			qcuOffset = 0;
222203c4805SLuis R. Rodriguez 			qcuBase++;
223203c4805SLuis R. Rodriguez 		}
224203c4805SLuis R. Rodriguez 
225203c4805SLuis R. Rodriguez 		if (i == 6) {
226203c4805SLuis R. Rodriguez 			dcuOffset = 0;
227203c4805SLuis R. Rodriguez 			dcuBase++;
228203c4805SLuis R. Rodriguez 		}
229203c4805SLuis R. Rodriguez 
230991a0987SPavel Roskin 		len += snprintf(buf + len, DMA_BUF_LEN - len,
231203c4805SLuis R. Rodriguez 			"%2d          %2x      %1x     %2x           %2x\n",
232203c4805SLuis R. Rodriguez 			i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
233203c4805SLuis R. Rodriguez 			(*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
234203c4805SLuis R. Rodriguez 			val[2] & (0x7 << (i * 3)) >> (i * 3),
235203c4805SLuis R. Rodriguez 			(*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
236203c4805SLuis R. Rodriguez 	}
237203c4805SLuis R. Rodriguez 
238991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
239203c4805SLuis R. Rodriguez 
240991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
241203c4805SLuis R. Rodriguez 		"qcu_stitch state:   %2x    qcu_fetch state:        %2x\n",
242203c4805SLuis R. Rodriguez 		(val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
243991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
244203c4805SLuis R. Rodriguez 		"qcu_complete state: %2x    dcu_complete state:     %2x\n",
245203c4805SLuis R. Rodriguez 		(val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
246991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
247203c4805SLuis R. Rodriguez 		"dcu_arb state:      %2x    dcu_fp state:           %2x\n",
248203c4805SLuis R. Rodriguez 		(val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
249991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
250203c4805SLuis R. Rodriguez 		"chan_idle_dur:     %3d    chan_idle_dur_valid:     %1d\n",
251203c4805SLuis R. Rodriguez 		(val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
252991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
253203c4805SLuis R. Rodriguez 		"txfifo_valid_0:      %1d    txfifo_valid_1:          %1d\n",
254203c4805SLuis R. Rodriguez 		(val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
255991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
256203c4805SLuis R. Rodriguez 		"txfifo_dcu_num_0:   %2d    txfifo_dcu_num_1:       %2d\n",
257203c4805SLuis R. Rodriguez 		(val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
258203c4805SLuis R. Rodriguez 
259991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
260475a6e4dSLuis R. Rodriguez 			REG_READ_D(ah, AR_OBS_BUS_1));
261991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
262475a6e4dSLuis R. Rodriguez 			"AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
263203c4805SLuis R. Rodriguez 
2647cf4a2e7SSujith 	ath9k_ps_restore(sc);
2657cf4a2e7SSujith 
2662b87f3aaSDan Carpenter 	if (len > DMA_BUF_LEN)
2672b87f3aaSDan Carpenter 		len = DMA_BUF_LEN;
2682b87f3aaSDan Carpenter 
269991a0987SPavel Roskin 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
270991a0987SPavel Roskin 	kfree(buf);
271991a0987SPavel Roskin 	return retval;
272203c4805SLuis R. Rodriguez }
273203c4805SLuis R. Rodriguez 
274203c4805SLuis R. Rodriguez static const struct file_operations fops_dma = {
275203c4805SLuis R. Rodriguez 	.read = read_file_dma,
276203c4805SLuis R. Rodriguez 	.open = ath9k_debugfs_open,
2776038f373SArnd Bergmann 	.owner = THIS_MODULE,
2786038f373SArnd Bergmann 	.llseek = default_llseek,
279203c4805SLuis R. Rodriguez };
280203c4805SLuis R. Rodriguez 
281203c4805SLuis R. Rodriguez 
282203c4805SLuis R. Rodriguez void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
283203c4805SLuis R. Rodriguez {
284203c4805SLuis R. Rodriguez 	if (status)
285203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.total++;
286a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
287a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXLP)
288a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxlp++;
289a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXHP)
290a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxhp++;
29108578b8fSLuis R. Rodriguez 		if (status & ATH9K_INT_BB_WATCHDOG)
29208578b8fSLuis R. Rodriguez 			sc->debug.stats.istats.bb_watchdog++;
293a9616f41SLuis R. Rodriguez 	} else {
294203c4805SLuis R. Rodriguez 		if (status & ATH9K_INT_RX)
295203c4805SLuis R. Rodriguez 			sc->debug.stats.istats.rxok++;
296a9616f41SLuis R. Rodriguez 	}
297203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXEOL)
298203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxeol++;
299203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXORN)
300203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxorn++;
301203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TX)
302203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txok++;
303203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TXURN)
304203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txurn++;
305203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_MIB)
306203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.mib++;
307203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXPHY)
308203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxphyerr++;
309203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXKCM)
310203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rx_keycache_miss++;
311203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_SWBA)
312203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.swba++;
313203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BMISS)
314203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bmiss++;
315203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BNR)
316203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bnr++;
317203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CST)
318203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cst++;
319203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_GTT)
320203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.gtt++;
321203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TIM)
322203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.tim++;
323203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CABEND)
324203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cabend++;
325203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIMSYNC)
326203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtimsync++;
327203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIM)
328203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtim++;
329203c4805SLuis R. Rodriguez }
330203c4805SLuis R. Rodriguez 
331203c4805SLuis R. Rodriguez static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
332203c4805SLuis R. Rodriguez 				   size_t count, loff_t *ppos)
333203c4805SLuis R. Rodriguez {
334203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
335203c4805SLuis R. Rodriguez 	char buf[512];
336203c4805SLuis R. Rodriguez 	unsigned int len = 0;
337203c4805SLuis R. Rodriguez 
338a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
339a9616f41SLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
340a9616f41SLuis R. Rodriguez 			"%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp);
341a9616f41SLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
342a9616f41SLuis R. Rodriguez 			"%8s: %10u\n", "RXHP", sc->debug.stats.istats.rxhp);
34308578b8fSLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
34408578b8fSLuis R. Rodriguez 			"%8s: %10u\n", "WATCHDOG",
34508578b8fSLuis R. Rodriguez 			sc->debug.stats.istats.bb_watchdog);
346a9616f41SLuis R. Rodriguez 	} else {
347203c4805SLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
348203c4805SLuis R. Rodriguez 			"%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
349a9616f41SLuis R. Rodriguez 	}
350203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
351203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol);
352203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
353203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn);
354203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
355203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TX", sc->debug.stats.istats.txok);
356203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
357203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn);
358203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
359203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "MIB", sc->debug.stats.istats.mib);
360203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
361203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr);
362203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
363203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss);
364203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
365203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba);
366203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
367203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss);
368203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
369203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr);
370203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
371203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "CST", sc->debug.stats.istats.cst);
372203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
373203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt);
374203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
375203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TIM", sc->debug.stats.istats.tim);
376203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
377203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend);
378203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
379203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync);
380203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
381203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim);
382203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
383203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total);
384203c4805SLuis R. Rodriguez 
3852b87f3aaSDan Carpenter 	if (len > sizeof(buf))
3862b87f3aaSDan Carpenter 		len = sizeof(buf);
3872b87f3aaSDan Carpenter 
388203c4805SLuis R. Rodriguez 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
389203c4805SLuis R. Rodriguez }
390203c4805SLuis R. Rodriguez 
391203c4805SLuis R. Rodriguez static const struct file_operations fops_interrupt = {
392203c4805SLuis R. Rodriguez 	.read = read_file_interrupt,
393203c4805SLuis R. Rodriguez 	.open = ath9k_debugfs_open,
3946038f373SArnd Bergmann 	.owner = THIS_MODULE,
3956038f373SArnd Bergmann 	.llseek = default_llseek,
396203c4805SLuis R. Rodriguez };
397203c4805SLuis R. Rodriguez 
3984e6975f7SBen Greear static const char *channel_type_str(enum nl80211_channel_type t)
3994e6975f7SBen Greear {
4004e6975f7SBen Greear 	switch (t) {
4014e6975f7SBen Greear 	case NL80211_CHAN_NO_HT:
4024e6975f7SBen Greear 		return "no ht";
4034e6975f7SBen Greear 	case NL80211_CHAN_HT20:
4044e6975f7SBen Greear 		return "ht20";
4054e6975f7SBen Greear 	case NL80211_CHAN_HT40MINUS:
4064e6975f7SBen Greear 		return "ht40-";
4074e6975f7SBen Greear 	case NL80211_CHAN_HT40PLUS:
4084e6975f7SBen Greear 		return "ht40+";
4094e6975f7SBen Greear 	default:
4104e6975f7SBen Greear 		return "???";
4114e6975f7SBen Greear 	}
4124e6975f7SBen Greear }
4134e6975f7SBen Greear 
414203c4805SLuis R. Rodriguez static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
415203c4805SLuis R. Rodriguez 			       size_t count, loff_t *ppos)
416203c4805SLuis R. Rodriguez {
417203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
41834302397SFelix Fietkau 	struct ieee80211_channel *chan = sc->hw->conf.channel;
4194e6975f7SBen Greear 	struct ieee80211_conf *conf = &(sc->hw->conf);
420203c4805SLuis R. Rodriguez 	char buf[512];
421203c4805SLuis R. Rodriguez 	unsigned int len = 0;
422203c4805SLuis R. Rodriguez 	u8 addr[ETH_ALEN];
42339057512SBen Greear 	u32 tmp;
424203c4805SLuis R. Rodriguez 
425203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
4264e6975f7SBen Greear 			"%s (chan=%d  center-freq: %d MHz  channel-type: %d (%s))\n",
42734302397SFelix Fietkau 			wiphy_name(sc->hw->wiphy),
4288e0167a4SMohammed Shafi Shajakhan 			ieee80211_frequency_to_channel(chan->center_freq),
4294e6975f7SBen Greear 			chan->center_freq,
4304e6975f7SBen Greear 			conf->channel_type,
4314e6975f7SBen Greear 			channel_type_str(conf->channel_type));
432203c4805SLuis R. Rodriguez 
433475a6e4dSLuis R. Rodriguez 	put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr);
434475a6e4dSLuis R. Rodriguez 	put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
435203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
436203c4805SLuis R. Rodriguez 			"addr: %pM\n", addr);
437475a6e4dSLuis R. Rodriguez 	put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr);
438475a6e4dSLuis R. Rodriguez 	put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
439203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
440203c4805SLuis R. Rodriguez 			"addrmask: %pM\n", addr);
44139057512SBen Greear 	tmp = ath9k_hw_getrxfilter(sc->sc_ah);
44239057512SBen Greear 	len += snprintf(buf + len, sizeof(buf) - len,
44339057512SBen Greear 			"rfilt: 0x%x", tmp);
44439057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_UCAST)
44539057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " UCAST");
44639057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_MCAST)
44739057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " MCAST");
44839057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_BCAST)
44939057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " BCAST");
45039057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_CONTROL)
45139057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " CONTROL");
45239057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_BEACON)
45339057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " BEACON");
45439057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_PROM)
45539057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " PROM");
45639057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_PROBEREQ)
45739057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
45839057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_PHYERR)
45939057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " PHYERR");
46039057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_MYBEACON)
46139057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " MYBEACON");
46239057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_COMP_BAR)
46339057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
46439057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_PSPOLL)
46539057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " PSPOLL");
46639057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_PHYRADAR)
46739057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
46839057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
46939057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL\n");
47039057512SBen Greear 	else
47139057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, "\n");
472203c4805SLuis R. Rodriguez 
4732b87f3aaSDan Carpenter 	if (len > sizeof(buf))
4742b87f3aaSDan Carpenter 		len = sizeof(buf);
4752b87f3aaSDan Carpenter 
476203c4805SLuis R. Rodriguez 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
477203c4805SLuis R. Rodriguez }
478203c4805SLuis R. Rodriguez 
479203c4805SLuis R. Rodriguez static const struct file_operations fops_wiphy = {
480203c4805SLuis R. Rodriguez 	.read = read_file_wiphy,
481203c4805SLuis R. Rodriguez 	.open = ath9k_debugfs_open,
4826038f373SArnd Bergmann 	.owner = THIS_MODULE,
4836038f373SArnd Bergmann 	.llseek = default_llseek,
484203c4805SLuis R. Rodriguez };
485203c4805SLuis R. Rodriguez 
4865bec3e5aSFelix Fietkau #define PR_QNUM(_n) sc->tx.txq_map[_n]->axq_qnum
487fec247c0SSujith #define PR(str, elem)							\
488fec247c0SSujith 	do {								\
489fec247c0SSujith 		len += snprintf(buf + len, size - len,			\
490fec247c0SSujith 				"%s%13u%11u%10u%10u\n", str,		\
4915bec3e5aSFelix Fietkau 		sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].elem, \
4925bec3e5aSFelix Fietkau 		sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].elem, \
4935bec3e5aSFelix Fietkau 		sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].elem, \
4945bec3e5aSFelix Fietkau 		sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].elem); \
4957f010c93SBen Greear 		if (len >= size)			  \
4967f010c93SBen Greear 			goto done;			  \
497fec247c0SSujith } while(0)
498fec247c0SSujith 
4991f427dd9SBen Greear #define PRX(str, elem)							\
5001f427dd9SBen Greear do {									\
5011f427dd9SBen Greear 	len += snprintf(buf + len, size - len,				\
5021f427dd9SBen Greear 			"%s%13u%11u%10u%10u\n", str,			\
5035bec3e5aSFelix Fietkau 			(unsigned int)(sc->tx.txq_map[WME_AC_BE]->elem),	\
5045bec3e5aSFelix Fietkau 			(unsigned int)(sc->tx.txq_map[WME_AC_BK]->elem),	\
5055bec3e5aSFelix Fietkau 			(unsigned int)(sc->tx.txq_map[WME_AC_VI]->elem),	\
5065bec3e5aSFelix Fietkau 			(unsigned int)(sc->tx.txq_map[WME_AC_VO]->elem));	\
5077f010c93SBen Greear 	if (len >= size)						\
5087f010c93SBen Greear 		goto done;						\
5091f427dd9SBen Greear } while(0)
5101f427dd9SBen Greear 
5112dac4fb9SBen Greear #define PRQLE(str, elem)						\
5122dac4fb9SBen Greear do {									\
5132dac4fb9SBen Greear 	len += snprintf(buf + len, size - len,				\
5142dac4fb9SBen Greear 			"%s%13i%11i%10i%10i\n", str,			\
5155bec3e5aSFelix Fietkau 			list_empty(&sc->tx.txq_map[WME_AC_BE]->elem),	\
5165bec3e5aSFelix Fietkau 			list_empty(&sc->tx.txq_map[WME_AC_BK]->elem),	\
5175bec3e5aSFelix Fietkau 			list_empty(&sc->tx.txq_map[WME_AC_VI]->elem),	\
5185bec3e5aSFelix Fietkau 			list_empty(&sc->tx.txq_map[WME_AC_VO]->elem));	\
5197f010c93SBen Greear 	if (len >= size)						\
5207f010c93SBen Greear 		goto done;						\
5212dac4fb9SBen Greear } while (0)
5222dac4fb9SBen Greear 
523fec247c0SSujith static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
524fec247c0SSujith 			      size_t count, loff_t *ppos)
525fec247c0SSujith {
526fec247c0SSujith 	struct ath_softc *sc = file->private_data;
527fec247c0SSujith 	char *buf;
5287f010c93SBen Greear 	unsigned int len = 0, size = 8000;
5292dac4fb9SBen Greear 	int i;
530fec247c0SSujith 	ssize_t retval = 0;
5312dac4fb9SBen Greear 	char tmp[32];
532fec247c0SSujith 
533fec247c0SSujith 	buf = kzalloc(size, GFP_KERNEL);
534fec247c0SSujith 	if (buf == NULL)
53504236066SDan Carpenter 		return -ENOMEM;
536fec247c0SSujith 
53760f2d1d5SBen Greear 	len += sprintf(buf, "Num-Tx-Queues: %i  tx-queues-setup: 0x%x"
53860f2d1d5SBen Greear 		       " poll-work-seen: %u\n"
5397f010c93SBen Greear 		       "%30s %10s%10s%10s\n\n",
5407f010c93SBen Greear 		       ATH9K_NUM_TX_QUEUES, sc->tx.txqsetup,
54160f2d1d5SBen Greear 		       sc->tx_complete_poll_work_seen,
5427f010c93SBen Greear 		       "BE", "BK", "VI", "VO");
543fec247c0SSujith 
544fec247c0SSujith 	PR("MPDUs Queued:    ", queued);
545fec247c0SSujith 	PR("MPDUs Completed: ", completed);
546fec247c0SSujith 	PR("Aggregates:      ", a_aggr);
547bda8addaSBen Greear 	PR("AMPDUs Queued HW:", a_queued_hw);
548bda8addaSBen Greear 	PR("AMPDUs Queued SW:", a_queued_sw);
549fec247c0SSujith 	PR("AMPDUs Completed:", a_completed);
550fec247c0SSujith 	PR("AMPDUs Retried:  ", a_retries);
551fec247c0SSujith 	PR("AMPDUs XRetried: ", a_xretries);
552fec247c0SSujith 	PR("FIFO Underrun:   ", fifo_underrun);
553fec247c0SSujith 	PR("TXOP Exceeded:   ", xtxop);
554fec247c0SSujith 	PR("TXTIMER Expiry:  ", timer_exp);
555fec247c0SSujith 	PR("DESC CFG Error:  ", desc_cfg_err);
556fec247c0SSujith 	PR("DATA Underrun:   ", data_underrun);
557fec247c0SSujith 	PR("DELIM Underrun:  ", delim_underrun);
55899c15bf5SBen Greear 	PR("TX-Pkts-All:     ", tx_pkts_all);
55999c15bf5SBen Greear 	PR("TX-Bytes-All:    ", tx_bytes_all);
5602dac4fb9SBen Greear 	PR("hw-put-tx-buf:   ", puttxbuf);
5612dac4fb9SBen Greear 	PR("hw-tx-start:     ", txstart);
5622dac4fb9SBen Greear 	PR("hw-tx-proc-desc: ", txprocdesc);
5637f010c93SBen Greear 	len += snprintf(buf + len, size - len,
5647f010c93SBen Greear 			"%s%11p%11p%10p%10p\n", "txq-memory-address:",
565*db7889cdSBen Greear 			sc->tx.txq_map[WME_AC_BE],
566*db7889cdSBen Greear 			sc->tx.txq_map[WME_AC_BK],
567*db7889cdSBen Greear 			sc->tx.txq_map[WME_AC_VI],
568*db7889cdSBen Greear 			sc->tx.txq_map[WME_AC_VO]);
5697f010c93SBen Greear 	if (len >= size)
5707f010c93SBen Greear 		goto done;
571fec247c0SSujith 
5721f427dd9SBen Greear 	PRX("axq-qnum:        ", axq_qnum);
5731f427dd9SBen Greear 	PRX("axq-depth:       ", axq_depth);
5742dac4fb9SBen Greear 	PRX("axq-ampdu_depth: ", axq_ampdu_depth);
5751f427dd9SBen Greear 	PRX("axq-stopped      ", stopped);
5761f427dd9SBen Greear 	PRX("tx-in-progress   ", axq_tx_inprogress);
5771f427dd9SBen Greear 	PRX("pending-frames   ", pending_frames);
5782dac4fb9SBen Greear 	PRX("txq_headidx:     ", txq_headidx);
5792dac4fb9SBen Greear 	PRX("txq_tailidx:     ", txq_headidx);
5801f427dd9SBen Greear 
5812dac4fb9SBen Greear 	PRQLE("axq_q empty:       ", axq_q);
5822dac4fb9SBen Greear 	PRQLE("axq_acq empty:     ", axq_acq);
5832dac4fb9SBen Greear 	PRQLE("txq_fifo_pending:  ", txq_fifo_pending);
5842dac4fb9SBen Greear 	for (i = 0; i < ATH_TXFIFO_DEPTH; i++) {
5852dac4fb9SBen Greear 		snprintf(tmp, sizeof(tmp) - 1, "txq_fifo[%i] empty: ", i);
5862dac4fb9SBen Greear 		PRQLE(tmp, txq_fifo[i]);
5872dac4fb9SBen Greear 	}
5887f010c93SBen Greear 
58971e025a5SBen Greear 	/* Print out more detailed queue-info */
59071e025a5SBen Greear 	for (i = 0; i <= WME_AC_BK; i++) {
59171e025a5SBen Greear 		struct ath_txq *txq = &(sc->tx.txq[i]);
59271e025a5SBen Greear 		struct ath_atx_ac *ac;
59371e025a5SBen Greear 		struct ath_atx_tid *tid;
59471e025a5SBen Greear 		if (len >= size)
59571e025a5SBen Greear 			goto done;
59671e025a5SBen Greear 		spin_lock_bh(&txq->axq_lock);
59771e025a5SBen Greear 		if (!list_empty(&txq->axq_acq)) {
59871e025a5SBen Greear 			ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac,
59971e025a5SBen Greear 					      list);
60071e025a5SBen Greear 			len += snprintf(buf + len, size - len,
60171e025a5SBen Greear 					"txq[%i] first-ac: %p sched: %i\n",
60271e025a5SBen Greear 					i, ac, ac->sched);
60371e025a5SBen Greear 			if (list_empty(&ac->tid_q) || (len >= size))
60471e025a5SBen Greear 				goto done_for;
60571e025a5SBen Greear 			tid = list_first_entry(&ac->tid_q, struct ath_atx_tid,
60671e025a5SBen Greear 					       list);
60771e025a5SBen Greear 			len += snprintf(buf + len, size - len,
60871e025a5SBen Greear 					" first-tid: %p sched: %i paused: %i\n",
60971e025a5SBen Greear 					tid, tid->sched, tid->paused);
61071e025a5SBen Greear 		}
61171e025a5SBen Greear 	done_for:
61271e025a5SBen Greear 		spin_unlock_bh(&txq->axq_lock);
61371e025a5SBen Greear 	}
61471e025a5SBen Greear 
6157f010c93SBen Greear done:
6167f010c93SBen Greear 	if (len > size)
6177f010c93SBen Greear 		len = size;
6187f010c93SBen Greear 
6197f010c93SBen Greear 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
6207f010c93SBen Greear 	kfree(buf);
6217f010c93SBen Greear 
6227f010c93SBen Greear 	return retval;
6237f010c93SBen Greear }
6247f010c93SBen Greear 
6257f010c93SBen Greear static ssize_t read_file_stations(struct file *file, char __user *user_buf,
6267f010c93SBen Greear 				  size_t count, loff_t *ppos)
6277f010c93SBen Greear {
6287f010c93SBen Greear 	struct ath_softc *sc = file->private_data;
6297f010c93SBen Greear 	char *buf;
6307f010c93SBen Greear 	unsigned int len = 0, size = 64000;
6317f010c93SBen Greear 	struct ath_node *an = NULL;
6327f010c93SBen Greear 	ssize_t retval = 0;
6337f010c93SBen Greear 	int q;
6347f010c93SBen Greear 
6357f010c93SBen Greear 	buf = kzalloc(size, GFP_KERNEL);
6367f010c93SBen Greear 	if (buf == NULL)
6377f010c93SBen Greear 		return -ENOMEM;
6387f010c93SBen Greear 
6397f010c93SBen Greear 	len += snprintf(buf + len, size - len,
6407f010c93SBen Greear 			"Stations:\n"
6417f010c93SBen Greear 			" tid: addr sched paused buf_q-empty an ac\n"
6427f010c93SBen Greear 			" ac: addr sched tid_q-empty txq\n");
6437f010c93SBen Greear 
6447f010c93SBen Greear 	spin_lock(&sc->nodes_lock);
6457f010c93SBen Greear 	list_for_each_entry(an, &sc->nodes, list) {
6467f010c93SBen Greear 		len += snprintf(buf + len, size - len,
6477f010c93SBen Greear 				"%pM\n", an->sta->addr);
6487f010c93SBen Greear 		if (len >= size)
6497f010c93SBen Greear 			goto done;
6507f010c93SBen Greear 
6517f010c93SBen Greear 		for (q = 0; q < WME_NUM_TID; q++) {
6527f010c93SBen Greear 			struct ath_atx_tid *tid = &(an->tid[q]);
6537f010c93SBen Greear 			len += snprintf(buf + len, size - len,
6547f010c93SBen Greear 					" tid: %p %s %s %i %p %p\n",
6557f010c93SBen Greear 					tid, tid->sched ? "sched" : "idle",
6567f010c93SBen Greear 					tid->paused ? "paused" : "running",
6577f010c93SBen Greear 					list_empty(&tid->buf_q),
6587f010c93SBen Greear 					tid->an, tid->ac);
6597f010c93SBen Greear 			if (len >= size)
6607f010c93SBen Greear 				goto done;
6617f010c93SBen Greear 		}
6627f010c93SBen Greear 
6637f010c93SBen Greear 		for (q = 0; q < WME_NUM_AC; q++) {
6647f010c93SBen Greear 			struct ath_atx_ac *ac = &(an->ac[q]);
6657f010c93SBen Greear 			len += snprintf(buf + len, size - len,
6667f010c93SBen Greear 					" ac: %p %s %i %p\n",
6677f010c93SBen Greear 					ac, ac->sched ? "sched" : "idle",
6687f010c93SBen Greear 					list_empty(&ac->tid_q), ac->txq);
6697f010c93SBen Greear 			if (len >= size)
6707f010c93SBen Greear 				goto done;
6717f010c93SBen Greear 		}
6727f010c93SBen Greear 	}
6737f010c93SBen Greear 
6747f010c93SBen Greear done:
6757f010c93SBen Greear 	spin_unlock(&sc->nodes_lock);
6762b87f3aaSDan Carpenter 	if (len > size)
6772b87f3aaSDan Carpenter 		len = size;
6782b87f3aaSDan Carpenter 
679fec247c0SSujith 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
680fec247c0SSujith 	kfree(buf);
681fec247c0SSujith 
682fec247c0SSujith 	return retval;
683fec247c0SSujith }
684fec247c0SSujith 
68555f6d0ffSBen Greear static ssize_t read_file_misc(struct file *file, char __user *user_buf,
68655f6d0ffSBen Greear 			      size_t count, loff_t *ppos)
68755f6d0ffSBen Greear {
68855f6d0ffSBen Greear 	struct ath_softc *sc = file->private_data;
68955f6d0ffSBen Greear 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
69055f6d0ffSBen Greear 	struct ath_hw *ah = sc->sc_ah;
69155f6d0ffSBen Greear 	struct ieee80211_hw *hw = sc->hw;
69255f6d0ffSBen Greear 	char *buf;
69355f6d0ffSBen Greear 	unsigned int len = 0, size = 8000;
69455f6d0ffSBen Greear 	ssize_t retval = 0;
69555f6d0ffSBen Greear 	const char *tmp;
69655f6d0ffSBen Greear 	unsigned int reg;
69755f6d0ffSBen Greear 	struct ath9k_vif_iter_data iter_data;
69855f6d0ffSBen Greear 
69955f6d0ffSBen Greear 	ath9k_calculate_iter_data(hw, NULL, &iter_data);
70055f6d0ffSBen Greear 
70155f6d0ffSBen Greear 	buf = kzalloc(size, GFP_KERNEL);
70255f6d0ffSBen Greear 	if (buf == NULL)
70355f6d0ffSBen Greear 		return -ENOMEM;
70455f6d0ffSBen Greear 
70555f6d0ffSBen Greear 	switch (sc->sc_ah->opmode) {
70655f6d0ffSBen Greear 	case  NL80211_IFTYPE_ADHOC:
70755f6d0ffSBen Greear 		tmp = "ADHOC";
70855f6d0ffSBen Greear 		break;
70955f6d0ffSBen Greear 	case  NL80211_IFTYPE_MESH_POINT:
71055f6d0ffSBen Greear 		tmp = "MESH";
71155f6d0ffSBen Greear 		break;
71255f6d0ffSBen Greear 	case  NL80211_IFTYPE_AP:
71355f6d0ffSBen Greear 		tmp = "AP";
71455f6d0ffSBen Greear 		break;
71555f6d0ffSBen Greear 	case  NL80211_IFTYPE_STATION:
71655f6d0ffSBen Greear 		tmp = "STATION";
71755f6d0ffSBen Greear 		break;
71855f6d0ffSBen Greear 	default:
71955f6d0ffSBen Greear 		tmp = "???";
72055f6d0ffSBen Greear 		break;
72155f6d0ffSBen Greear 	}
72255f6d0ffSBen Greear 
72355f6d0ffSBen Greear 	len += snprintf(buf + len, size - len,
72455f6d0ffSBen Greear 			"curbssid: %pM\n"
72555f6d0ffSBen Greear 			"OP-Mode: %s(%i)\n"
72655f6d0ffSBen Greear 			"Beacon-Timer-Register: 0x%x\n",
72755f6d0ffSBen Greear 			common->curbssid,
72855f6d0ffSBen Greear 			tmp, (int)(sc->sc_ah->opmode),
72955f6d0ffSBen Greear 			REG_READ(ah, AR_BEACON_PERIOD));
73055f6d0ffSBen Greear 
73155f6d0ffSBen Greear 	reg = REG_READ(ah, AR_TIMER_MODE);
73255f6d0ffSBen Greear 	len += snprintf(buf + len, size - len, "Timer-Mode-Register: 0x%x (",
73355f6d0ffSBen Greear 			reg);
73455f6d0ffSBen Greear 	if (reg & AR_TBTT_TIMER_EN)
73555f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "TBTT ");
73655f6d0ffSBen Greear 	if (reg & AR_DBA_TIMER_EN)
73755f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "DBA ");
73855f6d0ffSBen Greear 	if (reg & AR_SWBA_TIMER_EN)
73955f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "SWBA ");
74055f6d0ffSBen Greear 	if (reg & AR_HCF_TIMER_EN)
74155f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "HCF ");
74255f6d0ffSBen Greear 	if (reg & AR_TIM_TIMER_EN)
74355f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "TIM ");
74455f6d0ffSBen Greear 	if (reg & AR_DTIM_TIMER_EN)
74555f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "DTIM ");
74655f6d0ffSBen Greear 	len += snprintf(buf + len, size - len, ")\n");
74755f6d0ffSBen Greear 
74855f6d0ffSBen Greear 	reg = sc->sc_ah->imask;
74955f6d0ffSBen Greear 	len += snprintf(buf + len, size - len, "imask: 0x%x (", reg);
75055f6d0ffSBen Greear 	if (reg & ATH9K_INT_SWBA)
75155f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "SWBA ");
75255f6d0ffSBen Greear 	if (reg & ATH9K_INT_BMISS)
75355f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "BMISS ");
75455f6d0ffSBen Greear 	if (reg & ATH9K_INT_CST)
75555f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "CST ");
75655f6d0ffSBen Greear 	if (reg & ATH9K_INT_RX)
75755f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "RX ");
75855f6d0ffSBen Greear 	if (reg & ATH9K_INT_RXHP)
75955f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "RXHP ");
76055f6d0ffSBen Greear 	if (reg & ATH9K_INT_RXLP)
76155f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "RXLP ");
76255f6d0ffSBen Greear 	if (reg & ATH9K_INT_BB_WATCHDOG)
76355f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "BB_WATCHDOG ");
76455f6d0ffSBen Greear 	/* there are other IRQs if one wanted to add them. */
76555f6d0ffSBen Greear 	len += snprintf(buf + len, size - len, ")\n");
76655f6d0ffSBen Greear 
76755f6d0ffSBen Greear 	len += snprintf(buf + len, size - len,
76855f6d0ffSBen Greear 			"VIF Counts: AP: %i STA: %i MESH: %i WDS: %i"
76955f6d0ffSBen Greear 			" ADHOC: %i OTHER: %i nvifs: %hi beacon-vifs: %hi\n",
77055f6d0ffSBen Greear 			iter_data.naps, iter_data.nstations, iter_data.nmeshes,
77155f6d0ffSBen Greear 			iter_data.nwds, iter_data.nadhocs, iter_data.nothers,
77255f6d0ffSBen Greear 			sc->nvifs, sc->nbcnvifs);
77355f6d0ffSBen Greear 
77455f6d0ffSBen Greear 	len += snprintf(buf + len, size - len,
77555f6d0ffSBen Greear 			"Calculated-BSSID-Mask: %pM\n",
77655f6d0ffSBen Greear 			iter_data.mask);
77755f6d0ffSBen Greear 
77855f6d0ffSBen Greear 	if (len > size)
77955f6d0ffSBen Greear 		len = size;
78055f6d0ffSBen Greear 
78155f6d0ffSBen Greear 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
78255f6d0ffSBen Greear 	kfree(buf);
78355f6d0ffSBen Greear 
78455f6d0ffSBen Greear 	return retval;
78555f6d0ffSBen Greear }
78655f6d0ffSBen Greear 
787066dae93SFelix Fietkau void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
7885bec3e5aSFelix Fietkau 		       struct ath_tx_status *ts, struct ath_txq *txq)
789fec247c0SSujith {
7905bec3e5aSFelix Fietkau 	int qnum = txq->axq_qnum;
791066dae93SFelix Fietkau 
792066dae93SFelix Fietkau 	TX_STAT_INC(qnum, tx_pkts_all);
793066dae93SFelix Fietkau 	sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
79499c15bf5SBen Greear 
795fec247c0SSujith 	if (bf_isampdu(bf)) {
796fec247c0SSujith 		if (bf_isxretried(bf))
797066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_xretries);
798fec247c0SSujith 		else
799066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_completed);
800fec247c0SSujith 	} else {
801066dae93SFelix Fietkau 		TX_STAT_INC(qnum, completed);
802fec247c0SSujith 	}
803fec247c0SSujith 
804db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_FIFO)
805066dae93SFelix Fietkau 		TX_STAT_INC(qnum, fifo_underrun);
806db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_XTXOP)
807066dae93SFelix Fietkau 		TX_STAT_INC(qnum, xtxop);
808db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
809066dae93SFelix Fietkau 		TX_STAT_INC(qnum, timer_exp);
810db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
811066dae93SFelix Fietkau 		TX_STAT_INC(qnum, desc_cfg_err);
812db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
813066dae93SFelix Fietkau 		TX_STAT_INC(qnum, data_underrun);
814db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
815066dae93SFelix Fietkau 		TX_STAT_INC(qnum, delim_underrun);
816fec247c0SSujith }
817fec247c0SSujith 
818fec247c0SSujith static const struct file_operations fops_xmit = {
819fec247c0SSujith 	.read = read_file_xmit,
820fec247c0SSujith 	.open = ath9k_debugfs_open,
8216038f373SArnd Bergmann 	.owner = THIS_MODULE,
8226038f373SArnd Bergmann 	.llseek = default_llseek,
823fec247c0SSujith };
824203c4805SLuis R. Rodriguez 
8257f010c93SBen Greear static const struct file_operations fops_stations = {
8267f010c93SBen Greear 	.read = read_file_stations,
8277f010c93SBen Greear 	.open = ath9k_debugfs_open,
8287f010c93SBen Greear 	.owner = THIS_MODULE,
8297f010c93SBen Greear 	.llseek = default_llseek,
8307f010c93SBen Greear };
8317f010c93SBen Greear 
83255f6d0ffSBen Greear static const struct file_operations fops_misc = {
83355f6d0ffSBen Greear 	.read = read_file_misc,
83455f6d0ffSBen Greear 	.open = ath9k_debugfs_open,
83555f6d0ffSBen Greear 	.owner = THIS_MODULE,
83655f6d0ffSBen Greear 	.llseek = default_llseek,
83755f6d0ffSBen Greear };
83855f6d0ffSBen Greear 
8391395d3f0SSujith static ssize_t read_file_recv(struct file *file, char __user *user_buf,
8401395d3f0SSujith 			      size_t count, loff_t *ppos)
8411395d3f0SSujith {
8421395d3f0SSujith #define PHY_ERR(s, p) \
8431395d3f0SSujith 	len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \
8441395d3f0SSujith 			sc->debug.stats.rxstats.phy_err_stats[p]);
8451395d3f0SSujith 
8461395d3f0SSujith 	struct ath_softc *sc = file->private_data;
8471395d3f0SSujith 	char *buf;
8481395d3f0SSujith 	unsigned int len = 0, size = 1152;
8491395d3f0SSujith 	ssize_t retval = 0;
8501395d3f0SSujith 
8511395d3f0SSujith 	buf = kzalloc(size, GFP_KERNEL);
8521395d3f0SSujith 	if (buf == NULL)
85304236066SDan Carpenter 		return -ENOMEM;
8541395d3f0SSujith 
8551395d3f0SSujith 	len += snprintf(buf + len, size - len,
8561395d3f0SSujith 			"%18s : %10u\n", "CRC ERR",
8571395d3f0SSujith 			sc->debug.stats.rxstats.crc_err);
8581395d3f0SSujith 	len += snprintf(buf + len, size - len,
8591395d3f0SSujith 			"%18s : %10u\n", "DECRYPT CRC ERR",
8601395d3f0SSujith 			sc->debug.stats.rxstats.decrypt_crc_err);
8611395d3f0SSujith 	len += snprintf(buf + len, size - len,
8621395d3f0SSujith 			"%18s : %10u\n", "PHY ERR",
8631395d3f0SSujith 			sc->debug.stats.rxstats.phy_err);
8641395d3f0SSujith 	len += snprintf(buf + len, size - len,
8651395d3f0SSujith 			"%18s : %10u\n", "MIC ERR",
8661395d3f0SSujith 			sc->debug.stats.rxstats.mic_err);
8671395d3f0SSujith 	len += snprintf(buf + len, size - len,
8681395d3f0SSujith 			"%18s : %10u\n", "PRE-DELIM CRC ERR",
8691395d3f0SSujith 			sc->debug.stats.rxstats.pre_delim_crc_err);
8701395d3f0SSujith 	len += snprintf(buf + len, size - len,
8711395d3f0SSujith 			"%18s : %10u\n", "POST-DELIM CRC ERR",
8721395d3f0SSujith 			sc->debug.stats.rxstats.post_delim_crc_err);
8731395d3f0SSujith 	len += snprintf(buf + len, size - len,
8741395d3f0SSujith 			"%18s : %10u\n", "DECRYPT BUSY ERR",
8751395d3f0SSujith 			sc->debug.stats.rxstats.decrypt_busy_err);
8761395d3f0SSujith 
8771395d3f0SSujith 	PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN);
8781395d3f0SSujith 	PHY_ERR("TIMING", ATH9K_PHYERR_TIMING);
8791395d3f0SSujith 	PHY_ERR("PARITY", ATH9K_PHYERR_PARITY);
8801395d3f0SSujith 	PHY_ERR("RATE", ATH9K_PHYERR_RATE);
8811395d3f0SSujith 	PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH);
8821395d3f0SSujith 	PHY_ERR("RADAR", ATH9K_PHYERR_RADAR);
8831395d3f0SSujith 	PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE);
8841395d3f0SSujith 	PHY_ERR("TOR", ATH9K_PHYERR_TOR);
8851395d3f0SSujith 	PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING);
8861395d3f0SSujith 	PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
8871395d3f0SSujith 	PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
8881395d3f0SSujith 	PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
8891395d3f0SSujith 	PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP);
8901395d3f0SSujith 	PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE);
8911395d3f0SSujith 	PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART);
8921395d3f0SSujith 	PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT);
8931395d3f0SSujith 	PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING);
8941395d3f0SSujith 	PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC);
8951395d3f0SSujith 	PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
8961395d3f0SSujith 	PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE);
8971395d3f0SSujith 	PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART);
8981395d3f0SSujith 	PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
8991395d3f0SSujith 	PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP);
9001395d3f0SSujith 	PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR);
9011395d3f0SSujith 	PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
9021395d3f0SSujith 	PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL);
9031395d3f0SSujith 
90499c15bf5SBen Greear 	len += snprintf(buf + len, size - len,
90599c15bf5SBen Greear 			"%18s : %10u\n", "RX-Pkts-All",
90699c15bf5SBen Greear 			sc->debug.stats.rxstats.rx_pkts_all);
90799c15bf5SBen Greear 	len += snprintf(buf + len, size - len,
90899c15bf5SBen Greear 			"%18s : %10u\n", "RX-Bytes-All",
90999c15bf5SBen Greear 			sc->debug.stats.rxstats.rx_bytes_all);
91099c15bf5SBen Greear 
9112b87f3aaSDan Carpenter 	if (len > size)
9122b87f3aaSDan Carpenter 		len = size;
9132b87f3aaSDan Carpenter 
9141395d3f0SSujith 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
9151395d3f0SSujith 	kfree(buf);
9161395d3f0SSujith 
9171395d3f0SSujith 	return retval;
9181395d3f0SSujith 
9191395d3f0SSujith #undef PHY_ERR
9201395d3f0SSujith }
9211395d3f0SSujith 
9228e6f5aa2SFelix Fietkau void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
9231395d3f0SSujith {
9241395d3f0SSujith #define RX_STAT_INC(c) sc->debug.stats.rxstats.c++
9251395d3f0SSujith #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
9261395d3f0SSujith 
9271395d3f0SSujith 	u32 phyerr;
9281395d3f0SSujith 
92999c15bf5SBen Greear 	RX_STAT_INC(rx_pkts_all);
93099c15bf5SBen Greear 	sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
93199c15bf5SBen Greear 
9328e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_CRC)
9331395d3f0SSujith 		RX_STAT_INC(crc_err);
9348e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_DECRYPT)
9351395d3f0SSujith 		RX_STAT_INC(decrypt_crc_err);
9368e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_MIC)
9371395d3f0SSujith 		RX_STAT_INC(mic_err);
9388e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
9391395d3f0SSujith 		RX_STAT_INC(pre_delim_crc_err);
9408e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
9411395d3f0SSujith 		RX_STAT_INC(post_delim_crc_err);
9428e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
9431395d3f0SSujith 		RX_STAT_INC(decrypt_busy_err);
9441395d3f0SSujith 
9458e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_PHY) {
9461395d3f0SSujith 		RX_STAT_INC(phy_err);
9478e6f5aa2SFelix Fietkau 		phyerr = rs->rs_phyerr & 0x24;
9481395d3f0SSujith 		RX_PHY_ERR_INC(phyerr);
9491395d3f0SSujith 	}
9501395d3f0SSujith 
9511395d3f0SSujith #undef RX_STAT_INC
9521395d3f0SSujith #undef RX_PHY_ERR_INC
9531395d3f0SSujith }
9541395d3f0SSujith 
9551395d3f0SSujith static const struct file_operations fops_recv = {
9561395d3f0SSujith 	.read = read_file_recv,
9571395d3f0SSujith 	.open = ath9k_debugfs_open,
9586038f373SArnd Bergmann 	.owner = THIS_MODULE,
9596038f373SArnd Bergmann 	.llseek = default_llseek,
9601395d3f0SSujith };
9611395d3f0SSujith 
9629bff0bc4SFelix Fietkau static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
9639bff0bc4SFelix Fietkau                                 size_t count, loff_t *ppos)
9649bff0bc4SFelix Fietkau {
9659bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
9669bff0bc4SFelix Fietkau 	char buf[32];
9679bff0bc4SFelix Fietkau 	unsigned int len;
9689bff0bc4SFelix Fietkau 
9692b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
9709bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
9719bff0bc4SFelix Fietkau }
9729bff0bc4SFelix Fietkau 
9739bff0bc4SFelix Fietkau static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
9749bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
9759bff0bc4SFelix Fietkau {
9769bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
9779bff0bc4SFelix Fietkau 	unsigned long regidx;
9789bff0bc4SFelix Fietkau 	char buf[32];
9799bff0bc4SFelix Fietkau 	ssize_t len;
9809bff0bc4SFelix Fietkau 
9819bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
9829bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
98304236066SDan Carpenter 		return -EFAULT;
9849bff0bc4SFelix Fietkau 
9859bff0bc4SFelix Fietkau 	buf[len] = '\0';
9869bff0bc4SFelix Fietkau 	if (strict_strtoul(buf, 0, &regidx))
9879bff0bc4SFelix Fietkau 		return -EINVAL;
9889bff0bc4SFelix Fietkau 
9899bff0bc4SFelix Fietkau 	sc->debug.regidx = regidx;
9909bff0bc4SFelix Fietkau 	return count;
9919bff0bc4SFelix Fietkau }
9929bff0bc4SFelix Fietkau 
9939bff0bc4SFelix Fietkau static const struct file_operations fops_regidx = {
9949bff0bc4SFelix Fietkau 	.read = read_file_regidx,
9959bff0bc4SFelix Fietkau 	.write = write_file_regidx,
9969bff0bc4SFelix Fietkau 	.open = ath9k_debugfs_open,
9976038f373SArnd Bergmann 	.owner = THIS_MODULE,
9986038f373SArnd Bergmann 	.llseek = default_llseek,
9999bff0bc4SFelix Fietkau };
10009bff0bc4SFelix Fietkau 
10019bff0bc4SFelix Fietkau static ssize_t read_file_regval(struct file *file, char __user *user_buf,
10029bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
10039bff0bc4SFelix Fietkau {
10049bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
10059bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
10069bff0bc4SFelix Fietkau 	char buf[32];
10079bff0bc4SFelix Fietkau 	unsigned int len;
10089bff0bc4SFelix Fietkau 	u32 regval;
10099bff0bc4SFelix Fietkau 
10109bff0bc4SFelix Fietkau 	regval = REG_READ_D(ah, sc->debug.regidx);
10112b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", regval);
10129bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
10139bff0bc4SFelix Fietkau }
10149bff0bc4SFelix Fietkau 
10159bff0bc4SFelix Fietkau static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
10169bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
10179bff0bc4SFelix Fietkau {
10189bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
10199bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
10209bff0bc4SFelix Fietkau 	unsigned long regval;
10219bff0bc4SFelix Fietkau 	char buf[32];
10229bff0bc4SFelix Fietkau 	ssize_t len;
10239bff0bc4SFelix Fietkau 
10249bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
10259bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
102604236066SDan Carpenter 		return -EFAULT;
10279bff0bc4SFelix Fietkau 
10289bff0bc4SFelix Fietkau 	buf[len] = '\0';
10299bff0bc4SFelix Fietkau 	if (strict_strtoul(buf, 0, &regval))
10309bff0bc4SFelix Fietkau 		return -EINVAL;
10319bff0bc4SFelix Fietkau 
10329bff0bc4SFelix Fietkau 	REG_WRITE_D(ah, sc->debug.regidx, regval);
10339bff0bc4SFelix Fietkau 	return count;
10349bff0bc4SFelix Fietkau }
10359bff0bc4SFelix Fietkau 
10369bff0bc4SFelix Fietkau static const struct file_operations fops_regval = {
10379bff0bc4SFelix Fietkau 	.read = read_file_regval,
10389bff0bc4SFelix Fietkau 	.write = write_file_regval,
10399bff0bc4SFelix Fietkau 	.open = ath9k_debugfs_open,
10406038f373SArnd Bergmann 	.owner = THIS_MODULE,
10416038f373SArnd Bergmann 	.llseek = default_llseek,
10429bff0bc4SFelix Fietkau };
10439bff0bc4SFelix Fietkau 
1044582d0064SVasanthakumar Thiagarajan #define REGDUMP_LINE_SIZE	20
1045582d0064SVasanthakumar Thiagarajan 
1046582d0064SVasanthakumar Thiagarajan static int open_file_regdump(struct inode *inode, struct file *file)
1047582d0064SVasanthakumar Thiagarajan {
1048582d0064SVasanthakumar Thiagarajan 	struct ath_softc *sc = inode->i_private;
1049582d0064SVasanthakumar Thiagarajan 	unsigned int len = 0;
1050582d0064SVasanthakumar Thiagarajan 	u8 *buf;
1051582d0064SVasanthakumar Thiagarajan 	int i;
1052582d0064SVasanthakumar Thiagarajan 	unsigned long num_regs, regdump_len, max_reg_offset;
1053582d0064SVasanthakumar Thiagarajan 
1054582d0064SVasanthakumar Thiagarajan 	max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
1055582d0064SVasanthakumar Thiagarajan 	num_regs = max_reg_offset / 4 + 1;
1056582d0064SVasanthakumar Thiagarajan 	regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
1057582d0064SVasanthakumar Thiagarajan 	buf = vmalloc(regdump_len);
1058582d0064SVasanthakumar Thiagarajan 	if (!buf)
1059582d0064SVasanthakumar Thiagarajan 		return -ENOMEM;
1060582d0064SVasanthakumar Thiagarajan 
1061582d0064SVasanthakumar Thiagarajan 	ath9k_ps_wakeup(sc);
1062582d0064SVasanthakumar Thiagarajan 	for (i = 0; i < num_regs; i++)
1063582d0064SVasanthakumar Thiagarajan 		len += scnprintf(buf + len, regdump_len - len,
1064582d0064SVasanthakumar Thiagarajan 			"0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
1065582d0064SVasanthakumar Thiagarajan 	ath9k_ps_restore(sc);
1066582d0064SVasanthakumar Thiagarajan 
1067582d0064SVasanthakumar Thiagarajan 	file->private_data = buf;
1068582d0064SVasanthakumar Thiagarajan 
1069582d0064SVasanthakumar Thiagarajan 	return 0;
1070582d0064SVasanthakumar Thiagarajan }
1071582d0064SVasanthakumar Thiagarajan 
1072582d0064SVasanthakumar Thiagarajan static const struct file_operations fops_regdump = {
1073582d0064SVasanthakumar Thiagarajan 	.open = open_file_regdump,
1074582d0064SVasanthakumar Thiagarajan 	.read = ath9k_debugfs_read_buf,
1075582d0064SVasanthakumar Thiagarajan 	.release = ath9k_debugfs_release_buf,
1076582d0064SVasanthakumar Thiagarajan 	.owner = THIS_MODULE,
1077582d0064SVasanthakumar Thiagarajan 	.llseek = default_llseek,/* read accesses f_pos */
1078582d0064SVasanthakumar Thiagarajan };
1079582d0064SVasanthakumar Thiagarajan 
10804d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah)
1081203c4805SLuis R. Rodriguez {
1082bc974f4aSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(ah);
1083bc974f4aSLuis R. Rodriguez 	struct ath_softc *sc = (struct ath_softc *) common->priv;
10844d6b228dSLuis R. Rodriguez 
1085eb272441SBen Greear 	sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1086eb272441SBen Greear 						   sc->hw->wiphy->debugfsdir);
1087203c4805SLuis R. Rodriguez 	if (!sc->debug.debugfs_phy)
1088c8a72c00SFelix Fietkau 		return -ENOMEM;
1089203c4805SLuis R. Rodriguez 
1090a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
1091c8a72c00SFelix Fietkau 	if (!debugfs_create_file("debug", S_IRUSR | S_IWUSR,
1092c8a72c00SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_debug))
10932493928eSJeff Hansen 		goto err;
1094a830df07SFelix Fietkau #endif
10952493928eSJeff Hansen 
1096c8a72c00SFelix Fietkau 	if (!debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy,
1097c8a72c00SFelix Fietkau 			sc, &fops_dma))
1098203c4805SLuis R. Rodriguez 		goto err;
1099203c4805SLuis R. Rodriguez 
1100c8a72c00SFelix Fietkau 	if (!debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy,
1101c8a72c00SFelix Fietkau 			sc, &fops_interrupt))
1102203c4805SLuis R. Rodriguez 		goto err;
1103203c4805SLuis R. Rodriguez 
1104c8a72c00SFelix Fietkau 	if (!debugfs_create_file("wiphy", S_IRUSR | S_IWUSR,
1105c8a72c00SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_wiphy))
1106203c4805SLuis R. Rodriguez 		goto err;
1107203c4805SLuis R. Rodriguez 
1108c8a72c00SFelix Fietkau 	if (!debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy,
1109c8a72c00SFelix Fietkau 			sc, &fops_xmit))
1110fec247c0SSujith 		goto err;
1111fec247c0SSujith 
11127f010c93SBen Greear 	if (!debugfs_create_file("stations", S_IRUSR, sc->debug.debugfs_phy,
11137f010c93SBen Greear 			sc, &fops_stations))
11147f010c93SBen Greear 		goto err;
11157f010c93SBen Greear 
111655f6d0ffSBen Greear 	if (!debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy,
111755f6d0ffSBen Greear 			sc, &fops_misc))
111855f6d0ffSBen Greear 		goto err;
111955f6d0ffSBen Greear 
1120c8a72c00SFelix Fietkau 	if (!debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy,
1121c8a72c00SFelix Fietkau 			sc, &fops_recv))
11221395d3f0SSujith 		goto err;
11231395d3f0SSujith 
112415340694SFelix Fietkau 	if (!debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
112515340694SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_rx_chainmask))
112615340694SFelix Fietkau 		goto err;
112715340694SFelix Fietkau 
112815340694SFelix Fietkau 	if (!debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
112915340694SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_tx_chainmask))
113015340694SFelix Fietkau 		goto err;
113115340694SFelix Fietkau 
11329bff0bc4SFelix Fietkau 	if (!debugfs_create_file("regidx", S_IRUSR | S_IWUSR,
11339bff0bc4SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_regidx))
11349bff0bc4SFelix Fietkau 		goto err;
11359bff0bc4SFelix Fietkau 
11369bff0bc4SFelix Fietkau 	if (!debugfs_create_file("regval", S_IRUSR | S_IWUSR,
11379bff0bc4SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_regval))
11389bff0bc4SFelix Fietkau 		goto err;
11399bff0bc4SFelix Fietkau 
114041f3e54dSFelix Fietkau 	if (!debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
114141f3e54dSFelix Fietkau 			sc->debug.debugfs_phy, &ah->config.cwm_ignore_extcca))
114241f3e54dSFelix Fietkau 		goto err;
114341f3e54dSFelix Fietkau 
1144582d0064SVasanthakumar Thiagarajan 	if (!debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy,
1145582d0064SVasanthakumar Thiagarajan 			sc, &fops_regdump))
1146582d0064SVasanthakumar Thiagarajan 		goto err;
1147582d0064SVasanthakumar Thiagarajan 
11489bff0bc4SFelix Fietkau 	sc->debug.regidx = 0;
1149203c4805SLuis R. Rodriguez 	return 0;
1150203c4805SLuis R. Rodriguez err:
1151c8a72c00SFelix Fietkau 	debugfs_remove_recursive(sc->debug.debugfs_phy);
1152eb272441SBen Greear 	sc->debug.debugfs_phy = NULL;
1153eb272441SBen Greear 	return -ENOMEM;
1154203c4805SLuis R. Rodriguez }
1155