net: phy: make mdio consumer / device layer a separate module
authorHeiner Kallweit <hkallweit1@gmail.com>
Thu, 15 May 2025 08:11:54 +0000 (10:11 +0200)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 20 May 2025 10:22:47 +0000 (12:22 +0200)
After having factored out the provider part from mdio_bus.c, we can
make the mdio consumer / device layer a separate module. This also
allows to remove Kconfig symbol MDIO_DEVICE.
The module init / exit functions from mdio_bus.c no longer have to be
called from phy_device.c. The link order defined in
drivers/net/phy/Makefile ensures that init / exit functions are called
in the right order.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Link: https://patch.msgid.link/dba6b156-5748-44ce-b5e2-e8dc2fcee5a7@gmail.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/mdio/Kconfig
drivers/net/phy/Kconfig
drivers/net/phy/Makefile
drivers/net/phy/mdio_bus.c
drivers/net/phy/mdio_device.c
drivers/net/phy/phy_device.c
include/linux/phy.h

index d3219ca194ec476f7c90b0862331c2461cea1e2d..7db40aaa079dda80a2b6f85e40c0a760ce7e4218 100644 (file)
@@ -3,21 +3,10 @@
 # MDIO Layer Configuration
 #
 
-menuconfig MDIO_DEVICE
-       tristate "MDIO bus device drivers"
-       help
-         MDIO devices and driver infrastructure code.
-
-if MDIO_DEVICE
-
 config MDIO_BUS
-       tristate
-       default m if PHYLIB=m
-       default MDIO_DEVICE
+       tristate "MDIO bus consumer layer"
        help
-         This internal symbol is used for link time dependencies and it
-         reflects whether the mdio_bus/mdio_device code is built as a
-         loadable module or built-in.
+         MDIO bus consumer layer
 
 if PHYLIB
 
@@ -291,4 +280,3 @@ config MDIO_BUS_MUX_MMIOREG
 
 
 endif
-endif
index 677d56e065397e7089185c2db4136614e8739b02..127a9fd0feb9ea29704659ea0d32f7c148b9c65d 100644 (file)
@@ -14,7 +14,7 @@ config PHYLINK
 
 menuconfig PHYLIB
        tristate "PHY Device support and infrastructure"
-       select MDIO_DEVICE
+       select MDIO_BUS
        help
          Ethernet controllers are usually attached to PHY
          devices.  This option provides infrastructure for
index 59ac3a9a317788baa455b7ef27e26963bd8e129f..7de69320a3a78307a23753d276381c73cc6a09b1 100644 (file)
@@ -6,27 +6,19 @@ libphy-y                      := phy.o phy-c45.o phy-core.o phy_device.o \
                                   phy_package.o phy_caps.o mdio_bus_provider.o
 mdio-bus-y                     += mdio_bus.o mdio_device.o
 
-ifdef CONFIG_MDIO_DEVICE
-obj-y                          += mdio-boardinfo.o
-endif
-
-# PHYLIB implies MDIO_DEVICE, in that case, we have a bunch of circular
-# dependencies that does not make it possible to split mdio-bus objects into a
-# dedicated loadable module, so we bundle them all together into libphy.ko
 ifdef CONFIG_PHYLIB
-libphy-y                       += $(mdio-bus-y)
-# the stubs are built-in whenever PHYLIB is built-in or module
-obj-y                          += stubs.o
-else
-obj-$(CONFIG_MDIO_DEVICE)      += mdio-bus.o
+# built-in whenever PHYLIB is built-in or module
+obj-y                          += stubs.o mdio-boardinfo.o
 endif
-obj-$(CONFIG_PHYLIB)           += mdio_devres.o
+
 libphy-$(CONFIG_SWPHY)         += swphy.o
 libphy-$(CONFIG_LED_TRIGGER_PHY)       += phy_led_triggers.o
 libphy-$(CONFIG_OPEN_ALLIANCE_HELPERS) += open_alliance_helpers.o
 
+obj-$(CONFIG_MDIO_BUS)         += mdio-bus.o
 obj-$(CONFIG_PHYLINK)          += phylink.o
 obj-$(CONFIG_PHYLIB)           += libphy.o
