netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 net-next 0/9] net: ethernet: Rework EEE
@ 2023-06-18 18:41 Andrew Lunn
  2023-06-18 18:41 ` [PATCH v4 net-next 1/9] net: phy-c45: Fix genphy_c45_ethtool_set_eee description Andrew Lunn
                   ` (8 more replies)
  0 siblings, 9 replies; 20+ messages in thread
From: Andrew Lunn @ 2023-06-18 18:41 UTC (permalink / raw)
  To: netdev
  Cc: Russell King, Heiner Kallweit, Florian Fainelli, Oleksij Rempel,
	Andrew Lunn

Most MAC drivers get EEE wrong. The API to the PHY is not very
obvious, which is probably why. Rework the API, pushing most of the
EEE handling into phylib core, leaving the MAC drivers to just
enable/disable support for EEE in there change_link call back.

MAC drivers are now expect to indicate to phylib if they support
EEE. This will allow future patches to configure the PHY to advertise
no EEE link modes when EEE is not supported. The information could
also be used to enable SmartEEE if the PHY supports it.

With these changes, the uAPI configuration eee_enable becomes a global
on/off. tx-lpi must also be enabled before EEE is enabled. This fits
the discussion here:

https://lore.kernel.org/netdev/af880ce8-a7b8-138e-1ab9-8c89e662eecf@gmail.com/T/

This patchset puts in place all the infrastructure, and converts one
MAC driver to the new API. Following patchsets will convert other MAC
drivers, extend support into phylink, and when all MAC drivers are
converted to the new scheme, clean up some unneeded code.

v4
--

Only convert one MAC driver
Drop all phylink code
Conform to the uAPI discision.

v3
--
Rework phylink code to add a new callback.
Rework function to indicate clock should be stopped during LPI

Andrew Lunn (8):
  net: phy-c45: Fix genphy_c45_ethtool_set_eee description
  net: phy: Add phydev->enable_tx_lpi to simplify adjust link callbacks
  net: phy: Add helper to set EEE Clock stop enable bit
  net: phy: Keep track of EEE configuration
  net: phy: Immediately call adjust_link if only tx_lpi_enabled changes
  net: phy: Add phy_support_eee() indicating MAC support EEE
  net: fec: Move fec_enet_eee_mode_set() and helper earlier
  net: fec: Fixup EEE

Russell King (1):
  net: add helpers for EEE configuration

 drivers/net/ethernet/freescale/fec_main.c | 88 ++++++++++-------------
 drivers/net/phy/phy-c45.c                 | 20 ++++--
 drivers/net/phy/phy.c                     | 53 +++++++++++++-
 drivers/net/phy/phy_device.c              | 18 +++++
 include/linux/phy.h                       |  9 ++-
 include/net/eee.h                         | 38 ++++++++++
 6 files changed, 165 insertions(+), 61 deletions(-)
 create mode 100644 include/net/eee.h

-- 
2.40.1


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

* [PATCH v4 net-next 1/9] net: phy-c45: Fix genphy_c45_ethtool_set_eee description
  2023-06-18 18:41 [PATCH v4 net-next 0/9] net: ethernet: Rework EEE Andrew Lunn
@ 2023-06-18 18:41 ` Andrew Lunn
  2023-06-18 19:18   ` Russell King (Oracle)
  2023-06-18 18:41 ` [PATCH v4 net-next 2/9] net: add helpers for EEE configuration Andrew Lunn
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Andrew Lunn @ 2023-06-18 18:41 UTC (permalink / raw)
  To: netdev
  Cc: Russell King, Heiner Kallweit, Florian Fainelli, Oleksij Rempel,
	Andrew Lunn

The text has been cut/paste from  genphy_c45_ethtool_get_eee but not
changed to reflect it performs set.

Additionally, extend the comment. This function implements the logic
that eee_enabled has global control over EEE. When eee_enabled is
false, no link modes will be advertised, and as a result, the MAC
should not transmit LPI.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 drivers/net/phy/phy-c45.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c
index fee514b96ab1..d1d7cf34ac0b 100644
--- a/drivers/net/phy/phy-c45.c
+++ b/drivers/net/phy/phy-c45.c
@@ -1425,12 +1425,15 @@ int genphy_c45_ethtool_get_eee(struct phy_device *phydev,
 EXPORT_SYMBOL(genphy_c45_ethtool_get_eee);
 
 /**
- * genphy_c45_ethtool_set_eee - get EEE supported and status
+ * genphy_c45_ethtool_set_eee - set EEE supported and status
  * @phydev: target phy_device struct
  * @data: ethtool_eee data
  *
- * Description: it reportes the Supported/Advertisement/LP Advertisement
- * capabilities.
+ * Description: it set the Supported/Advertisement/LP Advertisement
+ * capabilities. If eee_enabled is false, no links modes are
+ * advertised, but the previously advertised link modes are
+ * retained. This allows EEE to be enabled/disabled in a none
+ * destructive way.
  */
 int genphy_c45_ethtool_set_eee(struct phy_device *phydev,
 			       struct ethtool_eee *data)
-- 
2.40.1


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

* [PATCH v4 net-next 2/9] net: add helpers for EEE configuration
  2023-06-18 18:41 [PATCH v4 net-next 0/9] net: ethernet: Rework EEE Andrew Lunn
  2023-06-18 18:41 ` [PATCH v4 net-next 1/9] net: phy-c45: Fix genphy_c45_ethtool_set_eee description Andrew Lunn
