DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ajit Kumar <Ajit.Kumar@amd.com>
To: <dev@dpdk.org>
Subject: [PATCH] net/axgbe: serialize PHY and link status access
Date: Thu, 12 Nov 2026 19:26:11 +0530	[thread overview]
Message-ID: <20261112135611.2757325-1-Ajit.Kumar@amd.com> (raw)

From: Ajit Kumar <ajit.kumar@amd.com>

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.

Signed-off-by: Ajit Kumar <ajit.kumar@amd.com>
---
 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(-)

diff --git a/drivers/net/axgbe/axgbe_ethdev.c b/drivers/net/axgbe/axgbe_ethdev.c
index 2411e74d97..9e36186eca 100644
--- a/drivers/net/axgbe/axgbe_ethdev.c
+++ b/drivers/net/axgbe/axgbe_ethdev.c
@@ -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) {
diff --git a/drivers/net/axgbe/axgbe_ethdev.h b/drivers/net/axgbe/axgbe_ethdev.h
index 77c21469a8..5bbda1b684 100644
--- a/drivers/net/axgbe/axgbe_ethdev.h
+++ b/drivers/net/axgbe/axgbe_ethdev.h
@@ -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;
diff --git a/drivers/net/axgbe/axgbe_phy_impl.c b/drivers/net/axgbe/axgbe_phy_impl.c
index 4abf5fdea9..43a258984f 100644
--- a/drivers/net/axgbe/axgbe_phy_impl.c
+++ b/drivers/net/axgbe/axgbe_phy_impl.c
@@ -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");
 
-- 
2.43.0


             reply	other threads:[~2026-11-13 16:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 13:56 Ajit Kumar [this message]
2026-11-15 21:23 ` [PATCH] net/axgbe: serialize PHY and link status access Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261112135611.2757325-1-Ajit.Kumar@amd.com \
    --to=ajit.kumar@amd.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox