Bluetooth: btintel: Consolidate intel_version_tlv parsing
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Tue, 23 Mar 2021 18:58:58 +0000 (11:58 -0700)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 25 Mar 2021 15:09:45 +0000 (16:09 +0100)
This moves version checks of intel_version_tlv() to btintel_version_info_tlv().

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Tested-by: Tedd Ho-Jeong An <tedd.an@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
drivers/bluetooth/btintel.c
drivers/bluetooth/btintel.h
drivers/bluetooth/btusb.c

index 13bc93a..bb2546c 100644 (file)
@@ -372,10 +372,53 @@ int btintel_read_version(struct hci_dev *hdev, struct intel_version *ver)
 }
 EXPORT_SYMBOL_GPL(btintel_read_version);
 
-void btintel_version_info_tlv(struct hci_dev *hdev, struct intel_version_tlv *version)
+int btintel_version_info_tlv(struct hci_dev *hdev, struct intel_version_tlv *version)
 {
        const char *variant;
 
+       /* The hardware platform number has a fixed value of 0x37 and
+        * for now only accept this single value.
+        */
+       if (INTEL_HW_PLATFORM(version->cnvi_bt) != 0x37) {
+               bt_dev_err(hdev, "Unsupported Intel hardware platform (0x%2x)",
+                          INTEL_HW_PLATFORM(version->cnvi_bt));
+               return -EINVAL;
+       }
+
+       /* Check for supported iBT hardware variants of this firmware
+        * loading method.
+        *
+        * This check has been put in place to ensure correct forward
+        * compatibility options when newer hardware variants come along.
+        */
+       switch (INTEL_HW_VARIANT(version->cnvi_bt)) {
+       case 0x17:      /* TyP */
+       case 0x18:      /* Slr */
+       case 0x19:      /* Slr-F */
+               break;
+       default:
+               bt_dev_err(hdev, "Unsupported Intel hardware variant (0x%x)",
+                          INTEL_HW_VARIANT(version->cnvi_bt));
+               return -EINVAL;
+       }
+
+       /* It is required that every single firmware fragment is acknowledged
+        * with a command complete event. If the boot parameters indicate
+        * that this bootloader does not send them, then abort the setup.
+        */
+       if (version->limited_cce != 0x00) {
+               bt_dev_err(hdev, "Unsupported Intel firmware loading method (0x%x)",
+                          version->limited_cce);
+               return -EINVAL;
+       }
+
+       /* Secure boot engine type should be either 1 (ECDSA) or 0 (RSA) */
+       if (version->sbe_type > 0x01) {
+               bt_dev_err(hdev, "Unsupported Intel secure boot engine type (0x%x)",
+                          version->sbe_type);
+               return -EINVAL;
+       }
+
        switch (version->img_type) {
        case 0x01:
                variant = "Bootloader";
@@ -397,15 +440,14 @@ void btintel_version_info_tlv(struct hci_dev *hdev, struct intel_version_tlv *ve
                break;
        default:
                bt_dev_err(hdev, "Unsupported image type(%02x)", version->img_type);
-               goto done;
+               return -EINVAL;
        }
 
        bt_dev_info(hdev, "%s timestamp %u.%u buildtype %u build %u", variant,
                    2000 + (version->timestamp >> 8), version->timestamp & 0xff,
                    version->build_type, version->build_num);
 
-done:
-       return;
+       return 0;
 }
 EXPORT_SYMBOL_GPL(btintel_version_info_tlv);
 
index 51f1f2c..56f30ea 100644 (file)
@@ -149,7 +149,7 @@ int btintel_set_diag_mfg(struct hci_dev *hdev, bool enable);
 void btintel_hw_error(struct hci_dev *hdev, u8 code);
 
 void btintel_version_info(struct hci_dev *hdev, struct intel_version *ver);
-void btintel_version_info_tlv(struct hci_dev *hdev, struct intel_version_tlv *version);
+int btintel_version_info_tlv(struct hci_dev *hdev, struct intel_version_tlv *version);
 int btintel_secure_send(struct hci_dev *hdev, u8 fragment_type, u32 plen,
                        const void *param);
 int btintel_load_ddc_config(struct hci_dev *hdev, const char *ddc_name);
@@ -216,9 +216,10 @@ static inline void btintel_version_info(struct hci_dev *hdev,
 {
 }
 
-static inline void btintel_version_info_tlv(struct hci_dev *hdev,
-                                           struct intel_version_tlv *version)
+static inline int btintel_version_info_tlv(struct hci_dev *hdev,
+                                          struct intel_version_tlv *version)
 {
+       return -EOPNOTSUPP;
 }
 
 static inline int btintel_secure_send(struct hci_dev *hdev, u8 fragment_type,
index a30f7ea..f163f17 100644 (file)
@@ -2465,15 +2465,6 @@ static int btusb_intel_download_firmware_newgen(struct hci_dev *hdev,
        if (!ver || !boot_param)
                return -EINVAL;
 
-       /* The hardware platform number has a fixed value of 0x37 and
-        * for now only accept this single value.
-        */
-       if (INTEL_HW_PLATFORM(ver->cnvi_bt) != 0x37) {
-               bt_dev_err(hdev, "Unsupported Intel hardware platform (0x%2x)",
-                          INTEL_HW_PLATFORM(ver->cnvi_bt));
-               return -EINVAL;
-       }
-
        /* The firmware variant determines if the device is in bootloader
         * mode or is running operational firmware. The value 0x03 identifies
         * the bootloader and the value 0x23 identifies the operational
@@ -2492,49 +2483,6 @@ static int btusb_intel_download_firmware_newgen(struct hci_dev *hdev,
                btintel_check_bdaddr(hdev);
        }
 
-       /* Check for supported iBT hardware variants of this firmware
-        * loading method.
-        *
-        * This check has been put in place to ensure correct forward
-        * compatibility options when newer hardware variants come along.
-        */
-       switch (INTEL_HW_VARIANT(ver->cnvi_bt)) {
-       case 0x17:      /* TyP */
-       case 0x18:      /* Slr */
-       case 0x19:      /* Slr-F */
-               break;
-       default:
-               bt_dev_err(hdev, "Unsupported Intel hardware variant (0x%x)",
-                          INTEL_HW_VARIANT(ver->cnvi_bt));
-               return -EINVAL;
-       }
-
-       /* If the device is not in bootloader mode, then the only possible
-        * choice is to return an error and abort the device initialization.
-        */
-       if (ver->img_type != 0x01) {
-               bt_dev_err(hdev, "Unsupported Intel firmware variant (0x%x)",
-                          ver->img_type);
-               return -ENODEV;
-       }
-
-       /* It is required that every single firmware fragment is acknowledged
-        * with a command complete event. If the boot parameters indicate
-        * that this bootloader does not send them, then abort the setup.
-        */
-       if (ver->limited_cce != 0x00) {
-               bt_dev_err(hdev, "Unsupported Intel firmware loading method (0x%x)",
-                          ver->limited_cce);
-               return -EINVAL;
-       }
-
-       /* Secure boot engine type should be either 1 (ECDSA) or 0 (RSA) */
-       if (ver->sbe_type > 0x01) {
-               bt_dev_err(hdev, "Unsupported Intel secure boot engine type (0x%x)",
-                          ver->sbe_type);
-               return -EINVAL;
-       }
-
        /* If the OTP has no valid Bluetooth device address, then there will
         * also be no valid address for the operational firmware.
         */
@@ -2972,7 +2920,9 @@ static int btusb_setup_intel_newgen(struct hci_dev *hdev)
                return err;
        }
 
-       btintel_version_info_tlv(hdev, &version);
+       err = btintel_version_info_tlv(hdev, &version);
+       if (err)
+               return err;
 
        err = btusb_intel_download_firmware_newgen(hdev, &version, &boot_param);
        if (err)