debugfs.c 46.4 KB
Newer Older
J
Johannes Berg 已提交
1 2 3 4 5 6 7
/******************************************************************************
 *
 * This file is provided under a dual BSD/GPLv2 license.  When using or
 * redistributing this file, you may do so under either license.
 *
 * GPL LICENSE SUMMARY
 *
8
 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9
 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10
 * Copyright(c) 2016 Intel Deutschland GmbH
J
Johannes Berg 已提交
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * 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
27
 * in the file called COPYING.
J
Johannes Berg 已提交
28 29
 *
 * Contact Information:
30
 *  Intel Linux Wireless <linuxwifi@intel.com>
J
Johannes Berg 已提交
31 32 33 34
 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
 *
 * BSD LICENSE
 *
35
 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
36
 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
J
Johannes Berg 已提交
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
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name Intel Corporation nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/
66
#include <linux/vmalloc.h>
67
#include <linux/ieee80211.h>
68

J
Johannes Berg 已提交
69
#include "mvm.h"
70
#include "fw-dbg.h"
J
Johannes Berg 已提交
71 72
#include "sta.h"
#include "iwl-io.h"
73
#include "debugfs.h"
74
#include "iwl-fw-error-dump.h"
J
Johannes Berg 已提交
75

76
static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf,
J
Johannes Berg 已提交
77 78
					size_t count, loff_t *ppos)
{
79
	int ret;
J
Johannes Berg 已提交
80 81 82 83 84 85 86 87 88 89 90
	u32 scd_q_msk;

	if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
		return -EIO;

	if (sscanf(buf, "%x", &scd_q_msk) != 1)
		return -EINVAL;

	IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk);

	mutex_lock(&mvm->mutex);
91
	ret =  iwl_mvm_flush_tx_path(mvm, scd_q_msk, 0) ? : count;
J
Johannes Berg 已提交
92 93 94 95 96
	mutex_unlock(&mvm->mutex);

	return ret;
}

97
static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf,
J
Johannes Berg 已提交
98 99
					 size_t count, loff_t *ppos)
{
100
	struct iwl_mvm_sta *mvmsta;
101
	int sta_id, drain, ret;
J
Johannes Berg 已提交
102 103 104 105 106 107

	if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
		return -EIO;

	if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
		return -EINVAL;
108 109 110 111
	if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
		return -EINVAL;
	if (drain < 0 || drain > 1)
		return -EINVAL;
J
Johannes Berg 已提交
112 113 114

	mutex_lock(&mvm->mutex);

115 116 117
	mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);

	if (!mvmsta)
J
Johannes Berg 已提交
118 119
		ret = -ENOENT;
	else
120
		ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count;
J
Johannes Berg 已提交
121 122 123 124 125 126 127 128 129 130 131

	mutex_unlock(&mvm->mutex);

	return ret;
}

static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
				   size_t count, loff_t *ppos)
{
	struct iwl_mvm *mvm = file->private_data;
	const struct fw_img *img;
132 133
	unsigned int ofs, len;
	size_t ret;
J
Johannes Berg 已提交
134 135
	u8 *ptr;

136 137 138
	if (!mvm->ucode_loaded)
		return -EINVAL;

J
Johannes Berg 已提交
139
	/* default is to dump the entire data segment */
140 141 142 143
	img = &mvm->fw->img[mvm->cur_ucode];
	ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
	len = img->sec[IWL_UCODE_SECTION_DATA].len;

144
	if (mvm->dbgfs_sram_len) {
145 146
		ofs = mvm->dbgfs_sram_offset;
		len = mvm->dbgfs_sram_len;
J
Johannes Berg 已提交
147 148 149
	}

	ptr = kzalloc(len, GFP_KERNEL);
150
	if (!ptr)
J
Johannes Berg 已提交
151 152
		return -ENOMEM;

153
	iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
J
Johannes Berg 已提交
154

155
	ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len);
J
Johannes Berg 已提交
156 157 158 159 160 161

	kfree(ptr);

	return ret;
}

162 163
static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf,
				    size_t count, loff_t *ppos)
J
Johannes Berg 已提交
164
{
165
	const struct fw_img *img;
J
Johannes Berg 已提交
166
	u32 offset, len;
167 168 169 170 171 172 173 174
	u32 img_offset, img_len;

	if (!mvm->ucode_loaded)
		return -EINVAL;

	img = &mvm->fw->img[mvm->cur_ucode];
	img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset;
	img_len = img->sec[IWL_UCODE_SECTION_DATA].len;
J
Johannes Berg 已提交
175 176 177 178

	if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
		if ((offset & 0x3) || (len & 0x3))
			return -EINVAL;
179 180 181 182

		if (offset + len > img_offset + img_len)
			return -EINVAL;

J
Johannes Berg 已提交
183 184 185 186 187 188 189 190 191 192
		mvm->dbgfs_sram_offset = offset;
		mvm->dbgfs_sram_len = len;
	} else {
		mvm->dbgfs_sram_offset = 0;
		mvm->dbgfs_sram_len = 0;
	}

	return count;
}

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
static ssize_t iwl_dbgfs_set_nic_temperature_read(struct file *file,
						  char __user *user_buf,
						  size_t count, loff_t *ppos)
{
	struct iwl_mvm *mvm = file->private_data;
	char buf[16];
	int pos;

	if (!mvm->temperature_test)
		pos = scnprintf(buf , sizeof(buf), "disabled\n");
	else
		pos = scnprintf(buf , sizeof(buf), "%d\n", mvm->temperature);

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

/*
 * Set NIC Temperature
 * Cause the driver to ignore the actual NIC temperature reported by the FW
 * Enable: any value between IWL_MVM_DEBUG_SET_TEMPERATURE_MIN -
 * IWL_MVM_DEBUG_SET_TEMPERATURE_MAX
 * Disable: IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE
 */
static ssize_t iwl_dbgfs_set_nic_temperature_write(struct iwl_mvm *mvm,
						   char *buf, size_t count,
						   loff_t *ppos)
{
	int temperature;

222 223 224
	if (!mvm->ucode_loaded && !mvm->temperature_test)
		return -EIO;

225 226 227 228 229 230 231 232 233 234
	if (kstrtoint(buf, 10, &temperature))
		return -EINVAL;
	/* not a legal temperature */
	if ((temperature > IWL_MVM_DEBUG_SET_TEMPERATURE_MAX &&
	     temperature != IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) ||
	    temperature < IWL_MVM_DEBUG_SET_TEMPERATURE_MIN)
		return -EINVAL;

	mutex_lock(&mvm->mutex);
	if (temperature == IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) {
235 236 237
		if (!mvm->temperature_test)
			goto out;

238
		mvm->temperature_test = false;
239 240 241 242 243
		/* Since we can't read the temp while awake, just set
		 * it to zero until we get the next RX stats from the
		 * firmware.
		 */
		mvm->temperature = 0;
244 245 246 247 248 249 250 251 252
	} else {
		mvm->temperature_test = true;
		mvm->temperature = temperature;
	}
	IWL_DEBUG_TEMP(mvm, "%sabling debug set temperature (temp = %d)\n",
		       mvm->temperature_test ? "En" : "Dis" ,
		       mvm->temperature);
	/* handle the temperature change */
	iwl_mvm_tt_handler(mvm);
253 254

out:
255 256 257 258 259
	mutex_unlock(&mvm->mutex);

	return count;
}

260 261 262 263 264 265
static ssize_t iwl_dbgfs_nic_temp_read(struct file *file,
				       char __user *user_buf,
				       size_t count, loff_t *ppos)
{
	struct iwl_mvm *mvm = file->private_data;
	char buf[16];
266 267
	int pos, ret;
	s32 temp;
268 269 270 271 272

	if (!mvm->ucode_loaded)
		return -EIO;

	mutex_lock(&mvm->mutex);
273
	ret = iwl_mvm_get_temp(mvm, &temp);
274 275
	mutex_unlock(&mvm->mutex);

276 277
	if (ret)
		return -EIO;
278 279 280 281 282 283

	pos = scnprintf(buf , sizeof(buf), "%d\n", temp);

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

J
Johannes Berg 已提交
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
				       size_t count, loff_t *ppos)
{
	struct iwl_mvm *mvm = file->private_data;
	struct ieee80211_sta *sta;
	char buf[400];
	int i, pos = 0, bufsz = sizeof(buf);

	mutex_lock(&mvm->mutex);

	for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
		pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
		sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
						lockdep_is_held(&mvm->mutex));
		if (!sta)
			pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
		else if (IS_ERR(sta))
			pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
					 PTR_ERR(sta));
		else
			pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
					 sta->addr);
	}

	mutex_unlock(&mvm->mutex);

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

