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>
29 #define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000
31 #define ATH10K_FW_CRASH_DUMP_VERSION 1
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 */
50 /* pad to 32-bit boundaries as needed */
54 struct ath10k_dump_file_data
{
55 /* dump file information */
57 /* "ATH10K-FW-DUMP" */
62 /* file dump version */
65 /* some info we can get from ath10k struct that might help */
71 /* 0 for now, in place for later hardware */
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
;
86 /* firmware version string */
87 char fw_ver
[ETHTOOL_FWVERS_LEN
];
89 /* Kernel related information */
91 /* time-of-day stamp */
94 /* time-of-day stamp, nano-seconds */
97 /* LINUX_VERSION_CODE */
98 __le32 kernel_ver_code
;
100 /* VERMAGIC_STRING */
103 /* room for growth w/out changing binary format */
106 /* struct ath10k_tlv_dump_data + more */
110 void ath10k_info(struct ath10k
*ar
, const char *fmt
, ...)
112 struct va_format vaf
= {
119 dev_info(ar
->dev
, "%pV", &vaf
);
120 trace_ath10k_log_info(ar
, &vaf
);
123 EXPORT_SYMBOL(ath10k_info
);
125 void ath10k_print_driver_info(struct ath10k
*ar
)
127 char fw_features
[128] = {};
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
);
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",
144 ar
->hw
->wiphy
->fw_version
,
147 ar
->htt
.target_version_major
,
148 ar
->htt
.target_version_minor
,
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
),
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
= {
174 dev_err(ar
->dev
, "%pV", &vaf
);
175 trace_ath10k_log_err(ar
, &vaf
);
178 EXPORT_SYMBOL(ath10k_err
);
180 void ath10k_warn(struct ath10k
*ar
, const char *fmt
, ...)
182 struct va_format vaf
= {
189 dev_warn_ratelimited(ar
->dev
, "%pV", &vaf
);
190 trace_ath10k_log_warn(ar
, &vaf
);
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
;
204 unsigned int len
= 0, buf_len
= 4096;
210 buf
= kzalloc(buf_len
, GFP_KERNEL
);
214 mutex_lock(&ar
->conf_mutex
);
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
);
226 len
+= scnprintf(buf
+ len
, buf_len
- len
,
227 "%-40s %s (bit %d)\n",
228 "unknown", "enabled", i
);
233 len
+= scnprintf(buf
+ len
, buf_len
- len
,
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
);
247 static const struct file_operations fops_wmi_services
= {
248 .read
= ath10k_read_wmi_services
,
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
) {
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
) {
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
) {
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
;
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
);
309 ath10k_warn(ar
, "failed to pull fw stats: %d\n", ret
);
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");
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
));
338 list_splice_tail_init(&stats
.pdevs
, &ar
->debug
.fw_stats
.pdevs
);
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");
354 if (num_vdevs
>= BITS_PER_LONG
) {
355 ath10k_warn(ar
, "dropping fw vdev stats\n");
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
);
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
;
381 lockdep_assert_held(&ar
->conf_mutex
);
383 timeout
= jiffies
+ msecs_to_jiffies(1 * HZ
);
385 ath10k_debug_fw_stats_reset(ar
);
388 if (time_after(jiffies
, timeout
))
391 reinit_completion(&ar
->debug
.fw_stats_complete
);
393 ret
= ath10k_wmi_request_stats(ar
, ar
->fw_stats_req_mask
);
395 ath10k_warn(ar
, "could not request stats (%d)\n", ret
);
400 wait_for_completion_timeout(&ar
->debug
.fw_stats_complete
,
405 spin_lock_bh(&ar
->data_lock
);
406 if (ar
->debug
.fw_stats_done
) {
407 spin_unlock_bh(&ar
->data_lock
);
410 spin_unlock_bh(&ar
->data_lock
);
416 static int ath10k_fw_stats_open(struct inode
*inode
, struct file
*file
)
418 struct ath10k
*ar
= inode
->i_private
;
422 mutex_lock(&ar
->conf_mutex
);
424 if (ar
->state
!= ATH10K_STATE_ON
) {
429 buf
= vmalloc(ATH10K_FW_STATS_BUF_SIZE
);
435 ret
= ath10k_debug_fw_stats_request(ar
);
437 ath10k_warn(ar
, "failed to request fw stats: %d\n", ret
);
441 ret
= ath10k_wmi_fw_stats_fill(ar
, &ar
->debug
.fw_stats
, buf
);
443 ath10k_warn(ar
, "failed to fill fw stats: %d\n", ret
);
447 file
->private_data
= buf
;
449 mutex_unlock(&ar
->conf_mutex
);
456 mutex_unlock(&ar
->conf_mutex
);
460 static int ath10k_fw_stats_release(struct inode
*inode
, struct file
*file
)
462 vfree(file
->private_data
);
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
;
493 buf
= kmalloc(buf_len
, GFP_KERNEL
);
497 spin_lock_bh(&ar
->data_lock
);
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
);
518 static const struct file_operations fops_fw_reset_stats
= {
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
;
531 skb
= ath10k_wmi_alloc_skb(ar
, sizeof(*cmd
) + 16);
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
)
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
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
;
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
) {
587 /* drop the possible '\n' from the end */
588 if (buf
[count
- 1] == '\n') {
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
);
617 ath10k_warn(ar
, "failed to simulate firmware crash: %d\n", ret
);
624 mutex_unlock(&ar
->conf_mutex
);
628 static const struct file_operations fops_simulate_fw_crash
= {
629 .read
= ath10k_read_simulate_fw_crash
,
630 .write
= ath10k_write_simulate_fw_crash
,
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
;
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
,
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
);
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;
680 len
+= sizeof(*dump_tlv
) + sizeof(crash_data
->registers
);
684 /* This is going to get big when we start dumping FW RAM and such,
685 * so go ahead and use vmalloc.
691 spin_lock_bh(&ar
->data_lock
);
693 if (!crash_data
->crashed_since_read
) {
694 spin_unlock_bh(&ar
->data_lock
);
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
);
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
);
755 file
->private_data
= dump
;
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
,
768 le32_to_cpu(dump_file
->len
));
771 static int ath10k_fw_crash_dump_release(struct inode
*inode
,
774 vfree(file
->private_data
);
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
;
793 unsigned int len
= 0;
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
;
813 ret
= kstrtou32_from_user(user_buf
, count
, 0, ®_addr
);
817 if (!IS_ALIGNED(reg_addr
, 4))
820 mutex_lock(&ar
->conf_mutex
);
821 ar
->debug
.reg_addr
= reg_addr
;
822 mutex_unlock(&ar
->conf_mutex
);
827 static const struct file_operations fops_reg_addr
= {
828 .read
= ath10k_reg_addr_read
,
829 .write
= ath10k_reg_addr_write
,
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
;
842 u32 reg_addr
, reg_val
;
845 mutex_lock(&ar
->conf_mutex
);
847 if (ar
->state
!= ATH10K_STATE_ON
&&
848 ar
->state
!= ATH10K_STATE_UTF
) {
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
);
861 mutex_unlock(&ar
->conf_mutex
);
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
;
874 mutex_lock(&ar
->conf_mutex
);
876 if (ar
->state
!= ATH10K_STATE_ON
&&
877 ar
->state
!= ATH10K_STATE_UTF
) {
882 reg_addr
= ar
->debug
.reg_addr
;
884 ret
= kstrtou32_from_user(user_buf
, count
, 0, ®_val
);
888 ath10k_hif_write32(ar
, reg_addr
, reg_val
);
893 mutex_unlock(&ar
->conf_mutex
);
898 static const struct file_operations fops_reg_value
= {
899 .read
= ath10k_reg_value_read
,
900 .write
= ath10k_reg_value_write
,
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
;
920 mutex_lock(&ar
->conf_mutex
);
922 buf
= vmalloc(count
);
928 if (ar
->state
!= ATH10K_STATE_ON
&&
929 ar
->state
!= ATH10K_STATE_UTF
) {
934 ret
= ath10k_hif_diag_read(ar
, *ppos
, buf
, count
);
936 ath10k_warn(ar
, "failed to read address 0x%08x via diagnose window fnrom debugfs: %d\n",
941 ret
= copy_to_user(user_buf
, buf
, count
);
953 mutex_unlock(&ar
->conf_mutex
);
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
;
972 mutex_lock(&ar
->conf_mutex
);
974 buf
= vmalloc(count
);
980 if (ar
->state
!= ATH10K_STATE_ON
&&
981 ar
->state
!= ATH10K_STATE_UTF
) {
986 ret
= copy_from_user(buf
, user_buf
, count
);
992 ret
= ath10k_hif_diag_write(ar
, *ppos
, buf
, count
);
994 ath10k_warn(ar
, "failed to write address 0x%08x via diagnose window from debugfs: %d\n",
1004 mutex_unlock(&ar
->conf_mutex
);
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
)
1022 lockdep_assert_held(&ar
->conf_mutex
);
1024 if (ar
->debug
.htt_stats_mask
== 0)
1025 /* htt stats are disabled */
1028 if (ar
->state
!= ATH10K_STATE_ON
)
1031 cookie
= get_jiffies_64();
1033 ret
= ath10k_htt_h2t_stats_req(&ar
->htt
, ar
->debug
.htt_stats_mask
,
1036 ath10k_warn(ar
, "failed to send htt stats request: %d\n", ret
);
1040 queue_delayed_work(ar
->workqueue
, &ar
->debug
.htt_stats_dwork
,
1041 msecs_to_jiffies(ATH10K_DEBUG_HTT_STATS_INTERVAL
));
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
;
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
;
1079 ret
= kstrtoul_from_user(user_buf
, count
, 0, &mask
);
1083 /* max 8 bit masks (for now) */
1087 mutex_lock(&ar
->conf_mutex
);
1089 ar
->debug
.htt_stats_mask
= mask
;
1091 ret
= ath10k_debug_htt_stats_req(ar
);
1098 mutex_unlock(&ar
->conf_mutex
);
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
;
1117 u8 amsdu
= 3, ampdu
= 64;
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
;
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
, &du
);
1150 mutex_lock(&ar
->conf_mutex
);
1152 res
= ath10k_htt_h2t_aggr_cfg_msg(&ar
->htt
, ampdu
, amsdu
);
1157 ar
->htt
.max_num_amsdu
= amsdu
;
1158 ar
->htt
.max_num_ampdu
= ampdu
;
1161 mutex_unlock(&ar
->conf_mutex
);
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
;
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
;
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
);
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
);
1219 ath10k_warn(ar
, "dbglog cfg failed from debugfs: %d\n",
1228 mutex_unlock(&ar
->conf_mutex
);
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
] = {
1249 "d_tx_power", /* in .5 dbM I think */
1250 "d_rx_crc_err", /* fcs_bad */
1252 "d_tx_mpdus_queued",
1254 "d_tx_msdu_dropped",
1257 "d_tx_ppdu_hw_queued",
1259 "d_tx_fifo_underrun",
1262 "d_tx_excessive_retries",
1264 "d_tx_dropped_sw_retries",
1265 "d_tx_illegal_rate",
1266 "d_tx_continuous_xretries",
1268 "d_tx_mpdu_txop_limit",
1270 "d_rx_mid_ppdu_route_change",
1272 "d_rx_extra_frags_ring0",
1273 "d_rx_extra_frags_ring1",
1274 "d_rx_extra_frags_ring2",
1275 "d_rx_extra_frags_ring3",
1281 "d_rx_phy_err_drops",
1282 "d_rx_mpdu_errors", /* FCS, MIC, ENC */
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
,
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
;
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
;
1317 mutex_lock(&ar
->conf_mutex
);
1319 if (ar
->state
== ATH10K_STATE_ON
) {
1320 ret
= ath10k_debug_fw_stats_request(ar
);
1322 /* just print a warning and try to use older results */
1324 "failed to get fw stats for ethtool: %d\n",
1329 pdev_stats
= list_first_entry_or_null(&ar
->debug
.fw_stats
.pdevs
,
1330 struct ath10k_fw_stats_pdev
,
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
;
1409 mutex_lock(&ar
->conf_mutex
);
1411 if (ar
->state
!= ATH10K_STATE_ON
&&
1412 ar
->state
!= ATH10K_STATE_UTF
) {
1417 buf
= vmalloc(QCA988X_CAL_DATA_LEN
);
1423 hi_addr
= host_interest_item_address(HI_ITEM(hi_board_data
));
1425 ret
= ath10k_hif_diag_read(ar
, hi_addr
, &addr
, sizeof(addr
));
1427 ath10k_warn(ar
, "failed to read hi_board_data address: %d\n", ret
);
1431 ret
= ath10k_hif_diag_read(ar
, le32_to_cpu(addr
), buf
,
1432 QCA988X_CAL_DATA_LEN
);
1434 ath10k_warn(ar
, "failed to read calibration data: %d\n", ret
);
1438 file
->private_data
= buf
;
1440 mutex_unlock(&ar
->conf_mutex
);
1448 mutex_unlock(&ar
->conf_mutex
);
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
,
1466 vfree(file
->private_data
);
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
;
1479 if (kstrtou8_from_user(user_buf
, count
, 0, &enable
))
1482 mutex_lock(&ar
->conf_mutex
);
1484 if (ar
->ani_enabled
== enable
) {
1489 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->ani_enable
,
1492 ath10k_warn(ar
, "ani_enable failed from debugfs: %d\n", ret
);
1495 ar
->ani_enabled
= enable
;
1500 mutex_unlock(&ar
->conf_mutex
);
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
;
1512 len
= scnprintf(buf
, sizeof(buf
) - len
, "%d\n",
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
;
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
;
1556 ret
= kstrtoul_from_user(user_buf
, count
, 0, &period
);
1560 if (period
> WMI_PDEV_PARAM_CAL_PERIOD_MAX
)
1563 /* there's no way to switch back to the firmware default */
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 */
1577 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->cal_period
,
1578 ar
->debug
.nf_cal_period
);
1580 ath10k_warn(ar
, "cal period cfg failed from debugfs: %d\n",
1588 mutex_unlock(&ar
->conf_mutex
);
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
)
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
);
1614 ath10k_warn(ar
, "failed to request tpc config: %d\n", ret
);
1618 time_left
= wait_for_completion_timeout(&ar
->debug
.tpc_complete
,
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",
1645 static const char pream_str
[][6] = { "CCK",
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",
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
,
1681 unsigned int len
, j
, buf_len
;
1684 buf_len
= ATH10K_TPC_CONFIG_BUF_SIZE
;
1686 spin_lock_bh(&ar
->data_lock
);
1689 ath10k_warn(ar
, "failed to get tpc stats\n");
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",
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
++) {
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");
1728 ath10k_tpc_stats_print(tpc_stats
, j
, buf
, &len
);
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");
1737 ath10k_tpc_stats_print(tpc_stats
, j
, buf
, &len
);
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");
1746 ath10k_tpc_stats_print(tpc_stats
, j
, buf
, &len
);
1749 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1756 spin_unlock_bh(&ar
->data_lock
);
1764 static int ath10k_tpc_stats_open(struct inode
*inode
, struct file
*file
)
1766 struct ath10k
*ar
= inode
->i_private
;
1770 mutex_lock(&ar
->conf_mutex
);
1772 if (ar
->state
!= ATH10K_STATE_ON
) {
1777 buf
= vmalloc(ATH10K_TPC_CONFIG_BUF_SIZE
);
1783 ret
= ath10k_debug_tpc_stats_request(ar
);
1785 ath10k_warn(ar
, "failed to request tpc config stats: %d\n",
1790 ath10k_tpc_stats_fill(ar
, ar
->debug
.tpc_stats
, buf
);
1791 file
->private_data
= buf
;
1793 mutex_unlock(&ar
->conf_mutex
);
1800 mutex_unlock(&ar
->conf_mutex
);
1804 static int ath10k_tpc_stats_release(struct inode
*inode
, struct file
*file
)
1806 vfree(file
->private_data
);
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
)
1832 lockdep_assert_held(&ar
->conf_mutex
);
1834 ret
= ath10k_debug_htt_stats_req(ar
);
1836 /* continue normally anyway, this isn't serious */
1837 ath10k_warn(ar
, "failed to start htt stats workqueue: %d\n",
1840 if (ar
->debug
.fw_dbglog_mask
) {
1841 ret
= ath10k_wmi_dbglog_cfg(ar
, ar
->debug
.fw_dbglog_mask
,
1842 ATH10K_DBGLOG_LEVEL_WARN
);
1845 ath10k_warn(ar
, "failed to enable dbglog during start: %d",
1849 if (ar
->debug
.pktlog_filter
) {
1850 ret
= ath10k_wmi_pdev_pktlog_enable(ar
,
1851 ar
->debug
.pktlog_filter
);
1855 "failed to enable pktlog filter %x: %d\n",
1856 ar
->debug
.pktlog_filter
, ret
);
1858 ret
= ath10k_wmi_pdev_pktlog_disable(ar
);
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
);
1870 ath10k_warn(ar
, "cal period cfg failed from debug start: %d\n",
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
)
1905 ieee80211_radar_detected(ar
->hw
);
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
;
1933 buf
= kzalloc(size
, GFP_KERNEL
);
1937 if (!ar
->dfs_detector
) {
1938 len
+= scnprintf(buf
+ len
, size
- len
, "DFS not enabled\n");
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
);
1966 retval
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
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
;
1987 if (kstrtouint_from_user(ubuf
, count
, 0, &filter
))
1990 mutex_lock(&ar
->conf_mutex
);
1992 if (ar
->state
!= ATH10K_STATE_ON
) {
1993 ar
->debug
.pktlog_filter
= filter
;
1998 if (filter
== ar
->debug
.pktlog_filter
) {
2004 ret
= ath10k_wmi_pdev_pktlog_enable(ar
, filter
);
2006 ath10k_warn(ar
, "failed to enable pktlog filter %x: %d\n",
2007 ar
->debug
.pktlog_filter
, ret
);
2011 ret
= ath10k_wmi_pdev_pktlog_disable(ar
);
2013 ath10k_warn(ar
, "failed to disable pktlog: %d\n", ret
);
2018 ar
->debug
.pktlog_filter
= filter
;
2022 mutex_unlock(&ar
->conf_mutex
);
2026 static ssize_t
ath10k_read_pktlog_filter(struct file
*file
, char __user
*ubuf
,
2027 size_t count
, loff_t
*ppos
)
2030 struct ath10k
*ar
= file
->private_data
;
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
,
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
;
2054 if (kstrtouint_from_user(ubuf
, count
, 0, &period
))
2057 if (period
< ATH10K_QUIET_PERIOD_MIN
) {
2058 ath10k_warn(ar
, "Quiet period %u can not be lesser than 25ms\n",
2062 mutex_lock(&ar
->conf_mutex
);
2063 ar
->thermal
.quiet_period
= period
;
2064 ath10k_thermal_set_throttling(ar
);
2065 mutex_unlock(&ar
->conf_mutex
);
2070 static ssize_t
ath10k_read_quiet_period(struct file
*file
, char __user
*ubuf
,
2071 size_t count
, loff_t
*ppos
)
2074 struct ath10k
*ar
= file
->private_data
;
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
,
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
)
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
);
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
);
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
,
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
,
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
,
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
);
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
;
2217 va_start(args
, fmt
);
2222 if (ath10k_debug_mask
& mask
)
2223 dev_printk(KERN_DEBUG
, ar
->dev
, "%pV", &vaf
);
2225 trace_ath10k_log_dbg(ar
, mask
, &vaf
);
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
)
2237 unsigned int linebuflen
;
2240 if (ath10k_debug_mask
& mask
) {
2242 ath10k_dbg(ar
, mask
, "%s\n", msg
);
2244 for (ptr
= buf
; (ptr
- buf
) < len
; ptr
+= 16) {
2246 linebuflen
+= scnprintf(linebuf
+ linebuflen
,
2247 sizeof(linebuf
) - linebuflen
,
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
: "",
2262 EXPORT_SYMBOL(ath10k_dbg_dump
);
2264 #endif /* CONFIG_ATH10K_DEBUG */