mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chris Babroski <cbabroski@nvidia.com>
To: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <bryan.whitehead@microchip.com>, <UNGLinuxDriver@microchip.com>,
	<andrew+netdev@lunn.ch>, <davem@davemloft.net>,
	<edumazet@kernel.org>, <kuba@kernel.org>, <pabeni@redhat.com>,
	<richardcochran@gmail.com>, <linux@armlinux.org.uk>,
	<Raju.Lakkaraju@microchip.com>, <maxime.chevallier@bootlin.com>,
	<yuiko.oshino@microchip.com>, <cbabroski@nvidia.com>,
	<nb@tipi-net.de>, <woojung.huh@microchip.com>
Subject: [PATCH net-next v2 1/7] net: lan743x: check DMA channel stop and reset results
Date: Tue, 24 Nov 2026 09:33:16 -0500	[thread overview]
Message-ID: <b1dc6a8037ab596053cc60c065a9b447982118df.1795027003.git.cbabroski@nvidia.com> (raw)
In-Reply-To: <cover.1795027003.git.cbabroski@nvidia.com>

lan743x_tx_close() and lan743x_rx_close() ask the DMA controller to stop
the channel and wait for it, but ignore the result. If the channel is
still stop-pending when the wait gives up, the descriptor ring, the head
write-back buffer and the packet buffers are unmapped and freed while
the channel may still be fetching from or writing to them.

A TX channel has been seen to stop making progress, with its head index
no longer advancing while DMAC_CMD still reports it as started. A
channel in that state may not honour the stop request either, and
closing the interface would then free memory the engine can still
access.

If a channel is still stop-pending after the wait, or still reads as
started, issue a channel soft reset and wait for it before anything is
freed, and log when that happens. For RX the FIFO is already disabled at
that point. For TX the reset is issued after the TX FIFO has been
disabled, since the TX channel should only be reset once its FIFO is
stopped.

Use the same helpers for the channel resets that lan743x_tx_open() and
lan743x_rx_open() already open-code. If the channel or TX FIFO reset
times out there, log it and fail the open instead of starting a channel
that never came out of reset.

Fixes: 23f0703c125b ("lan743x: Add main source files for new lan743x driver")
Signed-off-by: Chris Babroski <cbabroski@nvidia.com>
---
 drivers/net/ethernet/microchip/lan743x_main.c | 134 ++++++++++++++----
 1 file changed, 107 insertions(+), 27 deletions(-)

diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c
index 82d3ec20ba25..92cdc13495fe 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.c
+++ b/drivers/net/ethernet/microchip/lan743x_main.c
@@ -1584,6 +1584,21 @@ static int lan743x_dmac_tx_wait_till_stopped(struct lan743x_adapter *adapter,
 	return result;
 }
 
