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