iwl-debugfs.c 48.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


/* 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 =                     \
52 53
	debugfs_create_file(#name, S_IWUSR | S_IRUSR,                   \
				dbgfs->dir_##parent, priv,              \
T
Tomas Winkler 已提交
54 55 56 57 58
				&iwl_dbgfs_##name##_ops);               \
	if (!(dbgfs->dbgfs_##parent##_files.file_##name))               \
		goto err;                                               \
} while (0)

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

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

T
Tomas Winkler 已提交
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 104 105
#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,                    	\
};

106 107 108 109 110 111 112 113
#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 已提交
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;
129
	char *buf;
T
Tomas Winkler 已提交
130 131
	int pos = 0;

132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
	int cnt;
	ssize_t ret;
	const size_t bufsz = 100 + sizeof(char) * 24 * (MANAGEMENT_MAX + CONTROL_MAX);
	buf = kzalloc(bufsz, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;
	pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
	for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
		pos += scnprintf(buf + pos, bufsz - pos,
				 "\t%s\t\t: %u\n",
				 get_mgmt_string(cnt),
				 priv->tx_stats.mgmt[cnt]);
	}
	pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
	for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
		pos += scnprintf(buf + pos, bufsz - pos,
				 "\t%s\t\t: %u\n",
				 get_ctrl_string(cnt),
				 priv->tx_stats.ctrl[cnt]);
	}
	pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
	pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
			 priv->tx_stats.data_cnt);
	pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
			 priv->tx_stats.data_bytes);
	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	kfree(buf);
	return ret;
}

static ssize_t iwl_dbgfs_tx_statistics_write(struct file *file,
					const char __user *user_buf,
					size_t count, loff_t *ppos)
{
	struct iwl_priv *priv = file->private_data;
	u32 clear_flag;
	char buf[8];
	int buf_size;
T
Tomas Winkler 已提交
170

171 172 173 174 175 176 177 178 179 180
	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", &clear_flag) != 1)
		return -EFAULT;
	if (clear_flag == 1)
		iwl_clear_tx_stats(priv);

	return count;
T
Tomas Winkler 已提交
181 182 183 184 185 186 187
}

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;
188
	char *buf;
T
Tomas Winkler 已提交
189
	int pos = 0;
190 191 192 193 194 195 196
	int cnt;
	ssize_t ret;
	const size_t bufsz = 100 +
		sizeof(char) * 24 * (MANAGEMENT_MAX + CONTROL_MAX);
	buf = kzalloc(bufsz, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;
T
Tomas Winkler 已提交
197

198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
	pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
	for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
		pos += scnprintf(buf + pos, bufsz - pos,
				 "\t%s\t\t: %u\n",
				 get_mgmt_string(cnt),
				 priv->rx_stats.mgmt[cnt]);
	}
	pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
	for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
		pos += scnprintf(buf + pos, bufsz - pos,
				 "\t%s\t\t: %u\n",
				 get_ctrl_string(cnt),
				 priv->rx_stats.ctrl[cnt]);
	}
	pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
	pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
			 priv->rx_stats.data_cnt);
	pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
			 priv->rx_stats.data_bytes);
T
Tomas Winkler 已提交
217

218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	kfree(buf);
	return ret;
}

static ssize_t iwl_dbgfs_rx_statistics_write(struct file *file,
					const char __user *user_buf,
					size_t count, loff_t *ppos)
{
	struct iwl_priv *priv = file->private_data;
	u32 clear_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, "%x", &clear_flag) != 1)
		return -EFAULT;
	if (clear_flag == 1)
		iwl_clear_rx_stats(priv);
	return count;
T
Tomas Winkler 已提交
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
}

#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;
256
	const size_t bufsz = sizeof(buf);
T
Tomas Winkler 已提交
257 258

	for (i = priv->dbgfs->sram_len; i > 0; i -= 4) {
259
		val = iwl_read_targ_mem(priv, priv->dbgfs->sram_offset + \
T
Tomas Winkler 已提交
260 261 262 263 264 265 266 267 268 269 270 271 272 273
					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;
			}
		}
274
		pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
T
Tomas Winkler 已提交
275
	}
276
	pos += scnprintf(buf + pos, bufsz - pos, "\n");
T
Tomas Winkler 已提交
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310

	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;
311
	struct iwl_station_entry *station;
T
Tomas Winkler 已提交
312
	int max_sta = priv->hw_params.max_stations;
T
Tomas Winkler 已提交
313 314 315 316 317 318 319
	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);
320
	if (!buf)
T
Tomas Winkler 已提交
321 322
		return -ENOMEM;

323
	pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
T
Tomas Winkler 已提交
324 325 326 327 328
			priv->num_stations);

	for (i = 0; i < max_sta; i++) {
		station = &priv->stations[i];
		if (station->used) {
329 330 331
			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 已提交
332
					station->sta.sta.sta_id);
333
			pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n",
T
Tomas Winkler 已提交
334
					station->sta.mode);
335 336
			pos += scnprintf(buf + pos, bufsz - pos,
					"flags: 0x%x\n",
T
Tomas Winkler 已提交
337
					station->sta.station_flags_msk);
338 339 340 341
			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,
342
					"seq_num\t\ttxq_id");
343
			pos += scnprintf(buf + pos, bufsz - pos,
344
					"\tframe_count\twait_for_ba\t");
345 346 347
			pos += scnprintf(buf + pos, bufsz - pos,
					"start_idx\tbitmap0\t");
			pos += scnprintf(buf + pos, bufsz - pos,
348 349
					"bitmap1\trate_n_flags");
			pos += scnprintf(buf + pos, bufsz - pos, "\n");
T
Tomas Winkler 已提交
350 351

			for (j = 0; j < MAX_TID_COUNT; j++) {
352
				pos += scnprintf(buf + pos, bufsz - pos,
353
						"[%d]:\t\t%u", j,
354 355
						station->tid[j].seq_number);
				pos += scnprintf(buf + pos, bufsz - pos,
356
						"\t%u\t\t%u\t\t%u\t\t",
T
Tomas Winkler 已提交
357 358 359
						station->tid[j].agg.txq_id,
						station->tid[j].agg.frame_count,
						station->tid[j].agg.wait_for_ba);
360
				pos += scnprintf(buf + pos, bufsz - pos,
361
						"%u\t%llu\t%u",
T
Tomas Winkler 已提交
362
						station->tid[j].agg.start_idx,
363
						(unsigned long long)station->tid[j].agg.bitmap,
T
Tomas Winkler 已提交
364
						station->tid[j].agg.rate_n_flags);
365
				pos += scnprintf(buf + pos, bufsz - pos, "\n");
T
Tomas Winkler 已提交
366
			}
367
			pos += scnprintf(buf + pos, bufsz - pos, "\n");
T
Tomas Winkler 已提交
368 369 370 371 372 373 374 375
		}
	}

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

376
static ssize_t iwl_dbgfs_nvm_read(struct file *file,
T
Tomas Winkler 已提交
377 378 379 380 381 382 383 384 385 386 387 388 389
				       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) {
390
		IWL_ERR(priv, "NVM size is not multiple of 16.\n");
T
Tomas Winkler 已提交
391 392 393
		return -ENODATA;
	}

394 395 396 397 398 399
	ptr = priv->eeprom;
	if (!ptr) {
		IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
		return -ENOMEM;
	}

T
Tomas Winkler 已提交
400 401 402
	/* 4 characters for byte 0xYY */
	buf = kzalloc(buf_size, GFP_KERNEL);
	if (!buf) {
403
		IWL_ERR(priv, "Can not allocate Buffer\n");
T
Tomas Winkler 已提交
404 405
		return -ENOMEM;
	}
406 407 408
	pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s\n",
			(priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
			? "OTP" : "EEPROM");
T
Tomas Winkler 已提交
409 410 411 412 413 414 415 416 417 418 419 420 421
	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 已提交
422

423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
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;
}

444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460


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) {
461
		IWL_ERR(priv, "Can not allocate Buffer\n");
462 463 464 465
		return -ENOMEM;
	}

	supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
466 467
	if (supp_band) {
		channels = supp_band->channels;
468 469

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

473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
		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");
	}
489
	supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
490 491
	if (supp_band) {
		channels = supp_band->channels;
492 493

		pos += scnprintf(buf + pos, bufsz - pos,
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
				"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");
	}
513 514 515 516 517
	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	kfree(buf);
	return ret;
}

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
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_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);
}

564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
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;
}

W
Wey-Yi Guy 已提交
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673
static ssize_t iwl_dbgfs_qos_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, i;
	char buf[256];
	const size_t bufsz = sizeof(buf);
	ssize_t ret;

	for (i = 0; i < AC_NUM; i++) {
		pos += scnprintf(buf + pos, bufsz - pos,
			"\tcw_min\tcw_max\taifsn\ttxop\n");
		pos += scnprintf(buf + pos, bufsz - pos,
				"AC[%d]\t%u\t%u\t%u\t%u\n", i,
				priv->qos_data.def_qos_parm.ac[i].cw_min,
				priv->qos_data.def_qos_parm.ac[i].cw_max,
				priv->qos_data.def_qos_parm.ac[i].aifsn,
				priv->qos_data.def_qos_parm.ac[i].edca_txop);
	}
	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	return ret;
}
674

W
Wey-Yi Guy 已提交
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
#ifdef CONFIG_IWLWIFI_LEDS
static ssize_t iwl_dbgfs_led_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;
	char buf[256];
	const size_t bufsz = sizeof(buf);
	ssize_t ret;

	pos += scnprintf(buf + pos, bufsz - pos,
			 "allow blinking: %s\n",
			 (priv->allow_blinking) ? "True" : "False");
	if (priv->allow_blinking) {
		pos += scnprintf(buf + pos, bufsz - pos,
				 "Led blinking rate: %u\n",
				 priv->last_blink_rate);
		pos += scnprintf(buf + pos, bufsz - pos,
				 "Last blink time: %lu\n",
				 priv->last_blink_time);
	}

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

702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
static ssize_t iwl_dbgfs_thermal_throttling_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 iwl_tt_mgmt *tt = &priv->power_data.tt;
	struct iwl_tt_restriction *restriction;
	char buf[100];
	int pos = 0;
	const size_t bufsz = sizeof(buf);
	ssize_t ret;

	pos += scnprintf(buf + pos, bufsz - pos,
			"Thermal Throttling Mode: %s\n",
			(priv->power_data.adv_tt)
			? "Advance" : "Legacy");
	pos += scnprintf(buf + pos, bufsz - pos,
			"Thermal Throttling State: %d\n",
			tt->state);
	if (priv->power_data.adv_tt) {
		restriction = tt->restriction + tt->state;
		pos += scnprintf(buf + pos, bufsz - pos,
				"Tx mode: %d\n",
				restriction->tx_stream);
		pos += scnprintf(buf + pos, bufsz - pos,
				"Rx mode: %d\n",
				restriction->rx_stream);
		pos += scnprintf(buf + pos, bufsz - pos,
				"HT mode: %d\n",
				restriction->is_ht);
	}
	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	return ret;
}

