iwlwifi: mvm: BT Coex - add High Band retention
[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 *
51368bf7 8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
8ca151b5
JB
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 *
51368bf7 33 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
8ca151b5
JB
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 *****************************************************************************/
192c80a2
EG
63#include <linux/vmalloc.h>
64
8ca151b5
JB
65#include "mvm.h"
66#include "sta.h"
67#include "iwl-io.h"
820a1a50 68#include "debugfs.h"
4d075007 69#include "iwl-fw-error-dump.h"
8ca151b5 70
1fa3f57a 71static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf,
8ca151b5
JB
72 size_t count, loff_t *ppos)
73{
8a0bd168 74 int ret;
8ca151b5
JB
75 u32 scd_q_msk;
76
77 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
78 return -EIO;
79
8ca151b5
JB
80 if (sscanf(buf, "%x", &scd_q_msk) != 1)
81 return -EINVAL;
82
83 IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk);
84
85 mutex_lock(&mvm->mutex);
86 ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, true) ? : count;
87 mutex_unlock(&mvm->mutex);
88
89 return ret;
90}
91
1fa3f57a 92static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf,
8ca151b5
JB
93 size_t count, loff_t *ppos)
94{
f327b04c 95 struct iwl_mvm_sta *mvmsta;
8a0bd168 96 int sta_id, drain, ret;
8ca151b5
JB
97
98 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
99 return -EIO;
100
8ca151b5
JB
101 if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
102 return -EINVAL;
60765a47
JB
103 if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
104 return -EINVAL;
105 if (drain < 0 || drain > 1)
106 return -EINVAL;
8ca151b5
JB
107
108 mutex_lock(&mvm->mutex);
109
f327b04c
EG
110 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
111
112 if (!mvmsta)
8ca151b5
JB
113 ret = -ENOENT;
114 else
f327b04c 115 ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count;
8ca151b5
JB
116
117 mutex_unlock(&mvm->mutex);
118
119 return ret;
120}
121
1bd3cbc1
EG
122static int iwl_dbgfs_fw_error_dump_open(struct inode *inode, struct file *file)
123{
124 struct iwl_mvm *mvm = inode->i_private;
125 int ret;
126
127 if (!mvm)
128 return -EINVAL;
129
130 mutex_lock(&mvm->mutex);
131 if (!mvm->fw_error_dump) {
132 ret = -ENODATA;
133 goto out;
134 }
135
136 file->private_data = mvm->fw_error_dump;
137 mvm->fw_error_dump = NULL;
1bd3cbc1
EG
138 ret = 0;
139
140out:
141 mutex_unlock(&mvm->mutex);
142 return ret;
143}
144
145static ssize_t iwl_dbgfs_fw_error_dump_read(struct file *file,
146 char __user *user_buf,
147 size_t count, loff_t *ppos)
148{
149 struct iwl_fw_error_dump_file *dump_file = file->private_data;
150
151 return simple_read_from_buffer(user_buf, count, ppos,
152 dump_file,
153 le32_to_cpu(dump_file->file_len));
154}
155
156static int iwl_dbgfs_fw_error_dump_release(struct inode *inode,
157 struct file *file)
158{
159 vfree(file->private_data);
160
161 return 0;
162}
163
8ca151b5
JB
164static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
165 size_t count, loff_t *ppos)
166{
167 struct iwl_mvm *mvm = file->private_data;
168 const struct fw_img *img;
d510342f
EG
169 unsigned int ofs, len;
170 size_t ret;
8ca151b5
JB
171 u8 *ptr;
172
60191d99
JB
173 if (!mvm->ucode_loaded)
174 return -EINVAL;
175
8ca151b5 176 /* default is to dump the entire data segment */
d510342f
EG
177 img = &mvm->fw->img[mvm->cur_ucode];
178 ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
179 len = img->sec[IWL_UCODE_SECTION_DATA].len;
180
01e0efe3 181 if (mvm->dbgfs_sram_len) {
60191d99
JB
182 ofs = mvm->dbgfs_sram_offset;
183 len = mvm->dbgfs_sram_len;
8ca151b5 184 }
8ca151b5 185
8ca151b5 186 ptr = kzalloc(len, GFP_KERNEL);
d510342f 187 if (!ptr)
8ca151b5 188 return -ENOMEM;
8ca151b5 189
60191d99 190 iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
8ca151b5 191
d510342f 192 ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len);
8ca151b5 193
8ca151b5
JB
194 kfree(ptr);
195
196 return ret;
197}
198
1fa3f57a
JB
199static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf,
200 size_t count, loff_t *ppos)
8ca151b5 201{
d510342f 202 const struct fw_img *img;
8ca151b5 203 u32 offset, len;
d510342f
EG
204 u32 img_offset, img_len;
205
206 if (!mvm->ucode_loaded)
207 return -EINVAL;
208
209 img = &mvm->fw->img[mvm->cur_ucode];
210 img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset;
211 img_len = img->sec[IWL_UCODE_SECTION_DATA].len;
8ca151b5 212
8ca151b5
JB
213 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
214 if ((offset & 0x3) || (len & 0x3))
215 return -EINVAL;
d510342f
EG
216
217 if (offset + len > img_offset + img_len)
218 return -EINVAL;
219
8ca151b5
JB
220 mvm->dbgfs_sram_offset = offset;
221 mvm->dbgfs_sram_len = len;
222 } else {
223 mvm->dbgfs_sram_offset = 0;
224 mvm->dbgfs_sram_len = 0;
225 }
226
227 return count;
228}
229
230static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
231 size_t count, loff_t *ppos)
232{
233 struct iwl_mvm *mvm = file->private_data;
234 struct ieee80211_sta *sta;
235 char buf[400];
236 int i, pos = 0, bufsz = sizeof(buf);
237
238 mutex_lock(&mvm->mutex);
239
240 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
241 pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
242 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
243 lockdep_is_held(&mvm->mutex));
244 if (!sta)
245 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
246 else if (IS_ERR(sta))
247 pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
248 PTR_ERR(sta));
249 else
250 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
251 sta->addr);
252 }
253
254 mutex_unlock(&mvm->mutex);
255
256 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
257}
258
64b928c4
AB
259static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
260 char __user *user_buf,
8ca151b5
JB
261 size_t count, loff_t *ppos)
262{
263 struct iwl_mvm *mvm = file->private_data;
64b928c4
AB
264 char buf[64];
265 int bufsz = sizeof(buf);
266 int pos = 0;
8ca151b5 267
64b928c4
AB
268 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
269 mvm->disable_power_off);
270 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
271 mvm->disable_power_off_d3);
8ca151b5 272
64b928c4 273 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
8ca151b5
JB
274}
275
1fa3f57a 276static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf,
64b928c4 277 size_t count, loff_t *ppos)
8ca151b5 278{
1fa3f57a 279 int ret, val;
64b928c4
AB
280
281 if (!mvm->ucode_loaded)
282 return -EIO;
8ca151b5 283
64b928c4
AB
284 if (!strncmp("disable_power_off_d0=", buf, 21)) {
285 if (sscanf(buf + 21, "%d", &val) != 1)
286 return -EINVAL;
287 mvm->disable_power_off = val;
288 } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
289 if (sscanf(buf + 21, "%d", &val) != 1)
290 return -EINVAL;
291 mvm->disable_power_off_d3 = val;
292 } else {
8ca151b5 293 return -EINVAL;
64b928c4 294 }
8ca151b5 295
64b928c4 296 mutex_lock(&mvm->mutex);
c1cb92fc 297 ret = iwl_mvm_power_update_device(mvm);
64b928c4 298 mutex_unlock(&mvm->mutex);
8ca151b5 299
64b928c4 300 return ret ?: count;
8ca151b5
JB
301}
302
10942342
EG
303#define BT_MBOX_MSG(_notif, _num, _field) \
304 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
305 >> BT_MBOX##_num##_##_field##_POS)
306
307
308#define BT_MBOX_PRINT(_num, _field, _end) \
309 pos += scnprintf(buf + pos, bufsz - pos, \
310 "\t%s: %d%s", \
311 #_field, \
312 BT_MBOX_MSG(notif, _num, _field), \
313 true ? "\n" : ", ");
314
315static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
316 size_t count, loff_t *ppos)
317{
318 struct iwl_mvm *mvm = file->private_data;
430a3bba 319 struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
10942342
EG
320 char *buf;
321 int ret, pos = 0, bufsz = sizeof(char) * 1024;
322
323 buf = kmalloc(bufsz, GFP_KERNEL);
324 if (!buf)
325 return -ENOMEM;
326
327 mutex_lock(&mvm->mutex);
328
329 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
330
331 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
332 BT_MBOX_PRINT(0, LE_PROF1, false);
333 BT_MBOX_PRINT(0, LE_PROF2, false);
334 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
335 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
336 BT_MBOX_PRINT(0, INBAND_S, false);
337 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
338 BT_MBOX_PRINT(0, LE_SCAN, false);
339 BT_MBOX_PRINT(0, LE_ADV, false);
340 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
341 BT_MBOX_PRINT(0, OPEN_CON_1, true);
342
343 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
344
345 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
346 BT_MBOX_PRINT(1, IP_SR, false);
347 BT_MBOX_PRINT(1, LE_MSTR, false);
348 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
349 BT_MBOX_PRINT(1, MSG_TYPE, false);
350 BT_MBOX_PRINT(1, SSN, true);
351
352 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
353
354 BT_MBOX_PRINT(2, SNIFF_ACT, false);
355 BT_MBOX_PRINT(2, PAG, false);
356 BT_MBOX_PRINT(2, INQUIRY, false);
357 BT_MBOX_PRINT(2, CONN, false);
358 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
359 BT_MBOX_PRINT(2, DISC, false);
360 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
361 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
362 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
363 BT_MBOX_PRINT(2, SCO_DURATION, true);
364
365 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
366
367 BT_MBOX_PRINT(3, SCO_STATE, false);
368 BT_MBOX_PRINT(3, SNIFF_STATE, false);
369 BT_MBOX_PRINT(3, A2DP_STATE, false);
370 BT_MBOX_PRINT(3, ACL_STATE, false);
371 BT_MBOX_PRINT(3, MSTR_STATE, false);
372 BT_MBOX_PRINT(3, OBX_STATE, false);
373 BT_MBOX_PRINT(3, OPEN_CON_2, false);
374 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
375 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
376 BT_MBOX_PRINT(3, INBAND_P, false);
377 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
378 BT_MBOX_PRINT(3, SSN_2, false);
379 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
380
10942342 381 pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
2de13cae
EG
382 notif->bt_ci_compliance);
383 pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
384 le32_to_cpu(notif->primary_ch_lut));
385 pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
386 le32_to_cpu(notif->secondary_ch_lut));
387 pos += scnprintf(buf+pos, bufsz-pos, "bt_activity_grading = %d\n",
388 le32_to_cpu(notif->bt_activity_grading));
b9fae2d5
EG
389 pos += scnprintf(buf+pos, bufsz-pos,
390 "antenna isolation = %d CORUN LUT index = %d\n",
391 mvm->last_ant_isol, mvm->last_corun_lut);
10942342
EG
392
393 mutex_unlock(&mvm->mutex);
394
395 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
396 kfree(buf);
397
398 return ret;
399}
400#undef BT_MBOX_PRINT
401
2de13cae
EG
402static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
403 size_t count, loff_t *ppos)
404{
405 struct iwl_mvm *mvm = file->private_data;
430a3bba 406 struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
2de13cae
EG
407 char buf[256];
408 int bufsz = sizeof(buf);
409 int pos = 0;
410
411 mutex_lock(&mvm->mutex);
412
413 pos += scnprintf(buf+pos, bufsz-pos, "Channel inhibition CMD\n");
414 pos += scnprintf(buf+pos, bufsz-pos,
430a3bba
EG
415 "\tPrimary Channel Bitmap 0x%016llx\n",
416 le64_to_cpu(cmd->bt_primary_ci));
2de13cae 417 pos += scnprintf(buf+pos, bufsz-pos,
430a3bba
EG
418 "\tSecondary Channel Bitmap 0x%016llx\n",
419 le64_to_cpu(cmd->bt_secondary_ci));
2de13cae
EG
420
421 pos += scnprintf(buf+pos, bufsz-pos, "BT Configuration CMD\n");
422 pos += scnprintf(buf+pos, bufsz-pos, "\tACK Kill Mask 0x%08x\n",
423 iwl_bt_ack_kill_msk[mvm->bt_kill_msk]);
424 pos += scnprintf(buf+pos, bufsz-pos, "\tCTS Kill Mask 0x%08x\n",
425 iwl_bt_cts_kill_msk[mvm->bt_kill_msk]);
426
427 mutex_unlock(&mvm->mutex);
428
429 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
430}
431
cdb00563
EG
432static ssize_t
433iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf,
434 size_t count, loff_t *ppos)
435{
436 u32 bt_tx_prio;
437
438 if (sscanf(buf, "%u", &bt_tx_prio) != 1)
439 return -EINVAL;
440 if (bt_tx_prio > 4)
441 return -EINVAL;
442
443 mvm->bt_tx_prio = bt_tx_prio;
444
445 return count;
446}
447
a39979a8
EG
448static ssize_t
449iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char *buf,
450 size_t count, loff_t *ppos)
451{
452 static const char * const modes_str[BT_FORCE_ANT_MAX] = {
453 [BT_FORCE_ANT_DIS] = "dis",
454 [BT_FORCE_ANT_AUTO] = "auto",
455 [BT_FORCE_ANT_BT] = "bt",
456 [BT_FORCE_ANT_WIFI] = "wifi",
457 };
458 int ret, bt_force_ant_mode;
459
460 for (bt_force_ant_mode = 0;
461 bt_force_ant_mode < ARRAY_SIZE(modes_str);
462 bt_force_ant_mode++) {
463 if (!strcmp(buf, modes_str[bt_force_ant_mode]))
464 break;
465 }
466
467 if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
468 return -EINVAL;
469
470 ret = 0;
471 mutex_lock(&mvm->mutex);
472 if (mvm->bt_force_ant_mode == bt_force_ant_mode)
473 goto out;
474
475 mvm->bt_force_ant_mode = bt_force_ant_mode;
476 IWL_DEBUG_COEX(mvm, "Force mode: %s\n",
477 modes_str[mvm->bt_force_ant_mode]);
478 ret = iwl_send_bt_init_conf(mvm);
479
480out:
481 mutex_unlock(&mvm->mutex);
482 return ret ?: count;
483}
484
3848ab66
MG
485#define PRINT_STATS_LE32(_str, _val) \
486 pos += scnprintf(buf + pos, bufsz - pos, \
487 fmt_table, _str, \
488 le32_to_cpu(_val))
489
490static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
491 char __user *user_buf, size_t count,
492 loff_t *ppos)
493{
494 struct iwl_mvm *mvm = file->private_data;
495 static const char *fmt_table = "\t%-30s %10u\n";
496 static const char *fmt_header = "%-32s\n";
497 int pos = 0;
498 char *buf;
499 int ret;
3f617281
LC
500 /* 43 is the size of each data line, 33 is the size of each header */
501 size_t bufsz =
502 ((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) +
503 (4 * 33) + 1;
504
3848ab66
MG
505 struct mvm_statistics_rx_phy *ofdm;
506 struct mvm_statistics_rx_phy *cck;
507 struct mvm_statistics_rx_non_phy *general;
508 struct mvm_statistics_rx_ht_phy *ht;
509
510 buf = kzalloc(bufsz, GFP_KERNEL);
511 if (!buf)
512 return -ENOMEM;
513
514 mutex_lock(&mvm->mutex);
515
516 ofdm = &mvm->rx_stats.ofdm;
517 cck = &mvm->rx_stats.cck;
518 general = &mvm->rx_stats.general;
519 ht = &mvm->rx_stats.ofdm_ht;
520
521 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
522 "Statistics_Rx - OFDM");
523 PRINT_STATS_LE32("ina_cnt", ofdm->ina_cnt);
524 PRINT_STATS_LE32("fina_cnt", ofdm->fina_cnt);
525 PRINT_STATS_LE32("plcp_err", ofdm->plcp_err);
526 PRINT_STATS_LE32("crc32_err", ofdm->crc32_err);
527 PRINT_STATS_LE32("overrun_err", ofdm->overrun_err);
528 PRINT_STATS_LE32("early_overrun_err", ofdm->early_overrun_err);
529 PRINT_STATS_LE32("crc32_good", ofdm->crc32_good);
530 PRINT_STATS_LE32("false_alarm_cnt", ofdm->false_alarm_cnt);
531 PRINT_STATS_LE32("fina_sync_err_cnt", ofdm->fina_sync_err_cnt);
532 PRINT_STATS_LE32("sfd_timeout", ofdm->sfd_timeout);
533 PRINT_STATS_LE32("fina_timeout", ofdm->fina_timeout);
534 PRINT_STATS_LE32("unresponded_rts", ofdm->unresponded_rts);
535 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
536 ofdm->rxe_frame_limit_overrun);
537 PRINT_STATS_LE32("sent_ack_cnt", ofdm->sent_ack_cnt);
538 PRINT_STATS_LE32("sent_cts_cnt", ofdm->sent_cts_cnt);
539 PRINT_STATS_LE32("sent_ba_rsp_cnt", ofdm->sent_ba_rsp_cnt);
540 PRINT_STATS_LE32("dsp_self_kill", ofdm->dsp_self_kill);
541 PRINT_STATS_LE32("mh_format_err", ofdm->mh_format_err);
542 PRINT_STATS_LE32("re_acq_main_rssi_sum", ofdm->re_acq_main_rssi_sum);
543 PRINT_STATS_LE32("reserved", ofdm->reserved);
544
545 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
546 "Statistics_Rx - CCK");
547 PRINT_STATS_LE32("ina_cnt", cck->ina_cnt);
548 PRINT_STATS_LE32("fina_cnt", cck->fina_cnt);
549 PRINT_STATS_LE32("plcp_err", cck->plcp_err);
550 PRINT_STATS_LE32("crc32_err", cck->crc32_err);
551 PRINT_STATS_LE32("overrun_err", cck->overrun_err);
552 PRINT_STATS_LE32("early_overrun_err", cck->early_overrun_err);
553 PRINT_STATS_LE32("crc32_good", cck->crc32_good);
554 PRINT_STATS_LE32("false_alarm_cnt", cck->false_alarm_cnt);
555 PRINT_STATS_LE32("fina_sync_err_cnt", cck->fina_sync_err_cnt);
556 PRINT_STATS_LE32("sfd_timeout", cck->sfd_timeout);
557 PRINT_STATS_LE32("fina_timeout", cck->fina_timeout);
558 PRINT_STATS_LE32("unresponded_rts", cck->unresponded_rts);
559 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
560 cck->rxe_frame_limit_overrun);
561 PRINT_STATS_LE32("sent_ack_cnt", cck->sent_ack_cnt);
562 PRINT_STATS_LE32("sent_cts_cnt", cck->sent_cts_cnt);
563 PRINT_STATS_LE32("sent_ba_rsp_cnt", cck->sent_ba_rsp_cnt);
564 PRINT_STATS_LE32("dsp_self_kill", cck->dsp_self_kill);
565 PRINT_STATS_LE32("mh_format_err", cck->mh_format_err);
566 PRINT_STATS_LE32("re_acq_main_rssi_sum", cck->re_acq_main_rssi_sum);
567 PRINT_STATS_LE32("reserved", cck->reserved);
568
569 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
570 "Statistics_Rx - GENERAL");
571 PRINT_STATS_LE32("bogus_cts", general->bogus_cts);
572 PRINT_STATS_LE32("bogus_ack", general->bogus_ack);
573 PRINT_STATS_LE32("non_bssid_frames", general->non_bssid_frames);
574 PRINT_STATS_LE32("filtered_frames", general->filtered_frames);
575 PRINT_STATS_LE32("non_channel_beacons", general->non_channel_beacons);
576 PRINT_STATS_LE32("channel_beacons", general->channel_beacons);
577 PRINT_STATS_LE32("num_missed_bcon", general->num_missed_bcon);
578 PRINT_STATS_LE32("adc_rx_saturation_time",
579 general->adc_rx_saturation_time);
580 PRINT_STATS_LE32("ina_detection_search_time",
581 general->ina_detection_search_time);
582 PRINT_STATS_LE32("beacon_silence_rssi_a",
583 general->beacon_silence_rssi_a);
584 PRINT_STATS_LE32("beacon_silence_rssi_b",
585 general->beacon_silence_rssi_b);
586 PRINT_STATS_LE32("beacon_silence_rssi_c",
587 general->beacon_silence_rssi_c);
588 PRINT_STATS_LE32("interference_data_flag",
589 general->interference_data_flag);
590 PRINT_STATS_LE32("channel_load", general->channel_load);
591 PRINT_STATS_LE32("dsp_false_alarms", general->dsp_false_alarms);
592 PRINT_STATS_LE32("beacon_rssi_a", general->beacon_rssi_a);
593 PRINT_STATS_LE32("beacon_rssi_b", general->beacon_rssi_b);
594 PRINT_STATS_LE32("beacon_rssi_c", general->beacon_rssi_c);
595 PRINT_STATS_LE32("beacon_energy_a", general->beacon_energy_a);
596 PRINT_STATS_LE32("beacon_energy_b", general->beacon_energy_b);
597 PRINT_STATS_LE32("beacon_energy_c", general->beacon_energy_c);
598 PRINT_STATS_LE32("num_bt_kills", general->num_bt_kills);
3f617281 599 PRINT_STATS_LE32("mac_id", general->mac_id);
3848ab66
MG
600 PRINT_STATS_LE32("directed_data_mpdu", general->directed_data_mpdu);
601
602 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
603 "Statistics_Rx - HT");
604 PRINT_STATS_LE32("plcp_err", ht->plcp_err);
605 PRINT_STATS_LE32("overrun_err", ht->overrun_err);
606 PRINT_STATS_LE32("early_overrun_err", ht->early_overrun_err);
607 PRINT_STATS_LE32("crc32_good", ht->crc32_good);
608 PRINT_STATS_LE32("crc32_err", ht->crc32_err);
609 PRINT_STATS_LE32("mh_format_err", ht->mh_format_err);
610 PRINT_STATS_LE32("agg_crc32_good", ht->agg_crc32_good);
611 PRINT_STATS_LE32("agg_mpdu_cnt", ht->agg_mpdu_cnt);
612 PRINT_STATS_LE32("agg_cnt", ht->agg_cnt);
613 PRINT_STATS_LE32("unsupport_mcs", ht->unsupport_mcs);
614
615 mutex_unlock(&mvm->mutex);
616
617 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
618 kfree(buf);
619
620 return ret;
621}
622#undef PRINT_STAT_LE32
623
5fc0f76c
ES
624static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm,
625 char __user *user_buf, size_t count,
626 loff_t *ppos,
627 struct iwl_mvm_frame_stats *stats)
628{
f754b5ca
ES
629 char *buff, *pos, *endpos;
630 int idx, i;
5fc0f76c 631 int ret;
f754b5ca 632 static const size_t bufsz = 1024;
5fc0f76c
ES
633
634 buff = kmalloc(bufsz, GFP_KERNEL);
635 if (!buff)
636 return -ENOMEM;
637
638 spin_lock_bh(&mvm->drv_stats_lock);
f754b5ca
ES
639
640 pos = buff;
641 endpos = pos + bufsz;
642
643 pos += scnprintf(pos, endpos - pos,
5fc0f76c
ES
644 "Legacy/HT/VHT\t:\t%d/%d/%d\n",
645 stats->legacy_frames,
646 stats->ht_frames,
647 stats->vht_frames);
f754b5ca 648 pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n",
5fc0f76c
ES
649 stats->bw_20_frames,
650 stats->bw_40_frames,
651 stats->bw_80_frames);
f754b5ca 652 pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n",
5fc0f76c
ES
653 stats->ngi_frames,
654 stats->sgi_frames);
f754b5ca 655 pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n",
5fc0f76c
ES
656 stats->siso_frames,
657 stats->mimo2_frames);
f754b5ca 658 pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n",
5fc0f76c
ES
659 stats->fail_frames,
660 stats->success_frames);
f754b5ca 661 pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n",
5fc0f76c 662 stats->agg_frames);
f754b5ca 663 pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n",
5fc0f76c 664 stats->ampdu_count);
f754b5ca 665 pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n",
5fc0f76c
ES
666 stats->ampdu_count > 0 ?
667 (stats->agg_frames / stats->ampdu_count) : 0);
668
f754b5ca 669 pos += scnprintf(pos, endpos - pos, "Last Rates\n");
5fc0f76c
ES
670
671 idx = stats->last_frame_idx - 1;
672 for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) {
673 idx = (idx + 1) % ARRAY_SIZE(stats->last_rates);
674 if (stats->last_rates[idx] == 0)
675 continue;
f754b5ca 676 pos += scnprintf(pos, endpos - pos, "Rate[%d]: ",
5fc0f76c 677 (int)(ARRAY_SIZE(stats->last_rates) - i));
f754b5ca 678 pos += rs_pretty_print_rate(pos, stats->last_rates[idx]);
5fc0f76c
ES
679 }
680 spin_unlock_bh(&mvm->drv_stats_lock);
681
f754b5ca 682 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
5fc0f76c
ES
683 kfree(buff);
684
685 return ret;
686}
687
688static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file,
689 char __user *user_buf, size_t count,
690 loff_t *ppos)
691{
692 struct iwl_mvm *mvm = file->private_data;
693
694 return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos,
695 &mvm->drv_rx_stats);
696}
697
1fa3f57a 698static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
490953ac
EG
699 size_t count, loff_t *ppos)
700{
490953ac
EG
701 int ret;
702
490953ac
EG
703 mutex_lock(&mvm->mutex);
704
291aa7c4
EH
705 /* allow one more restart that we're provoking here */
706 if (mvm->restart_fw >= 0)
707 mvm->restart_fw++;
708
490953ac 709 /* take the return value to make compiler happy - it will fail anyway */
a1022927 710 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, 0, 0, NULL);
490953ac
EG
711
712 mutex_unlock(&mvm->mutex);
713
490953ac
EG
714 return count;
715}
716
1fa3f57a 717static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
119663c3
AB
718 size_t count, loff_t *ppos)
719{
4c9706dc 720 iwl_force_nmi(mvm->trans);
119663c3
AB
721
722 return count;
723}
724
91b05d10
OG
725static ssize_t
726iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
727 char __user *user_buf,
728 size_t count, loff_t *ppos)
729{
730 struct iwl_mvm *mvm = file->private_data;
731 int pos = 0;
732 char buf[32];
733 const size_t bufsz = sizeof(buf);
734
735 /* print which antennas were set for the scan command by the user */
736 pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
737 if (mvm->scan_rx_ant & ANT_A)
738 pos += scnprintf(buf + pos, bufsz - pos, "A");
739 if (mvm->scan_rx_ant & ANT_B)
740 pos += scnprintf(buf + pos, bufsz - pos, "B");
741 if (mvm->scan_rx_ant & ANT_C)
742 pos += scnprintf(buf + pos, bufsz - pos, "C");
743 pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
744
745 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
746}
747
748static ssize_t
1fa3f57a 749iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
91b05d10
OG
750 size_t count, loff_t *ppos)
751{
91b05d10
OG
752 u8 scan_rx_ant;
753
91b05d10
OG
754 if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
755 return -EINVAL;
756 if (scan_rx_ant > ANT_ABC)
757 return -EINVAL;
4ed735e7 758 if (scan_rx_ant & ~mvm->fw->valid_rx_ant)
91b05d10
OG
759 return -EINVAL;
760
91b05d10
OG
761 mvm->scan_rx_ant = scan_rx_ant;
762
763 return count;
764}
765
de06a59e
EP
766#define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__)
767#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
768static ssize_t iwl_dbgfs_bcast_filters_read(struct file *file,
769 char __user *user_buf,
770 size_t count, loff_t *ppos)
771{
772 struct iwl_mvm *mvm = file->private_data;
773 struct iwl_bcast_filter_cmd cmd;
774 const struct iwl_fw_bcast_filter *filter;
775 char *buf;
776 int bufsz = 1024;
777 int i, j, pos = 0;
778 ssize_t ret;
779
780 buf = kzalloc(bufsz, GFP_KERNEL);
781 if (!buf)
782 return -ENOMEM;
783
784 mutex_lock(&mvm->mutex);
785 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
786 ADD_TEXT("None\n");
787 mutex_unlock(&mvm->mutex);
788 goto out;
789 }
790 mutex_unlock(&mvm->mutex);
791
792 for (i = 0; cmd.filters[i].attrs[0].mask; i++) {
793 filter = &cmd.filters[i];
794
795 ADD_TEXT("Filter [%d]:\n", i);
796 ADD_TEXT("\tDiscard=%d\n", filter->discard);
797 ADD_TEXT("\tFrame Type: %s\n",
798 filter->frame_type ? "IPv4" : "Generic");
799
800 for (j = 0; j < ARRAY_SIZE(filter->attrs); j++) {
801 const struct iwl_fw_bcast_filter_attr *attr;
802
803 attr = &filter->attrs[j];
804 if (!attr->mask)
805 break;
806
807 ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n",
808 j, attr->offset,
809 attr->offset_type ? "IP End" :
810 "Payload Start",
811 be32_to_cpu(attr->mask),
812 be32_to_cpu(attr->val),
813 le16_to_cpu(attr->reserved1));
814 }
815 }
816out:
817 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
818 kfree(buf);
819 return ret;
820}
821
822static ssize_t iwl_dbgfs_bcast_filters_write(struct iwl_mvm *mvm, char *buf,
823 size_t count, loff_t *ppos)
824{
825 int pos, next_pos;
826 struct iwl_fw_bcast_filter filter = {};
827 struct iwl_bcast_filter_cmd cmd;
828 u32 filter_id, attr_id, mask, value;
829 int err = 0;
830
831 if (sscanf(buf, "%d %hhi %hhi %n", &filter_id, &filter.discard,
832 &filter.frame_type, &pos) != 3)
833 return -EINVAL;
834
835 if (filter_id >= ARRAY_SIZE(mvm->dbgfs_bcast_filtering.cmd.filters) ||
836 filter.frame_type > BCAST_FILTER_FRAME_TYPE_IPV4)
837 return -EINVAL;
838
839 for (attr_id = 0; attr_id < ARRAY_SIZE(filter.attrs);
840 attr_id++) {
841 struct iwl_fw_bcast_filter_attr *attr =
842 &filter.attrs[attr_id];
843
844 if (pos >= count)
845 break;
846
847 if (sscanf(&buf[pos], "%hhi %hhi %i %i %n",
848 &attr->offset, &attr->offset_type,
849 &mask, &value, &next_pos) != 4)
850 return -EINVAL;
851
852 attr->mask = cpu_to_be32(mask);
853 attr->val = cpu_to_be32(value);
854 if (mask)
855 filter.num_attrs++;
856
857 pos += next_pos;
858 }
859
860 mutex_lock(&mvm->mutex);
861 memcpy(&mvm->dbgfs_bcast_filtering.cmd.filters[filter_id],
862 &filter, sizeof(filter));
863
864 /* send updated bcast filtering configuration */
865 if (mvm->dbgfs_bcast_filtering.override &&
866 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
a1022927 867 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
de06a59e
EP
868 sizeof(cmd), &cmd);
869 mutex_unlock(&mvm->mutex);
870
871 return err ?: count;
872}
873
874static ssize_t iwl_dbgfs_bcast_filters_macs_read(struct file *file,
875 char __user *user_buf,
876 size_t count, loff_t *ppos)
877{
878 struct iwl_mvm *mvm = file->private_data;
879 struct iwl_bcast_filter_cmd cmd;
880 char *buf;
881 int bufsz = 1024;
882 int i, pos = 0;
883 ssize_t ret;
884
885 buf = kzalloc(bufsz, GFP_KERNEL);
886 if (!buf)
887 return -ENOMEM;
888
889 mutex_lock(&mvm->mutex);
890 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
891 ADD_TEXT("None\n");
892 mutex_unlock(&mvm->mutex);
893 goto out;
894 }
895 mutex_unlock(&mvm->mutex);
896
897 for (i = 0; i < ARRAY_SIZE(cmd.macs); i++) {
898 const struct iwl_fw_bcast_mac *mac = &cmd.macs[i];
899
900 ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n",
901 i, mac->default_discard, mac->attached_filters);
902 }
903out:
904 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
905 kfree(buf);
906 return ret;
907}
908
909static ssize_t iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm *mvm,
910 char *buf, size_t count,
911 loff_t *ppos)
912{
913 struct iwl_bcast_filter_cmd cmd;
914 struct iwl_fw_bcast_mac mac = {};
915 u32 mac_id, attached_filters;
916 int err = 0;
917
918 if (!mvm->bcast_filters)
919 return -ENOENT;
920
921 if (sscanf(buf, "%d %hhi %i", &mac_id, &mac.default_discard,
922 &attached_filters) != 3)
923 return -EINVAL;
924
925 if (mac_id >= ARRAY_SIZE(cmd.macs) ||
926 mac.default_discard > 1 ||
927 attached_filters >= BIT(ARRAY_SIZE(cmd.filters)))
928 return -EINVAL;
929
930 mac.attached_filters = cpu_to_le16(attached_filters);
931
932 mutex_lock(&mvm->mutex);
933 memcpy(&mvm->dbgfs_bcast_filtering.cmd.macs[mac_id],
934 &mac, sizeof(mac));
935
936 /* send updated bcast filtering configuration */
937 if (mvm->dbgfs_bcast_filtering.override &&
938 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
a1022927 939 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
de06a59e
EP
940 sizeof(cmd), &cmd);
941 mutex_unlock(&mvm->mutex);
942
943 return err ?: count;
944}
945#endif
946
afc66bb7 947#ifdef CONFIG_PM_SLEEP
1fa3f57a 948static ssize_t iwl_dbgfs_d3_sram_write(struct iwl_mvm *mvm, char *buf,
afc66bb7
JB
949 size_t count, loff_t *ppos)
950{
afc66bb7
JB
951 int store;
952
afc66bb7
JB
953 if (sscanf(buf, "%d", &store) != 1)
954 return -EINVAL;
955
956 mvm->store_d3_resume_sram = store;
957
958 return count;
959}
960
961static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
962 size_t count, loff_t *ppos)
963{
964 struct iwl_mvm *mvm = file->private_data;
965 const struct fw_img *img;
966 int ofs, len, pos = 0;
967 size_t bufsz, ret;
968 char *buf;
969 u8 *ptr = mvm->d3_resume_sram;
970
971 img = &mvm->fw->img[IWL_UCODE_WOWLAN];
972 len = img->sec[IWL_UCODE_SECTION_DATA].len;
973
974 bufsz = len * 4 + 256;
975 buf = kzalloc(bufsz, GFP_KERNEL);
976 if (!buf)
977 return -ENOMEM;
978
979 pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
980 mvm->store_d3_resume_sram ? "en" : "dis");
981
982 if (ptr) {
983 for (ofs = 0; ofs < len; ofs += 16) {
984 pos += scnprintf(buf + pos, bufsz - pos,
985 "0x%.4x ", ofs);
986 hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
987 bufsz - pos, false);
988 pos += strlen(buf + pos);
989 if (bufsz - pos > 0)
990 buf[pos++] = '\n';
991 }
992 } else {
993 pos += scnprintf(buf + pos, bufsz - pos,
994 "(no data captured)\n");
995 }
996
997 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
998
999 kfree(buf);
1000
1001 return ret;
1002}
1003#endif
1004
70d6babb
EP
1005#define PRINT_MVM_REF(ref) do { \
1006 if (test_bit(ref, mvm->ref_bitmap)) \
1007 pos += scnprintf(buf + pos, bufsz - pos, \
1008 "\t(0x%lx) %s\n", \
1009 BIT(ref), #ref); \
1010} while (0)
1011
1012static ssize_t iwl_dbgfs_d0i3_refs_read(struct file *file,
1013 char __user *user_buf,
1014 size_t count, loff_t *ppos)
1015{
1016 struct iwl_mvm *mvm = file->private_data;
1017 int pos = 0;
1018 char buf[256];
1019 const size_t bufsz = sizeof(buf);
1020
1021 pos += scnprintf(buf + pos, bufsz - pos, "taken mvm refs: 0x%lx\n",
1022 mvm->ref_bitmap[0]);
1023
1024 PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN);
1025 PRINT_MVM_REF(IWL_MVM_REF_SCAN);
1026 PRINT_MVM_REF(IWL_MVM_REF_ROC);
1027 PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT);
1028 PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS);
0eb83653 1029 PRINT_MVM_REF(IWL_MVM_REF_USER);
d15a747f 1030 PRINT_MVM_REF(IWL_MVM_REF_EXIT_WORK);
70d6babb
EP
1031
1032 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1033}
1034
0eb83653
EP
1035static ssize_t iwl_dbgfs_d0i3_refs_write(struct iwl_mvm *mvm, char *buf,
1036 size_t count, loff_t *ppos)
1037{
1038 unsigned long value;
1039 int ret;
1040 bool taken;
1041
1042 ret = kstrtoul(buf, 10, &value);
1043 if (ret < 0)
1044 return ret;
1045
1046 mutex_lock(&mvm->mutex);
1047
1048 taken = test_bit(IWL_MVM_REF_USER, mvm->ref_bitmap);
1049 if (value == 1 && !taken)
1050 iwl_mvm_ref(mvm, IWL_MVM_REF_USER);
1051 else if (value == 0 && taken)
1052 iwl_mvm_unref(mvm, IWL_MVM_REF_USER);
1053 else
1054 ret = -EINVAL;
1055
1056 mutex_unlock(&mvm->mutex);
1057
1058 if (ret < 0)
1059 return ret;
1060 return count;
1061}
1062
1fa3f57a
JB
1063#define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
1064 _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1065#define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
1066 _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
de06a59e
EP
1067#define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \
1068 if (!debugfs_create_file(alias, mode, parent, mvm, \
8ca151b5
JB
1069 &iwl_dbgfs_##name##_ops)) \
1070 goto err; \
1071 } while (0)
de06a59e
EP
1072#define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
1073 MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
8ca151b5 1074
f3c221f6
EP
1075static ssize_t
1076iwl_dbgfs_prph_reg_read(struct file *file,
1077 char __user *user_buf,
1078 size_t count, loff_t *ppos)
1079{
1080 struct iwl_mvm *mvm = file->private_data;
1081 int pos = 0;
1082 char buf[32];
1083 const size_t bufsz = sizeof(buf);
1084
1085 if (!mvm->dbgfs_prph_reg_addr)
1086 return -EINVAL;
1087
1088 pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n",
1089 mvm->dbgfs_prph_reg_addr,
1090 iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr));
1091
1092 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1093}
1094
1095static ssize_t
1096iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf,
1097 size_t count, loff_t *ppos)
1098{
1099 u8 args;
1100 u32 value;
1101
1102 args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value);
1103 /* if we only want to set the reg address - nothing more to do */
1104 if (args == 1)
1105 goto out;
1106
1107 /* otherwise, make sure we have both address and value */
1108 if (args != 2)
1109 return -EINVAL;
1110
1111 iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value);
1112out:
1113 return count;
1114}
1115
1116MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);
1117
8ca151b5 1118/* Device wide debugfs entries */
1fa3f57a
JB
1119MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
1120MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
1121MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64);
8ca151b5 1122MVM_DEBUGFS_READ_FILE_OPS(stations);
10942342 1123MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
2de13cae 1124MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
1fa3f57a 1125MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64);
3848ab66 1126MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
5fc0f76c 1127MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats);
1fa3f57a
JB
1128MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10);
1129MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10);
cdb00563 1130MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10);
a39979a8 1131MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant, 10);
1fa3f57a 1132MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
0eb83653 1133MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8);
91b05d10 1134
1bd3cbc1 1135static const struct file_operations iwl_dbgfs_fw_error_dump_ops = {
3a58d98e
EG
1136 .open = iwl_dbgfs_fw_error_dump_open,
1137 .read = iwl_dbgfs_fw_error_dump_read,
1138 .release = iwl_dbgfs_fw_error_dump_release,
1bd3cbc1
EG
1139};
1140
de06a59e
EP
1141#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1142MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256);
1143MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256);
1144#endif
1145
afc66bb7 1146#ifdef CONFIG_PM_SLEEP
1fa3f57a 1147MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8);
afc66bb7 1148#endif
8ca151b5
JB
1149
1150int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
1151{
de06a59e 1152 struct dentry *bcast_dir __maybe_unused;
8ca151b5
JB
1153 char buf[100];
1154
d07913aa
JB
1155 spin_lock_init(&mvm->drv_stats_lock);
1156
8ca151b5
JB
1157 mvm->debugfs_dir = dbgfs_dir;
1158
1159 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
1160 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
1161 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
1162 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
1bd3cbc1 1163 MVM_DEBUGFS_ADD_FILE(fw_error_dump, dbgfs_dir, S_IRUSR);
10942342 1164 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
2de13cae 1165 MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
639eabad
EG
1166 MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
1167 S_IRUSR | S_IWUSR);
3848ab66 1168 MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
5fc0f76c 1169 MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, S_IRUSR);
490953ac 1170 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
119663c3 1171 MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR);
cdb00563 1172 MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, S_IWUSR);
a39979a8 1173 MVM_DEBUGFS_ADD_FILE(bt_force_ant, mvm->debugfs_dir, S_IWUSR);
91b05d10
OG
1174 MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
1175 S_IWUSR | S_IRUSR);
f3c221f6 1176 MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
0eb83653 1177 MVM_DEBUGFS_ADD_FILE(d0i3_refs, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
de06a59e
EP
1178
1179#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1180 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING) {
1181 bcast_dir = debugfs_create_dir("bcast_filtering",
1182 mvm->debugfs_dir);
1183 if (!bcast_dir)
1184 goto err;
1185
1186 if (!debugfs_create_bool("override", S_IRUSR | S_IWUSR,
1187 bcast_dir,
1188 &mvm->dbgfs_bcast_filtering.override))
1189 goto err;
1190
1191 MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters,
1192 bcast_dir, S_IWUSR | S_IRUSR);
1193 MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs,
1194 bcast_dir, S_IWUSR | S_IRUSR);
1195 }
1196#endif
1197
afc66bb7
JB
1198#ifdef CONFIG_PM_SLEEP
1199 MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
debff618 1200 MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
b0114714
JB
1201 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
1202 mvm->debugfs_dir, &mvm->d3_wake_sysassert))
1203 goto err;
afc66bb7 1204#endif
8ca151b5 1205
086f7368
EG
1206 if (!debugfs_create_blob("nvm_hw", S_IRUSR,
1207 mvm->debugfs_dir, &mvm->nvm_hw_blob))
1208 goto err;
1209 if (!debugfs_create_blob("nvm_sw", S_IRUSR,
1210 mvm->debugfs_dir, &mvm->nvm_sw_blob))
1211 goto err;
1212 if (!debugfs_create_blob("nvm_calib", S_IRUSR,
1213 mvm->debugfs_dir, &mvm->nvm_calib_blob))
1214 goto err;
1215 if (!debugfs_create_blob("nvm_prod", S_IRUSR,
1216 mvm->debugfs_dir, &mvm->nvm_prod_blob))
1217 goto err;
1218
8ca151b5
JB
1219 /*
1220 * Create a symlink with mac80211. It will be removed when mac80211
1221 * exists (before the opmode exists which removes the target.)
1222 */
1223 snprintf(buf, 100, "../../%s/%s",
1224 dbgfs_dir->d_parent->d_parent->d_name.name,
1225 dbgfs_dir->d_parent->d_name.name);
1226 if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
1227 goto err;
1228
1229 return 0;
1230err:
1231 IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
1232 return -ENOMEM;
1233}
This page took 0.162587 seconds and 5 git commands to generate.