Linux wireless drivers development
 help / color / mirror / Atom feed
From: Zhao Li <enderaoelyther@gmail.com>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: "Jiangshan Yi" <yijiangshan@kylinos.cn>,
	"Arend van Spriel" <arend.vanspriel@broadcom.com>,
	"Stefan Hansson" <newbyte@postmarketos.org>,
	"Uwe Kleine-König" <u.kleine-koenig@baylibre.com>,
	"Ville Nummela" <ville.nummela@kempower.com>,
	"Jeongjun Park" <aha310510@gmail.com>,
	"Fariya Fatima" <fariyaf@gmail.com>,
	"John W. Linville" <linville@tuxdriver.com>,
	"Amitkumar Karwar" <amit.karwar@redpinesignals.com>,
	"Prameela Rani Garnepudi" <prameela.j04cs@gmail.com>,
	"Siva Rebbagondla" <siva.rebbagondla@redpinesignals.com>,
	"Kalle Valo" <kvalo@kernel.org>,
	linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH 2/2] wifi: rsi: stop coexistence TX before bus teardown
Date: Wed, 28 Oct 2026 22:20:15 +0800	[thread overview]
Message-ID: <20261028142015.10717-3-enderaoelyther@gmail.com> (raw)
In-Reply-To: <20261028142015.10717-1-enderaoelyther@gmail.com>

The coexistence TX thread can continue using an RSI bus after disconnect
resets or disables it. On USB, interface cleanup can also free the shared
TX buffer before the final core cleanup stops the thread.

rsi_coex_detach() only stops the thread from rsi_91x_deinit(), after the
bus has been reset or disabled. Its stop wakeup first drains any queued
Bluetooth packets through that unavailable bus.

Check the stop request before each queued packet. Stop coexistence TX
once HCI unregister has completed and before USB reset. Also stop it in
interface cleanup before freeing the TX buffer so probe unwind is
covered. On SDIO, stop it before chip reset and function disable on
disconnect, and before function disable during probe unwind.

rsi_coex_detach() still purges and frees the queues. The repeated stops
are harmless after the previous patch.

LLM assistance was used to find the bug and review.

Fixes: 716b840c7641 ("rsi: handle BT traffic in driver")
Cc: stable@vger.kernel.org
Signed-off-by: Zhao Li <enderaoelyther@gmail.com>
---
Validation: W=1 module builds with MODPOST passed for every prefix with
CONFIG_RSI_COEX enabled and disabled. The series applies to v7.3.
Not reproduced; RS9113/RS9116 hardware was unavailable.
Sparse C=2 passed. Smatch across all configured translation units under
drivers/net/wireless/rsi introduced no new diagnostics.

 drivers/net/wireless/rsi/rsi_91x_coex.c |  3 +++
 drivers/net/wireless/rsi/rsi_91x_sdio.c |  3 +++
 drivers/net/wireless/rsi/rsi_91x_usb.c  |  2 ++
 drivers/net/wireless/rsi/rsi_coex.h     | 12 ++++++++++++
 4 files changed, 20 insertions(+)

