Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp865566pxk; Thu, 24 Sep 2020 23:04:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMTdmem0tIIU2Hb0jOSg2ujNwkVMRI/J/znDfeljm6s3Sws6SByNZym8Jt6sFPWUNwLJ/d X-Received: by 2002:a17:907:374:: with SMTP id rs20mr1179894ejb.135.1601013887737; Thu, 24 Sep 2020 23:04:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601013887; cv=none; d=google.com; s=arc-20160816; b=LdQ6Q/7lGYKZ2hgnxIpNKxMUlAksQMFl4echIJ8aS2Y0HaJdDl8suVn6ep0u2dbTLD nV6po860I8iATMcwkYSGub3F90PvjDP9HFwCSL+rFx2JfTthgfDQAlH6cGeFHCMKK95+ 3HphxnXoZk5jyjeCAoSyCHR55AS+VRi/fAePyJyLDlr4GZAKQrgIotfzz2fdrCkQzAI/ StSE2j8Rs3+BpaphsXMSqkEmQYswta/YOobfeu3PLwWpHX63FYKlrMA5JLk1tSj3d05o 8BUCjdZzRrexIfpQyECiTY61ITE3okcK55zP+Hqfz0eQ9pUkUL9xg34m9xieQS/GOIGy 8RJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version; bh=lTC6ARcBBLb91vL61uRtLWpJKrFRuKKbdYWNNN2hGTA=; b=QRamWd5Fdzb6gN/WeSUqgB/KFH8BLLxBxGQdpXsxpZNvuFDaNF9/Ada/+lz4lm5fww Qcubi59FlCOnhJHLN7zHExU2lUG6W808uM+Uat6aEMX559eWGkaZJqxHljgKB4M5Pr6G M4yjuWF50tXnSWpsQihxFBjjBtcEvBxQGWdu9WAFA3R04PuKTKelY8Rkok8utGNPg/y3 R0NM92qxiTlK4uXfKuTb4Mqdy9YBrgqR6tbltMYwysAXpbGFU385eMtjd0pbpi8IADBp EHzrjz3hKEGkWt3Q5pAGI5o1IlVOTBhypJ55d1nRUQSQA7IwWW9jC82DHZVamvQBhVqn EA7A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ce16si1174091edb.302.2020.09.24.23.04.07; Thu, 24 Sep 2020 23:04:47 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727067AbgIYGDo convert rfc822-to-8bit (ORCPT + 99 others); Fri, 25 Sep 2020 02:03:44 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:53657 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726983AbgIYGDo (ORCPT ); Fri, 25 Sep 2020 02:03:44 -0400 Received: from mail-pf1-f198.google.com ([209.85.210.198]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kLgpZ-0005lo-LW for linux-bluetooth@vger.kernel.org; Fri, 25 Sep 2020 06:03:41 +0000 Received: by mail-pf1-f198.google.com with SMTP id e12so1323137pfm.0 for ; Thu, 24 Sep 2020 23:03:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=1yvwZFftP3xTcobSpqJkVCGIkCDtLpkz77Q75FFnu3Y=; b=tvsZnIJjTo3KB4QznFUED8sixWRu9esri6ZI8BFQckCumJ4nxF50syZ97QliB172wp 9LTqK0aZWbmxug82YnXL1eFemPRrEazlfulqqmlngo85yb/DIFlkwXlY3D8GJ4ugyFiF ZjC+LlJvA0PcOzTKQGE0ETSDl+VCnEsWWzziRvOL9IRuEgeGDDm3fhgyDoj+TVzTGWlo OufAhmo0npTa1UMAw811/83V1VgbJQv1HxCTk7E+ToeWA+MGVbYKUr+vCXYIbPQxPtrq AiS7DmegEEp389mRbTPNBvMpdApBnpjYlq8MmAvz5oJurfetFoXMKI2r76oo2cvPftsY QPPg== X-Gm-Message-State: AOAM530sVvRUN4tLb1AGdr110vTckGVk+/YA3GehUlnULR0MU3dco2+x cnW4u4RPKRPLaU9c0w/qN6ETEOsB7xFsQnRGRVTeWjDgiHUdnSW01MxtGZOIB3IwPQhrzqEx+wO exfRJle+v/+H4UR6SO53luH1skGUzLMS6NbaoSKHyTJXL9g== X-Received: by 2002:a17:90a:bd8b:: with SMTP id z11mr1252546pjr.2.1601013819768; Thu, 24 Sep 2020 23:03:39 -0700 (PDT) X-Received: by 2002:a17:90a:bd8b:: with SMTP id z11mr1252502pjr.2.1601013819085; Thu, 24 Sep 2020 23:03:39 -0700 (PDT) Received: from [192.168.1.208] (220-133-187-190.HINET-IP.hinet.net. [220.133.187.190]) by smtp.gmail.com with ESMTPSA id a9sm938208pjm.40.2020.09.24.23.03.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Sep 2020 23:03:38 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.1\)) Subject: Re: [PATCH] Bluetooth: btusb: Avoid unnecessary reset upon system resume From: Kai-Heng Feng In-Reply-To: Date: Fri, 25 Sep 2020 14:03:34 +0800 Cc: Alex Lu , Marcel Holtmann , Johan Hedberg , "open list:BLUETOOTH DRIVERS" , open list , "open list:USB XHCI DRIVER" Content-Transfer-Encoding: 8BIT Message-Id: References: <20200923175602.9523-1-kai.heng.feng@canonical.com> To: Abhishek Pandit-Subedi X-Mailer: Apple Mail (2.3608.120.23.2.1) Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Abhishek, > On Sep 25, 2020, at 11:33, Abhishek Pandit-Subedi wrote: > > + 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. Thanks for the clarification. > > 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 :) Yes :) > > In your case, the Realtek controller retains firmware unless the > platform cuts of power to USB (which it does during S3). Not all platform firmware (i.e. BIOS for x86) cut USB power during S3, as I describe in last reply. > In my case, the Realtek controller loses firmware when Remote Wakeup > isn't set, even if the platform doesn't cut power to USB. Thanks for the clarification, I believe it's a case that should to be handled separately. > > 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). So we have three cases here. Assuming reset_resume isn't flagged by btusb: 1) Both USB power and BT firmware were lost during suspend. USB core finds out power was lost, try to reset resume the device. Since btusb doesn't have reset_resume callback, USB core calls probe instead. 2) Both USB power and BT firmware were kept during suspend. This is my case. Regular resume handles everything. 3) USB power was kept but BT firmware was lost. This is your case. USB core finds out power was kept, use regular resume. However the BT firmware was lost, so resume fails. For this case, maybe we can use btrtl_setup_realtek() in btusb_resume()? It won't re-upload firmware if firmware is retained, and will do proper initializing if firmware was lost. Kai-Heng > > @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