Skip to content

Commit 90eff90

Browse files
ffainellidavem330
authored andcommitted
net: phy: Allow splitting MDIO bus/device support from PHYs
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> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 17487ee commit 90eff90

File tree

6 files changed

+76
-30
lines changed

6 files changed

+76
-30
lines changed

drivers/net/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ obj-$(CONFIG_MII) += mii.o
1818
obj-$(CONFIG_MDIO) += mdio.o
1919
obj-$(CONFIG_NET) += Space.o loopback.o
2020
obj-$(CONFIG_NETCONSOLE) += netconsole.o
21-
obj-$(CONFIG_PHYLIB) += phy/
21+
obj-$(CONFIG_MDIO_DEVICE) += phy/
2222
obj-$(CONFIG_RIONET) += rionet.o
2323
obj-$(CONFIG_NET_TEAM) += team/
2424
obj-$(CONFIG_TUN) += tun.o

drivers/net/phy/Kconfig

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,12 @@
22
# PHY Layer Configuration
33
#
44

5-
menuconfig PHYLIB
6-
tristate "PHY Device support and infrastructure"
7-
depends on NETDEVICES
5+
menuconfig MDIO_DEVICE
6+
tristate "MDIO bus device drivers"
87
help
9-
Ethernet controllers are usually attached to PHY
10-
devices. This option provides infrastructure for
11-
managing PHY devices.
12-
13-
if PHYLIB
14-
15-
config SWPHY
16-
bool
17-
18-
config LED_TRIGGER_PHY
19-
bool "Support LED triggers for tracking link state"
20-
depends on LEDS_TRIGGERS
21-
---help---
22-
Adds support for a set of LED trigger events per-PHY. Link
23-
state change will trigger the events, for consumption by an
24-
LED class driver. There are triggers for each link speed currently
25-
supported by the phy, and are of the form:
26-
<mii bus id>:<phy>:<speed>
27-
28-
Where speed is in the form:
29-
<Speed in megabits>Mbps or <Speed in gigabits>Gbps
8+
MDIO devices and driver infrastructure code.
309

31-
comment "MDIO bus device drivers"
10+
if MDIO_DEVICE
3211

3312
config MDIO_BCM_IPROC
3413
tristate "Broadcom iProc MDIO bus controller"
@@ -49,6 +28,7 @@ config MDIO_BCM_UNIMAC
4928

5029
config MDIO_BITBANG
5130
tristate "Bitbanged MDIO buses"
31+
depends on !(MDIO_DEVICE=y && PHYLIB=m)
5232
help
5333
This module implements the MDIO bus protocol in software,
5434
for use by low level drivers that export the ability to
@@ -160,6 +140,36 @@ config MDIO_XGENE
160140
This module provides a driver for the MDIO busses found in the
161141
APM X-Gene SoC's.
162142

143+
endif
144+
145+
menuconfig PHYLIB
146+
tristate "PHY Device support and infrastructure"
147+
depends on NETDEVICES
148+
select MDIO_DEVICE
149+
help
150+
Ethernet controllers are usually attached to PHY
151+
devices. This option provides infrastructure for
152+
managing PHY devices.
153+
154+
if PHYLIB
155+
156+
config SWPHY
157+
bool
158+
159+
config LED_TRIGGER_PHY
160+
bool "Support LED triggers for tracking link state"
161+
depends on LEDS_TRIGGERS
162+
---help---
163+
Adds support for a set of LED trigger events per-PHY. Link
164+
state change will trigger the events, for consumption by an
165+
LED class driver. There are triggers for each link speed currently
166+
supported by the phy, and are of the form:
167+
<mii bus id>:<phy>:<speed>
168+
169+
Where speed is in the form:
170+
<Speed in megabits>Mbps or <Speed in gigabits>Gbps
171+
172+
163173
comment "MII PHY device drivers"
164174

165175
config AMD_PHY

drivers/net/phy/Makefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
# Makefile for Linux PHY drivers and MDIO bus drivers
22

