There is a linking issue when using phy_register_fixup{,_for_uid,_for_id} and
CONFIG_PHYLIB is not a builtin:
arch/arm/mach-at91/built-in.o: In function `ksz9021rn_phy_fixup':
:(.text+0x1174): undefined reference to `mdiobus_write'
:(.text+0x1188): undefined reference to `mdiobus_write'
:(.text+0x119c): undefined reference to `mdiobus_write'
:(.text+0x11b0): undefined reference to `mdiobus_write'
arch/arm/mach-at91/built-in.o: In function `sama5_dt_device_init':
:(.init.text+0x1e34): undefined reference to `phy_register_fixup_for_uid'
This has been solved for arch/arm/mach-mxs/ and arch/arm/mach-imx/ by testing
IS_BUILTIN(CONFIG_PHYLIB) before calling the functions.
The first patch is an attempt at solving that issue globally.
The following patches remove the unnecessary IS_BUILTIN(CONFIG_PHYLIB) checks.
Quickly greping into the code shows that the issue may arise in:
arch/powerpc/platforms/85xx/mpc85xx_mds.c
arch/arm/mach-davinci/board-dm644x-evm.c
arch/arm/mach-orion5x/dns323-setup.c
arch/arm/mach-at91/board-dt-sama5.c
Alexandre Belloni (3):
net: phy: prevent linking breakage
arm: mxs: don't check for CONFIG_PHYLIB as builtin
arm: imx: don't check for CONFIG_PHYLIB as builtin
arch/arm/mach-imx/mach-imx6q.c | 23 ++++++++++-------------
arch/arm/mach-mxs/mach-mxs.c | 5 ++---
drivers/net/phy/phy_device.c | 6 ++++++
include/linux/phy.h | 12 ++++++++++++
4 files changed, 30 insertions(+), 16 deletions(-)
--
1.8.1.2
phy_register_fixup{,_for_uid,_for_id} are called from arch/, quite
often, there is no protection to check whether CONFIG_PHYLIB=y which is
the only case where this would work. Having phylib as a module or not
compiled at all will result in that kind of linking failure:
arch/arm/mach-at91/built-in.o: In function `ksz9021rn_phy_fixup':
:(.text+0x1174): undefined reference to `mdiobus_write'
:(.text+0x1188): undefined reference to `mdiobus_write'
:(.text+0x119c): undefined reference to `mdiobus_write'
:(.text+0x11b0): undefined reference to `mdiobus_write'
arch/arm/mach-at91/built-in.o: In function `sama5_dt_device_init':
:(.init.text+0x1e34): undefined reference to `phy_register_fixup_for_uid'
Signed-off-by: Alexandre Belloni <redacted>
---
drivers/net/phy/phy_device.c | 6 ++++++
include/linux/phy.h | 12 ++++++++++++
2 files changed, 18 insertions(+)
@@ -556,12 +556,24 @@ int phy_start_interrupts(struct phy_device *phydev);voidphy_print_status(structphy_device*phydev);voidphy_device_free(structphy_device*phydev);+/*+*phy_register_fixup{,_for_uid,_for_id}arecalledfromarch/sothiswon't+*workunlessphylibiscompiledinthekernel.+*Definingstubsallowstopreventlinkingerrors.+*/+#ifdef CONFIG_PHYLIBintphy_register_fixup(constchar*bus_id,u32phy_uid,u32phy_uid_mask,int(*run)(structphy_device*));intphy_register_fixup_for_id(constchar*bus_id,int(*run)(structphy_device*));intphy_register_fixup_for_uid(u32phy_uid,u32phy_uid_mask,int(*run)(structphy_device*));+#else+#define phy_register_fixup(a, b, c, d) do { } while (0)+#define phy_register_fixup_for_id(a, b) do { } while (0)+#define phy_register_fixup_for_uid(a, b, c) do { } while (0)+#endif /* CONFIG_PHYLIB */+intphy_scan_fixups(structphy_device*phydev);intphy_init_eee(structphy_device*phydev,boolclk_stop_enable);
@@ -99,16 +99,14 @@ soft:/* For imx6q sabrelite board: set KSZ9021RN RGMII pad skew */staticintksz9021rn_phy_fixup(structphy_device*phydev){-if(IS_BUILTIN(CONFIG_PHYLIB)){-/* min rx data delay */-phy_write(phydev,0x0b,0x8105);-phy_write(phydev,0x0c,0x0000);--/* max rx/tx clock delay, min rx/tx control delay */-phy_write(phydev,0x0b,0x8104);-phy_write(phydev,0x0c,0xf0f0);-phy_write(phydev,0x0b,0x104);-}+/* min rx data delay */+phy_write(phydev,0x0b,0x8105);+phy_write(phydev,0x0c,0x0000);++/* max rx/tx clock delay, min rx/tx control delay */+phy_write(phydev,0x0b,0x8104);+phy_write(phydev,0x0c,0xf0f0);+phy_write(phydev,0x0b,0x104);return0;}
On Mon, May 27, 2013 at 06:18:42PM +0200, Alexandre Belloni wrote:
quoted hunk
phy_register_fixup{,_for_uid,_for_id} are called from arch/, quite
often, there is no protection to check whether CONFIG_PHYLIB=y which is
the only case where this would work. Having phylib as a module or not
compiled at all will result in that kind of linking failure:
arch/arm/mach-at91/built-in.o: In function `ksz9021rn_phy_fixup':
:(.text+0x1174): undefined reference to `mdiobus_write'
:(.text+0x1188): undefined reference to `mdiobus_write'
:(.text+0x119c): undefined reference to `mdiobus_write'
:(.text+0x11b0): undefined reference to `mdiobus_write'
arch/arm/mach-at91/built-in.o: In function `sama5_dt_device_init':
:(.init.text+0x1e34): undefined reference to `phy_register_fixup_for_uid'
Signed-off-by: Alexandre Belloni <redacted>
---
drivers/net/phy/phy_device.c | 6 ++++++
include/linux/phy.h | 12 ++++++++++++
2 files changed, 18 insertions(+)
@@ -556,12 +556,24 @@ int phy_start_interrupts(struct phy_device *phydev);voidphy_print_status(structphy_device*phydev);voidphy_device_free(structphy_device*phydev);+/*+*phy_register_fixup{,_for_uid,_for_id}arecalledfromarch/sothiswon't+*workunlessphylibiscompiledinthekernel.+*Definingstubsallowstopreventlinkingerrors.+*/+#ifdef CONFIG_PHYLIBintphy_register_fixup(constchar*bus_id,u32phy_uid,u32phy_uid_mask,int(*run)(structphy_device*));intphy_register_fixup_for_id(constchar*bus_id,int(*run)(structphy_device*));intphy_register_fixup_for_uid(u32phy_uid,u32phy_uid_mask,int(*run)(structphy_device*));+#else+#define phy_register_fixup(a, b, c, d) do { } while (0)+#define phy_register_fixup_for_id(a, b) do { } while (0)+#define phy_register_fixup_for_uid(a, b, c) do { } while (0)
Use static inline functions here. This breaks if someone does result
checking on the functions which then expands to ret = do {} while (0);
Also we still have type safety for !CONFIG_PHYLIB.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
On Mon, May 27, 2013 at 06:18:42PM +0200, Alexandre Belloni wrote:
quoted
phy_register_fixup{,_for_uid,_for_id} are called from arch/, quite
often, there is no protection to check whether CONFIG_PHYLIB=y which is
the only case where this would work. Having phylib as a module or not
compiled at all will result in that kind of linking failure:
arch/arm/mach-at91/built-in.o: In function `ksz9021rn_phy_fixup':
:(.text+0x1174): undefined reference to `mdiobus_write'
:(.text+0x1188): undefined reference to `mdiobus_write'
:(.text+0x119c): undefined reference to `mdiobus_write'
:(.text+0x11b0): undefined reference to `mdiobus_write'
arch/arm/mach-at91/built-in.o: In function `sama5_dt_device_init':
:(.init.text+0x1e34): undefined reference to `phy_register_fixup_for_uid'
Signed-off-by: Alexandre Belloni <redacted>
---
drivers/net/phy/phy_device.c | 6 ++++++
include/linux/phy.h | 12 ++++++++++++
2 files changed, 18 insertions(+)
@@ -556,12 +556,24 @@ int phy_start_interrupts(struct phy_device *phydev);voidphy_print_status(structphy_device*phydev);voidphy_device_free(structphy_device*phydev);+/*+*phy_register_fixup{,_for_uid,_for_id}arecalledfromarch/sothiswon't+*workunlessphylibiscompiledinthekernel.+*Definingstubsallowstopreventlinkingerrors.+*/+#ifdef CONFIG_PHYLIBintphy_register_fixup(constchar*bus_id,u32phy_uid,u32phy_uid_mask,int(*run)(structphy_device*));intphy_register_fixup_for_id(constchar*bus_id,int(*run)(structphy_device*));intphy_register_fixup_for_uid(u32phy_uid,u32phy_uid_mask,int(*run)(structphy_device*));+#else+#define phy_register_fixup(a, b, c, d) do { } while (0)+#define phy_register_fixup_for_id(a, b) do { } while (0)+#define phy_register_fixup_for_uid(a, b, c) do { } while (0)
Use static inline functions here. This breaks if someone does result
checking on the functions which then expands to ret = do {} while (0);
Also we still have type safety for !CONFIG_PHYLIB.
Right, I tried that first but forgot static so I had issues with
redefinition of the functions. I even played with __weak at some point...
I'll wait a bit for comments before sending v2.
--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
Hi,
Le 27 mai 2013 19:38, "Alexandre Belloni" <alexandre.belloni@free-
electrons.com> a écrit :
[snip]
quoted
quoted
+/*
+ * phy_register_fixup{,_for_uid,_for_id} are called from arch/ so this
won't
quoted
quoted
+ * work unless phylib is compiled in the kernel.+ * Defining stubs allows to prevent linking errors.+ */+#ifdef CONFIG_PHYLIB int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask, int (*run)(struct phy_device *)); 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 *));+#else+#define phy_register_fixup(a, b, c, d) do { } while (0)+#define phy_register_fixup_for_id(a, b) do { } while (0)+#define phy_register_fixup_for_uid(a, b, c) do { } while (0)
Use static inline functions here. This breaks if someone does result
checking on the functions which then expands to ret = do {} while (0);
Also we still have
Right, I tried that first but forgot static so I had issues with
redefinition of the functions. I even played with __weak at some point...
You might even want to make these static inlines as mentionned earlier, and
return something like -ENOTSUPP so that someone using these in board code and
wondering why they do not work gets a chance to enable CONIFG_PHYLIB.
--
Florian