Linux USB
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Radhey Shyam Pandey" <radhey.shyam.pandey@amd.com>
Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v5 3/4] usb: dwc3: xilinx: Add Versal2 MMI USB 3.2 controller support with flat probe model
Date: Tue, 17 Nov 2026 15:55:48 +0000	[thread overview]
Message-ID: <sashiko-outbox-219119@kernel.org> (raw)
In-Reply-To: <20261117150219.1326693-4-radhey.shyam.pandey@amd.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] usb: dwc3: xilinx: unclocked access and clk underflow in
  dwc3_xlnx_suspend()
- [High] usb: dwc3: xilinx: wrong gsbuscfg0_reqinfo 0xf0f0 in
  dwc3_xlnx_probe_flat()
- [High] usb: dwc3: xilinx: double usb3-phy management in flat probe
  model
--

commit 18ab81bda6f0f5fc8594e87f3a2015f5b9af6de1
Author: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>

usb: dwc3: xilinx: Add Versal2 MMI USB 3.2 controller support with flat probe model

This commit adds a flat probe model to dwc3-xilinx that embeds struct dwc3
in struct dwc3_xlnx and uses it to support the Versal Gen2 MMI USB 3.2 DRD
controller.

> diff --git a/drivers/usb/dwc3/dwc3-xilinx.c b/drivers/usb/dwc3/dwc3-xilinx.c
> index b58fe034a94d4..c68246921a4c9 100644
> --- a/drivers/usb/dwc3/dwc3-xilinx.c
> +++ b/drivers/usb/dwc3/dwc3-xilinx.c

[ ... ]

