1 /* 2 * Copyright (c) 2007-2008 Bruno Randolf <bruno@thinktube.com> 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 #include <linux/export.h> 61 #include <linux/moduleparam.h> 62 63 #include <linux/seq_file.h> 64 #include <linux/list.h> 65 #include "debug.h" 66 #include "ath5k.h" 67 #include "reg.h" 68 #include "base.h" 69 70 static unsigned int ath5k_debug; 71 module_param_named(debug, ath5k_debug, uint, 0); 72 73 74 /* debugfs: registers */ 75 76 struct reg { 77 const char *name; 78 int addr; 79 }; 80 81 #define REG_STRUCT_INIT(r) { #r, r } 82 83 /* just a few random registers, might want to add more */ 84 static const struct reg regs[] = { 85 REG_STRUCT_INIT(AR5K_CR), 86 REG_STRUCT_INIT(AR5K_RXDP), 87 REG_STRUCT_INIT(AR5K_CFG), 88 REG_STRUCT_INIT(AR5K_IER), 89 REG_STRUCT_INIT(AR5K_BCR), 90 REG_STRUCT_INIT(AR5K_RTSD0), 91 REG_STRUCT_INIT(AR5K_RTSD1), 92 REG_STRUCT_INIT(AR5K_TXCFG), 93 REG_STRUCT_INIT(AR5K_RXCFG), 94 REG_STRUCT_INIT(AR5K_RXJLA), 95 REG_STRUCT_INIT(AR5K_MIBC), 96 REG_STRUCT_INIT(AR5K_TOPS), 97 REG_STRUCT_INIT(AR5K_RXNOFRM), 98 REG_STRUCT_INIT(AR5K_TXNOFRM), 99 REG_STRUCT_INIT(AR5K_RPGTO), 100 REG_STRUCT_INIT(AR5K_RFCNT), 101 REG_STRUCT_INIT(AR5K_MISC), 102 REG_STRUCT_INIT(AR5K_QCUDCU_CLKGT), 103 REG_STRUCT_INIT(AR5K_ISR), 104 REG_STRUCT_INIT(AR5K_PISR), 105 REG_STRUCT_INIT(AR5K_SISR0), 106 REG_STRUCT_INIT(AR5K_SISR1), 107 REG_STRUCT_INIT(AR5K_SISR2), 108 REG_STRUCT_INIT(AR5K_SISR3), 109 REG_STRUCT_INIT(AR5K_SISR4), 110 REG_STRUCT_INIT(AR5K_IMR), 111 REG_STRUCT_INIT(AR5K_PIMR), 112 REG_STRUCT_INIT(AR5K_SIMR0), 113 REG_STRUCT_INIT(AR5K_SIMR1), 114 REG_STRUCT_INIT(AR5K_SIMR2), 115 REG_STRUCT_INIT(AR5K_SIMR3), 116 REG_STRUCT_INIT(AR5K_SIMR4), 117 REG_STRUCT_INIT(AR5K_DCM_ADDR), 118 REG_STRUCT_INIT(AR5K_DCCFG), 119 REG_STRUCT_INIT(AR5K_CCFG), 120 REG_STRUCT_INIT(AR5K_CPC0), 121 REG_STRUCT_INIT(AR5K_CPC1), 122 REG_STRUCT_INIT(AR5K_CPC2), 123 REG_STRUCT_INIT(AR5K_CPC3), 124 REG_STRUCT_INIT(AR5K_CPCOVF), 125 REG_STRUCT_INIT(AR5K_RESET_CTL), 126 REG_STRUCT_INIT(AR5K_SLEEP_CTL), 127 REG_STRUCT_INIT(AR5K_INTPEND), 128 REG_STRUCT_INIT(AR5K_SFR), 129 REG_STRUCT_INIT(AR5K_PCICFG), 130 REG_STRUCT_INIT(AR5K_GPIOCR), 131 REG_STRUCT_INIT(AR5K_GPIODO), 132 REG_STRUCT_INIT(AR5K_SREV), 133 }; 134 135 static void *reg_start(struct seq_file *seq, loff_t *pos) 136 { 137 return *pos < ARRAY_SIZE(regs) ? (void *)®s[*pos] : NULL; 138 } 139 140 static void reg_stop(struct seq_file *seq, void *p) 141 { 142 /* nothing to do */ 143 } 144 145 static void *reg_next(struct seq_file *seq, void *p, loff_t *pos) 146 { 147 ++*pos; 148 return *pos < ARRAY_SIZE(regs) ? (void *)®s[*pos] : NULL; 149 } 150 151 static int reg_show(struct seq_file *seq, void *p) 152 { 153 struct ath5k_hw *ah = seq->private; 154 struct reg *r = p; 155 seq_printf(seq, "%-25s0x%08x\n", r->name, 156 ath5k_hw_reg_read(ah, r->addr)); 157 return 0; 158 } 159 160 static const struct seq_operations register_seq_ops = { 161 .start = reg_start, 162 .next = reg_next, 163 .stop = reg_stop, 164 .show = reg_show 165 }; 166 167 static int open_file_registers(struct inode *inode, struct file *file) 168 { 169 struct seq_file *s; 170 int res; 171 res = seq_open(file, ®ister_seq_ops); 172 if (res == 0) { 173 s = file->private_data; 174 s->private = inode->i_private; 175 } 176 return res; 177 } 178 179 static const struct file_operations fops_registers = { 180 .open = open_file_registers, 181 .read = seq_read, 182 .llseek = seq_lseek, 183 .release = seq_release, 184 .owner = THIS_MODULE, 185 }; 186 187 188 /* debugfs: beacons */ 189 190 static ssize_t read_file_beacon(struct file *file, char __user *user_buf, 191 size_t count, loff_t *ppos) 192 { 193 struct ath5k_hw *ah = file->private_data; 194 char buf[500]; 195 unsigned int len = 0; 196 unsigned int v; 197 u64 tsf; 198 199 v = ath5k_hw_reg_read(ah, AR5K_BEACON); 200 len += snprintf(buf + len, sizeof(buf) - len, 201 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n", 202 "AR5K_BEACON", v, v & AR5K_BEACON_PERIOD, 203 (v & AR5K_BEACON_TIM) >> AR5K_BEACON_TIM_S); 204 205 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\n", 206 "AR5K_LAST_TSTP", ath5k_hw_reg_read(ah, AR5K_LAST_TSTP)); 207 208 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\n\n", 209 "AR5K_BEACON_CNT", ath5k_hw_reg_read(ah, AR5K_BEACON_CNT)); 210 211 v = ath5k_hw_reg_read(ah, AR5K_TIMER0); 212 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\tTU: %08x\n", 213 "AR5K_TIMER0 (TBTT)", v, v); 214 215 v = ath5k_hw_reg_read(ah, AR5K_TIMER1); 216 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\tTU: %08x\n", 217 "AR5K_TIMER1 (DMA)", v, v >> 3); 218 219 v = ath5k_hw_reg_read(ah, AR5K_TIMER2); 220 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\tTU: %08x\n", 221 "AR5K_TIMER2 (SWBA)", v, v >> 3); 222 223 v = ath5k_hw_reg_read(ah, AR5K_TIMER3); 224 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\tTU: %08x\n", 225 "AR5K_TIMER3 (ATIM)", v, v); 226 227 tsf = ath5k_hw_get_tsf64(ah); 228 len += snprintf(buf + len, sizeof(buf) - len, 229 "TSF\t\t0x%016llx\tTU: %08x\n", 230 (unsigned long long)tsf, TSF_TO_TU(tsf)); 231 232 if (len > sizeof(buf)) 233 len = sizeof(buf); 234 235 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 236 } 237 238 static ssize_t write_file_beacon(struct file *file, 239 const char __user *userbuf, 240 size_t count, loff_t *ppos) 241 { 242 struct ath5k_hw *ah = file->private_data; 243 char buf[20]; 244 245 if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) 246 return -EFAULT; 247 248 if (strncmp(buf, "disable", 7) == 0) { 249 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE); 250 printk(KERN_INFO "debugfs disable beacons\n"); 251 } else if (strncmp(buf, "enable", 6) == 0) { 252 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE); 253 printk(KERN_INFO "debugfs enable beacons\n"); 254 } 255 return count; 256 } 257 258 static const struct file_operations fops_beacon = { 259 .read = read_file_beacon, 260 .write = write_file_beacon, 261 .open = simple_open, 262 .owner = THIS_MODULE, 263 .llseek = default_llseek, 264 }; 265 266 267 /* debugfs: reset */ 268 269 static ssize_t write_file_reset(struct file *file, 270 const char __user *userbuf, 271 size_t count, loff_t *ppos) 272 { 273 struct ath5k_hw *ah = file->private_data; 274 ATH5K_DBG(ah, ATH5K_DEBUG_RESET, "debug file triggered reset\n"); 275 ieee80211_queue_work(ah->hw, &ah->reset_work); 276 return count; 277 } 278 279 static const struct file_operations fops_reset = { 280 .write = write_file_reset, 281 .open = simple_open, 282 .owner = THIS_MODULE, 283 .llseek = noop_llseek, 284 }; 285 286 287 /* debugfs: debug level */ 288 289 static const struct { 290 enum ath5k_debug_level level; 291 const char *name; 292 const char *desc; 293 } dbg_info[] = { 294 { ATH5K_DEBUG_RESET, "reset", "reset and initialization" }, 295 { ATH5K_DEBUG_INTR, "intr", "interrupt handling" }, 296 { ATH5K_DEBUG_MODE, "mode", "mode init/setup" }, 297 { ATH5K_DEBUG_XMIT, "xmit", "basic xmit operation" }, 298 { ATH5K_DEBUG_BEACON, "beacon", "beacon handling" }, 299 { ATH5K_DEBUG_CALIBRATE, "calib", "periodic calibration" }, 300 { ATH5K_DEBUG_TXPOWER, "txpower", "transmit power setting" }, 301 { ATH5K_DEBUG_LED, "led", "LED management" }, 302 { ATH5K_DEBUG_DUMPBANDS, "dumpbands", "dump bands" }, 303 { ATH5K_DEBUG_DMA, "dma", "dma start/stop" }, 304 { ATH5K_DEBUG_ANI, "ani", "adaptive noise immunity" }, 305 { ATH5K_DEBUG_DESC, "desc", "descriptor chains" }, 306 { ATH5K_DEBUG_ANY, "all", "show all debug levels" }, 307 }; 308 309 static ssize_t read_file_debug(struct file *file, char __user *user_buf, 310 size_t count, loff_t *ppos) 311 { 312 struct ath5k_hw *ah = file->private_data; 313 char buf[700]; 314 unsigned int len = 0; 315 unsigned int i; 316 317 len += snprintf(buf + len, sizeof(buf) - len, 318 "DEBUG LEVEL: 0x%08x\n\n", ah->debug.level); 319 320 for (i = 0; i < ARRAY_SIZE(dbg_info) - 1; i++) { 321 len += snprintf(buf + len, sizeof(buf) - len, 322 "%10s %c 0x%08x - %s\n", dbg_info[i].name, 323 ah->debug.level & dbg_info[i].level ? '+' : ' ', 324 dbg_info[i].level, dbg_info[i].desc); 325 } 326 len += snprintf(buf + len, sizeof(buf) - len, 327 "%10s %c 0x%08x - %s\n", dbg_info[i].name, 328 ah->debug.level == dbg_info[i].level ? '+' : ' ', 329 dbg_info[i].level, dbg_info[i].desc); 330 331 if (len > sizeof(buf)) 332 len = sizeof(buf); 333 334 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 335 } 336 337 static ssize_t write_file_debug(struct file *file, 338 const char __user *userbuf, 339 size_t count, loff_t *ppos) 340 { 341 struct ath5k_hw *ah = file->private_data; 342 unsigned int i; 343 char buf[20]; 344 345 if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) 346 return -EFAULT; 347 348 for (i = 0; i < ARRAY_SIZE(dbg_info); i++) { 349 if (strncmp(buf, dbg_info[i].name, 350 strlen(dbg_info[i].name)) == 0) { 351 ah->debug.level ^= dbg_info[i].level; /* toggle bit */ 352 break; 353 } 354 } 355 return count; 356 } 357 358 static const struct file_operations fops_debug = { 359 .read = read_file_debug, 360 .write = write_file_debug, 361 .open = simple_open, 362 .owner = THIS_MODULE, 363 .llseek = default_llseek, 364 }; 365 366 367 /* debugfs: antenna */ 368 369 static ssize_t read_file_antenna(struct file *file, char __user *user_buf, 370 size_t count, loff_t *ppos) 371 { 372 struct ath5k_hw *ah = file->private_data; 373 char buf[700]; 374 unsigned int len = 0; 375 unsigned int i; 376 unsigned int v; 377 378 len += snprintf(buf + len, sizeof(buf) - len, "antenna mode\t%d\n", 379 ah->ah_ant_mode); 380 len += snprintf(buf + len, sizeof(buf) - len, "default antenna\t%d\n", 381 ah->ah_def_ant); 382 len += snprintf(buf + len, sizeof(buf) - len, "tx antenna\t%d\n", 383 ah->ah_tx_ant); 384 385 len += snprintf(buf + len, sizeof(buf) - len, "\nANTENNA\t\tRX\tTX\n"); 386 for (i = 1; i < ARRAY_SIZE(ah->stats.antenna_rx); i++) { 387 len += snprintf(buf + len, sizeof(buf) - len, 388 "[antenna %d]\t%d\t%d\n", 389 i, ah->stats.antenna_rx[i], ah->stats.antenna_tx[i]); 390 } 391 len += snprintf(buf + len, sizeof(buf) - len, "[invalid]\t%d\t%d\n", 392 ah->stats.antenna_rx[0], ah->stats.antenna_tx[0]); 393 394 v = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA); 395 len += snprintf(buf + len, sizeof(buf) - len, 396 "\nAR5K_DEFAULT_ANTENNA\t0x%08x\n", v); 397 398 v = ath5k_hw_reg_read(ah, AR5K_STA_ID1); 399 len += snprintf(buf + len, sizeof(buf) - len, 400 "AR5K_STA_ID1_DEFAULT_ANTENNA\t%d\n", 401 (v & AR5K_STA_ID1_DEFAULT_ANTENNA) != 0); 402 len += snprintf(buf + len, sizeof(buf) - len, 403 "AR5K_STA_ID1_DESC_ANTENNA\t%d\n", 404 (v & AR5K_STA_ID1_DESC_ANTENNA) != 0); 405 len += snprintf(buf + len, sizeof(buf) - len, 406 "AR5K_STA_ID1_RTS_DEF_ANTENNA\t%d\n", 407 (v & AR5K_STA_ID1_RTS_DEF_ANTENNA) != 0); 408 len += snprintf(buf + len, sizeof(buf) - len, 409 "AR5K_STA_ID1_SELFGEN_DEF_ANT\t%d\n", 410 (v & AR5K_STA_ID1_SELFGEN_DEF_ANT) != 0); 411 412 v = ath5k_hw_reg_read(ah, AR5K_PHY_AGCCTL); 413 len += snprintf(buf + len, sizeof(buf) - len, 414 "\nAR5K_PHY_AGCCTL_OFDM_DIV_DIS\t%d\n", 415 (v & AR5K_PHY_AGCCTL_OFDM_DIV_DIS) != 0); 416 417 v = ath5k_hw_reg_read(ah, AR5K_PHY_RESTART); 418 len += snprintf(buf + len, sizeof(buf) - len, 419 "AR5K_PHY_RESTART_DIV_GC\t\t%x\n", 420 (v & AR5K_PHY_RESTART_DIV_GC) >> AR5K_PHY_RESTART_DIV_GC_S); 421 422 v = ath5k_hw_reg_read(ah, AR5K_PHY_FAST_ANT_DIV); 423 len += snprintf(buf + len, sizeof(buf) - len, 424 "AR5K_PHY_FAST_ANT_DIV_EN\t%d\n", 425 (v & AR5K_PHY_FAST_ANT_DIV_EN) != 0); 426 427 v = ath5k_hw_reg_read(ah, AR5K_PHY_ANT_SWITCH_TABLE_0); 428 len += snprintf(buf + len, sizeof(buf) - len, 429 "\nAR5K_PHY_ANT_SWITCH_TABLE_0\t0x%08x\n", v); 430 v = ath5k_hw_reg_read(ah, AR5K_PHY_ANT_SWITCH_TABLE_1); 431 len += snprintf(buf + len, sizeof(buf) - len, 432 "AR5K_PHY_ANT_SWITCH_TABLE_1\t0x%08x\n", v); 433 434 if (len > sizeof(buf)) 435 len = sizeof(buf); 436 437 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 438 } 439 440 static ssize_t write_file_antenna(struct file *file, 441 const char __user *userbuf, 442 size_t count, loff_t *ppos) 443 { 444 struct ath5k_hw *ah = file->private_data; 445 unsigned int i; 446 char buf[20]; 447 448 if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) 449 return -EFAULT; 450 451 if (strncmp(buf, "diversity", 9) == 0) { 452 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_DEFAULT); 453 printk(KERN_INFO "ath5k debug: enable diversity\n"); 454 } else if (strncmp(buf, "fixed-a", 7) == 0) { 455 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_A); 456 printk(KERN_INFO "ath5k debugfs: fixed antenna A\n"); 457 } else if (strncmp(buf, "fixed-b", 7) == 0) { 458 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_B); 459 printk(KERN_INFO "ath5k debug: fixed antenna B\n"); 460 } else if (strncmp(buf, "clear", 5) == 0) { 461 for (i = 0; i < ARRAY_SIZE(ah->stats.antenna_rx); i++) { 462 ah->stats.antenna_rx[i] = 0; 463 ah->stats.antenna_tx[i] = 0; 464 } 465 printk(KERN_INFO "ath5k debug: cleared antenna stats\n"); 466 } 467 return count; 468 } 469 470 static const struct file_operations fops_antenna = { 471 .read = read_file_antenna, 472 .write = write_file_antenna, 473 .open = simple_open, 474 .owner = THIS_MODULE, 475 .llseek = default_llseek, 476 }; 477 478 /* debugfs: misc */ 479 480 static ssize_t read_file_misc(struct file *file, char __user *user_buf, 481 size_t count, loff_t *ppos) 482 { 483 struct ath5k_hw *ah = file->private_data; 484 char buf[700]; 485 unsigned int len = 0; 486 u32 filt = ath5k_hw_get_rx_filter(ah); 487 488 len += snprintf(buf + len, sizeof(buf) - len, "bssid-mask: %pM\n", 489 ah->bssidmask); 490 len += snprintf(buf + len, sizeof(buf) - len, "filter-flags: 0x%x ", 491 filt); 492 if (filt & AR5K_RX_FILTER_UCAST) 493 len += snprintf(buf + len, sizeof(buf) - len, " UCAST"); 494 if (filt & AR5K_RX_FILTER_MCAST) 495 len += snprintf(buf + len, sizeof(buf) - len, " MCAST"); 496 if (filt & AR5K_RX_FILTER_BCAST) 497 len += snprintf(buf + len, sizeof(buf) - len, " BCAST"); 498 if (filt & AR5K_RX_FILTER_CONTROL) 499 len += snprintf(buf + len, sizeof(buf) - len, " CONTROL"); 500 if (filt & AR5K_RX_FILTER_BEACON) 501 len += snprintf(buf + len, sizeof(buf) - len, " BEACON"); 502 if (filt & AR5K_RX_FILTER_PROM) 503 len += snprintf(buf + len, sizeof(buf) - len, " PROM"); 504 if (filt & AR5K_RX_FILTER_XRPOLL) 505 len += snprintf(buf + len, sizeof(buf) - len, " XRPOLL"); 506 if (filt & AR5K_RX_FILTER_PROBEREQ) 507 len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ"); 508 if (filt & AR5K_RX_FILTER_PHYERR_5212) 509 len += snprintf(buf + len, sizeof(buf) - len, " PHYERR-5212"); 510 if (filt & AR5K_RX_FILTER_RADARERR_5212) 511 len += snprintf(buf + len, sizeof(buf) - len, " RADARERR-5212"); 512 if (filt & AR5K_RX_FILTER_PHYERR_5211) 513 snprintf(buf + len, sizeof(buf) - len, " PHYERR-5211"); 514 if (filt & AR5K_RX_FILTER_RADARERR_5211) 515 len += snprintf(buf + len, sizeof(buf) - len, " RADARERR-5211"); 516 517 len += snprintf(buf + len, sizeof(buf) - len, "\nopmode: %s (%d)\n", 518 ath_opmode_to_string(ah->opmode), ah->opmode); 519 520 if (len > sizeof(buf)) 521 len = sizeof(buf); 522 523 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 524 } 525 526 static const struct file_operations fops_misc = { 527 .read = read_file_misc, 528 .open = simple_open, 529 .owner = THIS_MODULE, 530 }; 531 532 533 /* debugfs: frameerrors */ 534 535 static ssize_t read_file_frameerrors(struct file *file, char __user *user_buf, 536 size_t count, loff_t *ppos) 537 { 538 struct ath5k_hw *ah = file->private_data; 539 struct ath5k_statistics *st = &ah->stats; 540 char buf[700]; 541 unsigned int len = 0; 542 int i; 543 544 len += snprintf(buf + len, sizeof(buf) - len, 545 "RX\n---------------------\n"); 546 len += snprintf(buf + len, sizeof(buf) - len, "CRC\t%u\t(%u%%)\n", 547 st->rxerr_crc, 548 st->rx_all_count > 0 ? 549 st->rxerr_crc * 100 / st->rx_all_count : 0); 550 len += snprintf(buf + len, sizeof(buf) - len, "PHY\t%u\t(%u%%)\n", 551 st->rxerr_phy, 552 st->rx_all_count > 0 ? 553 st->rxerr_phy * 100 / st->rx_all_count : 0); 554 for (i = 0; i < 32; i++) { 555 if (st->rxerr_phy_code[i]) 556 len += snprintf(buf + len, sizeof(buf) - len, 557 " phy_err[%u]\t%u\n", 558 i, st->rxerr_phy_code[i]); 559 } 560 561 len += snprintf(buf + len, sizeof(buf) - len, "FIFO\t%u\t(%u%%)\n", 562 st->rxerr_fifo, 563 st->rx_all_count > 0 ? 564 st->rxerr_fifo * 100 / st->rx_all_count : 0); 565 len += snprintf(buf + len, sizeof(buf) - len, "decrypt\t%u\t(%u%%)\n", 566 st->rxerr_decrypt, 567 st->rx_all_count > 0 ? 568 st->rxerr_decrypt * 100 / st->rx_all_count : 0); 569 len += snprintf(buf + len, sizeof(buf) - len, "MIC\t%u\t(%u%%)\n", 570 st->rxerr_mic, 571 st->rx_all_count > 0 ? 572 st->rxerr_mic * 100 / st->rx_all_count : 0); 573 len += snprintf(buf + len, sizeof(buf) - len, "process\t%u\t(%u%%)\n", 574 st->rxerr_proc, 575 st->rx_all_count > 0 ? 576 st->rxerr_proc * 100 / st->rx_all_count : 0); 577 len += snprintf(buf + len, sizeof(buf) - len, "jumbo\t%u\t(%u%%)\n", 578 st->rxerr_jumbo, 579 st->rx_all_count > 0 ? 580 st->rxerr_jumbo * 100 / st->rx_all_count : 0); 581 len += snprintf(buf + len, sizeof(buf) - len, "[RX all\t%u]\n", 582 st->rx_all_count); 583 len += snprintf(buf + len, sizeof(buf) - len, "RX-all-bytes\t%u\n", 584 st->rx_bytes_count); 585 586 len += snprintf(buf + len, sizeof(buf) - len, 587 "\nTX\n---------------------\n"); 588 len += snprintf(buf + len, sizeof(buf) - len, "retry\t%u\t(%u%%)\n", 589 st->txerr_retry, 590 st->tx_all_count > 0 ? 591 st->txerr_retry * 100 / st->tx_all_count : 0); 592 len += snprintf(buf + len, sizeof(buf) - len, "FIFO\t%u\t(%u%%)\n", 593 st->txerr_fifo, 594 st->tx_all_count > 0 ? 595 st->txerr_fifo * 100 / st->tx_all_count : 0); 596 len += snprintf(buf + len, sizeof(buf) - len, "filter\t%u\t(%u%%)\n", 597 st->txerr_filt, 598 st->tx_all_count > 0 ? 599 st->txerr_filt * 100 / st->tx_all_count : 0); 600 len += snprintf(buf + len, sizeof(buf) - len, "[TX all\t%u]\n", 601 st->tx_all_count); 602 len += snprintf(buf + len, sizeof(buf) - len, "TX-all-bytes\t%u\n", 603 st->tx_bytes_count); 604 605 if (len > sizeof(buf)) 606 len = sizeof(buf); 607 608 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 609 } 610 611 static ssize_t write_file_frameerrors(struct file *file, 612 const char __user *userbuf, 613 size_t count, loff_t *ppos) 614 { 615 struct ath5k_hw *ah = file->private_data; 616 struct ath5k_statistics *st = &ah->stats; 617 char buf[20]; 618 619 if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) 620 return -EFAULT; 621 622 if (strncmp(buf, "clear", 5) == 0) { 623 st->rxerr_crc = 0; 624 st->rxerr_phy = 0; 625 st->rxerr_fifo = 0; 626 st->rxerr_decrypt = 0; 627 st->rxerr_mic = 0; 628 st->rxerr_proc = 0; 629 st->rxerr_jumbo = 0; 630 st->rx_all_count = 0; 631 st->txerr_retry = 0; 632 st->txerr_fifo = 0; 633 st->txerr_filt = 0; 634 st->tx_all_count = 0; 635 printk(KERN_INFO "ath5k debug: cleared frameerrors stats\n"); 636 } 637 return count; 638 } 639 640 static const struct file_operations fops_frameerrors = { 641 .read = read_file_frameerrors, 642 .write = write_file_frameerrors, 643 .open = simple_open, 644 .owner = THIS_MODULE, 645 .llseek = default_llseek, 646 }; 647 648 649 /* debugfs: ani */ 650 651 static ssize_t read_file_ani(struct file *file, char __user *user_buf, 652 size_t count, loff_t *ppos) 653 { 654 struct ath5k_hw *ah = file->private_data; 655 struct ath5k_statistics *st = &ah->stats; 656 struct ath5k_ani_state *as = &ah->ani_state; 657 658 char buf[700]; 659 unsigned int len = 0; 660 661 len += snprintf(buf + len, sizeof(buf) - len, 662 "HW has PHY error counters:\t%s\n", 663 ah->ah_capabilities.cap_has_phyerr_counters ? 664 "yes" : "no"); 665 len += snprintf(buf + len, sizeof(buf) - len, 666 "HW max spur immunity level:\t%d\n", 667 as->max_spur_level); 668 len += snprintf(buf + len, sizeof(buf) - len, 669 "\nANI state\n--------------------------------------------\n"); 670 len += snprintf(buf + len, sizeof(buf) - len, "operating mode:\t\t\t"); 671 switch (as->ani_mode) { 672 case ATH5K_ANI_MODE_OFF: 673 len += snprintf(buf + len, sizeof(buf) - len, "OFF\n"); 674 break; 675 case ATH5K_ANI_MODE_MANUAL_LOW: 676 len += snprintf(buf + len, sizeof(buf) - len, 677 "MANUAL LOW\n"); 678 break; 679 case ATH5K_ANI_MODE_MANUAL_HIGH: 680 len += snprintf(buf + len, sizeof(buf) - len, 681 "MANUAL HIGH\n"); 682 break; 683 case ATH5K_ANI_MODE_AUTO: 684 len += snprintf(buf + len, sizeof(buf) - len, "AUTO\n"); 685 break; 686 default: 687 len += snprintf(buf + len, sizeof(buf) - len, 688 "??? (not good)\n"); 689 break; 690 } 691 len += snprintf(buf + len, sizeof(buf) - len, 692 "noise immunity level:\t\t%d\n", 693 as->noise_imm_level); 694 len += snprintf(buf + len, sizeof(buf) - len, 695 "spur immunity level:\t\t%d\n", 696 as->spur_level); 697 len += snprintf(buf + len, sizeof(buf) - len, 698 "firstep level:\t\t\t%d\n", 699 as->firstep_level); 700 len += snprintf(buf + len, sizeof(buf) - len, 701 "OFDM weak signal detection:\t%s\n", 702 as->ofdm_weak_sig ? "on" : "off"); 703 len += snprintf(buf + len, sizeof(buf) - len, 704 "CCK weak signal detection:\t%s\n", 705 as->cck_weak_sig ? "on" : "off"); 706 707 len += snprintf(buf + len, sizeof(buf) - len, 708 "\nMIB INTERRUPTS:\t\t%u\n", 709 st->mib_intr); 710 len += snprintf(buf + len, sizeof(buf) - len, 711 "beacon RSSI average:\t%d\n", 712 (int)ewma_read(&ah->ah_beacon_rssi_avg)); 713 714 #define CC_PRINT(_struct, _field) \ 715 _struct._field, \ 716 _struct.cycles > 0 ? \ 717 _struct._field * 100 / _struct.cycles : 0 718 719 len += snprintf(buf + len, sizeof(buf) - len, 720 "profcnt tx\t\t%u\t(%d%%)\n", 721 CC_PRINT(as->last_cc, tx_frame)); 722 len += snprintf(buf + len, sizeof(buf) - len, 723 "profcnt rx\t\t%u\t(%d%%)\n", 724 CC_PRINT(as->last_cc, rx_frame)); 725 len += snprintf(buf + len, sizeof(buf) - len, 726 "profcnt busy\t\t%u\t(%d%%)\n", 727 CC_PRINT(as->last_cc, rx_busy)); 728 #undef CC_PRINT 729 len += snprintf(buf + len, sizeof(buf) - len, "profcnt cycles\t\t%u\n", 730 as->last_cc.cycles); 731 len += snprintf(buf + len, sizeof(buf) - len, 732 "listen time\t\t%d\tlast: %d\n", 733 as->listen_time, as->last_listen); 734 len += snprintf(buf + len, sizeof(buf) - len, 735 "OFDM errors\t\t%u\tlast: %u\tsum: %u\n", 736 as->ofdm_errors, as->last_ofdm_errors, 737 as->sum_ofdm_errors); 738 len += snprintf(buf + len, sizeof(buf) - len, 739 "CCK errors\t\t%u\tlast: %u\tsum: %u\n", 740 as->cck_errors, as->last_cck_errors, 741 as->sum_cck_errors); 742 len += snprintf(buf + len, sizeof(buf) - len, 743 "AR5K_PHYERR_CNT1\t%x\t(=%d)\n", 744 ath5k_hw_reg_read(ah, AR5K_PHYERR_CNT1), 745 ATH5K_ANI_OFDM_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX - 746 ath5k_hw_reg_read(ah, AR5K_PHYERR_CNT1))); 747 len += snprintf(buf + len, sizeof(buf) - len, 748 "AR5K_PHYERR_CNT2\t%x\t(=%d)\n", 749 ath5k_hw_reg_read(ah, AR5K_PHYERR_CNT2), 750 ATH5K_ANI_CCK_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX - 751 ath5k_hw_reg_read(ah, AR5K_PHYERR_CNT2))); 752 753 if (len > sizeof(buf)) 754 len = sizeof(buf); 755 756 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 757 } 758 759 static ssize_t write_file_ani(struct file *file, 760 const char __user *userbuf, 761 size_t count, loff_t *ppos) 762 { 763 struct ath5k_hw *ah = file->private_data; 764 char buf[20]; 765 766 if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) 767 return -EFAULT; 768 769 if (strncmp(buf, "sens-low", 8) == 0) { 770 ath5k_ani_init(ah, ATH5K_ANI_MODE_MANUAL_HIGH); 771 } else if (strncmp(buf, "sens-high", 9) == 0) { 772 ath5k_ani_init(ah, ATH5K_ANI_MODE_MANUAL_LOW); 773 } else if (strncmp(buf, "ani-off", 7) == 0) { 774 ath5k_ani_init(ah, ATH5K_ANI_MODE_OFF); 775 } else if (strncmp(buf, "ani-on", 6) == 0) { 776 ath5k_ani_init(ah, ATH5K_ANI_MODE_AUTO); 777 } else if (strncmp(buf, "noise-low", 9) == 0) { 778 ath5k_ani_set_noise_immunity_level(ah, 0); 779 } else if (strncmp(buf, "noise-high", 10) == 0) { 780 ath5k_ani_set_noise_immunity_level(ah, 781 ATH5K_ANI_MAX_NOISE_IMM_LVL); 782 } else if (strncmp(buf, "spur-low", 8) == 0) { 783 ath5k_ani_set_spur_immunity_level(ah, 0); 784 } else if (strncmp(buf, "spur-high", 9) == 0) { 785 ath5k_ani_set_spur_immunity_level(ah, 786 ah->ani_state.max_spur_level); 787 } else if (strncmp(buf, "fir-low", 7) == 0) { 788 ath5k_ani_set_firstep_level(ah, 0); 789 } else if (strncmp(buf, "fir-high", 8) == 0) { 790 ath5k_ani_set_firstep_level(ah, ATH5K_ANI_MAX_FIRSTEP_LVL); 791 } else if (strncmp(buf, "ofdm-off", 8) == 0) { 792 ath5k_ani_set_ofdm_weak_signal_detection(ah, false); 793 } else if (strncmp(buf, "ofdm-on", 7) == 0) { 794 ath5k_ani_set_ofdm_weak_signal_detection(ah, true); 795 } else if (strncmp(buf, "cck-off", 7) == 0) { 796 ath5k_ani_set_cck_weak_signal_detection(ah, false); 797 } else if (strncmp(buf, "cck-on", 6) == 0) { 798 ath5k_ani_set_cck_weak_signal_detection(ah, true); 799 } 800 return count; 801 } 802 803 static const struct file_operations fops_ani = { 804 .read = read_file_ani, 805 .write = write_file_ani, 806 .open = simple_open, 807 .owner = THIS_MODULE, 808 .llseek = default_llseek, 809 }; 810 811 812 /* debugfs: queues etc */ 813 814 static ssize_t read_file_queue(struct file *file, char __user *user_buf, 815 size_t count, loff_t *ppos) 816 { 817 struct ath5k_hw *ah = file->private_data; 818 char buf[700]; 819 unsigned int len = 0; 820 821 struct ath5k_txq *txq; 822 struct ath5k_buf *bf, *bf0; 823 int i, n; 824 825 len += snprintf(buf + len, sizeof(buf) - len, 826 "available txbuffers: %d\n", ah->txbuf_len); 827 828 for (i = 0; i < ARRAY_SIZE(ah->txqs); i++) { 829 txq = &ah->txqs[i]; 830 831 len += snprintf(buf + len, sizeof(buf) - len, 832 "%02d: %ssetup\n", i, txq->setup ? "" : "not "); 833 834 if (!txq->setup) 835 continue; 836 837 n = 0; 838 spin_lock_bh(&txq->lock); 839 list_for_each_entry_safe(bf, bf0, &txq->q, list) 840 n++; 841 spin_unlock_bh(&txq->lock); 842 843 len += snprintf(buf + len, sizeof(buf) - len, 844 " len: %d bufs: %d\n", txq->txq_len, n); 845 len += snprintf(buf + len, sizeof(buf) - len, 846 " stuck: %d\n", txq->txq_stuck); 847 } 848 849 if (len > sizeof(buf)) 850 len = sizeof(buf); 851 852 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 853 } 854 855 static ssize_t write_file_queue(struct file *file, 856 const char __user *userbuf, 857 size_t count, loff_t *ppos) 858 { 859 struct ath5k_hw *ah = file->private_data; 860 char buf[20]; 861 862 if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) 863 return -EFAULT; 864 865 if (strncmp(buf, "start", 5) == 0) 866 ieee80211_wake_queues(ah->hw); 867 else if (strncmp(buf, "stop", 4) == 0) 868 ieee80211_stop_queues(ah->hw); 869 870 return count; 871 } 872 873 874 static const struct file_operations fops_queue = { 875 .read = read_file_queue, 876 .write = write_file_queue, 877 .open = simple_open, 878 .owner = THIS_MODULE, 879 .llseek = default_llseek, 880 }; 881 882 883 void 884 ath5k_debug_init_device(struct ath5k_hw *ah) 885 { 886 struct dentry *phydir; 887 888 ah->debug.level = ath5k_debug; 889 890 phydir = debugfs_create_dir("ath5k", ah->hw->wiphy->debugfsdir); 891 if (!phydir) 892 return; 893 894 debugfs_create_file("debug", S_IWUSR | S_IRUSR, phydir, ah, 895 &fops_debug); 896 897 debugfs_create_file("registers", S_IRUSR, phydir, ah, &fops_registers); 898 899 debugfs_create_file("beacon", S_IWUSR | S_IRUSR, phydir, ah, 900 &fops_beacon); 901 902 debugfs_create_file("reset", S_IWUSR, phydir, ah, &fops_reset); 903 904 debugfs_create_file("antenna", S_IWUSR | S_IRUSR, phydir, ah, 905 &fops_antenna); 906 907 debugfs_create_file("misc", S_IRUSR, phydir, ah, &fops_misc); 908 909 debugfs_create_file("frameerrors", S_IWUSR | S_IRUSR, phydir, ah, 910 &fops_frameerrors); 911 912 debugfs_create_file("ani", S_IWUSR | S_IRUSR, phydir, ah, &fops_ani); 913 914 debugfs_create_file("queue", S_IWUSR | S_IRUSR, phydir, ah, 915 &fops_queue); 916 917 debugfs_create_bool("32khz_clock", S_IWUSR | S_IRUSR, phydir, 918 &ah->ah_use_32khz_clock); 919 } 920 921 /* functions used in other places */ 922 923 void 924 ath5k_debug_dump_bands(struct ath5k_hw *ah) 925 { 926 unsigned int b, i; 927 928 if (likely(!(ah->debug.level & ATH5K_DEBUG_DUMPBANDS))) 929 return; 930 931 BUG_ON(!ah->sbands); 932 933 for (b = 0; b < IEEE80211_NUM_BANDS; b++) { 934 struct ieee80211_supported_band *band = &ah->sbands[b]; 935 char bname[6]; 936 switch (band->band) { 937 case IEEE80211_BAND_2GHZ: 938 strcpy(bname, "2 GHz"); 939 break; 940 case IEEE80211_BAND_5GHZ: 941 strcpy(bname, "5 GHz"); 942 break; 943 default: 944 printk(KERN_DEBUG "Band not supported: %d\n", 945 band->band); 946 return; 947 } 948 printk(KERN_DEBUG "Band %s: channels %d, rates %d\n", bname, 949 band->n_channels, band->n_bitrates); 950 printk(KERN_DEBUG " channels:\n"); 951 for (i = 0; i < band->n_channels; i++) 952 printk(KERN_DEBUG " %3d %d %.4x %.4x\n", 953 ieee80211_frequency_to_channel( 954 band->channels[i].center_freq), 955 band->channels[i].center_freq, 956 band->channels[i].hw_value, 957 band->channels[i].flags); 958 printk(KERN_DEBUG " rates:\n"); 959 for (i = 0; i < band->n_bitrates; i++) 960 printk(KERN_DEBUG " %4d %.4x %.4x %.4x\n", 961 band->bitrates[i].bitrate, 962 band->bitrates[i].hw_value, 963 band->bitrates[i].flags, 964 band->bitrates[i].hw_value_short); 965 } 966 } 967 968 static inline void 969 ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done, 970 struct ath5k_rx_status *rs) 971 { 972 struct ath5k_desc *ds = bf->desc; 973 struct ath5k_hw_all_rx_desc *rd = &ds->ud.ds_rx; 974 975 printk(KERN_DEBUG "R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n", 976 ds, (unsigned long long)bf->daddr, 977 ds->ds_link, ds->ds_data, 978 rd->rx_ctl.rx_control_0, rd->rx_ctl.rx_control_1, 979 rd->rx_stat.rx_status_0, rd->rx_stat.rx_status_1, 980 !done ? ' ' : (rs->rs_status == 0) ? '*' : '!'); 981 } 982 983 void 984 ath5k_debug_printrxbuffs(struct ath5k_hw *ah) 985 { 986 struct ath5k_desc *ds; 987 struct ath5k_buf *bf; 988 struct ath5k_rx_status rs = {}; 989 int status; 990 991 if (likely(!(ah->debug.level & ATH5K_DEBUG_DESC))) 992 return; 993 994 printk(KERN_DEBUG "rxdp %x, rxlink %p\n", 995 ath5k_hw_get_rxdp(ah), ah->rxlink); 996 997 spin_lock_bh(&ah->rxbuflock); 998 list_for_each_entry(bf, &ah->rxbuf, list) { 999 ds = bf->desc; 1000 status = ah->ah_proc_rx_desc(ah, ds, &rs); 1001 if (!status) 1002 ath5k_debug_printrxbuf(bf, status == 0, &rs); 1003 } 1004 spin_unlock_bh(&ah->rxbuflock); 1005 } 1006 1007 void 1008 ath5k_debug_printtxbuf(struct ath5k_hw *ah, struct ath5k_buf *bf) 1009 { 1010 struct ath5k_desc *ds = bf->desc; 1011 struct ath5k_hw_5212_tx_desc *td = &ds->ud.ds_tx5212; 1012 struct ath5k_tx_status ts = {}; 1013 int done; 1014 1015 if (likely(!(ah->debug.level & ATH5K_DEBUG_DESC))) 1016 return; 1017 1018 done = ah->ah_proc_tx_desc(ah, bf->desc, &ts); 1019 1020 printk(KERN_DEBUG "T (%p %llx) %08x %08x %08x %08x %08x %08x %08x " 1021 "%08x %c\n", ds, (unsigned long long)bf->daddr, ds->ds_link, 1022 ds->ds_data, td->tx_ctl.tx_control_0, td->tx_ctl.tx_control_1, 1023 td->tx_ctl.tx_control_2, td->tx_ctl.tx_control_3, 1024 td->tx_stat.tx_status_0, td->tx_stat.tx_status_1, 1025 done ? ' ' : (ts.ts_status == 0) ? '*' : '!'); 1026 } 1027