diff mbox series

[3/5] Bluetooth: btintel: Refactor firmware payload download code

Message ID 20200702120315.26768-4-kiran.k@intel.com (mailing list archive)
State New, archived
Headers show
Series Refactor firmware download | expand

Commit Message

K, Kiran July 2, 2020, 12:03 p.m. UTC
Move firmware payload download code to a separate function to
enhance readability and reusability

Signed-off-by: Kiran K <kiran.k@intel.com>
Signed-off-by: Amit K Bag <amit.k.bag@intel.com>
Signed-off-by: Raghuram Hegde <raghuram.hegde@intel.com>
Reviewed-by: Chethan T N <chethan.tumkur.narayan@intel.com>
Reviewed-by: Sathish Narasimman <Sathish.Narasimman@intel.com>
Reviewed-by: Srivatsa Ravishankar <ravishankar.srivatsa@intel.com>
---
 drivers/bluetooth/btintel.c   | 29 ++++++++++++++++++++---------
 drivers/bluetooth/btintel.h   | 10 +++++-----
 drivers/bluetooth/btusb.c     |  2 +-
 drivers/bluetooth/hci_intel.c |  2 +-
 4 files changed, 27 insertions(+), 16 deletions(-)

Comments

Marcel Holtmann July 2, 2020, 1:27 p.m. UTC | #1
Hi Kiran,

> Move firmware payload download code to a separate function to
> enhance readability and reusability

this patch is doing more than that. It also introduces an extra public function.

Regards

Marcel
K, Kiran July 2, 2020, 5:20 p.m. UTC | #2
Hi Marcel,

> -----Original Message-----
> From: Marcel Holtmann <marcel@holtmann.org>
> Sent: Thursday, July 2, 2020 6:58 PM
> To: K, Kiran <kiran.k@intel.com>
> Cc: linux-bluetooth <linux-bluetooth@vger.kernel.org>; Srivatsa, Ravishankar
> <ravishankar.srivatsa@intel.com>; Tumkur Narayan, Chethan
> <chethan.tumkur.narayan@intel.com>; kiraank@gmail.com; Bag, Amit K
> <amit.k.bag@intel.com>; Raghuram Hegde <raghuram.hegde@intel.com>
> Subject: Re: [PATCH 3/5] Bluetooth: btintel: Refactor firmware payload
> download code
> 
> Hi Kiran,
> 
> > Move firmware payload download code to a separate function to enhance
> > readability and reusability
> 
> this patch is doing more than that. It also introduces an extra public function.

The existing firmware download function is suffixed with "_legacy" to distinguish from an upcoming method to support firmware download in tlv format.  I will retain the older one as it is and use "_tlv" suffix for new one without losing the intention of the methods. I will send the changes in the next version.
> 
> Regards
> 
> Marcel

Thanks,
Kiran
diff mbox series

Patch

diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c
index 1c820c187421..d0c6576212d7 100644
--- a/drivers/bluetooth/btintel.c
+++ b/drivers/bluetooth/btintel.c
@@ -19,6 +19,7 @@ 
 #define VERSION "0.1"
 
 #define BDADDR_INTEL (&(bdaddr_t) {{0x00, 0x8b, 0x9e, 0x19, 0x03, 0x00}})