+static int lan743x_dmac_tx_reset(struct lan743x_adapter *adapter,
+				 int tx_channel)
+{
+	int ret;
+
+	lan743x_csr_write(adapter, DMAC_CMD, DMAC_CMD_TX_SWR_(tx_channel));
+	ret = lan743x_csr_wait_for_bit(adapter, DMAC_CMD,
+				       DMAC_CMD_TX_SWR_(tx_channel),
+				       0, 1000, 20000, 100);
+	if (ret)
+		netdev_err(adapter->netdev,
+			   "TX channel %d reset timed out\n", tx_channel);
+	return ret;
+}
+
 static int lan743x_dmac_rx_get_state(struct lan743x_adapter *adapter,
 				     int rx_channel)
 {
@@ -1613,6 +1628,21 @@ static int lan743x_dmac_rx_wait_till_stopped(struct lan743x_adapter *adapter,
 	return result;
 }
 
+static int lan743x_dmac_rx_reset(struct lan743x_adapter *adapter,
+				 int rx_channel)
+{
+	int ret;
+
+	lan743x_csr_write(adapter, DMAC_CMD, DMAC_CMD_RX_SWR_(rx_channel));
+	ret = lan743x_csr_wait_for_bit(adapter, DMAC_CMD,
+				       DMAC_CMD_RX_SWR_(rx_channel),
+				       0, 1000, 20000, 100);
+	if (ret)
+		netdev_err(adapter->netdev,
+			   "RX channel %d reset timed out\n", rx_channel);
+	return ret;
+}
+
 static void lan743x_tx_release_desc(struct lan743x_tx *tx,
 				    int descriptor_index, bool cleanup)
 {
@@ -2218,14 +2248,63 @@ static int lan743x_tx_ring_init(struct lan743x_tx *tx)
 	return ret;
 }
 
+static int lan743x_tx_fifo_enable(struct lan743x_tx *tx)
+{
+	struct lan743x_adapter *adapter = tx->adapter;
+	int ret;
+
+	/* initialize fifo */
+	lan743x_csr_write(adapter, FCT_TX_CTL,
+			  FCT_TX_CTL_RESET_(tx->channel_number));
+	ret = lan743x_csr_wait_for_bit(adapter, FCT_TX_CTL,
+				       FCT_TX_CTL_RESET_(tx->channel_number),
+				       0, 1000, 20000, 100);
+	if (ret) {
+		netdev_err(adapter->netdev,
+			   "TX channel %d FIFO reset timed out\n",
+			   tx->channel_number);
+		return ret;
+	}
+
+	/* enable fifo */
+	lan743x_csr_write(adapter, FCT_TX_CTL,
+			  FCT_TX_CTL_EN_(tx->channel_number));
+	return 0;
+}
+
+static int lan743x_tx_fifo_disable(struct lan743x_tx *tx)
+{
+	struct lan743x_adapter *adapter = tx->adapter;
+	int ret;
+
+	lan743x_csr_write(adapter, FCT_TX_CTL,
+			  FCT_TX_CTL_DIS_(tx->channel_number));
+	ret = lan743x_csr_wait_for_bit(adapter, FCT_TX_CTL,
+				       FCT_TX_CTL_EN_(tx->channel_number),
+				       0, 1000, 20000, 100);
+	if (ret)
+		netdev_err(adapter->netdev,
+			   "TX channel %d FIFO disable timed out\n",
+			   tx->channel_number);
+	return ret;
+}
+
 static void lan743x_tx_close(struct lan743x_tx *tx)
 {
 	struct lan743x_adapter *adapter = tx->adapter;
+	bool stop_failed = false;
+	int ret;
 
 	lan743x_csr_write(adapter,
 			  DMAC_CMD,
 			  DMAC_CMD_STOP_T_(tx->channel_number));
-	lan743x_dmac_tx_wait_till_stopped(adapter, tx->channel_number);
+	ret = lan743x_dmac_tx_wait_till_stopped(adapter, tx->channel_number);
+	if (ret < 0 || ret == DMAC_CHANNEL_STATE_STARTED) {
+		stop_failed = true;
+		netdev_warn(adapter->netdev,
+			    "TX channel %d failed to stop, resetting it\n",
+			    tx->channel_number);
+	}
 
 	lan743x_csr_write(adapter,
 			  DMAC_INT_EN_CLR,
@@ -2235,11 +2314,9 @@ static void lan743x_tx_close(struct lan743x_tx *tx)
 	napi_disable(&tx->napi);
 	netif_napi_del(&tx->napi);
 
-	lan743x_csr_write(adapter, FCT_TX_CTL,
-			  FCT_TX_CTL_DIS_(tx->channel_number));
-	lan743x_csr_wait_for_bit(adapter, FCT_TX_CTL,
-				 FCT_TX_CTL_EN_(tx->channel_number),
-				 0, 1000, 20000, 100);
+	lan743x_tx_fifo_disable(tx);
+	if (stop_failed)
+		lan743x_dmac_tx_reset(adapter, tx->channel_number);
 
 	lan743x_tx_release_all_descriptors(tx);
 
@@ -2259,23 +2336,14 @@ static int lan743x_tx_open(struct lan743x_tx *tx)
 	if (ret)
 		return ret;
 
-	/* initialize fifo */
-	lan743x_csr_write(adapter, FCT_TX_CTL,
-			  FCT_TX_CTL_RESET_(tx->channel_number));
-	lan743x_csr_wait_for_bit(adapter, FCT_TX_CTL,
-				 FCT_TX_CTL_RESET_(tx->channel_number),
-				 0, 1000, 20000, 100);
-
-	/* enable fifo */
-	lan743x_csr_write(adapter, FCT_TX_CTL,
-			  FCT_TX_CTL_EN_(tx->channel_number));
+	ret = lan743x_tx_fifo_enable(tx);
+	if (ret)
+		goto ring_cleanup;
 
 	/* reset tx channel */
-	lan743x_csr_write(adapter, DMAC_CMD,
-			  DMAC_CMD_TX_SWR_(tx->channel_number));
-	lan743x_csr_wait_for_bit(adapter, DMAC_CMD,
-				 DMAC_CMD_TX_SWR_(tx->channel_number),
-				 0, 1000, 20000, 100);
+	ret = lan743x_dmac_tx_reset(adapter, tx->channel_number);
+	if (ret)
+		goto fifo_disable;
 
 	/* Write TX_BASE_ADDR */
 	lan743x_csr_write(adapter,
@@ -2347,6 +2415,13 @@ static int lan743x_tx_open(struct lan743x_tx *tx)
 	lan743x_csr_write(adapter, DMAC_CMD,
 			  DMAC_CMD_START_T_(tx->channel_number));
 	return 0;
+
+fifo_disable:
+	lan743x_tx_fifo_disable(tx);
+
+ring_cleanup:
+	lan743x_tx_ring_cleanup(tx);
+	return ret;
 }
 
 static int lan743x_rx_next_index(struct lan743x_rx *rx, int index)
@@ -2775,6 +2850,7 @@ static int lan743x_rx_ring_init(struct lan743x_rx *rx)
 static void lan743x_rx_close(struct lan743x_rx *rx)
 {
 	struct lan743x_adapter *adapter = rx->adapter;
+	int ret;
 
 	lan743x_csr_write(adapter, FCT_RX_CTL,
 			  FCT_RX_CTL_DIS_(rx->channel_number));
@@ -2784,7 +2860,13 @@ static void lan743x_rx_close(struct lan743x_rx *rx)
 
 	lan743x_csr_write(adapter, DMAC_CMD,
 			  DMAC_CMD_STOP_R_(rx->channel_number));
-	lan743x_dmac_rx_wait_till_stopped(adapter, rx->channel_number);
+	ret = lan743x_dmac_rx_wait_till_stopped(adapter, rx->channel_number);
+	if (ret < 0 || ret == DMAC_CHANNEL_STATE_STARTED) {
+		netdev_warn(adapter->netdev,
+			    "RX channel %d failed to stop, resetting it\n",
+			    rx->channel_number);
+		lan743x_dmac_rx_reset(adapter, rx->channel_number);
+	}
 
 	lan743x_csr_write(adapter, DMAC_INT_EN_CLR,
 			  DMAC_INT_BIT_RXFRM_(rx->channel_number));
@@ -2810,11 +2892,9 @@ static int lan743x_rx_open(struct lan743x_rx *rx)
 
 	netif_napi_add(adapter->netdev, &rx->napi, lan743x_rx_napi_poll);
 
-	lan743x_csr_write(adapter, DMAC_CMD,
-			  DMAC_CMD_RX_SWR_(rx->channel_number));
-	lan743x_csr_wait_for_bit(adapter, DMAC_CMD,
-				 DMAC_CMD_RX_SWR_(rx->channel_number),
-				 0, 1000, 20000, 100);
+	ret = lan743x_dmac_rx_reset(adapter, rx->channel_number);
+	if (ret)
+		goto napi_delete;
 
 	/* set ring base address */
 	lan743x_csr_write(adapter,
-- 
2.34.1


  reply	other threads:[~2026-11-24 14:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 14:33 [PATCH net-next v2 0/7] net: lan743x: automatically recover from TX hang Chris Babroski
2026-11-24 14:33 ` Chris Babroski [this message]
2026-11-24 14:33 ` [PATCH net-next v2 2/7] net: lan743x: quiesce TX before freeing the rings Chris Babroski
2026-11-24 14:33 ` [PATCH net-next v2 3/7] net: lan743x: start phylink last and stop it first Chris Babroski
2026-11-24 14:33 ` [PATCH net-next v2 4/7] net: lan743x: keep the fixed link across reopen Chris Babroski
2026-11-24 14:33 ` [PATCH net-next v2 5/7] net: lan743x: handle a failed reopen on resume Chris Babroski
2026-11-24 14:33 ` [PATCH net-next v2 6/7] net: lan743x: reset the device on TX timeout Chris Babroski
2026-11-24 14:33 ` [PATCH net-next v2 7/7] net: lan743x: add byte queue limits support Chris Babroski

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=b1dc6a8037ab596053cc60c065a9b447982118df.1795027003.git.cbabroski@nvidia.com \
    --to=cbabroski@nvidia.com \
    --cc=Raju.Lakkaraju@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=bryan.whitehead@microchip.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=maxime.chevallier@bootlin.com \
    --cc=nb@tipi-net.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=woojung.huh@microchip.com \
    --cc=yuiko.oshino@microchip.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

all inboxes | Powered by JetHome®