On Wednesday, December 2, 2026 at 4:34 PM, [email protected] wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issues to consider:
> - [Medium] phy: cadence-torrent: uninitialized rst_asserted breaks
> resume reset state
> - [Medium] phy: cadence-torrent: incomplete reset and link restoration
> in tp_resume_noirq()
> --
>
> commit a2bcc09aba1dcb8fcf52a6ca3d4a6b96ba68afa6
> Author: Benjamin Robin <[email protected]>
>
> phy: cadence-torrent: rework suspend/resume to restore link config
>
> This commit reworks suspend and resume to track per-link reset state, keep
> reference clocks enabled across suspend when links remain powered on, and
> re-program the PHY on resume when its configuration was lost.
>
> > diff --git a/drivers/phy/cadence/phy-cadence-torrent.c
> > b/drivers/phy/cadence/phy-cadence-torrent.c
> > index 02e3c91316d56..7c4c20b005a95 100644
> > --- a/drivers/phy/cadence/phy-cadence-torrent.c
> > +++ b/drivers/phy/cadence/phy-cadence-torrent.c
> > @@ -348,6 +348,7 @@ struct tp_link {
> > u8 num_lanes;
> > u8 max_lanes;
> > u16 bit_rate; /* in Mb/s */
> > + bool rst_asserted;
> > enum cdns_torrent_ssc_mode ssc_mode;
> > };
>
> [Severity: Medium]
> Should link->rst_asserted be initialized when each link is set up at probe
> time?
>
> cdns_torrent_phy_probe() zero-allocates tp_data via devm_kzalloc_obj(), so
> link->rst_asserted starts as false for all links even though unpowered
> links remain in reset until tp_phy_on() is called. In a multi-link setup
> where one link is powered on (nb_phy_on > 0) and another link has never
> been powered on, a state-losing suspend and resume takes the
> restore_resets path in tp_resume_noirq() and sees !link->rst_asserted on
> the never-powered link, deasserting link->lnk_rst on an unpowered link.
In v3 when already_configured is false, all reset lines are asserted before
configuring the torrent PHY. So it should initialize this variable in this
case.
When already_configured is true, we should assume that the reset lines
are deasserted. So the default value should be OK.
> Also, if link->rst_asserted is initialized to true at probe time when
> !tp_data->already_configured, note that the tp_data->already_configured
> early return in tp_phy_on() increments nb_phy_on without calling
> tp_control_link_reset(link, false), so rst_asserted needs to reflect
> whether the link was already out of reset.
In v3 the reset lines are deasserted unconditionally in tp_phy_on(),
so even if already_configured is true.
>
> [ ... ]
>
> > @@ -2994,51 +3010,80 @@ static int tp_refclk_driver_resume(struct tp_data
> > *tp_data)
> >
> > static int tp_suspend_noirq(struct device *dev)
> > {
> > + int ret = 0;
> > struct tp_data *tp_data = dev_get_drvdata(dev);
> > - int i;
> >
> > tp_refclk_driver_suspend(tp_data);
> >
> > - reset_control_assert(tp_data->phy_rst);
> > - reset_control_assert(tp_data->apb_rst);
> > - for (i = 0; i < tp_data->nb_links; i++)
> > - reset_control_assert(tp_data->links[i].lnk_rst);
> > -
> > tp_data->already_configured = false;
> > - tp_ref_clks_uninit(tp_data);
> > + if (!tp_data->nb_phy_on) {
> > + tp_ref_clks_uninit(tp_data);
> > + ret = reset_control_assert(tp_data->apb_rst);
> > + }
> >
> > - return 0;
> > + return ret;
> > }
> >
> > static int tp_resume_noirq(struct device *dev)
> > {
> > + int ret;
> > + bool config_needed = false;
> > + bool restore_resets = false;
> > struct tp_data *tp_data = dev_get_drvdata(dev);
> > - int node = tp_data->nb_links;
> > - int ret, i;
> >
> > - ret = tp_refclk_driver_resume(tp_data);
> > + /* Enable APB unconditionally */
> > + ret = reset_control_deassert(tp_data->apb_rst);
> > if (ret)
> > return ret;
> >
> > + ret = tp_refclk_driver_resume(tp_data);
> > + if (ret)
> > + goto failed;
> > +
> > ret = tp_ref_clks_init(tp_data);
> > if (ret)
> > - return ret;
> > + goto failed;
> >
> > - /* Enable APB */
> > - reset_control_deassert(tp_data->apb_rst);
> > + /* Check if we have lost the configuration */
> > + if (!tp_data->nb_phy_on) {
> > + /* All the links are in reset, and the torrent PHY is in reset
> > */
> > + config_needed = true;
> >
> > - ret = tp_configure_links(tp_data);
> > - if (ret)
> > - goto put_lnk_rst;
> > + } else if (!tp_is_already_configured(tp_data)) {
> > + /* First put all the links in reset, and the PHY in reset */
> > + for (u8 i = 0; i < tp_data->nb_links; ++i)
> > + reset_control_assert(tp_data->links[i].lnk_rst);
> > +
> > + reset_control_assert(tp_data->phy_rst);
> > + config_needed = true;
> > + restore_resets = true;
> > + }
> > +
> > + if (config_needed) {
> > + ret = tp_configure_links(tp_data);
> > + if (ret)
> > + goto failed;
> > + }
> > +
> > + if (restore_resets) {
> > + /* Restore resets in previous state */
> > + reset_control_deassert(tp_data->phy_rst);
> > +
> > + for (u8 i = 0; i < tp_data->nb_links; ++i) {
> > + struct tp_link *link = &tp_data->links[i];
> > +
> > + if (!link->rst_asserted)
> > + reset_control_deassert(link->lnk_rst);
> > + }
> > + }
>
> [Severity: Medium]
> Does the restore_resets path in tp_resume_noirq() leave active links
> uninitialized after deasserting phy_rst and lnk_rst?
>
> When nb_phy_on > 0 and the PHY lost its configuration during suspend,
> restore_resets only deasserts phy_rst and link->lnk_rst. Unlike
> tp_phy_init() and tp_phy_on(), it does not wait for PHY_PMA_CMN_CTRL1[0]
> (CMN ready), re-run tp_dp_phy_init() and tp_dp_run() for active TYPE_DP
> links, or poll PHY_PCS_ISO_LINK_CTRL for active TYPE_PCIE and TYPE_USB
> links, leaving consumers that keep the PHY powered across suspend (such as
> cdns-mhdp8546) with an unstarted link.
This might be an issue. In v3, for each link that has a power count and
which is not in reset, will wait for the link to be "started".
> In addition, when the PHY was pre-configured by the bootloader at probe
> time (tp_data->already_configured == true) and nb_phy_on == 0 at suspend,
> tp_suspend_noirq() clears already_configured without asserting phy_rst or
> lnk_rst. On resume, the !tp_data->nb_phy_on branch assumes all links and
> the PHY are already in reset and runs tp_configure_links() while the
> resets are still deasserted.
This might be an issue. This will be addressed in v3. The resume logic
will be reworked to reconfigure the registers when the torrent PHY was
in reset, or if all PHY are OFF, or if the configuration was lost.
Before writing the register config, the reset will be asserted, then
the reset state will be restored.
--
Benjamin Robin, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com