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