313 314
static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
						char __user *user_buf,
J
Johannes Berg 已提交
315 316 317
						size_t count, loff_t *ppos)
{
	struct iwl_mvm *mvm = file->private_data;
318 319 320
	char buf[64];
	int bufsz = sizeof(buf);
	int pos = 0;
J
Johannes Berg 已提交
321

322 323 324 325
	pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
			 mvm->disable_power_off);
	pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
			 mvm->disable_power_off_d3);
J
Johannes Berg 已提交
326

327
	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
J
Johannes Berg 已提交
328 329
}

330
static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf,
331
						 size_t count, loff_t *ppos)
J
Johannes Berg 已提交
332
{
333
	int ret, val;
334 335 336

	if (!mvm->ucode_loaded)
		return -EIO;
J
Johannes Berg 已提交
337

338 339 340 341 342 343 344 345 346
	if (!strncmp("disable_power_off_d0=", buf, 21)) {
		if (sscanf(buf + 21, "%d", &val) != 1)
			return -EINVAL;
		mvm->disable_power_off = val;
	} else if (!strncmp("disable_power_off_d3=", buf, 21)) {
		if (sscanf(buf + 21, "%d", &val) != 1)
			return -EINVAL;
		mvm->disable_power_off_d3 = val;
	} else {
J
Johannes Berg 已提交
347
		return -EINVAL;
348
	}
J
Johannes Berg 已提交
349

350
	mutex_lock(&mvm->mutex);
351
	ret = iwl_mvm_power_update_device(mvm);
352
	mutex_unlock(&mvm->mutex);
J
Johannes Berg 已提交
353

354
	return ret ?: count;
J
Johannes Berg 已提交
355 356
}

357 358 359 360 361 362 363 364 365 366 367 368
#define BT_MBOX_MSG(_notif, _num, _field)				     \
	((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
	>> BT_MBOX##_num##_##_field##_POS)


#define BT_MBOX_PRINT(_num, _field, _end)				    \
			pos += scnprintf(buf + pos, bufsz - pos,	    \
					 "\t%s: %d%s",			    \
					 #_field,			    \
					 BT_MBOX_MSG(notif, _num, _field),  \
					 true ? "\n" : ", ");

369 370 371
static
int iwl_mvm_coex_dump_mbox(struct iwl_bt_coex_profile_notif *notif, char *buf,
			   int pos, int bufsz)
372
{
373
	pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
374

375 376 377 378 379 380 381 382 383 384 385
	BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
	BT_MBOX_PRINT(0, LE_PROF1, false);
	BT_MBOX_PRINT(0, LE_PROF2, false);
	BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
	BT_MBOX_PRINT(0, CHL_SEQ_N, false);
	BT_MBOX_PRINT(0, INBAND_S, false);
	BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
	BT_MBOX_PRINT(0, LE_SCAN, false);
	BT_MBOX_PRINT(0, LE_ADV, false);
	BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
	BT_MBOX_PRINT(0, OPEN_CON_1, true);
386

387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
	pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");

	BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
	BT_MBOX_PRINT(1, IP_SR, false);
	BT_MBOX_PRINT(1, LE_MSTR, false);
	BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
	BT_MBOX_PRINT(1, MSG_TYPE, false);
	BT_MBOX_PRINT(1, SSN, true);

	pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");

	BT_MBOX_PRINT(2, SNIFF_ACT, false);
	BT_MBOX_PRINT(2, PAG, false);
	BT_MBOX_PRINT(2, INQUIRY, false);
	BT_MBOX_PRINT(2, CONN, false);
	BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
	BT_MBOX_PRINT(2, DISC, false);
	BT_MBOX_PRINT(2, SCO_TX_ACT, false);
	BT_MBOX_PRINT(2, SCO_RX_ACT, false);
	BT_MBOX_PRINT(2, ESCO_RE_TX, false);
	BT_MBOX_PRINT(2, SCO_DURATION, true);
408

409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
	pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");

	BT_MBOX_PRINT(3, SCO_STATE, false);
	BT_MBOX_PRINT(3, SNIFF_STATE, false);
	BT_MBOX_PRINT(3, A2DP_STATE, false);
	BT_MBOX_PRINT(3, ACL_STATE, false);
	BT_MBOX_PRINT(3, MSTR_STATE, false);
	BT_MBOX_PRINT(3, OBX_STATE, false);
	BT_MBOX_PRINT(3, OPEN_CON_2, false);
	BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
	BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
	BT_MBOX_PRINT(3, INBAND_P, false);
	BT_MBOX_PRINT(3, MSG_TYPE_2, false);
	BT_MBOX_PRINT(3, SSN_2, false);
	BT_MBOX_PRINT(3, UPDATE_REQUEST, true);

	return pos;
}

static
int iwl_mvm_coex_dump_mbox_old(struct iwl_bt_coex_profile_notif_old *notif,
			       char *buf, int pos, int bufsz)
{
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
	pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");

	BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
	BT_MBOX_PRINT(0, LE_PROF1, false);
	BT_MBOX_PRINT(0, LE_PROF2, false);
	BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
	BT_MBOX_PRINT(0, CHL_SEQ_N, false);
	BT_MBOX_PRINT(0, INBAND_S, false);
	BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
	BT_MBOX_PRINT(0, LE_SCAN, false);
	BT_MBOX_PRINT(0, LE_ADV, false);
	BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
	BT_MBOX_PRINT(0, OPEN_CON_1, true);

	pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");

	BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
	BT_MBOX_PRINT(1, IP_SR, false);
	BT_MBOX_PRINT(1, LE_MSTR, false);
	BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
	BT_MBOX_PRINT(1, MSG_TYPE, false);
	BT_MBOX_PRINT(1, SSN, true);

	pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");

	BT_MBOX_PRINT(2, SNIFF_ACT, false);
	BT_MBOX_PRINT(2, PAG, false);
	BT_MBOX_PRINT(2, INQUIRY, false);
	BT_MBOX_PRINT(2, CONN, false);
	BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
	BT_MBOX_PRINT(2, DISC, false);
	BT_MBOX_PRINT(2, SCO_TX_ACT, false);
	BT_MBOX_PRINT(2, SCO_RX_ACT, false);
	BT_MBOX_PRINT(2, ESCO_RE_TX, false);
	BT_MBOX_PRINT(2, SCO_DURATION, true);

	pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");

	BT_MBOX_PRINT(3, SCO_STATE, false);
	BT_MBOX_PRINT(3, SNIFF_STATE, false);
	BT_MBOX_PRINT(3, A2DP_STATE, false);
	BT_MBOX_PRINT(3, ACL_STATE, false);
	BT_MBOX_PRINT(3, MSTR_STATE, false);
	BT_MBOX_PRINT(3, OBX_STATE, false);
	BT_MBOX_PRINT(3, OPEN_CON_2, false);
	BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
	BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
	BT_MBOX_PRINT(3, INBAND_P, false);
	BT_MBOX_PRINT(3, MSG_TYPE_2, false);
	BT_MBOX_PRINT(3, SSN_2, false);
	BT_MBOX_PRINT(3, UPDATE_REQUEST, true);

484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
	return pos;
}

static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
				       size_t count, loff_t *ppos)
{
	struct iwl_mvm *mvm = file->private_data;
	char *buf;
	int ret, pos = 0, bufsz = sizeof(char) * 1024;

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

	mutex_lock(&mvm->mutex);

500 501
	if (!fw_has_api(&mvm->fw->ucode_capa,
			IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
		struct iwl_bt_coex_profile_notif_old *notif =
			&mvm->last_bt_notif_old;

		pos += iwl_mvm_coex_dump_mbox_old(notif, buf, pos, bufsz);

		pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
				 notif->bt_ci_compliance);
		pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
				 le32_to_cpu(notif->primary_ch_lut));
		pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
				 le32_to_cpu(notif->secondary_ch_lut));
		pos += scnprintf(buf+pos,
				 bufsz-pos, "bt_activity_grading = %d\n",
				 le32_to_cpu(notif->bt_activity_grading));
		pos += scnprintf(buf+pos, bufsz-pos,
				 "antenna isolation = %d CORUN LUT index = %d\n",
				 mvm->last_ant_isol, mvm->last_corun_lut);
519 520 521 522
		pos += scnprintf(buf + pos, bufsz - pos, "bt_rrc = %d\n",
				 notif->rrc_enabled);
		pos += scnprintf(buf + pos, bufsz - pos, "bt_ttc = %d\n",
				 notif->ttc_enabled);
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
	} else {
		struct iwl_bt_coex_profile_notif *notif =
			&mvm->last_bt_notif;

		pos += iwl_mvm_coex_dump_mbox(notif, buf, pos, bufsz);

		pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
				 notif->bt_ci_compliance);
		pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
				 le32_to_cpu(notif->primary_ch_lut));
		pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
				 le32_to_cpu(notif->secondary_ch_lut));
		pos += scnprintf(buf+pos,
				 bufsz-pos, "bt_activity_grading = %d\n",
				 le32_to_cpu(notif->bt_activity_grading));
		pos += scnprintf(buf+pos, bufsz-pos,
				 "antenna isolation = %d CORUN LUT index = %d\n",
				 mvm->last_ant_isol, mvm->last_corun_lut);
541 542 543 544
		pos += scnprintf(buf + pos, bufsz - pos, "bt_rrc = %d\n",
				 (notif->ttc_rrc_status >> 4) & 0xF);
		pos += scnprintf(buf + pos, bufsz - pos, "bt_ttc = %d\n",
				 notif->ttc_rrc_status & 0xF);
545
	}
546

547 548 549 550 551 552 553
	pos += scnprintf(buf + pos, bufsz - pos, "sync_sco = %d\n",
			 IWL_MVM_BT_COEX_SYNC2SCO);
	pos += scnprintf(buf + pos, bufsz - pos, "mplut = %d\n",
			 IWL_MVM_BT_COEX_MPLUT);
	pos += scnprintf(buf + pos, bufsz - pos, "corunning = %d\n",
			 IWL_MVM_BT_COEX_CORUNNING);

554 555 556 557 558 559 560 561 562
	mutex_unlock(&mvm->mutex);

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

	return ret;
}
#undef BT_MBOX_PRINT

563 564 565 566 567 568 569 570 571 572
static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
				     size_t count, loff_t *ppos)
{
	struct iwl_mvm *mvm = file->private_data;
	char buf[256];
	int bufsz = sizeof(buf);
	int pos = 0;

	mutex_lock(&mvm->mutex);

573 574
	if (!fw_has_api(&mvm->fw->ucode_capa,
			IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
575 576 577 578 579 580 581 582 583 584 585
		struct iwl_bt_coex_ci_cmd_old *cmd = &mvm->last_bt_ci_cmd_old;

		pos += scnprintf(buf+pos, bufsz-pos,
				 "Channel inhibition CMD\n");
		pos += scnprintf(buf+pos, bufsz-pos,
			       "\tPrimary Channel Bitmap 0x%016llx\n",
			       le64_to_cpu(cmd->bt_primary_ci));
		pos += scnprintf(buf+pos, bufsz-pos,
			       "\tSecondary Channel Bitmap 0x%016llx\n",
			       le64_to_cpu(cmd->bt_secondary_ci));

586 587 588 589 590 591
		pos += scnprintf(buf+pos, bufsz-pos,
				 "BT Configuration CMD - 0=default, 1=never, 2=always\n");
		pos += scnprintf(buf+pos, bufsz-pos, "\tACK Kill msk idx %d\n",
				 mvm->bt_ack_kill_msk[0]);
		pos += scnprintf(buf+pos, bufsz-pos, "\tCTS Kill msk idx %d\n",
				 mvm->bt_cts_kill_msk[0]);
592 593 594 595 596 597 598 599 600 601 602 603 604

	} else {
		struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;

		pos += scnprintf(buf+pos, bufsz-pos,
				 "Channel inhibition CMD\n");
		pos += scnprintf(buf+pos, bufsz-pos,
			       "\tPrimary Channel Bitmap 0x%016llx\n",
			       le64_to_cpu(cmd->bt_primary_ci));
		pos += scnprintf(buf+pos, bufsz-pos,
			       "\tSecondary Channel Bitmap 0x%016llx\n",
			       le64_to_cpu(cmd->bt_secondary_ci));
	}
605 606 607 608 609 610

	mutex_unlock(&mvm->mutex);

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

611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
static ssize_t
iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf,
			   size_t count, loff_t *ppos)
{
	u32 bt_tx_prio;

	if (sscanf(buf, "%u", &bt_tx_prio) != 1)
		return -EINVAL;
	if (bt_tx_prio > 4)
		return -EINVAL;

	mvm->bt_tx_prio = bt_tx_prio;

	return count;
}

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
static ssize_t
iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char *buf,
			     size_t count, loff_t *ppos)
{
	static const char * const modes_str[BT_FORCE_ANT_MAX] = {
		[BT_FORCE_ANT_DIS] = "dis",
		[BT_FORCE_ANT_AUTO] = "auto",
		[BT_FORCE_ANT_BT] = "bt",
		[BT_FORCE_ANT_WIFI] = "wifi",
	};
	int ret, bt_force_ant_mode;

	for (bt_force_ant_mode = 0;
	     bt_force_ant_mode < ARRAY_SIZE(modes_str);
	     bt_force_ant_mode++) {
		if (!strcmp(buf, modes_str[bt_force_ant_mode]))
			break;
	}

	if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
		return -EINVAL;

	ret = 0;
	mutex_lock(&mvm->mutex);
	if (mvm->bt_force_ant_mode == bt_force_ant_mode)
		goto out;

	mvm->bt_force_ant_mode = bt_force_ant_mode;
	IWL_DEBUG_COEX(mvm, "Force mode: %s\n",
		       modes_str[mvm->bt_force_ant_mode]);
	ret = iwl_send_bt_init_conf(mvm);

out:
	mutex_unlock(&mvm->mutex);
	return ret ?: count;
}

