net/axgbe: serialize PHY and link status access
PATCH 1/1 net/axgbe: serialize PHY and link status access
From: Ajit Kumar <[email protected]>
Concurrent link status polling and PHY access can result in simultaneous I2C/MDIO bus transactions. On systems with multiple AXGBE ports this may lead to I2C transfer failures such as -EAGAIN, -ENOTCONN, or -ETIMEDOUT and can cause incorrect link status reporting.
Serialize access to shared PHY communication resources by protecting PHY status updates and introducing a mutex around I2C/MDIO ownership acquisition. Also add retry delays for recoverable I2C transfer failures.
--- drivers/net/axgbe/axgbe_ethdev.c | 3 +++ drivers/net/axgbe/axgbe_ethdev.h | 1 + drivers/net/axgbe/axgbe_phy_impl.c | 18 ++++++++++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-)
drivers/net/axgbe/axgbe_ethdev.c +3 -0
@@ -760,7 +760,9 @@ axgbe_dev_link_update(struct rte_eth_dev *dev,PMD_INIT_FUNC_TRACE ();rte_delay_ms (800 ); +pthread_mutex_lock (&pdata->link_status_mutex); pdata->phy_if.phy_status (pdata); +pthread_mutex_unlock (&pdata->link_status_mutex);memset (&link,0 ,sizeof (struct rte_eth_link )); link.link_duplex = pdata->phy.duplex;
@@ -2406,6 +2408,7 @@ eth_axgbe_dev_init(struct rte_eth_dev *eth_dev)rte_thread_mutex_init_shared (&pdata->i2c_mutex);rte_thread_mutex_init_shared (&pdata->an_mutex);rte_thread_mutex_init_shared (&pdata->phy_mutex); +rte_thread_mutex_init_shared (&pdata->link_status_mutex); ret = pdata->phy_if.phy_init (pdata);if (ret) {
drivers/net/axgbe/axgbe_ethdev.h +1 -0
@@ -654,6 +654,7 @@ struct axgbe_port {pthread_mutex_t i2c_mutex;pthread_mutex_t an_mutex;pthread_mutex_t phy_mutex; +pthread_mutex_t link_status_mutex;/* Flow control settings */ unsigned int pause_autoneg;
drivers/net/axgbe/axgbe_phy_impl.c +16 -2
@@ -531,6 +531,10 @@ static int axgbe_phy_redrv_write(struct axgbe_port *pdata, unsigned int reg,return ret; } +#define AXGBE_I2C_RETRYABLE (_ret) \ + ((_ret) == -EAGAIN || (_ret) == -ENOTCONN || (_ret) == -ETIMEDOUT) +#define AXGBE_I2C_RETRY_DELAY_MS 2 +static int axgbe_phy_i2c_read (struct axgbe_port *pdata,unsigned int target,void *reg,unsigned int reg_len,void *val,unsigned int val_len)
@@ -547,8 +551,10 @@ static int axgbe_phy_i2c_read(struct axgbe_port *pdata, unsigned int target, i2c_op.buf = reg; ret =axgbe_phy_i2c_xfer (pdata, &i2c_op);if (ret) { -if ((ret == -EAGAIN ) && retry--) +if (AXGBE_I2C_RETRYABLE (ret) && retry--) { +rte_delay_ms (AXGBE_I2C_RETRY_DELAY_MS ); goto again1; + }return ret; }
@@ -561,8 +567,10 @@ static int axgbe_phy_i2c_read(struct axgbe_port *pdata, unsigned int target, i2c_op.len = val_len; i2c_op.buf = val; ret =axgbe_phy_i2c_xfer (pdata, &i2c_op); -if ((ret == -EAGAIN ) && retry--) +if (ret &&AXGBE_I2C_RETRYABLE (ret) && retry--) { +rte_delay_ms (AXGBE_I2C_RETRY_DELAY_MS ); goto again2; + }return ret; }
@@ -605,9 +613,12 @@ static int axgbe_phy_sfp_get_mux(struct axgbe_port *pdata)return axgbe_phy_i2c_xfer (pdata, &i2c_op); } +static pthread_mutex_t axgbe_i2c_mdio_bus_mutex =PTHREAD_MUTEX_INITIALIZER ; +static void axgbe_phy_put_comm_ownership (struct axgbe_port *pdata) {pthread_mutex_unlock (&pdata->phy_mutex); +pthread_mutex_unlock (&axgbe_i2c_mdio_bus_mutex); }static int axgbe_phy_get_comm_ownership (struct axgbe_port *pdata)
@@ -616,6 +627,8 @@ static int axgbe_phy_get_comm_ownership(struct axgbe_port *pdata)uint64_t timeout;unsigned int mutex_id; +pthread_mutex_lock (&axgbe_i2c_mdio_bus_mutex); +/* The I2C and MDIO/GPIO bus is multiplexed between multiple devices, * the driver needs to take the software mutex and then the hardware * mutexes before being able to use the busses.
@@ -648,6 +661,7 @@ static int axgbe_phy_get_comm_ownership(struct axgbe_port *pdata) }pthread_mutex_unlock (&pdata->phy_mutex); +pthread_mutex_unlock (&axgbe_i2c_mdio_bus_mutex);PMD_DRV_LOG_LINE (ERR ,"unable to obtain hardware mutexes" );
Signature · 1 line
2.43.0
Quoted 8 lines · On Thu, 12 Nov 2026 19:26:11 +0530 Ajit Kumar <[email protected]> wrote:
From: Ajit Kumar <[email protected]>
Concurrent link status polling and PHY access can result in simultaneous I2C/MDIO bus transactions. On systems with multiple AXGBE ports this may lead to I2C transfer failures such as
-EAGAIN,-ENOTCONN, or-ETIMEDOUTand can cause incorrect link status reporting.
Quoted 7 lines
Serialize access to shared PHY communication resources by protecting PHY status updates and introducing a mutex around I2C/MDIO ownership acquisition. Also add retry delays for recoverable I2C transfer failures.
Signed-off-by Ajit Kumar <[email protected]>---
AI found some issues that still need addressing before merge
Subject: Re: [PATCH] net/axgbe: serialize PHY and link status access
The global axgbe_i2c_mdio_bus_mutex is the right fix; it matches xgbe_phy_comm_lock in the Linux xgbe driver, which DPDK lost when the global lock became the per-port pdata->phy_mutex. The other two changes do not belong with it as written.
Warning
1. link_status_mutex does nothing useful.
It is per-port and only taken in axgbe_dev_link_update(). It cannot serialize bus access between ports (the problem in the commit message); the new bus mutex already does that inside axgbe_phy_get_comm_ownership(). It is also not taken by axgbe_dev_interrupt_handler() -> an_isr, the only other path touching PHY/AN state. Two concurrent link_update calls on the same port are control-vs-control, which ethdev does not promise to make safe. If they can happen, the lock must cover the ISR too; if not, there is no point in it. Drop the mutex, the struct member and the init.
2. Retrying -ETIMEDOUT and -ENOTCONN.
axgbe_i2c_xfer() already waits up to 1 s before returning -ETIMEDOUT. One retry doubles that per phase, and it now happens with the global bus mutex held, so every other port's link_update blocks behind it. -ENOTCONN is an address NAK (IC_TX_ABRT_7B_ADDR_NOACK), meaning nothing answered at that target, not bus contention.
If the bus mutex fixes the concurrent access, these errors should not occur any more, and retrying them hides a different fault. Keep the -EAGAIN (arbitration lost) retry only, or explain in the commit message what still causes the other two after serialization.
In the second hunk "ret &&" is redundant, and the closing brace in the first hunk is indented one level too shallow:
if (ret) {
if (ret == -EAGAIN && retry--) {
rte_delay_ms(AXGBE_I2C_RETRY_DELAY_MS);
goto again1;
}
return ret;
}
...
if (ret == -EAGAIN && retry--) {
rte_delay_ms(AXGBE_I2C_RETRY_DELAY_MS);
goto again2;
}3. Missing Fixes and stable tags. The per-port lock dates from the initial PHY code:
Info
4. The static mutex only covers ports in one process. When ports of the same device belong to different DPDK processes, or one port stays with the kernel xgbe driver, the only arbitration is the hardware mutex. axgbe_phy_get_comm_ownership() writes AXGBE_MUTEX_RELEASE to XP_I2C_MUTEX/XP_MDIO_MUTEX unconditionally before acquiring, which can take ownership away from the other agent. This bug is older than the patch, but the commit message should say the fix applies to ports in a single process.
5. Suggested commit message body, once 1 and 2 are addressed:
The I2C and MDIO buses are shared by all ports on the device. axgbe_phy_get_comm_ownership() takes the per-port phy_mutex, which does not stop two ports in the same process from using the bus at once, causing I2C failures and wrong link status.
Add a driver-wide mutex taken before the per-port one, as the Linux xgbe driver does.
PATCH v2 1/1 net/axgbe: serialize PHY and link status access
In reply to Ajit KumarFrom: Ajit Kumar <[email protected]>
The I2C and MDIO buses are shared by all ports on the device. axgbe_phy_get_comm_ownership() takes the per-port phy_mutex, which does not stop two ports in the same process from using the bus at once, causing I2C failures (-EAGAIN, -ENOTCONN, -ETIMEDOUT) and incorrect link status reporting.
Add a driver-wide mutex taken before the per-port one, as the Linux xgbe driver does (xgbe_phy_comm_lock), which this DPDK PMD lost when its equivalent global lock became the per-port pdata->phy_mutex.
This fix applies to ports owned by a single process. If ports of the same device are ever split across separate processes, or one port stays with the kernel xgbe driver, the hardware mutex registers remain the only arbitration between them; this is a pre-existing limitation, not something this patch changes.
v2: dropped the per-port link_status_mutex and the retry-on- -ENOTCONN/-ETIMEDOUT change from v1, per review (Stephen Hemminger):
- link_status_mutex only covered axgbe_dev_link_update() and not axgbe_dev_interrupt_handler()'s AN ISR, which touches the same PHY/ link state without it, so it was incomplete protection for a race that was never actually observed or validated, while the real, validated cross-port race is already fully handled by the bus mutex below. Removed, along with the struct member and its init.
- -ENOTCONN is an address NAK (IC_TX_ABRT_7B_ADDR_NOACK), not a bus- contention symptom, and axgbe_i2c_xfer() already waits up to 1s before returning -ETIMEDOUT, so retrying either while holding this new driver-wide mutex can block every other port's link_update behind it. Reverted axgbe_phy_i2c_read() to the existing -EAGAIN- only retry; a separate fix for a different, non-contention I2C failure mode will follow as its own patch with its own justification and hardware validation.
--- drivers/net/axgbe/axgbe_phy_impl.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/net/axgbe/axgbe_phy_impl.c +24 -0
@@ -605,9 +605,30 @@ static int axgbe_phy_sfp_get_mux(struct axgbe_port *pdata)return axgbe_phy_i2c_xfer (pdata, &i2c_op); } +/* +* The I2C and MDIO buses are shared by all ports on the device. +* axgbe_phy_get_comm_ownership() takes the per-port phy_mutex, which +* does not stop two ports in the same process from using the bus at +* once, causing I2C failures and wrong link status reporting. +* +* Add a single, driver-wide mutex, taken before the per-port one and +* before the hardware XP_I2C_MUTEX/XP_MDIO_MUTEX acquire sequence, so +* that only one port in this process is ever inside that sequence at +* a time. This matches xgbe_phy_comm_lock in the Linux xgbe driver, +* which this DPDK PMD lost when its equivalent global lock became the +* per-port pdata->phy_mutex. +* +* This only arbitrates ports owned by this process. If ports of the +* same device are split across separate processes, or one port stays +* with the kernel xgbe driver, the hardware mutex registers remain +* the only arbitration between them. +*/ +static pthread_mutex_t axgbe_i2c_mdio_bus_mutex =PTHREAD_MUTEX_INITIALIZER ; +static void axgbe_phy_put_comm_ownership (struct axgbe_port *pdata) {pthread_mutex_unlock (&pdata->phy_mutex); +pthread_mutex_unlock (&axgbe_i2c_mdio_bus_mutex); }static int axgbe_phy_get_comm_ownership (struct axgbe_port *pdata)
@@ -616,6 +637,8 @@ static int axgbe_phy_get_comm_ownership(struct axgbe_port *pdata)uint64_t timeout;unsigned int mutex_id; +pthread_mutex_lock (&axgbe_i2c_mdio_bus_mutex); +/* The I2C and MDIO/GPIO bus is multiplexed between multiple devices, * the driver needs to take the software mutex and then the hardware * mutexes before being able to use the busses.
@@ -648,6 +671,7 @@ static int axgbe_phy_get_comm_ownership(struct axgbe_port *pdata) }pthread_mutex_unlock (&pdata->phy_mutex); +pthread_mutex_unlock (&axgbe_i2c_mdio_bus_mutex);PMD_DRV_LOG_LINE (ERR ,"unable to obtain hardware mutexes" );
Signature · 1 line
2.43.0
Stephen Hemminger
AppliedQuoted 12 lines · On Tue, 17 Nov 2026 15:18:05 +0530 Ajit Kumar <[email protected]> wrote:
From: Ajit Kumar <[email protected]>
The I2C and MDIO buses are shared by all ports on the device.
axgbe_phy_get_comm_ownership()takes the per-portphy_mutex, which does not stop two ports in the same process from using the bus at once, causing I2C failures (-EAGAIN,-ENOTCONN,-ETIMEDOUT) and incorrect link status reporting.Add a driver-wide mutex taken before the per-port one, as the Linux xgbe driver does (
xgbe_phy_comm_lock), which this DPDK PMD lost when its equivalent global lock became the per-portpdata->phy_mutex.
Quoted 5 lines
This fix applies to ports owned by a single process. If ports of the same device are ever split across separate processes, or one port stays with the kernel xgbe driver, the hardware mutex registers remain the only arbitration between them; this is a pre-existing limitation, not something this patch changes.
Applied to next-net for 27.03 but I trimmed the commit message down. The version change should be below cutline --- and the link status part was not here anymore