debug.c 38.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/******************************************************************************
 *
 * GPL LICENSE SUMMARY
 *
 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
 *
 * 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:
 *  Intel Linux Wireless <ilw@linux.intel.com>
 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
 *****************************************************************************/
#include <linux/ieee80211.h>
29
#include <linux/export.h>
30 31
#include <net/mac80211.h>

32
#include "common.h"
33

34
static void
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
il_clear_traffic_stats(struct il_priv *il)
{
	memset(&il->tx_stats, 0, sizeof(struct traffic_stats));
	memset(&il->rx_stats, 0, sizeof(struct traffic_stats));
}

/*
 * il_update_stats function record all the MGMT, CTRL and DATA pkt for
 * both TX and Rx . Use debugfs to display the rx/rx_stats
 */
void
il_update_stats(struct il_priv *il, bool is_tx, __le16 fc, u16 len)
{
	struct traffic_stats *stats;

	if (is_tx)
		stats = &il->tx_stats;
	else
		stats = &il->rx_stats;

	if (ieee80211_is_mgmt(fc)) {
		switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
		case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
			stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
			break;
		case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
			stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
			break;
		case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
			stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
			break;
		case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
			stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
			break;
		case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
			stats->mgmt[MANAGEMENT_PROBE_REQ]++;
			break;
		case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
			stats->mgmt[MANAGEMENT_PROBE_RESP]++;
			break;
		case cpu_to_le16(IEEE80211_STYPE_BEACON):
			stats->mgmt[MANAGEMENT_BEACON]++;
			break;
		case cpu_to_le16(IEEE80211_STYPE_ATIM):
			stats->mgmt[MANAGEMENT_ATIM]++;
			break;
		case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
			stats->mgmt[MANAGEMENT_DISASSOC]++;
			break;
		case cpu_to_le16(IEEE80211_STYPE_AUTH):
			stats->mgmt[MANAGEMENT_AUTH]++;
			break;
		case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
			stats->mgmt[MANAGEMENT_DEAUTH]++;
			break;
		case cpu_to_le16(IEEE80211_STYPE_ACTION):
			stats->mgmt[MANAGEMENT_ACTION]++;
			break;
		}
	} else if (ieee80211_is_ctl(fc)) {
		switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
		case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
			stats->ctrl[CONTROL_BACK_REQ]++;
			break;
		case cpu_to_le16(IEEE80211_STYPE_BACK):
			stats->ctrl[CONTROL_BACK]++;
			break;
		case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
			stats->ctrl[CONTROL_PSPOLL]++;
			break;
		case cpu_to_le16(IEEE80211_STYPE_RTS):
			stats->ctrl[CONTROL_RTS]++;
			break;
		case cpu_to_le16(IEEE80211_STYPE_CTS):
			stats->ctrl[CONTROL_CTS]++;
			break;
		case cpu_to_le16(IEEE80211_STYPE_ACK):
			stats->ctrl[CONTROL_ACK]++;
			break;
		case cpu_to_le16(IEEE80211_STYPE_CFEND):
			stats->ctrl[CONTROL_CFEND]++;
			break;
		case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
			stats->ctrl[CONTROL_CFENDACK]++;
			break;
		}
	} else {
		/* data */
		stats->data_cnt++;
		stats->data_bytes += len;
	}
}
EXPORT_SYMBOL(il_update_stats);

129 130
/* create and remove of files */
#define DEBUGFS_ADD_FILE(name, parent, mode) do {			\
S
Stanislaw Gruszka 已提交
131
	if (!debugfs_create_file(#name, mode, parent, il,		\
S
Stanislaw Gruszka 已提交
132
			 &il_dbgfs_##name##_ops))		\
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
		goto err;						\
} while (0)

#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;						\
} while (0)

#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;						\
} while (0)

/* file operation */
#define DEBUGFS_READ_FUNC(name)                                         \
S
Stanislaw Gruszka 已提交
154
static ssize_t il_dbgfs_##name##_read(struct file *file,               \
155 156 157 158
					char __user *user_buf,          \
					size_t count, loff_t *ppos);

#define DEBUGFS_WRITE_FUNC(name)                                        \
S
Stanislaw Gruszka 已提交
159
static ssize_t il_dbgfs_##name##_write(struct file *file,              \
160 161 162 163
					const char __user *user_buf,    \
					size_t count, loff_t *ppos);


S
Stanislaw Gruszka 已提交
164 165
#define DEBUGFS_READ_FILE_OPS(name)				\
	DEBUGFS_READ_FUNC(name);				\
S
Stanislaw Gruszka 已提交
166 167
static const struct file_operations il_dbgfs_##name##_ops = {	\
	.read = il_dbgfs_##name##_read,				\
168
	.open = simple_open,					\
S
Stanislaw Gruszka 已提交
169
	.llseek = generic_file_llseek,				\
170 171
};

S
Stanislaw Gruszka 已提交
172 173
#define DEBUGFS_WRITE_FILE_OPS(name)				\
	DEBUGFS_WRITE_FUNC(name);				\
S
Stanislaw Gruszka 已提交
174 175
static const struct file_operations il_dbgfs_##name##_ops = {	\
	.write = il_dbgfs_##name##_write,			\
176
	.open = simple_open,					\
S
Stanislaw Gruszka 已提交
177
	.llseek = generic_file_llseek,				\
178 179
};

S
Stanislaw Gruszka 已提交
180 181 182
#define DEBUGFS_READ_WRITE_FILE_OPS(name)			\
	DEBUGFS_READ_FUNC(name);				\
	DEBUGFS_WRITE_FUNC(name);				\
S
Stanislaw Gruszka 已提交
183 184 185
static const struct file_operations il_dbgfs_##name##_ops = {	\
	.write = il_dbgfs_##name##_write,			\
	.read = il_dbgfs_##name##_read,				\
186
	.open = simple_open,					\
S
Stanislaw Gruszka 已提交
187
	.llseek = generic_file_llseek,				\
