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 <linux/relay.h>
21 #include <asm/unaligned.h>
22 
23 #include "ath9k.h"
24 
25 #define REG_WRITE_D(_ah, _reg, _val) \
26 	ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg))
27 #define REG_READ_D(_ah, _reg) \
28 	ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
29 
30 
31 static ssize_t ath9k_debugfs_read_buf(struct file *file, char __user *user_buf,
32 				      size_t count, loff_t *ppos)
33 {
34 	u8 *buf = file->private_data;
35 	return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
36 }
37 
38 static int ath9k_debugfs_release_buf(struct inode *inode, struct file *file)
39 {
40 	vfree(file->private_data);
41 	return 0;
42 }
43 
44 #ifdef CONFIG_ATH_DEBUG
45 
46 static ssize_t read_file_debug(struct file *file, char __user *user_buf,
47 			     size_t count, loff_t *ppos)
48 {
49 	struct ath_softc *sc = file->private_data;
50 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
51 	char buf[32];
52 	unsigned int len;
53 
54 	len = sprintf(buf, "0x%08x\n", common->debug_mask);
55 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
56 }
57 
58 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
59 			     size_t count, loff_t *ppos)
60 {
61 	struct ath_softc *sc = file->private_data;
62 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
63 	unsigned long mask;
64 	char buf[32];
65 	ssize_t len;
66 
67 	len = min(count, sizeof(buf) - 1);
68 	if (copy_from_user(buf, user_buf, len))
69 		return -EFAULT;
70 
71 	buf[len] = '\0';
72 	if (strict_strtoul(buf, 0, &mask))
73 		return -EINVAL;
74 
75 	common->debug_mask = mask;
76 	return count;
77 }
78 
79 static const struct file_operations fops_debug = {
80 	.read = read_file_debug,
81 	.write = write_file_debug,
82 	.open = simple_open,
83 	.owner = THIS_MODULE,
84 	.llseek = default_llseek,
85 };
86 
87 #endif
88 
89 #define DMA_BUF_LEN 1024
90 
91 static ssize_t read_file_tx_chainmask(struct file *file, char __user *user_buf,
92 			     size_t count, loff_t *ppos)
93 {
94 	struct ath_softc *sc = file->private_data;
95 	struct ath_hw *ah = sc->sc_ah;
96 	char buf[32];
97 	unsigned int len;
98 
99 	len = sprintf(buf, "0x%08x\n", ah->txchainmask);
100 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
101 }
102 
103 static ssize_t write_file_tx_chainmask(struct file *file, const char __user *user_buf,
104 			     size_t count, loff_t *ppos)
105 {
106 	struct ath_softc *sc = file->private_data;
107 	struct ath_hw *ah = sc->sc_ah;
108 	unsigned long mask;
109 	char buf[32];
110 	ssize_t len;
111 
112 	len = min(count, sizeof(buf) - 1);
113 	if (copy_from_user(buf, user_buf, len))
114 		return -EFAULT;
115 
116 	buf[len] = '\0';
117 	if (strict_strtoul(buf, 0, &mask))
118 		return -EINVAL;
119 
120 	ah->txchainmask = mask;
121 	ah->caps.tx_chainmask = mask;
122 	return count;
123 }
124 
125 static const struct file_operations fops_tx_chainmask = {
126 	.read = read_file_tx_chainmask,
127 	.write = write_file_tx_chainmask,
128 	.open = simple_open,
129 	.owner = THIS_MODULE,
130 	.llseek = default_llseek,
131 };
132 
133 
134 static ssize_t read_file_rx_chainmask(struct file *file, char __user *user_buf,
135 			     size_t count, loff_t *ppos)
136 {
137 	struct ath_softc *sc = file->private_data;
138 	struct ath_hw *ah = sc->sc_ah;
139 	char buf[32];
140 	unsigned int len;
141 
142 	len = sprintf(buf, "0x%08x\n", ah->rxchainmask);
143 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
144 }
145 
146 static ssize_t write_file_rx_chainmask(struct file *file, const char __user *user_buf,
147 			     size_t count, loff_t *ppos)
148 {
149 	struct ath_softc *sc = file->private_data;
150 	struct ath_hw *ah = sc->sc_ah;
151 	unsigned long mask;
152 	char buf[32];
153 	ssize_t len;
154 
155 	len = min(count, sizeof(buf) - 1);
156 	if (copy_from_user(buf, user_buf, len))
157 		return -EFAULT;
158 
159 	buf[len] = '\0';
160 	if (strict_strtoul(buf, 0, &mask))
161 		return -EINVAL;
162 
163 	ah->rxchainmask = mask;
164 	ah->caps.rx_chainmask = mask;
165 	return count;
166 }
167 
168 static const struct file_operations fops_rx_chainmask = {
169 	.read = read_file_rx_chainmask,
170 	.write = write_file_rx_chainmask,
171 	.open = simple_open,
172 	.owner = THIS_MODULE,
173 	.llseek = default_llseek,
174 };
175 
176 static ssize_t read_file_disable_ani(struct file *file, char __user *user_buf,
177 			     size_t count, loff_t *ppos)
178 {
179 	struct ath_softc *sc = file->private_data;
180 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
181 	char buf[32];
182 	unsigned int len;
183 
184 	len = sprintf(buf, "%d\n", common->disable_ani);
185 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
186 }
187 
188 static ssize_t write_file_disable_ani(struct file *file,
189 				      const char __user *user_buf,
190 				      size_t count, loff_t *ppos)
191 {
192 	struct ath_softc *sc = file->private_data;
193 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
194 	unsigned long disable_ani;
195 	char buf[32];
196 	ssize_t len;
197 
198 	len = min(count, sizeof(buf) - 1);
199 	if (copy_from_user(buf, user_buf, len))
200 		return -EFAULT;
201 
202 	buf[len] = '\0';
203 	if (strict_strtoul(buf, 0, &disable_ani))
204 		return -EINVAL;
205 
206 	common->disable_ani = !!disable_ani;
207 
208 	if (disable_ani) {
209 		clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
210 		ath_stop_ani(sc);
211 	} else {
212 		ath_check_ani(sc);
213 	}
214 
215 	return count;
216 }
217 
218 static const struct file_operations fops_disable_ani = {
219 	.read = read_file_disable_ani,
220 	.write = write_file_disable_ani,
221 	.open = simple_open,
222 	.owner = THIS_MODULE,
223 	.llseek = default_llseek,
224 };
225 
226 static ssize_t read_file_ant_diversity(struct file *file, char __user *user_buf,
227 				       size_t count, loff_t *ppos)
228 {
229 	struct ath_softc *sc = file->private_data;
230 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
231 	char buf[32];
232 	unsigned int len;
233 
234 	len = sprintf(buf, "%d\n", common->antenna_diversity);
235 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
236 }
237 
238 static ssize_t write_file_ant_diversity(struct file *file,
239 					const char __user *user_buf,
240 					size_t count, loff_t *ppos)
241 {
242 	struct ath_softc *sc = file->private_data;
243 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
244 	unsigned long antenna_diversity;
245 	char buf[32];
246 	ssize_t len;
247 
248 	len = min(count, sizeof(buf) - 1);
249 	if (copy_from_user(buf, user_buf, len))
250 		return -EFAULT;
251 
252 	if (!AR_SREV_9565(sc->sc_ah))
253 		goto exit;
254 
255 	buf[len] = '\0';
256 	if (strict_strtoul(buf, 0, &antenna_diversity))
257 		return -EINVAL;
258 
259 	common->antenna_diversity = !!antenna_diversity;
260 	ath9k_ps_wakeup(sc);
261 	ath_ant_comb_update(sc);
262 	ath_dbg(common, CONFIG, "Antenna diversity: %d\n",
263 		common->antenna_diversity);
264 	ath9k_ps_restore(sc);
265 exit:
266 	return count;
267 }
268 
269 static const struct file_operations fops_ant_diversity = {
270 	.read = read_file_ant_diversity,
271 	.write = write_file_ant_diversity,
272 	.open = simple_open,
273 	.owner = THIS_MODULE,
274 	.llseek = default_llseek,
275 };
276 
277 static ssize_t read_file_dma(struct file *file, char __user *user_buf,
278 			     size_t count, loff_t *ppos)
279 {
280 	struct ath_softc *sc = file->private_data;
281 	struct ath_hw *ah = sc->sc_ah;
282 	char *buf;
283 	int retval;
284 	unsigned int len = 0;
285 	u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
286 	int i, qcuOffset = 0, dcuOffset = 0;
287 	u32 *qcuBase = &val[0], *dcuBase = &val[4];
288 
289 	buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
290 	if (!buf)
291 		return -ENOMEM;
292 
293 	ath9k_ps_wakeup(sc);
294 
295 	REG_WRITE_D(ah, AR_MACMISC,
296 		  ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
297 		   (AR_MACMISC_MISC_OBS_BUS_1 <<
298 		    AR_MACMISC_MISC_OBS_BUS_MSB_S)));
299 
300 	len += snprintf(buf + len, DMA_BUF_LEN - len,
301 			"Raw DMA Debug values:\n");
302 
303 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
304 		if (i % 4 == 0)
305 			len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
306 
307 		val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
308 		len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
309 				i, val[i]);
310 	}
311 
312 	len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
313 	len += snprintf(buf + len, DMA_BUF_LEN - len,
314 			"Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
315 
316 	for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
317 		if (i == 8) {
318 			qcuOffset = 0;
319 			qcuBase++;
320 		}
321 
322 		if (i == 6) {
323 			dcuOffset = 0;
324 			dcuBase++;
325 		}
326 
327 		len += snprintf(buf + len, DMA_BUF_LEN - len,
328 			"%2d          %2x      %1x     %2x           %2x\n",
329 			i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
330 			(*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
331 			val[2] & (0x7 << (i * 3)) >> (i * 3),
332 			(*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
333 	}
334 
335 	len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
336 
337 	len += snprintf(buf + len, DMA_BUF_LEN - len,
338 		"qcu_stitch state:   %2x    qcu_fetch state:        %2x\n",
339 		(val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
340 	len += snprintf(buf + len, DMA_BUF_LEN - len,
341 		"qcu_complete state: %2x    dcu_complete state:     %2x\n",
342 		(val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
343 	len += snprintf(buf + len, DMA_BUF_LEN - len,
344 		"dcu_arb state:      %2x    dcu_fp state:           %2x\n",
345 		(val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
346 	len += snprintf(buf + len, DMA_BUF_LEN - len,
347 		"chan_idle_dur:     %3d    chan_idle_dur_valid:     %1d\n",
348 		(val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
349 	len += snprintf(buf + len, DMA_BUF_LEN - len,
350 		"txfifo_valid_0:      %1d    txfifo_valid_1:          %1d\n",
351 		(val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
352 	len += snprintf(buf + len, DMA_BUF_LEN - len,
353 		"txfifo_dcu_num_0:   %2d    txfifo_dcu_num_1:       %2d\n",
354 		(val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
355 
356 	len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
357 			REG_READ_D(ah, AR_OBS_BUS_1));
358 	len += snprintf(buf + len, DMA_BUF_LEN - len,
359 			"AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
360 
361 	ath9k_ps_restore(sc);
362 
363 	if (len > DMA_BUF_LEN)
364 		len = DMA_BUF_LEN;
365 
366 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
367 	kfree(buf);
368 	return retval;
369 }
370 
371 static const struct file_operations fops_dma = {
372 	.read = read_file_dma,
373 	.open = simple_open,
374 	.owner = THIS_MODULE,
375 	.llseek = default_llseek,
376 };
377 
378 
379 void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
380 {
381 	if (status)
382 		sc->debug.stats.istats.total++;
383 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
384 		if (status & ATH9K_INT_RXLP)
385 			sc->debug.stats.istats.rxlp++;
386 		if (status & ATH9K_INT_RXHP)
387 			sc->debug.stats.istats.rxhp++;
388 		if (status & ATH9K_INT_BB_WATCHDOG)
389 			sc->debug.stats.istats.bb_watchdog++;
390 	} else {
391 		if (status & ATH9K_INT_RX)
392 			sc->debug.stats.istats.rxok++;
393 	}
394 	if (status & ATH9K_INT_RXEOL)
395 		sc->debug.stats.istats.rxeol++;
396 	if (status & ATH9K_INT_RXORN)
397 		sc->debug.stats.istats.rxorn++;
398 	if (status & ATH9K_INT_TX)
399 		sc->debug.stats.istats.txok++;
400 	if (status & ATH9K_INT_TXURN)
401 		sc->debug.stats.istats.txurn++;
402 	if (status & ATH9K_INT_RXPHY)
403 		sc->debug.stats.istats.rxphyerr++;
404 	if (status & ATH9K_INT_RXKCM)
405 		sc->debug.stats.istats.rx_keycache_miss++;
406 	if (status & ATH9K_INT_SWBA)
407 		sc->debug.stats.istats.swba++;
408 	if (status & ATH9K_INT_BMISS)
409 		sc->debug.stats.istats.bmiss++;
410 	if (status & ATH9K_INT_BNR)
411 		sc->debug.stats.istats.bnr++;
412 	if (status & ATH9K_INT_CST)
413 		sc->debug.stats.istats.cst++;
414 	if (status & ATH9K_INT_GTT)
415 		sc->debug.stats.istats.gtt++;
416 	if (status & ATH9K_INT_TIM)
417 		sc->debug.stats.istats.tim++;
418 	if (status & ATH9K_INT_CABEND)
419 		sc->debug.stats.istats.cabend++;
420 	if (status & ATH9K_INT_DTIMSYNC)
421 		sc->debug.stats.istats.dtimsync++;
422 	if (status & ATH9K_INT_DTIM)
423 		sc->debug.stats.istats.dtim++;
424 	if (status & ATH9K_INT_TSFOOR)
425 		sc->debug.stats.istats.tsfoor++;
426 	if (status & ATH9K_INT_MCI)
427 		sc->debug.stats.istats.mci++;
428 	if (status & ATH9K_INT_GENTIMER)
429 		sc->debug.stats.istats.gen_timer++;
430 }
431 
432 static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
433 				   size_t count, loff_t *ppos)
434 {
435 	struct ath_softc *sc = file->private_data;
436 	unsigned int len = 0;
437 	int rv;
438 	int mxlen = 4000;
439 	char *buf = kmalloc(mxlen, GFP_KERNEL);
440 	if (!buf)
441 		return -ENOMEM;
442 
443 #define PR_IS(a, s)						\
444 	do {							\
445 		len += snprintf(buf + len, mxlen - len,		\
446 				"%21s: %10u\n", a,		\
447 				sc->debug.stats.istats.s);	\
448 	} while (0)
449 
450 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
451 		PR_IS("RXLP", rxlp);
452 		PR_IS("RXHP", rxhp);
453 		PR_IS("WATHDOG", bb_watchdog);
454 	} else {
455 		PR_IS("RX", rxok);
456 	}
457 	PR_IS("RXEOL", rxeol);
458 	PR_IS("RXORN", rxorn);
459 	PR_IS("TX", txok);
460 	PR_IS("TXURN", txurn);
461 	PR_IS("MIB", mib);
462 	PR_IS("RXPHY", rxphyerr);
463 	PR_IS("RXKCM", rx_keycache_miss);
464 	PR_IS("SWBA", swba);
465 	PR_IS("BMISS", bmiss);
466 	PR_IS("BNR", bnr);
467 	PR_IS("CST", cst);
468 	PR_IS("GTT", gtt);
469 	PR_IS("TIM", tim);
470 	PR_IS("CABEND", cabend);
471 	PR_IS("DTIMSYNC", dtimsync);
472 	PR_IS("DTIM", dtim);
473 	PR_IS("TSFOOR", tsfoor);
474 	PR_IS("MCI", mci);
475 	PR_IS("GENTIMER", gen_timer);
476 	PR_IS("TOTAL", total);
477 
478 	len += snprintf(buf + len, mxlen - len,
479 			"SYNC_CAUSE stats:\n");
480 
481 	PR_IS("Sync-All", sync_cause_all);
482 	PR_IS("RTC-IRQ", sync_rtc_irq);
483 	PR_IS("MAC-IRQ", sync_mac_irq);
484 	PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
485 	PR_IS("APB-Timeout", apb_timeout);
486 	PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
487 	PR_IS("HOST1-Fatal", host1_fatal);
488 	PR_IS("HOST1-Perr", host1_perr);
489 	PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
490 	PR_IS("RADM-CPL-EP", radm_cpl_ep);
491 	PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
492 	PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
493 	PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
494 	PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
495 	PR_IS("Local-Bus-Timeout", local_timeout);
496 	PR_IS("PM-Access", pm_access);
497 	PR_IS("MAC-Awake", mac_awake);
498 	PR_IS("MAC-Asleep", mac_asleep);
499 	PR_IS("MAC-Sleep-Access", mac_sleep_access);
500 
501 	if (len > mxlen)
502 		len = mxlen;
503 
504 	rv = simple_read_from_buffer(user_buf, count, ppos, buf, len);
505 	kfree(buf);
506 	return rv;
507 }
508 
509 static const struct file_operations fops_interrupt = {
510 	.read = read_file_interrupt,
511 	.open = simple_open,
512 	.owner = THIS_MODULE,
513 	.llseek = default_llseek,
514 };
515 
516 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
517 			      size_t count, loff_t *ppos)
518 {
519 	struct ath_softc *sc = file->private_data;
520 	char *buf;
521 	unsigned int len = 0, size = 2048;
522 	ssize_t retval = 0;
523 
524 	buf = kzalloc(size, GFP_KERNEL);
525 	if (buf == NULL)
526 		return -ENOMEM;
527 
528 	len += sprintf(buf, "%30s %10s%10s%10s\n\n",
529 		       "BE", "BK", "VI", "VO");
530 
531 	PR("MPDUs Queued:    ", queued);
532 	PR("MPDUs Completed: ", completed);
533 	PR("MPDUs XRetried:  ", xretries);
534 	PR("Aggregates:      ", a_aggr);
535 	PR("AMPDUs Queued HW:", a_queued_hw);
536 	PR("AMPDUs Queued SW:", a_queued_sw);
537 	PR("AMPDUs Completed:", a_completed);
538 	PR("AMPDUs Retried:  ", a_retries);
539 	PR("AMPDUs XRetried: ", a_xretries);
540 	PR("TXERR Filtered:  ", txerr_filtered);
541 	PR("FIFO Underrun:   ", fifo_underrun);
542 	PR("TXOP Exceeded:   ", xtxop);
543 	PR("TXTIMER Expiry:  ", timer_exp);
544 	PR("DESC CFG Error:  ", desc_cfg_err);
545 	PR("DATA Underrun:   ", data_underrun);
546 	PR("DELIM Underrun:  ", delim_underrun);
547 	PR("TX-Pkts-All:     ", tx_pkts_all);
548 	PR("TX-Bytes-All:    ", tx_bytes_all);
549 	PR("HW-put-tx-buf:   ", puttxbuf);
550 	PR("HW-tx-start:     ", txstart);
551 	PR("HW-tx-proc-desc: ", txprocdesc);
552 	PR("TX-Failed:       ", txfailed);
553 
554 	if (len > size)
555 		len = size;
556 
557 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
558 	kfree(buf);
559 
560 	return retval;
561 }
562 
563 static ssize_t read_file_queues(struct file *file, char __user *user_buf,
564 				size_t count, loff_t *ppos)
565 {
566 	struct ath_softc *sc = file->private_data;
567 	struct ath_txq *txq;
568 	char *buf;
569 	unsigned int len = 0, size = 1024;
570 	ssize_t retval = 0;
571 	int i;
572 	char *qname[4] = {"VO", "VI", "BE", "BK"};
573 
574 	buf = kzalloc(size, GFP_KERNEL);
575 	if (buf == NULL)
576 		return -ENOMEM;
577 
578 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
579 		txq = sc->tx.txq_map[i];
580 		len += snprintf(buf + len, size - len, "(%s): ", qname[i]);
581 
582 		ath_txq_lock(sc, txq);
583 
584 		len += snprintf(buf + len, size - len, "%s: %d ",
585 				"qnum", txq->axq_qnum);
586 		len += snprintf(buf + len, size - len, "%s: %2d ",
587 				"qdepth", txq->axq_depth);
588 		len += snprintf(buf + len, size - len, "%s: %2d ",
589 				"ampdu-depth", txq->axq_ampdu_depth);
590 		len += snprintf(buf + len, size - len, "%s: %3d ",
591 				"pending", txq->pending_frames);
592 		len += snprintf(buf + len, size - len, "%s: %d\n",
593 				"stopped", txq->stopped);
594 
595 		ath_txq_unlock(sc, txq);
596 	}
597 
598 	if (len > size)
599 		len = size;
600 
601 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
602 	kfree(buf);
603 
604 	return retval;
605 }
606 
607 static ssize_t read_file_misc(struct file *file, char __user *user_buf,
608 			      size_t count, loff_t *ppos)
609 {
610 	struct ath_softc *sc = file->private_data;
611 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
612 	struct ieee80211_hw *hw = sc->hw;
613 	struct ath9k_vif_iter_data iter_data;
614 	char buf[512];
615 	unsigned int len = 0;
616 	ssize_t retval = 0;
617 	unsigned int reg;
618 	u32 rxfilter;
619 
620 	len += snprintf(buf + len, sizeof(buf) - len,
621 			"BSSID: %pM\n", common->curbssid);
622 	len += snprintf(buf + len, sizeof(buf) - len,
623 			"BSSID-MASK: %pM\n", common->bssidmask);
624 	len += snprintf(buf + len, sizeof(buf) - len,
625 			"OPMODE: %s\n", ath_opmode_to_string(sc->sc_ah->opmode));
626 
627 	ath9k_ps_wakeup(sc);
628 	rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
629 	ath9k_ps_restore(sc);
630 
631 	len += snprintf(buf + len, sizeof(buf) - len,
632 			"RXFILTER: 0x%x", rxfilter);
633 
634 	if (rxfilter & ATH9K_RX_FILTER_UCAST)
635 		len += snprintf(buf + len, sizeof(buf) - len, " UCAST");
636 	if (rxfilter & ATH9K_RX_FILTER_MCAST)
637 		len += snprintf(buf + len, sizeof(buf) - len, " MCAST");
638 	if (rxfilter & ATH9K_RX_FILTER_BCAST)
639 		len += snprintf(buf + len, sizeof(buf) - len, " BCAST");
640 	if (rxfilter & ATH9K_RX_FILTER_CONTROL)
641 		len += snprintf(buf + len, sizeof(buf) - len, " CONTROL");
642 	if (rxfilter & ATH9K_RX_FILTER_BEACON)
643 		len += snprintf(buf + len, sizeof(buf) - len, " BEACON");
644 	if (rxfilter & ATH9K_RX_FILTER_PROM)
645 		len += snprintf(buf + len, sizeof(buf) - len, " PROM");
646 	if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
647 		len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
648 	if (rxfilter & ATH9K_RX_FILTER_PHYERR)
649 		len += snprintf(buf + len, sizeof(buf) - len, " PHYERR");
650 	if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
651 		len += snprintf(buf + len, sizeof(buf) - len, " MYBEACON");
652 	if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
653 		len += snprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
654 	if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
655 		len += snprintf(buf + len, sizeof(buf) - len, " PSPOLL");
656 	if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
657 		len += snprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
658 	if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
659 		len += snprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL");
660 	if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
661 		len += snprintf(buf + len, sizeof(buf) - len, " CONTROL_WRAPPER");
662 
663 	len += snprintf(buf + len, sizeof(buf) - len, "\n");
664 
665 	reg = sc->sc_ah->imask;
666 
667 	len += snprintf(buf + len, sizeof(buf) - len, "INTERRUPT-MASK: 0x%x", reg);
668 
669 	if (reg & ATH9K_INT_SWBA)
670 		len += snprintf(buf + len, sizeof(buf) - len, " SWBA");
671 	if (reg & ATH9K_INT_BMISS)
672 		len += snprintf(buf + len, sizeof(buf) - len, " BMISS");
673 	if (reg & ATH9K_INT_CST)
674 		len += snprintf(buf + len, sizeof(buf) - len, " CST");
675 	if (reg & ATH9K_INT_RX)
676 		len += snprintf(buf + len, sizeof(buf) - len, " RX");
677 	if (reg & ATH9K_INT_RXHP)
678 		len += snprintf(buf + len, sizeof(buf) - len, " RXHP");
679 	if (reg & ATH9K_INT_RXLP)
680 		len += snprintf(buf + len, sizeof(buf) - len, " RXLP");
681 	if (reg & ATH9K_INT_BB_WATCHDOG)
682 		len += snprintf(buf + len, sizeof(buf) - len, " BB_WATCHDOG");
683 
684 	len += snprintf(buf + len, sizeof(buf) - len, "\n");
685 
686 	ath9k_calculate_iter_data(hw, NULL, &iter_data);
687 
688 	len += snprintf(buf + len, sizeof(buf) - len,
689 			"VIF-COUNTS: AP: %i STA: %i MESH: %i WDS: %i"
690 			" ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n",
691 			iter_data.naps, iter_data.nstations, iter_data.nmeshes,
692 			iter_data.nwds, iter_data.nadhocs,
693 			sc->nvifs, sc->nbcnvifs);
694 
695 	if (len > sizeof(buf))
696 		len = sizeof(buf);
697 
698 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
699 	return retval;
700 }
701 
702 static ssize_t read_file_reset(struct file *file, char __user *user_buf,
703 			       size_t count, loff_t *ppos)
704 {
705 	struct ath_softc *sc = file->private_data;
706 	char buf[512];
707 	unsigned int len = 0;
708 
709 	len += snprintf(buf + len, sizeof(buf) - len,
710 			"%17s: %2d\n", "Baseband Hang",
711 			sc->debug.stats.reset[RESET_TYPE_BB_HANG]);
712 	len += snprintf(buf + len, sizeof(buf) - len,
713 			"%17s: %2d\n", "Baseband Watchdog",
714 			sc->debug.stats.reset[RESET_TYPE_BB_WATCHDOG]);
715 	len += snprintf(buf + len, sizeof(buf) - len,
716 			"%17s: %2d\n", "Fatal HW Error",
717 			sc->debug.stats.reset[RESET_TYPE_FATAL_INT]);
718 	len += snprintf(buf + len, sizeof(buf) - len,
719 			"%17s: %2d\n", "TX HW error",
720 			sc->debug.stats.reset[RESET_TYPE_TX_ERROR]);
721 	len += snprintf(buf + len, sizeof(buf) - len,
722 			"%17s: %2d\n", "TX Path Hang",
723 			sc->debug.stats.reset[RESET_TYPE_TX_HANG]);
724 	len += snprintf(buf + len, sizeof(buf) - len,
725 			"%17s: %2d\n", "PLL RX Hang",
726 			sc->debug.stats.reset[RESET_TYPE_PLL_HANG]);
727 	len += snprintf(buf + len, sizeof(buf) - len,
728 			"%17s: %2d\n", "MCI Reset",
729 			sc->debug.stats.reset[RESET_TYPE_MCI]);
730 
731 	if (len > sizeof(buf))
732 		len = sizeof(buf);
733 
734 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
735 }
736 
737 void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
738 		       struct ath_tx_status *ts, struct ath_txq *txq,
739 		       unsigned int flags)
740 {
741 #define TX_SAMP_DBG(c) (sc->debug.bb_mac_samp[sc->debug.sampidx].ts\
742 			[sc->debug.tsidx].c)
743 	int qnum = txq->axq_qnum;
744 
745 	TX_STAT_INC(qnum, tx_pkts_all);
746 	sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
747 
748 	if (bf_isampdu(bf)) {
749 		if (flags & ATH_TX_ERROR)
750 			TX_STAT_INC(qnum, a_xretries);
751 		else
752 			TX_STAT_INC(qnum, a_completed);
753 	} else {
754 		if (ts->ts_status & ATH9K_TXERR_XRETRY)
755 			TX_STAT_INC(qnum, xretries);
756 		else
757 			TX_STAT_INC(qnum, completed);
758 	}
759 
760 	if (ts->ts_status & ATH9K_TXERR_FILT)
761 		TX_STAT_INC(qnum, txerr_filtered);
762 	if (ts->ts_status & ATH9K_TXERR_FIFO)
763 		TX_STAT_INC(qnum, fifo_underrun);
764 	if (ts->ts_status & ATH9K_TXERR_XTXOP)
765 		TX_STAT_INC(qnum, xtxop);
766 	if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
767 		TX_STAT_INC(qnum, timer_exp);
768 	if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
769 		TX_STAT_INC(qnum, desc_cfg_err);
770 	if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
771 		TX_STAT_INC(qnum, data_underrun);
772 	if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
773 		TX_STAT_INC(qnum, delim_underrun);
774 
775 #ifdef CONFIG_ATH9K_MAC_DEBUG
776 	spin_lock(&sc->debug.samp_lock);
777 	TX_SAMP_DBG(jiffies) = jiffies;
778 	TX_SAMP_DBG(rssi_ctl0) = ts->ts_rssi_ctl0;
779 	TX_SAMP_DBG(rssi_ctl1) = ts->ts_rssi_ctl1;
780 	TX_SAMP_DBG(rssi_ctl2) = ts->ts_rssi_ctl2;
781 	TX_SAMP_DBG(rssi_ext0) = ts->ts_rssi_ext0;
782 	TX_SAMP_DBG(rssi_ext1) = ts->ts_rssi_ext1;
783 	TX_SAMP_DBG(rssi_ext2) = ts->ts_rssi_ext2;
784 	TX_SAMP_DBG(rateindex) = ts->ts_rateindex;
785 	TX_SAMP_DBG(isok) = !!(ts->ts_status & ATH9K_TXERR_MASK);
786 	TX_SAMP_DBG(rts_fail_cnt) = ts->ts_shortretry;
787 	TX_SAMP_DBG(data_fail_cnt) = ts->ts_longretry;
788 	TX_SAMP_DBG(rssi) = ts->ts_rssi;
789 	TX_SAMP_DBG(tid) = ts->tid;
790 	TX_SAMP_DBG(qid) = ts->qid;
791 
792 	if (ts->ts_flags & ATH9K_TX_BA) {
793 		TX_SAMP_DBG(ba_low) = ts->ba_low;
794 		TX_SAMP_DBG(ba_high) = ts->ba_high;
795 	} else {
796 		TX_SAMP_DBG(ba_low) = 0;
797 		TX_SAMP_DBG(ba_high) = 0;
798 	}
799 
800 	sc->debug.tsidx = (sc->debug.tsidx + 1) % ATH_DBG_MAX_SAMPLES;
801 	spin_unlock(&sc->debug.samp_lock);
802 #endif
803 
804 #undef TX_SAMP_DBG
805 }
806 
807 static const struct file_operations fops_xmit = {
808 	.read = read_file_xmit,
809 	.open = simple_open,
810 	.owner = THIS_MODULE,
811 	.llseek = default_llseek,
812 };
813 
814 static const struct file_operations fops_queues = {
815 	.read = read_file_queues,
816 	.open = simple_open,
817 	.owner = THIS_MODULE,
818 	.llseek = default_llseek,
819 };
820 
821 static const struct file_operations fops_misc = {
822 	.read = read_file_misc,
823 	.open = simple_open,
824 	.owner = THIS_MODULE,
825 	.llseek = default_llseek,
826 };
827 
828 static const struct file_operations fops_reset = {
829 	.read = read_file_reset,
830 	.open = simple_open,
831 	.owner = THIS_MODULE,
832 	.llseek = default_llseek,
833 };
834 
835 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
836 			      size_t count, loff_t *ppos)
837 {
838 #define PHY_ERR(s, p) \
839 	len += snprintf(buf + len, size - len, "%22s : %10u\n", s, \
840 			sc->debug.stats.rxstats.phy_err_stats[p]);
841 
842 #define RXS_ERR(s, e)					    \
843 	do {						    \
844 		len += snprintf(buf + len, size - len,	    \
845 				"%22s : %10u\n", s,	    \
846 				sc->debug.stats.rxstats.e); \
847 	} while (0)
848 
849 	struct ath_softc *sc = file->private_data;
850 	char *buf;
851 	unsigned int len = 0, size = 1600;
852 	ssize_t retval = 0;
853 
854 	buf = kzalloc(size, GFP_KERNEL);
855 	if (buf == NULL)
856 		return -ENOMEM;
857 
858 	RXS_ERR("CRC ERR", crc_err);
859 	RXS_ERR("DECRYPT CRC ERR", decrypt_crc_err);
860 	RXS_ERR("PHY ERR", phy_err);
861 	RXS_ERR("MIC ERR", mic_err);
862 	RXS_ERR("PRE-DELIM CRC ERR", pre_delim_crc_err);
863 	RXS_ERR("POST-DELIM CRC ERR", post_delim_crc_err);
864 	RXS_ERR("DECRYPT BUSY ERR", decrypt_busy_err);
865 	RXS_ERR("RX-LENGTH-ERR", rx_len_err);
866 	RXS_ERR("RX-OOM-ERR", rx_oom_err);
867 	RXS_ERR("RX-RATE-ERR", rx_rate_err);
868 	RXS_ERR("RX-TOO-MANY-FRAGS", rx_too_many_frags_err);
869 
870 	PHY_ERR("UNDERRUN ERR", ATH9K_PHYERR_UNDERRUN);
871 	PHY_ERR("TIMING ERR", ATH9K_PHYERR_TIMING);
872 	PHY_ERR("PARITY ERR", ATH9K_PHYERR_PARITY);
873 	PHY_ERR("RATE ERR", ATH9K_PHYERR_RATE);
874 	PHY_ERR("LENGTH ERR", ATH9K_PHYERR_LENGTH);
875 	PHY_ERR("RADAR ERR", ATH9K_PHYERR_RADAR);
876 	PHY_ERR("SERVICE ERR", ATH9K_PHYERR_SERVICE);
877 	PHY_ERR("TOR ERR", ATH9K_PHYERR_TOR);
878 	PHY_ERR("OFDM-TIMING ERR", ATH9K_PHYERR_OFDM_TIMING);
879 	PHY_ERR("OFDM-SIGNAL-PARITY ERR", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
880 	PHY_ERR("OFDM-RATE ERR", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
881 	PHY_ERR("OFDM-LENGTH ERR", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
882 	PHY_ERR("OFDM-POWER-DROP ERR", ATH9K_PHYERR_OFDM_POWER_DROP);
883 	PHY_ERR("OFDM-SERVICE ERR", ATH9K_PHYERR_OFDM_SERVICE);
884 	PHY_ERR("OFDM-RESTART ERR", ATH9K_PHYERR_OFDM_RESTART);
885 	PHY_ERR("FALSE-RADAR-EXT ERR", ATH9K_PHYERR_FALSE_RADAR_EXT);
886 	PHY_ERR("CCK-TIMING ERR", ATH9K_PHYERR_CCK_TIMING);
887 	PHY_ERR("CCK-HEADER-CRC ERR", ATH9K_PHYERR_CCK_HEADER_CRC);
888 	PHY_ERR("CCK-RATE ERR", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
889 	PHY_ERR("CCK-SERVICE ERR", ATH9K_PHYERR_CCK_SERVICE);
890 	PHY_ERR("CCK-RESTART ERR", ATH9K_PHYERR_CCK_RESTART);
891 	PHY_ERR("CCK-LENGTH ERR", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
892 	PHY_ERR("CCK-POWER-DROP ERR", ATH9K_PHYERR_CCK_POWER_DROP);
893 	PHY_ERR("HT-CRC ERR", ATH9K_PHYERR_HT_CRC_ERROR);
894 	PHY_ERR("HT-LENGTH ERR", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
895 	PHY_ERR("HT-RATE ERR", ATH9K_PHYERR_HT_RATE_ILLEGAL);
896 
897 	RXS_ERR("RX-Pkts-All", rx_pkts_all);
898 	RXS_ERR("RX-Bytes-All", rx_bytes_all);
899 	RXS_ERR("RX-Beacons", rx_beacons);
900 	RXS_ERR("RX-Frags", rx_frags);
901 	RXS_ERR("RX-Spectral", rx_spectral);
902 
903 	if (len > size)
904 		len = size;
905 
906 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
907 	kfree(buf);
908 
909 	return retval;
910 
911 #undef RXS_ERR
912 #undef PHY_ERR
913 }
914 
915 void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
916 {
917 #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
918 #define RX_SAMP_DBG(c) (sc->debug.bb_mac_samp[sc->debug.sampidx].rs\
919 			[sc->debug.rsidx].c)
920 
921 	RX_STAT_INC(rx_pkts_all);
922 	sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
923 
924 	if (rs->rs_status & ATH9K_RXERR_CRC)
925 		RX_STAT_INC(crc_err);
926 	if (rs->rs_status & ATH9K_RXERR_DECRYPT)
927 		RX_STAT_INC(decrypt_crc_err);
928 	if (rs->rs_status & ATH9K_RXERR_MIC)
929 		RX_STAT_INC(mic_err);
930 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
931 		RX_STAT_INC(pre_delim_crc_err);
932 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
933 		RX_STAT_INC(post_delim_crc_err);
934 	if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
935 		RX_STAT_INC(decrypt_busy_err);
936 
937 	if (rs->rs_status & ATH9K_RXERR_PHY) {
938 		RX_STAT_INC(phy_err);
939 		if (rs->rs_phyerr < ATH9K_PHYERR_MAX)
940 			RX_PHY_ERR_INC(rs->rs_phyerr);
941 	}
942 
943 #ifdef CONFIG_ATH9K_MAC_DEBUG
944 	spin_lock(&sc->debug.samp_lock);
945 	RX_SAMP_DBG(jiffies) = jiffies;
946 	RX_SAMP_DBG(rssi_ctl0) = rs->rs_rssi_ctl0;
947 	RX_SAMP_DBG(rssi_ctl1) = rs->rs_rssi_ctl1;
948 	RX_SAMP_DBG(rssi_ctl2) = rs->rs_rssi_ctl2;
949 	RX_SAMP_DBG(rssi_ext0) = rs->rs_rssi_ext0;
950 	RX_SAMP_DBG(rssi_ext1) = rs->rs_rssi_ext1;
951 	RX_SAMP_DBG(rssi_ext2) = rs->rs_rssi_ext2;
952 	RX_SAMP_DBG(antenna) = rs->rs_antenna;
953 	RX_SAMP_DBG(rssi) = rs->rs_rssi;
954 	RX_SAMP_DBG(rate) = rs->rs_rate;
955 	RX_SAMP_DBG(is_mybeacon) = rs->is_mybeacon;
956 
957 	sc->debug.rsidx = (sc->debug.rsidx + 1) % ATH_DBG_MAX_SAMPLES;
958 	spin_unlock(&sc->debug.samp_lock);
959 
960 #endif
961 
962 #undef RX_PHY_ERR_INC
963 #undef RX_SAMP_DBG
964 }
965 
966 static const struct file_operations fops_recv = {
967 	.read = read_file_recv,
968 	.open = simple_open,
969 	.owner = THIS_MODULE,
970 	.llseek = default_llseek,
971 };
972 
973 static ssize_t read_file_spec_scan_ctl(struct file *file, char __user *user_buf,
974 				       size_t count, loff_t *ppos)
975 {
976 	struct ath_softc *sc = file->private_data;
977 	char *mode = "";
978 	unsigned int len;
979 
980 	switch (sc->spectral_mode) {
981 	case SPECTRAL_DISABLED:
982 		mode = "disable";
983 		break;
984 	case SPECTRAL_BACKGROUND:
985 		mode = "background";
986 		break;
987 	case SPECTRAL_CHANSCAN:
988 		mode = "chanscan";
989 		break;
990 	case SPECTRAL_MANUAL:
991 		mode = "manual";
992 		break;
993 	}
994 	len = strlen(mode);
995 	return simple_read_from_buffer(user_buf, count, ppos, mode, len);
996 }
997 
998 static ssize_t write_file_spec_scan_ctl(struct file *file,
999 					const char __user *user_buf,
1000 					size_t count, loff_t *ppos)
1001 {
1002 	struct ath_softc *sc = file->private_data;
1003 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1004 	char buf[32];
1005 	ssize_t len;
1006 
1007 	len = min(count, sizeof(buf) - 1);
1008 	if (copy_from_user(buf, user_buf, len))
1009 		return -EFAULT;
1010 
1011 	buf[len] = '\0';
1012 
1013 	if (strncmp("trigger", buf, 7) == 0) {
1014 		ath9k_spectral_scan_trigger(sc->hw);
1015 	} else if (strncmp("background", buf, 9) == 0) {
1016 		ath9k_spectral_scan_config(sc->hw, SPECTRAL_BACKGROUND);
1017 		ath_dbg(common, CONFIG, "spectral scan: background mode enabled\n");
1018 	} else if (strncmp("chanscan", buf, 8) == 0) {
1019 		ath9k_spectral_scan_config(sc->hw, SPECTRAL_CHANSCAN);
1020 		ath_dbg(common, CONFIG, "spectral scan: channel scan mode enabled\n");
1021 	} else if (strncmp("manual", buf, 6) == 0) {
1022 		ath9k_spectral_scan_config(sc->hw, SPECTRAL_MANUAL);
1023 		ath_dbg(common, CONFIG, "spectral scan: manual mode enabled\n");
1024 	} else if (strncmp("disable", buf, 7) == 0) {
1025 		ath9k_spectral_scan_config(sc->hw, SPECTRAL_DISABLED);
1026 		ath_dbg(common, CONFIG, "spectral scan: disabled\n");
1027 	} else {
1028 		return -EINVAL;
1029 	}
1030 
1031 	return count;
1032 }
1033 
1034 static const struct file_operations fops_spec_scan_ctl = {
1035 	.read = read_file_spec_scan_ctl,
1036 	.write = write_file_spec_scan_ctl,
1037 	.open = simple_open,
1038 	.owner = THIS_MODULE,
1039 	.llseek = default_llseek,
1040 };
1041 
1042 static ssize_t read_file_spectral_short_repeat(struct file *file,
1043 					       char __user *user_buf,
1044 					       size_t count, loff_t *ppos)
1045 {
1046 	struct ath_softc *sc = file->private_data;
1047 	char buf[32];
1048 	unsigned int len;
1049 
1050 	len = sprintf(buf, "%d\n", sc->spec_config.short_repeat);
1051 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1052 }
1053 
1054 static ssize_t write_file_spectral_short_repeat(struct file *file,
1055 						const char __user *user_buf,
1056 						size_t count, loff_t *ppos)
1057 {
1058 	struct ath_softc *sc = file->private_data;
1059 	unsigned long val;
1060 	char buf[32];
1061 	ssize_t len;
1062 
1063 	len = min(count, sizeof(buf) - 1);
1064 	if (copy_from_user(buf, user_buf, len))
1065 		return -EFAULT;
1066 
1067 	buf[len] = '\0';
1068 	if (kstrtoul(buf, 0, &val))
1069 		return -EINVAL;
1070 
1071 	if (val < 0 || val > 1)
1072 		return -EINVAL;
1073 
1074 	sc->spec_config.short_repeat = val;
1075 	return count;
1076 }
1077 
1078 static const struct file_operations fops_spectral_short_repeat = {
1079 	.read = read_file_spectral_short_repeat,
1080 	.write = write_file_spectral_short_repeat,
1081 	.open = simple_open,
1082 	.owner = THIS_MODULE,
1083 	.llseek = default_llseek,
1084 };
1085 
1086 static ssize_t read_file_spectral_count(struct file *file,
1087 					char __user *user_buf,
1088 					size_t count, loff_t *ppos)
1089 {
1090 	struct ath_softc *sc = file->private_data;
1091 	char buf[32];
1092 	unsigned int len;
1093 
1094 	len = sprintf(buf, "%d\n", sc->spec_config.count);
1095 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1096 }
1097 
1098 static ssize_t write_file_spectral_count(struct file *file,
1099 					 const char __user *user_buf,
1100 					 size_t count, loff_t *ppos)
1101 {
1102 	struct ath_softc *sc = file->private_data;
1103 	unsigned long val;
1104 	char buf[32];
1105 	ssize_t len;
1106 
1107 	len = min(count, sizeof(buf) - 1);
1108 	if (copy_from_user(buf, user_buf, len))
1109 		return -EFAULT;
1110 
1111 	buf[len] = '\0';
1112 	if (kstrtoul(buf, 0, &val))
1113 		return -EINVAL;
1114 
1115 	if (val < 0 || val > 255)
1116 		return -EINVAL;
1117 
1118 	sc->spec_config.count = val;
1119 	return count;
1120 }
1121 
1122 static const struct file_operations fops_spectral_count = {
1123 	.read = read_file_spectral_count,
1124 	.write = write_file_spectral_count,
1125 	.open = simple_open,
1126 	.owner = THIS_MODULE,
1127 	.llseek = default_llseek,
1128 };
1129 
1130 static ssize_t read_file_spectral_period(struct file *file,
1131 					 char __user *user_buf,
1132 					 size_t count, loff_t *ppos)
1133 {
1134 	struct ath_softc *sc = file->private_data;
1135 	char buf[32];
1136 	unsigned int len;
1137 
1138 	len = sprintf(buf, "%d\n", sc->spec_config.period);
1139 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1140 }
1141 
1142 static ssize_t write_file_spectral_period(struct file *file,
1143 					  const char __user *user_buf,
1144 					  size_t count, loff_t *ppos)
1145 {
1146 	struct ath_softc *sc = file->private_data;
1147 	unsigned long val;
1148 	char buf[32];
1149 	ssize_t len;
1150 
1151 	len = min(count, sizeof(buf) - 1);
1152 	if (copy_from_user(buf, user_buf, len))
1153 		return -EFAULT;
1154 
1155 	buf[len] = '\0';
1156 	if (kstrtoul(buf, 0, &val))
1157 		return -EINVAL;
1158 
1159 	if (val < 0 || val > 255)
1160 		return -EINVAL;
1161 
1162 	sc->spec_config.period = val;
1163 	return count;
1164 }
1165 
1166 static const struct file_operations fops_spectral_period = {
1167 	.read = read_file_spectral_period,
1168 	.write = write_file_spectral_period,
1169 	.open = simple_open,
1170 	.owner = THIS_MODULE,
1171 	.llseek = default_llseek,
1172 };
1173 
1174 static ssize_t read_file_spectral_fft_period(struct file *file,
1175 					     char __user *user_buf,
1176 					     size_t count, loff_t *ppos)
1177 {
1178 	struct ath_softc *sc = file->private_data;
1179 	char buf[32];
1180 	unsigned int len;
1181 
1182 	len = sprintf(buf, "%d\n", sc->spec_config.fft_period);
1183 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1184 }
1185 
1186 static ssize_t write_file_spectral_fft_period(struct file *file,
1187 					      const char __user *user_buf,
1188 					      size_t count, loff_t *ppos)
1189 {
1190 	struct ath_softc *sc = file->private_data;
1191 	unsigned long val;
1192 	char buf[32];
1193 	ssize_t len;
1194 
1195 	len = min(count, sizeof(buf) - 1);
1196 	if (copy_from_user(buf, user_buf, len))
1197 		return -EFAULT;
1198 
1199 	buf[len] = '\0';
1200 	if (kstrtoul(buf, 0, &val))
1201 		return -EINVAL;
1202 
1203 	if (val < 0 || val > 15)
1204 		return -EINVAL;
1205 
1206 	sc->spec_config.fft_period = val;
1207 	return count;
1208 }
1209 
1210 static const struct file_operations fops_spectral_fft_period = {
1211 	.read = read_file_spectral_fft_period,
1212 	.write = write_file_spectral_fft_period,
1213 	.open = simple_open,
1214 	.owner = THIS_MODULE,
1215 	.llseek = default_llseek,
1216 };
1217 
1218 static struct dentry *create_buf_file_handler(const char *filename,
1219 					      struct dentry *parent,
1220 					      umode_t mode,
1221 					      struct rchan_buf *buf,
1222 					      int *is_global)
1223 {
1224 	struct dentry *buf_file;
1225 
1226 	buf_file = debugfs_create_file(filename, mode, parent, buf,
1227 				       &relay_file_operations);
1228 	*is_global = 1;
1229 	return buf_file;
1230 }
1231 
1232 static int remove_buf_file_handler(struct dentry *dentry)
1233 {
1234 	debugfs_remove(dentry);
1235 
1236 	return 0;
1237 }
1238 
1239 void ath_debug_send_fft_sample(struct ath_softc *sc,
1240 			       struct fft_sample_tlv *fft_sample_tlv)
1241 {
1242 	int length;
1243 	if (!sc->rfs_chan_spec_scan)
1244 		return;
1245 
1246 	length = __be16_to_cpu(fft_sample_tlv->length) +
1247 		 sizeof(*fft_sample_tlv);
1248 	relay_write(sc->rfs_chan_spec_scan, fft_sample_tlv, length);
1249 }
1250 
1251 static struct rchan_callbacks rfs_spec_scan_cb = {
1252 	.create_buf_file = create_buf_file_handler,
1253 	.remove_buf_file = remove_buf_file_handler,
1254 };
1255 
1256 
1257 static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
1258                                 size_t count, loff_t *ppos)
1259 {
1260 	struct ath_softc *sc = file->private_data;
1261 	char buf[32];
1262 	unsigned int len;
1263 
1264 	len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
1265 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1266 }
1267 
1268 static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
1269 			     size_t count, loff_t *ppos)
1270 {
1271 	struct ath_softc *sc = file->private_data;
1272 	unsigned long regidx;
1273 	char buf[32];
1274 	ssize_t len;
1275 
1276 	len = min(count, sizeof(buf) - 1);
1277 	if (copy_from_user(buf, user_buf, len))
1278 		return -EFAULT;
1279 
1280 	buf[len] = '\0';
1281 	if (strict_strtoul(buf, 0, &regidx))
1282 		return -EINVAL;
1283 
1284 	sc->debug.regidx = regidx;
1285 	return count;
1286 }
1287 
1288 static const struct file_operations fops_regidx = {
1289 	.read = read_file_regidx,
1290 	.write = write_file_regidx,
1291 	.open = simple_open,
1292 	.owner = THIS_MODULE,
1293 	.llseek = default_llseek,
1294 };
1295 
1296 static ssize_t read_file_regval(struct file *file, char __user *user_buf,
1297 			     size_t count, loff_t *ppos)
1298 {
1299 	struct ath_softc *sc = file->private_data;
1300 	struct ath_hw *ah = sc->sc_ah;
1301 	char buf[32];
1302 	unsigned int len;
1303 	u32 regval;
1304 
1305 	ath9k_ps_wakeup(sc);
1306 	regval = REG_READ_D(ah, sc->debug.regidx);
1307 	ath9k_ps_restore(sc);
1308 	len = sprintf(buf, "0x%08x\n", regval);
1309 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1310 }
1311 
1312 static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
1313 			     size_t count, loff_t *ppos)
1314 {
1315 	struct ath_softc *sc = file->private_data;
1316 	struct ath_hw *ah = sc->sc_ah;
1317 	unsigned long regval;
1318 	char buf[32];
1319 	ssize_t len;
1320 
1321 	len = min(count, sizeof(buf) - 1);
1322 	if (copy_from_user(buf, user_buf, len))
1323 		return -EFAULT;
1324 
1325 	buf[len] = '\0';
1326 	if (strict_strtoul(buf, 0, &regval))
1327 		return -EINVAL;
1328 
1329 	ath9k_ps_wakeup(sc);
1330 	REG_WRITE_D(ah, sc->debug.regidx, regval);
1331 	ath9k_ps_restore(sc);
1332 	return count;
1333 }
1334 
1335 static const struct file_operations fops_regval = {
1336 	.read = read_file_regval,
1337 	.write = write_file_regval,
1338 	.open = simple_open,
1339 	.owner = THIS_MODULE,
1340 	.llseek = default_llseek,
1341 };
1342 
1343 #define REGDUMP_LINE_SIZE	20
1344 
1345 static int open_file_regdump(struct inode *inode, struct file *file)
1346 {
1347 	struct ath_softc *sc = inode->i_private;
1348 	unsigned int len = 0;
1349 	u8 *buf;
1350 	int i;
1351 	unsigned long num_regs, regdump_len, max_reg_offset;
1352 
1353 	max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
1354 	num_regs = max_reg_offset / 4 + 1;
1355 	regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
1356 	buf = vmalloc(regdump_len);
1357 	if (!buf)
1358 		return -ENOMEM;
1359 
1360 	ath9k_ps_wakeup(sc);
1361 	for (i = 0; i < num_regs; i++)
1362 		len += scnprintf(buf + len, regdump_len - len,
1363 			"0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
1364 	ath9k_ps_restore(sc);
1365 
1366 	file->private_data = buf;
1367 
1368 	return 0;
1369 }
1370 
1371 static const struct file_operations fops_regdump = {
1372 	.open = open_file_regdump,
1373 	.read = ath9k_debugfs_read_buf,
1374 	.release = ath9k_debugfs_release_buf,
1375 	.owner = THIS_MODULE,
1376 	.llseek = default_llseek,/* read accesses f_pos */
1377 };
1378 
1379 static ssize_t read_file_dump_nfcal(struct file *file, char __user *user_buf,
1380 				    size_t count, loff_t *ppos)
1381 {
1382 	struct ath_softc *sc = file->private_data;
1383 	struct ath_hw *ah = sc->sc_ah;
1384 	struct ath9k_nfcal_hist *h = sc->caldata.nfCalHist;
1385 	struct ath_common *common = ath9k_hw_common(ah);
1386 	struct ieee80211_conf *conf = &common->hw->conf;
1387 	u32 len = 0, size = 1500;
1388 	u32 i, j;
1389 	ssize_t retval = 0;
1390 	char *buf;
1391 	u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1392 	u8 nread;
1393 
1394 	buf = kzalloc(size, GFP_KERNEL);
1395 	if (!buf)
1396 		return -ENOMEM;
1397 
1398 	len += snprintf(buf + len, size - len,
1399 			"Channel Noise Floor : %d\n", ah->noise);
1400 	len += snprintf(buf + len, size - len,
1401 			"Chain | privNF | # Readings | NF Readings\n");
1402 	for (i = 0; i < NUM_NF_READINGS; i++) {
1403 		if (!(chainmask & (1 << i)) ||
1404 		    ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1405 			continue;
1406 
1407 		nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
1408 		len += snprintf(buf + len, size - len, " %d\t %d\t %d\t\t",
1409 				i, h[i].privNF, nread);
1410 		for (j = 0; j < nread; j++)
1411 			len += snprintf(buf + len, size - len,
1412 					" %d", h[i].nfCalBuffer[j]);
1413 		len += snprintf(buf + len, size - len, "\n");
1414 	}
1415 
1416 	if (len > size)
1417 		len = size;
1418 
1419 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1420 	kfree(buf);
1421 
1422 	return retval;
1423 }
1424 
1425 static const struct file_operations fops_dump_nfcal = {
1426 	.read = read_file_dump_nfcal,
1427 	.open = simple_open,
1428 	.owner = THIS_MODULE,
1429 	.llseek = default_llseek,
1430 };
1431 
1432 static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf,
1433 				     size_t count, loff_t *ppos)
1434 {
1435 	struct ath_softc *sc = file->private_data;
1436 	struct ath_hw *ah = sc->sc_ah;
1437 	u32 len = 0, size = 1500;
1438 	ssize_t retval = 0;
1439 	char *buf;
1440 
1441 	buf = kzalloc(size, GFP_KERNEL);
1442 	if (!buf)
1443 		return -ENOMEM;
1444 
1445 	len = ah->eep_ops->dump_eeprom(ah, true, buf, len, size);
1446 
1447 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1448 	kfree(buf);
1449 
1450 	return retval;
1451 }
1452 
1453 static const struct file_operations fops_base_eeprom = {
1454 	.read = read_file_base_eeprom,
1455 	.open = simple_open,
1456 	.owner = THIS_MODULE,
1457 	.llseek = default_llseek,
1458 };
1459 
1460 static ssize_t read_file_modal_eeprom(struct file *file, char __user *user_buf,
1461 				      size_t count, loff_t *ppos)
1462 {
1463 	struct ath_softc *sc = file->private_data;
1464 	struct ath_hw *ah = sc->sc_ah;
1465 	u32 len = 0, size = 6000;
1466 	char *buf;
1467 	size_t retval;
1468 
1469 	buf = kzalloc(size, GFP_KERNEL);
1470 	if (buf == NULL)
1471 		return -ENOMEM;
1472 
1473 	len = ah->eep_ops->dump_eeprom(ah, false, buf, len, size);
1474 
1475 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1476 	kfree(buf);
1477 
1478 	return retval;
1479 }
1480 
1481 static const struct file_operations fops_modal_eeprom = {
1482 	.read = read_file_modal_eeprom,
1483 	.open = simple_open,
1484 	.owner = THIS_MODULE,
1485 	.llseek = default_llseek,
1486 };
1487 
1488 #ifdef CONFIG_ATH9K_MAC_DEBUG
1489 
1490 void ath9k_debug_samp_bb_mac(struct ath_softc *sc)
1491 {
1492 #define ATH_SAMP_DBG(c) (sc->debug.bb_mac_samp[sc->debug.sampidx].c)
1493 	struct ath_hw *ah = sc->sc_ah;
1494 	struct ath_common *common = ath9k_hw_common(ah);
1495 	unsigned long flags;
1496 	int i;
1497 
1498 	ath9k_ps_wakeup(sc);
1499 
1500 	spin_lock_bh(&sc->debug.samp_lock);
1501 
1502 	spin_lock_irqsave(&common->cc_lock, flags);
1503 	ath_hw_cycle_counters_update(common);
1504 
1505 	ATH_SAMP_DBG(cc.cycles) = common->cc_ani.cycles;
1506 	ATH_SAMP_DBG(cc.rx_busy) = common->cc_ani.rx_busy;
1507 	ATH_SAMP_DBG(cc.rx_frame) = common->cc_ani.rx_frame;
1508 	ATH_SAMP_DBG(cc.tx_frame) = common->cc_ani.tx_frame;
1509 	spin_unlock_irqrestore(&common->cc_lock, flags);
1510 
1511 	ATH_SAMP_DBG(noise) = ah->noise;
1512 
1513 	REG_WRITE_D(ah, AR_MACMISC,
1514 		  ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
1515 		   (AR_MACMISC_MISC_OBS_BUS_1 <<
1516 		    AR_MACMISC_MISC_OBS_BUS_MSB_S)));
1517 
1518 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++)
1519 		ATH_SAMP_DBG(dma_dbg_reg_vals[i]) = REG_READ_D(ah,
1520 				AR_DMADBG_0 + (i * sizeof(u32)));
1521 
1522 	ATH_SAMP_DBG(pcu_obs) = REG_READ_D(ah, AR_OBS_BUS_1);
1523 	ATH_SAMP_DBG(pcu_cr) = REG_READ_D(ah, AR_CR);
1524 
1525 	memcpy(ATH_SAMP_DBG(nfCalHist), sc->caldata.nfCalHist,
1526 			sizeof(ATH_SAMP_DBG(nfCalHist)));
1527 
1528 	sc->debug.sampidx = (sc->debug.sampidx + 1) % ATH_DBG_MAX_SAMPLES;
1529 	spin_unlock_bh(&sc->debug.samp_lock);
1530 	ath9k_ps_restore(sc);
1531 
1532 #undef ATH_SAMP_DBG
1533 }
1534 
1535 static int open_file_bb_mac_samps(struct inode *inode, struct file *file)
1536 {
1537 #define ATH_SAMP_DBG(c) bb_mac_samp[sampidx].c
1538 	struct ath_softc *sc = inode->i_private;
1539 	struct ath_hw *ah = sc->sc_ah;
1540 	struct ath_common *common = ath9k_hw_common(ah);
1541 	struct ieee80211_conf *conf = &common->hw->conf;
1542 	struct ath_dbg_bb_mac_samp *bb_mac_samp;
1543 	struct ath9k_nfcal_hist *h;
1544 	int i, j, qcuOffset = 0, dcuOffset = 0;
1545 	u32 *qcuBase, *dcuBase, size = 30000, len = 0;
1546 	u32 sampidx = 0;
1547 	u8 *buf;
1548 	u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1549 	u8 nread;
1550 
1551 	if (test_bit(SC_OP_INVALID, &sc->sc_flags))
1552 		return -EAGAIN;
1553 
1554 	buf = vmalloc(size);
1555 	if (!buf)
1556 		return -ENOMEM;
1557 	bb_mac_samp = vmalloc(sizeof(*bb_mac_samp) * ATH_DBG_MAX_SAMPLES);
1558 	if (!bb_mac_samp) {
1559 		vfree(buf);
1560 		return -ENOMEM;
1561 	}
1562 	/* Account the current state too */
1563 	ath9k_debug_samp_bb_mac(sc);
1564 
1565 	spin_lock_bh(&sc->debug.samp_lock);
1566 	memcpy(bb_mac_samp, sc->debug.bb_mac_samp,
1567 			sizeof(*bb_mac_samp) * ATH_DBG_MAX_SAMPLES);
1568 	len += snprintf(buf + len, size - len,
1569 			"Current Sample Index: %d\n", sc->debug.sampidx);
1570 	spin_unlock_bh(&sc->debug.samp_lock);
1571 
1572 	len += snprintf(buf + len, size - len,
1573 			"Raw DMA Debug Dump:\n");
1574 	len += snprintf(buf + len, size - len, "Sample |\t");
1575 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++)
1576 		len += snprintf(buf + len, size - len, " DMA Reg%d |\t", i);
1577 	len += snprintf(buf + len, size - len, "\n");
1578 
1579 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1580 		len += snprintf(buf + len, size - len, "%d\t", sampidx);
1581 
1582 		for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++)
1583 			len += snprintf(buf + len, size - len, " %08x\t",
1584 					ATH_SAMP_DBG(dma_dbg_reg_vals[i]));
1585 		len += snprintf(buf + len, size - len, "\n");
1586 	}
1587 	len += snprintf(buf + len, size - len, "\n");
1588 
1589 	len += snprintf(buf + len, size - len,
1590 			"Sample Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
1591 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1592 		qcuBase = &ATH_SAMP_DBG(dma_dbg_reg_vals[0]);
1593 		dcuBase = &ATH_SAMP_DBG(dma_dbg_reg_vals[4]);
1594 
1595 		for (i = 0; i < ATH9K_NUM_QUEUES; i++,
1596 				qcuOffset += 4, dcuOffset += 5) {
1597 			if (i == 8) {
1598 				qcuOffset = 0;
1599 				qcuBase++;
1600 			}
1601 
1602 			if (i == 6) {
1603 				dcuOffset = 0;
1604 				dcuBase++;
1605 			}
1606 			if (!sc->debug.stats.txstats[i].queued)
1607 				continue;
1608 
1609 			len += snprintf(buf + len, size - len,
1610 				"%4d %7d    %2x      %1x     %2x         %2x\n",
1611 				sampidx, i,
1612 				(*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
1613 				(*qcuBase & (0x8 << qcuOffset)) >>
1614 				(qcuOffset + 3),
1615 				ATH_SAMP_DBG(dma_dbg_reg_vals[2]) &
1616 				(0x7 << (i * 3)) >> (i * 3),
1617 				(*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
1618 		}
1619 		len += snprintf(buf + len, size - len, "\n");
1620 	}
1621 	len += snprintf(buf + len, size - len,
1622 			"samp qcu_sh qcu_fh qcu_comp dcu_comp dcu_arb dcu_fp "
1623 			"ch_idle_dur ch_idle_dur_val txfifo_val0 txfifo_val1 "
1624 			"txfifo_dcu0 txfifo_dcu1 pcu_obs AR_CR\n");
1625 
1626 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1627 		qcuBase = &ATH_SAMP_DBG(dma_dbg_reg_vals[0]);
1628 		dcuBase = &ATH_SAMP_DBG(dma_dbg_reg_vals[4]);
1629 
1630 		len += snprintf(buf + len, size - len, "%4d %5x %5x ", sampidx,
1631 			(ATH_SAMP_DBG(dma_dbg_reg_vals[3]) & 0x003c0000) >> 18,
1632 			(ATH_SAMP_DBG(dma_dbg_reg_vals[3]) & 0x03c00000) >> 22);
1633 		len += snprintf(buf + len, size - len, "%7x %8x ",
1634 			(ATH_SAMP_DBG(dma_dbg_reg_vals[3]) & 0x1c000000) >> 26,
1635 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x3));
1636 		len += snprintf(buf + len, size - len, "%7x %7x ",
1637 			(ATH_SAMP_DBG(dma_dbg_reg_vals[5]) & 0x06000000) >> 25,
1638 			(ATH_SAMP_DBG(dma_dbg_reg_vals[5]) & 0x38000000) >> 27);
1639 		len += snprintf(buf + len, size - len, "%7d %12d ",
1640 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x000003fc) >> 2,
1641 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x00000400) >> 10);
1642 		len += snprintf(buf + len, size - len, "%12d %12d ",
1643 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x00000800) >> 11,
1644 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x00001000) >> 12);
1645 		len += snprintf(buf + len, size - len, "%12d %12d ",
1646 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x0001e000) >> 13,
1647 			(ATH_SAMP_DBG(dma_dbg_reg_vals[6]) & 0x001e0000) >> 17);
1648 		len += snprintf(buf + len, size - len, "0x%07x 0x%07x\n",
1649 				ATH_SAMP_DBG(pcu_obs), ATH_SAMP_DBG(pcu_cr));
1650 	}
1651 
1652 	len += snprintf(buf + len, size - len,
1653 			"Sample ChNoise Chain privNF #Reading Readings\n");
1654 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1655 		h = ATH_SAMP_DBG(nfCalHist);
1656 		if (!ATH_SAMP_DBG(noise))
1657 			continue;
1658 
1659 		for (i = 0; i < NUM_NF_READINGS; i++) {
1660 			if (!(chainmask & (1 << i)) ||
1661 			    ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1662 				continue;
1663 
1664 			nread = AR_PHY_CCA_FILTERWINDOW_LENGTH -
1665 				h[i].invalidNFcount;
1666 			len += snprintf(buf + len, size - len,
1667 					"%4d %5d %4d\t   %d\t %d\t",
1668 					sampidx, ATH_SAMP_DBG(noise),
1669 					i, h[i].privNF, nread);
1670 			for (j = 0; j < nread; j++)
1671 				len += snprintf(buf + len, size - len,
1672 					" %d", h[i].nfCalBuffer[j]);
1673 			len += snprintf(buf + len, size - len, "\n");
1674 		}
1675 	}
1676 	len += snprintf(buf + len, size - len, "\nCycle counters:\n"
1677 			"Sample Total    Rxbusy   Rxframes Txframes\n");
1678 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1679 		if (!ATH_SAMP_DBG(cc.cycles))
1680 			continue;
1681 		len += snprintf(buf + len, size - len,
1682 				"%4d %08x %08x %08x %08x\n",
1683 				sampidx, ATH_SAMP_DBG(cc.cycles),
1684 				ATH_SAMP_DBG(cc.rx_busy),
1685 				ATH_SAMP_DBG(cc.rx_frame),
1686 				ATH_SAMP_DBG(cc.tx_frame));
1687 	}
1688 
1689 	len += snprintf(buf + len, size - len, "Tx status Dump :\n");
1690 	len += snprintf(buf + len, size - len,
1691 			"Sample rssi:- ctl0 ctl1 ctl2 ext0 ext1 ext2 comb "
1692 			"isok rts_fail data_fail rate tid qid "
1693 					"ba_low  ba_high tx_before(ms)\n");
1694 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1695 		for (i = 0; i < ATH_DBG_MAX_SAMPLES; i++) {
1696 			if (!ATH_SAMP_DBG(ts[i].jiffies))
1697 				continue;
1698 			len += snprintf(buf + len, size - len, "%-14d"
1699 				"%-4d %-4d %-4d %-4d %-4d %-4d %-4d %-4d %-8d "
1700 				"%-9d %-4d %-3d %-3d %08x %08x %-11d\n",
1701 				sampidx,
1702 				ATH_SAMP_DBG(ts[i].rssi_ctl0),
1703 				ATH_SAMP_DBG(ts[i].rssi_ctl1),
1704 				ATH_SAMP_DBG(ts[i].rssi_ctl2),
1705 				ATH_SAMP_DBG(ts[i].rssi_ext0),
1706 				ATH_SAMP_DBG(ts[i].rssi_ext1),
1707 				ATH_SAMP_DBG(ts[i].rssi_ext2),
1708 				ATH_SAMP_DBG(ts[i].rssi),
1709 				ATH_SAMP_DBG(ts[i].isok),
1710 				ATH_SAMP_DBG(ts[i].rts_fail_cnt),
1711 				ATH_SAMP_DBG(ts[i].data_fail_cnt),
1712 				ATH_SAMP_DBG(ts[i].rateindex),
1713 				ATH_SAMP_DBG(ts[i].tid),
1714 				ATH_SAMP_DBG(ts[i].qid),
1715 				ATH_SAMP_DBG(ts[i].ba_low),
1716 				ATH_SAMP_DBG(ts[i].ba_high),
1717 				jiffies_to_msecs(jiffies -
1718 					ATH_SAMP_DBG(ts[i].jiffies)));
1719 		}
1720 	}
1721 
1722 	len += snprintf(buf + len, size - len, "Rx status Dump :\n");
1723 	len += snprintf(buf + len, size - len, "Sample rssi:- ctl0 ctl1 ctl2 "
1724 			"ext0 ext1 ext2 comb beacon ant rate rx_before(ms)\n");
1725 	for (sampidx = 0; sampidx < ATH_DBG_MAX_SAMPLES; sampidx++) {
1726 		for (i = 0; i < ATH_DBG_MAX_SAMPLES; i++) {
1727 			if (!ATH_SAMP_DBG(rs[i].jiffies))
1728 				continue;
1729 			len += snprintf(buf + len, size - len, "%-14d"
1730 				"%-4d %-4d %-4d %-4d %-4d %-4d %-4d %-9s %-2d %02x %-13d\n",
1731 				sampidx,
1732 				ATH_SAMP_DBG(rs[i].rssi_ctl0),
1733 				ATH_SAMP_DBG(rs[i].rssi_ctl1),
1734 				ATH_SAMP_DBG(rs[i].rssi_ctl2),
1735 				ATH_SAMP_DBG(rs[i].rssi_ext0),
1736 				ATH_SAMP_DBG(rs[i].rssi_ext1),
1737 				ATH_SAMP_DBG(rs[i].rssi_ext2),
1738 				ATH_SAMP_DBG(rs[i].rssi),
1739 				ATH_SAMP_DBG(rs[i].is_mybeacon) ?
1740 				"True" : "False",
1741 				ATH_SAMP_DBG(rs[i].antenna),
1742 				ATH_SAMP_DBG(rs[i].rate),
1743 				jiffies_to_msecs(jiffies -
1744 					ATH_SAMP_DBG(rs[i].jiffies)));
1745 		}
1746 	}
1747 
1748 	vfree(bb_mac_samp);
1749 	file->private_data = buf;
1750 
1751 	return 0;
1752 #undef ATH_SAMP_DBG
1753 }
1754 
1755 static const struct file_operations fops_samps = {
1756 	.open = open_file_bb_mac_samps,
1757 	.read = ath9k_debugfs_read_buf,
1758 	.release = ath9k_debugfs_release_buf,
1759 	.owner = THIS_MODULE,
1760 	.llseek = default_llseek,
1761 };
1762 
1763 #endif
1764 
1765 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
1766 static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
1767 				size_t count, loff_t *ppos)
1768 {
1769 	struct ath_softc *sc = file->private_data;
1770 	u32 len = 0, size = 1500;
1771 	char *buf;
1772 	size_t retval;
1773 
1774 	buf = kzalloc(size, GFP_KERNEL);
1775 	if (buf == NULL)
1776 		return -ENOMEM;
1777 
1778 	if (!sc->sc_ah->common.btcoex_enabled) {
1779 		len = snprintf(buf, size, "%s\n",
1780 			       "BTCOEX is disabled");
1781 		goto exit;
1782 	}
1783 
1784 	len = ath9k_dump_btcoex(sc, buf, size);
1785 exit:
1786 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1787 	kfree(buf);
1788 
1789 	return retval;
1790 }
1791 
1792 static const struct file_operations fops_btcoex = {
1793 	.read = read_file_btcoex,
1794 	.open = simple_open,
1795 	.owner = THIS_MODULE,
1796 	.llseek = default_llseek,
1797 };
1798 #endif
1799 
1800 static ssize_t read_file_node_stat(struct file *file, char __user *user_buf,
1801 				   size_t count, loff_t *ppos)
1802 {
1803 	struct ath_node *an = file->private_data;
1804 	struct ath_softc *sc = an->sc;
1805 	struct ath_atx_tid *tid;
1806 	struct ath_atx_ac *ac;
1807 	struct ath_txq *txq;
1808 	u32 len = 0, size = 4096;
1809 	char *buf;
1810 	size_t retval;
1811 	int tidno, acno;
1812 
1813 	buf = kzalloc(size, GFP_KERNEL);
1814 	if (buf == NULL)
1815 		return -ENOMEM;
1816 
1817 	if (!an->sta->ht_cap.ht_supported) {
1818 		len = snprintf(buf, size, "%s\n",
1819 			       "HT not supported");
1820 		goto exit;
1821 	}
1822 
1823 	len = snprintf(buf, size, "Max-AMPDU: %d\n",
1824 		       an->maxampdu);
1825 	len += snprintf(buf + len, size - len, "MPDU Density: %d\n\n",
1826 			an->mpdudensity);
1827 
1828 	len += snprintf(buf + len, size - len,
1829 			"%2s%7s\n", "AC", "SCHED");
1830 
1831 	for (acno = 0, ac = &an->ac[acno];
1832 	     acno < IEEE80211_NUM_ACS; acno++, ac++) {
1833 		txq = ac->txq;
1834 		ath_txq_lock(sc, txq);
1835 		len += snprintf(buf + len, size - len,
1836 				"%2d%7d\n",
1837 				acno, ac->sched);
1838 		ath_txq_unlock(sc, txq);
1839 	}
1840 
1841 	len += snprintf(buf + len, size - len,
1842 			"\n%3s%11s%10s%10s%10s%10s%9s%6s%8s\n",
1843 			"TID", "SEQ_START", "SEQ_NEXT", "BAW_SIZE",
1844 			"BAW_HEAD", "BAW_TAIL", "BAR_IDX", "SCHED", "PAUSED");
1845 
1846 	for (tidno = 0, tid = &an->tid[tidno];
1847 	     tidno < IEEE80211_NUM_TIDS; tidno++, tid++) {
1848 		txq = tid->ac->txq;
1849 		ath_txq_lock(sc, txq);
1850 		len += snprintf(buf + len, size - len,
1851 				"%3d%11d%10d%10d%10d%10d%9d%6d%8d\n",
1852 				tid->tidno, tid->seq_start, tid->seq_next,
1853 				tid->baw_size, tid->baw_head, tid->baw_tail,
1854 				tid->bar_index, tid->sched, tid->paused);
1855 		ath_txq_unlock(sc, txq);
1856 	}
1857 exit:
1858 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1859 	kfree(buf);
1860 
1861 	return retval;
1862 }
1863 
1864 static const struct file_operations fops_node_stat = {
1865 	.read = read_file_node_stat,
1866 	.open = simple_open,
1867 	.owner = THIS_MODULE,
1868 	.llseek = default_llseek,
1869 };
1870 
1871 void ath9k_sta_add_debugfs(struct ieee80211_hw *hw,
1872 			   struct ieee80211_vif *vif,
1873 			   struct ieee80211_sta *sta,
1874 			   struct dentry *dir)
1875 {
1876 	struct ath_node *an = (struct ath_node *)sta->drv_priv;
1877 	an->node_stat = debugfs_create_file("node_stat", S_IRUGO,
1878 					    dir, an, &fops_node_stat);
1879 }
1880 
1881 void ath9k_sta_remove_debugfs(struct ieee80211_hw *hw,
1882 			      struct ieee80211_vif *vif,
1883 			      struct ieee80211_sta *sta,
1884 			      struct dentry *dir)
1885 {
1886 	struct ath_node *an = (struct ath_node *)sta->drv_priv;
1887 	debugfs_remove(an->node_stat);
1888 }
1889 
1890 /* Ethtool support for get-stats */
1891 
1892 #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1893 static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1894 	"tx_pkts_nic",
1895 	"tx_bytes_nic",
1896 	"rx_pkts_nic",
1897 	"rx_bytes_nic",
1898 	AMKSTR(d_tx_pkts),
1899 	AMKSTR(d_tx_bytes),
1900 	AMKSTR(d_tx_mpdus_queued),
1901 	AMKSTR(d_tx_mpdus_completed),
1902 	AMKSTR(d_tx_mpdu_xretries),
1903 	AMKSTR(d_tx_aggregates),
1904 	AMKSTR(d_tx_ampdus_queued_hw),
1905 	AMKSTR(d_tx_ampdus_queued_sw),
1906 	AMKSTR(d_tx_ampdus_completed),
1907 	AMKSTR(d_tx_ampdu_retries),
1908 	AMKSTR(d_tx_ampdu_xretries),
1909 	AMKSTR(d_tx_fifo_underrun),
1910 	AMKSTR(d_tx_op_exceeded),
1911 	AMKSTR(d_tx_timer_expiry),
1912 	AMKSTR(d_tx_desc_cfg_err),
1913 	AMKSTR(d_tx_data_underrun),
1914 	AMKSTR(d_tx_delim_underrun),
1915 	"d_rx_crc_err",
1916 	"d_rx_decrypt_crc_err",
1917 	"d_rx_phy_err",
1918 	"d_rx_mic_err",
1919 	"d_rx_pre_delim_crc_err",
1920 	"d_rx_post_delim_crc_err",
1921 	"d_rx_decrypt_busy_err",
1922 
1923 	"d_rx_phyerr_radar",
1924 	"d_rx_phyerr_ofdm_timing",
1925 	"d_rx_phyerr_cck_timing",
1926 
1927 };
1928 #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1929 
1930 void ath9k_get_et_strings(struct ieee80211_hw *hw,
1931 			  struct ieee80211_vif *vif,
1932 			  u32 sset, u8 *data)
1933 {
1934 	if (sset == ETH_SS_STATS)
1935 		memcpy(data, *ath9k_gstrings_stats,
1936 		       sizeof(ath9k_gstrings_stats));
1937 }
1938 
1939 int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
1940 			    struct ieee80211_vif *vif, int sset)
1941 {
1942 	if (sset == ETH_SS_STATS)
1943 		return ATH9K_SSTATS_LEN;
1944 	return 0;
1945 }
1946 
1947 #define AWDATA(elem)							\
1948 	do {								\
1949 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
1950 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
1951 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
1952 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
1953 	} while (0)
1954 
1955 #define AWDATA_RX(elem)						\
1956 	do {							\
1957 		data[i++] = sc->debug.stats.rxstats.elem;	\
1958 	} while (0)
1959 
1960 void ath9k_get_et_stats(struct ieee80211_hw *hw,
1961 			struct ieee80211_vif *vif,
1962 			struct ethtool_stats *stats, u64 *data)
1963 {
1964 	struct ath_softc *sc = hw->priv;
1965 	int i = 0;
1966 
1967 	data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
1968 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
1969 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
1970 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
1971 	data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
1972 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
1973 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
1974 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
1975 	AWDATA_RX(rx_pkts_all);
1976 	AWDATA_RX(rx_bytes_all);
1977 
1978 	AWDATA(tx_pkts_all);
1979 	AWDATA(tx_bytes_all);
1980 	AWDATA(queued);
1981 	AWDATA(completed);
1982 	AWDATA(xretries);
1983 	AWDATA(a_aggr);
1984 	AWDATA(a_queued_hw);
1985 	AWDATA(a_queued_sw);
1986 	AWDATA(a_completed);
1987 	AWDATA(a_retries);
1988 	AWDATA(a_xretries);
1989 	AWDATA(fifo_underrun);
1990 	AWDATA(xtxop);
1991 	AWDATA(timer_exp);
1992 	AWDATA(desc_cfg_err);
1993 	AWDATA(data_underrun);
1994 	AWDATA(delim_underrun);
1995 
1996 	AWDATA_RX(crc_err);
1997 	AWDATA_RX(decrypt_crc_err);
1998 	AWDATA_RX(phy_err);
1999 	AWDATA_RX(mic_err);
2000 	AWDATA_RX(pre_delim_crc_err);
2001 	AWDATA_RX(post_delim_crc_err);
2002 	AWDATA_RX(decrypt_busy_err);
2003 
2004 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
2005 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
2006 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
2007 
2008 	WARN_ON(i != ATH9K_SSTATS_LEN);
2009 }
2010 
2011 void ath9k_deinit_debug(struct ath_softc *sc)
2012 {
2013 	if (config_enabled(CONFIG_ATH9K_DEBUGFS) && sc->rfs_chan_spec_scan) {
2014 		relay_close(sc->rfs_chan_spec_scan);
2015 		sc->rfs_chan_spec_scan = NULL;
2016 	}
2017 }
2018 
2019 int ath9k_init_debug(struct ath_hw *ah)
2020 {
2021 	struct ath_common *common = ath9k_hw_common(ah);
2022 	struct ath_softc *sc = (struct ath_softc *) common->priv;
2023 
2024 	sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
2025 						   sc->hw->wiphy->debugfsdir);
2026 	if (!sc->debug.debugfs_phy)
2027 		return -ENOMEM;
2028 
2029 #ifdef CONFIG_ATH_DEBUG
2030 	debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
2031 			    sc, &fops_debug);
2032 #endif
2033 
2034 	ath9k_dfs_init_debug(sc);
2035 
2036 	debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
2037 			    &fops_dma);
2038 	debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
2039 			    &fops_interrupt);
2040 	debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc,
2041 			    &fops_xmit);
2042 	debugfs_create_file("queues", S_IRUSR, sc->debug.debugfs_phy, sc,
2043 			    &fops_queues);
2044 	debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
2045 			   &sc->tx.txq_max_pending[IEEE80211_AC_BK]);
2046 	debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
2047 			   &sc->tx.txq_max_pending[IEEE80211_AC_BE]);
2048 	debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
2049 			   &sc->tx.txq_max_pending[IEEE80211_AC_VI]);
2050 	debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
2051 			   &sc->tx.txq_max_pending[IEEE80211_AC_VO]);
2052 	debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy, sc,
2053 			    &fops_misc);
2054 	debugfs_create_file("reset", S_IRUSR, sc->debug.debugfs_phy, sc,
2055 			    &fops_reset);
2056 	debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy, sc,
2057 			    &fops_recv);
2058 	debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
2059 			    sc->debug.debugfs_phy, sc, &fops_rx_chainmask);
2060 	debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
2061 			    sc->debug.debugfs_phy, sc, &fops_tx_chainmask);
2062 	debugfs_create_file("disable_ani", S_IRUSR | S_IWUSR,
2063 			    sc->debug.debugfs_phy, sc, &fops_disable_ani);
2064 	debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
2065 			    &sc->sc_ah->config.enable_paprd);
2066 	debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
2067 			    sc, &fops_regidx);
2068 	debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
2069 			    sc, &fops_regval);
2070 	debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
2071 			    sc->debug.debugfs_phy,
2072 			    &ah->config.cwm_ignore_extcca);
2073 	debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
2074 			    &fops_regdump);
2075 	debugfs_create_file("dump_nfcal", S_IRUSR, sc->debug.debugfs_phy, sc,
2076 			    &fops_dump_nfcal);
2077 	debugfs_create_file("base_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
2078 			    &fops_base_eeprom);
2079 	debugfs_create_file("modal_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
2080 			    &fops_modal_eeprom);
2081 	sc->rfs_chan_spec_scan = relay_open("spectral_scan",
2082 					    sc->debug.debugfs_phy,
2083 					    1024, 256, &rfs_spec_scan_cb,
2084 					    NULL);
2085 	debugfs_create_file("spectral_scan_ctl", S_IRUSR | S_IWUSR,
2086 			    sc->debug.debugfs_phy, sc,
2087 			    &fops_spec_scan_ctl);
2088 	debugfs_create_file("spectral_short_repeat", S_IRUSR | S_IWUSR,
2089 			    sc->debug.debugfs_phy, sc,
2090 			    &fops_spectral_short_repeat);
2091 	debugfs_create_file("spectral_count", S_IRUSR | S_IWUSR,
2092 			    sc->debug.debugfs_phy, sc, &fops_spectral_count);
2093 	debugfs_create_file("spectral_period", S_IRUSR | S_IWUSR,
2094 			    sc->debug.debugfs_phy, sc, &fops_spectral_period);
2095 	debugfs_create_file("spectral_fft_period", S_IRUSR | S_IWUSR,
2096 			    sc->debug.debugfs_phy, sc,
2097 			    &fops_spectral_fft_period);
2098 
2099 #ifdef CONFIG_ATH9K_MAC_DEBUG
2100 	debugfs_create_file("samples", S_IRUSR, sc->debug.debugfs_phy, sc,
2101 			    &fops_samps);
2102 #endif
2103 	debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
2104 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
2105 	debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
2106 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
2107 	debugfs_create_file("diversity", S_IRUSR | S_IWUSR,
2108 			    sc->debug.debugfs_phy, sc, &fops_ant_diversity);
2109 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
2110 	debugfs_create_file("btcoex", S_IRUSR, sc->debug.debugfs_phy, sc,
2111 			    &fops_btcoex);
2112 #endif
2113 	return 0;
2114 }
2115