664
#define PRINT_STATS_LE32(_struct, _memb)				\
665
			 pos += scnprintf(buf + pos, bufsz - pos,	\
666 667
					  fmt_table, #_memb,		\
					  le32_to_cpu(_struct->_memb))
668 669 670 671 672 673 674 675 676 677 678

static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
					  char __user *user_buf, size_t count,
					  loff_t *ppos)
{
	struct iwl_mvm *mvm = file->private_data;
	static const char *fmt_table = "\t%-30s %10u\n";
	static const char *fmt_header = "%-32s\n";
	int pos = 0;
	char *buf;
	int ret;
679 680 681 682 683
	/* 43 is the size of each data line, 33 is the size of each header */
	size_t bufsz =
		((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) +
		(4 * 33) + 1;

684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
	struct mvm_statistics_rx_phy *ofdm;
	struct mvm_statistics_rx_phy *cck;
	struct mvm_statistics_rx_non_phy *general;
	struct mvm_statistics_rx_ht_phy *ht;

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

	mutex_lock(&mvm->mutex);

	ofdm = &mvm->rx_stats.ofdm;
	cck = &mvm->rx_stats.cck;
	general = &mvm->rx_stats.general;
	ht = &mvm->rx_stats.ofdm_ht;

	pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
			 "Statistics_Rx - OFDM");
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721
	PRINT_STATS_LE32(ofdm, ina_cnt);
	PRINT_STATS_LE32(ofdm, fina_cnt);
	PRINT_STATS_LE32(ofdm, plcp_err);
	PRINT_STATS_LE32(ofdm, crc32_err);
	PRINT_STATS_LE32(ofdm, overrun_err);
	PRINT_STATS_LE32(ofdm, early_overrun_err);
	PRINT_STATS_LE32(ofdm, crc32_good);
	PRINT_STATS_LE32(ofdm, false_alarm_cnt);
	PRINT_STATS_LE32(ofdm, fina_sync_err_cnt);
	PRINT_STATS_LE32(ofdm, sfd_timeout);
	PRINT_STATS_LE32(ofdm, fina_timeout);
	PRINT_STATS_LE32(ofdm, unresponded_rts);
	PRINT_STATS_LE32(ofdm, rxe_frame_lmt_overrun);
	PRINT_STATS_LE32(ofdm, sent_ack_cnt);
	PRINT_STATS_LE32(ofdm, sent_cts_cnt);
	PRINT_STATS_LE32(ofdm, sent_ba_rsp_cnt);
	PRINT_STATS_LE32(ofdm, dsp_self_kill);
	PRINT_STATS_LE32(ofdm, mh_format_err);
	PRINT_STATS_LE32(ofdm, re_acq_main_rssi_sum);
	PRINT_STATS_LE32(ofdm, reserved);
722 723 724

	pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
			 "Statistics_Rx - CCK");
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
	PRINT_STATS_LE32(cck, ina_cnt);
	PRINT_STATS_LE32(cck, fina_cnt);
	PRINT_STATS_LE32(cck, plcp_err);
	PRINT_STATS_LE32(cck, crc32_err);
	PRINT_STATS_LE32(cck, overrun_err);
	PRINT_STATS_LE32(cck, early_overrun_err);
	PRINT_STATS_LE32(cck, crc32_good);
	PRINT_STATS_LE32(cck, false_alarm_cnt);
	PRINT_STATS_LE32(cck, fina_sync_err_cnt);
	PRINT_STATS_LE32(cck, sfd_timeout);
	PRINT_STATS_LE32(cck, fina_timeout);
	PRINT_STATS_LE32(cck, unresponded_rts);
	PRINT_STATS_LE32(cck, rxe_frame_lmt_overrun);
	PRINT_STATS_LE32(cck, sent_ack_cnt);
	PRINT_STATS_LE32(cck, sent_cts_cnt);
	PRINT_STATS_LE32(cck, sent_ba_rsp_cnt);
	PRINT_STATS_LE32(cck, dsp_self_kill);
	PRINT_STATS_LE32(cck, mh_format_err);
	PRINT_STATS_LE32(cck, re_acq_main_rssi_sum);
	PRINT_STATS_LE32(cck, reserved);
745 746 747

	pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
			 "Statistics_Rx - GENERAL");
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
	PRINT_STATS_LE32(general, bogus_cts);
	PRINT_STATS_LE32(general, bogus_ack);
	PRINT_STATS_LE32(general, non_bssid_frames);
	PRINT_STATS_LE32(general, filtered_frames);
	PRINT_STATS_LE32(general, non_channel_beacons);
	PRINT_STATS_LE32(general, channel_beacons);
	PRINT_STATS_LE32(general, num_missed_bcon);
	PRINT_STATS_LE32(general, adc_rx_saturation_time);
	PRINT_STATS_LE32(general, ina_detection_search_time);
	PRINT_STATS_LE32(general, beacon_silence_rssi_a);
	PRINT_STATS_LE32(general, beacon_silence_rssi_b);
	PRINT_STATS_LE32(general, beacon_silence_rssi_c);
	PRINT_STATS_LE32(general, interference_data_flag);
	PRINT_STATS_LE32(general, channel_load);
	PRINT_STATS_LE32(general, dsp_false_alarms);
	PRINT_STATS_LE32(general, beacon_rssi_a);
	PRINT_STATS_LE32(general, beacon_rssi_b);
	PRINT_STATS_LE32(general, beacon_rssi_c);
	PRINT_STATS_LE32(general, beacon_energy_a);
	PRINT_STATS_LE32(general, beacon_energy_b);
	PRINT_STATS_LE32(general, beacon_energy_c);
	PRINT_STATS_LE32(general, num_bt_kills);
	PRINT_STATS_LE32(general, mac_id);
	PRINT_STATS_LE32(general, directed_data_mpdu);
772 773 774

	pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
			 "Statistics_Rx - HT");
775 776 777 778 779 780 781 782 783 784
	PRINT_STATS_LE32(ht, plcp_err);
	PRINT_STATS_LE32(ht, overrun_err);
	PRINT_STATS_LE32(ht, early_overrun_err);
	PRINT_STATS_LE32(ht, crc32_good);
	PRINT_STATS_LE32(ht, crc32_err);
	PRINT_STATS_LE32(ht, mh_format_err);
	PRINT_STATS_LE32(ht, agg_crc32_good);
	PRINT_STATS_LE32(ht, agg_mpdu_cnt);
	PRINT_STATS_LE32(ht, agg_cnt);
	PRINT_STATS_LE32(ht, unsupport_mcs);
785 786 787 788 789 790 791 792 793 794

	mutex_unlock(&mvm->mutex);

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

	return ret;
}
#undef PRINT_STAT_LE32

