[SRU] [F/G/Unstable/OEM-5.6] [PATCH 0/2] Ask 8821C Bluetooth controller to drop old firmware

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[SRU] [F/G/Unstable/OEM-5.6] [PATCH 0/2] Ask 8821C Bluetooth controller to drop old firmware

Kai-Heng Feng
BugLink: https://bugs.launchpad.net/bugs/1904221

[Impact]
Some platforms may keep USB power in S3/S4/S5, so Realtek 8821C retains
its firmware even with a cold boot.

[Fix]
Use vendor command to drop firmware if the version is old.

[Test case]
Use dmesg to check if new firmware is loaded.
With the patch applied, we can find new firmware is loaded.

[Where problems could occur]
There's a 200ms delay which can slow down when BT controller is opened
by userspace first time.

Colin Ian King (1):
  Bluetooth: btrtl: fix incorrect skb allocation failure check

Kai-Heng Feng (1):
  Bluetooth: btrtl: Ask 8821C to drop old firmware

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

--
2.28.0


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

[PATCH 1/2] Bluetooth: btrtl: Ask 8821C to drop old firmware

Kai-Heng Feng
BugLink: https://bugs.launchpad.net/bugs/1904221

Some platforms keep USB power even when they are powered off and in S5,
this makes Realtek 8821C keep its firmware even after a cold boot, and
make 8821C never load new firmware.

So use vendor specific HCI command to ask 8821C drop its firmware after
system shutdown.

Newer firmware doesn't have this issue so we only use this trick for old
8821C firmware version.

Suggested-by: Max Chou <[hidden email]>
Signed-off-by: Kai-Heng Feng <[hidden email]>
Signed-off-by: Marcel Holtmann <[hidden email]>
(cherry picked from commit 1996d9cad6ad4882a79464e9fb941a68c693f8fc linux-next)
Signed-off-by: Kai-Heng Feng <[hidden email]>
---
 drivers/bluetooth/btrtl.c | 46 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/drivers/bluetooth/btrtl.c b/drivers/bluetooth/btrtl.c
index 3a9afc905f24..37e24bbb2eb4 100644
--- a/drivers/bluetooth/btrtl.c
+++ b/drivers/bluetooth/btrtl.c
@@ -55,6 +55,7 @@ struct btrtl_device_info {
  int fw_len;
  u8 *cfg_data;
  int cfg_len;
+ bool drop_fw;
 };
 
 static const struct id_table ic_id_table[] = {
@@ -563,6 +564,8 @@ struct btrtl_device_info *btrtl_initialize(struct hci_dev *hdev,
  u16 hci_rev, lmp_subver;
  u8 hci_ver;
  int ret;
+ u16 opcode;
+ u8 cmd[2];
 
  btrtl_dev = kzalloc(sizeof(*btrtl_dev), GFP_KERNEL);
  if (!btrtl_dev) {
@@ -584,6 +587,49 @@ struct btrtl_device_info *btrtl_initialize(struct hci_dev *hdev,
  hci_ver = resp->hci_ver;
  hci_rev = le16_to_cpu(resp->hci_rev);
  lmp_subver = le16_to_cpu(resp->lmp_subver);
+
+ if (resp->hci_ver == 0x8 && le16_to_cpu(resp->hci_rev) == 0x826c &&
+    resp->lmp_ver == 0x8 && le16_to_cpu(resp->lmp_subver) == 0xa99e)
+ btrtl_dev->drop_fw = true;
+
+ if (btrtl_dev->drop_fw) {
+ opcode = hci_opcode_pack(0x3f, 0x66);
+ cmd[0] = opcode & 0xff;
+ cmd[1] = opcode >> 8;
+
+ skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
+ if (IS_ERR(skb))
+ goto out_free;
+
+ skb_put_data(skb, cmd, sizeof(cmd));
+ hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
+
+ hdev->send(hdev, skb);
+
+ /* Ensure the above vendor command is sent to controller and
+ * process has done.
+ */
+ msleep(200);
+
+ /* Read the local version again. Expect to have the vanilla
+ * version as cold boot.
+ */
+ skb = btrtl_read_local_version(hdev);
+ if (IS_ERR(skb)) {
+ ret = PTR_ERR(skb);
+ goto err_free;
+ }
+
+ resp = (struct hci_rp_read_local_version *)skb->data;
+ rtl_dev_info(hdev, "examining hci_ver=%02x hci_rev=%04x lmp_ver=%02x lmp_subver=%04x",
+     resp->hci_ver, resp->hci_rev,
+     resp->lmp_ver, resp->lmp_subver);
+
+ hci_ver = resp->hci_ver;
+ hci_rev = le16_to_cpu(resp->hci_rev);
+ lmp_subver = le16_to_cpu(resp->lmp_subver);
+ }
+out_free:
  kfree_skb(skb);
 
  btrtl_dev->ic_info = btrtl_match_ic(lmp_subver, hci_rev, hci_ver,
--
2.28.0


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

[PATCH 2/2] Bluetooth: btrtl: fix incorrect skb allocation failure check

Kai-Heng Feng
In reply to this post by Kai-Heng Feng
From: Colin Ian King <[hidden email]>

BugLink: https://bugs.launchpad.net/bugs/1904221

Currently the check for a failed bt_skb_alloc allocation is incorrectly
checking using IS_ERR and this can lead to a null pointer dereference. Fix
this by checking for a null pointer return using the !skb idiom.

Addresses-Coverity: ("Dereference null return")
Fixes: 1996d9cad6ad ("Bluetooth: btrtl: Ask 8821C to drop old firmware")
Signed-off-by: Colin Ian King <[hidden email]>
Signed-off-by: Marcel Holtmann <[hidden email]>
(cherry picked from commit f5e8e215869eed6163d5fdd309f0e674a0f23df6 linux-next)
Signed-off-by: Kai-Heng Feng <[hidden email]>
---
 drivers/bluetooth/btrtl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/bluetooth/btrtl.c b/drivers/bluetooth/btrtl.c
index 37e24bbb2eb4..35fb96dae337 100644
--- a/drivers/bluetooth/btrtl.c
+++ b/drivers/bluetooth/btrtl.c
@@ -598,7 +598,7 @@ struct btrtl_device_info *btrtl_initialize(struct hci_dev *hdev,
  cmd[1] = opcode >> 8;
 
  skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
- if (IS_ERR(skb))
+ if (!skb)
  goto out_free;
 
  skb_put_data(skb, cmd, sizeof(cmd));
--
2.28.0


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

ACK: [SRU] [F/G/Unstable/OEM-5.6] [PATCH 0/2] Ask 8821C Bluetooth controller to drop old firmware

Stefan Bader-2
In reply to this post by Kai-Heng Feng
On 13.11.20 17:15, Kai-Heng Feng wrote:

> BugLink: https://bugs.launchpad.net/bugs/1904221
>
> [Impact]
> Some platforms may keep USB power in S3/S4/S5, so Realtek 8821C retains
> its firmware even with a cold boot.
>
> [Fix]
> Use vendor command to drop firmware if the version is old.
>
> [Test case]
> Use dmesg to check if new firmware is loaded.
> With the patch applied, we can find new firmware is loaded.
>
> [Where problems could occur]
> There's a 200ms delay which can slow down when BT controller is opened
> by userspace first time.
>
> Colin Ian King (1):
>   Bluetooth: btrtl: fix incorrect skb allocation failure check
>
> Kai-Heng Feng (1):
>   Bluetooth: btrtl: Ask 8821C to drop old firmware
>
>  drivers/bluetooth/btrtl.c | 46 +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
>
The change to drop firmware appears a bit large but limited in scope and I
believe also in the range of hw which triggers a different behaviour. So with
testing results.


Acked-by: Stefan Bader <[hidden email]>


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

ACK: [SRU] [F/G/Unstable/OEM-5.6] [PATCH 0/2] Ask 8821C Bluetooth controller to drop old firmware

Kleber Souza
In reply to this post by Kai-Heng Feng
On 13.11.20 17:15, Kai-Heng Feng wrote:

> BugLink: https://bugs.launchpad.net/bugs/1904221
>
> [Impact]
> Some platforms may keep USB power in S3/S4/S5, so Realtek 8821C retains
> its firmware even with a cold boot.
>
> [Fix]
> Use vendor command to drop firmware if the version is old.
>
> [Test case]
> Use dmesg to check if new firmware is loaded.
> With the patch applied, we can find new firmware is loaded.
>
> [Where problems could occur]
> There's a 200ms delay which can slow down when BT controller is opened
> by userspace first time.
>
> Colin Ian King (1):
>    Bluetooth: btrtl: fix incorrect skb allocation failure check
>
> Kai-Heng Feng (1):
>    Bluetooth: btrtl: Ask 8821C to drop old firmware
>
>   drivers/bluetooth/btrtl.c | 46 +++++++++++++++++++++++++++++++++++++++
>   1 file changed, 46 insertions(+)
>


Acked-by: Kleber Sacilotto de Souza <[hidden email]>

--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

APPLIED: [SRU] [F/G] [PATCH 0/2] Ask 8821C Bluetooth controller to drop old firmware

William Breathitt Gray
In reply to this post by Kai-Heng Feng
On Sat, Nov 14, 2020 at 12:15:50AM +0800, Kai-Heng Feng wrote:

> BugLink: https://bugs.launchpad.net/bugs/1904221
>
> [Impact]
> Some platforms may keep USB power in S3/S4/S5, so Realtek 8821C retains
> its firmware even with a cold boot.
>
> [Fix]
> Use vendor command to drop firmware if the version is old.
>
> [Test case]
> Use dmesg to check if new firmware is loaded.
> With the patch applied, we can find new firmware is loaded.
>
> [Where problems could occur]
> There's a 200ms delay which can slow down when BT controller is opened
> by userspace first time.
>
> Colin Ian King (1):
>   Bluetooth: btrtl: fix incorrect skb allocation failure check
>
> Kai-Heng Feng (1):
>   Bluetooth: btrtl: Ask 8821C to drop old firmware
>
>  drivers/bluetooth/btrtl.c | 46 +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
>
> --
> 2.28.0
Applied to Focal:linux and Groovy:linux.

William Breathitt Gray

--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team

signature.asc (849 bytes) Download Attachment