+obj-$(CONFIG_PHYLIB)           += mdio_devres.o
 
 obj-$(CONFIG_NETWORK_PHY_TIMESTAMPING) += mii_timestamper.o
 
index f5ccbe33a3841d9715dec1793ce0b1a3a7164c77..a6bcb0fee8630964015b5d825c0036784584eea6 100644 (file)
@@ -988,7 +988,7 @@ const struct bus_type mdio_bus_type = {
 };
 EXPORT_SYMBOL(mdio_bus_type);
 
-int __init mdio_bus_init(void)
+static int __init mdio_bus_init(void)
 {
        int ret;
 
@@ -1002,16 +1002,14 @@ int __init mdio_bus_init(void)
        return ret;
 }
 
-#if IS_ENABLED(CONFIG_PHYLIB)
-void mdio_bus_exit(void)
+static void __exit mdio_bus_exit(void)
 {
        class_unregister(&mdio_bus_class);
        bus_unregister(&mdio_bus_type);
 }
-EXPORT_SYMBOL_GPL(mdio_bus_exit);
-#else
-module_init(mdio_bus_init);
-/* no module_exit, intentional */
+
+subsys_initcall(mdio_bus_init);
+module_exit(mdio_bus_exit);
+
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("MDIO bus/device layer");
-#endif
index e747ee63c665f785c5dc24b4bfa788cf879d8b0e..cce3f405d1a4c78f0a9ef453ed0cf78cf9814b52 100644 (file)
@@ -45,6 +45,7 @@ int mdio_device_bus_match(struct device *dev, const struct device_driver *drv)
 
        return strcmp(mdiodev->modalias, drv->name) == 0;
 }
+EXPORT_SYMBOL_GPL(mdio_device_bus_match);
 
 struct mdio_device *mdio_device_create(struct mii_bus *bus, int addr)
 {
index 2eb735e68dd82f572dc8f3858bb0cf983b0a8343..781dfa6680ebd4d5f0787b9828334d87fba60ab7 100644 (file)
@@ -3557,19 +3557,15 @@ static int __init phy_init(void)
        phylib_register_stubs();
        rtnl_unlock();
 
-       rc = mdio_bus_init();
-       if (rc)
-               goto err_ethtool_phy_ops;
-
        rc = phy_caps_init();
        if (rc)
-               goto err_mdio_bus;
+               goto err_ethtool_phy_ops;
 
        features_init();
 
        rc = phy_driver_register(&genphy_c45_driver, THIS_MODULE);
        if (rc)
-               goto err_mdio_bus;
+               goto err_ethtool_phy_ops;
 
        rc = phy_driver_register(&genphy_driver, THIS_MODULE);
        if (rc)
@@ -3579,8 +3575,6 @@ static int __init phy_init(void)
 
 err_c45:
        phy_driver_unregister(&genphy_c45_driver);
-err_mdio_bus:
-       mdio_bus_exit();
 err_ethtool_phy_ops:
        rtnl_lock();
        phylib_unregister_stubs();
@@ -3594,7 +3588,6 @@ static void __exit phy_exit(void)
 {
        phy_driver_unregister(&genphy_c45_driver);
        phy_driver_unregister(&genphy_driver);
-       mdio_bus_exit();
        rtnl_lock();
        phylib_unregister_stubs();
        ethtool_set_ethtool_phy_ops(NULL);
index 7c29d346d4b3c2716f056df294a5abc49dce5b2f..92a88b5ce35639bdc7fd43607da593586a40da68 100644 (file)
@@ -2033,9 +2033,6 @@ int phy_ethtool_set_link_ksettings(struct net_device *ndev,
                                   const struct ethtool_link_ksettings *cmd);
 int phy_ethtool_nway_reset(struct net_device *ndev);
 
-int __init mdio_bus_init(void);
-void mdio_bus_exit(void);
-
 int phy_ethtool_get_strings(struct phy_device *phydev, u8 *data);
 int phy_ethtool_get_sset_count(struct phy_device *phydev);
 int phy_ethtool_get_stats(struct phy_device *phydev,