Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp375699pxb; Thu, 19 Nov 2020 03:42:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJxuIKF97NlGykG+8GzIY1qjwYjWAk3kJib62fwcYrAAwMaMi0txjQfRqbiydKp1VQCweWP3 X-Received: by 2002:a05:6402:38a:: with SMTP id o10mr7122091edv.349.1605786128760; Thu, 19 Nov 2020 03:42:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605786128; cv=none; d=google.com; s=arc-20160816; b=HYK6EGPsbGyWgOB+YJl9WEWHFD2GphOIGNiDNMjt/AUuIyZe1wM14pdtrCSrX9VKT0 zVAEad2q5mdeJAmKn/SRcPAzoyP47o9Wr6D77FE19glPZiw4hmW9QzuEFeVc41IUZ1Q/ D2cNNHYQe/na9K5H6ybih+g1X1sApYTVRH44VNKfqGg8QNhSbGRlpUM8pG7lgaPpzYYZ cL+7bmyfs/knefperxlS41A7UhNTA8nAD9TjpkfOIOkMmlY6d0Vk8BSGcFaq3fSkxymq i1NAvdxZCYnh5UuQDhWp7tzIfDhNfZL++0b06F+Lx/507ftWG55BKxGp55knIkljzXnB i4+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:ironport-sdr:ironport-sdr; bh=sf+TdLc1DK7HjpZveTF2cGatRKqwL+BSSnL56tTS/iE=; b=CMdNCTLukNzQ8uEKx3eYUokM3Hw833tbI0Tb14DjSYq5ieJEkxNEbVZSbzyi7lzKl8 Az4pmUgEhhn4CQRVQGB5XKE7a05S+DqnjCVzVhJn0cU8igzAWTJxlJn6r5DK82ENeNaY 9pEyHYrqSmfgTCoig7SnV3GXQAOM2es93euwd8lTQayRxQ0IN7yfXUDT2aWXvxFkSsXZ jQZdnRy7Eb7VgRf6wwGbQS6iTBTSE/CogO2RgzvBYRVVb35kuoZPxkVZHZzstgkE3GrQ EyezY0ztT8IB7RJ6/ebMoerO6xr9YVKyom1V29L5ziR1Jmzk2007Blt5xFq/t5ojp62+ FVhA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x16si18211717eds.110.2020.11.19.03.41.45; Thu, 19 Nov 2020 03:42:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726480AbgKSLh6 (ORCPT + 99 others); Thu, 19 Nov 2020 06:37:58 -0500 Received: from mga11.intel.com ([192.55.52.93]:21909 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726860AbgKSLh5 (ORCPT ); Thu, 19 Nov 2020 06:37:57 -0500 IronPort-SDR: xnQobeZUxSUZmFShceLshYvirVl0hudpDM2mNNg8xmuPcJmSitz6siLAjem8I4waAqu8ooP7wq LpFazdwjj8oQ== X-IronPort-AV: E=McAfee;i="6000,8403,9809"; a="167763759" X-IronPort-AV: E=Sophos;i="5.77,490,1596524400"; d="scan'208";a="167763759" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Nov 2020 03:37:57 -0800 IronPort-SDR: jE7fhHXxOC1/JdUmqy4zlbGqU4X+a0vdes9OVHBpFph5CwCSUOvO/T1xrIGQ7Yv+eGx4lvCGZd YqUvKKcvtPUQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,490,1596524400"; d="scan'208";a="325950043" Received: from intel-lenovo-legion-y540-15irh-pg0.iind.intel.com ([10.224.186.95]) by orsmga003.jf.intel.com with ESMTP; 19 Nov 2020 03:37:55 -0800 From: Kiran K To: linux-bluetooth@vger.kernel.org Cc: ravishankar.srivatsa@intel.com, chethan.tumkur.narayan@intel.com, sathish.narasimman@intel.com, Kiran K Subject: [PATCH v8 4/5] Bluetooth: btusb: Helper function to download firmware to Intel adapters Date: Thu, 19 Nov 2020 17:09:42 +0530 Message-Id: <20201119113943.13839-4-kiran.k@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201119113943.13839-1-kiran.k@intel.com> References: <20201119113943.13839-1-kiran.k@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Define a helper function to download firmware for new generation Intel controllers Signed-off-by: Kiran K --- drivers/bluetooth/btusb.c | 165 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 579dd1343057..b3d470ec2622 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -2398,6 +2398,167 @@ static void btusb_setup_intel_newgen_get_fw_name(const struct intel_version_tlv suffix); } +static int btusb_intel_download_firmware_newgen(struct hci_dev *hdev, + struct intel_version_tlv *ver, + u32 *boot_param) +{ + const struct firmware *fw; + char fwname[64]; + int err; + struct btusb_data *data = hci_get_drvdata(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 + * firmware. + * + * When the operational firmware is already present, then only + * the check for valid Bluetooth device address is needed. This + * determines if the device will be added as configured or + * unconfigured controller. + * + * It is not possible to use the Secure Boot Parameters in this + * case since that command is only available in bootloader mode. + */ + 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 + * 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. + */ + if (!bacmp(&ver->otp_bd_addr, BDADDR_ANY)) { + bt_dev_info(hdev, "No device address configured"); + set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); + } + + btusb_setup_intel_newgen_get_fw_name(ver, fwname, sizeof(fwname), "sfi"); + err = request_firmware(&fw, fwname, &hdev->dev); + if (err < 0) { + bt_dev_err(hdev, "Failed to load Intel firmware file (%d)", err); + return err; + } + + bt_dev_info(hdev, "Found device firmware: %s", fwname); + + if (fw->size < 644) { + bt_dev_err(hdev, "Invalid size of firmware file (%zu)", + fw->size); + err = -EBADF; + goto done; + } + + set_bit(BTUSB_DOWNLOADING, &data->flags); + + /* Start firmware downloading and get boot parameter */ + err = btintel_download_firmware_newgen(hdev, fw, boot_param, + INTEL_HW_VARIANT(ver->cnvi_bt), + ver->sbe_type); + if (err < 0) { + /* When FW download fails, send Intel Reset to retry + * FW download. + */ + 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 + * that all fragments have been successfully received. + * + * When the event processing receives the notification, then the + * BTUSB_DOWNLOADING flag will be cleared. + * + * The firmware loading should not take longer than 5 seconds + * 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; + 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); + return err; +} + static int btusb_intel_download_firmware(struct hci_dev *hdev, struct intel_version *ver, struct intel_boot_params *params, @@ -2766,6 +2927,10 @@ static int btusb_setup_intel_newgen(struct hci_dev *hdev) btintel_version_info_tlv(hdev, &version); + err = btusb_intel_download_firmware_newgen(hdev, &version, &boot_param); + if (err) + return err; + /* check if controller is already having an operational firmware */ if (version.img_type == 0x03) goto finish; -- 2.17.1