iwl-debugfs.c 53.1 KB
Newer Older
T
Tomas Winkler 已提交
1 2 3 4
/******************************************************************************
 *
 * GPL LICENSE SUMMARY
 *
5
 * Copyright(c) 2008 - 2010 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
 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
 *****************************************************************************/

29
#include <linux/slab.h>
T
Tomas Winkler 已提交
30 31 32 33 34 35 36 37
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/debugfs.h>

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


38
#include "iwl-dev.h"
T
Tomas Winkler 已提交
39
#include "iwl-debug.h"
40
#include "iwl-core.h"
41
#include "iwl-io.h"
T
Tomas Winkler 已提交
42 43

/* create and remove of files */
J
Johannes Berg 已提交
44 45 46 47
#define DEBUGFS_ADD_FILE(name, parent, mode) do {			\
	if (!debugfs_create_file(#name, mode, parent, priv,		\
				 &iwl_dbgfs_##name##_ops))		\
		goto err;						\
T
Tomas Winkler 已提交
48 49
} while (0)

J
Johannes Berg 已提交
50 51 52 53 54 55
#define DEBUGFS_ADD_BOOL(name, parent, ptr) do {			\
	struct dentry *__tmp;						\
	__tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR,		\
				    parent, ptr);			\
	if (IS_ERR(__tmp) || !__tmp)					\
		goto err;						\
T
Tomas Winkler 已提交
56 57
} while (0)

J
Johannes Berg 已提交
58 59 60 61 62 63
#define DEBUGFS_ADD_X32(name, parent, ptr) do {				\
	struct dentry *__tmp;						\
	__tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR,		\
				   parent, ptr);			\
	if (IS_ERR(__tmp) || !__tmp)					\
		goto err;						\
64 65
} while (0)

T
Tomas Winkler 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
/* 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,                    	\
89
	.llseek = generic_file_llseek,					\
T
Tomas Winkler 已提交
90 91
};

92 93 94 95 96
#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,                    	\
97
	.llseek = generic_file_llseek,					\
98 99 100
};


T
Tomas Winkler 已提交
101 102 103 104 105 106 107
#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,                            \
108
	.llseek = generic_file_llseek,					\
T
Tomas Winkler 已提交
109 110 111 112 113 114
};

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

115
	struct iwl_priv *priv = file->private_data;
116
	char *buf;
T
Tomas Winkler 已提交
117 118
	int pos = 0;

119 120
	int cnt;
	ssize_t ret;
121 122
	const size_t bufsz = 100 +
		sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
123 124 125 126 127 128
	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,
129
				 "\t%25s\t\t: %u\n",
130 131 132 133 134 135
				 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,
136
				 "\t%25s\t\t: %u\n",
137 138 139 140 141 142 143 144 145 146 147 148 149
				 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;
}

150
static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
151 152 153 154 155 156 157
					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 已提交
158

159 160 161 162 163 164
	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;
165
	iwl_clear_traffic_stats(priv);
166 167

	return count;
T
Tomas Winkler 已提交
168 169 170 171 172 173
}

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

174
	struct iwl_priv *priv = file->private_data;
175
	char *buf;
T
Tomas Winkler 已提交
176
	int pos = 0;
177 178 179
	int cnt;
	ssize_t ret;
	const size_t bufsz = 100 +
180
		sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
181 182 183
	buf = kzalloc(bufsz, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;
T
Tomas Winkler 已提交
184

185 186 187
	pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
	for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
		pos += scnprintf(buf + pos, bufsz - pos,
188
				 "\t%25s\t\t: %u\n",
189 190 191 192 193 194
				 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,
195
				 "\t%25s\t\t: %u\n",
196 197 198 199 200 201 202 203
				 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 已提交
204

205 206 207 208 209
	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	kfree(buf);
	return ret;
}

T
Tomas Winkler 已提交
210 211 212 213 214 215 216 217
#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;
218
	char *buf;
T
Tomas Winkler 已提交
219 220 221
	ssize_t ret;
	int i;
	int pos = 0;
222
	struct iwl_priv *priv = file->private_data;
223
	size_t bufsz;
T
Tomas Winkler 已提交
224

225
	/* default is to dump the entire data segment */
J
Johannes Berg 已提交
226 227
	if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
		priv->dbgfs_sram_offset = 0x800000;
228
		if (priv->ucode_type == UCODE_INIT)
J
Johannes Berg 已提交
229
			priv->dbgfs_sram_len = priv->ucode_init_data.len;
230
		else
J
Johannes Berg 已提交
231
			priv->dbgfs_sram_len = priv->ucode_data.len;
232
	}
J
Johannes Berg 已提交
233
	bufsz =  30 + priv->dbgfs_sram_len * sizeof(char) * 10;
234 235 236
	buf = kmalloc(bufsz, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;
237
	pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
J
Johannes Berg 已提交
238
			priv->dbgfs_sram_len);
239
	pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
J
Johannes Berg 已提交
240 241 242 243
			priv->dbgfs_sram_offset);
	for (i = priv->dbgfs_sram_len; i > 0; i -= 4) {
		val = iwl_read_targ_mem(priv, priv->dbgfs_sram_offset + \
					priv->dbgfs_sram_len - i);
T
Tomas Winkler 已提交
244 245 246 247 248 249 250 251 252 253 254 255 256
		if (i < 4) {
			switch (i) {
			case 1:
				val &= BYTE1_MASK;
				break;
			case 2:
				val &= BYTE2_MASK;
				break;
			case 3:
				val &= BYTE3_MASK;
				break;
			}
		}
257 258
		if (!(i % 16))
			pos += scnprintf(buf + pos, bufsz - pos, "\n");
259
		pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
T
Tomas Winkler 已提交
260
	}
