All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v3 0/3] net: phy: Allow splitting MDIO bus/device support
@ 2017-03-23 17:01 Florian Fainelli
  2017-03-23 17:01 ` [PATCH net-next v3 1/3] of_mdio: Correct check against CONFIG_OF Florian Fainelli
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Florian Fainelli @ 2017-03-23 17:01 UTC (permalink / raw)
  To: netdev; +Cc: davem, andrew, rmk+kernel, arnd, Florian Fainelli

Hi all,

This patch series allows building support for MDIO bus controllers which
are sometimes usable and necessary in cases where there are no Ethernet PHYs.

Changes in v3:
- corrected of_mdio compile guards for prototypes vs. stubs
- added a missing OF_MDIO dependency for MDIO_BCM_UNIMAC
- fixed Kbuild bot reported errors against mdio-bitbang

Changes in v2:
- implement Russell's feedback
- solve the circular dependency in the CONFIG_MDIO_DEVICE + CONFIG_PHYLIB case


Florian Fainelli (3):
  of_mdio: Correct check against CONFIG_OF
  net: phy: MDIO_BCM_UNIMAC should depend on OF_MDIO
  net: phy: Allow splitting MDIO bus/device support from PHYs

 drivers/net/Makefile             |  2 +-
 drivers/net/phy/Kconfig          | 62 +++++++++++++++++++++++-----------------
 drivers/net/phy/Makefile         | 13 +++++++--
 drivers/net/phy/mdio-boardinfo.c |  1 +
 drivers/net/phy/mdio_bus.c       |  9 ++++++
 include/linux/of_mdio.h          |  4 +--
 include/linux/phy.h              | 21 ++++++++++++--
 7 files changed, 79 insertions(+), 33 deletions(-)

-- 
2.9.3

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net-next v3 1/3] of_mdio: Correct check against CONFIG_OF
  2017-03-23 17:01 [PATCH net-next v3 0/3] net: phy: Allow splitting MDIO bus/device support Florian Fainelli
@ 2017-03-23 17:01 ` Florian Fainelli
  2017-03-23 17:01 ` [PATCH net-next v3 2/3] net: phy: MDIO_BCM_UNIMAC should depend on OF_MDIO Florian Fainelli
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Florian Fainelli @ 2017-03-23 17:01 UTC (permalink / raw)
  To: netdev; +Cc: davem, andrew, rmk+kernel, arnd, Florian Fainelli

CONFIG_OF_MDIO is actually what triggers the build of drivers/of/of_mdio.c, so
providing inline stubs when CONFIG_OF_MDIO=y should be based on that symbol as
well.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 include/linux/of_mdio.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/of_mdio.h b/include/linux/of_mdio.h
index a58cca8bcb29..ba35ba520487 100644
--- a/include/linux/of_mdio.h
+++ b/include/linux/of_mdio.h
@@ -12,7 +12,7 @@
 #include <linux/phy.h>
 #include <linux/of.h>
 
-#ifdef CONFIG_OF
+#if IS_ENABLED(CONFIG_OF_MDIO)
 extern int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np);
 extern struct phy_device *of_phy_find_device(struct device_node *phy_np);
 extern struct phy_device *of_phy_connect(struct net_device *dev,
@@ -32,7 +32,7 @@ extern int of_phy_register_fixed_link(struct device_node *np);
 extern void of_phy_deregister_fixed_link(struct device_node *np);
 extern bool of_phy_is_fixed_link(struct device_node *np);
 
-#else /* CONFIG_OF */
+#else /* CONFIG_OF_MDIO */
 static inline int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
 {
 	/*
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next v3 2/3] net: phy: MDIO_BCM_UNIMAC should depend on OF_MDIO
  2017-03-23 17:01 [PATCH net-next v3 0/3] net: phy: Allow splitting MDIO bus/device support Florian Fainelli
  2017-03-23 17:01 ` [PATCH net-next v3 1/3] of_mdio: Correct check against CONFIG_OF Florian Fainelli
