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 *****************************************************************************/
68 static ssize_t iwl_dbgfs_tx_flush_write(struct file *file,
69 const char __user *user_buf,
70 size_t count, loff_t *ppos)
72 struct iwl_mvm *mvm = file->private_data;
74 size_t buf_size = min(count, sizeof(buf) - 1);
78 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
81 if (copy_from_user(buf, user_buf, buf_size))
84 if (sscanf(buf, "%x", &scd_q_msk) != 1)
87 IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk);
89 mutex_lock(&mvm->mutex);
90 ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, true) ? : count;
91 mutex_unlock(&mvm->mutex);
96 static ssize_t iwl_dbgfs_sta_drain_write(struct file *file,
97 const char __user *user_buf,
98 size_t count, loff_t *ppos)
100 struct iwl_mvm *mvm = file->private_data;
101 struct ieee80211_sta *sta;
103 size_t buf_size = min(count, sizeof(buf) - 1);
104 int sta_id, drain, ret;
106 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
109 if (copy_from_user(buf, user_buf, buf_size))
112 if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
114 if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
116 if (drain < 0 || drain > 1)
119 mutex_lock(&mvm->mutex);
121 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
122 lockdep_is_held(&mvm->mutex));
123 if (IS_ERR_OR_NULL(sta))
126 ret = iwl_mvm_drain_sta(mvm, (void *)sta->drv_priv, drain) ? :
129 mutex_unlock(&mvm->mutex);
134 static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
135 size_t count, loff_t *ppos)
137 struct iwl_mvm *mvm = file->private_data;
138 const struct fw_img *img;
139 int ofs, len, pos = 0;
144 if (!mvm->ucode_loaded)
147 /* default is to dump the entire data segment */
148 if (!mvm->dbgfs_sram_offset && !mvm->dbgfs_sram_len) {
149 img = &mvm->fw->img[mvm->cur_ucode];
150 ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
151 len = img->sec[IWL_UCODE_SECTION_DATA].len;
153 ofs = mvm->dbgfs_sram_offset;
154 len = mvm->dbgfs_sram_len;
157 bufsz = len * 4 + 256;
158 buf = kzalloc(bufsz, GFP_KERNEL);
162 ptr = kzalloc(len, GFP_KERNEL);
168 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n", len);
169 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n", ofs);
171 iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
172 for (ofs = 0; ofs < len; ofs += 16) {
173 pos += scnprintf(buf + pos, bufsz - pos, "0x%.4x ", ofs);
174 hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
176 pos += strlen(buf + pos);
181 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
189 static ssize_t iwl_dbgfs_sram_write(struct file *file,
190 const char __user *user_buf, size_t count,
193 struct iwl_mvm *mvm = file->private_data;
195 size_t buf_size = min(count, sizeof(buf) - 1);
198 if (copy_from_user(buf, user_buf, buf_size))
201 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
202 if ((offset & 0x3) || (len & 0x3))
204 mvm->dbgfs_sram_offset = offset;
205 mvm->dbgfs_sram_len = len;
207 mvm->dbgfs_sram_offset = 0;
208 mvm->dbgfs_sram_len = 0;
214 static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
215 size_t count, loff_t *ppos)
217 struct iwl_mvm *mvm = file->private_data;
218 struct ieee80211_sta *sta;
220 int i, pos = 0, bufsz = sizeof(buf);
222 mutex_lock(&mvm->mutex);
224 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
225 pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
226 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
227 lockdep_is_held(&mvm->mutex));
229 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
230 else if (IS_ERR(sta))
231 pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
234 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
238 mutex_unlock(&mvm->mutex);
240 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
243 static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
244 char __user *user_buf,
245 size_t count, loff_t *ppos)
247 struct iwl_mvm *mvm = file->private_data;
249 int bufsz = sizeof(buf);
252 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
253 mvm->disable_power_off);
254 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
255 mvm->disable_power_off_d3);
257 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
260 static ssize_t iwl_dbgfs_disable_power_off_write(struct file *file,
261 const char __user *user_buf,
262 size_t count, loff_t *ppos)
264 struct iwl_mvm *mvm = file->private_data;
266 size_t buf_size = min(count, sizeof(buf) - 1);
270 if (!mvm->ucode_loaded)
273 if (copy_from_user(buf, user_buf, buf_size))
276 if (!strncmp("disable_power_off_d0=", buf, 21)) {
277 if (sscanf(buf + 21, "%d", &val) != 1)
279 mvm->disable_power_off = val;
280 } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
281 if (sscanf(buf + 21, "%d", &val) != 1)
283 mvm->disable_power_off_d3 = val;
288 mutex_lock(&mvm->mutex);
289 ret = iwl_mvm_power_update_device_mode(mvm);
290 mutex_unlock(&mvm->mutex);
295 static void iwl_dbgfs_update_pm(struct iwl_mvm *mvm,
296 struct ieee80211_vif *vif,
297 enum iwl_dbgfs_pm_mask param, int val)
299 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
300 struct iwl_dbgfs_pm *dbgfs_pm = &mvmvif->dbgfs_pm;
302 dbgfs_pm->mask |= param;
305 case MVM_DEBUGFS_PM_KEEP_ALIVE: {
306 struct ieee80211_hw *hw = mvm->hw;
307 int dtimper = hw->conf.ps_dtim_period ?: 1;
308 int dtimper_msec = dtimper * vif->bss_conf.beacon_int;
310 IWL_DEBUG_POWER(mvm, "debugfs: set keep_alive= %d sec\n", val);
311 if (val * MSEC_PER_SEC < 3 * dtimper_msec)
313 "debugfs: keep alive period (%ld msec) is less than minimum required (%d msec)\n",
314 val * MSEC_PER_SEC, 3 * dtimper_msec);
315 dbgfs_pm->keep_alive_seconds = val;
318 case MVM_DEBUGFS_PM_SKIP_OVER_DTIM:
319 IWL_DEBUG_POWER(mvm, "skip_over_dtim %s\n",
320 val ? "enabled" : "disabled");
321 dbgfs_pm->skip_over_dtim = val;
323 case MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS:
324 IWL_DEBUG_POWER(mvm, "skip_dtim_periods=%d\n", val);
325 dbgfs_pm->skip_dtim_periods = val;
327 case MVM_DEBUGFS_PM_RX_DATA_TIMEOUT:
328 IWL_DEBUG_POWER(mvm, "rx_data_timeout=%d\n", val);
329 dbgfs_pm->rx_data_timeout = val;
331 case MVM_DEBUGFS_PM_TX_DATA_TIMEOUT:
332 IWL_DEBUG_POWER(mvm, "tx_data_timeout=%d\n", val);
333 dbgfs_pm->tx_data_timeout = val;
335 case MVM_DEBUGFS_PM_DISABLE_POWER_OFF:
336 IWL_DEBUG_POWER(mvm, "disable_power_off=%d\n", val);
337 dbgfs_pm->disable_power_off = val;
339 case MVM_DEBUGFS_PM_LPRX_ENA:
340 IWL_DEBUG_POWER(mvm, "lprx %s\n", val ? "enabled" : "disabled");
341 dbgfs_pm->lprx_ena = val;
343 case MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD:
344 IWL_DEBUG_POWER(mvm, "lprx_rssi_threshold=%d\n", val);
345 dbgfs_pm->lprx_rssi_threshold = val;
347 case MVM_DEBUGFS_PM_SNOOZE_ENABLE:
348 IWL_DEBUG_POWER(mvm, "snooze_enable=%d\n", val);
349 dbgfs_pm->snooze_ena = val;
354 static ssize_t iwl_dbgfs_pm_params_write(struct file *file,
355 const char __user *user_buf,
356 size_t count, loff_t *ppos)
358 struct ieee80211_vif *vif = file->private_data;
359 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
360 struct iwl_mvm *mvm = mvmvif->dbgfs_data;
361 enum iwl_dbgfs_pm_mask param;
363 size_t buf_size = min(count, sizeof(buf) - 1);
367 if (copy_from_user(buf, user_buf, buf_size))
370 if (!strncmp("keep_alive=", buf, 11)) {
371 if (sscanf(buf + 11, "%d", &val) != 1)
373 param = MVM_DEBUGFS_PM_KEEP_ALIVE;
374 } else if (!strncmp("skip_over_dtim=", buf, 15)) {
375 if (sscanf(buf + 15, "%d", &val) != 1)
377 param = MVM_DEBUGFS_PM_SKIP_OVER_DTIM;
378 } else if (!strncmp("skip_dtim_periods=", buf, 18)) {
379 if (sscanf(buf + 18, "%d", &val) != 1)
381 param = MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS;
382 } else if (!strncmp("rx_data_timeout=", buf, 16)) {
383 if (sscanf(buf + 16, "%d", &val) != 1)
385 param = MVM_DEBUGFS_PM_RX_DATA_TIMEOUT;
386 } else if (!strncmp("tx_data_timeout=", buf, 16)) {
387 if (sscanf(buf + 16, "%d", &val) != 1)
389 param = MVM_DEBUGFS_PM_TX_DATA_TIMEOUT;
390 } else if (!strncmp("disable_power_off=", buf, 18) &&
391 !(mvm->fw->ucode_capa.flags &
392 IWL_UCODE_TLV_FLAGS_DEVICE_PS_CMD)) {
393 if (sscanf(buf + 18, "%d", &val) != 1)
395 param = MVM_DEBUGFS_PM_DISABLE_POWER_OFF;
396 } else if (!strncmp("lprx=", buf, 5)) {
397 if (sscanf(buf + 5, "%d", &val) != 1)
399 param = MVM_DEBUGFS_PM_LPRX_ENA;
400 } else if (!strncmp("lprx_rssi_threshold=", buf, 20)) {
401 if (sscanf(buf + 20, "%d", &val) != 1)
403 if (val > POWER_LPRX_RSSI_THRESHOLD_MAX || val <
404 POWER_LPRX_RSSI_THRESHOLD_MIN)
406 param = MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD;
407 } else if (!strncmp("snooze_enable=", buf, 14)) {
408 if (sscanf(buf + 14, "%d", &val) != 1)
410 param = MVM_DEBUGFS_PM_SNOOZE_ENABLE;
415 mutex_lock(&mvm->mutex);
416 iwl_dbgfs_update_pm(mvm, vif, param, val);
417 ret = iwl_mvm_power_update_mode(mvm, vif);
418 mutex_unlock(&mvm->mutex);
423 static ssize_t iwl_dbgfs_pm_params_read(struct file *file,
424 char __user *user_buf,
425 size_t count, loff_t *ppos)
427 struct ieee80211_vif *vif = file->private_data;
428 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
429 struct iwl_mvm *mvm = mvmvif->dbgfs_data;
431 int bufsz = sizeof(buf);
434 pos = iwl_mvm_power_dbgfs_read(mvm, vif, buf, bufsz);
436 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
439 static ssize_t iwl_dbgfs_mac_params_read(struct file *file,
440 char __user *user_buf,
441 size_t count, loff_t *ppos)
443 struct ieee80211_vif *vif = file->private_data;
444 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
445 struct iwl_mvm *mvm = mvmvif->dbgfs_data;
447 struct ieee80211_chanctx_conf *chanctx_conf;
449 int bufsz = sizeof(buf);
453 mutex_lock(&mvm->mutex);
455 ap_sta_id = mvmvif->ap_sta_id;
457 pos += scnprintf(buf+pos, bufsz-pos, "mac id/color: %d / %d\n",
458 mvmvif->id, mvmvif->color);
459 pos += scnprintf(buf+pos, bufsz-pos, "bssid: %pM\n",
460 vif->bss_conf.bssid);
461 pos += scnprintf(buf+pos, bufsz-pos, "QoS:\n");
462 for (i = 0; i < ARRAY_SIZE(mvmvif->queue_params); i++)
463 pos += scnprintf(buf+pos, bufsz-pos,
464 "\t%d: txop:%d - cw_min:%d - cw_max = %d - aifs = %d upasd = %d\n",
465 i, mvmvif->queue_params[i].txop,
466 mvmvif->queue_params[i].cw_min,
467 mvmvif->queue_params[i].cw_max,
468 mvmvif->queue_params[i].aifs,
469 mvmvif->queue_params[i].uapsd);
471 if (vif->type == NL80211_IFTYPE_STATION &&
472 ap_sta_id != IWL_MVM_STATION_COUNT) {
473 struct ieee80211_sta *sta;
474 struct iwl_mvm_sta *mvm_sta;
476 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[ap_sta_id],
477 lockdep_is_held(&mvm->mutex));
478 mvm_sta = (void *)sta->drv_priv;
479 pos += scnprintf(buf+pos, bufsz-pos,
480 "ap_sta_id %d - reduced Tx power %d\n",
481 ap_sta_id, mvm_sta->bt_reduced_txpower);
485 chanctx_conf = rcu_dereference(vif->chanctx_conf);
487 pos += scnprintf(buf+pos, bufsz-pos,
488 "idle rx chains %d, active rx chains: %d\n",
489 chanctx_conf->rx_chains_static,
490 chanctx_conf->rx_chains_dynamic);
493 mutex_unlock(&mvm->mutex);
495 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
498 #define BT_MBOX_MSG(_notif, _num, _field) \
499 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
500 >> BT_MBOX##_num##_##_field##_POS)
503 #define BT_MBOX_PRINT(_num, _field, _end) \
504 pos += scnprintf(buf + pos, bufsz - pos, \
507 BT_MBOX_MSG(notif, _num, _field), \
510 static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
511 size_t count, loff_t *ppos)
513 struct iwl_mvm *mvm = file->private_data;
514 struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
516 int ret, pos = 0, bufsz = sizeof(char) * 1024;
518 buf = kmalloc(bufsz, GFP_KERNEL);
522 mutex_lock(&mvm->mutex);
524 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
526 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
527 BT_MBOX_PRINT(0, LE_PROF1, false);
528 BT_MBOX_PRINT(0, LE_PROF2, false);
529 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
530 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
531 BT_MBOX_PRINT(0, INBAND_S, false);
532 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
533 BT_MBOX_PRINT(0, LE_SCAN, false);
534 BT_MBOX_PRINT(0, LE_ADV, false);
535 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
536 BT_MBOX_PRINT(0, OPEN_CON_1, true);
538 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
540 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
541 BT_MBOX_PRINT(1, IP_SR, false);
542 BT_MBOX_PRINT(1, LE_MSTR, false);
543 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
544 BT_MBOX_PRINT(1, MSG_TYPE, false);
545 BT_MBOX_PRINT(1, SSN, true);
547 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
549 BT_MBOX_PRINT(2, SNIFF_ACT, false);
550 BT_MBOX_PRINT(2, PAG, false);
551 BT_MBOX_PRINT(2, INQUIRY, false);
552 BT_MBOX_PRINT(2, CONN, false);
553 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
554 BT_MBOX_PRINT(2, DISC, false);
555 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
556 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
557 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
558 BT_MBOX_PRINT(2, SCO_DURATION, true);
560 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
562 BT_MBOX_PRINT(3, SCO_STATE, false);
563 BT_MBOX_PRINT(3, SNIFF_STATE, false);
564 BT_MBOX_PRINT(3, A2DP_STATE, false);
565 BT_MBOX_PRINT(3, ACL_STATE, false);
566 BT_MBOX_PRINT(3, MSTR_STATE, false);
567 BT_MBOX_PRINT(3, OBX_STATE, false);
568 BT_MBOX_PRINT(3, OPEN_CON_2, false);
569 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
570 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
571 BT_MBOX_PRINT(3, INBAND_P, false);
572 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
573 BT_MBOX_PRINT(3, SSN_2, false);
574 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
576 pos += scnprintf(buf+pos, bufsz-pos, "bt_status = %d\n",
578 pos += scnprintf(buf+pos, bufsz-pos, "bt_open_conn = %d\n",
579 notif->bt_open_conn);
580 pos += scnprintf(buf+pos, bufsz-pos, "bt_traffic_load = %d\n",
581 notif->bt_traffic_load);
582 pos += scnprintf(buf+pos, bufsz-pos, "bt_agg_traffic_load = %d\n",
583 notif->bt_agg_traffic_load);
584 pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
585 notif->bt_ci_compliance);
586 pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
587 le32_to_cpu(notif->primary_ch_lut));
588 pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
589 le32_to_cpu(notif->secondary_ch_lut));
590 pos += scnprintf(buf+pos, bufsz-pos, "bt_activity_grading = %d\n",
591 le32_to_cpu(notif->bt_activity_grading));
593 mutex_unlock(&mvm->mutex);
595 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
602 static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
603 size_t count, loff_t *ppos)
605 struct iwl_mvm *mvm = file->private_data;
606 struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
608 int bufsz = sizeof(buf);
611 mutex_lock(&mvm->mutex);
613 pos += scnprintf(buf+pos, bufsz-pos, "Channel inhibition CMD\n");
614 pos += scnprintf(buf+pos, bufsz-pos,
615 "\tPrimary Channel Bitmap 0x%016llx Fat: %d\n",
616 le64_to_cpu(cmd->bt_primary_ci),
617 !!cmd->co_run_bw_primary);
618 pos += scnprintf(buf+pos, bufsz-pos,
619 "\tSecondary Channel Bitmap 0x%016llx Fat: %d\n",
620 le64_to_cpu(cmd->bt_secondary_ci),
621 !!cmd->co_run_bw_secondary);
623 pos += scnprintf(buf+pos, bufsz-pos, "BT Configuration CMD\n");
624 pos += scnprintf(buf+pos, bufsz-pos, "\tACK Kill Mask 0x%08x\n",
625 iwl_bt_ack_kill_msk[mvm->bt_kill_msk]);
626 pos += scnprintf(buf+pos, bufsz-pos, "\tCTS Kill Mask 0x%08x\n",
627 iwl_bt_cts_kill_msk[mvm->bt_kill_msk]);
629 mutex_unlock(&mvm->mutex);
631 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
634 #define PRINT_STATS_LE32(_str, _val) \
635 pos += scnprintf(buf + pos, bufsz - pos, \
639 static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
640 char __user *user_buf, size_t count,
643 struct iwl_mvm *mvm = file->private_data;
644 static const char *fmt_table = "\t%-30s %10u\n";
645 static const char *fmt_header = "%-32s\n";
649 /* 43 is the size of each data line, 33 is the size of each header */
651 ((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) +
654 struct mvm_statistics_rx_phy *ofdm;
655 struct mvm_statistics_rx_phy *cck;
656 struct mvm_statistics_rx_non_phy *general;
657 struct mvm_statistics_rx_ht_phy *ht;
659 buf = kzalloc(bufsz, GFP_KERNEL);
663 mutex_lock(&mvm->mutex);
665 ofdm = &mvm->rx_stats.ofdm;
666 cck = &mvm->rx_stats.cck;
667 general = &mvm->rx_stats.general;
668 ht = &mvm->rx_stats.ofdm_ht;
670 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
671 "Statistics_Rx - OFDM");
672 PRINT_STATS_LE32("ina_cnt", ofdm->ina_cnt);
673 PRINT_STATS_LE32("fina_cnt", ofdm->fina_cnt);
674 PRINT_STATS_LE32("plcp_err", ofdm->plcp_err);
675 PRINT_STATS_LE32("crc32_err", ofdm->crc32_err);
676 PRINT_STATS_LE32("overrun_err", ofdm->overrun_err);
677 PRINT_STATS_LE32("early_overrun_err", ofdm->early_overrun_err);
678 PRINT_STATS_LE32("crc32_good", ofdm->crc32_good);
679 PRINT_STATS_LE32("false_alarm_cnt", ofdm->false_alarm_cnt);
680 PRINT_STATS_LE32("fina_sync_err_cnt", ofdm->fina_sync_err_cnt);
681 PRINT_STATS_LE32("sfd_timeout", ofdm->sfd_timeout);
682 PRINT_STATS_LE32("fina_timeout", ofdm->fina_timeout);
683 PRINT_STATS_LE32("unresponded_rts", ofdm->unresponded_rts);
684 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
685 ofdm->rxe_frame_limit_overrun);
686 PRINT_STATS_LE32("sent_ack_cnt", ofdm->sent_ack_cnt);
687 PRINT_STATS_LE32("sent_cts_cnt", ofdm->sent_cts_cnt);
688 PRINT_STATS_LE32("sent_ba_rsp_cnt", ofdm->sent_ba_rsp_cnt);
689 PRINT_STATS_LE32("dsp_self_kill", ofdm->dsp_self_kill);
690 PRINT_STATS_LE32("mh_format_err", ofdm->mh_format_err);
691 PRINT_STATS_LE32("re_acq_main_rssi_sum", ofdm->re_acq_main_rssi_sum);
692 PRINT_STATS_LE32("reserved", ofdm->reserved);
694 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
695 "Statistics_Rx - CCK");
696 PRINT_STATS_LE32("ina_cnt", cck->ina_cnt);
697 PRINT_STATS_LE32("fina_cnt", cck->fina_cnt);
698 PRINT_STATS_LE32("plcp_err", cck->plcp_err);
699 PRINT_STATS_LE32("crc32_err", cck->crc32_err);
700 PRINT_STATS_LE32("overrun_err", cck->overrun_err);
701 PRINT_STATS_LE32("early_overrun_err", cck->early_overrun_err);
702 PRINT_STATS_LE32("crc32_good", cck->crc32_good);
703 PRINT_STATS_LE32("false_alarm_cnt", cck->false_alarm_cnt);
704 PRINT_STATS_LE32("fina_sync_err_cnt", cck->fina_sync_err_cnt);
705 PRINT_STATS_LE32("sfd_timeout", cck->sfd_timeout);
706 PRINT_STATS_LE32("fina_timeout", cck->fina_timeout);
707 PRINT_STATS_LE32("unresponded_rts", cck->unresponded_rts);
708 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
709 cck->rxe_frame_limit_overrun);
710 PRINT_STATS_LE32("sent_ack_cnt", cck->sent_ack_cnt);
711 PRINT_STATS_LE32("sent_cts_cnt", cck->sent_cts_cnt);
712 PRINT_STATS_LE32("sent_ba_rsp_cnt", cck->sent_ba_rsp_cnt);
713 PRINT_STATS_LE32("dsp_self_kill", cck->dsp_self_kill);
714 PRINT_STATS_LE32("mh_format_err", cck->mh_format_err);
715 PRINT_STATS_LE32("re_acq_main_rssi_sum", cck->re_acq_main_rssi_sum);
716 PRINT_STATS_LE32("reserved", cck->reserved);
718 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
719 "Statistics_Rx - GENERAL");
720 PRINT_STATS_LE32("bogus_cts", general->bogus_cts);
721 PRINT_STATS_LE32("bogus_ack", general->bogus_ack);
722 PRINT_STATS_LE32("non_bssid_frames", general->non_bssid_frames);
723 PRINT_STATS_LE32("filtered_frames", general->filtered_frames);
724 PRINT_STATS_LE32("non_channel_beacons", general->non_channel_beacons);
725 PRINT_STATS_LE32("channel_beacons", general->channel_beacons);
726 PRINT_STATS_LE32("num_missed_bcon", general->num_missed_bcon);
727 PRINT_STATS_LE32("adc_rx_saturation_time",
728 general->adc_rx_saturation_time);
729 PRINT_STATS_LE32("ina_detection_search_time",
730 general->ina_detection_search_time);
731 PRINT_STATS_LE32("beacon_silence_rssi_a",
732 general->beacon_silence_rssi_a);
733 PRINT_STATS_LE32("beacon_silence_rssi_b",
734 general->beacon_silence_rssi_b);
735 PRINT_STATS_LE32("beacon_silence_rssi_c",
736 general->beacon_silence_rssi_c);
737 PRINT_STATS_LE32("interference_data_flag",
738 general->interference_data_flag);
739 PRINT_STATS_LE32("channel_load", general->channel_load);
740 PRINT_STATS_LE32("dsp_false_alarms", general->dsp_false_alarms);
741 PRINT_STATS_LE32("beacon_rssi_a", general->beacon_rssi_a);
742 PRINT_STATS_LE32("beacon_rssi_b", general->beacon_rssi_b);
743 PRINT_STATS_LE32("beacon_rssi_c", general->beacon_rssi_c);
744 PRINT_STATS_LE32("beacon_energy_a", general->beacon_energy_a);
745 PRINT_STATS_LE32("beacon_energy_b", general->beacon_energy_b);
746 PRINT_STATS_LE32("beacon_energy_c", general->beacon_energy_c);
747 PRINT_STATS_LE32("num_bt_kills", general->num_bt_kills);
748 PRINT_STATS_LE32("mac_id", general->mac_id);
749 PRINT_STATS_LE32("directed_data_mpdu", general->directed_data_mpdu);
751 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
752 "Statistics_Rx - HT");
753 PRINT_STATS_LE32("plcp_err", ht->plcp_err);
754 PRINT_STATS_LE32("overrun_err", ht->overrun_err);
755 PRINT_STATS_LE32("early_overrun_err", ht->early_overrun_err);
756 PRINT_STATS_LE32("crc32_good", ht->crc32_good);
757 PRINT_STATS_LE32("crc32_err", ht->crc32_err);
758 PRINT_STATS_LE32("mh_format_err", ht->mh_format_err);
759 PRINT_STATS_LE32("agg_crc32_good", ht->agg_crc32_good);
760 PRINT_STATS_LE32("agg_mpdu_cnt", ht->agg_mpdu_cnt);
761 PRINT_STATS_LE32("agg_cnt", ht->agg_cnt);
762 PRINT_STATS_LE32("unsupport_mcs", ht->unsupport_mcs);
764 mutex_unlock(&mvm->mutex);
766 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
771 #undef PRINT_STAT_LE32
773 static ssize_t iwl_dbgfs_fw_restart_write(struct file *file,
774 const char __user *user_buf,
775 size_t count, loff_t *ppos)
777 struct iwl_mvm *mvm = file->private_data;
780 mutex_lock(&mvm->mutex);
782 /* allow one more restart that we're provoking here */
783 if (mvm->restart_fw >= 0)
786 /* take the return value to make compiler happy - it will fail anyway */
787 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, CMD_SYNC, 0, NULL);
789 mutex_unlock(&mvm->mutex);
794 static ssize_t iwl_dbgfs_fw_nmi_write(struct file *file,
795 const char __user *user_buf,
796 size_t count, loff_t *ppos)
798 struct iwl_mvm *mvm = file->private_data;
800 iwl_write_prph(mvm->trans, DEVICE_SET_NMI_REG, 1);
806 iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
807 char __user *user_buf,
808 size_t count, loff_t *ppos)
810 struct iwl_mvm *mvm = file->private_data;
813 const size_t bufsz = sizeof(buf);
815 /* print which antennas were set for the scan command by the user */
816 pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
817 if (mvm->scan_rx_ant & ANT_A)
818 pos += scnprintf(buf + pos, bufsz - pos, "A");
819 if (mvm->scan_rx_ant & ANT_B)
820 pos += scnprintf(buf + pos, bufsz - pos, "B");
821 if (mvm->scan_rx_ant & ANT_C)
822 pos += scnprintf(buf + pos, bufsz - pos, "C");
823 pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
825 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
829 iwl_dbgfs_scan_ant_rxchain_write(struct file *file,
830 const char __user *user_buf,
831 size_t count, loff_t *ppos)
833 struct iwl_mvm *mvm = file->private_data;
835 size_t buf_size = min(count, sizeof(buf) - 1);
838 if (copy_from_user(buf, user_buf, buf_size))
840 if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
842 if (scan_rx_ant > ANT_ABC)
844 if (scan_rx_ant & ~iwl_fw_valid_rx_ant(mvm->fw))
847 mvm->scan_rx_ant = scan_rx_ant;
853 static void iwl_dbgfs_update_bf(struct ieee80211_vif *vif,
854 enum iwl_dbgfs_bf_mask param, int value)
856 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
857 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
859 dbgfs_bf->mask |= param;
862 case MVM_DEBUGFS_BF_ENERGY_DELTA:
863 dbgfs_bf->bf_energy_delta = value;
865 case MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA:
866 dbgfs_bf->bf_roaming_energy_delta = value;
868 case MVM_DEBUGFS_BF_ROAMING_STATE:
869 dbgfs_bf->bf_roaming_state = value;
871 case MVM_DEBUGFS_BF_TEMP_THRESHOLD:
872 dbgfs_bf->bf_temp_threshold = value;
874 case MVM_DEBUGFS_BF_TEMP_FAST_FILTER:
875 dbgfs_bf->bf_temp_fast_filter = value;
877 case MVM_DEBUGFS_BF_TEMP_SLOW_FILTER:
878 dbgfs_bf->bf_temp_slow_filter = value;
880 case MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER:
881 dbgfs_bf->bf_enable_beacon_filter = value;
883 case MVM_DEBUGFS_BF_DEBUG_FLAG:
884 dbgfs_bf->bf_debug_flag = value;
886 case MVM_DEBUGFS_BF_ESCAPE_TIMER:
887 dbgfs_bf->bf_escape_timer = value;
889 case MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT:
890 dbgfs_bf->ba_enable_beacon_abort = value;
892 case MVM_DEBUGFS_BA_ESCAPE_TIMER:
893 dbgfs_bf->ba_escape_timer = value;
898 static ssize_t iwl_dbgfs_bf_params_write(struct file *file,
899 const char __user *user_buf,
900 size_t count, loff_t *ppos)
902 struct ieee80211_vif *vif = file->private_data;
903 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
904 struct iwl_mvm *mvm = mvmvif->dbgfs_data;
905 enum iwl_dbgfs_bf_mask param;
907 size_t buf_size = min(count, sizeof(buf) - 1);
910 if (copy_from_user(buf, user_buf, buf_size))
913 if (!strncmp("bf_energy_delta=", buf, 16)) {
914 if (sscanf(buf+16, "%d", &value) != 1)
916 if (value < IWL_BF_ENERGY_DELTA_MIN ||
917 value > IWL_BF_ENERGY_DELTA_MAX)
919 param = MVM_DEBUGFS_BF_ENERGY_DELTA;
920 } else if (!strncmp("bf_roaming_energy_delta=", buf, 24)) {
921 if (sscanf(buf+24, "%d", &value) != 1)
923 if (value < IWL_BF_ROAMING_ENERGY_DELTA_MIN ||
924 value > IWL_BF_ROAMING_ENERGY_DELTA_MAX)
926 param = MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA;
927 } else if (!strncmp("bf_roaming_state=", buf, 17)) {
928 if (sscanf(buf+17, "%d", &value) != 1)
930 if (value < IWL_BF_ROAMING_STATE_MIN ||
931 value > IWL_BF_ROAMING_STATE_MAX)
933 param = MVM_DEBUGFS_BF_ROAMING_STATE;
934 } else if (!strncmp("bf_temp_threshold=", buf, 18)) {
935 if (sscanf(buf+18, "%d", &value) != 1)
937 if (value < IWL_BF_TEMP_THRESHOLD_MIN ||
938 value > IWL_BF_TEMP_THRESHOLD_MAX)
940 param = MVM_DEBUGFS_BF_TEMP_THRESHOLD;
941 } else if (!strncmp("bf_temp_fast_filter=", buf, 20)) {
942 if (sscanf(buf+20, "%d", &value) != 1)
944 if (value < IWL_BF_TEMP_FAST_FILTER_MIN ||
945 value > IWL_BF_TEMP_FAST_FILTER_MAX)
947 param = MVM_DEBUGFS_BF_TEMP_FAST_FILTER;
948 } else if (!strncmp("bf_temp_slow_filter=", buf, 20)) {
949 if (sscanf(buf+20, "%d", &value) != 1)
951 if (value < IWL_BF_TEMP_SLOW_FILTER_MIN ||
952 value > IWL_BF_TEMP_SLOW_FILTER_MAX)
954 param = MVM_DEBUGFS_BF_TEMP_SLOW_FILTER;
955 } else if (!strncmp("bf_enable_beacon_filter=", buf, 24)) {
956 if (sscanf(buf+24, "%d", &value) != 1)
958 if (value < 0 || value > 1)
960 param = MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER;
961 } else if (!strncmp("bf_debug_flag=", buf, 14)) {
962 if (sscanf(buf+14, "%d", &value) != 1)
964 if (value < 0 || value > 1)
966 param = MVM_DEBUGFS_BF_DEBUG_FLAG;
967 } else if (!strncmp("bf_escape_timer=", buf, 16)) {
968 if (sscanf(buf+16, "%d", &value) != 1)
970 if (value < IWL_BF_ESCAPE_TIMER_MIN ||
971 value > IWL_BF_ESCAPE_TIMER_MAX)
973 param = MVM_DEBUGFS_BF_ESCAPE_TIMER;
974 } else if (!strncmp("ba_escape_timer=", buf, 16)) {
975 if (sscanf(buf+16, "%d", &value) != 1)
977 if (value < IWL_BA_ESCAPE_TIMER_MIN ||
978 value > IWL_BA_ESCAPE_TIMER_MAX)
980 param = MVM_DEBUGFS_BA_ESCAPE_TIMER;
981 } else if (!strncmp("ba_enable_beacon_abort=", buf, 23)) {
982 if (sscanf(buf+23, "%d", &value) != 1)
984 if (value < 0 || value > 1)
986 param = MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT;
991 mutex_lock(&mvm->mutex);
992 iwl_dbgfs_update_bf(vif, param, value);
993 if (param == MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER && !value)
994 ret = iwl_mvm_disable_beacon_filter(mvm, vif);
996 ret = iwl_mvm_enable_beacon_filter(mvm, vif);
997 mutex_unlock(&mvm->mutex);
1002 static ssize_t iwl_dbgfs_bf_params_read(struct file *file,
1003 char __user *user_buf,
1004 size_t count, loff_t *ppos)
1006 struct ieee80211_vif *vif = file->private_data;
1007 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1010 const size_t bufsz = sizeof(buf);
1011 struct iwl_beacon_filter_cmd cmd = {
1012 IWL_BF_CMD_CONFIG_DEFAULTS,
1013 .bf_enable_beacon_filter =
1014 cpu_to_le32(IWL_BF_ENABLE_BEACON_FILTER_DEFAULT),
1015 .ba_enable_beacon_abort =
1016 cpu_to_le32(IWL_BA_ENABLE_BEACON_ABORT_DEFAULT),
1019 iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
1020 if (mvmvif->bf_data.bf_enabled)
1021 cmd.bf_enable_beacon_filter = cpu_to_le32(1);
1023 cmd.bf_enable_beacon_filter = 0;
1025 pos += scnprintf(buf+pos, bufsz-pos, "bf_energy_delta = %d\n",
1026 le32_to_cpu(cmd.bf_energy_delta));
1027 pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_energy_delta = %d\n",
1028 le32_to_cpu(cmd.bf_roaming_energy_delta));
1029 pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_state = %d\n",
1030 le32_to_cpu(cmd.bf_roaming_state));
1031 pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_threshold = %d\n",
1032 le32_to_cpu(cmd.bf_temp_threshold));
1033 pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_fast_filter = %d\n",
1034 le32_to_cpu(cmd.bf_temp_fast_filter));
1035 pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_slow_filter = %d\n",
1036 le32_to_cpu(cmd.bf_temp_slow_filter));
1037 pos += scnprintf(buf+pos, bufsz-pos, "bf_enable_beacon_filter = %d\n",
1038 le32_to_cpu(cmd.bf_enable_beacon_filter));
1039 pos += scnprintf(buf+pos, bufsz-pos, "bf_debug_flag = %d\n",
1040 le32_to_cpu(cmd.bf_debug_flag));
1041 pos += scnprintf(buf+pos, bufsz-pos, "bf_escape_timer = %d\n",
1042 le32_to_cpu(cmd.bf_escape_timer));
1043 pos += scnprintf(buf+pos, bufsz-pos, "ba_escape_timer = %d\n",
1044 le32_to_cpu(cmd.ba_escape_timer));
1045 pos += scnprintf(buf+pos, bufsz-pos, "ba_enable_beacon_abort = %d\n",
1046 le32_to_cpu(cmd.ba_enable_beacon_abort));
1048 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1051 #ifdef CONFIG_PM_SLEEP
1052 static ssize_t iwl_dbgfs_d3_sram_write(struct file *file,
1053 const char __user *user_buf,
1054 size_t count, loff_t *ppos)
1056 struct iwl_mvm *mvm = file->private_data;
1058 size_t buf_size = min(count, sizeof(buf) - 1);
1061 if (copy_from_user(buf, user_buf, buf_size))
1064 if (sscanf(buf, "%d", &store) != 1)
1067 mvm->store_d3_resume_sram = store;
1072 static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
1073 size_t count, loff_t *ppos)
1075 struct iwl_mvm *mvm = file->private_data;
1076 const struct fw_img *img;
1077 int ofs, len, pos = 0;
1080 u8 *ptr = mvm->d3_resume_sram;
1082 img = &mvm->fw->img[IWL_UCODE_WOWLAN];
1083 len = img->sec[IWL_UCODE_SECTION_DATA].len;
1085 bufsz = len * 4 + 256;
1086 buf = kzalloc(bufsz, GFP_KERNEL);
1090 pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
1091 mvm->store_d3_resume_sram ? "en" : "dis");
1094 for (ofs = 0; ofs < len; ofs += 16) {
1095 pos += scnprintf(buf + pos, bufsz - pos,
1097 hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
1098 bufsz - pos, false);
1099 pos += strlen(buf + pos);
1100 if (bufsz - pos > 0)
1104 pos += scnprintf(buf + pos, bufsz - pos,
1105 "(no data captured)\n");
1108 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1116 #define MVM_DEBUGFS_READ_FILE_OPS(name) \
1117 static const struct file_operations iwl_dbgfs_##name##_ops = { \
1118 .read = iwl_dbgfs_##name##_read, \
1119 .open = simple_open, \
1120 .llseek = generic_file_llseek, \
1123 #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name) \
1124 static const struct file_operations iwl_dbgfs_##name##_ops = { \
1125 .write = iwl_dbgfs_##name##_write, \
1126 .read = iwl_dbgfs_##name##_read, \
1127 .open = simple_open, \
1128 .llseek = generic_file_llseek, \
1131 #define MVM_DEBUGFS_WRITE_FILE_OPS(name) \
1132 static const struct file_operations iwl_dbgfs_##name##_ops = { \
1133 .write = iwl_dbgfs_##name##_write, \
1134 .open = simple_open, \
1135 .llseek = generic_file_llseek, \
1138 #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) do { \
1139 if (!debugfs_create_file(#name, mode, parent, mvm, \
1140 &iwl_dbgfs_##name##_ops)) \
1144 #define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \
1145 if (!debugfs_create_file(#name, mode, parent, vif, \
1146 &iwl_dbgfs_##name##_ops)) \
1150 /* Device wide debugfs entries */
1151 MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush);
1152 MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain);
1153 MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram);
1154 MVM_DEBUGFS_READ_FILE_OPS(stations);
1155 MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
1156 MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
1157 MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off);
1158 MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
1159 MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart);
1160 MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi);
1161 MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain);
1163 #ifdef CONFIG_PM_SLEEP
1164 MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram);
1167 /* Interface specific debugfs entries */
1168 MVM_DEBUGFS_READ_FILE_OPS(mac_params);
1169 MVM_DEBUGFS_READ_WRITE_FILE_OPS(pm_params);
1170 MVM_DEBUGFS_READ_WRITE_FILE_OPS(bf_params);
1172 int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
1176 mvm->debugfs_dir = dbgfs_dir;
1178 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
1179 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
1180 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
1181 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
1182 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
1183 MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
1184 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_DEVICE_PS_CMD)
1185 MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
1187 MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
1188 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
1189 MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR);
1190 MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
1192 #ifdef CONFIG_PM_SLEEP
1193 MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
1194 MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
1195 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
1196 mvm->debugfs_dir, &mvm->d3_wake_sysassert))
1201 * Create a symlink with mac80211. It will be removed when mac80211
1202 * exists (before the opmode exists which removes the target.)
1204 snprintf(buf, 100, "../../%s/%s",
1205 dbgfs_dir->d_parent->d_parent->d_name.name,
1206 dbgfs_dir->d_parent->d_name.name);
1207 if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
1212 IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
1216 void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1218 struct dentry *dbgfs_dir = vif->debugfs_dir;
1219 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1223 * Check if debugfs directory already exist before creating it.
1224 * This may happen when, for example, resetting hw or suspend-resume
1226 if (!dbgfs_dir || mvmvif->dbgfs_dir)
1229 mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir);
1230 mvmvif->dbgfs_data = mvm;
1232 if (!mvmvif->dbgfs_dir) {
1233 IWL_ERR(mvm, "Failed to create debugfs directory under %s\n",
1234 dbgfs_dir->d_name.name);
1238 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM &&
1239 vif->type == NL80211_IFTYPE_STATION && !vif->p2p)
1240 MVM_DEBUGFS_ADD_FILE_VIF(pm_params, mvmvif->dbgfs_dir, S_IWUSR |
1243 MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir,
1246 if (vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
1247 mvmvif == mvm->bf_allowed_vif)
1248 MVM_DEBUGFS_ADD_FILE_VIF(bf_params, mvmvif->dbgfs_dir,
1252 * Create symlink for convenience pointing to interface specific
1253 * debugfs entries for the driver. For example, under
1254 * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/
1256 * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/
1258 snprintf(buf, 100, "../../../%s/%s/%s/%s",
1259 dbgfs_dir->d_parent->d_parent->d_name.name,
1260 dbgfs_dir->d_parent->d_name.name,
1261 dbgfs_dir->d_name.name,
1262 mvmvif->dbgfs_dir->d_name.name);
1264 mvmvif->dbgfs_slink = debugfs_create_symlink(dbgfs_dir->d_name.name,
1265 mvm->debugfs_dir, buf);
1266 if (!mvmvif->dbgfs_slink)
1267 IWL_ERR(mvm, "Can't create debugfs symbolic link under %s\n",
1268 dbgfs_dir->d_name.name);
1271 IWL_ERR(mvm, "Can't create debugfs entity\n");
1274 void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1276 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1278 debugfs_remove(mvmvif->dbgfs_slink);
1279 mvmvif->dbgfs_slink = NULL;
1281 debugfs_remove_recursive(mvmvif->dbgfs_dir);
1282 mvmvif->dbgfs_dir = NULL;