iwlwifi: mvm: fix fw_rx_stats debugfs entry
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / mvm / debugfs.c
CommitLineData
8ca151b5
JB
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
410dc5aa 25 * in the file called COPYING.
8ca151b5
JB
26 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63#include "mvm.h"
64#include "sta.h"
65#include "iwl-io.h"
66
67struct iwl_dbgfs_mvm_ctx {
68 struct iwl_mvm *mvm;
69 struct ieee80211_vif *vif;
70};
71
8ca151b5
JB
72static ssize_t iwl_dbgfs_tx_flush_write(struct file *file,
73 const char __user *user_buf,
74 size_t count, loff_t *ppos)
75{
76 struct iwl_mvm *mvm = file->private_data;
77
78 char buf[16];
79 int buf_size, ret;
80 u32 scd_q_msk;
81
82 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
83 return -EIO;
84
85 memset(buf, 0, sizeof(buf));
86 buf_size = min(count, sizeof(buf) - 1);
87 if (copy_from_user(buf, user_buf, buf_size))
88 return -EFAULT;
89
90 if (sscanf(buf, "%x", &scd_q_msk) != 1)
91 return -EINVAL;
92
93 IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk);
94
95 mutex_lock(&mvm->mutex);
96 ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, true) ? : count;
97 mutex_unlock(&mvm->mutex);
98
99 return ret;
100}
101
102static ssize_t iwl_dbgfs_sta_drain_write(struct file *file,
103 const char __user *user_buf,
104 size_t count, loff_t *ppos)
105{
106 struct iwl_mvm *mvm = file->private_data;
107 struct ieee80211_sta *sta;
108
109 char buf[8];
110 int buf_size, sta_id, drain, ret;
111
112 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
113 return -EIO;
114
115 memset(buf, 0, sizeof(buf));
116 buf_size = min(count, sizeof(buf) - 1);
117 if (copy_from_user(buf, user_buf, buf_size))
118 return -EFAULT;
119
120 if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
121 return -EINVAL;
122
123 mutex_lock(&mvm->mutex);
124
125 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
126 lockdep_is_held(&mvm->mutex));
127 if (IS_ERR_OR_NULL(sta))
128 ret = -ENOENT;
129 else
130 ret = iwl_mvm_drain_sta(mvm, (void *)sta->drv_priv, drain) ? :
131 count;
132
133 mutex_unlock(&mvm->mutex);
134
135 return ret;
136}
137
138static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
139 size_t count, loff_t *ppos)
140{
141 struct iwl_mvm *mvm = file->private_data;
142 const struct fw_img *img;
143 int ofs, len, pos = 0;
144 size_t bufsz, ret;
145 char *buf;
146 u8 *ptr;
147
60191d99
JB
148 if (!mvm->ucode_loaded)
149 return -EINVAL;
150
8ca151b5
JB
151 /* default is to dump the entire data segment */
152 if (!mvm->dbgfs_sram_offset && !mvm->dbgfs_sram_len) {
8ca151b5 153 img = &mvm->fw->img[mvm->cur_ucode];
60191d99
JB
154 ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
155 len = img->sec[IWL_UCODE_SECTION_DATA].len;
156 } else {
157 ofs = mvm->dbgfs_sram_offset;
158 len = mvm->dbgfs_sram_len;
8ca151b5 159 }
8ca151b5
JB
160
161 bufsz = len * 4 + 256;
162 buf = kzalloc(bufsz, GFP_KERNEL);
163 if (!buf)
164 return -ENOMEM;
165
166 ptr = kzalloc(len, GFP_KERNEL);
167 if (!ptr) {
168 kfree(buf);
169 return -ENOMEM;
170 }
171
172 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n", len);
60191d99 173 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n", ofs);
8ca151b5 174
60191d99 175 iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
8ca151b5
JB
176 for (ofs = 0; ofs < len; ofs += 16) {
177 pos += scnprintf(buf + pos, bufsz - pos, "0x%.4x ", ofs);
178 hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
179 bufsz - pos, false);
180 pos += strlen(buf + pos);
181 if (bufsz - pos > 0)
182 buf[pos++] = '\n';
183 }
184
185 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
186
187 kfree(buf);
188 kfree(ptr);
189
190 return ret;
191}
192
193static ssize_t iwl_dbgfs_sram_write(struct file *file,
194 const char __user *user_buf, size_t count,
195 loff_t *ppos)
196{
197 struct iwl_mvm *mvm = file->private_data;
198 char buf[64];
199 int buf_size;
200 u32 offset, len;
201
202 memset(buf, 0, sizeof(buf));
203 buf_size = min(count, sizeof(buf) - 1);
204 if (copy_from_user(buf, user_buf, buf_size))
205 return -EFAULT;
206
207 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
208 if ((offset & 0x3) || (len & 0x3))
209 return -EINVAL;
210 mvm->dbgfs_sram_offset = offset;
211 mvm->dbgfs_sram_len = len;
212 } else {
213 mvm->dbgfs_sram_offset = 0;
214 mvm->dbgfs_sram_len = 0;
215 }
216
217 return count;
218}
219
220static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
221 size_t count, loff_t *ppos)
222{
223 struct iwl_mvm *mvm = file->private_data;
224 struct ieee80211_sta *sta;
225 char buf[400];
226 int i, pos = 0, bufsz = sizeof(buf);
227
228 mutex_lock(&mvm->mutex);
229
230 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
231 pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
232 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
233 lockdep_is_held(&mvm->mutex));
234 if (!sta)
235 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
236 else if (IS_ERR(sta))
237 pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
238 PTR_ERR(sta));
239 else
240 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
241 sta->addr);
242 }
243
244 mutex_unlock(&mvm->mutex);
245
246 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
247}
248
64b928c4
AB
249static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
250 char __user *user_buf,
8ca151b5
JB
251 size_t count, loff_t *ppos)
252{
253 struct iwl_mvm *mvm = file->private_data;
64b928c4
AB
254 char buf[64];
255 int bufsz = sizeof(buf);
256 int pos = 0;
8ca151b5 257
64b928c4
AB
258 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
259 mvm->disable_power_off);
260 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
261 mvm->disable_power_off_d3);
8ca151b5 262
64b928c4 263 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
8ca151b5
JB
264}
265
64b928c4
AB
266static ssize_t iwl_dbgfs_disable_power_off_write(struct file *file,
267 const char __user *user_buf,
268 size_t count, loff_t *ppos)
8ca151b5
JB
269{
270 struct iwl_mvm *mvm = file->private_data;
64b928c4
AB
271 char buf[64] = {};
272 int ret;
273 int val;
274
275 if (!mvm->ucode_loaded)
276 return -EIO;
8ca151b5 277
0e9d84ea
DH
278 count = min_t(size_t, count, sizeof(buf) - 1);
279 if (copy_from_user(buf, user_buf, count))
8ca151b5
JB
280 return -EFAULT;
281
64b928c4
AB
282 if (!strncmp("disable_power_off_d0=", buf, 21)) {
283 if (sscanf(buf + 21, "%d", &val) != 1)
284 return -EINVAL;
285 mvm->disable_power_off = val;
286 } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
287 if (sscanf(buf + 21, "%d", &val) != 1)
288 return -EINVAL;
289 mvm->disable_power_off_d3 = val;
290 } else {
8ca151b5 291 return -EINVAL;
64b928c4 292 }
8ca151b5 293
64b928c4
AB
294 mutex_lock(&mvm->mutex);
295 ret = iwl_mvm_power_update_device_mode(mvm);
296 mutex_unlock(&mvm->mutex);
8ca151b5 297
64b928c4 298 return ret ?: count;
8ca151b5
JB
299}
300
b571a697
AB
301static void iwl_dbgfs_update_pm(struct iwl_mvm *mvm,
302 struct ieee80211_vif *vif,
303 enum iwl_dbgfs_pm_mask param, int val)
304{
305 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
306 struct iwl_dbgfs_pm *dbgfs_pm = &mvmvif->dbgfs_pm;
307
308 dbgfs_pm->mask |= param;
309
310 switch (param) {
311 case MVM_DEBUGFS_PM_KEEP_ALIVE: {
312 struct ieee80211_hw *hw = mvm->hw;
313 int dtimper = hw->conf.ps_dtim_period ?: 1;
314 int dtimper_msec = dtimper * vif->bss_conf.beacon_int;
315
316 IWL_DEBUG_POWER(mvm, "debugfs: set keep_alive= %d sec\n", val);
317 if (val * MSEC_PER_SEC < 3 * dtimper_msec) {
318 IWL_WARN(mvm,
319 "debugfs: keep alive period (%ld msec) is less than minimum required (%d msec)\n",
320 val * MSEC_PER_SEC, 3 * dtimper_msec);
321 }
322 dbgfs_pm->keep_alive_seconds = val;
323 break;
324 }
325 case MVM_DEBUGFS_PM_SKIP_OVER_DTIM:
326 IWL_DEBUG_POWER(mvm, "skip_over_dtim %s\n",
327 val ? "enabled" : "disabled");
328 dbgfs_pm->skip_over_dtim = val;
329 break;
330 case MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS:
331 IWL_DEBUG_POWER(mvm, "skip_dtim_periods=%d\n", val);
332 dbgfs_pm->skip_dtim_periods = val;
333 break;
334 case MVM_DEBUGFS_PM_RX_DATA_TIMEOUT:
335 IWL_DEBUG_POWER(mvm, "rx_data_timeout=%d\n", val);
336 dbgfs_pm->rx_data_timeout = val;
337 break;
338 case MVM_DEBUGFS_PM_TX_DATA_TIMEOUT:
339 IWL_DEBUG_POWER(mvm, "tx_data_timeout=%d\n", val);
340 dbgfs_pm->tx_data_timeout = val;
341 break;
342 case MVM_DEBUGFS_PM_DISABLE_POWER_OFF:
343 IWL_DEBUG_POWER(mvm, "disable_power_off=%d\n", val);
344 dbgfs_pm->disable_power_off = val;
bd4ace2a
AB
345 case MVM_DEBUGFS_PM_LPRX_ENA:
346 IWL_DEBUG_POWER(mvm, "lprx %s\n", val ? "enabled" : "disabled");
347 dbgfs_pm->lprx_ena = val;
348 break;
349 case MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD:
350 IWL_DEBUG_POWER(mvm, "lprx_rssi_threshold=%d\n", val);
351 dbgfs_pm->lprx_rssi_threshold = val;
b571a697 352 break;
89716344
AB
353 case MVM_DEBUGFS_PM_SNOOZE_ENABLE:
354 IWL_DEBUG_POWER(mvm, "snooze_enable=%d\n", val);
355 dbgfs_pm->snooze_ena = val;
356 break;
b571a697
AB
357 }
358}
359
360static ssize_t iwl_dbgfs_pm_params_write(struct file *file,
361 const char __user *user_buf,
362 size_t count, loff_t *ppos)
363{
364 struct ieee80211_vif *vif = file->private_data;
365 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
366 struct iwl_mvm *mvm = mvmvif->dbgfs_data;
367 enum iwl_dbgfs_pm_mask param;
368 char buf[32] = {};
369 int val;
370 int ret;
371
0e9d84ea
DH
372 count = min_t(size_t, count, sizeof(buf) - 1);
373 if (copy_from_user(buf, user_buf, count))
b571a697
AB
374 return -EFAULT;
375
376 if (!strncmp("keep_alive=", buf, 11)) {
377 if (sscanf(buf + 11, "%d", &val) != 1)
378 return -EINVAL;
379 param = MVM_DEBUGFS_PM_KEEP_ALIVE;
380 } else if (!strncmp("skip_over_dtim=", buf, 15)) {
381 if (sscanf(buf + 15, "%d", &val) != 1)
382 return -EINVAL;
383 param = MVM_DEBUGFS_PM_SKIP_OVER_DTIM;
384 } else if (!strncmp("skip_dtim_periods=", buf, 18)) {
385 if (sscanf(buf + 18, "%d", &val) != 1)
386 return -EINVAL;
387 param = MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS;
388 } else if (!strncmp("rx_data_timeout=", buf, 16)) {
389 if (sscanf(buf + 16, "%d", &val) != 1)
390 return -EINVAL;
391 param = MVM_DEBUGFS_PM_RX_DATA_TIMEOUT;
392 } else if (!strncmp("tx_data_timeout=", buf, 16)) {
393 if (sscanf(buf + 16, "%d", &val) != 1)
394 return -EINVAL;
395 param = MVM_DEBUGFS_PM_TX_DATA_TIMEOUT;
64b928c4
AB
396 } else if (!strncmp("disable_power_off=", buf, 18) &&
397 !(mvm->fw->ucode_capa.flags &
398 IWL_UCODE_TLV_FLAGS_DEVICE_PS_CMD)) {
b571a697
AB
399 if (sscanf(buf + 18, "%d", &val) != 1)
400 return -EINVAL;
401 param = MVM_DEBUGFS_PM_DISABLE_POWER_OFF;
bd4ace2a
AB
402 } else if (!strncmp("lprx=", buf, 5)) {
403 if (sscanf(buf + 5, "%d", &val) != 1)
404 return -EINVAL;
405 param = MVM_DEBUGFS_PM_LPRX_ENA;
406 } else if (!strncmp("lprx_rssi_threshold=", buf, 20)) {
407 if (sscanf(buf + 20, "%d", &val) != 1)
408 return -EINVAL;
409 if (val > POWER_LPRX_RSSI_THRESHOLD_MAX || val <
410 POWER_LPRX_RSSI_THRESHOLD_MIN)
411 return -EINVAL;
412 param = MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD;
89716344
AB
413 } else if (!strncmp("snooze_enable=", buf, 14)) {
414 if (sscanf(buf + 14, "%d", &val) != 1)
415 return -EINVAL;
416 param = MVM_DEBUGFS_PM_SNOOZE_ENABLE;
b571a697
AB
417 } else {
418 return -EINVAL;
419 }
420
421 mutex_lock(&mvm->mutex);
422 iwl_dbgfs_update_pm(mvm, vif, param, val);
423 ret = iwl_mvm_power_update_mode(mvm, vif);
424 mutex_unlock(&mvm->mutex);
425
426 return ret ?: count;
427}
428
429static ssize_t iwl_dbgfs_pm_params_read(struct file *file,
430 char __user *user_buf,
431 size_t count, loff_t *ppos)
432{
433 struct ieee80211_vif *vif = file->private_data;
434 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
435 struct iwl_mvm *mvm = mvmvif->dbgfs_data;
e3c588ec 436 char buf[512];
b571a697 437 int bufsz = sizeof(buf);
e811ada7 438 int pos;
b571a697 439
e811ada7 440 pos = iwl_mvm_power_dbgfs_read(mvm, vif, buf, bufsz);
b571a697
AB
441
442 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
443}
444
63494374
JB
445static ssize_t iwl_dbgfs_mac_params_read(struct file *file,
446 char __user *user_buf,
447 size_t count, loff_t *ppos)
448{
449 struct ieee80211_vif *vif = file->private_data;
450 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
451 struct iwl_mvm *mvm = mvmvif->dbgfs_data;
452 u8 ap_sta_id;
453 struct ieee80211_chanctx_conf *chanctx_conf;
454 char buf[512];
455 int bufsz = sizeof(buf);
456 int pos = 0;
457 int i;
458
459 mutex_lock(&mvm->mutex);
460
461 ap_sta_id = mvmvif->ap_sta_id;
462
463 pos += scnprintf(buf+pos, bufsz-pos, "mac id/color: %d / %d\n",
464 mvmvif->id, mvmvif->color);
465 pos += scnprintf(buf+pos, bufsz-pos, "bssid: %pM\n",
466 vif->bss_conf.bssid);
467 pos += scnprintf(buf+pos, bufsz-pos, "QoS:\n");
468 for (i = 0; i < ARRAY_SIZE(mvmvif->queue_params); i++) {
469 pos += scnprintf(buf+pos, bufsz-pos,
470 "\t%d: txop:%d - cw_min:%d - cw_max = %d - aifs = %d upasd = %d\n",
471 i, mvmvif->queue_params[i].txop,
472 mvmvif->queue_params[i].cw_min,
473 mvmvif->queue_params[i].cw_max,
474 mvmvif->queue_params[i].aifs,
475 mvmvif->queue_params[i].uapsd);
476 }
477
2b76ef13
EG
478 if (vif->type == NL80211_IFTYPE_STATION &&
479 ap_sta_id != IWL_MVM_STATION_COUNT) {
480 struct ieee80211_sta *sta;
481 struct iwl_mvm_sta *mvm_sta;
482
483 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[ap_sta_id],
484 lockdep_is_held(&mvm->mutex));
485 mvm_sta = (void *)sta->drv_priv;
486 pos += scnprintf(buf+pos, bufsz-pos,
487 "ap_sta_id %d - reduced Tx power %d\n",
488 ap_sta_id, mvm_sta->bt_reduced_txpower);
489 }
63494374
JB
490
491 rcu_read_lock();
492 chanctx_conf = rcu_dereference(vif->chanctx_conf);
493 if (chanctx_conf) {
494 pos += scnprintf(buf+pos, bufsz-pos,
495 "idle rx chains %d, active rx chains: %d\n",
496 chanctx_conf->rx_chains_static,
497 chanctx_conf->rx_chains_dynamic);
498 }
499 rcu_read_unlock();
500
501 mutex_unlock(&mvm->mutex);
502
503 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
504}
505
10942342
EG
506#define BT_MBOX_MSG(_notif, _num, _field) \
507 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
508 >> BT_MBOX##_num##_##_field##_POS)
509
510
511#define BT_MBOX_PRINT(_num, _field, _end) \
512 pos += scnprintf(buf + pos, bufsz - pos, \
513 "\t%s: %d%s", \
514 #_field, \
515 BT_MBOX_MSG(notif, _num, _field), \
516 true ? "\n" : ", ");
517
518static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
519 size_t count, loff_t *ppos)
520{
521 struct iwl_mvm *mvm = file->private_data;
522 struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
523 char *buf;
524 int ret, pos = 0, bufsz = sizeof(char) * 1024;
525
526 buf = kmalloc(bufsz, GFP_KERNEL);
527 if (!buf)
528 return -ENOMEM;
529
530 mutex_lock(&mvm->mutex);
531
532 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
533
534 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
535 BT_MBOX_PRINT(0, LE_PROF1, false);
536 BT_MBOX_PRINT(0, LE_PROF2, false);
537 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
538 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
539 BT_MBOX_PRINT(0, INBAND_S, false);
540 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
541 BT_MBOX_PRINT(0, LE_SCAN, false);
542 BT_MBOX_PRINT(0, LE_ADV, false);
543 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
544 BT_MBOX_PRINT(0, OPEN_CON_1, true);
545
546 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
547
548 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
549 BT_MBOX_PRINT(1, IP_SR, false);
550 BT_MBOX_PRINT(1, LE_MSTR, false);
551 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
552 BT_MBOX_PRINT(1, MSG_TYPE, false);
553 BT_MBOX_PRINT(1, SSN, true);
554
555 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
556
557 BT_MBOX_PRINT(2, SNIFF_ACT, false);
558 BT_MBOX_PRINT(2, PAG, false);
559 BT_MBOX_PRINT(2, INQUIRY, false);
560 BT_MBOX_PRINT(2, CONN, false);
561 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
562 BT_MBOX_PRINT(2, DISC, false);
563 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
564 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
565 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
566 BT_MBOX_PRINT(2, SCO_DURATION, true);
567
568 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
569
570 BT_MBOX_PRINT(3, SCO_STATE, false);
571 BT_MBOX_PRINT(3, SNIFF_STATE, false);
572 BT_MBOX_PRINT(3, A2DP_STATE, false);
573 BT_MBOX_PRINT(3, ACL_STATE, false);
574 BT_MBOX_PRINT(3, MSTR_STATE, false);
575 BT_MBOX_PRINT(3, OBX_STATE, false);
576 BT_MBOX_PRINT(3, OPEN_CON_2, false);
577 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
578 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
579 BT_MBOX_PRINT(3, INBAND_P, false);
580 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
581 BT_MBOX_PRINT(3, SSN_2, false);
582 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
583
584 pos += scnprintf(buf+pos, bufsz-pos, "bt_status = %d\n",
2de13cae 585 notif->bt_status);
10942342 586 pos += scnprintf(buf+pos, bufsz-pos, "bt_open_conn = %d\n",
2de13cae 587 notif->bt_open_conn);
10942342 588 pos += scnprintf(buf+pos, bufsz-pos, "bt_traffic_load = %d\n",
2de13cae 589 notif->bt_traffic_load);
10942342 590 pos += scnprintf(buf+pos, bufsz-pos, "bt_agg_traffic_load = %d\n",
2de13cae 591 notif->bt_agg_traffic_load);
10942342 592 pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
2de13cae
EG
593 notif->bt_ci_compliance);
594 pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
595 le32_to_cpu(notif->primary_ch_lut));
596 pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
597 le32_to_cpu(notif->secondary_ch_lut));
598 pos += scnprintf(buf+pos, bufsz-pos, "bt_activity_grading = %d\n",
599 le32_to_cpu(notif->bt_activity_grading));
10942342
EG
600
601 mutex_unlock(&mvm->mutex);
602
603 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
604 kfree(buf);
605
606 return ret;
607}
608#undef BT_MBOX_PRINT
609
2de13cae
EG
610static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
611 size_t count, loff_t *ppos)
612{
613 struct iwl_mvm *mvm = file->private_data;
614 struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
615 char buf[256];
616 int bufsz = sizeof(buf);
617 int pos = 0;
618
619 mutex_lock(&mvm->mutex);
620
621 pos += scnprintf(buf+pos, bufsz-pos, "Channel inhibition CMD\n");
622 pos += scnprintf(buf+pos, bufsz-pos,
623 "\tPrimary Channel Bitmap 0x%016llx Fat: %d\n",
624 le64_to_cpu(cmd->bt_primary_ci),
625 !!cmd->co_run_bw_primary);
626 pos += scnprintf(buf+pos, bufsz-pos,
627 "\tSecondary Channel Bitmap 0x%016llx Fat: %d\n",
628 le64_to_cpu(cmd->bt_secondary_ci),
629 !!cmd->co_run_bw_secondary);
630
631 pos += scnprintf(buf+pos, bufsz-pos, "BT Configuration CMD\n");
632 pos += scnprintf(buf+pos, bufsz-pos, "\tACK Kill Mask 0x%08x\n",
633 iwl_bt_ack_kill_msk[mvm->bt_kill_msk]);
634 pos += scnprintf(buf+pos, bufsz-pos, "\tCTS Kill Mask 0x%08x\n",
635 iwl_bt_cts_kill_msk[mvm->bt_kill_msk]);
636
637 mutex_unlock(&mvm->mutex);
638
639 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
640}
641
3848ab66
MG
642#define PRINT_STATS_LE32(_str, _val) \
643 pos += scnprintf(buf + pos, bufsz - pos, \
644 fmt_table, _str, \
645 le32_to_cpu(_val))
646
647static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
648 char __user *user_buf, size_t count,
649 loff_t *ppos)
650{
651 struct iwl_mvm *mvm = file->private_data;
652 static const char *fmt_table = "\t%-30s %10u\n";
653 static const char *fmt_header = "%-32s\n";
654 int pos = 0;
655 char *buf;
656 int ret;
3f617281
LC
657 /* 43 is the size of each data line, 33 is the size of each header */
658 size_t bufsz =
659 ((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) +
660 (4 * 33) + 1;
661
3848ab66
MG
662 struct mvm_statistics_rx_phy *ofdm;
663 struct mvm_statistics_rx_phy *cck;
664 struct mvm_statistics_rx_non_phy *general;
665 struct mvm_statistics_rx_ht_phy *ht;
666
667 buf = kzalloc(bufsz, GFP_KERNEL);
668 if (!buf)
669 return -ENOMEM;
670
671 mutex_lock(&mvm->mutex);
672
673 ofdm = &mvm->rx_stats.ofdm;
674 cck = &mvm->rx_stats.cck;
675 general = &mvm->rx_stats.general;
676 ht = &mvm->rx_stats.ofdm_ht;
677
678 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
679 "Statistics_Rx - OFDM");
680 PRINT_STATS_LE32("ina_cnt", ofdm->ina_cnt);
681 PRINT_STATS_LE32("fina_cnt", ofdm->fina_cnt);
682 PRINT_STATS_LE32("plcp_err", ofdm->plcp_err);
683 PRINT_STATS_LE32("crc32_err", ofdm->crc32_err);
684 PRINT_STATS_LE32("overrun_err", ofdm->overrun_err);
685 PRINT_STATS_LE32("early_overrun_err", ofdm->early_overrun_err);
686 PRINT_STATS_LE32("crc32_good", ofdm->crc32_good);
687 PRINT_STATS_LE32("false_alarm_cnt", ofdm->false_alarm_cnt);
688 PRINT_STATS_LE32("fina_sync_err_cnt", ofdm->fina_sync_err_cnt);
689 PRINT_STATS_LE32("sfd_timeout", ofdm->sfd_timeout);
690 PRINT_STATS_LE32("fina_timeout", ofdm->fina_timeout);
691 PRINT_STATS_LE32("unresponded_rts", ofdm->unresponded_rts);
692 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
693 ofdm->rxe_frame_limit_overrun);
694 PRINT_STATS_LE32("sent_ack_cnt", ofdm->sent_ack_cnt);
695 PRINT_STATS_LE32("sent_cts_cnt", ofdm->sent_cts_cnt);
696 PRINT_STATS_LE32("sent_ba_rsp_cnt", ofdm->sent_ba_rsp_cnt);
697 PRINT_STATS_LE32("dsp_self_kill", ofdm->dsp_self_kill);
698 PRINT_STATS_LE32("mh_format_err", ofdm->mh_format_err);
699 PRINT_STATS_LE32("re_acq_main_rssi_sum", ofdm->re_acq_main_rssi_sum);
700 PRINT_STATS_LE32("reserved", ofdm->reserved);
701
702 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
703 "Statistics_Rx - CCK");
704 PRINT_STATS_LE32("ina_cnt", cck->ina_cnt);
705 PRINT_STATS_LE32("fina_cnt", cck->fina_cnt);
706 PRINT_STATS_LE32("plcp_err", cck->plcp_err);
707 PRINT_STATS_LE32("crc32_err", cck->crc32_err);
708 PRINT_STATS_LE32("overrun_err", cck->overrun_err);
709 PRINT_STATS_LE32("early_overrun_err", cck->early_overrun_err);
710 PRINT_STATS_LE32("crc32_good", cck->crc32_good);
711 PRINT_STATS_LE32("false_alarm_cnt", cck->false_alarm_cnt);
712 PRINT_STATS_LE32("fina_sync_err_cnt", cck->fina_sync_err_cnt);
713 PRINT_STATS_LE32("sfd_timeout", cck->sfd_timeout);
714 PRINT_STATS_LE32("fina_timeout", cck->fina_timeout);
715 PRINT_STATS_LE32("unresponded_rts", cck->unresponded_rts);
716 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
717 cck->rxe_frame_limit_overrun);
718 PRINT_STATS_LE32("sent_ack_cnt", cck->sent_ack_cnt);
719 PRINT_STATS_LE32("sent_cts_cnt", cck->sent_cts_cnt);
720 PRINT_STATS_LE32("sent_ba_rsp_cnt", cck->sent_ba_rsp_cnt);
721 PRINT_STATS_LE32("dsp_self_kill", cck->dsp_self_kill);
722 PRINT_STATS_LE32("mh_format_err", cck->mh_format_err);
723 PRINT_STATS_LE32("re_acq_main_rssi_sum", cck->re_acq_main_rssi_sum);
724 PRINT_STATS_LE32("reserved", cck->reserved);
725
726 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
727 "Statistics_Rx - GENERAL");
728 PRINT_STATS_LE32("bogus_cts", general->bogus_cts);
729 PRINT_STATS_LE32("bogus_ack", general->bogus_ack);
730 PRINT_STATS_LE32("non_bssid_frames", general->non_bssid_frames);
731 PRINT_STATS_LE32("filtered_frames", general->filtered_frames);
732 PRINT_STATS_LE32("non_channel_beacons", general->non_channel_beacons);
733 PRINT_STATS_LE32("channel_beacons", general->channel_beacons);
734 PRINT_STATS_LE32("num_missed_bcon", general->num_missed_bcon);
735 PRINT_STATS_LE32("adc_rx_saturation_time",
736 general->adc_rx_saturation_time);
737 PRINT_STATS_LE32("ina_detection_search_time",
738 general->ina_detection_search_time);
739 PRINT_STATS_LE32("beacon_silence_rssi_a",
740 general->beacon_silence_rssi_a);
741 PRINT_STATS_LE32("beacon_silence_rssi_b",
742 general->beacon_silence_rssi_b);
743 PRINT_STATS_LE32("beacon_silence_rssi_c",
744 general->beacon_silence_rssi_c);
745 PRINT_STATS_LE32("interference_data_flag",
746 general->interference_data_flag);
747 PRINT_STATS_LE32("channel_load", general->channel_load);
748 PRINT_STATS_LE32("dsp_false_alarms", general->dsp_false_alarms);
749 PRINT_STATS_LE32("beacon_rssi_a", general->beacon_rssi_a);
750 PRINT_STATS_LE32("beacon_rssi_b", general->beacon_rssi_b);
751 PRINT_STATS_LE32("beacon_rssi_c", general->beacon_rssi_c);
752 PRINT_STATS_LE32("beacon_energy_a", general->beacon_energy_a);
753 PRINT_STATS_LE32("beacon_energy_b", general->beacon_energy_b);
754 PRINT_STATS_LE32("beacon_energy_c", general->beacon_energy_c);
755 PRINT_STATS_LE32("num_bt_kills", general->num_bt_kills);
3f617281 756 PRINT_STATS_LE32("mac_id", general->mac_id);
3848ab66
MG
757 PRINT_STATS_LE32("directed_data_mpdu", general->directed_data_mpdu);
758
759 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
760 "Statistics_Rx - HT");
761 PRINT_STATS_LE32("plcp_err", ht->plcp_err);
762 PRINT_STATS_LE32("overrun_err", ht->overrun_err);
763 PRINT_STATS_LE32("early_overrun_err", ht->early_overrun_err);
764 PRINT_STATS_LE32("crc32_good", ht->crc32_good);
765 PRINT_STATS_LE32("crc32_err", ht->crc32_err);
766 PRINT_STATS_LE32("mh_format_err", ht->mh_format_err);
767 PRINT_STATS_LE32("agg_crc32_good", ht->agg_crc32_good);
768 PRINT_STATS_LE32("agg_mpdu_cnt", ht->agg_mpdu_cnt);
769 PRINT_STATS_LE32("agg_cnt", ht->agg_cnt);
770 PRINT_STATS_LE32("unsupport_mcs", ht->unsupport_mcs);
771
772 mutex_unlock(&mvm->mutex);
773
774 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
775 kfree(buf);
776
777 return ret;
778}
779#undef PRINT_STAT_LE32
780
490953ac
EG
781static ssize_t iwl_dbgfs_fw_restart_write(struct file *file,
782 const char __user *user_buf,
783 size_t count, loff_t *ppos)
784{
785 struct iwl_mvm *mvm = file->private_data;
490953ac
EG
786 int ret;
787
490953ac
EG
788 mutex_lock(&mvm->mutex);
789
291aa7c4
EH
790 /* allow one more restart that we're provoking here */
791 if (mvm->restart_fw >= 0)
792 mvm->restart_fw++;
793
490953ac
EG
794 /* take the return value to make compiler happy - it will fail anyway */
795 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, CMD_SYNC, 0, NULL);
796
797 mutex_unlock(&mvm->mutex);
798
490953ac
EG
799 return count;
800}
801
91b05d10
OG
802static ssize_t
803iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
804 char __user *user_buf,
805 size_t count, loff_t *ppos)
806{
807 struct iwl_mvm *mvm = file->private_data;
808 int pos = 0;
809 char buf[32];
810 const size_t bufsz = sizeof(buf);
811
812 /* print which antennas were set for the scan command by the user */
813 pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
814 if (mvm->scan_rx_ant & ANT_A)
815 pos += scnprintf(buf + pos, bufsz - pos, "A");
816 if (mvm->scan_rx_ant & ANT_B)
817 pos += scnprintf(buf + pos, bufsz - pos, "B");
818 if (mvm->scan_rx_ant & ANT_C)
819 pos += scnprintf(buf + pos, bufsz - pos, "C");
820 pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
821
822 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
823}
824
825static ssize_t
826iwl_dbgfs_scan_ant_rxchain_write(struct file *file,
827 const char __user *user_buf,
828 size_t count, loff_t *ppos)
829{
830 struct iwl_mvm *mvm = file->private_data;
831 char buf[8];
832 int buf_size;
833 u8 scan_rx_ant;
834
835 memset(buf, 0, sizeof(buf));
836 buf_size = min(count, sizeof(buf) - 1);
837
838 /* get the argument from the user and check if it is valid */
839 if (copy_from_user(buf, user_buf, buf_size))
840 return -EFAULT;
841 if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
842 return -EINVAL;
843 if (scan_rx_ant > ANT_ABC)
844 return -EINVAL;
845 if (scan_rx_ant & ~iwl_fw_valid_rx_ant(mvm->fw))
846 return -EINVAL;
847
848 /* change the rx antennas for scan command */
849 mvm->scan_rx_ant = scan_rx_ant;
850
851 return count;
852}
853
854
b571a697
AB
855static void iwl_dbgfs_update_bf(struct ieee80211_vif *vif,
856 enum iwl_dbgfs_bf_mask param, int value)
857{
858 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
859 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
860
861 dbgfs_bf->mask |= param;
862
863 switch (param) {
864 case MVM_DEBUGFS_BF_ENERGY_DELTA:
865 dbgfs_bf->bf_energy_delta = value;
866 break;
867 case MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA:
868 dbgfs_bf->bf_roaming_energy_delta = value;
869 break;
870 case MVM_DEBUGFS_BF_ROAMING_STATE:
871 dbgfs_bf->bf_roaming_state = value;
872 break;
5dca7c24
HG
873 case MVM_DEBUGFS_BF_TEMP_THRESHOLD:
874 dbgfs_bf->bf_temp_threshold = value;
875 break;
876 case MVM_DEBUGFS_BF_TEMP_FAST_FILTER:
877 dbgfs_bf->bf_temp_fast_filter = value;
878 break;
879 case MVM_DEBUGFS_BF_TEMP_SLOW_FILTER:
880 dbgfs_bf->bf_temp_slow_filter = value;
b571a697
AB
881 break;
882 case MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER:
883 dbgfs_bf->bf_enable_beacon_filter = value;
884 break;
885 case MVM_DEBUGFS_BF_DEBUG_FLAG:
886 dbgfs_bf->bf_debug_flag = value;
887 break;
888 case MVM_DEBUGFS_BF_ESCAPE_TIMER:
889 dbgfs_bf->bf_escape_timer = value;
890 break;
891 case MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT:
892 dbgfs_bf->ba_enable_beacon_abort = value;
893 break;
894 case MVM_DEBUGFS_BA_ESCAPE_TIMER:
895 dbgfs_bf->ba_escape_timer = value;
896 break;
897 }
898}
899
900static ssize_t iwl_dbgfs_bf_params_write(struct file *file,
901 const char __user *user_buf,
902 size_t count, loff_t *ppos)
903{
904 struct ieee80211_vif *vif = file->private_data;
905 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
906 struct iwl_mvm *mvm = mvmvif->dbgfs_data;
907 enum iwl_dbgfs_bf_mask param;
908 char buf[256];
909 int buf_size;
910 int value;
911 int ret = 0;
912
913 memset(buf, 0, sizeof(buf));
914 buf_size = min(count, sizeof(buf) - 1);
915 if (copy_from_user(buf, user_buf, buf_size))
916 return -EFAULT;
917
918 if (!strncmp("bf_energy_delta=", buf, 16)) {
919 if (sscanf(buf+16, "%d", &value) != 1)
920 return -EINVAL;
921 if (value < IWL_BF_ENERGY_DELTA_MIN ||
922 value > IWL_BF_ENERGY_DELTA_MAX)
923 return -EINVAL;
924 param = MVM_DEBUGFS_BF_ENERGY_DELTA;
925 } else if (!strncmp("bf_roaming_energy_delta=", buf, 24)) {
926 if (sscanf(buf+24, "%d", &value) != 1)
927 return -EINVAL;
928 if (value < IWL_BF_ROAMING_ENERGY_DELTA_MIN ||
929 value > IWL_BF_ROAMING_ENERGY_DELTA_MAX)
930 return -EINVAL;
931 param = MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA;
932 } else if (!strncmp("bf_roaming_state=", buf, 17)) {
933 if (sscanf(buf+17, "%d", &value) != 1)
934 return -EINVAL;
935 if (value < IWL_BF_ROAMING_STATE_MIN ||
936 value > IWL_BF_ROAMING_STATE_MAX)
937 return -EINVAL;
938 param = MVM_DEBUGFS_BF_ROAMING_STATE;
5dca7c24
HG
939 } else if (!strncmp("bf_temp_threshold=", buf, 18)) {
940 if (sscanf(buf+18, "%d", &value) != 1)
941 return -EINVAL;
942 if (value < IWL_BF_TEMP_THRESHOLD_MIN ||
943 value > IWL_BF_TEMP_THRESHOLD_MAX)
944 return -EINVAL;
945 param = MVM_DEBUGFS_BF_TEMP_THRESHOLD;
946 } else if (!strncmp("bf_temp_fast_filter=", buf, 20)) {
947 if (sscanf(buf+20, "%d", &value) != 1)
948 return -EINVAL;
949 if (value < IWL_BF_TEMP_FAST_FILTER_MIN ||
950 value > IWL_BF_TEMP_FAST_FILTER_MAX)
951 return -EINVAL;
952 param = MVM_DEBUGFS_BF_TEMP_FAST_FILTER;
953 } else if (!strncmp("bf_temp_slow_filter=", buf, 20)) {
954 if (sscanf(buf+20, "%d", &value) != 1)
b571a697 955 return -EINVAL;
5dca7c24
HG
956 if (value < IWL_BF_TEMP_SLOW_FILTER_MIN ||
957 value > IWL_BF_TEMP_SLOW_FILTER_MAX)
b571a697 958 return -EINVAL;
5dca7c24 959 param = MVM_DEBUGFS_BF_TEMP_SLOW_FILTER;
b571a697
AB
960 } else if (!strncmp("bf_enable_beacon_filter=", buf, 24)) {
961 if (sscanf(buf+24, "%d", &value) != 1)
962 return -EINVAL;
963 if (value < 0 || value > 1)
964 return -EINVAL;
965 param = MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER;
966 } else if (!strncmp("bf_debug_flag=", buf, 14)) {
967 if (sscanf(buf+14, "%d", &value) != 1)
968 return -EINVAL;
969 if (value < 0 || value > 1)
970 return -EINVAL;
971 param = MVM_DEBUGFS_BF_DEBUG_FLAG;
972 } else if (!strncmp("bf_escape_timer=", buf, 16)) {
973 if (sscanf(buf+16, "%d", &value) != 1)
974 return -EINVAL;
975 if (value < IWL_BF_ESCAPE_TIMER_MIN ||
976 value > IWL_BF_ESCAPE_TIMER_MAX)
977 return -EINVAL;
978 param = MVM_DEBUGFS_BF_ESCAPE_TIMER;
979 } else if (!strncmp("ba_escape_timer=", buf, 16)) {
980 if (sscanf(buf+16, "%d", &value) != 1)
981 return -EINVAL;
982 if (value < IWL_BA_ESCAPE_TIMER_MIN ||
983 value > IWL_BA_ESCAPE_TIMER_MAX)
984 return -EINVAL;
985 param = MVM_DEBUGFS_BA_ESCAPE_TIMER;
986 } else if (!strncmp("ba_enable_beacon_abort=", buf, 23)) {
987 if (sscanf(buf+23, "%d", &value) != 1)
988 return -EINVAL;
989 if (value < 0 || value > 1)
990 return -EINVAL;
991 param = MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT;
992 } else {
993 return -EINVAL;
994 }
995
996 mutex_lock(&mvm->mutex);
997 iwl_dbgfs_update_bf(vif, param, value);
998 if (param == MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER && !value) {
999 ret = iwl_mvm_disable_beacon_filter(mvm, vif);
1000 } else {
495191c7 1001 ret = iwl_mvm_enable_beacon_filter(mvm, vif);
b571a697
AB
1002 }
1003 mutex_unlock(&mvm->mutex);
1004
1005 return ret ?: count;
1006}
1007
1008static ssize_t iwl_dbgfs_bf_params_read(struct file *file,
1009 char __user *user_buf,
1010 size_t count, loff_t *ppos)
1011{
1012 struct ieee80211_vif *vif = file->private_data;
1013 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1014 char buf[256];
1015 int pos = 0;
1016 const size_t bufsz = sizeof(buf);
1017 struct iwl_beacon_filter_cmd cmd = {
5dca7c24
HG
1018 IWL_BF_CMD_CONFIG_DEFAULTS,
1019 .bf_enable_beacon_filter =
1020 cpu_to_le32(IWL_BF_ENABLE_BEACON_FILTER_DEFAULT),
1021 .ba_enable_beacon_abort =
1022 cpu_to_le32(IWL_BA_ENABLE_BEACON_ABORT_DEFAULT),
b571a697
AB
1023 };
1024
1025 iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
a20fd398 1026 if (mvmvif->bf_data.bf_enabled)
5dca7c24 1027 cmd.bf_enable_beacon_filter = cpu_to_le32(1);
b571a697
AB
1028 else
1029 cmd.bf_enable_beacon_filter = 0;
1030
1031 pos += scnprintf(buf+pos, bufsz-pos, "bf_energy_delta = %d\n",
5dca7c24 1032 le32_to_cpu(cmd.bf_energy_delta));
b571a697 1033 pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_energy_delta = %d\n",
5dca7c24 1034 le32_to_cpu(cmd.bf_roaming_energy_delta));
b571a697 1035 pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_state = %d\n",
5dca7c24
HG
1036 le32_to_cpu(cmd.bf_roaming_state));
1037 pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_threshold = %d\n",
1038 le32_to_cpu(cmd.bf_temp_threshold));
1039 pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_fast_filter = %d\n",
1040 le32_to_cpu(cmd.bf_temp_fast_filter));
1041 pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_slow_filter = %d\n",
1042 le32_to_cpu(cmd.bf_temp_slow_filter));
b571a697 1043 pos += scnprintf(buf+pos, bufsz-pos, "bf_enable_beacon_filter = %d\n",
5dca7c24 1044 le32_to_cpu(cmd.bf_enable_beacon_filter));
b571a697 1045 pos += scnprintf(buf+pos, bufsz-pos, "bf_debug_flag = %d\n",
5dca7c24 1046 le32_to_cpu(cmd.bf_debug_flag));
b571a697 1047 pos += scnprintf(buf+pos, bufsz-pos, "bf_escape_timer = %d\n",
5dca7c24 1048 le32_to_cpu(cmd.bf_escape_timer));
b571a697 1049 pos += scnprintf(buf+pos, bufsz-pos, "ba_escape_timer = %d\n",
5dca7c24 1050 le32_to_cpu(cmd.ba_escape_timer));
b571a697 1051 pos += scnprintf(buf+pos, bufsz-pos, "ba_enable_beacon_abort = %d\n",
5dca7c24 1052 le32_to_cpu(cmd.ba_enable_beacon_abort));
b571a697
AB
1053
1054 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1055}
1056
afc66bb7
JB
1057#ifdef CONFIG_PM_SLEEP
1058static ssize_t iwl_dbgfs_d3_sram_write(struct file *file,
1059 const char __user *user_buf,
1060 size_t count, loff_t *ppos)
1061{
1062 struct iwl_mvm *mvm = file->private_data;
1063 char buf[8] = {};
1064 int store;
1065
0e9d84ea
DH
1066 count = min_t(size_t, count, sizeof(buf) - 1);
1067 if (copy_from_user(buf, user_buf, count))
afc66bb7
JB
1068 return -EFAULT;
1069
1070 if (sscanf(buf, "%d", &store) != 1)
1071 return -EINVAL;
1072
1073 mvm->store_d3_resume_sram = store;
1074
1075 return count;
1076}
1077
1078static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
1079 size_t count, loff_t *ppos)
1080{
1081 struct iwl_mvm *mvm = file->private_data;
1082 const struct fw_img *img;
1083 int ofs, len, pos = 0;
1084 size_t bufsz, ret;
1085 char *buf;
1086 u8 *ptr = mvm->d3_resume_sram;
1087
1088 img = &mvm->fw->img[IWL_UCODE_WOWLAN];
1089 len = img->sec[IWL_UCODE_SECTION_DATA].len;
1090
1091 bufsz = len * 4 + 256;
1092 buf = kzalloc(bufsz, GFP_KERNEL);
1093 if (!buf)
1094 return -ENOMEM;
1095
1096 pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
1097 mvm->store_d3_resume_sram ? "en" : "dis");
1098
1099 if (ptr) {
1100 for (ofs = 0; ofs < len; ofs += 16) {
1101 pos += scnprintf(buf + pos, bufsz - pos,
1102 "0x%.4x ", ofs);
1103 hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
1104 bufsz - pos, false);
1105 pos += strlen(buf + pos);
1106 if (bufsz - pos > 0)
1107 buf[pos++] = '\n';
1108 }
1109 } else {
1110 pos += scnprintf(buf + pos, bufsz - pos,
1111 "(no data captured)\n");
1112 }
1113
1114 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1115
1116 kfree(buf);
1117
1118 return ret;
1119}
1120#endif
1121
8ca151b5
JB
1122#define MVM_DEBUGFS_READ_FILE_OPS(name) \
1123static const struct file_operations iwl_dbgfs_##name##_ops = { \
1124 .read = iwl_dbgfs_##name##_read, \
ba5295f8 1125 .open = simple_open, \
8ca151b5
JB
1126 .llseek = generic_file_llseek, \
1127}
1128
1129#define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name) \
1130static const struct file_operations iwl_dbgfs_##name##_ops = { \
1131 .write = iwl_dbgfs_##name##_write, \
1132 .read = iwl_dbgfs_##name##_read, \
ba5295f8 1133 .open = simple_open, \
8ca151b5
JB
1134 .llseek = generic_file_llseek, \
1135};
1136
1137#define MVM_DEBUGFS_WRITE_FILE_OPS(name) \
1138static const struct file_operations iwl_dbgfs_##name##_ops = { \
1139 .write = iwl_dbgfs_##name##_write, \
ba5295f8 1140 .open = simple_open, \
8ca151b5
JB
1141 .llseek = generic_file_llseek, \
1142};
1143
1144#define MVM_DEBUGFS_ADD_FILE(name, parent, mode) do { \
1145 if (!debugfs_create_file(#name, mode, parent, mvm, \
1146 &iwl_dbgfs_##name##_ops)) \
1147 goto err; \
1148 } while (0)
1149
1150#define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \
1151 if (!debugfs_create_file(#name, mode, parent, vif, \
1152 &iwl_dbgfs_##name##_ops)) \
1153 goto err; \
1154 } while (0)
1155
1156/* Device wide debugfs entries */
1157MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush);
1158MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain);
1159MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram);
1160MVM_DEBUGFS_READ_FILE_OPS(stations);
10942342 1161MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
2de13cae 1162MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
64b928c4 1163MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off);
3848ab66 1164MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
490953ac 1165MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart);
91b05d10
OG
1166MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain);
1167
afc66bb7
JB
1168#ifdef CONFIG_PM_SLEEP
1169MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram);
1170#endif
8ca151b5 1171
63494374
JB
1172/* Interface specific debugfs entries */
1173MVM_DEBUGFS_READ_FILE_OPS(mac_params);
b571a697
AB
1174MVM_DEBUGFS_READ_WRITE_FILE_OPS(pm_params);
1175MVM_DEBUGFS_READ_WRITE_FILE_OPS(bf_params);
63494374 1176
8ca151b5
JB
1177int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
1178{
1179 char buf[100];
1180
1181 mvm->debugfs_dir = dbgfs_dir;
1182
1183 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
1184 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
1185 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
1186 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
10942342 1187 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
2de13cae 1188 MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
64b928c4
AB
1189 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_DEVICE_PS_CMD)
1190 MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
1191 S_IRUSR | S_IWUSR);
3848ab66 1192 MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
490953ac 1193 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
91b05d10
OG
1194 MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
1195 S_IWUSR | S_IRUSR);
afc66bb7
JB
1196#ifdef CONFIG_PM_SLEEP
1197 MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
debff618 1198 MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
b0114714
JB
1199 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
1200 mvm->debugfs_dir, &mvm->d3_wake_sysassert))
1201 goto err;
afc66bb7 1202#endif
8ca151b5
JB
1203
1204 /*
1205 * Create a symlink with mac80211. It will be removed when mac80211
1206 * exists (before the opmode exists which removes the target.)
1207 */
1208 snprintf(buf, 100, "../../%s/%s",
1209 dbgfs_dir->d_parent->d_parent->d_name.name,
1210 dbgfs_dir->d_parent->d_name.name);
1211 if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
1212 goto err;
1213
1214 return 0;
1215err:
1216 IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
1217 return -ENOMEM;
1218}
63494374
JB
1219
1220void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1221{
1222 struct dentry *dbgfs_dir = vif->debugfs_dir;
1223 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1224 char buf[100];
1225
0ecb3763
AB
1226 /*
1227 * Check if debugfs directory already exist before creating it.
1228 * This may happen when, for example, resetting hw or suspend-resume
1229 */
1230 if (!dbgfs_dir || mvmvif->dbgfs_dir)
63494374
JB
1231 return;
1232
1233 mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir);
1234 mvmvif->dbgfs_data = mvm;
1235
1236 if (!mvmvif->dbgfs_dir) {
1237 IWL_ERR(mvm, "Failed to create debugfs directory under %s\n",
1238 dbgfs_dir->d_name.name);
1239 return;
1240 }
1241
b571a697
AB
1242 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM &&
1243 vif->type == NL80211_IFTYPE_STATION && !vif->p2p)
1244 MVM_DEBUGFS_ADD_FILE_VIF(pm_params, mvmvif->dbgfs_dir, S_IWUSR |
1245 S_IRUSR);
1246
63494374
JB
1247 MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir,
1248 S_IRUSR);
1249
b571a697
AB
1250 if (vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
1251 mvmvif == mvm->bf_allowed_vif)
1252 MVM_DEBUGFS_ADD_FILE_VIF(bf_params, mvmvif->dbgfs_dir,
1253 S_IRUSR | S_IWUSR);
1254
63494374
JB
1255 /*
1256 * Create symlink for convenience pointing to interface specific
1257 * debugfs entries for the driver. For example, under
1258 * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/
1259 * find
1260 * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/
1261 */
1262 snprintf(buf, 100, "../../../%s/%s/%s/%s",
1263 dbgfs_dir->d_parent->d_parent->d_name.name,
1264 dbgfs_dir->d_parent->d_name.name,
1265 dbgfs_dir->d_name.name,
1266 mvmvif->dbgfs_dir->d_name.name);
1267
1268 mvmvif->dbgfs_slink = debugfs_create_symlink(dbgfs_dir->d_name.name,
1269 mvm->debugfs_dir, buf);
1270 if (!mvmvif->dbgfs_slink)
1271 IWL_ERR(mvm, "Can't create debugfs symbolic link under %s\n",
1272 dbgfs_dir->d_name.name);
1273 return;
1274err:
1275 IWL_ERR(mvm, "Can't create debugfs entity\n");
1276}
1277
1278void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1279{
1280 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1281
1282 debugfs_remove(mvmvif->dbgfs_slink);
1283 mvmvif->dbgfs_slink = NULL;
1284
1285 debugfs_remove_recursive(mvmvif->dbgfs_dir);
1286 mvmvif->dbgfs_dir = NULL;
1287}
This page took 0.125132 seconds and 5 git commands to generate.