debug.c 29.6 KB
Newer Older
1
/*
B
Bruno Randolf 已提交
2
 * Copyright (c) 2007-2008 Bruno Randolf <bruno@thinktube.com>
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
 *
 *  This file is free software: you may copy, redistribute and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation, either version 2 of the License, or (at your
 *  option) any later version.
 *
 *  This file is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *
 * This file incorporates work covered by the following copyright and
 * permission notice:
 *
 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
 * Copyright (c) 2004-2005 Atheros Communications, Inc.
 * Copyright (c) 2006 Devicescape Software, Inc.
 * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
 * Copyright (c) 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer,
 *    without modification.
 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
 *    redistribution must be conditioned upon including a substantially
 *    similar Disclaimer requirement for further binary redistribution.
 * 3. Neither the names of the above-listed copyright holders nor the names
 *    of any contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 *
 * NO WARRANTY
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGES.
 */

#include "base.h"
N
Nick Kossifidis 已提交
62
#include "debug.h"
63 64 65 66 67

static unsigned int ath5k_debug;
module_param_named(debug, ath5k_debug, uint, 0);


68
#ifdef CONFIG_ATH5K_DEBUG
69 70 71

#include <linux/seq_file.h>
#include "reg.h"
72
#include "ani.h"
73 74 75 76 77 78 79 80 81 82 83 84 85

static struct dentry *ath5k_global_debugfs;

static int ath5k_debugfs_open(struct inode *inode, struct file *file)
{
	file->private_data = inode->i_private;
	return 0;
}


/* debugfs: registers */

struct reg {
J
Jiri Slaby 已提交
86
	const char *name;
87 88 89 90 91 92
	int addr;
};

#define REG_STRUCT_INIT(r) { #r, r }

/* just a few random registers, might want to add more */
J
Jiri Slaby 已提交
93
static const struct reg regs[] = {
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
	REG_STRUCT_INIT(AR5K_CR),
	REG_STRUCT_INIT(AR5K_RXDP),
	REG_STRUCT_INIT(AR5K_CFG),
	REG_STRUCT_INIT(AR5K_IER),
	REG_STRUCT_INIT(AR5K_BCR),
	REG_STRUCT_INIT(AR5K_RTSD0),
	REG_STRUCT_INIT(AR5K_RTSD1),
	REG_STRUCT_INIT(AR5K_TXCFG),
	REG_STRUCT_INIT(AR5K_RXCFG),
	REG_STRUCT_INIT(AR5K_RXJLA),
	REG_STRUCT_INIT(AR5K_MIBC),
	REG_STRUCT_INIT(AR5K_TOPS),
	REG_STRUCT_INIT(AR5K_RXNOFRM),
	REG_STRUCT_INIT(AR5K_TXNOFRM),
	REG_STRUCT_INIT(AR5K_RPGTO),
	REG_STRUCT_INIT(AR5K_RFCNT),
	REG_STRUCT_INIT(AR5K_MISC),
	REG_STRUCT_INIT(AR5K_QCUDCU_CLKGT),
	REG_STRUCT_INIT(AR5K_ISR),
	REG_STRUCT_INIT(AR5K_PISR),
	REG_STRUCT_INIT(AR5K_SISR0),
	REG_STRUCT_INIT(AR5K_SISR1),
	REG_STRUCT_INIT(AR5K_SISR2),
	REG_STRUCT_INIT(AR5K_SISR3),
	REG_STRUCT_INIT(AR5K_SISR4),
	REG_STRUCT_INIT(AR5K_IMR),
	REG_STRUCT_INIT(AR5K_PIMR),
	REG_STRUCT_INIT(AR5K_SIMR0),
	REG_STRUCT_INIT(AR5K_SIMR1),
	REG_STRUCT_INIT(AR5K_SIMR2),
	REG_STRUCT_INIT(AR5K_SIMR3),
	REG_STRUCT_INIT(AR5K_SIMR4),
	REG_STRUCT_INIT(AR5K_DCM_ADDR),
	REG_STRUCT_INIT(AR5K_DCCFG),
	REG_STRUCT_INIT(AR5K_CCFG),
	REG_STRUCT_INIT(AR5K_CPC0),
	REG_STRUCT_INIT(AR5K_CPC1),
	REG_STRUCT_INIT(AR5K_CPC2),
	REG_STRUCT_INIT(AR5K_CPC3),
N
Nick Kossifidis 已提交
133
	REG_STRUCT_INIT(AR5K_CPCOVF),
134 135 136 137 138 139 140 141 142 143 144 145
	REG_STRUCT_INIT(AR5K_RESET_CTL),
	REG_STRUCT_INIT(AR5K_SLEEP_CTL),
	REG_STRUCT_INIT(AR5K_INTPEND),
	REG_STRUCT_INIT(AR5K_SFR),
	REG_STRUCT_INIT(AR5K_PCICFG),
	REG_STRUCT_INIT(AR5K_GPIOCR),
	REG_STRUCT_INIT(AR5K_GPIODO),
	REG_STRUCT_INIT(AR5K_SREV),
};

