amd-xgbe: RX adaptation and PHY handling fixes
Subsystems (3)
Raju Rangoju
maintainerv3 cover amd-xgbe: RX adaptation and PHY handling fixes
This series fixes several issues in the amd-xgbe driver related to RX adaptation and PHY handling in 10GBASE-KR mode, particularly when auto-negotiation is disabled.
Patch 1 fixes link status handling during RX adaptation by correctly reading the latched link status bit so transient link drops are detected without losing the current state.
Patch 2 prevents CRC errors that can occur when performing RX adaptation with auto-negotiation turned off. The driver now stops TX/RX before re-triggering RX adaptation and only re-enables traffic once adaptation completes and the link is confirmed up, ensuring packets are not corrupted during the adaptation window.
Patch 3 restores the intended ordering of PHY reset relative to phy_start(), making sure PHY settings are reset before the PHY is started instead of afterwards.
Changes since v1:
- change the data_path_stopped flag to boolean type as it is only used as a true/false indicator.
Changes since v2:
- use the correct fixes tag for the link status handling patch
- change the data_path_stopped flag to be cleared in phy_start() to ensure it is reset on device restart
Raju Rangoju (3):
amd-xgbe: fix link status handling in xgbe_rx_adaptation
amd-xgbe: prevent CRC errors during RX adaptation with AN disabled
amd-xgbe: reset PHY settings before starting PHY
drivers/net/ethernet/amd/xgbe/xgbe-drv.c | 19 ++--- drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c | 82 +++++++++++++++++++-- drivers/net/ethernet/amd/xgbe/xgbe.h | 4 + 3 files changed, 89 insertions(+), 16 deletions(-)
Signature · 1 line
2.34.1
Raju Rangoju
maintainerPATCH v3 1/3 amd-xgbe: fix link status handling in xgbe_rx_adaptation
The link status bit is latched low to allow detection of momentary link drops. If the status indicates that the link is already down, read it again to obtain the current state.
--- drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c +14 -5
@@ -1942,7 +1942,7 @@ static void xgbe_set_rx_adap_mode(struct xgbe_prv_data *pdata,static void xgbe_rx_adaptation (struct xgbe_prv_data *pdata) {struct xgbe_phy_data *phy_data = pdata->phy_data; -unsigned int reg; +int reg;/* step 2: force PCS to send RX_ADAPT Req to PHY */ XMDIO_WRITE_BITS(pdata, MDIO_MMD_PMAPMD, MDIO_PMA_RX_EQ_CTRL4,
@@ -1964,11 +1964,20 @@ static void xgbe_rx_adaptation(struct xgbe_prv_data *pdata)/* Step 4: Check for Block lock */ -/* Link status is latched low, so read once to clear -* and then read again to get current state -*/ - reg =XMDIO_READ (pdata,MDIO_MMD_PCS ,MDIO_STAT1 ); reg =XMDIO_READ (pdata,MDIO_MMD_PCS ,MDIO_STAT1 ); +if (reg <0 ) + goto set_mode; + +/* Link status is latched low so that momentary link drops +* can be detected. If link was already down read again +* to get the latest state. +*/ +if (!pdata->phy.link && !(reg &MDIO_STAT1_LSTATUS )) { + reg =XMDIO_READ (pdata,MDIO_MMD_PCS ,MDIO_STAT1 ); +if (reg <0 ) + goto set_mode; + } +if (reg &MDIO_STAT1_LSTATUS ) {/* If the block lock is found, update the helpers * and declare the link up
Signature · 1 line
2.34.1
Raju Rangoju
maintainerPATCH v3 2/3 amd-xgbe: prevent CRC errors during RX adaptation with AN disabled
In reply to Raju RangojuWhen operating in 10GBASE-KR mode with auto-negotiation disabled and RX adaptation enabled, CRC errors can occur during the RX adaptation process. This happens because the driver continues transmitting and receiving packets while adaptation is in progress.
Fix this by stopping TX/RX immediately when the link goes down and RX adaptation needs to be re-triggered, and only re-enabling TX/RX after adaptation completes and the link is confirmed up. Introduce a flag to track whether TX/RX was disabled for adaptation so it can be restored correctly.
This prevents packets from being transmitted or received during the RX adaptation window and avoids CRC errors from corrupted frames.
The flag tracking the data path state is synchronized with hardware state in xgbe_start() to prevent stale state after device restarts. This ensures that after a restart cycle (where xgbe_stop disables TX/RX and xgbe_start re-enables them), the flag correctly reflects that the data path is active.
---
Changes since v1:
- Change the data_path_stopped flag to boolean type
as it is only used as a true/false indicator.
Changes since v2:
- change the data_path_stopped flag to be cleared in phy_start() to ensure it is reset on device restart
drivers/net/ethernet/amd/xgbe/xgbe-drv.c | 4 ++ drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c | 63 ++++++++++++++++++++- drivers/net/ethernet/amd/xgbe/xgbe.h | 4 ++ 3 files changed, 69 insertions(+), 2 deletions(-)
drivers/net/ethernet/amd/xgbe/xgbe-drv.c +4 -0
@@ -1277,6 +1277,10 @@ static int xgbe_start(struct xgbe_prv_data *pdata) hw_if->enable_tx (pdata); hw_if->enable_rx (pdata); +/* Synchronize flag with hardware state after enabling TX/RX. +* This prevents stale state after device restart cycles. +*/ + pdata->data_path_stopped = false;udp_tunnel_nic_reset_ntf (netdev);
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c +61 -2
88 lines not on this page · raw message
drivers/net/ethernet/amd/xgbe/xgbe.h +4 -0
@@ -1266,6 +1266,10 @@ struct xgbe_prv_data {bool en_rx_adap;int rx_adapt_retries;bool rx_adapt_done; +/* Flag to track if data path (TX/RX) was stopped for RX adaptation. +* This prevents packet corruption during the adaptation window. +*/ +bool data_path_stopped;bool mode_set;bool sph; };
Signature · 1 line
2.34.1
Paolo Abeni
maintainerRe: [PATCH v3 net 2/3] amd-xgbe: prevent CRC errors during RX adaptation with AN disabled
Quoted 134 lines · Raju Rangoju
When operating in 10GBASE-KR mode with auto-negotiation disabled and RX adaptation enabled, CRC errors can occur during the RX adaptation process. This happens because the driver continues transmitting and receiving packets while adaptation is in progress.
Fix this by stopping TX/RX immediately when the link goes down and RX adaptation needs to be re-triggered, and only re-enabling TX/RX after adaptation completes and the link is confirmed up. Introduce a flag to track whether TX/RX was disabled for adaptation so it can be restored correctly.
This prevents packets from being transmitted or received during the RX adaptation window and avoids CRC errors from corrupted frames.
The flag tracking the data path state is synchronized with hardware state in
xgbe_start()to prevent stale state after device restarts. This ensures that after a restart cycle (wherexgbe_stopdisables TX/RX andxgbe_startre-enables them), the flag correctly reflects that the data path is active.Fixes 4f3b20bfbb75 ("amd-xgbe: add support for rx-adaptation")Signed-off-by Raju Rangoju <[email protected]>---
Changes since v1:
- Change thedata_path_stoppedflag to boolean type
as it is only used as a true/false indicator.
Changes since v2:
- change thedata_path_stoppedflag to be cleared inphy_start()to ensure it is reset on device restartdrivers/net/ethernet/amd/xgbe/xgbe-drv.c | 4 ++ drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c | 63 ++++++++++++++++++++- drivers/net/ethernet/amd/xgbe/xgbe.h | 4 ++ 3 files changed, 69 insertions(+), 2 deletions(-)drivers/net/ethernet/amd/xgbe/xgbe-drv.c +4
-0@@ -1277,6 +1277,10 @@ static int xgbe_start(struct xgbe_prv_data *pdata) hw_if->enable_tx (pdata); hw_if->enable_rx (pdata); +/* Synchronize flag with hardware state after enabling TX/RX. +* This prevents stale state after device restart cycles. +*/ + pdata->data_path_stopped = false;udp_tunnel_nic_reset_ntf (netdev);drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c +57
-1@@ -2017,6 +2017,48 @@ static void xgbe_phy_rx_adaptation(struct xgbe_prv_data *pdata)xgbe_rx_adaptation (pdata); } +/* +* xgbe_phy_stop_data_path - Stop TX/RX to prevent packet corruption +* @pdata: driver private data +* +* This function stops the data path (TX and RX) to prevent packet +* corruption during critical PHY operations like RX adaptation. +* Must be called before initiating RX adaptation when link goes down. +*/ +static void xgbe_phy_stop_data_path (struct xgbe_prv_data *pdata) +{ +if (pdata->data_path_stopped) +return ; + +/* Stop TX/RX to prevent packet corruption during RX adaptation */ + pdata->hw_if.disable_tx (pdata); + pdata->hw_if.disable_rx (pdata); + pdata->data_path_stopped = true; + +netif_dbg (pdata, link, pdata->netdev, +"stopping data path for RX adaptation\n" ); +} + +/* +* xgbe_phy_start_data_path - Re-enable TX/RX after RX adaptation +* @pdata: driver private data +* +* This function re-enables the data path (TX and RX) after RX adaptation +* has completed successfully. Only called when link is confirmed up. +*/ +static void xgbe_phy_start_data_path (struct xgbe_prv_data *pdata) +{ +if (!pdata->data_path_stopped) +return ; + + pdata->hw_if.enable_rx (pdata); + pdata->hw_if.enable_tx (pdata); + pdata->data_path_stopped = false; + +netif_dbg (pdata, link, pdata->netdev, +"restarting data path after RX adaptation\n" ); +} +static void xgbe_phy_rx_reset (struct xgbe_prv_data *pdata) {int reg;@@ -2826,13 +2868,27 @@ static int xgbe_phy_link_status(struct xgbe_prv_data *pdata, int *an_restart)if (pdata->en_rx_adap) {/* if the link is available and adaptation is done, * declare link up +* +* Note: When link is up and adaptation is done, we can +* safely re-enable the data path if it was stopped +* for adaptation. */ -if ((reg &MDIO_STAT1_LSTATUS ) && pdata->rx_adapt_done) +if ((reg &MDIO_STAT1_LSTATUS ) && pdata->rx_adapt_done) { +xgbe_phy_start_data_path (pdata);return 1 ; + }/* If either link is not available or adaptation is not done, * retrigger the adaptation logic. (if the mode is not set, * then issue mailbox command first) */ + +/* CRITICAL: Stop data path BEFORE triggering RX adaptation +* to prevent CRC errors from packets corrupted during +* the adaptation process. This is especially important +* when AN is OFF in 10G KR mode. +*/ +xgbe_phy_stop_data_path (pdata); +if (pdata->mode_set) {xgbe_phy_rx_adaptation (pdata); }else {@@ -2840,8 +2896,11 @@ static int xgbe_phy_link_status(struct xgbe_prv_data *pdata, int *an_restart)xgbe_phy_set_mode (pdata, phy_data->cur_mode);
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c static int xgbe_phy_link_status(struct xgbe_prv_data *pdata, int *an_restart) · line 2905
Quoted 10 lines
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c +4
-1} -if (pdata->rx_adapt_done) +if (pdata->rx_adapt_done) { +/* Adaptation complete, safe to re-enable data path */ +xgbe_phy_start_data_path (pdata);return 1 ; + } }else if (reg &MDIO_STAT1_LSTATUS )return 1 ;
AI says:
---
What happens if en_rx_adap transitions from true to false while data_path_stopped is true?
Consider this scenario during an SFP hot-swap from a passive cable (which enables rx_adap) to an active cable (which disables rx_adap):
1. Initially with passive cable: en_rx_adap=true, link down
2. xgbe_phy_link_status() enters the if (pdata->en_rx_adap) block
3. xgbe_phy_stop_data_path() sets data_path_stopped=true and disables TX/RX
4. Hot-swap to active cable: xgbe_phy_sfi_mode() sets en_rx_adap=0
5. Next call to xgbe_phy_link_status(): en_rx_adap is now false
6. The entire if (pdata->en_rx_adap) block is skipped
7. Link is up, so falls through to: else if (reg & MDIO_STAT1_LSTATUS) return 1
8. Returns link up, but TX/RX hardware remains disabled
At this point, data_path_stopped=true and the hardware TX/RX is disabled, but there's no code path to re-enable it when en_rx_adap becomes false (except a full device restart cycle through xgbe_stop + xgbe_start).
Would it be safer to check data_path_stopped in the else branch and call xgbe_phy_start_data_path() if needed before returning link up?
---
I think the remark is not correct, as AFAICS xgbe_phy_sfi_mode() is only invoked by xgbe_phy_link_status(), after checking en_rx_adap and ev. re-starting the ring. Reporting the remark here in case I misread the code and this actually need a follow-up.
/P
Raju Rangoju
maintainerPATCH v3 3/3 amd-xgbe: reset PHY settings before starting PHY
In reply to Raju Rangojucommit f93505f35745 ("amd-xgbe: let the MAC manage PHY PM") moved xgbe_phy_reset() from xgbe_open() to xgbe_start(), placing it after phy_start(). As a result, the PHY settings were being reset after the PHY had already started.
Reorder the calls so that the PHY settings are reset before phy_start() is invoked.
--- drivers/net/ethernet/amd/xgbe/xgbe-drv.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
drivers/net/ethernet/amd/xgbe/xgbe-drv.c +6 -9
@@ -1271,6 +1271,12 @@ static int xgbe_start(struct xgbe_prv_data *pdata)if (ret) goto err_napi; +/* Reset the phy settings */ + ret =xgbe_phy_reset (pdata); +if (ret) + goto err_irqs; + +/* Start the phy */ ret = phy_if->phy_start (pdata);if (ret) goto err_irqs;
@@ -1284,11 +1290,6 @@ static int xgbe_start(struct xgbe_prv_data *pdata)udp_tunnel_nic_reset_ntf (netdev); -/* Reset the phy settings */ - ret =xgbe_phy_reset (pdata); -if (ret) - goto err_txrx; -netif_tx_start_all_queues (netdev);xgbe_start_timers (pdata);
@@ -1298,10 +1299,6 @@ static int xgbe_start(struct xgbe_prv_data *pdata)return 0 ; -err_txrx: - hw_if->disable_rx (pdata); - hw_if->disable_tx (pdata); - err_irqs:xgbe_free_irqs (pdata);
Signature · 1 line
2.34.1
This series was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 9 lines · On Fri, 6 Mar 2026 16:46:26 +0530 you wrote:
This series fixes several issues in the amd-xgbe driver related to RX adaptation and PHY handling in 10GBASE-KR mode, particularly when auto-negotiation is disabled.
Patch 1 fixes link status handling during RX adaptation by correctly reading the latched link status bit so transient link drops are detected without losing the current state.
[...]
Here is the summary with links:
- [v3,net,1/3] amd-xgbe: fix link status handling in xgbe_rx_adaptation
https://git.kernel.org/netdev/net/c/6485cb96be5c - [v3,net,2/3] amd-xgbe: prevent CRC errors during RX adaptation with AN disabled https://git.kernel.org/netdev/net/c/27a4dd0c702b - [v3,net,3/3] amd-xgbe: reset PHY settings before starting PHY https://git.kernel.org/netdev/net/c/a8ba129af468
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html