From 0c35bb78ff0801ab07a8e2696c9f7b57ad1e5ac0 Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai@suse.de>
Date: Jun 20 2025 12:52:27 +0000
Subject: wifi: ath11k: don't use static variables in

ath11k_debugfs_fw_stats_process() (git-fixes).

---

diff --git a/patches.suse/wifi-ath11k-don-t-use-static-variables-in-ath11k_deb.patch b/patches.suse/wifi-ath11k-don-t-use-static-variables-in-ath11k_deb.patch
new file mode 100644
index 0000000..28a7633
--- /dev/null
+++ b/patches.suse/wifi-ath11k-don-t-use-static-variables-in-ath11k_deb.patch
@@ -0,0 +1,128 @@
+From 2bcf73b2612dda7432f2c2eaad6679bd291791f2 Mon Sep 17 00:00:00 2001
+From: Baochen Qiang <quic_bqiang@quicinc.com>
+Date: Thu, 20 Feb 2025 16:24:43 +0800
+Subject: [PATCH] wifi: ath11k: don't use static variables in ath11k_debugfs_fw_stats_process()
+Git-commit: 2bcf73b2612dda7432f2c2eaad6679bd291791f2
+Patch-mainline: v6.16-rc2
+References: git-fixes
+
+Currently ath11k_debugfs_fw_stats_process() is using static variables to count
+firmware stat events. Taking num_vdev as an example, if for whatever reason (
+say ar->num_started_vdevs is 0 or firmware bug etc.) the following condition
+
+	(++num_vdev) == total_vdevs_started
+
+is not met, is_end is not set thus num_vdev won't be cleared. Next time when
+firmware stats is requested again, even if everything is working fine, we will
+fail due to the condition above will never be satisfied.
+
+The same applies to num_bcn as well.
+
+Change to use non-static counters so that we have a chance to clear them each
+time firmware stats is requested. Currently only ath11k_fw_stats_request() and
+ath11k_debugfs_fw_stats_request() are requesting firmware stats, so clear
+counters there.
+
+Tested-on: WCN6855 hw2.0 PCI WLAN.HSP.1.1-03125-QCAHSPSWPL_V1_V2_SILICONZ_LITE-3.6510.37
+
+Fixes: da3a9d3c1576 ("ath11k: refactor debugfs code into debugfs.c")
+Signed-off-by: Baochen Qiang <quic_bqiang@quicinc.com>
+Acked-by: Kalle Valo <kvalo@kernel.org>
+Reviewed-by: Vasanthakumar Thiagarajan <vasanthakumar.thiagarajan@oss.qualcomm.com>
+Link: https://patch.msgid.link/20250220082448.31039-3-quic_bqiang@quicinc.com
+Signed-off-by: Jeff Johnson <jeff.johnson@oss.qualcomm.com>
+Acked-by: Takashi Iwai <tiwai@suse.de>
+
+---
+ drivers/net/wireless/ath/ath11k/core.h    |  2 ++
+ drivers/net/wireless/ath/ath11k/debugfs.c | 16 +++++++---------
+ drivers/net/wireless/ath/ath11k/mac.c     |  2 ++
+ 3 files changed, 11 insertions(+), 9 deletions(-)
+
+diff --git a/drivers/net/wireless/ath/ath11k/core.h b/drivers/net/wireless/ath/ath11k/core.h
+index 41bb81d00189..6b2f207975e3 100644
+--- a/drivers/net/wireless/ath/ath11k/core.h
++++ b/drivers/net/wireless/ath/ath11k/core.h
+@@ -600,6 +600,8 @@ struct ath11k_fw_stats {
+ 	struct list_head pdevs;
+ 	struct list_head vdevs;
+ 	struct list_head bcn;
++	u32 num_vdev_recvd;
++	u32 num_bcn_recvd;
+ };
+ 
+ struct ath11k_dbg_htt_stats {
+diff --git a/drivers/net/wireless/ath/ath11k/debugfs.c b/drivers/net/wireless/ath/ath11k/debugfs.c
+index 1d03e3aab011..27c93c0b4c22 100644
+--- a/drivers/net/wireless/ath/ath11k/debugfs.c
++++ b/drivers/net/wireless/ath/ath11k/debugfs.c
+@@ -98,6 +98,8 @@ static void ath11k_debugfs_fw_stats_reset(struct ath11k *ar)
+ 	spin_lock_bh(&ar->data_lock);
+ 	ath11k_fw_stats_pdevs_free(&ar->fw_stats.pdevs);
+ 	ath11k_fw_stats_vdevs_free(&ar->fw_stats.vdevs);
++	ar->fw_stats.num_vdev_recvd = 0;
++	ar->fw_stats.num_bcn_recvd = 0;
+ 	spin_unlock_bh(&ar->data_lock);
+ }
+ 
+@@ -106,7 +108,6 @@ void ath11k_debugfs_fw_stats_process(struct ath11k *ar, struct ath11k_fw_stats *
+ 	struct ath11k_base *ab = ar->ab;
+ 	struct ath11k_pdev *pdev;
+ 	bool is_end;
+-	static unsigned int num_vdev, num_bcn;
+ 	size_t total_vdevs_started = 0;
+ 	int i;
+ 
+@@ -131,15 +132,14 @@ void ath11k_debugfs_fw_stats_process(struct ath11k *ar, struct ath11k_fw_stats *
+ 				total_vdevs_started += ar->num_started_vdevs;
+ 		}
+ 
+-		is_end = ((++num_vdev) == total_vdevs_started);
++		is_end = ((++ar->fw_stats.num_vdev_recvd) == total_vdevs_started);
+ 
+ 		list_splice_tail_init(&stats->vdevs,
+ 				      &ar->fw_stats.vdevs);
+ 
+-		if (is_end) {
++		if (is_end)
+ 			complete(&ar->fw_stats_done);
+-			num_vdev = 0;
+-		}
++
+ 		return;
+ 	}
+ 
+@@ -151,15 +151,13 @@ void ath11k_debugfs_fw_stats_process(struct ath11k *ar, struct ath11k_fw_stats *
+ 		/* Mark end until we reached the count of all started VDEVs
+ 		 * within the PDEV
+ 		 */
+-		is_end = ((++num_bcn) == ar->num_started_vdevs);
++		is_end = ((++ar->fw_stats.num_bcn_recvd) == ar->num_started_vdevs);
+ 
+ 		list_splice_tail_init(&stats->bcn,
+ 				      &ar->fw_stats.bcn);
+ 
+-		if (is_end) {
++		if (is_end)
+ 			complete(&ar->fw_stats_done);
+-			num_bcn = 0;
+-		}
+ 	}
+ }
+ 
+diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c
+index 9ab501cd4f47..5e098780cf23 100644
+--- a/drivers/net/wireless/ath/ath11k/mac.c
++++ b/drivers/net/wireless/ath/ath11k/mac.c
+@@ -9391,6 +9391,8 @@ static int ath11k_fw_stats_request(struct ath11k *ar,
+ 
+ 	spin_lock_bh(&ar->data_lock);
+ 	ath11k_fw_stats_pdevs_free(&ar->fw_stats.pdevs);
++	ar->fw_stats.num_vdev_recvd = 0;
++	ar->fw_stats.num_bcn_recvd = 0;
+ 	spin_unlock_bh(&ar->data_lock);
+ 
+ 	reinit_completion(&ar->fw_stats_complete);
+-- 
+2.49.0
+
diff --git a/series.conf b/series.conf
index 383785d..ef97cae 100644
--- a/series.conf
+++ b/series.conf
@@ -32546,6 +32546,7 @@
 	patches.suse/Bluetooth-MGMT-Fix-sparse-errors.patch
 	patches.suse/ath10k-snoc-fix-unbalanced-IRQ-enable-in-crash-recov.patch
 	patches.suse/wifi-ath11k-avoid-burning-CPU-in-ath11k_debugfs_fw_s.patch
+	patches.suse/wifi-ath11k-don-t-use-static-variables-in-ath11k_deb.patch
 	patches.suse/wifi-ath11k-validate-ath11k_crypto_mode-on-top-of-at.patch
 	patches.suse/regulator-max20086-Fix-refcount-leak-in-max20086_par.patch
 	patches.suse/ACPI-CPPC-Fix-NULL-pointer-dereference-when-nosmp-is.patch