Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1 | /* |
Bruno Randolf | be9b725 | 2008-01-23 10:27:51 +0900 | [diff] [blame] | 2 | * Copyright (c) 2007-2008 Bruno Randolf <bruno@thinktube.com> |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 3 | * |
| 4 | * This file is free software: you may copy, redistribute and/or modify it |
| 5 | * under the terms of the GNU General Public License as published by the |
| 6 | * Free Software Foundation, either version 2 of the License, or (at your |
| 7 | * option) any later version. |
| 8 | * |
| 9 | * This file is distributed in the hope that it will be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | * |
| 17 | * |
| 18 | * This file incorporates work covered by the following copyright and |
| 19 | * permission notice: |
| 20 | * |
| 21 | * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting |
| 22 | * Copyright (c) 2004-2005 Atheros Communications, Inc. |
| 23 | * Copyright (c) 2006 Devicescape Software, Inc. |
| 24 | * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com> |
| 25 | * Copyright (c) 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu> |
| 26 | * |
| 27 | * All rights reserved. |
| 28 | * |
| 29 | * Redistribution and use in source and binary forms, with or without |
| 30 | * modification, are permitted provided that the following conditions |
| 31 | * are met: |
| 32 | * 1. Redistributions of source code must retain the above copyright |
| 33 | * notice, this list of conditions and the following disclaimer, |
| 34 | * without modification. |
| 35 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 36 | * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any |
| 37 | * redistribution must be conditioned upon including a substantially |
| 38 | * similar Disclaimer requirement for further binary redistribution. |
| 39 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 40 | * of any contributors may be used to endorse or promote products derived |
| 41 | * from this software without specific prior written permission. |
| 42 | * |
| 43 | * Alternatively, this software may be distributed under the terms of the |
| 44 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 45 | * Software Foundation. |
| 46 | * |
| 47 | * NO WARRANTY |
| 48 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 49 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 50 | * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY |
| 51 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
| 52 | * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, |
| 53 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 54 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 55 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
| 56 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 57 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 58 | * THE POSSIBILITY OF SUCH DAMAGES. |
| 59 | */ |
| 60 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 61 | #include "base.h" |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 62 | #include "debug.h" |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 63 | |
| 64 | static unsigned int ath5k_debug; |
| 65 | module_param_named(debug, ath5k_debug, uint, 0); |
| 66 | |
| 67 | |
Luis R. Rodriguez | b446197 | 2008-02-04 10:03:54 -0500 | [diff] [blame] | 68 | #ifdef CONFIG_ATH5K_DEBUG |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 69 | |
| 70 | #include <linux/seq_file.h> |
| 71 | #include "reg.h" |
Bruno Randolf | 2111ac0 | 2010-04-02 18:44:08 +0900 | [diff] [blame] | 72 | #include "ani.h" |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 73 | |
| 74 | static struct dentry *ath5k_global_debugfs; |
| 75 | |
| 76 | static int ath5k_debugfs_open(struct inode *inode, struct file *file) |
| 77 | { |
| 78 | file->private_data = inode->i_private; |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | |
| 83 | /* debugfs: registers */ |
| 84 | |
| 85 | struct reg { |
Jiri Slaby | 2c91108c | 2009-03-07 10:26:41 +0100 | [diff] [blame] | 86 | const char *name; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 87 | int addr; |
| 88 | }; |
| 89 | |
| 90 | #define REG_STRUCT_INIT(r) { #r, r } |
| 91 | |
| 92 | /* just a few random registers, might want to add more */ |
Jiri Slaby | 2c91108c | 2009-03-07 10:26:41 +0100 | [diff] [blame] | 93 | static const struct reg regs[] = { |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 94 | REG_STRUCT_INIT(AR5K_CR), |
| 95 | REG_STRUCT_INIT(AR5K_RXDP), |
| 96 | REG_STRUCT_INIT(AR5K_CFG), |
| 97 | REG_STRUCT_INIT(AR5K_IER), |
| 98 | REG_STRUCT_INIT(AR5K_BCR), |
| 99 | REG_STRUCT_INIT(AR5K_RTSD0), |
| 100 | REG_STRUCT_INIT(AR5K_RTSD1), |
| 101 | REG_STRUCT_INIT(AR5K_TXCFG), |
| 102 | REG_STRUCT_INIT(AR5K_RXCFG), |
| 103 | REG_STRUCT_INIT(AR5K_RXJLA), |
| 104 | REG_STRUCT_INIT(AR5K_MIBC), |
| 105 | REG_STRUCT_INIT(AR5K_TOPS), |
| 106 | REG_STRUCT_INIT(AR5K_RXNOFRM), |
| 107 | REG_STRUCT_INIT(AR5K_TXNOFRM), |
| 108 | REG_STRUCT_INIT(AR5K_RPGTO), |
| 109 | REG_STRUCT_INIT(AR5K_RFCNT), |
| 110 | REG_STRUCT_INIT(AR5K_MISC), |
| 111 | REG_STRUCT_INIT(AR5K_QCUDCU_CLKGT), |
| 112 | REG_STRUCT_INIT(AR5K_ISR), |
| 113 | REG_STRUCT_INIT(AR5K_PISR), |
| 114 | REG_STRUCT_INIT(AR5K_SISR0), |
| 115 | REG_STRUCT_INIT(AR5K_SISR1), |
| 116 | REG_STRUCT_INIT(AR5K_SISR2), |
| 117 | REG_STRUCT_INIT(AR5K_SISR3), |
| 118 | REG_STRUCT_INIT(AR5K_SISR4), |
| 119 | REG_STRUCT_INIT(AR5K_IMR), |
| 120 | REG_STRUCT_INIT(AR5K_PIMR), |
| 121 | REG_STRUCT_INIT(AR5K_SIMR0), |
| 122 | REG_STRUCT_INIT(AR5K_SIMR1), |
| 123 | REG_STRUCT_INIT(AR5K_SIMR2), |
| 124 | REG_STRUCT_INIT(AR5K_SIMR3), |
| 125 | REG_STRUCT_INIT(AR5K_SIMR4), |
| 126 | REG_STRUCT_INIT(AR5K_DCM_ADDR), |
| 127 | REG_STRUCT_INIT(AR5K_DCCFG), |
| 128 | REG_STRUCT_INIT(AR5K_CCFG), |
| 129 | REG_STRUCT_INIT(AR5K_CPC0), |
| 130 | REG_STRUCT_INIT(AR5K_CPC1), |
| 131 | REG_STRUCT_INIT(AR5K_CPC2), |
| 132 | REG_STRUCT_INIT(AR5K_CPC3), |
Nick Kossifidis | 0bacdf3 | 2008-07-30 13:18:59 +0300 | [diff] [blame] | 133 | REG_STRUCT_INIT(AR5K_CPCOVF), |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 134 | REG_STRUCT_INIT(AR5K_RESET_CTL), |
| 135 | REG_STRUCT_INIT(AR5K_SLEEP_CTL), |
| 136 | REG_STRUCT_INIT(AR5K_INTPEND), |
| 137 | REG_STRUCT_INIT(AR5K_SFR), |
| 138 | REG_STRUCT_INIT(AR5K_PCICFG), |
| 139 | REG_STRUCT_INIT(AR5K_GPIOCR), |
| 140 | REG_STRUCT_INIT(AR5K_GPIODO), |
| 141 | REG_STRUCT_INIT(AR5K_SREV), |
| 142 | }; |
| 143 | |
| 144 | static void *reg_start(struct seq_file *seq, loff_t *pos) |
| 145 | { |
Jiri Slaby | 2c91108c | 2009-03-07 10:26:41 +0100 | [diff] [blame] | 146 | return *pos < ARRAY_SIZE(regs) ? (void *)®s[*pos] : NULL; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static void reg_stop(struct seq_file *seq, void *p) |
| 150 | { |
| 151 | /* nothing to do */ |
| 152 | } |
| 153 | |
| 154 | static void *reg_next(struct seq_file *seq, void *p, loff_t *pos) |
| 155 | { |
| 156 | ++*pos; |
Jiri Slaby | 2c91108c | 2009-03-07 10:26:41 +0100 | [diff] [blame] | 157 | return *pos < ARRAY_SIZE(regs) ? (void *)®s[*pos] : NULL; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | static int reg_show(struct seq_file *seq, void *p) |
| 161 | { |
| 162 | struct ath5k_softc *sc = seq->private; |
| 163 | struct reg *r = p; |
| 164 | seq_printf(seq, "%-25s0x%08x\n", r->name, |
| 165 | ath5k_hw_reg_read(sc->ah, r->addr)); |
| 166 | return 0; |
| 167 | } |
| 168 | |
Jan Engelhardt | 4101dec | 2009-01-14 13:52:18 -0800 | [diff] [blame] | 169 | static const struct seq_operations register_seq_ops = { |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 170 | .start = reg_start, |
| 171 | .next = reg_next, |
| 172 | .stop = reg_stop, |
| 173 | .show = reg_show |
| 174 | }; |
| 175 | |
| 176 | static int open_file_registers(struct inode *inode, struct file *file) |
| 177 | { |
| 178 | struct seq_file *s; |
| 179 | int res; |
| 180 | res = seq_open(file, ®ister_seq_ops); |
| 181 | if (res == 0) { |
| 182 | s = file->private_data; |
| 183 | s->private = inode->i_private; |
| 184 | } |
| 185 | return res; |
| 186 | } |
| 187 | |
| 188 | static const struct file_operations fops_registers = { |
| 189 | .open = open_file_registers, |
| 190 | .read = seq_read, |
| 191 | .llseek = seq_lseek, |
| 192 | .release = seq_release, |
| 193 | .owner = THIS_MODULE, |
| 194 | }; |
| 195 | |
| 196 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 197 | /* debugfs: beacons */ |
| 198 | |
| 199 | static ssize_t read_file_beacon(struct file *file, char __user *user_buf, |
| 200 | size_t count, loff_t *ppos) |
| 201 | { |
| 202 | struct ath5k_softc *sc = file->private_data; |
| 203 | struct ath5k_hw *ah = sc->ah; |
Bruno Randolf | be9b725 | 2008-01-23 10:27:51 +0900 | [diff] [blame] | 204 | char buf[500]; |
| 205 | unsigned int len = 0; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 206 | unsigned int v; |
| 207 | u64 tsf; |
| 208 | |
| 209 | v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON); |
| 210 | len += snprintf(buf+len, sizeof(buf)-len, |
| 211 | "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n", |
| 212 | "AR5K_BEACON", v, v & AR5K_BEACON_PERIOD, |
| 213 | (v & AR5K_BEACON_TIM) >> AR5K_BEACON_TIM_S); |
| 214 | |
| 215 | len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n", |
| 216 | "AR5K_LAST_TSTP", ath5k_hw_reg_read(sc->ah, AR5K_LAST_TSTP)); |
| 217 | |
| 218 | len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n\n", |
| 219 | "AR5K_BEACON_CNT", ath5k_hw_reg_read(sc->ah, AR5K_BEACON_CNT)); |
| 220 | |
| 221 | v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER0); |
| 222 | len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n", |
| 223 | "AR5K_TIMER0 (TBTT)", v, v); |
| 224 | |
| 225 | v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER1); |
| 226 | len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n", |
| 227 | "AR5K_TIMER1 (DMA)", v, v >> 3); |
| 228 | |
| 229 | v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER2); |
| 230 | len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n", |
| 231 | "AR5K_TIMER2 (SWBA)", v, v >> 3); |
| 232 | |
| 233 | v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER3); |
| 234 | len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n", |
| 235 | "AR5K_TIMER3 (ATIM)", v, v); |
| 236 | |
| 237 | tsf = ath5k_hw_get_tsf64(sc->ah); |
| 238 | len += snprintf(buf+len, sizeof(buf)-len, |
John W. Linville | f868f4e | 2008-03-07 16:38:43 -0500 | [diff] [blame] | 239 | "TSF\t\t0x%016llx\tTU: %08x\n", |
| 240 | (unsigned long long)tsf, TSF_TO_TU(tsf)); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 241 | |
Dan Carpenter | 2189d13 | 2010-07-22 10:52:02 +0200 | [diff] [blame] | 242 | if (len > sizeof(buf)) |
| 243 | len = sizeof(buf); |
| 244 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 245 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 246 | } |
| 247 | |
| 248 | static ssize_t write_file_beacon(struct file *file, |
| 249 | const char __user *userbuf, |
| 250 | size_t count, loff_t *ppos) |
| 251 | { |
| 252 | struct ath5k_softc *sc = file->private_data; |
| 253 | struct ath5k_hw *ah = sc->ah; |
Bruno Randolf | be9b725 | 2008-01-23 10:27:51 +0900 | [diff] [blame] | 254 | char buf[20]; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 255 | |
Bruno Randolf | be9b725 | 2008-01-23 10:27:51 +0900 | [diff] [blame] | 256 | if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) |
| 257 | return -EFAULT; |
| 258 | |
| 259 | if (strncmp(buf, "disable", 7) == 0) { |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 260 | AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE); |
| 261 | printk(KERN_INFO "debugfs disable beacons\n"); |
Bruno Randolf | be9b725 | 2008-01-23 10:27:51 +0900 | [diff] [blame] | 262 | } else if (strncmp(buf, "enable", 6) == 0) { |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 263 | AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE); |
| 264 | printk(KERN_INFO "debugfs enable beacons\n"); |
| 265 | } |
| 266 | return count; |
| 267 | } |
| 268 | |
| 269 | static const struct file_operations fops_beacon = { |
| 270 | .read = read_file_beacon, |
| 271 | .write = write_file_beacon, |
| 272 | .open = ath5k_debugfs_open, |
| 273 | .owner = THIS_MODULE, |
| 274 | }; |
| 275 | |
| 276 | |
| 277 | /* debugfs: reset */ |
| 278 | |
| 279 | static ssize_t write_file_reset(struct file *file, |
| 280 | const char __user *userbuf, |
| 281 | size_t count, loff_t *ppos) |
| 282 | { |
| 283 | struct ath5k_softc *sc = file->private_data; |
Bruno Randolf | 8d67a03 | 2010-06-16 19:11:12 +0900 | [diff] [blame] | 284 | ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "debug file triggered reset\n"); |
Bob Copeland | 5faaff7 | 2010-07-13 11:32:40 -0400 | [diff] [blame] | 285 | ieee80211_queue_work(sc->hw, &sc->reset_work); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 286 | return count; |
| 287 | } |
| 288 | |
| 289 | static const struct file_operations fops_reset = { |
| 290 | .write = write_file_reset, |
| 291 | .open = ath5k_debugfs_open, |
| 292 | .owner = THIS_MODULE, |
| 293 | }; |
| 294 | |
| 295 | |
Bruno Randolf | be9b725 | 2008-01-23 10:27:51 +0900 | [diff] [blame] | 296 | /* debugfs: debug level */ |
| 297 | |
Jiri Slaby | 2c91108c | 2009-03-07 10:26:41 +0100 | [diff] [blame] | 298 | static const struct { |
Bruno Randolf | be9b725 | 2008-01-23 10:27:51 +0900 | [diff] [blame] | 299 | enum ath5k_debug_level level; |
| 300 | const char *name; |
| 301 | const char *desc; |
| 302 | } dbg_info[] = { |
| 303 | { ATH5K_DEBUG_RESET, "reset", "reset and initialization" }, |
| 304 | { ATH5K_DEBUG_INTR, "intr", "interrupt handling" }, |
| 305 | { ATH5K_DEBUG_MODE, "mode", "mode init/setup" }, |
| 306 | { ATH5K_DEBUG_XMIT, "xmit", "basic xmit operation" }, |
| 307 | { ATH5K_DEBUG_BEACON, "beacon", "beacon handling" }, |
| 308 | { ATH5K_DEBUG_CALIBRATE, "calib", "periodic calibration" }, |
| 309 | { ATH5K_DEBUG_TXPOWER, "txpower", "transmit power setting" }, |
Bob Copeland | 85519a6 | 2008-10-29 08:30:53 -0400 | [diff] [blame] | 310 | { ATH5K_DEBUG_LED, "led", "LED management" }, |
Bruno Randolf | be9b725 | 2008-01-23 10:27:51 +0900 | [diff] [blame] | 311 | { ATH5K_DEBUG_DUMP_RX, "dumprx", "print received skb content" }, |
| 312 | { ATH5K_DEBUG_DUMP_TX, "dumptx", "print transmit skb content" }, |
Luis R. Rodriguez | b446197 | 2008-02-04 10:03:54 -0500 | [diff] [blame] | 313 | { ATH5K_DEBUG_DUMPBANDS, "dumpbands", "dump bands" }, |
Bruno Randolf | 2111ac0 | 2010-04-02 18:44:08 +0900 | [diff] [blame] | 314 | { ATH5K_DEBUG_ANI, "ani", "adaptive noise immunity" }, |
Bob Copeland | b4c5261 | 2010-08-21 16:39:03 -0400 | [diff] [blame] | 315 | { ATH5K_DEBUG_DESC, "desc", "descriptor chains" }, |
Bruno Randolf | be9b725 | 2008-01-23 10:27:51 +0900 | [diff] [blame] | 316 | { ATH5K_DEBUG_ANY, "all", "show all debug levels" }, |
| 317 | }; |
| 318 | |
| 319 | static ssize_t read_file_debug(struct file *file, char __user *user_buf, |
| 320 | size_t count, loff_t *ppos) |
| 321 | { |
| 322 | struct ath5k_softc *sc = file->private_data; |
| 323 | char buf[700]; |
| 324 | unsigned int len = 0; |
| 325 | unsigned int i; |
| 326 | |
| 327 | len += snprintf(buf+len, sizeof(buf)-len, |
| 328 | "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level); |
| 329 | |
| 330 | for (i = 0; i < ARRAY_SIZE(dbg_info) - 1; i++) { |
| 331 | len += snprintf(buf+len, sizeof(buf)-len, |
| 332 | "%10s %c 0x%08x - %s\n", dbg_info[i].name, |
| 333 | sc->debug.level & dbg_info[i].level ? '+' : ' ', |
| 334 | dbg_info[i].level, dbg_info[i].desc); |
| 335 | } |
| 336 | len += snprintf(buf+len, sizeof(buf)-len, |
| 337 | "%10s %c 0x%08x - %s\n", dbg_info[i].name, |
| 338 | sc->debug.level == dbg_info[i].level ? '+' : ' ', |
| 339 | dbg_info[i].level, dbg_info[i].desc); |
| 340 | |
Dan Carpenter | 2189d13 | 2010-07-22 10:52:02 +0200 | [diff] [blame] | 341 | if (len > sizeof(buf)) |
| 342 | len = sizeof(buf); |
| 343 | |
Bruno Randolf | be9b725 | 2008-01-23 10:27:51 +0900 | [diff] [blame] | 344 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 345 | } |
| 346 | |
| 347 | static ssize_t write_file_debug(struct file *file, |
| 348 | const char __user *userbuf, |
| 349 | size_t count, loff_t *ppos) |
| 350 | { |
| 351 | struct ath5k_softc *sc = file->private_data; |
| 352 | unsigned int i; |
| 353 | char buf[20]; |
| 354 | |
| 355 | if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) |
| 356 | return -EFAULT; |
| 357 | |
| 358 | for (i = 0; i < ARRAY_SIZE(dbg_info); i++) { |
| 359 | if (strncmp(buf, dbg_info[i].name, |
| 360 | strlen(dbg_info[i].name)) == 0) { |
| 361 | sc->debug.level ^= dbg_info[i].level; /* toggle bit */ |
| 362 | break; |
| 363 | } |
| 364 | } |
| 365 | return count; |
| 366 | } |
| 367 | |
| 368 | static const struct file_operations fops_debug = { |
| 369 | .read = read_file_debug, |
| 370 | .write = write_file_debug, |
| 371 | .open = ath5k_debugfs_open, |
| 372 | .owner = THIS_MODULE, |
| 373 | }; |
| 374 | |
| 375 | |
Bruno Randolf | 604eead | 2010-03-09 16:55:17 +0900 | [diff] [blame] | 376 | /* debugfs: antenna */ |
| 377 | |
| 378 | static ssize_t read_file_antenna(struct file *file, char __user *user_buf, |
| 379 | size_t count, loff_t *ppos) |
| 380 | { |
| 381 | struct ath5k_softc *sc = file->private_data; |
| 382 | char buf[700]; |
| 383 | unsigned int len = 0; |
| 384 | unsigned int i; |
| 385 | unsigned int v; |
| 386 | |
| 387 | len += snprintf(buf+len, sizeof(buf)-len, "antenna mode\t%d\n", |
| 388 | sc->ah->ah_ant_mode); |
| 389 | len += snprintf(buf+len, sizeof(buf)-len, "default antenna\t%d\n", |
| 390 | sc->ah->ah_def_ant); |
| 391 | len += snprintf(buf+len, sizeof(buf)-len, "tx antenna\t%d\n", |
| 392 | sc->ah->ah_tx_ant); |
| 393 | |
| 394 | len += snprintf(buf+len, sizeof(buf)-len, "\nANTENNA\t\tRX\tTX\n"); |
| 395 | for (i = 1; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) { |
| 396 | len += snprintf(buf+len, sizeof(buf)-len, |
| 397 | "[antenna %d]\t%d\t%d\n", |
| 398 | i, sc->stats.antenna_rx[i], sc->stats.antenna_tx[i]); |
| 399 | } |
| 400 | len += snprintf(buf+len, sizeof(buf)-len, "[invalid]\t%d\t%d\n", |
| 401 | sc->stats.antenna_rx[0], sc->stats.antenna_tx[0]); |
| 402 | |
| 403 | v = ath5k_hw_reg_read(sc->ah, AR5K_DEFAULT_ANTENNA); |
| 404 | len += snprintf(buf+len, sizeof(buf)-len, |
| 405 | "\nAR5K_DEFAULT_ANTENNA\t0x%08x\n", v); |
| 406 | |
| 407 | v = ath5k_hw_reg_read(sc->ah, AR5K_STA_ID1); |
| 408 | len += snprintf(buf+len, sizeof(buf)-len, |
| 409 | "AR5K_STA_ID1_DEFAULT_ANTENNA\t%d\n", |
| 410 | (v & AR5K_STA_ID1_DEFAULT_ANTENNA) != 0); |
| 411 | len += snprintf(buf+len, sizeof(buf)-len, |
| 412 | "AR5K_STA_ID1_DESC_ANTENNA\t%d\n", |
| 413 | (v & AR5K_STA_ID1_DESC_ANTENNA) != 0); |
| 414 | len += snprintf(buf+len, sizeof(buf)-len, |
| 415 | "AR5K_STA_ID1_RTS_DEF_ANTENNA\t%d\n", |
| 416 | (v & AR5K_STA_ID1_RTS_DEF_ANTENNA) != 0); |
| 417 | len += snprintf(buf+len, sizeof(buf)-len, |
| 418 | "AR5K_STA_ID1_SELFGEN_DEF_ANT\t%d\n", |
| 419 | (v & AR5K_STA_ID1_SELFGEN_DEF_ANT) != 0); |
| 420 | |
| 421 | v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_AGCCTL); |
| 422 | len += snprintf(buf+len, sizeof(buf)-len, |
| 423 | "\nAR5K_PHY_AGCCTL_OFDM_DIV_DIS\t%d\n", |
| 424 | (v & AR5K_PHY_AGCCTL_OFDM_DIV_DIS) != 0); |
| 425 | |
| 426 | v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_RESTART); |
| 427 | len += snprintf(buf+len, sizeof(buf)-len, |
| 428 | "AR5K_PHY_RESTART_DIV_GC\t\t%x\n", |
| 429 | (v & AR5K_PHY_RESTART_DIV_GC) >> AR5K_PHY_RESTART_DIV_GC_S); |
| 430 | |
| 431 | v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_FAST_ANT_DIV); |
| 432 | len += snprintf(buf+len, sizeof(buf)-len, |
| 433 | "AR5K_PHY_FAST_ANT_DIV_EN\t%d\n", |
| 434 | (v & AR5K_PHY_FAST_ANT_DIV_EN) != 0); |
| 435 | |
Bruno Randolf | 0ca7402 | 2010-06-07 13:11:30 +0900 | [diff] [blame] | 436 | v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_ANT_SWITCH_TABLE_0); |
| 437 | len += snprintf(buf+len, sizeof(buf)-len, |
| 438 | "\nAR5K_PHY_ANT_SWITCH_TABLE_0\t0x%08x\n", v); |
| 439 | v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_ANT_SWITCH_TABLE_1); |
| 440 | len += snprintf(buf+len, sizeof(buf)-len, |
| 441 | "AR5K_PHY_ANT_SWITCH_TABLE_1\t0x%08x\n", v); |
| 442 | |
Dan Carpenter | 2189d13 | 2010-07-22 10:52:02 +0200 | [diff] [blame] | 443 | if (len > sizeof(buf)) |
| 444 | len = sizeof(buf); |
| 445 | |
Bruno Randolf | 604eead | 2010-03-09 16:55:17 +0900 | [diff] [blame] | 446 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 447 | } |
| 448 | |
| 449 | static ssize_t write_file_antenna(struct file *file, |
| 450 | const char __user *userbuf, |
| 451 | size_t count, loff_t *ppos) |
| 452 | { |
| 453 | struct ath5k_softc *sc = file->private_data; |
| 454 | unsigned int i; |
| 455 | char buf[20]; |
| 456 | |
| 457 | if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) |
| 458 | return -EFAULT; |
| 459 | |
| 460 | if (strncmp(buf, "diversity", 9) == 0) { |
| 461 | ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_DEFAULT); |
| 462 | printk(KERN_INFO "ath5k debug: enable diversity\n"); |
| 463 | } else if (strncmp(buf, "fixed-a", 7) == 0) { |
| 464 | ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_A); |
| 465 | printk(KERN_INFO "ath5k debugfs: fixed antenna A\n"); |
| 466 | } else if (strncmp(buf, "fixed-b", 7) == 0) { |
| 467 | ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_B); |
| 468 | printk(KERN_INFO "ath5k debug: fixed antenna B\n"); |
| 469 | } else if (strncmp(buf, "clear", 5) == 0) { |
| 470 | for (i = 0; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) { |
| 471 | sc->stats.antenna_rx[i] = 0; |
| 472 | sc->stats.antenna_tx[i] = 0; |
| 473 | } |
| 474 | printk(KERN_INFO "ath5k debug: cleared antenna stats\n"); |
| 475 | } |
| 476 | return count; |
| 477 | } |
| 478 | |
| 479 | static const struct file_operations fops_antenna = { |
| 480 | .read = read_file_antenna, |
| 481 | .write = write_file_antenna, |
| 482 | .open = ath5k_debugfs_open, |
| 483 | .owner = THIS_MODULE, |
| 484 | }; |
| 485 | |
| 486 | |
Bruno Randolf | 7644395 | 2010-03-09 16:56:00 +0900 | [diff] [blame] | 487 | /* debugfs: frameerrors */ |
| 488 | |
| 489 | static ssize_t read_file_frameerrors(struct file *file, char __user *user_buf, |
| 490 | size_t count, loff_t *ppos) |
| 491 | { |
| 492 | struct ath5k_softc *sc = file->private_data; |
| 493 | struct ath5k_statistics *st = &sc->stats; |
| 494 | char buf[700]; |
| 495 | unsigned int len = 0; |
Bruno Randolf | da35111 | 2010-03-25 14:49:42 +0900 | [diff] [blame] | 496 | int i; |
Bruno Randolf | 7644395 | 2010-03-09 16:56:00 +0900 | [diff] [blame] | 497 | |
| 498 | len += snprintf(buf+len, sizeof(buf)-len, |
| 499 | "RX\n---------------------\n"); |
| 500 | len += snprintf(buf+len, sizeof(buf)-len, "CRC\t%d\t(%d%%)\n", |
| 501 | st->rxerr_crc, |
| 502 | st->rx_all_count > 0 ? |
| 503 | st->rxerr_crc*100/st->rx_all_count : 0); |
| 504 | len += snprintf(buf+len, sizeof(buf)-len, "PHY\t%d\t(%d%%)\n", |
| 505 | st->rxerr_phy, |
| 506 | st->rx_all_count > 0 ? |
| 507 | st->rxerr_phy*100/st->rx_all_count : 0); |
Bruno Randolf | da35111 | 2010-03-25 14:49:42 +0900 | [diff] [blame] | 508 | for (i = 0; i < 32; i++) { |
| 509 | if (st->rxerr_phy_code[i]) |
| 510 | len += snprintf(buf+len, sizeof(buf)-len, |
| 511 | " phy_err[%d]\t%d\n", |
| 512 | i, st->rxerr_phy_code[i]); |
| 513 | } |
| 514 | |
Bruno Randolf | 7644395 | 2010-03-09 16:56:00 +0900 | [diff] [blame] | 515 | len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%d\t(%d%%)\n", |
| 516 | st->rxerr_fifo, |
| 517 | st->rx_all_count > 0 ? |
| 518 | st->rxerr_fifo*100/st->rx_all_count : 0); |
| 519 | len += snprintf(buf+len, sizeof(buf)-len, "decrypt\t%d\t(%d%%)\n", |
| 520 | st->rxerr_decrypt, |
| 521 | st->rx_all_count > 0 ? |
| 522 | st->rxerr_decrypt*100/st->rx_all_count : 0); |
| 523 | len += snprintf(buf+len, sizeof(buf)-len, "MIC\t%d\t(%d%%)\n", |
| 524 | st->rxerr_mic, |
| 525 | st->rx_all_count > 0 ? |
| 526 | st->rxerr_mic*100/st->rx_all_count : 0); |
| 527 | len += snprintf(buf+len, sizeof(buf)-len, "process\t%d\t(%d%%)\n", |
| 528 | st->rxerr_proc, |
| 529 | st->rx_all_count > 0 ? |
| 530 | st->rxerr_proc*100/st->rx_all_count : 0); |
| 531 | len += snprintf(buf+len, sizeof(buf)-len, "jumbo\t%d\t(%d%%)\n", |
| 532 | st->rxerr_jumbo, |
| 533 | st->rx_all_count > 0 ? |
| 534 | st->rxerr_jumbo*100/st->rx_all_count : 0); |
| 535 | len += snprintf(buf+len, sizeof(buf)-len, "[RX all\t%d]\n", |
| 536 | st->rx_all_count); |
| 537 | |
| 538 | len += snprintf(buf+len, sizeof(buf)-len, |
| 539 | "\nTX\n---------------------\n"); |
| 540 | len += snprintf(buf+len, sizeof(buf)-len, "retry\t%d\t(%d%%)\n", |
| 541 | st->txerr_retry, |
| 542 | st->tx_all_count > 0 ? |
| 543 | st->txerr_retry*100/st->tx_all_count : 0); |
| 544 | len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%d\t(%d%%)\n", |
| 545 | st->txerr_fifo, |
| 546 | st->tx_all_count > 0 ? |
| 547 | st->txerr_fifo*100/st->tx_all_count : 0); |
| 548 | len += snprintf(buf+len, sizeof(buf)-len, "filter\t%d\t(%d%%)\n", |
| 549 | st->txerr_filt, |
| 550 | st->tx_all_count > 0 ? |
| 551 | st->txerr_filt*100/st->tx_all_count : 0); |
| 552 | len += snprintf(buf+len, sizeof(buf)-len, "[TX all\t%d]\n", |
| 553 | st->tx_all_count); |
| 554 | |
Dan Carpenter | 2189d13 | 2010-07-22 10:52:02 +0200 | [diff] [blame] | 555 | if (len > sizeof(buf)) |
| 556 | len = sizeof(buf); |
| 557 | |
Bruno Randolf | 7644395 | 2010-03-09 16:56:00 +0900 | [diff] [blame] | 558 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 559 | } |
| 560 | |
| 561 | static ssize_t write_file_frameerrors(struct file *file, |
| 562 | const char __user *userbuf, |
| 563 | size_t count, loff_t *ppos) |
| 564 | { |
| 565 | struct ath5k_softc *sc = file->private_data; |
| 566 | struct ath5k_statistics *st = &sc->stats; |
| 567 | char buf[20]; |
| 568 | |
| 569 | if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) |
| 570 | return -EFAULT; |
| 571 | |
| 572 | if (strncmp(buf, "clear", 5) == 0) { |
| 573 | st->rxerr_crc = 0; |
| 574 | st->rxerr_phy = 0; |
| 575 | st->rxerr_fifo = 0; |
| 576 | st->rxerr_decrypt = 0; |
| 577 | st->rxerr_mic = 0; |
| 578 | st->rxerr_proc = 0; |
| 579 | st->rxerr_jumbo = 0; |
| 580 | st->rx_all_count = 0; |
| 581 | st->txerr_retry = 0; |
| 582 | st->txerr_fifo = 0; |
| 583 | st->txerr_filt = 0; |
| 584 | st->tx_all_count = 0; |
| 585 | printk(KERN_INFO "ath5k debug: cleared frameerrors stats\n"); |
| 586 | } |
| 587 | return count; |
| 588 | } |
| 589 | |
| 590 | static const struct file_operations fops_frameerrors = { |
| 591 | .read = read_file_frameerrors, |
| 592 | .write = write_file_frameerrors, |
| 593 | .open = ath5k_debugfs_open, |
| 594 | .owner = THIS_MODULE, |
| 595 | }; |
| 596 | |
| 597 | |
Bruno Randolf | 2111ac0 | 2010-04-02 18:44:08 +0900 | [diff] [blame] | 598 | /* debugfs: ani */ |
| 599 | |
| 600 | static ssize_t read_file_ani(struct file *file, char __user *user_buf, |
| 601 | size_t count, loff_t *ppos) |
| 602 | { |
| 603 | struct ath5k_softc *sc = file->private_data; |
| 604 | struct ath5k_statistics *st = &sc->stats; |
| 605 | struct ath5k_ani_state *as = &sc->ani_state; |
| 606 | |
| 607 | char buf[700]; |
| 608 | unsigned int len = 0; |
| 609 | |
| 610 | len += snprintf(buf+len, sizeof(buf)-len, |
| 611 | "HW has PHY error counters:\t%s\n", |
| 612 | sc->ah->ah_capabilities.cap_has_phyerr_counters ? |
| 613 | "yes" : "no"); |
| 614 | len += snprintf(buf+len, sizeof(buf)-len, |
| 615 | "HW max spur immunity level:\t%d\n", |
| 616 | as->max_spur_level); |
| 617 | len += snprintf(buf+len, sizeof(buf)-len, |
| 618 | "\nANI state\n--------------------------------------------\n"); |
| 619 | len += snprintf(buf+len, sizeof(buf)-len, "operating mode:\t\t\t"); |
| 620 | switch (as->ani_mode) { |
| 621 | case ATH5K_ANI_MODE_OFF: |
| 622 | len += snprintf(buf+len, sizeof(buf)-len, "OFF\n"); |
| 623 | break; |
| 624 | case ATH5K_ANI_MODE_MANUAL_LOW: |
| 625 | len += snprintf(buf+len, sizeof(buf)-len, |
| 626 | "MANUAL LOW\n"); |
| 627 | break; |
| 628 | case ATH5K_ANI_MODE_MANUAL_HIGH: |
| 629 | len += snprintf(buf+len, sizeof(buf)-len, |
| 630 | "MANUAL HIGH\n"); |
| 631 | break; |
| 632 | case ATH5K_ANI_MODE_AUTO: |
| 633 | len += snprintf(buf+len, sizeof(buf)-len, "AUTO\n"); |
| 634 | break; |
| 635 | default: |
| 636 | len += snprintf(buf+len, sizeof(buf)-len, |
| 637 | "??? (not good)\n"); |
| 638 | break; |
| 639 | } |
| 640 | len += snprintf(buf+len, sizeof(buf)-len, |
| 641 | "noise immunity level:\t\t%d\n", |
| 642 | as->noise_imm_level); |
| 643 | len += snprintf(buf+len, sizeof(buf)-len, |
| 644 | "spur immunity level:\t\t%d\n", |
| 645 | as->spur_level); |
| 646 | len += snprintf(buf+len, sizeof(buf)-len, "firstep level:\t\t\t%d\n", |
| 647 | as->firstep_level); |
| 648 | len += snprintf(buf+len, sizeof(buf)-len, |
| 649 | "OFDM weak signal detection:\t%s\n", |
| 650 | as->ofdm_weak_sig ? "on" : "off"); |
| 651 | len += snprintf(buf+len, sizeof(buf)-len, |
| 652 | "CCK weak signal detection:\t%s\n", |
| 653 | as->cck_weak_sig ? "on" : "off"); |
| 654 | |
| 655 | len += snprintf(buf+len, sizeof(buf)-len, |
| 656 | "\nMIB INTERRUPTS:\t\t%u\n", |
| 657 | st->mib_intr); |
| 658 | len += snprintf(buf+len, sizeof(buf)-len, |
| 659 | "beacon RSSI average:\t%d\n", |
| 660 | sc->ah->ah_beacon_rssi_avg.avg); |
| 661 | len += snprintf(buf+len, sizeof(buf)-len, "profcnt tx\t\t%u\t(%d%%)\n", |
| 662 | as->pfc_tx, |
| 663 | as->pfc_cycles > 0 ? |
| 664 | as->pfc_tx*100/as->pfc_cycles : 0); |
| 665 | len += snprintf(buf+len, sizeof(buf)-len, "profcnt rx\t\t%u\t(%d%%)\n", |
| 666 | as->pfc_rx, |
| 667 | as->pfc_cycles > 0 ? |
| 668 | as->pfc_rx*100/as->pfc_cycles : 0); |
| 669 | len += snprintf(buf+len, sizeof(buf)-len, "profcnt busy\t\t%u\t(%d%%)\n", |
| 670 | as->pfc_busy, |
| 671 | as->pfc_cycles > 0 ? |
| 672 | as->pfc_busy*100/as->pfc_cycles : 0); |
| 673 | len += snprintf(buf+len, sizeof(buf)-len, "profcnt cycles\t\t%u\n", |
| 674 | as->pfc_cycles); |
| 675 | len += snprintf(buf+len, sizeof(buf)-len, |
| 676 | "listen time\t\t%d\tlast: %d\n", |
| 677 | as->listen_time, as->last_listen); |
| 678 | len += snprintf(buf+len, sizeof(buf)-len, |
| 679 | "OFDM errors\t\t%u\tlast: %u\tsum: %u\n", |
| 680 | as->ofdm_errors, as->last_ofdm_errors, |
| 681 | as->sum_ofdm_errors); |
| 682 | len += snprintf(buf+len, sizeof(buf)-len, |
| 683 | "CCK errors\t\t%u\tlast: %u\tsum: %u\n", |
| 684 | as->cck_errors, as->last_cck_errors, |
| 685 | as->sum_cck_errors); |
| 686 | len += snprintf(buf+len, sizeof(buf)-len, |
| 687 | "AR5K_PHYERR_CNT1\t%x\t(=%d)\n", |
| 688 | ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1), |
| 689 | ATH5K_ANI_OFDM_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX - |
| 690 | ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1))); |
| 691 | len += snprintf(buf+len, sizeof(buf)-len, |
| 692 | "AR5K_PHYERR_CNT2\t%x\t(=%d)\n", |
| 693 | ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2), |
| 694 | ATH5K_ANI_CCK_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX - |
| 695 | ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2))); |
| 696 | |
Dan Carpenter | 2189d13 | 2010-07-22 10:52:02 +0200 | [diff] [blame] | 697 | if (len > sizeof(buf)) |
| 698 | len = sizeof(buf); |
| 699 | |
Bruno Randolf | 2111ac0 | 2010-04-02 18:44:08 +0900 | [diff] [blame] | 700 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 701 | } |
| 702 | |
| 703 | static ssize_t write_file_ani(struct file *file, |
| 704 | const char __user *userbuf, |
| 705 | size_t count, loff_t *ppos) |
| 706 | { |
| 707 | struct ath5k_softc *sc = file->private_data; |
| 708 | char buf[20]; |
| 709 | |
| 710 | if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) |
| 711 | return -EFAULT; |
| 712 | |
| 713 | if (strncmp(buf, "sens-low", 8) == 0) { |
| 714 | ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_HIGH); |
| 715 | } else if (strncmp(buf, "sens-high", 9) == 0) { |
| 716 | ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_LOW); |
| 717 | } else if (strncmp(buf, "ani-off", 7) == 0) { |
| 718 | ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_OFF); |
| 719 | } else if (strncmp(buf, "ani-on", 6) == 0) { |
| 720 | ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_AUTO); |
| 721 | } else if (strncmp(buf, "noise-low", 9) == 0) { |
| 722 | ath5k_ani_set_noise_immunity_level(sc->ah, 0); |
| 723 | } else if (strncmp(buf, "noise-high", 10) == 0) { |
| 724 | ath5k_ani_set_noise_immunity_level(sc->ah, |
| 725 | ATH5K_ANI_MAX_NOISE_IMM_LVL); |
| 726 | } else if (strncmp(buf, "spur-low", 8) == 0) { |
| 727 | ath5k_ani_set_spur_immunity_level(sc->ah, 0); |
| 728 | } else if (strncmp(buf, "spur-high", 9) == 0) { |
| 729 | ath5k_ani_set_spur_immunity_level(sc->ah, |
| 730 | sc->ani_state.max_spur_level); |
| 731 | } else if (strncmp(buf, "fir-low", 7) == 0) { |
| 732 | ath5k_ani_set_firstep_level(sc->ah, 0); |
| 733 | } else if (strncmp(buf, "fir-high", 8) == 0) { |
| 734 | ath5k_ani_set_firstep_level(sc->ah, ATH5K_ANI_MAX_FIRSTEP_LVL); |
| 735 | } else if (strncmp(buf, "ofdm-off", 8) == 0) { |
| 736 | ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, false); |
| 737 | } else if (strncmp(buf, "ofdm-on", 7) == 0) { |
| 738 | ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, true); |
| 739 | } else if (strncmp(buf, "cck-off", 7) == 0) { |
| 740 | ath5k_ani_set_cck_weak_signal_detection(sc->ah, false); |
| 741 | } else if (strncmp(buf, "cck-on", 6) == 0) { |
| 742 | ath5k_ani_set_cck_weak_signal_detection(sc->ah, true); |
| 743 | } |
| 744 | return count; |
| 745 | } |
| 746 | |
| 747 | static const struct file_operations fops_ani = { |
| 748 | .read = read_file_ani, |
| 749 | .write = write_file_ani, |
| 750 | .open = ath5k_debugfs_open, |
| 751 | .owner = THIS_MODULE, |
| 752 | }; |
| 753 | |
| 754 | |
Bruno Randolf | 3cfd43f | 2010-06-07 13:11:40 +0900 | [diff] [blame] | 755 | /* debugfs: queues etc */ |
| 756 | |
| 757 | static ssize_t read_file_queue(struct file *file, char __user *user_buf, |
| 758 | size_t count, loff_t *ppos) |
| 759 | { |
| 760 | struct ath5k_softc *sc = file->private_data; |
| 761 | char buf[700]; |
| 762 | unsigned int len = 0; |
| 763 | |
| 764 | struct ath5k_txq *txq; |
| 765 | struct ath5k_buf *bf, *bf0; |
Bruno Randolf | cfddc11 | 2010-09-17 11:36:40 +0900 | [diff] [blame^] | 766 | int i, n; |
Bruno Randolf | 3cfd43f | 2010-06-07 13:11:40 +0900 | [diff] [blame] | 767 | |
| 768 | len += snprintf(buf+len, sizeof(buf)-len, |
| 769 | "available txbuffers: %d\n", sc->txbuf_len); |
| 770 | |
| 771 | for (i = 0; i < ARRAY_SIZE(sc->txqs); i++) { |
| 772 | txq = &sc->txqs[i]; |
| 773 | |
| 774 | len += snprintf(buf+len, sizeof(buf)-len, |
| 775 | "%02d: %ssetup\n", i, txq->setup ? "" : "not "); |
| 776 | |
| 777 | if (!txq->setup) |
| 778 | continue; |
| 779 | |
Bruno Randolf | cfddc11 | 2010-09-17 11:36:40 +0900 | [diff] [blame^] | 780 | n = 0; |
| 781 | spin_lock_bh(&txq->lock); |
Bruno Randolf | 3cfd43f | 2010-06-07 13:11:40 +0900 | [diff] [blame] | 782 | list_for_each_entry_safe(bf, bf0, &txq->q, list) |
| 783 | n++; |
Bruno Randolf | cfddc11 | 2010-09-17 11:36:40 +0900 | [diff] [blame^] | 784 | spin_unlock_bh(&txq->lock); |
| 785 | |
| 786 | len += snprintf(buf+len, sizeof(buf)-len, |
| 787 | " len: %d bufs: %d\n", txq->txq_len, n); |
Bruno Randolf | 3cfd43f | 2010-06-07 13:11:40 +0900 | [diff] [blame] | 788 | } |
| 789 | |
Dan Carpenter | 2189d13 | 2010-07-22 10:52:02 +0200 | [diff] [blame] | 790 | if (len > sizeof(buf)) |
| 791 | len = sizeof(buf); |
| 792 | |
Bruno Randolf | 3cfd43f | 2010-06-07 13:11:40 +0900 | [diff] [blame] | 793 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 794 | } |
| 795 | |
| 796 | static ssize_t write_file_queue(struct file *file, |
| 797 | const char __user *userbuf, |
| 798 | size_t count, loff_t *ppos) |
| 799 | { |
| 800 | struct ath5k_softc *sc = file->private_data; |
| 801 | char buf[20]; |
| 802 | |
| 803 | if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) |
| 804 | return -EFAULT; |
| 805 | |
| 806 | if (strncmp(buf, "start", 5) == 0) |
| 807 | ieee80211_wake_queues(sc->hw); |
| 808 | else if (strncmp(buf, "stop", 4) == 0) |
| 809 | ieee80211_stop_queues(sc->hw); |
| 810 | |
| 811 | return count; |
| 812 | } |
| 813 | |
| 814 | |
| 815 | static const struct file_operations fops_queue = { |
| 816 | .read = read_file_queue, |
| 817 | .write = write_file_queue, |
| 818 | .open = ath5k_debugfs_open, |
| 819 | .owner = THIS_MODULE, |
| 820 | }; |
| 821 | |
| 822 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 823 | /* init */ |
| 824 | |
| 825 | void |
| 826 | ath5k_debug_init(void) |
| 827 | { |
| 828 | ath5k_global_debugfs = debugfs_create_dir("ath5k", NULL); |
| 829 | } |
| 830 | |
| 831 | void |
| 832 | ath5k_debug_init_device(struct ath5k_softc *sc) |
| 833 | { |
| 834 | sc->debug.level = ath5k_debug; |
Bruno Randolf | be9b725 | 2008-01-23 10:27:51 +0900 | [diff] [blame] | 835 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 836 | sc->debug.debugfs_phydir = debugfs_create_dir(wiphy_name(sc->hw->wiphy), |
Bruno Randolf | be9b725 | 2008-01-23 10:27:51 +0900 | [diff] [blame] | 837 | ath5k_global_debugfs); |
| 838 | |
Jiri Slaby | 3167007 | 2009-06-28 23:25:27 +0200 | [diff] [blame] | 839 | sc->debug.debugfs_debug = debugfs_create_file("debug", |
| 840 | S_IWUSR | S_IRUSR, |
Bruno Randolf | be9b725 | 2008-01-23 10:27:51 +0900 | [diff] [blame] | 841 | sc->debug.debugfs_phydir, sc, &fops_debug); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 842 | |
Jiri Slaby | 3167007 | 2009-06-28 23:25:27 +0200 | [diff] [blame] | 843 | sc->debug.debugfs_registers = debugfs_create_file("registers", S_IRUSR, |
Bruno Randolf | be9b725 | 2008-01-23 10:27:51 +0900 | [diff] [blame] | 844 | sc->debug.debugfs_phydir, sc, &fops_registers); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 845 | |
Jiri Slaby | 3167007 | 2009-06-28 23:25:27 +0200 | [diff] [blame] | 846 | sc->debug.debugfs_beacon = debugfs_create_file("beacon", |
| 847 | S_IWUSR | S_IRUSR, |
Bruno Randolf | be9b725 | 2008-01-23 10:27:51 +0900 | [diff] [blame] | 848 | sc->debug.debugfs_phydir, sc, &fops_beacon); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 849 | |
Cheng Renquan | 33ab625 | 2008-11-22 11:22:49 +0800 | [diff] [blame] | 850 | sc->debug.debugfs_reset = debugfs_create_file("reset", S_IWUSR, |
Bruno Randolf | be9b725 | 2008-01-23 10:27:51 +0900 | [diff] [blame] | 851 | sc->debug.debugfs_phydir, sc, &fops_reset); |
Bruno Randolf | 604eead | 2010-03-09 16:55:17 +0900 | [diff] [blame] | 852 | |
| 853 | sc->debug.debugfs_antenna = debugfs_create_file("antenna", |
| 854 | S_IWUSR | S_IRUSR, |
| 855 | sc->debug.debugfs_phydir, sc, &fops_antenna); |
Bruno Randolf | 7644395 | 2010-03-09 16:56:00 +0900 | [diff] [blame] | 856 | |
| 857 | sc->debug.debugfs_frameerrors = debugfs_create_file("frameerrors", |
| 858 | S_IWUSR | S_IRUSR, |
| 859 | sc->debug.debugfs_phydir, sc, |
| 860 | &fops_frameerrors); |
Bruno Randolf | 2111ac0 | 2010-04-02 18:44:08 +0900 | [diff] [blame] | 861 | |
| 862 | sc->debug.debugfs_ani = debugfs_create_file("ani", |
| 863 | S_IWUSR | S_IRUSR, |
| 864 | sc->debug.debugfs_phydir, sc, |
| 865 | &fops_ani); |
Bruno Randolf | 3cfd43f | 2010-06-07 13:11:40 +0900 | [diff] [blame] | 866 | |
| 867 | sc->debug.debugfs_queue = debugfs_create_file("queue", |
| 868 | S_IWUSR | S_IRUSR, |
| 869 | sc->debug.debugfs_phydir, sc, |
| 870 | &fops_queue); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | void |
| 874 | ath5k_debug_finish(void) |
| 875 | { |
| 876 | debugfs_remove(ath5k_global_debugfs); |
| 877 | } |
| 878 | |
| 879 | void |
| 880 | ath5k_debug_finish_device(struct ath5k_softc *sc) |
| 881 | { |
| 882 | debugfs_remove(sc->debug.debugfs_debug); |
| 883 | debugfs_remove(sc->debug.debugfs_registers); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 884 | debugfs_remove(sc->debug.debugfs_beacon); |
| 885 | debugfs_remove(sc->debug.debugfs_reset); |
Bruno Randolf | 604eead | 2010-03-09 16:55:17 +0900 | [diff] [blame] | 886 | debugfs_remove(sc->debug.debugfs_antenna); |
Bruno Randolf | 7644395 | 2010-03-09 16:56:00 +0900 | [diff] [blame] | 887 | debugfs_remove(sc->debug.debugfs_frameerrors); |
Bruno Randolf | 2111ac0 | 2010-04-02 18:44:08 +0900 | [diff] [blame] | 888 | debugfs_remove(sc->debug.debugfs_ani); |
Bruno Randolf | 3cfd43f | 2010-06-07 13:11:40 +0900 | [diff] [blame] | 889 | debugfs_remove(sc->debug.debugfs_queue); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 890 | debugfs_remove(sc->debug.debugfs_phydir); |
| 891 | } |
| 892 | |
| 893 | |
| 894 | /* functions used in other places */ |
| 895 | |
| 896 | void |
Luis R. Rodriguez | b446197 | 2008-02-04 10:03:54 -0500 | [diff] [blame] | 897 | ath5k_debug_dump_bands(struct ath5k_softc *sc) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 898 | { |
Luis R. Rodriguez | b446197 | 2008-02-04 10:03:54 -0500 | [diff] [blame] | 899 | unsigned int b, i; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 900 | |
Luis R. Rodriguez | b446197 | 2008-02-04 10:03:54 -0500 | [diff] [blame] | 901 | if (likely(!(sc->debug.level & ATH5K_DEBUG_DUMPBANDS))) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 902 | return; |
| 903 | |
Luis R. Rodriguez | b446197 | 2008-02-04 10:03:54 -0500 | [diff] [blame] | 904 | BUG_ON(!sc->sbands); |
| 905 | |
| 906 | for (b = 0; b < IEEE80211_NUM_BANDS; b++) { |
| 907 | struct ieee80211_supported_band *band = &sc->sbands[b]; |
Bob Copeland | b7fcb5c | 2009-04-27 22:12:43 -0400 | [diff] [blame] | 908 | char bname[6]; |
Luis R. Rodriguez | b446197 | 2008-02-04 10:03:54 -0500 | [diff] [blame] | 909 | switch (band->band) { |
| 910 | case IEEE80211_BAND_2GHZ: |
| 911 | strcpy(bname, "2 GHz"); |
| 912 | break; |
| 913 | case IEEE80211_BAND_5GHZ: |
| 914 | strcpy(bname, "5 GHz"); |
| 915 | break; |
| 916 | default: |
| 917 | printk(KERN_DEBUG "Band not supported: %d\n", |
| 918 | band->band); |
| 919 | return; |
| 920 | } |
| 921 | printk(KERN_DEBUG "Band %s: channels %d, rates %d\n", bname, |
| 922 | band->n_channels, band->n_bitrates); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 923 | printk(KERN_DEBUG " channels:\n"); |
Luis R. Rodriguez | b446197 | 2008-02-04 10:03:54 -0500 | [diff] [blame] | 924 | for (i = 0; i < band->n_channels; i++) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 925 | printk(KERN_DEBUG " %3d %d %.4x %.4x\n", |
Luis R. Rodriguez | b446197 | 2008-02-04 10:03:54 -0500 | [diff] [blame] | 926 | ieee80211_frequency_to_channel( |
| 927 | band->channels[i].center_freq), |
| 928 | band->channels[i].center_freq, |
| 929 | band->channels[i].hw_value, |
| 930 | band->channels[i].flags); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 931 | printk(KERN_DEBUG " rates:\n"); |
Luis R. Rodriguez | b446197 | 2008-02-04 10:03:54 -0500 | [diff] [blame] | 932 | for (i = 0; i < band->n_bitrates; i++) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 933 | printk(KERN_DEBUG " %4d %.4x %.4x %.4x\n", |
Luis R. Rodriguez | b446197 | 2008-02-04 10:03:54 -0500 | [diff] [blame] | 934 | band->bitrates[i].bitrate, |
| 935 | band->bitrates[i].hw_value, |
| 936 | band->bitrates[i].flags, |
| 937 | band->bitrates[i].hw_value_short); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 938 | } |
| 939 | } |
| 940 | |
| 941 | static inline void |
Bruno Randolf | b47f407 | 2008-03-05 18:35:45 +0900 | [diff] [blame] | 942 | ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done, |
| 943 | struct ath5k_rx_status *rs) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 944 | { |
| 945 | struct ath5k_desc *ds = bf->desc; |
Bruno Randolf | 19fd6e5 | 2008-03-05 18:35:23 +0900 | [diff] [blame] | 946 | struct ath5k_hw_all_rx_desc *rd = &ds->ud.ds_rx; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 947 | |
| 948 | printk(KERN_DEBUG "R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n", |
| 949 | ds, (unsigned long long)bf->daddr, |
Bruno Randolf | 19fd6e5 | 2008-03-05 18:35:23 +0900 | [diff] [blame] | 950 | ds->ds_link, ds->ds_data, |
| 951 | rd->rx_ctl.rx_control_0, rd->rx_ctl.rx_control_1, |
Bruno Randolf | 62412a8 | 2010-06-16 19:12:12 +0900 | [diff] [blame] | 952 | rd->rx_stat.rx_status_0, rd->rx_stat.rx_status_1, |
Bruno Randolf | b47f407 | 2008-03-05 18:35:45 +0900 | [diff] [blame] | 953 | !done ? ' ' : (rs->rs_status == 0) ? '*' : '!'); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | void |
| 957 | ath5k_debug_printrxbuffs(struct ath5k_softc *sc, struct ath5k_hw *ah) |
| 958 | { |
| 959 | struct ath5k_desc *ds; |
| 960 | struct ath5k_buf *bf; |
Bruno Randolf | b47f407 | 2008-03-05 18:35:45 +0900 | [diff] [blame] | 961 | struct ath5k_rx_status rs = {}; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 962 | int status; |
| 963 | |
Bob Copeland | b4c5261 | 2010-08-21 16:39:03 -0400 | [diff] [blame] | 964 | if (likely(!(sc->debug.level & ATH5K_DEBUG_DESC))) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 965 | return; |
| 966 | |
Bruno Randolf | 265faad | 2010-06-16 19:11:30 +0900 | [diff] [blame] | 967 | printk(KERN_DEBUG "rxdp %x, rxlink %p\n", |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 968 | ath5k_hw_get_rxdp(ah), sc->rxlink); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 969 | |
| 970 | spin_lock_bh(&sc->rxbuflock); |
| 971 | list_for_each_entry(bf, &sc->rxbuf, list) { |
| 972 | ds = bf->desc; |
Bruno Randolf | b47f407 | 2008-03-05 18:35:45 +0900 | [diff] [blame] | 973 | status = ah->ah_proc_rx_desc(ah, ds, &rs); |
Bruno Randolf | be9b725 | 2008-01-23 10:27:51 +0900 | [diff] [blame] | 974 | if (!status) |
Bruno Randolf | b47f407 | 2008-03-05 18:35:45 +0900 | [diff] [blame] | 975 | ath5k_debug_printrxbuf(bf, status == 0, &rs); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 976 | } |
| 977 | spin_unlock_bh(&sc->rxbuflock); |
| 978 | } |
| 979 | |
| 980 | void |
| 981 | ath5k_debug_dump_skb(struct ath5k_softc *sc, |
| 982 | struct sk_buff *skb, const char *prefix, int tx) |
| 983 | { |
| 984 | char buf[16]; |
| 985 | |
| 986 | if (likely(!((tx && (sc->debug.level & ATH5K_DEBUG_DUMP_TX)) || |
| 987 | (!tx && (sc->debug.level & ATH5K_DEBUG_DUMP_RX))))) |
| 988 | return; |
| 989 | |
| 990 | snprintf(buf, sizeof(buf), "%s %s", wiphy_name(sc->hw->wiphy), prefix); |
| 991 | |
| 992 | print_hex_dump_bytes(buf, DUMP_PREFIX_NONE, skb->data, |
| 993 | min(200U, skb->len)); |
| 994 | |
| 995 | printk(KERN_DEBUG "\n"); |
| 996 | } |
| 997 | |
| 998 | void |
Bruno Randolf | b47f407 | 2008-03-05 18:35:45 +0900 | [diff] [blame] | 999 | ath5k_debug_printtxbuf(struct ath5k_softc *sc, struct ath5k_buf *bf) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1000 | { |
| 1001 | struct ath5k_desc *ds = bf->desc; |
Bruno Randolf | 19fd6e5 | 2008-03-05 18:35:23 +0900 | [diff] [blame] | 1002 | struct ath5k_hw_5212_tx_desc *td = &ds->ud.ds_tx5212; |
Bruno Randolf | b47f407 | 2008-03-05 18:35:45 +0900 | [diff] [blame] | 1003 | struct ath5k_tx_status ts = {}; |
| 1004 | int done; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1005 | |
Bob Copeland | b4c5261 | 2010-08-21 16:39:03 -0400 | [diff] [blame] | 1006 | if (likely(!(sc->debug.level & ATH5K_DEBUG_DESC))) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1007 | return; |
| 1008 | |
Bruno Randolf | b47f407 | 2008-03-05 18:35:45 +0900 | [diff] [blame] | 1009 | done = sc->ah->ah_proc_tx_desc(sc->ah, bf->desc, &ts); |
| 1010 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1011 | printk(KERN_DEBUG "T (%p %llx) %08x %08x %08x %08x %08x %08x %08x " |
| 1012 | "%08x %c\n", ds, (unsigned long long)bf->daddr, ds->ds_link, |
Bruno Randolf | 19fd6e5 | 2008-03-05 18:35:23 +0900 | [diff] [blame] | 1013 | ds->ds_data, td->tx_ctl.tx_control_0, td->tx_ctl.tx_control_1, |
| 1014 | td->tx_ctl.tx_control_2, td->tx_ctl.tx_control_3, |
| 1015 | td->tx_stat.tx_status_0, td->tx_stat.tx_status_1, |
Bruno Randolf | b47f407 | 2008-03-05 18:35:45 +0900 | [diff] [blame] | 1016 | done ? ' ' : (ts.ts_status == 0) ? '*' : '!'); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1017 | } |
| 1018 | |
Luis R. Rodriguez | b446197 | 2008-02-04 10:03:54 -0500 | [diff] [blame] | 1019 | #endif /* ifdef CONFIG_ATH5K_DEBUG */ |