3-
libphy-y := phy.o phy_device.o mdio_bus.o mdio_device.o \
4-
mdio-boardinfo.o phy-core.o
3+
libphy-y := phy.o phy-core.o phy_device.o
4+
mdio-bus-y += mdio_bus.o mdio_device.o mdio-boardinfo.o
5+
6+
# PHYLIB implies MDIO_DEVICE, in that case, we have a bunch of circular
7+
# dependencies that does not make it possible to split mdio-bus objects into a
8+
# dedicated loadable module, so we bundle them all together into libphy.ko
9+
ifdef CONFIG_PHYLIB
10+
libphy-y += $(mdio-bus-y)
11+
else
12+
obj-$(CONFIG_MDIO_DEVICE) += mdio-bus.o
13+
endif
514
libphy-$(CONFIG_SWPHY) += swphy.o
615
libphy-$(CONFIG_LED_TRIGGER_PHY) += phy_led_triggers.o
716

drivers/net/phy/mdio-boardinfo.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,4 @@ int mdiobus_register_board_info(const struct mdio_board_info *info,
8484

8585
return 0;
8686
}
87+
EXPORT_SYMBOL(mdiobus_register_board_info);

drivers/net/phy/mdio_bus.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,9 +648,18 @@ int __init mdio_bus_init(void)
648648

649649
return ret;
650650
}
651+
EXPORT_SYMBOL_GPL(mdio_bus_init);
651652

653+
#if IS_ENABLED(CONFIG_PHYLIB)
652654
void mdio_bus_exit(void)
653655
{
654656
class_unregister(&mdio_bus_class);
655657
bus_unregister(&mdio_bus_type);
656658
}
659+
EXPORT_SYMBOL_GPL(mdio_bus_exit);
660+
#else
661+
module_init(mdio_bus_init);
662+
/* no module_exit, intentional */
663+
MODULE_LICENSE("GPL");
664+
MODULE_DESCRIPTION("MDIO bus/device layer");
665+
#endif

include/linux/phy.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,24 @@ int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val);
745745
struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
746746
bool is_c45,
747747
struct phy_c45_device_ids *c45_ids);
748+
#if IS_ENABLED(CONFIG_PHYLIB)
748749
struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45);
749750
int phy_device_register(struct phy_device *phy);
751+
void phy_device_free(struct phy_device *phydev);
752+
#else
753+
static inline
754+
struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45)
755+
{
756+
return NULL;
757+
}
758+
759+
static inline int phy_device_register(struct phy_device *phy)
760+
{
761+
return 0;
762+
}
763+
764+
static inline void phy_device_free(struct phy_device *phydev) { }
765+
#endif /* CONFIG_PHYLIB */
750766
void phy_device_remove(struct phy_device *phydev);
751767
int phy_init_hw(struct phy_device *phydev);
752768
int phy_suspend(struct phy_device *phydev);
@@ -827,7 +843,6 @@ int phy_ethtool_ksettings_set(struct phy_device *phydev,
827843
int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd);
828844
int phy_start_interrupts(struct phy_device *phydev);
829845
void phy_print_status(struct phy_device *phydev);
830-
void phy_device_free(struct phy_device *phydev);
831846
int phy_set_max_speed(struct phy_device *phydev, u32 max_speed);
832847

833848
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,
854869
const struct ethtool_link_ksettings *cmd);
855870
int phy_ethtool_nway_reset(struct net_device *ndev);
856871

872+
#if IS_ENABLED(CONFIG_PHYLIB)
857873
int __init mdio_bus_init(void);
858874
void mdio_bus_exit(void);
875+
#endif
859876

860877
extern struct bus_type mdio_bus_type;
861878

@@ -866,7 +883,7 @@ struct mdio_board_info {
866883
const void *platform_data;
867884
};
868885

869-
#if IS_ENABLED(CONFIG_PHYLIB)
886+
#if IS_ENABLED(CONFIG_MDIO_DEVICE)
870887
int mdiobus_register_board_info(const struct mdio_board_info *info,
871888
unsigned int n);
872889
#else

0 commit comments

Comments
 (0)