737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779
static ssize_t iwl_dbgfs_disable_ht40_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;
	int ht40;

	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", &ht40) != 1)
		return -EFAULT;
	if (!iwl_is_associated(priv))
		priv->disable_ht40 = ht40 ? true : false;
	else {
		IWL_ERR(priv, "Sta associated with AP - "
			"Change to 40MHz channel support is not allowed\n");
		return -EINVAL;
	}

	return count;
}

static ssize_t iwl_dbgfs_disable_ht40_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[100];
	int pos = 0;
	const size_t bufsz = sizeof(buf);
	ssize_t ret;

	pos += scnprintf(buf + pos, bufsz - pos,
			"11n 40MHz Mode: %s\n",
			priv->disable_ht40 ? "Disabled" : "Enabled");
	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	return ret;
}

T
Tomas Winkler 已提交
780
DEBUGFS_READ_WRITE_FILE_OPS(sram);
781
DEBUGFS_WRITE_FILE_OPS(log_event);
782
DEBUGFS_READ_FILE_OPS(nvm);
T
Tomas Winkler 已提交
783
DEBUGFS_READ_FILE_OPS(stations);
784
DEBUGFS_READ_FILE_OPS(channels);
785
DEBUGFS_READ_FILE_OPS(status);
786
DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
W
Wey-Yi Guy 已提交
787
DEBUGFS_READ_FILE_OPS(qos);
W
Wey-Yi Guy 已提交
788 789 790
#ifdef CONFIG_IWLWIFI_LEDS
DEBUGFS_READ_FILE_OPS(led);
#endif
791
DEBUGFS_READ_FILE_OPS(thermal_throttling);
792
DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
T
Tomas Winkler 已提交
793

794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889
static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
					 char __user *user_buf,
					 size_t count, loff_t *ppos)
{
	struct iwl_priv *priv = file->private_data;
	int pos = 0, ofs = 0;
	int cnt = 0, entry;
	struct iwl_tx_queue *txq;
	struct iwl_queue *q;
	struct iwl_rx_queue *rxq = &priv->rxq;
	char *buf;
	int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
		(IWL_MAX_NUM_QUEUES * 32 * 8) + 400;
	const u8 *ptr;
	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, "Tx Queue\n");
	for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
		txq = &priv->txq[cnt];
		q = &txq->q;
		pos += scnprintf(buf + pos, bufsz - pos,
				"q[%d]: read_ptr: %u, write_ptr: %u\n",
				cnt, q->read_ptr, q->write_ptr);
	}
	if (priv->tx_traffic && (iwl_debug_level & IWL_DL_TX)) {
		ptr = priv->tx_traffic;
		pos += scnprintf(buf + pos, bufsz - pos,
				"Tx Traffic idx: %u\n",	priv->tx_traffic_idx);
		for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
			for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
			     entry++,  ofs += 16) {
				pos += scnprintf(buf + pos, bufsz - pos,
						"0x%.4x ", ofs);
				hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
						   buf + pos, bufsz - pos, 0);
				pos += strlen(buf);
				if (bufsz - pos > 0)
					buf[pos++] = '\n';
			}
		}
	}

	pos += scnprintf(buf + pos, bufsz - pos, "Rx Queue\n");
	pos += scnprintf(buf + pos, bufsz - pos,
			"read: %u, write: %u\n",
			 rxq->read, rxq->write);

	if (priv->rx_traffic && (iwl_debug_level & IWL_DL_RX)) {
		ptr = priv->rx_traffic;
		pos += scnprintf(buf + pos, bufsz - pos,
				"Rx Traffic idx: %u\n",	priv->rx_traffic_idx);
		for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
			for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
			     entry++,  ofs += 16) {
				pos += scnprintf(buf + pos, bufsz - pos,
						"0x%.4x ", ofs);
				hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
						   buf + pos, bufsz - pos, 0);
				pos += strlen(buf);
				if (bufsz - pos > 0)
					buf[pos++] = '\n';
			}
		}
	}

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

static ssize_t iwl_dbgfs_traffic_log_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;
	int traffic_log;

	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", &traffic_log) != 1)
		return -EFAULT;
	if (traffic_log == 0)
		iwl_reset_traffic_log(priv);

	return count;
}

890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952
static ssize_t iwl_dbgfs_tx_queue_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 iwl_tx_queue *txq;
	struct iwl_queue *q;
	char *buf;
	int pos = 0;
	int cnt;
	int ret;
	const size_t bufsz = sizeof(char) * 60 * IWL_MAX_NUM_QUEUES;

	buf = kzalloc(bufsz, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;

	for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
		txq = &priv->txq[cnt];
		q = &txq->q;
		pos += scnprintf(buf + pos, bufsz - pos,
				"hwq %.2d: read=%u write=%u stop=%d"
				" swq_id=%#.2x (ac %d/hwq %d)\n",
				cnt, q->read_ptr, q->write_ptr,
				!!test_bit(cnt, priv->queue_stopped),
				txq->swq_id,
				txq->swq_id & 0x80 ? txq->swq_id & 3 :
				txq->swq_id,
				txq->swq_id & 0x80 ? (txq->swq_id >> 2) &
				0x1f : txq->swq_id);
		if (cnt >= 4)
			continue;
		/* for the ACs, display the stop count too */
		pos += scnprintf(buf + pos, bufsz - pos,
				"        stop-count: %d\n",
				atomic_read(&priv->queue_stop_count[cnt]));
	}
	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	kfree(buf);
	return ret;
}

static ssize_t iwl_dbgfs_rx_queue_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 iwl_rx_queue *rxq = &priv->rxq;
	char buf[256];
	int pos = 0;
	const size_t bufsz = sizeof(buf);

	pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
						rxq->read);
	pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
						rxq->write);
	pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
						rxq->free_count);
	pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
			 le16_to_cpu(rxq->rb_stts->closed_rb_num) &  0x0FFF);
	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
}

953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348
#define UCODE_STATISTICS_CLEAR_MSK		(0x1 << 0)
#define UCODE_STATISTICS_FREQUENCY_MSK		(0x1 << 1)
#define UCODE_STATISTICS_NARROW_BAND_MSK	(0x1 << 2)

static int iwl_dbgfs_statistics_flag(struct iwl_priv *priv, char *buf,
				     int bufsz)
{
	int p = 0;

	p += scnprintf(buf + p, bufsz - p,
		"Statistics Flag(0x%X):\n",
		le32_to_cpu(priv->statistics.flag));
	if (le32_to_cpu(priv->statistics.flag) & UCODE_STATISTICS_CLEAR_MSK)
		p += scnprintf(buf + p, bufsz - p,
		"\tStatistics have been cleared\n");
	p += scnprintf(buf + p, bufsz - p,
		"\tOperational Frequency: %s\n",
		(le32_to_cpu(priv->statistics.flag) &
		UCODE_STATISTICS_FREQUENCY_MSK)
		 ? "2.4 GHz" : "5.2 GHz");
	p += scnprintf(buf + p, bufsz - p,
		"\tTGj Narrow Band: %s\n",
		(le32_to_cpu(priv->statistics.flag) &
		UCODE_STATISTICS_NARROW_BAND_MSK)
		 ? "enabled" : "disabled");
	return p;
}


