From patchwork Tue Mar 23 18:58:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 12159111 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC884C433E0 for ; Tue, 23 Mar 2021 18:59:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B3160619B3 for ; Tue, 23 Mar 2021 18:59:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231901AbhCWS7Q (ORCPT ); Tue, 23 Mar 2021 14:59:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232051AbhCWS7G (ORCPT ); Tue, 23 Mar 2021 14:59:06 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80AB7C061574 for ; Tue, 23 Mar 2021 11:59:06 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id x7-20020a17090a2b07b02900c0ea793940so12623200pjc.2 for ; Tue, 23 Mar 2021 11:59:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=5S35RqV/iyjjUKRd30CMkCYafAi58/svbRji+isuYwo=; b=sCOL4KuGzF1HSTJu0Owrp26d3/wKbinPHmPUG92EdUnrdVUydcDCFbw3JhIjEZHhTT ZKq+Hms3em3JUoSDTkY1Fyw01ZWpCaw+eg61+G6NV87IEfYnsLtQtTiUT7KRU6TlbR+J e14JbbjFdLsLw1vcQhcmExBwbxwiC6ZiPWG2R8V/hBDosbKi+1EIz7tAWfFgjsCWnhuO bf9K9PbD3sTf5y149G1ILyBk2hxxBD/5TuUHm6SdtBshna3Da0AlY1FqCAzVSCD0MTh2 kSnLjfTrvP+vI5iywMKhwpC3V8H9HohEnEmlbE3SyYcqBSRcgOwke+DOBv1VbZFDm+Bi l4cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=5S35RqV/iyjjUKRd30CMkCYafAi58/svbRji+isuYwo=; b=R8WTwQR+KXBZiUaVjPaiJKubeueuEREB9zfoAiEYpkt2HaKCWUeIDyyeItSGnRwHFr BN9i3OzgXJypMwgXu832C3TO07XL2eI1VcnUrt0p7Jii70tgo45kqTLoZOyCFLEqbSNh DMUnNVWjcJgVshz5X9FzRQ+SWt67SKhpfXemeGbCEb5lb9Mzu+O3br5IlRn6mOqTaVnD RaD3SqN6twa3eW4o5e7E+6EvAz4Z07lHCqPz7moxVHcJuaBpaocfYYHN3u9cwc2KL684 yRpnknJFwTgSW44bYXPKCQwxCECKSvScBWhyB0VRaUvMtGJjzH+Idvc7vPcSOewU8cd/ MkwQ== X-Gm-Message-State: AOAM532u+ZinsbLX3RxpDfTvrNo7ALbixhtKhPA+78n+iygipDZUBb2z 5dmYeJ2MGwndqM3avH0bJ8Af507wPE4VfA== X-Google-Smtp-Source: ABdhPJzfawyJeUP1bsKjbO1OmzBL51h8jzJpNAmnn6wkFGHdgHTOGTJU31zUtlqfBlIZnRLY3sb/4w== X-Received: by 2002:a17:90a:d341:: with SMTP id i1mr5700780pjx.74.1616525945615; Tue, 23 Mar 2021 11:59:05 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id b10sm16132325pgm.76.2021.03.23.11.59.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 11:59:05 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v10 1/9] Bluetooth: btintel: Check firmware version before download Date: Tue, 23 Mar 2021 11:58:56 -0700 Message-Id: <20210323185904.3372987-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This checks the firmware build number, week and year against the repective loaded version. If details are a match, skip the download process. Signed-off-by: Luiz Augusto von Dentz Tested-by: Tedd Ho-Jeong An --- v2: Add patch that mover checks for operational mode after the version checking. v3: Fix not checking for operation mode before using btintel_read_boot_params since some models depend on that to contruct the fw filename. Also attempt to cleanup duplicated code. v4: Fix forwarding -EALREADY when firmware has already been loaded. v5: Fix not advancing fw_ptr. v6: Fix btusb_setup_intel_new_get_fw_name error checking for ddc. v7: Disable version checking for WsP/SfP. v8: Really disables version checking for WsP/SfP. v9: Reintroduce bootloader checks and add workaround for version checking when operation and version cannot be read. v10: Fix build error when BT_CONFIG_INTEL is not set. drivers/bluetooth/btintel.c | 106 +++++++++++++++++++++++++++------- drivers/bluetooth/btintel.h | 5 +- drivers/bluetooth/btusb.c | 18 +++++- drivers/bluetooth/hci_intel.c | 7 ++- 4 files changed, 109 insertions(+), 27 deletions(-) diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index fa97324454ea..3ff698a0bd25 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c @@ -24,6 +24,14 @@ #define ECDSA_OFFSET 644 #define ECDSA_HEADER_LEN 320 +#define CMD_WRITE_BOOT_PARAMS 0xfc0e +struct cmd_write_boot_params { + u32 boot_addr; + u8 fw_build_num; + u8 fw_build_ww; + u8 fw_build_yy; +} __packed; + int btintel_check_bdaddr(struct hci_dev *hdev) { struct hci_rp_read_bd_addr *bda; @@ -841,7 +849,7 @@ static int btintel_sfi_ecdsa_header_secure_send(struct hci_dev *hdev, static int btintel_download_firmware_payload(struct hci_dev *hdev, const struct firmware *fw, - u32 *boot_param, size_t offset) + size_t offset) { int err; const u8 *fw_ptr; @@ -854,21 +862,6 @@ static int btintel_download_firmware_payload(struct hci_dev *hdev, while (fw_ptr - fw->data < fw->size) { struct hci_command_hdr *cmd = (void *)(fw_ptr + frag_len); - /* Each SKU has a different reset parameter to use in the - * HCI_Intel_Reset command and it is embedded in the firmware - * data. So, instead of using static value per SKU, check - * the firmware data and save it for later use. - */ - if (le16_to_cpu(cmd->opcode) == 0xfc0e) { - /* The boot parameter is the first 32-bit value - * and rest of 3 octets are reserved. - */ - *boot_param = get_unaligned_le32(fw_ptr + frag_len + - sizeof(*cmd)); - - bt_dev_dbg(hdev, "boot_param=0x%x", *boot_param); - } - frag_len += sizeof(*cmd) + cmd->plen; /* The parameter length of the secure send command requires @@ -897,28 +890,101 @@ static int btintel_download_firmware_payload(struct hci_dev *hdev, return err; } +static bool btintel_firmware_version(struct hci_dev *hdev, + u8 num, u8 ww, u8 yy, + const struct firmware *fw, + u32 *boot_addr) +{ + const u8 *fw_ptr; + + fw_ptr = fw->data; + + while (fw_ptr - fw->data < fw->size) { + struct hci_command_hdr *cmd = (void *)(fw_ptr); + + /* Each SKU has a different reset parameter to use in the + * HCI_Intel_Reset command and it is embedded in the firmware + * data. So, instead of using static value per SKU, check + * the firmware data and save it for later use. + */ + if (le16_to_cpu(cmd->opcode) == CMD_WRITE_BOOT_PARAMS) { + struct cmd_write_boot_params *params; + + params = (void *)(fw_ptr + sizeof(*cmd)); + + bt_dev_info(hdev, "Boot Address: 0x%x", + le32_to_cpu(params->boot_addr)); + + bt_dev_info(hdev, "Firmware Version: %u-%u.%u", + params->fw_build_num, params->fw_build_ww, + params->fw_build_yy); + + return (num == params->fw_build_num && + ww == params->fw_build_ww && + yy == params->fw_build_yy); + } + + fw_ptr += sizeof(*cmd) + cmd->plen; + } + + return false; +} + int btintel_download_firmware(struct hci_dev *hdev, + struct intel_version *ver, const struct firmware *fw, u32 *boot_param) { int err; + /* SfP and WsP don't seem to update the firmware version on file + * so version checking is currently not possible. + */ + switch (ver->hw_variant) { + case 0x0b: /* SfP */ + case 0x0c: /* WsP */ + /* Skip version checking */ + break; + default: + /* Skip download if firmware has the same version */ + if (btintel_firmware_version(hdev, ver->fw_build_num, + ver->fw_build_ww, ver->fw_build_yy, + fw, boot_param)) { + bt_dev_info(hdev, "Firmware already loaded"); + /* Return -EALREADY to indicate that the firmware has + * already been loaded. + */ + return -EALREADY; + } + } + 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); + return btintel_download_firmware_payload(hdev, fw, RSA_HEADER_LEN); } EXPORT_SYMBOL_GPL(btintel_download_firmware); int btintel_download_firmware_newgen(struct hci_dev *hdev, + struct intel_version_tlv *ver, const struct firmware *fw, u32 *boot_param, u8 hw_variant, u8 sbe_type) { int err; u32 css_header_ver; + /* Skip download if firmware has the same version */ + if (btintel_firmware_version(hdev, ver->min_fw_build_nn, + ver->min_fw_build_cw, ver->min_fw_build_yy, + fw, boot_param)) { + bt_dev_info(hdev, "Firmware already loaded"); + /* Return -EALREADY to indicate that firmware has already been + * loaded. + */ + return -EALREADY; + } + /* iBT hardware variants 0x0b, 0x0c, 0x11, 0x12, 0x13, 0x14 support * only RSA secure boot engine. Hence, the corresponding sfi file will * have RSA header of 644 bytes followed by Command Buffer. @@ -948,7 +1014,7 @@ int btintel_download_firmware_newgen(struct hci_dev *hdev, if (err) return err; - err = btintel_download_firmware_payload(hdev, fw, boot_param, RSA_HEADER_LEN); + err = btintel_download_firmware_payload(hdev, fw, RSA_HEADER_LEN); if (err) return err; } else if (hw_variant >= 0x17) { @@ -969,7 +1035,6 @@ int btintel_download_firmware_newgen(struct hci_dev *hdev, return err; err = btintel_download_firmware_payload(hdev, fw, - boot_param, RSA_HEADER_LEN + ECDSA_HEADER_LEN); if (err) return err; @@ -979,7 +1044,6 @@ int btintel_download_firmware_newgen(struct hci_dev *hdev, return err; err = btintel_download_firmware_payload(hdev, fw, - boot_param, RSA_HEADER_LEN + ECDSA_HEADER_LEN); if (err) return err; diff --git a/drivers/bluetooth/btintel.h b/drivers/bluetooth/btintel.h index 6511b091caf5..51f1f2c883b4 100644 --- a/drivers/bluetooth/btintel.h +++ b/drivers/bluetooth/btintel.h @@ -163,9 +163,10 @@ 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(struct hci_dev *dev, struct intel_version *ver, + const struct firmware *fw, u32 *boot_param); int btintel_download_firmware_newgen(struct hci_dev *hdev, + struct intel_version_tlv *ver, const struct firmware *fw, u32 *boot_param, u8 hw_variant, u8 sbe_type); diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 0d355bb45e08..de220ab7f231 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -2557,10 +2557,17 @@ static int btusb_intel_download_firmware_newgen(struct hci_dev *hdev, set_bit(BTUSB_DOWNLOADING, &data->flags); /* Start firmware downloading and get boot parameter */ - err = btintel_download_firmware_newgen(hdev, fw, boot_param, + err = btintel_download_firmware_newgen(hdev, ver, fw, boot_param, INTEL_HW_VARIANT(ver->cnvi_bt), ver->sbe_type); if (err < 0) { + if (err == -EALREADY) { + /* Firmware has already been loaded */ + set_bit(BTUSB_FIRMWARE_LOADED, &data->flags); + err = 0; + goto done; + } + /* When FW download fails, send Intel Reset to retry * FW download. */ @@ -2752,8 +2759,15 @@ 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(hdev, ver, fw, boot_param); if (err < 0) { + if (err == -EALREADY) { + /* Firmware has already been loaded */ + set_bit(BTUSB_FIRMWARE_LOADED, &data->flags); + err = 0; + goto done; + } + /* 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 b20a40fab83e..7249b91d9b91 100644 --- a/drivers/bluetooth/hci_intel.c +++ b/drivers/bluetooth/hci_intel.c @@ -735,7 +735,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(hdev, &ver, fw, &boot_param); if (err < 0) goto done; @@ -784,7 +784,10 @@ static int intel_setup(struct hci_uart *hu) done: release_firmware(fw); - if (err < 0) + /* Check if there was an error and if is not -EALREADY which means the + * firmware has already been loaded. + */ + if (err < 0 && err != -EALREADY) return err; /* We need to restore the default speed before Intel reset */ From patchwork Tue Mar 23 18:58:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 12159105 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95965C433C1 for ; Tue, 23 Mar 2021 18:59:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 71D20619A3 for ; Tue, 23 Mar 2021 18:59:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232748AbhCWS7P (ORCPT ); Tue, 23 Mar 2021 14:59:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232408AbhCWS7H (ORCPT ); Tue, 23 Mar 2021 14:59:07 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77C04C061574 for ; Tue, 23 Mar 2021 11:59:07 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id ot17-20020a17090b3b51b0290109c9ac3c34so10329377pjb.4 for ; Tue, 23 Mar 2021 11:59:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=o4VR66b72NDwj9AcA+Kn10dg4DS4Df355mwoHIeLOss=; b=rfI78seF8S79HpN3BHKZZmyhWVANags/XVD87Hb8wQX07fTh13Ab7iBxQ5AoNLfhls B32NDXV51awBnyChHbvqytHn9h729uX3FCUYL+MDcUWucg3GYE1y7bb+JA+SezTb4NYl VtDjWKFf0IlJj7dp4/bmdHNo7vaZA2i9TRtJCFIulmY2eKsBULd0vnWik7SWES8ZkF0v O4g+ISoiaYPQL6k0CFlTlVH3l2pLyZa04YaSpqnr/xlG0Rvn1ma9j0MfTWgoilEaxVjR ajDc1IRCv8yNknPzu8MTP0a8/CvNG27p/J0RImGSk3eHaGaifiBhwpjetupc74P1INxa PXTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o4VR66b72NDwj9AcA+Kn10dg4DS4Df355mwoHIeLOss=; b=oWBrAI+OUAhe07ezc1IwcUjU3VjCK18MfVf3YMXBChVZOnIDIVQFasuGUNu2YYEg5/ 3ta/kaMgcK9GosAvLFRqm15ER0lNGZ4VyipFZo+dHZ3+Idpud0b3PejWSjqo5lma/jat 1cUrZNt7P70z9mh0hwi7WA266g/ks3LmPclLYUKLGdq0yJRui92r5Jr2xv+HRL2T3j6g gXHyqGhs0IX2oYldBDMRxDtUyK1NLGRD+GV4oaMdmkhFGr8koxtkLSNXpBLABHNPOLQu ND2nGR3hEcytWXiqZ84b9zGCUf/fbYfbXTtDOJSySK7jffB+QZtvLS5AHEG1oJnEO5V8 NmJA== X-Gm-Message-State: AOAM531n06w2qH2TxFQYZ7sk1rfcBHy76Or77I6hhBKfcP/Jxbr0+WH8 Y/3//CKWmFyEhNqCNtvfd61/nzhdzJd6sA== X-Google-Smtp-Source: ABdhPJxgMlqVObeu/hM/ROlCYPgCh+0+/DePKZXtCeN8PZbjKErX/IewbOvButcglIPyr52kZN2rkQ== X-Received: by 2002:a17:90a:ff91:: with SMTP id hf17mr6129435pjb.34.1616525946626; Tue, 23 Mar 2021 11:59:06 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id b10sm16132325pgm.76.2021.03.23.11.59.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 11:59:06 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v10 2/9] Bluetooth: btintel: Move operational checks after version check Date: Tue, 23 Mar 2021 11:58:57 -0700 Message-Id: <20210323185904.3372987-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210323185904.3372987-1-luiz.dentz@gmail.com> References: <20210323185904.3372987-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz In order to allow new firmware to load, it first needs to check if the firmware version on file matches the one loaded if it doesn't, then it needs to revert to bootloader mode in order to load the new firmware. Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel.c | 22 ++++++++++++ drivers/bluetooth/btusb.c | 68 +++++++++++++------------------------ 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index 3ff698a0bd25..13bc93a986c7 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c @@ -958,6 +958,17 @@ int btintel_download_firmware(struct hci_dev *hdev, } } + /* 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 + * firmware. + * + * If the firmware version has changed that means it needs to be reset + * to bootloader when operational so the new firmware can be loaded. + */ + if (ver->fw_variant == 0x23) + return -EINVAL; + err = btintel_sfi_rsa_header_secure_send(hdev, fw); if (err) return err; @@ -985,6 +996,17 @@ int btintel_download_firmware_newgen(struct hci_dev *hdev, return -EALREADY; } + /* The firmware variant determines if the device is in bootloader + * mode or is running operational firmware. The value 0x01 identifies + * the bootloader and the value 0x03 identifies the operational + * firmware. + * + * If the firmware version has changed that means it needs to be reset + * to bootloader when operational so the new firmware can be loaded. + */ + if (ver->img_type == 0x03) + return -EINVAL; + /* iBT hardware variants 0x0b, 0x0c, 0x11, 0x12, 0x13, 0x14 support * only RSA secure boot engine. Hence, the corresponding sfi file will * have RSA header of 644 bytes followed by Command Buffer. diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index de220ab7f231..a30f7ea9be36 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -2402,11 +2402,17 @@ static int btusb_send_frame_intel(struct hci_dev *hdev, struct sk_buff *skb) return -EILSEQ; } -static bool btusb_setup_intel_new_get_fw_name(struct intel_version *ver, +static int btusb_setup_intel_new_get_fw_name(struct intel_version *ver, struct intel_boot_params *params, 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 */ @@ -2426,9 +2432,10 @@ static bool btusb_setup_intel_new_get_fw_name(struct intel_version *ver, suffix); break; default: - return false; + return -EINVAL; } - return true; + + return 0; } static void btusb_setup_intel_newgen_get_fw_name(const struct intel_version_tlv *ver_tlv, @@ -2483,7 +2490,6 @@ static int btusb_intel_download_firmware_newgen(struct hci_dev *hdev, if (ver->img_type == 0x03) { clear_bit(BTUSB_BOOTLOADER, &data->flags); btintel_check_bdaddr(hdev); - return 0; } /* Check for supported iBT hardware variants of this firmware @@ -2628,35 +2634,6 @@ static int btusb_intel_download_firmware(struct hci_dev *hdev, if (!ver || !params) return -EINVAL; - /* 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; - } - btintel_version_info(hdev, ver); /* The firmware variant determines if the device is in bootloader @@ -2675,16 +2652,18 @@ static int btusb_intel_download_firmware(struct hci_dev *hdev, if (ver->fw_variant == 0x23) { clear_bit(BTUSB_BOOTLOADER, &data->flags); btintel_check_bdaddr(hdev); - return 0; - } - /* 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->fw_variant != 0x06) { - bt_dev_err(hdev, "Unsupported Intel firmware variant (%u)", - ver->fw_variant); - return -ENODEV; + /* SfP and WsP don't seem to update the firmware version on file + * so version checking is currently possible. + */ + switch (ver->hw_variant) { + case 0x0b: /* SfP */ + case 0x0c: /* WsP */ + return 0; + } + + /* Proceed to download to check if the version matches */ + goto download; } /* Read the secure boot parameters to identify the operating @@ -2712,6 +2691,7 @@ static int btusb_intel_download_firmware(struct hci_dev *hdev, set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); } +download: /* With this Intel bootloader only the hardware variant and device * revision information are used to select the right firmware for SfP * and WsP. @@ -2735,7 +2715,7 @@ static int btusb_intel_download_firmware(struct hci_dev *hdev, */ err = btusb_setup_intel_new_get_fw_name(ver, params, fwname, sizeof(fwname), "sfi"); - if (!err) { + if (err < 0) { bt_dev_err(hdev, "Unsupported Intel firmware naming"); return -EINVAL; } @@ -2908,7 +2888,7 @@ static int btusb_setup_intel_new(struct hci_dev *hdev) err = btusb_setup_intel_new_get_fw_name(&ver, ¶ms, ddcname, sizeof(ddcname), "ddc"); - if (!err) { + if (err < 0) { bt_dev_err(hdev, "Unsupported Intel firmware naming"); } else { /* Once the device is running in operational mode, it needs to From patchwork Tue Mar 23 18:58:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 12159107 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 163AAC433E3 for ; Tue, 23 Mar 2021 18:59:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D3757619CA for ; Tue, 23 Mar 2021 18:59:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232540AbhCWS7S (ORCPT ); Tue, 23 Mar 2021 14:59:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232509AbhCWS7I (ORCPT ); Tue, 23 Mar 2021 14:59:08 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8D7BC061574 for ; Tue, 23 Mar 2021 11:59:08 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id l123so15285829pfl.8 for ; Tue, 23 Mar 2021 11:59:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=JBTtQV0hAlsl83X4hF0AU8cBJgeZf3tDcBLBytjot5Q=; b=KojLWv0KIhwP9++eNj4hs51s1RmdYLduH2hbeYonhbufodZW/OPi3P7ZmJn8GHfFCB AXyHUhT3nbOcqaItYCeOaEsBhCBkNtR6RUHYFmkMvf2jPYpW9q1GmKHZke0fQD8O0cZU kh1ZBB2FnuvnUuJmMH3YArXmFz54JYMWmIIKz11L7+8mUXsymf1Y3vtpL0934RUKXn5+ D+NL/4bC31w4Y5gBMvlTNYfOclLaLNDesM1OF62i1G/utLWPX/bhlI/EzcuoIiypbJCV SFCeqcFfb/+IgpZ6btSRTcjDoWVxSbxBXHWz1bVV+D9sZXQDbChFkqWHNLMYCXHx/IzY 6tWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JBTtQV0hAlsl83X4hF0AU8cBJgeZf3tDcBLBytjot5Q=; b=hekvVNsrr+khIH7n4rbQIjwGVo7KNV8RIsySFgJW+4+xVBVO9zvqtqQcWNuI0WFwg+ Qk9kTN3GNqOPg1zwd895sLdSXCA/IKvG5WBYlT91ikh3c+1UyNNZALgkhGDNK3V3hNSm ODwXYNZfrW+WF1QkUr+eVF0xHCzY6XKvKyXuwmvotEpFeDkUF8P0FnunXTUSVklTC2bp HdiV3MdwrogCGVTdMeY8W+JAV9K2WxaMLtsoLJ8ojkmyvsgrKV8dlW3IeKVSFwYRX6aU tdD/ywDa5fMQDyqOuqTtjG8ynqiwl7Ps1iOxfpLnuUhl7mOfR7K3BmhzX5R/vXnQLcfn EptQ== X-Gm-Message-State: AOAM530+pPDcgE4hR2mWkyVXZUP/Qx7Wujqc6LrfMJQ/IUIeBb6FnUOc Tve9dKxpw5z1TOGw9kItF+njDeWLfHMqBw== X-Google-Smtp-Source: ABdhPJxgg0n/zal8CONCqDlqgyyl1knWi9rsomZHyM+CZUr2IcqBS/PsGTUXm/MT8RiHKxwOP+BNxQ== X-Received: by 2002:a17:902:8e89:b029:e6:ef44:6a54 with SMTP id bg9-20020a1709028e89b02900e6ef446a54mr6383606plb.7.1616525947889; Tue, 23 Mar 2021 11:59:07 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id b10sm16132325pgm.76.2021.03.23.11.59.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 11:59:07 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v10 3/9] Bluetooth: btintel: Consolidate intel_version_tlv parsing Date: Tue, 23 Mar 2021 11:58:58 -0700 Message-Id: <20210323185904.3372987-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210323185904.3372987-1-luiz.dentz@gmail.com> References: <20210323185904.3372987-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This moves version checks of intel_version_tlv() to btintel_version_info_tlv(). Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel.c | 50 ++++++++++++++++++++++++++++++--- drivers/bluetooth/btintel.h | 7 +++-- drivers/bluetooth/btusb.c | 56 ++----------------------------------- 3 files changed, 53 insertions(+), 60 deletions(-) diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index 13bc93a986c7..bb2546c4374a 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c @@ -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); diff --git a/drivers/bluetooth/btintel.h b/drivers/bluetooth/btintel.h index 51f1f2c883b4..56f30eaa1e3c 100644 --- a/drivers/bluetooth/btintel.h +++ b/drivers/bluetooth/btintel.h @@ -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, diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index a30f7ea9be36..f163f174185b 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -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) From patchwork Tue Mar 23 18:58:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 12159113 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38815C433E5 for ; Tue, 23 Mar 2021 18:59:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 09692619C8 for ; Tue, 23 Mar 2021 18:59:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232792AbhCWS7R (ORCPT ); Tue, 23 Mar 2021 14:59:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232540AbhCWS7J (ORCPT ); Tue, 23 Mar 2021 14:59:09 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48BECC061574 for ; Tue, 23 Mar 2021 11:59:09 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id y200so15268594pfb.5 for ; Tue, 23 Mar 2021 11:59:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=61ee+0CsnnmhnN9bNvQh7INhbAp79hNtI7De/C4MKXY=; b=nmw4fT8xFRuWigT8lAn9u0rJxU0tLZU4Km7iUFzqH1h4wrOEOarm57T6D/y3tGycdV 7AstE3/cZDPAKJMWuUT5YD/kdfS8Vn2rPrVJZCeXzQfbueyfrQ0DUL7Clxcb1a7aLWCk /aNbDQF1lU7sAiXuF7CMb9HPMOYTJ5Pzier4pTvQeVvT6dQYSoQZqHzJsQj128ynz9m3 DjwK8CfE1CLN/jEiEtogHeMBbTGi8+n03+WJr+UI/xH2FkwvA+DU//85eHjL15cGId6V IHJ7Pxm8EtbeZJGmxiC/S/5P4MA23QeUhsktJviDiRmz+kogQfNIoRk0zSt3+ezGDgnE X9Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=61ee+0CsnnmhnN9bNvQh7INhbAp79hNtI7De/C4MKXY=; b=E1diDe1Rtey7a4/OrNXMtXmiQAHZhghTT7Hdn4dKIUjKnJ+l/ZRkkKqxQvkwbVVPhp TuzwHGgGqvlWvTfkHijFBdc851H9gAIO5uIdze3eh6+mUgNl8p1pW9+jO5ncRnuPbpvW t+wnMuapVYvOAyiWIB7QjO0wotCXdxKRQE/C03ETc9nQExjN6Ivurnix5j8BNs7EtgjN mDSfPmmNPrSpu6l2a/+RZA0FMa3eELWz+pPw++D4s9PbO5VXodHiLPDUAqK1kwhrZUPj J/7DfED/c6CSnlFwT6CjFfjD3DDZZ3KB3GGAJHaYL/tePIPLdn0WTT8DY4Ox1o2xryXg qs2Q== X-Gm-Message-State: AOAM5333mRIaI0i0K2Dyy/hp2/0p1TwOQ9ZUZ+FOSxG9JZUaEEYK14Xl ItCepffslMEYH4xKswNj9i0y1UrKkw7CLw== X-Google-Smtp-Source: ABdhPJyLUEBeODqTjFC53Oc+crNBkTgeTVenagucP4eGjMcprJJyJm91+2HKtUIu6CUXnyEn+euR7g== X-Received: by 2002:a63:5924:: with SMTP id n36mr5436920pgb.183.1616525948477; Tue, 23 Mar 2021 11:59:08 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id b10sm16132325pgm.76.2021.03.23.11.59.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 11:59:08 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v10 4/9] Bluetooth: btintel: Consolidate intel_version parsing Date: Tue, 23 Mar 2021 11:58:59 -0700 Message-Id: <20210323185904.3372987-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210323185904.3372987-1-luiz.dentz@gmail.com> References: <20210323185904.3372987-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This moves version checks of intel_version() to btintel_version_info(). Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel.c | 36 ++++++++++++++++++++++++++++++++++-- drivers/bluetooth/btintel.h | 7 ++++--- drivers/bluetooth/btusb.c | 12 ++++-------- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index bb2546c4374a..bddaa4f32566 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c @@ -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); diff --git a/drivers/bluetooth/btintel.h b/drivers/bluetooth/btintel.h index 56f30eaa1e3c..d184064a5e7c 100644 --- a/drivers/bluetooth/btintel.h +++ b/drivers/bluetooth/btintel.h @@ -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, diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index f163f174185b..2d3498b74296 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -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, ¶ms, &boot_param); if (err) return err; From patchwork Tue Mar 23 18:59:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 12159109 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1C58C433E2 for ; Tue, 23 Mar 2021 18:59:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C2535619C8 for ; Tue, 23 Mar 2021 18:59:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232795AbhCWS7S (ORCPT ); Tue, 23 Mar 2021 14:59:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232711AbhCWS7K (ORCPT ); Tue, 23 Mar 2021 14:59:10 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34B45C061574 for ; Tue, 23 Mar 2021 11:59:10 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id u19so12677529pgh.10 for ; Tue, 23 Mar 2021 11:59:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ufsDvRHRPhFwKqbIwatE4/dZRCGgv5SmrtuZPyIPUwM=; b=QPDX+0basiVdWz4/a86Fm9HVZJXV2mUjC+46X1uC3BQsG0bBvu9B5n5UgAOcHHleb3 iQfVk/4vbdEXv9Q3PsQUAn2Dzm6G4ze2RTD5Jy2eCu2TU85uKe1UBrdh8M2MJnf8G0Pj HayiBrXesIrbjrZ7XEPPJPFNCaW6JrutwaSHfPYs7ErSCpI+URcjZwiThYQ+qguGlTdv JRgNlXIvZ5iF88rVaXe5ERNln8bJe0su/w8YfBbfwQOm05X7M8AOpTq8JZalVIaBWCBY rZkJsb7nkWV8DhSnLyUNHTaDh52HjU+zDPfUjZD+Li7ervuakJfCtZy6/tINynWR0sh8 A6Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ufsDvRHRPhFwKqbIwatE4/dZRCGgv5SmrtuZPyIPUwM=; b=n05TtwzY5X2qFbHlQ6dXxB6UCqiGvuMU289iJVfG2ooVqK+XxI4kBfxpRNCrychO3C +MhkixYkgx040cebX9Z2ERvD05SP1XfCJ4vJ8Fndc4nhDqC7l5O1IifYK2PyeAk/SoLk p86i4JHb2hZ0pZ1gELLvxhV9CfWvxlG47/Bw57nkN5O9ViYjn4Kze/1G+ehfOR7tcnN9 1N32AxmWNfoagE/lu0o26lvDouAMmqxRYKclUv9NvqoqUGI+HPtsFW/BmV/WlC3Y4ZAQ vyqg0hAXRaSTy/XDQeDaSRH88hp3YiHHST0C5qJUQ4bk4VByJo7o+859t0617FsG9ENF 8NQw== X-Gm-Message-State: AOAM533BW4PQvKqaNu7kcf1JdnpVogA5/gE2k/MIsqmz6ZeII399goE5 ZL77jFonsAbG5Mwy+dcqF/pbUy5z9DGxFg== X-Google-Smtp-Source: ABdhPJwsrnkzlSKa5meMbTYtS0T/ZgOH+tyHFymFY4wipfghJAATv2O4Eqc2O0T3MO2ZrFu+izxXzg== X-Received: by 2002:a17:902:ce8d:b029:e4:bc38:c4 with SMTP id f13-20020a170902ce8db02900e4bc3800c4mr7254761plg.48.1616525949379; Tue, 23 Mar 2021 11:59:09 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id b10sm16132325pgm.76.2021.03.23.11.59.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 11:59:08 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v10 5/9] Bluetooth: btusb: Consolidate code for waiting firmware download Date: Tue, 23 Mar 2021 11:59:00 -0700 Message-Id: <20210323185904.3372987-5-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210323185904.3372987-1-luiz.dentz@gmail.com> References: <20210323185904.3372987-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This moves duplicated code for waiting firmware download completion to a function that can be reused. Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btusb.c | 108 +++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 60 deletions(-) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 2d3498b74296..dcdc434cf794 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -2447,6 +2447,44 @@ static void btusb_setup_intel_newgen_get_fw_name(const struct intel_version_tlv suffix); } +static int btusb_download_wait(struct hci_dev *hdev, ktime_t calltime, int msec) +{ + struct btusb_data *data = hci_get_drvdata(hdev); + ktime_t delta, rettime; + unsigned long long duration; + int err; + + set_bit(BTUSB_FIRMWARE_LOADED, &data->flags); + + bt_dev_info(hdev, "Waiting for firmware download to complete"); + + err = wait_on_bit_timeout(&data->flags, BTUSB_DOWNLOADING, + TASK_INTERRUPTIBLE, + msecs_to_jiffies(msec)); + if (err == -EINTR) { + bt_dev_err(hdev, "Firmware loading interrupted"); + return err; + } + + if (err) { + bt_dev_err(hdev, "Firmware loading timeout"); + return -ETIMEDOUT; + } + + if (test_bit(BTUSB_FIRMWARE_FAILED, &data->flags)) { + bt_dev_err(hdev, "Firmware loading failed"); + return -ENOEXEC; + } + + rettime = ktime_get(); + delta = ktime_sub(rettime, calltime); + duration = (unsigned long long)ktime_to_ns(delta) >> 10; + + bt_dev_info(hdev, "Firmware loaded in %llu usecs", duration); + + return 0; +} + static int btusb_intel_download_firmware_newgen(struct hci_dev *hdev, struct intel_version_tlv *ver, u32 *boot_param) @@ -2455,6 +2493,7 @@ static int btusb_intel_download_firmware_newgen(struct hci_dev *hdev, char fwname[64]; int err; struct btusb_data *data = hci_get_drvdata(hdev); + ktime_t calltime; if (!ver || !boot_param) return -EINVAL; @@ -2502,6 +2541,8 @@ static int btusb_intel_download_firmware_newgen(struct hci_dev *hdev, goto done; } + calltime = ktime_get(); + set_bit(BTUSB_DOWNLOADING, &data->flags); /* Start firmware downloading and get boot parameter */ @@ -2522,9 +2563,6 @@ static int btusb_intel_download_firmware_newgen(struct hci_dev *hdev, btintel_reset_to_bootloader(hdev); goto done; } - set_bit(BTUSB_FIRMWARE_LOADED, &data->flags); - - bt_dev_info(hdev, "Waiting for firmware download to complete"); /* Before switching the device into operational mode and with that * booting the loaded firmware, wait for the bootloader notification @@ -2537,26 +2575,9 @@ static int btusb_intel_download_firmware_newgen(struct hci_dev *hdev, * and thus just timeout if that happens and fail the setup * of this device. */ - err = wait_on_bit_timeout(&data->flags, BTUSB_DOWNLOADING, - TASK_INTERRUPTIBLE, - msecs_to_jiffies(5000)); - if (err == -EINTR) { - bt_dev_err(hdev, "Firmware loading interrupted"); - goto done; - } - - if (err) { - bt_dev_err(hdev, "Firmware loading timeout"); - err = -ETIMEDOUT; + err = btusb_download_wait(hdev, calltime, 5000); + if (err == -ETIMEDOUT) btintel_reset_to_bootloader(hdev); - goto done; - } - - if (test_bit(BTUSB_FIRMWARE_FAILED, &data->flags)) { - bt_dev_err(hdev, "Firmware loading failed"); - err = -ENOEXEC; - goto done; - } done: release_firmware(fw); @@ -2572,6 +2593,7 @@ static int btusb_intel_download_firmware(struct hci_dev *hdev, char fwname[64]; int err; struct btusb_data *data = hci_get_drvdata(hdev); + ktime_t calltime; if (!ver || !params) return -EINVAL; @@ -2676,6 +2698,8 @@ static int btusb_intel_download_firmware(struct hci_dev *hdev, goto done; } + calltime = ktime_get(); + set_bit(BTUSB_DOWNLOADING, &data->flags); /* Start firmware downloading and get boot parameter */ @@ -2694,9 +2718,6 @@ static int btusb_intel_download_firmware(struct hci_dev *hdev, btintel_reset_to_bootloader(hdev); goto done; } - set_bit(BTUSB_FIRMWARE_LOADED, &data->flags); - - bt_dev_info(hdev, "Waiting for firmware download to complete"); /* Before switching the device into operational mode and with that * booting the loaded firmware, wait for the bootloader notification @@ -2709,26 +2730,9 @@ static int btusb_intel_download_firmware(struct hci_dev *hdev, * and thus just timeout if that happens and fail the setup * of this device. */ - err = wait_on_bit_timeout(&data->flags, BTUSB_DOWNLOADING, - TASK_INTERRUPTIBLE, - msecs_to_jiffies(5000)); - if (err == -EINTR) { - bt_dev_err(hdev, "Firmware loading interrupted"); - goto done; - } - - if (err) { - bt_dev_err(hdev, "Firmware loading timeout"); - err = -ETIMEDOUT; + err = btusb_download_wait(hdev, calltime, 5000); + if (err == -ETIMEDOUT) btintel_reset_to_bootloader(hdev); - goto done; - } - - if (test_bit(BTUSB_FIRMWARE_FAILED, &data->flags)) { - bt_dev_err(hdev, "Firmware loading failed"); - err = -ENOEXEC; - goto done; - } done: release_firmware(fw); @@ -2755,8 +2759,6 @@ static int btusb_setup_intel_new(struct hci_dev *hdev) */ boot_param = 0x00000000; - calltime = ktime_get(); - /* Read the Intel version information to determine if the device * is in bootloader mode or if it already has operational firmware * loaded. @@ -2780,12 +2782,6 @@ static int btusb_setup_intel_new(struct hci_dev *hdev) if (ver.fw_variant == 0x23) goto finish; - rettime = ktime_get(); - delta = ktime_sub(rettime, calltime); - duration = (unsigned long long) ktime_to_ns(delta) >> 10; - - bt_dev_info(hdev, "Firmware loaded in %llu usecs", duration); - calltime = ktime_get(); set_bit(BTUSB_BOOTING, &data->flags); @@ -2903,8 +2899,6 @@ static int btusb_setup_intel_newgen(struct hci_dev *hdev) */ boot_param = 0x00000000; - calltime = ktime_get(); - /* Read the Intel version information to determine if the device * is in bootloader mode or if it already has operational firmware * loaded. @@ -2928,12 +2922,6 @@ static int btusb_setup_intel_newgen(struct hci_dev *hdev) if (version.img_type == 0x03) goto finish; - rettime = ktime_get(); - delta = ktime_sub(rettime, calltime); - duration = (unsigned long long)ktime_to_ns(delta) >> 10; - - bt_dev_info(hdev, "Firmware loaded in %llu usecs", duration); - calltime = ktime_get(); set_bit(BTUSB_BOOTING, &data->flags); From patchwork Tue Mar 23 18:59:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 12159115 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B601C433E1 for ; Tue, 23 Mar 2021 18:59:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2DE06619C9 for ; Tue, 23 Mar 2021 18:59:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232800AbhCWS7S (ORCPT ); Tue, 23 Mar 2021 14:59:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232734AbhCWS7L (ORCPT ); Tue, 23 Mar 2021 14:59:11 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F3AFC061574 for ; Tue, 23 Mar 2021 11:59:11 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id y5so15284495pfn.1 for ; Tue, 23 Mar 2021 11:59:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=jyJY6fTBeeDElTRy5LQwXAFLN7zjYr+7ncEfoPRBoc0=; b=pIC6zFzlMpxF1XkYKF9aAtRTAbI84m9uxIac+/j1qxuGWhQ3m6UQ0wE1mGEkVyotSM ohxJLk7krHoABnAKK63czKPZjnIVlQB4AuRqTOviaZOs4lm28nhRRgMbKPWZ7rxEv4Kt XJv5Pk9xwKhJB0RtmcsNf1DbEkcs2U6IW2HhZYxFppQF1Y0TkrKJJ+v4R/lm5bbf3ICW jFInNuGJkDzbXbLxcBAHim+EOMJbq7c6Jz6T9/Wv0IkztfboGKh7UUHmG/+bsAa1L83A /Wlgr+eJZbYM9ioCE6Bdc+oQa2vJD/RrCTCJDCCcws7dBGMIA5xkYZEB7VJZsEmX+ykD eY7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jyJY6fTBeeDElTRy5LQwXAFLN7zjYr+7ncEfoPRBoc0=; b=nWt3+vNmzPtAJZ3KjHrXPwYU7G3vNnaaA6ZRcmWgteDHdlhKkj7YKtZMGcb3vEWBl7 Iv7yrx0ugpJw6SFrXoYGnWXnmmJReed/c4EtFMqCmlOjHeCuNY1QCg7lQfSkFeRPkE6P zneEdBWen0Cu+8SYiL/cmscZsHynqYeuUdMS8UHe29py8H+TpBLlT6au5Ejb4i4iX5iG biRZzhTWXt8h5jB3ROHOold6NruYhwHBCpUOQ20wqW5ftVIk9959QjGDW8G60+hjzgdF d9sDJ2McNI45VQqrrd/rnP4MznngHEcxjlaCnZFUjo/XPJNWYTzy573z/P+m1xPgqdlz TpJA== X-Gm-Message-State: AOAM532e+fE7DcpDn5NSMPP5zkqfq5LOaR9D4MY8RChmnCOP5I+nAaPj kUF458q6v8F4eoRKDqo6HJck5rz6bot8sQ== X-Google-Smtp-Source: ABdhPJzXt+wCmwKL3OejGeWbm6kXCWFQJdlx0bwiI8OEU8SlcQ9cxJ66OPYAdVOpQ3j3EAbovjlojw== X-Received: by 2002:a63:520e:: with SMTP id g14mr5139920pgb.350.1616525950390; Tue, 23 Mar 2021 11:59:10 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id b10sm16132325pgm.76.2021.03.23.11.59.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 11:59:09 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v10 6/9] Bluetooth: btusb: Consolidate code for waiting firmware to boot Date: Tue, 23 Mar 2021 11:59:01 -0700 Message-Id: <20210323185904.3372987-6-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210323185904.3372987-1-luiz.dentz@gmail.com> References: <20210323185904.3372987-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This moves duplicated code for waiting firmware download completion to a function that can be reused. Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btusb.c | 148 +++++++++++++++++--------------------- 1 file changed, 66 insertions(+), 82 deletions(-) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index dcdc434cf794..eb250f533265 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -2739,6 +2739,68 @@ static int btusb_intel_download_firmware(struct hci_dev *hdev, return err; } +static int btusb_boot_wait(struct hci_dev *hdev, ktime_t calltime, int msec) +{ + struct btusb_data *data = hci_get_drvdata(hdev); + ktime_t delta, rettime; + unsigned long long duration; + int err; + + bt_dev_info(hdev, "Waiting for device to boot"); + + err = wait_on_bit_timeout(&data->flags, BTUSB_BOOTING, + TASK_INTERRUPTIBLE, + msecs_to_jiffies(msec)); + if (err == -EINTR) { + bt_dev_err(hdev, "Device boot interrupted"); + return -EINTR; + } + + if (err) { + bt_dev_err(hdev, "Device boot timeout"); + return -ETIMEDOUT; + } + + rettime = ktime_get(); + delta = ktime_sub(rettime, calltime); + duration = (unsigned long long) ktime_to_ns(delta) >> 10; + + bt_dev_info(hdev, "Device booted in %llu usecs", duration); + + return 0; +} + +static int btusb_intel_boot(struct hci_dev *hdev, u32 boot_addr) +{ + struct btusb_data *data = hci_get_drvdata(hdev); + ktime_t calltime; + int err; + + calltime = ktime_get(); + + set_bit(BTUSB_BOOTING, &data->flags); + + err = btintel_send_intel_reset(hdev, boot_addr); + if (err) { + bt_dev_err(hdev, "Intel Soft Reset failed (%d)", err); + btintel_reset_to_bootloader(hdev); + return err; + } + + /* The bootloader will not indicate when the device is ready. This + * is done by the operational firmware sending bootup notification. + * + * Booting into operational firmware should not take longer than + * 1 second. However if that happens, then just fail the setup + * since something went wrong. + */ + err = btusb_boot_wait(hdev, calltime, 1000); + if (err == -ETIMEDOUT) + btintel_reset_to_bootloader(hdev); + + return err; +} + static int btusb_setup_intel_new(struct hci_dev *hdev) { struct btusb_data *data = hci_get_drvdata(hdev); @@ -2746,8 +2808,6 @@ static int btusb_setup_intel_new(struct hci_dev *hdev) struct intel_boot_params params; u32 boot_param; char ddcname[64]; - ktime_t calltime, delta, rettime; - unsigned long long duration; int err; struct intel_debug_features features; @@ -2782,46 +2842,9 @@ static int btusb_setup_intel_new(struct hci_dev *hdev) if (ver.fw_variant == 0x23) goto finish; - calltime = ktime_get(); - - set_bit(BTUSB_BOOTING, &data->flags); - - err = btintel_send_intel_reset(hdev, boot_param); - if (err) { - bt_dev_err(hdev, "Intel Soft Reset failed (%d)", err); - btintel_reset_to_bootloader(hdev); + err = btusb_intel_boot(hdev, boot_param); + if (err) return err; - } - - /* The bootloader will not indicate when the device is ready. This - * is done by the operational firmware sending bootup notification. - * - * Booting into operational firmware should not take longer than - * 1 second. However if that happens, then just fail the setup - * since something went wrong. - */ - bt_dev_info(hdev, "Waiting for device to boot"); - - err = wait_on_bit_timeout(&data->flags, BTUSB_BOOTING, - TASK_INTERRUPTIBLE, - msecs_to_jiffies(1000)); - - if (err == -EINTR) { - bt_dev_err(hdev, "Device boot interrupted"); - return -EINTR; - } - - if (err) { - bt_dev_err(hdev, "Device boot timeout"); - btintel_reset_to_bootloader(hdev); - return -ETIMEDOUT; - } - - rettime = ktime_get(); - delta = ktime_sub(rettime, calltime); - duration = (unsigned long long) ktime_to_ns(delta) >> 10; - - bt_dev_info(hdev, "Device booted in %llu usecs", duration); clear_bit(BTUSB_BOOTLOADER, &data->flags); @@ -2885,8 +2908,6 @@ static int btusb_setup_intel_newgen(struct hci_dev *hdev) struct btusb_data *data = hci_get_drvdata(hdev); u32 boot_param; char ddcname[64]; - ktime_t calltime, delta, rettime; - unsigned long long duration; int err; struct intel_debug_features features; struct intel_version_tlv version; @@ -2922,46 +2943,9 @@ static int btusb_setup_intel_newgen(struct hci_dev *hdev) if (version.img_type == 0x03) goto finish; - calltime = ktime_get(); - - set_bit(BTUSB_BOOTING, &data->flags); - - err = btintel_send_intel_reset(hdev, boot_param); - if (err) { - bt_dev_err(hdev, "Intel Soft Reset failed (%d)", err); - btintel_reset_to_bootloader(hdev); + err = btusb_intel_boot(hdev, boot_param); + if (err) return err; - } - - /* The bootloader will not indicate when the device is ready. This - * is done by the operational firmware sending bootup notification. - * - * Booting into operational firmware should not take longer than - * 1 second. However if that happens, then just fail the setup - * since something went wrong. - */ - bt_dev_info(hdev, "Waiting for device to boot"); - - err = wait_on_bit_timeout(&data->flags, BTUSB_BOOTING, - TASK_INTERRUPTIBLE, - msecs_to_jiffies(1000)); - - if (err == -EINTR) { - bt_dev_err(hdev, "Device boot interrupted"); - return -EINTR; - } - - if (err) { - bt_dev_err(hdev, "Device boot timeout"); - btintel_reset_to_bootloader(hdev); - return -ETIMEDOUT; - } - - rettime = ktime_get(); - delta = ktime_sub(rettime, calltime); - duration = (unsigned long long)ktime_to_ns(delta) >> 10; - - bt_dev_info(hdev, "Device booted in %llu usecs", duration); clear_bit(BTUSB_BOOTLOADER, &data->flags); From patchwork Tue Mar 23 18:59:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 12159117 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 563CAC433E6 for ; Tue, 23 Mar 2021 18:59:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D65B619DA for ; Tue, 23 Mar 2021 18:59:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232803AbhCWS7T (ORCPT ); Tue, 23 Mar 2021 14:59:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232742AbhCWS7N (ORCPT ); Tue, 23 Mar 2021 14:59:13 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07A4EC061574 for ; Tue, 23 Mar 2021 11:59:12 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id b184so15277472pfa.11 for ; Tue, 23 Mar 2021 11:59:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Ut7jlS+PqFbwTOsiLm+t82r8Nt+s/HeE/xV+iBk2Vfs=; b=rH/XHSE1YwJRQ5Isl05asIeeCrMDzOnbihD17GdmfjlJefefHvROQPktOHTU82Uoqa C8qII05BZHOmlE6xV6HJ8WYG24QJRwvpSvWkjhyd+EEQ928RK5p7M90msioSctfLLuca PghNnD+oAfrISogC0Cep2DCbNFleUodmyDW5ujHNu6HCxXyZ1emUTqaoPtrO1ra3I6uK EIMDlaJQRrRMB57Akpp+VAO/WNSNchfqculAe5cJ7/54VC71odWXEH4xXiuoFlrPxZGu wBJn4AuWVf+ggQ5g0SEyA8zmUdRsugrnmaqcgfpuAw6jeWWx4i1fT8LygKZSMd5p7Q4x McGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ut7jlS+PqFbwTOsiLm+t82r8Nt+s/HeE/xV+iBk2Vfs=; b=hyvkRBBe7Tig2LHoBXViZBlRcdoZhTKhSMcyQvyeHSNj78bLGaqJtl7ZaVbKolLHXy s3HX3B+mh/vD6xfsxJVywxEjhQ5zr5H2OyeoPMNtv2aKUAvijF3dGaP1QdcckdN5tN9N KDDW2wF0LTI9u3/aiXC8RydW2ySGVSIZfCKgn3bPtZdxwETO4fiBXNgdtmL1lGfu8rIU EVFkLWnxsxxpuRZkOqz5txtT0iqVw4u+EeGQgcPOf54MRGEqMrjxvxuIlo3cLHjSgijG PmE3O77kA8+cc3t4KChb+X5rtjCQwRfJZRT7aqPh1rKFWFoOyOe4wx6jUIKhJS/5uQAg XhIA== X-Gm-Message-State: AOAM531C3Nuo42sP1WzjlKL84wKMeAnNoksXqmihkcD1oHjMLWN4o30Z 7Os4PIKJK905zXsY2uUwXqkpqow5V7KBbA== X-Google-Smtp-Source: ABdhPJwJYlUeUe3T+HgMP6muqrOHSPzIq3RqlZ7r3/biyiLogSk5xNghKTvPB16EC/fHm8+G+TWw7g== X-Received: by 2002:a65:430b:: with SMTP id j11mr5395888pgq.143.1616525951318; Tue, 23 Mar 2021 11:59:11 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id b10sm16132325pgm.76.2021.03.23.11.59.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 11:59:10 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v10 7/9] Bluetooth: btintel: Reorganized bootloader mode tlv checks in intel_version_tlv parsing Date: Tue, 23 Mar 2021 11:59:02 -0700 Message-Id: <20210323185904.3372987-7-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210323185904.3372987-1-luiz.dentz@gmail.com> References: <20210323185904.3372987-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Lokendra Singh This moves limited_cce and sbe_type checks under bootloader during tlv parsing as operational firmware don't have access to these values. Any attempt to read such values in operational firmware will only fetch garbage data. Signed-off-by: Lokendra Singh Signed-off-by: Kiran K --- drivers/bluetooth/btintel.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index bddaa4f32566..4ddbf895c382 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c @@ -434,26 +434,26 @@ int btintel_version_info_tlv(struct hci_dev *hdev, struct intel_version_tlv *ver 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"; + /* 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; + } + bt_dev_info(hdev, "Device revision is %u", version->dev_rev_id); bt_dev_info(hdev, "Secure boot is %s", version->secure_boot ? "enabled" : "disabled"); From patchwork Tue Mar 23 18:59:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 12159121 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45CDEC433DB for ; Tue, 23 Mar 2021 19:00:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 197346198C for ; Tue, 23 Mar 2021 19:00:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232742AbhCWS7s (ORCPT ); Tue, 23 Mar 2021 14:59:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232741AbhCWS7N (ORCPT ); Tue, 23 Mar 2021 14:59:13 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7A8DC061763 for ; Tue, 23 Mar 2021 11:59:12 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id h3so15273058pfr.12 for ; Tue, 23 Mar 2021 11:59:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=mMJy1yhZReHkY2zk7BhuHTjzHoiiHD3MzV3UKZsessU=; b=LkAW2oTK/5McVOBC1oKMc/NjDZWWy+l6UA7fVcMQAEJ6aoxEG6+t9atdEHsb9/gy+Q SvjxBp7wDyobINLBlCVSk6mooN4wDFFNHhWTVZPfq87tG722ElaALQ/WNfpgvq+t9+/I xWDtqrCbv66xqQTvyalmYULjt+ybuuEH7TOcBOgNw1QCXIMpcrgD2yjbSdezHreNLLud KBSZGRKeNvo8voVCjY1Cd1/2oHCxdbEwj57RhtLKytonzFTH/ZbuM+WVzVAfRDpCu4cR VHdYGxxArqPxVeYokc/sZb7QyNn4RtHEiAM2aWCkbOKWgKsqMO4SuCaH/oG7wuMu8nb5 CNBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mMJy1yhZReHkY2zk7BhuHTjzHoiiHD3MzV3UKZsessU=; b=FX6NT+3pTJ2HZQULo19rXb5t/0SM7SnXQrWNzvrP+h2DpaxoUJiPe+IMmxHiqSuIBM 1YbWYxGXac9sFerRAVHnt+n78PPqzJdf10HMv6CiZN+q+Wik2hp7iN66E3tlv7CoB5vv l4ltOZ6tRld1c71Z2HFbA3ZdYUo5SiZ7F8DyGD7BTn4XKz10yX9gtWoqQSRx3XDSJjIv sxFhwosMD0iAbJqbGQaf/96PnBTu8PcMUYtTs78cBoczSPba5OsNi12X1IJHOaxmhO0q bJf0IOTZ5OS+7NjoZq7d4VkBxNznhA+db8XRd5yWmm9glADmCzIsCmPigPFxJlc6sZk6 nrtQ== X-Gm-Message-State: AOAM533xJnd4ZE7arN3uPLh/mPkJX1P/ZEy+VNWGycjCGkfY+oURP/1b NrAd2f7TbPmPdWo9edL3dcses9ojRTJeJw== X-Google-Smtp-Source: ABdhPJy/R7E86K84H51qYkof8Lsb6pNWVRmT7qqyQ8P3V8CguXjq5TD0wGYb+JiJV9UGlOEw/998+g== X-Received: by 2002:a63:fe56:: with SMTP id x22mr5172437pgj.329.1616525952158; Tue, 23 Mar 2021 11:59:12 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id b10sm16132325pgm.76.2021.03.23.11.59.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 11:59:11 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v10 8/9] Bluetooth: btintel: Collect tlv based active firmware build info in FW mode Date: Tue, 23 Mar 2021 11:59:03 -0700 Message-Id: <20210323185904.3372987-8-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210323185904.3372987-1-luiz.dentz@gmail.com> References: <20210323185904.3372987-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Lokendra Singh In Operational firmware mode, 'Minimum FW version' TLV ID is not available. So, we cannot fetch already running firmware info for comparison against another build. However, It can be collected using a combination of other TLV ID's information. Signed-off-by: Lokendra Singh --- drivers/bluetooth/btintel.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index 4ddbf895c382..6442acba76d1 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c @@ -537,12 +537,23 @@ int btintel_read_version_tlv(struct hci_dev *hdev, struct intel_version_tlv *ver version->img_type = tlv->val[0]; break; case INTEL_TLV_TIME_STAMP: + /* If image type is Operational firmware (0x03), then + * running FW Calendar Week and Year information can + * be extracted from Timestamp information + */ + version->min_fw_build_cw = tlv->val[0]; + version->min_fw_build_yy = tlv->val[1]; version->timestamp = get_unaligned_le16(tlv->val); break; case INTEL_TLV_BUILD_TYPE: version->build_type = tlv->val[0]; break; case INTEL_TLV_BUILD_NUM: + /* If image type is Operational firmware (0x03), then + * running FW build number can be extracted from the + * Build information + */ + version->min_fw_build_nn = tlv->val[0]; version->build_num = get_unaligned_le32(tlv->val); break; case INTEL_TLV_SECURE_BOOT: From patchwork Tue Mar 23 18:59:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 12159119 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36D47C433C1 for ; Tue, 23 Mar 2021 19:00:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F257E619A3 for ; Tue, 23 Mar 2021 19:00:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232598AbhCWS7r (ORCPT ); Tue, 23 Mar 2021 14:59:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232746AbhCWS7N (ORCPT ); Tue, 23 Mar 2021 14:59:13 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1821C061764 for ; Tue, 23 Mar 2021 11:59:13 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id y5so15284624pfn.1 for ; Tue, 23 Mar 2021 11:59:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=3tA1Um38m4hYMnv9CGiuJA7SkPRldGIsASeqovUw/Yg=; b=mSKNtZdNfji0zKO7l1792ESPrDU4DC1YWkrMTD0KG48LmeMATsSrDV31c+U41NAeKE GWW66LGL8r4I+ibqTjbuhjRFTRLy6sceenNKvi2pQIO1BeA/Tz32boxT/8kd4xVgfz4m mh6OjcKEo3VSQlawRjhQUF64FG8wQYs8eQVg2VeZgW0ptNT5OdPRgImIaibkEiOeVrbQ sX8COcQAQ3+1Kptv7E6RKEHKb8ZZPII7K7MqKKFCzJNYttGiMy52WB1L9uobcdbm8XVW /ByHKXvbf33rEh02/+QyDEoOhYznApPZYthnseLFHd6X6xFDDTquwhuQ4yWhZR191TXN A0+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3tA1Um38m4hYMnv9CGiuJA7SkPRldGIsASeqovUw/Yg=; b=MZtXwUINdUE/CoJ/U88kQEht5KV05W7WMEG2OjLUBPK+VFmYKCQ/kW9lRZR0CSZNRC wFlOOEwn1kXq2HZ9mkg8V4BCu3vcZqBAuKH7GJppv+HtvFRhgW9QGnJ0CrTZ2Cgxrkia OHfczeP3EOofVvP8nKimYAEZNBYWxgX1+W7QaYBnOY1wvdQQmqnqVtTQucMWvGIr/tRr QpEnsnJ2zs2VdSIpzN3rZJycmK/9Ti24g4g0m+p5h+sXd+YVVPh94FIUD5ml35rRneLA GSGTNC9w79750KY9uU9E9Aopt/f2APIrOiBA+0hfhtY2Z+/mIWlwWeFWNFv410jEM5Ky tqlg== X-Gm-Message-State: AOAM531XqO1o7nE0r6Lvk+gl36eQFecZ45mIblSzvVMGqvdoC59PuSot pp0f0vrk4bnBplXrpz+Ys5ktF9vom0sTsg== X-Google-Smtp-Source: ABdhPJz4BzKh2KvlmnRdYfQrYEH/bGMA8JP0QUPIXocfOuthO+Z/yTHxx/9PO7Pq46DPrNANJibbfQ== X-Received: by 2002:a65:6107:: with SMTP id z7mr5322160pgu.435.1616525952852; Tue, 23 Mar 2021 11:59:12 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id b10sm16132325pgm.76.2021.03.23.11.59.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 11:59:12 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v10 9/9] Bluetooth: btintel: Skip reading firmware file version while in bootloader mode Date: Tue, 23 Mar 2021 11:59:04 -0700 Message-Id: <20210323185904.3372987-9-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210323185904.3372987-1-luiz.dentz@gmail.com> References: <20210323185904.3372987-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Lokendra Singh This skips parsing the firmware version information from the firmware file while controller is in bootloader mode. As in bootloader mode, we are supposed to patch unconditionally. Signed-off-by: Lokendra Singh --- drivers/bluetooth/btintel.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index 6442acba76d1..e44b6993cf91 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c @@ -1031,6 +1031,10 @@ int btintel_download_firmware(struct hci_dev *hdev, /* Skip version checking */ break; default: + /* Skip reading firmware file version in bootloader mode */ + if (ver->fw_variant == 0x06) + break; + /* Skip download if firmware has the same version */ if (btintel_firmware_version(hdev, ver->fw_build_num, ver->fw_build_ww, ver->fw_build_yy, @@ -1070,15 +1074,19 @@ int btintel_download_firmware_newgen(struct hci_dev *hdev, int err; u32 css_header_ver; - /* Skip download if firmware has the same version */ - if (btintel_firmware_version(hdev, ver->min_fw_build_nn, - ver->min_fw_build_cw, ver->min_fw_build_yy, - fw, boot_param)) { - bt_dev_info(hdev, "Firmware already loaded"); - /* Return -EALREADY to indicate that firmware has already been - * loaded. - */ - return -EALREADY; + /* Skip reading firmware file version in bootloader mode */ + if (ver->img_type != 0x01) { + /* Skip download if firmware has the same version */ + if (btintel_firmware_version(hdev, ver->min_fw_build_nn, + ver->min_fw_build_cw, + ver->min_fw_build_yy, + fw, boot_param)) { + bt_dev_info(hdev, "Firmware already loaded"); + /* Return -EALREADY to indicate that firmware has + * already been loaded. + */ + return -EALREADY; + } } /* The firmware variant determines if the device is in bootloader