linux-mediatek.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/4] Bluetooth: btusb: Mediatek ISO interface claim/release adjustment
@ 2024-09-23  8:47 Chris Lu
  2024-09-23  8:47 ` [PATCH v3 1/4] Bluetooth: btusb: mediatek: move Bluetooth power off command position Chris Lu
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Chris Lu @ 2024-09-23  8:47 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.

---
v2: fix commit message typo and over maximum chars per line warning.
v3: [patch 3/4] add new function btusb_mtk_disconnect for releasing MediaTek
                ISO interface
    [patch 4/4] remove redundant condition statements
---

Chris Lu (4):
  Bluetooth: btusb: mediatek: move Bluetooth power off command position
  Bluetooth: btusb: mediatek: add callback function in btusb_disconnect
  Bluetooth: btusb: mediatek: add intf release flow when usb disconnect
  Bluetooth: btusb: mediatek: change the conditions for ISO interface

 drivers/bluetooth/btusb.c | 41 +++++++++++++++++++++++++++------------
 1 file changed, 29 insertions(+), 12 deletions(-)

-- 
2.18.0



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

* [PATCH v3 1/4] Bluetooth: btusb: mediatek: move Bluetooth power off command position
  2024-09-23  8:47 [PATCH v3 0/4] Bluetooth: btusb: Mediatek ISO interface claim/release adjustment Chris Lu
@ 2024-09-23  8:47 ` Chris Lu
  2024-09-23  8:47 ` [PATCH v3 2/4] Bluetooth: btusb: mediatek: add callback function in btusb_disconnect Chris Lu
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Chris Lu @ 2024-09-23  8:47 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 v3 2/4] Bluetooth: btusb: mediatek: add callback function in btusb_disconnect
  2024-09-23  8:47 [PATCH v3 0/4] Bluetooth: btusb: Mediatek ISO interface claim/release adjustment Chris Lu
  2024-09-23  8:47 ` [PATCH v3 1/4] Bluetooth: btusb: mediatek: move Bluetooth power off command position Chris Lu
@ 2024-09-23  8:47 ` Chris Lu
  2024-09-23  8:47 ` [PATCH v3 3/4] Bluetooth: btusb: mediatek: add intf release flow when usb disconnect Chris Lu
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Chris Lu @ 2024-09-23  8:47 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 v3 3/4] Bluetooth: btusb: mediatek: add intf release flow when usb disconnect
  2024-09-23  8:47 [PATCH v3 0/4] Bluetooth: btusb: Mediatek ISO interface claim/release adjustment Chris Lu
  2024-09-23  8:47 ` [PATCH v3 1/4] Bluetooth: btusb: mediatek: move Bluetooth power off command position Chris Lu
  2024-09-23  8:47 ` [PATCH v3 2/4] Bluetooth: btusb: mediatek: add callback function in btusb_disconnect Chris Lu
