xref: /linux/drivers/net/wireless/ath/ath9k/debug.c (revision 4e6975f7b8ca31febaa94a1ee1acfb5322f8a82b)
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 
384*4e6975f7SBen Greear static const char *channel_type_str(enum nl80211_channel_type t)
385*4e6975f7SBen Greear {
386*4e6975f7SBen Greear 	switch (t) {
387*4e6975f7SBen Greear 	case NL80211_CHAN_NO_HT:
388*4e6975f7SBen Greear 		return "no ht";
389*4e6975f7SBen Greear 	case NL80211_CHAN_HT20:
390*4e6975f7SBen Greear 		return "ht20";
391*4e6975f7SBen Greear 	case NL80211_CHAN_HT40MINUS:
392*4e6975f7SBen Greear 		return "ht40-";
393*4e6975f7SBen Greear 	case NL80211_CHAN_HT40PLUS:
394*4e6975f7SBen Greear 		return "ht40+";
395*4e6975f7SBen Greear 	default:
396*4e6975f7SBen Greear 		return "???";
397*4e6975f7SBen Greear 	}
398*4e6975f7SBen Greear }
399*4e6975f7SBen Greear 
400203c4805SLuis R. Rodriguez static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
401203c4805SLuis R. Rodriguez 			       size_t count, loff_t *ppos)
402203c4805SLuis R. Rodriguez {
403203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
40434302397SFelix Fietkau 	struct ieee80211_channel *chan = sc->hw->conf.channel;
405*4e6975f7SBen Greear 	struct ieee80211_conf *conf = &(sc->hw->conf);
406203c4805SLuis R. Rodriguez 	char buf[512];
407203c4805SLuis R. Rodriguez 	unsigned int len = 0;
408203c4805SLuis R. Rodriguez 	u8 addr[ETH_ALEN];
40939057512SBen Greear 	u32 tmp;
410203c4805SLuis R. Rodriguez 
411203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
412*4e6975f7SBen Greear 			"%s (chan=%d  center-freq: %d MHz  channel-type: %d (%s))\n",
41334302397SFelix Fietkau 			wiphy_name(sc->hw->wiphy),
4148e0167a4SMohammed Shafi Shajakhan 			ieee80211_frequency_to_channel(chan->center_freq),
415*4e6975f7SBen Greear 			chan->center_freq,
416*4e6975f7SBen Greear 			conf->channel_type,
417*4e6975f7SBen Greear 			channel_type_str(conf->channel_type));
418203c4805SLuis R. Rodriguez 
419475a6e4dSLuis R. Rodriguez 	put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr);
420475a6e4dSLuis R. Rodriguez 	put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
421203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
422203c4805SLuis R. Rodriguez 			"addr: %pM\n", addr);
423475a6e4dSLuis R. Rodriguez 	put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr);
424475a6e4dSLuis R. Rodriguez 	put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
425203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
426203c4805SLuis R. Rodriguez 			"addrmask: %pM\n", addr);
42739057512SBen Greear 	tmp = ath9k_hw_getrxfilter(sc->sc_ah);
42839057512SBen Greear 	len += snprintf(buf + len, sizeof(buf) - len,
42939057512SBen Greear 			"rfilt: 0x%x", tmp);
43039057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_UCAST)
43139057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " UCAST");
43239057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_MCAST)
43339057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " MCAST");
43439057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_BCAST)
43539057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " BCAST");
43639057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_CONTROL)
43739057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " CONTROL");
43839057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_BEACON)
43939057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " BEACON");
44039057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_PROM)
44139057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " PROM");
44239057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_PROBEREQ)
44339057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
44439057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_PHYERR)
44539057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " PHYERR");
44639057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_MYBEACON)
44739057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " MYBEACON");
44839057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_COMP_BAR)
44939057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
45039057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_PSPOLL)
45139057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " PSPOLL");
45239057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_PHYRADAR)
45339057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
45439057512SBen Greear 	if (tmp & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
45539057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL\n");
45639057512SBen Greear 	else
45739057512SBen Greear 		len += snprintf(buf + len, sizeof(buf) - len, "\n");
458203c4805SLuis R. Rodriguez 
4592b87f3aaSDan Carpenter 	if (len > sizeof(buf))
4602b87f3aaSDan Carpenter 		len = sizeof(buf);
4612b87f3aaSDan Carpenter 
462203c4805SLuis R. Rodriguez 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
463203c4805SLuis R. Rodriguez }
464203c4805SLuis R. Rodriguez 
465203c4805SLuis R. Rodriguez static const struct file_operations fops_wiphy = {
466203c4805SLuis R. Rodriguez 	.read = read_file_wiphy,
467203c4805SLuis R. Rodriguez 	.open = ath9k_debugfs_open,
4686038f373SArnd Bergmann 	.owner = THIS_MODULE,
4696038f373SArnd Bergmann 	.llseek = default_llseek,
470203c4805SLuis R. Rodriguez };
471203c4805SLuis R. Rodriguez 
4725bec3e5aSFelix Fietkau #define PR_QNUM(_n) sc->tx.txq_map[_n]->axq_qnum
473fec247c0SSujith #define PR(str, elem)							\
474fec247c0SSujith 	do {								\
475fec247c0SSujith 		len += snprintf(buf + len, size - len,			\
476fec247c0SSujith 				"%s%13u%11u%10u%10u\n", str,		\
4775bec3e5aSFelix Fietkau 		sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].elem, \
4785bec3e5aSFelix Fietkau 		sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].elem, \
4795bec3e5aSFelix Fietkau 		sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].elem, \
4805bec3e5aSFelix Fietkau 		sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].elem); \
4817f010c93SBen Greear 		if (len >= size)			  \
4827f010c93SBen Greear 			goto done;			  \
483fec247c0SSujith } while(0)
484fec247c0SSujith 
4851f427dd9SBen Greear #define PRX(str, elem)							\
4861f427dd9SBen Greear do {									\
4871f427dd9SBen Greear 	len += snprintf(buf + len, size - len,				\
4881f427dd9SBen Greear 			"%s%13u%11u%10u%10u\n", str,			\
4895bec3e5aSFelix Fietkau 			(unsigned int)(sc->tx.txq_map[WME_AC_BE]->elem),	\
4905bec3e5aSFelix Fietkau 			(unsigned int)(sc->tx.txq_map[WME_AC_BK]->elem),	\
4915bec3e5aSFelix Fietkau 			(unsigned int)(sc->tx.txq_map[WME_AC_VI]->elem),	\
4925bec3e5aSFelix Fietkau 			(unsigned int)(sc->tx.txq_map[WME_AC_VO]->elem));	\
4937f010c93SBen Greear 	if (len >= size)						\
4947f010c93SBen Greear 		goto done;						\
4951f427dd9SBen Greear } while(0)
4961f427dd9SBen Greear 
4972dac4fb9SBen Greear #define PRQLE(str, elem)						\
4982dac4fb9SBen Greear do {									\
4992dac4fb9SBen Greear 	len += snprintf(buf + len, size - len,				\
5002dac4fb9SBen Greear 			"%s%13i%11i%10i%10i\n", str,			\
5015bec3e5aSFelix Fietkau 			list_empty(&sc->tx.txq_map[WME_AC_BE]->elem),	\
5025bec3e5aSFelix Fietkau 			list_empty(&sc->tx.txq_map[WME_AC_BK]->elem),	\
5035bec3e5aSFelix Fietkau 			list_empty(&sc->tx.txq_map[WME_AC_VI]->elem),	\
5045bec3e5aSFelix Fietkau 			list_empty(&sc->tx.txq_map[WME_AC_VO]->elem));	\
5057f010c93SBen Greear 	if (len >= size)						\
5067f010c93SBen Greear 		goto done;						\
5072dac4fb9SBen Greear } while (0)
5082dac4fb9SBen Greear 
509fec247c0SSujith static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
510fec247c0SSujith 			      size_t count, loff_t *ppos)
511fec247c0SSujith {
512fec247c0SSujith 	struct ath_softc *sc = file->private_data;
513fec247c0SSujith 	char *buf;
5147f010c93SBen Greear 	unsigned int len = 0, size = 8000;
5152dac4fb9SBen Greear 	int i;
516fec247c0SSujith 	ssize_t retval = 0;
5172dac4fb9SBen Greear 	char tmp[32];
518fec247c0SSujith 
519fec247c0SSujith 	buf = kzalloc(size, GFP_KERNEL);
520fec247c0SSujith 	if (buf == NULL)
52104236066SDan Carpenter 		return -ENOMEM;
522fec247c0SSujith 
52360f2d1d5SBen Greear 	len += sprintf(buf, "Num-Tx-Queues: %i  tx-queues-setup: 0x%x"
52460f2d1d5SBen Greear 		       " poll-work-seen: %u\n"
5257f010c93SBen Greear 		       "%30s %10s%10s%10s\n\n",
5267f010c93SBen Greear 		       ATH9K_NUM_TX_QUEUES, sc->tx.txqsetup,
52760f2d1d5SBen Greear 		       sc->tx_complete_poll_work_seen,
5287f010c93SBen Greear 		       "BE", "BK", "VI", "VO");
529fec247c0SSujith 
530fec247c0SSujith 	PR("MPDUs Queued:    ", queued);
531fec247c0SSujith 	PR("MPDUs Completed: ", completed);
532fec247c0SSujith 	PR("Aggregates:      ", a_aggr);
533bda8addaSBen Greear 	PR("AMPDUs Queued HW:", a_queued_hw);
534bda8addaSBen Greear 	PR("AMPDUs Queued SW:", a_queued_sw);
535fec247c0SSujith 	PR("AMPDUs Completed:", a_completed);
536fec247c0SSujith 	PR("AMPDUs Retried:  ", a_retries);
537fec247c0SSujith 	PR("AMPDUs XRetried: ", a_xretries);
538fec247c0SSujith 	PR("FIFO Underrun:   ", fifo_underrun);
539fec247c0SSujith 	PR("TXOP Exceeded:   ", xtxop);
540fec247c0SSujith 	PR("TXTIMER Expiry:  ", timer_exp);
541fec247c0SSujith 	PR("DESC CFG Error:  ", desc_cfg_err);
542fec247c0SSujith 	PR("DATA Underrun:   ", data_underrun);
543fec247c0SSujith 	PR("DELIM Underrun:  ", delim_underrun);
54499c15bf5SBen Greear 	PR("TX-Pkts-All:     ", tx_pkts_all);
54599c15bf5SBen Greear 	PR("TX-Bytes-All:    ", tx_bytes_all);
5462dac4fb9SBen Greear 	PR("hw-put-tx-buf:   ", puttxbuf);
5472dac4fb9SBen Greear 	PR("hw-tx-start:     ", txstart);
5482dac4fb9SBen Greear 	PR("hw-tx-proc-desc: ", txprocdesc);
5497f010c93SBen Greear 	len += snprintf(buf + len, size - len,
5507f010c93SBen Greear 			"%s%11p%11p%10p%10p\n", "txq-memory-address:",
5515bec3e5aSFelix Fietkau 			&(sc->tx.txq_map[WME_AC_BE]),
5525bec3e5aSFelix Fietkau 			&(sc->tx.txq_map[WME_AC_BK]),
5535bec3e5aSFelix Fietkau 			&(sc->tx.txq_map[WME_AC_VI]),
5545bec3e5aSFelix Fietkau 			&(sc->tx.txq_map[WME_AC_VO]));
5557f010c93SBen Greear 	if (len >= size)
5567f010c93SBen Greear 		goto done;
557fec247c0SSujith 
5581f427dd9SBen Greear 	PRX("axq-qnum:        ", axq_qnum);
5591f427dd9SBen Greear 	PRX("axq-depth:       ", axq_depth);
5602dac4fb9SBen Greear 	PRX("axq-ampdu_depth: ", axq_ampdu_depth);
5611f427dd9SBen Greear 	PRX("axq-stopped      ", stopped);
5621f427dd9SBen Greear 	PRX("tx-in-progress   ", axq_tx_inprogress);
5631f427dd9SBen Greear 	PRX("pending-frames   ", pending_frames);
5642dac4fb9SBen Greear 	PRX("txq_headidx:     ", txq_headidx);
5652dac4fb9SBen Greear 	PRX("txq_tailidx:     ", txq_headidx);
5661f427dd9SBen Greear 
5672dac4fb9SBen Greear 	PRQLE("axq_q empty:       ", axq_q);
5682dac4fb9SBen Greear 	PRQLE("axq_acq empty:     ", axq_acq);
5692dac4fb9SBen Greear 	PRQLE("txq_fifo_pending:  ", txq_fifo_pending);
5702dac4fb9SBen Greear 	for (i = 0; i < ATH_TXFIFO_DEPTH; i++) {
5712dac4fb9SBen Greear 		snprintf(tmp, sizeof(tmp) - 1, "txq_fifo[%i] empty: ", i);
5722dac4fb9SBen Greear 		PRQLE(tmp, txq_fifo[i]);
5732dac4fb9SBen Greear 	}
5747f010c93SBen Greear 
57571e025a5SBen Greear 	/* Print out more detailed queue-info */
57671e025a5SBen Greear 	for (i = 0; i <= WME_AC_BK; i++) {
57771e025a5SBen Greear 		struct ath_txq *txq = &(sc->tx.txq[i]);
57871e025a5SBen Greear 		struct ath_atx_ac *ac;
57971e025a5SBen Greear 		struct ath_atx_tid *tid;
58071e025a5SBen Greear 		if (len >= size)
58171e025a5SBen Greear 			goto done;
58271e025a5SBen Greear 		spin_lock_bh(&txq->axq_lock);
58371e025a5SBen Greear 		if (!list_empty(&txq->axq_acq)) {
58471e025a5SBen Greear 			ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac,
58571e025a5SBen Greear 					      list);
58671e025a5SBen Greear 			len += snprintf(buf + len, size - len,
58771e025a5SBen Greear 					"txq[%i] first-ac: %p sched: %i\n",
58871e025a5SBen Greear 					i, ac, ac->sched);
58971e025a5SBen Greear 			if (list_empty(&ac->tid_q) || (len >= size))
59071e025a5SBen Greear 				goto done_for;
59171e025a5SBen Greear 			tid = list_first_entry(&ac->tid_q, struct ath_atx_tid,
59271e025a5SBen Greear 					       list);
59371e025a5SBen Greear 			len += snprintf(buf + len, size - len,
59471e025a5SBen Greear 					" first-tid: %p sched: %i paused: %i\n",
59571e025a5SBen Greear 					tid, tid->sched, tid->paused);
59671e025a5SBen Greear 		}
59771e025a5SBen Greear 	done_for:
59871e025a5SBen Greear 		spin_unlock_bh(&txq->axq_lock);
59971e025a5SBen Greear 	}
60071e025a5SBen Greear 
6017f010c93SBen Greear done:
6027f010c93SBen Greear 	if (len > size)
6037f010c93SBen Greear 		len = size;
6047f010c93SBen Greear 
6057f010c93SBen Greear 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
6067f010c93SBen Greear 	kfree(buf);
6077f010c93SBen Greear 
6087f010c93SBen Greear 	return retval;
6097f010c93SBen Greear }
6107f010c93SBen Greear 
6117f010c93SBen Greear static ssize_t read_file_stations(struct file *file, char __user *user_buf,
6127f010c93SBen Greear 				  size_t count, loff_t *ppos)
6137f010c93SBen Greear {
6147f010c93SBen Greear 	struct ath_softc *sc = file->private_data;
6157f010c93SBen Greear 	char *buf;
6167f010c93SBen Greear 	unsigned int len = 0, size = 64000;
6177f010c93SBen Greear 	struct ath_node *an = NULL;
6187f010c93SBen Greear 	ssize_t retval = 0;
6197f010c93SBen Greear 	int q;
6207f010c93SBen Greear 
6217f010c93SBen Greear 	buf = kzalloc(size, GFP_KERNEL);
6227f010c93SBen Greear 	if (buf == NULL)
6237f010c93SBen Greear 		return -ENOMEM;
6247f010c93SBen Greear 
6257f010c93SBen Greear 	len += snprintf(buf + len, size - len,
6267f010c93SBen Greear 			"Stations:\n"
6277f010c93SBen Greear 			" tid: addr sched paused buf_q-empty an ac\n"
6287f010c93SBen Greear 			" ac: addr sched tid_q-empty txq\n");
6297f010c93SBen Greear 
6307f010c93SBen Greear 	spin_lock(&sc->nodes_lock);
6317f010c93SBen Greear 	list_for_each_entry(an, &sc->nodes, list) {
6327f010c93SBen Greear 		len += snprintf(buf + len, size - len,
6337f010c93SBen Greear 				"%pM\n", an->sta->addr);
6347f010c93SBen Greear 		if (len >= size)
6357f010c93SBen Greear 			goto done;
6367f010c93SBen Greear 
6377f010c93SBen Greear 		for (q = 0; q < WME_NUM_TID; q++) {
6387f010c93SBen Greear 			struct ath_atx_tid *tid = &(an->tid[q]);
6397f010c93SBen Greear 			len += snprintf(buf + len, size - len,
6407f010c93SBen Greear 					" tid: %p %s %s %i %p %p\n",
6417f010c93SBen Greear 					tid, tid->sched ? "sched" : "idle",
6427f010c93SBen Greear 					tid->paused ? "paused" : "running",
6437f010c93SBen Greear 					list_empty(&tid->buf_q),
6447f010c93SBen Greear 					tid->an, tid->ac);
6457f010c93SBen Greear 			if (len >= size)
6467f010c93SBen Greear 				goto done;
6477f010c93SBen Greear 		}
6487f010c93SBen Greear 
6497f010c93SBen Greear 		for (q = 0; q < WME_NUM_AC; q++) {
6507f010c93SBen Greear 			struct ath_atx_ac *ac = &(an->ac[q]);
6517f010c93SBen Greear 			len += snprintf(buf + len, size - len,
6527f010c93SBen Greear 					" ac: %p %s %i %p\n",
6537f010c93SBen Greear 					ac, ac->sched ? "sched" : "idle",
6547f010c93SBen Greear 					list_empty(&ac->tid_q), ac->txq);
6557f010c93SBen Greear 			if (len >= size)
6567f010c93SBen Greear 				goto done;
6577f010c93SBen Greear 		}
6587f010c93SBen Greear 	}
6597f010c93SBen Greear 
6607f010c93SBen Greear done:
6617f010c93SBen Greear 	spin_unlock(&sc->nodes_lock);
6622b87f3aaSDan Carpenter 	if (len > size)
6632b87f3aaSDan Carpenter 		len = size;
6642b87f3aaSDan Carpenter 
665fec247c0SSujith 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
666fec247c0SSujith 	kfree(buf);
667fec247c0SSujith 
668fec247c0SSujith 	return retval;
669fec247c0SSujith }
670fec247c0SSujith 
67155f6d0ffSBen Greear static ssize_t read_file_misc(struct file *file, char __user *user_buf,
67255f6d0ffSBen Greear 			      size_t count, loff_t *ppos)
67355f6d0ffSBen Greear {
67455f6d0ffSBen Greear 	struct ath_softc *sc = file->private_data;
67555f6d0ffSBen Greear 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
67655f6d0ffSBen Greear 	struct ath_hw *ah = sc->sc_ah;
67755f6d0ffSBen Greear 	struct ieee80211_hw *hw = sc->hw;
67855f6d0ffSBen Greear 	char *buf;
67955f6d0ffSBen Greear 	unsigned int len = 0, size = 8000;
68055f6d0ffSBen Greear 	ssize_t retval = 0;
68155f6d0ffSBen Greear 	const char *tmp;
68255f6d0ffSBen Greear 	unsigned int reg;
68355f6d0ffSBen Greear 	struct ath9k_vif_iter_data iter_data;
68455f6d0ffSBen Greear 
68555f6d0ffSBen Greear 	ath9k_calculate_iter_data(hw, NULL, &iter_data);
68655f6d0ffSBen Greear 
68755f6d0ffSBen Greear 	buf = kzalloc(size, GFP_KERNEL);
68855f6d0ffSBen Greear 	if (buf == NULL)
68955f6d0ffSBen Greear 		return -ENOMEM;
69055f6d0ffSBen Greear 
69155f6d0ffSBen Greear 	switch (sc->sc_ah->opmode) {
69255f6d0ffSBen Greear 	case  NL80211_IFTYPE_ADHOC:
69355f6d0ffSBen Greear 		tmp = "ADHOC";
69455f6d0ffSBen Greear 		break;
69555f6d0ffSBen Greear 	case  NL80211_IFTYPE_MESH_POINT:
69655f6d0ffSBen Greear 		tmp = "MESH";
69755f6d0ffSBen Greear 		break;
69855f6d0ffSBen Greear 	case  NL80211_IFTYPE_AP:
69955f6d0ffSBen Greear 		tmp = "AP";
70055f6d0ffSBen Greear 		break;
70155f6d0ffSBen Greear 	case  NL80211_IFTYPE_STATION:
70255f6d0ffSBen Greear 		tmp = "STATION";
70355f6d0ffSBen Greear 		break;
70455f6d0ffSBen Greear 	default:
70555f6d0ffSBen Greear 		tmp = "???";
70655f6d0ffSBen Greear 		break;
70755f6d0ffSBen Greear 	}
70855f6d0ffSBen Greear 
70955f6d0ffSBen Greear 	len += snprintf(buf + len, size - len,
71055f6d0ffSBen Greear 			"curbssid: %pM\n"
71155f6d0ffSBen Greear 			"OP-Mode: %s(%i)\n"
71255f6d0ffSBen Greear 			"Beacon-Timer-Register: 0x%x\n",
71355f6d0ffSBen Greear 			common->curbssid,
71455f6d0ffSBen Greear 			tmp, (int)(sc->sc_ah->opmode),
71555f6d0ffSBen Greear 			REG_READ(ah, AR_BEACON_PERIOD));
71655f6d0ffSBen Greear 
71755f6d0ffSBen Greear 	reg = REG_READ(ah, AR_TIMER_MODE);
71855f6d0ffSBen Greear 	len += snprintf(buf + len, size - len, "Timer-Mode-Register: 0x%x (",
71955f6d0ffSBen Greear 			reg);
72055f6d0ffSBen Greear 	if (reg & AR_TBTT_TIMER_EN)
72155f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "TBTT ");
72255f6d0ffSBen Greear 	if (reg & AR_DBA_TIMER_EN)
72355f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "DBA ");
72455f6d0ffSBen Greear 	if (reg & AR_SWBA_TIMER_EN)
72555f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "SWBA ");
72655f6d0ffSBen Greear 	if (reg & AR_HCF_TIMER_EN)
72755f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "HCF ");
72855f6d0ffSBen Greear 	if (reg & AR_TIM_TIMER_EN)
72955f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "TIM ");
73055f6d0ffSBen Greear 	if (reg & AR_DTIM_TIMER_EN)
73155f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "DTIM ");
73255f6d0ffSBen Greear 	len += snprintf(buf + len, size - len, ")\n");
73355f6d0ffSBen Greear 
73455f6d0ffSBen Greear 	reg = sc->sc_ah->imask;
73555f6d0ffSBen Greear 	len += snprintf(buf + len, size - len, "imask: 0x%x (", reg);
73655f6d0ffSBen Greear 	if (reg & ATH9K_INT_SWBA)
73755f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "SWBA ");
73855f6d0ffSBen Greear 	if (reg & ATH9K_INT_BMISS)
73955f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "BMISS ");
74055f6d0ffSBen Greear 	if (reg & ATH9K_INT_CST)
74155f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "CST ");
74255f6d0ffSBen Greear 	if (reg & ATH9K_INT_RX)
74355f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "RX ");
74455f6d0ffSBen Greear 	if (reg & ATH9K_INT_RXHP)
74555f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "RXHP ");
74655f6d0ffSBen Greear 	if (reg & ATH9K_INT_RXLP)
74755f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "RXLP ");
74855f6d0ffSBen Greear 	if (reg & ATH9K_INT_BB_WATCHDOG)
74955f6d0ffSBen Greear 		len += snprintf(buf + len, size - len, "BB_WATCHDOG ");
75055f6d0ffSBen Greear 	/* there are other IRQs if one wanted to add them. */
75155f6d0ffSBen Greear 	len += snprintf(buf + len, size - len, ")\n");
75255f6d0ffSBen Greear 
75355f6d0ffSBen Greear 	len += snprintf(buf + len, size - len,
75455f6d0ffSBen Greear 			"VIF Counts: AP: %i STA: %i MESH: %i WDS: %i"
75555f6d0ffSBen Greear 			" ADHOC: %i OTHER: %i nvifs: %hi beacon-vifs: %hi\n",
75655f6d0ffSBen Greear 			iter_data.naps, iter_data.nstations, iter_data.nmeshes,
75755f6d0ffSBen Greear 			iter_data.nwds, iter_data.nadhocs, iter_data.nothers,
75855f6d0ffSBen Greear 			sc->nvifs, sc->nbcnvifs);
75955f6d0ffSBen Greear 
76055f6d0ffSBen Greear 	len += snprintf(buf + len, size - len,
76155f6d0ffSBen Greear 			"Calculated-BSSID-Mask: %pM\n",
76255f6d0ffSBen Greear 			iter_data.mask);
76355f6d0ffSBen Greear 
76455f6d0ffSBen Greear 	if (len > size)
76555f6d0ffSBen Greear 		len = size;
76655f6d0ffSBen Greear 
76755f6d0ffSBen Greear 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
76855f6d0ffSBen Greear 	kfree(buf);
76955f6d0ffSBen Greear 
77055f6d0ffSBen Greear 	return retval;
77155f6d0ffSBen Greear }
77255f6d0ffSBen Greear 
773066dae93SFelix Fietkau void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
7745bec3e5aSFelix Fietkau 		       struct ath_tx_status *ts, struct ath_txq *txq)
775fec247c0SSujith {
7765bec3e5aSFelix Fietkau 	int qnum = txq->axq_qnum;
777066dae93SFelix Fietkau 
778066dae93SFelix Fietkau 	TX_STAT_INC(qnum, tx_pkts_all);
779066dae93SFelix Fietkau 	sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
78099c15bf5SBen Greear 
781fec247c0SSujith 	if (bf_isampdu(bf)) {
782fec247c0SSujith 		if (bf_isxretried(bf))
783066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_xretries);
784fec247c0SSujith 		else
785066dae93SFelix Fietkau 			TX_STAT_INC(qnum, a_completed);
786fec247c0SSujith 	} else {
787066dae93SFelix Fietkau 		TX_STAT_INC(qnum, completed);
788fec247c0SSujith 	}
789fec247c0SSujith 
790db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_FIFO)
791066dae93SFelix Fietkau 		TX_STAT_INC(qnum, fifo_underrun);
792db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_XTXOP)
793066dae93SFelix Fietkau 		TX_STAT_INC(qnum, xtxop);
794db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
795066dae93SFelix Fietkau 		TX_STAT_INC(qnum, timer_exp);
796db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
797066dae93SFelix Fietkau 		TX_STAT_INC(qnum, desc_cfg_err);
798db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
799066dae93SFelix Fietkau 		TX_STAT_INC(qnum, data_underrun);
800db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
801066dae93SFelix Fietkau 		TX_STAT_INC(qnum, delim_underrun);
802fec247c0SSujith }
803fec247c0SSujith 
804fec247c0SSujith static const struct file_operations fops_xmit = {
805fec247c0SSujith 	.read = read_file_xmit,
806fec247c0SSujith 	.open = ath9k_debugfs_open,
8076038f373SArnd Bergmann 	.owner = THIS_MODULE,
8086038f373SArnd Bergmann 	.llseek = default_llseek,
809fec247c0SSujith };
810203c4805SLuis R. Rodriguez 
8117f010c93SBen Greear static const struct file_operations fops_stations = {
8127f010c93SBen Greear 	.read = read_file_stations,
8137f010c93SBen Greear 	.open = ath9k_debugfs_open,
8147f010c93SBen Greear 	.owner = THIS_MODULE,
8157f010c93SBen Greear 	.llseek = default_llseek,
8167f010c93SBen Greear };
8177f010c93SBen Greear 
81855f6d0ffSBen Greear static const struct file_operations fops_misc = {
81955f6d0ffSBen Greear 	.read = read_file_misc,
82055f6d0ffSBen Greear 	.open = ath9k_debugfs_open,
82155f6d0ffSBen Greear 	.owner = THIS_MODULE,
82255f6d0ffSBen Greear 	.llseek = default_llseek,
82355f6d0ffSBen Greear };
82455f6d0ffSBen Greear 
8251395d3f0SSujith static ssize_t read_file_recv(struct file *file, char __user *user_buf,
8261395d3f0SSujith 			      size_t count, loff_t *ppos)
8271395d3f0SSujith {
8281395d3f0SSujith #define PHY_ERR(s, p) \
8291395d3f0SSujith 	len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \
8301395d3f0SSujith 			sc->debug.stats.rxstats.phy_err_stats[p]);
8311395d3f0SSujith 
8321395d3f0SSujith 	struct ath_softc *sc = file->private_data;
8331395d3f0SSujith 	char *buf;
8341395d3f0SSujith 	unsigned int len = 0, size = 1152;
8351395d3f0SSujith 	ssize_t retval = 0;
8361395d3f0SSujith 
8371395d3f0SSujith 	buf = kzalloc(size, GFP_KERNEL);
8381395d3f0SSujith 	if (buf == NULL)
83904236066SDan Carpenter 		return -ENOMEM;
8401395d3f0SSujith 
8411395d3f0SSujith 	len += snprintf(buf + len, size - len,
8421395d3f0SSujith 			"%18s : %10u\n", "CRC ERR",
8431395d3f0SSujith 			sc->debug.stats.rxstats.crc_err);
8441395d3f0SSujith 	len += snprintf(buf + len, size - len,
8451395d3f0SSujith 			"%18s : %10u\n", "DECRYPT CRC ERR",
8461395d3f0SSujith 			sc->debug.stats.rxstats.decrypt_crc_err);
8471395d3f0SSujith 	len += snprintf(buf + len, size - len,
8481395d3f0SSujith 			"%18s : %10u\n", "PHY ERR",
8491395d3f0SSujith 			sc->debug.stats.rxstats.phy_err);
8501395d3f0SSujith 	len += snprintf(buf + len, size - len,
8511395d3f0SSujith 			"%18s : %10u\n", "MIC ERR",
8521395d3f0SSujith 			sc->debug.stats.rxstats.mic_err);
8531395d3f0SSujith 	len += snprintf(buf + len, size - len,
8541395d3f0SSujith 			"%18s : %10u\n", "PRE-DELIM CRC ERR",
8551395d3f0SSujith 			sc->debug.stats.rxstats.pre_delim_crc_err);
8561395d3f0SSujith 	len += snprintf(buf + len, size - len,
8571395d3f0SSujith 			"%18s : %10u\n", "POST-DELIM CRC ERR",
8581395d3f0SSujith 			sc->debug.stats.rxstats.post_delim_crc_err);
8591395d3f0SSujith 	len += snprintf(buf + len, size - len,
8601395d3f0SSujith 			"%18s : %10u\n", "DECRYPT BUSY ERR",
8611395d3f0SSujith 			sc->debug.stats.rxstats.decrypt_busy_err);
8621395d3f0SSujith 
8631395d3f0SSujith 	PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN);
8641395d3f0SSujith 	PHY_ERR("TIMING", ATH9K_PHYERR_TIMING);
8651395d3f0SSujith 	PHY_ERR("PARITY", ATH9K_PHYERR_PARITY);
8661395d3f0SSujith 	PHY_ERR("RATE", ATH9K_PHYERR_RATE);
8671395d3f0SSujith 	PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH);
8681395d3f0SSujith 	PHY_ERR("RADAR", ATH9K_PHYERR_RADAR);
8691395d3f0SSujith 	PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE);
8701395d3f0SSujith 	PHY_ERR("TOR", ATH9K_PHYERR_TOR);
8711395d3f0SSujith 	PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING);
8721395d3f0SSujith 	PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
8731395d3f0SSujith 	PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
8741395d3f0SSujith 	PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
8751395d3f0SSujith 	PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP);
8761395d3f0SSujith 	PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE);
8771395d3f0SSujith 	PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART);
8781395d3f0SSujith 	PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT);
8791395d3f0SSujith 	PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING);
8801395d3f0SSujith 	PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC);
8811395d3f0SSujith 	PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
8821395d3f0SSujith 	PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE);
8831395d3f0SSujith 	PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART);
8841395d3f0SSujith 	PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
8851395d3f0SSujith 	PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP);
8861395d3f0SSujith 	PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR);
8871395d3f0SSujith 	PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
8881395d3f0SSujith 	PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL);
8891395d3f0SSujith 
89099c15bf5SBen Greear 	len += snprintf(buf + len, size - len,
89199c15bf5SBen Greear 			"%18s : %10u\n", "RX-Pkts-All",
89299c15bf5SBen Greear 			sc->debug.stats.rxstats.rx_pkts_all);
89399c15bf5SBen Greear 	len += snprintf(buf + len, size - len,
89499c15bf5SBen Greear 			"%18s : %10u\n", "RX-Bytes-All",
89599c15bf5SBen Greear 			sc->debug.stats.rxstats.rx_bytes_all);
89699c15bf5SBen Greear 
8972b87f3aaSDan Carpenter 	if (len > size)
8982b87f3aaSDan Carpenter 		len = size;
8992b87f3aaSDan Carpenter 
9001395d3f0SSujith 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
9011395d3f0SSujith 	kfree(buf);
9021395d3f0SSujith 
9031395d3f0SSujith 	return retval;
9041395d3f0SSujith 
9051395d3f0SSujith #undef PHY_ERR
9061395d3f0SSujith }
9071395d3f0SSujith 
9088e6f5aa2SFelix Fietkau void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
9091395d3f0SSujith {
9101395d3f0SSujith #define RX_STAT_INC(c) sc->debug.stats.rxstats.c++
9111395d3f0SSujith #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
9121395d3f0SSujith 
9131395d3f0SSujith 	u32 phyerr;
9141395d3f0SSujith 
91599c15bf5SBen Greear 	RX_STAT_INC(rx_pkts_all);
91699c15bf5SBen Greear 	sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
91799c15bf5SBen Greear 
9188e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_CRC)
9191395d3f0SSujith 		RX_STAT_INC(crc_err);
9208e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_DECRYPT)
9211395d3f0SSujith 		RX_STAT_INC(decrypt_crc_err);
9228e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_MIC)
9231395d3f0SSujith 		RX_STAT_INC(mic_err);
9248e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
9251395d3f0SSujith 		RX_STAT_INC(pre_delim_crc_err);
9268e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
9271395d3f0SSujith 		RX_STAT_INC(post_delim_crc_err);
9288e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
9291395d3f0SSujith 		RX_STAT_INC(decrypt_busy_err);
9301395d3f0SSujith 
9318e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_PHY) {
9321395d3f0SSujith 		RX_STAT_INC(phy_err);
9338e6f5aa2SFelix Fietkau 		phyerr = rs->rs_phyerr & 0x24;
9341395d3f0SSujith 		RX_PHY_ERR_INC(phyerr);
9351395d3f0SSujith 	}
9361395d3f0SSujith 
9371395d3f0SSujith #undef RX_STAT_INC
9381395d3f0SSujith #undef RX_PHY_ERR_INC
9391395d3f0SSujith }
9401395d3f0SSujith 
9411395d3f0SSujith static const struct file_operations fops_recv = {
9421395d3f0SSujith 	.read = read_file_recv,
9431395d3f0SSujith 	.open = ath9k_debugfs_open,
9446038f373SArnd Bergmann 	.owner = THIS_MODULE,
9456038f373SArnd Bergmann 	.llseek = default_llseek,
9461395d3f0SSujith };
9471395d3f0SSujith 
9489bff0bc4SFelix Fietkau static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
9499bff0bc4SFelix Fietkau                                 size_t count, loff_t *ppos)
9509bff0bc4SFelix Fietkau {
9519bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
9529bff0bc4SFelix Fietkau 	char buf[32];
9539bff0bc4SFelix Fietkau 	unsigned int len;
9549bff0bc4SFelix Fietkau 
9552b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
9569bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
9579bff0bc4SFelix Fietkau }
9589bff0bc4SFelix Fietkau 
9599bff0bc4SFelix Fietkau static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
9609bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
9619bff0bc4SFelix Fietkau {
9629bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
9639bff0bc4SFelix Fietkau 	unsigned long regidx;
9649bff0bc4SFelix Fietkau 	char buf[32];
9659bff0bc4SFelix Fietkau 	ssize_t len;
9669bff0bc4SFelix Fietkau 
9679bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
9689bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
96904236066SDan Carpenter 		return -EFAULT;
9709bff0bc4SFelix Fietkau 
9719bff0bc4SFelix Fietkau 	buf[len] = '\0';
9729bff0bc4SFelix Fietkau 	if (strict_strtoul(buf, 0, &regidx))
9739bff0bc4SFelix Fietkau 		return -EINVAL;
9749bff0bc4SFelix Fietkau 
9759bff0bc4SFelix Fietkau 	sc->debug.regidx = regidx;
9769bff0bc4SFelix Fietkau 	return count;
9779bff0bc4SFelix Fietkau }
9789bff0bc4SFelix Fietkau 
9799bff0bc4SFelix Fietkau static const struct file_operations fops_regidx = {
9809bff0bc4SFelix Fietkau 	.read = read_file_regidx,
9819bff0bc4SFelix Fietkau 	.write = write_file_regidx,
9829bff0bc4SFelix Fietkau 	.open = ath9k_debugfs_open,
9836038f373SArnd Bergmann 	.owner = THIS_MODULE,
9846038f373SArnd Bergmann 	.llseek = default_llseek,
9859bff0bc4SFelix Fietkau };
9869bff0bc4SFelix Fietkau 
9879bff0bc4SFelix Fietkau static ssize_t read_file_regval(struct file *file, char __user *user_buf,
9889bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
9899bff0bc4SFelix Fietkau {
9909bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
9919bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
9929bff0bc4SFelix Fietkau 	char buf[32];
9939bff0bc4SFelix Fietkau 	unsigned int len;
9949bff0bc4SFelix Fietkau 	u32 regval;
9959bff0bc4SFelix Fietkau 
9969bff0bc4SFelix Fietkau 	regval = REG_READ_D(ah, sc->debug.regidx);
9972b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", regval);
9989bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
9999bff0bc4SFelix Fietkau }
10009bff0bc4SFelix Fietkau 
10019bff0bc4SFelix Fietkau static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
10029bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
10039bff0bc4SFelix Fietkau {
10049bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
10059bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
10069bff0bc4SFelix Fietkau 	unsigned long regval;
10079bff0bc4SFelix Fietkau 	char buf[32];
10089bff0bc4SFelix Fietkau 	ssize_t len;
10099bff0bc4SFelix Fietkau 
10109bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
10119bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
101204236066SDan Carpenter 		return -EFAULT;
10139bff0bc4SFelix Fietkau 
10149bff0bc4SFelix Fietkau 	buf[len] = '\0';
10159bff0bc4SFelix Fietkau 	if (strict_strtoul(buf, 0, &regval))
10169bff0bc4SFelix Fietkau 		return -EINVAL;
10179bff0bc4SFelix Fietkau 
10189bff0bc4SFelix Fietkau 	REG_WRITE_D(ah, sc->debug.regidx, regval);
10199bff0bc4SFelix Fietkau 	return count;
10209bff0bc4SFelix Fietkau }
10219bff0bc4SFelix Fietkau 
10229bff0bc4SFelix Fietkau static const struct file_operations fops_regval = {
10239bff0bc4SFelix Fietkau 	.read = read_file_regval,
10249bff0bc4SFelix Fietkau 	.write = write_file_regval,
10259bff0bc4SFelix Fietkau 	.open = ath9k_debugfs_open,
10266038f373SArnd Bergmann 	.owner = THIS_MODULE,
10276038f373SArnd Bergmann 	.llseek = default_llseek,
10289bff0bc4SFelix Fietkau };
10299bff0bc4SFelix Fietkau 
10304d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah)
1031203c4805SLuis R. Rodriguez {
1032bc974f4aSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(ah);
1033bc974f4aSLuis R. Rodriguez 	struct ath_softc *sc = (struct ath_softc *) common->priv;
10344d6b228dSLuis R. Rodriguez 
1035eb272441SBen Greear 	sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1036eb272441SBen Greear 						   sc->hw->wiphy->debugfsdir);
1037203c4805SLuis R. Rodriguez 	if (!sc->debug.debugfs_phy)
1038c8a72c00SFelix Fietkau 		return -ENOMEM;
1039203c4805SLuis R. Rodriguez 
1040a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
1041c8a72c00SFelix Fietkau 	if (!debugfs_create_file("debug", S_IRUSR | S_IWUSR,
1042c8a72c00SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_debug))
10432493928eSJeff Hansen 		goto err;
1044a830df07SFelix Fietkau #endif
10452493928eSJeff Hansen 
1046c8a72c00SFelix Fietkau 	if (!debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy,
1047c8a72c00SFelix Fietkau 			sc, &fops_dma))
1048203c4805SLuis R. Rodriguez 		goto err;
1049203c4805SLuis R. Rodriguez 
1050c8a72c00SFelix Fietkau 	if (!debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy,
1051c8a72c00SFelix Fietkau 			sc, &fops_interrupt))
1052203c4805SLuis R. Rodriguez 		goto err;
1053203c4805SLuis R. Rodriguez 
1054c8a72c00SFelix Fietkau 	if (!debugfs_create_file("wiphy", S_IRUSR | S_IWUSR,
1055c8a72c00SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_wiphy))
1056203c4805SLuis R. Rodriguez 		goto err;
1057203c4805SLuis R. Rodriguez 
1058c8a72c00SFelix Fietkau 	if (!debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy,
1059c8a72c00SFelix Fietkau 			sc, &fops_xmit))
1060fec247c0SSujith 		goto err;
1061fec247c0SSujith 
10627f010c93SBen Greear 	if (!debugfs_create_file("stations", S_IRUSR, sc->debug.debugfs_phy,
10637f010c93SBen Greear 			sc, &fops_stations))
10647f010c93SBen Greear 		goto err;
10657f010c93SBen Greear 
106655f6d0ffSBen Greear 	if (!debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy,
106755f6d0ffSBen Greear 			sc, &fops_misc))
106855f6d0ffSBen Greear 		goto err;
106955f6d0ffSBen Greear 
1070c8a72c00SFelix Fietkau 	if (!debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy,
1071c8a72c00SFelix Fietkau 			sc, &fops_recv))
10721395d3f0SSujith 		goto err;
10731395d3f0SSujith 
107415340694SFelix Fietkau 	if (!debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
107515340694SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_rx_chainmask))
107615340694SFelix Fietkau 		goto err;
107715340694SFelix Fietkau 
107815340694SFelix Fietkau 	if (!debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
107915340694SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_tx_chainmask))
108015340694SFelix Fietkau 		goto err;
108115340694SFelix Fietkau 
10829bff0bc4SFelix Fietkau 	if (!debugfs_create_file("regidx", S_IRUSR | S_IWUSR,
10839bff0bc4SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_regidx))
10849bff0bc4SFelix Fietkau 		goto err;
10859bff0bc4SFelix Fietkau 
10869bff0bc4SFelix Fietkau 	if (!debugfs_create_file("regval", S_IRUSR | S_IWUSR,
10879bff0bc4SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_regval))
10889bff0bc4SFelix Fietkau 		goto err;
10899bff0bc4SFelix Fietkau 
109041f3e54dSFelix Fietkau 	if (!debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
109141f3e54dSFelix Fietkau 			sc->debug.debugfs_phy, &ah->config.cwm_ignore_extcca))
109241f3e54dSFelix Fietkau 		goto err;
109341f3e54dSFelix Fietkau 
10949bff0bc4SFelix Fietkau 	sc->debug.regidx = 0;
1095203c4805SLuis R. Rodriguez 	return 0;
1096203c4805SLuis R. Rodriguez err:
1097c8a72c00SFelix Fietkau 	debugfs_remove_recursive(sc->debug.debugfs_phy);
1098eb272441SBen Greear 	sc->debug.debugfs_phy = NULL;
1099eb272441SBen Greear 	return -ENOMEM;
1100203c4805SLuis R. Rodriguez }
1101