@ 2017-03-23 17:01 ` Florian Fainelli
  2017-03-23 17:01 ` [PATCH net-next v3 3/3] net: phy: Allow splitting MDIO bus/device support from PHYs Florian Fainelli
  2017-03-24 19:51 ` [PATCH net-next v3 0/3] net: phy: Allow splitting MDIO bus/device support David Miller
  3 siblings, 0 replies; 6+ messages in thread
From: Florian Fainelli @ 2017-03-23 17:01 UTC (permalink / raw)
  To: netdev; +Cc: davem, andrew, rmk+kernel, arnd, Florian Fainelli

The Broadcom MDIO UniMAC driver uses routines provided by of_mdio.c which is
guarded by CONFIG_OF_MDIO.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 drivers/net/phy/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index 8dbd59baa34d..7ab4b14a43b7 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -40,7 +40,7 @@ config MDIO_BCM_IPROC
 
 config MDIO_BCM_UNIMAC
 	tristate "Broadcom UniMAC MDIO bus controller"
-	depends on HAS_IOMEM
+	depends on HAS_IOMEM && OF_MDIO
 	help
 	  This module provides a driver for the Broadcom UniMAC MDIO busses.
 	  This hardware can be found in the Broadcom GENET Ethernet MAC
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next v3 3/3] net: phy: Allow splitting MDIO bus/device support from PHYs
  2017-03-23 17:01 [PATCH net-next v3 0/3] net: phy: Allow splitting MDIO bus/device support Florian Fainelli
  2017-03-23 17:01 ` [PATCH net-next v3 1/3] of_mdio: Correct check against CONFIG_OF Florian Fainelli
  2017-03-23 17:01 ` [PATCH net-next v3 2/3] net: phy: MDIO_BCM_UNIMAC should depend on OF_MDIO Florian Fainelli
@ 2017-03-23 17:01 ` Florian Fainelli
  2017-03-27 15:41   ` Arnd Bergmann
  2017-03-24 19:51 ` [PATCH net-next v3 0/3] net: phy: Allow splitting MDIO bus/device support David Miller
  3 siblings, 1 reply; 6+ messages in thread
From: Florian Fainelli @ 2017-03-23 17:01 UTC (permalink / raw)
  To: netdev; +Cc: davem, andrew, rmk+kernel, arnd, Florian Fainelli

Introduce a new configuration symbol: MDIO_DEVICE which allows building
the MDIO devices and bus code, without pulling in the entire Ethernet
PHY library and devices code.

PHYLIB nows select MDIO_DEVICE and the relevant Makefile files are
updated to reflect that.

When MDIO_DEVICE (MDIO bus/device only) is selected, but not PHYLIB, we
have mdio-bus.ko as a loadable module, and it does not have a
module_exit() function because the safety of removing a bus class is
unclear.

When both MDIO_DEVICE and PHYLIB are enabled, we need to assemble
everything into a common loadable module: libphy.ko because of nasty
circular dependencies between phy.c, phy_device.c and mdio_bus.c which
are really tough to untangle.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 drivers/net/Makefile             |  2 +-
 drivers/net/phy/Kconfig          | 60 +++++++++++++++++++++++-----------------
 drivers/net/phy/Makefile         | 13 +++++++--
 drivers/net/phy/mdio-boardinfo.c |  1 +
 drivers/net/phy/mdio_bus.c       |  9 ++++++
 include/linux/phy.h              | 21 ++++++++++++--
 6 files changed, 76 insertions(+), 30 deletions(-)

diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index 98ed4d96987c..55f75aea283c 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -18,7 +18,7 @@ obj-$(CONFIG_MII) += mii.o
 obj-$(CONFIG_MDIO) += mdio.o
 obj-$(CONFIG_NET) += Space.o loopback.o
 obj-$(CONFIG_NETCONSOLE) += netconsole.o
-obj-$(CONFIG_PHYLIB) += phy/
+obj-$(CONFIG_MDIO_DEVICE) += phy/
 obj-$(CONFIG_RIONET) += rionet.o
 obj-$(CONFIG_NET_TEAM) += team/
 obj-$(CONFIG_TUN) += tun.o
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index 7ab4b14a43b7..60ffc9da6a28 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -2,33 +2,12 @@
 # PHY Layer Configuration
 #
 