795 796 797 798 799
static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm,
					  char __user *user_buf, size_t count,
					  loff_t *ppos,
					  struct iwl_mvm_frame_stats *stats)
{
800 801
	char *buff, *pos, *endpos;
	int idx, i;
802
	int ret;
803
	static const size_t bufsz = 1024;
804 805 806 807 808 809

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

	spin_lock_bh(&mvm->drv_stats_lock);
810 811 812 813 814

	pos = buff;
	endpos = pos + bufsz;

	pos += scnprintf(pos, endpos - pos,
815 816 817 818
			 "Legacy/HT/VHT\t:\t%d/%d/%d\n",
			 stats->legacy_frames,
			 stats->ht_frames,
			 stats->vht_frames);
819
	pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n",
820 821 822
			 stats->bw_20_frames,
			 stats->bw_40_frames,
			 stats->bw_80_frames);
823
	pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n",
824 825
			 stats->ngi_frames,
			 stats->sgi_frames);
826
	pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n",
827 828
			 stats->siso_frames,
			 stats->mimo2_frames);
829
	pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n",
830 831
			 stats->fail_frames,
			 stats->success_frames);
832
	pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n",
833
			 stats->agg_frames);
834
	pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n",
835
			 stats->ampdu_count);
836
	pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n",
837 838 839
			 stats->ampdu_count > 0 ?
			 (stats->agg_frames / stats->ampdu_count) : 0);

840
	pos += scnprintf(pos, endpos - pos, "Last Rates\n");
841 842 843 844 845 846

	idx = stats->last_frame_idx - 1;
	for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) {
		idx = (idx + 1) % ARRAY_SIZE(stats->last_rates);
		if (stats->last_rates[idx] == 0)
			continue;
847
		pos += scnprintf(pos, endpos - pos, "Rate[%d]: ",
848
				 (int)(ARRAY_SIZE(stats->last_rates) - i));
849
		pos += rs_pretty_print_rate(pos, stats->last_rates[idx]);
850 851 852
	}
	spin_unlock_bh(&mvm->drv_stats_lock);

853
	ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868
	kfree(buff);

	return ret;
}

static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file,
					   char __user *user_buf, size_t count,
					   loff_t *ppos)
{
	struct iwl_mvm *mvm = file->private_data;

	return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos,
					  &mvm->drv_rx_stats);
}

869
static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
870 871 872 873 874 875
					  size_t count, loff_t *ppos)
{
	int ret;

	mutex_lock(&mvm->mutex);

876 877 878 879
	/* allow one more restart that we're provoking here */
	if (mvm->restart_fw >= 0)
		mvm->restart_fw++;

880
	/* take the return value to make compiler happy - it will fail anyway */
E
Emmanuel Grumbach 已提交
881
	ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, 0, 0, NULL);
882 883 884 885 886 887

	mutex_unlock(&mvm->mutex);

	return count;
}

888
static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
889 890
				      size_t count, loff_t *ppos)
{
891 892 893 894
	int ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_NMI);
	if (ret)
		return ret;

L
Liad Kaufman 已提交
895
	iwl_force_nmi(mvm->trans);
896

897 898
	iwl_mvm_unref(mvm, IWL_MVM_REF_NMI);

899 900 901
	return count;
}

902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925
static ssize_t
iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
				char __user *user_buf,
				size_t count, loff_t *ppos)
{
	struct iwl_mvm *mvm = file->private_data;
	int pos = 0;
	char buf[32];
	const size_t bufsz = sizeof(buf);

	/* print which antennas were set for the scan command by the user */
	pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
	if (mvm->scan_rx_ant & ANT_A)
		pos += scnprintf(buf + pos, bufsz - pos, "A");
	if (mvm->scan_rx_ant & ANT_B)
		pos += scnprintf(buf + pos, bufsz - pos, "B");
	if (mvm->scan_rx_ant & ANT_C)
		pos += scnprintf(buf + pos, bufsz - pos, "C");
	pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);

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

static ssize_t
926
iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
927 928 929 930 931 932 933 934
				 size_t count, loff_t *ppos)
{
	u8 scan_rx_ant;

	if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
		return -EINVAL;
	if (scan_rx_ant > ANT_ABC)
		return -EINVAL;
935
	if (scan_rx_ant & ~(iwl_mvm_get_valid_rx_ant(mvm)))
936 937
		return -EINVAL;

938 939
	if (mvm->scan_rx_ant != scan_rx_ant) {
		mvm->scan_rx_ant = scan_rx_ant;
940 941
		if (fw_has_capa(&mvm->fw->ucode_capa,
				IWL_UCODE_TLV_CAPA_UMAC_SCAN))
942 943
			iwl_mvm_config_scan(mvm);
	}
944 945 946 947

	return count;
}

948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979
static ssize_t iwl_dbgfs_indirection_tbl_write(struct iwl_mvm *mvm,
					       char *buf, size_t count,
					       loff_t *ppos)
{
	struct iwl_rss_config_cmd cmd = {
		.flags = cpu_to_le32(IWL_RSS_ENABLE),
		.hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP |
			     IWL_RSS_HASH_TYPE_IPV4_PAYLOAD |
			     IWL_RSS_HASH_TYPE_IPV6_TCP |
			     IWL_RSS_HASH_TYPE_IPV6_PAYLOAD,
	};
	int ret, i, num_repeats, nbytes = count / 2;

	ret = hex2bin(cmd.indirection_table, buf, nbytes);
	if (ret)
		return ret;

	/*
	 * The input is the redirection table, partial or full.
	 * Repeat the pattern if needed.
	 * For example, input of 01020F will be repeated 42 times,
	 * indirecting RSS hash results to queues 1, 2, 15 (skipping
	 * queues 3 - 14).
	 */
	num_repeats = ARRAY_SIZE(cmd.indirection_table) / nbytes;
	for (i = 1; i < num_repeats; i++)
		memcpy(&cmd.indirection_table[i * nbytes],
		       cmd.indirection_table, nbytes);
	/* handle cut in the middle pattern for the last places */
	memcpy(&cmd.indirection_table[i * nbytes], cmd.indirection_table,
	       ARRAY_SIZE(cmd.indirection_table) % nbytes);

S
Sara Sharon 已提交
980
	memcpy(cmd.secret_key, mvm->secret_key, sizeof(cmd.secret_key));
981 982 983 984 985 986 987 988

	mutex_lock(&mvm->mutex);
	ret = iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0, sizeof(cmd), &cmd);
	mutex_unlock(&mvm->mutex);

	return ret ?: count;
}

