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