Skip to contentSkip to conversation

net: phy: factor out legacy PHY fixup support and make it always built-in

PATCH Applied Heiner Kallweit 2 participants 2 messages Sep 16 – Sep 19

Subsystems (4)
lore
Share & tools
lore

Heiner Kallweit

author maintainer
#0 lore raw

PATCH v2 1/1 net: phy: factor out legacy PHY fixup support and make it always built-in

PHY fixup registration is used from platform code in init phase only. Let's move the PHY fixup code from the modular part of phylib to the always built-in part of phylib. This allows to annotate the fixup registration as __init. No caller uses the return code of PHY fixup registration, therefore change related functions to return void.

phy_needs_fixup() and phy_scan_fixups() wouldn't have to be moved to the built-in part of phylib. But doing so allows to fully factor out legacy fixup support into its own source code file, and make struct phy_fixup and phy_fixup_list strictly private to phy_fixup.c.

phy_scan_fixups() is used after init phase only, then phy_fixup_list is read-only. So we don't need the mutex when accessing the list. Also when registering PHY fixups the mutex isn't needed, because fixup registration is done sequentially from platform init code. Actually there is only one platform with more than one fixup.

In addition this change lays the foundation for enabling modular phylib on platforms where the fixup just sets a flag.

Last but not least reflect the change in the documentation, and add a hint that fixup's are legacy functionality.

---
v2:
- adjust kdoc and reflect the change in the documentation

---
 Documentation/networking/phy.rst  | 17 +++---
 drivers/net/phy/Makefile          |  2 +-
 drivers/net/phy/phy_device.c      | 90 ----------------------------
 drivers/net/phy/phy_fixup.c       | 98 +++++++++++++++++++++++++++++++
 drivers/net/phy/phylib-internal.h |  1 +
 include/linux/phy.h               |  8 +--
 6 files changed, 114 insertions(+), 102 deletions(-)
 create mode 100644 drivers/net/phy/phy_fixup.c
Documentation/networking/phy.rst +10 -7
index 0170c9d4dc5..d53067ab1a6 100644
@@ -511,24 +511,27 @@ Board Fixups
 Sometimes the specific interaction between the platform and the PHY requires
 special handling.  For instance, to change where the PHY's clock input is,
 or to add a delay to account for latency issues in the data path.  In order
-to support such contingencies, the PHY Layer allows platform code to register
-fixups to be run when the PHY is brought up (or subsequently reset).
+to support such contingencies, the PHY Layer allows platform init code to
+register fixups to be run when the PHY is brought up (or subsequently reset).
+
+Note: This is legacy functionality and not supposed to be used in new code.
+      Fixup's should be handled in the PHY driver.
 
 When the PHY Layer brings up a PHY it checks to see if there are any fixups
 registered for it, matching based on UID (contained in the PHY device's phy_id
 field) and the bus identifier (contained in phydev->dev.bus_id).  Both must
-match, however two constants, PHY_ANY_ID and PHY_ANY_UID, are provided as
-wildcards for the bus ID and UID, respectively.
+match, however NULL for the bus identifier and 0 for phy_uid_mask can be
+used to disable the respective type of matching.
 
 When a match is found, the PHY layer will invoke the run function associated
 with the fixup.  This function is passed a pointer to the phy_device of
-interest.  It should therefore only operate on that PHY.
+interest. It should therefore only operate on that PHY.
 
 The platform code can register the fixup using one of::
 
- int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask,
+ void __init phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask,
 		int (*run)(struct phy_device *));
- int phy_register_fixup_for_id(const char *phy_id,
+ void __init phy_register_fixup_for_id(const char *phy_id,
 		int (*run)(struct phy_device *));
 
 Standards
drivers/net/phy/Makefile +1 -1
index 25c4a3c2429..6c2ee118a12 100644
@@ -8,7 +8,7 @@ libphy-y			:= phy.o phy-c45.o phy-core.o phy_device.o \
 
 ifdef CONFIG_PHYLIB
 # built-in whenever PHYLIB is built-in or module
-obj-y				+= stubs.o
+obj-y				+= stubs.o phy_fixup.o
 endif
 
 libphy-$(CONFIG_SWPHY)		+= swphy.o
drivers/net/phy/phy_device.c +0 -90

108 lines not on this page · raw message

drivers/net/phy/phy_fixup.c new file +98 -0

98 lines not on this page · raw message

drivers/net/phy/phylib-internal.h +1 -0
index 664ed7faa51..38ee294f3c9 100644
@@ -23,6 +23,7 @@ void of_set_phy_eee_broken(struct phy_device *phydev);
 void of_set_phy_timing_role(struct phy_device *phydev);
 int phy_speed_down_core(struct phy_device *phydev);
 void phy_check_downshift(struct phy_device *phydev);
+int phy_scan_fixups(struct phy_device *phydev);
 
 int mdiobus_register_device(struct mdio_device *mdiodev);
 int mdiobus_unregister_device(struct mdio_device *mdiodev);
include/linux/phy.h +4 -4
index 3d8afe6b7f1..257634a543a 100644
@@ -2440,10 +2440,10 @@ int phy_get_mac_termination(struct phy_device *phydev, struct device *dev,
 void phy_resolve_pause(unsigned long *local_adv, unsigned long *partner_adv,
 		       bool *tx_pause, bool *rx_pause);
 
-int phy_register_fixup_for_id(const char *bus_id,
-			      int (*run)(struct phy_device *));
-int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask,
-			       int (*run)(struct phy_device *));
+void __init phy_register_fixup_for_id(const char *bus_id,
+				      int (*run)(struct phy_device *));
+void __init phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask,
+				       int (*run)(struct phy_device *));
 
 int phy_eee_tx_clock_stop_capable(struct phy_device *phydev);
 int phy_eee_rx_clock_stop(struct phy_device *phydev, bool clk_stop_enable);
Signature · 1 line
2.55.0
#1 lore raw
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 6 lines · On Wed, 16 Sep 2026 08:05:22 +0200 you wrote:

PHY fixup registration is used from platform code in init phase only. Let's move the PHY fixup code from the modular part of phylib to the always built-in part of phylib. This allows to annotate the fixup registration as __init. No caller uses the return code of PHY fixup registration, therefore change related functions to return void.

Quoted 6 lines

phy_needs_fixup() and phy_scan_fixups() wouldn't have to be moved to the built-in part of phylib. But doing so allows to fully factor out legacy fixup support into its own source code file, and make struct phy_fixup and phy_fixup_list strictly private to phy_fixup.c.

[...]

Here is the summary with links:
- [v2,net-next] net: phy: factor out legacy PHY fixup support and make it always built-in

    https://git.kernel.org/netdev/net-next/c/f619d5003ff4

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html