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