@ 2023-06-18 18:41 ` Andrew Lunn
  2023-06-19 15:26   ` Florian Fainelli
  2023-06-18 18:41 ` [PATCH v4 net-next 3/9] net: phy: Add phydev->enable_tx_lpi to simplify adjust link callbacks Andrew Lunn
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Andrew Lunn @ 2023-06-18 18:41 UTC (permalink / raw)
  To: netdev
  Cc: Russell King, Heiner Kallweit, Florian Fainelli, Oleksij Rempel,
	Andrew Lunn

From: Russell King <rmk+kernel@armlinux.org.uk>

Add helpers that phylib and phylink can use to manage EEE configuration
and determine whether the MAC should be permitted to use LPI based on
that configuration.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 include/net/eee.h | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 include/net/eee.h

diff --git a/include/net/eee.h b/include/net/eee.h
new file mode 100644
index 000000000000..d353b79ae79f
--- /dev/null
+++ b/include/net/eee.h
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _EEE_H
+#define _EEE_H
+
+#include <linux/types.h>
+
+struct eee_config {
+	u32 tx_lpi_timer;
+	bool tx_lpi_enabled;
+	bool eee_enabled;
+};
+
+static inline bool eeecfg_mac_can_tx_lpi(const struct eee_config *eeecfg)
+{
+	/* eee_enabled is the master on/off */
+	if (!eeecfg->eee_enabled || !eeecfg->tx_lpi_enabled)
+		return false;
+
+	return true;
+}
+
+static inline void eeecfg_to_eee(const struct eee_config *eeecfg,
+			  struct ethtool_eee *eee)
+{
+	eee->tx_lpi_timer = eeecfg->tx_lpi_timer;
+	eee->tx_lpi_enabled = eeecfg->tx_lpi_enabled;
+	eee->eee_enabled = eeecfg->eee_enabled;
+}
+
+static inline void eee_to_eeecfg(const struct ethtool_eee *eee,
+				 struct eee_config *eeecfg)
+{
+	eeecfg->tx_lpi_timer = eee->tx_lpi_timer;
+	eeecfg->tx_lpi_enabled = eee->tx_lpi_enabled;
+	eeecfg->eee_enabled = eee->eee_enabled;
+}
+
+#endif
-- 
2.40.1


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

* [PATCH v4 net-next 3/9] net: phy: Add phydev->enable_tx_lpi to simplify adjust link callbacks
  2023-06-18 18:41 [PATCH v4 net-next 0/9] net: ethernet: Rework EEE Andrew Lunn
  2023-06-18 18:41 ` [PATCH v4 net-next 1/9] net: phy-c45: Fix genphy_c45_ethtool_set_eee description Andrew Lunn
  2023-06-18 18:41 ` [PATCH v4 net-next 2/9] net: add helpers for EEE configuration Andrew Lunn
@ 2023-06-18 18:41 ` Andrew Lunn
  2023-06-18 18:41 ` [PATCH v4 net-next 4/9] net: phy: Add helper to set EEE Clock stop enable bit Andrew Lunn
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Andrew Lunn @ 2023-06-18 18:41 UTC (permalink / raw)
  To: netdev
  Cc: Russell King, Heiner Kallweit, Florian Fainelli, Oleksij Rempel,
	Andrew Lunn, Florian Fainelli

MAC drivers which support EEE need to know the results of the EEE
auto-neg in order to program the hardware to perform EEE or not.  The
oddly named phy_init_eee() can be used to determine this, it returns 0
if EEE should be used, or a negative error code,
e.g. -EOPPROTONOTSUPPORT if the PHY does not support EEE or negotiate
resulted in it not being used.

However, many MAC drivers get this wrong. Add phydev->enable_tx_lpi
which indicates the result of the autoneg for EEE, including if EEE is
administratively disabled with ethtool. The MAC driver can then access
this in the same way as link speed and duplex in the adjust link
callback. If enable_tx_lpi is true, the MAC should send low power
indications and does not need to consider anything else with respect
to EEE.

Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
v2 Check for errors from genphy_c45_eee_is_active
v5: Rename to enable_tx_lpi to fit better with phylink changes
---
 drivers/net/phy/phy.c | 7 +++++++
 include/linux/phy.h   | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index bdf00b2b2c1d..add94626b604 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -929,9 +929,16 @@ static int phy_check_link_status(struct phy_device *phydev)
 	if (phydev->link && phydev->state != PHY_RUNNING) {
 		phy_check_downshift(phydev);
 		phydev->state = PHY_RUNNING;
+		err = genphy_c45_eee_is_active(phydev,
+					       NULL, NULL, NULL);
+		if (err < 0)
+			phydev->enable_tx_lpi = false;
+		else
+			phydev->enable_tx_lpi = err;
 		phy_link_up(phydev);
 	} else if (!phydev->link && phydev->state != PHY_NOLINK) {
 		phydev->state = PHY_NOLINK;
+		phydev->enable_tx_lpi = false;
 		phy_link_down(phydev);
 	}
 
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 11c1e91563d4..851421248212 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -584,6 +584,7 @@ struct macsec_ops;
  * @supported_eee: supported PHY EEE linkmodes
  * @advertising_eee: Currently advertised EEE linkmodes
  * @eee_enabled: Flag indicating whether the EEE feature is enabled
+ * @enable_tx_lpi: When True, MAC should transmit LPI to PHY
  * @lp_advertising: Current link partner advertised linkmodes
  * @host_interfaces: PHY interface modes supported by host
  * @eee_broken_modes: Energy efficient ethernet modes which should be prohibited
@@ -700,6 +701,7 @@ struct phy_device {
 
 	/* Energy efficient ethernet modes which should be prohibited */
 	u32 eee_broken_modes;
+	bool enable_tx_lpi;
 
 #ifdef CONFIG_LED_TRIGGER_PHY
 	struct phy_led_trigger *phy_led_triggers;
-- 
2.40.1


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

* [PATCH v4 net-next 4/9] net: phy: Add helper to set EEE Clock stop enable bit
  2023-06-18 18:41 [PATCH v4 net-next 0/9] net: ethernet: Rework EEE Andrew Lunn
                   ` (2 preceding siblings ...)
  2023-06-18 18:41 ` [PATCH v4 net-next 3/9] net: phy: Add phydev->enable_tx_lpi to simplify adjust link callbacks Andrew Lunn
@ 2023-06-18 18:41 ` Andrew Lunn
  2023-06-18 18:41 ` [PATCH v4 net-next 5/9] net: phy: Keep track of EEE configuration Andrew Lunn
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Andrew Lunn @ 2023-06-18 18:41 UTC (permalink / raw)
  To: netdev
  Cc: Russell King, Heiner Kallweit, Florian Fainelli, Oleksij Rempel,
	Andrew Lunn

The MAC driver can request that the PHY stops the clock during EEE
LPI. This has normally been does as part of phy_init_eee(), however
that function is overly complex and often wrongly used. Add a
standalone helper, to aid removing phy_init_eee().

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
v2: Add missing EXPORT_SYMBOL_GPL
---
 drivers/net/phy/phy.c | 20 ++++++++++++++++++++
 include/linux/phy.h   |  1 +
 2 files changed, 21 insertions(+)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index add94626b604..629499e5aff0 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -1506,6 +1506,26 @@ void phy_mac_interrupt(struct phy_device *phydev)
 }
 EXPORT_SYMBOL(phy_mac_interrupt);
 
+/**
+ * phy_eee_clk_stop_enable - Clock should stop during LIP
+ * @phydev: target phy_device struct
+ *
+ * Description: Program the MMD register 3.0 setting the "Clock stop enable"
+ * bit.
+ */
+int phy_eee_clk_stop_enable(struct phy_device *phydev)
+{
+	int ret;
+
+	mutex_lock(&phydev->lock);
+	ret = phy_set_bits_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1,
+			       MDIO_PCS_CTRL1_CLKSTOP_EN);
+	mutex_unlock(&phydev->lock);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(phy_eee_clk_stop_enable);
+
 /**
  * phy_init_eee - init and check the EEE feature
  * @phydev: target phy_device struct
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 851421248212..66f69d512f45 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -1925,6 +1925,7 @@ int phy_unregister_fixup_for_id(const char *bus_id);
 int phy_unregister_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask);
 
 int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable);
+int phy_eee_clk_stop_enable(struct phy_device *phydev);
 int phy_get_eee_err(struct phy_device *phydev);
 int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data);
 int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data);
-- 
2.40.1


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

* [PATCH v4 net-next 5/9] net: phy: Keep track of EEE configuration
  2023-06-18 18:41 [PATCH v4 net-next 0/9] net: ethernet: Rework EEE Andrew Lunn
                   ` (3 preceding siblings ...)
  2023-06-18 18:41 ` [PATCH v4 net-next 4/9] net: phy: Add helper to set EEE Clock stop enable bit Andrew Lunn
@ 2023-06-18 18:41 ` Andrew Lunn
  2023-06-18 19:20   ` Russell King (Oracle)
                     ` (2 more replies)
  2023-06-18 18:41 ` [PATCH v4 net-next 6/9] net: phy: Immediately call adjust_link if only tx_lpi_enabled changes Andrew Lunn
                   ` (3 subsequent siblings)
  8 siblings, 3 replies; 20+ messages in thread
