Skip to contentSkip to conversation

Bluetooth: btusb: Mediatek ISO interface cliam/release adjustment

PATCH Superseded Chris Lu 2 participants 6 messages Sep 16, 2024 – Sep 23, 2024

Subsystems (2)

v1 of 3 Superseded 2 of 4 applied Latest is v3 →

lore
Share & tools
lore

Chris Lu

author
#0 lore raw

cover Bluetooth: btusb: Mediatek ISO interface cliam/release adjustment

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(-)
Signature · 1 line
2.18.0
author
#1 lore raw

PATCH 1/4 Bluetooth: btusb: mediatek: move Bluetooth power off in btusb_mtk_shutdown

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

---
 drivers/bluetooth/btusb.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/bluetooth/btusb.c +4 -1
index 6c9c761d5b93..6cf1729a8225 100644
@@ -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
Signature · 1 line
2.18.0
author
#2 lore raw

PATCH 2/4 Bluetooth: btusb: add callback function in btusb_disconnect

In reply to Chris Lu

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

---
 drivers/bluetooth/btusb.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/bluetooth/btusb.c +4 -0
index 6cf1729a8225..dfc42bdc8aaf 100644
@@ -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) {
Signature · 1 line
2.18.0
author
#3 lore raw

PATCH 3/4 Bluetooth: btusb: mediatek: add intf release flow in usb disconnect

In reply to 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.

---
 drivers/bluetooth/btusb.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/bluetooth/btusb.c +7 -5
index dfc42bdc8aaf..37e67b451b34 100644
@@ -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) {
Signature · 1 line
2.18.0
author
#4 lore raw

PATCH 4/4 Bluetooth: btusb: mediatek: change the conditions for claiming/releasing ISO interface

In reply to Chris Lu

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

---
 drivers/bluetooth/btusb.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/bluetooth/btusb.c +6 -5
index 37e67b451b34..bb28a9b2dc11 100644
@@ -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;
Signature · 1 line
2.18.0
#5 lore raw
In reply to Chris Lu
This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 10 lines · 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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html