From: Alex Lu <alex_lu@realsil.com.cn>
To: Marcel Holtmann <marcel@holtmann.org>
Cc: Johan Hedberg <johan.hedberg@gmail.com>,
<linux-bluetooth@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Max Chou <max.chou@realtek.com>
Subject: [PATCH] Bluetooth: btrtl: Save firmware and config
Date: Fri, 2 Aug 2019 20:10:29 +0800 [thread overview]
Message-ID: <20190802121029.GA8795@toshiba> (raw)
From: Alex Lu <alex_lu@realsil.com.cn>
usb reset resume will cause downloading firmware again and
requesting firmware may be failed while host is resuming
Signed-off-by: Alex Lu <alex_lu@realsil.com.cn>
---
drivers/bluetooth/btrtl.c | 77 +++++++++++++++++++++++++++++++++++++--
1 file changed, 73 insertions(+), 4 deletions(-)
diff --git a/drivers/bluetooth/btrtl.c b/drivers/bluetooth/btrtl.c
index 208feef63de4..69f0c2765443 100644
--- a/drivers/bluetooth/btrtl.c
+++ b/drivers/bluetooth/btrtl.c
@@ -56,6 +56,10 @@ struct btrtl_device_info {
int cfg_len;
};
+static struct btrtl_device_info dev_info = {
+ NULL, 0, NULL, 0, NULL, 0
+};
+
static const struct id_table ic_id_table[] = {
{ IC_MATCH_FL_LMPSUBV, RTL_ROM_LMP_8723A, 0x0,
.config_needed = false,
@@ -553,8 +557,19 @@ struct btrtl_device_info *btrtl_initialize(struct hci_dev *hdev,
goto err_free;
}
- btrtl_dev->fw_len = rtl_load_file(hdev, btrtl_dev->ic_info->fw_name,
- &btrtl_dev->fw_data);
+ if (dev_info.ic_info == NULL ||
+ dev_info.ic_info != btrtl_dev->ic_info) {
+ btrtl_dev->fw_len = rtl_load_file(hdev,
+ btrtl_dev->ic_info->fw_name,
+ &btrtl_dev->fw_data);
+ } else {
+ if (dev_info.fw_len)
+ btrtl_dev->fw_data = kmemdup(dev_info.fw_data,
+ dev_info.fw_len,
+ GFP_KERNEL);
+ if (btrtl_dev->fw_data)
+ btrtl_dev->fw_len = dev_info.fw_len;
+ }
if (btrtl_dev->fw_len < 0) {
rtl_dev_err(hdev, "firmware file %s not found\n",
btrtl_dev->ic_info->fw_name);
@@ -570,8 +585,18 @@ struct btrtl_device_info *btrtl_initialize(struct hci_dev *hdev,
snprintf(cfg_name, sizeof(cfg_name), "%s.bin",
btrtl_dev->ic_info->cfg_name);
}
- btrtl_dev->cfg_len = rtl_load_file(hdev, cfg_name,
- &btrtl_dev->cfg_data);
+ if (dev_info.ic_info == NULL ||
+ dev_info.ic_info != btrtl_dev->ic_info) {
+ btrtl_dev->cfg_len = rtl_load_file(hdev, cfg_name,
+ &btrtl_dev->cfg_data);
+ } else {
+ if (dev_info.cfg_len)
+ btrtl_dev->cfg_data = kmemdup(dev_info.cfg_data,
+ dev_info.cfg_len,
+ GFP_KERNEL);
+ if (btrtl_dev->cfg_data)
+ btrtl_dev->cfg_len = dev_info.cfg_len;
+ }
if (btrtl_dev->ic_info->config_needed &&
btrtl_dev->cfg_len <= 0) {
rtl_dev_err(hdev, "mandatory config file %s not found\n",
@@ -620,6 +645,29 @@ int btrtl_download_firmware(struct hci_dev *hdev,
}
EXPORT_SYMBOL_GPL(btrtl_download_firmware);
+static void dev_fw_free(void)
+{
+ kfree(dev_info.fw_data);
+ kfree(dev_info.cfg_data);
+ memset(&dev_info, 0, sizeof(dev_info));
+}
+
+static void dev_fw_dup(struct btrtl_device_info *btrtl_dev)
+{
+ dev_info.ic_info = btrtl_dev->ic_info;
+ dev_info.rom_version = btrtl_dev->rom_version;
+
+ dev_info.fw_len = btrtl_dev->fw_len;
+ if (dev_info.fw_len)
+ dev_info.fw_data = kmemdup(btrtl_dev->fw_data,
+ btrtl_dev->fw_len,
+ GFP_KERNEL);
+ dev_info.cfg_len = btrtl_dev->cfg_len;
+ if (dev_info.cfg_len)
+ dev_info.cfg_data = kmemdup(btrtl_dev->cfg_data,
+ btrtl_dev->cfg_len, GFP_KERNEL);
+}
+
int btrtl_setup_realtek(struct hci_dev *hdev)
{
struct btrtl_device_info *btrtl_dev;
@@ -630,6 +678,10 @@ int btrtl_setup_realtek(struct hci_dev *hdev)
return PTR_ERR(btrtl_dev);
ret = btrtl_download_firmware(hdev, btrtl_dev);
+ if (!ret && btrtl_dev->ic_info != dev_info.ic_info) {
+ dev_fw_free();
+ dev_fw_dup(btrtl_dev);
+ }
btrtl_free(btrtl_dev);
@@ -745,6 +797,23 @@ int btrtl_get_uart_settings(struct hci_dev *hdev,
}
EXPORT_SYMBOL_GPL(btrtl_get_uart_settings);
+static int btrtl_module_init(void)
+{
+ BT_INFO("btrtl: init");
+
+ return 0;
+}
+
+static void btrtl_module_exit(void)
+{
+ BT_INFO("btrtl: exit");
+
+ dev_fw_free();
+}
+
+module_init(btrtl_module_init);
+module_exit(btrtl_module_exit)
+
MODULE_AUTHOR("Daniel Drake <drake@endlessm.com>");
MODULE_DESCRIPTION("Bluetooth support for Realtek devices ver " VERSION);
MODULE_VERSION(VERSION);
--
2.19.2
reply other threads:[~2019-08-02 12:10 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190802121029.GA8795@toshiba \
--to=alex_lu@realsil.com.cn \
--cc=johan.hedberg@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcel@holtmann.org \
--cc=max.chou@realtek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox