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 mutex_lock(&mvm->mutex);
524 iwl_mvm_get_sync_time(mvm, &curr_gp2, &curr_os);
525 mutex_unlock(&mvm->mutex);
527 do_div(curr_os, NSEC_PER_USEC);
528 diff = curr_os - curr_gp2;
529 pos += scnprintf(buf + pos, bufsz - pos, "diff=%lld\n", diff);
531 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
534 static ssize_t iwl_dbgfs_tof_enable_write(struct ieee80211_vif *vif,
536 size_t count, loff_t *ppos)
538 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
539 struct iwl_mvm *mvm = mvmvif->mvm;
544 mutex_lock(&mvm->mutex);
546 data = iwl_dbgfs_is_match("tof_disabled=", buf);
548 ret = kstrtou32(data, 10, &value);
550 mvm->tof_data.tof_cfg.tof_disabled = value;
554 data = iwl_dbgfs_is_match("one_sided_disabled=", buf);
556 ret = kstrtou32(data, 10, &value);
558 mvm->tof_data.tof_cfg.one_sided_disabled = value;
562 data = iwl_dbgfs_is_match("is_debug_mode=", buf);
564 ret = kstrtou32(data, 10, &value);
566 mvm->tof_data.tof_cfg.is_debug_mode = value;
570 data = iwl_dbgfs_is_match("is_buf=", buf);
572 ret = kstrtou32(data, 10, &value);
574 mvm->tof_data.tof_cfg.is_buf_required = value;
578 data = iwl_dbgfs_is_match("send_tof_cfg=", buf);
580 ret = kstrtou32(data, 10, &value);
581 if (ret == 0 && value) {
582 ret = iwl_mvm_tof_config_cmd(mvm);
588 mutex_unlock(&mvm->mutex);
593 static ssize_t iwl_dbgfs_tof_enable_read(struct file *file,
594 char __user *user_buf,
595 size_t count, loff_t *ppos)
597 struct ieee80211_vif *vif = file->private_data;
598 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
599 struct iwl_mvm *mvm = mvmvif->mvm;
602 const size_t bufsz = sizeof(buf);
603 struct iwl_tof_config_cmd *cmd;
605 cmd = &mvm->tof_data.tof_cfg;
607 mutex_lock(&mvm->mutex);
609 pos += scnprintf(buf + pos, bufsz - pos, "tof_disabled = %d\n",
611 pos += scnprintf(buf + pos, bufsz - pos, "one_sided_disabled = %d\n",
612 cmd->one_sided_disabled);
613 pos += scnprintf(buf + pos, bufsz - pos, "is_debug_mode = %d\n",
615 pos += scnprintf(buf + pos, bufsz - pos, "is_buf_required = %d\n",
616 cmd->is_buf_required);
618 mutex_unlock(&mvm->mutex);
620 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
623 static ssize_t iwl_dbgfs_tof_responder_params_write(struct ieee80211_vif *vif,
625 size_t count, loff_t *ppos)
627 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
628 struct iwl_mvm *mvm = mvmvif->mvm;
633 mutex_lock(&mvm->mutex);
635 data = iwl_dbgfs_is_match("burst_period=", buf);
637 ret = kstrtou32(data, 10, &value);
639 mvm->tof_data.responder_cfg.burst_period =
644 data = iwl_dbgfs_is_match("min_delta_ftm=", buf);
646 ret = kstrtou32(data, 10, &value);
648 mvm->tof_data.responder_cfg.min_delta_ftm = value;
652 data = iwl_dbgfs_is_match("burst_duration=", buf);
654 ret = kstrtou32(data, 10, &value);
656 mvm->tof_data.responder_cfg.burst_duration = value;
660 data = iwl_dbgfs_is_match("num_of_burst_exp=", buf);
662 ret = kstrtou32(data, 10, &value);
664 mvm->tof_data.responder_cfg.num_of_burst_exp = value;
668 data = iwl_dbgfs_is_match("abort_responder=", buf);
670 ret = kstrtou32(data, 10, &value);
672 mvm->tof_data.responder_cfg.abort_responder = value;
676 data = iwl_dbgfs_is_match("get_ch_est=", buf);
678 ret = kstrtou32(data, 10, &value);
680 mvm->tof_data.responder_cfg.get_ch_est = value;
684 data = iwl_dbgfs_is_match("recv_sta_req_params=", buf);
686 ret = kstrtou32(data, 10, &value);
688 mvm->tof_data.responder_cfg.recv_sta_req_params = value;
692 data = iwl_dbgfs_is_match("channel_num=", buf);
694 ret = kstrtou32(data, 10, &value);
696 mvm->tof_data.responder_cfg.channel_num = value;
700 data = iwl_dbgfs_is_match("bandwidth=", buf);
702 ret = kstrtou32(data, 10, &value);
704 mvm->tof_data.responder_cfg.bandwidth = value;
708 data = iwl_dbgfs_is_match("rate=", buf);
710 ret = kstrtou32(data, 10, &value);
712 mvm->tof_data.responder_cfg.rate = value;
716 data = iwl_dbgfs_is_match("bssid=", buf);
718 u8 *mac = mvm->tof_data.responder_cfg.bssid;
720 if (!mac_pton(data, mac)) {
726 data = iwl_dbgfs_is_match("tsf_timer_offset_msecs=", buf);
728 ret = kstrtou32(data, 10, &value);
730 mvm->tof_data.responder_cfg.tsf_timer_offset_msecs =
735 data = iwl_dbgfs_is_match("toa_offset=", buf);
737 ret = kstrtou32(data, 10, &value);
739 mvm->tof_data.responder_cfg.toa_offset =
744 data = iwl_dbgfs_is_match("center_freq=", buf);
746 struct iwl_tof_responder_config_cmd *cmd =
747 &mvm->tof_data.responder_cfg;
749 ret = kstrtou32(data, 10, &value);
750 if (ret == 0 && value) {
751 enum nl80211_band band = (cmd->channel_num <= 14) ?
754 struct ieee80211_channel chn = {
756 .center_freq = ieee80211_channel_to_frequency(
757 cmd->channel_num, band),
759 struct cfg80211_chan_def chandef = {
762 ieee80211_channel_to_frequency(value,
766 cmd->ctrl_ch_position = iwl_mvm_get_ctrl_pos(&chandef);
771 data = iwl_dbgfs_is_match("ftm_per_burst=", buf);
773 ret = kstrtou32(data, 10, &value);
775 mvm->tof_data.responder_cfg.ftm_per_burst = value;
779 data = iwl_dbgfs_is_match("ftm_resp_ts_avail=", buf);
781 ret = kstrtou32(data, 10, &value);
783 mvm->tof_data.responder_cfg.ftm_resp_ts_avail = value;
787 data = iwl_dbgfs_is_match("asap_mode=", buf);
789 ret = kstrtou32(data, 10, &value);
791 mvm->tof_data.responder_cfg.asap_mode = value;
795 data = iwl_dbgfs_is_match("send_responder_cfg=", buf);
797 ret = kstrtou32(data, 10, &value);
798 if (ret == 0 && value) {
799 ret = iwl_mvm_tof_responder_cmd(mvm, vif);
805 mutex_unlock(&mvm->mutex);
810 static ssize_t iwl_dbgfs_tof_responder_params_read(struct file *file,
811 char __user *user_buf,
812 size_t count, loff_t *ppos)
814 struct ieee80211_vif *vif = file->private_data;
815 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
816 struct iwl_mvm *mvm = mvmvif->mvm;
819 const size_t bufsz = sizeof(buf);
820 struct iwl_tof_responder_config_cmd *cmd;
822 cmd = &mvm->tof_data.responder_cfg;
824 mutex_lock(&mvm->mutex);
826 pos += scnprintf(buf + pos, bufsz - pos, "burst_period = %d\n",
827 le16_to_cpu(cmd->burst_period));
828 pos += scnprintf(buf + pos, bufsz - pos, "burst_duration = %d\n",
829 cmd->burst_duration);
830 pos += scnprintf(buf + pos, bufsz - pos, "bandwidth = %d\n",
832 pos += scnprintf(buf + pos, bufsz - pos, "channel_num = %d\n",
834 pos += scnprintf(buf + pos, bufsz - pos, "ctrl_ch_position = 0x%x\n",
835 cmd->ctrl_ch_position);
836 pos += scnprintf(buf + pos, bufsz - pos, "bssid = %pM\n",
838 pos += scnprintf(buf + pos, bufsz - pos, "min_delta_ftm = %d\n",
840 pos += scnprintf(buf + pos, bufsz - pos, "num_of_burst_exp = %d\n",
841 cmd->num_of_burst_exp);
842 pos += scnprintf(buf + pos, bufsz - pos, "rate = %d\n", cmd->rate);
843 pos += scnprintf(buf + pos, bufsz - pos, "abort_responder = %d\n",
844 cmd->abort_responder);
845 pos += scnprintf(buf + pos, bufsz - pos, "get_ch_est = %d\n",
847 pos += scnprintf(buf + pos, bufsz - pos, "recv_sta_req_params = %d\n",
848 cmd->recv_sta_req_params);
849 pos += scnprintf(buf + pos, bufsz - pos, "ftm_per_burst = %d\n",
851 pos += scnprintf(buf + pos, bufsz - pos, "ftm_resp_ts_avail = %d\n",
852 cmd->ftm_resp_ts_avail);
853 pos += scnprintf(buf + pos, bufsz - pos, "asap_mode = %d\n",
855 pos += scnprintf(buf + pos, bufsz - pos,
856 "tsf_timer_offset_msecs = %d\n",
857 le16_to_cpu(cmd->tsf_timer_offset_msecs));
858 pos += scnprintf(buf + pos, bufsz - pos, "toa_offset = %d\n",
859 le16_to_cpu(cmd->toa_offset));
861 mutex_unlock(&mvm->mutex);
863 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
866 static ssize_t iwl_dbgfs_tof_range_request_write(struct ieee80211_vif *vif,
867 char *buf, size_t count,
870 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
871 struct iwl_mvm *mvm = mvmvif->mvm;
876 mutex_lock(&mvm->mutex);
878 data = iwl_dbgfs_is_match("request_id=", buf);
880 ret = kstrtou32(data, 10, &value);
882 mvm->tof_data.range_req.request_id = value;
886 data = iwl_dbgfs_is_match("initiator=", buf);
888 ret = kstrtou32(data, 10, &value);
890 mvm->tof_data.range_req.initiator = value;
894 data = iwl_dbgfs_is_match("one_sided_los_disable=", buf);
896 ret = kstrtou32(data, 10, &value);
898 mvm->tof_data.range_req.one_sided_los_disable = value;
902 data = iwl_dbgfs_is_match("req_timeout=", buf);
904 ret = kstrtou32(data, 10, &value);
906 mvm->tof_data.range_req.req_timeout = value;
910 data = iwl_dbgfs_is_match("report_policy=", buf);
912 ret = kstrtou32(data, 10, &value);
914 mvm->tof_data.range_req.report_policy = value;
918 data = iwl_dbgfs_is_match("macaddr_random=", buf);
920 ret = kstrtou32(data, 10, &value);
922 mvm->tof_data.range_req.macaddr_random = value;
926 data = iwl_dbgfs_is_match("num_of_ap=", buf);
928 ret = kstrtou32(data, 10, &value);
930 mvm->tof_data.range_req.num_of_ap = value;
934 data = iwl_dbgfs_is_match("macaddr_template=", buf);
938 if (!mac_pton(data, mac)) {
942 memcpy(mvm->tof_data.range_req.macaddr_template, mac, ETH_ALEN);
946 data = iwl_dbgfs_is_match("macaddr_mask=", buf);
950 if (!mac_pton(data, mac)) {
954 memcpy(mvm->tof_data.range_req.macaddr_mask, mac, ETH_ALEN);
958 data = iwl_dbgfs_is_match("ap=", buf);
960 struct iwl_tof_range_req_ap_entry ap = {};
961 int size = sizeof(struct iwl_tof_range_req_ap_entry);
966 if (sscanf(data, "%u %hhd %hhd %hhd"
967 "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"
970 "%hhx %hhd %hhd %hhd",
971 &i, &ap.channel_num, &ap.bandwidth,
972 &ap.ctrl_ch_position,
973 mac, mac + 1, mac + 2, mac + 3, mac + 4, mac + 5,
974 &ap.measure_type, &ap.num_of_bursts,
976 &ap.samples_per_burst, &ap.retries_per_sample,
977 &ap.tsf_delta, &ap.location_req, &ap.asap_mode,
978 &ap.enable_dyn_ack, &ap.rssi) != 20) {
982 if (i >= IWL_MVM_TOF_MAX_APS) {
983 IWL_ERR(mvm, "Invalid AP index %d\n", i);
988 ap.burst_period = cpu_to_le16(burst_period);
990 memcpy(&mvm->tof_data.range_req.ap[i], &ap, size);
994 data = iwl_dbgfs_is_match("send_range_request=", buf);
996 ret = kstrtou32(data, 10, &value);
997 if (ret == 0 && value)
998 ret = iwl_mvm_tof_range_request_cmd(mvm, vif);
1004 mutex_unlock(&mvm->mutex);
1005 return ret ?: count;
1008 static ssize_t iwl_dbgfs_tof_range_request_read(struct file *file,
1009 char __user *user_buf,
1010 size_t count, loff_t *ppos)
1012 struct ieee80211_vif *vif = file->private_data;
1013 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1014 struct iwl_mvm *mvm = mvmvif->mvm;
1017 const size_t bufsz = sizeof(buf);
1018 struct iwl_tof_range_req_cmd *cmd;
1021 cmd = &mvm->tof_data.range_req;
1023 mutex_lock(&mvm->mutex);
1025 pos += scnprintf(buf + pos, bufsz - pos, "request_id= %d\n",
1027 pos += scnprintf(buf + pos, bufsz - pos, "initiator= %d\n",
1029 pos += scnprintf(buf + pos, bufsz - pos, "one_sided_los_disable = %d\n",
1030 cmd->one_sided_los_disable);
1031 pos += scnprintf(buf + pos, bufsz - pos, "req_timeout= %d\n",
1033 pos += scnprintf(buf + pos, bufsz - pos, "report_policy= %d\n",
1034 cmd->report_policy);
1035 pos += scnprintf(buf + pos, bufsz - pos, "macaddr_random= %d\n",
1036 cmd->macaddr_random);
1037 pos += scnprintf(buf + pos, bufsz - pos, "macaddr_template= %pM\n",
1038 cmd->macaddr_template);
1039 pos += scnprintf(buf + pos, bufsz - pos, "macaddr_mask= %pM\n",
1041 pos += scnprintf(buf + pos, bufsz - pos, "num_of_ap= %d\n",
1043 for (i = 0; i < cmd->num_of_ap; i++) {
1044 struct iwl_tof_range_req_ap_entry *ap = &cmd->ap[i];
1046 pos += scnprintf(buf + pos, bufsz - pos,
1047 "ap %.2d: channel_num=%hhd bw=%hhd"
1048 " control=%hhd bssid=%pM type=%hhd"
1049 " num_of_bursts=%hhd burst_period=%hd ftm=%hhd"
1050 " retries=%hhd tsf_delta=%d"
1051 " tsf_delta_direction=%hhd location_req=0x%hhx "
1052 " asap=%hhd enable=%hhd rssi=%hhd\n",
1053 i, ap->channel_num, ap->bandwidth,
1054 ap->ctrl_ch_position, ap->bssid,
1055 ap->measure_type, ap->num_of_bursts,
1056 ap->burst_period, ap->samples_per_burst,
1057 ap->retries_per_sample, ap->tsf_delta,
1058 ap->tsf_delta_direction,
1059 ap->location_req, ap->asap_mode,
1060 ap->enable_dyn_ack, ap->rssi);
1063 mutex_unlock(&mvm->mutex);
1065 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1068 static ssize_t iwl_dbgfs_tof_range_req_ext_write(struct ieee80211_vif *vif,
1070 size_t count, loff_t *ppos)
1072 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1073 struct iwl_mvm *mvm = mvmvif->mvm;
1078 mutex_lock(&mvm->mutex);
1080 data = iwl_dbgfs_is_match("tsf_timer_offset_msec=", buf);
1082 ret = kstrtou32(data, 10, &value);
1084 mvm->tof_data.range_req_ext.tsf_timer_offset_msec =
1089 data = iwl_dbgfs_is_match("min_delta_ftm=", buf);
1091 ret = kstrtou32(data, 10, &value);
1093 mvm->tof_data.range_req_ext.min_delta_ftm = value;
1097 data = iwl_dbgfs_is_match("ftm_format_and_bw20M=", buf);
1099 ret = kstrtou32(data, 10, &value);
1101 mvm->tof_data.range_req_ext.ftm_format_and_bw20M =
1106 data = iwl_dbgfs_is_match("ftm_format_and_bw40M=", buf);
1108 ret = kstrtou32(data, 10, &value);
1110 mvm->tof_data.range_req_ext.ftm_format_and_bw40M =
1115 data = iwl_dbgfs_is_match("ftm_format_and_bw80M=", buf);
1117 ret = kstrtou32(data, 10, &value);
1119 mvm->tof_data.range_req_ext.ftm_format_and_bw80M =
1124 data = iwl_dbgfs_is_match("send_range_req_ext=", buf);
1126 ret = kstrtou32(data, 10, &value);
1127 if (ret == 0 && value)
1128 ret = iwl_mvm_tof_range_request_ext_cmd(mvm, vif);
1134 mutex_unlock(&mvm->mutex);
1135 return ret ?: count;
1138 static ssize_t iwl_dbgfs_tof_range_req_ext_read(struct file *file,
1139 char __user *user_buf,
1140 size_t count, loff_t *ppos)
1142 struct ieee80211_vif *vif = file->private_data;
1143 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1144 struct iwl_mvm *mvm = mvmvif->mvm;
1147 const size_t bufsz = sizeof(buf);
1148 struct iwl_tof_range_req_ext_cmd *cmd;
1150 cmd = &mvm->tof_data.range_req_ext;
1152 mutex_lock(&mvm->mutex);
1154 pos += scnprintf(buf + pos, bufsz - pos,
1155 "tsf_timer_offset_msec = %hd\n",
1156 cmd->tsf_timer_offset_msec);
1157 pos += scnprintf(buf + pos, bufsz - pos, "min_delta_ftm = %hhd\n",
1158 cmd->min_delta_ftm);
1159 pos += scnprintf(buf + pos, bufsz - pos,
1160 "ftm_format_and_bw20M = %hhd\n",
1161 cmd->ftm_format_and_bw20M);
1162 pos += scnprintf(buf + pos, bufsz - pos,
1163 "ftm_format_and_bw40M = %hhd\n",
1164 cmd->ftm_format_and_bw40M);
1165 pos += scnprintf(buf + pos, bufsz - pos,
1166 "ftm_format_and_bw80M = %hhd\n",
1167 cmd->ftm_format_and_bw80M);
1169 mutex_unlock(&mvm->mutex);
1170 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1173 static ssize_t iwl_dbgfs_tof_range_abort_write(struct ieee80211_vif *vif,
1175 size_t count, loff_t *ppos)
1177 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1178 struct iwl_mvm *mvm = mvmvif->mvm;
1180 int abort_id, ret = 0;
1183 mutex_lock(&mvm->mutex);
1185 data = iwl_dbgfs_is_match("abort_id=", buf);
1187 ret = kstrtou32(data, 10, &value);
1189 mvm->tof_data.last_abort_id = value;
1193 data = iwl_dbgfs_is_match("send_range_abort=", buf);
1195 ret = kstrtou32(data, 10, &value);
1196 if (ret == 0 && value) {
1197 abort_id = mvm->tof_data.last_abort_id;
1198 ret = iwl_mvm_tof_range_abort_cmd(mvm, abort_id);
1204 mutex_unlock(&mvm->mutex);
1205 return ret ?: count;
1208 static ssize_t iwl_dbgfs_tof_range_abort_read(struct file *file,
1209 char __user *user_buf,
1210 size_t count, loff_t *ppos)
1212 struct ieee80211_vif *vif = file->private_data;
1213 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1214 struct iwl_mvm *mvm = mvmvif->mvm;
1217 const size_t bufsz = sizeof(buf);
1220 mutex_lock(&mvm->mutex);
1221 last_abort_id = mvm->tof_data.last_abort_id;
1222 mutex_unlock(&mvm->mutex);
1224 pos += scnprintf(buf + pos, bufsz - pos, "last_abort_id = %d\n",
1226 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1229 static ssize_t iwl_dbgfs_tof_range_response_read(struct file *file,
1230 char __user *user_buf,
1231 size_t count, loff_t *ppos)
1233 struct ieee80211_vif *vif = file->private_data;
1234 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1235 struct iwl_mvm *mvm = mvmvif->mvm;
1238 const size_t bufsz = sizeof(struct iwl_tof_range_rsp_ntfy) + 256;
1239 struct iwl_tof_range_rsp_ntfy *cmd;
1242 buf = kzalloc(bufsz, GFP_KERNEL);
1246 mutex_lock(&mvm->mutex);
1247 cmd = &mvm->tof_data.range_resp;
1249 pos += scnprintf(buf + pos, bufsz - pos, "request_id = %d\n",
1251 pos += scnprintf(buf + pos, bufsz - pos, "status = %d\n",
1252 cmd->request_status);
1253 pos += scnprintf(buf + pos, bufsz - pos, "last_in_batch = %d\n",
1254 cmd->last_in_batch);
1255 pos += scnprintf(buf + pos, bufsz - pos, "num_of_aps = %d\n",
1257 for (i = 0; i < cmd->num_of_aps; i++) {
1258 struct iwl_tof_range_rsp_ap_entry_ntfy *ap = &cmd->ap[i];
1260 pos += scnprintf(buf + pos, bufsz - pos,
1261 "ap %.2d: bssid=%pM status=%hhd bw=%hhd"
1262 " rtt=%d rtt_var=%d rtt_spread=%d"
1263 " rssi=%hhd rssi_spread=%hhd"
1264 " range=%d range_var=%d"
1266 i, ap->bssid, ap->measure_status,
1268 ap->rtt, ap->rtt_variance, ap->rtt_spread,
1269 ap->rssi, ap->rssi_spread, ap->range,
1270 ap->range_variance, ap->timestamp);
1272 mutex_unlock(&mvm->mutex);
1274 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1279 static ssize_t iwl_dbgfs_low_latency_write(struct ieee80211_vif *vif, char *buf,
1280 size_t count, loff_t *ppos)
1282 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1283 struct iwl_mvm *mvm = mvmvif->mvm;
1287 ret = kstrtou8(buf, 0, &value);
1293 mutex_lock(&mvm->mutex);
1294 iwl_mvm_update_low_latency(mvm, vif, value, LOW_LATENCY_DEBUGFS);
1295 mutex_unlock(&mvm->mutex);
1300 static ssize_t iwl_dbgfs_low_latency_read(struct file *file,
1301 char __user *user_buf,
1302 size_t count, loff_t *ppos)
1304 struct ieee80211_vif *vif = file->private_data;
1305 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1309 len = scnprintf(buf, sizeof(buf) - 1,
1310 "traffic=%d\ndbgfs=%d\nvcmd=%d\n",
1311 !!(mvmvif->low_latency & LOW_LATENCY_TRAFFIC),
1312 !!(mvmvif->low_latency & LOW_LATENCY_DEBUGFS),
1313 !!(mvmvif->low_latency & LOW_LATENCY_VCMD));
1314 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1317 static ssize_t iwl_dbgfs_uapsd_misbehaving_read(struct file *file,
1318 char __user *user_buf,
1319 size_t count, loff_t *ppos)
1321 struct ieee80211_vif *vif = file->private_data;
1322 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1326 len = sprintf(buf, "%pM\n", mvmvif->uapsd_misbehaving_bssid);
1327 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1330 static ssize_t iwl_dbgfs_uapsd_misbehaving_write(struct ieee80211_vif *vif,
1331 char *buf, size_t count,
1334 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1335 struct iwl_mvm *mvm = mvmvif->mvm;
1338 mutex_lock(&mvm->mutex);
1339 ret = mac_pton(buf, mvmvif->uapsd_misbehaving_bssid);
1340 mutex_unlock(&mvm->mutex);
1342 return ret ? count : -EINVAL;
1345 static ssize_t iwl_dbgfs_rx_phyinfo_write(struct ieee80211_vif *vif, char *buf,
1346 size_t count, loff_t *ppos)
1348 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1349 struct iwl_mvm *mvm = mvmvif->mvm;
1350 struct ieee80211_chanctx_conf *chanctx_conf;
1351 struct iwl_mvm_phy_ctxt *phy_ctxt;
1355 ret = kstrtou16(buf, 0, &value);
1359 mutex_lock(&mvm->mutex);
1362 chanctx_conf = rcu_dereference(vif->chanctx_conf);
1363 /* make sure the channel context is assigned */
1364 if (!chanctx_conf) {
1366 mutex_unlock(&mvm->mutex);
1370 phy_ctxt = &mvm->phy_ctxts[*(u16 *)chanctx_conf->drv_priv];
1373 mvm->dbgfs_rx_phyinfo = value;
1375 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chanctx_conf->min_def,
1376 chanctx_conf->rx_chains_static,
1377 chanctx_conf->rx_chains_dynamic);
1378 mutex_unlock(&mvm->mutex);
1380 return ret ?: count;
1383 static ssize_t iwl_dbgfs_rx_phyinfo_read(struct file *file,
1384 char __user *user_buf,
1385 size_t count, loff_t *ppos)
1387 struct ieee80211_vif *vif = file->private_data;
1388 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1392 len = scnprintf(buf, sizeof(buf), "0x%04x\n",
1393 mvmvif->mvm->dbgfs_rx_phyinfo);
1395 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1398 static void iwl_dbgfs_quota_check(void *data, u8 *mac,
1399 struct ieee80211_vif *vif)
1401 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1404 if (mvmvif->dbgfs_quota_min)
1408 static ssize_t iwl_dbgfs_quota_min_write(struct ieee80211_vif *vif, char *buf,
1409 size_t count, loff_t *ppos)
1411 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1412 struct iwl_mvm *mvm = mvmvif->mvm;
1416 ret = kstrtou16(buf, 0, &value);
1423 mutex_lock(&mvm->mutex);
1425 mvmvif->dbgfs_quota_min = 0;
1426 ieee80211_iterate_interfaces(mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1427 iwl_dbgfs_quota_check, &ret);
1429 mvmvif->dbgfs_quota_min = value;
1430 iwl_mvm_update_quotas(mvm, false, NULL);
1432 mutex_unlock(&mvm->mutex);
1434 return ret ?: count;
1437 static ssize_t iwl_dbgfs_quota_min_read(struct file *file,
1438 char __user *user_buf,
1439 size_t count, loff_t *ppos)
1441 struct ieee80211_vif *vif = file->private_data;
1442 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1446 len = scnprintf(buf, sizeof(buf), "%d\n", mvmvif->dbgfs_quota_min);
1448 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1451 static const char * const chanwidths[] = {
1452 [NL80211_CHAN_WIDTH_20_NOHT] = "noht",
1453 [NL80211_CHAN_WIDTH_20] = "ht20",
1454 [NL80211_CHAN_WIDTH_40] = "ht40",
1455 [NL80211_CHAN_WIDTH_80] = "vht80",
1456 [NL80211_CHAN_WIDTH_80P80] = "vht80p80",
1457 [NL80211_CHAN_WIDTH_160] = "vht160",
1460 #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
1461 _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
1462 #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
1463 _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
1464 #define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \
1465 if (!debugfs_create_file(#name, mode, parent, vif, \
1466 &iwl_dbgfs_##name##_ops)) \
1470 MVM_DEBUGFS_READ_FILE_OPS(mac_params);
1471 MVM_DEBUGFS_READ_FILE_OPS(tx_pwr_lmt);
1472 MVM_DEBUGFS_READ_WRITE_FILE_OPS(pm_params, 32);
1473 MVM_DEBUGFS_READ_WRITE_FILE_OPS(bf_params, 256);
1474 MVM_DEBUGFS_READ_WRITE_FILE_OPS(low_latency, 10);
1475 MVM_DEBUGFS_READ_WRITE_FILE_OPS(uapsd_misbehaving, 20);
1476 MVM_DEBUGFS_READ_WRITE_FILE_OPS(rx_phyinfo, 10);
1477 MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_enable, 32);
1478 MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_request, 512);
1479 MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_req_ext, 32);
1480 MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_abort, 32);
1481 MVM_DEBUGFS_READ_FILE_OPS(tof_range_response);
1482 MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_responder_params, 32);
1483 MVM_DEBUGFS_READ_WRITE_FILE_OPS(quota_min, 32);
1484 MVM_DEBUGFS_READ_FILE_OPS(os_device_timediff);
1487 void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1489 struct dentry *dbgfs_dir = vif->debugfs_dir;
1490 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1494 * Check if debugfs directory already exist before creating it.
1495 * This may happen when, for example, resetting hw or suspend-resume
1497 if (!dbgfs_dir || mvmvif->dbgfs_dir)
1500 mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir);
1502 if (!mvmvif->dbgfs_dir) {
1503 IWL_ERR(mvm, "Failed to create debugfs directory under %pd\n",
1508 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM &&
1509 ((vif->type == NL80211_IFTYPE_STATION && !vif->p2p) ||
1510 (vif->type == NL80211_IFTYPE_STATION && vif->p2p)))
1511 MVM_DEBUGFS_ADD_FILE_VIF(pm_params, mvmvif->dbgfs_dir, 0600);
1513 MVM_DEBUGFS_ADD_FILE_VIF(tx_pwr_lmt, mvmvif->dbgfs_dir, 0400);
1514 MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir, 0400);
1515 MVM_DEBUGFS_ADD_FILE_VIF(low_latency, mvmvif->dbgfs_dir, 0600);
1516 MVM_DEBUGFS_ADD_FILE_VIF(uapsd_misbehaving, mvmvif->dbgfs_dir, 0600);
1517 MVM_DEBUGFS_ADD_FILE_VIF(rx_phyinfo, mvmvif->dbgfs_dir, 0600);
1518 MVM_DEBUGFS_ADD_FILE_VIF(quota_min, mvmvif->dbgfs_dir, 0600);
1519 MVM_DEBUGFS_ADD_FILE_VIF(os_device_timediff, mvmvif->dbgfs_dir, 0400);
1521 if (vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
1522 mvmvif == mvm->bf_allowed_vif)
1523 MVM_DEBUGFS_ADD_FILE_VIF(bf_params, mvmvif->dbgfs_dir, 0600);
1525 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TOF_SUPPORT) &&
1526 !vif->p2p && (vif->type != NL80211_IFTYPE_P2P_DEVICE)) {
1527 if (IWL_MVM_TOF_IS_RESPONDER && vif->type == NL80211_IFTYPE_AP)
1528 MVM_DEBUGFS_ADD_FILE_VIF(tof_responder_params,
1529 mvmvif->dbgfs_dir, 0600);
1531 MVM_DEBUGFS_ADD_FILE_VIF(tof_range_request, mvmvif->dbgfs_dir,
1533 MVM_DEBUGFS_ADD_FILE_VIF(tof_range_req_ext, mvmvif->dbgfs_dir,
1535 MVM_DEBUGFS_ADD_FILE_VIF(tof_enable, mvmvif->dbgfs_dir,
1537 MVM_DEBUGFS_ADD_FILE_VIF(tof_range_abort, mvmvif->dbgfs_dir,
1539 MVM_DEBUGFS_ADD_FILE_VIF(tof_range_response, mvmvif->dbgfs_dir,
1544 * Create symlink for convenience pointing to interface specific
1545 * debugfs entries for the driver. For example, under
1546 * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/
1548 * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/
1550 snprintf(buf, 100, "../../../%pd3/%pd",
1554 mvmvif->dbgfs_slink = debugfs_create_symlink(dbgfs_dir->d_name.name,
1555 mvm->debugfs_dir, buf);
1556 if (!mvmvif->dbgfs_slink)
1557 IWL_ERR(mvm, "Can't create debugfs symbolic link under %pd\n",
1561 IWL_ERR(mvm, "Can't create debugfs entity\n");
1564 void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1566 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1568 debugfs_remove(mvmvif->dbgfs_slink);
1569 mvmvif->dbgfs_slink = NULL;
1571 debugfs_remove_recursive(mvmvif->dbgfs_dir);
1572 mvmvif->dbgfs_dir = NULL;