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 *****************************************************************************/
69 static ssize_t iwl_dbgfs_tx_flush_write(struct file *file,
70 const char __user *user_buf,
71 size_t count, loff_t *ppos)
73 struct iwl_mvm *mvm = file->private_data;
75 size_t buf_size = min(count, sizeof(buf) - 1);
79 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
82 if (copy_from_user(buf, user_buf, buf_size))
85 if (sscanf(buf, "%x", &scd_q_msk) != 1)
88 IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk);
90 mutex_lock(&mvm->mutex);
91 ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, true) ? : count;
92 mutex_unlock(&mvm->mutex);
97 static ssize_t iwl_dbgfs_sta_drain_write(struct file *file,
98 const char __user *user_buf,
99 size_t count, loff_t *ppos)
101 struct iwl_mvm *mvm = file->private_data;
102 struct ieee80211_sta *sta;
104 size_t buf_size = min(count, sizeof(buf) - 1);
105 int sta_id, drain, ret;
107 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
110 if (copy_from_user(buf, user_buf, buf_size))
113 if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
115 if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
117 if (drain < 0 || drain > 1)
120 mutex_lock(&mvm->mutex);
122 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
123 lockdep_is_held(&mvm->mutex));
124 if (IS_ERR_OR_NULL(sta))
127 ret = iwl_mvm_drain_sta(mvm, (void *)sta->drv_priv, drain) ? :
130 mutex_unlock(&mvm->mutex);
135 static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
136 size_t count, loff_t *ppos)
138 struct iwl_mvm *mvm = file->private_data;
139 const struct fw_img *img;
140 int ofs, len, pos = 0;
145 if (!mvm->ucode_loaded)
148 /* default is to dump the entire data segment */
149 if (!mvm->dbgfs_sram_offset && !mvm->dbgfs_sram_len) {
150 img = &mvm->fw->img[mvm->cur_ucode];
151 ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
152 len = img->sec[IWL_UCODE_SECTION_DATA].len;
154 ofs = mvm->dbgfs_sram_offset;
155 len = mvm->dbgfs_sram_len;
158 bufsz = len * 4 + 256;
159 buf = kzalloc(bufsz, GFP_KERNEL);
163 ptr = kzalloc(len, GFP_KERNEL);
169 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n", len);
170 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n", ofs);
172 iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
173 for (ofs = 0; ofs < len; ofs += 16) {
174 pos += scnprintf(buf + pos, bufsz - pos, "0x%.4x ", ofs);
175 hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
177 pos += strlen(buf + pos);
182 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
190 static ssize_t iwl_dbgfs_sram_write(struct file *file,
191 const char __user *user_buf, size_t count,
194 struct iwl_mvm *mvm = file->private_data;
196 size_t buf_size = min(count, sizeof(buf) - 1);
199 if (copy_from_user(buf, user_buf, buf_size))
202 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
203 if ((offset & 0x3) || (len & 0x3))
205 mvm->dbgfs_sram_offset = offset;
206 mvm->dbgfs_sram_len = len;
208 mvm->dbgfs_sram_offset = 0;
209 mvm->dbgfs_sram_len = 0;
215 static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
216 size_t count, loff_t *ppos)
218 struct iwl_mvm *mvm = file->private_data;
219 struct ieee80211_sta *sta;
221 int i, pos = 0, bufsz = sizeof(buf);
223 mutex_lock(&mvm->mutex);
225 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
226 pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
227 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
228 lockdep_is_held(&mvm->mutex));
230 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
231 else if (IS_ERR(sta))
232 pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
235 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
239 mutex_unlock(&mvm->mutex);
241 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
244 static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
245 char __user *user_buf,
246 size_t count, loff_t *ppos)
248 struct iwl_mvm *mvm = file->private_data;
250 int bufsz = sizeof(buf);
253 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
254 mvm->disable_power_off);
255 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
256 mvm->disable_power_off_d3);
258 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
261 static ssize_t iwl_dbgfs_disable_power_off_write(struct file *file,
262 const char __user *user_buf,
263 size_t count, loff_t *ppos)
265 struct iwl_mvm *mvm = file->private_data;
267 size_t buf_size = min(count, sizeof(buf) - 1);
271 if (!mvm->ucode_loaded)
274 if (copy_from_user(buf, user_buf, buf_size))
277 if (!strncmp("disable_power_off_d0=", buf, 21)) {
278 if (sscanf(buf + 21, "%d", &val) != 1)
280 mvm->disable_power_off = val;
281 } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
282 if (sscanf(buf + 21, "%d", &val) != 1)
284 mvm->disable_power_off_d3 = val;
289 mutex_lock(&mvm->mutex);
290 ret = iwl_mvm_power_update_device_mode(mvm);
291 mutex_unlock(&mvm->mutex);
296 #define BT_MBOX_MSG(_notif, _num, _field) \
297 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
298 >> BT_MBOX##_num##_##_field##_POS)
301 #define BT_MBOX_PRINT(_num, _field, _end) \
302 pos += scnprintf(buf + pos, bufsz - pos, \
305 BT_MBOX_MSG(notif, _num, _field), \
308 static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
309 size_t count, loff_t *ppos)
311 struct iwl_mvm *mvm = file->private_data;
312 struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
314 int ret, pos = 0, bufsz = sizeof(char) * 1024;
316 buf = kmalloc(bufsz, GFP_KERNEL);
320 mutex_lock(&mvm->mutex);
322 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
324 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
325 BT_MBOX_PRINT(0, LE_PROF1, false);
326 BT_MBOX_PRINT(0, LE_PROF2, false);
327 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
328 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
329 BT_MBOX_PRINT(0, INBAND_S, false);
330 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
331 BT_MBOX_PRINT(0, LE_SCAN, false);
332 BT_MBOX_PRINT(0, LE_ADV, false);
333 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
334 BT_MBOX_PRINT(0, OPEN_CON_1, true);
336 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
338 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
339 BT_MBOX_PRINT(1, IP_SR, false);
340 BT_MBOX_PRINT(1, LE_MSTR, false);
341 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
342 BT_MBOX_PRINT(1, MSG_TYPE, false);
343 BT_MBOX_PRINT(1, SSN, true);
345 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
347 BT_MBOX_PRINT(2, SNIFF_ACT, false);
348 BT_MBOX_PRINT(2, PAG, false);
349 BT_MBOX_PRINT(2, INQUIRY, false);
350 BT_MBOX_PRINT(2, CONN, false);
351 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
352 BT_MBOX_PRINT(2, DISC, false);
353 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
354 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
355 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
356 BT_MBOX_PRINT(2, SCO_DURATION, true);
358 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
360 BT_MBOX_PRINT(3, SCO_STATE, false);
361 BT_MBOX_PRINT(3, SNIFF_STATE, false);
362 BT_MBOX_PRINT(3, A2DP_STATE, false);
363 BT_MBOX_PRINT(3, ACL_STATE, false);
364 BT_MBOX_PRINT(3, MSTR_STATE, false);
365 BT_MBOX_PRINT(3, OBX_STATE, false);
366 BT_MBOX_PRINT(3, OPEN_CON_2, false);
367 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
368 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
369 BT_MBOX_PRINT(3, INBAND_P, false);
370 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
371 BT_MBOX_PRINT(3, SSN_2, false);
372 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
374 pos += scnprintf(buf+pos, bufsz-pos, "bt_status = %d\n",
376 pos += scnprintf(buf+pos, bufsz-pos, "bt_open_conn = %d\n",
377 notif->bt_open_conn);
378 pos += scnprintf(buf+pos, bufsz-pos, "bt_traffic_load = %d\n",
379 notif->bt_traffic_load);
380 pos += scnprintf(buf+pos, bufsz-pos, "bt_agg_traffic_load = %d\n",
381 notif->bt_agg_traffic_load);
382 pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
383 notif->bt_ci_compliance);
384 pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
385 le32_to_cpu(notif->primary_ch_lut));
386 pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
387 le32_to_cpu(notif->secondary_ch_lut));
388 pos += scnprintf(buf+pos, bufsz-pos, "bt_activity_grading = %d\n",
389 le32_to_cpu(notif->bt_activity_grading));
391 mutex_unlock(&mvm->mutex);
393 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
400 static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
401 size_t count, loff_t *ppos)
403 struct iwl_mvm *mvm = file->private_data;
404 struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
406 int bufsz = sizeof(buf);
409 mutex_lock(&mvm->mutex);
411 pos += scnprintf(buf+pos, bufsz-pos, "Channel inhibition CMD\n");
412 pos += scnprintf(buf+pos, bufsz-pos,
413 "\tPrimary Channel Bitmap 0x%016llx Fat: %d\n",
414 le64_to_cpu(cmd->bt_primary_ci),
415 !!cmd->co_run_bw_primary);
416 pos += scnprintf(buf+pos, bufsz-pos,
417 "\tSecondary Channel Bitmap 0x%016llx Fat: %d\n",
418 le64_to_cpu(cmd->bt_secondary_ci),
419 !!cmd->co_run_bw_secondary);
421 pos += scnprintf(buf+pos, bufsz-pos, "BT Configuration CMD\n");
422 pos += scnprintf(buf+pos, bufsz-pos, "\tACK Kill Mask 0x%08x\n",
423 iwl_bt_ack_kill_msk[mvm->bt_kill_msk]);
424 pos += scnprintf(buf+pos, bufsz-pos, "\tCTS Kill Mask 0x%08x\n",
425 iwl_bt_cts_kill_msk[mvm->bt_kill_msk]);
427 mutex_unlock(&mvm->mutex);
429 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
432 #define PRINT_STATS_LE32(_str, _val) \
433 pos += scnprintf(buf + pos, bufsz - pos, \
437 static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
438 char __user *user_buf, size_t count,
441 struct iwl_mvm *mvm = file->private_data;
442 static const char *fmt_table = "\t%-30s %10u\n";
443 static const char *fmt_header = "%-32s\n";
447 /* 43 is the size of each data line, 33 is the size of each header */
449 ((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) +
452 struct mvm_statistics_rx_phy *ofdm;
453 struct mvm_statistics_rx_phy *cck;
454 struct mvm_statistics_rx_non_phy *general;
455 struct mvm_statistics_rx_ht_phy *ht;
457 buf = kzalloc(bufsz, GFP_KERNEL);
461 mutex_lock(&mvm->mutex);
463 ofdm = &mvm->rx_stats.ofdm;
464 cck = &mvm->rx_stats.cck;
465 general = &mvm->rx_stats.general;
466 ht = &mvm->rx_stats.ofdm_ht;
468 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
469 "Statistics_Rx - OFDM");
470 PRINT_STATS_LE32("ina_cnt", ofdm->ina_cnt);
471 PRINT_STATS_LE32("fina_cnt", ofdm->fina_cnt);
472 PRINT_STATS_LE32("plcp_err", ofdm->plcp_err);
473 PRINT_STATS_LE32("crc32_err", ofdm->crc32_err);
474 PRINT_STATS_LE32("overrun_err", ofdm->overrun_err);
475 PRINT_STATS_LE32("early_overrun_err", ofdm->early_overrun_err);
476 PRINT_STATS_LE32("crc32_good", ofdm->crc32_good);
477 PRINT_STATS_LE32("false_alarm_cnt", ofdm->false_alarm_cnt);
478 PRINT_STATS_LE32("fina_sync_err_cnt", ofdm->fina_sync_err_cnt);
479 PRINT_STATS_LE32("sfd_timeout", ofdm->sfd_timeout);
480 PRINT_STATS_LE32("fina_timeout", ofdm->fina_timeout);
481 PRINT_STATS_LE32("unresponded_rts", ofdm->unresponded_rts);
482 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
483 ofdm->rxe_frame_limit_overrun);
484 PRINT_STATS_LE32("sent_ack_cnt", ofdm->sent_ack_cnt);
485 PRINT_STATS_LE32("sent_cts_cnt", ofdm->sent_cts_cnt);
486 PRINT_STATS_LE32("sent_ba_rsp_cnt", ofdm->sent_ba_rsp_cnt);
487 PRINT_STATS_LE32("dsp_self_kill", ofdm->dsp_self_kill);
488 PRINT_STATS_LE32("mh_format_err", ofdm->mh_format_err);
489 PRINT_STATS_LE32("re_acq_main_rssi_sum", ofdm->re_acq_main_rssi_sum);
490 PRINT_STATS_LE32("reserved", ofdm->reserved);
492 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
493 "Statistics_Rx - CCK");
494 PRINT_STATS_LE32("ina_cnt", cck->ina_cnt);
495 PRINT_STATS_LE32("fina_cnt", cck->fina_cnt);
496 PRINT_STATS_LE32("plcp_err", cck->plcp_err);
497 PRINT_STATS_LE32("crc32_err", cck->crc32_err);
498 PRINT_STATS_LE32("overrun_err", cck->overrun_err);
499 PRINT_STATS_LE32("early_overrun_err", cck->early_overrun_err);
500 PRINT_STATS_LE32("crc32_good", cck->crc32_good);
501 PRINT_STATS_LE32("false_alarm_cnt", cck->false_alarm_cnt);
502 PRINT_STATS_LE32("fina_sync_err_cnt", cck->fina_sync_err_cnt);
503 PRINT_STATS_LE32("sfd_timeout", cck->sfd_timeout);
504 PRINT_STATS_LE32("fina_timeout", cck->fina_timeout);
505 PRINT_STATS_LE32("unresponded_rts", cck->unresponded_rts);
506 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
507 cck->rxe_frame_limit_overrun);
508 PRINT_STATS_LE32("sent_ack_cnt", cck->sent_ack_cnt);
509 PRINT_STATS_LE32("sent_cts_cnt", cck->sent_cts_cnt);
510 PRINT_STATS_LE32("sent_ba_rsp_cnt", cck->sent_ba_rsp_cnt);
511 PRINT_STATS_LE32("dsp_self_kill", cck->dsp_self_kill);
512 PRINT_STATS_LE32("mh_format_err", cck->mh_format_err);
513 PRINT_STATS_LE32("re_acq_main_rssi_sum", cck->re_acq_main_rssi_sum);
514 PRINT_STATS_LE32("reserved", cck->reserved);
516 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
517 "Statistics_Rx - GENERAL");
518 PRINT_STATS_LE32("bogus_cts", general->bogus_cts);
519 PRINT_STATS_LE32("bogus_ack", general->bogus_ack);
520 PRINT_STATS_LE32("non_bssid_frames", general->non_bssid_frames);
521 PRINT_STATS_LE32("filtered_frames", general->filtered_frames);
522 PRINT_STATS_LE32("non_channel_beacons", general->non_channel_beacons);
523 PRINT_STATS_LE32("channel_beacons", general->channel_beacons);
524 PRINT_STATS_LE32("num_missed_bcon", general->num_missed_bcon);
525 PRINT_STATS_LE32("adc_rx_saturation_time",
526 general->adc_rx_saturation_time);
527 PRINT_STATS_LE32("ina_detection_search_time",
528 general->ina_detection_search_time);
529 PRINT_STATS_LE32("beacon_silence_rssi_a",
530 general->beacon_silence_rssi_a);
531 PRINT_STATS_LE32("beacon_silence_rssi_b",
532 general->beacon_silence_rssi_b);
533 PRINT_STATS_LE32("beacon_silence_rssi_c",
534 general->beacon_silence_rssi_c);
535 PRINT_STATS_LE32("interference_data_flag",
536 general->interference_data_flag);
537 PRINT_STATS_LE32("channel_load", general->channel_load);
538 PRINT_STATS_LE32("dsp_false_alarms", general->dsp_false_alarms);
539 PRINT_STATS_LE32("beacon_rssi_a", general->beacon_rssi_a);
540 PRINT_STATS_LE32("beacon_rssi_b", general->beacon_rssi_b);
541 PRINT_STATS_LE32("beacon_rssi_c", general->beacon_rssi_c);
542 PRINT_STATS_LE32("beacon_energy_a", general->beacon_energy_a);
543 PRINT_STATS_LE32("beacon_energy_b", general->beacon_energy_b);
544 PRINT_STATS_LE32("beacon_energy_c", general->beacon_energy_c);
545 PRINT_STATS_LE32("num_bt_kills", general->num_bt_kills);
546 PRINT_STATS_LE32("mac_id", general->mac_id);
547 PRINT_STATS_LE32("directed_data_mpdu", general->directed_data_mpdu);
549 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
550 "Statistics_Rx - HT");
551 PRINT_STATS_LE32("plcp_err", ht->plcp_err);
552 PRINT_STATS_LE32("overrun_err", ht->overrun_err);
553 PRINT_STATS_LE32("early_overrun_err", ht->early_overrun_err);
554 PRINT_STATS_LE32("crc32_good", ht->crc32_good);
555 PRINT_STATS_LE32("crc32_err", ht->crc32_err);
556 PRINT_STATS_LE32("mh_format_err", ht->mh_format_err);
557 PRINT_STATS_LE32("agg_crc32_good", ht->agg_crc32_good);
558 PRINT_STATS_LE32("agg_mpdu_cnt", ht->agg_mpdu_cnt);
559 PRINT_STATS_LE32("agg_cnt", ht->agg_cnt);
560 PRINT_STATS_LE32("unsupport_mcs", ht->unsupport_mcs);
562 mutex_unlock(&mvm->mutex);
564 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
569 #undef PRINT_STAT_LE32
571 static ssize_t iwl_dbgfs_fw_restart_write(struct file *file,
572 const char __user *user_buf,
573 size_t count, loff_t *ppos)
575 struct iwl_mvm *mvm = file->private_data;
578 mutex_lock(&mvm->mutex);
580 /* allow one more restart that we're provoking here */
581 if (mvm->restart_fw >= 0)
584 /* take the return value to make compiler happy - it will fail anyway */
585 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, CMD_SYNC, 0, NULL);
587 mutex_unlock(&mvm->mutex);
592 static ssize_t iwl_dbgfs_fw_nmi_write(struct file *file,
593 const char __user *user_buf,
594 size_t count, loff_t *ppos)
596 struct iwl_mvm *mvm = file->private_data;
598 iwl_write_prph(mvm->trans, DEVICE_SET_NMI_REG, 1);
604 iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
605 char __user *user_buf,
606 size_t count, loff_t *ppos)
608 struct iwl_mvm *mvm = file->private_data;
611 const size_t bufsz = sizeof(buf);
613 /* print which antennas were set for the scan command by the user */
614 pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
615 if (mvm->scan_rx_ant & ANT_A)
616 pos += scnprintf(buf + pos, bufsz - pos, "A");
617 if (mvm->scan_rx_ant & ANT_B)
618 pos += scnprintf(buf + pos, bufsz - pos, "B");
619 if (mvm->scan_rx_ant & ANT_C)
620 pos += scnprintf(buf + pos, bufsz - pos, "C");
621 pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
623 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
627 iwl_dbgfs_scan_ant_rxchain_write(struct file *file,
628 const char __user *user_buf,
629 size_t count, loff_t *ppos)
631 struct iwl_mvm *mvm = file->private_data;
633 size_t buf_size = min(count, sizeof(buf) - 1);
636 if (copy_from_user(buf, user_buf, buf_size))
638 if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
640 if (scan_rx_ant > ANT_ABC)
642 if (scan_rx_ant & ~iwl_fw_valid_rx_ant(mvm->fw))
645 mvm->scan_rx_ant = scan_rx_ant;
650 #ifdef CONFIG_PM_SLEEP
651 static ssize_t iwl_dbgfs_d3_sram_write(struct file *file,
652 const char __user *user_buf,
653 size_t count, loff_t *ppos)
655 struct iwl_mvm *mvm = file->private_data;
657 size_t buf_size = min(count, sizeof(buf) - 1);
660 if (copy_from_user(buf, user_buf, buf_size))
663 if (sscanf(buf, "%d", &store) != 1)
666 mvm->store_d3_resume_sram = store;
671 static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
672 size_t count, loff_t *ppos)
674 struct iwl_mvm *mvm = file->private_data;
675 const struct fw_img *img;
676 int ofs, len, pos = 0;
679 u8 *ptr = mvm->d3_resume_sram;
681 img = &mvm->fw->img[IWL_UCODE_WOWLAN];
682 len = img->sec[IWL_UCODE_SECTION_DATA].len;
684 bufsz = len * 4 + 256;
685 buf = kzalloc(bufsz, GFP_KERNEL);
689 pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
690 mvm->store_d3_resume_sram ? "en" : "dis");
693 for (ofs = 0; ofs < len; ofs += 16) {
694 pos += scnprintf(buf + pos, bufsz - pos,
696 hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
698 pos += strlen(buf + pos);
703 pos += scnprintf(buf + pos, bufsz - pos,
704 "(no data captured)\n");
707 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
715 #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) do { \
716 if (!debugfs_create_file(#name, mode, parent, mvm, \
717 &iwl_dbgfs_##name##_ops)) \
721 /* Device wide debugfs entries */
722 MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush);
723 MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain);
724 MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram);
725 MVM_DEBUGFS_READ_FILE_OPS(stations);
726 MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
727 MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
728 MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off);
729 MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
730 MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart);
731 MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi);
732 MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain);
734 #ifdef CONFIG_PM_SLEEP
735 MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram);
738 int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
742 mvm->debugfs_dir = dbgfs_dir;
744 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
745 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
746 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
747 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
748 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
749 MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
750 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_DEVICE_PS_CMD)
751 MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
753 MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
754 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
755 MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR);
756 MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
758 #ifdef CONFIG_PM_SLEEP
759 MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
760 MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
761 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
762 mvm->debugfs_dir, &mvm->d3_wake_sysassert))
767 * Create a symlink with mac80211. It will be removed when mac80211
768 * exists (before the opmode exists which removes the target.)
770 snprintf(buf, 100, "../../%s/%s",
771 dbgfs_dir->d_parent->d_parent->d_name.name,
772 dbgfs_dir->d_parent->d_name.name);
773 if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
778 IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");