netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tom Lendacky <thomas.lendacky@amd.com>
To: <netdev@vger.kernel.org>
Cc: Florian Fainelli <f.fainelli@gmail.com>,
	David Miller <davem@davemloft.net>
Subject: [PATCH net-next v1 09/21] amd-xgbe: Update how to determine DMA channel status
Date: Thu, 3 Nov 2016 08:29:14 -0500	[thread overview]
Message-ID: <20161103132914.3437.27657.stgit@tlendack-t1.amdoffice.net> (raw)
In-Reply-To: <20161103132744.3437.27332.stgit@tlendack-t1.amdoffice.net>

Tx and Rx DMA channel status determiniation is different depending on the
version of the hardware. Update the channel status processing code to
account for the change.  Also, reduce the timeout value used when stopping
the channels.

Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
---
 drivers/net/ethernet/amd/xgbe/xgbe-common.h |    4 ++
 drivers/net/ethernet/amd/xgbe/xgbe-dev.c    |   58 ++++++++++++++++++---------
 drivers/net/ethernet/amd/xgbe/xgbe.h        |    2 -
 3 files changed, 43 insertions(+), 21 deletions(-)

diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
index 6c40915..8036ee5 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
@@ -790,6 +790,10 @@
 #define MTL_Q_RQOMR_RSF_WIDTH		1
 #define MTL_Q_RQOMR_RTC_INDEX		0
 #define MTL_Q_RQOMR_RTC_WIDTH		2
+#define MTL_Q_TQDR_TRCSTS_INDEX		1
+#define MTL_Q_TQDR_TRCSTS_WIDTH		2
+#define MTL_Q_TQDR_TXQSTS_INDEX		4
+#define MTL_Q_TQDR_TXQSTS_WIDTH		1
 #define MTL_Q_TQOMR_FTQ_INDEX		0
 #define MTL_Q_TQOMR_FTQ_WIDTH		1
 #define MTL_Q_TQOMR_Q2TCMAP_INDEX	8
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
index 056f38c..89764cb 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
@@ -2946,20 +2946,48 @@ static void xgbe_config_mmc(struct xgbe_prv_data *pdata)
 	XGMAC_IOWRITE_BITS(pdata, MMC_CR, CR, 1);
 }
 
+static void xgbe_txq_prepare_tx_stop(struct xgbe_prv_data *pdata,
+				     unsigned int queue)
+{
+	unsigned int tx_status;
+	unsigned long tx_timeout;
+
+	/* 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...
+	 */
+	tx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ);
+	while (time_before(jiffies, tx_timeout)) {
+		tx_status = XGMAC_MTL_IOREAD(pdata, queue, MTL_Q_TQDR);
+		if ((XGMAC_GET_BITS(tx_status, MTL_Q_TQDR, TRCSTS) != 1) &&
+		    (XGMAC_GET_BITS(tx_status, MTL_Q_TQDR, TXQSTS) == 0))
+			break;
+
+		usleep_range(500, 1000);
+	}
+
+	if (!time_before(jiffies, tx_timeout))
+		netdev_info(pdata->netdev,
+			    "timed out waiting for Tx queue %u to empty\n",
+			    queue);
+}
+
 static void xgbe_prepare_tx_stop(struct xgbe_prv_data *pdata,
-				 struct xgbe_channel *channel)
+				 unsigned int queue)
 {
 	unsigned int tx_dsr, tx_pos, tx_qidx;
 	unsigned int tx_status;
 	unsigned long tx_timeout;
 
+	if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) > 0x20)
+		return xgbe_txq_prepare_tx_stop(pdata, queue);
+
 	/* Calculate the status register to read and the position within */
