net: phy: sfp: fix mii_bus leak and revert RollBall bridge probe
Subsystems (5)
v5 cover net: phy: sfp: fix mii_bus leak and revert RollBall bridge probe
v4 tried to fix the RollBall regression from 8fe125892f40 by deferring the bridge probe to PHY discovery time. Maxime Chevallier and Aleksander Bajkowski both tested that on genuine RollBall hardware and confirmed it does not restore PHY detection (the module still is not ready when the probe runs), and the Sashiko static review flagged the same path.
So this version drops the deferred-probe patch and instead reverts 8fe125892f40, restoring the pre-regression behaviour for genuine RollBall modules. A proper fix for slow-initializing modules needs per-module init timing (a longer module_t_wait / a per-module quirk) and genuine RollBall hardware to validate; that is better owned as a follow-up by someone with such a module.
Patch 1 is the independent mii_bus leak fix, unchanged, now carrying Reviewed-by from Maxime and Larysa.
Patch 2 reverts 8fe125892f40.
v4: https://lore.kernel.org/netdev/[email protected]/
Petr Wozniak (2):
net: phy: sfp: free mii_bus in sfp_i2c_mdiobus_destroy Revert "net: phy: sfp: probe for RollBall I2C-to-MDIO bridge in
mdio-i2c"
drivers/net/mdio/mdio-i2c.c | 59 +++++-------------------------------- drivers/net/phy/sfp.c | 15 +++------- 2 files changed, 11 insertions(+), 63 deletions(-)
Signature · 1 line
2.51.0
PATCH v5 1/2 net: phy: sfp: free mii_bus in sfp_i2c_mdiobus_destroy
sfp_i2c_mdiobus_create() allocates the I2C MDIO bus with mdio_i2c_alloc(), a plain (non-devm) allocation, and registers it. sfp_i2c_mdiobus_destroy() only unregisters the bus and clears sfp->i2c_mii without calling mdiobus_free(). As the only reference to the bus is then cleared, the struct mii_bus is leaked.
This is hit whenever a copper/RollBall SFP module that instantiated an MDIO bus is removed: sfp_sm_main() takes the global teardown path and calls sfp_i2c_mdiobus_destroy(). sfp_cleanup(), on driver unbind, frees sfp->i2c_mii directly, which is why the leak only triggered on module hot-removal and not on unbind.
Free the bus in sfp_i2c_mdiobus_destroy() to match the allocation done in sfp_i2c_mdiobus_create().
--- drivers/net/phy/sfp.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/phy/sfp.c +1 -0
@@ -963,6 +963,7 @@ static int sfp_i2c_mdiobus_create(struct sfp *sfp)static void sfp_i2c_mdiobus_destroy (struct sfp *sfp) {mdiobus_unregister (sfp->i2c_mii); +mdiobus_free (sfp->i2c_mii); sfp->i2c_mii =NULL ; }
Signature · 1 line
2.51.0
PATCH v5 2/2 Revert "net: phy: sfp: probe for RollBall I2C-to-MDIO bridge in mdio-i2c"
In reply to Petr WozniakThis reverts commit 8fe125892f40 ("net: phy: sfp: probe for RollBall I2C-to-MDIO bridge in mdio-i2c").
That commit added a RollBall bridge probe at MDIO bus creation time, in i2c_mii_init_rollball(), to avoid a multi-minute PHY probe retry loop on modules without a bridge (e.g. RTL8261BE). The probe runs in SFP_S_INIT, before genuine RollBall modules have finished their firmware/bridge initialization, so the bridge does not yet answer CMD_READ/CMD_DONE. The probe times out, mdio_protocol is set to MDIO_I2C_NONE, and PHY detection is then skipped for genuine RollBall modules that worked before the commit.
This was confirmed on hardware by Maxime Chevallier and Aleksander
Bajkowski: their RollBall modules no longer detect a PHY, and work again on v7.0 (before the bridge probing was introduced). The Sashiko static review flagged the same path.
Deferring the probe to PHY discovery time does not fix it either: at that point a slow module may still be initializing, so the probe still returns -ENODEV. A proper fix needs per-module init timing (a longer module_t_wait or a per-module quirk, per SFF-8472 the host must also wait at least 300 ms after insertion), which requires genuine RollBall hardware to develop and validate. Revert to restore the previous, working behaviour in the meantime.
The RTL8261BE retry-loop latency that the reverted commit addressed is handled in our downstream tree, so reverting upstream is safe on our side.
--- drivers/net/mdio/mdio-i2c.c | 59 +++++-------------------------------- drivers/net/phy/sfp.c | 14 ++------- 2 files changed, 10 insertions(+), 63 deletions(-)
drivers/net/mdio/mdio-i2c.c +7 -52
@@ -419,50 +419,6 @@ static int i2c_mii_write_rollball(struct mii_bus *bus, int phy_id, int devad,return 0 ; } -static int i2c_mii_probe_rollball (struct i2c_adapter *i2c) -{ -u8 data_buf[] = {ROLLBALL_DATA_ADDR ,0x01 ,0x00 ,0x00 }; -u8 cmd_buf[] = {ROLLBALL_CMD_ADDR ,ROLLBALL_CMD_READ }; -u8 cmd_addr =ROLLBALL_CMD_ADDR ; -struct i2c_msg msgs[2 ]; -u8 result; -int ret; -int i; - - msgs[0 ].addr =ROLLBALL_PHY_I2C_ADDR ; - msgs[0 ].flags =0 ; - msgs[0 ].len =sizeof (data_buf); - msgs[0 ].buf = data_buf; - msgs[1 ].addr =ROLLBALL_PHY_I2C_ADDR ; - msgs[1 ].flags =0 ; - msgs[1 ].len =sizeof (cmd_buf); - msgs[1 ].buf = cmd_buf; - - ret =i2c_transfer_rollball (i2c, msgs,ARRAY_SIZE (msgs)); -if (ret <0 ) -return -ENODEV ; - - msgs[0 ].addr =ROLLBALL_PHY_I2C_ADDR ; - msgs[0 ].flags =0 ; - msgs[0 ].len =1 ; - msgs[0 ].buf = &cmd_addr; - msgs[1 ].addr =ROLLBALL_PHY_I2C_ADDR ; - msgs[1 ].flags =I2C_M_RD ; - msgs[1 ].len =1 ; - msgs[1 ].buf = &result; - -for (i =0 ; i <10 ; i++) { -msleep (20 ); - ret =i2c_transfer_rollball (i2c, msgs,ARRAY_SIZE (msgs)); -if (ret <0 ) -return -ENODEV ; -if (result ==ROLLBALL_CMD_DONE ) -return 0 ; - } - -return -ENODEV ; -} -static int i2c_mii_init_rollball (struct i2c_adapter *i2c) {struct i2c_msg msg;
@@ -482,11 +438,11 @@ static int i2c_mii_init_rollball(struct i2c_adapter *i2c) ret =i2c_transfer (i2c, &msg,1 );if (ret <0 ) -return -ENODEV ; -if (ret !=1 ) +return ret; +else if (ret !=1 )return -EIO ; - -return i2c_mii_probe_rollball (i2c); +else +return 0 ; } static bool mdio_i2c_check_functionality(struct i2c_adapter *i2c,
@@ -531,10 +487,9 @@ struct mii_bus *mdio_i2c_alloc(struct device *parent, struct i2c_adapter *i2c,case MDIO_I2C_ROLLBALL : ret =i2c_mii_init_rollball (i2c);if (ret <0 ) { -if (ret != -ENODEV ) -dev_err (parent, -"Cannot initialize RollBall MDIO I2C protocol: %d\n" , - ret); +dev_err (parent, +"Cannot initialize RollBall MDIO I2C protocol: %d\n" , + ret);mdiobus_free (mii);return ERR_PTR (ret); }
drivers/net/phy/sfp.c +3 -11
@@ -597,7 +597,6 @@ static const struct sfp_quirk sfp_quirks[] = {// OEM SFP-GE-T is a 1000Base-T module with broken TX_FAULT indicator SFP_QUIRK_F ("OEM" ,"SFP-GE-T" , sfp_fixup_ignore_tx_fault), -SFP_QUIRK_F ("OEM" ,"SFP-10G-T-I" , sfp_fixup_rollball),SFP_QUIRK_F ("OEM" ,"SFP-10G-T" , sfp_fixup_rollball_cc),SFP_QUIRK_S ("OEM" ,"SFP-2.5G-T" , sfp_quirk_oem_2_5g), SFP_QUIRK_S("OEM", "SFP-2.5G-BX10-D", sfp_quirk_2500basex),
@@ -2174,17 +2173,10 @@ static void sfp_sm_fault(struct sfp *sfp, unsigned int next_state, bool warn)static int sfp_sm_add_mdio_bus (struct sfp *sfp) { -int ret; - -if (sfp->mdio_protocol ==MDIO_I2C_NONE ) -return 0 ; +if (sfp->mdio_protocol !=MDIO_I2C_NONE ) +return sfp_i2c_mdiobus_create (sfp); - ret =sfp_i2c_mdiobus_create (sfp); -if (ret == -ENODEV ) { - sfp->mdio_protocol =MDIO_I2C_NONE ; -return 0 ; - } -return ret; +return 0 ; }/* Probe a SFP for a PHY device if the module supports copper - the PHY
Signature · 1 line
2.51.0
Re: [PATCH net v5 2/2] Revert "net: phy: sfp: probe for RollBall I2C-to-MDIO bridge in mdio-i2c"
Hi Petr,
Quoted 16 lines · Petr Wozniak
This reverts commit
8fe125892f40("net: phy: sfp: probe for RollBall I2C-to-MDIO bridge in mdio-i2c").That commit added a RollBall bridge probe at MDIO bus creation time, in
i2c_mii_init_rollball(), to avoid a multi-minute PHY probe retry loop on modules without a bridge (e.g. RTL8261BE). The probe runs inSFP_S_INIT, before genuine RollBall modules have finished theirfirmware/bridgeinitialization, so the bridge does not yet answer CMD_READ/CMD_DONE. The probe times out,mdio_protocolis set toMDIO_I2C_NONE, and PHY detection is then skipped for genuine RollBall modules that worked before the commit.This was confirmed on hardware by Maxime Chevallier and Aleksander
Bajkowski: their RollBall modules no longer detect a PHY, and work again on v7.0 (before the bridge probing was introduced). The Sashiko static review flagged the same path.
Quoted 6 lines
Deferring the probe to PHY discovery time does not fix it either: at that point a slow module may still be initializing, so the probe still returns
-ENODEV. A proper fix needs per-module init timing (a longermodule_t_waitor a per-module quirk, per SFF-8472 the host must also wait at least 300 ms after insertion), which requires genuine RollBall hardware to develop and validate. Revert to restore the previous, working behaviour in the meantime.
Sorry this didn't work out :(
Quoted 9 lines
The RTL8261BE retry-loop latency that the reverted commit addressed is handled in our downstream tree, so reverting upstream is safe on our side.
Fixes 8fe125892f40 ("net: phy: sfp: probe for RollBall I2C-to-MDIO bridge in mdio-i2c")Reported-by Aleksander Bajkowski <[email protected]>Suggested-by Maxime Chevallier <[email protected]>Signed-off-by Petr Wozniak <[email protected]>
I confirm this restores rollball PHY detection on my side.
Thanks,
Maxime
Re: [PATCH net v5 2/2] Revert "net: phy: sfp: probe for RollBall I2C-to-MDIO bridge in mdio-i2c"
Hi Maxime,
Thanks a lot for testing and reviewing, much appreciated.
No worries about the original probe approach not panning out; restoring the working RollBall detection is what matters here. If I ever get my hands on genuine RollBall hardware, I'll revisit the per-module timing idea.
Thanks,
Petr