iwl-debugfs.c 20.6 KB
Newer Older
T
Tomas Winkler 已提交
1 2 3 4
/******************************************************************************
 *
 * GPL LICENSE SUMMARY
 *
5
 * Copyright(c) 2008 - 2009 Intel Corporation. All rights reserved.
T
Tomas Winkler 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
 * USA
 *
 * The full GNU General Public License is included in this distribution
 * in the file called LICENSE.GPL.
 *
 * Contact Information:
25
 *  Intel Linux Wireless <ilw@linux.intel.com>
T
Tomas Winkler 已提交
26 27 28 29 30 31 32 33 34 35 36
 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
 *****************************************************************************/

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/debugfs.h>

#include <linux/ieee80211.h>
#include <net/mac80211.h>


37
#include "iwl-dev.h"
T
Tomas Winkler 已提交
38
#include "iwl-debug.h"
39
#include "iwl-core.h"
40
#include "iwl-io.h"
T
Tomas Winkler 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57


/* create and remove of files */
#define DEBUGFS_ADD_DIR(name, parent) do {                              \
	dbgfs->dir_##name = debugfs_create_dir(#name, parent);          \
	if (!(dbgfs->dir_##name))                                       \
		goto err; 						\
} while (0)

#define DEBUGFS_ADD_FILE(name, parent) do {                             \
	dbgfs->dbgfs_##parent##_files.file_##name =                     \
	debugfs_create_file(#name, 0644, dbgfs->dir_##parent, priv,     \
				&iwl_dbgfs_##name##_ops);               \
	if (!(dbgfs->dbgfs_##parent##_files.file_##name))               \
		goto err;                                               \
} while (0)

58 59 60
#define DEBUGFS_ADD_BOOL(name, parent, ptr) do {                        \
	dbgfs->dbgfs_##parent##_files.file_##name =                     \
	debugfs_create_bool(#name, 0644, dbgfs->dir_##parent, ptr);     \
61 62
	if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name)		\
			|| !dbgfs->dbgfs_##parent##_files.file_##name)	\
63 64 65
		goto err;                                               \
} while (0)

66 67 68 69 70 71 72 73
#define DEBUGFS_ADD_X32(name, parent, ptr) do {                        \
	dbgfs->dbgfs_##parent##_files.file_##name =                     \
	debugfs_create_x32(#name, 0444, dbgfs->dir_##parent, ptr);     \
	if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name)		\
			|| !dbgfs->dbgfs_##parent##_files.file_##name)	\
		goto err;                                               \
} while (0)

T
Tomas Winkler 已提交
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
#define DEBUGFS_REMOVE(name)  do {              \
	debugfs_remove(name);                   \
	name = NULL;                            \
} while (0);

/* file operation */
#define DEBUGFS_READ_FUNC(name)                                         \
static ssize_t iwl_dbgfs_##name##_read(struct file *file,               \
					char __user *user_buf,          \
					size_t count, loff_t *ppos);

#define DEBUGFS_WRITE_FUNC(name)                                        \
static ssize_t iwl_dbgfs_##name##_write(struct file *file,              \
					const char __user *user_buf,    \
					size_t count, loff_t *ppos);


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

#define DEBUGFS_READ_FILE_OPS(name)                                     \
	DEBUGFS_READ_FUNC(name);                                        \
static const struct file_operations iwl_dbgfs_##name##_ops = {          \
	.read = iwl_dbgfs_##name##_read,                       		\
	.open = iwl_dbgfs_open_file_generic,                    	\
};

104 105 106 107 108 109 110 111
#define DEBUGFS_WRITE_FILE_OPS(name)                                    \
	DEBUGFS_WRITE_FUNC(name);                                       \
static const struct file_operations iwl_dbgfs_##name##_ops = {          \
	.write = iwl_dbgfs_##name##_write,                              \
	.open = iwl_dbgfs_open_file_generic,                    	\
};


T
Tomas Winkler 已提交
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
#define DEBUGFS_READ_WRITE_FILE_OPS(name)                               \
	DEBUGFS_READ_FUNC(name);                                        \
	DEBUGFS_WRITE_FUNC(name);                                       \
static const struct file_operations iwl_dbgfs_##name##_ops = {          \
	.write = iwl_dbgfs_##name##_write,                              \
	.read = iwl_dbgfs_##name##_read,                                \
	.open = iwl_dbgfs_open_file_generic,                            \
};


static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
						char __user *user_buf,
						size_t count, loff_t *ppos) {

	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
	char buf[256];
	int pos = 0;
129
	const size_t bufsz = sizeof(buf);
T
Tomas Winkler 已提交
130

131 132 133 134 135 136
	pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n",
						priv->tx_stats[0].cnt);
	pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n",
						priv->tx_stats[1].cnt);
	pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n",
						priv->tx_stats[2].cnt);
T
Tomas Winkler 已提交
137 138 139 140 141 142 143 144 145 146 147

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

static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
						char __user *user_buf,
						size_t count, loff_t *ppos) {

	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
	char buf[256];
	int pos = 0;
148
	const size_t bufsz = sizeof(buf);
T
Tomas Winkler 已提交
149

150 151 152 153 154 155
	pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n",
						priv->rx_stats[0].cnt);
	pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n",
						priv->rx_stats[1].cnt);
	pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n",
						priv->rx_stats[2].cnt);
T
Tomas Winkler 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172

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

#define BYTE1_MASK 0x000000ff;
#define BYTE2_MASK 0x0000ffff;
#define BYTE3_MASK 0x00ffffff;
static ssize_t iwl_dbgfs_sram_read(struct file *file,
					char __user *user_buf,
					size_t count, loff_t *ppos)
{
	u32 val;
	char buf[1024];
	ssize_t ret;
	int i;
	int pos = 0;
	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
173
	const size_t bufsz = sizeof(buf);
T
Tomas Winkler 已提交
174 175

	for (i = priv->dbgfs->sram_len; i > 0; i -= 4) {
176
		val = iwl_read_targ_mem(priv, priv->dbgfs->sram_offset + \
T
Tomas Winkler 已提交
177 178 179 180 181 182 183 184 185 186 187 188 189 190
					priv->dbgfs->sram_len - i);
		if (i < 4) {
			switch (i) {
			case 1:
				val &= BYTE1_MASK;
				break;
			case 2:
				val &= BYTE2_MASK;
				break;
			case 3:
				val &= BYTE3_MASK;
				break;
			}
		}
191
		pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
T
Tomas Winkler 已提交
192
	}
193
	pos += scnprintf(buf + pos, bufsz - pos, "\n");
T
Tomas Winkler 已提交
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227

	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	return ret;
}

static ssize_t iwl_dbgfs_sram_write(struct file *file,
					const char __user *user_buf,
					size_t count, loff_t *ppos)
{
	struct iwl_priv *priv = file->private_data;
	char buf[64];
	int buf_size;
	u32 offset, len;

	memset(buf, 0, sizeof(buf));
	buf_size = min(count, sizeof(buf) -  1);
	if (copy_from_user(buf, user_buf, buf_size))
		return -EFAULT;

	if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
		priv->dbgfs->sram_offset = offset;
		priv->dbgfs->sram_len = len;
	} else {
		priv->dbgfs->sram_offset = 0;
		priv->dbgfs->sram_len = 0;
	}

	return count;
}

static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
					size_t count, loff_t *ppos)
{
	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
228
	struct iwl_station_entry *station;
T
Tomas Winkler 已提交
229
	int max_sta = priv->hw_params.max_stations;
T
Tomas Winkler 已提交
230 231 232 233 234 235 236
	char *buf;
	int i, j, pos = 0;
	ssize_t ret;
	/* Add 30 for initial string */
	const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);

	buf = kmalloc(bufsz, GFP_KERNEL);
237
	if (!buf)
T
Tomas Winkler 已提交
238 239
		return -ENOMEM;

240
	pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
T
Tomas Winkler 已提交
241 242 243 244 245
			priv->num_stations);

	for (i = 0; i < max_sta; i++) {
		station = &priv->stations[i];
		if (station->used) {
246 247 248
			pos += scnprintf(buf + pos, bufsz - pos,
					"station %d:\ngeneral data:\n", i+1);
			pos += scnprintf(buf + pos, bufsz - pos, "id: %u\n",
T
Tomas Winkler 已提交
249
					station->sta.sta.sta_id);
250
			pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n",
T
Tomas Winkler 已提交
251
					station->sta.mode);
252 253
			pos += scnprintf(buf + pos, bufsz - pos,
					"flags: 0x%x\n",
T
Tomas Winkler 已提交
254
					station->sta.station_flags_msk);
255 256 257 258
			pos += scnprintf(buf + pos, bufsz - pos,
					"ps_status: %u\n", station->ps_status);
			pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n");
			pos += scnprintf(buf + pos, bufsz - pos,
259
					"seq_num\t\ttxq_id");
260
			pos += scnprintf(buf + pos, bufsz - pos,
261
					"\tframe_count\twait_for_ba\t");
262 263 264
			pos += scnprintf(buf + pos, bufsz - pos,
					"start_idx\tbitmap0\t");
			pos += scnprintf(buf + pos, bufsz - pos,
265 266
					"bitmap1\trate_n_flags");
			pos += scnprintf(buf + pos, bufsz - pos, "\n");
T
Tomas Winkler 已提交
267 268

			for (j = 0; j < MAX_TID_COUNT; j++) {
269
				pos += scnprintf(buf + pos, bufsz - pos,
270
						"[%d]:\t\t%u", j,
271 272
						station->tid[j].seq_number);
				pos += scnprintf(buf + pos, bufsz - pos,
273
						"\t%u\t\t%u\t\t%u\t\t",
T
Tomas Winkler 已提交
274 275 276
						station->tid[j].agg.txq_id,
						station->tid[j].agg.frame_count,
						station->tid[j].agg.wait_for_ba);
277
				pos += scnprintf(buf + pos, bufsz - pos,
278
						"%u\t%llu\t%u",
T
Tomas Winkler 已提交
279
						station->tid[j].agg.start_idx,
280
						(unsigned long long)station->tid[j].agg.bitmap,
T
Tomas Winkler 已提交
281
						station->tid[j].agg.rate_n_flags);
282
				pos += scnprintf(buf + pos, bufsz - pos, "\n");
T
Tomas Winkler 已提交
283
			}
284
			pos += scnprintf(buf + pos, bufsz - pos, "\n");
T
Tomas Winkler 已提交
285 286 287 288 289 290 291 292
		}
	}

	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	kfree(buf);
	return ret;
}

293
static ssize_t iwl_dbgfs_nvm_read(struct file *file,
T
Tomas Winkler 已提交
294 295 296 297 298 299 300 301 302 303 304 305 306
				       char __user *user_buf,
				       size_t count,
				       loff_t *ppos)
{
	ssize_t ret;
	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
	int pos = 0, ofs = 0, buf_size = 0;
	const u8 *ptr;
	char *buf;
	size_t eeprom_len = priv->cfg->eeprom_size;
	buf_size = 4 * eeprom_len + 256;

	if (eeprom_len % 16) {
307
		IWL_ERR(priv, "NVM size is not multiple of 16.\n");
T
Tomas Winkler 已提交
308 309 310 311 312 313
		return -ENODATA;
	}

	/* 4 characters for byte 0xYY */
	buf = kzalloc(buf_size, GFP_KERNEL);
	if (!buf) {
314
		IWL_ERR(priv, "Can not allocate Buffer\n");
T
Tomas Winkler 已提交
315 316 317 318
		return -ENOMEM;
	}

	ptr = priv->eeprom;
319 320 321 322 323 324 325
	if (!ptr) {
		IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
		return -ENOMEM;
	}
	pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s\n",
			(priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
			? "OTP" : "EEPROM");
T
Tomas Winkler 已提交
326 327 328 329 330 331 332 333 334 335 336 337 338
	for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
		pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
		hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
				   buf_size - pos, 0);
		pos += strlen(buf);
		if (buf_size - pos > 0)
			buf[pos++] = '\n';
	}

	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	kfree(buf);
	return ret;
}
T
Tomas Winkler 已提交
339