diff --git a/drivers/net/wireless/rsi/rsi_91x_coex.c b/drivers/net/wireless/rsi/rsi_91x_coex.c
index 023c539fc384..de2a973873ef 100644
--- a/drivers/net/wireless/rsi/rsi_91x_coex.c
+++ b/drivers/net/wireless/rsi/rsi_91x_coex.c
@@ -40,6 +40,9 @@ static void rsi_coex_sched_tx_pkts(struct rsi_coex_ctrl_block *coex_cb)
 	struct sk_buff *skb;
 
 	do {
+		if (atomic_read(&coex_cb->coex_tx_thread.thread_done))
+			break;
+
 		coex_q = rsi_coex_determine_coex_q(coex_cb);
 		rsi_dbg(INFO_ZONE, "queue = %d\n", coex_q);
 
diff --git a/drivers/net/wireless/rsi/rsi_91x_sdio.c b/drivers/net/wireless/rsi/rsi_91x_sdio.c
index c5619a34940d..87108f4a4326 100644
--- a/drivers/net/wireless/rsi/rsi_91x_sdio.c
+++ b/drivers/net/wireless/rsi/rsi_91x_sdio.c
@@ -1080,6 +1080,7 @@ static int rsi_probe(struct sdio_func *pfunction,
 	rsi_kill_thread(&sdev->rx_thread);
 fail_kill_thread:
 	rsi_kill_thread(&adapter->priv->tx_thread);
+	rsi_coex_stop_thread(adapter->priv);
 	sdio_claim_host(pfunction);
 	sdio_disable_func(pfunction);
 	sdio_release_host(pfunction);
@@ -1231,6 +1232,8 @@ static void rsi_disconnect(struct sdio_func *pfunction)
 		adapter->priv->bt_adapter = NULL;
 	}
 
+	rsi_coex_stop_thread(adapter->priv);
+
 	/* Reset Chip */
 	rsi_reset_chip(adapter);
 
diff --git a/drivers/net/wireless/rsi/rsi_91x_usb.c b/drivers/net/wireless/rsi/rsi_91x_usb.c
index 99e029e66407..f8b5c264a8a9 100644
--- a/drivers/net/wireless/rsi/rsi_91x_usb.c
+++ b/drivers/net/wireless/rsi/rsi_91x_usb.c
@@ -563,6 +563,7 @@ static void rsi_deinit_usb_interface(struct rsi_hw *adapter)
 
 	rsi_kill_thread(&dev->rx_thread);
 	rsi_kill_thread(&adapter->priv->tx_thread);
+	rsi_coex_stop_thread(adapter->priv);
 
 	usb_free_urb(dev->rx_cb[0].rx_urb);
 	if (adapter->priv->coex_mode > 1)
@@ -896,6 +897,7 @@ static void rsi_disconnect(struct usb_interface *pfunction)
 		adapter->priv->bt_adapter = NULL;
 	}
 
+	rsi_coex_stop_thread(adapter->priv);
 	rsi_reset_card(adapter);
 	rsi_deinit_usb_interface(adapter);
 	rsi_91x_deinit(adapter);
diff --git a/drivers/net/wireless/rsi/rsi_coex.h b/drivers/net/wireless/rsi/rsi_coex.h
index 2c14e4c651b9..cdd83650c5f1 100644
--- a/drivers/net/wireless/rsi/rsi_coex.h
+++ b/drivers/net/wireless/rsi/rsi_coex.h
@@ -29,9 +29,21 @@ struct rsi_coex_ctrl_block {
 	struct rsi_thread coex_tx_thread;
 };
 
+static inline void rsi_coex_stop_thread(struct rsi_common *common)
+{
+	struct rsi_coex_ctrl_block *coex_cb = common->coex_cb;
+
+	if (common->coex_mode > 1)
+		rsi_kill_thread(&coex_cb->coex_tx_thread);
+}
+
 int rsi_coex_attach(struct rsi_common *common);
 void rsi_coex_detach(struct rsi_common *common);
 int rsi_coex_send_pkt(void *priv, struct sk_buff *skb, u8 proto_type);
 int rsi_coex_recv_pkt(struct rsi_common *common, u8 *msg);
+#else
+static inline void rsi_coex_stop_thread(struct rsi_common *common)
+{
+}
 #endif
 #endif
-- 
2.56.0


      parent reply	other threads:[~2026-10-28 14:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28 14:20 [PATCH 0/2] wifi: rsi: stop packet threads before bus teardown Zhao Li
2026-10-28 14:20 ` [PATCH 1/2] wifi: rsi: stop WLAN threads before teardown Zhao Li
2026-10-28 14:20 ` Zhao Li [this message]

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=20261028142015.10717-3-enderaoelyther@gmail.com \
    --to=enderaoelyther@gmail.com \
    --cc=aha310510@gmail.com \
    --cc=amit.karwar@redpinesignals.com \
    --cc=arend.vanspriel@broadcom.com \
    --cc=fariyaf@gmail.com \
    --cc=johannes@sipsolutions.net \
    --cc=kvalo@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linville@tuxdriver.com \
    --cc=newbyte@postmarketos.org \
    --cc=prameela.j04cs@gmail.com \
    --cc=siva.rebbagondla@redpinesignals.com \
    --cc=stable@vger.kernel.org \
    --cc=u.kleine-koenig@baylibre.com \
    --cc=ville.nummela@kempower.com \
    --cc=yijiangshan@kylinos.cn \
    /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