Skip to contentSkip to conversation

amd-xgbe: TX resilience improvements for link-down handling

PATCH Applied Raju Rangoju 2 participants 5 messages Mar 19 – Mar 24

Subsystems (3)
lore
Share & tools
lore

Raju Rangoju

author maintainer
#0 lore raw

v3 cover amd-xgbe: TX resilience improvements for link-down handling

This series enhances the AMD 10GbE driver's TX queue handling during link-down events to improve resilience, prevent resource leaks, and enable fast failover in link aggregation configurations.

The three patches form a complete link-down handling solution:

1. Patch 1: Fast detection (know quickly when link goes down)
2. Patch 2: Quick response (stop TX immediately, skip waits)
3. Patch 3: Clean recovery (reclaim abandoned resources)

Changes since v2:
- remove the stale function xgbe_reset_tx_queues(), otherwise it would result in undefined symbol during linking.

Changes since v1:
- The original patch is split into multiple patches, to better isolate each specific improvements.

Raju Rangoju (3):
amd-xgbe: add adaptive link status polling
amd-xgbe: optimize TX shutdown on link-down
amd-xgbe: add TX descriptor cleanup for link-down

 drivers/net/ethernet/amd/xgbe/xgbe-common.h |  4 +
 drivers/net/ethernet/amd/xgbe/xgbe-dev.c    | 86 ++++++++++++++++++---
 drivers/net/ethernet/amd/xgbe/xgbe-drv.c    | 67 ++++++++++++++--
 drivers/net/ethernet/amd/xgbe/xgbe-mdio.c   | 18 +++++
 4 files changed, 158 insertions(+), 17 deletions(-)
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v3 1/3 amd-xgbe: add adaptive link status polling

Implement adaptive link status polling to enable fast link-down detection while conserving CPU resources during link-down periods.

Currently, the driver polls link status at a fixed 1-second interval regardless of link state. This creates a trade-off:
- Slow polling (1s): Misses rapid link state changes, causing delays
- Fast polling: Wastes CPU when link is stable or down

This enhancement introduces state-aware polling:

When carrier is UP:
Poll every 100ms to enable rapid link-down detection. This provides ~100-200ms response time to link failures, minimizing packet loss and enabling fast failover in link aggregation configurations.

When carrier is DOWN:
Poll every 1s to conserve CPU resources. Link-up detection is less time-critical since no traffic is flowing.

Performance impact:
- Link-down detection: 1000ms → 100-200ms (10x improvement)
- CPU overhead when link up: 0.1% → 1% (acceptable for active links)
- CPU overhead when link down: unchanged at 0.1%

This is particularly valuable for:
- Link aggregation deployments requiring sub-second failover
- Environments with flaky links or cable issues
- Applications sensitive to connection recovery time

---
 drivers/net/ethernet/amd/xgbe/xgbe-drv.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
drivers/net/ethernet/amd/xgbe/xgbe-drv.c +23 -1
index 2f39f38fecf9..6886d3b33ffe 100644
@@ -607,11 +607,33 @@ static void xgbe_service_timer(struct timer_list *t)
 	struct xgbe_prv_data *pdata = timer_container_of(pdata, t,
 							 service_timer);
 	struct xgbe_channel *channel;
+	unsigned int poll_interval;
 	unsigned int i;
 
 	queue_work(pdata->dev_workqueue, &pdata->service_work);
 
-	mod_timer(&pdata->service_timer, jiffies + HZ);
+	/* Adaptive link status polling for fast failure detection:
+	 *
+	 * - When carrier is UP: poll every 100ms for rapid link-down detection
+	 *   Enables sub-second response to link failures, minimizing traffic
+	 *   loss.
+	 *
+	 * - When carrier is DOWN: poll every 1s to conserve CPU resources
+	 *   Link-up events are less time-critical.
+	 *
+	 * The 100ms active polling interval balances responsiveness with
+	 * efficiency:
+	 * - Provides ~100-200ms link-down detection (10x faster than 1s
+	 *   polling)
+	 * - Minimal CPU overhead (1% vs 0.1% with 1s polling)
+	 * - Enables fast failover in link aggregation deployments
+	 */
+	if (netif_running(pdata->netdev) && netif_carrier_ok(pdata->netdev))
+		poll_interval = msecs_to_jiffies(100);  /* 100ms when up */
+	else
+		poll_interval = HZ;  /* 1 second when down */
+
+	mod_timer(&pdata->service_timer, jiffies + poll_interval);
 
 	if (!pdata->tx_usecs)
 		return;
