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