linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: btrtl: HCI reset on close for RTL8822BE
@ 2019-06-21  8:58 Jian-Hong Pan
  2019-06-24  4:53 ` Daniel Drake
  0 siblings, 1 reply; 8+ messages in thread
From: Jian-Hong Pan @ 2019-06-21  8:58 UTC (permalink / raw)
  To: Marcel Holtmann, Johan Hedberg, Daniel Drake
  Cc: linux-bluetooth, linux-kernel, Jian-Hong Pan

Realtek RTL8822BE BT chip on ASUS X420FA cannot be turned on correctly
after on-off several times.  Bluetooth daemon sets BT mode failed when
this issue happens.

bluetoothd[1576]: Failed to set mode: Failed (0x03)

If BT is tunred off, then turned on again, it works correctly again.
This patch makes RTL8822BE BT reset on close to fix this issue.

Signed-off-by: Jian-Hong Pan <jian-hong@endlessm.com>
---
 drivers/bluetooth/btrtl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/bluetooth/btrtl.c b/drivers/bluetooth/btrtl.c
index 208feef63de4..7e9930f0f231 100644
--- a/drivers/bluetooth/btrtl.c
+++ b/drivers/bluetooth/btrtl.c
@@ -608,10 +608,11 @@ int btrtl_download_firmware(struct hci_dev *hdev,
 	case RTL_ROM_LMP_8723A:
 	case RTL_ROM_LMP_3499:
 		return btrtl_setup_rtl8723a(hdev, btrtl_dev);
+	case RTL_ROM_LMP_8822B:
+		set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
 	case RTL_ROM_LMP_8723B:
 	case RTL_ROM_LMP_8821A:
 	case RTL_ROM_LMP_8761A:
-	case RTL_ROM_LMP_8822B:
 		return btrtl_setup_rtl8723b(hdev, btrtl_dev);
 	default:
 		rtl_dev_info(hdev, "rtl: assuming no firmware upload needed\n");
-- 
2.20.1


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

* Re: [PATCH] Bluetooth: btrtl: HCI reset on close for RTL8822BE
  2019-06-21  8:58 [PATCH] Bluetooth: btrtl: HCI reset on close for RTL8822BE Jian-Hong Pan
@ 2019-06-24  4:53 ` Daniel Drake
  2019-06-24  6:21   ` [PATCH v2] Bluetooth: btrtl: HCI reset on close for Realtek BT chip Jian-Hong Pan
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Drake @ 2019-06-24  4:53 UTC (permalink / raw)
  To: Jian-Hong Pan
  Cc: Marcel Holtmann, Johan Hedberg, Linux Bluetooth mailing list,
	Linux Kernel

Hi Jian-Hong,

On Fri, Jun 21, 2019 at 4:59 PM Jian-Hong Pan <jian-hong@endlessm.com> wrote:
> Realtek RTL8822BE BT chip on ASUS X420FA cannot be turned on correctly
> after on-off several times.  Bluetooth daemon sets BT mode failed when
> this issue happens.
>
> bluetoothd[1576]: Failed to set mode: Failed (0x03)
>
> If BT is tunred off, then turned on again, it works correctly again.
> This patch makes RTL8822BE BT reset on close to fix this issue.

I know we've been trying to understand why Realtek's own bluetooth
driver avoids this bug, but is this solution based upon code in the
vendor driver?
At a glance I can't see the flag (or equivalent) being set there.

Daniel

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

* [PATCH v2] Bluetooth: btrtl: HCI reset on close for Realtek BT chip
  2019-06-24  4:53 ` Daniel Drake
@ 2019-06-24  6:21   ` Jian-Hong Pan
  2019-06-25  5:10     ` Daniel Drake
  0 siblings, 1 reply; 8+ messages in thread
From: Jian-Hong Pan @ 2019-06-24  6:21 UTC (permalink / raw)
  To: Daniel Drake, Johan Hedberg, Marcel Holtmann
  Cc: linux-bluetooth, linux-kernel, Jian-Hong Pan