static ssize_t iwl_dbgfs_ucode_rx_stats_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;
	char *buf;
	int bufsz = sizeof(struct statistics_rx_phy) * 20 +
		sizeof(struct statistics_rx_non_phy) * 20 +
		sizeof(struct statistics_rx_ht_phy) * 20 + 400;
	ssize_t ret;
	struct statistics_rx_phy *ofdm;
	struct statistics_rx_phy *cck;
	struct statistics_rx_non_phy *general;
	struct statistics_rx_ht_phy *ht;

	if (!iwl_is_alive(priv))
		return -EAGAIN;

	/* make request to uCode to retrieve statistics information */
	mutex_lock(&priv->mutex);
	ret = iwl_send_statistics_request(priv, 0);
	mutex_unlock(&priv->mutex);

	if (ret) {
		IWL_ERR(priv,
			"Error sending statistics request: %zd\n", ret);
		return -EAGAIN;
	}
	buf = kzalloc(bufsz, GFP_KERNEL);
	if (!buf) {
		IWL_ERR(priv, "Can not allocate Buffer\n");
		return -ENOMEM;
	}

	/* the statistic information display here is based on
	 * the last statistics notification from uCode
	 * might not reflect the current uCode activity
	 */
	ofdm = &priv->statistics.rx.ofdm;
	cck = &priv->statistics.rx.cck;
	general = &priv->statistics.rx.general;
	ht = &priv->statistics.rx.ofdm_ht;
	pos += iwl_dbgfs_statistics_flag(priv, buf, bufsz);
	pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - OFDM:\n");
	pos += scnprintf(buf + pos, bufsz - pos, "ina_cnt: %u\n",
			 le32_to_cpu(ofdm->ina_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "fina_cnt: %u\n",
			 le32_to_cpu(ofdm->fina_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "plcp_err: %u\n",
			 le32_to_cpu(ofdm->plcp_err));
	pos += scnprintf(buf + pos, bufsz - pos, "crc32_err: %u\n",
			 le32_to_cpu(ofdm->crc32_err));
	pos += scnprintf(buf + pos, bufsz - pos, "overrun_err: %u\n",
			 le32_to_cpu(ofdm->overrun_err));
	pos += scnprintf(buf + pos, bufsz - pos, "early_overrun_err: %u\n",
			 le32_to_cpu(ofdm->early_overrun_err));
	pos += scnprintf(buf + pos, bufsz - pos, "crc32_good: %u\n",
			 le32_to_cpu(ofdm->crc32_good));
	pos += scnprintf(buf + pos, bufsz - pos, "false_alarm_cnt: %u\n",
			 le32_to_cpu(ofdm->false_alarm_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "fina_sync_err_cnt: %u\n",
			 le32_to_cpu(ofdm->fina_sync_err_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "sfd_timeout: %u\n",
			 le32_to_cpu(ofdm->sfd_timeout));
	pos += scnprintf(buf + pos, bufsz - pos, "fina_timeout: %u\n",
			 le32_to_cpu(ofdm->fina_timeout));
	pos += scnprintf(buf + pos, bufsz - pos, "unresponded_rts: %u\n",
			 le32_to_cpu(ofdm->unresponded_rts));
	pos += scnprintf(buf + pos, bufsz - pos,
			"rxe_frame_limit_overrun: %u\n",
			le32_to_cpu(ofdm->rxe_frame_limit_overrun));
	pos += scnprintf(buf + pos, bufsz - pos, "sent_ack_cnt: %u\n",
			 le32_to_cpu(ofdm->sent_ack_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "sent_cts_cnt: %u\n",
			 le32_to_cpu(ofdm->sent_cts_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "sent_ba_rsp_cnt: %u\n",
			 le32_to_cpu(ofdm->sent_ba_rsp_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "dsp_self_kill: %u\n",
			 le32_to_cpu(ofdm->dsp_self_kill));
	pos += scnprintf(buf + pos, bufsz - pos, "mh_format_err: %u\n",
			 le32_to_cpu(ofdm->mh_format_err));
	pos += scnprintf(buf + pos, bufsz - pos, "re_acq_main_rssi_sum: %u\n",
			 le32_to_cpu(ofdm->re_acq_main_rssi_sum));

	pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - CCK:\n");
	pos += scnprintf(buf + pos, bufsz - pos, "ina_cnt: %u\n",
			 le32_to_cpu(cck->ina_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "fina_cnt: %u\n",
			 le32_to_cpu(cck->fina_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "plcp_err: %u\n",
			 le32_to_cpu(cck->plcp_err));
	pos += scnprintf(buf + pos, bufsz - pos, "crc32_err: %u\n",
			 le32_to_cpu(cck->crc32_err));
	pos += scnprintf(buf + pos, bufsz - pos, "overrun_err: %u\n",
			 le32_to_cpu(cck->overrun_err));
	pos += scnprintf(buf + pos, bufsz - pos, "early_overrun_err: %u\n",
			 le32_to_cpu(cck->early_overrun_err));
	pos += scnprintf(buf + pos, bufsz - pos, "crc32_good: %u\n",
			 le32_to_cpu(cck->crc32_good));
	pos += scnprintf(buf + pos, bufsz - pos, "false_alarm_cnt: %u\n",
			 le32_to_cpu(cck->false_alarm_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "fina_sync_err_cnt: %u\n",
			 le32_to_cpu(cck->fina_sync_err_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "sfd_timeout: %u\n",
			 le32_to_cpu(cck->sfd_timeout));
	pos += scnprintf(buf + pos, bufsz - pos, "fina_timeout: %u\n",
			 le32_to_cpu(cck->fina_timeout));
	pos += scnprintf(buf + pos, bufsz - pos, "unresponded_rts: %u\n",
			 le32_to_cpu(cck->unresponded_rts));
	pos += scnprintf(buf + pos, bufsz - pos,
			"rxe_frame_limit_overrun: %u\n",
			le32_to_cpu(cck->rxe_frame_limit_overrun));
	pos += scnprintf(buf + pos, bufsz - pos, "sent_ack_cnt: %u\n",
			 le32_to_cpu(cck->sent_ack_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "sent_cts_cnt: %u\n",
			 le32_to_cpu(cck->sent_cts_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "sent_ba_rsp_cnt: %u\n",
			 le32_to_cpu(cck->sent_ba_rsp_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "dsp_self_kill: %u\n",
			 le32_to_cpu(cck->dsp_self_kill));
	pos += scnprintf(buf + pos, bufsz - pos, "mh_format_err: %u\n",
			 le32_to_cpu(cck->mh_format_err));
	pos += scnprintf(buf + pos, bufsz - pos, "re_acq_main_rssi_sum: %u\n",
			 le32_to_cpu(cck->re_acq_main_rssi_sum));

	pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - GENERAL:\n");
	pos += scnprintf(buf + pos, bufsz - pos, "bogus_cts: %u\n",
			 le32_to_cpu(general->bogus_cts));
	pos += scnprintf(buf + pos, bufsz - pos, "bogus_ack: %u\n",
			 le32_to_cpu(general->bogus_ack));
	pos += scnprintf(buf + pos, bufsz - pos, "non_bssid_frames: %u\n",
			 le32_to_cpu(general->non_bssid_frames));
	pos += scnprintf(buf + pos, bufsz - pos, "filtered_frames: %u\n",
			 le32_to_cpu(general->filtered_frames));
	pos += scnprintf(buf + pos, bufsz - pos, "non_channel_beacons: %u\n",
			 le32_to_cpu(general->non_channel_beacons));
	pos += scnprintf(buf + pos, bufsz - pos, "channel_beacons: %u\n",
			 le32_to_cpu(general->channel_beacons));
	pos += scnprintf(buf + pos, bufsz - pos, "num_missed_bcon: %u\n",
			 le32_to_cpu(general->num_missed_bcon));
	pos += scnprintf(buf + pos, bufsz - pos,
			"adc_rx_saturation_time: %u\n",
			le32_to_cpu(general->adc_rx_saturation_time));
	pos += scnprintf(buf + pos, bufsz - pos,
			"ina_detection_search_time: %u\n",
			le32_to_cpu(general->ina_detection_search_time));
	pos += scnprintf(buf + pos, bufsz - pos, "beacon_silence_rssi_a: %u\n",
			 le32_to_cpu(general->beacon_silence_rssi_a));
	pos += scnprintf(buf + pos, bufsz - pos, "beacon_silence_rssi_b: %u\n",
			 le32_to_cpu(general->beacon_silence_rssi_b));
	pos += scnprintf(buf + pos, bufsz - pos, "beacon_silence_rssi_c: %u\n",
			 le32_to_cpu(general->beacon_silence_rssi_c));
	pos += scnprintf(buf + pos, bufsz - pos,
			"interference_data_flag: %u\n",
			le32_to_cpu(general->interference_data_flag));
	pos += scnprintf(buf + pos, bufsz - pos, "channel_load: %u\n",
			 le32_to_cpu(general->channel_load));
	pos += scnprintf(buf + pos, bufsz - pos, "dsp_false_alarms: %u\n",
			 le32_to_cpu(general->dsp_false_alarms));
	pos += scnprintf(buf + pos, bufsz - pos, "beacon_rssi_a: %u\n",
			 le32_to_cpu(general->beacon_rssi_a));
	pos += scnprintf(buf + pos, bufsz - pos, "beacon_rssi_b: %u\n",
			 le32_to_cpu(general->beacon_rssi_b));
	pos += scnprintf(buf + pos, bufsz - pos, "beacon_rssi_c: %u\n",
			 le32_to_cpu(general->beacon_rssi_c));
	pos += scnprintf(buf + pos, bufsz - pos, "beacon_energy_a: %u\n",
			 le32_to_cpu(general->beacon_energy_a));
	pos += scnprintf(buf + pos, bufsz - pos, "beacon_energy_b: %u\n",
			 le32_to_cpu(general->beacon_energy_b));
	pos += scnprintf(buf + pos, bufsz - pos, "beacon_energy_c: %u\n",
			 le32_to_cpu(general->beacon_energy_c));

	pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - OFDM_HT:\n");
	pos += scnprintf(buf + pos, bufsz - pos, "plcp_err: %u\n",
			 le32_to_cpu(ht->plcp_err));
	pos += scnprintf(buf + pos, bufsz - pos, "overrun_err: %u\n",
			 le32_to_cpu(ht->overrun_err));
	pos += scnprintf(buf + pos, bufsz - pos, "early_overrun_err: %u\n",
			 le32_to_cpu(ht->early_overrun_err));
	pos += scnprintf(buf + pos, bufsz - pos, "crc32_good: %u\n",
			 le32_to_cpu(ht->crc32_good));
	pos += scnprintf(buf + pos, bufsz - pos, "crc32_err: %u\n",
			 le32_to_cpu(ht->crc32_err));
	pos += scnprintf(buf + pos, bufsz - pos, "mh_format_err: %u\n",
			 le32_to_cpu(ht->mh_format_err));
	pos += scnprintf(buf + pos, bufsz - pos, "agg_crc32_good: %u\n",
			 le32_to_cpu(ht->agg_crc32_good));
	pos += scnprintf(buf + pos, bufsz - pos, "agg_mpdu_cnt: %u\n",
			 le32_to_cpu(ht->agg_mpdu_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "agg_cnt: %u\n",
			 le32_to_cpu(ht->agg_cnt));

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

static ssize_t iwl_dbgfs_ucode_tx_stats_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;
	char *buf;
	int bufsz = (sizeof(struct statistics_tx) * 24) + 250;
	ssize_t ret;
	struct statistics_tx *tx;

	if (!iwl_is_alive(priv))
		return -EAGAIN;

	/* make request to uCode to retrieve statistics information */
	mutex_lock(&priv->mutex);
	ret = iwl_send_statistics_request(priv, 0);
	mutex_unlock(&priv->mutex);

	if (ret) {
		IWL_ERR(priv,
			"Error sending statistics request: %zd\n", ret);
		return -EAGAIN;
	}
	buf = kzalloc(bufsz, GFP_KERNEL);
	if (!buf) {
		IWL_ERR(priv, "Can not allocate Buffer\n");
		return -ENOMEM;
	}

	/* the statistic information display here is based on
	 * the last statistics notification from uCode
	 * might not reflect the current uCode activity
	 */
	tx = &priv->statistics.tx;
	pos += iwl_dbgfs_statistics_flag(priv, buf, bufsz);
	pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Tx:\n");
	pos += scnprintf(buf + pos, bufsz - pos, "preamble: %u\n",
			 le32_to_cpu(tx->preamble_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "rx_detected_cnt: %u\n",
			 le32_to_cpu(tx->rx_detected_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "bt_prio_defer_cnt: %u\n",
			 le32_to_cpu(tx->bt_prio_defer_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "bt_prio_kill_cnt: %u\n",
			 le32_to_cpu(tx->bt_prio_kill_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "few_bytes_cnt: %u\n",
			 le32_to_cpu(tx->few_bytes_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "cts_timeout: %u\n",
			 le32_to_cpu(tx->cts_timeout));
	pos += scnprintf(buf + pos, bufsz - pos, "ack_timeout: %u\n",
			 le32_to_cpu(tx->ack_timeout));
	pos += scnprintf(buf + pos, bufsz - pos, "expected_ack_cnt: %u\n",
			 le32_to_cpu(tx->expected_ack_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "actual_ack_cnt: %u\n",
			 le32_to_cpu(tx->actual_ack_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "dump_msdu_cnt: %u\n",
			 le32_to_cpu(tx->dump_msdu_cnt));
	pos += scnprintf(buf + pos, bufsz - pos,
			"burst_abort_next_frame_mismatch_cnt: %u\n",
			le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt));
	pos += scnprintf(buf + pos, bufsz - pos,
			"burst_abort_missing_next_frame_cnt: %u\n",
			le32_to_cpu(tx->burst_abort_missing_next_frame_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "cts_timeout_collision: %u\n",
			 le32_to_cpu(tx->cts_timeout_collision));
	pos += scnprintf(buf + pos, bufsz - pos,
			"ack_or_ba_timeout_collision: %u\n",
			le32_to_cpu(tx->ack_or_ba_timeout_collision));
	pos += scnprintf(buf + pos, bufsz - pos, "agg ba_timeout: %u\n",
			 le32_to_cpu(tx->agg.ba_timeout));
	pos += scnprintf(buf + pos, bufsz - pos,
			"agg ba_reschedule_frames: %u\n",
			le32_to_cpu(tx->agg.ba_reschedule_frames));
	pos += scnprintf(buf + pos, bufsz - pos,
			"agg scd_query_agg_frame_cnt: %u\n",
			le32_to_cpu(tx->agg.scd_query_agg_frame_cnt));
	pos += scnprintf(buf + pos, bufsz - pos, "agg scd_query_no_agg: %u\n",
			 le32_to_cpu(tx->agg.scd_query_no_agg));
	pos += scnprintf(buf + pos, bufsz - pos, "agg scd_query_agg: %u\n",
			 le32_to_cpu(tx->agg.scd_query_agg));
	pos += scnprintf(buf + pos, bufsz - pos,
			"agg scd_query_mismatch: %u\n",
			le32_to_cpu(tx->agg.scd_query_mismatch));
	pos += scnprintf(buf + pos, bufsz - pos, "agg frame_not_ready: %u\n",
			 le32_to_cpu(tx->agg.frame_not_ready));
	pos += scnprintf(buf + pos, bufsz - pos, "agg underrun: %u\n",
			 le32_to_cpu(tx->agg.underrun));
	pos += scnprintf(buf + pos, bufsz - pos, "agg bt_prio_kill: %u\n",
			 le32_to_cpu(tx->agg.bt_prio_kill));
	pos += scnprintf(buf + pos, bufsz - pos, "agg rx_ba_rsp_cnt: %u\n",
			 le32_to_cpu(tx->agg.rx_ba_rsp_cnt));

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

static ssize_t iwl_dbgfs_ucode_general_stats_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;
	char *buf;
	int bufsz = sizeof(struct statistics_general) * 4 + 250;
	ssize_t ret;
	struct statistics_general *general;
	struct statistics_dbg *dbg;
	struct statistics_div *div;

	if (!iwl_is_alive(priv))
		return -EAGAIN;

	/* make request to uCode to retrieve statistics information */
	mutex_lock(&priv->mutex);
	ret = iwl_send_statistics_request(priv, 0);
	mutex_unlock(&priv->mutex);

	if (ret) {
		IWL_ERR(priv,
			"Error sending statistics request: %zd\n", ret);
		return -EAGAIN;
	}
	buf = kzalloc(bufsz, GFP_KERNEL);
	if (!buf) {
		IWL_ERR(priv, "Can not allocate Buffer\n");
		return -ENOMEM;
	}

	/* the statistic information display here is based on
	 * the last statistics notification from uCode
	 * might not reflect the current uCode activity
	 */
	general = &priv->statistics.general;
	dbg = &priv->statistics.general.dbg;
	div = &priv->statistics.general.div;
	pos += iwl_dbgfs_statistics_flag(priv, buf, bufsz);
	pos += scnprintf(buf + pos, bufsz - pos, "Statistics_General:\n");
	pos += scnprintf(buf + pos, bufsz - pos, "temperature: %u\n",
			 le32_to_cpu(general->temperature));
	pos += scnprintf(buf + pos, bufsz - pos, "temperature_m: %u\n",
			 le32_to_cpu(general->temperature_m));
	pos += scnprintf(buf + pos, bufsz - pos, "burst_check: %u\n",
			 le32_to_cpu(dbg->burst_check));
	pos += scnprintf(buf + pos, bufsz - pos, "burst_count: %u\n",
			 le32_to_cpu(dbg->burst_count));
	pos += scnprintf(buf + pos, bufsz - pos, "sleep_time: %u\n",
			 le32_to_cpu(general->sleep_time));
	pos += scnprintf(buf + pos, bufsz - pos, "slots_out: %u\n",
			 le32_to_cpu(general->slots_out));
	pos += scnprintf(buf + pos, bufsz - pos, "slots_idle: %u\n",
			 le32_to_cpu(general->slots_idle));
	pos += scnprintf(buf + pos, bufsz - pos, "ttl_timestamp: %u\n",
			 le32_to_cpu(general->ttl_timestamp));
	pos += scnprintf(buf + pos, bufsz - pos, "tx_on_a: %u\n",
			 le32_to_cpu(div->tx_on_a));
	pos += scnprintf(buf + pos, bufsz - pos, "tx_on_b: %u\n",
			 le32_to_cpu(div->tx_on_b));
	pos += scnprintf(buf + pos, bufsz - pos, "exec_time: %u\n",
			 le32_to_cpu(div->exec_time));
	pos += scnprintf(buf + pos, bufsz - pos, "probe_time: %u\n",
			 le32_to_cpu(div->probe_time));
	pos += scnprintf(buf + pos, bufsz - pos, "rx_enable_counter: %u\n",
			 le32_to_cpu(general->rx_enable_counter));
	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	kfree(buf);
	return ret;
}

1349 1350
DEBUGFS_READ_WRITE_FILE_OPS(rx_statistics);
DEBUGFS_READ_WRITE_FILE_OPS(tx_statistics);
1351
DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
1352 1353
DEBUGFS_READ_FILE_OPS(rx_queue);
DEBUGFS_READ_FILE_OPS(tx_queue);
1354 1355 1356
DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
DEBUGFS_READ_FILE_OPS(ucode_general_stats);
1357

T
Tomas Winkler 已提交
1358 1359 1360 1361 1362 1363 1364
/*
 * Create the debugfs files and directories
 *
 */
int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
{
	struct iwl_debugfs *dbgfs;
1365
	struct dentry *phyd = priv->hw->wiphy->debugfsdir;
1366
	int ret = 0;
T
Tomas Winkler 已提交
1367 1368 1369

	dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
	if (!dbgfs) {
1370
		ret = -ENOMEM;
T
Tomas Winkler 已提交
1371 1372 1373 1374 1375
		goto err;
	}

	priv->dbgfs = dbgfs;
	dbgfs->name = name;
1376
	dbgfs->dir_drv = debugfs_create_dir(name, phyd);
1377 1378
	if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)) {
		ret = -ENOENT;
T
Tomas Winkler 已提交
1379 1380 1381 1382
		goto err;
	}

	DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
1383
	DEBUGFS_ADD_DIR(rf, dbgfs->dir_drv);
1384
	DEBUGFS_ADD_DIR(debug, dbgfs->dir_drv);
1385
	DEBUGFS_ADD_FILE(nvm, data);
T
Tomas Winkler 已提交
1386
	DEBUGFS_ADD_FILE(sram, data);
1387
	DEBUGFS_ADD_FILE(log_event, data);
T
Tomas Winkler 已提交
1388
	DEBUGFS_ADD_FILE(stations, data);
1389
	DEBUGFS_ADD_FILE(channels, data);
1390
	DEBUGFS_ADD_FILE(status, data);
1391
	DEBUGFS_ADD_FILE(interrupt, data);
W
Wey-Yi Guy 已提交
1392
	DEBUGFS_ADD_FILE(qos, data);
W
Wey-Yi Guy 已提交
1393 1394 1395
#ifdef CONFIG_IWLWIFI_LEDS
	DEBUGFS_ADD_FILE(led, data);
#endif
1396
	DEBUGFS_ADD_FILE(thermal_throttling, data);
1397
	DEBUGFS_ADD_FILE(disable_ht40, data);
1398 1399
	DEBUGFS_ADD_FILE(rx_statistics, debug);
	DEBUGFS_ADD_FILE(tx_statistics, debug);
1400
	DEBUGFS_ADD_FILE(traffic_log, debug);
1401 1402
	DEBUGFS_ADD_FILE(rx_queue, debug);
	DEBUGFS_ADD_FILE(tx_queue, debug);
1403 1404 1405 1406 1407
	if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) != CSR_HW_REV_TYPE_3945) {
		DEBUGFS_ADD_FILE(ucode_rx_stats, debug);
		DEBUGFS_ADD_FILE(ucode_tx_stats, debug);
		DEBUGFS_ADD_FILE(ucode_general_stats, debug);
	}
1408 1409 1410
	DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal);
	DEBUGFS_ADD_BOOL(disable_chain_noise, rf,
			 &priv->disable_chain_noise_cal);
1411 1412 1413 1414
	if (((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965) ||
	    ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_3945))
		DEBUGFS_ADD_BOOL(disable_tx_power, rf,
				&priv->disable_tx_power_cal);
T
Tomas Winkler 已提交
1415 1416 1417
	return 0;

err:
1418
	IWL_ERR(priv, "Can't open the debugfs directory\n");
T
Tomas Winkler 已提交
1419
	iwl_dbgfs_unregister(priv);
1420
	return ret;
T
Tomas Winkler 已提交
1421 1422 1423 1424 1425 1426 1427 1428 1429
}
EXPORT_SYMBOL(iwl_dbgfs_register);

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

1433
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_nvm);
T
Tomas Winkler 已提交
1434
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
1435
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_log_event);
T
Tomas Winkler 已提交
1436
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
1437
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_channels);
1438
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_status);
1439
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_interrupt);
W
Wey-Yi Guy 已提交
1440
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_qos);
W
Wey-Yi Guy 已提交
1441 1442 1443
#ifdef CONFIG_IWLWIFI_LEDS
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_led);
#endif
1444
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_thermal_throttling);
1445
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_disable_ht40);
T
Tomas Winkler 已提交
1446
	DEBUGFS_REMOVE(priv->dbgfs->dir_data);
1447 1448
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_rx_statistics);
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_tx_statistics);
1449
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_traffic_log);
1450 1451
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_rx_queue);
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_tx_queue);
1452 1453 1454 1455 1456 1457 1458 1459
	if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) != CSR_HW_REV_TYPE_3945) {
		DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
			file_ucode_rx_stats);
		DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
			file_ucode_tx_stats);
		DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
			file_ucode_general_stats);
	}
1460
	DEBUGFS_REMOVE(priv->dbgfs->dir_debug);
1461 1462
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity);
	DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise);
1463 1464 1465
	if (((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965) ||
	    ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_3945))
		DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_tx_power);
1466
	DEBUGFS_REMOVE(priv->dbgfs->dir_rf);
T
Tomas Winkler 已提交
1467 1468 1469 1470 1471 1472 1473
	DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
	kfree(priv->dbgfs);
	priv->dbgfs = NULL;
}
EXPORT_SYMBOL(iwl_dbgfs_unregister);


1474