LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] Bluetooth: btusb: Mediatek ISO interface cliam/release adjustment
@ 2024-09-16 11:39 Chris Lu
  2024-09-16 11:39 ` [PATCH 1/4] Bluetooth: btusb: mediatek: move Bluetooth power off in btusb_mtk_shutdown Chris Lu
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Chris Lu @ 2024-09-16 11:39 UTC (permalink / raw)
  To: Marcel Holtmann, Johan Hedberg, Luiz Von Dentz
  Cc: Sean Wang, Aaron Hou, Steve Lee, linux-bluetooth, linux-kernel,
	linux-mediatek, Chris Lu

MediaTek performs some test on the platform which can support LE audio and
ISO data transmission with kernel driver. We found the additional interface
claim and release flow issue need some adjustment.

These patches mainly add a callback function within the usb_disconnect function
to prevent a kernel panic caused by interfaces not being released when the BT USB
dongle is physically removed. Additionally, the condition for claiming/releasing
ISO usb interface have also been adjusted to make driver works as expected.

Chris Lu (4):
  Bluetooth: btusb: mediatek: move Bluetooth power off in
    btusb_mtk_shutdown
  Bluetooth: btusb: add callback function in btusb_disconnect
  Bluetooth: btusb: mediatek: add intf release flow in usb disconnect
  Bluetooth: btusb: mediatek: change the conditions for
    claiming/releasing iso interface

 drivers/bluetooth/btusb.c | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

-- 
2.18.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] Bluetooth: btusb: mediatek: move Bluetooth power off in btusb_mtk_shutdown
  2024-09-16 11:39 [PATCH 0/4] Bluetooth: btusb: Mediatek ISO interface cliam/release adjustment Chris Lu
@ 2024-09-16 11:39 ` Chris Lu
  2024-09-16 11:39 ` [PATCH 2/4] Bluetooth: btusb: add callback function in btusb_disconnect Chris Lu
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Chris Lu @ 2024-09-16 11:39 UTC (permalink / raw)
  To: Marcel Holtmann, Johan Hedberg, Luiz Von Dentz
  Cc: Sean Wang, Aaron Hou, Steve Lee, linux-bluetooth, linux-kernel,
	linux-mediatek, Chris Lu

Move MediaTek Bluetooth power off command before releasing usb ISO interface.

Signed-off-by: Chris Lu <chris.lu@mediatek.com>
---
 drivers/bluetooth/btusb.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 6c9c761d5b93..6cf1729a8225 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -2704,11 +2704,14 @@ static int btusb_mtk_shutdown(struct hci_dev *hdev)
 {
 	struct btusb_data *data = hci_get_drvdata(hdev);
 	struct btmtk_data *btmtk_data = hci_get_priv(hdev);
+	int ret;
+
+	ret = btmtk_usb_shutdown(hdev);
 
 	if (test_bit(BTMTK_ISOPKT_RUNNING, &btmtk_data->flags))
 		btusb_mtk_release_iso_intf(data);
 
-	return btmtk_usb_shutdown(hdev);
+	return ret;
 }
 
 #ifdef CONFIG_PM
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] Bluetooth: btusb: add callback function in btusb_disconnect
  2024-09-16 11:39 [PATCH 0/4] Bluetooth: btusb: Mediatek ISO interface cliam/release adjustment Chris Lu
  2024-09-16 11:39 ` [PATCH 1/4] Bluetooth: btusb: mediatek: move Bluetooth power off in btusb_mtk_shutdown Chris Lu
@ 2024-09-16 11:39 ` Chris Lu
  2024-09-16 11:39 ` [PATCH 3/4] Bluetooth: btusb: mediatek: add intf release flow in usb disconnect Chris Lu
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Chris Lu @ 2024-09-16 11:39 UTC (permalink / raw)
  To: Marcel Holtmann, Johan Hedberg, Luiz Von Dentz
  Cc: Sean Wang, Aaron Hou, Steve Lee, linux-bluetooth, linux-kernel,
	linux-mediatek, Chris Lu

