Linux USB
 help / color / mirror / Atom feed
From: "Guilherme G. Piccoli" <gpiccoli@igalia.com>
To: linux-usb@vger.kernel.org, Thinh.Nguyen@synopsys.com
Cc: balbi@kernel.org, gregkh@linuxfoundation.org, johan@kernel.org,
	quic_wcheng@quicinc.com, kernel@gpiccoli.net,
	kernel-dev@igalia.com, Andrey Smirnov <andrew.smirnov@gmail.com>,
	Vivek Dasmohapatra <vivek@collabora.com>
Subject: Re: [PATCH] usb: dwc3: Fix spurious wakeup when port is on device mode
Date: Mon, 4 Dec 2023 08:36:54 -0300	[thread overview]
Message-ID: <2dfbf5c9-dd38-c919-c604-618ad08ce456@igalia.com> (raw)
In-Reply-To: <20231122165931.443845-1-gpiccoli@igalia.com>

On 22/11/2023 13:51, Guilherme G. Piccoli wrote:
> It was noticed that on plugging a low-power USB source on Steam
> Deck USB-C port (handled by dwc3), if such port is on device role,
> the HW somehow keep asseting the PCIe PME line and triggering a
> wakeup event on S3/deep suspend (that manifests as a PME wakeup
> interrupt, failing the suspend path). That doesn't happen when the USB
> port is on host mode or if the USB device connected is not a low-power
> type (for example, a connected keyboard doesn't reproduce that).
> 
> Even by masking all maskable ACPI GPEs, the problem still reproduces; also
> by having the PCIe PME mechanism using non-MSI interrupts, the symptom is
> observed as the HW succeeding to S3/suspend but waking up right after.
> 
> By changing the PRTCAP mode to DWC3_GCTL_PRTCAP_HOST in the controller
> (as one of the latest steps on gadget common suspend), we managed to
> circumvent the issue. The mode restore is already done in the common
> resume function. Notice that this patch does not change the in-driver
> port state on suspend, or else the resume path "thinks" the port was
> in host mode prior to suspend and resume it on a wrong fashion.
> 
> Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
> Cc: Vivek Dasmohapatra <vivek@collabora.com>
> Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
> ---
> 
> 
> Hi folks, first of all thanks in advance for reviews/feedback on this one.
> 
> This patch is the result of a debug approach with no datasheet access.
> With that said, I'm not 100% sure writing to this register is free of
> undesired side-effects; one thing I'm considering is the following scenario:
> imagine a device A with the USB port on device/peripheral mode, and a device B
> connected to it, acting as host. What if we want device B be able to wakeup
> device A? Would this patch prevent that for all cases, always?
> 
> I appreciate ideas in case this is not the best approach to fix the
> problem. We could also gate this approach to the HW board as a first step,
> for example.
> 
> Thanks,
> 
> 
> Guilherme
> 
> 
>  drivers/usb/dwc3/core.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 0328c86ef806..5801d3ebbbcb 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -104,7 +104,7 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)
>  	return 0;
>  }
>  
> -void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
> +static void __dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
>  {
>  	u32 reg;
>  
> @@ -112,7 +112,11 @@ void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
>  	reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
>  	reg |= DWC3_GCTL_PRTCAPDIR(mode);
>  	dwc3_writel(dwc->regs, DWC3_GCTL, reg);
> +}
>  
> +void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
> +{
> +	__dwc3_set_prtcap(dwc, mode);
>  	dwc->current_dr_role = mode;
>  }
>  
> @@ -2128,6 +2132,7 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
>  			break;
>  		dwc3_gadget_suspend(dwc);
>  		synchronize_irq(dwc->irq_gadget);
> +		__dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST);
>  		dwc3_core_exit(dwc);
>  		break;
>  	case DWC3_GCTL_PRTCAP_HOST:

Hi folks, friendly ping on this one.
Thanks,


Guilherme

  reply	other threads:[~2023-12-04 11:37 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-22 16:51 [PATCH] usb: dwc3: Fix spurious wakeup when port is on device mode Guilherme G. Piccoli
2023-12-04 11:36 ` Guilherme G. Piccoli [this message]
2023-12-05  1:23   ` Thinh Nguyen
2023-12-05 14:40     ` Guilherme G. Piccoli
2024-01-09 18:00       ` Guilherme G. Piccoli
2024-01-11  2:01         ` Thinh Nguyen
2024-01-11 16:13           ` Guilherme G. Piccoli
2024-01-13  1:33             ` Thinh Nguyen
2024-01-15 10:44               ` Vivek Dasmohapatra
2024-01-17  0:37                 ` Thinh Nguyen
2024-01-16 16:11               ` Guilherme G. Piccoli
2024-01-17  0:34                 ` Thinh Nguyen
2024-01-17 10:44                   ` Guilherme G. Piccoli
2024-01-18  0:39                     ` Thinh Nguyen
2024-01-21 17:48                       ` Guilherme G. Piccoli
2024-01-23  2:12                         ` Thinh Nguyen
2024-01-28 15:25                           ` Guilherme G. Piccoli
2024-01-30  2:17                             ` Thinh Nguyen
2024-01-31 18:16                               ` Guilherme G. Piccoli
2024-01-31 19:16                                 ` Guilherme G. Piccoli
2024-02-01  1:23                                   ` Thinh Nguyen
2024-02-01  1:23                                 ` Thinh Nguyen
2024-02-01 14:39                                   ` Guilherme G. Piccoli
2024-02-06  2:53                                     ` Thinh Nguyen
2024-02-06 10:30                                       ` Guilherme G. Piccoli
2024-02-08 23:53                                         ` Thinh Nguyen
2024-02-09  1:18                                           ` Guilherme G. Piccoli
2024-03-04 15:59                                             ` Guilherme G. Piccoli
2024-03-05  2:41                                               ` Thinh Nguyen
2024-03-07  0:40                                               ` Thinh Nguyen
2024-03-07 19:22                                                 ` Guilherme G. Piccoli
2024-03-08  2:42                                                   ` Thinh Nguyen
2024-03-08 11:52                                                     ` Guilherme G. Piccoli

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=2dfbf5c9-dd38-c919-c604-618ad08ce456@igalia.com \
    --to=gpiccoli@igalia.com \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=andrew.smirnov@gmail.com \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan@kernel.org \
    --cc=kernel-dev@igalia.com \
    --cc=kernel@gpiccoli.net \
    --cc=linux-usb@vger.kernel.org \
    --cc=quic_wcheng@quicinc.com \
    --cc=vivek@collabora.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