]>
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 | ||
5a0e3ad6 | 17 | #include <linux/slab.h> |
52103115 GJ |
18 | #include <asm/unaligned.h> |
19 | ||
394cf0a1 | 20 | #include "ath9k.h" |
88b126af | 21 | |
475a6e4d LR |
22 | #define REG_WRITE_D(_ah, _reg, _val) \ |
23 | ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg)) | |
24 | #define REG_READ_D(_ah, _reg) \ | |
25 | ath9k_hw_common(_ah)->ops->read((_ah), (_reg)) | |
26 | ||
19d8bc22 GJ |
27 | static struct dentry *ath9k_debugfs_root; |
28 | ||
2a163c6d S |
29 | static int ath9k_debugfs_open(struct inode *inode, struct file *file) |
30 | { | |
31 | file->private_data = inode->i_private; | |
32 | return 0; | |
33 | } | |
34 | ||
a830df07 FF |
35 | #ifdef CONFIG_ATH_DEBUG |
36 | ||
2493928e JH |
37 | static ssize_t read_file_debug(struct file *file, char __user *user_buf, |
38 | size_t count, loff_t *ppos) | |
39 | { | |
40 | struct ath_softc *sc = file->private_data; | |
c46917bb | 41 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
2493928e | 42 | char buf[32]; |
581f725c VT |
43 | unsigned int len; |
44 | ||
2b87f3aa | 45 | len = sprintf(buf, "0x%08x\n", common->debug_mask); |
2493928e JH |
46 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
47 | } | |
48 | ||
49 | static ssize_t write_file_debug(struct file *file, const char __user *user_buf, | |
50 | size_t count, loff_t *ppos) | |
51 | { | |
52 | struct ath_softc *sc = file->private_data; | |
c46917bb | 53 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
2493928e JH |
54 | unsigned long mask; |
55 | char buf[32]; | |
581f725c VT |
56 | ssize_t len; |
57 | ||
58 | len = min(count, sizeof(buf) - 1); | |
59 | if (copy_from_user(buf, user_buf, len)) | |
04236066 | 60 | return -EFAULT; |
581f725c VT |
61 | |
62 | buf[len] = '\0'; | |
63 | if (strict_strtoul(buf, 0, &mask)) | |
64 | return -EINVAL; | |
65 | ||
c46917bb | 66 | common->debug_mask = mask; |
2493928e JH |
67 | return count; |
68 | } | |
69 | ||
70 | static const struct file_operations fops_debug = { | |
71 | .read = read_file_debug, | |
72 | .write = write_file_debug, | |
73 | .open = ath9k_debugfs_open, | |
74 | .owner = THIS_MODULE | |
75 | }; | |
76 | ||
a830df07 FF |
77 | #endif |
78 | ||
991a0987 PR |
79 | #define DMA_BUF_LEN 1024 |
80 | ||
15340694 FF |
81 | static ssize_t read_file_tx_chainmask(struct file *file, char __user *user_buf, |
82 | size_t count, loff_t *ppos) | |
83 | { | |
84 | struct ath_softc *sc = file->private_data; | |
85 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); | |
86 | char buf[32]; | |
87 | unsigned int len; | |
88 | ||
2b87f3aa | 89 | len = sprintf(buf, "0x%08x\n", common->tx_chainmask); |
15340694 FF |
90 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
91 | } | |
92 | ||
93 | static ssize_t write_file_tx_chainmask(struct file *file, const char __user *user_buf, | |
94 | size_t count, loff_t *ppos) | |
95 | { | |
96 | struct ath_softc *sc = file->private_data; | |
97 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); | |
98 | unsigned long mask; | |
99 | char buf[32]; | |
100 | ssize_t len; | |
101 | ||
102 | len = min(count, sizeof(buf) - 1); | |
103 | if (copy_from_user(buf, user_buf, len)) | |
04236066 | 104 | return -EFAULT; |
15340694 FF |
105 | |
106 | buf[len] = '\0'; | |
107 | if (strict_strtoul(buf, 0, &mask)) | |
108 | return -EINVAL; | |
109 | ||
110 | common->tx_chainmask = mask; | |
111 | sc->sc_ah->caps.tx_chainmask = mask; | |
112 | return count; | |
113 | } | |
114 | ||
115 | static const struct file_operations fops_tx_chainmask = { | |
116 | .read = read_file_tx_chainmask, | |
117 | .write = write_file_tx_chainmask, | |
118 | .open = ath9k_debugfs_open, | |
119 | .owner = THIS_MODULE | |
120 | }; | |
121 | ||
122 | ||
123 | static ssize_t read_file_rx_chainmask(struct file *file, char __user *user_buf, | |
124 | size_t count, loff_t *ppos) | |
125 | { | |
126 | struct ath_softc *sc = file->private_data; | |
127 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); | |
128 | char buf[32]; | |
129 | unsigned int len; | |
130 | ||
2b87f3aa | 131 | len = sprintf(buf, "0x%08x\n", common->rx_chainmask); |
15340694 FF |
132 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
133 | } | |
134 | ||
135 | static ssize_t write_file_rx_chainmask(struct file *file, const char __user *user_buf, | |
136 | size_t count, loff_t *ppos) | |
137 | { | |
138 | struct ath_softc *sc = file->private_data; | |
139 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); | |
140 | unsigned long mask; | |
141 | char buf[32]; | |
142 | ssize_t len; | |
143 | ||
144 | len = min(count, sizeof(buf) - 1); | |
145 | if (copy_from_user(buf, user_buf, len)) | |
04236066 | 146 | return -EFAULT; |
15340694 FF |
147 | |
148 | buf[len] = '\0'; | |
149 | if (strict_strtoul(buf, 0, &mask)) | |
150 | return -EINVAL; | |
151 | ||
152 | common->rx_chainmask = mask; | |
153 | sc->sc_ah->caps.rx_chainmask = mask; | |
154 | return count; | |
155 | } | |
156 | ||
157 | static const struct file_operations fops_rx_chainmask = { | |
158 | .read = read_file_rx_chainmask, | |
159 | .write = write_file_rx_chainmask, | |
160 | .open = ath9k_debugfs_open, | |
161 | .owner = THIS_MODULE | |
162 | }; | |
163 | ||
164 | ||
2a163c6d S |
165 | static ssize_t read_file_dma(struct file *file, char __user *user_buf, |
166 | size_t count, loff_t *ppos) | |
167 | { | |
168 | struct ath_softc *sc = file->private_data; | |
cbe61d8a | 169 | struct ath_hw *ah = sc->sc_ah; |
991a0987 PR |
170 | char *buf; |
171 | int retval; | |
2a163c6d S |
172 | unsigned int len = 0; |
173 | u32 val[ATH9K_NUM_DMA_DEBUG_REGS]; | |
174 | int i, qcuOffset = 0, dcuOffset = 0; | |
175 | u32 *qcuBase = &val[0], *dcuBase = &val[4]; | |
176 | ||
991a0987 PR |
177 | buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL); |
178 | if (!buf) | |
04236066 | 179 | return -ENOMEM; |
991a0987 | 180 | |
7cf4a2e7 S |
181 | ath9k_ps_wakeup(sc); |
182 | ||
475a6e4d | 183 | REG_WRITE_D(ah, AR_MACMISC, |
2a163c6d S |
184 | ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) | |
185 | (AR_MACMISC_MISC_OBS_BUS_1 << | |
186 | AR_MACMISC_MISC_OBS_BUS_MSB_S))); | |
187 | ||
991a0987 | 188 | len += snprintf(buf + len, DMA_BUF_LEN - len, |
2a163c6d S |
189 | "Raw DMA Debug values:\n"); |
190 | ||
191 | for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) { | |
192 | if (i % 4 == 0) | |
991a0987 | 193 | len += snprintf(buf + len, DMA_BUF_LEN - len, "\n"); |
2a163c6d | 194 | |
475a6e4d | 195 | val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32))); |
991a0987 | 196 | len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ", |
2a163c6d S |
197 | i, val[i]); |
198 | } | |
199 | ||
991a0987 PR |
200 | len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n"); |
201 | len += snprintf(buf + len, DMA_BUF_LEN - len, | |
2a163c6d S |
202 | "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n"); |
203 | ||
204 | for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) { | |
205 | if (i == 8) { | |
206 | qcuOffset = 0; | |
207 | qcuBase++; | |
208 | } | |
209 | ||
210 | if (i == 6) { | |
211 | dcuOffset = 0; | |
212 | dcuBase++; | |
213 | } | |
214 | ||
991a0987 | 215 | len += snprintf(buf + len, DMA_BUF_LEN - len, |
2a163c6d S |
216 | "%2d %2x %1x %2x %2x\n", |
217 | i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset, | |
218 | (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3), | |
219 | val[2] & (0x7 << (i * 3)) >> (i * 3), | |
220 | (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset); | |
221 | } | |
222 | ||
991a0987 | 223 | len += snprintf(buf + len, DMA_BUF_LEN - len, "\n"); |
2a163c6d | 224 | |
991a0987 | 225 | len += snprintf(buf + len, DMA_BUF_LEN - len, |
2a163c6d S |
226 | "qcu_stitch state: %2x qcu_fetch state: %2x\n", |
227 | (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22); | |
991a0987 | 228 | len += snprintf(buf + len, DMA_BUF_LEN - len, |
2a163c6d S |
229 | "qcu_complete state: %2x dcu_complete state: %2x\n", |
230 | (val[3] & 0x1c000000) >> 26, (val[6] & 0x3)); | |
991a0987 | 231 | len += snprintf(buf + len, DMA_BUF_LEN - len, |
2a163c6d S |
232 | "dcu_arb state: %2x dcu_fp state: %2x\n", |
233 | (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27); | |
991a0987 | 234 | len += snprintf(buf + len, DMA_BUF_LEN - len, |
2a163c6d S |
235 | "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n", |
236 | (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10); | |
991a0987 | 237 | len += snprintf(buf + len, DMA_BUF_LEN - len, |
2a163c6d S |
238 | "txfifo_valid_0: %1d txfifo_valid_1: %1d\n", |
239 | (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12); | |
991a0987 | 240 | len += snprintf(buf + len, DMA_BUF_LEN - len, |
2a163c6d S |
241 | "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n", |
242 | (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17); | |
243 | ||
60ece404 | 244 | len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n", |
475a6e4d | 245 | REG_READ_D(ah, AR_OBS_BUS_1)); |
991a0987 | 246 | len += snprintf(buf + len, DMA_BUF_LEN - len, |
60ece404 | 247 | "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR)); |
2a163c6d | 248 | |
7cf4a2e7 S |
249 | ath9k_ps_restore(sc); |
250 | ||
2b87f3aa DC |
251 | if (len > DMA_BUF_LEN) |
252 | len = DMA_BUF_LEN; | |
253 | ||
991a0987 PR |
254 | retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
255 | kfree(buf); | |
256 | return retval; | |
2a163c6d S |
257 | } |
258 | ||
259 | static const struct file_operations fops_dma = { | |
260 | .read = read_file_dma, | |
261 | .open = ath9k_debugfs_open, | |
262 | .owner = THIS_MODULE | |
263 | }; | |
264 | ||
817e11de S |
265 | |
266 | void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status) | |
267 | { | |
268 | if (status) | |
17d7904d | 269 | sc->debug.stats.istats.total++; |
a9616f41 LR |
270 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
271 | if (status & ATH9K_INT_RXLP) | |
272 | sc->debug.stats.istats.rxlp++; | |
273 | if (status & ATH9K_INT_RXHP) | |
274 | sc->debug.stats.istats.rxhp++; | |
08578b8f LR |
275 | if (status & ATH9K_INT_BB_WATCHDOG) |
276 | sc->debug.stats.istats.bb_watchdog++; | |
a9616f41 LR |
277 | } else { |
278 | if (status & ATH9K_INT_RX) | |
279 | sc->debug.stats.istats.rxok++; | |
280 | } | |
817e11de | 281 | if (status & ATH9K_INT_RXEOL) |
17d7904d | 282 | sc->debug.stats.istats.rxeol++; |
817e11de | 283 | if (status & ATH9K_INT_RXORN) |
17d7904d | 284 | sc->debug.stats.istats.rxorn++; |
817e11de | 285 | if (status & ATH9K_INT_TX) |
17d7904d | 286 | sc->debug.stats.istats.txok++; |
817e11de | 287 | if (status & ATH9K_INT_TXURN) |
17d7904d | 288 | sc->debug.stats.istats.txurn++; |
817e11de | 289 | if (status & ATH9K_INT_MIB) |
17d7904d | 290 | sc->debug.stats.istats.mib++; |
817e11de | 291 | if (status & ATH9K_INT_RXPHY) |
17d7904d | 292 | sc->debug.stats.istats.rxphyerr++; |
817e11de | 293 | if (status & ATH9K_INT_RXKCM) |
17d7904d | 294 | sc->debug.stats.istats.rx_keycache_miss++; |
817e11de | 295 | if (status & ATH9K_INT_SWBA) |
17d7904d | 296 | sc->debug.stats.istats.swba++; |
817e11de | 297 | if (status & ATH9K_INT_BMISS) |
17d7904d | 298 | sc->debug.stats.istats.bmiss++; |
817e11de | 299 | if (status & ATH9K_INT_BNR) |
17d7904d | 300 | sc->debug.stats.istats.bnr++; |
817e11de | 301 | if (status & ATH9K_INT_CST) |
17d7904d | 302 | sc->debug.stats.istats.cst++; |
817e11de | 303 | if (status & ATH9K_INT_GTT) |
17d7904d | 304 | sc->debug.stats.istats.gtt++; |
817e11de | 305 | if (status & ATH9K_INT_TIM) |
17d7904d | 306 | sc->debug.stats.istats.tim++; |
817e11de | 307 | if (status & ATH9K_INT_CABEND) |
17d7904d | 308 | sc->debug.stats.istats.cabend++; |
817e11de | 309 | if (status & ATH9K_INT_DTIMSYNC) |
17d7904d | 310 | sc->debug.stats.istats.dtimsync++; |
817e11de | 311 | if (status & ATH9K_INT_DTIM) |
17d7904d | 312 | sc->debug.stats.istats.dtim++; |
817e11de S |
313 | } |
314 | ||
315 | static ssize_t read_file_interrupt(struct file *file, char __user *user_buf, | |
316 | size_t count, loff_t *ppos) | |
317 | { | |
318 | struct ath_softc *sc = file->private_data; | |
319 | char buf[512]; | |
320 | unsigned int len = 0; | |
321 | ||
a9616f41 LR |
322 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
323 | len += snprintf(buf + len, sizeof(buf) - len, | |
324 | "%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp); | |
325 | len += snprintf(buf + len, sizeof(buf) - len, | |
326 | "%8s: %10u\n", "RXHP", sc->debug.stats.istats.rxhp); | |
08578b8f LR |
327 | len += snprintf(buf + len, sizeof(buf) - len, |
328 | "%8s: %10u\n", "WATCHDOG", | |
329 | sc->debug.stats.istats.bb_watchdog); | |
a9616f41 LR |
330 | } else { |
331 | len += snprintf(buf + len, sizeof(buf) - len, | |
332 | "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok); | |
333 | } | |
817e11de | 334 | len += snprintf(buf + len, sizeof(buf) - len, |
17d7904d | 335 | "%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol); |
817e11de | 336 | len += snprintf(buf + len, sizeof(buf) - len, |
17d7904d | 337 | "%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn); |
817e11de | 338 | len += snprintf(buf + len, sizeof(buf) - len, |
17d7904d | 339 | "%8s: %10u\n", "TX", sc->debug.stats.istats.txok); |
817e11de | 340 | len += snprintf(buf + len, sizeof(buf) - len, |
17d7904d | 341 | "%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn); |
817e11de | 342 | len += snprintf(buf + len, sizeof(buf) - len, |
17d7904d | 343 | "%8s: %10u\n", "MIB", sc->debug.stats.istats.mib); |
817e11de | 344 | len += snprintf(buf + len, sizeof(buf) - len, |
17d7904d | 345 | "%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr); |
817e11de | 346 | len += snprintf(buf + len, sizeof(buf) - len, |
17d7904d | 347 | "%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss); |
817e11de | 348 | len += snprintf(buf + len, sizeof(buf) - len, |
17d7904d | 349 | "%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba); |
817e11de | 350 | len += snprintf(buf + len, sizeof(buf) - len, |
17d7904d | 351 | "%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss); |
817e11de | 352 | len += snprintf(buf + len, sizeof(buf) - len, |
17d7904d | 353 | "%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr); |
817e11de | 354 | len += snprintf(buf + len, sizeof(buf) - len, |
17d7904d | 355 | "%8s: %10u\n", "CST", sc->debug.stats.istats.cst); |
817e11de | 356 | len += snprintf(buf + len, sizeof(buf) - len, |
17d7904d | 357 | "%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt); |
817e11de | 358 | len += snprintf(buf + len, sizeof(buf) - len, |
17d7904d | 359 | "%8s: %10u\n", "TIM", sc->debug.stats.istats.tim); |
817e11de | 360 | len += snprintf(buf + len, sizeof(buf) - len, |
17d7904d | 361 | "%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend); |
817e11de | 362 | len += snprintf(buf + len, sizeof(buf) - len, |
17d7904d | 363 | "%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync); |
817e11de | 364 | len += snprintf(buf + len, sizeof(buf) - len, |
17d7904d | 365 | "%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim); |
817e11de | 366 | len += snprintf(buf + len, sizeof(buf) - len, |
17d7904d | 367 | "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total); |
817e11de | 368 | |
2b87f3aa DC |
369 | if (len > sizeof(buf)) |
370 | len = sizeof(buf); | |
371 | ||
817e11de S |
372 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
373 | } | |
374 | ||
375 | static const struct file_operations fops_interrupt = { | |
376 | .read = read_file_interrupt, | |
377 | .open = ath9k_debugfs_open, | |
378 | .owner = THIS_MODULE | |
379 | }; | |
380 | ||
545750d3 | 381 | void ath_debug_stat_rc(struct ath_softc *sc, int final_rate) |
7a7dec65 | 382 | { |
bedf087a | 383 | struct ath_rc_stats *stats; |
7a7dec65 | 384 | |
545750d3 | 385 | stats = &sc->debug.stats.rcstats[final_rate]; |
bedf087a | 386 | stats->success++; |
7a7dec65 S |
387 | } |
388 | ||
029bc432 | 389 | void ath_debug_stat_retries(struct ath_softc *sc, int rix, |
9e712790 | 390 | int xretries, int retries, u8 per) |
029bc432 | 391 | { |
bedf087a | 392 | struct ath_rc_stats *stats = &sc->debug.stats.rcstats[rix]; |
029bc432 | 393 | |
bedf087a JH |
394 | stats->xretries += xretries; |
395 | stats->retries += retries; | |
396 | stats->per = per; | |
029bc432 S |
397 | } |
398 | ||
bedf087a JH |
399 | static ssize_t read_file_rcstat(struct file *file, char __user *user_buf, |
400 | size_t count, loff_t *ppos) | |
7a7dec65 S |
401 | { |
402 | struct ath_softc *sc = file->private_data; | |
bedf087a JH |
403 | char *buf; |
404 | unsigned int len = 0, max; | |
7a7dec65 | 405 | int i = 0; |
bedf087a | 406 | ssize_t retval; |
7a7dec65 | 407 | |
bedf087a JH |
408 | if (sc->cur_rate_table == NULL) |
409 | return 0; | |
7a7dec65 | 410 | |
2b87f3aa DC |
411 | max = 80 + sc->cur_rate_table->rate_cnt * 1024 + 1; |
412 | buf = kmalloc(max, GFP_KERNEL); | |
bedf087a | 413 | if (buf == NULL) |
04236066 | 414 | return -ENOMEM; |
7a7dec65 | 415 | |
c755ad34 LR |
416 | len += sprintf(buf, "%6s %6s %6s " |
417 | "%10s %10s %10s %10s\n", | |
418 | "HT", "MCS", "Rate", | |
419 | "Success", "Retries", "XRetries", "PER"); | |
7a7dec65 S |
420 | |
421 | for (i = 0; i < sc->cur_rate_table->rate_cnt; i++) { | |
bedf087a JH |
422 | u32 ratekbps = sc->cur_rate_table->info[i].ratekbps; |
423 | struct ath_rc_stats *stats = &sc->debug.stats.rcstats[i]; | |
c755ad34 LR |
424 | char mcs[5]; |
425 | char htmode[5]; | |
426 | int used_mcs = 0, used_htmode = 0; | |
427 | ||
428 | if (WLAN_RC_PHY_HT(sc->cur_rate_table->info[i].phy)) { | |
429 | used_mcs = snprintf(mcs, 5, "%d", | |
430 | sc->cur_rate_table->info[i].ratecode); | |
431 | ||
432 | if (WLAN_RC_PHY_40(sc->cur_rate_table->info[i].phy)) | |
433 | used_htmode = snprintf(htmode, 5, "HT40"); | |
434 | else if (WLAN_RC_PHY_20(sc->cur_rate_table->info[i].phy)) | |
435 | used_htmode = snprintf(htmode, 5, "HT20"); | |
436 | else | |
437 | used_htmode = snprintf(htmode, 5, "????"); | |
438 | } | |
439 | ||
440 | mcs[used_mcs] = '\0'; | |
441 | htmode[used_htmode] = '\0'; | |
bedf087a JH |
442 | |
443 | len += snprintf(buf + len, max - len, | |
c755ad34 LR |
444 | "%6s %6s %3u.%d: " |
445 | "%10u %10u %10u %10u\n", | |
446 | htmode, | |
447 | mcs, | |
448 | ratekbps / 1000, | |
449 | (ratekbps % 1000) / 100, | |
450 | stats->success, | |
451 | stats->retries, | |
452 | stats->xretries, | |
bedf087a | 453 | stats->per); |
7a7dec65 S |
454 | } |
455 | ||
2b87f3aa DC |
456 | if (len > max) |
457 | len = max; | |
458 | ||
bedf087a JH |
459 | retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
460 | kfree(buf); | |
461 | return retval; | |
7a7dec65 S |
462 | } |
463 | ||
464 | static const struct file_operations fops_rcstat = { | |
465 | .read = read_file_rcstat, | |
466 | .open = ath9k_debugfs_open, | |
467 | .owner = THIS_MODULE | |
468 | }; | |
27abe060 | 469 | |
39d89cd3 JM |
470 | static const char * ath_wiphy_state_str(enum ath_wiphy_state state) |
471 | { | |
472 | switch (state) { | |
473 | case ATH_WIPHY_INACTIVE: | |
474 | return "INACTIVE"; | |
475 | case ATH_WIPHY_ACTIVE: | |
476 | return "ACTIVE"; | |
477 | case ATH_WIPHY_PAUSING: | |
478 | return "PAUSING"; | |
479 | case ATH_WIPHY_PAUSED: | |
480 | return "PAUSED"; | |
481 | case ATH_WIPHY_SCAN: | |
482 | return "SCAN"; | |
483 | } | |
484 | return "?"; | |
485 | } | |
486 | ||
487 | static ssize_t read_file_wiphy(struct file *file, char __user *user_buf, | |
488 | size_t count, loff_t *ppos) | |
489 | { | |
490 | struct ath_softc *sc = file->private_data; | |
491 | char buf[512]; | |
492 | unsigned int len = 0; | |
493 | int i; | |
494 | u8 addr[ETH_ALEN]; | |
39057512 | 495 | u32 tmp; |
39d89cd3 JM |
496 | |
497 | len += snprintf(buf + len, sizeof(buf) - len, | |
498 | "primary: %s (%s chan=%d ht=%d)\n", | |
499 | wiphy_name(sc->pri_wiphy->hw->wiphy), | |
500 | ath_wiphy_state_str(sc->pri_wiphy->state), | |
501 | sc->pri_wiphy->chan_idx, sc->pri_wiphy->chan_is_ht); | |
39057512 BG |
502 | |
503 | put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr); | |
504 | put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4); | |
505 | len += snprintf(buf + len, sizeof(buf) - len, | |
506 | "addr: %pM\n", addr); | |
507 | put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr); | |
508 | put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4); | |
509 | len += snprintf(buf + len, sizeof(buf) - len, | |
510 | "addrmask: %pM\n", addr); | |
511 | tmp = ath9k_hw_getrxfilter(sc->sc_ah); | |
512 | len += snprintf(buf + len, sizeof(buf) - len, | |
513 | "rfilt: 0x%x", tmp); | |
514 | if (tmp & ATH9K_RX_FILTER_UCAST) | |
515 | len += snprintf(buf + len, sizeof(buf) - len, " UCAST"); | |
516 | if (tmp & ATH9K_RX_FILTER_MCAST) | |
517 | len += snprintf(buf + len, sizeof(buf) - len, " MCAST"); | |
518 | if (tmp & ATH9K_RX_FILTER_BCAST) | |
519 | len += snprintf(buf + len, sizeof(buf) - len, " BCAST"); | |
520 | if (tmp & ATH9K_RX_FILTER_CONTROL) | |
521 | len += snprintf(buf + len, sizeof(buf) - len, " CONTROL"); | |
522 | if (tmp & ATH9K_RX_FILTER_BEACON) | |
523 | len += snprintf(buf + len, sizeof(buf) - len, " BEACON"); | |
524 | if (tmp & ATH9K_RX_FILTER_PROM) | |
525 | len += snprintf(buf + len, sizeof(buf) - len, " PROM"); | |
526 | if (tmp & ATH9K_RX_FILTER_PROBEREQ) | |
527 | len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ"); | |
528 | if (tmp & ATH9K_RX_FILTER_PHYERR) | |
529 | len += snprintf(buf + len, sizeof(buf) - len, " PHYERR"); | |
530 | if (tmp & ATH9K_RX_FILTER_MYBEACON) | |
531 | len += snprintf(buf + len, sizeof(buf) - len, " MYBEACON"); | |
532 | if (tmp & ATH9K_RX_FILTER_COMP_BAR) | |
533 | len += snprintf(buf + len, sizeof(buf) - len, " COMP_BAR"); | |
534 | if (tmp & ATH9K_RX_FILTER_PSPOLL) | |
535 | len += snprintf(buf + len, sizeof(buf) - len, " PSPOLL"); | |
536 | if (tmp & ATH9K_RX_FILTER_PHYRADAR) | |
537 | len += snprintf(buf + len, sizeof(buf) - len, " PHYRADAR"); | |
538 | if (tmp & ATH9K_RX_FILTER_MCAST_BCAST_ALL) | |
539 | len += snprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL\n"); | |
540 | else | |
541 | len += snprintf(buf + len, sizeof(buf) - len, "\n"); | |
542 | ||
543 | /* Put variable-length stuff down here, and check for overflows. */ | |
39d89cd3 JM |
544 | for (i = 0; i < sc->num_sec_wiphy; i++) { |
545 | struct ath_wiphy *aphy = sc->sec_wiphy[i]; | |
546 | if (aphy == NULL) | |
547 | continue; | |
548 | len += snprintf(buf + len, sizeof(buf) - len, | |
549 | "secondary: %s (%s chan=%d ht=%d)\n", | |
550 | wiphy_name(aphy->hw->wiphy), | |
551 | ath_wiphy_state_str(aphy->state), | |
552 | aphy->chan_idx, aphy->chan_is_ht); | |
553 | } | |
2b87f3aa DC |
554 | if (len > sizeof(buf)) |
555 | len = sizeof(buf); | |
556 | ||
39d89cd3 JM |
557 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
558 | } | |
559 | ||
560 | static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name) | |
561 | { | |
562 | int i; | |
563 | if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0) | |
564 | return sc->pri_wiphy; | |
565 | for (i = 0; i < sc->num_sec_wiphy; i++) { | |
566 | struct ath_wiphy *aphy = sc->sec_wiphy[i]; | |
567 | if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0) | |
568 | return aphy; | |
569 | } | |
570 | return NULL; | |
571 | } | |
572 | ||
573 | static int del_wiphy(struct ath_softc *sc, const char *name) | |
574 | { | |
575 | struct ath_wiphy *aphy = get_wiphy(sc, name); | |
576 | if (!aphy) | |
577 | return -ENOENT; | |
578 | return ath9k_wiphy_del(aphy); | |
579 | } | |
580 | ||
581 | static int pause_wiphy(struct ath_softc *sc, const char *name) | |
582 | { | |
583 | struct ath_wiphy *aphy = get_wiphy(sc, name); | |
584 | if (!aphy) | |
585 | return -ENOENT; | |
586 | return ath9k_wiphy_pause(aphy); | |
587 | } | |
588 | ||
589 | static int unpause_wiphy(struct ath_softc *sc, const char *name) | |
590 | { | |
591 | struct ath_wiphy *aphy = get_wiphy(sc, name); | |
592 | if (!aphy) | |
593 | return -ENOENT; | |
594 | return ath9k_wiphy_unpause(aphy); | |
595 | } | |
596 | ||
597 | static int select_wiphy(struct ath_softc *sc, const char *name) | |
598 | { | |
599 | struct ath_wiphy *aphy = get_wiphy(sc, name); | |
600 | if (!aphy) | |
601 | return -ENOENT; | |
602 | return ath9k_wiphy_select(aphy); | |
603 | } | |
604 | ||
605 | static int schedule_wiphy(struct ath_softc *sc, const char *msec) | |
606 | { | |
607 | ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0)); | |
608 | return 0; | |
609 | } | |
610 | ||
611 | static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf, | |
612 | size_t count, loff_t *ppos) | |
613 | { | |
614 | struct ath_softc *sc = file->private_data; | |
615 | char buf[50]; | |
616 | size_t len; | |
617 | ||
618 | len = min(count, sizeof(buf) - 1); | |
619 | if (copy_from_user(buf, user_buf, len)) | |
620 | return -EFAULT; | |
621 | buf[len] = '\0'; | |
622 | if (len > 0 && buf[len - 1] == '\n') | |
623 | buf[len - 1] = '\0'; | |
624 | ||
625 | if (strncmp(buf, "add", 3) == 0) { | |
626 | int res = ath9k_wiphy_add(sc); | |
627 | if (res < 0) | |
628 | return res; | |
629 | } else if (strncmp(buf, "del=", 4) == 0) { | |
630 | int res = del_wiphy(sc, buf + 4); | |
631 | if (res < 0) | |
632 | return res; | |
633 | } else if (strncmp(buf, "pause=", 6) == 0) { | |
634 | int res = pause_wiphy(sc, buf + 6); | |
635 | if (res < 0) | |
636 | return res; | |
637 | } else if (strncmp(buf, "unpause=", 8) == 0) { | |
638 | int res = unpause_wiphy(sc, buf + 8); | |
639 | if (res < 0) | |
640 | return res; | |
641 | } else if (strncmp(buf, "select=", 7) == 0) { | |
642 | int res = select_wiphy(sc, buf + 7); | |
643 | if (res < 0) | |
644 | return res; | |
645 | } else if (strncmp(buf, "schedule=", 9) == 0) { | |
646 | int res = schedule_wiphy(sc, buf + 9); | |
647 | if (res < 0) | |
648 | return res; | |
649 | } else | |
650 | return -EOPNOTSUPP; | |
651 | ||
652 | return count; | |
653 | } | |
654 | ||
655 | static const struct file_operations fops_wiphy = { | |
656 | .read = read_file_wiphy, | |
657 | .write = write_file_wiphy, | |
658 | .open = ath9k_debugfs_open, | |
659 | .owner = THIS_MODULE | |
660 | }; | |
661 | ||
fec247c0 S |
662 | #define PR(str, elem) \ |
663 | do { \ | |
664 | len += snprintf(buf + len, size - len, \ | |
665 | "%s%13u%11u%10u%10u\n", str, \ | |
1d2231e2 FF |
666 | sc->debug.stats.txstats[sc->tx.hwq_map[WME_AC_BE]].elem, \ |
667 | sc->debug.stats.txstats[sc->tx.hwq_map[WME_AC_BK]].elem, \ | |
668 | sc->debug.stats.txstats[sc->tx.hwq_map[WME_AC_VI]].elem, \ | |
669 | sc->debug.stats.txstats[sc->tx.hwq_map[WME_AC_VO]].elem); \ | |
fec247c0 S |
670 | } while(0) |
671 | ||
672 | static ssize_t read_file_xmit(struct file *file, char __user *user_buf, | |
673 | size_t count, loff_t *ppos) | |
674 | { | |
675 | struct ath_softc *sc = file->private_data; | |
676 | char *buf; | |
677 | unsigned int len = 0, size = 2048; | |
678 | ssize_t retval = 0; | |
679 | ||
680 | buf = kzalloc(size, GFP_KERNEL); | |
681 | if (buf == NULL) | |
04236066 | 682 | return -ENOMEM; |
fec247c0 S |
683 | |
684 | len += sprintf(buf, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO"); | |
685 | ||
686 | PR("MPDUs Queued: ", queued); | |
687 | PR("MPDUs Completed: ", completed); | |
688 | PR("Aggregates: ", a_aggr); | |
689 | PR("AMPDUs Queued: ", a_queued); | |
690 | PR("AMPDUs Completed:", a_completed); | |
691 | PR("AMPDUs Retried: ", a_retries); | |
692 | PR("AMPDUs XRetried: ", a_xretries); | |
693 | PR("FIFO Underrun: ", fifo_underrun); | |
694 | PR("TXOP Exceeded: ", xtxop); | |
695 | PR("TXTIMER Expiry: ", timer_exp); | |
696 | PR("DESC CFG Error: ", desc_cfg_err); | |
697 | PR("DATA Underrun: ", data_underrun); | |
698 | PR("DELIM Underrun: ", delim_underrun); | |
699 | ||
2b87f3aa DC |
700 | if (len > size) |
701 | len = size; | |
702 | ||
fec247c0 S |
703 | retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
704 | kfree(buf); | |
705 | ||
706 | return retval; | |
707 | } | |
708 | ||
709 | void ath_debug_stat_tx(struct ath_softc *sc, struct ath_txq *txq, | |
db1a052b | 710 | struct ath_buf *bf, struct ath_tx_status *ts) |
fec247c0 | 711 | { |
fec247c0 S |
712 | if (bf_isampdu(bf)) { |
713 | if (bf_isxretried(bf)) | |
714 | TX_STAT_INC(txq->axq_qnum, a_xretries); | |
715 | else | |
716 | TX_STAT_INC(txq->axq_qnum, a_completed); | |
717 | } else { | |
718 | TX_STAT_INC(txq->axq_qnum, completed); | |
719 | } | |
720 | ||
db1a052b | 721 | if (ts->ts_status & ATH9K_TXERR_FIFO) |
fec247c0 | 722 | TX_STAT_INC(txq->axq_qnum, fifo_underrun); |
db1a052b | 723 | if (ts->ts_status & ATH9K_TXERR_XTXOP) |
fec247c0 | 724 | TX_STAT_INC(txq->axq_qnum, xtxop); |
db1a052b | 725 | if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED) |
fec247c0 | 726 | TX_STAT_INC(txq->axq_qnum, timer_exp); |
db1a052b | 727 | if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR) |
fec247c0 | 728 | TX_STAT_INC(txq->axq_qnum, desc_cfg_err); |
db1a052b | 729 | if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN) |
fec247c0 | 730 | TX_STAT_INC(txq->axq_qnum, data_underrun); |
db1a052b | 731 | if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN) |
fec247c0 S |
732 | TX_STAT_INC(txq->axq_qnum, delim_underrun); |
733 | } | |
734 | ||
735 | static const struct file_operations fops_xmit = { | |
736 | .read = read_file_xmit, | |
737 | .open = ath9k_debugfs_open, | |
738 | .owner = THIS_MODULE | |
739 | }; | |
39d89cd3 | 740 | |
1395d3f0 S |
741 | static ssize_t read_file_recv(struct file *file, char __user *user_buf, |
742 | size_t count, loff_t *ppos) | |
743 | { | |
744 | #define PHY_ERR(s, p) \ | |
745 | len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \ | |
746 | sc->debug.stats.rxstats.phy_err_stats[p]); | |
747 | ||
748 | struct ath_softc *sc = file->private_data; | |
749 | char *buf; | |
750 | unsigned int len = 0, size = 1152; | |
751 | ssize_t retval = 0; | |
752 | ||
753 | buf = kzalloc(size, GFP_KERNEL); | |
754 | if (buf == NULL) | |
04236066 | 755 | return -ENOMEM; |
1395d3f0 S |
756 | |
757 | len += snprintf(buf + len, size - len, | |
758 | "%18s : %10u\n", "CRC ERR", | |
759 | sc->debug.stats.rxstats.crc_err); | |
760 | len += snprintf(buf + len, size - len, | |
761 | "%18s : %10u\n", "DECRYPT CRC ERR", | |
762 | sc->debug.stats.rxstats.decrypt_crc_err); | |
763 | len += snprintf(buf + len, size - len, | |
764 | "%18s : %10u\n", "PHY ERR", | |
765 | sc->debug.stats.rxstats.phy_err); | |
766 | len += snprintf(buf + len, size - len, | |
767 | "%18s : %10u\n", "MIC ERR", | |
768 | sc->debug.stats.rxstats.mic_err); | |
769 | len += snprintf(buf + len, size - len, | |
770 | "%18s : %10u\n", "PRE-DELIM CRC ERR", | |
771 | sc->debug.stats.rxstats.pre_delim_crc_err); | |
772 | len += snprintf(buf + len, size - len, | |
773 | "%18s : %10u\n", "POST-DELIM CRC ERR", | |
774 | sc->debug.stats.rxstats.post_delim_crc_err); | |
775 | len += snprintf(buf + len, size - len, | |
776 | "%18s : %10u\n", "DECRYPT BUSY ERR", | |
777 | sc->debug.stats.rxstats.decrypt_busy_err); | |
778 | ||
779 | PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN); | |
780 | PHY_ERR("TIMING", ATH9K_PHYERR_TIMING); | |
781 | PHY_ERR("PARITY", ATH9K_PHYERR_PARITY); | |
782 | PHY_ERR("RATE", ATH9K_PHYERR_RATE); | |
783 | PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH); | |
784 | PHY_ERR("RADAR", ATH9K_PHYERR_RADAR); | |
785 | PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE); | |
786 | PHY_ERR("TOR", ATH9K_PHYERR_TOR); | |
787 | PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING); | |
788 | PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY); | |
789 | PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL); | |
790 | PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL); | |
791 | PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP); | |
792 | PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE); | |
793 | PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART); | |
794 | PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT); | |
795 | PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING); | |
796 | PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC); | |
797 | PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL); | |
798 | PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE); | |
799 | PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART); | |
800 | PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL); | |
801 | PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP); | |
802 | PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR); | |
803 | PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL); | |
804 | PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL); | |
805 | ||
2b87f3aa DC |
806 | if (len > size) |
807 | len = size; | |
808 | ||
1395d3f0 S |
809 | retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
810 | kfree(buf); | |
811 | ||
812 | return retval; | |
813 | ||
814 | #undef PHY_ERR | |
815 | } | |
816 | ||
8e6f5aa2 | 817 | void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs) |
1395d3f0 S |
818 | { |
819 | #define RX_STAT_INC(c) sc->debug.stats.rxstats.c++ | |
820 | #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++ | |
821 | ||
1395d3f0 S |
822 | u32 phyerr; |
823 | ||
8e6f5aa2 | 824 | if (rs->rs_status & ATH9K_RXERR_CRC) |
1395d3f0 | 825 | RX_STAT_INC(crc_err); |
8e6f5aa2 | 826 | if (rs->rs_status & ATH9K_RXERR_DECRYPT) |
1395d3f0 | 827 | RX_STAT_INC(decrypt_crc_err); |
8e6f5aa2 | 828 | if (rs->rs_status & ATH9K_RXERR_MIC) |
1395d3f0 | 829 | RX_STAT_INC(mic_err); |
8e6f5aa2 | 830 | if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE) |
1395d3f0 | 831 | RX_STAT_INC(pre_delim_crc_err); |
8e6f5aa2 | 832 | if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST) |
1395d3f0 | 833 | RX_STAT_INC(post_delim_crc_err); |
8e6f5aa2 | 834 | if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY) |
1395d3f0 S |
835 | RX_STAT_INC(decrypt_busy_err); |
836 | ||
8e6f5aa2 | 837 | if (rs->rs_status & ATH9K_RXERR_PHY) { |
1395d3f0 | 838 | RX_STAT_INC(phy_err); |
8e6f5aa2 | 839 | phyerr = rs->rs_phyerr & 0x24; |
1395d3f0 S |
840 | RX_PHY_ERR_INC(phyerr); |
841 | } | |
842 | ||
843 | #undef RX_STAT_INC | |
844 | #undef RX_PHY_ERR_INC | |
845 | } | |
846 | ||
847 | static const struct file_operations fops_recv = { | |
848 | .read = read_file_recv, | |
849 | .open = ath9k_debugfs_open, | |
850 | .owner = THIS_MODULE | |
851 | }; | |
852 | ||
9bff0bc4 FF |
853 | static ssize_t read_file_regidx(struct file *file, char __user *user_buf, |
854 | size_t count, loff_t *ppos) | |
855 | { | |
856 | struct ath_softc *sc = file->private_data; | |
857 | char buf[32]; | |
858 | unsigned int len; | |
859 | ||
2b87f3aa | 860 | len = sprintf(buf, "0x%08x\n", sc->debug.regidx); |
9bff0bc4 FF |
861 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
862 | } | |
863 | ||
864 | static ssize_t write_file_regidx(struct file *file, const char __user *user_buf, | |
865 | size_t count, loff_t *ppos) | |
866 | { | |
867 | struct ath_softc *sc = file->private_data; | |
868 | unsigned long regidx; | |
869 | char buf[32]; | |
870 | ssize_t len; | |
871 | ||
872 | len = min(count, sizeof(buf) - 1); | |
873 | if (copy_from_user(buf, user_buf, len)) | |
04236066 | 874 | return -EFAULT; |
9bff0bc4 FF |
875 | |
876 | buf[len] = '\0'; | |
877 | if (strict_strtoul(buf, 0, ®idx)) | |
878 | return -EINVAL; | |
879 | ||
880 | sc->debug.regidx = regidx; | |
881 | return count; | |
882 | } | |
883 | ||
884 | static const struct file_operations fops_regidx = { | |
885 | .read = read_file_regidx, | |
886 | .write = write_file_regidx, | |
887 | .open = ath9k_debugfs_open, | |
888 | .owner = THIS_MODULE | |
889 | }; | |
890 | ||
891 | static ssize_t read_file_regval(struct file *file, char __user *user_buf, | |
892 | size_t count, loff_t *ppos) | |
893 | { | |
894 | struct ath_softc *sc = file->private_data; | |
895 | struct ath_hw *ah = sc->sc_ah; | |
896 | char buf[32]; | |
897 | unsigned int len; | |
898 | u32 regval; | |
899 | ||
900 | regval = REG_READ_D(ah, sc->debug.regidx); | |
2b87f3aa | 901 | len = sprintf(buf, "0x%08x\n", regval); |
9bff0bc4 FF |
902 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
903 | } | |
904 | ||
905 | static ssize_t write_file_regval(struct file *file, const char __user *user_buf, | |
906 | size_t count, loff_t *ppos) | |
907 | { | |
908 | struct ath_softc *sc = file->private_data; | |
909 | struct ath_hw *ah = sc->sc_ah; | |
910 | unsigned long regval; | |
911 | char buf[32]; | |
912 | ssize_t len; | |
913 | ||
914 | len = min(count, sizeof(buf) - 1); | |
915 | if (copy_from_user(buf, user_buf, len)) | |
04236066 | 916 | return -EFAULT; |
9bff0bc4 FF |
917 | |
918 | buf[len] = '\0'; | |
919 | if (strict_strtoul(buf, 0, ®val)) | |
920 | return -EINVAL; | |
921 | ||
922 | REG_WRITE_D(ah, sc->debug.regidx, regval); | |
923 | return count; | |
924 | } | |
925 | ||
926 | static const struct file_operations fops_regval = { | |
927 | .read = read_file_regval, | |
928 | .write = write_file_regval, | |
929 | .open = ath9k_debugfs_open, | |
930 | .owner = THIS_MODULE | |
931 | }; | |
932 | ||
4d6b228d | 933 | int ath9k_init_debug(struct ath_hw *ah) |
88b126af | 934 | { |
bc974f4a LR |
935 | struct ath_common *common = ath9k_hw_common(ah); |
936 | struct ath_softc *sc = (struct ath_softc *) common->priv; | |
4d6b228d | 937 | |
7dd58748 S |
938 | if (!ath9k_debugfs_root) |
939 | return -ENOENT; | |
940 | ||
17d7904d | 941 | sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy), |
19d8bc22 | 942 | ath9k_debugfs_root); |
17d7904d | 943 | if (!sc->debug.debugfs_phy) |
c8a72c00 | 944 | return -ENOMEM; |
826d2680 | 945 | |
a830df07 | 946 | #ifdef CONFIG_ATH_DEBUG |
c8a72c00 FF |
947 | if (!debugfs_create_file("debug", S_IRUSR | S_IWUSR, |
948 | sc->debug.debugfs_phy, sc, &fops_debug)) | |
2493928e | 949 | goto err; |
a830df07 | 950 | #endif |
2493928e | 951 | |
c8a72c00 FF |
952 | if (!debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, |
953 | sc, &fops_dma)) | |
2a163c6d S |
954 | goto err; |
955 | ||
c8a72c00 FF |
956 | if (!debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, |
957 | sc, &fops_interrupt)) | |
817e11de S |
958 | goto err; |
959 | ||
c8a72c00 FF |
960 | if (!debugfs_create_file("rcstat", S_IRUSR, sc->debug.debugfs_phy, |
961 | sc, &fops_rcstat)) | |
7a7dec65 S |
962 | goto err; |
963 | ||
c8a72c00 FF |
964 | if (!debugfs_create_file("wiphy", S_IRUSR | S_IWUSR, |
965 | sc->debug.debugfs_phy, sc, &fops_wiphy)) | |
39d89cd3 JM |
966 | goto err; |
967 | ||
c8a72c00 FF |
968 | if (!debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, |
969 | sc, &fops_xmit)) | |
2a163c6d S |
970 | goto err; |
971 | ||
c8a72c00 FF |
972 | if (!debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy, |
973 | sc, &fops_recv)) | |
817e11de S |
974 | goto err; |
975 | ||
15340694 FF |
976 | if (!debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR, |
977 | sc->debug.debugfs_phy, sc, &fops_rx_chainmask)) | |
7a7dec65 S |
978 | goto err; |
979 | ||
15340694 FF |
980 | if (!debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR, |
981 | sc->debug.debugfs_phy, sc, &fops_tx_chainmask)) | |
39d89cd3 JM |
982 | goto err; |
983 | ||
9bff0bc4 FF |
984 | if (!debugfs_create_file("regidx", S_IRUSR | S_IWUSR, |
985 | sc->debug.debugfs_phy, sc, &fops_regidx)) | |
fec247c0 S |
986 | goto err; |
987 | ||
9bff0bc4 FF |
988 | if (!debugfs_create_file("regval", S_IRUSR | S_IWUSR, |
989 | sc->debug.debugfs_phy, sc, &fops_regval)) | |
1395d3f0 S |
990 | goto err; |
991 | ||
41f3e54d FF |
992 | if (!debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR, |
993 | sc->debug.debugfs_phy, &ah->config.cwm_ignore_extcca)) | |
994 | goto err; | |
995 | ||
9bff0bc4 | 996 | sc->debug.regidx = 0; |
826d2680 S |
997 | return 0; |
998 | err: | |
4d6b228d | 999 | ath9k_exit_debug(ah); |
826d2680 S |
1000 | return -ENOMEM; |
1001 | } | |
1002 | ||
4d6b228d | 1003 | void ath9k_exit_debug(struct ath_hw *ah) |
826d2680 | 1004 | { |
bc974f4a LR |
1005 | struct ath_common *common = ath9k_hw_common(ah); |
1006 | struct ath_softc *sc = (struct ath_softc *) common->priv; | |
4d6b228d | 1007 | |
c8a72c00 | 1008 | debugfs_remove_recursive(sc->debug.debugfs_phy); |
19d8bc22 GJ |
1009 | } |
1010 | ||
1011 | int ath9k_debug_create_root(void) | |
1012 | { | |
1013 | ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL); | |
1014 | if (!ath9k_debugfs_root) | |
1015 | return -ENOENT; | |
1016 | ||
1017 | return 0; | |
1018 | } | |
1019 | ||
1020 | void ath9k_debug_remove_root(void) | |
1021 | { | |
1022 | debugfs_remove(ath9k_debugfs_root); | |
1023 | ath9k_debugfs_root = NULL; | |
88b126af | 1024 | } |