2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <linux/module.h>
20 #include <linux/debugfs.h>
21 #include <linux/vmalloc.h>
22 #include <linux/utsname.h>
23 #include <linux/crc32.h>
24 #include <linux/firmware.h>
25 #include <linux/devcoredump.h>
33 #define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000
35 #define ATH10K_DEBUG_CAL_DATA_LEN 12064
37 #define ATH10K_FW_CRASH_DUMP_VERSION 1
40 * enum ath10k_fw_crash_dump_type - types of data in the dump file
41 * @ATH10K_FW_CRASH_DUMP_REGDUMP: Register crash dump in binary format
43 enum ath10k_fw_crash_dump_type {
44 ATH10K_FW_CRASH_DUMP_REGISTERS = 0,
45 ATH10K_FW_CRASH_DUMP_CE_DATA = 1,
47 ATH10K_FW_CRASH_DUMP_MAX,
50 struct ath10k_tlv_dump_data {
51 /* see ath10k_fw_crash_dump_type above */
57 /* pad to 32-bit boundaries as needed */
61 struct ath10k_dump_file_data {
62 /* dump file information */
64 /* "ATH10K-FW-DUMP" */
69 /* file dump version */
72 /* some info we can get from ath10k struct that might help */
78 /* 0 for now, in place for later hardware */
81 __le32 target_version;
82 __le32 fw_version_major;
83 __le32 fw_version_minor;
84 __le32 fw_version_release;
85 __le32 fw_version_build;
86 __le32 phy_capability;
87 __le32 hw_min_tx_power;
88 __le32 hw_max_tx_power;
93 /* firmware version string */
94 char fw_ver[ETHTOOL_FWVERS_LEN];
96 /* Kernel related information */
98 /* time-of-day stamp */
101 /* time-of-day stamp, nano-seconds */
104 /* LINUX_VERSION_CODE */
105 __le32 kernel_ver_code;
107 /* VERMAGIC_STRING */
110 /* room for growth w/out changing binary format */
113 /* struct ath10k_tlv_dump_data + more */
117 void ath10k_info(struct ath10k *ar, const char *fmt, ...)
119 struct va_format vaf = {
126 dev_info(ar->dev, "%pV", &vaf);
127 trace_ath10k_log_info(ar, &vaf);
130 EXPORT_SYMBOL(ath10k_info);
132 void ath10k_debug_print_hwfw_info(struct ath10k *ar)
134 const struct firmware *firmware;
135 char fw_features[128] = {};
138 ath10k_core_get_fw_features_str(ar, fw_features, sizeof(fw_features));
140 ath10k_info(ar, "%s target 0x%08x chip_id 0x%08x sub %04x:%04x",
144 ar->id.subsystem_vendor, ar->id.subsystem_device);
146 ath10k_info(ar, "kconfig debug %d debugfs %d tracing %d dfs %d testmode %d\n",
147 IS_ENABLED(CONFIG_ATH10K_DEBUG),
148 IS_ENABLED(CONFIG_ATH10K_DEBUGFS),
149 IS_ENABLED(CONFIG_ATH10K_TRACING),
150 IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED),
151 IS_ENABLED(CONFIG_NL80211_TESTMODE));
153 firmware = ar->normal_mode_fw.fw_file.firmware;
155 crc = crc32_le(0, firmware->data, firmware->size);
157 ath10k_info(ar, "firmware ver %s api %d features %s crc32 %08x\n",
158 ar->hw->wiphy->fw_version,
164 void ath10k_debug_print_board_info(struct ath10k *ar)
167 const struct firmware *board;
170 if (ar->id.bmi_ids_valid)
171 scnprintf(boardinfo, sizeof(boardinfo), "%d:%d",
172 ar->id.bmi_chip_id, ar->id.bmi_board_id);
174 scnprintf(boardinfo, sizeof(boardinfo), "N/A");
176 board = ar->normal_mode_fw.board;
177 if (!IS_ERR_OR_NULL(board))
178 crc = crc32_le(0, board->data, board->size);
182 ath10k_info(ar, "board_file api %d bmi_id %s crc32 %08x",
188 void ath10k_debug_print_boot_info(struct ath10k *ar)
190 ath10k_info(ar, "htt-ver %d.%d wmi-op %d htt-op %d cal %s max-sta %d raw %d hwcrypto %d\n",
191 ar->htt.target_version_major,
192 ar->htt.target_version_minor,
193 ar->normal_mode_fw.fw_file.wmi_op_version,
194 ar->normal_mode_fw.fw_file.htt_op_version,
195 ath10k_cal_mode_str(ar->cal_mode),
196 ar->max_num_stations,
197 test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags),
198 !test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags));
201 void ath10k_print_driver_info(struct ath10k *ar)
203 ath10k_debug_print_hwfw_info(ar);
204 ath10k_debug_print_board_info(ar);
205 ath10k_debug_print_boot_info(ar);
207 EXPORT_SYMBOL(ath10k_print_driver_info);
209 void ath10k_err(struct ath10k *ar, const char *fmt, ...)
211 struct va_format vaf = {
218 dev_err(ar->dev, "%pV", &vaf);
219 trace_ath10k_log_err(ar, &vaf);
222 EXPORT_SYMBOL(ath10k_err);
224 void ath10k_warn(struct ath10k *ar, const char *fmt, ...)
226 struct va_format vaf = {
233 dev_warn_ratelimited(ar->dev, "%pV", &vaf);
234 trace_ath10k_log_warn(ar, &vaf);
238 EXPORT_SYMBOL(ath10k_warn);
240 #ifdef CONFIG_ATH10K_DEBUGFS
242 static ssize_t ath10k_read_wmi_services(struct file *file,
243 char __user *user_buf,
244 size_t count, loff_t *ppos)
246 struct ath10k *ar = file->private_data;
248 size_t len = 0, buf_len = 8192;
254 buf = kzalloc(buf_len, GFP_KERNEL);
258 mutex_lock(&ar->conf_mutex);
260 spin_lock_bh(&ar->data_lock);
261 for (i = 0; i < WMI_SERVICE_MAX; i++) {
262 enabled = test_bit(i, ar->wmi.svc_map);
263 name = wmi_service_name(i);
267 len += scnprintf(buf + len, buf_len - len,
268 "%-40s %s (bit %d)\n",
269 "unknown", "enabled", i);
274 len += scnprintf(buf + len, buf_len - len,
276 name, enabled ? "enabled" : "-");
278 spin_unlock_bh(&ar->data_lock);
280 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
282 mutex_unlock(&ar->conf_mutex);
288 static const struct file_operations fops_wmi_services = {
289 .read = ath10k_read_wmi_services,
291 .owner = THIS_MODULE,
292 .llseek = default_llseek,
295 static void ath10k_fw_stats_pdevs_free(struct list_head *head)
297 struct ath10k_fw_stats_pdev *i, *tmp;
299 list_for_each_entry_safe(i, tmp, head, list) {
305 static void ath10k_fw_stats_vdevs_free(struct list_head *head)
307 struct ath10k_fw_stats_vdev *i, *tmp;
309 list_for_each_entry_safe(i, tmp, head, list) {
315 static void ath10k_fw_stats_peers_free(struct list_head *head)
317 struct ath10k_fw_stats_peer *i, *tmp;
319 list_for_each_entry_safe(i, tmp, head, list) {
325 static void ath10k_fw_extd_stats_peers_free(struct list_head *head)
327 struct ath10k_fw_extd_stats_peer *i, *tmp;
329 list_for_each_entry_safe(i, tmp, head, list) {
335 static void ath10k_debug_fw_stats_reset(struct ath10k *ar)
337 spin_lock_bh(&ar->data_lock);
338 ar->debug.fw_stats_done = false;
339 ar->debug.fw_stats.extended = false;
340 ath10k_fw_stats_pdevs_free(&ar->debug.fw_stats.pdevs);
341 ath10k_fw_stats_vdevs_free(&ar->debug.fw_stats.vdevs);
342 ath10k_fw_stats_peers_free(&ar->debug.fw_stats.peers);
343 ath10k_fw_extd_stats_peers_free(&ar->debug.fw_stats.peers_extd);
344 spin_unlock_bh(&ar->data_lock);
347 void ath10k_debug_fw_stats_process(struct ath10k *ar, struct sk_buff *skb)
349 struct ath10k_fw_stats stats = {};
350 bool is_start, is_started, is_end;
355 INIT_LIST_HEAD(&stats.pdevs);
356 INIT_LIST_HEAD(&stats.vdevs);
357 INIT_LIST_HEAD(&stats.peers);
358 INIT_LIST_HEAD(&stats.peers_extd);
360 spin_lock_bh(&ar->data_lock);
361 ret = ath10k_wmi_pull_fw_stats(ar, skb, &stats);
363 ath10k_warn(ar, "failed to pull fw stats: %d\n", ret);
367 /* Stat data may exceed htc-wmi buffer limit. In such case firmware
368 * splits the stats data and delivers it in a ping-pong fashion of
369 * request cmd-update event.
371 * However there is no explicit end-of-data. Instead start-of-data is
372 * used as an implicit one. This works as follows:
373 * a) discard stat update events until one with pdev stats is
374 * delivered - this skips session started at end of (b)
375 * b) consume stat update events until another one with pdev stats is
376 * delivered which is treated as end-of-data and is itself discarded
378 if (ath10k_peer_stats_enabled(ar))
379 ath10k_sta_update_rx_duration(ar, &stats);
381 if (ar->debug.fw_stats_done) {
382 if (!ath10k_peer_stats_enabled(ar))
383 ath10k_warn(ar, "received unsolicited stats update event\n");
388 num_peers = ath10k_wmi_fw_stats_num_peers(&ar->debug.fw_stats.peers);
389 num_vdevs = ath10k_wmi_fw_stats_num_vdevs(&ar->debug.fw_stats.vdevs);
390 is_start = (list_empty(&ar->debug.fw_stats.pdevs) &&
391 !list_empty(&stats.pdevs));
392 is_end = (!list_empty(&ar->debug.fw_stats.pdevs) &&
393 !list_empty(&stats.pdevs));
396 list_splice_tail_init(&stats.pdevs, &ar->debug.fw_stats.pdevs);
399 ar->debug.fw_stats_done = true;
401 is_started = !list_empty(&ar->debug.fw_stats.pdevs);
403 if (is_started && !is_end) {
404 if (num_peers >= ATH10K_MAX_NUM_PEER_IDS) {
405 /* Although this is unlikely impose a sane limit to
406 * prevent firmware from DoS-ing the host.
408 ath10k_fw_stats_peers_free(&ar->debug.fw_stats.peers);
409 ath10k_fw_extd_stats_peers_free(&ar->debug.fw_stats.peers_extd);
410 ath10k_warn(ar, "dropping fw peer stats\n");
414 if (num_vdevs >= BITS_PER_LONG) {
415 ath10k_fw_stats_vdevs_free(&ar->debug.fw_stats.vdevs);
416 ath10k_warn(ar, "dropping fw vdev stats\n");
420 if (!list_empty(&stats.peers))
421 list_splice_tail_init(&stats.peers_extd,
422 &ar->debug.fw_stats.peers_extd);
424 list_splice_tail_init(&stats.peers, &ar->debug.fw_stats.peers);
425 list_splice_tail_init(&stats.vdevs, &ar->debug.fw_stats.vdevs);
428 complete(&ar->debug.fw_stats_complete);
431 /* In some cases lists have been spliced and cleared. Free up
432 * resources if that is not the case.
434 ath10k_fw_stats_pdevs_free(&stats.pdevs);
435 ath10k_fw_stats_vdevs_free(&stats.vdevs);
436 ath10k_fw_stats_peers_free(&stats.peers);
437 ath10k_fw_extd_stats_peers_free(&stats.peers_extd);
439 spin_unlock_bh(&ar->data_lock);
442 static int ath10k_debug_fw_stats_request(struct ath10k *ar)
444 unsigned long timeout, time_left;
447 lockdep_assert_held(&ar->conf_mutex);
449 timeout = jiffies + msecs_to_jiffies(1 * HZ);
451 ath10k_debug_fw_stats_reset(ar);
454 if (time_after(jiffies, timeout))
457 reinit_completion(&ar->debug.fw_stats_complete);
459 ret = ath10k_wmi_request_stats(ar, ar->fw_stats_req_mask);
461 ath10k_warn(ar, "could not request stats (%d)\n", ret);
466 wait_for_completion_timeout(&ar->debug.fw_stats_complete,
471 spin_lock_bh(&ar->data_lock);
472 if (ar->debug.fw_stats_done) {
473 spin_unlock_bh(&ar->data_lock);
476 spin_unlock_bh(&ar->data_lock);
482 static int ath10k_fw_stats_open(struct inode *inode, struct file *file)
484 struct ath10k *ar = inode->i_private;
488 mutex_lock(&ar->conf_mutex);
490 if (ar->state != ATH10K_STATE_ON) {
495 buf = vmalloc(ATH10K_FW_STATS_BUF_SIZE);
501 ret = ath10k_debug_fw_stats_request(ar);
503 ath10k_warn(ar, "failed to request fw stats: %d\n", ret);
507 ret = ath10k_wmi_fw_stats_fill(ar, &ar->debug.fw_stats, buf);
509 ath10k_warn(ar, "failed to fill fw stats: %d\n", ret);
513 file->private_data = buf;
515 mutex_unlock(&ar->conf_mutex);
522 mutex_unlock(&ar->conf_mutex);
526 static int ath10k_fw_stats_release(struct inode *inode, struct file *file)
528 vfree(file->private_data);
533 static ssize_t ath10k_fw_stats_read(struct file *file, char __user *user_buf,
534 size_t count, loff_t *ppos)
536 const char *buf = file->private_data;
537 size_t len = strlen(buf);
539 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
542 static const struct file_operations fops_fw_stats = {
543 .open = ath10k_fw_stats_open,
544 .release = ath10k_fw_stats_release,
545 .read = ath10k_fw_stats_read,
546 .owner = THIS_MODULE,
547 .llseek = default_llseek,
550 static ssize_t ath10k_debug_fw_reset_stats_read(struct file *file,
551 char __user *user_buf,
552 size_t count, loff_t *ppos)
554 struct ath10k *ar = file->private_data;
556 size_t len = 0, buf_len = 500;
559 buf = kmalloc(buf_len, GFP_KERNEL);
563 spin_lock_bh(&ar->data_lock);
565 len += scnprintf(buf + len, buf_len - len,
566 "fw_crash_counter\t\t%d\n", ar->stats.fw_crash_counter);
567 len += scnprintf(buf + len, buf_len - len,
568 "fw_warm_reset_counter\t\t%d\n",
569 ar->stats.fw_warm_reset_counter);
570 len += scnprintf(buf + len, buf_len - len,
571 "fw_cold_reset_counter\t\t%d\n",
572 ar->stats.fw_cold_reset_counter);
574 spin_unlock_bh(&ar->data_lock);
576 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
583 static const struct file_operations fops_fw_reset_stats = {
585 .read = ath10k_debug_fw_reset_stats_read,
586 .owner = THIS_MODULE,
587 .llseek = default_llseek,
590 /* This is a clean assert crash in firmware. */
591 static int ath10k_debug_fw_assert(struct ath10k *ar)
593 struct wmi_vdev_install_key_cmd *cmd;
596 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd) + 16);
600 cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
601 memset(cmd, 0, sizeof(*cmd));
603 /* big enough number so that firmware asserts */
604 cmd->vdev_id = __cpu_to_le32(0x7ffe);
606 return ath10k_wmi_cmd_send(ar, skb,
607 ar->wmi.cmd->vdev_install_key_cmdid);
610 static ssize_t ath10k_read_simulate_fw_crash(struct file *file,
611 char __user *user_buf,
612 size_t count, loff_t *ppos)
615 "To simulate firmware crash write one of the keywords to this file:\n"
616 "`soft` - this will send WMI_FORCE_FW_HANG_ASSERT to firmware if FW supports that command.\n"
617 "`hard` - this will send to firmware command with illegal parameters causing firmware crash.\n"
618 "`assert` - this will send special illegal parameter to firmware to cause assert failure and crash.\n"
619 "`hw-restart` - this will simply queue hw restart without fw/hw actually crashing.\n";
621 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
624 /* Simulate firmware crash:
625 * 'soft': Call wmi command causing firmware hang. This firmware hang is
626 * recoverable by warm firmware reset.
627 * 'hard': Force firmware crash by setting any vdev parameter for not allowed
628 * vdev id. This is hard firmware crash because it is recoverable only by cold
631 static ssize_t ath10k_write_simulate_fw_crash(struct file *file,
632 const char __user *user_buf,
633 size_t count, loff_t *ppos)
635 struct ath10k *ar = file->private_data;
640 /* filter partial writes and invalid commands */
641 if (*ppos != 0 || count >= sizeof(buf) || count == 0)
644 rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
648 /* drop the possible '\n' from the end */
649 if (buf[*ppos - 1] == '\n')
650 buf[*ppos - 1] = '\0';
652 mutex_lock(&ar->conf_mutex);
654 if (ar->state != ATH10K_STATE_ON &&
655 ar->state != ATH10K_STATE_RESTARTED) {
660 if (!strcmp(buf, "soft")) {
661 ath10k_info(ar, "simulating soft firmware crash\n");
662 ret = ath10k_wmi_force_fw_hang(ar, WMI_FORCE_FW_HANG_ASSERT, 0);
663 } else if (!strcmp(buf, "hard")) {
664 ath10k_info(ar, "simulating hard firmware crash\n");
665 /* 0x7fff is vdev id, and it is always out of range for all
666 * firmware variants in order to force a firmware crash.
668 ret = ath10k_wmi_vdev_set_param(ar, 0x7fff,
669 ar->wmi.vdev_param->rts_threshold,
671 } else if (!strcmp(buf, "assert")) {
672 ath10k_info(ar, "simulating firmware assert crash\n");
673 ret = ath10k_debug_fw_assert(ar);
674 } else if (!strcmp(buf, "hw-restart")) {
675 ath10k_info(ar, "user requested hw restart\n");
676 queue_work(ar->workqueue, &ar->restart_work);
684 ath10k_warn(ar, "failed to simulate firmware crash: %d\n", ret);
691 mutex_unlock(&ar->conf_mutex);
695 static const struct file_operations fops_simulate_fw_crash = {
696 .read = ath10k_read_simulate_fw_crash,
697 .write = ath10k_write_simulate_fw_crash,
699 .owner = THIS_MODULE,
700 .llseek = default_llseek,
703 static ssize_t ath10k_read_chip_id(struct file *file, char __user *user_buf,
704 size_t count, loff_t *ppos)
706 struct ath10k *ar = file->private_data;
710 len = scnprintf(buf, sizeof(buf), "0x%08x\n", ar->chip_id);
712 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
715 static const struct file_operations fops_chip_id = {
716 .read = ath10k_read_chip_id,
718 .owner = THIS_MODULE,
719 .llseek = default_llseek,
722 struct ath10k_fw_crash_data *
723 ath10k_debug_get_new_fw_crash_data(struct ath10k *ar)
725 struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data;
727 lockdep_assert_held(&ar->data_lock);
729 crash_data->crashed_since_read = true;
730 guid_gen(&crash_data->guid);
731 getnstimeofday(&crash_data->timestamp);
735 EXPORT_SYMBOL(ath10k_debug_get_new_fw_crash_data);
737 static struct ath10k_dump_file_data *ath10k_build_dump_file(struct ath10k *ar,
740 struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data;
741 struct ath10k_ce_crash_hdr *ce_hdr;
742 struct ath10k_dump_file_data *dump_data;
743 struct ath10k_tlv_dump_data *dump_tlv;
744 size_t hdr_len = sizeof(*dump_data);
745 size_t len, sofar = 0;
749 len += sizeof(*dump_tlv) + sizeof(crash_data->registers);
750 len += sizeof(*dump_tlv) + sizeof(*ce_hdr) +
751 CE_COUNT * sizeof(ce_hdr->entries[0]);
755 /* This is going to get big when we start dumping FW RAM and such,
756 * so go ahead and use vmalloc.
762 spin_lock_bh(&ar->data_lock);
764 if (!crash_data->crashed_since_read) {
765 spin_unlock_bh(&ar->data_lock);
770 dump_data = (struct ath10k_dump_file_data *)(buf);
771 strlcpy(dump_data->df_magic, "ATH10K-FW-DUMP",
772 sizeof(dump_data->df_magic));
773 dump_data->len = cpu_to_le32(len);
775 dump_data->version = cpu_to_le32(ATH10K_FW_CRASH_DUMP_VERSION);
777 guid_copy(&dump_data->guid, &crash_data->guid);
778 dump_data->chip_id = cpu_to_le32(ar->chip_id);
779 dump_data->bus_type = cpu_to_le32(0);
780 dump_data->target_version = cpu_to_le32(ar->target_version);
781 dump_data->fw_version_major = cpu_to_le32(ar->fw_version_major);
782 dump_data->fw_version_minor = cpu_to_le32(ar->fw_version_minor);
783 dump_data->fw_version_release = cpu_to_le32(ar->fw_version_release);
784 dump_data->fw_version_build = cpu_to_le32(ar->fw_version_build);
785 dump_data->phy_capability = cpu_to_le32(ar->phy_capability);
786 dump_data->hw_min_tx_power = cpu_to_le32(ar->hw_min_tx_power);
787 dump_data->hw_max_tx_power = cpu_to_le32(ar->hw_max_tx_power);
788 dump_data->ht_cap_info = cpu_to_le32(ar->ht_cap_info);
789 dump_data->vht_cap_info = cpu_to_le32(ar->vht_cap_info);
790 dump_data->num_rf_chains = cpu_to_le32(ar->num_rf_chains);
792 strlcpy(dump_data->fw_ver, ar->hw->wiphy->fw_version,
793 sizeof(dump_data->fw_ver));
795 dump_data->kernel_ver_code = 0;
796 strlcpy(dump_data->kernel_ver, init_utsname()->release,
797 sizeof(dump_data->kernel_ver));
799 dump_data->tv_sec = cpu_to_le64(crash_data->timestamp.tv_sec);
800 dump_data->tv_nsec = cpu_to_le64(crash_data->timestamp.tv_nsec);
802 /* Gather crash-dump */
803 dump_tlv = (struct ath10k_tlv_dump_data *)(buf + sofar);
804 dump_tlv->type = cpu_to_le32(ATH10K_FW_CRASH_DUMP_REGISTERS);
805 dump_tlv->tlv_len = cpu_to_le32(sizeof(crash_data->registers));
806 memcpy(dump_tlv->tlv_data, &crash_data->registers,
807 sizeof(crash_data->registers));
808 sofar += sizeof(*dump_tlv) + sizeof(crash_data->registers);
810 dump_tlv = (struct ath10k_tlv_dump_data *)(buf + sofar);
811 dump_tlv->type = cpu_to_le32(ATH10K_FW_CRASH_DUMP_CE_DATA);
812 dump_tlv->tlv_len = cpu_to_le32(sizeof(*ce_hdr) +
813 CE_COUNT * sizeof(ce_hdr->entries[0]));
814 ce_hdr = (struct ath10k_ce_crash_hdr *)(dump_tlv->tlv_data);
815 ce_hdr->ce_count = cpu_to_le32(CE_COUNT);
816 memset(ce_hdr->reserved, 0, sizeof(ce_hdr->reserved));
817 memcpy(ce_hdr->entries, crash_data->ce_crash_data,
818 CE_COUNT * sizeof(ce_hdr->entries[0]));
819 sofar += sizeof(*dump_tlv) + sizeof(*ce_hdr) +
820 CE_COUNT * sizeof(ce_hdr->entries[0]);
822 ar->debug.fw_crash_data->crashed_since_read = !mark_read;
824 spin_unlock_bh(&ar->data_lock);
829 int ath10k_debug_fw_devcoredump(struct ath10k *ar)
831 struct ath10k_dump_file_data *dump;
835 /* To keep the dump file available also for debugfs don't mark the
836 * file read, only debugfs should do that.
838 dump = ath10k_build_dump_file(ar, false);
840 ath10k_warn(ar, "no crash dump data found for devcoredump");
844 /* Make a copy of the dump file for dev_coredumpv() as during the
845 * transition period we need to own the original file. Once
846 * fw_crash_dump debugfs file is removed no need to have a copy
849 dump_len = le32_to_cpu(dump->len);
850 dump_ptr = vzalloc(dump_len);
855 memcpy(dump_ptr, dump, dump_len);
857 dev_coredumpv(ar->dev, dump_ptr, dump_len, GFP_KERNEL);
862 static int ath10k_fw_crash_dump_open(struct inode *inode, struct file *file)
864 struct ath10k *ar = inode->i_private;
865 struct ath10k_dump_file_data *dump;
867 ath10k_warn(ar, "fw_crash_dump debugfs file is deprecated, please use /sys/class/devcoredump instead.");
869 dump = ath10k_build_dump_file(ar, true);
873 file->private_data = dump;
878 static ssize_t ath10k_fw_crash_dump_read(struct file *file,
879 char __user *user_buf,
880 size_t count, loff_t *ppos)
882 struct ath10k_dump_file_data *dump_file = file->private_data;
884 return simple_read_from_buffer(user_buf, count, ppos,
886 le32_to_cpu(dump_file->len));
889 static int ath10k_fw_crash_dump_release(struct inode *inode,
892 vfree(file->private_data);
897 static const struct file_operations fops_fw_crash_dump = {
898 .open = ath10k_fw_crash_dump_open,
899 .read = ath10k_fw_crash_dump_read,
900 .release = ath10k_fw_crash_dump_release,
901 .owner = THIS_MODULE,
902 .llseek = default_llseek,
905 static ssize_t ath10k_reg_addr_read(struct file *file,
906 char __user *user_buf,
907 size_t count, loff_t *ppos)
909 struct ath10k *ar = file->private_data;
914 mutex_lock(&ar->conf_mutex);
915 reg_addr = ar->debug.reg_addr;
916 mutex_unlock(&ar->conf_mutex);
918 len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n", reg_addr);
920 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
923 static ssize_t ath10k_reg_addr_write(struct file *file,
924 const char __user *user_buf,
925 size_t count, loff_t *ppos)
927 struct ath10k *ar = file->private_data;
931 ret = kstrtou32_from_user(user_buf, count, 0, ®_addr);
935 if (!IS_ALIGNED(reg_addr, 4))
938 mutex_lock(&ar->conf_mutex);
939 ar->debug.reg_addr = reg_addr;
940 mutex_unlock(&ar->conf_mutex);
945 static const struct file_operations fops_reg_addr = {
946 .read = ath10k_reg_addr_read,
947 .write = ath10k_reg_addr_write,
949 .owner = THIS_MODULE,
950 .llseek = default_llseek,
953 static ssize_t ath10k_reg_value_read(struct file *file,
954 char __user *user_buf,
955 size_t count, loff_t *ppos)
957 struct ath10k *ar = file->private_data;
960 u32 reg_addr, reg_val;
963 mutex_lock(&ar->conf_mutex);
965 if (ar->state != ATH10K_STATE_ON &&
966 ar->state != ATH10K_STATE_UTF) {
971 reg_addr = ar->debug.reg_addr;
973 reg_val = ath10k_hif_read32(ar, reg_addr);
974 len = scnprintf(buf, sizeof(buf), "0x%08x:0x%08x\n", reg_addr, reg_val);
976 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
979 mutex_unlock(&ar->conf_mutex);
984 static ssize_t ath10k_reg_value_write(struct file *file,
985 const char __user *user_buf,
986 size_t count, loff_t *ppos)
988 struct ath10k *ar = file->private_data;
989 u32 reg_addr, reg_val;
992 mutex_lock(&ar->conf_mutex);
994 if (ar->state != ATH10K_STATE_ON &&
995 ar->state != ATH10K_STATE_UTF) {
1000 reg_addr = ar->debug.reg_addr;
1002 ret = kstrtou32_from_user(user_buf, count, 0, ®_val);
1006 ath10k_hif_write32(ar, reg_addr, reg_val);
1011 mutex_unlock(&ar->conf_mutex);
1016 static const struct file_operations fops_reg_value = {
1017 .read = ath10k_reg_value_read,
1018 .write = ath10k_reg_value_write,
1019 .open = simple_open,
1020 .owner = THIS_MODULE,
1021 .llseek = default_llseek,
1024 static ssize_t ath10k_mem_value_read(struct file *file,
1025 char __user *user_buf,
1026 size_t count, loff_t *ppos)
1028 struct ath10k *ar = file->private_data;
1038 mutex_lock(&ar->conf_mutex);
1040 buf = vmalloc(count);
1046 if (ar->state != ATH10K_STATE_ON &&
1047 ar->state != ATH10K_STATE_UTF) {
1052 ret = ath10k_hif_diag_read(ar, *ppos, buf, count);
1054 ath10k_warn(ar, "failed to read address 0x%08x via diagnose window fnrom debugfs: %d\n",
1059 ret = copy_to_user(user_buf, buf, count);
1071 mutex_unlock(&ar->conf_mutex);
1076 static ssize_t ath10k_mem_value_write(struct file *file,
1077 const char __user *user_buf,
1078 size_t count, loff_t *ppos)
1080 struct ath10k *ar = file->private_data;
1090 mutex_lock(&ar->conf_mutex);
1092 buf = vmalloc(count);
1098 if (ar->state != ATH10K_STATE_ON &&
1099 ar->state != ATH10K_STATE_UTF) {
1104 ret = copy_from_user(buf, user_buf, count);
1110 ret = ath10k_hif_diag_write(ar, *ppos, buf, count);
1112 ath10k_warn(ar, "failed to write address 0x%08x via diagnose window from debugfs: %d\n",
1122 mutex_unlock(&ar->conf_mutex);
1127 static const struct file_operations fops_mem_value = {
1128 .read = ath10k_mem_value_read,
1129 .write = ath10k_mem_value_write,
1130 .open = simple_open,
1131 .owner = THIS_MODULE,
1132 .llseek = default_llseek,
1135 static int ath10k_debug_htt_stats_req(struct ath10k *ar)
1140 lockdep_assert_held(&ar->conf_mutex);
1142 if (ar->debug.htt_stats_mask == 0)
1143 /* htt stats are disabled */
1146 if (ar->state != ATH10K_STATE_ON)
1149 cookie = get_jiffies_64();
1151 ret = ath10k_htt_h2t_stats_req(&ar->htt, ar->debug.htt_stats_mask,
1154 ath10k_warn(ar, "failed to send htt stats request: %d\n", ret);
1158 queue_delayed_work(ar->workqueue, &ar->debug.htt_stats_dwork,
1159 msecs_to_jiffies(ATH10K_DEBUG_HTT_STATS_INTERVAL));
1164 static void ath10k_debug_htt_stats_dwork(struct work_struct *work)
1166 struct ath10k *ar = container_of(work, struct ath10k,
1167 debug.htt_stats_dwork.work);
1169 mutex_lock(&ar->conf_mutex);
1171 ath10k_debug_htt_stats_req(ar);
1173 mutex_unlock(&ar->conf_mutex);
1176 static ssize_t ath10k_read_htt_stats_mask(struct file *file,
1177 char __user *user_buf,
1178 size_t count, loff_t *ppos)
1180 struct ath10k *ar = file->private_data;
1184 len = scnprintf(buf, sizeof(buf), "%lu\n", ar->debug.htt_stats_mask);
1186 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1189 static ssize_t ath10k_write_htt_stats_mask(struct file *file,
1190 const char __user *user_buf,
1191 size_t count, loff_t *ppos)
1193 struct ath10k *ar = file->private_data;
1197 ret = kstrtoul_from_user(user_buf, count, 0, &mask);
1201 /* max 8 bit masks (for now) */
1205 mutex_lock(&ar->conf_mutex);
1207 ar->debug.htt_stats_mask = mask;
1209 ret = ath10k_debug_htt_stats_req(ar);
1216 mutex_unlock(&ar->conf_mutex);
1221 static const struct file_operations fops_htt_stats_mask = {
1222 .read = ath10k_read_htt_stats_mask,
1223 .write = ath10k_write_htt_stats_mask,
1224 .open = simple_open,
1225 .owner = THIS_MODULE,
1226 .llseek = default_llseek,
1229 static ssize_t ath10k_read_htt_max_amsdu_ampdu(struct file *file,
1230 char __user *user_buf,
1231 size_t count, loff_t *ppos)
1233 struct ath10k *ar = file->private_data;
1238 mutex_lock(&ar->conf_mutex);
1240 amsdu = ar->htt.max_num_amsdu;
1241 ampdu = ar->htt.max_num_ampdu;
1242 mutex_unlock(&ar->conf_mutex);
1244 len = scnprintf(buf, sizeof(buf), "%u %u\n", amsdu, ampdu);
1246 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1249 static ssize_t ath10k_write_htt_max_amsdu_ampdu(struct file *file,
1250 const char __user *user_buf,
1251 size_t count, loff_t *ppos)
1253 struct ath10k *ar = file->private_data;
1256 unsigned int amsdu, ampdu;
1258 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
1260 /* make sure that buf is null terminated */
1261 buf[sizeof(buf) - 1] = 0;
1263 res = sscanf(buf, "%u %u", &amsdu, &du);
1268 mutex_lock(&ar->conf_mutex);
1270 res = ath10k_htt_h2t_aggr_cfg_msg(&ar->htt, ampdu, amsdu);
1275 ar->htt.max_num_amsdu = amsdu;
1276 ar->htt.max_num_ampdu = ampdu;
1279 mutex_unlock(&ar->conf_mutex);
1283 static const struct file_operations fops_htt_max_amsdu_ampdu = {
1284 .read = ath10k_read_htt_max_amsdu_ampdu,
1285 .write = ath10k_write_htt_max_amsdu_ampdu,
1286 .open = simple_open,
1287 .owner = THIS_MODULE,
1288 .llseek = default_llseek,
1291 static ssize_t ath10k_read_fw_dbglog(struct file *file,
1292 char __user *user_buf,
1293 size_t count, loff_t *ppos)
1295 struct ath10k *ar = file->private_data;
1299 len = scnprintf(buf, sizeof(buf), "0x%16llx %u\n",
1300 ar->debug.fw_dbglog_mask, ar->debug.fw_dbglog_level);
1302 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1305 static ssize_t ath10k_write_fw_dbglog(struct file *file,
1306 const char __user *user_buf,
1307 size_t count, loff_t *ppos)
1309 struct ath10k *ar = file->private_data;
1312 unsigned int log_level;
1315 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
1317 /* make sure that buf is null terminated */
1318 buf[sizeof(buf) - 1] = 0;
1320 ret = sscanf(buf, "%llx %u", &mask, &log_level);
1326 /* default if user did not specify */
1327 log_level = ATH10K_DBGLOG_LEVEL_WARN;
1329 mutex_lock(&ar->conf_mutex);
1331 ar->debug.fw_dbglog_mask = mask;
1332 ar->debug.fw_dbglog_level = log_level;
1334 if (ar->state == ATH10K_STATE_ON) {
1335 ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask,
1336 ar->debug.fw_dbglog_level);
1338 ath10k_warn(ar, "dbglog cfg failed from debugfs: %d\n",
1347 mutex_unlock(&ar->conf_mutex);
1352 /* TODO: Would be nice to always support ethtool stats, would need to
1353 * move the stats storage out of ath10k_debug, or always have ath10k_debug
1354 * struct available..
1357 /* This generally cooresponds to the debugfs fw_stats file */
1358 static const char ath10k_gstrings_stats[][ETH_GSTRING_LEN] = {
1368 "d_tx_power", /* in .5 dbM I think */
1369 "d_rx_crc_err", /* fcs_bad */
1371 "d_tx_mpdus_queued",
1373 "d_tx_msdu_dropped",
1376 "d_tx_ppdu_hw_queued",
1378 "d_tx_fifo_underrun",
1381 "d_tx_excessive_retries",
1383 "d_tx_dropped_sw_retries",
1384 "d_tx_illegal_rate",
1385 "d_tx_continuous_xretries",
1387 "d_tx_mpdu_txop_limit",
1389 "d_rx_mid_ppdu_route_change",
1391 "d_rx_extra_frags_ring0",
1392 "d_rx_extra_frags_ring1",
1393 "d_rx_extra_frags_ring2",
1394 "d_rx_extra_frags_ring3",
1400 "d_rx_phy_err_drops",
1401 "d_rx_mpdu_errors", /* FCS, MIC, ENC */
1403 "d_fw_warm_reset_count",
1404 "d_fw_cold_reset_count",
1407 #define ATH10K_SSTATS_LEN ARRAY_SIZE(ath10k_gstrings_stats)
1409 void ath10k_debug_get_et_strings(struct ieee80211_hw *hw,
1410 struct ieee80211_vif *vif,
1413 if (sset == ETH_SS_STATS)
1414 memcpy(data, *ath10k_gstrings_stats,
1415 sizeof(ath10k_gstrings_stats));
1418 int ath10k_debug_get_et_sset_count(struct ieee80211_hw *hw,
1419 struct ieee80211_vif *vif, int sset)
1421 if (sset == ETH_SS_STATS)
1422 return ATH10K_SSTATS_LEN;
1427 void ath10k_debug_get_et_stats(struct ieee80211_hw *hw,
1428 struct ieee80211_vif *vif,
1429 struct ethtool_stats *stats, u64 *data)
1431 struct ath10k *ar = hw->priv;
1432 static const struct ath10k_fw_stats_pdev zero_stats = {};
1433 const struct ath10k_fw_stats_pdev *pdev_stats;
1436 mutex_lock(&ar->conf_mutex);
1438 if (ar->state == ATH10K_STATE_ON) {
1439 ret = ath10k_debug_fw_stats_request(ar);
1441 /* just print a warning and try to use older results */
1443 "failed to get fw stats for ethtool: %d\n",
1448 pdev_stats = list_first_entry_or_null(&ar->debug.fw_stats.pdevs,
1449 struct ath10k_fw_stats_pdev,
1452 /* no results available so just return zeroes */
1453 pdev_stats = &zero_stats;
1456 spin_lock_bh(&ar->data_lock);
1458 data[i++] = pdev_stats->hw_reaped; /* ppdu reaped */
1459 data[i++] = 0; /* tx bytes */
1460 data[i++] = pdev_stats->htt_mpdus;
1461 data[i++] = 0; /* rx bytes */
1462 data[i++] = pdev_stats->ch_noise_floor;
1463 data[i++] = pdev_stats->cycle_count;
1464 data[i++] = pdev_stats->phy_err_count;
1465 data[i++] = pdev_stats->rts_bad;
1466 data[i++] = pdev_stats->rts_good;
1467 data[i++] = pdev_stats->chan_tx_power;
1468 data[i++] = pdev_stats->fcs_bad;
1469 data[i++] = pdev_stats->no_beacons;
1470 data[i++] = pdev_stats->mpdu_enqued;
1471 data[i++] = pdev_stats->msdu_enqued;
1472 data[i++] = pdev_stats->wmm_drop;
1473 data[i++] = pdev_stats->local_enqued;
1474 data[i++] = pdev_stats->local_freed;
1475 data[i++] = pdev_stats->hw_queued;
1476 data[i++] = pdev_stats->hw_reaped;
1477 data[i++] = pdev_stats->underrun;
1478 data[i++] = pdev_stats->tx_abort;
1479 data[i++] = pdev_stats->mpdus_requed;
1480 data[i++] = pdev_stats->tx_ko;
1481 data[i++] = pdev_stats->data_rc;
1482 data[i++] = pdev_stats->sw_retry_failure;
1483 data[i++] = pdev_stats->illgl_rate_phy_err;
1484 data[i++] = pdev_stats->pdev_cont_xretry;
1485 data[i++] = pdev_stats->pdev_tx_timeout;
1486 data[i++] = pdev_stats->txop_ovf;
1487 data[i++] = pdev_stats->pdev_resets;
1488 data[i++] = pdev_stats->mid_ppdu_route_change;
1489 data[i++] = pdev_stats->status_rcvd;
1490 data[i++] = pdev_stats->r0_frags;
1491 data[i++] = pdev_stats->r1_frags;
1492 data[i++] = pdev_stats->r2_frags;
1493 data[i++] = pdev_stats->r3_frags;
1494 data[i++] = pdev_stats->htt_msdus;
1495 data[i++] = pdev_stats->htt_mpdus;
1496 data[i++] = pdev_stats->loc_msdus;
1497 data[i++] = pdev_stats->loc_mpdus;
1498 data[i++] = pdev_stats->phy_errs;
1499 data[i++] = pdev_stats->phy_err_drop;
1500 data[i++] = pdev_stats->mpdu_errs;
1501 data[i++] = ar->stats.fw_crash_counter;
1502 data[i++] = ar->stats.fw_warm_reset_counter;
1503 data[i++] = ar->stats.fw_cold_reset_counter;
1505 spin_unlock_bh(&ar->data_lock);
1507 mutex_unlock(&ar->conf_mutex);
1509 WARN_ON(i != ATH10K_SSTATS_LEN);
1512 static const struct file_operations fops_fw_dbglog = {
1513 .read = ath10k_read_fw_dbglog,
1514 .write = ath10k_write_fw_dbglog,
1515 .open = simple_open,
1516 .owner = THIS_MODULE,
1517 .llseek = default_llseek,
1520 static int ath10k_debug_cal_data_fetch(struct ath10k *ar)
1526 lockdep_assert_held(&ar->conf_mutex);
1528 if (WARN_ON(ar->hw_params.cal_data_len > ATH10K_DEBUG_CAL_DATA_LEN))
1531 hi_addr = host_interest_item_address(HI_ITEM(hi_board_data));
1533 ret = ath10k_hif_diag_read(ar, hi_addr, &addr, sizeof(addr));
1535 ath10k_warn(ar, "failed to read hi_board_data address: %d\n",
1540 ret = ath10k_hif_diag_read(ar, le32_to_cpu(addr), ar->debug.cal_data,
1541 ar->hw_params.cal_data_len);
1543 ath10k_warn(ar, "failed to read calibration data: %d\n", ret);
1550 static int ath10k_debug_cal_data_open(struct inode *inode, struct file *file)
1552 struct ath10k *ar = inode->i_private;
1554 mutex_lock(&ar->conf_mutex);
1556 if (ar->state == ATH10K_STATE_ON ||
1557 ar->state == ATH10K_STATE_UTF) {
1558 ath10k_debug_cal_data_fetch(ar);
1561 file->private_data = ar;
1562 mutex_unlock(&ar->conf_mutex);
1567 static ssize_t ath10k_debug_cal_data_read(struct file *file,
1568 char __user *user_buf,
1569 size_t count, loff_t *ppos)
1571 struct ath10k *ar = file->private_data;
1573 mutex_lock(&ar->conf_mutex);
1575 count = simple_read_from_buffer(user_buf, count, ppos,
1577 ar->hw_params.cal_data_len);
1579 mutex_unlock(&ar->conf_mutex);
1584 static ssize_t ath10k_write_ani_enable(struct file *file,
1585 const char __user *user_buf,
1586 size_t count, loff_t *ppos)
1588 struct ath10k *ar = file->private_data;
1592 if (kstrtou8_from_user(user_buf, count, 0, &enable))
1595 mutex_lock(&ar->conf_mutex);
1597 if (ar->ani_enabled == enable) {
1602 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->ani_enable,
1605 ath10k_warn(ar, "ani_enable failed from debugfs: %d\n", ret);
1608 ar->ani_enabled = enable;
1613 mutex_unlock(&ar->conf_mutex);
1618 static ssize_t ath10k_read_ani_enable(struct file *file, char __user *user_buf,
1619 size_t count, loff_t *ppos)
1621 struct ath10k *ar = file->private_data;
1625 len = scnprintf(buf, sizeof(buf), "%d\n", ar->ani_enabled);
1627 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1630 static const struct file_operations fops_ani_enable = {
1631 .read = ath10k_read_ani_enable,
1632 .write = ath10k_write_ani_enable,
1633 .open = simple_open,
1634 .owner = THIS_MODULE,
1635 .llseek = default_llseek,
1638 static const struct file_operations fops_cal_data = {
1639 .open = ath10k_debug_cal_data_open,
1640 .read = ath10k_debug_cal_data_read,
1641 .owner = THIS_MODULE,
1642 .llseek = default_llseek,
1645 static ssize_t ath10k_read_nf_cal_period(struct file *file,
1646 char __user *user_buf,
1647 size_t count, loff_t *ppos)
1649 struct ath10k *ar = file->private_data;
1653 len = scnprintf(buf, sizeof(buf), "%d\n", ar->debug.nf_cal_period);
1655 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1658 static ssize_t ath10k_write_nf_cal_period(struct file *file,
1659 const char __user *user_buf,
1660 size_t count, loff_t *ppos)
1662 struct ath10k *ar = file->private_data;
1663 unsigned long period;
1666 ret = kstrtoul_from_user(user_buf, count, 0, &period);
1670 if (period > WMI_PDEV_PARAM_CAL_PERIOD_MAX)
1673 /* there's no way to switch back to the firmware default */
1677 mutex_lock(&ar->conf_mutex);
1679 ar->debug.nf_cal_period = period;
1681 if (ar->state != ATH10K_STATE_ON) {
1682 /* firmware is not running, nothing else to do */
1687 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->cal_period,
1688 ar->debug.nf_cal_period);
1690 ath10k_warn(ar, "cal period cfg failed from debugfs: %d\n",
1698 mutex_unlock(&ar->conf_mutex);
1703 static const struct file_operations fops_nf_cal_period = {
1704 .read = ath10k_read_nf_cal_period,
1705 .write = ath10k_write_nf_cal_period,
1706 .open = simple_open,
1707 .owner = THIS_MODULE,
1708 .llseek = default_llseek,
1711 #define ATH10K_TPC_CONFIG_BUF_SIZE (1024 * 1024)
1713 static int ath10k_debug_tpc_stats_request(struct ath10k *ar)
1716 unsigned long time_left;
1718 lockdep_assert_held(&ar->conf_mutex);
1720 reinit_completion(&ar->debug.tpc_complete);
1722 ret = ath10k_wmi_pdev_get_tpc_config(ar, WMI_TPC_CONFIG_PARAM);
1724 ath10k_warn(ar, "failed to request tpc config: %d\n", ret);
1728 time_left = wait_for_completion_timeout(&ar->debug.tpc_complete,
1736 void ath10k_debug_tpc_stats_process(struct ath10k *ar,
1737 struct ath10k_tpc_stats *tpc_stats)
1739 spin_lock_bh(&ar->data_lock);
1741 kfree(ar->debug.tpc_stats);
1742 ar->debug.tpc_stats = tpc_stats;
1743 complete(&ar->debug.tpc_complete);
1745 spin_unlock_bh(&ar->data_lock);
1748 static void ath10k_tpc_stats_print(struct ath10k_tpc_stats *tpc_stats,
1749 unsigned int j, char *buf, size_t *len)
1753 static const char table_str[][5] = { "CDD",
1756 static const char pream_str[][6] = { "CCK",
1765 buf_len = ATH10K_TPC_CONFIG_BUF_SIZE;
1766 *len += scnprintf(buf + *len, buf_len - *len,
1767 "********************************\n");
1768 *len += scnprintf(buf + *len, buf_len - *len,
1769 "******************* %s POWER TABLE ****************\n",
1771 *len += scnprintf(buf + *len, buf_len - *len,
1772 "********************************\n");
1773 *len += scnprintf(buf + *len, buf_len - *len,
1774 "No. Preamble Rate_code tpc_value1 tpc_value2 tpc_value3\n");
1776 for (i = 0; i < tpc_stats->rate_max; i++) {
1777 *len += scnprintf(buf + *len, buf_len - *len,
1778 "%8d %s 0x%2x %s\n", i,
1779 pream_str[tpc_stats->tpc_table[j].pream_idx[i]],
1780 tpc_stats->tpc_table[j].rate_code[i],
1781 tpc_stats->tpc_table[j].tpc_value[i]);
1784 *len += scnprintf(buf + *len, buf_len - *len,
1785 "***********************************\n");
1788 static void ath10k_tpc_stats_fill(struct ath10k *ar,
1789 struct ath10k_tpc_stats *tpc_stats,
1793 size_t len, buf_len;
1796 buf_len = ATH10K_TPC_CONFIG_BUF_SIZE;
1798 spin_lock_bh(&ar->data_lock);
1801 ath10k_warn(ar, "failed to get tpc stats\n");
1805 len += scnprintf(buf + len, buf_len - len, "\n");
1806 len += scnprintf(buf + len, buf_len - len,
1807 "*************************************\n");
1808 len += scnprintf(buf + len, buf_len - len,
1809 "TPC config for channel %4d mode %d\n",
1810 tpc_stats->chan_freq,
1811 tpc_stats->phy_mode);
1812 len += scnprintf(buf + len, buf_len - len,
1813 "*************************************\n");
1814 len += scnprintf(buf + len, buf_len - len,
1815 "CTL = 0x%2x Reg. Domain = %2d\n",
1817 tpc_stats->reg_domain);
1818 len += scnprintf(buf + len, buf_len - len,
1819 "Antenna Gain = %2d Reg. Max Antenna Gain = %2d\n",
1820 tpc_stats->twice_antenna_gain,
1821 tpc_stats->twice_antenna_reduction);
1822 len += scnprintf(buf + len, buf_len - len,
1823 "Power Limit = %2d Reg. Max Power = %2d\n",
1824 tpc_stats->power_limit,
1825 tpc_stats->twice_max_rd_power / 2);
1826 len += scnprintf(buf + len, buf_len - len,
1827 "Num tx chains = %2d Num supported rates = %2d\n",
1828 tpc_stats->num_tx_chain,
1829 tpc_stats->rate_max);
1831 for (j = 0; j < WMI_TPC_FLAG; j++) {
1833 case WMI_TPC_TABLE_TYPE_CDD:
1834 if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) {
1835 len += scnprintf(buf + len, buf_len - len,
1836 "CDD not supported\n");
1840 ath10k_tpc_stats_print(tpc_stats, j, buf, &len);
1842 case WMI_TPC_TABLE_TYPE_STBC:
1843 if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) {
1844 len += scnprintf(buf + len, buf_len - len,
1845 "STBC not supported\n");
1849 ath10k_tpc_stats_print(tpc_stats, j, buf, &len);
1851 case WMI_TPC_TABLE_TYPE_TXBF:
1852 if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) {
1853 len += scnprintf(buf + len, buf_len - len,
1854 "TXBF not supported\n***************************\n");
1858 ath10k_tpc_stats_print(tpc_stats, j, buf, &len);
1861 len += scnprintf(buf + len, buf_len - len,
1868 spin_unlock_bh(&ar->data_lock);
1876 static int ath10k_tpc_stats_open(struct inode *inode, struct file *file)
1878 struct ath10k *ar = inode->i_private;
1882 mutex_lock(&ar->conf_mutex);
1884 if (ar->state != ATH10K_STATE_ON) {
1889 buf = vmalloc(ATH10K_TPC_CONFIG_BUF_SIZE);
1895 ret = ath10k_debug_tpc_stats_request(ar);
1897 ath10k_warn(ar, "failed to request tpc config stats: %d\n",
1902 ath10k_tpc_stats_fill(ar, ar->debug.tpc_stats, buf);
1903 file->private_data = buf;
1905 mutex_unlock(&ar->conf_mutex);
1912 mutex_unlock(&ar->conf_mutex);
1916 static int ath10k_tpc_stats_release(struct inode *inode, struct file *file)
1918 vfree(file->private_data);
1923 static ssize_t ath10k_tpc_stats_read(struct file *file, char __user *user_buf,
1924 size_t count, loff_t *ppos)
1926 const char *buf = file->private_data;
1927 size_t len = strlen(buf);
1929 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1932 static const struct file_operations fops_tpc_stats = {
1933 .open = ath10k_tpc_stats_open,
1934 .release = ath10k_tpc_stats_release,
1935 .read = ath10k_tpc_stats_read,
1936 .owner = THIS_MODULE,
1937 .llseek = default_llseek,
1940 int ath10k_debug_start(struct ath10k *ar)
1944 lockdep_assert_held(&ar->conf_mutex);
1946 ret = ath10k_debug_htt_stats_req(ar);
1948 /* continue normally anyway, this isn't serious */
1949 ath10k_warn(ar, "failed to start htt stats workqueue: %d\n",
1952 if (ar->debug.fw_dbglog_mask) {
1953 ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask,
1954 ATH10K_DBGLOG_LEVEL_WARN);
1957 ath10k_warn(ar, "failed to enable dbglog during start: %d",
1961 if (ar->debug.pktlog_filter) {
1962 ret = ath10k_wmi_pdev_pktlog_enable(ar,
1963 ar->debug.pktlog_filter);
1967 "failed to enable pktlog filter %x: %d\n",
1968 ar->debug.pktlog_filter, ret);
1970 ret = ath10k_wmi_pdev_pktlog_disable(ar);
1973 ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
1976 if (ar->debug.nf_cal_period) {
1977 ret = ath10k_wmi_pdev_set_param(ar,
1978 ar->wmi.pdev_param->cal_period,
1979 ar->debug.nf_cal_period);
1982 ath10k_warn(ar, "cal period cfg failed from debug start: %d\n",
1989 void ath10k_debug_stop(struct ath10k *ar)
1991 lockdep_assert_held(&ar->conf_mutex);
1993 ath10k_debug_cal_data_fetch(ar);
1995 /* Must not use _sync to avoid deadlock, we do that in
1996 * ath10k_debug_destroy(). The check for htt_stats_mask is to avoid
1997 * warning from del_timer().
1999 if (ar->debug.htt_stats_mask != 0)
2000 cancel_delayed_work(&ar->debug.htt_stats_dwork);
2002 ath10k_wmi_pdev_pktlog_disable(ar);
2005 static ssize_t ath10k_write_simulate_radar(struct file *file,
2006 const char __user *user_buf,
2007 size_t count, loff_t *ppos)
2009 struct ath10k *ar = file->private_data;
2010 struct ath10k_vif *arvif;
2012 /* Just check for for the first vif alone, as all the vifs will be
2013 * sharing the same channel and if the channel is disabled, all the
2014 * vifs will share the same 'is_started' state.
2016 arvif = list_first_entry(&ar->arvifs, typeof(*arvif), list);
2017 if (!arvif->is_started)
2020 ieee80211_radar_detected(ar->hw);
2025 static const struct file_operations fops_simulate_radar = {
2026 .write = ath10k_write_simulate_radar,
2027 .open = simple_open,
2028 .owner = THIS_MODULE,
2029 .llseek = default_llseek,
2032 #define ATH10K_DFS_STAT(s, p) (\
2033 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
2034 ar->debug.dfs_stats.p))
2036 #define ATH10K_DFS_POOL_STAT(s, p) (\
2037 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
2038 ar->debug.dfs_pool_stats.p))
2040 static ssize_t ath10k_read_dfs_stats(struct file *file, char __user *user_buf,
2041 size_t count, loff_t *ppos)
2043 int retval = 0, len = 0;
2044 const int size = 8000;
2045 struct ath10k *ar = file->private_data;
2048 buf = kzalloc(size, GFP_KERNEL);
2052 if (!ar->dfs_detector) {
2053 len += scnprintf(buf + len, size - len, "DFS not enabled\n");
2057 ar->debug.dfs_pool_stats =
2058 ar->dfs_detector->get_stats(ar->dfs_detector);
2060 len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n");
2062 ATH10K_DFS_STAT("reported phy errors", phy_errors);
2063 ATH10K_DFS_STAT("pulse events reported", pulses_total);
2064 ATH10K_DFS_STAT("DFS pulses detected", pulses_detected);
2065 ATH10K_DFS_STAT("DFS pulses discarded", pulses_discarded);
2066 ATH10K_DFS_STAT("Radars detected", radar_detected);
2068 len += scnprintf(buf + len, size - len, "Global Pool statistics:\n");
2069 ATH10K_DFS_POOL_STAT("Pool references", pool_reference);
2070 ATH10K_DFS_POOL_STAT("Pulses allocated", pulse_allocated);
2071 ATH10K_DFS_POOL_STAT("Pulses alloc error", pulse_alloc_error);
2072 ATH10K_DFS_POOL_STAT("Pulses in use", pulse_used);
2073 ATH10K_DFS_POOL_STAT("Seqs. allocated", pseq_allocated);
2074 ATH10K_DFS_POOL_STAT("Seqs. alloc error", pseq_alloc_error);
2075 ATH10K_DFS_POOL_STAT("Seqs. in use", pseq_used);
2081 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
2087 static const struct file_operations fops_dfs_stats = {
2088 .read = ath10k_read_dfs_stats,
2089 .open = simple_open,
2090 .owner = THIS_MODULE,
2091 .llseek = default_llseek,
2094 static ssize_t ath10k_write_pktlog_filter(struct file *file,
2095 const char __user *ubuf,
2096 size_t count, loff_t *ppos)
2098 struct ath10k *ar = file->private_data;
2102 if (kstrtouint_from_user(ubuf, count, 0, &filter))
2105 mutex_lock(&ar->conf_mutex);
2107 if (ar->state != ATH10K_STATE_ON) {
2108 ar->debug.pktlog_filter = filter;
2113 if (filter == ar->debug.pktlog_filter) {
2119 ret = ath10k_wmi_pdev_pktlog_enable(ar, filter);
2121 ath10k_warn(ar, "failed to enable pktlog filter %x: %d\n",
2122 ar->debug.pktlog_filter, ret);
2126 ret = ath10k_wmi_pdev_pktlog_disable(ar);
2128 ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
2133 ar->debug.pktlog_filter = filter;
2137 mutex_unlock(&ar->conf_mutex);
2141 static ssize_t ath10k_read_pktlog_filter(struct file *file, char __user *ubuf,
2142 size_t count, loff_t *ppos)
2145 struct ath10k *ar = file->private_data;
2148 mutex_lock(&ar->conf_mutex);
2149 len = scnprintf(buf, sizeof(buf) - len, "%08x\n",
2150 ar->debug.pktlog_filter);
2151 mutex_unlock(&ar->conf_mutex);
2153 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
2156 static const struct file_operations fops_pktlog_filter = {
2157 .read = ath10k_read_pktlog_filter,
2158 .write = ath10k_write_pktlog_filter,
2162 static ssize_t ath10k_write_quiet_period(struct file *file,
2163 const char __user *ubuf,
2164 size_t count, loff_t *ppos)
2166 struct ath10k *ar = file->private_data;
2169 if (kstrtouint_from_user(ubuf, count, 0, &period))
2172 if (period < ATH10K_QUIET_PERIOD_MIN) {
2173 ath10k_warn(ar, "Quiet period %u can not be lesser than 25ms\n",
2177 mutex_lock(&ar->conf_mutex);
2178 ar->thermal.quiet_period = period;
2179 ath10k_thermal_set_throttling(ar);
2180 mutex_unlock(&ar->conf_mutex);
2185 static ssize_t ath10k_read_quiet_period(struct file *file, char __user *ubuf,
2186 size_t count, loff_t *ppos)
2189 struct ath10k *ar = file->private_data;
2192 mutex_lock(&ar->conf_mutex);
2193 len = scnprintf(buf, sizeof(buf) - len, "%d\n",
2194 ar->thermal.quiet_period);
2195 mutex_unlock(&ar->conf_mutex);
2197 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
2200 static const struct file_operations fops_quiet_period = {
2201 .read = ath10k_read_quiet_period,
2202 .write = ath10k_write_quiet_period,
2206 static ssize_t ath10k_write_btcoex(struct file *file,
2207 const char __user *ubuf,
2208 size_t count, loff_t *ppos)
2210 struct ath10k *ar = file->private_data;
2217 buf_size = min(count, (sizeof(buf) - 1));
2218 if (copy_from_user(buf, ubuf, buf_size))
2221 buf[buf_size] = '\0';
2223 if (strtobool(buf, &val) != 0)
2226 mutex_lock(&ar->conf_mutex);
2228 if (ar->state != ATH10K_STATE_ON &&
2229 ar->state != ATH10K_STATE_RESTARTED) {
2234 if (!(test_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags) ^ val)) {
2239 pdev_param = ar->wmi.pdev_param->enable_btcoex;
2240 if (test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
2241 ar->running_fw->fw_file.fw_features)) {
2242 ret = ath10k_wmi_pdev_set_param(ar, pdev_param, val);
2244 ath10k_warn(ar, "failed to enable btcoex: %d\n", ret);
2249 ath10k_info(ar, "restarting firmware due to btcoex change");
2250 queue_work(ar->workqueue, &ar->restart_work);
2254 set_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
2256 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
2261 mutex_unlock(&ar->conf_mutex);
2266 static ssize_t ath10k_read_btcoex(struct file *file, char __user *ubuf,
2267 size_t count, loff_t *ppos)
2270 struct ath10k *ar = file->private_data;
2273 mutex_lock(&ar->conf_mutex);
2274 len = scnprintf(buf, sizeof(buf) - len, "%d\n",
2275 test_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags));
2276 mutex_unlock(&ar->conf_mutex);
2278 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
2281 static const struct file_operations fops_btcoex = {
2282 .read = ath10k_read_btcoex,
2283 .write = ath10k_write_btcoex,
2287 static ssize_t ath10k_write_peer_stats(struct file *file,
2288 const char __user *ubuf,
2289 size_t count, loff_t *ppos)
2291 struct ath10k *ar = file->private_data;
2297 buf_size = min(count, (sizeof(buf) - 1));
2298 if (copy_from_user(buf, ubuf, buf_size))
2301 buf[buf_size] = '\0';
2303 if (strtobool(buf, &val) != 0)
2306 mutex_lock(&ar->conf_mutex);
2308 if (ar->state != ATH10K_STATE_ON &&
2309 ar->state != ATH10K_STATE_RESTARTED) {
2314 if (!(test_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags) ^ val)) {
2320 set_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags);
2322 clear_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags);
2324 ath10k_info(ar, "restarting firmware due to Peer stats change");
2326 queue_work(ar->workqueue, &ar->restart_work);
2330 mutex_unlock(&ar->conf_mutex);
2334 static ssize_t ath10k_read_peer_stats(struct file *file, char __user *ubuf,
2335 size_t count, loff_t *ppos)
2339 struct ath10k *ar = file->private_data;
2342 mutex_lock(&ar->conf_mutex);
2343 len = scnprintf(buf, sizeof(buf) - len, "%d\n",
2344 test_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags));
2345 mutex_unlock(&ar->conf_mutex);
2347 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
2350 static const struct file_operations fops_peer_stats = {
2351 .read = ath10k_read_peer_stats,
2352 .write = ath10k_write_peer_stats,
2356 static ssize_t ath10k_debug_fw_checksums_read(struct file *file,
2357 char __user *user_buf,
2358 size_t count, loff_t *ppos)
2360 struct ath10k *ar = file->private_data;
2361 size_t len = 0, buf_len = 4096;
2365 buf = kzalloc(buf_len, GFP_KERNEL);
2369 mutex_lock(&ar->conf_mutex);
2371 len += scnprintf(buf + len, buf_len - len,
2372 "firmware-N.bin\t\t%08x\n",
2373 crc32_le(0, ar->normal_mode_fw.fw_file.firmware->data,
2374 ar->normal_mode_fw.fw_file.firmware->size));
2375 len += scnprintf(buf + len, buf_len - len,
2376 "athwlan\t\t\t%08x\n",
2377 crc32_le(0, ar->normal_mode_fw.fw_file.firmware_data,
2378 ar->normal_mode_fw.fw_file.firmware_len));
2379 len += scnprintf(buf + len, buf_len - len,
2381 crc32_le(0, ar->normal_mode_fw.fw_file.otp_data,
2382 ar->normal_mode_fw.fw_file.otp_len));
2383 len += scnprintf(buf + len, buf_len - len,
2384 "codeswap\t\t%08x\n",
2385 crc32_le(0, ar->normal_mode_fw.fw_file.codeswap_data,
2386 ar->normal_mode_fw.fw_file.codeswap_len));
2387 len += scnprintf(buf + len, buf_len - len,
2388 "board-N.bin\t\t%08x\n",
2389 crc32_le(0, ar->normal_mode_fw.board->data,
2390 ar->normal_mode_fw.board->size));
2391 len += scnprintf(buf + len, buf_len - len,
2392 "board\t\t\t%08x\n",
2393 crc32_le(0, ar->normal_mode_fw.board_data,
2394 ar->normal_mode_fw.board_len));
2396 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
2398 mutex_unlock(&ar->conf_mutex);
2404 static const struct file_operations fops_fw_checksums = {
2405 .read = ath10k_debug_fw_checksums_read,
2406 .open = simple_open,
2407 .owner = THIS_MODULE,
2408 .llseek = default_llseek,
2411 int ath10k_debug_create(struct ath10k *ar)
2413 ar->debug.fw_crash_data = vzalloc(sizeof(*ar->debug.fw_crash_data));
2414 if (!ar->debug.fw_crash_data)
2417 ar->debug.cal_data = vzalloc(ATH10K_DEBUG_CAL_DATA_LEN);
2418 if (!ar->debug.cal_data)
2421 INIT_LIST_HEAD(&ar->debug.fw_stats.pdevs);
2422 INIT_LIST_HEAD(&ar->debug.fw_stats.vdevs);
2423 INIT_LIST_HEAD(&ar->debug.fw_stats.peers);
2424 INIT_LIST_HEAD(&ar->debug.fw_stats.peers_extd);
2429 void ath10k_debug_destroy(struct ath10k *ar)
2431 vfree(ar->debug.fw_crash_data);
2432 ar->debug.fw_crash_data = NULL;
2434 vfree(ar->debug.cal_data);
2435 ar->debug.cal_data = NULL;
2437 ath10k_debug_fw_stats_reset(ar);
2439 kfree(ar->debug.tpc_stats);
2442 int ath10k_debug_register(struct ath10k *ar)
2444 ar->debug.debugfs_phy = debugfs_create_dir("ath10k",
2445 ar->hw->wiphy->debugfsdir);
2446 if (IS_ERR_OR_NULL(ar->debug.debugfs_phy)) {
2447 if (IS_ERR(ar->debug.debugfs_phy))
2448 return PTR_ERR(ar->debug.debugfs_phy);
2453 INIT_DELAYED_WORK(&ar->debug.htt_stats_dwork,
2454 ath10k_debug_htt_stats_dwork);
2456 init_completion(&ar->debug.tpc_complete);
2457 init_completion(&ar->debug.fw_stats_complete);
2459 debugfs_create_file("fw_stats", 0400, ar->debug.debugfs_phy, ar,
2462 debugfs_create_file("fw_reset_stats", 0400, ar->debug.debugfs_phy, ar,
2463 &fops_fw_reset_stats);
2465 debugfs_create_file("wmi_services", 0400, ar->debug.debugfs_phy, ar,
2466 &fops_wmi_services);
2468 debugfs_create_file("simulate_fw_crash", 0600, ar->debug.debugfs_phy, ar,
2469 &fops_simulate_fw_crash);
2471 debugfs_create_file("fw_crash_dump", 0400, ar->debug.debugfs_phy, ar,
2472 &fops_fw_crash_dump);
2474 debugfs_create_file("reg_addr", 0600, ar->debug.debugfs_phy, ar,
2477 debugfs_create_file("reg_value", 0600, ar->debug.debugfs_phy, ar,
2480 debugfs_create_file("mem_value", 0600, ar->debug.debugfs_phy, ar,
2483 debugfs_create_file("chip_id", 0400, ar->debug.debugfs_phy, ar,
2486 debugfs_create_file("htt_stats_mask", 0600, ar->debug.debugfs_phy, ar,
2487 &fops_htt_stats_mask);
2489 debugfs_create_file("htt_max_amsdu_ampdu", 0600, ar->debug.debugfs_phy, ar,
2490 &fops_htt_max_amsdu_ampdu);
2492 debugfs_create_file("fw_dbglog", 0600, ar->debug.debugfs_phy, ar,
2495 debugfs_create_file("cal_data", 0400, ar->debug.debugfs_phy, ar,
2498 debugfs_create_file("ani_enable", 0600, ar->debug.debugfs_phy, ar,
2501 debugfs_create_file("nf_cal_period", 0600, ar->debug.debugfs_phy, ar,
2502 &fops_nf_cal_period);
2504 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) {
2505 debugfs_create_file("dfs_simulate_radar", 0200, ar->debug.debugfs_phy,
2506 ar, &fops_simulate_radar);
2508 debugfs_create_bool("dfs_block_radar_events", 0200,
2509 ar->debug.debugfs_phy,
2510 &ar->dfs_block_radar_events);
2512 debugfs_create_file("dfs_stats", 0400, ar->debug.debugfs_phy, ar,
2516 debugfs_create_file("pktlog_filter", 0644, ar->debug.debugfs_phy, ar,
2517 &fops_pktlog_filter);
2519 debugfs_create_file("quiet_period", 0644, ar->debug.debugfs_phy, ar,
2520 &fops_quiet_period);
2522 debugfs_create_file("tpc_stats", 0400, ar->debug.debugfs_phy, ar,
2525 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map))
2526 debugfs_create_file("btcoex", 0644, ar->debug.debugfs_phy, ar,
2529 if (test_bit(WMI_SERVICE_PEER_STATS, ar->wmi.svc_map))
2530 debugfs_create_file("peer_stats", 0644, ar->debug.debugfs_phy, ar,
2533 debugfs_create_file("fw_checksums", 0400, ar->debug.debugfs_phy, ar,
2534 &fops_fw_checksums);
2539 void ath10k_debug_unregister(struct ath10k *ar)
2541 cancel_delayed_work_sync(&ar->debug.htt_stats_dwork);
2544 #endif /* CONFIG_ATH10K_DEBUGFS */
2546 #ifdef CONFIG_ATH10K_DEBUG
2547 void ath10k_dbg(struct ath10k *ar, enum ath10k_debug_mask mask,
2548 const char *fmt, ...)
2550 struct va_format vaf;
2553 va_start(args, fmt);
2558 if (ath10k_debug_mask & mask)
2559 dev_printk(KERN_DEBUG, ar->dev, "%pV", &vaf);
2561 trace_ath10k_log_dbg(ar, mask, &vaf);
2565 EXPORT_SYMBOL(ath10k_dbg);
2567 void ath10k_dbg_dump(struct ath10k *ar,
2568 enum ath10k_debug_mask mask,
2569 const char *msg, const char *prefix,
2570 const void *buf, size_t len)
2576 if (ath10k_debug_mask & mask) {
2578 ath10k_dbg(ar, mask, "%s\n", msg);
2580 for (ptr = buf; (ptr - buf) < len; ptr += 16) {
2582 linebuflen += scnprintf(linebuf + linebuflen,
2583 sizeof(linebuf) - linebuflen,
2585 (prefix ? prefix : ""),
2586 (unsigned int)(ptr - buf));
2587 hex_dump_to_buffer(ptr, len - (ptr - buf), 16, 1,
2588 linebuf + linebuflen,
2589 sizeof(linebuf) - linebuflen, true);
2590 dev_printk(KERN_DEBUG, ar->dev, "%s\n", linebuf);
2594 /* tracing code doesn't like null strings :/ */
2595 trace_ath10k_log_dbg_dump(ar, msg ? msg : "", prefix ? prefix : "",
2598 EXPORT_SYMBOL(ath10k_dbg_dump);
2600 #endif /* CONFIG_ATH10K_DEBUG */