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