Path: blob/main/sys/contrib/dev/iwlwifi/mvm/debugfs-vif.c
48287 views
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause1/*2* Copyright (C) 2012-2014, 2018-2024 Intel Corporation3* Copyright (C) 2013-2015 Intel Mobile Communications GmbH4* Copyright (C) 2016-2017 Intel Deutschland GmbH5*/6#include "mvm.h"7#include "debugfs.h"8#if defined(__FreeBSD__)9#include <linux/math64.h>10#endif1112static void iwl_dbgfs_update_pm(struct iwl_mvm *mvm,13struct ieee80211_vif *vif,14enum iwl_dbgfs_pm_mask param, int val)15{16struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);17struct iwl_dbgfs_pm *dbgfs_pm = &mvmvif->dbgfs_pm;1819dbgfs_pm->mask |= param;2021switch (param) {22case MVM_DEBUGFS_PM_KEEP_ALIVE: {23int dtimper = vif->bss_conf.dtim_period ?: 1;24int dtimper_msec = dtimper * vif->bss_conf.beacon_int;2526IWL_DEBUG_POWER(mvm, "debugfs: set keep_alive= %d sec\n", val);27if (val * MSEC_PER_SEC < 3 * dtimper_msec)28IWL_WARN(mvm,29"debugfs: keep alive period (%ld msec) is less than minimum required (%d msec)\n",30val * MSEC_PER_SEC, 3 * dtimper_msec);31dbgfs_pm->keep_alive_seconds = val;32break;33}34case MVM_DEBUGFS_PM_SKIP_OVER_DTIM:35IWL_DEBUG_POWER(mvm, "skip_over_dtim %s\n",36val ? "enabled" : "disabled");37dbgfs_pm->skip_over_dtim = val;38break;39case MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS:40IWL_DEBUG_POWER(mvm, "skip_dtim_periods=%d\n", val);41dbgfs_pm->skip_dtim_periods = val;42break;43case MVM_DEBUGFS_PM_RX_DATA_TIMEOUT:44IWL_DEBUG_POWER(mvm, "rx_data_timeout=%d\n", val);45dbgfs_pm->rx_data_timeout = val;46break;47case MVM_DEBUGFS_PM_TX_DATA_TIMEOUT:48IWL_DEBUG_POWER(mvm, "tx_data_timeout=%d\n", val);49dbgfs_pm->tx_data_timeout = val;50break;51case MVM_DEBUGFS_PM_LPRX_ENA:52IWL_DEBUG_POWER(mvm, "lprx %s\n", val ? "enabled" : "disabled");53dbgfs_pm->lprx_ena = val;54break;55case MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD:56IWL_DEBUG_POWER(mvm, "lprx_rssi_threshold=%d\n", val);57dbgfs_pm->lprx_rssi_threshold = val;58break;59case MVM_DEBUGFS_PM_SNOOZE_ENABLE:60IWL_DEBUG_POWER(mvm, "snooze_enable=%d\n", val);61dbgfs_pm->snooze_ena = val;62break;63case MVM_DEBUGFS_PM_UAPSD_MISBEHAVING:64IWL_DEBUG_POWER(mvm, "uapsd_misbehaving_enable=%d\n", val);65dbgfs_pm->uapsd_misbehaving = val;66break;67case MVM_DEBUGFS_PM_USE_PS_POLL:68IWL_DEBUG_POWER(mvm, "use_ps_poll=%d\n", val);69dbgfs_pm->use_ps_poll = val;70break;71}72}7374static ssize_t iwl_dbgfs_pm_params_write(struct ieee80211_vif *vif, char *buf,75size_t count, loff_t *ppos)76{77struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);78struct iwl_mvm *mvm = mvmvif->mvm;79enum iwl_dbgfs_pm_mask param;80int val, ret;8182if (!strncmp("keep_alive=", buf, 11)) {83if (sscanf(buf + 11, "%d", &val) != 1)84return -EINVAL;85param = MVM_DEBUGFS_PM_KEEP_ALIVE;86} else if (!strncmp("skip_over_dtim=", buf, 15)) {87if (sscanf(buf + 15, "%d", &val) != 1)88return -EINVAL;89param = MVM_DEBUGFS_PM_SKIP_OVER_DTIM;90} else if (!strncmp("skip_dtim_periods=", buf, 18)) {91if (sscanf(buf + 18, "%d", &val) != 1)92return -EINVAL;93param = MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS;94} else if (!strncmp("rx_data_timeout=", buf, 16)) {95if (sscanf(buf + 16, "%d", &val) != 1)96return -EINVAL;97param = MVM_DEBUGFS_PM_RX_DATA_TIMEOUT;98} else if (!strncmp("tx_data_timeout=", buf, 16)) {99if (sscanf(buf + 16, "%d", &val) != 1)100return -EINVAL;101param = MVM_DEBUGFS_PM_TX_DATA_TIMEOUT;102} else if (!strncmp("lprx=", buf, 5)) {103if (sscanf(buf + 5, "%d", &val) != 1)104return -EINVAL;105param = MVM_DEBUGFS_PM_LPRX_ENA;106} else if (!strncmp("lprx_rssi_threshold=", buf, 20)) {107if (sscanf(buf + 20, "%d", &val) != 1)108return -EINVAL;109if (val > POWER_LPRX_RSSI_THRESHOLD_MAX || val <110POWER_LPRX_RSSI_THRESHOLD_MIN)111return -EINVAL;112param = MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD;113} else if (!strncmp("snooze_enable=", buf, 14)) {114if (sscanf(buf + 14, "%d", &val) != 1)115return -EINVAL;116param = MVM_DEBUGFS_PM_SNOOZE_ENABLE;117} else if (!strncmp("uapsd_misbehaving=", buf, 18)) {118if (sscanf(buf + 18, "%d", &val) != 1)119return -EINVAL;120param = MVM_DEBUGFS_PM_UAPSD_MISBEHAVING;121} else if (!strncmp("use_ps_poll=", buf, 12)) {122if (sscanf(buf + 12, "%d", &val) != 1)123return -EINVAL;124param = MVM_DEBUGFS_PM_USE_PS_POLL;125} else {126return -EINVAL;127}128129mutex_lock(&mvm->mutex);130iwl_dbgfs_update_pm(mvm, vif, param, val);131ret = iwl_mvm_power_update_mac(mvm);132mutex_unlock(&mvm->mutex);133134return ret ?: count;135}136137static ssize_t iwl_dbgfs_tx_pwr_lmt_read(struct file *file,138char __user *user_buf,139size_t count, loff_t *ppos)140{141struct ieee80211_vif *vif = file->private_data;142char buf[64];143int bufsz = sizeof(buf);144int pos;145146pos = scnprintf(buf, bufsz, "bss limit = %d\n",147vif->bss_conf.txpower);148149return simple_read_from_buffer(user_buf, count, ppos, buf, pos);150}151152static ssize_t iwl_dbgfs_pm_params_read(struct file *file,153char __user *user_buf,154size_t count, loff_t *ppos)155{156struct ieee80211_vif *vif = file->private_data;157struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);158struct iwl_mvm *mvm = mvmvif->mvm;159char buf[512];160int bufsz = sizeof(buf);161int pos;162163pos = iwl_mvm_power_mac_dbgfs_read(mvm, vif, buf, bufsz);164165return simple_read_from_buffer(user_buf, count, ppos, buf, pos);166}167168static ssize_t iwl_dbgfs_mac_params_read(struct file *file,169char __user *user_buf,170size_t count, loff_t *ppos)171{172struct ieee80211_vif *vif = file->private_data;173struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);174struct iwl_mvm *mvm = mvmvif->mvm;175u8 ap_sta_id;176struct ieee80211_chanctx_conf *chanctx_conf;177char buf[512];178int bufsz = sizeof(buf);179int pos = 0;180int i;181182mutex_lock(&mvm->mutex);183184ap_sta_id = mvmvif->deflink.ap_sta_id;185186switch (ieee80211_vif_type_p2p(vif)) {187case NL80211_IFTYPE_ADHOC:188pos += scnprintf(buf+pos, bufsz-pos, "type: ibss\n");189break;190case NL80211_IFTYPE_STATION:191pos += scnprintf(buf+pos, bufsz-pos, "type: bss\n");192break;193case NL80211_IFTYPE_AP:194pos += scnprintf(buf+pos, bufsz-pos, "type: ap\n");195break;196case NL80211_IFTYPE_P2P_CLIENT:197pos += scnprintf(buf+pos, bufsz-pos, "type: p2p client\n");198break;199case NL80211_IFTYPE_P2P_GO:200pos += scnprintf(buf+pos, bufsz-pos, "type: p2p go\n");201break;202case NL80211_IFTYPE_P2P_DEVICE:203pos += scnprintf(buf+pos, bufsz-pos, "type: p2p dev\n");204break;205default:206break;207}208209pos += scnprintf(buf+pos, bufsz-pos, "mac id/color: %d / %d\n",210mvmvif->id, mvmvif->color);211pos += scnprintf(buf+pos, bufsz-pos, "bssid: %pM\n",212vif->bss_conf.bssid);213pos += scnprintf(buf+pos, bufsz-pos, "Load: %d\n",214mvm->tcm.result.load[mvmvif->id]);215pos += scnprintf(buf+pos, bufsz-pos, "QoS:\n");216for (i = 0; i < ARRAY_SIZE(mvmvif->deflink.queue_params); i++)217pos += scnprintf(buf+pos, bufsz-pos,218"\t%d: txop:%d - cw_min:%d - cw_max = %d - aifs = %d upasd = %d\n",219i, mvmvif->deflink.queue_params[i].txop,220mvmvif->deflink.queue_params[i].cw_min,221mvmvif->deflink.queue_params[i].cw_max,222mvmvif->deflink.queue_params[i].aifs,223mvmvif->deflink.queue_params[i].uapsd);224225if (vif->type == NL80211_IFTYPE_STATION &&226ap_sta_id != IWL_INVALID_STA) {227struct iwl_mvm_sta *mvm_sta;228229mvm_sta = iwl_mvm_sta_from_staid_protected(mvm, ap_sta_id);230if (mvm_sta) {231pos += scnprintf(buf+pos, bufsz-pos,232"ap_sta_id %d - reduced Tx power %d\n",233ap_sta_id,234mvm_sta->bt_reduced_txpower);235}236}237238rcu_read_lock();239chanctx_conf = rcu_dereference(vif->bss_conf.chanctx_conf);240if (chanctx_conf)241pos += scnprintf(buf+pos, bufsz-pos,242"idle rx chains %d, active rx chains: %d\n",243chanctx_conf->rx_chains_static,244chanctx_conf->rx_chains_dynamic);245rcu_read_unlock();246247mutex_unlock(&mvm->mutex);248249return simple_read_from_buffer(user_buf, count, ppos, buf, pos);250}251252static void iwl_dbgfs_update_bf(struct ieee80211_vif *vif,253enum iwl_dbgfs_bf_mask param, int value)254{255struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);256struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;257258dbgfs_bf->mask |= param;259260switch (param) {261case MVM_DEBUGFS_BF_ENERGY_DELTA:262dbgfs_bf->bf_energy_delta = value;263break;264case MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA:265dbgfs_bf->bf_roaming_energy_delta = value;266break;267case MVM_DEBUGFS_BF_ROAMING_STATE:268dbgfs_bf->bf_roaming_state = value;269break;270case MVM_DEBUGFS_BF_TEMP_THRESHOLD:271dbgfs_bf->bf_temp_threshold = value;272break;273case MVM_DEBUGFS_BF_TEMP_FAST_FILTER:274dbgfs_bf->bf_temp_fast_filter = value;275break;276case MVM_DEBUGFS_BF_TEMP_SLOW_FILTER:277dbgfs_bf->bf_temp_slow_filter = value;278break;279case MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER:280dbgfs_bf->bf_enable_beacon_filter = value;281break;282case MVM_DEBUGFS_BF_DEBUG_FLAG:283dbgfs_bf->bf_debug_flag = value;284break;285case MVM_DEBUGFS_BF_ESCAPE_TIMER:286dbgfs_bf->bf_escape_timer = value;287break;288case MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT:289dbgfs_bf->ba_enable_beacon_abort = value;290break;291case MVM_DEBUGFS_BA_ESCAPE_TIMER:292dbgfs_bf->ba_escape_timer = value;293break;294}295}296297static ssize_t iwl_dbgfs_bf_params_write(struct ieee80211_vif *vif, char *buf,298size_t count, loff_t *ppos)299{300struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);301struct iwl_mvm *mvm = mvmvif->mvm;302enum iwl_dbgfs_bf_mask param;303int value, ret = 0;304305if (!strncmp("bf_energy_delta=", buf, 16)) {306if (sscanf(buf+16, "%d", &value) != 1)307return -EINVAL;308if (value < IWL_BF_ENERGY_DELTA_MIN ||309value > IWL_BF_ENERGY_DELTA_MAX)310return -EINVAL;311param = MVM_DEBUGFS_BF_ENERGY_DELTA;312} else if (!strncmp("bf_roaming_energy_delta=", buf, 24)) {313if (sscanf(buf+24, "%d", &value) != 1)314return -EINVAL;315if (value < IWL_BF_ROAMING_ENERGY_DELTA_MIN ||316value > IWL_BF_ROAMING_ENERGY_DELTA_MAX)317return -EINVAL;318param = MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA;319} else if (!strncmp("bf_roaming_state=", buf, 17)) {320if (sscanf(buf+17, "%d", &value) != 1)321return -EINVAL;322if (value < IWL_BF_ROAMING_STATE_MIN ||323value > IWL_BF_ROAMING_STATE_MAX)324return -EINVAL;325param = MVM_DEBUGFS_BF_ROAMING_STATE;326} else if (!strncmp("bf_temp_threshold=", buf, 18)) {327if (sscanf(buf+18, "%d", &value) != 1)328return -EINVAL;329if (value < IWL_BF_TEMP_THRESHOLD_MIN ||330value > IWL_BF_TEMP_THRESHOLD_MAX)331return -EINVAL;332param = MVM_DEBUGFS_BF_TEMP_THRESHOLD;333} else if (!strncmp("bf_temp_fast_filter=", buf, 20)) {334if (sscanf(buf+20, "%d", &value) != 1)335return -EINVAL;336if (value < IWL_BF_TEMP_FAST_FILTER_MIN ||337value > IWL_BF_TEMP_FAST_FILTER_MAX)338return -EINVAL;339param = MVM_DEBUGFS_BF_TEMP_FAST_FILTER;340} else if (!strncmp("bf_temp_slow_filter=", buf, 20)) {341if (sscanf(buf+20, "%d", &value) != 1)342return -EINVAL;343if (value < IWL_BF_TEMP_SLOW_FILTER_MIN ||344value > IWL_BF_TEMP_SLOW_FILTER_MAX)345return -EINVAL;346param = MVM_DEBUGFS_BF_TEMP_SLOW_FILTER;347} else if (!strncmp("bf_enable_beacon_filter=", buf, 24)) {348if (sscanf(buf+24, "%d", &value) != 1)349return -EINVAL;350if (value < 0 || value > 1)351return -EINVAL;352param = MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER;353} else if (!strncmp("bf_debug_flag=", buf, 14)) {354if (sscanf(buf+14, "%d", &value) != 1)355return -EINVAL;356if (value < 0 || value > 1)357return -EINVAL;358param = MVM_DEBUGFS_BF_DEBUG_FLAG;359} else if (!strncmp("bf_escape_timer=", buf, 16)) {360if (sscanf(buf+16, "%d", &value) != 1)361return -EINVAL;362if (value < IWL_BF_ESCAPE_TIMER_MIN ||363value > IWL_BF_ESCAPE_TIMER_MAX)364return -EINVAL;365param = MVM_DEBUGFS_BF_ESCAPE_TIMER;366} else if (!strncmp("ba_escape_timer=", buf, 16)) {367if (sscanf(buf+16, "%d", &value) != 1)368return -EINVAL;369if (value < IWL_BA_ESCAPE_TIMER_MIN ||370value > IWL_BA_ESCAPE_TIMER_MAX)371return -EINVAL;372param = MVM_DEBUGFS_BA_ESCAPE_TIMER;373} else if (!strncmp("ba_enable_beacon_abort=", buf, 23)) {374if (sscanf(buf+23, "%d", &value) != 1)375return -EINVAL;376if (value < 0 || value > 1)377return -EINVAL;378param = MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT;379} else {380return -EINVAL;381}382383mutex_lock(&mvm->mutex);384iwl_dbgfs_update_bf(vif, param, value);385if (param == MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER && !value)386ret = iwl_mvm_disable_beacon_filter(mvm, vif);387else388ret = iwl_mvm_enable_beacon_filter(mvm, vif);389mutex_unlock(&mvm->mutex);390391return ret ?: count;392}393394static ssize_t iwl_dbgfs_bf_params_read(struct file *file,395char __user *user_buf,396size_t count, loff_t *ppos)397{398struct ieee80211_vif *vif = file->private_data;399struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);400char buf[256];401int pos = 0;402const size_t bufsz = sizeof(buf);403struct iwl_beacon_filter_cmd cmd = {404IWL_BF_CMD_CONFIG_DEFAULTS,405.bf_enable_beacon_filter =406cpu_to_le32(IWL_BF_ENABLE_BEACON_FILTER_DEFAULT),407.ba_enable_beacon_abort =408cpu_to_le32(IWL_BA_ENABLE_BEACON_ABORT_DEFAULT),409};410411iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);412if (mvmvif->bf_enabled)413cmd.bf_enable_beacon_filter = cpu_to_le32(1);414else415cmd.bf_enable_beacon_filter = 0;416417pos += scnprintf(buf+pos, bufsz-pos, "bf_energy_delta = %d\n",418le32_to_cpu(cmd.bf_energy_delta));419pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_energy_delta = %d\n",420le32_to_cpu(cmd.bf_roaming_energy_delta));421pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_state = %d\n",422le32_to_cpu(cmd.bf_roaming_state));423pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_threshold = %d\n",424le32_to_cpu(cmd.bf_temp_threshold));425pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_fast_filter = %d\n",426le32_to_cpu(cmd.bf_temp_fast_filter));427pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_slow_filter = %d\n",428le32_to_cpu(cmd.bf_temp_slow_filter));429pos += scnprintf(buf+pos, bufsz-pos, "bf_enable_beacon_filter = %d\n",430le32_to_cpu(cmd.bf_enable_beacon_filter));431pos += scnprintf(buf+pos, bufsz-pos, "bf_debug_flag = %d\n",432le32_to_cpu(cmd.bf_debug_flag));433pos += scnprintf(buf+pos, bufsz-pos, "bf_escape_timer = %d\n",434le32_to_cpu(cmd.bf_escape_timer));435pos += scnprintf(buf+pos, bufsz-pos, "ba_escape_timer = %d\n",436le32_to_cpu(cmd.ba_escape_timer));437pos += scnprintf(buf+pos, bufsz-pos, "ba_enable_beacon_abort = %d\n",438le32_to_cpu(cmd.ba_enable_beacon_abort));439440return simple_read_from_buffer(user_buf, count, ppos, buf, pos);441}442443static ssize_t iwl_dbgfs_os_device_timediff_read(struct file *file,444char __user *user_buf,445size_t count, loff_t *ppos)446{447struct ieee80211_vif *vif = file->private_data;448struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);449struct iwl_mvm *mvm = mvmvif->mvm;450u32 curr_gp2;451u64 curr_os;452s64 diff;453char buf[64];454const size_t bufsz = sizeof(buf);455int pos = 0;456457mutex_lock(&mvm->mutex);458iwl_mvm_get_sync_time(mvm, CLOCK_BOOTTIME, &curr_gp2, &curr_os, NULL);459mutex_unlock(&mvm->mutex);460461do_div(curr_os, NSEC_PER_USEC);462diff = curr_os - curr_gp2;463pos += scnprintf(buf + pos, bufsz - pos, "diff=%lld\n", diff);464465return simple_read_from_buffer(user_buf, count, ppos, buf, pos);466}467468static ssize_t469iwl_dbgfs_low_latency_write_handle(struct wiphy *wiphy, struct file *file,470char *buf, size_t count, void *data)471{472struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);473struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);474struct ieee80211_vif *vif = data;475u8 value;476int ret;477478ret = kstrtou8(buf, 0, &value);479if (ret)480return ret;481if (value > 1)482return -EINVAL;483484mutex_lock(&mvm->mutex);485iwl_mvm_update_low_latency(mvm, vif, value, LOW_LATENCY_DEBUGFS);486mutex_unlock(&mvm->mutex);487488return count;489}490491static ssize_t iwl_dbgfs_low_latency_write(struct file *file,492const char __user *user_buf,493size_t count, loff_t *ppos)494{495struct ieee80211_vif *vif = file->private_data;496struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);497struct iwl_mvm *mvm = mvmvif->mvm;498char buf[10] = {};499500return wiphy_locked_debugfs_write(mvm->hw->wiphy, file,501buf, sizeof(buf), user_buf, count,502iwl_dbgfs_low_latency_write_handle,503vif);504}505506static ssize_t507iwl_dbgfs_low_latency_force_write_handle(struct wiphy *wiphy, struct file *file,508char *buf, size_t count, void *data)509{510struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);511struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);512struct ieee80211_vif *vif = data;513u8 value;514int ret;515516ret = kstrtou8(buf, 0, &value);517if (ret)518return ret;519520if (value > NUM_LOW_LATENCY_FORCE)521return -EINVAL;522523mutex_lock(&mvm->mutex);524if (value == LOW_LATENCY_FORCE_UNSET) {525iwl_mvm_update_low_latency(mvm, vif, false,526LOW_LATENCY_DEBUGFS_FORCE);527iwl_mvm_update_low_latency(mvm, vif, false,528LOW_LATENCY_DEBUGFS_FORCE_ENABLE);529} else {530iwl_mvm_update_low_latency(mvm, vif,531value == LOW_LATENCY_FORCE_ON,532LOW_LATENCY_DEBUGFS_FORCE);533iwl_mvm_update_low_latency(mvm, vif, true,534LOW_LATENCY_DEBUGFS_FORCE_ENABLE);535}536mutex_unlock(&mvm->mutex);537return count;538}539540static ssize_t541iwl_dbgfs_low_latency_force_write(struct file *file,542const char __user *user_buf,543size_t count, loff_t *ppos)544{545struct ieee80211_vif *vif = file->private_data;546struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);547struct iwl_mvm *mvm = mvmvif->mvm;548char buf[10] = {};549550return wiphy_locked_debugfs_write(mvm->hw->wiphy, file,551buf, sizeof(buf), user_buf, count,552iwl_dbgfs_low_latency_force_write_handle,553vif);554}555556static ssize_t iwl_dbgfs_low_latency_read(struct file *file,557char __user *user_buf,558size_t count, loff_t *ppos)559{560struct ieee80211_vif *vif = file->private_data;561struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);562char format[] = "traffic=%d\ndbgfs=%d\nvcmd=%d\nvif_type=%d\n"563"dbgfs_force_enable=%d\ndbgfs_force=%d\nactual=%d\n";564565/*566* all values in format are boolean so the size of format is enough567* for holding the result string568*/569char buf[sizeof(format) + 1] = {};570int len;571572len = scnprintf(buf, sizeof(buf) - 1, format,573!!(mvmvif->low_latency & LOW_LATENCY_TRAFFIC),574!!(mvmvif->low_latency & LOW_LATENCY_DEBUGFS),575!!(mvmvif->low_latency & LOW_LATENCY_VCMD),576!!(mvmvif->low_latency & LOW_LATENCY_VIF_TYPE),577!!(mvmvif->low_latency &578LOW_LATENCY_DEBUGFS_FORCE_ENABLE),579!!(mvmvif->low_latency & LOW_LATENCY_DEBUGFS_FORCE),580!!(mvmvif->low_latency_actual));581return simple_read_from_buffer(user_buf, count, ppos, buf, len);582}583584static ssize_t iwl_dbgfs_uapsd_misbehaving_read(struct file *file,585char __user *user_buf,586size_t count, loff_t *ppos)587{588struct ieee80211_vif *vif = file->private_data;589struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);590char buf[20];591int len;592593#if defined(__linux__)594len = sprintf(buf, "%pM\n", mvmvif->uapsd_misbehaving_ap_addr);595#elif defined(__FreeBSD__)596len = sprintf(buf, "%6D\n", mvmvif->uapsd_misbehaving_ap_addr, ":");597#endif598return simple_read_from_buffer(user_buf, count, ppos, buf, len);599}600601static ssize_t iwl_dbgfs_uapsd_misbehaving_write(struct ieee80211_vif *vif,602char *buf, size_t count,603loff_t *ppos)604{605struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);606struct iwl_mvm *mvm = mvmvif->mvm;607bool ret;608609mutex_lock(&mvm->mutex);610ret = mac_pton(buf, mvmvif->uapsd_misbehaving_ap_addr);611mutex_unlock(&mvm->mutex);612613return ret ? count : -EINVAL;614}615616static ssize_t iwl_dbgfs_rx_phyinfo_write(struct ieee80211_vif *vif, char *buf,617size_t count, loff_t *ppos)618{619struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);620struct iwl_mvm *mvm = mvmvif->mvm;621struct ieee80211_bss_conf *link_conf;622u16 value;623int link_id, ret = -EINVAL;624625ret = kstrtou16(buf, 0, &value);626if (ret)627return ret;628629mutex_lock(&mvm->mutex);630631mvm->dbgfs_rx_phyinfo = value;632633for_each_vif_active_link(vif, link_conf, link_id) {634struct ieee80211_chanctx_conf *chanctx_conf;635struct cfg80211_chan_def min_def, ap_def;636struct iwl_mvm_phy_ctxt *phy_ctxt;637u8 chains_static, chains_dynamic;638639rcu_read_lock();640chanctx_conf = rcu_dereference(link_conf->chanctx_conf);641if (!chanctx_conf) {642rcu_read_unlock();643continue;644}645/* A command can't be sent with RCU lock held, so copy646* everything here and use it after unlocking647*/648min_def = chanctx_conf->min_def;649ap_def = chanctx_conf->ap;650chains_static = chanctx_conf->rx_chains_static;651chains_dynamic = chanctx_conf->rx_chains_dynamic;652rcu_read_unlock();653654phy_ctxt = mvmvif->link[link_id]->phy_ctxt;655if (!phy_ctxt)656continue;657658ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &min_def, &ap_def,659chains_static, chains_dynamic);660}661662mutex_unlock(&mvm->mutex);663664return ret ?: count;665}666667static ssize_t iwl_dbgfs_rx_phyinfo_read(struct file *file,668char __user *user_buf,669size_t count, loff_t *ppos)670{671struct ieee80211_vif *vif = file->private_data;672struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);673char buf[8];674int len;675676len = scnprintf(buf, sizeof(buf), "0x%04x\n",677mvmvif->mvm->dbgfs_rx_phyinfo);678679return simple_read_from_buffer(user_buf, count, ppos, buf, len);680}681682static void iwl_dbgfs_quota_check(void *data, u8 *mac,683struct ieee80211_vif *vif)684{685struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);686int *ret = data;687688if (mvmvif->dbgfs_quota_min)689*ret = -EINVAL;690}691692static ssize_t iwl_dbgfs_quota_min_write(struct ieee80211_vif *vif, char *buf,693size_t count, loff_t *ppos)694{695struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);696struct iwl_mvm *mvm = mvmvif->mvm;697u16 value;698int ret;699700ret = kstrtou16(buf, 0, &value);701if (ret)702return ret;703704if (value > 95)705return -EINVAL;706707mutex_lock(&mvm->mutex);708709mvmvif->dbgfs_quota_min = 0;710ieee80211_iterate_interfaces(mvm->hw, IEEE80211_IFACE_ITER_NORMAL,711iwl_dbgfs_quota_check, &ret);712if (ret == 0) {713mvmvif->dbgfs_quota_min = value;714iwl_mvm_update_quotas(mvm, false, NULL);715}716mutex_unlock(&mvm->mutex);717718return ret ?: count;719}720721static ssize_t iwl_dbgfs_quota_min_read(struct file *file,722char __user *user_buf,723size_t count, loff_t *ppos)724{725struct ieee80211_vif *vif = file->private_data;726struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);727char buf[10];728int len;729730len = scnprintf(buf, sizeof(buf), "%d\n", mvmvif->dbgfs_quota_min);731732return simple_read_from_buffer(user_buf, count, ppos, buf, len);733}734735static ssize_t iwl_dbgfs_max_tx_op_write(struct ieee80211_vif *vif, char *buf,736size_t count, loff_t *ppos)737{738struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);739struct iwl_mvm *mvm = mvmvif->mvm;740u16 value;741int ret;742743ret = kstrtou16(buf, 0, &value);744if (ret)745return ret;746747mutex_lock(&mvm->mutex);748mvmvif->max_tx_op = value;749mutex_unlock(&mvm->mutex);750751return count;752}753754static ssize_t iwl_dbgfs_max_tx_op_read(struct file *file,755char __user *user_buf,756size_t count, loff_t *ppos)757{758struct ieee80211_vif *vif = file->private_data;759struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);760struct iwl_mvm *mvm = mvmvif->mvm;761char buf[10];762int len;763764mutex_lock(&mvm->mutex);765len = scnprintf(buf, sizeof(buf), "%hu\n", mvmvif->max_tx_op);766mutex_unlock(&mvm->mutex);767768return simple_read_from_buffer(user_buf, count, ppos, buf, len);769}770771static ssize_t iwl_dbgfs_int_mlo_scan_write(struct ieee80211_vif *vif,772char *buf, size_t count,773loff_t *ppos)774{775struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);776struct iwl_mvm *mvm = mvmvif->mvm;777u32 action;778int ret;779780if (!vif->cfg.assoc || !ieee80211_vif_is_mld(vif))781return -EINVAL;782783if (kstrtou32(buf, 0, &action))784return -EINVAL;785786mutex_lock(&mvm->mutex);787788if (!action) {789ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_INT_MLO, false);790} else if (action == 1) {791ret = iwl_mvm_int_mlo_scan(mvm, vif);792} else {793ret = -EINVAL;794}795796mutex_unlock(&mvm->mutex);797798return ret ?: count;799}800801static ssize_t iwl_dbgfs_esr_disable_reason_read(struct file *file,802char __user *user_buf,803size_t count, loff_t *ppos)804{805struct ieee80211_vif *vif = file->private_data;806struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);807struct iwl_mvm *mvm = mvmvif->mvm;808unsigned long esr_mask;809char *buf;810int bufsz, pos, i;811ssize_t rv;812813mutex_lock(&mvm->mutex);814esr_mask = mvmvif->esr_disable_reason;815mutex_unlock(&mvm->mutex);816817bufsz = hweight32(esr_mask) * 32 + 40;818buf = kmalloc(bufsz, GFP_KERNEL);819if (!buf)820return -ENOMEM;821822pos = scnprintf(buf, bufsz, "EMLSR state: '0x%lx'\nreasons:\n",823esr_mask);824for_each_set_bit(i, &esr_mask, BITS_PER_LONG)825pos += scnprintf(buf + pos, bufsz - pos, " - %s\n",826iwl_get_esr_state_string(BIT(i)));827828rv = simple_read_from_buffer(user_buf, count, ppos, buf, pos);829kfree(buf);830return rv;831}832833static ssize_t iwl_dbgfs_esr_disable_reason_write(struct ieee80211_vif *vif,834char *buf, size_t count,835loff_t *ppos)836{837struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);838struct iwl_mvm *mvm = mvmvif->mvm;839u32 reason;840u8 block;841int ret;842843ret = sscanf(buf, "%u %hhu", &reason, &block);844if (ret < 0)845return ret;846847if (hweight16(reason) != 1 || !(reason & IWL_MVM_BLOCK_ESR_REASONS))848return -EINVAL;849850mutex_lock(&mvm->mutex);851if (block)852iwl_mvm_block_esr(mvm, vif, reason,853iwl_mvm_get_primary_link(vif));854else855iwl_mvm_unblock_esr(mvm, vif, reason);856mutex_unlock(&mvm->mutex);857858return count;859}860861#define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \862_MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)863#define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \864_MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)865#define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \866debugfs_create_file(#name, mode, parent, vif, \867&iwl_dbgfs_##name##_ops); \868} while (0)869870MVM_DEBUGFS_READ_FILE_OPS(mac_params);871MVM_DEBUGFS_READ_FILE_OPS(tx_pwr_lmt);872MVM_DEBUGFS_READ_WRITE_FILE_OPS(pm_params, 32);873MVM_DEBUGFS_READ_WRITE_FILE_OPS(bf_params, 256);874875static const struct file_operations iwl_dbgfs_low_latency_ops = {876.write = iwl_dbgfs_low_latency_write,877.read = iwl_dbgfs_low_latency_read,878.open = simple_open,879.llseek = generic_file_llseek,880};881882static const struct file_operations iwl_dbgfs_low_latency_force_ops = {883.write = iwl_dbgfs_low_latency_force_write,884.open = simple_open,885.llseek = generic_file_llseek,886};887888MVM_DEBUGFS_READ_WRITE_FILE_OPS(uapsd_misbehaving, 20);889MVM_DEBUGFS_READ_WRITE_FILE_OPS(rx_phyinfo, 10);890MVM_DEBUGFS_READ_WRITE_FILE_OPS(quota_min, 32);891MVM_DEBUGFS_READ_FILE_OPS(os_device_timediff);892MVM_DEBUGFS_READ_WRITE_FILE_OPS(max_tx_op, 10);893MVM_DEBUGFS_WRITE_FILE_OPS(int_mlo_scan, 32);894MVM_DEBUGFS_READ_WRITE_FILE_OPS(esr_disable_reason, 32);895896void iwl_mvm_vif_add_debugfs(struct ieee80211_hw *hw, struct ieee80211_vif *vif)897{898struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);899struct dentry *dbgfs_dir = vif->debugfs_dir;900struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);901902mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir);903if (IS_ERR_OR_NULL(mvmvif->dbgfs_dir)) {904IWL_ERR(mvm, "Failed to create debugfs directory under %pd\n",905dbgfs_dir);906return;907}908909if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM &&910((vif->type == NL80211_IFTYPE_STATION && !vif->p2p) ||911(vif->type == NL80211_IFTYPE_STATION && vif->p2p)))912MVM_DEBUGFS_ADD_FILE_VIF(pm_params, mvmvif->dbgfs_dir, 0600);913914MVM_DEBUGFS_ADD_FILE_VIF(tx_pwr_lmt, mvmvif->dbgfs_dir, 0400);915MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir, 0400);916MVM_DEBUGFS_ADD_FILE_VIF(low_latency, mvmvif->dbgfs_dir, 0600);917MVM_DEBUGFS_ADD_FILE_VIF(low_latency_force, mvmvif->dbgfs_dir, 0600);918MVM_DEBUGFS_ADD_FILE_VIF(uapsd_misbehaving, mvmvif->dbgfs_dir, 0600);919MVM_DEBUGFS_ADD_FILE_VIF(rx_phyinfo, mvmvif->dbgfs_dir, 0600);920MVM_DEBUGFS_ADD_FILE_VIF(quota_min, mvmvif->dbgfs_dir, 0600);921MVM_DEBUGFS_ADD_FILE_VIF(os_device_timediff, mvmvif->dbgfs_dir, 0400);922MVM_DEBUGFS_ADD_FILE_VIF(max_tx_op, mvmvif->dbgfs_dir, 0600);923debugfs_create_bool("ftm_unprotected", 0200, mvmvif->dbgfs_dir,924&mvmvif->ftm_unprotected);925MVM_DEBUGFS_ADD_FILE_VIF(int_mlo_scan, mvmvif->dbgfs_dir, 0200);926MVM_DEBUGFS_ADD_FILE_VIF(esr_disable_reason, mvmvif->dbgfs_dir, 0600);927928if (vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&929mvmvif == mvm->bf_allowed_vif)930MVM_DEBUGFS_ADD_FILE_VIF(bf_params, mvmvif->dbgfs_dir, 0600);931}932933void iwl_mvm_vif_dbgfs_add_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif)934{935struct dentry *dbgfs_dir = vif->debugfs_dir;936#if defined(__linux__)937struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);938char buf[3 * 3 + 11 + (NL80211_WIPHY_NAME_MAXLEN + 1) +939(7 + IFNAMSIZ + 1) + 6 + 1];940char name[7 + IFNAMSIZ + 1];941#endif942943/* this will happen in monitor mode */944if (!dbgfs_dir)945return;946947#if defined(__linux__)948/*949* Create symlink for convenience pointing to interface specific950* debugfs entries for the driver. For example, under951* /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/952* find953* netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/954*/955snprintf(name, sizeof(name), "%pd", dbgfs_dir);956snprintf(buf, sizeof(buf), "../../../%pd3/iwlmvm", dbgfs_dir);957958mvmvif->dbgfs_slink =959debugfs_create_symlink(name, mvm->debugfs_dir, buf);960#endif961}962963void iwl_mvm_vif_dbgfs_rm_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif)964{965struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);966967debugfs_remove(mvmvif->dbgfs_slink);968mvmvif->dbgfs_slink = NULL;969}970971#define MVM_DEBUGFS_WRITE_LINK_FILE_OPS(name, bufsz) \972_MVM_DEBUGFS_WRITE_FILE_OPS(link_##name, bufsz, \973struct ieee80211_bss_conf)974#define MVM_DEBUGFS_READ_WRITE_LINK_FILE_OPS(name, bufsz) \975_MVM_DEBUGFS_READ_WRITE_FILE_OPS(link_##name, bufsz, \976struct ieee80211_bss_conf)977#define MVM_DEBUGFS_ADD_LINK_FILE(name, parent, mode) \978debugfs_create_file(#name, mode, parent, link_conf, \979&iwl_dbgfs_link_##name##_ops)980981static void iwl_mvm_debugfs_add_link_files(struct ieee80211_vif *vif,982struct ieee80211_bss_conf *link_conf,983struct dentry *mvm_dir)984{985/* Add per-link files here*/986}987988void iwl_mvm_link_add_debugfs(struct ieee80211_hw *hw,989struct ieee80211_vif *vif,990struct ieee80211_bss_conf *link_conf,991struct dentry *dir)992{993struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);994struct iwl_mvm *mvm = mvmvif->mvm;995unsigned int link_id = link_conf->link_id;996struct iwl_mvm_vif_link_info *link_info = mvmvif->link[link_id];997struct dentry *mvm_dir;998999if (WARN_ON(!link_info) || !dir)1000return;10011002if (dir == vif->debugfs_dir) {1003WARN_ON(!mvmvif->dbgfs_dir);1004mvm_dir = mvmvif->dbgfs_dir;1005} else {1006mvm_dir = debugfs_create_dir("iwlmvm", dir);1007if (IS_ERR_OR_NULL(mvm_dir)) {1008IWL_ERR(mvm, "Failed to create debugfs directory under %pd\n",1009dir);1010return;1011}1012}10131014iwl_mvm_debugfs_add_link_files(vif, link_conf, mvm_dir);1015}101610171018