261
	pos += scnprintf(buf + pos, bufsz - pos, "\n");
T
Tomas Winkler 已提交
262 263

	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
264
	kfree(buf);
T
Tomas Winkler 已提交
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
	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) {
J
Johannes Berg 已提交
283 284
		priv->dbgfs_sram_offset = offset;
		priv->dbgfs_sram_len = len;
T
Tomas Winkler 已提交
285
	} else {
J
Johannes Berg 已提交
286 287
		priv->dbgfs_sram_offset = 0;
		priv->dbgfs_sram_len = 0;
T
Tomas Winkler 已提交
288 289 290 291 292 293 294 295
	}

	return count;
}

static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
					size_t count, loff_t *ppos)
{
296
	struct iwl_priv *priv = file->private_data;
297
	struct iwl_station_entry *station;
T
Tomas Winkler 已提交
298
	int max_sta = priv->hw_params.max_stations;
T
Tomas Winkler 已提交
299 300 301 302 303 304 305
	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);
306
	if (!buf)
T
Tomas Winkler 已提交
307 308
		return -ENOMEM;

309
	pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
T
Tomas Winkler 已提交
310 311 312 313
			priv->num_stations);

	for (i = 0; i < max_sta; i++) {
		station = &priv->stations[i];
J
Johannes Berg 已提交
314 315 316 317 318 319 320 321 322 323
		if (!station->used)
			continue;
		pos += scnprintf(buf + pos, bufsz - pos,
				 "station %d - addr: %pM, flags: %#x\n",
				 i, station->sta.sta.addr,
				 station->sta.station_flags_msk);
		pos += scnprintf(buf + pos, bufsz - pos,
				"TID\tseq_num\ttxq_id\tframes\ttfds\t");
		pos += scnprintf(buf + pos, bufsz - pos,
				"start_idx\tbitmap\t\t\trate_n_flags\n");
T
Tomas Winkler 已提交
324

J
Johannes Berg 已提交
325 326 327 328 329 330 331 332 333 334 335 336
		for (j = 0; j < MAX_TID_COUNT; j++) {
			pos += scnprintf(buf + pos, bufsz - pos,
				"%d:\t%#x\t%#x\t%u\t%u\t%u\t\t%#.16llx\t%#x",
				j, station->tid[j].seq_number,
				station->tid[j].agg.txq_id,
				station->tid[j].agg.frame_count,
				station->tid[j].tfds_in_queue,
				station->tid[j].agg.start_idx,
				station->tid[j].agg.bitmap,
				station->tid[j].agg.rate_n_flags);

			if (station->tid[j].agg.wait_for_ba)
337
				pos += scnprintf(buf + pos, bufsz - pos,
J
Johannes Berg 已提交
338
						 " - waitforba");
339
			pos += scnprintf(buf + pos, bufsz - pos, "\n");
T
Tomas Winkler 已提交
340
		}
J
Johannes Berg 已提交
341 342

		pos += scnprintf(buf + pos, bufsz - pos, "\n");
T
Tomas Winkler 已提交
343 344 345 346 347 348 349
	}

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

350
static ssize_t iwl_dbgfs_nvm_read(struct file *file,
T
Tomas Winkler 已提交
351 352 353 354 355
				       char __user *user_buf,
				       size_t count,
				       loff_t *ppos)
{
	ssize_t ret;
356
	struct iwl_priv *priv = file->private_data;
T
Tomas Winkler 已提交
357 358 359
	int pos = 0, ofs = 0, buf_size = 0;
	const u8 *ptr;
	char *buf;
W
Wey-Yi Guy 已提交
360
	u16 eeprom_ver;
361
	size_t eeprom_len = priv->cfg->base_params->eeprom_size;
T
Tomas Winkler 已提交
362 363 364
	buf_size = 4 * eeprom_len + 256;

	if (eeprom_len % 16) {
365
		IWL_ERR(priv, "NVM size is not multiple of 16.\n");
T
Tomas Winkler 已提交
366 367 368
		return -ENODATA;
	}

369 370 371 372 373 374
	ptr = priv->eeprom;
	if (!ptr) {
		IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
		return -ENOMEM;
	}

T
Tomas Winkler 已提交
375 376 377
	/* 4 characters for byte 0xYY */
	buf = kzalloc(buf_size, GFP_KERNEL);
	if (!buf) {
378
		IWL_ERR(priv, "Can not allocate Buffer\n");
T
Tomas Winkler 已提交
379 380
		return -ENOMEM;
	}
W
Wey-Yi Guy 已提交
381 382 383
	eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
	pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
			"version: 0x%x\n",
384
			(priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
W
Wey-Yi Guy 已提交
385
			 ? "OTP" : "EEPROM", eeprom_ver);
T
Tomas Winkler 已提交
386 387 388 389
	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);
390
		pos += strlen(buf + pos);
T
Tomas Winkler 已提交
391 392 393 394 395 396 397 398
		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 已提交
399

