Linux Audio

Check our new training course

Linux debugging, profiling, tracing and performance analysis training

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