ath: make gcc check format arguments of ath_print(), fix all misuses
[linux-2.6-block.git] / drivers / net / wireless / ath / ath9k / debug.c
CommitLineData
88b126af 1/*
cee075a2 2 * Copyright (c) 2008-2009 Atheros Communications Inc.
88b126af
S
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
52103115
GJ
17#include <asm/unaligned.h>
18
394cf0a1 19#include "ath9k.h"
88b126af 20
475a6e4d
LR
21#define REG_WRITE_D(_ah, _reg, _val) \
22 ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg))
23#define REG_READ_D(_ah, _reg) \
24 ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
25
19d8bc22
GJ
26static struct dentry *ath9k_debugfs_root;
27
2a163c6d
S
28static int ath9k_debugfs_open(struct inode *inode, struct file *file)
29{
30 file->private_data = inode->i_private;
31 return 0;
32}
33
a830df07
FF
34#ifdef CONFIG_ATH_DEBUG
35
2493928e
JH
36static ssize_t read_file_debug(struct file *file, char __user *user_buf,
37 size_t count, loff_t *ppos)
38{
39 struct ath_softc *sc = file->private_data;
c46917bb 40 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2493928e 41 char buf[32];
581f725c
VT
42 unsigned int len;
43
c46917bb 44 len = snprintf(buf, sizeof(buf), "0x%08x\n", common->debug_mask);
2493928e
JH
45 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
46}
47
48static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
49 size_t count, loff_t *ppos)
50{
51 struct ath_softc *sc = file->private_data;
c46917bb 52 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2493928e
JH
53 unsigned long mask;
54 char buf[32];
581f725c
VT
55 ssize_t len;
56
57 len = min(count, sizeof(buf) - 1);
58 if (copy_from_user(buf, user_buf, len))
59 return -EINVAL;
60
61 buf[len] = '\0';
62 if (strict_strtoul(buf, 0, &mask))
63 return -EINVAL;
64
c46917bb 65 common->debug_mask = mask;
2493928e
JH
66 return count;
67}
68
69static const struct file_operations fops_debug = {
70 .read = read_file_debug,
71 .write = write_file_debug,
72 .open = ath9k_debugfs_open,
73 .owner = THIS_MODULE
74};
75
a830df07
FF
76#endif
77
2a163c6d
S
78static ssize_t read_file_dma(struct file *file, char __user *user_buf,
79 size_t count, loff_t *ppos)
80{
81 struct ath_softc *sc = file->private_data;
cbe61d8a 82 struct ath_hw *ah = sc->sc_ah;
2a163c6d
S
83 char buf[1024];
84 unsigned int len = 0;
85 u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
86 int i, qcuOffset = 0, dcuOffset = 0;
87 u32 *qcuBase = &val[0], *dcuBase = &val[4];
88
7cf4a2e7
S
89 ath9k_ps_wakeup(sc);
90
475a6e4d 91 REG_WRITE_D(ah, AR_MACMISC,
2a163c6d
S
92 ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
93 (AR_MACMISC_MISC_OBS_BUS_1 <<
94 AR_MACMISC_MISC_OBS_BUS_MSB_S)));
95
96 len += snprintf(buf + len, sizeof(buf) - len,
97 "Raw DMA Debug values:\n");
98
99 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
100 if (i % 4 == 0)
101 len += snprintf(buf + len, sizeof(buf) - len, "\n");
102
475a6e4d 103 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
2a163c6d
S
104 len += snprintf(buf + len, sizeof(buf) - len, "%d: %08x ",
105 i, val[i]);
106 }
107
108 len += snprintf(buf + len, sizeof(buf) - len, "\n\n");
109 len += snprintf(buf + len, sizeof(buf) - len,
110 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
111
112 for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
113 if (i == 8) {
114 qcuOffset = 0;
115 qcuBase++;
116 }
117
118 if (i == 6) {
119 dcuOffset = 0;
120 dcuBase++;
121 }
122
123 len += snprintf(buf + len, sizeof(buf) - len,
124 "%2d %2x %1x %2x %2x\n",
125 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
126 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
127 val[2] & (0x7 << (i * 3)) >> (i * 3),
128 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
129 }
130
131 len += snprintf(buf + len, sizeof(buf) - len, "\n");
132
133 len += snprintf(buf + len, sizeof(buf) - len,
134 "qcu_stitch state: %2x qcu_fetch state: %2x\n",
135 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
136 len += snprintf(buf + len, sizeof(buf) - len,
137 "qcu_complete state: %2x dcu_complete state: %2x\n",
138 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
139 len += snprintf(buf + len, sizeof(buf) - len,
140 "dcu_arb state: %2x dcu_fp state: %2x\n",
141 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
142 len += snprintf(buf + len, sizeof(buf) - len,
143 "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
144 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
145 len += snprintf(buf + len, sizeof(buf) - len,
146 "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
147 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
148 len += snprintf(buf + len, sizeof(buf) - len,
149 "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
150 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
151
152 len += snprintf(buf + len, sizeof(buf) - len, "pcu observe: 0x%x \n",
475a6e4d 153 REG_READ_D(ah, AR_OBS_BUS_1));
2a163c6d 154 len += snprintf(buf + len, sizeof(buf) - len,
475a6e4d 155 "AR_CR: 0x%x \n", REG_READ_D(ah, AR_CR));
2a163c6d 156
7cf4a2e7
S
157 ath9k_ps_restore(sc);
158
2a163c6d
S
159 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
160}
161
162static const struct file_operations fops_dma = {
163 .read = read_file_dma,
164 .open = ath9k_debugfs_open,
165 .owner = THIS_MODULE
166};
167
817e11de
S
168
169void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
170{
171 if (status)
17d7904d 172 sc->debug.stats.istats.total++;
817e11de 173 if (status & ATH9K_INT_RX)
17d7904d 174 sc->debug.stats.istats.rxok++;
817e11de 175 if (status & ATH9K_INT_RXEOL)
17d7904d 176 sc->debug.stats.istats.rxeol++;
817e11de 177 if (status & ATH9K_INT_RXORN)
17d7904d 178 sc->debug.stats.istats.rxorn++;
817e11de 179 if (status & ATH9K_INT_TX)
17d7904d 180 sc->debug.stats.istats.txok++;
817e11de 181 if (status & ATH9K_INT_TXURN)
17d7904d 182 sc->debug.stats.istats.txurn++;
817e11de 183 if (status & ATH9K_INT_MIB)
17d7904d 184 sc->debug.stats.istats.mib++;
817e11de 185 if (status & ATH9K_INT_RXPHY)
17d7904d 186 sc->debug.stats.istats.rxphyerr++;
817e11de 187 if (status & ATH9K_INT_RXKCM)
17d7904d 188 sc->debug.stats.istats.rx_keycache_miss++;
817e11de 189 if (status & ATH9K_INT_SWBA)
17d7904d 190 sc->debug.stats.istats.swba++;
817e11de 191 if (status & ATH9K_INT_BMISS)
17d7904d 192 sc->debug.stats.istats.bmiss++;
817e11de 193 if (status & ATH9K_INT_BNR)
17d7904d 194 sc->debug.stats.istats.bnr++;
817e11de 195 if (status & ATH9K_INT_CST)
17d7904d 196 sc->debug.stats.istats.cst++;
817e11de 197 if (status & ATH9K_INT_GTT)
17d7904d 198 sc->debug.stats.istats.gtt++;
817e11de 199 if (status & ATH9K_INT_TIM)
17d7904d 200 sc->debug.stats.istats.tim++;
817e11de 201 if (status & ATH9K_INT_CABEND)
17d7904d 202 sc->debug.stats.istats.cabend++;
817e11de 203 if (status & ATH9K_INT_DTIMSYNC)
17d7904d 204 sc->debug.stats.istats.dtimsync++;
817e11de 205 if (status & ATH9K_INT_DTIM)
17d7904d 206 sc->debug.stats.istats.dtim++;
817e11de
S
207}
208
209static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
210 size_t count, loff_t *ppos)
211{
212 struct ath_softc *sc = file->private_data;
213 char buf[512];
214 unsigned int len = 0;
215
216 len += snprintf(buf + len, sizeof(buf) - len,
17d7904d 217 "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
817e11de 218 len += snprintf(buf + len, sizeof(buf) - len,
17d7904d 219 "%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol);
817e11de 220 len += snprintf(buf + len, sizeof(buf) - len,
17d7904d 221 "%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn);
817e11de 222 len += snprintf(buf + len, sizeof(buf) - len,
17d7904d 223 "%8s: %10u\n", "TX", sc->debug.stats.istats.txok);
817e11de 224 len += snprintf(buf + len, sizeof(buf) - len,
17d7904d 225 "%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn);
817e11de 226 len += snprintf(buf + len, sizeof(buf) - len,
17d7904d 227 "%8s: %10u\n", "MIB", sc->debug.stats.istats.mib);
817e11de 228 len += snprintf(buf + len, sizeof(buf) - len,
17d7904d 229 "%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr);
817e11de 230 len += snprintf(buf + len, sizeof(buf) - len,
17d7904d 231 "%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss);
817e11de 232 len += snprintf(buf + len, sizeof(buf) - len,
17d7904d 233 "%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba);
817e11de 234 len += snprintf(buf + len, sizeof(buf) - len,
17d7904d 235 "%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss);
817e11de 236 len += snprintf(buf + len, sizeof(buf) - len,
17d7904d 237 "%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr);
817e11de 238 len += snprintf(buf + len, sizeof(buf) - len,
17d7904d 239 "%8s: %10u\n", "CST", sc->debug.stats.istats.cst);
817e11de 240 len += snprintf(buf + len, sizeof(buf) - len,
17d7904d 241 "%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt);
817e11de 242 len += snprintf(buf + len, sizeof(buf) - len,
17d7904d 243 "%8s: %10u\n", "TIM", sc->debug.stats.istats.tim);
817e11de 244 len += snprintf(buf + len, sizeof(buf) - len,
17d7904d 245 "%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend);
817e11de 246 len += snprintf(buf + len, sizeof(buf) - len,
17d7904d 247 "%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync);
817e11de 248 len += snprintf(buf + len, sizeof(buf) - len,
17d7904d 249 "%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim);
817e11de 250 len += snprintf(buf + len, sizeof(buf) - len,
17d7904d 251 "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total);
817e11de
S
252
253 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
254}
255
256static const struct file_operations fops_interrupt = {
257 .read = read_file_interrupt,
258 .open = ath9k_debugfs_open,
259 .owner = THIS_MODULE
260};
261
545750d3 262void ath_debug_stat_rc(struct ath_softc *sc, int final_rate)
7a7dec65 263{
bedf087a 264 struct ath_rc_stats *stats;
7a7dec65 265
545750d3 266 stats = &sc->debug.stats.rcstats[final_rate];
bedf087a 267 stats->success++;
7a7dec65
S
268}
269
029bc432 270void ath_debug_stat_retries(struct ath_softc *sc, int rix,
9e712790 271 int xretries, int retries, u8 per)
029bc432 272{
bedf087a 273 struct ath_rc_stats *stats = &sc->debug.stats.rcstats[rix];
029bc432 274
bedf087a
JH
275 stats->xretries += xretries;
276 stats->retries += retries;
277 stats->per = per;
029bc432
S
278}
279
bedf087a
JH
280static ssize_t read_file_rcstat(struct file *file, char __user *user_buf,
281 size_t count, loff_t *ppos)
7a7dec65
S
282{
283 struct ath_softc *sc = file->private_data;
bedf087a
JH
284 char *buf;
285 unsigned int len = 0, max;
7a7dec65 286 int i = 0;
bedf087a 287 ssize_t retval;
7a7dec65 288
bedf087a
JH
289 if (sc->cur_rate_table == NULL)
290 return 0;
7a7dec65 291
c755ad34 292 max = 80 + sc->cur_rate_table->rate_cnt * 1024;
bedf087a
JH
293 buf = kmalloc(max + 1, GFP_KERNEL);
294 if (buf == NULL)
295 return 0;
296 buf[max] = 0;
7a7dec65 297
c755ad34
LR
298 len += sprintf(buf, "%6s %6s %6s "
299 "%10s %10s %10s %10s\n",
300 "HT", "MCS", "Rate",
301 "Success", "Retries", "XRetries", "PER");
7a7dec65
S
302
303 for (i = 0; i < sc->cur_rate_table->rate_cnt; i++) {
bedf087a
JH
304 u32 ratekbps = sc->cur_rate_table->info[i].ratekbps;
305 struct ath_rc_stats *stats = &sc->debug.stats.rcstats[i];
c755ad34
LR
306 char mcs[5];
307 char htmode[5];
308 int used_mcs = 0, used_htmode = 0;
309
310 if (WLAN_RC_PHY_HT(sc->cur_rate_table->info[i].phy)) {
311 used_mcs = snprintf(mcs, 5, "%d",
312 sc->cur_rate_table->info[i].ratecode);
313
314 if (WLAN_RC_PHY_40(sc->cur_rate_table->info[i].phy))
315 used_htmode = snprintf(htmode, 5, "HT40");
316 else if (WLAN_RC_PHY_20(sc->cur_rate_table->info[i].phy))
317 used_htmode = snprintf(htmode, 5, "HT20");
318 else
319 used_htmode = snprintf(htmode, 5, "????");
320 }
321
322 mcs[used_mcs] = '\0';
323 htmode[used_htmode] = '\0';
bedf087a
JH
324
325 len += snprintf(buf + len, max - len,
c755ad34
LR
326 "%6s %6s %3u.%d: "
327 "%10u %10u %10u %10u\n",
328 htmode,
329 mcs,
330 ratekbps / 1000,
331 (ratekbps % 1000) / 100,
332 stats->success,
333 stats->retries,
334 stats->xretries,
bedf087a 335 stats->per);
7a7dec65
S
336 }
337
bedf087a
JH
338 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
339 kfree(buf);
340 return retval;
7a7dec65
S
341}
342
343static const struct file_operations fops_rcstat = {
344 .read = read_file_rcstat,
345 .open = ath9k_debugfs_open,
346 .owner = THIS_MODULE
347};
27abe060 348
39d89cd3
JM
349static const char * ath_wiphy_state_str(enum ath_wiphy_state state)
350{
351 switch (state) {
352 case ATH_WIPHY_INACTIVE:
353 return "INACTIVE";
354 case ATH_WIPHY_ACTIVE:
355 return "ACTIVE";
356 case ATH_WIPHY_PAUSING:
357 return "PAUSING";
358 case ATH_WIPHY_PAUSED:
359 return "PAUSED";
360 case ATH_WIPHY_SCAN:
361 return "SCAN";
362 }
363 return "?";
364}
365
366static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
367 size_t count, loff_t *ppos)
368{
369 struct ath_softc *sc = file->private_data;
370 char buf[512];
371 unsigned int len = 0;
372 int i;
373 u8 addr[ETH_ALEN];
374
375 len += snprintf(buf + len, sizeof(buf) - len,
376 "primary: %s (%s chan=%d ht=%d)\n",
377 wiphy_name(sc->pri_wiphy->hw->wiphy),
378 ath_wiphy_state_str(sc->pri_wiphy->state),
379 sc->pri_wiphy->chan_idx, sc->pri_wiphy->chan_is_ht);
380 for (i = 0; i < sc->num_sec_wiphy; i++) {
381 struct ath_wiphy *aphy = sc->sec_wiphy[i];
382 if (aphy == NULL)
383 continue;
384 len += snprintf(buf + len, sizeof(buf) - len,
385 "secondary: %s (%s chan=%d ht=%d)\n",
386 wiphy_name(aphy->hw->wiphy),
387 ath_wiphy_state_str(aphy->state),
388 aphy->chan_idx, aphy->chan_is_ht);
389 }
390
475a6e4d
LR
391 put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr);
392 put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
39d89cd3
JM
393 len += snprintf(buf + len, sizeof(buf) - len,
394 "addr: %pM\n", addr);
475a6e4d
LR
395 put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr);
396 put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
39d89cd3
JM
397 len += snprintf(buf + len, sizeof(buf) - len,
398 "addrmask: %pM\n", addr);
399
400 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
401}
402
403static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name)
404{
405 int i;
406 if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0)
407 return sc->pri_wiphy;
408 for (i = 0; i < sc->num_sec_wiphy; i++) {
409 struct ath_wiphy *aphy = sc->sec_wiphy[i];
410 if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0)
411 return aphy;
412 }
413 return NULL;
414}
415
416static int del_wiphy(struct ath_softc *sc, const char *name)
417{
418 struct ath_wiphy *aphy = get_wiphy(sc, name);
419 if (!aphy)
420 return -ENOENT;
421 return ath9k_wiphy_del(aphy);
422}
423
424static int pause_wiphy(struct ath_softc *sc, const char *name)
425{
426 struct ath_wiphy *aphy = get_wiphy(sc, name);
427 if (!aphy)
428 return -ENOENT;
429 return ath9k_wiphy_pause(aphy);
430}
431
432static int unpause_wiphy(struct ath_softc *sc, const char *name)
433{
434 struct ath_wiphy *aphy = get_wiphy(sc, name);
435 if (!aphy)
436 return -ENOENT;
437 return ath9k_wiphy_unpause(aphy);
438}
439
440static int select_wiphy(struct ath_softc *sc, const char *name)
441{
442 struct ath_wiphy *aphy = get_wiphy(sc, name);
443 if (!aphy)
444 return -ENOENT;
445 return ath9k_wiphy_select(aphy);
446}
447
448static int schedule_wiphy(struct ath_softc *sc, const char *msec)
449{
450 ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0));
451 return 0;
452}
453
454static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf,
455 size_t count, loff_t *ppos)
456{
457 struct ath_softc *sc = file->private_data;
458 char buf[50];
459 size_t len;
460
461 len = min(count, sizeof(buf) - 1);
462 if (copy_from_user(buf, user_buf, len))
463 return -EFAULT;
464 buf[len] = '\0';
465 if (len > 0 && buf[len - 1] == '\n')
466 buf[len - 1] = '\0';
467
468 if (strncmp(buf, "add", 3) == 0) {
469 int res = ath9k_wiphy_add(sc);
470 if (res < 0)
471 return res;
472 } else if (strncmp(buf, "del=", 4) == 0) {
473 int res = del_wiphy(sc, buf + 4);
474 if (res < 0)
475 return res;
476 } else if (strncmp(buf, "pause=", 6) == 0) {
477 int res = pause_wiphy(sc, buf + 6);
478 if (res < 0)
479 return res;
480 } else if (strncmp(buf, "unpause=", 8) == 0) {
481 int res = unpause_wiphy(sc, buf + 8);
482 if (res < 0)
483 return res;
484 } else if (strncmp(buf, "select=", 7) == 0) {
485 int res = select_wiphy(sc, buf + 7);
486 if (res < 0)
487 return res;
488 } else if (strncmp(buf, "schedule=", 9) == 0) {
489 int res = schedule_wiphy(sc, buf + 9);
490 if (res < 0)
491 return res;
492 } else
493 return -EOPNOTSUPP;
494
495 return count;
496}
497
498static const struct file_operations fops_wiphy = {
499 .read = read_file_wiphy,
500 .write = write_file_wiphy,
501 .open = ath9k_debugfs_open,
502 .owner = THIS_MODULE
503};
504
fec247c0
S
505#define PR(str, elem) \
506 do { \
507 len += snprintf(buf + len, size - len, \
508 "%s%13u%11u%10u%10u\n", str, \
509 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BE]].elem, \
510 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BK]].elem, \
511 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VI]].elem, \
512 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VO]].elem); \
513} while(0)
514
515static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
516 size_t count, loff_t *ppos)
517{
518 struct ath_softc *sc = file->private_data;
519 char *buf;
520 unsigned int len = 0, size = 2048;
521 ssize_t retval = 0;
522
523 buf = kzalloc(size, GFP_KERNEL);
524 if (buf == NULL)
525 return 0;
526
527 len += sprintf(buf, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
528
529 PR("MPDUs Queued: ", queued);
530 PR("MPDUs Completed: ", completed);
531 PR("Aggregates: ", a_aggr);
532 PR("AMPDUs Queued: ", a_queued);
533 PR("AMPDUs Completed:", a_completed);
534 PR("AMPDUs Retried: ", a_retries);
535 PR("AMPDUs XRetried: ", a_xretries);
536 PR("FIFO Underrun: ", fifo_underrun);
537 PR("TXOP Exceeded: ", xtxop);
538 PR("TXTIMER Expiry: ", timer_exp);
539 PR("DESC CFG Error: ", desc_cfg_err);
540 PR("DATA Underrun: ", data_underrun);
541 PR("DELIM Underrun: ", delim_underrun);
542
543 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
544 kfree(buf);
545
546 return retval;
547}
548
549void ath_debug_stat_tx(struct ath_softc *sc, struct ath_txq *txq,
550 struct ath_buf *bf)
551{
552 struct ath_desc *ds = bf->bf_desc;
553
554 if (bf_isampdu(bf)) {
555 if (bf_isxretried(bf))
556 TX_STAT_INC(txq->axq_qnum, a_xretries);
557 else
558 TX_STAT_INC(txq->axq_qnum, a_completed);
559 } else {
560 TX_STAT_INC(txq->axq_qnum, completed);
561 }
562
563 if (ds->ds_txstat.ts_status & ATH9K_TXERR_FIFO)
564 TX_STAT_INC(txq->axq_qnum, fifo_underrun);
565 if (ds->ds_txstat.ts_status & ATH9K_TXERR_XTXOP)
566 TX_STAT_INC(txq->axq_qnum, xtxop);
567 if (ds->ds_txstat.ts_status & ATH9K_TXERR_TIMER_EXPIRED)
568 TX_STAT_INC(txq->axq_qnum, timer_exp);
569 if (ds->ds_txstat.ts_flags & ATH9K_TX_DESC_CFG_ERR)
570 TX_STAT_INC(txq->axq_qnum, desc_cfg_err);
571 if (ds->ds_txstat.ts_flags & ATH9K_TX_DATA_UNDERRUN)
572 TX_STAT_INC(txq->axq_qnum, data_underrun);
573 if (ds->ds_txstat.ts_flags & ATH9K_TX_DELIM_UNDERRUN)
574 TX_STAT_INC(txq->axq_qnum, delim_underrun);
575}
576
577static const struct file_operations fops_xmit = {
578 .read = read_file_xmit,
579 .open = ath9k_debugfs_open,
580 .owner = THIS_MODULE
581};
39d89cd3 582
1395d3f0
S
583static ssize_t read_file_recv(struct file *file, char __user *user_buf,
584 size_t count, loff_t *ppos)
585{
586#define PHY_ERR(s, p) \
587 len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \
588 sc->debug.stats.rxstats.phy_err_stats[p]);
589
590 struct ath_softc *sc = file->private_data;
591 char *buf;
592 unsigned int len = 0, size = 1152;
593 ssize_t retval = 0;
594
595 buf = kzalloc(size, GFP_KERNEL);
596 if (buf == NULL)
597 return 0;
598
599 len += snprintf(buf + len, size - len,
600 "%18s : %10u\n", "CRC ERR",
601 sc->debug.stats.rxstats.crc_err);
602 len += snprintf(buf + len, size - len,
603 "%18s : %10u\n", "DECRYPT CRC ERR",
604 sc->debug.stats.rxstats.decrypt_crc_err);
605 len += snprintf(buf + len, size - len,
606 "%18s : %10u\n", "PHY ERR",
607 sc->debug.stats.rxstats.phy_err);
608 len += snprintf(buf + len, size - len,
609 "%18s : %10u\n", "MIC ERR",
610 sc->debug.stats.rxstats.mic_err);
611 len += snprintf(buf + len, size - len,
612 "%18s : %10u\n", "PRE-DELIM CRC ERR",
613 sc->debug.stats.rxstats.pre_delim_crc_err);
614 len += snprintf(buf + len, size - len,
615 "%18s : %10u\n", "POST-DELIM CRC ERR",
616 sc->debug.stats.rxstats.post_delim_crc_err);
617 len += snprintf(buf + len, size - len,
618 "%18s : %10u\n", "DECRYPT BUSY ERR",
619 sc->debug.stats.rxstats.decrypt_busy_err);
620
621 PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN);
622 PHY_ERR("TIMING", ATH9K_PHYERR_TIMING);
623 PHY_ERR("PARITY", ATH9K_PHYERR_PARITY);
624 PHY_ERR("RATE", ATH9K_PHYERR_RATE);
625 PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH);
626 PHY_ERR("RADAR", ATH9K_PHYERR_RADAR);
627 PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE);
628 PHY_ERR("TOR", ATH9K_PHYERR_TOR);
629 PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING);
630 PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
631 PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
632 PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
633 PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP);
634 PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE);
635 PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART);
636 PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT);
637 PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING);
638 PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC);
639 PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
640 PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE);
641 PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART);
642 PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
643 PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP);
644 PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR);
645 PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
646 PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL);
647
648 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
649 kfree(buf);
650
651 return retval;
652
653#undef PHY_ERR
654}
655
656void ath_debug_stat_rx(struct ath_softc *sc, struct ath_buf *bf)
657{
658#define RX_STAT_INC(c) sc->debug.stats.rxstats.c++
659#define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
660
661 struct ath_desc *ds = bf->bf_desc;
662 u32 phyerr;
663
664 if (ds->ds_rxstat.rs_status & ATH9K_RXERR_CRC)
665 RX_STAT_INC(crc_err);
666 if (ds->ds_rxstat.rs_status & ATH9K_RXERR_DECRYPT)
667 RX_STAT_INC(decrypt_crc_err);
668 if (ds->ds_rxstat.rs_status & ATH9K_RXERR_MIC)
669 RX_STAT_INC(mic_err);
670 if (ds->ds_rxstat.rs_status & ATH9K_RX_DELIM_CRC_PRE)
671 RX_STAT_INC(pre_delim_crc_err);
672 if (ds->ds_rxstat.rs_status & ATH9K_RX_DELIM_CRC_POST)
673 RX_STAT_INC(post_delim_crc_err);
674 if (ds->ds_rxstat.rs_status & ATH9K_RX_DECRYPT_BUSY)
675 RX_STAT_INC(decrypt_busy_err);
676
677 if (ds->ds_rxstat.rs_status & ATH9K_RXERR_PHY) {
678 RX_STAT_INC(phy_err);
679 phyerr = ds->ds_rxstat.rs_phyerr & 0x24;
680 RX_PHY_ERR_INC(phyerr);
681 }
682
683#undef RX_STAT_INC
684#undef RX_PHY_ERR_INC
685}
686
687static const struct file_operations fops_recv = {
688 .read = read_file_recv,
689 .open = ath9k_debugfs_open,
690 .owner = THIS_MODULE
691};
692
4d6b228d 693int ath9k_init_debug(struct ath_hw *ah)
88b126af 694{
bc974f4a
LR
695 struct ath_common *common = ath9k_hw_common(ah);
696 struct ath_softc *sc = (struct ath_softc *) common->priv;
4d6b228d 697
7dd58748
S
698 if (!ath9k_debugfs_root)
699 return -ENOENT;
700
17d7904d 701 sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
19d8bc22 702 ath9k_debugfs_root);
17d7904d 703 if (!sc->debug.debugfs_phy)
826d2680
S
704 goto err;
705
a830df07 706#ifdef CONFIG_ATH_DEBUG
2493928e 707 sc->debug.debugfs_debug = debugfs_create_file("debug",
9d49e861 708 S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc, &fops_debug);
2493928e
JH
709 if (!sc->debug.debugfs_debug)
710 goto err;
a830df07 711#endif
2493928e 712
9d49e861 713 sc->debug.debugfs_dma = debugfs_create_file("dma", S_IRUSR,
17d7904d
S
714 sc->debug.debugfs_phy, sc, &fops_dma);
715 if (!sc->debug.debugfs_dma)
2a163c6d
S
716 goto err;
717
17d7904d 718 sc->debug.debugfs_interrupt = debugfs_create_file("interrupt",
9d49e861 719 S_IRUSR,
17d7904d 720 sc->debug.debugfs_phy,
817e11de 721 sc, &fops_interrupt);
17d7904d 722 if (!sc->debug.debugfs_interrupt)
817e11de
S
723 goto err;
724
17d7904d 725 sc->debug.debugfs_rcstat = debugfs_create_file("rcstat",
9d49e861 726 S_IRUSR,
17d7904d 727 sc->debug.debugfs_phy,
7a7dec65 728 sc, &fops_rcstat);
17d7904d 729 if (!sc->debug.debugfs_rcstat)
7a7dec65
S
730 goto err;
731
39d89cd3 732 sc->debug.debugfs_wiphy = debugfs_create_file(
9d49e861 733 "wiphy", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc,
39d89cd3
JM
734 &fops_wiphy);
735 if (!sc->debug.debugfs_wiphy)
736 goto err;
737
fec247c0
S
738 sc->debug.debugfs_xmit = debugfs_create_file("xmit",
739 S_IRUSR,
740 sc->debug.debugfs_phy,
741 sc, &fops_xmit);
742 if (!sc->debug.debugfs_xmit)
743 goto err;
744
1395d3f0
S
745 sc->debug.debugfs_recv = debugfs_create_file("recv",
746 S_IRUSR,
747 sc->debug.debugfs_phy,
748 sc, &fops_recv);
749 if (!sc->debug.debugfs_recv)
750 goto err;
751
826d2680
S
752 return 0;
753err:
4d6b228d 754 ath9k_exit_debug(ah);
826d2680
S
755 return -ENOMEM;
756}
757
4d6b228d 758void ath9k_exit_debug(struct ath_hw *ah)
826d2680 759{
bc974f4a
LR
760 struct ath_common *common = ath9k_hw_common(ah);
761 struct ath_softc *sc = (struct ath_softc *) common->priv;
4d6b228d 762
1395d3f0 763 debugfs_remove(sc->debug.debugfs_recv);
fec247c0 764 debugfs_remove(sc->debug.debugfs_xmit);
39d89cd3 765 debugfs_remove(sc->debug.debugfs_wiphy);
17d7904d
S
766 debugfs_remove(sc->debug.debugfs_rcstat);
767 debugfs_remove(sc->debug.debugfs_interrupt);
768 debugfs_remove(sc->debug.debugfs_dma);
2493928e 769 debugfs_remove(sc->debug.debugfs_debug);
17d7904d 770 debugfs_remove(sc->debug.debugfs_phy);
19d8bc22
GJ
771}
772
773int ath9k_debug_create_root(void)
774{
775 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
776 if (!ath9k_debugfs_root)
777 return -ENOENT;
778
779 return 0;
780}
781
782void ath9k_debug_remove_root(void)
783{
784 debugfs_remove(ath9k_debugfs_root);
785 ath9k_debugfs_root = NULL;
88b126af 786}