188 189
};

190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
static const char *
il_get_mgmt_string(int cmd)
{
	switch (cmd) {
	IL_CMD(MANAGEMENT_ASSOC_REQ);
	IL_CMD(MANAGEMENT_ASSOC_RESP);
	IL_CMD(MANAGEMENT_REASSOC_REQ);
	IL_CMD(MANAGEMENT_REASSOC_RESP);
	IL_CMD(MANAGEMENT_PROBE_REQ);
	IL_CMD(MANAGEMENT_PROBE_RESP);
	IL_CMD(MANAGEMENT_BEACON);
	IL_CMD(MANAGEMENT_ATIM);
	IL_CMD(MANAGEMENT_DISASSOC);
	IL_CMD(MANAGEMENT_AUTH);
	IL_CMD(MANAGEMENT_DEAUTH);
	IL_CMD(MANAGEMENT_ACTION);
	default:
		return "UNKNOWN";

	}
}

static const char *
il_get_ctrl_string(int cmd)
{
	switch (cmd) {
	IL_CMD(CONTROL_BACK_REQ);
	IL_CMD(CONTROL_BACK);
	IL_CMD(CONTROL_PSPOLL);
	IL_CMD(CONTROL_RTS);
	IL_CMD(CONTROL_CTS);
	IL_CMD(CONTROL_ACK);
	IL_CMD(CONTROL_CFEND);
	IL_CMD(CONTROL_CFENDACK);
	default:
		return "UNKNOWN";

	}
}

230
static ssize_t
S
Stanislaw Gruszka 已提交
231 232
il_dbgfs_tx_stats_read(struct file *file, char __user *user_buf, size_t count,
		       loff_t *ppos)
233
{
234

S
Stanislaw Gruszka 已提交
235
	struct il_priv *il = file->private_data;
236 237 238 239 240
	char *buf;
	int pos = 0;

	int cnt;
	ssize_t ret;
241 242
	const size_t bufsz =
	    100 + sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
243 244 245 246 247
	buf = kzalloc(bufsz, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;
	pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
	for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
248 249 250
		pos +=
		    scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
			      il_get_mgmt_string(cnt), il->tx_stats.mgmt[cnt]);
251 252 253
	}
	pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
	for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
254 255 256
		pos +=
		    scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
			      il_get_ctrl_string(cnt), il->tx_stats.ctrl[cnt]);
257 258
	}
	pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
259 260 261 262 263 264
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
		      il->tx_stats.data_cnt);
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
		      il->tx_stats.data_bytes);
265 266 267 268 269 270
	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	kfree(buf);
	return ret;
}

static ssize_t
S
Stanislaw Gruszka 已提交
271
il_dbgfs_clear_traffic_stats_write(struct file *file,
S
Stanislaw Gruszka 已提交
272 273
				   const char __user *user_buf, size_t count,
				   loff_t *ppos)
274
{
S
Stanislaw Gruszka 已提交
275
	struct il_priv *il = file->private_data;
276 277 278 279 280
	u32 clear_flag;
	char buf[8];
	int buf_size;

	memset(buf, 0, sizeof(buf));
281
	buf_size = min(count, sizeof(buf) - 1);
282 283 284 285
	if (copy_from_user(buf, user_buf, buf_size))
		return -EFAULT;
	if (sscanf(buf, "%x", &clear_flag) != 1)
		return -EFAULT;
S
Stanislaw Gruszka 已提交
286
	il_clear_traffic_stats(il);
287 288 289 290

	return count;
}

291
static ssize_t
S
Stanislaw Gruszka 已提交
292 293
il_dbgfs_rx_stats_read(struct file *file, char __user *user_buf, size_t count,
		       loff_t *ppos)
294
{
295

S
Stanislaw Gruszka 已提交
296
	struct il_priv *il = file->private_data;
297 298 299 300
	char *buf;
	int pos = 0;
	int cnt;
	ssize_t ret;
301 302
	const size_t bufsz =
	    100 + sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
303 304 305 306 307 308
	buf = kzalloc(bufsz, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;

	pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
	for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
309 310 311
		pos +=
		    scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
			      il_get_mgmt_string(cnt), il->rx_stats.mgmt[cnt]);
312 313 314
	}
	pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
	for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
315 316 317
		pos +=
		    scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
			      il_get_ctrl_string(cnt), il->rx_stats.ctrl[cnt]);
318 319
	}
	pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
320 321 322 323 324 325
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
		      il->rx_stats.data_cnt);
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
		      il->rx_stats.data_bytes);
326 327 328 329 330 331 332 333 334

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

#define BYTE1_MASK 0x000000ff;
#define BYTE2_MASK 0x0000ffff;
#define BYTE3_MASK 0x00ffffff;
335
static ssize_t
S
Stanislaw Gruszka 已提交
336 337
il_dbgfs_sram_read(struct file *file, char __user *user_buf, size_t count,
		   loff_t *ppos)
338 339 340 341 342 343
{
	u32 val;
	char *buf;
	ssize_t ret;
	int i;
	int pos = 0;
S
Stanislaw Gruszka 已提交
344
	struct il_priv *il = file->private_data;
345 346 347
	size_t bufsz;

	/* default is to dump the entire data segment */
S
Stanislaw Gruszka 已提交
348 349 350 351
	if (!il->dbgfs_sram_offset && !il->dbgfs_sram_len) {
		il->dbgfs_sram_offset = 0x800000;
		if (il->ucode_type == UCODE_INIT)
			il->dbgfs_sram_len = il->ucode_init_data.len;
352
		else
S
Stanislaw Gruszka 已提交
353
			il->dbgfs_sram_len = il->ucode_data.len;
354
	}
355
	bufsz = 30 + il->dbgfs_sram_len * sizeof(char) * 10;
356 357 358
	buf = kmalloc(bufsz, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;
359 360 361 362 363 364
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
		      il->dbgfs_sram_len);
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
		      il->dbgfs_sram_offset);
