Loading...
1/*
2 * Copyright (c) 2008-2011 Atheros Communications Inc.
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
17#include <linux/slab.h>
18#include <linux/vmalloc.h>
19#include <asm/unaligned.h>
20
21#include "ath9k.h"
22
23#define REG_WRITE_D(_ah, _reg, _val) \
24 ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg))
25#define REG_READ_D(_ah, _reg) \
26 ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
27
28static int ath9k_debugfs_open(struct inode *inode, struct file *file)
29{
30 file->private_data = inode->i_private;
31 return 0;
32}
33
34static ssize_t ath9k_debugfs_read_buf(struct file *file, char __user *user_buf,
35 size_t count, loff_t *ppos)
36{
37 u8 *buf = file->private_data;
38 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
39}
40
41static int ath9k_debugfs_release_buf(struct inode *inode, struct file *file)
42{
43 vfree(file->private_data);
44 return 0;
45}
46
47#ifdef CONFIG_ATH_DEBUG
48
49static ssize_t read_file_debug(struct file *file, char __user *user_buf,
50 size_t count, loff_t *ppos)
51{
52 struct ath_softc *sc = file->private_data;
53 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
54 char buf[32];
55 unsigned int len;
56
57 len = sprintf(buf, "0x%08x\n", common->debug_mask);
58 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
59}
60
61static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
62 size_t count, loff_t *ppos)
63{
64 struct ath_softc *sc = file->private_data;
65 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
66 unsigned long mask;
67 char buf[32];
68 ssize_t len;
69
70 len = min(count, sizeof(buf) - 1);
71 if (copy_from_user(buf, user_buf, len))
72 return -EFAULT;
73
74 buf[len] = '\0';
75 if (strict_strtoul(buf, 0, &mask))
76 return -EINVAL;
77
78 common->debug_mask = mask;
79 return count;
80}
81
82static const struct file_operations fops_debug = {
83 .read = read_file_debug,
84 .write = write_file_debug,
85 .open = ath9k_debugfs_open,
86 .owner = THIS_MODULE,
87 .llseek = default_llseek,
88};
89
90#endif
91
92#define DMA_BUF_LEN 1024
93
94static ssize_t read_file_tx_chainmask(struct file *file, char __user *user_buf,
95 size_t count, loff_t *ppos)
96{
97 struct ath_softc *sc = file->private_data;
98 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
99 char buf[32];
100 unsigned int len;
101
102 len = sprintf(buf, "0x%08x\n", common->tx_chainmask);
103 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
104}
105
106static ssize_t write_file_tx_chainmask(struct file *file, const char __user *user_buf,
107 size_t count, loff_t *ppos)
108{
109 struct ath_softc *sc = file->private_data;
110 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
111 unsigned long mask;
112 char buf[32];
113 ssize_t len;
114
115 len = min(count, sizeof(buf) - 1);
116 if (copy_from_user(buf, user_buf, len))
117 return -EFAULT;
118
119 buf[len] = '\0';
120 if (strict_strtoul(buf, 0, &mask))
121 return -EINVAL;
122
123 common->tx_chainmask = mask;
124 sc->sc_ah->caps.tx_chainmask = mask;
125 return count;
126}
127
128static const struct file_operations fops_tx_chainmask = {
129 .read = read_file_tx_chainmask,
130 .write = write_file_tx_chainmask,
131 .open = ath9k_debugfs_open,
132 .owner = THIS_MODULE,
133 .llseek = default_llseek,
134};
135
136
137static ssize_t read_file_rx_chainmask(struct file *file, char __user *user_buf,
138 size_t count, loff_t *ppos)
139{
140 struct ath_softc *sc = file->private_data;
141 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
142 char buf[32];
143 unsigned int len;
144
145 len = sprintf(buf, "0x%08x\n", common->rx_chainmask);
146 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
147}
148
149static ssize_t write_file_rx_chainmask(struct file *file, 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 mask;
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 (strict_strtoul(buf, 0, &mask))
164 return -EINVAL;
165
166 common->rx_chainmask = mask;
167 sc->sc_ah->caps.rx_chainmask = mask;
168 return count;
169}
170
171static const struct file_operations fops_rx_chainmask = {
172 .read = read_file_rx_chainmask,
173 .write = write_file_rx_chainmask,
174 .open = ath9k_debugfs_open,
175 .owner = THIS_MODULE,
176 .llseek = default_llseek,
177};
178
179static ssize_t read_file_disable_ani(struct file *file, char __user *user_buf,
180 size_t count, loff_t *ppos)
181{
182 struct ath_softc *sc = file->private_data;
183 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
184 char buf[32];
185 unsigned int len;
186
187 len = sprintf(buf, "%d\n", common->disable_ani);
188 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
189}
190
191static ssize_t write_file_disable_ani(struct file *file,
192 const 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 unsigned long disable_ani;
198 char buf[32];
199 ssize_t len;
200
201 len = min(count, sizeof(buf) - 1);
202 if (copy_from_user(buf, user_buf, len))
203 return -EFAULT;
204
205 buf[len] = '\0';
206 if (strict_strtoul(buf, 0, &disable_ani))
207 return -EINVAL;
208
209 common->disable_ani = !!disable_ani;
210
211 if (disable_ani) {
212 sc->sc_flags &= ~SC_OP_ANI_RUN;
213 del_timer_sync(&common->ani.timer);
214 } else {
215 sc->sc_flags |= SC_OP_ANI_RUN;
216 ath_start_ani(common);
217 }
218
219 return count;
220}
221
222static const struct file_operations fops_disable_ani = {
223 .read = read_file_disable_ani,
224 .write = write_file_disable_ani,
225 .open = ath9k_debugfs_open,
226 .owner = THIS_MODULE,
227 .llseek = default_llseek,
228};
229
230static ssize_t read_file_dma(struct file *file, char __user *user_buf,
231 size_t count, loff_t *ppos)
232{
233 struct ath_softc *sc = file->private_data;
234 struct ath_hw *ah = sc->sc_ah;
235 char *buf;
236 int retval;
237 unsigned int len = 0;
238 u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
239 int i, qcuOffset = 0, dcuOffset = 0;
240 u32 *qcuBase = &val[0], *dcuBase = &val[4];
241
242 buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
243 if (!buf)
244 return -ENOMEM;
245
246 ath9k_ps_wakeup(sc);
247
248 REG_WRITE_D(ah, AR_MACMISC,
249 ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
250 (AR_MACMISC_MISC_OBS_BUS_1 <<
251 AR_MACMISC_MISC_OBS_BUS_MSB_S)));
252
253 len += snprintf(buf + len, DMA_BUF_LEN - len,
254 "Raw DMA Debug values:\n");
255
256 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
257 if (i % 4 == 0)
258 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
259
260 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
261 len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
262 i, val[i]);
263 }
264
265 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
266 len += snprintf(buf + len, DMA_BUF_LEN - len,
267 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
268
269 for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
270 if (i == 8) {
271 qcuOffset = 0;
272 qcuBase++;
273 }
274
275 if (i == 6) {
276 dcuOffset = 0;
277 dcuBase++;
278 }
279
280 len += snprintf(buf + len, DMA_BUF_LEN - len,
281 "%2d %2x %1x %2x %2x\n",
282 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
283 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
284 val[2] & (0x7 << (i * 3)) >> (i * 3),
285 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
286 }
287
288 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
289
290 len += snprintf(buf + len, DMA_BUF_LEN - len,
291 "qcu_stitch state: %2x qcu_fetch state: %2x\n",
292 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
293 len += snprintf(buf + len, DMA_BUF_LEN - len,
294 "qcu_complete state: %2x dcu_complete state: %2x\n",
295 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
296 len += snprintf(buf + len, DMA_BUF_LEN - len,
297 "dcu_arb state: %2x dcu_fp state: %2x\n",
298 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
299 len += snprintf(buf + len, DMA_BUF_LEN - len,
300 "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
301 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
302 len += snprintf(buf + len, DMA_BUF_LEN - len,
303 "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
304 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
305 len += snprintf(buf + len, DMA_BUF_LEN - len,
306 "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
307 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
308
309 len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
310 REG_READ_D(ah, AR_OBS_BUS_1));
311 len += snprintf(buf + len, DMA_BUF_LEN - len,
312 "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
313
314 ath9k_ps_restore(sc);
315
316 if (len > DMA_BUF_LEN)
317 len = DMA_BUF_LEN;
318
319 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
320 kfree(buf);
321 return retval;
322}
323
324static const struct file_operations fops_dma = {
325 .read = read_file_dma,
326 .open = ath9k_debugfs_open,
327 .owner = THIS_MODULE,
328 .llseek = default_llseek,
329};
330
331
332void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
333{
334 if (status)
335 sc->debug.stats.istats.total++;
336 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
337 if (status & ATH9K_INT_RXLP)
338 sc->debug.stats.istats.rxlp++;
339 if (status & ATH9K_INT_RXHP)
340 sc->debug.stats.istats.rxhp++;
341 if (status & ATH9K_INT_BB_WATCHDOG)
342 sc->debug.stats.istats.bb_watchdog++;
343 } else {
344 if (status & ATH9K_INT_RX)
345 sc->debug.stats.istats.rxok++;
346 }
347 if (status & ATH9K_INT_RXEOL)
348 sc->debug.stats.istats.rxeol++;
349 if (status & ATH9K_INT_RXORN)
350 sc->debug.stats.istats.rxorn++;
351 if (status & ATH9K_INT_TX)
352 sc->debug.stats.istats.txok++;
353 if (status & ATH9K_INT_TXURN)
354 sc->debug.stats.istats.txurn++;
355 if (status & ATH9K_INT_MIB)
356 sc->debug.stats.istats.mib++;
357 if (status & ATH9K_INT_RXPHY)
358 sc->debug.stats.istats.rxphyerr++;
359 if (status & ATH9K_INT_RXKCM)
360 sc->debug.stats.istats.rx_keycache_miss++;
361 if (status & ATH9K_INT_SWBA)
362 sc->debug.stats.istats.swba++;
363 if (status & ATH9K_INT_BMISS)
364 sc->debug.stats.istats.bmiss++;
365 if (status & ATH9K_INT_BNR)
366 sc->debug.stats.istats.bnr++;
367 if (status & ATH9K_INT_CST)
368 sc->debug.stats.istats.cst++;
369 if (status & ATH9K_INT_GTT)
370 sc->debug.stats.istats.gtt++;
371 if (status & ATH9K_INT_TIM)
372 sc->debug.stats.istats.tim++;
373 if (status & ATH9K_INT_CABEND)
374 sc->debug.stats.istats.cabend++;
375 if (status & ATH9K_INT_DTIMSYNC)
376 sc->debug.stats.istats.dtimsync++;
377 if (status & ATH9K_INT_DTIM)
378 sc->debug.stats.istats.dtim++;
379 if (status & ATH9K_INT_TSFOOR)
380 sc->debug.stats.istats.tsfoor++;
381}
382
383static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
384 size_t count, loff_t *ppos)
385{
386 struct ath_softc *sc = file->private_data;
387 char buf[512];
388 unsigned int len = 0;
389
390 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
391 len += snprintf(buf + len, sizeof(buf) - len,
392 "%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp);
393 len += snprintf(buf + len, sizeof(buf) - len,
394 "%8s: %10u\n", "RXHP", sc->debug.stats.istats.rxhp);
395 len += snprintf(buf + len, sizeof(buf) - len,
396 "%8s: %10u\n", "WATCHDOG",
397 sc->debug.stats.istats.bb_watchdog);
398 } else {
399 len += snprintf(buf + len, sizeof(buf) - len,
400 "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
401 }
402 len += snprintf(buf + len, sizeof(buf) - len,
403 "%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol);
404 len += snprintf(buf + len, sizeof(buf) - len,
405 "%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn);
406 len += snprintf(buf + len, sizeof(buf) - len,
407 "%8s: %10u\n", "TX", sc->debug.stats.istats.txok);
408 len += snprintf(buf + len, sizeof(buf) - len,
409 "%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn);
410 len += snprintf(buf + len, sizeof(buf) - len,
411 "%8s: %10u\n", "MIB", sc->debug.stats.istats.mib);
412 len += snprintf(buf + len, sizeof(buf) - len,
413 "%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr);
414 len += snprintf(buf + len, sizeof(buf) - len,
415 "%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss);
416 len += snprintf(buf + len, sizeof(buf) - len,
417 "%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba);
418 len += snprintf(buf + len, sizeof(buf) - len,
419 "%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss);
420 len += snprintf(buf + len, sizeof(buf) - len,
421 "%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr);
422 len += snprintf(buf + len, sizeof(buf) - len,
423 "%8s: %10u\n", "CST", sc->debug.stats.istats.cst);
424 len += snprintf(buf + len, sizeof(buf) - len,
425 "%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt);
426 len += snprintf(buf + len, sizeof(buf) - len,
427 "%8s: %10u\n", "TIM", sc->debug.stats.istats.tim);
428 len += snprintf(buf + len, sizeof(buf) - len,
429 "%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend);
430 len += snprintf(buf + len, sizeof(buf) - len,
431 "%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync);
432 len += snprintf(buf + len, sizeof(buf) - len,
433 "%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim);
434 len += snprintf(buf + len, sizeof(buf) - len,
435 "%8s: %10u\n", "TSFOOR", sc->debug.stats.istats.tsfoor);
436 len += snprintf(buf + len, sizeof(buf) - len,
437 "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total);
438
439
440 if (len > sizeof(buf))
441 len = sizeof(buf);
442
443 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
444}
445
446static const struct file_operations fops_interrupt = {
447 .read = read_file_interrupt,
448 .open = ath9k_debugfs_open,
449 .owner = THIS_MODULE,
450 .llseek = default_llseek,
451};
452
453static const char *channel_type_str(enum nl80211_channel_type t)
454{
455 switch (t) {
456 case NL80211_CHAN_NO_HT:
457 return "no ht";
458 case NL80211_CHAN_HT20:
459 return "ht20";
460 case NL80211_CHAN_HT40MINUS:
461 return "ht40-";
462 case NL80211_CHAN_HT40PLUS:
463 return "ht40+";
464 default:
465 return "???";
466 }
467}
468
469static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
470 size_t count, loff_t *ppos)
471{
472 struct ath_softc *sc = file->private_data;
473 struct ieee80211_channel *chan = sc->hw->conf.channel;
474 struct ieee80211_conf *conf = &(sc->hw->conf);
475 char buf[512];
476 unsigned int len = 0;
477 u8 addr[ETH_ALEN];
478 u32 tmp;
479
480 len += snprintf(buf + len, sizeof(buf) - len,
481 "%s (chan=%d center-freq: %d MHz channel-type: %d (%s))\n",
482 wiphy_name(sc->hw->wiphy),
483 ieee80211_frequency_to_channel(chan->center_freq),
484 chan->center_freq,
485 conf->channel_type,
486 channel_type_str(conf->channel_type));
487
488 ath9k_ps_wakeup(sc);
489 put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr);
490 put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
491 len += snprintf(buf + len, sizeof(buf) - len,
492 "addr: %pM\n", addr);
493 put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr);
494 put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
495 len += snprintf(buf + len, sizeof(buf) - len,
496 "addrmask: %pM\n", addr);
497 tmp = ath9k_hw_getrxfilter(sc->sc_ah);
498 ath9k_ps_restore(sc);
499 len += snprintf(buf + len, sizeof(buf) - len,
500 "rfilt: 0x%x", tmp);
501 if (tmp & ATH9K_RX_FILTER_UCAST)
502 len += snprintf(buf + len, sizeof(buf) - len, " UCAST");
503 if (tmp & ATH9K_RX_FILTER_MCAST)
504 len += snprintf(buf + len, sizeof(buf) - len, " MCAST");
505 if (tmp & ATH9K_RX_FILTER_BCAST)
506 len += snprintf(buf + len, sizeof(buf) - len, " BCAST");
507 if (tmp & ATH9K_RX_FILTER_CONTROL)
508 len += snprintf(buf + len, sizeof(buf) - len, " CONTROL");
509 if (tmp & ATH9K_RX_FILTER_BEACON)
510 len += snprintf(buf + len, sizeof(buf) - len, " BEACON");
511 if (tmp & ATH9K_RX_FILTER_PROM)
512 len += snprintf(buf + len, sizeof(buf) - len, " PROM");
513 if (tmp & ATH9K_RX_FILTER_PROBEREQ)
514 len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
515 if (tmp & ATH9K_RX_FILTER_PHYERR)
516 len += snprintf(buf + len, sizeof(buf) - len, " PHYERR");
517 if (tmp & ATH9K_RX_FILTER_MYBEACON)
518 len += snprintf(buf + len, sizeof(buf) - len, " MYBEACON");
519 if (tmp & ATH9K_RX_FILTER_COMP_BAR)
520 len += snprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
521 if (tmp & ATH9K_RX_FILTER_PSPOLL)
522 len += snprintf(buf + len, sizeof(buf) - len, " PSPOLL");
523 if (tmp & ATH9K_RX_FILTER_PHYRADAR)
524 len += snprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
525 if (tmp & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
526 len += snprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL\n");
527 else
528 len += snprintf(buf + len, sizeof(buf) - len, "\n");
529
530 if (len > sizeof(buf))
531 len = sizeof(buf);
532
533 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
534}
535
536static const struct file_operations fops_wiphy = {
537 .read = read_file_wiphy,
538 .open = ath9k_debugfs_open,
539 .owner = THIS_MODULE,
540 .llseek = default_llseek,
541};
542
543#define PR_QNUM(_n) sc->tx.txq_map[_n]->axq_qnum
544#define PR(str, elem) \
545 do { \
546 len += snprintf(buf + len, size - len, \
547 "%s%13u%11u%10u%10u\n", str, \
548 sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].elem, \
549 sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].elem, \
550 sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].elem, \
551 sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].elem); \
552 if (len >= size) \
553 goto done; \
554} while(0)
555
556#define PRX(str, elem) \
557do { \
558 len += snprintf(buf + len, size - len, \
559 "%s%13u%11u%10u%10u\n", str, \
560 (unsigned int)(sc->tx.txq_map[WME_AC_BE]->elem), \
561 (unsigned int)(sc->tx.txq_map[WME_AC_BK]->elem), \
562 (unsigned int)(sc->tx.txq_map[WME_AC_VI]->elem), \
563 (unsigned int)(sc->tx.txq_map[WME_AC_VO]->elem)); \
564 if (len >= size) \
565 goto done; \
566} while(0)
567
568#define PRQLE(str, elem) \
569do { \
570 len += snprintf(buf + len, size - len, \
571 "%s%13i%11i%10i%10i\n", str, \
572 list_empty(&sc->tx.txq_map[WME_AC_BE]->elem), \
573 list_empty(&sc->tx.txq_map[WME_AC_BK]->elem), \
574 list_empty(&sc->tx.txq_map[WME_AC_VI]->elem), \
575 list_empty(&sc->tx.txq_map[WME_AC_VO]->elem)); \
576 if (len >= size) \
577 goto done; \
578} while (0)
579
580static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
581 size_t count, loff_t *ppos)
582{
583 struct ath_softc *sc = file->private_data;
584 char *buf;
585 unsigned int len = 0, size = 8000;
586 int i;
587 ssize_t retval = 0;
588 char tmp[32];
589
590 buf = kzalloc(size, GFP_KERNEL);
591 if (buf == NULL)
592 return -ENOMEM;
593
594 len += sprintf(buf, "Num-Tx-Queues: %i tx-queues-setup: 0x%x"
595 " poll-work-seen: %u\n"
596 "%30s %10s%10s%10s\n\n",
597 ATH9K_NUM_TX_QUEUES, sc->tx.txqsetup,
598 sc->tx_complete_poll_work_seen,
599 "BE", "BK", "VI", "VO");
600
601 PR("MPDUs Queued: ", queued);
602 PR("MPDUs Completed: ", completed);
603 PR("MPDUs XRetried: ", xretries);
604 PR("Aggregates: ", a_aggr);
605 PR("AMPDUs Queued HW:", a_queued_hw);
606 PR("AMPDUs Queued SW:", a_queued_sw);
607 PR("AMPDUs Completed:", a_completed);
608 PR("AMPDUs Retried: ", a_retries);
609 PR("AMPDUs XRetried: ", a_xretries);
610 PR("FIFO Underrun: ", fifo_underrun);
611 PR("TXOP Exceeded: ", xtxop);
612 PR("TXTIMER Expiry: ", timer_exp);
613 PR("DESC CFG Error: ", desc_cfg_err);
614 PR("DATA Underrun: ", data_underrun);
615 PR("DELIM Underrun: ", delim_underrun);
616 PR("TX-Pkts-All: ", tx_pkts_all);
617 PR("TX-Bytes-All: ", tx_bytes_all);
618 PR("hw-put-tx-buf: ", puttxbuf);
619 PR("hw-tx-start: ", txstart);
620 PR("hw-tx-proc-desc: ", txprocdesc);
621 len += snprintf(buf + len, size - len,
622 "%s%11p%11p%10p%10p\n", "txq-memory-address:",
623 sc->tx.txq_map[WME_AC_BE],
624 sc->tx.txq_map[WME_AC_BK],
625 sc->tx.txq_map[WME_AC_VI],
626 sc->tx.txq_map[WME_AC_VO]);
627 if (len >= size)
628 goto done;
629
630 PRX("axq-qnum: ", axq_qnum);
631 PRX("axq-depth: ", axq_depth);
632 PRX("axq-ampdu_depth: ", axq_ampdu_depth);
633 PRX("axq-stopped ", stopped);
634 PRX("tx-in-progress ", axq_tx_inprogress);
635 PRX("pending-frames ", pending_frames);
636 PRX("txq_headidx: ", txq_headidx);
637 PRX("txq_tailidx: ", txq_headidx);
638
639 PRQLE("axq_q empty: ", axq_q);
640 PRQLE("axq_acq empty: ", axq_acq);
641 for (i = 0; i < ATH_TXFIFO_DEPTH; i++) {
642 snprintf(tmp, sizeof(tmp) - 1, "txq_fifo[%i] empty: ", i);
643 PRQLE(tmp, txq_fifo[i]);
644 }
645
646 /* Print out more detailed queue-info */
647 for (i = 0; i <= WME_AC_BK; i++) {
648 struct ath_txq *txq = &(sc->tx.txq[i]);
649 struct ath_atx_ac *ac;
650 struct ath_atx_tid *tid;
651 if (len >= size)
652 goto done;
653 spin_lock_bh(&txq->axq_lock);
654 if (!list_empty(&txq->axq_acq)) {
655 ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac,
656 list);
657 len += snprintf(buf + len, size - len,
658 "txq[%i] first-ac: %p sched: %i\n",
659 i, ac, ac->sched);
660 if (list_empty(&ac->tid_q) || (len >= size))
661 goto done_for;
662 tid = list_first_entry(&ac->tid_q, struct ath_atx_tid,
663 list);
664 len += snprintf(buf + len, size - len,
665 " first-tid: %p sched: %i paused: %i\n",
666 tid, tid->sched, tid->paused);
667 }
668 done_for:
669 spin_unlock_bh(&txq->axq_lock);
670 }
671
672done:
673 if (len > size)
674 len = size;
675
676 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
677 kfree(buf);
678
679 return retval;
680}
681
682static ssize_t read_file_stations(struct file *file, char __user *user_buf,
683 size_t count, loff_t *ppos)
684{
685 struct ath_softc *sc = file->private_data;
686 char *buf;
687 unsigned int len = 0, size = 64000;
688 struct ath_node *an = NULL;
689 ssize_t retval = 0;
690 int q;
691
692 buf = kzalloc(size, GFP_KERNEL);
693 if (buf == NULL)
694 return -ENOMEM;
695
696 len += snprintf(buf + len, size - len,
697 "Stations:\n"
698 " tid: addr sched paused buf_q-empty an ac\n"
699 " ac: addr sched tid_q-empty txq\n");
700
701 spin_lock(&sc->nodes_lock);
702 list_for_each_entry(an, &sc->nodes, list) {
703 len += snprintf(buf + len, size - len,
704 "%pM\n", an->sta->addr);
705 if (len >= size)
706 goto done;
707
708 for (q = 0; q < WME_NUM_TID; q++) {
709 struct ath_atx_tid *tid = &(an->tid[q]);
710 len += snprintf(buf + len, size - len,
711 " tid: %p %s %s %i %p %p\n",
712 tid, tid->sched ? "sched" : "idle",
713 tid->paused ? "paused" : "running",
714 list_empty(&tid->buf_q),
715 tid->an, tid->ac);
716 if (len >= size)
717 goto done;
718 }
719
720 for (q = 0; q < WME_NUM_AC; q++) {
721 struct ath_atx_ac *ac = &(an->ac[q]);
722 len += snprintf(buf + len, size - len,
723 " ac: %p %s %i %p\n",
724 ac, ac->sched ? "sched" : "idle",
725 list_empty(&ac->tid_q), ac->txq);
726 if (len >= size)
727 goto done;
728 }
729 }
730
731done:
732 spin_unlock(&sc->nodes_lock);
733 if (len > size)
734 len = size;
735
736 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
737 kfree(buf);
738
739 return retval;
740}
741
742static ssize_t read_file_misc(struct file *file, char __user *user_buf,
743 size_t count, loff_t *ppos)
744{
745 struct ath_softc *sc = file->private_data;
746 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
747 struct ath_hw *ah = sc->sc_ah;
748 struct ieee80211_hw *hw = sc->hw;
749 char *buf;
750 unsigned int len = 0, size = 8000;
751 ssize_t retval = 0;
752 unsigned int reg;
753 struct ath9k_vif_iter_data iter_data;
754
755 ath9k_calculate_iter_data(hw, NULL, &iter_data);
756
757 buf = kzalloc(size, GFP_KERNEL);
758 if (buf == NULL)
759 return -ENOMEM;
760
761 ath9k_ps_wakeup(sc);
762 len += snprintf(buf + len, size - len,
763 "curbssid: %pM\n"
764 "OP-Mode: %s(%i)\n"
765 "Beacon-Timer-Register: 0x%x\n",
766 common->curbssid,
767 ath_opmode_to_string(sc->sc_ah->opmode),
768 (int)(sc->sc_ah->opmode),
769 REG_READ(ah, AR_BEACON_PERIOD));
770
771 reg = REG_READ(ah, AR_TIMER_MODE);
772 ath9k_ps_restore(sc);
773 len += snprintf(buf + len, size - len, "Timer-Mode-Register: 0x%x (",
774 reg);
775 if (reg & AR_TBTT_TIMER_EN)
776 len += snprintf(buf + len, size - len, "TBTT ");
777 if (reg & AR_DBA_TIMER_EN)
778 len += snprintf(buf + len, size - len, "DBA ");
779 if (reg & AR_SWBA_TIMER_EN)
780 len += snprintf(buf + len, size - len, "SWBA ");
781 if (reg & AR_HCF_TIMER_EN)
782 len += snprintf(buf + len, size - len, "HCF ");
783 if (reg & AR_TIM_TIMER_EN)
784 len += snprintf(buf + len, size - len, "TIM ");
785 if (reg & AR_DTIM_TIMER_EN)
786 len += snprintf(buf + len, size - len, "DTIM ");
787 len += snprintf(buf + len, size - len, ")\n");
788
789 reg = sc->sc_ah->imask;
790 len += snprintf(buf + len, size - len, "imask: 0x%x (", reg);
791 if (reg & ATH9K_INT_SWBA)
792 len += snprintf(buf + len, size - len, "SWBA ");
793 if (reg & ATH9K_INT_BMISS)
794 len += snprintf(buf + len, size - len, "BMISS ");
795 if (reg & ATH9K_INT_CST)
796 len += snprintf(buf + len, size - len, "CST ");
797 if (reg & ATH9K_INT_RX)
798 len += snprintf(buf + len, size - len, "RX ");
799 if (reg & ATH9K_INT_RXHP)
800 len += snprintf(buf + len, size - len, "RXHP ");
801 if (reg & ATH9K_INT_RXLP)
802 len += snprintf(buf + len, size - len, "RXLP ");
803 if (reg & ATH9K_INT_BB_WATCHDOG)
804 len += snprintf(buf + len, size - len, "BB_WATCHDOG ");
805 /* there are other IRQs if one wanted to add them. */
806 len += snprintf(buf + len, size - len, ")\n");
807
808 len += snprintf(buf + len, size - len,
809 "VIF Counts: AP: %i STA: %i MESH: %i WDS: %i"
810 " ADHOC: %i OTHER: %i nvifs: %hi beacon-vifs: %hi\n",
811 iter_data.naps, iter_data.nstations, iter_data.nmeshes,
812 iter_data.nwds, iter_data.nadhocs, iter_data.nothers,
813 sc->nvifs, sc->nbcnvifs);
814
815 len += snprintf(buf + len, size - len,
816 "Calculated-BSSID-Mask: %pM\n",
817 iter_data.mask);
818
819 if (len > size)
820 len = size;
821
822 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
823 kfree(buf);
824
825 return retval;
826}
827
828void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
829 struct ath_tx_status *ts, struct ath_txq *txq)
830{
831 int qnum = txq->axq_qnum;
832
833 TX_STAT_INC(qnum, tx_pkts_all);
834 sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
835
836 if (bf_isampdu(bf)) {
837 if (bf_isxretried(bf))
838 TX_STAT_INC(qnum, a_xretries);
839 else
840 TX_STAT_INC(qnum, a_completed);
841 } else {
842 if (bf_isxretried(bf))
843 TX_STAT_INC(qnum, xretries);
844 else
845 TX_STAT_INC(qnum, completed);
846 }
847
848 if (ts->ts_status & ATH9K_TXERR_FIFO)
849 TX_STAT_INC(qnum, fifo_underrun);
850 if (ts->ts_status & ATH9K_TXERR_XTXOP)
851 TX_STAT_INC(qnum, xtxop);
852 if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
853 TX_STAT_INC(qnum, timer_exp);
854 if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
855 TX_STAT_INC(qnum, desc_cfg_err);
856 if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
857 TX_STAT_INC(qnum, data_underrun);
858 if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
859 TX_STAT_INC(qnum, delim_underrun);
860}
861
862static const struct file_operations fops_xmit = {
863 .read = read_file_xmit,
864 .open = ath9k_debugfs_open,
865 .owner = THIS_MODULE,
866 .llseek = default_llseek,
867};
868
869static const struct file_operations fops_stations = {
870 .read = read_file_stations,
871 .open = ath9k_debugfs_open,
872 .owner = THIS_MODULE,
873 .llseek = default_llseek,
874};
875
876static const struct file_operations fops_misc = {
877 .read = read_file_misc,
878 .open = ath9k_debugfs_open,
879 .owner = THIS_MODULE,
880 .llseek = default_llseek,
881};
882
883static ssize_t read_file_recv(struct file *file, char __user *user_buf,
884 size_t count, loff_t *ppos)
885{
886#define PHY_ERR(s, p) \
887 len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \
888 sc->debug.stats.rxstats.phy_err_stats[p]);
889
890 struct ath_softc *sc = file->private_data;
891 char *buf;
892 unsigned int len = 0, size = 1400;
893 ssize_t retval = 0;
894
895 buf = kzalloc(size, GFP_KERNEL);
896 if (buf == NULL)
897 return -ENOMEM;
898
899 len += snprintf(buf + len, size - len,
900 "%18s : %10u\n", "CRC ERR",
901 sc->debug.stats.rxstats.crc_err);
902 len += snprintf(buf + len, size - len,
903 "%18s : %10u\n", "DECRYPT CRC ERR",
904 sc->debug.stats.rxstats.decrypt_crc_err);
905 len += snprintf(buf + len, size - len,
906 "%18s : %10u\n", "PHY ERR",
907 sc->debug.stats.rxstats.phy_err);
908 len += snprintf(buf + len, size - len,
909 "%18s : %10u\n", "MIC ERR",
910 sc->debug.stats.rxstats.mic_err);
911 len += snprintf(buf + len, size - len,
912 "%18s : %10u\n", "PRE-DELIM CRC ERR",
913 sc->debug.stats.rxstats.pre_delim_crc_err);
914 len += snprintf(buf + len, size - len,
915 "%18s : %10u\n", "POST-DELIM CRC ERR",
916 sc->debug.stats.rxstats.post_delim_crc_err);
917 len += snprintf(buf + len, size - len,
918 "%18s : %10u\n", "DECRYPT BUSY ERR",
919 sc->debug.stats.rxstats.decrypt_busy_err);
920
921 len += snprintf(buf + len, size - len,
922 "%18s : %10d\n", "RSSI-CTL0",
923 sc->debug.stats.rxstats.rs_rssi_ctl0);
924
925 len += snprintf(buf + len, size - len,
926 "%18s : %10d\n", "RSSI-CTL1",
927 sc->debug.stats.rxstats.rs_rssi_ctl1);
928
929 len += snprintf(buf + len, size - len,
930 "%18s : %10d\n", "RSSI-CTL2",
931 sc->debug.stats.rxstats.rs_rssi_ctl2);
932
933 len += snprintf(buf + len, size - len,
934 "%18s : %10d\n", "RSSI-EXT0",
935 sc->debug.stats.rxstats.rs_rssi_ext0);
936
937 len += snprintf(buf + len, size - len,
938 "%18s : %10d\n", "RSSI-EXT1",
939 sc->debug.stats.rxstats.rs_rssi_ext1);
940
941 len += snprintf(buf + len, size - len,
942 "%18s : %10d\n", "RSSI-EXT2",
943 sc->debug.stats.rxstats.rs_rssi_ext2);
944
945 len += snprintf(buf + len, size - len,
946 "%18s : %10d\n", "Rx Antenna",
947 sc->debug.stats.rxstats.rs_antenna);
948
949 PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN);
950 PHY_ERR("TIMING", ATH9K_PHYERR_TIMING);
951 PHY_ERR("PARITY", ATH9K_PHYERR_PARITY);
952 PHY_ERR("RATE", ATH9K_PHYERR_RATE);
953 PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH);
954 PHY_ERR("RADAR", ATH9K_PHYERR_RADAR);
955 PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE);
956 PHY_ERR("TOR", ATH9K_PHYERR_TOR);
957 PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING);
958 PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
959 PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
960 PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
961 PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP);
962 PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE);
963 PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART);
964 PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT);
965 PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING);
966 PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC);
967 PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
968 PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE);
969 PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART);
970 PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
971 PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP);
972 PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR);
973 PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
974 PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL);
975
976 len += snprintf(buf + len, size - len,
977 "%18s : %10u\n", "RX-Pkts-All",
978 sc->debug.stats.rxstats.rx_pkts_all);
979 len += snprintf(buf + len, size - len,
980 "%18s : %10u\n", "RX-Bytes-All",
981 sc->debug.stats.rxstats.rx_bytes_all);
982
983 if (len > size)
984 len = size;
985
986 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
987 kfree(buf);
988
989 return retval;
990
991#undef PHY_ERR
992}
993
994void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
995{
996#define RX_STAT_INC(c) sc->debug.stats.rxstats.c++
997#define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
998
999 u32 phyerr;
1000
1001 RX_STAT_INC(rx_pkts_all);
1002 sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
1003
1004 if (rs->rs_status & ATH9K_RXERR_CRC)
1005 RX_STAT_INC(crc_err);
1006 if (rs->rs_status & ATH9K_RXERR_DECRYPT)
1007 RX_STAT_INC(decrypt_crc_err);
1008 if (rs->rs_status & ATH9K_RXERR_MIC)
1009 RX_STAT_INC(mic_err);
1010 if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
1011 RX_STAT_INC(pre_delim_crc_err);
1012 if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
1013 RX_STAT_INC(post_delim_crc_err);
1014 if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
1015 RX_STAT_INC(decrypt_busy_err);
1016
1017 if (rs->rs_status & ATH9K_RXERR_PHY) {
1018 RX_STAT_INC(phy_err);
1019 phyerr = rs->rs_phyerr & 0x24;
1020 RX_PHY_ERR_INC(phyerr);
1021 }
1022
1023 sc->debug.stats.rxstats.rs_rssi_ctl0 = rs->rs_rssi_ctl0;
1024 sc->debug.stats.rxstats.rs_rssi_ctl1 = rs->rs_rssi_ctl1;
1025 sc->debug.stats.rxstats.rs_rssi_ctl2 = rs->rs_rssi_ctl2;
1026
1027 sc->debug.stats.rxstats.rs_rssi_ext0 = rs->rs_rssi_ext0;
1028 sc->debug.stats.rxstats.rs_rssi_ext1 = rs->rs_rssi_ext1;
1029 sc->debug.stats.rxstats.rs_rssi_ext2 = rs->rs_rssi_ext2;
1030
1031 sc->debug.stats.rxstats.rs_antenna = rs->rs_antenna;
1032
1033#undef RX_STAT_INC
1034#undef RX_PHY_ERR_INC
1035}
1036
1037static const struct file_operations fops_recv = {
1038 .read = read_file_recv,
1039 .open = ath9k_debugfs_open,
1040 .owner = THIS_MODULE,
1041 .llseek = default_llseek,
1042};
1043
1044static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
1045 size_t count, loff_t *ppos)
1046{
1047 struct ath_softc *sc = file->private_data;
1048 char buf[32];
1049 unsigned int len;
1050
1051 len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
1052 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1053}
1054
1055static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
1056 size_t count, loff_t *ppos)
1057{
1058 struct ath_softc *sc = file->private_data;
1059 unsigned long regidx;
1060 char buf[32];
1061 ssize_t len;
1062
1063 len = min(count, sizeof(buf) - 1);
1064 if (copy_from_user(buf, user_buf, len))
1065 return -EFAULT;
1066
1067 buf[len] = '\0';
1068 if (strict_strtoul(buf, 0, ®idx))
1069 return -EINVAL;
1070
1071 sc->debug.regidx = regidx;
1072 return count;
1073}
1074
1075static const struct file_operations fops_regidx = {
1076 .read = read_file_regidx,
1077 .write = write_file_regidx,
1078 .open = ath9k_debugfs_open,
1079 .owner = THIS_MODULE,
1080 .llseek = default_llseek,
1081};
1082
1083static ssize_t read_file_regval(struct file *file, char __user *user_buf,
1084 size_t count, loff_t *ppos)
1085{
1086 struct ath_softc *sc = file->private_data;
1087 struct ath_hw *ah = sc->sc_ah;
1088 char buf[32];
1089 unsigned int len;
1090 u32 regval;
1091
1092 ath9k_ps_wakeup(sc);
1093 regval = REG_READ_D(ah, sc->debug.regidx);
1094 ath9k_ps_restore(sc);
1095 len = sprintf(buf, "0x%08x\n", regval);
1096 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1097}
1098
1099static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
1100 size_t count, loff_t *ppos)
1101{
1102 struct ath_softc *sc = file->private_data;
1103 struct ath_hw *ah = sc->sc_ah;
1104 unsigned long regval;
1105 char buf[32];
1106 ssize_t len;
1107
1108 len = min(count, sizeof(buf) - 1);
1109 if (copy_from_user(buf, user_buf, len))
1110 return -EFAULT;
1111
1112 buf[len] = '\0';
1113 if (strict_strtoul(buf, 0, ®val))
1114 return -EINVAL;
1115
1116 ath9k_ps_wakeup(sc);
1117 REG_WRITE_D(ah, sc->debug.regidx, regval);
1118 ath9k_ps_restore(sc);
1119 return count;
1120}
1121
1122static const struct file_operations fops_regval = {
1123 .read = read_file_regval,
1124 .write = write_file_regval,
1125 .open = ath9k_debugfs_open,
1126 .owner = THIS_MODULE,
1127 .llseek = default_llseek,
1128};
1129
1130#define REGDUMP_LINE_SIZE 20
1131
1132static int open_file_regdump(struct inode *inode, struct file *file)
1133{
1134 struct ath_softc *sc = inode->i_private;
1135 unsigned int len = 0;
1136 u8 *buf;
1137 int i;
1138 unsigned long num_regs, regdump_len, max_reg_offset;
1139
1140 max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
1141 num_regs = max_reg_offset / 4 + 1;
1142 regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
1143 buf = vmalloc(regdump_len);
1144 if (!buf)
1145 return -ENOMEM;
1146
1147 ath9k_ps_wakeup(sc);
1148 for (i = 0; i < num_regs; i++)
1149 len += scnprintf(buf + len, regdump_len - len,
1150 "0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
1151 ath9k_ps_restore(sc);
1152
1153 file->private_data = buf;
1154
1155 return 0;
1156}
1157
1158static const struct file_operations fops_regdump = {
1159 .open = open_file_regdump,
1160 .read = ath9k_debugfs_read_buf,
1161 .release = ath9k_debugfs_release_buf,
1162 .owner = THIS_MODULE,
1163 .llseek = default_llseek,/* read accesses f_pos */
1164};
1165
1166int ath9k_init_debug(struct ath_hw *ah)
1167{
1168 struct ath_common *common = ath9k_hw_common(ah);
1169 struct ath_softc *sc = (struct ath_softc *) common->priv;
1170
1171 sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1172 sc->hw->wiphy->debugfsdir);
1173 if (!sc->debug.debugfs_phy)
1174 return -ENOMEM;
1175
1176#ifdef CONFIG_ATH_DEBUG
1177 debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1178 sc, &fops_debug);
1179#endif
1180 debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
1181 &fops_dma);
1182 debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
1183 &fops_interrupt);
1184 debugfs_create_file("wiphy", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1185 sc, &fops_wiphy);
1186 debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc,
1187 &fops_xmit);
1188 debugfs_create_file("stations", S_IRUSR, sc->debug.debugfs_phy, sc,
1189 &fops_stations);
1190 debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy, sc,
1191 &fops_misc);
1192 debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy, sc,
1193 &fops_recv);
1194 debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
1195 sc->debug.debugfs_phy, sc, &fops_rx_chainmask);
1196 debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
1197 sc->debug.debugfs_phy, sc, &fops_tx_chainmask);
1198 debugfs_create_file("disable_ani", S_IRUSR | S_IWUSR,
1199 sc->debug.debugfs_phy, sc, &fops_disable_ani);
1200 debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1201 sc, &fops_regidx);
1202 debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1203 sc, &fops_regval);
1204 debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1205 sc->debug.debugfs_phy,
1206 &ah->config.cwm_ignore_extcca);
1207 debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
1208 &fops_regdump);
1209
1210 debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
1211 sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
1212
1213 debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
1214 sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
1215
1216 sc->debug.regidx = 0;
1217 return 0;
1218}
1/*
2 * Copyright (c) 2008-2011 Atheros Communications Inc.
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
17#include <linux/slab.h>
18#include <linux/vmalloc.h>
19#include <linux/export.h>
20#include <asm/unaligned.h>
21
22#include "ath9k.h"
23
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
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}
70
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
84#ifdef CONFIG_ATH_DEBUG
85
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;
90 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
91 char buf[32];
92 unsigned int len;
93
94 len = sprintf(buf, "0x%08x\n", common->debug_mask);
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;
102 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
103 unsigned long mask;
104 char buf[32];
105 ssize_t len;
106
107 len = min(count, sizeof(buf) - 1);
108 if (copy_from_user(buf, user_buf, len))
109 return -EFAULT;
110
111 buf[len] = '\0';
112 if (kstrtoul(buf, 0, &mask))
113 return -EINVAL;
114
115 common->debug_mask = mask;
116 return count;
117}
118
119static const struct file_operations fops_debug = {
120 .read = read_file_debug,
121 .write = write_file_debug,
122 .open = simple_open,
123 .owner = THIS_MODULE,
124 .llseek = default_llseek,
125};
126
127#endif
128
129#define DMA_BUF_LEN 1024
130
131
132static ssize_t read_file_ani(struct file *file, char __user *user_buf,
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);
137 struct ath_hw *ah = sc->sc_ah;
138 unsigned int len = 0;
139 const unsigned int size = 1024;
140 ssize_t retval = 0;
141 char *buf;
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 };
162
163 buf = kzalloc(size, GFP_KERNEL);
164 if (buf == NULL)
165 return -ENOMEM;
166
167 len += scnprintf(buf + len, size - len, "%15s: %s\n", "ANI",
168 common->disable_ani ? "DISABLED" : "ENABLED");
169
170 if (common->disable_ani)
171 goto exit;
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
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;
185}
186
187static ssize_t write_file_ani(struct file *file,
188 const char __user *user_buf,
189 size_t count, loff_t *ppos)
190{
191 struct ath_softc *sc = file->private_data;
192 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
193 unsigned long ani;
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';
202 if (kstrtoul(buf, 0, &ani))
203 return -EINVAL;
204
205 if (ani > 1)
206 return -EINVAL;
207
208 common->disable_ani = !ani;
209
210 if (common->disable_ani) {
211 clear_bit(ATH_OP_ANI_RUN, &common->op_flags);
212 ath_stop_ani(sc);
213 } else {
214 ath_check_ani(sc);
215 }
216
217 return count;
218}
219
220static const struct file_operations fops_ani = {
221 .read = read_file_ani,
222 .write = write_file_ani,
223 .open = simple_open,
224 .owner = THIS_MODULE,
225 .llseek = default_llseek,
226};
227
228#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
229
230static ssize_t read_file_bt_ant_diversity(struct file *file,
231 char __user *user_buf,
232 size_t count, loff_t *ppos)
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
239 len = sprintf(buf, "%d\n", common->bt_ant_diversity);
240 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
241}
242
243static ssize_t write_file_bt_ant_diversity(struct file *file,
244 const char __user *user_buf,
245 size_t count, loff_t *ppos)
246{
247 struct ath_softc *sc = file->private_data;
248 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
249 struct ath9k_hw_capabilities *pCap = &sc->sc_ah->caps;
250 unsigned long bt_ant_diversity;
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
258 if (!(pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
259 goto exit;
260
261 buf[len] = '\0';
262 if (kstrtoul(buf, 0, &bt_ant_diversity))
263 return -EINVAL;
264
265 common->bt_ant_diversity = !!bt_ant_diversity;
266 ath9k_ps_wakeup(sc);
267 ath9k_hw_set_bt_ant_diversity(sc->sc_ah, common->bt_ant_diversity);
268 ath_dbg(common, CONFIG, "Enable WLAN/BT RX Antenna diversity: %d\n",
269 common->bt_ant_diversity);
270 ath9k_ps_restore(sc);
271exit:
272 return count;
273}
274
275static const struct file_operations fops_bt_ant_diversity = {
276 .read = read_file_bt_ant_diversity,
277 .write = write_file_bt_ant_diversity,
278 .open = simple_open,
279 .owner = THIS_MODULE,
280 .llseek = default_llseek,
281};
282
283#endif
284
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
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];
308 struct ath_hw_antcomb_conf div_ant_conf;
309 unsigned int len = 0;
310 const unsigned int size = 1024;
311 ssize_t retval = 0;
312 char *buf;
313 static const char *lna_conf_str[4] = {
314 "LNA1_MINUS_LNA2", "LNA2", "LNA1", "LNA1_PLUS_LNA2"
315 };
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)) {
322 len += scnprintf(buf + len, size - len, "%s\n",
323 "Antenna Diversity Combining is disabled");
324 goto exit;
325 }
326
327 ath9k_ps_wakeup(sc);
328 ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
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);
337 ath9k_ps_restore(sc);
338
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]);
386
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
404static int read_file_dma(struct seq_file *file, void *data)
405{
406 struct ieee80211_hw *hw = dev_get_drvdata(file->private);
407 struct ath_softc *sc = hw->priv;
408 struct ath_hw *ah = sc->sc_ah;
409 u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
410 int i, qcuOffset = 0, dcuOffset = 0;
411 u32 *qcuBase = &val[0], *dcuBase = &val[4];
412
413 ath9k_ps_wakeup(sc);
414
415 REG_WRITE_D(ah, AR_MACMISC,
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
420 seq_puts(file, "Raw DMA Debug values:\n");
421
422 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
423 if (i % 4 == 0)
424 seq_puts(file, "\n");
425
426 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
427 seq_printf(file, "%d: %08x ", i, val[i]);
428 }
429
430 seq_puts(file, "\n\n");
431 seq_puts(file, "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
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
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);
449 }
450
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));
468
469 ath9k_ps_restore(sc);
470
471 return 0;
472}
473
474void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
475{
476 if (status)
477 sc->debug.stats.istats.total++;
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++;
483 if (status & ATH9K_INT_BB_WATCHDOG)
484 sc->debug.stats.istats.bb_watchdog++;
485 } else {
486 if (status & ATH9K_INT_RX)
487 sc->debug.stats.istats.rxok++;
488 }
489 if (status & ATH9K_INT_RXEOL)
490 sc->debug.stats.istats.rxeol++;
491 if (status & ATH9K_INT_RXORN)
492 sc->debug.stats.istats.rxorn++;
493 if (status & ATH9K_INT_TX)
494 sc->debug.stats.istats.txok++;
495 if (status & ATH9K_INT_TXURN)
496 sc->debug.stats.istats.txurn++;
497 if (status & ATH9K_INT_RXPHY)
498 sc->debug.stats.istats.rxphyerr++;
499 if (status & ATH9K_INT_RXKCM)
500 sc->debug.stats.istats.rx_keycache_miss++;
501 if (status & ATH9K_INT_SWBA)
502 sc->debug.stats.istats.swba++;
503 if (status & ATH9K_INT_BMISS)
504 sc->debug.stats.istats.bmiss++;
505 if (status & ATH9K_INT_BNR)
506 sc->debug.stats.istats.bnr++;
507 if (status & ATH9K_INT_CST)
508 sc->debug.stats.istats.cst++;
509 if (status & ATH9K_INT_GTT)
510 sc->debug.stats.istats.gtt++;
511 if (status & ATH9K_INT_TIM)
512 sc->debug.stats.istats.tim++;
513 if (status & ATH9K_INT_CABEND)
514 sc->debug.stats.istats.cabend++;
515 if (status & ATH9K_INT_DTIMSYNC)
516 sc->debug.stats.istats.dtimsync++;
517 if (status & ATH9K_INT_DTIM)
518 sc->debug.stats.istats.dtim++;
519 if (status & ATH9K_INT_TSFOOR)
520 sc->debug.stats.istats.tsfoor++;
521 if (status & ATH9K_INT_MCI)
522 sc->debug.stats.istats.mci++;
523 if (status & ATH9K_INT_GENTIMER)
524 sc->debug.stats.istats.gen_timer++;
525}
526
527static int read_file_interrupt(struct seq_file *file, void *data)
528{
529 struct ieee80211_hw *hw = dev_get_drvdata(file->private);
530 struct ath_softc *sc = hw->priv;
531
532#define PR_IS(a, s) \
533 do { \
534 seq_printf(file, "%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 seq_puts(file, "SYNC_CAUSE stats:\n");
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
588 return 0;
589}
590
591static int read_file_xmit(struct seq_file *file, void *data)
592{
593 struct ieee80211_hw *hw = dev_get_drvdata(file->private);
594 struct ath_softc *sc = hw->priv;
595
596 seq_printf(file, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
597
598 PR("MPDUs Queued: ", queued);
599 PR("MPDUs Completed: ", completed);
600 PR("MPDUs XRetried: ", xretries);
601 PR("Aggregates: ", a_aggr);
602 PR("AMPDUs Queued HW:", a_queued_hw);
603 PR("AMPDUs Queued SW:", a_queued_sw);
604 PR("AMPDUs Completed:", a_completed);
605 PR("AMPDUs Retried: ", a_retries);
606 PR("AMPDUs XRetried: ", a_xretries);
607 PR("TXERR Filtered: ", txerr_filtered);
608 PR("FIFO Underrun: ", fifo_underrun);
609 PR("TXOP Exceeded: ", xtxop);
610 PR("TXTIMER Expiry: ", timer_exp);
611 PR("DESC CFG Error: ", desc_cfg_err);
612 PR("DATA Underrun: ", data_underrun);
613 PR("DELIM Underrun: ", delim_underrun);
614 PR("TX-Pkts-All: ", tx_pkts_all);
615 PR("TX-Bytes-All: ", tx_bytes_all);
616 PR("HW-put-tx-buf: ", puttxbuf);
617 PR("HW-tx-start: ", txstart);
618 PR("HW-tx-proc-desc: ", txprocdesc);
619 PR("TX-Failed: ", txfailed);
620
621 return 0;
622}
623
624static void print_queue(struct ath_softc *sc, struct ath_txq *txq,
625 struct seq_file *file)
626{
627 ath_txq_lock(sc, txq);
628
629 seq_printf(file, "%s: %d ", "qnum", txq->axq_qnum);
630 seq_printf(file, "%s: %2d ", "qdepth", txq->axq_depth);
631 seq_printf(file, "%s: %2d ", "ampdu-depth", txq->axq_ampdu_depth);
632 seq_printf(file, "%s: %3d ", "pending", txq->pending_frames);
633 seq_printf(file, "%s: %d\n", "stopped", txq->stopped);
634
635 ath_txq_unlock(sc, txq);
636}
637
638static int read_file_queues(struct seq_file *file, void *data)
639{
640 struct ieee80211_hw *hw = dev_get_drvdata(file->private);
641 struct ath_softc *sc = hw->priv;
642 struct ath_txq *txq;
643 int i;
644 static const char *qname[4] = {
645 "VO", "VI", "BE", "BK"
646 };
647
648 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
649 txq = sc->tx.txq_map[i];
650 seq_printf(file, "(%s): ", qname[i]);
651 print_queue(sc, txq, file);
652 }
653
654 seq_puts(file, "(CAB): ");
655 print_queue(sc, sc->beacon.cabq, file);
656
657 return 0;
658}
659
660static int read_file_misc(struct seq_file *file, void *data)
661{
662 struct ieee80211_hw *hw = dev_get_drvdata(file->private);
663 struct ath_softc *sc = hw->priv;
664 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
665 struct ath9k_vif_iter_data iter_data;
666 struct ath_chanctx *ctx;
667 unsigned int reg;
668 u32 rxfilter, i;
669
670 seq_printf(file, "BSSID: %pM\n", common->curbssid);
671 seq_printf(file, "BSSID-MASK: %pM\n", common->bssidmask);
672 seq_printf(file, "OPMODE: %s\n",
673 ath_opmode_to_string(sc->sc_ah->opmode));
674
675 ath9k_ps_wakeup(sc);
676 rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
677 ath9k_ps_restore(sc);
678
679 seq_printf(file, "RXFILTER: 0x%x", rxfilter);
680
681 if (rxfilter & ATH9K_RX_FILTER_UCAST)
682 seq_puts(file, " UCAST");
683 if (rxfilter & ATH9K_RX_FILTER_MCAST)
684 seq_puts(file, " MCAST");
685 if (rxfilter & ATH9K_RX_FILTER_BCAST)
686 seq_puts(file, " BCAST");
687 if (rxfilter & ATH9K_RX_FILTER_CONTROL)
688 seq_puts(file, " CONTROL");
689 if (rxfilter & ATH9K_RX_FILTER_BEACON)
690 seq_puts(file, " BEACON");
691 if (rxfilter & ATH9K_RX_FILTER_PROM)
692 seq_puts(file, " PROM");
693 if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
694 seq_puts(file, " PROBEREQ");
695 if (rxfilter & ATH9K_RX_FILTER_PHYERR)
696 seq_puts(file, " PHYERR");
697 if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
698 seq_puts(file, " MYBEACON");
699 if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
700 seq_puts(file, " COMP_BAR");
701 if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
702 seq_puts(file, " PSPOLL");
703 if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
704 seq_puts(file, " PHYRADAR");
705 if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
706 seq_puts(file, " MCAST_BCAST_ALL");
707 if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
708 seq_puts(file, " CONTROL_WRAPPER");
709
710 seq_puts(file, "\n");
711
712 reg = sc->sc_ah->imask;
713
714 seq_printf(file, "INTERRUPT-MASK: 0x%x", reg);
715
716 if (reg & ATH9K_INT_SWBA)
717 seq_puts(file, " SWBA");
718 if (reg & ATH9K_INT_BMISS)
719 seq_puts(file, " BMISS");
720 if (reg & ATH9K_INT_CST)
721 seq_puts(file, " CST");
722 if (reg & ATH9K_INT_RX)
723 seq_puts(file, " RX");
724 if (reg & ATH9K_INT_RXHP)
725 seq_puts(file, " RXHP");
726 if (reg & ATH9K_INT_RXLP)
727 seq_puts(file, " RXLP");
728 if (reg & ATH9K_INT_BB_WATCHDOG)
729 seq_puts(file, " BB_WATCHDOG");
730
731 seq_puts(file, "\n");
732
733 i = 0;
734 ath_for_each_chanctx(sc, ctx) {
735 if (list_empty(&ctx->vifs))
736 continue;
737 ath9k_calculate_iter_data(sc, ctx, &iter_data);
738
739 seq_printf(file,
740 "VIFS: CTX %i(%i) AP: %i STA: %i MESH: %i WDS: %i",
741 i++, (int)(ctx->assigned), iter_data.naps,
742 iter_data.nstations,
743 iter_data.nmeshes, iter_data.nwds);
744 seq_printf(file, " ADHOC: %i OCB: %i TOTAL: %hi BEACON-VIF: %hi\n",
745 iter_data.nadhocs, iter_data.nocbs, sc->cur_chan->nvifs,
746 sc->nbcnvifs);
747 }
748
749 return 0;
750}
751
752static int read_file_reset(struct seq_file *file, void *data)
753{
754 struct ieee80211_hw *hw = dev_get_drvdata(file->private);
755 struct ath_softc *sc = hw->priv;
756 static const char * const reset_cause[__RESET_TYPE_MAX] = {
757 [RESET_TYPE_BB_HANG] = "Baseband Hang",
758 [RESET_TYPE_BB_WATCHDOG] = "Baseband Watchdog",
759 [RESET_TYPE_FATAL_INT] = "Fatal HW Error",
760 [RESET_TYPE_TX_ERROR] = "TX HW error",
761 [RESET_TYPE_TX_GTT] = "Transmit timeout",
762 [RESET_TYPE_TX_HANG] = "TX Path Hang",
763 [RESET_TYPE_PLL_HANG] = "PLL RX Hang",
764 [RESET_TYPE_MAC_HANG] = "MAC Hang",
765 [RESET_TYPE_BEACON_STUCK] = "Stuck Beacon",
766 [RESET_TYPE_MCI] = "MCI Reset",
767 [RESET_TYPE_CALIBRATION] = "Calibration error",
768 [RESET_TX_DMA_ERROR] = "Tx DMA stop error",
769 [RESET_RX_DMA_ERROR] = "Rx DMA stop error",
770 };
771 int i;
772
773 for (i = 0; i < ARRAY_SIZE(reset_cause); i++) {
774 if (!reset_cause[i])
775 continue;
776
777 seq_printf(file, "%17s: %2d\n", reset_cause[i],
778 sc->debug.stats.reset[i]);
779 }
780
781 return 0;
782}
783
784void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
785 struct ath_tx_status *ts, struct ath_txq *txq,
786 unsigned int flags)
787{
788 int qnum = txq->axq_qnum;
789
790 TX_STAT_INC(qnum, tx_pkts_all);
791 sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
792
793 if (bf_isampdu(bf)) {
794 if (flags & ATH_TX_ERROR)
795 TX_STAT_INC(qnum, a_xretries);
796 else
797 TX_STAT_INC(qnum, a_completed);
798 } else {
799 if (ts->ts_status & ATH9K_TXERR_XRETRY)
800 TX_STAT_INC(qnum, xretries);
801 else
802 TX_STAT_INC(qnum, completed);
803 }
804
805 if (ts->ts_status & ATH9K_TXERR_FILT)
806 TX_STAT_INC(qnum, txerr_filtered);
807 if (ts->ts_status & ATH9K_TXERR_FIFO)
808 TX_STAT_INC(qnum, fifo_underrun);
809 if (ts->ts_status & ATH9K_TXERR_XTXOP)
810 TX_STAT_INC(qnum, xtxop);
811 if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
812 TX_STAT_INC(qnum, timer_exp);
813 if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
814 TX_STAT_INC(qnum, desc_cfg_err);
815 if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
816 TX_STAT_INC(qnum, data_underrun);
817 if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
818 TX_STAT_INC(qnum, delim_underrun);
819}
820
821void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
822{
823 ath9k_cmn_debug_stat_rx(&sc->debug.stats.rxstats, rs);
824}
825
826static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
827 size_t count, loff_t *ppos)
828{
829 struct ath_softc *sc = file->private_data;
830 char buf[32];
831 unsigned int len;
832
833 len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
834 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
835}
836
837static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
838 size_t count, loff_t *ppos)
839{
840 struct ath_softc *sc = file->private_data;
841 unsigned long regidx;
842 char buf[32];
843 ssize_t len;
844
845 len = min(count, sizeof(buf) - 1);
846 if (copy_from_user(buf, user_buf, len))
847 return -EFAULT;
848
849 buf[len] = '\0';
850 if (kstrtoul(buf, 0, ®idx))
851 return -EINVAL;
852
853 sc->debug.regidx = regidx;
854 return count;
855}
856
857static const struct file_operations fops_regidx = {
858 .read = read_file_regidx,
859 .write = write_file_regidx,
860 .open = simple_open,
861 .owner = THIS_MODULE,
862 .llseek = default_llseek,
863};
864
865static ssize_t read_file_regval(struct file *file, char __user *user_buf,
866 size_t count, loff_t *ppos)
867{
868 struct ath_softc *sc = file->private_data;
869 struct ath_hw *ah = sc->sc_ah;
870 char buf[32];
871 unsigned int len;
872 u32 regval;
873
874 ath9k_ps_wakeup(sc);
875 regval = REG_READ_D(ah, sc->debug.regidx);
876 ath9k_ps_restore(sc);
877 len = sprintf(buf, "0x%08x\n", regval);
878 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
879}
880
881static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
882 size_t count, loff_t *ppos)
883{
884 struct ath_softc *sc = file->private_data;
885 struct ath_hw *ah = sc->sc_ah;
886 unsigned long regval;
887 char buf[32];
888 ssize_t len;
889
890 len = min(count, sizeof(buf) - 1);
891 if (copy_from_user(buf, user_buf, len))
892 return -EFAULT;
893
894 buf[len] = '\0';
895 if (kstrtoul(buf, 0, ®val))
896 return -EINVAL;
897
898 ath9k_ps_wakeup(sc);
899 REG_WRITE_D(ah, sc->debug.regidx, regval);
900 ath9k_ps_restore(sc);
901 return count;
902}
903
904static const struct file_operations fops_regval = {
905 .read = read_file_regval,
906 .write = write_file_regval,
907 .open = simple_open,
908 .owner = THIS_MODULE,
909 .llseek = default_llseek,
910};
911
912#define REGDUMP_LINE_SIZE 20
913
914static int open_file_regdump(struct inode *inode, struct file *file)
915{
916 struct ath_softc *sc = inode->i_private;
917 unsigned int len = 0;
918 u8 *buf;
919 int i;
920 unsigned long num_regs, regdump_len, max_reg_offset;
921
922 max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
923 num_regs = max_reg_offset / 4 + 1;
924 regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
925 buf = vmalloc(regdump_len);
926 if (!buf)
927 return -ENOMEM;
928
929 ath9k_ps_wakeup(sc);
930 for (i = 0; i < num_regs; i++)
931 len += scnprintf(buf + len, regdump_len - len,
932 "0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
933 ath9k_ps_restore(sc);
934
935 file->private_data = buf;
936
937 return 0;
938}
939
940static const struct file_operations fops_regdump = {
941 .open = open_file_regdump,
942 .read = ath9k_debugfs_read_buf,
943 .release = ath9k_debugfs_release_buf,
944 .owner = THIS_MODULE,
945 .llseek = default_llseek,/* read accesses f_pos */
946};
947
948static int read_file_dump_nfcal(struct seq_file *file, void *data)
949{
950 struct ieee80211_hw *hw = dev_get_drvdata(file->private);
951 struct ath_softc *sc = hw->priv;
952 struct ath_hw *ah = sc->sc_ah;
953 struct ath9k_nfcal_hist *h = sc->cur_chan->caldata.nfCalHist;
954 struct ath_common *common = ath9k_hw_common(ah);
955 struct ieee80211_conf *conf = &common->hw->conf;
956 u32 i, j;
957 u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
958 u8 nread;
959
960 seq_printf(file, "Channel Noise Floor : %d\n", ah->noise);
961 seq_puts(file, "Chain | privNF | # Readings | NF Readings\n");
962 for (i = 0; i < NUM_NF_READINGS; i++) {
963 if (!(chainmask & (1 << i)) ||
964 ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
965 continue;
966
967 nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
968 seq_printf(file, " %d\t %d\t %d\t\t", i, h[i].privNF, nread);
969 for (j = 0; j < nread; j++)
970 seq_printf(file, " %d", h[i].nfCalBuffer[j]);
971 seq_puts(file, "\n");
972 }
973
974 return 0;
975}
976
977static int open_file_dump_nfcal(struct inode *inode, struct file *f)
978{
979 return single_open(f, read_file_dump_nfcal, inode->i_private);
980}
981
982static const struct file_operations fops_dump_nfcal = {
983 .read = seq_read,
984 .open = open_file_dump_nfcal,
985 .owner = THIS_MODULE,
986 .llseek = seq_lseek,
987 .release = single_release,
988};
989
990#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
991static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
992 size_t count, loff_t *ppos)
993{
994 struct ath_softc *sc = file->private_data;
995 u32 len = 0, size = 1500;
996 char *buf;
997 size_t retval;
998
999 buf = kzalloc(size, GFP_KERNEL);
1000 if (buf == NULL)
1001 return -ENOMEM;
1002
1003 if (!sc->sc_ah->common.btcoex_enabled) {
1004 len = scnprintf(buf, size, "%s\n",
1005 "BTCOEX is disabled");
1006 goto exit;
1007 }
1008
1009 len = ath9k_dump_btcoex(sc, buf, size);
1010exit:
1011 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1012 kfree(buf);
1013
1014 return retval;
1015}
1016
1017static const struct file_operations fops_btcoex = {
1018 .read = read_file_btcoex,
1019 .open = simple_open,
1020 .owner = THIS_MODULE,
1021 .llseek = default_llseek,
1022};
1023#endif
1024
1025#ifdef CONFIG_ATH9K_DYNACK
1026static ssize_t read_file_ackto(struct file *file, char __user *user_buf,
1027 size_t count, loff_t *ppos)
1028{
1029 struct ath_softc *sc = file->private_data;
1030 struct ath_hw *ah = sc->sc_ah;
1031 char buf[32];
1032 unsigned int len;
1033
1034 len = sprintf(buf, "%u %c\n", ah->dynack.ackto,
1035 (ah->dynack.enabled) ? 'A' : 'S');
1036
1037 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1038}
1039
1040static const struct file_operations fops_ackto = {
1041 .read = read_file_ackto,
1042 .open = simple_open,
1043 .owner = THIS_MODULE,
1044 .llseek = default_llseek,
1045};
1046#endif
1047
1048#ifdef CONFIG_ATH9K_WOW
1049
1050static ssize_t read_file_wow(struct file *file, char __user *user_buf,
1051 size_t count, loff_t *ppos)
1052{
1053 struct ath_softc *sc = file->private_data;
1054 unsigned int len = 0, size = 32;
1055 ssize_t retval;
1056 char *buf;
1057
1058 buf = kzalloc(size, GFP_KERNEL);
1059 if (!buf)
1060 return -ENOMEM;
1061
1062 len += scnprintf(buf + len, size - len, "WOW: %s\n",
1063 sc->force_wow ? "ENABLED" : "DISABLED");
1064
1065 if (len > size)
1066 len = size;
1067
1068 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1069 kfree(buf);
1070
1071 return retval;
1072}
1073
1074static ssize_t write_file_wow(struct file *file, const char __user *user_buf,
1075 size_t count, loff_t *ppos)
1076{
1077 struct ath_softc *sc = file->private_data;
1078 unsigned long val;
1079 char buf[32];
1080 ssize_t len;
1081
1082 len = min(count, sizeof(buf) - 1);
1083 if (copy_from_user(buf, user_buf, len))
1084 return -EFAULT;
1085
1086 buf[len] = '\0';
1087 if (kstrtoul(buf, 0, &val))
1088 return -EINVAL;
1089
1090 if (val != 1)
1091 return -EINVAL;
1092
1093 if (!sc->force_wow) {
1094 sc->force_wow = true;
1095 ath9k_init_wow(sc->hw);
1096 }
1097
1098 return count;
1099}
1100
1101static const struct file_operations fops_wow = {
1102 .read = read_file_wow,
1103 .write = write_file_wow,
1104 .open = simple_open,
1105 .owner = THIS_MODULE,
1106 .llseek = default_llseek,
1107};
1108
1109#endif
1110
1111static ssize_t read_file_tpc(struct file *file, char __user *user_buf,
1112 size_t count, loff_t *ppos)
1113{
1114 struct ath_softc *sc = file->private_data;
1115 struct ath_hw *ah = sc->sc_ah;
1116 unsigned int len = 0, size = 32;
1117 ssize_t retval;
1118 char *buf;
1119
1120 buf = kzalloc(size, GFP_KERNEL);
1121 if (!buf)
1122 return -ENOMEM;
1123
1124 len += scnprintf(buf + len, size - len, "%s\n",
1125 ah->tpc_enabled ? "ENABLED" : "DISABLED");
1126
1127 if (len > size)
1128 len = size;
1129
1130 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1131 kfree(buf);
1132
1133 return retval;
1134}
1135
1136static ssize_t write_file_tpc(struct file *file, const char __user *user_buf,
1137 size_t count, loff_t *ppos)
1138{
1139 struct ath_softc *sc = file->private_data;
1140 struct ath_hw *ah = sc->sc_ah;
1141 unsigned long val;
1142 char buf[32];
1143 ssize_t len;
1144 bool tpc_enabled;
1145
1146 len = min(count, sizeof(buf) - 1);
1147 if (copy_from_user(buf, user_buf, len))
1148 return -EFAULT;
1149
1150 buf[len] = '\0';
1151 if (kstrtoul(buf, 0, &val))
1152 return -EINVAL;
1153
1154 if (val < 0 || val > 1)
1155 return -EINVAL;
1156
1157 tpc_enabled = !!val;
1158
1159 if (tpc_enabled != ah->tpc_enabled) {
1160 ah->tpc_enabled = tpc_enabled;
1161
1162 mutex_lock(&sc->mutex);
1163 ath9k_set_txpower(sc, NULL);
1164 mutex_unlock(&sc->mutex);
1165 }
1166
1167 return count;
1168}
1169
1170static const struct file_operations fops_tpc = {
1171 .read = read_file_tpc,
1172 .write = write_file_tpc,
1173 .open = simple_open,
1174 .owner = THIS_MODULE,
1175 .llseek = default_llseek,
1176};
1177
1178/* Ethtool support for get-stats */
1179
1180#define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1181static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1182 "tx_pkts_nic",
1183 "tx_bytes_nic",
1184 "rx_pkts_nic",
1185 "rx_bytes_nic",
1186 AMKSTR(d_tx_pkts),
1187 AMKSTR(d_tx_bytes),
1188 AMKSTR(d_tx_mpdus_queued),
1189 AMKSTR(d_tx_mpdus_completed),
1190 AMKSTR(d_tx_mpdu_xretries),
1191 AMKSTR(d_tx_aggregates),
1192 AMKSTR(d_tx_ampdus_queued_hw),
1193 AMKSTR(d_tx_ampdus_queued_sw),
1194 AMKSTR(d_tx_ampdus_completed),
1195 AMKSTR(d_tx_ampdu_retries),
1196 AMKSTR(d_tx_ampdu_xretries),
1197 AMKSTR(d_tx_fifo_underrun),
1198 AMKSTR(d_tx_op_exceeded),
1199 AMKSTR(d_tx_timer_expiry),
1200 AMKSTR(d_tx_desc_cfg_err),
1201 AMKSTR(d_tx_data_underrun),
1202 AMKSTR(d_tx_delim_underrun),
1203 "d_rx_crc_err",
1204 "d_rx_decrypt_crc_err",
1205 "d_rx_phy_err",
1206 "d_rx_mic_err",
1207 "d_rx_pre_delim_crc_err",
1208 "d_rx_post_delim_crc_err",
1209 "d_rx_decrypt_busy_err",
1210
1211 "d_rx_phyerr_radar",
1212 "d_rx_phyerr_ofdm_timing",
1213 "d_rx_phyerr_cck_timing",
1214
1215};
1216#define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1217
1218void ath9k_get_et_strings(struct ieee80211_hw *hw,
1219 struct ieee80211_vif *vif,
1220 u32 sset, u8 *data)
1221{
1222 if (sset == ETH_SS_STATS)
1223 memcpy(data, *ath9k_gstrings_stats,
1224 sizeof(ath9k_gstrings_stats));
1225}
1226
1227int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
1228 struct ieee80211_vif *vif, int sset)
1229{
1230 if (sset == ETH_SS_STATS)
1231 return ATH9K_SSTATS_LEN;
1232 return 0;
1233}
1234
1235#define AWDATA(elem) \
1236 do { \
1237 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
1238 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
1239 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
1240 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
1241 } while (0)
1242
1243#define AWDATA_RX(elem) \
1244 do { \
1245 data[i++] = sc->debug.stats.rxstats.elem; \
1246 } while (0)
1247
1248void ath9k_get_et_stats(struct ieee80211_hw *hw,
1249 struct ieee80211_vif *vif,
1250 struct ethtool_stats *stats, u64 *data)
1251{
1252 struct ath_softc *sc = hw->priv;
1253 int i = 0;
1254
1255 data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
1256 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
1257 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
1258 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
1259 data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
1260 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
1261 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
1262 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
1263 AWDATA_RX(rx_pkts_all);
1264 AWDATA_RX(rx_bytes_all);
1265
1266 AWDATA(tx_pkts_all);
1267 AWDATA(tx_bytes_all);
1268 AWDATA(queued);
1269 AWDATA(completed);
1270 AWDATA(xretries);
1271 AWDATA(a_aggr);
1272 AWDATA(a_queued_hw);
1273 AWDATA(a_queued_sw);
1274 AWDATA(a_completed);
1275 AWDATA(a_retries);
1276 AWDATA(a_xretries);
1277 AWDATA(fifo_underrun);
1278 AWDATA(xtxop);
1279 AWDATA(timer_exp);
1280 AWDATA(desc_cfg_err);
1281 AWDATA(data_underrun);
1282 AWDATA(delim_underrun);
1283
1284 AWDATA_RX(crc_err);
1285 AWDATA_RX(decrypt_crc_err);
1286 AWDATA_RX(phy_err);
1287 AWDATA_RX(mic_err);
1288 AWDATA_RX(pre_delim_crc_err);
1289 AWDATA_RX(post_delim_crc_err);
1290 AWDATA_RX(decrypt_busy_err);
1291
1292 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
1293 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
1294 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
1295
1296 WARN_ON(i != ATH9K_SSTATS_LEN);
1297}
1298
1299void ath9k_deinit_debug(struct ath_softc *sc)
1300{
1301 ath9k_cmn_spectral_deinit_debug(&sc->spec_priv);
1302}
1303
1304int ath9k_init_debug(struct ath_hw *ah)
1305{
1306 struct ath_common *common = ath9k_hw_common(ah);
1307 struct ath_softc *sc = (struct ath_softc *) common->priv;
1308
1309 sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1310 sc->hw->wiphy->debugfsdir);
1311 if (!sc->debug.debugfs_phy)
1312 return -ENOMEM;
1313
1314#ifdef CONFIG_ATH_DEBUG
1315 debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1316 sc, &fops_debug);
1317#endif
1318
1319 ath9k_dfs_init_debug(sc);
1320 ath9k_tx99_init_debug(sc);
1321 ath9k_cmn_spectral_init_debug(&sc->spec_priv, sc->debug.debugfs_phy);
1322
1323 debugfs_create_devm_seqfile(sc->dev, "dma", sc->debug.debugfs_phy,
1324 read_file_dma);
1325 debugfs_create_devm_seqfile(sc->dev, "interrupt", sc->debug.debugfs_phy,
1326 read_file_interrupt);
1327 debugfs_create_devm_seqfile(sc->dev, "xmit", sc->debug.debugfs_phy,
1328 read_file_xmit);
1329 debugfs_create_devm_seqfile(sc->dev, "queues", sc->debug.debugfs_phy,
1330 read_file_queues);
1331 debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1332 &sc->tx.txq_max_pending[IEEE80211_AC_BK]);
1333 debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1334 &sc->tx.txq_max_pending[IEEE80211_AC_BE]);
1335 debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1336 &sc->tx.txq_max_pending[IEEE80211_AC_VI]);
1337 debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1338 &sc->tx.txq_max_pending[IEEE80211_AC_VO]);
1339 debugfs_create_devm_seqfile(sc->dev, "misc", sc->debug.debugfs_phy,
1340 read_file_misc);
1341 debugfs_create_devm_seqfile(sc->dev, "reset", sc->debug.debugfs_phy,
1342 read_file_reset);
1343
1344 ath9k_cmn_debug_recv(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
1345 ath9k_cmn_debug_phy_err(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
1346
1347 debugfs_create_u8("rx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
1348 &ah->rxchainmask);
1349 debugfs_create_u8("tx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
1350 &ah->txchainmask);
1351 debugfs_create_file("ani", S_IRUSR | S_IWUSR,
1352 sc->debug.debugfs_phy, sc, &fops_ani);
1353 debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1354 &sc->sc_ah->config.enable_paprd);
1355 debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1356 sc, &fops_regidx);
1357 debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1358 sc, &fops_regval);
1359 debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1360 sc->debug.debugfs_phy,
1361 &ah->config.cwm_ignore_extcca);
1362 debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
1363 &fops_regdump);
1364 debugfs_create_devm_seqfile(sc->dev, "dump_nfcal",
1365 sc->debug.debugfs_phy,
1366 read_file_dump_nfcal);
1367
1368 ath9k_cmn_debug_base_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
1369 ath9k_cmn_debug_modal_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
1370
1371 debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
1372 sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
1373 debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
1374 sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
1375 debugfs_create_file("antenna_diversity", S_IRUSR,
1376 sc->debug.debugfs_phy, sc, &fops_antenna_diversity);
1377#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
1378 debugfs_create_file("bt_ant_diversity", S_IRUSR | S_IWUSR,
1379 sc->debug.debugfs_phy, sc, &fops_bt_ant_diversity);
1380 debugfs_create_file("btcoex", S_IRUSR, sc->debug.debugfs_phy, sc,
1381 &fops_btcoex);
1382#endif
1383
1384#ifdef CONFIG_ATH9K_WOW
1385 debugfs_create_file("wow", S_IRUSR | S_IWUSR,
1386 sc->debug.debugfs_phy, sc, &fops_wow);
1387#endif
1388
1389#ifdef CONFIG_ATH9K_DYNACK
1390 debugfs_create_file("ack_to", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1391 sc, &fops_ackto);
1392#endif
1393 debugfs_create_file("tpc", S_IRUSR | S_IWUSR,
1394 sc->debug.debugfs_phy, sc, &fops_tpc);
1395
1396 return 0;
1397}