W
Wey-Yi Guy 已提交
400 401 402 403 404 405 406 407 408
static ssize_t iwl_dbgfs_log_event_read(struct file *file,
					 char __user *user_buf,
					 size_t count, loff_t *ppos)
{
	struct iwl_priv *priv = file->private_data;
	char *buf;
	int pos = 0;
	ssize_t ret = -ENOMEM;

409 410 411
	ret = pos = priv->cfg->ops->lib->dump_nic_event_log(
					priv, true, &buf, true);
	if (buf) {
W
Wey-Yi Guy 已提交
412 413 414 415 416 417
		ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
		kfree(buf);
	}
	return ret;
}

418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
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)
W
Wey-Yi Guy 已提交
434 435
		priv->cfg->ops->lib->dump_nic_event_log(priv, true,
							NULL, false);
436 437 438 439

	return count;
}

440 441 442 443 444


static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
				       size_t count, loff_t *ppos)
{
445
	struct iwl_priv *priv = file->private_data;
446 447 448 449 450 451 452 453 454 455 456
	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) {
457
		IWL_ERR(priv, "Can not allocate Buffer\n");
458 459 460 461
		return -ENOMEM;
	}

	supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
462 463
	if (supp_band) {
		channels = supp_band->channels;
464 465

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

469 470 471
		for (i = 0; i < supp_band->n_channels; i++)
			pos += scnprintf(buf + pos, bufsz - pos,
					"%d: %ddBm: BSS%s%s, %s.\n",
472
					channels[i].hw_value,
473 474 475 476 477 478 479 480 481 482 483
					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");
	}
484
	supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
485 486
	if (supp_band) {
		channels = supp_band->channels;
487 488

		pos += scnprintf(buf + pos, bufsz - pos,
489 490 491 492 493 494
				"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",
495
					channels[i].hw_value,
496 497 498 499 500 501 502 503 504 505 506
					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");
	}
507 508 509 510 511
	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	kfree(buf);
	return ret;
}

512 513 514 515
static ssize_t iwl_dbgfs_status_read(struct file *file,
						char __user *user_buf,
						size_t count, loff_t *ppos) {

516
	struct iwl_priv *priv = file->private_data;
517 518 519 520 521 522 523 524 525 526
	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_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));
527 528
	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
		test_bit(STATUS_CT_KILL, &priv->status));
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
	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));
	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
}

556 557 558 559
static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
					char __user *user_buf,
					size_t count, loff_t *ppos) {

560
	struct iwl_priv *priv = file->private_data;
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
	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);
580
	if (priv->isr_stats.sw || priv->isr_stats.hw) {
581 582
		pos += scnprintf(buf + pos, bufsz - pos,
			"\tLast Restarting Code:  0x%X\n",
583
			priv->isr_stats.err_code);
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
	}
#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 已提交
644 645 646
static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
				       size_t count, loff_t *ppos)
{
647
	struct iwl_priv *priv = file->private_data;
J
Johannes Berg 已提交
648
	struct iwl_rxon_context *ctx;
W
Wey-Yi Guy 已提交
649
	int pos = 0, i;
J
Johannes Berg 已提交
650
	char buf[256 * NUM_IWL_RXON_CTX];
W
Wey-Yi Guy 已提交
651 652
	const size_t bufsz = sizeof(buf);

J
Johannes Berg 已提交
653 654 655 656 657 658 659
	for_each_context(priv, ctx) {
		pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
				 ctx->ctxid);
		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,
W
Wey-Yi Guy 已提交
660
				"AC[%d]\t%u\t%u\t%u\t%u\n", i,
J
Johannes Berg 已提交
661 662 663 664 665 666
				ctx->qos_data.def_qos_parm.ac[i].cw_min,
				ctx->qos_data.def_qos_parm.ac[i].cw_max,
				ctx->qos_data.def_qos_parm.ac[i].aifsn,
				ctx->qos_data.def_qos_parm.ac[i].edca_txop);
		}
		pos += scnprintf(buf + pos, bufsz - pos, "\n");
W
Wey-Yi Guy 已提交
667
	}
668
	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
W
Wey-Yi Guy 已提交
669
}
670

W
Wey-Yi Guy 已提交
671 672 673
static ssize_t iwl_dbgfs_led_read(struct file *file, char __user *user_buf,
				  size_t count, loff_t *ppos)
{
674
	struct iwl_priv *priv = file->private_data;
W
Wey-Yi Guy 已提交
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
	int pos = 0;
	char buf[256];
	const size_t bufsz = sizeof(buf);

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

691
	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
W
Wey-Yi Guy 已提交
692 693
}

694 695 696 697
static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
				char __user *user_buf,
				size_t count, loff_t *ppos)
{
698
	struct iwl_priv *priv = file->private_data;
699
	struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
700 701 702 703 704 705 706
	struct iwl_tt_restriction *restriction;
	char buf[100];
	int pos = 0;
	const size_t bufsz = sizeof(buf);

	pos += scnprintf(buf + pos, bufsz - pos,
			"Thermal Throttling Mode: %s\n",
707
			tt->advanced_tt ? "Advance" : "Legacy");
708 709 710
	pos += scnprintf(buf + pos, bufsz - pos,
			"Thermal Throttling State: %d\n",
			tt->state);
711
	if (tt->advanced_tt) {
712 713 714 715 716 717 718 719 720 721 722
		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);
	}
723
	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
724 725
}

