Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp614597pxu; Wed, 14 Oct 2020 09:18:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJnc33h4X07qlSBi3MgvVQM4jo9uD/OtwHOzugFZECADVojfvmJdy7yziGRQoVXCJ9W0UM X-Received: by 2002:a17:906:d8b6:: with SMTP id qc22mr6254522ejb.196.1602692299755; Wed, 14 Oct 2020 09:18:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602692299; cv=none; d=google.com; s=arc-20160816; b=J+7XnaoDtxTCRgOBW2yavzpKxrIGL8pPg6P//CNw4VjrpMrgotHLNRloJ+LP/LLSwP tNKLvr5pMwREmTNF42sQJbAVNaqvCz99iEOA/pVJVpB8FQgm1ZlmE/h2UMr1nM8hhEOH QhOx2IYjinFzd4Cgq2kQfyGVrIq2sAxOgtO6iCdxo3EwaLeExPlm89B7gapcH22rzX/+ E5Ty95D171D9tEnA0UjLlAhnugjpuU4SrMLh2oxsM1HKP7Hw4K3tRjPi0LIYcP0khlI8 moh95zLdPHT0ERrKsRs3tWAn4ic3r8EjfYC35W7JfVvLgdzAgs/4e2A5J25+g29PLRh9 sldQ== 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:dkim-signature; bh=F+XP8vytQQ4d23/wZSRYuvhzk147xUDt8MC3FL0S8ek=; b=rfvdE8vReJEpzFX13SMUzBHBbq0/iJ9/VoQHHTMUZFHSm3RxVT2lMigPxwVt+47z3P J7gaP2JJ8WL7g5bNSi7fBnnDR1mrT++wbmB4Y7CYbzAzmsYXr0hfHIuUqzyOEJSdlpQn /OObaXwOhMVU+Xdpjbkzs96O4es6B7vfeEo+KQUTu6aOC5nivYH9HLnzdFRefP9vLm6u 5hsOHs6CXkcu5x+jBkNLiIiD3YjemTaojs0aWyMrkS/QVKXb8sKZ/QU3pqv7Tk6+kpuS 9M7bN7+tF8j6fT6o4LFddS9ulL3UA+3xnp/ZJEG6gUts52T1WCDtIvCzlnWMukrAJmGG /+PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="AB8qfY/K"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t26si2540369eds.280.2020.10.14.09.17.37; Wed, 14 Oct 2020 09:18:19 -0700 (PDT) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b="AB8qfY/K"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730536AbgJNM3D (ORCPT + 99 others); Wed, 14 Oct 2020 08:29:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730520AbgJNM3D (ORCPT ); Wed, 14 Oct 2020 08:29:03 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F30E3C0613D2 for ; Wed, 14 Oct 2020 05:29:02 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id n14so1889189pff.6 for ; Wed, 14 Oct 2020 05:29:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=F+XP8vytQQ4d23/wZSRYuvhzk147xUDt8MC3FL0S8ek=; b=AB8qfY/KFi8P59Nzf8WhNjAXFTPvP2fMaJj6TpR3Hsj9ZSWq1eLehosfgqqB/0Hqw9 dBWQBYi9wgMPdSFt+ey+FaVNTevKC5zCpjho9z6mGNm6ssoY/HfOxWTOl1OJ0XjlyA14 CyemirvScAZ8m/s2dgqqhZjZstEDxOaVjQYMnvChNaDGvpTMY7rGmqSMTQYON+2GPtAH 30hrZ95Pb00WyjB8JWamNYW+9N4M139lwMdApulYD/TCDR3EmMNrCuUBw/pMHdRSRySr d2mYYY+og5iGm9Qzr7rPjA3/pjv++cEyDwEyKYxyJ842ewG5NU0SUq7G+WpErKUI9yyJ EE1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=F+XP8vytQQ4d23/wZSRYuvhzk147xUDt8MC3FL0S8ek=; b=T+dG3WO6Id0sCNFNWuiO3USVRKQsDHhIsJQIFizvZGN4cSKeKbXO1VarVTwLjLO8ju 0FfGB8Hv9f4R1FEzabJbrnU1ki9xHNjzmm+roRtHyVCWNC9wiWwaK+nCY+HpG1/snvHr 0IZlwr+m/A7xkMqwFFLGEt1HsubjL5te0SSJfGlJ0z6ybfjXIIe8jbpoHgyMrL9O79zV /rIoMoZVqfywLRuR2FUzwPMQ+L5SuuuvbkPYxH7DKp5peedzb23ChbhW1/gImK2zHB2E 54UGj9Qjthj+GWvF2qvwIEoUkOHuhZkbFcu9brJzBv82AMLguoH0uyJXH7wju7B1b1dK grZQ== X-Gm-Message-State: AOAM530nfsTfmqaxb15VUHV+GhZe8wH5jnl/QuCujyfv2O+J/zEGndE4 OeBemQWyDGeJOlcqLPJ/Gy5zAiTai2jF8j8c X-Received: by 2002:a63:c342:: with SMTP id e2mr3638654pgd.56.1602678542163; Wed, 14 Oct 2020 05:29:02 -0700 (PDT) Received: from localhost.localdomain ([122.179.122.132]) by smtp.gmail.com with ESMTPSA id r16sm2930000pjo.19.2020.10.14.05.29.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Oct 2020 05:29:01 -0700 (PDT) From: Kiran K X-Google-Original-From: Kiran K To: linux-bluetooth@vger.kernel.org Cc: sathish.narasimman@intel.com, chethan.tumkur.narayan@intel.com, ravishankar.srivatsa@intel.com, kiraank@gmail.com, Kiran K Subject: [PATCH v7 3/4] Bluetooth: btusb: Helper function to download firmware to Intel adapters Date: Wed, 14 Oct 2020 17:58:36 +0530 Message-Id: <1602678517-9912-3-git-send-email-kiran.k@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1602678517-9912-1-git-send-email-kiran.k@intel.com> References: <1602678517-9912-1-git-send-email-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 Reviewed-by: Chethan T N --- drivers/bluetooth/btusb.c | 165 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 164 insertions(+), 1 deletion(-) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index ac532dd..5d68cdb 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -2375,6 +2375,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, @@ -2743,7 +2904,9 @@ static int btusb_setup_intel_newgen(struct hci_dev *hdev) btintel_version_info_tlv(hdev, &version); - /* TODO: Plugin in code here to download firmware */ + 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) -- 2.7.4