Realtek RTL8822BE BT chip on ASUS X420FA cannot be turned on correctly
after on-off several times. Bluetooth daemon sets BT mode failed when
this issue happens.

bluetoothd[1576]: Failed to set mode: Failed (0x03)

If BT is tunred off, then turned on again, it works correctly again.

According to the vendor driver, the HCI_QUIRK_RESET_ON_CLOSE flag is set
during probing. So, this patch makes Realtek's BT reset on close to fix
this issue.

Signed-off-by: Jian-Hong Pan <jian-hong@endlessm.com>
---
v2:
 - According to the vendor driver, it makes "all" Realtek's BT reset on
   close. So, this version makes it the same.
 - Change to the new subject for all Realtek BT chips.

 drivers/bluetooth/btrtl.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/bluetooth/btrtl.c b/drivers/bluetooth/btrtl.c
index 208feef63de4..be6d5f7e1e44 100644
--- a/drivers/bluetooth/btrtl.c
+++ b/drivers/bluetooth/btrtl.c
@@ -630,6 +630,10 @@ int btrtl_setup_realtek(struct hci_dev *hdev)
 		return PTR_ERR(btrtl_dev);
 
 	ret = btrtl_download_firmware(hdev, btrtl_dev);
+	/* According to the vendor driver, BT must be reset on close to avoid
+	 * firmware crash since kernel v3.7.1.
+	 */
+	set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
 
 	btrtl_free(btrtl_dev);
 
-- 
2.22.0


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

* Re: [PATCH v2] Bluetooth: btrtl: HCI reset on close for Realtek BT chip
  2019-06-24  6:21   ` [PATCH v2] Bluetooth: btrtl: HCI reset on close for Realtek BT chip Jian-Hong Pan
@ 2019-06-25  5:10     ` Daniel Drake
  2019-06-25  5:43       ` Marcel Holtmann
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Drake @ 2019-06-25  5:10 UTC (permalink / raw)
  To: Jian-Hong Pan
  Cc: Johan Hedberg, Marcel Holtmann, Linux Bluetooth mailing list,
	Linux Kernel

On Mon, Jun 24, 2019 at 2:24 PM Jian-Hong Pan <jian-hong@endlessm.com> wrote:
> Realtek RTL8822BE BT chip on ASUS X420FA cannot be turned on correctly
> after on-off several times. Bluetooth daemon sets BT mode failed when
> this issue happens.

You could also mention that scanning must be active while turning off
for this bug to be hit.

> bluetoothd[1576]: Failed to set mode: Failed (0x03)
>
> If BT is tunred off, then turned on again, it works correctly again.

Typo: turned

> According to the vendor driver, the HCI_QUIRK_RESET_ON_CLOSE flag is set
> during probing. So, this patch makes Realtek's BT reset on close to fix
> this issue.

Checked the vendor driver - I see what you are referring to, so the
change seems correct.

#if HCI_VERSION_CODE >= KERNEL_VERSION(3, 7, 1)
    if (!reset)
        set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
    RTKBT_DBG("set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);");
#endif

However I'm pretty sure this is not saying that kernel 3.7.0 did not
need the reset. I think it just means that the flag did not exist
before Linux-3.7.1, so they added the ifdef to add some level of
compatibility with older kernel versions. I think you can remove
"since kernel v3.7.1." from the comment.

After those changes you can add:

Link: https://bugzilla.kernel.org/show_bug.cgi?id=203429
Reviewed-by: Daniel Drake <drake@endlessm.com>


> Signed-off-by: Jian-Hong Pan <jian-hong@endlessm.com>
> ---
> v2:
>  - According to the vendor driver, it makes "all" Realtek's BT reset on
>    close. So, this version makes it the same.
>  - Change to the new subject for all Realtek BT chips.
>
>  drivers/bluetooth/btrtl.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/bluetooth/btrtl.c b/drivers/bluetooth/btrtl.c
> index 208feef63de4..be6d5f7e1e44 100644
> --- a/drivers/bluetooth/btrtl.c
> +++ b/drivers/bluetooth/btrtl.c
> @@ -630,6 +630,10 @@ int btrtl_setup_realtek(struct hci_dev *hdev)
>                 return PTR_ERR(btrtl_dev);
>
>         ret = btrtl_download_firmware(hdev, btrtl_dev);
> +       /* According to the vendor driver, BT must be reset on close to avoid
> +        * firmware crash since kernel v3.7.1.
> +        */
> +       set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
>
>         btrtl_free(btrtl_dev);
>
> --
> 2.22.0
>

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

* Re: [PATCH v2] Bluetooth: btrtl: HCI reset on close for Realtek BT chip
  2019-06-25  5:10     ` Daniel Drake
