Skip to contentSkip to conversation

net: dsa: add support for phylink managed EEE

PATCH Superseded Russell King (Oracle) 4 participants 8 messages Feb 5, 2025 – Feb 7, 2025

Subsystems (7)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Russell King (Oracle)

author maintainer
#0 lore raw

cover net: dsa: add support for phylink managed EEE

Hi,

This series adds support for phylink managed EEE to DSA, and converts mt753x to make use of this feature.

Patch 1 implements a helper to indicate whether the MAC LPI operations are populated (suggested by Vladimir)

Patch 2 makes the necessary changes to the core code - we retain calling set_mac_eee(), but this method now becomes a way to merely validate the arguments when using phylink managed EEE rather than performing any configuration.

Patch 3 converts the mt7530 driver to use phylink managed EEE.

 drivers/net/dsa/mt7530.c  | 69 ++++++++++++++++++++++++++++++++---------------
 drivers/net/phy/phylink.c |  3 +--
 include/linux/phylink.h   | 12 +++++++++
 net/dsa/user.c            | 21 +++++++++------
 4 files changed, 74 insertions(+), 31 deletions(-)
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#1 lore raw

PATCH 1/3 net: phylink: provide phylink_mac_implements_lpi()

Provide a helper to determine whether the MAC operations structure implements the LPI operations, which will be used by both phylink and DSA.

---
 drivers/net/phy/phylink.c |  3 +--
 include/linux/phylink.h   | 12 ++++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/net/phy/phylink.c +1 -2
index 214b62fba991..6fbb5fd5b400 100644
@@ -1957,8 +1957,7 @@ struct phylink *phylink_create(struct phylink_config *config,
 		return ERR_PTR(-EINVAL);
 	}
 
-	pl->mac_supports_eee_ops = mac_ops->mac_disable_tx_lpi &&
-				   mac_ops->mac_enable_tx_lpi;
+	pl->mac_supports_eee_ops = phylink_mac_implements_lpi(mac_ops);
 	pl->mac_supports_eee = pl->mac_supports_eee_ops &&
 			       pl->config->lpi_capabilities &&
 			       !phy_interface_empty(pl->config->lpi_interfaces);
include/linux/phylink.h +12 -0
index 898b00451bbf..0de78673172d 100644
@@ -737,6 +737,18 @@ static inline int phylink_get_link_timer_ns(phy_interface_t interface)
 	}
 }
 
+/**
+ * phylink_mac_implements_lpi() - determine if MAC implements LPI ops
+ * @ops: phylink_mac_ops structure
+ *
+ * Returns true if the phylink MAC operations structure indicates that the
+ * LPI operations have been implemented, false otherwise.
+ */
+static inline bool phylink_mac_implements_lpi(const struct phylink_mac_ops *ops)
+{
+	return ops && ops->mac_disable_tx_lpi && ops->mac_enable_tx_lpi;
+}
+
 void phylink_mii_c22_pcs_decode_state(struct phylink_link_state *state,
 				      unsigned int neg_mode, u16 bmsr, u16 lpa);
 void phylink_mii_c22_pcs_get_state(struct mdio_device *pcs,
Signature · 1 line
2.30.2
#2 lore raw

PATCH 2/3 net: dsa: allow use of phylink managed EEE support

In reply to Russell King (Oracle)

In order to allow DSA drivers to use phylink managed EEE, changes are necessary to the DSA .set_eee() and .get_eee() methods. Where drivers make use of phylink managed EEE, these should just pass the method on to their phylink implementation without calling the DSA specific operations.

---
 net/dsa/user.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
net/dsa/user.c +13 -8
index 291ab1b4acc4..2e0a51c1b750 100644
@@ -1243,16 +1243,21 @@ static int dsa_user_set_eee(struct net_device *dev, struct ethtool_keee *e)
 	if (!ds->ops->support_eee || !ds->ops->support_eee(ds, dp->index))
 		return -EOPNOTSUPP;
 
-	/* Port's PHY and MAC both need to be EEE capable */
-	if (!dev->phydev)
-		return -ENODEV;
+	/* If the port is using phylink managed EEE, then get_mac_eee is
+	 * unnecessary.
+	 */
+	if (!phylink_mac_implements_lpi(ds->phylink_mac_ops)) {
+		/* Port's PHY and MAC both need to be EEE capable */
+		if (!dev->phydev)
+			return -ENODEV;
 
-	if (!ds->ops->set_mac_eee)
-		return -EOPNOTSUPP;
+		if (!ds->ops->set_mac_eee)
+			return -EOPNOTSUPP;
 
-	ret = ds->ops->set_mac_eee(ds, dp->index, e);
-	if (ret)
-		return ret;
+		ret = ds->ops->set_mac_eee(ds, dp->index, e);
+		if (ret)
+			return ret;
+	}
 
 	return phylink_ethtool_set_eee(dp->pl, e);
 }
Signature · 1 line
2.30.2
#3 lore raw

PATCH 3/3 net: dsa: mt7530: convert to phylink managed EEE

In reply to Russell King (Oracle)

Fixme: doesn't bit 25 and 26 also need to be set in the PMCR for PMCR_FORCE_EEE100 and PMCR_FORCE_EEE1G to take effect?

---
 drivers/net/dsa/mt7530.c | 69 ++++++++++++++++++++++++++++------------
 1 file changed, 48 insertions(+), 21 deletions(-)
drivers/net/dsa/mt7530.c +48 -21
index 1c83af805209..24191c4d5221 100644
@@ -2957,28 +2957,62 @@ static void mt753x_phylink_mac_link_up(struct phylink_config *config,
 			mcr |= PMCR_FORCE_RX_FC_EN;
 	}
 
-	if (mode == MLO_AN_PHY && phydev && phy_init_eee(phydev, false) >= 0) {
-		switch (speed) {
-		case SPEED_1000:
-		case SPEED_2500:
-			mcr |= PMCR_FORCE_EEE1G;
-			break;
-		case SPEED_100:
-			mcr |= PMCR_FORCE_EEE100;
-			break;
-		}
-	}
-
 	mt7530_set(priv, MT753X_PMCR_P(dp->index), mcr);
 }
 
+static void mt753x_phylink_mac_disable_tx_lpi(struct phylink_config *config)
+{
+	struct dsa_port *dp = dsa_phylink_to_port(config);
+	struct mt7530_priv *priv = dp->ds->priv;
+
+	mt7530_clear(priv, MT753X_PMCR_P(dp->index),
+		     PMCR_FORCE_EEE1G | PMCR_FORCE_EEE100);
+}
+
+static int mt753x_phylink_mac_enable_tx_lpi(struct phylink_config *config,
+					    u32 timer, bool tx_clock_stop)
+{
+	struct dsa_port *dp = dsa_phylink_to_port(config);
+	struct mt7530_priv *priv = dp->ds->priv;
+	u32 val;
+
+	/* If the timer is zero, then set LPI_MODE_EN, which allows the
+	 * system to enter LPI mode immediately rather than waiting for
+	 * the LPI threshold.
+	 */
+	if (!timer)
+		val = LPI_MODE_EN;
+	else if (FIELD_FIT(LPI_THRESH_MASK, timer))
+		val = FIELD_PREP(LPI_THRESH_MASK, timer);
+	else
+		val = LPI_THRESH_MASK;
+
+	mt7530_rmw(priv, MT753X_PMEEECR_P(dp->index),
+		   LPI_THRESH_MASK | LPI_MODE_EN, val);
+
+	mt7530_set(priv, MT753X_PMCR_P(dp->index),
+		   PMCR_FORCE_EEE1G | PMCR_FORCE_EEE100);
+
+	return 0;
+}
+
 static void mt753x_phylink_get_caps(struct dsa_switch *ds, int port,
 				    struct phylink_config *config)
 {
 	struct mt7530_priv *priv = ds->priv;
+	u32 eeecr;
 
 	config->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE;
 
+	config->lpi_capabilities = MAC_100FD | MAC_1000FD | MAC_2500FD;
+	config->lpi_timer_limit_us = FIELD_MAX(LPI_THRESH_MASK);
+
+	eeecr = mt7530_read(priv, MT753X_PMEEECR_P(port));
+	/* tx_lpi_timer should be in microseconds. The time units for
+	 * LPI threshold are unspecified.
+	 */
+	config->lpi_timer_default = FIELD_GET(LPI_THRESH_MASK, eeecr);
+
 	priv->info->mac_port_get_caps(ds, port, config);
 }
 
@@ -3088,18 +3122,9 @@ mt753x_setup(struct dsa_switch *ds)
 static int mt753x_set_mac_eee(struct dsa_switch *ds, int port,
 			      struct ethtool_keee *e)
 {
-	struct mt7530_priv *priv = ds->priv;
-	u32 set, mask = LPI_THRESH_MASK | LPI_MODE_EN;
-
 	if (e->tx_lpi_timer > 0xFFF)
 		return -EINVAL;
 
-	set = LPI_THRESH_SET(e->tx_lpi_timer);
-	if (!e->tx_lpi_enabled)
-		/* Force LPI Mode without a delay */
-		set |= LPI_MODE_EN;
-	mt7530_rmw(priv, MT753X_PMEEECR_P(port), mask, set);
-
 	return 0;
 }
 
@@ -3238,6 +3263,8 @@ static const struct phylink_mac_ops mt753x_phylink_mac_ops = {
 	.mac_config	= mt753x_phylink_mac_config,
 	.mac_link_down	= mt753x_phylink_mac_link_down,
 	.mac_link_up	= mt753x_phylink_mac_link_up,
+	.mac_disable_tx_lpi = mt753x_phylink_mac_disable_tx_lpi,
+	.mac_enable_tx_lpi = mt753x_phylink_mac_enable_tx_lpi,
 };
 
 const struct mt753x_info mt753x_table[] = {
Signature · 1 line
2.30.2
maintainer
#4 lore raw

Re: [PATCH net-next 3/3] net: dsa: mt7530: convert to phylink managed EEE

Hello Russell.

Quoted 2 lines · Russell King (Oracle)

Fixme: doesn't bit 25 and 26 also need to be set in the PMCR for PMCR_FORCE_EEE100 and PMCR_FORCE_EEE1G to take effect?

Yes, but only for MT7531 and the switch component of the MT7988 SoC. For MT7530 and the switch component of the AN7581 SoC, bit 15 (MT7530_FORCE_MODE) must be set. The MT753X DSA subdriver sets these bits accordingly at the setup function that pertains to the specific switch model.

Chester A.

author maintainer
#5 lore raw

Re: [PATCH net-next 3/3] net: dsa: mt7530: convert to phylink managed EEE

Quoted 11 lines · Chester A. Unal

Hello Russell.

Quoted 2 lines · Russell King (Oracle)

Fixme: doesn't bit 25 and 26 also need to be set in the PMCR for PMCR_FORCE_EEE100 and PMCR_FORCE_EEE1G to take effect?

Yes, but only for MT7531 and the switch component of the MT7988 SoC. For MT7530 and the switch component of the AN7581 SoC, bit 15 (MT7530_FORCE_MODE) must be set. The MT753X DSA subdriver sets these bits accordingly at the setup function that pertains to the specific switch model.

I'll remove the comment in the commit message. I also note from patchwork that I need to remove lpi_timer_limit_us... so v2 will be posted in the next day or so.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#6 lore raw

Re: [PATCH net-next 3/3] net: dsa: mt7530: convert to phylink managed EEE

In reply to Russell King (Oracle)
kernel test robot noticed the following build errors:

Hi Russell,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Russell-King-Oracle/net-phylink-provide-phylink_mac_implements_lpi/20250206-032648
base:   net-next/main
patch link:    https://lore.kernel.org/r/E1tfh3R-003aRS-3M%40rmk-PC.armlinux.org.uk
patch subject: [PATCH net-next 3/3] net: dsa: mt7530: convert to phylink managed EEE
config: i386-buildonly-randconfig-002-20250207 (https://download.01.org/0day-ci/archive/20250207/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250207/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/net/dsa/mt7530.c: In function 'mt753x_phylink_get_caps':

>> drivers/net/dsa/mt7530.c:3008:15: error: 'struct phylink_config' has no member named 'lpi_timer_limit_us'
    3008 |         config->lpi_timer_limit_us = FIELD_MAX(LPI_THRESH_MASK);
         |               ^~

vim +3008 drivers/net/dsa/mt7530.c

2998
2999 static void mt753x_phylink_get_caps(struct dsa_switch *ds, int port,
3000 struct phylink_config *config)
3001 {
3002 struct mt7530_priv *priv = ds->priv;
3003 u32 eeecr;
3004
3005 config->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE;
3006
3007 config->lpi_capabilities = MAC_100FD | MAC_1000FD | MAC_2500FD;

> 3008		config->lpi_timer_limit_us = FIELD_MAX(LPI_THRESH_MASK);

3009
3010 eeecr = mt7530_read(priv, MT753X_PMEEECR_P(port));
3011 /* tx_lpi_timer should be in microseconds. The time units for
3012 * LPI threshold are unspecified.
3013 */
3014 config->lpi_timer_default = FIELD_GET(LPI_THRESH_MASK, eeecr);
3015
3016 priv->info->mac_port_get_caps(ds, port, config);
3017 }
3018

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#7 lore raw

Re: [PATCH net-next 3/3] net: dsa: mt7530: convert to phylink managed EEE

In reply to Russell King (Oracle)
kernel test robot noticed the following build errors:

Hi Russell,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Russell-King-Oracle/net-phylink-provide-phylink_mac_implements_lpi/20250206-032648
base:   net-next/main
patch link:    https://lore.kernel.org/r/E1tfh3R-003aRS-3M%40rmk-PC.armlinux.org.uk
patch subject: [PATCH net-next 3/3] net: dsa: mt7530: convert to phylink managed EEE
config: x86_64-randconfig-072-20250207 (https://download.01.org/0day-ci/archive/20250207/[email protected]/config)
compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250207/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/net/dsa/mt7530.c:3008:10: error: no member named 'lpi_timer_limit_us' in 'struct phylink_config'
    3008 |         config->lpi_timer_limit_us = FIELD_MAX(LPI_THRESH_MASK);
         |         ~~~~~~  ^

1 error generated.

vim +3008 drivers/net/dsa/mt7530.c

2998
2999 static void mt753x_phylink_get_caps(struct dsa_switch *ds, int port,
3000 struct phylink_config *config)
3001 {
3002 struct mt7530_priv *priv = ds->priv;
3003 u32 eeecr;
3004
3005 config->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE;
3006
3007 config->lpi_capabilities = MAC_100FD | MAC_1000FD | MAC_2500FD;

> 3008		config->lpi_timer_limit_us = FIELD_MAX(LPI_THRESH_MASK);

3009
3010 eeecr = mt7530_read(priv, MT753X_PMEEECR_P(port));
3011 /* tx_lpi_timer should be in microseconds. The time units for
3012 * LPI threshold are unspecified.
3013 */
3014 config->lpi_timer_default = FIELD_GET(LPI_THRESH_MASK, eeecr);
3015
3016 priv->info->mac_port_get_caps(ds, port, config);
3017 }
3018

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki