Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1779803pxb; Wed, 10 Feb 2021 17:17:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJxoYJafFmT2q9qN9G0Fi0kHQz7B7tGFFSAZ0nZ3LHODipQNqPKue2yNkdwjmz1bZXB81YRY X-Received: by 2002:a05:6402:27d1:: with SMTP id c17mr5776727ede.109.1613006226363; 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=SCH1jdopslorvBi5ABknsKKkaCwOdeDfbfjyo8PoXURa/PGCW9OzrD/flgicExYt0i HXUAI3yfZcmTTKT+FQRdT/xJHSmgPoclWloH09YJzI+Pkl3ccJJ2HXdNULC50UtSstx0 pUa5UBbnvVOHGnblAeEsmNxz5wGT1VPd6txWJJ7X277bMoFLHKco66v9aijkkaRAby5t z7sLH+V8NWMvDeqCtFuccAyj7gx97xzYC4jt12BkLL3u8xTUo/nHPE/lcyduYJ80KskO mYekhjqVtOKxMd7UL0y4mXxzh2Ga9kMwZ6zA2i1alBA3lKn4EFx7JAgTi7Nqs92lLhkk WC+w== 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=POHyWgPhXwLdgOtxaJdUW0I0XQWjJRclblXFGJXmvSv60YE1i7NvvFdq46jQf2vmLT 9CqCr+JHgbpnp8/+ewwnY03uRUl3j2jjx+7aishZIdloS3nAqEe6m6Tr42yJeB38c3uS VFZO6XjVo5I8AekRWG6xE4e4dJmcdNR+nZrZ05HjobnSG87Biww8d3yYvdn0ExK94W3+ PEM8Zw84U7tu2YjgDVNO0Dlh8gCcy4dCUEoILGlCShydqGn30jCh3rHAMnttJ0kypOLF jwM7duz7eX2gJ1zCJB6ymOUJ0J9nQHi/bWUbk/UWVg/Kw9o4Sq2TwzhMong1+WViG4Dr PwRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CqvMdMmA; 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 x21si2546780edv.185.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=CqvMdMmA; 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 S230098AbhBKBJs (ORCPT + 99 others); Wed, 10 Feb 2021 20:09:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230110AbhBKBJq (ORCPT ); Wed, 10 Feb 2021 20:09:46 -0500 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63470C06178A for ; Wed, 10 Feb 2021 17:09:06 -0800 (PST) Received: by mail-pl1-x62b.google.com with SMTP id k22so2293881pll.6 for ; Wed, 10 Feb 2021 17:09:06 -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=CqvMdMmA2BdwsutdyyR4bBvS+8iVD4DW32PNUUYd+R2Bb97r5xLiCQB24j6HgJGAQh RgFbujPEP2magXPKJmusYGuy8VRgAr5tQqYbo4Oa4MEk7O+ZknhuJU4ZyktYgqFNGRHM QrDjrt6Xu7LyYgtYbtCAfeeIfeyix6u5ZKowK5lo814W9ThTFVotbuUgtOIxI9J98bRH 5gJ2KyQ6OvxnQelpYgaLs7DDM7zKwY/PBTpvQZTkiLWvsb6f1NHKWnJPEiU8NYYo7JmQ 0lGHiuJxHRJ811QSIc5L7J9zUFKD6xVNrwcNVCh533nIZieNYOHYS9q0Lv0gO8+vtrBu m6RQ== 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=Mt6htDDcD7Q400EVl9Fh4drMaiqXA7VU73i/HqfMEBK9IzZhGZIIOljzYSWOFFJDLp r+qXh1IQ+PwzuP9/5xJUMCDBLW4W75wkruNUIR72NhthloR4uoPrkurna9wKgF5CheR5 EphaYiaHmw8qtzxj0PlKHe/TKQbdDg6a+numUvnjSl6NWpXg5ub1l6j2+FEw4ebRt11J mskNnHDIb92FIULOMrs+xsagBqcQhRvwvTj8ZE2ocepeHQu6vyxD7liqwt4TUL4MwZa0 ZUFhluFpICdihCxtU3uUauA6M6z+/wbCvjk6RFkV+Py0LIUvlybtzd0CG2yzhzjOeU5d qelQ== X-Gm-Message-State: AOAM5333hLPRL3umlsndNVpCkqUiUywZflfvDqWrqSUNDCIoEvy8M2c+ UG/4ByqHGOMiqnTn5YXrIOjP42m1p5cZ3A== X-Received: by 2002:a17:90a:e508:: with SMTP id t8mr1606362pjy.106.1613005745670; Wed, 10 Feb 2021 17:09:05 -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:05 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v8 6/6] Bluetooth: btusb: Consolidate code for waiting firmware to boot Date: Wed, 10 Feb 2021 17:09:00 -0800 Message-Id: <20210211010900.2326531-6-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 | 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