Revert "ath: ath9k: use debugfs_create_devm_seqfile() helper for seq_file entries"
[linux-2.6-microblaze.git] / drivers / net / wireless / ath / ath9k / debug.c
1 /*
2  * Copyright (c) 2008-2011 Atheros Communications Inc.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #include <linux/slab.h>
18 #include <linux/vmalloc.h>
19 #include <linux/export.h>
20 #include <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 void ath9k_debug_sync_cause(struct ath_softc *sc, u32 sync_cause)
30 {
31         if (sync_cause)
32                 sc->debug.stats.istats.sync_cause_all++;
33         if (sync_cause & AR_INTR_SYNC_RTC_IRQ)
34                 sc->debug.stats.istats.sync_rtc_irq++;
35         if (sync_cause & AR_INTR_SYNC_MAC_IRQ)
36                 sc->debug.stats.istats.sync_mac_irq++;
37         if (sync_cause & AR_INTR_SYNC_EEPROM_ILLEGAL_ACCESS)
38                 sc->debug.stats.istats.eeprom_illegal_access++;
39         if (sync_cause & AR_INTR_SYNC_APB_TIMEOUT)
40                 sc->debug.stats.istats.apb_timeout++;
41         if (sync_cause & AR_INTR_SYNC_PCI_MODE_CONFLICT)
42                 sc->debug.stats.istats.pci_mode_conflict++;
43         if (sync_cause & AR_INTR_SYNC_HOST1_FATAL)
44                 sc->debug.stats.istats.host1_fatal++;
45         if (sync_cause & AR_INTR_SYNC_HOST1_PERR)
46                 sc->debug.stats.istats.host1_perr++;
47         if (sync_cause & AR_INTR_SYNC_TRCV_FIFO_PERR)
48                 sc->debug.stats.istats.trcv_fifo_perr++;
49         if (sync_cause & AR_INTR_SYNC_RADM_CPL_EP)
50                 sc->debug.stats.istats.radm_cpl_ep++;
51         if (sync_cause & AR_INTR_SYNC_RADM_CPL_DLLP_ABORT)
52                 sc->debug.stats.istats.radm_cpl_dllp_abort++;
53         if (sync_cause & AR_INTR_SYNC_RADM_CPL_TLP_ABORT)
54                 sc->debug.stats.istats.radm_cpl_tlp_abort++;
55         if (sync_cause & AR_INTR_SYNC_RADM_CPL_ECRC_ERR)
56                 sc->debug.stats.istats.radm_cpl_ecrc_err++;
57         if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT)
58                 sc->debug.stats.istats.radm_cpl_timeout++;
59         if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT)
60                 sc->debug.stats.istats.local_timeout++;
61         if (sync_cause & AR_INTR_SYNC_PM_ACCESS)
62                 sc->debug.stats.istats.pm_access++;
63         if (sync_cause & AR_INTR_SYNC_MAC_AWAKE)
64                 sc->debug.stats.istats.mac_awake++;
65         if (sync_cause & AR_INTR_SYNC_MAC_ASLEEP)
66                 sc->debug.stats.istats.mac_asleep++;
67         if (sync_cause & AR_INTR_SYNC_MAC_SLEEP_ACCESS)
68                 sc->debug.stats.istats.mac_sleep_access++;
69 }
70
71 static ssize_t ath9k_debugfs_read_buf(struct file *file, char __user *user_buf,
72                                       size_t count, loff_t *ppos)
73 {
74         u8 *buf = file->private_data;
75         return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
76 }
77
78 static int ath9k_debugfs_release_buf(struct inode *inode, struct file *file)
79 {
80         vfree(file->private_data);
81         return 0;
82 }
83
84 #ifdef CONFIG_ATH_DEBUG
85
86 static ssize_t read_file_debug(struct file *file, char __user *user_buf,
87                              size_t count, loff_t *ppos)
88 {
89         struct ath_softc *sc = file->private_data;
90         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
91         char buf[32];
92         unsigned int len;
93
94         len = sprintf(buf, "0x%08x\n", common->debug_mask);
95         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
96 }
97
98 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
99                              size_t count, loff_t *ppos)
100 {
101         struct ath_softc *sc = file->private_data;
102         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
103         unsigned long mask;
104         char buf[32];
105         ssize_t len;
106
107         len = min(count, sizeof(buf) - 1);
108         if (copy_from_user(buf, user_buf, len))
109                 return -EFAULT;
110
111         buf[len] = '\0';
112         if (kstrtoul(buf, 0, &mask))
113                 return -EINVAL;
114
115         common->debug_mask = mask;
116         return count;
117 }
118
119 static const struct file_operations fops_debug = {
120         .read = read_file_debug,
121         .write = write_file_debug,
122         .open = simple_open,
123         .owner = THIS_MODULE,
124         .llseek = default_llseek,
125 };
126
127 #endif
128
129 #define DMA_BUF_LEN 1024
130
131
132 static ssize_t read_file_ani(struct file *file, char __user *user_buf,
133                              size_t count, loff_t *ppos)
134 {
135         struct ath_softc *sc = file->private_data;
136         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
137         struct ath_hw *ah = sc->sc_ah;
138         unsigned int len = 0;
139         const unsigned int size = 1024;
140         ssize_t retval = 0;
141         char *buf;
142         int i;
143         struct {
144                 const char *name;
145                 unsigned int val;
146         } ani_info[] = {
147                 { "ANI RESET", ah->stats.ast_ani_reset },
148                 { "OFDM LEVEL", ah->ani.ofdmNoiseImmunityLevel },
149                 { "CCK LEVEL", ah->ani.cckNoiseImmunityLevel },
150                 { "SPUR UP", ah->stats.ast_ani_spurup },
151                 { "SPUR DOWN", ah->stats.ast_ani_spurup },
152                 { "OFDM WS-DET ON", ah->stats.ast_ani_ofdmon },
153                 { "OFDM WS-DET OFF", ah->stats.ast_ani_ofdmoff },
154                 { "MRC-CCK ON", ah->stats.ast_ani_ccklow },
155                 { "MRC-CCK OFF", ah->stats.ast_ani_cckhigh },
156                 { "FIR-STEP UP", ah->stats.ast_ani_stepup },
157                 { "FIR-STEP DOWN", ah->stats.ast_ani_stepdown },
158                 { "INV LISTENTIME", ah->stats.ast_ani_lneg_or_lzero },
159                 { "OFDM ERRORS", ah->stats.ast_ani_ofdmerrs },
160                 { "CCK ERRORS", ah->stats.ast_ani_cckerrs },
161         };
162
163         buf = kzalloc(size, GFP_KERNEL);
164         if (buf == NULL)
165                 return -ENOMEM;
166
167         len += scnprintf(buf + len, size - len, "%15s: %s\n", "ANI",
168                          common->disable_ani ? "DISABLED" : "ENABLED");
169
170         if (common->disable_ani)
171                 goto exit;
172
173         for (i = 0; i < ARRAY_SIZE(ani_info); i++)
174                 len += scnprintf(buf + len, size - len, "%15s: %u\n",
175                                  ani_info[i].name, ani_info[i].val);
176
177 exit:
178         if (len > size)
179                 len = size;
180
181         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
182         kfree(buf);
183
184         return retval;
185 }
186
187 static ssize_t write_file_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 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 (kstrtoul(buf, 0, &ani))
203                 return -EINVAL;
204
205         if (ani > 1)
206                 return -EINVAL;
207
208         common->disable_ani = !ani;
209
210         if (common->disable_ani) {
211                 clear_bit(ATH_OP_ANI_RUN, &common->op_flags);
212                 ath_stop_ani(sc);
213         } else {
214                 ath_check_ani(sc);
215         }
216
217         return count;
218 }
219
220 static const struct file_operations fops_ani = {
221         .read = read_file_ani,
222         .write = write_file_ani,
223         .open = simple_open,
224         .owner = THIS_MODULE,
225         .llseek = default_llseek,
226 };
227
228 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
229
230 static ssize_t read_file_bt_ant_diversity(struct file *file,
231                                           char __user *user_buf,
232                                           size_t count, loff_t *ppos)
233 {
234         struct ath_softc *sc = file->private_data;
235         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
236         char buf[32];
237         unsigned int len;
238
239         len = sprintf(buf, "%d\n", common->bt_ant_diversity);
240         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
241 }
242
243 static ssize_t write_file_bt_ant_diversity(struct file *file,
244                                            const char __user *user_buf,
245                                            size_t count, loff_t *ppos)
246 {
247         struct ath_softc *sc = file->private_data;
248         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
249         struct ath9k_hw_capabilities *pCap = &sc->sc_ah->caps;
250         unsigned long bt_ant_diversity;
251         char buf[32];
252         ssize_t len;
253
254         len = min(count, sizeof(buf) - 1);
255         if (copy_from_user(buf, user_buf, len))
256                 return -EFAULT;
257
258         if (!(pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
259                 goto exit;
260
261         buf[len] = '\0';
262         if (kstrtoul(buf, 0, &bt_ant_diversity))
263                 return -EINVAL;
264
265         common->bt_ant_diversity = !!bt_ant_diversity;
266         ath9k_ps_wakeup(sc);
267         ath9k_hw_set_bt_ant_diversity(sc->sc_ah, common->bt_ant_diversity);
268         ath_dbg(common, CONFIG, "Enable WLAN/BT RX Antenna diversity: %d\n",
269                 common->bt_ant_diversity);
270         ath9k_ps_restore(sc);
271 exit:
272         return count;
273 }
274
275 static const struct file_operations fops_bt_ant_diversity = {
276         .read = read_file_bt_ant_diversity,
277         .write = write_file_bt_ant_diversity,
278         .open = simple_open,
279         .owner = THIS_MODULE,
280         .llseek = default_llseek,
281 };
282
283 #endif
284
285 void ath9k_debug_stat_ant(struct ath_softc *sc,
286                           struct ath_hw_antcomb_conf *div_ant_conf,
287                           int main_rssi_avg, int alt_rssi_avg)
288 {
289         struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
290         struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
291
292         as_main->lna_attempt_cnt[div_ant_conf->main_lna_conf]++;
293         as_alt->lna_attempt_cnt[div_ant_conf->alt_lna_conf]++;
294
295         as_main->rssi_avg = main_rssi_avg;
296         as_alt->rssi_avg = alt_rssi_avg;
297 }
298
299 static ssize_t read_file_antenna_diversity(struct file *file,
300                                            char __user *user_buf,
301                                            size_t count, loff_t *ppos)
302 {
303         struct ath_softc *sc = file->private_data;
304         struct ath_hw *ah = sc->sc_ah;
305         struct ath9k_hw_capabilities *pCap = &ah->caps;
306         struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
307         struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
308         struct ath_hw_antcomb_conf div_ant_conf;
309         unsigned int len = 0;
310         const unsigned int size = 1024;
311         ssize_t retval = 0;
312         char *buf;
313         static const char *lna_conf_str[4] = {
314                 "LNA1_MINUS_LNA2", "LNA2", "LNA1", "LNA1_PLUS_LNA2"
315         };
316
317         buf = kzalloc(size, GFP_KERNEL);
318         if (buf == NULL)
319                 return -ENOMEM;
320
321         if (!(pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)) {
322                 len += scnprintf(buf + len, size - len, "%s\n",
323                                  "Antenna Diversity Combining is disabled");
324                 goto exit;
325         }
326
327         ath9k_ps_wakeup(sc);
328         ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
329         len += scnprintf(buf + len, size - len, "Current MAIN config : %s\n",
330                          lna_conf_str[div_ant_conf.main_lna_conf]);
331         len += scnprintf(buf + len, size - len, "Current ALT config  : %s\n",
332                          lna_conf_str[div_ant_conf.alt_lna_conf]);
333         len += scnprintf(buf + len, size - len, "Average MAIN RSSI   : %d\n",
334                          as_main->rssi_avg);
335         len += scnprintf(buf + len, size - len, "Average ALT RSSI    : %d\n\n",
336                          as_alt->rssi_avg);
337         ath9k_ps_restore(sc);
338
339         len += scnprintf(buf + len, size - len, "Packet Receive Cnt:\n");
340         len += scnprintf(buf + len, size - len, "-------------------\n");
341
342         len += scnprintf(buf + len, size - len, "%30s%15s\n",
343                          "MAIN", "ALT");
344         len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
345                          "TOTAL COUNT",
346                          as_main->recv_cnt,
347                          as_alt->recv_cnt);
348         len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
349                          "LNA1",
350                          as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1],
351                          as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1]);
352         len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
353                          "LNA2",
354                          as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2],
355                          as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2]);
356         len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
357                          "LNA1 + LNA2",
358                          as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
359                          as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
360         len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
361                          "LNA1 - LNA2",
362                          as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
363                          as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
364
365         len += scnprintf(buf + len, size - len, "\nLNA Config Attempts:\n");
366         len += scnprintf(buf + len, size - len, "--------------------\n");
367
368         len += scnprintf(buf + len, size - len, "%30s%15s\n",
369                          "MAIN", "ALT");
370         len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
371                          "LNA1",
372                          as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1],
373                          as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1]);
374         len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
375                          "LNA2",
376                          as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2],
377                          as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2]);
378         len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
379                          "LNA1 + LNA2",
380                          as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
381                          as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
382         len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
383                          "LNA1 - LNA2",
384                          as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
385                          as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
386
387 exit:
388         if (len > size)
389                 len = size;
390
391         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
392         kfree(buf);
393
394         return retval;
395 }
396
397 static const struct file_operations fops_antenna_diversity = {
398         .read = read_file_antenna_diversity,
399         .open = simple_open,
400         .owner = THIS_MODULE,
401         .llseek = default_llseek,
402 };
403
404 static int read_file_dma(struct seq_file *file, void *data)
405 {
406         struct ath_softc *sc = file->private;
407         struct ath_hw *ah = sc->sc_ah;
408         u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
409         int i, qcuOffset = 0, dcuOffset = 0;
410         u32 *qcuBase = &val[0], *dcuBase = &val[4];
411
412         ath9k_ps_wakeup(sc);
413
414         REG_WRITE_D(ah, AR_MACMISC,
415                   ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
416                    (AR_MACMISC_MISC_OBS_BUS_1 <<
417                     AR_MACMISC_MISC_OBS_BUS_MSB_S)));
418
419         seq_puts(file, "Raw DMA Debug values:\n");
420
421         for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
422                 if (i % 4 == 0)
423                         seq_puts(file, "\n");
424
425                 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
426                 seq_printf(file, "%d: %08x ", i, val[i]);
427         }
428
429         seq_puts(file, "\n\n");
430         seq_puts(file, "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
431
432         for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
433                 if (i == 8) {
434                         qcuOffset = 0;
435                         qcuBase++;
436                 }
437
438                 if (i == 6) {
439                         dcuOffset = 0;
440                         dcuBase++;
441                 }
442
443                 seq_printf(file, "%2d          %2x      %1x     %2x           %2x\n",
444                            i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
445                            (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
446                            (val[2] & (0x7 << (i * 3))) >> (i * 3),
447                            (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
448         }
449
450         seq_puts(file, "\n");
451
452         seq_printf(file, "qcu_stitch state:   %2x    qcu_fetch state:        %2x\n",
453                    (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
454         seq_printf(file, "qcu_complete state: %2x    dcu_complete state:     %2x\n",
455                    (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
456         seq_printf(file, "dcu_arb state:      %2x    dcu_fp state:           %2x\n",
457                    (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
458         seq_printf(file, "chan_idle_dur:     %3d    chan_idle_dur_valid:     %1d\n",
459                    (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
460         seq_printf(file, "txfifo_valid_0:      %1d    txfifo_valid_1:          %1d\n",
461                    (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
462         seq_printf(file, "txfifo_dcu_num_0:   %2d    txfifo_dcu_num_1:       %2d\n",
463                    (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
464
465         seq_printf(file, "pcu observe: 0x%x\n", REG_READ_D(ah, AR_OBS_BUS_1));
466         seq_printf(file, "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
467
468         ath9k_ps_restore(sc);
469
470         return 0;
471 }
472
473 static int open_file_dma(struct inode *inode, struct file *f)
474 {
475         return single_open(f, read_file_dma, inode->i_private);
476 }
477
478 static const struct file_operations fops_dma = {
479         .open = open_file_dma,
480         .read = seq_read,
481         .owner = THIS_MODULE,
482         .llseek = seq_lseek,
483         .release = single_release,
484 };
485
486
487 void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
488 {
489         if (status)
490                 sc->debug.stats.istats.total++;
491         if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
492                 if (status & ATH9K_INT_RXLP)
493                         sc->debug.stats.istats.rxlp++;
494                 if (status & ATH9K_INT_RXHP)
495                         sc->debug.stats.istats.rxhp++;
496                 if (status & ATH9K_INT_BB_WATCHDOG)
497                         sc->debug.stats.istats.bb_watchdog++;
498         } else {
499                 if (status & ATH9K_INT_RX)
500                         sc->debug.stats.istats.rxok++;
501         }
502         if (status & ATH9K_INT_RXEOL)
503                 sc->debug.stats.istats.rxeol++;
504         if (status & ATH9K_INT_RXORN)
505                 sc->debug.stats.istats.rxorn++;
506         if (status & ATH9K_INT_TX)
507                 sc->debug.stats.istats.txok++;
508         if (status & ATH9K_INT_TXURN)
509                 sc->debug.stats.istats.txurn++;
510         if (status & ATH9K_INT_RXPHY)
511                 sc->debug.stats.istats.rxphyerr++;
512         if (status & ATH9K_INT_RXKCM)
513                 sc->debug.stats.istats.rx_keycache_miss++;
514         if (status & ATH9K_INT_SWBA)
515                 sc->debug.stats.istats.swba++;
516         if (status & ATH9K_INT_BMISS)
517                 sc->debug.stats.istats.bmiss++;
518         if (status & ATH9K_INT_BNR)
519                 sc->debug.stats.istats.bnr++;
520         if (status & ATH9K_INT_CST)
521                 sc->debug.stats.istats.cst++;
522         if (status & ATH9K_INT_GTT)
523                 sc->debug.stats.istats.gtt++;
524         if (status & ATH9K_INT_TIM)
525                 sc->debug.stats.istats.tim++;
526         if (status & ATH9K_INT_CABEND)
527                 sc->debug.stats.istats.cabend++;
528         if (status & ATH9K_INT_DTIMSYNC)
529                 sc->debug.stats.istats.dtimsync++;
530         if (status & ATH9K_INT_DTIM)
531                 sc->debug.stats.istats.dtim++;
532         if (status & ATH9K_INT_TSFOOR)
533                 sc->debug.stats.istats.tsfoor++;
534         if (status & ATH9K_INT_MCI)
535                 sc->debug.stats.istats.mci++;
536         if (status & ATH9K_INT_GENTIMER)
537                 sc->debug.stats.istats.gen_timer++;
538 }
539
540 static int read_file_interrupt(struct seq_file *file, void *data)
541 {
542         struct ath_softc *sc = file->private;
543
544 #define PR_IS(a, s)                                             \
545         do {                                                    \
546                 seq_printf(file, "%21s: %10u\n", a,             \
547                            sc->debug.stats.istats.s);           \
548         } while (0)
549
550         if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
551                 PR_IS("RXLP", rxlp);
552                 PR_IS("RXHP", rxhp);
553                 PR_IS("WATHDOG", bb_watchdog);
554         } else {
555                 PR_IS("RX", rxok);
556         }
557         PR_IS("RXEOL", rxeol);
558         PR_IS("RXORN", rxorn);
559         PR_IS("TX", txok);
560         PR_IS("TXURN", txurn);
561         PR_IS("MIB", mib);
562         PR_IS("RXPHY", rxphyerr);
563         PR_IS("RXKCM", rx_keycache_miss);
564         PR_IS("SWBA", swba);
565         PR_IS("BMISS", bmiss);
566         PR_IS("BNR", bnr);
567         PR_IS("CST", cst);
568         PR_IS("GTT", gtt);
569         PR_IS("TIM", tim);
570         PR_IS("CABEND", cabend);
571         PR_IS("DTIMSYNC", dtimsync);
572         PR_IS("DTIM", dtim);
573         PR_IS("TSFOOR", tsfoor);
574         PR_IS("MCI", mci);
575         PR_IS("GENTIMER", gen_timer);
576         PR_IS("TOTAL", total);
577
578         seq_puts(file, "SYNC_CAUSE stats:\n");
579
580         PR_IS("Sync-All", sync_cause_all);
581         PR_IS("RTC-IRQ", sync_rtc_irq);
582         PR_IS("MAC-IRQ", sync_mac_irq);
583         PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
584         PR_IS("APB-Timeout", apb_timeout);
585         PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
586         PR_IS("HOST1-Fatal", host1_fatal);
587         PR_IS("HOST1-Perr", host1_perr);
588         PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
589         PR_IS("RADM-CPL-EP", radm_cpl_ep);
590         PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
591         PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
592         PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
593         PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
594         PR_IS("Local-Bus-Timeout", local_timeout);
595         PR_IS("PM-Access", pm_access);
596         PR_IS("MAC-Awake", mac_awake);
597         PR_IS("MAC-Asleep", mac_asleep);
598         PR_IS("MAC-Sleep-Access", mac_sleep_access);
599
600         return 0;
601 }
602
603 static int open_file_interrupt(struct inode *inode, struct file *f)
604 {
605         return single_open(f, read_file_interrupt, inode->i_private);
606 }
607
608 static const struct file_operations fops_interrupt = {
609         .read = seq_read,
610         .open = open_file_interrupt,
611         .owner = THIS_MODULE,
612         .llseek = seq_lseek,
613         .release = single_release,
614 };
615
616 static int read_file_xmit(struct seq_file *file, void *data)
617 {
618         struct ath_softc *sc = file->private;
619
620         seq_printf(file, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
621
622         PR("MPDUs Queued:    ", queued);
623         PR("MPDUs Completed: ", completed);
624         PR("MPDUs XRetried:  ", xretries);
625         PR("Aggregates:      ", a_aggr);
626         PR("AMPDUs Queued HW:", a_queued_hw);
627         PR("AMPDUs Queued SW:", a_queued_sw);
628         PR("AMPDUs Completed:", a_completed);
629         PR("AMPDUs Retried:  ", a_retries);
630         PR("AMPDUs XRetried: ", a_xretries);
631         PR("TXERR Filtered:  ", txerr_filtered);
632         PR("FIFO Underrun:   ", fifo_underrun);
633         PR("TXOP Exceeded:   ", xtxop);
634         PR("TXTIMER Expiry:  ", timer_exp);
635         PR("DESC CFG Error:  ", desc_cfg_err);
636         PR("DATA Underrun:   ", data_underrun);
637         PR("DELIM Underrun:  ", delim_underrun);
638         PR("TX-Pkts-All:     ", tx_pkts_all);
639         PR("TX-Bytes-All:    ", tx_bytes_all);
640         PR("HW-put-tx-buf:   ", puttxbuf);
641         PR("HW-tx-start:     ", txstart);
642         PR("HW-tx-proc-desc: ", txprocdesc);
643         PR("TX-Failed:       ", txfailed);
644
645         return 0;
646 }
647
648 static void print_queue(struct ath_softc *sc, struct ath_txq *txq,
649                         struct seq_file *file)
650 {
651         ath_txq_lock(sc, txq);
652
653         seq_printf(file, "%s: %d ", "qnum", txq->axq_qnum);
654         seq_printf(file, "%s: %2d ", "qdepth", txq->axq_depth);
655         seq_printf(file, "%s: %2d ", "ampdu-depth", txq->axq_ampdu_depth);
656         seq_printf(file, "%s: %3d ", "pending", txq->pending_frames);
657         seq_printf(file, "%s: %d\n", "stopped", txq->stopped);
658
659         ath_txq_unlock(sc, txq);
660 }
661
662 static int read_file_queues(struct seq_file *file, void *data)
663 {
664         struct ath_softc *sc = file->private;
665         struct ath_txq *txq;
666         int i;
667         static const char *qname[4] = {
668                 "VO", "VI", "BE", "BK"
669         };
670
671         for (i = 0; i < IEEE80211_NUM_ACS; i++) {
672                 txq = sc->tx.txq_map[i];
673                 seq_printf(file, "(%s):  ", qname[i]);
674                 print_queue(sc, txq, file);
675         }
676
677         seq_puts(file, "(CAB): ");
678         print_queue(sc, sc->beacon.cabq, file);
679
680         return 0;
681 }
682
683 static int read_file_misc(struct seq_file *file, void *data)
684 {
685         struct ath_softc *sc = file->private;
686         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
687         struct ath9k_vif_iter_data iter_data;
688         struct ath_chanctx *ctx;
689         unsigned int reg;
690         u32 rxfilter, i;
691
692         seq_printf(file, "BSSID: %pM\n", common->curbssid);
693         seq_printf(file, "BSSID-MASK: %pM\n", common->bssidmask);
694         seq_printf(file, "OPMODE: %s\n",
695                    ath_opmode_to_string(sc->sc_ah->opmode));
696
697         ath9k_ps_wakeup(sc);
698         rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
699         ath9k_ps_restore(sc);
700
701         seq_printf(file, "RXFILTER: 0x%x", rxfilter);
702
703         if (rxfilter & ATH9K_RX_FILTER_UCAST)
704                 seq_puts(file, " UCAST");
705         if (rxfilter & ATH9K_RX_FILTER_MCAST)
706                 seq_puts(file, " MCAST");
707         if (rxfilter & ATH9K_RX_FILTER_BCAST)
708                 seq_puts(file, " BCAST");
709         if (rxfilter & ATH9K_RX_FILTER_CONTROL)
710                 seq_puts(file, " CONTROL");
711         if (rxfilter & ATH9K_RX_FILTER_BEACON)
712                 seq_puts(file, " BEACON");
713         if (rxfilter & ATH9K_RX_FILTER_PROM)
714                 seq_puts(file, " PROM");
715         if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
716                 seq_puts(file, " PROBEREQ");
717         if (rxfilter & ATH9K_RX_FILTER_PHYERR)
718                 seq_puts(file, " PHYERR");
719         if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
720                 seq_puts(file, " MYBEACON");
721         if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
722                 seq_puts(file, " COMP_BAR");
723         if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
724                 seq_puts(file, " PSPOLL");
725         if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
726                 seq_puts(file, " PHYRADAR");
727         if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
728                 seq_puts(file, " MCAST_BCAST_ALL");
729         if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
730                 seq_puts(file, " CONTROL_WRAPPER");
731
732         seq_puts(file, "\n");
733
734         reg = sc->sc_ah->imask;
735
736         seq_printf(file, "INTERRUPT-MASK: 0x%x", reg);
737
738         if (reg & ATH9K_INT_SWBA)
739                 seq_puts(file, " SWBA");
740         if (reg & ATH9K_INT_BMISS)
741                 seq_puts(file, " BMISS");
742         if (reg & ATH9K_INT_CST)
743                 seq_puts(file, " CST");
744         if (reg & ATH9K_INT_RX)
745                 seq_puts(file, " RX");
746         if (reg & ATH9K_INT_RXHP)
747                 seq_puts(file, " RXHP");
748         if (reg & ATH9K_INT_RXLP)
749                 seq_puts(file, " RXLP");
750         if (reg & ATH9K_INT_BB_WATCHDOG)
751                 seq_puts(file, " BB_WATCHDOG");
752
753         seq_puts(file, "\n");
754
755         i = 0;
756         ath_for_each_chanctx(sc, ctx) {
757                 if (!ctx->assigned || list_empty(&ctx->vifs))
758                         continue;
759                 ath9k_calculate_iter_data(sc, ctx, &iter_data);
760
761                 seq_printf(file,
762                            "VIF-COUNTS: CTX %i AP: %i STA: %i MESH: %i WDS: %i",
763                            i++, iter_data.naps, iter_data.nstations,
764                            iter_data.nmeshes, iter_data.nwds);
765                 seq_printf(file, " ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n",
766                            iter_data.nadhocs, sc->cur_chan->nvifs,
767                            sc->nbcnvifs);
768         }
769
770         return 0;
771 }
772
773 static int read_file_reset(struct seq_file *file, void *data)
774 {
775         struct ath_softc *sc = file->private;
776
777         seq_printf(file, "%17s: %2d\n", "Baseband Hang",
778                    sc->debug.stats.reset[RESET_TYPE_BB_HANG]);
779         seq_printf(file, "%17s: %2d\n", "Baseband Watchdog",
780                    sc->debug.stats.reset[RESET_TYPE_BB_WATCHDOG]);
781         seq_printf(file, "%17s: %2d\n", "Fatal HW Error",
782                    sc->debug.stats.reset[RESET_TYPE_FATAL_INT]);
783         seq_printf(file, "%17s: %2d\n", "TX HW error",
784                    sc->debug.stats.reset[RESET_TYPE_TX_ERROR]);
785         seq_printf(file, "%17s: %2d\n", "TX Path Hang",
786                    sc->debug.stats.reset[RESET_TYPE_TX_HANG]);
787         seq_printf(file, "%17s: %2d\n", "PLL RX Hang",
788                    sc->debug.stats.reset[RESET_TYPE_PLL_HANG]);
789         seq_printf(file, "%17s: %2d\n", "MAC Hang",
790                    sc->debug.stats.reset[RESET_TYPE_MAC_HANG]);
791         seq_printf(file, "%17s: %2d\n", "Stuck Beacon",
792                    sc->debug.stats.reset[RESET_TYPE_BEACON_STUCK]);
793         seq_printf(file, "%17s: %2d\n", "MCI Reset",
794                    sc->debug.stats.reset[RESET_TYPE_MCI]);
795
796         return 0;
797 }
798
799 void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
800                        struct ath_tx_status *ts, struct ath_txq *txq,
801                        unsigned int flags)
802 {
803         int qnum = txq->axq_qnum;
804
805         TX_STAT_INC(qnum, tx_pkts_all);
806         sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
807
808         if (bf_isampdu(bf)) {
809                 if (flags & ATH_TX_ERROR)
810                         TX_STAT_INC(qnum, a_xretries);
811                 else
812                         TX_STAT_INC(qnum, a_completed);
813         } else {
814                 if (ts->ts_status & ATH9K_TXERR_XRETRY)
815                         TX_STAT_INC(qnum, xretries);
816                 else
817                         TX_STAT_INC(qnum, completed);
818         }
819
820         if (ts->ts_status & ATH9K_TXERR_FILT)
821                 TX_STAT_INC(qnum, txerr_filtered);
822         if (ts->ts_status & ATH9K_TXERR_FIFO)
823                 TX_STAT_INC(qnum, fifo_underrun);
824         if (ts->ts_status & ATH9K_TXERR_XTXOP)
825                 TX_STAT_INC(qnum, xtxop);
826         if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
827                 TX_STAT_INC(qnum, timer_exp);
828         if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
829                 TX_STAT_INC(qnum, desc_cfg_err);
830         if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
831                 TX_STAT_INC(qnum, data_underrun);
832         if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
833                 TX_STAT_INC(qnum, delim_underrun);
834 }
835
836 static int open_file_xmit(struct inode *inode, struct file *f)
837 {
838         return single_open(f, read_file_xmit, inode->i_private);
839 }
840
841 static const struct file_operations fops_xmit = {
842         .read = seq_read,
843         .open = open_file_xmit,
844         .owner = THIS_MODULE,
845         .llseek = seq_lseek,
846         .release = single_release,
847 };
848
849 static int open_file_queues(struct inode *inode, struct file *f)
850 {
851         return single_open(f, read_file_queues, inode->i_private);
852 }
853
854 static const struct file_operations fops_queues = {
855         .read = seq_read,
856         .open = open_file_queues,
857         .owner = THIS_MODULE,
858         .llseek = seq_lseek,
859         .release = single_release,
860 };
861
862 static int open_file_misc(struct inode *inode, struct file *f)
863 {
864         return single_open(f, read_file_misc, inode->i_private);
865 }
866
867 static const struct file_operations fops_misc = {
868         .read = seq_read,
869         .open = open_file_misc,
870         .owner = THIS_MODULE,
871         .llseek = seq_lseek,
872         .release = single_release,
873 };
874
875 static int open_file_reset(struct inode *inode, struct file *f)
876 {
877         return single_open(f, read_file_reset, inode->i_private);
878 }
879
880 static const struct file_operations fops_reset = {
881         .read = seq_read,
882         .open = open_file_reset,
883         .owner = THIS_MODULE,
884         .llseek = seq_lseek,
885         .release = single_release,
886 };
887
888 void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
889 {
890         ath9k_cmn_debug_stat_rx(&sc->debug.stats.rxstats, rs);
891 }
892
893 static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
894                                 size_t count, loff_t *ppos)
895 {
896         struct ath_softc *sc = file->private_data;
897         char buf[32];
898         unsigned int len;
899
900         len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
901         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
902 }
903
904 static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
905                                  size_t count, loff_t *ppos)
906 {
907         struct ath_softc *sc = file->private_data;
908         unsigned long regidx;
909         char buf[32];
910         ssize_t len;
911
912         len = min(count, sizeof(buf) - 1);
913         if (copy_from_user(buf, user_buf, len))
914                 return -EFAULT;
915
916         buf[len] = '\0';
917         if (kstrtoul(buf, 0, &regidx))
918                 return -EINVAL;
919
920         sc->debug.regidx = regidx;
921         return count;
922 }
923
924 static const struct file_operations fops_regidx = {
925         .read = read_file_regidx,
926         .write = write_file_regidx,
927         .open = simple_open,
928         .owner = THIS_MODULE,
929         .llseek = default_llseek,
930 };
931
932 static ssize_t read_file_regval(struct file *file, char __user *user_buf,
933                                 size_t count, loff_t *ppos)
934 {
935         struct ath_softc *sc = file->private_data;
936         struct ath_hw *ah = sc->sc_ah;
937         char buf[32];
938         unsigned int len;
939         u32 regval;
940
941         ath9k_ps_wakeup(sc);
942         regval = REG_READ_D(ah, sc->debug.regidx);
943         ath9k_ps_restore(sc);
944         len = sprintf(buf, "0x%08x\n", regval);
945         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
946 }
947
948 static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
949                                  size_t count, loff_t *ppos)
950 {
951         struct ath_softc *sc = file->private_data;
952         struct ath_hw *ah = sc->sc_ah;
953         unsigned long regval;
954         char buf[32];
955         ssize_t len;
956
957         len = min(count, sizeof(buf) - 1);
958         if (copy_from_user(buf, user_buf, len))
959                 return -EFAULT;
960
961         buf[len] = '\0';
962         if (kstrtoul(buf, 0, &regval))
963                 return -EINVAL;
964
965         ath9k_ps_wakeup(sc);
966         REG_WRITE_D(ah, sc->debug.regidx, regval);
967         ath9k_ps_restore(sc);
968         return count;
969 }
970
971 static const struct file_operations fops_regval = {
972         .read = read_file_regval,
973         .write = write_file_regval,
974         .open = simple_open,
975         .owner = THIS_MODULE,
976         .llseek = default_llseek,
977 };
978
979 #define REGDUMP_LINE_SIZE       20
980
981 static int open_file_regdump(struct inode *inode, struct file *file)
982 {
983         struct ath_softc *sc = inode->i_private;
984         unsigned int len = 0;
985         u8 *buf;
986         int i;
987         unsigned long num_regs, regdump_len, max_reg_offset;
988
989         max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
990         num_regs = max_reg_offset / 4 + 1;
991         regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
992         buf = vmalloc(regdump_len);
993         if (!buf)
994                 return -ENOMEM;
995
996         ath9k_ps_wakeup(sc);
997         for (i = 0; i < num_regs; i++)
998                 len += scnprintf(buf + len, regdump_len - len,
999                         "0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
1000         ath9k_ps_restore(sc);
1001
1002         file->private_data = buf;
1003
1004         return 0;
1005 }
1006
1007 static const struct file_operations fops_regdump = {
1008         .open = open_file_regdump,
1009         .read = ath9k_debugfs_read_buf,
1010         .release = ath9k_debugfs_release_buf,
1011         .owner = THIS_MODULE,
1012         .llseek = default_llseek,/* read accesses f_pos */
1013 };
1014
1015 static int read_file_dump_nfcal(struct seq_file *file, void *data)
1016 {
1017         struct ath_softc *sc = file->private;
1018         struct ath_hw *ah = sc->sc_ah;
1019         struct ath9k_nfcal_hist *h = sc->cur_chan->caldata.nfCalHist;
1020         struct ath_common *common = ath9k_hw_common(ah);
1021         struct ieee80211_conf *conf = &common->hw->conf;
1022         u32 i, j;
1023         u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1024         u8 nread;
1025
1026         seq_printf(file, "Channel Noise Floor : %d\n", ah->noise);
1027         seq_puts(file, "Chain | privNF | # Readings | NF Readings\n");
1028         for (i = 0; i < NUM_NF_READINGS; i++) {
1029                 if (!(chainmask & (1 << i)) ||
1030                     ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1031                         continue;
1032
1033                 nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
1034                 seq_printf(file, " %d\t %d\t %d\t\t", i, h[i].privNF, nread);
1035                 for (j = 0; j < nread; j++)
1036                         seq_printf(file, " %d", h[i].nfCalBuffer[j]);
1037                 seq_puts(file, "\n");
1038         }
1039
1040         return 0;
1041 }
1042
1043 static int open_file_dump_nfcal(struct inode *inode, struct file *f)
1044 {
1045         return single_open(f, read_file_dump_nfcal, inode->i_private);
1046 }
1047
1048 static const struct file_operations fops_dump_nfcal = {
1049         .read = seq_read,
1050         .open = open_file_dump_nfcal,
1051         .owner = THIS_MODULE,
1052         .llseek = seq_lseek,
1053         .release = single_release,
1054 };
1055
1056 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
1057 static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
1058                                 size_t count, loff_t *ppos)
1059 {
1060         struct ath_softc *sc = file->private_data;
1061         u32 len = 0, size = 1500;
1062         char *buf;
1063         size_t retval;
1064
1065         buf = kzalloc(size, GFP_KERNEL);
1066         if (buf == NULL)
1067                 return -ENOMEM;
1068
1069         if (!sc->sc_ah->common.btcoex_enabled) {
1070                 len = scnprintf(buf, size, "%s\n",
1071                                 "BTCOEX is disabled");
1072                 goto exit;
1073         }
1074
1075         len = ath9k_dump_btcoex(sc, buf, size);
1076 exit:
1077         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1078         kfree(buf);
1079
1080         return retval;
1081 }
1082
1083 static const struct file_operations fops_btcoex = {
1084         .read = read_file_btcoex,
1085         .open = simple_open,
1086         .owner = THIS_MODULE,
1087         .llseek = default_llseek,
1088 };
1089 #endif
1090
1091 #ifdef CONFIG_ATH9K_DYNACK
1092 static ssize_t read_file_ackto(struct file *file, char __user *user_buf,
1093                                size_t count, loff_t *ppos)
1094 {
1095         struct ath_softc *sc = file->private_data;
1096         struct ath_hw *ah = sc->sc_ah;
1097         char buf[32];
1098         unsigned int len;
1099
1100         len = sprintf(buf, "%u %c\n", ah->dynack.ackto,
1101                       (ah->dynack.enabled) ? 'A' : 'S');
1102
1103         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1104 }
1105
1106 static const struct file_operations fops_ackto = {
1107         .read = read_file_ackto,
1108         .open = simple_open,
1109         .owner = THIS_MODULE,
1110         .llseek = default_llseek,
1111 };
1112 #endif
1113
1114 /* Ethtool support for get-stats */
1115
1116 #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1117 static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1118         "tx_pkts_nic",
1119         "tx_bytes_nic",
1120         "rx_pkts_nic",
1121         "rx_bytes_nic",
1122         AMKSTR(d_tx_pkts),
1123         AMKSTR(d_tx_bytes),
1124         AMKSTR(d_tx_mpdus_queued),
1125         AMKSTR(d_tx_mpdus_completed),
1126         AMKSTR(d_tx_mpdu_xretries),
1127         AMKSTR(d_tx_aggregates),
1128         AMKSTR(d_tx_ampdus_queued_hw),
1129         AMKSTR(d_tx_ampdus_queued_sw),
1130         AMKSTR(d_tx_ampdus_completed),
1131         AMKSTR(d_tx_ampdu_retries),
1132         AMKSTR(d_tx_ampdu_xretries),
1133         AMKSTR(d_tx_fifo_underrun),
1134         AMKSTR(d_tx_op_exceeded),
1135         AMKSTR(d_tx_timer_expiry),
1136         AMKSTR(d_tx_desc_cfg_err),
1137         AMKSTR(d_tx_data_underrun),
1138         AMKSTR(d_tx_delim_underrun),
1139         "d_rx_crc_err",
1140         "d_rx_decrypt_crc_err",
1141         "d_rx_phy_err",
1142         "d_rx_mic_err",
1143         "d_rx_pre_delim_crc_err",
1144         "d_rx_post_delim_crc_err",
1145         "d_rx_decrypt_busy_err",
1146
1147         "d_rx_phyerr_radar",
1148         "d_rx_phyerr_ofdm_timing",
1149         "d_rx_phyerr_cck_timing",
1150
1151 };
1152 #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1153
1154 void ath9k_get_et_strings(struct ieee80211_hw *hw,
1155                           struct ieee80211_vif *vif,
1156                           u32 sset, u8 *data)
1157 {
1158         if (sset == ETH_SS_STATS)
1159                 memcpy(data, *ath9k_gstrings_stats,
1160                        sizeof(ath9k_gstrings_stats));
1161 }
1162
1163 int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
1164                             struct ieee80211_vif *vif, int sset)
1165 {
1166         if (sset == ETH_SS_STATS)
1167                 return ATH9K_SSTATS_LEN;
1168         return 0;
1169 }
1170
1171 #define AWDATA(elem)                                                    \
1172         do {                                                            \
1173                 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
1174                 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
1175                 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
1176                 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
1177         } while (0)
1178
1179 #define AWDATA_RX(elem)                                         \
1180         do {                                                    \
1181                 data[i++] = sc->debug.stats.rxstats.elem;       \
1182         } while (0)
1183
1184 void ath9k_get_et_stats(struct ieee80211_hw *hw,
1185                         struct ieee80211_vif *vif,
1186                         struct ethtool_stats *stats, u64 *data)
1187 {
1188         struct ath_softc *sc = hw->priv;
1189         int i = 0;
1190
1191         data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
1192                      sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
1193                      sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
1194                      sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
1195         data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
1196                      sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
1197                      sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
1198                      sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
1199         AWDATA_RX(rx_pkts_all);
1200         AWDATA_RX(rx_bytes_all);
1201
1202         AWDATA(tx_pkts_all);
1203         AWDATA(tx_bytes_all);
1204         AWDATA(queued);
1205         AWDATA(completed);
1206         AWDATA(xretries);
1207         AWDATA(a_aggr);
1208         AWDATA(a_queued_hw);
1209         AWDATA(a_queued_sw);
1210         AWDATA(a_completed);
1211         AWDATA(a_retries);
1212         AWDATA(a_xretries);
1213         AWDATA(fifo_underrun);
1214         AWDATA(xtxop);
1215         AWDATA(timer_exp);
1216         AWDATA(desc_cfg_err);
1217         AWDATA(data_underrun);
1218         AWDATA(delim_underrun);
1219
1220         AWDATA_RX(crc_err);
1221         AWDATA_RX(decrypt_crc_err);
1222         AWDATA_RX(phy_err);
1223         AWDATA_RX(mic_err);
1224         AWDATA_RX(pre_delim_crc_err);
1225         AWDATA_RX(post_delim_crc_err);
1226         AWDATA_RX(decrypt_busy_err);
1227
1228         AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
1229         AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
1230         AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
1231
1232         WARN_ON(i != ATH9K_SSTATS_LEN);
1233 }
1234
1235 void ath9k_deinit_debug(struct ath_softc *sc)
1236 {
1237         ath9k_spectral_deinit_debug(sc);
1238 }
1239
1240 int ath9k_init_debug(struct ath_hw *ah)
1241 {
1242         struct ath_common *common = ath9k_hw_common(ah);
1243         struct ath_softc *sc = (struct ath_softc *) common->priv;
1244
1245         sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1246                                                    sc->hw->wiphy->debugfsdir);
1247         if (!sc->debug.debugfs_phy)
1248                 return -ENOMEM;
1249
1250 #ifdef CONFIG_ATH_DEBUG
1251         debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1252                             sc, &fops_debug);
1253 #endif
1254
1255         ath9k_dfs_init_debug(sc);
1256         ath9k_tx99_init_debug(sc);
1257         ath9k_spectral_init_debug(sc);
1258
1259         debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
1260                             &fops_dma);
1261         debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
1262                             &fops_interrupt);
1263         debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc,
1264                             &fops_xmit);
1265         debugfs_create_file("queues", S_IRUSR, sc->debug.debugfs_phy, sc,
1266                             &fops_queues);
1267         debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1268                            &sc->tx.txq_max_pending[IEEE80211_AC_BK]);
1269         debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1270                            &sc->tx.txq_max_pending[IEEE80211_AC_BE]);
1271         debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1272                            &sc->tx.txq_max_pending[IEEE80211_AC_VI]);
1273         debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1274                            &sc->tx.txq_max_pending[IEEE80211_AC_VO]);
1275         debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy, sc,
1276                             &fops_misc);
1277         debugfs_create_file("reset", S_IRUSR, sc->debug.debugfs_phy, sc,
1278                             &fops_reset);
1279
1280         ath9k_cmn_debug_recv(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
1281         ath9k_cmn_debug_phy_err(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
1282
1283         debugfs_create_u8("rx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
1284                           &ah->rxchainmask);
1285         debugfs_create_u8("tx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
1286                           &ah->txchainmask);
1287         debugfs_create_file("ani", S_IRUSR | S_IWUSR,
1288                             sc->debug.debugfs_phy, sc, &fops_ani);
1289         debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1290                             &sc->sc_ah->config.enable_paprd);
1291         debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1292                             sc, &fops_regidx);
1293         debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1294                             sc, &fops_regval);
1295         debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1296                             sc->debug.debugfs_phy,
1297                             &ah->config.cwm_ignore_extcca);
1298         debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
1299                             &fops_regdump);
1300         debugfs_create_file("dump_nfcal", S_IRUSR, sc->debug.debugfs_phy, sc,
1301                             &fops_dump_nfcal);
1302
1303         ath9k_cmn_debug_base_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
1304         ath9k_cmn_debug_modal_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
1305
1306         debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
1307                            sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
1308         debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
1309                            sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
1310         debugfs_create_file("antenna_diversity", S_IRUSR,
1311                             sc->debug.debugfs_phy, sc, &fops_antenna_diversity);
1312 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
1313         debugfs_create_file("bt_ant_diversity", S_IRUSR | S_IWUSR,
1314                             sc->debug.debugfs_phy, sc, &fops_bt_ant_diversity);
1315         debugfs_create_file("btcoex", S_IRUSR, sc->debug.debugfs_phy, sc,
1316                             &fops_btcoex);
1317 #endif
1318
1319 #ifdef CONFIG_ATH9K_DYNACK
1320         debugfs_create_file("ack_to", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1321                             sc, &fops_ackto);
1322 #endif
1323
1324         return 0;
1325 }