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"
19 #include "fw/error-dump.h"
20 #include "fw/api/phy-ctxt.h"
22 static ssize_t iwl_dbgfs_ctdp_budget_read(struct file *file,
23 char __user *user_buf,
24 size_t count, loff_t *ppos)
26 struct iwl_mvm *mvm = file->private_data;
30 if (!iwl_mvm_is_ctdp_supported(mvm))
33 if (!iwl_mvm_firmware_running(mvm) ||
34 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
37 mutex_lock(&mvm->mutex);
38 budget = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_REPORT, 0);
39 mutex_unlock(&mvm->mutex);
44 pos = scnprintf(buf, sizeof(buf), "%d\n", budget);
46 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
49 static ssize_t iwl_dbgfs_stop_ctdp_write(struct iwl_mvm *mvm, char *buf,
50 size_t count, loff_t *ppos)
54 if (!iwl_mvm_is_ctdp_supported(mvm))
57 if (!iwl_mvm_firmware_running(mvm) ||
58 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
61 mutex_lock(&mvm->mutex);
62 ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_STOP, 0);
63 mutex_unlock(&mvm->mutex);
68 static ssize_t iwl_dbgfs_force_ctkill_write(struct iwl_mvm *mvm, char *buf,
69 size_t count, loff_t *ppos)
71 if (!iwl_mvm_firmware_running(mvm) ||
72 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
75 iwl_mvm_enter_ctkill(mvm);
80 static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf,
81 size_t count, loff_t *ppos)
86 if (!iwl_mvm_firmware_running(mvm) ||
87 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
90 if (kstrtou32(buf, 0, &flush_arg))
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",
97 mutex_lock(&mvm->mutex);
98 ret = iwl_mvm_flush_sta_tids(mvm, flush_arg, 0xFFFF)
100 mutex_unlock(&mvm->mutex);
104 IWL_DEBUG_TX_QUEUES(mvm, "FLUSHING queues mask to flush = 0x%x\n",
107 mutex_lock(&mvm->mutex);
108 ret = iwl_mvm_flush_tx_path(mvm, flush_arg) ? : count;
109 mutex_unlock(&mvm->mutex);
114 static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf,
115 size_t count, loff_t *ppos)
117 struct iwl_mvm_sta *mvmsta;
118 int sta_id, drain, ret;
120 if (!iwl_mvm_firmware_running(mvm) ||
121 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
124 if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
126 if (sta_id < 0 || sta_id >= mvm->fw->ucode_capa.num_stations)
128 if (drain < 0 || drain > 1)
131 mutex_lock(&mvm->mutex);
133 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
138 ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count;
140 mutex_unlock(&mvm->mutex);
145 static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
146 size_t count, loff_t *ppos)
148 struct iwl_mvm *mvm = file->private_data;
149 const struct fw_img *img;
150 unsigned int ofs, len;
154 if (!iwl_mvm_firmware_running(mvm))
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;
162 if (mvm->dbgfs_sram_len) {
163 ofs = mvm->dbgfs_sram_offset;
164 len = mvm->dbgfs_sram_len;
167 ptr = kzalloc(len, GFP_KERNEL);
171 iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
173 ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len);
180 static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf,
181 size_t count, loff_t *ppos)
183 const struct fw_img *img;
185 u32 img_offset, img_len;
187 if (!iwl_mvm_firmware_running(mvm))
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;
194 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
195 if ((offset & 0x3) || (len & 0x3))
198 if (offset + len > img_offset + img_len)
201 mvm->dbgfs_sram_offset = offset;
202 mvm->dbgfs_sram_len = len;
204 mvm->dbgfs_sram_offset = 0;
205 mvm->dbgfs_sram_len = 0;
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)
215 struct iwl_mvm *mvm = file->private_data;
219 if (!mvm->temperature_test)
220 pos = scnprintf(buf, sizeof(buf), "disabled\n");
222 pos = scnprintf(buf, sizeof(buf), "%d\n", mvm->temperature);
224 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
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
234 static ssize_t iwl_dbgfs_set_nic_temperature_write(struct iwl_mvm *mvm,
235 char *buf, size_t count,
240 if (!iwl_mvm_firmware_running(mvm) && !mvm->temperature_test)
243 if (kstrtoint(buf, 10, &temperature))
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)
251 mutex_lock(&mvm->mutex);
252 if (temperature == IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) {
253 if (!mvm->temperature_test)
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
261 mvm->temperature = 0;
263 mvm->temperature_test = true;
264 mvm->temperature = temperature;
266 IWL_DEBUG_TEMP(mvm, "%sabling debug set temperature (temp = %d)\n",
267 mvm->temperature_test ? "En" : "Dis",
269 /* handle the temperature change */
270 iwl_mvm_tt_handler(mvm);
273 mutex_unlock(&mvm->mutex);
278 static ssize_t iwl_dbgfs_nic_temp_read(struct file *file,
279 char __user *user_buf,
280 size_t count, loff_t *ppos)
282 struct iwl_mvm *mvm = file->private_data;
287 if (!iwl_mvm_firmware_running(mvm))
290 mutex_lock(&mvm->mutex);
291 ret = iwl_mvm_get_temp(mvm, &temp);
292 mutex_unlock(&mvm->mutex);
297 pos = scnprintf(buf, sizeof(buf), "%d\n", temp);
299 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
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)
307 struct iwl_mvm *mvm = file->private_data;
310 int bufsz = sizeof(buf);
313 if (!iwl_mvm_firmware_running(mvm))
316 mutex_lock(&mvm->mutex);
317 tbl_idx = iwl_mvm_get_sar_geo_profile(mvm);
319 mutex_unlock(&mvm->mutex);
324 pos = scnprintf(buf, bufsz,
325 "SAR geographic profile disabled\n");
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);
340 mutex_unlock(&mvm->mutex);
342 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
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)
349 struct iwl_mvm *mvm = file->private_data;
354 err = iwl_acpi_get_dsm_u32(mvm->fwrt.dev, 0,
360 pos = sprintf(buf, "0x%08x\n", value);
362 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
366 static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
367 size_t count, loff_t *ppos)
369 struct iwl_mvm *mvm = file->private_data;
370 struct ieee80211_sta *sta;
372 int i, pos = 0, bufsz = sizeof(buf);
374 mutex_lock(&mvm->mutex);
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));
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",
386 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
390 mutex_unlock(&mvm->mutex);
392 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
395 static ssize_t iwl_dbgfs_rs_data_read(struct ieee80211_link_sta *link_sta,
396 struct iwl_mvm_sta *mvmsta,
398 struct iwl_mvm_link_sta *mvm_link_sta,
399 char __user *user_buf,
400 size_t count, loff_t *ppos)
402 struct iwl_lq_sta_rs_fw *lq_sta = &mvm_link_sta->lq_sta.rs_fw;
403 static const size_t bufsz = 2048;
408 buff = kmalloc(bufsz, GFP_KERNEL);
412 desc += scnprintf(buff + desc, bufsz - desc, "sta_id %d\n",
413 lq_sta->pers.sta_id);
414 desc += scnprintf(buff + desc, bufsz - desc,
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);
428 desc += rs_pretty_print_rate(buff + desc, bufsz - desc,
429 lq_sta->last_rate_n_flags);
430 if (desc < bufsz - 1)
433 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
438 static ssize_t iwl_dbgfs_amsdu_len_write(struct ieee80211_link_sta *link_sta,
439 struct iwl_mvm_sta *mvmsta,
441 struct iwl_mvm_link_sta *mvm_link_sta,
442 char *buf, size_t count,
448 if (kstrtou16(buf, 0, &amsdu_len))
451 /* only change from debug set <-> debug unset */
452 if (amsdu_len && mvm_link_sta->orig_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;
462 link_sta->agg.max_amsdu_len = mvm_link_sta->orig_amsdu_len;
463 mvm_link_sta->orig_amsdu_len = 0;
466 ieee80211_sta_recalc_aggregates(link_sta->sta);
471 static ssize_t iwl_dbgfs_amsdu_len_read(struct ieee80211_link_sta *link_sta,
472 struct iwl_mvm_sta *mvmsta,
474 struct iwl_mvm_link_sta *mvm_link_sta,
475 char __user *user_buf,
476 size_t count, loff_t *ppos)
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);
486 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
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)
493 struct iwl_mvm *mvm = file->private_data;
495 int bufsz = sizeof(buf);
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);
503 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
506 static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf,
507 size_t count, loff_t *ppos)
511 if (!iwl_mvm_firmware_running(mvm))
514 if (!strncmp("disable_power_off_d0=", buf, 21)) {
515 if (sscanf(buf + 21, "%d", &val) != 1)
517 mvm->disable_power_off = val;
518 } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
519 if (sscanf(buf + 21, "%d", &val) != 1)
521 mvm->disable_power_off_d3 = val;
526 mutex_lock(&mvm->mutex);
527 ret = iwl_mvm_power_update_device(mvm);
528 mutex_unlock(&mvm->mutex);
534 int iwl_mvm_coex_dump_mbox(struct iwl_bt_coex_profile_notif *notif, char *buf,
537 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
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);
551 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
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);
560 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
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);
573 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
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);
593 static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
594 size_t count, loff_t *ppos)
596 struct iwl_mvm *mvm = file->private_data;
597 struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
599 int ret, pos = 0, bufsz = sizeof(char) * 1024;
601 buf = kmalloc(bufsz, GFP_KERNEL);
605 mutex_lock(&mvm->mutex);
607 pos += iwl_mvm_coex_dump_mbox(notif, buf, pos, bufsz);
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);
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);
628 mutex_unlock(&mvm->mutex);
630 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
637 static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
638 size_t count, loff_t *ppos)
640 struct iwl_mvm *mvm = file->private_data;
641 struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
643 int bufsz = sizeof(buf);
646 mutex_lock(&mvm->mutex);
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));
656 mutex_unlock(&mvm->mutex);
658 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
662 iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf,
663 size_t count, loff_t *ppos)
667 if (sscanf(buf, "%u", &bt_tx_prio) != 1)
672 mvm->bt_tx_prio = bt_tx_prio;
678 iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char *buf,
679 size_t count, loff_t *ppos)
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",
687 int ret, bt_force_ant_mode;
689 ret = match_string(modes_str, ARRAY_SIZE(modes_str), buf);
693 bt_force_ant_mode = ret;
695 mutex_lock(&mvm->mutex);
696 if (mvm->bt_force_ant_mode == bt_force_ant_mode)
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]);
703 if (iwl_mvm_firmware_running(mvm))
704 ret = iwl_mvm_send_bt_init_conf(mvm);
709 mutex_unlock(&mvm->mutex);
713 static ssize_t iwl_dbgfs_fw_ver_read(struct file *file, char __user *user_buf,
714 size_t count, loff_t *ppos)
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];
722 buff = kmalloc(bufsz, GFP_KERNEL);
727 endpos = pos + bufsz;
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);
738 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
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)
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] =
756 [TAS_DISABLED_DUE_TO_SAR_6DBM] =
757 "Due To SAR Limit Less Than 6 dBm",
758 [TAS_DISABLED_REASON_INVALID] =
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",
773 struct iwl_host_cmd hcmd = {
774 .id = WIDE_ID(DEBUG_GROUP, GET_TAS_STATUS),
775 .flags = CMD_WANT_SKB,
780 bool tas_enabled = false;
781 unsigned long dyn_status;
783 if (!iwl_mvm_firmware_running(mvm))
786 mutex_lock(&mvm->mutex);
787 ret = iwl_mvm_send_cmd(mvm, &hcmd);
788 mutex_unlock(&mvm->mutex);
792 buff = kzalloc(bufsz, GFP_KERNEL);
796 endpos = pos + bufsz;
798 rsp = (void *)hcmd.resp_pkt->data;
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");
809 case TAS_LMAC_BAND_LB:
810 pos += scnprintf(pos, endpos - pos, "LB\n");
812 case TAS_LMAC_BAND_UHB:
813 pos += scnprintf(pos, endpos - pos, "UHB\n");
815 case TAS_LMAC_BAND_INVALID:
816 pos += scnprintf(pos, endpos - pos,
820 pos += scnprintf(pos, endpos - pos,
821 "Unsupported band (%d)\n",
822 rsp->tas_status_mac[i].band);
829 pos += scnprintf(pos, endpos - pos, "\tOFF\n");
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));
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]));
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");
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",
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");
867 case TAS_LMAC_BAND_LB:
868 pos += scnprintf(pos, endpos - pos, "Low band\n");
870 case TAS_LMAC_BAND_UHB:
871 pos += scnprintf(pos, endpos - pos,
872 "Ultra high band\n");
874 case TAS_LMAC_BAND_INVALID:
875 pos += scnprintf(pos, endpos - pos,
879 pos += scnprintf(pos, endpos - pos,
880 "Unsupported band (%d)\n",
881 rsp->tas_status_mac[i].band);
884 pos += scnprintf(pos, endpos - pos, "Static status: %sabled\n",
885 rsp->tas_status_mac[i].static_status ?
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);
894 pos += scnprintf(pos, endpos - pos,
895 "unsupported value (%d)\n",
896 rsp->tas_status_mac[i].static_dis_reason);
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,
904 tas_current_status[tmp], tmp);
907 pos += scnprintf(pos, endpos - pos,
908 "Is near disconnection?: %s\n",
909 rsp->tas_status_mac[i].near_disconnection ?
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));
922 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
924 iwl_free_resp(&hcmd);
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)
932 struct iwl_mvm *mvm = file->private_data;
938 bufsz = mvm->fw->phy_integration_ver_len + 2;
939 buf = kmalloc(bufsz, GFP_KERNEL);
943 pos = scnprintf(buf, bufsz, "%.*s\n", mvm->fw->phy_integration_ver_len,
944 mvm->fw->phy_integration_ver);
946 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
952 #define PRINT_STATS_LE32(_struct, _memb) \
953 pos += scnprintf(buf + pos, bufsz - pos, \
955 le32_to_cpu(_struct->_memb))
957 static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
958 char __user *user_buf, size_t count,
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";
969 if (iwl_mvm_has_new_rx_stats_api(mvm))
970 bufsz = ((sizeof(struct mvm_statistics_rx) /
971 sizeof(__le32)) * 43) + (4 * 33) + 1;
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;
977 buf = kzalloc(bufsz, GFP_KERNEL);
981 mutex_lock(&mvm->mutex);
983 if (iwl_mvm_firmware_running(mvm))
984 iwl_mvm_request_statistics(mvm, false);
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;
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);
1012 struct mvm_statistics_rx_phy *ofdm = &mvm->rx_stats.ofdm;
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);
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;
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);
1047 struct mvm_statistics_rx_phy *cck = &mvm->rx_stats.cck;
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);
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;
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);
1087 struct mvm_statistics_rx_non_phy *general =
1088 &mvm->rx_stats.general;
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);
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;
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);
1129 struct mvm_statistics_rx_ht_phy *ht =
1130 &mvm->rx_stats.ofdm_ht;
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);
1138 mutex_unlock(&mvm->mutex);
1140 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1145 #undef PRINT_STAT_LE32
1147 static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm,
1148 char __user *user_buf, size_t count,
1150 struct iwl_mvm_frame_stats *stats)
1152 char *buff, *pos, *endpos;
1155 static const size_t bufsz = 1024;
1157 buff = kmalloc(bufsz, GFP_KERNEL);
1161 spin_lock_bh(&mvm->drv_stats_lock);
1164 endpos = pos + bufsz;
1166 pos += scnprintf(pos, endpos - pos,
1167 "Legacy/HT/VHT\t:\t%d/%d/%d\n",
1168 stats->legacy_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",
1178 pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n",
1180 stats->mimo2_frames);
1181 pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n",
1183 stats->success_frames);
1184 pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n",
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);
1192 pos += scnprintf(pos, endpos - pos, "Last Rates\n");
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)
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)
1206 spin_unlock_bh(&mvm->drv_stats_lock);
1208 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
1214 static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file,
1215 char __user *user_buf, size_t count,
1218 struct iwl_mvm *mvm = file->private_data;
1220 return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos,
1221 &mvm->drv_rx_stats);
1224 static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
1225 size_t count, loff_t *ppos)
1227 int __maybe_unused ret;
1229 if (!iwl_mvm_firmware_running(mvm))
1232 mutex_lock(&mvm->mutex);
1234 /* allow one more restart that we're provoking here */
1235 if (mvm->fw_restart >= 0)
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);
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),
1248 mutex_unlock(&mvm->mutex);
1253 static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
1254 size_t count, loff_t *ppos)
1256 if (!iwl_mvm_firmware_running(mvm))
1259 if (count == 6 && !strcmp(buf, "nolog\n"))
1260 set_bit(IWL_MVM_STATUS_SUPPRESS_ERROR_LOG_ONCE, &mvm->status);
1262 iwl_force_nmi(mvm->trans);
1268 iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
1269 char __user *user_buf,
1270 size_t count, loff_t *ppos)
1272 struct iwl_mvm *mvm = file->private_data;
1275 const size_t bufsz = sizeof(buf);
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);
1285 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1289 iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
1290 size_t count, loff_t *ppos)
1294 if (!iwl_mvm_firmware_running(mvm))
1297 if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
1299 if (scan_rx_ant > ANT_ABC)
1301 if (scan_rx_ant & ~(iwl_mvm_get_valid_rx_ant(mvm)))
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);
1314 static ssize_t iwl_dbgfs_indirection_tbl_write(struct iwl_mvm *mvm,
1315 char *buf, size_t count,
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,
1327 int ret, i, num_repeats, nbytes = count / 2;
1329 ret = hex2bin(cmd.indirection_table, buf, nbytes);
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
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);
1348 netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key));
1350 mutex_lock(&mvm->mutex);
1351 if (iwl_mvm_firmware_running(mvm))
1352 ret = iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0,
1356 mutex_unlock(&mvm->mutex);
1358 return ret ?: count;
1361 static ssize_t iwl_dbgfs_inject_packet_write(struct iwl_mvm *mvm,
1362 char *buf, size_t count,
1365 struct iwl_op_mode *opmode = container_of((void *)mvm,
1368 struct iwl_rx_cmd_buffer rxb = {
1369 ._rx_page_order = 0,
1370 .truesize = 0, /* not used */
1373 struct iwl_rx_packet *pkt;
1374 int bin_len = count / 2;
1377 if (!iwl_mvm_firmware_running(mvm))
1380 /* supporting only MQ RX */
1381 if (!mvm->trans->trans_cfg->mq_rx_supported)
1384 rxb._page = alloc_pages(GFP_ATOMIC, 0);
1387 pkt = rxb_addr(&rxb);
1389 ret = hex2bin(page_address(rxb._page), buf, bin_len);
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))
1399 iwl_mvm_rx_mq(opmode, NULL, &rxb);
1406 return ret ?: count;
1409 static int _iwl_dbgfs_inject_beacon_ie(struct iwl_mvm *mvm, char *bin, int len)
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;
1422 /* Element len should be represented by u8 */
1426 if (!iwl_mvm_firmware_running(mvm))
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))
1434 mutex_lock(&mvm->mutex);
1436 for (i = 0; i < NUM_MAC_INDEX_DRIVER; i++) {
1437 vif = iwl_mvm_rcu_dereference_vif_id(mvm, i, false);
1441 if (vif->type == NL80211_IFTYPE_AP)
1445 if (i == NUM_MAC_INDEX_DRIVER || !vif)
1448 mvm->hw->extra_beacon_tailroom = len;
1450 beacon = ieee80211_beacon_get_template(mvm->hw, vif, NULL, 0);
1454 if (len && hex2bin(skb_put_zero(beacon, len), bin, len)) {
1455 dev_kfree_skb(beacon);
1459 mvm->beacon_inject_active = true;
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);
1465 for_each_mvm_vif_valid_link(mvmvif, link_id) {
1467 cpu_to_le16(iwl_mvm_mac_ctxt_get_beacon_flags(mvm->fw,
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);
1474 beacon_cmd.link_id = cpu_to_le32((u32)mvmvif->id);
1476 iwl_mvm_mac_ctxt_set_tim(mvm, &beacon_cmd.tim_idx,
1477 &beacon_cmd.tim_size,
1478 beacon->data, beacon->len);
1480 iwl_mvm_mac_ctxt_send_beacon_cmd(mvm, beacon, &beacon_cmd,
1481 sizeof(beacon_cmd));
1483 mutex_unlock(&mvm->mutex);
1485 dev_kfree_skb(beacon);
1490 mutex_unlock(&mvm->mutex);
1494 static ssize_t iwl_dbgfs_inject_beacon_ie_write(struct iwl_mvm *mvm,
1495 char *buf, size_t count,
1498 int ret = _iwl_dbgfs_inject_beacon_ie(mvm, buf, count);
1500 mvm->hw->extra_beacon_tailroom = 0;
1501 return ret ?: count;
1504 static ssize_t iwl_dbgfs_inject_beacon_ie_restore_write(struct iwl_mvm *mvm,
1509 int ret = _iwl_dbgfs_inject_beacon_ie(mvm, NULL, 0);
1511 mvm->hw->extra_beacon_tailroom = 0;
1512 mvm->beacon_inject_active = false;
1513 return ret ?: count;
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)
1520 struct iwl_mvm *mvm = file->private_data;
1523 const size_t bufsz = sizeof(buf);
1526 mutex_lock(&mvm->mutex);
1527 conf = mvm->fwrt.dump.conf;
1528 mutex_unlock(&mvm->mutex);
1530 pos += scnprintf(buf + pos, bufsz - pos, "%d\n", conf);
1532 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1535 static ssize_t iwl_dbgfs_fw_dbg_conf_write(struct iwl_mvm *mvm,
1536 char *buf, size_t count,
1539 unsigned int conf_id;
1542 if (!iwl_mvm_firmware_running(mvm))
1545 ret = kstrtouint(buf, 0, &conf_id);
1549 if (WARN_ON(conf_id >= FW_DBG_CONF_MAX))
1552 mutex_lock(&mvm->mutex);
1553 ret = iwl_fw_start_dbg_conf(&mvm->fwrt, conf_id);
1554 mutex_unlock(&mvm->mutex);
1556 return ret ?: count;
1559 static ssize_t iwl_dbgfs_fw_dbg_collect_write(struct iwl_mvm *mvm,
1560 char *buf, size_t count,
1566 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_USER_TRIGGER,
1569 iwl_fw_dbg_collect(&mvm->fwrt, FW_DBG_TRIGGER_USER, buf,
1575 static ssize_t iwl_dbgfs_dbg_time_point_write(struct iwl_mvm *mvm,
1576 char *buf, size_t count,
1581 if (kstrtou32(buf, 0, &timepoint))
1584 if (timepoint == IWL_FW_INI_TIME_POINT_INVALID ||
1585 timepoint >= IWL_FW_INI_TIME_POINT_NUM)
1588 iwl_dbg_tlv_time_point(&mvm->fwrt, timepoint, NULL);
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); \
1601 #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
1602 MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
1605 _iwl_dbgfs_link_sta_wrap_write(ssize_t (*real)(struct ieee80211_link_sta *,
1606 struct iwl_mvm_sta *,
1608 struct iwl_mvm_link_sta *,
1612 char *buf, size_t buf_size, loff_t *ppos)
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;
1620 mutex_lock(&mvm->mutex);
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);
1629 ret = real(link_sta, mvmsta, mvm, mvm_link_sta, buf, buf_size, ppos);
1631 mutex_unlock(&mvm->mutex);
1637 _iwl_dbgfs_link_sta_wrap_read(ssize_t (*real)(struct ieee80211_link_sta *,
1638 struct iwl_mvm_sta *,
1640 struct iwl_mvm_link_sta *,
1644 char __user *user_buf, size_t count, loff_t *ppos)
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;
1652 mutex_lock(&mvm->mutex);
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);
1661 ret = real(link_sta, mvmsta, mvm, mvm_link_sta, user_buf, count, ppos);
1663 mutex_unlock(&mvm->mutex);
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) \
1673 char buf[buflen] = {}; \
1674 size_t buf_size = min(count, sizeof(buf) - 1); \
1676 if (copy_from_user(buf, user_buf, sizeof(buf))) \
1679 return _iwl_dbgfs_link_sta_wrap_write(iwl_dbgfs_##name##_write, \
1681 buf, buf_size, ppos); \
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) \
1689 return _iwl_dbgfs_link_sta_wrap_read(iwl_dbgfs_##name##_read, \
1691 user_buf, count, ppos); \
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, \
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, \
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, \
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)
1727 iwl_dbgfs_prph_reg_read(struct file *file,
1728 char __user *user_buf,
1729 size_t count, loff_t *ppos)
1731 struct iwl_mvm *mvm = file->private_data;
1734 const size_t bufsz = sizeof(buf);
1736 if (!mvm->dbgfs_prph_reg_addr)
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));
1743 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1747 iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf,
1748 size_t count, loff_t *ppos)
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 */
1758 /* otherwise, make sure we have both address and value */
1762 iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value);
1769 iwl_dbgfs_send_echo_cmd_write(struct iwl_mvm *mvm, char *buf,
1770 size_t count, loff_t *ppos)
1774 if (!iwl_mvm_firmware_running(mvm))
1777 mutex_lock(&mvm->mutex);
1778 ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL);
1779 mutex_unlock(&mvm->mutex);
1781 return ret ?: count;
1784 struct iwl_mvm_sniffer_apply {
1785 struct iwl_mvm *mvm;
1790 static bool iwl_mvm_sniffer_apply(struct iwl_notif_wait_data *notif_data,
1791 struct iwl_rx_packet *pkt, void *data)
1793 struct iwl_mvm_sniffer_apply *apply = data;
1795 apply->mvm->cur_aid = cpu_to_le16(apply->aid);
1796 memcpy(apply->mvm->cur_bssid, apply->bssid,
1797 sizeof(apply->mvm->cur_bssid));
1803 iwl_dbgfs_he_sniffer_params_write(struct iwl_mvm *mvm, char *buf,
1804 size_t count, loff_t *ppos)
1806 struct iwl_notification_wait wait;
1807 struct iwl_he_monitor_cmd he_mon_cmd = {};
1808 struct iwl_mvm_sniffer_apply apply = {
1812 WIDE_ID(DATA_PATH_GROUP, HE_AIR_SNIFFER_CONFIG_CMD),
1817 if (!iwl_mvm_firmware_running(mvm))
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]);
1827 he_mon_cmd.aid = cpu_to_le16(aid);
1830 apply.bssid = (void *)he_mon_cmd.bssid;
1832 mutex_lock(&mvm->mutex);
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.
1843 iwl_init_notification_wait(&mvm->notif_wait, &wait,
1844 wait_cmds, ARRAY_SIZE(wait_cmds),
1845 iwl_mvm_sniffer_apply, &apply);
1847 ret = iwl_mvm_send_cmd_pdu(mvm,
1848 WIDE_ID(DATA_PATH_GROUP, HE_AIR_SNIFFER_CONFIG_CMD),
1850 sizeof(he_mon_cmd), &he_mon_cmd);
1852 /* no need to really wait, we already did anyway */
1853 iwl_remove_notification(&mvm->notif_wait, &wait);
1855 mutex_unlock(&mvm->mutex);
1857 return ret ?: count;
1861 iwl_dbgfs_he_sniffer_params_read(struct file *file, char __user *user_buf,
1862 size_t count, loff_t *ppos)
1864 struct iwl_mvm *mvm = file->private_data;
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]);
1874 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1878 iwl_dbgfs_uapsd_noagg_bssids_read(struct file *file, char __user *user_buf,
1879 size_t count, loff_t *ppos)
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);
1887 mutex_lock(&mvm->mutex);
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);
1893 mutex_unlock(&mvm->mutex);
1895 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1899 iwl_dbgfs_ltr_config_write(struct iwl_mvm *mvm,
1900 char *buf, size_t count, loff_t *ppos)
1903 struct iwl_ltr_config_cmd ltr_config = {0};
1905 if (!iwl_mvm_firmware_running(mvm))
1908 if (sscanf(buf, "%x,%x,%x,%x,%x,%x,%x",
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) {
1919 mutex_lock(&mvm->mutex);
1920 ret = iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0, sizeof(ltr_config),
1922 mutex_unlock(&mvm->mutex);
1925 IWL_ERR(mvm, "failed to send ltr configuration cmd\n");
1927 return ret ?: count;
1930 static ssize_t iwl_dbgfs_rfi_freq_table_write(struct iwl_mvm *mvm, char *buf,
1931 size_t count, loff_t *ppos)
1936 if (kstrtou16(buf, 10, &op_id))
1939 /* value zero triggers re-sending the default table to the device */
1941 mutex_lock(&mvm->mutex);
1942 ret = iwl_rfi_send_config_cmd(mvm, NULL);
1943 mutex_unlock(&mvm->mutex);
1945 ret = -EOPNOTSUPP; /* in the future a new table will be added */
1948 return ret ?: count;
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.
1956 #define IWL_RFI_BUF_SIZE (IWL_RFI_LUT_INSTALLED_SIZE *\
1957 (5 + IWL_RFI_LUT_ENTRY_CHANNELS_NUM * (6 + 5)))
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)
1963 struct iwl_mvm *mvm = file->private_data;
1964 struct iwl_rfi_freq_table_resp_cmd *resp;
1966 char buf[IWL_RFI_BUF_SIZE];
1969 resp = iwl_rfi_get_freq_table(mvm);
1971 return PTR_ERR(resp);
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);
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);
1983 for (j = 0; j < ARRAY_SIZE(resp->table[i].channels); j++)
1984 pos += scnprintf(buf + pos, IWL_RFI_BUF_SIZE - pos,
1986 resp->table[i].channels[j],
1987 resp->table[i].bands[j]);
1988 pos += scnprintf(buf + pos, IWL_RFI_BUF_SIZE - pos, "\n");
1993 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1996 MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);
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);
2032 MVM_DEBUGFS_READ_FILE_OPS(uapsd_noagg_bssids);
2035 MVM_DEBUGFS_READ_FILE_OPS(sar_geo_profile);
2036 MVM_DEBUGFS_READ_FILE_OPS(wifi_6e_enable);
2039 MVM_DEBUGFS_READ_WRITE_LINK_STA_FILE_OPS(amsdu_len, 16);
2041 MVM_DEBUGFS_READ_WRITE_FILE_OPS(he_sniffer_params, 32);
2043 MVM_DEBUGFS_WRITE_FILE_OPS(ltr_config, 512);
2044 MVM_DEBUGFS_READ_WRITE_FILE_OPS(rfi_freq_table, 16);
2046 static ssize_t iwl_dbgfs_mem_read(struct file *file, char __user *user_buf,
2047 size_t count, loff_t *ppos)
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,
2055 .len = { sizeof(cmd) },
2060 if (!iwl_mvm_firmware_running(mvm))
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);
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));
2072 mutex_lock(&mvm->mutex);
2073 ret = iwl_mvm_send_cmd(mvm, &hcmd);
2074 mutex_unlock(&mvm->mutex);
2079 if (iwl_rx_packet_payload_len(hcmd.resp_pkt) < sizeof(*rsp)) {
2084 rsp = (void *)hcmd.resp_pkt->data;
2085 if (le32_to_cpu(rsp->status) != DEBUG_MEM_STATUS_SUCCESS) {
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);
2098 ret = len - copy_to_user(user_buf, (u8 *)rsp->data + delta, len);
2102 iwl_free_resp(&hcmd);
2106 static ssize_t iwl_dbgfs_mem_write(struct file *file,
2107 const char __user *user_buf, size_t count,
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 = {};
2119 if (!iwl_mvm_firmware_running(mvm))
2122 hcmd.id = WIDE_ID(DEBUG_GROUP, *ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR);
2124 if (*ppos & 0x3 || count < 4) {
2125 op = DEBUG_MEM_OP_WRITE_BYTES;
2126 len = min(count, (size_t)(4 - (*ppos & 0x3)));
2129 op = DEBUG_MEM_OP_WRITE;
2130 len = min(count >> 2, (size_t)DEBUG_MEM_MAX_SIZE_DWORDS);
2131 data_size = len << 2;
2134 cmd_size = sizeof(*cmd) + ALIGN(data_size, 4);
2135 cmd = kzalloc(cmd_size, GFP_KERNEL);
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)) {
2147 hcmd.flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
2148 hcmd.data[0] = (void *)cmd;
2149 hcmd.len[0] = cmd_size;
2151 mutex_lock(&mvm->mutex);
2152 ret = iwl_mvm_send_cmd(mvm, &hcmd);
2153 mutex_unlock(&mvm->mutex);
2160 if (iwl_rx_packet_payload_len(hcmd.resp_pkt) < sizeof(*rsp)) {
2165 rsp = (void *)hcmd.resp_pkt->data;
2166 if (rsp->status != DEBUG_MEM_STATUS_SUCCESS) {
2175 iwl_free_resp(&hcmd);
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,
2186 void iwl_mvm_link_sta_add_debugfs(struct ieee80211_hw *hw,
2187 struct ieee80211_vif *vif,
2188 struct ieee80211_link_sta *link_sta,
2191 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2193 if (iwl_mvm_has_tlc_offload(mvm)) {
2194 MVM_DEBUGFS_ADD_LINK_STA_FILE(rs_data, dir, 0400);
2197 MVM_DEBUGFS_ADD_LINK_STA_FILE(amsdu_len, dir, 0600);
2200 void iwl_mvm_dbgfs_register(struct iwl_mvm *mvm)
2202 struct dentry *bcast_dir __maybe_unused;
2204 spin_lock_init(&mvm->drv_stats_lock);
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);
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);
2241 MVM_DEBUGFS_ADD_FILE(sar_geo_profile, mvm->debugfs_dir, 0400);
2242 MVM_DEBUGFS_ADD_FILE(wifi_6e_enable, mvm->debugfs_dir, 0400);
2244 MVM_DEBUGFS_ADD_FILE(he_sniffer_params, mvm->debugfs_dir, 0600);
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);
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);
2254 MVM_DEBUGFS_ADD_FILE(uapsd_noagg_bssids, mvm->debugfs_dir, S_IRUSR);
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);
2264 debugfs_create_u8("ps_disabled", 0400, mvm->debugfs_dir,
2266 debugfs_create_blob("nvm_hw", 0400, mvm->debugfs_dir,
2268 debugfs_create_blob("nvm_sw", 0400, mvm->debugfs_dir,
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);
2279 debugfs_create_file("mem", 0600, mvm->debugfs_dir, mvm,
2280 &iwl_dbgfs_mem_ops);
2283 * Create a symlink with mac80211. It will be removed when mac80211
2284 * exists (before the opmode exists which removes the target.)
2286 if (!IS_ERR(mvm->debugfs_dir)) {
2289 snprintf(buf, 100, "../../%pd2", mvm->debugfs_dir->d_parent);
2290 debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir,