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