From: Andrew Lunn @ 2023-06-18 18:41 UTC (permalink / raw)
  To: netdev
  Cc: Russell King, Heiner Kallweit, Florian Fainelli, Oleksij Rempel,
	Andrew Lunn

Have phylib keep track of the EEE configuration. This simplifies the
MAC drivers, in that they don't need to store it.

Future patches to phylib will also make use of this information to
further simplify the MAC drivers.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 drivers/net/phy/phy.c | 5 ++++-
 include/linux/phy.h   | 3 +++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 629499e5aff0..48150d5626d8 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -1588,7 +1588,7 @@ EXPORT_SYMBOL(phy_get_eee_err);
  * @data: ethtool_eee data
  *
  * Description: it reportes the Supported/Advertisement/LP Advertisement
- * capabilities.
+ * capabilities, etc.
  */
 int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data)
 {
@@ -1599,6 +1599,7 @@ int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data)
 
 	mutex_lock(&phydev->lock);
 	ret = genphy_c45_ethtool_get_eee(phydev, data);
+	eeecfg_to_eee(&phydev->eee_cfg, data);
 	mutex_unlock(&phydev->lock);
 
 	return ret;
@@ -1621,6 +1622,8 @@ int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data)
 
 	mutex_lock(&phydev->lock);
 	ret = genphy_c45_ethtool_set_eee(phydev, data);
+	if (!ret)
+		eee_to_eeecfg(data, &phydev->eee_cfg);
 	mutex_unlock(&phydev->lock);
 
 	return ret;
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 66f69d512f45..473ddf62bee9 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -30,6 +30,7 @@
 #include <linux/refcount.h>
 
 #include <linux/atomic.h>
+#include <net/eee.h>
 
 #define PHY_DEFAULT_FEATURES	(SUPPORTED_Autoneg | \
 				 SUPPORTED_TP | \
@@ -585,6 +586,7 @@ struct macsec_ops;
  * @advertising_eee: Currently advertised EEE linkmodes
  * @eee_enabled: Flag indicating whether the EEE feature is enabled
  * @enable_tx_lpi: When True, MAC should transmit LPI to PHY
+ * eee_cfg: User configuration of EEE
  * @lp_advertising: Current link partner advertised linkmodes
  * @host_interfaces: PHY interface modes supported by host
  * @eee_broken_modes: Energy efficient ethernet modes which should be prohibited
@@ -702,6 +704,7 @@ struct phy_device {
 	/* Energy efficient ethernet modes which should be prohibited */
 	u32 eee_broken_modes;
 	bool enable_tx_lpi;
+	struct eee_config eee_cfg;
 
 #ifdef CONFIG_LED_TRIGGER_PHY
 	struct phy_led_trigger *phy_led_triggers;
-- 
2.40.1


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

* [PATCH v4 net-next 6/9] net: phy: Immediately call adjust_link if only tx_lpi_enabled changes
  2023-06-18 18:41 [PATCH v4 net-next 0/9] net: ethernet: Rework EEE Andrew Lunn
                   ` (4 preceding siblings ...)
  2023-06-18 18:41 ` [PATCH v4 net-next 5/9] net: phy: Keep track of EEE configuration Andrew Lunn
@ 2023-06-18 18:41 ` Andrew Lunn
  2023-06-18 18:41 ` [PATCH v4 net-next 7/9] net: phy: Add phy_support_eee() indicating MAC support EEE Andrew Lunn
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Andrew Lunn @ 2023-06-18 18:41 UTC (permalink / raw)
  To: netdev
  Cc: Russell King, Heiner Kallweit, Florian Fainelli, Oleksij Rempel,
	Andrew Lunn

The MAC driver changes its EEE hardware configuration in its
adjust_link callback. This is called when auto-neg
completes. Disabling EEE via eee_enabled false will trigger an
autoneg, and as a result the adjust_link callback will be called with
phydev->enable_tx_lpi set to false. Similarly, eee_enabled set to true
and with a change of advertised link modes will result in a new
autoneg, and a call the adjust_link call.

If set_eee is called with only a change to tx_lpi_enabled which does
not trigger an auto-neg, it is necessary to call the adjust_link
callback so that the MAC is reconfigured to take this change into
account.

When setting phydev->enable_tx_lpi, take both eee_enabled and
tx_lpi_enabled into account, so the MAC drivers just needs to act on
phydev->enable_tx_lpi and not the whole EEE configuration.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 drivers/net/phy/phy-c45.c | 11 ++++++++---
 drivers/net/phy/phy.c     | 25 ++++++++++++++++++++++---
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c
index d1d7cf34ac0b..7ddae1df9254 100644
--- a/drivers/net/phy/phy-c45.c
+++ b/drivers/net/phy/phy-c45.c
@@ -1434,6 +1434,8 @@ EXPORT_SYMBOL(genphy_c45_ethtool_get_eee);
  * advertised, but the previously advertised link modes are
  * retained. This allows EEE to be enabled/disabled in a none
  * destructive way.
+ * Returns either error code, 0 if there was no change, or positive if
+ * there was a change which triggered auto-neg.
  */
 int genphy_c45_ethtool_set_eee(struct phy_device *phydev,
 			       struct ethtool_eee *data)
@@ -1467,9 +1469,12 @@ int genphy_c45_ethtool_set_eee(struct phy_device *phydev,
 	ret = genphy_c45_an_config_eee_aneg(phydev);
 	if (ret < 0)
 		return ret;
-	if (ret > 0)
-		return phy_restart_aneg(phydev);
-
+	if (ret > 0) {
+		ret = phy_restart_aneg(phydev);
+		if (ret < 0)
+			return ret;
+		return 1;
+	}
 	return 0;
 }
 EXPORT_SYMBOL(genphy_c45_ethtool_set_eee);
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 48150d5626d8..830bca772f68 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -934,7 +934,8 @@ static int phy_check_link_status(struct phy_device *phydev)
 		if (err < 0)
 			phydev->enable_tx_lpi = false;
 		else
-			phydev->enable_tx_lpi = err;
+			phydev->enable_tx_lpi = (err & phydev->eee_cfg.tx_lpi_enabled);
+
 		phy_link_up(phydev);
 	} else if (!phydev->link && phydev->state != PHY_NOLINK) {
 		phydev->state = PHY_NOLINK;
@@ -1606,6 +1607,21 @@ int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data)
 }
 EXPORT_SYMBOL(phy_ethtool_get_eee);
 
