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);
351 if (ar->debug.fw_stats_done && !peer_stats_svc) {
352 ath10k_warn(ar, "received unsolicited stats update event\n");
356 num_peers = ath10k_wmi_fw_stats_num_peers(&ar->debug.fw_stats.peers);
357 num_vdevs = ath10k_wmi_fw_stats_num_vdevs(&ar->debug.fw_stats.vdevs);
358 is_start = (list_empty(&ar->debug.fw_stats.pdevs) &&
359 !list_empty(&stats.pdevs));
360 is_end = (!list_empty(&ar->debug.fw_stats.pdevs) &&
361 !list_empty(&stats.pdevs));
364 list_splice_tail_init(&stats.pdevs, &ar->debug.fw_stats.pdevs);
367 ar->debug.fw_stats_done = true;
369 is_started = !list_empty(&ar->debug.fw_stats.pdevs);
371 if (is_started && !is_end) {
372 if (num_peers >= ATH10K_MAX_NUM_PEER_IDS) {
373 /* Although this is unlikely impose a sane limit to
374 * prevent firmware from DoS-ing the host.
376 ath10k_fw_stats_peers_free(&ar->debug.fw_stats.peers);
377 ath10k_warn(ar, "dropping fw peer stats\n");
381 if (num_vdevs >= BITS_PER_LONG) {
382 ath10k_fw_stats_vdevs_free(&ar->debug.fw_stats.vdevs);
383 ath10k_warn(ar, "dropping fw vdev stats\n");
388 ath10k_sta_update_rx_duration(ar, &stats.peers);
390 list_splice_tail_init(&stats.peers, &ar->debug.fw_stats.peers);
391 list_splice_tail_init(&stats.vdevs, &ar->debug.fw_stats.vdevs);
394 complete(&ar->debug.fw_stats_complete);
397 /* In some cases lists have been spliced and cleared. Free up
398 * resources if that is not the case.
400 ath10k_fw_stats_pdevs_free(&stats.pdevs);
401 ath10k_fw_stats_vdevs_free(&stats.vdevs);
402 ath10k_fw_stats_peers_free(&stats.peers);
404 spin_unlock_bh(&ar->data_lock);
407 static int ath10k_debug_fw_stats_request(struct ath10k *ar)
409 unsigned long timeout, time_left;
412 lockdep_assert_held(&ar->conf_mutex);
414 timeout = jiffies + msecs_to_jiffies(1 * HZ);
416 ath10k_debug_fw_stats_reset(ar);
419 if (time_after(jiffies, timeout))
422 reinit_completion(&ar->debug.fw_stats_complete);
424 ret = ath10k_wmi_request_stats(ar, ar->fw_stats_req_mask);
426 ath10k_warn(ar, "could not request stats (%d)\n", ret);
431 wait_for_completion_timeout(&ar->debug.fw_stats_complete,
436 spin_lock_bh(&ar->data_lock);
437 if (ar->debug.fw_stats_done) {
438 spin_unlock_bh(&ar->data_lock);
441 spin_unlock_bh(&ar->data_lock);
447 static int ath10k_fw_stats_open(struct inode *inode, struct file *file)
449 struct ath10k *ar = inode->i_private;
453 mutex_lock(&ar->conf_mutex);
455 if (ar->state != ATH10K_STATE_ON) {
460 buf = vmalloc(ATH10K_FW_STATS_BUF_SIZE);
466 ret = ath10k_debug_fw_stats_request(ar);
468 ath10k_warn(ar, "failed to request fw stats: %d\n", ret);
472 ret = ath10k_wmi_fw_stats_fill(ar, &ar->debug.fw_stats, buf);
474 ath10k_warn(ar, "failed to fill fw stats: %d\n", ret);
478 file->private_data = buf;
480 mutex_unlock(&ar->conf_mutex);
487 mutex_unlock(&ar->conf_mutex);
491 static int ath10k_fw_stats_release(struct inode *inode, struct file *file)
493 vfree(file->private_data);
498 static ssize_t ath10k_fw_stats_read(struct file *file, char __user *user_buf,
499 size_t count, loff_t *ppos)
501 const char *buf = file->private_data;
502 unsigned int len = strlen(buf);
504 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
507 static const struct file_operations fops_fw_stats = {
508 .open = ath10k_fw_stats_open,
509 .release = ath10k_fw_stats_release,
510 .read = ath10k_fw_stats_read,
511 .owner = THIS_MODULE,
512 .llseek = default_llseek,
515 static ssize_t ath10k_debug_fw_reset_stats_read(struct file *file,
516 char __user *user_buf,
517 size_t count, loff_t *ppos)
519 struct ath10k *ar = file->private_data;
520 int ret, len, buf_len;
524 buf = kmalloc(buf_len, GFP_KERNEL);
528 spin_lock_bh(&ar->data_lock);
531 len += scnprintf(buf + len, buf_len - len,
532 "fw_crash_counter\t\t%d\n", ar->stats.fw_crash_counter);
533 len += scnprintf(buf + len, buf_len - len,
534 "fw_warm_reset_counter\t\t%d\n",
535 ar->stats.fw_warm_reset_counter);
536 len += scnprintf(buf + len, buf_len - len,
537 "fw_cold_reset_counter\t\t%d\n",
538 ar->stats.fw_cold_reset_counter);
540 spin_unlock_bh(&ar->data_lock);
542 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
549 static const struct file_operations fops_fw_reset_stats = {
551 .read = ath10k_debug_fw_reset_stats_read,
552 .owner = THIS_MODULE,
553 .llseek = default_llseek,
556 /* This is a clean assert crash in firmware. */
557 static int ath10k_debug_fw_assert(struct ath10k *ar)
559 struct wmi_vdev_install_key_cmd *cmd;
562 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd) + 16);
566 cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
567 memset(cmd, 0, sizeof(*cmd));
569 /* big enough number so that firmware asserts */
570 cmd->vdev_id = __cpu_to_le32(0x7ffe);
572 return ath10k_wmi_cmd_send(ar, skb,
573 ar->wmi.cmd->vdev_install_key_cmdid);
576 static ssize_t ath10k_read_simulate_fw_crash(struct file *file,
577 char __user *user_buf,
578 size_t count, loff_t *ppos)
581 "To simulate firmware crash write one of the keywords to this file:\n"
582 "`soft` - this will send WMI_FORCE_FW_HANG_ASSERT to firmware if FW supports that command.\n"
583 "`hard` - this will send to firmware command with illegal parameters causing firmware crash.\n"
584 "`assert` - this will send special illegal parameter to firmware to cause assert failure and crash.\n"
585 "`hw-restart` - this will simply queue hw restart without fw/hw actually crashing.\n";
587 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
590 /* Simulate firmware crash:
591 * 'soft': Call wmi command causing firmware hang. This firmware hang is
592 * recoverable by warm firmware reset.
593 * 'hard': Force firmware crash by setting any vdev parameter for not allowed
594 * vdev id. This is hard firmware crash because it is recoverable only by cold
597 static ssize_t ath10k_write_simulate_fw_crash(struct file *file,
598 const char __user *user_buf,
599 size_t count, loff_t *ppos)
601 struct ath10k *ar = file->private_data;
605 mutex_lock(&ar->conf_mutex);
607 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
609 /* make sure that buf is null terminated */
610 buf[sizeof(buf) - 1] = 0;
612 if (ar->state != ATH10K_STATE_ON &&
613 ar->state != ATH10K_STATE_RESTARTED) {
618 /* drop the possible '\n' from the end */
619 if (buf[count - 1] == '\n') {
624 if (!strcmp(buf, "soft")) {
625 ath10k_info(ar, "simulating soft firmware crash\n");
626 ret = ath10k_wmi_force_fw_hang(ar, WMI_FORCE_FW_HANG_ASSERT, 0);
627 } else if (!strcmp(buf, "hard")) {
628 ath10k_info(ar, "simulating hard firmware crash\n");
629 /* 0x7fff is vdev id, and it is always out of range for all
630 * firmware variants in order to force a firmware crash.
632 ret = ath10k_wmi_vdev_set_param(ar, 0x7fff,
633 ar->wmi.vdev_param->rts_threshold,
635 } else if (!strcmp(buf, "assert")) {
636 ath10k_info(ar, "simulating firmware assert crash\n");
637 ret = ath10k_debug_fw_assert(ar);
638 } else if (!strcmp(buf, "hw-restart")) {
639 ath10k_info(ar, "user requested hw restart\n");
640 queue_work(ar->workqueue, &ar->restart_work);
648 ath10k_warn(ar, "failed to simulate firmware crash: %d\n", ret);
655 mutex_unlock(&ar->conf_mutex);
659 static const struct file_operations fops_simulate_fw_crash = {
660 .read = ath10k_read_simulate_fw_crash,
661 .write = ath10k_write_simulate_fw_crash,
663 .owner = THIS_MODULE,
664 .llseek = default_llseek,
667 static ssize_t ath10k_read_chip_id(struct file *file, char __user *user_buf,
668 size_t count, loff_t *ppos)
670 struct ath10k *ar = file->private_data;
674 len = scnprintf(buf, sizeof(buf), "0x%08x\n", ar->chip_id);
676 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
679 static const struct file_operations fops_chip_id = {
680 .read = ath10k_read_chip_id,
682 .owner = THIS_MODULE,
683 .llseek = default_llseek,
686 struct ath10k_fw_crash_data *
687 ath10k_debug_get_new_fw_crash_data(struct ath10k *ar)
689 struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data;
691 lockdep_assert_held(&ar->data_lock);
693 crash_data->crashed_since_read = true;
694 uuid_le_gen(&crash_data->uuid);
695 getnstimeofday(&crash_data->timestamp);
699 EXPORT_SYMBOL(ath10k_debug_get_new_fw_crash_data);
701 static struct ath10k_dump_file_data *ath10k_build_dump_file(struct ath10k *ar)
703 struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data;
704 struct ath10k_dump_file_data *dump_data;
705 struct ath10k_tlv_dump_data *dump_tlv;
706 int hdr_len = sizeof(*dump_data);
707 unsigned int len, sofar = 0;
711 len += sizeof(*dump_tlv) + sizeof(crash_data->registers);
715 /* This is going to get big when we start dumping FW RAM and such,
716 * so go ahead and use vmalloc.
722 spin_lock_bh(&ar->data_lock);
724 if (!crash_data->crashed_since_read) {
725 spin_unlock_bh(&ar->data_lock);
730 dump_data = (struct ath10k_dump_file_data *)(buf);
731 strlcpy(dump_data->df_magic, "ATH10K-FW-DUMP",
732 sizeof(dump_data->df_magic));
733 dump_data->len = cpu_to_le32(len);
735 dump_data->version = cpu_to_le32(ATH10K_FW_CRASH_DUMP_VERSION);
737 memcpy(dump_data->uuid, &crash_data->uuid, sizeof(dump_data->uuid));
738 dump_data->chip_id = cpu_to_le32(ar->chip_id);
739 dump_data->bus_type = cpu_to_le32(0);
740 dump_data->target_version = cpu_to_le32(ar->target_version);
741 dump_data->fw_version_major = cpu_to_le32(ar->fw_version_major);
742 dump_data->fw_version_minor = cpu_to_le32(ar->fw_version_minor);
743 dump_data->fw_version_release = cpu_to_le32(ar->fw_version_release);
744 dump_data->fw_version_build = cpu_to_le32(ar->fw_version_build);
745 dump_data->phy_capability = cpu_to_le32(ar->phy_capability);
746 dump_data->hw_min_tx_power = cpu_to_le32(ar->hw_min_tx_power);
747 dump_data->hw_max_tx_power = cpu_to_le32(ar->hw_max_tx_power);
748 dump_data->ht_cap_info = cpu_to_le32(ar->ht_cap_info);
749 dump_data->vht_cap_info = cpu_to_le32(ar->vht_cap_info);
750 dump_data->num_rf_chains = cpu_to_le32(ar->num_rf_chains);
752 strlcpy(dump_data->fw_ver, ar->hw->wiphy->fw_version,
753 sizeof(dump_data->fw_ver));
755 dump_data->kernel_ver_code = 0;
756 strlcpy(dump_data->kernel_ver, init_utsname()->release,
757 sizeof(dump_data->kernel_ver));
759 dump_data->tv_sec = cpu_to_le64(crash_data->timestamp.tv_sec);
760 dump_data->tv_nsec = cpu_to_le64(crash_data->timestamp.tv_nsec);
762 /* Gather crash-dump */
763 dump_tlv = (struct ath10k_tlv_dump_data *)(buf + sofar);
764 dump_tlv->type = cpu_to_le32(ATH10K_FW_CRASH_DUMP_REGISTERS);
765 dump_tlv->tlv_len = cpu_to_le32(sizeof(crash_data->registers));
766 memcpy(dump_tlv->tlv_data, &crash_data->registers,
767 sizeof(crash_data->registers));
768 sofar += sizeof(*dump_tlv) + sizeof(crash_data->registers);
770 ar->debug.fw_crash_data->crashed_since_read = false;
772 spin_unlock_bh(&ar->data_lock);
777 static int ath10k_fw_crash_dump_open(struct inode *inode, struct file *file)
779 struct ath10k *ar = inode->i_private;
780 struct ath10k_dump_file_data *dump;
782 dump = ath10k_build_dump_file(ar);
786 file->private_data = dump;
791 static ssize_t ath10k_fw_crash_dump_read(struct file *file,
792 char __user *user_buf,
793 size_t count, loff_t *ppos)
795 struct ath10k_dump_file_data *dump_file = file->private_data;
797 return simple_read_from_buffer(user_buf, count, ppos,
799 le32_to_cpu(dump_file->len));
802 static int ath10k_fw_crash_dump_release(struct inode *inode,
805 vfree(file->private_data);
810 static const struct file_operations fops_fw_crash_dump = {
811 .open = ath10k_fw_crash_dump_open,
812 .read = ath10k_fw_crash_dump_read,
813 .release = ath10k_fw_crash_dump_release,
814 .owner = THIS_MODULE,
815 .llseek = default_llseek,
818 static ssize_t ath10k_reg_addr_read(struct file *file,
819 char __user *user_buf,
820 size_t count, loff_t *ppos)
822 struct ath10k *ar = file->private_data;
824 unsigned int len = 0;
827 mutex_lock(&ar->conf_mutex);
828 reg_addr = ar->debug.reg_addr;
829 mutex_unlock(&ar->conf_mutex);
831 len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n", reg_addr);
833 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
836 static ssize_t ath10k_reg_addr_write(struct file *file,
837 const char __user *user_buf,
838 size_t count, loff_t *ppos)
840 struct ath10k *ar = file->private_data;
844 ret = kstrtou32_from_user(user_buf, count, 0, ®_addr);
848 if (!IS_ALIGNED(reg_addr, 4))
851 mutex_lock(&ar->conf_mutex);
852 ar->debug.reg_addr = reg_addr;
853 mutex_unlock(&ar->conf_mutex);
858 static const struct file_operations fops_reg_addr = {
859 .read = ath10k_reg_addr_read,
860 .write = ath10k_reg_addr_write,
862 .owner = THIS_MODULE,
863 .llseek = default_llseek,
866 static ssize_t ath10k_reg_value_read(struct file *file,
867 char __user *user_buf,
868 size_t count, loff_t *ppos)
870 struct ath10k *ar = file->private_data;
873 u32 reg_addr, reg_val;
876 mutex_lock(&ar->conf_mutex);
878 if (ar->state != ATH10K_STATE_ON &&
879 ar->state != ATH10K_STATE_UTF) {
884 reg_addr = ar->debug.reg_addr;
886 reg_val = ath10k_hif_read32(ar, reg_addr);
887 len = scnprintf(buf, sizeof(buf), "0x%08x:0x%08x\n", reg_addr, reg_val);
889 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
892 mutex_unlock(&ar->conf_mutex);
897 static ssize_t ath10k_reg_value_write(struct file *file,
898 const char __user *user_buf,
899 size_t count, loff_t *ppos)
901 struct ath10k *ar = file->private_data;
902 u32 reg_addr, reg_val;
905 mutex_lock(&ar->conf_mutex);
907 if (ar->state != ATH10K_STATE_ON &&
908 ar->state != ATH10K_STATE_UTF) {
913 reg_addr = ar->debug.reg_addr;
915 ret = kstrtou32_from_user(user_buf, count, 0, ®_val);
919 ath10k_hif_write32(ar, reg_addr, reg_val);
924 mutex_unlock(&ar->conf_mutex);
929 static const struct file_operations fops_reg_value = {
930 .read = ath10k_reg_value_read,
931 .write = ath10k_reg_value_write,
933 .owner = THIS_MODULE,
934 .llseek = default_llseek,
937 static ssize_t ath10k_mem_value_read(struct file *file,
938 char __user *user_buf,
939 size_t count, loff_t *ppos)
941 struct ath10k *ar = file->private_data;
951 mutex_lock(&ar->conf_mutex);
953 buf = vmalloc(count);
959 if (ar->state != ATH10K_STATE_ON &&
960 ar->state != ATH10K_STATE_UTF) {
965 ret = ath10k_hif_diag_read(ar, *ppos, buf, count);
967 ath10k_warn(ar, "failed to read address 0x%08x via diagnose window fnrom debugfs: %d\n",
972 ret = copy_to_user(user_buf, buf, count);
984 mutex_unlock(&ar->conf_mutex);
989 static ssize_t ath10k_mem_value_write(struct file *file,
990 const char __user *user_buf,
991 size_t count, loff_t *ppos)
993 struct ath10k *ar = file->private_data;
1003 mutex_lock(&ar->conf_mutex);
1005 buf = vmalloc(count);
1011 if (ar->state != ATH10K_STATE_ON &&
1012 ar->state != ATH10K_STATE_UTF) {
1017 ret = copy_from_user(buf, user_buf, count);
1023 ret = ath10k_hif_diag_write(ar, *ppos, buf, count);
1025 ath10k_warn(ar, "failed to write address 0x%08x via diagnose window from debugfs: %d\n",
1035 mutex_unlock(&ar->conf_mutex);
1040 static const struct file_operations fops_mem_value = {
1041 .read = ath10k_mem_value_read,
1042 .write = ath10k_mem_value_write,
1043 .open = simple_open,
1044 .owner = THIS_MODULE,
1045 .llseek = default_llseek,
1048 static int ath10k_debug_htt_stats_req(struct ath10k *ar)
1053 lockdep_assert_held(&ar->conf_mutex);
1055 if (ar->debug.htt_stats_mask == 0)
1056 /* htt stats are disabled */
1059 if (ar->state != ATH10K_STATE_ON)
1062 cookie = get_jiffies_64();
1064 ret = ath10k_htt_h2t_stats_req(&ar->htt, ar->debug.htt_stats_mask,
1067 ath10k_warn(ar, "failed to send htt stats request: %d\n", ret);
1071 queue_delayed_work(ar->workqueue, &ar->debug.htt_stats_dwork,
1072 msecs_to_jiffies(ATH10K_DEBUG_HTT_STATS_INTERVAL));
1077 static void ath10k_debug_htt_stats_dwork(struct work_struct *work)
1079 struct ath10k *ar = container_of(work, struct ath10k,
1080 debug.htt_stats_dwork.work);
1082 mutex_lock(&ar->conf_mutex);
1084 ath10k_debug_htt_stats_req(ar);
1086 mutex_unlock(&ar->conf_mutex);
1089 static ssize_t ath10k_read_htt_stats_mask(struct file *file,
1090 char __user *user_buf,
1091 size_t count, loff_t *ppos)
1093 struct ath10k *ar = file->private_data;
1097 len = scnprintf(buf, sizeof(buf), "%lu\n", ar->debug.htt_stats_mask);
1099 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1102 static ssize_t ath10k_write_htt_stats_mask(struct file *file,
1103 const char __user *user_buf,
1104 size_t count, loff_t *ppos)
1106 struct ath10k *ar = file->private_data;
1110 ret = kstrtoul_from_user(user_buf, count, 0, &mask);
1114 /* max 8 bit masks (for now) */
1118 mutex_lock(&ar->conf_mutex);
1120 ar->debug.htt_stats_mask = mask;
1122 ret = ath10k_debug_htt_stats_req(ar);
1129 mutex_unlock(&ar->conf_mutex);
1134 static const struct file_operations fops_htt_stats_mask = {
1135 .read = ath10k_read_htt_stats_mask,
1136 .write = ath10k_write_htt_stats_mask,
1137 .open = simple_open,
1138 .owner = THIS_MODULE,
1139 .llseek = default_llseek,
1142 static ssize_t ath10k_read_htt_max_amsdu_ampdu(struct file *file,
1143 char __user *user_buf,
1144 size_t count, loff_t *ppos)
1146 struct ath10k *ar = file->private_data;
1151 mutex_lock(&ar->conf_mutex);
1153 amsdu = ar->htt.max_num_amsdu;
1154 ampdu = ar->htt.max_num_ampdu;
1155 mutex_unlock(&ar->conf_mutex);
1157 len = scnprintf(buf, sizeof(buf), "%u %u\n", amsdu, ampdu);
1159 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1162 static ssize_t ath10k_write_htt_max_amsdu_ampdu(struct file *file,
1163 const char __user *user_buf,
1164 size_t count, loff_t *ppos)
1166 struct ath10k *ar = file->private_data;
1169 unsigned int amsdu, ampdu;
1171 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
1173 /* make sure that buf is null terminated */
1174 buf[sizeof(buf) - 1] = 0;
1176 res = sscanf(buf, "%u %u", &amsdu, &du);
1181 mutex_lock(&ar->conf_mutex);
1183 res = ath10k_htt_h2t_aggr_cfg_msg(&ar->htt, ampdu, amsdu);
1188 ar->htt.max_num_amsdu = amsdu;
1189 ar->htt.max_num_ampdu = ampdu;
1192 mutex_unlock(&ar->conf_mutex);
1196 static const struct file_operations fops_htt_max_amsdu_ampdu = {
1197 .read = ath10k_read_htt_max_amsdu_ampdu,
1198 .write = ath10k_write_htt_max_amsdu_ampdu,
1199 .open = simple_open,
1200 .owner = THIS_MODULE,
1201 .llseek = default_llseek,
1204 static ssize_t ath10k_read_fw_dbglog(struct file *file,
1205 char __user *user_buf,
1206 size_t count, loff_t *ppos)
1208 struct ath10k *ar = file->private_data;
1212 len = scnprintf(buf, sizeof(buf), "0x%08x %u\n",
1213 ar->debug.fw_dbglog_mask, ar->debug.fw_dbglog_level);
1215 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1218 static ssize_t ath10k_write_fw_dbglog(struct file *file,
1219 const char __user *user_buf,
1220 size_t count, loff_t *ppos)
1222 struct ath10k *ar = file->private_data;
1225 unsigned int log_level, mask;
1227 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
1229 /* make sure that buf is null terminated */
1230 buf[sizeof(buf) - 1] = 0;
1232 ret = sscanf(buf, "%x %u", &mask, &log_level);
1238 /* default if user did not specify */
1239 log_level = ATH10K_DBGLOG_LEVEL_WARN;
1241 mutex_lock(&ar->conf_mutex);
1243 ar->debug.fw_dbglog_mask = mask;
1244 ar->debug.fw_dbglog_level = log_level;
1246 if (ar->state == ATH10K_STATE_ON) {
1247 ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask,
1248 ar->debug.fw_dbglog_level);
1250 ath10k_warn(ar, "dbglog cfg failed from debugfs: %d\n",
1259 mutex_unlock(&ar->conf_mutex);
1264 /* TODO: Would be nice to always support ethtool stats, would need to
1265 * move the stats storage out of ath10k_debug, or always have ath10k_debug
1266 * struct available..
1269 /* This generally cooresponds to the debugfs fw_stats file */
1270 static const char ath10k_gstrings_stats[][ETH_GSTRING_LEN] = {
1280 "d_tx_power", /* in .5 dbM I think */
1281 "d_rx_crc_err", /* fcs_bad */
1283 "d_tx_mpdus_queued",
1285 "d_tx_msdu_dropped",
1288 "d_tx_ppdu_hw_queued",
1290 "d_tx_fifo_underrun",
1293 "d_tx_excessive_retries",
1295 "d_tx_dropped_sw_retries",
1296 "d_tx_illegal_rate",
1297 "d_tx_continuous_xretries",
1299 "d_tx_mpdu_txop_limit",
1301 "d_rx_mid_ppdu_route_change",
1303 "d_rx_extra_frags_ring0",
1304 "d_rx_extra_frags_ring1",
1305 "d_rx_extra_frags_ring2",
1306 "d_rx_extra_frags_ring3",
1312 "d_rx_phy_err_drops",
1313 "d_rx_mpdu_errors", /* FCS, MIC, ENC */
1315 "d_fw_warm_reset_count",
1316 "d_fw_cold_reset_count",
1319 #define ATH10K_SSTATS_LEN ARRAY_SIZE(ath10k_gstrings_stats)
1321 void ath10k_debug_get_et_strings(struct ieee80211_hw *hw,
1322 struct ieee80211_vif *vif,
1325 if (sset == ETH_SS_STATS)
1326 memcpy(data, *ath10k_gstrings_stats,
1327 sizeof(ath10k_gstrings_stats));
1330 int ath10k_debug_get_et_sset_count(struct ieee80211_hw *hw,
1331 struct ieee80211_vif *vif, int sset)
1333 if (sset == ETH_SS_STATS)
1334 return ATH10K_SSTATS_LEN;
1339 void ath10k_debug_get_et_stats(struct ieee80211_hw *hw,
1340 struct ieee80211_vif *vif,
1341 struct ethtool_stats *stats, u64 *data)
1343 struct ath10k *ar = hw->priv;
1344 static const struct ath10k_fw_stats_pdev zero_stats = {};
1345 const struct ath10k_fw_stats_pdev *pdev_stats;
1348 mutex_lock(&ar->conf_mutex);
1350 if (ar->state == ATH10K_STATE_ON) {
1351 ret = ath10k_debug_fw_stats_request(ar);
1353 /* just print a warning and try to use older results */
1355 "failed to get fw stats for ethtool: %d\n",
1360 pdev_stats = list_first_entry_or_null(&ar->debug.fw_stats.pdevs,
1361 struct ath10k_fw_stats_pdev,
1364 /* no results available so just return zeroes */
1365 pdev_stats = &zero_stats;
1368 spin_lock_bh(&ar->data_lock);
1370 data[i++] = pdev_stats->hw_reaped; /* ppdu reaped */
1371 data[i++] = 0; /* tx bytes */
1372 data[i++] = pdev_stats->htt_mpdus;
1373 data[i++] = 0; /* rx bytes */
1374 data[i++] = pdev_stats->ch_noise_floor;
1375 data[i++] = pdev_stats->cycle_count;
1376 data[i++] = pdev_stats->phy_err_count;
1377 data[i++] = pdev_stats->rts_bad;
1378 data[i++] = pdev_stats->rts_good;
1379 data[i++] = pdev_stats->chan_tx_power;
1380 data[i++] = pdev_stats->fcs_bad;
1381 data[i++] = pdev_stats->no_beacons;
1382 data[i++] = pdev_stats->mpdu_enqued;
1383 data[i++] = pdev_stats->msdu_enqued;
1384 data[i++] = pdev_stats->wmm_drop;
1385 data[i++] = pdev_stats->local_enqued;
1386 data[i++] = pdev_stats->local_freed;
1387 data[i++] = pdev_stats->hw_queued;
1388 data[i++] = pdev_stats->hw_reaped;
1389 data[i++] = pdev_stats->underrun;
1390 data[i++] = pdev_stats->tx_abort;
1391 data[i++] = pdev_stats->mpdus_requed;
1392 data[i++] = pdev_stats->tx_ko;
1393 data[i++] = pdev_stats->data_rc;
1394 data[i++] = pdev_stats->sw_retry_failure;
1395 data[i++] = pdev_stats->illgl_rate_phy_err;
1396 data[i++] = pdev_stats->pdev_cont_xretry;
1397 data[i++] = pdev_stats->pdev_tx_timeout;
1398 data[i++] = pdev_stats->txop_ovf;
1399 data[i++] = pdev_stats->pdev_resets;
1400 data[i++] = pdev_stats->mid_ppdu_route_change;
1401 data[i++] = pdev_stats->status_rcvd;
1402 data[i++] = pdev_stats->r0_frags;
1403 data[i++] = pdev_stats->r1_frags;
1404 data[i++] = pdev_stats->r2_frags;
1405 data[i++] = pdev_stats->r3_frags;
1406 data[i++] = pdev_stats->htt_msdus;
1407 data[i++] = pdev_stats->htt_mpdus;
1408 data[i++] = pdev_stats->loc_msdus;
1409 data[i++] = pdev_stats->loc_mpdus;
1410 data[i++] = pdev_stats->phy_errs;
1411 data[i++] = pdev_stats->phy_err_drop;
1412 data[i++] = pdev_stats->mpdu_errs;
1413 data[i++] = ar->stats.fw_crash_counter;
1414 data[i++] = ar->stats.fw_warm_reset_counter;
1415 data[i++] = ar->stats.fw_cold_reset_counter;
1417 spin_unlock_bh(&ar->data_lock);
1419 mutex_unlock(&ar->conf_mutex);
1421 WARN_ON(i != ATH10K_SSTATS_LEN);
1424 static const struct file_operations fops_fw_dbglog = {
1425 .read = ath10k_read_fw_dbglog,
1426 .write = ath10k_write_fw_dbglog,
1427 .open = simple_open,
1428 .owner = THIS_MODULE,
1429 .llseek = default_llseek,
1432 static int ath10k_debug_cal_data_open(struct inode *inode, struct file *file)
1434 struct ath10k *ar = inode->i_private;
1440 mutex_lock(&ar->conf_mutex);
1442 if (ar->state != ATH10K_STATE_ON &&
1443 ar->state != ATH10K_STATE_UTF) {
1448 buf = vmalloc(QCA988X_CAL_DATA_LEN);
1454 hi_addr = host_interest_item_address(HI_ITEM(hi_board_data));
1456 ret = ath10k_hif_diag_read(ar, hi_addr, &addr, sizeof(addr));
1458 ath10k_warn(ar, "failed to read hi_board_data address: %d\n", ret);
1462 ret = ath10k_hif_diag_read(ar, le32_to_cpu(addr), buf,
1463 QCA988X_CAL_DATA_LEN);
1465 ath10k_warn(ar, "failed to read calibration data: %d\n", ret);
1469 file->private_data = buf;
1471 mutex_unlock(&ar->conf_mutex);
1479 mutex_unlock(&ar->conf_mutex);
1484 static ssize_t ath10k_debug_cal_data_read(struct file *file,
1485 char __user *user_buf,
1486 size_t count, loff_t *ppos)
1488 void *buf = file->private_data;
1490 return simple_read_from_buffer(user_buf, count, ppos,
1491 buf, QCA988X_CAL_DATA_LEN);
1494 static int ath10k_debug_cal_data_release(struct inode *inode,
1497 vfree(file->private_data);
1502 static ssize_t ath10k_write_ani_enable(struct file *file,
1503 const char __user *user_buf,
1504 size_t count, loff_t *ppos)
1506 struct ath10k *ar = file->private_data;
1510 if (kstrtou8_from_user(user_buf, count, 0, &enable))
1513 mutex_lock(&ar->conf_mutex);
1515 if (ar->ani_enabled == enable) {
1520 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->ani_enable,
1523 ath10k_warn(ar, "ani_enable failed from debugfs: %d\n", ret);
1526 ar->ani_enabled = enable;
1531 mutex_unlock(&ar->conf_mutex);
1536 static ssize_t ath10k_read_ani_enable(struct file *file, char __user *user_buf,
1537 size_t count, loff_t *ppos)
1539 struct ath10k *ar = file->private_data;
1543 len = scnprintf(buf, sizeof(buf) - len, "%d\n",
1546 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1549 static const struct file_operations fops_ani_enable = {
1550 .read = ath10k_read_ani_enable,
1551 .write = ath10k_write_ani_enable,
1552 .open = simple_open,
1553 .owner = THIS_MODULE,
1554 .llseek = default_llseek,
1557 static const struct file_operations fops_cal_data = {
1558 .open = ath10k_debug_cal_data_open,
1559 .read = ath10k_debug_cal_data_read,
1560 .release = ath10k_debug_cal_data_release,
1561 .owner = THIS_MODULE,
1562 .llseek = default_llseek,
1565 static ssize_t ath10k_read_nf_cal_period(struct file *file,
1566 char __user *user_buf,
1567 size_t count, loff_t *ppos)
1569 struct ath10k *ar = file->private_data;
1573 len = scnprintf(buf, sizeof(buf), "%d\n",
1574 ar->debug.nf_cal_period);
1576 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1579 static ssize_t ath10k_write_nf_cal_period(struct file *file,
1580 const char __user *user_buf,
1581 size_t count, loff_t *ppos)
1583 struct ath10k *ar = file->private_data;
1584 unsigned long period;
1587 ret = kstrtoul_from_user(user_buf, count, 0, &period);
1591 if (period > WMI_PDEV_PARAM_CAL_PERIOD_MAX)
1594 /* there's no way to switch back to the firmware default */
1598 mutex_lock(&ar->conf_mutex);
1600 ar->debug.nf_cal_period = period;
1602 if (ar->state != ATH10K_STATE_ON) {
1603 /* firmware is not running, nothing else to do */
1608 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->cal_period,
1609 ar->debug.nf_cal_period);
1611 ath10k_warn(ar, "cal period cfg failed from debugfs: %d\n",
1619 mutex_unlock(&ar->conf_mutex);
1624 static const struct file_operations fops_nf_cal_period = {
1625 .read = ath10k_read_nf_cal_period,
1626 .write = ath10k_write_nf_cal_period,
1627 .open = simple_open,
1628 .owner = THIS_MODULE,
1629 .llseek = default_llseek,
1632 #define ATH10K_TPC_CONFIG_BUF_SIZE (1024 * 1024)
1634 static int ath10k_debug_tpc_stats_request(struct ath10k *ar)
1637 unsigned long time_left;
1639 lockdep_assert_held(&ar->conf_mutex);
1641 reinit_completion(&ar->debug.tpc_complete);
1643 ret = ath10k_wmi_pdev_get_tpc_config(ar, WMI_TPC_CONFIG_PARAM);
1645 ath10k_warn(ar, "failed to request tpc config: %d\n", ret);
1649 time_left = wait_for_completion_timeout(&ar->debug.tpc_complete,
1657 void ath10k_debug_tpc_stats_process(struct ath10k *ar,
1658 struct ath10k_tpc_stats *tpc_stats)
1660 spin_lock_bh(&ar->data_lock);
1662 kfree(ar->debug.tpc_stats);
1663 ar->debug.tpc_stats = tpc_stats;
1664 complete(&ar->debug.tpc_complete);
1666 spin_unlock_bh(&ar->data_lock);
1669 static void ath10k_tpc_stats_print(struct ath10k_tpc_stats *tpc_stats,
1670 unsigned int j, char *buf, unsigned int *len)
1672 unsigned int i, buf_len;
1673 static const char table_str[][5] = { "CDD",
1676 static const char pream_str[][6] = { "CCK",
1685 buf_len = ATH10K_TPC_CONFIG_BUF_SIZE;
1686 *len += scnprintf(buf + *len, buf_len - *len,
1687 "********************************\n");
1688 *len += scnprintf(buf + *len, buf_len - *len,
1689 "******************* %s POWER TABLE ****************\n",
1691 *len += scnprintf(buf + *len, buf_len - *len,
1692 "********************************\n");
1693 *len += scnprintf(buf + *len, buf_len - *len,
1694 "No. Preamble Rate_code tpc_value1 tpc_value2 tpc_value3\n");
1696 for (i = 0; i < tpc_stats->rate_max; i++) {
1697 *len += scnprintf(buf + *len, buf_len - *len,
1698 "%8d %s 0x%2x %s\n", i,
1699 pream_str[tpc_stats->tpc_table[j].pream_idx[i]],
1700 tpc_stats->tpc_table[j].rate_code[i],
1701 tpc_stats->tpc_table[j].tpc_value[i]);
1704 *len += scnprintf(buf + *len, buf_len - *len,
1705 "***********************************\n");
1708 static void ath10k_tpc_stats_fill(struct ath10k *ar,
1709 struct ath10k_tpc_stats *tpc_stats,
1712 unsigned int len, j, buf_len;
1715 buf_len = ATH10K_TPC_CONFIG_BUF_SIZE;
1717 spin_lock_bh(&ar->data_lock);
1720 ath10k_warn(ar, "failed to get tpc stats\n");
1724 len += scnprintf(buf + len, buf_len - len, "\n");
1725 len += scnprintf(buf + len, buf_len - len,
1726 "*************************************\n");
1727 len += scnprintf(buf + len, buf_len - len,
1728 "TPC config for channel %4d mode %d\n",
1729 tpc_stats->chan_freq,
1730 tpc_stats->phy_mode);
1731 len += scnprintf(buf + len, buf_len - len,
1732 "*************************************\n");
1733 len += scnprintf(buf + len, buf_len - len,
1734 "CTL = 0x%2x Reg. Domain = %2d\n",
1736 tpc_stats->reg_domain);
1737 len += scnprintf(buf + len, buf_len - len,
1738 "Antenna Gain = %2d Reg. Max Antenna Gain = %2d\n",
1739 tpc_stats->twice_antenna_gain,
1740 tpc_stats->twice_antenna_reduction);
1741 len += scnprintf(buf + len, buf_len - len,
1742 "Power Limit = %2d Reg. Max Power = %2d\n",
1743 tpc_stats->power_limit,
1744 tpc_stats->twice_max_rd_power / 2);
1745 len += scnprintf(buf + len, buf_len - len,
1746 "Num tx chains = %2d Num supported rates = %2d\n",
1747 tpc_stats->num_tx_chain,
1748 tpc_stats->rate_max);
1750 for (j = 0; j < tpc_stats->num_tx_chain ; j++) {
1752 case WMI_TPC_TABLE_TYPE_CDD:
1753 if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) {
1754 len += scnprintf(buf + len, buf_len - len,
1755 "CDD not supported\n");
1759 ath10k_tpc_stats_print(tpc_stats, j, buf, &len);
1761 case WMI_TPC_TABLE_TYPE_STBC:
1762 if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) {
1763 len += scnprintf(buf + len, buf_len - len,
1764 "STBC not supported\n");
1768 ath10k_tpc_stats_print(tpc_stats, j, buf, &len);
1770 case WMI_TPC_TABLE_TYPE_TXBF:
1771 if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) {
1772 len += scnprintf(buf + len, buf_len - len,
1773 "TXBF not supported\n***************************\n");
1777 ath10k_tpc_stats_print(tpc_stats, j, buf, &len);
1780 len += scnprintf(buf + len, buf_len - len,
1787 spin_unlock_bh(&ar->data_lock);
1795 static int ath10k_tpc_stats_open(struct inode *inode, struct file *file)
1797 struct ath10k *ar = inode->i_private;
1801 mutex_lock(&ar->conf_mutex);
1803 if (ar->state != ATH10K_STATE_ON) {
1808 buf = vmalloc(ATH10K_TPC_CONFIG_BUF_SIZE);
1814 ret = ath10k_debug_tpc_stats_request(ar);
1816 ath10k_warn(ar, "failed to request tpc config stats: %d\n",
1821 ath10k_tpc_stats_fill(ar, ar->debug.tpc_stats, buf);
1822 file->private_data = buf;
1824 mutex_unlock(&ar->conf_mutex);
1831 mutex_unlock(&ar->conf_mutex);
1835 static int ath10k_tpc_stats_release(struct inode *inode, struct file *file)
1837 vfree(file->private_data);
1842 static ssize_t ath10k_tpc_stats_read(struct file *file, char __user *user_buf,
1843 size_t count, loff_t *ppos)
1845 const char *buf = file->private_data;
1846 unsigned int len = strlen(buf);
1848 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1851 static const struct file_operations fops_tpc_stats = {
1852 .open = ath10k_tpc_stats_open,
1853 .release = ath10k_tpc_stats_release,
1854 .read = ath10k_tpc_stats_read,
1855 .owner = THIS_MODULE,
1856 .llseek = default_llseek,
1859 int ath10k_debug_start(struct ath10k *ar)
1863 lockdep_assert_held(&ar->conf_mutex);
1865 ret = ath10k_debug_htt_stats_req(ar);
1867 /* continue normally anyway, this isn't serious */
1868 ath10k_warn(ar, "failed to start htt stats workqueue: %d\n",
1871 if (ar->debug.fw_dbglog_mask) {
1872 ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask,
1873 ATH10K_DBGLOG_LEVEL_WARN);
1876 ath10k_warn(ar, "failed to enable dbglog during start: %d",
1880 if (ar->debug.pktlog_filter) {
1881 ret = ath10k_wmi_pdev_pktlog_enable(ar,
1882 ar->debug.pktlog_filter);
1886 "failed to enable pktlog filter %x: %d\n",
1887 ar->debug.pktlog_filter, ret);
1889 ret = ath10k_wmi_pdev_pktlog_disable(ar);
1892 ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
1895 if (ar->debug.nf_cal_period) {
1896 ret = ath10k_wmi_pdev_set_param(ar,
1897 ar->wmi.pdev_param->cal_period,
1898 ar->debug.nf_cal_period);
1901 ath10k_warn(ar, "cal period cfg failed from debug start: %d\n",
1908 void ath10k_debug_stop(struct ath10k *ar)
1910 lockdep_assert_held(&ar->conf_mutex);
1912 /* Must not use _sync to avoid deadlock, we do that in
1913 * ath10k_debug_destroy(). The check for htt_stats_mask is to avoid
1914 * warning from del_timer(). */
1915 if (ar->debug.htt_stats_mask != 0)
1916 cancel_delayed_work(&ar->debug.htt_stats_dwork);
1918 ath10k_wmi_pdev_pktlog_disable(ar);
1921 static ssize_t ath10k_write_simulate_radar(struct file *file,
1922 const char __user *user_buf,
1923 size_t count, loff_t *ppos)
1925 struct ath10k *ar = file->private_data;
1927 ieee80211_radar_detected(ar->hw);
1932 static const struct file_operations fops_simulate_radar = {
1933 .write = ath10k_write_simulate_radar,
1934 .open = simple_open,
1935 .owner = THIS_MODULE,
1936 .llseek = default_llseek,
1939 #define ATH10K_DFS_STAT(s, p) (\
1940 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1941 ar->debug.dfs_stats.p))
1943 #define ATH10K_DFS_POOL_STAT(s, p) (\
1944 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1945 ar->debug.dfs_pool_stats.p))
1947 static ssize_t ath10k_read_dfs_stats(struct file *file, char __user *user_buf,
1948 size_t count, loff_t *ppos)
1950 int retval = 0, len = 0;
1951 const int size = 8000;
1952 struct ath10k *ar = file->private_data;
1955 buf = kzalloc(size, GFP_KERNEL);
1959 if (!ar->dfs_detector) {
1960 len += scnprintf(buf + len, size - len, "DFS not enabled\n");
1964 ar->debug.dfs_pool_stats =
1965 ar->dfs_detector->get_stats(ar->dfs_detector);
1967 len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n");
1969 ATH10K_DFS_STAT("reported phy errors", phy_errors);
1970 ATH10K_DFS_STAT("pulse events reported", pulses_total);
1971 ATH10K_DFS_STAT("DFS pulses detected", pulses_detected);
1972 ATH10K_DFS_STAT("DFS pulses discarded", pulses_discarded);
1973 ATH10K_DFS_STAT("Radars detected", radar_detected);
1975 len += scnprintf(buf + len, size - len, "Global Pool statistics:\n");
1976 ATH10K_DFS_POOL_STAT("Pool references", pool_reference);
1977 ATH10K_DFS_POOL_STAT("Pulses allocated", pulse_allocated);
1978 ATH10K_DFS_POOL_STAT("Pulses alloc error", pulse_alloc_error);
1979 ATH10K_DFS_POOL_STAT("Pulses in use", pulse_used);
1980 ATH10K_DFS_POOL_STAT("Seqs. allocated", pseq_allocated);
1981 ATH10K_DFS_POOL_STAT("Seqs. alloc error", pseq_alloc_error);
1982 ATH10K_DFS_POOL_STAT("Seqs. in use", pseq_used);
1988 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1994 static const struct file_operations fops_dfs_stats = {
1995 .read = ath10k_read_dfs_stats,
1996 .open = simple_open,
1997 .owner = THIS_MODULE,
1998 .llseek = default_llseek,
2001 static ssize_t ath10k_write_pktlog_filter(struct file *file,
2002 const char __user *ubuf,
2003 size_t count, loff_t *ppos)
2005 struct ath10k *ar = file->private_data;
2009 if (kstrtouint_from_user(ubuf, count, 0, &filter))
2012 mutex_lock(&ar->conf_mutex);
2014 if (ar->state != ATH10K_STATE_ON) {
2015 ar->debug.pktlog_filter = filter;
2020 if (filter && (filter != ar->debug.pktlog_filter)) {
2021 ret = ath10k_wmi_pdev_pktlog_enable(ar, filter);
2023 ath10k_warn(ar, "failed to enable pktlog filter %x: %d\n",
2024 ar->debug.pktlog_filter, ret);
2028 ret = ath10k_wmi_pdev_pktlog_disable(ar);
2030 ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
2035 ar->debug.pktlog_filter = filter;
2039 mutex_unlock(&ar->conf_mutex);
2043 static ssize_t ath10k_read_pktlog_filter(struct file *file, char __user *ubuf,
2044 size_t count, loff_t *ppos)
2047 struct ath10k *ar = file->private_data;
2050 mutex_lock(&ar->conf_mutex);
2051 len = scnprintf(buf, sizeof(buf) - len, "%08x\n",
2052 ar->debug.pktlog_filter);
2053 mutex_unlock(&ar->conf_mutex);
2055 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
2058 static const struct file_operations fops_pktlog_filter = {
2059 .read = ath10k_read_pktlog_filter,
2060 .write = ath10k_write_pktlog_filter,
2064 static ssize_t ath10k_write_quiet_period(struct file *file,
2065 const char __user *ubuf,
2066 size_t count, loff_t *ppos)
2068 struct ath10k *ar = file->private_data;
2071 if (kstrtouint_from_user(ubuf, count, 0, &period))
2074 if (period < ATH10K_QUIET_PERIOD_MIN) {
2075 ath10k_warn(ar, "Quiet period %u can not be lesser than 25ms\n",
2079 mutex_lock(&ar->conf_mutex);
2080 ar->thermal.quiet_period = period;
2081 ath10k_thermal_set_throttling(ar);
2082 mutex_unlock(&ar->conf_mutex);
2087 static ssize_t ath10k_read_quiet_period(struct file *file, char __user *ubuf,
2088 size_t count, loff_t *ppos)
2091 struct ath10k *ar = file->private_data;
2094 mutex_lock(&ar->conf_mutex);
2095 len = scnprintf(buf, sizeof(buf) - len, "%d\n",
2096 ar->thermal.quiet_period);
2097 mutex_unlock(&ar->conf_mutex);
2099 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
2102 static const struct file_operations fops_quiet_period = {
2103 .read = ath10k_read_quiet_period,
2104 .write = ath10k_write_quiet_period,
2108 static ssize_t ath10k_write_btcoex(struct file *file,
2109 const char __user *ubuf,
2110 size_t count, loff_t *ppos)
2112 struct ath10k *ar = file->private_data;
2117 buf_size = min(count, (sizeof(buf) - 1));
2118 if (copy_from_user(buf, ubuf, buf_size))
2121 buf[buf_size] = '\0';
2123 if (strtobool(buf, &val) != 0)
2126 mutex_lock(&ar->conf_mutex);
2128 if (!(test_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags) ^ val))
2132 set_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
2134 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
2136 if (ar->state != ATH10K_STATE_ON)
2139 ath10k_info(ar, "restarting firmware due to btcoex change");
2141 queue_work(ar->workqueue, &ar->restart_work);
2144 mutex_unlock(&ar->conf_mutex);
2149 static ssize_t ath10k_read_btcoex(struct file *file, char __user *ubuf,
2150 size_t count, loff_t *ppos)
2153 struct ath10k *ar = file->private_data;
2156 mutex_lock(&ar->conf_mutex);
2157 len = scnprintf(buf, sizeof(buf) - len, "%d\n",
2158 test_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags));
2159 mutex_unlock(&ar->conf_mutex);
2161 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
2164 static const struct file_operations fops_btcoex = {
2165 .read = ath10k_read_btcoex,
2166 .write = ath10k_write_btcoex,
2170 static ssize_t ath10k_debug_fw_checksums_read(struct file *file,
2171 char __user *user_buf,
2172 size_t count, loff_t *ppos)
2174 struct ath10k *ar = file->private_data;
2175 unsigned int len = 0, buf_len = 4096;
2179 buf = kzalloc(buf_len, GFP_KERNEL);
2183 mutex_lock(&ar->conf_mutex);
2188 len += scnprintf(buf + len, buf_len - len,
2189 "firmware-N.bin\t\t%08x\n",
2190 crc32_le(0, ar->firmware->data, ar->firmware->size));
2191 len += scnprintf(buf + len, buf_len - len,
2192 "athwlan\t\t\t%08x\n",
2193 crc32_le(0, ar->firmware_data, ar->firmware_len));
2194 len += scnprintf(buf + len, buf_len - len,
2196 crc32_le(0, ar->otp_data, ar->otp_len));
2197 len += scnprintf(buf + len, buf_len - len,
2198 "codeswap\t\t%08x\n",
2199 crc32_le(0, ar->swap.firmware_codeswap_data,
2200 ar->swap.firmware_codeswap_len));
2201 len += scnprintf(buf + len, buf_len - len,
2202 "board-N.bin\t\t%08x\n",
2203 crc32_le(0, ar->board->data, ar->board->size));
2204 len += scnprintf(buf + len, buf_len - len,
2205 "board\t\t\t%08x\n",
2206 crc32_le(0, ar->board_data, ar->board_len));
2208 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
2210 mutex_unlock(&ar->conf_mutex);
2216 static const struct file_operations fops_fw_checksums = {
2217 .read = ath10k_debug_fw_checksums_read,
2218 .open = simple_open,
2219 .owner = THIS_MODULE,
2220 .llseek = default_llseek,
2223 int ath10k_debug_create(struct ath10k *ar)
2225 ar->debug.fw_crash_data = vzalloc(sizeof(*ar->debug.fw_crash_data));
2226 if (!ar->debug.fw_crash_data)
2229 INIT_LIST_HEAD(&ar->debug.fw_stats.pdevs);
2230 INIT_LIST_HEAD(&ar->debug.fw_stats.vdevs);
2231 INIT_LIST_HEAD(&ar->debug.fw_stats.peers);
2236 void ath10k_debug_destroy(struct ath10k *ar)
2238 vfree(ar->debug.fw_crash_data);
2239 ar->debug.fw_crash_data = NULL;
2241 ath10k_debug_fw_stats_reset(ar);
2243 kfree(ar->debug.tpc_stats);
2246 int ath10k_debug_register(struct ath10k *ar)
2248 ar->debug.debugfs_phy = debugfs_create_dir("ath10k",
2249 ar->hw->wiphy->debugfsdir);
2250 if (IS_ERR_OR_NULL(ar->debug.debugfs_phy)) {
2251 if (IS_ERR(ar->debug.debugfs_phy))
2252 return PTR_ERR(ar->debug.debugfs_phy);
2257 INIT_DELAYED_WORK(&ar->debug.htt_stats_dwork,
2258 ath10k_debug_htt_stats_dwork);
2260 init_completion(&ar->debug.tpc_complete);
2261 init_completion(&ar->debug.fw_stats_complete);
2263 debugfs_create_file("fw_stats", S_IRUSR, ar->debug.debugfs_phy, ar,
2266 debugfs_create_file("fw_reset_stats", S_IRUSR, ar->debug.debugfs_phy,
2267 ar, &fops_fw_reset_stats);
2269 debugfs_create_file("wmi_services", S_IRUSR, ar->debug.debugfs_phy, ar,
2270 &fops_wmi_services);
2272 debugfs_create_file("simulate_fw_crash", S_IRUSR | S_IWUSR,
2273 ar->debug.debugfs_phy, ar, &fops_simulate_fw_crash);
2275 debugfs_create_file("fw_crash_dump", S_IRUSR, ar->debug.debugfs_phy,
2276 ar, &fops_fw_crash_dump);
2278 debugfs_create_file("reg_addr", S_IRUSR | S_IWUSR,
2279 ar->debug.debugfs_phy, ar, &fops_reg_addr);
2281 debugfs_create_file("reg_value", S_IRUSR | S_IWUSR,
2282 ar->debug.debugfs_phy, ar, &fops_reg_value);
2284 debugfs_create_file("mem_value", S_IRUSR | S_IWUSR,
2285 ar->debug.debugfs_phy, ar, &fops_mem_value);
2287 debugfs_create_file("chip_id", S_IRUSR, ar->debug.debugfs_phy,
2290 debugfs_create_file("htt_stats_mask", S_IRUSR | S_IWUSR,
2291 ar->debug.debugfs_phy, ar, &fops_htt_stats_mask);
2293 debugfs_create_file("htt_max_amsdu_ampdu", S_IRUSR | S_IWUSR,
2294 ar->debug.debugfs_phy, ar,
2295 &fops_htt_max_amsdu_ampdu);
2297 debugfs_create_file("fw_dbglog", S_IRUSR | S_IWUSR,
2298 ar->debug.debugfs_phy, ar, &fops_fw_dbglog);
2300 debugfs_create_file("cal_data", S_IRUSR, ar->debug.debugfs_phy,
2301 ar, &fops_cal_data);
2303 debugfs_create_file("ani_enable", S_IRUSR | S_IWUSR,
2304 ar->debug.debugfs_phy, ar, &fops_ani_enable);
2306 debugfs_create_file("nf_cal_period", S_IRUSR | S_IWUSR,
2307 ar->debug.debugfs_phy, ar, &fops_nf_cal_period);
2309 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
2310 debugfs_create_file("dfs_simulate_radar", S_IWUSR,
2311 ar->debug.debugfs_phy, ar,
2312 &fops_simulate_radar);
2314 debugfs_create_bool("dfs_block_radar_events", S_IWUSR,
2315 ar->debug.debugfs_phy,
2316 &ar->dfs_block_radar_events);
2318 debugfs_create_file("dfs_stats", S_IRUSR,
2319 ar->debug.debugfs_phy, ar,
2323 debugfs_create_file("pktlog_filter", S_IRUGO | S_IWUSR,
2324 ar->debug.debugfs_phy, ar, &fops_pktlog_filter);
2326 debugfs_create_file("quiet_period", S_IRUGO | S_IWUSR,
2327 ar->debug.debugfs_phy, ar, &fops_quiet_period);
2329 debugfs_create_file("tpc_stats", S_IRUSR,
2330 ar->debug.debugfs_phy, ar, &fops_tpc_stats);
2332 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map))
2333 debugfs_create_file("btcoex", S_IRUGO | S_IWUSR,
2334 ar->debug.debugfs_phy, ar, &fops_btcoex);
2336 debugfs_create_file("fw_checksums", S_IRUSR,
2337 ar->debug.debugfs_phy, ar, &fops_fw_checksums);
2342 void ath10k_debug_unregister(struct ath10k *ar)
2344 cancel_delayed_work_sync(&ar->debug.htt_stats_dwork);
2347 #endif /* CONFIG_ATH10K_DEBUGFS */
2349 #ifdef CONFIG_ATH10K_DEBUG
2350 void ath10k_dbg(struct ath10k *ar, enum ath10k_debug_mask mask,
2351 const char *fmt, ...)
2353 struct va_format vaf;
2356 va_start(args, fmt);
2361 if (ath10k_debug_mask & mask)
2362 dev_printk(KERN_DEBUG, ar->dev, "%pV", &vaf);
2364 trace_ath10k_log_dbg(ar, mask, &vaf);
2368 EXPORT_SYMBOL(ath10k_dbg);
2370 void ath10k_dbg_dump(struct ath10k *ar,
2371 enum ath10k_debug_mask mask,
2372 const char *msg, const char *prefix,
2373 const void *buf, size_t len)
2376 unsigned int linebuflen;
2379 if (ath10k_debug_mask & mask) {
2381 ath10k_dbg(ar, mask, "%s\n", msg);
2383 for (ptr = buf; (ptr - buf) < len; ptr += 16) {
2385 linebuflen += scnprintf(linebuf + linebuflen,
2386 sizeof(linebuf) - linebuflen,
2388 (prefix ? prefix : ""),
2389 (unsigned int)(ptr - buf));
2390 hex_dump_to_buffer(ptr, len - (ptr - buf), 16, 1,
2391 linebuf + linebuflen,
2392 sizeof(linebuf) - linebuflen, true);
2393 dev_printk(KERN_DEBUG, ar->dev, "%s\n", linebuf);
2397 /* tracing code doesn't like null strings :/ */
2398 trace_ath10k_log_dbg_dump(ar, msg ? msg : "", prefix ? prefix : "",
2401 EXPORT_SYMBOL(ath10k_dbg_dump);
2403 #endif /* CONFIG_ATH10K_DEBUG */