static void *reg_start(struct seq_file *seq, loff_t *pos)
{
J
Jiri Slaby 已提交
146
	return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
147 148 149 150 151 152 153 154 155 156
}

static void reg_stop(struct seq_file *seq, void *p)
{
	/* nothing to do */
}

static void *reg_next(struct seq_file *seq, void *p, loff_t *pos)
{
	++*pos;
J
Jiri Slaby 已提交
157
	return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
158 159 160 161 162 163 164 165 166 167 168
}

static int reg_show(struct seq_file *seq, void *p)
{
	struct ath5k_softc *sc = seq->private;
	struct reg *r = p;
	seq_printf(seq, "%-25s0x%08x\n", r->name,
		ath5k_hw_reg_read(sc->ah, r->addr));
	return 0;
}

J
Jan Engelhardt 已提交
169
static const struct seq_operations register_seq_ops = {
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
	.start = reg_start,
	.next  = reg_next,
	.stop  = reg_stop,
	.show  = reg_show
};

static int open_file_registers(struct inode *inode, struct file *file)
{
	struct seq_file *s;
	int res;
	res = seq_open(file, &register_seq_ops);
	if (res == 0) {
		s = file->private_data;
		s->private = inode->i_private;
	}
	return res;
}

static const struct file_operations fops_registers = {
	.open = open_file_registers,
	.read    = seq_read,
	.llseek  = seq_lseek,
	.release = seq_release,
	.owner = THIS_MODULE,
};


/* debugfs: beacons */

static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
				   size_t count, loff_t *ppos)
{
	struct ath5k_softc *sc = file->private_data;
	struct ath5k_hw *ah = sc->ah;
B
Bruno Randolf 已提交
204 205
	char buf[500];
	unsigned int len = 0;
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
	unsigned int v;
	u64 tsf;

	v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
	len += snprintf(buf+len, sizeof(buf)-len,
		"%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
		"AR5K_BEACON", v, v & AR5K_BEACON_PERIOD,
		(v & AR5K_BEACON_TIM) >> AR5K_BEACON_TIM_S);

	len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n",
		"AR5K_LAST_TSTP", ath5k_hw_reg_read(sc->ah, AR5K_LAST_TSTP));

	len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n\n",
		"AR5K_BEACON_CNT", ath5k_hw_reg_read(sc->ah, AR5K_BEACON_CNT));

	v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER0);
	len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
		"AR5K_TIMER0 (TBTT)", v, v);

	v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER1);
	len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
		"AR5K_TIMER1 (DMA)", v, v >> 3);

	v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER2);
	len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
		"AR5K_TIMER2 (SWBA)", v, v >> 3);

	v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER3);
	len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
		"AR5K_TIMER3 (ATIM)", v, v);

	tsf = ath5k_hw_get_tsf64(sc->ah);
	len += snprintf(buf+len, sizeof(buf)-len,
239 240
		"TSF\t\t0x%016llx\tTU: %08x\n",
		(unsigned long long)tsf, TSF_TO_TU(tsf));
241 242 243 244 245 246 247 248 249 250

	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
}

static ssize_t write_file_beacon(struct file *file,
				 const char __user *userbuf,
				 size_t count, loff_t *ppos)
{
	struct ath5k_softc *sc = file->private_data;
	struct ath5k_hw *ah = sc->ah;
B
Bruno Randolf 已提交
251
	char buf[20];
252

B
Bruno Randolf 已提交
253 254 255 256
	if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
		return -EFAULT;

	if (strncmp(buf, "disable", 7) == 0) {
257 258
		AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
		printk(KERN_INFO "debugfs disable beacons\n");
B
Bruno Randolf 已提交
259
	} else if (strncmp(buf, "enable", 6) == 0) {
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
		AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
		printk(KERN_INFO "debugfs enable beacons\n");
	}
	return count;
}

static const struct file_operations fops_beacon = {
	.read = read_file_beacon,
	.write = write_file_beacon,
	.open = ath5k_debugfs_open,
	.owner = THIS_MODULE,
};


/* debugfs: reset */

static ssize_t write_file_reset(struct file *file,
				 const char __user *userbuf,
				 size_t count, loff_t *ppos)
{
	struct ath5k_softc *sc = file->private_data;
281
	ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "debug file triggered reset\n");
282 283 284 285 286 287 288 289 290 291 292
	tasklet_schedule(&sc->restq);
	return count;
}

static const struct file_operations fops_reset = {
	.write = write_file_reset,
	.open = ath5k_debugfs_open,
	.owner = THIS_MODULE,
};


B
Bruno Randolf 已提交
293 294
/* debugfs: debug level */

