netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2] net: ethernet: mediatek: add EEE support
@ 2025-02-10 12:52 Qingfang Deng
  2025-02-13  9:04 ` Paolo Abeni
  0 siblings, 1 reply; 4+ messages in thread
From: Qingfang Deng @ 2025-02-10 12:52 UTC (permalink / raw)
  To: Felix Fietkau, Sean Wang, Lorenzo Bianconi, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Matthias Brugger, AngeloGioacchino Del Regno, Russell King,
	netdev, linux-kernel, linux-arm-kernel, linux-mediatek

Add EEE support to MediaTek SoC Ethernet. The register fields are
similar to the ones in MT7531, except that the LPI threshold is in
milliseconds.

Signed-off-by: Qingfang Deng <dqfext@gmail.com>
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 64 +++++++++++++++++++++
 drivers/net/ethernet/mediatek/mtk_eth_soc.h | 11 ++++
 2 files changed, 75 insertions(+)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 53485142938c..943636d822b5 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -786,6 +786,7 @@ static void mtk_mac_link_up(struct phylink_config *config,
 
 	mcr = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));
 	mcr &= ~(MAC_MCR_SPEED_100 | MAC_MCR_SPEED_1000 |
+		 MAC_MCR_EEE100M | MAC_MCR_EEE1G |
 		 MAC_MCR_FORCE_DPX | MAC_MCR_FORCE_TX_FC |
 		 MAC_MCR_FORCE_RX_FC);
 
@@ -811,6 +812,18 @@ static void mtk_mac_link_up(struct phylink_config *config,
 	if (rx_pause)
 		mcr |= MAC_MCR_FORCE_RX_FC;
 
+	if (mode == MLO_AN_PHY && phy && phy_init_eee(phy, false) >= 0) {
+		switch (speed) {
+		case SPEED_2500:
+		case SPEED_1000:
+			mcr |= MAC_MCR_EEE1G;
+			break;
+		case SPEED_100:
+			mcr |= MAC_MCR_EEE100M;
+			break;
+		}
+	}
+
 	mcr |= MAC_MCR_TX_EN | MAC_MCR_RX_EN | MAC_MCR_FORCE_LINK;
 	mtk_w32(mac->hw, mcr, MTK_MAC_MCR(mac->id));
 }
@@ -4474,6 +4487,55 @@ static int mtk_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam
 	return phylink_ethtool_set_pauseparam(mac->phylink, pause);
 }
 
+static int mtk_get_eee(struct net_device *dev, struct ethtool_keee *eee)
+{
+	struct mtk_mac *mac = netdev_priv(dev);
+	u32 reg;
+	int ret;
+
+	ret = phylink_ethtool_get_eee(mac->phylink, eee);
+	if (ret)
+		return ret;
+
+	reg = mtk_r32(mac->hw, MTK_MAC_EEECR(mac->id));
+	eee->tx_lpi_enabled = !(reg & MAC_EEE_LPI_MODE);
+	eee->tx_lpi_timer = FIELD_GET(MAC_EEE_LPI_TXIDLE_THD, reg) * 1000;
+
+	return 0;
+}
+
+static int mtk_set_eee(struct net_device *dev, struct ethtool_keee *eee)
+{
+	struct mtk_mac *mac = netdev_priv(dev);
+	u32 txidle_thd_ms, reg;
+	int ret;
+
+	/* Tx idle timer in ms */
+	txidle_thd_ms = DIV_ROUND_UP(eee->tx_lpi_timer, 1000);
+	if (!FIELD_FIT(MAC_EEE_LPI_TXIDLE_THD, txidle_thd_ms))
+		return -EINVAL;
+
+	reg = FIELD_PREP(MAC_EEE_LPI_TXIDLE_THD, txidle_thd_ms);
+
+	/* PHY Wake-up time, this field does not have a reset value, so use the
+	 * reset value from MT7531 (36us for 100BaseT and 17us for 1000BaseT).
+	 */
+	reg |= FIELD_PREP(MAC_EEE_WAKEUP_TIME_1000, 17) |
+	       FIELD_PREP(MAC_EEE_WAKEUP_TIME_100, 36);
+
+	if (!eee->tx_lpi_enabled)
+		/* Force LPI Mode without a delay */
+		reg |= MAC_EEE_LPI_MODE;
+
+	ret = phylink_ethtool_set_eee(mac->phylink, eee);
+	if (ret)
+		return ret;
+
+	mtk_w32(mac->hw, reg, MTK_MAC_EEECR(mac->id));
+
+	return 0;
+}
+
 static u16 mtk_select_queue(struct net_device *dev, struct sk_buff *skb,
 			    struct net_device *sb_dev)
 {
@@ -4506,6 +4568,8 @@ static const struct ethtool_ops mtk_ethtool_ops = {
 	.set_pauseparam		= mtk_set_pauseparam,
 	.get_rxnfc		= mtk_get_rxnfc,
 	.set_rxnfc		= mtk_set_rxnfc,
+	.get_eee		= mtk_get_eee,
+	.set_eee		= mtk_set_eee,
 };
 
 static const struct net_device_ops mtk_netdev_ops = {
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
index 0d5225f1d3ee..90a377ab4359 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
@@ -453,6 +453,8 @@
 #define MAC_MCR_RX_FIFO_CLR_DIS	BIT(12)
 #define MAC_MCR_BACKOFF_EN	BIT(9)
 #define MAC_MCR_BACKPR_EN	BIT(8)
+#define MAC_MCR_EEE1G		BIT(7)
+#define MAC_MCR_EEE100M		BIT(6)
 #define MAC_MCR_FORCE_RX_FC	BIT(5)
 #define MAC_MCR_FORCE_TX_FC	BIT(4)
 #define MAC_MCR_SPEED_1000	BIT(3)
@@ -461,6 +463,15 @@
 #define MAC_MCR_FORCE_LINK	BIT(0)
 #define MAC_MCR_FORCE_LINK_DOWN	(MAC_MCR_FORCE_MODE)
 
+/* Mac EEE control registers */
+#define MTK_MAC_EEECR(x)		(0x10104 + (x * 0x100))
+#define MAC_EEE_WAKEUP_TIME_1000	GENMASK(31, 24)
+#define MAC_EEE_WAKEUP_TIME_100		GENMASK(23, 16)
+#define MAC_EEE_LPI_TXIDLE_THD		GENMASK(15, 8)
+#define MAC_EEE_CKG_TXIDLE		BIT(3)
+#define MAC_EEE_CKG_RXLPI		BIT(2)
+#define MAC_EEE_LPI_MODE		BIT(0)
+
 /* Mac status registers */
 #define MTK_MAC_MSR(x)		(0x10108 + (x * 0x100))
 #define MAC_MSR_EEE1G		BIT(7)
-- 
2.43.0


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

* Re: [PATCH net-next v2] net: ethernet: mediatek: add EEE support
  2025-02-10 12:52 [PATCH net-next v2] net: ethernet: mediatek: add EEE support Qingfang Deng
@ 2025-02-13  9:04 ` Paolo Abeni
  2025-02-13  9:10   ` Russell King (Oracle)
  0 siblings, 1 reply; 4+ messages in thread
From: Paolo Abeni @ 2025-02-13  9:04 UTC (permalink / raw)
  To: Felix Fietkau, Sean Wang, Lorenzo Bianconi
  Cc: linux-mediatek, linux-arm-kernel, netdev, Russell King,
	linux-kernel, AngeloGioacchino Del Regno, Matthias Brugger,
	Jakub Kicinski, Qingfang Deng, Andrew Lunn, David S. Miller,
	Eric Dumazet

On 2/10/25 1:52 PM, Qingfang Deng wrote:
> Add EEE support to MediaTek SoC Ethernet. The register fields are
> similar to the ones in MT7531, except that the LPI threshold is in
> milliseconds.
> 
> Signed-off-by: Qingfang Deng <dqfext@gmail.com>

@Felix, @Sean, @Lorenzo: could you please have a look?

Thanks!

Paolo


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

* Re: [PATCH net-next v2] net: ethernet: mediatek: add EEE support
  2025-02-13  9:04 ` Paolo Abeni