340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
static ssize_t iwl_dbgfs_log_event_write(struct file *file,
					const char __user *user_buf,
					size_t count, loff_t *ppos)
{
	struct iwl_priv *priv = file->private_data;
	u32 event_log_flag;
	char buf[8];
	int buf_size;

	memset(buf, 0, sizeof(buf));
	buf_size = min(count, sizeof(buf) -  1);
	if (copy_from_user(buf, user_buf, buf_size))
		return -EFAULT;
	if (sscanf(buf, "%d", &event_log_flag) != 1)
		return -EFAULT;
	if (event_log_flag == 1)
		iwl_dump_nic_event_log(priv);

	return count;
}

361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377


static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
				       size_t count, loff_t *ppos)
{
	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
	struct ieee80211_channel *channels = NULL;
	const struct ieee80211_supported_band *supp_band = NULL;
	int pos = 0, i, bufsz = PAGE_SIZE;
	char *buf;
	ssize_t ret;

	if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
		return -EAGAIN;

	buf = kzalloc(bufsz, GFP_KERNEL);
	if (!buf) {
378
		IWL_ERR(priv, "Can not allocate Buffer\n");
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
		return -ENOMEM;
	}

	supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
	channels = supp_band->channels;

	pos += scnprintf(buf + pos, bufsz - pos,
			"Displaying %d channels in 2.4GHz band 802.11bg):\n",
			 supp_band->n_channels);

	for (i = 0; i < supp_band->n_channels; i++)
		pos += scnprintf(buf + pos, bufsz - pos,
				"%d: %ddBm: BSS%s%s, %s.\n",
				ieee80211_frequency_to_channel(
				channels[i].center_freq),
				channels[i].max_power,
				channels[i].flags & IEEE80211_CHAN_RADAR ?
				" (IEEE 802.11h required)" : "",
397
				((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
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 429 430 431
				|| (channels[i].flags &
				IEEE80211_CHAN_RADAR)) ? "" :
				", IBSS",
				channels[i].flags &
				IEEE80211_CHAN_PASSIVE_SCAN ?
				"passive only" : "active/passive");

	supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
	channels = supp_band->channels;

	pos += scnprintf(buf + pos, bufsz - pos,
			"Displaying %d channels in 5.2GHz band (802.11a)\n",
			supp_band->n_channels);

	for (i = 0; i < supp_band->n_channels; i++)
		pos += scnprintf(buf + pos, bufsz - pos,
				"%d: %ddBm: BSS%s%s, %s.\n",
				ieee80211_frequency_to_channel(
				channels[i].center_freq),
				channels[i].max_power,
				channels[i].flags & IEEE80211_CHAN_RADAR ?
				" (IEEE 802.11h required)" : "",
				((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
				|| (channels[i].flags &
				IEEE80211_CHAN_RADAR)) ? "" :
				", IBSS",
				channels[i].flags &
				IEEE80211_CHAN_PASSIVE_SCAN ?
				"passive only" : "active/passive");
	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	kfree(buf);
	return ret;
}

432 433 434 435 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 477 478 479
static ssize_t iwl_dbgfs_status_read(struct file *file,
						char __user *user_buf,
						size_t count, loff_t *ppos) {

	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
	char buf[512];
	int pos = 0;
	const size_t bufsz = sizeof(buf);

	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
		test_bit(STATUS_HCMD_ACTIVE, &priv->status));
	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_SYNC_ACTIVE: %d\n",
		test_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status));
	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
		test_bit(STATUS_INT_ENABLED, &priv->status));
	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
		test_bit(STATUS_RF_KILL_HW, &priv->status));
	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_SW:\t %d\n",
		test_bit(STATUS_RF_KILL_SW, &priv->status));
	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
		test_bit(STATUS_INIT, &priv->status));
	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
		test_bit(STATUS_ALIVE, &priv->status));
	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
		test_bit(STATUS_READY, &priv->status));
	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
		test_bit(STATUS_TEMPERATURE, &priv->status));
	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
		test_bit(STATUS_GEO_CONFIGURED, &priv->status));
	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
		test_bit(STATUS_EXIT_PENDING, &priv->status));
	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
		test_bit(STATUS_STATISTICS, &priv->status));
	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
		test_bit(STATUS_SCANNING, &priv->status));
	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
		test_bit(STATUS_SCAN_ABORTING, &priv->status));
	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
		test_bit(STATUS_SCAN_HW, &priv->status));
	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
		test_bit(STATUS_POWER_PMI, &priv->status));
	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
		test_bit(STATUS_FW_ERROR, &priv->status));
	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_MODE_PENDING:\t %d\n",
		test_bit(STATUS_MODE_PENDING, &priv->status));
	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
}

