[PATCH] kernel: backport mtk_soc_eth fixes from v5.13

Ilya Lipnitskiy ilya.lipnitskiy at gmail.com
Sat Apr 24 01:19:22 BST 2021


Fixes logic that leads to this error when booting mt7621 and other
devices that use the mediatek ethernet driver:
  [   23.144378] mtk_soc_eth 1e100000.ethernet: PPE table busy

The rest are mostly moved from pending-5.10 to backport-5.10 with a
couple of cleanups and improvements from upstream.

Refresh patches.

Links:
    https://git.kernel.org/netdev/net-next/c/c5d66587b890
    https://git.kernel.org/netdev/net-next/c/3f57d8c40fea
    https://git.kernel.org/netdev/net-next/c/5196c4178549
    https://git.kernel.org/netdev/net-next/c/787082ab9f7b
    https://git.kernel.org/netdev/net-next/c/c30c4a827390
    https://git.kernel.org/netdev/net-next/c/3630d519d7c3
    https://git.kernel.org/netdev/net-next/c/16ef670789b2
    https://git.kernel.org/netdev/net-next/c/59555a8d0dd3
    https://git.kernel.org/netdev/net-next/c/6b4423b258b9
    https://git.kernel.org/netdev/net-next/c/e9229ffd550b
    https://git.kernel.org/netdev/net-next/c/4e6bf609569c
    https://git.kernel.org/netdev/net-next/c/816ac3e6e67b
    https://git.kernel.org/netdev/net-next/c/16769a8923fa
    https://git.kernel.org/netdev/net-next/c/db2c7b353db3
    https://git.kernel.org/netdev/net-next/c/fa817272c37e
    https://git.kernel.org/netdev/net-next/c/3bc8e0aff23b

Fixes: f07fe36f22fc ("kernel: update flow offload patches to upstream version")
Cc: Felix Fietkau <nbd at nbd.name>
Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy at gmail.com>
---
 ...rnet-mediatek-ppe-fix-busy-wait-loop.patch |  72 ++++++++++++
 ...net-mtk_eth_soc-fix-RX-VLAN-offload.patch} |  17 ++-
 ...eth_soc-unmap-RX-data-before-callin.patch} |  26 ++---
 ...et-mtk_eth_soc-fix-build_skb-cleanup.patch |  38 ++++++
 ...et-mtk_eth_soc-use-napi_consume_skb.patch} |  13 ++-
 ...eth_soc-reduce-MDIO-bus-access-late.patch} |  10 +-
 ...eth_soc-remove-unnecessary-TX-queue.patch} |  16 ++-
 ...eth_soc-use-larger-burst-size-for-Q.patch} |  13 ++-
 ...mtk_eth_soc-increase-DMA-ring-sizes.patch} |  11 +-
 ...eth_soc-implement-dynamic-interrupt.patch} |  58 ++++++---
 ...eth_soc-cache-HW-pointer-of-last-fr.patch} |  24 ++--
 ...eth_soc-only-read-the-full-RX-descr.patch} |  11 +-
 ...eth_soc-reduce-unnecessary-interrup.patch} |  12 +-
 ...et-mtk_eth_soc-rework-NAPI-callbacks.patch | 110 ++++++++++++++++++
 ...eth_soc-set-PPE-flow-hash-as-skb-ha.patch} |  16 ++-
 ..._eth_soc-use-iopoll.h-macro-for-DMA-.patch |  71 +++++++++++
 ...ethernet-mediatek-support-net-labels.patch |   4 +-
 17 files changed, 445 insertions(+), 77 deletions(-)
 create mode 100644 target/linux/generic/backport-5.10/610-v5.13-35-net-ethernet-mediatek-ppe-fix-busy-wait-loop.patch
 rename target/linux/generic/{pending-5.10/770-02-net-ethernet-mtk_eth_soc-fix-rx-vlan-offload.patch => backport-5.10/610-v5.13-37-net-ethernet-mtk_eth_soc-fix-RX-VLAN-offload.patch} (56%)
 rename target/linux/generic/{pending-5.10/770-10-net-ethernet-mtk_eth_soc-unmap-rx-data-before-callin.patch => backport-5.10/610-v5.13-38-net-ethernet-mtk_eth_soc-unmap-RX-data-before-callin.patch} (56%)
 create mode 100644 target/linux/generic/backport-5.10/610-v5.13-39-net-ethernet-mtk_eth_soc-fix-build_skb-cleanup.patch
 rename target/linux/generic/{pending-5.10/770-00-net-ethernet-mtk_eth_soc-use-napi_consume_skb.patch => backport-5.10/610-v5.13-40-net-ethernet-mtk_eth_soc-use-napi_consume_skb.patch} (77%)
 rename target/linux/generic/{pending-5.10/770-01-net-ethernet-mtk_eth_soc-significantly-reduce-mdio-b.patch => backport-5.10/610-v5.13-41-net-ethernet-mtk_eth_soc-reduce-MDIO-bus-access-late.patch} (65%)
 rename target/linux/generic/{pending-5.10/770-03-net-ethernet-mtk_eth_soc-fix-unnecessary-tx-queue-st.patch => backport-5.10/610-v5.13-42-net-ethernet-mtk_eth_soc-remove-unnecessary-TX-queue.patch} (68%)
 rename target/linux/generic/{pending-5.10/770-04-net-ethernet-mtk_eth_soc-use-larger-burst-size-for-q.patch => backport-5.10/610-v5.13-43-net-ethernet-mtk_eth_soc-use-larger-burst-size-for-Q.patch} (67%)
 rename target/linux/generic/{pending-5.10/770-05-net-ethernet-mtk_eth_soc-increase-DMA-ring-sizes.patch => backport-5.10/610-v5.13-44-net-ethernet-mtk_eth_soc-increase-DMA-ring-sizes.patch} (62%)
 rename target/linux/generic/{pending-5.10/770-06-net-ethernet-mtk_eth_soc-implement-dynamic-interrupt.patch => backport-5.10/610-v5.13-45-net-ethernet-mtk_eth_soc-implement-dynamic-interrupt.patch} (76%)
 rename target/linux/generic/{pending-5.10/770-08-net-ethernet-mtk_eth_soc-cache-hardware-pointer-of-l.patch => backport-5.10/610-v5.13-46-net-ethernet-mtk_eth_soc-cache-HW-pointer-of-last-fr.patch} (70%)
 rename target/linux/generic/{pending-5.10/770-09-net-ethernet-mtk_eth_soc-only-read-the-full-rx-descr.patch => backport-5.10/610-v5.13-47-net-ethernet-mtk_eth_soc-only-read-the-full-RX-descr.patch} (77%)
 rename target/linux/generic/{pending-5.10/770-11-net-ethernet-mtk_eth_soc-avoid-rearming-interrupt-if.patch => backport-5.10/610-v5.13-48-net-ethernet-mtk_eth_soc-reduce-unnecessary-interrup.patch} (61%)
 create mode 100644 target/linux/generic/backport-5.10/610-v5.13-49-net-ethernet-mtk_eth_soc-rework-NAPI-callbacks.patch
 rename target/linux/generic/{pending-5.10/770-14-net-ethernet-mtk_eth_soc-set-PPE-flow-hash-as-skb-ha.patch => backport-5.10/610-v5.13-50-net-ethernet-mtk_eth_soc-set-PPE-flow-hash-as-skb-ha.patch} (68%)
 create mode 100644 target/linux/generic/backport-5.10/610-v5.13-51-net-ethernet-mtk_eth_soc-use-iopoll.h-macro-for-DMA-.patch

