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 ssize_t
iwl_dbgfs_sram_read(struct file
*file
, char __user
*user_buf
,
125 size_t count
, loff_t
*ppos
)
127 struct iwl_mvm
*mvm
= file
->private_data
;
128 const struct fw_img
*img
;
129 unsigned int ofs
, len
;
133 if (!mvm
->ucode_loaded
)
136 /* default is to dump the entire data segment */
137 img
= &mvm
->fw
->img
[mvm
->cur_ucode
];
138 ofs
= img
->sec
[IWL_UCODE_SECTION_DATA
].offset
;
139 len
= img
->sec
[IWL_UCODE_SECTION_DATA
].len
;
141 if (mvm
->dbgfs_sram_len
) {
142 ofs
= mvm
->dbgfs_sram_offset
;
143 len
= mvm
->dbgfs_sram_len
;
146 ptr
= kzalloc(len
, GFP_KERNEL
);
150 iwl_trans_read_mem_bytes(mvm
->trans
, ofs
, ptr
, len
);
152 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, ptr
, len
);
159 static ssize_t
iwl_dbgfs_sram_write(struct iwl_mvm
*mvm
, char *buf
,
160 size_t count
, loff_t
*ppos
)
162 const struct fw_img
*img
;
164 u32 img_offset
, img_len
;
166 if (!mvm
->ucode_loaded
)
169 img
= &mvm
->fw
->img
[mvm
->cur_ucode
];
170 img_offset
= img
->sec
[IWL_UCODE_SECTION_DATA
].offset
;
171 img_len
= img
->sec
[IWL_UCODE_SECTION_DATA
].len
;
173 if (sscanf(buf
, "%x,%x", &offset
, &len
) == 2) {
174 if ((offset
& 0x3) || (len
& 0x3))
177 if (offset
+ len
> img_offset
+ img_len
)
180 mvm
->dbgfs_sram_offset
= offset
;
181 mvm
->dbgfs_sram_len
= len
;
183 mvm
->dbgfs_sram_offset
= 0;
184 mvm
->dbgfs_sram_len
= 0;
190 static ssize_t
iwl_dbgfs_set_nic_temperature_read(struct file
*file
,
191 char __user
*user_buf
,
192 size_t count
, loff_t
*ppos
)
194 struct iwl_mvm
*mvm
= file
->private_data
;
198 if (!mvm
->temperature_test
)
199 pos
= scnprintf(buf
, sizeof(buf
), "disabled\n");
201 pos
= scnprintf(buf
, sizeof(buf
), "%d\n", mvm
->temperature
);
203 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
207 * Set NIC Temperature
208 * Cause the driver to ignore the actual NIC temperature reported by the FW
209 * Enable: any value between IWL_MVM_DEBUG_SET_TEMPERATURE_MIN -
210 * IWL_MVM_DEBUG_SET_TEMPERATURE_MAX
211 * Disable: IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE
213 static ssize_t
iwl_dbgfs_set_nic_temperature_write(struct iwl_mvm
*mvm
,
214 char *buf
, size_t count
,
219 if (!mvm
->ucode_loaded
&& !mvm
->temperature_test
)
222 if (kstrtoint(buf
, 10, &temperature
))
224 /* not a legal temperature */
225 if ((temperature
> IWL_MVM_DEBUG_SET_TEMPERATURE_MAX
&&
226 temperature
!= IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE
) ||
227 temperature
< IWL_MVM_DEBUG_SET_TEMPERATURE_MIN
)
230 mutex_lock(&mvm
->mutex
);
231 if (temperature
== IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE
) {
232 if (!mvm
->temperature_test
)
235 mvm
->temperature_test
= false;
236 /* Since we can't read the temp while awake, just set
237 * it to zero until we get the next RX stats from the
240 mvm
->temperature
= 0;
242 mvm
->temperature_test
= true;
243 mvm
->temperature
= temperature
;
245 IWL_DEBUG_TEMP(mvm
, "%sabling debug set temperature (temp = %d)\n",
246 mvm
->temperature_test
? "En" : "Dis" ,
248 /* handle the temperature change */
249 iwl_mvm_tt_handler(mvm
);
252 mutex_unlock(&mvm
->mutex
);
257 static ssize_t
iwl_dbgfs_nic_temp_read(struct file
*file
,
258 char __user
*user_buf
,
259 size_t count
, loff_t
*ppos
)
261 struct iwl_mvm
*mvm
= file
->private_data
;
265 if (!mvm
->ucode_loaded
)
268 mutex_lock(&mvm
->mutex
);
269 temp
= iwl_mvm_get_temp(mvm
);
270 mutex_unlock(&mvm
->mutex
);
275 pos
= scnprintf(buf
, sizeof(buf
), "%d\n", temp
);
277 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
280 static ssize_t
iwl_dbgfs_stations_read(struct file
*file
, char __user
*user_buf
,
281 size_t count
, loff_t
*ppos
)
283 struct iwl_mvm
*mvm
= file
->private_data
;
284 struct ieee80211_sta
*sta
;
286 int i
, pos
= 0, bufsz
= sizeof(buf
);
288 mutex_lock(&mvm
->mutex
);
290 for (i
= 0; i
< IWL_MVM_STATION_COUNT
; i
++) {
291 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "%.2d: ", i
);
292 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[i
],
293 lockdep_is_held(&mvm
->mutex
));
295 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "N/A\n");
296 else if (IS_ERR(sta
))
297 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "%ld\n",
300 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "%pM\n",
304 mutex_unlock(&mvm
->mutex
);
306 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
309 static ssize_t
iwl_dbgfs_disable_power_off_read(struct file
*file
,
310 char __user
*user_buf
,
311 size_t count
, loff_t
*ppos
)
313 struct iwl_mvm
*mvm
= file
->private_data
;
315 int bufsz
= sizeof(buf
);
318 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "disable_power_off_d0=%d\n",
319 mvm
->disable_power_off
);
320 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "disable_power_off_d3=%d\n",
321 mvm
->disable_power_off_d3
);
323 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
326 static ssize_t
iwl_dbgfs_disable_power_off_write(struct iwl_mvm
*mvm
, char *buf
,
327 size_t count
, loff_t
*ppos
)
331 if (!mvm
->ucode_loaded
)
334 if (!strncmp("disable_power_off_d0=", buf
, 21)) {
335 if (sscanf(buf
+ 21, "%d", &val
) != 1)
337 mvm
->disable_power_off
= val
;
338 } else if (!strncmp("disable_power_off_d3=", buf
, 21)) {
339 if (sscanf(buf
+ 21, "%d", &val
) != 1)
341 mvm
->disable_power_off_d3
= val
;
346 mutex_lock(&mvm
->mutex
);
347 ret
= iwl_mvm_power_update_device(mvm
);
348 mutex_unlock(&mvm
->mutex
);
353 #define BT_MBOX_MSG(_notif, _num, _field) \
354 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
355 >> BT_MBOX##_num##_##_field##_POS)
358 #define BT_MBOX_PRINT(_num, _field, _end) \
359 pos += scnprintf(buf + pos, bufsz - pos, \
362 BT_MBOX_MSG(notif, _num, _field), \
366 int iwl_mvm_coex_dump_mbox(struct iwl_bt_coex_profile_notif
*notif
, char *buf
,
369 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "MBOX dw0:\n");
371 BT_MBOX_PRINT(0, LE_SLAVE_LAT
, false);
372 BT_MBOX_PRINT(0, LE_PROF1
, false);
373 BT_MBOX_PRINT(0, LE_PROF2
, false);
374 BT_MBOX_PRINT(0, LE_PROF_OTHER
, false);
375 BT_MBOX_PRINT(0, CHL_SEQ_N
, false);
376 BT_MBOX_PRINT(0, INBAND_S
, false);
377 BT_MBOX_PRINT(0, LE_MIN_RSSI
, false);
378 BT_MBOX_PRINT(0, LE_SCAN
, false);
379 BT_MBOX_PRINT(0, LE_ADV
, false);
380 BT_MBOX_PRINT(0, LE_MAX_TX_POWER
, false);
381 BT_MBOX_PRINT(0, OPEN_CON_1
, true);
383 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "MBOX dw1:\n");
385 BT_MBOX_PRINT(1, BR_MAX_TX_POWER
, false);
386 BT_MBOX_PRINT(1, IP_SR
, false);
387 BT_MBOX_PRINT(1, LE_MSTR
, false);
388 BT_MBOX_PRINT(1, AGGR_TRFC_LD
, false);
389 BT_MBOX_PRINT(1, MSG_TYPE
, false);
390 BT_MBOX_PRINT(1, SSN
, true);
392 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "MBOX dw2:\n");
394 BT_MBOX_PRINT(2, SNIFF_ACT
, false);
395 BT_MBOX_PRINT(2, PAG
, false);
396 BT_MBOX_PRINT(2, INQUIRY
, false);
397 BT_MBOX_PRINT(2, CONN
, false);
398 BT_MBOX_PRINT(2, SNIFF_INTERVAL
, false);
399 BT_MBOX_PRINT(2, DISC
, false);
400 BT_MBOX_PRINT(2, SCO_TX_ACT
, false);
401 BT_MBOX_PRINT(2, SCO_RX_ACT
, false);
402 BT_MBOX_PRINT(2, ESCO_RE_TX
, false);
403 BT_MBOX_PRINT(2, SCO_DURATION
, true);
405 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "MBOX dw3:\n");
407 BT_MBOX_PRINT(3, SCO_STATE
, false);
408 BT_MBOX_PRINT(3, SNIFF_STATE
, false);
409 BT_MBOX_PRINT(3, A2DP_STATE
, false);
410 BT_MBOX_PRINT(3, ACL_STATE
, false);
411 BT_MBOX_PRINT(3, MSTR_STATE
, false);
412 BT_MBOX_PRINT(3, OBX_STATE
, false);
413 BT_MBOX_PRINT(3, OPEN_CON_2
, false);
414 BT_MBOX_PRINT(3, TRAFFIC_LOAD
, false);
415 BT_MBOX_PRINT(3, CHL_SEQN_LSB
, false);
416 BT_MBOX_PRINT(3, INBAND_P
, false);
417 BT_MBOX_PRINT(3, MSG_TYPE_2
, false);
418 BT_MBOX_PRINT(3, SSN_2
, false);
419 BT_MBOX_PRINT(3, UPDATE_REQUEST
, true);
425 int iwl_mvm_coex_dump_mbox_old(struct iwl_bt_coex_profile_notif_old
*notif
,
426 char *buf
, int pos
, int bufsz
)
428 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "MBOX dw0:\n");
430 BT_MBOX_PRINT(0, LE_SLAVE_LAT
, false);
431 BT_MBOX_PRINT(0, LE_PROF1
, false);
432 BT_MBOX_PRINT(0, LE_PROF2
, false);
433 BT_MBOX_PRINT(0, LE_PROF_OTHER
, false);
434 BT_MBOX_PRINT(0, CHL_SEQ_N
, false);
435 BT_MBOX_PRINT(0, INBAND_S
, false);
436 BT_MBOX_PRINT(0, LE_MIN_RSSI
, false);
437 BT_MBOX_PRINT(0, LE_SCAN
, false);
438 BT_MBOX_PRINT(0, LE_ADV
, false);
439 BT_MBOX_PRINT(0, LE_MAX_TX_POWER
, false);
440 BT_MBOX_PRINT(0, OPEN_CON_1
, true);
442 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "MBOX dw1:\n");
444 BT_MBOX_PRINT(1, BR_MAX_TX_POWER
, false);
445 BT_MBOX_PRINT(1, IP_SR
, false);
446 BT_MBOX_PRINT(1, LE_MSTR
, false);
447 BT_MBOX_PRINT(1, AGGR_TRFC_LD
, false);
448 BT_MBOX_PRINT(1, MSG_TYPE
, false);
449 BT_MBOX_PRINT(1, SSN
, true);
451 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "MBOX dw2:\n");
453 BT_MBOX_PRINT(2, SNIFF_ACT
, false);
454 BT_MBOX_PRINT(2, PAG
, false);
455 BT_MBOX_PRINT(2, INQUIRY
, false);
456 BT_MBOX_PRINT(2, CONN
, false);
457 BT_MBOX_PRINT(2, SNIFF_INTERVAL
, false);
458 BT_MBOX_PRINT(2, DISC
, false);
459 BT_MBOX_PRINT(2, SCO_TX_ACT
, false);
460 BT_MBOX_PRINT(2, SCO_RX_ACT
, false);
461 BT_MBOX_PRINT(2, ESCO_RE_TX
, false);
462 BT_MBOX_PRINT(2, SCO_DURATION
, true);
464 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "MBOX dw3:\n");
466 BT_MBOX_PRINT(3, SCO_STATE
, false);
467 BT_MBOX_PRINT(3, SNIFF_STATE
, false);
468 BT_MBOX_PRINT(3, A2DP_STATE
, false);
469 BT_MBOX_PRINT(3, ACL_STATE
, false);
470 BT_MBOX_PRINT(3, MSTR_STATE
, false);
471 BT_MBOX_PRINT(3, OBX_STATE
, false);
472 BT_MBOX_PRINT(3, OPEN_CON_2
, false);
473 BT_MBOX_PRINT(3, TRAFFIC_LOAD
, false);
474 BT_MBOX_PRINT(3, CHL_SEQN_LSB
, false);
475 BT_MBOX_PRINT(3, INBAND_P
, false);
476 BT_MBOX_PRINT(3, MSG_TYPE_2
, false);
477 BT_MBOX_PRINT(3, SSN_2
, false);
478 BT_MBOX_PRINT(3, UPDATE_REQUEST
, true);
483 static ssize_t
iwl_dbgfs_bt_notif_read(struct file
*file
, char __user
*user_buf
,
484 size_t count
, loff_t
*ppos
)
486 struct iwl_mvm
*mvm
= file
->private_data
;
488 int ret
, pos
= 0, bufsz
= sizeof(char) * 1024;
490 buf
= kmalloc(bufsz
, GFP_KERNEL
);
494 mutex_lock(&mvm
->mutex
);
496 if (!(mvm
->fw
->ucode_capa
.api
[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT
)) {
497 struct iwl_bt_coex_profile_notif_old
*notif
=
498 &mvm
->last_bt_notif_old
;
500 pos
+= iwl_mvm_coex_dump_mbox_old(notif
, buf
, pos
, bufsz
);
502 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "bt_ci_compliance = %d\n",
503 notif
->bt_ci_compliance
);
504 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "primary_ch_lut = %d\n",
505 le32_to_cpu(notif
->primary_ch_lut
));
506 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "secondary_ch_lut = %d\n",
507 le32_to_cpu(notif
->secondary_ch_lut
));
508 pos
+= scnprintf(buf
+pos
,
509 bufsz
-pos
, "bt_activity_grading = %d\n",
510 le32_to_cpu(notif
->bt_activity_grading
));
511 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
512 "antenna isolation = %d CORUN LUT index = %d\n",
513 mvm
->last_ant_isol
, mvm
->last_corun_lut
);
515 struct iwl_bt_coex_profile_notif
*notif
=
518 pos
+= iwl_mvm_coex_dump_mbox(notif
, buf
, pos
, bufsz
);
520 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "bt_ci_compliance = %d\n",
521 notif
->bt_ci_compliance
);
522 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "primary_ch_lut = %d\n",
523 le32_to_cpu(notif
->primary_ch_lut
));
524 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "secondary_ch_lut = %d\n",
525 le32_to_cpu(notif
->secondary_ch_lut
));
526 pos
+= scnprintf(buf
+pos
,
527 bufsz
-pos
, "bt_activity_grading = %d\n",
528 le32_to_cpu(notif
->bt_activity_grading
));
529 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
530 "antenna isolation = %d CORUN LUT index = %d\n",
531 mvm
->last_ant_isol
, mvm
->last_corun_lut
);
534 mutex_unlock(&mvm
->mutex
);
536 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
543 static ssize_t
iwl_dbgfs_bt_cmd_read(struct file
*file
, char __user
*user_buf
,
544 size_t count
, loff_t
*ppos
)
546 struct iwl_mvm
*mvm
= file
->private_data
;
548 int bufsz
= sizeof(buf
);
551 mutex_lock(&mvm
->mutex
);
553 if (!(mvm
->fw
->ucode_capa
.api
[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT
)) {
554 struct iwl_bt_coex_ci_cmd_old
*cmd
= &mvm
->last_bt_ci_cmd_old
;
556 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
557 "Channel inhibition CMD\n");
558 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
559 "\tPrimary Channel Bitmap 0x%016llx\n",
560 le64_to_cpu(cmd
->bt_primary_ci
));
561 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
562 "\tSecondary Channel Bitmap 0x%016llx\n",
563 le64_to_cpu(cmd
->bt_secondary_ci
));
565 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "BT Configuration CMD\n");
566 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "\tACK Kill Mask 0x%08x\n",
567 iwl_bt_ctl_kill_msk
[mvm
->bt_ack_kill_msk
[0]]);
568 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "\tCTS Kill Mask 0x%08x\n",
569 iwl_bt_ctl_kill_msk
[mvm
->bt_cts_kill_msk
[0]]);
572 struct iwl_bt_coex_ci_cmd
*cmd
= &mvm
->last_bt_ci_cmd
;
574 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
575 "Channel inhibition CMD\n");
576 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
577 "\tPrimary Channel Bitmap 0x%016llx\n",
578 le64_to_cpu(cmd
->bt_primary_ci
));
579 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
580 "\tSecondary Channel Bitmap 0x%016llx\n",
581 le64_to_cpu(cmd
->bt_secondary_ci
));
583 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "BT Configuration CMD\n");
584 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
585 "\tPrimary: ACK Kill Mask 0x%08x\n",
586 iwl_bt_ctl_kill_msk
[mvm
->bt_ack_kill_msk
[0]]);
587 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
588 "\tPrimary: CTS Kill Mask 0x%08x\n",
589 iwl_bt_ctl_kill_msk
[mvm
->bt_cts_kill_msk
[0]]);
590 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
591 "\tSecondary: ACK Kill Mask 0x%08x\n",
592 iwl_bt_ctl_kill_msk
[mvm
->bt_ack_kill_msk
[1]]);
593 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
594 "\tSecondary: CTS Kill Mask 0x%08x\n",
595 iwl_bt_ctl_kill_msk
[mvm
->bt_cts_kill_msk
[1]]);
599 mutex_unlock(&mvm
->mutex
);
601 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
605 iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm
*mvm
, char *buf
,
606 size_t count
, loff_t
*ppos
)
610 if (sscanf(buf
, "%u", &bt_tx_prio
) != 1)
615 mvm
->bt_tx_prio
= bt_tx_prio
;
621 iwl_dbgfs_bt_force_ant_write(struct iwl_mvm
*mvm
, char *buf
,
622 size_t count
, loff_t
*ppos
)
624 static const char * const modes_str
[BT_FORCE_ANT_MAX
] = {
625 [BT_FORCE_ANT_DIS
] = "dis",
626 [BT_FORCE_ANT_AUTO
] = "auto",
627 [BT_FORCE_ANT_BT
] = "bt",
628 [BT_FORCE_ANT_WIFI
] = "wifi",
630 int ret
, bt_force_ant_mode
;
632 for (bt_force_ant_mode
= 0;
633 bt_force_ant_mode
< ARRAY_SIZE(modes_str
);
634 bt_force_ant_mode
++) {
635 if (!strcmp(buf
, modes_str
[bt_force_ant_mode
]))
639 if (bt_force_ant_mode
>= ARRAY_SIZE(modes_str
))
643 mutex_lock(&mvm
->mutex
);
644 if (mvm
->bt_force_ant_mode
== bt_force_ant_mode
)
647 mvm
->bt_force_ant_mode
= bt_force_ant_mode
;
648 IWL_DEBUG_COEX(mvm
, "Force mode: %s\n",
649 modes_str
[mvm
->bt_force_ant_mode
]);
650 ret
= iwl_send_bt_init_conf(mvm
);
653 mutex_unlock(&mvm
->mutex
);
657 #define PRINT_STATS_LE32(_struct, _memb) \
658 pos += scnprintf(buf + pos, bufsz - pos, \
660 le32_to_cpu(_struct->_memb))
662 static ssize_t
iwl_dbgfs_fw_rx_stats_read(struct file
*file
,
663 char __user
*user_buf
, size_t count
,
666 struct iwl_mvm
*mvm
= file
->private_data
;
667 static const char *fmt_table
= "\t%-30s %10u\n";
668 static const char *fmt_header
= "%-32s\n";
672 /* 43 is the size of each data line, 33 is the size of each header */
674 ((sizeof(struct mvm_statistics_rx
) / sizeof(__le32
)) * 43) +
677 struct mvm_statistics_rx_phy
*ofdm
;
678 struct mvm_statistics_rx_phy
*cck
;
679 struct mvm_statistics_rx_non_phy
*general
;
680 struct mvm_statistics_rx_ht_phy
*ht
;
682 buf
= kzalloc(bufsz
, GFP_KERNEL
);
686 mutex_lock(&mvm
->mutex
);
688 ofdm
= &mvm
->rx_stats
.ofdm
;
689 cck
= &mvm
->rx_stats
.cck
;
690 general
= &mvm
->rx_stats
.general
;
691 ht
= &mvm
->rx_stats
.ofdm_ht
;
693 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, fmt_header
,
694 "Statistics_Rx - OFDM");
695 PRINT_STATS_LE32(ofdm
, ina_cnt
);
696 PRINT_STATS_LE32(ofdm
, fina_cnt
);
697 PRINT_STATS_LE32(ofdm
, plcp_err
);
698 PRINT_STATS_LE32(ofdm
, crc32_err
);
699 PRINT_STATS_LE32(ofdm
, overrun_err
);
700 PRINT_STATS_LE32(ofdm
, early_overrun_err
);
701 PRINT_STATS_LE32(ofdm
, crc32_good
);
702 PRINT_STATS_LE32(ofdm
, false_alarm_cnt
);
703 PRINT_STATS_LE32(ofdm
, fina_sync_err_cnt
);
704 PRINT_STATS_LE32(ofdm
, sfd_timeout
);
705 PRINT_STATS_LE32(ofdm
, fina_timeout
);
706 PRINT_STATS_LE32(ofdm
, unresponded_rts
);
707 PRINT_STATS_LE32(ofdm
, rxe_frame_lmt_overrun
);
708 PRINT_STATS_LE32(ofdm
, sent_ack_cnt
);
709 PRINT_STATS_LE32(ofdm
, sent_cts_cnt
);
710 PRINT_STATS_LE32(ofdm
, sent_ba_rsp_cnt
);
711 PRINT_STATS_LE32(ofdm
, dsp_self_kill
);
712 PRINT_STATS_LE32(ofdm
, mh_format_err
);
713 PRINT_STATS_LE32(ofdm
, re_acq_main_rssi_sum
);
714 PRINT_STATS_LE32(ofdm
, reserved
);
716 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, fmt_header
,
717 "Statistics_Rx - CCK");
718 PRINT_STATS_LE32(cck
, ina_cnt
);
719 PRINT_STATS_LE32(cck
, fina_cnt
);
720 PRINT_STATS_LE32(cck
, plcp_err
);
721 PRINT_STATS_LE32(cck
, crc32_err
);
722 PRINT_STATS_LE32(cck
, overrun_err
);
723 PRINT_STATS_LE32(cck
, early_overrun_err
);
724 PRINT_STATS_LE32(cck
, crc32_good
);
725 PRINT_STATS_LE32(cck
, false_alarm_cnt
);
726 PRINT_STATS_LE32(cck
, fina_sync_err_cnt
);
727 PRINT_STATS_LE32(cck
, sfd_timeout
);
728 PRINT_STATS_LE32(cck
, fina_timeout
);
729 PRINT_STATS_LE32(cck
, unresponded_rts
);
730 PRINT_STATS_LE32(cck
, rxe_frame_lmt_overrun
);
731 PRINT_STATS_LE32(cck
, sent_ack_cnt
);
732 PRINT_STATS_LE32(cck
, sent_cts_cnt
);
733 PRINT_STATS_LE32(cck
, sent_ba_rsp_cnt
);
734 PRINT_STATS_LE32(cck
, dsp_self_kill
);
735 PRINT_STATS_LE32(cck
, mh_format_err
);
736 PRINT_STATS_LE32(cck
, re_acq_main_rssi_sum
);
737 PRINT_STATS_LE32(cck
, reserved
);
739 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, fmt_header
,
740 "Statistics_Rx - GENERAL");
741 PRINT_STATS_LE32(general
, bogus_cts
);
742 PRINT_STATS_LE32(general
, bogus_ack
);
743 PRINT_STATS_LE32(general
, non_bssid_frames
);
744 PRINT_STATS_LE32(general
, filtered_frames
);
745 PRINT_STATS_LE32(general
, non_channel_beacons
);
746 PRINT_STATS_LE32(general
, channel_beacons
);
747 PRINT_STATS_LE32(general
, num_missed_bcon
);
748 PRINT_STATS_LE32(general
, adc_rx_saturation_time
);
749 PRINT_STATS_LE32(general
, ina_detection_search_time
);
750 PRINT_STATS_LE32(general
, beacon_silence_rssi_a
);
751 PRINT_STATS_LE32(general
, beacon_silence_rssi_b
);
752 PRINT_STATS_LE32(general
, beacon_silence_rssi_c
);
753 PRINT_STATS_LE32(general
, interference_data_flag
);
754 PRINT_STATS_LE32(general
, channel_load
);
755 PRINT_STATS_LE32(general
, dsp_false_alarms
);
756 PRINT_STATS_LE32(general
, beacon_rssi_a
);
757 PRINT_STATS_LE32(general
, beacon_rssi_b
);
758 PRINT_STATS_LE32(general
, beacon_rssi_c
);
759 PRINT_STATS_LE32(general
, beacon_energy_a
);
760 PRINT_STATS_LE32(general
, beacon_energy_b
);
761 PRINT_STATS_LE32(general
, beacon_energy_c
);
762 PRINT_STATS_LE32(general
, num_bt_kills
);
763 PRINT_STATS_LE32(general
, mac_id
);
764 PRINT_STATS_LE32(general
, directed_data_mpdu
);
766 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, fmt_header
,
767 "Statistics_Rx - HT");
768 PRINT_STATS_LE32(ht
, plcp_err
);
769 PRINT_STATS_LE32(ht
, overrun_err
);
770 PRINT_STATS_LE32(ht
, early_overrun_err
);
771 PRINT_STATS_LE32(ht
, crc32_good
);
772 PRINT_STATS_LE32(ht
, crc32_err
);
773 PRINT_STATS_LE32(ht
, mh_format_err
);
774 PRINT_STATS_LE32(ht
, agg_crc32_good
);
775 PRINT_STATS_LE32(ht
, agg_mpdu_cnt
);
776 PRINT_STATS_LE32(ht
, agg_cnt
);
777 PRINT_STATS_LE32(ht
, unsupport_mcs
);
779 mutex_unlock(&mvm
->mutex
);
781 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
786 #undef PRINT_STAT_LE32
788 static ssize_t
iwl_dbgfs_frame_stats_read(struct iwl_mvm
*mvm
,
789 char __user
*user_buf
, size_t count
,
791 struct iwl_mvm_frame_stats
*stats
)
793 char *buff
, *pos
, *endpos
;
796 static const size_t bufsz
= 1024;
798 buff
= kmalloc(bufsz
, GFP_KERNEL
);
802 spin_lock_bh(&mvm
->drv_stats_lock
);
805 endpos
= pos
+ bufsz
;
807 pos
+= scnprintf(pos
, endpos
- pos
,
808 "Legacy/HT/VHT\t:\t%d/%d/%d\n",
809 stats
->legacy_frames
,
812 pos
+= scnprintf(pos
, endpos
- pos
, "20/40/80\t:\t%d/%d/%d\n",
815 stats
->bw_80_frames
);
816 pos
+= scnprintf(pos
, endpos
- pos
, "NGI/SGI\t\t:\t%d/%d\n",
819 pos
+= scnprintf(pos
, endpos
- pos
, "SISO/MIMO2\t:\t%d/%d\n",
821 stats
->mimo2_frames
);
822 pos
+= scnprintf(pos
, endpos
- pos
, "FAIL/SCSS\t:\t%d/%d\n",
824 stats
->success_frames
);
825 pos
+= scnprintf(pos
, endpos
- pos
, "MPDUs agg\t:\t%d\n",
827 pos
+= scnprintf(pos
, endpos
- pos
, "A-MPDUs\t\t:\t%d\n",
829 pos
+= scnprintf(pos
, endpos
- pos
, "Avg MPDUs/A-MPDU:\t%d\n",
830 stats
->ampdu_count
> 0 ?
831 (stats
->agg_frames
/ stats
->ampdu_count
) : 0);
833 pos
+= scnprintf(pos
, endpos
- pos
, "Last Rates\n");
835 idx
= stats
->last_frame_idx
- 1;
836 for (i
= 0; i
< ARRAY_SIZE(stats
->last_rates
); i
++) {
837 idx
= (idx
+ 1) % ARRAY_SIZE(stats
->last_rates
);
838 if (stats
->last_rates
[idx
] == 0)
840 pos
+= scnprintf(pos
, endpos
- pos
, "Rate[%d]: ",
841 (int)(ARRAY_SIZE(stats
->last_rates
) - i
));
842 pos
+= rs_pretty_print_rate(pos
, stats
->last_rates
[idx
]);
844 spin_unlock_bh(&mvm
->drv_stats_lock
);
846 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buff
, pos
- buff
);
852 static ssize_t
iwl_dbgfs_drv_rx_stats_read(struct file
*file
,
853 char __user
*user_buf
, size_t count
,
856 struct iwl_mvm
*mvm
= file
->private_data
;
858 return iwl_dbgfs_frame_stats_read(mvm
, user_buf
, count
, ppos
,
862 static ssize_t
iwl_dbgfs_fw_restart_write(struct iwl_mvm
*mvm
, char *buf
,
863 size_t count
, loff_t
*ppos
)
867 mutex_lock(&mvm
->mutex
);
869 /* allow one more restart that we're provoking here */
870 if (mvm
->restart_fw
>= 0)
873 /* take the return value to make compiler happy - it will fail anyway */
874 ret
= iwl_mvm_send_cmd_pdu(mvm
, REPLY_ERROR
, 0, 0, NULL
);
876 mutex_unlock(&mvm
->mutex
);
881 static ssize_t
iwl_dbgfs_fw_nmi_write(struct iwl_mvm
*mvm
, char *buf
,
882 size_t count
, loff_t
*ppos
)
884 int ret
= iwl_mvm_ref_sync(mvm
, IWL_MVM_REF_NMI
);
888 iwl_force_nmi(mvm
->trans
);
890 iwl_mvm_unref(mvm
, IWL_MVM_REF_NMI
);
896 iwl_dbgfs_scan_ant_rxchain_read(struct file
*file
,
897 char __user
*user_buf
,
898 size_t count
, loff_t
*ppos
)
900 struct iwl_mvm
*mvm
= file
->private_data
;
903 const size_t bufsz
= sizeof(buf
);
905 /* print which antennas were set for the scan command by the user */
906 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "Antennas for scan: ");
907 if (mvm
->scan_rx_ant
& ANT_A
)
908 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "A");
909 if (mvm
->scan_rx_ant
& ANT_B
)
910 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "B");
911 if (mvm
->scan_rx_ant
& ANT_C
)
912 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "C");
913 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, " (%hhx)\n", mvm
->scan_rx_ant
);
915 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
919 iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm
*mvm
, char *buf
,
920 size_t count
, loff_t
*ppos
)
924 if (sscanf(buf
, "%hhx", &scan_rx_ant
) != 1)
926 if (scan_rx_ant
> ANT_ABC
)
928 if (scan_rx_ant
& ~(iwl_mvm_get_valid_rx_ant(mvm
)))
931 if (mvm
->scan_rx_ant
!= scan_rx_ant
) {
932 mvm
->scan_rx_ant
= scan_rx_ant
;
933 if (mvm
->fw
->ucode_capa
.capa
[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN
)
934 iwl_mvm_config_scan(mvm
);
940 static ssize_t
iwl_dbgfs_fw_dbg_conf_read(struct file
*file
,
941 char __user
*user_buf
,
942 size_t count
, loff_t
*ppos
)
944 struct iwl_mvm
*mvm
= file
->private_data
;
945 enum iwl_fw_dbg_conf conf
;
947 const size_t bufsz
= sizeof(buf
);
950 mutex_lock(&mvm
->mutex
);
951 conf
= mvm
->fw_dbg_conf
;
952 mutex_unlock(&mvm
->mutex
);
954 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "%d\n", conf
);
956 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
959 static ssize_t
iwl_dbgfs_fw_dbg_conf_write(struct iwl_mvm
*mvm
,
960 char *buf
, size_t count
,
965 ret
= kstrtoint(buf
, 0, &conf_id
);
969 if (WARN_ON(conf_id
>= FW_DBG_MAX
))
972 mutex_lock(&mvm
->mutex
);
973 ret
= iwl_mvm_start_fw_dbg_conf(mvm
, conf_id
);
974 mutex_unlock(&mvm
->mutex
);
979 static ssize_t
iwl_dbgfs_fw_dbg_collect_write(struct iwl_mvm
*mvm
,
980 char *buf
, size_t count
,
983 int ret
= iwl_mvm_ref_sync(mvm
, IWL_MVM_REF_PRPH_WRITE
);
988 iwl_mvm_fw_dbg_collect(mvm
);
990 iwl_mvm_unref(mvm
, IWL_MVM_REF_PRPH_WRITE
);
995 #define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__)
996 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
997 static ssize_t
iwl_dbgfs_bcast_filters_read(struct file
*file
,
998 char __user
*user_buf
,
999 size_t count
, loff_t
*ppos
)
1001 struct iwl_mvm
*mvm
= file
->private_data
;
1002 struct iwl_bcast_filter_cmd cmd
;
1003 const struct iwl_fw_bcast_filter
*filter
;
1009 buf
= kzalloc(bufsz
, GFP_KERNEL
);
1013 mutex_lock(&mvm
->mutex
);
1014 if (!iwl_mvm_bcast_filter_build_cmd(mvm
, &cmd
)) {
1016 mutex_unlock(&mvm
->mutex
);
1019 mutex_unlock(&mvm
->mutex
);
1021 for (i
= 0; cmd
.filters
[i
].attrs
[0].mask
; i
++) {
1022 filter
= &cmd
.filters
[i
];
1024 ADD_TEXT("Filter [%d]:\n", i
);
1025 ADD_TEXT("\tDiscard=%d\n", filter
->discard
);
1026 ADD_TEXT("\tFrame Type: %s\n",
1027 filter
->frame_type
? "IPv4" : "Generic");
1029 for (j
= 0; j
< ARRAY_SIZE(filter
->attrs
); j
++) {
1030 const struct iwl_fw_bcast_filter_attr
*attr
;
1032 attr
= &filter
->attrs
[j
];
1036 ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n",
1038 attr
->offset_type
? "IP End" :
1040 be32_to_cpu(attr
->mask
),
1041 be32_to_cpu(attr
->val
),
1042 le16_to_cpu(attr
->reserved1
));
1046 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1051 static ssize_t
iwl_dbgfs_bcast_filters_write(struct iwl_mvm
*mvm
, char *buf
,
1052 size_t count
, loff_t
*ppos
)
1055 struct iwl_fw_bcast_filter filter
= {};
1056 struct iwl_bcast_filter_cmd cmd
;
1057 u32 filter_id
, attr_id
, mask
, value
;
1060 if (sscanf(buf
, "%d %hhi %hhi %n", &filter_id
, &filter
.discard
,
1061 &filter
.frame_type
, &pos
) != 3)
1064 if (filter_id
>= ARRAY_SIZE(mvm
->dbgfs_bcast_filtering
.cmd
.filters
) ||
1065 filter
.frame_type
> BCAST_FILTER_FRAME_TYPE_IPV4
)
1068 for (attr_id
= 0; attr_id
< ARRAY_SIZE(filter
.attrs
);
1070 struct iwl_fw_bcast_filter_attr
*attr
=
1071 &filter
.attrs
[attr_id
];
1076 if (sscanf(&buf
[pos
], "%hhi %hhi %i %i %n",
1077 &attr
->offset
, &attr
->offset_type
,
1078 &mask
, &value
, &next_pos
) != 4)
1081 attr
->mask
= cpu_to_be32(mask
);
1082 attr
->val
= cpu_to_be32(value
);
1089 mutex_lock(&mvm
->mutex
);
1090 memcpy(&mvm
->dbgfs_bcast_filtering
.cmd
.filters
[filter_id
],
1091 &filter
, sizeof(filter
));
1093 /* send updated bcast filtering configuration */
1094 if (mvm
->dbgfs_bcast_filtering
.override
&&
1095 iwl_mvm_bcast_filter_build_cmd(mvm
, &cmd
))
1096 err
= iwl_mvm_send_cmd_pdu(mvm
, BCAST_FILTER_CMD
, 0,
1098 mutex_unlock(&mvm
->mutex
);
1100 return err
?: count
;
1103 static ssize_t
iwl_dbgfs_bcast_filters_macs_read(struct file
*file
,
1104 char __user
*user_buf
,
1105 size_t count
, loff_t
*ppos
)
1107 struct iwl_mvm
*mvm
= file
->private_data
;
1108 struct iwl_bcast_filter_cmd cmd
;
1114 buf
= kzalloc(bufsz
, GFP_KERNEL
);
1118 mutex_lock(&mvm
->mutex
);
1119 if (!iwl_mvm_bcast_filter_build_cmd(mvm
, &cmd
)) {
1121 mutex_unlock(&mvm
->mutex
);
1124 mutex_unlock(&mvm
->mutex
);
1126 for (i
= 0; i
< ARRAY_SIZE(cmd
.macs
); i
++) {
1127 const struct iwl_fw_bcast_mac
*mac
= &cmd
.macs
[i
];
1129 ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n",
1130 i
, mac
->default_discard
, mac
->attached_filters
);
1133 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1138 static ssize_t
iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm
*mvm
,
1139 char *buf
, size_t count
,
1142 struct iwl_bcast_filter_cmd cmd
;
1143 struct iwl_fw_bcast_mac mac
= {};
1144 u32 mac_id
, attached_filters
;
1147 if (!mvm
->bcast_filters
)
1150 if (sscanf(buf
, "%d %hhi %i", &mac_id
, &mac
.default_discard
,
1151 &attached_filters
) != 3)
1154 if (mac_id
>= ARRAY_SIZE(cmd
.macs
) ||
1155 mac
.default_discard
> 1 ||
1156 attached_filters
>= BIT(ARRAY_SIZE(cmd
.filters
)))
1159 mac
.attached_filters
= cpu_to_le16(attached_filters
);
1161 mutex_lock(&mvm
->mutex
);
1162 memcpy(&mvm
->dbgfs_bcast_filtering
.cmd
.macs
[mac_id
],
1165 /* send updated bcast filtering configuration */
1166 if (mvm
->dbgfs_bcast_filtering
.override
&&
1167 iwl_mvm_bcast_filter_build_cmd(mvm
, &cmd
))
1168 err
= iwl_mvm_send_cmd_pdu(mvm
, BCAST_FILTER_CMD
, 0,
1170 mutex_unlock(&mvm
->mutex
);
1172 return err
?: count
;
1176 #ifdef CONFIG_PM_SLEEP
1177 static ssize_t
iwl_dbgfs_d3_sram_write(struct iwl_mvm
*mvm
, char *buf
,
1178 size_t count
, loff_t
*ppos
)
1182 if (sscanf(buf
, "%d", &store
) != 1)
1185 mvm
->store_d3_resume_sram
= store
;
1190 static ssize_t
iwl_dbgfs_d3_sram_read(struct file
*file
, char __user
*user_buf
,
1191 size_t count
, loff_t
*ppos
)
1193 struct iwl_mvm
*mvm
= file
->private_data
;
1194 const struct fw_img
*img
;
1195 int ofs
, len
, pos
= 0;
1198 u8
*ptr
= mvm
->d3_resume_sram
;
1200 img
= &mvm
->fw
->img
[IWL_UCODE_WOWLAN
];
1201 len
= img
->sec
[IWL_UCODE_SECTION_DATA
].len
;
1203 bufsz
= len
* 4 + 256;
1204 buf
= kzalloc(bufsz
, GFP_KERNEL
);
1208 pos
+= scnprintf(buf
, bufsz
, "D3 SRAM capture: %sabled\n",
1209 mvm
->store_d3_resume_sram
? "en" : "dis");
1212 for (ofs
= 0; ofs
< len
; ofs
+= 16) {
1213 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1215 hex_dump_to_buffer(ptr
+ ofs
, 16, 16, 1, buf
+ pos
,
1216 bufsz
- pos
, false);
1217 pos
+= strlen(buf
+ pos
);
1218 if (bufsz
- pos
> 0)
1222 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1223 "(no data captured)\n");
1226 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1233 #define MAX_NUM_ND_MATCHSETS 10
1235 static ssize_t
iwl_dbgfs_netdetect_write(struct iwl_mvm
*mvm
, char *buf
,
1236 size_t count
, loff_t
*ppos
)
1238 const char *seps
= ",\n";
1239 char *buf_ptr
= buf
;
1240 char *value_str
= NULL
;
1243 /* TODO: don't free if write is being called several times in one go */
1244 if (mvm
->nd_config
) {
1245 kfree(mvm
->nd_config
->match_sets
);
1246 kfree(mvm
->nd_config
);
1247 mvm
->nd_config
= NULL
;
1250 mvm
->nd_config
= kzalloc(sizeof(*mvm
->nd_config
) +
1251 (11 * sizeof(struct ieee80211_channel
*)),
1253 if (!mvm
->nd_config
) {
1258 mvm
->nd_config
->n_channels
= 11;
1259 mvm
->nd_config
->scan_width
= NL80211_BSS_CHAN_WIDTH_20
;
1260 mvm
->nd_config
->interval
= 5;
1261 mvm
->nd_config
->min_rssi_thold
= -80;
1262 for (i
= 0; i
< mvm
->nd_config
->n_channels
; i
++)
1263 mvm
->nd_config
->channels
[i
] = &mvm
->nvm_data
->channels
[i
];
1265 mvm
->nd_config
->match_sets
=
1266 kcalloc(MAX_NUM_ND_MATCHSETS
,
1267 sizeof(*mvm
->nd_config
->match_sets
),
1269 if (!mvm
->nd_config
->match_sets
) {
1274 while ((value_str
= strsep(&buf_ptr
, seps
)) &&
1275 strlen(value_str
)) {
1276 struct cfg80211_match_set
*set
;
1278 if (mvm
->nd_config
->n_match_sets
>= MAX_NUM_ND_MATCHSETS
) {
1283 set
= &mvm
->nd_config
->match_sets
[mvm
->nd_config
->n_match_sets
];
1284 set
->ssid
.ssid_len
= strlen(value_str
);
1286 if (set
->ssid
.ssid_len
> IEEE80211_MAX_SSID_LEN
) {
1291 memcpy(set
->ssid
.ssid
, value_str
, set
->ssid
.ssid_len
);
1293 mvm
->nd_config
->n_match_sets
++;
1298 if (mvm
->nd_config
->n_match_sets
)
1303 kfree(mvm
->nd_config
->match_sets
);
1304 kfree(mvm
->nd_config
);
1305 mvm
->nd_config
= NULL
;
1311 iwl_dbgfs_netdetect_read(struct file
*file
, char __user
*user_buf
,
1312 size_t count
, loff_t
*ppos
)
1314 struct iwl_mvm
*mvm
= file
->private_data
;
1317 int i
, n_match_sets
, pos
= 0;
1319 n_match_sets
= mvm
->nd_config
? mvm
->nd_config
->n_match_sets
: 0;
1321 bufsz
= n_match_sets
* (IEEE80211_MAX_SSID_LEN
+ 1) + 1;
1322 buf
= kzalloc(bufsz
, GFP_KERNEL
);
1326 for (i
= 0; i
< n_match_sets
; i
++) {
1328 mvm
->nd_config
->match_sets
[i
].ssid
.ssid_len
+ 2 > bufsz
) {
1333 memcpy(buf
+ pos
, mvm
->nd_config
->match_sets
[i
].ssid
.ssid
,
1334 mvm
->nd_config
->match_sets
[i
].ssid
.ssid_len
);
1335 pos
+= mvm
->nd_config
->match_sets
[i
].ssid
.ssid_len
;
1339 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1346 #define PRINT_MVM_REF(ref) do { \
1347 if (mvm->refs[ref]) \
1348 pos += scnprintf(buf + pos, bufsz - pos, \
1349 "\t(0x%lx): %d %s\n", \
1350 BIT(ref), mvm->refs[ref], #ref); \
1353 static ssize_t
iwl_dbgfs_d0i3_refs_read(struct file
*file
,
1354 char __user
*user_buf
,
1355 size_t count
, loff_t
*ppos
)
1357 struct iwl_mvm
*mvm
= file
->private_data
;
1360 const size_t bufsz
= sizeof(buf
);
1363 for (i
= 0; i
< IWL_MVM_REF_COUNT
; i
++)
1367 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "taken mvm refs: 0x%x\n",
1370 PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN
);
1371 PRINT_MVM_REF(IWL_MVM_REF_SCAN
);
1372 PRINT_MVM_REF(IWL_MVM_REF_ROC
);
1373 PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT
);
1374 PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS
);
1375 PRINT_MVM_REF(IWL_MVM_REF_USER
);
1376 PRINT_MVM_REF(IWL_MVM_REF_TX
);
1377 PRINT_MVM_REF(IWL_MVM_REF_TX_AGG
);
1378 PRINT_MVM_REF(IWL_MVM_REF_ADD_IF
);
1379 PRINT_MVM_REF(IWL_MVM_REF_START_AP
);
1380 PRINT_MVM_REF(IWL_MVM_REF_BSS_CHANGED
);
1381 PRINT_MVM_REF(IWL_MVM_REF_PREPARE_TX
);
1382 PRINT_MVM_REF(IWL_MVM_REF_PROTECT_TDLS
);
1383 PRINT_MVM_REF(IWL_MVM_REF_CHECK_CTKILL
);
1384 PRINT_MVM_REF(IWL_MVM_REF_PRPH_READ
);
1385 PRINT_MVM_REF(IWL_MVM_REF_PRPH_WRITE
);
1386 PRINT_MVM_REF(IWL_MVM_REF_NMI
);
1387 PRINT_MVM_REF(IWL_MVM_REF_TM_CMD
);
1388 PRINT_MVM_REF(IWL_MVM_REF_EXIT_WORK
);
1389 PRINT_MVM_REF(IWL_MVM_REF_PROTECT_CSA
);
1390 PRINT_MVM_REF(IWL_MVM_REF_FW_DBG_COLLECT
);
1392 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1395 static ssize_t
iwl_dbgfs_d0i3_refs_write(struct iwl_mvm
*mvm
, char *buf
,
1396 size_t count
, loff_t
*ppos
)
1398 unsigned long value
;
1402 ret
= kstrtoul(buf
, 10, &value
);
1406 mutex_lock(&mvm
->mutex
);
1408 taken
= mvm
->refs
[IWL_MVM_REF_USER
];
1409 if (value
== 1 && !taken
)
1410 iwl_mvm_ref(mvm
, IWL_MVM_REF_USER
);
1411 else if (value
== 0 && taken
)
1412 iwl_mvm_unref(mvm
, IWL_MVM_REF_USER
);
1416 mutex_unlock(&mvm
->mutex
);
1423 #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
1424 _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1425 #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
1426 _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1427 #define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \
1428 if (!debugfs_create_file(alias, mode, parent, mvm, \
1429 &iwl_dbgfs_##name##_ops)) \
1432 #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
1433 MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
1436 iwl_dbgfs_prph_reg_read(struct file
*file
,
1437 char __user
*user_buf
,
1438 size_t count
, loff_t
*ppos
)
1440 struct iwl_mvm
*mvm
= file
->private_data
;
1443 const size_t bufsz
= sizeof(buf
);
1446 if (!mvm
->dbgfs_prph_reg_addr
)
1449 ret
= iwl_mvm_ref_sync(mvm
, IWL_MVM_REF_PRPH_READ
);
1453 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "Reg 0x%x: (0x%x)\n",
1454 mvm
->dbgfs_prph_reg_addr
,
1455 iwl_read_prph(mvm
->trans
, mvm
->dbgfs_prph_reg_addr
));
1457 iwl_mvm_unref(mvm
, IWL_MVM_REF_PRPH_READ
);
1459 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1463 iwl_dbgfs_prph_reg_write(struct iwl_mvm
*mvm
, char *buf
,
1464 size_t count
, loff_t
*ppos
)
1470 args
= sscanf(buf
, "%i %i", &mvm
->dbgfs_prph_reg_addr
, &value
);
1471 /* if we only want to set the reg address - nothing more to do */
1475 /* otherwise, make sure we have both address and value */
1479 ret
= iwl_mvm_ref_sync(mvm
, IWL_MVM_REF_PRPH_WRITE
);
1483 iwl_write_prph(mvm
->trans
, mvm
->dbgfs_prph_reg_addr
, value
);
1485 iwl_mvm_unref(mvm
, IWL_MVM_REF_PRPH_WRITE
);
1490 static ssize_t
iwl_dbgfs_enable_scan_iteration_notif_write(struct iwl_mvm
*mvm
,
1497 mutex_lock(&mvm
->mutex
);
1499 if (kstrtoint(buf
, 10, &val
)) {
1500 mutex_unlock(&mvm
->mutex
);
1504 mvm
->scan_iter_notif_enabled
= val
;
1505 mutex_unlock(&mvm
->mutex
);
1510 MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg
, 64);
1512 /* Device wide debugfs entries */
1513 MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush
, 16);
1514 MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain
, 8);
1515 MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram
, 64);
1516 MVM_DEBUGFS_READ_WRITE_FILE_OPS(set_nic_temperature
, 64);
1517 MVM_DEBUGFS_READ_FILE_OPS(nic_temp
);
1518 MVM_DEBUGFS_READ_FILE_OPS(stations
);
1519 MVM_DEBUGFS_READ_FILE_OPS(bt_notif
);
1520 MVM_DEBUGFS_READ_FILE_OPS(bt_cmd
);
1521 MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off
, 64);
1522 MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats
);
1523 MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats
);
1524 MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart
, 10);
1525 MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi
, 10);
1526 MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio
, 10);
1527 MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant
, 10);
1528 MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain
, 8);
1529 MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs
, 8);
1530 MVM_DEBUGFS_READ_WRITE_FILE_OPS(fw_dbg_conf
, 8);
1531 MVM_DEBUGFS_WRITE_FILE_OPS(fw_dbg_collect
, 8);
1532 MVM_DEBUGFS_WRITE_FILE_OPS(enable_scan_iteration_notif
, 8);
1534 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1535 MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters
, 256);
1536 MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs
, 256);
1539 #ifdef CONFIG_PM_SLEEP
1540 MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram
, 8);
1541 MVM_DEBUGFS_READ_WRITE_FILE_OPS(netdetect
, 384);
1544 int iwl_mvm_dbgfs_register(struct iwl_mvm
*mvm
, struct dentry
*dbgfs_dir
)
1546 struct dentry
*bcast_dir __maybe_unused
;
1549 spin_lock_init(&mvm
->drv_stats_lock
);
1551 mvm
->debugfs_dir
= dbgfs_dir
;
1553 MVM_DEBUGFS_ADD_FILE(tx_flush
, mvm
->debugfs_dir
, S_IWUSR
);
1554 MVM_DEBUGFS_ADD_FILE(sta_drain
, mvm
->debugfs_dir
, S_IWUSR
);
1555 MVM_DEBUGFS_ADD_FILE(sram
, mvm
->debugfs_dir
, S_IWUSR
| S_IRUSR
);
1556 MVM_DEBUGFS_ADD_FILE(set_nic_temperature
, mvm
->debugfs_dir
,
1558 MVM_DEBUGFS_ADD_FILE(nic_temp
, dbgfs_dir
, S_IRUSR
);
1559 MVM_DEBUGFS_ADD_FILE(stations
, dbgfs_dir
, S_IRUSR
);
1560 MVM_DEBUGFS_ADD_FILE(bt_notif
, dbgfs_dir
, S_IRUSR
);
1561 MVM_DEBUGFS_ADD_FILE(bt_cmd
, dbgfs_dir
, S_IRUSR
);
1562 MVM_DEBUGFS_ADD_FILE(disable_power_off
, mvm
->debugfs_dir
,
1564 MVM_DEBUGFS_ADD_FILE(fw_rx_stats
, mvm
->debugfs_dir
, S_IRUSR
);
1565 MVM_DEBUGFS_ADD_FILE(drv_rx_stats
, mvm
->debugfs_dir
, S_IRUSR
);
1566 MVM_DEBUGFS_ADD_FILE(fw_restart
, mvm
->debugfs_dir
, S_IWUSR
);
1567 MVM_DEBUGFS_ADD_FILE(fw_nmi
, mvm
->debugfs_dir
, S_IWUSR
);
1568 MVM_DEBUGFS_ADD_FILE(bt_tx_prio
, mvm
->debugfs_dir
, S_IWUSR
);
1569 MVM_DEBUGFS_ADD_FILE(bt_force_ant
, mvm
->debugfs_dir
, S_IWUSR
);
1570 MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain
, mvm
->debugfs_dir
,
1572 MVM_DEBUGFS_ADD_FILE(prph_reg
, mvm
->debugfs_dir
, S_IWUSR
| S_IRUSR
);
1573 MVM_DEBUGFS_ADD_FILE(d0i3_refs
, mvm
->debugfs_dir
, S_IRUSR
| S_IWUSR
);
1574 MVM_DEBUGFS_ADD_FILE(fw_dbg_conf
, mvm
->debugfs_dir
, S_IRUSR
| S_IWUSR
);
1575 MVM_DEBUGFS_ADD_FILE(fw_dbg_collect
, mvm
->debugfs_dir
, S_IWUSR
);
1576 MVM_DEBUGFS_ADD_FILE(enable_scan_iteration_notif
, mvm
->debugfs_dir
,
1579 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1580 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_BCAST_FILTERING
) {
1581 bcast_dir
= debugfs_create_dir("bcast_filtering",
1586 if (!debugfs_create_bool("override", S_IRUSR
| S_IWUSR
,
1588 &mvm
->dbgfs_bcast_filtering
.override
))
1591 MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters
,
1592 bcast_dir
, S_IWUSR
| S_IRUSR
);
1593 MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs
,
1594 bcast_dir
, S_IWUSR
| S_IRUSR
);
1598 #ifdef CONFIG_PM_SLEEP
1599 MVM_DEBUGFS_ADD_FILE(d3_sram
, mvm
->debugfs_dir
, S_IRUSR
| S_IWUSR
);
1600 MVM_DEBUGFS_ADD_FILE(d3_test
, mvm
->debugfs_dir
, S_IRUSR
);
1601 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR
| S_IWUSR
,
1602 mvm
->debugfs_dir
, &mvm
->d3_wake_sysassert
))
1604 MVM_DEBUGFS_ADD_FILE(netdetect
, mvm
->debugfs_dir
, S_IRUSR
| S_IWUSR
);
1607 if (!debugfs_create_u8("low_latency_agg_frame_limit", S_IRUSR
| S_IWUSR
,
1609 &mvm
->low_latency_agg_frame_limit
))
1611 if (!debugfs_create_u8("ps_disabled", S_IRUSR
,
1612 mvm
->debugfs_dir
, &mvm
->ps_disabled
))
1614 if (!debugfs_create_blob("nvm_hw", S_IRUSR
,
1615 mvm
->debugfs_dir
, &mvm
->nvm_hw_blob
))
1617 if (!debugfs_create_blob("nvm_sw", S_IRUSR
,
1618 mvm
->debugfs_dir
, &mvm
->nvm_sw_blob
))
1620 if (!debugfs_create_blob("nvm_calib", S_IRUSR
,
1621 mvm
->debugfs_dir
, &mvm
->nvm_calib_blob
))
1623 if (!debugfs_create_blob("nvm_prod", S_IRUSR
,
1624 mvm
->debugfs_dir
, &mvm
->nvm_prod_blob
))
1628 * Create a symlink with mac80211. It will be removed when mac80211
1629 * exists (before the opmode exists which removes the target.)
1631 snprintf(buf
, 100, "../../%s/%s",
1632 dbgfs_dir
->d_parent
->d_parent
->d_name
.name
,
1633 dbgfs_dir
->d_parent
->d_name
.name
);
1634 if (!debugfs_create_symlink("iwlwifi", mvm
->hw
->wiphy
->debugfsdir
, buf
))
1639 IWL_ERR(mvm
, "Can't create the mvm debugfs directory\n");