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