989 990 991 992 993
static ssize_t iwl_dbgfs_fw_dbg_conf_read(struct file *file,
					  char __user *user_buf,
					  size_t count, loff_t *ppos)
{
	struct iwl_mvm *mvm = file->private_data;
994
	int conf;
995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007
	char buf[8];
	const size_t bufsz = sizeof(buf);
	int pos = 0;

	mutex_lock(&mvm->mutex);
	conf = mvm->fw_dbg_conf;
	mutex_unlock(&mvm->mutex);

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

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

1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029
/*
 * Enable / Disable continuous recording.
 * Cause the FW to start continuous recording, by sending the relevant hcmd.
 * Enable: input of every integer larger than 0, ENABLE_CONT_RECORDING.
 * Disable: for 0 as input, DISABLE_CONT_RECORDING.
 */
static ssize_t iwl_dbgfs_cont_recording_write(struct iwl_mvm *mvm,
					      char *buf, size_t count,
					      loff_t *ppos)
{
	struct iwl_trans *trans = mvm->trans;
	const struct iwl_fw_dbg_dest_tlv *dest = trans->dbg_dest_tlv;
	struct iwl_continuous_record_cmd cont_rec = {};
	int ret, rec_mode;

	if (!dest)
		return -EOPNOTSUPP;

	if (dest->monitor_mode != SMEM_MODE ||
	    trans->cfg->device_family != IWL_DEVICE_FAMILY_8000)
		return -EOPNOTSUPP;

1030
	ret = kstrtoint(buf, 0, &rec_mode);
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
	if (ret)
		return ret;

	cont_rec.record_mode.enable_recording = rec_mode ?
		cpu_to_le16(ENABLE_CONT_RECORDING) :
		cpu_to_le16(DISABLE_CONT_RECORDING);

	mutex_lock(&mvm->mutex);
	ret = iwl_mvm_send_cmd_pdu(mvm, LDBG_CONFIG_CMD, 0,
				   sizeof(cont_rec), &cont_rec);
	mutex_unlock(&mvm->mutex);

	return ret ?: count;
}

1046 1047 1048 1049
static ssize_t iwl_dbgfs_fw_dbg_conf_write(struct iwl_mvm *mvm,
					   char *buf, size_t count,
					   loff_t *ppos)
{
1050 1051
	unsigned int conf_id;
	int ret;
1052

1053
	ret = kstrtouint(buf, 0, &conf_id);
1054 1055 1056
	if (ret)
		return ret;

1057
	if (WARN_ON(conf_id >= FW_DBG_CONF_MAX))
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
		return -EINVAL;

	mutex_lock(&mvm->mutex);
	ret = iwl_mvm_start_fw_dbg_conf(mvm, conf_id);
	mutex_unlock(&mvm->mutex);

	return ret ?: count;
}

static ssize_t iwl_dbgfs_fw_dbg_collect_write(struct iwl_mvm *mvm,
					      char *buf, size_t count,
					      loff_t *ppos)
{
1071 1072 1073 1074 1075
	int ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);

	if (ret)
		return ret;

1076 1077
	iwl_mvm_fw_dbg_collect(mvm, FW_DBG_TRIGGER_USER, buf,
			       (count - 1), NULL);
1078 1079

	iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
1080 1081 1082 1083

	return count;
}

1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
static ssize_t iwl_dbgfs_max_amsdu_len_write(struct iwl_mvm *mvm,
					     char *buf, size_t count,
					     loff_t *ppos)
{
	unsigned int max_amsdu_len;
	int ret;

	ret = kstrtouint(buf, 0, &max_amsdu_len);

	if (max_amsdu_len > IEEE80211_MAX_MPDU_LEN_VHT_11454)
		return -EINVAL;
	mvm->max_amsdu_len = max_amsdu_len;

	return count;
}

1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200
#define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__)
#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
static ssize_t iwl_dbgfs_bcast_filters_read(struct file *file,
					    char __user *user_buf,
					    size_t count, loff_t *ppos)
{
	struct iwl_mvm *mvm = file->private_data;
	struct iwl_bcast_filter_cmd cmd;
	const struct iwl_fw_bcast_filter *filter;
	char *buf;
	int bufsz = 1024;
	int i, j, pos = 0;
	ssize_t ret;

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

	mutex_lock(&mvm->mutex);
	if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
		ADD_TEXT("None\n");
		mutex_unlock(&mvm->mutex);
		goto out;
	}
	mutex_unlock(&mvm->mutex);

	for (i = 0; cmd.filters[i].attrs[0].mask; i++) {
		filter = &cmd.filters[i];

		ADD_TEXT("Filter [%d]:\n", i);
		ADD_TEXT("\tDiscard=%d\n", filter->discard);
		ADD_TEXT("\tFrame Type: %s\n",
			 filter->frame_type ? "IPv4" : "Generic");

		for (j = 0; j < ARRAY_SIZE(filter->attrs); j++) {
			const struct iwl_fw_bcast_filter_attr *attr;

			attr = &filter->attrs[j];
			if (!attr->mask)
				break;

			ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n",
				 j, attr->offset,
				 attr->offset_type ? "IP End" :
						     "Payload Start",
				 be32_to_cpu(attr->mask),
				 be32_to_cpu(attr->val),
				 le16_to_cpu(attr->reserved1));
		}
	}
out:
	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	kfree(buf);
	return ret;
}

static ssize_t iwl_dbgfs_bcast_filters_write(struct iwl_mvm *mvm, char *buf,
					     size_t count, loff_t *ppos)
{
	int pos, next_pos;
	struct iwl_fw_bcast_filter filter = {};
	struct iwl_bcast_filter_cmd cmd;
	u32 filter_id, attr_id, mask, value;
	int err = 0;

	if (sscanf(buf, "%d %hhi %hhi %n", &filter_id, &filter.discard,
		   &filter.frame_type, &pos) != 3)
		return -EINVAL;

	if (filter_id >= ARRAY_SIZE(mvm->dbgfs_bcast_filtering.cmd.filters) ||
	    filter.frame_type > BCAST_FILTER_FRAME_TYPE_IPV4)
		return -EINVAL;

	for (attr_id = 0; attr_id < ARRAY_SIZE(filter.attrs);
	     attr_id++) {
		struct iwl_fw_bcast_filter_attr *attr =
				&filter.attrs[attr_id];

		if (pos >= count)
			break;

		if (sscanf(&buf[pos], "%hhi %hhi %i %i %n",
			   &attr->offset, &attr->offset_type,
			   &mask, &value, &next_pos) != 4)
			return -EINVAL;

		attr->mask = cpu_to_be32(mask);
		attr->val = cpu_to_be32(value);
		if (mask)
			filter.num_attrs++;

		pos += next_pos;
	}

	mutex_lock(&mvm->mutex);
	memcpy(&mvm->dbgfs_bcast_filtering.cmd.filters[filter_id],
	       &filter, sizeof(filter));

	/* send updated bcast filtering configuration */
	if (mvm->dbgfs_bcast_filtering.override &&
	    iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
E
Emmanuel Grumbach 已提交
1201
		err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272
					   sizeof(cmd), &cmd);
	mutex_unlock(&mvm->mutex);

	return err ?: count;
}

static ssize_t iwl_dbgfs_bcast_filters_macs_read(struct file *file,
						 char __user *user_buf,
						 size_t count, loff_t *ppos)
{
	struct iwl_mvm *mvm = file->private_data;
	struct iwl_bcast_filter_cmd cmd;
	char *buf;
	int bufsz = 1024;
	int i, pos = 0;
	ssize_t ret;

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

	mutex_lock(&mvm->mutex);
	if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
		ADD_TEXT("None\n");
		mutex_unlock(&mvm->mutex);
		goto out;
	}
	mutex_unlock(&mvm->mutex);

	for (i = 0; i < ARRAY_SIZE(cmd.macs); i++) {
		const struct iwl_fw_bcast_mac *mac = &cmd.macs[i];

		ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n",
			 i, mac->default_discard, mac->attached_filters);
	}
out:
	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	kfree(buf);
	return ret;
}

static ssize_t iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm *mvm,
						  char *buf, size_t count,
						  loff_t *ppos)
{
	struct iwl_bcast_filter_cmd cmd;
	struct iwl_fw_bcast_mac mac = {};
	u32 mac_id, attached_filters;
	int err = 0;

	if (!mvm->bcast_filters)
		return -ENOENT;

	if (sscanf(buf, "%d %hhi %i", &mac_id, &mac.default_discard,
		   &attached_filters) != 3)
		return -EINVAL;

	if (mac_id >= ARRAY_SIZE(cmd.macs) ||
	    mac.default_discard > 1 ||
	    attached_filters >= BIT(ARRAY_SIZE(cmd.filters)))
		return -EINVAL;

	mac.attached_filters = cpu_to_le16(attached_filters);

	mutex_lock(&mvm->mutex);
	memcpy(&mvm->dbgfs_bcast_filtering.cmd.macs[mac_id],
	       &mac, sizeof(mac));

	/* send updated bcast filtering configuration */
	if (mvm->dbgfs_bcast_filtering.override &&
	    iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
E
Emmanuel Grumbach 已提交
1273
		err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1274 1275 1276 1277 1278 1279 1280
					   sizeof(cmd), &cmd);
	mutex_unlock(&mvm->mutex);

	return err ?: count;
}
#endif

1281
#ifdef CONFIG_PM_SLEEP
1282
static ssize_t iwl_dbgfs_d3_sram_write(struct iwl_mvm *mvm, char *buf,
1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318
				       size_t count, loff_t *ppos)
{
	int store;

	if (sscanf(buf, "%d", &store) != 1)
		return -EINVAL;

	mvm->store_d3_resume_sram = store;

	return count;
}

static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
				      size_t count, loff_t *ppos)
{
	struct iwl_mvm *mvm = file->private_data;
	const struct fw_img *img;
	int ofs, len, pos = 0;
	size_t bufsz, ret;
	char *buf;
	u8 *ptr = mvm->d3_resume_sram;

	img = &mvm->fw->img[IWL_UCODE_WOWLAN];
	len = img->sec[IWL_UCODE_SECTION_DATA].len;

	bufsz = len * 4 + 256;
	buf = kzalloc(bufsz, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;

	pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
			 mvm->store_d3_resume_sram ? "en" : "dis");

	if (ptr) {
		for (ofs = 0; ofs < len; ofs += 16) {
			pos += scnprintf(buf + pos, bufsz - pos,
1319
					 "0x%.4x %16ph\n", ofs, ptr + ofs);
1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333
		}
	} else {
		pos += scnprintf(buf + pos, bufsz - pos,
				 "(no data captured)\n");
	}

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

	kfree(buf);

	return ret;
}
#endif

1334 1335 1336 1337 1338
#define PRINT_MVM_REF(ref) do {						\
	if (mvm->refs[ref])						\
		pos += scnprintf(buf + pos, bufsz - pos,		\
				 "\t(0x%lx): %d %s\n",			\
				 BIT(ref), mvm->refs[ref], #ref);	\
1339 1340 1341 1342 1343 1344 1345
} while (0)

static ssize_t iwl_dbgfs_d0i3_refs_read(struct file *file,
					char __user *user_buf,
					size_t count, loff_t *ppos)
{
	struct iwl_mvm *mvm = file->private_data;
1346
	int i, pos = 0;
1347 1348
	char buf[256];
	const size_t bufsz = sizeof(buf);
1349 1350 1351 1352 1353
	u32 refs = 0;

	for (i = 0; i < IWL_MVM_REF_COUNT; i++)
		if (mvm->refs[i])
			refs |= BIT(i);
1354

1355 1356
	pos += scnprintf(buf + pos, bufsz - pos, "taken mvm refs: 0x%x\n",
			 refs);
1357 1358 1359 1360

	PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN);
	PRINT_MVM_REF(IWL_MVM_REF_SCAN);
	PRINT_MVM_REF(IWL_MVM_REF_ROC);
1361
	PRINT_MVM_REF(IWL_MVM_REF_ROC_AUX);
1362 1363
	PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT);
	PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS);
1364
	PRINT_MVM_REF(IWL_MVM_REF_USER);
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376
	PRINT_MVM_REF(IWL_MVM_REF_TX);
	PRINT_MVM_REF(IWL_MVM_REF_TX_AGG);
	PRINT_MVM_REF(IWL_MVM_REF_ADD_IF);
	PRINT_MVM_REF(IWL_MVM_REF_START_AP);
	PRINT_MVM_REF(IWL_MVM_REF_BSS_CHANGED);
	PRINT_MVM_REF(IWL_MVM_REF_PREPARE_TX);
	PRINT_MVM_REF(IWL_MVM_REF_PROTECT_TDLS);
	PRINT_MVM_REF(IWL_MVM_REF_CHECK_CTKILL);
	PRINT_MVM_REF(IWL_MVM_REF_PRPH_READ);
	PRINT_MVM_REF(IWL_MVM_REF_PRPH_WRITE);
	PRINT_MVM_REF(IWL_MVM_REF_NMI);
	PRINT_MVM_REF(IWL_MVM_REF_TM_CMD);
1377
	PRINT_MVM_REF(IWL_MVM_REF_EXIT_WORK);
1378
	PRINT_MVM_REF(IWL_MVM_REF_PROTECT_CSA);
1379
	PRINT_MVM_REF(IWL_MVM_REF_FW_DBG_COLLECT);
1380
	PRINT_MVM_REF(IWL_MVM_REF_INIT_UCODE);
1381 1382 1383 1384

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

1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397
static ssize_t iwl_dbgfs_d0i3_refs_write(struct iwl_mvm *mvm, char *buf,
					 size_t count, loff_t *ppos)
{
	unsigned long value;
	int ret;
	bool taken;

	ret = kstrtoul(buf, 10, &value);
	if (ret < 0)
		return ret;

	mutex_lock(&mvm->mutex);

1398
	taken = mvm->refs[IWL_MVM_REF_USER];
1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412
	if (value == 1 && !taken)
		iwl_mvm_ref(mvm, IWL_MVM_REF_USER);
	else if (value == 0 && taken)
		iwl_mvm_unref(mvm, IWL_MVM_REF_USER);
	else
		ret = -EINVAL;

	mutex_unlock(&mvm->mutex);

	if (ret < 0)
		return ret;
	return count;
}

1413 1414 1415 1416
#define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
	_MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
#define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
	_MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1417 1418
#define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do {	\
		if (!debugfs_create_file(alias, mode, parent, mvm,	\
J
Johannes Berg 已提交
1419 1420 1421
					 &iwl_dbgfs_##name##_ops))	\
			goto err;					\
	} while (0)
1422 1423
#define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
	MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
J
Johannes Berg 已提交
1424

1425 1426 1427 1428 1429 1430 1431 1432 1433
static ssize_t
iwl_dbgfs_prph_reg_read(struct file *file,
			char __user *user_buf,
			size_t count, loff_t *ppos)
{
	struct iwl_mvm *mvm = file->private_data;
	int pos = 0;
	char buf[32];
	const size_t bufsz = sizeof(buf);
1434
	int ret;
1435 1436 1437 1438

	if (!mvm->dbgfs_prph_reg_addr)
		return -EINVAL;

1439 1440 1441 1442
	ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_READ);
	if (ret)
		return ret;

1443 1444 1445 1446
	pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n",
		mvm->dbgfs_prph_reg_addr,
		iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr));

1447 1448
	iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_READ);

1449 1450 1451 1452 1453 1454 1455 1456 1457
	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
}

