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 - 2013 Intel Corporation. All rights reserved.
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.
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.
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,
24 * The full GNU General Public License is included in this distribution
25 * in the file called COPYING.
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
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
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.
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.
62 *****************************************************************************/
67 struct iwl_dbgfs_mvm_ctx
{
69 struct ieee80211_vif
*vif
;
72 static ssize_t
iwl_dbgfs_tx_flush_write(struct file
*file
,
73 const char __user
*user_buf
,
74 size_t count
, loff_t
*ppos
)
76 struct iwl_mvm
*mvm
= file
->private_data
;
82 if (!mvm
->ucode_loaded
|| mvm
->cur_ucode
!= IWL_UCODE_REGULAR
)
85 memset(buf
, 0, sizeof(buf
));
86 buf_size
= min(count
, sizeof(buf
) - 1);
87 if (copy_from_user(buf
, user_buf
, buf_size
))
90 if (sscanf(buf
, "%x", &scd_q_msk
) != 1)
93 IWL_ERR(mvm
, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk
);
95 mutex_lock(&mvm
->mutex
);
96 ret
= iwl_mvm_flush_tx_path(mvm
, scd_q_msk
, true) ? : count
;
97 mutex_unlock(&mvm
->mutex
);
102 static ssize_t
iwl_dbgfs_sta_drain_write(struct file
*file
,
103 const char __user
*user_buf
,
104 size_t count
, loff_t
*ppos
)
106 struct iwl_mvm
*mvm
= file
->private_data
;
107 struct ieee80211_sta
*sta
;
110 int buf_size
, sta_id
, drain
, ret
;
112 if (!mvm
->ucode_loaded
|| mvm
->cur_ucode
!= IWL_UCODE_REGULAR
)
115 memset(buf
, 0, sizeof(buf
));
116 buf_size
= min(count
, sizeof(buf
) - 1);
117 if (copy_from_user(buf
, user_buf
, buf_size
))
120 if (sscanf(buf
, "%d %d", &sta_id
, &drain
) != 2)
123 mutex_lock(&mvm
->mutex
);
125 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
126 lockdep_is_held(&mvm
->mutex
));
127 if (IS_ERR_OR_NULL(sta
))
130 ret
= iwl_mvm_drain_sta(mvm
, (void *)sta
->drv_priv
, drain
) ? :
133 mutex_unlock(&mvm
->mutex
);
138 static ssize_t
iwl_dbgfs_sram_read(struct file
*file
, char __user
*user_buf
,
139 size_t count
, loff_t
*ppos
)
141 struct iwl_mvm
*mvm
= file
->private_data
;
142 const struct fw_img
*img
;
143 int ofs
, len
, pos
= 0;
148 if (!mvm
->ucode_loaded
)
151 /* default is to dump the entire data segment */
152 if (!mvm
->dbgfs_sram_offset
&& !mvm
->dbgfs_sram_len
) {
153 img
= &mvm
->fw
->img
[mvm
->cur_ucode
];
154 ofs
= img
->sec
[IWL_UCODE_SECTION_DATA
].offset
;
155 len
= img
->sec
[IWL_UCODE_SECTION_DATA
].len
;
157 ofs
= mvm
->dbgfs_sram_offset
;
158 len
= mvm
->dbgfs_sram_len
;
161 bufsz
= len
* 4 + 256;
162 buf
= kzalloc(bufsz
, GFP_KERNEL
);
166 ptr
= kzalloc(len
, GFP_KERNEL
);
172 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "sram_len: 0x%x\n", len
);
173 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "sram_offset: 0x%x\n", ofs
);
175 iwl_trans_read_mem_bytes(mvm
->trans
, ofs
, ptr
, len
);
176 for (ofs
= 0; ofs
< len
; ofs
+= 16) {
177 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "0x%.4x ", ofs
);
178 hex_dump_to_buffer(ptr
+ ofs
, 16, 16, 1, buf
+ pos
,
180 pos
+= strlen(buf
+ pos
);
185 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
193 static ssize_t
iwl_dbgfs_sram_write(struct file
*file
,
194 const char __user
*user_buf
, size_t count
,
197 struct iwl_mvm
*mvm
= file
->private_data
;
202 memset(buf
, 0, sizeof(buf
));
203 buf_size
= min(count
, sizeof(buf
) - 1);
204 if (copy_from_user(buf
, user_buf
, buf_size
))
207 if (sscanf(buf
, "%x,%x", &offset
, &len
) == 2) {
208 if ((offset
& 0x3) || (len
& 0x3))
210 mvm
->dbgfs_sram_offset
= offset
;
211 mvm
->dbgfs_sram_len
= len
;
213 mvm
->dbgfs_sram_offset
= 0;
214 mvm
->dbgfs_sram_len
= 0;
220 static ssize_t
iwl_dbgfs_stations_read(struct file
*file
, char __user
*user_buf
,
221 size_t count
, loff_t
*ppos
)
223 struct iwl_mvm
*mvm
= file
->private_data
;
224 struct ieee80211_sta
*sta
;
226 int i
, pos
= 0, bufsz
= sizeof(buf
);
228 mutex_lock(&mvm
->mutex
);
230 for (i
= 0; i
< IWL_MVM_STATION_COUNT
; i
++) {
231 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "%.2d: ", i
);
232 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[i
],
233 lockdep_is_held(&mvm
->mutex
));
235 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "N/A\n");
236 else if (IS_ERR(sta
))
237 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "%ld\n",
240 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "%pM\n",
244 mutex_unlock(&mvm
->mutex
);
246 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
249 static ssize_t
iwl_dbgfs_power_down_allow_write(struct file
*file
,
250 const char __user
*user_buf
,
251 size_t count
, loff_t
*ppos
)
253 struct iwl_mvm
*mvm
= file
->private_data
;
257 if (!mvm
->ucode_loaded
)
260 if (copy_from_user(buf
, user_buf
, sizeof(buf
)))
263 if (sscanf(buf
, "%d", &allow
) != 1)
266 IWL_DEBUG_POWER(mvm
, "%s device power down\n",
267 allow
? "allow" : "prevent");
270 * TODO: Send REPLY_DEBUG_CMD (0xf0) when FW support it
276 static ssize_t
iwl_dbgfs_power_down_d3_allow_write(struct file
*file
,
277 const char __user
*user_buf
,
278 size_t count
, loff_t
*ppos
)
280 struct iwl_mvm
*mvm
= file
->private_data
;
284 if (copy_from_user(buf
, user_buf
, sizeof(buf
)))
287 if (sscanf(buf
, "%d", &allow
) != 1)
290 IWL_DEBUG_POWER(mvm
, "%s device power down in d3\n",
291 allow
? "allow" : "prevent");
294 * TODO: When WoWLAN FW alive notification happens, driver will send
295 * REPLY_DEBUG_CMD setting power_down_allow flag according to
296 * mvm->prevent_power_down_d3
298 mvm
->prevent_power_down_d3
= !allow
;
303 static void iwl_dbgfs_update_pm(struct iwl_mvm
*mvm
,
304 struct ieee80211_vif
*vif
,
305 enum iwl_dbgfs_pm_mask param
, int val
)
307 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
308 struct iwl_dbgfs_pm
*dbgfs_pm
= &mvmvif
->dbgfs_pm
;
310 dbgfs_pm
->mask
|= param
;
313 case MVM_DEBUGFS_PM_KEEP_ALIVE
: {
314 struct ieee80211_hw
*hw
= mvm
->hw
;
315 int dtimper
= hw
->conf
.ps_dtim_period
?: 1;
316 int dtimper_msec
= dtimper
* vif
->bss_conf
.beacon_int
;
318 IWL_DEBUG_POWER(mvm
, "debugfs: set keep_alive= %d sec\n", val
);
319 if (val
* MSEC_PER_SEC
< 3 * dtimper_msec
) {
321 "debugfs: keep alive period (%ld msec) is less than minimum required (%d msec)\n",
322 val
* MSEC_PER_SEC
, 3 * dtimper_msec
);
324 dbgfs_pm
->keep_alive_seconds
= val
;
327 case MVM_DEBUGFS_PM_SKIP_OVER_DTIM
:
328 IWL_DEBUG_POWER(mvm
, "skip_over_dtim %s\n",
329 val
? "enabled" : "disabled");
330 dbgfs_pm
->skip_over_dtim
= val
;
332 case MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS
:
333 IWL_DEBUG_POWER(mvm
, "skip_dtim_periods=%d\n", val
);
334 dbgfs_pm
->skip_dtim_periods
= val
;
336 case MVM_DEBUGFS_PM_RX_DATA_TIMEOUT
:
337 IWL_DEBUG_POWER(mvm
, "rx_data_timeout=%d\n", val
);
338 dbgfs_pm
->rx_data_timeout
= val
;
340 case MVM_DEBUGFS_PM_TX_DATA_TIMEOUT
:
341 IWL_DEBUG_POWER(mvm
, "tx_data_timeout=%d\n", val
);
342 dbgfs_pm
->tx_data_timeout
= val
;
344 case MVM_DEBUGFS_PM_DISABLE_POWER_OFF
:
345 IWL_DEBUG_POWER(mvm
, "disable_power_off=%d\n", val
);
346 dbgfs_pm
->disable_power_off
= val
;
351 static ssize_t
iwl_dbgfs_pm_params_write(struct file
*file
,
352 const char __user
*user_buf
,
353 size_t count
, loff_t
*ppos
)
355 struct ieee80211_vif
*vif
= file
->private_data
;
356 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
357 struct iwl_mvm
*mvm
= mvmvif
->dbgfs_data
;
358 enum iwl_dbgfs_pm_mask param
;
363 if (copy_from_user(buf
, user_buf
, sizeof(buf
)))
366 if (!strncmp("keep_alive=", buf
, 11)) {
367 if (sscanf(buf
+ 11, "%d", &val
) != 1)
369 param
= MVM_DEBUGFS_PM_KEEP_ALIVE
;
370 } else if (!strncmp("skip_over_dtim=", buf
, 15)) {
371 if (sscanf(buf
+ 15, "%d", &val
) != 1)
373 param
= MVM_DEBUGFS_PM_SKIP_OVER_DTIM
;
374 } else if (!strncmp("skip_dtim_periods=", buf
, 18)) {
375 if (sscanf(buf
+ 18, "%d", &val
) != 1)
377 param
= MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS
;
378 } else if (!strncmp("rx_data_timeout=", buf
, 16)) {
379 if (sscanf(buf
+ 16, "%d", &val
) != 1)
381 param
= MVM_DEBUGFS_PM_RX_DATA_TIMEOUT
;
382 } else if (!strncmp("tx_data_timeout=", buf
, 16)) {
383 if (sscanf(buf
+ 16, "%d", &val
) != 1)
385 param
= MVM_DEBUGFS_PM_TX_DATA_TIMEOUT
;
386 } else if (!strncmp("disable_power_off=", buf
, 18)) {
387 if (sscanf(buf
+ 18, "%d", &val
) != 1)
389 param
= MVM_DEBUGFS_PM_DISABLE_POWER_OFF
;
394 mutex_lock(&mvm
->mutex
);
395 iwl_dbgfs_update_pm(mvm
, vif
, param
, val
);
396 ret
= iwl_mvm_power_update_mode(mvm
, vif
);
397 mutex_unlock(&mvm
->mutex
);
402 static ssize_t
iwl_dbgfs_pm_params_read(struct file
*file
,
403 char __user
*user_buf
,
404 size_t count
, loff_t
*ppos
)
406 struct ieee80211_vif
*vif
= file
->private_data
;
407 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
408 struct iwl_mvm
*mvm
= mvmvif
->dbgfs_data
;
409 struct iwl_powertable_cmd cmd
= {};
411 int bufsz
= sizeof(buf
);
414 iwl_mvm_power_build_cmd(mvm
, vif
, &cmd
);
416 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "disable_power_off = %d\n",
418 cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK
)) ?
420 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "skip_dtim_periods = %d\n",
421 le32_to_cpu(cmd
.skip_dtim_periods
));
422 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "power_scheme = %d\n",
423 iwlmvm_mod_params
.power_scheme
);
424 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "flags = %d\n",
425 le16_to_cpu(cmd
.flags
));
426 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "keep_alive = %d\n",
427 cmd
.keep_alive_seconds
);
429 if (cmd
.flags
& cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK
)) {
430 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "skip_over_dtim = %d\n",
432 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK
)) ?
434 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "rx_data_timeout = %d\n",
435 le32_to_cpu(cmd
.rx_data_timeout
));
436 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "tx_data_timeout = %d\n",
437 le32_to_cpu(cmd
.tx_data_timeout
));
440 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
443 static ssize_t
iwl_dbgfs_mac_params_read(struct file
*file
,
444 char __user
*user_buf
,
445 size_t count
, loff_t
*ppos
)
447 struct ieee80211_vif
*vif
= file
->private_data
;
448 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
449 struct iwl_mvm
*mvm
= mvmvif
->dbgfs_data
;
451 struct ieee80211_chanctx_conf
*chanctx_conf
;
453 int bufsz
= sizeof(buf
);
457 mutex_lock(&mvm
->mutex
);
459 ap_sta_id
= mvmvif
->ap_sta_id
;
461 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "mac id/color: %d / %d\n",
462 mvmvif
->id
, mvmvif
->color
);
463 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "bssid: %pM\n",
464 vif
->bss_conf
.bssid
);
465 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "QoS:\n");
466 for (i
= 0; i
< ARRAY_SIZE(mvmvif
->queue_params
); i
++) {
467 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
468 "\t%d: txop:%d - cw_min:%d - cw_max = %d - aifs = %d upasd = %d\n",
469 i
, mvmvif
->queue_params
[i
].txop
,
470 mvmvif
->queue_params
[i
].cw_min
,
471 mvmvif
->queue_params
[i
].cw_max
,
472 mvmvif
->queue_params
[i
].aifs
,
473 mvmvif
->queue_params
[i
].uapsd
);
476 if (vif
->type
== NL80211_IFTYPE_STATION
&&
477 ap_sta_id
!= IWL_MVM_STATION_COUNT
) {
478 struct ieee80211_sta
*sta
;
479 struct iwl_mvm_sta
*mvm_sta
;
481 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[ap_sta_id
],
482 lockdep_is_held(&mvm
->mutex
));
483 mvm_sta
= (void *)sta
->drv_priv
;
484 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
485 "ap_sta_id %d - reduced Tx power %d\n",
486 ap_sta_id
, mvm_sta
->bt_reduced_txpower
);
490 chanctx_conf
= rcu_dereference(vif
->chanctx_conf
);
492 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
493 "idle rx chains %d, active rx chains: %d\n",
494 chanctx_conf
->rx_chains_static
,
495 chanctx_conf
->rx_chains_dynamic
);
499 mutex_unlock(&mvm
->mutex
);
501 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
504 #define BT_MBOX_MSG(_notif, _num, _field) \
505 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
506 >> BT_MBOX##_num##_##_field##_POS)
509 #define BT_MBOX_PRINT(_num, _field, _end) \
510 pos += scnprintf(buf + pos, bufsz - pos, \
513 BT_MBOX_MSG(notif, _num, _field), \
516 static ssize_t
iwl_dbgfs_bt_notif_read(struct file
*file
, char __user
*user_buf
,
517 size_t count
, loff_t
*ppos
)
519 struct iwl_mvm
*mvm
= file
->private_data
;
520 struct iwl_bt_coex_profile_notif
*notif
= &mvm
->last_bt_notif
;
522 int ret
, pos
= 0, bufsz
= sizeof(char) * 1024;
524 buf
= kmalloc(bufsz
, GFP_KERNEL
);
528 mutex_lock(&mvm
->mutex
);
530 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "MBOX dw0:\n");
532 BT_MBOX_PRINT(0, LE_SLAVE_LAT
, false);
533 BT_MBOX_PRINT(0, LE_PROF1
, false);
534 BT_MBOX_PRINT(0, LE_PROF2
, false);
535 BT_MBOX_PRINT(0, LE_PROF_OTHER
, false);
536 BT_MBOX_PRINT(0, CHL_SEQ_N
, false);
537 BT_MBOX_PRINT(0, INBAND_S
, false);
538 BT_MBOX_PRINT(0, LE_MIN_RSSI
, false);
539 BT_MBOX_PRINT(0, LE_SCAN
, false);
540 BT_MBOX_PRINT(0, LE_ADV
, false);
541 BT_MBOX_PRINT(0, LE_MAX_TX_POWER
, false);
542 BT_MBOX_PRINT(0, OPEN_CON_1
, true);
544 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "MBOX dw1:\n");
546 BT_MBOX_PRINT(1, BR_MAX_TX_POWER
, false);
547 BT_MBOX_PRINT(1, IP_SR
, false);
548 BT_MBOX_PRINT(1, LE_MSTR
, false);
549 BT_MBOX_PRINT(1, AGGR_TRFC_LD
, false);
550 BT_MBOX_PRINT(1, MSG_TYPE
, false);
551 BT_MBOX_PRINT(1, SSN
, true);
553 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "MBOX dw2:\n");
555 BT_MBOX_PRINT(2, SNIFF_ACT
, false);
556 BT_MBOX_PRINT(2, PAG
, false);
557 BT_MBOX_PRINT(2, INQUIRY
, false);
558 BT_MBOX_PRINT(2, CONN
, false);
559 BT_MBOX_PRINT(2, SNIFF_INTERVAL
, false);
560 BT_MBOX_PRINT(2, DISC
, false);
561 BT_MBOX_PRINT(2, SCO_TX_ACT
, false);
562 BT_MBOX_PRINT(2, SCO_RX_ACT
, false);
563 BT_MBOX_PRINT(2, ESCO_RE_TX
, false);
564 BT_MBOX_PRINT(2, SCO_DURATION
, true);
566 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "MBOX dw3:\n");
568 BT_MBOX_PRINT(3, SCO_STATE
, false);
569 BT_MBOX_PRINT(3, SNIFF_STATE
, false);
570 BT_MBOX_PRINT(3, A2DP_STATE
, false);
571 BT_MBOX_PRINT(3, ACL_STATE
, false);
572 BT_MBOX_PRINT(3, MSTR_STATE
, false);
573 BT_MBOX_PRINT(3, OBX_STATE
, false);
574 BT_MBOX_PRINT(3, OPEN_CON_2
, false);
575 BT_MBOX_PRINT(3, TRAFFIC_LOAD
, false);
576 BT_MBOX_PRINT(3, CHL_SEQN_LSB
, false);
577 BT_MBOX_PRINT(3, INBAND_P
, false);
578 BT_MBOX_PRINT(3, MSG_TYPE_2
, false);
579 BT_MBOX_PRINT(3, SSN_2
, false);
580 BT_MBOX_PRINT(3, UPDATE_REQUEST
, true);
582 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "bt_status = %d\n",
584 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "bt_open_conn = %d\n",
585 notif
->bt_open_conn
);
586 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "bt_traffic_load = %d\n",
587 notif
->bt_traffic_load
);
588 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "bt_agg_traffic_load = %d\n",
589 notif
->bt_agg_traffic_load
);
590 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "bt_ci_compliance = %d\n",
591 notif
->bt_ci_compliance
);
593 mutex_unlock(&mvm
->mutex
);
595 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
602 static ssize_t
iwl_dbgfs_fw_restart_write(struct file
*file
,
603 const char __user
*user_buf
,
604 size_t count
, loff_t
*ppos
)
606 struct iwl_mvm
*mvm
= file
->private_data
;
607 bool restart_fw
= iwlwifi_mod_params
.restart_fw
;
610 iwlwifi_mod_params
.restart_fw
= true;
612 mutex_lock(&mvm
->mutex
);
614 /* take the return value to make compiler happy - it will fail anyway */
615 ret
= iwl_mvm_send_cmd_pdu(mvm
, REPLY_ERROR
, CMD_SYNC
, 0, NULL
);
617 mutex_unlock(&mvm
->mutex
);
619 iwlwifi_mod_params
.restart_fw
= restart_fw
;
624 static void iwl_dbgfs_update_bf(struct ieee80211_vif
*vif
,
625 enum iwl_dbgfs_bf_mask param
, int value
)
627 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
628 struct iwl_dbgfs_bf
*dbgfs_bf
= &mvmvif
->dbgfs_bf
;
630 dbgfs_bf
->mask
|= param
;
633 case MVM_DEBUGFS_BF_ENERGY_DELTA
:
634 dbgfs_bf
->bf_energy_delta
= value
;
636 case MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA
:
637 dbgfs_bf
->bf_roaming_energy_delta
= value
;
639 case MVM_DEBUGFS_BF_ROAMING_STATE
:
640 dbgfs_bf
->bf_roaming_state
= value
;
642 case MVM_DEBUGFS_BF_TEMPERATURE_DELTA
:
643 dbgfs_bf
->bf_temperature_delta
= value
;
645 case MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER
:
646 dbgfs_bf
->bf_enable_beacon_filter
= value
;
648 case MVM_DEBUGFS_BF_DEBUG_FLAG
:
649 dbgfs_bf
->bf_debug_flag
= value
;
651 case MVM_DEBUGFS_BF_ESCAPE_TIMER
:
652 dbgfs_bf
->bf_escape_timer
= value
;
654 case MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT
:
655 dbgfs_bf
->ba_enable_beacon_abort
= value
;
657 case MVM_DEBUGFS_BA_ESCAPE_TIMER
:
658 dbgfs_bf
->ba_escape_timer
= value
;
663 static ssize_t
iwl_dbgfs_bf_params_write(struct file
*file
,
664 const char __user
*user_buf
,
665 size_t count
, loff_t
*ppos
)
667 struct ieee80211_vif
*vif
= file
->private_data
;
668 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
669 struct iwl_mvm
*mvm
= mvmvif
->dbgfs_data
;
670 enum iwl_dbgfs_bf_mask param
;
676 memset(buf
, 0, sizeof(buf
));
677 buf_size
= min(count
, sizeof(buf
) - 1);
678 if (copy_from_user(buf
, user_buf
, buf_size
))
681 if (!strncmp("bf_energy_delta=", buf
, 16)) {
682 if (sscanf(buf
+16, "%d", &value
) != 1)
684 if (value
< IWL_BF_ENERGY_DELTA_MIN
||
685 value
> IWL_BF_ENERGY_DELTA_MAX
)
687 param
= MVM_DEBUGFS_BF_ENERGY_DELTA
;
688 } else if (!strncmp("bf_roaming_energy_delta=", buf
, 24)) {
689 if (sscanf(buf
+24, "%d", &value
) != 1)
691 if (value
< IWL_BF_ROAMING_ENERGY_DELTA_MIN
||
692 value
> IWL_BF_ROAMING_ENERGY_DELTA_MAX
)
694 param
= MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA
;
695 } else if (!strncmp("bf_roaming_state=", buf
, 17)) {
696 if (sscanf(buf
+17, "%d", &value
) != 1)
698 if (value
< IWL_BF_ROAMING_STATE_MIN
||
699 value
> IWL_BF_ROAMING_STATE_MAX
)
701 param
= MVM_DEBUGFS_BF_ROAMING_STATE
;
702 } else if (!strncmp("bf_temperature_delta=", buf
, 21)) {
703 if (sscanf(buf
+21, "%d", &value
) != 1)
705 if (value
< IWL_BF_TEMPERATURE_DELTA_MIN
||
706 value
> IWL_BF_TEMPERATURE_DELTA_MAX
)
708 param
= MVM_DEBUGFS_BF_TEMPERATURE_DELTA
;
709 } else if (!strncmp("bf_enable_beacon_filter=", buf
, 24)) {
710 if (sscanf(buf
+24, "%d", &value
) != 1)
712 if (value
< 0 || value
> 1)
714 param
= MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER
;
715 } else if (!strncmp("bf_debug_flag=", buf
, 14)) {
716 if (sscanf(buf
+14, "%d", &value
) != 1)
718 if (value
< 0 || value
> 1)
720 param
= MVM_DEBUGFS_BF_DEBUG_FLAG
;
721 } else if (!strncmp("bf_escape_timer=", buf
, 16)) {
722 if (sscanf(buf
+16, "%d", &value
) != 1)
724 if (value
< IWL_BF_ESCAPE_TIMER_MIN
||
725 value
> IWL_BF_ESCAPE_TIMER_MAX
)
727 param
= MVM_DEBUGFS_BF_ESCAPE_TIMER
;
728 } else if (!strncmp("ba_escape_timer=", buf
, 16)) {
729 if (sscanf(buf
+16, "%d", &value
) != 1)
731 if (value
< IWL_BA_ESCAPE_TIMER_MIN
||
732 value
> IWL_BA_ESCAPE_TIMER_MAX
)
734 param
= MVM_DEBUGFS_BA_ESCAPE_TIMER
;
735 } else if (!strncmp("ba_enable_beacon_abort=", buf
, 23)) {
736 if (sscanf(buf
+23, "%d", &value
) != 1)
738 if (value
< 0 || value
> 1)
740 param
= MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT
;
745 mutex_lock(&mvm
->mutex
);
746 iwl_dbgfs_update_bf(vif
, param
, value
);
747 if (param
== MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER
&& !value
) {
748 ret
= iwl_mvm_disable_beacon_filter(mvm
, vif
);
750 if (mvmvif
->bf_enabled
)
751 ret
= iwl_mvm_enable_beacon_filter(mvm
, vif
);
753 ret
= iwl_mvm_disable_beacon_filter(mvm
, vif
);
755 mutex_unlock(&mvm
->mutex
);
760 static ssize_t
iwl_dbgfs_bf_params_read(struct file
*file
,
761 char __user
*user_buf
,
762 size_t count
, loff_t
*ppos
)
764 struct ieee80211_vif
*vif
= file
->private_data
;
765 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
768 const size_t bufsz
= sizeof(buf
);
769 struct iwl_beacon_filter_cmd cmd
= {
770 .bf_energy_delta
= IWL_BF_ENERGY_DELTA_DEFAULT
,
771 .bf_roaming_energy_delta
= IWL_BF_ROAMING_ENERGY_DELTA_DEFAULT
,
772 .bf_roaming_state
= IWL_BF_ROAMING_STATE_DEFAULT
,
773 .bf_temperature_delta
= IWL_BF_TEMPERATURE_DELTA_DEFAULT
,
774 .bf_enable_beacon_filter
= IWL_BF_ENABLE_BEACON_FILTER_DEFAULT
,
775 .bf_debug_flag
= IWL_BF_DEBUG_FLAG_DEFAULT
,
776 .bf_escape_timer
= cpu_to_le32(IWL_BF_ESCAPE_TIMER_DEFAULT
),
777 .ba_escape_timer
= cpu_to_le32(IWL_BA_ESCAPE_TIMER_DEFAULT
),
778 .ba_enable_beacon_abort
= IWL_BA_ENABLE_BEACON_ABORT_DEFAULT
,
781 iwl_mvm_beacon_filter_debugfs_parameters(vif
, &cmd
);
782 if (mvmvif
->bf_enabled
)
783 cmd
.bf_enable_beacon_filter
= 1;
785 cmd
.bf_enable_beacon_filter
= 0;
787 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "bf_energy_delta = %d\n",
788 cmd
.bf_energy_delta
);
789 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "bf_roaming_energy_delta = %d\n",
790 cmd
.bf_roaming_energy_delta
);
791 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "bf_roaming_state = %d\n",
792 cmd
.bf_roaming_state
);
793 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "bf_temperature_delta = %d\n",
794 cmd
.bf_temperature_delta
);
795 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "bf_enable_beacon_filter = %d\n",
796 cmd
.bf_enable_beacon_filter
);
797 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "bf_debug_flag = %d\n",
799 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "bf_escape_timer = %d\n",
800 cmd
.bf_escape_timer
);
801 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "ba_escape_timer = %d\n",
802 cmd
.ba_escape_timer
);
803 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "ba_enable_beacon_abort = %d\n",
804 cmd
.ba_enable_beacon_abort
);
806 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
809 #ifdef CONFIG_PM_SLEEP
810 static ssize_t
iwl_dbgfs_d3_sram_write(struct file
*file
,
811 const char __user
*user_buf
,
812 size_t count
, loff_t
*ppos
)
814 struct iwl_mvm
*mvm
= file
->private_data
;
818 if (copy_from_user(buf
, user_buf
, sizeof(buf
)))
821 if (sscanf(buf
, "%d", &store
) != 1)
824 mvm
->store_d3_resume_sram
= store
;
829 static ssize_t
iwl_dbgfs_d3_sram_read(struct file
*file
, char __user
*user_buf
,
830 size_t count
, loff_t
*ppos
)
832 struct iwl_mvm
*mvm
= file
->private_data
;
833 const struct fw_img
*img
;
834 int ofs
, len
, pos
= 0;
837 u8
*ptr
= mvm
->d3_resume_sram
;
839 img
= &mvm
->fw
->img
[IWL_UCODE_WOWLAN
];
840 len
= img
->sec
[IWL_UCODE_SECTION_DATA
].len
;
842 bufsz
= len
* 4 + 256;
843 buf
= kzalloc(bufsz
, GFP_KERNEL
);
847 pos
+= scnprintf(buf
, bufsz
, "D3 SRAM capture: %sabled\n",
848 mvm
->store_d3_resume_sram
? "en" : "dis");
851 for (ofs
= 0; ofs
< len
; ofs
+= 16) {
852 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
854 hex_dump_to_buffer(ptr
+ ofs
, 16, 16, 1, buf
+ pos
,
856 pos
+= strlen(buf
+ pos
);
861 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
862 "(no data captured)\n");
865 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
873 #define MVM_DEBUGFS_READ_FILE_OPS(name) \
874 static const struct file_operations iwl_dbgfs_##name##_ops = { \
875 .read = iwl_dbgfs_##name##_read, \
876 .open = simple_open, \
877 .llseek = generic_file_llseek, \
880 #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name) \
881 static const struct file_operations iwl_dbgfs_##name##_ops = { \
882 .write = iwl_dbgfs_##name##_write, \
883 .read = iwl_dbgfs_##name##_read, \
884 .open = simple_open, \
885 .llseek = generic_file_llseek, \
888 #define MVM_DEBUGFS_WRITE_FILE_OPS(name) \
889 static const struct file_operations iwl_dbgfs_##name##_ops = { \
890 .write = iwl_dbgfs_##name##_write, \
891 .open = simple_open, \
892 .llseek = generic_file_llseek, \
895 #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) do { \
896 if (!debugfs_create_file(#name, mode, parent, mvm, \
897 &iwl_dbgfs_##name##_ops)) \
901 #define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \
902 if (!debugfs_create_file(#name, mode, parent, vif, \
903 &iwl_dbgfs_##name##_ops)) \
907 /* Device wide debugfs entries */
908 MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush
);
909 MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain
);
910 MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram
);
911 MVM_DEBUGFS_READ_FILE_OPS(stations
);
912 MVM_DEBUGFS_READ_FILE_OPS(bt_notif
);
913 MVM_DEBUGFS_WRITE_FILE_OPS(power_down_allow
);
914 MVM_DEBUGFS_WRITE_FILE_OPS(power_down_d3_allow
);
915 MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart
);
916 #ifdef CONFIG_PM_SLEEP
917 MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram
);
920 /* Interface specific debugfs entries */
921 MVM_DEBUGFS_READ_FILE_OPS(mac_params
);
922 MVM_DEBUGFS_READ_WRITE_FILE_OPS(pm_params
);
923 MVM_DEBUGFS_READ_WRITE_FILE_OPS(bf_params
);
925 int iwl_mvm_dbgfs_register(struct iwl_mvm
*mvm
, struct dentry
*dbgfs_dir
)
929 mvm
->debugfs_dir
= dbgfs_dir
;
931 MVM_DEBUGFS_ADD_FILE(tx_flush
, mvm
->debugfs_dir
, S_IWUSR
);
932 MVM_DEBUGFS_ADD_FILE(sta_drain
, mvm
->debugfs_dir
, S_IWUSR
);
933 MVM_DEBUGFS_ADD_FILE(sram
, mvm
->debugfs_dir
, S_IWUSR
| S_IRUSR
);
934 MVM_DEBUGFS_ADD_FILE(stations
, dbgfs_dir
, S_IRUSR
);
935 MVM_DEBUGFS_ADD_FILE(bt_notif
, dbgfs_dir
, S_IRUSR
);
936 MVM_DEBUGFS_ADD_FILE(power_down_allow
, mvm
->debugfs_dir
, S_IWUSR
);
937 MVM_DEBUGFS_ADD_FILE(power_down_d3_allow
, mvm
->debugfs_dir
, S_IWUSR
);
938 MVM_DEBUGFS_ADD_FILE(fw_restart
, mvm
->debugfs_dir
, S_IWUSR
);
939 #ifdef CONFIG_PM_SLEEP
940 MVM_DEBUGFS_ADD_FILE(d3_sram
, mvm
->debugfs_dir
, S_IRUSR
| S_IWUSR
);
941 MVM_DEBUGFS_ADD_FILE(d3_test
, mvm
->debugfs_dir
, S_IRUSR
);
942 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR
| S_IWUSR
,
943 mvm
->debugfs_dir
, &mvm
->d3_wake_sysassert
))
948 * Create a symlink with mac80211. It will be removed when mac80211
949 * exists (before the opmode exists which removes the target.)
951 snprintf(buf
, 100, "../../%s/%s",
952 dbgfs_dir
->d_parent
->d_parent
->d_name
.name
,
953 dbgfs_dir
->d_parent
->d_name
.name
);
954 if (!debugfs_create_symlink("iwlwifi", mvm
->hw
->wiphy
->debugfsdir
, buf
))
959 IWL_ERR(mvm
, "Can't create the mvm debugfs directory\n");
963 void iwl_mvm_vif_dbgfs_register(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
965 struct dentry
*dbgfs_dir
= vif
->debugfs_dir
;
966 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
972 mvmvif
->dbgfs_dir
= debugfs_create_dir("iwlmvm", dbgfs_dir
);
973 mvmvif
->dbgfs_data
= mvm
;
975 if (!mvmvif
->dbgfs_dir
) {
976 IWL_ERR(mvm
, "Failed to create debugfs directory under %s\n",
977 dbgfs_dir
->d_name
.name
);
981 if (iwlmvm_mod_params
.power_scheme
!= IWL_POWER_SCHEME_CAM
&&
982 vif
->type
== NL80211_IFTYPE_STATION
&& !vif
->p2p
)
983 MVM_DEBUGFS_ADD_FILE_VIF(pm_params
, mvmvif
->dbgfs_dir
, S_IWUSR
|
986 MVM_DEBUGFS_ADD_FILE_VIF(mac_params
, mvmvif
->dbgfs_dir
,
989 if (vif
->type
== NL80211_IFTYPE_STATION
&& !vif
->p2p
&&
990 mvmvif
== mvm
->bf_allowed_vif
)
991 MVM_DEBUGFS_ADD_FILE_VIF(bf_params
, mvmvif
->dbgfs_dir
,
995 * Create symlink for convenience pointing to interface specific
996 * debugfs entries for the driver. For example, under
997 * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/
999 * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/
1001 snprintf(buf
, 100, "../../../%s/%s/%s/%s",
1002 dbgfs_dir
->d_parent
->d_parent
->d_name
.name
,
1003 dbgfs_dir
->d_parent
->d_name
.name
,
1004 dbgfs_dir
->d_name
.name
,
1005 mvmvif
->dbgfs_dir
->d_name
.name
);
1007 mvmvif
->dbgfs_slink
= debugfs_create_symlink(dbgfs_dir
->d_name
.name
,
1008 mvm
->debugfs_dir
, buf
);
1009 if (!mvmvif
->dbgfs_slink
)
1010 IWL_ERR(mvm
, "Can't create debugfs symbolic link under %s\n",
1011 dbgfs_dir
->d_name
.name
);
1014 IWL_ERR(mvm
, "Can't create debugfs entity\n");
1017 void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
1019 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1021 debugfs_remove(mvmvif
->dbgfs_slink
);
1022 mvmvif
->dbgfs_slink
= NULL
;
1024 debugfs_remove_recursive(mvmvif
->dbgfs_dir
);
1025 mvmvif
->dbgfs_dir
= NULL
;