+/* auto-neg not triggered, directly inform the MAC if something
+ * changed'
+ */
+static void phy_ethtool_set_eee_noneg(struct phy_device *phydev,
+				      struct ethtool_eee *data)
+{
+	if (phydev->eee_cfg.tx_lpi_enabled !=
+	    data->tx_lpi_enabled) {
+		eee_to_eeecfg(data, &phydev->eee_cfg);
+		phydev->enable_tx_lpi = eeecfg_mac_can_tx_lpi(&phydev->eee_cfg);
+		if (phydev->link)
+			phy_link_up(phydev);
+	}
+}
+
 /**
  * phy_ethtool_set_eee - set EEE supported and status
  * @phydev: target phy_device struct
@@ -1622,11 +1638,14 @@ int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data)
 
 	mutex_lock(&phydev->lock);
 	ret = genphy_c45_ethtool_set_eee(phydev, data);
-	if (!ret)
+	if (ret >= 0) {
+		if (ret == 0)
+			phy_ethtool_set_eee_noneg(phydev, data);
 		eee_to_eeecfg(data, &phydev->eee_cfg);
+	}
 	mutex_unlock(&phydev->lock);
 
-	return ret;
+	return (ret < 0 ? ret : 0);
 }
 EXPORT_SYMBOL(phy_ethtool_set_eee);
 
-- 
2.40.1


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

* [PATCH v4 net-next 7/9] net: phy: Add phy_support_eee() indicating MAC support EEE
  2023-06-18 18:41 [PATCH v4 net-next 0/9] net: ethernet: Rework EEE Andrew Lunn
                   ` (5 preceding siblings ...)
  2023-06-18 18:41 ` [PATCH v4 net-next 6/9] net: phy: Immediately call adjust_link if only tx_lpi_enabled changes Andrew Lunn
@ 2023-06-18 18:41 ` Andrew Lunn
  2023-06-19 15:21   ` Florian Fainelli
  2023-06-18 18:41 ` [PATCH v4 net-next 8/9] net: fec: Move fec_enet_eee_mode_set() and helper earlier Andrew Lunn
  2023-06-18 18:41 ` [PATCH v4 net-next 9/9] net: fec: Fixup EEE Andrew Lunn
  8 siblings, 1 reply; 20+ messages in thread
From: Andrew Lunn @ 2023-06-18 18:41 UTC (permalink / raw)
  To: netdev
  Cc: Russell King, Heiner Kallweit, Florian Fainelli, Oleksij Rempel,
	Andrew Lunn

In order for EEE to operate, both the MAC and the PHY need to support
it, similar to how pause works. Copy the pause concept and add the
call phy_support_eee() which the MAC makes after connecting the PHY to
indicate it supports EEE. phylib will then advertise EEE when auto-neg
is performed.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 drivers/net/phy/phy_device.c | 18 ++++++++++++++++++
 include/linux/phy.h          |  3 ++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 2cad9cc3f6b8..ae2ebe1df15c 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -2762,6 +2762,24 @@ void phy_advertise_supported(struct phy_device *phydev)
 }
 EXPORT_SYMBOL(phy_advertise_supported);
 
+/**
+ * phy_support_eee - Enable support of EEE
+ * @phydev: target phy_device struct
+ *
+ * Description: Called by the MAC to indicate is supports Energy
+ * Efficient Ethernet. This should be called before phy_start() in
+ * order that EEE is negotiated when the link comes up as part of
+ * phy_start(). EEE is enabled by default when the hardware supports
+ * it.
+ */
+void phy_support_eee(struct phy_device *phydev)
+{
+	linkmode_copy(phydev->advertising_eee, phydev->supported_eee);
+	phydev->eee_cfg.tx_lpi_enabled = true;
+	phydev->eee_cfg.eee_enabled = true;
+}
+EXPORT_SYMBOL(phy_support_eee);
+
 /**
  * phy_support_sym_pause - Enable support of symmetrical pause
  * @phydev: target phy_device struct
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 473ddf62bee9..29ae45d37011 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -693,7 +693,7 @@ struct phy_device {
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
 	/* used with phy_speed_down */
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(adv_old);
-	/* used for eee validation */
+	/* used for eee validation and configuration*/
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(supported_eee);
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(advertising_eee);
 	bool eee_enabled;
@@ -1903,6 +1903,7 @@ void phy_remove_link_mode(struct phy_device *phydev, u32 link_mode);
 void phy_advertise_supported(struct phy_device *phydev);
 void phy_support_sym_pause(struct phy_device *phydev);
 void phy_support_asym_pause(struct phy_device *phydev);
+void phy_support_eee(struct phy_device *phydev);
 void phy_set_sym_pause(struct phy_device *phydev, bool rx, bool tx,
 		       bool autoneg);
 void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx);
-- 
2.40.1


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

* [PATCH v4 net-next 8/9] net: fec: Move fec_enet_eee_mode_set() and helper earlier
  2023-06-18 18:41 [PATCH v4 net-next 0/9] net: ethernet: Rework EEE Andrew Lunn
                   ` (6 preceding siblings ...)
  2023-06-18 18:41 ` [PATCH v4 net-next 7/9] net: phy: Add phy_support_eee() indicating MAC support EEE Andrew Lunn
