blob: b66f72dbf7b93f9c52bc254b1c54f7c0dd256422 [file] [log] [blame]
Sujith88b126a2008-11-28 22:19:02 +05301/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 Atheros Communications Inc.
Sujith88b126a2008-11-28 22:19:02 +05303 *
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
Gabor Juhos52103112009-03-06 09:57:39 +010017#include <asm/unaligned.h>
18
Sujith394cf0a2009-02-09 13:26:54 +053019#include "ath9k.h"
Sujith88b126a2008-11-28 22:19:02 +053020
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -040021#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
Gabor Juhos19d8bc22009-03-05 16:55:18 +010026static struct dentry *ath9k_debugfs_root;
27
Sujith2a163c62008-11-28 22:21:08 +053028static int ath9k_debugfs_open(struct inode *inode, struct file *file)
29{
30 file->private_data = inode->i_private;
31 return 0;
32}
33
Felix Fietkaua830df02009-11-23 22:33:27 +010034#ifdef CONFIG_ATH_DEBUG
35
Jeff Hansen24939282009-05-27 12:48:29 +000036static 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;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070040 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jeff Hansen24939282009-05-27 12:48:29 +000041 char buf[32];
Vasanthakumar Thiagarajan581f7252009-06-02 19:28:55 +053042 unsigned int len;
43
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070044 len = snprintf(buf, sizeof(buf), "0x%08x\n", common->debug_mask);
Jeff Hansen24939282009-05-27 12:48:29 +000045 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;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070052 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jeff Hansen24939282009-05-27 12:48:29 +000053 unsigned long mask;
54 char buf[32];
Vasanthakumar Thiagarajan581f7252009-06-02 19:28:55 +053055 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
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070065 common->debug_mask = mask;
Jeff Hansen24939282009-05-27 12:48:29 +000066 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
Felix Fietkaua830df02009-11-23 22:33:27 +010076#endif
77
Sujith2a163c62008-11-28 22:21:08 +053078static 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;
Sujithcbe61d82009-02-09 13:27:12 +053082 struct ath_hw *ah = sc->sc_ah;
Sujith2a163c62008-11-28 22:21:08 +053083 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
Sujith7cf4a2e2009-08-26 11:11:57 +053089 ath9k_ps_wakeup(sc);
90
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -040091 REG_WRITE_D(ah, AR_MACMISC,
Sujith2a163c62008-11-28 22:21:08 +053092 ((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
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400103 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
Sujith2a163c62008-11-28 22:21:08 +0530104 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",
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400153 REG_READ_D(ah, AR_OBS_BUS_1));
Sujith2a163c62008-11-28 22:21:08 +0530154 len += snprintf(buf + len, sizeof(buf) - len,
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400155 "AR_CR: 0x%x \n", REG_READ_D(ah, AR_CR));
Sujith2a163c62008-11-28 22:21:08 +0530156
Sujith7cf4a2e2009-08-26 11:11:57 +0530157 ath9k_ps_restore(sc);
158
Sujith2a163c62008-11-28 22:21:08 +0530159 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
Sujith817e11d2008-12-07 21:42:44 +0530168
169void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
170{
171 if (status)
Sujith17d79042009-02-09 13:27:03 +0530172 sc->debug.stats.istats.total++;
Sujith817e11d2008-12-07 21:42:44 +0530173 if (status & ATH9K_INT_RX)
Sujith17d79042009-02-09 13:27:03 +0530174 sc->debug.stats.istats.rxok++;
Sujith817e11d2008-12-07 21:42:44 +0530175 if (status & ATH9K_INT_RXEOL)
Sujith17d79042009-02-09 13:27:03 +0530176 sc->debug.stats.istats.rxeol++;
Sujith817e11d2008-12-07 21:42:44 +0530177 if (status & ATH9K_INT_RXORN)
Sujith17d79042009-02-09 13:27:03 +0530178 sc->debug.stats.istats.rxorn++;
Sujith817e11d2008-12-07 21:42:44 +0530179 if (status & ATH9K_INT_TX)
Sujith17d79042009-02-09 13:27:03 +0530180 sc->debug.stats.istats.txok++;
Sujith817e11d2008-12-07 21:42:44 +0530181 if (status & ATH9K_INT_TXURN)
Sujith17d79042009-02-09 13:27:03 +0530182 sc->debug.stats.istats.txurn++;
Sujith817e11d2008-12-07 21:42:44 +0530183 if (status & ATH9K_INT_MIB)
Sujith17d79042009-02-09 13:27:03 +0530184 sc->debug.stats.istats.mib++;
Sujith817e11d2008-12-07 21:42:44 +0530185 if (status & ATH9K_INT_RXPHY)
Sujith17d79042009-02-09 13:27:03 +0530186 sc->debug.stats.istats.rxphyerr++;
Sujith817e11d2008-12-07 21:42:44 +0530187 if (status & ATH9K_INT_RXKCM)
Sujith17d79042009-02-09 13:27:03 +0530188 sc->debug.stats.istats.rx_keycache_miss++;
Sujith817e11d2008-12-07 21:42:44 +0530189 if (status & ATH9K_INT_SWBA)
Sujith17d79042009-02-09 13:27:03 +0530190 sc->debug.stats.istats.swba++;
Sujith817e11d2008-12-07 21:42:44 +0530191 if (status & ATH9K_INT_BMISS)
Sujith17d79042009-02-09 13:27:03 +0530192 sc->debug.stats.istats.bmiss++;
Sujith817e11d2008-12-07 21:42:44 +0530193 if (status & ATH9K_INT_BNR)
Sujith17d79042009-02-09 13:27:03 +0530194 sc->debug.stats.istats.bnr++;
Sujith817e11d2008-12-07 21:42:44 +0530195 if (status & ATH9K_INT_CST)
Sujith17d79042009-02-09 13:27:03 +0530196 sc->debug.stats.istats.cst++;
Sujith817e11d2008-12-07 21:42:44 +0530197 if (status & ATH9K_INT_GTT)
Sujith17d79042009-02-09 13:27:03 +0530198 sc->debug.stats.istats.gtt++;
Sujith817e11d2008-12-07 21:42:44 +0530199 if (status & ATH9K_INT_TIM)
Sujith17d79042009-02-09 13:27:03 +0530200 sc->debug.stats.istats.tim++;
Sujith817e11d2008-12-07 21:42:44 +0530201 if (status & ATH9K_INT_CABEND)
Sujith17d79042009-02-09 13:27:03 +0530202 sc->debug.stats.istats.cabend++;
Sujith817e11d2008-12-07 21:42:44 +0530203 if (status & ATH9K_INT_DTIMSYNC)
Sujith17d79042009-02-09 13:27:03 +0530204 sc->debug.stats.istats.dtimsync++;
Sujith817e11d2008-12-07 21:42:44 +0530205 if (status & ATH9K_INT_DTIM)
Sujith17d79042009-02-09 13:27:03 +0530206 sc->debug.stats.istats.dtim++;
Sujith817e11d2008-12-07 21:42:44 +0530207}
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,
Sujith17d79042009-02-09 13:27:03 +0530217 "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
Sujith817e11d2008-12-07 21:42:44 +0530218 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530219 "%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol);
Sujith817e11d2008-12-07 21:42:44 +0530220 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530221 "%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn);
Sujith817e11d2008-12-07 21:42:44 +0530222 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530223 "%8s: %10u\n", "TX", sc->debug.stats.istats.txok);
Sujith817e11d2008-12-07 21:42:44 +0530224 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530225 "%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn);
Sujith817e11d2008-12-07 21:42:44 +0530226 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530227 "%8s: %10u\n", "MIB", sc->debug.stats.istats.mib);
Sujith817e11d2008-12-07 21:42:44 +0530228 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530229 "%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr);
Sujith817e11d2008-12-07 21:42:44 +0530230 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530231 "%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss);
Sujith817e11d2008-12-07 21:42:44 +0530232 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530233 "%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba);
Sujith817e11d2008-12-07 21:42:44 +0530234 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530235 "%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss);
Sujith817e11d2008-12-07 21:42:44 +0530236 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530237 "%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr);
Sujith817e11d2008-12-07 21:42:44 +0530238 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530239 "%8s: %10u\n", "CST", sc->debug.stats.istats.cst);
Sujith817e11d2008-12-07 21:42:44 +0530240 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530241 "%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt);
Sujith817e11d2008-12-07 21:42:44 +0530242 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530243 "%8s: %10u\n", "TIM", sc->debug.stats.istats.tim);
Sujith817e11d2008-12-07 21:42:44 +0530244 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530245 "%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend);
Sujith817e11d2008-12-07 21:42:44 +0530246 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530247 "%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync);
Sujith817e11d2008-12-07 21:42:44 +0530248 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530249 "%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim);
Sujith817e11d2008-12-07 21:42:44 +0530250 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530251 "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total);
Sujith817e11d2008-12-07 21:42:44 +0530252
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
Felix Fietkau545750d2009-11-23 22:21:01 +0100262void ath_debug_stat_rc(struct ath_softc *sc, int final_rate)
Sujith7a7dec62009-01-30 14:32:09 +0530263{
Jeff Hansenbedf0872009-05-27 12:48:28 +0000264 struct ath_rc_stats *stats;
Sujith7a7dec62009-01-30 14:32:09 +0530265
Felix Fietkau545750d2009-11-23 22:21:01 +0100266 stats = &sc->debug.stats.rcstats[final_rate];
Jeff Hansenbedf0872009-05-27 12:48:28 +0000267 stats->success++;
Sujith7a7dec62009-01-30 14:32:09 +0530268}
269
Sujith029bc432009-02-04 08:10:26 +0530270void ath_debug_stat_retries(struct ath_softc *sc, int rix,
Sujith9e712792009-02-20 15:13:20 +0530271 int xretries, int retries, u8 per)
Sujith029bc432009-02-04 08:10:26 +0530272{
Jeff Hansenbedf0872009-05-27 12:48:28 +0000273 struct ath_rc_stats *stats = &sc->debug.stats.rcstats[rix];
Sujith029bc432009-02-04 08:10:26 +0530274
Jeff Hansenbedf0872009-05-27 12:48:28 +0000275 stats->xretries += xretries;
276 stats->retries += retries;
277 stats->per = per;
Sujith7a7dec62009-01-30 14:32:09 +0530278}
279
280static ssize_t read_file_rcstat(struct file *file, char __user *user_buf,
281 size_t count, loff_t *ppos)
282{
283 struct ath_softc *sc = file->private_data;
Jeff Hansenbedf0872009-05-27 12:48:28 +0000284 char *buf;
285 unsigned int len = 0, max;
286 int i = 0;
287 ssize_t retval;
Sujith7a7dec62009-01-30 14:32:09 +0530288
Sujith62b4fb62009-03-09 09:32:01 +0530289 if (sc->cur_rate_table == NULL)
290 return 0;
291
Jeff Hansenbedf0872009-05-27 12:48:28 +0000292 max = 80 + sc->cur_rate_table->rate_cnt * 64;
293 buf = kmalloc(max + 1, GFP_KERNEL);
294 if (buf == NULL)
295 return 0;
296 buf[max] = 0;
297
298 len += sprintf(buf, "%5s %15s %8s %9s %3s\n\n", "Rate", "Success",
299 "Retries", "XRetries", "PER");
300
301 for (i = 0; i < sc->cur_rate_table->rate_cnt; i++) {
302 u32 ratekbps = sc->cur_rate_table->info[i].ratekbps;
303 struct ath_rc_stats *stats = &sc->debug.stats.rcstats[i];
304
305 len += snprintf(buf + len, max - len,
306 "%3u.%d: %8u %8u %8u %8u\n", ratekbps / 1000,
307 (ratekbps % 1000) / 100, stats->success,
308 stats->retries, stats->xretries,
309 stats->per);
310 }
311
312 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
313 kfree(buf);
314 return retval;
Sujith7a7dec62009-01-30 14:32:09 +0530315}
316
317static const struct file_operations fops_rcstat = {
318 .read = read_file_rcstat,
319 .open = ath9k_debugfs_open,
320 .owner = THIS_MODULE
321};
Alina Friedrichsen27abe062009-01-23 05:44:21 +0100322
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200323static const char * ath_wiphy_state_str(enum ath_wiphy_state state)
324{
325 switch (state) {
326 case ATH_WIPHY_INACTIVE:
327 return "INACTIVE";
328 case ATH_WIPHY_ACTIVE:
329 return "ACTIVE";
330 case ATH_WIPHY_PAUSING:
331 return "PAUSING";
332 case ATH_WIPHY_PAUSED:
333 return "PAUSED";
334 case ATH_WIPHY_SCAN:
335 return "SCAN";
336 }
337 return "?";
338}
339
340static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
341 size_t count, loff_t *ppos)
342{
343 struct ath_softc *sc = file->private_data;
344 char buf[512];
345 unsigned int len = 0;
346 int i;
347 u8 addr[ETH_ALEN];
348
349 len += snprintf(buf + len, sizeof(buf) - len,
350 "primary: %s (%s chan=%d ht=%d)\n",
351 wiphy_name(sc->pri_wiphy->hw->wiphy),
352 ath_wiphy_state_str(sc->pri_wiphy->state),
353 sc->pri_wiphy->chan_idx, sc->pri_wiphy->chan_is_ht);
354 for (i = 0; i < sc->num_sec_wiphy; i++) {
355 struct ath_wiphy *aphy = sc->sec_wiphy[i];
356 if (aphy == NULL)
357 continue;
358 len += snprintf(buf + len, sizeof(buf) - len,
359 "secondary: %s (%s chan=%d ht=%d)\n",
360 wiphy_name(aphy->hw->wiphy),
361 ath_wiphy_state_str(aphy->state),
362 aphy->chan_idx, aphy->chan_is_ht);
363 }
364
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400365 put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr);
366 put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200367 len += snprintf(buf + len, sizeof(buf) - len,
368 "addr: %pM\n", addr);
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400369 put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr);
370 put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200371 len += snprintf(buf + len, sizeof(buf) - len,
372 "addrmask: %pM\n", addr);
373
374 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
375}
376
377static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name)
378{
379 int i;
380 if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0)
381 return sc->pri_wiphy;
382 for (i = 0; i < sc->num_sec_wiphy; i++) {
383 struct ath_wiphy *aphy = sc->sec_wiphy[i];
384 if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0)
385 return aphy;
386 }
387 return NULL;
388}
389
390static int del_wiphy(struct ath_softc *sc, const char *name)
391{
392 struct ath_wiphy *aphy = get_wiphy(sc, name);
393 if (!aphy)
394 return -ENOENT;
395 return ath9k_wiphy_del(aphy);
396}
397
398static int pause_wiphy(struct ath_softc *sc, const char *name)
399{
400 struct ath_wiphy *aphy = get_wiphy(sc, name);
401 if (!aphy)
402 return -ENOENT;
403 return ath9k_wiphy_pause(aphy);
404}
405
406static int unpause_wiphy(struct ath_softc *sc, const char *name)
407{
408 struct ath_wiphy *aphy = get_wiphy(sc, name);
409 if (!aphy)
410 return -ENOENT;
411 return ath9k_wiphy_unpause(aphy);
412}
413
414static int select_wiphy(struct ath_softc *sc, const char *name)
415{
416 struct ath_wiphy *aphy = get_wiphy(sc, name);
417 if (!aphy)
418 return -ENOENT;
419 return ath9k_wiphy_select(aphy);
420}
421
422static int schedule_wiphy(struct ath_softc *sc, const char *msec)
423{
424 ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0));
425 return 0;
426}
427
428static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf,
429 size_t count, loff_t *ppos)
430{
431 struct ath_softc *sc = file->private_data;
432 char buf[50];
433 size_t len;
434
435 len = min(count, sizeof(buf) - 1);
436 if (copy_from_user(buf, user_buf, len))
437 return -EFAULT;
438 buf[len] = '\0';
439 if (len > 0 && buf[len - 1] == '\n')
440 buf[len - 1] = '\0';
441
442 if (strncmp(buf, "add", 3) == 0) {
443 int res = ath9k_wiphy_add(sc);
444 if (res < 0)
445 return res;
446 } else if (strncmp(buf, "del=", 4) == 0) {
447 int res = del_wiphy(sc, buf + 4);
448 if (res < 0)
449 return res;
450 } else if (strncmp(buf, "pause=", 6) == 0) {
451 int res = pause_wiphy(sc, buf + 6);
452 if (res < 0)
453 return res;
454 } else if (strncmp(buf, "unpause=", 8) == 0) {
455 int res = unpause_wiphy(sc, buf + 8);
456 if (res < 0)
457 return res;
458 } else if (strncmp(buf, "select=", 7) == 0) {
459 int res = select_wiphy(sc, buf + 7);
460 if (res < 0)
461 return res;
462 } else if (strncmp(buf, "schedule=", 9) == 0) {
463 int res = schedule_wiphy(sc, buf + 9);
464 if (res < 0)
465 return res;
466 } else
467 return -EOPNOTSUPP;
468
469 return count;
470}
471
472static const struct file_operations fops_wiphy = {
473 .read = read_file_wiphy,
474 .write = write_file_wiphy,
475 .open = ath9k_debugfs_open,
476 .owner = THIS_MODULE
477};
478
Sujithfec247c2009-07-27 12:08:16 +0530479#define PR(str, elem) \
480 do { \
481 len += snprintf(buf + len, size - len, \
482 "%s%13u%11u%10u%10u\n", str, \
483 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BE]].elem, \
484 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BK]].elem, \
485 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VI]].elem, \
486 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VO]].elem); \
487} while(0)
488
489static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
490 size_t count, loff_t *ppos)
491{
492 struct ath_softc *sc = file->private_data;
493 char *buf;
494 unsigned int len = 0, size = 2048;
495 ssize_t retval = 0;
496
497 buf = kzalloc(size, GFP_KERNEL);
498 if (buf == NULL)
499 return 0;
500
501 len += sprintf(buf, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
502
503 PR("MPDUs Queued: ", queued);
504 PR("MPDUs Completed: ", completed);
505 PR("Aggregates: ", a_aggr);
506 PR("AMPDUs Queued: ", a_queued);
507 PR("AMPDUs Completed:", a_completed);
508 PR("AMPDUs Retried: ", a_retries);
509 PR("AMPDUs XRetried: ", a_xretries);
510 PR("FIFO Underrun: ", fifo_underrun);
511 PR("TXOP Exceeded: ", xtxop);
512 PR("TXTIMER Expiry: ", timer_exp);
513 PR("DESC CFG Error: ", desc_cfg_err);
514 PR("DATA Underrun: ", data_underrun);
515 PR("DELIM Underrun: ", delim_underrun);
516
517 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
518 kfree(buf);
519
520 return retval;
521}
522
523void ath_debug_stat_tx(struct ath_softc *sc, struct ath_txq *txq,
524 struct ath_buf *bf)
525{
526 struct ath_desc *ds = bf->bf_desc;
527
528 if (bf_isampdu(bf)) {
529 if (bf_isxretried(bf))
530 TX_STAT_INC(txq->axq_qnum, a_xretries);
531 else
532 TX_STAT_INC(txq->axq_qnum, a_completed);
533 } else {
534 TX_STAT_INC(txq->axq_qnum, completed);
535 }
536
537 if (ds->ds_txstat.ts_status & ATH9K_TXERR_FIFO)
538 TX_STAT_INC(txq->axq_qnum, fifo_underrun);
539 if (ds->ds_txstat.ts_status & ATH9K_TXERR_XTXOP)
540 TX_STAT_INC(txq->axq_qnum, xtxop);
541 if (ds->ds_txstat.ts_status & ATH9K_TXERR_TIMER_EXPIRED)
542 TX_STAT_INC(txq->axq_qnum, timer_exp);
543 if (ds->ds_txstat.ts_flags & ATH9K_TX_DESC_CFG_ERR)
544 TX_STAT_INC(txq->axq_qnum, desc_cfg_err);
545 if (ds->ds_txstat.ts_flags & ATH9K_TX_DATA_UNDERRUN)
546 TX_STAT_INC(txq->axq_qnum, data_underrun);
547 if (ds->ds_txstat.ts_flags & ATH9K_TX_DELIM_UNDERRUN)
548 TX_STAT_INC(txq->axq_qnum, delim_underrun);
549}
550
551static const struct file_operations fops_xmit = {
552 .read = read_file_xmit,
553 .open = ath9k_debugfs_open,
554 .owner = THIS_MODULE
555};
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200556
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700557int ath9k_init_debug(struct ath_hw *ah)
Sujith88b126a2008-11-28 22:19:02 +0530558{
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -0400559 struct ath_common *common = ath9k_hw_common(ah);
560 struct ath_softc *sc = (struct ath_softc *) common->priv;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700561
Sujith7dd58742009-03-30 15:28:42 +0530562 if (!ath9k_debugfs_root)
563 return -ENOENT;
564
Sujith17d79042009-02-09 13:27:03 +0530565 sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
Gabor Juhos19d8bc22009-03-05 16:55:18 +0100566 ath9k_debugfs_root);
Sujith17d79042009-02-09 13:27:03 +0530567 if (!sc->debug.debugfs_phy)
Sujith826d2682008-11-28 22:20:23 +0530568 goto err;
569
Felix Fietkaua830df02009-11-23 22:33:27 +0100570#ifdef CONFIG_ATH_DEBUG
Jeff Hansen24939282009-05-27 12:48:29 +0000571 sc->debug.debugfs_debug = debugfs_create_file("debug",
Jiri Slaby9d49e862009-06-28 23:25:28 +0200572 S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc, &fops_debug);
Jeff Hansen24939282009-05-27 12:48:29 +0000573 if (!sc->debug.debugfs_debug)
574 goto err;
Felix Fietkaua830df02009-11-23 22:33:27 +0100575#endif
Jeff Hansen24939282009-05-27 12:48:29 +0000576
Jiri Slaby9d49e862009-06-28 23:25:28 +0200577 sc->debug.debugfs_dma = debugfs_create_file("dma", S_IRUSR,
Sujith17d79042009-02-09 13:27:03 +0530578 sc->debug.debugfs_phy, sc, &fops_dma);
579 if (!sc->debug.debugfs_dma)
Sujith2a163c62008-11-28 22:21:08 +0530580 goto err;
581
Sujith17d79042009-02-09 13:27:03 +0530582 sc->debug.debugfs_interrupt = debugfs_create_file("interrupt",
Jiri Slaby9d49e862009-06-28 23:25:28 +0200583 S_IRUSR,
Sujith17d79042009-02-09 13:27:03 +0530584 sc->debug.debugfs_phy,
Sujith817e11d2008-12-07 21:42:44 +0530585 sc, &fops_interrupt);
Sujith17d79042009-02-09 13:27:03 +0530586 if (!sc->debug.debugfs_interrupt)
Sujith817e11d2008-12-07 21:42:44 +0530587 goto err;
588
Sujith17d79042009-02-09 13:27:03 +0530589 sc->debug.debugfs_rcstat = debugfs_create_file("rcstat",
Jiri Slaby9d49e862009-06-28 23:25:28 +0200590 S_IRUSR,
Sujith17d79042009-02-09 13:27:03 +0530591 sc->debug.debugfs_phy,
Sujith7a7dec62009-01-30 14:32:09 +0530592 sc, &fops_rcstat);
Sujith17d79042009-02-09 13:27:03 +0530593 if (!sc->debug.debugfs_rcstat)
Sujith7a7dec62009-01-30 14:32:09 +0530594 goto err;
595
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200596 sc->debug.debugfs_wiphy = debugfs_create_file(
Jiri Slaby9d49e862009-06-28 23:25:28 +0200597 "wiphy", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc,
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200598 &fops_wiphy);
599 if (!sc->debug.debugfs_wiphy)
600 goto err;
601
Sujithfec247c2009-07-27 12:08:16 +0530602 sc->debug.debugfs_xmit = debugfs_create_file("xmit",
603 S_IRUSR,
604 sc->debug.debugfs_phy,
605 sc, &fops_xmit);
606 if (!sc->debug.debugfs_xmit)
607 goto err;
608
Sujith826d2682008-11-28 22:20:23 +0530609 return 0;
610err:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700611 ath9k_exit_debug(ah);
Sujith826d2682008-11-28 22:20:23 +0530612 return -ENOMEM;
613}
614
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700615void ath9k_exit_debug(struct ath_hw *ah)
Sujith826d2682008-11-28 22:20:23 +0530616{
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -0400617 struct ath_common *common = ath9k_hw_common(ah);
618 struct ath_softc *sc = (struct ath_softc *) common->priv;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700619
Sujithfec247c2009-07-27 12:08:16 +0530620 debugfs_remove(sc->debug.debugfs_xmit);
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200621 debugfs_remove(sc->debug.debugfs_wiphy);
Sujith17d79042009-02-09 13:27:03 +0530622 debugfs_remove(sc->debug.debugfs_rcstat);
623 debugfs_remove(sc->debug.debugfs_interrupt);
624 debugfs_remove(sc->debug.debugfs_dma);
Jeff Hansen24939282009-05-27 12:48:29 +0000625 debugfs_remove(sc->debug.debugfs_debug);
Sujith17d79042009-02-09 13:27:03 +0530626 debugfs_remove(sc->debug.debugfs_phy);
Gabor Juhos19d8bc22009-03-05 16:55:18 +0100627}
628
629int ath9k_debug_create_root(void)
630{
631 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
632 if (!ath9k_debugfs_root)
633 return -ENOENT;
634
635 return 0;
636}
637
638void ath9k_debug_remove_root(void)
639{
640 debugfs_remove(ath9k_debugfs_root);
641 ath9k_debugfs_root = NULL;
Sujith88b126a2008-11-28 22:19:02 +0530642}