The download is unconditional, so a chip whose firmware was loaded by something else - a bootloader, an earlier bind of the PHY driver, or an MDIO device serving the chip - is reprogrammed at 144KB per probe. Read the status register the loader already polls for readiness and skip the download when it reports ready, only picking up the running firmware's version. Adopting is reported back distinctly from loading, because nothing on that path touches FW_CTRL_1: the PHY driver must leave the MCU restart to .config_init() rather than assume probe already did it. The image in RAM now wins over the files on disk. Where the PHY node carries no reset-gpios nothing clears that RAM on unbind, so writing new firmware files and rebinding keeps the old image running and reports its version as the current one. A power cycle, or a reset line on the PHY node for phy_detach() to assert, brings the reload back. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin --- drivers/net/phy/air_en8811h.c | 4 ++-- drivers/net/phy/air_phy_lib.c | 23 +++++++++++++++++++++++ drivers/net/phy/air_phy_lib.h | 3 +++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/air_en8811h.c b/drivers/net/phy/air_en8811h.c index 43d2eff808f1..c9b46cfc854f 100644 --- a/drivers/net/phy/air_en8811h.c +++ b/drivers/net/phy/air_en8811h.c @@ -1028,8 +1028,8 @@ static int en8811h_probe(struct phy_device *phydev) if (ret < 0) return ret; - /* mcu has just restarted after firmware load */ - priv->mcu_needs_restart = false; + /* Firmware that was already running was never restarted here. */ + priv->mcu_needs_restart = (ret == 1); /* MDIO_DEVS1/2 empty, so set mmds_present bits here */ phydev->c45_ids.mmds_present |= MDIO_DEVS_PMAPMD | MDIO_DEVS_AN; diff --git a/drivers/net/phy/air_phy_lib.c b/drivers/net/phy/air_phy_lib.c index 672a82539dbe..2b1a73beca8d 100644 --- a/drivers/net/phy/air_phy_lib.c +++ b/drivers/net/phy/air_phy_lib.c @@ -410,6 +410,16 @@ static int air_mmd_status_read(struct mdio_device *mdiodev) return ret; } +int air_en8811h_mcu_running(struct mdio_device *mdiodev) +{ + int ret = air_mmd_status_read(mdiodev); + + if (ret < 0) + return ret; + + return ret == EN8811H_PHY_READY; +} + int air_en8811h_wait_mcu_ready(struct mdio_device *mdiodev) { int ret, reg_value; @@ -443,6 +453,19 @@ int air_en8811h_fw_download(struct mdio_device *mdiodev, u32 *fw_version) const struct firmware *fw1, *fw2; int ret; + ret = air_en8811h_mcu_running(mdiodev); + if (ret < 0) + return ret; + + if (ret) { + ret = air_mdio_buckpbus_reg_read(mdiodev, EN8811H_FW_VERSION, + fw_version); + if (ret < 0) + return ret; + + return 1; + } + ret = request_firmware_direct(&fw1, EN8811H_MD32_DM, dev); if (ret < 0) return ret; diff --git a/drivers/net/phy/air_phy_lib.h b/drivers/net/phy/air_phy_lib.h index c288b34f2ffc..47b4bd0b7c1e 100644 --- a/drivers/net/phy/air_phy_lib.h +++ b/drivers/net/phy/air_phy_lib.h @@ -64,7 +64,10 @@ int air_phy_write_page(struct phy_device *phydev, int page); int air_fw_write_buf(struct mdio_device *mdiodev, u32 address, const struct firmware *fw); +/* Returns 1 running, 0 dormant, negative on a failed status read. */ +int air_en8811h_mcu_running(struct mdio_device *mdiodev); int air_en8811h_wait_mcu_ready(struct mdio_device *mdiodev); +/* Returns 1 when it adopted firmware that was already running. */ int air_en8811h_fw_download(struct mdio_device *mdiodev, u32 *fw_version); #endif /* __AIR_PHY_LIB_H */ -- 2.53.0