J
Jiri Slaby 已提交
295
static const struct {
B
Bruno Randolf 已提交
296 297 298 299 300 301 302 303 304 305 306
	enum ath5k_debug_level level;
	const char *name;
	const char *desc;
} dbg_info[] = {
	{ ATH5K_DEBUG_RESET,	"reset",	"reset and initialization" },
	{ ATH5K_DEBUG_INTR,	"intr",		"interrupt handling" },
	{ ATH5K_DEBUG_MODE,	"mode",		"mode init/setup" },
	{ ATH5K_DEBUG_XMIT,	"xmit",		"basic xmit operation" },
	{ ATH5K_DEBUG_BEACON,	"beacon",	"beacon handling" },
	{ ATH5K_DEBUG_CALIBRATE, "calib",	"periodic calibration" },
	{ ATH5K_DEBUG_TXPOWER,	"txpower",	"transmit power setting" },
307
	{ ATH5K_DEBUG_LED,	"led",		"LED management" },
B
Bruno Randolf 已提交
308 309
	{ ATH5K_DEBUG_DUMP_RX,	"dumprx",	"print received skb content" },
	{ ATH5K_DEBUG_DUMP_TX,	"dumptx",	"print transmit skb content" },
310
	{ ATH5K_DEBUG_DUMPBANDS, "dumpbands",	"dump bands" },
311
	{ ATH5K_DEBUG_ANI,	"ani",		"adaptive noise immunity" },
B
Bruno Randolf 已提交
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
	{ ATH5K_DEBUG_ANY,	"all",		"show all debug levels" },
};

static ssize_t read_file_debug(struct file *file, char __user *user_buf,
				   size_t count, loff_t *ppos)
{
	struct ath5k_softc *sc = file->private_data;
	char buf[700];
	unsigned int len = 0;
	unsigned int i;

	len += snprintf(buf+len, sizeof(buf)-len,
		"DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);

	for (i = 0; i < ARRAY_SIZE(dbg_info) - 1; i++) {
		len += snprintf(buf+len, sizeof(buf)-len,
			"%10s %c 0x%08x - %s\n", dbg_info[i].name,
			sc->debug.level & dbg_info[i].level ? '+' : ' ',
			dbg_info[i].level, dbg_info[i].desc);
	}
	len += snprintf(buf+len, sizeof(buf)-len,
		"%10s %c 0x%08x - %s\n", dbg_info[i].name,
		sc->debug.level == dbg_info[i].level ? '+' : ' ',
		dbg_info[i].level, dbg_info[i].desc);

	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
}

static ssize_t write_file_debug(struct file *file,
				 const char __user *userbuf,
				 size_t count, loff_t *ppos)
{
	struct ath5k_softc *sc = file->private_data;
	unsigned int i;
	char buf[20];

	if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
		return -EFAULT;

	for (i = 0; i < ARRAY_SIZE(dbg_info); i++) {
		if (strncmp(buf, dbg_info[i].name,
					strlen(dbg_info[i].name)) == 0) {
			sc->debug.level ^= dbg_info[i].level; /* toggle bit */
			break;
		}
	}
	return count;
}

static const struct file_operations fops_debug = {
	.read = read_file_debug,
	.write = write_file_debug,
	.open = ath5k_debugfs_open,
	.owner = THIS_MODULE,
};


369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
/* debugfs: antenna */

static ssize_t read_file_antenna(struct file *file, char __user *user_buf,
				   size_t count, loff_t *ppos)
{
	struct ath5k_softc *sc = file->private_data;
	char buf[700];
	unsigned int len = 0;
	unsigned int i;
	unsigned int v;

	len += snprintf(buf+len, sizeof(buf)-len, "antenna mode\t%d\n",
		sc->ah->ah_ant_mode);
	len += snprintf(buf+len, sizeof(buf)-len, "default antenna\t%d\n",
		sc->ah->ah_def_ant);
	len += snprintf(buf+len, sizeof(buf)-len, "tx antenna\t%d\n",
		sc->ah->ah_tx_ant);

	len += snprintf(buf+len, sizeof(buf)-len, "\nANTENNA\t\tRX\tTX\n");
	for (i = 1; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) {
		len += snprintf(buf+len, sizeof(buf)-len,
			"[antenna %d]\t%d\t%d\n",
			i, sc->stats.antenna_rx[i], sc->stats.antenna_tx[i]);
	}
	len += snprintf(buf+len, sizeof(buf)-len, "[invalid]\t%d\t%d\n",
			sc->stats.antenna_rx[0], sc->stats.antenna_tx[0]);

	v = ath5k_hw_reg_read(sc->ah, AR5K_DEFAULT_ANTENNA);
	len += snprintf(buf+len, sizeof(buf)-len,
			"\nAR5K_DEFAULT_ANTENNA\t0x%08x\n", v);

	v = ath5k_hw_reg_read(sc->ah, AR5K_STA_ID1);
	len += snprintf(buf+len, sizeof(buf)-len,
		"AR5K_STA_ID1_DEFAULT_ANTENNA\t%d\n",
		(v & AR5K_STA_ID1_DEFAULT_ANTENNA) != 0);
	len += snprintf(buf+len, sizeof(buf)-len,
		"AR5K_STA_ID1_DESC_ANTENNA\t%d\n",
		(v & AR5K_STA_ID1_DESC_ANTENNA) != 0);
	len += snprintf(buf+len, sizeof(buf)-len,
		"AR5K_STA_ID1_RTS_DEF_ANTENNA\t%d\n",
		(v & AR5K_STA_ID1_RTS_DEF_ANTENNA) != 0);
	len += snprintf(buf+len, sizeof(buf)-len,
		"AR5K_STA_ID1_SELFGEN_DEF_ANT\t%d\n",
		(v & AR5K_STA_ID1_SELFGEN_DEF_ANT) != 0);

	v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_AGCCTL);
	len += snprintf(buf+len, sizeof(buf)-len,
		"\nAR5K_PHY_AGCCTL_OFDM_DIV_DIS\t%d\n",
		(v & AR5K_PHY_AGCCTL_OFDM_DIV_DIS) != 0);

	v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_RESTART);
	len += snprintf(buf+len, sizeof(buf)-len,
		"AR5K_PHY_RESTART_DIV_GC\t\t%x\n",
		(v & AR5K_PHY_RESTART_DIV_GC) >> AR5K_PHY_RESTART_DIV_GC_S);

	v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_FAST_ANT_DIV);
	len += snprintf(buf+len, sizeof(buf)-len,
		"AR5K_PHY_FAST_ANT_DIV_EN\t%d\n",
		(v & AR5K_PHY_FAST_ANT_DIV_EN) != 0);

