2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <linux/module.h>
19 #include <linux/debugfs.h>
20 #include <linux/vmalloc.h>
21 #include <linux/utsname.h>
22 #include <linux/crc32.h>
23 #include <linux/firmware.h>
31 #define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000
33 #define ATH10K_FW_CRASH_DUMP_VERSION 1
36 * enum ath10k_fw_crash_dump_type - types of data in the dump file
37 * @ATH10K_FW_CRASH_DUMP_REGDUMP: Register crash dump in binary format
39 enum ath10k_fw_crash_dump_type {
40 ATH10K_FW_CRASH_DUMP_REGISTERS = 0,
42 ATH10K_FW_CRASH_DUMP_MAX,
45 struct ath10k_tlv_dump_data {
46 /* see ath10k_fw_crash_dump_type above */
52 /* pad to 32-bit boundaries as needed */
56 struct ath10k_dump_file_data {
57 /* dump file information */
59 /* "ATH10K-FW-DUMP" */
64 /* file dump version */
67 /* some info we can get from ath10k struct that might help */
73 /* 0 for now, in place for later hardware */
76 __le32 target_version;
77 __le32 fw_version_major;
78 __le32 fw_version_minor;
79 __le32 fw_version_release;
80 __le32 fw_version_build;
81 __le32 phy_capability;
82 __le32 hw_min_tx_power;
83 __le32 hw_max_tx_power;
88 /* firmware version string */
89 char fw_ver[ETHTOOL_FWVERS_LEN];
91 /* Kernel related information */
93 /* time-of-day stamp */
96 /* time-of-day stamp, nano-seconds */
99 /* LINUX_VERSION_CODE */
100 __le32 kernel_ver_code;
102 /* VERMAGIC_STRING */
105 /* room for growth w/out changing binary format */
108 /* struct ath10k_tlv_dump_data + more */
112 void ath10k_info(struct ath10k *ar, const char *fmt, ...)
114 struct va_format vaf = {
121 dev_info(ar->dev, "%pV", &vaf);
122 trace_ath10k_log_info(ar, &vaf);
125 EXPORT_SYMBOL(ath10k_info);
127 void ath10k_debug_print_hwfw_info(struct ath10k *ar)
129 char fw_features[128] = {};
131 ath10k_core_get_fw_features_str(ar, fw_features, sizeof(fw_features));
133 ath10k_info(ar, "%s target 0x%08x chip_id 0x%08x sub %04x:%04x",
137 ar->id.subsystem_vendor, ar->id.subsystem_device);
139 ath10k_info(ar, "kconfig debug %d debugfs %d tracing %d dfs %d testmode %d\n",
140 config_enabled(CONFIG_ATH10K_DEBUG),
141 config_enabled(CONFIG_ATH10K_DEBUGFS),
142 config_enabled(CONFIG_ATH10K_TRACING),
143 config_enabled(CONFIG_ATH10K_DFS_CERTIFIED),
144 config_enabled(CONFIG_NL80211_TESTMODE));
146 ath10k_info(ar, "firmware ver %s api %d features %s crc32 %08x\n",
147 ar->hw->wiphy->fw_version,
150 crc32_le(0, ar->firmware->data, ar->firmware->size));
153 void ath10k_debug_print_board_info(struct ath10k *ar)
157 if (ar->id.bmi_ids_valid)
158 scnprintf(boardinfo, sizeof(boardinfo), "%d:%d",
159 ar->id.bmi_chip_id, ar->id.bmi_board_id);
161 scnprintf(boardinfo, sizeof(boardinfo), "N/A");
163 ath10k_info(ar, "board_file api %d bmi_id %s crc32 %08x",
166 crc32_le(0, ar->board->data, ar->board->size));
169 void ath10k_debug_print_boot_info(struct ath10k *ar)
171 ath10k_info(ar, "htt-ver %d.%d wmi-op %d htt-op %d cal %s max-sta %d raw %d hwcrypto %d\n",
172 ar->htt.target_version_major,
173 ar->htt.target_version_minor,
176 ath10k_cal_mode_str(ar->cal_mode),
177 ar->max_num_stations,
178 test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags),
179 !test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags));
182 void ath10k_print_driver_info(struct ath10k *ar)
184 ath10k_debug_print_hwfw_info(ar);
185 ath10k_debug_print_board_info(ar);
186 ath10k_debug_print_boot_info(ar);
188 EXPORT_SYMBOL(ath10k_print_driver_info);
190 void ath10k_err(struct ath10k *ar, const char *fmt, ...)
192 struct va_format vaf = {
199 dev_err(ar->dev, "%pV", &vaf);
200 trace_ath10k_log_err(ar, &vaf);
203 EXPORT_SYMBOL(ath10k_err);
205 void ath10k_warn(struct ath10k *ar, const char *fmt, ...)
207 struct va_format vaf = {
214 dev_warn_ratelimited(ar->dev, "%pV", &vaf);
215 trace_ath10k_log_warn(ar, &vaf);
219 EXPORT_SYMBOL(ath10k_warn);
221 #ifdef CONFIG_ATH10K_DEBUGFS
223 static ssize_t ath10k_read_wmi_services(struct file *file,
224 char __user *user_buf,
225 size_t count, loff_t *ppos)
227 struct ath10k *ar = file->private_data;
229 unsigned int len = 0, buf_len = 4096;
235 buf = kzalloc(buf_len, GFP_KERNEL);
239 mutex_lock(&ar->conf_mutex);
244 spin_lock_bh(&ar->data_lock);
245 for (i = 0; i < WMI_SERVICE_MAX; i++) {
246 enabled = test_bit(i, ar->wmi.svc_map);
247 name = wmi_service_name(i);
251 len += scnprintf(buf + len, buf_len - len,
252 "%-40s %s (bit %d)\n",
253 "unknown", "enabled", i);
258 len += scnprintf(buf + len, buf_len - len,
260 name, enabled ? "enabled" : "-");
262 spin_unlock_bh(&ar->data_lock);
264 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
266 mutex_unlock(&ar->conf_mutex);
272 static const struct file_operations fops_wmi_services = {
273 .read = ath10k_read_wmi_services,
275 .owner = THIS_MODULE,
276 .llseek = default_llseek,
279 static void ath10k_debug_fw_stats_pdevs_free(struct list_head *head)
281 struct ath10k_fw_stats_pdev *i, *tmp;
283 list_for_each_entry_safe(i, tmp, head, list) {
289 static void ath10k_debug_fw_stats_vdevs_free(struct list_head *head)
291 struct ath10k_fw_stats_vdev *i, *tmp;
293 list_for_each_entry_safe(i, tmp, head, list) {
299 static void ath10k_debug_fw_stats_peers_free(struct list_head *head)
301 struct ath10k_fw_stats_peer *i, *tmp;
303 list_for_each_entry_safe(i, tmp, head, list) {
309 static void ath10k_debug_fw_stats_reset(struct ath10k *ar)
311 spin_lock_bh(&ar->data_lock);
312 ar->debug.fw_stats_done = false;
313 ath10k_debug_fw_stats_pdevs_free(&ar->debug.fw_stats.pdevs);
314 ath10k_debug_fw_stats_vdevs_free(&ar->debug.fw_stats.vdevs);
315 ath10k_debug_fw_stats_peers_free(&ar->debug.fw_stats.peers);
316 spin_unlock_bh(&ar->data_lock);
319 void ath10k_debug_fw_stats_process(struct ath10k *ar, struct sk_buff *skb)
321 struct ath10k_fw_stats stats = {};
322 bool is_start, is_started, is_end;
327 INIT_LIST_HEAD(&stats.pdevs);
328 INIT_LIST_HEAD(&stats.vdevs);
329 INIT_LIST_HEAD(&stats.peers);
331 spin_lock_bh(&ar->data_lock);
332 ret = ath10k_wmi_pull_fw_stats(ar, skb, &stats);
334 ath10k_warn(ar, "failed to pull fw stats: %d\n", ret);
338 /* Stat data may exceed htc-wmi buffer limit. In such case firmware
339 * splits the stats data and delivers it in a ping-pong fashion of
340 * request cmd-update event.
342 * However there is no explicit end-of-data. Instead start-of-data is
343 * used as an implicit one. This works as follows:
344 * a) discard stat update events until one with pdev stats is
345 * delivered - this skips session started at end of (b)
346 * b) consume stat update events until another one with pdev stats is
347 * delivered which is treated as end-of-data and is itself discarded
350 if (ar->debug.fw_stats_done) {
351 ath10k_warn(ar, "received unsolicited stats update event\n");
355 num_peers = ath10k_wmi_fw_stats_num_peers(&ar->debug.fw_stats.peers);
356 num_vdevs = ath10k_wmi_fw_stats_num_vdevs(&ar->debug.fw_stats.vdevs);
357 is_start = (list_empty(&ar->debug.fw_stats.pdevs) &&
358 !list_empty(&stats.pdevs));
359 is_end = (!list_empty(&ar->debug.fw_stats.pdevs) &&
360 !list_empty(&stats.pdevs));
363 list_splice_tail_init(&stats.pdevs, &ar->debug.fw_stats.pdevs);
366 ar->debug.fw_stats_done = true;
368 is_started = !list_empty(&ar->debug.fw_stats.pdevs);
370 if (is_started && !is_end) {
371 if (num_peers >= ATH10K_MAX_NUM_PEER_IDS) {
372 /* Although this is unlikely impose a sane limit to
373 * prevent firmware from DoS-ing the host.
375 ath10k_warn(ar, "dropping fw peer stats\n");
379 if (num_vdevs >= BITS_PER_LONG) {
380 ath10k_warn(ar, "dropping fw vdev stats\n");
384 list_splice_tail_init(&stats.peers, &ar->debug.fw_stats.peers);
385 list_splice_tail_init(&stats.vdevs, &ar->debug.fw_stats.vdevs);
388 complete(&ar->debug.fw_stats_complete);
391 /* In some cases lists have been spliced and cleared. Free up
392 * resources if that is not the case.
394 ath10k_debug_fw_stats_pdevs_free(&stats.pdevs);
395 ath10k_debug_fw_stats_vdevs_free(&stats.vdevs);
396 ath10k_debug_fw_stats_peers_free(&stats.peers);
398 spin_unlock_bh(&ar->data_lock);
401 static int ath10k_debug_fw_stats_request(struct ath10k *ar)
403 unsigned long timeout, time_left;
406 lockdep_assert_held(&ar->conf_mutex);
408 timeout = jiffies + msecs_to_jiffies(1 * HZ);
410 ath10k_debug_fw_stats_reset(ar);
413 if (time_after(jiffies, timeout))
416 reinit_completion(&ar->debug.fw_stats_complete);
418 ret = ath10k_wmi_request_stats(ar, ar->fw_stats_req_mask);
420 ath10k_warn(ar, "could not request stats (%d)\n", ret);
425 wait_for_completion_timeout(&ar->debug.fw_stats_complete,
430 spin_lock_bh(&ar->data_lock);
431 if (ar->debug.fw_stats_done) {
432 spin_unlock_bh(&ar->data_lock);
435 spin_unlock_bh(&ar->data_lock);
441 static int ath10k_fw_stats_open(struct inode *inode, struct file *file)
443 struct ath10k *ar = inode->i_private;
447 mutex_lock(&ar->conf_mutex);
449 if (ar->state != ATH10K_STATE_ON) {
454 buf = vmalloc(ATH10K_FW_STATS_BUF_SIZE);
460 ret = ath10k_debug_fw_stats_request(ar);
462 ath10k_warn(ar, "failed to request fw stats: %d\n", ret);
466 ret = ath10k_wmi_fw_stats_fill(ar, &ar->debug.fw_stats, buf);
468 ath10k_warn(ar, "failed to fill fw stats: %d\n", ret);
472 file->private_data = buf;
474 mutex_unlock(&ar->conf_mutex);
481 mutex_unlock(&ar->conf_mutex);
485 static int ath10k_fw_stats_release(struct inode *inode, struct file *file)
487 vfree(file->private_data);
492 static ssize_t ath10k_fw_stats_read(struct file *file, char __user *user_buf,
493 size_t count, loff_t *ppos)
495 const char *buf = file->private_data;
496 unsigned int len = strlen(buf);
498 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
501 static const struct file_operations fops_fw_stats = {
502 .open = ath10k_fw_stats_open,
503 .release = ath10k_fw_stats_release,
504 .read = ath10k_fw_stats_read,
505 .owner = THIS_MODULE,
506 .llseek = default_llseek,
509 static ssize_t ath10k_debug_fw_reset_stats_read(struct file *file,
510 char __user *user_buf,
511 size_t count, loff_t *ppos)
513 struct ath10k *ar = file->private_data;
514 int ret, len, buf_len;
518 buf = kmalloc(buf_len, GFP_KERNEL);
522 spin_lock_bh(&ar->data_lock);
525 len += scnprintf(buf + len, buf_len - len,
526 "fw_crash_counter\t\t%d\n", ar->stats.fw_crash_counter);
527 len += scnprintf(buf + len, buf_len - len,
528 "fw_warm_reset_counter\t\t%d\n",
529 ar->stats.fw_warm_reset_counter);
530 len += scnprintf(buf + len, buf_len - len,
531 "fw_cold_reset_counter\t\t%d\n",
532 ar->stats.fw_cold_reset_counter);
534 spin_unlock_bh(&ar->data_lock);
536 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
543 static const struct file_operations fops_fw_reset_stats = {
545 .read = ath10k_debug_fw_reset_stats_read,
546 .owner = THIS_MODULE,
547 .llseek = default_llseek,
550 /* This is a clean assert crash in firmware. */
551 static int ath10k_debug_fw_assert(struct ath10k *ar)
553 struct wmi_vdev_install_key_cmd *cmd;
556 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd) + 16);
560 cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
561 memset(cmd, 0, sizeof(*cmd));
563 /* big enough number so that firmware asserts */
564 cmd->vdev_id = __cpu_to_le32(0x7ffe);
566 return ath10k_wmi_cmd_send(ar, skb,
567 ar->wmi.cmd->vdev_install_key_cmdid);
570 static ssize_t ath10k_read_simulate_fw_crash(struct file *file,
571 char __user *user_buf,
572 size_t count, loff_t *ppos)
575 "To simulate firmware crash write one of the keywords to this file:\n"
576 "`soft` - this will send WMI_FORCE_FW_HANG_ASSERT to firmware if FW supports that command.\n"
577 "`hard` - this will send to firmware command with illegal parameters causing firmware crash.\n"
578 "`assert` - this will send special illegal parameter to firmware to cause assert failure and crash.\n"
579 "`hw-restart` - this will simply queue hw restart without fw/hw actually crashing.\n";
581 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
584 /* Simulate firmware crash:
585 * 'soft': Call wmi command causing firmware hang. This firmware hang is
586 * recoverable by warm firmware reset.
587 * 'hard': Force firmware crash by setting any vdev parameter for not allowed
588 * vdev id. This is hard firmware crash because it is recoverable only by cold
591 static ssize_t ath10k_write_simulate_fw_crash(struct file *file,
592 const char __user *user_buf,
593 size_t count, loff_t *ppos)
595 struct ath10k *ar = file->private_data;
599 mutex_lock(&ar->conf_mutex);
601 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
603 /* make sure that buf is null terminated */
604 buf[sizeof(buf) - 1] = 0;
606 if (ar->state != ATH10K_STATE_ON &&
607 ar->state != ATH10K_STATE_RESTARTED) {
612 /* drop the possible '\n' from the end */
613 if (buf[count - 1] == '\n') {
618 if (!strcmp(buf, "soft")) {
619 ath10k_info(ar, "simulating soft firmware crash\n");
620 ret = ath10k_wmi_force_fw_hang(ar, WMI_FORCE_FW_HANG_ASSERT, 0);
621 } else if (!strcmp(buf, "hard")) {
622 ath10k_info(ar, "simulating hard firmware crash\n");
623 /* 0x7fff is vdev id, and it is always out of range for all
624 * firmware variants in order to force a firmware crash.
626 ret = ath10k_wmi_vdev_set_param(ar, 0x7fff,
627 ar->wmi.vdev_param->rts_threshold,
629 } else if (!strcmp(buf, "assert")) {
630 ath10k_info(ar, "simulating firmware assert crash\n");
631 ret = ath10k_debug_fw_assert(ar);
632 } else if (!strcmp(buf, "hw-restart")) {
633 ath10k_info(ar, "user requested hw restart\n");
634 queue_work(ar->workqueue, &ar->restart_work);
642 ath10k_warn(ar, "failed to simulate firmware crash: %d\n", ret);
649 mutex_unlock(&ar->conf_mutex);
653 static const struct file_operations fops_simulate_fw_crash = {
654 .read = ath10k_read_simulate_fw_crash,
655 .write = ath10k_write_simulate_fw_crash,
657 .owner = THIS_MODULE,
658 .llseek = default_llseek,
661 static ssize_t ath10k_read_chip_id(struct file *file, char __user *user_buf,
662 size_t count, loff_t *ppos)
664 struct ath10k *ar = file->private_data;
668 len = scnprintf(buf, sizeof(buf), "0x%08x\n", ar->chip_id);
670 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
673 static const struct file_operations fops_chip_id = {
674 .read = ath10k_read_chip_id,
676 .owner = THIS_MODULE,
677 .llseek = default_llseek,
680 struct ath10k_fw_crash_data *
681 ath10k_debug_get_new_fw_crash_data(struct ath10k *ar)
683 struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data;
685 lockdep_assert_held(&ar->data_lock);
687 crash_data->crashed_since_read = true;
688 uuid_le_gen(&crash_data->uuid);
689 getnstimeofday(&crash_data->timestamp);
693 EXPORT_SYMBOL(ath10k_debug_get_new_fw_crash_data);
695 static struct ath10k_dump_file_data *ath10k_build_dump_file(struct ath10k *ar)
697 struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data;
698 struct ath10k_dump_file_data *dump_data;
699 struct ath10k_tlv_dump_data *dump_tlv;
700 int hdr_len = sizeof(*dump_data);
701 unsigned int len, sofar = 0;
705 len += sizeof(*dump_tlv) + sizeof(crash_data->registers);
709 /* This is going to get big when we start dumping FW RAM and such,
710 * so go ahead and use vmalloc.
716 spin_lock_bh(&ar->data_lock);
718 if (!crash_data->crashed_since_read) {
719 spin_unlock_bh(&ar->data_lock);
724 dump_data = (struct ath10k_dump_file_data *)(buf);
725 strlcpy(dump_data->df_magic, "ATH10K-FW-DUMP",
726 sizeof(dump_data->df_magic));
727 dump_data->len = cpu_to_le32(len);
729 dump_data->version = cpu_to_le32(ATH10K_FW_CRASH_DUMP_VERSION);
731 memcpy(dump_data->uuid, &crash_data->uuid, sizeof(dump_data->uuid));
732 dump_data->chip_id = cpu_to_le32(ar->chip_id);
733 dump_data->bus_type = cpu_to_le32(0);
734 dump_data->target_version = cpu_to_le32(ar->target_version);
735 dump_data->fw_version_major = cpu_to_le32(ar->fw_version_major);
736 dump_data->fw_version_minor = cpu_to_le32(ar->fw_version_minor);
737 dump_data->fw_version_release = cpu_to_le32(ar->fw_version_release);
738 dump_data->fw_version_build = cpu_to_le32(ar->fw_version_build);
739 dump_data->phy_capability = cpu_to_le32(ar->phy_capability);
740 dump_data->hw_min_tx_power = cpu_to_le32(ar->hw_min_tx_power);
741 dump_data->hw_max_tx_power = cpu_to_le32(ar->hw_max_tx_power);
742 dump_data->ht_cap_info = cpu_to_le32(ar->ht_cap_info);
743 dump_data->vht_cap_info = cpu_to_le32(ar->vht_cap_info);
744 dump_data->num_rf_chains = cpu_to_le32(ar->num_rf_chains);
746 strlcpy(dump_data->fw_ver, ar->hw->wiphy->fw_version,
747 sizeof(dump_data->fw_ver));
749 dump_data->kernel_ver_code = 0;
750 strlcpy(dump_data->kernel_ver, init_utsname()->release,
751 sizeof(dump_data->kernel_ver));
753 dump_data->tv_sec = cpu_to_le64(crash_data->timestamp.tv_sec);
754 dump_data->tv_nsec = cpu_to_le64(crash_data->timestamp.tv_nsec);
756 /* Gather crash-dump */
757 dump_tlv = (struct ath10k_tlv_dump_data *)(buf + sofar);
758 dump_tlv->type = cpu_to_le32(ATH10K_FW_CRASH_DUMP_REGISTERS);
759 dump_tlv->tlv_len = cpu_to_le32(sizeof(crash_data->registers));
760 memcpy(dump_tlv->tlv_data, &crash_data->registers,
761 sizeof(crash_data->registers));
762 sofar += sizeof(*dump_tlv) + sizeof(crash_data->registers);
764 ar->debug.fw_crash_data->crashed_since_read = false;
766 spin_unlock_bh(&ar->data_lock);
771 static int ath10k_fw_crash_dump_open(struct inode *inode, struct file *file)
773 struct ath10k *ar = inode->i_private;
774 struct ath10k_dump_file_data *dump;
776 dump = ath10k_build_dump_file(ar);
780 file->private_data = dump;
785 static ssize_t ath10k_fw_crash_dump_read(struct file *file,
786 char __user *user_buf,
787 size_t count, loff_t *ppos)
789 struct ath10k_dump_file_data *dump_file = file->private_data;
791 return simple_read_from_buffer(user_buf, count, ppos,
793 le32_to_cpu(dump_file->len));
796 static int ath10k_fw_crash_dump_release(struct inode *inode,
799 vfree(file->private_data);
804 static const struct file_operations fops_fw_crash_dump = {
805 .open = ath10k_fw_crash_dump_open,
806 .read = ath10k_fw_crash_dump_read,
807 .release = ath10k_fw_crash_dump_release,
808 .owner = THIS_MODULE,
809 .llseek = default_llseek,
812 static ssize_t ath10k_reg_addr_read(struct file *file,
813 char __user *user_buf,
814 size_t count, loff_t *ppos)
816 struct ath10k *ar = file->private_data;
818 unsigned int len = 0;
821 mutex_lock(&ar->conf_mutex);
822 reg_addr = ar->debug.reg_addr;
823 mutex_unlock(&ar->conf_mutex);
825 len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n", reg_addr);
827 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
830 static ssize_t ath10k_reg_addr_write(struct file *file,
831 const char __user *user_buf,
832 size_t count, loff_t *ppos)
834 struct ath10k *ar = file->private_data;
838 ret = kstrtou32_from_user(user_buf, count, 0, ®_addr);
842 if (!IS_ALIGNED(reg_addr, 4))
845 mutex_lock(&ar->conf_mutex);
846 ar->debug.reg_addr = reg_addr;
847 mutex_unlock(&ar->conf_mutex);
852 static const struct file_operations fops_reg_addr = {
853 .read = ath10k_reg_addr_read,
854 .write = ath10k_reg_addr_write,
856 .owner = THIS_MODULE,
857 .llseek = default_llseek,
860 static ssize_t ath10k_reg_value_read(struct file *file,
861 char __user *user_buf,
862 size_t count, loff_t *ppos)
864 struct ath10k *ar = file->private_data;
867 u32 reg_addr, reg_val;
870 mutex_lock(&ar->conf_mutex);
872 if (ar->state != ATH10K_STATE_ON &&
873 ar->state != ATH10K_STATE_UTF) {
878 reg_addr = ar->debug.reg_addr;
880 reg_val = ath10k_hif_read32(ar, reg_addr);
881 len = scnprintf(buf, sizeof(buf), "0x%08x:0x%08x\n", reg_addr, reg_val);
883 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
886 mutex_unlock(&ar->conf_mutex);
891 static ssize_t ath10k_reg_value_write(struct file *file,
892 const char __user *user_buf,
893 size_t count, loff_t *ppos)
895 struct ath10k *ar = file->private_data;
896 u32 reg_addr, reg_val;
899 mutex_lock(&ar->conf_mutex);
901 if (ar->state != ATH10K_STATE_ON &&
902 ar->state != ATH10K_STATE_UTF) {
907 reg_addr = ar->debug.reg_addr;
909 ret = kstrtou32_from_user(user_buf, count, 0, ®_val);
913 ath10k_hif_write32(ar, reg_addr, reg_val);
918 mutex_unlock(&ar->conf_mutex);
923 static const struct file_operations fops_reg_value = {
924 .read = ath10k_reg_value_read,
925 .write = ath10k_reg_value_write,
927 .owner = THIS_MODULE,
928 .llseek = default_llseek,
931 static ssize_t ath10k_mem_value_read(struct file *file,
932 char __user *user_buf,
933 size_t count, loff_t *ppos)
935 struct ath10k *ar = file->private_data;
945 mutex_lock(&ar->conf_mutex);
947 buf = vmalloc(count);
953 if (ar->state != ATH10K_STATE_ON &&
954 ar->state != ATH10K_STATE_UTF) {
959 ret = ath10k_hif_diag_read(ar, *ppos, buf, count);
961 ath10k_warn(ar, "failed to read address 0x%08x via diagnose window fnrom debugfs: %d\n",
966 ret = copy_to_user(user_buf, buf, count);
978 mutex_unlock(&ar->conf_mutex);
983 static ssize_t ath10k_mem_value_write(struct file *file,
984 const char __user *user_buf,
985 size_t count, loff_t *ppos)
987 struct ath10k *ar = file->private_data;
997 mutex_lock(&ar->conf_mutex);
999 buf = vmalloc(count);
1005 if (ar->state != ATH10K_STATE_ON &&
1006 ar->state != ATH10K_STATE_UTF) {
1011 ret = copy_from_user(buf, user_buf, count);
1017 ret = ath10k_hif_diag_write(ar, *ppos, buf, count);
1019 ath10k_warn(ar, "failed to write address 0x%08x via diagnose window from debugfs: %d\n",
1029 mutex_unlock(&ar->conf_mutex);
1034 static const struct file_operations fops_mem_value = {
1035 .read = ath10k_mem_value_read,
1036 .write = ath10k_mem_value_write,
1037 .open = simple_open,
1038 .owner = THIS_MODULE,
1039 .llseek = default_llseek,
1042 static int ath10k_debug_htt_stats_req(struct ath10k *ar)
1047 lockdep_assert_held(&ar->conf_mutex);
1049 if (ar->debug.htt_stats_mask == 0)
1050 /* htt stats are disabled */
1053 if (ar->state != ATH10K_STATE_ON)
1056 cookie = get_jiffies_64();
1058 ret = ath10k_htt_h2t_stats_req(&ar->htt, ar->debug.htt_stats_mask,
1061 ath10k_warn(ar, "failed to send htt stats request: %d\n", ret);
1065 queue_delayed_work(ar->workqueue, &ar->debug.htt_stats_dwork,
1066 msecs_to_jiffies(ATH10K_DEBUG_HTT_STATS_INTERVAL));
1071 static void ath10k_debug_htt_stats_dwork(struct work_struct *work)
1073 struct ath10k *ar = container_of(work, struct ath10k,
1074 debug.htt_stats_dwork.work);
1076 mutex_lock(&ar->conf_mutex);
1078 ath10k_debug_htt_stats_req(ar);
1080 mutex_unlock(&ar->conf_mutex);
1083 static ssize_t ath10k_read_htt_stats_mask(struct file *file,
1084 char __user *user_buf,
1085 size_t count, loff_t *ppos)
1087 struct ath10k *ar = file->private_data;
1091 len = scnprintf(buf, sizeof(buf), "%lu\n", ar->debug.htt_stats_mask);
1093 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1096 static ssize_t ath10k_write_htt_stats_mask(struct file *file,
1097 const char __user *user_buf,
1098 size_t count, loff_t *ppos)
1100 struct ath10k *ar = file->private_data;
1104 ret = kstrtoul_from_user(user_buf, count, 0, &mask);
1108 /* max 8 bit masks (for now) */
1112 mutex_lock(&ar->conf_mutex);
1114 ar->debug.htt_stats_mask = mask;
1116 ret = ath10k_debug_htt_stats_req(ar);
1123 mutex_unlock(&ar->conf_mutex);
1128 static const struct file_operations fops_htt_stats_mask = {
1129 .read = ath10k_read_htt_stats_mask,
1130 .write = ath10k_write_htt_stats_mask,
1131 .open = simple_open,
1132 .owner = THIS_MODULE,
1133 .llseek = default_llseek,
1136 static ssize_t ath10k_read_htt_max_amsdu_ampdu(struct file *file,
1137 char __user *user_buf,
1138 size_t count, loff_t *ppos)
1140 struct ath10k *ar = file->private_data;
1142 u8 amsdu = 3, ampdu = 64;
1145 mutex_lock(&ar->conf_mutex);
1147 amsdu = ar->htt.max_num_amsdu;
1148 ampdu = ar->htt.max_num_ampdu;
1149 mutex_unlock(&ar->conf_mutex);
1151 len = scnprintf(buf, sizeof(buf), "%u %u\n", amsdu, ampdu);
1153 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1156 static ssize_t ath10k_write_htt_max_amsdu_ampdu(struct file *file,
1157 const char __user *user_buf,
1158 size_t count, loff_t *ppos)
1160 struct ath10k *ar = file->private_data;
1163 unsigned int amsdu, ampdu;
1165 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
1167 /* make sure that buf is null terminated */
1168 buf[sizeof(buf) - 1] = 0;
1170 res = sscanf(buf, "%u %u", &amsdu, &du);
1175 mutex_lock(&ar->conf_mutex);
1177 res = ath10k_htt_h2t_aggr_cfg_msg(&ar->htt, ampdu, amsdu);
1182 ar->htt.max_num_amsdu = amsdu;
1183 ar->htt.max_num_ampdu = ampdu;
1186 mutex_unlock(&ar->conf_mutex);
1190 static const struct file_operations fops_htt_max_amsdu_ampdu = {
1191 .read = ath10k_read_htt_max_amsdu_ampdu,
1192 .write = ath10k_write_htt_max_amsdu_ampdu,
1193 .open = simple_open,
1194 .owner = THIS_MODULE,
1195 .llseek = default_llseek,
1198 static ssize_t ath10k_read_fw_dbglog(struct file *file,
1199 char __user *user_buf,
1200 size_t count, loff_t *ppos)
1202 struct ath10k *ar = file->private_data;
1206 len = scnprintf(buf, sizeof(buf), "0x%08x %u\n",
1207 ar->debug.fw_dbglog_mask, ar->debug.fw_dbglog_level);
1209 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1212 static ssize_t ath10k_write_fw_dbglog(struct file *file,
1213 const char __user *user_buf,
1214 size_t count, loff_t *ppos)
1216 struct ath10k *ar = file->private_data;
1219 unsigned int log_level, mask;
1221 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
1223 /* make sure that buf is null terminated */
1224 buf[sizeof(buf) - 1] = 0;
1226 ret = sscanf(buf, "%x %u", &mask, &log_level);
1232 /* default if user did not specify */
1233 log_level = ATH10K_DBGLOG_LEVEL_WARN;
1235 mutex_lock(&ar->conf_mutex);
1237 ar->debug.fw_dbglog_mask = mask;
1238 ar->debug.fw_dbglog_level = log_level;
1240 if (ar->state == ATH10K_STATE_ON) {
1241 ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask,
1242 ar->debug.fw_dbglog_level);
1244 ath10k_warn(ar, "dbglog cfg failed from debugfs: %d\n",
1253 mutex_unlock(&ar->conf_mutex);
1258 /* TODO: Would be nice to always support ethtool stats, would need to
1259 * move the stats storage out of ath10k_debug, or always have ath10k_debug
1260 * struct available..
1263 /* This generally cooresponds to the debugfs fw_stats file */
1264 static const char ath10k_gstrings_stats[][ETH_GSTRING_LEN] = {
1274 "d_tx_power", /* in .5 dbM I think */
1275 "d_rx_crc_err", /* fcs_bad */
1277 "d_tx_mpdus_queued",
1279 "d_tx_msdu_dropped",
1282 "d_tx_ppdu_hw_queued",
1284 "d_tx_fifo_underrun",
1287 "d_tx_excessive_retries",
1289 "d_tx_dropped_sw_retries",
1290 "d_tx_illegal_rate",
1291 "d_tx_continuous_xretries",
1293 "d_tx_mpdu_txop_limit",
1295 "d_rx_mid_ppdu_route_change",
1297 "d_rx_extra_frags_ring0",
1298 "d_rx_extra_frags_ring1",
1299 "d_rx_extra_frags_ring2",
1300 "d_rx_extra_frags_ring3",
1306 "d_rx_phy_err_drops",
1307 "d_rx_mpdu_errors", /* FCS, MIC, ENC */
1309 "d_fw_warm_reset_count",
1310 "d_fw_cold_reset_count",
1313 #define ATH10K_SSTATS_LEN ARRAY_SIZE(ath10k_gstrings_stats)
1315 void ath10k_debug_get_et_strings(struct ieee80211_hw *hw,
1316 struct ieee80211_vif *vif,
1319 if (sset == ETH_SS_STATS)
1320 memcpy(data, *ath10k_gstrings_stats,
1321 sizeof(ath10k_gstrings_stats));
1324 int ath10k_debug_get_et_sset_count(struct ieee80211_hw *hw,
1325 struct ieee80211_vif *vif, int sset)
1327 if (sset == ETH_SS_STATS)
1328 return ATH10K_SSTATS_LEN;
1333 void ath10k_debug_get_et_stats(struct ieee80211_hw *hw,
1334 struct ieee80211_vif *vif,
1335 struct ethtool_stats *stats, u64 *data)
1337 struct ath10k *ar = hw->priv;
1338 static const struct ath10k_fw_stats_pdev zero_stats = {};
1339 const struct ath10k_fw_stats_pdev *pdev_stats;
1342 mutex_lock(&ar->conf_mutex);
1344 if (ar->state == ATH10K_STATE_ON) {
1345 ret = ath10k_debug_fw_stats_request(ar);
1347 /* just print a warning and try to use older results */
1349 "failed to get fw stats for ethtool: %d\n",
1354 pdev_stats = list_first_entry_or_null(&ar->debug.fw_stats.pdevs,
1355 struct ath10k_fw_stats_pdev,
1358 /* no results available so just return zeroes */
1359 pdev_stats = &zero_stats;
1362 spin_lock_bh(&ar->data_lock);
1364 data[i++] = pdev_stats->hw_reaped; /* ppdu reaped */
1365 data[i++] = 0; /* tx bytes */
1366 data[i++] = pdev_stats->htt_mpdus;
1367 data[i++] = 0; /* rx bytes */
1368 data[i++] = pdev_stats->ch_noise_floor;
1369 data[i++] = pdev_stats->cycle_count;
1370 data[i++] = pdev_stats->phy_err_count;
1371 data[i++] = pdev_stats->rts_bad;
1372 data[i++] = pdev_stats->rts_good;
1373 data[i++] = pdev_stats->chan_tx_power;
1374 data[i++] = pdev_stats->fcs_bad;
1375 data[i++] = pdev_stats->no_beacons;
1376 data[i++] = pdev_stats->mpdu_enqued;
1377 data[i++] = pdev_stats->msdu_enqued;
1378 data[i++] = pdev_stats->wmm_drop;
1379 data[i++] = pdev_stats->local_enqued;
1380 data[i++] = pdev_stats->local_freed;
1381 data[i++] = pdev_stats->hw_queued;
1382 data[i++] = pdev_stats->hw_reaped;
1383 data[i++] = pdev_stats->underrun;
1384 data[i++] = pdev_stats->tx_abort;
1385 data[i++] = pdev_stats->mpdus_requed;
1386 data[i++] = pdev_stats->tx_ko;
1387 data[i++] = pdev_stats->data_rc;
1388 data[i++] = pdev_stats->sw_retry_failure;
1389 data[i++] = pdev_stats->illgl_rate_phy_err;
1390 data[i++] = pdev_stats->pdev_cont_xretry;
1391 data[i++] = pdev_stats->pdev_tx_timeout;
1392 data[i++] = pdev_stats->txop_ovf;
1393 data[i++] = pdev_stats->pdev_resets;
1394 data[i++] = pdev_stats->mid_ppdu_route_change;
1395 data[i++] = pdev_stats->status_rcvd;
1396 data[i++] = pdev_stats->r0_frags;
1397 data[i++] = pdev_stats->r1_frags;
1398 data[i++] = pdev_stats->r2_frags;
1399 data[i++] = pdev_stats->r3_frags;
1400 data[i++] = pdev_stats->htt_msdus;
1401 data[i++] = pdev_stats->htt_mpdus;
1402 data[i++] = pdev_stats->loc_msdus;
1403 data[i++] = pdev_stats->loc_mpdus;
1404 data[i++] = pdev_stats->phy_errs;
1405 data[i++] = pdev_stats->phy_err_drop;
1406 data[i++] = pdev_stats->mpdu_errs;
1407 data[i++] = ar->stats.fw_crash_counter;
1408 data[i++] = ar->stats.fw_warm_reset_counter;
1409 data[i++] = ar->stats.fw_cold_reset_counter;
1411 spin_unlock_bh(&ar->data_lock);
1413 mutex_unlock(&ar->conf_mutex);
1415 WARN_ON(i != ATH10K_SSTATS_LEN);
1418 static const struct file_operations fops_fw_dbglog = {
1419 .read = ath10k_read_fw_dbglog,
1420 .write = ath10k_write_fw_dbglog,
1421 .open = simple_open,
1422 .owner = THIS_MODULE,
1423 .llseek = default_llseek,
1426 static int ath10k_debug_cal_data_open(struct inode *inode, struct file *file)
1428 struct ath10k *ar = inode->i_private;
1434 mutex_lock(&ar->conf_mutex);
1436 if (ar->state != ATH10K_STATE_ON &&
1437 ar->state != ATH10K_STATE_UTF) {
1442 buf = vmalloc(QCA988X_CAL_DATA_LEN);
1448 hi_addr = host_interest_item_address(HI_ITEM(hi_board_data));
1450 ret = ath10k_hif_diag_read(ar, hi_addr, &addr, sizeof(addr));
1452 ath10k_warn(ar, "failed to read hi_board_data address: %d\n", ret);
1456 ret = ath10k_hif_diag_read(ar, le32_to_cpu(addr), buf,
1457 QCA988X_CAL_DATA_LEN);
1459 ath10k_warn(ar, "failed to read calibration data: %d\n", ret);
1463 file->private_data = buf;
1465 mutex_unlock(&ar->conf_mutex);
1473 mutex_unlock(&ar->conf_mutex);
1478 static ssize_t ath10k_debug_cal_data_read(struct file *file,
1479 char __user *user_buf,
1480 size_t count, loff_t *ppos)
1482 void *buf = file->private_data;
1484 return simple_read_from_buffer(user_buf, count, ppos,
1485 buf, QCA988X_CAL_DATA_LEN);
1488 static int ath10k_debug_cal_data_release(struct inode *inode,
1491 vfree(file->private_data);
1496 static ssize_t ath10k_write_ani_enable(struct file *file,
1497 const char __user *user_buf,
1498 size_t count, loff_t *ppos)
1500 struct ath10k *ar = file->private_data;
1504 if (kstrtou8_from_user(user_buf, count, 0, &enable))
1507 mutex_lock(&ar->conf_mutex);
1509 if (ar->ani_enabled == enable) {
1514 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->ani_enable,
1517 ath10k_warn(ar, "ani_enable failed from debugfs: %d\n", ret);
1520 ar->ani_enabled = enable;
1525 mutex_unlock(&ar->conf_mutex);
1530 static ssize_t ath10k_read_ani_enable(struct file *file, char __user *user_buf,
1531 size_t count, loff_t *ppos)
1533 struct ath10k *ar = file->private_data;
1537 len = scnprintf(buf, sizeof(buf) - len, "%d\n",
1540 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1543 static const struct file_operations fops_ani_enable = {
1544 .read = ath10k_read_ani_enable,
1545 .write = ath10k_write_ani_enable,
1546 .open = simple_open,
1547 .owner = THIS_MODULE,
1548 .llseek = default_llseek,
1551 static const struct file_operations fops_cal_data = {
1552 .open = ath10k_debug_cal_data_open,
1553 .read = ath10k_debug_cal_data_read,
1554 .release = ath10k_debug_cal_data_release,
1555 .owner = THIS_MODULE,
1556 .llseek = default_llseek,
1559 static ssize_t ath10k_read_nf_cal_period(struct file *file,
1560 char __user *user_buf,
1561 size_t count, loff_t *ppos)
1563 struct ath10k *ar = file->private_data;
1567 len = scnprintf(buf, sizeof(buf), "%d\n",
1568 ar->debug.nf_cal_period);
1570 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1573 static ssize_t ath10k_write_nf_cal_period(struct file *file,
1574 const char __user *user_buf,
1575 size_t count, loff_t *ppos)
1577 struct ath10k *ar = file->private_data;
1578 unsigned long period;
1581 ret = kstrtoul_from_user(user_buf, count, 0, &period);
1585 if (period > WMI_PDEV_PARAM_CAL_PERIOD_MAX)
1588 /* there's no way to switch back to the firmware default */
1592 mutex_lock(&ar->conf_mutex);
1594 ar->debug.nf_cal_period = period;
1596 if (ar->state != ATH10K_STATE_ON) {
1597 /* firmware is not running, nothing else to do */
1602 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->cal_period,
1603 ar->debug.nf_cal_period);
1605 ath10k_warn(ar, "cal period cfg failed from debugfs: %d\n",
1613 mutex_unlock(&ar->conf_mutex);
1618 static const struct file_operations fops_nf_cal_period = {
1619 .read = ath10k_read_nf_cal_period,
1620 .write = ath10k_write_nf_cal_period,
1621 .open = simple_open,
1622 .owner = THIS_MODULE,
1623 .llseek = default_llseek,
1626 #define ATH10K_TPC_CONFIG_BUF_SIZE (1024 * 1024)
1628 static int ath10k_debug_tpc_stats_request(struct ath10k *ar)
1631 unsigned long time_left;
1633 lockdep_assert_held(&ar->conf_mutex);
1635 reinit_completion(&ar->debug.tpc_complete);
1637 ret = ath10k_wmi_pdev_get_tpc_config(ar, WMI_TPC_CONFIG_PARAM);
1639 ath10k_warn(ar, "failed to request tpc config: %d\n", ret);
1643 time_left = wait_for_completion_timeout(&ar->debug.tpc_complete,
1651 void ath10k_debug_tpc_stats_process(struct ath10k *ar,
1652 struct ath10k_tpc_stats *tpc_stats)
1654 spin_lock_bh(&ar->data_lock);
1656 kfree(ar->debug.tpc_stats);
1657 ar->debug.tpc_stats = tpc_stats;
1658 complete(&ar->debug.tpc_complete);
1660 spin_unlock_bh(&ar->data_lock);
1663 static void ath10k_tpc_stats_print(struct ath10k_tpc_stats *tpc_stats,
1664 unsigned int j, char *buf, unsigned int *len)
1666 unsigned int i, buf_len;
1667 static const char table_str[][5] = { "CDD",
1670 static const char pream_str[][6] = { "CCK",
1679 buf_len = ATH10K_TPC_CONFIG_BUF_SIZE;
1680 *len += scnprintf(buf + *len, buf_len - *len,
1681 "********************************\n");
1682 *len += scnprintf(buf + *len, buf_len - *len,
1683 "******************* %s POWER TABLE ****************\n",
1685 *len += scnprintf(buf + *len, buf_len - *len,
1686 "********************************\n");
1687 *len += scnprintf(buf + *len, buf_len - *len,
1688 "No. Preamble Rate_code tpc_value1 tpc_value2 tpc_value3\n");
1690 for (i = 0; i < tpc_stats->rate_max; i++) {
1691 *len += scnprintf(buf + *len, buf_len - *len,
1692 "%8d %s 0x%2x %s\n", i,
1693 pream_str[tpc_stats->tpc_table[j].pream_idx[i]],
1694 tpc_stats->tpc_table[j].rate_code[i],
1695 tpc_stats->tpc_table[j].tpc_value[i]);
1698 *len += scnprintf(buf + *len, buf_len - *len,
1699 "***********************************\n");
1702 static void ath10k_tpc_stats_fill(struct ath10k *ar,
1703 struct ath10k_tpc_stats *tpc_stats,
1706 unsigned int len, j, buf_len;
1709 buf_len = ATH10K_TPC_CONFIG_BUF_SIZE;
1711 spin_lock_bh(&ar->data_lock);
1714 ath10k_warn(ar, "failed to get tpc stats\n");
1718 len += scnprintf(buf + len, buf_len - len, "\n");
1719 len += scnprintf(buf + len, buf_len - len,
1720 "*************************************\n");
1721 len += scnprintf(buf + len, buf_len - len,
1722 "TPC config for channel %4d mode %d\n",
1723 tpc_stats->chan_freq,
1724 tpc_stats->phy_mode);
1725 len += scnprintf(buf + len, buf_len - len,
1726 "*************************************\n");
1727 len += scnprintf(buf + len, buf_len - len,
1728 "CTL = 0x%2x Reg. Domain = %2d\n",
1730 tpc_stats->reg_domain);
1731 len += scnprintf(buf + len, buf_len - len,
1732 "Antenna Gain = %2d Reg. Max Antenna Gain = %2d\n",
1733 tpc_stats->twice_antenna_gain,
1734 tpc_stats->twice_antenna_reduction);
1735 len += scnprintf(buf + len, buf_len - len,
1736 "Power Limit = %2d Reg. Max Power = %2d\n",
1737 tpc_stats->power_limit,
1738 tpc_stats->twice_max_rd_power / 2);
1739 len += scnprintf(buf + len, buf_len - len,
1740 "Num tx chains = %2d Num supported rates = %2d\n",
1741 tpc_stats->num_tx_chain,
1742 tpc_stats->rate_max);
1744 for (j = 0; j < tpc_stats->num_tx_chain ; j++) {
1746 case WMI_TPC_TABLE_TYPE_CDD:
1747 if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) {
1748 len += scnprintf(buf + len, buf_len - len,
1749 "CDD not supported\n");
1753 ath10k_tpc_stats_print(tpc_stats, j, buf, &len);
1755 case WMI_TPC_TABLE_TYPE_STBC:
1756 if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) {
1757 len += scnprintf(buf + len, buf_len - len,
1758 "STBC not supported\n");
1762 ath10k_tpc_stats_print(tpc_stats, j, buf, &len);
1764 case WMI_TPC_TABLE_TYPE_TXBF:
1765 if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) {
1766 len += scnprintf(buf + len, buf_len - len,
1767 "TXBF not supported\n***************************\n");
1771 ath10k_tpc_stats_print(tpc_stats, j, buf, &len);
1774 len += scnprintf(buf + len, buf_len - len,
1781 spin_unlock_bh(&ar->data_lock);
1789 static int ath10k_tpc_stats_open(struct inode *inode, struct file *file)
1791 struct ath10k *ar = inode->i_private;
1795 mutex_lock(&ar->conf_mutex);
1797 if (ar->state != ATH10K_STATE_ON) {
1802 buf = vmalloc(ATH10K_TPC_CONFIG_BUF_SIZE);
1808 ret = ath10k_debug_tpc_stats_request(ar);
1810 ath10k_warn(ar, "failed to request tpc config stats: %d\n",
1815 ath10k_tpc_stats_fill(ar, ar->debug.tpc_stats, buf);
1816 file->private_data = buf;
1818 mutex_unlock(&ar->conf_mutex);
1825 mutex_unlock(&ar->conf_mutex);
1829 static int ath10k_tpc_stats_release(struct inode *inode, struct file *file)
1831 vfree(file->private_data);
1836 static ssize_t ath10k_tpc_stats_read(struct file *file, char __user *user_buf,
1837 size_t count, loff_t *ppos)
1839 const char *buf = file->private_data;
1840 unsigned int len = strlen(buf);
1842 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1845 static const struct file_operations fops_tpc_stats = {
1846 .open = ath10k_tpc_stats_open,
1847 .release = ath10k_tpc_stats_release,
1848 .read = ath10k_tpc_stats_read,
1849 .owner = THIS_MODULE,
1850 .llseek = default_llseek,
1853 int ath10k_debug_start(struct ath10k *ar)
1857 lockdep_assert_held(&ar->conf_mutex);
1859 ret = ath10k_debug_htt_stats_req(ar);
1861 /* continue normally anyway, this isn't serious */
1862 ath10k_warn(ar, "failed to start htt stats workqueue: %d\n",
1865 if (ar->debug.fw_dbglog_mask) {
1866 ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask,
1867 ATH10K_DBGLOG_LEVEL_WARN);
1870 ath10k_warn(ar, "failed to enable dbglog during start: %d",
1874 if (ar->debug.pktlog_filter) {
1875 ret = ath10k_wmi_pdev_pktlog_enable(ar,
1876 ar->debug.pktlog_filter);
1880 "failed to enable pktlog filter %x: %d\n",
1881 ar->debug.pktlog_filter, ret);
1883 ret = ath10k_wmi_pdev_pktlog_disable(ar);
1886 ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
1889 if (ar->debug.nf_cal_period) {
1890 ret = ath10k_wmi_pdev_set_param(ar,
1891 ar->wmi.pdev_param->cal_period,
1892 ar->debug.nf_cal_period);
1895 ath10k_warn(ar, "cal period cfg failed from debug start: %d\n",
1902 void ath10k_debug_stop(struct ath10k *ar)
1904 lockdep_assert_held(&ar->conf_mutex);
1906 /* Must not use _sync to avoid deadlock, we do that in
1907 * ath10k_debug_destroy(). The check for htt_stats_mask is to avoid
1908 * warning from del_timer(). */
1909 if (ar->debug.htt_stats_mask != 0)
1910 cancel_delayed_work(&ar->debug.htt_stats_dwork);
1912 ath10k_wmi_pdev_pktlog_disable(ar);
1915 static ssize_t ath10k_write_simulate_radar(struct file *file,
1916 const char __user *user_buf,
1917 size_t count, loff_t *ppos)
1919 struct ath10k *ar = file->private_data;
1921 ieee80211_radar_detected(ar->hw);
1926 static const struct file_operations fops_simulate_radar = {
1927 .write = ath10k_write_simulate_radar,
1928 .open = simple_open,
1929 .owner = THIS_MODULE,
1930 .llseek = default_llseek,
1933 #define ATH10K_DFS_STAT(s, p) (\
1934 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1935 ar->debug.dfs_stats.p))
1937 #define ATH10K_DFS_POOL_STAT(s, p) (\
1938 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1939 ar->debug.dfs_pool_stats.p))
1941 static ssize_t ath10k_read_dfs_stats(struct file *file, char __user *user_buf,
1942 size_t count, loff_t *ppos)
1944 int retval = 0, len = 0;
1945 const int size = 8000;
1946 struct ath10k *ar = file->private_data;
1949 buf = kzalloc(size, GFP_KERNEL);
1953 if (!ar->dfs_detector) {
1954 len += scnprintf(buf + len, size - len, "DFS not enabled\n");
1958 ar->debug.dfs_pool_stats =
1959 ar->dfs_detector->get_stats(ar->dfs_detector);
1961 len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n");
1963 ATH10K_DFS_STAT("reported phy errors", phy_errors);
1964 ATH10K_DFS_STAT("pulse events reported", pulses_total);
1965 ATH10K_DFS_STAT("DFS pulses detected", pulses_detected);
1966 ATH10K_DFS_STAT("DFS pulses discarded", pulses_discarded);
1967 ATH10K_DFS_STAT("Radars detected", radar_detected);
1969 len += scnprintf(buf + len, size - len, "Global Pool statistics:\n");
1970 ATH10K_DFS_POOL_STAT("Pool references", pool_reference);
1971 ATH10K_DFS_POOL_STAT("Pulses allocated", pulse_allocated);
1972 ATH10K_DFS_POOL_STAT("Pulses alloc error", pulse_alloc_error);
1973 ATH10K_DFS_POOL_STAT("Pulses in use", pulse_used);
1974 ATH10K_DFS_POOL_STAT("Seqs. allocated", pseq_allocated);
1975 ATH10K_DFS_POOL_STAT("Seqs. alloc error", pseq_alloc_error);
1976 ATH10K_DFS_POOL_STAT("Seqs. in use", pseq_used);
1982 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1988 static const struct file_operations fops_dfs_stats = {
1989 .read = ath10k_read_dfs_stats,
1990 .open = simple_open,
1991 .owner = THIS_MODULE,
1992 .llseek = default_llseek,
1995 static ssize_t ath10k_write_pktlog_filter(struct file *file,
1996 const char __user *ubuf,
1997 size_t count, loff_t *ppos)
1999 struct ath10k *ar = file->private_data;
2003 if (kstrtouint_from_user(ubuf, count, 0, &filter))
2006 mutex_lock(&ar->conf_mutex);
2008 if (ar->state != ATH10K_STATE_ON) {
2009 ar->debug.pktlog_filter = filter;
2014 if (filter && (filter != ar->debug.pktlog_filter)) {
2015 ret = ath10k_wmi_pdev_pktlog_enable(ar, filter);
2017 ath10k_warn(ar, "failed to enable pktlog filter %x: %d\n",
2018 ar->debug.pktlog_filter, ret);
2022 ret = ath10k_wmi_pdev_pktlog_disable(ar);
2024 ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
2029 ar->debug.pktlog_filter = filter;
2033 mutex_unlock(&ar->conf_mutex);
2037 static ssize_t ath10k_read_pktlog_filter(struct file *file, char __user *ubuf,
2038 size_t count, loff_t *ppos)
2041 struct ath10k *ar = file->private_data;
2044 mutex_lock(&ar->conf_mutex);
2045 len = scnprintf(buf, sizeof(buf) - len, "%08x\n",
2046 ar->debug.pktlog_filter);
2047 mutex_unlock(&ar->conf_mutex);
2049 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
2052 static const struct file_operations fops_pktlog_filter = {
2053 .read = ath10k_read_pktlog_filter,
2054 .write = ath10k_write_pktlog_filter,
2058 static ssize_t ath10k_write_quiet_period(struct file *file,
2059 const char __user *ubuf,
2060 size_t count, loff_t *ppos)
2062 struct ath10k *ar = file->private_data;
2065 if (kstrtouint_from_user(ubuf, count, 0, &period))
2068 if (period < ATH10K_QUIET_PERIOD_MIN) {
2069 ath10k_warn(ar, "Quiet period %u can not be lesser than 25ms\n",
2073 mutex_lock(&ar->conf_mutex);
2074 ar->thermal.quiet_period = period;
2075 ath10k_thermal_set_throttling(ar);
2076 mutex_unlock(&ar->conf_mutex);
2081 static ssize_t ath10k_read_quiet_period(struct file *file, char __user *ubuf,
2082 size_t count, loff_t *ppos)
2085 struct ath10k *ar = file->private_data;
2088 mutex_lock(&ar->conf_mutex);
2089 len = scnprintf(buf, sizeof(buf) - len, "%d\n",
2090 ar->thermal.quiet_period);
2091 mutex_unlock(&ar->conf_mutex);
2093 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
2096 static const struct file_operations fops_quiet_period = {
2097 .read = ath10k_read_quiet_period,
2098 .write = ath10k_write_quiet_period,
2102 static ssize_t ath10k_write_btcoex(struct file *file,
2103 const char __user *ubuf,
2104 size_t count, loff_t *ppos)
2106 struct ath10k *ar = file->private_data;
2111 buf_size = min(count, (sizeof(buf) - 1));
2112 if (copy_from_user(buf, ubuf, buf_size))
2115 buf[buf_size] = '\0';
2117 if (strtobool(buf, &val) != 0)
2120 mutex_lock(&ar->conf_mutex);
2122 if (!(test_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags) ^ val))
2126 set_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
2128 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
2130 if (ar->state != ATH10K_STATE_ON)
2133 ath10k_info(ar, "restarting firmware due to btcoex change");
2135 queue_work(ar->workqueue, &ar->restart_work);
2138 mutex_unlock(&ar->conf_mutex);
2143 static ssize_t ath10k_read_btcoex(struct file *file, char __user *ubuf,
2144 size_t count, loff_t *ppos)
2147 struct ath10k *ar = file->private_data;
2150 mutex_lock(&ar->conf_mutex);
2151 len = scnprintf(buf, sizeof(buf) - len, "%d\n",
2152 test_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags));
2153 mutex_unlock(&ar->conf_mutex);
2155 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
2158 static const struct file_operations fops_btcoex = {
2159 .read = ath10k_read_btcoex,
2160 .write = ath10k_write_btcoex,
2164 int ath10k_debug_create(struct ath10k *ar)
2166 ar->debug.fw_crash_data = vzalloc(sizeof(*ar->debug.fw_crash_data));
2167 if (!ar->debug.fw_crash_data)
2170 INIT_LIST_HEAD(&ar->debug.fw_stats.pdevs);
2171 INIT_LIST_HEAD(&ar->debug.fw_stats.vdevs);
2172 INIT_LIST_HEAD(&ar->debug.fw_stats.peers);
2177 void ath10k_debug_destroy(struct ath10k *ar)
2179 vfree(ar->debug.fw_crash_data);
2180 ar->debug.fw_crash_data = NULL;
2182 ath10k_debug_fw_stats_reset(ar);
2184 kfree(ar->debug.tpc_stats);
2187 int ath10k_debug_register(struct ath10k *ar)
2189 ar->debug.debugfs_phy = debugfs_create_dir("ath10k",
2190 ar->hw->wiphy->debugfsdir);
2191 if (IS_ERR_OR_NULL(ar->debug.debugfs_phy)) {
2192 if (IS_ERR(ar->debug.debugfs_phy))
2193 return PTR_ERR(ar->debug.debugfs_phy);
2198 INIT_DELAYED_WORK(&ar->debug.htt_stats_dwork,
2199 ath10k_debug_htt_stats_dwork);
2201 init_completion(&ar->debug.tpc_complete);
2202 init_completion(&ar->debug.fw_stats_complete);
2204 debugfs_create_file("fw_stats", S_IRUSR, ar->debug.debugfs_phy, ar,
2207 debugfs_create_file("fw_reset_stats", S_IRUSR, ar->debug.debugfs_phy,
2208 ar, &fops_fw_reset_stats);
2210 debugfs_create_file("wmi_services", S_IRUSR, ar->debug.debugfs_phy, ar,
2211 &fops_wmi_services);
2213 debugfs_create_file("simulate_fw_crash", S_IRUSR | S_IWUSR,
2214 ar->debug.debugfs_phy, ar, &fops_simulate_fw_crash);
2216 debugfs_create_file("fw_crash_dump", S_IRUSR, ar->debug.debugfs_phy,
2217 ar, &fops_fw_crash_dump);
2219 debugfs_create_file("reg_addr", S_IRUSR | S_IWUSR,
2220 ar->debug.debugfs_phy, ar, &fops_reg_addr);
2222 debugfs_create_file("reg_value", S_IRUSR | S_IWUSR,
2223 ar->debug.debugfs_phy, ar, &fops_reg_value);
2225 debugfs_create_file("mem_value", S_IRUSR | S_IWUSR,
2226 ar->debug.debugfs_phy, ar, &fops_mem_value);
2228 debugfs_create_file("chip_id", S_IRUSR, ar->debug.debugfs_phy,
2231 debugfs_create_file("htt_stats_mask", S_IRUSR | S_IWUSR,
2232 ar->debug.debugfs_phy, ar, &fops_htt_stats_mask);
2234 debugfs_create_file("htt_max_amsdu_ampdu", S_IRUSR | S_IWUSR,
2235 ar->debug.debugfs_phy, ar,
2236 &fops_htt_max_amsdu_ampdu);
2238 debugfs_create_file("fw_dbglog", S_IRUSR | S_IWUSR,
2239 ar->debug.debugfs_phy, ar, &fops_fw_dbglog);
2241 debugfs_create_file("cal_data", S_IRUSR, ar->debug.debugfs_phy,
2242 ar, &fops_cal_data);
2244 debugfs_create_file("ani_enable", S_IRUSR | S_IWUSR,
2245 ar->debug.debugfs_phy, ar, &fops_ani_enable);
2247 debugfs_create_file("nf_cal_period", S_IRUSR | S_IWUSR,
2248 ar->debug.debugfs_phy, ar, &fops_nf_cal_period);
2250 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
2251 debugfs_create_file("dfs_simulate_radar", S_IWUSR,
2252 ar->debug.debugfs_phy, ar,
2253 &fops_simulate_radar);
2255 debugfs_create_bool("dfs_block_radar_events", S_IWUSR,
2256 ar->debug.debugfs_phy,
2257 &ar->dfs_block_radar_events);
2259 debugfs_create_file("dfs_stats", S_IRUSR,
2260 ar->debug.debugfs_phy, ar,
2264 debugfs_create_file("pktlog_filter", S_IRUGO | S_IWUSR,
2265 ar->debug.debugfs_phy, ar, &fops_pktlog_filter);
2267 debugfs_create_file("quiet_period", S_IRUGO | S_IWUSR,
2268 ar->debug.debugfs_phy, ar, &fops_quiet_period);
2270 debugfs_create_file("tpc_stats", S_IRUSR,
2271 ar->debug.debugfs_phy, ar, &fops_tpc_stats);
2273 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map))
2274 debugfs_create_file("btcoex", S_IRUGO | S_IWUSR,
2275 ar->debug.debugfs_phy, ar, &fops_btcoex);
2280 void ath10k_debug_unregister(struct ath10k *ar)
2282 cancel_delayed_work_sync(&ar->debug.htt_stats_dwork);
2285 #endif /* CONFIG_ATH10K_DEBUGFS */
2287 #ifdef CONFIG_ATH10K_DEBUG
2288 void ath10k_dbg(struct ath10k *ar, enum ath10k_debug_mask mask,
2289 const char *fmt, ...)
2291 struct va_format vaf;
2294 va_start(args, fmt);
2299 if (ath10k_debug_mask & mask)
2300 dev_printk(KERN_DEBUG, ar->dev, "%pV", &vaf);
2302 trace_ath10k_log_dbg(ar, mask, &vaf);
2306 EXPORT_SYMBOL(ath10k_dbg);
2308 void ath10k_dbg_dump(struct ath10k *ar,
2309 enum ath10k_debug_mask mask,
2310 const char *msg, const char *prefix,
2311 const void *buf, size_t len)
2314 unsigned int linebuflen;
2317 if (ath10k_debug_mask & mask) {
2319 ath10k_dbg(ar, mask, "%s\n", msg);
2321 for (ptr = buf; (ptr - buf) < len; ptr += 16) {
2323 linebuflen += scnprintf(linebuf + linebuflen,
2324 sizeof(linebuf) - linebuflen,
2326 (prefix ? prefix : ""),
2327 (unsigned int)(ptr - buf));
2328 hex_dump_to_buffer(ptr, len - (ptr - buf), 16, 1,
2329 linebuf + linebuflen,
2330 sizeof(linebuf) - linebuflen, true);
2331 dev_printk(KERN_DEBUG, ar->dev, "%s\n", linebuf);
2335 /* tracing code doesn't like null strings :/ */
2336 trace_ath10k_log_dbg_dump(ar, msg ? msg : "", prefix ? prefix : "",
2339 EXPORT_SYMBOL(ath10k_dbg_dump);
2341 #endif /* CONFIG_ATH10K_DEBUG */