Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: m-malladi@ti.com
Cc: diogo.ivo@siemens.com, haokexin@gmail.com,
	philippe.schenker@impulsing.ch, devnexen@gmail.com,
	horms@kernel.org, jacob.e.keller@intel.com, pabeni@redhat.com,
	kuba@kernel.org, edumazet@kernel.org, davem@davemloft.net,
	andrew+netdev@lunn.ch, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	vigneshr@ti.com, danishanwar@ti.com
Subject: Re: [PATCH net v3 RESEND 2/3] net: ti: icssg-prueth: Fix phylib stop/start in emac_restart
Date: Mon, 16 Nov 2026 13:54:53 +0000	[thread overview]
Message-ID: <179483729301.3136.8061372443057253896@kernel.org> (raw)
In-Reply-To: <20261112102140.2744508-3-m-malladi@ti.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 2 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] prueth_emac_restart()
  (drivers/net/ethernet/ti/icssg/icssg_prueth.c) now calls phy_stop()…
- [Medium] The new restart_phy error label in prueth_emac_restart()
  restarts phylib even when the firmware is known to be stopped.
- [Medium] The commit message presents phy_stop()/phy_start() only as a
  way to block emac_adjust_link() R30 commands.

--

net: ti: icssg-prueth: Fix phylib stop/start in emac_restart

This patch adds phy_stop() calls for both ports before
prueth_emac_restart() halts the PRU firmware, and phy_start() calls after
the restart. It also turns the early error returns into a goto to a new
restart_phy label. The goal is to keep emac_adjust_link() from sending R30
commands to the PRU while it is stopped.

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> index 591be5c8056b4..ef5dce595f68a 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> @@ -1837,6 +1837,14 @@ static int prueth_emac_restart(struct prueth *prueth)
>  	struct prueth_emac *emac1 = prueth->emac[PRUETH_MAC1];
>  	int ret;
>  
> +	/* Halt phylib to stop emac_adjust_link() from issuing R30 commands
> +	 * to the PRU while the firmware is stopped.
> +	 */
> +	if (emac0->ndev->phydev)
> +		phy_stop(emac0->ndev->phydev);
> +	if (emac1->ndev->phydev)
> +		phy_stop(emac1->ndev->phydev);

[Severity: High]

What happens when one of the ports is down at this point?
emac_phy_connect() runs at probe, so ndev->phydev is never NULL here. None
of the callers check netif_running():

prueth_netdevice_port_link()->icssg_change_mode()->prueth_emac_restart()
prueth_netdevice_port_unlink()->prueth_emac_restart()
prueth_hsr_port_link()->icssg_change_mode()->prueth_emac_restart()
prueth_hsr_port_unlink()->prueth_emac_restart()

prueth_emac_restart() itself checks netif_running() before calling
netif_device_detach(), so it already expects ports to be down sometimes.

A port that was never opened has its PHY in PHY_READY. A port closed by
emac_ndo_stop() has its PHY in PHY_HALTED. phy_stop() WARNs and returns for
both of those states:

drivers/net/phy/phy.c:phy_stop() {
	...
	if (!phy_is_started(phydev) && phydev->state != PHY_DOWN &&
	    phydev->state != PHY_ERROR) {
		WARN(1, "called from state %s\n",
		     phy_state_to_str(phydev->state));
		return;
	}
	...
}

The phy_start() at restart_phy runs unconditionally. It accepts READY and
HALTED, so it resumes the PHY and starts the state machine on a netdev
that is administratively down.

Once autoneg completes, emac_adjust_link() runs for the closed port. It
sends icssg_config_set_speed() and ICSSG_EMAC_PORT_FORWARD commands and
wakes the tx queues. Before this patch, that PHY stayed halted.

If both ports are down, emacs_initialized is 0 and the PRUs are not
running. Then icssg_set_port_state(ICSSG_EMAC_PORT_DISABLE) times out, the
code jumps to restart_phy, and both PHYs are started.

Wouldn't emac_adjust_link() then send R30 commands to the halted PRU cores,
which is the case this patch is meant to prevent?

On the next ifup, emac_ndo_open() calls phy_start() while the PHY is
already in PHY_UP, PHY_NOLINK or PHY_RUNNING. phy_start() then WARNs and
does nothing.

A CAP_NET_ADMIN user can hit this with "ip link set ethX master br0", or
by adding the port to an HSR/PRP master, while the other ICSSG port is
down.

Would it work to record which ports were running, or phy_is_started(),
before calling phy_stop(), and restart only those PHYs?

[Severity: Medium]

The commit message describes phy_stop() and phy_start() only as a way to
block emac_adjust_link() R30 commands. phy_stop() also does more than
that. It sets PHY_HALTED and runs _phy_state_machine() synchronously.
That path clears phydev->link, calls phy_link_down() and returns
PHY_STATE_WORK_SUSPEND, so the PHY gets suspended. phy_start() later
resumes it and restarts autoneg.

