From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: "Mathias Nyman" <mathias.nyman@linux.intel.com>,
"Roger Quadros" <rogerq@kernel.org>,
"Peter Chen" <peter.chen@kernel.org>,
"Pawel Laszczak" <pawell@cadence.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Mathias Nyman" <mathias.nyman@intel.com>
Cc: "Grégory Clement" <gregory.clement@bootlin.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 4/5] xhci: introduce xhci->lost_power flag
Date: Wed, 29 Jan 2025 11:45:31 +0100 [thread overview]
Message-ID: <D7EHVKGXIFM4.3IDSI7TDG85AV@bootlin.com> (raw)
In-Reply-To: <e181717a-8b3f-4ad4-b075-95c95888ce5c@linux.intel.com>
Hello Mathias,
On Wed Jan 8, 2025 at 7:43 PM CET, Mathias Nyman wrote:
> This would be a fourth way the upper layers inform xhci_resume() that the
> xHC host should be reset instead of restoring the registers.
>
> option 1 creates the first dynamic xhci->quirk flag,
> option 2 adds a xhci->lost_power flag that is touched outside of xhci driver.
>
> Neither seem like a good idea just to get rid of a dev_warn() message.
>
> Maybe its time to split xhci_resume() into xhci_reset_resume()
> and xhci_restore_resume(), and let those upper layers decide what they need.
>
> Doesn't cdns driver already have a xhci_plat_priv resume_quirk() function
> called during xhci_plat_resume(), before xhci_resume()?
> Can that be used?
I agree with your feeling: another solution is needed. Discussing the
topic gave some new ideas and I have a new solution that feels much
more appropriate.
### Opinion on splitting xhci_resume() into two implementations
About splitting xhci_resume() into two different implementations that is
picked by above layer: I am not convinced.
What would go into xhci_reset_resume() and xhci_restore_resume()? There
isn't a clear cut inbetween the reset procedure and the normal restore
procedure, as we might do a reset if the normal restore procedure
fails (with some logging that reset was unexpected).
We would probably end up with many small functions called by either,
which would blur the overall step sequence.
### Proposal
Instead, I propose we keep xhci_resume() as a single function but change
its signature from the current:
int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg);
To this:
int xhci_resume(struct xhci_hcd *xhci, bool power_lost,
bool is_auto_resume);
The key insight is that xhci_resume() extracts two information out of
the message:
- whether we are after hibernation: msg.event == PM_EVENT_RESTORE,
- whether this is an auto resume: msg.event == PM_EVENT_AUTO_RESUME.
First bulletpoint is somewhat wrong: driver wants to know if the device
did lose power, it doesn't care about hibernation per se. It just
happened to be that hibernation was the only case of power loss.
Knowing that, we can refactor to ask upper layers the right questions:
(1) "did we lose power?" and, (2) "is this an auto resume?".
Then, each caller is responsible for handing those booleans. If they
themselves receive pm_message_t messages (eg xhci-pci), then they do
the simple conversion:
bool power_lost = msg.event == PM_EVENT_RESTORE;
bool is_auto_resume = msg.event == PM_EVENT_AUTO_RESUME;
Others can do more more or less computation to pick a power_lost value.
### About xhci-plat power_lost value
In the case of xhci-plat, I think it will be:
- A new power_lost field in `struct xhci_plat_priv`.
- That gets set inside the cdns_role_driver::resume() callback of
drivers/usb/cdns3/host.c.
- Then xhci_plat_resume_common() computes power_lost being:
power_lost = is_restore || priv->power_lost;
### About xhci_plat_priv::resume_quirk()
It isn't really useful to use. drivers/usb/cdns3/host.c can know whether
power was lost through its USB role resume() callback. From there to
the resume_quirk(), the boolean must be stored somewhere. That
somewhere can only be... inside xhci_plat_priv. So it is simpler if
xhci-plat retrieves the boolean directly.
xhci_plat_priv::resume_quirk() can change the power_lost value if it
wants to, that is fine. But in our case, the info isn't available from
there.
###
I am unsure if the above explanation is clear, so I'll be sending my
current work-in-progress series as an answer to this. The goal being
that you can give me your opinion on the proposal: ACK and we continue
in this direction, NACK and we keep digging.
I'll wait for the merge window to end before sending a proper revision.
Thanks!
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2025-01-29 10:45 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-10 17:13 [PATCH v6 0/5] Fix USB suspend on TI J7200 (cdns3-ti, cdns3, xhci) Théo Lebrun
2024-12-10 17:13 ` [PATCH v6 1/5] usb: cdns3-ti: move reg writes to separate function Théo Lebrun
2024-12-12 12:12 ` Roger Quadros
2024-12-10 17:13 ` [PATCH v6 2/5] usb: cdns3-ti: run HW init at resume() if HW was reset Théo Lebrun
2024-12-12 12:18 ` Roger Quadros
2024-12-13 15:28 ` Théo Lebrun
2024-12-17 21:13 ` Roger Quadros
2024-12-14 8:49 ` Peter Chen
2024-12-16 14:02 ` Théo Lebrun
2024-12-17 6:12 ` Peter Chen
2024-12-10 17:13 ` [PATCH v6 3/5] usb: cdns3: rename hibernated argument of role->resume() to lost_power Théo Lebrun
2024-12-14 8:51 ` Peter Chen
2024-12-10 17:13 ` [PATCH v6 4/5] xhci: introduce xhci->lost_power flag Théo Lebrun
2024-12-12 12:37 ` Roger Quadros
2024-12-13 16:03 ` Théo Lebrun
2024-12-17 21:00 ` Roger Quadros
2024-12-18 17:49 ` Théo Lebrun
2025-01-08 10:59 ` Théo Lebrun
2025-01-08 18:43 ` Mathias Nyman
2025-01-29 10:45 ` Théo Lebrun [this message]
2025-01-29 10:56 ` [PATCH 1/9] usb: host: xhci-plat: mvebu: use ->quirks instead of ->init_quirk() func Théo Lebrun
2025-01-29 10:56 ` [PATCH 2/9] usb: xhci: tegra: rename `runtime` boolean to `is_auto_runtime` Théo Lebrun
2025-01-29 10:56 ` [PATCH 3/9] usb: cdns3-ti: move reg writes to separate function Théo Lebrun
2025-01-29 10:56 ` [PATCH 4/9] usb: cdns3-ti: run HW init at resume() if HW was reset Théo Lebrun
2025-01-29 10:56 ` [PATCH 5/9] usb: cdns3: rename hibernated argument of role->resume() to lost_power Théo Lebrun
2025-01-29 10:56 ` [PATCH 6/9] usb: cdns3: call cdns_power_is_lost() only once in cdns_resume() Théo Lebrun
2025-01-29 10:56 ` [PATCH 7/9] usb: xhci: change xhci_resume() parameters to explicit the desired info Théo Lebrun
2025-01-29 10:56 ` [PATCH 8/9] usb: host: xhci-plat: allow upper layers to signal power loss Théo Lebrun
2025-01-29 10:56 ` [PATCH 9/9] usb: host: cdns3: forward lost power information to xhci Théo Lebrun
2024-12-10 17:13 ` [PATCH v6 5/5] usb: cdns3: host: transmit lost_power signal from wrapper to XHCI Théo Lebrun
2024-12-14 9:06 ` [PATCH v6 0/5] Fix USB suspend on TI J7200 (cdns3-ti, cdns3, xhci) Peter Chen
2024-12-16 14:09 ` Théo Lebrun
2024-12-17 6:17 ` Peter Chen
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=D7EHVKGXIFM4.3IDSI7TDG85AV@bootlin.com \
--to=theo.lebrun@bootlin.com \
--cc=gregkh@linuxfoundation.org \
--cc=gregory.clement@bootlin.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@intel.com \
--cc=mathias.nyman@linux.intel.com \
--cc=pawell@cadence.com \
--cc=peter.chen@kernel.org \
--cc=rogerq@kernel.org \
--cc=thomas.petazzoni@bootlin.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