@ 2023-06-18 18:41 ` Andrew Lunn
  2023-06-19 15:22   ` Florian Fainelli
  2023-06-18 18:41 ` [PATCH v4 net-next 9/9] net: fec: Fixup EEE Andrew Lunn
  8 siblings, 1 reply; 20+ messages in thread
From: Andrew Lunn @ 2023-06-18 18:41 UTC (permalink / raw)
  To: netdev
  Cc: Russell King, Heiner Kallweit, Florian Fainelli, Oleksij Rempel,
	Andrew Lunn

FEC is about to get its EEE code re-written. To allow this, move
fec_enet_eee_mode_set() before fec_enet_adjust_link() which will
need to call it.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 drivers/net/ethernet/freescale/fec_main.c | 79 ++++++++++++-----------
 1 file changed, 40 insertions(+), 39 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 4d37a811ae15..69c62e49c7e6 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -1904,6 +1904,46 @@ static int fec_get_mac(struct net_device *ndev)
 /*
  * Phy section
  */
+
+/* LPI Sleep Ts count base on tx clk (clk_ref).
+ * The lpi sleep cnt value = X us / (cycle_ns).
+ */
+static int fec_enet_us_to_tx_cycle(struct net_device *ndev, int us)
+{
+	struct fec_enet_private *fep = netdev_priv(ndev);
+
+	return us * (fep->clk_ref_rate / 1000) / 1000;
+}
+
+static int fec_enet_eee_mode_set(struct net_device *ndev, bool enable)
+{
+	struct fec_enet_private *fep = netdev_priv(ndev);
+	struct ethtool_eee *p = &fep->eee;
+	unsigned int sleep_cycle, wake_cycle;
+	int ret = 0;
+
+	if (enable) {
+		ret = phy_init_eee(ndev->phydev, false);
+		if (ret)
+			return ret;
+
+		sleep_cycle = fec_enet_us_to_tx_cycle(ndev, p->tx_lpi_timer);
+		wake_cycle = sleep_cycle;
+	} else {
+		sleep_cycle = 0;
+		wake_cycle = 0;
+	}
+
+	p->tx_lpi_enabled = enable;
+	p->eee_enabled = enable;
+	p->eee_active = enable;
+
+	writel(sleep_cycle, fep->hwp + FEC_LPI_SLEEP);
+	writel(wake_cycle, fep->hwp + FEC_LPI_WAKE);
+
+	return 0;
+}
+
 static void fec_enet_adjust_link(struct net_device *ndev)
 {
 	struct fec_enet_private *fep = netdev_priv(ndev);
@@ -3044,45 +3084,6 @@ static int fec_enet_set_tunable(struct net_device *netdev,
 	return ret;
 }
 
-/* LPI Sleep Ts count base on tx clk (clk_ref).
- * The lpi sleep cnt value = X us / (cycle_ns).
- */
-static int fec_enet_us_to_tx_cycle(struct net_device *ndev, int us)
-{
-	struct fec_enet_private *fep = netdev_priv(ndev);
-
-	return us * (fep->clk_ref_rate / 1000) / 1000;
-}
-
-static int fec_enet_eee_mode_set(struct net_device *ndev, bool enable)
-{
-	struct fec_enet_private *fep = netdev_priv(ndev);
-	struct ethtool_eee *p = &fep->eee;
-	unsigned int sleep_cycle, wake_cycle;
-	int ret = 0;
-
-	if (enable) {
-		ret = phy_init_eee(ndev->phydev, false);
-		if (ret)
-			return ret;
-
-		sleep_cycle = fec_enet_us_to_tx_cycle(ndev, p->tx_lpi_timer);
-		wake_cycle = sleep_cycle;
-	} else {
-		sleep_cycle = 0;
-		wake_cycle = 0;
-	}
-
-	p->tx_lpi_enabled = enable;
-	p->eee_enabled = enable;
-	p->eee_active = enable;
-
-	writel(sleep_cycle, fep->hwp + FEC_LPI_SLEEP);
-	writel(wake_cycle, fep->hwp + FEC_LPI_WAKE);
-
-	return 0;
-}
-
 static int
 fec_enet_get_eee(struct net_device *ndev, struct ethtool_eee *edata)
 {
-- 
2.40.1


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

* [PATCH v4 net-next 9/9] net: fec: Fixup EEE
  2023-06-18 18:41 [PATCH v4 net-next 0/9] net: ethernet: Rework EEE Andrew Lunn
                   ` (7 preceding siblings ...)
  2023-06-18 18:41 ` [PATCH v4 net-next 8/9] net: fec: Move fec_enet_eee_mode_set() and helper earlier Andrew Lunn
@ 2023-06-18 18:41 ` Andrew Lunn
  8 siblings, 0 replies; 20+ messages in thread
From: Andrew Lunn @ 2023-06-18 18:41 UTC (permalink / raw)
  To: netdev
  Cc: Russell King, Heiner Kallweit, Florian Fainelli, Oleksij Rempel,
	Andrew Lunn

The enabling/disabling of EEE in the MAC should happen as a result of
auto negotiation. So move the enable/disable into
fec_enet_adjust_link() which gets called by phylib when there is a
change in link status.

fec_enet_set_eee() now just stores away the LPI timer value.
Everything else is passed to phylib, so it can correctly setup the
PHY.

fec_enet_get_eee() relies on phylib doing most of the work,
the MAC driver just adds the LPI timer value.

Call phy_support_eee() if the quirk is present to indicate the MAC
actually supports EEE.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
v2: Only call fec_enet_eee_mode_set for those that support EEE
---
 drivers/net/ethernet/freescale/fec_main.c | 27 +++++------------------
 1 file changed, 5 insertions(+), 22 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 69c62e49c7e6..7b83a4a544cc 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -1920,13 +1920,8 @@ static int fec_enet_eee_mode_set(struct net_device *ndev, bool enable)
 	struct fec_enet_private *fep = netdev_priv(ndev);
 	struct ethtool_eee *p = &fep->eee;
 	unsigned int sleep_cycle, wake_cycle;
-	int ret = 0;
 
 	if (enable) {
-		ret = phy_init_eee(ndev->phydev, false);
-		if (ret)
-			return ret;
-
 		sleep_cycle = fec_enet_us_to_tx_cycle(ndev, p->tx_lpi_timer);
 		wake_cycle = sleep_cycle;
 	} else {
@@ -1934,10 +1929,6 @@ static int fec_enet_eee_mode_set(struct net_device *ndev, bool enable)
 		wake_cycle = 0;
 	}
 
-	p->tx_lpi_enabled = enable;
-	p->eee_enabled = enable;
-	p->eee_active = enable;
-
 	writel(sleep_cycle, fep->hwp + FEC_LPI_SLEEP);
 	writel(wake_cycle, fep->hwp + FEC_LPI_WAKE);
 
@@ -1982,6 +1973,8 @@ static void fec_enet_adjust_link(struct net_device *ndev)
 			netif_tx_unlock_bh(ndev);
 			napi_enable(&fep->napi);
 		}