static ssize_t
iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf,
			 size_t count, loff_t *ppos)
{
	u8 args;
	u32 value;
1458
	int ret;
1459 1460 1461 1462 1463 1464 1465 1466 1467 1468

	args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value);
	/* if we only want to set the reg address - nothing more to do */
	if (args == 1)
		goto out;

	/* otherwise, make sure we have both address and value */
	if (args != 2)
		return -EINVAL;

1469 1470 1471 1472
	ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
	if (ret)
		return ret;

1473
	iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value);
1474 1475

	iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
1476 1477 1478 1479
out:
	return count;
}

1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492
static ssize_t
iwl_dbgfs_send_echo_cmd_write(struct iwl_mvm *mvm, char *buf,
			      size_t count, loff_t *ppos)
{
	int ret;

	mutex_lock(&mvm->mutex);
	ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL);
	mutex_unlock(&mvm->mutex);

	return ret ?: count;
}

1493 1494
MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);

J
Johannes Berg 已提交
1495
/* Device wide debugfs entries */
1496 1497
MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
1498
MVM_DEBUGFS_WRITE_FILE_OPS(send_echo_cmd, 8);
1499
MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64);
1500
MVM_DEBUGFS_READ_WRITE_FILE_OPS(set_nic_temperature, 64);
1501
MVM_DEBUGFS_READ_FILE_OPS(nic_temp);
J
Johannes Berg 已提交
1502
MVM_DEBUGFS_READ_FILE_OPS(stations);
1503
MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
1504
MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
1505
MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64);
1506
MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
1507
MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats);
1508 1509
MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10);
MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10);
1510
MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10);
1511
MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant, 10);
1512
MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
1513
MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8);
1514
MVM_DEBUGFS_READ_WRITE_FILE_OPS(fw_dbg_conf, 8);
1515
MVM_DEBUGFS_WRITE_FILE_OPS(fw_dbg_collect, 64);
1516
MVM_DEBUGFS_WRITE_FILE_OPS(cont_recording, 8);
1517
MVM_DEBUGFS_WRITE_FILE_OPS(max_amsdu_len, 8);
S
Sara Sharon 已提交
1518 1519
MVM_DEBUGFS_WRITE_FILE_OPS(indirection_tbl,
			   (IWL_RSS_INDIRECTION_TABLE_SIZE * 2));
1520

1521 1522 1523 1524 1525
#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256);
MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256);
#endif

1526
#ifdef CONFIG_PM_SLEEP
1527
MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8);
1528
#endif
J
Johannes Berg 已提交
1529 1530 1531

int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
{
1532
	struct dentry *bcast_dir __maybe_unused;
J
Johannes Berg 已提交
1533 1534
	char buf[100];

1535 1536
	spin_lock_init(&mvm->drv_stats_lock);

J
Johannes Berg 已提交
1537 1538 1539 1540 1541
	mvm->debugfs_dir = dbgfs_dir;

	MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
	MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
	MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
1542 1543
	MVM_DEBUGFS_ADD_FILE(set_nic_temperature, mvm->debugfs_dir,
			     S_IWUSR | S_IRUSR);
1544
	MVM_DEBUGFS_ADD_FILE(nic_temp, dbgfs_dir, S_IRUSR);
J
Johannes Berg 已提交
1545
	MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
1546
	MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
1547
	MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
1548 1549
	MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
			     S_IRUSR | S_IWUSR);
1550
	MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
1551
	MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, S_IRUSR);
1552
	MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
1553
	MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR);
1554
	MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, S_IWUSR);
1555
	MVM_DEBUGFS_ADD_FILE(bt_force_ant, mvm->debugfs_dir, S_IWUSR);
1556 1557
	MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
			     S_IWUSR | S_IRUSR);
1558
	MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
1559
	MVM_DEBUGFS_ADD_FILE(d0i3_refs, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
1560 1561
	MVM_DEBUGFS_ADD_FILE(fw_dbg_conf, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
	MVM_DEBUGFS_ADD_FILE(fw_dbg_collect, mvm->debugfs_dir, S_IWUSR);
1562
	MVM_DEBUGFS_ADD_FILE(max_amsdu_len, mvm->debugfs_dir, S_IWUSR);
1563
	MVM_DEBUGFS_ADD_FILE(send_echo_cmd, mvm->debugfs_dir, S_IWUSR);
1564
	MVM_DEBUGFS_ADD_FILE(cont_recording, mvm->debugfs_dir, S_IWUSR);
1565
	MVM_DEBUGFS_ADD_FILE(indirection_tbl, mvm->debugfs_dir, S_IWUSR);
1566 1567 1568 1569 1570
	if (!debugfs_create_bool("enable_scan_iteration_notif",
				 S_IRUSR | S_IWUSR,
				 mvm->debugfs_dir,
				 &mvm->scan_iter_notif_enabled))
		goto err;
1571 1572 1573
	if (!debugfs_create_bool("drop_bcn_ap_mode", S_IRUSR | S_IWUSR,
				 mvm->debugfs_dir, &mvm->drop_bcn_ap_mode))
		goto err;
1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593

#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
	if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING) {
		bcast_dir = debugfs_create_dir("bcast_filtering",
					       mvm->debugfs_dir);
		if (!bcast_dir)
			goto err;

		if (!debugfs_create_bool("override", S_IRUSR | S_IWUSR,
				bcast_dir,
				&mvm->dbgfs_bcast_filtering.override))
			goto err;

		MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters,
					   bcast_dir, S_IWUSR | S_IRUSR);
		MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs,
					   bcast_dir, S_IWUSR | S_IRUSR);
	}
#endif

1594 1595
#ifdef CONFIG_PM_SLEEP
	MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
1596
	MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
1597 1598 1599
	if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
				 mvm->debugfs_dir, &mvm->d3_wake_sysassert))
		goto err;
1600 1601 1602
	if (!debugfs_create_u32("last_netdetect_scans", S_IRUSR,
				mvm->debugfs_dir, &mvm->last_netdetect_scans))
		goto err;
1603
#endif
J
Johannes Berg 已提交
1604

1605 1606 1607
	if (!debugfs_create_u8("ps_disabled", S_IRUSR,
			       mvm->debugfs_dir, &mvm->ps_disabled))
		goto err;
1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619
	if (!debugfs_create_blob("nvm_hw", S_IRUSR,
				  mvm->debugfs_dir, &mvm->nvm_hw_blob))
		goto err;
	if (!debugfs_create_blob("nvm_sw", S_IRUSR,
				  mvm->debugfs_dir, &mvm->nvm_sw_blob))
		goto err;
	if (!debugfs_create_blob("nvm_calib", S_IRUSR,
				  mvm->debugfs_dir, &mvm->nvm_calib_blob))
		goto err;
	if (!debugfs_create_blob("nvm_prod", S_IRUSR,
				  mvm->debugfs_dir, &mvm->nvm_prod_blob))
		goto err;
1620 1621 1622
	if (!debugfs_create_blob("nvm_phy_sku", S_IRUSR,
				 mvm->debugfs_dir, &mvm->nvm_phy_sku_blob))
		goto err;
1623

J
Johannes Berg 已提交
1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638
	/*
	 * Create a symlink with mac80211. It will be removed when mac80211
	 * exists (before the opmode exists which removes the target.)
	 */
	snprintf(buf, 100, "../../%s/%s",
		 dbgfs_dir->d_parent->d_parent->d_name.name,
		 dbgfs_dir->d_parent->d_name.name);
	if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
		goto err;

	return 0;
err:
	IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
	return -ENOMEM;
}