Commit 0898849a authored by Raju Rangoju's avatar Raju Rangoju Committed by Paolo Abeni
Browse files

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: default avatarRaju Rangoju <Raju.Rangoju@amd.com>
Link: https://patch.msgid.link/20260319163251.1808611-3-Raju.Rangoju@amd.com


Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent 31b2d4e0
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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);
+18 −0
Original line number Diff line number Diff line
@@ -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))