> @@ -113,6 +143,59 @@ static int dwc3_xlnx_init_versal(struct dwc3_xlnx *priv_data)
>  	return 0;
>  }
>  
> +static void dwc3_xlnx_versal2_teardown(void *data)
> +{
> +	struct dwc3_xlnx *priv_data = data;
> +
> +	phy_power_off(priv_data->usb3_phy);
> +	reset_control_assert(priv_data->usb_crst);
> +	phy_exit(priv_data->usb3_phy);
> +}
> +
> +static int dwc3_xlnx_init_versal2(struct dwc3_xlnx *priv_data)
> +{
> +	struct device *dev = priv_data->dev;
> +	int ret;
> +
> +	priv_data->usb3_phy = devm_phy_optional_get(dev, "usb3-phy");
> +	if (IS_ERR(priv_data->usb3_phy))
> +		return dev_err_probe(dev, PTR_ERR(priv_data->usb3_phy),
> +				     "failed to get USB3 PHY\n");
> +
> +	priv_data->usb_crst = devm_reset_control_get_exclusive(dev, NULL);
> +	if (IS_ERR(priv_data->usb_crst))
> +		return dev_err_probe(dev, PTR_ERR(priv_data->usb_crst),
> +				     "failed to get reset signal\n");
> +
> +	ret = reset_control_assert(priv_data->usb_crst);
> +	if (ret < 0)
> +		return dev_err_probe(dev, ret, "failed to assert reset\n");
> +
> +	ret = phy_init(priv_data->usb3_phy);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = reset_control_deassert(priv_data->usb_crst);
> +	if (ret < 0) {
> +		dev_err_probe(dev, ret, "failed to deassert reset\n");
> +		goto err_phy_exit;
> +	}
> +
> +	ret = phy_power_on(priv_data->usb3_phy);
> +	if (ret < 0)
> +		goto err_crst_assert;

[Severity: High]
Does acquiring, initializing, and powering on "usb3-phy" here conflict with
dwc3_core_probe() managing the same PHY in the flat model?

In the legacy wrapper model, "usb3-phy" is on the parent wrapper node while
the DWC3 core is a child device.  In the flat model, priv_data->dev and
priv_data->dwc.dev are the same device, so dwc3_core_probe() ->
dwc3_core_init() -> dwc3_core_get_phy() also calls devm_phy_get(dev,
"usb3-phy") into dwc->usb3_generic_phy[0] and calls dwc3_phy_init() and
dwc3_phy_power_on(), bumping phy->init_count and phy->power_count to 2.

During probe and dwc3_xlnx_resume(), the PHY is initialized and powered on
before dwc3_core_init() runs dwc3_phy_setup(), dwc3_core_soft_reset(), and
dwc3_config_soc_bus().  During dwc3_xlnx_runtime_suspend(),
dwc3_runtime_suspend() drops only the core's reference while
priv_data->usb3_phy is left active, so init_count and power_count stay at 1
(and in host mode the extra runtime PM usage count from the second
phy_power_on() remains held), preventing the PHY from powering off in
runtime suspend or across direct_complete system suspend.

[ ... ]

> +static int dwc3_xlnx_probe_flat(struct platform_device *pdev,
> +				struct dwc3_xlnx *priv_data)
> +{
> +	struct dwc3_probe_data probe_data = {};
> +	struct device *dev = &pdev->dev;
> +	struct resource *res;
> +	int ret;
> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (!res) {
> +		ret = -ENODEV;
> +		goto err_clk_put;
> +	}
> +
> +	priv_data->dwc.dev = dev;
> +	probe_data.dwc = &priv_data->dwc;
> +	probe_data.res = res;
> +	probe_data.ignore_clocks_and_resets = true;
> +	probe_data.properties = DWC3_DEFAULT_PROPERTIES;
> +
> +	if (of_dma_is_coherent(dev->of_node))
> +		probe_data.properties.gsbuscfg0_reqinfo = 0xf0f0;

[Severity: High]
Should probe_data.properties.gsbuscfg0_reqinfo be 0xffff instead of 0xf0f0
to match dwc3_set_swnode()?

dwc3_config_soc_bus() writes gsbuscfg0_reqinfo into DWC3_GSBUSCFG0[31:16],
covering DESWRREQINFO [31:28], DATWRREQINFO [27:24], DESRDREQINFO [23:20],
and DATRDREQINFO [19:16].  Using 0xf0f0 marks descriptor accesses as
cacheable but leaves data read and write accesses (DATWRREQINFO and
DATRDREQINFO) as 0 while dma-coherent tells the DMA layer to skip CPU cache
maintenance on data buffers, which can corrupt USB DMA data transfers.

[ ... ]

> @@ -414,13 +603,24 @@ static void dwc3_xlnx_remove(struct platform_device *pdev)
>  	clk_bulk_disable_unprepare(priv_data->num_clocks, priv_data->clks);
>  	priv_data->num_clocks = 0;
>  
> +	if (priv_data->plat->flat)
> +		return;
> +
>  	pm_runtime_put_noidle(dev);
>  	pm_runtime_set_suspended(dev);
>  }
>  
>  static int __maybe_unused dwc3_xlnx_runtime_suspend(struct device *dev)
>  {
> -	struct dwc3_xlnx *priv_data = dev_get_drvdata(dev);
> +	struct dwc3_xlnx *priv_data = dwc3_xlnx_get_priv(dev);
> +	int ret;
> +
> +	/* Quiesce the core while its register interface is still clocked. */
> +	if (priv_data->plat->flat) {
> +		ret = dwc3_runtime_suspend(&priv_data->dwc);
> +		if (ret)
> +			return ret;
> +	}
>  
>  	clk_bulk_disable(priv_data->num_clocks, priv_data->clks);
>  

[ ... ]

> @@ -443,12 +659,19 @@ static int __maybe_unused dwc3_xlnx_runtime_idle(struct device *dev)
>  
>  static int __maybe_unused dwc3_xlnx_suspend(struct device *dev)
>  {
> -	struct dwc3_xlnx *priv_data = dev_get_drvdata(dev);
> +	struct dwc3_xlnx *priv_data = dwc3_xlnx_get_priv(dev);
>  	int ret;
>  
> +	/* Quiesce the core while its register interface is still clocked. */
> +	if (priv_data->plat->flat) {
> +		ret = dwc3_pm_suspend(&priv_data->dwc);
> +		if (ret)
> +			return ret;
> +	}
> +
>  	ret = phy_power_off(priv_data->usb3_phy);
>  	if (ret < 0)
> -		return ret;
> +		goto err_core_resume;
>  
>  	ret = phy_exit(priv_data->usb3_phy);
>  	if (ret < 0)
> @@ -462,13 +685,16 @@ static int __maybe_unused dwc3_xlnx_suspend(struct device *dev)
>  err_phy_power_on:
>  	if (phy_power_on(priv_data->usb3_phy))
>  		dev_err(dev, "failed to restore PHY power after suspend error\n");
> +err_core_resume:
> +	if (priv_data->plat->flat)
> +		dwc3_pm_resume(&priv_data->dwc);
>  
>  	return ret;
>  }

[Severity: High]
What happens if the system suspends while the flat device is already
runtime-suspended?

Unlike dwc3_xlnx_probe_legacy(), which holds a runtime PM reference via
pm_runtime_resume_and_get(), dwc3_core_probe() drops its reference at the
end of probe so the flat device can enter dwc3_xlnx_runtime_suspend(),
which disables priv_data->clks.

When system suspend then runs while pm_runtime_suspended(dev) is true,
dwc3_xlnx_prepare() -> dwc3_pm_prepare() returns 0 in host or OTG mode (or
whenever a genpd power domain is attached, since genpd_prepare() returns 0)
and the PM core calls dwc3_xlnx_suspend() without runtime-resuming the
device:

1. dwc3_pm_suspend() -> dwc3_suspend_common() calls dwc3_core_exit() in
   host and OTG modes without checking pm_runtime_suspended(), accessing
   DWC3 registers while priv_data->clks are disabled.
2. dwc3_xlnx_suspend() unconditionally calls clk_bulk_disable() a second
   time on priv_data->clks (and on error, err_core_resume calls
   dwc3_pm_resume() with clocks disabled), whereas dwc3_xlnx_resume() only
   enables them once and marks the device runtime active.
3. Conversely, if direct_complete is ever used in device mode when
   dwc3_pm_prepare() returns 1, dwc3_xlnx_suspend() is skipped and
   priv_data->usb3_phy remains powered on across system sleep.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117150219.1326693-1-radhey.shyam.pandey@amd.com?part=3

  reply	other threads:[~2026-11-17 15:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 15:02 [PATCH v5 0/4] usb: dwc3: xilinx: Add Versal2 MMI USB 3.2 controller support Radhey Shyam Pandey
2026-11-17 15:02 ` [PATCH v5 1/4] usb: dwc3: xilinx: use device_get_match_data() in probe Radhey Shyam Pandey
2026-11-17 15:18   ` sashiko-bot
2026-11-17 15:02 ` [PATCH v5 2/4] dt-bindings: usb: amd,versal2-mmi-dwc3: Add MMI USB support on Versal Gen2 platform Radhey Shyam Pandey
2026-11-17 15:20   ` sashiko-bot
2026-11-17 15:02 ` [PATCH v5 3/4] usb: dwc3: xilinx: Add Versal2 MMI USB 3.2 controller support with flat probe model Radhey Shyam Pandey
2026-11-17 15:55   ` sashiko-bot [this message]
2026-11-17 15:02 ` [PATCH v5 4/4] usb: dwc3: xilinx: Add support to program MMI USB TX deemphasis Radhey Shyam Pandey
2026-11-17 16:00   ` sashiko-bot

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=sashiko-outbox-219119@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=radhey.shyam.pandey@amd.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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