cw1200: Fix an assorted pile of checkpatch warnings.
[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_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         struct ath_hw *ah = sc->sc_ah;
182         unsigned int len = 0, size = 1024;
183         ssize_t retval = 0;
184         char *buf;
185
186         buf = kzalloc(size, GFP_KERNEL);
187         if (buf == NULL)
188                 return -ENOMEM;
189
190         if (common->disable_ani) {
191                 len += snprintf(buf + len, size - len, "%s: %s\n",
192                                 "ANI", "DISABLED");
193                 goto exit;
194         }
195
196         len += snprintf(buf + len, size - len, "%15s: %s\n",
197                         "ANI", "ENABLED");
198         len += snprintf(buf + len, size - len, "%15s: %u\n",
199                         "ANI RESET", ah->stats.ast_ani_reset);
200         len += snprintf(buf + len, size - len, "%15s: %u\n",
201                         "SPUR UP", ah->stats.ast_ani_spurup);
202         len += snprintf(buf + len, size - len, "%15s: %u\n",
203                         "SPUR DOWN", ah->stats.ast_ani_spurup);
204         len += snprintf(buf + len, size - len, "%15s: %u\n",
205                         "OFDM WS-DET ON", ah->stats.ast_ani_ofdmon);
206         len += snprintf(buf + len, size - len, "%15s: %u\n",
207                         "OFDM WS-DET OFF", ah->stats.ast_ani_ofdmoff);
208         len += snprintf(buf + len, size - len, "%15s: %u\n",
209                         "MRC-CCK ON", ah->stats.ast_ani_ccklow);
210         len += snprintf(buf + len, size - len, "%15s: %u\n",
211                         "MRC-CCK OFF", ah->stats.ast_ani_cckhigh);
212         len += snprintf(buf + len, size - len, "%15s: %u\n",
213                         "FIR-STEP UP", ah->stats.ast_ani_stepup);
214         len += snprintf(buf + len, size - len, "%15s: %u\n",
215                         "FIR-STEP DOWN", ah->stats.ast_ani_stepdown);
216         len += snprintf(buf + len, size - len, "%15s: %u\n",
217                         "INV LISTENTIME", ah->stats.ast_ani_lneg_or_lzero);
218         len += snprintf(buf + len, size - len, "%15s: %u\n",
219                         "OFDM ERRORS", ah->stats.ast_ani_ofdmerrs);
220         len += snprintf(buf + len, size - len, "%15s: %u\n",
221                         "CCK ERRORS", ah->stats.ast_ani_cckerrs);
222 exit:
223         if (len > size)
224                 len = size;
225
226         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
227         kfree(buf);
228
229         return retval;
230 }
231
232 static ssize_t write_file_ani(struct file *file,
233                               const char __user *user_buf,
234                               size_t count, loff_t *ppos)
235 {
236         struct ath_softc *sc = file->private_data;
237         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
238         unsigned long ani;
239         char buf[32];
240         ssize_t len;
241
242         len = min(count, sizeof(buf) - 1);
243         if (copy_from_user(buf, user_buf, len))
244                 return -EFAULT;
245
246         buf[len] = '\0';
247         if (strict_strtoul(buf, 0, &ani))
248                 return -EINVAL;
249
250         if (ani < 0 || ani > 1)
251                 return -EINVAL;
252
253         common->disable_ani = !ani;
254
255         if (common->disable_ani) {
256                 clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
257                 ath_stop_ani(sc);
258         } else {
259                 ath_check_ani(sc);
260         }
261
262         return count;
263 }
264
265 static const struct file_operations fops_ani = {
266         .read = read_file_ani,
267         .write = write_file_ani,
268         .open = simple_open,
269         .owner = THIS_MODULE,
270         .llseek = default_llseek,
271 };
272
273 static ssize_t read_file_ant_diversity(struct file *file, char __user *user_buf,
274                                        size_t count, loff_t *ppos)
275 {
276         struct ath_softc *sc = file->private_data;
277         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
278         char buf[32];
279         unsigned int len;
280
281         len = sprintf(buf, "%d\n", common->antenna_diversity);
282         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
283 }
284
285 static ssize_t write_file_ant_diversity(struct file *file,
286                                         const char __user *user_buf,
287                                         size_t count, loff_t *ppos)
288 {
289         struct ath_softc *sc = file->private_data;
290         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
291         unsigned long antenna_diversity;
292         char buf[32];
293         ssize_t len;
294
295         len = min(count, sizeof(buf) - 1);
296         if (copy_from_user(buf, user_buf, len))
297                 return -EFAULT;
298
299         if (!AR_SREV_9565(sc->sc_ah))
300                 goto exit;
301
302         buf[len] = '\0';
303         if (strict_strtoul(buf, 0, &antenna_diversity))
304                 return -EINVAL;
305
306         common->antenna_diversity = !!antenna_diversity;
307         ath9k_ps_wakeup(sc);
308         ath_ant_comb_update(sc);
309         ath_dbg(common, CONFIG, "Antenna diversity: %d\n",
310                 common->antenna_diversity);
311         ath9k_ps_restore(sc);
312 exit:
313         return count;
314 }
315
316 static const struct file_operations fops_ant_diversity = {
317         .read = read_file_ant_diversity,
318         .write = write_file_ant_diversity,
319         .open = simple_open,
320         .owner = THIS_MODULE,
321         .llseek = default_llseek,
322 };
323
324 static ssize_t read_file_dma(struct file *file, char __user *user_buf,
325                              size_t count, loff_t *ppos)
326 {
327         struct ath_softc *sc = file->private_data;
328         struct ath_hw *ah = sc->sc_ah;
329         char *buf;
330         int retval;
331         unsigned int len = 0;
332         u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
333         int i, qcuOffset = 0, dcuOffset = 0;
334         u32 *qcuBase = &val[0], *dcuBase = &val[4];
335
336         buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
337         if (!buf)
338                 return -ENOMEM;
339
340         ath9k_ps_wakeup(sc);
341
342         REG_WRITE_D(ah, AR_MACMISC,
343                   ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
344                    (AR_MACMISC_MISC_OBS_BUS_1 <<
345                     AR_MACMISC_MISC_OBS_BUS_MSB_S)));
346
347         len += snprintf(buf + len, DMA_BUF_LEN - len,
348                         "Raw DMA Debug values:\n");
349
350         for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
351                 if (i % 4 == 0)
352                         len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
353
354                 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
355                 len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
356                                 i, val[i]);
357         }
358
359         len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
360         len += snprintf(buf + len, DMA_BUF_LEN - len,
361                         "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
362
363         for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
364                 if (i == 8) {
365                         qcuOffset = 0;
366                         qcuBase++;
367                 }
368
369                 if (i == 6) {
370                         dcuOffset = 0;
371                         dcuBase++;
372                 }
373
374                 len += snprintf(buf + len, DMA_BUF_LEN - len,
375                         "%2d          %2x      %1x     %2x           %2x\n",
376                         i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
377                         (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
378                         val[2] & (0x7 << (i * 3)) >> (i * 3),
379                         (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
380         }
381
382         len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
383
384         len += snprintf(buf + len, DMA_BUF_LEN - len,
385                 "qcu_stitch state:   %2x    qcu_fetch state:        %2x\n",
386                 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
387         len += snprintf(buf + len, DMA_BUF_LEN - len,
388                 "qcu_complete state: %2x    dcu_complete state:     %2x\n",
389                 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
390         len += snprintf(buf + len, DMA_BUF_LEN - len,
391                 "dcu_arb state:      %2x    dcu_fp state:           %2x\n",
392                 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
393         len += snprintf(buf + len, DMA_BUF_LEN - len,
394                 "chan_idle_dur:     %3d    chan_idle_dur_valid:     %1d\n",
395                 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
396         len += snprintf(buf + len, DMA_BUF_LEN - len,
397                 "txfifo_valid_0:      %1d    txfifo_valid_1:          %1d\n",
398                 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
399         len += snprintf(buf + len, DMA_BUF_LEN - len,
400                 "txfifo_dcu_num_0:   %2d    txfifo_dcu_num_1:       %2d\n",
401                 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
402
403         len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
404                         REG_READ_D(ah, AR_OBS_BUS_1));
405         len += snprintf(buf + len, DMA_BUF_LEN - len,
406                         "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
407
408         ath9k_ps_restore(sc);
409
410         if (len > DMA_BUF_LEN)
411                 len = DMA_BUF_LEN;
412
413         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
414         kfree(buf);
415         return retval;
416 }
417
418 static const struct file_operations fops_dma = {
419         .read = read_file_dma,
420         .open = simple_open,
421         .owner = THIS_MODULE,
422         .llseek = default_llseek,
423 };
424
425
426 void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
427 {
428         if (status)
429                 sc->debug.stats.istats.total++;
430         if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
431                 if (status & ATH9K_INT_RXLP)
432                         sc->debug.stats.istats.rxlp++;
433                 if (status & ATH9K_INT_RXHP)
434                         sc->debug.stats.istats.rxhp++;
435                 if (status & ATH9K_INT_BB_WATCHDOG)
436                         sc->debug.stats.istats.bb_watchdog++;
437         } else {
438                 if (status & ATH9K_INT_RX)
439                         sc->debug.stats.istats.rxok++;
440         }
441         if (status & ATH9K_INT_RXEOL)
442                 sc->debug.stats.istats.rxeol++;
443         if (status & ATH9K_INT_RXORN)
444                 sc->debug.stats.istats.rxorn++;
445         if (status & ATH9K_INT_TX)
446                 sc->debug.stats.istats.txok++;
447         if (status & ATH9K_INT_TXURN)
448                 sc->debug.stats.istats.txurn++;
449         if (status & ATH9K_INT_RXPHY)
450                 sc->debug.stats.istats.rxphyerr++;
451         if (status & ATH9K_INT_RXKCM)
452                 sc->debug.stats.istats.rx_keycache_miss++;
453         if (status & ATH9K_INT_SWBA)
454                 sc->debug.stats.istats.swba++;
455         if (status & ATH9K_INT_BMISS)
456                 sc->debug.stats.istats.bmiss++;
457         if (status & ATH9K_INT_BNR)
458                 sc->debug.stats.istats.bnr++;
459         if (status & ATH9K_INT_CST)
460                 sc->debug.stats.istats.cst++;
461         if (status & ATH9K_INT_GTT)
462                 sc->debug.stats.istats.gtt++;
463         if (status & ATH9K_INT_TIM)
464                 sc->debug.stats.istats.tim++;
465         if (status & ATH9K_INT_CABEND)
466                 sc->debug.stats.istats.cabend++;
467         if (status & ATH9K_INT_DTIMSYNC)
468                 sc->debug.stats.istats.dtimsync++;
469         if (status & ATH9K_INT_DTIM)
470                 sc->debug.stats.istats.dtim++;
471         if (status & ATH9K_INT_TSFOOR)
472                 sc->debug.stats.istats.tsfoor++;
473         if (status & ATH9K_INT_MCI)
474                 sc->debug.stats.istats.mci++;
475         if (status & ATH9K_INT_GENTIMER)
476                 sc->debug.stats.istats.gen_timer++;
477 }
478
479 static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
480                                    size_t count, loff_t *ppos)
481 {
482         struct ath_softc *sc = file->private_data;
483         unsigned int len = 0;
484         int rv;
485         int mxlen = 4000;
486         char *buf = kmalloc(mxlen, GFP_KERNEL);
487         if (!buf)
488                 return -ENOMEM;
489
490 #define PR_IS(a, s)                                             \
491         do {                                                    \
492                 len += snprintf(buf + len, mxlen - len,         \
493                                 "%21s: %10u\n", a,              \
494                                 sc->debug.stats.istats.s);      \
495         } while (0)
496
497         if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
498                 PR_IS("RXLP", rxlp);
499                 PR_IS("RXHP", rxhp);
500                 PR_IS("WATHDOG", bb_watchdog);
501         } else {
502                 PR_IS("RX", rxok);
503         }
504         PR_IS("RXEOL", rxeol);
505         PR_IS("RXORN", rxorn);
506         PR_IS("TX", txok);
507         PR_IS("TXURN", txurn);
508         PR_IS("MIB", mib);
509         PR_IS("RXPHY", rxphyerr);
510         PR_IS("RXKCM", rx_keycache_miss);
511         PR_IS("SWBA", swba);
512         PR_IS("BMISS", bmiss);
513         PR_IS("BNR", bnr);
514         PR_IS("CST", cst);
515         PR_IS("GTT", gtt);
516         PR_IS("TIM", tim);
517         PR_IS("CABEND", cabend);
518         PR_IS("DTIMSYNC", dtimsync);
519         PR_IS("DTIM", dtim);
520         PR_IS("TSFOOR", tsfoor);
521         PR_IS("MCI", mci);
522         PR_IS("GENTIMER", gen_timer);
523         PR_IS("TOTAL", total);
524
525         len += snprintf(buf + len, mxlen - len,
526                         "SYNC_CAUSE stats:\n");
527
528         PR_IS("Sync-All", sync_cause_all);
529         PR_IS("RTC-IRQ", sync_rtc_irq);
530         PR_IS("MAC-IRQ", sync_mac_irq);
531         PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
532         PR_IS("APB-Timeout", apb_timeout);
533         PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
534         PR_IS("HOST1-Fatal", host1_fatal);
535         PR_IS("HOST1-Perr", host1_perr);
536         PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
537         PR_IS("RADM-CPL-EP", radm_cpl_ep);
538         PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
539         PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
540         PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
541         PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
542         PR_IS("Local-Bus-Timeout", local_timeout);
543         PR_IS("PM-Access", pm_access);
544         PR_IS("MAC-Awake", mac_awake);
545         PR_IS("MAC-Asleep", mac_asleep);
546         PR_IS("MAC-Sleep-Access", mac_sleep_access);
547
548         if (len > mxlen)
549                 len = mxlen;
550
551         rv = simple_read_from_buffer(user_buf, count, ppos, buf, len);
552         kfree(buf);
553         return rv;
554 }
555
556 static const struct file_operations fops_interrupt = {
557         .read = read_file_interrupt,
558         .open = simple_open,
559         .owner = THIS_MODULE,
560         .llseek = default_llseek,
561 };
562
563 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
564                               size_t count, loff_t *ppos)
565 {
566         struct ath_softc *sc = file->private_data;
567         char *buf;
568         unsigned int len = 0, size = 2048;
569         ssize_t retval = 0;
570
571         buf = kzalloc(size, GFP_KERNEL);
572         if (buf == NULL)
573                 return -ENOMEM;
574
575         len += sprintf(buf, "%30s %10s%10s%10s\n\n",
576                        "BE", "BK", "VI", "VO");
577
578         PR("MPDUs Queued:    ", queued);
579         PR("MPDUs Completed: ", completed);
580         PR("MPDUs XRetried:  ", xretries);
581         PR("Aggregates:      ", a_aggr);
582         PR("AMPDUs Queued HW:", a_queued_hw);
583         PR("AMPDUs Queued SW:", a_queued_sw);
584         PR("AMPDUs Completed:", a_completed);
585         PR("AMPDUs Retried:  ", a_retries);
586         PR("AMPDUs XRetried: ", a_xretries);
587         PR("TXERR Filtered:  ", txerr_filtered);
588         PR("FIFO Underrun:   ", fifo_underrun);
589         PR("TXOP Exceeded:   ", xtxop);
590         PR("TXTIMER Expiry:  ", timer_exp);
591         PR("DESC CFG Error:  ", desc_cfg_err);
592         PR("DATA Underrun:   ", data_underrun);
593         PR("DELIM Underrun:  ", delim_underrun);
594         PR("TX-Pkts-All:     ", tx_pkts_all);
595         PR("TX-Bytes-All:    ", tx_bytes_all);
596         PR("HW-put-tx-buf:   ", puttxbuf);
597         PR("HW-tx-start:     ", txstart);
598         PR("HW-tx-proc-desc: ", txprocdesc);
599         PR("TX-Failed:       ", txfailed);
600
601         if (len > size)
602                 len = size;
603
604         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
605         kfree(buf);
606
607         return retval;
608 }
609
610 static ssize_t read_file_queues(struct file *file, char __user *user_buf,
611                                 size_t count, loff_t *ppos)
612 {
613         struct ath_softc *sc = file->private_data;
614         struct ath_txq *txq;
615         char *buf;
616         unsigned int len = 0, size = 1024;
617         ssize_t retval = 0;
618         int i;
619         char *qname[4] = {"VO", "VI", "BE", "BK"};
620
621         buf = kzalloc(size, GFP_KERNEL);
622         if (buf == NULL)
623                 return -ENOMEM;
624
625         for (i = 0; i < IEEE80211_NUM_ACS; i++) {
626                 txq = sc->tx.txq_map[i];
627                 len += snprintf(buf + len, size - len, "(%s): ", qname[i]);
628
629                 ath_txq_lock(sc, txq);
630
631                 len += snprintf(buf + len, size - len, "%s: %d ",
632                                 "qnum", txq->axq_qnum);
633                 len += snprintf(buf + len, size - len, "%s: %2d ",
634                                 "qdepth", txq->axq_depth);
635                 len += snprintf(buf + len, size - len, "%s: %2d ",
636                                 "ampdu-depth", txq->axq_ampdu_depth);
637                 len += snprintf(buf + len, size - len, "%s: %3d ",
638                                 "pending", txq->pending_frames);
639                 len += snprintf(buf + len, size - len, "%s: %d\n",
640                                 "stopped", txq->stopped);
641
642                 ath_txq_unlock(sc, txq);
643         }
644
645         if (len > size)
646                 len = size;
647
648         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
649         kfree(buf);
650
651         return retval;
652 }
653
654 static ssize_t read_file_misc(struct file *file, char __user *user_buf,
655                               size_t count, loff_t *ppos)
656 {
657         struct ath_softc *sc = file->private_data;
658         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
659         struct ieee80211_hw *hw = sc->hw;
660         struct ath9k_vif_iter_data iter_data;
661         char buf[512];
662         unsigned int len = 0;
663         ssize_t retval = 0;
664         unsigned int reg;
665         u32 rxfilter;
666
667         len += snprintf(buf + len, sizeof(buf) - len,
668                         "BSSID: %pM\n", common->curbssid);
669         len += snprintf(buf + len, sizeof(buf) - len,
670                         "BSSID-MASK: %pM\n", common->bssidmask);
671         len += snprintf(buf + len, sizeof(buf) - len,
672                         "OPMODE: %s\n", ath_opmode_to_string(sc->sc_ah->opmode));
673
674         ath9k_ps_wakeup(sc);
675         rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
676         ath9k_ps_restore(sc);
677
678         len += snprintf(buf + len, sizeof(buf) - len,
679                         "RXFILTER: 0x%x", rxfilter);
680
681         if (rxfilter & ATH9K_RX_FILTER_UCAST)
682                 len += snprintf(buf + len, sizeof(buf) - len, " UCAST");
683         if (rxfilter & ATH9K_RX_FILTER_MCAST)
684                 len += snprintf(buf + len, sizeof(buf) - len, " MCAST");
685         if (rxfilter & ATH9K_RX_FILTER_BCAST)
686                 len += snprintf(buf + len, sizeof(buf) - len, " BCAST");
687         if (rxfilter & ATH9K_RX_FILTER_CONTROL)
688                 len += snprintf(buf + len, sizeof(buf) - len, " CONTROL");
689         if (rxfilter & ATH9K_RX_FILTER_BEACON)
690                 len += snprintf(buf + len, sizeof(buf) - len, " BEACON");
691         if (rxfilter & ATH9K_RX_FILTER_PROM)
692                 len += snprintf(buf + len, sizeof(buf) - len, " PROM");
693         if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
694                 len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
695         if (rxfilter & ATH9K_RX_FILTER_PHYERR)
696                 len += snprintf(buf + len, sizeof(buf) - len, " PHYERR");
697         if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
698                 len += snprintf(buf + len, sizeof(buf) - len, " MYBEACON");
699         if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
700                 len += snprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
701         if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
702                 len += snprintf(buf + len, sizeof(buf) - len, " PSPOLL");
703         if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
704                 len += snprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
705         if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
706                 len += snprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL");
707         if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
708                 len += snprintf(buf + len, sizeof(buf) - len, " CONTROL_WRAPPER");
709
710         len += snprintf(buf + len, sizeof(buf) - len, "\n");
711
712         reg = sc->sc_ah->imask;
713
714         len += snprintf(buf + len, sizeof(buf) - len, "INTERRUPT-MASK: 0x%x", reg);
715
716         if (reg & ATH9K_INT_SWBA)
717                 len += snprintf(buf + len, sizeof(buf) - len, " SWBA");
718         if (reg & ATH9K_INT_BMISS)
719                 len += snprintf(buf + len, sizeof(buf) - len, " BMISS");
720         if (reg & ATH9K_INT_CST)
721                 len += snprintf(buf + len, sizeof(buf) - len, " CST");
722         if (reg & ATH9K_INT_RX)
723                 len += snprintf(buf + len, sizeof(buf) - len, " RX");
724         if (reg & ATH9K_INT_RXHP)
725                 len += snprintf(buf + len, sizeof(buf) - len, " RXHP");
726         if (reg & ATH9K_INT_RXLP)
727                 len += snprintf(buf + len, sizeof(buf) - len, " RXLP");
728         if (reg & ATH9K_INT_BB_WATCHDOG)
729                 len += snprintf(buf + len, sizeof(buf) - len, " BB_WATCHDOG");
730
731         len += snprintf(buf + len, sizeof(buf) - len, "\n");
732
733         ath9k_calculate_iter_data(hw, NULL, &iter_data);
734
735         len += snprintf(buf + len, sizeof(buf) - len,
736                         "VIF-COUNTS: AP: %i STA: %i MESH: %i WDS: %i"
737                         " ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n",
738                         iter_data.naps, iter_data.nstations, iter_data.nmeshes,
739                         iter_data.nwds, iter_data.nadhocs,
740                         sc->nvifs, sc->nbcnvifs);
741
742         if (len > sizeof(buf))
743                 len = sizeof(buf);
744
745         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
746         return retval;
747 }
748
749 static ssize_t read_file_reset(struct file *file, char __user *user_buf,
750                                size_t count, loff_t *ppos)
751 {
752         struct ath_softc *sc = file->private_data;
753         char buf[512];
754         unsigned int len = 0;
755
756         len += snprintf(buf + len, sizeof(buf) - len,
757                         "%17s: %2d\n", "Baseband Hang",
758                         sc->debug.stats.reset[RESET_TYPE_BB_HANG]);
759         len += snprintf(buf + len, sizeof(buf) - len,
760                         "%17s: %2d\n", "Baseband Watchdog",
761                         sc->debug.stats.reset[RESET_TYPE_BB_WATCHDOG]);
762         len += snprintf(buf + len, sizeof(buf) - len,
763                         "%17s: %2d\n", "Fatal HW Error",
764                         sc->debug.stats.reset[RESET_TYPE_FATAL_INT]);
765         len += snprintf(buf + len, sizeof(buf) - len,
766                         "%17s: %2d\n", "TX HW error",
767                         sc->debug.stats.reset[RESET_TYPE_TX_ERROR]);
768         len += snprintf(buf + len, sizeof(buf) - len,
769                         "%17s: %2d\n", "TX Path Hang",
770                         sc->debug.stats.reset[RESET_TYPE_TX_HANG]);
771         len += snprintf(buf + len, sizeof(buf) - len,
772                         "%17s: %2d\n", "PLL RX Hang",
773                         sc->debug.stats.reset[RESET_TYPE_PLL_HANG]);
774         len += snprintf(buf + len, sizeof(buf) - len,
775                         "%17s: %2d\n", "MCI Reset",
776                         sc->debug.stats.reset[RESET_TYPE_MCI]);
777
778         if (len > sizeof(buf))
779                 len = sizeof(buf);
780
781         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
782 }
783
784 void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
785                        struct ath_tx_status *ts, struct ath_txq *txq,
786                        unsigned int flags)
787 {
788         int qnum = txq->axq_qnum;
789
790         TX_STAT_INC(qnum, tx_pkts_all);
791         sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
792
793         if (bf_isampdu(bf)) {
794                 if (flags & ATH_TX_ERROR)
795                         TX_STAT_INC(qnum, a_xretries);
796                 else
797                         TX_STAT_INC(qnum, a_completed);
798         } else {
799                 if (ts->ts_status & ATH9K_TXERR_XRETRY)
800                         TX_STAT_INC(qnum, xretries);
801                 else
802                         TX_STAT_INC(qnum, completed);
803         }
804
805         if (ts->ts_status & ATH9K_TXERR_FILT)
806                 TX_STAT_INC(qnum, txerr_filtered);
807         if (ts->ts_status & ATH9K_TXERR_FIFO)
808                 TX_STAT_INC(qnum, fifo_underrun);
809         if (ts->ts_status & ATH9K_TXERR_XTXOP)
810                 TX_STAT_INC(qnum, xtxop);
811         if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
812                 TX_STAT_INC(qnum, timer_exp);
813         if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
814                 TX_STAT_INC(qnum, desc_cfg_err);
815         if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
816                 TX_STAT_INC(qnum, data_underrun);
817         if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
818                 TX_STAT_INC(qnum, delim_underrun);
819 }
820
821 static const struct file_operations fops_xmit = {
822         .read = read_file_xmit,
823         .open = simple_open,
824         .owner = THIS_MODULE,
825         .llseek = default_llseek,
826 };
827
828 static const struct file_operations fops_queues = {
829         .read = read_file_queues,
830         .open = simple_open,
831         .owner = THIS_MODULE,
832         .llseek = default_llseek,
833 };
834
835 static const struct file_operations fops_misc = {
836         .read = read_file_misc,
837         .open = simple_open,
838         .owner = THIS_MODULE,
839         .llseek = default_llseek,
840 };
841
842 static const struct file_operations fops_reset = {
843         .read = read_file_reset,
844         .open = simple_open,
845         .owner = THIS_MODULE,
846         .llseek = default_llseek,
847 };
848
849 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
850                               size_t count, loff_t *ppos)
851 {
852 #define PHY_ERR(s, p) \
853         len += snprintf(buf + len, size - len, "%22s : %10u\n", s, \
854                         sc->debug.stats.rxstats.phy_err_stats[p]);
855
856 #define RXS_ERR(s, e)                                       \
857         do {                                                \
858                 len += snprintf(buf + len, size - len,      \
859                                 "%22s : %10u\n", s,         \
860                                 sc->debug.stats.rxstats.e); \
861         } while (0)
862
863         struct ath_softc *sc = file->private_data;
864         char *buf;
865         unsigned int len = 0, size = 1600;
866         ssize_t retval = 0;
867
868         buf = kzalloc(size, GFP_KERNEL);
869         if (buf == NULL)
870                 return -ENOMEM;
871
872         RXS_ERR("CRC ERR", crc_err);
873         RXS_ERR("DECRYPT CRC ERR", decrypt_crc_err);
874         RXS_ERR("PHY ERR", phy_err);
875         RXS_ERR("MIC ERR", mic_err);
876         RXS_ERR("PRE-DELIM CRC ERR", pre_delim_crc_err);
877         RXS_ERR("POST-DELIM CRC ERR", post_delim_crc_err);
878         RXS_ERR("DECRYPT BUSY ERR", decrypt_busy_err);
879         RXS_ERR("RX-LENGTH-ERR", rx_len_err);
880         RXS_ERR("RX-OOM-ERR", rx_oom_err);
881         RXS_ERR("RX-RATE-ERR", rx_rate_err);
882         RXS_ERR("RX-TOO-MANY-FRAGS", rx_too_many_frags_err);
883
884         PHY_ERR("UNDERRUN ERR", ATH9K_PHYERR_UNDERRUN);
885         PHY_ERR("TIMING ERR", ATH9K_PHYERR_TIMING);
886         PHY_ERR("PARITY ERR", ATH9K_PHYERR_PARITY);
887         PHY_ERR("RATE ERR", ATH9K_PHYERR_RATE);
888         PHY_ERR("LENGTH ERR", ATH9K_PHYERR_LENGTH);
889         PHY_ERR("RADAR ERR", ATH9K_PHYERR_RADAR);
890         PHY_ERR("SERVICE ERR", ATH9K_PHYERR_SERVICE);
891         PHY_ERR("TOR ERR", ATH9K_PHYERR_TOR);
892         PHY_ERR("OFDM-TIMING ERR", ATH9K_PHYERR_OFDM_TIMING);
893         PHY_ERR("OFDM-SIGNAL-PARITY ERR", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
894         PHY_ERR("OFDM-RATE ERR", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
895         PHY_ERR("OFDM-LENGTH ERR", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
896         PHY_ERR("OFDM-POWER-DROP ERR", ATH9K_PHYERR_OFDM_POWER_DROP);
897         PHY_ERR("OFDM-SERVICE ERR", ATH9K_PHYERR_OFDM_SERVICE);
898         PHY_ERR("OFDM-RESTART ERR", ATH9K_PHYERR_OFDM_RESTART);
899         PHY_ERR("FALSE-RADAR-EXT ERR", ATH9K_PHYERR_FALSE_RADAR_EXT);
900         PHY_ERR("CCK-TIMING ERR", ATH9K_PHYERR_CCK_TIMING);
901         PHY_ERR("CCK-HEADER-CRC ERR", ATH9K_PHYERR_CCK_HEADER_CRC);
902         PHY_ERR("CCK-RATE ERR", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
903         PHY_ERR("CCK-SERVICE ERR", ATH9K_PHYERR_CCK_SERVICE);
904         PHY_ERR("CCK-RESTART ERR", ATH9K_PHYERR_CCK_RESTART);
905         PHY_ERR("CCK-LENGTH ERR", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
906         PHY_ERR("CCK-POWER-DROP ERR", ATH9K_PHYERR_CCK_POWER_DROP);
907         PHY_ERR("HT-CRC ERR", ATH9K_PHYERR_HT_CRC_ERROR);
908         PHY_ERR("HT-LENGTH ERR", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
909         PHY_ERR("HT-RATE ERR", ATH9K_PHYERR_HT_RATE_ILLEGAL);
910
911         RXS_ERR("RX-Pkts-All", rx_pkts_all);
912         RXS_ERR("RX-Bytes-All", rx_bytes_all);
913         RXS_ERR("RX-Beacons", rx_beacons);
914         RXS_ERR("RX-Frags", rx_frags);
915         RXS_ERR("RX-Spectral", rx_spectral);
916
917         if (len > size)
918                 len = size;
919
920         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
921         kfree(buf);
922
923         return retval;
924
925 #undef RXS_ERR
926 #undef PHY_ERR
927 }
928
929 void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
930 {
931 #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
932
933         RX_STAT_INC(rx_pkts_all);
934         sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
935
936         if (rs->rs_status & ATH9K_RXERR_CRC)
937                 RX_STAT_INC(crc_err);
938         if (rs->rs_status & ATH9K_RXERR_DECRYPT)
939                 RX_STAT_INC(decrypt_crc_err);
940         if (rs->rs_status & ATH9K_RXERR_MIC)
941                 RX_STAT_INC(mic_err);
942         if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
943                 RX_STAT_INC(pre_delim_crc_err);
944         if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
945                 RX_STAT_INC(post_delim_crc_err);
946         if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
947                 RX_STAT_INC(decrypt_busy_err);
948
949         if (rs->rs_status & ATH9K_RXERR_PHY) {
950                 RX_STAT_INC(phy_err);
951                 if (rs->rs_phyerr < ATH9K_PHYERR_MAX)
952                         RX_PHY_ERR_INC(rs->rs_phyerr);
953         }
954
955 #undef RX_PHY_ERR_INC
956 }
957
958 static const struct file_operations fops_recv = {
959         .read = read_file_recv,
960         .open = simple_open,
961         .owner = THIS_MODULE,
962         .llseek = default_llseek,
963 };
964
965 static ssize_t read_file_spec_scan_ctl(struct file *file, char __user *user_buf,
966                                        size_t count, loff_t *ppos)
967 {
968         struct ath_softc *sc = file->private_data;
969         char *mode = "";
970         unsigned int len;
971
972         switch (sc->spectral_mode) {
973         case SPECTRAL_DISABLED:
974                 mode = "disable";
975                 break;
976         case SPECTRAL_BACKGROUND:
977                 mode = "background";
978                 break;
979         case SPECTRAL_CHANSCAN:
980                 mode = "chanscan";
981                 break;
982         case SPECTRAL_MANUAL:
983                 mode = "manual";
984                 break;
985         }
986         len = strlen(mode);
987         return simple_read_from_buffer(user_buf, count, ppos, mode, len);
988 }
989
990 static ssize_t write_file_spec_scan_ctl(struct file *file,
991                                         const char __user *user_buf,
992                                         size_t count, loff_t *ppos)
993 {
994         struct ath_softc *sc = file->private_data;
995         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
996         char buf[32];
997         ssize_t len;
998
999         len = min(count, sizeof(buf) - 1);
1000         if (copy_from_user(buf, user_buf, len))
1001                 return -EFAULT;
1002
1003         buf[len] = '\0';
1004
1005         if (strncmp("trigger", buf, 7) == 0) {
1006                 ath9k_spectral_scan_trigger(sc->hw);
1007         } else if (strncmp("background", buf, 9) == 0) {
1008                 ath9k_spectral_scan_config(sc->hw, SPECTRAL_BACKGROUND);
1009                 ath_dbg(common, CONFIG, "spectral scan: background mode enabled\n");
1010         } else if (strncmp("chanscan", buf, 8) == 0) {
1011                 ath9k_spectral_scan_config(sc->hw, SPECTRAL_CHANSCAN);
1012                 ath_dbg(common, CONFIG, "spectral scan: channel scan mode enabled\n");
1013         } else if (strncmp("manual", buf, 6) == 0) {
1014                 ath9k_spectral_scan_config(sc->hw, SPECTRAL_MANUAL);
1015                 ath_dbg(common, CONFIG, "spectral scan: manual mode enabled\n");
1016         } else if (strncmp("disable", buf, 7) == 0) {
1017                 ath9k_spectral_scan_config(sc->hw, SPECTRAL_DISABLED);
1018                 ath_dbg(common, CONFIG, "spectral scan: disabled\n");
1019         } else {
1020                 return -EINVAL;
1021         }
1022
1023         return count;
1024 }
1025
1026 static const struct file_operations fops_spec_scan_ctl = {
1027         .read = read_file_spec_scan_ctl,
1028         .write = write_file_spec_scan_ctl,
1029         .open = simple_open,
1030         .owner = THIS_MODULE,
1031         .llseek = default_llseek,
1032 };
1033
1034 static ssize_t read_file_spectral_short_repeat(struct file *file,
1035                                                char __user *user_buf,
1036                                                size_t count, loff_t *ppos)
1037 {
1038         struct ath_softc *sc = file->private_data;
1039         char buf[32];
1040         unsigned int len;
1041
1042         len = sprintf(buf, "%d\n", sc->spec_config.short_repeat);
1043         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1044 }
1045
1046 static ssize_t write_file_spectral_short_repeat(struct file *file,
1047                                                 const char __user *user_buf,
1048                                                 size_t count, loff_t *ppos)
1049 {
1050         struct ath_softc *sc = file->private_data;
1051         unsigned long val;
1052         char buf[32];
1053         ssize_t len;
1054
1055         len = min(count, sizeof(buf) - 1);
1056         if (copy_from_user(buf, user_buf, len))
1057                 return -EFAULT;
1058
1059         buf[len] = '\0';
1060         if (kstrtoul(buf, 0, &val))
1061                 return -EINVAL;
1062
1063         if (val < 0 || val > 1)
1064                 return -EINVAL;
1065
1066         sc->spec_config.short_repeat = val;
1067         return count;
1068 }
1069
1070 static const struct file_operations fops_spectral_short_repeat = {
1071         .read = read_file_spectral_short_repeat,
1072         .write = write_file_spectral_short_repeat,
1073         .open = simple_open,
1074         .owner = THIS_MODULE,
1075         .llseek = default_llseek,
1076 };
1077
1078 static ssize_t read_file_spectral_count(struct file *file,
1079                                         char __user *user_buf,
1080                                         size_t count, loff_t *ppos)
1081 {
1082         struct ath_softc *sc = file->private_data;
1083         char buf[32];
1084         unsigned int len;
1085
1086         len = sprintf(buf, "%d\n", sc->spec_config.count);
1087         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1088 }
1089
1090 static ssize_t write_file_spectral_count(struct file *file,
1091                                          const char __user *user_buf,
1092                                          size_t count, loff_t *ppos)
1093 {
1094         struct ath_softc *sc = file->private_data;
1095         unsigned long val;
1096         char buf[32];
1097         ssize_t len;
1098
1099         len = min(count, sizeof(buf) - 1);
1100         if (copy_from_user(buf, user_buf, len))
1101                 return -EFAULT;
1102
1103         buf[len] = '\0';
1104         if (kstrtoul(buf, 0, &val))
1105                 return -EINVAL;
1106
1107         if (val < 0 || val > 255)
1108                 return -EINVAL;
1109
1110         sc->spec_config.count = val;
1111         return count;
1112 }
1113
1114 static const struct file_operations fops_spectral_count = {
1115         .read = read_file_spectral_count,
1116         .write = write_file_spectral_count,
1117         .open = simple_open,
1118         .owner = THIS_MODULE,
1119         .llseek = default_llseek,
1120 };
1121
1122 static ssize_t read_file_spectral_period(struct file *file,
1123                                          char __user *user_buf,
1124                                          size_t count, loff_t *ppos)
1125 {
1126         struct ath_softc *sc = file->private_data;
1127         char buf[32];
1128         unsigned int len;
1129
1130         len = sprintf(buf, "%d\n", sc->spec_config.period);
1131         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1132 }
1133
1134 static ssize_t write_file_spectral_period(struct file *file,
1135                                           const char __user *user_buf,
1136                                           size_t count, loff_t *ppos)
1137 {
1138         struct ath_softc *sc = file->private_data;
1139         unsigned long val;
1140         char buf[32];
1141         ssize_t len;
1142
1143         len = min(count, sizeof(buf) - 1);
1144         if (copy_from_user(buf, user_buf, len))
1145                 return -EFAULT;
1146
1147         buf[len] = '\0';
1148         if (kstrtoul(buf, 0, &val))
1149                 return -EINVAL;
1150
1151         if (val < 0 || val > 255)
1152                 return -EINVAL;
1153
1154         sc->spec_config.period = val;
1155         return count;
1156 }
1157
1158 static const struct file_operations fops_spectral_period = {
1159         .read = read_file_spectral_period,
1160         .write = write_file_spectral_period,
1161         .open = simple_open,
1162         .owner = THIS_MODULE,
1163         .llseek = default_llseek,
1164 };
1165
1166 static ssize_t read_file_spectral_fft_period(struct file *file,
1167                                              char __user *user_buf,
1168                                              size_t count, loff_t *ppos)
1169 {
1170         struct ath_softc *sc = file->private_data;
1171         char buf[32];
1172         unsigned int len;
1173
1174         len = sprintf(buf, "%d\n", sc->spec_config.fft_period);
1175         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1176 }
1177
1178 static ssize_t write_file_spectral_fft_period(struct file *file,
1179                                               const char __user *user_buf,
1180                                               size_t count, loff_t *ppos)
1181 {
1182         struct ath_softc *sc = file->private_data;
1183         unsigned long val;
1184         char buf[32];
1185         ssize_t len;
1186
1187         len = min(count, sizeof(buf) - 1);
1188         if (copy_from_user(buf, user_buf, len))
1189                 return -EFAULT;
1190
1191         buf[len] = '\0';
1192         if (kstrtoul(buf, 0, &val))
1193                 return -EINVAL;
1194
1195         if (val < 0 || val > 15)
1196                 return -EINVAL;
1197
1198         sc->spec_config.fft_period = val;
1199         return count;
1200 }
1201
1202 static const struct file_operations fops_spectral_fft_period = {
1203         .read = read_file_spectral_fft_period,
1204         .write = write_file_spectral_fft_period,
1205         .open = simple_open,
1206         .owner = THIS_MODULE,
1207         .llseek = default_llseek,
1208 };
1209
1210 static struct dentry *create_buf_file_handler(const char *filename,
1211                                               struct dentry *parent,
1212                                               umode_t mode,
1213                                               struct rchan_buf *buf,
1214                                               int *is_global)
1215 {
1216         struct dentry *buf_file;
1217
1218         buf_file = debugfs_create_file(filename, mode, parent, buf,
1219                                        &relay_file_operations);
1220         *is_global = 1;
1221         return buf_file;
1222 }
1223
1224 static int remove_buf_file_handler(struct dentry *dentry)
1225 {
1226         debugfs_remove(dentry);
1227
1228         return 0;
1229 }
1230
1231 void ath_debug_send_fft_sample(struct ath_softc *sc,
1232                                struct fft_sample_tlv *fft_sample_tlv)
1233 {
1234         int length;
1235         if (!sc->rfs_chan_spec_scan)
1236                 return;
1237
1238         length = __be16_to_cpu(fft_sample_tlv->length) +
1239                  sizeof(*fft_sample_tlv);
1240         relay_write(sc->rfs_chan_spec_scan, fft_sample_tlv, length);
1241 }
1242
1243 static struct rchan_callbacks rfs_spec_scan_cb = {
1244         .create_buf_file = create_buf_file_handler,
1245         .remove_buf_file = remove_buf_file_handler,
1246 };
1247
1248
1249 static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
1250                                 size_t count, loff_t *ppos)
1251 {
1252         struct ath_softc *sc = file->private_data;
1253         char buf[32];
1254         unsigned int len;
1255
1256         len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
1257         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1258 }
1259
1260 static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
1261                              size_t count, loff_t *ppos)
1262 {
1263         struct ath_softc *sc = file->private_data;
1264         unsigned long regidx;
1265         char buf[32];
1266         ssize_t len;
1267
1268         len = min(count, sizeof(buf) - 1);
1269         if (copy_from_user(buf, user_buf, len))
1270                 return -EFAULT;
1271
1272         buf[len] = '\0';
1273         if (strict_strtoul(buf, 0, &regidx))
1274                 return -EINVAL;
1275
1276         sc->debug.regidx = regidx;
1277         return count;
1278 }
1279
1280 static const struct file_operations fops_regidx = {
1281         .read = read_file_regidx,
1282         .write = write_file_regidx,
1283         .open = simple_open,
1284         .owner = THIS_MODULE,
1285         .llseek = default_llseek,
1286 };
1287
1288 static ssize_t read_file_regval(struct file *file, char __user *user_buf,
1289                              size_t count, loff_t *ppos)
1290 {
1291         struct ath_softc *sc = file->private_data;
1292         struct ath_hw *ah = sc->sc_ah;
1293         char buf[32];
1294         unsigned int len;
1295         u32 regval;
1296
1297         ath9k_ps_wakeup(sc);
1298         regval = REG_READ_D(ah, sc->debug.regidx);
1299         ath9k_ps_restore(sc);
1300         len = sprintf(buf, "0x%08x\n", regval);
1301         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1302 }
1303
1304 static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
1305                              size_t count, loff_t *ppos)
1306 {
1307         struct ath_softc *sc = file->private_data;
1308         struct ath_hw *ah = sc->sc_ah;
1309         unsigned long regval;
1310         char buf[32];
1311         ssize_t len;
1312
1313         len = min(count, sizeof(buf) - 1);
1314         if (copy_from_user(buf, user_buf, len))
1315                 return -EFAULT;
1316
1317         buf[len] = '\0';
1318         if (strict_strtoul(buf, 0, &regval))
1319                 return -EINVAL;
1320
1321         ath9k_ps_wakeup(sc);
1322         REG_WRITE_D(ah, sc->debug.regidx, regval);
1323         ath9k_ps_restore(sc);
1324         return count;
1325 }
1326
1327 static const struct file_operations fops_regval = {
1328         .read = read_file_regval,
1329         .write = write_file_regval,
1330         .open = simple_open,
1331         .owner = THIS_MODULE,
1332         .llseek = default_llseek,
1333 };
1334
1335 #define REGDUMP_LINE_SIZE       20
1336
1337 static int open_file_regdump(struct inode *inode, struct file *file)
1338 {
1339         struct ath_softc *sc = inode->i_private;
1340         unsigned int len = 0;
1341         u8 *buf;
1342         int i;
1343         unsigned long num_regs, regdump_len, max_reg_offset;
1344
1345         max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
1346         num_regs = max_reg_offset / 4 + 1;
1347         regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
1348         buf = vmalloc(regdump_len);
1349         if (!buf)
1350                 return -ENOMEM;
1351
1352         ath9k_ps_wakeup(sc);
1353         for (i = 0; i < num_regs; i++)
1354                 len += scnprintf(buf + len, regdump_len - len,
1355                         "0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
1356         ath9k_ps_restore(sc);
1357
1358         file->private_data = buf;
1359
1360         return 0;
1361 }
1362
1363 static const struct file_operations fops_regdump = {
1364         .open = open_file_regdump,
1365         .read = ath9k_debugfs_read_buf,
1366         .release = ath9k_debugfs_release_buf,
1367         .owner = THIS_MODULE,
1368         .llseek = default_llseek,/* read accesses f_pos */
1369 };
1370
1371 static ssize_t read_file_dump_nfcal(struct file *file, char __user *user_buf,
1372                                     size_t count, loff_t *ppos)
1373 {
1374         struct ath_softc *sc = file->private_data;
1375         struct ath_hw *ah = sc->sc_ah;
1376         struct ath9k_nfcal_hist *h = sc->caldata.nfCalHist;
1377         struct ath_common *common = ath9k_hw_common(ah);
1378         struct ieee80211_conf *conf = &common->hw->conf;
1379         u32 len = 0, size = 1500;
1380         u32 i, j;
1381         ssize_t retval = 0;
1382         char *buf;
1383         u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1384         u8 nread;
1385
1386         buf = kzalloc(size, GFP_KERNEL);
1387         if (!buf)
1388                 return -ENOMEM;
1389
1390         len += snprintf(buf + len, size - len,
1391                         "Channel Noise Floor : %d\n", ah->noise);
1392         len += snprintf(buf + len, size - len,
1393                         "Chain | privNF | # Readings | NF Readings\n");
1394         for (i = 0; i < NUM_NF_READINGS; i++) {
1395                 if (!(chainmask & (1 << i)) ||
1396                     ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1397                         continue;
1398
1399                 nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
1400                 len += snprintf(buf + len, size - len, " %d\t %d\t %d\t\t",
1401                                 i, h[i].privNF, nread);
1402                 for (j = 0; j < nread; j++)
1403                         len += snprintf(buf + len, size - len,
1404                                         " %d", h[i].nfCalBuffer[j]);
1405                 len += snprintf(buf + len, size - len, "\n");
1406         }
1407
1408         if (len > size)
1409                 len = size;
1410
1411         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1412         kfree(buf);
1413
1414         return retval;
1415 }
1416
1417 static const struct file_operations fops_dump_nfcal = {
1418         .read = read_file_dump_nfcal,
1419         .open = simple_open,
1420         .owner = THIS_MODULE,
1421         .llseek = default_llseek,
1422 };
1423
1424 static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf,
1425                                      size_t count, loff_t *ppos)
1426 {
1427         struct ath_softc *sc = file->private_data;
1428         struct ath_hw *ah = sc->sc_ah;
1429         u32 len = 0, size = 1500;
1430         ssize_t retval = 0;
1431         char *buf;
1432
1433         buf = kzalloc(size, GFP_KERNEL);
1434         if (!buf)
1435                 return -ENOMEM;
1436
1437         len = ah->eep_ops->dump_eeprom(ah, true, buf, len, size);
1438
1439         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1440         kfree(buf);
1441
1442         return retval;
1443 }
1444
1445 static const struct file_operations fops_base_eeprom = {
1446         .read = read_file_base_eeprom,
1447         .open = simple_open,
1448         .owner = THIS_MODULE,
1449         .llseek = default_llseek,
1450 };
1451
1452 static ssize_t read_file_modal_eeprom(struct file *file, char __user *user_buf,
1453                                       size_t count, loff_t *ppos)
1454 {
1455         struct ath_softc *sc = file->private_data;
1456         struct ath_hw *ah = sc->sc_ah;
1457         u32 len = 0, size = 6000;
1458         char *buf;
1459         size_t retval;
1460
1461         buf = kzalloc(size, GFP_KERNEL);
1462         if (buf == NULL)
1463                 return -ENOMEM;
1464
1465         len = ah->eep_ops->dump_eeprom(ah, false, buf, len, size);
1466
1467         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1468         kfree(buf);
1469
1470         return retval;
1471 }
1472
1473 static const struct file_operations fops_modal_eeprom = {
1474         .read = read_file_modal_eeprom,
1475         .open = simple_open,
1476         .owner = THIS_MODULE,
1477         .llseek = default_llseek,
1478 };
1479
1480 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
1481 static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
1482                                 size_t count, loff_t *ppos)
1483 {
1484         struct ath_softc *sc = file->private_data;
1485         u32 len = 0, size = 1500;
1486         char *buf;
1487         size_t retval;
1488
1489         buf = kzalloc(size, GFP_KERNEL);
1490         if (buf == NULL)
1491                 return -ENOMEM;
1492
1493         if (!sc->sc_ah->common.btcoex_enabled) {
1494                 len = snprintf(buf, size, "%s\n",
1495                                "BTCOEX is disabled");
1496                 goto exit;
1497         }
1498
1499         len = ath9k_dump_btcoex(sc, buf, size);
1500 exit:
1501         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1502         kfree(buf);
1503
1504         return retval;
1505 }
1506
1507 static const struct file_operations fops_btcoex = {
1508         .read = read_file_btcoex,
1509         .open = simple_open,
1510         .owner = THIS_MODULE,
1511         .llseek = default_llseek,
1512 };
1513 #endif
1514
1515 static ssize_t read_file_node_stat(struct file *file, char __user *user_buf,
1516                                    size_t count, loff_t *ppos)
1517 {
1518         struct ath_node *an = file->private_data;
1519         struct ath_softc *sc = an->sc;
1520         struct ath_atx_tid *tid;
1521         struct ath_atx_ac *ac;
1522         struct ath_txq *txq;
1523         u32 len = 0, size = 4096;
1524         char *buf;
1525         size_t retval;
1526         int tidno, acno;
1527
1528         buf = kzalloc(size, GFP_KERNEL);
1529         if (buf == NULL)
1530                 return -ENOMEM;
1531
1532         if (!an->sta->ht_cap.ht_supported) {
1533                 len = snprintf(buf, size, "%s\n",
1534                                "HT not supported");
1535                 goto exit;
1536         }
1537
1538         len = snprintf(buf, size, "Max-AMPDU: %d\n",
1539                        an->maxampdu);
1540         len += snprintf(buf + len, size - len, "MPDU Density: %d\n\n",
1541                         an->mpdudensity);
1542
1543         len += snprintf(buf + len, size - len,
1544                         "%2s%7s\n", "AC", "SCHED");
1545
1546         for (acno = 0, ac = &an->ac[acno];
1547              acno < IEEE80211_NUM_ACS; acno++, ac++) {
1548                 txq = ac->txq;
1549                 ath_txq_lock(sc, txq);
1550                 len += snprintf(buf + len, size - len,
1551                                 "%2d%7d\n",
1552                                 acno, ac->sched);
1553                 ath_txq_unlock(sc, txq);
1554         }
1555
1556         len += snprintf(buf + len, size - len,
1557                         "\n%3s%11s%10s%10s%10s%10s%9s%6s%8s\n",
1558                         "TID", "SEQ_START", "SEQ_NEXT", "BAW_SIZE",
1559                         "BAW_HEAD", "BAW_TAIL", "BAR_IDX", "SCHED", "PAUSED");
1560
1561         for (tidno = 0, tid = &an->tid[tidno];
1562              tidno < IEEE80211_NUM_TIDS; tidno++, tid++) {
1563                 txq = tid->ac->txq;
1564                 ath_txq_lock(sc, txq);
1565                 len += snprintf(buf + len, size - len,
1566                                 "%3d%11d%10d%10d%10d%10d%9d%6d%8d\n",
1567                                 tid->tidno, tid->seq_start, tid->seq_next,
1568                                 tid->baw_size, tid->baw_head, tid->baw_tail,
1569                                 tid->bar_index, tid->sched, tid->paused);
1570                 ath_txq_unlock(sc, txq);
1571         }
1572 exit:
1573         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1574         kfree(buf);
1575
1576         return retval;
1577 }
1578
1579 static const struct file_operations fops_node_stat = {
1580         .read = read_file_node_stat,
1581         .open = simple_open,
1582         .owner = THIS_MODULE,
1583         .llseek = default_llseek,
1584 };
1585
1586 void ath9k_sta_add_debugfs(struct ieee80211_hw *hw,
1587                            struct ieee80211_vif *vif,
1588                            struct ieee80211_sta *sta,
1589                            struct dentry *dir)
1590 {
1591         struct ath_node *an = (struct ath_node *)sta->drv_priv;
1592         an->node_stat = debugfs_create_file("node_stat", S_IRUGO,
1593                                             dir, an, &fops_node_stat);
1594 }
1595
1596 void ath9k_sta_remove_debugfs(struct ieee80211_hw *hw,
1597                               struct ieee80211_vif *vif,
1598                               struct ieee80211_sta *sta,
1599                               struct dentry *dir)
1600 {
1601         struct ath_node *an = (struct ath_node *)sta->drv_priv;
1602         debugfs_remove(an->node_stat);
1603 }
1604
1605 /* Ethtool support for get-stats */
1606
1607 #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1608 static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1609         "tx_pkts_nic",
1610         "tx_bytes_nic",
1611         "rx_pkts_nic",
1612         "rx_bytes_nic",
1613         AMKSTR(d_tx_pkts),
1614         AMKSTR(d_tx_bytes),
1615         AMKSTR(d_tx_mpdus_queued),
1616         AMKSTR(d_tx_mpdus_completed),
1617         AMKSTR(d_tx_mpdu_xretries),
1618         AMKSTR(d_tx_aggregates),
1619         AMKSTR(d_tx_ampdus_queued_hw),
1620         AMKSTR(d_tx_ampdus_queued_sw),
1621         AMKSTR(d_tx_ampdus_completed),
1622         AMKSTR(d_tx_ampdu_retries),
1623         AMKSTR(d_tx_ampdu_xretries),
1624         AMKSTR(d_tx_fifo_underrun),
1625         AMKSTR(d_tx_op_exceeded),
1626         AMKSTR(d_tx_timer_expiry),
1627         AMKSTR(d_tx_desc_cfg_err),
1628         AMKSTR(d_tx_data_underrun),
1629         AMKSTR(d_tx_delim_underrun),
1630         "d_rx_crc_err",
1631         "d_rx_decrypt_crc_err",
1632         "d_rx_phy_err",
1633         "d_rx_mic_err",
1634         "d_rx_pre_delim_crc_err",
1635         "d_rx_post_delim_crc_err",
1636         "d_rx_decrypt_busy_err",
1637
1638         "d_rx_phyerr_radar",
1639         "d_rx_phyerr_ofdm_timing",
1640         "d_rx_phyerr_cck_timing",
1641
1642 };
1643 #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1644
1645 void ath9k_get_et_strings(struct ieee80211_hw *hw,
1646                           struct ieee80211_vif *vif,
1647                           u32 sset, u8 *data)
1648 {
1649         if (sset == ETH_SS_STATS)
1650                 memcpy(data, *ath9k_gstrings_stats,
1651                        sizeof(ath9k_gstrings_stats));
1652 }
1653
1654 int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
1655                             struct ieee80211_vif *vif, int sset)
1656 {
1657         if (sset == ETH_SS_STATS)
1658                 return ATH9K_SSTATS_LEN;
1659         return 0;
1660 }
1661
1662 #define AWDATA(elem)                                                    \
1663         do {                                                            \
1664                 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
1665                 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
1666                 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
1667                 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
1668         } while (0)
1669
1670 #define AWDATA_RX(elem)                                         \
1671         do {                                                    \
1672                 data[i++] = sc->debug.stats.rxstats.elem;       \
1673         } while (0)
1674
1675 void ath9k_get_et_stats(struct ieee80211_hw *hw,
1676                         struct ieee80211_vif *vif,
1677                         struct ethtool_stats *stats, u64 *data)
1678 {
1679         struct ath_softc *sc = hw->priv;
1680         int i = 0;
1681
1682         data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
1683                      sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
1684                      sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
1685                      sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
1686         data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
1687                      sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
1688                      sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
1689                      sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
1690         AWDATA_RX(rx_pkts_all);
1691         AWDATA_RX(rx_bytes_all);
1692
1693         AWDATA(tx_pkts_all);
1694         AWDATA(tx_bytes_all);
1695         AWDATA(queued);
1696         AWDATA(completed);
1697         AWDATA(xretries);
1698         AWDATA(a_aggr);
1699         AWDATA(a_queued_hw);
1700         AWDATA(a_queued_sw);
1701         AWDATA(a_completed);
1702         AWDATA(a_retries);
1703         AWDATA(a_xretries);
1704         AWDATA(fifo_underrun);
1705         AWDATA(xtxop);
1706         AWDATA(timer_exp);
1707         AWDATA(desc_cfg_err);
1708         AWDATA(data_underrun);
1709         AWDATA(delim_underrun);
1710
1711         AWDATA_RX(crc_err);
1712         AWDATA_RX(decrypt_crc_err);
1713         AWDATA_RX(phy_err);
1714         AWDATA_RX(mic_err);
1715         AWDATA_RX(pre_delim_crc_err);
1716         AWDATA_RX(post_delim_crc_err);
1717         AWDATA_RX(decrypt_busy_err);
1718
1719         AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
1720         AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
1721         AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
1722
1723         WARN_ON(i != ATH9K_SSTATS_LEN);
1724 }
1725
1726 int ath9k_init_debug(struct ath_hw *ah)
1727 {
1728         struct ath_common *common = ath9k_hw_common(ah);
1729         struct ath_softc *sc = (struct ath_softc *) common->priv;
1730
1731         sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1732                                                    sc->hw->wiphy->debugfsdir);
1733         if (!sc->debug.debugfs_phy)
1734                 return -ENOMEM;
1735
1736 #ifdef CONFIG_ATH_DEBUG
1737         debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1738                             sc, &fops_debug);
1739 #endif
1740
1741         ath9k_dfs_init_debug(sc);
1742
1743         debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
1744                             &fops_dma);
1745         debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
1746                             &fops_interrupt);
1747         debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc,
1748                             &fops_xmit);
1749         debugfs_create_file("queues", S_IRUSR, sc->debug.debugfs_phy, sc,
1750                             &fops_queues);
1751         debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1752                            &sc->tx.txq_max_pending[IEEE80211_AC_BK]);
1753         debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1754                            &sc->tx.txq_max_pending[IEEE80211_AC_BE]);
1755         debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1756                            &sc->tx.txq_max_pending[IEEE80211_AC_VI]);
1757         debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1758                            &sc->tx.txq_max_pending[IEEE80211_AC_VO]);
1759         debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy, sc,
1760                             &fops_misc);
1761         debugfs_create_file("reset", S_IRUSR, sc->debug.debugfs_phy, sc,
1762                             &fops_reset);
1763         debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy, sc,
1764                             &fops_recv);
1765         debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
1766                             sc->debug.debugfs_phy, sc, &fops_rx_chainmask);
1767         debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
1768                             sc->debug.debugfs_phy, sc, &fops_tx_chainmask);
1769         debugfs_create_file("ani", S_IRUSR | S_IWUSR,
1770                             sc->debug.debugfs_phy, sc, &fops_ani);
1771         debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1772                             &sc->sc_ah->config.enable_paprd);
1773         debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1774                             sc, &fops_regidx);
1775         debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1776                             sc, &fops_regval);
1777         debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1778                             sc->debug.debugfs_phy,
1779                             &ah->config.cwm_ignore_extcca);
1780         debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
1781                             &fops_regdump);
1782         debugfs_create_file("dump_nfcal", S_IRUSR, sc->debug.debugfs_phy, sc,
1783                             &fops_dump_nfcal);
1784         debugfs_create_file("base_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
1785                             &fops_base_eeprom);
1786         debugfs_create_file("modal_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
1787                             &fops_modal_eeprom);
1788         sc->rfs_chan_spec_scan = relay_open("spectral_scan",
1789                                             sc->debug.debugfs_phy,
1790                                             1024, 256, &rfs_spec_scan_cb,
1791                                             NULL);
1792         debugfs_create_file("spectral_scan_ctl", S_IRUSR | S_IWUSR,
1793                             sc->debug.debugfs_phy, sc,
1794                             &fops_spec_scan_ctl);
1795         debugfs_create_file("spectral_short_repeat", S_IRUSR | S_IWUSR,
1796                             sc->debug.debugfs_phy, sc,
1797                             &fops_spectral_short_repeat);
1798         debugfs_create_file("spectral_count", S_IRUSR | S_IWUSR,
1799                             sc->debug.debugfs_phy, sc, &fops_spectral_count);
1800         debugfs_create_file("spectral_period", S_IRUSR | S_IWUSR,
1801                             sc->debug.debugfs_phy, sc, &fops_spectral_period);
1802         debugfs_create_file("spectral_fft_period", S_IRUSR | S_IWUSR,
1803                             sc->debug.debugfs_phy, sc,
1804                             &fops_spectral_fft_period);
1805         debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
1806                            sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
1807         debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
1808                            sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
1809         debugfs_create_file("diversity", S_IRUSR | S_IWUSR,
1810                             sc->debug.debugfs_phy, sc, &fops_ant_diversity);
1811 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
1812         debugfs_create_file("btcoex", S_IRUSR, sc->debug.debugfs_phy, sc,
1813                             &fops_btcoex);
1814 #endif
1815         return 0;
1816 }