From: Roger Quadros <rogerq@kernel.org>
To: "Théo Lebrun" <theo.lebrun@bootlin.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Peter Chen" <peter.chen@kernel.org>,
"Pawel Laszczak" <pawell@cadence.com>,
"Mathias Nyman" <mathias.nyman@intel.com>,
"Nishanth Menon" <nm@ti.com>,
"Vignesh Raghavendra" <vigneshr@ti.com>,
"Tero Kristo" <kristo@kernel.org>
Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
"Kevin Hilman" <khilman@kernel.org>,
"Grégory Clement" <gregory.clement@bootlin.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>
Subject: Re: [PATCH v5 09/12] xhci: introduce xhci->lost_power flag
Date: Wed, 20 Nov 2024 16:49:31 +0200 [thread overview]
Message-ID: <ea3b4e40-8798-4352-8f45-242962532500@kernel.org> (raw)
In-Reply-To: <D42NIH63EHZG.KKWZR2WZB68L@bootlin.com>
Hello Théo,
On 10/09/2024 16:50, Théo Lebrun wrote:
> On Mon Aug 5, 2024 at 3:41 PM CEST, Roger Quadros wrote:
>> On 26/07/2024 21:17, Théo Lebrun wrote:
>>> The XHCI_RESET_ON_RESUME quirk allows wrappers to signal that they
>>> expect a reset after resume. It is also used by some to enforce a XHCI
>>> reset on resume (see needs-reset-on-resume DT prop).
>>>
>>> Some wrappers are unsure beforehands if they will reset. Add a mechanism
>>> to signal *at resume* if power has been lost. Parent devices can set
>>> this flag, that defaults to the XHCI_RESET_ON_RESUME value.
>>>
>>> The XHCI_RESET_ON_RESUME quirk still triggers a runtime_pm_get() on the
>>> controller. This is required as we do not know if a suspend will
>>> trigger a reset, so the best guess is to avoid runtime PM.
>>>
>>> Reset the xhci->lost_power value each time in xhci_resume(), making it
>>> safe for devices to only set lost_power on some resumes.
>>>
>>> Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
>>> ---
>>> drivers/usb/host/xhci.c | 8 +++++++-
>>> drivers/usb/host/xhci.h | 6 ++++++
>>> 2 files changed, 13 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
>>> index 0a8cf6c17f82..2c9b32d339f9 100644
>>> --- a/drivers/usb/host/xhci.c
>>> +++ b/drivers/usb/host/xhci.c
>>> @@ -1029,9 +1029,12 @@ int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg)
>>>
>>> spin_lock_irq(&xhci->lock);
>>>
>>> - if (hibernated || xhci->quirks & XHCI_RESET_ON_RESUME || xhci->broken_suspend)
>>> + if (hibernated || xhci->lost_power || xhci->broken_suspend)
>>
>> Why not treat xhci->lost_power and xhci->quriks & XHCI_RESET_ON_RESUME independently?
>>
>> XHCI_RESET_ON_RESUME is sued by devices that know they always need to be reset on resume.
>>
>> xhci->lost_power is used by devices that don't have consistent behavior.
>
> The goal is to avoid almost-duplicate functionality. I feel like:
>
> XHCI_RESET_ON_RESUME is the default value of xhci->lost_power,
> which might be modified at resume.
>
> Is a more straight forward solution than:
>
> Both XHCI_RESET_ON_RESUME and xhci->lost_power define if power was
> lost at resume. First must be statically known, second can be
> updated during runtime. If second is used, first one must NOT be
> set.
>
> Indeed, the first solution brings two additional lines of code as you
> commented below. I'd argue the easier-to-wrap-your-head-around logic is
> more important.
>
> Tell me if you are convinced the second approach is better.
>
I would still vote to keep logic tied to separate flags.
so XHCI_RESET_ON_RESUME to always resume on RESET
xhci->lost_power, reset based on runtime checks.
Which implies that platforms using xhci->lost_power should not
set XHCI_RESET_ON_RESUME.
But XHCI maintainers should give their opinion on this.
>>
>>
>>> reinit_xhc = true;
>>>
>>> + /* Reset to default value, parent devices might correct it at next resume. */
>>> + xhci->lost_power = !!(xhci->quirks & XHCI_RESET_ON_RESUME);
>>> +
>>
>> then you don't need to do this.
>
> To be honest, I added this line out of rigor. We could remove it and say
> that any device that modifies xhci->lost_power once at resume must set
> it at each later resume.
>
> The above line felt like a small safety net to avoid logic mistakes.
>
>>
>>> if (!reinit_xhc) {
>>> /*
>>> * Some controllers might lose power during suspend, so wait
>>> @@ -5228,6 +5231,9 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
>>> if (get_quirks)
>>> get_quirks(dev, xhci);
>>>
>>> + /* Default value, that can be corrected at resume. */
>>> + xhci->lost_power = !!(xhci->quirks & XHCI_RESET_ON_RESUME);
>>> +
>>
>> nor this.
>
> Regards,
>
> --
> Théo Lebrun, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
--
cheers,
-roger
next prev parent reply other threads:[~2024-11-20 14:50 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-26 18:17 [PATCH v5 00/12] Fix USB suspend on TI J7200 (cdns3-ti, cdns3, xhci) Théo Lebrun
2024-07-26 18:17 ` [PATCH v5 01/12] dt-bindings: usb: ti,j721e-usb: fix compatible list Théo Lebrun
2024-08-05 13:31 ` Roger Quadros
2024-07-26 18:17 ` [PATCH v5 02/12] dt-bindings: usb: ti,j721e-usb: add ti,j7200-usb compatible Théo Lebrun
2024-07-26 19:26 ` Rob Herring (Arm)
2024-09-10 10:03 ` Théo Lebrun
2024-07-26 18:17 ` [PATCH v5 03/12] usb: cdns3-ti: move reg writes to separate function Théo Lebrun
2024-07-26 18:17 ` [PATCH v5 04/12] usb: cdns3-ti: run HW init at resume() if HW was reset Théo Lebrun
2024-07-26 18:17 ` [PATCH v5 05/12] usb: cdns3: add quirk to platform data for reset-on-resume Théo Lebrun
2024-08-05 13:49 ` Roger Quadros
2024-07-26 18:17 ` [PATCH v5 06/12] usb: cdns3-ti: grab auxdata from match data Théo Lebrun
2024-08-05 13:51 ` Roger Quadros
2024-07-26 18:17 ` [PATCH v5 07/12] usb: cdns3-ti: add J7200 support with reset-on-resume behavior Théo Lebrun
2024-08-05 13:54 ` Roger Quadros
2024-09-10 13:57 ` Théo Lebrun
2024-07-26 18:17 ` [PATCH v5 08/12] usb: cdns3: rename hibernated argument of role->resume() to lost_power Théo Lebrun
2024-07-26 18:17 ` [PATCH v5 09/12] xhci: introduce xhci->lost_power flag Théo Lebrun
2024-08-05 13:41 ` Roger Quadros
2024-09-10 13:50 ` Théo Lebrun
2024-11-20 14:49 ` Roger Quadros [this message]
2024-07-26 18:17 ` [PATCH v5 10/12] usb: cdns3: host: transmit lost_power signal from wrapper to XHCI Théo Lebrun
2024-07-26 18:17 ` [PATCH v5 11/12] arm64: dts: ti: k3-j7200: use J7200-specific USB compatible Théo Lebrun
2024-08-05 14:01 ` Roger Quadros
2024-07-26 18:18 ` [PATCH v5 12/12] arm64: dts: ti: k3-am64: add USB fallback compatible to J721E Théo Lebrun
2024-08-05 14:03 ` Roger Quadros
2024-08-03 15:14 ` [PATCH v5 00/12] Fix USB suspend on TI J7200 (cdns3-ti, cdns3, xhci) Roger Quadros
2024-08-05 8:58 ` Théo Lebrun
2024-08-05 14:01 ` Roger Quadros
2024-08-06 23:12 ` Kevin Hilman
2024-08-09 1:19 ` Peter Chen
2024-09-10 14:04 ` Théo Lebrun
2024-09-01 20:20 ` (subset) " Nishanth Menon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ea3b4e40-8798-4352-8f45-242962532500@kernel.org \
--to=rogerq@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=gregory.clement@bootlin.com \
--cc=khilman@kernel.org \
--cc=kristo@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@intel.com \
--cc=nm@ti.com \
--cc=pawell@cadence.com \
--cc=peter.chen@kernel.org \
--cc=robh@kernel.org \
--cc=theo.lebrun@bootlin.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).