xref: /linux/drivers/net/wireless/ath/ath9k/debug.c (revision 08578b8f16ca551499c54f2cd229df3e58c8f381)
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 
45c46917bbSLuis R. Rodriguez 	len = snprintf(buf, sizeof(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))
60581f725cSVasanthakumar Thiagarajan 		return -EINVAL;
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,
742493928eSJeff Hansen 	.owner = THIS_MODULE
752493928eSJeff Hansen };
762493928eSJeff Hansen 
77a830df07SFelix Fietkau #endif
78a830df07SFelix Fietkau 
79991a0987SPavel Roskin #define DMA_BUF_LEN 1024
80991a0987SPavel Roskin 
8115340694SFelix Fietkau static ssize_t read_file_tx_chainmask(struct file *file, char __user *user_buf,
8215340694SFelix Fietkau 			     size_t count, loff_t *ppos)
8315340694SFelix Fietkau {
8415340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
8515340694SFelix Fietkau 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
8615340694SFelix Fietkau 	char buf[32];
8715340694SFelix Fietkau 	unsigned int len;
8815340694SFelix Fietkau 
8915340694SFelix Fietkau 	len = snprintf(buf, sizeof(buf), "0x%08x\n", common->tx_chainmask);
9015340694SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
9115340694SFelix Fietkau }
9215340694SFelix Fietkau 
9315340694SFelix Fietkau static ssize_t write_file_tx_chainmask(struct file *file, const char __user *user_buf,
9415340694SFelix Fietkau 			     size_t count, loff_t *ppos)
9515340694SFelix Fietkau {
9615340694SFelix Fietkau 	struct ath_softc *sc = file->private_data;
9715340694SFelix Fietkau 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
9815340694SFelix Fietkau 	unsigned long mask;
9915340694SFelix Fietkau 	char buf[32];
10015340694SFelix Fietkau 	ssize_t len;
10115340694SFelix Fietkau 
10215340694SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
10315340694SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
10415340694SFelix Fietkau 		return -EINVAL;
10515340694SFelix Fietkau 
10615340694SFelix Fietkau 	buf[len] = '\0';
10715340694SFelix Fietkau 	if (strict_strtoul(buf, 0, &mask))
10815340694SFelix Fietkau 		return -EINVAL;
10915340694SFelix Fietkau 
11015340694SFelix Fietkau 	common->tx_chainmask = mask;
11115340694SFelix Fietkau 	sc->sc_ah->caps.tx_chainmask = mask;
11215340694SFelix Fietkau 	return count;
11315340694SFelix Fietkau }
11415340694SFelix Fietkau 
11515340694SFelix Fietkau static const struct file_operations fops_tx_chainmask = {
11615340694SFelix Fietkau 	.read = read_file_tx_chainmask,
11715340694SFelix Fietkau 	.write = write_file_tx_chainmask,
11815340694SFelix Fietkau 	.open = ath9k_debugfs_open,
11915340694SFelix Fietkau 	.owner = THIS_MODULE
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 
13115340694SFelix Fietkau 	len = snprintf(buf, sizeof(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))
14615340694SFelix Fietkau 		return -EINVAL;
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,
16115340694SFelix Fietkau 	.owner = THIS_MODULE
16215340694SFelix Fietkau };
16315340694SFelix Fietkau 
16415340694SFelix Fietkau 
165203c4805SLuis R. Rodriguez static ssize_t read_file_dma(struct file *file, char __user *user_buf,
166203c4805SLuis R. Rodriguez 			     size_t count, loff_t *ppos)
167203c4805SLuis R. Rodriguez {
168203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
169203c4805SLuis R. Rodriguez 	struct ath_hw *ah = sc->sc_ah;
170991a0987SPavel Roskin 	char *buf;
171991a0987SPavel Roskin 	int retval;
172203c4805SLuis R. Rodriguez 	unsigned int len = 0;
173203c4805SLuis R. Rodriguez 	u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
174203c4805SLuis R. Rodriguez 	int i, qcuOffset = 0, dcuOffset = 0;
175203c4805SLuis R. Rodriguez 	u32 *qcuBase = &val[0], *dcuBase = &val[4];
176203c4805SLuis R. Rodriguez 
177991a0987SPavel Roskin 	buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
178991a0987SPavel Roskin 	if (!buf)
179991a0987SPavel Roskin 		return 0;
180991a0987SPavel Roskin 
1817cf4a2e7SSujith 	ath9k_ps_wakeup(sc);
1827cf4a2e7SSujith 
183475a6e4dSLuis R. Rodriguez 	REG_WRITE_D(ah, AR_MACMISC,
184203c4805SLuis R. Rodriguez 		  ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
185203c4805SLuis R. Rodriguez 		   (AR_MACMISC_MISC_OBS_BUS_1 <<
186203c4805SLuis R. Rodriguez 		    AR_MACMISC_MISC_OBS_BUS_MSB_S)));
187203c4805SLuis R. Rodriguez 
188991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
189203c4805SLuis R. Rodriguez 			"Raw DMA Debug values:\n");
190203c4805SLuis R. Rodriguez 
191203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
192203c4805SLuis R. Rodriguez 		if (i % 4 == 0)
193991a0987SPavel Roskin 			len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
194203c4805SLuis R. Rodriguez 
195475a6e4dSLuis R. Rodriguez 		val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
196991a0987SPavel Roskin 		len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
197203c4805SLuis R. Rodriguez 				i, val[i]);
198203c4805SLuis R. Rodriguez 	}
199203c4805SLuis R. Rodriguez 
200991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
201991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
202203c4805SLuis R. Rodriguez 			"Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
203203c4805SLuis R. Rodriguez 
204203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
205203c4805SLuis R. Rodriguez 		if (i == 8) {
206203c4805SLuis R. Rodriguez 			qcuOffset = 0;
207203c4805SLuis R. Rodriguez 			qcuBase++;
208203c4805SLuis R. Rodriguez 		}
209203c4805SLuis R. Rodriguez 
210203c4805SLuis R. Rodriguez 		if (i == 6) {
211203c4805SLuis R. Rodriguez 			dcuOffset = 0;
212203c4805SLuis R. Rodriguez 			dcuBase++;
213203c4805SLuis R. Rodriguez 		}
214203c4805SLuis R. Rodriguez 
215991a0987SPavel Roskin 		len += snprintf(buf + len, DMA_BUF_LEN - len,
216203c4805SLuis R. Rodriguez 			"%2d          %2x      %1x     %2x           %2x\n",
217203c4805SLuis R. Rodriguez 			i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
218203c4805SLuis R. Rodriguez 			(*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
219203c4805SLuis R. Rodriguez 			val[2] & (0x7 << (i * 3)) >> (i * 3),
220203c4805SLuis R. Rodriguez 			(*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
221203c4805SLuis R. Rodriguez 	}
222203c4805SLuis R. Rodriguez 
223991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
224203c4805SLuis R. Rodriguez 
225991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
226203c4805SLuis R. Rodriguez 		"qcu_stitch state:   %2x    qcu_fetch state:        %2x\n",
227203c4805SLuis R. Rodriguez 		(val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
228991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
229203c4805SLuis R. Rodriguez 		"qcu_complete state: %2x    dcu_complete state:     %2x\n",
230203c4805SLuis R. Rodriguez 		(val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
231991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
232203c4805SLuis R. Rodriguez 		"dcu_arb state:      %2x    dcu_fp state:           %2x\n",
233203c4805SLuis R. Rodriguez 		(val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
234991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
235203c4805SLuis R. Rodriguez 		"chan_idle_dur:     %3d    chan_idle_dur_valid:     %1d\n",
236203c4805SLuis R. Rodriguez 		(val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
237991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
238203c4805SLuis R. Rodriguez 		"txfifo_valid_0:      %1d    txfifo_valid_1:          %1d\n",
239203c4805SLuis R. Rodriguez 		(val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
240991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
241203c4805SLuis R. Rodriguez 		"txfifo_dcu_num_0:   %2d    txfifo_dcu_num_1:       %2d\n",
242203c4805SLuis R. Rodriguez 		(val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
243203c4805SLuis R. Rodriguez 
244991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
245475a6e4dSLuis R. Rodriguez 			REG_READ_D(ah, AR_OBS_BUS_1));
246991a0987SPavel Roskin 	len += snprintf(buf + len, DMA_BUF_LEN - len,
247475a6e4dSLuis R. Rodriguez 			"AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
248203c4805SLuis R. Rodriguez 
2497cf4a2e7SSujith 	ath9k_ps_restore(sc);
2507cf4a2e7SSujith 
251991a0987SPavel Roskin 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
252991a0987SPavel Roskin 	kfree(buf);
253991a0987SPavel Roskin 	return retval;
254203c4805SLuis R. Rodriguez }
255203c4805SLuis R. Rodriguez 
256203c4805SLuis R. Rodriguez static const struct file_operations fops_dma = {
257203c4805SLuis R. Rodriguez 	.read = read_file_dma,
258203c4805SLuis R. Rodriguez 	.open = ath9k_debugfs_open,
259203c4805SLuis R. Rodriguez 	.owner = THIS_MODULE
260203c4805SLuis R. Rodriguez };
261203c4805SLuis R. Rodriguez 
262203c4805SLuis R. Rodriguez 
263203c4805SLuis R. Rodriguez void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
264203c4805SLuis R. Rodriguez {
265203c4805SLuis R. Rodriguez 	if (status)
266203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.total++;
267a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
268a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXLP)
269a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxlp++;
270a9616f41SLuis R. Rodriguez 		if (status & ATH9K_INT_RXHP)
271a9616f41SLuis R. Rodriguez 			sc->debug.stats.istats.rxhp++;
272*08578b8fSLuis R. Rodriguez 		if (status & ATH9K_INT_BB_WATCHDOG)
273*08578b8fSLuis R. Rodriguez 			sc->debug.stats.istats.bb_watchdog++;
274a9616f41SLuis R. Rodriguez 	} else {
275203c4805SLuis R. Rodriguez 		if (status & ATH9K_INT_RX)
276203c4805SLuis R. Rodriguez 			sc->debug.stats.istats.rxok++;
277a9616f41SLuis R. Rodriguez 	}
278203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXEOL)
279203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxeol++;
280203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXORN)
281203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxorn++;
282203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TX)
283203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txok++;
284203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TXURN)
285203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txurn++;
286203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_MIB)
287203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.mib++;
288203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXPHY)
289203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxphyerr++;
290203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXKCM)
291203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rx_keycache_miss++;
292203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_SWBA)
293203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.swba++;
294203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BMISS)
295203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bmiss++;
296203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BNR)
297203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bnr++;
298203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CST)
299203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cst++;
300203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_GTT)
301203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.gtt++;
302203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TIM)
303203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.tim++;
304203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CABEND)
305203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cabend++;
306203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIMSYNC)
307203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtimsync++;
308203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIM)
309203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtim++;
310203c4805SLuis R. Rodriguez }
311203c4805SLuis R. Rodriguez 
312203c4805SLuis R. Rodriguez static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
313203c4805SLuis R. Rodriguez 				   size_t count, loff_t *ppos)
314203c4805SLuis R. Rodriguez {
315203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
316203c4805SLuis R. Rodriguez 	char buf[512];
317203c4805SLuis R. Rodriguez 	unsigned int len = 0;
318203c4805SLuis R. Rodriguez 
319a9616f41SLuis R. Rodriguez 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
320a9616f41SLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
321a9616f41SLuis R. Rodriguez 			"%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp);
322a9616f41SLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
323a9616f41SLuis R. Rodriguez 			"%8s: %10u\n", "RXHP", sc->debug.stats.istats.rxhp);
324*08578b8fSLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
325*08578b8fSLuis R. Rodriguez 			"%8s: %10u\n", "WATCHDOG",
326*08578b8fSLuis R. Rodriguez 			sc->debug.stats.istats.bb_watchdog);
327a9616f41SLuis R. Rodriguez 	} else {
328203c4805SLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
329203c4805SLuis R. Rodriguez 			"%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
330a9616f41SLuis R. Rodriguez 	}
331203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
332203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol);
333203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
334203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn);
335203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
336203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TX", sc->debug.stats.istats.txok);
337203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
338203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn);
339203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
340203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "MIB", sc->debug.stats.istats.mib);
341203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
342203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr);
343203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
344203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss);
345203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
346203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba);
347203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
348203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss);
349203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
350203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr);
351203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
352203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "CST", sc->debug.stats.istats.cst);
353203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
354203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt);
355203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
356203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TIM", sc->debug.stats.istats.tim);
357203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
358203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend);
359203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
360203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync);
361203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
362203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim);
363203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
364203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total);
365203c4805SLuis R. Rodriguez 
366203c4805SLuis R. Rodriguez 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
367203c4805SLuis R. Rodriguez }
368203c4805SLuis R. Rodriguez 
369203c4805SLuis R. Rodriguez static const struct file_operations fops_interrupt = {
370203c4805SLuis R. Rodriguez 	.read = read_file_interrupt,
371203c4805SLuis R. Rodriguez 	.open = ath9k_debugfs_open,
372203c4805SLuis R. Rodriguez 	.owner = THIS_MODULE
373203c4805SLuis R. Rodriguez };
374203c4805SLuis R. Rodriguez 
375545750d3SFelix Fietkau void ath_debug_stat_rc(struct ath_softc *sc, int final_rate)
376203c4805SLuis R. Rodriguez {
377bedf087aSJeff Hansen 	struct ath_rc_stats *stats;
378203c4805SLuis R. Rodriguez 
379545750d3SFelix Fietkau 	stats = &sc->debug.stats.rcstats[final_rate];
380bedf087aSJeff Hansen 	stats->success++;
381203c4805SLuis R. Rodriguez }
382203c4805SLuis R. Rodriguez 
383203c4805SLuis R. Rodriguez void ath_debug_stat_retries(struct ath_softc *sc, int rix,
384203c4805SLuis R. Rodriguez 			    int xretries, int retries, u8 per)
385203c4805SLuis R. Rodriguez {
386bedf087aSJeff Hansen 	struct ath_rc_stats *stats = &sc->debug.stats.rcstats[rix];
387203c4805SLuis R. Rodriguez 
388bedf087aSJeff Hansen 	stats->xretries += xretries;
389bedf087aSJeff Hansen 	stats->retries += retries;
390bedf087aSJeff Hansen 	stats->per = per;
391203c4805SLuis R. Rodriguez }
392203c4805SLuis R. Rodriguez 
393203c4805SLuis R. Rodriguez static ssize_t read_file_rcstat(struct file *file, char __user *user_buf,
394203c4805SLuis R. Rodriguez 				size_t count, loff_t *ppos)
395203c4805SLuis R. Rodriguez {
396203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
397bedf087aSJeff Hansen 	char *buf;
398bedf087aSJeff Hansen 	unsigned int len = 0, max;
399bedf087aSJeff Hansen 	int i = 0;
400bedf087aSJeff Hansen 	ssize_t retval;
401203c4805SLuis R. Rodriguez 
402203c4805SLuis R. Rodriguez 	if (sc->cur_rate_table == NULL)
403203c4805SLuis R. Rodriguez 		return 0;
404203c4805SLuis R. Rodriguez 
405c755ad34SLuis R. Rodriguez 	max = 80 + sc->cur_rate_table->rate_cnt * 1024;
406bedf087aSJeff Hansen 	buf = kmalloc(max + 1, GFP_KERNEL);
407bedf087aSJeff Hansen 	if (buf == NULL)
408bedf087aSJeff Hansen 		return 0;
409bedf087aSJeff Hansen 	buf[max] = 0;
410bedf087aSJeff Hansen 
411c755ad34SLuis R. Rodriguez 	len += sprintf(buf, "%6s %6s %6s "
412c755ad34SLuis R. Rodriguez 		       "%10s %10s %10s %10s\n",
413c755ad34SLuis R. Rodriguez 		       "HT", "MCS", "Rate",
414c755ad34SLuis R. Rodriguez 		       "Success", "Retries", "XRetries", "PER");
415bedf087aSJeff Hansen 
416bedf087aSJeff Hansen 	for (i = 0; i < sc->cur_rate_table->rate_cnt; i++) {
417bedf087aSJeff Hansen 		u32 ratekbps = sc->cur_rate_table->info[i].ratekbps;
418bedf087aSJeff Hansen 		struct ath_rc_stats *stats = &sc->debug.stats.rcstats[i];
419c755ad34SLuis R. Rodriguez 		char mcs[5];
420c755ad34SLuis R. Rodriguez 		char htmode[5];
421c755ad34SLuis R. Rodriguez 		int used_mcs = 0, used_htmode = 0;
422c755ad34SLuis R. Rodriguez 
423c755ad34SLuis R. Rodriguez 		if (WLAN_RC_PHY_HT(sc->cur_rate_table->info[i].phy)) {
424c755ad34SLuis R. Rodriguez 			used_mcs = snprintf(mcs, 5, "%d",
425c755ad34SLuis R. Rodriguez 				sc->cur_rate_table->info[i].ratecode);
426c755ad34SLuis R. Rodriguez 
427c755ad34SLuis R. Rodriguez 			if (WLAN_RC_PHY_40(sc->cur_rate_table->info[i].phy))
428c755ad34SLuis R. Rodriguez 				used_htmode = snprintf(htmode, 5, "HT40");
429c755ad34SLuis R. Rodriguez 			else if (WLAN_RC_PHY_20(sc->cur_rate_table->info[i].phy))
430c755ad34SLuis R. Rodriguez 				used_htmode = snprintf(htmode, 5, "HT20");
431c755ad34SLuis R. Rodriguez 			else
432c755ad34SLuis R. Rodriguez 				used_htmode = snprintf(htmode, 5, "????");
433c755ad34SLuis R. Rodriguez 		}
434c755ad34SLuis R. Rodriguez 
435c755ad34SLuis R. Rodriguez 		mcs[used_mcs] = '\0';
436c755ad34SLuis R. Rodriguez 		htmode[used_htmode] = '\0';
437bedf087aSJeff Hansen 
438bedf087aSJeff Hansen 		len += snprintf(buf + len, max - len,
439c755ad34SLuis R. Rodriguez 			"%6s %6s %3u.%d: "
440c755ad34SLuis R. Rodriguez 			"%10u %10u %10u %10u\n",
441c755ad34SLuis R. Rodriguez 			htmode,
442c755ad34SLuis R. Rodriguez 			mcs,
443c755ad34SLuis R. Rodriguez 			ratekbps / 1000,
444c755ad34SLuis R. Rodriguez 			(ratekbps % 1000) / 100,
445c755ad34SLuis R. Rodriguez 			stats->success,
446c755ad34SLuis R. Rodriguez 			stats->retries,
447c755ad34SLuis R. Rodriguez 			stats->xretries,
448bedf087aSJeff Hansen 			stats->per);
449bedf087aSJeff Hansen 	}
450bedf087aSJeff Hansen 
451bedf087aSJeff Hansen 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
452bedf087aSJeff Hansen 	kfree(buf);
453bedf087aSJeff Hansen 	return retval;
454203c4805SLuis R. Rodriguez }
455203c4805SLuis R. Rodriguez 
456203c4805SLuis R. Rodriguez static const struct file_operations fops_rcstat = {
457203c4805SLuis R. Rodriguez 	.read = read_file_rcstat,
458203c4805SLuis R. Rodriguez 	.open = ath9k_debugfs_open,
459203c4805SLuis R. Rodriguez 	.owner = THIS_MODULE
460203c4805SLuis R. Rodriguez };
461203c4805SLuis R. Rodriguez 
462203c4805SLuis R. Rodriguez static const char * ath_wiphy_state_str(enum ath_wiphy_state state)
463203c4805SLuis R. Rodriguez {
464203c4805SLuis R. Rodriguez 	switch (state) {
465203c4805SLuis R. Rodriguez 	case ATH_WIPHY_INACTIVE:
466203c4805SLuis R. Rodriguez 		return "INACTIVE";
467203c4805SLuis R. Rodriguez 	case ATH_WIPHY_ACTIVE:
468203c4805SLuis R. Rodriguez 		return "ACTIVE";
469203c4805SLuis R. Rodriguez 	case ATH_WIPHY_PAUSING:
470203c4805SLuis R. Rodriguez 		return "PAUSING";
471203c4805SLuis R. Rodriguez 	case ATH_WIPHY_PAUSED:
472203c4805SLuis R. Rodriguez 		return "PAUSED";
473203c4805SLuis R. Rodriguez 	case ATH_WIPHY_SCAN:
474203c4805SLuis R. Rodriguez 		return "SCAN";
475203c4805SLuis R. Rodriguez 	}
476203c4805SLuis R. Rodriguez 	return "?";
477203c4805SLuis R. Rodriguez }
478203c4805SLuis R. Rodriguez 
479203c4805SLuis R. Rodriguez static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
480203c4805SLuis R. Rodriguez 			       size_t count, loff_t *ppos)
481203c4805SLuis R. Rodriguez {
482203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
483203c4805SLuis R. Rodriguez 	char buf[512];
484203c4805SLuis R. Rodriguez 	unsigned int len = 0;
485203c4805SLuis R. Rodriguez 	int i;
486203c4805SLuis R. Rodriguez 	u8 addr[ETH_ALEN];
487203c4805SLuis R. Rodriguez 
488203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
489203c4805SLuis R. Rodriguez 			"primary: %s (%s chan=%d ht=%d)\n",
490203c4805SLuis R. Rodriguez 			wiphy_name(sc->pri_wiphy->hw->wiphy),
491203c4805SLuis R. Rodriguez 			ath_wiphy_state_str(sc->pri_wiphy->state),
492203c4805SLuis R. Rodriguez 			sc->pri_wiphy->chan_idx, sc->pri_wiphy->chan_is_ht);
493203c4805SLuis R. Rodriguez 	for (i = 0; i < sc->num_sec_wiphy; i++) {
494203c4805SLuis R. Rodriguez 		struct ath_wiphy *aphy = sc->sec_wiphy[i];
495203c4805SLuis R. Rodriguez 		if (aphy == NULL)
496203c4805SLuis R. Rodriguez 			continue;
497203c4805SLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
498203c4805SLuis R. Rodriguez 				"secondary: %s (%s chan=%d ht=%d)\n",
499203c4805SLuis R. Rodriguez 				wiphy_name(aphy->hw->wiphy),
500203c4805SLuis R. Rodriguez 				ath_wiphy_state_str(aphy->state),
501203c4805SLuis R. Rodriguez 				aphy->chan_idx, aphy->chan_is_ht);
502203c4805SLuis R. Rodriguez 	}
503203c4805SLuis R. Rodriguez 
504475a6e4dSLuis R. Rodriguez 	put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr);
505475a6e4dSLuis R. Rodriguez 	put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
506203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
507203c4805SLuis R. Rodriguez 			"addr: %pM\n", addr);
508475a6e4dSLuis R. Rodriguez 	put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr);
509475a6e4dSLuis R. Rodriguez 	put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
510203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
511203c4805SLuis R. Rodriguez 			"addrmask: %pM\n", addr);
512203c4805SLuis R. Rodriguez 
513203c4805SLuis R. Rodriguez 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
514203c4805SLuis R. Rodriguez }
515203c4805SLuis R. Rodriguez 
516203c4805SLuis R. Rodriguez static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name)
517203c4805SLuis R. Rodriguez {
518203c4805SLuis R. Rodriguez 	int i;
519203c4805SLuis R. Rodriguez 	if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0)
520203c4805SLuis R. Rodriguez 		return sc->pri_wiphy;
521203c4805SLuis R. Rodriguez 	for (i = 0; i < sc->num_sec_wiphy; i++) {
522203c4805SLuis R. Rodriguez 		struct ath_wiphy *aphy = sc->sec_wiphy[i];
523203c4805SLuis R. Rodriguez 		if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0)
524203c4805SLuis R. Rodriguez 			return aphy;
525203c4805SLuis R. Rodriguez 	}
526203c4805SLuis R. Rodriguez 	return NULL;
527203c4805SLuis R. Rodriguez }
528203c4805SLuis R. Rodriguez 
529203c4805SLuis R. Rodriguez static int del_wiphy(struct ath_softc *sc, const char *name)
530203c4805SLuis R. Rodriguez {
531203c4805SLuis R. Rodriguez 	struct ath_wiphy *aphy = get_wiphy(sc, name);
532203c4805SLuis R. Rodriguez 	if (!aphy)
533203c4805SLuis R. Rodriguez 		return -ENOENT;
534203c4805SLuis R. Rodriguez 	return ath9k_wiphy_del(aphy);
535203c4805SLuis R. Rodriguez }
536203c4805SLuis R. Rodriguez 
537203c4805SLuis R. Rodriguez static int pause_wiphy(struct ath_softc *sc, const char *name)
538203c4805SLuis R. Rodriguez {
539203c4805SLuis R. Rodriguez 	struct ath_wiphy *aphy = get_wiphy(sc, name);
540203c4805SLuis R. Rodriguez 	if (!aphy)
541203c4805SLuis R. Rodriguez 		return -ENOENT;
542203c4805SLuis R. Rodriguez 	return ath9k_wiphy_pause(aphy);
543203c4805SLuis R. Rodriguez }
544203c4805SLuis R. Rodriguez 
545203c4805SLuis R. Rodriguez static int unpause_wiphy(struct ath_softc *sc, const char *name)
546203c4805SLuis R. Rodriguez {
547203c4805SLuis R. Rodriguez 	struct ath_wiphy *aphy = get_wiphy(sc, name);
548203c4805SLuis R. Rodriguez 	if (!aphy)
549203c4805SLuis R. Rodriguez 		return -ENOENT;
550203c4805SLuis R. Rodriguez 	return ath9k_wiphy_unpause(aphy);
551203c4805SLuis R. Rodriguez }
552203c4805SLuis R. Rodriguez 
553203c4805SLuis R. Rodriguez static int select_wiphy(struct ath_softc *sc, const char *name)
554203c4805SLuis R. Rodriguez {
555203c4805SLuis R. Rodriguez 	struct ath_wiphy *aphy = get_wiphy(sc, name);
556203c4805SLuis R. Rodriguez 	if (!aphy)
557203c4805SLuis R. Rodriguez 		return -ENOENT;
558203c4805SLuis R. Rodriguez 	return ath9k_wiphy_select(aphy);
559203c4805SLuis R. Rodriguez }
560203c4805SLuis R. Rodriguez 
561203c4805SLuis R. Rodriguez static int schedule_wiphy(struct ath_softc *sc, const char *msec)
562203c4805SLuis R. Rodriguez {
563203c4805SLuis R. Rodriguez 	ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0));
564203c4805SLuis R. Rodriguez 	return 0;
565203c4805SLuis R. Rodriguez }
566203c4805SLuis R. Rodriguez 
567203c4805SLuis R. Rodriguez static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf,
568203c4805SLuis R. Rodriguez 				size_t count, loff_t *ppos)
569203c4805SLuis R. Rodriguez {
570203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
571203c4805SLuis R. Rodriguez 	char buf[50];
572203c4805SLuis R. Rodriguez 	size_t len;
573203c4805SLuis R. Rodriguez 
574203c4805SLuis R. Rodriguez 	len = min(count, sizeof(buf) - 1);
575203c4805SLuis R. Rodriguez 	if (copy_from_user(buf, user_buf, len))
576203c4805SLuis R. Rodriguez 		return -EFAULT;
577203c4805SLuis R. Rodriguez 	buf[len] = '\0';
578203c4805SLuis R. Rodriguez 	if (len > 0 && buf[len - 1] == '\n')
579203c4805SLuis R. Rodriguez 		buf[len - 1] = '\0';
580203c4805SLuis R. Rodriguez 
581203c4805SLuis R. Rodriguez 	if (strncmp(buf, "add", 3) == 0) {
582203c4805SLuis R. Rodriguez 		int res = ath9k_wiphy_add(sc);
583203c4805SLuis R. Rodriguez 		if (res < 0)
584203c4805SLuis R. Rodriguez 			return res;
585203c4805SLuis R. Rodriguez 	} else if (strncmp(buf, "del=", 4) == 0) {
586203c4805SLuis R. Rodriguez 		int res = del_wiphy(sc, buf + 4);
587203c4805SLuis R. Rodriguez 		if (res < 0)
588203c4805SLuis R. Rodriguez 			return res;
589203c4805SLuis R. Rodriguez 	} else if (strncmp(buf, "pause=", 6) == 0) {
590203c4805SLuis R. Rodriguez 		int res = pause_wiphy(sc, buf + 6);
591203c4805SLuis R. Rodriguez 		if (res < 0)
592203c4805SLuis R. Rodriguez 			return res;
593203c4805SLuis R. Rodriguez 	} else if (strncmp(buf, "unpause=", 8) == 0) {
594203c4805SLuis R. Rodriguez 		int res = unpause_wiphy(sc, buf + 8);
595203c4805SLuis R. Rodriguez 		if (res < 0)
596203c4805SLuis R. Rodriguez 			return res;
597203c4805SLuis R. Rodriguez 	} else if (strncmp(buf, "select=", 7) == 0) {
598203c4805SLuis R. Rodriguez 		int res = select_wiphy(sc, buf + 7);
599203c4805SLuis R. Rodriguez 		if (res < 0)
600203c4805SLuis R. Rodriguez 			return res;
601203c4805SLuis R. Rodriguez 	} else if (strncmp(buf, "schedule=", 9) == 0) {
602203c4805SLuis R. Rodriguez 		int res = schedule_wiphy(sc, buf + 9);
603203c4805SLuis R. Rodriguez 		if (res < 0)
604203c4805SLuis R. Rodriguez 			return res;
605203c4805SLuis R. Rodriguez 	} else
606203c4805SLuis R. Rodriguez 		return -EOPNOTSUPP;
607203c4805SLuis R. Rodriguez 
608203c4805SLuis R. Rodriguez 	return count;
609203c4805SLuis R. Rodriguez }
610203c4805SLuis R. Rodriguez 
611203c4805SLuis R. Rodriguez static const struct file_operations fops_wiphy = {
612203c4805SLuis R. Rodriguez 	.read = read_file_wiphy,
613203c4805SLuis R. Rodriguez 	.write = write_file_wiphy,
614203c4805SLuis R. Rodriguez 	.open = ath9k_debugfs_open,
615203c4805SLuis R. Rodriguez 	.owner = THIS_MODULE
616203c4805SLuis R. Rodriguez };
617203c4805SLuis R. Rodriguez 
618fec247c0SSujith #define PR(str, elem)							\
619fec247c0SSujith 	do {								\
620fec247c0SSujith 		len += snprintf(buf + len, size - len,			\
621fec247c0SSujith 				"%s%13u%11u%10u%10u\n", str,		\
622fec247c0SSujith 		sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BE]].elem, \
623fec247c0SSujith 		sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BK]].elem, \
624fec247c0SSujith 		sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VI]].elem, \
625fec247c0SSujith 		sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VO]].elem); \
626fec247c0SSujith } while(0)
627fec247c0SSujith 
628fec247c0SSujith static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
629fec247c0SSujith 			      size_t count, loff_t *ppos)
630fec247c0SSujith {
631fec247c0SSujith 	struct ath_softc *sc = file->private_data;
632fec247c0SSujith 	char *buf;
633fec247c0SSujith 	unsigned int len = 0, size = 2048;
634fec247c0SSujith 	ssize_t retval = 0;
635fec247c0SSujith 
636fec247c0SSujith 	buf = kzalloc(size, GFP_KERNEL);
637fec247c0SSujith 	if (buf == NULL)
638fec247c0SSujith 		return 0;
639fec247c0SSujith 
640fec247c0SSujith 	len += sprintf(buf, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
641fec247c0SSujith 
642fec247c0SSujith 	PR("MPDUs Queued:    ", queued);
643fec247c0SSujith 	PR("MPDUs Completed: ", completed);
644fec247c0SSujith 	PR("Aggregates:      ", a_aggr);
645fec247c0SSujith 	PR("AMPDUs Queued:   ", a_queued);
646fec247c0SSujith 	PR("AMPDUs Completed:", a_completed);
647fec247c0SSujith 	PR("AMPDUs Retried:  ", a_retries);
648fec247c0SSujith 	PR("AMPDUs XRetried: ", a_xretries);
649fec247c0SSujith 	PR("FIFO Underrun:   ", fifo_underrun);
650fec247c0SSujith 	PR("TXOP Exceeded:   ", xtxop);
651fec247c0SSujith 	PR("TXTIMER Expiry:  ", timer_exp);
652fec247c0SSujith 	PR("DESC CFG Error:  ", desc_cfg_err);
653fec247c0SSujith 	PR("DATA Underrun:   ", data_underrun);
654fec247c0SSujith 	PR("DELIM Underrun:  ", delim_underrun);
655fec247c0SSujith 
656fec247c0SSujith 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
657fec247c0SSujith 	kfree(buf);
658fec247c0SSujith 
659fec247c0SSujith 	return retval;
660fec247c0SSujith }
661fec247c0SSujith 
662fec247c0SSujith void ath_debug_stat_tx(struct ath_softc *sc, struct ath_txq *txq,
663db1a052bSFelix Fietkau 		       struct ath_buf *bf, struct ath_tx_status *ts)
664fec247c0SSujith {
665fec247c0SSujith 	if (bf_isampdu(bf)) {
666fec247c0SSujith 		if (bf_isxretried(bf))
667fec247c0SSujith 			TX_STAT_INC(txq->axq_qnum, a_xretries);
668fec247c0SSujith 		else
669fec247c0SSujith 			TX_STAT_INC(txq->axq_qnum, a_completed);
670fec247c0SSujith 	} else {
671fec247c0SSujith 		TX_STAT_INC(txq->axq_qnum, completed);
672fec247c0SSujith 	}
673fec247c0SSujith 
674db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_FIFO)
675fec247c0SSujith 		TX_STAT_INC(txq->axq_qnum, fifo_underrun);
676db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_XTXOP)
677fec247c0SSujith 		TX_STAT_INC(txq->axq_qnum, xtxop);
678db1a052bSFelix Fietkau 	if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
679fec247c0SSujith 		TX_STAT_INC(txq->axq_qnum, timer_exp);
680db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
681fec247c0SSujith 		TX_STAT_INC(txq->axq_qnum, desc_cfg_err);
682db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
683fec247c0SSujith 		TX_STAT_INC(txq->axq_qnum, data_underrun);
684db1a052bSFelix Fietkau 	if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
685fec247c0SSujith 		TX_STAT_INC(txq->axq_qnum, delim_underrun);
686fec247c0SSujith }
687fec247c0SSujith 
688fec247c0SSujith static const struct file_operations fops_xmit = {
689fec247c0SSujith 	.read = read_file_xmit,
690fec247c0SSujith 	.open = ath9k_debugfs_open,
691fec247c0SSujith 	.owner = THIS_MODULE
692fec247c0SSujith };
693203c4805SLuis R. Rodriguez 
6941395d3f0SSujith static ssize_t read_file_recv(struct file *file, char __user *user_buf,
6951395d3f0SSujith 			      size_t count, loff_t *ppos)
6961395d3f0SSujith {
6971395d3f0SSujith #define PHY_ERR(s, p) \
6981395d3f0SSujith 	len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \
6991395d3f0SSujith 			sc->debug.stats.rxstats.phy_err_stats[p]);
7001395d3f0SSujith 
7011395d3f0SSujith 	struct ath_softc *sc = file->private_data;
7021395d3f0SSujith 	char *buf;
7031395d3f0SSujith 	unsigned int len = 0, size = 1152;
7041395d3f0SSujith 	ssize_t retval = 0;
7051395d3f0SSujith 
7061395d3f0SSujith 	buf = kzalloc(size, GFP_KERNEL);
7071395d3f0SSujith 	if (buf == NULL)
7081395d3f0SSujith 		return 0;
7091395d3f0SSujith 
7101395d3f0SSujith 	len += snprintf(buf + len, size - len,
7111395d3f0SSujith 			"%18s : %10u\n", "CRC ERR",
7121395d3f0SSujith 			sc->debug.stats.rxstats.crc_err);
7131395d3f0SSujith 	len += snprintf(buf + len, size - len,
7141395d3f0SSujith 			"%18s : %10u\n", "DECRYPT CRC ERR",
7151395d3f0SSujith 			sc->debug.stats.rxstats.decrypt_crc_err);
7161395d3f0SSujith 	len += snprintf(buf + len, size - len,
7171395d3f0SSujith 			"%18s : %10u\n", "PHY ERR",
7181395d3f0SSujith 			sc->debug.stats.rxstats.phy_err);
7191395d3f0SSujith 	len += snprintf(buf + len, size - len,
7201395d3f0SSujith 			"%18s : %10u\n", "MIC ERR",
7211395d3f0SSujith 			sc->debug.stats.rxstats.mic_err);
7221395d3f0SSujith 	len += snprintf(buf + len, size - len,
7231395d3f0SSujith 			"%18s : %10u\n", "PRE-DELIM CRC ERR",
7241395d3f0SSujith 			sc->debug.stats.rxstats.pre_delim_crc_err);
7251395d3f0SSujith 	len += snprintf(buf + len, size - len,
7261395d3f0SSujith 			"%18s : %10u\n", "POST-DELIM CRC ERR",
7271395d3f0SSujith 			sc->debug.stats.rxstats.post_delim_crc_err);
7281395d3f0SSujith 	len += snprintf(buf + len, size - len,
7291395d3f0SSujith 			"%18s : %10u\n", "DECRYPT BUSY ERR",
7301395d3f0SSujith 			sc->debug.stats.rxstats.decrypt_busy_err);
7311395d3f0SSujith 
7321395d3f0SSujith 	PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN);
7331395d3f0SSujith 	PHY_ERR("TIMING", ATH9K_PHYERR_TIMING);
7341395d3f0SSujith 	PHY_ERR("PARITY", ATH9K_PHYERR_PARITY);
7351395d3f0SSujith 	PHY_ERR("RATE", ATH9K_PHYERR_RATE);
7361395d3f0SSujith 	PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH);
7371395d3f0SSujith 	PHY_ERR("RADAR", ATH9K_PHYERR_RADAR);
7381395d3f0SSujith 	PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE);
7391395d3f0SSujith 	PHY_ERR("TOR", ATH9K_PHYERR_TOR);
7401395d3f0SSujith 	PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING);
7411395d3f0SSujith 	PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
7421395d3f0SSujith 	PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
7431395d3f0SSujith 	PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
7441395d3f0SSujith 	PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP);
7451395d3f0SSujith 	PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE);
7461395d3f0SSujith 	PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART);
7471395d3f0SSujith 	PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT);
7481395d3f0SSujith 	PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING);
7491395d3f0SSujith 	PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC);
7501395d3f0SSujith 	PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
7511395d3f0SSujith 	PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE);
7521395d3f0SSujith 	PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART);
7531395d3f0SSujith 	PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
7541395d3f0SSujith 	PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP);
7551395d3f0SSujith 	PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR);
7561395d3f0SSujith 	PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
7571395d3f0SSujith 	PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL);
7581395d3f0SSujith 
7591395d3f0SSujith 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
7601395d3f0SSujith 	kfree(buf);
7611395d3f0SSujith 
7621395d3f0SSujith 	return retval;
7631395d3f0SSujith 
7641395d3f0SSujith #undef PHY_ERR
7651395d3f0SSujith }
7661395d3f0SSujith 
7678e6f5aa2SFelix Fietkau void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
7681395d3f0SSujith {
7691395d3f0SSujith #define RX_STAT_INC(c) sc->debug.stats.rxstats.c++
7701395d3f0SSujith #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
7711395d3f0SSujith 
7721395d3f0SSujith 	u32 phyerr;
7731395d3f0SSujith 
7748e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_CRC)
7751395d3f0SSujith 		RX_STAT_INC(crc_err);
7768e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_DECRYPT)
7771395d3f0SSujith 		RX_STAT_INC(decrypt_crc_err);
7788e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_MIC)
7791395d3f0SSujith 		RX_STAT_INC(mic_err);
7808e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
7811395d3f0SSujith 		RX_STAT_INC(pre_delim_crc_err);
7828e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
7831395d3f0SSujith 		RX_STAT_INC(post_delim_crc_err);
7848e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
7851395d3f0SSujith 		RX_STAT_INC(decrypt_busy_err);
7861395d3f0SSujith 
7878e6f5aa2SFelix Fietkau 	if (rs->rs_status & ATH9K_RXERR_PHY) {
7881395d3f0SSujith 		RX_STAT_INC(phy_err);
7898e6f5aa2SFelix Fietkau 		phyerr = rs->rs_phyerr & 0x24;
7901395d3f0SSujith 		RX_PHY_ERR_INC(phyerr);
7911395d3f0SSujith 	}
7921395d3f0SSujith 
7931395d3f0SSujith #undef RX_STAT_INC
7941395d3f0SSujith #undef RX_PHY_ERR_INC
7951395d3f0SSujith }
7961395d3f0SSujith 
7971395d3f0SSujith static const struct file_operations fops_recv = {
7981395d3f0SSujith 	.read = read_file_recv,
7991395d3f0SSujith 	.open = ath9k_debugfs_open,
8001395d3f0SSujith 	.owner = THIS_MODULE
8011395d3f0SSujith };
8021395d3f0SSujith 
8039bff0bc4SFelix Fietkau static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
8049bff0bc4SFelix Fietkau                                 size_t count, loff_t *ppos)
8059bff0bc4SFelix Fietkau {
8069bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
8079bff0bc4SFelix Fietkau 	char buf[32];
8089bff0bc4SFelix Fietkau 	unsigned int len;
8099bff0bc4SFelix Fietkau 
8109bff0bc4SFelix Fietkau 	len = snprintf(buf, sizeof(buf), "0x%08x\n", sc->debug.regidx);
8119bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
8129bff0bc4SFelix Fietkau }
8139bff0bc4SFelix Fietkau 
8149bff0bc4SFelix Fietkau static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
8159bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
8169bff0bc4SFelix Fietkau {
8179bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
8189bff0bc4SFelix Fietkau 	unsigned long regidx;
8199bff0bc4SFelix Fietkau 	char buf[32];
8209bff0bc4SFelix Fietkau 	ssize_t len;
8219bff0bc4SFelix Fietkau 
8229bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
8239bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
8249bff0bc4SFelix Fietkau 		return -EINVAL;
8259bff0bc4SFelix Fietkau 
8269bff0bc4SFelix Fietkau 	buf[len] = '\0';
8279bff0bc4SFelix Fietkau 	if (strict_strtoul(buf, 0, &regidx))
8289bff0bc4SFelix Fietkau 		return -EINVAL;
8299bff0bc4SFelix Fietkau 
8309bff0bc4SFelix Fietkau 	sc->debug.regidx = regidx;
8319bff0bc4SFelix Fietkau 	return count;
8329bff0bc4SFelix Fietkau }
8339bff0bc4SFelix Fietkau 
8349bff0bc4SFelix Fietkau static const struct file_operations fops_regidx = {
8359bff0bc4SFelix Fietkau 	.read = read_file_regidx,
8369bff0bc4SFelix Fietkau 	.write = write_file_regidx,
8379bff0bc4SFelix Fietkau 	.open = ath9k_debugfs_open,
8389bff0bc4SFelix Fietkau 	.owner = THIS_MODULE
8399bff0bc4SFelix Fietkau };
8409bff0bc4SFelix Fietkau 
8419bff0bc4SFelix Fietkau static ssize_t read_file_regval(struct file *file, char __user *user_buf,
8429bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
8439bff0bc4SFelix Fietkau {
8449bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
8459bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
8469bff0bc4SFelix Fietkau 	char buf[32];
8479bff0bc4SFelix Fietkau 	unsigned int len;
8489bff0bc4SFelix Fietkau 	u32 regval;
8499bff0bc4SFelix Fietkau 
8509bff0bc4SFelix Fietkau 	regval = REG_READ_D(ah, sc->debug.regidx);
8519bff0bc4SFelix Fietkau 	len = snprintf(buf, sizeof(buf), "0x%08x\n", regval);
8529bff0bc4SFelix Fietkau 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
8539bff0bc4SFelix Fietkau }
8549bff0bc4SFelix Fietkau 
8559bff0bc4SFelix Fietkau static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
8569bff0bc4SFelix Fietkau 			     size_t count, loff_t *ppos)
8579bff0bc4SFelix Fietkau {
8589bff0bc4SFelix Fietkau 	struct ath_softc *sc = file->private_data;
8599bff0bc4SFelix Fietkau 	struct ath_hw *ah = sc->sc_ah;
8609bff0bc4SFelix Fietkau 	unsigned long regval;
8619bff0bc4SFelix Fietkau 	char buf[32];
8629bff0bc4SFelix Fietkau 	ssize_t len;
8639bff0bc4SFelix Fietkau 
8649bff0bc4SFelix Fietkau 	len = min(count, sizeof(buf) - 1);
8659bff0bc4SFelix Fietkau 	if (copy_from_user(buf, user_buf, len))
8669bff0bc4SFelix Fietkau 		return -EINVAL;
8679bff0bc4SFelix Fietkau 
8689bff0bc4SFelix Fietkau 	buf[len] = '\0';
8699bff0bc4SFelix Fietkau 	if (strict_strtoul(buf, 0, &regval))
8709bff0bc4SFelix Fietkau 		return -EINVAL;
8719bff0bc4SFelix Fietkau 
8729bff0bc4SFelix Fietkau 	REG_WRITE_D(ah, sc->debug.regidx, regval);
8739bff0bc4SFelix Fietkau 	return count;
8749bff0bc4SFelix Fietkau }
8759bff0bc4SFelix Fietkau 
8769bff0bc4SFelix Fietkau static const struct file_operations fops_regval = {
8779bff0bc4SFelix Fietkau 	.read = read_file_regval,
8789bff0bc4SFelix Fietkau 	.write = write_file_regval,
8799bff0bc4SFelix Fietkau 	.open = ath9k_debugfs_open,
8809bff0bc4SFelix Fietkau 	.owner = THIS_MODULE
8819bff0bc4SFelix Fietkau };
8829bff0bc4SFelix Fietkau 
8834d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah)
884203c4805SLuis R. Rodriguez {
885bc974f4aSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(ah);
886bc974f4aSLuis R. Rodriguez 	struct ath_softc *sc = (struct ath_softc *) common->priv;
8874d6b228dSLuis R. Rodriguez 
888203c4805SLuis R. Rodriguez 	if (!ath9k_debugfs_root)
889203c4805SLuis R. Rodriguez 		return -ENOENT;
890203c4805SLuis R. Rodriguez 
891203c4805SLuis R. Rodriguez 	sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
892203c4805SLuis R. Rodriguez 						      ath9k_debugfs_root);
893203c4805SLuis R. Rodriguez 	if (!sc->debug.debugfs_phy)
894c8a72c00SFelix Fietkau 		return -ENOMEM;
895203c4805SLuis R. Rodriguez 
896a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG
897c8a72c00SFelix Fietkau 	if (!debugfs_create_file("debug", S_IRUSR | S_IWUSR,
898c8a72c00SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_debug))
8992493928eSJeff Hansen 		goto err;
900a830df07SFelix Fietkau #endif
9012493928eSJeff Hansen 
902c8a72c00SFelix Fietkau 	if (!debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy,
903c8a72c00SFelix Fietkau 			sc, &fops_dma))
904203c4805SLuis R. Rodriguez 		goto err;
905203c4805SLuis R. Rodriguez 
906c8a72c00SFelix Fietkau 	if (!debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy,
907c8a72c00SFelix Fietkau 			sc, &fops_interrupt))
908203c4805SLuis R. Rodriguez 		goto err;
909203c4805SLuis R. Rodriguez 
910c8a72c00SFelix Fietkau 	if (!debugfs_create_file("rcstat", S_IRUSR, sc->debug.debugfs_phy,
911c8a72c00SFelix Fietkau 			sc, &fops_rcstat))
912203c4805SLuis R. Rodriguez 		goto err;
913203c4805SLuis R. Rodriguez 
914c8a72c00SFelix Fietkau 	if (!debugfs_create_file("wiphy", S_IRUSR | S_IWUSR,
915c8a72c00SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_wiphy))
916203c4805SLuis R. Rodriguez 		goto err;
917203c4805SLuis R. Rodriguez 
918c8a72c00SFelix Fietkau 	if (!debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy,
919c8a72c00SFelix Fietkau 			sc, &fops_xmit))
920fec247c0SSujith 		goto err;
921fec247c0SSujith 
922c8a72c00SFelix Fietkau 	if (!debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy,
923c8a72c00SFelix Fietkau 			sc, &fops_recv))
9241395d3f0SSujith 		goto err;
9251395d3f0SSujith 
92615340694SFelix Fietkau 	if (!debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
92715340694SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_rx_chainmask))
92815340694SFelix Fietkau 		goto err;
92915340694SFelix Fietkau 
93015340694SFelix Fietkau 	if (!debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
93115340694SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_tx_chainmask))
93215340694SFelix Fietkau 		goto err;
93315340694SFelix Fietkau 
9349bff0bc4SFelix Fietkau 	if (!debugfs_create_file("regidx", S_IRUSR | S_IWUSR,
9359bff0bc4SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_regidx))
9369bff0bc4SFelix Fietkau 		goto err;
9379bff0bc4SFelix Fietkau 
9389bff0bc4SFelix Fietkau 	if (!debugfs_create_file("regval", S_IRUSR | S_IWUSR,
9399bff0bc4SFelix Fietkau 			sc->debug.debugfs_phy, sc, &fops_regval))
9409bff0bc4SFelix Fietkau 		goto err;
9419bff0bc4SFelix Fietkau 
9429bff0bc4SFelix Fietkau 	sc->debug.regidx = 0;
943203c4805SLuis R. Rodriguez 	return 0;
944203c4805SLuis R. Rodriguez err:
9454d6b228dSLuis R. Rodriguez 	ath9k_exit_debug(ah);
946203c4805SLuis R. Rodriguez 	return -ENOMEM;
947203c4805SLuis R. Rodriguez }
948203c4805SLuis R. Rodriguez 
9494d6b228dSLuis R. Rodriguez void ath9k_exit_debug(struct ath_hw *ah)
950203c4805SLuis R. Rodriguez {
951bc974f4aSLuis R. Rodriguez 	struct ath_common *common = ath9k_hw_common(ah);
952bc974f4aSLuis R. Rodriguez 	struct ath_softc *sc = (struct ath_softc *) common->priv;
9534d6b228dSLuis R. Rodriguez 
954c8a72c00SFelix Fietkau 	debugfs_remove_recursive(sc->debug.debugfs_phy);
955203c4805SLuis R. Rodriguez }
956203c4805SLuis R. Rodriguez 
957203c4805SLuis R. Rodriguez int ath9k_debug_create_root(void)
958203c4805SLuis R. Rodriguez {
959203c4805SLuis R. Rodriguez 	ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
960203c4805SLuis R. Rodriguez 	if (!ath9k_debugfs_root)
961203c4805SLuis R. Rodriguez 		return -ENOENT;
962203c4805SLuis R. Rodriguez 
963203c4805SLuis R. Rodriguez 	return 0;
964203c4805SLuis R. Rodriguez }
965203c4805SLuis R. Rodriguez 
966203c4805SLuis R. Rodriguez void ath9k_debug_remove_root(void)
967203c4805SLuis R. Rodriguez {
968203c4805SLuis R. Rodriguez 	debugfs_remove(ath9k_debugfs_root);
969203c4805SLuis R. Rodriguez 	ath9k_debugfs_root = NULL;
970203c4805SLuis R. Rodriguez }
971