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