Move firmware payload download code to a separate function to enhance readability and reusability Signed-off-by: Kiran K <kiran.k@xxxxxxxxx> Signed-off-by: Amit K Bag <amit.k.bag@xxxxxxxxx> Signed-off-by: Raghuram Hegde <raghuram.hegde@xxxxxxxxx> Reviewed-by: Chethan T N <chethan.tumkur.narayan@xxxxxxxxx> Reviewed-by: Sathish Narasimman <Sathish.Narasimman@xxxxxxxxx> Reviewed-by: Srivatsa Ravishankar <ravishankar.srivatsa@xxxxxxxxx> --- 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(-) 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; -- 2.17.1