429 430 431 432 433 434 435
	v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_ANT_SWITCH_TABLE_0);
	len += snprintf(buf+len, sizeof(buf)-len,
			"\nAR5K_PHY_ANT_SWITCH_TABLE_0\t0x%08x\n", v);
	v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_ANT_SWITCH_TABLE_1);
	len += snprintf(buf+len, sizeof(buf)-len,
			"AR5K_PHY_ANT_SWITCH_TABLE_1\t0x%08x\n", v);

436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
}

static ssize_t write_file_antenna(struct file *file,
				 const char __user *userbuf,
				 size_t count, loff_t *ppos)
{
	struct ath5k_softc *sc = file->private_data;
	unsigned int i;
	char buf[20];

	if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
		return -EFAULT;

	if (strncmp(buf, "diversity", 9) == 0) {
		ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_DEFAULT);
		printk(KERN_INFO "ath5k debug: enable diversity\n");
	} else if (strncmp(buf, "fixed-a", 7) == 0) {
		ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_A);
		printk(KERN_INFO "ath5k debugfs: fixed antenna A\n");
	} else if (strncmp(buf, "fixed-b", 7) == 0) {
		ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_B);
		printk(KERN_INFO "ath5k debug: fixed antenna B\n");
	} else if (strncmp(buf, "clear", 5) == 0) {
		for (i = 0; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) {
			sc->stats.antenna_rx[i] = 0;
			sc->stats.antenna_tx[i] = 0;
		}
		printk(KERN_INFO "ath5k debug: cleared antenna stats\n");
	}
	return count;
}

static const struct file_operations fops_antenna = {
	.read = read_file_antenna,
	.write = write_file_antenna,
	.open = ath5k_debugfs_open,
	.owner = THIS_MODULE,
};


477 478 479 480 481 482 483 484 485
/* debugfs: frameerrors */

static ssize_t read_file_frameerrors(struct file *file, char __user *user_buf,
				   size_t count, loff_t *ppos)
{
	struct ath5k_softc *sc = file->private_data;
	struct ath5k_statistics *st = &sc->stats;
	char buf[700];
	unsigned int len = 0;
B
Bruno Randolf 已提交
486
	int i;
487 488 489 490 491 492 493 494 495 496 497

	len += snprintf(buf+len, sizeof(buf)-len,
			"RX\n---------------------\n");
	len += snprintf(buf+len, sizeof(buf)-len, "CRC\t%d\t(%d%%)\n",
			st->rxerr_crc,
			st->rx_all_count > 0 ?
				st->rxerr_crc*100/st->rx_all_count : 0);
	len += snprintf(buf+len, sizeof(buf)-len, "PHY\t%d\t(%d%%)\n",
			st->rxerr_phy,
			st->rx_all_count > 0 ?
				st->rxerr_phy*100/st->rx_all_count : 0);
B
Bruno Randolf 已提交
498 499 500 501 502 503 504
	for (i = 0; i < 32; i++) {
		if (st->rxerr_phy_code[i])
			len += snprintf(buf+len, sizeof(buf)-len,
				" phy_err[%d]\t%d\n",
				i, st->rxerr_phy_code[i]);
	}

505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
	len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%d\t(%d%%)\n",
			st->rxerr_fifo,
			st->rx_all_count > 0 ?
				st->rxerr_fifo*100/st->rx_all_count : 0);
	len += snprintf(buf+len, sizeof(buf)-len, "decrypt\t%d\t(%d%%)\n",
			st->rxerr_decrypt,
			st->rx_all_count > 0 ?
				st->rxerr_decrypt*100/st->rx_all_count : 0);
	len += snprintf(buf+len, sizeof(buf)-len, "MIC\t%d\t(%d%%)\n",
			st->rxerr_mic,
			st->rx_all_count > 0 ?
				st->rxerr_mic*100/st->rx_all_count : 0);
	len += snprintf(buf+len, sizeof(buf)-len, "process\t%d\t(%d%%)\n",
			st->rxerr_proc,
			st->rx_all_count > 0 ?
				st->rxerr_proc*100/st->rx_all_count : 0);
	len += snprintf(buf+len, sizeof(buf)-len, "jumbo\t%d\t(%d%%)\n",
			st->rxerr_jumbo,
			st->rx_all_count > 0 ?
				st->rxerr_jumbo*100/st->rx_all_count : 0);
	len += snprintf(buf+len, sizeof(buf)-len, "[RX all\t%d]\n",
			st->rx_all_count);

	len += snprintf(buf+len, sizeof(buf)-len,
			"\nTX\n---------------------\n");
	len += snprintf(buf+len, sizeof(buf)-len, "retry\t%d\t(%d%%)\n",
			st->txerr_retry,
			st->tx_all_count > 0 ?
				st->txerr_retry*100/st->tx_all_count : 0);
	len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%d\t(%d%%)\n",
			st->txerr_fifo,
			st->tx_all_count > 0 ?
				st->txerr_fifo*100/st->tx_all_count : 0);
	len += snprintf(buf+len, sizeof(buf)-len, "filter\t%d\t(%d%%)\n",
			st->txerr_filt,
			st->tx_all_count > 0 ?
				st->txerr_filt*100/st->tx_all_count : 0);
	len += snprintf(buf+len, sizeof(buf)-len, "[TX all\t%d]\n",
			st->tx_all_count);

	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
}