-	if (channel->queue_index < DMA_DSRX_FIRST_QUEUE) {
+	if (queue < DMA_DSRX_FIRST_QUEUE) {
 		tx_dsr = DMA_DSR0;
-		tx_pos = (channel->queue_index * DMA_DSR_Q_WIDTH) +
-			 DMA_DSR0_TPS_START;
+		tx_pos = (queue * DMA_DSR_Q_WIDTH) + DMA_DSR0_TPS_START;
 	} else {
-		tx_qidx = channel->queue_index - DMA_DSRX_FIRST_QUEUE;
+		tx_qidx = queue - DMA_DSRX_FIRST_QUEUE;
 
 		tx_dsr = DMA_DSR1 + ((tx_qidx / DMA_DSRX_QPR) * DMA_DSRX_INC);
 		tx_pos = ((tx_qidx % DMA_DSRX_QPR) * DMA_DSR_Q_WIDTH) +
@@ -2984,7 +3012,7 @@ static void xgbe_prepare_tx_stop(struct xgbe_prv_data *pdata,
 	if (!time_before(jiffies, tx_timeout))
 		netdev_info(pdata->netdev,
 			    "timed out waiting for Tx DMA channel %u to stop\n",
-			    channel->queue_index);
+			    queue);
 }
 
 static void xgbe_enable_tx(struct xgbe_prv_data *pdata)
@@ -3016,13 +3044,8 @@ static void xgbe_disable_tx(struct xgbe_prv_data *pdata)
 	unsigned int i;
 
 	/* Prepare for Tx DMA channel stop */
-	channel = pdata->channel;
-	for (i = 0; i < pdata->channel_count; i++, channel++) {
-		if (!channel->tx_ring)
-			break;
-
-		xgbe_prepare_tx_stop(pdata, channel);
-	}
+	for (i = 0; i < pdata->tx_q_count; i++)
+		xgbe_prepare_tx_stop(pdata, i);
 
 	/* Disable MAC Tx */
 	XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
@@ -3146,13 +3169,8 @@ static void xgbe_powerdown_tx(struct xgbe_prv_data *pdata)
 	unsigned int i;
 
 	/* Prepare for Tx DMA channel stop */
-	channel = pdata->channel;
-	for (i = 0; i < pdata->channel_count; i++, channel++) {
-		if (!channel->tx_ring)
-			break;
-
-		xgbe_prepare_tx_stop(pdata, channel);
-	}
+	for (i = 0; i < pdata->tx_q_count; i++)
+		xgbe_prepare_tx_stop(pdata, i);
 
 	/* Disable MAC Tx */
 	XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
index 7cbf91b..d5cae15 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe.h
+++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
@@ -159,7 +159,7 @@
 #define XGBE_MAX_DMA_CHANNELS	16
 #define XGBE_MAX_QUEUES		16
 #define XGBE_PRIORITY_QUEUES	8
-#define XGBE_DMA_STOP_TIMEOUT	5
+#define XGBE_DMA_STOP_TIMEOUT	1
 
 /* DMA cache settings - Outer sharable, write-back, write-allocate */
 #define XGBE_DMA_OS_AXDOMAIN	0x2

  parent reply	other threads:[~2016-11-03 13:43 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-03 13:27 [PATCH net-next v1 00/21] amd-xgbe: AMD XGBE driver updates 2016-11-01 Tom Lendacky
2016-11-03 13:27 ` [PATCH net-next v1 01/21] amd-xgbe: Fix formatting of PCS register dump Tom Lendacky
2016-11-03 13:28 ` [PATCH net-next v1 02/21] amd-xgbe: Prepare for priority-based FIFO allocation Tom Lendacky
2016-11-03 13:51   ` Mintz, Yuval
2016-11-03 14:50     ` Tom Lendacky
2016-11-03 13:28 ` [PATCH net-next v1 03/21] amd-xgbe: Perform priority-based hardware " Tom Lendacky
2016-11-03 13:28 ` [PATCH net-next v1 04/21] amd-xgbe: Prepare for working with more than one type of phy Tom Lendacky
2016-11-03 13:28 ` [PATCH net-next v1 05/21] amd-xgbe: Prepare for introduction of clause 37 autoneg Tom Lendacky
2016-11-03 13:28 ` [PATCH net-next v1 06/21] amd-xgbe: Add support for clause 37 auto-negotiation Tom Lendacky
2016-11-03 13:28 ` [PATCH net-next v1 07/21] amd-xgbe: Prepare for a new PCS register access method Tom Lendacky
2016-11-03 13:29 ` [PATCH net-next v1 08/21] amd-xgbe: Support for 64-bit management counter registers Tom Lendacky
2016-11-03 13:29 ` Tom Lendacky [this message]
2016-11-03 13:29 ` [PATCH net-next v1 10/21] amd-xgbe: Prepare for supporting PCI devices Tom Lendacky
2016-11-03 13:29 ` [PATCH net-next v1 11/21] amd-xgbe: Guard against incorrectly generated interrupts Tom Lendacky
2016-11-03 13:29 ` [PATCH net-next v1 12/21] amd-xgbe: Add a workaround for Tx timestamp issue Tom Lendacky
2016-11-03 13:29 ` [PATCH net-next v1 13/21] amd-xgbe: Add PCI device support Tom Lendacky
2016-11-03 13:30 ` [PATCH net-next v1 14/21] amd-xgbe: Allow for a greater number of Rx queues Tom Lendacky
2016-11-03 13:30 ` [PATCH net-next v1 15/21] amd-xgbe: Add support for new DMA interrupt mode Tom Lendacky
2016-11-03 13:30 ` [PATCH net-next v1 16/21] amd-xgbe: Add ECC status support for the device memory Tom Lendacky
2016-11-03 13:30 ` [PATCH net-next v1 17/21] amd-xgbe: Add I2C support for determining SFP media types Tom Lendacky
2016-11-03 14:28   ` Andrew Lunn
2016-11-03 15:01     ` Tom Lendacky
2016-11-03 15:18       ` Andrew Lunn
2016-11-09 15:35         ` Tom Lendacky
2016-11-03 13:30 ` [PATCH net-next v1 18/21] net: phy: expose phy_aneg_done API for use by drivers Tom Lendacky
2016-11-04  2:13   ` kbuild test robot
2016-11-07 15:01     ` Tom Lendacky
2016-11-08 10:17       ` Andreas Larsson
2016-11-03 13:30 ` [PATCH net-next v1 19/21] amd-xgbe: Add support for SFP+ modules Tom Lendacky
2016-11-03 13:31 ` [PATCH net-next v1 20/21] amd-xgbe: Add support for MDIO attached PHYs Tom Lendacky
2016-11-03 13:31 ` [PATCH net-next v1 21/21] amd-xgbe: Add support for a KR redriver Tom Lendacky
2016-11-03 17:14 ` [PATCH net-next v1 00/21] amd-xgbe: AMD XGBE driver updates 2016-11-01 David Miller
2016-11-03 17:23   ` Tom Lendacky

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=20161103132914.3437.27657.stgit@tlendack-t1.amdoffice.net \
    --to=thomas.lendacky@amd.com \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=netdev@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).