Add disconnect callback function in btusb_disconnect which is reserved
for vendor specific usage before deregister hci in btusb_disconnect.

Signed-off-by: Chris Lu <chris.lu@mediatek.com>
---
 drivers/bluetooth/btusb.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 6cf1729a8225..dfc42bdc8aaf 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -846,6 +846,7 @@ struct btusb_data {
 
 	int (*suspend)(struct hci_dev *hdev);
 	int (*resume)(struct hci_dev *hdev);
+	int (*disconnect)(struct hci_dev *hdev);
 
 	int oob_wake_irq;   /* irq for out-of-band wake-on-bt */
 	unsigned cmd_timeout_cnt;
@@ -4011,6 +4012,9 @@ static void btusb_disconnect(struct usb_interface *intf)
 	if (data->diag)
 		usb_set_intfdata(data->diag, NULL);
 
+	if (data->disconnect)
+		data->disconnect(hdev);
+
 	hci_unregister_dev(hdev);
 
 	if (intf == data->intf) {
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] Bluetooth: btusb: mediatek: add intf release flow in usb disconnect
  2024-09-16 11:39 [PATCH 0/4] Bluetooth: btusb: Mediatek ISO interface cliam/release adjustment Chris Lu
  2024-09-16 11:39 ` [PATCH 1/4] Bluetooth: btusb: mediatek: move Bluetooth power off in btusb_mtk_shutdown Chris Lu
  2024-09-16 11:39 ` [PATCH 2/4] Bluetooth: btusb: add callback function in btusb_disconnect Chris Lu
@ 2024-09-16 11:39 ` Chris Lu
  2024-09-16 11:39 ` [PATCH 4/4] Bluetooth: btusb: mediatek: change the conditions for claiming/releasing ISO interface Chris Lu
  2024-09-23 17:00 ` [PATCH 0/4] Bluetooth: btusb: Mediatek ISO interface cliam/release adjustment patchwork-bot+bluetooth
  4 siblings, 0 replies; 6+ messages in thread
From: Chris Lu @ 2024-09-16 11:39 UTC (permalink / raw)
  To: Marcel Holtmann, Johan Hedberg, Luiz Von Dentz
  Cc: Sean Wang, Aaron Hou, Steve Lee, linux-bluetooth, linux-kernel,
	linux-mediatek, Chris Lu

MediaTek claim an special usb intr interface for ISO data transmission.
The interface need to be released before unregistering hci device when
usb disconnect. Removing BT usb dongle without properly releasing the
interface may cause Kernel panic while unregister hci device.

Signed-off-by: Chris Lu <chris.lu@mediatek.com>
---
 drivers/bluetooth/btusb.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index dfc42bdc8aaf..37e67b451b34 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -2614,9 +2614,9 @@ static void btusb_mtk_claim_iso_intf(struct btusb_data *data)
 	set_bit(BTMTK_ISOPKT_OVER_INTR, &btmtk_data->flags);
 }
 
-static void btusb_mtk_release_iso_intf(struct btusb_data *data)
+static int btusb_mtk_release_iso_intf(struct hci_dev *hdev)
 {
-	struct btmtk_data *btmtk_data = hci_get_priv(data->hdev);
+	struct btmtk_data *btmtk_data = hci_get_priv(hdev);
 
 	if (btmtk_data->isopkt_intf) {
 		usb_kill_anchored_urbs(&btmtk_data->isopkt_anchor);
@@ -2630,6 +2630,8 @@ static void btusb_mtk_release_iso_intf(struct btusb_data *data)
 	}
 
 	clear_bit(BTMTK_ISOPKT_OVER_INTR, &btmtk_data->flags);
+
+	return 0;
 }
 
 static int btusb_mtk_reset(struct hci_dev *hdev, void *rst_data)
@@ -2649,7 +2651,7 @@ static int btusb_mtk_reset(struct hci_dev *hdev, void *rst_data)
 		return err;
 
 	if (test_bit(BTMTK_ISOPKT_RUNNING, &btmtk_data->flags))
-		btusb_mtk_release_iso_intf(data);
+		btusb_mtk_release_iso_intf(hdev);
 
 	btusb_stop_traffic(data);
 	usb_kill_anchored_urbs(&data->tx_anchor);
@@ -2703,14 +2705,13 @@ static int btusb_mtk_setup(struct hci_dev *hdev)
 
 static int btusb_mtk_shutdown(struct hci_dev *hdev)
 {
-	struct btusb_data *data = hci_get_drvdata(hdev);
 	struct btmtk_data *btmtk_data = hci_get_priv(hdev);
 	int ret;
 
 	ret = btmtk_usb_shutdown(hdev);
 
 	if (test_bit(BTMTK_ISOPKT_RUNNING, &btmtk_data->flags))
-		btusb_mtk_release_iso_intf(data);
+		btusb_mtk_release_iso_intf(hdev);
 
 	return ret;
 }
@@ -3824,6 +3825,7 @@ static int btusb_probe(struct usb_interface *intf,
 		data->recv_acl = btmtk_usb_recv_acl;
 		data->suspend = btmtk_usb_suspend;
 		data->resume = btmtk_usb_resume;
+		data->disconnect = btusb_mtk_release_iso_intf;
 	}
 
 	if (id->driver_info & BTUSB_SWAVE) {
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] Bluetooth: btusb: mediatek: change the conditions for claiming/releasing ISO interface
  2024-09-16 11:39 [PATCH 0/4] Bluetooth: btusb: Mediatek ISO interface cliam/release adjustment Chris Lu
                   ` (2 preceding siblings ...)
  2024-09-16 11:39 ` [PATCH 3/4] Bluetooth: btusb: mediatek: add intf release flow in usb disconnect Chris Lu
@ 2024-09-16 11:39 ` Chris Lu
  2024-09-23 17:00 ` [PATCH 0/4] Bluetooth: btusb: Mediatek ISO interface cliam/release adjustment patchwork-bot+bluetooth
  4 siblings, 0 replies; 6+ messages in thread
From: Chris Lu @ 2024-09-16 11:39 UTC (permalink / raw)
  To: Marcel Holtmann, Johan Hedberg, Luiz Von Dentz
  Cc: Sean Wang, Aaron Hou, Steve Lee, linux-bluetooth, linux-kernel,
	linux-mediatek, Chris Lu

Change conditions for Bluetooth driver claiming and releasing usb
ISO interface for MediaTek ISO data transmission.

Signed-off-by: Chris Lu <chris.lu@mediatek.com>
---
 drivers/bluetooth/btusb.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 37e67b451b34..bb28a9b2dc11 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -2618,7 +2618,7 @@ static int btusb_mtk_release_iso_intf(struct hci_dev *hdev)
 {
 	struct btmtk_data *btmtk_data = hci_get_priv(hdev);
 
-	if (btmtk_data->isopkt_intf) {
+	if (test_bit(BTMTK_ISOPKT_OVER_INTR, &btmtk_data->flags)) {
 		usb_kill_anchored_urbs(&btmtk_data->isopkt_anchor);
 		clear_bit(BTMTK_ISOPKT_RUNNING, &btmtk_data->flags);
 
@@ -2650,7 +2650,7 @@ static int btusb_mtk_reset(struct hci_dev *hdev, void *rst_data)
 	if (err < 0)
 		return err;
 
-	if (test_bit(BTMTK_ISOPKT_RUNNING, &btmtk_data->flags))
+	if (test_bit(BTMTK_ISOPKT_OVER_INTR, &btmtk_data->flags))
 		btusb_mtk_release_iso_intf(hdev);
 
 	btusb_stop_traffic(data);
@@ -2696,9 +2696,10 @@ static int btusb_mtk_setup(struct hci_dev *hdev)
 	btmtk_data->reset_sync = btusb_mtk_reset;
 
 	/* Claim ISO data interface and endpoint */
-	btmtk_data->isopkt_intf = usb_ifnum_to_if(data->udev, MTK_ISO_IFNUM);
-	if (btmtk_data->isopkt_intf)
+	if (!test_bit(BTMTK_ISOPKT_OVER_INTR, &btmtk_data->flags)) {
+		btmtk_data->isopkt_intf = usb_ifnum_to_if(data->udev, MTK_ISO_IFNUM);
 		btusb_mtk_claim_iso_intf(data);
+	}
 
 	return btmtk_usb_setup(hdev);
 }
@@ -2710,7 +2711,7 @@ static int btusb_mtk_shutdown(struct hci_dev *hdev)
 
 	ret = btmtk_usb_shutdown(hdev);
 
-	if (test_bit(BTMTK_ISOPKT_RUNNING, &btmtk_data->flags))
+	if (test_bit(BTMTK_ISOPKT_OVER_INTR, &btmtk_data->flags))
 		btusb_mtk_release_iso_intf(hdev);
 
 	return ret;
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] Bluetooth: btusb: Mediatek ISO interface cliam/release adjustment
  2024-09-16 11:39 [PATCH 0/4] Bluetooth: btusb: Mediatek ISO interface cliam/release adjustment Chris Lu
                   ` (3 preceding siblings ...)
  2024-09-16 11:39 ` [PATCH 4/4] Bluetooth: btusb: mediatek: change the conditions for claiming/releasing ISO interface Chris Lu
@ 2024-09-23 17:00 ` patchwork-bot+bluetooth
  4 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+bluetooth @ 2024-09-23 17:00 UTC (permalink / raw)
  To: Chris Lu
  Cc: marcel, johan.hedberg, luiz.dentz, sean.wang, aaron.hou,
	steve.lee, linux-bluetooth, linux-kernel, linux-mediatek

Hello:

This series was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Mon, 16 Sep 2024 19:39:34 +0800 you wrote:
> MediaTek performs some test on the platform which can support LE audio and
> ISO data transmission with kernel driver. We found the additional interface
> claim and release flow issue need some adjustment.
> 
> These patches mainly add a callback function within the usb_disconnect function
> to prevent a kernel panic caused by interfaces not being released when the BT USB
> dongle is physically removed. Additionally, the condition for claiming/releasing
> ISO usb interface have also been adjusted to make driver works as expected.
> 
> [...]

Here is the summary with links:
  - [1/4] Bluetooth: btusb: mediatek: move Bluetooth power off in btusb_mtk_shutdown
    https://git.kernel.org/bluetooth/bluetooth-next/c/65e9c1bf2076
  - [2/4] Bluetooth: btusb: add callback function in btusb_disconnect
    https://git.kernel.org/bluetooth/bluetooth-next/c/bcfc09e8a15d
  - [3/4] Bluetooth: btusb: mediatek: add intf release flow in usb disconnect
    (no matching commit)
  - [4/4] Bluetooth: btusb: mediatek: change the conditions for claiming/releasing ISO interface
    (no matching commit)

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-09-23 17:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-16 11:39 [PATCH 0/4] Bluetooth: btusb: Mediatek ISO interface cliam/release adjustment Chris Lu
2024-09-16 11:39 ` [PATCH 1/4] Bluetooth: btusb: mediatek: move Bluetooth power off in btusb_mtk_shutdown Chris Lu
2024-09-16 11:39 ` [PATCH 2/4] Bluetooth: btusb: add callback function in btusb_disconnect Chris Lu
2024-09-16 11:39 ` [PATCH 3/4] Bluetooth: btusb: mediatek: add intf release flow in usb disconnect Chris Lu
2024-09-16 11:39 ` [PATCH 4/4] Bluetooth: btusb: mediatek: change the conditions for claiming/releasing ISO interface Chris Lu
2024-09-23 17:00 ` [PATCH 0/4] Bluetooth: btusb: Mediatek ISO interface cliam/release adjustment patchwork-bot+bluetooth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).