Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sebastian Reichel" <sebastian.reichel@collabora.com>
Cc: robh@kernel.org, linux-phy@lists.infradead.org,
	conor+dt@kernel.org, devicetree@vger.kernel.org,
	neil.armstrong@linaro.org, vkoul@kernel.org, olteanv@gmail.com
Subject: Re: [PATCH v9 35/38] phy: rockchip: usbdp: Simplify power state handling
Date: Thu, 02 Jul 2026 00:12:23 +0000	[thread overview]
Message-ID: <20260702001223.A7B601F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260702-rockchip-usbdp-cleanup-v9-35-e31efbb62d2e@collabora.com>

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [Critical] Dynamic PHY re-initialization destroys active DP lane state, silently breaking the active display link.
- [High] State leak on initialization failure leaves the driver desynchronized from the PHY subsystem.
- [High] High-speed only configurations fully power on unused SuperSpeed PHY hardware, wasting power and risking timeouts.
- [High] The PHY fails to re-initialize when the Type-C mux changes between 2-lane DP and 4-lane DP while only DP is actively powered on.
- [High] Initialization failure during a mode change leaves the software state permanently desynchronized from the hardware.
- [Medium] PHY_NOTIFY_POST_RESET is sent to the DWC3 driver unconditionally, even when powering down the PHY.
--

commit e22432b71115cadf57aac2173cacace2579279d3
Author: Sebastian Reichel <sebastian.reichel@collabora.com>
Subject: phy: rockchip: usbdp: Simplify power state handling

This commit introduces a sw_mode field to track software-requested PHY modes
independently from hardware capabilities. It centralizes power state
management and re-initialization into a single update function.

> diff --git a/drivers/phy/rockchip/phy-rockchip-usbdp.c b/drivers/phy/rockchip/phy-rockchip-usbdp.c
> index a19b048fb39ca..51aac07ef9fe9 100644
> --- a/drivers/phy/rockchip/phy-rockchip-usbdp.c
> +++ b/drivers/phy/rockchip/phy-rockchip-usbdp.c

[ ... ]

> @@ -1023,66 +1015,61 @@ static int rk_udphy_parse_dt(struct rk_udphy *udphy)
>  	return rk_udphy_reset_init(udphy, dev);
>  }
>  
> -static int rk_udphy_power_on(struct rk_udphy *udphy, u8 mode)
> +static int rk_udphy_update_power_state(struct rk_udphy *udphy)
>  {
> +	u8 target_mode = udphy->hw_mode & udphy->sw_mode;
>  	int ret;
>  
> -	if (!(udphy->hw_mode & mode)) {
> -		dev_info(udphy->dev, "mode 0x%02x is not support\n", mode);
> +	if (!udphy->phy_needs_reinit && udphy->status == target_mode)
>  		return 0;

[Severity: High]
Does this early return prevent the PHY from re-initializing when the Type-C
mux changes between 2-lane and 4-lane DP?

If the Type-C driver changes the mux configuration so hw_mode changes from
UDPHY_MODE_DP_USB to UDPHY_MODE_DP, but only DP is currently requested
(sw_mode == UDPHY_MODE_DP), target_mode will evaluate to UDPHY_MODE_DP in
both cases.

Because target_mode acts as a bitmask, the lane count change in hw_mode is
masked out, causing this check to succeed and entirely skip the required
re-initialization.

[ ... ]

> +	if (udphy->status == UDPHY_MODE_NONE) {
> +		/* Power up (incl. clocks) */
>  		ret = rk_udphy_setup(udphy);
> -		if (ret)
> +		if (ret) {
> +			phy_notify_reset(udphy->phy_u3, PHY_NOTIFY_POST_RESET);
>  			return ret;
> -
> -		if (!udphy->hs && udphy->hw_mode & UDPHY_MODE_USB)
> -			rk_udphy_u3_port_disable(udphy, false);
> -		udphy->phy_needs_reinit = false;
> -
> -		phy_notify_reset(udphy->phy_u3, PHY_NOTIFY_POST_RESET);
> -	} else if (udphy->phy_needs_reinit) {
> -		phy_notify_reset(udphy->phy_u3, PHY_NOTIFY_PRE_RESET);
> -
> -		rk_udphy_u3_port_disable(udphy, true);
> -		udelay(10);
> -
> +		}
> +	} else if (target_mode == UDPHY_MODE_NONE) {
> +		/* Power down (incl. clocks) */
> +		rk_udphy_disable(udphy);
> +	} else {
> +		/* Mode change => re-init */
>  		ret = rk_udphy_init(udphy);

[Severity: Critical]
Does dynamically re-initializing the PHY here destroy the active DP lane
state and silently break the display link?

When a concurrent mode change occurs, such as the DWC3 controller waking
from runtime suspend and requesting UDPHY_MODE_USB, rk_udphy_init is called
to re-initialize the PHY.

During initialization, rk_udphy_init unconditionally asserts resets and
writes 0 to CMN_DP_LANE_EN_ALL. However, rk_udphy_dp_lane_enable is
exclusively called during rk_udphy_dp_phy_power_on.

Since the DP lanes are never restored after this re-initialization, will
any USB runtime PM transition drop the display link without notifying the
DRM stack?

>  		if (ret) {
>  			phy_notify_reset(udphy->phy_u3, PHY_NOTIFY_POST_RESET);
>  			return ret;
>  		}

[Severity: High]
If rk_udphy_init fails, does this leave the software state permanently
desynchronized from the hardware?

If a failure occurs during a mode change, such as a PLL lock timeout,
rk_udphy_init jumps to its assert_resets error label, leaving all PHY
hardware resets asserted.

Since this error path returns without clearing udphy->status, the software
state will believe the previous mode is actively running while the hardware
is dead. If the subsystem retries or reverts to the old mode,
udphy->status == target_mode will erroneously succeed, trapping the PHY
in a broken state.

[ ... ]

> +	/* Ensure USB3 support is enabled when supported and requested */
> +	if (!udphy->hs && target_mode & UDPHY_MODE_USB)
> +		rk_udphy_u3_port_disable(udphy, false);
>  
> -	udphy->status |= mode;
> +	/*
> +	 * Inform DWC3, that we are done with the reset, so that it can deassert
> +	 * its PIPE reset line.
> +	 */
> +	phy_notify_reset(udphy->phy_u3, PHY_NOTIFY_POST_RESET);

[Severity: Medium]
Is it safe to unconditionally send PHY_NOTIFY_POST_RESET to the DWC3 driver
here, even when target_mode == UDPHY_MODE_NONE?

Since this notification is now sent after the power-down branch calls
rk_udphy_disable, the DWC3 driver may deassert its internal reset line
and resume PIPE communication. Doing this when the PHY is completely powered
off and its clocks are disabled could lead to internal controller state
corruption or SErrors.

[ ... ]

> @@ -1091,9 +1078,11 @@ static int rk_udphy_dp_phy_power_on(struct phy *phy)
>  	int ret;
>  
>  	scoped_guard(mutex, &udphy->mutex) {
> +		udphy->sw_mode |= UDPHY_MODE_DP;
> +
>  		phy_set_bus_width(phy, udphy->dp_lanes);
>  
> -		ret = rk_udphy_power_on(udphy, UDPHY_MODE_DP);
> +		ret = rk_udphy_update_power_state(udphy);
>  		if (ret)
>  			return ret;

[Severity: High]
If rk_udphy_update_power_state fails, does this leak the UDPHY_MODE_DP bit
in sw_mode?

The bit is added before the fallible update call and is never reverted on
error. The PHY framework considers the initialization failed and will never
call phy_power_off to clear the state. Future operations will then
incorrectly include this leaked mode in target_mode.

[ ... ]

> @@ -1329,13 +1320,9 @@ static int rk_udphy_usb3_phy_init(struct phy *phy)
>  
>  	guard(mutex)(&udphy->mutex);
>  
> -	/* DP only or high-speed, disable U3 port */
> -	if (!(udphy->hw_mode & UDPHY_MODE_USB) || udphy->hs) {
> -		rk_udphy_u3_port_disable(udphy, true);
> -		return 0;
> -	}
> +	udphy->sw_mode |= UDPHY_MODE_USB;
>  
> -	return rk_udphy_power_on(udphy, UDPHY_MODE_USB);
> +	return rk_udphy_update_power_state(udphy);
>  }

[Severity: High]
By removing the early return for high-speed only configurations (udphy->hs),
does this force full SuperSpeed initialization unnecessarily?

Without the early return, UDPHY_MODE_USB is unconditionally set in sw_mode.
This forces rk_udphy_update_power_state to power up the PMA/PCS and wait
for the SuperSpeed LCPLL to lock, which wastes power on unconnected or
unsupported hardware and may cause LCPLL lock timeouts.

[Severity: High]
Similar to the DP power on routine, if rk_udphy_update_power_state fails
here, does this leak the UDPHY_MODE_USB bit in sw_mode?

The bit is set before the update call and is never reverted on error,
desynchronizing the driver from the PHY subsystem.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260702-rockchip-usbdp-cleanup-v9-0-e31efbb62d2e@collabora.com?part=35

  reply	other threads:[~2026-07-02  0:12 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01 23:35 [PATCH v9 00/38] phy: rockchip: usbdp: Clean up the mess Sebastian Reichel
2026-07-01 23:35 ` [PATCH v9 01/38] dt-bindings: phy: rockchip-usbdp: add improved ports scheme Sebastian Reichel
2026-07-01 23:54   ` sashiko-bot
2026-07-01 23:35 ` [PATCH v9 02/38] phy: rockchip: usbdp: Update mode_change after error handling Sebastian Reichel
2026-07-01 23:35 ` [PATCH v9 03/38] phy: rockchip: usbdp: Do not lose USB3 PHY status Sebastian Reichel
2026-07-01 23:35 ` [PATCH v9 04/38] phy: rockchip: usbdp: Fix devm_clk_bulk_get_all check Sebastian Reichel
2026-07-01 23:35 ` [PATCH v9 05/38] phy: rockchip: usbdp: Handle missing clock-names DT property gracefully Sebastian Reichel
2026-07-01 23:35 ` [PATCH v9 06/38] phy: rockchip: usbdp: Drop seamless DP takeover Sebastian Reichel
2026-07-01 23:59   ` sashiko-bot
2026-07-01 23:35 ` [PATCH v9 07/38] phy: rockchip: usbdp: Handle rk_udphy_reset_deassert_all errors in init check Sebastian Reichel
2026-07-01 23:35 ` [PATCH v9 08/38] phy: rockchip: usbdp: Keep clocks running on PHY re-init Sebastian Reichel
2026-07-01 23:57   ` sashiko-bot
2026-07-01 23:35 ` [PATCH v9 09/38] phy: rockchip: usbdp: Amend SSC modulation deviation Sebastian Reichel
2026-07-01 23:35 ` [PATCH v9 10/38] phy: rockchip: usbdp: Fix LFPS detect threshold control Sebastian Reichel
2026-07-01 23:35 ` [PATCH v9 11/38] phy: rockchip: usbdp: Add missing mode_change update Sebastian Reichel
2026-07-01 23:35 ` [PATCH v9 12/38] phy: rockchip: usbdp: Support single-lane DP Sebastian Reichel
2026-07-01 23:35 ` [PATCH v9 13/38] phy: rockchip: usbdp: Limit DP lane count to muxed lanes Sebastian Reichel
2026-07-01 23:59   ` sashiko-bot
2026-07-01 23:35 ` [PATCH v9 14/38] phy: rockchip: usbdp: Rename DP lane functions Sebastian Reichel
2026-07-01 23:35 ` [PATCH v9 15/38] phy: rockchip: usbdp: Use FIELD_PREP_WM16_CONST Sebastian Reichel
2026-07-01 23:35 ` [PATCH v9 16/38] phy: rockchip: usbdp: Cleanup DP lane selection function Sebastian Reichel
2026-07-01 23:35 ` [PATCH v9 17/38] phy: rockchip: usbdp: Register DP aux bridge Sebastian Reichel
2026-07-01 23:35 ` [PATCH v9 18/38] phy: rockchip: usbdp: Drop DP HPD handling Sebastian Reichel
2026-07-02  0:00   ` sashiko-bot
2026-07-01 23:35 ` [PATCH v9 19/38] phy: rockchip: usbdp: Rename mode_change to phy_needs_reinit Sebastian Reichel
2026-07-01 23:35 ` [PATCH v9 20/38] phy: rockchip: usbdp: Re-init the PHY on orientation change Sebastian Reichel
2026-07-01 23:35 ` [PATCH v9 21/38] phy: rockchip: usbdp: Factor out lane_mux_sel setup Sebastian Reichel
2026-07-01 23:36 ` [PATCH v9 22/38] phy: rockchip: usbdp: Properly handle TYPEC_STATE_SAFE and TYPEC_STATE_USB Sebastian Reichel
2026-07-01 23:36 ` [PATCH v9 23/38] phy: rockchip: usbdp: Use guard functions for mutex Sebastian Reichel
2026-07-01 23:36 ` [PATCH v9 24/38] phy: rockchip: usbdp: Clear USB status on PHY exit Sebastian Reichel
2026-07-01 23:36 ` [PATCH v9 25/38] phy: rockchip: usbdp: Hold mutex in DP PHY configure Sebastian Reichel
2026-07-01 23:36 ` [PATCH v9 26/38] phy: rockchip: usbdp: Add some extra debug messages Sebastian Reichel
2026-07-01 23:36 ` [PATCH v9 27/38] phy: rockchip: usbdp: Avoid xHCI SErrors Sebastian Reichel
2026-07-01 23:36 ` [PATCH v9 28/38] phy: rockchip: usbdp: Disable USB3 on probe Sebastian Reichel
2026-07-01 23:36 ` [PATCH v9 29/38] phy: rockchip: usbdp: Handle rk_udphy_reset_deassert errors Sebastian Reichel
2026-07-01 23:36 ` [PATCH v9 30/38] phy: rockchip: usbdp: Only enable USB3 when not in high-speed mode Sebastian Reichel
2026-07-01 23:36 ` [PATCH v9 31/38] phy: core: add notifier infrastructure Sebastian Reichel
2026-07-02  0:06   ` sashiko-bot
2026-07-01 23:36 ` [PATCH v9 32/38] usb: dwc3: core: support PHY reset notifications Sebastian Reichel
2026-07-02  0:08   ` sashiko-bot
2026-07-01 23:36 ` [PATCH v9 33/38] phy: rockchip: usbdp: Add phy reset notification support Sebastian Reichel
2026-07-01 23:36 ` [PATCH v9 34/38] phy: rockchip: usbdp: Rename mode to hw_mode Sebastian Reichel
2026-07-01 23:36 ` [PATCH v9 35/38] phy: rockchip: usbdp: Simplify power state handling Sebastian Reichel
2026-07-02  0:12   ` sashiko-bot [this message]
2026-07-01 23:36 ` [PATCH v9 36/38] phy: rockchip: usbdp: Rename phy_needs_reinit to orientation_changed Sebastian Reichel
2026-07-02  0:08   ` sashiko-bot
2026-07-01 23:36 ` [PATCH v9 37/38] phy: rockchip: usbdp: Re-init PHY on mux change Sebastian Reichel
2026-07-02  0:12   ` sashiko-bot
2026-07-01 23:36 ` [PATCH v9 38/38] phy: rockchip: usbdp: Power optimizations Sebastian Reichel
2026-07-02  0:06   ` 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=20260702001223.A7B601F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=neil.armstrong@linaro.org \
    --cc=olteanv@gmail.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sebastian.reichel@collabora.com \
    --cc=vkoul@kernel.org \
    /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