Merge branches 'for-4.6/upstream-fixes', 'for-4.7/asus', 'for-4.7/hidraw' and 'for...
[deliverable/linux.git] / drivers / net / wireless / intel / 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 *
51368bf7 8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
c779273b 9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
43413a97 10 * Copyright(c) 2016 Intel Deutschland GmbH
8ca151b5
JB
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
410dc5aa 27 * in the file called COPYING.
8ca151b5
JB
28 *
29 * Contact Information:
cb2f8277 30 * Intel Linux Wireless <linuxwifi@intel.com>
8ca151b5
JB
31 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
32 *
33 * BSD LICENSE
34 *
51368bf7 35 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
c779273b 36 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
8ca151b5
JB
37 * All rights reserved.
38 *
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 *
43 * * Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * * Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in
47 * the documentation and/or other materials provided with the
48 * distribution.
49 * * Neither the name Intel Corporation nor the names of its
50 * contributors may be used to endorse or promote products derived
51 * from this software without specific prior written permission.
52 *
53 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
54 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
55 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
56 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
57 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
58 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
59 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
60 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
61 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
62 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
63 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 *
65 *****************************************************************************/
192c80a2 66#include <linux/vmalloc.h>
9e7dce28 67#include <linux/ieee80211.h>
192c80a2 68
8ca151b5 69#include "mvm.h"
2f89a5d7 70#include "fw-dbg.h"
8ca151b5
JB
71#include "sta.h"
72#include "iwl-io.h"
820a1a50 73#include "debugfs.h"
4d075007 74#include "iwl-fw-error-dump.h"
8ca151b5 75
00f481bd
CRI
76static ssize_t iwl_dbgfs_ctdp_budget_read(struct file *file,
77 char __user *user_buf,
78 size_t count, loff_t *ppos)
79{
80 struct iwl_mvm *mvm = file->private_data;
81 char buf[16];
82 int pos, budget;
83
84 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
85 return -EIO;
86
87 mutex_lock(&mvm->mutex);
88 budget = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_REPORT, 0);
89 mutex_unlock(&mvm->mutex);
90
91 if (budget < 0)
92 return budget;
93
94 pos = scnprintf(buf, sizeof(buf), "%d\n", budget);
95
96 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
97}
98
99static ssize_t iwl_dbgfs_stop_ctdp_write(struct iwl_mvm *mvm, char *buf,
100 size_t count, loff_t *ppos)
101{
102 int ret;
103
104 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
105 return -EIO;
106
107 mutex_lock(&mvm->mutex);
108 ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_STOP, 0);
109 mutex_unlock(&mvm->mutex);
110
111 return ret ?: count;
112}
113
1fa3f57a 114static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf,
8ca151b5
JB
115 size_t count, loff_t *ppos)
116{
8a0bd168 117 int ret;
8ca151b5
JB
118 u32 scd_q_msk;
119
120 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
121 return -EIO;
122
8ca151b5
JB
123 if (sscanf(buf, "%x", &scd_q_msk) != 1)
124 return -EINVAL;
125
126 IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk);
127
128 mutex_lock(&mvm->mutex);
5888a40c 129 ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, 0) ? : count;
8ca151b5
JB
130 mutex_unlock(&mvm->mutex);
131
132 return ret;
133}
134
1fa3f57a 135static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf,
8ca151b5
JB
136 size_t count, loff_t *ppos)
137{
f327b04c 138 struct iwl_mvm_sta *mvmsta;
8a0bd168 139 int sta_id, drain, ret;
8ca151b5
JB
140
141 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
142 return -EIO;
143
8ca151b5
JB
144 if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
145 return -EINVAL;
60765a47
JB
146 if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
147 return -EINVAL;
148 if (drain < 0 || drain > 1)
149 return -EINVAL;
8ca151b5
JB
150
151 mutex_lock(&mvm->mutex);
152
f327b04c
EG
153 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
154
155 if (!mvmsta)
8ca151b5
JB
156 ret = -ENOENT;
157 else
f327b04c 158 ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count;
8ca151b5
JB
159
160 mutex_unlock(&mvm->mutex);
161
162 return ret;
163}
164
165static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
166 size_t count, loff_t *ppos)
167{
168 struct iwl_mvm *mvm = file->private_data;
169 const struct fw_img *img;
d510342f
EG
170 unsigned int ofs, len;
171 size_t ret;
8ca151b5
JB
172 u8 *ptr;
173
60191d99
JB
174 if (!mvm->ucode_loaded)
175 return -EINVAL;
176
8ca151b5 177 /* default is to dump the entire data segment */
d510342f
EG
178 img = &mvm->fw->img[mvm->cur_ucode];
179 ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
180 len = img->sec[IWL_UCODE_SECTION_DATA].len;
181
01e0efe3 182 if (mvm->dbgfs_sram_len) {
60191d99
JB
183 ofs = mvm->dbgfs_sram_offset;
184 len = mvm->dbgfs_sram_len;
8ca151b5 185 }
8ca151b5 186
8ca151b5 187 ptr = kzalloc(len, GFP_KERNEL);
d510342f 188 if (!ptr)
8ca151b5 189 return -ENOMEM;
8ca151b5 190
60191d99 191 iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
8ca151b5 192
d510342f 193 ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len);
8ca151b5 194
8ca151b5
JB
195 kfree(ptr);
196
197 return ret;
198}
199
1fa3f57a
JB
200static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf,
201 size_t count, loff_t *ppos)
8ca151b5 202{
d510342f 203 const struct fw_img *img;
8ca151b5 204 u32 offset, len;
d510342f
EG
205 u32 img_offset, img_len;
206
207 if (!mvm->ucode_loaded)
208 return -EINVAL;
209
210 img = &mvm->fw->img[mvm->cur_ucode];
211 img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset;
212 img_len = img->sec[IWL_UCODE_SECTION_DATA].len;
8ca151b5 213
8ca151b5
JB
214 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
215 if ((offset & 0x3) || (len & 0x3))
216 return -EINVAL;
d510342f
EG
217
218 if (offset + len > img_offset + img_len)
219 return -EINVAL;
220
8ca151b5
JB
221 mvm->dbgfs_sram_offset = offset;
222 mvm->dbgfs_sram_len = len;
223 } else {
224 mvm->dbgfs_sram_offset = 0;
225 mvm->dbgfs_sram_len = 0;
226 }
227
228 return count;
229}
230
7280d1f0
MG
231static ssize_t iwl_dbgfs_set_nic_temperature_read(struct file *file,
232 char __user *user_buf,
233 size_t count, loff_t *ppos)
234{
235 struct iwl_mvm *mvm = file->private_data;
236 char buf[16];
237 int pos;
238
239 if (!mvm->temperature_test)
240 pos = scnprintf(buf , sizeof(buf), "disabled\n");
241 else
242 pos = scnprintf(buf , sizeof(buf), "%d\n", mvm->temperature);
243
244 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
245}
246
247/*
248 * Set NIC Temperature
249 * Cause the driver to ignore the actual NIC temperature reported by the FW
250 * Enable: any value between IWL_MVM_DEBUG_SET_TEMPERATURE_MIN -
251 * IWL_MVM_DEBUG_SET_TEMPERATURE_MAX
252 * Disable: IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE
253 */
254static ssize_t iwl_dbgfs_set_nic_temperature_write(struct iwl_mvm *mvm,
255 char *buf, size_t count,
256 loff_t *ppos)
257{
258 int temperature;
259
a26d4e7b
LC
260 if (!mvm->ucode_loaded && !mvm->temperature_test)
261 return -EIO;
262
7280d1f0
MG
263 if (kstrtoint(buf, 10, &temperature))
264 return -EINVAL;
265 /* not a legal temperature */
266 if ((temperature > IWL_MVM_DEBUG_SET_TEMPERATURE_MAX &&
267 temperature != IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) ||
268 temperature < IWL_MVM_DEBUG_SET_TEMPERATURE_MIN)
269 return -EINVAL;
270
271 mutex_lock(&mvm->mutex);
272 if (temperature == IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) {
b689fa79
LC
273 if (!mvm->temperature_test)
274 goto out;
275
7280d1f0 276 mvm->temperature_test = false;
b689fa79
LC
277 /* Since we can't read the temp while awake, just set
278 * it to zero until we get the next RX stats from the
279 * firmware.
280 */
281 mvm->temperature = 0;
7280d1f0
MG
282 } else {
283 mvm->temperature_test = true;
284 mvm->temperature = temperature;
285 }
286 IWL_DEBUG_TEMP(mvm, "%sabling debug set temperature (temp = %d)\n",
287 mvm->temperature_test ? "En" : "Dis" ,
288 mvm->temperature);
289 /* handle the temperature change */
290 iwl_mvm_tt_handler(mvm);
b689fa79
LC
291
292out:
7280d1f0
MG
293 mutex_unlock(&mvm->mutex);
294
295 return count;
296}
297
c549e390
LC
298static ssize_t iwl_dbgfs_nic_temp_read(struct file *file,
299 char __user *user_buf,
300 size_t count, loff_t *ppos)
301{
302 struct iwl_mvm *mvm = file->private_data;
303 char buf[16];
7869318e
CRI
304 int pos, ret;
305 s32 temp;
c549e390
LC
306
307 if (!mvm->ucode_loaded)
308 return -EIO;
309
310 mutex_lock(&mvm->mutex);
7869318e 311 ret = iwl_mvm_get_temp(mvm, &temp);
c549e390
LC
312 mutex_unlock(&mvm->mutex);
313
7869318e
CRI
314 if (ret)
315 return -EIO;
c549e390
LC
316
317 pos = scnprintf(buf , sizeof(buf), "%d\n", temp);
318
319 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
320}
321
8ca151b5
JB
322static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
323 size_t count, loff_t *ppos)
324{
325 struct iwl_mvm *mvm = file->private_data;
326 struct ieee80211_sta *sta;
327 char buf[400];
328 int i, pos = 0, bufsz = sizeof(buf);
329
330 mutex_lock(&mvm->mutex);
331
332 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
333 pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
334 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
335 lockdep_is_held(&mvm->mutex));
336 if (!sta)
337 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
338 else if (IS_ERR(sta))
339 pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
340 PTR_ERR(sta));
341 else
342 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
343 sta->addr);
344 }
345
346 mutex_unlock(&mvm->mutex);
347
348 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
349}
350
64b928c4
AB
351static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
352 char __user *user_buf,
8ca151b5
JB
353 size_t count, loff_t *ppos)
354{
355 struct iwl_mvm *mvm = file->private_data;
64b928c4
AB
356 char buf[64];
357 int bufsz = sizeof(buf);
358 int pos = 0;
8ca151b5 359
64b928c4
AB
360 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
361 mvm->disable_power_off);
362 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
363 mvm->disable_power_off_d3);
8ca151b5 364
64b928c4 365 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
8ca151b5
JB
366}
367
1fa3f57a 368static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf,
64b928c4 369 size_t count, loff_t *ppos)
8ca151b5 370{
1fa3f57a 371 int ret, val;
64b928c4
AB
372
373 if (!mvm->ucode_loaded)
374 return -EIO;
8ca151b5 375
64b928c4
AB
376 if (!strncmp("disable_power_off_d0=", buf, 21)) {
377 if (sscanf(buf + 21, "%d", &val) != 1)
378 return -EINVAL;
379 mvm->disable_power_off = val;
380 } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
381 if (sscanf(buf + 21, "%d", &val) != 1)
382 return -EINVAL;
383 mvm->disable_power_off_d3 = val;
384 } else {
8ca151b5 385 return -EINVAL;
64b928c4 386 }
8ca151b5 387
64b928c4 388 mutex_lock(&mvm->mutex);
c1cb92fc 389 ret = iwl_mvm_power_update_device(mvm);
64b928c4 390 mutex_unlock(&mvm->mutex);
8ca151b5 391
64b928c4 392 return ret ?: count;
8ca151b5
JB
393}
394
10942342
EG
395#define BT_MBOX_MSG(_notif, _num, _field) \
396 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
397 >> BT_MBOX##_num##_##_field##_POS)
398
399
400#define BT_MBOX_PRINT(_num, _field, _end) \
401 pos += scnprintf(buf + pos, bufsz - pos, \
402 "\t%s: %d%s", \
403 #_field, \
404 BT_MBOX_MSG(notif, _num, _field), \
405 true ? "\n" : ", ");
406
160be571
EG
407static
408int iwl_mvm_coex_dump_mbox(struct iwl_bt_coex_profile_notif *notif, char *buf,
409 int pos, int bufsz)
10942342 410{
160be571 411 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
10942342 412
160be571
EG
413 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
414 BT_MBOX_PRINT(0, LE_PROF1, false);
415 BT_MBOX_PRINT(0, LE_PROF2, false);
416 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
417 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
418 BT_MBOX_PRINT(0, INBAND_S, false);
419 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
420 BT_MBOX_PRINT(0, LE_SCAN, false);
421 BT_MBOX_PRINT(0, LE_ADV, false);
422 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
423 BT_MBOX_PRINT(0, OPEN_CON_1, true);
10942342 424
160be571
EG
425 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
426
427 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
428 BT_MBOX_PRINT(1, IP_SR, false);
429 BT_MBOX_PRINT(1, LE_MSTR, false);
430 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
431 BT_MBOX_PRINT(1, MSG_TYPE, false);
432 BT_MBOX_PRINT(1, SSN, true);
433
434 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
435
436 BT_MBOX_PRINT(2, SNIFF_ACT, false);
437 BT_MBOX_PRINT(2, PAG, false);
438 BT_MBOX_PRINT(2, INQUIRY, false);
439 BT_MBOX_PRINT(2, CONN, false);
440 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
441 BT_MBOX_PRINT(2, DISC, false);
442 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
443 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
444 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
445 BT_MBOX_PRINT(2, SCO_DURATION, true);
10942342 446
160be571
EG
447 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
448
449 BT_MBOX_PRINT(3, SCO_STATE, false);
450 BT_MBOX_PRINT(3, SNIFF_STATE, false);
451 BT_MBOX_PRINT(3, A2DP_STATE, false);
452 BT_MBOX_PRINT(3, ACL_STATE, false);
453 BT_MBOX_PRINT(3, MSTR_STATE, false);
454 BT_MBOX_PRINT(3, OBX_STATE, false);
455 BT_MBOX_PRINT(3, OPEN_CON_2, false);
456 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
457 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
458 BT_MBOX_PRINT(3, INBAND_P, false);
459 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
460 BT_MBOX_PRINT(3, SSN_2, false);
461 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
462
463 return pos;
464}
465
466static
467int iwl_mvm_coex_dump_mbox_old(struct iwl_bt_coex_profile_notif_old *notif,
468 char *buf, int pos, int bufsz)
469{
10942342
EG
470 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
471
472 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
473 BT_MBOX_PRINT(0, LE_PROF1, false);
474 BT_MBOX_PRINT(0, LE_PROF2, false);
475 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
476 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
477 BT_MBOX_PRINT(0, INBAND_S, false);
478 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
479 BT_MBOX_PRINT(0, LE_SCAN, false);
480 BT_MBOX_PRINT(0, LE_ADV, false);
481 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
482 BT_MBOX_PRINT(0, OPEN_CON_1, true);
483
484 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
485
486 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
487 BT_MBOX_PRINT(1, IP_SR, false);
488 BT_MBOX_PRINT(1, LE_MSTR, false);
489 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
490 BT_MBOX_PRINT(1, MSG_TYPE, false);
491 BT_MBOX_PRINT(1, SSN, true);
492
493 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
494
495 BT_MBOX_PRINT(2, SNIFF_ACT, false);
496 BT_MBOX_PRINT(2, PAG, false);
497 BT_MBOX_PRINT(2, INQUIRY, false);
498 BT_MBOX_PRINT(2, CONN, false);
499 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
500 BT_MBOX_PRINT(2, DISC, false);
501 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
502 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
503 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
504 BT_MBOX_PRINT(2, SCO_DURATION, true);
505
506 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
507
508 BT_MBOX_PRINT(3, SCO_STATE, false);
509 BT_MBOX_PRINT(3, SNIFF_STATE, false);
510 BT_MBOX_PRINT(3, A2DP_STATE, false);
511 BT_MBOX_PRINT(3, ACL_STATE, false);
512 BT_MBOX_PRINT(3, MSTR_STATE, false);
513 BT_MBOX_PRINT(3, OBX_STATE, false);
514 BT_MBOX_PRINT(3, OPEN_CON_2, false);
515 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
516 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
517 BT_MBOX_PRINT(3, INBAND_P, false);
518 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
519 BT_MBOX_PRINT(3, SSN_2, false);
520 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
521
160be571
EG
522 return pos;
523}
524
525static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
526 size_t count, loff_t *ppos)
527{
528 struct iwl_mvm *mvm = file->private_data;
529 char *buf;
530 int ret, pos = 0, bufsz = sizeof(char) * 1024;
531
532 buf = kmalloc(bufsz, GFP_KERNEL);
533 if (!buf)
534 return -ENOMEM;
535
536 mutex_lock(&mvm->mutex);
537
859d914c
JB
538 if (!fw_has_api(&mvm->fw->ucode_capa,
539 IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
160be571
EG
540 struct iwl_bt_coex_profile_notif_old *notif =
541 &mvm->last_bt_notif_old;
542
543 pos += iwl_mvm_coex_dump_mbox_old(notif, buf, pos, bufsz);
544
545 pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
546 notif->bt_ci_compliance);
547 pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
548 le32_to_cpu(notif->primary_ch_lut));
549 pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
550 le32_to_cpu(notif->secondary_ch_lut));
551 pos += scnprintf(buf+pos,
552 bufsz-pos, "bt_activity_grading = %d\n",
553 le32_to_cpu(notif->bt_activity_grading));
554 pos += scnprintf(buf+pos, bufsz-pos,
555 "antenna isolation = %d CORUN LUT index = %d\n",
556 mvm->last_ant_isol, mvm->last_corun_lut);
48f0a038
MH
557 pos += scnprintf(buf + pos, bufsz - pos, "bt_rrc = %d\n",
558 notif->rrc_enabled);
559 pos += scnprintf(buf + pos, bufsz - pos, "bt_ttc = %d\n",
560 notif->ttc_enabled);
160be571
EG
561 } else {
562 struct iwl_bt_coex_profile_notif *notif =
563 &mvm->last_bt_notif;
564
565 pos += iwl_mvm_coex_dump_mbox(notif, buf, pos, bufsz);
566
567 pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
568 notif->bt_ci_compliance);
569 pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
570 le32_to_cpu(notif->primary_ch_lut));
571 pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
572 le32_to_cpu(notif->secondary_ch_lut));
573 pos += scnprintf(buf+pos,
574 bufsz-pos, "bt_activity_grading = %d\n",
575 le32_to_cpu(notif->bt_activity_grading));
576 pos += scnprintf(buf+pos, bufsz-pos,
577 "antenna isolation = %d CORUN LUT index = %d\n",
578 mvm->last_ant_isol, mvm->last_corun_lut);
48f0a038
MH
579 pos += scnprintf(buf + pos, bufsz - pos, "bt_rrc = %d\n",
580 (notif->ttc_rrc_status >> 4) & 0xF);
581 pos += scnprintf(buf + pos, bufsz - pos, "bt_ttc = %d\n",
582 notif->ttc_rrc_status & 0xF);
160be571 583 }
10942342 584
c725a46b
MH
585 pos += scnprintf(buf + pos, bufsz - pos, "sync_sco = %d\n",
586 IWL_MVM_BT_COEX_SYNC2SCO);
587 pos += scnprintf(buf + pos, bufsz - pos, "mplut = %d\n",
588 IWL_MVM_BT_COEX_MPLUT);
589 pos += scnprintf(buf + pos, bufsz - pos, "corunning = %d\n",
590 IWL_MVM_BT_COEX_CORUNNING);
591
10942342
EG
592 mutex_unlock(&mvm->mutex);
593
594 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
595 kfree(buf);
596
597 return ret;
598}
599#undef BT_MBOX_PRINT
600
2de13cae
EG
601static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
602 size_t count, loff_t *ppos)
603{
604 struct iwl_mvm *mvm = file->private_data;
2de13cae
EG
605 char buf[256];
606 int bufsz = sizeof(buf);
607 int pos = 0;
608
609 mutex_lock(&mvm->mutex);
610
859d914c
JB
611 if (!fw_has_api(&mvm->fw->ucode_capa,
612 IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
160be571
EG
613 struct iwl_bt_coex_ci_cmd_old *cmd = &mvm->last_bt_ci_cmd_old;
614
615 pos += scnprintf(buf+pos, bufsz-pos,
616 "Channel inhibition CMD\n");
617 pos += scnprintf(buf+pos, bufsz-pos,
618 "\tPrimary Channel Bitmap 0x%016llx\n",
619 le64_to_cpu(cmd->bt_primary_ci));
620 pos += scnprintf(buf+pos, bufsz-pos,
621 "\tSecondary Channel Bitmap 0x%016llx\n",
622 le64_to_cpu(cmd->bt_secondary_ci));
623
aee8bf5d
EG
624 pos += scnprintf(buf+pos, bufsz-pos,
625 "BT Configuration CMD - 0=default, 1=never, 2=always\n");
626 pos += scnprintf(buf+pos, bufsz-pos, "\tACK Kill msk idx %d\n",
627 mvm->bt_ack_kill_msk[0]);
628 pos += scnprintf(buf+pos, bufsz-pos, "\tCTS Kill msk idx %d\n",
629 mvm->bt_cts_kill_msk[0]);
160be571
EG
630
631 } else {
632 struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
633
634 pos += scnprintf(buf+pos, bufsz-pos,
635 "Channel inhibition CMD\n");
636 pos += scnprintf(buf+pos, bufsz-pos,
637 "\tPrimary Channel Bitmap 0x%016llx\n",
638 le64_to_cpu(cmd->bt_primary_ci));
639 pos += scnprintf(buf+pos, bufsz-pos,
640 "\tSecondary Channel Bitmap 0x%016llx\n",
641 le64_to_cpu(cmd->bt_secondary_ci));
160be571 642 }
2de13cae
EG
643
644 mutex_unlock(&mvm->mutex);
645
646 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
647}
648
cdb00563
EG
649static ssize_t
650iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf,
651 size_t count, loff_t *ppos)
652{
653 u32 bt_tx_prio;
654
655 if (sscanf(buf, "%u", &bt_tx_prio) != 1)
656 return -EINVAL;
657 if (bt_tx_prio > 4)
658 return -EINVAL;
659
660 mvm->bt_tx_prio = bt_tx_prio;
661
662 return count;
663}
664
a39979a8
EG
665static ssize_t
666iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char *buf,
667 size_t count, loff_t *ppos)
668{
669 static const char * const modes_str[BT_FORCE_ANT_MAX] = {
670 [BT_FORCE_ANT_DIS] = "dis",
671 [BT_FORCE_ANT_AUTO] = "auto",
672 [BT_FORCE_ANT_BT] = "bt",
673 [BT_FORCE_ANT_WIFI] = "wifi",
674 };
675 int ret, bt_force_ant_mode;
676
677 for (bt_force_ant_mode = 0;
678 bt_force_ant_mode < ARRAY_SIZE(modes_str);
679 bt_force_ant_mode++) {
680 if (!strcmp(buf, modes_str[bt_force_ant_mode]))
681 break;
682 }
683
684 if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
685 return -EINVAL;
686
687 ret = 0;
688 mutex_lock(&mvm->mutex);
689 if (mvm->bt_force_ant_mode == bt_force_ant_mode)
690 goto out;
691
692 mvm->bt_force_ant_mode = bt_force_ant_mode;
693 IWL_DEBUG_COEX(mvm, "Force mode: %s\n",
694 modes_str[mvm->bt_force_ant_mode]);
695 ret = iwl_send_bt_init_conf(mvm);
696
697out:
698 mutex_unlock(&mvm->mutex);
699 return ret ?: count;
700}
701
93d17cce 702#define PRINT_STATS_LE32(_struct, _memb) \
3848ab66 703 pos += scnprintf(buf + pos, bufsz - pos, \
93d17cce
JB
704 fmt_table, #_memb, \
705 le32_to_cpu(_struct->_memb))
3848ab66
MG
706
707static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
708 char __user *user_buf, size_t count,
709 loff_t *ppos)
710{
711 struct iwl_mvm *mvm = file->private_data;
712 static const char *fmt_table = "\t%-30s %10u\n";
713 static const char *fmt_header = "%-32s\n";
714 int pos = 0;
715 char *buf;
716 int ret;
3f617281
LC
717 /* 43 is the size of each data line, 33 is the size of each header */
718 size_t bufsz =
719 ((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) +
720 (4 * 33) + 1;
721
3848ab66
MG
722 struct mvm_statistics_rx_phy *ofdm;
723 struct mvm_statistics_rx_phy *cck;
724 struct mvm_statistics_rx_non_phy *general;
725 struct mvm_statistics_rx_ht_phy *ht;
726
727 buf = kzalloc(bufsz, GFP_KERNEL);
728 if (!buf)
729 return -ENOMEM;
730
731 mutex_lock(&mvm->mutex);
732
733 ofdm = &mvm->rx_stats.ofdm;
734 cck = &mvm->rx_stats.cck;
735 general = &mvm->rx_stats.general;
736 ht = &mvm->rx_stats.ofdm_ht;
737
738 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
739 "Statistics_Rx - OFDM");
93d17cce
JB
740 PRINT_STATS_LE32(ofdm, ina_cnt);
741 PRINT_STATS_LE32(ofdm, fina_cnt);
742 PRINT_STATS_LE32(ofdm, plcp_err);
743 PRINT_STATS_LE32(ofdm, crc32_err);
744 PRINT_STATS_LE32(ofdm, overrun_err);
745 PRINT_STATS_LE32(ofdm, early_overrun_err);
746 PRINT_STATS_LE32(ofdm, crc32_good);
747 PRINT_STATS_LE32(ofdm, false_alarm_cnt);
748 PRINT_STATS_LE32(ofdm, fina_sync_err_cnt);
749 PRINT_STATS_LE32(ofdm, sfd_timeout);
750 PRINT_STATS_LE32(ofdm, fina_timeout);
751 PRINT_STATS_LE32(ofdm, unresponded_rts);
752 PRINT_STATS_LE32(ofdm, rxe_frame_lmt_overrun);
753 PRINT_STATS_LE32(ofdm, sent_ack_cnt);
754 PRINT_STATS_LE32(ofdm, sent_cts_cnt);
755 PRINT_STATS_LE32(ofdm, sent_ba_rsp_cnt);
756 PRINT_STATS_LE32(ofdm, dsp_self_kill);
757 PRINT_STATS_LE32(ofdm, mh_format_err);
758 PRINT_STATS_LE32(ofdm, re_acq_main_rssi_sum);
759 PRINT_STATS_LE32(ofdm, reserved);
3848ab66
MG
760
761 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
762 "Statistics_Rx - CCK");
93d17cce
JB
763 PRINT_STATS_LE32(cck, ina_cnt);
764 PRINT_STATS_LE32(cck, fina_cnt);
765 PRINT_STATS_LE32(cck, plcp_err);
766 PRINT_STATS_LE32(cck, crc32_err);
767 PRINT_STATS_LE32(cck, overrun_err);
768 PRINT_STATS_LE32(cck, early_overrun_err);
769 PRINT_STATS_LE32(cck, crc32_good);
770 PRINT_STATS_LE32(cck, false_alarm_cnt);
771 PRINT_STATS_LE32(cck, fina_sync_err_cnt);
772 PRINT_STATS_LE32(cck, sfd_timeout);
773 PRINT_STATS_LE32(cck, fina_timeout);
774 PRINT_STATS_LE32(cck, unresponded_rts);
775 PRINT_STATS_LE32(cck, rxe_frame_lmt_overrun);
776 PRINT_STATS_LE32(cck, sent_ack_cnt);
777 PRINT_STATS_LE32(cck, sent_cts_cnt);
778 PRINT_STATS_LE32(cck, sent_ba_rsp_cnt);
779 PRINT_STATS_LE32(cck, dsp_self_kill);
780 PRINT_STATS_LE32(cck, mh_format_err);
781 PRINT_STATS_LE32(cck, re_acq_main_rssi_sum);
782 PRINT_STATS_LE32(cck, reserved);
3848ab66
MG
783
784 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
785 "Statistics_Rx - GENERAL");
93d17cce
JB
786 PRINT_STATS_LE32(general, bogus_cts);
787 PRINT_STATS_LE32(general, bogus_ack);
788 PRINT_STATS_LE32(general, non_bssid_frames);
789 PRINT_STATS_LE32(general, filtered_frames);
790 PRINT_STATS_LE32(general, non_channel_beacons);
791 PRINT_STATS_LE32(general, channel_beacons);
792 PRINT_STATS_LE32(general, num_missed_bcon);
793 PRINT_STATS_LE32(general, adc_rx_saturation_time);
794 PRINT_STATS_LE32(general, ina_detection_search_time);
795 PRINT_STATS_LE32(general, beacon_silence_rssi_a);
796 PRINT_STATS_LE32(general, beacon_silence_rssi_b);
797 PRINT_STATS_LE32(general, beacon_silence_rssi_c);
798 PRINT_STATS_LE32(general, interference_data_flag);
799 PRINT_STATS_LE32(general, channel_load);
800 PRINT_STATS_LE32(general, dsp_false_alarms);
801 PRINT_STATS_LE32(general, beacon_rssi_a);
802 PRINT_STATS_LE32(general, beacon_rssi_b);
803 PRINT_STATS_LE32(general, beacon_rssi_c);
804 PRINT_STATS_LE32(general, beacon_energy_a);
805 PRINT_STATS_LE32(general, beacon_energy_b);
806 PRINT_STATS_LE32(general, beacon_energy_c);
807 PRINT_STATS_LE32(general, num_bt_kills);
808 PRINT_STATS_LE32(general, mac_id);
809 PRINT_STATS_LE32(general, directed_data_mpdu);
3848ab66
MG
810
811 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
812 "Statistics_Rx - HT");
93d17cce
JB
813 PRINT_STATS_LE32(ht, plcp_err);
814 PRINT_STATS_LE32(ht, overrun_err);
815 PRINT_STATS_LE32(ht, early_overrun_err);
816 PRINT_STATS_LE32(ht, crc32_good);
817 PRINT_STATS_LE32(ht, crc32_err);
818 PRINT_STATS_LE32(ht, mh_format_err);
819 PRINT_STATS_LE32(ht, agg_crc32_good);
820 PRINT_STATS_LE32(ht, agg_mpdu_cnt);
821 PRINT_STATS_LE32(ht, agg_cnt);
822 PRINT_STATS_LE32(ht, unsupport_mcs);
3848ab66
MG
823
824 mutex_unlock(&mvm->mutex);
825
826 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
827 kfree(buf);
828
829 return ret;
830}
831#undef PRINT_STAT_LE32
832
5fc0f76c
ES
833static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm,
834 char __user *user_buf, size_t count,
835 loff_t *ppos,
836 struct iwl_mvm_frame_stats *stats)
837{
f754b5ca
ES
838 char *buff, *pos, *endpos;
839 int idx, i;
5fc0f76c 840 int ret;
f754b5ca 841 static const size_t bufsz = 1024;
5fc0f76c
ES
842
843 buff = kmalloc(bufsz, GFP_KERNEL);
844 if (!buff)
845 return -ENOMEM;
846
847 spin_lock_bh(&mvm->drv_stats_lock);
f754b5ca
ES
848
849 pos = buff;
850 endpos = pos + bufsz;
851
852 pos += scnprintf(pos, endpos - pos,
5fc0f76c
ES
853 "Legacy/HT/VHT\t:\t%d/%d/%d\n",
854 stats->legacy_frames,
855 stats->ht_frames,
856 stats->vht_frames);
f754b5ca 857 pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n",
5fc0f76c
ES
858 stats->bw_20_frames,
859 stats->bw_40_frames,
860 stats->bw_80_frames);
f754b5ca 861 pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n",
5fc0f76c
ES
862 stats->ngi_frames,
863 stats->sgi_frames);
f754b5ca 864 pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n",
5fc0f76c
ES
865 stats->siso_frames,
866 stats->mimo2_frames);
f754b5ca 867 pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n",
5fc0f76c
ES
868 stats->fail_frames,
869 stats->success_frames);
f754b5ca 870 pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n",
5fc0f76c 871 stats->agg_frames);
f754b5ca 872 pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n",
5fc0f76c 873 stats->ampdu_count);
f754b5ca 874 pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n",
5fc0f76c
ES
875 stats->ampdu_count > 0 ?
876 (stats->agg_frames / stats->ampdu_count) : 0);
877
f754b5ca 878 pos += scnprintf(pos, endpos - pos, "Last Rates\n");
5fc0f76c
ES
879
880 idx = stats->last_frame_idx - 1;
881 for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) {
882 idx = (idx + 1) % ARRAY_SIZE(stats->last_rates);
883 if (stats->last_rates[idx] == 0)
884 continue;
f754b5ca 885 pos += scnprintf(pos, endpos - pos, "Rate[%d]: ",
5fc0f76c 886 (int)(ARRAY_SIZE(stats->last_rates) - i));
f754b5ca 887 pos += rs_pretty_print_rate(pos, stats->last_rates[idx]);
5fc0f76c
ES
888 }
889 spin_unlock_bh(&mvm->drv_stats_lock);
890
f754b5ca 891 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
5fc0f76c
ES
892 kfree(buff);
893
894 return ret;
895}
896
897static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file,
898 char __user *user_buf, size_t count,
899 loff_t *ppos)
900{
901 struct iwl_mvm *mvm = file->private_data;
902
903 return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos,
904 &mvm->drv_rx_stats);
905}
906
1fa3f57a 907static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
490953ac
EG
908 size_t count, loff_t *ppos)
909{
490953ac
EG
910 int ret;
911
490953ac
EG
912 mutex_lock(&mvm->mutex);
913
291aa7c4
EH
914 /* allow one more restart that we're provoking here */
915 if (mvm->restart_fw >= 0)
916 mvm->restart_fw++;
917
490953ac 918 /* take the return value to make compiler happy - it will fail anyway */
a1022927 919 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, 0, 0, NULL);
490953ac
EG
920
921 mutex_unlock(&mvm->mutex);
922
490953ac
EG
923 return count;
924}
925
1fa3f57a 926static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
119663c3
AB
927 size_t count, loff_t *ppos)
928{
576eeee9
EP
929 int ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_NMI);
930 if (ret)
931 return ret;
932
4c9706dc 933 iwl_force_nmi(mvm->trans);
119663c3 934
576eeee9
EP
935 iwl_mvm_unref(mvm, IWL_MVM_REF_NMI);
936
119663c3
AB
937 return count;
938}
939
91b05d10
OG
940static ssize_t
941iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
942 char __user *user_buf,
943 size_t count, loff_t *ppos)
944{
945 struct iwl_mvm *mvm = file->private_data;
946 int pos = 0;
947 char buf[32];
948 const size_t bufsz = sizeof(buf);
949
950 /* print which antennas were set for the scan command by the user */
951 pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
952 if (mvm->scan_rx_ant & ANT_A)
953 pos += scnprintf(buf + pos, bufsz - pos, "A");
954 if (mvm->scan_rx_ant & ANT_B)
955 pos += scnprintf(buf + pos, bufsz - pos, "B");
956 if (mvm->scan_rx_ant & ANT_C)
957 pos += scnprintf(buf + pos, bufsz - pos, "C");
958 pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
959
960 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
961}
962
963static ssize_t
1fa3f57a 964iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
91b05d10
OG
965 size_t count, loff_t *ppos)
966{
91b05d10
OG
967 u8 scan_rx_ant;
968
91b05d10
OG
969 if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
970 return -EINVAL;
971 if (scan_rx_ant > ANT_ABC)
972 return -EINVAL;
a0544272 973 if (scan_rx_ant & ~(iwl_mvm_get_valid_rx_ant(mvm)))
91b05d10
OG
974 return -EINVAL;
975
d2496221
DS
976 if (mvm->scan_rx_ant != scan_rx_ant) {
977 mvm->scan_rx_ant = scan_rx_ant;
859d914c
JB
978 if (fw_has_capa(&mvm->fw->ucode_capa,
979 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
d2496221
DS
980 iwl_mvm_config_scan(mvm);
981 }
91b05d10
OG
982
983 return count;
984}
985
43413a97
SS
986static ssize_t iwl_dbgfs_indirection_tbl_write(struct iwl_mvm *mvm,
987 char *buf, size_t count,
988 loff_t *ppos)
989{
990 struct iwl_rss_config_cmd cmd = {
991 .flags = cpu_to_le32(IWL_RSS_ENABLE),
992 .hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP |
993 IWL_RSS_HASH_TYPE_IPV4_PAYLOAD |
994 IWL_RSS_HASH_TYPE_IPV6_TCP |
995 IWL_RSS_HASH_TYPE_IPV6_PAYLOAD,
996 };
997 int ret, i, num_repeats, nbytes = count / 2;
998
999 ret = hex2bin(cmd.indirection_table, buf, nbytes);
1000 if (ret)
1001 return ret;
1002
1003 /*
1004 * The input is the redirection table, partial or full.
1005 * Repeat the pattern if needed.
1006 * For example, input of 01020F will be repeated 42 times,
1007 * indirecting RSS hash results to queues 1, 2, 15 (skipping
1008 * queues 3 - 14).
1009 */
1010 num_repeats = ARRAY_SIZE(cmd.indirection_table) / nbytes;
1011 for (i = 1; i < num_repeats; i++)
1012 memcpy(&cmd.indirection_table[i * nbytes],
1013 cmd.indirection_table, nbytes);
1014 /* handle cut in the middle pattern for the last places */
1015 memcpy(&cmd.indirection_table[i * nbytes], cmd.indirection_table,
1016 ARRAY_SIZE(cmd.indirection_table) % nbytes);
1017
dd4d3161 1018 memcpy(cmd.secret_key, mvm->secret_key, sizeof(cmd.secret_key));
43413a97
SS
1019
1020 mutex_lock(&mvm->mutex);
1021 ret = iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0, sizeof(cmd), &cmd);
1022 mutex_unlock(&mvm->mutex);
1023
1024 return ret ?: count;
1025}
1026
8c23f95c
EG
1027static ssize_t iwl_dbgfs_fw_dbg_conf_read(struct file *file,
1028 char __user *user_buf,
1029 size_t count, loff_t *ppos)
1030{
1031 struct iwl_mvm *mvm = file->private_data;
d2709ad7 1032 int conf;
8c23f95c
EG
1033 char buf[8];
1034 const size_t bufsz = sizeof(buf);
1035 int pos = 0;
1036
1037 mutex_lock(&mvm->mutex);
1038 conf = mvm->fw_dbg_conf;
1039 mutex_unlock(&mvm->mutex);
1040
1041 pos += scnprintf(buf + pos, bufsz - pos, "%d\n", conf);
1042
1043 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1044}
1045
321c2104
GBA
1046/*
1047 * Enable / Disable continuous recording.
1048 * Cause the FW to start continuous recording, by sending the relevant hcmd.
1049 * Enable: input of every integer larger than 0, ENABLE_CONT_RECORDING.
1050 * Disable: for 0 as input, DISABLE_CONT_RECORDING.
1051 */
1052static ssize_t iwl_dbgfs_cont_recording_write(struct iwl_mvm *mvm,
1053 char *buf, size_t count,
1054 loff_t *ppos)
1055{
1056 struct iwl_trans *trans = mvm->trans;
1057 const struct iwl_fw_dbg_dest_tlv *dest = trans->dbg_dest_tlv;
1058 struct iwl_continuous_record_cmd cont_rec = {};
1059 int ret, rec_mode;
1060
1061 if (!dest)
1062 return -EOPNOTSUPP;
1063
1064 if (dest->monitor_mode != SMEM_MODE ||
1065 trans->cfg->device_family != IWL_DEVICE_FAMILY_8000)
1066 return -EOPNOTSUPP;
1067
27e070d3 1068 ret = kstrtoint(buf, 0, &rec_mode);
321c2104
GBA
1069 if (ret)
1070 return ret;
1071
1072 cont_rec.record_mode.enable_recording = rec_mode ?
1073 cpu_to_le16(ENABLE_CONT_RECORDING) :
1074 cpu_to_le16(DISABLE_CONT_RECORDING);
1075
1076 mutex_lock(&mvm->mutex);
1077 ret = iwl_mvm_send_cmd_pdu(mvm, LDBG_CONFIG_CMD, 0,
1078 sizeof(cont_rec), &cont_rec);
1079 mutex_unlock(&mvm->mutex);
1080
1081 return ret ?: count;
1082}
1083
8c23f95c
EG
1084static ssize_t iwl_dbgfs_fw_dbg_conf_write(struct iwl_mvm *mvm,
1085 char *buf, size_t count,
1086 loff_t *ppos)
1087{
8e8114de
DC
1088 unsigned int conf_id;
1089 int ret;
8c23f95c 1090
8e8114de 1091 ret = kstrtouint(buf, 0, &conf_id);
8c23f95c
EG
1092 if (ret)
1093 return ret;
1094
d2709ad7 1095 if (WARN_ON(conf_id >= FW_DBG_CONF_MAX))
8c23f95c
EG
1096 return -EINVAL;
1097
1098 mutex_lock(&mvm->mutex);
1099 ret = iwl_mvm_start_fw_dbg_conf(mvm, conf_id);
1100 mutex_unlock(&mvm->mutex);
1101
1102 return ret ?: count;
1103}
1104
1105static ssize_t iwl_dbgfs_fw_dbg_collect_write(struct iwl_mvm *mvm,
1106 char *buf, size_t count,
1107 loff_t *ppos)
1108{
e93475a0
LK
1109 int ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
1110
1111 if (ret)
1112 return ret;
1113
c91b865c
GBA
1114 iwl_mvm_fw_dbg_collect(mvm, FW_DBG_TRIGGER_USER, buf,
1115 (count - 1), NULL);
e93475a0
LK
1116
1117 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
8c23f95c
EG
1118
1119 return count;
1120}
1121
9e7dce28
EG
1122static ssize_t iwl_dbgfs_max_amsdu_len_write(struct iwl_mvm *mvm,
1123 char *buf, size_t count,
1124 loff_t *ppos)
1125{
1126 unsigned int max_amsdu_len;
1127 int ret;
1128
1129 ret = kstrtouint(buf, 0, &max_amsdu_len);
1130
1131 if (max_amsdu_len > IEEE80211_MAX_MPDU_LEN_VHT_11454)
1132 return -EINVAL;
1133 mvm->max_amsdu_len = max_amsdu_len;
1134
1135 return count;
1136}
1137
de06a59e
EP
1138#define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__)
1139#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1140static ssize_t iwl_dbgfs_bcast_filters_read(struct file *file,
1141 char __user *user_buf,
1142 size_t count, loff_t *ppos)
1143{
1144 struct iwl_mvm *mvm = file->private_data;
1145 struct iwl_bcast_filter_cmd cmd;
1146 const struct iwl_fw_bcast_filter *filter;
1147 char *buf;
1148 int bufsz = 1024;
1149 int i, j, pos = 0;
1150 ssize_t ret;
1151
1152 buf = kzalloc(bufsz, GFP_KERNEL);
1153 if (!buf)
1154 return -ENOMEM;
1155
1156 mutex_lock(&mvm->mutex);
1157 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
1158 ADD_TEXT("None\n");
1159 mutex_unlock(&mvm->mutex);
1160 goto out;
1161 }
1162 mutex_unlock(&mvm->mutex);
1163
1164 for (i = 0; cmd.filters[i].attrs[0].mask; i++) {
1165 filter = &cmd.filters[i];
1166
1167 ADD_TEXT("Filter [%d]:\n", i);
1168 ADD_TEXT("\tDiscard=%d\n", filter->discard);
1169 ADD_TEXT("\tFrame Type: %s\n",
1170 filter->frame_type ? "IPv4" : "Generic");
1171
1172 for (j = 0; j < ARRAY_SIZE(filter->attrs); j++) {
1173 const struct iwl_fw_bcast_filter_attr *attr;
1174
1175 attr = &filter->attrs[j];
1176 if (!attr->mask)
1177 break;
1178
1179 ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n",
1180 j, attr->offset,
1181 attr->offset_type ? "IP End" :
1182 "Payload Start",
1183 be32_to_cpu(attr->mask),
1184 be32_to_cpu(attr->val),
1185 le16_to_cpu(attr->reserved1));
1186 }
1187 }
1188out:
1189 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1190 kfree(buf);
1191 return ret;
1192}
1193
1194static ssize_t iwl_dbgfs_bcast_filters_write(struct iwl_mvm *mvm, char *buf,
1195 size_t count, loff_t *ppos)
1196{
1197 int pos, next_pos;
1198 struct iwl_fw_bcast_filter filter = {};
1199 struct iwl_bcast_filter_cmd cmd;
1200 u32 filter_id, attr_id, mask, value;
1201 int err = 0;
1202
1203 if (sscanf(buf, "%d %hhi %hhi %n", &filter_id, &filter.discard,
1204 &filter.frame_type, &pos) != 3)
1205 return -EINVAL;
1206
1207 if (filter_id >= ARRAY_SIZE(mvm->dbgfs_bcast_filtering.cmd.filters) ||
1208 filter.frame_type > BCAST_FILTER_FRAME_TYPE_IPV4)
1209 return -EINVAL;
1210
1211 for (attr_id = 0; attr_id < ARRAY_SIZE(filter.attrs);
1212 attr_id++) {
1213 struct iwl_fw_bcast_filter_attr *attr =
1214 &filter.attrs[attr_id];
1215
1216 if (pos >= count)
1217 break;
1218
1219 if (sscanf(&buf[pos], "%hhi %hhi %i %i %n",
1220 &attr->offset, &attr->offset_type,
1221 &mask, &value, &next_pos) != 4)
1222 return -EINVAL;
1223
1224 attr->mask = cpu_to_be32(mask);
1225 attr->val = cpu_to_be32(value);
1226 if (mask)
1227 filter.num_attrs++;
1228
1229 pos += next_pos;
1230 }
1231
1232 mutex_lock(&mvm->mutex);
1233 memcpy(&mvm->dbgfs_bcast_filtering.cmd.filters[filter_id],
1234 &filter, sizeof(filter));
1235
1236 /* send updated bcast filtering configuration */
1237 if (mvm->dbgfs_bcast_filtering.override &&
1238 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
a1022927 1239 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
de06a59e
EP
1240 sizeof(cmd), &cmd);
1241 mutex_unlock(&mvm->mutex);
1242
1243 return err ?: count;
1244}
1245
1246static ssize_t iwl_dbgfs_bcast_filters_macs_read(struct file *file,
1247 char __user *user_buf,
1248 size_t count, loff_t *ppos)
1249{
1250 struct iwl_mvm *mvm = file->private_data;
1251 struct iwl_bcast_filter_cmd cmd;
1252 char *buf;
1253 int bufsz = 1024;
1254 int i, pos = 0;
1255 ssize_t ret;
1256
1257 buf = kzalloc(bufsz, GFP_KERNEL);
1258 if (!buf)
1259 return -ENOMEM;
1260
1261 mutex_lock(&mvm->mutex);
1262 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
1263 ADD_TEXT("None\n");
1264 mutex_unlock(&mvm->mutex);
1265 goto out;
1266 }
1267 mutex_unlock(&mvm->mutex);
1268
1269 for (i = 0; i < ARRAY_SIZE(cmd.macs); i++) {
1270 const struct iwl_fw_bcast_mac *mac = &cmd.macs[i];
1271
1272 ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n",
1273 i, mac->default_discard, mac->attached_filters);
1274 }
1275out:
1276 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1277 kfree(buf);
1278 return ret;
1279}
1280
1281static ssize_t iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm *mvm,
1282 char *buf, size_t count,
1283 loff_t *ppos)
1284{
1285 struct iwl_bcast_filter_cmd cmd;
1286 struct iwl_fw_bcast_mac mac = {};
1287 u32 mac_id, attached_filters;
1288 int err = 0;
1289
1290 if (!mvm->bcast_filters)
1291 return -ENOENT;
1292
1293 if (sscanf(buf, "%d %hhi %i", &mac_id, &mac.default_discard,
1294 &attached_filters) != 3)
1295 return -EINVAL;
1296
1297 if (mac_id >= ARRAY_SIZE(cmd.macs) ||
1298 mac.default_discard > 1 ||
1299 attached_filters >= BIT(ARRAY_SIZE(cmd.filters)))
1300 return -EINVAL;
1301
1302 mac.attached_filters = cpu_to_le16(attached_filters);
1303
1304 mutex_lock(&mvm->mutex);
1305 memcpy(&mvm->dbgfs_bcast_filtering.cmd.macs[mac_id],
1306 &mac, sizeof(mac));
1307
1308 /* send updated bcast filtering configuration */
1309 if (mvm->dbgfs_bcast_filtering.override &&
1310 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
a1022927 1311 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
de06a59e
EP
1312 sizeof(cmd), &cmd);
1313 mutex_unlock(&mvm->mutex);
1314
1315 return err ?: count;
1316}
1317#endif
1318
afc66bb7 1319#ifdef CONFIG_PM_SLEEP
1fa3f57a 1320static ssize_t iwl_dbgfs_d3_sram_write(struct iwl_mvm *mvm, char *buf,
afc66bb7
JB
1321 size_t count, loff_t *ppos)
1322{
afc66bb7
JB
1323 int store;
1324
afc66bb7
JB
1325 if (sscanf(buf, "%d", &store) != 1)
1326 return -EINVAL;
1327
1328 mvm->store_d3_resume_sram = store;
1329
1330 return count;
1331}
1332
1333static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
1334 size_t count, loff_t *ppos)
1335{
1336 struct iwl_mvm *mvm = file->private_data;
1337 const struct fw_img *img;
1338 int ofs, len, pos = 0;
1339 size_t bufsz, ret;
1340 char *buf;
1341 u8 *ptr = mvm->d3_resume_sram;
1342
1343 img = &mvm->fw->img[IWL_UCODE_WOWLAN];
1344 len = img->sec[IWL_UCODE_SECTION_DATA].len;
1345
1346 bufsz = len * 4 + 256;
1347 buf = kzalloc(bufsz, GFP_KERNEL);
1348 if (!buf)
1349 return -ENOMEM;
1350
1351 pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
1352 mvm->store_d3_resume_sram ? "en" : "dis");
1353
1354 if (ptr) {
1355 for (ofs = 0; ofs < len; ofs += 16) {
1356 pos += scnprintf(buf + pos, bufsz - pos,
3cd6e2f7 1357 "0x%.4x %16ph\n", ofs, ptr + ofs);
afc66bb7
JB
1358 }
1359 } else {
1360 pos += scnprintf(buf + pos, bufsz - pos,
1361 "(no data captured)\n");
1362 }
1363
1364 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1365
1366 kfree(buf);
1367
1368 return ret;
1369}
1370#endif
1371
576eeee9
EP
1372#define PRINT_MVM_REF(ref) do { \
1373 if (mvm->refs[ref]) \
1374 pos += scnprintf(buf + pos, bufsz - pos, \
1375 "\t(0x%lx): %d %s\n", \
1376 BIT(ref), mvm->refs[ref], #ref); \
70d6babb
EP
1377} while (0)
1378
1379static ssize_t iwl_dbgfs_d0i3_refs_read(struct file *file,
1380 char __user *user_buf,
1381 size_t count, loff_t *ppos)
1382{
1383 struct iwl_mvm *mvm = file->private_data;
576eeee9 1384 int i, pos = 0;
70d6babb
EP
1385 char buf[256];
1386 const size_t bufsz = sizeof(buf);
576eeee9
EP
1387 u32 refs = 0;
1388
1389 for (i = 0; i < IWL_MVM_REF_COUNT; i++)
1390 if (mvm->refs[i])
1391 refs |= BIT(i);
70d6babb 1392
576eeee9
EP
1393 pos += scnprintf(buf + pos, bufsz - pos, "taken mvm refs: 0x%x\n",
1394 refs);
70d6babb
EP
1395
1396 PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN);
1397 PRINT_MVM_REF(IWL_MVM_REF_SCAN);
1398 PRINT_MVM_REF(IWL_MVM_REF_ROC);
c779273b 1399 PRINT_MVM_REF(IWL_MVM_REF_ROC_AUX);
70d6babb
EP
1400 PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT);
1401 PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS);
0eb83653 1402 PRINT_MVM_REF(IWL_MVM_REF_USER);
34e611ea
JB
1403 PRINT_MVM_REF(IWL_MVM_REF_TX);
1404 PRINT_MVM_REF(IWL_MVM_REF_TX_AGG);
1405 PRINT_MVM_REF(IWL_MVM_REF_ADD_IF);
1406 PRINT_MVM_REF(IWL_MVM_REF_START_AP);
1407 PRINT_MVM_REF(IWL_MVM_REF_BSS_CHANGED);
1408 PRINT_MVM_REF(IWL_MVM_REF_PREPARE_TX);
1409 PRINT_MVM_REF(IWL_MVM_REF_PROTECT_TDLS);
1410 PRINT_MVM_REF(IWL_MVM_REF_CHECK_CTKILL);
1411 PRINT_MVM_REF(IWL_MVM_REF_PRPH_READ);
1412 PRINT_MVM_REF(IWL_MVM_REF_PRPH_WRITE);
1413 PRINT_MVM_REF(IWL_MVM_REF_NMI);
1414 PRINT_MVM_REF(IWL_MVM_REF_TM_CMD);
d15a747f 1415 PRINT_MVM_REF(IWL_MVM_REF_EXIT_WORK);
160acc0e 1416 PRINT_MVM_REF(IWL_MVM_REF_PROTECT_CSA);
fb2380a2 1417 PRINT_MVM_REF(IWL_MVM_REF_FW_DBG_COLLECT);
08f0d23d 1418 PRINT_MVM_REF(IWL_MVM_REF_INIT_UCODE);
70d6babb
EP
1419
1420 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1421}
1422
0eb83653
EP
1423static ssize_t iwl_dbgfs_d0i3_refs_write(struct iwl_mvm *mvm, char *buf,
1424 size_t count, loff_t *ppos)
1425{
1426 unsigned long value;
1427 int ret;
1428 bool taken;
1429
1430 ret = kstrtoul(buf, 10, &value);
1431 if (ret < 0)
1432 return ret;
1433
1434 mutex_lock(&mvm->mutex);
1435
576eeee9 1436 taken = mvm->refs[IWL_MVM_REF_USER];
0eb83653
EP
1437 if (value == 1 && !taken)
1438 iwl_mvm_ref(mvm, IWL_MVM_REF_USER);
1439 else if (value == 0 && taken)
1440 iwl_mvm_unref(mvm, IWL_MVM_REF_USER);
1441 else
1442 ret = -EINVAL;
1443
1444 mutex_unlock(&mvm->mutex);
1445
1446 if (ret < 0)
1447 return ret;
1448 return count;
1449}
1450
1fa3f57a
JB
1451#define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
1452 _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1453#define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
1454 _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
de06a59e
EP
1455#define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \
1456 if (!debugfs_create_file(alias, mode, parent, mvm, \
8ca151b5
JB
1457 &iwl_dbgfs_##name##_ops)) \
1458 goto err; \
1459 } while (0)
de06a59e
EP
1460#define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
1461 MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
8ca151b5 1462
f3c221f6
EP
1463static ssize_t
1464iwl_dbgfs_prph_reg_read(struct file *file,
1465 char __user *user_buf,
1466 size_t count, loff_t *ppos)
1467{
1468 struct iwl_mvm *mvm = file->private_data;
1469 int pos = 0;
1470 char buf[32];
1471 const size_t bufsz = sizeof(buf);
576eeee9 1472 int ret;
f3c221f6
EP
1473
1474 if (!mvm->dbgfs_prph_reg_addr)
1475 return -EINVAL;
1476
576eeee9
EP
1477 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_READ);
1478 if (ret)
1479 return ret;
1480
f3c221f6
EP
1481 pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n",
1482 mvm->dbgfs_prph_reg_addr,
1483 iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr));
1484
576eeee9
EP
1485 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_READ);
1486
f3c221f6
EP
1487 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1488}
1489
1490static ssize_t
1491iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf,
1492 size_t count, loff_t *ppos)
1493{
1494 u8 args;
1495 u32 value;
576eeee9 1496 int ret;
f3c221f6
EP
1497
1498 args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value);
1499 /* if we only want to set the reg address - nothing more to do */
1500 if (args == 1)
1501 goto out;
1502
1503 /* otherwise, make sure we have both address and value */
1504 if (args != 2)
1505 return -EINVAL;
1506
576eeee9
EP
1507 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
1508 if (ret)
1509 return ret;
1510
f3c221f6 1511 iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value);
576eeee9
EP
1512
1513 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
f3c221f6
EP
1514out:
1515 return count;
1516}
1517
e5046019
EG
1518static ssize_t
1519iwl_dbgfs_send_echo_cmd_write(struct iwl_mvm *mvm, char *buf,
1520 size_t count, loff_t *ppos)
1521{
1522 int ret;
1523
1524 mutex_lock(&mvm->mutex);
1525 ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL);
1526 mutex_unlock(&mvm->mutex);
1527
1528 return ret ?: count;
1529}
1530
f3c221f6
EP
1531MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);
1532
8ca151b5 1533/* Device wide debugfs entries */
00f481bd
CRI
1534MVM_DEBUGFS_READ_FILE_OPS(ctdp_budget);
1535MVM_DEBUGFS_WRITE_FILE_OPS(stop_ctdp, 8);
1fa3f57a
JB
1536MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
1537MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
e5046019 1538MVM_DEBUGFS_WRITE_FILE_OPS(send_echo_cmd, 8);
1fa3f57a 1539MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64);
7280d1f0 1540MVM_DEBUGFS_READ_WRITE_FILE_OPS(set_nic_temperature, 64);
c549e390 1541MVM_DEBUGFS_READ_FILE_OPS(nic_temp);
8ca151b5 1542MVM_DEBUGFS_READ_FILE_OPS(stations);
10942342 1543MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
2de13cae 1544MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
1fa3f57a 1545MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64);
3848ab66 1546MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
5fc0f76c 1547MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats);
1fa3f57a
JB
1548MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10);
1549MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10);
cdb00563 1550MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10);
a39979a8 1551MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant, 10);
1fa3f57a 1552MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
0eb83653 1553MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8);
8c23f95c 1554MVM_DEBUGFS_READ_WRITE_FILE_OPS(fw_dbg_conf, 8);
c91b865c 1555MVM_DEBUGFS_WRITE_FILE_OPS(fw_dbg_collect, 64);
321c2104 1556MVM_DEBUGFS_WRITE_FILE_OPS(cont_recording, 8);
9e7dce28 1557MVM_DEBUGFS_WRITE_FILE_OPS(max_amsdu_len, 8);
dd4d3161
SS
1558MVM_DEBUGFS_WRITE_FILE_OPS(indirection_tbl,
1559 (IWL_RSS_INDIRECTION_TABLE_SIZE * 2));
91b05d10 1560
de06a59e
EP
1561#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1562MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256);
1563MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256);
1564#endif
1565
afc66bb7 1566#ifdef CONFIG_PM_SLEEP
1fa3f57a 1567MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8);
afc66bb7 1568#endif
8ca151b5
JB
1569
1570int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
1571{
de06a59e 1572 struct dentry *bcast_dir __maybe_unused;
8ca151b5
JB
1573 char buf[100];
1574
d07913aa
JB
1575 spin_lock_init(&mvm->drv_stats_lock);
1576
8ca151b5
JB
1577 mvm->debugfs_dir = dbgfs_dir;
1578
1579 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
1580 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
1581 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
7280d1f0
MG
1582 MVM_DEBUGFS_ADD_FILE(set_nic_temperature, mvm->debugfs_dir,
1583 S_IWUSR | S_IRUSR);
c549e390 1584 MVM_DEBUGFS_ADD_FILE(nic_temp, dbgfs_dir, S_IRUSR);
00f481bd
CRI
1585 MVM_DEBUGFS_ADD_FILE(ctdp_budget, dbgfs_dir, S_IRUSR);
1586 MVM_DEBUGFS_ADD_FILE(stop_ctdp, dbgfs_dir, S_IWUSR);
8ca151b5 1587 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
10942342 1588 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
2de13cae 1589 MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
639eabad
EG
1590 MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
1591 S_IRUSR | S_IWUSR);
3848ab66 1592 MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
5fc0f76c 1593 MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, S_IRUSR);
490953ac 1594 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
119663c3 1595 MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR);
cdb00563 1596 MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, S_IWUSR);
a39979a8 1597 MVM_DEBUGFS_ADD_FILE(bt_force_ant, mvm->debugfs_dir, S_IWUSR);
91b05d10
OG
1598 MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
1599 S_IWUSR | S_IRUSR);
f3c221f6 1600 MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
0eb83653 1601 MVM_DEBUGFS_ADD_FILE(d0i3_refs, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
8c23f95c
EG
1602 MVM_DEBUGFS_ADD_FILE(fw_dbg_conf, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
1603 MVM_DEBUGFS_ADD_FILE(fw_dbg_collect, mvm->debugfs_dir, S_IWUSR);
9e7dce28 1604 MVM_DEBUGFS_ADD_FILE(max_amsdu_len, mvm->debugfs_dir, S_IWUSR);
e5046019 1605 MVM_DEBUGFS_ADD_FILE(send_echo_cmd, mvm->debugfs_dir, S_IWUSR);
321c2104 1606 MVM_DEBUGFS_ADD_FILE(cont_recording, mvm->debugfs_dir, S_IWUSR);
43413a97 1607 MVM_DEBUGFS_ADD_FILE(indirection_tbl, mvm->debugfs_dir, S_IWUSR);
cb2513bb
LC
1608 if (!debugfs_create_bool("enable_scan_iteration_notif",
1609 S_IRUSR | S_IWUSR,
1610 mvm->debugfs_dir,
1611 &mvm->scan_iter_notif_enabled))
1612 goto err;
c89e333d
AO
1613 if (!debugfs_create_bool("drop_bcn_ap_mode", S_IRUSR | S_IWUSR,
1614 mvm->debugfs_dir, &mvm->drop_bcn_ap_mode))
1615 goto err;
de06a59e
EP
1616
1617#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1618 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING) {
1619 bcast_dir = debugfs_create_dir("bcast_filtering",
1620 mvm->debugfs_dir);
1621 if (!bcast_dir)
1622 goto err;
1623
1624 if (!debugfs_create_bool("override", S_IRUSR | S_IWUSR,
1625 bcast_dir,
1626 &mvm->dbgfs_bcast_filtering.override))
1627 goto err;
1628
1629 MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters,
1630 bcast_dir, S_IWUSR | S_IRUSR);
1631 MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs,
1632 bcast_dir, S_IWUSR | S_IRUSR);
1633 }
1634#endif
1635
afc66bb7
JB
1636#ifdef CONFIG_PM_SLEEP
1637 MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
debff618 1638 MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
b0114714
JB
1639 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
1640 mvm->debugfs_dir, &mvm->d3_wake_sysassert))
1641 goto err;
484b3d13
LC
1642 if (!debugfs_create_u32("last_netdetect_scans", S_IRUSR,
1643 mvm->debugfs_dir, &mvm->last_netdetect_scans))
1644 goto err;
afc66bb7 1645#endif
8ca151b5 1646
bdd54839
LC
1647 if (!debugfs_create_u8("ps_disabled", S_IRUSR,
1648 mvm->debugfs_dir, &mvm->ps_disabled))
1649 goto err;
086f7368
EG
1650 if (!debugfs_create_blob("nvm_hw", S_IRUSR,
1651 mvm->debugfs_dir, &mvm->nvm_hw_blob))
1652 goto err;
1653 if (!debugfs_create_blob("nvm_sw", S_IRUSR,
1654 mvm->debugfs_dir, &mvm->nvm_sw_blob))
1655 goto err;
1656 if (!debugfs_create_blob("nvm_calib", S_IRUSR,
1657 mvm->debugfs_dir, &mvm->nvm_calib_blob))
1658 goto err;
1659 if (!debugfs_create_blob("nvm_prod", S_IRUSR,
1660 mvm->debugfs_dir, &mvm->nvm_prod_blob))
1661 goto err;
91fac940
MH
1662 if (!debugfs_create_blob("nvm_phy_sku", S_IRUSR,
1663 mvm->debugfs_dir, &mvm->nvm_phy_sku_blob))
1664 goto err;
086f7368 1665
8ca151b5
JB
1666 /*
1667 * Create a symlink with mac80211. It will be removed when mac80211
1668 * exists (before the opmode exists which removes the target.)
1669 */
1670 snprintf(buf, 100, "../../%s/%s",
1671 dbgfs_dir->d_parent->d_parent->d_name.name,
1672 dbgfs_dir->d_parent->d_name.name);
1673 if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
1674 goto err;
1675
1676 return 0;
1677err:
1678 IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
1679 return -ENOMEM;
1680}
This page took 0.259414 seconds and 5 git commands to generate.