From: Ajit Kumar <[email protected]>

A port's first I2C access to its SFP cage after axgbe_phy_start() can
fail with a quick NACK (-ENOTCONN) or a stall until the 1-second I2C
timeout (-ETIMEDOUT). This is distinct from the cross-port race fixed
by the driver-wide I2C/MDIO bus mutex: it reproduces on a single port
with no sibling active, right after that port's own phy_start().

v2 retried these codes inside axgbe_phy_i2c_read(), gated by a flag
set on first success. Two problems: the flag lives in phy_data,
allocated once at probe and never cleared across phy_start()/
phy_stop(), so it doesn't track the access it's meant to gate; and a
device that never responds never sets it, so a persistent fault pays
the extra retry on every later link_update() poll, unbounded. The
retry also ran while holding the bus mutex, blocking other ports for
its duration, the concern raised against the original combined patch.

Drop the retry and the flag. Instead, wait briefly in
axgbe_phy_start() before the first SFP probe, before the bus mutex is
even taken. Fixed, known cost per phy_start(), no state to go stale,
nothing held while waiting. axgbe_phy_i2c_read() reverts to its
original -EAGAIN-only retry, unchanged.

Fixes: a5c7273771e8 ("net/axgbe: add phy programming APIs")
Cc: [email protected]

Signed-off-by: Ajit Kumar <[email protected]>
---
Depends on the driver-wide I2C/MDIO bus mutex from "net/axgbe:
serialize PHY and link status access" for the cross-port case;
applies independently otherwise.

v3: dropped the retry/flag design, replaced with a settle delay before
the first SFP probe in axgbe_phy_start(), outside the bus mutex.
axgbe_phy_i2c_read() is unchanged from upstream.
v2: gated the extended retry with a per-port settled flag (bounded to
first access, per CI bot); switched to a real sleep; shortened the
comment.
---
 drivers/net/axgbe/axgbe_phy_impl.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/net/axgbe/axgbe_phy_impl.c 
b/drivers/net/axgbe/axgbe_phy_impl.c
index 55d45bfb7b..83e6a16753 100644
--- a/drivers/net/axgbe/axgbe_phy_impl.c
+++ b/drivers/net/axgbe/axgbe_phy_impl.c
@@ -2520,6 +2520,8 @@ static void axgbe_phy_stop(struct axgbe_port *pdata)
        pdata->i2c_if.i2c_stop(pdata);
 }
 
+#define AXGBE_SFP_I2C_SETTLE_DELAY_US  2000
+
 static int axgbe_phy_start(struct axgbe_port *pdata)
 {
        struct axgbe_phy_data *phy_data = pdata->phy_data;
@@ -2536,9 +2538,16 @@ static int axgbe_phy_start(struct axgbe_port *pdata)
        /* Reset CDR support */
        axgbe_phy_cdr_track(pdata);
 
-       /* After starting the I2C controller, we can check for an SFP */
+       /*
+        * After starting the I2C controller, we can check for an SFP. The
+        * cage's GPIO expander/mux may not yet be ready to respond to the
+        * very first access, so give it a short settle delay before the
+        * first probe instead of failing and leaving recovery to a later
+        * poll.
+        */
        switch (phy_data->port_mode) {
        case AXGBE_PORT_MODE_SFP:
+               rte_delay_us_sleep(AXGBE_SFP_I2C_SETTLE_DELAY_US);
                axgbe_phy_sfp_detect(pdata);
                break;
        default:
-- 
2.43.0

Reply via email to