From 18bcd286cb1f6f6296e13281803541eb385960cc Mon Sep 17 00:00:00 2001 From: Nagarajan Maran Date: Tue, 6 Jun 2023 06:55:56 +0530 Subject: [PATCH] ath12k: Add debugfs support to enable and disable sawf stats Add support to enable sawf stats from debugfs Enable Basic stats: echo 1 > /sys/kernel/debug/ath12k//mac0/sawf_stats Enable Advanced stats: echo 2 > /sys/kernel/debug/ath12k//mac0/sawf_stats Enable Latency stats: echo 4 > /sys/kernel/debug/ath12k//mac0/sawf_stats Signed-off-by: Nagarajan Maran --- drivers/net/wireless/ath/ath12k/core.h | 1 + drivers/net/wireless/ath/ath12k/debugfs.c | 64 +++++++++++++++++++++++ drivers/net/wireless/ath/ath12k/debugfs.h | 10 ++++ drivers/net/wireless/ath/ath12k/sawf.h | 12 +++++ 4 files changed, 87 insertions(+) --- a/drivers/net/wireless/ath/ath12k/core.h +++ b/drivers/net/wireless/ath/ath12k/core.h @@ -748,6 +748,9 @@ struct ath12k_debug { struct ath12k_dbg_htt_stats htt_stats; u32 extd_tx_stats; u32 extd_rx_stats; +#ifdef CPTCFG_ATH12K_SAWF + u32 sawf_stats; +#endif u32 pktlog_filter; u32 pktlog_mode; u32 pktlog_peer_valid; --- a/drivers/net/wireless/ath/ath12k/debugfs.c +++ b/drivers/net/wireless/ath/ath12k/debugfs.c @@ -4107,6 +4107,73 @@ static const struct file_operations fops .llseek = default_llseek, }; +#ifdef CPTCFG_ATH12K_SAWF +static ssize_t ath12k_write_sawf_stats(struct file *file, + const char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct ath12k *ar = file->private_data; + u32 sawf_stats; + int ret; + + if (kstrtouint_from_user(ubuf, count, 0, &sawf_stats)) + return -EINVAL; + + mutex_lock(&ar->conf_mutex); + + if (ar->state != ATH12K_STATE_ON) { + ath12k_err(ar->ab, "Netdev is down\n"); + ret = -ENETDOWN; + goto out; + } + + if (!ath12k_sawf_enable) + { + ath12k_err(ar->ab, "SAWF support is not enabled\n"); + ret = -EOPNOTSUPP; + goto out; + } + + if (sawf_stats > ATH12K_SAWF_STATS_MAX) { + ret = -EINVAL; + goto out; + } + + ret = count; + + if (sawf_stats == ar->debug.sawf_stats) + goto out; + + ar->debug.sawf_stats = sawf_stats; + +out: + mutex_unlock(&ar->conf_mutex); + return ret; +} + +static ssize_t ath12k_read_sawf_stats(struct file *file, + char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct ath12k *ar = file->private_data; + int len = 0; + char buf[32] = {0}; + + mutex_lock(&ar->conf_mutex); + len = scnprintf(buf, sizeof(buf) - len, "%08x\n", + ar->debug.sawf_stats); + mutex_unlock(&ar->conf_mutex); + + return simple_read_from_buffer(ubuf, count, ppos, buf, len); +} + +static const struct file_operations fops_sawf_stats = { + .read = ath12k_read_sawf_stats, + .write = ath12k_write_sawf_stats, + .open = simple_open +}; +#endif /* CPTCFG_ATH12K_SAWF */ + int ath12k_debugfs_register(struct ath12k *ar) { struct ath12k_base *ab = ar->ab; @@ -4205,7 +4272,11 @@ int ath12k_debugfs_register(struct ath12 debugfs_create_file("btcoex_priority", 0600, ar->debug.debugfs_pdev, ar, &fops_btcoex_priority); - +#ifdef CPTCFG_ATH12K_SAWF + debugfs_create_file("sawf_stats", 0644, + ar->debug.debugfs_pdev, ar, + &fops_sawf_stats); +#endif return 0; } --- a/drivers/net/wireless/ath/ath12k/debugfs.h +++ b/drivers/net/wireless/ath/ath12k/debugfs.h @@ -405,6 +405,21 @@ static inline void ath12k_debugfs_nrp_cl } #endif /* CPTCFG_MAC80211_DEBUGFS*/ +#ifdef CPTCFG_ATH12K_SAWF +static inline unsigned int ath12k_debugfs_is_sawf_stats_enabled(struct ath12k *ar) +{ + return ar->debug.sawf_stats; +} + +#else + +static inline unsigned int ath12k_debugfs_is_sawf_stats_enabled(struct ath12k *ar) +{ + return 0; +} + +#endif + #ifdef CPTCFG_ATH12K_PKTLOG void ath12k_init_pktlog(struct ath12k *ar); void ath12k_deinit_pktlog(struct ath12k *ar); --- a/drivers/net/wireless/ath/ath12k/sawf.h +++ b/drivers/net/wireless/ath/ath12k/sawf.h @@ -463,6 +463,20 @@ struct wmi_tid_latency_info { __le32 latency_tid_info; } __packed; +/** + * ath12k_sawf_stats_level - sawf stats level + * @ATH12K_SAWF_STATS_BASIC : sawf basic stats + * @ATH12K_SAWF_STATS_ADVANCED : sawf advanced stats + * @ATH12K_SAWF_STATS_LATENCY : sawf latency stats + */ +enum ath12k_sawf_stats_level { + ATH12K_SAWF_STATS_BASIC = BIT(0), + ATH12K_SAWF_STATS_ADVNCD = BIT(1), + ATH12K_SAWF_STATS_LATENCY = BIT(2), +}; + +#define ATH12K_SAWF_STATS_MAX (ATH12K_SAWF_STATS_BASIC | ATH12K_SAWF_STATS_ADVNCD | ATH12K_SAWF_STATS_LATENCY) + extern bool ath12k_sawf_enable; struct ath12k_sawf_ctx *ath12k_get_sawf_context(void); void ath12k_sawf_init(struct ath12k_base *ab);