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 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 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, "QoS:\n");
273 for (i = 0; i < ARRAY_SIZE(mvmvif->queue_params); i++)
274 pos += scnprintf(buf+pos, bufsz-pos,
275 "\t%d: txop:%d - cw_min:%d - cw_max = %d - aifs = %d upasd = %d\n",
276 i, mvmvif->queue_params[i].txop,
277 mvmvif->queue_params[i].cw_min,
278 mvmvif->queue_params[i].cw_max,
279 mvmvif->queue_params[i].aifs,
280 mvmvif->queue_params[i].uapsd);
282 if (vif->type == NL80211_IFTYPE_STATION &&
283 ap_sta_id != IWL_MVM_STATION_COUNT) {
284 struct iwl_mvm_sta *mvm_sta;
286 mvm_sta = iwl_mvm_sta_from_staid_protected(mvm, ap_sta_id);
288 pos += scnprintf(buf+pos, bufsz-pos,
289 "ap_sta_id %d - reduced Tx power %d\n",
291 mvm_sta->bt_reduced_txpower);
296 chanctx_conf = rcu_dereference(vif->chanctx_conf);
298 pos += scnprintf(buf+pos, bufsz-pos,
299 "idle rx chains %d, active rx chains: %d\n",
300 chanctx_conf->rx_chains_static,
301 chanctx_conf->rx_chains_dynamic);
304 mutex_unlock(&mvm->mutex);
306 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
309 static void iwl_dbgfs_update_bf(struct ieee80211_vif *vif,
310 enum iwl_dbgfs_bf_mask param, int value)
312 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
313 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
315 dbgfs_bf->mask |= param;
318 case MVM_DEBUGFS_BF_ENERGY_DELTA:
319 dbgfs_bf->bf_energy_delta = value;
321 case MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA:
322 dbgfs_bf->bf_roaming_energy_delta = value;
324 case MVM_DEBUGFS_BF_ROAMING_STATE:
325 dbgfs_bf->bf_roaming_state = value;
327 case MVM_DEBUGFS_BF_TEMP_THRESHOLD:
328 dbgfs_bf->bf_temp_threshold = value;
330 case MVM_DEBUGFS_BF_TEMP_FAST_FILTER:
331 dbgfs_bf->bf_temp_fast_filter = value;
333 case MVM_DEBUGFS_BF_TEMP_SLOW_FILTER:
334 dbgfs_bf->bf_temp_slow_filter = value;
336 case MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER:
337 dbgfs_bf->bf_enable_beacon_filter = value;
339 case MVM_DEBUGFS_BF_DEBUG_FLAG:
340 dbgfs_bf->bf_debug_flag = value;
342 case MVM_DEBUGFS_BF_ESCAPE_TIMER:
343 dbgfs_bf->bf_escape_timer = value;
345 case MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT:
346 dbgfs_bf->ba_enable_beacon_abort = value;
348 case MVM_DEBUGFS_BA_ESCAPE_TIMER:
349 dbgfs_bf->ba_escape_timer = value;
354 static ssize_t iwl_dbgfs_bf_params_write(struct ieee80211_vif *vif, char *buf,
355 size_t count, loff_t *ppos)
357 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
358 struct iwl_mvm *mvm = mvmvif->mvm;
359 enum iwl_dbgfs_bf_mask param;
362 if (!strncmp("bf_energy_delta=", buf, 16)) {
363 if (sscanf(buf+16, "%d", &value) != 1)
365 if (value < IWL_BF_ENERGY_DELTA_MIN ||
366 value > IWL_BF_ENERGY_DELTA_MAX)
368 param = MVM_DEBUGFS_BF_ENERGY_DELTA;
369 } else if (!strncmp("bf_roaming_energy_delta=", buf, 24)) {
370 if (sscanf(buf+24, "%d", &value) != 1)
372 if (value < IWL_BF_ROAMING_ENERGY_DELTA_MIN ||
373 value > IWL_BF_ROAMING_ENERGY_DELTA_MAX)
375 param = MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA;
376 } else if (!strncmp("bf_roaming_state=", buf, 17)) {
377 if (sscanf(buf+17, "%d", &value) != 1)
379 if (value < IWL_BF_ROAMING_STATE_MIN ||
380 value > IWL_BF_ROAMING_STATE_MAX)
382 param = MVM_DEBUGFS_BF_ROAMING_STATE;
383 } else if (!strncmp("bf_temp_threshold=", buf, 18)) {
384 if (sscanf(buf+18, "%d", &value) != 1)
386 if (value < IWL_BF_TEMP_THRESHOLD_MIN ||
387 value > IWL_BF_TEMP_THRESHOLD_MAX)
389 param = MVM_DEBUGFS_BF_TEMP_THRESHOLD;
390 } else if (!strncmp("bf_temp_fast_filter=", buf, 20)) {
391 if (sscanf(buf+20, "%d", &value) != 1)
393 if (value < IWL_BF_TEMP_FAST_FILTER_MIN ||
394 value > IWL_BF_TEMP_FAST_FILTER_MAX)
396 param = MVM_DEBUGFS_BF_TEMP_FAST_FILTER;
397 } else if (!strncmp("bf_temp_slow_filter=", buf, 20)) {
398 if (sscanf(buf+20, "%d", &value) != 1)
400 if (value < IWL_BF_TEMP_SLOW_FILTER_MIN ||
401 value > IWL_BF_TEMP_SLOW_FILTER_MAX)
403 param = MVM_DEBUGFS_BF_TEMP_SLOW_FILTER;
404 } else if (!strncmp("bf_enable_beacon_filter=", buf, 24)) {
405 if (sscanf(buf+24, "%d", &value) != 1)
407 if (value < 0 || value > 1)
409 param = MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER;
410 } else if (!strncmp("bf_debug_flag=", buf, 14)) {
411 if (sscanf(buf+14, "%d", &value) != 1)
413 if (value < 0 || value > 1)
415 param = MVM_DEBUGFS_BF_DEBUG_FLAG;
416 } else if (!strncmp("bf_escape_timer=", buf, 16)) {
417 if (sscanf(buf+16, "%d", &value) != 1)
419 if (value < IWL_BF_ESCAPE_TIMER_MIN ||
420 value > IWL_BF_ESCAPE_TIMER_MAX)
422 param = MVM_DEBUGFS_BF_ESCAPE_TIMER;
423 } else if (!strncmp("ba_escape_timer=", buf, 16)) {
424 if (sscanf(buf+16, "%d", &value) != 1)
426 if (value < IWL_BA_ESCAPE_TIMER_MIN ||
427 value > IWL_BA_ESCAPE_TIMER_MAX)
429 param = MVM_DEBUGFS_BA_ESCAPE_TIMER;
430 } else if (!strncmp("ba_enable_beacon_abort=", buf, 23)) {
431 if (sscanf(buf+23, "%d", &value) != 1)
433 if (value < 0 || value > 1)
435 param = MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT;
440 mutex_lock(&mvm->mutex);
441 iwl_dbgfs_update_bf(vif, param, value);
442 if (param == MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER && !value)
443 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
445 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
446 mutex_unlock(&mvm->mutex);
451 static ssize_t iwl_dbgfs_bf_params_read(struct file *file,
452 char __user *user_buf,
453 size_t count, loff_t *ppos)
455 struct ieee80211_vif *vif = file->private_data;
456 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
459 const size_t bufsz = sizeof(buf);
460 struct iwl_beacon_filter_cmd cmd = {
461 IWL_BF_CMD_CONFIG_DEFAULTS,
462 .bf_enable_beacon_filter =
463 cpu_to_le32(IWL_BF_ENABLE_BEACON_FILTER_DEFAULT),
464 .ba_enable_beacon_abort =
465 cpu_to_le32(IWL_BA_ENABLE_BEACON_ABORT_DEFAULT),
468 iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
469 if (mvmvif->bf_data.bf_enabled)
470 cmd.bf_enable_beacon_filter = cpu_to_le32(1);
472 cmd.bf_enable_beacon_filter = 0;
474 pos += scnprintf(buf+pos, bufsz-pos, "bf_energy_delta = %d\n",
475 le32_to_cpu(cmd.bf_energy_delta));
476 pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_energy_delta = %d\n",
477 le32_to_cpu(cmd.bf_roaming_energy_delta));
478 pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_state = %d\n",
479 le32_to_cpu(cmd.bf_roaming_state));
480 pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_threshold = %d\n",
481 le32_to_cpu(cmd.bf_temp_threshold));
482 pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_fast_filter = %d\n",
483 le32_to_cpu(cmd.bf_temp_fast_filter));
484 pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_slow_filter = %d\n",
485 le32_to_cpu(cmd.bf_temp_slow_filter));
486 pos += scnprintf(buf+pos, bufsz-pos, "bf_enable_beacon_filter = %d\n",
487 le32_to_cpu(cmd.bf_enable_beacon_filter));
488 pos += scnprintf(buf+pos, bufsz-pos, "bf_debug_flag = %d\n",
489 le32_to_cpu(cmd.bf_debug_flag));
490 pos += scnprintf(buf+pos, bufsz-pos, "bf_escape_timer = %d\n",
491 le32_to_cpu(cmd.bf_escape_timer));
492 pos += scnprintf(buf+pos, bufsz-pos, "ba_escape_timer = %d\n",
493 le32_to_cpu(cmd.ba_escape_timer));
494 pos += scnprintf(buf+pos, bufsz-pos, "ba_enable_beacon_abort = %d\n",
495 le32_to_cpu(cmd.ba_enable_beacon_abort));
497 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
500 static inline char *iwl_dbgfs_is_match(char *name, char *buf)
502 int len = strlen(name);
504 return !strncmp(name, buf, len) ? buf + len : NULL;
507 static ssize_t iwl_dbgfs_os_device_timediff_read(struct file *file,
508 char __user *user_buf,
509 size_t count, loff_t *ppos)
511 struct ieee80211_vif *vif = file->private_data;
512 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
513 struct iwl_mvm *mvm = mvmvif->mvm;
518 const size_t bufsz = sizeof(buf);
521 mutex_lock(&mvm->mutex);
522 iwl_mvm_get_sync_time(mvm, &curr_gp2, &curr_os);
523 mutex_unlock(&mvm->mutex);
525 do_div(curr_os, NSEC_PER_USEC);
526 diff = curr_os - curr_gp2;
527 pos += scnprintf(buf + pos, bufsz - pos, "diff=%lld\n", diff);
529 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
532 static ssize_t iwl_dbgfs_tof_enable_write(struct ieee80211_vif *vif,
534 size_t count, loff_t *ppos)
536 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
537 struct iwl_mvm *mvm = mvmvif->mvm;
542 mutex_lock(&mvm->mutex);
544 data = iwl_dbgfs_is_match("tof_disabled=", buf);
546 ret = kstrtou32(data, 10, &value);
548 mvm->tof_data.tof_cfg.tof_disabled = value;
552 data = iwl_dbgfs_is_match("one_sided_disabled=", buf);
554 ret = kstrtou32(data, 10, &value);
556 mvm->tof_data.tof_cfg.one_sided_disabled = value;
560 data = iwl_dbgfs_is_match("is_debug_mode=", buf);
562 ret = kstrtou32(data, 10, &value);
564 mvm->tof_data.tof_cfg.is_debug_mode = value;
568 data = iwl_dbgfs_is_match("is_buf=", buf);
570 ret = kstrtou32(data, 10, &value);
572 mvm->tof_data.tof_cfg.is_buf_required = value;
576 data = iwl_dbgfs_is_match("send_tof_cfg=", buf);
578 ret = kstrtou32(data, 10, &value);
579 if (ret == 0 && value) {
580 ret = iwl_mvm_tof_config_cmd(mvm);
586 mutex_unlock(&mvm->mutex);
591 static ssize_t iwl_dbgfs_tof_enable_read(struct file *file,
592 char __user *user_buf,
593 size_t count, loff_t *ppos)
595 struct ieee80211_vif *vif = file->private_data;
596 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
597 struct iwl_mvm *mvm = mvmvif->mvm;
600 const size_t bufsz = sizeof(buf);
601 struct iwl_tof_config_cmd *cmd;
603 cmd = &mvm->tof_data.tof_cfg;
605 mutex_lock(&mvm->mutex);
607 pos += scnprintf(buf + pos, bufsz - pos, "tof_disabled = %d\n",
609 pos += scnprintf(buf + pos, bufsz - pos, "one_sided_disabled = %d\n",
610 cmd->one_sided_disabled);
611 pos += scnprintf(buf + pos, bufsz - pos, "is_debug_mode = %d\n",
613 pos += scnprintf(buf + pos, bufsz - pos, "is_buf_required = %d\n",
614 cmd->is_buf_required);
616 mutex_unlock(&mvm->mutex);
618 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
621 static ssize_t iwl_dbgfs_tof_responder_params_write(struct ieee80211_vif *vif,
623 size_t count, loff_t *ppos)
625 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
626 struct iwl_mvm *mvm = mvmvif->mvm;
631 mutex_lock(&mvm->mutex);
633 data = iwl_dbgfs_is_match("burst_period=", buf);
635 ret = kstrtou32(data, 10, &value);
637 mvm->tof_data.responder_cfg.burst_period =
642 data = iwl_dbgfs_is_match("min_delta_ftm=", buf);
644 ret = kstrtou32(data, 10, &value);
646 mvm->tof_data.responder_cfg.min_delta_ftm = value;
650 data = iwl_dbgfs_is_match("burst_duration=", buf);
652 ret = kstrtou32(data, 10, &value);
654 mvm->tof_data.responder_cfg.burst_duration = value;
658 data = iwl_dbgfs_is_match("num_of_burst_exp=", buf);
660 ret = kstrtou32(data, 10, &value);
662 mvm->tof_data.responder_cfg.num_of_burst_exp = value;
666 data = iwl_dbgfs_is_match("abort_responder=", buf);
668 ret = kstrtou32(data, 10, &value);
670 mvm->tof_data.responder_cfg.abort_responder = value;
674 data = iwl_dbgfs_is_match("get_ch_est=", buf);
676 ret = kstrtou32(data, 10, &value);
678 mvm->tof_data.responder_cfg.get_ch_est = value;
682 data = iwl_dbgfs_is_match("recv_sta_req_params=", buf);
684 ret = kstrtou32(data, 10, &value);
686 mvm->tof_data.responder_cfg.recv_sta_req_params = value;
690 data = iwl_dbgfs_is_match("channel_num=", buf);
692 ret = kstrtou32(data, 10, &value);
694 mvm->tof_data.responder_cfg.channel_num = value;
698 data = iwl_dbgfs_is_match("bandwidth=", buf);
700 ret = kstrtou32(data, 10, &value);
702 mvm->tof_data.responder_cfg.bandwidth = value;
706 data = iwl_dbgfs_is_match("rate=", buf);
708 ret = kstrtou32(data, 10, &value);
710 mvm->tof_data.responder_cfg.rate = value;
714 data = iwl_dbgfs_is_match("bssid=", buf);
716 u8 *mac = mvm->tof_data.responder_cfg.bssid;
718 if (!mac_pton(data, mac)) {
724 data = iwl_dbgfs_is_match("tsf_timer_offset_msecs=", buf);
726 ret = kstrtou32(data, 10, &value);
728 mvm->tof_data.responder_cfg.tsf_timer_offset_msecs =
733 data = iwl_dbgfs_is_match("toa_offset=", buf);
735 ret = kstrtou32(data, 10, &value);
737 mvm->tof_data.responder_cfg.toa_offset =
742 data = iwl_dbgfs_is_match("center_freq=", buf);
744 struct iwl_tof_responder_config_cmd *cmd =
745 &mvm->tof_data.responder_cfg;
747 ret = kstrtou32(data, 10, &value);
748 if (ret == 0 && value) {
749 enum nl80211_band band = (cmd->channel_num <= 14) ?
752 struct ieee80211_channel chn = {
754 .center_freq = ieee80211_channel_to_frequency(
755 cmd->channel_num, band),
757 struct cfg80211_chan_def chandef = {
760 ieee80211_channel_to_frequency(value,
764 cmd->ctrl_ch_position = iwl_mvm_get_ctrl_pos(&chandef);
769 data = iwl_dbgfs_is_match("ftm_per_burst=", buf);
771 ret = kstrtou32(data, 10, &value);
773 mvm->tof_data.responder_cfg.ftm_per_burst = value;
777 data = iwl_dbgfs_is_match("ftm_resp_ts_avail=", buf);
779 ret = kstrtou32(data, 10, &value);
781 mvm->tof_data.responder_cfg.ftm_resp_ts_avail = value;
785 data = iwl_dbgfs_is_match("asap_mode=", buf);
787 ret = kstrtou32(data, 10, &value);
789 mvm->tof_data.responder_cfg.asap_mode = value;
793 data = iwl_dbgfs_is_match("send_responder_cfg=", buf);
795 ret = kstrtou32(data, 10, &value);
796 if (ret == 0 && value) {
797 ret = iwl_mvm_tof_responder_cmd(mvm, vif);
803 mutex_unlock(&mvm->mutex);
808 static ssize_t iwl_dbgfs_tof_responder_params_read(struct file *file,
809 char __user *user_buf,
810 size_t count, loff_t *ppos)
812 struct ieee80211_vif *vif = file->private_data;
813 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
814 struct iwl_mvm *mvm = mvmvif->mvm;
817 const size_t bufsz = sizeof(buf);
818 struct iwl_tof_responder_config_cmd *cmd;
820 cmd = &mvm->tof_data.responder_cfg;
822 mutex_lock(&mvm->mutex);
824 pos += scnprintf(buf + pos, bufsz - pos, "burst_period = %d\n",
825 le16_to_cpu(cmd->burst_period));
826 pos += scnprintf(buf + pos, bufsz - pos, "burst_duration = %d\n",
827 cmd->burst_duration);
828 pos += scnprintf(buf + pos, bufsz - pos, "bandwidth = %d\n",
830 pos += scnprintf(buf + pos, bufsz - pos, "channel_num = %d\n",
832 pos += scnprintf(buf + pos, bufsz - pos, "ctrl_ch_position = 0x%x\n",
833 cmd->ctrl_ch_position);
834 pos += scnprintf(buf + pos, bufsz - pos, "bssid = %pM\n",
836 pos += scnprintf(buf + pos, bufsz - pos, "min_delta_ftm = %d\n",
838 pos += scnprintf(buf + pos, bufsz - pos, "num_of_burst_exp = %d\n",
839 cmd->num_of_burst_exp);
840 pos += scnprintf(buf + pos, bufsz - pos, "rate = %d\n", cmd->rate);
841 pos += scnprintf(buf + pos, bufsz - pos, "abort_responder = %d\n",
842 cmd->abort_responder);
843 pos += scnprintf(buf + pos, bufsz - pos, "get_ch_est = %d\n",
845 pos += scnprintf(buf + pos, bufsz - pos, "recv_sta_req_params = %d\n",
846 cmd->recv_sta_req_params);
847 pos += scnprintf(buf + pos, bufsz - pos, "ftm_per_burst = %d\n",
849 pos += scnprintf(buf + pos, bufsz - pos, "ftm_resp_ts_avail = %d\n",
850 cmd->ftm_resp_ts_avail);
851 pos += scnprintf(buf + pos, bufsz - pos, "asap_mode = %d\n",
853 pos += scnprintf(buf + pos, bufsz - pos,
854 "tsf_timer_offset_msecs = %d\n",
855 le16_to_cpu(cmd->tsf_timer_offset_msecs));
856 pos += scnprintf(buf + pos, bufsz - pos, "toa_offset = %d\n",
857 le16_to_cpu(cmd->toa_offset));
859 mutex_unlock(&mvm->mutex);
861 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
864 static ssize_t iwl_dbgfs_tof_range_request_write(struct ieee80211_vif *vif,
865 char *buf, size_t count,
868 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
869 struct iwl_mvm *mvm = mvmvif->mvm;
874 mutex_lock(&mvm->mutex);
876 data = iwl_dbgfs_is_match("request_id=", buf);
878 ret = kstrtou32(data, 10, &value);
880 mvm->tof_data.range_req.request_id = value;
884 data = iwl_dbgfs_is_match("initiator=", buf);
886 ret = kstrtou32(data, 10, &value);
888 mvm->tof_data.range_req.initiator = value;
892 data = iwl_dbgfs_is_match("one_sided_los_disable=", buf);
894 ret = kstrtou32(data, 10, &value);
896 mvm->tof_data.range_req.one_sided_los_disable = value;
900 data = iwl_dbgfs_is_match("req_timeout=", buf);
902 ret = kstrtou32(data, 10, &value);
904 mvm->tof_data.range_req.req_timeout = value;
908 data = iwl_dbgfs_is_match("report_policy=", buf);
910 ret = kstrtou32(data, 10, &value);
912 mvm->tof_data.range_req.report_policy = value;
916 data = iwl_dbgfs_is_match("macaddr_random=", buf);
918 ret = kstrtou32(data, 10, &value);
920 mvm->tof_data.range_req.macaddr_random = value;
924 data = iwl_dbgfs_is_match("num_of_ap=", buf);
926 ret = kstrtou32(data, 10, &value);
928 mvm->tof_data.range_req.num_of_ap = value;
932 data = iwl_dbgfs_is_match("macaddr_template=", buf);
936 if (!mac_pton(data, mac)) {
940 memcpy(mvm->tof_data.range_req.macaddr_template, mac, ETH_ALEN);
944 data = iwl_dbgfs_is_match("macaddr_mask=", buf);
948 if (!mac_pton(data, mac)) {
952 memcpy(mvm->tof_data.range_req.macaddr_mask, mac, ETH_ALEN);
956 data = iwl_dbgfs_is_match("ap=", buf);
958 struct iwl_tof_range_req_ap_entry ap = {};
959 int size = sizeof(struct iwl_tof_range_req_ap_entry);
964 if (sscanf(data, "%u %hhd %hhd %hhd"
965 "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"
968 "%hhx %hhd %hhd %hhd",
969 &i, &ap.channel_num, &ap.bandwidth,
970 &ap.ctrl_ch_position,
971 mac, mac + 1, mac + 2, mac + 3, mac + 4, mac + 5,
972 &ap.measure_type, &ap.num_of_bursts,
974 &ap.samples_per_burst, &ap.retries_per_sample,
975 &ap.tsf_delta, &ap.location_req, &ap.asap_mode,
976 &ap.enable_dyn_ack, &ap.rssi) != 20) {
980 if (i >= IWL_MVM_TOF_MAX_APS) {
981 IWL_ERR(mvm, "Invalid AP index %d\n", i);
986 ap.burst_period = cpu_to_le16(burst_period);
988 memcpy(&mvm->tof_data.range_req.ap[i], &ap, size);
992 data = iwl_dbgfs_is_match("send_range_request=", buf);
994 ret = kstrtou32(data, 10, &value);
995 if (ret == 0 && value)
996 ret = iwl_mvm_tof_range_request_cmd(mvm, vif);
1002 mutex_unlock(&mvm->mutex);
1003 return ret ?: count;
1006 static ssize_t iwl_dbgfs_tof_range_request_read(struct file *file,
1007 char __user *user_buf,
1008 size_t count, loff_t *ppos)
1010 struct ieee80211_vif *vif = file->private_data;
1011 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1012 struct iwl_mvm *mvm = mvmvif->mvm;
1015 const size_t bufsz = sizeof(buf);
1016 struct iwl_tof_range_req_cmd *cmd;
1019 cmd = &mvm->tof_data.range_req;
1021 mutex_lock(&mvm->mutex);
1023 pos += scnprintf(buf + pos, bufsz - pos, "request_id= %d\n",
1025 pos += scnprintf(buf + pos, bufsz - pos, "initiator= %d\n",
1027 pos += scnprintf(buf + pos, bufsz - pos, "one_sided_los_disable = %d\n",
1028 cmd->one_sided_los_disable);
1029 pos += scnprintf(buf + pos, bufsz - pos, "req_timeout= %d\n",
1031 pos += scnprintf(buf + pos, bufsz - pos, "report_policy= %d\n",
1032 cmd->report_policy);
1033 pos += scnprintf(buf + pos, bufsz - pos, "macaddr_random= %d\n",
1034 cmd->macaddr_random);
1035 pos += scnprintf(buf + pos, bufsz - pos, "macaddr_template= %pM\n",
1036 cmd->macaddr_template);
1037 pos += scnprintf(buf + pos, bufsz - pos, "macaddr_mask= %pM\n",
1039 pos += scnprintf(buf + pos, bufsz - pos, "num_of_ap= %d\n",
1041 for (i = 0; i < cmd->num_of_ap; i++) {
1042 struct iwl_tof_range_req_ap_entry *ap = &cmd->ap[i];
1044 pos += scnprintf(buf + pos, bufsz - pos,
1045 "ap %.2d: channel_num=%hhd bw=%hhd"
1046 " control=%hhd bssid=%pM type=%hhd"
1047 " num_of_bursts=%hhd burst_period=%hd ftm=%hhd"
1048 " retries=%hhd tsf_delta=%d"
1049 " tsf_delta_direction=%hhd location_req=0x%hhx "
1050 " asap=%hhd enable=%hhd rssi=%hhd\n",
1051 i, ap->channel_num, ap->bandwidth,
1052 ap->ctrl_ch_position, ap->bssid,
1053 ap->measure_type, ap->num_of_bursts,
1054 ap->burst_period, ap->samples_per_burst,
1055 ap->retries_per_sample, ap->tsf_delta,
1056 ap->tsf_delta_direction,
1057 ap->location_req, ap->asap_mode,
1058 ap->enable_dyn_ack, ap->rssi);
1061 mutex_unlock(&mvm->mutex);
1063 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1066 static ssize_t iwl_dbgfs_tof_range_req_ext_write(struct ieee80211_vif *vif,
1068 size_t count, loff_t *ppos)
1070 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1071 struct iwl_mvm *mvm = mvmvif->mvm;
1076 mutex_lock(&mvm->mutex);
1078 data = iwl_dbgfs_is_match("tsf_timer_offset_msec=", buf);
1080 ret = kstrtou32(data, 10, &value);
1082 mvm->tof_data.range_req_ext.tsf_timer_offset_msec =
1087 data = iwl_dbgfs_is_match("min_delta_ftm=", buf);
1089 ret = kstrtou32(data, 10, &value);
1091 mvm->tof_data.range_req_ext.min_delta_ftm = value;
1095 data = iwl_dbgfs_is_match("ftm_format_and_bw20M=", buf);
1097 ret = kstrtou32(data, 10, &value);
1099 mvm->tof_data.range_req_ext.ftm_format_and_bw20M =
1104 data = iwl_dbgfs_is_match("ftm_format_and_bw40M=", buf);
1106 ret = kstrtou32(data, 10, &value);
1108 mvm->tof_data.range_req_ext.ftm_format_and_bw40M =
1113 data = iwl_dbgfs_is_match("ftm_format_and_bw80M=", buf);
1115 ret = kstrtou32(data, 10, &value);
1117 mvm->tof_data.range_req_ext.ftm_format_and_bw80M =
1122 data = iwl_dbgfs_is_match("send_range_req_ext=", buf);
1124 ret = kstrtou32(data, 10, &value);
1125 if (ret == 0 && value)
1126 ret = iwl_mvm_tof_range_request_ext_cmd(mvm, vif);
1132 mutex_unlock(&mvm->mutex);
1133 return ret ?: count;
1136 static ssize_t iwl_dbgfs_tof_range_req_ext_read(struct file *file,
1137 char __user *user_buf,
1138 size_t count, loff_t *ppos)
1140 struct ieee80211_vif *vif = file->private_data;
1141 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1142 struct iwl_mvm *mvm = mvmvif->mvm;
1145 const size_t bufsz = sizeof(buf);
1146 struct iwl_tof_range_req_ext_cmd *cmd;
1148 cmd = &mvm->tof_data.range_req_ext;
1150 mutex_lock(&mvm->mutex);
1152 pos += scnprintf(buf + pos, bufsz - pos,
1153 "tsf_timer_offset_msec = %hd\n",
1154 cmd->tsf_timer_offset_msec);
1155 pos += scnprintf(buf + pos, bufsz - pos, "min_delta_ftm = %hhd\n",
1156 cmd->min_delta_ftm);
1157 pos += scnprintf(buf + pos, bufsz - pos,
1158 "ftm_format_and_bw20M = %hhd\n",
1159 cmd->ftm_format_and_bw20M);
1160 pos += scnprintf(buf + pos, bufsz - pos,
1161 "ftm_format_and_bw40M = %hhd\n",
1162 cmd->ftm_format_and_bw40M);
1163 pos += scnprintf(buf + pos, bufsz - pos,
1164 "ftm_format_and_bw80M = %hhd\n",
1165 cmd->ftm_format_and_bw80M);
1167 mutex_unlock(&mvm->mutex);
1168 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1171 static ssize_t iwl_dbgfs_tof_range_abort_write(struct ieee80211_vif *vif,
1173 size_t count, loff_t *ppos)
1175 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1176 struct iwl_mvm *mvm = mvmvif->mvm;
1178 int abort_id, ret = 0;
1181 mutex_lock(&mvm->mutex);
1183 data = iwl_dbgfs_is_match("abort_id=", buf);
1185 ret = kstrtou32(data, 10, &value);
1187 mvm->tof_data.last_abort_id = value;
1191 data = iwl_dbgfs_is_match("send_range_abort=", buf);
1193 ret = kstrtou32(data, 10, &value);
1194 if (ret == 0 && value) {
1195 abort_id = mvm->tof_data.last_abort_id;
1196 ret = iwl_mvm_tof_range_abort_cmd(mvm, abort_id);
1202 mutex_unlock(&mvm->mutex);
1203 return ret ?: count;
1206 static ssize_t iwl_dbgfs_tof_range_abort_read(struct file *file,
1207 char __user *user_buf,
1208 size_t count, loff_t *ppos)
1210 struct ieee80211_vif *vif = file->private_data;
1211 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1212 struct iwl_mvm *mvm = mvmvif->mvm;
1215 const size_t bufsz = sizeof(buf);
1218 mutex_lock(&mvm->mutex);
1219 last_abort_id = mvm->tof_data.last_abort_id;
1220 mutex_unlock(&mvm->mutex);
1222 pos += scnprintf(buf + pos, bufsz - pos, "last_abort_id = %d\n",
1224 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1227 static ssize_t iwl_dbgfs_tof_range_response_read(struct file *file,
1228 char __user *user_buf,
1229 size_t count, loff_t *ppos)
1231 struct ieee80211_vif *vif = file->private_data;
1232 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1233 struct iwl_mvm *mvm = mvmvif->mvm;
1236 const size_t bufsz = sizeof(struct iwl_tof_range_rsp_ntfy) + 256;
1237 struct iwl_tof_range_rsp_ntfy *cmd;
1240 buf = kzalloc(bufsz, GFP_KERNEL);
1244 mutex_lock(&mvm->mutex);
1245 cmd = &mvm->tof_data.range_resp;
1247 pos += scnprintf(buf + pos, bufsz - pos, "request_id = %d\n",
1249 pos += scnprintf(buf + pos, bufsz - pos, "status = %d\n",
1250 cmd->request_status);
1251 pos += scnprintf(buf + pos, bufsz - pos, "last_in_batch = %d\n",
1252 cmd->last_in_batch);
1253 pos += scnprintf(buf + pos, bufsz - pos, "num_of_aps = %d\n",
1255 for (i = 0; i < cmd->num_of_aps; i++) {
1256 struct iwl_tof_range_rsp_ap_entry_ntfy *ap = &cmd->ap[i];
1258 pos += scnprintf(buf + pos, bufsz - pos,
1259 "ap %.2d: bssid=%pM status=%hhd bw=%hhd"
1260 " rtt=%d rtt_var=%d rtt_spread=%d"
1261 " rssi=%hhd rssi_spread=%hhd"
1262 " range=%d range_var=%d"
1264 i, ap->bssid, ap->measure_status,
1266 ap->rtt, ap->rtt_variance, ap->rtt_spread,
1267 ap->rssi, ap->rssi_spread, ap->range,
1268 ap->range_variance, ap->timestamp);
1270 mutex_unlock(&mvm->mutex);
1272 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1277 static ssize_t iwl_dbgfs_low_latency_write(struct ieee80211_vif *vif, char *buf,
1278 size_t count, loff_t *ppos)
1280 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1281 struct iwl_mvm *mvm = mvmvif->mvm;
1286 ret = kstrtou8(buf, 0, &value);
1292 mutex_lock(&mvm->mutex);
1293 prev = iwl_mvm_vif_low_latency(mvmvif);
1294 mvmvif->low_latency_dbgfs = value;
1295 iwl_mvm_update_low_latency(mvm, vif, prev);
1296 mutex_unlock(&mvm->mutex);
1301 static ssize_t iwl_dbgfs_low_latency_read(struct file *file,
1302 char __user *user_buf,
1303 size_t count, loff_t *ppos)
1305 struct ieee80211_vif *vif = file->private_data;
1306 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1310 len = snprintf(buf, sizeof(buf) - 1,
1311 "traffic=%d\ndbgfs=%d\nvcmd=%d\n",
1312 mvmvif->low_latency_traffic,
1313 mvmvif->low_latency_dbgfs,
1314 mvmvif->low_latency_vcmd);
1315 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1318 static ssize_t iwl_dbgfs_uapsd_misbehaving_read(struct file *file,
1319 char __user *user_buf,
1320 size_t count, loff_t *ppos)
1322 struct ieee80211_vif *vif = file->private_data;
1323 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1327 len = sprintf(buf, "%pM\n", mvmvif->uapsd_misbehaving_bssid);
1328 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1331 static ssize_t iwl_dbgfs_uapsd_misbehaving_write(struct ieee80211_vif *vif,
1332 char *buf, size_t count,
1335 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1336 struct iwl_mvm *mvm = mvmvif->mvm;
1339 mutex_lock(&mvm->mutex);
1340 ret = mac_pton(buf, mvmvif->uapsd_misbehaving_bssid);
1341 mutex_unlock(&mvm->mutex);
1343 return ret ? count : -EINVAL;
1346 static ssize_t iwl_dbgfs_rx_phyinfo_write(struct ieee80211_vif *vif, char *buf,
1347 size_t count, loff_t *ppos)
1349 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1350 struct iwl_mvm *mvm = mvmvif->mvm;
1351 struct ieee80211_chanctx_conf *chanctx_conf;
1352 struct iwl_mvm_phy_ctxt *phy_ctxt;
1356 ret = kstrtou16(buf, 0, &value);
1360 mutex_lock(&mvm->mutex);
1363 chanctx_conf = rcu_dereference(vif->chanctx_conf);
1364 /* make sure the channel context is assigned */
1365 if (!chanctx_conf) {
1367 mutex_unlock(&mvm->mutex);
1371 phy_ctxt = &mvm->phy_ctxts[*(u16 *)chanctx_conf->drv_priv];
1374 mvm->dbgfs_rx_phyinfo = value;
1376 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chanctx_conf->min_def,
1377 chanctx_conf->rx_chains_static,
1378 chanctx_conf->rx_chains_dynamic);
1379 mutex_unlock(&mvm->mutex);
1381 return ret ?: count;
1384 static ssize_t iwl_dbgfs_rx_phyinfo_read(struct file *file,
1385 char __user *user_buf,
1386 size_t count, loff_t *ppos)
1388 struct ieee80211_vif *vif = file->private_data;
1389 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1392 snprintf(buf, sizeof(buf), "0x%04x\n", mvmvif->mvm->dbgfs_rx_phyinfo);
1394 return simple_read_from_buffer(user_buf, count, ppos, buf, sizeof(buf));
1397 static void iwl_dbgfs_quota_check(void *data, u8 *mac,
1398 struct ieee80211_vif *vif)
1400 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1403 if (mvmvif->dbgfs_quota_min)
1407 static ssize_t iwl_dbgfs_quota_min_write(struct ieee80211_vif *vif, char *buf,
1408 size_t count, loff_t *ppos)
1410 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1411 struct iwl_mvm *mvm = mvmvif->mvm;
1415 ret = kstrtou16(buf, 0, &value);
1422 mutex_lock(&mvm->mutex);
1424 mvmvif->dbgfs_quota_min = 0;
1425 ieee80211_iterate_interfaces(mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1426 iwl_dbgfs_quota_check, &ret);
1428 mvmvif->dbgfs_quota_min = value;
1429 iwl_mvm_update_quotas(mvm, false, NULL);
1431 mutex_unlock(&mvm->mutex);
1433 return ret ?: count;
1436 static ssize_t iwl_dbgfs_quota_min_read(struct file *file,
1437 char __user *user_buf,
1438 size_t count, loff_t *ppos)
1440 struct ieee80211_vif *vif = file->private_data;
1441 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1445 len = snprintf(buf, sizeof(buf), "%d\n", mvmvif->dbgfs_quota_min);
1447 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1450 static const char * const chanwidths[] = {
1451 [NL80211_CHAN_WIDTH_20_NOHT] = "noht",
1452 [NL80211_CHAN_WIDTH_20] = "ht20",
1453 [NL80211_CHAN_WIDTH_40] = "ht40",
1454 [NL80211_CHAN_WIDTH_80] = "vht80",
1455 [NL80211_CHAN_WIDTH_80P80] = "vht80p80",
1456 [NL80211_CHAN_WIDTH_160] = "vht160",
1459 static bool iwl_mvm_lqm_notif_wait(struct iwl_notif_wait_data *notif_wait,
1460 struct iwl_rx_packet *pkt, void *data)
1462 struct ieee80211_vif *vif = data;
1463 struct iwl_mvm *mvm =
1464 container_of(notif_wait, struct iwl_mvm, notif_wait);
1465 struct iwl_link_qual_msrmnt_notif *report = (void *)pkt->data;
1466 u32 num_of_stations = le32_to_cpu(report->number_of_stations);
1469 IWL_INFO(mvm, "LQM report:\n");
1470 IWL_INFO(mvm, "\tstatus: %d\n", report->status);
1471 IWL_INFO(mvm, "\tmacID: %d\n", le32_to_cpu(report->mac_id));
1472 IWL_INFO(mvm, "\ttx_frame_dropped: %d\n",
1473 le32_to_cpu(report->tx_frame_dropped));
1474 IWL_INFO(mvm, "\ttime_in_measurement_window: %d us\n",
1475 le32_to_cpu(report->time_in_measurement_window));
1476 IWL_INFO(mvm, "\ttotal_air_time_other_stations: %d\n",
1477 le32_to_cpu(report->total_air_time_other_stations));
1478 IWL_INFO(mvm, "\tchannel_freq: %d\n",
1479 vif->bss_conf.chandef.center_freq1);
1480 IWL_INFO(mvm, "\tchannel_width: %s\n",
1481 chanwidths[vif->bss_conf.chandef.width]);
1482 IWL_INFO(mvm, "\tnumber_of_stations: %d\n", num_of_stations);
1483 for (i = 0; i < num_of_stations; i++)
1484 IWL_INFO(mvm, "\t\tsta[%d]: %d\n", i,
1485 report->frequent_stations_air_time[i]);
1490 static ssize_t iwl_dbgfs_lqm_send_cmd_write(struct ieee80211_vif *vif,
1491 char *buf, size_t count,
1494 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1495 struct iwl_mvm *mvm = mvmvif->mvm;
1496 struct iwl_notification_wait wait_lqm_notif;
1497 static u16 lqm_notif[] = {
1498 WIDE_ID(MAC_CONF_GROUP,
1499 LINK_QUALITY_MEASUREMENT_COMPLETE_NOTIF)
1505 if (sscanf(buf, "%d,%d", &duration, &timeout) != 2)
1508 iwl_init_notification_wait(&mvm->notif_wait, &wait_lqm_notif,
1509 lqm_notif, ARRAY_SIZE(lqm_notif),
1510 iwl_mvm_lqm_notif_wait, vif);
1511 mutex_lock(&mvm->mutex);
1512 err = iwl_mvm_send_lqm_cmd(vif, LQM_CMD_OPERATION_START_MEASUREMENT,
1514 mutex_unlock(&mvm->mutex);
1517 IWL_ERR(mvm, "Failed to send lqm cmdf(err=%d)\n", err);
1518 iwl_remove_notification(&mvm->notif_wait, &wait_lqm_notif);
1522 /* wait for 2 * timeout (safety guard) and convert to jiffies*/
1523 timeout = msecs_to_jiffies((timeout * 2) / 1000);
1525 err = iwl_wait_notification(&mvm->notif_wait, &wait_lqm_notif,
1528 IWL_ERR(mvm, "Getting lqm notif timed out\n");
1533 #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
1534 _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
1535 #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
1536 _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
1537 #define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \
1538 if (!debugfs_create_file(#name, mode, parent, vif, \
1539 &iwl_dbgfs_##name##_ops)) \
1543 MVM_DEBUGFS_READ_FILE_OPS(mac_params);
1544 MVM_DEBUGFS_READ_FILE_OPS(tx_pwr_lmt);
1545 MVM_DEBUGFS_READ_WRITE_FILE_OPS(pm_params, 32);
1546 MVM_DEBUGFS_READ_WRITE_FILE_OPS(bf_params, 256);
1547 MVM_DEBUGFS_READ_WRITE_FILE_OPS(low_latency, 10);
1548 MVM_DEBUGFS_READ_WRITE_FILE_OPS(uapsd_misbehaving, 20);
1549 MVM_DEBUGFS_READ_WRITE_FILE_OPS(rx_phyinfo, 10);
1550 MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_enable, 32);
1551 MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_request, 512);
1552 MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_req_ext, 32);
1553 MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_abort, 32);
1554 MVM_DEBUGFS_READ_FILE_OPS(tof_range_response);
1555 MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_responder_params, 32);
1556 MVM_DEBUGFS_READ_WRITE_FILE_OPS(quota_min, 32);
1557 MVM_DEBUGFS_WRITE_FILE_OPS(lqm_send_cmd, 64);
1558 MVM_DEBUGFS_READ_FILE_OPS(os_device_timediff);
1561 void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1563 struct dentry *dbgfs_dir = vif->debugfs_dir;
1564 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1568 * Check if debugfs directory already exist before creating it.
1569 * This may happen when, for example, resetting hw or suspend-resume
1571 if (!dbgfs_dir || mvmvif->dbgfs_dir)
1574 mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir);
1576 if (!mvmvif->dbgfs_dir) {
1577 IWL_ERR(mvm, "Failed to create debugfs directory under %pd\n",
1582 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM &&
1583 ((vif->type == NL80211_IFTYPE_STATION && !vif->p2p) ||
1584 (vif->type == NL80211_IFTYPE_STATION && vif->p2p)))
1585 MVM_DEBUGFS_ADD_FILE_VIF(pm_params, mvmvif->dbgfs_dir, S_IWUSR |
1588 MVM_DEBUGFS_ADD_FILE_VIF(tx_pwr_lmt, mvmvif->dbgfs_dir, S_IRUSR);
1589 MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir, S_IRUSR);
1590 MVM_DEBUGFS_ADD_FILE_VIF(low_latency, mvmvif->dbgfs_dir,
1592 MVM_DEBUGFS_ADD_FILE_VIF(uapsd_misbehaving, mvmvif->dbgfs_dir,
1594 MVM_DEBUGFS_ADD_FILE_VIF(rx_phyinfo, mvmvif->dbgfs_dir,
1596 MVM_DEBUGFS_ADD_FILE_VIF(quota_min, mvmvif->dbgfs_dir,
1598 MVM_DEBUGFS_ADD_FILE_VIF(lqm_send_cmd, mvmvif->dbgfs_dir, S_IWUSR);
1599 MVM_DEBUGFS_ADD_FILE_VIF(os_device_timediff,
1600 mvmvif->dbgfs_dir, S_IRUSR);
1602 if (vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
1603 mvmvif == mvm->bf_allowed_vif)
1604 MVM_DEBUGFS_ADD_FILE_VIF(bf_params, mvmvif->dbgfs_dir,
1607 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TOF_SUPPORT) &&
1608 !vif->p2p && (vif->type != NL80211_IFTYPE_P2P_DEVICE)) {
1609 if (IWL_MVM_TOF_IS_RESPONDER && vif->type == NL80211_IFTYPE_AP)
1610 MVM_DEBUGFS_ADD_FILE_VIF(tof_responder_params,
1614 MVM_DEBUGFS_ADD_FILE_VIF(tof_range_request, mvmvif->dbgfs_dir,
1616 MVM_DEBUGFS_ADD_FILE_VIF(tof_range_req_ext, mvmvif->dbgfs_dir,
1618 MVM_DEBUGFS_ADD_FILE_VIF(tof_enable, mvmvif->dbgfs_dir,
1620 MVM_DEBUGFS_ADD_FILE_VIF(tof_range_abort, mvmvif->dbgfs_dir,
1622 MVM_DEBUGFS_ADD_FILE_VIF(tof_range_response, mvmvif->dbgfs_dir,
1627 * Create symlink for convenience pointing to interface specific
1628 * debugfs entries for the driver. For example, under
1629 * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/
1631 * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/
1633 snprintf(buf, 100, "../../../%pd3/%pd",
1637 mvmvif->dbgfs_slink = debugfs_create_symlink(dbgfs_dir->d_name.name,
1638 mvm->debugfs_dir, buf);
1639 if (!mvmvif->dbgfs_slink)
1640 IWL_ERR(mvm, "Can't create debugfs symbolic link under %pd\n",
1644 IWL_ERR(mvm, "Can't create debugfs entity\n");
1647 void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1649 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1651 debugfs_remove(mvmvif->dbgfs_slink);
1652 mvmvif->dbgfs_slink = NULL;
1654 debugfs_remove_recursive(mvmvif->dbgfs_dir);
1655 mvmvif->dbgfs_dir = NULL;