1 From 52c956003a9d5bcae1f445f9dfd42b624adb6e87 Mon Sep 17 00:00:00 2001
2 From: Russell King <rmk+kernel@armlinux.org.uk>
3 Date: Wed, 11 Dec 2019 10:56:45 +0000
4 Subject: [PATCH] net: phylink: delay MAC configuration for copper SFP modules
6 Knowing whether we need to delay the MAC configuration because a module
7 may have a PHY is useful to phylink to allow NBASE-T modules to work on
8 systems supporting no more than 2.5G speeds.
10 This commit allows us to delay such configuration until after the PHY
11 has been probed by recording the parsed capabilities, and if the module
12 may have a PHY, doing no more until the module_start() notification is
13 called. At that point, we either have a PHY, or we don't.
15 We move the PHY-based setup a little later, and use the PHYs support
16 capabilities rather than the EEPROM parsed capabilities to determine
17 whether we can support the PHY.
19 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
20 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
21 Signed-off-by: David S. Miller <davem@davemloft.net>
23 drivers/net/phy/phylink.c | 53 +++++++++++++++++++++++++++++++--------
24 drivers/net/phy/sfp-bus.c | 28 +++++++++++++++++++++
25 include/linux/sfp.h | 7 ++++++
26 3 files changed, 78 insertions(+), 10 deletions(-)
28 --- a/drivers/net/phy/phylink.c
29 +++ b/drivers/net/phy/phylink.c
30 @@ -72,6 +72,9 @@ struct phylink {
31 bool mac_link_dropped;
33 struct sfp_bus *sfp_bus;
34 + bool sfp_may_have_phy;
35 + __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support);
39 #define phylink_printk(level, pl, fmt, ...) \
40 @@ -1688,7 +1691,7 @@ static void phylink_sfp_detach(void *ups
41 pl->netdev->sfp_bus = NULL;
44 -static int phylink_sfp_config(struct phylink *pl, u8 mode, u8 port,
45 +static int phylink_sfp_config(struct phylink *pl, u8 mode,
46 const unsigned long *supported,
47 const unsigned long *advertising)
49 @@ -1762,7 +1765,7 @@ static int phylink_sfp_config(struct phy
50 phy_modes(config.interface));
53 - pl->link_port = port;
54 + pl->link_port = pl->sfp_port;
56 if (changed && !test_bit(PHYLINK_DISABLE_STOPPED,
57 &pl->phylink_disable_state))
58 @@ -1775,15 +1778,20 @@ static int phylink_sfp_module_insert(voi
59 const struct sfp_eeprom_id *id)
61 struct phylink *pl = upstream;
62 - __ETHTOOL_DECLARE_LINK_MODE_MASK(support) = { 0, };
64 + unsigned long *support = pl->sfp_support;
68 + linkmode_zero(support);
69 sfp_parse_support(pl->sfp_bus, id, support);
70 - port = sfp_parse_port(pl->sfp_bus, id, support);
71 + pl->sfp_port = sfp_parse_port(pl->sfp_bus, id, support);
73 - return phylink_sfp_config(pl, MLO_AN_INBAND, port, support, support);
74 + /* If this module may have a PHY connecting later, defer until later */
75 + pl->sfp_may_have_phy = sfp_may_have_phy(pl->sfp_bus, id);
76 + if (pl->sfp_may_have_phy)
79 + return phylink_sfp_config(pl, MLO_AN_INBAND, support, support);
82 static int phylink_sfp_module_start(void *upstream)
83 @@ -1791,10 +1799,19 @@ static int phylink_sfp_module_start(void
84 struct phylink *pl = upstream;
86 /* If this SFP module has a PHY, start the PHY now. */
89 phy_start(pl->phydev);
95 + /* If the module may have a PHY but we didn't detect one we
96 + * need to configure the MAC here.
98 + if (!pl->sfp_may_have_phy)
101 + return phylink_sfp_config(pl, MLO_AN_INBAND,
102 + pl->sfp_support, pl->sfp_support);
105 static void phylink_sfp_module_stop(void *upstream)
106 @@ -1828,10 +1845,26 @@ static void phylink_sfp_link_up(void *up
107 static int phylink_sfp_connect_phy(void *upstream, struct phy_device *phy)
109 struct phylink *pl = upstream;
110 - phy_interface_t interface = pl->link_config.interface;
111 + phy_interface_t interface;
114 - ret = phylink_attach_phy(pl, phy, pl->link_config.interface);
116 + * This is the new way of dealing with flow control for PHYs,
117 + * as described by Timur Tabi in commit 529ed1275263 ("net: phy:
118 + * phy drivers should not set SUPPORTED_[Asym_]Pause") except
119 + * using our validate call to the MAC, we rely upon the MAC
120 + * clearing the bits from both supported and advertising fields.
122 + phy_support_asym_pause(phy);
124 + /* Do the initial configuration */
125 + ret = phylink_sfp_config(pl, MLO_AN_INBAND, phy->supported,
130 + interface = pl->link_config.interface;
131 + ret = phylink_attach_phy(pl, phy, interface);
135 --- a/drivers/net/phy/sfp-bus.c
136 +++ b/drivers/net/phy/sfp-bus.c
137 @@ -103,6 +103,7 @@ static const struct sfp_quirk *sfp_looku
143 * sfp_parse_port() - Parse the EEPROM base ID, setting the port type
144 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
145 @@ -179,6 +180,33 @@ int sfp_parse_port(struct sfp_bus *bus,
146 EXPORT_SYMBOL_GPL(sfp_parse_port);
149 + * sfp_may_have_phy() - indicate whether the module may have a PHY
150 + * @bus: a pointer to the &struct sfp_bus structure for the sfp module
151 + * @id: a pointer to the module's &struct sfp_eeprom_id
153 + * Parse the EEPROM identification given in @id, and return whether
154 + * this module may have a PHY.
156 +bool sfp_may_have_phy(struct sfp_bus *bus, const struct sfp_eeprom_id *id)
158 + if (id->base.e1000_base_t)
161 + if (id->base.phys_id != SFF8024_ID_DWDM_SFP) {
162 + switch (id->base.extended_cc) {
163 + case SFF8024_ECC_10GBASE_T_SFI:
164 + case SFF8024_ECC_10GBASE_T_SR:
165 + case SFF8024_ECC_5GBASE_T:
166 + case SFF8024_ECC_2_5GBASE_T:
173 +EXPORT_SYMBOL_GPL(sfp_may_have_phy);
176 * sfp_parse_support() - Parse the eeprom id for supported link modes
177 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
178 * @id: a pointer to the module's &struct sfp_eeprom_id
179 --- a/include/linux/sfp.h
180 +++ b/include/linux/sfp.h
181 @@ -533,6 +533,7 @@ struct sfp_upstream_ops {
182 #if IS_ENABLED(CONFIG_SFP)
183 int sfp_parse_port(struct sfp_bus *bus, const struct sfp_eeprom_id *id,
184 unsigned long *support);
185 +bool sfp_may_have_phy(struct sfp_bus *bus, const struct sfp_eeprom_id *id);
186 void sfp_parse_support(struct sfp_bus *bus, const struct sfp_eeprom_id *id,
187 unsigned long *support);
188 phy_interface_t sfp_select_interface(struct sfp_bus *bus,
189 @@ -556,6 +557,12 @@ static inline int sfp_parse_port(struct
193 +static inline bool sfp_may_have_phy(struct sfp_bus *bus,
194 + const struct sfp_eeprom_id *id)
199 static inline void sfp_parse_support(struct sfp_bus *bus,
200 const struct sfp_eeprom_id *id,
201 unsigned long *support)