726 727 728 729 730 731 732 733 734 735 736 737 738 739 740
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;
741
	if (!iwl_is_any_associated(priv))
742 743 744 745 746 747 748 749 750 751 752 753 754 755
		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)
{
756
	struct iwl_priv *priv = file->private_data;
757 758 759 760 761 762 763
	char buf[100];
	int pos = 0;
	const size_t bufsz = sizeof(buf);

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

767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788
static ssize_t iwl_dbgfs_sleep_level_override_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 value;

	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", &value) != 1)
		return -EINVAL;

	/*
	 * Our users expect 0 to be "CAM", but 0 isn't actually
	 * valid here. However, let's not confuse them and present
	 * IWL_POWER_INDEX_1 as "1", not "0".
	 */
789 790 791
	if (value == 0)
		return -EINVAL;
	else if (value > 0)
792 793 794 795 796
		value -= 1;

	if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
		return -EINVAL;

W
Wey-Yi Guy 已提交
797 798 799
	if (!iwl_is_ready_rf(priv))
		return -EAGAIN;

800 801
	priv->power_data.debug_sleep_level_override = value;

802
	mutex_lock(&priv->mutex);
W
Wey-Yi Guy 已提交
803
	iwl_power_update_mode(priv, true);
804
	mutex_unlock(&priv->mutex);
805 806 807 808 809 810 811 812

	return count;
}

static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
						   char __user *user_buf,
						   size_t count, loff_t *ppos)
{
813
	struct iwl_priv *priv = file->private_data;
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830
	char buf[10];
	int pos, value;
	const size_t bufsz = sizeof(buf);

	/* see the write function */
	value = priv->power_data.debug_sleep_level_override;
	if (value >= 0)
		value += 1;

	pos = scnprintf(buf, bufsz, "%d\n", value);
	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
}

static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
						    char __user *user_buf,
						    size_t count, loff_t *ppos)
{
831
	struct iwl_priv *priv = file->private_data;
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
	char buf[200];
	int pos = 0, i;
	const size_t bufsz = sizeof(buf);
	struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;

	pos += scnprintf(buf + pos, bufsz - pos,
			 "flags: %#.2x\n", le16_to_cpu(cmd->flags));
	pos += scnprintf(buf + pos, bufsz - pos,
			 "RX/TX timeout: %d/%d usec\n",
			 le32_to_cpu(cmd->rx_data_timeout),
			 le32_to_cpu(cmd->tx_data_timeout));
	for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
		pos += scnprintf(buf + pos, bufsz - pos,
				 "sleep_interval[%d]: %d\n", i,
				 le32_to_cpu(cmd->sleep_interval[i]));

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

T
Tomas Winkler 已提交
851
DEBUGFS_READ_WRITE_FILE_OPS(sram);
W
Wey-Yi Guy 已提交
852
DEBUGFS_READ_WRITE_FILE_OPS(log_event);
853
DEBUGFS_READ_FILE_OPS(nvm);
T
Tomas Winkler 已提交
854
DEBUGFS_READ_FILE_OPS(stations);
855
DEBUGFS_READ_FILE_OPS(channels);
856
DEBUGFS_READ_FILE_OPS(status);
857
DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
W
Wey-Yi Guy 已提交
858
DEBUGFS_READ_FILE_OPS(qos);
W
Wey-Yi Guy 已提交
859
DEBUGFS_READ_FILE_OPS(led);
860
DEBUGFS_READ_FILE_OPS(thermal_throttling);
861
DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
862 863
DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
DEBUGFS_READ_FILE_OPS(current_sleep_command);
T
Tomas Winkler 已提交
864

865 866 867 868 869 870 871 872 873 874 875 876
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) +
877
		(priv->cfg->base_params->num_of_queues * 32 * 8) + 400;
878 879 880
	const u8 *ptr;
	ssize_t ret;

881 882 883 884
	if (!priv->txq) {
		IWL_ERR(priv, "txq not ready\n");
		return -EAGAIN;
	}
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908
	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);
909
				pos += strlen(buf + pos);
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931
				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);
932
				pos += strlen(buf + pos);
933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964
				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;
}

965 966 967 968
static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
						char __user *user_buf,
						size_t count, loff_t *ppos) {

969
	struct iwl_priv *priv = file->private_data;
970 971 972 973 974 975
	struct iwl_tx_queue *txq;
	struct iwl_queue *q;
	char *buf;
	int pos = 0;
	int cnt;
	int ret;
976 977
	const size_t bufsz = sizeof(char) * 64 *
				priv->cfg->base_params->num_of_queues;
978

979 980 981 982
	if (!priv->txq) {
		IWL_ERR(priv, "txq not ready\n");
		return -EAGAIN;
	}
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
	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) {

1016
	struct iwl_priv *priv = file->private_data;
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
	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);
1028 1029
	if (rxq->rb_stts) {
		pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
1030
			 le16_to_cpu(rxq->rb_stts->closed_rb_num) &  0x0FFF);
1031 1032 1033 1034
	} else {
		pos += scnprintf(buf + pos, bufsz - pos,
					"closed_rb_num: Not Allocated\n");
	}
1035 1036 1037
	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
}

1038 1039 1040 1041
static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
					char __user *user_buf,
					size_t count, loff_t *ppos)
{
1042
	struct iwl_priv *priv = file->private_data;
A
Abhijeet Kolekar 已提交
1043 1044
	return priv->cfg->ops->lib->debugfs_ops.rx_stats_read(file,
			user_buf, count, ppos);
1045 1046 1047 1048 1049 1050
}

static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
					char __user *user_buf,
					size_t count, loff_t *ppos)
{
1051
	struct iwl_priv *priv = file->private_data;
A
Abhijeet Kolekar 已提交
1052 1053
	return priv->cfg->ops->lib->debugfs_ops.tx_stats_read(file,
			user_buf, count, ppos);
1054 1055 1056 1057 1058 1059
}

static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
					char __user *user_buf,
					size_t count, loff_t *ppos)
{
1060
	struct iwl_priv *priv = file->private_data;
A
Abhijeet Kolekar 已提交
1061 1062
	return priv->cfg->ops->lib->debugfs_ops.general_stats_read(file,
			user_buf, count, ppos);
1063 1064
}

1065 1066 1067 1068
static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
					char __user *user_buf,
					size_t count, loff_t *ppos) {

1069
	struct iwl_priv *priv = file->private_data;
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
	int pos = 0;
	int cnt = 0;
	char *buf;
	int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
	ssize_t ret;
	struct iwl_sensitivity_data *data;

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

	pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
			data->auto_corr_ofdm);
	pos += scnprintf(buf + pos, bufsz - pos,
			"auto_corr_ofdm_mrc:\t\t %u\n",
			data->auto_corr_ofdm_mrc);
	pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
			data->auto_corr_ofdm_x1);
	pos += scnprintf(buf + pos, bufsz - pos,
			"auto_corr_ofdm_mrc_x1:\t\t %u\n",
			data->auto_corr_ofdm_mrc_x1);
	pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
			data->auto_corr_cck);
	pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
			data->auto_corr_cck_mrc);
	pos += scnprintf(buf + pos, bufsz - pos,
			"last_bad_plcp_cnt_ofdm:\t\t %u\n",
			data->last_bad_plcp_cnt_ofdm);
	pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
			data->last_fa_cnt_ofdm);
	pos += scnprintf(buf + pos, bufsz - pos,
			"last_bad_plcp_cnt_cck:\t\t %u\n",
			data->last_bad_plcp_cnt_cck);
	pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
			data->last_fa_cnt_cck);
	pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
			data->nrg_curr_state);
	pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
			data->nrg_prev_state);
	pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
	for (cnt = 0; cnt < 10; cnt++) {
		pos += scnprintf(buf + pos, bufsz - pos, " %u",
				data->nrg_value[cnt]);
	}
	pos += scnprintf(buf + pos, bufsz - pos, "\n");
	pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
	for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
		pos += scnprintf(buf + pos, bufsz - pos, " %u",
				data->nrg_silence_rssi[cnt]);
	}
	pos += scnprintf(buf + pos, bufsz - pos, "\n");
	pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
			data->nrg_silence_ref);
	pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
			data->nrg_energy_idx);
	pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
			data->nrg_silence_idx);
	pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
			data->nrg_th_cck);
	pos += scnprintf(buf + pos, bufsz - pos,
			"nrg_auto_corr_silence_diff:\t %u\n",
			data->nrg_auto_corr_silence_diff);
	pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
			data->num_in_cck_no_fa);
	pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
			data->nrg_th_ofdm);

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


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

1150
	struct iwl_priv *priv = file->private_data;
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
	int pos = 0;
	int cnt = 0;
	char *buf;
	int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
	ssize_t ret;
	struct iwl_chain_noise_data *data;

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

	pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
			data->active_chains);
	pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
			data->chain_noise_a);
	pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
			data->chain_noise_b);
	pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
			data->chain_noise_c);
	pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
			data->chain_signal_a);
	pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
			data->chain_signal_b);
	pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
			data->chain_signal_c);
	pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
			data->beacon_count);

	pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
	for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
		pos += scnprintf(buf + pos, bufsz - pos, " %u",
				data->disconn_array[cnt]);
	}
	pos += scnprintf(buf + pos, bufsz - pos, "\n");
	pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
	for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
		pos += scnprintf(buf + pos, bufsz - pos, " %u",
				data->delta_gain_code[cnt]);
	}
	pos += scnprintf(buf + pos, bufsz - pos, "\n");
	pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
			data->radio_write);
	pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
			data->state);

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

1204 1205 1206 1207
static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
						    char __user *user_buf,
						    size_t count, loff_t *ppos)
{
1208
	struct iwl_priv *priv = file->private_data;
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226
	char buf[60];
	int pos = 0;
	const size_t bufsz = sizeof(buf);
	u32 pwrsave_status;

	pwrsave_status = iwl_read32(priv, CSR_GP_CNTRL) &
			CSR_GP_REG_POWER_SAVE_STATUS_MSK;

	pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
	pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
		(pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
		(pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
		(pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
		"error");

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

1227
static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250
					 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 clear;

	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", &clear) != 1)
		return -EFAULT;

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

	return count;
}

1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272
static ssize_t iwl_dbgfs_csr_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 csr;

	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", &csr) != 1)
		return -EFAULT;

	if (priv->cfg->ops->lib->dump_csr)
		priv->cfg->ops->lib->dump_csr(priv);

	return count;
}

1273 1274 1275 1276
static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
					char __user *user_buf,
					size_t count, loff_t *ppos) {

1277
	struct iwl_priv *priv = file->private_data;
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290
	int pos = 0;
	char buf[128];
	const size_t bufsz = sizeof(buf);

	pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
			priv->event_log.ucode_trace ? "On" : "Off");
	pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
			priv->event_log.non_wraps_count);
	pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
			priv->event_log.wraps_once_count);
	pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
			priv->event_log.wraps_more_count);