-menuconfig PHYLIB
-	tristate "PHY Device support and infrastructure"
-	depends on NETDEVICES
+menuconfig MDIO_DEVICE
+	tristate "MDIO bus device drivers"
 	help
-	  Ethernet controllers are usually attached to PHY
-	  devices.  This option provides infrastructure for
-	  managing PHY devices.
-
-if PHYLIB
-
-config SWPHY
-	bool
-
-config LED_TRIGGER_PHY
-	bool "Support LED triggers for tracking link state"
-	depends on LEDS_TRIGGERS
-	---help---
-	  Adds support for a set of LED trigger events per-PHY.  Link
-	  state change will trigger the events, for consumption by an
-	  LED class driver.  There are triggers for each link speed currently
-	  supported by the phy, and are of the form:
-	       <mii bus id>:<phy>:<speed>
-
-	  Where speed is in the form:
-		<Speed in megabits>Mbps or <Speed in gigabits>Gbps
+	   MDIO devices and driver infrastructure code.
 
-comment "MDIO bus device drivers"
+if MDIO_DEVICE
 
 config MDIO_BCM_IPROC
 	tristate "Broadcom iProc MDIO bus controller"
@@ -49,6 +28,7 @@ config MDIO_BCM_UNIMAC
 
 config MDIO_BITBANG
 	tristate "Bitbanged MDIO buses"
+	depends on !(MDIO_DEVICE=y && PHYLIB=m)
 	help
 	  This module implements the MDIO bus protocol in software,
 	  for use by low level drivers that export the ability to
@@ -160,6 +140,36 @@ config MDIO_XGENE
 	  This module provides a driver for the MDIO busses found in the
 	  APM X-Gene SoC's.
 
+endif
+
+menuconfig PHYLIB
+	tristate "PHY Device support and infrastructure"
+	depends on NETDEVICES
+	select MDIO_DEVICE
+	help
+	  Ethernet controllers are usually attached to PHY
+	  devices.  This option provides infrastructure for
+	  managing PHY devices.
+
+if PHYLIB
+
+config SWPHY
+	bool
+
+config LED_TRIGGER_PHY
+	bool "Support LED triggers for tracking link state"
+	depends on LEDS_TRIGGERS
+	---help---
+	  Adds support for a set of LED trigger events per-PHY.  Link
+	  state change will trigger the events, for consumption by an
+	  LED class driver.  There are triggers for each link speed currently
+	  supported by the phy, and are of the form:
+	       <mii bus id>:<phy>:<speed>
+
+	  Where speed is in the form:
+		<Speed in megabits>Mbps or <Speed in gigabits>Gbps
+
+
 comment "MII PHY device drivers"
 
 config AMD_PHY
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
index 82d915614646..0e1ec0438c23 100644
--- a/drivers/net/phy/Makefile
+++ b/drivers/net/phy/Makefile
@@ -1,7 +1,16 @@
 # Makefile for Linux PHY drivers and MDIO bus drivers
 
-libphy-y			:= phy.o phy_device.o mdio_bus.o mdio_device.o \
-				   mdio-boardinfo.o phy-core.o
+libphy-y			:= phy.o phy-core.o phy_device.o
+mdio-bus-y			+= mdio_bus.o mdio_device.o mdio-boardinfo.o
+
+# 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)
+else
+obj-$(CONFIG_MDIO_DEVICE)	+= mdio-bus.o
+endif
 libphy-$(CONFIG_SWPHY)		+= swphy.o
 libphy-$(CONFIG_LED_TRIGGER_PHY)	+= phy_led_triggers.o
 
diff --git a/drivers/net/phy/mdio-boardinfo.c b/drivers/net/phy/mdio-boardinfo.c
index 6b988f77da08..61941e29daae 100644
--- a/drivers/net/phy/mdio-boardinfo.c
+++ b/drivers/net/phy/mdio-boardinfo.c
@@ -84,3 +84,4 @@ int mdiobus_register_board_info(const struct mdio_board_info *info,
 
 	return 0;
 }
