All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: "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, 18 Dec 2024 18:49:11 +0100	[thread overview]
Message-ID: <D6F0L2L02YIS.3D2DW1P7691L4@bootlin.com> (raw)
In-Reply-To: <ed77988a-ba26-4a71-a8cf-b1e5a6425a2e@kernel.org>

Hello Roger, Peter, Pawel, Greg, Mathias,

On Tue Dec 17, 2024 at 10:00 PM CET, Roger Quadros wrote:
>
>
> On 13/12/2024 18:03, Théo Lebrun wrote:
> > On Thu Dec 12, 2024 at 1:37 PM CET, Roger Quadros wrote:
> >> On 10/12/2024 19:13, 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 false.
> >>>
> >>> 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.
> >>>
> >>> Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
> >>> ---
> >>>  drivers/usb/host/xhci.c | 3 ++-
> >>>  drivers/usb/host/xhci.h | 6 ++++++
> >>>  2 files changed, 8 insertions(+), 1 deletion(-)
> >>>
> >>> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
> >>> index 5ebde8cae4fc44cdb997b0f61314e309bda56c0d..ae2c8daa206a87da24d58a62b0a0485ebf68cdd6 100644
> >>> --- a/drivers/usb/host/xhci.c
> >>> +++ b/drivers/usb/host/xhci.c
> >>> @@ -1017,7 +1017,8 @@ 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->quirks & XHCI_RESET_ON_RESUME ||
> >>> +	    xhci->broken_suspend || xhci->lost_power)
> >>>  		reinit_xhc = true;
> >>>  
> >>>  	if (!reinit_xhc) {
> >>> diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
> >>> index 4914f0a10cff42dbc1448dcf7908534d582c848e..32526df75925989d40cbe7d59a187c945f498a30 100644
> >>> --- a/drivers/usb/host/xhci.h
> >>> +++ b/drivers/usb/host/xhci.h
> >>> @@ -1645,6 +1645,12 @@ struct xhci_hcd {
> >>>  	unsigned		broken_suspend:1;
> >>>  	/* Indicates that omitting hcd is supported if root hub has no ports */
> >>>  	unsigned		allow_single_roothub:1;
> >>> +	/*
> >>> +	 * Signal from upper stacks that we lost power during system-wide
> >>> +	 * suspend. Its default value is based on XHCI_RESET_ON_RESUME, meaning
> >>> +	 * it is safe for wrappers to not modify lost_power at resume.
> >>> +	 */
> >>> +	unsigned                lost_power:1;
> >>
> >> I suppose this is private to XHCI driver and not legitimate to be accessed
> >> by another driver after HCD is instantiated?
> > 
> > Yes it is private.
> > 
> >> Doesn't access to xhci_hcd need to be serialized via xhci->lock?
> > 
> > Good question. In theory maybe. In practice I don't see how
> > cdns_host_resume(), called by cdns_resume(), could clash with anything
> > else. I'll add that to be safe.
> > 
> >> Just curious, what happens if you don't include patch 4 and 5?
> >> Is USB functionality still broken for you?
> > 
> > No it works fine. Patches 4+5 are only there to avoid the below warning.
> > Logging "xHC error in resume" is a lie, so I want to avoid it.
>
> How is it a lie?
> The XHCI controller did loose its save/restore state during a PM operation.
> As far as XHCI is concerned this is an error. no?

The `xhci->quirks & XHCI_RESET_ON_RESUME` is exactly the same thing;
both the quirk and the flag we add have for purpose:

1. skipping this block

	if (!reinit_xhc) {
		retval = xhci_handshake(&xhci->op_regs->status,
					STS_CNR, 0, 10 * 1000 * 1000);
		// ...
		xhci_restore_registers(xhci);
		xhci_set_cmd_ring_deq(xhci);
		command = readl(&xhci->op_regs->command);
		command |= CMD_CRS;
		writel(command, &xhci->op_regs->command);
		if (xhci_handshake(&xhci->op_regs->status,
			      STS_RESTORE, 0, 100 * 1000)) {
			// ...
		}
	}

2. avoiding this warning:

	xhci_warn(xhci, "xHC error in resume, USBSTS 0x%x, Reinit\n", temp);

I don't think the block skipped is important in resume duration (to be
confirmed). But the xhci_warn() is not desired: we do not want to log
warnings if we know it is expected.

I'll think some more about it.

Thanks,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


  reply	other threads:[~2024-12-18 17:49 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 [this message]
2025-01-08 10:59           ` Théo Lebrun
2025-01-08 18:43             ` Mathias Nyman
2025-01-29 10:45               ` Théo Lebrun
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=D6F0L2L02YIS.3D2DW1P7691L4@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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.