Skip to contentSkip to conversation

net: cadence: macb: add IEEE 802.3az EEE support

PATCH Superseded Nicolai Buchwitz 5 participants 18 messages Feb 25 – Feb 27

Subsystems (3)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover net: cadence: macb: add IEEE 802.3az EEE support

Add Energy Efficient Ethernet (IEEE 802.3az) support to the Cadence GEM (macb) driver using phylink's managed EEE framework. The GEM MAC has hardware LPI registers but no built-in idle timer, so the driver implements software-managed TX LPI using a delayed_work timer while delegating EEE negotiation and ethtool state to phylink.

Changes from v2:
- macb_tx_lpi_set() now returns bool indicating whether the register value actually changed, avoiding redundant writes.
- Removed tx_lpi_enabled field from struct macb; LPI state is tracked entirely within the spinlock-protected register read/modify/write.
- macb_tx_lpi_wake() uses the return value of macb_tx_lpi_set() to skip the cancel/udelay when TXLPIEN was already clear.
All changes based on feedback from Russell King.

Changes from v1:
- Rewrote to use phylink managed EEE (mac_enable_tx_lpi / mac_disable_tx_lpi callbacks) instead of the obsolete phy_init_eee() approach, as recommended by Russell King.
- ethtool get_eee/set_eee are now pure phylink passthroughs.
- Removed all manual EEE state tracking from mac_link_up/down; phylink handles the lifecycle.

The series is structured as follows:

1. Register definitions: LPI counter offsets (0x270-0x27c), TXLPIEN bitfield (NCR bit 19), and MACB_CAPS_EEE capability flag.

2. LPI statistics: Expose the four hardware EEE counters (RX/TX LPI transitions and time) through ethtool -S, accumulated in software since they are clear-on-read.

3. TX LPI engine: phylink mac_enable_tx_lpi / mac_disable_tx_lpi callbacks with a delayed_work-based idle timer. LPI entry is deferred 1 second after link-up per IEEE 802.3az. Wake before transmit with a conservative 50us PHY wake delay.

4. ethtool EEE ops: get_eee/set_eee delegating to phylink for PHY negotiation and timer management.

5. RP1 enablement: Set MACB_CAPS_EEE for the Raspberry Pi 5's RP1

     southbridge (Cadence GEM_GXL rev 0x00070109 + BCM54213PE PHY).

Tested on Raspberry Pi 5 (1000BASE-T, BCM54213PE PHY, 250ms LPI timer):

iperf3 throughput (no regression):

    TCP TX: 937.8 Mbit/s (EEE on) vs 937.0 Mbit/s (EEE off)
    TCP RX: 936.5 Mbit/s both

Latency (ping RTT, small expected increase from LPI wake):

    1s interval:  0.273 ms (EEE on) vs 0.181 ms (EEE off)
    10ms interval: 0.206 ms (EEE on) vs 0.168 ms (EEE off)
    flood ping:   0.200 ms (EEE on) vs 0.156 ms (EEE off)

LPI counters (ethtool -S, 1s-interval ping, EEE on):

    tx_lpi_transitions: 112
    tx_lpi_time: 15574651

Zero packet loss across all tests. Also verified with ethtool --show-eee / --set-eee and cable unplug/replug cycling.

Nicolai Buchwitz (5):
net: cadence: macb: add EEE register definitions and capability flag
net: cadence: macb: add EEE LPI statistics counters
net: cadence: macb: implement EEE TX LPI support
net: cadence: macb: add ethtool EEE support
net: cadence: macb: enable EEE for Raspberry Pi RP1

 drivers/net/ethernet/cadence/macb.h      |  20 ++++
 drivers/net/ethernet/cadence/macb_main.c | 136 ++++++++++++++++++++++-
 2 files changed, 155 insertions(+), 1 deletion(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH v3 1/5 net: cadence: macb: add EEE register definitions and capability flag

Add register and bitfield definitions for the Cadence GEM MAC's IEEE 802.3az Energy Efficient Ethernet (EEE) support:

- LPI statistics counter registers (GEM_RXLPI, GEM_RXLPITIME, GEM_TXLPI, GEM_TXLPITIME) at offsets 0x270-0x27c
- TX LPI enable bitfield (GEM_TXLPIEN) in the NCR register (bit 19), which directly asserts/deasserts LPI on the transmit path
- MACB_CAPS_EEE capability flag to gate EEE support per platform

These registers are present in all Cadence GEM revisions that support EEE (verified on SAMA5D2, SAME70, PIC32CZ, and RP1 variants).

No functional change.

---
 drivers/net/ethernet/cadence/macb.h | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/net/ethernet/cadence/macb.h +7 -0
index 87414a2ddf6e..729751d424c2 100644
@@ -170,6 +170,10 @@
 #define GEM_PCSANNPTX		0x021c /* PCS AN Next Page TX */
 #define GEM_PCSANNPLP		0x0220 /* PCS AN Next Page LP */
 #define GEM_PCSANEXTSTS		0x023c /* PCS AN Extended Status */
+#define GEM_RXLPI		0x0270 /* RX LPI Transitions */
+#define GEM_RXLPITIME		0x0274 /* RX LPI Time */
+#define GEM_TXLPI		0x0278 /* TX LPI Transitions */
+#define GEM_TXLPITIME		0x027c /* TX LPI Time */
 #define GEM_DCFG1		0x0280 /* Design Config 1 */
 #define GEM_DCFG2		0x0284 /* Design Config 2 */
 #define GEM_DCFG3		0x0288 /* Design Config 3 */
@@ -305,6 +309,8 @@
 #define MACB_IRXFCS_SIZE	1
 
 /* GEM specific NCR bitfields. */
+#define GEM_TXLPIEN_OFFSET		19
+#define GEM_TXLPIEN_SIZE		1
 #define GEM_ENABLE_HS_MAC_OFFSET	31
 #define GEM_ENABLE_HS_MAC_SIZE		1
 
@@ -779,6 +785,7 @@
 #define MACB_CAPS_DMA_PTP			BIT(22)
 #define MACB_CAPS_RSC				BIT(23)
 #define MACB_CAPS_NO_LSO			BIT(24)
+#define MACB_CAPS_EEE				BIT(25)
 
 /* LSO settings */
 #define MACB_LSO_UFO_ENABLE			0x01
Signature · 1 line
2.51.0
#4 lore raw

PATCH v3 2/5 net: cadence: macb: add EEE LPI statistics counters

In reply to Nicolai Buchwitz

Expose the GEM MAC's EEE Low Power Idle hardware counters through ethtool -S:

- rx_lpi_transitions: number of RX LPI entry events
- rx_lpi_time: cumulative time spent in RX LPI
- tx_lpi_transitions: number of TX LPI entry events (TXLPIEN 0->1)
- tx_lpi_time: cumulative time in TX LPI

These are clear-on-read hardware registers at offsets 0x270-0x27c, automatically collected by the existing gem_statistics read loop.

---
 drivers/net/ethernet/cadence/macb.h | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/net/ethernet/cadence/macb.h +8 -0
index 729751d424c2..e3520e5aec67 100644
@@ -1050,6 +1050,10 @@ struct gem_stats {
 	u64	rx_ip_header_checksum_errors;
 	u64	rx_tcp_checksum_errors;
 	u64	rx_udp_checksum_errors;
+	u64	rx_lpi_transitions;
+	u64	rx_lpi_time;
+	u64	tx_lpi_transitions;
+	u64	tx_lpi_time;
 };
 
 /* Describes the name and offset of an individual statistic register, as
@@ -1149,6 +1153,10 @@ static const struct gem_statistic gem_statistics[] = {
 			    GEM_BIT(NDS_RXERR)),
 	GEM_STAT_TITLE_BITS(RXUDPCCNT, "rx_udp_checksum_errors",
 			    GEM_BIT(NDS_RXERR)),
+	GEM_STAT_TITLE(RXLPI, "rx_lpi_transitions"),
+	GEM_STAT_TITLE(RXLPITIME, "rx_lpi_time"),
+	GEM_STAT_TITLE(TXLPI, "tx_lpi_transitions"),
+	GEM_STAT_TITLE(TXLPITIME, "tx_lpi_time"),
 };
 
 #define GEM_STATS_LEN ARRAY_SIZE(gem_statistics)
Signature · 1 line
2.51.0
#5 lore raw

PATCH v3 3/5 net: cadence: macb: implement EEE TX LPI support

In reply to Nicolai Buchwitz

Implement Energy Efficient Ethernet TX Low Power Idle using phylink's managed EEE framework. The Cadence GEM MAC has no built-in idle timer — TXLPIEN (NCR bit 19) immediately blocks all TX when set and the MAC does NOT auto-wake — so the driver uses a software delayed_work timer for idle detection.

The TX LPI lifecycle:
- phylink calls mac_enable_tx_lpi() after link-up with the negotiated timer value. The driver defers the first LPI entry by 1 second per IEEE 802.3az section 22.7a.
- macb_tx_complete() reschedules the idle timer after each TX drain.
- macb_start_xmit() wakes from LPI by clearing TXLPIEN, cancelling the pending work, and waiting 50us (conservative Tw_sys) before initiating the transmit.
- phylink calls mac_disable_tx_lpi() before link-down, which cancels the work and clears TXLPIEN.

The phylink_config is populated with LPI capabilities (MII, GMII, RGMII modes; 100FD and 1000FD speeds) and a 250ms default idle timer, gated on MACB_CAPS_EEE.

---
 drivers/net/ethernet/cadence/macb.h      |   5 +
 drivers/net/ethernet/cadence/macb_main.c | 111 +++++++++++++++++++++++
 2 files changed, 116 insertions(+)
drivers/net/ethernet/cadence/macb.h +5 -0
index e3520e5aec67..c69828b27dae 100644
@@ -1372,6 +1372,11 @@ struct macb {
 
 	struct work_struct	hresp_err_bh_work;
 
+	/* EEE / LPI state */
+	bool			eee_active;
+	struct delayed_work	tx_lpi_work;
+	u32			tx_lpi_timer;
+
 	int	rx_bd_rd_prefetch;
 	int	tx_bd_rd_prefetch;
 
drivers/net/ethernet/cadence/macb_main.c +111 -0

165 lines not on this page · raw message

Signature · 1 line
2.51.0
#15 lore raw

PATCH v3 4/5 net: cadence: macb: add ethtool EEE support

In reply to Nicolai Buchwitz

Implement ethtool get_eee and set_eee operations for the Cadence GEM MAC, delegating to phylink for PHY-level EEE negotiation state.

The MAC-level LPI control (TXLPIEN) is not manipulated directly in the ethtool ops - phylink manages the full EEE lifecycle through the mac_enable_tx_lpi / mac_disable_tx_lpi callbacks.

Both ops are gated on MACB_CAPS_EEE; platforms without the capability flag return -EOPNOTSUPP.

---
 drivers/net/ethernet/cadence/macb_main.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/net/ethernet/cadence/macb_main.c +22 -0
index a9ae7ecf9fe9..37a5b866e3a5 100644
@@ -4033,6 +4033,26 @@ static const struct ethtool_ops macb_ethtool_ops = {
 	.set_ringparam		= macb_set_ringparam,
 };
 
+static int macb_get_eee(struct net_device *dev, struct ethtool_keee *eee)
+{
+	struct macb *bp = netdev_priv(dev);
+
+	if (!(bp->caps & MACB_CAPS_EEE))
+		return -EOPNOTSUPP;
+
+	return phylink_ethtool_get_eee(bp->phylink, eee);
+}
+
+static int macb_set_eee(struct net_device *dev, struct ethtool_keee *eee)
+{
+	struct macb *bp = netdev_priv(dev);
+
+	if (!(bp->caps & MACB_CAPS_EEE))
+		return -EOPNOTSUPP;
+
+	return phylink_ethtool_set_eee(bp->phylink, eee);
+}
+
 static const struct ethtool_ops gem_ethtool_ops = {
 	.get_regs_len		= macb_get_regs_len,
 	.get_regs		= macb_get_regs,
@@ -4054,6 +4074,8 @@ static const struct ethtool_ops gem_ethtool_ops = {
 	.get_rxnfc			= gem_get_rxnfc,
 	.set_rxnfc			= gem_set_rxnfc,
 	.get_rx_ring_count		= gem_get_rx_ring_count,
+	.get_eee		= macb_get_eee,
+	.set_eee		= macb_set_eee,
 };
 
 static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
Signature · 1 line
2.51.0
#16 lore raw

PATCH v3 5/5 net: cadence: macb: enable EEE for Raspberry Pi RP1

In reply to Nicolai Buchwitz

Enable IEEE 802.3az Energy Efficient Ethernet on the Raspberry Pi 5's RP1 southbridge by adding MACB_CAPS_EEE to its platform config.

The RP1 contains a Cadence GEM_GXL MAC (revision 0x00070109) paired with a Broadcom BCM54213PE PHY, both of which support EEE at 1000BASE-T and 100BASE-TX.

---
 drivers/net/ethernet/cadence/macb_main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/cadence/macb_main.c +2 -1
index 37a5b866e3a5..7fe7e5338a2e 100644
@@ -5517,7 +5517,8 @@ static const struct macb_config eyeq5_config = {
 static const struct macb_config raspberrypi_rp1_config = {
 	.caps = MACB_CAPS_GIGABIT_MODE_AVAILABLE | MACB_CAPS_CLK_HW_CHG |
 		MACB_CAPS_JUMBO |
-		MACB_CAPS_GEM_HAS_PTP,
+		MACB_CAPS_GEM_HAS_PTP |
+		MACB_CAPS_EEE,
 	.dma_burst_length = 16,
 	.clk_init = macb_clk_init,
 	.init = macb_init,
Signature · 1 line
2.51.0
#17 lore raw
In reply to Nicolai Buchwitz
Quoted 6 lines · Nicolai Buchwitz

Add Energy Efficient Ethernet (IEEE 802.3az) support to the Cadence GEM (macb) driver using phylink's managed EEE framework. The GEM MAC has hardware LPI registers but no built-in idle timer, so the driver implements software-managed TX LPI using a delayed_work timer while delegating EEE negotiation and ethtool state to phylink.

Quoted 9 lines

Changes from v2:
- macb_tx_lpi_set() now returns bool indicating whether the register value actually changed, avoiding redundant writes.
- Removed tx_lpi_enabled field from struct macb; LPI state is tracked entirely within the spinlock-protected register read/modify/write.
- macb_tx_lpi_wake() uses the return value of macb_tx_lpi_set() to skip the cancel/udelay when TXLPIEN was already clear.
All changes based on feedback from Russell King.

Apologies for the missing subject prefix and version tags on this series - should have been [PATCH net-next v3]. I'm still fairly new to the kernel mailing list workflow and building up the muscle memory around git-format-patch/send-email. I'll resend as v4 with the proper tags. In the meantime, feedback on the code itself is very welcome.

Quoted 53 lines

Changes from v1:
- Rewrote to use phylink managed EEE (mac_enable_tx_lpi / mac_disable_tx_lpi callbacks) instead of the obsolete phy_init_eee() approach, as recommended by Russell King.
- ethtool get_eee/set_eee are now pure phylink passthroughs.
- Removed all manual EEE state tracking from mac_link_up/down; phylink handles the lifecycle.

The series is structured as follows:

1. Register definitions: LPI counter offsets (0x270-0x27c), TXLPIEN bitfield (NCR bit 19), and MACB_CAPS_EEE capability flag.

2. LPI statistics: Expose the four hardware EEE counters (RX/TX LPI transitions and time) through ethtool -S, accumulated in software since they are clear-on-read.

3. TX LPI engine: phylink mac_enable_tx_lpi / mac_disable_tx_lpi callbacks with a delayed_work-based idle timer. LPI entry is deferred 1 second after link-up per IEEE 802.3az. Wake before transmit with a conservative 50us PHY wake delay.

4. ethtool EEE ops: get_eee/set_eee delegating to phylink for PHY negotiation and timer management.

5. RP1 enablement: Set MACB_CAPS_EEE for the Raspberry Pi 5's RP1

     southbridge (Cadence GEM_GXL rev 0x00070109 + BCM54213PE PHY).

Tested on Raspberry Pi 5 (1000BASE-T, BCM54213PE PHY, 250ms LPI timer):

iperf3 throughput (no regression):

    TCP TX: 937.8 Mbit/s (EEE on) vs 937.0 Mbit/s (EEE off)
    TCP RX: 936.5 Mbit/s both

Latency (ping RTT, small expected increase from LPI wake):

    1s interval:  0.273 ms (EEE on) vs 0.181 ms (EEE off)
    10ms interval: 0.206 ms (EEE on) vs 0.168 ms (EEE off)
    flood ping:   0.200 ms (EEE on) vs 0.156 ms (EEE off)

LPI counters (ethtool -S, 1s-interval ping, EEE on):

    tx_lpi_transitions: 112
    tx_lpi_time: 15574651

Zero packet loss across all tests. Also verified with ethtool --show-eee / --set-eee and cable unplug/replug cycling.

Nicolai Buchwitz (5):
net: cadence: macb: add EEE register definitions and capability flag
net: cadence: macb: add EEE LPI statistics counters
net: cadence: macb: implement EEE TX LPI support
net: cadence: macb: add ethtool EEE support
net: cadence: macb: enable EEE for Raspberry Pi RP1

Quoted 3 lines
 drivers/net/ethernet/cadence/macb.h      |  20 ++++
 drivers/net/ethernet/cadence/macb_main.c | 136 ++++++++++++++++++++++-
 2 files changed, 155 insertions(+), 1 deletion(-)

Nicolai

maintainer
#2 lore raw

Re: [PATCH 1/5] net: cadence: macb: add EEE register definitions and capability flag

In reply to Nicolai Buchwitz

Hello Nicolai,

Quoted 2 lines · Nicolai Buchwitz

Add register and bitfield definitions for the Cadence GEM MAC's IEEE 802.3az Energy Efficient Ethernet (EEE) support:

nit: could this patch be squashed into [3/5]?

Quoted 8 lines

- LPI statistics counter registers (GEM_RXLPI, GEM_RXLPITIME, GEM_TXLPI, GEM_TXLPITIME) at offsets 0x270-0x27c
- TX LPI enable bitfield (GEM_TXLPIEN) in the NCR register (bit 19), which directly asserts/deasserts LPI on the transmit path
- MACB_CAPS_EEE capability flag to gate EEE support per platform

These registers are present in all Cadence GEM revisions that support EEE (verified on SAMA5D2, SAME70, PIC32CZ, and RP1 variants).

Would the capability flag deserve to be added to any other compatible?

Thanks,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

#6 lore raw

RE: [PATCH 3/5] net: cadence: macb: implement EEE TX LPI support

In reply to Nicolai Buchwitz
Quoted 121 lines

-----Original Message-----
From: Nicolai Buchwitz <[email protected]>
Sent: Wednesday, February 25, 2026 2:46 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Nicolai Buchwitz <[email protected]>
Subject: [PATCH 3/5] net: cadence: macb: implement EEE TX LPI support

Implement Energy Efficient Ethernet TX Low Power Idle using phylink's managed EEE framework. The Cadence GEM MAC has no built-in idle timer — TXLPIEN (NCR bit 19) immediately blocks all TX when set and the MAC does NOT auto-wake — so the driver
Implement Energy Efficient Ethernet TX Low Power Idle using phylink's managed EEE framework. The Cadence GEM MAC has no built-in idle timer — TXLPIEN (NCR bit 19) immediately blocks all TX when set and the MAC does NOT auto-wake — so the driver uses a software delayed_work timer for idle detection.

The TX LPI lifecycle:
- phylink calls mac_enable_tx_lpi() after link-up with the negotiated timer value. The driver defers the first LPI entry by 1 second per IEEE 802.3az section 22.7a.
- macb_tx_complete() reschedules the idle timer after each TX drain.
- macb_start_xmit() wakes from LPI by clearing TXLPIEN, cancelling the pending work, and waiting 50us (conservative Tw_sys) before initiating the transmit.
- phylink calls mac_disable_tx_lpi() before link-down, which cancels the work and clears TXLPIEN.

The phylink_config is populated with LPI capabilities (MII, GMII, RGMII modes; 100FD and 1000FD speeds) and a 250ms default idle timer, gated on MACB_CAPS_EEE.

---
 drivers/net/ethernet/cadence/macb.h      |   5 +
 drivers/net/ethernet/cadence/macb_main.c | 111
+++++++++++++++++++++++
 2 files changed, 116 insertions(+)
drivers/net/ethernet/cadence/macb.h +5 -0
index e3520e5aec67..c69828b27dae 100644
@@ -1372,6 +1372,11 @@ struct macb {
 
 	struct work_struct	hresp_err_bh_work;
 
+	/* EEE / LPI state */
+	bool			eee_active;
+	struct delayed_work	tx_lpi_work;
+	u32			tx_lpi_timer;
+
 	int	rx_bd_rd_prefetch;
 	int	tx_bd_rd_prefetch;
 
drivers/net/ethernet/cadence/macb_main.c +1 -0
index 43cd013bb70e..a9ae7ecf9fe9 100644
@@ -10,6 +10,7 @@
 #include <linux/clk-provider.h>
 #include <linux/clk.h>
 #include <linux/crc32.h>
+#include <linux/delay.h>
 #include <linux/dma-mapping.h>
 #include <linux/etherdevice.h>
 #include <linux/firmware/xlnx-zynqmp.h> @@ -589,6 +590,93 @@ static

const struct phylink_pcs_ops macb_phylink_pcs_ops = {

drivers/net/ethernet/cadence/macb_main.c +43 -0
 	.pcs_config = macb_pcs_config,
 };
 
+static bool macb_tx_lpi_set(struct macb *bp, bool enable) {
+	unsigned long flags;
+	u32 old, ncr;
+
+	spin_lock_irqsave(&bp->lock, flags);
+	old = ncr = macb_readl(bp, NCR);
+	if (enable)
+		ncr |= GEM_BIT(TXLPIEN);
+	else
+		ncr &= ~GEM_BIT(TXLPIEN);
+	if (old != ncr)
+		macb_writel(bp, NCR, ncr);
+	spin_unlock_irqrestore(&bp->lock, flags);
+
+	return old != ncr;
+}
+
+static bool macb_tx_all_queues_idle(struct macb *bp) {
+	unsigned int q;
+
+	for (q = 0; q < bp->num_queues; q++) {
+		struct macb_queue *queue = &bp->queues[q];
+
+		if (queue->tx_head != queue->tx_tail)
+			return false;
+	}
+	return true;
+}
+
+static void macb_tx_lpi_work_fn(struct work_struct *work) {
+	struct macb *bp = container_of(work, struct macb, tx_lpi_work.work);
+
+	if (bp->eee_active && macb_tx_all_queues_idle(bp))
+		macb_tx_lpi_set(bp, true);
+}
+
+static void macb_tx_lpi_schedule(struct macb *bp) {
+	if (bp->eee_active)
+		mod_delayed_work(system_wq, &bp->tx_lpi_work,
+				 usecs_to_jiffies(bp->tx_lpi_timer));
+}
+
+/* Wake from LPI before transmitting. The MAC must deassert TXLPIEN

drivers/net/ethernet/cadence/macb_main.c static const struct phylink_pcs_ops macb_phylink_pcs_ops = { · line 650

Quoted 10 lines
drivers/net/ethernet/cadence/macb_main.c +10 -0
+ * and wait for the PHY to exit LPI before any frame can be sent.
+ * IEEE 802.3az Tw_sys is ~17us for 1000BASE-T, ~30us for 100BASE-TX;
+ * we use a conservative 50us.
+ */
+static void macb_tx_lpi_wake(struct macb *bp) {
+	if (!macb_tx_lpi_set(bp, false))
+		return;
+
+	cancel_delayed_work(&bp->tx_lpi_work);
+	udelay(50);

Any reason the 50µs busy-wait in xmit path? Can it be avoided?

Quoted 115 lines
drivers/net/ethernet/cadence/macb_main.c +24 -0
+}
+
+static void macb_mac_disable_tx_lpi(struct phylink_config *config) {
+	struct net_device *ndev = to_net_dev(config->dev);
+	struct macb *bp = netdev_priv(ndev);
+
+	bp->eee_active = false;
+	cancel_delayed_work_sync(&bp->tx_lpi_work);
+	macb_tx_lpi_set(bp, false);
+}
+
+static int macb_mac_enable_tx_lpi(struct phylink_config *config, u32 timer,
+				  bool tx_clk_stop)
+{
+	struct net_device *ndev = to_net_dev(config->dev);
+	struct macb *bp = netdev_priv(ndev);
+
+	bp->tx_lpi_timer = timer;
+	bp->eee_active = true;
+
+	/* Defer initial LPI entry by 1 second after link-up per
+	 * IEEE 802.3az section 22.7a.
+	 */
+	mod_delayed_work(system_wq, &bp->tx_lpi_work,

msecs_to_jiffies(1000));

drivers/net/ethernet/cadence/macb_main.c +4 -0
+
+	return 0;
+}
+
 static void macb_mac_config(struct phylink_config *config, unsigned int

mode,

drivers/net/ethernet/cadence/macb_main.c +12 -0
 			    const struct phylink_link_state *state)  { @@ -753,6
+841,8 @@ static const struct phylink_mac_ops macb_phylink_ops = {
 	.mac_config = macb_mac_config,
 	.mac_link_down = macb_mac_link_down,
 	.mac_link_up = macb_mac_link_up,
+	.mac_disable_tx_lpi = macb_mac_disable_tx_lpi,
+	.mac_enable_tx_lpi = macb_mac_enable_tx_lpi,
 };
 
 static bool macb_phy_handle_exists(struct device_node *dn) @@ -848,6
+938,18 @@ static int macb_mii_probe(struct net_device *dev)
 		}
 	}
 
+	/* Configure EEE LPI if supported */
+	if (bp->caps & MACB_CAPS_EEE) {
+		__set_bit(PHY_INTERFACE_MODE_MII,
+			  bp->phylink_config.lpi_interfaces);
+		__set_bit(PHY_INTERFACE_MODE_GMII,
+			  bp->phylink_config.lpi_interfaces);
+		phy_interface_set_rgmii(bp->phylink_config.lpi_interfaces);
+		bp->phylink_config.lpi_capabilities = MAC_100FD |

MAC_1000FD;

drivers/net/ethernet/cadence/macb_main.c +4 -0
+		bp->phylink_config.lpi_timer_default = 250000;
+		bp->phylink_config.eee_enabled_default = true;
+	}
+
 	bp->phylink = phylink_create(&bp->phylink_config, bp->pdev-
Quoted 1 line

dev.fwnode,

drivers/net/ethernet/cadence/macb_main.c +5 -0
 				     bp->phy_interface, &macb_phylink_ops);
 	if (IS_ERR(bp->phylink)) {
@@ -1244,6 +1346,9 @@ static int macb_tx_complete(struct macb_queue
 *queue, int budget)
 		netif_wake_subqueue(bp->dev, queue_index);
 	spin_unlock_irqrestore(&queue->tx_ptr_lock, flags);
 
+	if (packets)
+		macb_tx_lpi_schedule(bp);
+
 	return packets;
 }
@@ -2349,6 +2454,8 @@ static netdev_tx_t macb_start_xmit(struct sk_buff
 *skb, struct net_device *dev)
 	netdev_tx_sent_queue(netdev_get_tx_queue(bp->dev,
 queue_index),
 			     skb->len);
 
+	macb_tx_lpi_wake(bp);
+
 	spin_lock(&bp->lock);
drivers/net/ethernet/cadence/macb_main.c +3 -0
 	macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TSTART));
 	spin_unlock(&bp->lock);
@@ -3010,6 +3117,8 @@ static int macb_close(struct net_device *dev)
 		netdev_tx_reset_queue(netdev_get_tx_queue(dev, q));
 	}
 
+	cancel_delayed_work_sync(&bp->tx_lpi_work);
+
 	phylink_stop(bp->phylink);
 	phylink_disconnect_phy(bp->phylink);
 
@@ -5616,6 +5725,7 @@ static int macb_probe(struct platform_device
 *pdev)
 	}
 
 	INIT_WORK(&bp->hresp_err_bh_work, macb_hresp_error_task);
