net: enetc: do not transmit redirected XDP frames when the link is down
Subsystems (5)
Wei Fang
maintainerPATCH v3 1/1 net: enetc: do not transmit redirected XDP frames when the link is down
In the current implementation, the enetc_xdp_xmit() always transmits redirected XDP frames even if the link is down, but the frames cannot be transmitted from TX BD rings when the link is down, so the frames are still kept in the TX BD rings. If the XDP program is uninstalled, users will see the following warning logs.
fsl_enetc 0000:00:00.0 eno0: timeout for tx ring #6 clear
More worse, the TX BD ring cannot work properly anymore, because the HW PIR and CIR are not equal after the re-initialization of the TX BD ring. At this point, the BDs between CIR and PIR are invalid, which will cause a hardware malfunction.
Another reason is that there is internal context in the ring prefetch logic that will retain the state from the first incarnation of the ring and continue prefetching from the stale location when we re-initialize the ring. The internal context is only reset by an FLR. That is to say, for LS1028A ENETC, software cannot set the HW CIR and PIR when initializing the TX BD ring.
It does not make sense to transmit redirected XDP frames when the link is down. Add a link status check to prevent transmission in this condition. This fixes part of the issue, but more complex cases remain. For example, the TX BD ring may still contain unsent frames when the link goes down. Those situations require additional patches, which will build on this one.
---
v3 changes:
1. Improve the commit message
2. Collect Reviewed-by tag
v2: https://lore.kernel.org/imx/[email protected]/
v2 changes:
Improve the commit message
v1: https://lore.kernel.org/imx/[email protected]/
--- drivers/net/ethernet/freescale/enetc/enetc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/freescale/enetc/enetc.c +2 -1
@@ -1778,7 +1778,8 @@ int enetc_xdp_xmit(struct net_device *ndev, int num_frames,int xdp_tx_bd_cnt, i, k;int xdp_tx_frm_cnt =0 ; -if (unlikely (test_bit (ENETC_TX_DOWN , &priv->flags))) +if (unlikely (test_bit (ENETC_TX_DOWN , &priv->flags) || + !netif_carrier_ok (ndev)))return -ENETDOWN ;enetc_lock_mdio ();
Signature · 1 line
2.34.1
Quoted 60 lines · Wei Fang
In the current implementation, the
enetc_xdp_xmit()always transmits redirected XDP frames even if the link is down, but the frames cannot be transmitted from TX BD rings when the link is down, so the frames are still kept in the TX BD rings. If the XDP program is uninstalled, users will see the following warning logs.
fsl_enetc0000:00:00.0 eno0: timeout for tx ring #6 clearMore worse, the TX BD ring cannot work properly anymore, because the HW PIR and CIR are not equal after the re-initialization of the TX BD ring. At this point, the BDs between CIR and PIR are invalid, which will cause a hardware malfunction.
Another reason is that there is internal context in the ring prefetch logic that will retain the state from the first incarnation of the ring and continue prefetching from the stale location when we re-initialize the ring. The internal context is only reset by an FLR. That is to say, for LS1028A ENETC, software cannot set the HW CIR and PIR when initializing the TX BD ring.
It does not make sense to transmit redirected XDP frames when the link is down. Add a link status check to prevent transmission in this condition. This fixes part of the issue, but more complex cases remain. For example, the TX BD ring may still contain unsent frames when the link goes down. Those situations require additional patches, which will build on this one.
Fixes 9d2b68cc108d ("net: enetc: add support for XDP_REDIRECT")Signed-off-by Wei Fang <[email protected]>Reviewed-by Frank Li <[email protected]>---
v3 changes:
1. Improve the commit message
2. Collect Reviewed-by tag
v2: https://lore.kernel.org/imx/[email protected]/
v2 changes:
Improve the commit message
v1: https://lore.kernel.org/imx/[email protected]/--- drivers/net/ethernet/freescale/enetc/enetc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/net/ethernet/freescale/enetc/enetc.c +2
-1@@ -1778,7 +1778,8 @@ int enetc_xdp_xmit(struct net_device *ndev, int num_frames,int xdp_tx_bd_cnt, i, k;int xdp_tx_frm_cnt =0 ; -if (unlikely (test_bit (ENETC_TX_DOWN , &priv->flags))) +if (unlikely (test_bit (ENETC_TX_DOWN , &priv->flags) || + !netif_carrier_ok (ndev)))return -ENETDOWN ;enetc_lock_mdio ();Signature · 1 line
2.34.1
Quoted 27 lines · Wei Fang
In the current implementation, the
enetc_xdp_xmit()always transmits redirected XDP frames even if the link is down, but the frames cannot be transmitted from TX BD rings when the link is down, so the frames are still kept in the TX BD rings. If the XDP program is uninstalled, users will see the following warning logs.
fsl_enetc0000:00:00.0 eno0: timeout for tx ring #6 clearMore worse, the TX BD ring cannot work properly anymore, because the HW PIR and CIR are not equal after the re-initialization of the TX BD ring. At this point, the BDs between CIR and PIR are invalid, which will cause a hardware malfunction.
Another reason is that there is internal context in the ring prefetch logic that will retain the state from the first incarnation of the ring and continue prefetching from the stale location when we re-initialize the ring. The internal context is only reset by an FLR. That is to say, for LS1028A ENETC, software cannot set the HW CIR and PIR when initializing the TX BD ring.
It does not make sense to transmit redirected XDP frames when the link is down. Add a link status check to prevent transmission in this condition. This fixes part of the issue, but more complex cases remain. For example, the TX BD ring may still contain unsent frames when the link goes down. Those situations require additional patches, which will build on this one.
Quoted 5 lines
Fixes 9d2b68cc108d ("net: enetc: add support for XDP_REDIRECT")Signed-off-by Wei Fang <[email protected]>Reviewed-by Frank Li <[email protected]>---
More patches to fix the other conditions are coming. I can confirm that they do not render this one useless. xdp_ok_fwd_dev() only tests that the device is administratively up.
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 9 lines · On Thu, 11 Dec 2025 10:09:19 +0800 you wrote:
In the current implementation, the
enetc_xdp_xmit()always transmits redirected XDP frames even if the link is down, but the frames cannot be transmitted from TX BD rings when the link is down, so the frames are still kept in the TX BD rings. If the XDP program is uninstalled, users will see the following warning logs.
fsl_enetc0000:00:00.0 eno0: timeout for tx ring #6 clear[...]
Here is the summary with links:
- [v3,net] net: enetc: do not transmit redirected XDP frames when the link is down
https://git.kernel.org/netdev/net/c/2939203ffee8
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html