iwlwifi: mvm: ToF - fill bssid of responder configuration
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / mvm / debugfs-vif.c
CommitLineData
820a1a50
JB
1/******************************************************************************
2 *
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.
5 *
6 * GPL LICENSE SUMMARY
7 *
51368bf7 8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
25870cb7 9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
820a1a50
JB
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
23 * USA
24 *
25 * The full GNU General Public License is included in this distribution
26 * in the file called COPYING.
27 *
28 * Contact Information:
29 * Intel Linux Wireless <ilw@linux.intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 *
32 * BSD LICENSE
33 *
51368bf7 34 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
25870cb7 35 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
820a1a50
JB
36 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 *
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
47 * distribution.
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *
64 *****************************************************************************/
65#include "mvm.h"
ce792918 66#include "fw-api-tof.h"
820a1a50
JB
67#include "debugfs.h"
68
e45a941d
AB
69static void iwl_dbgfs_update_pm(struct iwl_mvm *mvm,
70 struct ieee80211_vif *vif,
71 enum iwl_dbgfs_pm_mask param, int val)
72{
73 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
74 struct iwl_dbgfs_pm *dbgfs_pm = &mvmvif->dbgfs_pm;
75
76 dbgfs_pm->mask |= param;
77
78 switch (param) {
79 case MVM_DEBUGFS_PM_KEEP_ALIVE: {
717e2390 80 int dtimper = vif->bss_conf.dtim_period ?: 1;
e45a941d
AB
81 int dtimper_msec = dtimper * vif->bss_conf.beacon_int;
82
83 IWL_DEBUG_POWER(mvm, "debugfs: set keep_alive= %d sec\n", val);
84 if (val * MSEC_PER_SEC < 3 * dtimper_msec)
85 IWL_WARN(mvm,
86 "debugfs: keep alive period (%ld msec) is less than minimum required (%d msec)\n",
87 val * MSEC_PER_SEC, 3 * dtimper_msec);
88 dbgfs_pm->keep_alive_seconds = val;
89 break;
90 }
91 case MVM_DEBUGFS_PM_SKIP_OVER_DTIM:
92 IWL_DEBUG_POWER(mvm, "skip_over_dtim %s\n",
93 val ? "enabled" : "disabled");
94 dbgfs_pm->skip_over_dtim = val;
95 break;
96 case MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS:
97 IWL_DEBUG_POWER(mvm, "skip_dtim_periods=%d\n", val);
98 dbgfs_pm->skip_dtim_periods = val;
99 break;
100 case MVM_DEBUGFS_PM_RX_DATA_TIMEOUT:
101 IWL_DEBUG_POWER(mvm, "rx_data_timeout=%d\n", val);
102 dbgfs_pm->rx_data_timeout = val;
103 break;
104 case MVM_DEBUGFS_PM_TX_DATA_TIMEOUT:
105 IWL_DEBUG_POWER(mvm, "tx_data_timeout=%d\n", val);
106 dbgfs_pm->tx_data_timeout = val;
107 break;
e45a941d
AB
108 case MVM_DEBUGFS_PM_LPRX_ENA:
109 IWL_DEBUG_POWER(mvm, "lprx %s\n", val ? "enabled" : "disabled");
110 dbgfs_pm->lprx_ena = val;
111 break;
112 case MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD:
113 IWL_DEBUG_POWER(mvm, "lprx_rssi_threshold=%d\n", val);
114 dbgfs_pm->lprx_rssi_threshold = val;
115 break;
116 case MVM_DEBUGFS_PM_SNOOZE_ENABLE:
117 IWL_DEBUG_POWER(mvm, "snooze_enable=%d\n", val);
118 dbgfs_pm->snooze_ena = val;
119 break;
120 case MVM_DEBUGFS_PM_UAPSD_MISBEHAVING:
121 IWL_DEBUG_POWER(mvm, "uapsd_misbehaving_enable=%d\n", val);
122 dbgfs_pm->uapsd_misbehaving = val;
123 break;
84fd7608
EP
124 case MVM_DEBUGFS_PM_USE_PS_POLL:
125 IWL_DEBUG_POWER(mvm, "use_ps_poll=%d\n", val);
126 dbgfs_pm->use_ps_poll = val;
127 break;
e45a941d
AB
128 }
129}
130
131static ssize_t iwl_dbgfs_pm_params_write(struct ieee80211_vif *vif, char *buf,
132 size_t count, loff_t *ppos)
133{
134 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
135 struct iwl_mvm *mvm = mvmvif->mvm;
136 enum iwl_dbgfs_pm_mask param;
137 int val, ret;
138
139 if (!strncmp("keep_alive=", buf, 11)) {
140 if (sscanf(buf + 11, "%d", &val) != 1)
141 return -EINVAL;
142 param = MVM_DEBUGFS_PM_KEEP_ALIVE;
143 } else if (!strncmp("skip_over_dtim=", buf, 15)) {
144 if (sscanf(buf + 15, "%d", &val) != 1)
145 return -EINVAL;
146 param = MVM_DEBUGFS_PM_SKIP_OVER_DTIM;
147 } else if (!strncmp("skip_dtim_periods=", buf, 18)) {
148 if (sscanf(buf + 18, "%d", &val) != 1)
149 return -EINVAL;
150 param = MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS;
151 } else if (!strncmp("rx_data_timeout=", buf, 16)) {
152 if (sscanf(buf + 16, "%d", &val) != 1)
153 return -EINVAL;
154 param = MVM_DEBUGFS_PM_RX_DATA_TIMEOUT;
155 } else if (!strncmp("tx_data_timeout=", buf, 16)) {
156 if (sscanf(buf + 16, "%d", &val) != 1)
157 return -EINVAL;
158 param = MVM_DEBUGFS_PM_TX_DATA_TIMEOUT;
e45a941d
AB
159 } else if (!strncmp("lprx=", buf, 5)) {
160 if (sscanf(buf + 5, "%d", &val) != 1)
161 return -EINVAL;
162 param = MVM_DEBUGFS_PM_LPRX_ENA;
163 } else if (!strncmp("lprx_rssi_threshold=", buf, 20)) {
164 if (sscanf(buf + 20, "%d", &val) != 1)
165 return -EINVAL;
166 if (val > POWER_LPRX_RSSI_THRESHOLD_MAX || val <
167 POWER_LPRX_RSSI_THRESHOLD_MIN)
168 return -EINVAL;
169 param = MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD;
170 } else if (!strncmp("snooze_enable=", buf, 14)) {
171 if (sscanf(buf + 14, "%d", &val) != 1)
172 return -EINVAL;
173 param = MVM_DEBUGFS_PM_SNOOZE_ENABLE;
174 } else if (!strncmp("uapsd_misbehaving=", buf, 18)) {
175 if (sscanf(buf + 18, "%d", &val) != 1)
176 return -EINVAL;
177 param = MVM_DEBUGFS_PM_UAPSD_MISBEHAVING;
84fd7608
EP
178 } else if (!strncmp("use_ps_poll=", buf, 12)) {
179 if (sscanf(buf + 12, "%d", &val) != 1)
180 return -EINVAL;
181 param = MVM_DEBUGFS_PM_USE_PS_POLL;
e45a941d
AB
182 } else {
183 return -EINVAL;
184 }
185
186 mutex_lock(&mvm->mutex);
187 iwl_dbgfs_update_pm(mvm, vif, param, val);
999609f1 188 ret = iwl_mvm_power_update_mac(mvm);
e45a941d
AB
189 mutex_unlock(&mvm->mutex);
190
191 return ret ?: count;
192}
193
25870cb7
MG
194static ssize_t iwl_dbgfs_tx_pwr_lmt_read(struct file *file,
195 char __user *user_buf,
196 size_t count, loff_t *ppos)
197{
198 struct ieee80211_vif *vif = file->private_data;
199 char buf[64];
200 int bufsz = sizeof(buf);
201 int pos;
202
203 pos = scnprintf(buf, bufsz, "bss limit = %d\n",
204 vif->bss_conf.txpower);
205
206 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
207}
208
e45a941d
AB
209static ssize_t iwl_dbgfs_pm_params_read(struct file *file,
210 char __user *user_buf,
211 size_t count, loff_t *ppos)
212{
213 struct ieee80211_vif *vif = file->private_data;
214 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
215 struct iwl_mvm *mvm = mvmvif->mvm;
216 char buf[512];
217 int bufsz = sizeof(buf);
218 int pos;
219
c1cb92fc 220 pos = iwl_mvm_power_mac_dbgfs_read(mvm, vif, buf, bufsz);
e45a941d
AB
221
222 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
223}
224
820a1a50
JB
225static ssize_t iwl_dbgfs_mac_params_read(struct file *file,
226 char __user *user_buf,
227 size_t count, loff_t *ppos)
228{
229 struct ieee80211_vif *vif = file->private_data;
230 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
7f09d704 231 struct iwl_mvm *mvm = mvmvif->mvm;
820a1a50
JB
232 u8 ap_sta_id;
233 struct ieee80211_chanctx_conf *chanctx_conf;
234 char buf[512];
235 int bufsz = sizeof(buf);
236 int pos = 0;
237 int i;
238
239 mutex_lock(&mvm->mutex);
240
241 ap_sta_id = mvmvif->ap_sta_id;
242
2284b951
EG
243 switch (ieee80211_vif_type_p2p(vif)) {
244 case NL80211_IFTYPE_ADHOC:
245 pos += scnprintf(buf+pos, bufsz-pos, "type: ibss\n");
246 break;
247 case NL80211_IFTYPE_STATION:
248 pos += scnprintf(buf+pos, bufsz-pos, "type: bss\n");
249 break;
250 case NL80211_IFTYPE_AP:
251 pos += scnprintf(buf+pos, bufsz-pos, "type: ap\n");
252 break;
253 case NL80211_IFTYPE_P2P_CLIENT:
254 pos += scnprintf(buf+pos, bufsz-pos, "type: p2p client\n");
255 break;
256 case NL80211_IFTYPE_P2P_GO:
257 pos += scnprintf(buf+pos, bufsz-pos, "type: p2p go\n");
258 break;
259 case NL80211_IFTYPE_P2P_DEVICE:
260 pos += scnprintf(buf+pos, bufsz-pos, "type: p2p dev\n");
261 break;
262 default:
263 break;
264 }
265
820a1a50
JB
266 pos += scnprintf(buf+pos, bufsz-pos, "mac id/color: %d / %d\n",
267 mvmvif->id, mvmvif->color);
268 pos += scnprintf(buf+pos, bufsz-pos, "bssid: %pM\n",
269 vif->bss_conf.bssid);
270 pos += scnprintf(buf+pos, bufsz-pos, "QoS:\n");
271 for (i = 0; i < ARRAY_SIZE(mvmvif->queue_params); i++)
272 pos += scnprintf(buf+pos, bufsz-pos,
273 "\t%d: txop:%d - cw_min:%d - cw_max = %d - aifs = %d upasd = %d\n",
274 i, mvmvif->queue_params[i].txop,
275 mvmvif->queue_params[i].cw_min,
276 mvmvif->queue_params[i].cw_max,
277 mvmvif->queue_params[i].aifs,
278 mvmvif->queue_params[i].uapsd);
279
280 if (vif->type == NL80211_IFTYPE_STATION &&
281 ap_sta_id != IWL_MVM_STATION_COUNT) {
282 struct ieee80211_sta *sta;
820a1a50
JB
283
284 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[ap_sta_id],
285 lockdep_is_held(&mvm->mutex));
1ddbbb0c 286 if (!IS_ERR_OR_NULL(sta)) {
9d8ce6af 287 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
1ddbbb0c
JB
288
289 pos += scnprintf(buf+pos, bufsz-pos,
1fa477c6 290 "ap_sta_id %d - reduced Tx power %d\n",
1ddbbb0c 291 ap_sta_id,
1fa477c6 292 mvm_sta->bt_reduced_txpower);
1ddbbb0c 293 }
820a1a50
JB
294 }
295
296 rcu_read_lock();
297 chanctx_conf = rcu_dereference(vif->chanctx_conf);
298 if (chanctx_conf)
299 pos += scnprintf(buf+pos, bufsz-pos,
300 "idle rx chains %d, active rx chains: %d\n",
301 chanctx_conf->rx_chains_static,
302 chanctx_conf->rx_chains_dynamic);
303 rcu_read_unlock();
304
305 mutex_unlock(&mvm->mutex);
306
307 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
308}
309
e45a941d
AB
310static void iwl_dbgfs_update_bf(struct ieee80211_vif *vif,
311 enum iwl_dbgfs_bf_mask param, int value)
312{
313 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
314 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
315
316 dbgfs_bf->mask |= param;
317
318 switch (param) {
319 case MVM_DEBUGFS_BF_ENERGY_DELTA:
320 dbgfs_bf->bf_energy_delta = value;
321 break;
322 case MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA:
323 dbgfs_bf->bf_roaming_energy_delta = value;
324 break;
325 case MVM_DEBUGFS_BF_ROAMING_STATE:
326 dbgfs_bf->bf_roaming_state = value;
327 break;
328 case MVM_DEBUGFS_BF_TEMP_THRESHOLD:
329 dbgfs_bf->bf_temp_threshold = value;
330 break;
331 case MVM_DEBUGFS_BF_TEMP_FAST_FILTER:
332 dbgfs_bf->bf_temp_fast_filter = value;
333 break;
334 case MVM_DEBUGFS_BF_TEMP_SLOW_FILTER:
335 dbgfs_bf->bf_temp_slow_filter = value;
336 break;
337 case MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER:
338 dbgfs_bf->bf_enable_beacon_filter = value;
339 break;
340 case MVM_DEBUGFS_BF_DEBUG_FLAG:
341 dbgfs_bf->bf_debug_flag = value;
342 break;
343 case MVM_DEBUGFS_BF_ESCAPE_TIMER:
344 dbgfs_bf->bf_escape_timer = value;
345 break;
346 case MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT:
347 dbgfs_bf->ba_enable_beacon_abort = value;
348 break;
349 case MVM_DEBUGFS_BA_ESCAPE_TIMER:
350 dbgfs_bf->ba_escape_timer = value;
351 break;
352 }
353}
354
355static ssize_t iwl_dbgfs_bf_params_write(struct ieee80211_vif *vif, char *buf,
356 size_t count, loff_t *ppos)
357{
358 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
359 struct iwl_mvm *mvm = mvmvif->mvm;
360 enum iwl_dbgfs_bf_mask param;
361 int value, ret = 0;
362
363 if (!strncmp("bf_energy_delta=", buf, 16)) {
364 if (sscanf(buf+16, "%d", &value) != 1)
365 return -EINVAL;
366 if (value < IWL_BF_ENERGY_DELTA_MIN ||
367 value > IWL_BF_ENERGY_DELTA_MAX)
368 return -EINVAL;
369 param = MVM_DEBUGFS_BF_ENERGY_DELTA;
370 } else if (!strncmp("bf_roaming_energy_delta=", buf, 24)) {
371 if (sscanf(buf+24, "%d", &value) != 1)
372 return -EINVAL;
373 if (value < IWL_BF_ROAMING_ENERGY_DELTA_MIN ||
374 value > IWL_BF_ROAMING_ENERGY_DELTA_MAX)
375 return -EINVAL;
376 param = MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA;
377 } else if (!strncmp("bf_roaming_state=", buf, 17)) {
378 if (sscanf(buf+17, "%d", &value) != 1)
379 return -EINVAL;
380 if (value < IWL_BF_ROAMING_STATE_MIN ||
381 value > IWL_BF_ROAMING_STATE_MAX)
382 return -EINVAL;
383 param = MVM_DEBUGFS_BF_ROAMING_STATE;
384 } else if (!strncmp("bf_temp_threshold=", buf, 18)) {
385 if (sscanf(buf+18, "%d", &value) != 1)
386 return -EINVAL;
387 if (value < IWL_BF_TEMP_THRESHOLD_MIN ||
388 value > IWL_BF_TEMP_THRESHOLD_MAX)
389 return -EINVAL;
390 param = MVM_DEBUGFS_BF_TEMP_THRESHOLD;
391 } else if (!strncmp("bf_temp_fast_filter=", buf, 20)) {
392 if (sscanf(buf+20, "%d", &value) != 1)
393 return -EINVAL;
394 if (value < IWL_BF_TEMP_FAST_FILTER_MIN ||
395 value > IWL_BF_TEMP_FAST_FILTER_MAX)
396 return -EINVAL;
397 param = MVM_DEBUGFS_BF_TEMP_FAST_FILTER;
398 } else if (!strncmp("bf_temp_slow_filter=", buf, 20)) {
399 if (sscanf(buf+20, "%d", &value) != 1)
400 return -EINVAL;
401 if (value < IWL_BF_TEMP_SLOW_FILTER_MIN ||
402 value > IWL_BF_TEMP_SLOW_FILTER_MAX)
403 return -EINVAL;
404 param = MVM_DEBUGFS_BF_TEMP_SLOW_FILTER;
405 } else if (!strncmp("bf_enable_beacon_filter=", buf, 24)) {
406 if (sscanf(buf+24, "%d", &value) != 1)
407 return -EINVAL;
408 if (value < 0 || value > 1)
409 return -EINVAL;
410 param = MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER;
411 } else if (!strncmp("bf_debug_flag=", buf, 14)) {
412 if (sscanf(buf+14, "%d", &value) != 1)
413 return -EINVAL;
414 if (value < 0 || value > 1)
415 return -EINVAL;
416 param = MVM_DEBUGFS_BF_DEBUG_FLAG;
417 } else if (!strncmp("bf_escape_timer=", buf, 16)) {
418 if (sscanf(buf+16, "%d", &value) != 1)
419 return -EINVAL;
420 if (value < IWL_BF_ESCAPE_TIMER_MIN ||
421 value > IWL_BF_ESCAPE_TIMER_MAX)
422 return -EINVAL;
423 param = MVM_DEBUGFS_BF_ESCAPE_TIMER;
424 } else if (!strncmp("ba_escape_timer=", buf, 16)) {
425 if (sscanf(buf+16, "%d", &value) != 1)
426 return -EINVAL;
427 if (value < IWL_BA_ESCAPE_TIMER_MIN ||
428 value > IWL_BA_ESCAPE_TIMER_MAX)
429 return -EINVAL;
430 param = MVM_DEBUGFS_BA_ESCAPE_TIMER;
431 } else if (!strncmp("ba_enable_beacon_abort=", buf, 23)) {
432 if (sscanf(buf+23, "%d", &value) != 1)
433 return -EINVAL;
434 if (value < 0 || value > 1)
435 return -EINVAL;
436 param = MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT;
437 } else {
438 return -EINVAL;
439 }
440
441 mutex_lock(&mvm->mutex);
442 iwl_dbgfs_update_bf(vif, param, value);
443 if (param == MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER && !value)
a1022927 444 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
e45a941d 445 else
a1022927 446 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
e45a941d
AB
447 mutex_unlock(&mvm->mutex);
448
449 return ret ?: count;
450}
451
452static ssize_t iwl_dbgfs_bf_params_read(struct file *file,
453 char __user *user_buf,
454 size_t count, loff_t *ppos)
455{
456 struct ieee80211_vif *vif = file->private_data;
457 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
458 char buf[256];
459 int pos = 0;
460 const size_t bufsz = sizeof(buf);
461 struct iwl_beacon_filter_cmd cmd = {
462 IWL_BF_CMD_CONFIG_DEFAULTS,
463 .bf_enable_beacon_filter =
464 cpu_to_le32(IWL_BF_ENABLE_BEACON_FILTER_DEFAULT),
465 .ba_enable_beacon_abort =
466 cpu_to_le32(IWL_BA_ENABLE_BEACON_ABORT_DEFAULT),
467 };
468
469 iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
470 if (mvmvif->bf_data.bf_enabled)
471 cmd.bf_enable_beacon_filter = cpu_to_le32(1);
472 else
473 cmd.bf_enable_beacon_filter = 0;
474
475 pos += scnprintf(buf+pos, bufsz-pos, "bf_energy_delta = %d\n",
476 le32_to_cpu(cmd.bf_energy_delta));
477 pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_energy_delta = %d\n",
478 le32_to_cpu(cmd.bf_roaming_energy_delta));
479 pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_state = %d\n",
480 le32_to_cpu(cmd.bf_roaming_state));
481 pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_threshold = %d\n",
482 le32_to_cpu(cmd.bf_temp_threshold));
483 pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_fast_filter = %d\n",
484 le32_to_cpu(cmd.bf_temp_fast_filter));
485 pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_slow_filter = %d\n",
486 le32_to_cpu(cmd.bf_temp_slow_filter));
487 pos += scnprintf(buf+pos, bufsz-pos, "bf_enable_beacon_filter = %d\n",
488 le32_to_cpu(cmd.bf_enable_beacon_filter));
489 pos += scnprintf(buf+pos, bufsz-pos, "bf_debug_flag = %d\n",
490 le32_to_cpu(cmd.bf_debug_flag));
491 pos += scnprintf(buf+pos, bufsz-pos, "bf_escape_timer = %d\n",
492 le32_to_cpu(cmd.bf_escape_timer));
493 pos += scnprintf(buf+pos, bufsz-pos, "ba_escape_timer = %d\n",
494 le32_to_cpu(cmd.ba_escape_timer));
495 pos += scnprintf(buf+pos, bufsz-pos, "ba_enable_beacon_abort = %d\n",
496 le32_to_cpu(cmd.ba_enable_beacon_abort));
497
498 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
499}
500
ce792918
GG
501static inline char *iwl_dbgfs_is_match(char *name, char *buf)
502{
503 int len = strlen(name);
504
505 return !strncmp(name, buf, len) ? buf + len : NULL;
506}
507
508static ssize_t iwl_dbgfs_tof_enable_write(struct ieee80211_vif *vif,
509 char *buf,
510 size_t count, loff_t *ppos)
511{
512 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
513 struct iwl_mvm *mvm = mvmvif->mvm;
514 int value, ret = -EINVAL;
515 char *data;
516
517 mutex_lock(&mvm->mutex);
518
519 data = iwl_dbgfs_is_match("tof_disabled=", buf);
520 if (data) {
521 ret = kstrtou32(data, 10, &value);
522 if (ret == 0)
523 mvm->tof_data.tof_cfg.tof_disabled = value;
524 goto out;
525 }
526
527 data = iwl_dbgfs_is_match("one_sided_disabled=", buf);
528 if (data) {
529 ret = kstrtou32(data, 10, &value);
530 if (ret == 0)
531 mvm->tof_data.tof_cfg.one_sided_disabled = value;
532 goto out;
533 }
534
535 data = iwl_dbgfs_is_match("is_debug_mode=", buf);
536 if (data) {
537 ret = kstrtou32(data, 10, &value);
538 if (ret == 0)
539 mvm->tof_data.tof_cfg.is_debug_mode = value;
540 goto out;
541 }
542
543 data = iwl_dbgfs_is_match("is_buf=", buf);
544 if (data) {
545 ret = kstrtou32(data, 10, &value);
546 if (ret == 0)
547 mvm->tof_data.tof_cfg.is_buf_required = value;
548 goto out;
549 }
550
551 data = iwl_dbgfs_is_match("send_tof_cfg=", buf);
552 if (data) {
553 ret = kstrtou32(data, 10, &value);
554 if (ret == 0 && value) {
555 ret = iwl_mvm_tof_config_cmd(mvm);
556 goto out;
557 }
558 }
559
560out:
561 mutex_unlock(&mvm->mutex);
562
563 return ret ?: count;
564}
565
566static ssize_t iwl_dbgfs_tof_enable_read(struct file *file,
567 char __user *user_buf,
568 size_t count, loff_t *ppos)
569{
570 struct ieee80211_vif *vif = file->private_data;
571 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
572 struct iwl_mvm *mvm = mvmvif->mvm;
573 char buf[256];
574 int pos = 0;
575 const size_t bufsz = sizeof(buf);
576 struct iwl_tof_config_cmd *cmd;
577
578 cmd = &mvm->tof_data.tof_cfg;
579
580 mutex_lock(&mvm->mutex);
581
582 pos += scnprintf(buf + pos, bufsz - pos, "tof_disabled = %d\n",
583 cmd->tof_disabled);
584 pos += scnprintf(buf + pos, bufsz - pos, "one_sided_disabled = %d\n",
585 cmd->one_sided_disabled);
586 pos += scnprintf(buf + pos, bufsz - pos, "is_debug_mode = %d\n",
587 cmd->is_debug_mode);
588 pos += scnprintf(buf + pos, bufsz - pos, "is_buf_required = %d\n",
589 cmd->is_buf_required);
590
591 mutex_unlock(&mvm->mutex);
592
593 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
594}
595
596static ssize_t iwl_dbgfs_tof_responder_params_write(struct ieee80211_vif *vif,
597 char *buf,
598 size_t count, loff_t *ppos)
599{
600 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
601 struct iwl_mvm *mvm = mvmvif->mvm;
602 int value, ret = 0;
603 char *data;
604
605 mutex_lock(&mvm->mutex);
606
607 data = iwl_dbgfs_is_match("burst_period=", buf);
608 if (data) {
609 ret = kstrtou32(data, 10, &value);
610 if (!ret)
611 mvm->tof_data.responder_cfg.burst_period =
612 cpu_to_le16(value);
613 goto out;
614 }
615
616 data = iwl_dbgfs_is_match("min_delta_ftm=", buf);
617 if (data) {
618 ret = kstrtou32(data, 10, &value);
619 if (ret == 0)
620 mvm->tof_data.responder_cfg.min_delta_ftm = value;
621 goto out;
622 }
623
624 data = iwl_dbgfs_is_match("burst_duration=", buf);
625 if (data) {
626 ret = kstrtou32(data, 10, &value);
627 if (ret == 0)
628 mvm->tof_data.responder_cfg.burst_duration = value;
629 goto out;
630 }
631
632 data = iwl_dbgfs_is_match("num_of_burst_exp=", buf);
633 if (data) {
634 ret = kstrtou32(data, 10, &value);
635 if (ret == 0)
636 mvm->tof_data.responder_cfg.num_of_burst_exp = value;
637 goto out;
638 }
639
640 data = iwl_dbgfs_is_match("abort_responder=", buf);
641 if (data) {
642 ret = kstrtou32(data, 10, &value);
643 if (ret == 0)
644 mvm->tof_data.responder_cfg.abort_responder = value;
645 goto out;
646 }
647
648 data = iwl_dbgfs_is_match("get_ch_est=", buf);
649 if (data) {
650 ret = kstrtou32(data, 10, &value);
651 if (ret == 0)
652 mvm->tof_data.responder_cfg.get_ch_est = value;
653 goto out;
654 }
655
656 data = iwl_dbgfs_is_match("recv_sta_req_params=", buf);
657 if (data) {
658 ret = kstrtou32(data, 10, &value);
659 if (ret == 0)
660 mvm->tof_data.responder_cfg.recv_sta_req_params = value;
661 goto out;
662 }
663
664 data = iwl_dbgfs_is_match("channel_num=", buf);
665 if (data) {
666 ret = kstrtou32(data, 10, &value);
667 if (ret == 0)
668 mvm->tof_data.responder_cfg.channel_num = value;
669 goto out;
670 }
671
672 data = iwl_dbgfs_is_match("bandwidth=", buf);
673 if (data) {
674 ret = kstrtou32(data, 10, &value);
675 if (ret == 0)
676 mvm->tof_data.responder_cfg.bandwidth = value;
677 goto out;
678 }
679
680 data = iwl_dbgfs_is_match("rate=", buf);
681 if (data) {
682 ret = kstrtou32(data, 10, &value);
683 if (ret == 0)
684 mvm->tof_data.responder_cfg.rate = value;
685 goto out;
686 }
687
688 data = iwl_dbgfs_is_match("bssid=", buf);
689 if (data) {
690 u8 *mac = mvm->tof_data.responder_cfg.bssid;
691
692 if (!mac_pton(data, mac)) {
693 ret = -EINVAL;
694 goto out;
695 }
696 }
697
698 data = iwl_dbgfs_is_match("tsf_timer_offset_msecs=", buf);
699 if (data) {
700 ret = kstrtou32(data, 10, &value);
701 if (ret == 0)
702 mvm->tof_data.responder_cfg.tsf_timer_offset_msecs =
703 cpu_to_le16(value);
704 goto out;
705 }
706
707 data = iwl_dbgfs_is_match("toa_offset=", buf);
708 if (data) {
709 ret = kstrtou32(data, 10, &value);
710 if (ret == 0)
711 mvm->tof_data.responder_cfg.toa_offset =
712 cpu_to_le16(value);
713 goto out;
714 }
715
716 data = iwl_dbgfs_is_match("ctrl_ch_position=", buf);
717 if (data) {
718 ret = kstrtou32(data, 10, &value);
719 if (ret == 0)
720 mvm->tof_data.responder_cfg.ctrl_ch_position = value;
721 goto out;
722 }
723
724 data = iwl_dbgfs_is_match("ftm_per_burst=", buf);
725 if (data) {
726 ret = kstrtou32(data, 10, &value);
727 if (ret == 0)
728 mvm->tof_data.responder_cfg.ftm_per_burst = value;
729 goto out;
730 }
731
732 data = iwl_dbgfs_is_match("ftm_resp_ts_avail=", buf);
733 if (data) {
734 ret = kstrtou32(data, 10, &value);
735 if (ret == 0)
736 mvm->tof_data.responder_cfg.ftm_resp_ts_avail = value;
737 goto out;
738 }
739
740 data = iwl_dbgfs_is_match("asap_mode=", buf);
741 if (data) {
742 ret = kstrtou32(data, 10, &value);
743 if (ret == 0)
744 mvm->tof_data.responder_cfg.asap_mode = value;
745 goto out;
746 }
747
748 data = iwl_dbgfs_is_match("send_responder_cfg=", buf);
749 if (data) {
750 ret = kstrtou32(data, 10, &value);
751 if (ret == 0 && value) {
752 ret = iwl_mvm_tof_responder_cmd(mvm, vif);
753 goto out;
754 }
755 }
756
757out:
758 mutex_unlock(&mvm->mutex);
759
760 return ret ?: count;
761}
762
763static ssize_t iwl_dbgfs_tof_responder_params_read(struct file *file,
764 char __user *user_buf,
765 size_t count, loff_t *ppos)
766{
767 struct ieee80211_vif *vif = file->private_data;
768 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
769 struct iwl_mvm *mvm = mvmvif->mvm;
770 char buf[256];
771 int pos = 0;
772 const size_t bufsz = sizeof(buf);
773 struct iwl_tof_responder_config_cmd *cmd;
774
775 cmd = &mvm->tof_data.responder_cfg;
776
777 mutex_lock(&mvm->mutex);
778
779 pos += scnprintf(buf + pos, bufsz - pos, "burst_period = %d\n",
780 le16_to_cpu(cmd->burst_period));
781 pos += scnprintf(buf + pos, bufsz - pos, "burst_duration = %d\n",
782 cmd->burst_duration);
783 pos += scnprintf(buf + pos, bufsz - pos, "bandwidth = %d\n",
784 cmd->bandwidth);
785 pos += scnprintf(buf + pos, bufsz - pos, "channel_num = %d\n",
786 cmd->channel_num);
787 pos += scnprintf(buf + pos, bufsz - pos, "ctrl_ch_position = 0x%x\n",
788 cmd->ctrl_ch_position);
789 pos += scnprintf(buf + pos, bufsz - pos, "bssid = %pM\n",
790 cmd->bssid);
791 pos += scnprintf(buf + pos, bufsz - pos, "min_delta_ftm = %d\n",
792 cmd->min_delta_ftm);
793 pos += scnprintf(buf + pos, bufsz - pos, "num_of_burst_exp = %d\n",
794 cmd->num_of_burst_exp);
795 pos += scnprintf(buf + pos, bufsz - pos, "rate = %d\n", cmd->rate);
796 pos += scnprintf(buf + pos, bufsz - pos, "abort_responder = %d\n",
797 cmd->abort_responder);
798 pos += scnprintf(buf + pos, bufsz - pos, "get_ch_est = %d\n",
799 cmd->get_ch_est);
800 pos += scnprintf(buf + pos, bufsz - pos, "recv_sta_req_params = %d\n",
801 cmd->recv_sta_req_params);
802 pos += scnprintf(buf + pos, bufsz - pos, "ftm_per_burst = %d\n",
803 cmd->ftm_per_burst);
804 pos += scnprintf(buf + pos, bufsz - pos, "ftm_resp_ts_avail = %d\n",
805 cmd->ftm_resp_ts_avail);
806 pos += scnprintf(buf + pos, bufsz - pos, "asap_mode = %d\n",
807 cmd->asap_mode);
808 pos += scnprintf(buf + pos, bufsz - pos,
809 "tsf_timer_offset_msecs = %d\n",
810 le16_to_cpu(cmd->tsf_timer_offset_msecs));
811 pos += scnprintf(buf + pos, bufsz - pos, "toa_offset = %d\n",
812 le16_to_cpu(cmd->toa_offset));
813
814 mutex_unlock(&mvm->mutex);
815
816 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
817}
818
819static ssize_t iwl_dbgfs_tof_range_request_write(struct ieee80211_vif *vif,
820 char *buf, size_t count,
821 loff_t *ppos)
822{
823 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
824 struct iwl_mvm *mvm = mvmvif->mvm;
825 int value, ret = 0;
826 char *data;
827
828 mutex_lock(&mvm->mutex);
829
830 data = iwl_dbgfs_is_match("request_id=", buf);
831 if (data) {
832 ret = kstrtou32(data, 10, &value);
833 if (ret == 0)
834 mvm->tof_data.range_req.request_id = value;
835 goto out;
836 }
837
838 data = iwl_dbgfs_is_match("initiator=", buf);
839 if (data) {
840 ret = kstrtou32(data, 10, &value);
841 if (ret == 0)
842 mvm->tof_data.range_req.initiator = value;
843 goto out;
844 }
845
846 data = iwl_dbgfs_is_match("one_sided_los_disable=", buf);
847 if (data) {
848 ret = kstrtou32(data, 10, &value);
849 if (ret == 0)
850 mvm->tof_data.range_req.one_sided_los_disable = value;
851 goto out;
852 }
853
854 data = iwl_dbgfs_is_match("req_timeout=", buf);
855 if (data) {
856 ret = kstrtou32(data, 10, &value);
857 if (ret == 0)
858 mvm->tof_data.range_req.req_timeout = value;
859 goto out;
860 }
861
862 data = iwl_dbgfs_is_match("report_policy=", buf);
863 if (data) {
864 ret = kstrtou32(data, 10, &value);
865 if (ret == 0)
866 mvm->tof_data.range_req.report_policy = value;
867 goto out;
868 }
869
870 data = iwl_dbgfs_is_match("macaddr_random=", buf);
871 if (data) {
872 ret = kstrtou32(data, 10, &value);
873 if (ret == 0)
874 mvm->tof_data.range_req.macaddr_random = value;
875 goto out;
876 }
877
878 data = iwl_dbgfs_is_match("num_of_ap=", buf);
879 if (data) {
880 ret = kstrtou32(data, 10, &value);
881 if (ret == 0)
882 mvm->tof_data.range_req.num_of_ap = value;
883 goto out;
884 }
885
886 data = iwl_dbgfs_is_match("macaddr_template=", buf);
887 if (data) {
888 u8 mac[ETH_ALEN];
889
890 if (!mac_pton(data, mac)) {
891 ret = -EINVAL;
892 goto out;
893 }
894 memcpy(mvm->tof_data.range_req.macaddr_template, mac, ETH_ALEN);
895 }
896
897 data = iwl_dbgfs_is_match("macaddr_mask=", buf);
898 if (data) {
899 u8 mac[ETH_ALEN];
900
901 if (!mac_pton(data, mac)) {
902 ret = -EINVAL;
903 goto out;
904 }
905 memcpy(mvm->tof_data.range_req.macaddr_mask, mac, ETH_ALEN);
906 }
907
908 data = iwl_dbgfs_is_match("ap=", buf);
909 if (data) {
910 struct iwl_tof_range_req_ap_entry ap;
911 int size = sizeof(struct iwl_tof_range_req_ap_entry);
912 u16 burst_period;
913 u8 *mac = ap.bssid;
5b9d47cd 914 unsigned int i;
ce792918 915
3e0fa505 916 if (sscanf(data, "%u %hhd %hhd %hhd"
ce792918 917 "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"
3e0fa505
AK
918 "%hhd %hhd %hd"
919 "%hhd %hhd %d"
920 "%hhx %hhd %hhd %hhd",
ce792918
GG
921 &i, &ap.channel_num, &ap.bandwidth,
922 &ap.ctrl_ch_position,
923 mac, mac + 1, mac + 2, mac + 3, mac + 4, mac + 5,
924 &ap.measure_type, &ap.num_of_bursts,
925 &burst_period,
926 &ap.samples_per_burst, &ap.retries_per_sample,
927 &ap.tsf_delta, &ap.location_req, &ap.asap_mode,
928 &ap.enable_dyn_ack, &ap.rssi) != 20) {
929 ret = -EINVAL;
930 goto out;
931 }
5b9d47cd 932 if (i >= IWL_MVM_TOF_MAX_APS) {
ce792918
GG
933 IWL_ERR(mvm, "Invalid AP index %d\n", i);
934 ret = -EINVAL;
935 goto out;
936 }
937
938 ap.burst_period = cpu_to_le16(burst_period);
939
940 memcpy(&mvm->tof_data.range_req.ap[i], &ap, size);
941 goto out;
942 }
943
944 data = iwl_dbgfs_is_match("send_range_request=", buf);
945 if (data) {
946 ret = kstrtou32(data, 10, &value);
947 if (ret == 0 && value) {
948 ret = iwl_mvm_tof_range_request_cmd(mvm, vif);
949 goto out;
950 }
951 }
952
953out:
954 mutex_unlock(&mvm->mutex);
955 return ret ?: count;
956}
957
958static ssize_t iwl_dbgfs_tof_range_request_read(struct file *file,
959 char __user *user_buf,
960 size_t count, loff_t *ppos)
961{
962 struct ieee80211_vif *vif = file->private_data;
963 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
964 struct iwl_mvm *mvm = mvmvif->mvm;
965 char buf[512];
966 int pos = 0;
967 const size_t bufsz = sizeof(buf);
968 struct iwl_tof_range_req_cmd *cmd;
969 int i;
970
971 cmd = &mvm->tof_data.range_req;
972
973 mutex_lock(&mvm->mutex);
974
975 pos += scnprintf(buf + pos, bufsz - pos, "request_id= %d\n",
976 cmd->request_id);
977 pos += scnprintf(buf + pos, bufsz - pos, "initiator= %d\n",
978 cmd->initiator);
979 pos += scnprintf(buf + pos, bufsz - pos, "one_sided_los_disable = %d\n",
980 cmd->one_sided_los_disable);
981 pos += scnprintf(buf + pos, bufsz - pos, "req_timeout= %d\n",
982 cmd->req_timeout);
983 pos += scnprintf(buf + pos, bufsz - pos, "report_policy= %d\n",
984 cmd->report_policy);
985 pos += scnprintf(buf + pos, bufsz - pos, "macaddr_random= %d\n",
986 cmd->macaddr_random);
987 pos += scnprintf(buf + pos, bufsz - pos, "macaddr_template= %pM\n",
988 cmd->macaddr_template);
989 pos += scnprintf(buf + pos, bufsz - pos, "macaddr_mask= %pM\n",
990 cmd->macaddr_mask);
991 pos += scnprintf(buf + pos, bufsz - pos, "num_of_ap= %d\n",
992 cmd->num_of_ap);
993 for (i = 0; i < cmd->num_of_ap; i++) {
994 struct iwl_tof_range_req_ap_entry *ap = &cmd->ap[i];
995
996 pos += scnprintf(buf + pos, bufsz - pos,
3e0fa505
AK
997 "ap %.2d: channel_num=%hhd bw=%hhd"
998 " control=%hhd bssid=%pM type=%hhd"
999 " num_of_bursts=%hhd burst_period=%hd ftm=%hhd"
1000 " retries=%hhd tsf_delta=%d"
1001 " tsf_delta_direction=%hhd location_req=0x%hhx "
1002 " asap=%hhd enable=%hhd rssi=%hhd\n",
ce792918
GG
1003 i, ap->channel_num, ap->bandwidth,
1004 ap->ctrl_ch_position, ap->bssid,
1005 ap->measure_type, ap->num_of_bursts,
1006 ap->burst_period, ap->samples_per_burst,
1007 ap->retries_per_sample, ap->tsf_delta,
3e0fa505 1008 ap->tsf_delta_direction,
ce792918
GG
1009 ap->location_req, ap->asap_mode,
1010 ap->enable_dyn_ack, ap->rssi);
1011 }
1012
1013 mutex_unlock(&mvm->mutex);
1014
1015 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1016}
1017
1018static ssize_t iwl_dbgfs_tof_range_req_ext_write(struct ieee80211_vif *vif,
1019 char *buf,
1020 size_t count, loff_t *ppos)
1021{
1022 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1023 struct iwl_mvm *mvm = mvmvif->mvm;
1024 int value, ret = 0;
1025 char *data;
1026
1027 mutex_lock(&mvm->mutex);
1028
1029 data = iwl_dbgfs_is_match("tsf_timer_offset_msec=", buf);
1030 if (data) {
1031 ret = kstrtou32(data, 10, &value);
1032 if (ret == 0)
1033 mvm->tof_data.range_req_ext.tsf_timer_offset_msec =
1034 cpu_to_le16(value);
1035 goto out;
1036 }
1037
1038 data = iwl_dbgfs_is_match("min_delta_ftm=", buf);
1039 if (data) {
1040 ret = kstrtou32(data, 10, &value);
1041 if (ret == 0)
1042 mvm->tof_data.range_req_ext.min_delta_ftm = value;
1043 goto out;
1044 }
1045
1046 data = iwl_dbgfs_is_match("ftm_format_and_bw20M=", buf);
1047 if (data) {
1048 ret = kstrtou32(data, 10, &value);
1049 if (ret == 0)
1050 mvm->tof_data.range_req_ext.ftm_format_and_bw20M =
1051 value;
1052 goto out;
1053 }
1054
1055 data = iwl_dbgfs_is_match("ftm_format_and_bw40M=", buf);
1056 if (data) {
1057 ret = kstrtou32(data, 10, &value);
1058 if (ret == 0)
1059 mvm->tof_data.range_req_ext.ftm_format_and_bw40M =
1060 value;
1061 goto out;
1062 }
1063
1064 data = iwl_dbgfs_is_match("ftm_format_and_bw80M=", buf);
1065 if (data) {
1066 ret = kstrtou32(data, 10, &value);
1067 if (ret == 0)
1068 mvm->tof_data.range_req_ext.ftm_format_and_bw80M =
1069 value;
1070 goto out;
1071 }
1072
1073 data = iwl_dbgfs_is_match("send_range_req_ext=", buf);
1074 if (data) {
1075 ret = kstrtou32(data, 10, &value);
1076 if (ret == 0 && value) {
1077 ret = iwl_mvm_tof_range_request_ext_cmd(mvm, vif);
1078 goto out;
1079 }
1080 }
1081
1082out:
1083 mutex_unlock(&mvm->mutex);
1084 return ret ?: count;
1085}
1086
1087static ssize_t iwl_dbgfs_tof_range_req_ext_read(struct file *file,
1088 char __user *user_buf,
1089 size_t count, loff_t *ppos)
1090{
1091 struct ieee80211_vif *vif = file->private_data;
1092 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1093 struct iwl_mvm *mvm = mvmvif->mvm;
1094 char buf[256];
1095 int pos = 0;
1096 const size_t bufsz = sizeof(buf);
1097 struct iwl_tof_range_req_ext_cmd *cmd;
1098
1099 cmd = &mvm->tof_data.range_req_ext;
1100
1101 mutex_lock(&mvm->mutex);
1102
1103 pos += scnprintf(buf + pos, bufsz - pos,
3e0fa505 1104 "tsf_timer_offset_msec = %hd\n",
ce792918 1105 cmd->tsf_timer_offset_msec);
3e0fa505 1106 pos += scnprintf(buf + pos, bufsz - pos, "min_delta_ftm = %hhd\n",
ce792918
GG
1107 cmd->min_delta_ftm);
1108 pos += scnprintf(buf + pos, bufsz - pos,
3e0fa505 1109 "ftm_format_and_bw20M = %hhd\n",
ce792918
GG
1110 cmd->ftm_format_and_bw20M);
1111 pos += scnprintf(buf + pos, bufsz - pos,
3e0fa505 1112 "ftm_format_and_bw40M = %hhd\n",
ce792918
GG
1113 cmd->ftm_format_and_bw40M);
1114 pos += scnprintf(buf + pos, bufsz - pos,
3e0fa505 1115 "ftm_format_and_bw80M = %hhd\n",
ce792918
GG
1116 cmd->ftm_format_and_bw80M);
1117
1118 mutex_unlock(&mvm->mutex);
1119 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1120}
1121
1122static ssize_t iwl_dbgfs_tof_range_abort_write(struct ieee80211_vif *vif,
1123 char *buf,
1124 size_t count, loff_t *ppos)
1125{
1126 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1127 struct iwl_mvm *mvm = mvmvif->mvm;
1128 int value, ret = 0;
1129 int abort_id;
1130 char *data;
1131
1132 mutex_lock(&mvm->mutex);
1133
1134 data = iwl_dbgfs_is_match("abort_id=", buf);
1135 if (data) {
1136 ret = kstrtou32(data, 10, &value);
1137 if (ret == 0)
1138 mvm->tof_data.last_abort_id = value;
1139 goto out;
1140 }
1141
1142 data = iwl_dbgfs_is_match("send_range_abort=", buf);
1143 if (data) {
1144 ret = kstrtou32(data, 10, &value);
1145 if (ret == 0 && value) {
1146 abort_id = mvm->tof_data.last_abort_id;
1147 ret = iwl_mvm_tof_range_abort_cmd(mvm, abort_id);
1148 goto out;
1149 }
1150 }
1151
1152out:
1153 mutex_unlock(&mvm->mutex);
1154 return ret ?: count;
1155}
1156
1157static ssize_t iwl_dbgfs_tof_range_abort_read(struct file *file,
1158 char __user *user_buf,
1159 size_t count, loff_t *ppos)
1160{
1161 struct ieee80211_vif *vif = file->private_data;
1162 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1163 struct iwl_mvm *mvm = mvmvif->mvm;
1164 char buf[32];
1165 int pos = 0;
1166 const size_t bufsz = sizeof(buf);
1167 int last_abort_id;
1168
1169 mutex_lock(&mvm->mutex);
1170 last_abort_id = mvm->tof_data.last_abort_id;
1171 mutex_unlock(&mvm->mutex);
1172
1173 pos += scnprintf(buf + pos, bufsz - pos, "last_abort_id = %d\n",
1174 last_abort_id);
1175 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1176}
1177
1178static ssize_t iwl_dbgfs_tof_range_response_read(struct file *file,
1179 char __user *user_buf,
1180 size_t count, loff_t *ppos)
1181{
1182 struct ieee80211_vif *vif = file->private_data;
1183 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1184 struct iwl_mvm *mvm = mvmvif->mvm;
1185 char *buf;
1186 int pos = 0;
1187 const size_t bufsz = sizeof(struct iwl_tof_range_rsp_ntfy) + 256;
1188 struct iwl_tof_range_rsp_ntfy *cmd;
1189 int i, ret;
1190
1191 buf = kzalloc(bufsz, GFP_KERNEL);
1192 if (!buf)
1193 return -ENOMEM;
1194
1195 mutex_lock(&mvm->mutex);
1196 cmd = &mvm->tof_data.range_resp;
1197
1198 pos += scnprintf(buf + pos, bufsz - pos, "request_id = %d\n",
1199 cmd->request_id);
1200 pos += scnprintf(buf + pos, bufsz - pos, "status = %d\n",
1201 cmd->request_status);
1202 pos += scnprintf(buf + pos, bufsz - pos, "last_in_batch = %d\n",
1203 cmd->last_in_batch);
1204 pos += scnprintf(buf + pos, bufsz - pos, "num_of_aps = %d\n",
1205 cmd->num_of_aps);
1206 for (i = 0; i < cmd->num_of_aps; i++) {
1207 struct iwl_tof_range_rsp_ap_entry_ntfy *ap = &cmd->ap[i];
1208
1209 pos += scnprintf(buf + pos, bufsz - pos,
3e0fa505
AK
1210 "ap %.2d: bssid=%pM status=%hhd bw=%hhd"
1211 " rtt=%d rtt_var=%d rtt_spread=%d"
1212 " rssi=%hhd rssi_spread=%hhd"
1213 " range=%d range_var=%d"
1214 " time_stamp=%d\n",
ce792918
GG
1215 i, ap->bssid, ap->measure_status,
1216 ap->measure_bw,
1217 ap->rtt, ap->rtt_variance, ap->rtt_spread,
1218 ap->rssi, ap->rssi_spread, ap->range,
1219 ap->range_variance, ap->timestamp);
1220 }
1221 mutex_unlock(&mvm->mutex);
1222
1223 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1224 kfree(buf);
1225 return ret;
1226}
1227
a21d7bcb
JB
1228static ssize_t iwl_dbgfs_low_latency_write(struct ieee80211_vif *vif, char *buf,
1229 size_t count, loff_t *ppos)
1230{
1231 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1232 struct iwl_mvm *mvm = mvmvif->mvm;
1233 u8 value;
1234 int ret;
1235
1236 ret = kstrtou8(buf, 0, &value);
1237 if (ret)
1238 return ret;
1239 if (value > 1)
1240 return -EINVAL;
1241
1242 mutex_lock(&mvm->mutex);
1243 iwl_mvm_update_low_latency(mvm, vif, value);
1244 mutex_unlock(&mvm->mutex);
1245
1246 return count;
1247}
1248
1249static ssize_t iwl_dbgfs_low_latency_read(struct file *file,
1250 char __user *user_buf,
1251 size_t count, loff_t *ppos)
1252{
1253 struct ieee80211_vif *vif = file->private_data;
1254 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
cfe417bc 1255 char buf[2];
a21d7bcb
JB
1256
1257 buf[0] = mvmvif->low_latency ? '1' : '0';
1258 buf[1] = '\n';
a21d7bcb
JB
1259 return simple_read_from_buffer(user_buf, count, ppos, buf, sizeof(buf));
1260}
1261
e39c1b5f
JB
1262static ssize_t iwl_dbgfs_uapsd_misbehaving_read(struct file *file,
1263 char __user *user_buf,
1264 size_t count, loff_t *ppos)
1265{
1266 struct ieee80211_vif *vif = file->private_data;
1267 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1268 char buf[20];
1269 int len;
1270
1271 len = sprintf(buf, "%pM\n", mvmvif->uapsd_misbehaving_bssid);
1272 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1273}
1274
1275static ssize_t iwl_dbgfs_uapsd_misbehaving_write(struct ieee80211_vif *vif,
1276 char *buf, size_t count,
1277 loff_t *ppos)
1278{
1279 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1280 struct iwl_mvm *mvm = mvmvif->mvm;
1281 bool ret;
1282
1283 mutex_lock(&mvm->mutex);
1284 ret = mac_pton(buf, mvmvif->uapsd_misbehaving_bssid);
1285 mutex_unlock(&mvm->mutex);
1286
1287 return ret ? count : -EINVAL;
1288}
1289
ddf89ab1
EG
1290static ssize_t iwl_dbgfs_rx_phyinfo_write(struct ieee80211_vif *vif, char *buf,
1291 size_t count, loff_t *ppos)
1292{
1293 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1294 struct iwl_mvm *mvm = mvmvif->mvm;
1295 struct ieee80211_chanctx_conf *chanctx_conf;
1296 struct iwl_mvm_phy_ctxt *phy_ctxt;
1297 u16 value;
1298 int ret;
1299
1300 ret = kstrtou16(buf, 0, &value);
1301 if (ret)
1302 return ret;
1303
1304 mutex_lock(&mvm->mutex);
1305 rcu_read_lock();
1306
1307 chanctx_conf = rcu_dereference(vif->chanctx_conf);
1308 /* make sure the channel context is assigned */
1309 if (!chanctx_conf) {
1310 rcu_read_unlock();
1311 mutex_unlock(&mvm->mutex);
1312 return -EINVAL;
1313 }
1314
1315 phy_ctxt = &mvm->phy_ctxts[*(u16 *)chanctx_conf->drv_priv];
1316 rcu_read_unlock();
1317
1318 mvm->dbgfs_rx_phyinfo = value;
1319
1320 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chanctx_conf->min_def,
1321 chanctx_conf->rx_chains_static,
1322 chanctx_conf->rx_chains_dynamic);
1323 mutex_unlock(&mvm->mutex);
1324
1325 return ret ?: count;
1326}
1327
1328static ssize_t iwl_dbgfs_rx_phyinfo_read(struct file *file,
1329 char __user *user_buf,
1330 size_t count, loff_t *ppos)
1331{
1332 struct ieee80211_vif *vif = file->private_data;
1333 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1334 char buf[8];
1335
1336 snprintf(buf, sizeof(buf), "0x%04x\n", mvmvif->mvm->dbgfs_rx_phyinfo);
1337
1338 return simple_read_from_buffer(user_buf, count, ppos, buf, sizeof(buf));
1339}
1340
e45a941d
AB
1341#define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
1342 _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
1343#define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
1344 _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
820a1a50
JB
1345#define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \
1346 if (!debugfs_create_file(#name, mode, parent, vif, \
1347 &iwl_dbgfs_##name##_ops)) \
1348 goto err; \
1349 } while (0)
1350
1351MVM_DEBUGFS_READ_FILE_OPS(mac_params);
25870cb7 1352MVM_DEBUGFS_READ_FILE_OPS(tx_pwr_lmt);
e45a941d
AB
1353MVM_DEBUGFS_READ_WRITE_FILE_OPS(pm_params, 32);
1354MVM_DEBUGFS_READ_WRITE_FILE_OPS(bf_params, 256);
a21d7bcb 1355MVM_DEBUGFS_READ_WRITE_FILE_OPS(low_latency, 10);
e39c1b5f 1356MVM_DEBUGFS_READ_WRITE_FILE_OPS(uapsd_misbehaving, 20);
ddf89ab1 1357MVM_DEBUGFS_READ_WRITE_FILE_OPS(rx_phyinfo, 10);
ce792918
GG
1358MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_enable, 32);
1359MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_request, 512);
1360MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_req_ext, 32);
1361MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_abort, 32);
1362MVM_DEBUGFS_READ_FILE_OPS(tof_range_response);
1363MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_responder_params, 32);
820a1a50
JB
1364
1365void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1366{
1367 struct dentry *dbgfs_dir = vif->debugfs_dir;
1368 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1369 char buf[100];
1370
1371 /*
1372 * Check if debugfs directory already exist before creating it.
1373 * This may happen when, for example, resetting hw or suspend-resume
1374 */
1375 if (!dbgfs_dir || mvmvif->dbgfs_dir)
1376 return;
1377
1378 mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir);
820a1a50
JB
1379
1380 if (!mvmvif->dbgfs_dir) {
1381 IWL_ERR(mvm, "Failed to create debugfs directory under %s\n",
1382 dbgfs_dir->d_name.name);
1383 return;
1384 }
1385
ad2549d8 1386 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM &&
e45a941d
AB
1387 ((vif->type == NL80211_IFTYPE_STATION && !vif->p2p) ||
1388 (vif->type == NL80211_IFTYPE_STATION && vif->p2p &&
7303dd7f 1389 mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_DCM)))
e45a941d
AB
1390 MVM_DEBUGFS_ADD_FILE_VIF(pm_params, mvmvif->dbgfs_dir, S_IWUSR |
1391 S_IRUSR);
1392
25870cb7 1393 MVM_DEBUGFS_ADD_FILE_VIF(tx_pwr_lmt, mvmvif->dbgfs_dir, S_IRUSR);
32a65c34 1394 MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir, S_IRUSR);
a21d7bcb
JB
1395 MVM_DEBUGFS_ADD_FILE_VIF(low_latency, mvmvif->dbgfs_dir,
1396 S_IRUSR | S_IWUSR);
e39c1b5f
JB
1397 MVM_DEBUGFS_ADD_FILE_VIF(uapsd_misbehaving, mvmvif->dbgfs_dir,
1398 S_IRUSR | S_IWUSR);
ddf89ab1
EG
1399 MVM_DEBUGFS_ADD_FILE_VIF(rx_phyinfo, mvmvif->dbgfs_dir,
1400 S_IRUSR | S_IWUSR);
820a1a50 1401
e45a941d
AB
1402 if (vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
1403 mvmvif == mvm->bf_allowed_vif)
1404 MVM_DEBUGFS_ADD_FILE_VIF(bf_params, mvmvif->dbgfs_dir,
1405 S_IRUSR | S_IWUSR);
1406
ce792918
GG
1407 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TOF_SUPPORT) &&
1408 !vif->p2p && (vif->type != NL80211_IFTYPE_P2P_DEVICE)) {
1409 if (IWL_MVM_TOF_IS_RESPONDER && vif->type == NL80211_IFTYPE_AP)
1410 MVM_DEBUGFS_ADD_FILE_VIF(tof_responder_params,
1411 mvmvif->dbgfs_dir,
1412 S_IRUSR | S_IWUSR);
1413
1414 MVM_DEBUGFS_ADD_FILE_VIF(tof_range_request, mvmvif->dbgfs_dir,
1415 S_IRUSR | S_IWUSR);
1416 MVM_DEBUGFS_ADD_FILE_VIF(tof_range_req_ext, mvmvif->dbgfs_dir,
1417 S_IRUSR | S_IWUSR);
1418 MVM_DEBUGFS_ADD_FILE_VIF(tof_enable, mvmvif->dbgfs_dir,
1419 S_IRUSR | S_IWUSR);
1420 MVM_DEBUGFS_ADD_FILE_VIF(tof_range_abort, mvmvif->dbgfs_dir,
1421 S_IRUSR | S_IWUSR);
1422 MVM_DEBUGFS_ADD_FILE_VIF(tof_range_response, mvmvif->dbgfs_dir,
1423 S_IRUSR);
1424 }
1425
820a1a50
JB
1426 /*
1427 * Create symlink for convenience pointing to interface specific
1428 * debugfs entries for the driver. For example, under
1429 * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/
1430 * find
1431 * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/
1432 */
1433 snprintf(buf, 100, "../../../%s/%s/%s/%s",
1434 dbgfs_dir->d_parent->d_parent->d_name.name,
1435 dbgfs_dir->d_parent->d_name.name,
1436 dbgfs_dir->d_name.name,
1437 mvmvif->dbgfs_dir->d_name.name);
1438
1439 mvmvif->dbgfs_slink = debugfs_create_symlink(dbgfs_dir->d_name.name,
1440 mvm->debugfs_dir, buf);
1441 if (!mvmvif->dbgfs_slink)
1442 IWL_ERR(mvm, "Can't create debugfs symbolic link under %s\n",
1443 dbgfs_dir->d_name.name);
1444 return;
1445err:
1446 IWL_ERR(mvm, "Can't create debugfs entity\n");
1447}
1448
1449void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1450{
1451 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1452
1453 debugfs_remove(mvmvif->dbgfs_slink);
1454 mvmvif->dbgfs_slink = NULL;
1455
1456 debugfs_remove_recursive(mvmvif->dbgfs_dir);
1457 mvmvif->dbgfs_dir = NULL;
1458}
This page took 0.189552 seconds and 5 git commands to generate.