+	INIT_DELAYED_WORK(&bp->tx_lpi_work, macb_tx_lpi_work_fn);
 
 	netdev_info(dev, "Cadence %s rev 0x%08x at 0x%08lx irq %d

(%pM)\n",
macb_is_gem(bp) ? "GEM" : "MACB", macb_readl(bp,
MID), @@ -5659,6 +5769,7 @@ static void macb_remove(struct platform_device *pdev)

drivers/net/ethernet/cadence/macb_main.c +1 -1
 		mdiobus_free(bp->mii_bus);
 
 		device_set_wakeup_enable(&bp->pdev->dev, 0);
+		cancel_delayed_work_sync(&bp->tx_lpi_work);
 		cancel_work_sync(&bp->hresp_err_bh_work);
 		pm_runtime_disable(&pdev->dev);
 		pm_runtime_dont_use_autosuspend(&pdev->dev);
--

2.51.0

maintainer Reviewed-by on v3 3/5
#8 lore raw

Re: [PATCH 3/5] net: cadence: macb: implement EEE TX LPI support

In reply to Nicolai Buchwitz
Quoted 31 lines · Nicolai Buchwitz

Implement Energy Efficient Ethernet TX Low Power Idle using phylink's managed EEE framework. The Cadence GEM MAC has no built-in idle timer — TXLPIEN (NCR bit 19) immediately blocks all TX when set and the MAC does NOT auto-wake — so the driver uses a software delayed_work timer for idle detection.

The TX LPI lifecycle:
- phylink calls mac_enable_tx_lpi() after link-up with the negotiated timer value. The driver defers the first LPI entry by 1 second per IEEE 802.3az section 22.7a.
- macb_tx_complete() reschedules the idle timer after each TX drain.
- macb_start_xmit() wakes from LPI by clearing TXLPIEN, cancelling the pending work, and waiting 50us (conservative Tw_sys) before initiating the transmit.
- phylink calls mac_disable_tx_lpi() before link-down, which cancels the work and clears TXLPIEN.

The phylink_config is populated with LPI capabilities (MII, GMII, RGMII modes; 100FD and 1000FD speeds) and a 250ms default idle timer, gated on MACB_CAPS_EEE.

---
 drivers/net/ethernet/cadence/macb.h      |   5 +
 drivers/net/ethernet/cadence/macb_main.c | 111 +++++++++++++++++++++++
 2 files changed, 116 insertions(+)
drivers/net/ethernet/cadence/macb_main.c +0 -0
index 43cd013bb70e..a9ae7ecf9fe9 100644

[...]

Quoted 13 lines
drivers/net/ethernet/cadence/macb_main.c +13 -0
+/* Wake from LPI before transmitting. The MAC must deassert TXLPIEN
+ * and wait for the PHY to exit LPI before any frame can be sent.
+ * IEEE 802.3az Tw_sys is ~17us for 1000BASE-T, ~30us for 100BASE-TX;
+ * we use a conservative 50us.
+ */
+static void macb_tx_lpi_wake(struct macb *bp)
+{
+	if (!macb_tx_lpi_set(bp, false))
+		return;
+
+	cancel_delayed_work(&bp->tx_lpi_work);
+	udelay(50);
+}

[...]

drivers/net/ethernet/cadence/macb_main.c static netdev_tx_t macb_start_xmit(struct sk_buff *skb, struct net_device *dev) · line 2457

Quoted 5 lines
drivers/net/ethernet/cadence/macb_main.c +1 -0
@@ -2349,6 +2454,8 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	netdev_tx_sent_queue(netdev_get_tx_queue(bp->dev, queue_index),
 			     skb->len);
 
+	macb_tx_lpi_wake(bp);

Should this be protected by a bp->eee_active condition? It could go in macb_tx_lpi_wake(). We avoid a spinlock acquire per xmit for most platforms. Probably negligeable though.

For the full series:

Thanks!

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

#9 lore raw

Re: [PATCH 3/5] net: cadence: macb: implement EEE TX LPI support

Quoted 10 lines · Théo Lebrun

drivers/net/ethernet/cadence/macb_main.c static netdev_tx_t macb_start_xmit(struct sk_buff *skb, struct net_device *dev) · line 2457

Quoted 5 lines · Nicolai Buchwitz
drivers/net/ethernet/cadence/macb_main.c +1 -0
@@ -2349,6 +2454,8 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	netdev_tx_sent_queue(netdev_get_tx_queue(bp->dev, queue_index),
 			     skb->len);
 
+	macb_tx_lpi_wake(bp);

Should this be protected by a bp->eee_active condition? It could go in macb_tx_lpi_wake(). We avoid a spinlock acquire per xmit for most platforms. Probably negligeable though.

It will read the register, find the bit clear, and then return if EEE is already disabled.

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!
maintainer
#3 lore raw

Re: [PATCH 1/5] net: cadence: macb: add EEE register definitions and capability flag

In reply to Théo Lebrun
Quoted 5 lines · On Wed, 25 Feb 2026 18:26:18 +0100 Théo Lebrun wrote:
Quoted 2 lines · Nicolai Buchwitz

Add register and bitfield definitions for the Cadence GEM MAC's IEEE 802.3az Energy Efficient Ethernet (EEE) support:

nit: could this patch be squashed into [3/5]?

Maybe split into two in fact, the relevant part squashed into patch 2 and the rest in patch 3?

#7 lore raw

Re: [PATCH 3/5] net: cadence: macb: implement EEE TX LPI support

In reply to Sai Krishna Gajula
Quoted 11 lines · Sai Krishna Gajula
Quoted 11 lines

-----Original Message-----
From: Nicolai Buchwitz <[email protected]>
Sent: Wednesday, February 25, 2026 2:46 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Nicolai Buchwitz <[email protected]>
Subject: [PATCH 3/5] net: cadence: macb: implement EEE TX LPI support

[...]

Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/cadence/macb_main.c +11 -0
+
+static void macb_tx_lpi_schedule(struct macb *bp) {
+	if (bp->eee_active)
+		mod_delayed_work(system_wq, &bp->tx_lpi_work,
+				 usecs_to_jiffies(bp->tx_lpi_timer));
+}
+
+/* Wake from LPI before transmitting. The MAC must deassert TXLPIEN
+ * and wait for the PHY to exit LPI before any frame can be sent.
+ * IEEE 802.3az Tw_sys is ~17us for 1000BASE-T, ~30us for 100BASE-TX;
+ * we use a conservative 50us.
Quoted 9 lines

drivers/net/ethernet/cadence/macb_main.c static const struct phylink_pcs_ops macb_phylink_pcs_ops = { · line 650

Quoted 7 lines

+ */

drivers/net/ethernet/cadence/macb_main.c +6 -0
+static void macb_tx_lpi_wake(struct macb *bp) {
+	if (!macb_tx_lpi_set(bp, false))
+		return;
+
+	cancel_delayed_work(&bp->tx_lpi_work);
+	udelay(50);

Any reason the 50µs busy-wait in xmit path? Can it be avoided?

The 50us delay is required by IEEE 802.3az. After clearing TXLPIEN the PHY needs time to exit LPI and re-establish normal operation before the MAC can transmit. This is defined as Tw_sys_tx - approximately 16.5us for 1000BASE-T and 30us for 100BASE-TX. We use a conservative 50us to cover both speeds without needing to track the current link rate.

Testing without the delay confirmed packet loss on the first frame after waking from LPI, as the PHY had not yet fully transitioned back to normal mode.

This delay is specific to the GEM MAC because TXLPIEN directly and immediately controls LPI with no hardware enforcement of Tw_sys_tx - the software must enforce it. Other phylink-managed EEE drivers (mvneta, stmmac, lan743x, mtk) don't need an explicit delay because their hardware handles the wake timing automatically.

The cost is also bounded: the delay only fires when TXLPIEN was actually asserted, i.e. on the first transmit after an idle period.

[...]

Nicolai

maintainer
#10 lore raw

Re: [PATCH 3/5] net: cadence: macb: implement EEE TX LPI support

In reply to Russell King (Oracle)
Quoted 6 lines · Russell King (Oracle)
Quoted 5 lines · Théo Lebrun
Quoted 4 lines · Nicolai Buchwitz
drivers/net/ethernet/cadence/macb_main.c +0 -0
@@ -2349,6 +2454,8 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	netdev_tx_sent_queue(netdev_get_tx_queue(bp->dev, queue_index),
 			     skb->len);
 
Quoted 8 lines
Quoted 5 lines

drivers/net/ethernet/cadence/macb_main.c static netdev_tx_t macb_start_xmit(struct sk_buff *skb, struct net_device *dev) · line 2457

Quoted 1 line
drivers/net/ethernet/cadence/macb_main.c +1 -0
+	macb_tx_lpi_wake(bp);

Should this be protected by a bp->eee_active condition? It could go in macb_tx_lpi_wake(). We avoid a spinlock acquire per xmit for most platforms. Probably negligeable though.

It will read the register, find the bit clear, and then return if EEE is already disabled.

Yes I agree with your sentence, sorry my point was unclear. I was not describing a bug but rather a performance optimisation.

We would look up bp->eee_active to know if we can avoid calling macb_tx_lpi_set(), to avoid grabbing bp->lock once per xmit. That spinlock is interface-wide.

Thanks,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

#11 lore raw

Re: [PATCH 3/5] net: cadence: macb: implement EEE TX LPI support

Quoted 16 lines · Théo Lebrun
Quoted 6 lines · Russell King (Oracle)
Quoted 5 lines · Théo Lebrun
Quoted 4 lines · Nicolai Buchwitz
drivers/net/ethernet/cadence/macb_main.c +0 -0
@@ -2349,6 +2454,8 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	netdev_tx_sent_queue(netdev_get_tx_queue(bp->dev, queue_index),
 			     skb->len);
 
Quoted 8 lines
Quoted 5 lines

drivers/net/ethernet/cadence/macb_main.c static netdev_tx_t macb_start_xmit(struct sk_buff *skb, struct net_device *dev) · line 2457

Quoted 1 line
drivers/net/ethernet/cadence/macb_main.c +1 -0
+	macb_tx_lpi_wake(bp);

Should this be protected by a bp->eee_active condition? It could go in macb_tx_lpi_wake(). We avoid a spinlock acquire per xmit for most platforms. Probably negligeable though.

It will read the register, find the bit clear, and then return if EEE is already disabled.

Quoted 6 lines

Yes I agree with your sentence, sorry my point was unclear. I was not describing a bug but rather a performance optimisation.

We would look up bp->eee_active to know if we can avoid calling macb_tx_lpi_set(), to avoid grabbing bp->lock once per xmit. That spinlock is interface-wide.

So you're suggesting to revert to the v2 approach?
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/

Quoted 7 lines

Thanks,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

Nicolai

maintainer
#12 lore raw

Re: [PATCH 3/5] net: cadence: macb: implement EEE TX LPI support

Quoted 20 lines · Nicolai Buchwitz
Quoted 19 lines · Théo Lebrun
Quoted 6 lines · Russell King (Oracle)
Quoted 5 lines · Théo Lebrun
Quoted 4 lines · Nicolai Buchwitz
drivers/net/ethernet/cadence/macb_main.c +0 -0
@@ -2349,6 +2454,8 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	netdev_tx_sent_queue(netdev_get_tx_queue(bp->dev, queue_index),
 			     skb->len);
 
Quoted 8 lines
Quoted 5 lines

drivers/net/ethernet/cadence/macb_main.c static netdev_tx_t macb_start_xmit(struct sk_buff *skb, struct net_device *dev) · line 2457

Quoted 1 line
drivers/net/ethernet/cadence/macb_main.c +1 -0
+	macb_tx_lpi_wake(bp);

Should this be protected by a bp->eee_active condition? It could go in macb_tx_lpi_wake(). We avoid a spinlock acquire per xmit for most platforms. Probably negligeable though.

It will read the register, find the bit clear, and then return if EEE is already disabled.

Yes I agree with your sentence, sorry my point was unclear. I was not describing a bug but rather a performance optimisation.

Quoted 6 lines
Quoted 3 lines

We would look up bp->eee_active to know if we can avoid calling macb_tx_lpi_set(), to avoid grabbing bp->lock once per xmit. That spinlock is interface-wide.

So you're suggesting to revert to the v2 approach?
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/

I discovered this series at its V3.
It seems like I was suggesting a mix of both V2 & V3 approaches.

// V2 was:
static void macb_tx_lpi_wake(struct macb *bp)

{
	if (!bp->eee_active)
		return;

	macb_tx_lpi_set(bp, false);
	cancel_delayed_work(&bp->tx_lpi_work);
	udelay(50);
}

// V3 & V3 are:
static void macb_tx_lpi_wake(struct macb *bp)

{
	if (!macb_tx_lpi_set(bp, false))
		return;

	cancel_delayed_work(&bp->tx_lpi_work);
	udelay(50);
}

// I was suggesting:
static void macb_tx_lpi_wake(struct macb *bp)

{
	if (!eee_active || !macb_tx_lpi_set(bp, false))
		return;

	cancel_delayed_work(&bp->tx_lpi_work);
	udelay(50);
}

But talking about perf, let's measure.

I don't get any measurable performance improvement on average/max time spent in macb_start_xmit() between net-next and this series. We spend <3µs per call anyway. 10s iperf3 1G TCP test on EyeQ5, ftrace function graph tracer on macb_start_xmit().

Summary: you can ignore my remark.

Thanks,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

#13 lore raw

Re: [PATCH 3/5] net: cadence: macb: implement EEE TX LPI support

Quoted 62 lines · Théo Lebrun
Quoted 20 lines · Nicolai Buchwitz
Quoted 19 lines · Théo Lebrun
Quoted 6 lines · Russell King (Oracle)
Quoted 5 lines · Théo Lebrun
Quoted 4 lines · Nicolai Buchwitz
drivers/net/ethernet/cadence/macb_main.c +0 -0
@@ -2349,6 +2454,8 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	netdev_tx_sent_queue(netdev_get_tx_queue(bp->dev, queue_index),
 			     skb->len);
 
Quoted 8 lines
Quoted 5 lines

drivers/net/ethernet/cadence/macb_main.c static netdev_tx_t macb_start_xmit(struct sk_buff *skb, struct net_device *dev) · line 2457

Quoted 1 line
drivers/net/ethernet/cadence/macb_main.c +1 -0
+	macb_tx_lpi_wake(bp);

Should this be protected by a bp->eee_active condition? It could go in macb_tx_lpi_wake(). We avoid a spinlock acquire per xmit for most platforms. Probably negligeable though.

It will read the register, find the bit clear, and then return if EEE is already disabled.

Yes I agree with your sentence, sorry my point was unclear. I was not describing a bug but rather a performance optimisation.

Quoted 6 lines
Quoted 3 lines

We would look up bp->eee_active to know if we can avoid calling macb_tx_lpi_set(), to avoid grabbing bp->lock once per xmit. That spinlock is interface-wide.

So you're suggesting to revert to the v2 approach?
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/

I discovered this series at its V3.
It seems like I was suggesting a mix of both V2 & V3 approaches.

// V2 was:
static void macb_tx_lpi_wake(struct macb *bp)

{
	if (!bp->eee_active)
		return;

	macb_tx_lpi_set(bp, false);
	cancel_delayed_work(&bp->tx_lpi_work);
	udelay(50);
}

// V3 & V3 are:
static void macb_tx_lpi_wake(struct macb *bp)

{
	if (!macb_tx_lpi_set(bp, false))
		return;

	cancel_delayed_work(&bp->tx_lpi_work);
	udelay(50);
}

// I was suggesting:
static void macb_tx_lpi_wake(struct macb *bp)

{
	if (!eee_active || !macb_tx_lpi_set(bp, false))
		return;

	cancel_delayed_work(&bp->tx_lpi_work);
	udelay(50);
}
Quoted 1 line

But talking about perf, let's measure.

Tthanks for testing! Since you have the hardware at hand, would you be willing to add MACB_CAPS_EEE to eyeq5_config as well? I'm happy to include it in the series if you can confirm it works correctly.

Quoted 6 lines

I don't get any measurable performance improvement on average/max time spent in macb_start_xmit() between net-next and this series. We spend <3µs per call anyway. 10s iperf3 1G TCP test on EyeQ5, ftrace function graph tracer on macb_start_xmit().

Quoted 8 lines

Summary: you can ignore my remark.

Thanks,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

Nicolai

maintainer Tested-by
#14 lore raw

Re: [PATCH 3/5] net: cadence: macb: implement EEE TX LPI support

Hello Nicolai,

Quoted 7 lines · Nicolai Buchwitz
Quoted 2 lines · Théo Lebrun

On Thu Feb 26, 2026 at 11:49 AM CET, Nicolai Buchwitz wrote:
But talking about perf, let's measure.

Tthanks for testing! Since you have the hardware at hand, would you be willing to add MACB_CAPS_EEE to eyeq5_config as well? I'm happy to include it in the series if you can confirm it works correctly.

Tested using a hardware loopback and a net namespace.

# ip netns add netns_eth1
# ip link set eth1 netns netns_eth1
# ip -n netns_eth1 a add 10.0.0.2/24 dev eth1
# ip -n netns_eth1 link set eth1 up
# ip a add 10.0.0.1/24 dev eth0
# ip link set eth0 up

... ping and iperf3 ...

# ethtool --show-eee eth0
EEE settings for eth0:
enabled - active
250000 (us)
        Supported EEE link modes:  100baseT/Full
                                   1000baseT/Full
        Advertised EEE link modes:  100baseT/Full
                                    1000baseT/Full
        Link partner advertised EEE link modes:  100baseT/Full
                                                 1000baseT/Full
# ip netns exec netns_eth1 ethtool --show-eee eth1
EEE settings for eth1:
enabled - active
250000 (us)
        Supported EEE link modes:  100baseT/Full
                                   1000baseT/Full
        Advertised EEE link modes:  100baseT/Full
                                    1000baseT/Full
        Link partner advertised EEE link modes:  100baseT/Full
                                                 1000baseT/Full

Thanks,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com