S
Stanislaw Gruszka 已提交
365
	for (i = il->dbgfs_sram_len; i > 0; i -= 4) {
366 367 368 369
		val =
		    il_read_targ_mem(il,
				     il->dbgfs_sram_offset +
				     il->dbgfs_sram_len - i);
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
		if (i < 4) {
			switch (i) {
			case 1:
				val &= BYTE1_MASK;
				break;
			case 2:
				val &= BYTE2_MASK;
				break;
			case 3:
				val &= BYTE3_MASK;
				break;
			}
		}
		if (!(i % 16))
			pos += scnprintf(buf + pos, bufsz - pos, "\n");
		pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
	}
	pos += scnprintf(buf + pos, bufsz - pos, "\n");

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

394
static ssize_t
S
Stanislaw Gruszka 已提交
395 396
il_dbgfs_sram_write(struct file *file, const char __user *user_buf,
		    size_t count, loff_t *ppos)
397
{
S
Stanislaw Gruszka 已提交
398
	struct il_priv *il = file->private_data;
399 400 401 402 403
	char buf[64];
	int buf_size;
	u32 offset, len;

	memset(buf, 0, sizeof(buf));
404
	buf_size = min(count, sizeof(buf) - 1);
405 406 407 408
	if (copy_from_user(buf, user_buf, buf_size))
		return -EFAULT;

	if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
S
Stanislaw Gruszka 已提交
409 410
		il->dbgfs_sram_offset = offset;
		il->dbgfs_sram_len = len;
411
	} else {
S
Stanislaw Gruszka 已提交
412 413
		il->dbgfs_sram_offset = 0;
		il->dbgfs_sram_len = 0;
414 415 416 417 418 419
	}

	return count;
}

static ssize_t
S
Stanislaw Gruszka 已提交
420 421
il_dbgfs_stations_read(struct file *file, char __user *user_buf, size_t count,
		       loff_t *ppos)
422
{
S
Stanislaw Gruszka 已提交
423
	struct il_priv *il = file->private_data;
S
Stanislaw Gruszka 已提交
424
	struct il_station_entry *station;
S
Stanislaw Gruszka 已提交
425
	int max_sta = il->hw_params.max_stations;
426 427 428 429
	char *buf;
	int i, j, pos = 0;
	ssize_t ret;
	/* Add 30 for initial string */
S
Stanislaw Gruszka 已提交
430
	const size_t bufsz = 30 + sizeof(char) * 500 * (il->num_stations);
431 432 433 434 435

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

436 437 438
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
		      il->num_stations);
439 440

	for (i = 0; i < max_sta; i++) {
S
Stanislaw Gruszka 已提交
441
		station = &il->stations[i];
442 443
		if (!station->used)
			continue;
444 445 446 447 448 449 450 451 452 453 454
		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");
455 456

		for (j = 0; j < MAX_TID_COUNT; j++) {
457 458 459 460 461 462 463 464 465 466
			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);
467 468

			if (station->tid[j].agg.wait_for_ba)
469 470 471
				pos +=
				    scnprintf(buf + pos, bufsz - pos,
					      " - waitforba");
472 473 474 475 476 477 478 479 480 481 482
			pos += scnprintf(buf + pos, bufsz - pos, "\n");
		}

		pos += scnprintf(buf + pos, bufsz - pos, "\n");
	}

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

483
static ssize_t
S
Stanislaw Gruszka 已提交
484 485
il_dbgfs_nvm_read(struct file *file, char __user *user_buf, size_t count,
		  loff_t *ppos)
486 487
{
	ssize_t ret;
S
Stanislaw Gruszka 已提交
488
	struct il_priv *il = file->private_data;
489 490 491 492
	int pos = 0, ofs = 0, buf_size = 0;
	const u8 *ptr;
	char *buf;
	u16 eeprom_ver;
493
	size_t eeprom_len = il->cfg->eeprom_size;
494 495 496
	buf_size = 4 * eeprom_len + 256;

	if (eeprom_len % 16) {
497
		IL_ERR("NVM size is not multiple of 16.\n");
498 499 500
		return -ENODATA;
	}

S
Stanislaw Gruszka 已提交
501
	ptr = il->eeprom;
502
	if (!ptr) {
503
		IL_ERR("Invalid EEPROM memory\n");
504 505 506 507 508 509
		return -ENOMEM;
	}

	/* 4 characters for byte 0xYY */
	buf = kzalloc(buf_size, GFP_KERNEL);
	if (!buf) {
510
		IL_ERR("Can not allocate Buffer\n");
511 512
		return -ENOMEM;
	}
S
Stanislaw Gruszka 已提交
513
	eeprom_ver = il_eeprom_query16(il, EEPROM_VERSION);
514 515 516 517
	pos +=
	    scnprintf(buf + pos, buf_size - pos, "EEPROM " "version: 0x%x\n",
		      eeprom_ver);
	for (ofs = 0; ofs < eeprom_len; ofs += 16) {
518 519
		pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x %16ph\n",
				 ofs, ptr + ofs);
520 521 522 523 524 525 526 527
	}

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

static ssize_t
S
Stanislaw Gruszka 已提交
528 529
il_dbgfs_channels_read(struct file *file, char __user *user_buf, size_t count,
		       loff_t *ppos)
