GNU Linux-libre 4.14.266-gnu1
[releases.git] / drivers / net / wireless / intel / iwlwifi / mvm / debugfs-vif.c
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
71 static void iwl_dbgfs_update_pm(struct iwl_mvm *mvm,
72                                  struct ieee80211_vif *vif,
73                                  enum iwl_dbgfs_pm_mask param, int val)
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
133 static 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
196 static ssize_t iwl_dbgfs_tx_pwr_lmt_read(struct file *file,
197                                          char __user *user_buf,
198                                          size_t count, loff_t *ppos)
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
211 static 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
227 static 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
309 static 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
354 static 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
451 static 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
500 static 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
507 static ssize_t iwl_dbgfs_os_device_timediff_read(struct file *file,
508                                                  char __user *user_buf,
509                                                  size_t count, loff_t *ppos)
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         mutex_lock(&mvm->mutex);
522         iwl_mvm_get_sync_time(mvm, &curr_gp2, &curr_os);
523         mutex_unlock(&mvm->mutex);
524
525         do_div(curr_os, NSEC_PER_USEC);
526         diff = curr_os - curr_gp2;
527         pos += scnprintf(buf + pos, bufsz - pos, "diff=%lld\n", diff);
528
529         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
530 }
531
532 static ssize_t iwl_dbgfs_tof_enable_write(struct ieee80211_vif *vif,
533                                           char *buf,
534                                           size_t count, loff_t *ppos)
535 {
536         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
537         struct iwl_mvm *mvm = mvmvif->mvm;
538         u32 value;
539         int ret = -EINVAL;
540         char *data;
541
542         mutex_lock(&mvm->mutex);
543
544         data = iwl_dbgfs_is_match("tof_disabled=", buf);
545         if (data) {
546                 ret = kstrtou32(data, 10, &value);
547                 if (ret == 0)
548                         mvm->tof_data.tof_cfg.tof_disabled = value;
549                 goto out;
550         }
551
552         data = iwl_dbgfs_is_match("one_sided_disabled=", buf);
553         if (data) {
554                 ret = kstrtou32(data, 10, &value);
555                 if (ret == 0)
556                         mvm->tof_data.tof_cfg.one_sided_disabled = value;
557                 goto out;
558         }
559
560         data = iwl_dbgfs_is_match("is_debug_mode=", buf);
561         if (data) {
562                 ret = kstrtou32(data, 10, &value);
563                 if (ret == 0)
564                         mvm->tof_data.tof_cfg.is_debug_mode = value;
565                 goto out;
566         }
567
568         data = iwl_dbgfs_is_match("is_buf=", buf);
569         if (data) {
570                 ret = kstrtou32(data, 10, &value);
571                 if (ret == 0)
572                         mvm->tof_data.tof_cfg.is_buf_required = value;
573                 goto out;
574         }
575
576         data = iwl_dbgfs_is_match("send_tof_cfg=", buf);
577         if (data) {
578                 ret = kstrtou32(data, 10, &value);
579                 if (ret == 0 && value) {
580                         ret = iwl_mvm_tof_config_cmd(mvm);
581                         goto out;
582                 }
583         }
584
585 out:
586         mutex_unlock(&mvm->mutex);
587
588         return ret ?: count;
589 }
590
591 static ssize_t iwl_dbgfs_tof_enable_read(struct file *file,
592                                          char __user *user_buf,
593                                          size_t count, loff_t *ppos)
594 {
595         struct ieee80211_vif *vif = file->private_data;
596         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
597         struct iwl_mvm *mvm = mvmvif->mvm;
598         char buf[256];
599         int pos = 0;
600         const size_t bufsz = sizeof(buf);
601         struct iwl_tof_config_cmd *cmd;
602
603         cmd = &mvm->tof_data.tof_cfg;
604
605         mutex_lock(&mvm->mutex);
606
607         pos += scnprintf(buf + pos, bufsz - pos, "tof_disabled = %d\n",
608                          cmd->tof_disabled);
609         pos += scnprintf(buf + pos, bufsz - pos, "one_sided_disabled = %d\n",
610                          cmd->one_sided_disabled);
611         pos += scnprintf(buf + pos, bufsz - pos, "is_debug_mode = %d\n",
612                          cmd->is_debug_mode);
613         pos += scnprintf(buf + pos, bufsz - pos, "is_buf_required = %d\n",
614                          cmd->is_buf_required);
615
616         mutex_unlock(&mvm->mutex);
617
618         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
619 }
620
621 static ssize_t iwl_dbgfs_tof_responder_params_write(struct ieee80211_vif *vif,
622                                                     char *buf,
623                                                     size_t count, loff_t *ppos)
624 {
625         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
626         struct iwl_mvm *mvm = mvmvif->mvm;
627         u32 value;
628         int ret = 0;
629         char *data;
630
631         mutex_lock(&mvm->mutex);
632
633         data = iwl_dbgfs_is_match("burst_period=", buf);
634         if (data) {
635                 ret = kstrtou32(data, 10, &value);
636                 if (!ret)
637                         mvm->tof_data.responder_cfg.burst_period =
638                                                         cpu_to_le16(value);
639                 goto out;
640         }
641
642         data = iwl_dbgfs_is_match("min_delta_ftm=", buf);
643         if (data) {
644                 ret = kstrtou32(data, 10, &value);
645                 if (ret == 0)
646                         mvm->tof_data.responder_cfg.min_delta_ftm = value;
647                 goto out;
648         }
649
650         data = iwl_dbgfs_is_match("burst_duration=", buf);
651         if (data) {
652                 ret = kstrtou32(data, 10, &value);
653                 if (ret == 0)
654                         mvm->tof_data.responder_cfg.burst_duration = value;
655                 goto out;
656         }
657
658         data = iwl_dbgfs_is_match("num_of_burst_exp=", buf);
659         if (data) {
660                 ret = kstrtou32(data, 10, &value);
661                 if (ret == 0)
662                         mvm->tof_data.responder_cfg.num_of_burst_exp = value;
663                 goto out;
664         }
665
666         data = iwl_dbgfs_is_match("abort_responder=", buf);
667         if (data) {
668                 ret = kstrtou32(data, 10, &value);
669                 if (ret == 0)
670                         mvm->tof_data.responder_cfg.abort_responder = value;
671                 goto out;
672         }
673
674         data = iwl_dbgfs_is_match("get_ch_est=", buf);
675         if (data) {
676                 ret = kstrtou32(data, 10, &value);
677                 if (ret == 0)
678                         mvm->tof_data.responder_cfg.get_ch_est = value;
679                 goto out;
680         }
681
682         data = iwl_dbgfs_is_match("recv_sta_req_params=", buf);
683         if (data) {
684                 ret = kstrtou32(data, 10, &value);
685                 if (ret == 0)
686                         mvm->tof_data.responder_cfg.recv_sta_req_params = value;
687                 goto out;
688         }
689
690         data = iwl_dbgfs_is_match("channel_num=", buf);
691         if (data) {
692                 ret = kstrtou32(data, 10, &value);
693                 if (ret == 0)
694                         mvm->tof_data.responder_cfg.channel_num = value;
695                 goto out;
696         }
697
698         data = iwl_dbgfs_is_match("bandwidth=", buf);
699         if (data) {
700                 ret = kstrtou32(data, 10, &value);
701                 if (ret == 0)
702                         mvm->tof_data.responder_cfg.bandwidth = value;
703                 goto out;
704         }
705
706         data = iwl_dbgfs_is_match("rate=", buf);
707         if (data) {
708                 ret = kstrtou32(data, 10, &value);
709                 if (ret == 0)
710                         mvm->tof_data.responder_cfg.rate = value;
711                 goto out;
712         }
713
714         data = iwl_dbgfs_is_match("bssid=", buf);
715         if (data) {
716                 u8 *mac = mvm->tof_data.responder_cfg.bssid;
717
718                 if (!mac_pton(data, mac)) {
719                         ret = -EINVAL;
720                         goto out;
721                 }
722         }
723
724         data = iwl_dbgfs_is_match("tsf_timer_offset_msecs=", buf);
725         if (data) {
726                 ret = kstrtou32(data, 10, &value);
727                 if (ret == 0)
728                         mvm->tof_data.responder_cfg.tsf_timer_offset_msecs =
729                                                         cpu_to_le16(value);
730                 goto out;
731         }
732
733         data = iwl_dbgfs_is_match("toa_offset=", buf);
734         if (data) {
735                 ret = kstrtou32(data, 10, &value);
736                 if (ret == 0)
737                         mvm->tof_data.responder_cfg.toa_offset =
738                                                         cpu_to_le16(value);
739                 goto out;
740         }
741
742         data = iwl_dbgfs_is_match("center_freq=", buf);
743         if (data) {
744                 struct iwl_tof_responder_config_cmd *cmd =
745                         &mvm->tof_data.responder_cfg;
746
747                 ret = kstrtou32(data, 10, &value);
748                 if (ret == 0 && value) {
749                         enum nl80211_band band = (cmd->channel_num <= 14) ?
750                                                    NL80211_BAND_2GHZ :
751                                                    NL80211_BAND_5GHZ;
752                         struct ieee80211_channel chn = {
753                                 .band = band,
754                                 .center_freq = ieee80211_channel_to_frequency(
755                                         cmd->channel_num, band),
756                                 };
757                         struct cfg80211_chan_def chandef = {
758                                 .chan =  &chn,
759                                 .center_freq1 =
760                                         ieee80211_channel_to_frequency(value,
761                                                                        band),
762                         };
763
764                         cmd->ctrl_ch_position = iwl_mvm_get_ctrl_pos(&chandef);
765                 }
766                 goto out;
767         }
768
769         data = iwl_dbgfs_is_match("ftm_per_burst=", buf);
770         if (data) {
771                 ret = kstrtou32(data, 10, &value);
772                 if (ret == 0)
773                         mvm->tof_data.responder_cfg.ftm_per_burst = value;
774                 goto out;
775         }
776
777         data = iwl_dbgfs_is_match("ftm_resp_ts_avail=", buf);
778         if (data) {
779                 ret = kstrtou32(data, 10, &value);
780                 if (ret == 0)
781                         mvm->tof_data.responder_cfg.ftm_resp_ts_avail = value;
782                 goto out;
783         }
784
785         data = iwl_dbgfs_is_match("asap_mode=", buf);
786         if (data) {
787                 ret = kstrtou32(data, 10, &value);
788                 if (ret == 0)
789                         mvm->tof_data.responder_cfg.asap_mode = value;
790                 goto out;
791         }
792
793         data = iwl_dbgfs_is_match("send_responder_cfg=", buf);
794         if (data) {
795                 ret = kstrtou32(data, 10, &value);
796                 if (ret == 0 && value) {
797                         ret = iwl_mvm_tof_responder_cmd(mvm, vif);
798                         goto out;
799                 }
800         }
801
802 out:
803         mutex_unlock(&mvm->mutex);
804
805         return ret ?: count;
806 }
807
808 static ssize_t iwl_dbgfs_tof_responder_params_read(struct file *file,
809                                                    char __user *user_buf,
810                                                    size_t count, loff_t *ppos)
811 {
812         struct ieee80211_vif *vif = file->private_data;
813         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
814         struct iwl_mvm *mvm = mvmvif->mvm;
815         char buf[256];
816         int pos = 0;
817         const size_t bufsz = sizeof(buf);
818         struct iwl_tof_responder_config_cmd *cmd;
819
820         cmd = &mvm->tof_data.responder_cfg;
821
822         mutex_lock(&mvm->mutex);
823
824         pos += scnprintf(buf + pos, bufsz - pos, "burst_period = %d\n",
825                          le16_to_cpu(cmd->burst_period));
826         pos += scnprintf(buf + pos, bufsz - pos, "burst_duration = %d\n",
827                          cmd->burst_duration);
828         pos += scnprintf(buf + pos, bufsz - pos, "bandwidth = %d\n",
829                          cmd->bandwidth);
830         pos += scnprintf(buf + pos, bufsz - pos, "channel_num = %d\n",
831                          cmd->channel_num);
832         pos += scnprintf(buf + pos, bufsz - pos, "ctrl_ch_position = 0x%x\n",
833                          cmd->ctrl_ch_position);
834         pos += scnprintf(buf + pos, bufsz - pos, "bssid = %pM\n",
835                          cmd->bssid);
836         pos += scnprintf(buf + pos, bufsz - pos, "min_delta_ftm = %d\n",
837                          cmd->min_delta_ftm);
838         pos += scnprintf(buf + pos, bufsz - pos, "num_of_burst_exp = %d\n",
839                          cmd->num_of_burst_exp);
840         pos += scnprintf(buf + pos, bufsz - pos, "rate = %d\n", cmd->rate);
841         pos += scnprintf(buf + pos, bufsz - pos, "abort_responder = %d\n",
842                          cmd->abort_responder);
843         pos += scnprintf(buf + pos, bufsz - pos, "get_ch_est = %d\n",
844                          cmd->get_ch_est);
845         pos += scnprintf(buf + pos, bufsz - pos, "recv_sta_req_params = %d\n",
846                          cmd->recv_sta_req_params);
847         pos += scnprintf(buf + pos, bufsz - pos, "ftm_per_burst = %d\n",
848                          cmd->ftm_per_burst);
849         pos += scnprintf(buf + pos, bufsz - pos, "ftm_resp_ts_avail = %d\n",
850                          cmd->ftm_resp_ts_avail);
851         pos += scnprintf(buf + pos, bufsz - pos, "asap_mode = %d\n",
852                          cmd->asap_mode);
853         pos += scnprintf(buf + pos, bufsz - pos,
854                          "tsf_timer_offset_msecs = %d\n",
855                          le16_to_cpu(cmd->tsf_timer_offset_msecs));
856         pos += scnprintf(buf + pos, bufsz - pos, "toa_offset = %d\n",
857                          le16_to_cpu(cmd->toa_offset));
858
859         mutex_unlock(&mvm->mutex);
860
861         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
862 }
863
864 static ssize_t iwl_dbgfs_tof_range_request_write(struct ieee80211_vif *vif,
865                                                  char *buf, size_t count,
866                                                  loff_t *ppos)
867 {
868         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
869         struct iwl_mvm *mvm = mvmvif->mvm;
870         u32 value;
871         int ret = 0;
872         char *data;
873
874         mutex_lock(&mvm->mutex);
875
876         data = iwl_dbgfs_is_match("request_id=", buf);
877         if (data) {
878                 ret = kstrtou32(data, 10, &value);
879                 if (ret == 0)
880                         mvm->tof_data.range_req.request_id = value;
881                 goto out;
882         }
883
884         data = iwl_dbgfs_is_match("initiator=", buf);
885         if (data) {
886                 ret = kstrtou32(data, 10, &value);
887                 if (ret == 0)
888                         mvm->tof_data.range_req.initiator = value;
889                 goto out;
890         }
891
892         data = iwl_dbgfs_is_match("one_sided_los_disable=", buf);
893         if (data) {
894                 ret = kstrtou32(data, 10, &value);
895                 if (ret == 0)
896                         mvm->tof_data.range_req.one_sided_los_disable = value;
897                 goto out;
898         }
899
900         data = iwl_dbgfs_is_match("req_timeout=", buf);
901         if (data) {
902                 ret = kstrtou32(data, 10, &value);
903                 if (ret == 0)
904                         mvm->tof_data.range_req.req_timeout = value;
905                 goto out;
906         }
907
908         data = iwl_dbgfs_is_match("report_policy=", buf);
909         if (data) {
910                 ret = kstrtou32(data, 10, &value);
911                 if (ret == 0)
912                         mvm->tof_data.range_req.report_policy = value;
913                 goto out;
914         }
915
916         data = iwl_dbgfs_is_match("macaddr_random=", buf);
917         if (data) {
918                 ret = kstrtou32(data, 10, &value);
919                 if (ret == 0)
920                         mvm->tof_data.range_req.macaddr_random = value;
921                 goto out;
922         }
923
924         data = iwl_dbgfs_is_match("num_of_ap=", buf);
925         if (data) {
926                 ret = kstrtou32(data, 10, &value);
927                 if (ret == 0)
928                         mvm->tof_data.range_req.num_of_ap = value;
929                 goto out;
930         }
931
932         data = iwl_dbgfs_is_match("macaddr_template=", buf);
933         if (data) {
934                 u8 mac[ETH_ALEN];
935
936                 if (!mac_pton(data, mac)) {
937                         ret = -EINVAL;
938                         goto out;
939                 }
940                 memcpy(mvm->tof_data.range_req.macaddr_template, mac, ETH_ALEN);
941                 goto out;
942         }
943
944         data = iwl_dbgfs_is_match("macaddr_mask=", buf);
945         if (data) {
946                 u8 mac[ETH_ALEN];
947
948                 if (!mac_pton(data, mac)) {
949                         ret = -EINVAL;
950                         goto out;
951                 }
952                 memcpy(mvm->tof_data.range_req.macaddr_mask, mac, ETH_ALEN);
953                 goto out;
954         }
955
956         data = iwl_dbgfs_is_match("ap=", buf);
957         if (data) {
958                 struct iwl_tof_range_req_ap_entry ap = {};
959                 int size = sizeof(struct iwl_tof_range_req_ap_entry);
960                 u16 burst_period;
961                 u8 *mac = ap.bssid;
962                 unsigned int i;
963
964                 if (sscanf(data, "%u %hhd %hhd %hhd"
965                            "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"
966                            "%hhd %hhd %hd"
967                            "%hhd %hhd %d"
968                            "%hhx %hhd %hhd %hhd",
969                            &i, &ap.channel_num, &ap.bandwidth,
970                            &ap.ctrl_ch_position,
971                            mac, mac + 1, mac + 2, mac + 3, mac + 4, mac + 5,
972                            &ap.measure_type, &ap.num_of_bursts,
973                            &burst_period,
974                            &ap.samples_per_burst, &ap.retries_per_sample,
975                            &ap.tsf_delta, &ap.location_req, &ap.asap_mode,
976                            &ap.enable_dyn_ack, &ap.rssi) != 20) {
977                         ret = -EINVAL;
978                         goto out;
979                 }
980                 if (i >= IWL_MVM_TOF_MAX_APS) {
981                         IWL_ERR(mvm, "Invalid AP index %d\n", i);
982                         ret = -EINVAL;
983                         goto out;
984                 }
985
986                 ap.burst_period = cpu_to_le16(burst_period);
987
988                 memcpy(&mvm->tof_data.range_req.ap[i], &ap, size);
989                 goto out;
990         }
991
992         data = iwl_dbgfs_is_match("send_range_request=", buf);
993         if (data) {
994                 ret = kstrtou32(data, 10, &value);
995                 if (ret == 0 && value)
996                         ret = iwl_mvm_tof_range_request_cmd(mvm, vif);
997                 goto out;
998         }
999
1000         ret = -EINVAL;
1001 out:
1002         mutex_unlock(&mvm->mutex);
1003         return ret ?: count;
1004 }
1005
1006 static ssize_t iwl_dbgfs_tof_range_request_read(struct file *file,
1007                                                 char __user *user_buf,
1008                                                 size_t count, loff_t *ppos)
1009 {
1010         struct ieee80211_vif *vif = file->private_data;
1011         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1012         struct iwl_mvm *mvm = mvmvif->mvm;
1013         char buf[512];
1014         int pos = 0;
1015         const size_t bufsz = sizeof(buf);
1016         struct iwl_tof_range_req_cmd *cmd;
1017         int i;
1018
1019         cmd = &mvm->tof_data.range_req;
1020
1021         mutex_lock(&mvm->mutex);
1022
1023         pos += scnprintf(buf + pos, bufsz - pos, "request_id= %d\n",
1024                          cmd->request_id);
1025         pos += scnprintf(buf + pos, bufsz - pos, "initiator= %d\n",
1026                          cmd->initiator);
1027         pos += scnprintf(buf + pos, bufsz - pos, "one_sided_los_disable = %d\n",
1028                          cmd->one_sided_los_disable);
1029         pos += scnprintf(buf + pos, bufsz - pos, "req_timeout= %d\n",
1030                          cmd->req_timeout);
1031         pos += scnprintf(buf + pos, bufsz - pos, "report_policy= %d\n",
1032                          cmd->report_policy);
1033         pos += scnprintf(buf + pos, bufsz - pos, "macaddr_random= %d\n",
1034                          cmd->macaddr_random);
1035         pos += scnprintf(buf + pos, bufsz - pos, "macaddr_template= %pM\n",
1036                          cmd->macaddr_template);
1037         pos += scnprintf(buf + pos, bufsz - pos, "macaddr_mask= %pM\n",
1038                          cmd->macaddr_mask);
1039         pos += scnprintf(buf + pos, bufsz - pos, "num_of_ap= %d\n",
1040                          cmd->num_of_ap);
1041         for (i = 0; i < cmd->num_of_ap; i++) {
1042                 struct iwl_tof_range_req_ap_entry *ap = &cmd->ap[i];
1043
1044                 pos += scnprintf(buf + pos, bufsz - pos,
1045                                 "ap %.2d: channel_num=%hhd bw=%hhd"
1046                                 " control=%hhd bssid=%pM type=%hhd"
1047                                 " num_of_bursts=%hhd burst_period=%hd ftm=%hhd"
1048                                 " retries=%hhd tsf_delta=%d"
1049                                 " tsf_delta_direction=%hhd location_req=0x%hhx "
1050                                 " asap=%hhd enable=%hhd rssi=%hhd\n",
1051                                 i, ap->channel_num, ap->bandwidth,
1052                                 ap->ctrl_ch_position, ap->bssid,
1053                                 ap->measure_type, ap->num_of_bursts,
1054                                 ap->burst_period, ap->samples_per_burst,
1055                                 ap->retries_per_sample, ap->tsf_delta,
1056                                 ap->tsf_delta_direction,
1057                                 ap->location_req, ap->asap_mode,
1058                                 ap->enable_dyn_ack, ap->rssi);
1059         }
1060
1061         mutex_unlock(&mvm->mutex);
1062
1063         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1064 }
1065
1066 static ssize_t iwl_dbgfs_tof_range_req_ext_write(struct ieee80211_vif *vif,
1067                                                  char *buf,
1068                                                  size_t count, loff_t *ppos)
1069 {
1070         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1071         struct iwl_mvm *mvm = mvmvif->mvm;
1072         u32 value;
1073         int ret = 0;
1074         char *data;
1075
1076         mutex_lock(&mvm->mutex);
1077
1078         data = iwl_dbgfs_is_match("tsf_timer_offset_msec=", buf);
1079         if (data) {
1080                 ret = kstrtou32(data, 10, &value);
1081                 if (ret == 0)
1082                         mvm->tof_data.range_req_ext.tsf_timer_offset_msec =
1083                                                         cpu_to_le16(value);
1084                 goto out;
1085         }
1086
1087         data = iwl_dbgfs_is_match("min_delta_ftm=", buf);
1088         if (data) {
1089                 ret = kstrtou32(data, 10, &value);
1090                 if (ret == 0)
1091                         mvm->tof_data.range_req_ext.min_delta_ftm = value;
1092                 goto out;
1093         }
1094
1095         data = iwl_dbgfs_is_match("ftm_format_and_bw20M=", buf);
1096         if (data) {
1097                 ret = kstrtou32(data, 10, &value);
1098                 if (ret == 0)
1099                         mvm->tof_data.range_req_ext.ftm_format_and_bw20M =
1100                                                                         value;
1101                 goto out;
1102         }
1103
1104         data = iwl_dbgfs_is_match("ftm_format_and_bw40M=", buf);
1105         if (data) {
1106                 ret = kstrtou32(data, 10, &value);
1107                 if (ret == 0)
1108                         mvm->tof_data.range_req_ext.ftm_format_and_bw40M =
1109                                                                         value;
1110                 goto out;
1111         }
1112
1113         data = iwl_dbgfs_is_match("ftm_format_and_bw80M=", buf);
1114         if (data) {
1115                 ret = kstrtou32(data, 10, &value);
1116                 if (ret == 0)
1117                         mvm->tof_data.range_req_ext.ftm_format_and_bw80M =
1118                                                                         value;
1119                 goto out;
1120         }
1121
1122         data = iwl_dbgfs_is_match("send_range_req_ext=", buf);
1123         if (data) {
1124                 ret = kstrtou32(data, 10, &value);
1125                 if (ret == 0 && value)
1126                         ret = iwl_mvm_tof_range_request_ext_cmd(mvm, vif);
1127                 goto out;
1128         }
1129
1130         ret = -EINVAL;
1131 out:
1132         mutex_unlock(&mvm->mutex);
1133         return ret ?: count;
1134 }
1135
1136 static ssize_t iwl_dbgfs_tof_range_req_ext_read(struct file *file,
1137                                                 char __user *user_buf,
1138                                                 size_t count, loff_t *ppos)
1139 {
1140         struct ieee80211_vif *vif = file->private_data;
1141         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1142         struct iwl_mvm *mvm = mvmvif->mvm;
1143         char buf[256];
1144         int pos = 0;
1145         const size_t bufsz = sizeof(buf);
1146         struct iwl_tof_range_req_ext_cmd *cmd;
1147
1148         cmd = &mvm->tof_data.range_req_ext;
1149
1150         mutex_lock(&mvm->mutex);
1151
1152         pos += scnprintf(buf + pos, bufsz - pos,
1153                          "tsf_timer_offset_msec = %hd\n",
1154                          cmd->tsf_timer_offset_msec);
1155         pos += scnprintf(buf + pos, bufsz - pos, "min_delta_ftm = %hhd\n",
1156                          cmd->min_delta_ftm);
1157         pos += scnprintf(buf + pos, bufsz - pos,
1158                          "ftm_format_and_bw20M = %hhd\n",
1159                          cmd->ftm_format_and_bw20M);
1160         pos += scnprintf(buf + pos, bufsz - pos,
1161                          "ftm_format_and_bw40M = %hhd\n",
1162                          cmd->ftm_format_and_bw40M);
1163         pos += scnprintf(buf + pos, bufsz - pos,
1164                          "ftm_format_and_bw80M = %hhd\n",
1165                          cmd->ftm_format_and_bw80M);
1166
1167         mutex_unlock(&mvm->mutex);
1168         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1169 }
1170
1171 static ssize_t iwl_dbgfs_tof_range_abort_write(struct ieee80211_vif *vif,
1172                                                char *buf,
1173                                                size_t count, loff_t *ppos)
1174 {
1175         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1176         struct iwl_mvm *mvm = mvmvif->mvm;
1177         u32 value;
1178         int abort_id, ret = 0;
1179         char *data;
1180
1181         mutex_lock(&mvm->mutex);
1182
1183         data = iwl_dbgfs_is_match("abort_id=", buf);
1184         if (data) {
1185                 ret = kstrtou32(data, 10, &value);
1186                 if (ret == 0)
1187                         mvm->tof_data.last_abort_id = value;
1188                 goto out;
1189         }
1190
1191         data = iwl_dbgfs_is_match("send_range_abort=", buf);
1192         if (data) {
1193                 ret = kstrtou32(data, 10, &value);
1194                 if (ret == 0 && value) {
1195                         abort_id = mvm->tof_data.last_abort_id;
1196                         ret = iwl_mvm_tof_range_abort_cmd(mvm, abort_id);
1197                         goto out;
1198                 }
1199         }
1200
1201 out:
1202         mutex_unlock(&mvm->mutex);
1203         return ret ?: count;
1204 }
1205
1206 static ssize_t iwl_dbgfs_tof_range_abort_read(struct file *file,
1207                                               char __user *user_buf,
1208                                               size_t count, loff_t *ppos)
1209 {
1210         struct ieee80211_vif *vif = file->private_data;
1211         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1212         struct iwl_mvm *mvm = mvmvif->mvm;
1213         char buf[32];
1214         int pos = 0;
1215         const size_t bufsz = sizeof(buf);
1216         int last_abort_id;
1217
1218         mutex_lock(&mvm->mutex);
1219         last_abort_id = mvm->tof_data.last_abort_id;
1220         mutex_unlock(&mvm->mutex);
1221
1222         pos += scnprintf(buf + pos, bufsz - pos, "last_abort_id = %d\n",
1223                          last_abort_id);
1224         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1225 }
1226
1227 static ssize_t iwl_dbgfs_tof_range_response_read(struct file *file,
1228                                                  char __user *user_buf,
1229                                                  size_t count, loff_t *ppos)
1230 {
1231         struct ieee80211_vif *vif = file->private_data;
1232         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1233         struct iwl_mvm *mvm = mvmvif->mvm;
1234         char *buf;
1235         int pos = 0;
1236         const size_t bufsz = sizeof(struct iwl_tof_range_rsp_ntfy) + 256;
1237         struct iwl_tof_range_rsp_ntfy *cmd;
1238         int i, ret;
1239
1240         buf = kzalloc(bufsz, GFP_KERNEL);
1241         if (!buf)
1242                 return -ENOMEM;
1243
1244         mutex_lock(&mvm->mutex);
1245         cmd = &mvm->tof_data.range_resp;
1246
1247         pos += scnprintf(buf + pos, bufsz - pos, "request_id = %d\n",
1248                          cmd->request_id);
1249         pos += scnprintf(buf + pos, bufsz - pos, "status = %d\n",
1250                          cmd->request_status);
1251         pos += scnprintf(buf + pos, bufsz - pos, "last_in_batch = %d\n",
1252                          cmd->last_in_batch);
1253         pos += scnprintf(buf + pos, bufsz - pos, "num_of_aps = %d\n",
1254                          cmd->num_of_aps);
1255         for (i = 0; i < cmd->num_of_aps; i++) {
1256                 struct iwl_tof_range_rsp_ap_entry_ntfy *ap = &cmd->ap[i];
1257
1258                 pos += scnprintf(buf + pos, bufsz - pos,
1259                                 "ap %.2d: bssid=%pM status=%hhd bw=%hhd"
1260                                 " rtt=%d rtt_var=%d rtt_spread=%d"
1261                                 " rssi=%hhd  rssi_spread=%hhd"
1262                                 " range=%d range_var=%d"
1263                                 " time_stamp=%d\n",
1264                                 i, ap->bssid, ap->measure_status,
1265                                 ap->measure_bw,
1266                                 ap->rtt, ap->rtt_variance, ap->rtt_spread,
1267                                 ap->rssi, ap->rssi_spread, ap->range,
1268                                 ap->range_variance, ap->timestamp);
1269         }
1270         mutex_unlock(&mvm->mutex);
1271
1272         ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1273         kfree(buf);
1274         return ret;
1275 }
1276
1277 static ssize_t iwl_dbgfs_low_latency_write(struct ieee80211_vif *vif, char *buf,
1278                                            size_t count, loff_t *ppos)
1279 {
1280         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1281         struct iwl_mvm *mvm = mvmvif->mvm;
1282         bool prev;
1283         u8 value;
1284         int ret;
1285
1286         ret = kstrtou8(buf, 0, &value);
1287         if (ret)
1288                 return ret;
1289         if (value > 1)
1290                 return -EINVAL;
1291
1292         mutex_lock(&mvm->mutex);
1293         prev = iwl_mvm_vif_low_latency(mvmvif);
1294         mvmvif->low_latency_dbgfs = value;
1295         iwl_mvm_update_low_latency(mvm, vif, prev);
1296         mutex_unlock(&mvm->mutex);
1297
1298         return count;
1299 }
1300
1301 static ssize_t iwl_dbgfs_low_latency_read(struct file *file,
1302                                           char __user *user_buf,
1303                                           size_t count, loff_t *ppos)
1304 {
1305         struct ieee80211_vif *vif = file->private_data;
1306         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1307         char buf[30] = {};
1308         int len;
1309
1310         len = scnprintf(buf, sizeof(buf) - 1,
1311                         "traffic=%d\ndbgfs=%d\nvcmd=%d\n",
1312                         mvmvif->low_latency_traffic,
1313                         mvmvif->low_latency_dbgfs,
1314                         mvmvif->low_latency_vcmd);
1315         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1316 }
1317
1318 static ssize_t iwl_dbgfs_uapsd_misbehaving_read(struct file *file,
1319                                                 char __user *user_buf,
1320                                                 size_t count, loff_t *ppos)
1321 {
1322         struct ieee80211_vif *vif = file->private_data;
1323         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1324         char buf[20];
1325         int len;
1326
1327         len = sprintf(buf, "%pM\n", mvmvif->uapsd_misbehaving_bssid);
1328         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1329 }
1330
1331 static ssize_t iwl_dbgfs_uapsd_misbehaving_write(struct ieee80211_vif *vif,
1332                                                  char *buf, size_t count,
1333                                                  loff_t *ppos)
1334 {
1335         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1336         struct iwl_mvm *mvm = mvmvif->mvm;
1337         bool ret;
1338
1339         mutex_lock(&mvm->mutex);
1340         ret = mac_pton(buf, mvmvif->uapsd_misbehaving_bssid);
1341         mutex_unlock(&mvm->mutex);
1342
1343         return ret ? count : -EINVAL;
1344 }
1345
1346 static ssize_t iwl_dbgfs_rx_phyinfo_write(struct ieee80211_vif *vif, char *buf,
1347                                           size_t count, loff_t *ppos)
1348 {
1349         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1350         struct iwl_mvm *mvm = mvmvif->mvm;
1351         struct ieee80211_chanctx_conf *chanctx_conf;
1352         struct iwl_mvm_phy_ctxt *phy_ctxt;
1353         u16 value;
1354         int ret;
1355
1356         ret = kstrtou16(buf, 0, &value);
1357         if (ret)
1358                 return ret;
1359
1360         mutex_lock(&mvm->mutex);
1361         rcu_read_lock();
1362
1363         chanctx_conf = rcu_dereference(vif->chanctx_conf);
1364         /* make sure the channel context is assigned */
1365         if (!chanctx_conf) {
1366                 rcu_read_unlock();
1367                 mutex_unlock(&mvm->mutex);
1368                 return -EINVAL;
1369         }
1370
1371         phy_ctxt = &mvm->phy_ctxts[*(u16 *)chanctx_conf->drv_priv];
1372         rcu_read_unlock();
1373
1374         mvm->dbgfs_rx_phyinfo = value;
1375
1376         ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chanctx_conf->min_def,
1377                                        chanctx_conf->rx_chains_static,
1378                                        chanctx_conf->rx_chains_dynamic);
1379         mutex_unlock(&mvm->mutex);
1380
1381         return ret ?: count;
1382 }
1383
1384 static ssize_t iwl_dbgfs_rx_phyinfo_read(struct file *file,
1385                                          char __user *user_buf,
1386                                          size_t count, loff_t *ppos)
1387 {
1388         struct ieee80211_vif *vif = file->private_data;
1389         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1390         char buf[8];
1391         int len;
1392
1393         len = scnprintf(buf, sizeof(buf), "0x%04x\n",
1394                         mvmvif->mvm->dbgfs_rx_phyinfo);
1395
1396         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1397 }
1398
1399 static void iwl_dbgfs_quota_check(void *data, u8 *mac,
1400                                   struct ieee80211_vif *vif)
1401 {
1402         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1403         int *ret = data;
1404
1405         if (mvmvif->dbgfs_quota_min)
1406                 *ret = -EINVAL;
1407 }
1408
1409 static ssize_t iwl_dbgfs_quota_min_write(struct ieee80211_vif *vif, char *buf,
1410                                          size_t count, loff_t *ppos)
1411 {
1412         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1413         struct iwl_mvm *mvm = mvmvif->mvm;
1414         u16 value;
1415         int ret;
1416
1417         ret = kstrtou16(buf, 0, &value);
1418         if (ret)
1419                 return ret;
1420
1421         if (value > 95)
1422                 return -EINVAL;
1423
1424         mutex_lock(&mvm->mutex);
1425
1426         mvmvif->dbgfs_quota_min = 0;
1427         ieee80211_iterate_interfaces(mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1428                                      iwl_dbgfs_quota_check, &ret);
1429         if (ret == 0) {
1430                 mvmvif->dbgfs_quota_min = value;
1431                 iwl_mvm_update_quotas(mvm, false, NULL);
1432         }
1433         mutex_unlock(&mvm->mutex);
1434
1435         return ret ?: count;
1436 }
1437
1438 static ssize_t iwl_dbgfs_quota_min_read(struct file *file,
1439                                         char __user *user_buf,
1440                                         size_t count, loff_t *ppos)
1441 {
1442         struct ieee80211_vif *vif = file->private_data;
1443         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1444         char buf[10];
1445         int len;
1446
1447         len = scnprintf(buf, sizeof(buf), "%d\n", mvmvif->dbgfs_quota_min);
1448
1449         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1450 }
1451
1452 static const char * const chanwidths[] = {
1453         [NL80211_CHAN_WIDTH_20_NOHT] = "noht",
1454         [NL80211_CHAN_WIDTH_20] = "ht20",
1455         [NL80211_CHAN_WIDTH_40] = "ht40",
1456         [NL80211_CHAN_WIDTH_80] = "vht80",
1457         [NL80211_CHAN_WIDTH_80P80] = "vht80p80",
1458         [NL80211_CHAN_WIDTH_160] = "vht160",
1459 };
1460
1461 static bool iwl_mvm_lqm_notif_wait(struct iwl_notif_wait_data *notif_wait,
1462                                    struct iwl_rx_packet *pkt, void *data)
1463 {
1464         struct ieee80211_vif *vif = data;
1465         struct iwl_mvm *mvm =
1466                 container_of(notif_wait, struct iwl_mvm, notif_wait);
1467         struct iwl_link_qual_msrmnt_notif *report = (void *)pkt->data;
1468         u32 num_of_stations = le32_to_cpu(report->number_of_stations);
1469         int i;
1470
1471         IWL_INFO(mvm, "LQM report:\n");
1472         IWL_INFO(mvm, "\tstatus: %d\n", report->status);
1473         IWL_INFO(mvm, "\tmacID: %d\n", le32_to_cpu(report->mac_id));
1474         IWL_INFO(mvm, "\ttx_frame_dropped: %d\n",
1475                  le32_to_cpu(report->tx_frame_dropped));
1476         IWL_INFO(mvm, "\ttime_in_measurement_window: %d us\n",
1477                  le32_to_cpu(report->time_in_measurement_window));
1478         IWL_INFO(mvm, "\ttotal_air_time_other_stations: %d\n",
1479                  le32_to_cpu(report->total_air_time_other_stations));
1480         IWL_INFO(mvm, "\tchannel_freq: %d\n",
1481                  vif->bss_conf.chandef.center_freq1);
1482         IWL_INFO(mvm, "\tchannel_width: %s\n",
1483                  chanwidths[vif->bss_conf.chandef.width]);
1484         IWL_INFO(mvm, "\tnumber_of_stations: %d\n", num_of_stations);
1485         for (i = 0; i < num_of_stations; i++)
1486                 IWL_INFO(mvm, "\t\tsta[%d]: %d\n", i,
1487                          report->frequent_stations_air_time[i]);
1488
1489         return true;
1490 }
1491
1492 static ssize_t iwl_dbgfs_lqm_send_cmd_write(struct ieee80211_vif *vif,
1493                                             char *buf, size_t count,
1494                                             loff_t *ppos)
1495 {
1496         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1497         struct iwl_mvm *mvm = mvmvif->mvm;
1498         struct iwl_notification_wait wait_lqm_notif;
1499         static u16 lqm_notif[] = {
1500                 WIDE_ID(MAC_CONF_GROUP,
1501                         LINK_QUALITY_MEASUREMENT_COMPLETE_NOTIF)
1502         };
1503         int err;
1504         u32 duration;
1505         u32 timeout;
1506
1507         if (sscanf(buf, "%d,%d", &duration, &timeout) != 2)
1508                 return -EINVAL;
1509
1510         iwl_init_notification_wait(&mvm->notif_wait, &wait_lqm_notif,
1511                                    lqm_notif, ARRAY_SIZE(lqm_notif),
1512                                    iwl_mvm_lqm_notif_wait, vif);
1513         mutex_lock(&mvm->mutex);
1514         err = iwl_mvm_send_lqm_cmd(vif, LQM_CMD_OPERATION_START_MEASUREMENT,
1515                                    duration, timeout);
1516         mutex_unlock(&mvm->mutex);
1517
1518         if (err) {
1519                 IWL_ERR(mvm, "Failed to send lqm cmdf(err=%d)\n", err);
1520                 iwl_remove_notification(&mvm->notif_wait, &wait_lqm_notif);
1521                 return err;
1522         }
1523
1524         /* wait for 2 * timeout (safety guard) and convert to jiffies*/
1525         timeout = msecs_to_jiffies((timeout * 2) / 1000);
1526
1527         err = iwl_wait_notification(&mvm->notif_wait, &wait_lqm_notif,
1528                                     timeout);
1529         if (err)
1530                 IWL_ERR(mvm, "Getting lqm notif timed out\n");
1531
1532         return count;
1533 }
1534
1535 #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
1536         _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
1537 #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
1538         _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
1539 #define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do {               \
1540                 if (!debugfs_create_file(#name, mode, parent, vif,      \
1541                                          &iwl_dbgfs_##name##_ops))      \
1542                         goto err;                                       \
1543         } while (0)
1544
1545 MVM_DEBUGFS_READ_FILE_OPS(mac_params);
1546 MVM_DEBUGFS_READ_FILE_OPS(tx_pwr_lmt);
1547 MVM_DEBUGFS_READ_WRITE_FILE_OPS(pm_params, 32);
1548 MVM_DEBUGFS_READ_WRITE_FILE_OPS(bf_params, 256);
1549 MVM_DEBUGFS_READ_WRITE_FILE_OPS(low_latency, 10);
1550 MVM_DEBUGFS_READ_WRITE_FILE_OPS(uapsd_misbehaving, 20);
1551 MVM_DEBUGFS_READ_WRITE_FILE_OPS(rx_phyinfo, 10);
1552 MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_enable, 32);
1553 MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_request, 512);
1554 MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_req_ext, 32);
1555 MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_abort, 32);
1556 MVM_DEBUGFS_READ_FILE_OPS(tof_range_response);
1557 MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_responder_params, 32);
1558 MVM_DEBUGFS_READ_WRITE_FILE_OPS(quota_min, 32);
1559 MVM_DEBUGFS_WRITE_FILE_OPS(lqm_send_cmd, 64);
1560 MVM_DEBUGFS_READ_FILE_OPS(os_device_timediff);
1561
1562
1563 void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1564 {
1565         struct dentry *dbgfs_dir = vif->debugfs_dir;
1566         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1567         char buf[100];
1568
1569         /*
1570          * Check if debugfs directory already exist before creating it.
1571          * This may happen when, for example, resetting hw or suspend-resume
1572          */
1573         if (!dbgfs_dir || mvmvif->dbgfs_dir)
1574                 return;
1575
1576         mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir);
1577
1578         if (!mvmvif->dbgfs_dir) {
1579                 IWL_ERR(mvm, "Failed to create debugfs directory under %pd\n",
1580                         dbgfs_dir);
1581                 return;
1582         }
1583
1584         if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM &&
1585             ((vif->type == NL80211_IFTYPE_STATION && !vif->p2p) ||
1586              (vif->type == NL80211_IFTYPE_STATION && vif->p2p)))
1587                 MVM_DEBUGFS_ADD_FILE_VIF(pm_params, mvmvif->dbgfs_dir, S_IWUSR |
1588                                          S_IRUSR);
1589
1590         MVM_DEBUGFS_ADD_FILE_VIF(tx_pwr_lmt, mvmvif->dbgfs_dir, S_IRUSR);
1591         MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir, S_IRUSR);
1592         MVM_DEBUGFS_ADD_FILE_VIF(low_latency, mvmvif->dbgfs_dir,
1593                                  S_IRUSR | S_IWUSR);
1594         MVM_DEBUGFS_ADD_FILE_VIF(uapsd_misbehaving, mvmvif->dbgfs_dir,
1595                                  S_IRUSR | S_IWUSR);
1596         MVM_DEBUGFS_ADD_FILE_VIF(rx_phyinfo, mvmvif->dbgfs_dir,
1597                                  S_IRUSR | S_IWUSR);
1598         MVM_DEBUGFS_ADD_FILE_VIF(quota_min, mvmvif->dbgfs_dir,
1599                                  S_IRUSR | S_IWUSR);
1600         MVM_DEBUGFS_ADD_FILE_VIF(lqm_send_cmd, mvmvif->dbgfs_dir, S_IWUSR);
1601         MVM_DEBUGFS_ADD_FILE_VIF(os_device_timediff,
1602                                  mvmvif->dbgfs_dir, S_IRUSR);
1603
1604         if (vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
1605             mvmvif == mvm->bf_allowed_vif)
1606                 MVM_DEBUGFS_ADD_FILE_VIF(bf_params, mvmvif->dbgfs_dir,
1607                                          S_IRUSR | S_IWUSR);
1608
1609         if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TOF_SUPPORT) &&
1610             !vif->p2p && (vif->type != NL80211_IFTYPE_P2P_DEVICE)) {
1611                 if (IWL_MVM_TOF_IS_RESPONDER && vif->type == NL80211_IFTYPE_AP)
1612                         MVM_DEBUGFS_ADD_FILE_VIF(tof_responder_params,
1613                                                  mvmvif->dbgfs_dir,
1614                                                  S_IRUSR | S_IWUSR);
1615
1616                 MVM_DEBUGFS_ADD_FILE_VIF(tof_range_request, mvmvif->dbgfs_dir,
1617                                          S_IRUSR | S_IWUSR);
1618                 MVM_DEBUGFS_ADD_FILE_VIF(tof_range_req_ext, mvmvif->dbgfs_dir,
1619                                          S_IRUSR | S_IWUSR);
1620                 MVM_DEBUGFS_ADD_FILE_VIF(tof_enable, mvmvif->dbgfs_dir,
1621                                          S_IRUSR | S_IWUSR);
1622                 MVM_DEBUGFS_ADD_FILE_VIF(tof_range_abort, mvmvif->dbgfs_dir,
1623                                          S_IRUSR | S_IWUSR);
1624                 MVM_DEBUGFS_ADD_FILE_VIF(tof_range_response, mvmvif->dbgfs_dir,
1625                                          S_IRUSR);
1626         }
1627
1628         /*
1629          * Create symlink for convenience pointing to interface specific
1630          * debugfs entries for the driver. For example, under
1631          * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/
1632          * find
1633          * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/
1634          */
1635         snprintf(buf, 100, "../../../%pd3/%pd",
1636                  dbgfs_dir,
1637                  mvmvif->dbgfs_dir);
1638
1639         mvmvif->dbgfs_slink = debugfs_create_symlink(dbgfs_dir->d_name.name,
1640                                                      mvm->debugfs_dir, buf);
1641         if (!mvmvif->dbgfs_slink)
1642                 IWL_ERR(mvm, "Can't create debugfs symbolic link under %pd\n",
1643                         dbgfs_dir);
1644         return;
1645 err:
1646         IWL_ERR(mvm, "Can't create debugfs entity\n");
1647 }
1648
1649 void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1650 {
1651         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1652
1653         debugfs_remove(mvmvif->dbgfs_slink);
1654         mvmvif->dbgfs_slink = NULL;
1655
1656         debugfs_remove_recursive(mvmvif->dbgfs_dir);
1657         mvmvif->dbgfs_dir = NULL;
1658 }