]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/net/wireless/ath/ath9k/debug.c
bcma: add missing put_device call
[mirror_ubuntu-hirsute-kernel.git] / drivers / net / wireless / ath / ath9k / debug.c
CommitLineData
88b126af 1/*
5b68138e 2 * Copyright (c) 2008-2011 Atheros Communications Inc.
88b126af
S
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
5a0e3ad6 17#include <linux/slab.h>
582d0064 18#include <linux/vmalloc.h>
ee40fa06 19#include <linux/export.h>
52103115
GJ
20#include <asm/unaligned.h>
21
394cf0a1 22#include "ath9k.h"
88b126af 23
475a6e4d
LR
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
2a163c6d 29
582d0064
VT
30static 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
37static int ath9k_debugfs_release_buf(struct inode *inode, struct file *file)
38{
39 vfree(file->private_data);
40 return 0;
41}
42
a830df07
FF
43#ifdef CONFIG_ATH_DEBUG
44
2493928e
JH
45static 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;
c46917bb 49 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2493928e 50 char buf[32];
581f725c
VT
51 unsigned int len;
52
2b87f3aa 53 len = sprintf(buf, "0x%08x\n", common->debug_mask);
2493928e
JH
54 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
55}
56
57static 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;
c46917bb 61 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2493928e
JH
62 unsigned long mask;
63 char buf[32];
581f725c
VT
64 ssize_t len;
65
66 len = min(count, sizeof(buf) - 1);
67 if (copy_from_user(buf, user_buf, len))
04236066 68 return -EFAULT;
581f725c
VT
69
70 buf[len] = '\0';
27d7f477 71 if (kstrtoul(buf, 0, &mask))
581f725c
VT
72 return -EINVAL;
73
c46917bb 74 common->debug_mask = mask;
2493928e
JH
75 return count;
76}
77
78static const struct file_operations fops_debug = {
79 .read = read_file_debug,
80 .write = write_file_debug,
234e3405 81 .open = simple_open,
6038f373
AB
82 .owner = THIS_MODULE,
83 .llseek = default_llseek,
2493928e
JH
84};
85
a830df07
FF
86#endif
87
991a0987
PR
88#define DMA_BUF_LEN 1024
89
15340694 90
6e4d291e 91static ssize_t read_file_ani(struct file *file, char __user *user_buf,
05c0be2f
MSS
92 size_t count, loff_t *ppos)
93{
94 struct ath_softc *sc = file->private_data;
95 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
6e4d291e
SM
96 struct ath_hw *ah = sc->sc_ah;
97 unsigned int len = 0, size = 1024;
98 ssize_t retval = 0;
99 char *buf;
05c0be2f 100
6e4d291e
SM
101 buf = kzalloc(size, GFP_KERNEL);
102 if (buf == NULL)
103 return -ENOMEM;
104
105 if (common->disable_ani) {
5e88ba62
ZK
106 len += scnprintf(buf + len, size - len, "%s: %s\n",
107 "ANI", "DISABLED");
6e4d291e
SM
108 goto exit;
109 }
110
5e88ba62
ZK
111 len += scnprintf(buf + len, size - len, "%15s: %s\n",
112 "ANI", "ENABLED");
113 len += scnprintf(buf + len, size - len, "%15s: %u\n",
114 "ANI RESET", ah->stats.ast_ani_reset);
115 len += scnprintf(buf + len, size - len, "%15s: %u\n",
116 "SPUR UP", ah->stats.ast_ani_spurup);
117 len += scnprintf(buf + len, size - len, "%15s: %u\n",
118 "SPUR DOWN", ah->stats.ast_ani_spurup);
119 len += scnprintf(buf + len, size - len, "%15s: %u\n",
120 "OFDM WS-DET ON", ah->stats.ast_ani_ofdmon);
121 len += scnprintf(buf + len, size - len, "%15s: %u\n",
122 "OFDM WS-DET OFF", ah->stats.ast_ani_ofdmoff);
123 len += scnprintf(buf + len, size - len, "%15s: %u\n",
124 "MRC-CCK ON", ah->stats.ast_ani_ccklow);
125 len += scnprintf(buf + len, size - len, "%15s: %u\n",
126 "MRC-CCK OFF", ah->stats.ast_ani_cckhigh);
127 len += scnprintf(buf + len, size - len, "%15s: %u\n",
128 "FIR-STEP UP", ah->stats.ast_ani_stepup);
129 len += scnprintf(buf + len, size - len, "%15s: %u\n",
130 "FIR-STEP DOWN", ah->stats.ast_ani_stepdown);
131 len += scnprintf(buf + len, size - len, "%15s: %u\n",
132 "INV LISTENTIME", ah->stats.ast_ani_lneg_or_lzero);
133 len += scnprintf(buf + len, size - len, "%15s: %u\n",
134 "OFDM ERRORS", ah->stats.ast_ani_ofdmerrs);
135 len += scnprintf(buf + len, size - len, "%15s: %u\n",
136 "CCK ERRORS", ah->stats.ast_ani_cckerrs);
6e4d291e
SM
137exit:
138 if (len > size)
139 len = size;
140
141 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
142 kfree(buf);
143
144 return retval;
05c0be2f
MSS
145}
146
6e4d291e
SM
147static ssize_t write_file_ani(struct file *file,
148 const char __user *user_buf,
149 size_t count, loff_t *ppos)
05c0be2f
MSS
150{
151 struct ath_softc *sc = file->private_data;
152 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
6e4d291e 153 unsigned long ani;
05c0be2f
MSS
154 char buf[32];
155 ssize_t len;
156
157 len = min(count, sizeof(buf) - 1);
158 if (copy_from_user(buf, user_buf, len))
159 return -EFAULT;
160
161 buf[len] = '\0';
3899ba90 162 if (kstrtoul(buf, 0, &ani))
05c0be2f
MSS
163 return -EINVAL;
164
6e4d291e 165 if (ani < 0 || ani > 1)
05c0be2f
MSS
166 return -EINVAL;
167
6e4d291e 168 common->disable_ani = !ani;
05c0be2f 169
6e4d291e 170 if (common->disable_ani) {
781b14a3 171 clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
da0d45f7 172 ath_stop_ani(sc);
05c0be2f 173 } else {
da0d45f7 174 ath_check_ani(sc);
05c0be2f
MSS
175 }
176
177 return count;
178}
179
6e4d291e
SM
180static const struct file_operations fops_ani = {
181 .read = read_file_ani,
182 .write = write_file_ani,
234e3405 183 .open = simple_open,
05c0be2f
MSS
184 .owner = THIS_MODULE,
185 .llseek = default_llseek,
186};
15340694 187
36e8825e
SM
188#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
189
63081305
SM
190static ssize_t read_file_bt_ant_diversity(struct file *file,
191 char __user *user_buf,
192 size_t count, loff_t *ppos)
302a3c3a
SM
193{
194 struct ath_softc *sc = file->private_data;
195 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
196 char buf[32];
197 unsigned int len;
198
63081305 199 len = sprintf(buf, "%d\n", common->bt_ant_diversity);
302a3c3a
SM
200 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
201}
202
63081305
SM
203static ssize_t write_file_bt_ant_diversity(struct file *file,
204 const char __user *user_buf,
205 size_t count, loff_t *ppos)
302a3c3a
SM
206{
207 struct ath_softc *sc = file->private_data;
208 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
3f2da955 209 struct ath9k_hw_capabilities *pCap = &sc->sc_ah->caps;
63081305 210 unsigned long bt_ant_diversity;
302a3c3a
SM
211 char buf[32];
212 ssize_t len;
213
214 len = min(count, sizeof(buf) - 1);
215 if (copy_from_user(buf, user_buf, len))
216 return -EFAULT;
217
3f2da955
SM
218 if (!(pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
219 goto exit;
220
302a3c3a 221 buf[len] = '\0';
63081305 222 if (kstrtoul(buf, 0, &bt_ant_diversity))
302a3c3a
SM
223 return -EINVAL;
224
63081305 225 common->bt_ant_diversity = !!bt_ant_diversity;
302a3c3a 226 ath9k_ps_wakeup(sc);
047dc3ac 227 ath9k_hw_set_bt_ant_diversity(sc->sc_ah, common->bt_ant_diversity);
63081305
SM
228 ath_dbg(common, CONFIG, "Enable WLAN/BT RX Antenna diversity: %d\n",
229 common->bt_ant_diversity);
302a3c3a 230 ath9k_ps_restore(sc);
3f2da955 231exit:
302a3c3a
SM
232 return count;
233}
234
63081305
SM
235static const struct file_operations fops_bt_ant_diversity = {
236 .read = read_file_bt_ant_diversity,
237 .write = write_file_bt_ant_diversity,
302a3c3a
SM
238 .open = simple_open,
239 .owner = THIS_MODULE,
240 .llseek = default_llseek,
241};
242
36e8825e
SM
243#endif
244
e3d52914
SM
245void ath9k_debug_stat_ant(struct ath_softc *sc,
246 struct ath_hw_antcomb_conf *div_ant_conf,
247 int main_rssi_avg, int alt_rssi_avg)
248{
249 struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
250 struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
251
252 as_main->lna_attempt_cnt[div_ant_conf->main_lna_conf]++;
253 as_alt->lna_attempt_cnt[div_ant_conf->alt_lna_conf]++;
254
255 as_main->rssi_avg = main_rssi_avg;
256 as_alt->rssi_avg = alt_rssi_avg;
257}
258
4eba10cc
SM
259static ssize_t read_file_antenna_diversity(struct file *file,
260 char __user *user_buf,
261 size_t count, loff_t *ppos)
262{
263 struct ath_softc *sc = file->private_data;
264 struct ath_hw *ah = sc->sc_ah;
265 struct ath9k_hw_capabilities *pCap = &ah->caps;
266 struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
267 struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
e3d52914 268 struct ath_hw_antcomb_conf div_ant_conf;
4eba10cc
SM
269 unsigned int len = 0, size = 1024;
270 ssize_t retval = 0;
271 char *buf;
e3d52914
SM
272 char *lna_conf_str[4] = {"LNA1_MINUS_LNA2",
273 "LNA2",
274 "LNA1",
275 "LNA1_PLUS_LNA2"};
4eba10cc
SM
276
277 buf = kzalloc(size, GFP_KERNEL);
278 if (buf == NULL)
279 return -ENOMEM;
280
281 if (!(pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)) {
5e88ba62
ZK
282 len += scnprintf(buf + len, size - len, "%s\n",
283 "Antenna Diversity Combining is disabled");
4eba10cc
SM
284 goto exit;
285 }
286
e3d52914
SM
287 ath9k_ps_wakeup(sc);
288 ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
5e88ba62
ZK
289 len += scnprintf(buf + len, size - len, "Current MAIN config : %s\n",
290 lna_conf_str[div_ant_conf.main_lna_conf]);
291 len += scnprintf(buf + len, size - len, "Current ALT config : %s\n",
292 lna_conf_str[div_ant_conf.alt_lna_conf]);
293 len += scnprintf(buf + len, size - len, "Average MAIN RSSI : %d\n",
294 as_main->rssi_avg);
295 len += scnprintf(buf + len, size - len, "Average ALT RSSI : %d\n\n",
296 as_alt->rssi_avg);
e3d52914
SM
297 ath9k_ps_restore(sc);
298
5e88ba62
ZK
299 len += scnprintf(buf + len, size - len, "Packet Receive Cnt:\n");
300 len += scnprintf(buf + len, size - len, "-------------------\n");
301
302 len += scnprintf(buf + len, size - len, "%30s%15s\n",
303 "MAIN", "ALT");
304 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
305 "TOTAL COUNT",
306 as_main->recv_cnt,
307 as_alt->recv_cnt);
308 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
309 "LNA1",
310 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1],
311 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1]);
312 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
313 "LNA2",
314 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2],
315 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2]);
316 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
317 "LNA1 + LNA2",
318 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
319 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
320 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
321 "LNA1 - LNA2",
322 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
323 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
324
325 len += scnprintf(buf + len, size - len, "\nLNA Config Attempts:\n");
326 len += scnprintf(buf + len, size - len, "--------------------\n");
327
328 len += scnprintf(buf + len, size - len, "%30s%15s\n",
329 "MAIN", "ALT");
330 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
331 "LNA1",
332 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1],
333 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1]);
334 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
335 "LNA2",
336 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2],
337 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2]);
338 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
339 "LNA1 + LNA2",
340 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
341 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
342 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
343 "LNA1 - LNA2",
344 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
345 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
e3d52914 346
4eba10cc
SM
347exit:
348 if (len > size)
349 len = size;
350
351 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
352 kfree(buf);
353
354 return retval;
355}
356
357static const struct file_operations fops_antenna_diversity = {
358 .read = read_file_antenna_diversity,
359 .open = simple_open,
360 .owner = THIS_MODULE,
361 .llseek = default_llseek,
362};
363
2a163c6d
S
364static ssize_t read_file_dma(struct file *file, char __user *user_buf,
365 size_t count, loff_t *ppos)
366{
367 struct ath_softc *sc = file->private_data;
cbe61d8a 368 struct ath_hw *ah = sc->sc_ah;
991a0987
PR
369 char *buf;
370 int retval;
2a163c6d
S
371 unsigned int len = 0;
372 u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
373 int i, qcuOffset = 0, dcuOffset = 0;
374 u32 *qcuBase = &val[0], *dcuBase = &val[4];
375
991a0987
PR
376 buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
377 if (!buf)
04236066 378 return -ENOMEM;
991a0987 379
7cf4a2e7
S
380 ath9k_ps_wakeup(sc);
381
475a6e4d 382 REG_WRITE_D(ah, AR_MACMISC,
2a163c6d
S
383 ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
384 (AR_MACMISC_MISC_OBS_BUS_1 <<
385 AR_MACMISC_MISC_OBS_BUS_MSB_S)));
386
5e88ba62
ZK
387 len += scnprintf(buf + len, DMA_BUF_LEN - len,
388 "Raw DMA Debug values:\n");
2a163c6d
S
389
390 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
391 if (i % 4 == 0)
5e88ba62 392 len += scnprintf(buf + len, DMA_BUF_LEN - len, "\n");
2a163c6d 393
475a6e4d 394 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
5e88ba62
ZK
395 len += scnprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
396 i, val[i]);
2a163c6d
S
397 }
398
5e88ba62
ZK
399 len += scnprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
400 len += scnprintf(buf + len, DMA_BUF_LEN - len,
401 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
2a163c6d
S
402
403 for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
404 if (i == 8) {
405 qcuOffset = 0;
406 qcuBase++;
407 }
408
409 if (i == 6) {
410 dcuOffset = 0;
411 dcuBase++;
412 }
413
5e88ba62
ZK
414 len += scnprintf(buf + len, DMA_BUF_LEN - len,
415 "%2d %2x %1x %2x %2x\n",
416 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
417 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
418 val[2] & (0x7 << (i * 3)) >> (i * 3),
419 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
2a163c6d
S
420 }
421
5e88ba62 422 len += scnprintf(buf + len, DMA_BUF_LEN - len, "\n");
2a163c6d 423
5e88ba62 424 len += scnprintf(buf + len, DMA_BUF_LEN - len,
2a163c6d
S
425 "qcu_stitch state: %2x qcu_fetch state: %2x\n",
426 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
5e88ba62 427 len += scnprintf(buf + len, DMA_BUF_LEN - len,
2a163c6d
S
428 "qcu_complete state: %2x dcu_complete state: %2x\n",
429 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
5e88ba62 430 len += scnprintf(buf + len, DMA_BUF_LEN - len,
2a163c6d
S
431 "dcu_arb state: %2x dcu_fp state: %2x\n",
432 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
5e88ba62 433 len += scnprintf(buf + len, DMA_BUF_LEN - len,
2a163c6d
S
434 "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
435 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
5e88ba62 436 len += scnprintf(buf + len, DMA_BUF_LEN - len,
2a163c6d
S
437 "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
438 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
5e88ba62 439 len += scnprintf(buf + len, DMA_BUF_LEN - len,
2a163c6d
S
440 "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
441 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
442
5e88ba62
ZK
443 len += scnprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
444 REG_READ_D(ah, AR_OBS_BUS_1));
445 len += scnprintf(buf + len, DMA_BUF_LEN - len,
446 "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
2a163c6d 447
7cf4a2e7
S
448 ath9k_ps_restore(sc);
449
2b87f3aa
DC
450 if (len > DMA_BUF_LEN)
451 len = DMA_BUF_LEN;
452
991a0987
PR
453 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
454 kfree(buf);
455 return retval;
2a163c6d
S
456}
457
458static const struct file_operations fops_dma = {
459 .read = read_file_dma,
234e3405 460 .open = simple_open,
6038f373
AB
461 .owner = THIS_MODULE,
462 .llseek = default_llseek,
2a163c6d
S
463};
464
817e11de
S
465
466void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
467{
468 if (status)
17d7904d 469 sc->debug.stats.istats.total++;
a9616f41
LR
470 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
471 if (status & ATH9K_INT_RXLP)
472 sc->debug.stats.istats.rxlp++;
473 if (status & ATH9K_INT_RXHP)
474 sc->debug.stats.istats.rxhp++;
08578b8f
LR
475 if (status & ATH9K_INT_BB_WATCHDOG)
476 sc->debug.stats.istats.bb_watchdog++;
a9616f41
LR
477 } else {
478 if (status & ATH9K_INT_RX)
479 sc->debug.stats.istats.rxok++;
480 }
817e11de 481 if (status & ATH9K_INT_RXEOL)
17d7904d 482 sc->debug.stats.istats.rxeol++;
817e11de 483 if (status & ATH9K_INT_RXORN)
17d7904d 484 sc->debug.stats.istats.rxorn++;
817e11de 485 if (status & ATH9K_INT_TX)
17d7904d 486 sc->debug.stats.istats.txok++;
817e11de 487 if (status & ATH9K_INT_TXURN)
17d7904d 488 sc->debug.stats.istats.txurn++;
817e11de 489 if (status & ATH9K_INT_RXPHY)
17d7904d 490 sc->debug.stats.istats.rxphyerr++;
817e11de 491 if (status & ATH9K_INT_RXKCM)
17d7904d 492 sc->debug.stats.istats.rx_keycache_miss++;
817e11de 493 if (status & ATH9K_INT_SWBA)
17d7904d 494 sc->debug.stats.istats.swba++;
817e11de 495 if (status & ATH9K_INT_BMISS)
17d7904d 496 sc->debug.stats.istats.bmiss++;
817e11de 497 if (status & ATH9K_INT_BNR)
17d7904d 498 sc->debug.stats.istats.bnr++;
817e11de 499 if (status & ATH9K_INT_CST)
17d7904d 500 sc->debug.stats.istats.cst++;
817e11de 501 if (status & ATH9K_INT_GTT)
17d7904d 502 sc->debug.stats.istats.gtt++;
817e11de 503 if (status & ATH9K_INT_TIM)
17d7904d 504 sc->debug.stats.istats.tim++;
817e11de 505 if (status & ATH9K_INT_CABEND)
17d7904d 506 sc->debug.stats.istats.cabend++;
817e11de 507 if (status & ATH9K_INT_DTIMSYNC)
17d7904d 508 sc->debug.stats.istats.dtimsync++;
817e11de 509 if (status & ATH9K_INT_DTIM)
17d7904d 510 sc->debug.stats.istats.dtim++;
6dde1aab
MSS
511 if (status & ATH9K_INT_TSFOOR)
512 sc->debug.stats.istats.tsfoor++;
97ba515a
SM
513 if (status & ATH9K_INT_MCI)
514 sc->debug.stats.istats.mci++;
c9e6e980
MSS
515 if (status & ATH9K_INT_GENTIMER)
516 sc->debug.stats.istats.gen_timer++;
817e11de
S
517}
518
519static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
520 size_t count, loff_t *ppos)
521{
522 struct ath_softc *sc = file->private_data;
817e11de 523 unsigned int len = 0;
462e58f2
BG
524 int rv;
525 int mxlen = 4000;
526 char *buf = kmalloc(mxlen, GFP_KERNEL);
527 if (!buf)
528 return -ENOMEM;
529
530#define PR_IS(a, s) \
531 do { \
5e88ba62
ZK
532 len += scnprintf(buf + len, mxlen - len, \
533 "%21s: %10u\n", a, \
534 sc->debug.stats.istats.s); \
462e58f2 535 } while (0)
817e11de 536
a9616f41 537 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
462e58f2
BG
538 PR_IS("RXLP", rxlp);
539 PR_IS("RXHP", rxhp);
540 PR_IS("WATHDOG", bb_watchdog);
a9616f41 541 } else {
462e58f2 542 PR_IS("RX", rxok);
a9616f41 543 }
462e58f2
BG
544 PR_IS("RXEOL", rxeol);
545 PR_IS("RXORN", rxorn);
546 PR_IS("TX", txok);
547 PR_IS("TXURN", txurn);
548 PR_IS("MIB", mib);
549 PR_IS("RXPHY", rxphyerr);
550 PR_IS("RXKCM", rx_keycache_miss);
551 PR_IS("SWBA", swba);
552 PR_IS("BMISS", bmiss);
553 PR_IS("BNR", bnr);
554 PR_IS("CST", cst);
555 PR_IS("GTT", gtt);
556 PR_IS("TIM", tim);
557 PR_IS("CABEND", cabend);
558 PR_IS("DTIMSYNC", dtimsync);
559 PR_IS("DTIM", dtim);
560 PR_IS("TSFOOR", tsfoor);
97ba515a 561 PR_IS("MCI", mci);
c9e6e980 562 PR_IS("GENTIMER", gen_timer);
462e58f2
BG
563 PR_IS("TOTAL", total);
564
5e88ba62
ZK
565 len += scnprintf(buf + len, mxlen - len,
566 "SYNC_CAUSE stats:\n");
462e58f2
BG
567
568 PR_IS("Sync-All", sync_cause_all);
569 PR_IS("RTC-IRQ", sync_rtc_irq);
570 PR_IS("MAC-IRQ", sync_mac_irq);
571 PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
572 PR_IS("APB-Timeout", apb_timeout);
573 PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
574 PR_IS("HOST1-Fatal", host1_fatal);
575 PR_IS("HOST1-Perr", host1_perr);
576 PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
577 PR_IS("RADM-CPL-EP", radm_cpl_ep);
578 PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
579 PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
580 PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
581 PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
582 PR_IS("Local-Bus-Timeout", local_timeout);
583 PR_IS("PM-Access", pm_access);
584 PR_IS("MAC-Awake", mac_awake);
585 PR_IS("MAC-Asleep", mac_asleep);
586 PR_IS("MAC-Sleep-Access", mac_sleep_access);
587
588 if (len > mxlen)
589 len = mxlen;
590
591 rv = simple_read_from_buffer(user_buf, count, ppos, buf, len);
592 kfree(buf);
593 return rv;
817e11de
S
594}
595
596static const struct file_operations fops_interrupt = {
597 .read = read_file_interrupt,
234e3405 598 .open = simple_open,
6038f373
AB
599 .owner = THIS_MODULE,
600 .llseek = default_llseek,
817e11de
S
601};
602
fec247c0
S
603static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
604 size_t count, loff_t *ppos)
605{
606 struct ath_softc *sc = file->private_data;
607 char *buf;
78ef731c 608 unsigned int len = 0, size = 2048;
fec247c0
S
609 ssize_t retval = 0;
610
611 buf = kzalloc(size, GFP_KERNEL);
612 if (buf == NULL)
04236066 613 return -ENOMEM;
fec247c0 614
78ef731c 615 len += sprintf(buf, "%30s %10s%10s%10s\n\n",
7f010c93 616 "BE", "BK", "VI", "VO");
fec247c0
S
617
618 PR("MPDUs Queued: ", queued);
619 PR("MPDUs Completed: ", completed);
5a6f78af 620 PR("MPDUs XRetried: ", xretries);
fec247c0 621 PR("Aggregates: ", a_aggr);
bda8adda
BG
622 PR("AMPDUs Queued HW:", a_queued_hw);
623 PR("AMPDUs Queued SW:", a_queued_sw);
fec247c0
S
624 PR("AMPDUs Completed:", a_completed);
625 PR("AMPDUs Retried: ", a_retries);
626 PR("AMPDUs XRetried: ", a_xretries);
4d900389 627 PR("TXERR Filtered: ", txerr_filtered);
fec247c0
S
628 PR("FIFO Underrun: ", fifo_underrun);
629 PR("TXOP Exceeded: ", xtxop);
630 PR("TXTIMER Expiry: ", timer_exp);
631 PR("DESC CFG Error: ", desc_cfg_err);
632 PR("DATA Underrun: ", data_underrun);
633 PR("DELIM Underrun: ", delim_underrun);
99c15bf5
BG
634 PR("TX-Pkts-All: ", tx_pkts_all);
635 PR("TX-Bytes-All: ", tx_bytes_all);
78ef731c
SM
636 PR("HW-put-tx-buf: ", puttxbuf);
637 PR("HW-tx-start: ", txstart);
638 PR("HW-tx-proc-desc: ", txprocdesc);
a5a0bca1 639 PR("TX-Failed: ", txfailed);
71e025a5 640
7f010c93
BG
641 if (len > size)
642 len = size;
643
644 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
645 kfree(buf);
646
647 return retval;
648}
649
18fcf1c6
FF
650static ssize_t print_queue(struct ath_softc *sc, struct ath_txq *txq,
651 char *buf, ssize_t size)
652{
653 ssize_t len = 0;
654
655 ath_txq_lock(sc, txq);
656
5e88ba62
ZK
657 len += scnprintf(buf + len, size - len, "%s: %d ",
658 "qnum", txq->axq_qnum);
659 len += scnprintf(buf + len, size - len, "%s: %2d ",
660 "qdepth", txq->axq_depth);
661 len += scnprintf(buf + len, size - len, "%s: %2d ",
662 "ampdu-depth", txq->axq_ampdu_depth);
663 len += scnprintf(buf + len, size - len, "%s: %3d ",
664 "pending", txq->pending_frames);
665 len += scnprintf(buf + len, size - len, "%s: %d\n",
666 "stopped", txq->stopped);
18fcf1c6
FF
667
668 ath_txq_unlock(sc, txq);
669 return len;
670}
671
c0b74876
SM
672static ssize_t read_file_queues(struct file *file, char __user *user_buf,
673 size_t count, loff_t *ppos)
674{
675 struct ath_softc *sc = file->private_data;
676 struct ath_txq *txq;
677 char *buf;
678 unsigned int len = 0, size = 1024;
679 ssize_t retval = 0;
680 int i;
681 char *qname[4] = {"VO", "VI", "BE", "BK"};
682
683 buf = kzalloc(size, GFP_KERNEL);
684 if (buf == NULL)
685 return -ENOMEM;
686
687 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
688 txq = sc->tx.txq_map[i];
5e88ba62 689 len += scnprintf(buf + len, size - len, "(%s): ", qname[i]);
18fcf1c6 690 len += print_queue(sc, txq, buf + len, size - len);
c0b74876
SM
691 }
692
5e88ba62 693 len += scnprintf(buf + len, size - len, "(CAB): ");
18fcf1c6
FF
694 len += print_queue(sc, sc->beacon.cabq, buf + len, size - len);
695
c0b74876
SM
696 if (len > size)
697 len = size;
698
699 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
700 kfree(buf);
701
702 return retval;
703}
704
55f6d0ff
BG
705static ssize_t read_file_misc(struct file *file, char __user *user_buf,
706 size_t count, loff_t *ppos)
707{
708 struct ath_softc *sc = file->private_data;
709 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
55f6d0ff 710 struct ieee80211_hw *hw = sc->hw;
6bcf6f64
SM
711 struct ath9k_vif_iter_data iter_data;
712 char buf[512];
713 unsigned int len = 0;
55f6d0ff 714 ssize_t retval = 0;
55f6d0ff 715 unsigned int reg;
6bcf6f64 716 u32 rxfilter;
55f6d0ff 717
5e88ba62
ZK
718 len += scnprintf(buf + len, sizeof(buf) - len,
719 "BSSID: %pM\n", common->curbssid);
720 len += scnprintf(buf + len, sizeof(buf) - len,
721 "BSSID-MASK: %pM\n", common->bssidmask);
722 len += scnprintf(buf + len, sizeof(buf) - len,
723 "OPMODE: %s\n",
724 ath_opmode_to_string(sc->sc_ah->opmode));
55f6d0ff 725
79d2b157 726 ath9k_ps_wakeup(sc);
6bcf6f64 727 rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
79d2b157 728 ath9k_ps_restore(sc);
6bcf6f64 729
5e88ba62
ZK
730 len += scnprintf(buf + len, sizeof(buf) - len,
731 "RXFILTER: 0x%x", rxfilter);
6bcf6f64
SM
732
733 if (rxfilter & ATH9K_RX_FILTER_UCAST)
5e88ba62 734 len += scnprintf(buf + len, sizeof(buf) - len, " UCAST");
6bcf6f64 735 if (rxfilter & ATH9K_RX_FILTER_MCAST)
5e88ba62 736 len += scnprintf(buf + len, sizeof(buf) - len, " MCAST");
6bcf6f64 737 if (rxfilter & ATH9K_RX_FILTER_BCAST)
5e88ba62 738 len += scnprintf(buf + len, sizeof(buf) - len, " BCAST");
6bcf6f64 739 if (rxfilter & ATH9K_RX_FILTER_CONTROL)
5e88ba62 740 len += scnprintf(buf + len, sizeof(buf) - len, " CONTROL");
6bcf6f64 741 if (rxfilter & ATH9K_RX_FILTER_BEACON)
5e88ba62 742 len += scnprintf(buf + len, sizeof(buf) - len, " BEACON");
6bcf6f64 743 if (rxfilter & ATH9K_RX_FILTER_PROM)
5e88ba62 744 len += scnprintf(buf + len, sizeof(buf) - len, " PROM");
6bcf6f64 745 if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
5e88ba62 746 len += scnprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
6bcf6f64 747 if (rxfilter & ATH9K_RX_FILTER_PHYERR)
5e88ba62 748 len += scnprintf(buf + len, sizeof(buf) - len, " PHYERR");
6bcf6f64 749 if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
5e88ba62 750 len += scnprintf(buf + len, sizeof(buf) - len, " MYBEACON");
6bcf6f64 751 if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
5e88ba62 752 len += scnprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
6bcf6f64 753 if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
5e88ba62 754 len += scnprintf(buf + len, sizeof(buf) - len, " PSPOLL");
6bcf6f64 755 if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
5e88ba62 756 len += scnprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
6bcf6f64 757 if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
5e88ba62 758 len += scnprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL");
6bcf6f64 759 if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
5e88ba62 760 len += scnprintf(buf + len, sizeof(buf) - len, " CONTROL_WRAPPER");
6bcf6f64 761
5e88ba62 762 len += scnprintf(buf + len, sizeof(buf) - len, "\n");
55f6d0ff
BG
763
764 reg = sc->sc_ah->imask;
6bcf6f64 765
5e88ba62
ZK
766 len += scnprintf(buf + len, sizeof(buf) - len,
767 "INTERRUPT-MASK: 0x%x", reg);
6bcf6f64 768
55f6d0ff 769 if (reg & ATH9K_INT_SWBA)
5e88ba62 770 len += scnprintf(buf + len, sizeof(buf) - len, " SWBA");
55f6d0ff 771 if (reg & ATH9K_INT_BMISS)
5e88ba62 772 len += scnprintf(buf + len, sizeof(buf) - len, " BMISS");
55f6d0ff 773 if (reg & ATH9K_INT_CST)
5e88ba62 774 len += scnprintf(buf + len, sizeof(buf) - len, " CST");
55f6d0ff 775 if (reg & ATH9K_INT_RX)
5e88ba62 776 len += scnprintf(buf + len, sizeof(buf) - len, " RX");
55f6d0ff 777 if (reg & ATH9K_INT_RXHP)
5e88ba62 778 len += scnprintf(buf + len, sizeof(buf) - len, " RXHP");
55f6d0ff 779 if (reg & ATH9K_INT_RXLP)
5e88ba62 780 len += scnprintf(buf + len, sizeof(buf) - len, " RXLP");
55f6d0ff 781 if (reg & ATH9K_INT_BB_WATCHDOG)
5e88ba62 782 len += scnprintf(buf + len, sizeof(buf) - len, " BB_WATCHDOG");
55f6d0ff 783
5e88ba62 784 len += scnprintf(buf + len, sizeof(buf) - len, "\n");
6bcf6f64
SM
785
786 ath9k_calculate_iter_data(hw, NULL, &iter_data);
787
5e88ba62
ZK
788 len += scnprintf(buf + len, sizeof(buf) - len,
789 "VIF-COUNTS: AP: %i STA: %i MESH: %i WDS: %i"
790 " ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n",
791 iter_data.naps, iter_data.nstations, iter_data.nmeshes,
792 iter_data.nwds, iter_data.nadhocs,
793 sc->nvifs, sc->nbcnvifs);
55f6d0ff 794
6bcf6f64
SM
795 if (len > sizeof(buf))
796 len = sizeof(buf);
55f6d0ff
BG
797
798 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
55f6d0ff
BG
799 return retval;
800}
801
f8b815dc
SM
802static ssize_t read_file_reset(struct file *file, char __user *user_buf,
803 size_t count, loff_t *ppos)
804{
805 struct ath_softc *sc = file->private_data;
806 char buf[512];
807 unsigned int len = 0;
808
5e88ba62
ZK
809 len += scnprintf(buf + len, sizeof(buf) - len,
810 "%17s: %2d\n", "Baseband Hang",
811 sc->debug.stats.reset[RESET_TYPE_BB_HANG]);
812 len += scnprintf(buf + len, sizeof(buf) - len,
813 "%17s: %2d\n", "Baseband Watchdog",
814 sc->debug.stats.reset[RESET_TYPE_BB_WATCHDOG]);
815 len += scnprintf(buf + len, sizeof(buf) - len,
816 "%17s: %2d\n", "Fatal HW Error",
817 sc->debug.stats.reset[RESET_TYPE_FATAL_INT]);
818 len += scnprintf(buf + len, sizeof(buf) - len,
819 "%17s: %2d\n", "TX HW error",
820 sc->debug.stats.reset[RESET_TYPE_TX_ERROR]);
821 len += scnprintf(buf + len, sizeof(buf) - len,
822 "%17s: %2d\n", "TX Path Hang",
823 sc->debug.stats.reset[RESET_TYPE_TX_HANG]);
824 len += scnprintf(buf + len, sizeof(buf) - len,
825 "%17s: %2d\n", "PLL RX Hang",
826 sc->debug.stats.reset[RESET_TYPE_PLL_HANG]);
827 len += scnprintf(buf + len, sizeof(buf) - len,
828 "%17s: %2d\n", "MCI Reset",
829 sc->debug.stats.reset[RESET_TYPE_MCI]);
f8b815dc
SM
830
831 if (len > sizeof(buf))
832 len = sizeof(buf);
833
834 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
835}
836
066dae93 837void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
55797b1a
FF
838 struct ath_tx_status *ts, struct ath_txq *txq,
839 unsigned int flags)
fec247c0 840{
5bec3e5a 841 int qnum = txq->axq_qnum;
066dae93
FF
842
843 TX_STAT_INC(qnum, tx_pkts_all);
844 sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
99c15bf5 845
fec247c0 846 if (bf_isampdu(bf)) {
156369fa 847 if (flags & ATH_TX_ERROR)
066dae93 848 TX_STAT_INC(qnum, a_xretries);
fec247c0 849 else
066dae93 850 TX_STAT_INC(qnum, a_completed);
fec247c0 851 } else {
55797b1a 852 if (ts->ts_status & ATH9K_TXERR_XRETRY)
5a6f78af
FF
853 TX_STAT_INC(qnum, xretries);
854 else
855 TX_STAT_INC(qnum, completed);
fec247c0
S
856 }
857
4d900389
BG
858 if (ts->ts_status & ATH9K_TXERR_FILT)
859 TX_STAT_INC(qnum, txerr_filtered);
db1a052b 860 if (ts->ts_status & ATH9K_TXERR_FIFO)
066dae93 861 TX_STAT_INC(qnum, fifo_underrun);
db1a052b 862 if (ts->ts_status & ATH9K_TXERR_XTXOP)
066dae93 863 TX_STAT_INC(qnum, xtxop);
db1a052b 864 if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
066dae93 865 TX_STAT_INC(qnum, timer_exp);
db1a052b 866 if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
066dae93 867 TX_STAT_INC(qnum, desc_cfg_err);
db1a052b 868 if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
066dae93 869 TX_STAT_INC(qnum, data_underrun);
db1a052b 870 if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
066dae93 871 TX_STAT_INC(qnum, delim_underrun);
fec247c0
S
872}
873
874static const struct file_operations fops_xmit = {
875 .read = read_file_xmit,
234e3405 876 .open = simple_open,
6038f373
AB
877 .owner = THIS_MODULE,
878 .llseek = default_llseek,
fec247c0 879};
39d89cd3 880
c0b74876
SM
881static const struct file_operations fops_queues = {
882 .read = read_file_queues,
883 .open = simple_open,
884 .owner = THIS_MODULE,
885 .llseek = default_llseek,
886};
887
55f6d0ff
BG
888static const struct file_operations fops_misc = {
889 .read = read_file_misc,
234e3405 890 .open = simple_open,
55f6d0ff
BG
891 .owner = THIS_MODULE,
892 .llseek = default_llseek,
893};
894
f8b815dc
SM
895static const struct file_operations fops_reset = {
896 .read = read_file_reset,
234e3405 897 .open = simple_open,
f8b815dc
SM
898 .owner = THIS_MODULE,
899 .llseek = default_llseek,
900};
901
1395d3f0
S
902static ssize_t read_file_recv(struct file *file, char __user *user_buf,
903 size_t count, loff_t *ppos)
904{
905#define PHY_ERR(s, p) \
5e88ba62
ZK
906 len += scnprintf(buf + len, size - len, "%22s : %10u\n", s, \
907 sc->debug.stats.rxstats.phy_err_stats[p]);
1395d3f0 908
24a0731e
BG
909#define RXS_ERR(s, e) \
910 do { \
5e88ba62
ZK
911 len += scnprintf(buf + len, size - len, \
912 "%22s : %10u\n", s, \
913 sc->debug.stats.rxstats.e);\
24a0731e
BG
914 } while (0)
915
1395d3f0
S
916 struct ath_softc *sc = file->private_data;
917 char *buf;
4203214e 918 unsigned int len = 0, size = 1600;
1395d3f0
S
919 ssize_t retval = 0;
920
921 buf = kzalloc(size, GFP_KERNEL);
922 if (buf == NULL)
04236066 923 return -ENOMEM;
1395d3f0 924
24a0731e
BG
925 RXS_ERR("CRC ERR", crc_err);
926 RXS_ERR("DECRYPT CRC ERR", decrypt_crc_err);
927 RXS_ERR("PHY ERR", phy_err);
928 RXS_ERR("MIC ERR", mic_err);
929 RXS_ERR("PRE-DELIM CRC ERR", pre_delim_crc_err);
930 RXS_ERR("POST-DELIM CRC ERR", post_delim_crc_err);
931 RXS_ERR("DECRYPT BUSY ERR", decrypt_busy_err);
932 RXS_ERR("RX-LENGTH-ERR", rx_len_err);
933 RXS_ERR("RX-OOM-ERR", rx_oom_err);
934 RXS_ERR("RX-RATE-ERR", rx_rate_err);
24a0731e 935 RXS_ERR("RX-TOO-MANY-FRAGS", rx_too_many_frags_err);
1395d3f0 936
4203214e
SM
937 PHY_ERR("UNDERRUN ERR", ATH9K_PHYERR_UNDERRUN);
938 PHY_ERR("TIMING ERR", ATH9K_PHYERR_TIMING);
939 PHY_ERR("PARITY ERR", ATH9K_PHYERR_PARITY);
940 PHY_ERR("RATE ERR", ATH9K_PHYERR_RATE);
941 PHY_ERR("LENGTH ERR", ATH9K_PHYERR_LENGTH);
942 PHY_ERR("RADAR ERR", ATH9K_PHYERR_RADAR);
943 PHY_ERR("SERVICE ERR", ATH9K_PHYERR_SERVICE);
944 PHY_ERR("TOR ERR", ATH9K_PHYERR_TOR);
945 PHY_ERR("OFDM-TIMING ERR", ATH9K_PHYERR_OFDM_TIMING);
946 PHY_ERR("OFDM-SIGNAL-PARITY ERR", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
947 PHY_ERR("OFDM-RATE ERR", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
948 PHY_ERR("OFDM-LENGTH ERR", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
949 PHY_ERR("OFDM-POWER-DROP ERR", ATH9K_PHYERR_OFDM_POWER_DROP);
950 PHY_ERR("OFDM-SERVICE ERR", ATH9K_PHYERR_OFDM_SERVICE);
951 PHY_ERR("OFDM-RESTART ERR", ATH9K_PHYERR_OFDM_RESTART);
952 PHY_ERR("FALSE-RADAR-EXT ERR", ATH9K_PHYERR_FALSE_RADAR_EXT);
953 PHY_ERR("CCK-TIMING ERR", ATH9K_PHYERR_CCK_TIMING);
954 PHY_ERR("CCK-HEADER-CRC ERR", ATH9K_PHYERR_CCK_HEADER_CRC);
955 PHY_ERR("CCK-RATE ERR", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
956 PHY_ERR("CCK-SERVICE ERR", ATH9K_PHYERR_CCK_SERVICE);
957 PHY_ERR("CCK-RESTART ERR", ATH9K_PHYERR_CCK_RESTART);
958 PHY_ERR("CCK-LENGTH ERR", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
959 PHY_ERR("CCK-POWER-DROP ERR", ATH9K_PHYERR_CCK_POWER_DROP);
960 PHY_ERR("HT-CRC ERR", ATH9K_PHYERR_HT_CRC_ERROR);
961 PHY_ERR("HT-LENGTH ERR", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
962 PHY_ERR("HT-RATE ERR", ATH9K_PHYERR_HT_RATE_ILLEGAL);
963
24a0731e
BG
964 RXS_ERR("RX-Pkts-All", rx_pkts_all);
965 RXS_ERR("RX-Bytes-All", rx_bytes_all);
966 RXS_ERR("RX-Beacons", rx_beacons);
967 RXS_ERR("RX-Frags", rx_frags);
9b99e665 968 RXS_ERR("RX-Spectral", rx_spectral);
99c15bf5 969
2b87f3aa
DC
970 if (len > size)
971 len = size;
972
1395d3f0
S
973 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
974 kfree(buf);
975
976 return retval;
977
24a0731e 978#undef RXS_ERR
1395d3f0
S
979#undef PHY_ERR
980}
981
8e6f5aa2 982void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
1395d3f0 983{
1395d3f0
S
984#define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
985
99c15bf5
BG
986 RX_STAT_INC(rx_pkts_all);
987 sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
988
8e6f5aa2 989 if (rs->rs_status & ATH9K_RXERR_CRC)
1395d3f0 990 RX_STAT_INC(crc_err);
8e6f5aa2 991 if (rs->rs_status & ATH9K_RXERR_DECRYPT)
1395d3f0 992 RX_STAT_INC(decrypt_crc_err);
8e6f5aa2 993 if (rs->rs_status & ATH9K_RXERR_MIC)
1395d3f0 994 RX_STAT_INC(mic_err);
8e6f5aa2 995 if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
1395d3f0 996 RX_STAT_INC(pre_delim_crc_err);
8e6f5aa2 997 if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
1395d3f0 998 RX_STAT_INC(post_delim_crc_err);
8e6f5aa2 999 if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
1395d3f0
S
1000 RX_STAT_INC(decrypt_busy_err);
1001
8e6f5aa2 1002 if (rs->rs_status & ATH9K_RXERR_PHY) {
1395d3f0 1003 RX_STAT_INC(phy_err);
dbb07f00
SM
1004 if (rs->rs_phyerr < ATH9K_PHYERR_MAX)
1005 RX_PHY_ERR_INC(rs->rs_phyerr);
1395d3f0
S
1006 }
1007
1395d3f0
S
1008#undef RX_PHY_ERR_INC
1009}
1010
1011static const struct file_operations fops_recv = {
1012 .read = read_file_recv,
234e3405 1013 .open = simple_open,
6038f373
AB
1014 .owner = THIS_MODULE,
1015 .llseek = default_llseek,
1395d3f0
S
1016};
1017
9bff0bc4
FF
1018static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
1019 size_t count, loff_t *ppos)
1020{
1021 struct ath_softc *sc = file->private_data;
1022 char buf[32];
1023 unsigned int len;
1024
2b87f3aa 1025 len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
9bff0bc4
FF
1026 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1027}
1028
1029static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
1030 size_t count, loff_t *ppos)
1031{
1032 struct ath_softc *sc = file->private_data;
1033 unsigned long regidx;
1034 char buf[32];
1035 ssize_t len;
1036
1037 len = min(count, sizeof(buf) - 1);
1038 if (copy_from_user(buf, user_buf, len))
04236066 1039 return -EFAULT;
9bff0bc4
FF
1040
1041 buf[len] = '\0';
27d7f477 1042 if (kstrtoul(buf, 0, &regidx))
9bff0bc4
FF
1043 return -EINVAL;
1044
1045 sc->debug.regidx = regidx;
1046 return count;
1047}
1048
1049static const struct file_operations fops_regidx = {
1050 .read = read_file_regidx,
1051 .write = write_file_regidx,
234e3405 1052 .open = simple_open,
6038f373
AB
1053 .owner = THIS_MODULE,
1054 .llseek = default_llseek,
9bff0bc4
FF
1055};
1056
1057static ssize_t read_file_regval(struct file *file, char __user *user_buf,
1058 size_t count, loff_t *ppos)
1059{
1060 struct ath_softc *sc = file->private_data;
1061 struct ath_hw *ah = sc->sc_ah;
1062 char buf[32];
1063 unsigned int len;
1064 u32 regval;
1065
79d2b157 1066 ath9k_ps_wakeup(sc);
9bff0bc4 1067 regval = REG_READ_D(ah, sc->debug.regidx);
79d2b157 1068 ath9k_ps_restore(sc);
2b87f3aa 1069 len = sprintf(buf, "0x%08x\n", regval);
9bff0bc4
FF
1070 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1071}
1072
1073static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
1074 size_t count, loff_t *ppos)
1075{
1076 struct ath_softc *sc = file->private_data;
1077 struct ath_hw *ah = sc->sc_ah;
1078 unsigned long regval;
1079 char buf[32];
1080 ssize_t len;
1081
1082 len = min(count, sizeof(buf) - 1);
1083 if (copy_from_user(buf, user_buf, len))
04236066 1084 return -EFAULT;
9bff0bc4
FF
1085
1086 buf[len] = '\0';
27d7f477 1087 if (kstrtoul(buf, 0, &regval))
9bff0bc4
FF
1088 return -EINVAL;
1089
79d2b157 1090 ath9k_ps_wakeup(sc);
9bff0bc4 1091 REG_WRITE_D(ah, sc->debug.regidx, regval);
79d2b157 1092 ath9k_ps_restore(sc);
9bff0bc4
FF
1093 return count;
1094}
1095
1096static const struct file_operations fops_regval = {
1097 .read = read_file_regval,
1098 .write = write_file_regval,
234e3405 1099 .open = simple_open,
6038f373
AB
1100 .owner = THIS_MODULE,
1101 .llseek = default_llseek,
9bff0bc4
FF
1102};
1103
582d0064
VT
1104#define REGDUMP_LINE_SIZE 20
1105
1106static int open_file_regdump(struct inode *inode, struct file *file)
1107{
1108 struct ath_softc *sc = inode->i_private;
1109 unsigned int len = 0;
1110 u8 *buf;
1111 int i;
1112 unsigned long num_regs, regdump_len, max_reg_offset;
1113
1114 max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
1115 num_regs = max_reg_offset / 4 + 1;
1116 regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
1117 buf = vmalloc(regdump_len);
1118 if (!buf)
1119 return -ENOMEM;
1120
1121 ath9k_ps_wakeup(sc);
1122 for (i = 0; i < num_regs; i++)
1123 len += scnprintf(buf + len, regdump_len - len,
1124 "0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
1125 ath9k_ps_restore(sc);
1126
1127 file->private_data = buf;
1128
1129 return 0;
1130}
1131
1132static const struct file_operations fops_regdump = {
1133 .open = open_file_regdump,
1134 .read = ath9k_debugfs_read_buf,
1135 .release = ath9k_debugfs_release_buf,
1136 .owner = THIS_MODULE,
1137 .llseek = default_llseek,/* read accesses f_pos */
1138};
1139
d069a46b
RM
1140static ssize_t read_file_dump_nfcal(struct file *file, char __user *user_buf,
1141 size_t count, loff_t *ppos)
1142{
1143 struct ath_softc *sc = file->private_data;
1144 struct ath_hw *ah = sc->sc_ah;
1145 struct ath9k_nfcal_hist *h = sc->caldata.nfCalHist;
1146 struct ath_common *common = ath9k_hw_common(ah);
1147 struct ieee80211_conf *conf = &common->hw->conf;
1148 u32 len = 0, size = 1500;
1149 u32 i, j;
1150 ssize_t retval = 0;
1151 char *buf;
1152 u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1153 u8 nread;
1154
1155 buf = kzalloc(size, GFP_KERNEL);
1156 if (!buf)
1157 return -ENOMEM;
1158
5e88ba62
ZK
1159 len += scnprintf(buf + len, size - len,
1160 "Channel Noise Floor : %d\n", ah->noise);
1161 len += scnprintf(buf + len, size - len,
1162 "Chain | privNF | # Readings | NF Readings\n");
d069a46b
RM
1163 for (i = 0; i < NUM_NF_READINGS; i++) {
1164 if (!(chainmask & (1 << i)) ||
1165 ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1166 continue;
1167
1168 nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
5e88ba62
ZK
1169 len += scnprintf(buf + len, size - len, " %d\t %d\t %d\t\t",
1170 i, h[i].privNF, nread);
d069a46b 1171 for (j = 0; j < nread; j++)
5e88ba62
ZK
1172 len += scnprintf(buf + len, size - len,
1173 " %d", h[i].nfCalBuffer[j]);
1174 len += scnprintf(buf + len, size - len, "\n");
d069a46b
RM
1175 }
1176
1177 if (len > size)
1178 len = size;
1179
1180 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1181 kfree(buf);
1182
1183 return retval;
1184}
1185
1186static const struct file_operations fops_dump_nfcal = {
1187 .read = read_file_dump_nfcal,
234e3405 1188 .open = simple_open,
d069a46b
RM
1189 .owner = THIS_MODULE,
1190 .llseek = default_llseek,
1191};
1192
580f010f
RM
1193static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf,
1194 size_t count, loff_t *ppos)
1195{
1196 struct ath_softc *sc = file->private_data;
1197 struct ath_hw *ah = sc->sc_ah;
1198 u32 len = 0, size = 1500;
1199 ssize_t retval = 0;
1200 char *buf;
1201
1202 buf = kzalloc(size, GFP_KERNEL);
1203 if (!buf)
1204 return -ENOMEM;
1205
1206 len = ah->eep_ops->dump_eeprom(ah, true, buf, len, size);
1207
1208 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1209 kfree(buf);
1210
1211 return retval;
1212}
1213
1214static const struct file_operations fops_base_eeprom = {
1215 .read = read_file_base_eeprom,
234e3405 1216 .open = simple_open,
580f010f
RM
1217 .owner = THIS_MODULE,
1218 .llseek = default_llseek,
1219};
1220
3f4c4bdd
RM
1221static ssize_t read_file_modal_eeprom(struct file *file, char __user *user_buf,
1222 size_t count, loff_t *ppos)
1223{
1224 struct ath_softc *sc = file->private_data;
1225 struct ath_hw *ah = sc->sc_ah;
1226 u32 len = 0, size = 6000;
1227 char *buf;
1228 size_t retval;
1229
1230 buf = kzalloc(size, GFP_KERNEL);
1231 if (buf == NULL)
1232 return -ENOMEM;
1233
1234 len = ah->eep_ops->dump_eeprom(ah, false, buf, len, size);
1235
1236 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1237 kfree(buf);
1238
1239 return retval;
1240}
1241
1242static const struct file_operations fops_modal_eeprom = {
1243 .read = read_file_modal_eeprom,
234e3405 1244 .open = simple_open,
3f4c4bdd
RM
1245 .owner = THIS_MODULE,
1246 .llseek = default_llseek,
1247};
1248
4df50ca8
RM
1249#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
1250static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
1251 size_t count, loff_t *ppos)
1252{
1253 struct ath_softc *sc = file->private_data;
1254 u32 len = 0, size = 1500;
1255 char *buf;
1256 size_t retval;
1257
1258 buf = kzalloc(size, GFP_KERNEL);
1259 if (buf == NULL)
1260 return -ENOMEM;
1261
ac46ba43 1262 if (!sc->sc_ah->common.btcoex_enabled) {
5e88ba62
ZK
1263 len = scnprintf(buf, size, "%s\n",
1264 "BTCOEX is disabled");
ac46ba43
SM
1265 goto exit;
1266 }
4df50ca8 1267
ac46ba43
SM
1268 len = ath9k_dump_btcoex(sc, buf, size);
1269exit:
4df50ca8
RM
1270 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1271 kfree(buf);
1272
1273 return retval;
1274}
1275
1276static const struct file_operations fops_btcoex = {
1277 .read = read_file_btcoex,
1278 .open = simple_open,
1279 .owner = THIS_MODULE,
1280 .llseek = default_llseek,
1281};
1282#endif
1283
a145daf7
SM
1284static ssize_t read_file_node_stat(struct file *file, char __user *user_buf,
1285 size_t count, loff_t *ppos)
1286{
1287 struct ath_node *an = file->private_data;
1288 struct ath_softc *sc = an->sc;
1289 struct ath_atx_tid *tid;
1290 struct ath_atx_ac *ac;
1291 struct ath_txq *txq;
1292 u32 len = 0, size = 4096;
1293 char *buf;
1294 size_t retval;
1295 int tidno, acno;
1296
1297 buf = kzalloc(size, GFP_KERNEL);
1298 if (buf == NULL)
1299 return -ENOMEM;
1300
1301 if (!an->sta->ht_cap.ht_supported) {
5e88ba62
ZK
1302 len = scnprintf(buf, size, "%s\n",
1303 "HT not supported");
a145daf7
SM
1304 goto exit;
1305 }
1306
5e88ba62
ZK
1307 len = scnprintf(buf, size, "Max-AMPDU: %d\n",
1308 an->maxampdu);
1309 len += scnprintf(buf + len, size - len, "MPDU Density: %d\n\n",
1310 an->mpdudensity);
a145daf7 1311
5e88ba62
ZK
1312 len += scnprintf(buf + len, size - len,
1313 "%2s%7s\n", "AC", "SCHED");
a145daf7
SM
1314
1315 for (acno = 0, ac = &an->ac[acno];
1316 acno < IEEE80211_NUM_ACS; acno++, ac++) {
1317 txq = ac->txq;
1318 ath_txq_lock(sc, txq);
5e88ba62
ZK
1319 len += scnprintf(buf + len, size - len,
1320 "%2d%7d\n",
1321 acno, ac->sched);
a145daf7
SM
1322 ath_txq_unlock(sc, txq);
1323 }
1324
5e88ba62
ZK
1325 len += scnprintf(buf + len, size - len,
1326 "\n%3s%11s%10s%10s%10s%10s%9s%6s%8s\n",
1327 "TID", "SEQ_START", "SEQ_NEXT", "BAW_SIZE",
1328 "BAW_HEAD", "BAW_TAIL", "BAR_IDX", "SCHED", "PAUSED");
a145daf7
SM
1329
1330 for (tidno = 0, tid = &an->tid[tidno];
1331 tidno < IEEE80211_NUM_TIDS; tidno++, tid++) {
1332 txq = tid->ac->txq;
1333 ath_txq_lock(sc, txq);
5e88ba62
ZK
1334 len += scnprintf(buf + len, size - len,
1335 "%3d%11d%10d%10d%10d%10d%9d%6d%8d\n",
1336 tid->tidno, tid->seq_start, tid->seq_next,
1337 tid->baw_size, tid->baw_head, tid->baw_tail,
1338 tid->bar_index, tid->sched, tid->paused);
a145daf7
SM
1339 ath_txq_unlock(sc, txq);
1340 }
1341exit:
1342 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1343 kfree(buf);
1344
1345 return retval;
1346}
1347
1348static const struct file_operations fops_node_stat = {
1349 .read = read_file_node_stat,
1350 .open = simple_open,
1351 .owner = THIS_MODULE,
1352 .llseek = default_llseek,
1353};
1354
1355void ath9k_sta_add_debugfs(struct ieee80211_hw *hw,
1356 struct ieee80211_vif *vif,
1357 struct ieee80211_sta *sta,
1358 struct dentry *dir)
1359{
1360 struct ath_node *an = (struct ath_node *)sta->drv_priv;
f5bde5b8 1361 debugfs_create_file("node_stat", S_IRUGO, dir, an, &fops_node_stat);
a145daf7
SM
1362}
1363
c175db87
SM
1364/* Ethtool support for get-stats */
1365
1366#define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1367static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1368 "tx_pkts_nic",
1369 "tx_bytes_nic",
1370 "rx_pkts_nic",
1371 "rx_bytes_nic",
1372 AMKSTR(d_tx_pkts),
1373 AMKSTR(d_tx_bytes),
1374 AMKSTR(d_tx_mpdus_queued),
1375 AMKSTR(d_tx_mpdus_completed),
1376 AMKSTR(d_tx_mpdu_xretries),
1377 AMKSTR(d_tx_aggregates),
1378 AMKSTR(d_tx_ampdus_queued_hw),
1379 AMKSTR(d_tx_ampdus_queued_sw),
1380 AMKSTR(d_tx_ampdus_completed),
1381 AMKSTR(d_tx_ampdu_retries),
1382 AMKSTR(d_tx_ampdu_xretries),
1383 AMKSTR(d_tx_fifo_underrun),
1384 AMKSTR(d_tx_op_exceeded),
1385 AMKSTR(d_tx_timer_expiry),
1386 AMKSTR(d_tx_desc_cfg_err),
1387 AMKSTR(d_tx_data_underrun),
1388 AMKSTR(d_tx_delim_underrun),
18c45b10 1389 "d_rx_crc_err",
c175db87
SM
1390 "d_rx_decrypt_crc_err",
1391 "d_rx_phy_err",
1392 "d_rx_mic_err",
1393 "d_rx_pre_delim_crc_err",
1394 "d_rx_post_delim_crc_err",
1395 "d_rx_decrypt_busy_err",
1396
1397 "d_rx_phyerr_radar",
1398 "d_rx_phyerr_ofdm_timing",
1399 "d_rx_phyerr_cck_timing",
1400
1401};
1402#define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1403
1404void ath9k_get_et_strings(struct ieee80211_hw *hw,
1405 struct ieee80211_vif *vif,
1406 u32 sset, u8 *data)
1407{
1408 if (sset == ETH_SS_STATS)
1409 memcpy(data, *ath9k_gstrings_stats,
1410 sizeof(ath9k_gstrings_stats));
1411}
1412
1413int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
1414 struct ieee80211_vif *vif, int sset)
1415{
1416 if (sset == ETH_SS_STATS)
1417 return ATH9K_SSTATS_LEN;
1418 return 0;
1419}
1420
1421#define AWDATA(elem) \
1422 do { \
1423 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
1424 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
1425 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
1426 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
1427 } while (0)
1428
1429#define AWDATA_RX(elem) \
1430 do { \
1431 data[i++] = sc->debug.stats.rxstats.elem; \
1432 } while (0)
1433
1434void ath9k_get_et_stats(struct ieee80211_hw *hw,
1435 struct ieee80211_vif *vif,
1436 struct ethtool_stats *stats, u64 *data)
1437{
1438 struct ath_softc *sc = hw->priv;
1439 int i = 0;
1440
1441 data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
1442 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
1443 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
1444 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
1445 data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
1446 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
1447 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
1448 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
1449 AWDATA_RX(rx_pkts_all);
1450 AWDATA_RX(rx_bytes_all);
1451
1452 AWDATA(tx_pkts_all);
1453 AWDATA(tx_bytes_all);
1454 AWDATA(queued);
1455 AWDATA(completed);
1456 AWDATA(xretries);
1457 AWDATA(a_aggr);
1458 AWDATA(a_queued_hw);
1459 AWDATA(a_queued_sw);
1460 AWDATA(a_completed);
1461 AWDATA(a_retries);
1462 AWDATA(a_xretries);
1463 AWDATA(fifo_underrun);
1464 AWDATA(xtxop);
1465 AWDATA(timer_exp);
1466 AWDATA(desc_cfg_err);
1467 AWDATA(data_underrun);
1468 AWDATA(delim_underrun);
1469
18c45b10 1470 AWDATA_RX(crc_err);
c175db87
SM
1471 AWDATA_RX(decrypt_crc_err);
1472 AWDATA_RX(phy_err);
1473 AWDATA_RX(mic_err);
1474 AWDATA_RX(pre_delim_crc_err);
1475 AWDATA_RX(post_delim_crc_err);
1476 AWDATA_RX(decrypt_busy_err);
1477
1478 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
1479 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
1480 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
1481
1482 WARN_ON(i != ATH9K_SSTATS_LEN);
1483}
1484
af690092
SM
1485void ath9k_deinit_debug(struct ath_softc *sc)
1486{
f65c0825 1487 ath9k_spectral_deinit_debug(sc);
af690092
SM
1488}
1489
4d6b228d 1490int ath9k_init_debug(struct ath_hw *ah)
88b126af 1491{
bc974f4a
LR
1492 struct ath_common *common = ath9k_hw_common(ah);
1493 struct ath_softc *sc = (struct ath_softc *) common->priv;
4d6b228d 1494
eb272441
BG
1495 sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1496 sc->hw->wiphy->debugfsdir);
17d7904d 1497 if (!sc->debug.debugfs_phy)
c8a72c00 1498 return -ENOMEM;
826d2680 1499
a830df07 1500#ifdef CONFIG_ATH_DEBUG
c70cab1a
FF
1501 debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1502 sc, &fops_debug);
a830df07 1503#endif
29942bc1
ZK
1504
1505 ath9k_dfs_init_debug(sc);
ef6b19e4 1506 ath9k_tx99_init_debug(sc);
f65c0825 1507 ath9k_spectral_init_debug(sc);
29942bc1 1508
c70cab1a
FF
1509 debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
1510 &fops_dma);
1511 debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
1512 &fops_interrupt);
c70cab1a
FF
1513 debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc,
1514 &fops_xmit);
c0b74876
SM
1515 debugfs_create_file("queues", S_IRUSR, sc->debug.debugfs_phy, sc,
1516 &fops_queues);
7702e788 1517 debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
bea843c7 1518 &sc->tx.txq_max_pending[IEEE80211_AC_BK]);
7702e788 1519 debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
bea843c7 1520 &sc->tx.txq_max_pending[IEEE80211_AC_BE]);
7702e788 1521 debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
bea843c7 1522 &sc->tx.txq_max_pending[IEEE80211_AC_VI]);
7702e788 1523 debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
bea843c7 1524 &sc->tx.txq_max_pending[IEEE80211_AC_VO]);
c70cab1a
FF
1525 debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy, sc,
1526 &fops_misc);
f8b815dc
SM
1527 debugfs_create_file("reset", S_IRUSR, sc->debug.debugfs_phy, sc,
1528 &fops_reset);
c70cab1a
FF
1529 debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy, sc,
1530 &fops_recv);
ca6d4a74
FF
1531 debugfs_create_u8("rx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
1532 &ah->rxchainmask);
1533 debugfs_create_u8("tx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
1534 &ah->txchainmask);
6e4d291e
SM
1535 debugfs_create_file("ani", S_IRUSR | S_IWUSR,
1536 sc->debug.debugfs_phy, sc, &fops_ani);
74673db9
FF
1537 debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1538 &sc->sc_ah->config.enable_paprd);
c70cab1a
FF
1539 debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1540 sc, &fops_regidx);
1541 debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1542 sc, &fops_regval);
1543 debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1544 sc->debug.debugfs_phy,
1545 &ah->config.cwm_ignore_extcca);
1546 debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
1547 &fops_regdump);
d069a46b
RM
1548 debugfs_create_file("dump_nfcal", S_IRUSR, sc->debug.debugfs_phy, sc,
1549 &fops_dump_nfcal);
580f010f
RM
1550 debugfs_create_file("base_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
1551 &fops_base_eeprom);
3f4c4bdd
RM
1552 debugfs_create_file("modal_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
1553 &fops_modal_eeprom);
691680b8
FF
1554 debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
1555 sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
691680b8
FF
1556 debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
1557 sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
4eba10cc
SM
1558 debugfs_create_file("antenna_diversity", S_IRUSR,
1559 sc->debug.debugfs_phy, sc, &fops_antenna_diversity);
4df50ca8 1560#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
36e8825e
SM
1561 debugfs_create_file("bt_ant_diversity", S_IRUSR | S_IWUSR,
1562 sc->debug.debugfs_phy, sc, &fops_bt_ant_diversity);
4df50ca8
RM
1563 debugfs_create_file("btcoex", S_IRUSR, sc->debug.debugfs_phy, sc,
1564 &fops_btcoex);
1565#endif
89f927af 1566
826d2680 1567 return 0;
88b126af 1568}