Bluetooth: btusb: Mediatek ISO interface claim/release adjustment
Subsystems (2)
v3 cover Bluetooth: btusb: Mediatek ISO interface claim/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.
---
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(-)
Signature · 1 line
2.18.0
PATCH v3 1/4 Bluetooth: btusb: mediatek: move Bluetooth power off command position
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
@@ -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
PATCH v3 2/4 Bluetooth: btusb: mediatek: add callback function in btusb_disconnect
In reply to Chris LuAdd 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
@@ -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
PATCH v3 3/4 Bluetooth: btusb: mediatek: add intf release flow when usb disconnect
In reply to Chris LuMediaTek 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 | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
drivers/bluetooth/btusb.c +15 -5
@@ -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 ) {
Signature · 1 line
2.18.0
PATCH v3 4/4 Bluetooth: btusb: mediatek: change the conditions for ISO interface
In reply to Chris LuChange conditions for Bluetooth driver claiming and releasing usb ISO interface for MediaTek ISO data transmission.
--- drivers/bluetooth/btusb.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/bluetooth/btusb.c +8 -8
@@ -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; }
Signature · 1 line
2.18.0
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 11 lines · 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_disconnectfunction 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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html