From: Raju Rangoju Date: Thu, 19 Mar 2026 16:32:50 +0000 (+0530) Subject: amd-xgbe: optimize TX shutdown on link-down X-Git-Tag: v7.1-rc1~173^2~187^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0898849ad9715d163555b8f8bfd13b7691a2b3b8;p=thirdparty%2Fkernel%2Flinux.git amd-xgbe: optimize TX shutdown on link-down 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. Signed-off-by: Raju Rangoju Link: https://patch.msgid.link/20260319163251.1808611-3-Raju.Rangoju@amd.com Signed-off-by: Paolo Abeni --- diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c index f1357619097ea..b7bf74c6bb47b 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c @@ -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); diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c index 7675bb98f0295..fa0df61812076 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c +++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c @@ -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))