diff --git a/target/linux/generic/backport-5.10/610-v5.13-35-net-ethernet-mediatek-ppe-fix-busy-wait-loop.patch b/target/linux/generic/backport-5.10/610-v5.13-35-net-ethernet-mediatek-ppe-fix-busy-wait-loop.patch
new file mode 100644
index 000000000000..66cd053cd1af
--- /dev/null
+++ b/target/linux/generic/backport-5.10/610-v5.13-35-net-ethernet-mediatek-ppe-fix-busy-wait-loop.patch
@@ -0,0 +1,72 @@
+From c5d66587b8900201e1530b7c18d41e87bd5812f4 Mon Sep 17 00:00:00 2001
+From: Ilya Lipnitskiy <ilya.lipnitskiy at gmail.com>
+Date: Thu, 15 Apr 2021 17:37:48 -0700
+Subject: [PATCH] net: ethernet: mediatek: ppe: fix busy wait loop
+
+The intention is for the loop to timeout if the body does not succeed.
+The current logic calls time_is_before_jiffies(timeout) which is false
+until after the timeout, so the loop body never executes.
+
+Fix by using readl_poll_timeout as a more standard and less error-prone
+solution.
+
+Fixes: ba37b7caf1ed ("net: ethernet: mtk_eth_soc: add support for initializing the PPE")
+Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy at gmail.com>
+Cc: Felix Fietkau <nbd at nbd.name>
+Reviewed-by: Andrew Lunn <andrew at lunn.ch>
+Signed-off-by: David S. Miller <davem at davemloft.net>
+---
+ drivers/net/ethernet/mediatek/mtk_ppe.c | 20 +++++++++-----------
+ drivers/net/ethernet/mediatek/mtk_ppe.h |  1 +
+ 2 files changed, 10 insertions(+), 11 deletions(-)
+
+--- a/drivers/net/ethernet/mediatek/mtk_ppe.c
++++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
+@@ -2,9 +2,8 @@
+ /* Copyright (C) 2020 Felix Fietkau <nbd at nbd.name> */
+ 
+ #include <linux/kernel.h>
+-#include <linux/jiffies.h>
+-#include <linux/delay.h>
+ #include <linux/io.h>
++#include <linux/iopoll.h>
+ #include <linux/etherdevice.h>
+ #include <linux/platform_device.h>
+ #include "mtk_ppe.h"
+@@ -44,18 +43,17 @@ static u32 ppe_clear(struct mtk_ppe *ppe
+ 
+ static int mtk_ppe_wait_busy(struct mtk_ppe *ppe)
+ {
+-	unsigned long timeout = jiffies + HZ;
+-
+-	while (time_is_before_jiffies(timeout)) {
+-		if (!(ppe_r32(ppe, MTK_PPE_GLO_CFG) & MTK_PPE_GLO_CFG_BUSY))
+-			return 0;
++	int ret;
++	u32 val;
+ 
+-		usleep_range(10, 20);
+-	}
++	ret = readl_poll_timeout(ppe->base + MTK_PPE_GLO_CFG, val,
++				 !(val & MTK_PPE_GLO_CFG_BUSY),
++				 20, MTK_PPE_WAIT_TIMEOUT_US);
+ 
+-	dev_err(ppe->dev, "PPE table busy");
++	if (ret)
++		dev_err(ppe->dev, "PPE table busy");
+ 
+-	return -ETIMEDOUT;
++	return ret;
+ }
+ 
+ static void mtk_ppe_cache_clear(struct mtk_ppe *ppe)
+--- a/drivers/net/ethernet/mediatek/mtk_ppe.h
++++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
+@@ -12,6 +12,7 @@
+ #define MTK_PPE_ENTRIES_SHIFT		3
+ #define MTK_PPE_ENTRIES			(1024 << MTK_PPE_ENTRIES_SHIFT)
+ #define MTK_PPE_HASH_MASK		(MTK_PPE_ENTRIES - 1)
++#define MTK_PPE_WAIT_TIMEOUT_US		1000000
+ 
+ #define MTK_FOE_IB1_UNBIND_TIMESTAMP	GENMASK(7, 0)
+ #define MTK_FOE_IB1_UNBIND_PACKETS	GENMASK(23, 8)
diff --git a/target/linux/generic/pending-5.10/770-02-net-ethernet-mtk_eth_soc-fix-rx-vlan-offload.patch b/target/linux/generic/backport-5.10/610-v5.13-37-net-ethernet-mtk_eth_soc-fix-RX-VLAN-offload.patch
similarity index 56%
rename from target/linux/generic/pending-5.10/770-02-net-ethernet-mtk_eth_soc-fix-rx-vlan-offload.patch
rename to target/linux/generic/backport-5.10/610-v5.13-37-net-ethernet-mtk_eth_soc-fix-RX-VLAN-offload.patch
index 9357e79c88dc..7020fd714303 100644
--- a/target/linux/generic/pending-5.10/770-02-net-ethernet-mtk_eth_soc-fix-rx-vlan-offload.patch
+++ b/target/linux/generic/backport-5.10/610-v5.13-37-net-ethernet-mtk_eth_soc-fix-RX-VLAN-offload.patch
@@ -1,16 +1,23 @@
+From 3f57d8c40fea9b20543cab4da12f4680d2ef182c Mon Sep 17 00:00:00 2001
 From: Felix Fietkau <nbd at nbd.name>
-Date: Wed, 26 Aug 2020 16:52:12 +0200
-Subject: [PATCH] net: ethernet: mtk_eth_soc: fix rx vlan offload
+Date: Thu, 22 Apr 2021 22:20:54 -0700
+Subject: [PATCH] net: ethernet: mtk_eth_soc: fix RX VLAN offload
 
-The VLAN ID in the rx descriptor is only valid if the RX_DMA_VID bit is set
-Fixes frames wrongly marked with VLAN tags
+The VLAN ID in the rx descriptor is only valid if the RX_DMA_VTAG bit is
+set. Fixes frames wrongly marked with VLAN tags.
 
 Signed-off-by: Felix Fietkau <nbd at nbd.name>
+[Ilya: fix commit message]
+Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy at gmail.com>
+Signed-off-by: David S. Miller <davem at davemloft.net>
 ---
+ drivers/net/ethernet/mediatek/mtk_eth_soc.c | 2 +-
+ drivers/net/ethernet/mediatek/mtk_eth_soc.h | 1 +
+ 2 files changed, 2 insertions(+), 1 deletion(-)
 
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -1324,7 +1324,7 @@ static int mtk_poll_rx(struct napi_struc
+@@ -1319,7 +1319,7 @@ static int mtk_poll_rx(struct napi_struc
  		skb->protocol = eth_type_trans(skb, netdev);
  
  		if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX &&
diff --git a/target/linux/generic/pending-5.10/770-10-net-ethernet-mtk_eth_soc-unmap-rx-data-before-callin.patch b/target/linux/generic/backport-5.10/610-v5.13-38-net-ethernet-mtk_eth_soc-unmap-RX-data-before-callin.patch
similarity index 56%
rename from target/linux/generic/pending-5.10/770-10-net-ethernet-mtk_eth_soc-unmap-rx-data-before-callin.patch
rename to target/linux/generic/backport-5.10/610-v5.13-38-net-ethernet-mtk_eth_soc-unmap-RX-data-before-callin.patch
index 4a19fa1164fb..ff88c9e84baf 100644
--- a/target/linux/generic/pending-5.10/770-10-net-ethernet-mtk_eth_soc-unmap-rx-data-before-callin.patch
+++ b/target/linux/generic/backport-5.10/610-v5.13-38-net-ethernet-mtk_eth_soc-unmap-RX-data-before-callin.patch
@@ -1,17 +1,23 @@
+From 5196c417854942e218a59ec87bf7d414b3bd581e Mon Sep 17 00:00:00 2001
 From: Felix Fietkau <nbd at nbd.name>
-Date: Thu, 27 Aug 2020 09:44:43 +0200
-Subject: [PATCH] net: ethernet: mtk_eth_soc: unmap rx data before calling
+Date: Thu, 22 Apr 2021 22:20:55 -0700
+Subject: [PATCH] net: ethernet: mtk_eth_soc: unmap RX data before calling
  build_skb
 
 Since build_skb accesses the data area (for initializing shinfo), dma unmap
 needs to happen before that call
 
 Signed-off-by: Felix Fietkau <nbd at nbd.name>
+[Ilya: split build_skb cleanup fix into a separate commit]
+Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy at gmail.com>
+Signed-off-by: David S. Miller <davem at davemloft.net>
 ---
+ drivers/net/ethernet/mediatek/mtk_eth_soc.c | 5 +++--
+ 1 file changed, 3 insertions(+), 2 deletions(-)
 
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -1297,17 +1297,18 @@ static int mtk_poll_rx(struct napi_struc
+@@ -1298,6 +1298,9 @@ static int mtk_poll_rx(struct napi_struc
  			goto release_desc;
  		}
  
@@ -21,11 +27,7 @@ Signed-off-by: Felix Fietkau <nbd at nbd.name>
  		/* receive data */
  		skb = build_skb(data, ring->frag_size);
  		if (unlikely(!skb)) {
--			skb_free_frag(new_data);
-+			skb_free_frag(data);
- 			netdev->stats.rx_dropped++;
--			goto release_desc;
-+			goto skip_rx;
+@@ -1307,8 +1310,6 @@ static int mtk_poll_rx(struct napi_struc
  		}
  		skb_reserve(skb, NET_SKB_PAD + NET_IP_ALIGN);
  
@@ -34,11 +36,3 @@ Signed-off-by: Felix Fietkau <nbd at nbd.name>
  		pktlen = RX_DMA_GET_PLEN0(trxd.rxd2);
  		skb->dev = netdev;
  		skb_put(skb, pktlen);
-@@ -1325,6 +1326,7 @@ static int mtk_poll_rx(struct napi_struc
- 		skb_record_rx_queue(skb, 0);
- 		napi_gro_receive(napi, skb);
- 
-+skip_rx:
- 		ring->data[idx] = new_data;
- 		rxd->rxd1 = (unsigned int)dma_addr;
- 
diff --git a/target/linux/generic/backport-5.10/610-v5.13-39-net-ethernet-mtk_eth_soc-fix-build_skb-cleanup.patch b/target/linux/generic/backport-5.10/610-v5.13-39-net-ethernet-mtk_eth_soc-fix-build_skb-cleanup.patch
new file mode 100644
index 000000000000..dee26ccff106
--- /dev/null
+++ b/target/linux/generic/backport-5.10/610-v5.13-39-net-ethernet-mtk_eth_soc-fix-build_skb-cleanup.patch
@@ -0,0 +1,38 @@
+From 787082ab9f7be4711e52f67c388535eda74a1269 Mon Sep 17 00:00:00 2001
+From: Ilya Lipnitskiy <ilya.lipnitskiy at gmail.com>
+Date: Thu, 22 Apr 2021 22:20:56 -0700
+Subject: [PATCH] net: ethernet: mtk_eth_soc: fix build_skb cleanup
+
+In case build_skb fails, call skb_free_frag on the correct pointer. Also
+update the DMA structures with the new mapping before exiting, because
+the mapping was successful
+
+Suggested-by: Felix Fietkau <nbd at nbd.name>
+Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy at gmail.com>
+Signed-off-by: David S. Miller <davem at davemloft.net>
+---
+ drivers/net/ethernet/mediatek/mtk_eth_soc.c | 5 +++--
+ 1 file changed, 3 insertions(+), 2 deletions(-)
+
+--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
++++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+@@ -1304,9 +1304,9 @@ static int mtk_poll_rx(struct napi_struc
+ 		/* receive data */
+ 		skb = build_skb(data, ring->frag_size);
+ 		if (unlikely(!skb)) {
+-			skb_free_frag(new_data);
++			skb_free_frag(data);
+ 			netdev->stats.rx_dropped++;
+-			goto release_desc;
++			goto skip_rx;
+ 		}
+ 		skb_reserve(skb, NET_SKB_PAD + NET_IP_ALIGN);
+ 
+@@ -1326,6 +1326,7 @@ static int mtk_poll_rx(struct napi_struc
+ 		skb_record_rx_queue(skb, 0);
+ 		napi_gro_receive(napi, skb);
+ 
++skip_rx:
+ 		ring->data[idx] = new_data;
+ 		rxd->rxd1 = (unsigned int)dma_addr;
+ 
diff --git a/target/linux/generic/pending-5.10/770-00-net-ethernet-mtk_eth_soc-use-napi_consume_skb.patch b/target/linux/generic/backport-5.10/610-v5.13-40-net-ethernet-mtk_eth_soc-use-napi_consume_skb.patch
similarity index 77%
rename from target/linux/generic/pending-5.10/770-00-net-ethernet-mtk_eth_soc-use-napi_consume_skb.patch
rename to target/linux/generic/backport-5.10/610-v5.13-40-net-ethernet-mtk_eth_soc-use-napi_consume_skb.patch
index 58cecb6026f0..1d1845fa8491 100644
--- a/target/linux/generic/pending-5.10/770-00-net-ethernet-mtk_eth_soc-use-napi_consume_skb.patch
+++ b/target/linux/generic/backport-5.10/610-v5.13-40-net-ethernet-mtk_eth_soc-use-napi_consume_skb.patch
@@ -1,11 +1,16 @@
+From c30c4a82739090a2de4a4e3f245355ea4fb3ec14 Mon Sep 17 00:00:00 2001
 From: Felix Fietkau <nbd at nbd.name>
-Date: Mon, 8 Jun 2020 17:01:12 +0200
+Date: Thu, 22 Apr 2021 22:20:57 -0700
 Subject: [PATCH] net: ethernet: mtk_eth_soc: use napi_consume_skb
 
 Should improve performance, since it can use bulk free
 
 Signed-off-by: Felix Fietkau <nbd at nbd.name>
+Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy at gmail.com>
+Signed-off-by: David S. Miller <davem at davemloft.net>
 ---
+ drivers/net/ethernet/mediatek/mtk_eth_soc.c | 19 ++++++++++++-------
+ 1 file changed, 12 insertions(+), 7 deletions(-)
 
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -43,7 +48,7 @@ Signed-off-by: Felix Fietkau <nbd at nbd.name>
  
  		itxd->txd3 = TX_DMA_LS0 | TX_DMA_OWNER_CPU;
  		if (!MTK_HAS_CAPS(eth->soc->caps, MTK_QDMA))
-@@ -1386,7 +1391,7 @@ static int mtk_poll_tx_qdma(struct mtk_e
+@@ -1388,7 +1393,7 @@ static int mtk_poll_tx_qdma(struct mtk_e
  			done[mac]++;
  			budget--;
  		}
@@ -52,7 +57,7 @@ Signed-off-by: Felix Fietkau <nbd at nbd.name>
  
  		ring->last_free = desc;
  		atomic_inc(&ring->free_count);
-@@ -1423,7 +1428,7 @@ static int mtk_poll_tx_pdma(struct mtk_e
+@@ -1425,7 +1430,7 @@ static int mtk_poll_tx_pdma(struct mtk_e
  			budget--;
  		}
  
@@ -61,7 +66,7 @@ Signed-off-by: Felix Fietkau <nbd at nbd.name>
  
  		desc = &ring->dma[cpu];
  		ring->last_free = desc;
-@@ -1625,7 +1630,7 @@ static void mtk_tx_clean(struct mtk_eth
+@@ -1627,7 +1632,7 @@ static void mtk_tx_clean(struct mtk_eth
  
  	if (ring->buf) {
  		for (i = 0; i < MTK_DMA_SIZE; i++)
diff --git a/target/linux/generic/pending-5.10/770-01-net-ethernet-mtk_eth_soc-significantly-reduce-mdio-b.patch b/target/linux/generic/backport-5.10/610-v5.13-41-net-ethernet-mtk_eth_soc-reduce-MDIO-bus-access-late.patch
similarity index 65%
rename from target/linux/generic/pending-5.10/770-01-net-ethernet-mtk_eth_soc-significantly-reduce-mdio-b.patch
rename to target/linux/generic/backport-5.10/610-v5.13-41-net-ethernet-mtk_eth_soc-reduce-MDIO-bus-access-late.patch
index 577b2eda162a..7ebc3fa90345 100644
--- a/target/linux/generic/pending-5.10/770-01-net-ethernet-mtk_eth_soc-significantly-reduce-mdio-b.patch
+++ b/target/linux/generic/backport-5.10/610-v5.13-41-net-ethernet-mtk_eth_soc-reduce-MDIO-bus-access-late.patch
@@ -1,7 +1,7 @@
+From 3630d519d7c3eab92567658690e44ffe0517d109 Mon Sep 17 00:00:00 2001
 From: Felix Fietkau <nbd at nbd.name>
-Date: Mon, 8 Jun 2020 17:02:39 +0200
-Subject: [PATCH] net: ethernet: mtk_eth_soc: significantly reduce mdio bus
- access latency
+Date: Thu, 22 Apr 2021 22:20:58 -0700
+Subject: [PATCH] net: ethernet: mtk_eth_soc: reduce MDIO bus access latency
 
 usleep_range often ends up sleeping much longer than the 10-20us provided
 as a range here. This causes significant latency in mdio bus acceses,
@@ -11,7 +11,11 @@ Use cond_resched instead of usleep_range, since the MDIO access does not
 take much time
 
 Signed-off-by: Felix Fietkau <nbd at nbd.name>
+Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy at gmail.com>
+Signed-off-by: David S. Miller <davem at davemloft.net>
 ---
+ drivers/net/ethernet/mediatek/mtk_eth_soc.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
 
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
diff --git a/target/linux/generic/pending-5.10/770-03-net-ethernet-mtk_eth_soc-fix-unnecessary-tx-queue-st.patch b/target/linux/generic/backport-5.10/610-v5.13-42-net-ethernet-mtk_eth_soc-remove-unnecessary-TX-queue.patch
similarity index 68%
rename from target/linux/generic/pending-5.10/770-03-net-ethernet-mtk_eth_soc-fix-unnecessary-tx-queue-st.patch
rename to target/linux/generic/backport-5.10/610-v5.13-42-net-ethernet-mtk_eth_soc-remove-unnecessary-TX-queue.patch
index eda10a452e77..67a7e3baed9f 100644
--- a/target/linux/generic/pending-5.10/770-03-net-ethernet-mtk_eth_soc-fix-unnecessary-tx-queue-st.patch
+++ b/target/linux/generic/backport-5.10/610-v5.13-42-net-ethernet-mtk_eth_soc-remove-unnecessary-TX-queue.patch
@@ -1,14 +1,18 @@
+From 16ef670789b252b221700adc413497ed2f941d8a Mon Sep 17 00:00:00 2001
 From: Felix Fietkau <nbd at nbd.name>
-Date: Wed, 26 Aug 2020 16:55:54 +0200
-Subject: [PATCH] net: ethernet: mtk_eth_soc: fix unnecessary tx queue
- stops
+Date: Thu, 22 Apr 2021 22:20:59 -0700
+Subject: [PATCH] net: ethernet: mtk_eth_soc: remove unnecessary TX queue stops
 
-When running short on descriptors, only stop the queue for the netdev that tx
-was attempted for. By the time the something tries to send on the other netdev,
-the ring might have some more room already
+When running short on descriptors, only stop the queue for the netdev that
+tx was attempted for. By the time something tries to send on the other
+netdev, the ring might have some more room already.
 
 Signed-off-by: Felix Fietkau <nbd at nbd.name>
+Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy at gmail.com>
+Signed-off-by: David S. Miller <davem at davemloft.net>
 ---
+ drivers/net/ethernet/mediatek/mtk_eth_soc.c | 15 ++-------------
+ 1 file changed, 2 insertions(+), 13 deletions(-)
 
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
diff --git a/target/linux/generic/pending-5.10/770-04-net-ethernet-mtk_eth_soc-use-larger-burst-size-for-q.patch b/target/linux/generic/backport-5.10/610-v5.13-43-net-ethernet-mtk_eth_soc-use-larger-burst-size-for-Q.patch
similarity index 67%
rename from target/linux/generic/pending-5.10/770-04-net-ethernet-mtk_eth_soc-use-larger-burst-size-for-q.patch
rename to target/linux/generic/backport-5.10/610-v5.13-43-net-ethernet-mtk_eth_soc-use-larger-burst-size-for-Q.patch
index 24e069b8ae50..7c95b335782c 100644
--- a/target/linux/generic/pending-5.10/770-04-net-ethernet-mtk_eth_soc-use-larger-burst-size-for-q.patch
+++ b/target/linux/generic/backport-5.10/610-v5.13-43-net-ethernet-mtk_eth_soc-use-larger-burst-size-for-Q.patch
@@ -1,16 +1,21 @@
+From 59555a8d0dd39bf60b7ca1ba5e7393d293f7398d Mon Sep 17 00:00:00 2001
 From: Felix Fietkau <nbd at nbd.name>
-Date: Wed, 26 Aug 2020 16:58:55 +0200
-Subject: [PATCH] net: ethernet: mtk_eth_soc: use larger burst size for
- qdma tx
+Date: Thu, 22 Apr 2021 22:21:00 -0700
+Subject: [PATCH] net: ethernet: mtk_eth_soc: use larger burst size for QDMA TX
 
 Improves tx performance
 
 Signed-off-by: Felix Fietkau <nbd at nbd.name>
+Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy at gmail.com>
+Signed-off-by: David S. Miller <davem at davemloft.net>
 ---
+ drivers/net/ethernet/mediatek/mtk_eth_soc.c | 2 +-
+ drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 +-
+ 2 files changed, 2 insertions(+), 2 deletions(-)
 
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -2191,7 +2191,7 @@ static int mtk_start_dma(struct mtk_eth
+@@ -2193,7 +2193,7 @@ static int mtk_start_dma(struct mtk_eth
  	if (MTK_HAS_CAPS(eth->soc->caps, MTK_QDMA)) {
  		mtk_w32(eth,
  			MTK_TX_WB_DDONE | MTK_TX_DMA_EN |
diff --git a/target/linux/generic/pending-5.10/770-05-net-ethernet-mtk_eth_soc-increase-DMA-ring-sizes.patch b/target/linux/generic/backport-5.10/610-v5.13-44-net-ethernet-mtk_eth_soc-increase-DMA-ring-sizes.patch
similarity index 62%
rename from target/linux/generic/pending-5.10/770-05-net-ethernet-mtk_eth_soc-increase-DMA-ring-sizes.patch
rename to target/linux/generic/backport-5.10/610-v5.13-44-net-ethernet-mtk_eth_soc-increase-DMA-ring-sizes.patch
index 201b70b65d39..d695f0fb8a6c 100644
--- a/target/linux/generic/pending-5.10/770-05-net-ethernet-mtk_eth_soc-increase-DMA-ring-sizes.patch
+++ b/target/linux/generic/backport-5.10/610-v5.13-44-net-ethernet-mtk_eth_soc-increase-DMA-ring-sizes.patch
@@ -1,12 +1,17 @@
+From 6b4423b258b91032c50a5efca15d3d9bb194ea1d Mon Sep 17 00:00:00 2001
 From: Felix Fietkau <nbd at nbd.name>
-Date: Wed, 26 Aug 2020 16:59:41 +0200
+Date: Thu, 22 Apr 2021 22:21:01 -0700
 Subject: [PATCH] net: ethernet: mtk_eth_soc: increase DMA ring sizes
 
-256 descriptors is not enough for multi-gigabit traffic under load on MT7622.
-Bump it to 512 to improve performance
+256 descriptors is not enough for multi-gigabit traffic under load on
+MT7622. Bump it to 512 to improve performance.
 
 Signed-off-by: Felix Fietkau <nbd at nbd.name>
+Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy at gmail.com>
+Signed-off-by: David S. Miller <davem at davemloft.net>
 ---
+ drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
 
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
diff --git a/target/linux/generic/pending-5.10/770-06-net-ethernet-mtk_eth_soc-implement-dynamic-interrupt.patch b/target/linux/generic/backport-5.10/610-v5.13-45-net-ethernet-mtk_eth_soc-implement-dynamic-interrupt.patch
similarity index 76%
rename from target/linux/generic/pending-5.10/770-06-net-ethernet-mtk_eth_soc-implement-dynamic-interrupt.patch
rename to target/linux/generic/backport-5.10/610-v5.13-45-net-ethernet-mtk_eth_soc-implement-dynamic-interrupt.patch
index be82637e6dc9..ef4d2e875b76 100644
--- a/target/linux/generic/pending-5.10/770-06-net-ethernet-mtk_eth_soc-implement-dynamic-interrupt.patch
+++ b/target/linux/generic/backport-5.10/610-v5.13-45-net-ethernet-mtk_eth_soc-implement-dynamic-interrupt.patch
@@ -1,12 +1,20 @@
+From e9229ffd550b2d8c4997c67a501dbc3919fd4e26 Mon Sep 17 00:00:00 2001
 From: Felix Fietkau <nbd at nbd.name>
-Date: Wed, 26 Aug 2020 17:02:30 +0200
+Date: Thu, 22 Apr 2021 22:21:02 -0700
 Subject: [PATCH] net: ethernet: mtk_eth_soc: implement dynamic interrupt
  moderation
 
 Reduces the number of interrupts under load
 
 Signed-off-by: Felix Fietkau <nbd at nbd.name>
+[Ilya: add documentation for new struct fields]
+Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy at gmail.com>
+Signed-off-by: David S. Miller <davem at davemloft.net>
 ---
+ drivers/net/ethernet/mediatek/Kconfig       |  1 +
+ drivers/net/ethernet/mediatek/mtk_eth_soc.c | 96 +++++++++++++++++++--
+ drivers/net/ethernet/mediatek/mtk_eth_soc.h | 41 +++++++--
+ 3 files changed, 124 insertions(+), 14 deletions(-)
 
 --- a/drivers/net/ethernet/mediatek/Kconfig
 +++ b/drivers/net/ethernet/mediatek/Kconfig
@@ -35,7 +43,7 @@ Signed-off-by: Felix Fietkau <nbd at nbd.name>
  
  	while (done < budget) {
  		struct net_device *netdev;
-@@ -1311,6 +1312,7 @@ static int mtk_poll_rx(struct napi_struc
+@@ -1312,6 +1313,7 @@ static int mtk_poll_rx(struct napi_struc
  		else
  			skb_checksum_none_assert(skb);
  		skb->protocol = eth_type_trans(skb, netdev);
@@ -43,7 +51,7 @@ Signed-off-by: Felix Fietkau <nbd at nbd.name>
  
  		if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX &&
  		    (trxd.rxd2 & RX_DMA_VTAG))
-@@ -1342,6 +1344,12 @@ rx_done:
+@@ -1344,6 +1346,12 @@ rx_done:
  		mtk_update_rx_cpu_idx(eth);
  	}
  
@@ -56,7 +64,7 @@ Signed-off-by: Felix Fietkau <nbd at nbd.name>
  	return done;
  }
  
-@@ -1434,6 +1442,7 @@ static int mtk_poll_tx_pdma(struct mtk_e
+@@ -1436,6 +1444,7 @@ static int mtk_poll_tx_pdma(struct mtk_e
  static int mtk_poll_tx(struct mtk_eth *eth, int budget)
  {
  	struct mtk_tx_ring *ring = &eth->tx_ring;
@@ -64,7 +72,7 @@ Signed-off-by: Felix Fietkau <nbd at nbd.name>
  	unsigned int done[MTK_MAX_DEVS];
  	unsigned int bytes[MTK_MAX_DEVS];
  	int total = 0, i;
-@@ -1451,8 +1460,14 @@ static int mtk_poll_tx(struct mtk_eth *e
+@@ -1453,8 +1462,14 @@ static int mtk_poll_tx(struct mtk_eth *e
  			continue;
  		netdev_completed_queue(eth->netdev[i], done[i], bytes[i]);
  		total += done[i];
@@ -79,7 +87,7 @@ Signed-off-by: Felix Fietkau <nbd at nbd.name>
  	if (mtk_queue_stopped(eth) &&
  	    (atomic_read(&ring->free_count) > ring->thresh))
  		mtk_wake_queue(eth);
-@@ -2127,6 +2142,7 @@ static irqreturn_t mtk_handle_irq_rx(int
+@@ -2129,6 +2144,7 @@ static irqreturn_t mtk_handle_irq_rx(int
  {
  	struct mtk_eth *eth = _eth;
  
@@ -87,7 +95,7 @@ Signed-off-by: Felix Fietkau <nbd at nbd.name>
  	if (likely(napi_schedule_prep(&eth->rx_napi))) {
  		__napi_schedule(&eth->rx_napi);
  		mtk_rx_irq_disable(eth, MTK_RX_DONE_INT);
-@@ -2139,6 +2155,7 @@ static irqreturn_t mtk_handle_irq_tx(int
+@@ -2141,6 +2157,7 @@ static irqreturn_t mtk_handle_irq_tx(int
  {
  	struct mtk_eth *eth = _eth;
  
@@ -95,7 +103,7 @@ Signed-off-by: Felix Fietkau <nbd at nbd.name>
  	if (likely(napi_schedule_prep(&eth->tx_napi))) {
  		__napi_schedule(&eth->tx_napi);
  		mtk_tx_irq_disable(eth, MTK_TX_DONE_INT);
-@@ -2323,6 +2340,9 @@ static int mtk_stop(struct net_device *d
+@@ -2325,6 +2342,9 @@ static int mtk_stop(struct net_device *d
  	napi_disable(&eth->tx_napi);
  	napi_disable(&eth->rx_napi);
  
@@ -105,7 +113,7 @@ Signed-off-by: Felix Fietkau <nbd at nbd.name>
  	if (MTK_HAS_CAPS(eth->soc->caps, MTK_QDMA))
  		mtk_stop_dma(eth, MTK_QDMA_GLO_CFG);
  	mtk_stop_dma(eth, MTK_PDMA_GLO_CFG);
-@@ -2375,6 +2395,64 @@ err_disable_clks:
+@@ -2377,6 +2397,64 @@ err_disable_clks:
  	return ret;
  }
  
@@ -170,7 +178,7 @@ Signed-off-by: Felix Fietkau <nbd at nbd.name>
  static int mtk_hw_init(struct mtk_eth *eth)
  {
  	int i, val, ret;
-@@ -2396,9 +2474,6 @@ static int mtk_hw_init(struct mtk_eth *e
+@@ -2398,9 +2476,6 @@ static int mtk_hw_init(struct mtk_eth *e
  			goto err_disable_pm;
  		}
  
@@ -180,12 +188,13 @@ Signed-off-by: Felix Fietkau <nbd at nbd.name>
  		/* disable delay and normal interrupt */
  		mtk_tx_irq_disable(eth, ~0);
  		mtk_rx_irq_disable(eth, ~0);
-@@ -2437,11 +2512,10 @@ static int mtk_hw_init(struct mtk_eth *e
+@@ -2439,11 +2514,11 @@ static int mtk_hw_init(struct mtk_eth *e
  	/* Enable RX VLan Offloading */
  	mtk_w32(eth, 1, MTK_CDMP_EG_CTRL);
  
 -	/* enable interrupt delay for RX */
 -	mtk_w32(eth, MTK_PDMA_DELAY_RX_DELAY, MTK_PDMA_DELAY_INT);
++	/* set interrupt delays based on current Net DIM sample */
 +	mtk_dim_rx(&eth->rx_dim.work);
 +	mtk_dim_tx(&eth->tx_dim.work);
  
@@ -194,7 +203,7 @@ Signed-off-by: Felix Fietkau <nbd at nbd.name>
  	mtk_tx_irq_disable(eth, ~0);
  	mtk_rx_irq_disable(eth, ~0);
  
-@@ -2946,6 +3020,13 @@ static int mtk_probe(struct platform_dev
+@@ -2948,6 +3023,13 @@ static int mtk_probe(struct platform_dev
  	spin_lock_init(&eth->page_lock);
  	spin_lock_init(&eth->tx_irq_lock);
  	spin_lock_init(&eth->rx_irq_lock);
@@ -260,7 +269,30 @@ Signed-off-by: Felix Fietkau <nbd at nbd.name>
  
  /* QDMA Interrupt grouping registers */
  #define MTK_QDMA_INT_GRP1	0x1a20
-@@ -905,6 +911,18 @@ struct mtk_eth {
+@@ -843,6 +849,7 @@ struct mtk_sgmii {
+  * @page_lock:		Make sure that register operations are atomic
+  * @tx_irq__lock:	Make sure that IRQ register operations are atomic
+  * @rx_irq__lock:	Make sure that IRQ register operations are atomic
++ * @dim_lock:		Make sure that Net DIM operations are atomic
+  * @dummy_dev:		we run 2 netdevs on 1 physical DMA ring and need a
+  *			dummy for NAPI to work
+  * @netdev:		The netdev instances
+@@ -861,6 +868,14 @@ struct mtk_sgmii {
+  * @rx_ring_qdma:	Pointer to the memory holding info about the QDMA RX ring
+  * @tx_napi:		The TX NAPI struct
+  * @rx_napi:		The RX NAPI struct
++ * @rx_events:		Net DIM RX event counter
++ * @rx_packets:		Net DIM RX packet counter
++ * @rx_bytes:		Net DIM RX byte counter
++ * @rx_dim:		Net DIM RX context
++ * @tx_events:		Net DIM TX event counter
++ * @tx_packets:		Net DIM TX packet counter
++ * @tx_bytes:		Net DIM TX byte counter
++ * @tx_dim:		Net DIM TX context
+  * @scratch_ring:	Newer SoCs need memory for a second HW managed TX ring
+  * @phy_scratch_ring:	physical address of scratch_ring
+  * @scratch_head:	The scratch memory that scratch_ring points to.
+@@ -905,6 +920,18 @@ struct mtk_eth {
  
  	const struct mtk_soc_data	*soc;
  
diff --git a/target/linux/generic/pending-5.10/770-08-net-ethernet-mtk_eth_soc-cache-hardware-pointer-of-l.patch b/target/linux/generic/backport-5.10/610-v5.13-46-net-ethernet-mtk_eth_soc-cache-HW-pointer-of-last-fr.patch
similarity index 70%
rename from target/linux/generic/pending-5.10/770-08-net-ethernet-mtk_eth_soc-cache-hardware-pointer-of-l.patch
rename to target/linux/generic/backport-5.10/610-v5.13-46-net-ethernet-mtk_eth_soc-cache-HW-pointer-of-last-fr.patch
index b4ae8dc2e8da..db21878e92e1 100644
--- a/target/linux/generic/pending-5.10/770-08-net-ethernet-mtk_eth_soc-cache-hardware-pointer-of-l.patch
+++ b/target/linux/generic/backport-5.10/610-v5.13-46-net-ethernet-mtk_eth_soc-cache-HW-pointer-of-last-fr.patch
@@ -1,17 +1,23 @@
+From 4e6bf609569c59b6bd6acf4a607c096cbd820d79 Mon Sep 17 00:00:00 2001
 From: Felix Fietkau <nbd at nbd.name>
-Date: Thu, 27 Aug 2020 06:32:03 +0200
-Subject: [PATCH] net: ethernet: mtk_eth_soc: cache hardware pointer of last
- freed tx descriptor
+Date: Thu, 22 Apr 2021 22:21:03 -0700
+Subject: [PATCH] net: ethernet: mtk_eth_soc: cache HW pointer of last freed TX
+ descriptor
 
-The value is only updated by the CPU, so it is cheaper to access from the ring
-data structure than from a hardware register
+The value is only updated by the CPU, so it is cheaper to access from the
+ring data structure than from a hardware register.
 
 Signed-off-by: Felix Fietkau <nbd at nbd.name>
+Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy at gmail.com>
+Signed-off-by: David S. Miller <davem at davemloft.net>
 ---
+ drivers/net/ethernet/mediatek/mtk_eth_soc.c | 8 ++++----
+ drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 ++
+ 2 files changed, 6 insertions(+), 4 deletions(-)
 
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -1362,7 +1362,7 @@ static int mtk_poll_tx_qdma(struct mtk_e
+@@ -1364,7 +1364,7 @@ static int mtk_poll_tx_qdma(struct mtk_e
  	struct mtk_tx_buf *tx_buf;
  	u32 cpu, dma;
  
@@ -20,7 +26,7 @@ Signed-off-by: Felix Fietkau <nbd at nbd.name>
  	dma = mtk_r32(eth, MTK_QTX_DRX_PTR);
  
  	desc = mtk_qdma_phys_to_virt(ring, cpu);
-@@ -1396,6 +1396,7 @@ static int mtk_poll_tx_qdma(struct mtk_e
+@@ -1398,6 +1398,7 @@ static int mtk_poll_tx_qdma(struct mtk_e
  		cpu = next_cpu;
  	}
  
@@ -28,7 +34,7 @@ Signed-off-by: Felix Fietkau <nbd at nbd.name>
  	mtk_w32(eth, cpu, MTK_QTX_CRX_PTR);
  
  	return budget;
-@@ -1596,6 +1597,7 @@ static int mtk_tx_alloc(struct mtk_eth *
+@@ -1598,6 +1599,7 @@ static int mtk_tx_alloc(struct mtk_eth *
  	atomic_set(&ring->free_count, MTK_DMA_SIZE - 2);
  	ring->next_free = &ring->dma[0];
  	ring->last_free = &ring->dma[MTK_DMA_SIZE - 1];
@@ -36,7 +42,7 @@ Signed-off-by: Felix Fietkau <nbd at nbd.name>
  	ring->thresh = MAX_SKB_FRAGS;
  
  	/* make sure that all changes to the dma ring are flushed before we
-@@ -1609,9 +1611,7 @@ static int mtk_tx_alloc(struct mtk_eth *
+@@ -1611,9 +1613,7 @@ static int mtk_tx_alloc(struct mtk_eth *
  		mtk_w32(eth,
  			ring->phys + ((MTK_DMA_SIZE - 1) * sz),
  			MTK_QTX_CRX_PTR);
diff --git a/target/linux/generic/pending-5.10/770-09-net-ethernet-mtk_eth_soc-only-read-the-full-rx-descr.patch b/target/linux/generic/backport-5.10/610-v5.13-47-net-ethernet-mtk_eth_soc-only-read-the-full-RX-descr.patch
similarity index 77%
rename from target/linux/generic/pending-5.10/770-09-net-ethernet-mtk_eth_soc-only-read-the-full-rx-descr.patch
rename to target/linux/generic/backport-5.10/610-v5.13-47-net-ethernet-mtk_eth_soc-only-read-the-full-RX-descr.patch
index b744ac643cee..f1a3fbd864cf 100644
--- a/target/linux/generic/pending-5.10/770-09-net-ethernet-mtk_eth_soc-only-read-the-full-rx-descr.patch
+++ b/target/linux/generic/backport-5.10/610-v5.13-47-net-ethernet-mtk_eth_soc-only-read-the-full-RX-descr.patch
@@ -1,13 +1,18 @@
+From 816ac3e6e67bdd78d86226c6eb53619780750e92 Mon Sep 17 00:00:00 2001
 From: Felix Fietkau <nbd at nbd.name>
-Date: Thu, 27 Aug 2020 09:24:25 +0200
-Subject: [PATCH] net: ethernet: mtk_eth_soc: only read the full rx
- descriptor if DMA is done
+Date: Thu, 22 Apr 2021 22:21:04 -0700
+Subject: [PATCH] net: ethernet: mtk_eth_soc: only read the full RX descriptor
+ if DMA is done
 
 Uncached memory access is expensive, and there is no need to access all
 descriptor words if we can't process them anyway
 
 Signed-off-by: Felix Fietkau <nbd at nbd.name>
+Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy at gmail.com>
+Signed-off-by: David S. Miller <davem at davemloft.net>
 ---
+ drivers/net/ethernet/mediatek/mtk_eth_soc.c | 12 ++++++++----
+ 1 file changed, 8 insertions(+), 4 deletions(-)
 
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
diff --git a/target/linux/generic/pending-5.10/770-11-net-ethernet-mtk_eth_soc-avoid-rearming-interrupt-if.patch b/target/linux/generic/backport-5.10/610-v5.13-48-net-ethernet-mtk_eth_soc-reduce-unnecessary-interrup.patch
similarity index 61%
rename from target/linux/generic/pending-5.10/770-11-net-ethernet-mtk_eth_soc-avoid-rearming-interrupt-if.patch
rename to target/linux/generic/backport-5.10/610-v5.13-48-net-ethernet-mtk_eth_soc-reduce-unnecessary-interrup.patch
index 4c61951d77c5..21e14ed1e5ab 100644
--- a/target/linux/generic/pending-5.10/770-11-net-ethernet-mtk_eth_soc-avoid-rearming-interrupt-if.patch
+++ b/target/linux/generic/backport-5.10/610-v5.13-48-net-ethernet-mtk_eth_soc-reduce-unnecessary-interrup.patch
@@ -1,12 +1,16 @@
+From 16769a8923fad5a5377253bcd76b0e0d64976c73 Mon Sep 17 00:00:00 2001
 From: Felix Fietkau <nbd at nbd.name>
-Date: Fri, 4 Sep 2020 18:14:05 +0200
-Subject: [PATCH] net: ethernet: mtk_eth_soc: avoid rearming interrupt if
- napi_complete returns false
+Date: Thu, 22 Apr 2021 22:21:05 -0700
+Subject: [PATCH] net: ethernet: mtk_eth_soc: reduce unnecessary interrupts
 
-Reduces unnecessary interrupts
+Avoid rearming interrupt if napi_complete returns false
 
 Signed-off-by: Felix Fietkau <nbd at nbd.name>
+Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy at gmail.com>
+Signed-off-by: David S. Miller <davem at davemloft.net>
 ---
+ drivers/net/ethernet/mediatek/mtk_eth_soc.c | 9 +++++----
+ 1 file changed, 5 insertions(+), 4 deletions(-)
 
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
diff --git a/target/linux/generic/backport-5.10/610-v5.13-49-net-ethernet-mtk_eth_soc-rework-NAPI-callbacks.patch b/target/linux/generic/backport-5.10/610-v5.13-49-net-ethernet-mtk_eth_soc-rework-NAPI-callbacks.patch
new file mode 100644
index 000000000000..9bc948015d24
--- /dev/null
+++ b/target/linux/generic/backport-5.10/610-v5.13-49-net-ethernet-mtk_eth_soc-rework-NAPI-callbacks.patch
@@ -0,0 +1,110 @@
+From db2c7b353db3b3f71b55f9ff4627d8a786446fbe Mon Sep 17 00:00:00 2001
+From: Ilya Lipnitskiy <ilya.lipnitskiy at gmail.com>
+Date: Thu, 22 Apr 2021 22:21:06 -0700
+Subject: [PATCH] net: ethernet: mtk_eth_soc: rework NAPI callbacks
+
+Use napi_complete_done to communicate total TX and RX work done to NAPI.
+Count total RX work up instead of remaining work down for clarity.
+Remove unneeded local variables for clarity. Use do {} while instead of
+goto for clarity.
+
+Suggested-by: Jakub Kicinski <kuba at kernel.org>
+Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy at gmail.com>
+Signed-off-by: David S. Miller <davem at davemloft.net>
+---
+ drivers/net/ethernet/mediatek/mtk_eth_soc.c | 54 +++++++++------------
+ 1 file changed, 24 insertions(+), 30 deletions(-)
+
+--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
++++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+@@ -1496,7 +1496,6 @@ static void mtk_handle_status_irq(struct
+ static int mtk_napi_tx(struct napi_struct *napi, int budget)
+ {
+ 	struct mtk_eth *eth = container_of(napi, struct mtk_eth, tx_napi);
+-	u32 status, mask;
+ 	int tx_done = 0;
+ 
+ 	if (MTK_HAS_CAPS(eth->soc->caps, MTK_QDMA))
+@@ -1505,21 +1504,19 @@ static int mtk_napi_tx(struct napi_struc
+ 	tx_done = mtk_poll_tx(eth, budget);
+ 
+ 	if (unlikely(netif_msg_intr(eth))) {
+-		status = mtk_r32(eth, eth->tx_int_status_reg);
+-		mask = mtk_r32(eth, eth->tx_int_mask_reg);
+ 		dev_info(eth->dev,
+-			 "done tx %d, intr 0x%08x/0x%x\n",
+-			 tx_done, status, mask);
++			 "done tx %d, intr 0x%08x/0x%x\n", tx_done,
++			 mtk_r32(eth, eth->tx_int_status_reg),
++			 mtk_r32(eth, eth->tx_int_mask_reg));
+ 	}
+ 
+ 	if (tx_done == budget)
+ 		return budget;
+ 
+-	status = mtk_r32(eth, eth->tx_int_status_reg);
+-	if (status & MTK_TX_DONE_INT)
++	if (mtk_r32(eth, eth->tx_int_status_reg) & MTK_TX_DONE_INT)
+ 		return budget;
+ 
+-	if (napi_complete(napi))
++	if (napi_complete_done(napi, tx_done))
+ 		mtk_tx_irq_enable(eth, MTK_TX_DONE_INT);
+ 
+ 	return tx_done;
+@@ -1528,36 +1525,33 @@ static int mtk_napi_tx(struct napi_struc
+ static int mtk_napi_rx(struct napi_struct *napi, int budget)
+ {
+ 	struct mtk_eth *eth = container_of(napi, struct mtk_eth, rx_napi);
+-	u32 status, mask;
+-	int rx_done = 0;
+-	int remain_budget = budget;
++	int rx_done_total = 0;
+ 
+ 	mtk_handle_status_irq(eth);
+ 
+-poll_again:
+-	mtk_w32(eth, MTK_RX_DONE_INT, MTK_PDMA_INT_STATUS);
+-	rx_done = mtk_poll_rx(napi, remain_budget, eth);
++	do {
++		int rx_done;
+ 
+-	if (unlikely(netif_msg_intr(eth))) {
+-		status = mtk_r32(eth, MTK_PDMA_INT_STATUS);
+-		mask = mtk_r32(eth, MTK_PDMA_INT_MASK);
+-		dev_info(eth->dev,
+-			 "done rx %d, intr 0x%08x/0x%x\n",
+-			 rx_done, status, mask);
+-	}
+-	if (rx_done == remain_budget)
+-		return budget;
++		mtk_w32(eth, MTK_RX_DONE_INT, MTK_PDMA_INT_STATUS);
++		rx_done = mtk_poll_rx(napi, budget - rx_done_total, eth);
++		rx_done_total += rx_done;
++
++		if (unlikely(netif_msg_intr(eth))) {
++			dev_info(eth->dev,
++				 "done rx %d, intr 0x%08x/0x%x\n", rx_done,
++				 mtk_r32(eth, MTK_PDMA_INT_STATUS),
++				 mtk_r32(eth, MTK_PDMA_INT_MASK));
++		}
+ 
+-	status = mtk_r32(eth, MTK_PDMA_INT_STATUS);
+-	if (status & MTK_RX_DONE_INT) {
+-		remain_budget -= rx_done;
+-		goto poll_again;
+-	}
++		if (rx_done_total == budget)
++			return budget;
++
++	} while (mtk_r32(eth, MTK_PDMA_INT_STATUS) & MTK_RX_DONE_INT);
+ 
+-	if (napi_complete(napi))
++	if (napi_complete_done(napi, rx_done_total))
+ 		mtk_rx_irq_enable(eth, MTK_RX_DONE_INT);
+ 
+-	return rx_done + budget - remain_budget;
++	return rx_done_total;
+ }
+ 
+ static int mtk_tx_alloc(struct mtk_eth *eth)
diff --git a/target/linux/generic/pending-5.10/770-14-net-ethernet-mtk_eth_soc-set-PPE-flow-hash-as-skb-ha.patch b/target/linux/generic/backport-5.10/610-v5.13-50-net-ethernet-mtk_eth_soc-set-PPE-flow-hash-as-skb-ha.patch
similarity index 68%
rename from target/linux/generic/pending-5.10/770-14-net-ethernet-mtk_eth_soc-set-PPE-flow-hash-as-skb-ha.patch
rename to target/linux/generic/backport-5.10/610-v5.13-50-net-ethernet-mtk_eth_soc-set-PPE-flow-hash-as-skb-ha.patch
index e94b352b9ce4..2355a4831d7f 100644
--- a/target/linux/generic/pending-5.10/770-14-net-ethernet-mtk_eth_soc-set-PPE-flow-hash-as-skb-ha.patch
+++ b/target/linux/generic/backport-5.10/610-v5.13-50-net-ethernet-mtk_eth_soc-set-PPE-flow-hash-as-skb-ha.patch
@@ -1,12 +1,18 @@
+From fa817272c37ef78e25dc14e4760ac78a7043a18a Mon Sep 17 00:00:00 2001
 From: Felix Fietkau <nbd at nbd.name>
-Date: Sun, 13 Sep 2020 08:27:24 +0200
-Subject: [PATCH] net: ethernet: mtk_eth_soc: set PPE flow hash as skb hash
- if present
+Date: Thu, 22 Apr 2021 22:21:07 -0700
+Subject: [PATCH] net: ethernet: mtk_eth_soc: set PPE flow hash as skb hash if
+ present
 
 This improves GRO performance
 
 Signed-off-by: Felix Fietkau <nbd at nbd.name>
+[Ilya: Use MTK_RXD4_FOE_ENTRY instead of GENMASK(13, 0)]
+Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy at gmail.com>
+Signed-off-by: David S. Miller <davem at davemloft.net>
 ---
+ drivers/net/ethernet/mediatek/mtk_eth_soc.c | 8 ++++++++
+ 1 file changed, 8 insertions(+)
 
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -30,8 +36,8 @@ Signed-off-by: Felix Fietkau <nbd at nbd.name>
  		skb->protocol = eth_type_trans(skb, netdev);
  		bytes += pktlen;
  
-+		hash = trxd.rxd4 & GENMASK(13, 0);
-+		if (hash != GENMASK(13, 0)) {
++		hash = trxd.rxd4 & MTK_RXD4_FOE_ENTRY;
++		if (hash != MTK_RXD4_FOE_ENTRY) {
 +			hash = jhash_1word(hash, 0);
 +			skb_set_hash(skb, hash, PKT_HASH_TYPE_L4);
 +		}
diff --git a/target/linux/generic/backport-5.10/610-v5.13-51-net-ethernet-mtk_eth_soc-use-iopoll.h-macro-for-DMA-.patch b/target/linux/generic/backport-5.10/610-v5.13-51-net-ethernet-mtk_eth_soc-use-iopoll.h-macro-for-DMA-.patch
new file mode 100644
index 000000000000..fd2fb0f7c418
--- /dev/null
+++ b/target/linux/generic/backport-5.10/610-v5.13-51-net-ethernet-mtk_eth_soc-use-iopoll.h-macro-for-DMA-.patch
@@ -0,0 +1,71 @@
+From 3bc8e0aff23be0526af0dbc7973a8866a08d73f1 Mon Sep 17 00:00:00 2001
+From: Ilya Lipnitskiy <ilya.lipnitskiy at gmail.com>
+Date: Thu, 22 Apr 2021 22:21:08 -0700
+Subject: [PATCH] net: ethernet: mtk_eth_soc: use iopoll.h macro for DMA init
+
+Replace a tight busy-wait loop without a pause with a standard
+readx_poll_timeout_atomic routine with a 5 us poll period.
+
+Tested by booting a MT7621 device to ensure the driver initializes
+properly.
+
+Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy at gmail.com>
+Reviewed-by: Andrew Lunn <andrew at lunn.ch>
+Signed-off-by: David S. Miller <davem at davemloft.net>
+---
+ drivers/net/ethernet/mediatek/mtk_eth_soc.c | 29 +++++++++------------
+ drivers/net/ethernet/mediatek/mtk_eth_soc.h |  2 +-
+ 2 files changed, 14 insertions(+), 17 deletions(-)
+
+--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
++++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+@@ -2033,25 +2033,22 @@ static int mtk_set_features(struct net_d
+ /* wait for DMA to finish whatever it is doing before we start using it again */
+ static int mtk_dma_busy_wait(struct mtk_eth *eth)
+ {
+-	unsigned long t_start = jiffies;
++	unsigned int reg;
++	int ret;
++	u32 val;
+ 
+-	while (1) {
+-		if (MTK_HAS_CAPS(eth->soc->caps, MTK_QDMA)) {
+-			if (!(mtk_r32(eth, MTK_QDMA_GLO_CFG) &
+-			      (MTK_RX_DMA_BUSY | MTK_TX_DMA_BUSY)))
+-				return 0;
+-		} else {
+-			if (!(mtk_r32(eth, MTK_PDMA_GLO_CFG) &
+-			      (MTK_RX_DMA_BUSY | MTK_TX_DMA_BUSY)))
+-				return 0;
+-		}
++	if (MTK_HAS_CAPS(eth->soc->caps, MTK_QDMA))
++		reg = MTK_QDMA_GLO_CFG;
++	else
++		reg = MTK_PDMA_GLO_CFG;
+ 
+-		if (time_after(jiffies, t_start + MTK_DMA_BUSY_TIMEOUT))
+-			break;
+-	}
++	ret = readx_poll_timeout_atomic(__raw_readl, eth->base + reg, val,
++					!(val & (MTK_RX_DMA_BUSY | MTK_TX_DMA_BUSY)),
++					5, MTK_DMA_BUSY_TIMEOUT_US);
++	if (ret)
++		dev_err(eth->dev, "DMA init timeout\n");
+ 
+-	dev_err(eth->dev, "DMA init timeout\n");
+-	return -1;
++	return ret;
+ }
+ 
+ static int mtk_dma_init(struct mtk_eth *eth)
+--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
++++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
+@@ -213,7 +213,7 @@
+ #define MTK_TX_DMA_BUSY		BIT(1)
+ #define MTK_RX_DMA_EN		BIT(2)
+ #define MTK_TX_DMA_EN		BIT(0)
+-#define MTK_DMA_BUSY_TIMEOUT	HZ
++#define MTK_DMA_BUSY_TIMEOUT_US	1000000
+ 
+ /* QDMA Reset Index Register */
+ #define MTK_QDMA_RST_IDX	0x1A08
diff --git a/target/linux/ramips/patches-5.10/700-net-ethernet-mediatek-support-net-labels.patch b/target/linux/ramips/patches-5.10/700-net-ethernet-mediatek-support-net-labels.patch
index ec3ca93770cb..e94999b73e7a 100644
--- a/target/linux/ramips/patches-5.10/700-net-ethernet-mediatek-support-net-labels.patch
+++ b/target/linux/ramips/patches-5.10/700-net-ethernet-mediatek-support-net-labels.patch
@@ -14,7 +14,7 @@ Signed-off-by: René van Dorst <opensource at vdorst.com>
 
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -2901,6 +2901,7 @@ static const struct net_device_ops mtk_n
+@@ -2893,6 +2893,7 @@ static const struct net_device_ops mtk_n
  
  static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
  {
@@ -22,7 +22,7 @@ Signed-off-by: René van Dorst <opensource at vdorst.com>
  	const __be32 *_id = of_get_property(np, "reg", NULL);
  	phy_interface_t phy_mode;
  	struct phylink *phylink;
-@@ -2993,6 +2994,9 @@ static int mtk_add_mac(struct mtk_eth *e
+@@ -2985,6 +2986,9 @@ static int mtk_add_mac(struct mtk_eth *e
  
  	eth->netdev[id]->max_mtu = MTK_MAX_RX_LENGTH - MTK_RX_ETH_HLEN;
  
-- 
2.31.1




More information about the openwrt-devel mailing list