@ 2025-02-13  9:10   ` Russell King (Oracle)
  2025-02-13 15:23     ` Paolo Abeni
  0 siblings, 1 reply; 4+ messages in thread
From: Russell King (Oracle) @ 2025-02-13  9:10 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: Felix Fietkau, Sean Wang, Lorenzo Bianconi, linux-mediatek,
	linux-arm-kernel, netdev, linux-kernel,
	AngeloGioacchino Del Regno, Matthias Brugger, Jakub Kicinski,
	Qingfang Deng, Andrew Lunn, David S. Miller, Eric Dumazet

On Thu, Feb 13, 2025 at 10:04:50AM +0100, Paolo Abeni wrote:
> On 2/10/25 1:52 PM, Qingfang Deng wrote:
> > Add EEE support to MediaTek SoC Ethernet. The register fields are
> > similar to the ones in MT7531, except that the LPI threshold is in
> > milliseconds.
> > 
> > Signed-off-by: Qingfang Deng <dqfext@gmail.com>
> 
> @Felix, @Sean, @Lorenzo: could you please have a look?

That would be a waste of time, because it's implementing the "old way"
including using phy_init_eee() which Andrew wants to get rid of. It
should be using phylink's EEE management.

The patches for the mt753x driver converting that over have now been
apparently merged last night according to patchwork into net-next, but
something's gone wrong because there's no updates to the git trees
on korg,

