Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp804357pxk; Thu, 24 Sep 2020 20:35:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7LYbJd6yt/mS8nyPmWhBSKLY6TPd0wc+urpc2kBunbvr0jjrxceTI6Qsk1HIN9y9vZkrN X-Received: by 2002:aa7:c98d:: with SMTP id c13mr1951925edt.199.1601004958113; Thu, 24 Sep 2020 20:35:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601004958; cv=none; d=google.com; s=arc-20160816; b=dkS1xA+4O/Qzardk5bNZgXGUkpFXRPSV/HFReP/yD2+K6zbHRBK1l4ZB/CCMhZUuUT Hp9JDCm+xmApYbvrtC7Coxy2rCECN99yqTf7c6uYCT9n6GYE2MC36OcRJWOON4tR2CFE EUBODC+CEO9Pgwz+/mmSH3dEegkCfDoRyEzxGb8LW6Pd7BUDdvXpxcytv0yxw8zQsQnW gC5bjwt56UvlvZEDgXbfGRKxy1+OLgsfmcaVF3jvI5Fgn2bIwJr2/2FAT92WbA8SMb0+ CtkpfqeIIuLlpp1bCn91OSHjJilc1RcTJxN7DNWGh4ld3/M47HkJ8ThMiz6FoBeRe6a8 M6Hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=aJ7yarg421rbw+0Qq+LWPlS5VfbAKELCgdAWUBAvzsc=; b=F9miGGmW1rURBJGVRC0+ddofFD5P9DwUpZA2KB9XMIwyZeoj3D3tRaKgZ4LOiXllpE SaXNP/fPy6FXfksFcrGhFZHbPrlJg3HyZeqmH9H+mlOn0+Z4/49BTULmzJ2qlml/4MZV Dpv04pYlwRALou8sLQxwiJkdohvsLPuYQkhwUUpKBcwEFC80FxlMU/LmKryxB8Dsjc0K xC9N2DfnUC02NmNvx63OOPFbUfE5HeA3eFGkmjn+z3DxS/3KkVcWrvWfILAl8kVl7Dea BW45fMeIVK2AWkegy6PTe90APJzCEKgvDsBfT/JNEyJqwRFUpV89mhq1AXlFbpkPG2Q3 G3Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ReBzNMLA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l15si958599edr.581.2020.09.24.20.35.35; Thu, 24 Sep 2020 20:35:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@chromium.org header.s=google header.b=ReBzNMLA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726807AbgIYDeN (ORCPT + 99 others); Thu, 24 Sep 2020 23:34:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726829AbgIYDeN (ORCPT ); Thu, 24 Sep 2020 23:34:13 -0400 Received: from mail-vs1-xe44.google.com (mail-vs1-xe44.google.com [IPv6:2607:f8b0:4864:20::e44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70F19C0613D4 for ; Thu, 24 Sep 2020 20:34:13 -0700 (PDT) Received: by mail-vs1-xe44.google.com with SMTP id j3so598141vsm.0 for ; Thu, 24 Sep 2020 20:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aJ7yarg421rbw+0Qq+LWPlS5VfbAKELCgdAWUBAvzsc=; b=ReBzNMLAJQ7JvxuqCGbfVlbHL7w3Y8Va3lZUvb3PIAhRaT16VlY1qjYuzJC621Dhni lYyGP8nsOwlvz6y5nInidjsFMXyPsh4dpywzyTw51Jqp7uMPRmNYCHnvXKuX7I/6pcg9 KrAsTZFab/nY3lMFNB62DocRBa8s825D73y2A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aJ7yarg421rbw+0Qq+LWPlS5VfbAKELCgdAWUBAvzsc=; b=krQfPXtRQjmHmgpTFNv8zxOMFpSOQFxgWX4BCpEC4uPnxzlUeGF1BpK2we1+csjyBm ICLqzAqYA+OItOhk3BE1Fb18mUgUfBB/knOZnQd52tKMhOWgkMZjy1Q95c/DX0wb3xXU Hc9VkAABdLLwSfUN142BKDev/LjclypXxRdquSiUUFEkE0Mfao0cnasHt1tVPRT11AEY sQ6mhIGQzsuOAV3duo+aSdfALEaHXk5zpMEgppE9n8KEeryQToyFYeppKHG6gCWWchvs fT9GxsNLPFPMEcmo1E18mGsXZN8YuXMU/5LL2WQ/WCC8VzM4wY7X7tW8jhDqNBLav8Le wPYA== X-Gm-Message-State: AOAM531angXSvBVmEa81CnDCuVjtHSc2YoZRdtX32GRVhjXIQ6+oUyZk r/FXo5G6OYtdx6mKErGFrR84+nzSrJiOxxjK0vLZNQ== X-Received: by 2002:a67:8b45:: with SMTP id n66mr1824347vsd.45.1601004852342; Thu, 24 Sep 2020 20:34:12 -0700 (PDT) MIME-Version: 1.0 References: <20200923175602.9523-1-kai.heng.feng@canonical.com> In-Reply-To: From: Abhishek Pandit-Subedi Date: Thu, 24 Sep 2020 20:33:59 -0700 Message-ID: Subject: Re: [PATCH] Bluetooth: btusb: Avoid unnecessary reset upon system resume To: Kai-Heng Feng , Alex Lu Cc: Marcel Holtmann , Johan Hedberg , "open list:BLUETOOTH DRIVERS" , open list , "open list:USB XHCI DRIVER" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org + Alex Lu (who contributed the original change) Hi Kai-Heng, On Thu, Sep 24, 2020 at 12:10 AM Kai-Heng Feng wrote: > > [+Cc linux-usb] > > Hi Abhishek, > > > On Sep 24, 2020, at 04:41, Abhishek Pandit-Subedi wrote: > > > > Hi Kai-Heng, > > > > Which Realtek controller is this on?' > > The issue happens on 8821CE. > > > > > Specifically for RTL8822CE, we tested without reset_resume being set > > and that was causing the controller being reset without bluez ever > > learning about it (resulting in devices being unusable without > > toggling the BT power). > > The reset is done by the kernel, so how does that affect bluez? > > From what you described, it sounds more like runtime resume since bluez is already running. > If we need reset resume for runtime resume, maybe it's another bug which needs to be addressed? From btusb.c: https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/tree/drivers/bluetooth/btusb.c#n4189 /* Realtek devices lose their updated firmware over global * suspend that means host doesn't send SET_FEATURE * (DEVICE_REMOTE_WAKEUP) */ Runtime suspend always requires remote wakeup to be set and reset resume isn't used there. During system suspend, when remote wakeup is not set, RTL8822CE loses the FW loaded by the driver and any state currently in the controller. This causes the kernel and the controller state to go out of sync. One of the issues we observed on the Realtek controller without the reset resume quirk was that paired or connected devices would just stop working after resume. > > > If the firmware doesn't cut off power during suspend, maybe you > > shouldn't set the BTUSB_WAKEUP_DISABLE flag for that controller. > > We don't know beforehand if the platform firmware (BIOS for my case) will cut power off or not. > > In general, laptops will cut off the USB power during S3. > When AC is plugged, some laptops cuts USB power off and some don't. This also applies to many desktops. Not to mention there can be BIOS options to control USB power under S3/S4/S5... > > So we don't know beforehand. > I think the confusion here stems from what is actually being turned off between our two boards and what we're referring to as firmware :) In your case, the Realtek controller retains firmware unless the platform cuts of power to USB (which it does during S3). In my case, the Realtek controller loses firmware when Remote Wakeup isn't set, even if the platform doesn't cut power to USB. In your case, since you don't need to enforce the 'Remote Wakeup' bit, if you unset the BTUSB_WAKEUP_DISABLE for that VID:PID, you should get the desirable behavior (which is actually the default behavior; remote wake will always be asserted instead of only during Runtime Suspend). @Alex -- What is the common behavior for Realtek controllers? Should we set BTUSB_WAKEUP_DISABLE only on RTL8822CE or should we unset it only on RTL8821CE? > > > > I would prefer this doesn't get accepted in its current state. > > Of course. > I think we need to find the root cause for your case before applying this one. > > Kai-Heng > > > > > Abhishek > > > > On Wed, Sep 23, 2020 at 10:56 AM Kai-Heng Feng > > wrote: > >> > >> Realtek bluetooth controller may fail to work after system sleep: > >> [ 1272.707670] Bluetooth: hci0: command 0x1001 tx timeout > >> [ 1280.835712] Bluetooth: hci0: RTL: HCI_OP_READ_LOCAL_VERSION failed (-110) > >> > >> If platform firmware doesn't cut power off during suspend, the firmware > >> is considered retained in controller but the driver is still asking USB > >> core to perform a reset-resume. This can make bluetooth controller > >> unusable. > >> > >> So avoid unnecessary reset to resolve the issue. > >> > >> For devices that really lose power during suspend, USB core will detect > >> and handle reset-resume correctly. > >> > >> Signed-off-by: Kai-Heng Feng > >> --- > >> drivers/bluetooth/btusb.c | 8 +++----- > >> 1 file changed, 3 insertions(+), 5 deletions(-) > >> > >> diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c > >> index 8d2608ddfd08..de86ef4388f9 100644 > >> --- a/drivers/bluetooth/btusb.c > >> +++ b/drivers/bluetooth/btusb.c > >> @@ -4255,17 +4255,15 @@ static int btusb_suspend(struct usb_interface *intf, pm_message_t message) > >> enable_irq(data->oob_wake_irq); > >> } > >> > >> - /* For global suspend, Realtek devices lose the loaded fw > >> - * in them. But for autosuspend, firmware should remain. > >> - * Actually, it depends on whether the usb host sends > >> + /* For global suspend, Realtek devices lose the loaded fw in them if > >> + * platform firmware cut power off. But for autosuspend, firmware > >> + * should remain. Actually, it depends on whether the usb host sends > >> * set feature (enable wakeup) or not. > >> */ > >> if (test_bit(BTUSB_WAKEUP_DISABLE, &data->flags)) { > >> if (PMSG_IS_AUTO(message) && > >> device_can_wakeup(&data->udev->dev)) > >> data->udev->do_remote_wakeup = 1; > >> - else if (!PMSG_IS_AUTO(message)) > >> - data->udev->reset_resume = 1; > >> } > >> > >> return 0; > >> -- > >> 2.17.1 > >> >