+EXPORT_SYMBOL(mdiobus_register_board_info);
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index fa7d51f14869..46b468eb6e12 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -648,9 +648,18 @@ int __init mdio_bus_init(void)
 
 	return ret;
 }
+EXPORT_SYMBOL_GPL(mdio_bus_init);
 
+#if IS_ENABLED(CONFIG_PHYLIB)
 void 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 */
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("MDIO bus/device layer");
+#endif
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 2efca6b39fba..624cecf69c28 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -745,8 +745,24 @@ int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val);
 struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
 				     bool is_c45,
 				     struct phy_c45_device_ids *c45_ids);
+#if IS_ENABLED(CONFIG_PHYLIB)
 struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45);
 int phy_device_register(struct phy_device *phy);
+void phy_device_free(struct phy_device *phydev);
+#else
+static inline
+struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45)
+{
+	return NULL;
+}
+
+static inline int phy_device_register(struct phy_device *phy)
+{
+	return 0;
+}
+
+static inline void phy_device_free(struct phy_device *phydev) { }
+#endif /* CONFIG_PHYLIB */
 void phy_device_remove(struct phy_device *phydev);
 int phy_init_hw(struct phy_device *phydev);
 int phy_suspend(struct phy_device *phydev);
@@ -827,7 +843,6 @@ int phy_ethtool_ksettings_set(struct phy_device *phydev,
 int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd);
 int phy_start_interrupts(struct phy_device *phydev);
 void phy_print_status(struct phy_device *phydev);
-void phy_device_free(struct phy_device *phydev);
 int phy_set_max_speed(struct phy_device *phydev, u32 max_speed);
 
 int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask,
@@ -854,8 +869,10 @@ 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);
 
+#if IS_ENABLED(CONFIG_PHYLIB)
 int __init mdio_bus_init(void);
 void mdio_bus_exit(void);
+#endif
 
 extern struct bus_type mdio_bus_type;
 
@@ -866,7 +883,7 @@ struct mdio_board_info {
 	const void	*platform_data;
 };
 
-#if IS_ENABLED(CONFIG_PHYLIB)
+#if IS_ENABLED(CONFIG_MDIO_DEVICE)
 int mdiobus_register_board_info(const struct mdio_board_info *info,
 				unsigned int n);
 #else
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v3 0/3] net: phy: Allow splitting MDIO bus/device support
  2017-03-23 17:01 [PATCH net-next v3 0/3] net: phy: Allow splitting MDIO bus/device support Florian Fainelli
                   ` (2 preceding siblings ...)
  2017-03-23 17:01 ` [PATCH net-next v3 3/3] net: phy: Allow splitting MDIO bus/device support from PHYs Florian Fainelli
@ 2017-03-24 19:51 ` David Miller
  3 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2017-03-24 19:51 UTC (permalink / raw)
  To: f.fainelli; +Cc: netdev, andrew, rmk+kernel, arnd

From: Florian Fainelli <f.fainelli@gmail.com>
Date: Thu, 23 Mar 2017 10:01:16 -0700

> This patch series allows building support for MDIO bus controllers which
> are sometimes usable and necessary in cases where there are no Ethernet PHYs.
> 
> Changes in v3:
> - corrected of_mdio compile guards for prototypes vs. stubs
> - added a missing OF_MDIO dependency for MDIO_BCM_UNIMAC
> - fixed Kbuild bot reported errors against mdio-bitbang
> 
> Changes in v2:
> - implement Russell's feedback
> - solve the circular dependency in the CONFIG_MDIO_DEVICE + CONFIG_PHYLIB case

Series applied, thanks Florian.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v3 3/3] net: phy: Allow splitting MDIO bus/device support from PHYs
  2017-03-23 17:01 ` [PATCH net-next v3 3/3] net: phy: Allow splitting MDIO bus/device support from PHYs Florian Fainelli