-- 
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] 4+ messages in thread

* Re: [PATCH net-next v2] net: ethernet: mediatek: add EEE support
  2025-02-13  9:10   ` Russell King (Oracle)
@ 2025-02-13 15:23     ` Paolo Abeni
  0 siblings, 0 replies; 4+ messages in thread
From: Paolo Abeni @ 2025-02-13 15:23 UTC (permalink / raw)
  To: Russell King (Oracle)
  Cc: Felix Fietkau, Sean Wang, Lorenzo Bianconi, linux-mediatek,
	linux-arm-kernel, netdev, linux-kernel,
	AngeloGioacchino Del Regno, Matthias Brugger, Jakub Kicinski,
	Qingfang Deng, Andrew Lunn, David S. Miller, Eric Dumazet

On 2/13/25 10:10 AM, Russell King (Oracle) wrote:
> On Thu, Feb 13, 2025 at 10:04:50AM +0100, Paolo Abeni wrote:
>> On 2/10/25 1:52 PM, Qingfang Deng wrote:
>>> Add EEE support to MediaTek SoC Ethernet. The register fields are
>>> similar to the ones in MT7531, except that the LPI threshold is in
>>> milliseconds.
>>>
>>> Signed-off-by: Qingfang Deng <dqfext@gmail.com>
>>
>> @Felix, @Sean, @Lorenzo: could you please have a look?
> 
> That would be a waste of time, because it's implementing the "old way"
> including using phy_init_eee() which Andrew wants to get rid of. It
> should be using phylink's EEE management.
> 
> The patches for the mt753x driver converting that over have now been
> apparently merged last night according to patchwork into net-next, but
> something's gone wrong because there's no updates to the git trees
> on korg,

this series:

https://lore.kernel.org/all/Z6nWujbjxlkzK_3P@shell.armlinux.org.uk/

is in net-next commit 443b5ca4d7245eec9a9192461113a4c341e441e5.

In the past few days there has been a few slowdowns in the kernel infra.
Perhaps some mirror or cache not updated?

Cheers,

Paolo


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

end of thread, other threads:[~2025-02-13 15:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-10 12:52 [PATCH net-next v2] net: ethernet: mediatek: add EEE support Qingfang Deng
2025-02-13  9:04 ` Paolo Abeni
2025-02-13  9:10   ` Russell King (Oracle)
2025-02-13 15:23     ` Paolo Abeni

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).