1291
	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
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
}

static ssize_t iwl_dbgfs_ucode_tracing_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 trace;

	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", &trace) != 1)
		return -EFAULT;

	if (trace) {
		priv->event_log.ucode_trace = true;
		/* schedule the ucode timer to occur in UCODE_TRACE_PERIOD */
		mod_timer(&priv->ucode_trace,
			jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
	} else {
		priv->event_log.ucode_trace = false;
		del_timer_sync(&priv->ucode_trace);
	}

	return count;
}

1323 1324 1325 1326
static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
					 char __user *user_buf,
					 size_t count, loff_t *ppos) {

1327
	struct iwl_priv *priv = file->private_data;
1328 1329 1330
	int len = 0;
	char buf[20];

1331 1332
	len = sprintf(buf, "0x%04X\n",
		le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.flags));
1333 1334 1335 1336 1337 1338 1339
	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
}

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

1340
	struct iwl_priv *priv = file->private_data;
1341 1342 1343 1344
	int len = 0;
	char buf[20];

	len = sprintf(buf, "0x%04X\n",
1345
		le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags));
1346 1347 1348
	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
}

1349 1350 1351 1352
static ssize_t iwl_dbgfs_fh_reg_read(struct file *file,
					 char __user *user_buf,
					 size_t count, loff_t *ppos)
{
1353
	struct iwl_priv *priv = file->private_data;
1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369
	char *buf;
	int pos = 0;
	ssize_t ret = -EFAULT;

	if (priv->cfg->ops->lib->dump_fh) {
		ret = pos = priv->cfg->ops->lib->dump_fh(priv, &buf, true);
		if (buf) {
			ret = simple_read_from_buffer(user_buf,
						      count, ppos, buf, pos);
			kfree(buf);
		}
	}

	return ret;
}

1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381
static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
					char __user *user_buf,
					size_t count, loff_t *ppos) {

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

	pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
			priv->missed_beacon_threshold);

1382
	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410
}

static ssize_t iwl_dbgfs_missed_beacon_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 missed;

	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", &missed) != 1)
		return -EINVAL;

	if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
	    missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
		priv->missed_beacon_threshold =
			IWL_MISSED_BEACON_THRESHOLD_DEF;
	else
		priv->missed_beacon_threshold = missed;

	return count;
}

1411 1412 1413 1414
static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
					char __user *user_buf,
					size_t count, loff_t *ppos) {

1415
	struct iwl_priv *priv = file->private_data;
1416 1417 1418 1419 1420
	int pos = 0;
	char buf[12];
	const size_t bufsz = sizeof(buf);

	pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
1421
			priv->cfg->base_params->plcp_delta_threshold);
1422

1423
	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440
}

static ssize_t iwl_dbgfs_plcp_delta_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 plcp;

	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", &plcp) != 1)
		return -EINVAL;
1441
	if ((plcp < IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
1442
		(plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
1443
		priv->cfg->base_params->plcp_delta_threshold =
1444
			IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE;
1445
	else
1446
		priv->cfg->base_params->plcp_delta_threshold = plcp;
1447 1448 1449
	return count;
}

1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479
static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
					char __user *user_buf,
					size_t count, loff_t *ppos) {

	struct iwl_priv *priv = file->private_data;
	int i, pos = 0;
	char buf[300];
	const size_t bufsz = sizeof(buf);
	struct iwl_force_reset *force_reset;

	for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
		force_reset = &priv->force_reset[i];
		pos += scnprintf(buf + pos, bufsz - pos,
				"Force reset method %d\n", i);
		pos += scnprintf(buf + pos, bufsz - pos,
				"\tnumber of reset request: %d\n",
				force_reset->reset_request_count);
		pos += scnprintf(buf + pos, bufsz - pos,
				"\tnumber of reset request success: %d\n",
				force_reset->reset_success_count);
		pos += scnprintf(buf + pos, bufsz - pos,
				"\tnumber of reset request reject: %d\n",
				force_reset->reset_reject_count);
		pos += scnprintf(buf + pos, bufsz - pos,
				"\treset duration: %lu\n",
				force_reset->reset_duration);
	}
	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
}

1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497
static ssize_t iwl_dbgfs_force_reset_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 reset, ret;

	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", &reset) != 1)
		return -EINVAL;
	switch (reset) {
	case IWL_RF_RESET:
	case IWL_FW_RESET:
1498
		ret = iwl_force_reset(priv, reset, true);
1499 1500 1501 1502 1503 1504 1505
		break;
	default:
		return -EINVAL;
	}
	return ret ? ret : count;
}

1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529
static ssize_t iwl_dbgfs_txfifo_flush_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 flush;

	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", &flush) != 1)
		return -EINVAL;

	if (iwl_is_rfkill(priv))
		return -EFAULT;

	priv->cfg->ops->lib->dev_txfifo_flush(priv, IWL_DROP_ALL);

	return count;
}

1530 1531 1532 1533 1534 1535 1536 1537 1538 1539
static ssize_t iwl_dbgfs_ucode_bt_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;

	return priv->cfg->ops->lib->debugfs_ops.bt_stats_read(file,
			user_buf, count, ppos);
}