static ssize_t write_file_frameerrors(struct file *file,
				 const char __user *userbuf,
				 size_t count, loff_t *ppos)
{
	struct ath5k_softc *sc = file->private_data;
	struct ath5k_statistics *st = &sc->stats;
	char buf[20];

	if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
		return -EFAULT;

	if (strncmp(buf, "clear", 5) == 0) {
		st->rxerr_crc = 0;
		st->rxerr_phy = 0;
		st->rxerr_fifo = 0;
		st->rxerr_decrypt = 0;
		st->rxerr_mic = 0;
		st->rxerr_proc = 0;
		st->rxerr_jumbo = 0;
		st->rx_all_count = 0;
		st->txerr_retry = 0;
		st->txerr_fifo = 0;
		st->txerr_filt = 0;
		st->tx_all_count = 0;
		printk(KERN_INFO "ath5k debug: cleared frameerrors stats\n");
	}
	return count;
}

static const struct file_operations fops_frameerrors = {
	.read = read_file_frameerrors,
	.write = write_file_frameerrors,
	.open = ath5k_debugfs_open,
	.owner = THIS_MODULE,
};


585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
/* debugfs: ani */

static ssize_t read_file_ani(struct file *file, char __user *user_buf,
				   size_t count, loff_t *ppos)
{
	struct ath5k_softc *sc = file->private_data;
	struct ath5k_statistics *st = &sc->stats;
	struct ath5k_ani_state *as = &sc->ani_state;

	char buf[700];
	unsigned int len = 0;

	len += snprintf(buf+len, sizeof(buf)-len,
			"HW has PHY error counters:\t%s\n",
			sc->ah->ah_capabilities.cap_has_phyerr_counters ?
			"yes" : "no");
	len += snprintf(buf+len, sizeof(buf)-len,
			"HW max spur immunity level:\t%d\n",
			as->max_spur_level);
	len += snprintf(buf+len, sizeof(buf)-len,
		"\nANI state\n--------------------------------------------\n");
	len += snprintf(buf+len, sizeof(buf)-len, "operating mode:\t\t\t");
	switch (as->ani_mode) {
	case ATH5K_ANI_MODE_OFF:
		len += snprintf(buf+len, sizeof(buf)-len, "OFF\n");
		break;
	case ATH5K_ANI_MODE_MANUAL_LOW:
		len += snprintf(buf+len, sizeof(buf)-len,
			"MANUAL LOW\n");
		break;
	case ATH5K_ANI_MODE_MANUAL_HIGH:
		len += snprintf(buf+len, sizeof(buf)-len,
			"MANUAL HIGH\n");
		break;
	case ATH5K_ANI_MODE_AUTO:
		len += snprintf(buf+len, sizeof(buf)-len, "AUTO\n");
		break;
	default:
		len += snprintf(buf+len, sizeof(buf)-len,
			"??? (not good)\n");
		break;
	}
	len += snprintf(buf+len, sizeof(buf)-len,
			"noise immunity level:\t\t%d\n",
			as->noise_imm_level);
	len += snprintf(buf+len, sizeof(buf)-len,
			"spur immunity level:\t\t%d\n",
			as->spur_level);
	len += snprintf(buf+len, sizeof(buf)-len, "firstep level:\t\t\t%d\n",
			as->firstep_level);
	len += snprintf(buf+len, sizeof(buf)-len,
			"OFDM weak signal detection:\t%s\n",
			as->ofdm_weak_sig ? "on" : "off");
	len += snprintf(buf+len, sizeof(buf)-len,
			"CCK weak signal detection:\t%s\n",
			as->cck_weak_sig ? "on" : "off");

	len += snprintf(buf+len, sizeof(buf)-len,
			"\nMIB INTERRUPTS:\t\t%u\n",
			st->mib_intr);
	len += snprintf(buf+len, sizeof(buf)-len,
			"beacon RSSI average:\t%d\n",
			sc->ah->ah_beacon_rssi_avg.avg);
	len += snprintf(buf+len, sizeof(buf)-len, "profcnt tx\t\t%u\t(%d%%)\n",
			as->pfc_tx,
			as->pfc_cycles > 0 ?
			as->pfc_tx*100/as->pfc_cycles : 0);
	len += snprintf(buf+len, sizeof(buf)-len, "profcnt rx\t\t%u\t(%d%%)\n",
			as->pfc_rx,
			as->pfc_cycles > 0 ?
			as->pfc_rx*100/as->pfc_cycles : 0);
	len += snprintf(buf+len, sizeof(buf)-len, "profcnt busy\t\t%u\t(%d%%)\n",
			as->pfc_busy,
			as->pfc_cycles > 0 ?
			as->pfc_busy*100/as->pfc_cycles : 0);
	len += snprintf(buf+len, sizeof(buf)-len, "profcnt cycles\t\t%u\n",
			as->pfc_cycles);
	len += snprintf(buf+len, sizeof(buf)-len,
			"listen time\t\t%d\tlast: %d\n",
			as->listen_time, as->last_listen);
	len += snprintf(buf+len, sizeof(buf)-len,
			"OFDM errors\t\t%u\tlast: %u\tsum: %u\n",
			as->ofdm_errors, as->last_ofdm_errors,
			as->sum_ofdm_errors);
	len += snprintf(buf+len, sizeof(buf)-len,
			"CCK errors\t\t%u\tlast: %u\tsum: %u\n",
			as->cck_errors, as->last_cck_errors,
			as->sum_cck_errors);
	len += snprintf(buf+len, sizeof(buf)-len,
			"AR5K_PHYERR_CNT1\t%x\t(=%d)\n",
			ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1),
			ATH5K_ANI_OFDM_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
			ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1)));
	len += snprintf(buf+len, sizeof(buf)-len,
			"AR5K_PHYERR_CNT2\t%x\t(=%d)\n",
			ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2),
			ATH5K_ANI_CCK_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
			ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2)));

	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
}

