xref: /linux/drivers/net/wireless/ath/ath9k/debug.c (revision 5b68138e5659cbfd5df2879d17f9ba0b66477fec)
1203c4805SLuis R. Rodriguez /*
2*5b68138eSSujith 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>
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++;
3296dde1aabSMohammed Shafi Shajakhan 	if (status & ATH9K_INT_TSFOOR)
3306dde1aabSMohammed Shafi Shajakhan 		sc->debug.stats.istats.tsfoor++;
331203c4805SLuis R. Rodriguez }
332203c4805SLuis R. Rodriguez 
333203c4805SLuis R. Rodriguez static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
334203c4805SLuis R. Rodriguez 				   size_t count, loff_t *ppos)
335203c4805SLuis R. Rodriguez {
336203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
337203c4805SLuis R. Rodriguez 	char buf[512];
338203c4805SLuis R. Rodriguez 	unsigned int len = 0;
339203c4805SLuis R. Rodriguez 
340a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
341a9616f41SLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
342a9616f41SLuis R. Rodriguez 			"%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp);
343a9616f41SLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
344a9616f41SLuis R. Rodriguez 			"%8s: %10u\n", "RXHP", sc->debug.stats.istats.rxhp);
34508578b8fSLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
34608578b8fSLuis R. Rodriguez 			"%8s: %10u\n", "WATCHDOG",
34708578b8fSLuis R. Rodriguez 			sc->debug.stats.istats.bb_watchdog);
348a9616f41SLuis R. Rodriguez 	} else {
349203c4805SLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
350203c4805SLuis R. Rodriguez 			"%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
351a9616f41SLuis R. Rodriguez 	}
352203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
353203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol);
354203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
355203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn);
356203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
357203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TX", sc->debug.stats.istats.txok);
358203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
359203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn);
360203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
361203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "MIB", sc->debug.stats.istats.mib);
362203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
363203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr);
364203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
365203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss);
366203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
367203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba);
368203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
369203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss);
370203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
371203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr);
372203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
373203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "CST", sc->debug.stats.istats.cst);
374203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
375203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt);
376203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
377203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TIM", sc->debug.stats.istats.tim);
378203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
379203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend);
380203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
381203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync);
382203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
383203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim);
384203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
3856dde1aabSMohammed Shafi Shajakhan 		"%8s: %10u\n", "TSFOOR", sc->debug.stats.istats.tsfoor);
3866dde1aabSMohammed Shafi Shajakhan 	len += snprintf(buf + len, sizeof(buf) - len,
387203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total);
388203c4805SLuis R. Rodriguez 
3896dde1aabSMohammed Shafi Shajakhan 
3902b87f3aaSDan Carpenter 	if (len > sizeof(buf))
3912b87f3aaSDan Carpenter 		len = sizeof(buf);
3922b87f3aaSDan Carpenter 
393203c4805SLuis R. Rodriguez 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
394203c4805SLuis R. Rodriguez }
395203c4805SLuis R. Rodriguez 
396203c4805SLuis R. Rodriguez static const struct file_operations fops_interrupt = {
397203c4805SLuis R. Rodriguez 	.read = read_file_interrupt,
398203c4805SLuis R. Rodriguez 	.open = ath9k_debugfs_open,
3996038f373SArnd Bergmann 	.owner = THIS_MODULE,
4006038f373SArnd Bergmann 	.llseek = default_llseek,
401203c4805SLuis R. Rodriguez };
402203c4805SLuis R. Rodriguez 
4034e6975f7SBen Greear static const char *channel_type_str(enum nl80211_channel_type t)
4044e6975f7SBen Greear {
4054e6975f7SBen Greear 	switch (t) {
4064e6975f7SBen Greear 	case NL80211_CHAN_NO_HT:
4074e6975f7SBen Greear 		return "no ht";
4084e6975f7SBen Greear 	case NL80211_CHAN_HT20:
4094e6975f7SBen Greear 		return "ht20";
4104e6975f7SBen Greear 	case NL80211_CHAN_HT40MINUS:
4114e6975f7SBen Greear 		return "ht40-";
4124e6975f7SBen Greear 	case NL80211_CHAN_HT40PLUS:
4134e6975f7SBen Greear 		return "ht40+";
4144e6975f7SBen Greear 	default:
4154e6975f7SBen Greear 		return "???";
4164e6975f7SBen Greear 	}
4174e6975f7SBen Greear }
4184e6975f7SBen Greear 
419203c4805SLuis R. Rodriguez static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
420203c4805SLuis R. Rodriguez 			       size_t count, loff_t *ppos)
421203c4805SLuis R. Rodriguez {
422203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
42334302397SFelix Fietkau 	struct ieee80211_channel *chan = sc->hw->conf.channel;
4244e6975f7SBen Greear 	struct ieee80211_conf *conf = &(sc->hw->conf);
425203c4805SLuis R. Rodriguez 	char buf[512];
426203c4805SLuis R. Rodriguez 	unsigned int len = 0;
427203c4805SLuis R. Rodriguez 	u8 addr[ETH_ALEN];
42839057512SBen Greear 	u32 tmp;
429203c4805SLuis R. Rodriguez 
430203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
4314e6975f7SBen Greear 			"%s (chan=%d  center-freq: %d MHz  channel-type: %d (%s))\n",
43234302397SFelix Fietkau 			wiphy_name(sc->hw->wiphy),
4338e0167a4SMohammed Shafi Shajakhan 			ieee80211_frequency_to_channel(chan->center_freq),
4344e6975f7SBen Greear 			chan->center_freq,
4354e6975f7SBen Greear 			conf->channel_type,
4364e6975f7SBen Greear 			channel_type_str(conf->channel_type));
437203c4805SLuis R. Rodriguez 
438475a6e4dSLuis R. Rodriguez 	put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr);
439475a6e4dSLuis R. Rodriguez 	put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
440203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
441203c4805SLuis R. Rodriguez 			"addr: %pM\n", addr);
442475a6e4dSLuis R. Rodriguez 	put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr);
443475a6e4dSLuis R. Rodriguez 	put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
444203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
445203c4805SLuis R. Rodriguez 			"addrmask: %pM\n", addr);
44679d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
44739057512SBen Greear 	tmp = ath9k_hw_getrxfilter(sc->sc_ah);
44879d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
44939057512SBen Greear 	len += snprintf(buf + len, sizeof(buf) - len,
45039057512SBen Greear 			"rfilt: 0x%x", tmp);
45139057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_UCAST)
45239057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " UCAST");
45339057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_MCAST)
45439057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " MCAST");
45539057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_BCAST)
45639057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " BCAST");
45739057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_CONTROL)
45839057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " CONTROL");
45939057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_BEACON)
46039057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " BEACON");
46139057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_PROM)
46239057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " PROM");
46339057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_PROBEREQ)
46439057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
46539057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_PHYERR)
46639057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " PHYERR");
46739057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_MYBEACON)
46839057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " MYBEACON");
46939057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_COMP_BAR)
47039057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
47139057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_PSPOLL)
47239057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " PSPOLL");
47339057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_PHYRADAR)
47439057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
47539057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
47639057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL\n");
47739057512SBen Greear 	else
47839057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, "\n");
479203c4805SLuis R. Rodriguez 
4802b87f3aaSDan Carpenter 	if (len > sizeof(buf))
4812b87f3aaSDan Carpenter 		len = sizeof(buf);
4822b87f3aaSDan Carpenter 
483203c4805SLuis R. Rodriguez 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
484203c4805SLuis R. Rodriguez }
485203c4805SLuis R. Rodriguez 
486203c4805SLuis R. Rodriguez static const struct file_operations fops_wiphy = {
487203c4805SLuis R. Rodriguez 	.read = read_file_wiphy,
488203c4805SLuis R. Rodriguez 	.open = ath9k_debugfs_open,
4896038f373SArnd Bergmann 	.owner = THIS_MODULE,
4906038f373SArnd Bergmann 	.llseek = default_llseek,
491203c4805SLuis R. Rodriguez };
492203c4805SLuis R. Rodriguez 
4935bec3e5aSFelix Fietkau #define PR_QNUM(_n) sc->tx.txq_map[_n]->axq_qnum
494fec247c0SSujith #define PR(str, elem)							\
495fec247c0SSujith 	do {								\
496fec247c0SSujith 		len += snprintf(buf + len, size - len,			\
497fec247c0SSujith 				"%s%13u%11u%10u%10u\n", str,		\
4985bec3e5aSFelix Fietkau 		sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].elem, \
4995bec3e5aSFelix Fietkau 		sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].elem, \
5005bec3e5aSFelix Fietkau 		sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].elem, \
5015bec3e5aSFelix Fietkau 		sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].elem); \
5027f010c93SBen Greear 		if (len >= size)			  \
5037f010c93SBen Greear 			goto done;			  \
504fec247c0SSujith } while(0)
505fec247c0SSujith 
5061f427dd9SBen Greear #define PRX(str, elem)							\
5071f427dd9SBen Greear do {									\
5081f427dd9SBen Greear 	len += snprintf(buf + len, size - len,				\
5091f427dd9SBen Greear 			"%s%13u%11u%10u%10u\n", str,			\
5105bec3e5aSFelix Fietkau 			(unsigned int)(sc->tx.txq_map[WME_AC_BE]->elem),	\
5115bec3e5aSFelix Fietkau 			(unsigned int)(sc->tx.txq_map[WME_AC_BK]->elem),	\
5125bec3e5aSFelix Fietkau 			(unsigned int)(sc->tx.txq_map[WME_AC_VI]->elem),	\
5135bec3e5aSFelix Fietkau 			(unsigned int)(sc->tx.txq_map[WME_AC_VO]->elem));	\
5147f010c93SBen Greear 	if (len >= size)						\
5157f010c93SBen Greear 		goto done;						\
5161f427dd9SBen Greear } while(0)
5171f427dd9SBen Greear 
5182dac4fb9SBen Greear #define PRQLE(str, elem)						\
5192dac4fb9SBen Greear do {									\
5202dac4fb9SBen Greear 	len += snprintf(buf + len, size - len,				\
5212dac4fb9SBen Greear 			"%s%13i%11i%10i%10i\n", str,			\
5225bec3e5aSFelix Fietkau 			list_empty(&sc->tx.txq_map[WME_AC_BE]->elem),	\
5235bec3e5aSFelix Fietkau 			list_empty(&sc->tx.txq_map[WME_AC_BK]->elem),	\
5245bec3e5aSFelix Fietkau 			list_empty(&sc->tx.txq_map[WME_AC_VI]->elem),	\
5255bec3e5aSFelix Fietkau 			list_empty(&sc->tx.txq_map[WME_AC_VO]->elem));	\
5267f010c93SBen Greear 	if (len >= size)						\
5277f010c93SBen Greear 		goto done;						\
5282dac4fb9SBen Greear } while (0)
5292dac4fb9SBen Greear 
530fec247c0SSujith static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
531fec247c0SSujith 			      size_t count, loff_t *ppos)
532fec247c0SSujith {
533fec247c0SSujith 	struct ath_softc *sc = file->private_data;
534fec247c0SSujith 	char *buf;
5357f010c93SBen Greear 	unsigned int len = 0, size = 8000;
5362dac4fb9SBen Greear 	int i;
537fec247c0SSujith 	ssize_t retval = 0;
5382dac4fb9SBen Greear 	char tmp[32];
539fec247c0SSujith 
540fec247c0SSujith 	buf = kzalloc(size, GFP_KERNEL);
541fec247c0SSujith 	if (buf == NULL)
54204236066SDan Carpenter 		return -ENOMEM;
543fec247c0SSujith 
54460f2d1d5SBen Greear 	len += sprintf(buf, "Num-Tx-Queues: %i  tx-queues-setup: 0x%x"
54560f2d1d5SBen Greear 		       " poll-work-seen: %u\n"
5467f010c93SBen Greear 		       "%30s %10s%10s%10s\n\n",
5477f010c93SBen Greear 		       ATH9K_NUM_TX_QUEUES, sc->tx.txqsetup,
54860f2d1d5SBen Greear 		       sc->tx_complete_poll_work_seen,
5497f010c93SBen Greear 		       "BE", "BK", "VI", "VO");
550fec247c0SSujith 
551fec247c0SSujith 	PR("MPDUs Queued:    ", queued);
552fec247c0SSujith 	PR("MPDUs Completed: ", completed);
553fec247c0SSujith 	PR("Aggregates:      ", a_aggr);
554bda8addaSBen Greear 	PR("AMPDUs Queued HW:", a_queued_hw);
555bda8addaSBen Greear 	PR("AMPDUs Queued SW:", a_queued_sw);
556fec247c0SSujith 	PR("AMPDUs Completed:", a_completed);
557fec247c0SSujith 	PR("AMPDUs Retried:  ", a_retries);
558fec247c0SSujith 	PR("AMPDUs XRetried: ", a_xretries);
559fec247c0SSujith 	PR("FIFO Underrun:   ", fifo_underrun);
560fec247c0SSujith 	PR("TXOP Exceeded:   ", xtxop);
561fec247c0SSujith 	PR("TXTIMER Expiry:  ", timer_exp);
562fec247c0SSujith 	PR("DESC CFG Error:  ", desc_cfg_err);
563fec247c0SSujith 	PR("DATA Underrun:   ", data_underrun);
564fec247c0SSujith 	PR("DELIM Underrun:  ", delim_underrun);
56599c15bf5SBen Greear 	PR("TX-Pkts-All:     ", tx_pkts_all);
56699c15bf5SBen Greear 	PR("TX-Bytes-All:    ", tx_bytes_all);
5672dac4fb9SBen Greear 	PR("hw-put-tx-buf:   ", puttxbuf);
5682dac4fb9SBen Greear 	PR("hw-tx-start:     ", txstart);
5692dac4fb9SBen Greear 	PR("hw-tx-proc-desc: ", txprocdesc);
5707f010c93SBen Greear 	len += snprintf(buf + len, size - len,
5717f010c93SBen Greear 			"%s%11p%11p%10p%10p\n", "txq-memory-address:",
572db7889cdSBen Greear 			sc->tx.txq_map[WME_AC_BE],
573db7889cdSBen Greear 			sc->tx.txq_map[WME_AC_BK],
574db7889cdSBen Greear 			sc->tx.txq_map[WME_AC_VI],
575db7889cdSBen Greear 			sc->tx.txq_map[WME_AC_VO]);
5767f010c93SBen Greear 	if (len >= size)
5777f010c93SBen Greear 		goto done;
578fec247c0SSujith 
5791f427dd9SBen Greear 	PRX("axq-qnum:        ", axq_qnum);
5801f427dd9SBen Greear 	PRX("axq-depth:       ", axq_depth);
5812dac4fb9SBen Greear 	PRX("axq-ampdu_depth: ", axq_ampdu_depth);
5821f427dd9SBen Greear 	PRX("axq-stopped      ", stopped);
5831f427dd9SBen Greear 	PRX("tx-in-progress   ", axq_tx_inprogress);
5841f427dd9SBen Greear 	PRX("pending-frames   ", pending_frames);
5852dac4fb9SBen Greear 	PRX("txq_headidx:     ", txq_headidx);
5862dac4fb9SBen Greear 	PRX("txq_tailidx:     ", txq_headidx);
5871f427dd9SBen Greear 
5882dac4fb9SBen Greear 	PRQLE("axq_q empty:       ", axq_q);
5892dac4fb9SBen Greear 	PRQLE("axq_acq empty:     ", axq_acq);
5902dac4fb9SBen Greear 	PRQLE("txq_fifo_pending:  ", txq_fifo_pending);
5912dac4fb9SBen Greear 	for (i = 0; i < ATH_TXFIFO_DEPTH; i++) {
5922dac4fb9SBen Greear 		snprintf(tmp, sizeof(tmp) - 1, "txq_fifo[%i] empty: ", i);
5932dac4fb9SBen Greear 		PRQLE(tmp, txq_fifo[i]);
5942dac4fb9SBen Greear 	}
5957f010c93SBen Greear 
59671e025a5SBen Greear 	/* Print out more detailed queue-info */
59771e025a5SBen Greear 	for (i = 0; i <= WME_AC_BK; i++) {
59871e025a5SBen Greear 		struct ath_txq *txq = &(sc->tx.txq[i]);
59971e025a5SBen Greear 		struct ath_atx_ac *ac;
60071e025a5SBen Greear 		struct ath_atx_tid *tid;
60171e025a5SBen Greear 		if (len >= size)
60271e025a5SBen Greear 			goto done;
60371e025a5SBen Greear 		spin_lock_bh(&txq->axq_lock);
60471e025a5SBen Greear 		if (!list_empty(&txq->axq_acq)) {
60571e025a5SBen Greear 			ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac,
60671e025a5SBen Greear 					      list);
60771e025a5SBen Greear 			len += snprintf(buf + len, size - len,
60871e025a5SBen Greear 					"txq[%i] first-ac: %p sched: %i\n",
60971e025a5SBen Greear 					i, ac, ac->sched);
61071e025a5SBen Greear 			if (list_empty(&ac->tid_q) || (len >= size))
61171e025a5SBen Greear 				goto done_for;
61271e025a5SBen Greear 			tid = list_first_entry(&ac->tid_q, struct ath_atx_tid,
61371e025a5SBen Greear 					       list);
61471e025a5SBen Greear 			len += snprintf(buf + len, size - len,
61571e025a5SBen Greear 					" first-tid: %p sched: %i paused: %i\n",
61671e025a5SBen Greear 					tid, tid->sched, tid->paused);
61771e025a5SBen Greear 		}
61871e025a5SBen Greear 	done_for:
61971e025a5SBen Greear 		spin_unlock_bh(&txq->axq_lock);
62071e025a5SBen Greear 	}
62171e025a5SBen Greear 
6227f010c93SBen Greear done:
6237f010c93SBen Greear 	if (len > size)
6247f010c93SBen Greear 		len = size;
6257f010c93SBen Greear 
6267f010c93SBen Greear 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
6277f010c93SBen Greear 	kfree(buf);
6287f010c93SBen Greear 
6297f010c93SBen Greear 	return retval;
6307f010c93SBen Greear }
6317f010c93SBen Greear 
6327f010c93SBen Greear static ssize_t read_file_stations(struct file *file, char __user *user_buf,
6337f010c93SBen Greear 				  size_t count, loff_t *ppos)
6347f010c93SBen Greear {
6357f010c93SBen Greear 	struct ath_softc *sc = file->private_data;
6367f010c93SBen Greear 	char *buf;
6377f010c93SBen Greear 	unsigned int len = 0, size = 64000;
6387f010c93SBen Greear 	struct ath_node *an = NULL;
6397f010c93SBen Greear 	ssize_t retval = 0;
6407f010c93SBen Greear 	int q;
6417f010c93SBen Greear 
6427f010c93SBen Greear 	buf = kzalloc(size, GFP_KERNEL);
6437f010c93SBen Greear 	if (buf == NULL)
6447f010c93SBen Greear 		return -ENOMEM;
6457f010c93SBen Greear 
6467f010c93SBen Greear 	len += snprintf(buf + len, size - len,
6477f010c93SBen Greear 			"Stations:\n"
6487f010c93SBen Greear 			" tid: addr sched paused buf_q-empty an ac\n"
6497f010c93SBen Greear 			" ac: addr sched tid_q-empty txq\n");
6507f010c93SBen Greear 
6517f010c93SBen Greear 	spin_lock(&sc->nodes_lock);
6527f010c93SBen Greear 	list_for_each_entry(an, &sc->nodes, list) {
6537f010c93SBen Greear 		len += snprintf(buf + len, size - len,
6547f010c93SBen Greear 				"%pM\n", an->sta->addr);
6557f010c93SBen Greear 		if (len >= size)
6567f010c93SBen Greear 			goto done;
6577f010c93SBen Greear 
6587f010c93SBen Greear 		for (q = 0; q < WME_NUM_TID; q++) {
6597f010c93SBen Greear 			struct ath_atx_tid *tid = &(an->tid[q]);
6607f010c93SBen Greear 			len += snprintf(buf + len, size - len,
6617f010c93SBen Greear 					" tid: %p %s %s %i %p %p\n",
6627f010c93SBen Greear 					tid, tid->sched ? "sched" : "idle",
6637f010c93SBen Greear 					tid->paused ? "paused" : "running",
6647f010c93SBen Greear 					list_empty(&tid->buf_q),
6657f010c93SBen Greear 					tid->an, tid->ac);
6667f010c93SBen Greear 			if (len >= size)
6677f010c93SBen Greear 				goto done;
6687f010c93SBen Greear 		}
6697f010c93SBen Greear 
6707f010c93SBen Greear 		for (q = 0; q < WME_NUM_AC; q++) {
6717f010c93SBen Greear 			struct ath_atx_ac *ac = &(an->ac[q]);
6727f010c93SBen Greear 			len += snprintf(buf + len, size - len,
6737f010c93SBen Greear 					" ac: %p %s %i %p\n",
6747f010c93SBen Greear 					ac, ac->sched ? "sched" : "idle",
6757f010c93SBen Greear 					list_empty(&ac->tid_q), ac->txq);
6767f010c93SBen Greear 			if (len >= size)
6777f010c93SBen Greear 				goto done;
6787f010c93SBen Greear 		}
6797f010c93SBen Greear 	}
6807f010c93SBen Greear 
6817f010c93SBen Greear done:
6827f010c93SBen Greear 	spin_unlock(&sc->nodes_lock);
6832b87f3aaSDan Carpenter 	if (len > size)
6842b87f3aaSDan Carpenter 		len = size;
6852b87f3aaSDan Carpenter 
686fec247c0SSujith 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
687fec247c0SSujith 	kfree(buf);
688fec247c0SSujith 
689fec247c0SSujith 	return retval;
690fec247c0SSujith }
691fec247c0SSujith 
69255f6d0ffSBen Greear static ssize_t read_file_misc(struct file *file, char __user *user_buf,
69355f6d0ffSBen Greear 			      size_t count, loff_t *ppos)
69455f6d0ffSBen Greear {
69555f6d0ffSBen Greear 	struct ath_softc *sc = file->private_data;
69655f6d0ffSBen Greear 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
69755f6d0ffSBen Greear 	struct ath_hw *ah = sc->sc_ah;
69855f6d0ffSBen Greear 	struct ieee80211_hw *hw = sc->hw;
69955f6d0ffSBen Greear 	char *buf;
70055f6d0ffSBen Greear 	unsigned int len = 0, size = 8000;
70155f6d0ffSBen Greear 	ssize_t retval = 0;
70255f6d0ffSBen Greear 	const char *tmp;
70355f6d0ffSBen Greear 	unsigned int reg;
70455f6d0ffSBen Greear 	struct ath9k_vif_iter_data iter_data;
70555f6d0ffSBen Greear 
70655f6d0ffSBen Greear 	ath9k_calculate_iter_data(hw, NULL, &iter_data);
70755f6d0ffSBen Greear 
70855f6d0ffSBen Greear 	buf = kzalloc(size, GFP_KERNEL);
70955f6d0ffSBen Greear 	if (buf == NULL)
71055f6d0ffSBen Greear 		return -ENOMEM;
71155f6d0ffSBen Greear 
71255f6d0ffSBen Greear 	switch (sc->sc_ah->opmode) {
71355f6d0ffSBen Greear 	case  NL80211_IFTYPE_ADHOC:
71455f6d0ffSBen Greear 		tmp = "ADHOC";
71555f6d0ffSBen Greear 		break;
71655f6d0ffSBen Greear 	case  NL80211_IFTYPE_MESH_POINT:
71755f6d0ffSBen Greear 		tmp = "MESH";
71855f6d0ffSBen Greear 		break;
71955f6d0ffSBen Greear 	case  NL80211_IFTYPE_AP:
72055f6d0ffSBen Greear 		tmp = "AP";
72155f6d0ffSBen Greear 		break;
72255f6d0ffSBen Greear 	case  NL80211_IFTYPE_STATION:
72355f6d0ffSBen Greear 		tmp = "STATION";
72455f6d0ffSBen Greear 		break;
72555f6d0ffSBen Greear 	default:
72655f6d0ffSBen Greear 		tmp = "???";
72755f6d0ffSBen Greear 		break;
72855f6d0ffSBen Greear 	}
72955f6d0ffSBen Greear 
73079d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
73155f6d0ffSBen Greear 	len += snprintf(buf + len, size - len,
73255f6d0ffSBen Greear 			"curbssid: %pM\n"
73355f6d0ffSBen Greear 			"OP-Mode: %s(%i)\n"
73455f6d0ffSBen Greear 			"Beacon-Timer-Register: 0x%x\n",
73555f6d0ffSBen Greear 			common->curbssid,
73655f6d0ffSBen Greear 			tmp, (int)(sc->sc_ah->opmode),
73755f6d0ffSBen Greear 			REG_READ(ah, AR_BEACON_PERIOD));
73855f6d0ffSBen Greear 
73955f6d0ffSBen Greear 	reg = REG_READ(ah, AR_TIMER_MODE);
74079d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
74155f6d0ffSBen Greear 	len += snprintf(buf + len, size - len, "Timer-Mode-Register: 0x%x (",
74255f6d0ffSBen Greear 			reg);
74355f6d0ffSBen Greear 	if (reg & AR_TBTT_TIMER_EN)
74455f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "TBTT ");
74555f6d0ffSBen Greear 	if (reg & AR_DBA_TIMER_EN)
74655f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "DBA ");
74755f6d0ffSBen Greear 	if (reg & AR_SWBA_TIMER_EN)
74855f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "SWBA ");
74955f6d0ffSBen Greear 	if (reg & AR_HCF_TIMER_EN)
75055f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "HCF ");
75155f6d0ffSBen Greear 	if (reg & AR_TIM_TIMER_EN)
75255f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "TIM ");
75355f6d0ffSBen Greear 	if (reg & AR_DTIM_TIMER_EN)
75455f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "DTIM ");
75555f6d0ffSBen Greear 	len += snprintf(buf + len, size - len, ")\n");
75655f6d0ffSBen Greear 
75755f6d0ffSBen Greear 	reg = sc->sc_ah->imask;
75855f6d0ffSBen Greear 	len += snprintf(buf + len, size - len, "imask: 0x%x (", reg);
75955f6d0ffSBen Greear 	if (reg & ATH9K_INT_SWBA)
76055f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "SWBA ");
76155f6d0ffSBen Greear 	if (reg & ATH9K_INT_BMISS)
76255f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "BMISS ");
76355f6d0ffSBen Greear 	if (reg & ATH9K_INT_CST)
76455f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "CST ");
76555f6d0ffSBen Greear 	if (reg & ATH9K_INT_RX)
76655f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "RX ");
76755f6d0ffSBen Greear 	if (reg & ATH9K_INT_RXHP)
76855f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "RXHP ");
76955f6d0ffSBen Greear 	if (reg & ATH9K_INT_RXLP)
77055f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "RXLP ");
77155f6d0ffSBen Greear 	if (reg & ATH9K_INT_BB_WATCHDOG)
77255f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "BB_WATCHDOG ");
77355f6d0ffSBen Greear 	/* there are other IRQs if one wanted to add them. */
77455f6d0ffSBen Greear 	len += snprintf(buf + len, size - len, ")\n");
77555f6d0ffSBen Greear 
77655f6d0ffSBen Greear 	len += snprintf(buf + len, size - len,
77755f6d0ffSBen Greear 			"VIF Counts: AP: %i STA: %i MESH: %i WDS: %i"
77855f6d0ffSBen Greear 			" ADHOC: %i OTHER: %i nvifs: %hi beacon-vifs: %hi\n",
77955f6d0ffSBen Greear 			iter_data.naps, iter_data.nstations, iter_data.nmeshes,
78055f6d0ffSBen Greear 			iter_data.nwds, iter_data.nadhocs, iter_data.nothers,
78155f6d0ffSBen Greear 			sc->nvifs, sc->nbcnvifs);
78255f6d0ffSBen Greear 
78355f6d0ffSBen Greear 	len += snprintf(buf + len, size - len,
78455f6d0ffSBen Greear 			"Calculated-BSSID-Mask: %pM\n",
78555f6d0ffSBen Greear 			iter_data.mask);
78655f6d0ffSBen Greear 
78755f6d0ffSBen Greear 	if (len > size)
78855f6d0ffSBen Greear 		len = size;
78955f6d0ffSBen Greear 
79055f6d0ffSBen Greear 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
79155f6d0ffSBen Greear 	kfree(buf);
79255f6d0ffSBen Greear 
79355f6d0ffSBen Greear 	return retval;
79455f6d0ffSBen Greear }
79555f6d0ffSBen Greear 
796066dae93SFelix Fietkau void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
7975bec3e5aSFelix Fietkau 		       struct ath_tx_status *ts, struct ath_txq *txq)
798fec247c0SSujith {
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)) {
805fec247c0SSujith 		if (bf_isxretried(bf))
806066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_xretries);
807fec247c0SSujith 		else
808066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_completed);
809fec247c0SSujith 	} else {
810066dae93SFelix Fietkau 		TX_STAT_INC(qnum, completed);
811fec247c0SSujith 	}
812fec247c0SSujith 
813db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_FIFO)
814066dae93SFelix Fietkau 		TX_STAT_INC(qnum, fifo_underrun);
815db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_XTXOP)
816066dae93SFelix Fietkau 		TX_STAT_INC(qnum, xtxop);
817db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
818066dae93SFelix Fietkau 		TX_STAT_INC(qnum, timer_exp);
819db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
820066dae93SFelix Fietkau 		TX_STAT_INC(qnum, desc_cfg_err);
821db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
822066dae93SFelix Fietkau 		TX_STAT_INC(qnum, data_underrun);
823db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
824066dae93SFelix Fietkau 		TX_STAT_INC(qnum, delim_underrun);
825fec247c0SSujith }
826fec247c0SSujith 
827fec247c0SSujith static const struct file_operations fops_xmit = {
828fec247c0SSujith 	.read = read_file_xmit,
829fec247c0SSujith 	.open = ath9k_debugfs_open,
8306038f373SArnd Bergmann 	.owner = THIS_MODULE,
8316038f373SArnd Bergmann 	.llseek = default_llseek,
832fec247c0SSujith };
833203c4805SLuis R. Rodriguez 
8347f010c93SBen Greear static const struct file_operations fops_stations = {
8357f010c93SBen Greear 	.read = read_file_stations,
8367f010c93SBen Greear 	.open = ath9k_debugfs_open,
8377f010c93SBen Greear 	.owner = THIS_MODULE,
8387f010c93SBen Greear 	.llseek = default_llseek,
8397f010c93SBen Greear };
8407f010c93SBen Greear 
84155f6d0ffSBen Greear static const struct file_operations fops_misc = {
84255f6d0ffSBen Greear 	.read = read_file_misc,
84355f6d0ffSBen Greear 	.open = ath9k_debugfs_open,
84455f6d0ffSBen Greear 	.owner = THIS_MODULE,
84555f6d0ffSBen Greear 	.llseek = default_llseek,
84655f6d0ffSBen Greear };
84755f6d0ffSBen Greear 
8481395d3f0SSujith static ssize_t read_file_recv(struct file *file, char __user *user_buf,
8491395d3f0SSujith 			      size_t count, loff_t *ppos)
8501395d3f0SSujith {
8511395d3f0SSujith #define PHY_ERR(s, p) \
8521395d3f0SSujith 	len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \
8531395d3f0SSujith 			sc->debug.stats.rxstats.phy_err_stats[p]);
8541395d3f0SSujith 
8551395d3f0SSujith 	struct ath_softc *sc = file->private_data;
8561395d3f0SSujith 	char *buf;
8577d755414SSenthil Balasubramanian 	unsigned int len = 0, size = 1400;
8581395d3f0SSujith 	ssize_t retval = 0;
8591395d3f0SSujith 
8601395d3f0SSujith 	buf = kzalloc(size, GFP_KERNEL);
8611395d3f0SSujith 	if (buf == NULL)
86204236066SDan Carpenter 		return -ENOMEM;
8631395d3f0SSujith 
8641395d3f0SSujith 	len += snprintf(buf + len, size - len,
8651395d3f0SSujith 			"%18s : %10u\n", "CRC ERR",
8661395d3f0SSujith 			sc->debug.stats.rxstats.crc_err);
8671395d3f0SSujith 	len += snprintf(buf + len, size - len,
8681395d3f0SSujith 			"%18s : %10u\n", "DECRYPT CRC ERR",
8691395d3f0SSujith 			sc->debug.stats.rxstats.decrypt_crc_err);
8701395d3f0SSujith 	len += snprintf(buf + len, size - len,
8711395d3f0SSujith 			"%18s : %10u\n", "PHY ERR",
8721395d3f0SSujith 			sc->debug.stats.rxstats.phy_err);
8731395d3f0SSujith 	len += snprintf(buf + len, size - len,
8741395d3f0SSujith 			"%18s : %10u\n", "MIC ERR",
8751395d3f0SSujith 			sc->debug.stats.rxstats.mic_err);
8761395d3f0SSujith 	len += snprintf(buf + len, size - len,
8771395d3f0SSujith 			"%18s : %10u\n", "PRE-DELIM CRC ERR",
8781395d3f0SSujith 			sc->debug.stats.rxstats.pre_delim_crc_err);
8791395d3f0SSujith 	len += snprintf(buf + len, size - len,
8801395d3f0SSujith 			"%18s : %10u\n", "POST-DELIM CRC ERR",
8811395d3f0SSujith 			sc->debug.stats.rxstats.post_delim_crc_err);
8821395d3f0SSujith 	len += snprintf(buf + len, size - len,
8831395d3f0SSujith 			"%18s : %10u\n", "DECRYPT BUSY ERR",
8841395d3f0SSujith 			sc->debug.stats.rxstats.decrypt_busy_err);
8851395d3f0SSujith 
8867d755414SSenthil Balasubramanian 	len += snprintf(buf + len, size - len,
8877d755414SSenthil Balasubramanian 			"%18s : %10d\n", "RSSI-CTL0",
8887d755414SSenthil Balasubramanian 			sc->debug.stats.rxstats.rs_rssi_ctl0);
8897d755414SSenthil Balasubramanian 
8907d755414SSenthil Balasubramanian 	len += snprintf(buf + len, size - len,
8917d755414SSenthil Balasubramanian 			"%18s : %10d\n", "RSSI-CTL1",
8927d755414SSenthil Balasubramanian 			sc->debug.stats.rxstats.rs_rssi_ctl1);
8937d755414SSenthil Balasubramanian 
8947d755414SSenthil Balasubramanian 	len += snprintf(buf + len, size - len,
8957d755414SSenthil Balasubramanian 			"%18s : %10d\n", "RSSI-CTL2",
8967d755414SSenthil Balasubramanian 			sc->debug.stats.rxstats.rs_rssi_ctl2);
8977d755414SSenthil Balasubramanian 
8987d755414SSenthil Balasubramanian 	len += snprintf(buf + len, size - len,
8997d755414SSenthil Balasubramanian 			"%18s : %10d\n", "RSSI-EXT0",
9007d755414SSenthil Balasubramanian 			sc->debug.stats.rxstats.rs_rssi_ext0);
9017d755414SSenthil Balasubramanian 
9027d755414SSenthil Balasubramanian 	len += snprintf(buf + len, size - len,
9037d755414SSenthil Balasubramanian 			"%18s : %10d\n", "RSSI-EXT1",
9047d755414SSenthil Balasubramanian 			sc->debug.stats.rxstats.rs_rssi_ext1);
9057d755414SSenthil Balasubramanian 
9067d755414SSenthil Balasubramanian 	len += snprintf(buf + len, size - len,
9077d755414SSenthil Balasubramanian 			"%18s : %10d\n", "RSSI-EXT2",
9087d755414SSenthil Balasubramanian 			sc->debug.stats.rxstats.rs_rssi_ext2);
9097d755414SSenthil Balasubramanian 
9107d755414SSenthil Balasubramanian 	len += snprintf(buf + len, size - len,
9117d755414SSenthil Balasubramanian 			"%18s : %10d\n", "Rx Antenna",
9127d755414SSenthil Balasubramanian 			sc->debug.stats.rxstats.rs_antenna);
9137d755414SSenthil Balasubramanian 
9141395d3f0SSujith 	PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN);
9151395d3f0SSujith 	PHY_ERR("TIMING", ATH9K_PHYERR_TIMING);
9161395d3f0SSujith 	PHY_ERR("PARITY", ATH9K_PHYERR_PARITY);
9171395d3f0SSujith 	PHY_ERR("RATE", ATH9K_PHYERR_RATE);
9181395d3f0SSujith 	PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH);
9191395d3f0SSujith 	PHY_ERR("RADAR", ATH9K_PHYERR_RADAR);
9201395d3f0SSujith 	PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE);
9211395d3f0SSujith 	PHY_ERR("TOR", ATH9K_PHYERR_TOR);
9221395d3f0SSujith 	PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING);
9231395d3f0SSujith 	PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
9241395d3f0SSujith 	PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
9251395d3f0SSujith 	PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
9261395d3f0SSujith 	PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP);
9271395d3f0SSujith 	PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE);
9281395d3f0SSujith 	PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART);
9291395d3f0SSujith 	PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT);
9301395d3f0SSujith 	PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING);
9311395d3f0SSujith 	PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC);
9321395d3f0SSujith 	PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
9331395d3f0SSujith 	PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE);
9341395d3f0SSujith 	PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART);
9351395d3f0SSujith 	PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
9361395d3f0SSujith 	PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP);
9371395d3f0SSujith 	PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR);
9381395d3f0SSujith 	PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
9391395d3f0SSujith 	PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL);
9401395d3f0SSujith 
94199c15bf5SBen Greear 	len += snprintf(buf + len, size - len,
94299c15bf5SBen Greear 			"%18s : %10u\n", "RX-Pkts-All",
94399c15bf5SBen Greear 			sc->debug.stats.rxstats.rx_pkts_all);
94499c15bf5SBen Greear 	len += snprintf(buf + len, size - len,
94599c15bf5SBen Greear 			"%18s : %10u\n", "RX-Bytes-All",
94699c15bf5SBen Greear 			sc->debug.stats.rxstats.rx_bytes_all);
94799c15bf5SBen Greear 
9482b87f3aaSDan Carpenter 	if (len > size)
9492b87f3aaSDan Carpenter 		len = size;
9502b87f3aaSDan Carpenter 
9511395d3f0SSujith 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
9521395d3f0SSujith 	kfree(buf);
9531395d3f0SSujith 
9541395d3f0SSujith 	return retval;
9551395d3f0SSujith 
9561395d3f0SSujith #undef PHY_ERR
9571395d3f0SSujith }
9581395d3f0SSujith 
9598e6f5aa2SFelix Fietkau void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
9601395d3f0SSujith {
9611395d3f0SSujith #define RX_STAT_INC(c) sc->debug.stats.rxstats.c++
9621395d3f0SSujith #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
9631395d3f0SSujith 
9641395d3f0SSujith 	u32 phyerr;
9651395d3f0SSujith 
96699c15bf5SBen Greear 	RX_STAT_INC(rx_pkts_all);
96799c15bf5SBen Greear 	sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
96899c15bf5SBen Greear 
9698e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_CRC)
9701395d3f0SSujith 		RX_STAT_INC(crc_err);
9718e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_DECRYPT)
9721395d3f0SSujith 		RX_STAT_INC(decrypt_crc_err);
9738e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_MIC)
9741395d3f0SSujith 		RX_STAT_INC(mic_err);
9758e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
9761395d3f0SSujith 		RX_STAT_INC(pre_delim_crc_err);
9778e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
9781395d3f0SSujith 		RX_STAT_INC(post_delim_crc_err);
9798e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
9801395d3f0SSujith 		RX_STAT_INC(decrypt_busy_err);
9811395d3f0SSujith 
9828e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_PHY) {
9831395d3f0SSujith 		RX_STAT_INC(phy_err);
9848e6f5aa2SFelix Fietkau 		phyerr = rs->rs_phyerr & 0x24;
9851395d3f0SSujith 		RX_PHY_ERR_INC(phyerr);
9861395d3f0SSujith 	}
9871395d3f0SSujith 
9887d755414SSenthil Balasubramanian 	sc->debug.stats.rxstats.rs_rssi_ctl0 = rs->rs_rssi_ctl0;
9897d755414SSenthil Balasubramanian 	sc->debug.stats.rxstats.rs_rssi_ctl1 = rs->rs_rssi_ctl1;
9907d755414SSenthil Balasubramanian 	sc->debug.stats.rxstats.rs_rssi_ctl2 = rs->rs_rssi_ctl2;
9917d755414SSenthil Balasubramanian 
9927d755414SSenthil Balasubramanian 	sc->debug.stats.rxstats.rs_rssi_ext0 = rs->rs_rssi_ext0;
9937d755414SSenthil Balasubramanian 	sc->debug.stats.rxstats.rs_rssi_ext1 = rs->rs_rssi_ext1;
9947d755414SSenthil Balasubramanian 	sc->debug.stats.rxstats.rs_rssi_ext2 = rs->rs_rssi_ext2;
9957d755414SSenthil Balasubramanian 
9967d755414SSenthil Balasubramanian 	sc->debug.stats.rxstats.rs_antenna = rs->rs_antenna;
9977d755414SSenthil Balasubramanian 
9981395d3f0SSujith #undef RX_STAT_INC
9991395d3f0SSujith #undef RX_PHY_ERR_INC
10001395d3f0SSujith }
10011395d3f0SSujith 
10021395d3f0SSujith static const struct file_operations fops_recv = {
10031395d3f0SSujith 	.read = read_file_recv,
10041395d3f0SSujith 	.open = ath9k_debugfs_open,
10056038f373SArnd Bergmann 	.owner = THIS_MODULE,
10066038f373SArnd Bergmann 	.llseek = default_llseek,
10071395d3f0SSujith };
10081395d3f0SSujith 
10099bff0bc4SFelix Fietkau static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
10109bff0bc4SFelix Fietkau                                 size_t count, loff_t *ppos)
10119bff0bc4SFelix Fietkau {
10129bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
10139bff0bc4SFelix Fietkau 	char buf[32];
10149bff0bc4SFelix Fietkau 	unsigned int len;
10159bff0bc4SFelix Fietkau 
10162b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
10179bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
10189bff0bc4SFelix Fietkau }
10199bff0bc4SFelix Fietkau 
10209bff0bc4SFelix Fietkau static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
10219bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
10229bff0bc4SFelix Fietkau {
10239bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
10249bff0bc4SFelix Fietkau 	unsigned long regidx;
10259bff0bc4SFelix Fietkau 	char buf[32];
10269bff0bc4SFelix Fietkau 	ssize_t len;
10279bff0bc4SFelix Fietkau 
10289bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
10299bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
103004236066SDan Carpenter 		return -EFAULT;
10319bff0bc4SFelix Fietkau 
10329bff0bc4SFelix Fietkau 	buf[len] = '\0';
10339bff0bc4SFelix Fietkau 	if (strict_strtoul(buf, 0, &regidx))
10349bff0bc4SFelix Fietkau 		return -EINVAL;
10359bff0bc4SFelix Fietkau 
10369bff0bc4SFelix Fietkau 	sc->debug.regidx = regidx;
10379bff0bc4SFelix Fietkau 	return count;
10389bff0bc4SFelix Fietkau }
10399bff0bc4SFelix Fietkau 
10409bff0bc4SFelix Fietkau static const struct file_operations fops_regidx = {
10419bff0bc4SFelix Fietkau 	.read = read_file_regidx,
10429bff0bc4SFelix Fietkau 	.write = write_file_regidx,
10439bff0bc4SFelix Fietkau 	.open = ath9k_debugfs_open,
10446038f373SArnd Bergmann 	.owner = THIS_MODULE,
10456038f373SArnd Bergmann 	.llseek = default_llseek,
10469bff0bc4SFelix Fietkau };
10479bff0bc4SFelix Fietkau 
10489bff0bc4SFelix Fietkau static ssize_t read_file_regval(struct file *file, char __user *user_buf,
10499bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
10509bff0bc4SFelix Fietkau {
10519bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
10529bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
10539bff0bc4SFelix Fietkau 	char buf[32];
10549bff0bc4SFelix Fietkau 	unsigned int len;
10559bff0bc4SFelix Fietkau 	u32 regval;
10569bff0bc4SFelix Fietkau 
105779d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
10589bff0bc4SFelix Fietkau 	regval = REG_READ_D(ah, sc->debug.regidx);
105979d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
10602b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", regval);
10619bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
10629bff0bc4SFelix Fietkau }
10639bff0bc4SFelix Fietkau 
10649bff0bc4SFelix Fietkau static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
10659bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
10669bff0bc4SFelix Fietkau {
10679bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
10689bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
10699bff0bc4SFelix Fietkau 	unsigned long regval;
10709bff0bc4SFelix Fietkau 	char buf[32];
10719bff0bc4SFelix Fietkau 	ssize_t len;
10729bff0bc4SFelix Fietkau 
10739bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
10749bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
107504236066SDan Carpenter 		return -EFAULT;
10769bff0bc4SFelix Fietkau 
10779bff0bc4SFelix Fietkau 	buf[len] = '\0';
10789bff0bc4SFelix Fietkau 	if (strict_strtoul(buf, 0, &regval))
10799bff0bc4SFelix Fietkau 		return -EINVAL;
10809bff0bc4SFelix Fietkau 
108179d2b157SRajkumar Manoharan 	ath9k_ps_wakeup(sc);
10829bff0bc4SFelix Fietkau 	REG_WRITE_D(ah, sc->debug.regidx, regval);
108379d2b157SRajkumar Manoharan 	ath9k_ps_restore(sc);
10849bff0bc4SFelix Fietkau 	return count;
10859bff0bc4SFelix Fietkau }
10869bff0bc4SFelix Fietkau 
10879bff0bc4SFelix Fietkau static const struct file_operations fops_regval = {
10889bff0bc4SFelix Fietkau 	.read = read_file_regval,
10899bff0bc4SFelix Fietkau 	.write = write_file_regval,
10909bff0bc4SFelix Fietkau 	.open = ath9k_debugfs_open,
10916038f373SArnd Bergmann 	.owner = THIS_MODULE,
10926038f373SArnd Bergmann 	.llseek = default_llseek,
10939bff0bc4SFelix Fietkau };
10949bff0bc4SFelix Fietkau 
1095582d0064SVasanthakumar Thiagarajan #define REGDUMP_LINE_SIZE	20
1096582d0064SVasanthakumar Thiagarajan 
1097582d0064SVasanthakumar Thiagarajan static int open_file_regdump(struct inode *inode, struct file *file)
1098582d0064SVasanthakumar Thiagarajan {
1099582d0064SVasanthakumar Thiagarajan 	struct ath_softc *sc = inode->i_private;
1100582d0064SVasanthakumar Thiagarajan 	unsigned int len = 0;
1101582d0064SVasanthakumar Thiagarajan 	u8 *buf;
1102582d0064SVasanthakumar Thiagarajan 	int i;
1103582d0064SVasanthakumar Thiagarajan 	unsigned long num_regs, regdump_len, max_reg_offset;
1104582d0064SVasanthakumar Thiagarajan 
1105582d0064SVasanthakumar Thiagarajan 	max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
1106582d0064SVasanthakumar Thiagarajan 	num_regs = max_reg_offset / 4 + 1;
1107582d0064SVasanthakumar Thiagarajan 	regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
1108582d0064SVasanthakumar Thiagarajan 	buf = vmalloc(regdump_len);
1109582d0064SVasanthakumar Thiagarajan 	if (!buf)
1110582d0064SVasanthakumar Thiagarajan 		return -ENOMEM;
1111582d0064SVasanthakumar Thiagarajan 
1112582d0064SVasanthakumar Thiagarajan 	ath9k_ps_wakeup(sc);
1113582d0064SVasanthakumar Thiagarajan 	for (i = 0; i < num_regs; i++)
1114582d0064SVasanthakumar Thiagarajan 		len += scnprintf(buf + len, regdump_len - len,
1115582d0064SVasanthakumar Thiagarajan 			"0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
1116582d0064SVasanthakumar Thiagarajan 	ath9k_ps_restore(sc);
1117582d0064SVasanthakumar Thiagarajan 
1118582d0064SVasanthakumar Thiagarajan 	file->private_data = buf;
1119582d0064SVasanthakumar Thiagarajan 
1120582d0064SVasanthakumar Thiagarajan 	return 0;
1121582d0064SVasanthakumar Thiagarajan }
1122582d0064SVasanthakumar Thiagarajan 
1123582d0064SVasanthakumar Thiagarajan static const struct file_operations fops_regdump = {
1124582d0064SVasanthakumar Thiagarajan 	.open = open_file_regdump,
1125582d0064SVasanthakumar Thiagarajan 	.read = ath9k_debugfs_read_buf,
1126582d0064SVasanthakumar Thiagarajan 	.release = ath9k_debugfs_release_buf,
1127582d0064SVasanthakumar Thiagarajan 	.owner = THIS_MODULE,
1128582d0064SVasanthakumar Thiagarajan 	.llseek = default_llseek,/* read accesses f_pos */
1129582d0064SVasanthakumar Thiagarajan };
1130582d0064SVasanthakumar Thiagarajan 
11314d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah)
1132203c4805SLuis R. Rodriguez {
1133bc974f4aSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(ah);
1134bc974f4aSLuis R. Rodriguez 	struct ath_softc *sc = (struct ath_softc *) common->priv;
11354d6b228dSLuis R. Rodriguez 
1136eb272441SBen Greear 	sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1137eb272441SBen Greear 						   sc->hw->wiphy->debugfsdir);
1138203c4805SLuis R. Rodriguez 	if (!sc->debug.debugfs_phy)
1139c8a72c00SFelix Fietkau 		return -ENOMEM;
1140203c4805SLuis R. Rodriguez 
1141a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
1142c70cab1aSFelix Fietkau 	debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1143c70cab1aSFelix Fietkau 			    sc, &fops_debug);
1144a830df07SFelix Fietkau #endif
1145c70cab1aSFelix Fietkau 	debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
1146c70cab1aSFelix Fietkau 			    &fops_dma);
1147c70cab1aSFelix Fietkau 	debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
1148c70cab1aSFelix Fietkau 			    &fops_interrupt);
1149c70cab1aSFelix Fietkau 	debugfs_create_file("wiphy", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1150c70cab1aSFelix Fietkau 			    sc, &fops_wiphy);
1151c70cab1aSFelix Fietkau 	debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc,
1152c70cab1aSFelix Fietkau 			    &fops_xmit);
1153c70cab1aSFelix Fietkau 	debugfs_create_file("stations", S_IRUSR, sc->debug.debugfs_phy, sc,
1154c70cab1aSFelix Fietkau 			    &fops_stations);
1155c70cab1aSFelix Fietkau 	debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy, sc,
1156c70cab1aSFelix Fietkau 			    &fops_misc);
1157c70cab1aSFelix Fietkau 	debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy, sc,
1158c70cab1aSFelix Fietkau 			    &fops_recv);
1159c70cab1aSFelix Fietkau 	debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
1160c70cab1aSFelix Fietkau 			    sc->debug.debugfs_phy, sc, &fops_rx_chainmask);
1161c70cab1aSFelix Fietkau 	debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
1162c70cab1aSFelix Fietkau 			    sc->debug.debugfs_phy, sc, &fops_tx_chainmask);
1163c70cab1aSFelix Fietkau 	debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1164c70cab1aSFelix Fietkau 			    sc, &fops_regidx);
1165c70cab1aSFelix Fietkau 	debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1166c70cab1aSFelix Fietkau 			    sc, &fops_regval);
1167c70cab1aSFelix Fietkau 	debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1168c70cab1aSFelix Fietkau 			    sc->debug.debugfs_phy,
1169c70cab1aSFelix Fietkau 			    &ah->config.cwm_ignore_extcca);
1170c70cab1aSFelix Fietkau 	debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
1171c70cab1aSFelix Fietkau 			    &fops_regdump);
1172582d0064SVasanthakumar Thiagarajan 
1173691680b8SFelix Fietkau 	debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
1174691680b8SFelix Fietkau 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
1175691680b8SFelix Fietkau 
1176691680b8SFelix Fietkau 	debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
1177691680b8SFelix Fietkau 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
1178691680b8SFelix Fietkau 
11799bff0bc4SFelix Fietkau 	sc->debug.regidx = 0;
1180203c4805SLuis R. Rodriguez 	return 0;
1181203c4805SLuis R. Rodriguez }
1182