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