+		if (fep->quirks & FEC_QUIRK_HAS_EEE)
+			fec_enet_eee_mode_set(ndev, phy_dev->enable_tx_lpi);
 	} else {
 		if (fep->link) {
 			napi_disable(&fep->napi);
@@ -2340,6 +2333,9 @@ static int fec_enet_mii_probe(struct net_device *ndev)
 	else
 		phy_set_max_speed(phy_dev, 100);
 
+	if (fep->quirks & FEC_QUIRK_HAS_EEE)
+		phy_support_eee(phy_dev);
+
 	fep->link = 0;
 	fep->full_duplex = 0;
 
@@ -3096,10 +3092,7 @@ fec_enet_get_eee(struct net_device *ndev, struct ethtool_eee *edata)
 	if (!netif_running(ndev))
 		return -ENETDOWN;
 
-	edata->eee_enabled = p->eee_enabled;
-	edata->eee_active = p->eee_active;
 	edata->tx_lpi_timer = p->tx_lpi_timer;
-	edata->tx_lpi_enabled = p->tx_lpi_enabled;
 
 	return phy_ethtool_get_eee(ndev->phydev, edata);
 }
@@ -3109,7 +3102,6 @@ fec_enet_set_eee(struct net_device *ndev, struct ethtool_eee *edata)
 {
 	struct fec_enet_private *fep = netdev_priv(ndev);
 	struct ethtool_eee *p = &fep->eee;
-	int ret = 0;
 
 	if (!(fep->quirks & FEC_QUIRK_HAS_EEE))
 		return -EOPNOTSUPP;
@@ -3119,15 +3111,6 @@ fec_enet_set_eee(struct net_device *ndev, struct ethtool_eee *edata)
 
 	p->tx_lpi_timer = edata->tx_lpi_timer;
 
-	if (!edata->eee_enabled || !edata->tx_lpi_enabled ||
-	    !edata->tx_lpi_timer)
-		ret = fec_enet_eee_mode_set(ndev, false);
-	else
-		ret = fec_enet_eee_mode_set(ndev, true);
-
-	if (ret)
-		return ret;
-
 	return phy_ethtool_set_eee(ndev->phydev, edata);
 }
 
-- 
2.40.1


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

* Re: [PATCH v4 net-next 1/9] net: phy-c45: Fix genphy_c45_ethtool_set_eee description
  2023-06-18 18:41 ` [PATCH v4 net-next 1/9] net: phy-c45: Fix genphy_c45_ethtool_set_eee description Andrew Lunn
@ 2023-06-18 19:18   ` Russell King (Oracle)
  2023-06-18 20:30     ` Andrew Lunn
  0 siblings, 1 reply; 20+ messages in thread
From: Russell King (Oracle) @ 2023-06-18 19:18 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: netdev, Heiner Kallweit, Florian Fainelli, Oleksij Rempel

On Sun, Jun 18, 2023 at 08:41:11PM +0200, Andrew Lunn wrote:
> The text has been cut/paste from  genphy_c45_ethtool_get_eee but not
> changed to reflect it performs set.
> 
> Additionally, extend the comment. This function implements the logic
> that eee_enabled has global control over EEE. When eee_enabled is
> false, no link modes will be advertised, and as a result, the MAC
> should not transmit LPI.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---
>  drivers/net/phy/phy-c45.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c
> index fee514b96ab1..d1d7cf34ac0b 100644
> --- a/drivers/net/phy/phy-c45.c
> +++ b/drivers/net/phy/phy-c45.c
> @@ -1425,12 +1425,15 @@ int genphy_c45_ethtool_get_eee(struct phy_device *phydev,
>  EXPORT_SYMBOL(genphy_c45_ethtool_get_eee);
>  
>  /**
> - * genphy_c45_ethtool_set_eee - get EEE supported and status
> + * genphy_c45_ethtool_set_eee - set EEE supported and status
>   * @phydev: target phy_device struct
>   * @data: ethtool_eee data
>   *
> - * Description: it reportes the Supported/Advertisement/LP Advertisement
> - * capabilities.
> + * Description: it set the Supported/Advertisement/LP Advertisement

      Description: sets the ...

> + * capabilities. If eee_enabled is false, no links modes are
> + * advertised, but the previously advertised link modes are

I'd suggest moving "advertised," to the preceding line to fill it
more...

> + * retained. This allows EEE to be enabled/disabled in a none
> + * destructive way.

which then would allow "non-destructive" here rather than the slightly
more awkward (but correct) "non-
destructive" formatting here.

Thanks!

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

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

* Re: [PATCH v4 net-next 5/9] net: phy: Keep track of EEE configuration
  2023-06-18 18:41 ` [PATCH v4 net-next 5/9] net: phy: Keep track of EEE configuration Andrew Lunn
@ 2023-06-18 19:20   ` Russell King (Oracle)
  2023-06-19 14:20   ` Simon Horman
  2023-06-19 15:27   ` Florian Fainelli
  2 siblings, 0 replies; 20+ messages in thread
From: Russell King (Oracle) @ 2023-06-18 19:20 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: netdev, Heiner Kallweit, Florian Fainelli, Oleksij Rempel

On Sun, Jun 18, 2023 at 08:41:15PM +0200, Andrew Lunn wrote:
> Have phylib keep track of the EEE configuration. This simplifies the
> MAC drivers, in that they don't need to store it.
> 
> Future patches to phylib will also make use of this information to
> further simplify the MAC drivers.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---
>  drivers/net/phy/phy.c | 5 ++++-
>  include/linux/phy.h   | 3 +++
>  2 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index 629499e5aff0..48150d5626d8 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c
> @@ -1588,7 +1588,7 @@ EXPORT_SYMBOL(phy_get_eee_err);
>   * @data: ethtool_eee data
>   *
>   * Description: it reportes the Supported/Advertisement/LP Advertisement
> - * capabilities.
> + * capabilities, etc.

Any scope to drop the "it" and fix "reports" ?

Apart from that, looks good.

Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>

Thanks!

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

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

* Re: [PATCH v4 net-next 1/9] net: phy-c45: Fix genphy_c45_ethtool_set_eee description
  2023-06-18 19:18   ` Russell King (Oracle)
@ 2023-06-18 20:30     ` Andrew Lunn
  0 siblings, 0 replies; 20+ messages in thread
From: Andrew Lunn @ 2023-06-18 20:30 UTC (permalink / raw)
  To: Russell King (Oracle)
  Cc: netdev, Heiner Kallweit, Florian Fainelli, Oleksij Rempel

> >  /**
> > - * genphy_c45_ethtool_set_eee - get EEE supported and status
> > + * genphy_c45_ethtool_set_eee - set EEE supported and status
> >   * @phydev: target phy_device struct
> >   * @data: ethtool_eee data
> >   *
> > - * Description: it reportes the Supported/Advertisement/LP Advertisement
> > - * capabilities.
> > + * Description: it set the Supported/Advertisement/LP Advertisement
> 
>       Description: sets the ...
> 
> > + * capabilities. If eee_enabled is false, no links modes are
> > + * advertised, but the previously advertised link modes are
> 
> I'd suggest moving "advertised," to the preceding line to fill it
> more...
> 
> > + * retained. This allows EEE to be enabled/disabled in a none
> > + * destructive way.
> 
> which then would allow "non-destructive" here rather than the slightly
> more awkward (but correct) "non-
> destructive" formatting here.

Thanks for the comments. I actually ended up submitting this patch
twice, one standalone and then again as part of this patchset. I
should stop submitting patches today, i'm getting too many things
wrong :-)

I will fixup the standalone version.

  Andrew

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

* Re: [PATCH v4 net-next 5/9] net: phy: Keep track of EEE configuration
  2023-06-18 18:41 ` [PATCH v4 net-next 5/9] net: phy: Keep track of EEE configuration Andrew Lunn
  2023-06-18 19:20   ` Russell King (Oracle)
@ 2023-06-19 14:20   ` Simon Horman
  2023-06-19 15:27   ` Florian Fainelli
  2 siblings, 0 replies; 20+ messages in thread
From: Simon Horman @ 2023-06-19 14:20 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: netdev, Russell King, Heiner Kallweit, Florian Fainelli, Oleksij Rempel

On Sun, Jun 18, 2023 at 08:41:15PM +0200, Andrew Lunn wrote:
> Have phylib keep track of the EEE configuration. This simplifies the
> MAC drivers, in that they don't need to store it.
> 
> Future patches to phylib will also make use of this information to
> further simplify the MAC drivers.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

...

> diff --git a/include/linux/phy.h b/include/linux/phy.h
> index 66f69d512f45..473ddf62bee9 100644
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h
> @@ -30,6 +30,7 @@
>  #include <linux/refcount.h>
>  
>  #include <linux/atomic.h>
> +#include <net/eee.h>
>  
>  #define PHY_DEFAULT_FEATURES	(SUPPORTED_Autoneg | \
>  				 SUPPORTED_TP | \
> @@ -585,6 +586,7 @@ struct macsec_ops;
>   * @advertising_eee: Currently advertised EEE linkmodes
>   * @eee_enabled: Flag indicating whether the EEE feature is enabled
>   * @enable_tx_lpi: When True, MAC should transmit LPI to PHY
> + * eee_cfg: User configuration of EEE

Hi Andrew,

a minor nit from my side: eee_cfg: -> @eee_cfg:

>   * @lp_advertising: Current link partner advertised linkmodes
>   * @host_interfaces: PHY interface modes supported by host
>   * @eee_broken_modes: Energy efficient ethernet modes which should be prohibited
> @@ -702,6 +704,7 @@ struct phy_device {
>  	/* Energy efficient ethernet modes which should be prohibited */
>  	u32 eee_broken_modes;
>  	bool enable_tx_lpi;
> +	struct eee_config eee_cfg;
>  
>  #ifdef CONFIG_LED_TRIGGER_PHY
>  	struct phy_led_trigger *phy_led_triggers;
> -- 
> 2.40.1
> 
> 

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

* Re: [PATCH v4 net-next 7/9] net: phy: Add phy_support_eee() indicating MAC support EEE
  2023-06-18 18:41 ` [PATCH v4 net-next 7/9] net: phy: Add phy_support_eee() indicating MAC support EEE Andrew Lunn
@ 2023-06-19 15:21   ` Florian Fainelli
  2023-06-22 15:20     ` Russell King (Oracle)
  0 siblings, 1 reply; 20+ messages in thread
From: Florian Fainelli @ 2023-06-19 15:21 UTC (permalink / raw)
  To: Andrew Lunn, netdev; +Cc: Russell King, Heiner Kallweit, Oleksij Rempel



On 6/18/2023 7:41 PM, Andrew Lunn wrote:
> In order for EEE to operate, both the MAC and the PHY need to support
> it, similar to how pause works. Copy the pause concept and add the
> call phy_support_eee() which the MAC makes after connecting the PHY to
> indicate it supports EEE. phylib will then advertise EEE when auto-neg
> is performed.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---
>   drivers/net/phy/phy_device.c | 18 ++++++++++++++++++
>   include/linux/phy.h          |  3 ++-
>   2 files changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 2cad9cc3f6b8..ae2ebe1df15c 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -2762,6 +2762,24 @@ void phy_advertise_supported(struct phy_device *phydev)
>   }
>   EXPORT_SYMBOL(phy_advertise_supported);
>   
> +/**
> + * phy_support_eee - Enable support of EEE
> + * @phydev: target phy_device struct
> + *
> + * Description: Called by the MAC to indicate is supports Energy

typo: is/it

> + * Efficient Ethernet. This should be called before phy_start() in
> + * order that EEE is negotiated when the link comes up as part of
> + * phy_start(). EEE is enabled by default when the hardware supports
> + * it.
> + */
> +void phy_support_eee(struct phy_device *phydev)
> +{
> +	linkmode_copy(phydev->advertising_eee, phydev->supported_eee);
> +	phydev->eee_cfg.tx_lpi_enabled = true;
> +	phydev->eee_cfg.eee_enabled = true;
> +}
> +EXPORT_SYMBOL(phy_support_eee);

