Linux 4.4.145
[linux/fpc-iii.git] / drivers / net / wireless / ath / ath10k / debug.c
blob30c3575670544d1de7a217b4541152955eb6e15f
1 /*
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>
23 #include "core.h"
24 #include "debug.h"
25 #include "hif.h"
26 #include "wmi-ops.h"
28 /* ms */
29 #define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000
31 #define ATH10K_FW_CRASH_DUMP_VERSION 1
33 /**
34 * enum ath10k_fw_crash_dump_type - types of data in the dump file
35 * @ATH10K_FW_CRASH_DUMP_REGDUMP: Register crash dump in binary format
37 enum ath10k_fw_crash_dump_type {
38 ATH10K_FW_CRASH_DUMP_REGISTERS = 0,
40 ATH10K_FW_CRASH_DUMP_MAX,
43 struct ath10k_tlv_dump_data {
44 /* see ath10k_fw_crash_dump_type above */
45 __le32 type;
47 /* in bytes */
48 __le32 tlv_len;
50 /* pad to 32-bit boundaries as needed */
51 u8 tlv_data[];
52 } __packed;
54 struct ath10k_dump_file_data {
55 /* dump file information */
57 /* "ATH10K-FW-DUMP" */
58 char df_magic[16];
60 __le32 len;
62 /* file dump version */
63 __le32 version;
65 /* some info we can get from ath10k struct that might help */
67 u8 uuid[16];
69 __le32 chip_id;
71 /* 0 for now, in place for later hardware */
72 __le32 bus_type;
74 __le32 target_version;
75 __le32 fw_version_major;
76 __le32 fw_version_minor;
77 __le32 fw_version_release;
78 __le32 fw_version_build;
79 __le32 phy_capability;
80 __le32 hw_min_tx_power;
81 __le32 hw_max_tx_power;
82 __le32 ht_cap_info;
83 __le32 vht_cap_info;
84 __le32 num_rf_chains;
86 /* firmware version string */
87 char fw_ver[ETHTOOL_FWVERS_LEN];
89 /* Kernel related information */
91 /* time-of-day stamp */
92 __le64 tv_sec;
94 /* time-of-day stamp, nano-seconds */
95 __le64 tv_nsec;
97 /* LINUX_VERSION_CODE */
98 __le32 kernel_ver_code;
100 /* VERMAGIC_STRING */
101 char kernel_ver[64];
103 /* room for growth w/out changing binary format */
104 u8 unused[128];
106 /* struct ath10k_tlv_dump_data + more */
107 u8 data[0];
108 } __packed;
110 void ath10k_info(struct ath10k *ar, const char *fmt, ...)
112 struct va_format vaf = {
113 .fmt = fmt,
115 va_list args;
117 va_start(args, fmt);
118 vaf.va = &args;
119 dev_info(ar->dev, "%pV", &vaf);
120 trace_ath10k_log_info(ar, &vaf);
121 va_end(args);
123 EXPORT_SYMBOL(ath10k_info);
125 void ath10k_print_driver_info(struct ath10k *ar)
127 char fw_features[128] = {};
128 char boardinfo[100];
130 ath10k_core_get_fw_features_str(ar, fw_features, sizeof(fw_features));
132 if (ar->id.bmi_ids_valid)
133 scnprintf(boardinfo, sizeof(boardinfo), "bmi %d:%d",
134 ar->id.bmi_chip_id, ar->id.bmi_board_id);
135 else
136 scnprintf(boardinfo, sizeof(boardinfo), "sub %04x:%04x",
137 ar->id.subsystem_vendor, ar->id.subsystem_device);
139 ath10k_info(ar, "%s (0x%08x, 0x%08x %s) fw %s fwapi %d bdapi %d htt-ver %d.%d wmi-op %d htt-op %d cal %s max-sta %d raw %d hwcrypto %d features %s\n",
140 ar->hw_params.name,
141 ar->target_version,
142 ar->chip_id,
143 boardinfo,
144 ar->hw->wiphy->fw_version,
145 ar->fw_api,
146 ar->bd_api,
147 ar->htt.target_version_major,
148 ar->htt.target_version_minor,
149 ar->wmi.op_version,
150 ar->htt.op_version,
151 ath10k_cal_mode_str(ar->cal_mode),
152 ar->max_num_stations,
153 test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags),
154 !test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags),
155 fw_features);
156 ath10k_info(ar, "debug %d debugfs %d tracing %d dfs %d testmode %d\n",
157 config_enabled(CONFIG_ATH10K_DEBUG),
158 config_enabled(CONFIG_ATH10K_DEBUGFS),
159 config_enabled(CONFIG_ATH10K_TRACING),
160 config_enabled(CONFIG_ATH10K_DFS_CERTIFIED),
161 config_enabled(CONFIG_NL80211_TESTMODE));
163 EXPORT_SYMBOL(ath10k_print_driver_info);
165 void ath10k_err(struct ath10k *ar, const char *fmt, ...)
167 struct va_format vaf = {
168 .fmt = fmt,
170 va_list args;
172 va_start(args, fmt);
173 vaf.va = &args;
174 dev_err(ar->dev, "%pV", &vaf);
175 trace_ath10k_log_err(ar, &vaf);
176 va_end(args);
178 EXPORT_SYMBOL(ath10k_err);
180 void ath10k_warn(struct ath10k *ar, const char *fmt, ...)
182 struct va_format vaf = {
183 .fmt = fmt,
185 va_list args;
187 va_start(args, fmt);
188 vaf.va = &args;
189 dev_warn_ratelimited(ar->dev, "%pV", &vaf);
190 trace_ath10k_log_warn(ar, &vaf);
192 va_end(args);
194 EXPORT_SYMBOL(ath10k_warn);
196 #ifdef CONFIG_ATH10K_DEBUGFS
198 static ssize_t ath10k_read_wmi_services(struct file *file,
199 char __user *user_buf,
200 size_t count, loff_t *ppos)
202 struct ath10k *ar = file->private_data;
203 char *buf;
204 unsigned int len = 0, buf_len = 4096;
205 const char *name;
206 ssize_t ret_cnt;
207 bool enabled;
208 int i;
210 buf = kzalloc(buf_len, GFP_KERNEL);
211 if (!buf)
212 return -ENOMEM;
214 mutex_lock(&ar->conf_mutex);
216 if (len > buf_len)
217 len = buf_len;
219 spin_lock_bh(&ar->data_lock);
220 for (i = 0; i < WMI_SERVICE_MAX; i++) {
221 enabled = test_bit(i, ar->wmi.svc_map);
222 name = wmi_service_name(i);
224 if (!name) {
225 if (enabled)
226 len += scnprintf(buf + len, buf_len - len,
227 "%-40s %s (bit %d)\n",
228 "unknown", "enabled", i);
230 continue;
233 len += scnprintf(buf + len, buf_len - len,
234 "%-40s %s\n",
235 name, enabled ? "enabled" : "-");
237 spin_unlock_bh(&ar->data_lock);
239 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
241 mutex_unlock(&ar->conf_mutex);
243 kfree(buf);
244 return ret_cnt;
247 static const struct file_operations fops_wmi_services = {
248 .read = ath10k_read_wmi_services,
249 .open = simple_open,
250 .owner = THIS_MODULE,
251 .llseek = default_llseek,
254 static void ath10k_debug_fw_stats_pdevs_free(struct list_head *head)
256 struct ath10k_fw_stats_pdev *i, *tmp;
258 list_for_each_entry_safe(i, tmp, head, list) {
259 list_del(&i->list);
260 kfree(i);
264 static void ath10k_debug_fw_stats_vdevs_free(struct list_head *head)
266 struct ath10k_fw_stats_vdev *i, *tmp;
268 list_for_each_entry_safe(i, tmp, head, list) {
269 list_del(&i->list);
270 kfree(i);
274 static void ath10k_debug_fw_stats_peers_free(struct list_head *head)
276 struct ath10k_fw_stats_peer *i, *tmp;
278 list_for_each_entry_safe(i, tmp, head, list) {
279 list_del(&i->list);
280 kfree(i);
284 static void ath10k_debug_fw_stats_reset(struct ath10k *ar)
286 spin_lock_bh(&ar->data_lock);
287 ar->debug.fw_stats_done = false;
288 ath10k_debug_fw_stats_pdevs_free(&ar->debug.fw_stats.pdevs);
289 ath10k_debug_fw_stats_vdevs_free(&ar->debug.fw_stats.vdevs);
290 ath10k_debug_fw_stats_peers_free(&ar->debug.fw_stats.peers);
291 spin_unlock_bh(&ar->data_lock);
294 void ath10k_debug_fw_stats_process(struct ath10k *ar, struct sk_buff *skb)
296 struct ath10k_fw_stats stats = {};
297 bool is_start, is_started, is_end;
298 size_t num_peers;
299 size_t num_vdevs;
300 int ret;
302 INIT_LIST_HEAD(&stats.pdevs);
303 INIT_LIST_HEAD(&stats.vdevs);
304 INIT_LIST_HEAD(&stats.peers);
306 spin_lock_bh(&ar->data_lock);
307 ret = ath10k_wmi_pull_fw_stats(ar, skb, &stats);
308 if (ret) {
309 ath10k_warn(ar, "failed to pull fw stats: %d\n", ret);
310 goto free;
313 /* Stat data may exceed htc-wmi buffer limit. In such case firmware
314 * splits the stats data and delivers it in a ping-pong fashion of
315 * request cmd-update event.
317 * However there is no explicit end-of-data. Instead start-of-data is
318 * used as an implicit one. This works as follows:
319 * a) discard stat update events until one with pdev stats is
320 * delivered - this skips session started at end of (b)
321 * b) consume stat update events until another one with pdev stats is
322 * delivered which is treated as end-of-data and is itself discarded
325 if (ar->debug.fw_stats_done) {
326 ath10k_warn(ar, "received unsolicited stats update event\n");
327 goto free;
330 num_peers = ath10k_wmi_fw_stats_num_peers(&ar->debug.fw_stats.peers);
331 num_vdevs = ath10k_wmi_fw_stats_num_vdevs(&ar->debug.fw_stats.vdevs);
332 is_start = (list_empty(&ar->debug.fw_stats.pdevs) &&
333 !list_empty(&stats.pdevs));
334 is_end = (!list_empty(&ar->debug.fw_stats.pdevs) &&
335 !list_empty(&stats.pdevs));
337 if (is_start)
338 list_splice_tail_init(&stats.pdevs, &ar->debug.fw_stats.pdevs);
340 if (is_end)
341 ar->debug.fw_stats_done = true;
343 is_started = !list_empty(&ar->debug.fw_stats.pdevs);
345 if (is_started && !is_end) {
346 if (num_peers >= ATH10K_MAX_NUM_PEER_IDS) {
347 /* Although this is unlikely impose a sane limit to
348 * prevent firmware from DoS-ing the host.
350 ath10k_warn(ar, "dropping fw peer stats\n");
351 goto free;
354 if (num_vdevs >= BITS_PER_LONG) {
355 ath10k_warn(ar, "dropping fw vdev stats\n");
356 goto free;
359 list_splice_tail_init(&stats.peers, &ar->debug.fw_stats.peers);
360 list_splice_tail_init(&stats.vdevs, &ar->debug.fw_stats.vdevs);
363 complete(&ar->debug.fw_stats_complete);
365 free:
366 /* In some cases lists have been spliced and cleared. Free up
367 * resources if that is not the case.
369 ath10k_debug_fw_stats_pdevs_free(&stats.pdevs);
370 ath10k_debug_fw_stats_vdevs_free(&stats.vdevs);
371 ath10k_debug_fw_stats_peers_free(&stats.peers);
373 spin_unlock_bh(&ar->data_lock);
376 static int ath10k_debug_fw_stats_request(struct ath10k *ar)
378 unsigned long timeout, time_left;
379 int ret;
381 lockdep_assert_held(&ar->conf_mutex);
383 timeout = jiffies + msecs_to_jiffies(1 * HZ);
385 ath10k_debug_fw_stats_reset(ar);
387 for (;;) {
388 if (time_after(jiffies, timeout))
389 return -ETIMEDOUT;
391 reinit_completion(&ar->debug.fw_stats_complete);
393 ret = ath10k_wmi_request_stats(ar, ar->fw_stats_req_mask);
394 if (ret) {
395 ath10k_warn(ar, "could not request stats (%d)\n", ret);
396 return ret;
399 time_left =
400 wait_for_completion_timeout(&ar->debug.fw_stats_complete,
401 1 * HZ);
402 if (!time_left)
403 return -ETIMEDOUT;
405 spin_lock_bh(&ar->data_lock);
406 if (ar->debug.fw_stats_done) {
407 spin_unlock_bh(&ar->data_lock);
408 break;
410 spin_unlock_bh(&ar->data_lock);
413 return 0;
416 static int ath10k_fw_stats_open(struct inode *inode, struct file *file)
418 struct ath10k *ar = inode->i_private;
419 void *buf = NULL;
420 int ret;
422 mutex_lock(&ar->conf_mutex);
424 if (ar->state != ATH10K_STATE_ON) {
425 ret = -ENETDOWN;
426 goto err_unlock;
429 buf = vmalloc(ATH10K_FW_STATS_BUF_SIZE);
430 if (!buf) {
431 ret = -ENOMEM;
432 goto err_unlock;
435 ret = ath10k_debug_fw_stats_request(ar);
436 if (ret) {
437 ath10k_warn(ar, "failed to request fw stats: %d\n", ret);
438 goto err_free;
441 ret = ath10k_wmi_fw_stats_fill(ar, &ar->debug.fw_stats, buf);
442 if (ret) {
443 ath10k_warn(ar, "failed to fill fw stats: %d\n", ret);
444 goto err_free;
447 file->private_data = buf;
449 mutex_unlock(&ar->conf_mutex);
450 return 0;
452 err_free:
453 vfree(buf);
455 err_unlock:
456 mutex_unlock(&ar->conf_mutex);
457 return ret;
460 static int ath10k_fw_stats_release(struct inode *inode, struct file *file)
462 vfree(file->private_data);
464 return 0;
467 static ssize_t ath10k_fw_stats_read(struct file *file, char __user *user_buf,
468 size_t count, loff_t *ppos)
470 const char *buf = file->private_data;
471 unsigned int len = strlen(buf);
473 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
476 static const struct file_operations fops_fw_stats = {
477 .open = ath10k_fw_stats_open,
478 .release = ath10k_fw_stats_release,
479 .read = ath10k_fw_stats_read,
480 .owner = THIS_MODULE,
481 .llseek = default_llseek,
484 static ssize_t ath10k_debug_fw_reset_stats_read(struct file *file,
485 char __user *user_buf,
486 size_t count, loff_t *ppos)
488 struct ath10k *ar = file->private_data;
489 int ret, len, buf_len;
490 char *buf;
492 buf_len = 500;
493 buf = kmalloc(buf_len, GFP_KERNEL);
494 if (!buf)
495 return -ENOMEM;
497 spin_lock_bh(&ar->data_lock);
499 len = 0;
500 len += scnprintf(buf + len, buf_len - len,
501 "fw_crash_counter\t\t%d\n", ar->stats.fw_crash_counter);
502 len += scnprintf(buf + len, buf_len - len,
503 "fw_warm_reset_counter\t\t%d\n",
504 ar->stats.fw_warm_reset_counter);
505 len += scnprintf(buf + len, buf_len - len,
506 "fw_cold_reset_counter\t\t%d\n",
507 ar->stats.fw_cold_reset_counter);
509 spin_unlock_bh(&ar->data_lock);
511 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
513 kfree(buf);
515 return ret;
518 static const struct file_operations fops_fw_reset_stats = {
519 .open = simple_open,
520 .read = ath10k_debug_fw_reset_stats_read,
521 .owner = THIS_MODULE,
522 .llseek = default_llseek,
525 /* This is a clean assert crash in firmware. */
526 static int ath10k_debug_fw_assert(struct ath10k *ar)
528 struct wmi_vdev_install_key_cmd *cmd;
529 struct sk_buff *skb;
531 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd) + 16);
532 if (!skb)
533 return -ENOMEM;
535 cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
536 memset(cmd, 0, sizeof(*cmd));
538 /* big enough number so that firmware asserts */
539 cmd->vdev_id = __cpu_to_le32(0x7ffe);
541 return ath10k_wmi_cmd_send(ar, skb,
542 ar->wmi.cmd->vdev_install_key_cmdid);
545 static ssize_t ath10k_read_simulate_fw_crash(struct file *file,
546 char __user *user_buf,
547 size_t count, loff_t *ppos)
549 const char buf[] =
550 "To simulate firmware crash write one of the keywords to this file:\n"
551 "`soft` - this will send WMI_FORCE_FW_HANG_ASSERT to firmware if FW supports that command.\n"
552 "`hard` - this will send to firmware command with illegal parameters causing firmware crash.\n"
553 "`assert` - this will send special illegal parameter to firmware to cause assert failure and crash.\n"
554 "`hw-restart` - this will simply queue hw restart without fw/hw actually crashing.\n";
556 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
559 /* Simulate firmware crash:
560 * 'soft': Call wmi command causing firmware hang. This firmware hang is
561 * recoverable by warm firmware reset.
562 * 'hard': Force firmware crash by setting any vdev parameter for not allowed
563 * vdev id. This is hard firmware crash because it is recoverable only by cold
564 * firmware reset.
566 static ssize_t ath10k_write_simulate_fw_crash(struct file *file,
567 const char __user *user_buf,
568 size_t count, loff_t *ppos)
570 struct ath10k *ar = file->private_data;
571 char buf[32];
572 int ret;
574 mutex_lock(&ar->conf_mutex);
576 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
578 /* make sure that buf is null terminated */
579 buf[sizeof(buf) - 1] = 0;
581 if (ar->state != ATH10K_STATE_ON &&
582 ar->state != ATH10K_STATE_RESTARTED) {
583 ret = -ENETDOWN;
584 goto exit;
587 /* drop the possible '\n' from the end */
588 if (buf[count - 1] == '\n') {
589 buf[count - 1] = 0;
590 count--;
593 if (!strcmp(buf, "soft")) {
594 ath10k_info(ar, "simulating soft firmware crash\n");
595 ret = ath10k_wmi_force_fw_hang(ar, WMI_FORCE_FW_HANG_ASSERT, 0);
596 } else if (!strcmp(buf, "hard")) {
597 ath10k_info(ar, "simulating hard firmware crash\n");
598 /* 0x7fff is vdev id, and it is always out of range for all
599 * firmware variants in order to force a firmware crash.
601 ret = ath10k_wmi_vdev_set_param(ar, 0x7fff,
602 ar->wmi.vdev_param->rts_threshold,
604 } else if (!strcmp(buf, "assert")) {
605 ath10k_info(ar, "simulating firmware assert crash\n");
606 ret = ath10k_debug_fw_assert(ar);
607 } else if (!strcmp(buf, "hw-restart")) {
608 ath10k_info(ar, "user requested hw restart\n");
609 queue_work(ar->workqueue, &ar->restart_work);
610 ret = 0;
611 } else {
612 ret = -EINVAL;
613 goto exit;
616 if (ret) {
617 ath10k_warn(ar, "failed to simulate firmware crash: %d\n", ret);
618 goto exit;
621 ret = count;
623 exit:
624 mutex_unlock(&ar->conf_mutex);
625 return ret;
628 static const struct file_operations fops_simulate_fw_crash = {
629 .read = ath10k_read_simulate_fw_crash,
630 .write = ath10k_write_simulate_fw_crash,
631 .open = simple_open,
632 .owner = THIS_MODULE,
633 .llseek = default_llseek,
636 static ssize_t ath10k_read_chip_id(struct file *file, char __user *user_buf,
637 size_t count, loff_t *ppos)
639 struct ath10k *ar = file->private_data;
640 unsigned int len;
641 char buf[50];
643 len = scnprintf(buf, sizeof(buf), "0x%08x\n", ar->chip_id);
645 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
648 static const struct file_operations fops_chip_id = {
649 .read = ath10k_read_chip_id,
650 .open = simple_open,
651 .owner = THIS_MODULE,
652 .llseek = default_llseek,
655 struct ath10k_fw_crash_data *
656 ath10k_debug_get_new_fw_crash_data(struct ath10k *ar)
658 struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data;
660 lockdep_assert_held(&ar->data_lock);
662 crash_data->crashed_since_read = true;
663 uuid_le_gen(&crash_data->uuid);
664 getnstimeofday(&crash_data->timestamp);
666 return crash_data;
668 EXPORT_SYMBOL(ath10k_debug_get_new_fw_crash_data);
670 static struct ath10k_dump_file_data *ath10k_build_dump_file(struct ath10k *ar)
672 struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data;
673 struct ath10k_dump_file_data *dump_data;
674 struct ath10k_tlv_dump_data *dump_tlv;
675 int hdr_len = sizeof(*dump_data);
676 unsigned int len, sofar = 0;
677 unsigned char *buf;
679 len = hdr_len;
680 len += sizeof(*dump_tlv) + sizeof(crash_data->registers);
682 sofar += hdr_len;
684 /* This is going to get big when we start dumping FW RAM and such,
685 * so go ahead and use vmalloc.
687 buf = vzalloc(len);
688 if (!buf)
689 return NULL;
691 spin_lock_bh(&ar->data_lock);
693 if (!crash_data->crashed_since_read) {
694 spin_unlock_bh(&ar->data_lock);
695 vfree(buf);
696 return NULL;
699 dump_data = (struct ath10k_dump_file_data *)(buf);
700 strlcpy(dump_data->df_magic, "ATH10K-FW-DUMP",
701 sizeof(dump_data->df_magic));
702 dump_data->len = cpu_to_le32(len);
704 dump_data->version = cpu_to_le32(ATH10K_FW_CRASH_DUMP_VERSION);
706 memcpy(dump_data->uuid, &crash_data->uuid, sizeof(dump_data->uuid));
707 dump_data->chip_id = cpu_to_le32(ar->chip_id);
708 dump_data->bus_type = cpu_to_le32(0);
709 dump_data->target_version = cpu_to_le32(ar->target_version);
710 dump_data->fw_version_major = cpu_to_le32(ar->fw_version_major);
711 dump_data->fw_version_minor = cpu_to_le32(ar->fw_version_minor);
712 dump_data->fw_version_release = cpu_to_le32(ar->fw_version_release);
713 dump_data->fw_version_build = cpu_to_le32(ar->fw_version_build);
714 dump_data->phy_capability = cpu_to_le32(ar->phy_capability);
715 dump_data->hw_min_tx_power = cpu_to_le32(ar->hw_min_tx_power);
716 dump_data->hw_max_tx_power = cpu_to_le32(ar->hw_max_tx_power);
717 dump_data->ht_cap_info = cpu_to_le32(ar->ht_cap_info);
718 dump_data->vht_cap_info = cpu_to_le32(ar->vht_cap_info);
719 dump_data->num_rf_chains = cpu_to_le32(ar->num_rf_chains);
721 strlcpy(dump_data->fw_ver, ar->hw->wiphy->fw_version,
722 sizeof(dump_data->fw_ver));
724 dump_data->kernel_ver_code = 0;
725 strlcpy(dump_data->kernel_ver, init_utsname()->release,
726 sizeof(dump_data->kernel_ver));
728 dump_data->tv_sec = cpu_to_le64(crash_data->timestamp.tv_sec);
729 dump_data->tv_nsec = cpu_to_le64(crash_data->timestamp.tv_nsec);
731 /* Gather crash-dump */
732 dump_tlv = (struct ath10k_tlv_dump_data *)(buf + sofar);
733 dump_tlv->type = cpu_to_le32(ATH10K_FW_CRASH_DUMP_REGISTERS);
734 dump_tlv->tlv_len = cpu_to_le32(sizeof(crash_data->registers));
735 memcpy(dump_tlv->tlv_data, &crash_data->registers,
736 sizeof(crash_data->registers));
737 sofar += sizeof(*dump_tlv) + sizeof(crash_data->registers);
739 ar->debug.fw_crash_data->crashed_since_read = false;
741 spin_unlock_bh(&ar->data_lock);
743 return dump_data;
746 static int ath10k_fw_crash_dump_open(struct inode *inode, struct file *file)
748 struct ath10k *ar = inode->i_private;
749 struct ath10k_dump_file_data *dump;
751 dump = ath10k_build_dump_file(ar);
752 if (!dump)
753 return -ENODATA;
755 file->private_data = dump;
757 return 0;
760 static ssize_t ath10k_fw_crash_dump_read(struct file *file,
761 char __user *user_buf,
762 size_t count, loff_t *ppos)
764 struct ath10k_dump_file_data *dump_file = file->private_data;
766 return simple_read_from_buffer(user_buf, count, ppos,
767 dump_file,
768 le32_to_cpu(dump_file->len));
771 static int ath10k_fw_crash_dump_release(struct inode *inode,
772 struct file *file)
774 vfree(file->private_data);
776 return 0;
779 static const struct file_operations fops_fw_crash_dump = {
780 .open = ath10k_fw_crash_dump_open,
781 .read = ath10k_fw_crash_dump_read,
782 .release = ath10k_fw_crash_dump_release,
783 .owner = THIS_MODULE,
784 .llseek = default_llseek,
787 static ssize_t ath10k_reg_addr_read(struct file *file,
788 char __user *user_buf,
789 size_t count, loff_t *ppos)
791 struct ath10k *ar = file->private_data;
792 u8 buf[32];
793 unsigned int len = 0;
794 u32 reg_addr;
796 mutex_lock(&ar->conf_mutex);
797 reg_addr = ar->debug.reg_addr;
798 mutex_unlock(&ar->conf_mutex);
800 len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n", reg_addr);
802 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
805 static ssize_t ath10k_reg_addr_write(struct file *file,
806 const char __user *user_buf,
807 size_t count, loff_t *ppos)
809 struct ath10k *ar = file->private_data;
810 u32 reg_addr;
811 int ret;
813 ret = kstrtou32_from_user(user_buf, count, 0, &reg_addr);
814 if (ret)
815 return ret;
817 if (!IS_ALIGNED(reg_addr, 4))
818 return -EFAULT;
820 mutex_lock(&ar->conf_mutex);
821 ar->debug.reg_addr = reg_addr;
822 mutex_unlock(&ar->conf_mutex);
824 return count;
827 static const struct file_operations fops_reg_addr = {
828 .read = ath10k_reg_addr_read,
829 .write = ath10k_reg_addr_write,
830 .open = simple_open,
831 .owner = THIS_MODULE,
832 .llseek = default_llseek,
835 static ssize_t ath10k_reg_value_read(struct file *file,
836 char __user *user_buf,
837 size_t count, loff_t *ppos)
839 struct ath10k *ar = file->private_data;
840 u8 buf[48];
841 unsigned int len;
842 u32 reg_addr, reg_val;
843 int ret;
845 mutex_lock(&ar->conf_mutex);
847 if (ar->state != ATH10K_STATE_ON &&
848 ar->state != ATH10K_STATE_UTF) {
849 ret = -ENETDOWN;
850 goto exit;
853 reg_addr = ar->debug.reg_addr;
855 reg_val = ath10k_hif_read32(ar, reg_addr);
856 len = scnprintf(buf, sizeof(buf), "0x%08x:0x%08x\n", reg_addr, reg_val);
858 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
860 exit:
861 mutex_unlock(&ar->conf_mutex);
863 return ret;
866 static ssize_t ath10k_reg_value_write(struct file *file,
867 const char __user *user_buf,
868 size_t count, loff_t *ppos)
870 struct ath10k *ar = file->private_data;
871 u32 reg_addr, reg_val;
872 int ret;
874 mutex_lock(&ar->conf_mutex);
876 if (ar->state != ATH10K_STATE_ON &&
877 ar->state != ATH10K_STATE_UTF) {
878 ret = -ENETDOWN;
879 goto exit;
882 reg_addr = ar->debug.reg_addr;
884 ret = kstrtou32_from_user(user_buf, count, 0, &reg_val);
885 if (ret)
886 goto exit;
888 ath10k_hif_write32(ar, reg_addr, reg_val);
890 ret = count;
892 exit:
893 mutex_unlock(&ar->conf_mutex);
895 return ret;
898 static const struct file_operations fops_reg_value = {
899 .read = ath10k_reg_value_read,
900 .write = ath10k_reg_value_write,
901 .open = simple_open,
902 .owner = THIS_MODULE,
903 .llseek = default_llseek,
906 static ssize_t ath10k_mem_value_read(struct file *file,
907 char __user *user_buf,
908 size_t count, loff_t *ppos)
910 struct ath10k *ar = file->private_data;
911 u8 *buf;
912 int ret;
914 if (*ppos < 0)
915 return -EINVAL;
917 if (!count)
918 return 0;
920 mutex_lock(&ar->conf_mutex);
922 buf = vmalloc(count);
923 if (!buf) {
924 ret = -ENOMEM;
925 goto exit;
928 if (ar->state != ATH10K_STATE_ON &&
929 ar->state != ATH10K_STATE_UTF) {
930 ret = -ENETDOWN;
931 goto exit;
934 ret = ath10k_hif_diag_read(ar, *ppos, buf, count);
935 if (ret) {
936 ath10k_warn(ar, "failed to read address 0x%08x via diagnose window fnrom debugfs: %d\n",
937 (u32)(*ppos), ret);
938 goto exit;
941 ret = copy_to_user(user_buf, buf, count);
942 if (ret) {
943 ret = -EFAULT;
944 goto exit;
947 count -= ret;
948 *ppos += count;
949 ret = count;
951 exit:
952 vfree(buf);
953 mutex_unlock(&ar->conf_mutex);
955 return ret;
958 static ssize_t ath10k_mem_value_write(struct file *file,
959 const char __user *user_buf,
960 size_t count, loff_t *ppos)
962 struct ath10k *ar = file->private_data;
963 u8 *buf;
964 int ret;
966 if (*ppos < 0)
967 return -EINVAL;
969 if (!count)
970 return 0;
972 mutex_lock(&ar->conf_mutex);
974 buf = vmalloc(count);
975 if (!buf) {
976 ret = -ENOMEM;
977 goto exit;
980 if (ar->state != ATH10K_STATE_ON &&
981 ar->state != ATH10K_STATE_UTF) {
982 ret = -ENETDOWN;
983 goto exit;
986 ret = copy_from_user(buf, user_buf, count);
987 if (ret) {
988 ret = -EFAULT;
989 goto exit;
992 ret = ath10k_hif_diag_write(ar, *ppos, buf, count);
993 if (ret) {
994 ath10k_warn(ar, "failed to write address 0x%08x via diagnose window from debugfs: %d\n",
995 (u32)(*ppos), ret);
996 goto exit;
999 *ppos += count;
1000 ret = count;
1002 exit:
1003 vfree(buf);
1004 mutex_unlock(&ar->conf_mutex);
1006 return ret;
1009 static const struct file_operations fops_mem_value = {
1010 .read = ath10k_mem_value_read,
1011 .write = ath10k_mem_value_write,
1012 .open = simple_open,
1013 .owner = THIS_MODULE,
1014 .llseek = default_llseek,
1017 static int ath10k_debug_htt_stats_req(struct ath10k *ar)
1019 u64 cookie;
1020 int ret;
1022 lockdep_assert_held(&ar->conf_mutex);
1024 if (ar->debug.htt_stats_mask == 0)
1025 /* htt stats are disabled */
1026 return 0;
1028 if (ar->state != ATH10K_STATE_ON)
1029 return 0;
1031 cookie = get_jiffies_64();
1033 ret = ath10k_htt_h2t_stats_req(&ar->htt, ar->debug.htt_stats_mask,
1034 cookie);
1035 if (ret) {
1036 ath10k_warn(ar, "failed to send htt stats request: %d\n", ret);
1037 return ret;
1040 queue_delayed_work(ar->workqueue, &ar->debug.htt_stats_dwork,
1041 msecs_to_jiffies(ATH10K_DEBUG_HTT_STATS_INTERVAL));
1043 return 0;
1046 static void ath10k_debug_htt_stats_dwork(struct work_struct *work)
1048 struct ath10k *ar = container_of(work, struct ath10k,
1049 debug.htt_stats_dwork.work);
1051 mutex_lock(&ar->conf_mutex);
1053 ath10k_debug_htt_stats_req(ar);
1055 mutex_unlock(&ar->conf_mutex);
1058 static ssize_t ath10k_read_htt_stats_mask(struct file *file,
1059 char __user *user_buf,
1060 size_t count, loff_t *ppos)
1062 struct ath10k *ar = file->private_data;
1063 char buf[32];
1064 unsigned int len;
1066 len = scnprintf(buf, sizeof(buf), "%lu\n", ar->debug.htt_stats_mask);
1068 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1071 static ssize_t ath10k_write_htt_stats_mask(struct file *file,
1072 const char __user *user_buf,
1073 size_t count, loff_t *ppos)
1075 struct ath10k *ar = file->private_data;
1076 unsigned long mask;
1077 int ret;
1079 ret = kstrtoul_from_user(user_buf, count, 0, &mask);
1080 if (ret)
1081 return ret;
1083 /* max 8 bit masks (for now) */
1084 if (mask > 0xff)
1085 return -E2BIG;
1087 mutex_lock(&ar->conf_mutex);
1089 ar->debug.htt_stats_mask = mask;
1091 ret = ath10k_debug_htt_stats_req(ar);
1092 if (ret)
1093 goto out;
1095 ret = count;
1097 out:
1098 mutex_unlock(&ar->conf_mutex);
1100 return ret;
1103 static const struct file_operations fops_htt_stats_mask = {
1104 .read = ath10k_read_htt_stats_mask,
1105 .write = ath10k_write_htt_stats_mask,
1106 .open = simple_open,
1107 .owner = THIS_MODULE,
1108 .llseek = default_llseek,
1111 static ssize_t ath10k_read_htt_max_amsdu_ampdu(struct file *file,
1112 char __user *user_buf,
1113 size_t count, loff_t *ppos)
1115 struct ath10k *ar = file->private_data;
1116 char buf[64];
1117 u8 amsdu = 3, ampdu = 64;
1118 unsigned int len;
1120 mutex_lock(&ar->conf_mutex);
1122 amsdu = ar->htt.max_num_amsdu;
1123 ampdu = ar->htt.max_num_ampdu;
1124 mutex_unlock(&ar->conf_mutex);
1126 len = scnprintf(buf, sizeof(buf), "%u %u\n", amsdu, ampdu);
1128 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1131 static ssize_t ath10k_write_htt_max_amsdu_ampdu(struct file *file,
1132 const char __user *user_buf,
1133 size_t count, loff_t *ppos)
1135 struct ath10k *ar = file->private_data;
1136 int res;
1137 char buf[64];
1138 unsigned int amsdu, ampdu;
1140 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
1142 /* make sure that buf is null terminated */
1143 buf[sizeof(buf) - 1] = 0;
1145 res = sscanf(buf, "%u %u", &amsdu, &ampdu);
1147 if (res != 2)
1148 return -EINVAL;
1150 mutex_lock(&ar->conf_mutex);
1152 res = ath10k_htt_h2t_aggr_cfg_msg(&ar->htt, ampdu, amsdu);
1153 if (res)
1154 goto out;
1156 res = count;
1157 ar->htt.max_num_amsdu = amsdu;
1158 ar->htt.max_num_ampdu = ampdu;
1160 out:
1161 mutex_unlock(&ar->conf_mutex);
1162 return res;
1165 static const struct file_operations fops_htt_max_amsdu_ampdu = {
1166 .read = ath10k_read_htt_max_amsdu_ampdu,
1167 .write = ath10k_write_htt_max_amsdu_ampdu,
1168 .open = simple_open,
1169 .owner = THIS_MODULE,
1170 .llseek = default_llseek,
1173 static ssize_t ath10k_read_fw_dbglog(struct file *file,
1174 char __user *user_buf,
1175 size_t count, loff_t *ppos)
1177 struct ath10k *ar = file->private_data;
1178 unsigned int len;
1179 char buf[64];
1181 len = scnprintf(buf, sizeof(buf), "0x%08x %u\n",
1182 ar->debug.fw_dbglog_mask, ar->debug.fw_dbglog_level);
1184 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1187 static ssize_t ath10k_write_fw_dbglog(struct file *file,
1188 const char __user *user_buf,
1189 size_t count, loff_t *ppos)
1191 struct ath10k *ar = file->private_data;
1192 int ret;
1193 char buf[64];
1194 unsigned int log_level, mask;
1196 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
1198 /* make sure that buf is null terminated */
1199 buf[sizeof(buf) - 1] = 0;
1201 ret = sscanf(buf, "%x %u", &mask, &log_level);
1203 if (!ret)
1204 return -EINVAL;
1206 if (ret == 1)
1207 /* default if user did not specify */
1208 log_level = ATH10K_DBGLOG_LEVEL_WARN;
1210 mutex_lock(&ar->conf_mutex);
1212 ar->debug.fw_dbglog_mask = mask;
1213 ar->debug.fw_dbglog_level = log_level;
1215 if (ar->state == ATH10K_STATE_ON) {
1216 ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask,
1217 ar->debug.fw_dbglog_level);
1218 if (ret) {
1219 ath10k_warn(ar, "dbglog cfg failed from debugfs: %d\n",
1220 ret);
1221 goto exit;
1225 ret = count;
1227 exit:
1228 mutex_unlock(&ar->conf_mutex);
1230 return ret;
1233 /* TODO: Would be nice to always support ethtool stats, would need to
1234 * move the stats storage out of ath10k_debug, or always have ath10k_debug
1235 * struct available..
1238 /* This generally cooresponds to the debugfs fw_stats file */
1239 static const char ath10k_gstrings_stats[][ETH_GSTRING_LEN] = {
1240 "tx_pkts_nic",
1241 "tx_bytes_nic",
1242 "rx_pkts_nic",
1243 "rx_bytes_nic",
1244 "d_noise_floor",
1245 "d_cycle_count",
1246 "d_phy_error",
1247 "d_rts_bad",
1248 "d_rts_good",
1249 "d_tx_power", /* in .5 dbM I think */
1250 "d_rx_crc_err", /* fcs_bad */
1251 "d_no_beacon",
1252 "d_tx_mpdus_queued",
1253 "d_tx_msdu_queued",
1254 "d_tx_msdu_dropped",
1255 "d_local_enqued",
1256 "d_local_freed",
1257 "d_tx_ppdu_hw_queued",
1258 "d_tx_ppdu_reaped",
1259 "d_tx_fifo_underrun",
1260 "d_tx_ppdu_abort",
1261 "d_tx_mpdu_requed",
1262 "d_tx_excessive_retries",
1263 "d_tx_hw_rate",
1264 "d_tx_dropped_sw_retries",
1265 "d_tx_illegal_rate",
1266 "d_tx_continuous_xretries",
1267 "d_tx_timeout",
1268 "d_tx_mpdu_txop_limit",
1269 "d_pdev_resets",
1270 "d_rx_mid_ppdu_route_change",
1271 "d_rx_status",
1272 "d_rx_extra_frags_ring0",
1273 "d_rx_extra_frags_ring1",
1274 "d_rx_extra_frags_ring2",
1275 "d_rx_extra_frags_ring3",
1276 "d_rx_msdu_htt",
1277 "d_rx_mpdu_htt",
1278 "d_rx_msdu_stack",
1279 "d_rx_mpdu_stack",
1280 "d_rx_phy_err",
1281 "d_rx_phy_err_drops",
1282 "d_rx_mpdu_errors", /* FCS, MIC, ENC */
1283 "d_fw_crash_count",
1284 "d_fw_warm_reset_count",
1285 "d_fw_cold_reset_count",
1288 #define ATH10K_SSTATS_LEN ARRAY_SIZE(ath10k_gstrings_stats)
1290 void ath10k_debug_get_et_strings(struct ieee80211_hw *hw,
1291 struct ieee80211_vif *vif,
1292 u32 sset, u8 *data)
1294 if (sset == ETH_SS_STATS)
1295 memcpy(data, *ath10k_gstrings_stats,
1296 sizeof(ath10k_gstrings_stats));
1299 int ath10k_debug_get_et_sset_count(struct ieee80211_hw *hw,
1300 struct ieee80211_vif *vif, int sset)
1302 if (sset == ETH_SS_STATS)
1303 return ATH10K_SSTATS_LEN;
1305 return 0;
1308 void ath10k_debug_get_et_stats(struct ieee80211_hw *hw,
1309 struct ieee80211_vif *vif,
1310 struct ethtool_stats *stats, u64 *data)
1312 struct ath10k *ar = hw->priv;
1313 static const struct ath10k_fw_stats_pdev zero_stats = {};
1314 const struct ath10k_fw_stats_pdev *pdev_stats;
1315 int i = 0, ret;
1317 mutex_lock(&ar->conf_mutex);
1319 if (ar->state == ATH10K_STATE_ON) {
1320 ret = ath10k_debug_fw_stats_request(ar);
1321 if (ret) {
1322 /* just print a warning and try to use older results */
1323 ath10k_warn(ar,
1324 "failed to get fw stats for ethtool: %d\n",
1325 ret);
1329 pdev_stats = list_first_entry_or_null(&ar->debug.fw_stats.pdevs,
1330 struct ath10k_fw_stats_pdev,
1331 list);
1332 if (!pdev_stats) {
1333 /* no results available so just return zeroes */
1334 pdev_stats = &zero_stats;
1337 spin_lock_bh(&ar->data_lock);
1339 data[i++] = pdev_stats->hw_reaped; /* ppdu reaped */
1340 data[i++] = 0; /* tx bytes */
1341 data[i++] = pdev_stats->htt_mpdus;
1342 data[i++] = 0; /* rx bytes */
1343 data[i++] = pdev_stats->ch_noise_floor;
1344 data[i++] = pdev_stats->cycle_count;
1345 data[i++] = pdev_stats->phy_err_count;
1346 data[i++] = pdev_stats->rts_bad;
1347 data[i++] = pdev_stats->rts_good;
1348 data[i++] = pdev_stats->chan_tx_power;
1349 data[i++] = pdev_stats->fcs_bad;
1350 data[i++] = pdev_stats->no_beacons;
1351 data[i++] = pdev_stats->mpdu_enqued;
1352 data[i++] = pdev_stats->msdu_enqued;
1353 data[i++] = pdev_stats->wmm_drop;
1354 data[i++] = pdev_stats->local_enqued;
1355 data[i++] = pdev_stats->local_freed;
1356 data[i++] = pdev_stats->hw_queued;
1357 data[i++] = pdev_stats->hw_reaped;
1358 data[i++] = pdev_stats->underrun;
1359 data[i++] = pdev_stats->tx_abort;
1360 data[i++] = pdev_stats->mpdus_requed;
1361 data[i++] = pdev_stats->tx_ko;
1362 data[i++] = pdev_stats->data_rc;
1363 data[i++] = pdev_stats->sw_retry_failure;
1364 data[i++] = pdev_stats->illgl_rate_phy_err;
1365 data[i++] = pdev_stats->pdev_cont_xretry;
1366 data[i++] = pdev_stats->pdev_tx_timeout;
1367 data[i++] = pdev_stats->txop_ovf;
1368 data[i++] = pdev_stats->pdev_resets;
1369 data[i++] = pdev_stats->mid_ppdu_route_change;
1370 data[i++] = pdev_stats->status_rcvd;
1371 data[i++] = pdev_stats->r0_frags;
1372 data[i++] = pdev_stats->r1_frags;
1373 data[i++] = pdev_stats->r2_frags;
1374 data[i++] = pdev_stats->r3_frags;
1375 data[i++] = pdev_stats->htt_msdus;
1376 data[i++] = pdev_stats->htt_mpdus;
1377 data[i++] = pdev_stats->loc_msdus;
1378 data[i++] = pdev_stats->loc_mpdus;
1379 data[i++] = pdev_stats->phy_errs;
1380 data[i++] = pdev_stats->phy_err_drop;
1381 data[i++] = pdev_stats->mpdu_errs;
1382 data[i++] = ar->stats.fw_crash_counter;
1383 data[i++] = ar->stats.fw_warm_reset_counter;
1384 data[i++] = ar->stats.fw_cold_reset_counter;
1386 spin_unlock_bh(&ar->data_lock);
1388 mutex_unlock(&ar->conf_mutex);
1390 WARN_ON(i != ATH10K_SSTATS_LEN);
1393 static const struct file_operations fops_fw_dbglog = {
1394 .read = ath10k_read_fw_dbglog,
1395 .write = ath10k_write_fw_dbglog,
1396 .open = simple_open,
1397 .owner = THIS_MODULE,
1398 .llseek = default_llseek,
1401 static int ath10k_debug_cal_data_open(struct inode *inode, struct file *file)
1403 struct ath10k *ar = inode->i_private;
1404 void *buf;
1405 u32 hi_addr;
1406 __le32 addr;
1407 int ret;
1409 mutex_lock(&ar->conf_mutex);
1411 if (ar->state != ATH10K_STATE_ON &&
1412 ar->state != ATH10K_STATE_UTF) {
1413 ret = -ENETDOWN;
1414 goto err;
1417 buf = vmalloc(QCA988X_CAL_DATA_LEN);
1418 if (!buf) {
1419 ret = -ENOMEM;
1420 goto err;
1423 hi_addr = host_interest_item_address(HI_ITEM(hi_board_data));
1425 ret = ath10k_hif_diag_read(ar, hi_addr, &addr, sizeof(addr));
1426 if (ret) {
1427 ath10k_warn(ar, "failed to read hi_board_data address: %d\n", ret);
1428 goto err_vfree;
1431 ret = ath10k_hif_diag_read(ar, le32_to_cpu(addr), buf,
1432 QCA988X_CAL_DATA_LEN);
1433 if (ret) {
1434 ath10k_warn(ar, "failed to read calibration data: %d\n", ret);
1435 goto err_vfree;
1438 file->private_data = buf;
1440 mutex_unlock(&ar->conf_mutex);
1442 return 0;
1444 err_vfree:
1445 vfree(buf);
1447 err:
1448 mutex_unlock(&ar->conf_mutex);
1450 return ret;
1453 static ssize_t ath10k_debug_cal_data_read(struct file *file,
1454 char __user *user_buf,
1455 size_t count, loff_t *ppos)
1457 void *buf = file->private_data;
1459 return simple_read_from_buffer(user_buf, count, ppos,
1460 buf, QCA988X_CAL_DATA_LEN);
1463 static int ath10k_debug_cal_data_release(struct inode *inode,
1464 struct file *file)
1466 vfree(file->private_data);
1468 return 0;
1471 static ssize_t ath10k_write_ani_enable(struct file *file,
1472 const char __user *user_buf,
1473 size_t count, loff_t *ppos)
1475 struct ath10k *ar = file->private_data;
1476 int ret;
1477 u8 enable;
1479 if (kstrtou8_from_user(user_buf, count, 0, &enable))
1480 return -EINVAL;
1482 mutex_lock(&ar->conf_mutex);
1484 if (ar->ani_enabled == enable) {
1485 ret = count;
1486 goto exit;
1489 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->ani_enable,
1490 enable);
1491 if (ret) {
1492 ath10k_warn(ar, "ani_enable failed from debugfs: %d\n", ret);
1493 goto exit;
1495 ar->ani_enabled = enable;
1497 ret = count;
1499 exit:
1500 mutex_unlock(&ar->conf_mutex);
1502 return ret;
1505 static ssize_t ath10k_read_ani_enable(struct file *file, char __user *user_buf,
1506 size_t count, loff_t *ppos)
1508 struct ath10k *ar = file->private_data;
1509 int len = 0;
1510 char buf[32];
1512 len = scnprintf(buf, sizeof(buf) - len, "%d\n",
1513 ar->ani_enabled);
1515 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1518 static const struct file_operations fops_ani_enable = {
1519 .read = ath10k_read_ani_enable,
1520 .write = ath10k_write_ani_enable,
1521 .open = simple_open,
1522 .owner = THIS_MODULE,
1523 .llseek = default_llseek,
1526 static const struct file_operations fops_cal_data = {
1527 .open = ath10k_debug_cal_data_open,
1528 .read = ath10k_debug_cal_data_read,
1529 .release = ath10k_debug_cal_data_release,
1530 .owner = THIS_MODULE,
1531 .llseek = default_llseek,
1534 static ssize_t ath10k_read_nf_cal_period(struct file *file,
1535 char __user *user_buf,
1536 size_t count, loff_t *ppos)
1538 struct ath10k *ar = file->private_data;
1539 unsigned int len;
1540 char buf[32];
1542 len = scnprintf(buf, sizeof(buf), "%d\n",
1543 ar->debug.nf_cal_period);
1545 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1548 static ssize_t ath10k_write_nf_cal_period(struct file *file,
1549 const char __user *user_buf,
1550 size_t count, loff_t *ppos)
1552 struct ath10k *ar = file->private_data;
1553 unsigned long period;
1554 int ret;
1556 ret = kstrtoul_from_user(user_buf, count, 0, &period);
1557 if (ret)
1558 return ret;
1560 if (period > WMI_PDEV_PARAM_CAL_PERIOD_MAX)
1561 return -EINVAL;
1563 /* there's no way to switch back to the firmware default */
1564 if (period == 0)
1565 return -EINVAL;
1567 mutex_lock(&ar->conf_mutex);
1569 ar->debug.nf_cal_period = period;
1571 if (ar->state != ATH10K_STATE_ON) {
1572 /* firmware is not running, nothing else to do */
1573 ret = count;
1574 goto exit;
1577 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->cal_period,
1578 ar->debug.nf_cal_period);
1579 if (ret) {
1580 ath10k_warn(ar, "cal period cfg failed from debugfs: %d\n",
1581 ret);
1582 goto exit;
1585 ret = count;
1587 exit:
1588 mutex_unlock(&ar->conf_mutex);
1590 return ret;
1593 static const struct file_operations fops_nf_cal_period = {
1594 .read = ath10k_read_nf_cal_period,
1595 .write = ath10k_write_nf_cal_period,
1596 .open = simple_open,
1597 .owner = THIS_MODULE,
1598 .llseek = default_llseek,
1601 #define ATH10K_TPC_CONFIG_BUF_SIZE (1024 * 1024)
1603 static int ath10k_debug_tpc_stats_request(struct ath10k *ar)
1605 int ret;
1606 unsigned long time_left;
1608 lockdep_assert_held(&ar->conf_mutex);
1610 reinit_completion(&ar->debug.tpc_complete);
1612 ret = ath10k_wmi_pdev_get_tpc_config(ar, WMI_TPC_CONFIG_PARAM);
1613 if (ret) {
1614 ath10k_warn(ar, "failed to request tpc config: %d\n", ret);
1615 return ret;
1618 time_left = wait_for_completion_timeout(&ar->debug.tpc_complete,
1619 1 * HZ);
1620 if (time_left == 0)
1621 return -ETIMEDOUT;
1623 return 0;
1626 void ath10k_debug_tpc_stats_process(struct ath10k *ar,
1627 struct ath10k_tpc_stats *tpc_stats)
1629 spin_lock_bh(&ar->data_lock);
1631 kfree(ar->debug.tpc_stats);
1632 ar->debug.tpc_stats = tpc_stats;
1633 complete(&ar->debug.tpc_complete);
1635 spin_unlock_bh(&ar->data_lock);
1638 static void ath10k_tpc_stats_print(struct ath10k_tpc_stats *tpc_stats,
1639 unsigned int j, char *buf, unsigned int *len)
1641 unsigned int i, buf_len;
1642 static const char table_str[][5] = { "CDD",
1643 "STBC",
1644 "TXBF" };
1645 static const char pream_str[][6] = { "CCK",
1646 "OFDM",
1647 "HT20",
1648 "HT40",
1649 "VHT20",
1650 "VHT40",
1651 "VHT80",
1652 "HTCUP" };
1654 buf_len = ATH10K_TPC_CONFIG_BUF_SIZE;
1655 *len += scnprintf(buf + *len, buf_len - *len,
1656 "********************************\n");
1657 *len += scnprintf(buf + *len, buf_len - *len,
1658 "******************* %s POWER TABLE ****************\n",
1659 table_str[j]);
1660 *len += scnprintf(buf + *len, buf_len - *len,
1661 "********************************\n");
1662 *len += scnprintf(buf + *len, buf_len - *len,
1663 "No. Preamble Rate_code tpc_value1 tpc_value2 tpc_value3\n");
1665 for (i = 0; i < tpc_stats->rate_max; i++) {
1666 *len += scnprintf(buf + *len, buf_len - *len,
1667 "%8d %s 0x%2x %s\n", i,
1668 pream_str[tpc_stats->tpc_table[j].pream_idx[i]],
1669 tpc_stats->tpc_table[j].rate_code[i],
1670 tpc_stats->tpc_table[j].tpc_value[i]);
1673 *len += scnprintf(buf + *len, buf_len - *len,
1674 "***********************************\n");
1677 static void ath10k_tpc_stats_fill(struct ath10k *ar,
1678 struct ath10k_tpc_stats *tpc_stats,
1679 char *buf)
1681 unsigned int len, j, buf_len;
1683 len = 0;
1684 buf_len = ATH10K_TPC_CONFIG_BUF_SIZE;
1686 spin_lock_bh(&ar->data_lock);
1688 if (!tpc_stats) {
1689 ath10k_warn(ar, "failed to get tpc stats\n");
1690 goto unlock;
1693 len += scnprintf(buf + len, buf_len - len, "\n");
1694 len += scnprintf(buf + len, buf_len - len,
1695 "*************************************\n");
1696 len += scnprintf(buf + len, buf_len - len,
1697 "TPC config for channel %4d mode %d\n",
1698 tpc_stats->chan_freq,
1699 tpc_stats->phy_mode);
1700 len += scnprintf(buf + len, buf_len - len,
1701 "*************************************\n");
1702 len += scnprintf(buf + len, buf_len - len,
1703 "CTL = 0x%2x Reg. Domain = %2d\n",
1704 tpc_stats->ctl,
1705 tpc_stats->reg_domain);
1706 len += scnprintf(buf + len, buf_len - len,
1707 "Antenna Gain = %2d Reg. Max Antenna Gain = %2d\n",
1708 tpc_stats->twice_antenna_gain,
1709 tpc_stats->twice_antenna_reduction);
1710 len += scnprintf(buf + len, buf_len - len,
1711 "Power Limit = %2d Reg. Max Power = %2d\n",
1712 tpc_stats->power_limit,
1713 tpc_stats->twice_max_rd_power / 2);
1714 len += scnprintf(buf + len, buf_len - len,
1715 "Num tx chains = %2d Num supported rates = %2d\n",
1716 tpc_stats->num_tx_chain,
1717 tpc_stats->rate_max);
1719 for (j = 0; j < tpc_stats->num_tx_chain ; j++) {
1720 switch (j) {
1721 case WMI_TPC_TABLE_TYPE_CDD:
1722 if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) {
1723 len += scnprintf(buf + len, buf_len - len,
1724 "CDD not supported\n");
1725 break;
1728 ath10k_tpc_stats_print(tpc_stats, j, buf, &len);
1729 break;
1730 case WMI_TPC_TABLE_TYPE_STBC:
1731 if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) {
1732 len += scnprintf(buf + len, buf_len - len,
1733 "STBC not supported\n");
1734 break;
1737 ath10k_tpc_stats_print(tpc_stats, j, buf, &len);
1738 break;
1739 case WMI_TPC_TABLE_TYPE_TXBF:
1740 if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) {
1741 len += scnprintf(buf + len, buf_len - len,
1742 "TXBF not supported\n***************************\n");
1743 break;
1746 ath10k_tpc_stats_print(tpc_stats, j, buf, &len);
1747 break;
1748 default:
1749 len += scnprintf(buf + len, buf_len - len,
1750 "Invalid Type\n");
1751 break;
1755 unlock:
1756 spin_unlock_bh(&ar->data_lock);
1758 if (len >= buf_len)
1759 buf[len - 1] = 0;
1760 else
1761 buf[len] = 0;
1764 static int ath10k_tpc_stats_open(struct inode *inode, struct file *file)
1766 struct ath10k *ar = inode->i_private;
1767 void *buf = NULL;
1768 int ret;
1770 mutex_lock(&ar->conf_mutex);
1772 if (ar->state != ATH10K_STATE_ON) {
1773 ret = -ENETDOWN;
1774 goto err_unlock;
1777 buf = vmalloc(ATH10K_TPC_CONFIG_BUF_SIZE);
1778 if (!buf) {
1779 ret = -ENOMEM;
1780 goto err_unlock;
1783 ret = ath10k_debug_tpc_stats_request(ar);
1784 if (ret) {
1785 ath10k_warn(ar, "failed to request tpc config stats: %d\n",
1786 ret);
1787 goto err_free;
1790 ath10k_tpc_stats_fill(ar, ar->debug.tpc_stats, buf);
1791 file->private_data = buf;
1793 mutex_unlock(&ar->conf_mutex);
1794 return 0;
1796 err_free:
1797 vfree(buf);
1799 err_unlock:
1800 mutex_unlock(&ar->conf_mutex);
1801 return ret;
1804 static int ath10k_tpc_stats_release(struct inode *inode, struct file *file)
1806 vfree(file->private_data);
1808 return 0;
1811 static ssize_t ath10k_tpc_stats_read(struct file *file, char __user *user_buf,
1812 size_t count, loff_t *ppos)
1814 const char *buf = file->private_data;
1815 unsigned int len = strlen(buf);
1817 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1820 static const struct file_operations fops_tpc_stats = {
1821 .open = ath10k_tpc_stats_open,
1822 .release = ath10k_tpc_stats_release,
1823 .read = ath10k_tpc_stats_read,
1824 .owner = THIS_MODULE,
1825 .llseek = default_llseek,
1828 int ath10k_debug_start(struct ath10k *ar)
1830 int ret;
1832 lockdep_assert_held(&ar->conf_mutex);
1834 ret = ath10k_debug_htt_stats_req(ar);
1835 if (ret)
1836 /* continue normally anyway, this isn't serious */
1837 ath10k_warn(ar, "failed to start htt stats workqueue: %d\n",
1838 ret);
1840 if (ar->debug.fw_dbglog_mask) {
1841 ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask,
1842 ATH10K_DBGLOG_LEVEL_WARN);
1843 if (ret)
1844 /* not serious */
1845 ath10k_warn(ar, "failed to enable dbglog during start: %d",
1846 ret);
1849 if (ar->debug.pktlog_filter) {
1850 ret = ath10k_wmi_pdev_pktlog_enable(ar,
1851 ar->debug.pktlog_filter);
1852 if (ret)
1853 /* not serious */
1854 ath10k_warn(ar,
1855 "failed to enable pktlog filter %x: %d\n",
1856 ar->debug.pktlog_filter, ret);
1857 } else {
1858 ret = ath10k_wmi_pdev_pktlog_disable(ar);
1859 if (ret)
1860 /* not serious */
1861 ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
1864 if (ar->debug.nf_cal_period) {
1865 ret = ath10k_wmi_pdev_set_param(ar,
1866 ar->wmi.pdev_param->cal_period,
1867 ar->debug.nf_cal_period);
1868 if (ret)
1869 /* not serious */
1870 ath10k_warn(ar, "cal period cfg failed from debug start: %d\n",
1871 ret);
1874 return ret;
1877 void ath10k_debug_stop(struct ath10k *ar)
1879 lockdep_assert_held(&ar->conf_mutex);
1881 /* Must not use _sync to avoid deadlock, we do that in
1882 * ath10k_debug_destroy(). The check for htt_stats_mask is to avoid
1883 * warning from del_timer(). */
1884 if (ar->debug.htt_stats_mask != 0)
1885 cancel_delayed_work(&ar->debug.htt_stats_dwork);
1887 ath10k_wmi_pdev_pktlog_disable(ar);
1890 static ssize_t ath10k_write_simulate_radar(struct file *file,
1891 const char __user *user_buf,
1892 size_t count, loff_t *ppos)
1894 struct ath10k *ar = file->private_data;
1895 struct ath10k_vif *arvif;
1897 /* Just check for for the first vif alone, as all the vifs will be
1898 * sharing the same channel and if the channel is disabled, all the
1899 * vifs will share the same 'is_started' state.
1901 arvif = list_first_entry(&ar->arvifs, typeof(*arvif), list);
1902 if (!arvif->is_started)
1903 return -EINVAL;
1905 ieee80211_radar_detected(ar->hw);
1907 return count;
1910 static const struct file_operations fops_simulate_radar = {
1911 .write = ath10k_write_simulate_radar,
1912 .open = simple_open,
1913 .owner = THIS_MODULE,
1914 .llseek = default_llseek,
1917 #define ATH10K_DFS_STAT(s, p) (\
1918 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1919 ar->debug.dfs_stats.p))
1921 #define ATH10K_DFS_POOL_STAT(s, p) (\
1922 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1923 ar->debug.dfs_pool_stats.p))
1925 static ssize_t ath10k_read_dfs_stats(struct file *file, char __user *user_buf,
1926 size_t count, loff_t *ppos)
1928 int retval = 0, len = 0;
1929 const int size = 8000;
1930 struct ath10k *ar = file->private_data;
1931 char *buf;
1933 buf = kzalloc(size, GFP_KERNEL);
1934 if (buf == NULL)
1935 return -ENOMEM;
1937 if (!ar->dfs_detector) {
1938 len += scnprintf(buf + len, size - len, "DFS not enabled\n");
1939 goto exit;
1942 ar->debug.dfs_pool_stats =
1943 ar->dfs_detector->get_stats(ar->dfs_detector);
1945 len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n");
1947 ATH10K_DFS_STAT("reported phy errors", phy_errors);
1948 ATH10K_DFS_STAT("pulse events reported", pulses_total);
1949 ATH10K_DFS_STAT("DFS pulses detected", pulses_detected);
1950 ATH10K_DFS_STAT("DFS pulses discarded", pulses_discarded);
1951 ATH10K_DFS_STAT("Radars detected", radar_detected);
1953 len += scnprintf(buf + len, size - len, "Global Pool statistics:\n");
1954 ATH10K_DFS_POOL_STAT("Pool references", pool_reference);
1955 ATH10K_DFS_POOL_STAT("Pulses allocated", pulse_allocated);
1956 ATH10K_DFS_POOL_STAT("Pulses alloc error", pulse_alloc_error);
1957 ATH10K_DFS_POOL_STAT("Pulses in use", pulse_used);
1958 ATH10K_DFS_POOL_STAT("Seqs. allocated", pseq_allocated);
1959 ATH10K_DFS_POOL_STAT("Seqs. alloc error", pseq_alloc_error);
1960 ATH10K_DFS_POOL_STAT("Seqs. in use", pseq_used);
1962 exit:
1963 if (len > size)
1964 len = size;
1966 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1967 kfree(buf);
1969 return retval;
1972 static const struct file_operations fops_dfs_stats = {
1973 .read = ath10k_read_dfs_stats,
1974 .open = simple_open,
1975 .owner = THIS_MODULE,
1976 .llseek = default_llseek,
1979 static ssize_t ath10k_write_pktlog_filter(struct file *file,
1980 const char __user *ubuf,
1981 size_t count, loff_t *ppos)
1983 struct ath10k *ar = file->private_data;
1984 u32 filter;
1985 int ret;
1987 if (kstrtouint_from_user(ubuf, count, 0, &filter))
1988 return -EINVAL;
1990 mutex_lock(&ar->conf_mutex);
1992 if (ar->state != ATH10K_STATE_ON) {
1993 ar->debug.pktlog_filter = filter;
1994 ret = count;
1995 goto out;
1998 if (filter == ar->debug.pktlog_filter) {
1999 ret = count;
2000 goto out;
2003 if (filter) {
2004 ret = ath10k_wmi_pdev_pktlog_enable(ar, filter);
2005 if (ret) {
2006 ath10k_warn(ar, "failed to enable pktlog filter %x: %d\n",
2007 ar->debug.pktlog_filter, ret);
2008 goto out;
2010 } else {
2011 ret = ath10k_wmi_pdev_pktlog_disable(ar);
2012 if (ret) {
2013 ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
2014 goto out;
2018 ar->debug.pktlog_filter = filter;
2019 ret = count;
2021 out:
2022 mutex_unlock(&ar->conf_mutex);
2023 return ret;
2026 static ssize_t ath10k_read_pktlog_filter(struct file *file, char __user *ubuf,
2027 size_t count, loff_t *ppos)
2029 char buf[32];
2030 struct ath10k *ar = file->private_data;
2031 int len = 0;
2033 mutex_lock(&ar->conf_mutex);
2034 len = scnprintf(buf, sizeof(buf) - len, "%08x\n",
2035 ar->debug.pktlog_filter);
2036 mutex_unlock(&ar->conf_mutex);
2038 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
2041 static const struct file_operations fops_pktlog_filter = {
2042 .read = ath10k_read_pktlog_filter,
2043 .write = ath10k_write_pktlog_filter,
2044 .open = simple_open
2047 static ssize_t ath10k_write_quiet_period(struct file *file,
2048 const char __user *ubuf,
2049 size_t count, loff_t *ppos)
2051 struct ath10k *ar = file->private_data;
2052 u32 period;
2054 if (kstrtouint_from_user(ubuf, count, 0, &period))
2055 return -EINVAL;
2057 if (period < ATH10K_QUIET_PERIOD_MIN) {
2058 ath10k_warn(ar, "Quiet period %u can not be lesser than 25ms\n",
2059 period);
2060 return -EINVAL;
2062 mutex_lock(&ar->conf_mutex);
2063 ar->thermal.quiet_period = period;
2064 ath10k_thermal_set_throttling(ar);
2065 mutex_unlock(&ar->conf_mutex);
2067 return count;
2070 static ssize_t ath10k_read_quiet_period(struct file *file, char __user *ubuf,
2071 size_t count, loff_t *ppos)
2073 char buf[32];
2074 struct ath10k *ar = file->private_data;
2075 int len = 0;
2077 mutex_lock(&ar->conf_mutex);
2078 len = scnprintf(buf, sizeof(buf) - len, "%d\n",
2079 ar->thermal.quiet_period);
2080 mutex_unlock(&ar->conf_mutex);
2082 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
2085 static const struct file_operations fops_quiet_period = {
2086 .read = ath10k_read_quiet_period,
2087 .write = ath10k_write_quiet_period,
2088 .open = simple_open
2091 int ath10k_debug_create(struct ath10k *ar)
2093 ar->debug.fw_crash_data = vzalloc(sizeof(*ar->debug.fw_crash_data));
2094 if (!ar->debug.fw_crash_data)
2095 return -ENOMEM;
2097 INIT_LIST_HEAD(&ar->debug.fw_stats.pdevs);
2098 INIT_LIST_HEAD(&ar->debug.fw_stats.vdevs);
2099 INIT_LIST_HEAD(&ar->debug.fw_stats.peers);
2101 return 0;
2104 void ath10k_debug_destroy(struct ath10k *ar)
2106 vfree(ar->debug.fw_crash_data);
2107 ar->debug.fw_crash_data = NULL;
2109 ath10k_debug_fw_stats_reset(ar);
2111 kfree(ar->debug.tpc_stats);
2114 int ath10k_debug_register(struct ath10k *ar)
2116 ar->debug.debugfs_phy = debugfs_create_dir("ath10k",
2117 ar->hw->wiphy->debugfsdir);
2118 if (IS_ERR_OR_NULL(ar->debug.debugfs_phy)) {
2119 if (IS_ERR(ar->debug.debugfs_phy))
2120 return PTR_ERR(ar->debug.debugfs_phy);
2122 return -ENOMEM;
2125 INIT_DELAYED_WORK(&ar->debug.htt_stats_dwork,
2126 ath10k_debug_htt_stats_dwork);
2128 init_completion(&ar->debug.tpc_complete);
2129 init_completion(&ar->debug.fw_stats_complete);
2131 debugfs_create_file("fw_stats", S_IRUSR, ar->debug.debugfs_phy, ar,
2132 &fops_fw_stats);
2134 debugfs_create_file("fw_reset_stats", S_IRUSR, ar->debug.debugfs_phy,
2135 ar, &fops_fw_reset_stats);
2137 debugfs_create_file("wmi_services", S_IRUSR, ar->debug.debugfs_phy, ar,
2138 &fops_wmi_services);
2140 debugfs_create_file("simulate_fw_crash", S_IRUSR, ar->debug.debugfs_phy,
2141 ar, &fops_simulate_fw_crash);
2143 debugfs_create_file("fw_crash_dump", S_IRUSR, ar->debug.debugfs_phy,
2144 ar, &fops_fw_crash_dump);
2146 debugfs_create_file("reg_addr", S_IRUSR | S_IWUSR,
2147 ar->debug.debugfs_phy, ar, &fops_reg_addr);
2149 debugfs_create_file("reg_value", S_IRUSR | S_IWUSR,
2150 ar->debug.debugfs_phy, ar, &fops_reg_value);
2152 debugfs_create_file("mem_value", S_IRUSR | S_IWUSR,
2153 ar->debug.debugfs_phy, ar, &fops_mem_value);
2155 debugfs_create_file("chip_id", S_IRUSR, ar->debug.debugfs_phy,
2156 ar, &fops_chip_id);
2158 debugfs_create_file("htt_stats_mask", S_IRUSR, ar->debug.debugfs_phy,
2159 ar, &fops_htt_stats_mask);
2161 debugfs_create_file("htt_max_amsdu_ampdu", S_IRUSR | S_IWUSR,
2162 ar->debug.debugfs_phy, ar,
2163 &fops_htt_max_amsdu_ampdu);
2165 debugfs_create_file("fw_dbglog", S_IRUSR, ar->debug.debugfs_phy,
2166 ar, &fops_fw_dbglog);
2168 debugfs_create_file("cal_data", S_IRUSR, ar->debug.debugfs_phy,
2169 ar, &fops_cal_data);
2171 debugfs_create_file("ani_enable", S_IRUSR | S_IWUSR,
2172 ar->debug.debugfs_phy, ar, &fops_ani_enable);
2174 debugfs_create_file("nf_cal_period", S_IRUSR | S_IWUSR,
2175 ar->debug.debugfs_phy, ar, &fops_nf_cal_period);
2177 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
2178 debugfs_create_file("dfs_simulate_radar", S_IWUSR,
2179 ar->debug.debugfs_phy, ar,
2180 &fops_simulate_radar);
2182 debugfs_create_bool("dfs_block_radar_events", S_IWUSR,
2183 ar->debug.debugfs_phy,
2184 &ar->dfs_block_radar_events);
2186 debugfs_create_file("dfs_stats", S_IRUSR,
2187 ar->debug.debugfs_phy, ar,
2188 &fops_dfs_stats);
2191 debugfs_create_file("pktlog_filter", S_IRUGO | S_IWUSR,
2192 ar->debug.debugfs_phy, ar, &fops_pktlog_filter);
2194 debugfs_create_file("quiet_period", S_IRUGO | S_IWUSR,
2195 ar->debug.debugfs_phy, ar, &fops_quiet_period);
2197 debugfs_create_file("tpc_stats", S_IRUSR,
2198 ar->debug.debugfs_phy, ar, &fops_tpc_stats);
2200 return 0;
2203 void ath10k_debug_unregister(struct ath10k *ar)
2205 cancel_delayed_work_sync(&ar->debug.htt_stats_dwork);
2208 #endif /* CONFIG_ATH10K_DEBUGFS */
2210 #ifdef CONFIG_ATH10K_DEBUG
2211 void ath10k_dbg(struct ath10k *ar, enum ath10k_debug_mask mask,
2212 const char *fmt, ...)
2214 struct va_format vaf;
2215 va_list args;
2217 va_start(args, fmt);
2219 vaf.fmt = fmt;
2220 vaf.va = &args;
2222 if (ath10k_debug_mask & mask)
2223 dev_printk(KERN_DEBUG, ar->dev, "%pV", &vaf);
2225 trace_ath10k_log_dbg(ar, mask, &vaf);
2227 va_end(args);
2229 EXPORT_SYMBOL(ath10k_dbg);
2231 void ath10k_dbg_dump(struct ath10k *ar,
2232 enum ath10k_debug_mask mask,
2233 const char *msg, const char *prefix,
2234 const void *buf, size_t len)
2236 char linebuf[256];
2237 unsigned int linebuflen;
2238 const void *ptr;
2240 if (ath10k_debug_mask & mask) {
2241 if (msg)
2242 ath10k_dbg(ar, mask, "%s\n", msg);
2244 for (ptr = buf; (ptr - buf) < len; ptr += 16) {
2245 linebuflen = 0;
2246 linebuflen += scnprintf(linebuf + linebuflen,
2247 sizeof(linebuf) - linebuflen,
2248 "%s%08x: ",
2249 (prefix ? prefix : ""),
2250 (unsigned int)(ptr - buf));
2251 hex_dump_to_buffer(ptr, len - (ptr - buf), 16, 1,
2252 linebuf + linebuflen,
2253 sizeof(linebuf) - linebuflen, true);
2254 dev_printk(KERN_DEBUG, ar->dev, "%s\n", linebuf);
2258 /* tracing code doesn't like null strings :/ */
2259 trace_ath10k_log_dbg_dump(ar, msg ? msg : "", prefix ? prefix : "",
2260 buf, len);
2262 EXPORT_SYMBOL(ath10k_dbg_dump);
2264 #endif /* CONFIG_ATH10K_DEBUG */