1 /******************************************************************************
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
26 * The full GNU General Public License is included in this distribution
27 * in the file called COPYING.
29 * Contact Information:
30 * Intel Linux Wireless <linuxwifi@intel.com>
31 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
35 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
36 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
37 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
38 * All rights reserved.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
44 * * Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * * Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in
48 * the documentation and/or other materials provided with the
50 * * Neither the name Intel Corporation nor the names of its
51 * contributors may be used to endorse or promote products derived
52 * from this software without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
55 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
56 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
57 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
58 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
60 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
61 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
62 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
64 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66 *****************************************************************************/
68 #include "fw/api/tof.h"
71 static void iwl_dbgfs_update_pm(struct iwl_mvm *mvm,
72 struct ieee80211_vif *vif,
73 enum iwl_dbgfs_pm_mask param, int val)
75 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
76 struct iwl_dbgfs_pm *dbgfs_pm = &mvmvif->dbgfs_pm;
78 dbgfs_pm->mask |= param;
81 case MVM_DEBUGFS_PM_KEEP_ALIVE: {
82 int dtimper = vif->bss_conf.dtim_period ?: 1;
83 int dtimper_msec = dtimper * vif->bss_conf.beacon_int;
85 IWL_DEBUG_POWER(mvm, "debugfs: set keep_alive= %d sec\n", val);
86 if (val * MSEC_PER_SEC < 3 * dtimper_msec)
88 "debugfs: keep alive period (%ld msec) is less than minimum required (%d msec)\n",
89 val * MSEC_PER_SEC, 3 * dtimper_msec);
90 dbgfs_pm->keep_alive_seconds = val;
93 case MVM_DEBUGFS_PM_SKIP_OVER_DTIM:
94 IWL_DEBUG_POWER(mvm, "skip_over_dtim %s\n",
95 val ? "enabled" : "disabled");
96 dbgfs_pm->skip_over_dtim = val;
98 case MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS:
99 IWL_DEBUG_POWER(mvm, "skip_dtim_periods=%d\n", val);
100 dbgfs_pm->skip_dtim_periods = val;
102 case MVM_DEBUGFS_PM_RX_DATA_TIMEOUT:
103 IWL_DEBUG_POWER(mvm, "rx_data_timeout=%d\n", val);
104 dbgfs_pm->rx_data_timeout = val;
106 case MVM_DEBUGFS_PM_TX_DATA_TIMEOUT:
107 IWL_DEBUG_POWER(mvm, "tx_data_timeout=%d\n", val);
108 dbgfs_pm->tx_data_timeout = val;
110 case MVM_DEBUGFS_PM_LPRX_ENA:
111 IWL_DEBUG_POWER(mvm, "lprx %s\n", val ? "enabled" : "disabled");
112 dbgfs_pm->lprx_ena = val;
114 case MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD:
115 IWL_DEBUG_POWER(mvm, "lprx_rssi_threshold=%d\n", val);
116 dbgfs_pm->lprx_rssi_threshold = val;
118 case MVM_DEBUGFS_PM_SNOOZE_ENABLE:
119 IWL_DEBUG_POWER(mvm, "snooze_enable=%d\n", val);
120 dbgfs_pm->snooze_ena = val;
122 case MVM_DEBUGFS_PM_UAPSD_MISBEHAVING:
123 IWL_DEBUG_POWER(mvm, "uapsd_misbehaving_enable=%d\n", val);
124 dbgfs_pm->uapsd_misbehaving = val;
126 case MVM_DEBUGFS_PM_USE_PS_POLL:
127 IWL_DEBUG_POWER(mvm, "use_ps_poll=%d\n", val);
128 dbgfs_pm->use_ps_poll = val;
133 static ssize_t iwl_dbgfs_pm_params_write(struct ieee80211_vif *vif, char *buf,
134 size_t count, loff_t *ppos)
136 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
137 struct iwl_mvm *mvm = mvmvif->mvm;
138 enum iwl_dbgfs_pm_mask param;
141 if (!strncmp("keep_alive=", buf, 11)) {
142 if (sscanf(buf + 11, "%d", &val) != 1)
144 param = MVM_DEBUGFS_PM_KEEP_ALIVE;
145 } else if (!strncmp("skip_over_dtim=", buf, 15)) {
146 if (sscanf(buf + 15, "%d", &val) != 1)
148 param = MVM_DEBUGFS_PM_SKIP_OVER_DTIM;
149 } else if (!strncmp("skip_dtim_periods=", buf, 18)) {
150 if (sscanf(buf + 18, "%d", &val) != 1)
152 param = MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS;
153 } else if (!strncmp("rx_data_timeout=", buf, 16)) {
154 if (sscanf(buf + 16, "%d", &val) != 1)
156 param = MVM_DEBUGFS_PM_RX_DATA_TIMEOUT;
157 } else if (!strncmp("tx_data_timeout=", buf, 16)) {
158 if (sscanf(buf + 16, "%d", &val) != 1)
160 param = MVM_DEBUGFS_PM_TX_DATA_TIMEOUT;
161 } else if (!strncmp("lprx=", buf, 5)) {
162 if (sscanf(buf + 5, "%d", &val) != 1)
164 param = MVM_DEBUGFS_PM_LPRX_ENA;
165 } else if (!strncmp("lprx_rssi_threshold=", buf, 20)) {
166 if (sscanf(buf + 20, "%d", &val) != 1)
168 if (val > POWER_LPRX_RSSI_THRESHOLD_MAX || val <
169 POWER_LPRX_RSSI_THRESHOLD_MIN)
171 param = MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD;
172 } else if (!strncmp("snooze_enable=", buf, 14)) {
173 if (sscanf(buf + 14, "%d", &val) != 1)
175 param = MVM_DEBUGFS_PM_SNOOZE_ENABLE;
176 } else if (!strncmp("uapsd_misbehaving=", buf, 18)) {
177 if (sscanf(buf + 18, "%d", &val) != 1)
179 param = MVM_DEBUGFS_PM_UAPSD_MISBEHAVING;
180 } else if (!strncmp("use_ps_poll=", buf, 12)) {
181 if (sscanf(buf + 12, "%d", &val) != 1)
183 param = MVM_DEBUGFS_PM_USE_PS_POLL;
188 mutex_lock(&mvm->mutex);
189 iwl_dbgfs_update_pm(mvm, vif, param, val);
190 ret = iwl_mvm_power_update_mac(mvm);
191 mutex_unlock(&mvm->mutex);
196 static ssize_t iwl_dbgfs_tx_pwr_lmt_read(struct file *file,
197 char __user *user_buf,
198 size_t count, loff_t *ppos)
200 struct ieee80211_vif *vif = file->private_data;
202 int bufsz = sizeof(buf);
205 pos = scnprintf(buf, bufsz, "bss limit = %d\n",
206 vif->bss_conf.txpower);
208 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
211 static ssize_t iwl_dbgfs_pm_params_read(struct file *file,
212 char __user *user_buf,
213 size_t count, loff_t *ppos)
215 struct ieee80211_vif *vif = file->private_data;
216 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
217 struct iwl_mvm *mvm = mvmvif->mvm;
219 int bufsz = sizeof(buf);
222 pos = iwl_mvm_power_mac_dbgfs_read(mvm, vif, buf, bufsz);
224 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
227 static ssize_t iwl_dbgfs_mac_params_read(struct file *file,
228 char __user *user_buf,
229 size_t count, loff_t *ppos)
231 struct ieee80211_vif *vif = file->private_data;
232 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
233 struct iwl_mvm *mvm = mvmvif->mvm;
235 struct ieee80211_chanctx_conf *chanctx_conf;
237 int bufsz = sizeof(buf);
241 mutex_lock(&mvm->mutex);
243 ap_sta_id = mvmvif->ap_sta_id;
245 switch (ieee80211_vif_type_p2p(vif)) {
246 case NL80211_IFTYPE_ADHOC:
247 pos += scnprintf(buf+pos, bufsz-pos, "type: ibss\n");
249 case NL80211_IFTYPE_STATION:
250 pos += scnprintf(buf+pos, bufsz-pos, "type: bss\n");
252 case NL80211_IFTYPE_AP:
253 pos += scnprintf(buf+pos, bufsz-pos, "type: ap\n");
255 case NL80211_IFTYPE_P2P_CLIENT:
256 pos += scnprintf(buf+pos, bufsz-pos, "type: p2p client\n");
258 case NL80211_IFTYPE_P2P_GO:
259 pos += scnprintf(buf+pos, bufsz-pos, "type: p2p go\n");
261 case NL80211_IFTYPE_P2P_DEVICE:
262 pos += scnprintf(buf+pos, bufsz-pos, "type: p2p dev\n");
268 pos += scnprintf(buf+pos, bufsz-pos, "mac id/color: %d / %d\n",
269 mvmvif->id, mvmvif->color);
270 pos += scnprintf(buf+pos, bufsz-pos, "bssid: %pM\n",
271 vif->bss_conf.bssid);
272 pos += scnprintf(buf+pos, bufsz-pos, "Load: %d\n",
273 mvm->tcm.result.load[mvmvif->id]);
274 pos += scnprintf(buf+pos, bufsz-pos, "QoS:\n");
275 for (i = 0; i < ARRAY_SIZE(mvmvif->queue_params); i++)
276 pos += scnprintf(buf+pos, bufsz-pos,
277 "\t%d: txop:%d - cw_min:%d - cw_max = %d - aifs = %d upasd = %d\n",
278 i, mvmvif->queue_params[i].txop,
279 mvmvif->queue_params[i].cw_min,
280 mvmvif->queue_params[i].cw_max,
281 mvmvif->queue_params[i].aifs,
282 mvmvif->queue_params[i].uapsd);
284 if (vif->type == NL80211_IFTYPE_STATION &&
285 ap_sta_id != IWL_MVM_INVALID_STA) {
286 struct iwl_mvm_sta *mvm_sta;
288 mvm_sta = iwl_mvm_sta_from_staid_protected(mvm, ap_sta_id);
290 pos += scnprintf(buf+pos, bufsz-pos,
291 "ap_sta_id %d - reduced Tx power %d\n",
293 mvm_sta->bt_reduced_txpower);
298 chanctx_conf = rcu_dereference(vif->chanctx_conf);
300 pos += scnprintf(buf+pos, bufsz-pos,
301 "idle rx chains %d, active rx chains: %d\n",
302 chanctx_conf->rx_chains_static,
303 chanctx_conf->rx_chains_dynamic);
306 mutex_unlock(&mvm->mutex);
308 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
311 static void iwl_dbgfs_update_bf(struct ieee80211_vif *vif,
312 enum iwl_dbgfs_bf_mask param, int value)
314 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
315 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
317 dbgfs_bf->mask |= param;
320 case MVM_DEBUGFS_BF_ENERGY_DELTA:
321 dbgfs_bf->bf_energy_delta = value;
323 case MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA:
324 dbgfs_bf->bf_roaming_energy_delta = value;
326 case MVM_DEBUGFS_BF_ROAMING_STATE:
327 dbgfs_bf->bf_roaming_state = value;
329 case MVM_DEBUGFS_BF_TEMP_THRESHOLD:
330 dbgfs_bf->bf_temp_threshold = value;
332 case MVM_DEBUGFS_BF_TEMP_FAST_FILTER:
333 dbgfs_bf->bf_temp_fast_filter = value;
335 case MVM_DEBUGFS_BF_TEMP_SLOW_FILTER:
336 dbgfs_bf->bf_temp_slow_filter = value;
338 case MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER:
339 dbgfs_bf->bf_enable_beacon_filter = value;
341 case MVM_DEBUGFS_BF_DEBUG_FLAG:
342 dbgfs_bf->bf_debug_flag = value;
344 case MVM_DEBUGFS_BF_ESCAPE_TIMER:
345 dbgfs_bf->bf_escape_timer = value;
347 case MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT:
348 dbgfs_bf->ba_enable_beacon_abort = value;
350 case MVM_DEBUGFS_BA_ESCAPE_TIMER:
351 dbgfs_bf->ba_escape_timer = value;
356 static ssize_t iwl_dbgfs_bf_params_write(struct ieee80211_vif *vif, char *buf,
357 size_t count, loff_t *ppos)
359 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
360 struct iwl_mvm *mvm = mvmvif->mvm;
361 enum iwl_dbgfs_bf_mask param;
364 if (!strncmp("bf_energy_delta=", buf, 16)) {
365 if (sscanf(buf+16, "%d", &value) != 1)
367 if (value < IWL_BF_ENERGY_DELTA_MIN ||
368 value > IWL_BF_ENERGY_DELTA_MAX)
370 param = MVM_DEBUGFS_BF_ENERGY_DELTA;
371 } else if (!strncmp("bf_roaming_energy_delta=", buf, 24)) {
372 if (sscanf(buf+24, "%d", &value) != 1)
374 if (value < IWL_BF_ROAMING_ENERGY_DELTA_MIN ||
375 value > IWL_BF_ROAMING_ENERGY_DELTA_MAX)
377 param = MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA;
378 } else if (!strncmp("bf_roaming_state=", buf, 17)) {
379 if (sscanf(buf+17, "%d", &value) != 1)
381 if (value < IWL_BF_ROAMING_STATE_MIN ||
382 value > IWL_BF_ROAMING_STATE_MAX)
384 param = MVM_DEBUGFS_BF_ROAMING_STATE;
385 } else if (!strncmp("bf_temp_threshold=", buf, 18)) {
386 if (sscanf(buf+18, "%d", &value) != 1)
388 if (value < IWL_BF_TEMP_THRESHOLD_MIN ||
389 value > IWL_BF_TEMP_THRESHOLD_MAX)
391 param = MVM_DEBUGFS_BF_TEMP_THRESHOLD;
392 } else if (!strncmp("bf_temp_fast_filter=", buf, 20)) {
393 if (sscanf(buf+20, "%d", &value) != 1)
395 if (value < IWL_BF_TEMP_FAST_FILTER_MIN ||
396 value > IWL_BF_TEMP_FAST_FILTER_MAX)
398 param = MVM_DEBUGFS_BF_TEMP_FAST_FILTER;
399 } else if (!strncmp("bf_temp_slow_filter=", buf, 20)) {
400 if (sscanf(buf+20, "%d", &value) != 1)
402 if (value < IWL_BF_TEMP_SLOW_FILTER_MIN ||
403 value > IWL_BF_TEMP_SLOW_FILTER_MAX)
405 param = MVM_DEBUGFS_BF_TEMP_SLOW_FILTER;
406 } else if (!strncmp("bf_enable_beacon_filter=", buf, 24)) {
407 if (sscanf(buf+24, "%d", &value) != 1)
409 if (value < 0 || value > 1)
411 param = MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER;
412 } else if (!strncmp("bf_debug_flag=", buf, 14)) {
413 if (sscanf(buf+14, "%d", &value) != 1)
415 if (value < 0 || value > 1)
417 param = MVM_DEBUGFS_BF_DEBUG_FLAG;
418 } else if (!strncmp("bf_escape_timer=", buf, 16)) {
419 if (sscanf(buf+16, "%d", &value) != 1)
421 if (value < IWL_BF_ESCAPE_TIMER_MIN ||
422 value > IWL_BF_ESCAPE_TIMER_MAX)
424 param = MVM_DEBUGFS_BF_ESCAPE_TIMER;
425 } else if (!strncmp("ba_escape_timer=", buf, 16)) {
426 if (sscanf(buf+16, "%d", &value) != 1)
428 if (value < IWL_BA_ESCAPE_TIMER_MIN ||
429 value > IWL_BA_ESCAPE_TIMER_MAX)
431 param = MVM_DEBUGFS_BA_ESCAPE_TIMER;
432 } else if (!strncmp("ba_enable_beacon_abort=", buf, 23)) {
433 if (sscanf(buf+23, "%d", &value) != 1)
435 if (value < 0 || value > 1)
437 param = MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT;
442 mutex_lock(&mvm->mutex);
443 iwl_dbgfs_update_bf(vif, param, value);
444 if (param == MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER && !value)
445 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
447 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
448 mutex_unlock(&mvm->mutex);
453 static ssize_t iwl_dbgfs_bf_params_read(struct file *file,
454 char __user *user_buf,
455 size_t count, loff_t *ppos)
457 struct ieee80211_vif *vif = file->private_data;
458 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
461 const size_t bufsz = sizeof(buf);
462 struct iwl_beacon_filter_cmd cmd = {
463 IWL_BF_CMD_CONFIG_DEFAULTS,
464 .bf_enable_beacon_filter =
465 cpu_to_le32(IWL_BF_ENABLE_BEACON_FILTER_DEFAULT),
466 .ba_enable_beacon_abort =
467 cpu_to_le32(IWL_BA_ENABLE_BEACON_ABORT_DEFAULT),
470 iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
471 if (mvmvif->bf_data.bf_enabled)
472 cmd.bf_enable_beacon_filter = cpu_to_le32(1);
474 cmd.bf_enable_beacon_filter = 0;
476 pos += scnprintf(buf+pos, bufsz-pos, "bf_energy_delta = %d\n",
477 le32_to_cpu(cmd.bf_energy_delta));
478 pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_energy_delta = %d\n",
479 le32_to_cpu(cmd.bf_roaming_energy_delta));
480 pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_state = %d\n",
481 le32_to_cpu(cmd.bf_roaming_state));
482 pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_threshold = %d\n",
483 le32_to_cpu(cmd.bf_temp_threshold));
484 pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_fast_filter = %d\n",
485 le32_to_cpu(cmd.bf_temp_fast_filter));
486 pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_slow_filter = %d\n",
487 le32_to_cpu(cmd.bf_temp_slow_filter));
488 pos += scnprintf(buf+pos, bufsz-pos, "bf_enable_beacon_filter = %d\n",
489 le32_to_cpu(cmd.bf_enable_beacon_filter));
490 pos += scnprintf(buf+pos, bufsz-pos, "bf_debug_flag = %d\n",
491 le32_to_cpu(cmd.bf_debug_flag));
492 pos += scnprintf(buf+pos, bufsz-pos, "bf_escape_timer = %d\n",
493 le32_to_cpu(cmd.bf_escape_timer));
494 pos += scnprintf(buf+pos, bufsz-pos, "ba_escape_timer = %d\n",
495 le32_to_cpu(cmd.ba_escape_timer));
496 pos += scnprintf(buf+pos, bufsz-pos, "ba_enable_beacon_abort = %d\n",
497 le32_to_cpu(cmd.ba_enable_beacon_abort));
499 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
502 static inline char *iwl_dbgfs_is_match(char *name, char *buf)
504 int len = strlen(name);
506 return !strncmp(name, buf, len) ? buf + len : NULL;
509 static ssize_t iwl_dbgfs_os_device_timediff_read(struct file *file,
510 char __user *user_buf,
511 size_t count, loff_t *ppos)
513 struct ieee80211_vif *vif = file->private_data;
514 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
515 struct iwl_mvm *mvm = mvmvif->mvm;
520 const size_t bufsz = sizeof(buf);
523 iwl_mvm_get_sync_time(mvm, &curr_gp2, &curr_os);
524 do_div(curr_os, NSEC_PER_USEC);
525 diff = curr_os - curr_gp2;
526 pos += scnprintf(buf + pos, bufsz - pos, "diff=%lld\n", diff);
528 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
531 static ssize_t iwl_dbgfs_tof_enable_write(struct ieee80211_vif *vif,
533 size_t count, loff_t *ppos)
535 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
536 struct iwl_mvm *mvm = mvmvif->mvm;
541 mutex_lock(&mvm->mutex);
543 data = iwl_dbgfs_is_match("tof_disabled=", buf);
545 ret = kstrtou32(data, 10, &value);
547 mvm->tof_data.tof_cfg.tof_disabled = value;
551 data = iwl_dbgfs_is_match("one_sided_disabled=", buf);
553 ret = kstrtou32(data, 10, &value);
555 mvm->tof_data.tof_cfg.one_sided_disabled = value;
559 data = iwl_dbgfs_is_match("is_debug_mode=", buf);
561 ret = kstrtou32(data, 10, &value);
563 mvm->tof_data.tof_cfg.is_debug_mode = value;
567 data = iwl_dbgfs_is_match("is_buf=", buf);
569 ret = kstrtou32(data, 10, &value);
571 mvm->tof_data.tof_cfg.is_buf_required = value;
575 data = iwl_dbgfs_is_match("send_tof_cfg=", buf);
577 ret = kstrtou32(data, 10, &value);
578 if (ret == 0 && value) {
579 ret = iwl_mvm_tof_config_cmd(mvm);
585 mutex_unlock(&mvm->mutex);
590 static ssize_t iwl_dbgfs_tof_enable_read(struct file *file,
591 char __user *user_buf,
592 size_t count, loff_t *ppos)
594 struct ieee80211_vif *vif = file->private_data;
595 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
596 struct iwl_mvm *mvm = mvmvif->mvm;
599 const size_t bufsz = sizeof(buf);
600 struct iwl_tof_config_cmd *cmd;
602 cmd = &mvm->tof_data.tof_cfg;
604 mutex_lock(&mvm->mutex);
606 pos += scnprintf(buf + pos, bufsz - pos, "tof_disabled = %d\n",
608 pos += scnprintf(buf + pos, bufsz - pos, "one_sided_disabled = %d\n",
609 cmd->one_sided_disabled);
610 pos += scnprintf(buf + pos, bufsz - pos, "is_debug_mode = %d\n",
612 pos += scnprintf(buf + pos, bufsz - pos, "is_buf_required = %d\n",
613 cmd->is_buf_required);
615 mutex_unlock(&mvm->mutex);
617 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
620 static ssize_t iwl_dbgfs_tof_responder_params_write(struct ieee80211_vif *vif,
622 size_t count, loff_t *ppos)
624 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
625 struct iwl_mvm *mvm = mvmvif->mvm;
630 mutex_lock(&mvm->mutex);
632 data = iwl_dbgfs_is_match("burst_period=", buf);
634 ret = kstrtou32(data, 10, &value);
636 mvm->tof_data.responder_cfg.burst_period =
641 data = iwl_dbgfs_is_match("min_delta_ftm=", buf);
643 ret = kstrtou32(data, 10, &value);
645 mvm->tof_data.responder_cfg.min_delta_ftm = value;
649 data = iwl_dbgfs_is_match("burst_duration=", buf);
651 ret = kstrtou32(data, 10, &value);
653 mvm->tof_data.responder_cfg.burst_duration = value;
657 data = iwl_dbgfs_is_match("num_of_burst_exp=", buf);
659 ret = kstrtou32(data, 10, &value);
661 mvm->tof_data.responder_cfg.num_of_burst_exp = value;
665 data = iwl_dbgfs_is_match("abort_responder=", buf);
667 ret = kstrtou32(data, 10, &value);
669 mvm->tof_data.responder_cfg.abort_responder = value;
673 data = iwl_dbgfs_is_match("get_ch_est=", buf);
675 ret = kstrtou32(data, 10, &value);
677 mvm->tof_data.responder_cfg.get_ch_est = value;
681 data = iwl_dbgfs_is_match("recv_sta_req_params=", buf);
683 ret = kstrtou32(data, 10, &value);
685 mvm->tof_data.responder_cfg.recv_sta_req_params = value;
689 data = iwl_dbgfs_is_match("channel_num=", buf);
691 ret = kstrtou32(data, 10, &value);
693 mvm->tof_data.responder_cfg.channel_num = value;
697 data = iwl_dbgfs_is_match("bandwidth=", buf);
699 ret = kstrtou32(data, 10, &value);
701 mvm->tof_data.responder_cfg.bandwidth = value;
705 data = iwl_dbgfs_is_match("rate=", buf);
707 ret = kstrtou32(data, 10, &value);
709 mvm->tof_data.responder_cfg.rate = value;
713 data = iwl_dbgfs_is_match("bssid=", buf);
715 u8 *mac = mvm->tof_data.responder_cfg.bssid;
717 if (!mac_pton(data, mac)) {
723 data = iwl_dbgfs_is_match("tsf_timer_offset_msecs=", buf);
725 ret = kstrtou32(data, 10, &value);
727 mvm->tof_data.responder_cfg.tsf_timer_offset_msecs =
732 data = iwl_dbgfs_is_match("toa_offset=", buf);
734 ret = kstrtou32(data, 10, &value);
736 mvm->tof_data.responder_cfg.toa_offset =
741 data = iwl_dbgfs_is_match("center_freq=", buf);
743 struct iwl_tof_responder_config_cmd *cmd =
744 &mvm->tof_data.responder_cfg;
746 ret = kstrtou32(data, 10, &value);
747 if (ret == 0 && value) {
748 enum nl80211_band band = (cmd->channel_num <= 14) ?
751 struct ieee80211_channel chn = {
753 .center_freq = ieee80211_channel_to_frequency(
754 cmd->channel_num, band),
756 struct cfg80211_chan_def chandef = {
759 ieee80211_channel_to_frequency(value,
763 cmd->ctrl_ch_position = iwl_mvm_get_ctrl_pos(&chandef);
768 data = iwl_dbgfs_is_match("ftm_per_burst=", buf);
770 ret = kstrtou32(data, 10, &value);
772 mvm->tof_data.responder_cfg.ftm_per_burst = value;
776 data = iwl_dbgfs_is_match("ftm_resp_ts_avail=", buf);
778 ret = kstrtou32(data, 10, &value);
780 mvm->tof_data.responder_cfg.ftm_resp_ts_avail = value;
784 data = iwl_dbgfs_is_match("asap_mode=", buf);
786 ret = kstrtou32(data, 10, &value);
788 mvm->tof_data.responder_cfg.asap_mode = value;
792 data = iwl_dbgfs_is_match("send_responder_cfg=", buf);
794 ret = kstrtou32(data, 10, &value);
795 if (ret == 0 && value) {
796 ret = iwl_mvm_tof_responder_cmd(mvm, vif);
802 mutex_unlock(&mvm->mutex);
807 static ssize_t iwl_dbgfs_tof_responder_params_read(struct file *file,
808 char __user *user_buf,
809 size_t count, loff_t *ppos)
811 struct ieee80211_vif *vif = file->private_data;
812 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
813 struct iwl_mvm *mvm = mvmvif->mvm;
816 const size_t bufsz = sizeof(buf);
817 struct iwl_tof_responder_config_cmd *cmd;
819 cmd = &mvm->tof_data.responder_cfg;
821 mutex_lock(&mvm->mutex);
823 pos += scnprintf(buf + pos, bufsz - pos, "burst_period = %d\n",
824 le16_to_cpu(cmd->burst_period));
825 pos += scnprintf(buf + pos, bufsz - pos, "burst_duration = %d\n",
826 cmd->burst_duration);
827 pos += scnprintf(buf + pos, bufsz - pos, "bandwidth = %d\n",
829 pos += scnprintf(buf + pos, bufsz - pos, "channel_num = %d\n",
831 pos += scnprintf(buf + pos, bufsz - pos, "ctrl_ch_position = 0x%x\n",
832 cmd->ctrl_ch_position);
833 pos += scnprintf(buf + pos, bufsz - pos, "bssid = %pM\n",
835 pos += scnprintf(buf + pos, bufsz - pos, "min_delta_ftm = %d\n",
837 pos += scnprintf(buf + pos, bufsz - pos, "num_of_burst_exp = %d\n",
838 cmd->num_of_burst_exp);
839 pos += scnprintf(buf + pos, bufsz - pos, "rate = %d\n", cmd->rate);
840 pos += scnprintf(buf + pos, bufsz - pos, "abort_responder = %d\n",
841 cmd->abort_responder);
842 pos += scnprintf(buf + pos, bufsz - pos, "get_ch_est = %d\n",
844 pos += scnprintf(buf + pos, bufsz - pos, "recv_sta_req_params = %d\n",
845 cmd->recv_sta_req_params);
846 pos += scnprintf(buf + pos, bufsz - pos, "ftm_per_burst = %d\n",
848 pos += scnprintf(buf + pos, bufsz - pos, "ftm_resp_ts_avail = %d\n",
849 cmd->ftm_resp_ts_avail);
850 pos += scnprintf(buf + pos, bufsz - pos, "asap_mode = %d\n",
852 pos += scnprintf(buf + pos, bufsz - pos,
853 "tsf_timer_offset_msecs = %d\n",
854 le16_to_cpu(cmd->tsf_timer_offset_msecs));
855 pos += scnprintf(buf + pos, bufsz - pos, "toa_offset = %d\n",
856 le16_to_cpu(cmd->toa_offset));
858 mutex_unlock(&mvm->mutex);
860 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
863 static ssize_t iwl_dbgfs_tof_range_request_write(struct ieee80211_vif *vif,
864 char *buf, size_t count,
867 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
868 struct iwl_mvm *mvm = mvmvif->mvm;
873 mutex_lock(&mvm->mutex);
875 data = iwl_dbgfs_is_match("request_id=", buf);
877 ret = kstrtou32(data, 10, &value);
879 mvm->tof_data.range_req.request_id = value;
883 data = iwl_dbgfs_is_match("initiator=", buf);
885 ret = kstrtou32(data, 10, &value);
887 mvm->tof_data.range_req.initiator = value;
891 data = iwl_dbgfs_is_match("one_sided_los_disable=", buf);
893 ret = kstrtou32(data, 10, &value);
895 mvm->tof_data.range_req.one_sided_los_disable = value;
899 data = iwl_dbgfs_is_match("req_timeout=", buf);
901 ret = kstrtou32(data, 10, &value);
903 mvm->tof_data.range_req.req_timeout = value;
907 data = iwl_dbgfs_is_match("report_policy=", buf);
909 ret = kstrtou32(data, 10, &value);
911 mvm->tof_data.range_req.report_policy = value;
915 data = iwl_dbgfs_is_match("macaddr_random=", buf);
917 ret = kstrtou32(data, 10, &value);
919 mvm->tof_data.range_req.macaddr_random = value;
923 data = iwl_dbgfs_is_match("num_of_ap=", buf);
925 ret = kstrtou32(data, 10, &value);
927 mvm->tof_data.range_req.num_of_ap = value;
931 data = iwl_dbgfs_is_match("macaddr_template=", buf);
935 if (!mac_pton(data, mac)) {
939 memcpy(mvm->tof_data.range_req.macaddr_template, mac, ETH_ALEN);
943 data = iwl_dbgfs_is_match("macaddr_mask=", buf);
947 if (!mac_pton(data, mac)) {
951 memcpy(mvm->tof_data.range_req.macaddr_mask, mac, ETH_ALEN);
955 data = iwl_dbgfs_is_match("ap=", buf);
957 struct iwl_tof_range_req_ap_entry ap = {};
958 int size = sizeof(struct iwl_tof_range_req_ap_entry);
963 if (sscanf(data, "%u %hhd %hhd %hhd"
964 "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"
967 "%hhx %hhd %hhd %hhd",
968 &i, &ap.channel_num, &ap.bandwidth,
969 &ap.ctrl_ch_position,
970 mac, mac + 1, mac + 2, mac + 3, mac + 4, mac + 5,
971 &ap.measure_type, &ap.num_of_bursts,
973 &ap.samples_per_burst, &ap.retries_per_sample,
974 &ap.tsf_delta, &ap.location_req, &ap.asap_mode,
975 &ap.enable_dyn_ack, &ap.rssi) != 20) {
979 if (i >= IWL_MVM_TOF_MAX_APS) {
980 IWL_ERR(mvm, "Invalid AP index %d\n", i);
985 ap.burst_period = cpu_to_le16(burst_period);
987 memcpy(&mvm->tof_data.range_req.ap[i], &ap, size);
991 data = iwl_dbgfs_is_match("send_range_request=", buf);
993 ret = kstrtou32(data, 10, &value);
994 if (ret == 0 && value)
995 ret = iwl_mvm_tof_range_request_cmd(mvm, vif);
1001 mutex_unlock(&mvm->mutex);
1002 return ret ?: count;
1005 static ssize_t iwl_dbgfs_tof_range_request_read(struct file *file,
1006 char __user *user_buf,
1007 size_t count, loff_t *ppos)
1009 struct ieee80211_vif *vif = file->private_data;
1010 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1011 struct iwl_mvm *mvm = mvmvif->mvm;
1014 const size_t bufsz = sizeof(buf);
1015 struct iwl_tof_range_req_cmd *cmd;
1018 cmd = &mvm->tof_data.range_req;
1020 mutex_lock(&mvm->mutex);
1022 pos += scnprintf(buf + pos, bufsz - pos, "request_id= %d\n",
1024 pos += scnprintf(buf + pos, bufsz - pos, "initiator= %d\n",
1026 pos += scnprintf(buf + pos, bufsz - pos, "one_sided_los_disable = %d\n",
1027 cmd->one_sided_los_disable);
1028 pos += scnprintf(buf + pos, bufsz - pos, "req_timeout= %d\n",
1030 pos += scnprintf(buf + pos, bufsz - pos, "report_policy= %d\n",
1031 cmd->report_policy);
1032 pos += scnprintf(buf + pos, bufsz - pos, "macaddr_random= %d\n",
1033 cmd->macaddr_random);
1034 pos += scnprintf(buf + pos, bufsz - pos, "macaddr_template= %pM\n",
1035 cmd->macaddr_template);
1036 pos += scnprintf(buf + pos, bufsz - pos, "macaddr_mask= %pM\n",
1038 pos += scnprintf(buf + pos, bufsz - pos, "num_of_ap= %d\n",
1040 for (i = 0; i < cmd->num_of_ap; i++) {
1041 struct iwl_tof_range_req_ap_entry *ap = &cmd->ap[i];
1043 pos += scnprintf(buf + pos, bufsz - pos,
1044 "ap %.2d: channel_num=%hhd bw=%hhd"
1045 " control=%hhd bssid=%pM type=%hhd"
1046 " num_of_bursts=%hhd burst_period=%hd ftm=%hhd"
1047 " retries=%hhd tsf_delta=%d"
1048 " tsf_delta_direction=%hhd location_req=0x%hhx "
1049 " asap=%hhd enable=%hhd rssi=%hhd\n",
1050 i, ap->channel_num, ap->bandwidth,
1051 ap->ctrl_ch_position, ap->bssid,
1052 ap->measure_type, ap->num_of_bursts,
1053 ap->burst_period, ap->samples_per_burst,
1054 ap->retries_per_sample, ap->tsf_delta,
1055 ap->tsf_delta_direction,
1056 ap->location_req, ap->asap_mode,
1057 ap->enable_dyn_ack, ap->rssi);
1060 mutex_unlock(&mvm->mutex);
1062 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1065 static ssize_t iwl_dbgfs_tof_range_req_ext_write(struct ieee80211_vif *vif,
1067 size_t count, loff_t *ppos)
1069 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1070 struct iwl_mvm *mvm = mvmvif->mvm;
1075 mutex_lock(&mvm->mutex);
1077 data = iwl_dbgfs_is_match("tsf_timer_offset_msec=", buf);
1079 ret = kstrtou32(data, 10, &value);
1081 mvm->tof_data.range_req_ext.tsf_timer_offset_msec =
1086 data = iwl_dbgfs_is_match("min_delta_ftm=", buf);
1088 ret = kstrtou32(data, 10, &value);
1090 mvm->tof_data.range_req_ext.min_delta_ftm = value;
1094 data = iwl_dbgfs_is_match("ftm_format_and_bw20M=", buf);
1096 ret = kstrtou32(data, 10, &value);
1098 mvm->tof_data.range_req_ext.ftm_format_and_bw20M =
1103 data = iwl_dbgfs_is_match("ftm_format_and_bw40M=", buf);
1105 ret = kstrtou32(data, 10, &value);
1107 mvm->tof_data.range_req_ext.ftm_format_and_bw40M =
1112 data = iwl_dbgfs_is_match("ftm_format_and_bw80M=", buf);
1114 ret = kstrtou32(data, 10, &value);
1116 mvm->tof_data.range_req_ext.ftm_format_and_bw80M =
1121 data = iwl_dbgfs_is_match("send_range_req_ext=", buf);
1123 ret = kstrtou32(data, 10, &value);
1124 if (ret == 0 && value)
1125 ret = iwl_mvm_tof_range_request_ext_cmd(mvm, vif);
1131 mutex_unlock(&mvm->mutex);
1132 return ret ?: count;
1135 static ssize_t iwl_dbgfs_tof_range_req_ext_read(struct file *file,
1136 char __user *user_buf,
1137 size_t count, loff_t *ppos)
1139 struct ieee80211_vif *vif = file->private_data;
1140 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1141 struct iwl_mvm *mvm = mvmvif->mvm;
1144 const size_t bufsz = sizeof(buf);
1145 struct iwl_tof_range_req_ext_cmd *cmd;
1147 cmd = &mvm->tof_data.range_req_ext;
1149 mutex_lock(&mvm->mutex);
1151 pos += scnprintf(buf + pos, bufsz - pos,
1152 "tsf_timer_offset_msec = %hd\n",
1153 cmd->tsf_timer_offset_msec);
1154 pos += scnprintf(buf + pos, bufsz - pos, "min_delta_ftm = %hhd\n",
1155 cmd->min_delta_ftm);
1156 pos += scnprintf(buf + pos, bufsz - pos,
1157 "ftm_format_and_bw20M = %hhd\n",
1158 cmd->ftm_format_and_bw20M);
1159 pos += scnprintf(buf + pos, bufsz - pos,
1160 "ftm_format_and_bw40M = %hhd\n",
1161 cmd->ftm_format_and_bw40M);
1162 pos += scnprintf(buf + pos, bufsz - pos,
1163 "ftm_format_and_bw80M = %hhd\n",
1164 cmd->ftm_format_and_bw80M);
1166 mutex_unlock(&mvm->mutex);
1167 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1170 static ssize_t iwl_dbgfs_tof_range_abort_write(struct ieee80211_vif *vif,
1172 size_t count, loff_t *ppos)
1174 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1175 struct iwl_mvm *mvm = mvmvif->mvm;
1177 int abort_id, ret = 0;
1180 mutex_lock(&mvm->mutex);
1182 data = iwl_dbgfs_is_match("abort_id=", buf);
1184 ret = kstrtou32(data, 10, &value);
1186 mvm->tof_data.last_abort_id = value;
1190 data = iwl_dbgfs_is_match("send_range_abort=", buf);
1192 ret = kstrtou32(data, 10, &value);
1193 if (ret == 0 && value) {
1194 abort_id = mvm->tof_data.last_abort_id;
1195 ret = iwl_mvm_tof_range_abort_cmd(mvm, abort_id);
1201 mutex_unlock(&mvm->mutex);
1202 return ret ?: count;
1205 static ssize_t iwl_dbgfs_tof_range_abort_read(struct file *file,
1206 char __user *user_buf,
1207 size_t count, loff_t *ppos)
1209 struct ieee80211_vif *vif = file->private_data;
1210 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1211 struct iwl_mvm *mvm = mvmvif->mvm;
1214 const size_t bufsz = sizeof(buf);
1217 mutex_lock(&mvm->mutex);
1218 last_abort_id = mvm->tof_data.last_abort_id;
1219 mutex_unlock(&mvm->mutex);
1221 pos += scnprintf(buf + pos, bufsz - pos, "last_abort_id = %d\n",
1223 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1226 static ssize_t iwl_dbgfs_tof_range_response_read(struct file *file,
1227 char __user *user_buf,
1228 size_t count, loff_t *ppos)
1230 struct ieee80211_vif *vif = file->private_data;
1231 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1232 struct iwl_mvm *mvm = mvmvif->mvm;
1235 const size_t bufsz = sizeof(struct iwl_tof_range_rsp_ntfy) + 256;
1236 struct iwl_tof_range_rsp_ntfy *cmd;
1239 buf = kzalloc(bufsz, GFP_KERNEL);
1243 mutex_lock(&mvm->mutex);
1244 cmd = &mvm->tof_data.range_resp;
1246 pos += scnprintf(buf + pos, bufsz - pos, "request_id = %d\n",
1248 pos += scnprintf(buf + pos, bufsz - pos, "status = %d\n",
1249 cmd->request_status);
1250 pos += scnprintf(buf + pos, bufsz - pos, "last_in_batch = %d\n",
1251 cmd->last_in_batch);
1252 pos += scnprintf(buf + pos, bufsz - pos, "num_of_aps = %d\n",
1254 for (i = 0; i < cmd->num_of_aps; i++) {
1255 struct iwl_tof_range_rsp_ap_entry_ntfy *ap = &cmd->ap[i];
1257 pos += scnprintf(buf + pos, bufsz - pos,
1258 "ap %.2d: bssid=%pM status=%hhd bw=%hhd"
1259 " rtt=%d rtt_var=%d rtt_spread=%d"
1260 " rssi=%hhd rssi_spread=%hhd"
1261 " range=%d range_var=%d"
1263 i, ap->bssid, ap->measure_status,
1265 ap->rtt, ap->rtt_variance, ap->rtt_spread,
1266 ap->rssi, ap->rssi_spread, ap->range,
1267 ap->range_variance, ap->timestamp);
1269 mutex_unlock(&mvm->mutex);
1271 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1276 static ssize_t iwl_dbgfs_low_latency_write(struct ieee80211_vif *vif, char *buf,
1277 size_t count, loff_t *ppos)
1279 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1280 struct iwl_mvm *mvm = mvmvif->mvm;
1284 ret = kstrtou8(buf, 0, &value);
1290 mutex_lock(&mvm->mutex);
1291 iwl_mvm_update_low_latency(mvm, vif, value, LOW_LATENCY_DEBUGFS);
1292 mutex_unlock(&mvm->mutex);
1297 static ssize_t iwl_dbgfs_low_latency_read(struct file *file,
1298 char __user *user_buf,
1299 size_t count, loff_t *ppos)
1301 struct ieee80211_vif *vif = file->private_data;
1302 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1306 len = scnprintf(buf, sizeof(buf) - 1,
1307 "traffic=%d\ndbgfs=%d\nvcmd=%d\n",
1308 !!(mvmvif->low_latency & LOW_LATENCY_TRAFFIC),
1309 !!(mvmvif->low_latency & LOW_LATENCY_DEBUGFS),
1310 !!(mvmvif->low_latency & LOW_LATENCY_VCMD));
1311 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1314 static ssize_t iwl_dbgfs_uapsd_misbehaving_read(struct file *file,
1315 char __user *user_buf,
1316 size_t count, loff_t *ppos)
1318 struct ieee80211_vif *vif = file->private_data;
1319 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1323 len = sprintf(buf, "%pM\n", mvmvif->uapsd_misbehaving_bssid);
1324 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1327 static ssize_t iwl_dbgfs_uapsd_misbehaving_write(struct ieee80211_vif *vif,
1328 char *buf, size_t count,
1331 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1332 struct iwl_mvm *mvm = mvmvif->mvm;
1335 mutex_lock(&mvm->mutex);
1336 ret = mac_pton(buf, mvmvif->uapsd_misbehaving_bssid);
1337 mutex_unlock(&mvm->mutex);
1339 return ret ? count : -EINVAL;
1342 static ssize_t iwl_dbgfs_rx_phyinfo_write(struct ieee80211_vif *vif, char *buf,
1343 size_t count, loff_t *ppos)
1345 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1346 struct iwl_mvm *mvm = mvmvif->mvm;
1347 struct ieee80211_chanctx_conf *chanctx_conf;
1348 struct iwl_mvm_phy_ctxt *phy_ctxt;
1352 ret = kstrtou16(buf, 0, &value);
1356 mutex_lock(&mvm->mutex);
1359 chanctx_conf = rcu_dereference(vif->chanctx_conf);
1360 /* make sure the channel context is assigned */
1361 if (!chanctx_conf) {
1363 mutex_unlock(&mvm->mutex);
1367 phy_ctxt = &mvm->phy_ctxts[*(u16 *)chanctx_conf->drv_priv];
1370 mvm->dbgfs_rx_phyinfo = value;
1372 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chanctx_conf->min_def,
1373 chanctx_conf->rx_chains_static,
1374 chanctx_conf->rx_chains_dynamic);
1375 mutex_unlock(&mvm->mutex);
1377 return ret ?: count;
1380 static ssize_t iwl_dbgfs_rx_phyinfo_read(struct file *file,
1381 char __user *user_buf,
1382 size_t count, loff_t *ppos)
1384 struct ieee80211_vif *vif = file->private_data;
1385 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1389 len = scnprintf(buf, sizeof(buf), "0x%04x\n",
1390 mvmvif->mvm->dbgfs_rx_phyinfo);
1392 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1395 static void iwl_dbgfs_quota_check(void *data, u8 *mac,
1396 struct ieee80211_vif *vif)
1398 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1401 if (mvmvif->dbgfs_quota_min)
1405 static ssize_t iwl_dbgfs_quota_min_write(struct ieee80211_vif *vif, char *buf,
1406 size_t count, loff_t *ppos)
1408 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1409 struct iwl_mvm *mvm = mvmvif->mvm;
1413 ret = kstrtou16(buf, 0, &value);
1420 mutex_lock(&mvm->mutex);
1422 mvmvif->dbgfs_quota_min = 0;
1423 ieee80211_iterate_interfaces(mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1424 iwl_dbgfs_quota_check, &ret);
1426 mvmvif->dbgfs_quota_min = value;
1427 iwl_mvm_update_quotas(mvm, false, NULL);
1429 mutex_unlock(&mvm->mutex);
1431 return ret ?: count;
1434 static ssize_t iwl_dbgfs_quota_min_read(struct file *file,
1435 char __user *user_buf,
1436 size_t count, loff_t *ppos)
1438 struct ieee80211_vif *vif = file->private_data;
1439 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1443 len = scnprintf(buf, sizeof(buf), "%d\n", mvmvif->dbgfs_quota_min);
1445 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1448 static const char * const chanwidths[] = {
1449 [NL80211_CHAN_WIDTH_20_NOHT] = "noht",
1450 [NL80211_CHAN_WIDTH_20] = "ht20",
1451 [NL80211_CHAN_WIDTH_40] = "ht40",
1452 [NL80211_CHAN_WIDTH_80] = "vht80",
1453 [NL80211_CHAN_WIDTH_80P80] = "vht80p80",
1454 [NL80211_CHAN_WIDTH_160] = "vht160",
1457 #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
1458 _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
1459 #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
1460 _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
1461 #define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \
1462 if (!debugfs_create_file(#name, mode, parent, vif, \
1463 &iwl_dbgfs_##name##_ops)) \
1467 MVM_DEBUGFS_READ_FILE_OPS(mac_params);
1468 MVM_DEBUGFS_READ_FILE_OPS(tx_pwr_lmt);
1469 MVM_DEBUGFS_READ_WRITE_FILE_OPS(pm_params, 32);
1470 MVM_DEBUGFS_READ_WRITE_FILE_OPS(bf_params, 256);
1471 MVM_DEBUGFS_READ_WRITE_FILE_OPS(low_latency, 10);
1472 MVM_DEBUGFS_READ_WRITE_FILE_OPS(uapsd_misbehaving, 20);
1473 MVM_DEBUGFS_READ_WRITE_FILE_OPS(rx_phyinfo, 10);
1474 MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_enable, 32);
1475 MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_request, 512);
1476 MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_req_ext, 32);
1477 MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_abort, 32);
1478 MVM_DEBUGFS_READ_FILE_OPS(tof_range_response);
1479 MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_responder_params, 32);
1480 MVM_DEBUGFS_READ_WRITE_FILE_OPS(quota_min, 32);
1481 MVM_DEBUGFS_READ_FILE_OPS(os_device_timediff);
1484 void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1486 struct dentry *dbgfs_dir = vif->debugfs_dir;
1487 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1491 * Check if debugfs directory already exist before creating it.
1492 * This may happen when, for example, resetting hw or suspend-resume
1494 if (!dbgfs_dir || mvmvif->dbgfs_dir)
1497 mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir);
1499 if (!mvmvif->dbgfs_dir) {
1500 IWL_ERR(mvm, "Failed to create debugfs directory under %pd\n",
1505 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM &&
1506 ((vif->type == NL80211_IFTYPE_STATION && !vif->p2p) ||
1507 (vif->type == NL80211_IFTYPE_STATION && vif->p2p)))
1508 MVM_DEBUGFS_ADD_FILE_VIF(pm_params, mvmvif->dbgfs_dir, 0600);
1510 MVM_DEBUGFS_ADD_FILE_VIF(tx_pwr_lmt, mvmvif->dbgfs_dir, 0400);
1511 MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir, 0400);
1512 MVM_DEBUGFS_ADD_FILE_VIF(low_latency, mvmvif->dbgfs_dir, 0600);
1513 MVM_DEBUGFS_ADD_FILE_VIF(uapsd_misbehaving, mvmvif->dbgfs_dir, 0600);
1514 MVM_DEBUGFS_ADD_FILE_VIF(rx_phyinfo, mvmvif->dbgfs_dir, 0600);
1515 MVM_DEBUGFS_ADD_FILE_VIF(quota_min, mvmvif->dbgfs_dir, 0600);
1516 MVM_DEBUGFS_ADD_FILE_VIF(os_device_timediff, mvmvif->dbgfs_dir, 0400);
1518 if (vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
1519 mvmvif == mvm->bf_allowed_vif)
1520 MVM_DEBUGFS_ADD_FILE_VIF(bf_params, mvmvif->dbgfs_dir, 0600);
1522 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TOF_SUPPORT) &&
1523 !vif->p2p && (vif->type != NL80211_IFTYPE_P2P_DEVICE)) {
1524 if (IWL_MVM_TOF_IS_RESPONDER && vif->type == NL80211_IFTYPE_AP)
1525 MVM_DEBUGFS_ADD_FILE_VIF(tof_responder_params,
1526 mvmvif->dbgfs_dir, 0600);
1528 MVM_DEBUGFS_ADD_FILE_VIF(tof_range_request, mvmvif->dbgfs_dir,
1530 MVM_DEBUGFS_ADD_FILE_VIF(tof_range_req_ext, mvmvif->dbgfs_dir,
1532 MVM_DEBUGFS_ADD_FILE_VIF(tof_enable, mvmvif->dbgfs_dir,
1534 MVM_DEBUGFS_ADD_FILE_VIF(tof_range_abort, mvmvif->dbgfs_dir,
1536 MVM_DEBUGFS_ADD_FILE_VIF(tof_range_response, mvmvif->dbgfs_dir,
1541 * Create symlink for convenience pointing to interface specific
1542 * debugfs entries for the driver. For example, under
1543 * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/
1545 * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/
1547 snprintf(buf, 100, "../../../%pd3/%pd",
1551 mvmvif->dbgfs_slink = debugfs_create_symlink(dbgfs_dir->d_name.name,
1552 mvm->debugfs_dir, buf);
1553 if (!mvmvif->dbgfs_slink)
1554 IWL_ERR(mvm, "Can't create debugfs symbolic link under %pd\n",
1558 IWL_ERR(mvm, "Can't create debugfs entity\n");
1561 void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1563 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1565 debugfs_remove(mvmvif->dbgfs_slink);
1566 mvmvif->dbgfs_slink = NULL;
1568 debugfs_remove_recursive(mvmvif->dbgfs_dir);
1569 mvmvif->dbgfs_dir = NULL;