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_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_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_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_fw_stats_pdevs_free(&ar->debug.fw_stats.pdevs);
314 ath10k_fw_stats_vdevs_free(&ar->debug.fw_stats.vdevs);
315 ath10k_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, peer_stats_svc;
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 peer_stats_svc = test_bit(WMI_SERVICE_PEER_STATS, ar->wmi.svc_map);
352 ath10k_sta_update_rx_duration(ar, &stats.peers);
354 if (ar->debug.fw_stats_done) {
356 ath10k_warn(ar, "received unsolicited stats update event\n");
361 num_peers = ath10k_wmi_fw_stats_num_peers(&ar->debug.fw_stats.peers);
362 num_vdevs = ath10k_wmi_fw_stats_num_vdevs(&ar->debug.fw_stats.vdevs);
363 is_start = (list_empty(&ar->debug.fw_stats.pdevs) &&
364 !list_empty(&stats.pdevs));
365 is_end = (!list_empty(&ar->debug.fw_stats.pdevs) &&
366 !list_empty(&stats.pdevs));
369 list_splice_tail_init(&stats.pdevs, &ar->debug.fw_stats.pdevs);
372 ar->debug.fw_stats_done = true;
374 is_started = !list_empty(&ar->debug.fw_stats.pdevs);
376 if (is_started && !is_end) {
377 if (num_peers >= ATH10K_MAX_NUM_PEER_IDS) {
378 /* Although this is unlikely impose a sane limit to
379 * prevent firmware from DoS-ing the host.
381 ath10k_fw_stats_peers_free(&ar->debug.fw_stats.peers);
382 ath10k_warn(ar, "dropping fw peer stats\n");
386 if (num_vdevs >= BITS_PER_LONG) {
387 ath10k_fw_stats_vdevs_free(&ar->debug.fw_stats.vdevs);
388 ath10k_warn(ar, "dropping fw vdev stats\n");
392 list_splice_tail_init(&stats.peers, &ar->debug.fw_stats.peers);
393 list_splice_tail_init(&stats.vdevs, &ar->debug.fw_stats.vdevs);
396 complete(&ar->debug.fw_stats_complete);
399 /* In some cases lists have been spliced and cleared. Free up
400 * resources if that is not the case.
402 ath10k_fw_stats_pdevs_free(&stats.pdevs);
403 ath10k_fw_stats_vdevs_free(&stats.vdevs);
404 ath10k_fw_stats_peers_free(&stats.peers);
406 spin_unlock_bh(&ar->data_lock);
409 static int ath10k_debug_fw_stats_request(struct ath10k *ar)
411 unsigned long timeout, time_left;
414 lockdep_assert_held(&ar->conf_mutex);
416 timeout = jiffies + msecs_to_jiffies(1 * HZ);
418 ath10k_debug_fw_stats_reset(ar);
421 if (time_after(jiffies, timeout))
424 reinit_completion(&ar->debug.fw_stats_complete);
426 ret = ath10k_wmi_request_stats(ar, ar->fw_stats_req_mask);
428 ath10k_warn(ar, "could not request stats (%d)\n", ret);
433 wait_for_completion_timeout(&ar->debug.fw_stats_complete,
438 spin_lock_bh(&ar->data_lock);
439 if (ar->debug.fw_stats_done) {
440 spin_unlock_bh(&ar->data_lock);
443 spin_unlock_bh(&ar->data_lock);
449 static int ath10k_fw_stats_open(struct inode *inode, struct file *file)
451 struct ath10k *ar = inode->i_private;
455 mutex_lock(&ar->conf_mutex);
457 if (ar->state != ATH10K_STATE_ON) {
462 buf = vmalloc(ATH10K_FW_STATS_BUF_SIZE);
468 ret = ath10k_debug_fw_stats_request(ar);
470 ath10k_warn(ar, "failed to request fw stats: %d\n", ret);
474 ret = ath10k_wmi_fw_stats_fill(ar, &ar->debug.fw_stats, buf);
476 ath10k_warn(ar, "failed to fill fw stats: %d\n", ret);
480 file->private_data = buf;
482 mutex_unlock(&ar->conf_mutex);
489 mutex_unlock(&ar->conf_mutex);
493 static int ath10k_fw_stats_release(struct inode *inode, struct file *file)
495 vfree(file->private_data);
500 static ssize_t ath10k_fw_stats_read(struct file *file, char __user *user_buf,
501 size_t count, loff_t *ppos)
503 const char *buf = file->private_data;
504 unsigned int len = strlen(buf);
506 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
509 static const struct file_operations fops_fw_stats = {
510 .open = ath10k_fw_stats_open,
511 .release = ath10k_fw_stats_release,
512 .read = ath10k_fw_stats_read,
513 .owner = THIS_MODULE,
514 .llseek = default_llseek,
517 static ssize_t ath10k_debug_fw_reset_stats_read(struct file *file,
518 char __user *user_buf,
519 size_t count, loff_t *ppos)
521 struct ath10k *ar = file->private_data;
522 int ret, len, buf_len;
526 buf = kmalloc(buf_len, GFP_KERNEL);
530 spin_lock_bh(&ar->data_lock);
533 len += scnprintf(buf + len, buf_len - len,
534 "fw_crash_counter\t\t%d\n", ar->stats.fw_crash_counter);
535 len += scnprintf(buf + len, buf_len - len,
536 "fw_warm_reset_counter\t\t%d\n",
537 ar->stats.fw_warm_reset_counter);
538 len += scnprintf(buf + len, buf_len - len,
539 "fw_cold_reset_counter\t\t%d\n",
540 ar->stats.fw_cold_reset_counter);
542 spin_unlock_bh(&ar->data_lock);
544 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
551 static const struct file_operations fops_fw_reset_stats = {
553 .read = ath10k_debug_fw_reset_stats_read,
554 .owner = THIS_MODULE,
555 .llseek = default_llseek,
558 /* This is a clean assert crash in firmware. */
559 static int ath10k_debug_fw_assert(struct ath10k *ar)
561 struct wmi_vdev_install_key_cmd *cmd;
564 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd) + 16);
568 cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
569 memset(cmd, 0, sizeof(*cmd));
571 /* big enough number so that firmware asserts */
572 cmd->vdev_id = __cpu_to_le32(0x7ffe);
574 return ath10k_wmi_cmd_send(ar, skb,
575 ar->wmi.cmd->vdev_install_key_cmdid);
578 static ssize_t ath10k_read_simulate_fw_crash(struct file *file,
579 char __user *user_buf,
580 size_t count, loff_t *ppos)
583 "To simulate firmware crash write one of the keywords to this file:\n"
584 "`soft` - this will send WMI_FORCE_FW_HANG_ASSERT to firmware if FW supports that command.\n"
585 "`hard` - this will send to firmware command with illegal parameters causing firmware crash.\n"
586 "`assert` - this will send special illegal parameter to firmware to cause assert failure and crash.\n"
587 "`hw-restart` - this will simply queue hw restart without fw/hw actually crashing.\n";
589 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
592 /* Simulate firmware crash:
593 * 'soft': Call wmi command causing firmware hang. This firmware hang is
594 * recoverable by warm firmware reset.
595 * 'hard': Force firmware crash by setting any vdev parameter for not allowed
596 * vdev id. This is hard firmware crash because it is recoverable only by cold
599 static ssize_t ath10k_write_simulate_fw_crash(struct file *file,
600 const char __user *user_buf,
601 size_t count, loff_t *ppos)
603 struct ath10k *ar = file->private_data;
607 mutex_lock(&ar->conf_mutex);
609 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
611 /* make sure that buf is null terminated */
612 buf[sizeof(buf) - 1] = 0;
614 if (ar->state != ATH10K_STATE_ON &&
615 ar->state != ATH10K_STATE_RESTARTED) {
620 /* drop the possible '\n' from the end */
621 if (buf[count - 1] == '\n') {
626 if (!strcmp(buf, "soft")) {
627 ath10k_info(ar, "simulating soft firmware crash\n");
628 ret = ath10k_wmi_force_fw_hang(ar, WMI_FORCE_FW_HANG_ASSERT, 0);
629 } else if (!strcmp(buf, "hard")) {
630 ath10k_info(ar, "simulating hard firmware crash\n");
631 /* 0x7fff is vdev id, and it is always out of range for all
632 * firmware variants in order to force a firmware crash.
634 ret = ath10k_wmi_vdev_set_param(ar, 0x7fff,
635 ar->wmi.vdev_param->rts_threshold,
637 } else if (!strcmp(buf, "assert")) {
638 ath10k_info(ar, "simulating firmware assert crash\n");
639 ret = ath10k_debug_fw_assert(ar);
640 } else if (!strcmp(buf, "hw-restart")) {
641 ath10k_info(ar, "user requested hw restart\n");
642 queue_work(ar->workqueue, &ar->restart_work);
650 ath10k_warn(ar, "failed to simulate firmware crash: %d\n", ret);
657 mutex_unlock(&ar->conf_mutex);
661 static const struct file_operations fops_simulate_fw_crash = {
662 .read = ath10k_read_simulate_fw_crash,
663 .write = ath10k_write_simulate_fw_crash,
665 .owner = THIS_MODULE,
666 .llseek = default_llseek,
669 static ssize_t ath10k_read_chip_id(struct file *file, char __user *user_buf,
670 size_t count, loff_t *ppos)
672 struct ath10k *ar = file->private_data;
676 len = scnprintf(buf, sizeof(buf), "0x%08x\n", ar->chip_id);
678 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
681 static const struct file_operations fops_chip_id = {
682 .read = ath10k_read_chip_id,
684 .owner = THIS_MODULE,
685 .llseek = default_llseek,
688 struct ath10k_fw_crash_data *
689 ath10k_debug_get_new_fw_crash_data(struct ath10k *ar)
691 struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data;
693 lockdep_assert_held(&ar->data_lock);
695 crash_data->crashed_since_read = true;
696 uuid_le_gen(&crash_data->uuid);
697 getnstimeofday(&crash_data->timestamp);
701 EXPORT_SYMBOL(ath10k_debug_get_new_fw_crash_data);
703 static struct ath10k_dump_file_data *ath10k_build_dump_file(struct ath10k *ar)
705 struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data;
706 struct ath10k_dump_file_data *dump_data;
707 struct ath10k_tlv_dump_data *dump_tlv;
708 int hdr_len = sizeof(*dump_data);
709 unsigned int len, sofar = 0;
713 len += sizeof(*dump_tlv) + sizeof(crash_data->registers);
717 /* This is going to get big when we start dumping FW RAM and such,
718 * so go ahead and use vmalloc.
724 spin_lock_bh(&ar->data_lock);
726 if (!crash_data->crashed_since_read) {
727 spin_unlock_bh(&ar->data_lock);
732 dump_data = (struct ath10k_dump_file_data *)(buf);
733 strlcpy(dump_data->df_magic, "ATH10K-FW-DUMP",
734 sizeof(dump_data->df_magic));
735 dump_data->len = cpu_to_le32(len);
737 dump_data->version = cpu_to_le32(ATH10K_FW_CRASH_DUMP_VERSION);
739 memcpy(dump_data->uuid, &crash_data->uuid, sizeof(dump_data->uuid));
740 dump_data->chip_id = cpu_to_le32(ar->chip_id);
741 dump_data->bus_type = cpu_to_le32(0);
742 dump_data->target_version = cpu_to_le32(ar->target_version);
743 dump_data->fw_version_major = cpu_to_le32(ar->fw_version_major);
744 dump_data->fw_version_minor = cpu_to_le32(ar->fw_version_minor);
745 dump_data->fw_version_release = cpu_to_le32(ar->fw_version_release);
746 dump_data->fw_version_build = cpu_to_le32(ar->fw_version_build);
747 dump_data->phy_capability = cpu_to_le32(ar->phy_capability);
748 dump_data->hw_min_tx_power = cpu_to_le32(ar->hw_min_tx_power);
749 dump_data->hw_max_tx_power = cpu_to_le32(ar->hw_max_tx_power);
750 dump_data->ht_cap_info = cpu_to_le32(ar->ht_cap_info);
751 dump_data->vht_cap_info = cpu_to_le32(ar->vht_cap_info);
752 dump_data->num_rf_chains = cpu_to_le32(ar->num_rf_chains);
754 strlcpy(dump_data->fw_ver, ar->hw->wiphy->fw_version,
755 sizeof(dump_data->fw_ver));
757 dump_data->kernel_ver_code = 0;
758 strlcpy(dump_data->kernel_ver, init_utsname()->release,
759 sizeof(dump_data->kernel_ver));
761 dump_data->tv_sec = cpu_to_le64(crash_data->timestamp.tv_sec);
762 dump_data->tv_nsec = cpu_to_le64(crash_data->timestamp.tv_nsec);
764 /* Gather crash-dump */
765 dump_tlv = (struct ath10k_tlv_dump_data *)(buf + sofar);
766 dump_tlv->type = cpu_to_le32(ATH10K_FW_CRASH_DUMP_REGISTERS);
767 dump_tlv->tlv_len = cpu_to_le32(sizeof(crash_data->registers));
768 memcpy(dump_tlv->tlv_data, &crash_data->registers,
769 sizeof(crash_data->registers));
770 sofar += sizeof(*dump_tlv) + sizeof(crash_data->registers);
772 ar->debug.fw_crash_data->crashed_since_read = false;
774 spin_unlock_bh(&ar->data_lock);
779 static int ath10k_fw_crash_dump_open(struct inode *inode, struct file *file)
781 struct ath10k *ar = inode->i_private;
782 struct ath10k_dump_file_data *dump;
784 dump = ath10k_build_dump_file(ar);
788 file->private_data = dump;
793 static ssize_t ath10k_fw_crash_dump_read(struct file *file,
794 char __user *user_buf,
795 size_t count, loff_t *ppos)
797 struct ath10k_dump_file_data *dump_file = file->private_data;
799 return simple_read_from_buffer(user_buf, count, ppos,
801 le32_to_cpu(dump_file->len));
804 static int ath10k_fw_crash_dump_release(struct inode *inode,
807 vfree(file->private_data);
812 static const struct file_operations fops_fw_crash_dump = {
813 .open = ath10k_fw_crash_dump_open,
814 .read = ath10k_fw_crash_dump_read,
815 .release = ath10k_fw_crash_dump_release,
816 .owner = THIS_MODULE,
817 .llseek = default_llseek,
820 static ssize_t ath10k_reg_addr_read(struct file *file,
821 char __user *user_buf,
822 size_t count, loff_t *ppos)
824 struct ath10k *ar = file->private_data;
826 unsigned int len = 0;
829 mutex_lock(&ar->conf_mutex);
830 reg_addr = ar->debug.reg_addr;
831 mutex_unlock(&ar->conf_mutex);
833 len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n", reg_addr);
835 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
838 static ssize_t ath10k_reg_addr_write(struct file *file,
839 const char __user *user_buf,
840 size_t count, loff_t *ppos)
842 struct ath10k *ar = file->private_data;
846 ret = kstrtou32_from_user(user_buf, count, 0, ®_addr);
850 if (!IS_ALIGNED(reg_addr, 4))
853 mutex_lock(&ar->conf_mutex);
854 ar->debug.reg_addr = reg_addr;
855 mutex_unlock(&ar->conf_mutex);
860 static const struct file_operations fops_reg_addr = {
861 .read = ath10k_reg_addr_read,
862 .write = ath10k_reg_addr_write,
864 .owner = THIS_MODULE,
865 .llseek = default_llseek,
868 static ssize_t ath10k_reg_value_read(struct file *file,
869 char __user *user_buf,
870 size_t count, loff_t *ppos)
872 struct ath10k *ar = file->private_data;
875 u32 reg_addr, reg_val;
878 mutex_lock(&ar->conf_mutex);
880 if (ar->state != ATH10K_STATE_ON &&
881 ar->state != ATH10K_STATE_UTF) {
886 reg_addr = ar->debug.reg_addr;
888 reg_val = ath10k_hif_read32(ar, reg_addr);
889 len = scnprintf(buf, sizeof(buf), "0x%08x:0x%08x\n", reg_addr, reg_val);
891 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
894 mutex_unlock(&ar->conf_mutex);
899 static ssize_t ath10k_reg_value_write(struct file *file,
900 const char __user *user_buf,
901 size_t count, loff_t *ppos)
903 struct ath10k *ar = file->private_data;
904 u32 reg_addr, reg_val;
907 mutex_lock(&ar->conf_mutex);
909 if (ar->state != ATH10K_STATE_ON &&
910 ar->state != ATH10K_STATE_UTF) {
915 reg_addr = ar->debug.reg_addr;
917 ret = kstrtou32_from_user(user_buf, count, 0, ®_val);
921 ath10k_hif_write32(ar, reg_addr, reg_val);
926 mutex_unlock(&ar->conf_mutex);
931 static const struct file_operations fops_reg_value = {
932 .read = ath10k_reg_value_read,
933 .write = ath10k_reg_value_write,
935 .owner = THIS_MODULE,
936 .llseek = default_llseek,
939 static ssize_t ath10k_mem_value_read(struct file *file,
940 char __user *user_buf,
941 size_t count, loff_t *ppos)
943 struct ath10k *ar = file->private_data;
953 mutex_lock(&ar->conf_mutex);
955 buf = vmalloc(count);
961 if (ar->state != ATH10K_STATE_ON &&
962 ar->state != ATH10K_STATE_UTF) {
967 ret = ath10k_hif_diag_read(ar, *ppos, buf, count);
969 ath10k_warn(ar, "failed to read address 0x%08x via diagnose window fnrom debugfs: %d\n",
974 ret = copy_to_user(user_buf, buf, count);
986 mutex_unlock(&ar->conf_mutex);
991 static ssize_t ath10k_mem_value_write(struct file *file,
992 const char __user *user_buf,
993 size_t count, loff_t *ppos)
995 struct ath10k *ar = file->private_data;
1005 mutex_lock(&ar->conf_mutex);
1007 buf = vmalloc(count);
1013 if (ar->state != ATH10K_STATE_ON &&
1014 ar->state != ATH10K_STATE_UTF) {
1019 ret = copy_from_user(buf, user_buf, count);
1025 ret = ath10k_hif_diag_write(ar, *ppos, buf, count);
1027 ath10k_warn(ar, "failed to write address 0x%08x via diagnose window from debugfs: %d\n",
1037 mutex_unlock(&ar->conf_mutex);
1042 static const struct file_operations fops_mem_value = {
1043 .read = ath10k_mem_value_read,
1044 .write = ath10k_mem_value_write,
1045 .open = simple_open,
1046 .owner = THIS_MODULE,
1047 .llseek = default_llseek,
1050 static int ath10k_debug_htt_stats_req(struct ath10k *ar)
1055 lockdep_assert_held(&ar->conf_mutex);
1057 if (ar->debug.htt_stats_mask == 0)
1058 /* htt stats are disabled */
1061 if (ar->state != ATH10K_STATE_ON)
1064 cookie = get_jiffies_64();
1066 ret = ath10k_htt_h2t_stats_req(&ar->htt, ar->debug.htt_stats_mask,
1069 ath10k_warn(ar, "failed to send htt stats request: %d\n", ret);
1073 queue_delayed_work(ar->workqueue, &ar->debug.htt_stats_dwork,
1074 msecs_to_jiffies(ATH10K_DEBUG_HTT_STATS_INTERVAL));
1079 static void ath10k_debug_htt_stats_dwork(struct work_struct *work)
1081 struct ath10k *ar = container_of(work, struct ath10k,
1082 debug.htt_stats_dwork.work);
1084 mutex_lock(&ar->conf_mutex);
1086 ath10k_debug_htt_stats_req(ar);
1088 mutex_unlock(&ar->conf_mutex);
1091 static ssize_t ath10k_read_htt_stats_mask(struct file *file,
1092 char __user *user_buf,
1093 size_t count, loff_t *ppos)
1095 struct ath10k *ar = file->private_data;
1099 len = scnprintf(buf, sizeof(buf), "%lu\n", ar->debug.htt_stats_mask);
1101 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1104 static ssize_t ath10k_write_htt_stats_mask(struct file *file,
1105 const char __user *user_buf,
1106 size_t count, loff_t *ppos)
1108 struct ath10k *ar = file->private_data;
1112 ret = kstrtoul_from_user(user_buf, count, 0, &mask);
1116 /* max 8 bit masks (for now) */
1120 mutex_lock(&ar->conf_mutex);
1122 ar->debug.htt_stats_mask = mask;
1124 ret = ath10k_debug_htt_stats_req(ar);
1131 mutex_unlock(&ar->conf_mutex);
1136 static const struct file_operations fops_htt_stats_mask = {
1137 .read = ath10k_read_htt_stats_mask,
1138 .write = ath10k_write_htt_stats_mask,
1139 .open = simple_open,
1140 .owner = THIS_MODULE,
1141 .llseek = default_llseek,
1144 static ssize_t ath10k_read_htt_max_amsdu_ampdu(struct file *file,
1145 char __user *user_buf,
1146 size_t count, loff_t *ppos)
1148 struct ath10k *ar = file->private_data;
1153 mutex_lock(&ar->conf_mutex);
1155 amsdu = ar->htt.max_num_amsdu;
1156 ampdu = ar->htt.max_num_ampdu;
1157 mutex_unlock(&ar->conf_mutex);
1159 len = scnprintf(buf, sizeof(buf), "%u %u\n", amsdu, ampdu);
1161 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1164 static ssize_t ath10k_write_htt_max_amsdu_ampdu(struct file *file,
1165 const char __user *user_buf,
1166 size_t count, loff_t *ppos)
1168 struct ath10k *ar = file->private_data;
1171 unsigned int amsdu, ampdu;
1173 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
1175 /* make sure that buf is null terminated */
1176 buf[sizeof(buf) - 1] = 0;
1178 res = sscanf(buf, "%u %u", &amsdu, &du);
1183 mutex_lock(&ar->conf_mutex);
1185 res = ath10k_htt_h2t_aggr_cfg_msg(&ar->htt, ampdu, amsdu);
1190 ar->htt.max_num_amsdu = amsdu;
1191 ar->htt.max_num_ampdu = ampdu;
1194 mutex_unlock(&ar->conf_mutex);
1198 static const struct file_operations fops_htt_max_amsdu_ampdu = {
1199 .read = ath10k_read_htt_max_amsdu_ampdu,
1200 .write = ath10k_write_htt_max_amsdu_ampdu,
1201 .open = simple_open,
1202 .owner = THIS_MODULE,
1203 .llseek = default_llseek,
1206 static ssize_t ath10k_read_fw_dbglog(struct file *file,
1207 char __user *user_buf,
1208 size_t count, loff_t *ppos)
1210 struct ath10k *ar = file->private_data;
1214 len = scnprintf(buf, sizeof(buf), "0x%08x %u\n",
1215 ar->debug.fw_dbglog_mask, ar->debug.fw_dbglog_level);
1217 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1220 static ssize_t ath10k_write_fw_dbglog(struct file *file,
1221 const char __user *user_buf,
1222 size_t count, loff_t *ppos)
1224 struct ath10k *ar = file->private_data;
1227 unsigned int log_level, mask;
1229 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
1231 /* make sure that buf is null terminated */
1232 buf[sizeof(buf) - 1] = 0;
1234 ret = sscanf(buf, "%x %u", &mask, &log_level);
1240 /* default if user did not specify */
1241 log_level = ATH10K_DBGLOG_LEVEL_WARN;
1243 mutex_lock(&ar->conf_mutex);
1245 ar->debug.fw_dbglog_mask = mask;
1246 ar->debug.fw_dbglog_level = log_level;
1248 if (ar->state == ATH10K_STATE_ON) {
1249 ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask,
1250 ar->debug.fw_dbglog_level);
1252 ath10k_warn(ar, "dbglog cfg failed from debugfs: %d\n",
1261 mutex_unlock(&ar->conf_mutex);
1266 /* TODO: Would be nice to always support ethtool stats, would need to
1267 * move the stats storage out of ath10k_debug, or always have ath10k_debug
1268 * struct available..
1271 /* This generally cooresponds to the debugfs fw_stats file */
1272 static const char ath10k_gstrings_stats[][ETH_GSTRING_LEN] = {
1282 "d_tx_power", /* in .5 dbM I think */
1283 "d_rx_crc_err", /* fcs_bad */
1285 "d_tx_mpdus_queued",
1287 "d_tx_msdu_dropped",
1290 "d_tx_ppdu_hw_queued",
1292 "d_tx_fifo_underrun",
1295 "d_tx_excessive_retries",
1297 "d_tx_dropped_sw_retries",
1298 "d_tx_illegal_rate",
1299 "d_tx_continuous_xretries",
1301 "d_tx_mpdu_txop_limit",
1303 "d_rx_mid_ppdu_route_change",
1305 "d_rx_extra_frags_ring0",
1306 "d_rx_extra_frags_ring1",
1307 "d_rx_extra_frags_ring2",
1308 "d_rx_extra_frags_ring3",
1314 "d_rx_phy_err_drops",
1315 "d_rx_mpdu_errors", /* FCS, MIC, ENC */
1317 "d_fw_warm_reset_count",
1318 "d_fw_cold_reset_count",
1321 #define ATH10K_SSTATS_LEN ARRAY_SIZE(ath10k_gstrings_stats)
1323 void ath10k_debug_get_et_strings(struct ieee80211_hw *hw,
1324 struct ieee80211_vif *vif,
1327 if (sset == ETH_SS_STATS)
1328 memcpy(data, *ath10k_gstrings_stats,
1329 sizeof(ath10k_gstrings_stats));
1332 int ath10k_debug_get_et_sset_count(struct ieee80211_hw *hw,
1333 struct ieee80211_vif *vif, int sset)
1335 if (sset == ETH_SS_STATS)
1336 return ATH10K_SSTATS_LEN;
1341 void ath10k_debug_get_et_stats(struct ieee80211_hw *hw,
1342 struct ieee80211_vif *vif,
1343 struct ethtool_stats *stats, u64 *data)
1345 struct ath10k *ar = hw->priv;
1346 static const struct ath10k_fw_stats_pdev zero_stats = {};
1347 const struct ath10k_fw_stats_pdev *pdev_stats;
1350 mutex_lock(&ar->conf_mutex);
1352 if (ar->state == ATH10K_STATE_ON) {
1353 ret = ath10k_debug_fw_stats_request(ar);
1355 /* just print a warning and try to use older results */
1357 "failed to get fw stats for ethtool: %d\n",
1362 pdev_stats = list_first_entry_or_null(&ar->debug.fw_stats.pdevs,
1363 struct ath10k_fw_stats_pdev,
1366 /* no results available so just return zeroes */
1367 pdev_stats = &zero_stats;
1370 spin_lock_bh(&ar->data_lock);
1372 data[i++] = pdev_stats->hw_reaped; /* ppdu reaped */
1373 data[i++] = 0; /* tx bytes */
1374 data[i++] = pdev_stats->htt_mpdus;
1375 data[i++] = 0; /* rx bytes */
1376 data[i++] = pdev_stats->ch_noise_floor;
1377 data[i++] = pdev_stats->cycle_count;
1378 data[i++] = pdev_stats->phy_err_count;
1379 data[i++] = pdev_stats->rts_bad;
1380 data[i++] = pdev_stats->rts_good;
1381 data[i++] = pdev_stats->chan_tx_power;
1382 data[i++] = pdev_stats->fcs_bad;
1383 data[i++] = pdev_stats->no_beacons;
1384 data[i++] = pdev_stats->mpdu_enqued;
1385 data[i++] = pdev_stats->msdu_enqued;
1386 data[i++] = pdev_stats->wmm_drop;
1387 data[i++] = pdev_stats->local_enqued;
1388 data[i++] = pdev_stats->local_freed;
1389 data[i++] = pdev_stats->hw_queued;
1390 data[i++] = pdev_stats->hw_reaped;
1391 data[i++] = pdev_stats->underrun;
1392 data[i++] = pdev_stats->tx_abort;
1393 data[i++] = pdev_stats->mpdus_requed;
1394 data[i++] = pdev_stats->tx_ko;
1395 data[i++] = pdev_stats->data_rc;
1396 data[i++] = pdev_stats->sw_retry_failure;
1397 data[i++] = pdev_stats->illgl_rate_phy_err;
1398 data[i++] = pdev_stats->pdev_cont_xretry;
1399 data[i++] = pdev_stats->pdev_tx_timeout;
1400 data[i++] = pdev_stats->txop_ovf;
1401 data[i++] = pdev_stats->pdev_resets;
1402 data[i++] = pdev_stats->mid_ppdu_route_change;
1403 data[i++] = pdev_stats->status_rcvd;
1404 data[i++] = pdev_stats->r0_frags;
1405 data[i++] = pdev_stats->r1_frags;
1406 data[i++] = pdev_stats->r2_frags;
1407 data[i++] = pdev_stats->r3_frags;
1408 data[i++] = pdev_stats->htt_msdus;
1409 data[i++] = pdev_stats->htt_mpdus;
1410 data[i++] = pdev_stats->loc_msdus;
1411 data[i++] = pdev_stats->loc_mpdus;
1412 data[i++] = pdev_stats->phy_errs;
1413 data[i++] = pdev_stats->phy_err_drop;
1414 data[i++] = pdev_stats->mpdu_errs;
1415 data[i++] = ar->stats.fw_crash_counter;
1416 data[i++] = ar->stats.fw_warm_reset_counter;
1417 data[i++] = ar->stats.fw_cold_reset_counter;
1419 spin_unlock_bh(&ar->data_lock);
1421 mutex_unlock(&ar->conf_mutex);
1423 WARN_ON(i != ATH10K_SSTATS_LEN);
1426 static const struct file_operations fops_fw_dbglog = {
1427 .read = ath10k_read_fw_dbglog,
1428 .write = ath10k_write_fw_dbglog,
1429 .open = simple_open,
1430 .owner = THIS_MODULE,
1431 .llseek = default_llseek,
1434 static int ath10k_debug_cal_data_open(struct inode *inode, struct file *file)
1436 struct ath10k *ar = inode->i_private;
1442 mutex_lock(&ar->conf_mutex);
1444 if (ar->state != ATH10K_STATE_ON &&
1445 ar->state != ATH10K_STATE_UTF) {
1450 buf = vmalloc(QCA988X_CAL_DATA_LEN);
1456 hi_addr = host_interest_item_address(HI_ITEM(hi_board_data));
1458 ret = ath10k_hif_diag_read(ar, hi_addr, &addr, sizeof(addr));
1460 ath10k_warn(ar, "failed to read hi_board_data address: %d\n", ret);
1464 ret = ath10k_hif_diag_read(ar, le32_to_cpu(addr), buf,
1465 QCA988X_CAL_DATA_LEN);
1467 ath10k_warn(ar, "failed to read calibration data: %d\n", ret);
1471 file->private_data = buf;
1473 mutex_unlock(&ar->conf_mutex);
1481 mutex_unlock(&ar->conf_mutex);
1486 static ssize_t ath10k_debug_cal_data_read(struct file *file,
1487 char __user *user_buf,
1488 size_t count, loff_t *ppos)
1490 void *buf = file->private_data;
1492 return simple_read_from_buffer(user_buf, count, ppos,
1493 buf, QCA988X_CAL_DATA_LEN);
1496 static int ath10k_debug_cal_data_release(struct inode *inode,
1499 vfree(file->private_data);
1504 static ssize_t ath10k_write_ani_enable(struct file *file,
1505 const char __user *user_buf,
1506 size_t count, loff_t *ppos)
1508 struct ath10k *ar = file->private_data;
1512 if (kstrtou8_from_user(user_buf, count, 0, &enable))
1515 mutex_lock(&ar->conf_mutex);
1517 if (ar->ani_enabled == enable) {
1522 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->ani_enable,
1525 ath10k_warn(ar, "ani_enable failed from debugfs: %d\n", ret);
1528 ar->ani_enabled = enable;
1533 mutex_unlock(&ar->conf_mutex);
1538 static ssize_t ath10k_read_ani_enable(struct file *file, char __user *user_buf,
1539 size_t count, loff_t *ppos)
1541 struct ath10k *ar = file->private_data;
1545 len = scnprintf(buf, sizeof(buf) - len, "%d\n",
1548 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1551 static const struct file_operations fops_ani_enable = {
1552 .read = ath10k_read_ani_enable,
1553 .write = ath10k_write_ani_enable,
1554 .open = simple_open,
1555 .owner = THIS_MODULE,
1556 .llseek = default_llseek,
1559 static const struct file_operations fops_cal_data = {
1560 .open = ath10k_debug_cal_data_open,
1561 .read = ath10k_debug_cal_data_read,
1562 .release = ath10k_debug_cal_data_release,
1563 .owner = THIS_MODULE,
1564 .llseek = default_llseek,
1567 static ssize_t ath10k_read_nf_cal_period(struct file *file,
1568 char __user *user_buf,
1569 size_t count, loff_t *ppos)
1571 struct ath10k *ar = file->private_data;
1575 len = scnprintf(buf, sizeof(buf), "%d\n",
1576 ar->debug.nf_cal_period);
1578 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1581 static ssize_t ath10k_write_nf_cal_period(struct file *file,
1582 const char __user *user_buf,
1583 size_t count, loff_t *ppos)
1585 struct ath10k *ar = file->private_data;
1586 unsigned long period;
1589 ret = kstrtoul_from_user(user_buf, count, 0, &period);
1593 if (period > WMI_PDEV_PARAM_CAL_PERIOD_MAX)
1596 /* there's no way to switch back to the firmware default */
1600 mutex_lock(&ar->conf_mutex);
1602 ar->debug.nf_cal_period = period;
1604 if (ar->state != ATH10K_STATE_ON) {
1605 /* firmware is not running, nothing else to do */
1610 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->cal_period,
1611 ar->debug.nf_cal_period);
1613 ath10k_warn(ar, "cal period cfg failed from debugfs: %d\n",
1621 mutex_unlock(&ar->conf_mutex);
1626 static const struct file_operations fops_nf_cal_period = {
1627 .read = ath10k_read_nf_cal_period,
1628 .write = ath10k_write_nf_cal_period,
1629 .open = simple_open,
1630 .owner = THIS_MODULE,
1631 .llseek = default_llseek,
1634 #define ATH10K_TPC_CONFIG_BUF_SIZE (1024 * 1024)
1636 static int ath10k_debug_tpc_stats_request(struct ath10k *ar)
1639 unsigned long time_left;
1641 lockdep_assert_held(&ar->conf_mutex);
1643 reinit_completion(&ar->debug.tpc_complete);
1645 ret = ath10k_wmi_pdev_get_tpc_config(ar, WMI_TPC_CONFIG_PARAM);
1647 ath10k_warn(ar, "failed to request tpc config: %d\n", ret);
1651 time_left = wait_for_completion_timeout(&ar->debug.tpc_complete,
1659 void ath10k_debug_tpc_stats_process(struct ath10k *ar,
1660 struct ath10k_tpc_stats *tpc_stats)
1662 spin_lock_bh(&ar->data_lock);
1664 kfree(ar->debug.tpc_stats);
1665 ar->debug.tpc_stats = tpc_stats;
1666 complete(&ar->debug.tpc_complete);
1668 spin_unlock_bh(&ar->data_lock);
1671 static void ath10k_tpc_stats_print(struct ath10k_tpc_stats *tpc_stats,
1672 unsigned int j, char *buf, unsigned int *len)
1674 unsigned int i, buf_len;
1675 static const char table_str[][5] = { "CDD",
1678 static const char pream_str[][6] = { "CCK",
1687 buf_len = ATH10K_TPC_CONFIG_BUF_SIZE;
1688 *len += scnprintf(buf + *len, buf_len - *len,
1689 "********************************\n");
1690 *len += scnprintf(buf + *len, buf_len - *len,
1691 "******************* %s POWER TABLE ****************\n",
1693 *len += scnprintf(buf + *len, buf_len - *len,
1694 "********************************\n");
1695 *len += scnprintf(buf + *len, buf_len - *len,
1696 "No. Preamble Rate_code tpc_value1 tpc_value2 tpc_value3\n");
1698 for (i = 0; i < tpc_stats->rate_max; i++) {
1699 *len += scnprintf(buf + *len, buf_len - *len,
1700 "%8d %s 0x%2x %s\n", i,
1701 pream_str[tpc_stats->tpc_table[j].pream_idx[i]],
1702 tpc_stats->tpc_table[j].rate_code[i],
1703 tpc_stats->tpc_table[j].tpc_value[i]);
1706 *len += scnprintf(buf + *len, buf_len - *len,
1707 "***********************************\n");
1710 static void ath10k_tpc_stats_fill(struct ath10k *ar,
1711 struct ath10k_tpc_stats *tpc_stats,
1714 unsigned int len, j, buf_len;
1717 buf_len = ATH10K_TPC_CONFIG_BUF_SIZE;
1719 spin_lock_bh(&ar->data_lock);
1722 ath10k_warn(ar, "failed to get tpc stats\n");
1726 len += scnprintf(buf + len, buf_len - len, "\n");
1727 len += scnprintf(buf + len, buf_len - len,
1728 "*************************************\n");
1729 len += scnprintf(buf + len, buf_len - len,
1730 "TPC config for channel %4d mode %d\n",
1731 tpc_stats->chan_freq,
1732 tpc_stats->phy_mode);
1733 len += scnprintf(buf + len, buf_len - len,
1734 "*************************************\n");
1735 len += scnprintf(buf + len, buf_len - len,
1736 "CTL = 0x%2x Reg. Domain = %2d\n",
1738 tpc_stats->reg_domain);
1739 len += scnprintf(buf + len, buf_len - len,
1740 "Antenna Gain = %2d Reg. Max Antenna Gain = %2d\n",
1741 tpc_stats->twice_antenna_gain,
1742 tpc_stats->twice_antenna_reduction);
1743 len += scnprintf(buf + len, buf_len - len,
1744 "Power Limit = %2d Reg. Max Power = %2d\n",
1745 tpc_stats->power_limit,
1746 tpc_stats->twice_max_rd_power / 2);
1747 len += scnprintf(buf + len, buf_len - len,
1748 "Num tx chains = %2d Num supported rates = %2d\n",
1749 tpc_stats->num_tx_chain,
1750 tpc_stats->rate_max);
1752 for (j = 0; j < tpc_stats->num_tx_chain ; j++) {
1754 case WMI_TPC_TABLE_TYPE_CDD:
1755 if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) {
1756 len += scnprintf(buf + len, buf_len - len,
1757 "CDD not supported\n");
1761 ath10k_tpc_stats_print(tpc_stats, j, buf, &len);
1763 case WMI_TPC_TABLE_TYPE_STBC:
1764 if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) {
1765 len += scnprintf(buf + len, buf_len - len,
1766 "STBC not supported\n");
1770 ath10k_tpc_stats_print(tpc_stats, j, buf, &len);
1772 case WMI_TPC_TABLE_TYPE_TXBF:
1773 if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) {
1774 len += scnprintf(buf + len, buf_len - len,
1775 "TXBF not supported\n***************************\n");
1779 ath10k_tpc_stats_print(tpc_stats, j, buf, &len);
1782 len += scnprintf(buf + len, buf_len - len,
1789 spin_unlock_bh(&ar->data_lock);
1797 static int ath10k_tpc_stats_open(struct inode *inode, struct file *file)
1799 struct ath10k *ar = inode->i_private;
1803 mutex_lock(&ar->conf_mutex);
1805 if (ar->state != ATH10K_STATE_ON) {
1810 buf = vmalloc(ATH10K_TPC_CONFIG_BUF_SIZE);
1816 ret = ath10k_debug_tpc_stats_request(ar);
1818 ath10k_warn(ar, "failed to request tpc config stats: %d\n",
1823 ath10k_tpc_stats_fill(ar, ar->debug.tpc_stats, buf);
1824 file->private_data = buf;
1826 mutex_unlock(&ar->conf_mutex);
1833 mutex_unlock(&ar->conf_mutex);
1837 static int ath10k_tpc_stats_release(struct inode *inode, struct file *file)
1839 vfree(file->private_data);
1844 static ssize_t ath10k_tpc_stats_read(struct file *file, char __user *user_buf,
1845 size_t count, loff_t *ppos)
1847 const char *buf = file->private_data;
1848 unsigned int len = strlen(buf);
1850 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1853 static const struct file_operations fops_tpc_stats = {
1854 .open = ath10k_tpc_stats_open,
1855 .release = ath10k_tpc_stats_release,
1856 .read = ath10k_tpc_stats_read,
1857 .owner = THIS_MODULE,
1858 .llseek = default_llseek,
1861 int ath10k_debug_start(struct ath10k *ar)
1865 lockdep_assert_held(&ar->conf_mutex);
1867 ret = ath10k_debug_htt_stats_req(ar);
1869 /* continue normally anyway, this isn't serious */
1870 ath10k_warn(ar, "failed to start htt stats workqueue: %d\n",
1873 if (ar->debug.fw_dbglog_mask) {
1874 ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask,
1875 ATH10K_DBGLOG_LEVEL_WARN);
1878 ath10k_warn(ar, "failed to enable dbglog during start: %d",
1882 if (ar->debug.pktlog_filter) {
1883 ret = ath10k_wmi_pdev_pktlog_enable(ar,
1884 ar->debug.pktlog_filter);
1888 "failed to enable pktlog filter %x: %d\n",
1889 ar->debug.pktlog_filter, ret);
1891 ret = ath10k_wmi_pdev_pktlog_disable(ar);
1894 ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
1897 if (ar->debug.nf_cal_period) {
1898 ret = ath10k_wmi_pdev_set_param(ar,
1899 ar->wmi.pdev_param->cal_period,
1900 ar->debug.nf_cal_period);
1903 ath10k_warn(ar, "cal period cfg failed from debug start: %d\n",
1910 void ath10k_debug_stop(struct ath10k *ar)
1912 lockdep_assert_held(&ar->conf_mutex);
1914 /* Must not use _sync to avoid deadlock, we do that in
1915 * ath10k_debug_destroy(). The check for htt_stats_mask is to avoid
1916 * warning from del_timer(). */
1917 if (ar->debug.htt_stats_mask != 0)
1918 cancel_delayed_work(&ar->debug.htt_stats_dwork);
1920 ath10k_wmi_pdev_pktlog_disable(ar);
1923 static ssize_t ath10k_write_simulate_radar(struct file *file,
1924 const char __user *user_buf,
1925 size_t count, loff_t *ppos)
1927 struct ath10k *ar = file->private_data;
1929 ieee80211_radar_detected(ar->hw);
1934 static const struct file_operations fops_simulate_radar = {
1935 .write = ath10k_write_simulate_radar,
1936 .open = simple_open,
1937 .owner = THIS_MODULE,
1938 .llseek = default_llseek,
1941 #define ATH10K_DFS_STAT(s, p) (\
1942 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1943 ar->debug.dfs_stats.p))
1945 #define ATH10K_DFS_POOL_STAT(s, p) (\
1946 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1947 ar->debug.dfs_pool_stats.p))
1949 static ssize_t ath10k_read_dfs_stats(struct file *file, char __user *user_buf,
1950 size_t count, loff_t *ppos)
1952 int retval = 0, len = 0;
1953 const int size = 8000;
1954 struct ath10k *ar = file->private_data;
1957 buf = kzalloc(size, GFP_KERNEL);
1961 if (!ar->dfs_detector) {
1962 len += scnprintf(buf + len, size - len, "DFS not enabled\n");
1966 ar->debug.dfs_pool_stats =
1967 ar->dfs_detector->get_stats(ar->dfs_detector);
1969 len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n");
1971 ATH10K_DFS_STAT("reported phy errors", phy_errors);
1972 ATH10K_DFS_STAT("pulse events reported", pulses_total);
1973 ATH10K_DFS_STAT("DFS pulses detected", pulses_detected);
1974 ATH10K_DFS_STAT("DFS pulses discarded", pulses_discarded);
1975 ATH10K_DFS_STAT("Radars detected", radar_detected);
1977 len += scnprintf(buf + len, size - len, "Global Pool statistics:\n");
1978 ATH10K_DFS_POOL_STAT("Pool references", pool_reference);
1979 ATH10K_DFS_POOL_STAT("Pulses allocated", pulse_allocated);
1980 ATH10K_DFS_POOL_STAT("Pulses alloc error", pulse_alloc_error);
1981 ATH10K_DFS_POOL_STAT("Pulses in use", pulse_used);
1982 ATH10K_DFS_POOL_STAT("Seqs. allocated", pseq_allocated);
1983 ATH10K_DFS_POOL_STAT("Seqs. alloc error", pseq_alloc_error);
1984 ATH10K_DFS_POOL_STAT("Seqs. in use", pseq_used);
1990 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1996 static const struct file_operations fops_dfs_stats = {
1997 .read = ath10k_read_dfs_stats,
1998 .open = simple_open,
1999 .owner = THIS_MODULE,
2000 .llseek = default_llseek,
2003 static ssize_t ath10k_write_pktlog_filter(struct file *file,
2004 const char __user *ubuf,
2005 size_t count, loff_t *ppos)
2007 struct ath10k *ar = file->private_data;
2011 if (kstrtouint_from_user(ubuf, count, 0, &filter))
2014 mutex_lock(&ar->conf_mutex);
2016 if (ar->state != ATH10K_STATE_ON) {
2017 ar->debug.pktlog_filter = filter;
2022 if (filter && (filter != ar->debug.pktlog_filter)) {
2023 ret = ath10k_wmi_pdev_pktlog_enable(ar, filter);
2025 ath10k_warn(ar, "failed to enable pktlog filter %x: %d\n",
2026 ar->debug.pktlog_filter, ret);
2030 ret = ath10k_wmi_pdev_pktlog_disable(ar);
2032 ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
2037 ar->debug.pktlog_filter = filter;
2041 mutex_unlock(&ar->conf_mutex);
2045 static ssize_t ath10k_read_pktlog_filter(struct file *file, char __user *ubuf,
2046 size_t count, loff_t *ppos)
2049 struct ath10k *ar = file->private_data;
2052 mutex_lock(&ar->conf_mutex);
2053 len = scnprintf(buf, sizeof(buf) - len, "%08x\n",
2054 ar->debug.pktlog_filter);
2055 mutex_unlock(&ar->conf_mutex);
2057 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
2060 static const struct file_operations fops_pktlog_filter = {
2061 .read = ath10k_read_pktlog_filter,
2062 .write = ath10k_write_pktlog_filter,
2066 static ssize_t ath10k_write_quiet_period(struct file *file,
2067 const char __user *ubuf,
2068 size_t count, loff_t *ppos)
2070 struct ath10k *ar = file->private_data;
2073 if (kstrtouint_from_user(ubuf, count, 0, &period))
2076 if (period < ATH10K_QUIET_PERIOD_MIN) {
2077 ath10k_warn(ar, "Quiet period %u can not be lesser than 25ms\n",
2081 mutex_lock(&ar->conf_mutex);
2082 ar->thermal.quiet_period = period;
2083 ath10k_thermal_set_throttling(ar);
2084 mutex_unlock(&ar->conf_mutex);
2089 static ssize_t ath10k_read_quiet_period(struct file *file, char __user *ubuf,
2090 size_t count, loff_t *ppos)
2093 struct ath10k *ar = file->private_data;
2096 mutex_lock(&ar->conf_mutex);
2097 len = scnprintf(buf, sizeof(buf) - len, "%d\n",
2098 ar->thermal.quiet_period);
2099 mutex_unlock(&ar->conf_mutex);
2101 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
2104 static const struct file_operations fops_quiet_period = {
2105 .read = ath10k_read_quiet_period,
2106 .write = ath10k_write_quiet_period,
2110 static ssize_t ath10k_write_btcoex(struct file *file,
2111 const char __user *ubuf,
2112 size_t count, loff_t *ppos)
2114 struct ath10k *ar = file->private_data;
2120 buf_size = min(count, (sizeof(buf) - 1));
2121 if (copy_from_user(buf, ubuf, buf_size))
2124 buf[buf_size] = '\0';
2126 if (strtobool(buf, &val) != 0)
2129 mutex_lock(&ar->conf_mutex);
2131 if (ar->state != ATH10K_STATE_ON &&
2132 ar->state != ATH10K_STATE_RESTARTED) {
2137 if (!(test_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags) ^ val))
2141 set_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
2143 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
2145 ath10k_info(ar, "restarting firmware due to btcoex change");
2147 queue_work(ar->workqueue, &ar->restart_work);
2151 mutex_unlock(&ar->conf_mutex);
2156 static ssize_t ath10k_read_btcoex(struct file *file, char __user *ubuf,
2157 size_t count, loff_t *ppos)
2160 struct ath10k *ar = file->private_data;
2163 mutex_lock(&ar->conf_mutex);
2164 len = scnprintf(buf, sizeof(buf) - len, "%d\n",
2165 test_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags));
2166 mutex_unlock(&ar->conf_mutex);
2168 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
2171 static const struct file_operations fops_btcoex = {
2172 .read = ath10k_read_btcoex,
2173 .write = ath10k_write_btcoex,
2177 static ssize_t ath10k_debug_fw_checksums_read(struct file *file,
2178 char __user *user_buf,
2179 size_t count, loff_t *ppos)
2181 struct ath10k *ar = file->private_data;
2182 unsigned int len = 0, buf_len = 4096;
2186 buf = kzalloc(buf_len, GFP_KERNEL);
2190 mutex_lock(&ar->conf_mutex);
2192 len += scnprintf(buf + len, buf_len - len,
2193 "firmware-N.bin\t\t%08x\n",
2194 crc32_le(0, ar->firmware->data, ar->firmware->size));
2195 len += scnprintf(buf + len, buf_len - len,
2196 "athwlan\t\t\t%08x\n",
2197 crc32_le(0, ar->firmware_data, ar->firmware_len));
2198 len += scnprintf(buf + len, buf_len - len,
2200 crc32_le(0, ar->otp_data, ar->otp_len));
2201 len += scnprintf(buf + len, buf_len - len,
2202 "codeswap\t\t%08x\n",
2203 crc32_le(0, ar->swap.firmware_codeswap_data,
2204 ar->swap.firmware_codeswap_len));
2205 len += scnprintf(buf + len, buf_len - len,
2206 "board-N.bin\t\t%08x\n",
2207 crc32_le(0, ar->board->data, ar->board->size));
2208 len += scnprintf(buf + len, buf_len - len,
2209 "board\t\t\t%08x\n",
2210 crc32_le(0, ar->board_data, ar->board_len));
2212 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
2214 mutex_unlock(&ar->conf_mutex);
2220 static const struct file_operations fops_fw_checksums = {
2221 .read = ath10k_debug_fw_checksums_read,
2222 .open = simple_open,
2223 .owner = THIS_MODULE,
2224 .llseek = default_llseek,
2227 int ath10k_debug_create(struct ath10k *ar)
2229 ar->debug.fw_crash_data = vzalloc(sizeof(*ar->debug.fw_crash_data));
2230 if (!ar->debug.fw_crash_data)
2233 INIT_LIST_HEAD(&ar->debug.fw_stats.pdevs);
2234 INIT_LIST_HEAD(&ar->debug.fw_stats.vdevs);
2235 INIT_LIST_HEAD(&ar->debug.fw_stats.peers);
2240 void ath10k_debug_destroy(struct ath10k *ar)
2242 vfree(ar->debug.fw_crash_data);
2243 ar->debug.fw_crash_data = NULL;
2245 ath10k_debug_fw_stats_reset(ar);
2247 kfree(ar->debug.tpc_stats);
2250 int ath10k_debug_register(struct ath10k *ar)
2252 ar->debug.debugfs_phy = debugfs_create_dir("ath10k",
2253 ar->hw->wiphy->debugfsdir);
2254 if (IS_ERR_OR_NULL(ar->debug.debugfs_phy)) {
2255 if (IS_ERR(ar->debug.debugfs_phy))
2256 return PTR_ERR(ar->debug.debugfs_phy);
2261 INIT_DELAYED_WORK(&ar->debug.htt_stats_dwork,
2262 ath10k_debug_htt_stats_dwork);
2264 init_completion(&ar->debug.tpc_complete);
2265 init_completion(&ar->debug.fw_stats_complete);
2267 debugfs_create_file("fw_stats", S_IRUSR, ar->debug.debugfs_phy, ar,
2270 debugfs_create_file("fw_reset_stats", S_IRUSR, ar->debug.debugfs_phy,
2271 ar, &fops_fw_reset_stats);
2273 debugfs_create_file("wmi_services", S_IRUSR, ar->debug.debugfs_phy, ar,
2274 &fops_wmi_services);
2276 debugfs_create_file("simulate_fw_crash", S_IRUSR | S_IWUSR,
2277 ar->debug.debugfs_phy, ar, &fops_simulate_fw_crash);
2279 debugfs_create_file("fw_crash_dump", S_IRUSR, ar->debug.debugfs_phy,
2280 ar, &fops_fw_crash_dump);
2282 debugfs_create_file("reg_addr", S_IRUSR | S_IWUSR,
2283 ar->debug.debugfs_phy, ar, &fops_reg_addr);
2285 debugfs_create_file("reg_value", S_IRUSR | S_IWUSR,
2286 ar->debug.debugfs_phy, ar, &fops_reg_value);
2288 debugfs_create_file("mem_value", S_IRUSR | S_IWUSR,
2289 ar->debug.debugfs_phy, ar, &fops_mem_value);
2291 debugfs_create_file("chip_id", S_IRUSR, ar->debug.debugfs_phy,
2294 debugfs_create_file("htt_stats_mask", S_IRUSR | S_IWUSR,
2295 ar->debug.debugfs_phy, ar, &fops_htt_stats_mask);
2297 debugfs_create_file("htt_max_amsdu_ampdu", S_IRUSR | S_IWUSR,
2298 ar->debug.debugfs_phy, ar,
2299 &fops_htt_max_amsdu_ampdu);
2301 debugfs_create_file("fw_dbglog", S_IRUSR | S_IWUSR,
2302 ar->debug.debugfs_phy, ar, &fops_fw_dbglog);
2304 debugfs_create_file("cal_data", S_IRUSR, ar->debug.debugfs_phy,
2305 ar, &fops_cal_data);
2307 debugfs_create_file("ani_enable", S_IRUSR | S_IWUSR,
2308 ar->debug.debugfs_phy, ar, &fops_ani_enable);
2310 debugfs_create_file("nf_cal_period", S_IRUSR | S_IWUSR,
2311 ar->debug.debugfs_phy, ar, &fops_nf_cal_period);
2313 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
2314 debugfs_create_file("dfs_simulate_radar", S_IWUSR,
2315 ar->debug.debugfs_phy, ar,
2316 &fops_simulate_radar);
2318 debugfs_create_bool("dfs_block_radar_events", S_IWUSR,
2319 ar->debug.debugfs_phy,
2320 &ar->dfs_block_radar_events);
2322 debugfs_create_file("dfs_stats", S_IRUSR,
2323 ar->debug.debugfs_phy, ar,
2327 debugfs_create_file("pktlog_filter", S_IRUGO | S_IWUSR,
2328 ar->debug.debugfs_phy, ar, &fops_pktlog_filter);
2330 debugfs_create_file("quiet_period", S_IRUGO | S_IWUSR,
2331 ar->debug.debugfs_phy, ar, &fops_quiet_period);
2333 debugfs_create_file("tpc_stats", S_IRUSR,
2334 ar->debug.debugfs_phy, ar, &fops_tpc_stats);
2336 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map))
2337 debugfs_create_file("btcoex", S_IRUGO | S_IWUSR,
2338 ar->debug.debugfs_phy, ar, &fops_btcoex);
2340 debugfs_create_file("fw_checksums", S_IRUSR,
2341 ar->debug.debugfs_phy, ar, &fops_fw_checksums);
2346 void ath10k_debug_unregister(struct ath10k *ar)
2348 cancel_delayed_work_sync(&ar->debug.htt_stats_dwork);
2351 #endif /* CONFIG_ATH10K_DEBUGFS */
2353 #ifdef CONFIG_ATH10K_DEBUG
2354 void ath10k_dbg(struct ath10k *ar, enum ath10k_debug_mask mask,
2355 const char *fmt, ...)
2357 struct va_format vaf;
2360 va_start(args, fmt);
2365 if (ath10k_debug_mask & mask)
2366 dev_printk(KERN_DEBUG, ar->dev, "%pV", &vaf);
2368 trace_ath10k_log_dbg(ar, mask, &vaf);
2372 EXPORT_SYMBOL(ath10k_dbg);
2374 void ath10k_dbg_dump(struct ath10k *ar,
2375 enum ath10k_debug_mask mask,
2376 const char *msg, const char *prefix,
2377 const void *buf, size_t len)
2380 unsigned int linebuflen;
2383 if (ath10k_debug_mask & mask) {
2385 ath10k_dbg(ar, mask, "%s\n", msg);
2387 for (ptr = buf; (ptr - buf) < len; ptr += 16) {
2389 linebuflen += scnprintf(linebuf + linebuflen,
2390 sizeof(linebuf) - linebuflen,
2392 (prefix ? prefix : ""),
2393 (unsigned int)(ptr - buf));
2394 hex_dump_to_buffer(ptr, len - (ptr - buf), 16, 1,
2395 linebuf + linebuflen,
2396 sizeof(linebuf) - linebuflen, true);
2397 dev_printk(KERN_DEBUG, ar->dev, "%s\n", linebuf);
2401 /* tracing code doesn't like null strings :/ */
2402 trace_ath10k_log_dbg_dump(ar, msg ? msg : "", prefix ? prefix : "",
2405 EXPORT_SYMBOL(ath10k_dbg_dump);
2407 #endif /* CONFIG_ATH10K_DEBUG */