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