* [PATCH v2] Bluetooth: btrtl: Ask 8821C to drop old firmware
@ 2020-10-26 8:28 Kai-Heng Feng
2020-11-02 13:32 ` Kai-Heng Feng
2020-11-09 12:39 ` Marcel Holtmann
0 siblings, 2 replies; 4+ messages in thread
From: Kai-Heng Feng @ 2020-10-26 8:28 UTC (permalink / raw)
To: marcel, johan.hedberg
Cc: max.chou, alex_lu, Kai-Heng Feng, open list:BLUETOOTH DRIVERS, open list
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 <max.chou@realtek.com>
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
v2:
- Fix incorrect parAnthesis on le16_to_cpu.
- Ensure firmware gets re-uploaded in initialization.
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.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] Bluetooth: btrtl: Ask 8821C to drop old firmware
2020-10-26 8:28 [PATCH v2] Bluetooth: btrtl: Ask 8821C to drop old firmware Kai-Heng Feng
@ 2020-11-02 13:32 ` Kai-Heng Feng
2020-11-03 2:30 ` Max Chou
2020-11-09 12:39 ` Marcel Holtmann
1 sibling, 1 reply; 4+ messages in thread
From: Kai-Heng Feng @ 2020-11-02 13:32 UTC (permalink / raw)
To: Max Chou, alex_lu
Cc: Marcel Holtmann, Johan Hedberg, open list:BLUETOOTH DRIVERS, open list
> On Oct 26, 2020, at 16:28, Kai-Heng Feng <kai.heng.feng@canonical.com> wrote:
>
> 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 <max.chou@realtek.com>
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Max and Alex,
Can you please ack or review the patch?
Kai-Heng
> ---
> v2:
> - Fix incorrect parAnthesis on le16_to_cpu.
> - Ensure firmware gets re-uploaded in initialization.
>
> 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.17.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH v2] Bluetooth: btrtl: Ask 8821C to drop old firmware
2020-11-02 13:32 ` Kai-Heng Feng
@ 2020-11-03 2:30 ` Max Chou
0 siblings, 0 replies; 4+ messages in thread
From: Max Chou @ 2020-11-03 2:30 UTC (permalink / raw)
To: Kai-Heng Feng, alex_lu
Cc: Marcel Holtmann, Johan Hedberg, open list:BLUETOOTH DRIVERS, open list
Dear guys,
I agree this patch.
BRs,
Max
-----Original Message-----
From: Kai-Heng Feng <kai.heng.feng@canonical.com>
Sent: Monday, November 2, 2020 9:33 PM
To: Max Chou <max.chou@realtek.com>; alex_lu <alex_lu@realsil.com.cn>
Cc: Marcel Holtmann <marcel@holtmann.org>; Johan Hedberg <johan.hedberg@gmail.com>; open list:BLUETOOTH DRIVERS <linux-bluetooth@vger.kernel.org>; open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] Bluetooth: btrtl: Ask 8821C to drop old firmware
> On Oct 26, 2020, at 16:28, Kai-Heng Feng <kai.heng.feng@canonical.com> wrote:
>
> 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 <max.chou@realtek.com>
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Max and Alex,
Can you please ack or review the patch?
Kai-Heng
> ---
> v2:
> - Fix incorrect parAnthesis on le16_to_cpu.
> - Ensure firmware gets re-uploaded in initialization.
>
> 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.17.1
>
------Please consider the environment before printing this e-mail.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] Bluetooth: btrtl: Ask 8821C to drop old firmware
2020-10-26 8:28 [PATCH v2] Bluetooth: btrtl: Ask 8821C to drop old firmware Kai-Heng Feng
2020-11-02 13:32 ` Kai-Heng Feng
@ 2020-11-09 12:39 ` Marcel Holtmann
1 sibling, 0 replies; 4+ messages in thread
From: Marcel Holtmann @ 2020-11-09 12:39 UTC (permalink / raw)
To: Kai-Heng Feng
Cc: Johan Hedberg, max.chou, alex_lu, open list:BLUETOOTH DRIVERS, open list
Hi Kai-Heng,
> 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 <max.chou@realtek.com>
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> ---
> v2:
> - Fix incorrect parAnthesis on le16_to_cpu.
> - Ensure firmware gets re-uploaded in initialization.
>
> drivers/bluetooth/btrtl.c | 46 +++++++++++++++++++++++++++++++++++++++
> 1 file changed, 46 insertions(+)
patch has been applied to bluetooth-next tree.
Regards
Marcel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-11-09 12:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-26 8:28 [PATCH v2] Bluetooth: btrtl: Ask 8821C to drop old firmware Kai-Heng Feng
2020-11-02 13:32 ` Kai-Heng Feng
2020-11-03 2:30 ` Max Chou
2020-11-09 12:39 ` Marcel Holtmann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.