1 /******************************************************************************
2  *
3  * This file is provided under a dual BSD/GPLv2 license.  When using or
4  * redistributing this file, you may do so under either license.
5  *
6  * GPL LICENSE SUMMARY
7  *
8  * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9  * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10  * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
11  * Copyright(c) 2018 - 2019 Intel Corporation
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of version 2 of the GNU General Public License as
15  * published by the Free Software Foundation.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * General Public License for more details.
21  *
22  * The full GNU General Public License is included in this distribution
23  * in the file called COPYING.
24  *
25  * Contact Information:
26  *  Intel Linux Wireless <linuxwifi@intel.com>
27  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28  *
29  * BSD LICENSE
30  *
31  * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
32  * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
33  * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
34  * Copyright(c) 2018 - 2019 Intel Corporation
35  * All rights reserved.
36  *
37  * Redistribution and use in source and binary forms, with or without
38  * modification, are permitted provided that the following conditions
39  * are met:
40  *
41  *  * Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  *  * Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in
45  *    the documentation and/or other materials provided with the
46  *    distribution.
47  *  * Neither the name Intel Corporation nor the names of its
48  *    contributors may be used to endorse or promote products derived
49  *    from this software without specific prior written permission.
50  *
51  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62  *
63  *****************************************************************************/
64 #include <linux/vmalloc.h>
65 #include <linux/ieee80211.h>
66 #include <linux/netdevice.h>
67 
68 #include "mvm.h"
69 #include "sta.h"
70 #include "iwl-io.h"
71 #include "debugfs.h"
72 #include "iwl-modparams.h"
73 #include "fw/error-dump.h"
74 
75 static ssize_t iwl_dbgfs_ctdp_budget_read(struct file *file,
76 					  char __user *user_buf,
77 					  size_t count, loff_t *ppos)
78 {
79 	struct iwl_mvm *mvm = file->private_data;
80 	char buf[16];
81 	int pos, budget;
82 
83 	if (!iwl_mvm_is_ctdp_supported(mvm))
84 		return -EOPNOTSUPP;
85 
86 	if (!iwl_mvm_firmware_running(mvm) ||
87 	    mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
88 		return -EIO;
89 
90 	mutex_lock(&mvm->mutex);
91 	budget = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_REPORT, 0);
92 	mutex_unlock(&mvm->mutex);
93 
94 	if (budget < 0)
95 		return budget;
96 
97 	pos = scnprintf(buf, sizeof(buf), "%d\n", budget);
98 
99 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
100 }
101 
102 static ssize_t iwl_dbgfs_stop_ctdp_write(struct iwl_mvm *mvm, char *buf,
103 					 size_t count, loff_t *ppos)
104 {
105 	int ret;
106 
107 	if (!iwl_mvm_is_ctdp_supported(mvm))
108 		return -EOPNOTSUPP;
109 
110 	if (!iwl_mvm_firmware_running(mvm) ||
111 	    mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
112 		return -EIO;
113 
114 	mutex_lock(&mvm->mutex);
115 	ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_STOP, 0);
116 	mutex_unlock(&mvm->mutex);
117 
118 	return ret ?: count;
119 }
120 
121 static ssize_t iwl_dbgfs_force_ctkill_write(struct iwl_mvm *mvm, char *buf,
122 					    size_t count, loff_t *ppos)
123 {
124 	if (!iwl_mvm_firmware_running(mvm) ||
125 	    mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
126 		return -EIO;
127 
128 	iwl_mvm_enter_ctkill(mvm);
129 
130 	return count;
131 }
132 
133 static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf,
134 					size_t count, loff_t *ppos)
135 {
136 	int ret;
137 	u32 flush_arg;
138 
139 	if (!iwl_mvm_firmware_running(mvm) ||
140 	    mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
141 		return -EIO;
142 
143 	if (kstrtou32(buf, 0, &flush_arg))
144 		return -EINVAL;
145 
146 	if (iwl_mvm_has_new_tx_api(mvm)) {
147 		IWL_DEBUG_TX_QUEUES(mvm,
148 				    "FLUSHING all tids queues on sta_id = %d\n",
149 				    flush_arg);
150 		mutex_lock(&mvm->mutex);
151 		ret = iwl_mvm_flush_sta_tids(mvm, flush_arg, 0xFFFF, 0)
152 			? : count;
153 		mutex_unlock(&mvm->mutex);
154 		return ret;
155 	}
156 
157 	IWL_DEBUG_TX_QUEUES(mvm, "FLUSHING queues mask to flush = 0x%x\n",
158 			    flush_arg);
159 
160 	mutex_lock(&mvm->mutex);
161 	ret =  iwl_mvm_flush_tx_path(mvm, flush_arg, 0) ? : count;
162 	mutex_unlock(&mvm->mutex);
163 
164 	return ret;
165 }
166 
167 static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf,
168 					 size_t count, loff_t *ppos)
169 {
170 	struct iwl_mvm_sta *mvmsta;
171 	int sta_id, drain, ret;
172 
173 	if (!iwl_mvm_firmware_running(mvm) ||
174 	    mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
175 		return -EIO;
176 
177 	if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
178 		return -EINVAL;
179 	if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
180 		return -EINVAL;
181 	if (drain < 0 || drain > 1)
182 		return -EINVAL;
183 
184 	mutex_lock(&mvm->mutex);
185 
186 	mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
187 
188 	if (!mvmsta)
189 		ret = -ENOENT;
190 	else
191 		ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count;
192 
193 	mutex_unlock(&mvm->mutex);
194 
195 	return ret;
196 }
197 
198 static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
199 				   size_t count, loff_t *ppos)
200 {
201 	struct iwl_mvm *mvm = file->private_data;
202 	const struct fw_img *img;
203 	unsigned int ofs, len;
204 	size_t ret;
205 	u8 *ptr;
206 
207 	if (!iwl_mvm_firmware_running(mvm))
208 		return -EINVAL;
209 
210 	/* default is to dump the entire data segment */
211 	img = &mvm->fw->img[mvm->fwrt.cur_fw_img];
212 	ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
213 	len = img->sec[IWL_UCODE_SECTION_DATA].len;
214 
215 	if (mvm->dbgfs_sram_len) {
216 		ofs = mvm->dbgfs_sram_offset;
217 		len = mvm->dbgfs_sram_len;
218 	}
219 
220 	ptr = kzalloc(len, GFP_KERNEL);
221 	if (!ptr)
222 		return -ENOMEM;
223 
224 	iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
225 
226 	ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len);
227 
228 	kfree(ptr);
229 
230 	return ret;
231 }
232 
233 static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf,
234 				    size_t count, loff_t *ppos)
235 {
236 	const struct fw_img *img;
237 	u32 offset, len;
238 	u32 img_offset, img_len;
239 
240 	if (!iwl_mvm_firmware_running(mvm))
241 		return -EINVAL;
242 
243 	img = &mvm->fw->img[mvm->fwrt.cur_fw_img];
244 	img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset;
245 	img_len = img->sec[IWL_UCODE_SECTION_DATA].len;
246 
247 	if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
248 		if ((offset & 0x3) || (len & 0x3))
249 			return -EINVAL;
250 
251 		if (offset + len > img_offset + img_len)
252 			return -EINVAL;
253 
254 		mvm->dbgfs_sram_offset = offset;
255 		mvm->dbgfs_sram_len = len;
256 	} else {
257 		mvm->dbgfs_sram_offset = 0;
258 		mvm->dbgfs_sram_len = 0;
259 	}
260 
261 	return count;
262 }
263 
264 static ssize_t iwl_dbgfs_set_nic_temperature_read(struct file *file,
265 						  char __user *user_buf,
266 						  size_t count, loff_t *ppos)
267 {
268 	struct iwl_mvm *mvm = file->private_data;
269 	char buf[16];
270 	int pos;
271 
272 	if (!mvm->temperature_test)
273 		pos = scnprintf(buf , sizeof(buf), "disabled\n");
274 	else
275 		pos = scnprintf(buf , sizeof(buf), "%d\n", mvm->temperature);
276 
277 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
278 }
279 
280 /*
281  * Set NIC Temperature
282  * Cause the driver to ignore the actual NIC temperature reported by the FW
283  * Enable: any value between IWL_MVM_DEBUG_SET_TEMPERATURE_MIN -
284  * IWL_MVM_DEBUG_SET_TEMPERATURE_MAX
285  * Disable: IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE
286  */
287 static ssize_t iwl_dbgfs_set_nic_temperature_write(struct iwl_mvm *mvm,
288 						   char *buf, size_t count,
289 						   loff_t *ppos)
290 {
291 	int temperature;
292 
293 	if (!iwl_mvm_firmware_running(mvm) && !mvm->temperature_test)
294 		return -EIO;
295 
296 	if (kstrtoint(buf, 10, &temperature))
297 		return -EINVAL;
298 	/* not a legal temperature */
299 	if ((temperature > IWL_MVM_DEBUG_SET_TEMPERATURE_MAX &&
300 	     temperature != IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) ||
301 	    temperature < IWL_MVM_DEBUG_SET_TEMPERATURE_MIN)
302 		return -EINVAL;
303 
304 	mutex_lock(&mvm->mutex);
305 	if (temperature == IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) {
306 		if (!mvm->temperature_test)
307 			goto out;
308 
309 		mvm->temperature_test = false;
310 		/* Since we can't read the temp while awake, just set
311 		 * it to zero until we get the next RX stats from the
312 		 * firmware.
313 		 */
314 		mvm->temperature = 0;
315 	} else {
316 		mvm->temperature_test = true;
317 		mvm->temperature = temperature;
318 	}
319 	IWL_DEBUG_TEMP(mvm, "%sabling debug set temperature (temp = %d)\n",
320 		       mvm->temperature_test ? "En" : "Dis" ,
321 		       mvm->temperature);
322 	/* handle the temperature change */
323 	iwl_mvm_tt_handler(mvm);
324 
325 out:
326 	mutex_unlock(&mvm->mutex);
327 
328 	return count;
329 }
330 
331 static ssize_t iwl_dbgfs_nic_temp_read(struct file *file,
332 				       char __user *user_buf,
333 				       size_t count, loff_t *ppos)
334 {
335 	struct iwl_mvm *mvm = file->private_data;
336 	char buf[16];
337 	int pos, ret;
338 	s32 temp;
339 
340 	if (!iwl_mvm_firmware_running(mvm))
341 		return -EIO;
342 
343 	mutex_lock(&mvm->mutex);
344 	ret = iwl_mvm_get_temp(mvm, &temp);
345 	mutex_unlock(&mvm->mutex);
346 
347 	if (ret)
348 		return -EIO;
349 
350 	pos = scnprintf(buf , sizeof(buf), "%d\n", temp);
351 
352 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
353 }
354 
355 #ifdef CONFIG_ACPI
356 static ssize_t iwl_dbgfs_sar_geo_profile_read(struct file *file,
357 					      char __user *user_buf,
358 					      size_t count, loff_t *ppos)
359 {
360 	struct iwl_mvm *mvm = file->private_data;
361 	char buf[256];
362 	int pos = 0;
363 	int bufsz = sizeof(buf);
364 	int tbl_idx;
365 	u8 *value;
366 
367 	if (!iwl_mvm_firmware_running(mvm))
368 		return -EIO;
369 
370 	mutex_lock(&mvm->mutex);
371 	tbl_idx = iwl_mvm_get_sar_geo_profile(mvm);
372 	if (tbl_idx < 0) {
373 		mutex_unlock(&mvm->mutex);
374 		return tbl_idx;
375 	}
376 
377 	if (!tbl_idx) {
378 		pos = scnprintf(buf, bufsz,
379 				"SAR geographic profile disabled\n");
380 	} else {
381 		value = &mvm->fwrt.geo_profiles[tbl_idx - 1].values[0];
382 
383 		pos += scnprintf(buf + pos, bufsz - pos,
384 				 "Use geographic profile %d\n", tbl_idx);
385 		pos += scnprintf(buf + pos, bufsz - pos,
386 				 "2.4GHz:\n\tChain A offset: %hhd dBm\n\tChain B offset: %hhd dBm\n\tmax tx power: %hhd dBm\n",
387 				 value[1], value[2], value[0]);
388 		pos += scnprintf(buf + pos, bufsz - pos,
389 				 "5.2GHz:\n\tChain A offset: %hhd dBm\n\tChain B offset: %hhd dBm\n\tmax tx power: %hhd dBm\n",
390 				 value[4], value[5], value[3]);
391 	}
392 	mutex_unlock(&mvm->mutex);
393 
394 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
395 }
396 #endif
397 
398 static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
399 				       size_t count, loff_t *ppos)
400 {
401 	struct iwl_mvm *mvm = file->private_data;
402 	struct ieee80211_sta *sta;
403 	char buf[400];
404 	int i, pos = 0, bufsz = sizeof(buf);
405 
406 	mutex_lock(&mvm->mutex);
407 
408 	for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
409 		pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
410 		sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
411 						lockdep_is_held(&mvm->mutex));
412 		if (!sta)
413 			pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
414 		else if (IS_ERR(sta))
415 			pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
416 					 PTR_ERR(sta));
417 		else
418 			pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
419 					 sta->addr);
420 	}
421 
422 	mutex_unlock(&mvm->mutex);
423 
424 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
425 }
426 
427 static ssize_t iwl_dbgfs_rs_data_read(struct file *file, char __user *user_buf,
428 				      size_t count, loff_t *ppos)
429 {
430 	struct ieee80211_sta *sta = file->private_data;
431 	struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
432 	struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->lq_sta.rs_fw;
433 	struct iwl_mvm *mvm = lq_sta->pers.drv;
434 	static const size_t bufsz = 2048;
435 	char *buff;
436 	int desc = 0;
437 	ssize_t ret;
438 
439 	buff = kmalloc(bufsz, GFP_KERNEL);
440 	if (!buff)
441 		return -ENOMEM;
442 
443 	mutex_lock(&mvm->mutex);
444 
445 	desc += scnprintf(buff + desc, bufsz - desc, "sta_id %d\n",
446 			  lq_sta->pers.sta_id);
447 	desc += scnprintf(buff + desc, bufsz - desc,
448 			  "fixed rate 0x%X\n",
449 			  lq_sta->pers.dbg_fixed_rate);
450 	desc += scnprintf(buff + desc, bufsz - desc,
451 			  "A-MPDU size limit %d\n",
452 			  lq_sta->pers.dbg_agg_frame_count_lim);
453 	desc += scnprintf(buff + desc, bufsz - desc,
454 			  "valid_tx_ant %s%s%s\n",
455 		(iwl_mvm_get_valid_tx_ant(mvm) & ANT_A) ? "ANT_A," : "",
456 		(iwl_mvm_get_valid_tx_ant(mvm) & ANT_B) ? "ANT_B," : "",
457 		(iwl_mvm_get_valid_tx_ant(mvm) & ANT_C) ? "ANT_C" : "");
458 	desc += scnprintf(buff + desc, bufsz - desc,
459 			  "last tx rate=0x%X ",
460 			  lq_sta->last_rate_n_flags);
461 
462 	desc += rs_pretty_print_rate(buff + desc, bufsz - desc,
463 				     lq_sta->last_rate_n_flags);
464 	if (desc < bufsz - 1)
465 		buff[desc++] = '\n';
466 	mutex_unlock(&mvm->mutex);
467 
468 	ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
469 	kfree(buff);
470 	return ret;
471 }
472 
473 static ssize_t iwl_dbgfs_amsdu_len_write(struct ieee80211_sta *sta,
474 					 char *buf, size_t count,
475 					 loff_t *ppos)
476 {
477 	struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
478 	int i;
479 	u16 amsdu_len;
480 
481 	if (kstrtou16(buf, 0, &amsdu_len))
482 		return -EINVAL;
483 
484 	if (amsdu_len) {
485 		mvmsta->orig_amsdu_len = sta->max_amsdu_len;
486 		sta->max_amsdu_len = amsdu_len;
487 		for (i = 0; i < ARRAY_SIZE(sta->max_tid_amsdu_len); i++)
488 			sta->max_tid_amsdu_len[i] = amsdu_len;
489 	} else {
490 		sta->max_amsdu_len = mvmsta->orig_amsdu_len;
491 		mvmsta->orig_amsdu_len = 0;
492 	}
493 	return count;
494 }
495 
496 static ssize_t iwl_dbgfs_amsdu_len_read(struct file *file,
497 					char __user *user_buf,
498 					size_t count, loff_t *ppos)
499 {
500 	struct ieee80211_sta *sta = file->private_data;
501 	struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
502 
503 	char buf[32];
504 	int pos;
505 
506 	pos = scnprintf(buf, sizeof(buf), "current %d ", sta->max_amsdu_len);
507 	pos += scnprintf(buf + pos, sizeof(buf) - pos, "stored %d\n",
508 			 mvmsta->orig_amsdu_len);
509 
510 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
511 }
512 
513 static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
514 						char __user *user_buf,
515 						size_t count, loff_t *ppos)
516 {
517 	struct iwl_mvm *mvm = file->private_data;
518 	char buf[64];
519 	int bufsz = sizeof(buf);
520 	int pos = 0;
521 
522 	pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
523 			 mvm->disable_power_off);
524 	pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
525 			 mvm->disable_power_off_d3);
526 
527 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
528 }
529 
530 static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf,
531 						 size_t count, loff_t *ppos)
532 {
533 	int ret, val;
534 
535 	if (!iwl_mvm_firmware_running(mvm))
536 		return -EIO;
537 
538 	if (!strncmp("disable_power_off_d0=", buf, 21)) {
539 		if (sscanf(buf + 21, "%d", &val) != 1)
540 			return -EINVAL;
541 		mvm->disable_power_off = val;
542 	} else if (!strncmp("disable_power_off_d3=", buf, 21)) {
543 		if (sscanf(buf + 21, "%d", &val) != 1)
544 			return -EINVAL;
545 		mvm->disable_power_off_d3 = val;
546 	} else {
547 		return -EINVAL;
548 	}
549 
550 	mutex_lock(&mvm->mutex);
551 	ret = iwl_mvm_power_update_device(mvm);
552 	mutex_unlock(&mvm->mutex);
553 
554 	return ret ?: count;
555 }
556 
557 static
558 int iwl_mvm_coex_dump_mbox(struct iwl_bt_coex_profile_notif *notif, char *buf,
559 			   int pos, int bufsz)
560 {
561 	pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
562 
563 	BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
564 	BT_MBOX_PRINT(0, LE_PROF1, false);
565 	BT_MBOX_PRINT(0, LE_PROF2, false);
566 	BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
567 	BT_MBOX_PRINT(0, CHL_SEQ_N, false);
568 	BT_MBOX_PRINT(0, INBAND_S, false);
569 	BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
570 	BT_MBOX_PRINT(0, LE_SCAN, false);
571 	BT_MBOX_PRINT(0, LE_ADV, false);
572 	BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
573 	BT_MBOX_PRINT(0, OPEN_CON_1, true);
574 
575 	pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
576 
577 	BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
578 	BT_MBOX_PRINT(1, IP_SR, false);
579 	BT_MBOX_PRINT(1, LE_MSTR, false);
580 	BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
581 	BT_MBOX_PRINT(1, MSG_TYPE, false);
582 	BT_MBOX_PRINT(1, SSN, true);
583 
584 	pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
585 
586 	BT_MBOX_PRINT(2, SNIFF_ACT, false);
587 	BT_MBOX_PRINT(2, PAG, false);
588 	BT_MBOX_PRINT(2, INQUIRY, false);
589 	BT_MBOX_PRINT(2, CONN, false);
590 	BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
591 	BT_MBOX_PRINT(2, DISC, false);
592 	BT_MBOX_PRINT(2, SCO_TX_ACT, false);
593 	BT_MBOX_PRINT(2, SCO_RX_ACT, false);
594 	BT_MBOX_PRINT(2, ESCO_RE_TX, false);
595 	BT_MBOX_PRINT(2, SCO_DURATION, true);
596 
597 	pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
598 
599 	BT_MBOX_PRINT(3, SCO_STATE, false);
600 	BT_MBOX_PRINT(3, SNIFF_STATE, false);
601 	BT_MBOX_PRINT(3, A2DP_STATE, false);
602 	BT_MBOX_PRINT(3, A2DP_SRC, false);
603 	BT_MBOX_PRINT(3, ACL_STATE, false);
604 	BT_MBOX_PRINT(3, MSTR_STATE, false);
605 	BT_MBOX_PRINT(3, OBX_STATE, false);
606 	BT_MBOX_PRINT(3, OPEN_CON_2, false);
607 	BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
608 	BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
609 	BT_MBOX_PRINT(3, INBAND_P, false);
610 	BT_MBOX_PRINT(3, MSG_TYPE_2, false);
611 	BT_MBOX_PRINT(3, SSN_2, false);
612 	BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
613 
614 	return pos;
615 }
616 
617 static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
618 				       size_t count, loff_t *ppos)
619 {
620 	struct iwl_mvm *mvm = file->private_data;
621 	struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
622 	char *buf;
623 	int ret, pos = 0, bufsz = sizeof(char) * 1024;
624 
625 	buf = kmalloc(bufsz, GFP_KERNEL);
626 	if (!buf)
627 		return -ENOMEM;
628 
629 	mutex_lock(&mvm->mutex);
630 
631 	pos += iwl_mvm_coex_dump_mbox(notif, buf, pos, bufsz);
632 
633 	pos += scnprintf(buf + pos, bufsz - pos, "bt_ci_compliance = %d\n",
634 			 notif->bt_ci_compliance);
635 	pos += scnprintf(buf + pos, bufsz - pos, "primary_ch_lut = %d\n",
636 			 le32_to_cpu(notif->primary_ch_lut));
637 	pos += scnprintf(buf + pos, bufsz - pos, "secondary_ch_lut = %d\n",
638 			 le32_to_cpu(notif->secondary_ch_lut));
639 	pos += scnprintf(buf + pos,
640 			 bufsz - pos, "bt_activity_grading = %d\n",
641 			 le32_to_cpu(notif->bt_activity_grading));
642 	pos += scnprintf(buf + pos, bufsz - pos, "bt_rrc = %d\n",
643 			 notif->rrc_status & 0xF);
644 	pos += scnprintf(buf + pos, bufsz - pos, "bt_ttc = %d\n",
645 			 notif->ttc_status & 0xF);
646 
647 	pos += scnprintf(buf + pos, bufsz - pos, "sync_sco = %d\n",
648 			 IWL_MVM_BT_COEX_SYNC2SCO);
649 	pos += scnprintf(buf + pos, bufsz - pos, "mplut = %d\n",
650 			 IWL_MVM_BT_COEX_MPLUT);
651 
652 	mutex_unlock(&mvm->mutex);
653 
654 	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
655 	kfree(buf);
656 
657 	return ret;
658 }
659 #undef BT_MBOX_PRINT
660 
661 static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
662 				     size_t count, loff_t *ppos)
663 {
664 	struct iwl_mvm *mvm = file->private_data;
665 	struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
666 	char buf[256];
667 	int bufsz = sizeof(buf);
668 	int pos = 0;
669 
670 	mutex_lock(&mvm->mutex);
671 
672 	pos += scnprintf(buf + pos, bufsz - pos, "Channel inhibition CMD\n");
673 	pos += scnprintf(buf + pos, bufsz - pos,
674 			 "\tPrimary Channel Bitmap 0x%016llx\n",
675 			 le64_to_cpu(cmd->bt_primary_ci));
676 	pos += scnprintf(buf + pos, bufsz - pos,
677 			 "\tSecondary Channel Bitmap 0x%016llx\n",
678 			 le64_to_cpu(cmd->bt_secondary_ci));
679 
680 	mutex_unlock(&mvm->mutex);
681 
682 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
683 }
684 
685 static ssize_t
686 iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf,
687 			   size_t count, loff_t *ppos)
688 {
689 	u32 bt_tx_prio;
690 
691 	if (sscanf(buf, "%u", &bt_tx_prio) != 1)
692 		return -EINVAL;
693 	if (bt_tx_prio > 4)
694 		return -EINVAL;
695 
696 	mvm->bt_tx_prio = bt_tx_prio;
697 
698 	return count;
699 }
700 
701 static ssize_t
702 iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char *buf,
703 			     size_t count, loff_t *ppos)
704 {
705 	static const char * const modes_str[BT_FORCE_ANT_MAX] = {
706 		[BT_FORCE_ANT_DIS] = "dis",
707 		[BT_FORCE_ANT_AUTO] = "auto",
708 		[BT_FORCE_ANT_BT] = "bt",
709 		[BT_FORCE_ANT_WIFI] = "wifi",
710 	};
711 	int ret, bt_force_ant_mode;
712 
713 	ret = match_string(modes_str, ARRAY_SIZE(modes_str), buf);
714 	if (ret < 0)
715 		return ret;
716 
717 	bt_force_ant_mode = ret;
718 	ret = 0;
719 	mutex_lock(&mvm->mutex);
720 	if (mvm->bt_force_ant_mode == bt_force_ant_mode)
721 		goto out;
722 
723 	mvm->bt_force_ant_mode = bt_force_ant_mode;
724 	IWL_DEBUG_COEX(mvm, "Force mode: %s\n",
725 		       modes_str[mvm->bt_force_ant_mode]);
726 
727 	if (iwl_mvm_firmware_running(mvm))
728 		ret = iwl_mvm_send_bt_init_conf(mvm);
729 	else
730 		ret = 0;
731 
732 out:
733 	mutex_unlock(&mvm->mutex);
734 	return ret ?: count;
735 }
736 
737 static ssize_t iwl_dbgfs_fw_ver_read(struct file *file, char __user *user_buf,
738 				     size_t count, loff_t *ppos)
739 {
740 	struct iwl_mvm *mvm = file->private_data;
741 	char *buff, *pos, *endpos;
742 	static const size_t bufsz = 1024;
743 	int ret;
744 
745 	buff = kmalloc(bufsz, GFP_KERNEL);
746 	if (!buff)
747 		return -ENOMEM;
748 
749 	pos = buff;
750 	endpos = pos + bufsz;
751 
752 	pos += scnprintf(pos, endpos - pos, "FW prefix: %s\n",
753 			 mvm->trans->cfg->fw_name_pre);
754 	pos += scnprintf(pos, endpos - pos, "FW: %s\n",
755 			 mvm->fwrt.fw->human_readable);
756 	pos += scnprintf(pos, endpos - pos, "Device: %s\n",
757 			 mvm->fwrt.trans->name);
758 	pos += scnprintf(pos, endpos - pos, "Bus: %s\n",
759 			 mvm->fwrt.dev->bus->name);
760 
761 	ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
762 	kfree(buff);
763 
764 	return ret;
765 }
766 
767 #define PRINT_STATS_LE32(_struct, _memb)				\
768 			 pos += scnprintf(buf + pos, bufsz - pos,	\
769 					  fmt_table, #_memb,		\
770 					  le32_to_cpu(_struct->_memb))
771 
772 static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
773 					  char __user *user_buf, size_t count,
774 					  loff_t *ppos)
775 {
776 	struct iwl_mvm *mvm = file->private_data;
777 	static const char *fmt_table = "\t%-30s %10u\n";
778 	static const char *fmt_header = "%-32s\n";
779 	int pos = 0;
780 	char *buf;
781 	int ret;
782 	size_t bufsz;
783 
784 	if (iwl_mvm_has_new_rx_stats_api(mvm))
785 		bufsz = ((sizeof(struct mvm_statistics_rx) /
786 			  sizeof(__le32)) * 43) + (4 * 33) + 1;
787 	else
788 		/* 43 = size of each data line; 33 = size of each header */
789 		bufsz = ((sizeof(struct mvm_statistics_rx_v3) /
790 			  sizeof(__le32)) * 43) + (4 * 33) + 1;
791 
792 	buf = kzalloc(bufsz, GFP_KERNEL);
793 	if (!buf)
794 		return -ENOMEM;
795 
796 	mutex_lock(&mvm->mutex);
797 
798 	if (iwl_mvm_firmware_running(mvm))
799 		iwl_mvm_request_statistics(mvm, false);
800 
801 	pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
802 			 "Statistics_Rx - OFDM");
803 	if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
804 		struct mvm_statistics_rx_phy_v2 *ofdm = &mvm->rx_stats_v3.ofdm;
805 
806 		PRINT_STATS_LE32(ofdm, ina_cnt);
807 		PRINT_STATS_LE32(ofdm, fina_cnt);
808 		PRINT_STATS_LE32(ofdm, plcp_err);
809 		PRINT_STATS_LE32(ofdm, crc32_err);
810 		PRINT_STATS_LE32(ofdm, overrun_err);
811 		PRINT_STATS_LE32(ofdm, early_overrun_err);
812 		PRINT_STATS_LE32(ofdm, crc32_good);
813 		PRINT_STATS_LE32(ofdm, false_alarm_cnt);
814 		PRINT_STATS_LE32(ofdm, fina_sync_err_cnt);
815 		PRINT_STATS_LE32(ofdm, sfd_timeout);
816 		PRINT_STATS_LE32(ofdm, fina_timeout);
817 		PRINT_STATS_LE32(ofdm, unresponded_rts);
818 		PRINT_STATS_LE32(ofdm, rxe_frame_lmt_overrun);
819 		PRINT_STATS_LE32(ofdm, sent_ack_cnt);
820 		PRINT_STATS_LE32(ofdm, sent_cts_cnt);
821 		PRINT_STATS_LE32(ofdm, sent_ba_rsp_cnt);
822 		PRINT_STATS_LE32(ofdm, dsp_self_kill);
823 		PRINT_STATS_LE32(ofdm, mh_format_err);
824 		PRINT_STATS_LE32(ofdm, re_acq_main_rssi_sum);
825 		PRINT_STATS_LE32(ofdm, reserved);
826 	} else {
827 		struct mvm_statistics_rx_phy *ofdm = &mvm->rx_stats.ofdm;
828 
829 		PRINT_STATS_LE32(ofdm, unresponded_rts);
830 		PRINT_STATS_LE32(ofdm, rxe_frame_lmt_overrun);
831 		PRINT_STATS_LE32(ofdm, sent_ba_rsp_cnt);
832 		PRINT_STATS_LE32(ofdm, dsp_self_kill);
833 		PRINT_STATS_LE32(ofdm, reserved);
834 	}
835 
836 	pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
837 			 "Statistics_Rx - CCK");
838 	if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
839 		struct mvm_statistics_rx_phy_v2 *cck = &mvm->rx_stats_v3.cck;
840 
841 		PRINT_STATS_LE32(cck, ina_cnt);
842 		PRINT_STATS_LE32(cck, fina_cnt);
843 		PRINT_STATS_LE32(cck, plcp_err);
844 		PRINT_STATS_LE32(cck, crc32_err);
845 		PRINT_STATS_LE32(cck, overrun_err);
846 		PRINT_STATS_LE32(cck, early_overrun_err);
847 		PRINT_STATS_LE32(cck, crc32_good);
848 		PRINT_STATS_LE32(cck, false_alarm_cnt);
849 		PRINT_STATS_LE32(cck, fina_sync_err_cnt);
850 		PRINT_STATS_LE32(cck, sfd_timeout);
851 		PRINT_STATS_LE32(cck, fina_timeout);
852 		PRINT_STATS_LE32(cck, unresponded_rts);
853 		PRINT_STATS_LE32(cck, rxe_frame_lmt_overrun);
854 		PRINT_STATS_LE32(cck, sent_ack_cnt);
855 		PRINT_STATS_LE32(cck, sent_cts_cnt);
856 		PRINT_STATS_LE32(cck, sent_ba_rsp_cnt);
857 		PRINT_STATS_LE32(cck, dsp_self_kill);
858 		PRINT_STATS_LE32(cck, mh_format_err);
859 		PRINT_STATS_LE32(cck, re_acq_main_rssi_sum);
860 		PRINT_STATS_LE32(cck, reserved);
861 	} else {
862 		struct mvm_statistics_rx_phy *cck = &mvm->rx_stats.cck;
863 
864 		PRINT_STATS_LE32(cck, unresponded_rts);
865 		PRINT_STATS_LE32(cck, rxe_frame_lmt_overrun);
866 		PRINT_STATS_LE32(cck, sent_ba_rsp_cnt);
867 		PRINT_STATS_LE32(cck, dsp_self_kill);
868 		PRINT_STATS_LE32(cck, reserved);
869 	}
870 
871 	pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
872 			 "Statistics_Rx - GENERAL");
873 	if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
874 		struct mvm_statistics_rx_non_phy_v3 *general =
875 			&mvm->rx_stats_v3.general;
876 
877 		PRINT_STATS_LE32(general, bogus_cts);
878 		PRINT_STATS_LE32(general, bogus_ack);
879 		PRINT_STATS_LE32(general, non_bssid_frames);
880 		PRINT_STATS_LE32(general, filtered_frames);
881 		PRINT_STATS_LE32(general, non_channel_beacons);
882 		PRINT_STATS_LE32(general, channel_beacons);
883 		PRINT_STATS_LE32(general, num_missed_bcon);
884 		PRINT_STATS_LE32(general, adc_rx_saturation_time);
885 		PRINT_STATS_LE32(general, ina_detection_search_time);
886 		PRINT_STATS_LE32(general, beacon_silence_rssi_a);
887 		PRINT_STATS_LE32(general, beacon_silence_rssi_b);
888 		PRINT_STATS_LE32(general, beacon_silence_rssi_c);
889 		PRINT_STATS_LE32(general, interference_data_flag);
890 		PRINT_STATS_LE32(general, channel_load);
891 		PRINT_STATS_LE32(general, dsp_false_alarms);
892 		PRINT_STATS_LE32(general, beacon_rssi_a);
893 		PRINT_STATS_LE32(general, beacon_rssi_b);
894 		PRINT_STATS_LE32(general, beacon_rssi_c);
895 		PRINT_STATS_LE32(general, beacon_energy_a);
896 		PRINT_STATS_LE32(general, beacon_energy_b);
897 		PRINT_STATS_LE32(general, beacon_energy_c);
898 		PRINT_STATS_LE32(general, num_bt_kills);
899 		PRINT_STATS_LE32(general, mac_id);
900 		PRINT_STATS_LE32(general, directed_data_mpdu);
901 	} else {
902 		struct mvm_statistics_rx_non_phy *general =
903 			&mvm->rx_stats.general;
904 
905 		PRINT_STATS_LE32(general, bogus_cts);
906 		PRINT_STATS_LE32(general, bogus_ack);
907 		PRINT_STATS_LE32(general, non_channel_beacons);
908 		PRINT_STATS_LE32(general, channel_beacons);
909 		PRINT_STATS_LE32(general, num_missed_bcon);
910 		PRINT_STATS_LE32(general, adc_rx_saturation_time);
911 		PRINT_STATS_LE32(general, ina_detection_search_time);
912 		PRINT_STATS_LE32(general, beacon_silence_rssi_a);
913 		PRINT_STATS_LE32(general, beacon_silence_rssi_b);
914 		PRINT_STATS_LE32(general, beacon_silence_rssi_c);
915 		PRINT_STATS_LE32(general, interference_data_flag);
916 		PRINT_STATS_LE32(general, channel_load);
917 		PRINT_STATS_LE32(general, beacon_rssi_a);
918 		PRINT_STATS_LE32(general, beacon_rssi_b);
919 		PRINT_STATS_LE32(general, beacon_rssi_c);
920 		PRINT_STATS_LE32(general, beacon_energy_a);
921 		PRINT_STATS_LE32(general, beacon_energy_b);
922 		PRINT_STATS_LE32(general, beacon_energy_c);
923 		PRINT_STATS_LE32(general, num_bt_kills);
924 		PRINT_STATS_LE32(general, mac_id);
925 	}
926 
927 	pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
928 			 "Statistics_Rx - HT");
929 	if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
930 		struct mvm_statistics_rx_ht_phy_v1 *ht =
931 			&mvm->rx_stats_v3.ofdm_ht;
932 
933 		PRINT_STATS_LE32(ht, plcp_err);
934 		PRINT_STATS_LE32(ht, overrun_err);
935 		PRINT_STATS_LE32(ht, early_overrun_err);
936 		PRINT_STATS_LE32(ht, crc32_good);
937 		PRINT_STATS_LE32(ht, crc32_err);
938 		PRINT_STATS_LE32(ht, mh_format_err);
939 		PRINT_STATS_LE32(ht, agg_crc32_good);
940 		PRINT_STATS_LE32(ht, agg_mpdu_cnt);
941 		PRINT_STATS_LE32(ht, agg_cnt);
942 		PRINT_STATS_LE32(ht, unsupport_mcs);
943 	} else {
944 		struct mvm_statistics_rx_ht_phy *ht =
945 			&mvm->rx_stats.ofdm_ht;
946 
947 		PRINT_STATS_LE32(ht, mh_format_err);
948 		PRINT_STATS_LE32(ht, agg_mpdu_cnt);
949 		PRINT_STATS_LE32(ht, agg_cnt);
950 		PRINT_STATS_LE32(ht, unsupport_mcs);
951 	}
952 
953 	mutex_unlock(&mvm->mutex);
954 
955 	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
956 	kfree(buf);
957 
958 	return ret;
959 }
960 #undef PRINT_STAT_LE32
961 
962 static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm,
963 					  char __user *user_buf, size_t count,
964 					  loff_t *ppos,
965 					  struct iwl_mvm_frame_stats *stats)
966 {
967 	char *buff, *pos, *endpos;
968 	int idx, i;
969 	int ret;
970 	static const size_t bufsz = 1024;
971 
972 	buff = kmalloc(bufsz, GFP_KERNEL);
973 	if (!buff)
974 		return -ENOMEM;
975 
976 	spin_lock_bh(&mvm->drv_stats_lock);
977 
978 	pos = buff;
979 	endpos = pos + bufsz;
980 
981 	pos += scnprintf(pos, endpos - pos,
982 			 "Legacy/HT/VHT\t:\t%d/%d/%d\n",
983 			 stats->legacy_frames,
984 			 stats->ht_frames,
985 			 stats->vht_frames);
986 	pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n",
987 			 stats->bw_20_frames,
988 			 stats->bw_40_frames,
989 			 stats->bw_80_frames);
990 	pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n",
991 			 stats->ngi_frames,
992 			 stats->sgi_frames);
993 	pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n",
994 			 stats->siso_frames,
995 			 stats->mimo2_frames);
996 	pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n",
997 			 stats->fail_frames,
998 			 stats->success_frames);
999 	pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n",
1000 			 stats->agg_frames);
1001 	pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n",
1002 			 stats->ampdu_count);
1003 	pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n",
1004 			 stats->ampdu_count > 0 ?
1005 			 (stats->agg_frames / stats->ampdu_count) : 0);
1006 
1007 	pos += scnprintf(pos, endpos - pos, "Last Rates\n");
1008 
1009 	idx = stats->last_frame_idx - 1;
1010 	for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) {
1011 		idx = (idx + 1) % ARRAY_SIZE(stats->last_rates);
1012 		if (stats->last_rates[idx] == 0)
1013 			continue;
1014 		pos += scnprintf(pos, endpos - pos, "Rate[%d]: ",
1015 				 (int)(ARRAY_SIZE(stats->last_rates) - i));
1016 		pos += rs_pretty_print_rate(pos, endpos - pos,
1017 					    stats->last_rates[idx]);
1018 		if (pos < endpos - 1)
1019 			*pos++ = '\n';
1020 	}
1021 	spin_unlock_bh(&mvm->drv_stats_lock);
1022 
1023 	ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
1024 	kfree(buff);
1025 
1026 	return ret;
1027 }
1028 
1029 static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file,
1030 					   char __user *user_buf, size_t count,
1031 					   loff_t *ppos)
1032 {
1033 	struct iwl_mvm *mvm = file->private_data;
1034 
1035 	return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos,
1036 					  &mvm->drv_rx_stats);
1037 }
1038 
1039 static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
1040 					  size_t count, loff_t *ppos)
1041 {
1042 	int __maybe_unused ret;
1043 
1044 	if (!iwl_mvm_firmware_running(mvm))
1045 		return -EIO;
1046 
1047 	mutex_lock(&mvm->mutex);
1048 
1049 	/* allow one more restart that we're provoking here */
1050 	if (mvm->fw_restart >= 0)
1051 		mvm->fw_restart++;
1052 
1053 	/* take the return value to make compiler happy - it will fail anyway */
1054 	ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, 0, 0, NULL);
1055 
1056 	mutex_unlock(&mvm->mutex);
1057 
1058 	return count;
1059 }
1060 
1061 static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
1062 				      size_t count, loff_t *ppos)
1063 {
1064 	if (!iwl_mvm_firmware_running(mvm))
1065 		return -EIO;
1066 
1067 	iwl_force_nmi(mvm->trans);
1068 
1069 	return count;
1070 }
1071 
1072 static ssize_t
1073 iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
1074 				char __user *user_buf,
1075 				size_t count, loff_t *ppos)
1076 {
1077 	struct iwl_mvm *mvm = file->private_data;
1078 	int pos = 0;
1079 	char buf[32];
1080 	const size_t bufsz = sizeof(buf);
1081 
1082 	/* print which antennas were set for the scan command by the user */
1083 	pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
1084 	if (mvm->scan_rx_ant & ANT_A)
1085 		pos += scnprintf(buf + pos, bufsz - pos, "A");
1086 	if (mvm->scan_rx_ant & ANT_B)
1087 		pos += scnprintf(buf + pos, bufsz - pos, "B");
1088 	if (mvm->scan_rx_ant & ANT_C)
1089 		pos += scnprintf(buf + pos, bufsz - pos, "C");
1090 	pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
1091 
1092 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1093 }
1094 
1095 static ssize_t
1096 iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
1097 				 size_t count, loff_t *ppos)
1098 {
1099 	u8 scan_rx_ant;
1100 
1101 	if (!iwl_mvm_firmware_running(mvm))
1102 		return -EIO;
1103 
1104 	if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
1105 		return -EINVAL;
1106 	if (scan_rx_ant > ANT_ABC)
1107 		return -EINVAL;
1108 	if (scan_rx_ant & ~(iwl_mvm_get_valid_rx_ant(mvm)))
1109 		return -EINVAL;
1110 
1111 	if (mvm->scan_rx_ant != scan_rx_ant) {
1112 		mvm->scan_rx_ant = scan_rx_ant;
1113 		if (fw_has_capa(&mvm->fw->ucode_capa,
1114 				IWL_UCODE_TLV_CAPA_UMAC_SCAN))
1115 			iwl_mvm_config_scan(mvm);
1116 	}
1117 
1118 	return count;
1119 }
1120 
1121 static ssize_t iwl_dbgfs_indirection_tbl_write(struct iwl_mvm *mvm,
1122 					       char *buf, size_t count,
1123 					       loff_t *ppos)
1124 {
1125 	struct iwl_rss_config_cmd cmd = {
1126 		.flags = cpu_to_le32(IWL_RSS_ENABLE),
1127 		.hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP |
1128 			     IWL_RSS_HASH_TYPE_IPV4_UDP |
1129 			     IWL_RSS_HASH_TYPE_IPV4_PAYLOAD |
1130 			     IWL_RSS_HASH_TYPE_IPV6_TCP |
1131 			     IWL_RSS_HASH_TYPE_IPV6_UDP |
1132 			     IWL_RSS_HASH_TYPE_IPV6_PAYLOAD,
1133 	};
1134 	int ret, i, num_repeats, nbytes = count / 2;
1135 
1136 	ret = hex2bin(cmd.indirection_table, buf, nbytes);
1137 	if (ret)
1138 		return ret;
1139 
1140 	/*
1141 	 * The input is the redirection table, partial or full.
1142 	 * Repeat the pattern if needed.
1143 	 * For example, input of 01020F will be repeated 42 times,
1144 	 * indirecting RSS hash results to queues 1, 2, 15 (skipping
1145 	 * queues 3 - 14).
1146 	 */
1147 	num_repeats = ARRAY_SIZE(cmd.indirection_table) / nbytes;
1148 	for (i = 1; i < num_repeats; i++)
1149 		memcpy(&cmd.indirection_table[i * nbytes],
1150 		       cmd.indirection_table, nbytes);
1151 	/* handle cut in the middle pattern for the last places */
1152 	memcpy(&cmd.indirection_table[i * nbytes], cmd.indirection_table,
1153 	       ARRAY_SIZE(cmd.indirection_table) % nbytes);
1154 
1155 	netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key));
1156 
1157 	mutex_lock(&mvm->mutex);
1158 	if (iwl_mvm_firmware_running(mvm))
1159 		ret = iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0,
1160 					   sizeof(cmd), &cmd);
1161 	else
1162 		ret = 0;
1163 	mutex_unlock(&mvm->mutex);
1164 
1165 	return ret ?: count;
1166 }
1167 
1168 static ssize_t iwl_dbgfs_inject_packet_write(struct iwl_mvm *mvm,
1169 					     char *buf, size_t count,
1170 					     loff_t *ppos)
1171 {
1172 	struct iwl_rx_cmd_buffer rxb = {
1173 		._rx_page_order = 0,
1174 		.truesize = 0, /* not used */
1175 		._offset = 0,
1176 	};
1177 	struct iwl_rx_packet *pkt;
1178 	struct iwl_rx_mpdu_desc *desc;
1179 	int bin_len = count / 2;
1180 	int ret = -EINVAL;
1181 	size_t mpdu_cmd_hdr_size = (mvm->trans->trans_cfg->device_family >=
1182 				    IWL_DEVICE_FAMILY_AX210) ?
1183 		sizeof(struct iwl_rx_mpdu_desc) :
1184 		IWL_RX_DESC_SIZE_V1;
1185 
1186 	if (!iwl_mvm_firmware_running(mvm))
1187 		return -EIO;
1188 
1189 	/* supporting only 9000 descriptor */
1190 	if (!mvm->trans->trans_cfg->mq_rx_supported)
1191 		return -ENOTSUPP;
1192 
1193 	rxb._page = alloc_pages(GFP_ATOMIC, 0);
1194 	if (!rxb._page)
1195 		return -ENOMEM;
1196 	pkt = rxb_addr(&rxb);
1197 
1198 	ret = hex2bin(page_address(rxb._page), buf, bin_len);
1199 	if (ret)
1200 		goto out;
1201 
1202 	/* avoid invalid memory access */
1203 	if (bin_len < sizeof(*pkt) + mpdu_cmd_hdr_size)
1204 		goto out;
1205 
1206 	/* check this is RX packet */
1207 	if (WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd) !=
1208 	    WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD))
1209 		goto out;
1210 
1211 	/* check the length in metadata matches actual received length */
1212 	desc = (void *)pkt->data;
1213 	if (le16_to_cpu(desc->mpdu_len) !=
1214 	    (bin_len - mpdu_cmd_hdr_size - sizeof(*pkt)))
1215 		goto out;
1216 
1217 	local_bh_disable();
1218 	iwl_mvm_rx_mpdu_mq(mvm, NULL, &rxb, 0);
1219 	local_bh_enable();
1220 	ret = 0;
1221 
1222 out:
1223 	iwl_free_rxb(&rxb);
1224 
1225 	return ret ?: count;
1226 }
1227 
1228 static int _iwl_dbgfs_inject_beacon_ie(struct iwl_mvm *mvm, char *bin, int len)
1229 {
1230 	struct ieee80211_vif *vif;
1231 	struct iwl_mvm_vif *mvmvif;
1232 	struct sk_buff *beacon;
1233 	struct ieee80211_tx_info *info;
1234 	struct iwl_mac_beacon_cmd beacon_cmd = {};
1235 	u8 rate;
1236 	u16 flags;
1237 	int i;
1238 
1239 	len /= 2;
1240 
1241 	/* Element len should be represented by u8 */
1242 	if (len >= U8_MAX)
1243 		return -EINVAL;
1244 
1245 	if (!iwl_mvm_firmware_running(mvm))
1246 		return -EIO;
1247 
1248 	if (!iwl_mvm_has_new_tx_api(mvm) &&
1249 	    !fw_has_api(&mvm->fw->ucode_capa,
1250 			IWL_UCODE_TLV_API_NEW_BEACON_TEMPLATE))
1251 		return -EINVAL;
1252 
1253 	rcu_read_lock();
1254 
1255 	for (i = 0; i < NUM_MAC_INDEX_DRIVER; i++) {
1256 		vif = iwl_mvm_rcu_dereference_vif_id(mvm, i, true);
1257 		if (!vif)
1258 			continue;
1259 
1260 		if (vif->type == NL80211_IFTYPE_AP)
1261 			break;
1262 	}
1263 
1264 	if (i == NUM_MAC_INDEX_DRIVER || !vif)
1265 		goto out_err;
1266 
1267 	mvm->hw->extra_beacon_tailroom = len;
1268 
1269 	beacon = ieee80211_beacon_get_template(mvm->hw, vif, NULL);
1270 	if (!beacon)
1271 		goto out_err;
1272 
1273 	if (len && hex2bin(skb_put_zero(beacon, len), bin, len)) {
1274 		dev_kfree_skb(beacon);
1275 		goto out_err;
1276 	}
1277 
1278 	mvm->beacon_inject_active = true;
1279 
1280 	mvmvif = iwl_mvm_vif_from_mac80211(vif);
1281 	info = IEEE80211_SKB_CB(beacon);
1282 	rate = iwl_mvm_mac_ctxt_get_lowest_rate(info, vif);
1283 	flags = iwl_mvm_mac80211_idx_to_hwrate(rate);
1284 
1285 	if (rate == IWL_FIRST_CCK_RATE)
1286 		flags |= IWL_MAC_BEACON_CCK;
1287 
1288 	beacon_cmd.flags = cpu_to_le16(flags);
1289 	beacon_cmd.byte_cnt = cpu_to_le16((u16)beacon->len);
1290 	beacon_cmd.template_id = cpu_to_le32((u32)mvmvif->id);
1291 
1292 	iwl_mvm_mac_ctxt_set_tim(mvm, &beacon_cmd.tim_idx,
1293 				 &beacon_cmd.tim_size,
1294 				 beacon->data, beacon->len);
1295 
1296 	mutex_lock(&mvm->mutex);
1297 	iwl_mvm_mac_ctxt_send_beacon_cmd(mvm, beacon, &beacon_cmd,
1298 					 sizeof(beacon_cmd));
1299 	mutex_unlock(&mvm->mutex);
1300 
1301 	dev_kfree_skb(beacon);
1302 
1303 	rcu_read_unlock();
1304 	return 0;
1305 
1306 out_err:
1307 	rcu_read_unlock();
1308 	return -EINVAL;
1309 }
1310 
1311 static ssize_t iwl_dbgfs_inject_beacon_ie_write(struct iwl_mvm *mvm,
1312 						char *buf, size_t count,
1313 						loff_t *ppos)
1314 {
1315 	int ret = _iwl_dbgfs_inject_beacon_ie(mvm, buf, count);
1316 
1317 	mvm->hw->extra_beacon_tailroom = 0;
1318 	return ret ?: count;
1319 }
1320 
1321 static ssize_t iwl_dbgfs_inject_beacon_ie_restore_write(struct iwl_mvm *mvm,
1322 							char *buf,
1323 							size_t count,
1324 							loff_t *ppos)
1325 {
1326 	int ret = _iwl_dbgfs_inject_beacon_ie(mvm, NULL, 0);
1327 
1328 	mvm->hw->extra_beacon_tailroom = 0;
1329 	mvm->beacon_inject_active = false;
1330 	return ret ?: count;
1331 }
1332 
1333 static ssize_t iwl_dbgfs_fw_dbg_conf_read(struct file *file,
1334 					  char __user *user_buf,
1335 					  size_t count, loff_t *ppos)
1336 {
1337 	struct iwl_mvm *mvm = file->private_data;
1338 	int conf;
1339 	char buf[8];
1340 	const size_t bufsz = sizeof(buf);
1341 	int pos = 0;
1342 
1343 	mutex_lock(&mvm->mutex);
1344 	conf = mvm->fwrt.dump.conf;
1345 	mutex_unlock(&mvm->mutex);
1346 
1347 	pos += scnprintf(buf + pos, bufsz - pos, "%d\n", conf);
1348 
1349 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1350 }
1351 
1352 static ssize_t iwl_dbgfs_fw_dbg_conf_write(struct iwl_mvm *mvm,
1353 					   char *buf, size_t count,
1354 					   loff_t *ppos)
1355 {
1356 	unsigned int conf_id;
1357 	int ret;
1358 
1359 	if (!iwl_mvm_firmware_running(mvm))
1360 		return -EIO;
1361 
1362 	ret = kstrtouint(buf, 0, &conf_id);
1363 	if (ret)
1364 		return ret;
1365 
1366 	if (WARN_ON(conf_id >= FW_DBG_CONF_MAX))
1367 		return -EINVAL;
1368 
1369 	mutex_lock(&mvm->mutex);
1370 	ret = iwl_fw_start_dbg_conf(&mvm->fwrt, conf_id);
1371 	mutex_unlock(&mvm->mutex);
1372 
1373 	return ret ?: count;
1374 }
1375 
1376 static ssize_t iwl_dbgfs_fw_dbg_collect_write(struct iwl_mvm *mvm,
1377 					      char *buf, size_t count,
1378 					      loff_t *ppos)
1379 {
1380 	if (count == 0)
1381 		return 0;
1382 
1383 	iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_USER_TRIGGER,
1384 			       NULL);
1385 
1386 	iwl_fw_dbg_collect(&mvm->fwrt, FW_DBG_TRIGGER_USER, buf,
1387 			   (count - 1), NULL);
1388 
1389 	return count;
1390 }
1391 
1392 #define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__)
1393 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1394 static ssize_t iwl_dbgfs_bcast_filters_read(struct file *file,
1395 					    char __user *user_buf,
1396 					    size_t count, loff_t *ppos)
1397 {
1398 	struct iwl_mvm *mvm = file->private_data;
1399 	struct iwl_bcast_filter_cmd cmd;
1400 	const struct iwl_fw_bcast_filter *filter;
1401 	char *buf;
1402 	int bufsz = 1024;
1403 	int i, j, pos = 0;
1404 	ssize_t ret;
1405 
1406 	buf = kzalloc(bufsz, GFP_KERNEL);
1407 	if (!buf)
1408 		return -ENOMEM;
1409 
1410 	mutex_lock(&mvm->mutex);
1411 	if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
1412 		ADD_TEXT("None\n");
1413 		mutex_unlock(&mvm->mutex);
1414 		goto out;
1415 	}
1416 	mutex_unlock(&mvm->mutex);
1417 
1418 	for (i = 0; cmd.filters[i].attrs[0].mask; i++) {
1419 		filter = &cmd.filters[i];
1420 
1421 		ADD_TEXT("Filter [%d]:\n", i);
1422 		ADD_TEXT("\tDiscard=%d\n", filter->discard);
1423 		ADD_TEXT("\tFrame Type: %s\n",
1424 			 filter->frame_type ? "IPv4" : "Generic");
1425 
1426 		for (j = 0; j < ARRAY_SIZE(filter->attrs); j++) {
1427 			const struct iwl_fw_bcast_filter_attr *attr;
1428 
1429 			attr = &filter->attrs[j];
1430 			if (!attr->mask)
1431 				break;
1432 
1433 			ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n",
1434 				 j, attr->offset,
1435 				 attr->offset_type ? "IP End" :
1436 						     "Payload Start",
1437 				 be32_to_cpu(attr->mask),
1438 				 be32_to_cpu(attr->val),
1439 				 le16_to_cpu(attr->reserved1));
1440 		}
1441 	}
1442 out:
1443 	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1444 	kfree(buf);
1445 	return ret;
1446 }
1447 
1448 static ssize_t iwl_dbgfs_bcast_filters_write(struct iwl_mvm *mvm, char *buf,
1449 					     size_t count, loff_t *ppos)
1450 {
1451 	int pos, next_pos;
1452 	struct iwl_fw_bcast_filter filter = {};
1453 	struct iwl_bcast_filter_cmd cmd;
1454 	u32 filter_id, attr_id, mask, value;
1455 	int err = 0;
1456 
1457 	if (sscanf(buf, "%d %hhi %hhi %n", &filter_id, &filter.discard,
1458 		   &filter.frame_type, &pos) != 3)
1459 		return -EINVAL;
1460 
1461 	if (filter_id >= ARRAY_SIZE(mvm->dbgfs_bcast_filtering.cmd.filters) ||
1462 	    filter.frame_type > BCAST_FILTER_FRAME_TYPE_IPV4)
1463 		return -EINVAL;
1464 
1465 	for (attr_id = 0; attr_id < ARRAY_SIZE(filter.attrs);
1466 	     attr_id++) {
1467 		struct iwl_fw_bcast_filter_attr *attr =
1468 				&filter.attrs[attr_id];
1469 
1470 		if (pos >= count)
1471 			break;
1472 
1473 		if (sscanf(&buf[pos], "%hhi %hhi %i %i %n",
1474 			   &attr->offset, &attr->offset_type,
1475 			   &mask, &value, &next_pos) != 4)
1476 			return -EINVAL;
1477 
1478 		attr->mask = cpu_to_be32(mask);
1479 		attr->val = cpu_to_be32(value);
1480 		if (mask)
1481 			filter.num_attrs++;
1482 
1483 		pos += next_pos;
1484 	}
1485 
1486 	mutex_lock(&mvm->mutex);
1487 	memcpy(&mvm->dbgfs_bcast_filtering.cmd.filters[filter_id],
1488 	       &filter, sizeof(filter));
1489 
1490 	/* send updated bcast filtering configuration */
1491 	if (iwl_mvm_firmware_running(mvm) &&
1492 	    mvm->dbgfs_bcast_filtering.override &&
1493 	    iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1494 		err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1495 					   sizeof(cmd), &cmd);
1496 	mutex_unlock(&mvm->mutex);
1497 
1498 	return err ?: count;
1499 }
1500 
1501 static ssize_t iwl_dbgfs_bcast_filters_macs_read(struct file *file,
1502 						 char __user *user_buf,
1503 						 size_t count, loff_t *ppos)
1504 {
1505 	struct iwl_mvm *mvm = file->private_data;
1506 	struct iwl_bcast_filter_cmd cmd;
1507 	char *buf;
1508 	int bufsz = 1024;
1509 	int i, pos = 0;
1510 	ssize_t ret;
1511 
1512 	buf = kzalloc(bufsz, GFP_KERNEL);
1513 	if (!buf)
1514 		return -ENOMEM;
1515 
1516 	mutex_lock(&mvm->mutex);
1517 	if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
1518 		ADD_TEXT("None\n");
1519 		mutex_unlock(&mvm->mutex);
1520 		goto out;
1521 	}
1522 	mutex_unlock(&mvm->mutex);
1523 
1524 	for (i = 0; i < ARRAY_SIZE(cmd.macs); i++) {
1525 		const struct iwl_fw_bcast_mac *mac = &cmd.macs[i];
1526 
1527 		ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n",
1528 			 i, mac->default_discard, mac->attached_filters);
1529 	}
1530 out:
1531 	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1532 	kfree(buf);
1533 	return ret;
1534 }
1535 
1536 static ssize_t iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm *mvm,
1537 						  char *buf, size_t count,
1538 						  loff_t *ppos)
1539 {
1540 	struct iwl_bcast_filter_cmd cmd;
1541 	struct iwl_fw_bcast_mac mac = {};
1542 	u32 mac_id, attached_filters;
1543 	int err = 0;
1544 
1545 	if (!mvm->bcast_filters)
1546 		return -ENOENT;
1547 
1548 	if (sscanf(buf, "%d %hhi %i", &mac_id, &mac.default_discard,
1549 		   &attached_filters) != 3)
1550 		return -EINVAL;
1551 
1552 	if (mac_id >= ARRAY_SIZE(cmd.macs) ||
1553 	    mac.default_discard > 1 ||
1554 	    attached_filters >= BIT(ARRAY_SIZE(cmd.filters)))
1555 		return -EINVAL;
1556 
1557 	mac.attached_filters = cpu_to_le16(attached_filters);
1558 
1559 	mutex_lock(&mvm->mutex);
1560 	memcpy(&mvm->dbgfs_bcast_filtering.cmd.macs[mac_id],
1561 	       &mac, sizeof(mac));
1562 
1563 	/* send updated bcast filtering configuration */
1564 	if (iwl_mvm_firmware_running(mvm) &&
1565 	    mvm->dbgfs_bcast_filtering.override &&
1566 	    iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1567 		err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1568 					   sizeof(cmd), &cmd);
1569 	mutex_unlock(&mvm->mutex);
1570 
1571 	return err ?: count;
1572 }
1573 #endif
1574 
1575 #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
1576 	_MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1577 #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
1578 	_MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1579 #define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do {	\
1580 		debugfs_create_file(alias, mode, parent, mvm,		\
1581 				    &iwl_dbgfs_##name##_ops);		\
1582 	} while (0)
1583 #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
1584 	MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
1585 
1586 #define MVM_DEBUGFS_WRITE_STA_FILE_OPS(name, bufsz) \
1587 	_MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct ieee80211_sta)
1588 #define MVM_DEBUGFS_READ_WRITE_STA_FILE_OPS(name, bufsz) \
1589 	_MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct ieee80211_sta)
1590 
1591 #define MVM_DEBUGFS_ADD_STA_FILE_ALIAS(alias, name, parent, mode) do {	\
1592 		debugfs_create_file(alias, mode, parent, sta,		\
1593 				    &iwl_dbgfs_##name##_ops);		\
1594 	} while (0)
1595 #define MVM_DEBUGFS_ADD_STA_FILE(name, parent, mode) \
1596 	MVM_DEBUGFS_ADD_STA_FILE_ALIAS(#name, name, parent, mode)
1597 
1598 static ssize_t
1599 iwl_dbgfs_prph_reg_read(struct file *file,
1600 			char __user *user_buf,
1601 			size_t count, loff_t *ppos)
1602 {
1603 	struct iwl_mvm *mvm = file->private_data;
1604 	int pos = 0;
1605 	char buf[32];
1606 	const size_t bufsz = sizeof(buf);
1607 
1608 	if (!mvm->dbgfs_prph_reg_addr)
1609 		return -EINVAL;
1610 
1611 	pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n",
1612 		mvm->dbgfs_prph_reg_addr,
1613 		iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr));
1614 
1615 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1616 }
1617 
1618 static ssize_t
1619 iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf,
1620 			 size_t count, loff_t *ppos)
1621 {
1622 	u8 args;
1623 	u32 value;
1624 
1625 	args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value);
1626 	/* if we only want to set the reg address - nothing more to do */
1627 	if (args == 1)
1628 		goto out;
1629 
1630 	/* otherwise, make sure we have both address and value */
1631 	if (args != 2)
1632 		return -EINVAL;
1633 
1634 	iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value);
1635 
1636 out:
1637 	return count;
1638 }
1639 
1640 static ssize_t
1641 iwl_dbgfs_send_echo_cmd_write(struct iwl_mvm *mvm, char *buf,
1642 			      size_t count, loff_t *ppos)
1643 {
1644 	int ret;
1645 
1646 	if (!iwl_mvm_firmware_running(mvm))
1647 		return -EIO;
1648 
1649 	mutex_lock(&mvm->mutex);
1650 	ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL);
1651 	mutex_unlock(&mvm->mutex);
1652 
1653 	return ret ?: count;
1654 }
1655 
1656 struct iwl_mvm_sniffer_apply {
1657 	struct iwl_mvm *mvm;
1658 	u8 *bssid;
1659 	u16 aid;
1660 };
1661 
1662 static bool iwl_mvm_sniffer_apply(struct iwl_notif_wait_data *notif_data,
1663 				  struct iwl_rx_packet *pkt, void *data)
1664 {
1665 	struct iwl_mvm_sniffer_apply *apply = data;
1666 
1667 	apply->mvm->cur_aid = cpu_to_le16(apply->aid);
1668 	memcpy(apply->mvm->cur_bssid, apply->bssid,
1669 	       sizeof(apply->mvm->cur_bssid));
1670 
1671 	return true;
1672 }
1673 
1674 static ssize_t
1675 iwl_dbgfs_he_sniffer_params_write(struct iwl_mvm *mvm, char *buf,
1676 				  size_t count, loff_t *ppos)
1677 {
1678 	struct iwl_notification_wait wait;
1679 	struct iwl_he_monitor_cmd he_mon_cmd = {};
1680 	struct iwl_mvm_sniffer_apply apply = {
1681 		.mvm = mvm,
1682 	};
1683 	u16 wait_cmds[] = {
1684 		iwl_cmd_id(HE_AIR_SNIFFER_CONFIG_CMD, DATA_PATH_GROUP, 0),
1685 	};
1686 	u32 aid;
1687 	int ret;
1688 
1689 	if (!iwl_mvm_firmware_running(mvm))
1690 		return -EIO;
1691 
1692 	ret = sscanf(buf, "%x %2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx", &aid,
1693 		     &he_mon_cmd.bssid[0], &he_mon_cmd.bssid[1],
1694 		     &he_mon_cmd.bssid[2], &he_mon_cmd.bssid[3],
1695 		     &he_mon_cmd.bssid[4], &he_mon_cmd.bssid[5]);
1696 	if (ret != 7)
1697 		return -EINVAL;
1698 
1699 	he_mon_cmd.aid = cpu_to_le16(aid);
1700 
1701 	apply.aid = aid;
1702 	apply.bssid = (void *)he_mon_cmd.bssid;
1703 
1704 	mutex_lock(&mvm->mutex);
1705 
1706 	/*
1707 	 * Use the notification waiter to get our function triggered
1708 	 * in sequence with other RX. This ensures that frames we get
1709 	 * on the RX queue _before_ the new configuration is applied
1710 	 * still have mvm->cur_aid pointing to the old AID, and that
1711 	 * frames on the RX queue _after_ the firmware processed the
1712 	 * new configuration (and sent the response, synchronously)
1713 	 * get mvm->cur_aid correctly set to the new AID.
1714 	 */
1715 	iwl_init_notification_wait(&mvm->notif_wait, &wait,
1716 				   wait_cmds, ARRAY_SIZE(wait_cmds),
1717 				   iwl_mvm_sniffer_apply, &apply);
1718 
1719 	ret = iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(HE_AIR_SNIFFER_CONFIG_CMD,
1720 						   DATA_PATH_GROUP, 0), 0,
1721 				   sizeof(he_mon_cmd), &he_mon_cmd);
1722 
1723 	/* no need to really wait, we already did anyway */
1724 	iwl_remove_notification(&mvm->notif_wait, &wait);
1725 
1726 	mutex_unlock(&mvm->mutex);
1727 
1728 	return ret ?: count;
1729 }
1730 
1731 static ssize_t
1732 iwl_dbgfs_he_sniffer_params_read(struct file *file, char __user *user_buf,
1733 				 size_t count, loff_t *ppos)
1734 {
1735 	struct iwl_mvm *mvm = file->private_data;
1736 	u8 buf[32];
1737 	int len;
1738 
1739 	len = scnprintf(buf, sizeof(buf),
1740 			"%d %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n",
1741 			le16_to_cpu(mvm->cur_aid), mvm->cur_bssid[0],
1742 			mvm->cur_bssid[1], mvm->cur_bssid[2], mvm->cur_bssid[3],
1743 			mvm->cur_bssid[4], mvm->cur_bssid[5]);
1744 
1745 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1746 }
1747 
1748 static ssize_t
1749 iwl_dbgfs_uapsd_noagg_bssids_read(struct file *file, char __user *user_buf,
1750 				  size_t count, loff_t *ppos)
1751 {
1752 	struct iwl_mvm *mvm = file->private_data;
1753 	u8 buf[IWL_MVM_UAPSD_NOAGG_BSSIDS_NUM * ETH_ALEN * 3 + 1];
1754 	unsigned int pos = 0;
1755 	size_t bufsz = sizeof(buf);
1756 	int i;
1757 
1758 	mutex_lock(&mvm->mutex);
1759 
1760 	for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++)
1761 		pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
1762 				 mvm->uapsd_noagg_bssids[i].addr);
1763 
1764 	mutex_unlock(&mvm->mutex);
1765 
1766 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1767 }
1768 
1769 static ssize_t
1770 iwl_dbgfs_ltr_config_write(struct iwl_mvm *mvm,
1771 			   char *buf, size_t count, loff_t *ppos)
1772 {
1773 	int ret;
1774 	struct iwl_ltr_config_cmd ltr_config = {0};
1775 
1776 	if (!iwl_mvm_firmware_running(mvm))
1777 		return -EIO;
1778 
1779 	if (sscanf(buf, "%x,%x,%x,%x,%x,%x,%x",
1780 		   &ltr_config.flags,
1781 		   &ltr_config.static_long,
1782 		   &ltr_config.static_short,
1783 		   &ltr_config.ltr_cfg_values[0],
1784 		   &ltr_config.ltr_cfg_values[1],
1785 		   &ltr_config.ltr_cfg_values[2],
1786 		   &ltr_config.ltr_cfg_values[3]) != 7) {
1787 		return -EINVAL;
1788 	}
1789 
1790 	mutex_lock(&mvm->mutex);
1791 	ret = iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0, sizeof(ltr_config),
1792 				   &ltr_config);
1793 	mutex_unlock(&mvm->mutex);
1794 
1795 	if (ret)
1796 		IWL_ERR(mvm, "failed to send ltr configuration cmd\n");
1797 
1798 	return ret ?: count;
1799 }
1800 
1801 MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);
1802 
1803 /* Device wide debugfs entries */
1804 MVM_DEBUGFS_READ_FILE_OPS(ctdp_budget);
1805 MVM_DEBUGFS_WRITE_FILE_OPS(stop_ctdp, 8);
1806 MVM_DEBUGFS_WRITE_FILE_OPS(force_ctkill, 8);
1807 MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
1808 MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
1809 MVM_DEBUGFS_WRITE_FILE_OPS(send_echo_cmd, 8);
1810 MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64);
1811 MVM_DEBUGFS_READ_WRITE_FILE_OPS(set_nic_temperature, 64);
1812 MVM_DEBUGFS_READ_FILE_OPS(nic_temp);
1813 MVM_DEBUGFS_READ_FILE_OPS(stations);
1814 MVM_DEBUGFS_READ_FILE_OPS(rs_data);
1815 MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
1816 MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
1817 MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64);
1818 MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
1819 MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats);
1820 MVM_DEBUGFS_READ_FILE_OPS(fw_ver);
1821 MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10);
1822 MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10);
1823 MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10);
1824 MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant, 10);
1825 MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
1826 MVM_DEBUGFS_READ_WRITE_FILE_OPS(fw_dbg_conf, 8);
1827 MVM_DEBUGFS_WRITE_FILE_OPS(fw_dbg_collect, 64);
1828 MVM_DEBUGFS_WRITE_FILE_OPS(indirection_tbl,
1829 			   (IWL_RSS_INDIRECTION_TABLE_SIZE * 2));
1830 MVM_DEBUGFS_WRITE_FILE_OPS(inject_packet, 512);
1831 MVM_DEBUGFS_WRITE_FILE_OPS(inject_beacon_ie, 512);
1832 MVM_DEBUGFS_WRITE_FILE_OPS(inject_beacon_ie_restore, 512);
1833 
1834 MVM_DEBUGFS_READ_FILE_OPS(uapsd_noagg_bssids);
1835 
1836 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1837 MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256);
1838 MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256);
1839 #endif
1840 
1841 #ifdef CONFIG_ACPI
1842 MVM_DEBUGFS_READ_FILE_OPS(sar_geo_profile);
1843 #endif
1844 
1845 MVM_DEBUGFS_READ_WRITE_STA_FILE_OPS(amsdu_len, 16);
1846 
1847 MVM_DEBUGFS_READ_WRITE_FILE_OPS(he_sniffer_params, 32);
1848 
1849 MVM_DEBUGFS_WRITE_FILE_OPS(ltr_config, 512);
1850 
1851 static ssize_t iwl_dbgfs_mem_read(struct file *file, char __user *user_buf,
1852 				  size_t count, loff_t *ppos)
1853 {
1854 	struct iwl_mvm *mvm = file->private_data;
1855 	struct iwl_dbg_mem_access_cmd cmd = {};
1856 	struct iwl_dbg_mem_access_rsp *rsp;
1857 	struct iwl_host_cmd hcmd = {
1858 		.flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
1859 		.data = { &cmd, },
1860 		.len = { sizeof(cmd) },
1861 	};
1862 	size_t delta;
1863 	ssize_t ret, len;
1864 
1865 	if (!iwl_mvm_firmware_running(mvm))
1866 		return -EIO;
1867 
1868 	hcmd.id = iwl_cmd_id(*ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR,
1869 			     DEBUG_GROUP, 0);
1870 	cmd.op = cpu_to_le32(DEBUG_MEM_OP_READ);
1871 
1872 	/* Take care of alignment of both the position and the length */
1873 	delta = *ppos & 0x3;
1874 	cmd.addr = cpu_to_le32(*ppos - delta);
1875 	cmd.len = cpu_to_le32(min(ALIGN(count + delta, 4) / 4,
1876 				  (size_t)DEBUG_MEM_MAX_SIZE_DWORDS));
1877 
1878 	mutex_lock(&mvm->mutex);
1879 	ret = iwl_mvm_send_cmd(mvm, &hcmd);
1880 	mutex_unlock(&mvm->mutex);
1881 
1882 	if (ret < 0)
1883 		return ret;
1884 
1885 	rsp = (void *)hcmd.resp_pkt->data;
1886 	if (le32_to_cpu(rsp->status) != DEBUG_MEM_STATUS_SUCCESS) {
1887 		ret = -ENXIO;
1888 		goto out;
1889 	}
1890 
1891 	len = min((size_t)le32_to_cpu(rsp->len) << 2,
1892 		  iwl_rx_packet_payload_len(hcmd.resp_pkt) - sizeof(*rsp));
1893 	len = min(len - delta, count);
1894 	if (len < 0) {
1895 		ret = -EFAULT;
1896 		goto out;
1897 	}
1898 
1899 	ret = len - copy_to_user(user_buf, (void *)rsp->data + delta, len);
1900 	*ppos += ret;
1901 
1902 out:
1903 	iwl_free_resp(&hcmd);
1904 	return ret;
1905 }
1906 
1907 static ssize_t iwl_dbgfs_mem_write(struct file *file,
1908 				   const char __user *user_buf, size_t count,
1909 				   loff_t *ppos)
1910 {
1911 	struct iwl_mvm *mvm = file->private_data;
1912 	struct iwl_dbg_mem_access_cmd *cmd;
1913 	struct iwl_dbg_mem_access_rsp *rsp;
1914 	struct iwl_host_cmd hcmd = {};
1915 	size_t cmd_size;
1916 	size_t data_size;
1917 	u32 op, len;
1918 	ssize_t ret;
1919 
1920 	if (!iwl_mvm_firmware_running(mvm))
1921 		return -EIO;
1922 
1923 	hcmd.id = iwl_cmd_id(*ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR,
1924 			     DEBUG_GROUP, 0);
1925 
1926 	if (*ppos & 0x3 || count < 4) {
1927 		op = DEBUG_MEM_OP_WRITE_BYTES;
1928 		len = min(count, (size_t)(4 - (*ppos & 0x3)));
1929 		data_size = len;
1930 	} else {
1931 		op = DEBUG_MEM_OP_WRITE;
1932 		len = min(count >> 2, (size_t)DEBUG_MEM_MAX_SIZE_DWORDS);
1933 		data_size = len << 2;
1934 	}
1935 
1936 	cmd_size = sizeof(*cmd) + ALIGN(data_size, 4);
1937 	cmd = kzalloc(cmd_size, GFP_KERNEL);
1938 	if (!cmd)
1939 		return -ENOMEM;
1940 
1941 	cmd->op = cpu_to_le32(op);
1942 	cmd->len = cpu_to_le32(len);
1943 	cmd->addr = cpu_to_le32(*ppos);
1944 	if (copy_from_user((void *)cmd->data, user_buf, data_size)) {
1945 		kfree(cmd);
1946 		return -EFAULT;
1947 	}
1948 
1949 	hcmd.flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
1950 	hcmd.data[0] = (void *)cmd;
1951 	hcmd.len[0] = cmd_size;
1952 
1953 	mutex_lock(&mvm->mutex);
1954 	ret = iwl_mvm_send_cmd(mvm, &hcmd);
1955 	mutex_unlock(&mvm->mutex);
1956 
1957 	kfree(cmd);
1958 
1959 	if (ret < 0)
1960 		return ret;
1961 
1962 	rsp = (void *)hcmd.resp_pkt->data;
1963 	if (rsp->status != DEBUG_MEM_STATUS_SUCCESS) {
1964 		ret = -ENXIO;
1965 		goto out;
1966 	}
1967 
1968 	ret = data_size;
1969 	*ppos += ret;
1970 
1971 out:
1972 	iwl_free_resp(&hcmd);
1973 	return ret;
1974 }
1975 
1976 static const struct file_operations iwl_dbgfs_mem_ops = {
1977 	.read = iwl_dbgfs_mem_read,
1978 	.write = iwl_dbgfs_mem_write,
1979 	.open = simple_open,
1980 	.llseek = default_llseek,
1981 };
1982 
1983 void iwl_mvm_sta_add_debugfs(struct ieee80211_hw *hw,
1984 			     struct ieee80211_vif *vif,
1985 			     struct ieee80211_sta *sta,
1986 			     struct dentry *dir)
1987 {
1988 	struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1989 
1990 	if (iwl_mvm_has_tlc_offload(mvm)) {
1991 		MVM_DEBUGFS_ADD_STA_FILE(rs_data, dir, 0400);
1992 	}
1993 	MVM_DEBUGFS_ADD_STA_FILE(amsdu_len, dir, 0600);
1994 }
1995 
1996 void iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
1997 {
1998 	struct dentry *bcast_dir __maybe_unused;
1999 	char buf[100];
2000 
2001 	spin_lock_init(&mvm->drv_stats_lock);
2002 
2003 	mvm->debugfs_dir = dbgfs_dir;
2004 
2005 	MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, 0200);
2006 	MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, 0200);
2007 	MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, 0600);
2008 	MVM_DEBUGFS_ADD_FILE(set_nic_temperature, mvm->debugfs_dir, 0600);
2009 	MVM_DEBUGFS_ADD_FILE(nic_temp, dbgfs_dir, 0400);
2010 	MVM_DEBUGFS_ADD_FILE(ctdp_budget, dbgfs_dir, 0400);
2011 	MVM_DEBUGFS_ADD_FILE(stop_ctdp, dbgfs_dir, 0200);
2012 	MVM_DEBUGFS_ADD_FILE(force_ctkill, dbgfs_dir, 0200);
2013 	MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, 0400);
2014 	MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, 0400);
2015 	MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, 0400);
2016 	MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir, 0600);
2017 	MVM_DEBUGFS_ADD_FILE(fw_ver, mvm->debugfs_dir, 0400);
2018 	MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, 0400);
2019 	MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, 0400);
2020 	MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, 0200);
2021 	MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, 0200);
2022 	MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, 0200);
2023 	MVM_DEBUGFS_ADD_FILE(bt_force_ant, mvm->debugfs_dir, 0200);
2024 	MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir, 0600);
2025 	MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, 0600);
2026 	MVM_DEBUGFS_ADD_FILE(fw_dbg_conf, mvm->debugfs_dir, 0600);
2027 	MVM_DEBUGFS_ADD_FILE(fw_dbg_collect, mvm->debugfs_dir, 0200);
2028 	MVM_DEBUGFS_ADD_FILE(send_echo_cmd, mvm->debugfs_dir, 0200);
2029 	MVM_DEBUGFS_ADD_FILE(indirection_tbl, mvm->debugfs_dir, 0200);
2030 	MVM_DEBUGFS_ADD_FILE(inject_packet, mvm->debugfs_dir, 0200);
2031 	MVM_DEBUGFS_ADD_FILE(inject_beacon_ie, mvm->debugfs_dir, 0200);
2032 	MVM_DEBUGFS_ADD_FILE(inject_beacon_ie_restore, mvm->debugfs_dir, 0200);
2033 #ifdef CONFIG_ACPI
2034 	MVM_DEBUGFS_ADD_FILE(sar_geo_profile, dbgfs_dir, 0400);
2035 #endif
2036 	MVM_DEBUGFS_ADD_FILE(he_sniffer_params, mvm->debugfs_dir, 0600);
2037 
2038 	if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_SET_LTR_GEN2))
2039 		MVM_DEBUGFS_ADD_FILE(ltr_config, mvm->debugfs_dir, 0200);
2040 
2041 	debugfs_create_bool("enable_scan_iteration_notif", 0600,
2042 			    mvm->debugfs_dir, &mvm->scan_iter_notif_enabled);
2043 	debugfs_create_bool("drop_bcn_ap_mode", 0600, mvm->debugfs_dir,
2044 			    &mvm->drop_bcn_ap_mode);
2045 
2046 	MVM_DEBUGFS_ADD_FILE(uapsd_noagg_bssids, mvm->debugfs_dir, S_IRUSR);
2047 
2048 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
2049 	if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING) {
2050 		bcast_dir = debugfs_create_dir("bcast_filtering",
2051 					       mvm->debugfs_dir);
2052 
2053 		debugfs_create_bool("override", 0600, bcast_dir,
2054 				    &mvm->dbgfs_bcast_filtering.override);
2055 
2056 		MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters,
2057 					   bcast_dir, 0600);
2058 		MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs,
2059 					   bcast_dir, 0600);
2060 	}
2061 #endif
2062 
2063 #ifdef CONFIG_PM_SLEEP
2064 	MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, 0400);
2065 	debugfs_create_bool("d3_wake_sysassert", 0600, mvm->debugfs_dir,
2066 			    &mvm->d3_wake_sysassert);
2067 	debugfs_create_u32("last_netdetect_scans", 0400, mvm->debugfs_dir,
2068 			   &mvm->last_netdetect_scans);
2069 #endif
2070 
2071 	debugfs_create_u8("ps_disabled", 0400, mvm->debugfs_dir,
2072 			  &mvm->ps_disabled);
2073 	debugfs_create_blob("nvm_hw", 0400, mvm->debugfs_dir,
2074 			    &mvm->nvm_hw_blob);
2075 	debugfs_create_blob("nvm_sw", 0400, mvm->debugfs_dir,
2076 			    &mvm->nvm_sw_blob);
2077 	debugfs_create_blob("nvm_calib", 0400, mvm->debugfs_dir,
2078 			    &mvm->nvm_calib_blob);
2079 	debugfs_create_blob("nvm_prod", 0400, mvm->debugfs_dir,
2080 			    &mvm->nvm_prod_blob);
2081 	debugfs_create_blob("nvm_phy_sku", 0400, mvm->debugfs_dir,
2082 			    &mvm->nvm_phy_sku_blob);
2083 	debugfs_create_blob("nvm_reg", S_IRUSR,
2084 			    mvm->debugfs_dir, &mvm->nvm_reg_blob);
2085 
2086 	debugfs_create_file("mem", 0600, dbgfs_dir, mvm, &iwl_dbgfs_mem_ops);
2087 
2088 	/*
2089 	 * Create a symlink with mac80211. It will be removed when mac80211
2090 	 * exists (before the opmode exists which removes the target.)
2091 	 */
2092 	snprintf(buf, 100, "../../%pd2", dbgfs_dir->d_parent);
2093 	debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf);
2094 }
2095