530
{
S
Stanislaw Gruszka 已提交
531
	struct il_priv *il = file->private_data;
532 533 534 535 536 537
	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;

S
Stanislaw Gruszka 已提交
538
	if (!test_bit(S_GEO_CONFIGURED, &il->status))
539 540 541 542
		return -EAGAIN;

	buf = kzalloc(bufsz, GFP_KERNEL);
	if (!buf) {
543
		IL_ERR("Can not allocate Buffer\n");
544 545 546
		return -ENOMEM;
	}

S
Stanislaw Gruszka 已提交
547
	supp_band = il_get_hw_mode(il, IEEE80211_BAND_2GHZ);
548 549 550
	if (supp_band) {
		channels = supp_band->channels;

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

		for (i = 0; i < supp_band->n_channels; i++)
557 558 559 560 561 562 563 564 565
			pos +=
			    scnprintf(buf + pos, bufsz - pos,
				      "%d: %ddBm: BSS%s%s, %s.\n",
				      channels[i].hw_value,
				      channels[i].max_power,
				      channels[i].
				      flags & IEEE80211_CHAN_RADAR ?
				      " (IEEE 802.11h required)" : "",
				      ((channels[i].
566
					flags & IEEE80211_CHAN_NO_IR) ||
567 568 569 570
				       (channels[i].
					flags & IEEE80211_CHAN_RADAR)) ? "" :
				      ", IBSS",
				      channels[i].
571
				      flags & IEEE80211_CHAN_NO_IR ?
572
				      "passive only" : "active/passive");
573
	}
S
Stanislaw Gruszka 已提交
574
	supp_band = il_get_hw_mode(il, IEEE80211_BAND_5GHZ);
575 576 577
	if (supp_band) {
		channels = supp_band->channels;

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

		for (i = 0; i < supp_band->n_channels; i++)
584 585 586 587 588 589 590 591 592
			pos +=
			    scnprintf(buf + pos, bufsz - pos,
				      "%d: %ddBm: BSS%s%s, %s.\n",
				      channels[i].hw_value,
				      channels[i].max_power,
				      channels[i].
				      flags & IEEE80211_CHAN_RADAR ?
				      " (IEEE 802.11h required)" : "",
				      ((channels[i].
593
					flags & IEEE80211_CHAN_NO_IR) ||
594 595 596 597
				       (channels[i].
					flags & IEEE80211_CHAN_RADAR)) ? "" :
				      ", IBSS",
				      channels[i].
598
				      flags & IEEE80211_CHAN_NO_IR ?
599
				      "passive only" : "active/passive");
600 601 602 603 604 605
	}
	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	kfree(buf);
	return ret;
}

606
static ssize_t
S
Stanislaw Gruszka 已提交
607 608
il_dbgfs_status_read(struct file *file, char __user *user_buf, size_t count,
		     loff_t *ppos)
609
{
610

S
Stanislaw Gruszka 已提交
611
	struct il_priv *il = file->private_data;
612 613 614 615
	char buf[512];
	int pos = 0;
	const size_t bufsz = sizeof(buf);

616 617 618 619 620 621 622
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "S_HCMD_ACTIVE:\t %d\n",
		      test_bit(S_HCMD_ACTIVE, &il->status));
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "S_INT_ENABLED:\t %d\n",
		      test_bit(S_INT_ENABLED, &il->status));
	pos +=
623 624
	    scnprintf(buf + pos, bufsz - pos, "S_RFKILL:\t %d\n",
		      test_bit(S_RFKILL, &il->status));
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "S_CT_KILL:\t\t %d\n",
		      test_bit(S_CT_KILL, &il->status));
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "S_INIT:\t\t %d\n",
		      test_bit(S_INIT, &il->status));
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "S_ALIVE:\t\t %d\n",
		      test_bit(S_ALIVE, &il->status));
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "S_READY:\t\t %d\n",
		      test_bit(S_READY, &il->status));
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "S_TEMPERATURE:\t %d\n",
		      test_bit(S_TEMPERATURE, &il->status));
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "S_GEO_CONFIGURED:\t %d\n",
		      test_bit(S_GEO_CONFIGURED, &il->status));
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "S_EXIT_PENDING:\t %d\n",
		      test_bit(S_EXIT_PENDING, &il->status));
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "S_STATS:\t %d\n",
		      test_bit(S_STATS, &il->status));
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "S_SCANNING:\t %d\n",
		      test_bit(S_SCANNING, &il->status));
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "S_SCAN_ABORTING:\t %d\n",
		      test_bit(S_SCAN_ABORTING, &il->status));
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "S_SCAN_HW:\t\t %d\n",
		      test_bit(S_SCAN_HW, &il->status));
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "S_POWER_PMI:\t %d\n",
		      test_bit(S_POWER_PMI, &il->status));
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "S_FW_ERROR:\t %d\n",
		      test_bit(S_FW_ERROR, &il->status));
664 665 666
	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
}

667
static ssize_t
S
Stanislaw Gruszka 已提交
668 669
il_dbgfs_interrupt_read(struct file *file, char __user *user_buf, size_t count,
			loff_t *ppos)
670
{
671

S
Stanislaw Gruszka 已提交
672
	struct il_priv *il = file->private_data;
673 674 675
	int pos = 0;
	int cnt = 0;
	char *buf;
676
	int bufsz = 24 * 64;	/* 24 items * 64 char per item */
677 678 679 680
	ssize_t ret;

	buf = kzalloc(bufsz, GFP_KERNEL);
	if (!buf) {
681
		IL_ERR("Can not allocate Buffer\n");
682 683 684
		return -ENOMEM;
	}

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

688 689 690 691 692 693
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
		      il->isr_stats.hw);
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
		      il->isr_stats.sw);
S
Stanislaw Gruszka 已提交
694
	if (il->isr_stats.sw || il->isr_stats.hw) {
695 696 697 698
		pos +=
		    scnprintf(buf + pos, bufsz - pos,
			      "\tLast Restarting Code:  0x%X\n",
			      il->isr_stats.err_code);
699
	}
700
#ifdef CONFIG_IWLEGACY_DEBUG
701 702 703 704 705 706
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
		      il->isr_stats.sch);
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
		      il->isr_stats.alive);
707
#endif
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723
	pos +=
	    scnprintf(buf + pos, bufsz - pos,
		      "HW RF KILL switch toggled:\t %u\n",
		      il->isr_stats.rfkill);

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

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

	pos +=
	    scnprintf(buf + pos, bufsz - pos, "Rx command responses:\t\t %u\n",
		      il->isr_stats.rx);
724
	for (cnt = 0; cnt < IL_CN_MAX; cnt++) {
725
		if (il->isr_stats.handlers[cnt] > 0)
726 727 728 729 730
			pos +=
			    scnprintf(buf + pos, bufsz - pos,
				      "\tRx handler[%36s]:\t\t %u\n",
				      il_get_cmd_string(cnt),
				      il->isr_stats.handlers[cnt]);
731 732
	}

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

737 738 739
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
		      il->isr_stats.unhandled);
740 741 742 743 744 745

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

746
static ssize_t
S
Stanislaw Gruszka 已提交
747 748
il_dbgfs_interrupt_write(struct file *file, const char __user *user_buf,
			 size_t count, loff_t *ppos)
749
{
S
Stanislaw Gruszka 已提交
750
	struct il_priv *il = file->private_data;
751 752 753 754 755
	char buf[8];
	int buf_size;
	u32 reset_flag;

	memset(buf, 0, sizeof(buf));
756
	buf_size = min(count, sizeof(buf) - 1);
757 758 759 760 761
	if (copy_from_user(buf, user_buf, buf_size))
		return -EFAULT;
	if (sscanf(buf, "%x", &reset_flag) != 1)
		return -EFAULT;
	if (reset_flag == 0)
S
Stanislaw Gruszka 已提交
762
		il_clear_isr_stats(il);
763 764 765 766 767

	return count;
}

static ssize_t
S
Stanislaw Gruszka 已提交
768 769
il_dbgfs_qos_read(struct file *file, char __user *user_buf, size_t count,
		  loff_t *ppos)
770
{
S
Stanislaw Gruszka 已提交
771
	struct il_priv *il = file->private_data;
772
	int pos = 0, i;
773
	char buf[256];
774 775
	const size_t bufsz = sizeof(buf);

776
	for (i = 0; i < AC_NUM; i++) {
777 778 779 780 781 782
		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,
783 784 785 786
			      il->qos_data.def_qos_parm.ac[i].cw_min,
			      il->qos_data.def_qos_parm.ac[i].cw_max,
			      il->qos_data.def_qos_parm.ac[i].aifsn,
			      il->qos_data.def_qos_parm.ac[i].edca_txop);
787
	}
788

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

792
static ssize_t
S
Stanislaw Gruszka 已提交
793 794
il_dbgfs_disable_ht40_write(struct file *file, const char __user *user_buf,
			    size_t count, loff_t *ppos)
795
{
S
Stanislaw Gruszka 已提交
796
	struct il_priv *il = file->private_data;
797 798 799 800 801
	char buf[8];
	int buf_size;
	int ht40;

	memset(buf, 0, sizeof(buf));
802
	buf_size = min(count, sizeof(buf) - 1);
803 804 805 806
	if (copy_from_user(buf, user_buf, buf_size))
		return -EFAULT;
	if (sscanf(buf, "%d", &ht40) != 1)
		return -EFAULT;
S
Stanislaw Gruszka 已提交
807 808
	if (!il_is_any_associated(il))
		il->disable_ht40 = ht40 ? true : false;
809
	else {
810
		IL_ERR("Sta associated with AP - "
811
		       "Change to 40MHz channel support is not allowed\n");
812 813 814 815 816 817
		return -EINVAL;
	}

	return count;
}

818
static ssize_t
S
Stanislaw Gruszka 已提交
819 820
il_dbgfs_disable_ht40_read(struct file *file, char __user *user_buf,
			   size_t count, loff_t *ppos)
821
{
S
Stanislaw Gruszka 已提交
822
	struct il_priv *il = file->private_data;
823 824 825 826
	char buf[100];
	int pos = 0;
	const size_t bufsz = sizeof(buf);

827 828 829
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "11n 40MHz Mode: %s\n",
		      il->disable_ht40 ? "Disabled" : "Enabled");
830 831 832 833 834 835 836 837 838 839 840 841
	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
}

DEBUGFS_READ_WRITE_FILE_OPS(sram);
DEBUGFS_READ_FILE_OPS(nvm);
DEBUGFS_READ_FILE_OPS(stations);
DEBUGFS_READ_FILE_OPS(channels);
DEBUGFS_READ_FILE_OPS(status);
DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
DEBUGFS_READ_FILE_OPS(qos);
DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);

842
static ssize_t
S
Stanislaw Gruszka 已提交
843 844
il_dbgfs_tx_queue_read(struct file *file, char __user *user_buf, size_t count,
		       loff_t *ppos)
845
{
846

S
Stanislaw Gruszka 已提交
847
	struct il_priv *il = file->private_data;
S
Stanislaw Gruszka 已提交
848 849
	struct il_tx_queue *txq;
	struct il_queue *q;
850 851 852 853
	char *buf;
	int pos = 0;
	int cnt;
	int ret;
854
	const size_t bufsz =
855
	    sizeof(char) * 64 * il->cfg->num_of_queues;
856

S
Stanislaw Gruszka 已提交
857
	if (!il->txq) {
858
		IL_ERR("txq not ready\n");
859 860 861 862 863 864
		return -EAGAIN;
	}
	buf = kzalloc(bufsz, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;

S
Stanislaw Gruszka 已提交
865 866
	for (cnt = 0; cnt < il->hw_params.max_txq_num; cnt++) {
		txq = &il->txq[cnt];
867
		q = &txq->q;
868 869 870 871
		pos +=
		    scnprintf(buf + pos, bufsz - pos,
			      "hwq %.2d: read=%u write=%u stop=%d"
			      " swq_id=%#.2x (ac %d/hwq %d)\n", cnt,
S
Stanislaw Gruszka 已提交
872 873
			      q->read_ptr, q->write_ptr,
			      !!test_bit(cnt, il->queue_stopped),
874 875
			      txq->swq_id, txq->swq_id & 3,
			      (txq->swq_id >> 2) & 0x1f);
876 877 878
		if (cnt >= 4)
			continue;
		/* for the ACs, display the stop count too */
879 880 881 882
		pos +=
		    scnprintf(buf + pos, bufsz - pos,
			      "        stop-count: %d\n",
			      atomic_read(&il->queue_stop_count[cnt]));
883 884 885 886 887 888
	}
	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	kfree(buf);
	return ret;
}

889
static ssize_t
S
Stanislaw Gruszka 已提交
890 891
il_dbgfs_rx_queue_read(struct file *file, char __user *user_buf, size_t count,
		       loff_t *ppos)
892
{
893

S
Stanislaw Gruszka 已提交
894 895
	struct il_priv *il = file->private_data;
	struct il_rx_queue *rxq = &il->rxq;
896 897 898 899
	char buf[256];
	int pos = 0;
	const size_t bufsz = sizeof(buf);

900 901 902 903 904
	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);
905
	if (rxq->rb_stts) {
906 907 908 909
		pos +=
		    scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
			      le16_to_cpu(rxq->rb_stts->
					  closed_rb_num) & 0x0FFF);
910
	} else {
911 912 913
		pos +=
		    scnprintf(buf + pos, bufsz - pos,
			      "closed_rb_num: Not Allocated\n");
914 915 916 917
	}
	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
}