Signature · 1 line
2.34.1
author maintainer
#2 lore raw

PATCH v3 2/3 amd-xgbe: optimize TX shutdown on link-down

In reply to Raju Rangoju

Optimize the TX shutdown sequence when link goes down by skipping futile hardware wait operations and immediately stopping TX queues.

Current behavior creates delays and resource issues during link-down:

1. xgbe_txq_prepare_tx_stop() waits up to XGBE_DMA_STOP_TIMEOUT for TX queues to drain, but when link is down, hardware will never complete the pending descriptors. This causes unnecessary delays during interface shutdown.

2. TX queues remain active after link-down, allowing the network stack to continue queuing packets that cannot be transmitted. This leads to resource buildup and complicates recovery.

This patch adds two optimizations:

Optimization 1: Skip TX queue drain when link is down
In xgbe_txq_prepare_tx_stop(), detect link-down state and return immediately instead of waiting for hardware. Abandoned descriptors will be cleaned up by the force-cleanup mechanism (next patch).

Optimization 2: Immediate TX queue stop on link-down
In xgbe_phy_adjust_link(), call netif_tx_stop_all_queues() as soon as link-down is detected. Also wake TX queues on link-up to resume transmission.

Benefits:
- Faster interface shutdown (no pointless timeout waits)
- Prevents packet queue buildup in network stack
- Cleaner state management during link transitions
- Enables orderly descriptor cleanup by NAPI poll

Note: We do not call netdev_tx_reset_queue() on link-down because NAPI poll may still be running, which would trigger BQL assertions. BQL state is cleaned up naturally during descriptor reclamation.

---
 drivers/net/ethernet/amd/xgbe/xgbe-dev.c  |  9 +++++++++
 drivers/net/ethernet/amd/xgbe/xgbe-mdio.c | 18 ++++++++++++++++++
 2 files changed, 27 insertions(+)
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +9 -0
index f1357619097e..b7bf74c6bb47 100644
@@ -3186,7 +3186,16 @@ static void xgbe_txq_prepare_tx_stop(struct xgbe_prv_data *pdata,
 	/* The Tx engine cannot be stopped if it is actively processing
 	 * packets. Wait for the Tx queue to empty the Tx fifo.  Don't
 	 * wait forever though...
+	 *
+	 * Optimization: Skip the wait when link is down. Hardware won't
+	 * complete TX processing, so waiting serves no purpose and only
+	 * delays interface shutdown. Descriptors will be reclaimed via
+	 * the force-cleanup path in tx_poll.
 	 */
+
+	if (!pdata->phy.link)
+		return;
+
 	tx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ);
 	while (time_before(jiffies, tx_timeout)) {
 		tx_status = XGMAC_MTL_IOREAD(pdata, queue, MTL_Q_TQDR);
drivers/net/ethernet/amd/xgbe/xgbe-mdio.c +18 -0
index 7675bb98f029..fa0df6181207 100644
@@ -1047,11 +1047,29 @@ static void xgbe_phy_adjust_link(struct xgbe_prv_data *pdata)
 		if (pdata->phy_link != pdata->phy.link) {
 			new_state = 1;
 			pdata->phy_link = pdata->phy.link;
+
+			/* Link is coming up - wake TX queues */
+			netif_tx_wake_all_queues(pdata->netdev);
 		}
 	} else if (pdata->phy_link) {
 		new_state = 1;
 		pdata->phy_link = 0;
 		pdata->phy_speed = SPEED_UNKNOWN;
+
+		/* Proactive TX queue management on link-down.
+		 *
+		 * Immediately stop TX queues to enable clean link-down
+		 * handling:
+		 * - Prevents queueing packets that can't be transmitted
+		 * - Allows orderly descriptor cleanup by NAPI poll
+		 * - Enables rapid failover in link aggregation configurations
+		 *
+		 * Note: We do NOT call netdev_tx_reset_queue() here because
+		 * NAPI poll may still be running and would trigger BQL
+		 * assertion. BQL state is cleaned up naturally during
+		 * descriptor reclamation.
+		 */
+		netif_tx_stop_all_queues(pdata->netdev);
 	}
 
 	if (new_state && netif_msg_link(pdata))