1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555
static ssize_t iwl_dbgfs_monitor_period_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 period;

	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", &period) != 1)
		return -EINVAL;
	if (period < 0 || period > IWL_MAX_MONITORING_PERIOD)
1556 1557
		priv->cfg->base_params->monitor_recover_period =
			IWL_DEF_MONITORING_PERIOD;
1558
	else
1559
		priv->cfg->base_params->monitor_recover_period = period;
1560

1561
	if (priv->cfg->base_params->monitor_recover_period)
1562
		mod_timer(&priv->monitor_recover, jiffies + msecs_to_jiffies(
1563
			  priv->cfg->base_params->monitor_recover_period));
1564 1565 1566 1567 1568
	else
		del_timer_sync(&priv->monitor_recover);
	return count;
}

1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610
static ssize_t iwl_dbgfs_bt_traffic_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[200];
	const size_t bufsz = sizeof(buf);
	ssize_t ret;

	pos += scnprintf(buf + pos, bufsz - pos, "BT in %s mode\n",
		priv->bt_full_concurrent ? "full concurrency" : "3-wire");
	pos += scnprintf(buf + pos, bufsz - pos, "BT status: %s, "
			 "last traffic notif: %d\n",
		priv->bt_status ? "On" : "Off", priv->notif_bt_traffic_load);
	pos += scnprintf(buf + pos, bufsz - pos, "ch_announcement: %d, "
			 "sco_active: %d, kill_ack_mask: %x, "
			 "kill_cts_mask: %x\n",
		priv->bt_ch_announce, priv->bt_sco_active,
		priv->kill_ack_mask, priv->kill_cts_mask);

	pos += scnprintf(buf + pos, bufsz - pos, "bluetooth traffic load: ");
	switch (priv->bt_traffic_load) {
	case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
		pos += scnprintf(buf + pos, bufsz - pos, "Continuous\n");
		break;
	case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
		pos += scnprintf(buf + pos, bufsz - pos, "High\n");
		break;
	case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
		pos += scnprintf(buf + pos, bufsz - pos, "Low\n");
		break;
	case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
	default:
		pos += scnprintf(buf + pos, bufsz - pos, "None\n");
		break;
	}

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

1611 1612 1613 1614 1615 1616 1617 1618 1619 1620
static ssize_t iwl_dbgfs_protection_mode_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[40];
	const size_t bufsz = sizeof(buf);

1621 1622 1623 1624 1625 1626 1627 1628
	if (priv->cfg->ht_params)
		pos += scnprintf(buf + pos, bufsz - pos,
			 "use %s for aggregation\n",
			 (priv->cfg->ht_params->use_rts_for_aggregation) ?
				"rts/cts" : "cts-to-self");
	else
		pos += scnprintf(buf + pos, bufsz - pos, "N/A");

1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640
	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
}

static ssize_t iwl_dbgfs_protection_mode_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 rts;

1641 1642 1643
	if (!priv->cfg->ht_params)
		return -EINVAL;

1644 1645 1646 1647 1648 1649 1650
	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", &rts) != 1)
		return -EINVAL;
	if (rts)
1651
		priv->cfg->ht_params->use_rts_for_aggregation = true;
1652
	else
1653
		priv->cfg->ht_params->use_rts_for_aggregation = false;
1654 1655 1656
	return count;
}

1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668
static ssize_t iwl_dbgfs_reply_tx_error_read(struct file *file,
					char __user *user_buf,
					size_t count, loff_t *ppos)
{
	struct iwl_priv *priv = file->private_data;

	if (priv->cfg->ops->lib->debugfs_ops.reply_tx_error)
		return priv->cfg->ops->lib->debugfs_ops.reply_tx_error(
			file, user_buf, count, ppos);
	else
		return -ENODATA;
}
1669 1670
DEBUGFS_READ_FILE_OPS(rx_statistics);
DEBUGFS_READ_FILE_OPS(tx_statistics);
1671
DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
1672 1673
DEBUGFS_READ_FILE_OPS(rx_queue);
DEBUGFS_READ_FILE_OPS(tx_queue);
1674 1675 1676
DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
DEBUGFS_READ_FILE_OPS(ucode_general_stats);
1677 1678
DEBUGFS_READ_FILE_OPS(sensitivity);
DEBUGFS_READ_FILE_OPS(chain_noise);
1679
DEBUGFS_READ_FILE_OPS(power_save_status);
1680 1681
DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
1682
DEBUGFS_WRITE_FILE_OPS(csr);
1683
DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
1684
DEBUGFS_READ_FILE_OPS(fh_reg);
1685
DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
1686
DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
1687
DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
1688 1689
DEBUGFS_READ_FILE_OPS(rxon_flags);
DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
1690
DEBUGFS_WRITE_FILE_OPS(txfifo_flush);
1691
DEBUGFS_READ_FILE_OPS(ucode_bt_stats);
1692
DEBUGFS_WRITE_FILE_OPS(monitor_period);
1693
DEBUGFS_READ_FILE_OPS(bt_traffic);
1694
DEBUGFS_READ_WRITE_FILE_OPS(protection_mode);
1695
DEBUGFS_READ_FILE_OPS(reply_tx_error);
1696

