Skip to contentSkip to conversation

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

PATCH Superseded Nicolai Buchwitz 2 participants 8 messages Feb 24

Subsystems (3)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 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 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      |  21 ++++
 drivers/net/ethernet/cadence/macb_main.c | 135 ++++++++++++++++++++++-
 2 files changed, 155 insertions(+), 1 deletion(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH v2 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
#2 lore raw

PATCH v2 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
#3 lore raw

PATCH v2 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      |   6 ++
 drivers/net/ethernet/cadence/macb_main.c | 110 +++++++++++++++++++++++
 2 files changed, 116 insertions(+)
drivers/net/ethernet/cadence/macb.h +6 -0
index e3520e5aec67..a17e537cdeb6 100644
@@ -1372,6 +1372,12 @@ struct macb {
 
 	struct work_struct	hresp_err_bh_work;
 
+	/* EEE / LPI state */
+	bool			eee_active;
+	bool			tx_lpi_enabled;
+	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 +110 -0

164 lines not on this page · raw message

Signature · 1 line
2.51.0
#4 lore raw

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

Quoted 17 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.

Quoted 3 lines

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.

Much better, thanks. One suggestion:

Quoted 1 line

+static void macb_tx_lpi_set(struct macb *bp, bool enable)

bool return type.

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

Quoted 3 lines
drivers/net/ethernet/cadence/macb_main.c +3 -0
+{
+	unsigned long flags;
+	u32 ncr;
	u32 old, ncr;

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

Quoted 3 lines
drivers/net/ethernet/cadence/macb_main.c +3 -0
+
+	spin_lock_irqsave(&bp->lock, flags);
+	ncr = macb_readl(bp, NCR);
	old = ncr;

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

Quoted 4 lines
drivers/net/ethernet/cadence/macb_main.c +4 -0
+	if (enable)
+		ncr |= GEM_BIT(TXLPIEN);
+	else
+		ncr &= ~GEM_BIT(TXLPIEN);
	if (old != ncr)

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

Quoted 2 lines
drivers/net/ethernet/cadence/macb_main.c +2 -0
+	macb_writel(bp, NCR, ncr);
+	bp->tx_lpi_enabled = enable;

No need for tx_lpi_enabled

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

Quoted 1 line
drivers/net/ethernet/cadence/macb_main.c +1 -0
+	spin_unlock_irqrestore(&bp->lock, flags);
	return old != ncr;
Quoted 1 line

+}

...

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

Quoted 9 lines
drivers/net/ethernet/cadence/macb_main.c +9 -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 (!bp->tx_lpi_enabled)
+		return;

No need for this if().

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	macb_tx_lpi_set(bp, false);

instead:

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

The presence of the spinlock in macb_tx_lpi_set() suggests that there could be races, so keeping the state completely inside the spinlock region would be sensible.

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

Quoted 1 line
drivers/net/ethernet/cadence/macb_main.c +1 -0
+	cancel_delayed_work(&bp->tx_lpi_work);

I wonder whether this is reliable on its own. cancel_delayed_work() documentation says:

* Note:
* The work callback function may still be running on return, unless
* it returns %true and the work doesn't re-arm itself. Explicitly flush or
* use cancel_delayed_work_sync() to wait on it.

That means macb_tx_lpi_work_fn() could have just been entered at the point that cancel_delayed_work() has been called. Would that cause a problem, e.g. setting LPI mode again, or would we be guaranteed that macb_tx_all_queues_idle() returns false preventing LPI mode being set again?

Thanks.

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

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

Quoted 19 lines · Russell King (Oracle)
Quoted 18 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.

Quoted 5 lines
Quoted 3 lines

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.

Much better, thanks. One suggestion:

Thanks for the quick feedback! I will address this in a v3 of this series.

Quoted 70 lines
Quoted 2 lines

+static void macb_tx_lpi_set(struct macb *bp, bool enable)

bool return type.

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

Quoted 3 lines
drivers/net/ethernet/cadence/macb_main.c +3 -0
+{
+	unsigned long flags;
+	u32 ncr;
	u32 old, ncr;

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

Quoted 3 lines
drivers/net/ethernet/cadence/macb_main.c +3 -0
+
+	spin_lock_irqsave(&bp->lock, flags);
+	ncr = macb_readl(bp, NCR);
	old = ncr;

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

Quoted 4 lines
drivers/net/ethernet/cadence/macb_main.c +4 -0
+	if (enable)
+		ncr |= GEM_BIT(TXLPIEN);
+	else
+		ncr &= ~GEM_BIT(TXLPIEN);
	if (old != ncr)

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

Quoted 2 lines
drivers/net/ethernet/cadence/macb_main.c +2 -0
+	macb_writel(bp, NCR, ncr);
+	bp->tx_lpi_enabled = enable;

No need for tx_lpi_enabled

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

Quoted 1 line
drivers/net/ethernet/cadence/macb_main.c +1 -0
+	spin_unlock_irqrestore(&bp->lock, flags);
	return old != ncr;
Quoted 1 line

+}

...

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

Quoted 9 lines
drivers/net/ethernet/cadence/macb_main.c +9 -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 (!bp->tx_lpi_enabled)
+		return;

No need for this if().

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	macb_tx_lpi_set(bp, false);

instead:

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

The presence of the spinlock in macb_tx_lpi_set() suggests that there could be races, so keeping the state completely inside the spinlock region would be sensible.

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

Quoted 1 line
drivers/net/ethernet/cadence/macb_main.c +1 -0
+	cancel_delayed_work(&bp->tx_lpi_work);

I wonder whether this is reliable on its own. cancel_delayed_work() documentation says:

* Note:
* The work callback function may still be running on return, unless
* it returns %true and the work doesn't re-arm itself. Explicitly
flush or
* use cancel_delayed_work_sync() to wait on it.

Quoted 5 lines

That means macb_tx_lpi_work_fn() could have just been entered at the point that cancel_delayed_work() has been called. Would that cause a problem, e.g. setting LPI mode again, or would we be guaranteed that macb_tx_all_queues_idle() returns false preventing LPI mode being set again?

AFAIK, the race shouldn't be an issue here because macb_tx_lpi_wake() is called from macb_start_xmit() after the TX descriptors have been written and tx_head has been advanced (there's a wmb() before the call to ensure visibility). So if macb_tx_lpi_work_fn() happens to be running concurrently, macb_tx_all_queues_idle() will see tx_head != tx_tail and return false, preventing LPI from being re-enabled.

Quoted 2 lines

Thanks.

Nicolai

#6 lore raw

PATCH v2 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 fb64a97725b1..87097100b88c 100644
@@ -4032,6 +4032,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,
@@ -4053,6 +4073,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
#7 lore raw

PATCH v2 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 87097100b88c..2bf27a266e16 100644
@@ -5516,7 +5516,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