So does every bridge or HSR/PRP join or leave that reaches
prueth_emac_restart() now take the physical link down on both ports and
force a full renegotiation? The link partner and the bridge, STP or HSR
layer would see the carrier drop.

Should the commit message mention this?

This also seems to turn the forced resync in prueth_emac_common_start()
into a no-op on the restart path:

prueth_emac_common_start() {
	...
		emac->link = 0;

		mutex_lock(&emac->ndev->phydev->lock);
		emac_adjust_link(emac->ndev);
		mutex_unlock(&emac->ndev->phydev->lock);
	...
}

After phy_stop(), phydev->link is already 0. emac_adjust_link() sees no
state change, so speed and FORWARD programming waits until autoneg
finishes after phy_start().

> +
>  	/* Detach the net_device for both PRUeth ports*/
>  	if (netif_running(emac0->ndev))
>  		netif_device_detach(emac0->ndev);
> @@ -1847,20 +1855,20 @@ static int prueth_emac_restart(struct prueth *prueth)
>  	ret = icssg_set_port_state(emac0, ICSSG_EMAC_PORT_DISABLE);
>  	ret |= icssg_set_port_state(emac1, ICSSG_EMAC_PORT_DISABLE);
>  	if (ret)
> -		return ret;
> +		goto restart_phy;
>  
>  	/* Stop both pru cores for both PRUeth ports*/
>  	ret = prueth_emac_common_stop(prueth);
>  	if (ret) {
>  		dev_err(prueth->dev, "Failed to stop the firmwares");
> -		return ret;
> +		goto restart_phy;
>  	}
>  
>  	/* Start both pru cores for both PRUeth ports */
>  	ret = prueth_emac_common_start(prueth);
>  	if (ret) {
>  		dev_err(prueth->dev, "Failed to start the firmwares");
> -		return ret;
> +		goto restart_phy;
>  	}

[ ... ]

> @@ -1871,6 +1879,13 @@ static int prueth_emac_restart(struct prueth *prueth)
>  	netif_device_attach(emac0->ndev);
>  	netif_device_attach(emac1->ndev);
>  
> +restart_phy:
> +	/* Resume phylib now that the firmware is running again. */
> +	if (emac0->ndev->phydev)
> +		phy_start(emac0->ndev->phydev);
> +	if (emac1->ndev->phydev)
> +		phy_start(emac1->ndev->phydev);

[Severity: Medium]

Does this comment hold on the error paths? Say prueth_emac_common_stop()
succeeds and then prueth_emac_common_start() fails in icssg_config(),
prueth_emac_start() or icss_iep_init(). Its own unwind leaves the PRUs
stopped and classification disabled. The goto restart_phy still calls
phy_start() on both PHYs.

When the state machine runs again, emac_adjust_link() calls
icssg_config_set_speed() and icssg_set_port_state() against the halted
PRU. Each call polls for up to 10ms before it times out.

Isn't that the case the commit message says this patch fixes?

  "to prevent phylib from issuing R30 commands to the stopped PRU"

The label also comes after netif_device_attach(), so both netdevs stay
detached while phylib toggles carrier and tx queues on them. The netdevs
were already left detached on error before this patch.

Should phylib be restarted only after the firmware has actually come back
up?

> +
>  	return ret;
>  }
>

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112102140.2744508-1-m-malladi%40ti.com

  reply	other threads:[~2026-11-16 13:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 10:21 [PATCH net v3 RESEND 0/3] Fix switch mode for offload and non-offload cases Meghana Malladi
2026-11-12 10:21 ` [PATCH net v3 RESEND 1/3] net: ti: icssg-prueth: Fix TX timestamp cleanup crash Meghana Malladi
2026-11-16 13:54   ` netdev-bot+sashiko
2026-11-12 10:21 ` [PATCH net v3 RESEND 2/3] net: ti: icssg-prueth: Fix phylib stop/start in emac_restart Meghana Malladi
2026-11-16 13:54   ` netdev-bot+sashiko [this message]
2026-11-12 10:21 ` [PATCH net v3 RESEND 3/3] net: ti: icssg-prueth: Fix bridge port_vlan and flooding state Meghana Malladi
2026-11-16 13:54   ` netdev-bot+sashiko
2026-11-12 10:26 ` [PATCH net v3 RESEND 0/3] Fix switch mode for offload and non-offload cases netdev-bot+sinfo

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=179483729301.3136.8061372443057253896@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=danishanwar@ti.com \
    --cc=davem@davemloft.net \
    --cc=devnexen@gmail.com \
    --cc=diogo.ivo@siemens.com \
    --cc=edumazet@kernel.org \
    --cc=haokexin@gmail.com \
    --cc=horms@kernel.org \
    --cc=jacob.e.keller@intel.com \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m-malladi@ti.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=philippe.schenker@impulsing.ch \
    --cc=vigneshr@ti.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