Signature · 1 line
2.34.1
author maintainer
#3 lore raw

PATCH v3 3/3 amd-xgbe: add TX descriptor cleanup for link-down

In reply to Raju Rangoju

Add intelligent TX descriptor cleanup mechanism to reclaim abandoned descriptors when the physical link goes down.

When the link goes down while TX packets are in-flight, the hardware stops processing descriptors with the OWN bit still set. The current driver waits indefinitely for these descriptors to complete, which never happens. This causes:

- TX ring exhaustion (no descriptors available for new packets)
- Memory leaks (skbs never freed)
- DMA mapping leaks (mappings never unmapped)
- Network stack backpressure buildup

Add force-cleanup mechanism in xgbe_tx_poll() that detects link-down state and reclaims abandoned descriptors. The helper functions and DMA optimizations support efficient TX shutdown:
- xgbe_wait_for_dma_tx_complete(): Wait for DMA completion with link-down optimization
- Restructure xgbe_disable_tx() for proper shutdown sequence

Implementation:
1. Check link state at the start of tx_poll
2. If link is down, set force_cleanup flag
3. For descriptors that hardware hasn't completed (!tx_complete):
- If force_cleanup: treat as completed and reclaim resources
- If link up: break and wait for hardware (normal behavior)

The cleanup process:
- Frees skbs that will never be transmitted
- Unmaps DMA mappings
- Resets descriptors for reuse
- Does NOT count as successful transmission (correct statistics)

Benefits:
- Prevents TX ring starvation
- Eliminates memory and DMA mapping leaks
- Enables fast link recovery when link comes back up
- Critical for link aggregation failover scenarios

---
Changes since v2:
- remove the stale function xgbe_reset_tx_queues(), otherwise it would result in undefined symbol during linking.

 drivers/net/ethernet/amd/xgbe/xgbe-common.h |  4 ++
 drivers/net/ethernet/amd/xgbe/xgbe-dev.c    | 77 ++++++++++++++++++---
 drivers/net/ethernet/amd/xgbe/xgbe-drv.c    | 43 ++++++++++--
 3 files changed, 108 insertions(+), 16 deletions(-)
drivers/net/ethernet/amd/xgbe/xgbe-common.h +4 -0
index c17900a49595..66807d67e984 100644
@@ -330,6 +330,10 @@
 #define MAC_ISR_SMI_WIDTH		1
 #define MAC_ISR_TSIS_INDEX		12
 #define MAC_ISR_TSIS_WIDTH		1
+#define MAC_ISR_LS_INDEX		24
+#define MAC_ISR_LS_WIDTH		2
+#define MAC_ISR_LSI_INDEX		0
+#define MAC_ISR_LSI_WIDTH		1
 #define MAC_MACA1HR_AE_INDEX		31
 #define MAC_MACA1HR_AE_WIDTH		1
 #define MAC_MDIOIER_SNGLCOMPIE_INDEX	12
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +66 -11

94 lines not on this page · raw message

drivers/net/ethernet/amd/xgbe/xgbe-drv.c +38 -5

66 lines not on this page · raw message

Signature · 1 line
2.34.1
#4 lore raw
In reply to Raju Rangoju
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Quoted 11 lines · On Thu, 19 Mar 2026 22:02:48 +0530 you wrote:

This series enhances the AMD 10GbE driver's TX queue handling during link-down events to improve resilience, prevent resource leaks, and enable fast failover in link aggregation configurations.

The three patches form a complete link-down handling solution:

1. Patch 1: Fast detection (know quickly when link goes down)
2. Patch 2: Quick response (stop TX immediately, skip waits)
3. Patch 3: Clean recovery (reclaim abandoned resources)

[...]

Here is the summary with links:
- [v3,net-next,1/3] amd-xgbe: add adaptive link status polling

    https://git.kernel.org/netdev/net-next/c/31b2d4e00260
  - [v3,net-next,2/3] amd-xgbe: optimize TX shutdown on link-down
    https://git.kernel.org/netdev/net-next/c/0898849ad971
  - [v3,net-next,3/3] amd-xgbe: add TX descriptor cleanup for link-down
    https://git.kernel.org/netdev/net-next/c/b7fb3677840d

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html