@ 2019-06-25  5:43       ` Marcel Holtmann
  2019-06-25  8:30         ` [PATCH v3] " Jian-Hong Pan
  0 siblings, 1 reply; 8+ messages in thread
From: Marcel Holtmann @ 2019-06-25  5:43 UTC (permalink / raw)
  To: Daniel Drake
  Cc: Jian-Hong Pan, Johan Hedberg, Linux Bluetooth mailing list, Linux Kernel

Hi Daniel,

>> Realtek RTL8822BE BT chip on ASUS X420FA cannot be turned on correctly
>> after on-off several times. Bluetooth daemon sets BT mode failed when
>> this issue happens.
> 
> You could also mention that scanning must be active while turning off
> for this bug to be hit.
> 
>> bluetoothd[1576]: Failed to set mode: Failed (0x03)
>> 
>> If BT is tunred off, then turned on again, it works correctly again.
> 
> Typo: turned
> 
>> According to the vendor driver, the HCI_QUIRK_RESET_ON_CLOSE flag is set
>> during probing. So, this patch makes Realtek's BT reset on close to fix
>> this issue.
> 
> Checked the vendor driver - I see what you are referring to, so the
> change seems correct.
> 
> #if HCI_VERSION_CODE >= KERNEL_VERSION(3, 7, 1)
>    if (!reset)
>        set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
>    RTKBT_DBG("set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);");
> #endif
> 
> However I'm pretty sure this is not saying that kernel 3.7.0 did not
> need the reset. I think it just means that the flag did not exist
> before Linux-3.7.1, so they added the ifdef to add some level of
> compatibility with older kernel versions. I think you can remove
> "since kernel v3.7.1." from the comment.
> 
> After those changes you can add:
> 
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=203429
> Reviewed-by: Daniel Drake <drake@endlessm.com>

if someone wants to use HCI_Reset to ensure that all their connections and radio usage is reset, then they should do that via the hdev->shutdown handler. Look at btusb.c if you need an example.

This quirk is for hardware that can not use HCI_Reset on init which is Bluetooth 1.0b hardware.

Regards

Marcel


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

* [PATCH v3] Bluetooth: btrtl: HCI reset on close for Realtek BT chip
  2019-06-25  5:43       ` Marcel Holtmann
@ 2019-06-25  8:30         ` Jian-Hong Pan
  2019-07-01  7:45           ` Daniel Drake
  2019-07-06 10:51           ` Marcel Holtmann
  0 siblings, 2 replies; 8+ messages in thread
From: Jian-Hong Pan @ 2019-06-25  8:30 UTC (permalink / raw)
  To: Daniel Drake, Johan Hedberg, Marcel Holtmann
  Cc: linux-bluetooth, linux-kernel, Jian-Hong Pan

Realtek RTL8822BE BT chip on ASUS X420FA cannot be turned on correctly
after on-off several times. Bluetooth daemon sets BT mode failed when
this issue happens. Scanning must be active while turning off for this
bug to be hit.

bluetoothd[1576]: Failed to set mode: Failed (0x03)

If BT is turned off, then turned on again, it works correctly again.

