mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Aditya Kumar Singh <quic_adisi@quicinc.com>
To: Kalle Valo <kvalo@kernel.org>, Jeff Johnson <jjohnson@kernel.org>,
	Karthikeyan Periyasamy <quic_periyasa@quicinc.com>,
	Harshitha Prem <quic_hprem@quicinc.com>
Cc: Jeff Johnson <jeff.johnson@oss.qualcomm.com>,
	Kalle Valo <quic_kvalo@quicinc.com>,
	<linux-wireless@vger.kernel.org>, <ath12k@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>,
	"Aditya Kumar Singh" <quic_adisi@quicinc.com>
Subject: [PATCH v2 02/10] wifi: ath12k: add reference counting for core attachment to hardware group
Date: Mon, 20 Jan 2025 15:18:22 +0530	[thread overview]
Message-ID: <20250120-fix_reboot_issues_with_hw_grouping-v2-2-b7d073bb2a22@quicinc.com> (raw)
In-Reply-To: <20250120-fix_reboot_issues_with_hw_grouping-v2-0-b7d073bb2a22@quicinc.com>

Currently, driver does not manage reference counting for attaching and
detaching cores to/from hardware groups. This can lead to issues when
multiple cores are involved. Or with same core, attach/detach is called
multiple times back to back.

Fix this issue by using reference counting.

With that, it is now ensured that the core is properly attached or detached
from the hardware group and even back to back calls will not alter the
count.

Additionally, add some debug logs during the attachment and detachment
events for better debugging and tracking.

Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.3.1-00173-QCAHKSWPL_SILICONZ-1

Acked-by: Jeff Johnson <jeff.johnson@oss.qualcomm.com>
Signed-off-by: Aditya Kumar Singh <quic_adisi@quicinc.com>
---
 drivers/net/wireless/ath/ath12k/core.c | 47 +++++++++++++++++++++++++++++++---
 drivers/net/wireless/ath/ath12k/core.h | 15 +----------
 2 files changed, 44 insertions(+), 18 deletions(-)

diff --git a/drivers/net/wireless/ath/ath12k/core.c b/drivers/net/wireless/ath/ath12k/core.c
index 1959c59cb2bb18aeec215b9d309468b7c6716752..05a914a3f8555236deeab89729d02527e7b4d786 100644
--- a/drivers/net/wireless/ath/ath12k/core.c
+++ b/drivers/net/wireless/ath/ath12k/core.c
@@ -603,9 +603,49 @@ u32 ath12k_core_get_max_num_tids(struct ath12k_base *ab)
 	return TARGET_NUM_TIDS(SINGLE);
 }
 
