xref: /openbmc/linux/drivers/net/wireless/ath/ath9k/debug.c (revision 71e025a5a630681ad8b37d4426a994d199976ec9)
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>
18203c4805SLuis R. Rodriguez #include <asm/unaligned.h>
19203c4805SLuis R. Rodriguez 
20203c4805SLuis R. Rodriguez #include "ath9k.h"
21203c4805SLuis R. Rodriguez 
22475a6e4dSLuis R. Rodriguez #define REG_WRITE_D(_ah, _reg, _val) \
23475a6e4dSLuis R. Rodriguez 	ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg))
24475a6e4dSLuis R. Rodriguez #define REG_READ_D(_ah, _reg) \
25475a6e4dSLuis R. Rodriguez 	ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
26475a6e4dSLuis R. Rodriguez 
27203c4805SLuis R. Rodriguez static int ath9k_debugfs_open(struct inode *inode, struct file *file)
28203c4805SLuis R. Rodriguez {
29203c4805SLuis R. Rodriguez 	file->private_data = inode->i_private;
30203c4805SLuis R. Rodriguez 	return 0;
31203c4805SLuis R. Rodriguez }
32203c4805SLuis R. Rodriguez 
33a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
34a830df07SFelix Fietkau 
352493928eSJeff Hansen static ssize_t read_file_debug(struct file *file, char __user *user_buf,
362493928eSJeff Hansen 			     size_t count, loff_t *ppos)
372493928eSJeff Hansen {
382493928eSJeff Hansen 	struct ath_softc *sc = file->private_data;
39c46917bbSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
402493928eSJeff Hansen 	char buf[32];
41581f725cSVasanthakumar Thiagarajan 	unsigned int len;
42581f725cSVasanthakumar Thiagarajan 
432b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", common->debug_mask);
442493928eSJeff Hansen 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
452493928eSJeff Hansen }
462493928eSJeff Hansen 
472493928eSJeff Hansen static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
482493928eSJeff Hansen 			     size_t count, loff_t *ppos)
492493928eSJeff Hansen {
502493928eSJeff Hansen 	struct ath_softc *sc = file->private_data;
51c46917bbSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
522493928eSJeff Hansen 	unsigned long mask;
532493928eSJeff Hansen 	char buf[32];
54581f725cSVasanthakumar Thiagarajan 	ssize_t len;
55581f725cSVasanthakumar Thiagarajan 
56581f725cSVasanthakumar Thiagarajan 	len = min(count, sizeof(buf) - 1);
57581f725cSVasanthakumar Thiagarajan 	if (copy_from_user(buf, user_buf, len))
5804236066SDan Carpenter 		return -EFAULT;
59581f725cSVasanthakumar Thiagarajan 
60581f725cSVasanthakumar Thiagarajan 	buf[len] = '\0';
61581f725cSVasanthakumar Thiagarajan 	if (strict_strtoul(buf, 0, &mask))
62581f725cSVasanthakumar Thiagarajan 		return -EINVAL;
63581f725cSVasanthakumar Thiagarajan 
64c46917bbSLuis R. Rodriguez 	common->debug_mask = mask;
652493928eSJeff Hansen 	return count;
662493928eSJeff Hansen }
672493928eSJeff Hansen 
682493928eSJeff Hansen static const struct file_operations fops_debug = {
692493928eSJeff Hansen 	.read = read_file_debug,
702493928eSJeff Hansen 	.write = write_file_debug,
712493928eSJeff Hansen 	.open = ath9k_debugfs_open,
726038f373SArnd Bergmann 	.owner = THIS_MODULE,
736038f373SArnd Bergmann 	.llseek = default_llseek,
742493928eSJeff Hansen };
752493928eSJeff Hansen 
76a830df07SFelix Fietkau #endif
77a830df07SFelix Fietkau 
78991a0987SPavel Roskin #define DMA_BUF_LEN 1024
79991a0987SPavel Roskin 
8015340694SFelix Fietkau static ssize_t read_file_tx_chainmask(struct file *file, char __user *user_buf,
8115340694SFelix Fietkau 			     size_t count, loff_t *ppos)
8215340694SFelix Fietkau {
8315340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
8415340694SFelix Fietkau 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
8515340694SFelix Fietkau 	char buf[32];
8615340694SFelix Fietkau 	unsigned int len;
8715340694SFelix Fietkau 
882b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", common->tx_chainmask);
8915340694SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
9015340694SFelix Fietkau }
9115340694SFelix Fietkau 
9215340694SFelix Fietkau static ssize_t write_file_tx_chainmask(struct file *file, const char __user *user_buf,
9315340694SFelix Fietkau 			     size_t count, loff_t *ppos)
9415340694SFelix Fietkau {
9515340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
9615340694SFelix Fietkau 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
9715340694SFelix Fietkau 	unsigned long mask;
9815340694SFelix Fietkau 	char buf[32];
9915340694SFelix Fietkau 	ssize_t len;
10015340694SFelix Fietkau 
10115340694SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
10215340694SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
10304236066SDan Carpenter 		return -EFAULT;
10415340694SFelix Fietkau 
10515340694SFelix Fietkau 	buf[len] = '\0';
10615340694SFelix Fietkau 	if (strict_strtoul(buf, 0, &mask))
10715340694SFelix Fietkau 		return -EINVAL;
10815340694SFelix Fietkau 
10915340694SFelix Fietkau 	common->tx_chainmask = mask;
11015340694SFelix Fietkau 	sc->sc_ah->caps.tx_chainmask = mask;
11115340694SFelix Fietkau 	return count;
11215340694SFelix Fietkau }
11315340694SFelix Fietkau 
11415340694SFelix Fietkau static const struct file_operations fops_tx_chainmask = {
11515340694SFelix Fietkau 	.read = read_file_tx_chainmask,
11615340694SFelix Fietkau 	.write = write_file_tx_chainmask,
11715340694SFelix Fietkau 	.open = ath9k_debugfs_open,
1186038f373SArnd Bergmann 	.owner = THIS_MODULE,
1196038f373SArnd Bergmann 	.llseek = default_llseek,
12015340694SFelix Fietkau };
12115340694SFelix Fietkau 
12215340694SFelix Fietkau 
12315340694SFelix Fietkau static ssize_t read_file_rx_chainmask(struct file *file, char __user *user_buf,
12415340694SFelix Fietkau 			     size_t count, loff_t *ppos)
12515340694SFelix Fietkau {
12615340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
12715340694SFelix Fietkau 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
12815340694SFelix Fietkau 	char buf[32];
12915340694SFelix Fietkau 	unsigned int len;
13015340694SFelix Fietkau 
1312b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", common->rx_chainmask);
13215340694SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
13315340694SFelix Fietkau }
13415340694SFelix Fietkau 
13515340694SFelix Fietkau static ssize_t write_file_rx_chainmask(struct file *file, const char __user *user_buf,
13615340694SFelix Fietkau 			     size_t count, loff_t *ppos)
13715340694SFelix Fietkau {
13815340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
13915340694SFelix Fietkau 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
14015340694SFelix Fietkau 	unsigned long mask;
14115340694SFelix Fietkau 	char buf[32];
14215340694SFelix Fietkau 	ssize_t len;
14315340694SFelix Fietkau 
14415340694SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
14515340694SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
14604236066SDan Carpenter 		return -EFAULT;
14715340694SFelix Fietkau 
14815340694SFelix Fietkau 	buf[len] = '\0';
14915340694SFelix Fietkau 	if (strict_strtoul(buf, 0, &mask))
15015340694SFelix Fietkau 		return -EINVAL;
15115340694SFelix Fietkau 
15215340694SFelix Fietkau 	common->rx_chainmask = mask;
15315340694SFelix Fietkau 	sc->sc_ah->caps.rx_chainmask = mask;
15415340694SFelix Fietkau 	return count;
15515340694SFelix Fietkau }
15615340694SFelix Fietkau 
15715340694SFelix Fietkau static const struct file_operations fops_rx_chainmask = {
15815340694SFelix Fietkau 	.read = read_file_rx_chainmask,
15915340694SFelix Fietkau 	.write = write_file_rx_chainmask,
16015340694SFelix Fietkau 	.open = ath9k_debugfs_open,
1616038f373SArnd Bergmann 	.owner = THIS_MODULE,
1626038f373SArnd Bergmann 	.llseek = default_llseek,
16315340694SFelix Fietkau };
16415340694SFelix Fietkau 
16515340694SFelix Fietkau 
166203c4805SLuis R. Rodriguez static ssize_t read_file_dma(struct file *file, char __user *user_buf,
167203c4805SLuis R. Rodriguez 			     size_t count, loff_t *ppos)
168203c4805SLuis R. Rodriguez {
169203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
170203c4805SLuis R. Rodriguez 	struct ath_hw *ah = sc->sc_ah;
171991a0987SPavel Roskin 	char *buf;
172991a0987SPavel Roskin 	int retval;
173203c4805SLuis R. Rodriguez 	unsigned int len = 0;
174203c4805SLuis R. Rodriguez 	u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
175203c4805SLuis R. Rodriguez 	int i, qcuOffset = 0, dcuOffset = 0;
176203c4805SLuis R. Rodriguez 	u32 *qcuBase = &val[0], *dcuBase = &val[4];
177203c4805SLuis R. Rodriguez 
178991a0987SPavel Roskin 	buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
179991a0987SPavel Roskin 	if (!buf)
18004236066SDan Carpenter 		return -ENOMEM;
181991a0987SPavel Roskin 
1827cf4a2e7SSujith 	ath9k_ps_wakeup(sc);
1837cf4a2e7SSujith 
184475a6e4dSLuis R. Rodriguez 	REG_WRITE_D(ah, AR_MACMISC,
185203c4805SLuis R. Rodriguez 		  ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
186203c4805SLuis R. Rodriguez 		   (AR_MACMISC_MISC_OBS_BUS_1 <<
187203c4805SLuis R. Rodriguez 		    AR_MACMISC_MISC_OBS_BUS_MSB_S)));
188203c4805SLuis R. Rodriguez 
189991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
190203c4805SLuis R. Rodriguez 			"Raw DMA Debug values:\n");
191203c4805SLuis R. Rodriguez 
192203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
193203c4805SLuis R. Rodriguez 		if (i % 4 == 0)
194991a0987SPavel Roskin 			len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
195203c4805SLuis R. Rodriguez 
196475a6e4dSLuis R. Rodriguez 		val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
197991a0987SPavel Roskin 		len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
198203c4805SLuis R. Rodriguez 				i, val[i]);
199203c4805SLuis R. Rodriguez 	}
200203c4805SLuis R. Rodriguez 
201991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
202991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
203203c4805SLuis R. Rodriguez 			"Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
204203c4805SLuis R. Rodriguez 
205203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
206203c4805SLuis R. Rodriguez 		if (i == 8) {
207203c4805SLuis R. Rodriguez 			qcuOffset = 0;
208203c4805SLuis R. Rodriguez 			qcuBase++;
209203c4805SLuis R. Rodriguez 		}
210203c4805SLuis R. Rodriguez 
211203c4805SLuis R. Rodriguez 		if (i == 6) {
212203c4805SLuis R. Rodriguez 			dcuOffset = 0;
213203c4805SLuis R. Rodriguez 			dcuBase++;
214203c4805SLuis R. Rodriguez 		}
215203c4805SLuis R. Rodriguez 
216991a0987SPavel Roskin 		len += snprintf(buf + len, DMA_BUF_LEN - len,
217203c4805SLuis R. Rodriguez 			"%2d          %2x      %1x     %2x           %2x\n",
218203c4805SLuis R. Rodriguez 			i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
219203c4805SLuis R. Rodriguez 			(*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
220203c4805SLuis R. Rodriguez 			val[2] & (0x7 << (i * 3)) >> (i * 3),
221203c4805SLuis R. Rodriguez 			(*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
222203c4805SLuis R. Rodriguez 	}
223203c4805SLuis R. Rodriguez 
224991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
225203c4805SLuis R. Rodriguez 
226991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
227203c4805SLuis R. Rodriguez 		"qcu_stitch state:   %2x    qcu_fetch state:        %2x\n",
228203c4805SLuis R. Rodriguez 		(val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
229991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
230203c4805SLuis R. Rodriguez 		"qcu_complete state: %2x    dcu_complete state:     %2x\n",
231203c4805SLuis R. Rodriguez 		(val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
232991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
233203c4805SLuis R. Rodriguez 		"dcu_arb state:      %2x    dcu_fp state:           %2x\n",
234203c4805SLuis R. Rodriguez 		(val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
235991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
236203c4805SLuis R. Rodriguez 		"chan_idle_dur:     %3d    chan_idle_dur_valid:     %1d\n",
237203c4805SLuis R. Rodriguez 		(val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
238991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
239203c4805SLuis R. Rodriguez 		"txfifo_valid_0:      %1d    txfifo_valid_1:          %1d\n",
240203c4805SLuis R. Rodriguez 		(val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
241991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
242203c4805SLuis R. Rodriguez 		"txfifo_dcu_num_0:   %2d    txfifo_dcu_num_1:       %2d\n",
243203c4805SLuis R. Rodriguez 		(val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
244203c4805SLuis R. Rodriguez 
245991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
246475a6e4dSLuis R. Rodriguez 			REG_READ_D(ah, AR_OBS_BUS_1));
247991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
248475a6e4dSLuis R. Rodriguez 			"AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
249203c4805SLuis R. Rodriguez 
2507cf4a2e7SSujith 	ath9k_ps_restore(sc);
2517cf4a2e7SSujith 
2522b87f3aaSDan Carpenter 	if (len > DMA_BUF_LEN)
2532b87f3aaSDan Carpenter 		len = DMA_BUF_LEN;
2542b87f3aaSDan Carpenter 
255991a0987SPavel Roskin 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
256991a0987SPavel Roskin 	kfree(buf);
257991a0987SPavel Roskin 	return retval;
258203c4805SLuis R. Rodriguez }
259203c4805SLuis R. Rodriguez 
260203c4805SLuis R. Rodriguez static const struct file_operations fops_dma = {
261203c4805SLuis R. Rodriguez 	.read = read_file_dma,
262203c4805SLuis R. Rodriguez 	.open = ath9k_debugfs_open,
2636038f373SArnd Bergmann 	.owner = THIS_MODULE,
2646038f373SArnd Bergmann 	.llseek = default_llseek,
265203c4805SLuis R. Rodriguez };
266203c4805SLuis R. Rodriguez 
267203c4805SLuis R. Rodriguez 
268203c4805SLuis R. Rodriguez void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
269203c4805SLuis R. Rodriguez {
270203c4805SLuis R. Rodriguez 	if (status)
271203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.total++;
272a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
273a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXLP)
274a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxlp++;
275a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXHP)
276a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxhp++;
27708578b8fSLuis R. Rodriguez 		if (status & ATH9K_INT_BB_WATCHDOG)
27808578b8fSLuis R. Rodriguez 			sc->debug.stats.istats.bb_watchdog++;
279a9616f41SLuis R. Rodriguez 	} else {
280203c4805SLuis R. Rodriguez 		if (status & ATH9K_INT_RX)
281203c4805SLuis R. Rodriguez 			sc->debug.stats.istats.rxok++;
282a9616f41SLuis R. Rodriguez 	}
283203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXEOL)
284203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxeol++;
285203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXORN)
286203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxorn++;
287203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TX)
288203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txok++;
289203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TXURN)
290203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txurn++;
291203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_MIB)
292203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.mib++;
293203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXPHY)
294203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxphyerr++;
295203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXKCM)
296203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rx_keycache_miss++;
297203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_SWBA)
298203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.swba++;
299203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BMISS)
300203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bmiss++;
301203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BNR)
302203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bnr++;
303203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CST)
304203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cst++;
305203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_GTT)
306203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.gtt++;
307203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TIM)
308203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.tim++;
309203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CABEND)
310203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cabend++;
311203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIMSYNC)
312203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtimsync++;
313203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIM)
314203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtim++;
315203c4805SLuis R. Rodriguez }
316203c4805SLuis R. Rodriguez 
317203c4805SLuis R. Rodriguez static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
318203c4805SLuis R. Rodriguez 				   size_t count, loff_t *ppos)
319203c4805SLuis R. Rodriguez {
320203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
321203c4805SLuis R. Rodriguez 	char buf[512];
322203c4805SLuis R. Rodriguez 	unsigned int len = 0;
323203c4805SLuis R. Rodriguez 
324a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
325a9616f41SLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
326a9616f41SLuis R. Rodriguez 			"%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp);
327a9616f41SLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
328a9616f41SLuis R. Rodriguez 			"%8s: %10u\n", "RXHP", sc->debug.stats.istats.rxhp);
32908578b8fSLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
33008578b8fSLuis R. Rodriguez 			"%8s: %10u\n", "WATCHDOG",
33108578b8fSLuis R. Rodriguez 			sc->debug.stats.istats.bb_watchdog);
332a9616f41SLuis R. Rodriguez 	} else {
333203c4805SLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
334203c4805SLuis R. Rodriguez 			"%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
335a9616f41SLuis R. Rodriguez 	}
336203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
337203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol);
338203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
339203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn);
340203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
341203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TX", sc->debug.stats.istats.txok);
342203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
343203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn);
344203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
345203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "MIB", sc->debug.stats.istats.mib);
346203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
347203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr);
348203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
349203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss);
350203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
351203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba);
352203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
353203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss);
354203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
355203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr);
356203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
357203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "CST", sc->debug.stats.istats.cst);
358203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
359203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt);
360203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
361203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TIM", sc->debug.stats.istats.tim);
362203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
363203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend);
364203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
365203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync);
366203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
367203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim);
368203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
369203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total);
370203c4805SLuis R. Rodriguez 
3712b87f3aaSDan Carpenter 	if (len > sizeof(buf))
3722b87f3aaSDan Carpenter 		len = sizeof(buf);
3732b87f3aaSDan Carpenter 
374203c4805SLuis R. Rodriguez 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
375203c4805SLuis R. Rodriguez }
376203c4805SLuis R. Rodriguez 
377203c4805SLuis R. Rodriguez static const struct file_operations fops_interrupt = {
378203c4805SLuis R. Rodriguez 	.read = read_file_interrupt,
379203c4805SLuis R. Rodriguez 	.open = ath9k_debugfs_open,
3806038f373SArnd Bergmann 	.owner = THIS_MODULE,
3816038f373SArnd Bergmann 	.llseek = default_llseek,
382203c4805SLuis R. Rodriguez };
383203c4805SLuis R. Rodriguez 
384203c4805SLuis R. Rodriguez static const char * ath_wiphy_state_str(enum ath_wiphy_state state)
385203c4805SLuis R. Rodriguez {
386203c4805SLuis R. Rodriguez 	switch (state) {
387203c4805SLuis R. Rodriguez 	case ATH_WIPHY_INACTIVE:
388203c4805SLuis R. Rodriguez 		return "INACTIVE";
389203c4805SLuis R. Rodriguez 	case ATH_WIPHY_ACTIVE:
390203c4805SLuis R. Rodriguez 		return "ACTIVE";
391203c4805SLuis R. Rodriguez 	case ATH_WIPHY_PAUSING:
392203c4805SLuis R. Rodriguez 		return "PAUSING";
393203c4805SLuis R. Rodriguez 	case ATH_WIPHY_PAUSED:
394203c4805SLuis R. Rodriguez 		return "PAUSED";
395203c4805SLuis R. Rodriguez 	case ATH_WIPHY_SCAN:
396203c4805SLuis R. Rodriguez 		return "SCAN";
397203c4805SLuis R. Rodriguez 	}
398203c4805SLuis R. Rodriguez 	return "?";
399203c4805SLuis R. Rodriguez }
400203c4805SLuis R. Rodriguez 
401203c4805SLuis R. Rodriguez static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
402203c4805SLuis R. Rodriguez 			       size_t count, loff_t *ppos)
403203c4805SLuis R. Rodriguez {
404203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
4058e0167a4SMohammed Shafi Shajakhan 	struct ath_wiphy *aphy = sc->pri_wiphy;
4068e0167a4SMohammed Shafi Shajakhan 	struct ieee80211_channel *chan = aphy->hw->conf.channel;
407203c4805SLuis R. Rodriguez 	char buf[512];
408203c4805SLuis R. Rodriguez 	unsigned int len = 0;
409203c4805SLuis R. Rodriguez 	int i;
410203c4805SLuis R. Rodriguez 	u8 addr[ETH_ALEN];
41139057512SBen Greear 	u32 tmp;
412203c4805SLuis R. Rodriguez 
413203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
414203c4805SLuis R. Rodriguez 			"primary: %s (%s chan=%d ht=%d)\n",
415203c4805SLuis R. Rodriguez 			wiphy_name(sc->pri_wiphy->hw->wiphy),
416203c4805SLuis R. Rodriguez 			ath_wiphy_state_str(sc->pri_wiphy->state),
4178e0167a4SMohammed Shafi Shajakhan 			ieee80211_frequency_to_channel(chan->center_freq),
4188e0167a4SMohammed Shafi Shajakhan 			aphy->chan_is_ht);
419203c4805SLuis R. Rodriguez 
420475a6e4dSLuis R. Rodriguez 	put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr);
421475a6e4dSLuis R. Rodriguez 	put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
422203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
423203c4805SLuis R. Rodriguez 			"addr: %pM\n", addr);
424475a6e4dSLuis R. Rodriguez 	put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr);
425475a6e4dSLuis R. Rodriguez 	put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
426203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
427203c4805SLuis R. Rodriguez 			"addrmask: %pM\n", addr);
42839057512SBen Greear 	tmp = ath9k_hw_getrxfilter(sc->sc_ah);
42939057512SBen Greear 	len += snprintf(buf + len, sizeof(buf) - len,
43039057512SBen Greear 			"rfilt: 0x%x", tmp);
43139057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_UCAST)
43239057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " UCAST");
43339057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_MCAST)
43439057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " MCAST");
43539057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_BCAST)
43639057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " BCAST");
43739057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_CONTROL)
43839057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " CONTROL");
43939057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_BEACON)
44039057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " BEACON");
44139057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_PROM)
44239057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " PROM");
44339057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_PROBEREQ)
44439057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
44539057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_PHYERR)
44639057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " PHYERR");
44739057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_MYBEACON)
44839057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " MYBEACON");
44939057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_COMP_BAR)
45039057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
45139057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_PSPOLL)
45239057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " PSPOLL");
45339057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_PHYRADAR)
45439057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
45539057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
45639057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL\n");
45739057512SBen Greear 	else
45839057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, "\n");
459203c4805SLuis R. Rodriguez 
46039057512SBen Greear 	/* Put variable-length stuff down here, and check for overflows. */
461203c4805SLuis R. Rodriguez 	for (i = 0; i < sc->num_sec_wiphy; i++) {
462191d6a11SLuis R. Rodriguez 		struct ath_wiphy *aphy_tmp = sc->sec_wiphy[i];
463191d6a11SLuis R. Rodriguez 		if (aphy_tmp == NULL)
464203c4805SLuis R. Rodriguez 			continue;
465191d6a11SLuis R. Rodriguez 		chan = aphy_tmp->hw->conf.channel;
466203c4805SLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
467203c4805SLuis R. Rodriguez 			"secondary: %s (%s chan=%d ht=%d)\n",
468191d6a11SLuis R. Rodriguez 			wiphy_name(aphy_tmp->hw->wiphy),
469191d6a11SLuis R. Rodriguez 			ath_wiphy_state_str(aphy_tmp->state),
4708e0167a4SMohammed Shafi Shajakhan 			ieee80211_frequency_to_channel(chan->center_freq),
471191d6a11SLuis R. Rodriguez 						       aphy_tmp->chan_is_ht);
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 struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name)
480203c4805SLuis R. Rodriguez {
481203c4805SLuis R. Rodriguez 	int i;
482203c4805SLuis R. Rodriguez 	if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0)
483203c4805SLuis R. Rodriguez 		return sc->pri_wiphy;
484203c4805SLuis R. Rodriguez 	for (i = 0; i < sc->num_sec_wiphy; i++) {
485203c4805SLuis R. Rodriguez 		struct ath_wiphy *aphy = sc->sec_wiphy[i];
486203c4805SLuis R. Rodriguez 		if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0)
487203c4805SLuis R. Rodriguez 			return aphy;
488203c4805SLuis R. Rodriguez 	}
489203c4805SLuis R. Rodriguez 	return NULL;
490203c4805SLuis R. Rodriguez }
491203c4805SLuis R. Rodriguez 
492203c4805SLuis R. Rodriguez static int del_wiphy(struct ath_softc *sc, const char *name)
493203c4805SLuis R. Rodriguez {
494203c4805SLuis R. Rodriguez 	struct ath_wiphy *aphy = get_wiphy(sc, name);
495203c4805SLuis R. Rodriguez 	if (!aphy)
496203c4805SLuis R. Rodriguez 		return -ENOENT;
497203c4805SLuis R. Rodriguez 	return ath9k_wiphy_del(aphy);
498203c4805SLuis R. Rodriguez }
499203c4805SLuis R. Rodriguez 
500203c4805SLuis R. Rodriguez static int pause_wiphy(struct ath_softc *sc, const char *name)
501203c4805SLuis R. Rodriguez {
502203c4805SLuis R. Rodriguez 	struct ath_wiphy *aphy = get_wiphy(sc, name);
503203c4805SLuis R. Rodriguez 	if (!aphy)
504203c4805SLuis R. Rodriguez 		return -ENOENT;
505203c4805SLuis R. Rodriguez 	return ath9k_wiphy_pause(aphy);
506203c4805SLuis R. Rodriguez }
507203c4805SLuis R. Rodriguez 
508203c4805SLuis R. Rodriguez static int unpause_wiphy(struct ath_softc *sc, const char *name)
509203c4805SLuis R. Rodriguez {
510203c4805SLuis R. Rodriguez 	struct ath_wiphy *aphy = get_wiphy(sc, name);
511203c4805SLuis R. Rodriguez 	if (!aphy)
512203c4805SLuis R. Rodriguez 		return -ENOENT;
513203c4805SLuis R. Rodriguez 	return ath9k_wiphy_unpause(aphy);
514203c4805SLuis R. Rodriguez }
515203c4805SLuis R. Rodriguez 
516203c4805SLuis R. Rodriguez static int select_wiphy(struct ath_softc *sc, const char *name)
517203c4805SLuis R. Rodriguez {
518203c4805SLuis R. Rodriguez 	struct ath_wiphy *aphy = get_wiphy(sc, name);
519203c4805SLuis R. Rodriguez 	if (!aphy)
520203c4805SLuis R. Rodriguez 		return -ENOENT;
521203c4805SLuis R. Rodriguez 	return ath9k_wiphy_select(aphy);
522203c4805SLuis R. Rodriguez }
523203c4805SLuis R. Rodriguez 
524203c4805SLuis R. Rodriguez static int schedule_wiphy(struct ath_softc *sc, const char *msec)
525203c4805SLuis R. Rodriguez {
526203c4805SLuis R. Rodriguez 	ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0));
527203c4805SLuis R. Rodriguez 	return 0;
528203c4805SLuis R. Rodriguez }
529203c4805SLuis R. Rodriguez 
530203c4805SLuis R. Rodriguez static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf,
531203c4805SLuis R. Rodriguez 				size_t count, loff_t *ppos)
532203c4805SLuis R. Rodriguez {
533203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
534203c4805SLuis R. Rodriguez 	char buf[50];
535203c4805SLuis R. Rodriguez 	size_t len;
536203c4805SLuis R. Rodriguez 
537203c4805SLuis R. Rodriguez 	len = min(count, sizeof(buf) - 1);
538203c4805SLuis R. Rodriguez 	if (copy_from_user(buf, user_buf, len))
539203c4805SLuis R. Rodriguez 		return -EFAULT;
540203c4805SLuis R. Rodriguez 	buf[len] = '\0';
541203c4805SLuis R. Rodriguez 	if (len > 0 && buf[len - 1] == '\n')
542203c4805SLuis R. Rodriguez 		buf[len - 1] = '\0';
543203c4805SLuis R. Rodriguez 
544203c4805SLuis R. Rodriguez 	if (strncmp(buf, "add", 3) == 0) {
545203c4805SLuis R. Rodriguez 		int res = ath9k_wiphy_add(sc);
546203c4805SLuis R. Rodriguez 		if (res < 0)
547203c4805SLuis R. Rodriguez 			return res;
548203c4805SLuis R. Rodriguez 	} else if (strncmp(buf, "del=", 4) == 0) {
549203c4805SLuis R. Rodriguez 		int res = del_wiphy(sc, buf + 4);
550203c4805SLuis R. Rodriguez 		if (res < 0)
551203c4805SLuis R. Rodriguez 			return res;
552203c4805SLuis R. Rodriguez 	} else if (strncmp(buf, "pause=", 6) == 0) {
553203c4805SLuis R. Rodriguez 		int res = pause_wiphy(sc, buf + 6);
554203c4805SLuis R. Rodriguez 		if (res < 0)
555203c4805SLuis R. Rodriguez 			return res;
556203c4805SLuis R. Rodriguez 	} else if (strncmp(buf, "unpause=", 8) == 0) {
557203c4805SLuis R. Rodriguez 		int res = unpause_wiphy(sc, buf + 8);
558203c4805SLuis R. Rodriguez 		if (res < 0)
559203c4805SLuis R. Rodriguez 			return res;
560203c4805SLuis R. Rodriguez 	} else if (strncmp(buf, "select=", 7) == 0) {
561203c4805SLuis R. Rodriguez 		int res = select_wiphy(sc, buf + 7);
562203c4805SLuis R. Rodriguez 		if (res < 0)
563203c4805SLuis R. Rodriguez 			return res;
564203c4805SLuis R. Rodriguez 	} else if (strncmp(buf, "schedule=", 9) == 0) {
565203c4805SLuis R. Rodriguez 		int res = schedule_wiphy(sc, buf + 9);
566203c4805SLuis R. Rodriguez 		if (res < 0)
567203c4805SLuis R. Rodriguez 			return res;
568203c4805SLuis R. Rodriguez 	} else
569203c4805SLuis R. Rodriguez 		return -EOPNOTSUPP;
570203c4805SLuis R. Rodriguez 
571203c4805SLuis R. Rodriguez 	return count;
572203c4805SLuis R. Rodriguez }
573203c4805SLuis R. Rodriguez 
574203c4805SLuis R. Rodriguez static const struct file_operations fops_wiphy = {
575203c4805SLuis R. Rodriguez 	.read = read_file_wiphy,
576203c4805SLuis R. Rodriguez 	.write = write_file_wiphy,
577203c4805SLuis R. Rodriguez 	.open = ath9k_debugfs_open,
5786038f373SArnd Bergmann 	.owner = THIS_MODULE,
5796038f373SArnd Bergmann 	.llseek = default_llseek,
580203c4805SLuis R. Rodriguez };
581203c4805SLuis R. Rodriguez 
582fec247c0SSujith #define PR(str, elem)							\
583fec247c0SSujith 	do {								\
584fec247c0SSujith 		len += snprintf(buf + len, size - len,			\
585fec247c0SSujith 				"%s%13u%11u%10u%10u\n", str,		\
586066dae93SFelix Fietkau 		sc->debug.stats.txstats[WME_AC_BE].elem, \
587066dae93SFelix Fietkau 		sc->debug.stats.txstats[WME_AC_BK].elem, \
588066dae93SFelix Fietkau 		sc->debug.stats.txstats[WME_AC_VI].elem, \
589066dae93SFelix Fietkau 		sc->debug.stats.txstats[WME_AC_VO].elem); \
5907f010c93SBen Greear 		if (len >= size)			  \
5917f010c93SBen Greear 			goto done;			  \
592fec247c0SSujith } while(0)
593fec247c0SSujith 
5941f427dd9SBen Greear #define PRX(str, elem)							\
5951f427dd9SBen Greear do {									\
5961f427dd9SBen Greear 	len += snprintf(buf + len, size - len,				\
5971f427dd9SBen Greear 			"%s%13u%11u%10u%10u\n", str,			\
5981f427dd9SBen Greear 			(unsigned int)(sc->tx.txq[WME_AC_BE].elem),	\
5991f427dd9SBen Greear 			(unsigned int)(sc->tx.txq[WME_AC_BK].elem),	\
6001f427dd9SBen Greear 			(unsigned int)(sc->tx.txq[WME_AC_VI].elem),	\
6011f427dd9SBen Greear 			(unsigned int)(sc->tx.txq[WME_AC_VO].elem));	\
6027f010c93SBen Greear 	if (len >= size)						\
6037f010c93SBen Greear 		goto done;						\
6041f427dd9SBen Greear } while(0)
6051f427dd9SBen Greear 
6062dac4fb9SBen Greear #define PRQLE(str, elem)						\
6072dac4fb9SBen Greear do {									\
6082dac4fb9SBen Greear 	len += snprintf(buf + len, size - len,				\
6092dac4fb9SBen Greear 			"%s%13i%11i%10i%10i\n", str,			\
6102dac4fb9SBen Greear 			list_empty(&sc->tx.txq[WME_AC_BE].elem),	\
6112dac4fb9SBen Greear 			list_empty(&sc->tx.txq[WME_AC_BK].elem),	\
6122dac4fb9SBen Greear 			list_empty(&sc->tx.txq[WME_AC_VI].elem),	\
6132dac4fb9SBen Greear 			list_empty(&sc->tx.txq[WME_AC_VO].elem));	\
6147f010c93SBen Greear 	if (len >= size)						\
6157f010c93SBen Greear 		goto done;						\
6162dac4fb9SBen Greear } while (0)
6172dac4fb9SBen Greear 
618fec247c0SSujith static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
619fec247c0SSujith 			      size_t count, loff_t *ppos)
620fec247c0SSujith {
621fec247c0SSujith 	struct ath_softc *sc = file->private_data;
622fec247c0SSujith 	char *buf;
6237f010c93SBen Greear 	unsigned int len = 0, size = 8000;
6242dac4fb9SBen Greear 	int i;
625fec247c0SSujith 	ssize_t retval = 0;
6262dac4fb9SBen Greear 	char tmp[32];
627fec247c0SSujith 
628fec247c0SSujith 	buf = kzalloc(size, GFP_KERNEL);
629fec247c0SSujith 	if (buf == NULL)
63004236066SDan Carpenter 		return -ENOMEM;
631fec247c0SSujith 
6327f010c93SBen Greear 	len += sprintf(buf, "Num-Tx-Queues: %i  tx-queues-setup: 0x%x\n"
6337f010c93SBen Greear 		       "%30s %10s%10s%10s\n\n",
6347f010c93SBen Greear 		       ATH9K_NUM_TX_QUEUES, sc->tx.txqsetup,
6357f010c93SBen Greear 		       "BE", "BK", "VI", "VO");
636fec247c0SSujith 
637fec247c0SSujith 	PR("MPDUs Queued:    ", queued);
638fec247c0SSujith 	PR("MPDUs Completed: ", completed);
639fec247c0SSujith 	PR("Aggregates:      ", a_aggr);
640bda8addaSBen Greear 	PR("AMPDUs Queued HW:", a_queued_hw);
641bda8addaSBen Greear 	PR("AMPDUs Queued SW:", a_queued_sw);
642fec247c0SSujith 	PR("AMPDUs Completed:", a_completed);
643fec247c0SSujith 	PR("AMPDUs Retried:  ", a_retries);
644fec247c0SSujith 	PR("AMPDUs XRetried: ", a_xretries);
645fec247c0SSujith 	PR("FIFO Underrun:   ", fifo_underrun);
646fec247c0SSujith 	PR("TXOP Exceeded:   ", xtxop);
647fec247c0SSujith 	PR("TXTIMER Expiry:  ", timer_exp);
648fec247c0SSujith 	PR("DESC CFG Error:  ", desc_cfg_err);
649fec247c0SSujith 	PR("DATA Underrun:   ", data_underrun);
650fec247c0SSujith 	PR("DELIM Underrun:  ", delim_underrun);
65199c15bf5SBen Greear 	PR("TX-Pkts-All:     ", tx_pkts_all);
65299c15bf5SBen Greear 	PR("TX-Bytes-All:    ", tx_bytes_all);
6532dac4fb9SBen Greear 	PR("hw-put-tx-buf:   ", puttxbuf);
6542dac4fb9SBen Greear 	PR("hw-tx-start:     ", txstart);
6552dac4fb9SBen Greear 	PR("hw-tx-proc-desc: ", txprocdesc);
6567f010c93SBen Greear 	len += snprintf(buf + len, size - len,
6577f010c93SBen Greear 			"%s%11p%11p%10p%10p\n", "txq-memory-address:",
6587f010c93SBen Greear 			&(sc->tx.txq[WME_AC_BE]),
6597f010c93SBen Greear 			&(sc->tx.txq[WME_AC_BK]),
6607f010c93SBen Greear 			&(sc->tx.txq[WME_AC_VI]),
6617f010c93SBen Greear 			&(sc->tx.txq[WME_AC_VO]));
6627f010c93SBen Greear 	if (len >= size)
6637f010c93SBen Greear 		goto done;
664fec247c0SSujith 
6651f427dd9SBen Greear 	PRX("axq-qnum:        ", axq_qnum);
6661f427dd9SBen Greear 	PRX("axq-depth:       ", axq_depth);
6672dac4fb9SBen Greear 	PRX("axq-ampdu_depth: ", axq_ampdu_depth);
6681f427dd9SBen Greear 	PRX("axq-stopped      ", stopped);
6691f427dd9SBen Greear 	PRX("tx-in-progress   ", axq_tx_inprogress);
6701f427dd9SBen Greear 	PRX("pending-frames   ", pending_frames);
6712dac4fb9SBen Greear 	PRX("txq_headidx:     ", txq_headidx);
6722dac4fb9SBen Greear 	PRX("txq_tailidx:     ", txq_headidx);
6731f427dd9SBen Greear 
6742dac4fb9SBen Greear 	PRQLE("axq_q empty:       ", axq_q);
6752dac4fb9SBen Greear 	PRQLE("axq_acq empty:     ", axq_acq);
6762dac4fb9SBen Greear 	PRQLE("txq_fifo_pending:  ", txq_fifo_pending);
6772dac4fb9SBen Greear 	for (i = 0; i < ATH_TXFIFO_DEPTH; i++) {
6782dac4fb9SBen Greear 		snprintf(tmp, sizeof(tmp) - 1, "txq_fifo[%i] empty: ", i);
6792dac4fb9SBen Greear 		PRQLE(tmp, txq_fifo[i]);
6802dac4fb9SBen Greear 	}
6817f010c93SBen Greear 
682*71e025a5SBen Greear 	/* Print out more detailed queue-info */
683*71e025a5SBen Greear 	for (i = 0; i <= WME_AC_BK; i++) {
684*71e025a5SBen Greear 		struct ath_txq *txq = &(sc->tx.txq[i]);
685*71e025a5SBen Greear 		struct ath_atx_ac *ac;
686*71e025a5SBen Greear 		struct ath_atx_tid *tid;
687*71e025a5SBen Greear 		if (len >= size)
688*71e025a5SBen Greear 			goto done;
689*71e025a5SBen Greear 		spin_lock_bh(&txq->axq_lock);
690*71e025a5SBen Greear 		if (!list_empty(&txq->axq_acq)) {
691*71e025a5SBen Greear 			ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac,
692*71e025a5SBen Greear 					      list);
693*71e025a5SBen Greear 			len += snprintf(buf + len, size - len,
694*71e025a5SBen Greear 					"txq[%i] first-ac: %p sched: %i\n",
695*71e025a5SBen Greear 					i, ac, ac->sched);
696*71e025a5SBen Greear 			if (list_empty(&ac->tid_q) || (len >= size))
697*71e025a5SBen Greear 				goto done_for;
698*71e025a5SBen Greear 			tid = list_first_entry(&ac->tid_q, struct ath_atx_tid,
699*71e025a5SBen Greear 					       list);
700*71e025a5SBen Greear 			len += snprintf(buf + len, size - len,
701*71e025a5SBen Greear 					" first-tid: %p sched: %i paused: %i\n",
702*71e025a5SBen Greear 					tid, tid->sched, tid->paused);
703*71e025a5SBen Greear 		}
704*71e025a5SBen Greear 	done_for:
705*71e025a5SBen Greear 		spin_unlock_bh(&txq->axq_lock);
706*71e025a5SBen Greear 	}
707*71e025a5SBen Greear 
7087f010c93SBen Greear done:
7097f010c93SBen Greear 	if (len > size)
7107f010c93SBen Greear 		len = size;
7117f010c93SBen Greear 
7127f010c93SBen Greear 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
7137f010c93SBen Greear 	kfree(buf);
7147f010c93SBen Greear 
7157f010c93SBen Greear 	return retval;
7167f010c93SBen Greear }
7177f010c93SBen Greear 
7187f010c93SBen Greear static ssize_t read_file_stations(struct file *file, char __user *user_buf,
7197f010c93SBen Greear 				  size_t count, loff_t *ppos)
7207f010c93SBen Greear {
7217f010c93SBen Greear 	struct ath_softc *sc = file->private_data;
7227f010c93SBen Greear 	char *buf;
7237f010c93SBen Greear 	unsigned int len = 0, size = 64000;
7247f010c93SBen Greear 	struct ath_node *an = NULL;
7257f010c93SBen Greear 	ssize_t retval = 0;
7267f010c93SBen Greear 	int q;
7277f010c93SBen Greear 
7287f010c93SBen Greear 	buf = kzalloc(size, GFP_KERNEL);
7297f010c93SBen Greear 	if (buf == NULL)
7307f010c93SBen Greear 		return -ENOMEM;
7317f010c93SBen Greear 
7327f010c93SBen Greear 	len += snprintf(buf + len, size - len,
7337f010c93SBen Greear 			"Stations:\n"
7347f010c93SBen Greear 			" tid: addr sched paused buf_q-empty an ac\n"
7357f010c93SBen Greear 			" ac: addr sched tid_q-empty txq\n");
7367f010c93SBen Greear 
7377f010c93SBen Greear 	spin_lock(&sc->nodes_lock);
7387f010c93SBen Greear 	list_for_each_entry(an, &sc->nodes, list) {
7397f010c93SBen Greear 		len += snprintf(buf + len, size - len,
7407f010c93SBen Greear 				"%pM\n", an->sta->addr);
7417f010c93SBen Greear 		if (len >= size)
7427f010c93SBen Greear 			goto done;
7437f010c93SBen Greear 
7447f010c93SBen Greear 		for (q = 0; q < WME_NUM_TID; q++) {
7457f010c93SBen Greear 			struct ath_atx_tid *tid = &(an->tid[q]);
7467f010c93SBen Greear 			len += snprintf(buf + len, size - len,
7477f010c93SBen Greear 					" tid: %p %s %s %i %p %p\n",
7487f010c93SBen Greear 					tid, tid->sched ? "sched" : "idle",
7497f010c93SBen Greear 					tid->paused ? "paused" : "running",
7507f010c93SBen Greear 					list_empty(&tid->buf_q),
7517f010c93SBen Greear 					tid->an, tid->ac);
7527f010c93SBen Greear 			if (len >= size)
7537f010c93SBen Greear 				goto done;
7547f010c93SBen Greear 		}
7557f010c93SBen Greear 
7567f010c93SBen Greear 		for (q = 0; q < WME_NUM_AC; q++) {
7577f010c93SBen Greear 			struct ath_atx_ac *ac = &(an->ac[q]);
7587f010c93SBen Greear 			len += snprintf(buf + len, size - len,
7597f010c93SBen Greear 					" ac: %p %s %i %p\n",
7607f010c93SBen Greear 					ac, ac->sched ? "sched" : "idle",
7617f010c93SBen Greear 					list_empty(&ac->tid_q), ac->txq);
7627f010c93SBen Greear 			if (len >= size)
7637f010c93SBen Greear 				goto done;
7647f010c93SBen Greear 		}
7657f010c93SBen Greear 	}
7667f010c93SBen Greear 
7677f010c93SBen Greear done:
7687f010c93SBen Greear 	spin_unlock(&sc->nodes_lock);
7692b87f3aaSDan Carpenter 	if (len > size)
7702b87f3aaSDan Carpenter 		len = size;
7712b87f3aaSDan Carpenter 
772fec247c0SSujith 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
773fec247c0SSujith 	kfree(buf);
774fec247c0SSujith 
775fec247c0SSujith 	return retval;
776fec247c0SSujith }
777fec247c0SSujith 
778066dae93SFelix Fietkau void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
779066dae93SFelix Fietkau 		       struct ath_tx_status *ts)
780fec247c0SSujith {
781066dae93SFelix Fietkau 	int qnum = skb_get_queue_mapping(bf->bf_mpdu);
782066dae93SFelix Fietkau 
783066dae93SFelix Fietkau 	TX_STAT_INC(qnum, tx_pkts_all);
784066dae93SFelix Fietkau 	sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
78599c15bf5SBen Greear 
786fec247c0SSujith 	if (bf_isampdu(bf)) {
787fec247c0SSujith 		if (bf_isxretried(bf))
788066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_xretries);
789fec247c0SSujith 		else
790066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_completed);
791fec247c0SSujith 	} else {
792066dae93SFelix Fietkau 		TX_STAT_INC(qnum, completed);
793fec247c0SSujith 	}
794fec247c0SSujith 
795db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_FIFO)
796066dae93SFelix Fietkau 		TX_STAT_INC(qnum, fifo_underrun);
797db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_XTXOP)
798066dae93SFelix Fietkau 		TX_STAT_INC(qnum, xtxop);
799db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
800066dae93SFelix Fietkau 		TX_STAT_INC(qnum, timer_exp);
801db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
802066dae93SFelix Fietkau 		TX_STAT_INC(qnum, desc_cfg_err);
803db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
804066dae93SFelix Fietkau 		TX_STAT_INC(qnum, data_underrun);
805db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
806066dae93SFelix Fietkau 		TX_STAT_INC(qnum, delim_underrun);
807fec247c0SSujith }
808fec247c0SSujith 
809fec247c0SSujith static const struct file_operations fops_xmit = {
810fec247c0SSujith 	.read = read_file_xmit,
811fec247c0SSujith 	.open = ath9k_debugfs_open,
8126038f373SArnd Bergmann 	.owner = THIS_MODULE,
8136038f373SArnd Bergmann 	.llseek = default_llseek,
814fec247c0SSujith };
815203c4805SLuis R. Rodriguez 
8167f010c93SBen Greear static const struct file_operations fops_stations = {
8177f010c93SBen Greear 	.read = read_file_stations,
8187f010c93SBen Greear 	.open = ath9k_debugfs_open,
8197f010c93SBen Greear 	.owner = THIS_MODULE,
8207f010c93SBen Greear 	.llseek = default_llseek,
8217f010c93SBen Greear };
8227f010c93SBen Greear 
8231395d3f0SSujith static ssize_t read_file_recv(struct file *file, char __user *user_buf,
8241395d3f0SSujith 			      size_t count, loff_t *ppos)
8251395d3f0SSujith {
8261395d3f0SSujith #define PHY_ERR(s, p) \
8271395d3f0SSujith 	len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \
8281395d3f0SSujith 			sc->debug.stats.rxstats.phy_err_stats[p]);
8291395d3f0SSujith 
8301395d3f0SSujith 	struct ath_softc *sc = file->private_data;
8311395d3f0SSujith 	char *buf;
8321395d3f0SSujith 	unsigned int len = 0, size = 1152;
8331395d3f0SSujith 	ssize_t retval = 0;
8341395d3f0SSujith 
8351395d3f0SSujith 	buf = kzalloc(size, GFP_KERNEL);
8361395d3f0SSujith 	if (buf == NULL)
83704236066SDan Carpenter 		return -ENOMEM;
8381395d3f0SSujith 
8391395d3f0SSujith 	len += snprintf(buf + len, size - len,
8401395d3f0SSujith 			"%18s : %10u\n", "CRC ERR",
8411395d3f0SSujith 			sc->debug.stats.rxstats.crc_err);
8421395d3f0SSujith 	len += snprintf(buf + len, size - len,
8431395d3f0SSujith 			"%18s : %10u\n", "DECRYPT CRC ERR",
8441395d3f0SSujith 			sc->debug.stats.rxstats.decrypt_crc_err);
8451395d3f0SSujith 	len += snprintf(buf + len, size - len,
8461395d3f0SSujith 			"%18s : %10u\n", "PHY ERR",
8471395d3f0SSujith 			sc->debug.stats.rxstats.phy_err);
8481395d3f0SSujith 	len += snprintf(buf + len, size - len,
8491395d3f0SSujith 			"%18s : %10u\n", "MIC ERR",
8501395d3f0SSujith 			sc->debug.stats.rxstats.mic_err);
8511395d3f0SSujith 	len += snprintf(buf + len, size - len,
8521395d3f0SSujith 			"%18s : %10u\n", "PRE-DELIM CRC ERR",
8531395d3f0SSujith 			sc->debug.stats.rxstats.pre_delim_crc_err);
8541395d3f0SSujith 	len += snprintf(buf + len, size - len,
8551395d3f0SSujith 			"%18s : %10u\n", "POST-DELIM CRC ERR",
8561395d3f0SSujith 			sc->debug.stats.rxstats.post_delim_crc_err);
8571395d3f0SSujith 	len += snprintf(buf + len, size - len,
8581395d3f0SSujith 			"%18s : %10u\n", "DECRYPT BUSY ERR",
8591395d3f0SSujith 			sc->debug.stats.rxstats.decrypt_busy_err);
8601395d3f0SSujith 
8611395d3f0SSujith 	PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN);
8621395d3f0SSujith 	PHY_ERR("TIMING", ATH9K_PHYERR_TIMING);
8631395d3f0SSujith 	PHY_ERR("PARITY", ATH9K_PHYERR_PARITY);
8641395d3f0SSujith 	PHY_ERR("RATE", ATH9K_PHYERR_RATE);
8651395d3f0SSujith 	PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH);
8661395d3f0SSujith 	PHY_ERR("RADAR", ATH9K_PHYERR_RADAR);
8671395d3f0SSujith 	PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE);
8681395d3f0SSujith 	PHY_ERR("TOR", ATH9K_PHYERR_TOR);
8691395d3f0SSujith 	PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING);
8701395d3f0SSujith 	PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
8711395d3f0SSujith 	PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
8721395d3f0SSujith 	PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
8731395d3f0SSujith 	PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP);
8741395d3f0SSujith 	PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE);
8751395d3f0SSujith 	PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART);
8761395d3f0SSujith 	PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT);
8771395d3f0SSujith 	PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING);
8781395d3f0SSujith 	PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC);
8791395d3f0SSujith 	PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
8801395d3f0SSujith 	PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE);
8811395d3f0SSujith 	PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART);
8821395d3f0SSujith 	PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
8831395d3f0SSujith 	PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP);
8841395d3f0SSujith 	PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR);
8851395d3f0SSujith 	PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
8861395d3f0SSujith 	PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL);
8871395d3f0SSujith 
88899c15bf5SBen Greear 	len += snprintf(buf + len, size - len,
88999c15bf5SBen Greear 			"%18s : %10u\n", "RX-Pkts-All",
89099c15bf5SBen Greear 			sc->debug.stats.rxstats.rx_pkts_all);
89199c15bf5SBen Greear 	len += snprintf(buf + len, size - len,
89299c15bf5SBen Greear 			"%18s : %10u\n", "RX-Bytes-All",
89399c15bf5SBen Greear 			sc->debug.stats.rxstats.rx_bytes_all);
89499c15bf5SBen Greear 
8952b87f3aaSDan Carpenter 	if (len > size)
8962b87f3aaSDan Carpenter 		len = size;
8972b87f3aaSDan Carpenter 
8981395d3f0SSujith 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
8991395d3f0SSujith 	kfree(buf);
9001395d3f0SSujith 
9011395d3f0SSujith 	return retval;
9021395d3f0SSujith 
9031395d3f0SSujith #undef PHY_ERR
9041395d3f0SSujith }
9051395d3f0SSujith 
9068e6f5aa2SFelix Fietkau void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
9071395d3f0SSujith {
9081395d3f0SSujith #define RX_STAT_INC(c) sc->debug.stats.rxstats.c++
9091395d3f0SSujith #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
9101395d3f0SSujith 
9111395d3f0SSujith 	u32 phyerr;
9121395d3f0SSujith 
91399c15bf5SBen Greear 	RX_STAT_INC(rx_pkts_all);
91499c15bf5SBen Greear 	sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
91599c15bf5SBen Greear 
9168e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_CRC)
9171395d3f0SSujith 		RX_STAT_INC(crc_err);
9188e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_DECRYPT)
9191395d3f0SSujith 		RX_STAT_INC(decrypt_crc_err);
9208e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_MIC)
9211395d3f0SSujith 		RX_STAT_INC(mic_err);
9228e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
9231395d3f0SSujith 		RX_STAT_INC(pre_delim_crc_err);
9248e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
9251395d3f0SSujith 		RX_STAT_INC(post_delim_crc_err);
9268e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
9271395d3f0SSujith 		RX_STAT_INC(decrypt_busy_err);
9281395d3f0SSujith 
9298e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_PHY) {
9301395d3f0SSujith 		RX_STAT_INC(phy_err);
9318e6f5aa2SFelix Fietkau 		phyerr = rs->rs_phyerr & 0x24;
9321395d3f0SSujith 		RX_PHY_ERR_INC(phyerr);
9331395d3f0SSujith 	}
9341395d3f0SSujith 
9351395d3f0SSujith #undef RX_STAT_INC
9361395d3f0SSujith #undef RX_PHY_ERR_INC
9371395d3f0SSujith }
9381395d3f0SSujith 
9391395d3f0SSujith static const struct file_operations fops_recv = {
9401395d3f0SSujith 	.read = read_file_recv,
9411395d3f0SSujith 	.open = ath9k_debugfs_open,
9426038f373SArnd Bergmann 	.owner = THIS_MODULE,
9436038f373SArnd Bergmann 	.llseek = default_llseek,
9441395d3f0SSujith };
9451395d3f0SSujith 
9469bff0bc4SFelix Fietkau static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
9479bff0bc4SFelix Fietkau                                 size_t count, loff_t *ppos)
9489bff0bc4SFelix Fietkau {
9499bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
9509bff0bc4SFelix Fietkau 	char buf[32];
9519bff0bc4SFelix Fietkau 	unsigned int len;
9529bff0bc4SFelix Fietkau 
9532b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
9549bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
9559bff0bc4SFelix Fietkau }
9569bff0bc4SFelix Fietkau 
9579bff0bc4SFelix Fietkau static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
9589bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
9599bff0bc4SFelix Fietkau {
9609bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
9619bff0bc4SFelix Fietkau 	unsigned long regidx;
9629bff0bc4SFelix Fietkau 	char buf[32];
9639bff0bc4SFelix Fietkau 	ssize_t len;
9649bff0bc4SFelix Fietkau 
9659bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
9669bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
96704236066SDan Carpenter 		return -EFAULT;
9689bff0bc4SFelix Fietkau 
9699bff0bc4SFelix Fietkau 	buf[len] = '\0';
9709bff0bc4SFelix Fietkau 	if (strict_strtoul(buf, 0, &regidx))
9719bff0bc4SFelix Fietkau 		return -EINVAL;
9729bff0bc4SFelix Fietkau 
9739bff0bc4SFelix Fietkau 	sc->debug.regidx = regidx;
9749bff0bc4SFelix Fietkau 	return count;
9759bff0bc4SFelix Fietkau }
9769bff0bc4SFelix Fietkau 
9779bff0bc4SFelix Fietkau static const struct file_operations fops_regidx = {
9789bff0bc4SFelix Fietkau 	.read = read_file_regidx,
9799bff0bc4SFelix Fietkau 	.write = write_file_regidx,
9809bff0bc4SFelix Fietkau 	.open = ath9k_debugfs_open,
9816038f373SArnd Bergmann 	.owner = THIS_MODULE,
9826038f373SArnd Bergmann 	.llseek = default_llseek,
9839bff0bc4SFelix Fietkau };
9849bff0bc4SFelix Fietkau 
9859bff0bc4SFelix Fietkau static ssize_t read_file_regval(struct file *file, char __user *user_buf,
9869bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
9879bff0bc4SFelix Fietkau {
9889bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
9899bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
9909bff0bc4SFelix Fietkau 	char buf[32];
9919bff0bc4SFelix Fietkau 	unsigned int len;
9929bff0bc4SFelix Fietkau 	u32 regval;
9939bff0bc4SFelix Fietkau 
9949bff0bc4SFelix Fietkau 	regval = REG_READ_D(ah, sc->debug.regidx);
9952b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", regval);
9969bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
9979bff0bc4SFelix Fietkau }
9989bff0bc4SFelix Fietkau 
9999bff0bc4SFelix Fietkau static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
10009bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
10019bff0bc4SFelix Fietkau {
10029bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
10039bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
10049bff0bc4SFelix Fietkau 	unsigned long regval;
10059bff0bc4SFelix Fietkau 	char buf[32];
10069bff0bc4SFelix Fietkau 	ssize_t len;
10079bff0bc4SFelix Fietkau 
10089bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
10099bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
101004236066SDan Carpenter 		return -EFAULT;
10119bff0bc4SFelix Fietkau 
10129bff0bc4SFelix Fietkau 	buf[len] = '\0';
10139bff0bc4SFelix Fietkau 	if (strict_strtoul(buf, 0, &regval))
10149bff0bc4SFelix Fietkau 		return -EINVAL;
10159bff0bc4SFelix Fietkau 
10169bff0bc4SFelix Fietkau 	REG_WRITE_D(ah, sc->debug.regidx, regval);
10179bff0bc4SFelix Fietkau 	return count;
10189bff0bc4SFelix Fietkau }
10199bff0bc4SFelix Fietkau 
10209bff0bc4SFelix Fietkau static const struct file_operations fops_regval = {
10219bff0bc4SFelix Fietkau 	.read = read_file_regval,
10229bff0bc4SFelix Fietkau 	.write = write_file_regval,
10239bff0bc4SFelix Fietkau 	.open = ath9k_debugfs_open,
10246038f373SArnd Bergmann 	.owner = THIS_MODULE,
10256038f373SArnd Bergmann 	.llseek = default_llseek,
10269bff0bc4SFelix Fietkau };
10279bff0bc4SFelix Fietkau 
10284d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah)
1029203c4805SLuis R. Rodriguez {
1030bc974f4aSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(ah);
1031bc974f4aSLuis R. Rodriguez 	struct ath_softc *sc = (struct ath_softc *) common->priv;
10324d6b228dSLuis R. Rodriguez 
1033eb272441SBen Greear 	sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1034eb272441SBen Greear 						   sc->hw->wiphy->debugfsdir);
1035203c4805SLuis R. Rodriguez 	if (!sc->debug.debugfs_phy)
1036c8a72c00SFelix Fietkau 		return -ENOMEM;
1037203c4805SLuis R. Rodriguez 
1038a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
1039c8a72c00SFelix Fietkau 	if (!debugfs_create_file("debug", S_IRUSR | S_IWUSR,
1040c8a72c00SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_debug))
10412493928eSJeff Hansen 		goto err;
1042a830df07SFelix Fietkau #endif
10432493928eSJeff Hansen 
1044c8a72c00SFelix Fietkau 	if (!debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy,
1045c8a72c00SFelix Fietkau 			sc, &fops_dma))
1046203c4805SLuis R. Rodriguez 		goto err;
1047203c4805SLuis R. Rodriguez 
1048c8a72c00SFelix Fietkau 	if (!debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy,
1049c8a72c00SFelix Fietkau 			sc, &fops_interrupt))
1050203c4805SLuis R. Rodriguez 		goto err;
1051203c4805SLuis R. Rodriguez 
1052c8a72c00SFelix Fietkau 	if (!debugfs_create_file("wiphy", S_IRUSR | S_IWUSR,
1053c8a72c00SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_wiphy))
1054203c4805SLuis R. Rodriguez 		goto err;
1055203c4805SLuis R. Rodriguez 
1056c8a72c00SFelix Fietkau 	if (!debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy,
1057c8a72c00SFelix Fietkau 			sc, &fops_xmit))
1058fec247c0SSujith 		goto err;
1059fec247c0SSujith 
10607f010c93SBen Greear 	if (!debugfs_create_file("stations", S_IRUSR, sc->debug.debugfs_phy,
10617f010c93SBen Greear 			sc, &fops_stations))
10627f010c93SBen Greear 		goto err;
10637f010c93SBen Greear 
1064c8a72c00SFelix Fietkau 	if (!debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy,
1065c8a72c00SFelix Fietkau 			sc, &fops_recv))
10661395d3f0SSujith 		goto err;
10671395d3f0SSujith 
106815340694SFelix Fietkau 	if (!debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
106915340694SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_rx_chainmask))
107015340694SFelix Fietkau 		goto err;
107115340694SFelix Fietkau 
107215340694SFelix Fietkau 	if (!debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
107315340694SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_tx_chainmask))
107415340694SFelix Fietkau 		goto err;
107515340694SFelix Fietkau 
10769bff0bc4SFelix Fietkau 	if (!debugfs_create_file("regidx", S_IRUSR | S_IWUSR,
10779bff0bc4SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_regidx))
10789bff0bc4SFelix Fietkau 		goto err;
10799bff0bc4SFelix Fietkau 
10809bff0bc4SFelix Fietkau 	if (!debugfs_create_file("regval", S_IRUSR | S_IWUSR,
10819bff0bc4SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_regval))
10829bff0bc4SFelix Fietkau 		goto err;
10839bff0bc4SFelix Fietkau 
108441f3e54dSFelix Fietkau 	if (!debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
108541f3e54dSFelix Fietkau 			sc->debug.debugfs_phy, &ah->config.cwm_ignore_extcca))
108641f3e54dSFelix Fietkau 		goto err;
108741f3e54dSFelix Fietkau 
10889bff0bc4SFelix Fietkau 	sc->debug.regidx = 0;
1089203c4805SLuis R. Rodriguez 	return 0;
1090203c4805SLuis R. Rodriguez err:
1091c8a72c00SFelix Fietkau 	debugfs_remove_recursive(sc->debug.debugfs_phy);
1092eb272441SBen Greear 	sc->debug.debugfs_phy = NULL;
1093eb272441SBen Greear 	return -ENOMEM;
1094203c4805SLuis R. Rodriguez }
1095