1 /******************************************************************************
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.
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
25 * The full GNU General Public License is included in this distribution
26 * in the file called COPYING.
28 * Contact Information:
29 * Intel Linux Wireless <ilw@linux.intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
34 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
35 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
36 * All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 *****************************************************************************/
65 #include <linux/vmalloc.h>
71 #include "iwl-fw-error-dump.h"
73 static ssize_t
iwl_dbgfs_tx_flush_write(struct iwl_mvm
*mvm
, char *buf
,
74 size_t count
, loff_t
*ppos
)
79 if (!mvm
->ucode_loaded
|| mvm
->cur_ucode
!= IWL_UCODE_REGULAR
)
82 if (sscanf(buf
, "%x", &scd_q_msk
) != 1)
85 IWL_ERR(mvm
, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk
);
87 mutex_lock(&mvm
->mutex
);
88 ret
= iwl_mvm_flush_tx_path(mvm
, scd_q_msk
, true) ? : count
;
89 mutex_unlock(&mvm
->mutex
);
94 static ssize_t
iwl_dbgfs_sta_drain_write(struct iwl_mvm
*mvm
, char *buf
,
95 size_t count
, loff_t
*ppos
)
97 struct iwl_mvm_sta
*mvmsta
;
98 int sta_id
, drain
, ret
;
100 if (!mvm
->ucode_loaded
|| mvm
->cur_ucode
!= IWL_UCODE_REGULAR
)
103 if (sscanf(buf
, "%d %d", &sta_id
, &drain
) != 2)
105 if (sta_id
< 0 || sta_id
>= IWL_MVM_STATION_COUNT
)
107 if (drain
< 0 || drain
> 1)
110 mutex_lock(&mvm
->mutex
);
112 mvmsta
= iwl_mvm_sta_from_staid_protected(mvm
, sta_id
);
117 ret
= iwl_mvm_drain_sta(mvm
, mvmsta
, drain
) ? : count
;
119 mutex_unlock(&mvm
->mutex
);
124 static int iwl_dbgfs_fw_error_dump_open(struct inode
*inode
, struct file
*file
)
126 struct iwl_mvm
*mvm
= inode
->i_private
;
132 mutex_lock(&mvm
->mutex
);
133 if (!mvm
->fw_error_dump
) {
138 file
->private_data
= mvm
->fw_error_dump
;
139 mvm
->fw_error_dump
= NULL
;
143 mutex_unlock(&mvm
->mutex
);
147 static ssize_t
iwl_dbgfs_fw_error_dump_read(struct file
*file
,
148 char __user
*user_buf
,
149 size_t count
, loff_t
*ppos
)
151 struct iwl_mvm_dump_ptrs
*dump_ptrs
= (void *)file
->private_data
;
152 ssize_t bytes_read
= 0;
153 ssize_t bytes_read_trans
= 0;
155 if (*ppos
< dump_ptrs
->op_mode_len
)
157 simple_read_from_buffer(user_buf
, count
, ppos
,
158 dump_ptrs
->op_mode_ptr
,
159 dump_ptrs
->op_mode_len
);
161 if (bytes_read
< 0 || *ppos
< dump_ptrs
->op_mode_len
)
164 if (dump_ptrs
->trans_ptr
) {
165 *ppos
-= dump_ptrs
->op_mode_len
;
167 simple_read_from_buffer(user_buf
+ bytes_read
,
168 count
- bytes_read
, ppos
,
169 dump_ptrs
->trans_ptr
->data
,
170 dump_ptrs
->trans_ptr
->len
);
171 *ppos
+= dump_ptrs
->op_mode_len
;
173 if (bytes_read_trans
>= 0)
174 bytes_read
+= bytes_read_trans
;
175 else if (!bytes_read
)
176 /* propagate the failure */
177 return bytes_read_trans
;
184 static int iwl_dbgfs_fw_error_dump_release(struct inode
*inode
,
187 struct iwl_mvm_dump_ptrs
*dump_ptrs
= (void *)file
->private_data
;
189 vfree(dump_ptrs
->op_mode_ptr
);
190 vfree(dump_ptrs
->trans_ptr
);
196 static ssize_t
iwl_dbgfs_sram_read(struct file
*file
, char __user
*user_buf
,
197 size_t count
, loff_t
*ppos
)
199 struct iwl_mvm
*mvm
= file
->private_data
;
200 const struct fw_img
*img
;
201 unsigned int ofs
, len
;
205 if (!mvm
->ucode_loaded
)
208 /* default is to dump the entire data segment */
209 img
= &mvm
->fw
->img
[mvm
->cur_ucode
];
210 ofs
= img
->sec
[IWL_UCODE_SECTION_DATA
].offset
;
211 len
= img
->sec
[IWL_UCODE_SECTION_DATA
].len
;
213 if (mvm
->dbgfs_sram_len
) {
214 ofs
= mvm
->dbgfs_sram_offset
;
215 len
= mvm
->dbgfs_sram_len
;
218 ptr
= kzalloc(len
, GFP_KERNEL
);
222 iwl_trans_read_mem_bytes(mvm
->trans
, ofs
, ptr
, len
);
224 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, ptr
, len
);
231 static ssize_t
iwl_dbgfs_sram_write(struct iwl_mvm
*mvm
, char *buf
,
232 size_t count
, loff_t
*ppos
)
234 const struct fw_img
*img
;
236 u32 img_offset
, img_len
;
238 if (!mvm
->ucode_loaded
)
241 img
= &mvm
->fw
->img
[mvm
->cur_ucode
];
242 img_offset
= img
->sec
[IWL_UCODE_SECTION_DATA
].offset
;
243 img_len
= img
->sec
[IWL_UCODE_SECTION_DATA
].len
;
245 if (sscanf(buf
, "%x,%x", &offset
, &len
) == 2) {
246 if ((offset
& 0x3) || (len
& 0x3))
249 if (offset
+ len
> img_offset
+ img_len
)
252 mvm
->dbgfs_sram_offset
= offset
;
253 mvm
->dbgfs_sram_len
= len
;
255 mvm
->dbgfs_sram_offset
= 0;
256 mvm
->dbgfs_sram_len
= 0;
262 static ssize_t
iwl_dbgfs_set_nic_temperature_read(struct file
*file
,
263 char __user
*user_buf
,
264 size_t count
, loff_t
*ppos
)
266 struct iwl_mvm
*mvm
= file
->private_data
;
270 if (!mvm
->temperature_test
)
271 pos
= scnprintf(buf
, sizeof(buf
), "disabled\n");
273 pos
= scnprintf(buf
, sizeof(buf
), "%d\n", mvm
->temperature
);
275 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
279 * Set NIC Temperature
280 * Cause the driver to ignore the actual NIC temperature reported by the FW
281 * Enable: any value between IWL_MVM_DEBUG_SET_TEMPERATURE_MIN -
282 * IWL_MVM_DEBUG_SET_TEMPERATURE_MAX
283 * Disable: IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE
285 static ssize_t
iwl_dbgfs_set_nic_temperature_write(struct iwl_mvm
*mvm
,
286 char *buf
, size_t count
,
291 if (!mvm
->ucode_loaded
&& !mvm
->temperature_test
)
294 if (kstrtoint(buf
, 10, &temperature
))
296 /* not a legal temperature */
297 if ((temperature
> IWL_MVM_DEBUG_SET_TEMPERATURE_MAX
&&
298 temperature
!= IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE
) ||
299 temperature
< IWL_MVM_DEBUG_SET_TEMPERATURE_MIN
)
302 mutex_lock(&mvm
->mutex
);
303 if (temperature
== IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE
) {
304 if (!mvm
->temperature_test
)
307 mvm
->temperature_test
= false;
308 /* Since we can't read the temp while awake, just set
309 * it to zero until we get the next RX stats from the
312 mvm
->temperature
= 0;
314 mvm
->temperature_test
= true;
315 mvm
->temperature
= temperature
;
317 IWL_DEBUG_TEMP(mvm
, "%sabling debug set temperature (temp = %d)\n",
318 mvm
->temperature_test
? "En" : "Dis" ,
320 /* handle the temperature change */
321 iwl_mvm_tt_handler(mvm
);
324 mutex_unlock(&mvm
->mutex
);
329 static ssize_t
iwl_dbgfs_stations_read(struct file
*file
, char __user
*user_buf
,
330 size_t count
, loff_t
*ppos
)
332 struct iwl_mvm
*mvm
= file
->private_data
;
333 struct ieee80211_sta
*sta
;
335 int i
, pos
= 0, bufsz
= sizeof(buf
);
337 mutex_lock(&mvm
->mutex
);
339 for (i
= 0; i
< IWL_MVM_STATION_COUNT
; i
++) {
340 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "%.2d: ", i
);
341 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[i
],
342 lockdep_is_held(&mvm
->mutex
));
344 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "N/A\n");
345 else if (IS_ERR(sta
))
346 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "%ld\n",
349 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "%pM\n",
353 mutex_unlock(&mvm
->mutex
);
355 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
358 static ssize_t
iwl_dbgfs_disable_power_off_read(struct file
*file
,
359 char __user
*user_buf
,
360 size_t count
, loff_t
*ppos
)
362 struct iwl_mvm
*mvm
= file
->private_data
;
364 int bufsz
= sizeof(buf
);
367 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "disable_power_off_d0=%d\n",
368 mvm
->disable_power_off
);
369 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "disable_power_off_d3=%d\n",
370 mvm
->disable_power_off_d3
);
372 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
375 static ssize_t
iwl_dbgfs_disable_power_off_write(struct iwl_mvm
*mvm
, char *buf
,
376 size_t count
, loff_t
*ppos
)
380 if (!mvm
->ucode_loaded
)
383 if (!strncmp("disable_power_off_d0=", buf
, 21)) {
384 if (sscanf(buf
+ 21, "%d", &val
) != 1)
386 mvm
->disable_power_off
= val
;
387 } else if (!strncmp("disable_power_off_d3=", buf
, 21)) {
388 if (sscanf(buf
+ 21, "%d", &val
) != 1)
390 mvm
->disable_power_off_d3
= val
;
395 mutex_lock(&mvm
->mutex
);
396 ret
= iwl_mvm_power_update_device(mvm
);
397 mutex_unlock(&mvm
->mutex
);
402 #define BT_MBOX_MSG(_notif, _num, _field) \
403 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
404 >> BT_MBOX##_num##_##_field##_POS)
407 #define BT_MBOX_PRINT(_num, _field, _end) \
408 pos += scnprintf(buf + pos, bufsz - pos, \
411 BT_MBOX_MSG(notif, _num, _field), \
415 int iwl_mvm_coex_dump_mbox(struct iwl_bt_coex_profile_notif
*notif
, char *buf
,
418 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "MBOX dw0:\n");
420 BT_MBOX_PRINT(0, LE_SLAVE_LAT
, false);
421 BT_MBOX_PRINT(0, LE_PROF1
, false);
422 BT_MBOX_PRINT(0, LE_PROF2
, false);
423 BT_MBOX_PRINT(0, LE_PROF_OTHER
, false);
424 BT_MBOX_PRINT(0, CHL_SEQ_N
, false);
425 BT_MBOX_PRINT(0, INBAND_S
, false);
426 BT_MBOX_PRINT(0, LE_MIN_RSSI
, false);
427 BT_MBOX_PRINT(0, LE_SCAN
, false);
428 BT_MBOX_PRINT(0, LE_ADV
, false);
429 BT_MBOX_PRINT(0, LE_MAX_TX_POWER
, false);
430 BT_MBOX_PRINT(0, OPEN_CON_1
, true);
432 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "MBOX dw1:\n");
434 BT_MBOX_PRINT(1, BR_MAX_TX_POWER
, false);
435 BT_MBOX_PRINT(1, IP_SR
, false);
436 BT_MBOX_PRINT(1, LE_MSTR
, false);
437 BT_MBOX_PRINT(1, AGGR_TRFC_LD
, false);
438 BT_MBOX_PRINT(1, MSG_TYPE
, false);
439 BT_MBOX_PRINT(1, SSN
, true);
441 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "MBOX dw2:\n");
443 BT_MBOX_PRINT(2, SNIFF_ACT
, false);
444 BT_MBOX_PRINT(2, PAG
, false);
445 BT_MBOX_PRINT(2, INQUIRY
, false);
446 BT_MBOX_PRINT(2, CONN
, false);
447 BT_MBOX_PRINT(2, SNIFF_INTERVAL
, false);
448 BT_MBOX_PRINT(2, DISC
, false);
449 BT_MBOX_PRINT(2, SCO_TX_ACT
, false);
450 BT_MBOX_PRINT(2, SCO_RX_ACT
, false);
451 BT_MBOX_PRINT(2, ESCO_RE_TX
, false);
452 BT_MBOX_PRINT(2, SCO_DURATION
, true);
454 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "MBOX dw3:\n");
456 BT_MBOX_PRINT(3, SCO_STATE
, false);
457 BT_MBOX_PRINT(3, SNIFF_STATE
, false);
458 BT_MBOX_PRINT(3, A2DP_STATE
, false);
459 BT_MBOX_PRINT(3, ACL_STATE
, false);
460 BT_MBOX_PRINT(3, MSTR_STATE
, false);
461 BT_MBOX_PRINT(3, OBX_STATE
, false);
462 BT_MBOX_PRINT(3, OPEN_CON_2
, false);
463 BT_MBOX_PRINT(3, TRAFFIC_LOAD
, false);
464 BT_MBOX_PRINT(3, CHL_SEQN_LSB
, false);
465 BT_MBOX_PRINT(3, INBAND_P
, false);
466 BT_MBOX_PRINT(3, MSG_TYPE_2
, false);
467 BT_MBOX_PRINT(3, SSN_2
, false);
468 BT_MBOX_PRINT(3, UPDATE_REQUEST
, true);
474 int iwl_mvm_coex_dump_mbox_old(struct iwl_bt_coex_profile_notif_old
*notif
,
475 char *buf
, int pos
, int bufsz
)
477 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "MBOX dw0:\n");
479 BT_MBOX_PRINT(0, LE_SLAVE_LAT
, false);
480 BT_MBOX_PRINT(0, LE_PROF1
, false);
481 BT_MBOX_PRINT(0, LE_PROF2
, false);
482 BT_MBOX_PRINT(0, LE_PROF_OTHER
, false);
483 BT_MBOX_PRINT(0, CHL_SEQ_N
, false);
484 BT_MBOX_PRINT(0, INBAND_S
, false);
485 BT_MBOX_PRINT(0, LE_MIN_RSSI
, false);
486 BT_MBOX_PRINT(0, LE_SCAN
, false);
487 BT_MBOX_PRINT(0, LE_ADV
, false);
488 BT_MBOX_PRINT(0, LE_MAX_TX_POWER
, false);
489 BT_MBOX_PRINT(0, OPEN_CON_1
, true);
491 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "MBOX dw1:\n");
493 BT_MBOX_PRINT(1, BR_MAX_TX_POWER
, false);
494 BT_MBOX_PRINT(1, IP_SR
, false);
495 BT_MBOX_PRINT(1, LE_MSTR
, false);
496 BT_MBOX_PRINT(1, AGGR_TRFC_LD
, false);
497 BT_MBOX_PRINT(1, MSG_TYPE
, false);
498 BT_MBOX_PRINT(1, SSN
, true);
500 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "MBOX dw2:\n");
502 BT_MBOX_PRINT(2, SNIFF_ACT
, false);
503 BT_MBOX_PRINT(2, PAG
, false);
504 BT_MBOX_PRINT(2, INQUIRY
, false);
505 BT_MBOX_PRINT(2, CONN
, false);
506 BT_MBOX_PRINT(2, SNIFF_INTERVAL
, false);
507 BT_MBOX_PRINT(2, DISC
, false);
508 BT_MBOX_PRINT(2, SCO_TX_ACT
, false);
509 BT_MBOX_PRINT(2, SCO_RX_ACT
, false);
510 BT_MBOX_PRINT(2, ESCO_RE_TX
, false);
511 BT_MBOX_PRINT(2, SCO_DURATION
, true);
513 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "MBOX dw3:\n");
515 BT_MBOX_PRINT(3, SCO_STATE
, false);
516 BT_MBOX_PRINT(3, SNIFF_STATE
, false);
517 BT_MBOX_PRINT(3, A2DP_STATE
, false);
518 BT_MBOX_PRINT(3, ACL_STATE
, false);
519 BT_MBOX_PRINT(3, MSTR_STATE
, false);
520 BT_MBOX_PRINT(3, OBX_STATE
, false);
521 BT_MBOX_PRINT(3, OPEN_CON_2
, false);
522 BT_MBOX_PRINT(3, TRAFFIC_LOAD
, false);
523 BT_MBOX_PRINT(3, CHL_SEQN_LSB
, false);
524 BT_MBOX_PRINT(3, INBAND_P
, false);
525 BT_MBOX_PRINT(3, MSG_TYPE_2
, false);
526 BT_MBOX_PRINT(3, SSN_2
, false);
527 BT_MBOX_PRINT(3, UPDATE_REQUEST
, true);
532 static ssize_t
iwl_dbgfs_bt_notif_read(struct file
*file
, char __user
*user_buf
,
533 size_t count
, loff_t
*ppos
)
535 struct iwl_mvm
*mvm
= file
->private_data
;
537 int ret
, pos
= 0, bufsz
= sizeof(char) * 1024;
539 buf
= kmalloc(bufsz
, GFP_KERNEL
);
543 mutex_lock(&mvm
->mutex
);
545 if (!(mvm
->fw
->ucode_capa
.api
[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT
)) {
546 struct iwl_bt_coex_profile_notif_old
*notif
=
547 &mvm
->last_bt_notif_old
;
549 pos
+= iwl_mvm_coex_dump_mbox_old(notif
, buf
, pos
, bufsz
);
551 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "bt_ci_compliance = %d\n",
552 notif
->bt_ci_compliance
);
553 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "primary_ch_lut = %d\n",
554 le32_to_cpu(notif
->primary_ch_lut
));
555 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "secondary_ch_lut = %d\n",
556 le32_to_cpu(notif
->secondary_ch_lut
));
557 pos
+= scnprintf(buf
+pos
,
558 bufsz
-pos
, "bt_activity_grading = %d\n",
559 le32_to_cpu(notif
->bt_activity_grading
));
560 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
561 "antenna isolation = %d CORUN LUT index = %d\n",
562 mvm
->last_ant_isol
, mvm
->last_corun_lut
);
564 struct iwl_bt_coex_profile_notif
*notif
=
567 pos
+= iwl_mvm_coex_dump_mbox(notif
, buf
, pos
, bufsz
);
569 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "bt_ci_compliance = %d\n",
570 notif
->bt_ci_compliance
);
571 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "primary_ch_lut = %d\n",
572 le32_to_cpu(notif
->primary_ch_lut
));
573 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "secondary_ch_lut = %d\n",
574 le32_to_cpu(notif
->secondary_ch_lut
));
575 pos
+= scnprintf(buf
+pos
,
576 bufsz
-pos
, "bt_activity_grading = %d\n",
577 le32_to_cpu(notif
->bt_activity_grading
));
578 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
579 "antenna isolation = %d CORUN LUT index = %d\n",
580 mvm
->last_ant_isol
, mvm
->last_corun_lut
);
583 mutex_unlock(&mvm
->mutex
);
585 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
592 static ssize_t
iwl_dbgfs_bt_cmd_read(struct file
*file
, char __user
*user_buf
,
593 size_t count
, loff_t
*ppos
)
595 struct iwl_mvm
*mvm
= file
->private_data
;
597 int bufsz
= sizeof(buf
);
600 mutex_lock(&mvm
->mutex
);
602 if (!(mvm
->fw
->ucode_capa
.api
[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT
)) {
603 struct iwl_bt_coex_ci_cmd_old
*cmd
= &mvm
->last_bt_ci_cmd_old
;
605 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
606 "Channel inhibition CMD\n");
607 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
608 "\tPrimary Channel Bitmap 0x%016llx\n",
609 le64_to_cpu(cmd
->bt_primary_ci
));
610 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
611 "\tSecondary Channel Bitmap 0x%016llx\n",
612 le64_to_cpu(cmd
->bt_secondary_ci
));
614 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "BT Configuration CMD\n");
615 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "\tACK Kill Mask 0x%08x\n",
616 iwl_bt_ctl_kill_msk
[mvm
->bt_ack_kill_msk
[0]]);
617 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "\tCTS Kill Mask 0x%08x\n",
618 iwl_bt_ctl_kill_msk
[mvm
->bt_cts_kill_msk
[0]]);
621 struct iwl_bt_coex_ci_cmd
*cmd
= &mvm
->last_bt_ci_cmd
;
623 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
624 "Channel inhibition CMD\n");
625 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
626 "\tPrimary Channel Bitmap 0x%016llx\n",
627 le64_to_cpu(cmd
->bt_primary_ci
));
628 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
629 "\tSecondary Channel Bitmap 0x%016llx\n",
630 le64_to_cpu(cmd
->bt_secondary_ci
));
632 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "BT Configuration CMD\n");
633 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
634 "\tPrimary: ACK Kill Mask 0x%08x\n",
635 iwl_bt_ctl_kill_msk
[mvm
->bt_ack_kill_msk
[0]]);
636 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
637 "\tPrimary: CTS Kill Mask 0x%08x\n",
638 iwl_bt_ctl_kill_msk
[mvm
->bt_cts_kill_msk
[0]]);
639 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
640 "\tSecondary: ACK Kill Mask 0x%08x\n",
641 iwl_bt_ctl_kill_msk
[mvm
->bt_ack_kill_msk
[1]]);
642 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
643 "\tSecondary: CTS Kill Mask 0x%08x\n",
644 iwl_bt_ctl_kill_msk
[mvm
->bt_cts_kill_msk
[1]]);
648 mutex_unlock(&mvm
->mutex
);
650 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
654 iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm
*mvm
, char *buf
,
655 size_t count
, loff_t
*ppos
)
659 if (sscanf(buf
, "%u", &bt_tx_prio
) != 1)
664 mvm
->bt_tx_prio
= bt_tx_prio
;
670 iwl_dbgfs_bt_force_ant_write(struct iwl_mvm
*mvm
, char *buf
,
671 size_t count
, loff_t
*ppos
)
673 static const char * const modes_str
[BT_FORCE_ANT_MAX
] = {
674 [BT_FORCE_ANT_DIS
] = "dis",
675 [BT_FORCE_ANT_AUTO
] = "auto",
676 [BT_FORCE_ANT_BT
] = "bt",
677 [BT_FORCE_ANT_WIFI
] = "wifi",
679 int ret
, bt_force_ant_mode
;
681 for (bt_force_ant_mode
= 0;
682 bt_force_ant_mode
< ARRAY_SIZE(modes_str
);
683 bt_force_ant_mode
++) {
684 if (!strcmp(buf
, modes_str
[bt_force_ant_mode
]))
688 if (bt_force_ant_mode
>= ARRAY_SIZE(modes_str
))
692 mutex_lock(&mvm
->mutex
);
693 if (mvm
->bt_force_ant_mode
== bt_force_ant_mode
)
696 mvm
->bt_force_ant_mode
= bt_force_ant_mode
;
697 IWL_DEBUG_COEX(mvm
, "Force mode: %s\n",
698 modes_str
[mvm
->bt_force_ant_mode
]);
699 ret
= iwl_send_bt_init_conf(mvm
);
702 mutex_unlock(&mvm
->mutex
);
706 #define PRINT_STATS_LE32(_str, _val) \
707 pos += scnprintf(buf + pos, bufsz - pos, \
711 static ssize_t
iwl_dbgfs_fw_rx_stats_read(struct file
*file
,
712 char __user
*user_buf
, size_t count
,
715 struct iwl_mvm
*mvm
= file
->private_data
;
716 static const char *fmt_table
= "\t%-30s %10u\n";
717 static const char *fmt_header
= "%-32s\n";
721 /* 43 is the size of each data line, 33 is the size of each header */
723 ((sizeof(struct mvm_statistics_rx
) / sizeof(__le32
)) * 43) +
726 struct mvm_statistics_rx_phy
*ofdm
;
727 struct mvm_statistics_rx_phy
*cck
;
728 struct mvm_statistics_rx_non_phy
*general
;
729 struct mvm_statistics_rx_ht_phy
*ht
;
731 buf
= kzalloc(bufsz
, GFP_KERNEL
);
735 mutex_lock(&mvm
->mutex
);
737 ofdm
= &mvm
->rx_stats
.ofdm
;
738 cck
= &mvm
->rx_stats
.cck
;
739 general
= &mvm
->rx_stats
.general
;
740 ht
= &mvm
->rx_stats
.ofdm_ht
;
742 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, fmt_header
,
743 "Statistics_Rx - OFDM");
744 PRINT_STATS_LE32("ina_cnt", ofdm
->ina_cnt
);
745 PRINT_STATS_LE32("fina_cnt", ofdm
->fina_cnt
);
746 PRINT_STATS_LE32("plcp_err", ofdm
->plcp_err
);
747 PRINT_STATS_LE32("crc32_err", ofdm
->crc32_err
);
748 PRINT_STATS_LE32("overrun_err", ofdm
->overrun_err
);
749 PRINT_STATS_LE32("early_overrun_err", ofdm
->early_overrun_err
);
750 PRINT_STATS_LE32("crc32_good", ofdm
->crc32_good
);
751 PRINT_STATS_LE32("false_alarm_cnt", ofdm
->false_alarm_cnt
);
752 PRINT_STATS_LE32("fina_sync_err_cnt", ofdm
->fina_sync_err_cnt
);
753 PRINT_STATS_LE32("sfd_timeout", ofdm
->sfd_timeout
);
754 PRINT_STATS_LE32("fina_timeout", ofdm
->fina_timeout
);
755 PRINT_STATS_LE32("unresponded_rts", ofdm
->unresponded_rts
);
756 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
757 ofdm
->rxe_frame_limit_overrun
);
758 PRINT_STATS_LE32("sent_ack_cnt", ofdm
->sent_ack_cnt
);
759 PRINT_STATS_LE32("sent_cts_cnt", ofdm
->sent_cts_cnt
);
760 PRINT_STATS_LE32("sent_ba_rsp_cnt", ofdm
->sent_ba_rsp_cnt
);
761 PRINT_STATS_LE32("dsp_self_kill", ofdm
->dsp_self_kill
);
762 PRINT_STATS_LE32("mh_format_err", ofdm
->mh_format_err
);
763 PRINT_STATS_LE32("re_acq_main_rssi_sum", ofdm
->re_acq_main_rssi_sum
);
764 PRINT_STATS_LE32("reserved", ofdm
->reserved
);
766 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, fmt_header
,
767 "Statistics_Rx - CCK");
768 PRINT_STATS_LE32("ina_cnt", cck
->ina_cnt
);
769 PRINT_STATS_LE32("fina_cnt", cck
->fina_cnt
);
770 PRINT_STATS_LE32("plcp_err", cck
->plcp_err
);
771 PRINT_STATS_LE32("crc32_err", cck
->crc32_err
);
772 PRINT_STATS_LE32("overrun_err", cck
->overrun_err
);
773 PRINT_STATS_LE32("early_overrun_err", cck
->early_overrun_err
);
774 PRINT_STATS_LE32("crc32_good", cck
->crc32_good
);
775 PRINT_STATS_LE32("false_alarm_cnt", cck
->false_alarm_cnt
);
776 PRINT_STATS_LE32("fina_sync_err_cnt", cck
->fina_sync_err_cnt
);
777 PRINT_STATS_LE32("sfd_timeout", cck
->sfd_timeout
);
778 PRINT_STATS_LE32("fina_timeout", cck
->fina_timeout
);
779 PRINT_STATS_LE32("unresponded_rts", cck
->unresponded_rts
);
780 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
781 cck
->rxe_frame_limit_overrun
);
782 PRINT_STATS_LE32("sent_ack_cnt", cck
->sent_ack_cnt
);
783 PRINT_STATS_LE32("sent_cts_cnt", cck
->sent_cts_cnt
);
784 PRINT_STATS_LE32("sent_ba_rsp_cnt", cck
->sent_ba_rsp_cnt
);
785 PRINT_STATS_LE32("dsp_self_kill", cck
->dsp_self_kill
);
786 PRINT_STATS_LE32("mh_format_err", cck
->mh_format_err
);
787 PRINT_STATS_LE32("re_acq_main_rssi_sum", cck
->re_acq_main_rssi_sum
);
788 PRINT_STATS_LE32("reserved", cck
->reserved
);
790 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, fmt_header
,
791 "Statistics_Rx - GENERAL");
792 PRINT_STATS_LE32("bogus_cts", general
->bogus_cts
);
793 PRINT_STATS_LE32("bogus_ack", general
->bogus_ack
);
794 PRINT_STATS_LE32("non_bssid_frames", general
->non_bssid_frames
);
795 PRINT_STATS_LE32("filtered_frames", general
->filtered_frames
);
796 PRINT_STATS_LE32("non_channel_beacons", general
->non_channel_beacons
);
797 PRINT_STATS_LE32("channel_beacons", general
->channel_beacons
);
798 PRINT_STATS_LE32("num_missed_bcon", general
->num_missed_bcon
);
799 PRINT_STATS_LE32("adc_rx_saturation_time",
800 general
->adc_rx_saturation_time
);
801 PRINT_STATS_LE32("ina_detection_search_time",
802 general
->ina_detection_search_time
);
803 PRINT_STATS_LE32("beacon_silence_rssi_a",
804 general
->beacon_silence_rssi_a
);
805 PRINT_STATS_LE32("beacon_silence_rssi_b",
806 general
->beacon_silence_rssi_b
);
807 PRINT_STATS_LE32("beacon_silence_rssi_c",
808 general
->beacon_silence_rssi_c
);
809 PRINT_STATS_LE32("interference_data_flag",
810 general
->interference_data_flag
);
811 PRINT_STATS_LE32("channel_load", general
->channel_load
);
812 PRINT_STATS_LE32("dsp_false_alarms", general
->dsp_false_alarms
);
813 PRINT_STATS_LE32("beacon_rssi_a", general
->beacon_rssi_a
);
814 PRINT_STATS_LE32("beacon_rssi_b", general
->beacon_rssi_b
);
815 PRINT_STATS_LE32("beacon_rssi_c", general
->beacon_rssi_c
);
816 PRINT_STATS_LE32("beacon_energy_a", general
->beacon_energy_a
);
817 PRINT_STATS_LE32("beacon_energy_b", general
->beacon_energy_b
);
818 PRINT_STATS_LE32("beacon_energy_c", general
->beacon_energy_c
);
819 PRINT_STATS_LE32("num_bt_kills", general
->num_bt_kills
);
820 PRINT_STATS_LE32("mac_id", general
->mac_id
);
821 PRINT_STATS_LE32("directed_data_mpdu", general
->directed_data_mpdu
);
823 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, fmt_header
,
824 "Statistics_Rx - HT");
825 PRINT_STATS_LE32("plcp_err", ht
->plcp_err
);
826 PRINT_STATS_LE32("overrun_err", ht
->overrun_err
);
827 PRINT_STATS_LE32("early_overrun_err", ht
->early_overrun_err
);
828 PRINT_STATS_LE32("crc32_good", ht
->crc32_good
);
829 PRINT_STATS_LE32("crc32_err", ht
->crc32_err
);
830 PRINT_STATS_LE32("mh_format_err", ht
->mh_format_err
);
831 PRINT_STATS_LE32("agg_crc32_good", ht
->agg_crc32_good
);
832 PRINT_STATS_LE32("agg_mpdu_cnt", ht
->agg_mpdu_cnt
);
833 PRINT_STATS_LE32("agg_cnt", ht
->agg_cnt
);
834 PRINT_STATS_LE32("unsupport_mcs", ht
->unsupport_mcs
);
836 mutex_unlock(&mvm
->mutex
);
838 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
843 #undef PRINT_STAT_LE32
845 static ssize_t
iwl_dbgfs_frame_stats_read(struct iwl_mvm
*mvm
,
846 char __user
*user_buf
, size_t count
,
848 struct iwl_mvm_frame_stats
*stats
)
850 char *buff
, *pos
, *endpos
;
853 static const size_t bufsz
= 1024;
855 buff
= kmalloc(bufsz
, GFP_KERNEL
);
859 spin_lock_bh(&mvm
->drv_stats_lock
);
862 endpos
= pos
+ bufsz
;
864 pos
+= scnprintf(pos
, endpos
- pos
,
865 "Legacy/HT/VHT\t:\t%d/%d/%d\n",
866 stats
->legacy_frames
,
869 pos
+= scnprintf(pos
, endpos
- pos
, "20/40/80\t:\t%d/%d/%d\n",
872 stats
->bw_80_frames
);
873 pos
+= scnprintf(pos
, endpos
- pos
, "NGI/SGI\t\t:\t%d/%d\n",
876 pos
+= scnprintf(pos
, endpos
- pos
, "SISO/MIMO2\t:\t%d/%d\n",
878 stats
->mimo2_frames
);
879 pos
+= scnprintf(pos
, endpos
- pos
, "FAIL/SCSS\t:\t%d/%d\n",
881 stats
->success_frames
);
882 pos
+= scnprintf(pos
, endpos
- pos
, "MPDUs agg\t:\t%d\n",
884 pos
+= scnprintf(pos
, endpos
- pos
, "A-MPDUs\t\t:\t%d\n",
886 pos
+= scnprintf(pos
, endpos
- pos
, "Avg MPDUs/A-MPDU:\t%d\n",
887 stats
->ampdu_count
> 0 ?
888 (stats
->agg_frames
/ stats
->ampdu_count
) : 0);
890 pos
+= scnprintf(pos
, endpos
- pos
, "Last Rates\n");
892 idx
= stats
->last_frame_idx
- 1;
893 for (i
= 0; i
< ARRAY_SIZE(stats
->last_rates
); i
++) {
894 idx
= (idx
+ 1) % ARRAY_SIZE(stats
->last_rates
);
895 if (stats
->last_rates
[idx
] == 0)
897 pos
+= scnprintf(pos
, endpos
- pos
, "Rate[%d]: ",
898 (int)(ARRAY_SIZE(stats
->last_rates
) - i
));
899 pos
+= rs_pretty_print_rate(pos
, stats
->last_rates
[idx
]);
901 spin_unlock_bh(&mvm
->drv_stats_lock
);
903 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buff
, pos
- buff
);
909 static ssize_t
iwl_dbgfs_drv_rx_stats_read(struct file
*file
,
910 char __user
*user_buf
, size_t count
,
913 struct iwl_mvm
*mvm
= file
->private_data
;
915 return iwl_dbgfs_frame_stats_read(mvm
, user_buf
, count
, ppos
,
919 static ssize_t
iwl_dbgfs_fw_restart_write(struct iwl_mvm
*mvm
, char *buf
,
920 size_t count
, loff_t
*ppos
)
924 mutex_lock(&mvm
->mutex
);
926 /* allow one more restart that we're provoking here */
927 if (mvm
->restart_fw
>= 0)
930 /* take the return value to make compiler happy - it will fail anyway */
931 ret
= iwl_mvm_send_cmd_pdu(mvm
, REPLY_ERROR
, 0, 0, NULL
);
933 mutex_unlock(&mvm
->mutex
);
938 static ssize_t
iwl_dbgfs_fw_nmi_write(struct iwl_mvm
*mvm
, char *buf
,
939 size_t count
, loff_t
*ppos
)
941 int ret
= iwl_mvm_ref_sync(mvm
, IWL_MVM_REF_NMI
);
945 iwl_force_nmi(mvm
->trans
);
947 iwl_mvm_unref(mvm
, IWL_MVM_REF_NMI
);
953 iwl_dbgfs_scan_ant_rxchain_read(struct file
*file
,
954 char __user
*user_buf
,
955 size_t count
, loff_t
*ppos
)
957 struct iwl_mvm
*mvm
= file
->private_data
;
960 const size_t bufsz
= sizeof(buf
);
962 /* print which antennas were set for the scan command by the user */
963 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "Antennas for scan: ");
964 if (mvm
->scan_rx_ant
& ANT_A
)
965 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "A");
966 if (mvm
->scan_rx_ant
& ANT_B
)
967 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "B");
968 if (mvm
->scan_rx_ant
& ANT_C
)
969 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "C");
970 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, " (%hhx)\n", mvm
->scan_rx_ant
);
972 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
976 iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm
*mvm
, char *buf
,
977 size_t count
, loff_t
*ppos
)
981 if (sscanf(buf
, "%hhx", &scan_rx_ant
) != 1)
983 if (scan_rx_ant
> ANT_ABC
)
985 if (scan_rx_ant
& ~mvm
->fw
->valid_rx_ant
)
988 mvm
->scan_rx_ant
= scan_rx_ant
;
993 #define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__)
994 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
995 static ssize_t
iwl_dbgfs_bcast_filters_read(struct file
*file
,
996 char __user
*user_buf
,
997 size_t count
, loff_t
*ppos
)
999 struct iwl_mvm
*mvm
= file
->private_data
;
1000 struct iwl_bcast_filter_cmd cmd
;
1001 const struct iwl_fw_bcast_filter
*filter
;
1007 buf
= kzalloc(bufsz
, GFP_KERNEL
);
1011 mutex_lock(&mvm
->mutex
);
1012 if (!iwl_mvm_bcast_filter_build_cmd(mvm
, &cmd
)) {
1014 mutex_unlock(&mvm
->mutex
);
1017 mutex_unlock(&mvm
->mutex
);
1019 for (i
= 0; cmd
.filters
[i
].attrs
[0].mask
; i
++) {
1020 filter
= &cmd
.filters
[i
];
1022 ADD_TEXT("Filter [%d]:\n", i
);
1023 ADD_TEXT("\tDiscard=%d\n", filter
->discard
);
1024 ADD_TEXT("\tFrame Type: %s\n",
1025 filter
->frame_type
? "IPv4" : "Generic");
1027 for (j
= 0; j
< ARRAY_SIZE(filter
->attrs
); j
++) {
1028 const struct iwl_fw_bcast_filter_attr
*attr
;
1030 attr
= &filter
->attrs
[j
];
1034 ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n",
1036 attr
->offset_type
? "IP End" :
1038 be32_to_cpu(attr
->mask
),
1039 be32_to_cpu(attr
->val
),
1040 le16_to_cpu(attr
->reserved1
));
1044 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1049 static ssize_t
iwl_dbgfs_bcast_filters_write(struct iwl_mvm
*mvm
, char *buf
,
1050 size_t count
, loff_t
*ppos
)
1053 struct iwl_fw_bcast_filter filter
= {};
1054 struct iwl_bcast_filter_cmd cmd
;
1055 u32 filter_id
, attr_id
, mask
, value
;
1058 if (sscanf(buf
, "%d %hhi %hhi %n", &filter_id
, &filter
.discard
,
1059 &filter
.frame_type
, &pos
) != 3)
1062 if (filter_id
>= ARRAY_SIZE(mvm
->dbgfs_bcast_filtering
.cmd
.filters
) ||
1063 filter
.frame_type
> BCAST_FILTER_FRAME_TYPE_IPV4
)
1066 for (attr_id
= 0; attr_id
< ARRAY_SIZE(filter
.attrs
);
1068 struct iwl_fw_bcast_filter_attr
*attr
=
1069 &filter
.attrs
[attr_id
];
1074 if (sscanf(&buf
[pos
], "%hhi %hhi %i %i %n",
1075 &attr
->offset
, &attr
->offset_type
,
1076 &mask
, &value
, &next_pos
) != 4)
1079 attr
->mask
= cpu_to_be32(mask
);
1080 attr
->val
= cpu_to_be32(value
);
1087 mutex_lock(&mvm
->mutex
);
1088 memcpy(&mvm
->dbgfs_bcast_filtering
.cmd
.filters
[filter_id
],
1089 &filter
, sizeof(filter
));
1091 /* send updated bcast filtering configuration */
1092 if (mvm
->dbgfs_bcast_filtering
.override
&&
1093 iwl_mvm_bcast_filter_build_cmd(mvm
, &cmd
))
1094 err
= iwl_mvm_send_cmd_pdu(mvm
, BCAST_FILTER_CMD
, 0,
1096 mutex_unlock(&mvm
->mutex
);
1098 return err
?: count
;
1101 static ssize_t
iwl_dbgfs_bcast_filters_macs_read(struct file
*file
,
1102 char __user
*user_buf
,
1103 size_t count
, loff_t
*ppos
)
1105 struct iwl_mvm
*mvm
= file
->private_data
;
1106 struct iwl_bcast_filter_cmd cmd
;
1112 buf
= kzalloc(bufsz
, GFP_KERNEL
);
1116 mutex_lock(&mvm
->mutex
);
1117 if (!iwl_mvm_bcast_filter_build_cmd(mvm
, &cmd
)) {
1119 mutex_unlock(&mvm
->mutex
);
1122 mutex_unlock(&mvm
->mutex
);
1124 for (i
= 0; i
< ARRAY_SIZE(cmd
.macs
); i
++) {
1125 const struct iwl_fw_bcast_mac
*mac
= &cmd
.macs
[i
];
1127 ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n",
1128 i
, mac
->default_discard
, mac
->attached_filters
);
1131 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1136 static ssize_t
iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm
*mvm
,
1137 char *buf
, size_t count
,
1140 struct iwl_bcast_filter_cmd cmd
;
1141 struct iwl_fw_bcast_mac mac
= {};
1142 u32 mac_id
, attached_filters
;
1145 if (!mvm
->bcast_filters
)
1148 if (sscanf(buf
, "%d %hhi %i", &mac_id
, &mac
.default_discard
,
1149 &attached_filters
) != 3)
1152 if (mac_id
>= ARRAY_SIZE(cmd
.macs
) ||
1153 mac
.default_discard
> 1 ||
1154 attached_filters
>= BIT(ARRAY_SIZE(cmd
.filters
)))
1157 mac
.attached_filters
= cpu_to_le16(attached_filters
);
1159 mutex_lock(&mvm
->mutex
);
1160 memcpy(&mvm
->dbgfs_bcast_filtering
.cmd
.macs
[mac_id
],
1163 /* send updated bcast filtering configuration */
1164 if (mvm
->dbgfs_bcast_filtering
.override
&&
1165 iwl_mvm_bcast_filter_build_cmd(mvm
, &cmd
))
1166 err
= iwl_mvm_send_cmd_pdu(mvm
, BCAST_FILTER_CMD
, 0,
1168 mutex_unlock(&mvm
->mutex
);
1170 return err
?: count
;
1174 #ifdef CONFIG_PM_SLEEP
1175 static ssize_t
iwl_dbgfs_d3_sram_write(struct iwl_mvm
*mvm
, char *buf
,
1176 size_t count
, loff_t
*ppos
)
1180 if (sscanf(buf
, "%d", &store
) != 1)
1183 mvm
->store_d3_resume_sram
= store
;
1188 static ssize_t
iwl_dbgfs_d3_sram_read(struct file
*file
, char __user
*user_buf
,
1189 size_t count
, loff_t
*ppos
)
1191 struct iwl_mvm
*mvm
= file
->private_data
;
1192 const struct fw_img
*img
;
1193 int ofs
, len
, pos
= 0;
1196 u8
*ptr
= mvm
->d3_resume_sram
;
1198 img
= &mvm
->fw
->img
[IWL_UCODE_WOWLAN
];
1199 len
= img
->sec
[IWL_UCODE_SECTION_DATA
].len
;
1201 bufsz
= len
* 4 + 256;
1202 buf
= kzalloc(bufsz
, GFP_KERNEL
);
1206 pos
+= scnprintf(buf
, bufsz
, "D3 SRAM capture: %sabled\n",
1207 mvm
->store_d3_resume_sram
? "en" : "dis");
1210 for (ofs
= 0; ofs
< len
; ofs
+= 16) {
1211 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1213 hex_dump_to_buffer(ptr
+ ofs
, 16, 16, 1, buf
+ pos
,
1214 bufsz
- pos
, false);
1215 pos
+= strlen(buf
+ pos
);
1216 if (bufsz
- pos
> 0)
1220 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1221 "(no data captured)\n");
1224 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1232 #define PRINT_MVM_REF(ref) do { \
1233 if (mvm->refs[ref]) \
1234 pos += scnprintf(buf + pos, bufsz - pos, \
1235 "\t(0x%lx): %d %s\n", \
1236 BIT(ref), mvm->refs[ref], #ref); \
1239 static ssize_t
iwl_dbgfs_d0i3_refs_read(struct file
*file
,
1240 char __user
*user_buf
,
1241 size_t count
, loff_t
*ppos
)
1243 struct iwl_mvm
*mvm
= file
->private_data
;
1246 const size_t bufsz
= sizeof(buf
);
1249 for (i
= 0; i
< IWL_MVM_REF_COUNT
; i
++)
1253 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "taken mvm refs: 0x%x\n",
1256 PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN
);
1257 PRINT_MVM_REF(IWL_MVM_REF_SCAN
);
1258 PRINT_MVM_REF(IWL_MVM_REF_ROC
);
1259 PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT
);
1260 PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS
);
1261 PRINT_MVM_REF(IWL_MVM_REF_USER
);
1262 PRINT_MVM_REF(IWL_MVM_REF_TX
);
1263 PRINT_MVM_REF(IWL_MVM_REF_TX_AGG
);
1264 PRINT_MVM_REF(IWL_MVM_REF_ADD_IF
);
1265 PRINT_MVM_REF(IWL_MVM_REF_START_AP
);
1266 PRINT_MVM_REF(IWL_MVM_REF_BSS_CHANGED
);
1267 PRINT_MVM_REF(IWL_MVM_REF_PREPARE_TX
);
1268 PRINT_MVM_REF(IWL_MVM_REF_PROTECT_TDLS
);
1269 PRINT_MVM_REF(IWL_MVM_REF_CHECK_CTKILL
);
1270 PRINT_MVM_REF(IWL_MVM_REF_PRPH_READ
);
1271 PRINT_MVM_REF(IWL_MVM_REF_PRPH_WRITE
);
1272 PRINT_MVM_REF(IWL_MVM_REF_NMI
);
1273 PRINT_MVM_REF(IWL_MVM_REF_TM_CMD
);
1274 PRINT_MVM_REF(IWL_MVM_REF_EXIT_WORK
);
1276 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1279 static ssize_t
iwl_dbgfs_d0i3_refs_write(struct iwl_mvm
*mvm
, char *buf
,
1280 size_t count
, loff_t
*ppos
)
1282 unsigned long value
;
1286 ret
= kstrtoul(buf
, 10, &value
);
1290 mutex_lock(&mvm
->mutex
);
1292 taken
= mvm
->refs
[IWL_MVM_REF_USER
];
1293 if (value
== 1 && !taken
)
1294 iwl_mvm_ref(mvm
, IWL_MVM_REF_USER
);
1295 else if (value
== 0 && taken
)
1296 iwl_mvm_unref(mvm
, IWL_MVM_REF_USER
);
1300 mutex_unlock(&mvm
->mutex
);
1307 #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
1308 _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1309 #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
1310 _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1311 #define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \
1312 if (!debugfs_create_file(alias, mode, parent, mvm, \
1313 &iwl_dbgfs_##name##_ops)) \
1316 #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
1317 MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
1320 iwl_dbgfs_prph_reg_read(struct file
*file
,
1321 char __user
*user_buf
,
1322 size_t count
, loff_t
*ppos
)
1324 struct iwl_mvm
*mvm
= file
->private_data
;
1327 const size_t bufsz
= sizeof(buf
);
1330 if (!mvm
->dbgfs_prph_reg_addr
)
1333 ret
= iwl_mvm_ref_sync(mvm
, IWL_MVM_REF_PRPH_READ
);
1337 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "Reg 0x%x: (0x%x)\n",
1338 mvm
->dbgfs_prph_reg_addr
,
1339 iwl_read_prph(mvm
->trans
, mvm
->dbgfs_prph_reg_addr
));
1341 iwl_mvm_unref(mvm
, IWL_MVM_REF_PRPH_READ
);
1343 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1347 iwl_dbgfs_prph_reg_write(struct iwl_mvm
*mvm
, char *buf
,
1348 size_t count
, loff_t
*ppos
)
1354 args
= sscanf(buf
, "%i %i", &mvm
->dbgfs_prph_reg_addr
, &value
);
1355 /* if we only want to set the reg address - nothing more to do */
1359 /* otherwise, make sure we have both address and value */
1363 ret
= iwl_mvm_ref_sync(mvm
, IWL_MVM_REF_PRPH_WRITE
);
1367 iwl_write_prph(mvm
->trans
, mvm
->dbgfs_prph_reg_addr
, value
);
1369 iwl_mvm_unref(mvm
, IWL_MVM_REF_PRPH_WRITE
);
1374 MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg
, 64);
1376 /* Device wide debugfs entries */
1377 MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush
, 16);
1378 MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain
, 8);
1379 MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram
, 64);
1380 MVM_DEBUGFS_READ_WRITE_FILE_OPS(set_nic_temperature
, 64);
1381 MVM_DEBUGFS_READ_FILE_OPS(stations
);
1382 MVM_DEBUGFS_READ_FILE_OPS(bt_notif
);
1383 MVM_DEBUGFS_READ_FILE_OPS(bt_cmd
);
1384 MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off
, 64);
1385 MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats
);
1386 MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats
);
1387 MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart
, 10);
1388 MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi
, 10);
1389 MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio
, 10);
1390 MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant
, 10);
1391 MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain
, 8);
1392 MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs
, 8);
1394 static const struct file_operations iwl_dbgfs_fw_error_dump_ops
= {
1395 .open
= iwl_dbgfs_fw_error_dump_open
,
1396 .read
= iwl_dbgfs_fw_error_dump_read
,
1397 .release
= iwl_dbgfs_fw_error_dump_release
,
1400 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1401 MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters
, 256);
1402 MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs
, 256);
1405 #ifdef CONFIG_PM_SLEEP
1406 MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram
, 8);
1409 int iwl_mvm_dbgfs_register(struct iwl_mvm
*mvm
, struct dentry
*dbgfs_dir
)
1411 struct dentry
*bcast_dir __maybe_unused
;
1414 spin_lock_init(&mvm
->drv_stats_lock
);
1416 mvm
->debugfs_dir
= dbgfs_dir
;
1418 MVM_DEBUGFS_ADD_FILE(tx_flush
, mvm
->debugfs_dir
, S_IWUSR
);
1419 MVM_DEBUGFS_ADD_FILE(sta_drain
, mvm
->debugfs_dir
, S_IWUSR
);
1420 MVM_DEBUGFS_ADD_FILE(sram
, mvm
->debugfs_dir
, S_IWUSR
| S_IRUSR
);
1421 MVM_DEBUGFS_ADD_FILE(set_nic_temperature
, mvm
->debugfs_dir
,
1423 MVM_DEBUGFS_ADD_FILE(stations
, dbgfs_dir
, S_IRUSR
);
1424 MVM_DEBUGFS_ADD_FILE(fw_error_dump
, dbgfs_dir
, S_IRUSR
);
1425 MVM_DEBUGFS_ADD_FILE(bt_notif
, dbgfs_dir
, S_IRUSR
);
1426 MVM_DEBUGFS_ADD_FILE(bt_cmd
, dbgfs_dir
, S_IRUSR
);
1427 MVM_DEBUGFS_ADD_FILE(disable_power_off
, mvm
->debugfs_dir
,
1429 MVM_DEBUGFS_ADD_FILE(fw_rx_stats
, mvm
->debugfs_dir
, S_IRUSR
);
1430 MVM_DEBUGFS_ADD_FILE(drv_rx_stats
, mvm
->debugfs_dir
, S_IRUSR
);
1431 MVM_DEBUGFS_ADD_FILE(fw_restart
, mvm
->debugfs_dir
, S_IWUSR
);
1432 MVM_DEBUGFS_ADD_FILE(fw_nmi
, mvm
->debugfs_dir
, S_IWUSR
);
1433 MVM_DEBUGFS_ADD_FILE(bt_tx_prio
, mvm
->debugfs_dir
, S_IWUSR
);
1434 MVM_DEBUGFS_ADD_FILE(bt_force_ant
, mvm
->debugfs_dir
, S_IWUSR
);
1435 MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain
, mvm
->debugfs_dir
,
1437 MVM_DEBUGFS_ADD_FILE(prph_reg
, mvm
->debugfs_dir
, S_IWUSR
| S_IRUSR
);
1438 MVM_DEBUGFS_ADD_FILE(d0i3_refs
, mvm
->debugfs_dir
, S_IRUSR
| S_IWUSR
);
1440 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1441 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_BCAST_FILTERING
) {
1442 bcast_dir
= debugfs_create_dir("bcast_filtering",
1447 if (!debugfs_create_bool("override", S_IRUSR
| S_IWUSR
,
1449 &mvm
->dbgfs_bcast_filtering
.override
))
1452 MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters
,
1453 bcast_dir
, S_IWUSR
| S_IRUSR
);
1454 MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs
,
1455 bcast_dir
, S_IWUSR
| S_IRUSR
);
1459 #ifdef CONFIG_PM_SLEEP
1460 MVM_DEBUGFS_ADD_FILE(d3_sram
, mvm
->debugfs_dir
, S_IRUSR
| S_IWUSR
);
1461 MVM_DEBUGFS_ADD_FILE(d3_test
, mvm
->debugfs_dir
, S_IRUSR
);
1462 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR
| S_IWUSR
,
1463 mvm
->debugfs_dir
, &mvm
->d3_wake_sysassert
))
1467 if (!debugfs_create_u8("low_latency_agg_frame_limit", S_IRUSR
| S_IWUSR
,
1469 &mvm
->low_latency_agg_frame_limit
))
1471 if (!debugfs_create_u8("ps_disabled", S_IRUSR
,
1472 mvm
->debugfs_dir
, &mvm
->ps_disabled
))
1474 if (!debugfs_create_blob("nvm_hw", S_IRUSR
,
1475 mvm
->debugfs_dir
, &mvm
->nvm_hw_blob
))
1477 if (!debugfs_create_blob("nvm_sw", S_IRUSR
,
1478 mvm
->debugfs_dir
, &mvm
->nvm_sw_blob
))
1480 if (!debugfs_create_blob("nvm_calib", S_IRUSR
,
1481 mvm
->debugfs_dir
, &mvm
->nvm_calib_blob
))
1483 if (!debugfs_create_blob("nvm_prod", S_IRUSR
,
1484 mvm
->debugfs_dir
, &mvm
->nvm_prod_blob
))
1488 * Create a symlink with mac80211. It will be removed when mac80211
1489 * exists (before the opmode exists which removes the target.)
1491 snprintf(buf
, 100, "../../%s/%s",
1492 dbgfs_dir
->d_parent
->d_parent
->d_name
.name
,
1493 dbgfs_dir
->d_parent
->d_name
.name
);
1494 if (!debugfs_create_symlink("iwlwifi", mvm
->hw
->wiphy
->debugfsdir
, buf
))
1499 IWL_ERR(mvm
, "Can't create the mvm debugfs directory\n");