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