linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] net: stmmac: Enable Flow Control
@ 2019-04-17  7:33 Jose Abreu
  2019-04-17  7:33 ` [PATCH net-next 1/2] net: stmmac: dwxgmac: Finish the Flow Control implementation Jose Abreu
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Jose Abreu @ 2019-04-17  7:33 UTC (permalink / raw)
  To: netdev, linux-kernel
  Cc: Jose Abreu, Joao Pinto, David S . Miller, Giuseppe Cavallaro,
	Alexandre Torgue

I don't know of any specific reason why Flow Control is off by default but
do let me know if there is any.

Tested in B2B between XGMAC2 and GMAC5.

Cc: Joao Pinto <jpinto@synopsys.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>

Jose Abreu (2):
  net: stmmac: dwxgmac: Finish the Flow Control implementation
  net: stmmac: Set Flow Control to automatic mode in the driver

 drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h     |  5 +++
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c | 46 ++++++++++++++++++++++
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  |  2 +-
 3 files changed, 52 insertions(+), 1 deletion(-)

-- 
2.7.4


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net-next 1/2] net: stmmac: dwxgmac: Finish the Flow Control implementation
  2019-04-17  7:33 [PATCH net-next 0/2] net: stmmac: Enable Flow Control Jose Abreu
@ 2019-04-17  7:33 ` Jose Abreu
  2019-04-17  7:33 ` [PATCH net-next 2/2] net: stmmac: Set Flow Control to automatic mode in the driver Jose Abreu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Jose Abreu @ 2019-04-17  7:33 UTC (permalink / raw)
  To: netdev, linux-kernel
  Cc: Jose Abreu, Joao Pinto, David S . Miller, Giuseppe Cavallaro,
	Alexandre Torgue

Finish the implementation of Flow Control feature. In order for it to
work correctly we need to set EHFC bit and the correct threshold values
for activating and deactivating it.

Signed-off-by: Jose Abreu <joabreu@synopsys.com>
Cc: Joao Pinto <jpinto@synopsys.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h     |  5 +++
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c | 46 ++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
index 37d5e6fe7473..085b700a4994 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
@@ -143,6 +143,11 @@
 #define XGMAC_RSF			BIT(5)
 #define XGMAC_RTC			GENMASK(1, 0)
 #define XGMAC_RTC_SHIFT			0
+#define XGMAC_MTL_RXQ_FLOW_CONTROL(x)	(0x00001150 + (0x80 * (x)))
+#define XGMAC_RFD			GENMASK(31, 17)
+#define XGMAC_RFD_SHIFT			17
+#define XGMAC_RFA			GENMASK(15, 1)
+#define XGMAC_RFA_SHIFT			1
 #define XGMAC_MTL_QINTEN(x)		(0x00001170 + (0x80 * (x)))
 #define XGMAC_RXOIE			BIT(16)
 #define XGMAC_MTL_QINT_STATUS(x)	(0x00001174 + (0x80 * (x)))
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
index 2ba712b48a89..e79037f511e1 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
@@ -147,6 +147,52 @@ static void dwxgmac2_dma_rx_mode(void __iomem *ioaddr, int mode,
 	value &= ~XGMAC_RQS;
 	value |= (rqs << XGMAC_RQS_SHIFT) & XGMAC_RQS;
 
+	if ((fifosz >= 4096) && (qmode != MTL_QUEUE_AVB)) {
+		u32 flow = readl(ioaddr + XGMAC_MTL_RXQ_FLOW_CONTROL(channel));
+		unsigned int rfd, rfa;
+
+		value |= XGMAC_EHFC;
+
+		/* Set Threshold for Activating Flow Control to min 2 frames,
+		 * i.e. 1500 * 2 = 3000 bytes.
+		 *
+		 * Set Threshold for Deactivating Flow Control to min 1 frame,
+		 * i.e. 1500 bytes.
+		 */
+		switch (fifosz) {
+		case 4096:
+			/* This violates the above formula because of FIFO size
+			 * limit therefore overflow may occur in spite of this.
+			 */
+			rfd = 0x03; /* Full-2.5K */
+			rfa = 0x01; /* Full-1.5K */
+			break;
+
+		case 8192:
+			rfd = 0x06; /* Full-4K */
+			rfa = 0x0a; /* Full-6K */
+			break;
+
+		case 16384:
+			rfd = 0x06; /* Full-4K */
+			rfa = 0x12; /* Full-10K */
+			break;
+
+		default:
+			rfd = 0x06; /* Full-4K */
+			rfa = 0x1e; /* Full-16K */
+			break;
+		}
+
+		flow &= ~XGMAC_RFD;
+		flow |= rfd << XGMAC_RFD_SHIFT;
+
+		flow &= ~XGMAC_RFA;
+		flow |= rfa << XGMAC_RFA_SHIFT;
+
+		writel(flow, ioaddr + XGMAC_MTL_RXQ_FLOW_CONTROL(channel));
+	}
+
 	writel(value, ioaddr + XGMAC_MTL_RXQ_OPMODE(channel));
 
 	/* Enable MTL RX overflow */
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net-next 2/2] net: stmmac: Set Flow Control to automatic mode in the driver
  2019-04-17  7:33 [PATCH net-next 0/2] net: stmmac: Enable Flow Control Jose Abreu
  2019-04-17  7:33 ` [PATCH net-next 1/2] net: stmmac: dwxgmac: Finish the Flow Control implementation Jose Abreu