static ssize_t write_file_ani(struct file *file,
				 const char __user *userbuf,
				 size_t count, loff_t *ppos)
{
	struct ath5k_softc *sc = file->private_data;
	char buf[20];

	if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
		return -EFAULT;

	if (strncmp(buf, "sens-low", 8) == 0) {
		ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_HIGH);
	} else if (strncmp(buf, "sens-high", 9) == 0) {
		ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_LOW);
	} else if (strncmp(buf, "ani-off", 7) == 0) {
		ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_OFF);
	} else if (strncmp(buf, "ani-on", 6) == 0) {
		ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_AUTO);
	} else if (strncmp(buf, "noise-low", 9) == 0) {
		ath5k_ani_set_noise_immunity_level(sc->ah, 0);
	} else if (strncmp(buf, "noise-high", 10) == 0) {
		ath5k_ani_set_noise_immunity_level(sc->ah,
						   ATH5K_ANI_MAX_NOISE_IMM_LVL);
	} else if (strncmp(buf, "spur-low", 8) == 0) {
		ath5k_ani_set_spur_immunity_level(sc->ah, 0);
	} else if (strncmp(buf, "spur-high", 9) == 0) {
		ath5k_ani_set_spur_immunity_level(sc->ah,
						  sc->ani_state.max_spur_level);
	} else if (strncmp(buf, "fir-low", 7) == 0) {
		ath5k_ani_set_firstep_level(sc->ah, 0);
	} else if (strncmp(buf, "fir-high", 8) == 0) {
		ath5k_ani_set_firstep_level(sc->ah, ATH5K_ANI_MAX_FIRSTEP_LVL);
	} else if (strncmp(buf, "ofdm-off", 8) == 0) {
		ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, false);
	} else if (strncmp(buf, "ofdm-on", 7) == 0) {
		ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, true);
	} else if (strncmp(buf, "cck-off", 7) == 0) {
		ath5k_ani_set_cck_weak_signal_detection(sc->ah, false);
	} else if (strncmp(buf, "cck-on", 6) == 0) {
		ath5k_ani_set_cck_weak_signal_detection(sc->ah, true);
	}
	return count;
}

static const struct file_operations fops_ani = {
	.read = read_file_ani,
	.write = write_file_ani,
	.open = ath5k_debugfs_open,
	.owner = THIS_MODULE,
};


739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798
/* debugfs: queues etc */