+static inline
+void ath12k_core_to_group_ref_get(struct ath12k_base *ab)
+{
+	struct ath12k_hw_group *ag = ab->ag;
+
+	lockdep_assert_held(&ag->mutex);
+
+	if (ab->hw_group_ref) {
+		ath12k_dbg(ab, ATH12K_DBG_BOOT, "core already attached to group %d\n",
+			   ag->id);
+		return;
+	}
+
+	ab->hw_group_ref = true;
+	ag->num_started++;
+
+	ath12k_dbg(ab, ATH12K_DBG_BOOT, "core attached to group %d, num_started %d\n",
+		   ag->id, ag->num_started);
+}
+
+static inline
+void ath12k_core_to_group_ref_put(struct ath12k_base *ab)
+{
+	struct ath12k_hw_group *ag = ab->ag;
+
+	lockdep_assert_held(&ag->mutex);
+
+	if (!ab->hw_group_ref) {
+		ath12k_dbg(ab, ATH12K_DBG_BOOT, "core already de-attached from group %d\n",
+			   ag->id);
+		return;
+	}
+
+	ab->hw_group_ref = false;
+	ag->num_started--;
+
+	ath12k_dbg(ab, ATH12K_DBG_BOOT, "core de-attached from group %d, num_started %d\n",
+		   ag->id, ag->num_started);
+}
+
 static void ath12k_core_stop(struct ath12k_base *ab)
 {
-	ath12k_core_stopped(ab);
+	ath12k_core_to_group_ref_put(ab);
 
 	if (!test_bit(ATH12K_FLAG_CRASH_FLUSH, &ab->dev_flags))
 		ath12k_qmi_firmware_stop(ab);
@@ -841,9 +881,8 @@ static int ath12k_core_start(struct ath12k_base *ab,
 		/* ACPI is optional so continue in case of an error */
 		ath12k_dbg(ab, ATH12K_DBG_BOOT, "acpi failed: %d\n", ret);
 
-	if (!test_bit(ATH12K_FLAG_RECOVERY, &ab->dev_flags))
-		/* Indicate the core start in the appropriate group */
-		ath12k_core_started(ab);
+	/* Indicate the core start in the appropriate group */
+	ath12k_core_to_group_ref_get(ab);
 
 	return 0;
 
diff --git a/drivers/net/wireless/ath/ath12k/core.h b/drivers/net/wireless/ath/ath12k/core.h
index ee595794a7aee83a7695fb57d6b8e2e74eabf3aa..e20551a8838622dfaaff8943915b0a251d5b4e86 100644
--- a/drivers/net/wireless/ath/ath12k/core.h
+++ b/drivers/net/wireless/ath/ath12k/core.h
@@ -1052,6 +1052,7 @@ struct ath12k_base {
 
 	struct ath12k_hw_group *ag;
 	struct ath12k_wsi_info wsi_info;
+	bool hw_group_ref;
 
 	/* must be last */
 	u8 drv_priv[] __aligned(sizeof(void *));
@@ -1210,20 +1211,6 @@ static inline struct ath12k_hw_group *ath12k_ab_to_ag(struct ath12k_base *ab)
 	return ab->ag;
 }
 
-static inline void ath12k_core_started(struct ath12k_base *ab)
-{
-	lockdep_assert_held(&ab->ag->mutex);
-
-	ab->ag->num_started++;
-}
-
-static inline void ath12k_core_stopped(struct ath12k_base *ab)
-{
-	lockdep_assert_held(&ab->ag->mutex);
-
-	ab->ag->num_started--;
-}
-
 static inline struct ath12k_base *ath12k_ag_to_ab(struct ath12k_hw_group *ag,
 						  u8 device_id)
 {

-- 
2.34.1


  parent reply	other threads:[~2025-01-20  9:49 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-20  9:48 [PATCH v2 00/10] wifi: ath12k: fixes for rmmod and recovery issues with hardware grouping Aditya Kumar Singh
2025-01-20  9:48 ` [PATCH v2 01/10] wifi: ath12k: prevent race condition in ath12k_core_hw_group_destroy() Aditya Kumar Singh
2025-01-20  9:48 ` Aditya Kumar Singh [this message]
2025-01-20  9:48 ` [PATCH v2 03/10] wifi: ath12k: fix failed to set mhi state error during reboot with hardware grouping Aditya Kumar Singh
2025-01-20  9:48 ` [PATCH v2 04/10] wifi: ath12k: fix firmware assert " Aditya Kumar Singh
2025-01-20  9:48 ` [PATCH v2 05/10] wifi: ath12k: fix SLUB BUG - Object already free in ath12k_reg_free() Aditya Kumar Singh
2025-01-20  9:48 ` [PATCH v2 06/10] wifi: ath12k: fix ath12k_core_pre_reconfigure_recovery() with grouping Aditya Kumar Singh
2025-01-20  9:48 ` [PATCH v2 07/10] wifi: ath12k: fix ATH12K_FLAG_REGISTERED flag handling Aditya Kumar Singh
2025-01-20  9:48 ` [PATCH v2 08/10] wifi: ath12k: handle ath12k_core_restart() with hardware grouping Aditya Kumar Singh
2025-01-20  9:48 ` [PATCH v2 09/10] wifi: ath12k: handle ath12k_core_reset() " Aditya Kumar Singh
2025-01-20  9:48 ` [PATCH v2 10/10] wifi: ath12k: reset MLO global memory during recovery Aditya Kumar Singh
2025-01-23 17:47 ` [PATCH v2 00/10] wifi: ath12k: fixes for rmmod and recovery issues with hardware grouping Jeff Johnson
2025-01-24  4:10   ` Aditya Kumar Singh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250120-fix_reboot_issues_with_hw_grouping-v2-2-b7d073bb2a22@quicinc.com \
    --to=quic_adisi@quicinc.com \
    --cc=ath12k@lists.infradead.org \
    --cc=jeff.johnson@oss.qualcomm.com \
    --cc=jjohnson@kernel.org \
    --cc=kvalo@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=quic_hprem@quicinc.com \
    --cc=quic_kvalo@quicinc.com \
    --cc=quic_periyasa@quicinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®