Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1779804pxb; Wed, 10 Feb 2021 17:17:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJzJEVj2mnj9fG42a3bGnCpZYF9B2DSCLBf9dzHEGXPVNEwE823E1e2bstB/aOe/D6stQ9aG X-Received: by 2002:a17:906:16c6:: with SMTP id t6mr5573323ejd.102.1613006226358; Wed, 10 Feb 2021 17:17:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613006226; cv=none; d=google.com; s=arc-20160816; b=0Onl0IRm7NYAMDMLDdi/L3OjZuLIsgknvxPXvmGlGd79JuFRCh7H4RnoXKrKFVQFzl b02uXZOikUYHsP26HURIGt12UgGb2u3NCRSKG+sOC6pPC4NIFpwnWN4itZi/LfRtx7cr DF93J+u5C02bVnqxF73UjEebXoNAZkKeZmmYXoqBXG3a9suzQT6k9z77qmlpETDJesWB yB52y5wlw1Cr4x4MoNijo9LutIBoYyTIX/gqHGF/z6KlsLsKj7PAj2AWELPl7tmKTlS7 wWt4PCya+AtLNYKRdfxah7mDjUDHdzJGwais20/Drsjox/AAwihekUjPhRyQDybVjlON NfwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=VmNbal+6pTvzxSQV2RErY1Ip55BmzrxOqTRVYU1f9rw=; b=s073Gt9l9MVOGyyzghaLXuKCkBfpRLyXGDForwbSUdYnryGqCJMUrASNM68Ju1ozTq Q1wSswVAVHN3E6mFI60fC4a4Cdp1g5imhSKJzdS04xGWKAGTLk3FJye2T2NGdJRzoF0X CqUmJhgifMTPhs//LajZO+lLcR42plAAcYT55kiSJP8BrduxqhBhZ/ngBLQV5ITEQo0N kCigK2ZPRwdSDNnDuu+TFemb4WjDnPshwPv9WnG8i2+pvpCdZQVHxSrtHEl0UEK7psli 4wgC5/kVFlE4Q+zNlSck0m9jYLC3M1cdt7bX4P9581ld2qGRL7Vq6Lh2y5w3G/AHT/I8 quBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CVxqMLIs; 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 f11si2512428ejw.77.2021.02.10.17.15.14; Wed, 10 Feb 2021 17:17:06 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CVxqMLIs; 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 S230307AbhBKBJq (ORCPT + 99 others); Wed, 10 Feb 2021 20:09:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230098AbhBKBJp (ORCPT ); Wed, 10 Feb 2021 20:09:45 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D139C061788 for ; Wed, 10 Feb 2021 17:09:05 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id q72so2272678pjq.2 for ; Wed, 10 Feb 2021 17:09:05 -0800 (PST) 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=VmNbal+6pTvzxSQV2RErY1Ip55BmzrxOqTRVYU1f9rw=; b=CVxqMLIsGPQYqkhW/SGmH+1m5y384etzDsfDQ68VdQ+bimud650ydbDJIOMZU1bjDP GnfFI5Ydzyh7yIE0Sfm7KNlTlu2hNQnMSfkLZ94PBfImbYDPk5PowjNwcIey1iNnR/x1 wtXtWX0gukiN2pzrEaxH11TgrbMZhP4wxYB3907glANc4rOPt3zofNFcO5WiCu/ZY4E3 33RZxbmUIzMmGxgcU0CpFICBGnX2vc9/2ntrvxuIeedjg+WtMGdFzolLqyBvoSYbCiye m7lmAA0q+YZ/zn9IHnhva420vnqH68zqhCUV4F8sITxOc3hMXZiDUI1VBxS+XG9KbD9e K1Hg== 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=VmNbal+6pTvzxSQV2RErY1Ip55BmzrxOqTRVYU1f9rw=; b=cWNnmB1OkOjYmlO0EcUotkixZ5BV+oWQRrTi3OtpCSUpX0GLv6yOPk3NXpWxCjs74d NKBQ9ESQlEvmDZBxmWdeJPl4A1D7w3+OVpxDhHoZ1dcM8pnhbOKPg05YRva+POaDHxtI 5zVUVBa0Q+wRM2zbR42AS7vMIK27laVtadOJOYjeUGD9Cojy8oXLzrCFC98PEAsqGc4S oaej/2atwT4P88FRq5IL4Is3dyweHGQ5DN+jZd91yIw2Q3smmp2g7MjFXR3nIf/kuGh6 S760A/1/eJL9ozpvd7h91SHw25MXLZPIFNQNgdrBcbEvNrrim2vs7kV8EFMUwn/YZojK WWuQ== X-Gm-Message-State: AOAM533KjpMMSeHQTL1FQdAqoOD0etSLc1SyaEBRb52hfbOiFflRTM24 84SXLg737UBjaAIH22CcobxmJlJQBaxFkQ== X-Received: by 2002:a17:90b:14cf:: with SMTP id jz15mr1552499pjb.180.1613005744861; Wed, 10 Feb 2021 17:09:04 -0800 (PST) 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 lf4sm3141319pjb.0.2021.02.10.17.09.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Feb 2021 17:09:04 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v8 5/6] Bluetooth: btusb: Consolidate code for waiting firmware download Date: Wed, 10 Feb 2021 17:08:59 -0800 Message-Id: <20210211010900.2326531-5-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210211010900.2326531-1-luiz.dentz@gmail.com> References: <20210211010900.2326531-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 to complete to a function that can then 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 1f2b74eaaccf..8d343bf33438 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -2514,6 +2514,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) @@ -2522,6 +2560,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; @@ -2568,6 +2607,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 */ @@ -2588,9 +2629,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 @@ -2603,26 +2641,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); @@ -2638,6 +2659,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; @@ -2741,6 +2763,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 */ @@ -2759,9 +2783,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 @@ -2774,26 +2795,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); @@ -2820,8 +2824,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. @@ -2845,12 +2847,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); @@ -2967,8 +2963,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. @@ -2992,12 +2986,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); -- 2.26.2