From: Raju Rangoju <Raju.Rangoju@amd.com>
To: <netdev@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <pabeni@redhat.com>,
<kuba@kernel.org>, <edumazet@google.com>, <davem@davemloft.net>,
<andrew+netdev@lunn.ch>, "Raju Rangoju" <Raju.Rangoju@amd.com>
Subject: [PATCH v2 net-next 2/3] amd-xgbe: optimize TX shutdown on link-down
Date: Wed, 18 Mar 2026 17:40:05 +0530 [thread overview]
Message-ID: <20260318121006.1565435-3-Raju.Rangoju@amd.com> (raw)
In-Reply-To: <20260318121006.1565435-1-Raju.Rangoju@amd.com>
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 <Raju.Rangoju@amd.com>
---
drivers/net/ethernet/amd/xgbe/xgbe-dev.c | 9 +++++++++
drivers/net/ethernet/amd/xgbe/xgbe-mdio.c | 18 ++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
index f1357619097e..b7bf74c6bb47 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 7675bb98f029..fa0df6181207 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))
--
2.34.1
next prev parent reply other threads:[~2026-03-18 12:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-18 12:10 [PATCH v2 net-next 0/3] amd-xgbe: TX resilience improvements for link-down handling Raju Rangoju
2026-03-18 12:10 ` [PATCH v2 net-next 1/3] amd-xgbe: add adaptive link status polling Raju Rangoju
2026-03-18 12:10 ` Raju Rangoju [this message]
2026-03-18 12:10 ` [PATCH v2 net-next 3/3] amd-xgbe: add TX descriptor cleanup for link-down Raju Rangoju
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260318121006.1565435-3-Raju.Rangoju@amd.com \
--to=raju.rangoju@amd.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox