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