amd-xgbe: synchronize KR training with device operations
Subsystems (3)
Raju Rangoju
maintainerPATCH v2 1/1 amd-xgbe: synchronize KR training with device operations
During 10GBASE-KR link training, the PHY state machine can be corrupted if device stop or rate change operations are initiated while training is in progress. This manifests as:
- Link stability issues after interface down/up cycles
- PHY state machine lockups requiring a full driver reset
- Intermittent link failures on Inphi re-driver configurations
The root cause is that the firmware mailbox operations for device stop and rate changes can interfere with ongoing KR training sequences, leaving the PHY in an inconsistent state.
Add synchronization to prevent device operations from interrupting active KR training:
- Introduce a mailbox mutex to serialize firmware command access
- Wait for KR training completion (or timeout) before proceeding with stop/rate change operations
- Only wait when KR training is actually active (KR mode with autoneg enabled or Inphi re-driver present)
- Use a 500ms timeout to handle hung training sequences
The mailbox mutex protects the critical section of firmware command submission and completion checking, preventing concurrent mailbox access from multiple code paths.
Testing on AMD platforms with both direct-attach and Inphi re-driver configurations shows this eliminates PHY state corruption during interface operations and link changes.
---
Changes since v1:
- use scoped_guard() instead of guard() for functions longer than 20 lines
drivers/net/ethernet/amd/xgbe/xgbe-drv.c | 2 + drivers/net/ethernet/amd/xgbe/xgbe-main.c | 1 + drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c | 77 ++++++++++++++++++--- drivers/net/ethernet/amd/xgbe/xgbe.h | 5 ++ 4 files changed, 74 insertions(+), 11 deletions(-)
drivers/net/ethernet/amd/xgbe/xgbe-drv.c +2 -0
@@ -1321,6 +1321,8 @@ static void xgbe_stop(struct xgbe_prv_data *pdata)DBGPR ("-->xgbe_stop\n" ); +xgbe_check_kr_training_in_progress (pdata); +if (test_bit (XGBE_STOPPED , &pdata->dev_state))return ;
drivers/net/ethernet/amd/xgbe/xgbe-main.c +1 -0
@@ -78,6 +78,7 @@ struct xgbe_prv_data *xgbe_alloc_pdata(struct device *dev)spin_lock_init (&pdata->xpcs_lock);mutex_init (&pdata->rss_mutex); +mutex_init (&pdata->mailbox_lock);spin_lock_init (&pdata->tstamp_lock);mutex_init (&pdata->i2c_mutex);init_completion (&pdata->i2c_complete);
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c +66 -11
98 lines not on this page · raw message
drivers/net/ethernet/amd/xgbe/xgbe.h +5 -0
@@ -202,6 +202,7 @@#define XGBE_AN_MS_TIMEOUT 500#define XGBE_LINK_TIMEOUT 5#define XGBE_KR_TRAINING_WAIT_ITER 50 +#define XGBE_KR_TRAINING_WAIT_MS 100#define XGBE_SGMII_AN_LINK_DUPLEX BIT(1)#define XGBE_SGMII_AN_LINK_SPEED (BIT(2) | BIT(3))
@@ -1015,6 +1016,9 @@ struct xgbe_prv_data {/* RSS addressing mutex */ struct mutex rss_mutex; +/* Firmware mailbox mutex */ +struct mutex mailbox_lock; +/* Flags representing xgbe_state */ unsigned long dev_state;
@@ -1252,6 +1256,7 @@ struct xgbe_prv_data { };/* Function prototypes*/ +void xgbe_check_kr_training_in_progress (struct xgbe_prv_data *pdata);struct xgbe_prv_data *xgbe_alloc_pdata (struct device *);void xgbe_free_pdata (struct xgbe_prv_data *);void xgbe_set_counts (struct xgbe_prv_data *);
Signature · 1 line
2.34.1
Jakub Kicinski
maintainerQuoted 7 lines · On Wed, 18 Mar 2026 14:46:08 +0530 Raju Rangoju wrote:
During 10GBASE-KR link training, the PHY state machine can be corrupted if device stop or rate change operations are initiated while training is in progress. This manifests as:
- Link stability issues after interface down/up cycles
- PHY state machine lockups requiring a full driver reset
- Intermittent link failures on Inphi re-driver configurations
Please take a look at this AI review, the locking race looks legit:
https://sashiko.dev/#/message/20260318091608.1266381-1-Raju.Rangoju%40amd.com
Signature · 1 line
pw-bot: cr