mirror-linux/drivers/net/phy
Wei Fang 2aa1545ba8 net: phy: micrel: fix clk warning when removing the driver
Since the commit 25c6a5ab15 ("net: phy: micrel: Dynamically control
external clock of KSZ PHY"), the clock of Micrel PHY has been enabled
by phy_driver::resume() and disabled by phy_driver::suspend(). However,
devm_clk_get_optional_enabled() is used in kszphy_probe(), so the clock
will automatically be disabled when the device is unbound from the bus.
Therefore, this could cause the clock to be disabled twice, resulting
in clk driver warnings.

For example, this issue can be reproduced on i.MX6ULL platform, and we
can see the following logs when removing the FEC MAC drivers.

$ echo 2188000.ethernet > /sys/bus/platform/drivers/fec/unbind
$ echo 20b4000.ethernet > /sys/bus/platform/drivers/fec/unbind
[  109.758207] ------------[ cut here ]------------
[  109.758240] WARNING: drivers/clk/clk.c:1188 at clk_core_disable+0xb4/0xd0, CPU#0: sh/639
[  109.771011] enet2_ref already disabled
[  109.793359] Call trace:
[  109.822006]  clk_core_disable from clk_disable+0x28/0x34
[  109.827340]  clk_disable from clk_disable_unprepare+0xc/0x18
[  109.833029]  clk_disable_unprepare from devm_clk_release+0x1c/0x28
[  109.839241]  devm_clk_release from devres_release_all+0x98/0x100
[  109.845278]  devres_release_all from device_unbind_cleanup+0xc/0x70
[  109.851571]  device_unbind_cleanup from device_release_driver_internal+0x1a4/0x1f4
[  109.859170]  device_release_driver_internal from bus_remove_device+0xbc/0xe4
[  109.866243]  bus_remove_device from device_del+0x140/0x458
[  109.871757]  device_del from phy_mdio_device_remove+0xc/0x24
[  109.877452]  phy_mdio_device_remove from mdiobus_unregister+0x40/0xac
[  109.883918]  mdiobus_unregister from fec_enet_mii_remove+0x40/0x78
[  109.890125]  fec_enet_mii_remove from fec_drv_remove+0x4c/0x158
[  109.896076]  fec_drv_remove from device_release_driver_internal+0x17c/0x1f4
[  109.962748] WARNING: drivers/clk/clk.c:1047 at clk_core_unprepare+0xfc/0x13c, CPU#0: sh/639
[  109.975805] enet2_ref already unprepared
[  110.002866] Call trace:
[  110.031758]  clk_core_unprepare from clk_unprepare+0x24/0x2c
[  110.037440]  clk_unprepare from devm_clk_release+0x1c/0x28
[  110.042957]  devm_clk_release from devres_release_all+0x98/0x100
[  110.048989]  devres_release_all from device_unbind_cleanup+0xc/0x70
[  110.055280]  device_unbind_cleanup from device_release_driver_internal+0x1a4/0x1f4
[  110.062877]  device_release_driver_internal from bus_remove_device+0xbc/0xe4
[  110.069950]  bus_remove_device from device_del+0x140/0x458
[  110.075469]  device_del from phy_mdio_device_remove+0xc/0x24
[  110.081165]  phy_mdio_device_remove from mdiobus_unregister+0x40/0xac
[  110.087632]  mdiobus_unregister from fec_enet_mii_remove+0x40/0x78
[  110.093836]  fec_enet_mii_remove from fec_drv_remove+0x4c/0x158
[  110.099782]  fec_drv_remove from device_release_driver_internal+0x17c/0x1f4

After analyzing the process of removing the FEC driver, as shown below,
it can be seen that the clock was disabled twice by the PHY driver.

fec_drv_remove()
  --> fec_enet_close()
    --> phy_stop()
      --> phy_suspend()
        --> kszphy_suspend() #1 The clock is disabled
  --> fec_enet_mii_remove()
    --> mdiobus_unregister()
      --> phy_mdio_device_remove()
        --> device_del()
          --> devm_clk_release() #2 The clock is disabled again

Therefore, devm_clk_get_optional() is used to fix the above issue. And
to avoid the issue mentioned by the commit 9853294627 ("net: phy:
micrel: use devm_clk_get_optional_enabled for the rmii-ref clock"), the
clock is enabled by clk_prepare_enable() to get the correct clock rate.

Fixes: 25c6a5ab15 ("net: phy: micrel: Dynamically control external clock of KSZ PHY")
Signed-off-by: Wei Fang <wei.fang@nxp.com>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Link: https://patch.msgid.link/20260126081544.983517-1-wei.fang@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2026-01-28 20:10:39 -08:00
..
aquantia net: phy: aquantia: check for NVMEM deferral 2025-11-28 19:40:42 -08:00
mediatek net: phy: mediatek: fix nvmem cell reference leak in mt798x_phy_calibration 2025-12-22 12:18:54 +01:00
mscc phy: mscc: add HW timestamp configuration reporting 2025-11-26 16:56:34 -08:00
qcom net: phy: update all PHYs to use sfp_get_module_caps() 2025-09-22 16:05:15 -07:00
realtek net: phy: RTL8211FVD: Restore disabling of PHY-mode EEE 2025-12-04 12:10:49 +01:00
Kconfig net: phy: microchip_t1s: add support for Microchip LAN867X Rev.D0 PHY 2025-10-31 16:52:05 -07:00
Makefile net: phy: remove mdio_board_info support from phylib 2025-09-17 15:24:01 -07:00
adin.c
adin1100.c net: phy: adin1100: Simplify register value passing 2025-11-20 18:03:59 -08:00
air_en8811h.c
amd.c
as21xxx.c
ax88796b.c net: phy: ax88796b: Replace hard-coded values with PHY_ID_MATCH_MODEL() 2025-09-22 16:38:59 -07:00
ax88796b_rust.rs
bcm-cygnus.c
bcm-phy-lib.c
bcm-phy-lib.h
bcm-phy-ptp.c net: phy: broadcom: add HW timestamp configuration reporting 2025-11-26 16:56:34 -08:00
bcm7xxx.c
bcm63xx.c
bcm87xx.c
bcm54140.c
bcm84881.c
broadcom.c net: phy: bcm54811: Fix GMII/MII/MII-Lite selection 2025-10-13 17:36:20 -07:00
cicada.c
cortina.c
davicom.c
dp83tc811.c
dp83td510.c net: phy: dp83td510: add MSE interface support for 10BASE-T1L 2025-11-03 18:32:27 -08:00
dp83tg720.c
dp83640.c net: phy: dp83640: add HW timestamp configuration reporting 2025-11-26 16:56:34 -08:00
dp83640_reg.h
dp83822.c
dp83848.c
dp83867.c net: phy: dp83867: implement configurability for SGMII in-band auto-negotiation 2025-11-26 18:04:17 -08:00
dp83869.c net: phy: dp83869: fix STRAP_OPMODE bitmask 2025-10-29 17:59:09 -07:00
et1011c.c
fixed_phy.c net: phy: fixed_phy: remove not needed initialization of phy_device members 2025-11-20 18:18:54 -08:00
icplus.c
intel-xway.c net: phy: intel-xway: fix OF node refcount leakage 2026-01-20 15:57:21 -08:00
linkmode.c
lxt.c
marvell-88q2xxx.c net: phy: marvell-88q2xxx: Fix clamped value in mv88q2xxx_hwmon_write 2025-12-04 17:49:31 -08:00
marvell-88x2222.c net: phy: update all PHYs to use sfp_get_module_caps() 2025-09-22 16:05:15 -07:00
marvell.c net: phy: update all PHYs to use sfp_get_module_caps() 2025-09-22 16:05:15 -07:00
marvell10g.c net: phy: update all PHYs to use sfp_get_module_caps() 2025-09-22 16:05:15 -07:00
mdio-open-alliance.h net: phy: phy-c45: add SQI and SQI+ support for OATC14 10Base-T1S PHYs 2025-12-01 15:08:24 -08:00
mdio-private.h net: mdio: common handling of phy device reset properties 2025-11-20 17:41:39 -08:00
mdio_bus.c net: mdio: eliminate kdoc warnings in mdio_device.c and mdio_bus.c 2025-11-25 18:43:56 -08:00
mdio_bus_provider.c net: phy: use new iterator mdiobus_for_each_phy in mdiobus_prevent_c45_scan 2025-10-29 19:00:34 -07:00
mdio_device.c net: mdio: eliminate kdoc warnings in mdio_device.c and mdio_bus.c 2025-11-25 18:43:56 -08:00
mdio_devres.c
meson-gxl.c
micrel.c net: phy: micrel: fix clk warning when removing the driver 2026-01-28 20:10:39 -08:00
microchip.c
microchip_rds_ptp.c phy: rename hwtstamp callback to hwtstamp_set 2025-11-26 16:56:33 -08:00
microchip_rds_ptp.h
microchip_t1.c
microchip_t1s.c net: phy: microchip_t1s: add SQI support for LAN867x Rev.D0 PHYs 2025-12-01 15:08:24 -08:00
mii_timestamper.c
motorcomm.c net: phy: motorcomm: fix duplex setting error for phy leds 2026-01-12 18:01:09 -08:00
mxl-86110.c net: phy: mxl-86110: Add power management and soft reset support 2026-01-04 09:53:33 -08:00
mxl-gpy.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2025-11-27 12:19:08 -08:00
national.c
ncn26000.c
nxp-c45-tja11xx-macsec.c net: phy: nxp-c45-tja11xx: use bitmap_empty() where appropriate 2025-09-16 12:15:49 +02:00
nxp-c45-tja11xx.c net: phy: nxp-c45-tja11xx: add HW timestamp configuration reporting 2025-11-26 16:56:34 -08:00
nxp-c45-tja11xx.h
nxp-cbtx.c
nxp-tja11xx.c
open_alliance_helpers.c
open_alliance_helpers.h
phy-c45.c net: phy: phy-c45: add SQI and SQI+ support for OATC14 10Base-T1S PHYs 2025-12-01 15:08:24 -08:00
phy-caps.h net: ethtool: Add support for 1600Gbps speed 2025-11-20 18:21:29 -08:00
phy-core.c net: ethtool: Add support for 1600Gbps speed 2025-11-20 18:21:29 -08:00
phy.c phy: add hwtstamp_get callback to phy drivers 2025-11-26 16:56:33 -08:00
phy_caps.c net: ethtool: Add support for 1600Gbps speed 2025-11-20 18:21:29 -08:00
phy_device.c net: phy: make phy_device members pause and asym_pause bitfield bits 2025-11-04 18:14:35 -08:00
phy_led_triggers.c
phy_link_topology.c
phy_package.c
phylib-internal.h
phylib.h
phylink.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2025-11-20 09:13:26 -08:00
qsemi.c
qt2025.rs net: phy: qt2025: Wait until PHY becomes ready 2025-11-06 14:47:19 -08:00
rockchip.c
sfp-bus.c net: sfp: remove old sfp_parse_* functions 2025-09-22 16:05:15 -07:00
sfp.c net: sfp: add potron quirk to the H-COM SPP425H-GAB4 SFP+ Stick 2026-01-17 16:45:40 -08:00
sfp.h net: sfp: convert sfp quirks to modify struct sfp_module_support 2025-09-22 16:05:14 -07:00
smsc.c
ste10Xp.c
stubs.c
swphy.c
swphy.h
teranetics.c
uPD60620.c
vitesse.c
xilinx_gmii2rgmii.c