480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 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
static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
					char __user *user_buf,
					size_t count, loff_t *ppos) {

	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
	int pos = 0;
	int cnt = 0;
	char *buf;
	int bufsz = 24 * 64; /* 24 items * 64 char per item */
	ssize_t ret;

	buf = kzalloc(bufsz, GFP_KERNEL);
	if (!buf) {
		IWL_ERR(priv, "Can not allocate Buffer\n");
		return -ENOMEM;
	}

	pos += scnprintf(buf + pos, bufsz - pos,
			"Interrupt Statistics Report:\n");

	pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
		priv->isr_stats.hw);
	pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
		priv->isr_stats.sw);
	if (priv->isr_stats.sw > 0) {
		pos += scnprintf(buf + pos, bufsz - pos,
			"\tLast Restarting Code:  0x%X\n",
			priv->isr_stats.sw_err);
	}
#ifdef CONFIG_IWLWIFI_DEBUG
	pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
		priv->isr_stats.sch);
	pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
		priv->isr_stats.alive);
#endif
	pos += scnprintf(buf + pos, bufsz - pos,
		"HW RF KILL switch toggled:\t %u\n",
		priv->isr_stats.rfkill);

	pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
		priv->isr_stats.ctkill);

	pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
		priv->isr_stats.wakeup);

	pos += scnprintf(buf + pos, bufsz - pos,
		"Rx command responses:\t\t %u\n",
		priv->isr_stats.rx);
	for (cnt = 0; cnt < REPLY_MAX; cnt++) {
		if (priv->isr_stats.rx_handlers[cnt] > 0)
			pos += scnprintf(buf + pos, bufsz - pos,
				"\tRx handler[%36s]:\t\t %u\n",
				get_cmd_string(cnt),
				priv->isr_stats.rx_handlers[cnt]);
	}

	pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
		priv->isr_stats.tx);

	pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
		priv->isr_stats.unhandled);

	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	kfree(buf);
	return ret;
}

static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
					 const char __user *user_buf,
					 size_t count, loff_t *ppos)
{
	struct iwl_priv *priv = file->private_data;
	char buf[8];
	int buf_size;
	u32 reset_flag;

	memset(buf, 0, sizeof(buf));
	buf_size = min(count, sizeof(buf) -  1);
	if (copy_from_user(buf, user_buf, buf_size))
		return -EFAULT;
	if (sscanf(buf, "%x", &reset_flag) != 1)
		return -EFAULT;
	if (reset_flag == 0)
		iwl_clear_isr_stats(priv);

	return count;
}


T
Tomas Winkler 已提交
569
DEBUGFS_READ_WRITE_FILE_OPS(sram);
570
DEBUGFS_WRITE_FILE_OPS(log_event);
571
DEBUGFS_READ_FILE_OPS(nvm);
T
Tomas Winkler 已提交
572 573 574
DEBUGFS_READ_FILE_OPS(stations);
DEBUGFS_READ_FILE_OPS(rx_statistics);
DEBUGFS_READ_FILE_OPS(tx_statistics);
575
DEBUGFS_READ_FILE_OPS(channels);
576
DEBUGFS_READ_FILE_OPS(status);
577
DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
T
Tomas Winkler 已提交
578 579 580 581 582 583 584 585

/*
 * Create the debugfs files and directories
 *
 */
int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
{
	struct iwl_debugfs *dbgfs;
586
	struct dentry *phyd = priv->hw->wiphy->debugfsdir;
587
	int ret = 0;
T
Tomas Winkler 已提交
588 589 590

	dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
	if (!dbgfs) {
591
		ret = -ENOMEM;
T
Tomas Winkler 已提交
592 593 594 595 596
		goto err;
	}

	priv->dbgfs = dbgfs;
	dbgfs->name = name;
597
	dbgfs->dir_drv = debugfs_create_dir(name, phyd);
598 599
	if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)) {
		ret = -ENOENT;
T
Tomas Winkler 已提交
600 601 602 603
		goto err;
	}

	DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
604
	DEBUGFS_ADD_DIR(rf, dbgfs->dir_drv);
605
	DEBUGFS_ADD_FILE(nvm, data);
T
Tomas Winkler 已提交
606
	DEBUGFS_ADD_FILE(sram, data);
607
	DEBUGFS_ADD_FILE(log_event, data);
T
Tomas Winkler 已提交
608 609 610
	DEBUGFS_ADD_FILE(stations, data);
	DEBUGFS_ADD_FILE(rx_statistics, data);
	DEBUGFS_ADD_FILE(tx_statistics, data);
611
	DEBUGFS_ADD_FILE(channels, data);
612
	DEBUGFS_ADD_FILE(status, data);
613
	DEBUGFS_ADD_FILE(interrupt, data);
614 615 616
	DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal);
	DEBUGFS_ADD_BOOL(disable_chain_noise, rf,
			 &priv->disable_chain_noise_cal);
617
	DEBUGFS_ADD_BOOL(disable_tx_power, rf, &priv->disable_tx_power_cal);
T
Tomas Winkler 已提交
618 619 620
	return 0;

err:
621
	IWL_ERR(priv, "Can't open the debugfs directory\n");
T
Tomas Winkler 已提交
622
	iwl_dbgfs_unregister(priv);
623
	return ret;
T
Tomas Winkler 已提交
624 625 626 627 628 629 630 631 632
}
EXPORT_SYMBOL(iwl_dbgfs_register);

/**
 * Remove the debugfs files and directories
 *
 */
void iwl_dbgfs_unregister(struct iwl_priv *priv)
{
633
	if (!priv->dbgfs)
T
Tomas Winkler 已提交
634 635
		return;

636
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_nvm);
T
Tomas Winkler 已提交
637 638 639
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_rx_statistics);
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_tx_statistics);
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
640
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_log_event);
T
Tomas Winkler 已提交
641
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
642
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_channels);
643
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_status);
644
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_interrupt);
T
Tomas Winkler 已提交
645
	DEBUGFS_REMOVE(priv->dbgfs->dir_data);
646 647
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity);
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise);
648
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_tx_power);
649
	DEBUGFS_REMOVE(priv->dbgfs->dir_rf);
T
Tomas Winkler 已提交
650 651 652 653 654 655 656
	DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
	kfree(priv->dbgfs);
	priv->dbgfs = NULL;
}
EXPORT_SYMBOL(iwl_dbgfs_unregister);


657