T
Tomas Winkler 已提交
1697 1698 1699 1700 1701 1702
/*
 * Create the debugfs files and directories
 *
 */
int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
{
1703
	struct dentry *phyd = priv->hw->wiphy->debugfsdir;
J
Johannes Berg 已提交
1704
	struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
T
Tomas Winkler 已提交
1705

J
Johannes Berg 已提交
1706 1707 1708
	dir_drv = debugfs_create_dir(name, phyd);
	if (!dir_drv)
		return -ENOMEM;
T
Tomas Winkler 已提交
1709

J
Johannes Berg 已提交
1710 1711 1712 1713 1714 1715 1716 1717 1718 1719
	priv->debugfs_dir = dir_drv;

	dir_data = debugfs_create_dir("data", dir_drv);
	if (!dir_data)
		goto err;
	dir_rf = debugfs_create_dir("rf", dir_drv);
	if (!dir_rf)
		goto err;
	dir_debug = debugfs_create_dir("debug", dir_drv);
	if (!dir_debug)
T
Tomas Winkler 已提交
1720 1721
		goto err;

J
Johannes Berg 已提交
1722 1723 1724 1725 1726 1727 1728 1729 1730
	DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
	DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
	DEBUGFS_ADD_FILE(log_event, dir_data, S_IWUSR | S_IRUSR);
	DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
	DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
	DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
	DEBUGFS_ADD_FILE(interrupt, dir_data, S_IWUSR | S_IRUSR);
	DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
	DEBUGFS_ADD_FILE(led, dir_data, S_IRUSR);
1731
	if (!priv->cfg->base_params->broken_powersave) {
1732 1733 1734 1735
		DEBUGFS_ADD_FILE(sleep_level_override, dir_data,
				 S_IWUSR | S_IRUSR);
		DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
	}
J
Johannes Berg 已提交
1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749
	DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
	DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
	DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR);
	DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR);
	DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
	DEBUGFS_ADD_FILE(rx_queue, dir_debug, S_IRUSR);
	DEBUGFS_ADD_FILE(tx_queue, dir_debug, S_IRUSR);
	DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
	DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
	DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
	DEBUGFS_ADD_FILE(csr, dir_debug, S_IWUSR);
	DEBUGFS_ADD_FILE(fh_reg, dir_debug, S_IRUSR);
	DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
	DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
1750
	DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
1751 1752 1753
	DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
	DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
	DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
1754 1755
	if (priv->cfg->ops->lib->dev_txfifo_flush)
		DEBUGFS_ADD_FILE(txfifo_flush, dir_debug, S_IWUSR);
1756
	DEBUGFS_ADD_FILE(protection_mode, dir_debug, S_IWUSR | S_IRUSR);
1757

1758
	if (priv->cfg->base_params->sensitivity_calib_by_driver)
J
Johannes Berg 已提交
1759
		DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
1760
	if (priv->cfg->base_params->chain_noise_calib_by_driver)
J
Johannes Berg 已提交
1761
		DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
1762
	if (priv->cfg->base_params->ucode_tracing)
J
Johannes Berg 已提交
1763
		DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
1764
	if (priv->cfg->bt_params && priv->cfg->bt_params->bt_statistics)
1765
		DEBUGFS_ADD_FILE(ucode_bt_stats, dir_debug, S_IRUSR);
1766
	DEBUGFS_ADD_FILE(reply_tx_error, dir_debug, S_IRUSR);
1767 1768
	DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
	DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
1769
	DEBUGFS_ADD_FILE(monitor_period, dir_debug, S_IWUSR);
1770
	if (priv->cfg->bt_params && priv->cfg->bt_params->advanced_bt_coexist)
1771
		DEBUGFS_ADD_FILE(bt_traffic, dir_debug, S_IRUSR);
1772
	if (priv->cfg->base_params->sensitivity_calib_by_driver)
1773 1774
		DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
				 &priv->disable_sens_cal);
1775
	if (priv->cfg->base_params->chain_noise_calib_by_driver)
1776 1777
		DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
				 &priv->disable_chain_noise_cal);
1778
	if (priv->cfg->base_params->tx_power_by_driver)
J
Johannes Berg 已提交
1779
		DEBUGFS_ADD_BOOL(disable_tx_power, dir_rf,
1780
				&priv->disable_tx_power_cal);
T
Tomas Winkler 已提交
1781 1782 1783
	return 0;

err:
J
Johannes Berg 已提交
1784
	IWL_ERR(priv, "Can't create the debugfs directory\n");
T
Tomas Winkler 已提交
1785
	iwl_dbgfs_unregister(priv);
J
Johannes Berg 已提交
1786
	return -ENOMEM;
T
Tomas Winkler 已提交
1787 1788 1789 1790 1791 1792 1793 1794 1795
}
EXPORT_SYMBOL(iwl_dbgfs_register);

/**
 * Remove the debugfs files and directories
 *
 */
void iwl_dbgfs_unregister(struct iwl_priv *priv)
{
J
Johannes Berg 已提交
1796
	if (!priv->debugfs_dir)
T
Tomas Winkler 已提交
1797 1798
		return;

J
Johannes Berg 已提交
1799 1800
	debugfs_remove_recursive(priv->debugfs_dir);
	priv->debugfs_dir = NULL;
T
Tomas Winkler 已提交
1801 1802 1803 1804
}
EXPORT_SYMBOL(iwl_dbgfs_unregister);


1805