A bit worried that naming this function might be confusing driver 
authors that this is a function that reports whether EEE is supported, 
though I am not able to come up with better names.

> +
>   /**
>    * phy_support_sym_pause - Enable support of symmetrical pause
>    * @phydev: target phy_device struct
> diff --git a/include/linux/phy.h b/include/linux/phy.h
> index 473ddf62bee9..29ae45d37011 100644
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h
> @@ -693,7 +693,7 @@ struct phy_device {
>   	__ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
>   	/* used with phy_speed_down */
>   	__ETHTOOL_DECLARE_LINK_MODE_MASK(adv_old);
> -	/* used for eee validation */
> +	/* used for eee validation and configuration*/

While at it, maybe capitalize to EEE?

>   	__ETHTOOL_DECLARE_LINK_MODE_MASK(supported_eee);
>   	__ETHTOOL_DECLARE_LINK_MODE_MASK(advertising_eee);
>   	bool eee_enabled;
> @@ -1903,6 +1903,7 @@ void phy_remove_link_mode(struct phy_device *phydev, u32 link_mode);
>   void phy_advertise_supported(struct phy_device *phydev);
>   void phy_support_sym_pause(struct phy_device *phydev);
>   void phy_support_asym_pause(struct phy_device *phydev);
> +void phy_support_eee(struct phy_device *phydev);
>   void phy_set_sym_pause(struct phy_device *phydev, bool rx, bool tx,
>   		       bool autoneg);
>   void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx);

-- 
Florian

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

* Re: [PATCH v4 net-next 8/9] net: fec: Move fec_enet_eee_mode_set() and helper earlier
  2023-06-18 18:41 ` [PATCH v4 net-next 8/9] net: fec: Move fec_enet_eee_mode_set() and helper earlier Andrew Lunn
@ 2023-06-19 15:22   ` Florian Fainelli
  0 siblings, 0 replies; 20+ messages in thread
From: Florian Fainelli @ 2023-06-19 15:22 UTC (permalink / raw)
  To: Andrew Lunn, netdev; +Cc: Russell King, Heiner Kallweit, Oleksij Rempel



On 6/18/2023 7:41 PM, Andrew Lunn wrote:
> FEC is about to get its EEE code re-written. To allow this, move
> fec_enet_eee_mode_set() before fec_enet_adjust_link() which will
> need to call it.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
-- 
Florian

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

* Re: [PATCH v4 net-next 2/9] net: add helpers for EEE configuration
  2023-06-18 18:41 ` [PATCH v4 net-next 2/9] net: add helpers for EEE configuration Andrew Lunn
@ 2023-06-19 15:26   ` Florian Fainelli
  0 siblings, 0 replies; 20+ messages in thread
From: Florian Fainelli @ 2023-06-19 15:26 UTC (permalink / raw)
  To: Andrew Lunn, netdev; +Cc: Russell King, Heiner Kallweit, Oleksij Rempel



On 6/18/2023 7:41 PM, Andrew Lunn wrote:
> From: Russell King <rmk+kernel@armlinux.org.uk>
> 
> Add helpers that phylib and phylink can use to manage EEE configuration
> and determine whether the MAC should be permitted to use LPI based on
> that configuration.
> 
> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
-- 
Florian

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

* Re: [PATCH v4 net-next 5/9] net: phy: Keep track of EEE configuration
  2023-06-18 18:41 ` [PATCH v4 net-next 5/9] net: phy: Keep track of EEE configuration Andrew Lunn
  2023-06-18 19:20   ` Russell King (Oracle)
  2023-06-19 14:20   ` Simon Horman
@ 2023-06-19 15:27   ` Florian Fainelli
  2 siblings, 0 replies; 20+ messages in thread
From: Florian Fainelli @ 2023-06-19 15:27 UTC (permalink / raw)
  To: Andrew Lunn, netdev; +Cc: Russell King, Heiner Kallweit, Oleksij Rempel



On 6/18/2023 7:41 PM, Andrew Lunn wrote:
> Have phylib keep track of the EEE configuration. This simplifies the
> MAC drivers, in that they don't need to store it.
> 
> Future patches to phylib will also make use of this information to
> further simplify the MAC drivers.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

With both Simon's and Russell's feedback addressed:

Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
-- 
Florian

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

* Re: [PATCH v4 net-next 7/9] net: phy: Add phy_support_eee() indicating MAC support EEE
  2023-06-19 15:21   ` Florian Fainelli
@ 2023-06-22 15:20     ` Russell King (Oracle)
  2023-06-22 15:43       ` Andrew Lunn
  0 siblings, 1 reply; 20+ messages in thread
From: Russell King (Oracle) @ 2023-06-22 15:20 UTC (permalink / raw)
  To: Florian Fainelli; +Cc: Andrew Lunn, netdev, Heiner Kallweit, Oleksij Rempel

On Mon, Jun 19, 2023 at 04:21:09PM +0100, Florian Fainelli wrote:
> 
> 
> On 6/18/2023 7:41 PM, Andrew Lunn wrote:
> > In order for EEE to operate, both the MAC and the PHY need to support
> > it, similar to how pause works. Copy the pause concept and add the
> > call phy_support_eee() which the MAC makes after connecting the PHY to
> > indicate it supports EEE. phylib will then advertise EEE when auto-neg
> > is performed.
> > 
> > Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> > ---
> >   drivers/net/phy/phy_device.c | 18 ++++++++++++++++++
> >   include/linux/phy.h          |  3 ++-
> >   2 files changed, 20 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> > index 2cad9cc3f6b8..ae2ebe1df15c 100644
> > --- a/drivers/net/phy/phy_device.c
> > +++ b/drivers/net/phy/phy_device.c
> > @@ -2762,6 +2762,24 @@ void phy_advertise_supported(struct phy_device *phydev)
> >   }
> >   EXPORT_SYMBOL(phy_advertise_supported);
> > +/**
> > + * phy_support_eee - Enable support of EEE
> > + * @phydev: target phy_device struct
> > + *
> > + * Description: Called by the MAC to indicate is supports Energy
> 
> typo: is/it
> 
> > + * Efficient Ethernet. This should be called before phy_start() in
> > + * order that EEE is negotiated when the link comes up as part of
> > + * phy_start(). EEE is enabled by default when the hardware supports
> > + * it.
> > + */
> > +void phy_support_eee(struct phy_device *phydev)
> > +{
> > +	linkmode_copy(phydev->advertising_eee, phydev->supported_eee);
> > +	phydev->eee_cfg.tx_lpi_enabled = true;
> > +	phydev->eee_cfg.eee_enabled = true;
> > +}
> > +EXPORT_SYMBOL(phy_support_eee);
> 
> A bit worried that naming this function might be confusing driver authors
> that this is a function that reports whether EEE is supported, though I am
> not able to come up with better names.

Possibly phy_enable_eee_support() ?

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

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

* Re: [PATCH v4 net-next 7/9] net: phy: Add phy_support_eee() indicating MAC support EEE
  2023-06-22 15:20     ` Russell King (Oracle)
@ 2023-06-22 15:43       ` Andrew Lunn
  0 siblings, 0 replies; 20+ messages in thread
From: Andrew Lunn @ 2023-06-22 15:43 UTC (permalink / raw)
  To: Russell King (Oracle)
  Cc: Florian Fainelli, netdev, Heiner Kallweit, Oleksij Rempel

> > > + * Efficient Ethernet. This should be called before phy_start() in
> > > + * order that EEE is negotiated when the link comes up as part of
> > > + * phy_start(). EEE is enabled by default when the hardware supports
> > > + * it.
> > > + */
> > > +void phy_support_eee(struct phy_device *phydev)
> > > +{
> > > +	linkmode_copy(phydev->advertising_eee, phydev->supported_eee);
> > > +	phydev->eee_cfg.tx_lpi_enabled = true;
> > > +	phydev->eee_cfg.eee_enabled = true;
> > > +}
> > > +EXPORT_SYMBOL(phy_support_eee);
> > 
> > A bit worried that naming this function might be confusing driver authors
> > that this is a function that reports whether EEE is supported, though I am
> > not able to come up with better names.
> 
> Possibly phy_enable_eee_support() ?

As i said in the commit message, i followed what we do for pause:

void phy_support_sym_pause(struct phy_device *phydev);
void phy_support_asym_pause(struct phy_device *phydev);

but phy_enable_eee_support() is less ambiguous.

    Andrew



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

end of thread, other threads:[~2023-06-22 15:43 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-18 18:41 [PATCH v4 net-next 0/9] net: ethernet: Rework EEE Andrew Lunn
2023-06-18 18:41 ` [PATCH v4 net-next 1/9] net: phy-c45: Fix genphy_c45_ethtool_set_eee description Andrew Lunn
2023-06-18 19:18   ` Russell King (Oracle)
2023-06-18 20:30     ` Andrew Lunn
2023-06-18 18:41 ` [PATCH v4 net-next 2/9] net: add helpers for EEE configuration Andrew Lunn
2023-06-19 15:26   ` Florian Fainelli
2023-06-18 18:41 ` [PATCH v4 net-next 3/9] net: phy: Add phydev->enable_tx_lpi to simplify adjust link callbacks Andrew Lunn
2023-06-18 18:41 ` [PATCH v4 net-next 4/9] net: phy: Add helper to set EEE Clock stop enable bit Andrew Lunn
2023-06-18 18:41 ` [PATCH v4 net-next 5/9] net: phy: Keep track of EEE configuration Andrew Lunn
2023-06-18 19:20   ` Russell King (Oracle)
2023-06-19 14:20   ` Simon Horman
2023-06-19 15:27   ` Florian Fainelli
2023-06-18 18:41 ` [PATCH v4 net-next 6/9] net: phy: Immediately call adjust_link if only tx_lpi_enabled changes Andrew Lunn
2023-06-18 18:41 ` [PATCH v4 net-next 7/9] net: phy: Add phy_support_eee() indicating MAC support EEE Andrew Lunn
2023-06-19 15:21   ` Florian Fainelli
2023-06-22 15:20     ` Russell King (Oracle)
2023-06-22 15:43       ` Andrew Lunn
2023-06-18 18:41 ` [PATCH v4 net-next 8/9] net: fec: Move fec_enet_eee_mode_set() and helper earlier Andrew Lunn
2023-06-19 15:22   ` Florian Fainelli
2023-06-18 18:41 ` [PATCH v4 net-next 9/9] net: fec: Fixup EEE Andrew Lunn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).