xref: /openbmc/linux/drivers/net/wireless/ath/ath9k/debug.c (revision 4d6b228d84ba992ee13c90312c1ed539191c94b1)
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 
17203c4805SLuis R. Rodriguez #include <asm/unaligned.h>
18203c4805SLuis R. Rodriguez 
19203c4805SLuis R. Rodriguez #include "ath9k.h"
20203c4805SLuis R. Rodriguez 
21203c4805SLuis R. Rodriguez static unsigned int ath9k_debug = DBG_DEFAULT;
22203c4805SLuis R. Rodriguez module_param_named(debug, ath9k_debug, uint, 0);
23203c4805SLuis R. Rodriguez 
24203c4805SLuis R. Rodriguez static struct dentry *ath9k_debugfs_root;
25203c4805SLuis R. Rodriguez 
26*4d6b228dSLuis R. Rodriguez void DPRINTF(struct ath_hw *ah, int dbg_mask, const char *fmt, ...)
27203c4805SLuis R. Rodriguez {
28*4d6b228dSLuis R. Rodriguez 	if (!ah->ah_sc)
29203c4805SLuis R. Rodriguez 		return;
30203c4805SLuis R. Rodriguez 
31*4d6b228dSLuis R. Rodriguez 	if (ah->ah_sc->debug.debug_mask & dbg_mask) {
32203c4805SLuis R. Rodriguez 		va_list args;
33203c4805SLuis R. Rodriguez 
34203c4805SLuis R. Rodriguez 		va_start(args, fmt);
35203c4805SLuis R. Rodriguez 		printk(KERN_DEBUG "ath9k: ");
36203c4805SLuis R. Rodriguez 		vprintk(fmt, args);
37203c4805SLuis R. Rodriguez 		va_end(args);
38203c4805SLuis R. Rodriguez 	}
39203c4805SLuis R. Rodriguez }
40203c4805SLuis R. Rodriguez 
41203c4805SLuis R. Rodriguez static int ath9k_debugfs_open(struct inode *inode, struct file *file)
42203c4805SLuis R. Rodriguez {
43203c4805SLuis R. Rodriguez 	file->private_data = inode->i_private;
44203c4805SLuis R. Rodriguez 	return 0;
45203c4805SLuis R. Rodriguez }
46203c4805SLuis R. Rodriguez 
472493928eSJeff Hansen static ssize_t read_file_debug(struct file *file, char __user *user_buf,
482493928eSJeff Hansen 			     size_t count, loff_t *ppos)
492493928eSJeff Hansen {
502493928eSJeff Hansen 	struct ath_softc *sc = file->private_data;
512493928eSJeff Hansen 	char buf[32];
52581f725cSVasanthakumar Thiagarajan 	unsigned int len;
53581f725cSVasanthakumar Thiagarajan 
54581f725cSVasanthakumar Thiagarajan 	len = snprintf(buf, sizeof(buf), "0x%08x\n", sc->debug.debug_mask);
552493928eSJeff Hansen 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
562493928eSJeff Hansen }
572493928eSJeff Hansen 
582493928eSJeff Hansen static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
592493928eSJeff Hansen 			     size_t count, loff_t *ppos)
602493928eSJeff Hansen {
612493928eSJeff Hansen 	struct ath_softc *sc = file->private_data;
622493928eSJeff Hansen 	unsigned long mask;
632493928eSJeff Hansen 	char buf[32];
64581f725cSVasanthakumar Thiagarajan 	ssize_t len;
65581f725cSVasanthakumar Thiagarajan 
66581f725cSVasanthakumar Thiagarajan 	len = min(count, sizeof(buf) - 1);
67581f725cSVasanthakumar Thiagarajan 	if (copy_from_user(buf, user_buf, len))
68581f725cSVasanthakumar Thiagarajan 		return -EINVAL;
69581f725cSVasanthakumar Thiagarajan 
70581f725cSVasanthakumar Thiagarajan 	buf[len] = '\0';
71581f725cSVasanthakumar Thiagarajan 	if (strict_strtoul(buf, 0, &mask))
72581f725cSVasanthakumar Thiagarajan 		return -EINVAL;
73581f725cSVasanthakumar Thiagarajan 
742493928eSJeff Hansen 	sc->debug.debug_mask = mask;
752493928eSJeff Hansen 	return count;
762493928eSJeff Hansen }
772493928eSJeff Hansen 
782493928eSJeff Hansen static const struct file_operations fops_debug = {
792493928eSJeff Hansen 	.read = read_file_debug,
802493928eSJeff Hansen 	.write = write_file_debug,
812493928eSJeff Hansen 	.open = ath9k_debugfs_open,
822493928eSJeff Hansen 	.owner = THIS_MODULE
832493928eSJeff Hansen };
842493928eSJeff Hansen 
85203c4805SLuis R. Rodriguez static ssize_t read_file_dma(struct file *file, char __user *user_buf,
86203c4805SLuis R. Rodriguez 			     size_t count, loff_t *ppos)
87203c4805SLuis R. Rodriguez {
88203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
89203c4805SLuis R. Rodriguez 	struct ath_hw *ah = sc->sc_ah;
90203c4805SLuis R. Rodriguez 	char buf[1024];
91203c4805SLuis R. Rodriguez 	unsigned int len = 0;
92203c4805SLuis R. Rodriguez 	u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
93203c4805SLuis R. Rodriguez 	int i, qcuOffset = 0, dcuOffset = 0;
94203c4805SLuis R. Rodriguez 	u32 *qcuBase = &val[0], *dcuBase = &val[4];
95203c4805SLuis R. Rodriguez 
967cf4a2e7SSujith 	ath9k_ps_wakeup(sc);
977cf4a2e7SSujith 
98203c4805SLuis R. Rodriguez 	REG_WRITE(ah, AR_MACMISC,
99203c4805SLuis R. Rodriguez 		  ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
100203c4805SLuis R. Rodriguez 		   (AR_MACMISC_MISC_OBS_BUS_1 <<
101203c4805SLuis R. Rodriguez 		    AR_MACMISC_MISC_OBS_BUS_MSB_S)));
102203c4805SLuis R. Rodriguez 
103203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
104203c4805SLuis R. Rodriguez 			"Raw DMA Debug values:\n");
105203c4805SLuis R. Rodriguez 
106203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
107203c4805SLuis R. Rodriguez 		if (i % 4 == 0)
108203c4805SLuis R. Rodriguez 			len += snprintf(buf + len, sizeof(buf) - len, "\n");
109203c4805SLuis R. Rodriguez 
110203c4805SLuis R. Rodriguez 		val[i] = REG_READ(ah, AR_DMADBG_0 + (i * sizeof(u32)));
111203c4805SLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len, "%d: %08x ",
112203c4805SLuis R. Rodriguez 				i, val[i]);
113203c4805SLuis R. Rodriguez 	}
114203c4805SLuis R. Rodriguez 
115203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len, "\n\n");
116203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
117203c4805SLuis R. Rodriguez 			"Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
118203c4805SLuis R. Rodriguez 
119203c4805SLuis R. Rodriguez 	for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
120203c4805SLuis R. Rodriguez 		if (i == 8) {
121203c4805SLuis R. Rodriguez 			qcuOffset = 0;
122203c4805SLuis R. Rodriguez 			qcuBase++;
123203c4805SLuis R. Rodriguez 		}
124203c4805SLuis R. Rodriguez 
125203c4805SLuis R. Rodriguez 		if (i == 6) {
126203c4805SLuis R. Rodriguez 			dcuOffset = 0;
127203c4805SLuis R. Rodriguez 			dcuBase++;
128203c4805SLuis R. Rodriguez 		}
129203c4805SLuis R. Rodriguez 
130203c4805SLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
131203c4805SLuis R. Rodriguez 			"%2d          %2x      %1x     %2x           %2x\n",
132203c4805SLuis R. Rodriguez 			i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
133203c4805SLuis R. Rodriguez 			(*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
134203c4805SLuis R. Rodriguez 			val[2] & (0x7 << (i * 3)) >> (i * 3),
135203c4805SLuis R. Rodriguez 			(*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
136203c4805SLuis R. Rodriguez 	}
137203c4805SLuis R. Rodriguez 
138203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len, "\n");
139203c4805SLuis R. Rodriguez 
140203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
141203c4805SLuis R. Rodriguez 		"qcu_stitch state:   %2x    qcu_fetch state:        %2x\n",
142203c4805SLuis R. Rodriguez 		(val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
143203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
144203c4805SLuis R. Rodriguez 		"qcu_complete state: %2x    dcu_complete state:     %2x\n",
145203c4805SLuis R. Rodriguez 		(val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
146203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
147203c4805SLuis R. Rodriguez 		"dcu_arb state:      %2x    dcu_fp state:           %2x\n",
148203c4805SLuis R. Rodriguez 		(val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
149203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
150203c4805SLuis R. Rodriguez 		"chan_idle_dur:     %3d    chan_idle_dur_valid:     %1d\n",
151203c4805SLuis R. Rodriguez 		(val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
152203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
153203c4805SLuis R. Rodriguez 		"txfifo_valid_0:      %1d    txfifo_valid_1:          %1d\n",
154203c4805SLuis R. Rodriguez 		(val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
155203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
156203c4805SLuis R. Rodriguez 		"txfifo_dcu_num_0:   %2d    txfifo_dcu_num_1:       %2d\n",
157203c4805SLuis R. Rodriguez 		(val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
158203c4805SLuis R. Rodriguez 
159203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len, "pcu observe: 0x%x \n",
160203c4805SLuis R. Rodriguez 			REG_READ(ah, AR_OBS_BUS_1));
161203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
162203c4805SLuis R. Rodriguez 			"AR_CR: 0x%x \n", REG_READ(ah, AR_CR));
163203c4805SLuis R. Rodriguez 
1647cf4a2e7SSujith 	ath9k_ps_restore(sc);
1657cf4a2e7SSujith 
166203c4805SLuis R. Rodriguez 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
167203c4805SLuis R. Rodriguez }
168203c4805SLuis R. Rodriguez 
169203c4805SLuis R. Rodriguez static const struct file_operations fops_dma = {
170203c4805SLuis R. Rodriguez 	.read = read_file_dma,
171203c4805SLuis R. Rodriguez 	.open = ath9k_debugfs_open,
172203c4805SLuis R. Rodriguez 	.owner = THIS_MODULE
173203c4805SLuis R. Rodriguez };
174203c4805SLuis R. Rodriguez 
175203c4805SLuis R. Rodriguez 
176203c4805SLuis R. Rodriguez void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
177203c4805SLuis R. Rodriguez {
178203c4805SLuis R. Rodriguez 	if (status)
179203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.total++;
180203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RX)
181203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxok++;
182203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXEOL)
183203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxeol++;
184203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXORN)
185203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxorn++;
186203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TX)
187203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txok++;
188203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TXURN)
189203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.txurn++;
190203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_MIB)
191203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.mib++;
192203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXPHY)
193203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rxphyerr++;
194203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_RXKCM)
195203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.rx_keycache_miss++;
196203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_SWBA)
197203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.swba++;
198203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BMISS)
199203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bmiss++;
200203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_BNR)
201203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.bnr++;
202203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CST)
203203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cst++;
204203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_GTT)
205203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.gtt++;
206203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_TIM)
207203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.tim++;
208203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_CABEND)
209203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.cabend++;
210203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIMSYNC)
211203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtimsync++;
212203c4805SLuis R. Rodriguez 	if (status & ATH9K_INT_DTIM)
213203c4805SLuis R. Rodriguez 		sc->debug.stats.istats.dtim++;
214203c4805SLuis R. Rodriguez }
215203c4805SLuis R. Rodriguez 
216203c4805SLuis R. Rodriguez static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
217203c4805SLuis R. Rodriguez 				   size_t count, loff_t *ppos)
218203c4805SLuis R. Rodriguez {
219203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
220203c4805SLuis R. Rodriguez 	char buf[512];
221203c4805SLuis R. Rodriguez 	unsigned int len = 0;
222203c4805SLuis R. Rodriguez 
223203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
224203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
225203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
226203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol);
227203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
228203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn);
229203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
230203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TX", sc->debug.stats.istats.txok);
231203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
232203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn);
233203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
234203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "MIB", sc->debug.stats.istats.mib);
235203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
236203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr);
237203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
238203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss);
239203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
240203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba);
241203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
242203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss);
243203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
244203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr);
245203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
246203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "CST", sc->debug.stats.istats.cst);
247203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
248203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt);
249203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
250203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TIM", sc->debug.stats.istats.tim);
251203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
252203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend);
253203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
254203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync);
255203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
256203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim);
257203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
258203c4805SLuis R. Rodriguez 		"%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total);
259203c4805SLuis R. Rodriguez 
260203c4805SLuis R. Rodriguez 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
261203c4805SLuis R. Rodriguez }
262203c4805SLuis R. Rodriguez 
263203c4805SLuis R. Rodriguez static const struct file_operations fops_interrupt = {
264203c4805SLuis R. Rodriguez 	.read = read_file_interrupt,
265203c4805SLuis R. Rodriguez 	.open = ath9k_debugfs_open,
266203c4805SLuis R. Rodriguez 	.owner = THIS_MODULE
267203c4805SLuis R. Rodriguez };
268203c4805SLuis R. Rodriguez 
269bedf087aSJeff Hansen void ath_debug_stat_rc(struct ath_softc *sc, struct sk_buff *skb)
270203c4805SLuis R. Rodriguez {
271203c4805SLuis R. Rodriguez 	struct ath_tx_info_priv *tx_info_priv = NULL;
272203c4805SLuis R. Rodriguez 	struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
273203c4805SLuis R. Rodriguez 	struct ieee80211_tx_rate *rates = tx_info->status.rates;
274203c4805SLuis R. Rodriguez 	int final_ts_idx, idx;
275bedf087aSJeff Hansen 	struct ath_rc_stats *stats;
276203c4805SLuis R. Rodriguez 
277203c4805SLuis R. Rodriguez 	tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
278203c4805SLuis R. Rodriguez 	final_ts_idx = tx_info_priv->tx.ts_rateindex;
279203c4805SLuis R. Rodriguez 	idx = rates[final_ts_idx].idx;
280bedf087aSJeff Hansen 	stats = &sc->debug.stats.rcstats[idx];
281bedf087aSJeff Hansen 	stats->success++;
282203c4805SLuis R. Rodriguez }
283203c4805SLuis R. Rodriguez 
284203c4805SLuis R. Rodriguez void ath_debug_stat_retries(struct ath_softc *sc, int rix,
285203c4805SLuis R. Rodriguez 			    int xretries, int retries, u8 per)
286203c4805SLuis R. Rodriguez {
287bedf087aSJeff Hansen 	struct ath_rc_stats *stats = &sc->debug.stats.rcstats[rix];
288203c4805SLuis R. Rodriguez 
289bedf087aSJeff Hansen 	stats->xretries += xretries;
290bedf087aSJeff Hansen 	stats->retries += retries;
291bedf087aSJeff Hansen 	stats->per = per;
292203c4805SLuis R. Rodriguez }
293203c4805SLuis R. Rodriguez 
294203c4805SLuis R. Rodriguez static ssize_t read_file_rcstat(struct file *file, char __user *user_buf,
295203c4805SLuis R. Rodriguez 				size_t count, loff_t *ppos)
296203c4805SLuis R. Rodriguez {
297203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
298bedf087aSJeff Hansen 	char *buf;
299bedf087aSJeff Hansen 	unsigned int len = 0, max;
300bedf087aSJeff Hansen 	int i = 0;
301bedf087aSJeff Hansen 	ssize_t retval;
302203c4805SLuis R. Rodriguez 
303203c4805SLuis R. Rodriguez 	if (sc->cur_rate_table == NULL)
304203c4805SLuis R. Rodriguez 		return 0;
305203c4805SLuis R. Rodriguez 
306bedf087aSJeff Hansen 	max = 80 + sc->cur_rate_table->rate_cnt * 64;
307bedf087aSJeff Hansen 	buf = kmalloc(max + 1, GFP_KERNEL);
308bedf087aSJeff Hansen 	if (buf == NULL)
309bedf087aSJeff Hansen 		return 0;
310bedf087aSJeff Hansen 	buf[max] = 0;
311bedf087aSJeff Hansen 
312bedf087aSJeff Hansen 	len += sprintf(buf, "%5s %15s %8s %9s %3s\n\n", "Rate", "Success",
313bedf087aSJeff Hansen 		       "Retries", "XRetries", "PER");
314bedf087aSJeff Hansen 
315bedf087aSJeff Hansen 	for (i = 0; i < sc->cur_rate_table->rate_cnt; i++) {
316bedf087aSJeff Hansen 		u32 ratekbps = sc->cur_rate_table->info[i].ratekbps;
317bedf087aSJeff Hansen 		struct ath_rc_stats *stats = &sc->debug.stats.rcstats[i];
318bedf087aSJeff Hansen 
319bedf087aSJeff Hansen 		len += snprintf(buf + len, max - len,
320bedf087aSJeff Hansen 			"%3u.%d: %8u %8u %8u %8u\n", ratekbps / 1000,
321bedf087aSJeff Hansen 			(ratekbps % 1000) / 100, stats->success,
322bedf087aSJeff Hansen 			stats->retries, stats->xretries,
323bedf087aSJeff Hansen 			stats->per);
324bedf087aSJeff Hansen 	}
325bedf087aSJeff Hansen 
326bedf087aSJeff Hansen 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
327bedf087aSJeff Hansen 	kfree(buf);
328bedf087aSJeff Hansen 	return retval;
329203c4805SLuis R. Rodriguez }
330203c4805SLuis R. Rodriguez 
331203c4805SLuis R. Rodriguez static const struct file_operations fops_rcstat = {
332203c4805SLuis R. Rodriguez 	.read = read_file_rcstat,
333203c4805SLuis R. Rodriguez 	.open = ath9k_debugfs_open,
334203c4805SLuis R. Rodriguez 	.owner = THIS_MODULE
335203c4805SLuis R. Rodriguez };
336203c4805SLuis R. Rodriguez 
337203c4805SLuis R. Rodriguez static const char * ath_wiphy_state_str(enum ath_wiphy_state state)
338203c4805SLuis R. Rodriguez {
339203c4805SLuis R. Rodriguez 	switch (state) {
340203c4805SLuis R. Rodriguez 	case ATH_WIPHY_INACTIVE:
341203c4805SLuis R. Rodriguez 		return "INACTIVE";
342203c4805SLuis R. Rodriguez 	case ATH_WIPHY_ACTIVE:
343203c4805SLuis R. Rodriguez 		return "ACTIVE";
344203c4805SLuis R. Rodriguez 	case ATH_WIPHY_PAUSING:
345203c4805SLuis R. Rodriguez 		return "PAUSING";
346203c4805SLuis R. Rodriguez 	case ATH_WIPHY_PAUSED:
347203c4805SLuis R. Rodriguez 		return "PAUSED";
348203c4805SLuis R. Rodriguez 	case ATH_WIPHY_SCAN:
349203c4805SLuis R. Rodriguez 		return "SCAN";
350203c4805SLuis R. Rodriguez 	}
351203c4805SLuis R. Rodriguez 	return "?";
352203c4805SLuis R. Rodriguez }
353203c4805SLuis R. Rodriguez 
354203c4805SLuis R. Rodriguez static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
355203c4805SLuis R. Rodriguez 			       size_t count, loff_t *ppos)
356203c4805SLuis R. Rodriguez {
357203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
358203c4805SLuis R. Rodriguez 	char buf[512];
359203c4805SLuis R. Rodriguez 	unsigned int len = 0;
360203c4805SLuis R. Rodriguez 	int i;
361203c4805SLuis R. Rodriguez 	u8 addr[ETH_ALEN];
362203c4805SLuis R. Rodriguez 
363203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
364203c4805SLuis R. Rodriguez 			"primary: %s (%s chan=%d ht=%d)\n",
365203c4805SLuis R. Rodriguez 			wiphy_name(sc->pri_wiphy->hw->wiphy),
366203c4805SLuis R. Rodriguez 			ath_wiphy_state_str(sc->pri_wiphy->state),
367203c4805SLuis R. Rodriguez 			sc->pri_wiphy->chan_idx, sc->pri_wiphy->chan_is_ht);
368203c4805SLuis R. Rodriguez 	for (i = 0; i < sc->num_sec_wiphy; i++) {
369203c4805SLuis R. Rodriguez 		struct ath_wiphy *aphy = sc->sec_wiphy[i];
370203c4805SLuis R. Rodriguez 		if (aphy == NULL)
371203c4805SLuis R. Rodriguez 			continue;
372203c4805SLuis R. Rodriguez 		len += snprintf(buf + len, sizeof(buf) - len,
373203c4805SLuis R. Rodriguez 				"secondary: %s (%s chan=%d ht=%d)\n",
374203c4805SLuis R. Rodriguez 				wiphy_name(aphy->hw->wiphy),
375203c4805SLuis R. Rodriguez 				ath_wiphy_state_str(aphy->state),
376203c4805SLuis R. Rodriguez 				aphy->chan_idx, aphy->chan_is_ht);
377203c4805SLuis R. Rodriguez 	}
378203c4805SLuis R. Rodriguez 
379203c4805SLuis R. Rodriguez 	put_unaligned_le32(REG_READ(sc->sc_ah, AR_STA_ID0), addr);
380203c4805SLuis R. Rodriguez 	put_unaligned_le16(REG_READ(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
381203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
382203c4805SLuis R. Rodriguez 			"addr: %pM\n", addr);
383203c4805SLuis R. Rodriguez 	put_unaligned_le32(REG_READ(sc->sc_ah, AR_BSSMSKL), addr);
384203c4805SLuis R. Rodriguez 	put_unaligned_le16(REG_READ(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
385203c4805SLuis R. Rodriguez 	len += snprintf(buf + len, sizeof(buf) - len,
386203c4805SLuis R. Rodriguez 			"addrmask: %pM\n", addr);
387203c4805SLuis R. Rodriguez 
388203c4805SLuis R. Rodriguez 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
389203c4805SLuis R. Rodriguez }
390203c4805SLuis R. Rodriguez 
391203c4805SLuis R. Rodriguez static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name)
392203c4805SLuis R. Rodriguez {
393203c4805SLuis R. Rodriguez 	int i;
394203c4805SLuis R. Rodriguez 	if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0)
395203c4805SLuis R. Rodriguez 		return sc->pri_wiphy;
396203c4805SLuis R. Rodriguez 	for (i = 0; i < sc->num_sec_wiphy; i++) {
397203c4805SLuis R. Rodriguez 		struct ath_wiphy *aphy = sc->sec_wiphy[i];
398203c4805SLuis R. Rodriguez 		if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0)
399203c4805SLuis R. Rodriguez 			return aphy;
400203c4805SLuis R. Rodriguez 	}
401203c4805SLuis R. Rodriguez 	return NULL;
402203c4805SLuis R. Rodriguez }
403203c4805SLuis R. Rodriguez 
404203c4805SLuis R. Rodriguez static int del_wiphy(struct ath_softc *sc, const char *name)
405203c4805SLuis R. Rodriguez {
406203c4805SLuis R. Rodriguez 	struct ath_wiphy *aphy = get_wiphy(sc, name);
407203c4805SLuis R. Rodriguez 	if (!aphy)
408203c4805SLuis R. Rodriguez 		return -ENOENT;
409203c4805SLuis R. Rodriguez 	return ath9k_wiphy_del(aphy);
410203c4805SLuis R. Rodriguez }
411203c4805SLuis R. Rodriguez 
412203c4805SLuis R. Rodriguez static int pause_wiphy(struct ath_softc *sc, const char *name)
413203c4805SLuis R. Rodriguez {
414203c4805SLuis R. Rodriguez 	struct ath_wiphy *aphy = get_wiphy(sc, name);
415203c4805SLuis R. Rodriguez 	if (!aphy)
416203c4805SLuis R. Rodriguez 		return -ENOENT;
417203c4805SLuis R. Rodriguez 	return ath9k_wiphy_pause(aphy);
418203c4805SLuis R. Rodriguez }
419203c4805SLuis R. Rodriguez 
420203c4805SLuis R. Rodriguez static int unpause_wiphy(struct ath_softc *sc, const char *name)
421203c4805SLuis R. Rodriguez {
422203c4805SLuis R. Rodriguez 	struct ath_wiphy *aphy = get_wiphy(sc, name);
423203c4805SLuis R. Rodriguez 	if (!aphy)
424203c4805SLuis R. Rodriguez 		return -ENOENT;
425203c4805SLuis R. Rodriguez 	return ath9k_wiphy_unpause(aphy);
426203c4805SLuis R. Rodriguez }
427203c4805SLuis R. Rodriguez 
428203c4805SLuis R. Rodriguez static int select_wiphy(struct ath_softc *sc, const char *name)
429203c4805SLuis R. Rodriguez {
430203c4805SLuis R. Rodriguez 	struct ath_wiphy *aphy = get_wiphy(sc, name);
431203c4805SLuis R. Rodriguez 	if (!aphy)
432203c4805SLuis R. Rodriguez 		return -ENOENT;
433203c4805SLuis R. Rodriguez 	return ath9k_wiphy_select(aphy);
434203c4805SLuis R. Rodriguez }
435203c4805SLuis R. Rodriguez 
436203c4805SLuis R. Rodriguez static int schedule_wiphy(struct ath_softc *sc, const char *msec)
437203c4805SLuis R. Rodriguez {
438203c4805SLuis R. Rodriguez 	ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0));
439203c4805SLuis R. Rodriguez 	return 0;
440203c4805SLuis R. Rodriguez }
441203c4805SLuis R. Rodriguez 
442203c4805SLuis R. Rodriguez static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf,
443203c4805SLuis R. Rodriguez 				size_t count, loff_t *ppos)
444203c4805SLuis R. Rodriguez {
445203c4805SLuis R. Rodriguez 	struct ath_softc *sc = file->private_data;
446203c4805SLuis R. Rodriguez 	char buf[50];
447203c4805SLuis R. Rodriguez 	size_t len;
448203c4805SLuis R. Rodriguez 
449203c4805SLuis R. Rodriguez 	len = min(count, sizeof(buf) - 1);
450203c4805SLuis R. Rodriguez 	if (copy_from_user(buf, user_buf, len))
451203c4805SLuis R. Rodriguez 		return -EFAULT;
452203c4805SLuis R. Rodriguez 	buf[len] = '\0';
453203c4805SLuis R. Rodriguez 	if (len > 0 && buf[len - 1] == '\n')
454203c4805SLuis R. Rodriguez 		buf[len - 1] = '\0';
455203c4805SLuis R. Rodriguez 
456203c4805SLuis R. Rodriguez 	if (strncmp(buf, "add", 3) == 0) {
457203c4805SLuis R. Rodriguez 		int res = ath9k_wiphy_add(sc);
458203c4805SLuis R. Rodriguez 		if (res < 0)
459203c4805SLuis R. Rodriguez 			return res;
460203c4805SLuis R. Rodriguez 	} else if (strncmp(buf, "del=", 4) == 0) {
461203c4805SLuis R. Rodriguez 		int res = del_wiphy(sc, buf + 4);
462203c4805SLuis R. Rodriguez 		if (res < 0)
463203c4805SLuis R. Rodriguez 			return res;
464203c4805SLuis R. Rodriguez 	} else if (strncmp(buf, "pause=", 6) == 0) {
465203c4805SLuis R. Rodriguez 		int res = pause_wiphy(sc, buf + 6);
466203c4805SLuis R. Rodriguez 		if (res < 0)
467203c4805SLuis R. Rodriguez 			return res;
468203c4805SLuis R. Rodriguez 	} else if (strncmp(buf, "unpause=", 8) == 0) {
469203c4805SLuis R. Rodriguez 		int res = unpause_wiphy(sc, buf + 8);
470203c4805SLuis R. Rodriguez 		if (res < 0)
471203c4805SLuis R. Rodriguez 			return res;
472203c4805SLuis R. Rodriguez 	} else if (strncmp(buf, "select=", 7) == 0) {
473203c4805SLuis R. Rodriguez 		int res = select_wiphy(sc, buf + 7);
474203c4805SLuis R. Rodriguez 		if (res < 0)
475203c4805SLuis R. Rodriguez 			return res;
476203c4805SLuis R. Rodriguez 	} else if (strncmp(buf, "schedule=", 9) == 0) {
477203c4805SLuis R. Rodriguez 		int res = schedule_wiphy(sc, buf + 9);
478203c4805SLuis R. Rodriguez 		if (res < 0)
479203c4805SLuis R. Rodriguez 			return res;
480203c4805SLuis R. Rodriguez 	} else
481203c4805SLuis R. Rodriguez 		return -EOPNOTSUPP;
482203c4805SLuis R. Rodriguez 
483203c4805SLuis R. Rodriguez 	return count;
484203c4805SLuis R. Rodriguez }
485203c4805SLuis R. Rodriguez 
486203c4805SLuis R. Rodriguez static const struct file_operations fops_wiphy = {
487203c4805SLuis R. Rodriguez 	.read = read_file_wiphy,
488203c4805SLuis R. Rodriguez 	.write = write_file_wiphy,
489203c4805SLuis R. Rodriguez 	.open = ath9k_debugfs_open,
490203c4805SLuis R. Rodriguez 	.owner = THIS_MODULE
491203c4805SLuis R. Rodriguez };
492203c4805SLuis R. Rodriguez 
493fec247c0SSujith #define PR(str, elem)							\
494fec247c0SSujith 	do {								\
495fec247c0SSujith 		len += snprintf(buf + len, size - len,			\
496fec247c0SSujith 				"%s%13u%11u%10u%10u\n", str,		\
497fec247c0SSujith 		sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BE]].elem, \
498fec247c0SSujith 		sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BK]].elem, \
499fec247c0SSujith 		sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VI]].elem, \
500fec247c0SSujith 		sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VO]].elem); \
501fec247c0SSujith } while(0)
502fec247c0SSujith 
503fec247c0SSujith static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
504fec247c0SSujith 			      size_t count, loff_t *ppos)
505fec247c0SSujith {
506fec247c0SSujith 	struct ath_softc *sc = file->private_data;
507fec247c0SSujith 	char *buf;
508fec247c0SSujith 	unsigned int len = 0, size = 2048;
509fec247c0SSujith 	ssize_t retval = 0;
510fec247c0SSujith 
511fec247c0SSujith 	buf = kzalloc(size, GFP_KERNEL);
512fec247c0SSujith 	if (buf == NULL)
513fec247c0SSujith 		return 0;
514fec247c0SSujith 
515fec247c0SSujith 	len += sprintf(buf, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
516fec247c0SSujith 
517fec247c0SSujith 	PR("MPDUs Queued:    ", queued);
518fec247c0SSujith 	PR("MPDUs Completed: ", completed);
519fec247c0SSujith 	PR("Aggregates:      ", a_aggr);
520fec247c0SSujith 	PR("AMPDUs Queued:   ", a_queued);
521fec247c0SSujith 	PR("AMPDUs Completed:", a_completed);
522fec247c0SSujith 	PR("AMPDUs Retried:  ", a_retries);
523fec247c0SSujith 	PR("AMPDUs XRetried: ", a_xretries);
524fec247c0SSujith 	PR("FIFO Underrun:   ", fifo_underrun);
525fec247c0SSujith 	PR("TXOP Exceeded:   ", xtxop);
526fec247c0SSujith 	PR("TXTIMER Expiry:  ", timer_exp);
527fec247c0SSujith 	PR("DESC CFG Error:  ", desc_cfg_err);
528fec247c0SSujith 	PR("DATA Underrun:   ", data_underrun);
529fec247c0SSujith 	PR("DELIM Underrun:  ", delim_underrun);
530fec247c0SSujith 
531fec247c0SSujith 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
532fec247c0SSujith 	kfree(buf);
533fec247c0SSujith 
534fec247c0SSujith 	return retval;
535fec247c0SSujith }
536fec247c0SSujith 
537fec247c0SSujith void ath_debug_stat_tx(struct ath_softc *sc, struct ath_txq *txq,
538fec247c0SSujith 		       struct ath_buf *bf)
539fec247c0SSujith {
540fec247c0SSujith 	struct ath_desc *ds = bf->bf_desc;
541fec247c0SSujith 
542fec247c0SSujith 	if (bf_isampdu(bf)) {
543fec247c0SSujith 		if (bf_isxretried(bf))
544fec247c0SSujith 			TX_STAT_INC(txq->axq_qnum, a_xretries);
545fec247c0SSujith 		else
546fec247c0SSujith 			TX_STAT_INC(txq->axq_qnum, a_completed);
547fec247c0SSujith 	} else {
548fec247c0SSujith 		TX_STAT_INC(txq->axq_qnum, completed);
549fec247c0SSujith 	}
550fec247c0SSujith 
551fec247c0SSujith 	if (ds->ds_txstat.ts_status & ATH9K_TXERR_FIFO)
552fec247c0SSujith 		TX_STAT_INC(txq->axq_qnum, fifo_underrun);
553fec247c0SSujith 	if (ds->ds_txstat.ts_status & ATH9K_TXERR_XTXOP)
554fec247c0SSujith 		TX_STAT_INC(txq->axq_qnum, xtxop);
555fec247c0SSujith 	if (ds->ds_txstat.ts_status & ATH9K_TXERR_TIMER_EXPIRED)
556fec247c0SSujith 		TX_STAT_INC(txq->axq_qnum, timer_exp);
557fec247c0SSujith 	if (ds->ds_txstat.ts_flags & ATH9K_TX_DESC_CFG_ERR)
558fec247c0SSujith 		TX_STAT_INC(txq->axq_qnum, desc_cfg_err);
559fec247c0SSujith 	if (ds->ds_txstat.ts_flags & ATH9K_TX_DATA_UNDERRUN)
560fec247c0SSujith 		TX_STAT_INC(txq->axq_qnum, data_underrun);
561fec247c0SSujith 	if (ds->ds_txstat.ts_flags & ATH9K_TX_DELIM_UNDERRUN)
562fec247c0SSujith 		TX_STAT_INC(txq->axq_qnum, delim_underrun);
563fec247c0SSujith }
564fec247c0SSujith 
565fec247c0SSujith static const struct file_operations fops_xmit = {
566fec247c0SSujith 	.read = read_file_xmit,
567fec247c0SSujith 	.open = ath9k_debugfs_open,
568fec247c0SSujith 	.owner = THIS_MODULE
569fec247c0SSujith };
570203c4805SLuis R. Rodriguez 
571*4d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah)
572203c4805SLuis R. Rodriguez {
573*4d6b228dSLuis R. Rodriguez 	struct ath_softc *sc = ah->ah_sc;
574*4d6b228dSLuis R. Rodriguez 
575203c4805SLuis R. Rodriguez 	sc->debug.debug_mask = ath9k_debug;
576203c4805SLuis R. Rodriguez 
577203c4805SLuis R. Rodriguez 	if (!ath9k_debugfs_root)
578203c4805SLuis R. Rodriguez 		return -ENOENT;
579203c4805SLuis R. Rodriguez 
580203c4805SLuis R. Rodriguez 	sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
581203c4805SLuis R. Rodriguez 						      ath9k_debugfs_root);
582203c4805SLuis R. Rodriguez 	if (!sc->debug.debugfs_phy)
583203c4805SLuis R. Rodriguez 		goto err;
584203c4805SLuis R. Rodriguez 
5852493928eSJeff Hansen 	sc->debug.debugfs_debug = debugfs_create_file("debug",
5869d49e861SJiri Slaby 		S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc, &fops_debug);
5872493928eSJeff Hansen 	if (!sc->debug.debugfs_debug)
5882493928eSJeff Hansen 		goto err;
5892493928eSJeff Hansen 
5909d49e861SJiri Slaby 	sc->debug.debugfs_dma = debugfs_create_file("dma", S_IRUSR,
591203c4805SLuis R. Rodriguez 				       sc->debug.debugfs_phy, sc, &fops_dma);
592203c4805SLuis R. Rodriguez 	if (!sc->debug.debugfs_dma)
593203c4805SLuis R. Rodriguez 		goto err;
594203c4805SLuis R. Rodriguez 
595203c4805SLuis R. Rodriguez 	sc->debug.debugfs_interrupt = debugfs_create_file("interrupt",
5969d49e861SJiri Slaby 						     S_IRUSR,
597203c4805SLuis R. Rodriguez 						     sc->debug.debugfs_phy,
598203c4805SLuis R. Rodriguez 						     sc, &fops_interrupt);
599203c4805SLuis R. Rodriguez 	if (!sc->debug.debugfs_interrupt)
600203c4805SLuis R. Rodriguez 		goto err;
601203c4805SLuis R. Rodriguez 
602203c4805SLuis R. Rodriguez 	sc->debug.debugfs_rcstat = debugfs_create_file("rcstat",
6039d49e861SJiri Slaby 						  S_IRUSR,
604203c4805SLuis R. Rodriguez 						  sc->debug.debugfs_phy,
605203c4805SLuis R. Rodriguez 						  sc, &fops_rcstat);
606203c4805SLuis R. Rodriguez 	if (!sc->debug.debugfs_rcstat)
607203c4805SLuis R. Rodriguez 		goto err;
608203c4805SLuis R. Rodriguez 
609203c4805SLuis R. Rodriguez 	sc->debug.debugfs_wiphy = debugfs_create_file(
6109d49e861SJiri Slaby 		"wiphy", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc,
611203c4805SLuis R. Rodriguez 		&fops_wiphy);
612203c4805SLuis R. Rodriguez 	if (!sc->debug.debugfs_wiphy)
613203c4805SLuis R. Rodriguez 		goto err;
614203c4805SLuis R. Rodriguez 
615fec247c0SSujith 	sc->debug.debugfs_xmit = debugfs_create_file("xmit",
616fec247c0SSujith 						     S_IRUSR,
617fec247c0SSujith 						     sc->debug.debugfs_phy,
618fec247c0SSujith 						     sc, &fops_xmit);
619fec247c0SSujith 	if (!sc->debug.debugfs_xmit)
620fec247c0SSujith 		goto err;
621fec247c0SSujith 
622203c4805SLuis R. Rodriguez 	return 0;
623203c4805SLuis R. Rodriguez err:
624*4d6b228dSLuis R. Rodriguez 	ath9k_exit_debug(ah);
625203c4805SLuis R. Rodriguez 	return -ENOMEM;
626203c4805SLuis R. Rodriguez }
627203c4805SLuis R. Rodriguez 
628*4d6b228dSLuis R. Rodriguez void ath9k_exit_debug(struct ath_hw *ah)
629203c4805SLuis R. Rodriguez {
630*4d6b228dSLuis R. Rodriguez 	struct ath_softc *sc = ah->ah_sc;
631*4d6b228dSLuis R. Rodriguez 
632fec247c0SSujith 	debugfs_remove(sc->debug.debugfs_xmit);
633203c4805SLuis R. Rodriguez 	debugfs_remove(sc->debug.debugfs_wiphy);
634203c4805SLuis R. Rodriguez 	debugfs_remove(sc->debug.debugfs_rcstat);
635203c4805SLuis R. Rodriguez 	debugfs_remove(sc->debug.debugfs_interrupt);
636203c4805SLuis R. Rodriguez 	debugfs_remove(sc->debug.debugfs_dma);
6372493928eSJeff Hansen 	debugfs_remove(sc->debug.debugfs_debug);
638203c4805SLuis R. Rodriguez 	debugfs_remove(sc->debug.debugfs_phy);
639203c4805SLuis R. Rodriguez }
640203c4805SLuis R. Rodriguez 
641203c4805SLuis R. Rodriguez int ath9k_debug_create_root(void)
642203c4805SLuis R. Rodriguez {
643203c4805SLuis R. Rodriguez 	ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
644203c4805SLuis R. Rodriguez 	if (!ath9k_debugfs_root)
645203c4805SLuis R. Rodriguez 		return -ENOENT;
646203c4805SLuis R. Rodriguez 
647203c4805SLuis R. Rodriguez 	return 0;
648203c4805SLuis R. Rodriguez }
649203c4805SLuis R. Rodriguez 
650203c4805SLuis R. Rodriguez void ath9k_debug_remove_root(void)
651203c4805SLuis R. Rodriguez {
652203c4805SLuis R. Rodriguez 	debugfs_remove(ath9k_debugfs_root);
653203c4805SLuis R. Rodriguez 	ath9k_debugfs_root = NULL;
654203c4805SLuis R. Rodriguez }
655