@ 2019-04-17  7:33 ` Jose Abreu
  2019-04-17 17:14 ` [PATCH net-next 0/2] net: stmmac: Enable Flow Control David Miller
  2019-04-17 18:01 ` Aaro Koskinen
  3 siblings, 0 replies; 5+ messages in thread
From: Jose Abreu @ 2019-04-17  7:33 UTC (permalink / raw)
  To: netdev, linux-kernel
  Cc: Jose Abreu, Joao Pinto, David S . Miller, Giuseppe Cavallaro,
	Alexandre Torgue

By default Flow Control feature is not being enabled in stmmac.

This is a useful feature that can prevent loss of packets and now that
XGMAC already supports it (along with GMAC and QoS) it makes sense to
activate it.

Switch the module parameter to FLOW_AUTO so that Flow Control is
activated.

Signed-off-by: Jose Abreu <joabreu@synopsys.com>
Cc: Joao Pinto <jpinto@synopsys.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index a26e36dbb5df..7a895a2889e3 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -74,7 +74,7 @@ MODULE_PARM_DESC(phyaddr, "Physical device address");
 #define STMMAC_TX_THRESH	(DMA_TX_SIZE / 4)
 #define STMMAC_RX_THRESH	(DMA_RX_SIZE / 4)
 
-static int flow_ctrl = FLOW_OFF;
+static int flow_ctrl = FLOW_AUTO;
 module_param(flow_ctrl, int, 0644);
 MODULE_PARM_DESC(flow_ctrl, "Flow control ability [on/off]");
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next 0/2] net: stmmac: Enable Flow Control
  2019-04-17  7:33 [PATCH net-next 0/2] net: stmmac: Enable Flow Control Jose Abreu
  2019-04-17  7:33 ` [PATCH net-next 1/2] net: stmmac: dwxgmac: Finish the Flow Control implementation Jose Abreu
  2019-04-17  7:33 ` [PATCH net-next 2/2] net: stmmac: Set Flow Control to automatic mode in the driver Jose Abreu
@ 2019-04-17 17:14 ` David Miller
  2019-04-17 18:01 ` Aaro Koskinen
  3 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2019-04-17 17:14 UTC (permalink / raw)
  To: Jose.Abreu
  Cc: netdev, linux-kernel, Joao.Pinto, peppe.cavallaro, alexandre.torgue

From: Jose Abreu <Jose.Abreu@synopsys.com>
Date: Wed, 17 Apr 2019 09:33:03 +0200

> I don't know of any specific reason why Flow Control is off by default but
> do let me know if there is any.
> 
> Tested in B2B between XGMAC2 and GMAC5.
> 
> Cc: Joao Pinto <jpinto@synopsys.com>
> Cc: David S. Miller <davem@davemloft.net>
> Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
> Cc: Alexandre Torgue <alexandre.torgue@st.com>

I'm just going to apply this series now, it's easy to revert if necessary.

Thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next 0/2] net: stmmac: Enable Flow Control
  2019-04-17  7:33 [PATCH net-next 0/2] net: stmmac: Enable Flow Control Jose Abreu
                   ` (2 preceding siblings ...)
  2019-04-17 17:14 ` [PATCH net-next 0/2] net: stmmac: Enable Flow Control David Miller
@ 2019-04-17 18:01 ` Aaro Koskinen
  3 siblings, 0 replies; 5+ messages in thread
From: Aaro Koskinen @ 2019-04-17 18:01 UTC (permalink / raw)
  To: Jose Abreu
  Cc: netdev, linux-kernel, Joao Pinto, David S . Miller,
	Giuseppe Cavallaro, Alexandre Torgue

Hi,

On Wed, Apr 17, 2019 at 09:33:03AM +0200, Jose Abreu wrote:
> I don't know of any specific reason why Flow Control is off by default but
> do let me know if there is any.

It seems dwmac1000 assumes 4K FIFO size when configuring threshold
values. This could be non-optimal for 8K/16K FIFOs, but that can be
fixed later on with incremental patches.

A.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-04-17 18:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-17  7:33 [PATCH net-next 0/2] net: stmmac: Enable Flow Control Jose Abreu
2019-04-17  7:33 ` [PATCH net-next 1/2] net: stmmac: dwxgmac: Finish the Flow Control implementation Jose Abreu
2019-04-17  7:33 ` [PATCH net-next 2/2] net: stmmac: Set Flow Control to automatic mode in the driver Jose Abreu
2019-04-17 17:14 ` [PATCH net-next 0/2] net: stmmac: Enable Flow Control David Miller
2019-04-17 18:01 ` Aaro Koskinen

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).