xref: /linux/drivers/net/wireless/ath/ath9k/debug.c (revision 4413e16d9d21673bb5048a2e542f1aaa00015c2e)
1 /*
2  * Copyright (c) 2008-2011 Atheros Communications Inc.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #include <linux/slab.h>
18 #include <linux/vmalloc.h>
19 #include <linux/export.h>
20 #include <asm/unaligned.h>
21 
22 #include "ath9k.h"
23 
24 #define REG_WRITE_D(_ah, _reg, _val) \
25 	ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg))
26 #define REG_READ_D(_ah, _reg) \
27 	ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
28 
29 
30 static ssize_t ath9k_debugfs_read_buf(struct file *file, char __user *user_buf,
31 				      size_t count, loff_t *ppos)
32 {
33 	u8 *buf = file->private_data;
34 	return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
35 }
36 
37 static int ath9k_debugfs_release_buf(struct inode *inode, struct file *file)
38 {
39 	vfree(file->private_data);
40 	return 0;
41 }
42 
43 #ifdef CONFIG_ATH_DEBUG
44 
45 static ssize_t read_file_debug(struct file *file, char __user *user_buf,
46 			     size_t count, loff_t *ppos)
47 {
48 	struct ath_softc *sc = file->private_data;
49 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
50 	char buf[32];
51 	unsigned int len;
52 
53 	len = sprintf(buf, "0x%08x\n", common->debug_mask);
54 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
55 }
56 
57 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
58 			     size_t count, loff_t *ppos)
59 {
60 	struct ath_softc *sc = file->private_data;
61 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
62 	unsigned long mask;
63 	char buf[32];
64 	ssize_t len;
65 
66 	len = min(count, sizeof(buf) - 1);
67 	if (copy_from_user(buf, user_buf, len))
68 		return -EFAULT;
69 
70 	buf[len] = '\0';
71 	if (strict_strtoul(buf, 0, &mask))
72 		return -EINVAL;
73 
74 	common->debug_mask = mask;
75 	return count;
76 }
77 
78 static const struct file_operations fops_debug = {
79 	.read = read_file_debug,
80 	.write = write_file_debug,
81 	.open = simple_open,
82 	.owner = THIS_MODULE,
83 	.llseek = default_llseek,
84 };
85 
86 #endif
87 
88 #define DMA_BUF_LEN 1024
89 
90 static ssize_t read_file_tx_chainmask(struct file *file, char __user *user_buf,
91 			     size_t count, loff_t *ppos)
92 {
93 	struct ath_softc *sc = file->private_data;
94 	struct ath_hw *ah = sc->sc_ah;
95 	char buf[32];
96 	unsigned int len;
97 
98 	len = sprintf(buf, "0x%08x\n", ah->txchainmask);
99 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
100 }
101 
102 static ssize_t write_file_tx_chainmask(struct file *file, const char __user *user_buf,
103 			     size_t count, loff_t *ppos)
104 {
105 	struct ath_softc *sc = file->private_data;
106 	struct ath_hw *ah = sc->sc_ah;
107 	unsigned long mask;
108 	char buf[32];
109 	ssize_t len;
110 
111 	len = min(count, sizeof(buf) - 1);
112 	if (copy_from_user(buf, user_buf, len))
113 		return -EFAULT;
114 
115 	buf[len] = '\0';
116 	if (strict_strtoul(buf, 0, &mask))
117 		return -EINVAL;
118 
119 	ah->txchainmask = mask;
120 	ah->caps.tx_chainmask = mask;
121 	return count;
122 }
123 
124 static const struct file_operations fops_tx_chainmask = {
125 	.read = read_file_tx_chainmask,
126 	.write = write_file_tx_chainmask,
127 	.open = simple_open,
128 	.owner = THIS_MODULE,
129 	.llseek = default_llseek,
130 };
131 
132 
133 static ssize_t read_file_rx_chainmask(struct file *file, char __user *user_buf,
134 			     size_t count, loff_t *ppos)
135 {
136 	struct ath_softc *sc = file->private_data;
137 	struct ath_hw *ah = sc->sc_ah;
138 	char buf[32];
139 	unsigned int len;
140 
141 	len = sprintf(buf, "0x%08x\n", ah->rxchainmask);
142 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
143 }
144 
145 static ssize_t write_file_rx_chainmask(struct file *file, const char __user *user_buf,
146 			     size_t count, loff_t *ppos)
147 {
148 	struct ath_softc *sc = file->private_data;
149 	struct ath_hw *ah = sc->sc_ah;
150 	unsigned long mask;
151 	char buf[32];
152 	ssize_t len;
153 
154 	len = min(count, sizeof(buf) - 1);
155 	if (copy_from_user(buf, user_buf, len))
156 		return -EFAULT;
157 
158 	buf[len] = '\0';
159 	if (strict_strtoul(buf, 0, &mask))
160 		return -EINVAL;
161 
162 	ah->rxchainmask = mask;
163 	ah->caps.rx_chainmask = mask;
164 	return count;
165 }
166 
167 static const struct file_operations fops_rx_chainmask = {
168 	.read = read_file_rx_chainmask,
169 	.write = write_file_rx_chainmask,
170 	.open = simple_open,
171 	.owner = THIS_MODULE,
172 	.llseek = default_llseek,
173 };
174 
175 static ssize_t read_file_disable_ani(struct file *file, char __user *user_buf,
176 			     size_t count, loff_t *ppos)
177 {
178 	struct ath_softc *sc = file->private_data;
179 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
180 	char buf[32];
181 	unsigned int len;
182 
183 	len = sprintf(buf, "%d\n", common->disable_ani);
184 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
185 }
186 
187 static ssize_t write_file_disable_ani(struct file *file,
188 				      const char __user *user_buf,
189 				      size_t count, loff_t *ppos)
190 {
191 	struct ath_softc *sc = file->private_data;
192 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
193 	unsigned long disable_ani;
194 	char buf[32];
195 	ssize_t len;
196 
197 	len = min(count, sizeof(buf) - 1);
198 	if (copy_from_user(buf, user_buf, len))
199 		return -EFAULT;
200 
201 	buf[len] = '\0';
202 	if (strict_strtoul(buf, 0, &disable_ani))
203 		return -EINVAL;
204 
205 	common->disable_ani = !!disable_ani;
206 
207 	if (disable_ani) {
208 		clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
209 		ath_stop_ani(sc);
210 	} else {
211 		ath_check_ani(sc);
212 	}
213 
214 	return count;
215 }
216 
217 static const struct file_operations fops_disable_ani = {
218 	.read = read_file_disable_ani,
219 	.write = write_file_disable_ani,
220 	.open = simple_open,
221 	.owner = THIS_MODULE,
222 	.llseek = default_llseek,
223 };
224 
225 static ssize_t read_file_dma(struct file *file, char __user *user_buf,
226 			     size_t count, loff_t *ppos)
227 {
228 	struct ath_softc *sc = file->private_data;
229 	struct ath_hw *ah = sc->sc_ah;
230 	char *buf;
231 	int retval;
232 	unsigned int len = 0;
233 	u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
234 	int i, qcuOffset = 0, dcuOffset = 0;
235 	u32 *qcuBase = &val[0], *dcuBase = &val[4];
236 
237 	buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
238 	if (!buf)
239 		return -ENOMEM;
240 
241 	ath9k_ps_wakeup(sc);
242 
243 	REG_WRITE_D(ah, AR_MACMISC,
244 		  ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
245 		   (AR_MACMISC_MISC_OBS_BUS_1 <<
246 		    AR_MACMISC_MISC_OBS_BUS_MSB_S)));
247 
248 	len += snprintf(buf + len, DMA_BUF_LEN - len,
249 			"Raw DMA Debug values:\n");
250 
251 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
252 		if (i % 4 == 0)
253 			len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
254 
255 		val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
256 		len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
257 				i, val[i]);
258 	}
259 
260 	len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
261 	len += snprintf(buf + len, DMA_BUF_LEN - len,
262 			"Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
263 
264 	for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
265 		if (i == 8) {
266 			qcuOffset = 0;
267 			qcuBase++;
268 		}
269 
270 		if (i == 6) {
271 			dcuOffset = 0;
272 			dcuBase++;
273 		}
274 
275 		len += snprintf(buf + len, DMA_BUF_LEN - len,
276 			"%2d          %2x      %1x     %2x           %2x\n",
277 			i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
278 			(*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
279 			val[2] & (0x7 << (i * 3)) >> (i * 3),
280 			(*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
281 	}
282 
283 	len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
284 
285 	len += snprintf(buf + len, DMA_BUF_LEN - len,
286 		"qcu_stitch state:   %2x    qcu_fetch state:        %2x\n",
287 		(val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
288 	len += snprintf(buf + len, DMA_BUF_LEN - len,
289 		"qcu_complete state: %2x    dcu_complete state:     %2x\n",
290 		(val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
291 	len += snprintf(buf + len, DMA_BUF_LEN - len,
292 		"dcu_arb state:      %2x    dcu_fp state:           %2x\n",
293 		(val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
294 	len += snprintf(buf + len, DMA_BUF_LEN - len,
295 		"chan_idle_dur:     %3d    chan_idle_dur_valid:     %1d\n",
296 		(val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
297 	len += snprintf(buf + len, DMA_BUF_LEN - len,
298 		"txfifo_valid_0:      %1d    txfifo_valid_1:          %1d\n",
299 		(val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
300 	len += snprintf(buf + len, DMA_BUF_LEN - len,
301 		"txfifo_dcu_num_0:   %2d    txfifo_dcu_num_1:       %2d\n",
302 		(val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
303 
304 	len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
305 			REG_READ_D(ah, AR_OBS_BUS_1));
306 	len += snprintf(buf + len, DMA_BUF_LEN - len,
307 			"AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
308 
309 	ath9k_ps_restore(sc);
310 
311 	if (len > DMA_BUF_LEN)
312 		len = DMA_BUF_LEN;
313 
314 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
315 	kfree(buf);
316 	return retval;
317 }
318 
319 static const struct file_operations fops_dma = {
320 	.read = read_file_dma,
321 	.open = simple_open,
322 	.owner = THIS_MODULE,
323 	.llseek = default_llseek,
324 };
325 
326 
327 void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
328 {
329 	if (status)
330 		sc->debug.stats.istats.total++;
331 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
332 		if (status & ATH9K_INT_RXLP)
333 			sc->debug.stats.istats.rxlp++;
334 		if (status & ATH9K_INT_RXHP)
335 			sc->debug.stats.istats.rxhp++;
336 		if (status & ATH9K_INT_BB_WATCHDOG)
337 			sc->debug.stats.istats.bb_watchdog++;
338 	} else {
339 		if (status & ATH9K_INT_RX)
340 			sc->debug.stats.istats.rxok++;
341 	}
342 	if (status & ATH9K_INT_RXEOL)
343 		sc->debug.stats.istats.rxeol++;
344 	if (status & ATH9K_INT_RXORN)
345 		sc->debug.stats.istats.rxorn++;
346 	if (status & ATH9K_INT_TX)
347 		sc->debug.stats.istats.txok++;
348 	if (status & ATH9K_INT_TXURN)
349 		sc->debug.stats.istats.txurn++;
350 	if (status & ATH9K_INT_RXPHY)
351 		sc->debug.stats.istats.rxphyerr++;
352 	if (status & ATH9K_INT_RXKCM)
353 		sc->debug.stats.istats.rx_keycache_miss++;
354 	if (status & ATH9K_INT_SWBA)
355 		sc->debug.stats.istats.swba++;
356 	if (status & ATH9K_INT_BMISS)
357 		sc->debug.stats.istats.bmiss++;
358 	if (status & ATH9K_INT_BNR)
359 		sc->debug.stats.istats.bnr++;
360 	if (status & ATH9K_INT_CST)
361 		sc->debug.stats.istats.cst++;
362 	if (status & ATH9K_INT_GTT)
363 		sc->debug.stats.istats.gtt++;
364 	if (status & ATH9K_INT_TIM)
365 		sc->debug.stats.istats.tim++;
366 	if (status & ATH9K_INT_CABEND)
367 		sc->debug.stats.istats.cabend++;
368 	if (status & ATH9K_INT_DTIMSYNC)
369 		sc->debug.stats.istats.dtimsync++;
370 	if (status & ATH9K_INT_DTIM)
371 		sc->debug.stats.istats.dtim++;
372 	if (status & ATH9K_INT_TSFOOR)
373 		sc->debug.stats.istats.tsfoor++;
374 	if (status & ATH9K_INT_MCI)
375 		sc->debug.stats.istats.mci++;
376 }
377 
378 static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
379 				   size_t count, loff_t *ppos)
380 {
381 	struct ath_softc *sc = file->private_data;
382 	unsigned int len = 0;
383 	int rv;
384 	int mxlen = 4000;
385 	char *buf = kmalloc(mxlen, GFP_KERNEL);
386 	if (!buf)
387 		return -ENOMEM;
388 
389 #define PR_IS(a, s)						\
390 	do {							\
391 		len += snprintf(buf + len, mxlen - len,		\
392 				"%21s: %10u\n", a,		\
393 				sc->debug.stats.istats.s);	\
394 	} while (0)
395 
396 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
397 		PR_IS("RXLP", rxlp);
398 		PR_IS("RXHP", rxhp);
399 		PR_IS("WATHDOG", bb_watchdog);
400 	} else {
401 		PR_IS("RX", rxok);
402 	}
403 	PR_IS("RXEOL", rxeol);
404 	PR_IS("RXORN", rxorn);
405 	PR_IS("TX", txok);
406 	PR_IS("TXURN", txurn);
407 	PR_IS("MIB", mib);
408 	PR_IS("RXPHY", rxphyerr);
409 	PR_IS("RXKCM", rx_keycache_miss);
410 	PR_IS("SWBA", swba);
411 	PR_IS("BMISS", bmiss);
412 	PR_IS("BNR", bnr);
413 	PR_IS("CST", cst);
414 	PR_IS("GTT", gtt);
415 	PR_IS("TIM", tim);
416 	PR_IS("CABEND", cabend);
417 	PR_IS("DTIMSYNC", dtimsync);
418 	PR_IS("DTIM", dtim);
419 	PR_IS("TSFOOR", tsfoor);
420 	PR_IS("MCI", mci);
421 	PR_IS("TOTAL", total);
422 
423 	len += snprintf(buf + len, mxlen - len,
424 			"SYNC_CAUSE stats:\n");
425 
426 	PR_IS("Sync-All", sync_cause_all);
427 	PR_IS("RTC-IRQ", sync_rtc_irq);
428 	PR_IS("MAC-IRQ", sync_mac_irq);
429 	PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
430 	PR_IS("APB-Timeout", apb_timeout);
431 	PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
432 	PR_IS("HOST1-Fatal", host1_fatal);
433 	PR_IS("HOST1-Perr", host1_perr);
434 	PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
435 	PR_IS("RADM-CPL-EP", radm_cpl_ep);
436 	PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
437 	PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
438 	PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
439 	PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
440 	PR_IS("Local-Bus-Timeout", local_timeout);
441 	PR_IS("PM-Access", pm_access);
442 	PR_IS("MAC-Awake", mac_awake);
443 	PR_IS("MAC-Asleep", mac_asleep);
444 	PR_IS("MAC-Sleep-Access", mac_sleep_access);
445 
446 	if (len > mxlen)
447 		len = mxlen;
448 
449 	rv = simple_read_from_buffer(user_buf, count, ppos, buf, len);
450 	kfree(buf);
451 	return rv;
452 }
453 
454 static const struct file_operations fops_interrupt = {
455 	.read = read_file_interrupt,
456 	.open = simple_open,
457 	.owner = THIS_MODULE,
458 	.llseek = default_llseek,
459 };
460 
461 #define PR_QNUM(_n) sc->tx.txq_map[_n]->axq_qnum
462 #define PR(str, elem)							\
463 	do {								\
464 		len += snprintf(buf + len, size - len,			\
465 				"%s%13u%11u%10u%10u\n", str,		\
466 		sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].elem, \
467 		sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].elem, \
468 		sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].elem, \
469 		sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].elem); \
470 		if (len >= size)			  \
471 			goto done;			  \
472 } while(0)
473 
474 #define PRX(str, elem)							\
475 do {									\
476 	len += snprintf(buf + len, size - len,				\
477 			"%s%13u%11u%10u%10u\n", str,			\
478 			(unsigned int)(sc->tx.txq_map[WME_AC_BE]->elem),	\
479 			(unsigned int)(sc->tx.txq_map[WME_AC_BK]->elem),	\
480 			(unsigned int)(sc->tx.txq_map[WME_AC_VI]->elem),	\
481 			(unsigned int)(sc->tx.txq_map[WME_AC_VO]->elem));	\
482 	if (len >= size)						\
483 		goto done;						\
484 } while(0)
485 
486 #define PRQLE(str, elem)						\
487 do {									\
488 	len += snprintf(buf + len, size - len,				\
489 			"%s%13i%11i%10i%10i\n", str,			\
490 			list_empty(&sc->tx.txq_map[WME_AC_BE]->elem),	\
491 			list_empty(&sc->tx.txq_map[WME_AC_BK]->elem),	\
492 			list_empty(&sc->tx.txq_map[WME_AC_VI]->elem),	\
493 			list_empty(&sc->tx.txq_map[WME_AC_VO]->elem));	\
494 	if (len >= size)						\
495 		goto done;						\
496 } while (0)
497 
498 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
499 			      size_t count, loff_t *ppos)
500 {
501 	struct ath_softc *sc = file->private_data;
502 	char *buf;
503 	unsigned int len = 0, size = 8000;
504 	int i;
505 	ssize_t retval = 0;
506 	char tmp[32];
507 
508 	buf = kzalloc(size, GFP_KERNEL);
509 	if (buf == NULL)
510 		return -ENOMEM;
511 
512 	len += sprintf(buf, "Num-Tx-Queues: %i  tx-queues-setup: 0x%x"
513 		       " poll-work-seen: %u\n"
514 		       "%30s %10s%10s%10s\n\n",
515 		       ATH9K_NUM_TX_QUEUES, sc->tx.txqsetup,
516 		       sc->tx_complete_poll_work_seen,
517 		       "BE", "BK", "VI", "VO");
518 
519 	PR("MPDUs Queued:    ", queued);
520 	PR("MPDUs Completed: ", completed);
521 	PR("MPDUs XRetried:  ", xretries);
522 	PR("Aggregates:      ", a_aggr);
523 	PR("AMPDUs Queued HW:", a_queued_hw);
524 	PR("AMPDUs Queued SW:", a_queued_sw);
525 	PR("AMPDUs Completed:", a_completed);
526 	PR("AMPDUs Retried:  ", a_retries);
527 	PR("AMPDUs XRetried: ", a_xretries);
528 	PR("FIFO Underrun:   ", fifo_underrun);
529 	PR("TXOP Exceeded:   ", xtxop);
530 	PR("TXTIMER Expiry:  ", timer_exp);
531 	PR("DESC CFG Error:  ", desc_cfg_err);
532 	PR("DATA Underrun:   ", data_underrun);
533 	PR("DELIM Underrun:  ", delim_underrun);
534 	PR("TX-Pkts-All:     ", tx_pkts_all);
535 	PR("TX-Bytes-All:    ", tx_bytes_all);
536 	PR("hw-put-tx-buf:   ", puttxbuf);
537 	PR("hw-tx-start:     ", txstart);
538 	PR("hw-tx-proc-desc: ", txprocdesc);
539 	PR("TX-Failed:       ", txfailed);
540 	len += snprintf(buf + len, size - len,
541 			"%s%11p%11p%10p%10p\n", "txq-memory-address:",
542 			sc->tx.txq_map[WME_AC_BE],
543 			sc->tx.txq_map[WME_AC_BK],
544 			sc->tx.txq_map[WME_AC_VI],
545 			sc->tx.txq_map[WME_AC_VO]);
546 	if (len >= size)
547 		goto done;
548 
549 	PRX("axq-qnum:        ", axq_qnum);
550 	PRX("axq-depth:       ", axq_depth);
551 	PRX("axq-ampdu_depth: ", axq_ampdu_depth);
552 	PRX("axq-stopped      ", stopped);
553 	PRX("tx-in-progress   ", axq_tx_inprogress);
554 	PRX("pending-frames   ", pending_frames);
555 	PRX("txq_headidx:     ", txq_headidx);
556 	PRX("txq_tailidx:     ", txq_headidx);
557 
558 	PRQLE("axq_q empty:       ", axq_q);
559 	PRQLE("axq_acq empty:     ", axq_acq);
560 	for (i = 0; i < ATH_TXFIFO_DEPTH; i++) {
561 		snprintf(tmp, sizeof(tmp) - 1, "txq_fifo[%i] empty: ", i);
562 		PRQLE(tmp, txq_fifo[i]);
563 	}
564 
565 	/* Print out more detailed queue-info */
566 	for (i = 0; i <= WME_AC_BK; i++) {
567 		struct ath_txq *txq = &(sc->tx.txq[i]);
568 		struct ath_atx_ac *ac;
569 		struct ath_atx_tid *tid;
570 		if (len >= size)
571 			goto done;
572 		spin_lock_bh(&txq->axq_lock);
573 		if (!list_empty(&txq->axq_acq)) {
574 			ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac,
575 					      list);
576 			len += snprintf(buf + len, size - len,
577 					"txq[%i] first-ac: %p sched: %i\n",
578 					i, ac, ac->sched);
579 			if (list_empty(&ac->tid_q) || (len >= size))
580 				goto done_for;
581 			tid = list_first_entry(&ac->tid_q, struct ath_atx_tid,
582 					       list);
583 			len += snprintf(buf + len, size - len,
584 					" first-tid: %p sched: %i paused: %i\n",
585 					tid, tid->sched, tid->paused);
586 		}
587 	done_for:
588 		spin_unlock_bh(&txq->axq_lock);
589 	}
590 
591 done:
592 	if (len > size)
593 		len = size;
594 
595 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
596 	kfree(buf);
597 
598 	return retval;
599 }
600 
601 static ssize_t read_file_stations(struct file *file, char __user *user_buf,
602 				  size_t count, loff_t *ppos)
603 {
604 	struct ath_softc *sc = file->private_data;
605 	char *buf;
606 	unsigned int len = 0, size = 64000;
607 	struct ath_node *an = NULL;
608 	ssize_t retval = 0;
609 	int q;
610 
611 	buf = kzalloc(size, GFP_KERNEL);
612 	if (buf == NULL)
613 		return -ENOMEM;
614 
615 	len += snprintf(buf + len, size - len,
616 			"Stations:\n"
617 			" tid: addr sched paused buf_q-empty an ac baw\n"
618 			" ac: addr sched tid_q-empty txq\n");
619 
620 	spin_lock(&sc->nodes_lock);
621 	list_for_each_entry(an, &sc->nodes, list) {
622 		unsigned short ma = an->maxampdu;
623 		if (ma == 0)
624 			ma = 65535; /* see ath_lookup_rate */
625 		len += snprintf(buf + len, size - len,
626 				"iface: %pM  sta: %pM max-ampdu: %hu mpdu-density: %uus\n",
627 				an->vif->addr, an->sta->addr, ma,
628 				(unsigned int)(an->mpdudensity));
629 		if (len >= size)
630 			goto done;
631 
632 		for (q = 0; q < WME_NUM_TID; q++) {
633 			struct ath_atx_tid *tid = &(an->tid[q]);
634 			len += snprintf(buf + len, size - len,
635 					" tid: %p %s %s %i %p %p %hu\n",
636 					tid, tid->sched ? "sched" : "idle",
637 					tid->paused ? "paused" : "running",
638 					skb_queue_empty(&tid->buf_q),
639 					tid->an, tid->ac, tid->baw_size);
640 			if (len >= size)
641 				goto done;
642 		}
643 
644 		for (q = 0; q < WME_NUM_AC; q++) {
645 			struct ath_atx_ac *ac = &(an->ac[q]);
646 			len += snprintf(buf + len, size - len,
647 					" ac: %p %s %i %p\n",
648 					ac, ac->sched ? "sched" : "idle",
649 					list_empty(&ac->tid_q), ac->txq);
650 			if (len >= size)
651 				goto done;
652 		}
653 	}
654 
655 done:
656 	spin_unlock(&sc->nodes_lock);
657 	if (len > size)
658 		len = size;
659 
660 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
661 	kfree(buf);
662 
663 	return retval;
664 }
665 
666 static ssize_t read_file_misc(struct file *file, char __user *user_buf,
667 			      size_t count, loff_t *ppos)
668 {
669 	struct ath_softc *sc = file->private_data;
670 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
671 	struct ieee80211_hw *hw = sc->hw;
672 	struct ath9k_vif_iter_data iter_data;
673 	char buf[512];
674 	unsigned int len = 0;
675 	ssize_t retval = 0;
676 	unsigned int reg;
677 	u32 rxfilter;
678 
679 	len += snprintf(buf + len, sizeof(buf) - len,
680 			"BSSID: %pM\n", common->curbssid);
681 	len += snprintf(buf + len, sizeof(buf) - len,
682 			"BSSID-MASK: %pM\n", common->bssidmask);
683 	len += snprintf(buf + len, sizeof(buf) - len,
684 			"OPMODE: %s\n", ath_opmode_to_string(sc->sc_ah->opmode));
685 
686 	ath9k_ps_wakeup(sc);
687 	rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
688 	ath9k_ps_restore(sc);
689 
690 	len += snprintf(buf + len, sizeof(buf) - len,
691 			"RXFILTER: 0x%x", rxfilter);
692 
693 	if (rxfilter & ATH9K_RX_FILTER_UCAST)
694 		len += snprintf(buf + len, sizeof(buf) - len, " UCAST");
695 	if (rxfilter & ATH9K_RX_FILTER_MCAST)
696 		len += snprintf(buf + len, sizeof(buf) - len, " MCAST");
697 	if (rxfilter & ATH9K_RX_FILTER_BCAST)
698 		len += snprintf(buf + len, sizeof(buf) - len, " BCAST");
699 	if (rxfilter & ATH9K_RX_FILTER_CONTROL)
700 		len += snprintf(buf + len, sizeof(buf) - len, " CONTROL");
701 	if (rxfilter & ATH9K_RX_FILTER_BEACON)
702 		len += snprintf(buf + len, sizeof(buf) - len, " BEACON");
703 	if (rxfilter & ATH9K_RX_FILTER_PROM)
704 		len += snprintf(buf + len, sizeof(buf) - len, " PROM");
705 	if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
706 		len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
707 	if (rxfilter & ATH9K_RX_FILTER_PHYERR)
708 		len += snprintf(buf + len, sizeof(buf) - len, " PHYERR");
709 	if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
710 		len += snprintf(buf + len, sizeof(buf) - len, " MYBEACON");
711 	if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
712 		len += snprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
713 	if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
714 		len += snprintf(buf + len, sizeof(buf) - len, " PSPOLL");
715 	if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
716 		len += snprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
717 	if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
718 		len += snprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL");
719 	if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
720 		len += snprintf(buf + len, sizeof(buf) - len, " CONTROL_WRAPPER");
721 
722 	len += snprintf(buf + len, sizeof(buf) - len, "\n");
723 
724 	reg = sc->sc_ah->imask;
725 
726 	len += snprintf(buf + len, sizeof(buf) - len, "INTERRUPT-MASK: 0x%x", reg);
727 
728 	if (reg & ATH9K_INT_SWBA)
729 		len += snprintf(buf + len, sizeof(buf) - len, " SWBA");
730 	if (reg & ATH9K_INT_BMISS)
731 		len += snprintf(buf + len, sizeof(buf) - len, " BMISS");
732 	if (reg & ATH9K_INT_CST)
733 		len += snprintf(buf + len, sizeof(buf) - len, " CST");
734 	if (reg & ATH9K_INT_RX)
735 		len += snprintf(buf + len, sizeof(buf) - len, " RX");
736 	if (reg & ATH9K_INT_RXHP)
737 		len += snprintf(buf + len, sizeof(buf) - len, " RXHP");
738 	if (reg & ATH9K_INT_RXLP)
739 		len += snprintf(buf + len, sizeof(buf) - len, " RXLP");
740 	if (reg & ATH9K_INT_BB_WATCHDOG)
741 		len += snprintf(buf + len, sizeof(buf) - len, " BB_WATCHDOG");
742 
743 	len += snprintf(buf + len, sizeof(buf) - len, "\n");
744 
745 	ath9k_calculate_iter_data(hw, NULL, &iter_data);
746 
747 	len += snprintf(buf + len, sizeof(buf) - len,
748 			"VIF-COUNTS: AP: %i STA: %i MESH: %i WDS: %i"
749 			" ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n",
750 			iter_data.naps, iter_data.nstations, iter_data.nmeshes,
751 			iter_data.nwds, iter_data.nadhocs,
752 			sc->nvifs, sc->nbcnvifs);
753 
754 	if (len > sizeof(buf))
755 		len = sizeof(buf);
756 
757 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
758 	return retval;
759 }
760 
761 static ssize_t read_file_reset(struct file *file, char __user *user_buf,
762 			       size_t count, loff_t *ppos)
763 {
764 	struct ath_softc *sc = file->private_data;
765 	char buf[512];
766 	unsigned int len = 0;
767 
768 	len += snprintf(buf + len, sizeof(buf) - len,
769 			"%17s: %2d\n", "Baseband Hang",
770 			sc->debug.stats.reset[RESET_TYPE_BB_HANG]);
771 	len += snprintf(buf + len, sizeof(buf) - len,
772 			"%17s: %2d\n", "Baseband Watchdog",
773 			sc->debug.stats.reset[RESET_TYPE_BB_WATCHDOG]);
774 	len += snprintf(buf + len, sizeof(buf) - len,
775 			"%17s: %2d\n", "Fatal HW Error",
776 			sc->debug.stats.reset[RESET_TYPE_FATAL_INT]);
777 	len += snprintf(buf + len, sizeof(buf) - len,
778 			"%17s: %2d\n", "TX HW error",
779 			sc->debug.stats.reset[RESET_TYPE_TX_ERROR]);
780 	len += snprintf(buf + len, sizeof(buf) - len,
781 			"%17s: %2d\n", "TX Path Hang",
782 			sc->debug.stats.reset[RESET_TYPE_TX_HANG]);
783 	len += snprintf(buf + len, sizeof(buf) - len,
784 			"%17s: %2d\n", "PLL RX Hang",
785 			sc->debug.stats.reset[RESET_TYPE_PLL_HANG]);
786 
787 	if (len > sizeof(buf))
788 		len = sizeof(buf);
789 
790 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
791 }
792 
793 void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
794 		       struct ath_tx_status *ts, struct ath_txq *txq,
795 		       unsigned int flags)
796 {
797 #define TX_SAMP_DBG(c) (sc->debug.bb_mac_samp[sc->debug.sampidx].ts\
798 			[sc->debug.tsidx].c)
799 	int qnum = txq->axq_qnum;
800 
801 	TX_STAT_INC(qnum, tx_pkts_all);
802 	sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
803 
804 	if (bf_isampdu(bf)) {
805 		if (flags & ATH_TX_ERROR)
806 			TX_STAT_INC(qnum, a_xretries);
807 		else
808 			TX_STAT_INC(qnum, a_completed);
809 	} else {
810 		if (ts->ts_status & ATH9K_TXERR_XRETRY)
811 			TX_STAT_INC(qnum, xretries);
812 		else
813 			TX_STAT_INC(qnum, completed);
814 	}
815 
816 	if (ts->ts_status & ATH9K_TXERR_FIFO)
817 		TX_STAT_INC(qnum, fifo_underrun);
818 	if (ts->ts_status & ATH9K_TXERR_XTXOP)
819 		TX_STAT_INC(qnum, xtxop);
820 	if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
821 		TX_STAT_INC(qnum, timer_exp);
822 	if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
823 		TX_STAT_INC(qnum, desc_cfg_err);
824 	if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
825 		TX_STAT_INC(qnum, data_underrun);
826 	if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
827 		TX_STAT_INC(qnum, delim_underrun);
828 
829 #ifdef CONFIG_ATH9K_MAC_DEBUG
830 	spin_lock(&sc->debug.samp_lock);
831 	TX_SAMP_DBG(jiffies) = jiffies;
832 	TX_SAMP_DBG(rssi_ctl0) = ts->ts_rssi_ctl0;
833 	TX_SAMP_DBG(rssi_ctl1) = ts->ts_rssi_ctl1;
834 	TX_SAMP_DBG(rssi_ctl2) = ts->ts_rssi_ctl2;
835 	TX_SAMP_DBG(rssi_ext0) = ts->ts_rssi_ext0;
836 	TX_SAMP_DBG(rssi_ext1) = ts->ts_rssi_ext1;
837 	TX_SAMP_DBG(rssi_ext2) = ts->ts_rssi_ext2;
838 	TX_SAMP_DBG(rateindex) = ts->ts_rateindex;
839 	TX_SAMP_DBG(isok) = !!(ts->ts_status & ATH9K_TXERR_MASK);
840 	TX_SAMP_DBG(rts_fail_cnt) = ts->ts_shortretry;
841 	TX_SAMP_DBG(data_fail_cnt) = ts->ts_longretry;
842 	TX_SAMP_DBG(rssi) = ts->ts_rssi;
843 	TX_SAMP_DBG(tid) = ts->tid;
844 	TX_SAMP_DBG(qid) = ts->qid;
845 
846 	if (ts->ts_flags & ATH9K_TX_BA) {
847 		TX_SAMP_DBG(ba_low) = ts->ba_low;
848 		TX_SAMP_DBG(ba_high) = ts->ba_high;
849 	} else {
850 		TX_SAMP_DBG(ba_low) = 0;
851 		TX_SAMP_DBG(ba_high) = 0;
852 	}
853 
854 	sc->debug.tsidx = (sc->debug.tsidx + 1) % ATH_DBG_MAX_SAMPLES;
855 	spin_unlock(&sc->debug.samp_lock);
856 #endif
857 
858 #undef TX_SAMP_DBG
859 }
860 
861 static const struct file_operations fops_xmit = {
862 	.read = read_file_xmit,
863 	.open = simple_open,
864 	.owner = THIS_MODULE,
865 	.llseek = default_llseek,
866 };
867 
868 static const struct file_operations fops_stations = {
869 	.read = read_file_stations,
870 	.open = simple_open,
871 	.owner = THIS_MODULE,
872 	.llseek = default_llseek,
873 };
874 
875 static const struct file_operations fops_misc = {
876 	.read = read_file_misc,
877 	.open = simple_open,
878 	.owner = THIS_MODULE,
879 	.llseek = default_llseek,
880 };
881 
882 static const struct file_operations fops_reset = {
883 	.read = read_file_reset,
884 	.open = simple_open,
885 	.owner = THIS_MODULE,
886 	.llseek = default_llseek,
887 };
888 
889 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
890 			      size_t count, loff_t *ppos)
891 {
892 #define PHY_ERR(s, p) \
893 	len += snprintf(buf + len, size - len, "%22s : %10u\n", s, \
894 			sc->debug.stats.rxstats.phy_err_stats[p]);
895 
896 #define RXS_ERR(s, e)					    \
897 	do {						    \
898 		len += snprintf(buf + len, size - len,	    \
899 				"%22s : %10u\n", s,	    \
900 				sc->debug.stats.rxstats.e); \
901 	} while (0)
902 
903 	struct ath_softc *sc = file->private_data;
904 	char *buf;
905 	unsigned int len = 0, size = 1600;
906 	ssize_t retval = 0;
907 
908 	buf = kzalloc(size, GFP_KERNEL);
909 	if (buf == NULL)
910 		return -ENOMEM;
911 
912 	RXS_ERR("CRC ERR", crc_err);
913 	RXS_ERR("DECRYPT CRC ERR", decrypt_crc_err);
914 	RXS_ERR("PHY ERR", phy_err);
915 	RXS_ERR("MIC ERR", mic_err);
916 	RXS_ERR("PRE-DELIM CRC ERR", pre_delim_crc_err);
917 	RXS_ERR("POST-DELIM CRC ERR", post_delim_crc_err);
918 	RXS_ERR("DECRYPT BUSY ERR", decrypt_busy_err);
919 	RXS_ERR("RX-LENGTH-ERR", rx_len_err);
920 	RXS_ERR("RX-OOM-ERR", rx_oom_err);
921 	RXS_ERR("RX-RATE-ERR", rx_rate_err);
922 	RXS_ERR("RX-DROP-RXFLUSH", rx_drop_rxflush);
923 	RXS_ERR("RX-TOO-MANY-FRAGS", rx_too_many_frags_err);
924 
925 	PHY_ERR("UNDERRUN ERR", ATH9K_PHYERR_UNDERRUN);
926 	PHY_ERR("TIMING ERR", ATH9K_PHYERR_TIMING);
927 	PHY_ERR("PARITY ERR", ATH9K_PHYERR_PARITY);
928 	PHY_ERR("RATE ERR", ATH9K_PHYERR_RATE);
929 	PHY_ERR("LENGTH ERR", ATH9K_PHYERR_LENGTH);
930 	PHY_ERR("RADAR ERR", ATH9K_PHYERR_RADAR);
931 	PHY_ERR("SERVICE ERR", ATH9K_PHYERR_SERVICE);
932 	PHY_ERR("TOR ERR", ATH9K_PHYERR_TOR);
933 	PHY_ERR("OFDM-TIMING ERR", ATH9K_PHYERR_OFDM_TIMING);
934 	PHY_ERR("OFDM-SIGNAL-PARITY ERR", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
935 	PHY_ERR("OFDM-RATE ERR", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
936 	PHY_ERR("OFDM-LENGTH ERR", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
937 	PHY_ERR("OFDM-POWER-DROP ERR", ATH9K_PHYERR_OFDM_POWER_DROP);
938 	PHY_ERR("OFDM-SERVICE ERR", ATH9K_PHYERR_OFDM_SERVICE);
939 	PHY_ERR("OFDM-RESTART ERR", ATH9K_PHYERR_OFDM_RESTART);
940 	PHY_ERR("FALSE-RADAR-EXT ERR", ATH9K_PHYERR_FALSE_RADAR_EXT);
941 	PHY_ERR("CCK-TIMING ERR", ATH9K_PHYERR_CCK_TIMING);
942 	PHY_ERR("CCK-HEADER-CRC ERR", ATH9K_PHYERR_CCK_HEADER_CRC);
943 	PHY_ERR("CCK-RATE ERR", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
944 	PHY_ERR("CCK-SERVICE ERR", ATH9K_PHYERR_CCK_SERVICE);
945 	PHY_ERR("CCK-RESTART ERR", ATH9K_PHYERR_CCK_RESTART);
946 	PHY_ERR("CCK-LENGTH ERR", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
947 	PHY_ERR("CCK-POWER-DROP ERR", ATH9K_PHYERR_CCK_POWER_DROP);
948 	PHY_ERR("HT-CRC ERR", ATH9K_PHYERR_HT_CRC_ERROR);
949 	PHY_ERR("HT-LENGTH ERR", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
950 	PHY_ERR("HT-RATE ERR", ATH9K_PHYERR_HT_RATE_ILLEGAL);
951 
952 	RXS_ERR("RX-Pkts-All", rx_pkts_all);
953 	RXS_ERR("RX-Bytes-All", rx_bytes_all);
954 	RXS_ERR("RX-Beacons", rx_beacons);
955 	RXS_ERR("RX-Frags", rx_frags);
956 
957 	if (len > size)
958 		len = size;
959 
960 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
961 	kfree(buf);
962 
963 	return retval;
964 
965 #undef RXS_ERR
966 #undef PHY_ERR
967 }
968 
969 void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
970 {
971 #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
972 #define RX_SAMP_DBG(c) (sc->debug.bb_mac_samp[sc->debug.sampidx].rs\
973 			[sc->debug.rsidx].c)
974 
975 	RX_STAT_INC(rx_pkts_all);
976 	sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
977 
978 	if (rs->rs_status & ATH9K_RXERR_CRC)
979 		RX_STAT_INC(crc_err);
980 	if (rs->rs_status & ATH9K_RXERR_DECRYPT)
981 		RX_STAT_INC(decrypt_crc_err);
982 	if (rs->rs_status & ATH9K_RXERR_MIC)
983 		RX_STAT_INC(mic_err);
984 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
985 		RX_STAT_INC(pre_delim_crc_err);
986 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
987 		RX_STAT_INC(post_delim_crc_err);
988 	if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
989 		RX_STAT_INC(decrypt_busy_err);
990 
991 	if (rs->rs_status & ATH9K_RXERR_PHY) {
992 		RX_STAT_INC(phy_err);
993 		if (rs->rs_phyerr < ATH9K_PHYERR_MAX)
994 			RX_PHY_ERR_INC(rs->rs_phyerr);
995 	}
996 
997 #ifdef CONFIG_ATH9K_MAC_DEBUG
998 	spin_lock(&sc->debug.samp_lock);
999 	RX_SAMP_DBG(jiffies) = jiffies;
1000 	RX_SAMP_DBG(rssi_ctl0) = rs->rs_rssi_ctl0;
1001 	RX_SAMP_DBG(rssi_ctl1) = rs->rs_rssi_ctl1;
1002 	RX_SAMP_DBG(rssi_ctl2) = rs->rs_rssi_ctl2;
1003 	RX_SAMP_DBG(rssi_ext0) = rs->rs_rssi_ext0;
1004 	RX_SAMP_DBG(rssi_ext1) = rs->rs_rssi_ext1;
1005 	RX_SAMP_DBG(rssi_ext2) = rs->rs_rssi_ext2;
1006 	RX_SAMP_DBG(antenna) = rs->rs_antenna;
1007 	RX_SAMP_DBG(rssi) = rs->rs_rssi;
1008 	RX_SAMP_DBG(rate) = rs->rs_rate;
1009 	RX_SAMP_DBG(is_mybeacon) = rs->is_mybeacon;
1010 
1011 	sc->debug.rsidx = (sc->debug.rsidx + 1) % ATH_DBG_MAX_SAMPLES;
1012 	spin_unlock(&sc->debug.samp_lock);
1013 
1014 #endif
1015 
1016 #undef RX_PHY_ERR_INC
1017 #undef RX_SAMP_DBG
1018 }
1019 
1020 static const struct file_operations fops_recv = {
1021 	.read = read_file_recv,
1022 	.open = simple_open,
1023 	.owner = THIS_MODULE,
1024 	.llseek = default_llseek,
1025 };
1026 
1027 static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
1028                                 size_t count, loff_t *ppos)
1029 {
1030 	struct ath_softc *sc = file->private_data;
1031 	char buf[32];
1032 	unsigned int len;
1033 
1034 	len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
1035 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1036 }
1037 
1038 static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
1039 			     size_t count, loff_t *ppos)
1040 {
1041 	struct ath_softc *sc = file->private_data;
1042 	unsigned long regidx;
1043 	char buf[32];
1044 	ssize_t len;
1045 
1046 	len = min(count, sizeof(buf) - 1);
1047 	if (copy_from_user(buf, user_buf, len))
1048 		return -EFAULT;
1049 
1050 	buf[len] = '\0';
1051 	if (strict_strtoul(buf, 0, &regidx))
1052 		return -EINVAL;
1053 
1054 	sc->debug.regidx = regidx;
1055 	return count;
1056 }
1057 
1058 static const struct file_operations fops_regidx = {
1059 	.read = read_file_regidx,
1060 	.write = write_file_regidx,
1061 	.open = simple_open,
1062 	.owner = THIS_MODULE,
1063 	.llseek = default_llseek,
1064 };
1065 
1066 static ssize_t read_file_regval(struct file *file, char __user *user_buf,
1067 			     size_t count, loff_t *ppos)
1068 {
1069 	struct ath_softc *sc = file->private_data;
1070 	struct ath_hw *ah = sc->sc_ah;
1071 	char buf[32];
1072 	unsigned int len;
1073 	u32 regval;
1074 
1075 	ath9k_ps_wakeup(sc);
1076 	regval = REG_READ_D(ah, sc->debug.regidx);
1077 	ath9k_ps_restore(sc);
1078 	len = sprintf(buf, "0x%08x\n", regval);
1079 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1080 }
1081 
1082 static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
1083 			     size_t count, loff_t *ppos)
1084 {
1085 	struct ath_softc *sc = file->private_data;
1086 	struct ath_hw *ah = sc->sc_ah;
1087 	unsigned long regval;
1088 	char buf[32];
1089 	ssize_t len;
1090 
1091 	len = min(count, sizeof(buf) - 1);
1092 	if (copy_from_user(buf, user_buf, len))
1093 		return -EFAULT;
1094 
1095 	buf[len] = '\0';
1096 	if (strict_strtoul(buf, 0, &regval))
1097 		return -EINVAL;
1098 
1099 	ath9k_ps_wakeup(sc);
1100 	REG_WRITE_D(ah, sc->debug.regidx, regval);
1101 	ath9k_ps_restore(sc);
1102 	return count;
1103 }
1104 
1105 static const struct file_operations fops_regval = {
1106 	.read = read_file_regval,
1107 	.write = write_file_regval,
1108 	.open = simple_open,
1109 	.owner = THIS_MODULE,
1110 	.llseek = default_llseek,
1111 };
1112 
1113 #define REGDUMP_LINE_SIZE	20
1114 
1115 static int open_file_regdump(struct inode *inode, struct file *file)
1116 {
1117 	struct ath_softc *sc = inode->i_private;
1118 	unsigned int len = 0;
1119 	u8 *buf;
1120 	int i;
1121 	unsigned long num_regs, regdump_len, max_reg_offset;
1122 
1123 	max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
1124 	num_regs = max_reg_offset / 4 + 1;
1125 	regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
1126 	buf = vmalloc(regdump_len);
1127 	if (!buf)
1128 		return -ENOMEM;
1129 
1130 	ath9k_ps_wakeup(sc);
1131 	for (i = 0; i < num_regs; i++)
1132 		len += scnprintf(buf + len, regdump_len - len,
1133 			"0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
1134 	ath9k_ps_restore(sc);
1135 
1136 	file->private_data = buf;
1137 
1138 	return 0;
1139 }
1140 
1141 static const struct file_operations fops_regdump = {
1142 	.open = open_file_regdump,
1143 	.read = ath9k_debugfs_read_buf,
1144 	.release = ath9k_debugfs_release_buf,
1145 	.owner = THIS_MODULE,
1146 	.llseek = default_llseek,/* read accesses f_pos */
1147 };
1148 
1149 static ssize_t read_file_dump_nfcal(struct file *file, char __user *user_buf,
1150 				    size_t count, loff_t *ppos)
1151 {
1152 	struct ath_softc *sc = file->private_data;
1153 	struct ath_hw *ah = sc->sc_ah;
1154 	struct ath9k_nfcal_hist *h = sc->caldata.nfCalHist;
1155 	struct ath_common *common = ath9k_hw_common(ah);
1156 	struct ieee80211_conf *conf = &common->hw->conf;
1157 	u32 len = 0, size = 1500;
1158 	u32 i, j;
1159 	ssize_t retval = 0;
1160 	char *buf;
1161 	u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1162 	u8 nread;
1163 
1164 	buf = kzalloc(size, GFP_KERNEL);
1165 	if (!buf)
1166 		return -ENOMEM;
1167 
1168 	len += snprintf(buf + len, size - len,
1169 			"Channel Noise Floor : %d\n", ah->noise);
1170 	len += snprintf(buf + len, size - len,
1171 			"Chain | privNF | # Readings | NF Readings\n");
1172 	for (i = 0; i < NUM_NF_READINGS; i++) {
1173 		if (!(chainmask & (1 << i)) ||
1174 		    ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1175 			continue;
1176 
1177 		nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
1178 		len += snprintf(buf + len, size - len, " %d\t %d\t %d\t\t",
1179 				i, h[i].privNF, nread);
1180 		for (j = 0; j < nread; j++)
1181 			len += snprintf(buf + len, size - len,
1182 					" %d", h[i].nfCalBuffer[j]);
1183 		len += snprintf(buf + len, size - len, "\n");
1184 	}
1185 
1186 	if (len > size)
1187 		len = size;
1188 
1189 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1190 	kfree(buf);
1191 
1192 	return retval;
1193 }
1194 
1195 static const struct file_operations fops_dump_nfcal = {
1196 	.read = read_file_dump_nfcal,
1197 	.open = simple_open,
1198 	.owner = THIS_MODULE,
1199 	.llseek = default_llseek,
1200 };
1201 
1202 static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf,
1203 				     size_t count, loff_t *ppos)
1204 {
1205 	struct ath_softc *sc = file->private_data;
1206 	struct ath_hw *ah = sc->sc_ah;
1207 	u32 len = 0, size = 1500;
1208 	ssize_t retval = 0;
1209 	char *buf;
1210 
1211 	buf = kzalloc(size, GFP_KERNEL);
1212 	if (!buf)
1213 		return -ENOMEM;
1214 
1215 	len = ah->eep_ops->dump_eeprom(ah, true, buf, len, size);
1216 
1217 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1218 	kfree(buf);
1219 
1220 	return retval;
1221 }
1222 
1223 static const struct file_operations fops_base_eeprom = {
1224 	.read = read_file_base_eeprom,
1225 	.open = simple_open,
1226 	.owner = THIS_MODULE,
1227 	.llseek = default_llseek,
1228 };
1229 
1230 static ssize_t read_file_modal_eeprom(struct file *file, char __user *user_buf,
1231 				      size_t count, loff_t *ppos)
1232 {
1233 	struct ath_softc *sc = file->private_data;
1234 	struct ath_hw *ah = sc->sc_ah;
1235 	u32 len = 0, size = 6000;
1236 	char *buf;
1237 	size_t retval;
1238 
1239 	buf = kzalloc(size, GFP_KERNEL);
1240 	if (buf == NULL)
1241 		return -ENOMEM;
1242 
1243 	len = ah->eep_ops->dump_eeprom(ah, false, buf, len, size);
1244 
1245 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1246 	kfree(buf);
1247 
1248 	return retval;
1249 }
1250 
1251 static const struct file_operations fops_modal_eeprom = {
1252 	.read = read_file_modal_eeprom,
1253 	.open = simple_open,
1254 	.owner = THIS_MODULE,
1255 	.llseek = default_llseek,
1256 };
1257 
1258 #ifdef CONFIG_ATH9K_MAC_DEBUG
1259 
1260 void ath9k_debug_samp_bb_mac(struct ath_softc *sc)
1261 {
1262 #define ATH_SAMP_DBG(c) (sc->debug.bb_mac_samp[sc->debug.sampidx].c)
1263 	struct ath_hw *ah = sc->sc_ah;
1264 	struct ath_common *common = ath9k_hw_common(ah);
1265 	unsigned long flags;
1266 	int i;
1267 
1268 	ath9k_ps_wakeup(sc);
1269 
1270 	spin_lock_bh(&sc->debug.samp_lock);
1271 
1272 	spin_lock_irqsave(&common->cc_lock, flags);
1273 	ath_hw_cycle_counters_update(common);
1274 
1275 	ATH_SAMP_DBG(cc.cycles) = common->cc_ani.cycles;
1276 	ATH_SAMP_DBG(cc.rx_busy) = common->cc_ani.rx_busy;
1277 	ATH_SAMP_DBG(cc.rx_frame) = common->cc_ani.rx_frame;
1278 	ATH_SAMP_DBG(cc.tx_frame) = common->cc_ani.tx_frame;
1279 	spin_unlock_irqrestore(&common->cc_lock, flags);
1280 
1281 	ATH_SAMP_DBG(noise) = ah->noise;
1282 
1283 	REG_WRITE_D(ah, AR_MACMISC,
1284 		  ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
1285 		   (AR_MACMISC_MISC_OBS_BUS_1 <<
1286 		    AR_MACMISC_MISC_OBS_BUS_MSB_S)));
1287 
1288 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++)
1289 		ATH_SAMP_DBG(dma_dbg_reg_vals[i]) = REG_READ_D(ah,
1290 				AR_DMADBG_0 + (i * sizeof(u32)));
1291 
1292 	ATH_SAMP_DBG(pcu_obs) = REG_READ_D(ah, AR_OBS_BUS_1);
1293 	ATH_SAMP_DBG(pcu_cr) = REG_READ_D(ah, AR_CR);
1294 
1295 	memcpy(ATH_SAMP_DBG(nfCalHist), sc->caldata.nfCalHist,
1296 			sizeof(ATH_SAMP_DBG(nfCalHist)));
1297 
1298 	sc->debug.sampidx = (sc->debug.sampidx + 1) % ATH_DBG_MAX_SAMPLES;
1299 	spin_unlock_bh(&sc->debug.samp_lock);
1300 	ath9k_ps_restore(sc);
1301 
1302 #undef ATH_SAMP_DBG
1303 }
1304 
1305 static int open_file_bb_mac_samps(struct inode *inode, struct file *file)
1306 {
1307 #define ATH_SAMP_DBG(c) bb_mac_samp[sampidx].c
1308 	struct ath_softc *sc = inode->i_private;
1309 	struct ath_hw *ah = sc->sc_ah;
1310 	struct ath_common *common = ath9k_hw_common(ah);
1311 	struct ieee80211_conf *conf = &common->hw->conf;
1312 	struct ath_dbg_bb_mac_samp *bb_mac_samp;
1313 	struct ath9k_nfcal_hist *h;
1314 	int i, j, qcuOffset = 0, dcuOffset = 0;
1315 	u32 *qcuBase, *dcuBase, size = 30000, len = 0;
1316 	u32 sampidx = 0;
1317 	u8 *buf;
1318 	u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1319 	u8 nread;
1320 
1321 	if (test_bit(SC_OP_INVALID, &sc->sc_flags))
1322 		return -EAGAIN;
1323 
1324 	buf = vmalloc(size);
1325 	if (!buf)
1326 		return -ENOMEM;
1327 	bb_mac_samp = vmalloc(sizeof(*bb_mac_samp) * ATH_DBG_MAX_SAMPLES);
1328 	if (!bb_mac_samp) {
1329 		vfree(buf);
1330 		return -ENOMEM;
1331 	}
1332 	/* Account the current state too */
1333 	ath9k_debug_samp_bb_mac(sc);
1334 
1335 	spin_lock_bh(&sc->debug.samp_lock);
1336 	memcpy(bb_mac_samp, sc->debug.bb_mac_samp,
1337 			sizeof(*bb_mac_samp) * ATH_DBG_MAX_SAMPLES);
1338 	len += snprintf(buf + len, size - len,
1339 			"Current Sample Index: %d\n", sc->debug.sampidx);
1340 	spin_unlock_bh(&sc->debug.samp_lock);
1341 
1342 	len += snprintf(buf + len, size - len,
1343 			"Raw DMA Debug Dump:\n");
1344 	len += snprintf(buf + len, size - len, "Sample |\t");
1345 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++)
1346 		len += snprintf(buf + len, size - len, " DMA Reg%d |\t", i);
1347 	len += snprintf(buf + len, size - len, "\n");
1348 
1349 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1350 		len += snprintf(buf + len, size - len, "%d\t", sampidx);
1351 
1352 		for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++)
1353 			len += snprintf(buf + len, size - len, " %08x\t",
1354 					ATH_SAMP_DBG(dma_dbg_reg_vals[i]));
1355 		len += snprintf(buf + len, size - len, "\n");
1356 	}
1357 	len += snprintf(buf + len, size - len, "\n");
1358 
1359 	len += snprintf(buf + len, size - len,
1360 			"Sample Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
1361 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1362 		qcuBase = &ATH_SAMP_DBG(dma_dbg_reg_vals[0]);
1363 		dcuBase = &ATH_SAMP_DBG(dma_dbg_reg_vals[4]);
1364 
1365 		for (i = 0; i < ATH9K_NUM_QUEUES; i++,
1366 				qcuOffset += 4, dcuOffset += 5) {
1367 			if (i == 8) {
1368 				qcuOffset = 0;
1369 				qcuBase++;
1370 			}
1371 
1372 			if (i == 6) {
1373 				dcuOffset = 0;
1374 				dcuBase++;
1375 			}
1376 			if (!sc->debug.stats.txstats[i].queued)
1377 				continue;
1378 
1379 			len += snprintf(buf + len, size - len,
1380 				"%4d %7d    %2x      %1x     %2x         %2x\n",
1381 				sampidx, i,
1382 				(*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
1383 				(*qcuBase & (0x8 << qcuOffset)) >>
1384 				(qcuOffset + 3),
1385 				ATH_SAMP_DBG(dma_dbg_reg_vals[2]) &
1386 				(0x7 << (i * 3)) >> (i * 3),
1387 				(*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
1388 		}
1389 		len += snprintf(buf + len, size - len, "\n");
1390 	}
1391 	len += snprintf(buf + len, size - len,
1392 			"samp qcu_sh qcu_fh qcu_comp dcu_comp dcu_arb dcu_fp "
1393 			"ch_idle_dur ch_idle_dur_val txfifo_val0 txfifo_val1 "
1394 			"txfifo_dcu0 txfifo_dcu1 pcu_obs AR_CR\n");
1395 
1396 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1397 		qcuBase = &ATH_SAMP_DBG(dma_dbg_reg_vals[0]);
1398 		dcuBase = &ATH_SAMP_DBG(dma_dbg_reg_vals[4]);
1399 
1400 		len += snprintf(buf + len, size - len, "%4d %5x %5x ", sampidx,
1401 			(ATH_SAMP_DBG(dma_dbg_reg_vals[3]) & 0x003c0000) >> 18,
1402 			(ATH_SAMP_DBG(dma_dbg_reg_vals[3]) & 0x03c00000) >> 22);
1403 		len += snprintf(buf + len, size - len, "%7x %8x ",
1404 			(ATH_SAMP_DBG(dma_dbg_reg_vals[3]) & 0x1c000000) >> 26,
1405 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x3));
1406 		len += snprintf(buf + len, size - len, "%7x %7x ",
1407 			(ATH_SAMP_DBG(dma_dbg_reg_vals[5]) & 0x06000000) >> 25,
1408 			(ATH_SAMP_DBG(dma_dbg_reg_vals[5]) & 0x38000000) >> 27);
1409 		len += snprintf(buf + len, size - len, "%7d %12d ",
1410 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x000003fc) >> 2,
1411 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x00000400) >> 10);
1412 		len += snprintf(buf + len, size - len, "%12d %12d ",
1413 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x00000800) >> 11,
1414 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x00001000) >> 12);
1415 		len += snprintf(buf + len, size - len, "%12d %12d ",
1416 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x0001e000) >> 13,
1417 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x001e0000) >> 17);
1418 		len += snprintf(buf + len, size - len, "0x%07x 0x%07x\n",
1419 				ATH_SAMP_DBG(pcu_obs), ATH_SAMP_DBG(pcu_cr));
1420 	}
1421 
1422 	len += snprintf(buf + len, size - len,
1423 			"Sample ChNoise Chain privNF #Reading Readings\n");
1424 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1425 		h = ATH_SAMP_DBG(nfCalHist);
1426 		if (!ATH_SAMP_DBG(noise))
1427 			continue;
1428 
1429 		for (i = 0; i < NUM_NF_READINGS; i++) {
1430 			if (!(chainmask & (1 << i)) ||
1431 			    ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1432 				continue;
1433 
1434 			nread = AR_PHY_CCA_FILTERWINDOW_LENGTH -
1435 				h[i].invalidNFcount;
1436 			len += snprintf(buf + len, size - len,
1437 					"%4d %5d %4d\t   %d\t %d\t",
1438 					sampidx, ATH_SAMP_DBG(noise),
1439 					i, h[i].privNF, nread);
1440 			for (j = 0; j < nread; j++)
1441 				len += snprintf(buf + len, size - len,
1442 					" %d", h[i].nfCalBuffer[j]);
1443 			len += snprintf(buf + len, size - len, "\n");
1444 		}
1445 	}
1446 	len += snprintf(buf + len, size - len, "\nCycle counters:\n"
1447 			"Sample Total    Rxbusy   Rxframes Txframes\n");
1448 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1449 		if (!ATH_SAMP_DBG(cc.cycles))
1450 			continue;
1451 		len += snprintf(buf + len, size - len,
1452 				"%4d %08x %08x %08x %08x\n",
1453 				sampidx, ATH_SAMP_DBG(cc.cycles),
1454 				ATH_SAMP_DBG(cc.rx_busy),
1455 				ATH_SAMP_DBG(cc.rx_frame),
1456 				ATH_SAMP_DBG(cc.tx_frame));
1457 	}
1458 
1459 	len += snprintf(buf + len, size - len, "Tx status Dump :\n");
1460 	len += snprintf(buf + len, size - len,
1461 			"Sample rssi:- ctl0 ctl1 ctl2 ext0 ext1 ext2 comb "
1462 			"isok rts_fail data_fail rate tid qid "
1463 					"ba_low  ba_high tx_before(ms)\n");
1464 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1465 		for (i = 0; i < ATH_DBG_MAX_SAMPLES; i++) {
1466 			if (!ATH_SAMP_DBG(ts[i].jiffies))
1467 				continue;
1468 			len += snprintf(buf + len, size - len, "%-14d"
1469 				"%-4d %-4d %-4d %-4d %-4d %-4d %-4d %-4d %-8d "
1470 				"%-9d %-4d %-3d %-3d %08x %08x %-11d\n",
1471 				sampidx,
1472 				ATH_SAMP_DBG(ts[i].rssi_ctl0),
1473 				ATH_SAMP_DBG(ts[i].rssi_ctl1),
1474 				ATH_SAMP_DBG(ts[i].rssi_ctl2),
1475 				ATH_SAMP_DBG(ts[i].rssi_ext0),
1476 				ATH_SAMP_DBG(ts[i].rssi_ext1),
1477 				ATH_SAMP_DBG(ts[i].rssi_ext2),
1478 				ATH_SAMP_DBG(ts[i].rssi),
1479 				ATH_SAMP_DBG(ts[i].isok),
1480 				ATH_SAMP_DBG(ts[i].rts_fail_cnt),
1481 				ATH_SAMP_DBG(ts[i].data_fail_cnt),
1482 				ATH_SAMP_DBG(ts[i].rateindex),
1483 				ATH_SAMP_DBG(ts[i].tid),
1484 				ATH_SAMP_DBG(ts[i].qid),
1485 				ATH_SAMP_DBG(ts[i].ba_low),
1486 				ATH_SAMP_DBG(ts[i].ba_high),
1487 				jiffies_to_msecs(jiffies -
1488 					ATH_SAMP_DBG(ts[i].jiffies)));
1489 		}
1490 	}
1491 
1492 	len += snprintf(buf + len, size - len, "Rx status Dump :\n");
1493 	len += snprintf(buf + len, size - len, "Sample rssi:- ctl0 ctl1 ctl2 "
1494 			"ext0 ext1 ext2 comb beacon ant rate rx_before(ms)\n");
1495 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1496 		for (i = 0; i < ATH_DBG_MAX_SAMPLES; i++) {
1497 			if (!ATH_SAMP_DBG(rs[i].jiffies))
1498 				continue;
1499 			len += snprintf(buf + len, size - len, "%-14d"
1500 				"%-4d %-4d %-4d %-4d %-4d %-4d %-4d %-9s %-2d %02x %-13d\n",
1501 				sampidx,
1502 				ATH_SAMP_DBG(rs[i].rssi_ctl0),
1503 				ATH_SAMP_DBG(rs[i].rssi_ctl1),
1504 				ATH_SAMP_DBG(rs[i].rssi_ctl2),
1505 				ATH_SAMP_DBG(rs[i].rssi_ext0),
1506 				ATH_SAMP_DBG(rs[i].rssi_ext1),
1507 				ATH_SAMP_DBG(rs[i].rssi_ext2),
1508 				ATH_SAMP_DBG(rs[i].rssi),
1509 				ATH_SAMP_DBG(rs[i].is_mybeacon) ?
1510 				"True" : "False",
1511 				ATH_SAMP_DBG(rs[i].antenna),
1512 				ATH_SAMP_DBG(rs[i].rate),
1513 				jiffies_to_msecs(jiffies -
1514 					ATH_SAMP_DBG(rs[i].jiffies)));
1515 		}
1516 	}
1517 
1518 	vfree(bb_mac_samp);
1519 	file->private_data = buf;
1520 
1521 	return 0;
1522 #undef ATH_SAMP_DBG
1523 }
1524 
1525 static const struct file_operations fops_samps = {
1526 	.open = open_file_bb_mac_samps,
1527 	.read = ath9k_debugfs_read_buf,
1528 	.release = ath9k_debugfs_release_buf,
1529 	.owner = THIS_MODULE,
1530 	.llseek = default_llseek,
1531 };
1532 
1533 #endif
1534 
1535 int ath9k_init_debug(struct ath_hw *ah)
1536 {
1537 	struct ath_common *common = ath9k_hw_common(ah);
1538 	struct ath_softc *sc = (struct ath_softc *) common->priv;
1539 
1540 	sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1541 						   sc->hw->wiphy->debugfsdir);
1542 	if (!sc->debug.debugfs_phy)
1543 		return -ENOMEM;
1544 
1545 #ifdef CONFIG_ATH_DEBUG
1546 	debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1547 			    sc, &fops_debug);
1548 #endif
1549 
1550 	ath9k_dfs_init_debug(sc);
1551 
1552 	debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
1553 			    &fops_dma);
1554 	debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
1555 			    &fops_interrupt);
1556 	debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc,
1557 			    &fops_xmit);
1558 	debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1559 			   &sc->tx.txq_max_pending[WME_AC_BK]);
1560 	debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1561 			   &sc->tx.txq_max_pending[WME_AC_BE]);
1562 	debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1563 			   &sc->tx.txq_max_pending[WME_AC_VI]);
1564 	debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1565 			   &sc->tx.txq_max_pending[WME_AC_VO]);
1566 	debugfs_create_file("stations", S_IRUSR, sc->debug.debugfs_phy, sc,
1567 			    &fops_stations);
1568 	debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy, sc,
1569 			    &fops_misc);
1570 	debugfs_create_file("reset", S_IRUSR, sc->debug.debugfs_phy, sc,
1571 			    &fops_reset);
1572 	debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy, sc,
1573 			    &fops_recv);
1574 	debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
1575 			    sc->debug.debugfs_phy, sc, &fops_rx_chainmask);
1576 	debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
1577 			    sc->debug.debugfs_phy, sc, &fops_tx_chainmask);
1578 	debugfs_create_file("disable_ani", S_IRUSR | S_IWUSR,
1579 			    sc->debug.debugfs_phy, sc, &fops_disable_ani);
1580 	debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1581 			    &sc->sc_ah->config.enable_paprd);
1582 	debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1583 			    sc, &fops_regidx);
1584 	debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1585 			    sc, &fops_regval);
1586 	debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1587 			    sc->debug.debugfs_phy,
1588 			    &ah->config.cwm_ignore_extcca);
1589 	debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
1590 			    &fops_regdump);
1591 	debugfs_create_file("dump_nfcal", S_IRUSR, sc->debug.debugfs_phy, sc,
1592 			    &fops_dump_nfcal);
1593 	debugfs_create_file("base_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
1594 			    &fops_base_eeprom);
1595 	debugfs_create_file("modal_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
1596 			    &fops_modal_eeprom);
1597 #ifdef CONFIG_ATH9K_MAC_DEBUG
1598 	debugfs_create_file("samples", S_IRUSR, sc->debug.debugfs_phy, sc,
1599 			    &fops_samps);
1600 #endif
1601 
1602 	debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
1603 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
1604 
1605 	debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
1606 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
1607 
1608 	return 0;
1609 }
1610