Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/contrib/dev/iwlwifi/mvm/debugfs-vif.c
48287 views
1
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2
/*
3
* Copyright (C) 2012-2014, 2018-2024 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
#if defined(__FreeBSD__)
10
#include <linux/math64.h>
11
#endif
12
13
static void iwl_dbgfs_update_pm(struct iwl_mvm *mvm,
14
struct ieee80211_vif *vif,
15
enum iwl_dbgfs_pm_mask param, int val)
16
{
17
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
18
struct iwl_dbgfs_pm *dbgfs_pm = &mvmvif->dbgfs_pm;
19
20
dbgfs_pm->mask |= param;
21
22
switch (param) {
23
case MVM_DEBUGFS_PM_KEEP_ALIVE: {
24
int dtimper = vif->bss_conf.dtim_period ?: 1;
25
int dtimper_msec = dtimper * vif->bss_conf.beacon_int;
26
27
IWL_DEBUG_POWER(mvm, "debugfs: set keep_alive= %d sec\n", val);
28
if (val * MSEC_PER_SEC < 3 * dtimper_msec)
29
IWL_WARN(mvm,
30
"debugfs: keep alive period (%ld msec) is less than minimum required (%d msec)\n",
31
val * MSEC_PER_SEC, 3 * dtimper_msec);
32
dbgfs_pm->keep_alive_seconds = val;
33
break;
34
}
35
case MVM_DEBUGFS_PM_SKIP_OVER_DTIM:
36
IWL_DEBUG_POWER(mvm, "skip_over_dtim %s\n",
37
val ? "enabled" : "disabled");
38
dbgfs_pm->skip_over_dtim = val;
39
break;
40
case MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS:
41
IWL_DEBUG_POWER(mvm, "skip_dtim_periods=%d\n", val);
42
dbgfs_pm->skip_dtim_periods = val;
43
break;
44
case MVM_DEBUGFS_PM_RX_DATA_TIMEOUT:
45
IWL_DEBUG_POWER(mvm, "rx_data_timeout=%d\n", val);
46
dbgfs_pm->rx_data_timeout = val;
47
break;
48
case MVM_DEBUGFS_PM_TX_DATA_TIMEOUT:
49
IWL_DEBUG_POWER(mvm, "tx_data_timeout=%d\n", val);
50
dbgfs_pm->tx_data_timeout = val;
51
break;
52
case MVM_DEBUGFS_PM_LPRX_ENA:
53
IWL_DEBUG_POWER(mvm, "lprx %s\n", val ? "enabled" : "disabled");
54
dbgfs_pm->lprx_ena = val;
55
break;
56
case MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD:
57
IWL_DEBUG_POWER(mvm, "lprx_rssi_threshold=%d\n", val);
58
dbgfs_pm->lprx_rssi_threshold = val;
59
break;
60
case MVM_DEBUGFS_PM_SNOOZE_ENABLE:
61
IWL_DEBUG_POWER(mvm, "snooze_enable=%d\n", val);
62
dbgfs_pm->snooze_ena = val;
63
break;
64
case MVM_DEBUGFS_PM_UAPSD_MISBEHAVING:
65
IWL_DEBUG_POWER(mvm, "uapsd_misbehaving_enable=%d\n", val);
66
dbgfs_pm->uapsd_misbehaving = val;
67
break;
68
case MVM_DEBUGFS_PM_USE_PS_POLL:
69
IWL_DEBUG_POWER(mvm, "use_ps_poll=%d\n", val);
70
dbgfs_pm->use_ps_poll = val;
71
break;
72
}
73
}
74
75
static ssize_t iwl_dbgfs_pm_params_write(struct ieee80211_vif *vif, char *buf,
76
size_t count, loff_t *ppos)
77
{
78
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
79
struct iwl_mvm *mvm = mvmvif->mvm;
80
enum iwl_dbgfs_pm_mask param;
81
int val, ret;
82
83
if (!strncmp("keep_alive=", buf, 11)) {
84
if (sscanf(buf + 11, "%d", &val) != 1)
85
return -EINVAL;
86
param = MVM_DEBUGFS_PM_KEEP_ALIVE;
87
} else if (!strncmp("skip_over_dtim=", buf, 15)) {
88
if (sscanf(buf + 15, "%d", &val) != 1)
89
return -EINVAL;
90
param = MVM_DEBUGFS_PM_SKIP_OVER_DTIM;
91
} else if (!strncmp("skip_dtim_periods=", buf, 18)) {
92
if (sscanf(buf + 18, "%d", &val) != 1)
93
return -EINVAL;
94
param = MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS;
95
} else if (!strncmp("rx_data_timeout=", buf, 16)) {
96
if (sscanf(buf + 16, "%d", &val) != 1)
97
return -EINVAL;
98
param = MVM_DEBUGFS_PM_RX_DATA_TIMEOUT;
99
} else if (!strncmp("tx_data_timeout=", buf, 16)) {
100
if (sscanf(buf + 16, "%d", &val) != 1)
101
return -EINVAL;
102
param = MVM_DEBUGFS_PM_TX_DATA_TIMEOUT;
103
} else if (!strncmp("lprx=", buf, 5)) {
104
if (sscanf(buf + 5, "%d", &val) != 1)
105
return -EINVAL;
106
param = MVM_DEBUGFS_PM_LPRX_ENA;
107
} else if (!strncmp("lprx_rssi_threshold=", buf, 20)) {
108
if (sscanf(buf + 20, "%d", &val) != 1)
109
return -EINVAL;
110
if (val > POWER_LPRX_RSSI_THRESHOLD_MAX || val <
111
POWER_LPRX_RSSI_THRESHOLD_MIN)
112
return -EINVAL;
113
param = MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD;
114
} else if (!strncmp("snooze_enable=", buf, 14)) {
115
if (sscanf(buf + 14, "%d", &val) != 1)
116
return -EINVAL;
117
param = MVM_DEBUGFS_PM_SNOOZE_ENABLE;
118
} else if (!strncmp("uapsd_misbehaving=", buf, 18)) {
119
if (sscanf(buf + 18, "%d", &val) != 1)
120
return -EINVAL;
121
param = MVM_DEBUGFS_PM_UAPSD_MISBEHAVING;
122
} else if (!strncmp("use_ps_poll=", buf, 12)) {
123
if (sscanf(buf + 12, "%d", &val) != 1)
124
return -EINVAL;
125
param = MVM_DEBUGFS_PM_USE_PS_POLL;
126
} else {
127
return -EINVAL;
128
}
129
130
mutex_lock(&mvm->mutex);
131
iwl_dbgfs_update_pm(mvm, vif, param, val);
132
ret = iwl_mvm_power_update_mac(mvm);
133
mutex_unlock(&mvm->mutex);
134
135
return ret ?: count;
136
}
137
138
static ssize_t iwl_dbgfs_tx_pwr_lmt_read(struct file *file,
139
char __user *user_buf,
140
size_t count, loff_t *ppos)
141
{
142
struct ieee80211_vif *vif = file->private_data;
143
char buf[64];
144
int bufsz = sizeof(buf);
145
int pos;
146
147
pos = scnprintf(buf, bufsz, "bss limit = %d\n",
148
vif->bss_conf.txpower);
149
150
return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
151
}
152
153
static ssize_t iwl_dbgfs_pm_params_read(struct file *file,
154
char __user *user_buf,
155
size_t count, loff_t *ppos)
156
{
157
struct ieee80211_vif *vif = file->private_data;
158
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
159
struct iwl_mvm *mvm = mvmvif->mvm;
160
char buf[512];
161
int bufsz = sizeof(buf);
162
int pos;
163
164
pos = iwl_mvm_power_mac_dbgfs_read(mvm, vif, buf, bufsz);
165
166
return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
167
}
168
169
static ssize_t iwl_dbgfs_mac_params_read(struct file *file,
170
char __user *user_buf,
171
size_t count, loff_t *ppos)
172
{
173
struct ieee80211_vif *vif = file->private_data;
174
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
175
struct iwl_mvm *mvm = mvmvif->mvm;
176
u8 ap_sta_id;
177
struct ieee80211_chanctx_conf *chanctx_conf;
178
char buf[512];
179
int bufsz = sizeof(buf);
180
int pos = 0;
181
int i;
182
183
mutex_lock(&mvm->mutex);
184
185
ap_sta_id = mvmvif->deflink.ap_sta_id;
186
187
switch (ieee80211_vif_type_p2p(vif)) {
188
case NL80211_IFTYPE_ADHOC:
189
pos += scnprintf(buf+pos, bufsz-pos, "type: ibss\n");
190
break;
191
case NL80211_IFTYPE_STATION:
192
pos += scnprintf(buf+pos, bufsz-pos, "type: bss\n");
193
break;
194
case NL80211_IFTYPE_AP:
195
pos += scnprintf(buf+pos, bufsz-pos, "type: ap\n");
196
break;
197
case NL80211_IFTYPE_P2P_CLIENT:
198
pos += scnprintf(buf+pos, bufsz-pos, "type: p2p client\n");
199
break;
200
case NL80211_IFTYPE_P2P_GO:
201
pos += scnprintf(buf+pos, bufsz-pos, "type: p2p go\n");
202
break;
203
case NL80211_IFTYPE_P2P_DEVICE:
204
pos += scnprintf(buf+pos, bufsz-pos, "type: p2p dev\n");
205
break;
206
default:
207
break;
208
}
209
210
pos += scnprintf(buf+pos, bufsz-pos, "mac id/color: %d / %d\n",
211
mvmvif->id, mvmvif->color);
212
pos += scnprintf(buf+pos, bufsz-pos, "bssid: %pM\n",
213
vif->bss_conf.bssid);
214
pos += scnprintf(buf+pos, bufsz-pos, "Load: %d\n",
215
mvm->tcm.result.load[mvmvif->id]);
216
pos += scnprintf(buf+pos, bufsz-pos, "QoS:\n");
217
for (i = 0; i < ARRAY_SIZE(mvmvif->deflink.queue_params); i++)
218
pos += scnprintf(buf+pos, bufsz-pos,
219
"\t%d: txop:%d - cw_min:%d - cw_max = %d - aifs = %d upasd = %d\n",
220
i, mvmvif->deflink.queue_params[i].txop,
221
mvmvif->deflink.queue_params[i].cw_min,
222
mvmvif->deflink.queue_params[i].cw_max,
223
mvmvif->deflink.queue_params[i].aifs,
224
mvmvif->deflink.queue_params[i].uapsd);
225
226
if (vif->type == NL80211_IFTYPE_STATION &&
227
ap_sta_id != IWL_INVALID_STA) {
228
struct iwl_mvm_sta *mvm_sta;
229
230
mvm_sta = iwl_mvm_sta_from_staid_protected(mvm, ap_sta_id);
231
if (mvm_sta) {
232
pos += scnprintf(buf+pos, bufsz-pos,
233
"ap_sta_id %d - reduced Tx power %d\n",
234
ap_sta_id,
235
mvm_sta->bt_reduced_txpower);
236
}
237
}
238
239
rcu_read_lock();
240
chanctx_conf = rcu_dereference(vif->bss_conf.chanctx_conf);
241
if (chanctx_conf)
242
pos += scnprintf(buf+pos, bufsz-pos,
243
"idle rx chains %d, active rx chains: %d\n",
244
chanctx_conf->rx_chains_static,
245
chanctx_conf->rx_chains_dynamic);
246
rcu_read_unlock();
247
248
mutex_unlock(&mvm->mutex);
249
250
return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
251
}
252
253
static void iwl_dbgfs_update_bf(struct ieee80211_vif *vif,
254
enum iwl_dbgfs_bf_mask param, int value)
255
{
256
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
257
struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
258
259
dbgfs_bf->mask |= param;
260
261
switch (param) {
262
case MVM_DEBUGFS_BF_ENERGY_DELTA:
263
dbgfs_bf->bf_energy_delta = value;
264
break;
265
case MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA:
266
dbgfs_bf->bf_roaming_energy_delta = value;
267
break;
268
case MVM_DEBUGFS_BF_ROAMING_STATE:
269
dbgfs_bf->bf_roaming_state = value;
270
break;
271
case MVM_DEBUGFS_BF_TEMP_THRESHOLD:
272
dbgfs_bf->bf_temp_threshold = value;
273
break;
274
case MVM_DEBUGFS_BF_TEMP_FAST_FILTER:
275
dbgfs_bf->bf_temp_fast_filter = value;
276
break;
277
case MVM_DEBUGFS_BF_TEMP_SLOW_FILTER:
278
dbgfs_bf->bf_temp_slow_filter = value;
279
break;
280
case MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER:
281
dbgfs_bf->bf_enable_beacon_filter = value;
282
break;
283
case MVM_DEBUGFS_BF_DEBUG_FLAG:
284
dbgfs_bf->bf_debug_flag = value;
285
break;
286
case MVM_DEBUGFS_BF_ESCAPE_TIMER:
287
dbgfs_bf->bf_escape_timer = value;
288
break;
289
case MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT:
290
dbgfs_bf->ba_enable_beacon_abort = value;
291
break;
292
case MVM_DEBUGFS_BA_ESCAPE_TIMER:
293
dbgfs_bf->ba_escape_timer = value;
294
break;
295
}
296
}
297
298
static ssize_t iwl_dbgfs_bf_params_write(struct ieee80211_vif *vif, char *buf,
299
size_t count, loff_t *ppos)
300
{
301
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
302
struct iwl_mvm *mvm = mvmvif->mvm;
303
enum iwl_dbgfs_bf_mask param;
304
int value, ret = 0;
305
306
if (!strncmp("bf_energy_delta=", buf, 16)) {
307
if (sscanf(buf+16, "%d", &value) != 1)
308
return -EINVAL;
309
if (value < IWL_BF_ENERGY_DELTA_MIN ||
310
value > IWL_BF_ENERGY_DELTA_MAX)
311
return -EINVAL;
312
param = MVM_DEBUGFS_BF_ENERGY_DELTA;
313
} else if (!strncmp("bf_roaming_energy_delta=", buf, 24)) {
314
if (sscanf(buf+24, "%d", &value) != 1)
315
return -EINVAL;
316
if (value < IWL_BF_ROAMING_ENERGY_DELTA_MIN ||
317
value > IWL_BF_ROAMING_ENERGY_DELTA_MAX)
318
return -EINVAL;
319
param = MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA;
320
} else if (!strncmp("bf_roaming_state=", buf, 17)) {
321
if (sscanf(buf+17, "%d", &value) != 1)
322
return -EINVAL;
323
if (value < IWL_BF_ROAMING_STATE_MIN ||
324
value > IWL_BF_ROAMING_STATE_MAX)
325
return -EINVAL;
326
param = MVM_DEBUGFS_BF_ROAMING_STATE;
327
} else if (!strncmp("bf_temp_threshold=", buf, 18)) {
328
if (sscanf(buf+18, "%d", &value) != 1)
329
return -EINVAL;
330
if (value < IWL_BF_TEMP_THRESHOLD_MIN ||
331
value > IWL_BF_TEMP_THRESHOLD_MAX)
332
return -EINVAL;
333
param = MVM_DEBUGFS_BF_TEMP_THRESHOLD;
334
} else if (!strncmp("bf_temp_fast_filter=", buf, 20)) {
335
if (sscanf(buf+20, "%d", &value) != 1)
336
return -EINVAL;
337
if (value < IWL_BF_TEMP_FAST_FILTER_MIN ||
338
value > IWL_BF_TEMP_FAST_FILTER_MAX)
339
return -EINVAL;
340
param = MVM_DEBUGFS_BF_TEMP_FAST_FILTER;
341
} else if (!strncmp("bf_temp_slow_filter=", buf, 20)) {
342
if (sscanf(buf+20, "%d", &value) != 1)
343
return -EINVAL;
344
if (value < IWL_BF_TEMP_SLOW_FILTER_MIN ||
345
value > IWL_BF_TEMP_SLOW_FILTER_MAX)
346
return -EINVAL;
347
param = MVM_DEBUGFS_BF_TEMP_SLOW_FILTER;
348
} else if (!strncmp("bf_enable_beacon_filter=", buf, 24)) {
349
if (sscanf(buf+24, "%d", &value) != 1)
350
return -EINVAL;
351
if (value < 0 || value > 1)
352
return -EINVAL;
353
param = MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER;
354
} else if (!strncmp("bf_debug_flag=", buf, 14)) {
355
if (sscanf(buf+14, "%d", &value) != 1)
356
return -EINVAL;
357
if (value < 0 || value > 1)
358
return -EINVAL;
359
param = MVM_DEBUGFS_BF_DEBUG_FLAG;
360
} else if (!strncmp("bf_escape_timer=", buf, 16)) {
361
if (sscanf(buf+16, "%d", &value) != 1)
362
return -EINVAL;
363
if (value < IWL_BF_ESCAPE_TIMER_MIN ||
364
value > IWL_BF_ESCAPE_TIMER_MAX)
365
return -EINVAL;
366
param = MVM_DEBUGFS_BF_ESCAPE_TIMER;
367
} else if (!strncmp("ba_escape_timer=", buf, 16)) {
368
if (sscanf(buf+16, "%d", &value) != 1)
369
return -EINVAL;
370
if (value < IWL_BA_ESCAPE_TIMER_MIN ||
371
value > IWL_BA_ESCAPE_TIMER_MAX)
372
return -EINVAL;
373
param = MVM_DEBUGFS_BA_ESCAPE_TIMER;
374
} else if (!strncmp("ba_enable_beacon_abort=", buf, 23)) {
375
if (sscanf(buf+23, "%d", &value) != 1)
376
return -EINVAL;
377
if (value < 0 || value > 1)
378
return -EINVAL;
379
param = MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT;
380
} else {
381
return -EINVAL;
382
}
383
384
mutex_lock(&mvm->mutex);
385
iwl_dbgfs_update_bf(vif, param, value);
386
if (param == MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER && !value)
387
ret = iwl_mvm_disable_beacon_filter(mvm, vif);
388
else
389
ret = iwl_mvm_enable_beacon_filter(mvm, vif);
390
mutex_unlock(&mvm->mutex);
391
392
return ret ?: count;
393
}
394
395
static ssize_t iwl_dbgfs_bf_params_read(struct file *file,
396
char __user *user_buf,
397
size_t count, loff_t *ppos)
398
{
399
struct ieee80211_vif *vif = file->private_data;
400
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
401
char buf[256];
402
int pos = 0;
403
const size_t bufsz = sizeof(buf);
404
struct iwl_beacon_filter_cmd cmd = {
405
IWL_BF_CMD_CONFIG_DEFAULTS,
406
.bf_enable_beacon_filter =
407
cpu_to_le32(IWL_BF_ENABLE_BEACON_FILTER_DEFAULT),
408
.ba_enable_beacon_abort =
409
cpu_to_le32(IWL_BA_ENABLE_BEACON_ABORT_DEFAULT),
410
};
411
412
iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
413
if (mvmvif->bf_enabled)
414
cmd.bf_enable_beacon_filter = cpu_to_le32(1);
415
else
416
cmd.bf_enable_beacon_filter = 0;
417
418
pos += scnprintf(buf+pos, bufsz-pos, "bf_energy_delta = %d\n",
419
le32_to_cpu(cmd.bf_energy_delta));
420
pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_energy_delta = %d\n",
421
le32_to_cpu(cmd.bf_roaming_energy_delta));
422
pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_state = %d\n",
423
le32_to_cpu(cmd.bf_roaming_state));
424
pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_threshold = %d\n",
425
le32_to_cpu(cmd.bf_temp_threshold));
426
pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_fast_filter = %d\n",
427
le32_to_cpu(cmd.bf_temp_fast_filter));
428
pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_slow_filter = %d\n",
429
le32_to_cpu(cmd.bf_temp_slow_filter));
430
pos += scnprintf(buf+pos, bufsz-pos, "bf_enable_beacon_filter = %d\n",
431
le32_to_cpu(cmd.bf_enable_beacon_filter));
432
pos += scnprintf(buf+pos, bufsz-pos, "bf_debug_flag = %d\n",
433
le32_to_cpu(cmd.bf_debug_flag));
434
pos += scnprintf(buf+pos, bufsz-pos, "bf_escape_timer = %d\n",
435
le32_to_cpu(cmd.bf_escape_timer));
436
pos += scnprintf(buf+pos, bufsz-pos, "ba_escape_timer = %d\n",
437
le32_to_cpu(cmd.ba_escape_timer));
438
pos += scnprintf(buf+pos, bufsz-pos, "ba_enable_beacon_abort = %d\n",
439
le32_to_cpu(cmd.ba_enable_beacon_abort));
440
441
return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
442
}
443
444
static ssize_t iwl_dbgfs_os_device_timediff_read(struct file *file,
445
char __user *user_buf,
446
size_t count, loff_t *ppos)
447
{
448
struct ieee80211_vif *vif = file->private_data;
449
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
450
struct iwl_mvm *mvm = mvmvif->mvm;
451
u32 curr_gp2;
452
u64 curr_os;
453
s64 diff;
454
char buf[64];
455
const size_t bufsz = sizeof(buf);
456
int pos = 0;
457
458
mutex_lock(&mvm->mutex);
459
iwl_mvm_get_sync_time(mvm, CLOCK_BOOTTIME, &curr_gp2, &curr_os, NULL);
460
mutex_unlock(&mvm->mutex);
461
462
do_div(curr_os, NSEC_PER_USEC);
463
diff = curr_os - curr_gp2;
464
pos += scnprintf(buf + pos, bufsz - pos, "diff=%lld\n", diff);
465
466
return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
467
}
468
469
static ssize_t
470
iwl_dbgfs_low_latency_write_handle(struct wiphy *wiphy, struct file *file,
471
char *buf, size_t count, void *data)
472
{
473
struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
474
struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
475
struct ieee80211_vif *vif = data;
476
u8 value;
477
int ret;
478
479
ret = kstrtou8(buf, 0, &value);
480
if (ret)
481
return ret;
482
if (value > 1)
483
return -EINVAL;
484
485
mutex_lock(&mvm->mutex);
486
iwl_mvm_update_low_latency(mvm, vif, value, LOW_LATENCY_DEBUGFS);
487
mutex_unlock(&mvm->mutex);
488
489
return count;
490
}
491
492
static ssize_t iwl_dbgfs_low_latency_write(struct file *file,
493
const char __user *user_buf,
494
size_t count, loff_t *ppos)
495
{
496
struct ieee80211_vif *vif = file->private_data;
497
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
498
struct iwl_mvm *mvm = mvmvif->mvm;
499
char buf[10] = {};
500
501
return wiphy_locked_debugfs_write(mvm->hw->wiphy, file,
502
buf, sizeof(buf), user_buf, count,
503
iwl_dbgfs_low_latency_write_handle,
504
vif);
505
}
506
507
static ssize_t
508
iwl_dbgfs_low_latency_force_write_handle(struct wiphy *wiphy, struct file *file,
509
char *buf, size_t count, void *data)
510
{
511
struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
512
struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
513
struct ieee80211_vif *vif = data;
514
u8 value;
515
int ret;
516
517
ret = kstrtou8(buf, 0, &value);
518
if (ret)
519
return ret;
520
521
if (value > NUM_LOW_LATENCY_FORCE)
522
return -EINVAL;
523
524
mutex_lock(&mvm->mutex);
525
if (value == LOW_LATENCY_FORCE_UNSET) {
526
iwl_mvm_update_low_latency(mvm, vif, false,
527
LOW_LATENCY_DEBUGFS_FORCE);
528
iwl_mvm_update_low_latency(mvm, vif, false,
529
LOW_LATENCY_DEBUGFS_FORCE_ENABLE);
530
} else {
531
iwl_mvm_update_low_latency(mvm, vif,
532
value == LOW_LATENCY_FORCE_ON,
533
LOW_LATENCY_DEBUGFS_FORCE);
534
iwl_mvm_update_low_latency(mvm, vif, true,
535
LOW_LATENCY_DEBUGFS_FORCE_ENABLE);
536
}
537
mutex_unlock(&mvm->mutex);
538
return count;
539
}
540
541
static ssize_t
542
iwl_dbgfs_low_latency_force_write(struct file *file,
543
const char __user *user_buf,
544
size_t count, loff_t *ppos)
545
{
546
struct ieee80211_vif *vif = file->private_data;
547
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
548
struct iwl_mvm *mvm = mvmvif->mvm;
549
char buf[10] = {};
550
551
return wiphy_locked_debugfs_write(mvm->hw->wiphy, file,
552
buf, sizeof(buf), user_buf, count,
553
iwl_dbgfs_low_latency_force_write_handle,
554
vif);
555
}
556
557
static ssize_t iwl_dbgfs_low_latency_read(struct file *file,
558
char __user *user_buf,
559
size_t count, loff_t *ppos)
560
{
561
struct ieee80211_vif *vif = file->private_data;
562
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
563
char format[] = "traffic=%d\ndbgfs=%d\nvcmd=%d\nvif_type=%d\n"
564
"dbgfs_force_enable=%d\ndbgfs_force=%d\nactual=%d\n";
565
566
/*
567
* all values in format are boolean so the size of format is enough
568
* for holding the result string
569
*/
570
char buf[sizeof(format) + 1] = {};
571
int len;
572
573
len = scnprintf(buf, sizeof(buf) - 1, format,
574
!!(mvmvif->low_latency & LOW_LATENCY_TRAFFIC),
575
!!(mvmvif->low_latency & LOW_LATENCY_DEBUGFS),
576
!!(mvmvif->low_latency & LOW_LATENCY_VCMD),
577
!!(mvmvif->low_latency & LOW_LATENCY_VIF_TYPE),
578
!!(mvmvif->low_latency &
579
LOW_LATENCY_DEBUGFS_FORCE_ENABLE),
580
!!(mvmvif->low_latency & LOW_LATENCY_DEBUGFS_FORCE),
581
!!(mvmvif->low_latency_actual));
582
return simple_read_from_buffer(user_buf, count, ppos, buf, len);
583
}
584
585
static ssize_t iwl_dbgfs_uapsd_misbehaving_read(struct file *file,
586
char __user *user_buf,
587
size_t count, loff_t *ppos)
588
{
589
struct ieee80211_vif *vif = file->private_data;
590
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
591
char buf[20];
592
int len;
593
594
#if defined(__linux__)
595
len = sprintf(buf, "%pM\n", mvmvif->uapsd_misbehaving_ap_addr);
596
#elif defined(__FreeBSD__)
597
len = sprintf(buf, "%6D\n", mvmvif->uapsd_misbehaving_ap_addr, ":");
598
#endif
599
return simple_read_from_buffer(user_buf, count, ppos, buf, len);
600
}
601
602
static ssize_t iwl_dbgfs_uapsd_misbehaving_write(struct ieee80211_vif *vif,
603
char *buf, size_t count,
604
loff_t *ppos)
605
{
606
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
607
struct iwl_mvm *mvm = mvmvif->mvm;
608
bool ret;
609
610
mutex_lock(&mvm->mutex);
611
ret = mac_pton(buf, mvmvif->uapsd_misbehaving_ap_addr);
612
mutex_unlock(&mvm->mutex);
613
614
return ret ? count : -EINVAL;
615
}
616
617
static ssize_t iwl_dbgfs_rx_phyinfo_write(struct ieee80211_vif *vif, char *buf,
618
size_t count, loff_t *ppos)
619
{
620
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
621
struct iwl_mvm *mvm = mvmvif->mvm;
622
struct ieee80211_bss_conf *link_conf;
623
u16 value;
624
int link_id, ret = -EINVAL;
625
626
ret = kstrtou16(buf, 0, &value);
627
if (ret)
628
return ret;
629
630
mutex_lock(&mvm->mutex);
631
632
mvm->dbgfs_rx_phyinfo = value;
633
634
for_each_vif_active_link(vif, link_conf, link_id) {
635
struct ieee80211_chanctx_conf *chanctx_conf;
636
struct cfg80211_chan_def min_def, ap_def;
637
struct iwl_mvm_phy_ctxt *phy_ctxt;
638
u8 chains_static, chains_dynamic;
639
640
rcu_read_lock();
641
chanctx_conf = rcu_dereference(link_conf->chanctx_conf);
642
if (!chanctx_conf) {
643
rcu_read_unlock();
644
continue;
645
}
646
/* A command can't be sent with RCU lock held, so copy
647
* everything here and use it after unlocking
648
*/
649
min_def = chanctx_conf->min_def;
650
ap_def = chanctx_conf->ap;
651
chains_static = chanctx_conf->rx_chains_static;
652
chains_dynamic = chanctx_conf->rx_chains_dynamic;
653
rcu_read_unlock();
654
655
phy_ctxt = mvmvif->link[link_id]->phy_ctxt;
656
if (!phy_ctxt)
657
continue;
658
659
ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &min_def, &ap_def,
660
chains_static, chains_dynamic);
661
}
662
663
mutex_unlock(&mvm->mutex);
664
665
return ret ?: count;
666
}
667
668
static ssize_t iwl_dbgfs_rx_phyinfo_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[8];
675
int len;
676
677
len = scnprintf(buf, sizeof(buf), "0x%04x\n",
678
mvmvif->mvm->dbgfs_rx_phyinfo);
679
680
return simple_read_from_buffer(user_buf, count, ppos, buf, len);
681
}
682
683
static void iwl_dbgfs_quota_check(void *data, u8 *mac,
684
struct ieee80211_vif *vif)
685
{
686
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
687
int *ret = data;
688
689
if (mvmvif->dbgfs_quota_min)
690
*ret = -EINVAL;
691
}
692
693
static ssize_t iwl_dbgfs_quota_min_write(struct ieee80211_vif *vif, char *buf,
694
size_t count, loff_t *ppos)
695
{
696
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
697
struct iwl_mvm *mvm = mvmvif->mvm;
698
u16 value;
699
int ret;
700
701
ret = kstrtou16(buf, 0, &value);
702
if (ret)
703
return ret;
704
705
if (value > 95)
706
return -EINVAL;
707
708
mutex_lock(&mvm->mutex);
709
710
mvmvif->dbgfs_quota_min = 0;
711
ieee80211_iterate_interfaces(mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
712
iwl_dbgfs_quota_check, &ret);
713
if (ret == 0) {
714
mvmvif->dbgfs_quota_min = value;
715
iwl_mvm_update_quotas(mvm, false, NULL);
716
}
717
mutex_unlock(&mvm->mutex);
718
719
return ret ?: count;
720
}
721
722
static ssize_t iwl_dbgfs_quota_min_read(struct file *file,
723
char __user *user_buf,
724
size_t count, loff_t *ppos)
725
{
726
struct ieee80211_vif *vif = file->private_data;
727
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
728
char buf[10];
729
int len;
730
731
len = scnprintf(buf, sizeof(buf), "%d\n", mvmvif->dbgfs_quota_min);
732
733
return simple_read_from_buffer(user_buf, count, ppos, buf, len);
734
}
735
736
static ssize_t iwl_dbgfs_max_tx_op_write(struct ieee80211_vif *vif, char *buf,
737
size_t count, loff_t *ppos)
738
{
739
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
740
struct iwl_mvm *mvm = mvmvif->mvm;
741
u16 value;
742
int ret;
743
744
ret = kstrtou16(buf, 0, &value);
745
if (ret)
746
return ret;
747
748
mutex_lock(&mvm->mutex);
749
mvmvif->max_tx_op = value;
750
mutex_unlock(&mvm->mutex);
751
752
return count;
753
}
754
755
static ssize_t iwl_dbgfs_max_tx_op_read(struct file *file,
756
char __user *user_buf,
757
size_t count, loff_t *ppos)
758
{
759
struct ieee80211_vif *vif = file->private_data;
760
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
761
struct iwl_mvm *mvm = mvmvif->mvm;
762
char buf[10];
763
int len;
764
765
mutex_lock(&mvm->mutex);
766
len = scnprintf(buf, sizeof(buf), "%hu\n", mvmvif->max_tx_op);
767
mutex_unlock(&mvm->mutex);
768
769
return simple_read_from_buffer(user_buf, count, ppos, buf, len);
770
}
771
772
static ssize_t iwl_dbgfs_int_mlo_scan_write(struct ieee80211_vif *vif,
773
char *buf, size_t count,
774
loff_t *ppos)
775
{
776
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
777
struct iwl_mvm *mvm = mvmvif->mvm;
778
u32 action;
779
int ret;
780
781
if (!vif->cfg.assoc || !ieee80211_vif_is_mld(vif))
782
return -EINVAL;
783
784
if (kstrtou32(buf, 0, &action))
785
return -EINVAL;
786
787
mutex_lock(&mvm->mutex);
788
789
if (!action) {
790
ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_INT_MLO, false);
791
} else if (action == 1) {
792
ret = iwl_mvm_int_mlo_scan(mvm, vif);
793
} else {
794
ret = -EINVAL;
795
}
796
797
mutex_unlock(&mvm->mutex);
798
799
return ret ?: count;
800
}
801
802
static ssize_t iwl_dbgfs_esr_disable_reason_read(struct file *file,
803
char __user *user_buf,
804
size_t count, loff_t *ppos)
805
{
806
struct ieee80211_vif *vif = file->private_data;
807
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
808
struct iwl_mvm *mvm = mvmvif->mvm;
809
unsigned long esr_mask;
810
char *buf;
811
int bufsz, pos, i;
812
ssize_t rv;
813
814
mutex_lock(&mvm->mutex);
815
esr_mask = mvmvif->esr_disable_reason;
816
mutex_unlock(&mvm->mutex);
817
818
bufsz = hweight32(esr_mask) * 32 + 40;
819
buf = kmalloc(bufsz, GFP_KERNEL);
820
if (!buf)
821
return -ENOMEM;
822
823
pos = scnprintf(buf, bufsz, "EMLSR state: '0x%lx'\nreasons:\n",
824
esr_mask);
825
for_each_set_bit(i, &esr_mask, BITS_PER_LONG)
826
pos += scnprintf(buf + pos, bufsz - pos, " - %s\n",
827
iwl_get_esr_state_string(BIT(i)));
828
829
rv = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
830
kfree(buf);
831
return rv;
832
}
833
834
static ssize_t iwl_dbgfs_esr_disable_reason_write(struct ieee80211_vif *vif,
835
char *buf, size_t count,
836
loff_t *ppos)
837
{
838
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
839
struct iwl_mvm *mvm = mvmvif->mvm;
840
u32 reason;
841
u8 block;
842
int ret;
843
844
ret = sscanf(buf, "%u %hhu", &reason, &block);
845
if (ret < 0)
846
return ret;
847
848
if (hweight16(reason) != 1 || !(reason & IWL_MVM_BLOCK_ESR_REASONS))
849
return -EINVAL;
850
851
mutex_lock(&mvm->mutex);
852
if (block)
853
iwl_mvm_block_esr(mvm, vif, reason,
854
iwl_mvm_get_primary_link(vif));
855
else
856
iwl_mvm_unblock_esr(mvm, vif, reason);
857
mutex_unlock(&mvm->mutex);
858
859
return count;
860
}
861
862
#define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
863
_MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
864
#define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
865
_MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
866
#define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \
867
debugfs_create_file(#name, mode, parent, vif, \
868
&iwl_dbgfs_##name##_ops); \
869
} while (0)
870
871
MVM_DEBUGFS_READ_FILE_OPS(mac_params);
872
MVM_DEBUGFS_READ_FILE_OPS(tx_pwr_lmt);
873
MVM_DEBUGFS_READ_WRITE_FILE_OPS(pm_params, 32);
874
MVM_DEBUGFS_READ_WRITE_FILE_OPS(bf_params, 256);
875
876
static const struct file_operations iwl_dbgfs_low_latency_ops = {
877
.write = iwl_dbgfs_low_latency_write,
878
.read = iwl_dbgfs_low_latency_read,
879
.open = simple_open,
880
.llseek = generic_file_llseek,
881
};
882
883
static const struct file_operations iwl_dbgfs_low_latency_force_ops = {
884
.write = iwl_dbgfs_low_latency_force_write,
885
.open = simple_open,
886
.llseek = generic_file_llseek,
887
};
888
889
MVM_DEBUGFS_READ_WRITE_FILE_OPS(uapsd_misbehaving, 20);
890
MVM_DEBUGFS_READ_WRITE_FILE_OPS(rx_phyinfo, 10);
891
MVM_DEBUGFS_READ_WRITE_FILE_OPS(quota_min, 32);
892
MVM_DEBUGFS_READ_FILE_OPS(os_device_timediff);
893
MVM_DEBUGFS_READ_WRITE_FILE_OPS(max_tx_op, 10);
894
MVM_DEBUGFS_WRITE_FILE_OPS(int_mlo_scan, 32);
895
MVM_DEBUGFS_READ_WRITE_FILE_OPS(esr_disable_reason, 32);
896
897
void iwl_mvm_vif_add_debugfs(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
898
{
899
struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
900
struct dentry *dbgfs_dir = vif->debugfs_dir;
901
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
902
903
mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir);
904
if (IS_ERR_OR_NULL(mvmvif->dbgfs_dir)) {
905
IWL_ERR(mvm, "Failed to create debugfs directory under %pd\n",
906
dbgfs_dir);
907
return;
908
}
909
910
if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM &&
911
((vif->type == NL80211_IFTYPE_STATION && !vif->p2p) ||
912
(vif->type == NL80211_IFTYPE_STATION && vif->p2p)))
913
MVM_DEBUGFS_ADD_FILE_VIF(pm_params, mvmvif->dbgfs_dir, 0600);
914
915
MVM_DEBUGFS_ADD_FILE_VIF(tx_pwr_lmt, mvmvif->dbgfs_dir, 0400);
916
MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir, 0400);
917
MVM_DEBUGFS_ADD_FILE_VIF(low_latency, mvmvif->dbgfs_dir, 0600);
918
MVM_DEBUGFS_ADD_FILE_VIF(low_latency_force, mvmvif->dbgfs_dir, 0600);
919
MVM_DEBUGFS_ADD_FILE_VIF(uapsd_misbehaving, mvmvif->dbgfs_dir, 0600);
920
MVM_DEBUGFS_ADD_FILE_VIF(rx_phyinfo, mvmvif->dbgfs_dir, 0600);
921
MVM_DEBUGFS_ADD_FILE_VIF(quota_min, mvmvif->dbgfs_dir, 0600);
922
MVM_DEBUGFS_ADD_FILE_VIF(os_device_timediff, mvmvif->dbgfs_dir, 0400);
923
MVM_DEBUGFS_ADD_FILE_VIF(max_tx_op, mvmvif->dbgfs_dir, 0600);
924
debugfs_create_bool("ftm_unprotected", 0200, mvmvif->dbgfs_dir,
925
&mvmvif->ftm_unprotected);
926
MVM_DEBUGFS_ADD_FILE_VIF(int_mlo_scan, mvmvif->dbgfs_dir, 0200);
927
MVM_DEBUGFS_ADD_FILE_VIF(esr_disable_reason, mvmvif->dbgfs_dir, 0600);
928
929
if (vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
930
mvmvif == mvm->bf_allowed_vif)
931
MVM_DEBUGFS_ADD_FILE_VIF(bf_params, mvmvif->dbgfs_dir, 0600);
932
}
933
934
void iwl_mvm_vif_dbgfs_add_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
935
{
936
struct dentry *dbgfs_dir = vif->debugfs_dir;
937
#if defined(__linux__)
938
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
939
char buf[3 * 3 + 11 + (NL80211_WIPHY_NAME_MAXLEN + 1) +
940
(7 + IFNAMSIZ + 1) + 6 + 1];
941
char name[7 + IFNAMSIZ + 1];
942
#endif
943
944
/* this will happen in monitor mode */
945
if (!dbgfs_dir)
946
return;
947
948
#if defined(__linux__)
949
/*
950
* Create symlink for convenience pointing to interface specific
951
* debugfs entries for the driver. For example, under
952
* /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/
953
* find
954
* netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/
955
*/
956
snprintf(name, sizeof(name), "%pd", dbgfs_dir);
957
snprintf(buf, sizeof(buf), "../../../%pd3/iwlmvm", dbgfs_dir);
958
959
mvmvif->dbgfs_slink =
960
debugfs_create_symlink(name, mvm->debugfs_dir, buf);
961
#endif
962
}
963
964
void iwl_mvm_vif_dbgfs_rm_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
965
{
966
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
967
968
debugfs_remove(mvmvif->dbgfs_slink);
969
mvmvif->dbgfs_slink = NULL;
970
}
971
972
#define MVM_DEBUGFS_WRITE_LINK_FILE_OPS(name, bufsz) \
973
_MVM_DEBUGFS_WRITE_FILE_OPS(link_##name, bufsz, \
974
struct ieee80211_bss_conf)
975
#define MVM_DEBUGFS_READ_WRITE_LINK_FILE_OPS(name, bufsz) \
976
_MVM_DEBUGFS_READ_WRITE_FILE_OPS(link_##name, bufsz, \
977
struct ieee80211_bss_conf)
978
#define MVM_DEBUGFS_ADD_LINK_FILE(name, parent, mode) \
979
debugfs_create_file(#name, mode, parent, link_conf, \
980
&iwl_dbgfs_link_##name##_ops)
981
982
static void iwl_mvm_debugfs_add_link_files(struct ieee80211_vif *vif,
983
struct ieee80211_bss_conf *link_conf,
984
struct dentry *mvm_dir)
985
{
986
/* Add per-link files here*/
987
}
988
989
void iwl_mvm_link_add_debugfs(struct ieee80211_hw *hw,
990
struct ieee80211_vif *vif,
991
struct ieee80211_bss_conf *link_conf,
992
struct dentry *dir)
993
{
994
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
995
struct iwl_mvm *mvm = mvmvif->mvm;
996
unsigned int link_id = link_conf->link_id;
997
struct iwl_mvm_vif_link_info *link_info = mvmvif->link[link_id];
998
struct dentry *mvm_dir;
999
1000
if (WARN_ON(!link_info) || !dir)
1001
return;
1002
1003
if (dir == vif->debugfs_dir) {
1004
WARN_ON(!mvmvif->dbgfs_dir);
1005
mvm_dir = mvmvif->dbgfs_dir;
1006
} else {
1007
mvm_dir = debugfs_create_dir("iwlmvm", dir);
1008
if (IS_ERR_OR_NULL(mvm_dir)) {
1009
IWL_ERR(mvm, "Failed to create debugfs directory under %pd\n",
1010
dir);
1011
return;
1012
}
1013
}
1014
1015
iwl_mvm_debugfs_add_link_files(vif, link_conf, mvm_dir);
1016
}
1017
1018