Merge remote-tracking branch 'wireless-next/master' into iwlwifi-next
[linux-2.6-microblaze.git] / drivers / net / wireless / ath / ath9k / debug.c
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         int qnum = txq->axq_qnum;
742
743         TX_STAT_INC(qnum, tx_pkts_all);
744         sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
745
746         if (bf_isampdu(bf)) {
747                 if (flags & ATH_TX_ERROR)
748                         TX_STAT_INC(qnum, a_xretries);
749                 else
750                         TX_STAT_INC(qnum, a_completed);
751         } else {
752                 if (ts->ts_status & ATH9K_TXERR_XRETRY)
753                         TX_STAT_INC(qnum, xretries);
754                 else
755                         TX_STAT_INC(qnum, completed);
756         }
757
758         if (ts->ts_status & ATH9K_TXERR_FILT)
759                 TX_STAT_INC(qnum, txerr_filtered);
760         if (ts->ts_status & ATH9K_TXERR_FIFO)
761                 TX_STAT_INC(qnum, fifo_underrun);
762         if (ts->ts_status & ATH9K_TXERR_XTXOP)
763                 TX_STAT_INC(qnum, xtxop);
764         if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
765                 TX_STAT_INC(qnum, timer_exp);
766         if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
767                 TX_STAT_INC(qnum, desc_cfg_err);
768         if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
769                 TX_STAT_INC(qnum, data_underrun);
770         if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
771                 TX_STAT_INC(qnum, delim_underrun);
772 }
773
774 static const struct file_operations fops_xmit = {
775         .read = read_file_xmit,
776         .open = simple_open,
777         .owner = THIS_MODULE,
778         .llseek = default_llseek,
779 };
780
781 static const struct file_operations fops_queues = {
782         .read = read_file_queues,
783         .open = simple_open,
784         .owner = THIS_MODULE,
785         .llseek = default_llseek,
786 };
787
788 static const struct file_operations fops_misc = {
789         .read = read_file_misc,
790         .open = simple_open,
791         .owner = THIS_MODULE,
792         .llseek = default_llseek,
793 };
794
795 static const struct file_operations fops_reset = {
796         .read = read_file_reset,
797         .open = simple_open,
798         .owner = THIS_MODULE,
799         .llseek = default_llseek,
800 };
801
802 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
803                               size_t count, loff_t *ppos)
804 {
805 #define PHY_ERR(s, p) \
806         len += snprintf(buf + len, size - len, "%22s : %10u\n", s, \
807                         sc->debug.stats.rxstats.phy_err_stats[p]);
808
809 #define RXS_ERR(s, e)                                       \
810         do {                                                \
811                 len += snprintf(buf + len, size - len,      \
812                                 "%22s : %10u\n", s,         \
813                                 sc->debug.stats.rxstats.e); \
814         } while (0)
815
816         struct ath_softc *sc = file->private_data;
817         char *buf;
818         unsigned int len = 0, size = 1600;
819         ssize_t retval = 0;
820
821         buf = kzalloc(size, GFP_KERNEL);
822         if (buf == NULL)
823                 return -ENOMEM;
824
825         RXS_ERR("CRC ERR", crc_err);
826         RXS_ERR("DECRYPT CRC ERR", decrypt_crc_err);
827         RXS_ERR("PHY ERR", phy_err);
828         RXS_ERR("MIC ERR", mic_err);
829         RXS_ERR("PRE-DELIM CRC ERR", pre_delim_crc_err);
830         RXS_ERR("POST-DELIM CRC ERR", post_delim_crc_err);
831         RXS_ERR("DECRYPT BUSY ERR", decrypt_busy_err);
832         RXS_ERR("RX-LENGTH-ERR", rx_len_err);
833         RXS_ERR("RX-OOM-ERR", rx_oom_err);
834         RXS_ERR("RX-RATE-ERR", rx_rate_err);
835         RXS_ERR("RX-TOO-MANY-FRAGS", rx_too_many_frags_err);
836
837         PHY_ERR("UNDERRUN ERR", ATH9K_PHYERR_UNDERRUN);
838         PHY_ERR("TIMING ERR", ATH9K_PHYERR_TIMING);
839         PHY_ERR("PARITY ERR", ATH9K_PHYERR_PARITY);
840         PHY_ERR("RATE ERR", ATH9K_PHYERR_RATE);
841         PHY_ERR("LENGTH ERR", ATH9K_PHYERR_LENGTH);
842         PHY_ERR("RADAR ERR", ATH9K_PHYERR_RADAR);
843         PHY_ERR("SERVICE ERR", ATH9K_PHYERR_SERVICE);
844         PHY_ERR("TOR ERR", ATH9K_PHYERR_TOR);
845         PHY_ERR("OFDM-TIMING ERR", ATH9K_PHYERR_OFDM_TIMING);
846         PHY_ERR("OFDM-SIGNAL-PARITY ERR", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
847         PHY_ERR("OFDM-RATE ERR", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
848         PHY_ERR("OFDM-LENGTH ERR", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
849         PHY_ERR("OFDM-POWER-DROP ERR", ATH9K_PHYERR_OFDM_POWER_DROP);
850         PHY_ERR("OFDM-SERVICE ERR", ATH9K_PHYERR_OFDM_SERVICE);
851         PHY_ERR("OFDM-RESTART ERR", ATH9K_PHYERR_OFDM_RESTART);
852         PHY_ERR("FALSE-RADAR-EXT ERR", ATH9K_PHYERR_FALSE_RADAR_EXT);
853         PHY_ERR("CCK-TIMING ERR", ATH9K_PHYERR_CCK_TIMING);
854         PHY_ERR("CCK-HEADER-CRC ERR", ATH9K_PHYERR_CCK_HEADER_CRC);
855         PHY_ERR("CCK-RATE ERR", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
856         PHY_ERR("CCK-SERVICE ERR", ATH9K_PHYERR_CCK_SERVICE);
857         PHY_ERR("CCK-RESTART ERR", ATH9K_PHYERR_CCK_RESTART);
858         PHY_ERR("CCK-LENGTH ERR", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
859         PHY_ERR("CCK-POWER-DROP ERR", ATH9K_PHYERR_CCK_POWER_DROP);
860         PHY_ERR("HT-CRC ERR", ATH9K_PHYERR_HT_CRC_ERROR);
861         PHY_ERR("HT-LENGTH ERR", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
862         PHY_ERR("HT-RATE ERR", ATH9K_PHYERR_HT_RATE_ILLEGAL);
863
864         RXS_ERR("RX-Pkts-All", rx_pkts_all);
865         RXS_ERR("RX-Bytes-All", rx_bytes_all);
866         RXS_ERR("RX-Beacons", rx_beacons);
867         RXS_ERR("RX-Frags", rx_frags);
868         RXS_ERR("RX-Spectral", rx_spectral);
869
870         if (len > size)
871                 len = size;
872
873         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
874         kfree(buf);
875
876         return retval;
877
878 #undef RXS_ERR
879 #undef PHY_ERR
880 }
881
882 void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
883 {
884 #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
885
886         RX_STAT_INC(rx_pkts_all);
887         sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
888
889         if (rs->rs_status & ATH9K_RXERR_CRC)
890                 RX_STAT_INC(crc_err);
891         if (rs->rs_status & ATH9K_RXERR_DECRYPT)
892                 RX_STAT_INC(decrypt_crc_err);
893         if (rs->rs_status & ATH9K_RXERR_MIC)
894                 RX_STAT_INC(mic_err);
895         if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
896                 RX_STAT_INC(pre_delim_crc_err);
897         if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
898                 RX_STAT_INC(post_delim_crc_err);
899         if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
900                 RX_STAT_INC(decrypt_busy_err);
901
902         if (rs->rs_status & ATH9K_RXERR_PHY) {
903                 RX_STAT_INC(phy_err);
904                 if (rs->rs_phyerr < ATH9K_PHYERR_MAX)
905                         RX_PHY_ERR_INC(rs->rs_phyerr);
906         }
907
908 #undef RX_PHY_ERR_INC
909 }
910
911 static const struct file_operations fops_recv = {
912         .read = read_file_recv,
913         .open = simple_open,
914         .owner = THIS_MODULE,
915         .llseek = default_llseek,
916 };
917
918 static ssize_t read_file_spec_scan_ctl(struct file *file, char __user *user_buf,
919                                        size_t count, loff_t *ppos)
920 {
921         struct ath_softc *sc = file->private_data;
922         char *mode = "";
923         unsigned int len;
924
925         switch (sc->spectral_mode) {
926         case SPECTRAL_DISABLED:
927                 mode = "disable";
928                 break;
929         case SPECTRAL_BACKGROUND:
930                 mode = "background";
931                 break;
932         case SPECTRAL_CHANSCAN:
933                 mode = "chanscan";
934                 break;
935         case SPECTRAL_MANUAL:
936                 mode = "manual";
937                 break;
938         }
939         len = strlen(mode);
940         return simple_read_from_buffer(user_buf, count, ppos, mode, len);
941 }
942
943 static ssize_t write_file_spec_scan_ctl(struct file *file,
944                                         const char __user *user_buf,
945                                         size_t count, loff_t *ppos)
946 {
947         struct ath_softc *sc = file->private_data;
948         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
949         char buf[32];
950         ssize_t len;
951
952         len = min(count, sizeof(buf) - 1);
953         if (copy_from_user(buf, user_buf, len))
954                 return -EFAULT;
955
956         buf[len] = '\0';
957
958         if (strncmp("trigger", buf, 7) == 0) {
959                 ath9k_spectral_scan_trigger(sc->hw);
960         } else if (strncmp("background", buf, 9) == 0) {
961                 ath9k_spectral_scan_config(sc->hw, SPECTRAL_BACKGROUND);
962                 ath_dbg(common, CONFIG, "spectral scan: background mode enabled\n");
963         } else if (strncmp("chanscan", buf, 8) == 0) {
964                 ath9k_spectral_scan_config(sc->hw, SPECTRAL_CHANSCAN);
965                 ath_dbg(common, CONFIG, "spectral scan: channel scan mode enabled\n");
966         } else if (strncmp("manual", buf, 6) == 0) {
967                 ath9k_spectral_scan_config(sc->hw, SPECTRAL_MANUAL);
968                 ath_dbg(common, CONFIG, "spectral scan: manual mode enabled\n");
969         } else if (strncmp("disable", buf, 7) == 0) {
970                 ath9k_spectral_scan_config(sc->hw, SPECTRAL_DISABLED);
971                 ath_dbg(common, CONFIG, "spectral scan: disabled\n");
972         } else {
973                 return -EINVAL;
974         }
975
976         return count;
977 }
978
979 static const struct file_operations fops_spec_scan_ctl = {
980         .read = read_file_spec_scan_ctl,
981         .write = write_file_spec_scan_ctl,
982         .open = simple_open,
983         .owner = THIS_MODULE,
984         .llseek = default_llseek,
985 };
986
987 static ssize_t read_file_spectral_short_repeat(struct file *file,
988                                                char __user *user_buf,
989                                                size_t count, loff_t *ppos)
990 {
991         struct ath_softc *sc = file->private_data;
992         char buf[32];
993         unsigned int len;
994
995         len = sprintf(buf, "%d\n", sc->spec_config.short_repeat);
996         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
997 }
998
999 static ssize_t write_file_spectral_short_repeat(struct file *file,
1000                                                 const char __user *user_buf,
1001                                                 size_t count, loff_t *ppos)
1002 {
1003         struct ath_softc *sc = file->private_data;
1004         unsigned long val;
1005         char buf[32];
1006         ssize_t len;
1007
1008         len = min(count, sizeof(buf) - 1);
1009         if (copy_from_user(buf, user_buf, len))
1010                 return -EFAULT;
1011
1012         buf[len] = '\0';
1013         if (kstrtoul(buf, 0, &val))
1014                 return -EINVAL;
1015
1016         if (val < 0 || val > 1)
1017                 return -EINVAL;
1018
1019         sc->spec_config.short_repeat = val;
1020         return count;
1021 }
1022
1023 static const struct file_operations fops_spectral_short_repeat = {
1024         .read = read_file_spectral_short_repeat,
1025         .write = write_file_spectral_short_repeat,
1026         .open = simple_open,
1027         .owner = THIS_MODULE,
1028         .llseek = default_llseek,
1029 };
1030
1031 static ssize_t read_file_spectral_count(struct file *file,
1032                                         char __user *user_buf,
1033                                         size_t count, loff_t *ppos)
1034 {
1035         struct ath_softc *sc = file->private_data;
1036         char buf[32];
1037         unsigned int len;
1038
1039         len = sprintf(buf, "%d\n", sc->spec_config.count);
1040         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1041 }
1042
1043 static ssize_t write_file_spectral_count(struct file *file,
1044                                          const char __user *user_buf,
1045                                          size_t count, loff_t *ppos)
1046 {
1047         struct ath_softc *sc = file->private_data;
1048         unsigned long val;
1049         char buf[32];
1050         ssize_t len;
1051
1052         len = min(count, sizeof(buf) - 1);
1053         if (copy_from_user(buf, user_buf, len))
1054                 return -EFAULT;
1055
1056         buf[len] = '\0';
1057         if (kstrtoul(buf, 0, &val))
1058                 return -EINVAL;
1059
1060         if (val < 0 || val > 255)
1061                 return -EINVAL;
1062
1063         sc->spec_config.count = val;
1064         return count;
1065 }
1066
1067 static const struct file_operations fops_spectral_count = {
1068         .read = read_file_spectral_count,
1069         .write = write_file_spectral_count,
1070         .open = simple_open,
1071         .owner = THIS_MODULE,
1072         .llseek = default_llseek,
1073 };
1074
1075 static ssize_t read_file_spectral_period(struct file *file,
1076                                          char __user *user_buf,
1077                                          size_t count, loff_t *ppos)
1078 {
1079         struct ath_softc *sc = file->private_data;
1080         char buf[32];
1081         unsigned int len;
1082
1083         len = sprintf(buf, "%d\n", sc->spec_config.period);
1084         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1085 }
1086
1087 static ssize_t write_file_spectral_period(struct file *file,
1088                                           const char __user *user_buf,
1089                                           size_t count, loff_t *ppos)
1090 {
1091         struct ath_softc *sc = file->private_data;
1092         unsigned long val;
1093         char buf[32];
1094         ssize_t len;
1095
1096         len = min(count, sizeof(buf) - 1);
1097         if (copy_from_user(buf, user_buf, len))
1098                 return -EFAULT;
1099
1100         buf[len] = '\0';
1101         if (kstrtoul(buf, 0, &val))
1102                 return -EINVAL;
1103
1104         if (val < 0 || val > 255)
1105                 return -EINVAL;
1106
1107         sc->spec_config.period = val;
1108         return count;
1109 }
1110
1111 static const struct file_operations fops_spectral_period = {
1112         .read = read_file_spectral_period,
1113         .write = write_file_spectral_period,
1114         .open = simple_open,
1115         .owner = THIS_MODULE,
1116         .llseek = default_llseek,
1117 };
1118
1119 static ssize_t read_file_spectral_fft_period(struct file *file,
1120                                              char __user *user_buf,
1121                                              size_t count, loff_t *ppos)
1122 {
1123         struct ath_softc *sc = file->private_data;
1124         char buf[32];
1125         unsigned int len;
1126
1127         len = sprintf(buf, "%d\n", sc->spec_config.fft_period);
1128         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1129 }
1130
1131 static ssize_t write_file_spectral_fft_period(struct file *file,
1132                                               const char __user *user_buf,
1133                                               size_t count, loff_t *ppos)
1134 {
1135         struct ath_softc *sc = file->private_data;
1136         unsigned long val;
1137         char buf[32];
1138         ssize_t len;
1139
1140         len = min(count, sizeof(buf) - 1);
1141         if (copy_from_user(buf, user_buf, len))
1142                 return -EFAULT;
1143
1144         buf[len] = '\0';
1145         if (kstrtoul(buf, 0, &val))
1146                 return -EINVAL;
1147
1148         if (val < 0 || val > 15)
1149                 return -EINVAL;
1150
1151         sc->spec_config.fft_period = val;
1152         return count;
1153 }
1154
1155 static const struct file_operations fops_spectral_fft_period = {
1156         .read = read_file_spectral_fft_period,
1157         .write = write_file_spectral_fft_period,
1158         .open = simple_open,
1159         .owner = THIS_MODULE,
1160         .llseek = default_llseek,
1161 };
1162
1163 static struct dentry *create_buf_file_handler(const char *filename,
1164                                               struct dentry *parent,
1165                                               umode_t mode,
1166                                               struct rchan_buf *buf,
1167                                               int *is_global)
1168 {
1169         struct dentry *buf_file;
1170
1171         buf_file = debugfs_create_file(filename, mode, parent, buf,
1172                                        &relay_file_operations);
1173         *is_global = 1;
1174         return buf_file;
1175 }
1176
1177 static int remove_buf_file_handler(struct dentry *dentry)
1178 {
1179         debugfs_remove(dentry);
1180
1181         return 0;
1182 }
1183
1184 void ath_debug_send_fft_sample(struct ath_softc *sc,
1185                                struct fft_sample_tlv *fft_sample_tlv)
1186 {
1187         int length;
1188         if (!sc->rfs_chan_spec_scan)
1189                 return;
1190
1191         length = __be16_to_cpu(fft_sample_tlv->length) +
1192                  sizeof(*fft_sample_tlv);
1193         relay_write(sc->rfs_chan_spec_scan, fft_sample_tlv, length);
1194 }
1195
1196 static struct rchan_callbacks rfs_spec_scan_cb = {
1197         .create_buf_file = create_buf_file_handler,
1198         .remove_buf_file = remove_buf_file_handler,
1199 };
1200
1201
1202 static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
1203                                 size_t count, loff_t *ppos)
1204 {
1205         struct ath_softc *sc = file->private_data;
1206         char buf[32];
1207         unsigned int len;
1208
1209         len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
1210         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1211 }
1212
1213 static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
1214                              size_t count, loff_t *ppos)
1215 {
1216         struct ath_softc *sc = file->private_data;
1217         unsigned long regidx;
1218         char buf[32];
1219         ssize_t len;
1220
1221         len = min(count, sizeof(buf) - 1);
1222         if (copy_from_user(buf, user_buf, len))
1223                 return -EFAULT;
1224
1225         buf[len] = '\0';
1226         if (strict_strtoul(buf, 0, &regidx))
1227                 return -EINVAL;
1228
1229         sc->debug.regidx = regidx;
1230         return count;
1231 }
1232
1233 static const struct file_operations fops_regidx = {
1234         .read = read_file_regidx,
1235         .write = write_file_regidx,
1236         .open = simple_open,
1237         .owner = THIS_MODULE,
1238         .llseek = default_llseek,
1239 };
1240
1241 static ssize_t read_file_regval(struct file *file, char __user *user_buf,
1242                              size_t count, loff_t *ppos)
1243 {
1244         struct ath_softc *sc = file->private_data;
1245         struct ath_hw *ah = sc->sc_ah;
1246         char buf[32];
1247         unsigned int len;
1248         u32 regval;
1249
1250         ath9k_ps_wakeup(sc);
1251         regval = REG_READ_D(ah, sc->debug.regidx);
1252         ath9k_ps_restore(sc);
1253         len = sprintf(buf, "0x%08x\n", regval);
1254         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1255 }
1256
1257 static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
1258                              size_t count, loff_t *ppos)
1259 {
1260         struct ath_softc *sc = file->private_data;
1261         struct ath_hw *ah = sc->sc_ah;
1262         unsigned long regval;
1263         char buf[32];
1264         ssize_t len;
1265
1266         len = min(count, sizeof(buf) - 1);
1267         if (copy_from_user(buf, user_buf, len))
1268                 return -EFAULT;
1269
1270         buf[len] = '\0';
1271         if (strict_strtoul(buf, 0, &regval))
1272                 return -EINVAL;
1273
1274         ath9k_ps_wakeup(sc);
1275         REG_WRITE_D(ah, sc->debug.regidx, regval);
1276         ath9k_ps_restore(sc);
1277         return count;
1278 }
1279
1280 static const struct file_operations fops_regval = {
1281         .read = read_file_regval,
1282         .write = write_file_regval,
1283         .open = simple_open,
1284         .owner = THIS_MODULE,
1285         .llseek = default_llseek,
1286 };
1287
1288 #define REGDUMP_LINE_SIZE       20
1289
1290 static int open_file_regdump(struct inode *inode, struct file *file)
1291 {
1292         struct ath_softc *sc = inode->i_private;
1293         unsigned int len = 0;
1294         u8 *buf;
1295         int i;
1296         unsigned long num_regs, regdump_len, max_reg_offset;
1297
1298         max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
1299         num_regs = max_reg_offset / 4 + 1;
1300         regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
1301         buf = vmalloc(regdump_len);
1302         if (!buf)
1303                 return -ENOMEM;
1304
1305         ath9k_ps_wakeup(sc);
1306         for (i = 0; i < num_regs; i++)
1307                 len += scnprintf(buf + len, regdump_len - len,
1308                         "0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
1309         ath9k_ps_restore(sc);
1310
1311         file->private_data = buf;
1312
1313         return 0;
1314 }
1315
1316 static const struct file_operations fops_regdump = {
1317         .open = open_file_regdump,
1318         .read = ath9k_debugfs_read_buf,
1319         .release = ath9k_debugfs_release_buf,
1320         .owner = THIS_MODULE,
1321         .llseek = default_llseek,/* read accesses f_pos */
1322 };
1323
1324 static ssize_t read_file_dump_nfcal(struct file *file, char __user *user_buf,
1325                                     size_t count, loff_t *ppos)
1326 {
1327         struct ath_softc *sc = file->private_data;
1328         struct ath_hw *ah = sc->sc_ah;
1329         struct ath9k_nfcal_hist *h = sc->caldata.nfCalHist;
1330         struct ath_common *common = ath9k_hw_common(ah);
1331         struct ieee80211_conf *conf = &common->hw->conf;
1332         u32 len = 0, size = 1500;
1333         u32 i, j;
1334         ssize_t retval = 0;
1335         char *buf;
1336         u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1337         u8 nread;
1338
1339         buf = kzalloc(size, GFP_KERNEL);
1340         if (!buf)
1341                 return -ENOMEM;
1342
1343         len += snprintf(buf + len, size - len,
1344                         "Channel Noise Floor : %d\n", ah->noise);
1345         len += snprintf(buf + len, size - len,
1346                         "Chain | privNF | # Readings | NF Readings\n");
1347         for (i = 0; i < NUM_NF_READINGS; i++) {
1348                 if (!(chainmask & (1 << i)) ||
1349                     ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1350                         continue;
1351
1352                 nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
1353                 len += snprintf(buf + len, size - len, " %d\t %d\t %d\t\t",
1354                                 i, h[i].privNF, nread);
1355                 for (j = 0; j < nread; j++)
1356                         len += snprintf(buf + len, size - len,
1357                                         " %d", h[i].nfCalBuffer[j]);
1358                 len += snprintf(buf + len, size - len, "\n");
1359         }
1360
1361         if (len > size)
1362                 len = size;
1363
1364         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1365         kfree(buf);
1366
1367         return retval;
1368 }
1369
1370 static const struct file_operations fops_dump_nfcal = {
1371         .read = read_file_dump_nfcal,
1372         .open = simple_open,
1373         .owner = THIS_MODULE,
1374         .llseek = default_llseek,
1375 };
1376
1377 static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf,
1378                                      size_t count, loff_t *ppos)
1379 {
1380         struct ath_softc *sc = file->private_data;
1381         struct ath_hw *ah = sc->sc_ah;
1382         u32 len = 0, size = 1500;
1383         ssize_t retval = 0;
1384         char *buf;
1385
1386         buf = kzalloc(size, GFP_KERNEL);
1387         if (!buf)
1388                 return -ENOMEM;
1389
1390         len = ah->eep_ops->dump_eeprom(ah, true, buf, len, size);
1391
1392         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1393         kfree(buf);
1394
1395         return retval;
1396 }
1397
1398 static const struct file_operations fops_base_eeprom = {
1399         .read = read_file_base_eeprom,
1400         .open = simple_open,
1401         .owner = THIS_MODULE,
1402         .llseek = default_llseek,
1403 };
1404
1405 static ssize_t read_file_modal_eeprom(struct file *file, char __user *user_buf,
1406                                       size_t count, loff_t *ppos)
1407 {
1408         struct ath_softc *sc = file->private_data;
1409         struct ath_hw *ah = sc->sc_ah;
1410         u32 len = 0, size = 6000;
1411         char *buf;
1412         size_t retval;
1413
1414         buf = kzalloc(size, GFP_KERNEL);
1415         if (buf == NULL)
1416                 return -ENOMEM;
1417
1418         len = ah->eep_ops->dump_eeprom(ah, false, buf, len, size);
1419
1420         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1421         kfree(buf);
1422
1423         return retval;
1424 }
1425
1426 static const struct file_operations fops_modal_eeprom = {
1427         .read = read_file_modal_eeprom,
1428         .open = simple_open,
1429         .owner = THIS_MODULE,
1430         .llseek = default_llseek,
1431 };
1432
1433 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
1434 static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
1435                                 size_t count, loff_t *ppos)
1436 {
1437         struct ath_softc *sc = file->private_data;
1438         u32 len = 0, size = 1500;
1439         char *buf;
1440         size_t retval;
1441
1442         buf = kzalloc(size, GFP_KERNEL);
1443         if (buf == NULL)
1444                 return -ENOMEM;
1445
1446         if (!sc->sc_ah->common.btcoex_enabled) {
1447                 len = snprintf(buf, size, "%s\n",
1448                                "BTCOEX is disabled");
1449                 goto exit;
1450         }
1451
1452         len = ath9k_dump_btcoex(sc, buf, size);
1453 exit:
1454         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1455         kfree(buf);
1456
1457         return retval;
1458 }
1459
1460 static const struct file_operations fops_btcoex = {
1461         .read = read_file_btcoex,
1462         .open = simple_open,
1463         .owner = THIS_MODULE,
1464         .llseek = default_llseek,
1465 };
1466 #endif
1467
1468 static ssize_t read_file_node_stat(struct file *file, char __user *user_buf,
1469                                    size_t count, loff_t *ppos)
1470 {
1471         struct ath_node *an = file->private_data;
1472         struct ath_softc *sc = an->sc;
1473         struct ath_atx_tid *tid;
1474         struct ath_atx_ac *ac;
1475         struct ath_txq *txq;
1476         u32 len = 0, size = 4096;
1477         char *buf;
1478         size_t retval;
1479         int tidno, acno;
1480
1481         buf = kzalloc(size, GFP_KERNEL);
1482         if (buf == NULL)
1483                 return -ENOMEM;
1484
1485         if (!an->sta->ht_cap.ht_supported) {
1486                 len = snprintf(buf, size, "%s\n",
1487                                "HT not supported");
1488                 goto exit;
1489         }
1490
1491         len = snprintf(buf, size, "Max-AMPDU: %d\n",
1492                        an->maxampdu);
1493         len += snprintf(buf + len, size - len, "MPDU Density: %d\n\n",
1494                         an->mpdudensity);
1495
1496         len += snprintf(buf + len, size - len,
1497                         "%2s%7s\n", "AC", "SCHED");
1498
1499         for (acno = 0, ac = &an->ac[acno];
1500              acno < IEEE80211_NUM_ACS; acno++, ac++) {
1501                 txq = ac->txq;
1502                 ath_txq_lock(sc, txq);
1503                 len += snprintf(buf + len, size - len,
1504                                 "%2d%7d\n",
1505                                 acno, ac->sched);
1506                 ath_txq_unlock(sc, txq);
1507         }
1508
1509         len += snprintf(buf + len, size - len,
1510                         "\n%3s%11s%10s%10s%10s%10s%9s%6s%8s\n",
1511                         "TID", "SEQ_START", "SEQ_NEXT", "BAW_SIZE",
1512                         "BAW_HEAD", "BAW_TAIL", "BAR_IDX", "SCHED", "PAUSED");
1513
1514         for (tidno = 0, tid = &an->tid[tidno];
1515              tidno < IEEE80211_NUM_TIDS; tidno++, tid++) {
1516                 txq = tid->ac->txq;
1517                 ath_txq_lock(sc, txq);
1518                 len += snprintf(buf + len, size - len,
1519                                 "%3d%11d%10d%10d%10d%10d%9d%6d%8d\n",
1520                                 tid->tidno, tid->seq_start, tid->seq_next,
1521                                 tid->baw_size, tid->baw_head, tid->baw_tail,
1522                                 tid->bar_index, tid->sched, tid->paused);
1523                 ath_txq_unlock(sc, txq);
1524         }
1525 exit:
1526         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1527         kfree(buf);
1528
1529         return retval;
1530 }
1531
1532 static const struct file_operations fops_node_stat = {
1533         .read = read_file_node_stat,
1534         .open = simple_open,
1535         .owner = THIS_MODULE,
1536         .llseek = default_llseek,
1537 };
1538
1539 void ath9k_sta_add_debugfs(struct ieee80211_hw *hw,
1540                            struct ieee80211_vif *vif,
1541                            struct ieee80211_sta *sta,
1542                            struct dentry *dir)
1543 {
1544         struct ath_node *an = (struct ath_node *)sta->drv_priv;
1545         an->node_stat = debugfs_create_file("node_stat", S_IRUGO,
1546                                             dir, an, &fops_node_stat);
1547 }
1548
1549 void ath9k_sta_remove_debugfs(struct ieee80211_hw *hw,
1550                               struct ieee80211_vif *vif,
1551                               struct ieee80211_sta *sta,
1552                               struct dentry *dir)
1553 {
1554         struct ath_node *an = (struct ath_node *)sta->drv_priv;
1555         debugfs_remove(an->node_stat);
1556 }
1557
1558 /* Ethtool support for get-stats */
1559
1560 #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1561 static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1562         "tx_pkts_nic",
1563         "tx_bytes_nic",
1564         "rx_pkts_nic",
1565         "rx_bytes_nic",
1566         AMKSTR(d_tx_pkts),
1567         AMKSTR(d_tx_bytes),
1568         AMKSTR(d_tx_mpdus_queued),
1569         AMKSTR(d_tx_mpdus_completed),
1570         AMKSTR(d_tx_mpdu_xretries),
1571         AMKSTR(d_tx_aggregates),
1572         AMKSTR(d_tx_ampdus_queued_hw),
1573         AMKSTR(d_tx_ampdus_queued_sw),
1574         AMKSTR(d_tx_ampdus_completed),
1575         AMKSTR(d_tx_ampdu_retries),
1576         AMKSTR(d_tx_ampdu_xretries),
1577         AMKSTR(d_tx_fifo_underrun),
1578         AMKSTR(d_tx_op_exceeded),
1579         AMKSTR(d_tx_timer_expiry),
1580         AMKSTR(d_tx_desc_cfg_err),
1581         AMKSTR(d_tx_data_underrun),
1582         AMKSTR(d_tx_delim_underrun),
1583         "d_rx_crc_err",
1584         "d_rx_decrypt_crc_err",
1585         "d_rx_phy_err",
1586         "d_rx_mic_err",
1587         "d_rx_pre_delim_crc_err",
1588         "d_rx_post_delim_crc_err",
1589         "d_rx_decrypt_busy_err",
1590
1591         "d_rx_phyerr_radar",
1592         "d_rx_phyerr_ofdm_timing",
1593         "d_rx_phyerr_cck_timing",
1594
1595 };
1596 #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1597
1598 void ath9k_get_et_strings(struct ieee80211_hw *hw,
1599                           struct ieee80211_vif *vif,
1600                           u32 sset, u8 *data)
1601 {
1602         if (sset == ETH_SS_STATS)
1603                 memcpy(data, *ath9k_gstrings_stats,
1604                        sizeof(ath9k_gstrings_stats));
1605 }
1606
1607 int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
1608                             struct ieee80211_vif *vif, int sset)
1609 {
1610         if (sset == ETH_SS_STATS)
1611                 return ATH9K_SSTATS_LEN;
1612         return 0;
1613 }
1614
1615 #define AWDATA(elem)                                                    \
1616         do {                                                            \
1617                 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
1618                 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
1619                 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
1620                 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
1621         } while (0)
1622
1623 #define AWDATA_RX(elem)                                         \
1624         do {                                                    \
1625                 data[i++] = sc->debug.stats.rxstats.elem;       \
1626         } while (0)
1627
1628 void ath9k_get_et_stats(struct ieee80211_hw *hw,
1629                         struct ieee80211_vif *vif,
1630                         struct ethtool_stats *stats, u64 *data)
1631 {
1632         struct ath_softc *sc = hw->priv;
1633         int i = 0;
1634
1635         data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
1636                      sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
1637                      sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
1638                      sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
1639         data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
1640                      sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
1641                      sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
1642                      sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
1643         AWDATA_RX(rx_pkts_all);
1644         AWDATA_RX(rx_bytes_all);
1645
1646         AWDATA(tx_pkts_all);
1647         AWDATA(tx_bytes_all);
1648         AWDATA(queued);
1649         AWDATA(completed);
1650         AWDATA(xretries);
1651         AWDATA(a_aggr);
1652         AWDATA(a_queued_hw);
1653         AWDATA(a_queued_sw);
1654         AWDATA(a_completed);
1655         AWDATA(a_retries);
1656         AWDATA(a_xretries);
1657         AWDATA(fifo_underrun);
1658         AWDATA(xtxop);
1659         AWDATA(timer_exp);
1660         AWDATA(desc_cfg_err);
1661         AWDATA(data_underrun);
1662         AWDATA(delim_underrun);
1663
1664         AWDATA_RX(crc_err);
1665         AWDATA_RX(decrypt_crc_err);
1666         AWDATA_RX(phy_err);
1667         AWDATA_RX(mic_err);
1668         AWDATA_RX(pre_delim_crc_err);
1669         AWDATA_RX(post_delim_crc_err);
1670         AWDATA_RX(decrypt_busy_err);
1671
1672         AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
1673         AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
1674         AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
1675
1676         WARN_ON(i != ATH9K_SSTATS_LEN);
1677 }
1678
1679 int ath9k_init_debug(struct ath_hw *ah)
1680 {
1681         struct ath_common *common = ath9k_hw_common(ah);
1682         struct ath_softc *sc = (struct ath_softc *) common->priv;
1683
1684         sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1685                                                    sc->hw->wiphy->debugfsdir);
1686         if (!sc->debug.debugfs_phy)
1687                 return -ENOMEM;
1688
1689 #ifdef CONFIG_ATH_DEBUG
1690         debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1691                             sc, &fops_debug);
1692 #endif
1693
1694         ath9k_dfs_init_debug(sc);
1695
1696         debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
1697                             &fops_dma);
1698         debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
1699                             &fops_interrupt);
1700         debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc,
1701                             &fops_xmit);
1702         debugfs_create_file("queues", S_IRUSR, sc->debug.debugfs_phy, sc,
1703                             &fops_queues);
1704         debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1705                            &sc->tx.txq_max_pending[IEEE80211_AC_BK]);
1706         debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1707                            &sc->tx.txq_max_pending[IEEE80211_AC_BE]);
1708         debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1709                            &sc->tx.txq_max_pending[IEEE80211_AC_VI]);
1710         debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1711                            &sc->tx.txq_max_pending[IEEE80211_AC_VO]);
1712         debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy, sc,
1713                             &fops_misc);
1714         debugfs_create_file("reset", S_IRUSR, sc->debug.debugfs_phy, sc,
1715                             &fops_reset);
1716         debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy, sc,
1717                             &fops_recv);
1718         debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
1719                             sc->debug.debugfs_phy, sc, &fops_rx_chainmask);
1720         debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
1721                             sc->debug.debugfs_phy, sc, &fops_tx_chainmask);
1722         debugfs_create_file("disable_ani", S_IRUSR | S_IWUSR,
1723                             sc->debug.debugfs_phy, sc, &fops_disable_ani);
1724         debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1725                             &sc->sc_ah->config.enable_paprd);
1726         debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1727                             sc, &fops_regidx);
1728         debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1729                             sc, &fops_regval);
1730         debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1731                             sc->debug.debugfs_phy,
1732                             &ah->config.cwm_ignore_extcca);
1733         debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
1734                             &fops_regdump);
1735         debugfs_create_file("dump_nfcal", S_IRUSR, sc->debug.debugfs_phy, sc,
1736                             &fops_dump_nfcal);
1737         debugfs_create_file("base_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
1738                             &fops_base_eeprom);
1739         debugfs_create_file("modal_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
1740                             &fops_modal_eeprom);
1741         sc->rfs_chan_spec_scan = relay_open("spectral_scan",
1742                                             sc->debug.debugfs_phy,
1743                                             1024, 256, &rfs_spec_scan_cb,
1744                                             NULL);
1745         debugfs_create_file("spectral_scan_ctl", S_IRUSR | S_IWUSR,
1746                             sc->debug.debugfs_phy, sc,
1747                             &fops_spec_scan_ctl);
1748         debugfs_create_file("spectral_short_repeat", S_IRUSR | S_IWUSR,
1749                             sc->debug.debugfs_phy, sc,
1750                             &fops_spectral_short_repeat);
1751         debugfs_create_file("spectral_count", S_IRUSR | S_IWUSR,
1752                             sc->debug.debugfs_phy, sc, &fops_spectral_count);
1753         debugfs_create_file("spectral_period", S_IRUSR | S_IWUSR,
1754                             sc->debug.debugfs_phy, sc, &fops_spectral_period);
1755         debugfs_create_file("spectral_fft_period", S_IRUSR | S_IWUSR,
1756                             sc->debug.debugfs_phy, sc,
1757                             &fops_spectral_fft_period);
1758         debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
1759                            sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
1760         debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
1761                            sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
1762         debugfs_create_file("diversity", S_IRUSR | S_IWUSR,
1763                             sc->debug.debugfs_phy, sc, &fops_ant_diversity);
1764 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
1765         debugfs_create_file("btcoex", S_IRUSR, sc->debug.debugfs_phy, sc,
1766                             &fops_btcoex);
1767 #endif
1768         return 0;
1769 }