static ssize_t read_file_queue(struct file *file, char __user *user_buf,
				   size_t count, loff_t *ppos)
{
	struct ath5k_softc *sc = file->private_data;
	char buf[700];
	unsigned int len = 0;

	struct ath5k_txq *txq;
	struct ath5k_buf *bf, *bf0;
	int i, n = 0;

	len += snprintf(buf+len, sizeof(buf)-len,
			"available txbuffers: %d\n", sc->txbuf_len);

	for (i = 0; i < ARRAY_SIZE(sc->txqs); i++) {
		txq = &sc->txqs[i];

		len += snprintf(buf+len, sizeof(buf)-len,
			"%02d: %ssetup\n", i, txq->setup ? "" : "not ");

		if (!txq->setup)
			continue;

		list_for_each_entry_safe(bf, bf0, &txq->q, list)
			n++;
		len += snprintf(buf+len, sizeof(buf)-len, "  len: %d\n", n);
	}

	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
}

static ssize_t write_file_queue(struct file *file,
				 const char __user *userbuf,
				 size_t count, loff_t *ppos)
{
	struct ath5k_softc *sc = file->private_data;
	char buf[20];

	if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
		return -EFAULT;

	if (strncmp(buf, "start", 5) == 0)
		ieee80211_wake_queues(sc->hw);
	else if (strncmp(buf, "stop", 4) == 0)
		ieee80211_stop_queues(sc->hw);

	return count;
}


static const struct file_operations fops_queue = {
	.read = read_file_queue,
	.write = write_file_queue,
	.open = ath5k_debugfs_open,
	.owner = THIS_MODULE,
};


799 800 801 802 803 804 805 806 807 808 809 810
/* init */

void
ath5k_debug_init(void)
{
	ath5k_global_debugfs = debugfs_create_dir("ath5k", NULL);
}

void
ath5k_debug_init_device(struct ath5k_softc *sc)
{
	sc->debug.level = ath5k_debug;
B
Bruno Randolf 已提交
811

812
	sc->debug.debugfs_phydir = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
B
Bruno Randolf 已提交
813 814
				ath5k_global_debugfs);

815 816
	sc->debug.debugfs_debug = debugfs_create_file("debug",
				S_IWUSR | S_IRUSR,
B
Bruno Randolf 已提交
817
				sc->debug.debugfs_phydir, sc, &fops_debug);
818

819
	sc->debug.debugfs_registers = debugfs_create_file("registers", S_IRUSR,
B
Bruno Randolf 已提交
820
				sc->debug.debugfs_phydir, sc, &fops_registers);
821

822 823
	sc->debug.debugfs_beacon = debugfs_create_file("beacon",
				S_IWUSR | S_IRUSR,
B
Bruno Randolf 已提交
824
				sc->debug.debugfs_phydir, sc, &fops_beacon);
825

826
	sc->debug.debugfs_reset = debugfs_create_file("reset", S_IWUSR,
B
Bruno Randolf 已提交
827
				sc->debug.debugfs_phydir, sc, &fops_reset);
828 829 830 831

	sc->debug.debugfs_antenna = debugfs_create_file("antenna",
				S_IWUSR | S_IRUSR,
				sc->debug.debugfs_phydir, sc, &fops_antenna);
832 833 834 835 836

	sc->debug.debugfs_frameerrors = debugfs_create_file("frameerrors",
				S_IWUSR | S_IRUSR,
				sc->debug.debugfs_phydir, sc,
				&fops_frameerrors);
837 838 839 840 841

	sc->debug.debugfs_ani = debugfs_create_file("ani",
				S_IWUSR | S_IRUSR,
				sc->debug.debugfs_phydir, sc,
				&fops_ani);
842 843 844 845 846

	sc->debug.debugfs_queue = debugfs_create_file("queue",
				S_IWUSR | S_IRUSR,
				sc->debug.debugfs_phydir, sc,
				&fops_queue);
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861
}

void
ath5k_debug_finish(void)
{
	debugfs_remove(ath5k_global_debugfs);
}

void
ath5k_debug_finish_device(struct ath5k_softc *sc)
{
	debugfs_remove(sc->debug.debugfs_debug);
	debugfs_remove(sc->debug.debugfs_registers);
	debugfs_remove(sc->debug.debugfs_beacon);
	debugfs_remove(sc->debug.debugfs_reset);
862
	debugfs_remove(sc->debug.debugfs_antenna);
863
	debugfs_remove(sc->debug.debugfs_frameerrors);
864
	debugfs_remove(sc->debug.debugfs_ani);
865
	debugfs_remove(sc->debug.debugfs_queue);
866 867 868 869 870 871 872
	debugfs_remove(sc->debug.debugfs_phydir);
}


/* functions used in other places */