+#define RSA_HEADER_LEN	644
 
 int btintel_check_bdaddr(struct hci_dev *hdev)
 {
@@ -681,20 +682,17 @@  static int btintel_sfi_rsa_header_secure_send(struct hci_dev *hdev,
 	return err;
 }
 
-int btintel_download_firmware(struct hci_dev *hdev, const struct firmware *fw,
-			      u32 *boot_param)
+static int btintel_download_firmware_payload(struct hci_dev *hdev,
+					     const struct firmware *fw,
+					     u32 *boot_param, size_t offset)
 {
 	int err;
 	const u8 *fw_ptr;
 	u32 frag_len;
 
-	err = btintel_sfi_rsa_header_secure_send(hdev, fw);
-	if (err)
-		goto done;
-
-
-	fw_ptr = fw->data + 644;
+	fw_ptr = fw->data + offset;
 	frag_len = 0;
+	err = -EINVAL;
 
 	while (fw_ptr - fw->data < fw->size) {
 		struct hci_command_hdr *cmd = (void *)(fw_ptr + frag_len);
@@ -740,7 +738,20 @@  int btintel_download_firmware(struct hci_dev *hdev, const struct firmware *fw,
 done:
 	return err;
 }
-EXPORT_SYMBOL_GPL(btintel_download_firmware);
+
+int btintel_download_firmware_legacy(struct hci_dev *hdev,
+				     const struct firmware *fw,
+				     u32 *boot_param)
+{
+	int err;
+
+	err = btintel_sfi_rsa_header_secure_send(hdev, fw);
+	if (err)
+		return err;
+
+	return btintel_download_firmware_payload(hdev, fw, boot_param, RSA_HEADER_LEN);
+}
+EXPORT_SYMBOL_GPL(btintel_download_firmware_legacy);
 
 void btintel_reset_to_bootloader(struct hci_dev *hdev)
 {
diff --git a/drivers/bluetooth/btintel.h b/drivers/bluetooth/btintel.h
index 0865d2d4aca7..e476105d495b 100644
--- a/drivers/bluetooth/btintel.h
+++ b/drivers/bluetooth/btintel.h
@@ -96,8 +96,8 @@  struct regmap *btintel_regmap_init(struct hci_dev *hdev, u16 opcode_read,
 int btintel_send_intel_reset(struct hci_dev *hdev, u32 boot_param);
 int btintel_read_boot_params(struct hci_dev *hdev,
 			     struct intel_boot_params *params);
-int btintel_download_firmware(struct hci_dev *dev, const struct firmware *fw,
-			      u32 *boot_param);
+int btintel_download_firmware_legacy(struct hci_dev *dev, const struct firmware *fw,
+				     u32 *boot_param);
 void btintel_reset_to_bootloader(struct hci_dev *hdev);
 int btintel_read_debug_features(struct hci_dev *hdev,
 				struct intel_debug_features *features);
@@ -191,9 +191,9 @@  static inline int btintel_read_boot_params(struct hci_dev *hdev,
 	return -EOPNOTSUPP;
 }
 
-static inline int btintel_download_firmware(struct hci_dev *dev,
-					    const struct firmware *fw,
-					    u32 *boot_param)
+static inline int btintel_download_firmware_legacy(struct hci_dev *dev,
+						   const struct firmware *fw,
+						   u32 *boot_param)
 {
 	return -EOPNOTSUPP;
 }
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index d06c946f7810..364da6d44ee3 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -2438,7 +2438,7 @@  static int btusb_intel_download_firmware(struct hci_dev *hdev,
 	set_bit(BTUSB_DOWNLOADING, &data->flags);
 
 	/* Start firmware downloading and get boot parameter */
-	err = btintel_download_firmware(hdev, fw, &boot_param);
+	err = btintel_download_firmware_legacy(hdev, fw, &boot_param);
 	if (err < 0) {
 		/* When FW download fails, send Intel Reset to retry
 		 * FW download.
diff --git a/drivers/bluetooth/hci_intel.c b/drivers/bluetooth/hci_intel.c
index f30cbc66d48f..14045a464309 100644
--- a/drivers/bluetooth/hci_intel.c
+++ b/drivers/bluetooth/hci_intel.c
@@ -755,7 +755,7 @@  static int intel_setup(struct hci_uart *hu)
 	set_bit(STATE_DOWNLOADING, &intel->flags);
 
 	/* Start firmware downloading and get boot parameter */
-	err = btintel_download_firmware(hdev, fw, &boot_param);
+	err = btintel_download_firmware_legacy(hdev, fw, &boot_param);
 	if (err < 0)
 		goto done;