According to the vendor driver, the HCI_QUIRK_RESET_ON_CLOSE flag is set
during probing. So, this patch makes Realtek's BT reset on close to fix
this issue.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=203429
Signed-off-by: Jian-Hong Pan <jian-hong@endlessm.com>
---
v2:
 - According to the vendor driver, it makes "all" Realtek's BT reset on
   close. So, this version makes it the same.
 - Change to the new subject for all Realtek BT chips.

v3:
 - Fix the commit message and add the bug link.
 - Have btrtl_shutdown_realtek() which sends HCI reset command and as
   the callback function of hdev->shutdown for Realtek BT instead of
   setting HCI_QUIRK_RESET_ON_CLOSE flag.

 drivers/bluetooth/btrtl.c | 20 ++++++++++++++++++++
 drivers/bluetooth/btrtl.h |  6 ++++++
 drivers/bluetooth/btusb.c |  1 +
 3 files changed, 27 insertions(+)

diff --git a/drivers/bluetooth/btrtl.c b/drivers/bluetooth/btrtl.c
index 208feef63de4..d04b443cad1f 100644
--- a/drivers/bluetooth/btrtl.c
+++ b/drivers/bluetooth/btrtl.c
@@ -637,6 +637,26 @@ int btrtl_setup_realtek(struct hci_dev *hdev)
 }
 EXPORT_SYMBOL_GPL(btrtl_setup_realtek);
 
+int btrtl_shutdown_realtek(struct hci_dev *hdev)
+{
+	struct sk_buff *skb;
+	int ret;
+
+	/* According to the vendor driver, BT must be reset on close to avoid
+	 * firmware crash.
+	 */
+	skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
+	if (IS_ERR(skb)) {
+		ret = PTR_ERR(skb);
+		bt_dev_err(hdev, "HCI reset during shutdown failed");
+		return ret;
+	}
+	kfree_skb(skb);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(btrtl_shutdown_realtek);
+
 static unsigned int btrtl_convert_baudrate(u32 device_baudrate)
 {
 	switch (device_baudrate) {
diff --git a/drivers/bluetooth/btrtl.h b/drivers/bluetooth/btrtl.h
index f1676144fce8..10ad40c3e42c 100644
--- a/drivers/bluetooth/btrtl.h
+++ b/drivers/bluetooth/btrtl.h
@@ -55,6 +55,7 @@ void btrtl_free(struct btrtl_device_info *btrtl_dev);
 int btrtl_download_firmware(struct hci_dev *hdev,
 			    struct btrtl_device_info *btrtl_dev);
 int btrtl_setup_realtek(struct hci_dev *hdev);
+int btrtl_shutdown_realtek(struct hci_dev *hdev);
 int btrtl_get_uart_settings(struct hci_dev *hdev,
 			    struct btrtl_device_info *btrtl_dev,
 			    unsigned int *controller_baudrate,
@@ -83,6 +84,11 @@ static inline int btrtl_setup_realtek(struct hci_dev *hdev)
 	return -EOPNOTSUPP;
 }
 
+static inline int btrtl_shutdown_realtek(struct hci_dev *hdev)
+{
+	return -EOPNOTSUPP;
+}
+
 static inline int btrtl_get_uart_settings(struct hci_dev *hdev,
 					  struct btrtl_device_info *btrtl_dev,
 					  unsigned int *controller_baudrate,
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 50aed5259c2b..342e1de6bcba 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -3184,6 +3184,7 @@ static int btusb_probe(struct usb_interface *intf,
 #ifdef CONFIG_BT_HCIBTUSB_RTL
 	if (id->driver_info & BTUSB_REALTEK) {
 		hdev->setup = btrtl_setup_realtek;
+		hdev->shutdown = btrtl_shutdown_realtek;
 
 		/* Realtek devices lose their updated firmware over suspend,
 		 * but the USB hub doesn't notice any status change.
-- 
2.22.0


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

* Re: [PATCH v3] Bluetooth: btrtl: HCI reset on close for Realtek BT chip
  2019-06-25  8:30         ` [PATCH v3] " Jian-Hong Pan
@ 2019-07-01  7:45           ` Daniel Drake
  2019-07-06 10:51           ` Marcel Holtmann
  1 sibling, 0 replies; 8+ messages in thread
From: Daniel Drake @ 2019-07-01  7:45 UTC (permalink / raw)
  To: Jian-Hong Pan
  Cc: Johan Hedberg, Marcel Holtmann, Linux Bluetooth mailing list,
	Linux Kernel

On Tue, Jun 25, 2019 at 4:32 PM Jian-Hong Pan <jian-hong@endlessm.com> wrote:
> Realtek RTL8822BE BT chip on ASUS X420FA cannot be turned on correctly
> after on-off several times. Bluetooth daemon sets BT mode failed when
> this issue happens. Scanning must be active while turning off for this
> bug to be hit.
>
> bluetoothd[1576]: Failed to set mode: Failed (0x03)
>
> If BT is turned off, then turned on again, it works correctly again.
>
> According to the vendor driver, the HCI_QUIRK_RESET_ON_CLOSE flag is set
> during probing. So, this patch makes Realtek's BT reset on close to fix
> this issue.
>
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=203429
> Signed-off-by: Jian-Hong Pan <jian-hong@endlessm.com>

Reviewed-by: Daniel Drake <drake@endlessm.com>

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

* Re: [PATCH v3] Bluetooth: btrtl: HCI reset on close for Realtek BT chip
  2019-06-25  8:30         ` [PATCH v3] " Jian-Hong Pan
  2019-07-01  7:45           ` Daniel Drake
@ 2019-07-06 10:51           ` Marcel Holtmann
  1 sibling, 0 replies; 8+ messages in thread
From: Marcel Holtmann @ 2019-07-06 10:51 UTC (permalink / raw)
  To: Jian-Hong Pan; +Cc: Daniel Drake, Johan Hedberg, linux-bluetooth, linux-kernel

Hi Jian-Hong,

> Realtek RTL8822BE BT chip on ASUS X420FA cannot be turned on correctly
> after on-off several times. Bluetooth daemon sets BT mode failed when
> this issue happens. Scanning must be active while turning off for this
> bug to be hit.
> 
> bluetoothd[1576]: Failed to set mode: Failed (0x03)
> 
> If BT is turned off, then turned on again, it works correctly again.
> 
> According to the vendor driver, the HCI_QUIRK_RESET_ON_CLOSE flag is set
> during probing. So, this patch makes Realtek's BT reset on close to fix
> this issue.
> 
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=203429
> Signed-off-by: Jian-Hong Pan <jian-hong@endlessm.com>
> ---
> v2:
> - According to the vendor driver, it makes "all" Realtek's BT reset on
>   close. So, this version makes it the same.
> - Change to the new subject for all Realtek BT chips.
> 
> v3:
> - Fix the commit message and add the bug link.
> - Have btrtl_shutdown_realtek() which sends HCI reset command and as
>   the callback function of hdev->shutdown for Realtek BT instead of
>   setting HCI_QUIRK_RESET_ON_CLOSE flag.
> 
> drivers/bluetooth/btrtl.c | 20 ++++++++++++++++++++
> drivers/bluetooth/btrtl.h |  6 ++++++
> drivers/bluetooth/btusb.c |  1 +
> 3 files changed, 27 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel


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

end of thread, other threads:[~2019-07-06 10:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-21  8:58 [PATCH] Bluetooth: btrtl: HCI reset on close for RTL8822BE Jian-Hong Pan
2019-06-24  4:53 ` Daniel Drake
2019-06-24  6:21   ` [PATCH v2] Bluetooth: btrtl: HCI reset on close for Realtek BT chip Jian-Hong Pan
2019-06-25  5:10     ` Daniel Drake
2019-06-25  5:43       ` Marcel Holtmann
2019-06-25  8:30         ` [PATCH v3] " Jian-Hong Pan
2019-07-01  7:45           ` Daniel Drake
2019-07-06 10:51           ` Marcel Holtmann

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).