918
static ssize_t
S
Stanislaw Gruszka 已提交
919 920
il_dbgfs_ucode_rx_stats_read(struct file *file, char __user *user_buf,
			     size_t count, loff_t *ppos)
921
{
S
Stanislaw Gruszka 已提交
922
	struct il_priv *il = file->private_data;
923 924

	return il->debugfs_ops->rx_stats_read(file, user_buf, count, ppos);
925 926
}

927
static ssize_t
S
Stanislaw Gruszka 已提交
928 929
il_dbgfs_ucode_tx_stats_read(struct file *file, char __user *user_buf,
			     size_t count, loff_t *ppos)
930
{
S
Stanislaw Gruszka 已提交
931
	struct il_priv *il = file->private_data;
932 933

	return il->debugfs_ops->tx_stats_read(file, user_buf, count, ppos);
934 935
}

936
static ssize_t
S
Stanislaw Gruszka 已提交
937 938
il_dbgfs_ucode_general_stats_read(struct file *file, char __user *user_buf,
				  size_t count, loff_t *ppos)
939
{
S
Stanislaw Gruszka 已提交
940
	struct il_priv *il = file->private_data;
941 942

	return il->debugfs_ops->general_stats_read(file, user_buf, count, ppos);
943 944
}

945
static ssize_t
S
Stanislaw Gruszka 已提交
946 947
il_dbgfs_sensitivity_read(struct file *file, char __user *user_buf,
			  size_t count, loff_t *ppos)
948
{
949

S
Stanislaw Gruszka 已提交
950
	struct il_priv *il = file->private_data;
951 952 953
	int pos = 0;
	int cnt = 0;
	char *buf;
S
Stanislaw Gruszka 已提交
954
	int bufsz = sizeof(struct il_sensitivity_data) * 4 + 100;
955
	ssize_t ret;
S
Stanislaw Gruszka 已提交
956
	struct il_sensitivity_data *data;
957

S
Stanislaw Gruszka 已提交
958
	data = &il->sensitivity_data;
959 960
	buf = kzalloc(bufsz, GFP_KERNEL);
	if (!buf) {
961
		IL_ERR("Can not allocate Buffer\n");
962 963 964
		return -ENOMEM;
	}

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
	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);
1002 1003
	pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
	for (cnt = 0; cnt < 10; cnt++) {
1004 1005 1006
		pos +=
		    scnprintf(buf + pos, bufsz - pos, " %u",
			      data->nrg_value[cnt]);
1007 1008 1009 1010
	}
	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++) {
1011 1012 1013
		pos +=
		    scnprintf(buf + pos, bufsz - pos, " %u",
			      data->nrg_silence_rssi[cnt]);
1014 1015
	}
	pos += scnprintf(buf + pos, bufsz - pos, "\n");
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
	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);
1038 1039 1040 1041 1042 1043

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

1044
static ssize_t
S
Stanislaw Gruszka 已提交
1045 1046
il_dbgfs_chain_noise_read(struct file *file, char __user *user_buf,
			  size_t count, loff_t *ppos)
1047
{
1048

S
Stanislaw Gruszka 已提交
1049
	struct il_priv *il = file->private_data;
1050 1051 1052
	int pos = 0;
	int cnt = 0;
	char *buf;
S
Stanislaw Gruszka 已提交
1053
	int bufsz = sizeof(struct il_chain_noise_data) * 4 + 100;
1054
	ssize_t ret;
S
Stanislaw Gruszka 已提交
1055
	struct il_chain_noise_data *data;
1056

S
Stanislaw Gruszka 已提交
1057
	data = &il->chain_noise_data;
1058 1059
	buf = kzalloc(bufsz, GFP_KERNEL);
	if (!buf) {
1060
		IL_ERR("Can not allocate Buffer\n");
1061 1062 1063
		return -ENOMEM;
	}

1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087
	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);
1088 1089 1090

	pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
	for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1091 1092 1093
		pos +=
		    scnprintf(buf + pos, bufsz - pos, " %u",
			      data->disconn_array[cnt]);
1094 1095 1096 1097
	}
	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++) {
1098 1099 1100
		pos +=
		    scnprintf(buf + pos, bufsz - pos, " %u",
			      data->delta_gain_code[cnt]);
1101 1102
	}
	pos += scnprintf(buf + pos, bufsz - pos, "\n");
1103 1104 1105 1106 1107 1108
	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);
1109 1110 1111 1112 1113 1114

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

1115
static ssize_t
S
Stanislaw Gruszka 已提交
1116 1117
il_dbgfs_power_save_status_read(struct file *file, char __user *user_buf,
				size_t count, loff_t *ppos)
