iwlwifi: split fw-error-dump between transport and mvm
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / mvm / debugfs.c
1 /******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9 *
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
25 * in the file called COPYING.
26 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63 #include <linux/vmalloc.h>
64
65 #include "mvm.h"
66 #include "sta.h"
67 #include "iwl-io.h"
68 #include "debugfs.h"
69 #include "iwl-fw-error-dump.h"
70
71 static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf,
72 size_t count, loff_t *ppos)
73 {
74 int ret;
75 u32 scd_q_msk;
76
77 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
78 return -EIO;
79
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
92 static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf,
93 size_t count, loff_t *ppos)
94 {
95 struct iwl_mvm_sta *mvmsta;
96 int sta_id, drain, ret;
97
98 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
99 return -EIO;
100
101 if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
102 return -EINVAL;
103 if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
104 return -EINVAL;
105 if (drain < 0 || drain > 1)
106 return -EINVAL;
107
108 mutex_lock(&mvm->mutex);
109
110 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
111
112 if (!mvmsta)
113 ret = -ENOENT;
114 else
115 ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count;
116
117 mutex_unlock(&mvm->mutex);
118
119 return ret;
120 }
121
122 static 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;
138 ret = 0;
139
140 out:
141 mutex_unlock(&mvm->mutex);
142 return ret;
143 }
144
145 static 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_mvm_dump_ptrs *dump_ptrs = (void *)file->private_data;
150 ssize_t bytes_read = 0;
151 ssize_t bytes_read_trans = 0;
152
153 if (*ppos < dump_ptrs->op_mode_len)
154 bytes_read +=
155 simple_read_from_buffer(user_buf, count, ppos,
156 dump_ptrs->op_mode_ptr,
157 dump_ptrs->op_mode_len);
158
159 if (bytes_read < 0 || *ppos < dump_ptrs->op_mode_len)
160 return bytes_read;
161
162 if (dump_ptrs->trans_ptr) {
163 *ppos -= dump_ptrs->op_mode_len;
164 bytes_read_trans =
165 simple_read_from_buffer(user_buf + bytes_read,
166 count - bytes_read, ppos,
167 dump_ptrs->trans_ptr->data,
168 dump_ptrs->trans_ptr->len);
169 *ppos += dump_ptrs->op_mode_len;
170
171 if (bytes_read_trans >= 0)
172 bytes_read += bytes_read_trans;
173 else if (!bytes_read)
174 /* propagate the failure */
175 return bytes_read_trans;
176 }
177
178 return bytes_read;
179
180 }
181
182 static int iwl_dbgfs_fw_error_dump_release(struct inode *inode,
183 struct file *file)
184 {
185 struct iwl_mvm_dump_ptrs *dump_ptrs = (void *)file->private_data;
186
187 vfree(dump_ptrs->op_mode_ptr);
188 vfree(dump_ptrs->trans_ptr);
189 kfree(dump_ptrs);
190
191 return 0;
192 }
193
194 static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
195 size_t count, loff_t *ppos)
196 {
197 struct iwl_mvm *mvm = file->private_data;
198 const struct fw_img *img;
199 unsigned int ofs, len;
200 size_t ret;
201 u8 *ptr;
202
203 if (!mvm->ucode_loaded)
204 return -EINVAL;
205
206 /* default is to dump the entire data segment */
207 img = &mvm->fw->img[mvm->cur_ucode];
208 ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
209 len = img->sec[IWL_UCODE_SECTION_DATA].len;
210
211 if (mvm->dbgfs_sram_len) {
212 ofs = mvm->dbgfs_sram_offset;
213 len = mvm->dbgfs_sram_len;
214 }
215
216 ptr = kzalloc(len, GFP_KERNEL);
217 if (!ptr)
218 return -ENOMEM;
219
220 iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
221
222 ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len);
223
224 kfree(ptr);
225
226 return ret;
227 }
228
229 static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf,
230 size_t count, loff_t *ppos)
231 {
232 const struct fw_img *img;
233 u32 offset, len;
234 u32 img_offset, img_len;
235
236 if (!mvm->ucode_loaded)
237 return -EINVAL;
238
239 img = &mvm->fw->img[mvm->cur_ucode];
240 img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset;
241 img_len = img->sec[IWL_UCODE_SECTION_DATA].len;
242
243 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
244 if ((offset & 0x3) || (len & 0x3))
245 return -EINVAL;
246
247 if (offset + len > img_offset + img_len)
248 return -EINVAL;
249
250 mvm->dbgfs_sram_offset = offset;
251 mvm->dbgfs_sram_len = len;
252 } else {
253 mvm->dbgfs_sram_offset = 0;
254 mvm->dbgfs_sram_len = 0;
255 }
256
257 return count;
258 }
259
260 static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
261 size_t count, loff_t *ppos)
262 {
263 struct iwl_mvm *mvm = file->private_data;
264 struct ieee80211_sta *sta;
265 char buf[400];
266 int i, pos = 0, bufsz = sizeof(buf);
267
268 mutex_lock(&mvm->mutex);
269
270 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
271 pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
272 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
273 lockdep_is_held(&mvm->mutex));
274 if (!sta)
275 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
276 else if (IS_ERR(sta))
277 pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
278 PTR_ERR(sta));
279 else
280 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
281 sta->addr);
282 }
283
284 mutex_unlock(&mvm->mutex);
285
286 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
287 }
288
289 static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
290 char __user *user_buf,
291 size_t count, loff_t *ppos)
292 {
293 struct iwl_mvm *mvm = file->private_data;
294 char buf[64];
295 int bufsz = sizeof(buf);
296 int pos = 0;
297
298 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
299 mvm->disable_power_off);
300 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
301 mvm->disable_power_off_d3);
302
303 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
304 }
305
306 static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf,
307 size_t count, loff_t *ppos)
308 {
309 int ret, val;
310
311 if (!mvm->ucode_loaded)
312 return -EIO;
313
314 if (!strncmp("disable_power_off_d0=", buf, 21)) {
315 if (sscanf(buf + 21, "%d", &val) != 1)
316 return -EINVAL;
317 mvm->disable_power_off = val;
318 } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
319 if (sscanf(buf + 21, "%d", &val) != 1)
320 return -EINVAL;
321 mvm->disable_power_off_d3 = val;
322 } else {
323 return -EINVAL;
324 }
325
326 mutex_lock(&mvm->mutex);
327 ret = iwl_mvm_power_update_device(mvm);
328 mutex_unlock(&mvm->mutex);
329
330 return ret ?: count;
331 }
332
333 #define BT_MBOX_MSG(_notif, _num, _field) \
334 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
335 >> BT_MBOX##_num##_##_field##_POS)
336
337
338 #define BT_MBOX_PRINT(_num, _field, _end) \
339 pos += scnprintf(buf + pos, bufsz - pos, \
340 "\t%s: %d%s", \
341 #_field, \
342 BT_MBOX_MSG(notif, _num, _field), \
343 true ? "\n" : ", ");
344
345 static
346 int iwl_mvm_coex_dump_mbox(struct iwl_bt_coex_profile_notif *notif, char *buf,
347 int pos, int bufsz)
348 {
349 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
350
351 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
352 BT_MBOX_PRINT(0, LE_PROF1, false);
353 BT_MBOX_PRINT(0, LE_PROF2, false);
354 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
355 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
356 BT_MBOX_PRINT(0, INBAND_S, false);
357 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
358 BT_MBOX_PRINT(0, LE_SCAN, false);
359 BT_MBOX_PRINT(0, LE_ADV, false);
360 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
361 BT_MBOX_PRINT(0, OPEN_CON_1, true);
362
363 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
364
365 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
366 BT_MBOX_PRINT(1, IP_SR, false);
367 BT_MBOX_PRINT(1, LE_MSTR, false);
368 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
369 BT_MBOX_PRINT(1, MSG_TYPE, false);
370 BT_MBOX_PRINT(1, SSN, true);
371
372 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
373
374 BT_MBOX_PRINT(2, SNIFF_ACT, false);
375 BT_MBOX_PRINT(2, PAG, false);
376 BT_MBOX_PRINT(2, INQUIRY, false);
377 BT_MBOX_PRINT(2, CONN, false);
378 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
379 BT_MBOX_PRINT(2, DISC, false);
380 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
381 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
382 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
383 BT_MBOX_PRINT(2, SCO_DURATION, true);
384
385 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
386
387 BT_MBOX_PRINT(3, SCO_STATE, false);
388 BT_MBOX_PRINT(3, SNIFF_STATE, false);
389 BT_MBOX_PRINT(3, A2DP_STATE, false);
390 BT_MBOX_PRINT(3, ACL_STATE, false);
391 BT_MBOX_PRINT(3, MSTR_STATE, false);
392 BT_MBOX_PRINT(3, OBX_STATE, false);
393 BT_MBOX_PRINT(3, OPEN_CON_2, false);
394 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
395 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
396 BT_MBOX_PRINT(3, INBAND_P, false);
397 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
398 BT_MBOX_PRINT(3, SSN_2, false);
399 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
400
401 return pos;
402 }
403
404 static
405 int iwl_mvm_coex_dump_mbox_old(struct iwl_bt_coex_profile_notif_old *notif,
406 char *buf, int pos, int bufsz)
407 {
408 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
409
410 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
411 BT_MBOX_PRINT(0, LE_PROF1, false);
412 BT_MBOX_PRINT(0, LE_PROF2, false);
413 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
414 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
415 BT_MBOX_PRINT(0, INBAND_S, false);
416 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
417 BT_MBOX_PRINT(0, LE_SCAN, false);
418 BT_MBOX_PRINT(0, LE_ADV, false);
419 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
420 BT_MBOX_PRINT(0, OPEN_CON_1, true);
421
422 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
423
424 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
425 BT_MBOX_PRINT(1, IP_SR, false);
426 BT_MBOX_PRINT(1, LE_MSTR, false);
427 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
428 BT_MBOX_PRINT(1, MSG_TYPE, false);
429 BT_MBOX_PRINT(1, SSN, true);
430
431 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
432
433 BT_MBOX_PRINT(2, SNIFF_ACT, false);
434 BT_MBOX_PRINT(2, PAG, false);
435 BT_MBOX_PRINT(2, INQUIRY, false);
436 BT_MBOX_PRINT(2, CONN, false);
437 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
438 BT_MBOX_PRINT(2, DISC, false);
439 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
440 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
441 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
442 BT_MBOX_PRINT(2, SCO_DURATION, true);
443
444 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
445
446 BT_MBOX_PRINT(3, SCO_STATE, false);
447 BT_MBOX_PRINT(3, SNIFF_STATE, false);
448 BT_MBOX_PRINT(3, A2DP_STATE, false);
449 BT_MBOX_PRINT(3, ACL_STATE, false);
450 BT_MBOX_PRINT(3, MSTR_STATE, false);
451 BT_MBOX_PRINT(3, OBX_STATE, false);
452 BT_MBOX_PRINT(3, OPEN_CON_2, false);
453 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
454 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
455 BT_MBOX_PRINT(3, INBAND_P, false);
456 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
457 BT_MBOX_PRINT(3, SSN_2, false);
458 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
459
460 return pos;
461 }
462
463 static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
464 size_t count, loff_t *ppos)
465 {
466 struct iwl_mvm *mvm = file->private_data;
467 char *buf;
468 int ret, pos = 0, bufsz = sizeof(char) * 1024;
469
470 buf = kmalloc(bufsz, GFP_KERNEL);
471 if (!buf)
472 return -ENOMEM;
473
474 mutex_lock(&mvm->mutex);
475
476 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
477 struct iwl_bt_coex_profile_notif_old *notif =
478 &mvm->last_bt_notif_old;
479
480 pos += iwl_mvm_coex_dump_mbox_old(notif, buf, pos, bufsz);
481
482 pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
483 notif->bt_ci_compliance);
484 pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
485 le32_to_cpu(notif->primary_ch_lut));
486 pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
487 le32_to_cpu(notif->secondary_ch_lut));
488 pos += scnprintf(buf+pos,
489 bufsz-pos, "bt_activity_grading = %d\n",
490 le32_to_cpu(notif->bt_activity_grading));
491 pos += scnprintf(buf+pos, bufsz-pos,
492 "antenna isolation = %d CORUN LUT index = %d\n",
493 mvm->last_ant_isol, mvm->last_corun_lut);
494 } else {
495 struct iwl_bt_coex_profile_notif *notif =
496 &mvm->last_bt_notif;
497
498 pos += iwl_mvm_coex_dump_mbox(notif, buf, pos, bufsz);
499
500 pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
501 notif->bt_ci_compliance);
502 pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
503 le32_to_cpu(notif->primary_ch_lut));
504 pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
505 le32_to_cpu(notif->secondary_ch_lut));
506 pos += scnprintf(buf+pos,
507 bufsz-pos, "bt_activity_grading = %d\n",
508 le32_to_cpu(notif->bt_activity_grading));
509 pos += scnprintf(buf+pos, bufsz-pos,
510 "antenna isolation = %d CORUN LUT index = %d\n",
511 mvm->last_ant_isol, mvm->last_corun_lut);
512 }
513
514 mutex_unlock(&mvm->mutex);
515
516 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
517 kfree(buf);
518
519 return ret;
520 }
521 #undef BT_MBOX_PRINT
522
523 static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
524 size_t count, loff_t *ppos)
525 {
526 struct iwl_mvm *mvm = file->private_data;
527 char buf[256];
528 int bufsz = sizeof(buf);
529 int pos = 0;
530
531 mutex_lock(&mvm->mutex);
532
533 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
534 struct iwl_bt_coex_ci_cmd_old *cmd = &mvm->last_bt_ci_cmd_old;
535
536 pos += scnprintf(buf+pos, bufsz-pos,
537 "Channel inhibition CMD\n");
538 pos += scnprintf(buf+pos, bufsz-pos,
539 "\tPrimary Channel Bitmap 0x%016llx\n",
540 le64_to_cpu(cmd->bt_primary_ci));
541 pos += scnprintf(buf+pos, bufsz-pos,
542 "\tSecondary Channel Bitmap 0x%016llx\n",
543 le64_to_cpu(cmd->bt_secondary_ci));
544
545 pos += scnprintf(buf+pos, bufsz-pos, "BT Configuration CMD\n");
546 pos += scnprintf(buf+pos, bufsz-pos, "\tACK Kill Mask 0x%08x\n",
547 iwl_bt_ctl_kill_msk[mvm->bt_ack_kill_msk[0]]);
548 pos += scnprintf(buf+pos, bufsz-pos, "\tCTS Kill Mask 0x%08x\n",
549 iwl_bt_ctl_kill_msk[mvm->bt_cts_kill_msk[0]]);
550
551 } else {
552 struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
553
554 pos += scnprintf(buf+pos, bufsz-pos,
555 "Channel inhibition CMD\n");
556 pos += scnprintf(buf+pos, bufsz-pos,
557 "\tPrimary Channel Bitmap 0x%016llx\n",
558 le64_to_cpu(cmd->bt_primary_ci));
559 pos += scnprintf(buf+pos, bufsz-pos,
560 "\tSecondary Channel Bitmap 0x%016llx\n",
561 le64_to_cpu(cmd->bt_secondary_ci));
562
563 pos += scnprintf(buf+pos, bufsz-pos, "BT Configuration CMD\n");
564 pos += scnprintf(buf+pos, bufsz-pos,
565 "\tPrimary: ACK Kill Mask 0x%08x\n",
566 iwl_bt_ctl_kill_msk[mvm->bt_ack_kill_msk[0]]);
567 pos += scnprintf(buf+pos, bufsz-pos,
568 "\tPrimary: CTS Kill Mask 0x%08x\n",
569 iwl_bt_ctl_kill_msk[mvm->bt_cts_kill_msk[0]]);
570 pos += scnprintf(buf+pos, bufsz-pos,
571 "\tSecondary: ACK Kill Mask 0x%08x\n",
572 iwl_bt_ctl_kill_msk[mvm->bt_ack_kill_msk[1]]);
573 pos += scnprintf(buf+pos, bufsz-pos,
574 "\tSecondary: CTS Kill Mask 0x%08x\n",
575 iwl_bt_ctl_kill_msk[mvm->bt_cts_kill_msk[1]]);
576
577 }
578
579 mutex_unlock(&mvm->mutex);
580
581 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
582 }
583
584 static ssize_t
585 iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf,
586 size_t count, loff_t *ppos)
587 {
588 u32 bt_tx_prio;
589
590 if (sscanf(buf, "%u", &bt_tx_prio) != 1)
591 return -EINVAL;
592 if (bt_tx_prio > 4)
593 return -EINVAL;
594
595 mvm->bt_tx_prio = bt_tx_prio;
596
597 return count;
598 }
599
600 static ssize_t
601 iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char *buf,
602 size_t count, loff_t *ppos)
603 {
604 static const char * const modes_str[BT_FORCE_ANT_MAX] = {
605 [BT_FORCE_ANT_DIS] = "dis",
606 [BT_FORCE_ANT_AUTO] = "auto",
607 [BT_FORCE_ANT_BT] = "bt",
608 [BT_FORCE_ANT_WIFI] = "wifi",
609 };
610 int ret, bt_force_ant_mode;
611
612 for (bt_force_ant_mode = 0;
613 bt_force_ant_mode < ARRAY_SIZE(modes_str);
614 bt_force_ant_mode++) {
615 if (!strcmp(buf, modes_str[bt_force_ant_mode]))
616 break;
617 }
618
619 if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
620 return -EINVAL;
621
622 ret = 0;
623 mutex_lock(&mvm->mutex);
624 if (mvm->bt_force_ant_mode == bt_force_ant_mode)
625 goto out;
626
627 mvm->bt_force_ant_mode = bt_force_ant_mode;
628 IWL_DEBUG_COEX(mvm, "Force mode: %s\n",
629 modes_str[mvm->bt_force_ant_mode]);
630 ret = iwl_send_bt_init_conf(mvm);
631
632 out:
633 mutex_unlock(&mvm->mutex);
634 return ret ?: count;
635 }
636
637 #define PRINT_STATS_LE32(_str, _val) \
638 pos += scnprintf(buf + pos, bufsz - pos, \
639 fmt_table, _str, \
640 le32_to_cpu(_val))
641
642 static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
643 char __user *user_buf, size_t count,
644 loff_t *ppos)
645 {
646 struct iwl_mvm *mvm = file->private_data;
647 static const char *fmt_table = "\t%-30s %10u\n";
648 static const char *fmt_header = "%-32s\n";
649 int pos = 0;
650 char *buf;
651 int ret;
652 /* 43 is the size of each data line, 33 is the size of each header */
653 size_t bufsz =
654 ((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) +
655 (4 * 33) + 1;
656
657 struct mvm_statistics_rx_phy *ofdm;
658 struct mvm_statistics_rx_phy *cck;
659 struct mvm_statistics_rx_non_phy *general;
660 struct mvm_statistics_rx_ht_phy *ht;
661
662 buf = kzalloc(bufsz, GFP_KERNEL);
663 if (!buf)
664 return -ENOMEM;
665
666 mutex_lock(&mvm->mutex);
667
668 ofdm = &mvm->rx_stats.ofdm;
669 cck = &mvm->rx_stats.cck;
670 general = &mvm->rx_stats.general;
671 ht = &mvm->rx_stats.ofdm_ht;
672
673 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
674 "Statistics_Rx - OFDM");
675 PRINT_STATS_LE32("ina_cnt", ofdm->ina_cnt);
676 PRINT_STATS_LE32("fina_cnt", ofdm->fina_cnt);
677 PRINT_STATS_LE32("plcp_err", ofdm->plcp_err);
678 PRINT_STATS_LE32("crc32_err", ofdm->crc32_err);
679 PRINT_STATS_LE32("overrun_err", ofdm->overrun_err);
680 PRINT_STATS_LE32("early_overrun_err", ofdm->early_overrun_err);
681 PRINT_STATS_LE32("crc32_good", ofdm->crc32_good);
682 PRINT_STATS_LE32("false_alarm_cnt", ofdm->false_alarm_cnt);
683 PRINT_STATS_LE32("fina_sync_err_cnt", ofdm->fina_sync_err_cnt);
684 PRINT_STATS_LE32("sfd_timeout", ofdm->sfd_timeout);
685 PRINT_STATS_LE32("fina_timeout", ofdm->fina_timeout);
686 PRINT_STATS_LE32("unresponded_rts", ofdm->unresponded_rts);
687 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
688 ofdm->rxe_frame_limit_overrun);
689 PRINT_STATS_LE32("sent_ack_cnt", ofdm->sent_ack_cnt);
690 PRINT_STATS_LE32("sent_cts_cnt", ofdm->sent_cts_cnt);
691 PRINT_STATS_LE32("sent_ba_rsp_cnt", ofdm->sent_ba_rsp_cnt);
692 PRINT_STATS_LE32("dsp_self_kill", ofdm->dsp_self_kill);
693 PRINT_STATS_LE32("mh_format_err", ofdm->mh_format_err);
694 PRINT_STATS_LE32("re_acq_main_rssi_sum", ofdm->re_acq_main_rssi_sum);
695 PRINT_STATS_LE32("reserved", ofdm->reserved);
696
697 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
698 "Statistics_Rx - CCK");
699 PRINT_STATS_LE32("ina_cnt", cck->ina_cnt);
700 PRINT_STATS_LE32("fina_cnt", cck->fina_cnt);
701 PRINT_STATS_LE32("plcp_err", cck->plcp_err);
702 PRINT_STATS_LE32("crc32_err", cck->crc32_err);
703 PRINT_STATS_LE32("overrun_err", cck->overrun_err);
704 PRINT_STATS_LE32("early_overrun_err", cck->early_overrun_err);
705 PRINT_STATS_LE32("crc32_good", cck->crc32_good);
706 PRINT_STATS_LE32("false_alarm_cnt", cck->false_alarm_cnt);
707 PRINT_STATS_LE32("fina_sync_err_cnt", cck->fina_sync_err_cnt);
708 PRINT_STATS_LE32("sfd_timeout", cck->sfd_timeout);
709 PRINT_STATS_LE32("fina_timeout", cck->fina_timeout);
710 PRINT_STATS_LE32("unresponded_rts", cck->unresponded_rts);
711 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
712 cck->rxe_frame_limit_overrun);
713 PRINT_STATS_LE32("sent_ack_cnt", cck->sent_ack_cnt);
714 PRINT_STATS_LE32("sent_cts_cnt", cck->sent_cts_cnt);
715 PRINT_STATS_LE32("sent_ba_rsp_cnt", cck->sent_ba_rsp_cnt);
716 PRINT_STATS_LE32("dsp_self_kill", cck->dsp_self_kill);
717 PRINT_STATS_LE32("mh_format_err", cck->mh_format_err);
718 PRINT_STATS_LE32("re_acq_main_rssi_sum", cck->re_acq_main_rssi_sum);
719 PRINT_STATS_LE32("reserved", cck->reserved);
720
721 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
722 "Statistics_Rx - GENERAL");
723 PRINT_STATS_LE32("bogus_cts", general->bogus_cts);
724 PRINT_STATS_LE32("bogus_ack", general->bogus_ack);
725 PRINT_STATS_LE32("non_bssid_frames", general->non_bssid_frames);
726 PRINT_STATS_LE32("filtered_frames", general->filtered_frames);
727 PRINT_STATS_LE32("non_channel_beacons", general->non_channel_beacons);
728 PRINT_STATS_LE32("channel_beacons", general->channel_beacons);
729 PRINT_STATS_LE32("num_missed_bcon", general->num_missed_bcon);
730 PRINT_STATS_LE32("adc_rx_saturation_time",
731 general->adc_rx_saturation_time);
732 PRINT_STATS_LE32("ina_detection_search_time",
733 general->ina_detection_search_time);
734 PRINT_STATS_LE32("beacon_silence_rssi_a",
735 general->beacon_silence_rssi_a);
736 PRINT_STATS_LE32("beacon_silence_rssi_b",
737 general->beacon_silence_rssi_b);
738 PRINT_STATS_LE32("beacon_silence_rssi_c",
739 general->beacon_silence_rssi_c);
740 PRINT_STATS_LE32("interference_data_flag",
741 general->interference_data_flag);
742 PRINT_STATS_LE32("channel_load", general->channel_load);
743 PRINT_STATS_LE32("dsp_false_alarms", general->dsp_false_alarms);
744 PRINT_STATS_LE32("beacon_rssi_a", general->beacon_rssi_a);
745 PRINT_STATS_LE32("beacon_rssi_b", general->beacon_rssi_b);
746 PRINT_STATS_LE32("beacon_rssi_c", general->beacon_rssi_c);
747 PRINT_STATS_LE32("beacon_energy_a", general->beacon_energy_a);
748 PRINT_STATS_LE32("beacon_energy_b", general->beacon_energy_b);
749 PRINT_STATS_LE32("beacon_energy_c", general->beacon_energy_c);
750 PRINT_STATS_LE32("num_bt_kills", general->num_bt_kills);
751 PRINT_STATS_LE32("mac_id", general->mac_id);
752 PRINT_STATS_LE32("directed_data_mpdu", general->directed_data_mpdu);
753
754 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
755 "Statistics_Rx - HT");
756 PRINT_STATS_LE32("plcp_err", ht->plcp_err);
757 PRINT_STATS_LE32("overrun_err", ht->overrun_err);
758 PRINT_STATS_LE32("early_overrun_err", ht->early_overrun_err);
759 PRINT_STATS_LE32("crc32_good", ht->crc32_good);
760 PRINT_STATS_LE32("crc32_err", ht->crc32_err);
761 PRINT_STATS_LE32("mh_format_err", ht->mh_format_err);
762 PRINT_STATS_LE32("agg_crc32_good", ht->agg_crc32_good);
763 PRINT_STATS_LE32("agg_mpdu_cnt", ht->agg_mpdu_cnt);
764 PRINT_STATS_LE32("agg_cnt", ht->agg_cnt);
765 PRINT_STATS_LE32("unsupport_mcs", ht->unsupport_mcs);
766
767 mutex_unlock(&mvm->mutex);
768
769 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
770 kfree(buf);
771
772 return ret;
773 }
774 #undef PRINT_STAT_LE32
775
776 static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm,
777 char __user *user_buf, size_t count,
778 loff_t *ppos,
779 struct iwl_mvm_frame_stats *stats)
780 {
781 char *buff, *pos, *endpos;
782 int idx, i;
783 int ret;
784 static const size_t bufsz = 1024;
785
786 buff = kmalloc(bufsz, GFP_KERNEL);
787 if (!buff)
788 return -ENOMEM;
789
790 spin_lock_bh(&mvm->drv_stats_lock);
791
792 pos = buff;
793 endpos = pos + bufsz;
794
795 pos += scnprintf(pos, endpos - pos,
796 "Legacy/HT/VHT\t:\t%d/%d/%d\n",
797 stats->legacy_frames,
798 stats->ht_frames,
799 stats->vht_frames);
800 pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n",
801 stats->bw_20_frames,
802 stats->bw_40_frames,
803 stats->bw_80_frames);
804 pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n",
805 stats->ngi_frames,
806 stats->sgi_frames);
807 pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n",
808 stats->siso_frames,
809 stats->mimo2_frames);
810 pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n",
811 stats->fail_frames,
812 stats->success_frames);
813 pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n",
814 stats->agg_frames);
815 pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n",
816 stats->ampdu_count);
817 pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n",
818 stats->ampdu_count > 0 ?
819 (stats->agg_frames / stats->ampdu_count) : 0);
820
821 pos += scnprintf(pos, endpos - pos, "Last Rates\n");
822
823 idx = stats->last_frame_idx - 1;
824 for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) {
825 idx = (idx + 1) % ARRAY_SIZE(stats->last_rates);
826 if (stats->last_rates[idx] == 0)
827 continue;
828 pos += scnprintf(pos, endpos - pos, "Rate[%d]: ",
829 (int)(ARRAY_SIZE(stats->last_rates) - i));
830 pos += rs_pretty_print_rate(pos, stats->last_rates[idx]);
831 }
832 spin_unlock_bh(&mvm->drv_stats_lock);
833
834 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
835 kfree(buff);
836
837 return ret;
838 }
839
840 static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file,
841 char __user *user_buf, size_t count,
842 loff_t *ppos)
843 {
844 struct iwl_mvm *mvm = file->private_data;
845
846 return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos,
847 &mvm->drv_rx_stats);
848 }
849
850 static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
851 size_t count, loff_t *ppos)
852 {
853 int ret;
854
855 mutex_lock(&mvm->mutex);
856
857 /* allow one more restart that we're provoking here */
858 if (mvm->restart_fw >= 0)
859 mvm->restart_fw++;
860
861 /* take the return value to make compiler happy - it will fail anyway */
862 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, 0, 0, NULL);
863
864 mutex_unlock(&mvm->mutex);
865
866 return count;
867 }
868
869 static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
870 size_t count, loff_t *ppos)
871 {
872 int ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_NMI);
873 if (ret)
874 return ret;
875
876 iwl_force_nmi(mvm->trans);
877
878 iwl_mvm_unref(mvm, IWL_MVM_REF_NMI);
879
880 return count;
881 }
882
883 static ssize_t
884 iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
885 char __user *user_buf,
886 size_t count, loff_t *ppos)
887 {
888 struct iwl_mvm *mvm = file->private_data;
889 int pos = 0;
890 char buf[32];
891 const size_t bufsz = sizeof(buf);
892
893 /* print which antennas were set for the scan command by the user */
894 pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
895 if (mvm->scan_rx_ant & ANT_A)
896 pos += scnprintf(buf + pos, bufsz - pos, "A");
897 if (mvm->scan_rx_ant & ANT_B)
898 pos += scnprintf(buf + pos, bufsz - pos, "B");
899 if (mvm->scan_rx_ant & ANT_C)
900 pos += scnprintf(buf + pos, bufsz - pos, "C");
901 pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
902
903 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
904 }
905
906 static ssize_t
907 iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
908 size_t count, loff_t *ppos)
909 {
910 u8 scan_rx_ant;
911
912 if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
913 return -EINVAL;
914 if (scan_rx_ant > ANT_ABC)
915 return -EINVAL;
916 if (scan_rx_ant & ~mvm->fw->valid_rx_ant)
917 return -EINVAL;
918
919 mvm->scan_rx_ant = scan_rx_ant;
920
921 return count;
922 }
923
924 #define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__)
925 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
926 static ssize_t iwl_dbgfs_bcast_filters_read(struct file *file,
927 char __user *user_buf,
928 size_t count, loff_t *ppos)
929 {
930 struct iwl_mvm *mvm = file->private_data;
931 struct iwl_bcast_filter_cmd cmd;
932 const struct iwl_fw_bcast_filter *filter;
933 char *buf;
934 int bufsz = 1024;
935 int i, j, pos = 0;
936 ssize_t ret;
937
938 buf = kzalloc(bufsz, GFP_KERNEL);
939 if (!buf)
940 return -ENOMEM;
941
942 mutex_lock(&mvm->mutex);
943 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
944 ADD_TEXT("None\n");
945 mutex_unlock(&mvm->mutex);
946 goto out;
947 }
948 mutex_unlock(&mvm->mutex);
949
950 for (i = 0; cmd.filters[i].attrs[0].mask; i++) {
951 filter = &cmd.filters[i];
952
953 ADD_TEXT("Filter [%d]:\n", i);
954 ADD_TEXT("\tDiscard=%d\n", filter->discard);
955 ADD_TEXT("\tFrame Type: %s\n",
956 filter->frame_type ? "IPv4" : "Generic");
957
958 for (j = 0; j < ARRAY_SIZE(filter->attrs); j++) {
959 const struct iwl_fw_bcast_filter_attr *attr;
960
961 attr = &filter->attrs[j];
962 if (!attr->mask)
963 break;
964
965 ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n",
966 j, attr->offset,
967 attr->offset_type ? "IP End" :
968 "Payload Start",
969 be32_to_cpu(attr->mask),
970 be32_to_cpu(attr->val),
971 le16_to_cpu(attr->reserved1));
972 }
973 }
974 out:
975 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
976 kfree(buf);
977 return ret;
978 }
979
980 static ssize_t iwl_dbgfs_bcast_filters_write(struct iwl_mvm *mvm, char *buf,
981 size_t count, loff_t *ppos)
982 {
983 int pos, next_pos;
984 struct iwl_fw_bcast_filter filter = {};
985 struct iwl_bcast_filter_cmd cmd;
986 u32 filter_id, attr_id, mask, value;
987 int err = 0;
988
989 if (sscanf(buf, "%d %hhi %hhi %n", &filter_id, &filter.discard,
990 &filter.frame_type, &pos) != 3)
991 return -EINVAL;
992
993 if (filter_id >= ARRAY_SIZE(mvm->dbgfs_bcast_filtering.cmd.filters) ||
994 filter.frame_type > BCAST_FILTER_FRAME_TYPE_IPV4)
995 return -EINVAL;
996
997 for (attr_id = 0; attr_id < ARRAY_SIZE(filter.attrs);
998 attr_id++) {
999 struct iwl_fw_bcast_filter_attr *attr =
1000 &filter.attrs[attr_id];
1001
1002 if (pos >= count)
1003 break;
1004
1005 if (sscanf(&buf[pos], "%hhi %hhi %i %i %n",
1006 &attr->offset, &attr->offset_type,
1007 &mask, &value, &next_pos) != 4)
1008 return -EINVAL;
1009
1010 attr->mask = cpu_to_be32(mask);
1011 attr->val = cpu_to_be32(value);
1012 if (mask)
1013 filter.num_attrs++;
1014
1015 pos += next_pos;
1016 }
1017
1018 mutex_lock(&mvm->mutex);
1019 memcpy(&mvm->dbgfs_bcast_filtering.cmd.filters[filter_id],
1020 &filter, sizeof(filter));
1021
1022 /* send updated bcast filtering configuration */
1023 if (mvm->dbgfs_bcast_filtering.override &&
1024 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1025 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1026 sizeof(cmd), &cmd);
1027 mutex_unlock(&mvm->mutex);
1028
1029 return err ?: count;
1030 }
1031
1032 static ssize_t iwl_dbgfs_bcast_filters_macs_read(struct file *file,
1033 char __user *user_buf,
1034 size_t count, loff_t *ppos)
1035 {
1036 struct iwl_mvm *mvm = file->private_data;
1037 struct iwl_bcast_filter_cmd cmd;
1038 char *buf;
1039 int bufsz = 1024;
1040 int i, pos = 0;
1041 ssize_t ret;
1042
1043 buf = kzalloc(bufsz, GFP_KERNEL);
1044 if (!buf)
1045 return -ENOMEM;
1046
1047 mutex_lock(&mvm->mutex);
1048 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
1049 ADD_TEXT("None\n");
1050 mutex_unlock(&mvm->mutex);
1051 goto out;
1052 }
1053 mutex_unlock(&mvm->mutex);
1054
1055 for (i = 0; i < ARRAY_SIZE(cmd.macs); i++) {
1056 const struct iwl_fw_bcast_mac *mac = &cmd.macs[i];
1057
1058 ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n",
1059 i, mac->default_discard, mac->attached_filters);
1060 }
1061 out:
1062 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1063 kfree(buf);
1064 return ret;
1065 }
1066
1067 static ssize_t iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm *mvm,
1068 char *buf, size_t count,
1069 loff_t *ppos)
1070 {
1071 struct iwl_bcast_filter_cmd cmd;
1072 struct iwl_fw_bcast_mac mac = {};
1073 u32 mac_id, attached_filters;
1074 int err = 0;
1075
1076 if (!mvm->bcast_filters)
1077 return -ENOENT;
1078
1079 if (sscanf(buf, "%d %hhi %i", &mac_id, &mac.default_discard,
1080 &attached_filters) != 3)
1081 return -EINVAL;
1082
1083 if (mac_id >= ARRAY_SIZE(cmd.macs) ||
1084 mac.default_discard > 1 ||
1085 attached_filters >= BIT(ARRAY_SIZE(cmd.filters)))
1086 return -EINVAL;
1087
1088 mac.attached_filters = cpu_to_le16(attached_filters);
1089
1090 mutex_lock(&mvm->mutex);
1091 memcpy(&mvm->dbgfs_bcast_filtering.cmd.macs[mac_id],
1092 &mac, sizeof(mac));
1093
1094 /* send updated bcast filtering configuration */
1095 if (mvm->dbgfs_bcast_filtering.override &&
1096 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1097 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1098 sizeof(cmd), &cmd);
1099 mutex_unlock(&mvm->mutex);
1100
1101 return err ?: count;
1102 }
1103 #endif
1104
1105 #ifdef CONFIG_PM_SLEEP
1106 static ssize_t iwl_dbgfs_d3_sram_write(struct iwl_mvm *mvm, char *buf,
1107 size_t count, loff_t *ppos)
1108 {
1109 int store;
1110
1111 if (sscanf(buf, "%d", &store) != 1)
1112 return -EINVAL;
1113
1114 mvm->store_d3_resume_sram = store;
1115
1116 return count;
1117 }
1118
1119 static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
1120 size_t count, loff_t *ppos)
1121 {
1122 struct iwl_mvm *mvm = file->private_data;
1123 const struct fw_img *img;
1124 int ofs, len, pos = 0;
1125 size_t bufsz, ret;
1126 char *buf;
1127 u8 *ptr = mvm->d3_resume_sram;
1128
1129 img = &mvm->fw->img[IWL_UCODE_WOWLAN];
1130 len = img->sec[IWL_UCODE_SECTION_DATA].len;
1131
1132 bufsz = len * 4 + 256;
1133 buf = kzalloc(bufsz, GFP_KERNEL);
1134 if (!buf)
1135 return -ENOMEM;
1136
1137 pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
1138 mvm->store_d3_resume_sram ? "en" : "dis");
1139
1140 if (ptr) {
1141 for (ofs = 0; ofs < len; ofs += 16) {
1142 pos += scnprintf(buf + pos, bufsz - pos,
1143 "0x%.4x ", ofs);
1144 hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
1145 bufsz - pos, false);
1146 pos += strlen(buf + pos);
1147 if (bufsz - pos > 0)
1148 buf[pos++] = '\n';
1149 }
1150 } else {
1151 pos += scnprintf(buf + pos, bufsz - pos,
1152 "(no data captured)\n");
1153 }
1154
1155 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1156
1157 kfree(buf);
1158
1159 return ret;
1160 }
1161 #endif
1162
1163 #define PRINT_MVM_REF(ref) do { \
1164 if (mvm->refs[ref]) \
1165 pos += scnprintf(buf + pos, bufsz - pos, \
1166 "\t(0x%lx): %d %s\n", \
1167 BIT(ref), mvm->refs[ref], #ref); \
1168 } while (0)
1169
1170 static ssize_t iwl_dbgfs_d0i3_refs_read(struct file *file,
1171 char __user *user_buf,
1172 size_t count, loff_t *ppos)
1173 {
1174 struct iwl_mvm *mvm = file->private_data;
1175 int i, pos = 0;
1176 char buf[256];
1177 const size_t bufsz = sizeof(buf);
1178 u32 refs = 0;
1179
1180 for (i = 0; i < IWL_MVM_REF_COUNT; i++)
1181 if (mvm->refs[i])
1182 refs |= BIT(i);
1183
1184 pos += scnprintf(buf + pos, bufsz - pos, "taken mvm refs: 0x%x\n",
1185 refs);
1186
1187 PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN);
1188 PRINT_MVM_REF(IWL_MVM_REF_SCAN);
1189 PRINT_MVM_REF(IWL_MVM_REF_ROC);
1190 PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT);
1191 PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS);
1192 PRINT_MVM_REF(IWL_MVM_REF_USER);
1193 PRINT_MVM_REF(IWL_MVM_REF_EXIT_WORK);
1194
1195 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1196 }
1197
1198 static ssize_t iwl_dbgfs_d0i3_refs_write(struct iwl_mvm *mvm, char *buf,
1199 size_t count, loff_t *ppos)
1200 {
1201 unsigned long value;
1202 int ret;
1203 bool taken;
1204
1205 ret = kstrtoul(buf, 10, &value);
1206 if (ret < 0)
1207 return ret;
1208
1209 mutex_lock(&mvm->mutex);
1210
1211 taken = mvm->refs[IWL_MVM_REF_USER];
1212 if (value == 1 && !taken)
1213 iwl_mvm_ref(mvm, IWL_MVM_REF_USER);
1214 else if (value == 0 && taken)
1215 iwl_mvm_unref(mvm, IWL_MVM_REF_USER);
1216 else
1217 ret = -EINVAL;
1218
1219 mutex_unlock(&mvm->mutex);
1220
1221 if (ret < 0)
1222 return ret;
1223 return count;
1224 }
1225
1226 #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
1227 _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1228 #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
1229 _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1230 #define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \
1231 if (!debugfs_create_file(alias, mode, parent, mvm, \
1232 &iwl_dbgfs_##name##_ops)) \
1233 goto err; \
1234 } while (0)
1235 #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
1236 MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
1237
1238 static ssize_t
1239 iwl_dbgfs_prph_reg_read(struct file *file,
1240 char __user *user_buf,
1241 size_t count, loff_t *ppos)
1242 {
1243 struct iwl_mvm *mvm = file->private_data;
1244 int pos = 0;
1245 char buf[32];
1246 const size_t bufsz = sizeof(buf);
1247 int ret;
1248
1249 if (!mvm->dbgfs_prph_reg_addr)
1250 return -EINVAL;
1251
1252 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_READ);
1253 if (ret)
1254 return ret;
1255
1256 pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n",
1257 mvm->dbgfs_prph_reg_addr,
1258 iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr));
1259
1260 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_READ);
1261
1262 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1263 }
1264
1265 static ssize_t
1266 iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf,
1267 size_t count, loff_t *ppos)
1268 {
1269 u8 args;
1270 u32 value;
1271 int ret;
1272
1273 args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value);
1274 /* if we only want to set the reg address - nothing more to do */
1275 if (args == 1)
1276 goto out;
1277
1278 /* otherwise, make sure we have both address and value */
1279 if (args != 2)
1280 return -EINVAL;
1281
1282 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
1283 if (ret)
1284 return ret;
1285
1286 iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value);
1287
1288 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
1289 out:
1290 return count;
1291 }
1292
1293 MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);
1294
1295 /* Device wide debugfs entries */
1296 MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
1297 MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
1298 MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64);
1299 MVM_DEBUGFS_READ_FILE_OPS(stations);
1300 MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
1301 MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
1302 MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64);
1303 MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
1304 MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats);
1305 MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10);
1306 MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10);
1307 MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10);
1308 MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant, 10);
1309 MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
1310 MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8);
1311
1312 static const struct file_operations iwl_dbgfs_fw_error_dump_ops = {
1313 .open = iwl_dbgfs_fw_error_dump_open,
1314 .read = iwl_dbgfs_fw_error_dump_read,
1315 .release = iwl_dbgfs_fw_error_dump_release,
1316 };
1317
1318 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1319 MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256);
1320 MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256);
1321 #endif
1322
1323 #ifdef CONFIG_PM_SLEEP
1324 MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8);
1325 #endif
1326
1327 int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
1328 {
1329 struct dentry *bcast_dir __maybe_unused;
1330 char buf[100];
1331
1332 spin_lock_init(&mvm->drv_stats_lock);
1333
1334 mvm->debugfs_dir = dbgfs_dir;
1335
1336 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
1337 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
1338 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
1339 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
1340 MVM_DEBUGFS_ADD_FILE(fw_error_dump, dbgfs_dir, S_IRUSR);
1341 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
1342 MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
1343 MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
1344 S_IRUSR | S_IWUSR);
1345 MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
1346 MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, S_IRUSR);
1347 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
1348 MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR);
1349 MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, S_IWUSR);
1350 MVM_DEBUGFS_ADD_FILE(bt_force_ant, mvm->debugfs_dir, S_IWUSR);
1351 MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
1352 S_IWUSR | S_IRUSR);
1353 MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
1354 MVM_DEBUGFS_ADD_FILE(d0i3_refs, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
1355
1356 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1357 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING) {
1358 bcast_dir = debugfs_create_dir("bcast_filtering",
1359 mvm->debugfs_dir);
1360 if (!bcast_dir)
1361 goto err;
1362
1363 if (!debugfs_create_bool("override", S_IRUSR | S_IWUSR,
1364 bcast_dir,
1365 &mvm->dbgfs_bcast_filtering.override))
1366 goto err;
1367
1368 MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters,
1369 bcast_dir, S_IWUSR | S_IRUSR);
1370 MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs,
1371 bcast_dir, S_IWUSR | S_IRUSR);
1372 }
1373 #endif
1374
1375 #ifdef CONFIG_PM_SLEEP
1376 MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
1377 MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
1378 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
1379 mvm->debugfs_dir, &mvm->d3_wake_sysassert))
1380 goto err;
1381 #endif
1382
1383 if (!debugfs_create_blob("nvm_hw", S_IRUSR,
1384 mvm->debugfs_dir, &mvm->nvm_hw_blob))
1385 goto err;
1386 if (!debugfs_create_blob("nvm_sw", S_IRUSR,
1387 mvm->debugfs_dir, &mvm->nvm_sw_blob))
1388 goto err;
1389 if (!debugfs_create_blob("nvm_calib", S_IRUSR,
1390 mvm->debugfs_dir, &mvm->nvm_calib_blob))
1391 goto err;
1392 if (!debugfs_create_blob("nvm_prod", S_IRUSR,
1393 mvm->debugfs_dir, &mvm->nvm_prod_blob))
1394 goto err;
1395
1396 /*
1397 * Create a symlink with mac80211. It will be removed when mac80211
1398 * exists (before the opmode exists which removes the target.)
1399 */
1400 snprintf(buf, 100, "../../%s/%s",
1401 dbgfs_dir->d_parent->d_parent->d_name.name,
1402 dbgfs_dir->d_parent->d_name.name);
1403 if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
1404 goto err;
1405
1406 return 0;
1407 err:
1408 IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
1409 return -ENOMEM;
1410 }
This page took 0.099061 seconds and 5 git commands to generate.