@ 2017-03-27 15:41   ` Arnd Bergmann
  0 siblings, 0 replies; 6+ messages in thread
From: Arnd Bergmann @ 2017-03-27 15:41 UTC (permalink / raw)
  To: Florian Fainelli; +Cc: Networking, David Miller, Andrew Lunn, rmk+kernel

On Thu, Mar 23, 2017 at 6:01 PM, Florian Fainelli <f.fainelli@gmail.com> wrote:
> Introduce a new configuration symbol: MDIO_DEVICE which allows building
> the MDIO devices and bus code, without pulling in the entire Ethernet
> PHY library and devices code.
>
> PHYLIB nows select MDIO_DEVICE and the relevant Makefile files are
> updated to reflect that.
>
> When MDIO_DEVICE (MDIO bus/device only) is selected, but not PHYLIB, we
> have mdio-bus.ko as a loadable module, and it does not have a
> module_exit() function because the safety of removing a bus class is
> unclear.
>
> When both MDIO_DEVICE and PHYLIB are enabled, we need to assemble
> everything into a common loadable module: libphy.ko because of nasty
> circular dependencies between phy.c, phy_device.c and mdio_bus.c which
> are really tough to untangle.

I'm getting a couple of link errors with this:

- ARCH_ORION5X calls mdiobus_register_board_info and must force
  mdio-boardinfo.o to be built-in, but I don't see how it should
ideally do that:

arch/arm/plat-orion/common.o: In function `orion_ge00_switch_init':
common.c:(.init.text+0x6a6): undefined reference to
`mdiobus_register_board_info'

- sun4i_mdio.ko depends on mdiobus, but it gets selected from another driver
  which makes it built-in without checking if mdiobus is a module

drivers/net/built-in.o: In function `sun4i_mdio_remove':
:(.text+0x51c): undefined reference to `mdiobus_unregister'
:(.text+0x524): undefined reference to `mdiobus_free'
drivers/net/built-in.o: In function `sun4i_mdio_probe':
:(.text+0x728): undefined reference to `mdiobus_alloc_size'
:(.text+0x85c): undefined reference to `of_mdiobus_register'
:(.text+0x894): undefined reference to `mdiobus_free'

- Some drivers select MDIO_BITBANG, which may need to be a module:
warning: (FS_ENET_MDIO_FCC && AX88796 && SH_ETH && RAVB) selects
MDIO_BITBANG which has unmet direct dependencies (NETDEVICES &&
MDIO_DEVICE && (MDIO_DEVICE!=y || PHYLIB!=m))

I've been able to work around the latter two using this hack:

diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index 60ffc9da6a28..d82857f46cec 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -28,7 +28,7 @@ config MDIO_BCM_UNIMAC

 config MDIO_BITBANG
  tristate "Bitbanged MDIO buses"
- depends on !(MDIO_DEVICE=y && PHYLIB=m)
+ depends on m || !(MDIO_DEVICE=y && PHYLIB=m)
  help
   This module implements the MDIO bus protocol in software,
   for use by low level drivers that export the ability to
@@ -118,6 +118,7 @@ config MDIO_OCTEON
 config MDIO_SUN4I
  tristate "Allwinner sun4i MDIO interface support"
  depends on ARCH_SUNXI
+ depends on m || !(MDIO_DEVICE=y && PHYLIB=m)
  help
   This driver supports the MDIO interface found in the network
   interface units of the Allwinner SoC that have an EMAC (A10,


      Arnd

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-03-27 15:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-23 17:01 [PATCH net-next v3 0/3] net: phy: Allow splitting MDIO bus/device support Florian Fainelli
2017-03-23 17:01 ` [PATCH net-next v3 1/3] of_mdio: Correct check against CONFIG_OF Florian Fainelli
2017-03-23 17:01 ` [PATCH net-next v3 2/3] net: phy: MDIO_BCM_UNIMAC should depend on OF_MDIO Florian Fainelli
2017-03-23 17:01 ` [PATCH net-next v3 3/3] net: phy: Allow splitting MDIO bus/device support from PHYs Florian Fainelli
2017-03-27 15:41   ` Arnd Bergmann
2017-03-24 19:51 ` [PATCH net-next v3 0/3] net: phy: Allow splitting MDIO bus/device support David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.