@ 2024-09-23  8:47 ` Chris Lu
  2024-09-23  8:47 ` [PATCH v3 4/4] Bluetooth: btusb: mediatek: change the conditions for ISO interface Chris Lu
  2024-09-23 17:00 ` [PATCH v3 0/4] Bluetooth: btusb: Mediatek ISO interface claim/release adjustment patchwork-bot+bluetooth
  4 siblings, 0 replies; 6+ messages in thread
From: Chris Lu @ 2024-09-23  8:47 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 | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index dfc42bdc8aaf..a434aefe68f2 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 void 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);
@@ -2632,6 +2632,16 @@ static void btusb_mtk_release_iso_intf(struct btusb_data *data)
 	clear_bit(BTMTK_ISOPKT_OVER_INTR, &btmtk_data->flags);
 }
 
+static int btusb_mtk_disconnect(struct hci_dev *hdev)
+{
+	/* This function describes the specific additional steps taken by MediaTek
+	 * when Bluetooth usb driver's resume function is called.
+	 */
+	btusb_mtk_release_iso_intf(hdev);
+
+	return 0;
+}
+
 static int btusb_mtk_reset(struct hci_dev *hdev, void *rst_data)
 {
 	struct btusb_data *data = hci_get_drvdata(hdev);
@@ -2649,7 +2659,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 +2713,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 +3833,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_disconnect;
 	}
 
 	if (id->driver_info & BTUSB_SWAVE) {
-- 
2.18.0



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

* [PATCH v3 4/4] Bluetooth: btusb: mediatek: change the conditions for ISO interface
  2024-09-23  8:47 [PATCH v3 0/4] Bluetooth: btusb: Mediatek ISO interface claim/release adjustment Chris Lu
                   ` (2 preceding siblings ...)
  2024-09-23  8:47 ` [PATCH v3 3/4] Bluetooth: btusb: mediatek: add intf release flow when usb disconnect Chris Lu
@ 2024-09-23  8:47 ` Chris Lu
  2024-09-23 17:00 ` [PATCH v3 0/4] Bluetooth: btusb: Mediatek ISO interface claim/release adjustment patchwork-bot+bluetooth
  4 siblings, 0 replies; 6+ messages in thread
From: Chris Lu @ 2024-09-23  8:47 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 | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index a434aefe68f2..9affe4f81294 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -2618,7 +2618,7 @@ static void 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);
 
@@ -2658,8 +2658,8 @@ 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))
-		btusb_mtk_release_iso_intf(hdev);
+	/* Release MediaTek ISO data interface */
+	btusb_mtk_release_iso_intf(hdev);
 
 	btusb_stop_traffic(data);
 	usb_kill_anchored_urbs(&data->tx_anchor);
@@ -2704,22 +2704,22 @@ 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);
 }
 
 static int btusb_mtk_shutdown(struct hci_dev *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(hdev);
+	/* Release MediaTek iso interface after shutdown */
+	btusb_mtk_release_iso_intf(hdev);
 
 	return ret;
 }
-- 
2.18.0



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

* Re: [PATCH v3 0/4] Bluetooth: btusb: Mediatek ISO interface claim/release adjustment
  2024-09-23  8:47 [PATCH v3 0/4] Bluetooth: btusb: Mediatek ISO interface claim/release adjustment Chris Lu
                   ` (3 preceding siblings ...)
  2024-09-23  8:47 ` [PATCH v3 4/4] Bluetooth: btusb: mediatek: change the conditions for 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, 23 Sep 2024 16:47:01 +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:
  - [v3,1/4] Bluetooth: btusb: mediatek: move Bluetooth power off command position
    https://git.kernel.org/bluetooth/bluetooth-next/c/65e9c1bf2076
  - [v3,2/4] Bluetooth: btusb: mediatek: add callback function in btusb_disconnect
    https://git.kernel.org/bluetooth/bluetooth-next/c/bcfc09e8a15d
  - [v3,3/4] Bluetooth: btusb: mediatek: add intf release flow when usb disconnect
    https://git.kernel.org/bluetooth/bluetooth-next/c/6f3f7e941483
  - [v3,4/4] Bluetooth: btusb: mediatek: change the conditions for ISO interface
    https://git.kernel.org/bluetooth/bluetooth-next/c/667e8026261d

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-23  8:47 [PATCH v3 0/4] Bluetooth: btusb: Mediatek ISO interface claim/release adjustment Chris Lu
2024-09-23  8:47 ` [PATCH v3 1/4] Bluetooth: btusb: mediatek: move Bluetooth power off command position Chris Lu
2024-09-23  8:47 ` [PATCH v3 2/4] Bluetooth: btusb: mediatek: add callback function in btusb_disconnect Chris Lu
2024-09-23  8:47 ` [PATCH v3 3/4] Bluetooth: btusb: mediatek: add intf release flow when usb disconnect Chris Lu
2024-09-23  8:47 ` [PATCH v3 4/4] Bluetooth: btusb: mediatek: change the conditions for ISO interface Chris Lu
2024-09-23 17:00 ` [PATCH v3 0/4] Bluetooth: btusb: Mediatek ISO interface claim/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 NNTP newsgroup(s).