xref: /linux/drivers/net/wireless/ath/ath9k/debug.c (revision 6038f373a3dc1f1c26496e60b6c40b164716f07e)
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 struct dentry *ath9k_debugfs_root;
28203c4805SLuis R. Rodriguez 
29203c4805SLuis R. Rodriguez static int ath9k_debugfs_open(struct inode *inode, struct file *file)
30203c4805SLuis R. Rodriguez {
31203c4805SLuis R. Rodriguez 	file->private_data = inode->i_private;
32203c4805SLuis R. Rodriguez 	return 0;
33203c4805SLuis R. Rodriguez }
34203c4805SLuis R. Rodriguez 
35a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
36a830df07SFelix Fietkau 
372493928eSJeff Hansen static ssize_t read_file_debug(struct file *file, char __user *user_buf,
382493928eSJeff Hansen 			     size_t count, loff_t *ppos)
392493928eSJeff Hansen {
402493928eSJeff Hansen 	struct ath_softc *sc = file->private_data;
41c46917bbSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
422493928eSJeff Hansen 	char buf[32];
43581f725cSVasanthakumar Thiagarajan 	unsigned int len;
44581f725cSVasanthakumar Thiagarajan 
452b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", common->debug_mask);
462493928eSJeff Hansen 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
472493928eSJeff Hansen }
482493928eSJeff Hansen 
492493928eSJeff Hansen static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
502493928eSJeff Hansen 			     size_t count, loff_t *ppos)
512493928eSJeff Hansen {
522493928eSJeff Hansen 	struct ath_softc *sc = file->private_data;
53c46917bbSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
542493928eSJeff Hansen 	unsigned long mask;
552493928eSJeff Hansen 	char buf[32];
56581f725cSVasanthakumar Thiagarajan 	ssize_t len;
57581f725cSVasanthakumar Thiagarajan 
58581f725cSVasanthakumar Thiagarajan 	len = min(count, sizeof(buf) - 1);
59581f725cSVasanthakumar Thiagarajan 	if (copy_from_user(buf, user_buf, len))
6004236066SDan Carpenter 		return -EFAULT;
61581f725cSVasanthakumar Thiagarajan 
62581f725cSVasanthakumar Thiagarajan 	buf[len] = '\0';
63581f725cSVasanthakumar Thiagarajan 	if (strict_strtoul(buf, 0, &mask))
64581f725cSVasanthakumar Thiagarajan 		return -EINVAL;
65581f725cSVasanthakumar Thiagarajan 
66c46917bbSLuis R. Rodriguez 	common->debug_mask = mask;
672493928eSJeff Hansen 	return count;
682493928eSJeff Hansen }
692493928eSJeff Hansen 
702493928eSJeff Hansen static const struct file_operations fops_debug = {
712493928eSJeff Hansen 	.read = read_file_debug,
722493928eSJeff Hansen 	.write = write_file_debug,
732493928eSJeff Hansen 	.open = ath9k_debugfs_open,
74*6038f373SArnd Bergmann 	.owner = THIS_MODULE,
75*6038f373SArnd Bergmann 	.llseek = default_llseek,
762493928eSJeff Hansen };
772493928eSJeff Hansen 
78a830df07SFelix Fietkau #endif
79a830df07SFelix Fietkau 
80991a0987SPavel Roskin #define DMA_BUF_LEN 1024
81991a0987SPavel Roskin 
8215340694SFelix Fietkau static ssize_t read_file_tx_chainmask(struct file *file, char __user *user_buf,
8315340694SFelix Fietkau 			     size_t count, loff_t *ppos)
8415340694SFelix Fietkau {
8515340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
8615340694SFelix Fietkau 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
8715340694SFelix Fietkau 	char buf[32];
8815340694SFelix Fietkau 	unsigned int len;
8915340694SFelix Fietkau 
902b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", common->tx_chainmask);
9115340694SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
9215340694SFelix Fietkau }
9315340694SFelix Fietkau 
9415340694SFelix Fietkau static ssize_t write_file_tx_chainmask(struct file *file, const char __user *user_buf,
9515340694SFelix Fietkau 			     size_t count, loff_t *ppos)
9615340694SFelix Fietkau {
9715340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
9815340694SFelix Fietkau 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
9915340694SFelix Fietkau 	unsigned long mask;
10015340694SFelix Fietkau 	char buf[32];
10115340694SFelix Fietkau 	ssize_t len;
10215340694SFelix Fietkau 
10315340694SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
10415340694SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
10504236066SDan Carpenter 		return -EFAULT;
10615340694SFelix Fietkau 
10715340694SFelix Fietkau 	buf[len] = '\0';
10815340694SFelix Fietkau 	if (strict_strtoul(buf, 0, &mask))
10915340694SFelix Fietkau 		return -EINVAL;
11015340694SFelix Fietkau 
11115340694SFelix Fietkau 	common->tx_chainmask = mask;
11215340694SFelix Fietkau 	sc->sc_ah->caps.tx_chainmask = mask;
11315340694SFelix Fietkau 	return count;
11415340694SFelix Fietkau }
11515340694SFelix Fietkau 
11615340694SFelix Fietkau static const struct file_operations fops_tx_chainmask = {
11715340694SFelix Fietkau 	.read = read_file_tx_chainmask,
11815340694SFelix Fietkau 	.write = write_file_tx_chainmask,
11915340694SFelix Fietkau 	.open = ath9k_debugfs_open,
120*6038f373SArnd Bergmann 	.owner = THIS_MODULE,
121*6038f373SArnd Bergmann 	.llseek = default_llseek,
12215340694SFelix Fietkau };
12315340694SFelix Fietkau 
12415340694SFelix Fietkau 
12515340694SFelix Fietkau static ssize_t read_file_rx_chainmask(struct file *file, char __user *user_buf,
12615340694SFelix Fietkau 			     size_t count, loff_t *ppos)
12715340694SFelix Fietkau {
12815340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
12915340694SFelix Fietkau 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
13015340694SFelix Fietkau 	char buf[32];
13115340694SFelix Fietkau 	unsigned int len;
13215340694SFelix Fietkau 
1332b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", common->rx_chainmask);
13415340694SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
13515340694SFelix Fietkau }
13615340694SFelix Fietkau 
13715340694SFelix Fietkau static ssize_t write_file_rx_chainmask(struct file *file, const char __user *user_buf,
13815340694SFelix Fietkau 			     size_t count, loff_t *ppos)
13915340694SFelix Fietkau {
14015340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
14115340694SFelix Fietkau 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
14215340694SFelix Fietkau 	unsigned long mask;
14315340694SFelix Fietkau 	char buf[32];
14415340694SFelix Fietkau 	ssize_t len;
14515340694SFelix Fietkau 
14615340694SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
14715340694SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
14804236066SDan Carpenter 		return -EFAULT;
14915340694SFelix Fietkau 
15015340694SFelix Fietkau 	buf[len] = '\0';
15115340694SFelix Fietkau 	if (strict_strtoul(buf, 0, &mask))
15215340694SFelix Fietkau 		return -EINVAL;
15315340694SFelix Fietkau 
15415340694SFelix Fietkau 	common->rx_chainmask = mask;
15515340694SFelix Fietkau 	sc->sc_ah->caps.rx_chainmask = mask;
15615340694SFelix Fietkau 	return count;
15715340694SFelix Fietkau }
15815340694SFelix Fietkau 
15915340694SFelix Fietkau static const struct file_operations fops_rx_chainmask = {
16015340694SFelix Fietkau 	.read = read_file_rx_chainmask,
16115340694SFelix Fietkau 	.write = write_file_rx_chainmask,
16215340694SFelix Fietkau 	.open = ath9k_debugfs_open,
163*6038f373SArnd Bergmann 	.owner = THIS_MODULE,
164*6038f373SArnd Bergmann 	.llseek = default_llseek,
16515340694SFelix Fietkau };
16615340694SFelix Fietkau 
16715340694SFelix Fietkau 
168203c4805SLuis R. Rodriguez static ssize_t read_file_dma(struct file *file, char __user *user_buf,
169203c4805SLuis R. Rodriguez 			     size_t count, loff_t *ppos)
170203c4805SLuis R. Rodriguez {
171203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
172203c4805SLuis R. Rodriguez 	struct ath_hw *ah = sc->sc_ah;
173991a0987SPavel Roskin 	char *buf;
174991a0987SPavel Roskin 	int retval;
175203c4805SLuis R. Rodriguez 	unsigned int len = 0;
176203c4805SLuis R. Rodriguez 	u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
177203c4805SLuis R. Rodriguez 	int i, qcuOffset = 0, dcuOffset = 0;
178203c4805SLuis R. Rodriguez 	u32 *qcuBase = &val[0], *dcuBase = &val[4];
179203c4805SLuis R. Rodriguez 
180991a0987SPavel Roskin 	buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
181991a0987SPavel Roskin 	if (!buf)
18204236066SDan Carpenter 		return -ENOMEM;
183991a0987SPavel Roskin 
1847cf4a2e7SSujith 	ath9k_ps_wakeup(sc);
1857cf4a2e7SSujith 
186475a6e4dSLuis R. Rodriguez 	REG_WRITE_D(ah, AR_MACMISC,
187203c4805SLuis R. Rodriguez 		  ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
188203c4805SLuis R. Rodriguez 		   (AR_MACMISC_MISC_OBS_BUS_1 <<
189203c4805SLuis R. Rodriguez 		    AR_MACMISC_MISC_OBS_BUS_MSB_S)));
190203c4805SLuis R. Rodriguez 
191991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
192203c4805SLuis R. Rodriguez 			"Raw DMA Debug values:\n");
193203c4805SLuis R. Rodriguez 
194203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
195203c4805SLuis R. Rodriguez 		if (i % 4 == 0)
196991a0987SPavel Roskin 			len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
197203c4805SLuis R. Rodriguez 
198475a6e4dSLuis R. Rodriguez 		val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
199991a0987SPavel Roskin 		len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
200203c4805SLuis R. Rodriguez 				i, val[i]);
201203c4805SLuis R. Rodriguez 	}
202203c4805SLuis R. Rodriguez 
203991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
204991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
205203c4805SLuis R. Rodriguez 			"Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
206203c4805SLuis R. Rodriguez 
207203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
208203c4805SLuis R. Rodriguez 		if (i == 8) {
209203c4805SLuis R. Rodriguez 			qcuOffset = 0;
210203c4805SLuis R. Rodriguez 			qcuBase++;
211203c4805SLuis R. Rodriguez 		}
212203c4805SLuis R. Rodriguez 
213203c4805SLuis R. Rodriguez 		if (i == 6) {
214203c4805SLuis R. Rodriguez 			dcuOffset = 0;
215203c4805SLuis R. Rodriguez 			dcuBase++;
216203c4805SLuis R. Rodriguez 		}
217203c4805SLuis R. Rodriguez 
218991a0987SPavel Roskin 		len += snprintf(buf + len, DMA_BUF_LEN - len,
219203c4805SLuis R. Rodriguez 			"%2d          %2x      %1x     %2x           %2x\n",
220203c4805SLuis R. Rodriguez 			i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
221203c4805SLuis R. Rodriguez 			(*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
222203c4805SLuis R. Rodriguez 			val[2] & (0x7 << (i * 3)) >> (i * 3),
223203c4805SLuis R. Rodriguez 			(*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
224203c4805SLuis R. Rodriguez 	}
225203c4805SLuis R. Rodriguez 
226991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
227203c4805SLuis R. Rodriguez 
228991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
229203c4805SLuis R. Rodriguez 		"qcu_stitch state:   %2x    qcu_fetch state:        %2x\n",
230203c4805SLuis R. Rodriguez 		(val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
231991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
232203c4805SLuis R. Rodriguez 		"qcu_complete state: %2x    dcu_complete state:     %2x\n",
233203c4805SLuis R. Rodriguez 		(val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
234991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
235203c4805SLuis R. Rodriguez 		"dcu_arb state:      %2x    dcu_fp state:           %2x\n",
236203c4805SLuis R. Rodriguez 		(val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
237991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
238203c4805SLuis R. Rodriguez 		"chan_idle_dur:     %3d    chan_idle_dur_valid:     %1d\n",
239203c4805SLuis R. Rodriguez 		(val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
240991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
241203c4805SLuis R. Rodriguez 		"txfifo_valid_0:      %1d    txfifo_valid_1:          %1d\n",
242203c4805SLuis R. Rodriguez 		(val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
243991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
244203c4805SLuis R. Rodriguez 		"txfifo_dcu_num_0:   %2d    txfifo_dcu_num_1:       %2d\n",
245203c4805SLuis R. Rodriguez 		(val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
246203c4805SLuis R. Rodriguez 
247991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
248475a6e4dSLuis R. Rodriguez 			REG_READ_D(ah, AR_OBS_BUS_1));
249991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
250475a6e4dSLuis R. Rodriguez 			"AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
251203c4805SLuis R. Rodriguez 
2527cf4a2e7SSujith 	ath9k_ps_restore(sc);
2537cf4a2e7SSujith 
2542b87f3aaSDan Carpenter 	if (len > DMA_BUF_LEN)
2552b87f3aaSDan Carpenter 		len = DMA_BUF_LEN;
2562b87f3aaSDan Carpenter 
257991a0987SPavel Roskin 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
258991a0987SPavel Roskin 	kfree(buf);
259991a0987SPavel Roskin 	return retval;
260203c4805SLuis R. Rodriguez }
261203c4805SLuis R. Rodriguez 
262203c4805SLuis R. Rodriguez static const struct file_operations fops_dma = {
263203c4805SLuis R. Rodriguez 	.read = read_file_dma,
264203c4805SLuis R. Rodriguez 	.open = ath9k_debugfs_open,
265*6038f373SArnd Bergmann 	.owner = THIS_MODULE,
266*6038f373SArnd Bergmann 	.llseek = default_llseek,
267203c4805SLuis R. Rodriguez };
268203c4805SLuis R. Rodriguez 
269203c4805SLuis R. Rodriguez 
270203c4805SLuis R. Rodriguez void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
271203c4805SLuis R. Rodriguez {
272203c4805SLuis R. Rodriguez 	if (status)
273203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.total++;
274a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
275a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXLP)
276a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxlp++;
277a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXHP)
278a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxhp++;
27908578b8fSLuis R. Rodriguez 		if (status & ATH9K_INT_BB_WATCHDOG)
28008578b8fSLuis R. Rodriguez 			sc->debug.stats.istats.bb_watchdog++;
281a9616f41SLuis R. Rodriguez 	} else {
282203c4805SLuis R. Rodriguez 		if (status & ATH9K_INT_RX)
283203c4805SLuis R. Rodriguez 			sc->debug.stats.istats.rxok++;
284a9616f41SLuis R. Rodriguez 	}
285203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXEOL)
286203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxeol++;
287203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXORN)
288203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxorn++;
289203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TX)
290203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txok++;
291203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TXURN)
292203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txurn++;
293203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_MIB)
294203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.mib++;
295203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXPHY)
296203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxphyerr++;
297203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXKCM)
298203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rx_keycache_miss++;
299203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_SWBA)
300203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.swba++;
301203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BMISS)
302203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bmiss++;
303203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BNR)
304203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bnr++;
305203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CST)
306203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cst++;
307203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_GTT)
308203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.gtt++;
309203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TIM)
310203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.tim++;
311203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CABEND)
312203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cabend++;
313203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIMSYNC)
314203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtimsync++;
315203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIM)
316203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtim++;
317203c4805SLuis R. Rodriguez }
318203c4805SLuis R. Rodriguez 
319203c4805SLuis R. Rodriguez static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
320203c4805SLuis R. Rodriguez 				   size_t count, loff_t *ppos)
321203c4805SLuis R. Rodriguez {
322203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
323203c4805SLuis R. Rodriguez 	char buf[512];
324203c4805SLuis R. Rodriguez 	unsigned int len = 0;
325203c4805SLuis R. Rodriguez 
326a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
327a9616f41SLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
328a9616f41SLuis R. Rodriguez 			"%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp);
329a9616f41SLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
330a9616f41SLuis R. Rodriguez 			"%8s: %10u\n", "RXHP", sc->debug.stats.istats.rxhp);
33108578b8fSLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
33208578b8fSLuis R. Rodriguez 			"%8s: %10u\n", "WATCHDOG",
33308578b8fSLuis R. Rodriguez 			sc->debug.stats.istats.bb_watchdog);
334a9616f41SLuis R. Rodriguez 	} else {
335203c4805SLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
336203c4805SLuis R. Rodriguez 			"%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
337a9616f41SLuis R. Rodriguez 	}
338203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
339203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol);
340203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
341203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn);
342203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
343203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TX", sc->debug.stats.istats.txok);
344203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
345203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn);
346203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
347203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "MIB", sc->debug.stats.istats.mib);
348203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
349203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr);
350203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
351203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss);
352203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
353203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba);
354203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
355203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss);
356203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
357203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr);
358203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
359203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "CST", sc->debug.stats.istats.cst);
360203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
361203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt);
362203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
363203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TIM", sc->debug.stats.istats.tim);
364203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
365203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend);
366203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
367203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync);
368203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
369203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim);
370203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
371203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total);
372203c4805SLuis R. Rodriguez 
3732b87f3aaSDan Carpenter 	if (len > sizeof(buf))
3742b87f3aaSDan Carpenter 		len = sizeof(buf);
3752b87f3aaSDan Carpenter 
376203c4805SLuis R. Rodriguez 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
377203c4805SLuis R. Rodriguez }
378203c4805SLuis R. Rodriguez 
379203c4805SLuis R. Rodriguez static const struct file_operations fops_interrupt = {
380203c4805SLuis R. Rodriguez 	.read = read_file_interrupt,
381203c4805SLuis R. Rodriguez 	.open = ath9k_debugfs_open,
382*6038f373SArnd Bergmann 	.owner = THIS_MODULE,
383*6038f373SArnd Bergmann 	.llseek = default_llseek,
384203c4805SLuis R. Rodriguez };
385203c4805SLuis R. Rodriguez 
386545750d3SFelix Fietkau void ath_debug_stat_rc(struct ath_softc *sc, int final_rate)
387203c4805SLuis R. Rodriguez {
388bedf087aSJeff Hansen 	struct ath_rc_stats *stats;
389203c4805SLuis R. Rodriguez 
390545750d3SFelix Fietkau 	stats = &sc->debug.stats.rcstats[final_rate];
391bedf087aSJeff Hansen 	stats->success++;
392203c4805SLuis R. Rodriguez }
393203c4805SLuis R. Rodriguez 
394203c4805SLuis R. Rodriguez void ath_debug_stat_retries(struct ath_softc *sc, int rix,
395203c4805SLuis R. Rodriguez 			    int xretries, int retries, u8 per)
396203c4805SLuis R. Rodriguez {
397bedf087aSJeff Hansen 	struct ath_rc_stats *stats = &sc->debug.stats.rcstats[rix];
398203c4805SLuis R. Rodriguez 
399bedf087aSJeff Hansen 	stats->xretries += xretries;
400bedf087aSJeff Hansen 	stats->retries += retries;
401bedf087aSJeff Hansen 	stats->per = per;
402203c4805SLuis R. Rodriguez }
403203c4805SLuis R. Rodriguez 
404203c4805SLuis R. Rodriguez static ssize_t read_file_rcstat(struct file *file, char __user *user_buf,
405203c4805SLuis R. Rodriguez 				size_t count, loff_t *ppos)
406203c4805SLuis R. Rodriguez {
407203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
408bedf087aSJeff Hansen 	char *buf;
409bedf087aSJeff Hansen 	unsigned int len = 0, max;
410bedf087aSJeff Hansen 	int i = 0;
411bedf087aSJeff Hansen 	ssize_t retval;
412203c4805SLuis R. Rodriguez 
413203c4805SLuis R. Rodriguez 	if (sc->cur_rate_table == NULL)
414203c4805SLuis R. Rodriguez 		return 0;
415203c4805SLuis R. Rodriguez 
4162b87f3aaSDan Carpenter 	max = 80 + sc->cur_rate_table->rate_cnt * 1024 + 1;
4172b87f3aaSDan Carpenter 	buf = kmalloc(max, GFP_KERNEL);
418bedf087aSJeff Hansen 	if (buf == NULL)
41904236066SDan Carpenter 		return -ENOMEM;
420bedf087aSJeff Hansen 
421c755ad34SLuis R. Rodriguez 	len += sprintf(buf, "%6s %6s %6s "
422c755ad34SLuis R. Rodriguez 		       "%10s %10s %10s %10s\n",
423c755ad34SLuis R. Rodriguez 		       "HT", "MCS", "Rate",
424c755ad34SLuis R. Rodriguez 		       "Success", "Retries", "XRetries", "PER");
425bedf087aSJeff Hansen 
426bedf087aSJeff Hansen 	for (i = 0; i < sc->cur_rate_table->rate_cnt; i++) {
427bedf087aSJeff Hansen 		u32 ratekbps = sc->cur_rate_table->info[i].ratekbps;
428bedf087aSJeff Hansen 		struct ath_rc_stats *stats = &sc->debug.stats.rcstats[i];
429c755ad34SLuis R. Rodriguez 		char mcs[5];
430c755ad34SLuis R. Rodriguez 		char htmode[5];
431c755ad34SLuis R. Rodriguez 		int used_mcs = 0, used_htmode = 0;
432c755ad34SLuis R. Rodriguez 
433c755ad34SLuis R. Rodriguez 		if (WLAN_RC_PHY_HT(sc->cur_rate_table->info[i].phy)) {
434c755ad34SLuis R. Rodriguez 			used_mcs = snprintf(mcs, 5, "%d",
435c755ad34SLuis R. Rodriguez 				sc->cur_rate_table->info[i].ratecode);
436c755ad34SLuis R. Rodriguez 
437c755ad34SLuis R. Rodriguez 			if (WLAN_RC_PHY_40(sc->cur_rate_table->info[i].phy))
438c755ad34SLuis R. Rodriguez 				used_htmode = snprintf(htmode, 5, "HT40");
439c755ad34SLuis R. Rodriguez 			else if (WLAN_RC_PHY_20(sc->cur_rate_table->info[i].phy))
440c755ad34SLuis R. Rodriguez 				used_htmode = snprintf(htmode, 5, "HT20");
441c755ad34SLuis R. Rodriguez 			else
442c755ad34SLuis R. Rodriguez 				used_htmode = snprintf(htmode, 5, "????");
443c755ad34SLuis R. Rodriguez 		}
444c755ad34SLuis R. Rodriguez 
445c755ad34SLuis R. Rodriguez 		mcs[used_mcs] = '\0';
446c755ad34SLuis R. Rodriguez 		htmode[used_htmode] = '\0';
447bedf087aSJeff Hansen 
448bedf087aSJeff Hansen 		len += snprintf(buf + len, max - len,
449c755ad34SLuis R. Rodriguez 			"%6s %6s %3u.%d: "
450c755ad34SLuis R. Rodriguez 			"%10u %10u %10u %10u\n",
451c755ad34SLuis R. Rodriguez 			htmode,
452c755ad34SLuis R. Rodriguez 			mcs,
453c755ad34SLuis R. Rodriguez 			ratekbps / 1000,
454c755ad34SLuis R. Rodriguez 			(ratekbps % 1000) / 100,
455c755ad34SLuis R. Rodriguez 			stats->success,
456c755ad34SLuis R. Rodriguez 			stats->retries,
457c755ad34SLuis R. Rodriguez 			stats->xretries,
458bedf087aSJeff Hansen 			stats->per);
459bedf087aSJeff Hansen 	}
460bedf087aSJeff Hansen 
4612b87f3aaSDan Carpenter 	if (len > max)
4622b87f3aaSDan Carpenter 		len = max;
4632b87f3aaSDan Carpenter 
464bedf087aSJeff Hansen 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
465bedf087aSJeff Hansen 	kfree(buf);
466bedf087aSJeff Hansen 	return retval;
467203c4805SLuis R. Rodriguez }
468203c4805SLuis R. Rodriguez 
469203c4805SLuis R. Rodriguez static const struct file_operations fops_rcstat = {
470203c4805SLuis R. Rodriguez 	.read = read_file_rcstat,
471203c4805SLuis R. Rodriguez 	.open = ath9k_debugfs_open,
472*6038f373SArnd Bergmann 	.owner = THIS_MODULE,
473*6038f373SArnd Bergmann 	.llseek = default_llseek,
474203c4805SLuis R. Rodriguez };
475203c4805SLuis R. Rodriguez 
476203c4805SLuis R. Rodriguez static const char * ath_wiphy_state_str(enum ath_wiphy_state state)
477203c4805SLuis R. Rodriguez {
478203c4805SLuis R. Rodriguez 	switch (state) {
479203c4805SLuis R. Rodriguez 	case ATH_WIPHY_INACTIVE:
480203c4805SLuis R. Rodriguez 		return "INACTIVE";
481203c4805SLuis R. Rodriguez 	case ATH_WIPHY_ACTIVE:
482203c4805SLuis R. Rodriguez 		return "ACTIVE";
483203c4805SLuis R. Rodriguez 	case ATH_WIPHY_PAUSING:
484203c4805SLuis R. Rodriguez 		return "PAUSING";
485203c4805SLuis R. Rodriguez 	case ATH_WIPHY_PAUSED:
486203c4805SLuis R. Rodriguez 		return "PAUSED";
487203c4805SLuis R. Rodriguez 	case ATH_WIPHY_SCAN:
488203c4805SLuis R. Rodriguez 		return "SCAN";
489203c4805SLuis R. Rodriguez 	}
490203c4805SLuis R. Rodriguez 	return "?";
491203c4805SLuis R. Rodriguez }
492203c4805SLuis R. Rodriguez 
493203c4805SLuis R. Rodriguez static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
494203c4805SLuis R. Rodriguez 			       size_t count, loff_t *ppos)
495203c4805SLuis R. Rodriguez {
496203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
497203c4805SLuis R. Rodriguez 	char buf[512];
498203c4805SLuis R. Rodriguez 	unsigned int len = 0;
499203c4805SLuis R. Rodriguez 	int i;
500203c4805SLuis R. Rodriguez 	u8 addr[ETH_ALEN];
501203c4805SLuis R. Rodriguez 
502203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
503203c4805SLuis R. Rodriguez 			"primary: %s (%s chan=%d ht=%d)\n",
504203c4805SLuis R. Rodriguez 			wiphy_name(sc->pri_wiphy->hw->wiphy),
505203c4805SLuis R. Rodriguez 			ath_wiphy_state_str(sc->pri_wiphy->state),
506203c4805SLuis R. Rodriguez 			sc->pri_wiphy->chan_idx, sc->pri_wiphy->chan_is_ht);
507203c4805SLuis R. Rodriguez 	for (i = 0; i < sc->num_sec_wiphy; i++) {
508203c4805SLuis R. Rodriguez 		struct ath_wiphy *aphy = sc->sec_wiphy[i];
509203c4805SLuis R. Rodriguez 		if (aphy == NULL)
510203c4805SLuis R. Rodriguez 			continue;
511203c4805SLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
512203c4805SLuis R. Rodriguez 				"secondary: %s (%s chan=%d ht=%d)\n",
513203c4805SLuis R. Rodriguez 				wiphy_name(aphy->hw->wiphy),
514203c4805SLuis R. Rodriguez 				ath_wiphy_state_str(aphy->state),
515203c4805SLuis R. Rodriguez 				aphy->chan_idx, aphy->chan_is_ht);
516203c4805SLuis R. Rodriguez 	}
517203c4805SLuis R. Rodriguez 
518475a6e4dSLuis R. Rodriguez 	put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr);
519475a6e4dSLuis R. Rodriguez 	put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
520203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
521203c4805SLuis R. Rodriguez 			"addr: %pM\n", addr);
522475a6e4dSLuis R. Rodriguez 	put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr);
523475a6e4dSLuis R. Rodriguez 	put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
524203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
525203c4805SLuis R. Rodriguez 			"addrmask: %pM\n", addr);
526203c4805SLuis R. Rodriguez 
5272b87f3aaSDan Carpenter 	if (len > sizeof(buf))
5282b87f3aaSDan Carpenter 		len = sizeof(buf);
5292b87f3aaSDan Carpenter 
530203c4805SLuis R. Rodriguez 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
531203c4805SLuis R. Rodriguez }
532203c4805SLuis R. Rodriguez 
533203c4805SLuis R. Rodriguez static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name)
534203c4805SLuis R. Rodriguez {
535203c4805SLuis R. Rodriguez 	int i;
536203c4805SLuis R. Rodriguez 	if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0)
537203c4805SLuis R. Rodriguez 		return sc->pri_wiphy;
538203c4805SLuis R. Rodriguez 	for (i = 0; i < sc->num_sec_wiphy; i++) {
539203c4805SLuis R. Rodriguez 		struct ath_wiphy *aphy = sc->sec_wiphy[i];
540203c4805SLuis R. Rodriguez 		if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0)
541203c4805SLuis R. Rodriguez 			return aphy;
542203c4805SLuis R. Rodriguez 	}
543203c4805SLuis R. Rodriguez 	return NULL;
544203c4805SLuis R. Rodriguez }
545203c4805SLuis R. Rodriguez 
546203c4805SLuis R. Rodriguez static int del_wiphy(struct ath_softc *sc, const char *name)
547203c4805SLuis R. Rodriguez {
548203c4805SLuis R. Rodriguez 	struct ath_wiphy *aphy = get_wiphy(sc, name);
549203c4805SLuis R. Rodriguez 	if (!aphy)
550203c4805SLuis R. Rodriguez 		return -ENOENT;
551203c4805SLuis R. Rodriguez 	return ath9k_wiphy_del(aphy);
552203c4805SLuis R. Rodriguez }
553203c4805SLuis R. Rodriguez 
554203c4805SLuis R. Rodriguez static int pause_wiphy(struct ath_softc *sc, const char *name)
555203c4805SLuis R. Rodriguez {
556203c4805SLuis R. Rodriguez 	struct ath_wiphy *aphy = get_wiphy(sc, name);
557203c4805SLuis R. Rodriguez 	if (!aphy)
558203c4805SLuis R. Rodriguez 		return -ENOENT;
559203c4805SLuis R. Rodriguez 	return ath9k_wiphy_pause(aphy);
560203c4805SLuis R. Rodriguez }
561203c4805SLuis R. Rodriguez 
562203c4805SLuis R. Rodriguez static int unpause_wiphy(struct ath_softc *sc, const char *name)
563203c4805SLuis R. Rodriguez {
564203c4805SLuis R. Rodriguez 	struct ath_wiphy *aphy = get_wiphy(sc, name);
565203c4805SLuis R. Rodriguez 	if (!aphy)
566203c4805SLuis R. Rodriguez 		return -ENOENT;
567203c4805SLuis R. Rodriguez 	return ath9k_wiphy_unpause(aphy);
568203c4805SLuis R. Rodriguez }
569203c4805SLuis R. Rodriguez 
570203c4805SLuis R. Rodriguez static int select_wiphy(struct ath_softc *sc, const char *name)
571203c4805SLuis R. Rodriguez {
572203c4805SLuis R. Rodriguez 	struct ath_wiphy *aphy = get_wiphy(sc, name);
573203c4805SLuis R. Rodriguez 	if (!aphy)
574203c4805SLuis R. Rodriguez 		return -ENOENT;
575203c4805SLuis R. Rodriguez 	return ath9k_wiphy_select(aphy);
576203c4805SLuis R. Rodriguez }
577203c4805SLuis R. Rodriguez 
578203c4805SLuis R. Rodriguez static int schedule_wiphy(struct ath_softc *sc, const char *msec)
579203c4805SLuis R. Rodriguez {
580203c4805SLuis R. Rodriguez 	ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0));
581203c4805SLuis R. Rodriguez 	return 0;
582203c4805SLuis R. Rodriguez }
583203c4805SLuis R. Rodriguez 
584203c4805SLuis R. Rodriguez static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf,
585203c4805SLuis R. Rodriguez 				size_t count, loff_t *ppos)
586203c4805SLuis R. Rodriguez {
587203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
588203c4805SLuis R. Rodriguez 	char buf[50];
589203c4805SLuis R. Rodriguez 	size_t len;
590203c4805SLuis R. Rodriguez 
591203c4805SLuis R. Rodriguez 	len = min(count, sizeof(buf) - 1);
592203c4805SLuis R. Rodriguez 	if (copy_from_user(buf, user_buf, len))
593203c4805SLuis R. Rodriguez 		return -EFAULT;
594203c4805SLuis R. Rodriguez 	buf[len] = '\0';
595203c4805SLuis R. Rodriguez 	if (len > 0 && buf[len - 1] == '\n')
596203c4805SLuis R. Rodriguez 		buf[len - 1] = '\0';
597203c4805SLuis R. Rodriguez 
598203c4805SLuis R. Rodriguez 	if (strncmp(buf, "add", 3) == 0) {
599203c4805SLuis R. Rodriguez 		int res = ath9k_wiphy_add(sc);
600203c4805SLuis R. Rodriguez 		if (res < 0)
601203c4805SLuis R. Rodriguez 			return res;
602203c4805SLuis R. Rodriguez 	} else if (strncmp(buf, "del=", 4) == 0) {
603203c4805SLuis R. Rodriguez 		int res = del_wiphy(sc, buf + 4);
604203c4805SLuis R. Rodriguez 		if (res < 0)
605203c4805SLuis R. Rodriguez 			return res;
606203c4805SLuis R. Rodriguez 	} else if (strncmp(buf, "pause=", 6) == 0) {
607203c4805SLuis R. Rodriguez 		int res = pause_wiphy(sc, buf + 6);
608203c4805SLuis R. Rodriguez 		if (res < 0)
609203c4805SLuis R. Rodriguez 			return res;
610203c4805SLuis R. Rodriguez 	} else if (strncmp(buf, "unpause=", 8) == 0) {
611203c4805SLuis R. Rodriguez 		int res = unpause_wiphy(sc, buf + 8);
612203c4805SLuis R. Rodriguez 		if (res < 0)
613203c4805SLuis R. Rodriguez 			return res;
614203c4805SLuis R. Rodriguez 	} else if (strncmp(buf, "select=", 7) == 0) {
615203c4805SLuis R. Rodriguez 		int res = select_wiphy(sc, buf + 7);
616203c4805SLuis R. Rodriguez 		if (res < 0)
617203c4805SLuis R. Rodriguez 			return res;
618203c4805SLuis R. Rodriguez 	} else if (strncmp(buf, "schedule=", 9) == 0) {
619203c4805SLuis R. Rodriguez 		int res = schedule_wiphy(sc, buf + 9);
620203c4805SLuis R. Rodriguez 		if (res < 0)
621203c4805SLuis R. Rodriguez 			return res;
622203c4805SLuis R. Rodriguez 	} else
623203c4805SLuis R. Rodriguez 		return -EOPNOTSUPP;
624203c4805SLuis R. Rodriguez 
625203c4805SLuis R. Rodriguez 	return count;
626203c4805SLuis R. Rodriguez }
627203c4805SLuis R. Rodriguez 
628203c4805SLuis R. Rodriguez static const struct file_operations fops_wiphy = {
629203c4805SLuis R. Rodriguez 	.read = read_file_wiphy,
630203c4805SLuis R. Rodriguez 	.write = write_file_wiphy,
631203c4805SLuis R. Rodriguez 	.open = ath9k_debugfs_open,
632*6038f373SArnd Bergmann 	.owner = THIS_MODULE,
633*6038f373SArnd Bergmann 	.llseek = default_llseek,
634203c4805SLuis R. Rodriguez };
635203c4805SLuis R. Rodriguez 
636fec247c0SSujith #define PR(str, elem)							\
637fec247c0SSujith 	do {								\
638fec247c0SSujith 		len += snprintf(buf + len, size - len,			\
639fec247c0SSujith 				"%s%13u%11u%10u%10u\n", str,		\
6401d2231e2SFelix Fietkau 		sc->debug.stats.txstats[sc->tx.hwq_map[WME_AC_BE]].elem, \
6411d2231e2SFelix Fietkau 		sc->debug.stats.txstats[sc->tx.hwq_map[WME_AC_BK]].elem, \
6421d2231e2SFelix Fietkau 		sc->debug.stats.txstats[sc->tx.hwq_map[WME_AC_VI]].elem, \
6431d2231e2SFelix Fietkau 		sc->debug.stats.txstats[sc->tx.hwq_map[WME_AC_VO]].elem); \
644fec247c0SSujith } while(0)
645fec247c0SSujith 
646fec247c0SSujith static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
647fec247c0SSujith 			      size_t count, loff_t *ppos)
648fec247c0SSujith {
649fec247c0SSujith 	struct ath_softc *sc = file->private_data;
650fec247c0SSujith 	char *buf;
651fec247c0SSujith 	unsigned int len = 0, size = 2048;
652fec247c0SSujith 	ssize_t retval = 0;
653fec247c0SSujith 
654fec247c0SSujith 	buf = kzalloc(size, GFP_KERNEL);
655fec247c0SSujith 	if (buf == NULL)
65604236066SDan Carpenter 		return -ENOMEM;
657fec247c0SSujith 
658fec247c0SSujith 	len += sprintf(buf, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
659fec247c0SSujith 
660fec247c0SSujith 	PR("MPDUs Queued:    ", queued);
661fec247c0SSujith 	PR("MPDUs Completed: ", completed);
662fec247c0SSujith 	PR("Aggregates:      ", a_aggr);
663fec247c0SSujith 	PR("AMPDUs Queued:   ", a_queued);
664fec247c0SSujith 	PR("AMPDUs Completed:", a_completed);
665fec247c0SSujith 	PR("AMPDUs Retried:  ", a_retries);
666fec247c0SSujith 	PR("AMPDUs XRetried: ", a_xretries);
667fec247c0SSujith 	PR("FIFO Underrun:   ", fifo_underrun);
668fec247c0SSujith 	PR("TXOP Exceeded:   ", xtxop);
669fec247c0SSujith 	PR("TXTIMER Expiry:  ", timer_exp);
670fec247c0SSujith 	PR("DESC CFG Error:  ", desc_cfg_err);
671fec247c0SSujith 	PR("DATA Underrun:   ", data_underrun);
672fec247c0SSujith 	PR("DELIM Underrun:  ", delim_underrun);
673fec247c0SSujith 
6742b87f3aaSDan Carpenter 	if (len > size)
6752b87f3aaSDan Carpenter 		len = size;
6762b87f3aaSDan Carpenter 
677fec247c0SSujith 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
678fec247c0SSujith 	kfree(buf);
679fec247c0SSujith 
680fec247c0SSujith 	return retval;
681fec247c0SSujith }
682fec247c0SSujith 
683fec247c0SSujith void ath_debug_stat_tx(struct ath_softc *sc, struct ath_txq *txq,
684db1a052bSFelix Fietkau 		       struct ath_buf *bf, struct ath_tx_status *ts)
685fec247c0SSujith {
686fec247c0SSujith 	if (bf_isampdu(bf)) {
687fec247c0SSujith 		if (bf_isxretried(bf))
688fec247c0SSujith 			TX_STAT_INC(txq->axq_qnum, a_xretries);
689fec247c0SSujith 		else
690fec247c0SSujith 			TX_STAT_INC(txq->axq_qnum, a_completed);
691fec247c0SSujith 	} else {
692fec247c0SSujith 		TX_STAT_INC(txq->axq_qnum, completed);
693fec247c0SSujith 	}
694fec247c0SSujith 
695db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_FIFO)
696fec247c0SSujith 		TX_STAT_INC(txq->axq_qnum, fifo_underrun);
697db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_XTXOP)
698fec247c0SSujith 		TX_STAT_INC(txq->axq_qnum, xtxop);
699db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
700fec247c0SSujith 		TX_STAT_INC(txq->axq_qnum, timer_exp);
701db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
702fec247c0SSujith 		TX_STAT_INC(txq->axq_qnum, desc_cfg_err);
703db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
704fec247c0SSujith 		TX_STAT_INC(txq->axq_qnum, data_underrun);
705db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
706fec247c0SSujith 		TX_STAT_INC(txq->axq_qnum, delim_underrun);
707fec247c0SSujith }
708fec247c0SSujith 
709fec247c0SSujith static const struct file_operations fops_xmit = {
710fec247c0SSujith 	.read = read_file_xmit,
711fec247c0SSujith 	.open = ath9k_debugfs_open,
712*6038f373SArnd Bergmann 	.owner = THIS_MODULE,
713*6038f373SArnd Bergmann 	.llseek = default_llseek,
714fec247c0SSujith };
715203c4805SLuis R. Rodriguez 
7161395d3f0SSujith static ssize_t read_file_recv(struct file *file, char __user *user_buf,
7171395d3f0SSujith 			      size_t count, loff_t *ppos)
7181395d3f0SSujith {
7191395d3f0SSujith #define PHY_ERR(s, p) \
7201395d3f0SSujith 	len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \
7211395d3f0SSujith 			sc->debug.stats.rxstats.phy_err_stats[p]);
7221395d3f0SSujith 
7231395d3f0SSujith 	struct ath_softc *sc = file->private_data;
7241395d3f0SSujith 	char *buf;
7251395d3f0SSujith 	unsigned int len = 0, size = 1152;
7261395d3f0SSujith 	ssize_t retval = 0;
7271395d3f0SSujith 
7281395d3f0SSujith 	buf = kzalloc(size, GFP_KERNEL);
7291395d3f0SSujith 	if (buf == NULL)
73004236066SDan Carpenter 		return -ENOMEM;
7311395d3f0SSujith 
7321395d3f0SSujith 	len += snprintf(buf + len, size - len,
7331395d3f0SSujith 			"%18s : %10u\n", "CRC ERR",
7341395d3f0SSujith 			sc->debug.stats.rxstats.crc_err);
7351395d3f0SSujith 	len += snprintf(buf + len, size - len,
7361395d3f0SSujith 			"%18s : %10u\n", "DECRYPT CRC ERR",
7371395d3f0SSujith 			sc->debug.stats.rxstats.decrypt_crc_err);
7381395d3f0SSujith 	len += snprintf(buf + len, size - len,
7391395d3f0SSujith 			"%18s : %10u\n", "PHY ERR",
7401395d3f0SSujith 			sc->debug.stats.rxstats.phy_err);
7411395d3f0SSujith 	len += snprintf(buf + len, size - len,
7421395d3f0SSujith 			"%18s : %10u\n", "MIC ERR",
7431395d3f0SSujith 			sc->debug.stats.rxstats.mic_err);
7441395d3f0SSujith 	len += snprintf(buf + len, size - len,
7451395d3f0SSujith 			"%18s : %10u\n", "PRE-DELIM CRC ERR",
7461395d3f0SSujith 			sc->debug.stats.rxstats.pre_delim_crc_err);
7471395d3f0SSujith 	len += snprintf(buf + len, size - len,
7481395d3f0SSujith 			"%18s : %10u\n", "POST-DELIM CRC ERR",
7491395d3f0SSujith 			sc->debug.stats.rxstats.post_delim_crc_err);
7501395d3f0SSujith 	len += snprintf(buf + len, size - len,
7511395d3f0SSujith 			"%18s : %10u\n", "DECRYPT BUSY ERR",
7521395d3f0SSujith 			sc->debug.stats.rxstats.decrypt_busy_err);
7531395d3f0SSujith 
7541395d3f0SSujith 	PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN);
7551395d3f0SSujith 	PHY_ERR("TIMING", ATH9K_PHYERR_TIMING);
7561395d3f0SSujith 	PHY_ERR("PARITY", ATH9K_PHYERR_PARITY);
7571395d3f0SSujith 	PHY_ERR("RATE", ATH9K_PHYERR_RATE);
7581395d3f0SSujith 	PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH);
7591395d3f0SSujith 	PHY_ERR("RADAR", ATH9K_PHYERR_RADAR);
7601395d3f0SSujith 	PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE);
7611395d3f0SSujith 	PHY_ERR("TOR", ATH9K_PHYERR_TOR);
7621395d3f0SSujith 	PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING);
7631395d3f0SSujith 	PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
7641395d3f0SSujith 	PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
7651395d3f0SSujith 	PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
7661395d3f0SSujith 	PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP);
7671395d3f0SSujith 	PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE);
7681395d3f0SSujith 	PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART);
7691395d3f0SSujith 	PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT);
7701395d3f0SSujith 	PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING);
7711395d3f0SSujith 	PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC);
7721395d3f0SSujith 	PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
7731395d3f0SSujith 	PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE);
7741395d3f0SSujith 	PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART);
7751395d3f0SSujith 	PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
7761395d3f0SSujith 	PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP);
7771395d3f0SSujith 	PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR);
7781395d3f0SSujith 	PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
7791395d3f0SSujith 	PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL);
7801395d3f0SSujith 
7812b87f3aaSDan Carpenter 	if (len > size)
7822b87f3aaSDan Carpenter 		len = size;
7832b87f3aaSDan Carpenter 
7841395d3f0SSujith 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
7851395d3f0SSujith 	kfree(buf);
7861395d3f0SSujith 
7871395d3f0SSujith 	return retval;
7881395d3f0SSujith 
7891395d3f0SSujith #undef PHY_ERR
7901395d3f0SSujith }
7911395d3f0SSujith 
7928e6f5aa2SFelix Fietkau void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
7931395d3f0SSujith {
7941395d3f0SSujith #define RX_STAT_INC(c) sc->debug.stats.rxstats.c++
7951395d3f0SSujith #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
7961395d3f0SSujith 
7971395d3f0SSujith 	u32 phyerr;
7981395d3f0SSujith 
7998e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_CRC)
8001395d3f0SSujith 		RX_STAT_INC(crc_err);
8018e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_DECRYPT)
8021395d3f0SSujith 		RX_STAT_INC(decrypt_crc_err);
8038e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_MIC)
8041395d3f0SSujith 		RX_STAT_INC(mic_err);
8058e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
8061395d3f0SSujith 		RX_STAT_INC(pre_delim_crc_err);
8078e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
8081395d3f0SSujith 		RX_STAT_INC(post_delim_crc_err);
8098e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
8101395d3f0SSujith 		RX_STAT_INC(decrypt_busy_err);
8111395d3f0SSujith 
8128e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_PHY) {
8131395d3f0SSujith 		RX_STAT_INC(phy_err);
8148e6f5aa2SFelix Fietkau 		phyerr = rs->rs_phyerr & 0x24;
8151395d3f0SSujith 		RX_PHY_ERR_INC(phyerr);
8161395d3f0SSujith 	}
8171395d3f0SSujith 
8181395d3f0SSujith #undef RX_STAT_INC
8191395d3f0SSujith #undef RX_PHY_ERR_INC
8201395d3f0SSujith }
8211395d3f0SSujith 
8221395d3f0SSujith static const struct file_operations fops_recv = {
8231395d3f0SSujith 	.read = read_file_recv,
8241395d3f0SSujith 	.open = ath9k_debugfs_open,
825*6038f373SArnd Bergmann 	.owner = THIS_MODULE,
826*6038f373SArnd Bergmann 	.llseek = default_llseek,
8271395d3f0SSujith };
8281395d3f0SSujith 
8299bff0bc4SFelix Fietkau static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
8309bff0bc4SFelix Fietkau                                 size_t count, loff_t *ppos)
8319bff0bc4SFelix Fietkau {
8329bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
8339bff0bc4SFelix Fietkau 	char buf[32];
8349bff0bc4SFelix Fietkau 	unsigned int len;
8359bff0bc4SFelix Fietkau 
8362b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
8379bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
8389bff0bc4SFelix Fietkau }
8399bff0bc4SFelix Fietkau 
8409bff0bc4SFelix Fietkau static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
8419bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
8429bff0bc4SFelix Fietkau {
8439bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
8449bff0bc4SFelix Fietkau 	unsigned long regidx;
8459bff0bc4SFelix Fietkau 	char buf[32];
8469bff0bc4SFelix Fietkau 	ssize_t len;
8479bff0bc4SFelix Fietkau 
8489bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
8499bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
85004236066SDan Carpenter 		return -EFAULT;
8519bff0bc4SFelix Fietkau 
8529bff0bc4SFelix Fietkau 	buf[len] = '\0';
8539bff0bc4SFelix Fietkau 	if (strict_strtoul(buf, 0, &regidx))
8549bff0bc4SFelix Fietkau 		return -EINVAL;
8559bff0bc4SFelix Fietkau 
8569bff0bc4SFelix Fietkau 	sc->debug.regidx = regidx;
8579bff0bc4SFelix Fietkau 	return count;
8589bff0bc4SFelix Fietkau }
8599bff0bc4SFelix Fietkau 
8609bff0bc4SFelix Fietkau static const struct file_operations fops_regidx = {
8619bff0bc4SFelix Fietkau 	.read = read_file_regidx,
8629bff0bc4SFelix Fietkau 	.write = write_file_regidx,
8639bff0bc4SFelix Fietkau 	.open = ath9k_debugfs_open,
864*6038f373SArnd Bergmann 	.owner = THIS_MODULE,
865*6038f373SArnd Bergmann 	.llseek = default_llseek,
8669bff0bc4SFelix Fietkau };
8679bff0bc4SFelix Fietkau 
8689bff0bc4SFelix Fietkau static ssize_t read_file_regval(struct file *file, char __user *user_buf,
8699bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
8709bff0bc4SFelix Fietkau {
8719bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
8729bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
8739bff0bc4SFelix Fietkau 	char buf[32];
8749bff0bc4SFelix Fietkau 	unsigned int len;
8759bff0bc4SFelix Fietkau 	u32 regval;
8769bff0bc4SFelix Fietkau 
8779bff0bc4SFelix Fietkau 	regval = REG_READ_D(ah, sc->debug.regidx);
8782b87f3aaSDan Carpenter 	len = sprintf(buf, "0x%08x\n", regval);
8799bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
8809bff0bc4SFelix Fietkau }
8819bff0bc4SFelix Fietkau 
8829bff0bc4SFelix Fietkau static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
8839bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
8849bff0bc4SFelix Fietkau {
8859bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
8869bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
8879bff0bc4SFelix Fietkau 	unsigned long regval;
8889bff0bc4SFelix Fietkau 	char buf[32];
8899bff0bc4SFelix Fietkau 	ssize_t len;
8909bff0bc4SFelix Fietkau 
8919bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
8929bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
89304236066SDan Carpenter 		return -EFAULT;
8949bff0bc4SFelix Fietkau 
8959bff0bc4SFelix Fietkau 	buf[len] = '\0';
8969bff0bc4SFelix Fietkau 	if (strict_strtoul(buf, 0, &regval))
8979bff0bc4SFelix Fietkau 		return -EINVAL;
8989bff0bc4SFelix Fietkau 
8999bff0bc4SFelix Fietkau 	REG_WRITE_D(ah, sc->debug.regidx, regval);
9009bff0bc4SFelix Fietkau 	return count;
9019bff0bc4SFelix Fietkau }
9029bff0bc4SFelix Fietkau 
9039bff0bc4SFelix Fietkau static const struct file_operations fops_regval = {
9049bff0bc4SFelix Fietkau 	.read = read_file_regval,
9059bff0bc4SFelix Fietkau 	.write = write_file_regval,
9069bff0bc4SFelix Fietkau 	.open = ath9k_debugfs_open,
907*6038f373SArnd Bergmann 	.owner = THIS_MODULE,
908*6038f373SArnd Bergmann 	.llseek = default_llseek,
9099bff0bc4SFelix Fietkau };
9109bff0bc4SFelix Fietkau 
9114d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah)
912203c4805SLuis R. Rodriguez {
913bc974f4aSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(ah);
914bc974f4aSLuis R. Rodriguez 	struct ath_softc *sc = (struct ath_softc *) common->priv;
9154d6b228dSLuis R. Rodriguez 
916203c4805SLuis R. Rodriguez 	if (!ath9k_debugfs_root)
917203c4805SLuis R. Rodriguez 		return -ENOENT;
918203c4805SLuis R. Rodriguez 
919203c4805SLuis R. Rodriguez 	sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
920203c4805SLuis R. Rodriguez 						      ath9k_debugfs_root);
921203c4805SLuis R. Rodriguez 	if (!sc->debug.debugfs_phy)
922c8a72c00SFelix Fietkau 		return -ENOMEM;
923203c4805SLuis R. Rodriguez 
924a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
925c8a72c00SFelix Fietkau 	if (!debugfs_create_file("debug", S_IRUSR | S_IWUSR,
926c8a72c00SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_debug))
9272493928eSJeff Hansen 		goto err;
928a830df07SFelix Fietkau #endif
9292493928eSJeff Hansen 
930c8a72c00SFelix Fietkau 	if (!debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy,
931c8a72c00SFelix Fietkau 			sc, &fops_dma))
932203c4805SLuis R. Rodriguez 		goto err;
933203c4805SLuis R. Rodriguez 
934c8a72c00SFelix Fietkau 	if (!debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy,
935c8a72c00SFelix Fietkau 			sc, &fops_interrupt))
936203c4805SLuis R. Rodriguez 		goto err;
937203c4805SLuis R. Rodriguez 
938c8a72c00SFelix Fietkau 	if (!debugfs_create_file("rcstat", S_IRUSR, sc->debug.debugfs_phy,
939c8a72c00SFelix Fietkau 			sc, &fops_rcstat))
940203c4805SLuis R. Rodriguez 		goto err;
941203c4805SLuis R. Rodriguez 
942c8a72c00SFelix Fietkau 	if (!debugfs_create_file("wiphy", S_IRUSR | S_IWUSR,
943c8a72c00SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_wiphy))
944203c4805SLuis R. Rodriguez 		goto err;
945203c4805SLuis R. Rodriguez 
946c8a72c00SFelix Fietkau 	if (!debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy,
947c8a72c00SFelix Fietkau 			sc, &fops_xmit))
948fec247c0SSujith 		goto err;
949fec247c0SSujith 
950c8a72c00SFelix Fietkau 	if (!debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy,
951c8a72c00SFelix Fietkau 			sc, &fops_recv))
9521395d3f0SSujith 		goto err;
9531395d3f0SSujith 
95415340694SFelix Fietkau 	if (!debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
95515340694SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_rx_chainmask))
95615340694SFelix Fietkau 		goto err;
95715340694SFelix Fietkau 
95815340694SFelix Fietkau 	if (!debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
95915340694SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_tx_chainmask))
96015340694SFelix Fietkau 		goto err;
96115340694SFelix Fietkau 
9629bff0bc4SFelix Fietkau 	if (!debugfs_create_file("regidx", S_IRUSR | S_IWUSR,
9639bff0bc4SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_regidx))
9649bff0bc4SFelix Fietkau 		goto err;
9659bff0bc4SFelix Fietkau 
9669bff0bc4SFelix Fietkau 	if (!debugfs_create_file("regval", S_IRUSR | S_IWUSR,
9679bff0bc4SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_regval))
9689bff0bc4SFelix Fietkau 		goto err;
9699bff0bc4SFelix Fietkau 
97041f3e54dSFelix Fietkau 	if (!debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
97141f3e54dSFelix Fietkau 			sc->debug.debugfs_phy, &ah->config.cwm_ignore_extcca))
97241f3e54dSFelix Fietkau 		goto err;
97341f3e54dSFelix Fietkau 
9749bff0bc4SFelix Fietkau 	sc->debug.regidx = 0;
975203c4805SLuis R. Rodriguez 	return 0;
976203c4805SLuis R. Rodriguez err:
9774d6b228dSLuis R. Rodriguez 	ath9k_exit_debug(ah);
978203c4805SLuis R. Rodriguez 	return -ENOMEM;
979203c4805SLuis R. Rodriguez }
980203c4805SLuis R. Rodriguez 
9814d6b228dSLuis R. Rodriguez void ath9k_exit_debug(struct ath_hw *ah)
982203c4805SLuis R. Rodriguez {
983bc974f4aSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(ah);
984bc974f4aSLuis R. Rodriguez 	struct ath_softc *sc = (struct ath_softc *) common->priv;
9854d6b228dSLuis R. Rodriguez 
986c8a72c00SFelix Fietkau 	debugfs_remove_recursive(sc->debug.debugfs_phy);
987203c4805SLuis R. Rodriguez }
988203c4805SLuis R. Rodriguez 
989203c4805SLuis R. Rodriguez int ath9k_debug_create_root(void)
990203c4805SLuis R. Rodriguez {
991203c4805SLuis R. Rodriguez 	ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
992203c4805SLuis R. Rodriguez 	if (!ath9k_debugfs_root)
993203c4805SLuis R. Rodriguez 		return -ENOENT;
994203c4805SLuis R. Rodriguez 
995203c4805SLuis R. Rodriguez 	return 0;
996203c4805SLuis R. Rodriguez }
997203c4805SLuis R. Rodriguez 
998203c4805SLuis R. Rodriguez void ath9k_debug_remove_root(void)
999203c4805SLuis R. Rodriguez {
1000203c4805SLuis R. Rodriguez 	debugfs_remove(ath9k_debugfs_root);
1001203c4805SLuis R. Rodriguez 	ath9k_debugfs_root = NULL;
1002203c4805SLuis R. Rodriguez }
1003