Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1737093pxb; Wed, 10 Feb 2021 15:56:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJwm3to9y0Tgo2QPkwXJOTTWLbWE1MT/WBMD2GEwaQ2zj++hykqWqQvV1Dz5T7ZPvUqZQB/X X-Received: by 2002:a17:906:2898:: with SMTP id o24mr5356464ejd.215.1613001408781; Wed, 10 Feb 2021 15:56:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613001408; cv=none; d=google.com; s=arc-20160816; b=0271v9hi/X2jCfTp+CqEa+sB3SzBkZIEMl28rQVo3lETUY5MVziNRvEl/aFOH+kzBV bR+Yu86Zh+DpyIpsBqtouVg9rCe36dHEcYzqSN2pMLvxLmF9weAoD7vtZgkVTGrT6FZk uP2occPqWMhejJqhgW1tO6TF8LqJD4tw4Xif3QGiLBETvVgDNMSwdWiE+9lzqp8BdMUL 3X157iAdCn1/DLGQuGLEO0J/aMvwtts0oRfMPsV7oGwEazYTSPlZAyV1yR+EVfbzzFuJ T81jSF0SN4pr27Jr1RN8wPCIylgt95X0Aye18pwcLf4oAH58ypbp6eL80CjnJmys2kHu GAsg== 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=dLB7vhC9uuiz026hgr1eH1jbQMXLdTjovN95ZprIn4s=; b=lzw7CX5jA3KIWGMaJdGAhJkiE0pviWPR7HHutCaD1DJXwAZgPOyRvGjStTx/Qa8dLy c6yl73wm1gNeQ1oq7zB9n60Swq8id8RrF0S90BVLgTqNSX+Qaiz+RKtK4R8xRWoBbQBE PFG7OeUrQlYjQuLLOsLx0IpR7a4bnse2EeUcTnjBOSRcW5zKBo0bMtffA+H0pvZwB4+/ +s7xAkL5BUHYgXCpa9G3Yihmj+mW0lIJ7E5+HoxrV4c+qupWi2lF1MevwfhFufeX+9Z5 iDu2Fa1s3ojbDSYrgXndE1rRiCL5Xv+gYaUgX1rQQEJTzAvGj1uP8p8joK8L2iSUxRqA mCXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iToV773m; 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 ds6si2287686ejc.350.2021.02.10.15.55.59; Wed, 10 Feb 2021 15:56:48 -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=iToV773m; 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 S233972AbhBJXqo (ORCPT + 99 others); Wed, 10 Feb 2021 18:46:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233971AbhBJXqn (ORCPT ); Wed, 10 Feb 2021 18:46:43 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 810F6C06178C for ; Wed, 10 Feb 2021 15:45:55 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id a24so217075plm.11 for ; Wed, 10 Feb 2021 15:45:55 -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=dLB7vhC9uuiz026hgr1eH1jbQMXLdTjovN95ZprIn4s=; b=iToV773m1RBS2kQ9mC/dS+OeMaLITk6tT5qtkWchelpwgIYtfYULQ9Lxq6fR2KDOlO gKlVMeveCCbHy95NNLuoGxbm1+zNBjKGuXnI6NSXD+/O+Rwy79xJX2h56W0HVjehJNAt IokmkT9Xh09i2vrboP9wxzrCX4affOUra7O7nAXMdYq2RHxRfZA8rLry/16+o0zuuVR2 XufN/NecttXdn59yL4ycUE/zKVEwK+klRQyzuvoIiXfj9vy7l++dUUVqkZ4CFYMB4hnU EtHVutfGn2kQKnoP535zENrnLH95spwWcA03lZwpy069kZaAizin0Gb7pugF96gJy8Dj JUdg== 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=dLB7vhC9uuiz026hgr1eH1jbQMXLdTjovN95ZprIn4s=; b=Gxdo9s15kRYBx3zQQIRZw/vhyOr/ACTmuk6ZVBZyQblWy77O0uoQ/As7jKFwRdRC8n zVK3IPylTIia6RLPOW2YsfEFj61+duK6LhyB4yK8dZ9sPxbglbU6j8Gcm8+dTDNq/o5q S1ZMGxbrS0AE6dbooNzL6Yj9n+NzNrdt8Fox/sENy2txw3Sxlxvfrxeo9ZIjvKZnSjX8 ccgKIutaw3T/U57c58YZe+hvN6ygQyDQ+NknRZn9ZVhyC6iVeUfLfI3f7E/aXarb1pb1 OXdinILZgSORgAtMeR7OMmA5PUt6/6W/Dz3U/mWaLGuynPh1Xl9gvzmTWXScwPi9/LXp NqsQ== X-Gm-Message-State: AOAM530mom+vqM+I+pRDetNuOw/L4VYPMtqpNA7qImdWL3L1IJKZjbe5 +4UqLk3nJpTOtRP5ZatO4JFAYO0hNspnDg== X-Received: by 2002:a17:90a:470b:: with SMTP id h11mr1279040pjg.186.1613000754717; Wed, 10 Feb 2021 15:45:54 -0800 (PST) Received: from localhost.localdomain (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id w124sm3377569pfw.176.2021.02.10.15.45.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Feb 2021 15:45:54 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v7 6/6] Bluetooth: btusb: Consolidate code for waiting firmware to boot Date: Wed, 10 Feb 2021 15:45:49 -0800 Message-Id: <20210210234549.2293917-6-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210210234549.2293917-1-luiz.dentz@gmail.com> References: <20210210234549.2293917-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 | 148 +++++++++++++++++--------------------- 1 file changed, 66 insertions(+), 82 deletions(-) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 8d343bf33438..64c62a19df69 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -2804,6 +2804,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); @@ -2811,8 +2873,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; @@ -2847,46 +2907,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); @@ -2949,8 +2972,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; @@ -2986,46 +3007,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); -- 2.26.2