net: cadence: macb: add IEEE 802.3az EEE support
Subsystems (3)
cover net: cadence: macb: add IEEE 802.3az EEE support
Add Energy Efficient Ethernet (IEEE 802.3az) support to the Cadence GEM (macb) driver. 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, as recommended by Microchip's GMAC documentation.
The series is structured as follows:
1. Register definitions: LPI counter offsets (0x270-0x27c), TXLPIEN bitfield (NCR bit 19), and a 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: A delayed_work-based idle timer that enters LPI after 250ms of TX inactivity and wakes before transmit with a conservative 50us PHY wake delay. LPI entry is deferred 1 second after link-up per IEEE 802.3az.
4. ethtool EEE ops: get_eee/set_eee delegating to phylink for PHY negotiation; the MAC-level TXLPIEN is controlled only from the phylink mac_link_up/mac_link_down callbacks.
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 with iperf3 throughput/latency benchmarks, ethtool --show-eee / --set-eee, ethtool -S LPI counter verification, 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 | 23 ++++ drivers/net/ethernet/cadence/macb_main.c | 160 ++++++++++++++++++++++- 2 files changed, 180 insertions(+), 3 deletions(-)
Signature · 1 line
2.39.5
PATCH 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 | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/net/ethernet/cadence/macb.h +9 -0
@@ -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/* EEE RX LPI Transitions */ +#define GEM_RXLPITIME 0x0274/* EEE RX LPI Time */ +#define GEM_TXLPI 0x0278/* EEE TX LPI Transitions */ +#define GEM_TXLPITIME 0x027c/* EEE TX LPI Time */ #define GEM_DCFG1 0x0280/* Design Config 1 */ #define GEM_DCFG2 0x0284/* Design Config 2 */ #define GEM_DCFG3 0x0288/* Design Config 3 */
@@ -264,6 +268,10 @@#define MACB_MIIONRGMII_OFFSET 28/* MII Usage on RGMII Interface */ #define MACB_MIIONRGMII_SIZE 1 +/* GEM specific NCR bitfields. */ +#define GEM_TXLPIEN_OFFSET 19/* TX LPI Enable */ +#define GEM_TXLPIEN_SIZE 1 +/* Bitfields in NCFGR */ #define MACB_SPD_OFFSET 0/* Speed */ #define MACB_SPD_SIZE 1
@@ -779,6 +787,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.39.5
PATCH 2/5 net: cadence: macb: add EEE LPI statistics counters
In reply to Nicolai BuchwitzExpose 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
@@ -1052,6 +1052,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
@@ -1151,6 +1155,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.39.5
PATCH 3/5 net: cadence: macb: implement EEE TX LPI support
In reply to Nicolai BuchwitzImplement software-managed TX Low Power Idle (LPI) for the Cadence GEM MAC as part of IEEE 802.3az Energy Efficient Ethernet support.
The GEM MAC has no built-in idle timer - the TXLPIEN bit (NCR bit 19) immediately asserts LPI and blocks all TX while set. The MAC does not auto-wake for transmit. Per Microchip GMAC documentation (section 40.6.19): "It is best to use firmware to control LPI."
This patch implements a software idle timer using delayed_work:
- On TX completion with an empty ring, schedule LPI entry after a configurable idle timeout (default 250ms). The work function verifies all TX queues are truly idle before entering LPI to prevent entering LPI while traffic is still active.
- On TX start, wake from LPI by clearing TXLPIEN, cancelling any pending re-entry, and waiting 50us for the PHY to exit LPI (conservative vs IEEE 802.3az Tw_sys of ~17us/~30us)
- On link up, check EEE negotiation via phy_init_eee() and defer first LPI entry by 1 second per IEEE 802.3az requirements
- On link down, immediately cancel pending work and clear TXLPIEN
The timer value is configurable at runtime via ethtool --set-eee tx-timer.
The implementation is gated on MACB_CAPS_EEE so platforms must explicitly opt in via their macb_config.
--- drivers/net/ethernet/cadence/macb.h | 6 ++ drivers/net/ethernet/cadence/macb_main.c | 120 ++++++++++++++++++++++- 2 files changed, 124 insertions(+), 2 deletions(-)
drivers/net/ethernet/cadence/macb.h +6 -0
@@ -1358,6 +1358,12 @@ struct macb {struct macb_ptp_info *ptp_info;/* macb-ptp interface */ +/* EEE / LPI state */ +bool eee_active; +bool tx_lpi_enabled; +struct delayed_work tx_lpi_work; +unsigned int tx_lpi_timer_ms;/* idle timeout before LPI */ +struct phy *phy;spinlock_t tsu_clk_lock;/* gem tsu clock locking */
drivers/net/ethernet/cadence/macb_main.c +118 -2
176 lines not on this page · raw message
Signature · 1 line
2.39.5
Re: [PATCH net-next 3/5] net: cadence: macb: implement EEE TX LPI support
Quoted 20 lines · Nicolai Buchwitz
Implement software-managed TX Low Power Idle (LPI) for the Cadence GEM MAC as part of IEEE 802.3az Energy Efficient Ethernet support.
The GEM MAC has no built-in idle timer - the TXLPIEN bit (NCR bit 19) immediately asserts LPI and blocks all TX while set. The MAC does not auto-wake for transmit. Per Microchip GMAC documentation (section 40.6.19): "It is best to use firmware to control LPI."
This patch implements a software idle timer using
delayed_work:
- On TX completion with an empty ring, schedule LPI entry after a configurable idle timeout (default 250ms). The work function verifies all TX queues are truly idle before entering LPI to prevent entering LPI while traffic is still active.
- On TX start, wake from LPI by clearing TXLPIEN, cancelling any pending re-entry, and waiting 50us for the PHY to exit LPI (conservative vs IEEE 802.3azTw_sysof ~17us/~30us)
- On link up, check EEE negotiation viaphy_init_eee()and defer first LPI entry by 1 second per IEEE 802.3az requirements
- On link down, immediately cancel pending work and clear TXLPIEN
Quoted 5 lines
The timer value is configurable at runtime via ethtool --set-eee tx-timer.
The implementation is gated on
MACB_CAPS_EEEso platforms must explicitly opt in via theirmacb_config.
In addition to my comments, please check the nipabot status for this patch which can be found at:
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
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!
Re: [PATCH net-next 3/5] net: cadence: macb: implement EEE TX LPI support
Quoted 24 lines · Russell King (Oracle)
Quoted 23 lines · Nicolai Buchwitz
Implement software-managed TX Low Power Idle (LPI) for the Cadence GEM MAC as part of IEEE 802.3az Energy Efficient Ethernet support.
The GEM MAC has no built-in idle timer - the TXLPIEN bit (NCR bit 19) immediately asserts LPI and blocks all TX while set. The MAC does not auto-wake for transmit. Per Microchip GMAC documentation (section 40.6.19): "It is best to use firmware to control LPI."
This patch implements a software idle timer using
delayed_work:
- On TX completion with an empty ring, schedule LPI entry after a configurable idle timeout (default 250ms). The work function verifies all TX queues are truly idle before entering LPI to prevent entering LPI while traffic is still active.
- On TX start, wake from LPI by clearing TXLPIEN, cancelling any pending re-entry, and waiting 50us for the PHY to exit LPI (conservative vs IEEE 802.3azTw_sysof ~17us/~30us)
- On link up, check EEE negotiation viaphy_init_eee()and defer first LPI entry by 1 second per IEEE 802.3az requirements
- On link down, immediately cancel pending work and clear TXLPIENThe timer value is configurable at runtime via ethtool --set-eee tx-timer.
Quoted 8 lines
Quoted 2 lines
The implementation is gated on
MACB_CAPS_EEEso platforms must explicitly opt in via theirmacb_config.In addition to my comments, please check the nipabot status for this patch which can be found at:
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Thanks. I will have a look at the mentioned patches + feedback from the pipeline and prepare a v2 of this series.
Quoted 1 line
Thanks.
Nicolai
PATCH 4/5 net: cadence: macb: add ethtool EEE support
In reply to Nicolai BuchwitzImplement 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. Instead, phylink_ethtool_set_eee() updates the PHY's EEE advertisement, which triggers link renegotiation. The mac_link_up callback then checks the negotiated EEE state and enables LPI accordingly.
--- drivers/net/ethernet/cadence/macb_main.c | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
drivers/net/ethernet/cadence/macb_main.c +37 -0
@@ -3634,6 +3634,41 @@ static int macb_set_ringparam(struct net_device *netdev,return 0 ; } +static int macb_get_eee (struct net_device *ndev,struct ethtool_keee *edata) +{ +struct macb *bp =netdev_priv (ndev); +int ret; + +if (!(bp->caps &MACB_CAPS_EEE )) +return -EOPNOTSUPP ; + + ret =phylink_ethtool_get_eee (bp->phylink, edata); +if (ret) +return ret; + + edata->tx_lpi_timer = bp->tx_lpi_timer_ms *1000 ; + +return 0 ; +} + +static int macb_set_eee (struct net_device *ndev,struct ethtool_keee *edata) +{ +struct macb *bp =netdev_priv (ndev); + +if (!(bp->caps &MACB_CAPS_EEE )) +return -EOPNOTSUPP ; + +if (edata->tx_lpi_timer) + bp->tx_lpi_timer_ms = edata->tx_lpi_timer /1000 ; + +/* Don't directly control TXLPIEN here. phylink_ethtool_set_eee() +* updates the PHY, which will bounce the link if tx_lpi_enabled +* changes. That triggers mac_link_down/mac_link_up where we +* enable/disable TXLPIEN based on the negotiated state. +*/ +return phylink_ethtool_set_eee (bp->phylink, edata); +} +#ifdef CONFIG_MACB_USE_HWSTAMP static unsigned int gem_get_tsu_rate (struct macb *bp) {
@@ -4058,6 +4093,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.39.5
PATCH 5/5 net: cadence: macb: enable EEE for Raspberry Pi RP1
In reply to Nicolai BuchwitzEnable 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
@@ -5536,7 +5536,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.39.5
Quoted 14 lines · Nicolai Buchwitz
Add Energy Efficient Ethernet (IEEE 802.3az) support to the Cadence GEM (macb) driver. The GEM MAC has hardware LPI registers but no built-in idle timer, so the driver implements software-managed TX LPI using a
delayed_worktimer, as recommended by Microchip's GMAC documentation.The series is structured as follows:
1. Register definitions: LPI counter offsets (0x270-0x27c), TXLPIEN bitfield (NCR bit 19), and a
MACB_CAPS_EEEcapability 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.
Quoted 8 lines
3. TX LPI engine: A delayed_work-based idle timer that enters LPI after 250ms of TX inactivity and wakes before transmit with a conservative 50us PHY wake delay. LPI entry is deferred 1 second after link-up per IEEE 802.3az.
4. ethtool EEE ops: get_eee/set_eee delegating to phylink for PHY negotiation; the MAC-level TXLPIEN is controlled only from the phylink mac_link_up/mac_link_down callbacks.
This needs a rewrite - phylink has EEE support now, with new callbacks and configuration. There is no need to use the obsolete (and incorrect) phy_init_eee() anymore.
Please see:
e9f03a6a879b net: phylink: add support for notifying PCS about EEE
and
03abf2a7c654 net: phylink: add EEE management
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!