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

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 bb2546c..bddaa4f 100644 (file)
@@ -216,10 +216,39 @@ void btintel_hw_error(struct hci_dev *hdev, u8 code)
 }
 EXPORT_SYMBOL_GPL(btintel_hw_error);
 
-void btintel_version_info(struct hci_dev *hdev, struct intel_version *ver)
+int btintel_version_info(struct hci_dev *hdev, struct intel_version *ver)
 {
        const char *variant;
 
+       /* The hardware platform number has a fixed value of 0x37 and
+        * for now only accept this single value.
+        */
+       if (ver->hw_platform != 0x37) {
+               bt_dev_err(hdev, "Unsupported Intel hardware platform (%u)",
+                          ver->hw_platform);
+               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 (ver->hw_variant) {
+       case 0x0b:      /* SfP */
+       case 0x0c:      /* WsP */
+       case 0x11:      /* JfP */
+       case 0x12:      /* ThP */
+       case 0x13:      /* HrP */
+       case 0x14:      /* CcP */
+               break;
+       default:
+               bt_dev_err(hdev, "Unsupported Intel hardware variant (%u)",
+                          ver->hw_variant);
+               return -EINVAL;
+       }
+
        switch (ver->fw_variant) {
        case 0x06:
                variant = "Bootloader";
@@ -228,13 +257,16 @@ void btintel_version_info(struct hci_dev *hdev, struct intel_version *ver)
                variant = "Firmware";
                break;
        default:
-               return;
+               bt_dev_err(hdev, "Unsupported firmware variant(%02x)", ver->fw_variant);
+               return -EINVAL;
        }
 
        bt_dev_info(hdev, "%s revision %u.%u build %u week %u %u",
                    variant, ver->fw_revision >> 4, ver->fw_revision & 0x0f,
                    ver->fw_build_num, ver->fw_build_ww,
                    2000 + ver->fw_build_yy);
+
+       return 0;
 }
 EXPORT_SYMBOL_GPL(btintel_version_info);
 
index 56f30ea..d184064 100644 (file)
@@ -148,7 +148,7 @@ int btintel_set_diag(struct hci_dev *hdev, bool enable);
 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);
+int btintel_version_info(struct hci_dev *hdev, struct intel_version *ver);
 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);
@@ -211,9 +211,10 @@ static inline void btintel_hw_error(struct hci_dev *hdev, u8 code)
 {
 }
 
-static inline void btintel_version_info(struct hci_dev *hdev,
-                                       struct intel_version *ver)
+static inline int btintel_version_info(struct hci_dev *hdev,
+                                      struct intel_version *ver)
 {
+       return -EOPNOTSUPP;
 }
 
 static inline int btintel_version_info_tlv(struct hci_dev *hdev,
index f163f17..2d3498b 100644 (file)
@@ -2407,12 +2407,6 @@ static int btusb_setup_intel_new_get_fw_name(struct intel_version *ver,
                                             char *fw_name, size_t len,
                                             const char *suffix)
 {
-       /* The hardware platform number has a fixed value of 0x37 and
-        * for now only accept this single value.
-        */
-       if (ver->hw_platform != 0x37)
-               return -EINVAL;
-
        switch (ver->hw_variant) {
        case 0x0b:      /* SfP */
        case 0x0c:      /* WsP */
@@ -2582,8 +2576,6 @@ static int btusb_intel_download_firmware(struct hci_dev *hdev,
        if (!ver || !params)
                return -EINVAL;
 
-       btintel_version_info(hdev, ver);
-
        /* The firmware variant determines if the device is in bootloader
         * mode or is running operational firmware. The value 0x06 identifies
         * the bootloader and the value 0x23 identifies the operational
@@ -2776,6 +2768,10 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
                return err;
        }
 
+       err = btintel_version_info(hdev, &ver);
+       if (err)
+               return err;
+
        err = btusb_intel_download_firmware(hdev, &ver, &params, &boot_param);
        if (err)
                return err;