amd-xgbe: RX adaptation and PHY handling fixes
Subsystems (3)
Raju Rangoju
maintainerv2 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:
- Patch 2: change the rx_adapt_data_path_stopped flag to boolean type as it is only used as a true/false indicator.
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 | 15 ++-- drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c | 78 +++++++++++++++++++-- drivers/net/ethernet/amd/xgbe/xgbe.h | 4 ++ 3 files changed, 83 insertions(+), 14 deletions(-)
Signature · 1 line
2.34.1
Raju Rangoju
maintainerPATCH v2 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 | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c +13 -4
@@ -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
Paolo Abeni
maintainerRe: [PATCH v2 net 1/3] amd-xgbe: fix link status handling in xgbe_rx_adaptation
Quoted 5 lines · Raju Rangoju
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c +0
-0
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c static void xgbe_rx_adaptation(struct xgbe_prv_data *pdata) · line 1968
Quoted 9 lines
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c +1
-4@@ -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 )
Coccinelle says:
/srv/nipa-builds-contest/testing/wt-cocci/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c:1968:5-8:
WARNING: Unsigned expression compared with zero: reg <
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c static void xgbe_rx_adaptation(struct xgbe_prv_data *pdata) · line 1977
Quoted 9 lines
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c +9
-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 )
Same here.
/P
Raju Rangoju
maintainerPATCH v2 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.
---
Changes since v1:
- Change the rx_adapt_data_path_stopped flag to boolean type as it is only used as a true/false indicator.
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c | 61 ++++++++++++++++++++- drivers/net/ethernet/amd/xgbe/xgbe.h | 4 ++ 2 files changed, 64 insertions(+), 1 deletion(-)
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c +60 -1
@@ -2017,6 +2017,50 @@ 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->rx_adapt_data_path_stopped) +return ; + +netif_dbg (pdata, link, pdata->netdev, +"stopping data path for RX adaptation\n" ); + +/* Stop TX/RX to prevent packet corruption during RX adaptation */ + pdata->hw_if.disable_tx (pdata); + pdata->hw_if.disable_rx (pdata); + + pdata->rx_adapt_data_path_stopped = true; +} + +/* +* 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->rx_adapt_data_path_stopped) +return ; + +netif_dbg (pdata, link, pdata->netdev, +"restarting data path after RX adaptation\n" ); + + pdata->hw_if.enable_rx (pdata); + pdata->hw_if.enable_tx (pdata); + + pdata->rx_adapt_data_path_stopped = false; +} +static void xgbe_phy_rx_reset (struct xgbe_prv_data *pdata) {int reg;
@@ -2826,6 +2870,10 @@ 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)return 1 ;
@@ -2833,6 +2881,14 @@ static int xgbe_phy_link_status(struct xgbe_prv_data *pdata, int *an_restart)* 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); } -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 ;
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 rx_adapt_data_path_stopped;bool mode_set;bool sph; };
Signature · 1 line
2.34.1
Raju Rangoju
maintainerPATCH v2 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;
@@ -1280,11 +1286,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);
@@ -1294,10 +1295,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