1118
{
S
Stanislaw Gruszka 已提交
1119
	struct il_priv *il = file->private_data;
1120 1121 1122 1123 1124
	char buf[60];
	int pos = 0;
	const size_t bufsz = sizeof(buf);
	u32 pwrsave_status;

1125 1126
	pwrsave_status =
	    _il_rd(il, CSR_GP_CNTRL) & CSR_GP_REG_POWER_SAVE_STATUS_MSK;
1127 1128

	pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
1129 1130
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "%s\n",
S
Stanislaw Gruszka 已提交
1131 1132 1133 1134
		      (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");
1135 1136 1137 1138

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

1139 1140
static ssize_t
il_dbgfs_clear_ucode_stats_write(struct file *file,
S
Stanislaw Gruszka 已提交
1141 1142
				 const char __user *user_buf, size_t count,
				 loff_t *ppos)
1143
{
S
Stanislaw Gruszka 已提交
1144
	struct il_priv *il = file->private_data;
1145 1146 1147 1148 1149
	char buf[8];
	int buf_size;
	int clear;

	memset(buf, 0, sizeof(buf));
1150
	buf_size = min(count, sizeof(buf) - 1);
1151 1152 1153 1154 1155
	if (copy_from_user(buf, user_buf, buf_size))
		return -EFAULT;
	if (sscanf(buf, "%d", &clear) != 1)
		return -EFAULT;

S
Stanislaw Gruszka 已提交
1156
	/* make request to uCode to retrieve stats information */
S
Stanislaw Gruszka 已提交
1157
	mutex_lock(&il->mutex);
S
Stanislaw Gruszka 已提交
1158
	il_send_stats_request(il, CMD_SYNC, true);
S
Stanislaw Gruszka 已提交
1159
	mutex_unlock(&il->mutex);
1160 1161 1162 1163

	return count;
}

1164
static ssize_t
S
Stanislaw Gruszka 已提交
1165 1166
il_dbgfs_rxon_flags_read(struct file *file, char __user *user_buf,
			 size_t count, loff_t *ppos)
1167
{
1168

S
Stanislaw Gruszka 已提交
1169
	struct il_priv *il = file->private_data;
1170 1171 1172
	int len = 0;
	char buf[20];

1173
	len = sprintf(buf, "0x%04X\n", le32_to_cpu(il->active.flags));
1174 1175 1176
	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
}

1177
static ssize_t
S
Stanislaw Gruszka 已提交
1178 1179
il_dbgfs_rxon_filter_flags_read(struct file *file, char __user *user_buf,
				size_t count, loff_t *ppos)
1180
{
1181

S
Stanislaw Gruszka 已提交
1182
	struct il_priv *il = file->private_data;
1183 1184 1185
	int len = 0;
	char buf[20];

1186
	len =
1187
	    sprintf(buf, "0x%04X\n", le32_to_cpu(il->active.filter_flags));
1188 1189 1190
	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
}

1191
static ssize_t
S
Stanislaw Gruszka 已提交
1192 1193
il_dbgfs_fh_reg_read(struct file *file, char __user *user_buf, size_t count,
		     loff_t *ppos)
1194
{
S
Stanislaw Gruszka 已提交
1195
	struct il_priv *il = file->private_data;
1196 1197 1198 1199
	char *buf;
	int pos = 0;
	ssize_t ret = -EFAULT;

1200 1201
	if (il->ops->dump_fh) {
		ret = pos = il->ops->dump_fh(il, &buf, true);
1202
		if (buf) {
1203 1204 1205
			ret =
			    simple_read_from_buffer(user_buf, count, ppos, buf,
						    pos);
1206 1207 1208 1209 1210 1211 1212
			kfree(buf);
		}
	}

	return ret;
}

1213
static ssize_t
S
Stanislaw Gruszka 已提交
1214 1215
il_dbgfs_missed_beacon_read(struct file *file, char __user *user_buf,
			    size_t count, loff_t *ppos)
1216
{
1217

S
Stanislaw Gruszka 已提交
1218
	struct il_priv *il = file->private_data;
1219 1220 1221 1222
	int pos = 0;
	char buf[12];
	const size_t bufsz = sizeof(buf);

1223 1224 1225
	pos +=
	    scnprintf(buf + pos, bufsz - pos, "%d\n",
		      il->missed_beacon_threshold);
1226 1227 1228 1229

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

1230
static ssize_t
S
Stanislaw Gruszka 已提交
1231 1232
il_dbgfs_missed_beacon_write(struct file *file, const char __user *user_buf,
			     size_t count, loff_t *ppos)
1233
{
S
Stanislaw Gruszka 已提交
1234
	struct il_priv *il = file->private_data;
1235 1236 1237 1238 1239
	char buf[8];
	int buf_size;
	int missed;

	memset(buf, 0, sizeof(buf));
1240
	buf_size = min(count, sizeof(buf) - 1);
1241 1242 1243 1244 1245
	if (copy_from_user(buf, user_buf, buf_size))
		return -EFAULT;
	if (sscanf(buf, "%d", &missed) != 1)
		return -EINVAL;

S
Stanislaw Gruszka 已提交
1246 1247
	if (missed < IL_MISSED_BEACON_THRESHOLD_MIN ||
	    missed > IL_MISSED_BEACON_THRESHOLD_MAX)
1248
		il->missed_beacon_threshold = IL_MISSED_BEACON_THRESHOLD_DEF;
1249
	else
S
Stanislaw Gruszka 已提交
1250
		il->missed_beacon_threshold = missed;
1251 1252 1253 1254

	return count;
}

1255
static ssize_t
S
Stanislaw Gruszka 已提交
1256 1257
il_dbgfs_force_reset_read(struct file *file, char __user *user_buf,
			  size_t count, loff_t *ppos)
1258
{
1259

S
Stanislaw Gruszka 已提交
1260
	struct il_priv *il = file->private_data;
1261
	int pos = 0;
1262 1263
	char buf[300];
	const size_t bufsz = sizeof(buf);
S
Stanislaw Gruszka 已提交
1264
	struct il_force_reset *force_reset;
1265

S
Stanislaw Gruszka 已提交
1266
	force_reset = &il->force_reset;
1267

1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281
	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);
1282

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

1286
static ssize_t
S
Stanislaw Gruszka 已提交
1287 1288
il_dbgfs_force_reset_write(struct file *file, const char __user *user_buf,
			   size_t count, loff_t *ppos)
1289
{
1290

1291
	int ret;
S
Stanislaw Gruszka 已提交
1292
	struct il_priv *il = file->private_data;
1293

S
Stanislaw Gruszka 已提交
1294
	ret = il_force_reset(il, true);
1295

1296 1297 1298
	return ret ? ret : count;
}

1299
static ssize_t
S
Stanislaw Gruszka 已提交
1300 1301
il_dbgfs_wd_timeout_write(struct file *file, const char __user *user_buf,
			  size_t count, loff_t *ppos)
1302
{
1303

S
Stanislaw Gruszka 已提交
1304
	struct il_priv *il = file->private_data;
1305 1306 1307 1308 1309
	char buf[8];
	int buf_size;
	int timeout;

	memset(buf, 0, sizeof(buf));
1310
	buf_size = min(count, sizeof(buf) - 1);
1311 1312 1313 1314
	if (copy_from_user(buf, user_buf, buf_size))
		return -EFAULT;
	if (sscanf(buf, "%d", &timeout) != 1)
		return -EINVAL;
S
Stanislaw Gruszka 已提交
1315 1316
	if (timeout < 0 || timeout > IL_MAX_WD_TIMEOUT)
		timeout = IL_DEF_WD_TIMEOUT;
1317

1318
	il->cfg->wd_timeout = timeout;
S
Stanislaw Gruszka 已提交
1319
	il_setup_watchdog(il);
1320 1321 1322
	return count;
}

S
Stanislaw Gruszka 已提交
1323 1324
DEBUGFS_READ_FILE_OPS(rx_stats);
DEBUGFS_READ_FILE_OPS(tx_stats);
1325 1326 1327 1328 1329 1330 1331 1332
DEBUGFS_READ_FILE_OPS(rx_queue);
DEBUGFS_READ_FILE_OPS(tx_queue);
DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
DEBUGFS_READ_FILE_OPS(ucode_general_stats);
DEBUGFS_READ_FILE_OPS(sensitivity);
DEBUGFS_READ_FILE_OPS(chain_noise);
DEBUGFS_READ_FILE_OPS(power_save_status);
S
Stanislaw Gruszka 已提交
1333 1334
DEBUGFS_WRITE_FILE_OPS(clear_ucode_stats);
DEBUGFS_WRITE_FILE_OPS(clear_traffic_stats);
1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345
DEBUGFS_READ_FILE_OPS(fh_reg);
DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
DEBUGFS_READ_FILE_OPS(rxon_flags);
DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
DEBUGFS_WRITE_FILE_OPS(wd_timeout);

/*
 * Create the debugfs files and directories
 *
 */
1346 1347
int
il_dbgfs_register(struct il_priv *il, const char *name)
1348
{
S
Stanislaw Gruszka 已提交
1349
	struct dentry *phyd = il->hw->wiphy->debugfsdir;
1350 1351 1352 1353 1354 1355
	struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;

	dir_drv = debugfs_create_dir(name, phyd);
	if (!dir_drv)
		return -ENOMEM;

S
Stanislaw Gruszka 已提交
1356
	il->debugfs_dir = dir_drv;
1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375

	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)
		goto err;

	DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
	DEBUGFS_ADD_FILE(sram, 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(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
S
Stanislaw Gruszka 已提交
1376 1377
	DEBUGFS_ADD_FILE(rx_stats, dir_debug, S_IRUSR);
	DEBUGFS_ADD_FILE(tx_stats, dir_debug, S_IRUSR);
1378 1379 1380
	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);
S
Stanislaw Gruszka 已提交
1381 1382
	DEBUGFS_ADD_FILE(clear_ucode_stats, dir_debug, S_IWUSR);
	DEBUGFS_ADD_FILE(clear_traffic_stats, dir_debug, S_IWUSR);
1383 1384 1385 1386 1387 1388 1389
	DEBUGFS_ADD_FILE(fh_reg, dir_debug, S_IRUSR);
	DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
	DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
	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);

1390
	if (il->cfg->sensitivity_calib_by_driver)
1391
		DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
1392
	if (il->cfg->chain_noise_calib_by_driver)
1393 1394 1395 1396
		DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
	DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
	DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
	DEBUGFS_ADD_FILE(wd_timeout, dir_debug, S_IWUSR);
1397
	if (il->cfg->sensitivity_calib_by_driver)
1398
		DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
S
Stanislaw Gruszka 已提交
1399
				 &il->disable_sens_cal);
1400
	if (il->cfg->chain_noise_calib_by_driver)
1401
		DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
S
Stanislaw Gruszka 已提交
1402
				 &il->disable_chain_noise_cal);
1403
	DEBUGFS_ADD_BOOL(disable_tx_power, dir_rf, &il->disable_tx_power_cal);
1404 1405 1406
	return 0;

err:
1407
	IL_ERR("Can't create the debugfs directory\n");
S
Stanislaw Gruszka 已提交
1408
	il_dbgfs_unregister(il);
1409 1410
	return -ENOMEM;
}
S
Stanislaw Gruszka 已提交
1411
EXPORT_SYMBOL(il_dbgfs_register);
1412 1413 1414 1415 1416

/**
 * Remove the debugfs files and directories
 *
 */
1417 1418
void
il_dbgfs_unregister(struct il_priv *il)
1419
{
S
Stanislaw Gruszka 已提交
1420
	if (!il->debugfs_dir)
1421 1422
		return;

S
Stanislaw Gruszka 已提交
1423 1424
	debugfs_remove_recursive(il->debugfs_dir);
	il->debugfs_dir = NULL;
1425
}
S
Stanislaw Gruszka 已提交
1426
EXPORT_SYMBOL(il_dbgfs_unregister);