void
873
ath5k_debug_dump_bands(struct ath5k_softc *sc)
874
{
875
	unsigned int b, i;
876

877
	if (likely(!(sc->debug.level & ATH5K_DEBUG_DUMPBANDS)))
878 879
		return;

880 881 882 883
	BUG_ON(!sc->sbands);

	for (b = 0; b < IEEE80211_NUM_BANDS; b++) {
		struct ieee80211_supported_band *band = &sc->sbands[b];
884
		char bname[6];
885 886 887 888 889 890 891 892 893 894 895 896 897 898
		switch (band->band) {
		case IEEE80211_BAND_2GHZ:
			strcpy(bname, "2 GHz");
			break;
		case IEEE80211_BAND_5GHZ:
			strcpy(bname, "5 GHz");
			break;
		default:
			printk(KERN_DEBUG "Band not supported: %d\n",
				band->band);
			return;
		}
		printk(KERN_DEBUG "Band %s: channels %d, rates %d\n", bname,
				band->n_channels, band->n_bitrates);
899
		printk(KERN_DEBUG " channels:\n");
900
		for (i = 0; i < band->n_channels; i++)
901
			printk(KERN_DEBUG "  %3d %d %.4x %.4x\n",
902 903 904 905 906
					ieee80211_frequency_to_channel(
						band->channels[i].center_freq),
					band->channels[i].center_freq,
					band->channels[i].hw_value,
					band->channels[i].flags);
907
		printk(KERN_DEBUG " rates:\n");
908
		for (i = 0; i < band->n_bitrates; i++)
909
			printk(KERN_DEBUG "  %4d %.4x %.4x %.4x\n",
910 911 912 913
					band->bitrates[i].bitrate,
					band->bitrates[i].hw_value,
					band->bitrates[i].flags,
					band->bitrates[i].hw_value_short);
914 915 916 917
	}
}

static inline void
918 919
ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done,
		       struct ath5k_rx_status *rs)
920 921
{
	struct ath5k_desc *ds = bf->desc;
922
	struct ath5k_hw_all_rx_desc *rd = &ds->ud.ds_rx;
923 924 925

	printk(KERN_DEBUG "R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n",
		ds, (unsigned long long)bf->daddr,
926 927
		ds->ds_link, ds->ds_data,
		rd->rx_ctl.rx_control_0, rd->rx_ctl.rx_control_1,
928
		rd->rx_stat.rx_status_0, rd->rx_stat.rx_status_1,
929
		!done ? ' ' : (rs->rs_status == 0) ? '*' : '!');
930 931 932 933 934 935 936
}

void
ath5k_debug_printrxbuffs(struct ath5k_softc *sc, struct ath5k_hw *ah)
{
	struct ath5k_desc *ds;
	struct ath5k_buf *bf;
937
	struct ath5k_rx_status rs = {};
938 939
	int status;

B
Bruno Randolf 已提交
940
	if (likely(!(sc->debug.level & ATH5K_DEBUG_RESET)))
941 942
		return;

943
	printk(KERN_DEBUG "rxdp %x, rxlink %p\n",
N
Nick Kossifidis 已提交
944
		ath5k_hw_get_rxdp(ah), sc->rxlink);
945 946 947 948

	spin_lock_bh(&sc->rxbuflock);
	list_for_each_entry(bf, &sc->rxbuf, list) {
		ds = bf->desc;
949
		status = ah->ah_proc_rx_desc(ah, ds, &rs);
B
Bruno Randolf 已提交
950
		if (!status)
951
			ath5k_debug_printrxbuf(bf, status == 0, &rs);
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974
	}
	spin_unlock_bh(&sc->rxbuflock);
}

void
ath5k_debug_dump_skb(struct ath5k_softc *sc,
			struct sk_buff *skb, const char *prefix, int tx)
{
	char buf[16];

	if (likely(!((tx && (sc->debug.level & ATH5K_DEBUG_DUMP_TX)) ||
		     (!tx && (sc->debug.level & ATH5K_DEBUG_DUMP_RX)))))
		return;

	snprintf(buf, sizeof(buf), "%s %s", wiphy_name(sc->hw->wiphy), prefix);

	print_hex_dump_bytes(buf, DUMP_PREFIX_NONE, skb->data,
		min(200U, skb->len));

	printk(KERN_DEBUG "\n");
}

void
975
ath5k_debug_printtxbuf(struct ath5k_softc *sc, struct ath5k_buf *bf)
976 977
{
	struct ath5k_desc *ds = bf->desc;
978
	struct ath5k_hw_5212_tx_desc *td = &ds->ud.ds_tx5212;
979 980
	struct ath5k_tx_status ts = {};
	int done;
981 982 983 984

	if (likely(!(sc->debug.level & ATH5K_DEBUG_RESET)))
		return;

985 986
	done = sc->ah->ah_proc_tx_desc(sc->ah, bf->desc, &ts);

987 988
	printk(KERN_DEBUG "T (%p %llx) %08x %08x %08x %08x %08x %08x %08x "
		"%08x %c\n", ds, (unsigned long long)bf->daddr, ds->ds_link,
989 990 991
		ds->ds_data, td->tx_ctl.tx_control_0, td->tx_ctl.tx_control_1,
		td->tx_ctl.tx_control_2, td->tx_ctl.tx_control_3,
		td->tx_stat.tx_status_0, td->tx_stat.tx_status_1,
992
		done ? ' ' : (ts.ts_status == 0) ? '*' : '!');
993 994
}

995
#endif /* ifdef CONFIG_ATH5K_DEBUG */