1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
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
7 #include <linux/vmalloc.h>
9 #include <linux/ieee80211.h>
10 #include <linux/netdevice.h>
11 #include <linux/dmi.h>
17 #include "iwl-modparams.h"
18 #include "fw/error-dump.h"
19 #include "fw/api/phy-ctxt.h"
21 static ssize_t iwl_dbgfs_ctdp_budget_read(struct file *file,
22 char __user *user_buf,
23 size_t count, loff_t *ppos)
25 struct iwl_mvm *mvm = file->private_data;
29 if (!iwl_mvm_is_ctdp_supported(mvm))
32 if (!iwl_mvm_firmware_running(mvm) ||
33 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
36 mutex_lock(&mvm->mutex);
37 budget = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_REPORT, 0);
38 mutex_unlock(&mvm->mutex);
43 pos = scnprintf(buf, sizeof(buf), "%d\n", budget);
45 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
48 static ssize_t iwl_dbgfs_stop_ctdp_write(struct iwl_mvm *mvm, char *buf,
49 size_t count, loff_t *ppos)
53 if (!iwl_mvm_is_ctdp_supported(mvm))
56 if (!iwl_mvm_firmware_running(mvm) ||
57 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
60 mutex_lock(&mvm->mutex);
61 ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_STOP, 0);
62 mutex_unlock(&mvm->mutex);
67 static ssize_t iwl_dbgfs_force_ctkill_write(struct iwl_mvm *mvm, char *buf,
68 size_t count, loff_t *ppos)
70 if (!iwl_mvm_firmware_running(mvm) ||
71 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
74 iwl_mvm_enter_ctkill(mvm);
79 static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf,
80 size_t count, loff_t *ppos)
85 if (!iwl_mvm_firmware_running(mvm) ||
86 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
89 if (kstrtou32(buf, 0, &flush_arg))
92 if (iwl_mvm_has_new_tx_api(mvm)) {
93 IWL_DEBUG_TX_QUEUES(mvm,
94 "FLUSHING all tids queues on sta_id = %d\n",
96 mutex_lock(&mvm->mutex);
97 ret = iwl_mvm_flush_sta_tids(mvm, flush_arg, 0xFFFF)
99 mutex_unlock(&mvm->mutex);
103 IWL_DEBUG_TX_QUEUES(mvm, "FLUSHING queues mask to flush = 0x%x\n",
106 mutex_lock(&mvm->mutex);
107 ret = iwl_mvm_flush_tx_path(mvm, flush_arg) ? : count;
108 mutex_unlock(&mvm->mutex);
113 static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf,
114 size_t count, loff_t *ppos)
116 struct iwl_mvm_sta *mvmsta;
117 int sta_id, drain, ret;
119 if (!iwl_mvm_firmware_running(mvm) ||
120 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
123 if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
125 if (sta_id < 0 || sta_id >= mvm->fw->ucode_capa.num_stations)
127 if (drain < 0 || drain > 1)
130 mutex_lock(&mvm->mutex);
132 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
137 ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count;
139 mutex_unlock(&mvm->mutex);
144 static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
145 size_t count, loff_t *ppos)
147 struct iwl_mvm *mvm = file->private_data;
148 const struct fw_img *img;
149 unsigned int ofs, len;
153 if (!iwl_mvm_firmware_running(mvm))
156 /* default is to dump the entire data segment */
157 img = &mvm->fw->img[mvm->fwrt.cur_fw_img];
158 ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
159 len = img->sec[IWL_UCODE_SECTION_DATA].len;
161 if (mvm->dbgfs_sram_len) {
162 ofs = mvm->dbgfs_sram_offset;
163 len = mvm->dbgfs_sram_len;
166 ptr = kzalloc(len, GFP_KERNEL);
170 iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
172 ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len);
179 static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf,
180 size_t count, loff_t *ppos)
182 const struct fw_img *img;
184 u32 img_offset, img_len;
186 if (!iwl_mvm_firmware_running(mvm))
189 img = &mvm->fw->img[mvm->fwrt.cur_fw_img];
190 img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset;
191 img_len = img->sec[IWL_UCODE_SECTION_DATA].len;
193 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
194 if ((offset & 0x3) || (len & 0x3))
197 if (offset + len > img_offset + img_len)
200 mvm->dbgfs_sram_offset = offset;
201 mvm->dbgfs_sram_len = len;
203 mvm->dbgfs_sram_offset = 0;
204 mvm->dbgfs_sram_len = 0;
210 static ssize_t iwl_dbgfs_set_nic_temperature_read(struct file *file,
211 char __user *user_buf,
212 size_t count, loff_t *ppos)
214 struct iwl_mvm *mvm = file->private_data;
218 if (!mvm->temperature_test)
219 pos = scnprintf(buf, sizeof(buf), "disabled\n");
221 pos = scnprintf(buf, sizeof(buf), "%d\n", mvm->temperature);
223 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
227 * Set NIC Temperature
228 * Cause the driver to ignore the actual NIC temperature reported by the FW
229 * Enable: any value between IWL_MVM_DEBUG_SET_TEMPERATURE_MIN -
230 * IWL_MVM_DEBUG_SET_TEMPERATURE_MAX
231 * Disable: IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE
233 static ssize_t iwl_dbgfs_set_nic_temperature_write(struct iwl_mvm *mvm,
234 char *buf, size_t count,
239 if (!iwl_mvm_firmware_running(mvm) && !mvm->temperature_test)
242 if (kstrtoint(buf, 10, &temperature))
244 /* not a legal temperature */
245 if ((temperature > IWL_MVM_DEBUG_SET_TEMPERATURE_MAX &&
246 temperature != IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) ||
247 temperature < IWL_MVM_DEBUG_SET_TEMPERATURE_MIN)
250 mutex_lock(&mvm->mutex);
251 if (temperature == IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) {
252 if (!mvm->temperature_test)
255 mvm->temperature_test = false;
256 /* Since we can't read the temp while awake, just set
257 * it to zero until we get the next RX stats from the
260 mvm->temperature = 0;
262 mvm->temperature_test = true;
263 mvm->temperature = temperature;
265 IWL_DEBUG_TEMP(mvm, "%sabling debug set temperature (temp = %d)\n",
266 mvm->temperature_test ? "En" : "Dis",
268 /* handle the temperature change */
269 iwl_mvm_tt_handler(mvm);
272 mutex_unlock(&mvm->mutex);
277 static ssize_t iwl_dbgfs_nic_temp_read(struct file *file,
278 char __user *user_buf,
279 size_t count, loff_t *ppos)
281 struct iwl_mvm *mvm = file->private_data;
286 if (!iwl_mvm_firmware_running(mvm))
289 mutex_lock(&mvm->mutex);
290 ret = iwl_mvm_get_temp(mvm, &temp);
291 mutex_unlock(&mvm->mutex);
296 pos = scnprintf(buf, sizeof(buf), "%d\n", temp);
298 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
302 static ssize_t iwl_dbgfs_sar_geo_profile_read(struct file *file,
303 char __user *user_buf,
304 size_t count, loff_t *ppos)
306 struct iwl_mvm *mvm = file->private_data;
309 int bufsz = sizeof(buf);
312 if (!iwl_mvm_firmware_running(mvm))
315 mutex_lock(&mvm->mutex);
316 tbl_idx = iwl_mvm_get_sar_geo_profile(mvm);
318 mutex_unlock(&mvm->mutex);
323 pos = scnprintf(buf, bufsz,
324 "SAR geographic profile disabled\n");
326 pos += scnprintf(buf + pos, bufsz - pos,
327 "Use geographic profile %d\n", tbl_idx);
328 pos += scnprintf(buf + pos, bufsz - pos,
329 "2.4GHz:\n\tChain A offset: %u dBm\n\tChain B offset: %u dBm\n\tmax tx power: %u dBm\n",
330 mvm->fwrt.geo_profiles[tbl_idx - 1].bands[0].chains[0],
331 mvm->fwrt.geo_profiles[tbl_idx - 1].bands[0].chains[1],
332 mvm->fwrt.geo_profiles[tbl_idx - 1].bands[0].max);
333 pos += scnprintf(buf + pos, bufsz - pos,
334 "5.2GHz:\n\tChain A offset: %u dBm\n\tChain B offset: %u dBm\n\tmax tx power: %u dBm\n",
335 mvm->fwrt.geo_profiles[tbl_idx - 1].bands[1].chains[0],
336 mvm->fwrt.geo_profiles[tbl_idx - 1].bands[1].chains[1],
337 mvm->fwrt.geo_profiles[tbl_idx - 1].bands[1].max);
339 mutex_unlock(&mvm->mutex);
341 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
344 static ssize_t iwl_dbgfs_wifi_6e_enable_read(struct file *file,
345 char __user *user_buf,
346 size_t count, loff_t *ppos)
348 struct iwl_mvm *mvm = file->private_data;
353 err = iwl_acpi_get_dsm_u32(mvm->fwrt.dev, 0,
359 pos = sprintf(buf, "0x%08x\n", value);
361 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
365 static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
366 size_t count, loff_t *ppos)
368 struct iwl_mvm *mvm = file->private_data;
369 struct ieee80211_sta *sta;
371 int i, pos = 0, bufsz = sizeof(buf);
373 mutex_lock(&mvm->mutex);
375 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) {
376 pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
377 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
378 lockdep_is_held(&mvm->mutex));
380 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
381 else if (IS_ERR(sta))
382 pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
385 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
389 mutex_unlock(&mvm->mutex);
391 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
394 static ssize_t iwl_dbgfs_rs_data_read(struct ieee80211_link_sta *link_sta,
395 struct iwl_mvm_sta *mvmsta,
397 struct iwl_mvm_link_sta *mvm_link_sta,
398 char __user *user_buf,
399 size_t count, loff_t *ppos)
401 struct iwl_lq_sta_rs_fw *lq_sta = &mvm_link_sta->lq_sta.rs_fw;
402 static const size_t bufsz = 2048;
407 buff = kmalloc(bufsz, GFP_KERNEL);
411 desc += scnprintf(buff + desc, bufsz - desc, "sta_id %d\n",
412 lq_sta->pers.sta_id);
413 desc += scnprintf(buff + desc, bufsz - desc,
415 lq_sta->pers.dbg_fixed_rate);
416 desc += scnprintf(buff + desc, bufsz - desc,
417 "A-MPDU size limit %d\n",
418 lq_sta->pers.dbg_agg_frame_count_lim);
419 desc += scnprintf(buff + desc, bufsz - desc,
420 "valid_tx_ant %s%s\n",
421 (iwl_mvm_get_valid_tx_ant(mvm) & ANT_A) ? "ANT_A," : "",
422 (iwl_mvm_get_valid_tx_ant(mvm) & ANT_B) ? "ANT_B," : "");
423 desc += scnprintf(buff + desc, bufsz - desc,
424 "last tx rate=0x%X ",
425 lq_sta->last_rate_n_flags);
427 desc += rs_pretty_print_rate(buff + desc, bufsz - desc,
428 lq_sta->last_rate_n_flags);
429 if (desc < bufsz - 1)
432 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
437 static ssize_t iwl_dbgfs_amsdu_len_write(struct ieee80211_link_sta *link_sta,
438 struct iwl_mvm_sta *mvmsta,
440 struct iwl_mvm_link_sta *mvm_link_sta,
441 char *buf, size_t count,
447 if (kstrtou16(buf, 0, &amsdu_len))
450 /* only change from debug set <-> debug unset */
451 if (amsdu_len && mvm_link_sta->orig_amsdu_len)
455 mvm_link_sta->orig_amsdu_len = link_sta->agg.max_amsdu_len;
456 link_sta->agg.max_amsdu_len = amsdu_len;
457 link_sta->agg.max_amsdu_len = amsdu_len;
458 for (i = 0; i < ARRAY_SIZE(link_sta->agg.max_tid_amsdu_len); i++)
459 link_sta->agg.max_tid_amsdu_len[i] = amsdu_len;
461 link_sta->agg.max_amsdu_len = mvm_link_sta->orig_amsdu_len;
462 mvm_link_sta->orig_amsdu_len = 0;
465 ieee80211_sta_recalc_aggregates(link_sta->sta);
470 static ssize_t iwl_dbgfs_amsdu_len_read(struct ieee80211_link_sta *link_sta,
471 struct iwl_mvm_sta *mvmsta,
473 struct iwl_mvm_link_sta *mvm_link_sta,
474 char __user *user_buf,
475 size_t count, loff_t *ppos)
480 pos = scnprintf(buf, sizeof(buf), "current %d ",
481 link_sta->agg.max_amsdu_len);
482 pos += scnprintf(buf + pos, sizeof(buf) - pos, "stored %d\n",
483 mvm_link_sta->orig_amsdu_len);
485 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
488 static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
489 char __user *user_buf,
490 size_t count, loff_t *ppos)
492 struct iwl_mvm *mvm = file->private_data;
494 int bufsz = sizeof(buf);
497 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
498 mvm->disable_power_off);
499 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
500 mvm->disable_power_off_d3);
502 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
505 static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf,
506 size_t count, loff_t *ppos)
510 if (!iwl_mvm_firmware_running(mvm))
513 if (!strncmp("disable_power_off_d0=", buf, 21)) {
514 if (sscanf(buf + 21, "%d", &val) != 1)
516 mvm->disable_power_off = val;
517 } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
518 if (sscanf(buf + 21, "%d", &val) != 1)
520 mvm->disable_power_off_d3 = val;
525 mutex_lock(&mvm->mutex);
526 ret = iwl_mvm_power_update_device(mvm);
527 mutex_unlock(&mvm->mutex);
533 int iwl_mvm_coex_dump_mbox(struct iwl_bt_coex_profile_notif *notif, char *buf,
536 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
538 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
539 BT_MBOX_PRINT(0, LE_PROF1, false);
540 BT_MBOX_PRINT(0, LE_PROF2, false);
541 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
542 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
543 BT_MBOX_PRINT(0, INBAND_S, false);
544 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
545 BT_MBOX_PRINT(0, LE_SCAN, false);
546 BT_MBOX_PRINT(0, LE_ADV, false);
547 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
548 BT_MBOX_PRINT(0, OPEN_CON_1, true);
550 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
552 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
553 BT_MBOX_PRINT(1, IP_SR, false);
554 BT_MBOX_PRINT(1, LE_MSTR, false);
555 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
556 BT_MBOX_PRINT(1, MSG_TYPE, false);
557 BT_MBOX_PRINT(1, SSN, true);
559 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
561 BT_MBOX_PRINT(2, SNIFF_ACT, false);
562 BT_MBOX_PRINT(2, PAG, false);
563 BT_MBOX_PRINT(2, INQUIRY, false);
564 BT_MBOX_PRINT(2, CONN, false);
565 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
566 BT_MBOX_PRINT(2, DISC, false);
567 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
568 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
569 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
570 BT_MBOX_PRINT(2, SCO_DURATION, true);
572 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
574 BT_MBOX_PRINT(3, SCO_STATE, false);
575 BT_MBOX_PRINT(3, SNIFF_STATE, false);
576 BT_MBOX_PRINT(3, A2DP_STATE, false);
577 BT_MBOX_PRINT(3, A2DP_SRC, false);
578 BT_MBOX_PRINT(3, ACL_STATE, false);
579 BT_MBOX_PRINT(3, MSTR_STATE, false);
580 BT_MBOX_PRINT(3, OBX_STATE, false);
581 BT_MBOX_PRINT(3, OPEN_CON_2, false);
582 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
583 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
584 BT_MBOX_PRINT(3, INBAND_P, false);
585 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
586 BT_MBOX_PRINT(3, SSN_2, false);
587 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
592 static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
593 size_t count, loff_t *ppos)
595 struct iwl_mvm *mvm = file->private_data;
596 struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
598 int ret, pos = 0, bufsz = sizeof(char) * 1024;
600 buf = kmalloc(bufsz, GFP_KERNEL);
604 mutex_lock(&mvm->mutex);
606 pos += iwl_mvm_coex_dump_mbox(notif, buf, pos, bufsz);
608 pos += scnprintf(buf + pos, bufsz - pos, "bt_ci_compliance = %d\n",
609 notif->bt_ci_compliance);
610 pos += scnprintf(buf + pos, bufsz - pos, "primary_ch_lut = %d\n",
611 le32_to_cpu(notif->primary_ch_lut));
612 pos += scnprintf(buf + pos, bufsz - pos, "secondary_ch_lut = %d\n",
613 le32_to_cpu(notif->secondary_ch_lut));
614 pos += scnprintf(buf + pos,
615 bufsz - pos, "bt_activity_grading = %d\n",
616 le32_to_cpu(notif->bt_activity_grading));
617 pos += scnprintf(buf + pos, bufsz - pos, "bt_rrc = %d\n",
618 notif->rrc_status & 0xF);
619 pos += scnprintf(buf + pos, bufsz - pos, "bt_ttc = %d\n",
620 notif->ttc_status & 0xF);
622 pos += scnprintf(buf + pos, bufsz - pos, "sync_sco = %d\n",
623 IWL_MVM_BT_COEX_SYNC2SCO);
624 pos += scnprintf(buf + pos, bufsz - pos, "mplut = %d\n",
625 IWL_MVM_BT_COEX_MPLUT);
627 mutex_unlock(&mvm->mutex);
629 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
636 static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
637 size_t count, loff_t *ppos)
639 struct iwl_mvm *mvm = file->private_data;
640 struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
642 int bufsz = sizeof(buf);
645 mutex_lock(&mvm->mutex);
647 pos += scnprintf(buf + pos, bufsz - pos, "Channel inhibition CMD\n");
648 pos += scnprintf(buf + pos, bufsz - pos,
649 "\tPrimary Channel Bitmap 0x%016llx\n",
650 le64_to_cpu(cmd->bt_primary_ci));
651 pos += scnprintf(buf + pos, bufsz - pos,
652 "\tSecondary Channel Bitmap 0x%016llx\n",
653 le64_to_cpu(cmd->bt_secondary_ci));
655 mutex_unlock(&mvm->mutex);
657 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
661 iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf,
662 size_t count, loff_t *ppos)
666 if (sscanf(buf, "%u", &bt_tx_prio) != 1)
671 mvm->bt_tx_prio = bt_tx_prio;
677 iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char *buf,
678 size_t count, loff_t *ppos)
680 static const char * const modes_str[BT_FORCE_ANT_MAX] = {
681 [BT_FORCE_ANT_DIS] = "dis",
682 [BT_FORCE_ANT_AUTO] = "auto",
683 [BT_FORCE_ANT_BT] = "bt",
684 [BT_FORCE_ANT_WIFI] = "wifi",
686 int ret, bt_force_ant_mode;
688 ret = match_string(modes_str, ARRAY_SIZE(modes_str), buf);
692 bt_force_ant_mode = ret;
694 mutex_lock(&mvm->mutex);
695 if (mvm->bt_force_ant_mode == bt_force_ant_mode)
698 mvm->bt_force_ant_mode = bt_force_ant_mode;
699 IWL_DEBUG_COEX(mvm, "Force mode: %s\n",
700 modes_str[mvm->bt_force_ant_mode]);
702 if (iwl_mvm_firmware_running(mvm))
703 ret = iwl_mvm_send_bt_init_conf(mvm);
708 mutex_unlock(&mvm->mutex);
712 static ssize_t iwl_dbgfs_fw_ver_read(struct file *file, char __user *user_buf,
713 size_t count, loff_t *ppos)
715 struct iwl_mvm *mvm = file->private_data;
716 char *buff, *pos, *endpos;
717 static const size_t bufsz = 1024;
720 buff = kmalloc(bufsz, GFP_KERNEL);
725 endpos = pos + bufsz;
727 pos += scnprintf(pos, endpos - pos, "FW prefix: %s\n",
728 mvm->trans->cfg->fw_name_pre);
729 pos += scnprintf(pos, endpos - pos, "FW: %s\n",
730 mvm->fwrt.fw->human_readable);
731 pos += scnprintf(pos, endpos - pos, "Device: %s\n",
732 mvm->fwrt.trans->name);
733 pos += scnprintf(pos, endpos - pos, "Bus: %s\n",
734 mvm->fwrt.dev->bus->name);
736 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
742 static ssize_t iwl_dbgfs_tas_get_status_read(struct file *file,
743 char __user *user_buf,
744 size_t count, loff_t *ppos)
746 struct iwl_mvm *mvm = file->private_data;
747 struct iwl_mvm_tas_status_resp tas_rsp;
748 struct iwl_mvm_tas_status_resp *rsp = &tas_rsp;
749 static const size_t bufsz = 1024;
750 char *buff, *pos, *endpos;
751 const char * const tas_dis_reason[TAS_DISABLED_REASON_MAX] = {
752 [TAS_DISABLED_DUE_TO_BIOS] =
754 [TAS_DISABLED_DUE_TO_SAR_6DBM] =
755 "Due To SAR Limit Less Than 6 dBm",
756 [TAS_DISABLED_REASON_INVALID] =
759 const char * const tas_current_status[TAS_DYNA_STATUS_MAX] = {
760 [TAS_DYNA_INACTIVE] = "INACTIVE",
761 [TAS_DYNA_INACTIVE_MVM_MODE] =
762 "inactive due to mvm mode",
763 [TAS_DYNA_INACTIVE_TRIGGER_MODE] =
764 "inactive due to trigger mode",
765 [TAS_DYNA_INACTIVE_BLOCK_LISTED] =
766 "inactive due to block listed",
767 [TAS_DYNA_INACTIVE_UHB_NON_US] =
768 "inactive due to uhb non US",
769 [TAS_DYNA_ACTIVE] = "ACTIVE",
771 struct iwl_host_cmd hcmd = {
772 .id = WIDE_ID(DEBUG_GROUP, GET_TAS_STATUS),
773 .flags = CMD_WANT_SKB,
778 bool tas_enabled = false;
779 unsigned long dyn_status;
781 if (!iwl_mvm_firmware_running(mvm))
784 mutex_lock(&mvm->mutex);
785 ret = iwl_mvm_send_cmd(mvm, &hcmd);
786 mutex_unlock(&mvm->mutex);
790 buff = kzalloc(bufsz, GFP_KERNEL);
794 endpos = pos + bufsz;
796 rsp = (void *)hcmd.resp_pkt->data;
798 pos += scnprintf(pos, endpos - pos, "TAS Conclusion:\n");
799 for (i = 0; i < rsp->in_dual_radio + 1; i++) {
800 if (rsp->tas_status_mac[i].band != TAS_LMAC_BAND_INVALID &&
801 rsp->tas_status_mac[i].dynamic_status & BIT(TAS_DYNA_ACTIVE)) {
802 pos += scnprintf(pos, endpos - pos, "\tON for ");
803 switch (rsp->tas_status_mac[i].band) {
804 case TAS_LMAC_BAND_HB:
805 pos += scnprintf(pos, endpos - pos, "HB\n");
807 case TAS_LMAC_BAND_LB:
808 pos += scnprintf(pos, endpos - pos, "LB\n");
810 case TAS_LMAC_BAND_UHB:
811 pos += scnprintf(pos, endpos - pos, "UHB\n");
813 case TAS_LMAC_BAND_INVALID:
814 pos += scnprintf(pos, endpos - pos,
818 pos += scnprintf(pos, endpos - pos,
819 "Unsupported band (%d)\n",
820 rsp->tas_status_mac[i].band);
827 pos += scnprintf(pos, endpos - pos, "\tOFF\n");
829 pos += scnprintf(pos, endpos - pos, "TAS Report\n");
830 pos += scnprintf(pos, endpos - pos, "TAS FW version: %d\n",
831 rsp->tas_fw_version);
832 pos += scnprintf(pos, endpos - pos, "Is UHB enabled for USA?: %s\n",
833 rsp->is_uhb_for_usa_enable ? "True" : "False");
834 pos += scnprintf(pos, endpos - pos, "Current MCC: 0x%x\n",
835 le16_to_cpu(rsp->curr_mcc));
837 pos += scnprintf(pos, endpos - pos, "Block list entries:");
838 for (i = 0; i < APCI_WTAS_BLACK_LIST_MAX; i++)
839 pos += scnprintf(pos, endpos - pos, " 0x%x",
840 le16_to_cpu(rsp->block_list[i]));
842 pos += scnprintf(pos, endpos - pos, "\nOEM name: %s\n",
843 dmi_get_system_info(DMI_SYS_VENDOR));
844 pos += scnprintf(pos, endpos - pos, "\tVendor In Approved List: %s\n",
845 iwl_mvm_is_vendor_in_approved_list() ? "YES" : "NO");
846 pos += scnprintf(pos, endpos - pos,
847 "\tDo TAS Support Dual Radio?: %s\n",
848 rsp->in_dual_radio ? "TRUE" : "FALSE");
850 for (i = 0; i < rsp->in_dual_radio + 1; i++) {
851 if (rsp->tas_status_mac[i].static_status == 0) {
852 pos += scnprintf(pos, endpos - pos,
853 "Static status: disabled\n");
854 pos += scnprintf(pos, endpos - pos,
855 "Static disabled reason: %s (0)\n",
860 pos += scnprintf(pos, endpos - pos, "TAS status for ");
861 switch (rsp->tas_status_mac[i].band) {
862 case TAS_LMAC_BAND_HB:
863 pos += scnprintf(pos, endpos - pos, "High band\n");
865 case TAS_LMAC_BAND_LB:
866 pos += scnprintf(pos, endpos - pos, "Low band\n");
868 case TAS_LMAC_BAND_UHB:
869 pos += scnprintf(pos, endpos - pos,
870 "Ultra high band\n");
872 case TAS_LMAC_BAND_INVALID:
873 pos += scnprintf(pos, endpos - pos,
877 pos += scnprintf(pos, endpos - pos,
878 "Unsupported band (%d)\n",
879 rsp->tas_status_mac[i].band);
882 pos += scnprintf(pos, endpos - pos, "Static status: %sabled\n",
883 rsp->tas_status_mac[i].static_status ?
885 pos += scnprintf(pos, endpos - pos,
886 "\tStatic Disabled Reason: ");
887 if (rsp->tas_status_mac[i].static_dis_reason < TAS_DISABLED_REASON_MAX)
888 pos += scnprintf(pos, endpos - pos, "%s (%d)\n",
889 tas_dis_reason[rsp->tas_status_mac[i].static_dis_reason],
890 rsp->tas_status_mac[i].static_dis_reason);
892 pos += scnprintf(pos, endpos - pos,
893 "unsupported value (%d)\n",
894 rsp->tas_status_mac[i].static_dis_reason);
896 pos += scnprintf(pos, endpos - pos, "Dynamic status:\n");
897 dyn_status = (rsp->tas_status_mac[i].dynamic_status);
898 for_each_set_bit(tmp, &dyn_status, sizeof(dyn_status)) {
899 if (tmp >= 0 && tmp < TAS_DYNA_STATUS_MAX)
900 pos += scnprintf(pos, endpos - pos,
902 tas_current_status[tmp], tmp);
905 pos += scnprintf(pos, endpos - pos,
906 "Is near disconnection?: %s\n",
907 rsp->tas_status_mac[i].near_disconnection ?
909 tmp = le16_to_cpu(rsp->tas_status_mac[i].max_reg_pwr_limit);
910 pos += scnprintf(pos, endpos - pos,
911 "Max. regulatory pwr limit (dBm): %d.%03d\n",
912 tmp / 8, 125 * (tmp % 8));
913 tmp = le16_to_cpu(rsp->tas_status_mac[i].sar_limit);
914 pos += scnprintf(pos, endpos - pos,
915 "SAR limit (dBm): %d.%03d\n",
916 tmp / 8, 125 * (tmp % 8));
920 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
922 iwl_free_resp(&hcmd);
926 static ssize_t iwl_dbgfs_phy_integration_ver_read(struct file *file,
927 char __user *user_buf,
928 size_t count, loff_t *ppos)
930 struct iwl_mvm *mvm = file->private_data;
936 bufsz = mvm->fw->phy_integration_ver_len + 2;
937 buf = kmalloc(bufsz, GFP_KERNEL);
941 pos = scnprintf(buf, bufsz, "%.*s\n", mvm->fw->phy_integration_ver_len,
942 mvm->fw->phy_integration_ver);
944 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
950 #define PRINT_STATS_LE32(_struct, _memb) \
951 pos += scnprintf(buf + pos, bufsz - pos, \
953 le32_to_cpu(_struct->_memb))
955 static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
956 char __user *user_buf, size_t count,
959 struct iwl_mvm *mvm = file->private_data;
960 static const char *fmt_table = "\t%-30s %10u\n";
961 static const char *fmt_header = "%-32s\n";
967 if (iwl_mvm_has_new_rx_stats_api(mvm))
968 bufsz = ((sizeof(struct mvm_statistics_rx) /
969 sizeof(__le32)) * 43) + (4 * 33) + 1;
971 /* 43 = size of each data line; 33 = size of each header */
972 bufsz = ((sizeof(struct mvm_statistics_rx_v3) /
973 sizeof(__le32)) * 43) + (4 * 33) + 1;
975 buf = kzalloc(bufsz, GFP_KERNEL);
979 mutex_lock(&mvm->mutex);
981 if (iwl_mvm_firmware_running(mvm))
982 iwl_mvm_request_statistics(mvm, false);
984 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
985 "Statistics_Rx - OFDM");
986 if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
987 struct mvm_statistics_rx_phy_v2 *ofdm = &mvm->rx_stats_v3.ofdm;
989 PRINT_STATS_LE32(ofdm, ina_cnt);
990 PRINT_STATS_LE32(ofdm, fina_cnt);
991 PRINT_STATS_LE32(ofdm, plcp_err);
992 PRINT_STATS_LE32(ofdm, crc32_err);
993 PRINT_STATS_LE32(ofdm, overrun_err);
994 PRINT_STATS_LE32(ofdm, early_overrun_err);
995 PRINT_STATS_LE32(ofdm, crc32_good);
996 PRINT_STATS_LE32(ofdm, false_alarm_cnt);
997 PRINT_STATS_LE32(ofdm, fina_sync_err_cnt);
998 PRINT_STATS_LE32(ofdm, sfd_timeout);
999 PRINT_STATS_LE32(ofdm, fina_timeout);
1000 PRINT_STATS_LE32(ofdm, unresponded_rts);
1001 PRINT_STATS_LE32(ofdm, rxe_frame_lmt_overrun);
1002 PRINT_STATS_LE32(ofdm, sent_ack_cnt);
1003 PRINT_STATS_LE32(ofdm, sent_cts_cnt);
1004 PRINT_STATS_LE32(ofdm, sent_ba_rsp_cnt);
1005 PRINT_STATS_LE32(ofdm, dsp_self_kill);
1006 PRINT_STATS_LE32(ofdm, mh_format_err);
1007 PRINT_STATS_LE32(ofdm, re_acq_main_rssi_sum);
1008 PRINT_STATS_LE32(ofdm, reserved);
1010 struct mvm_statistics_rx_phy *ofdm = &mvm->rx_stats.ofdm;
1012 PRINT_STATS_LE32(ofdm, unresponded_rts);
1013 PRINT_STATS_LE32(ofdm, rxe_frame_lmt_overrun);
1014 PRINT_STATS_LE32(ofdm, sent_ba_rsp_cnt);
1015 PRINT_STATS_LE32(ofdm, dsp_self_kill);
1016 PRINT_STATS_LE32(ofdm, reserved);
1019 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
1020 "Statistics_Rx - CCK");
1021 if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
1022 struct mvm_statistics_rx_phy_v2 *cck = &mvm->rx_stats_v3.cck;
1024 PRINT_STATS_LE32(cck, ina_cnt);
1025 PRINT_STATS_LE32(cck, fina_cnt);
1026 PRINT_STATS_LE32(cck, plcp_err);
1027 PRINT_STATS_LE32(cck, crc32_err);
1028 PRINT_STATS_LE32(cck, overrun_err);
1029 PRINT_STATS_LE32(cck, early_overrun_err);
1030 PRINT_STATS_LE32(cck, crc32_good);
1031 PRINT_STATS_LE32(cck, false_alarm_cnt);
1032 PRINT_STATS_LE32(cck, fina_sync_err_cnt);
1033 PRINT_STATS_LE32(cck, sfd_timeout);
1034 PRINT_STATS_LE32(cck, fina_timeout);
1035 PRINT_STATS_LE32(cck, unresponded_rts);
1036 PRINT_STATS_LE32(cck, rxe_frame_lmt_overrun);
1037 PRINT_STATS_LE32(cck, sent_ack_cnt);
1038 PRINT_STATS_LE32(cck, sent_cts_cnt);
1039 PRINT_STATS_LE32(cck, sent_ba_rsp_cnt);
1040 PRINT_STATS_LE32(cck, dsp_self_kill);
1041 PRINT_STATS_LE32(cck, mh_format_err);
1042 PRINT_STATS_LE32(cck, re_acq_main_rssi_sum);
1043 PRINT_STATS_LE32(cck, reserved);
1045 struct mvm_statistics_rx_phy *cck = &mvm->rx_stats.cck;
1047 PRINT_STATS_LE32(cck, unresponded_rts);
1048 PRINT_STATS_LE32(cck, rxe_frame_lmt_overrun);
1049 PRINT_STATS_LE32(cck, sent_ba_rsp_cnt);
1050 PRINT_STATS_LE32(cck, dsp_self_kill);
1051 PRINT_STATS_LE32(cck, reserved);
1054 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
1055 "Statistics_Rx - GENERAL");
1056 if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
1057 struct mvm_statistics_rx_non_phy_v3 *general =
1058 &mvm->rx_stats_v3.general;
1060 PRINT_STATS_LE32(general, bogus_cts);
1061 PRINT_STATS_LE32(general, bogus_ack);
1062 PRINT_STATS_LE32(general, non_bssid_frames);
1063 PRINT_STATS_LE32(general, filtered_frames);
1064 PRINT_STATS_LE32(general, non_channel_beacons);
1065 PRINT_STATS_LE32(general, channel_beacons);
1066 PRINT_STATS_LE32(general, num_missed_bcon);
1067 PRINT_STATS_LE32(general, adc_rx_saturation_time);
1068 PRINT_STATS_LE32(general, ina_detection_search_time);
1069 PRINT_STATS_LE32(general, beacon_silence_rssi_a);
1070 PRINT_STATS_LE32(general, beacon_silence_rssi_b);
1071 PRINT_STATS_LE32(general, beacon_silence_rssi_c);
1072 PRINT_STATS_LE32(general, interference_data_flag);
1073 PRINT_STATS_LE32(general, channel_load);
1074 PRINT_STATS_LE32(general, dsp_false_alarms);
1075 PRINT_STATS_LE32(general, beacon_rssi_a);
1076 PRINT_STATS_LE32(general, beacon_rssi_b);
1077 PRINT_STATS_LE32(general, beacon_rssi_c);
1078 PRINT_STATS_LE32(general, beacon_energy_a);
1079 PRINT_STATS_LE32(general, beacon_energy_b);
1080 PRINT_STATS_LE32(general, beacon_energy_c);
1081 PRINT_STATS_LE32(general, num_bt_kills);
1082 PRINT_STATS_LE32(general, mac_id);
1083 PRINT_STATS_LE32(general, directed_data_mpdu);
1085 struct mvm_statistics_rx_non_phy *general =
1086 &mvm->rx_stats.general;
1088 PRINT_STATS_LE32(general, bogus_cts);
1089 PRINT_STATS_LE32(general, bogus_ack);
1090 PRINT_STATS_LE32(general, non_channel_beacons);
1091 PRINT_STATS_LE32(general, channel_beacons);
1092 PRINT_STATS_LE32(general, num_missed_bcon);
1093 PRINT_STATS_LE32(general, adc_rx_saturation_time);
1094 PRINT_STATS_LE32(general, ina_detection_search_time);
1095 PRINT_STATS_LE32(general, beacon_silence_rssi_a);
1096 PRINT_STATS_LE32(general, beacon_silence_rssi_b);
1097 PRINT_STATS_LE32(general, beacon_silence_rssi_c);
1098 PRINT_STATS_LE32(general, interference_data_flag);
1099 PRINT_STATS_LE32(general, channel_load);
1100 PRINT_STATS_LE32(general, beacon_rssi_a);
1101 PRINT_STATS_LE32(general, beacon_rssi_b);
1102 PRINT_STATS_LE32(general, beacon_rssi_c);
1103 PRINT_STATS_LE32(general, beacon_energy_a);
1104 PRINT_STATS_LE32(general, beacon_energy_b);
1105 PRINT_STATS_LE32(general, beacon_energy_c);
1106 PRINT_STATS_LE32(general, num_bt_kills);
1107 PRINT_STATS_LE32(general, mac_id);
1110 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
1111 "Statistics_Rx - HT");
1112 if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
1113 struct mvm_statistics_rx_ht_phy_v1 *ht =
1114 &mvm->rx_stats_v3.ofdm_ht;
1116 PRINT_STATS_LE32(ht, plcp_err);
1117 PRINT_STATS_LE32(ht, overrun_err);
1118 PRINT_STATS_LE32(ht, early_overrun_err);
1119 PRINT_STATS_LE32(ht, crc32_good);
1120 PRINT_STATS_LE32(ht, crc32_err);
1121 PRINT_STATS_LE32(ht, mh_format_err);
1122 PRINT_STATS_LE32(ht, agg_crc32_good);
1123 PRINT_STATS_LE32(ht, agg_mpdu_cnt);
1124 PRINT_STATS_LE32(ht, agg_cnt);
1125 PRINT_STATS_LE32(ht, unsupport_mcs);
1127 struct mvm_statistics_rx_ht_phy *ht =
1128 &mvm->rx_stats.ofdm_ht;
1130 PRINT_STATS_LE32(ht, mh_format_err);
1131 PRINT_STATS_LE32(ht, agg_mpdu_cnt);
1132 PRINT_STATS_LE32(ht, agg_cnt);
1133 PRINT_STATS_LE32(ht, unsupport_mcs);
1136 mutex_unlock(&mvm->mutex);
1138 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1143 #undef PRINT_STAT_LE32
1145 static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm,
1146 char __user *user_buf, size_t count,
1148 struct iwl_mvm_frame_stats *stats)
1150 char *buff, *pos, *endpos;
1153 static const size_t bufsz = 1024;
1155 buff = kmalloc(bufsz, GFP_KERNEL);
1159 spin_lock_bh(&mvm->drv_stats_lock);
1162 endpos = pos + bufsz;
1164 pos += scnprintf(pos, endpos - pos,
1165 "Legacy/HT/VHT\t:\t%d/%d/%d\n",
1166 stats->legacy_frames,
1169 pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n",
1170 stats->bw_20_frames,
1171 stats->bw_40_frames,
1172 stats->bw_80_frames);
1173 pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n",
1176 pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n",
1178 stats->mimo2_frames);
1179 pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n",
1181 stats->success_frames);
1182 pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n",
1184 pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n",
1185 stats->ampdu_count);
1186 pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n",
1187 stats->ampdu_count > 0 ?
1188 (stats->agg_frames / stats->ampdu_count) : 0);
1190 pos += scnprintf(pos, endpos - pos, "Last Rates\n");
1192 idx = stats->last_frame_idx - 1;
1193 for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) {
1194 idx = (idx + 1) % ARRAY_SIZE(stats->last_rates);
1195 if (stats->last_rates[idx] == 0)
1197 pos += scnprintf(pos, endpos - pos, "Rate[%d]: ",
1198 (int)(ARRAY_SIZE(stats->last_rates) - i));
1199 pos += rs_pretty_print_rate_v1(pos, endpos - pos,
1200 stats->last_rates[idx]);
1201 if (pos < endpos - 1)
1204 spin_unlock_bh(&mvm->drv_stats_lock);
1206 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
1212 static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file,
1213 char __user *user_buf, size_t count,
1216 struct iwl_mvm *mvm = file->private_data;
1218 return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos,
1219 &mvm->drv_rx_stats);
1222 static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
1223 size_t count, loff_t *ppos)
1225 int __maybe_unused ret;
1227 if (!iwl_mvm_firmware_running(mvm))
1230 mutex_lock(&mvm->mutex);
1232 /* allow one more restart that we're provoking here */
1233 if (mvm->fw_restart >= 0)
1236 if (count == 6 && !strcmp(buf, "nolog\n")) {
1237 set_bit(IWL_MVM_STATUS_SUPPRESS_ERROR_LOG_ONCE, &mvm->status);
1238 set_bit(STATUS_SUPPRESS_CMD_ERROR_ONCE, &mvm->trans->status);
1241 /* take the return value to make compiler happy - it will fail anyway */
1242 ret = iwl_mvm_send_cmd_pdu(mvm,
1243 WIDE_ID(LONG_GROUP, REPLY_ERROR),
1246 mutex_unlock(&mvm->mutex);
1251 static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
1252 size_t count, loff_t *ppos)
1254 if (!iwl_mvm_firmware_running(mvm))
1257 if (count == 6 && !strcmp(buf, "nolog\n"))
1258 set_bit(IWL_MVM_STATUS_SUPPRESS_ERROR_LOG_ONCE, &mvm->status);
1260 iwl_force_nmi(mvm->trans);
1266 iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
1267 char __user *user_buf,
1268 size_t count, loff_t *ppos)
1270 struct iwl_mvm *mvm = file->private_data;
1273 const size_t bufsz = sizeof(buf);
1275 /* print which antennas were set for the scan command by the user */
1276 pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
1277 if (mvm->scan_rx_ant & ANT_A)
1278 pos += scnprintf(buf + pos, bufsz - pos, "A");
1279 if (mvm->scan_rx_ant & ANT_B)
1280 pos += scnprintf(buf + pos, bufsz - pos, "B");
1281 pos += scnprintf(buf + pos, bufsz - pos, " (%x)\n", mvm->scan_rx_ant);
1283 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1287 iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
1288 size_t count, loff_t *ppos)
1292 if (!iwl_mvm_firmware_running(mvm))
1295 if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
1297 if (scan_rx_ant > ANT_ABC)
1299 if (scan_rx_ant & ~(iwl_mvm_get_valid_rx_ant(mvm)))
1302 if (mvm->scan_rx_ant != scan_rx_ant) {
1303 mvm->scan_rx_ant = scan_rx_ant;
1304 if (fw_has_capa(&mvm->fw->ucode_capa,
1305 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
1306 iwl_mvm_config_scan(mvm);
1312 static ssize_t iwl_dbgfs_indirection_tbl_write(struct iwl_mvm *mvm,
1313 char *buf, size_t count,
1316 struct iwl_rss_config_cmd cmd = {
1317 .flags = cpu_to_le32(IWL_RSS_ENABLE),
1318 .hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP |
1319 IWL_RSS_HASH_TYPE_IPV4_UDP |
1320 IWL_RSS_HASH_TYPE_IPV4_PAYLOAD |
1321 IWL_RSS_HASH_TYPE_IPV6_TCP |
1322 IWL_RSS_HASH_TYPE_IPV6_UDP |
1323 IWL_RSS_HASH_TYPE_IPV6_PAYLOAD,
1325 int ret, i, num_repeats, nbytes = count / 2;
1327 ret = hex2bin(cmd.indirection_table, buf, nbytes);
1332 * The input is the redirection table, partial or full.
1333 * Repeat the pattern if needed.
1334 * For example, input of 01020F will be repeated 42 times,
1335 * indirecting RSS hash results to queues 1, 2, 15 (skipping
1338 num_repeats = ARRAY_SIZE(cmd.indirection_table) / nbytes;
1339 for (i = 1; i < num_repeats; i++)
1340 memcpy(&cmd.indirection_table[i * nbytes],
1341 cmd.indirection_table, nbytes);
1342 /* handle cut in the middle pattern for the last places */
1343 memcpy(&cmd.indirection_table[i * nbytes], cmd.indirection_table,
1344 ARRAY_SIZE(cmd.indirection_table) % nbytes);
1346 netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key));
1348 mutex_lock(&mvm->mutex);
1349 if (iwl_mvm_firmware_running(mvm))
1350 ret = iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0,
1354 mutex_unlock(&mvm->mutex);
1356 return ret ?: count;
1359 static ssize_t iwl_dbgfs_inject_packet_write(struct iwl_mvm *mvm,
1360 char *buf, size_t count,
1363 struct iwl_op_mode *opmode = container_of((void *)mvm,
1366 struct iwl_rx_cmd_buffer rxb = {
1367 ._rx_page_order = 0,
1368 .truesize = 0, /* not used */
1371 struct iwl_rx_packet *pkt;
1372 int bin_len = count / 2;
1375 if (!iwl_mvm_firmware_running(mvm))
1378 /* supporting only MQ RX */
1379 if (!mvm->trans->trans_cfg->mq_rx_supported)
1382 rxb._page = alloc_pages(GFP_ATOMIC, 0);
1385 pkt = rxb_addr(&rxb);
1387 ret = hex2bin(page_address(rxb._page), buf, bin_len);
1391 /* avoid invalid memory access and malformed packet */
1392 if (bin_len < sizeof(*pkt) ||
1393 bin_len != sizeof(*pkt) + iwl_rx_packet_payload_len(pkt))
1397 iwl_mvm_rx_mq(opmode, NULL, &rxb);
1404 return ret ?: count;
1407 static int _iwl_dbgfs_inject_beacon_ie(struct iwl_mvm *mvm, char *bin, int len)
1409 struct ieee80211_vif *vif;
1410 struct iwl_mvm_vif *mvmvif;
1411 struct sk_buff *beacon;
1412 struct ieee80211_tx_info *info;
1413 struct iwl_mac_beacon_cmd beacon_cmd = {};
1414 unsigned int link_id;
1420 /* Element len should be represented by u8 */
1424 if (!iwl_mvm_firmware_running(mvm))
1427 if (!iwl_mvm_has_new_tx_api(mvm) &&
1428 !fw_has_api(&mvm->fw->ucode_capa,
1429 IWL_UCODE_TLV_API_NEW_BEACON_TEMPLATE))
1432 mutex_lock(&mvm->mutex);
1434 for (i = 0; i < NUM_MAC_INDEX_DRIVER; i++) {
1435 vif = iwl_mvm_rcu_dereference_vif_id(mvm, i, false);
1439 if (vif->type == NL80211_IFTYPE_AP)
1443 if (i == NUM_MAC_INDEX_DRIVER || !vif)
1446 mvm->hw->extra_beacon_tailroom = len;
1448 beacon = ieee80211_beacon_get_template(mvm->hw, vif, NULL, 0);
1452 if (len && hex2bin(skb_put_zero(beacon, len), bin, len)) {
1453 dev_kfree_skb(beacon);
1457 mvm->beacon_inject_active = true;
1459 mvmvif = iwl_mvm_vif_from_mac80211(vif);
1460 info = IEEE80211_SKB_CB(beacon);
1461 rate = iwl_mvm_mac_ctxt_get_beacon_rate(mvm, info, vif);
1463 for_each_mvm_vif_valid_link(mvmvif, link_id) {
1465 cpu_to_le16(iwl_mvm_mac_ctxt_get_beacon_flags(mvm->fw,
1467 beacon_cmd.byte_cnt = cpu_to_le16((u16)beacon->len);
1468 if (iwl_fw_lookup_cmd_ver(mvm->fw, BEACON_TEMPLATE_CMD, 0) > 12)
1469 beacon_cmd.link_id =
1470 cpu_to_le32(mvmvif->link[link_id]->fw_link_id);
1472 beacon_cmd.link_id = cpu_to_le32((u32)mvmvif->id);
1474 iwl_mvm_mac_ctxt_set_tim(mvm, &beacon_cmd.tim_idx,
1475 &beacon_cmd.tim_size,
1476 beacon->data, beacon->len);
1478 iwl_mvm_mac_ctxt_send_beacon_cmd(mvm, beacon, &beacon_cmd,
1479 sizeof(beacon_cmd));
1481 mutex_unlock(&mvm->mutex);
1483 dev_kfree_skb(beacon);
1488 mutex_unlock(&mvm->mutex);
1492 static ssize_t iwl_dbgfs_inject_beacon_ie_write(struct iwl_mvm *mvm,
1493 char *buf, size_t count,
1496 int ret = _iwl_dbgfs_inject_beacon_ie(mvm, buf, count);
1498 mvm->hw->extra_beacon_tailroom = 0;
1499 return ret ?: count;
1502 static ssize_t iwl_dbgfs_inject_beacon_ie_restore_write(struct iwl_mvm *mvm,
1507 int ret = _iwl_dbgfs_inject_beacon_ie(mvm, NULL, 0);
1509 mvm->hw->extra_beacon_tailroom = 0;
1510 mvm->beacon_inject_active = false;
1511 return ret ?: count;
1514 static ssize_t iwl_dbgfs_fw_dbg_conf_read(struct file *file,
1515 char __user *user_buf,
1516 size_t count, loff_t *ppos)
1518 struct iwl_mvm *mvm = file->private_data;
1521 const size_t bufsz = sizeof(buf);
1524 mutex_lock(&mvm->mutex);
1525 conf = mvm->fwrt.dump.conf;
1526 mutex_unlock(&mvm->mutex);
1528 pos += scnprintf(buf + pos, bufsz - pos, "%d\n", conf);
1530 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1533 static ssize_t iwl_dbgfs_fw_dbg_conf_write(struct iwl_mvm *mvm,
1534 char *buf, size_t count,
1537 unsigned int conf_id;
1540 if (!iwl_mvm_firmware_running(mvm))
1543 ret = kstrtouint(buf, 0, &conf_id);
1547 if (WARN_ON(conf_id >= FW_DBG_CONF_MAX))
1550 mutex_lock(&mvm->mutex);
1551 ret = iwl_fw_start_dbg_conf(&mvm->fwrt, conf_id);
1552 mutex_unlock(&mvm->mutex);
1554 return ret ?: count;
1557 static ssize_t iwl_dbgfs_fw_dbg_collect_write(struct iwl_mvm *mvm,
1558 char *buf, size_t count,
1564 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_USER_TRIGGER,
1567 iwl_fw_dbg_collect(&mvm->fwrt, FW_DBG_TRIGGER_USER, buf,
1573 static ssize_t iwl_dbgfs_dbg_time_point_write(struct iwl_mvm *mvm,
1574 char *buf, size_t count,
1579 if (kstrtou32(buf, 0, &timepoint))
1582 if (timepoint == IWL_FW_INI_TIME_POINT_INVALID ||
1583 timepoint >= IWL_FW_INI_TIME_POINT_NUM)
1586 iwl_dbg_tlv_time_point(&mvm->fwrt, timepoint, NULL);
1591 #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
1592 _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1593 #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
1594 _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1595 #define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \
1596 debugfs_create_file(alias, mode, parent, mvm, \
1597 &iwl_dbgfs_##name##_ops); \
1599 #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
1600 MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
1603 _iwl_dbgfs_link_sta_wrap_write(ssize_t (*real)(struct ieee80211_link_sta *,
1604 struct iwl_mvm_sta *,
1606 struct iwl_mvm_link_sta *,
1610 char *buf, size_t buf_size, loff_t *ppos)
1612 struct ieee80211_link_sta *link_sta = file->private_data;
1613 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(link_sta->sta);
1614 struct iwl_mvm *mvm = iwl_mvm_vif_from_mac80211(mvmsta->vif)->mvm;
1615 struct iwl_mvm_link_sta *mvm_link_sta;
1618 mutex_lock(&mvm->mutex);
1620 mvm_link_sta = rcu_dereference_protected(mvmsta->link[link_sta->link_id],
1621 lockdep_is_held(&mvm->mutex));
1622 if (WARN_ON(!mvm_link_sta)) {
1623 mutex_unlock(&mvm->mutex);
1627 ret = real(link_sta, mvmsta, mvm, mvm_link_sta, buf, buf_size, ppos);
1629 mutex_unlock(&mvm->mutex);
1635 _iwl_dbgfs_link_sta_wrap_read(ssize_t (*real)(struct ieee80211_link_sta *,
1636 struct iwl_mvm_sta *,
1638 struct iwl_mvm_link_sta *,
1642 char __user *user_buf, size_t count, loff_t *ppos)
1644 struct ieee80211_link_sta *link_sta = file->private_data;
1645 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(link_sta->sta);
1646 struct iwl_mvm *mvm = iwl_mvm_vif_from_mac80211(mvmsta->vif)->mvm;
1647 struct iwl_mvm_link_sta *mvm_link_sta;
1650 mutex_lock(&mvm->mutex);
1652 mvm_link_sta = rcu_dereference_protected(mvmsta->link[link_sta->link_id],
1653 lockdep_is_held(&mvm->mutex));
1654 if (WARN_ON(!mvm_link_sta)) {
1655 mutex_unlock(&mvm->mutex);
1659 ret = real(link_sta, mvmsta, mvm, mvm_link_sta, user_buf, count, ppos);
1661 mutex_unlock(&mvm->mutex);
1666 #define MVM_DEBUGFS_LINK_STA_WRITE_WRAPPER(name, buflen) \
1667 static ssize_t _iwl_dbgfs_link_sta_##name##_write(struct file *file, \
1668 const char __user *user_buf, \
1669 size_t count, loff_t *ppos) \
1671 char buf[buflen] = {}; \
1672 size_t buf_size = min(count, sizeof(buf) - 1); \
1674 if (copy_from_user(buf, user_buf, sizeof(buf))) \
1677 return _iwl_dbgfs_link_sta_wrap_write(iwl_dbgfs_##name##_write, \
1679 buf, buf_size, ppos); \
1682 #define MVM_DEBUGFS_LINK_STA_READ_WRAPPER(name) \
1683 static ssize_t _iwl_dbgfs_link_sta_##name##_read(struct file *file, \
1684 char __user *user_buf, \
1685 size_t count, loff_t *ppos) \
1687 return _iwl_dbgfs_link_sta_wrap_read(iwl_dbgfs_##name##_read, \
1689 user_buf, count, ppos); \
1692 #define MVM_DEBUGFS_WRITE_LINK_STA_FILE_OPS(name, bufsz) \
1693 MVM_DEBUGFS_LINK_STA_WRITE_WRAPPER(name, bufsz) \
1694 static const struct file_operations iwl_dbgfs_link_sta_##name##_ops = { \
1695 .write = _iwl_dbgfs_link_sta_##name##_write, \
1696 .open = simple_open, \
1697 .llseek = generic_file_llseek, \
1700 #define MVM_DEBUGFS_READ_LINK_STA_FILE_OPS(name) \
1701 MVM_DEBUGFS_LINK_STA_READ_WRAPPER(name) \
1702 static const struct file_operations iwl_dbgfs_link_sta_##name##_ops = { \
1703 .read = _iwl_dbgfs_link_sta_##name##_read, \
1704 .open = simple_open, \
1705 .llseek = generic_file_llseek, \
1708 #define MVM_DEBUGFS_READ_WRITE_LINK_STA_FILE_OPS(name, bufsz) \
1709 MVM_DEBUGFS_LINK_STA_READ_WRAPPER(name) \
1710 MVM_DEBUGFS_LINK_STA_WRITE_WRAPPER(name, bufsz) \
1711 static const struct file_operations iwl_dbgfs_link_sta_##name##_ops = { \
1712 .read = _iwl_dbgfs_link_sta_##name##_read, \
1713 .write = _iwl_dbgfs_link_sta_##name##_write, \
1714 .open = simple_open, \
1715 .llseek = generic_file_llseek, \
1718 #define MVM_DEBUGFS_ADD_LINK_STA_FILE_ALIAS(alias, name, parent, mode) \
1719 debugfs_create_file(alias, mode, parent, link_sta, \
1720 &iwl_dbgfs_link_sta_##name##_ops)
1721 #define MVM_DEBUGFS_ADD_LINK_STA_FILE(name, parent, mode) \
1722 MVM_DEBUGFS_ADD_LINK_STA_FILE_ALIAS(#name, name, parent, mode)
1725 iwl_dbgfs_prph_reg_read(struct file *file,
1726 char __user *user_buf,
1727 size_t count, loff_t *ppos)
1729 struct iwl_mvm *mvm = file->private_data;
1732 const size_t bufsz = sizeof(buf);
1734 if (!mvm->dbgfs_prph_reg_addr)
1737 pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n",
1738 mvm->dbgfs_prph_reg_addr,
1739 iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr));
1741 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1745 iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf,
1746 size_t count, loff_t *ppos)
1751 args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value);
1752 /* if we only want to set the reg address - nothing more to do */
1756 /* otherwise, make sure we have both address and value */
1760 iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value);
1767 iwl_dbgfs_send_echo_cmd_write(struct iwl_mvm *mvm, char *buf,
1768 size_t count, loff_t *ppos)
1772 if (!iwl_mvm_firmware_running(mvm))
1775 mutex_lock(&mvm->mutex);
1776 ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL);
1777 mutex_unlock(&mvm->mutex);
1779 return ret ?: count;
1782 struct iwl_mvm_sniffer_apply {
1783 struct iwl_mvm *mvm;
1788 static bool iwl_mvm_sniffer_apply(struct iwl_notif_wait_data *notif_data,
1789 struct iwl_rx_packet *pkt, void *data)
1791 struct iwl_mvm_sniffer_apply *apply = data;
1793 apply->mvm->cur_aid = cpu_to_le16(apply->aid);
1794 memcpy(apply->mvm->cur_bssid, apply->bssid,
1795 sizeof(apply->mvm->cur_bssid));
1801 iwl_dbgfs_he_sniffer_params_write(struct iwl_mvm *mvm, char *buf,
1802 size_t count, loff_t *ppos)
1804 struct iwl_notification_wait wait;
1805 struct iwl_he_monitor_cmd he_mon_cmd = {};
1806 struct iwl_mvm_sniffer_apply apply = {
1810 WIDE_ID(DATA_PATH_GROUP, HE_AIR_SNIFFER_CONFIG_CMD),
1815 if (!iwl_mvm_firmware_running(mvm))
1818 ret = sscanf(buf, "%x %2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx", &aid,
1819 &he_mon_cmd.bssid[0], &he_mon_cmd.bssid[1],
1820 &he_mon_cmd.bssid[2], &he_mon_cmd.bssid[3],
1821 &he_mon_cmd.bssid[4], &he_mon_cmd.bssid[5]);
1825 he_mon_cmd.aid = cpu_to_le16(aid);
1828 apply.bssid = (void *)he_mon_cmd.bssid;
1830 mutex_lock(&mvm->mutex);
1833 * Use the notification waiter to get our function triggered
1834 * in sequence with other RX. This ensures that frames we get
1835 * on the RX queue _before_ the new configuration is applied
1836 * still have mvm->cur_aid pointing to the old AID, and that
1837 * frames on the RX queue _after_ the firmware processed the
1838 * new configuration (and sent the response, synchronously)
1839 * get mvm->cur_aid correctly set to the new AID.
1841 iwl_init_notification_wait(&mvm->notif_wait, &wait,
1842 wait_cmds, ARRAY_SIZE(wait_cmds),
1843 iwl_mvm_sniffer_apply, &apply);
1845 ret = iwl_mvm_send_cmd_pdu(mvm,
1846 WIDE_ID(DATA_PATH_GROUP, HE_AIR_SNIFFER_CONFIG_CMD),
1848 sizeof(he_mon_cmd), &he_mon_cmd);
1850 /* no need to really wait, we already did anyway */
1851 iwl_remove_notification(&mvm->notif_wait, &wait);
1853 mutex_unlock(&mvm->mutex);
1855 return ret ?: count;
1859 iwl_dbgfs_he_sniffer_params_read(struct file *file, char __user *user_buf,
1860 size_t count, loff_t *ppos)
1862 struct iwl_mvm *mvm = file->private_data;
1866 len = scnprintf(buf, sizeof(buf),
1867 "%d %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n",
1868 le16_to_cpu(mvm->cur_aid), mvm->cur_bssid[0],
1869 mvm->cur_bssid[1], mvm->cur_bssid[2], mvm->cur_bssid[3],
1870 mvm->cur_bssid[4], mvm->cur_bssid[5]);
1872 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1876 iwl_dbgfs_uapsd_noagg_bssids_read(struct file *file, char __user *user_buf,
1877 size_t count, loff_t *ppos)
1879 struct iwl_mvm *mvm = file->private_data;
1880 u8 buf[IWL_MVM_UAPSD_NOAGG_BSSIDS_NUM * ETH_ALEN * 3 + 1];
1881 unsigned int pos = 0;
1882 size_t bufsz = sizeof(buf);
1885 mutex_lock(&mvm->mutex);
1887 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++)
1888 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
1889 mvm->uapsd_noagg_bssids[i].addr);
1891 mutex_unlock(&mvm->mutex);
1893 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1897 iwl_dbgfs_ltr_config_write(struct iwl_mvm *mvm,
1898 char *buf, size_t count, loff_t *ppos)
1901 struct iwl_ltr_config_cmd ltr_config = {0};
1903 if (!iwl_mvm_firmware_running(mvm))
1906 if (sscanf(buf, "%x,%x,%x,%x,%x,%x,%x",
1908 <r_config.static_long,
1909 <r_config.static_short,
1910 <r_config.ltr_cfg_values[0],
1911 <r_config.ltr_cfg_values[1],
1912 <r_config.ltr_cfg_values[2],
1913 <r_config.ltr_cfg_values[3]) != 7) {
1917 mutex_lock(&mvm->mutex);
1918 ret = iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0, sizeof(ltr_config),
1920 mutex_unlock(&mvm->mutex);
1923 IWL_ERR(mvm, "failed to send ltr configuration cmd\n");
1925 return ret ?: count;
1928 static ssize_t iwl_dbgfs_rfi_freq_table_write(struct iwl_mvm *mvm, char *buf,
1929 size_t count, loff_t *ppos)
1934 if (kstrtou16(buf, 10, &op_id))
1937 /* value zero triggers re-sending the default table to the device */
1939 mutex_lock(&mvm->mutex);
1940 ret = iwl_rfi_send_config_cmd(mvm, NULL);
1941 mutex_unlock(&mvm->mutex);
1943 ret = -EOPNOTSUPP; /* in the future a new table will be added */
1946 return ret ?: count;
1949 /* The size computation is as follows:
1950 * each number needs at most 3 characters, number of rows is the size of
1951 * the table; So, need 5 chars for the "freq: " part and each tuple afterwards
1952 * needs 6 characters for numbers and 5 for the punctuation around.
1954 #define IWL_RFI_BUF_SIZE (IWL_RFI_LUT_INSTALLED_SIZE *\
1955 (5 + IWL_RFI_LUT_ENTRY_CHANNELS_NUM * (6 + 5)))
1957 static ssize_t iwl_dbgfs_rfi_freq_table_read(struct file *file,
1958 char __user *user_buf,
1959 size_t count, loff_t *ppos)
1961 struct iwl_mvm *mvm = file->private_data;
1962 struct iwl_rfi_freq_table_resp_cmd *resp;
1964 char buf[IWL_RFI_BUF_SIZE];
1967 resp = iwl_rfi_get_freq_table(mvm);
1969 return PTR_ERR(resp);
1971 status = le32_to_cpu(resp->status);
1972 if (status != RFI_FREQ_TABLE_OK) {
1973 scnprintf(buf, IWL_RFI_BUF_SIZE, "status = %d\n", status);
1977 for (i = 0; i < ARRAY_SIZE(resp->table); i++) {
1978 pos += scnprintf(buf + pos, IWL_RFI_BUF_SIZE - pos, "%d: ",
1979 resp->table[i].freq);
1981 for (j = 0; j < ARRAY_SIZE(resp->table[i].channels); j++)
1982 pos += scnprintf(buf + pos, IWL_RFI_BUF_SIZE - pos,
1984 resp->table[i].channels[j],
1985 resp->table[i].bands[j]);
1986 pos += scnprintf(buf + pos, IWL_RFI_BUF_SIZE - pos, "\n");
1991 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1994 MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);
1996 /* Device wide debugfs entries */
1997 MVM_DEBUGFS_READ_FILE_OPS(ctdp_budget);
1998 MVM_DEBUGFS_WRITE_FILE_OPS(stop_ctdp, 8);
1999 MVM_DEBUGFS_WRITE_FILE_OPS(force_ctkill, 8);
2000 MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
2001 MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
2002 MVM_DEBUGFS_WRITE_FILE_OPS(send_echo_cmd, 8);
2003 MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64);
2004 MVM_DEBUGFS_READ_WRITE_FILE_OPS(set_nic_temperature, 64);
2005 MVM_DEBUGFS_READ_FILE_OPS(nic_temp);
2006 MVM_DEBUGFS_READ_FILE_OPS(stations);
2007 MVM_DEBUGFS_READ_LINK_STA_FILE_OPS(rs_data);
2008 MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
2009 MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
2010 MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64);
2011 MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
2012 MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats);
2013 MVM_DEBUGFS_READ_FILE_OPS(fw_ver);
2014 MVM_DEBUGFS_READ_FILE_OPS(phy_integration_ver);
2015 MVM_DEBUGFS_READ_FILE_OPS(tas_get_status);
2016 MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10);
2017 MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10);
2018 MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10);
2019 MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant, 10);
2020 MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
2021 MVM_DEBUGFS_READ_WRITE_FILE_OPS(fw_dbg_conf, 8);
2022 MVM_DEBUGFS_WRITE_FILE_OPS(fw_dbg_collect, 64);
2023 MVM_DEBUGFS_WRITE_FILE_OPS(dbg_time_point, 64);
2024 MVM_DEBUGFS_WRITE_FILE_OPS(indirection_tbl,
2025 (IWL_RSS_INDIRECTION_TABLE_SIZE * 2));
2026 MVM_DEBUGFS_WRITE_FILE_OPS(inject_packet, 512);
2027 MVM_DEBUGFS_WRITE_FILE_OPS(inject_beacon_ie, 512);
2028 MVM_DEBUGFS_WRITE_FILE_OPS(inject_beacon_ie_restore, 512);
2030 MVM_DEBUGFS_READ_FILE_OPS(uapsd_noagg_bssids);
2033 MVM_DEBUGFS_READ_FILE_OPS(sar_geo_profile);
2034 MVM_DEBUGFS_READ_FILE_OPS(wifi_6e_enable);
2037 MVM_DEBUGFS_READ_WRITE_LINK_STA_FILE_OPS(amsdu_len, 16);
2039 MVM_DEBUGFS_READ_WRITE_FILE_OPS(he_sniffer_params, 32);
2041 MVM_DEBUGFS_WRITE_FILE_OPS(ltr_config, 512);
2042 MVM_DEBUGFS_READ_WRITE_FILE_OPS(rfi_freq_table, 16);
2044 static ssize_t iwl_dbgfs_mem_read(struct file *file, char __user *user_buf,
2045 size_t count, loff_t *ppos)
2047 struct iwl_mvm *mvm = file->private_data;
2048 struct iwl_dbg_mem_access_cmd cmd = {};
2049 struct iwl_dbg_mem_access_rsp *rsp;
2050 struct iwl_host_cmd hcmd = {
2051 .flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
2053 .len = { sizeof(cmd) },
2058 if (!iwl_mvm_firmware_running(mvm))
2061 hcmd.id = WIDE_ID(DEBUG_GROUP, *ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR);
2062 cmd.op = cpu_to_le32(DEBUG_MEM_OP_READ);
2064 /* Take care of alignment of both the position and the length */
2065 delta = *ppos & 0x3;
2066 cmd.addr = cpu_to_le32(*ppos - delta);
2067 cmd.len = cpu_to_le32(min(ALIGN(count + delta, 4) / 4,
2068 (size_t)DEBUG_MEM_MAX_SIZE_DWORDS));
2070 mutex_lock(&mvm->mutex);
2071 ret = iwl_mvm_send_cmd(mvm, &hcmd);
2072 mutex_unlock(&mvm->mutex);
2077 if (iwl_rx_packet_payload_len(hcmd.resp_pkt) < sizeof(*rsp)) {
2082 rsp = (void *)hcmd.resp_pkt->data;
2083 if (le32_to_cpu(rsp->status) != DEBUG_MEM_STATUS_SUCCESS) {
2088 len = min((size_t)le32_to_cpu(rsp->len) << 2,
2089 iwl_rx_packet_payload_len(hcmd.resp_pkt) - sizeof(*rsp));
2090 len = min(len - delta, count);
2096 ret = len - copy_to_user(user_buf, (u8 *)rsp->data + delta, len);
2100 iwl_free_resp(&hcmd);
2104 static ssize_t iwl_dbgfs_mem_write(struct file *file,
2105 const char __user *user_buf, size_t count,
2108 struct iwl_mvm *mvm = file->private_data;
2109 struct iwl_dbg_mem_access_cmd *cmd;
2110 struct iwl_dbg_mem_access_rsp *rsp;
2111 struct iwl_host_cmd hcmd = {};
2117 if (!iwl_mvm_firmware_running(mvm))
2120 hcmd.id = WIDE_ID(DEBUG_GROUP, *ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR);
2122 if (*ppos & 0x3 || count < 4) {
2123 op = DEBUG_MEM_OP_WRITE_BYTES;
2124 len = min(count, (size_t)(4 - (*ppos & 0x3)));
2127 op = DEBUG_MEM_OP_WRITE;
2128 len = min(count >> 2, (size_t)DEBUG_MEM_MAX_SIZE_DWORDS);
2129 data_size = len << 2;
2132 cmd_size = sizeof(*cmd) + ALIGN(data_size, 4);
2133 cmd = kzalloc(cmd_size, GFP_KERNEL);
2137 cmd->op = cpu_to_le32(op);
2138 cmd->len = cpu_to_le32(len);
2139 cmd->addr = cpu_to_le32(*ppos);
2140 if (copy_from_user((void *)cmd->data, user_buf, data_size)) {
2145 hcmd.flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
2146 hcmd.data[0] = (void *)cmd;
2147 hcmd.len[0] = cmd_size;
2149 mutex_lock(&mvm->mutex);
2150 ret = iwl_mvm_send_cmd(mvm, &hcmd);
2151 mutex_unlock(&mvm->mutex);
2158 if (iwl_rx_packet_payload_len(hcmd.resp_pkt) < sizeof(*rsp)) {
2163 rsp = (void *)hcmd.resp_pkt->data;
2164 if (rsp->status != DEBUG_MEM_STATUS_SUCCESS) {
2173 iwl_free_resp(&hcmd);
2177 static const struct file_operations iwl_dbgfs_mem_ops = {
2178 .read = iwl_dbgfs_mem_read,
2179 .write = iwl_dbgfs_mem_write,
2180 .open = simple_open,
2181 .llseek = default_llseek,
2184 void iwl_mvm_link_sta_add_debugfs(struct ieee80211_hw *hw,
2185 struct ieee80211_vif *vif,
2186 struct ieee80211_link_sta *link_sta,
2189 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2191 if (iwl_mvm_has_tlc_offload(mvm)) {
2192 MVM_DEBUGFS_ADD_LINK_STA_FILE(rs_data, dir, 0400);
2195 MVM_DEBUGFS_ADD_LINK_STA_FILE(amsdu_len, dir, 0600);
2198 void iwl_mvm_dbgfs_register(struct iwl_mvm *mvm)
2200 struct dentry *bcast_dir __maybe_unused;
2202 spin_lock_init(&mvm->drv_stats_lock);
2204 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, 0200);
2205 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, 0200);
2206 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, 0600);
2207 MVM_DEBUGFS_ADD_FILE(set_nic_temperature, mvm->debugfs_dir, 0600);
2208 MVM_DEBUGFS_ADD_FILE(nic_temp, mvm->debugfs_dir, 0400);
2209 MVM_DEBUGFS_ADD_FILE(ctdp_budget, mvm->debugfs_dir, 0400);
2210 MVM_DEBUGFS_ADD_FILE(stop_ctdp, mvm->debugfs_dir, 0200);
2211 MVM_DEBUGFS_ADD_FILE(force_ctkill, mvm->debugfs_dir, 0200);
2212 MVM_DEBUGFS_ADD_FILE(stations, mvm->debugfs_dir, 0400);
2213 MVM_DEBUGFS_ADD_FILE(bt_notif, mvm->debugfs_dir, 0400);
2214 MVM_DEBUGFS_ADD_FILE(bt_cmd, mvm->debugfs_dir, 0400);
2215 MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir, 0600);
2216 MVM_DEBUGFS_ADD_FILE(fw_ver, mvm->debugfs_dir, 0400);
2217 MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, 0400);
2218 MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, 0400);
2219 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, 0200);
2220 MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, 0200);
2221 MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, 0200);
2222 MVM_DEBUGFS_ADD_FILE(bt_force_ant, mvm->debugfs_dir, 0200);
2223 MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir, 0600);
2224 MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, 0600);
2225 MVM_DEBUGFS_ADD_FILE(fw_dbg_conf, mvm->debugfs_dir, 0600);
2226 MVM_DEBUGFS_ADD_FILE(fw_dbg_collect, mvm->debugfs_dir, 0200);
2227 MVM_DEBUGFS_ADD_FILE(dbg_time_point, mvm->debugfs_dir, 0200);
2228 MVM_DEBUGFS_ADD_FILE(send_echo_cmd, mvm->debugfs_dir, 0200);
2229 MVM_DEBUGFS_ADD_FILE(indirection_tbl, mvm->debugfs_dir, 0200);
2230 MVM_DEBUGFS_ADD_FILE(inject_packet, mvm->debugfs_dir, 0200);
2231 MVM_DEBUGFS_ADD_FILE(inject_beacon_ie, mvm->debugfs_dir, 0200);
2232 MVM_DEBUGFS_ADD_FILE(inject_beacon_ie_restore, mvm->debugfs_dir, 0200);
2233 MVM_DEBUGFS_ADD_FILE(rfi_freq_table, mvm->debugfs_dir, 0600);
2235 if (mvm->fw->phy_integration_ver)
2236 MVM_DEBUGFS_ADD_FILE(phy_integration_ver, mvm->debugfs_dir, 0400);
2237 MVM_DEBUGFS_ADD_FILE(tas_get_status, mvm->debugfs_dir, 0400);
2239 MVM_DEBUGFS_ADD_FILE(sar_geo_profile, mvm->debugfs_dir, 0400);
2240 MVM_DEBUGFS_ADD_FILE(wifi_6e_enable, mvm->debugfs_dir, 0400);
2242 MVM_DEBUGFS_ADD_FILE(he_sniffer_params, mvm->debugfs_dir, 0600);
2244 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_SET_LTR_GEN2))
2245 MVM_DEBUGFS_ADD_FILE(ltr_config, mvm->debugfs_dir, 0200);
2247 debugfs_create_bool("enable_scan_iteration_notif", 0600,
2248 mvm->debugfs_dir, &mvm->scan_iter_notif_enabled);
2249 debugfs_create_bool("drop_bcn_ap_mode", 0600, mvm->debugfs_dir,
2250 &mvm->drop_bcn_ap_mode);
2252 MVM_DEBUGFS_ADD_FILE(uapsd_noagg_bssids, mvm->debugfs_dir, S_IRUSR);
2254 #ifdef CONFIG_PM_SLEEP
2255 MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, 0400);
2256 debugfs_create_bool("d3_wake_sysassert", 0600, mvm->debugfs_dir,
2257 &mvm->d3_wake_sysassert);
2258 debugfs_create_u32("last_netdetect_scans", 0400, mvm->debugfs_dir,
2259 &mvm->last_netdetect_scans);
2262 debugfs_create_u8("ps_disabled", 0400, mvm->debugfs_dir,
2264 debugfs_create_blob("nvm_hw", 0400, mvm->debugfs_dir,
2266 debugfs_create_blob("nvm_sw", 0400, mvm->debugfs_dir,
2268 debugfs_create_blob("nvm_calib", 0400, mvm->debugfs_dir,
2269 &mvm->nvm_calib_blob);
2270 debugfs_create_blob("nvm_prod", 0400, mvm->debugfs_dir,
2271 &mvm->nvm_prod_blob);
2272 debugfs_create_blob("nvm_phy_sku", 0400, mvm->debugfs_dir,
2273 &mvm->nvm_phy_sku_blob);
2274 debugfs_create_blob("nvm_reg", S_IRUSR,
2275 mvm->debugfs_dir, &mvm->nvm_reg_blob);
2277 debugfs_create_file("mem", 0600, mvm->debugfs_dir, mvm,
2278 &iwl_dbgfs_mem_ops);
2281 * Create a symlink with mac80211. It will be removed when mac80211
2282 * exists (before the opmode exists which removes the target.)
2284 if (!IS_ERR(mvm->debugfs_dir)) {
2287 snprintf(buf, 100, "../../%pd2", mvm->debugfs_dir->d_parent);
2288 debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir,