[][openwrt][MAC80211][hnat][Fix issue of TCP traffic from eth1 to eth0 goes into the wrong QDMA queue, causing throughput degradation]

[Description]
Fix issue of TCP traffic from eth1 to eth0 goes into the wrong QDMA
queue, causing throughput degradation.

Without this patch, after dscp learning flow is enabled,
the PPE entry of TCP Data path might be set to high
priority queue in TCP throughput test, leads to throughput
unbalance issue and throughput degrade.

[Release-log]
N/A


Change-Id: Ic4fb1caccbae850ff2be6b794ed0659c8177d3a2
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/10890208
diff --git a/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3012-flow-offload-add-mtkhnat-qdma-qos.patch b/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3012-flow-offload-add-mtkhnat-qdma-qos.patch
index 2ad013a..467908f 100644
--- a/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3012-flow-offload-add-mtkhnat-qdma-qos.patch
+++ b/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3012-flow-offload-add-mtkhnat-qdma-qos.patch
@@ -1,19 +1,19 @@
-From c2ccdb141e1f626e826ac081b7c978a705f16caf Mon Sep 17 00:00:00 2001
-From: Bo-Cun Chen <bc-bocun.chen@mediatek.com>
-Date: Wed, 23 Oct 2024 10:29:08 +0800
-Subject: [PATCH] flow-offload-add-mtkhnat-qdma-qos
+From afe52388d50de92c69e0ce0beb22f8dbb33fc8c1 Mon Sep 17 00:00:00 2001
+From: "chak-kei.lam" <chak-kei.lam@mediatek.com>
+Date: Tue, 15 Jul 2025 10:23:04 +0800
+Subject: [PATCH] flow offload add mtkhnat qdma qos
 
 ---
  drivers/net/ethernet/mediatek/Makefile        |   2 +-
  drivers/net/ethernet/mediatek/mtk_eth_soc.c   |   2 +
- drivers/net/ethernet/mediatek/mtk_eth_soc.h   |  33 +++++
- drivers/net/ethernet/mediatek/mtk_ppe.c       |  49 ++++++-
- drivers/net/ethernet/mediatek/mtk_ppe.h       |   4 +
- .../net/ethernet/mediatek/mtk_ppe_offload.c   |  28 +++-
+ drivers/net/ethernet/mediatek/mtk_eth_soc.h   |  24 ++++
+ drivers/net/ethernet/mediatek/mtk_ppe.c       |  37 ++++-
+ drivers/net/ethernet/mediatek/mtk_ppe.h       |   3 +
+ .../net/ethernet/mediatek/mtk_ppe_offload.c   |  48 +++++--
  .../net/ethernet/mediatek/mtk_qdma_debugfs.c  | 135 ++++++++++++++++++
  include/net/flow_offload.h                    |   1 +
  net/netfilter/nf_flow_table_offload.c         |   4 +-
- 9 files changed, 253 insertions(+), 5 deletions(-)
+ 9 files changed, 244 insertions(+), 12 deletions(-)
  create mode 100644 drivers/net/ethernet/mediatek/mtk_qdma_debugfs.c
 
 diff --git a/drivers/net/ethernet/mediatek/Makefile b/drivers/net/ethernet/mediatek/Makefile
@@ -30,10 +30,10 @@
  ifdef CONFIG_DEBUG_FS
  mtk_eth-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed_debugfs.o
 diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-index c03b59a..2dcb02c 100644
+index ab93631..ca37ba5 100644
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -6462,6 +6462,8 @@ static int mtk_probe(struct platform_device *pdev)
+@@ -6707,6 +6707,8 @@ static int mtk_probe(struct platform_device *pdev)
  		}
  
  		mtk_ppe_debugfs_init(eth);
@@ -43,10 +43,10 @@
  
  	for (i = 0; i < MTK_MAX_DEVS; i++) {
 diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-index d52c29a..2e62560 100644
+index a66cffe..efad9eb 100644
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-@@ -2361,6 +2361,7 @@ struct mtk_eth {
+@@ -2383,6 +2383,7 @@ struct mtk_eth {
  	spinlock_t			syscfg0_lock;
  	struct notifier_block		netdevice_notifier;
  
@@ -54,17 +54,10 @@
  	u8				ppe_num;
  	struct mtk_ppe			*ppe[MTK_MAX_PPE_NUM];
  	struct rhashtable		flow_table;
-@@ -2433,6 +2434,36 @@ mtk_foe_get_entry(struct mtk_ppe *ppe, u16 hash)
+@@ -2462,6 +2463,27 @@ mtk_foe_get_entry(struct mtk_ppe *ppe, u16 hash)
  	return ppe->foe_table + hash * soc->foe_entry_size;
  }
  
-+static inline void mtk_set_ib1_sp(struct mtk_eth *eth, struct mtk_foe_entry *foe, u32 val)
-+{
-+#if defined(CONFIG_MEDIATEK_NETSYS_V2)
-+	foe->ib1 |= FIELD_PREP(MTK_FOE_IB1_UNBIND_SRC_PORT, val);
-+#endif
-+}
-+
 +static inline u32 mtk_get_ib1_sp(struct mtk_eth *eth, struct mtk_foe_entry *foe)
 +{
 +#if defined(CONFIG_MEDIATEK_NETSYS_V2)
@@ -75,14 +68,12 @@
 +}
 +
 +static inline int
-+mtk_ppe_check_pppq_path(struct mtk_eth *eth, struct mtk_foe_entry *foe, int dsa_port)
++mtk_ppe_check_pppq_path(struct net_device *idev, int dsa_port)
 +{
-+	u32 sp = mtk_get_ib1_sp(eth, foe);
++	bool wifi_rx = !!(idev->ieee80211_ptr);
 +
 +	if ((dsa_port >= 0 && dsa_port <= 4) ||
-+	    (dsa_port == 5 && (sp == PSE_WDMA0_PORT ||
-+			       sp == PSE_WDMA1_PORT ||
-+			       sp == PSE_WDMA2_PORT)))
++	    (dsa_port == 5 && wifi_rx))
 +		return 1;
 +
 +	return 0;
@@ -91,15 +82,15 @@
  /* read the hardware status register */
  void mtk_stats_update_mac(struct mtk_mac *mac);
  
-@@ -2470,4 +2501,6 @@ int mtk_ptp_hwtstamp_get_config(struct net_device *dev, struct ifreq *ifr);
- int mtk_ptp_clock_init(struct mtk_eth *eth);
+@@ -2500,4 +2522,6 @@ int mtk_ptp_clock_init(struct mtk_eth *eth);
+ int mtk_ptp_clock_deinit(struct mtk_eth *eth);
  
  int mtk_ppe_debugfs_init(struct mtk_eth *eth);
 +
 +int mtk_qdma_debugfs_init(struct mtk_eth *eth);
  #endif /* MTK_ETH_H */
 diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
-index ef6e992..f14e96f 100755
+index ef6e992..62b500b 100755
 --- a/drivers/net/ethernet/mediatek/mtk_ppe.c
 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
 @@ -128,7 +128,7 @@ static void mtk_ppe_cache_enable(struct mtk_ppe *ppe, bool enable)
@@ -111,7 +102,7 @@
  {
  	u32 hv1, hv2, hv3;
  	u32 hash;
-@@ -420,12 +420,59 @@ int mtk_foe_entry_set_wdma(struct mtk_foe_entry *entry, int wdma_idx, int txq,
+@@ -420,12 +420,39 @@ int mtk_foe_entry_set_wdma(struct mtk_foe_entry *entry, int wdma_idx, int txq,
  	return 0;
  }
  
@@ -125,6 +116,7 @@
 +
 +	return 0;
 +}
++
  static inline bool mtk_foe_entry_usable(struct mtk_foe_entry *entry)
  {
  	return !(entry->ib1 & MTK_FOE_IB1_STATIC) &&
@@ -147,41 +139,39 @@
 +	return !memcmp(&entry->data, &data->data, len - 4);
 +}
 +
-+int mtk_foe_entry_set_sp(struct mtk_ppe *ppe, struct mtk_foe_entry *entry)
-+{
-+	struct mtk_eth *eth = ppe->eth;
-+	struct mtk_foe_entry *hwe;
-+	u32 hash, sp = 0;
-+	int i;
-+
-+	hash = mtk_ppe_hash_entry(eth, entry);
-+	for (i = 0; i < eth->soc->hash_offset; i++) {
-+		hwe = mtk_foe_get_entry(ppe, hash + i);
-+		if (mtk_foe_entry_match(hwe, entry)) {
-+			sp = mtk_get_ib1_sp(ppe->eth, hwe);
-+			break;
-+		}
-+	}
-+
-+	mtk_set_ib1_sp(ppe->eth, entry, sp);
-+
-+	return 0;
-+}
-+
  static bool
  mtk_flow_entry_match(struct mtk_flow_entry *entry, struct mtk_foe_entry *data)
  {
+@@ -573,12 +600,18 @@ __mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_foe_entry *entry,
+ 	struct mtk_foe_entry *hwe;
+ 	u16 timestamp;
+ 
++	hwe = mtk_foe_get_entry(ppe, hash);
++
+ 	timestamp = mtk_eth_timestamp(ppe->eth);
+ 	timestamp &= MTK_FOE_IB1_BIND_TIMESTAMP;
+ 	entry->ib1 &= ~MTK_FOE_IB1_BIND_TIMESTAMP;
+ 	entry->ib1 |= FIELD_PREP(MTK_FOE_IB1_BIND_TIMESTAMP, timestamp);
++#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++	entry->ib1 &= ~MTK_FOE_IB1_BIND_SRC_PORT;
++	entry->ib1 |= FIELD_PREP(MTK_FOE_IB1_BIND_SRC_PORT,
++				 mtk_get_ib1_sp(eth, hwe));
++#endif
+ 
+-	hwe = mtk_foe_get_entry(ppe, hash);
+ 	memcpy(&hwe->data, &entry->data, eth->soc->foe_entry_size - sizeof(hwe->ib1));
+ 	wmb();
+ 	hwe->ib1 = entry->ib1;
 diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
-index 6c3fdb1..4beac4f 100644
+index 6c3fdb1..c3fbbc5 100644
 --- a/drivers/net/ethernet/mediatek/mtk_ppe.h
 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
-@@ -390,9 +390,13 @@ int mtk_foe_entry_set_vlan(struct mtk_foe_entry *entry, int vid);
+@@ -390,9 +390,12 @@ int mtk_foe_entry_set_vlan(struct mtk_foe_entry *entry, int vid);
  int mtk_foe_entry_set_pppoe(struct mtk_foe_entry *entry, int sid);
  int mtk_foe_entry_set_wdma(struct mtk_foe_entry *entry, int wdma_idx, int txq,
  			   int bss, int wcid);
 +int mtk_foe_entry_set_qid(struct mtk_foe_entry *entry, int qid);
 +bool mtk_foe_entry_match(struct mtk_foe_entry *entry, struct mtk_foe_entry *data);
-+int mtk_foe_entry_set_sp(struct mtk_ppe *ppe, struct mtk_foe_entry *entry);
  int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_flow_entry *entry);
  void mtk_foe_entry_clear(struct mtk_ppe *ppe, struct mtk_flow_entry *entry);
  int mtk_foe_entry_idle_time(struct mtk_ppe *ppe, struct mtk_flow_entry *entry);
@@ -190,75 +180,100 @@
  
  #endif
 diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
-index b80f72d..3bc50a4 100755
+index b80f72d..53cc9cf 100755
 --- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
 +++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
 @@ -9,6 +9,8 @@
  #include <linux/ipv6.h>
  #include <net/flow_offload.h>
  #include <net/pkt_cls.h>
-+#include <net/netfilter/nf_conntrack.h>
++#include <net/netfilter/nf_conntrack_acct.h>
 +#include <net/netfilter/nf_flow_table.h>
  #include <net/dsa.h>
  #include "mtk_eth_soc.h"
  #include "mtk_wed.h"
-@@ -183,7 +185,7 @@ mtk_flow_get_dsa_port(struct net_device **dev)
+@@ -183,13 +185,21 @@ mtk_flow_get_dsa_port(struct net_device **dev)
  
  static int
  mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
 -			   struct net_device *dev, const u8 *dest_mac,
-+			   struct net_device *dev, struct nf_conn *ct, const u8 *dest_mac,
++			   struct net_device *idev, struct net_device *odev,
++			   struct flow_cls_offload *f, const u8 *dest_mac,
  			   int *wed_index)
  {
  	struct mtk_wdma_info info = {};
-@@ -209,6 +211,9 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
- 	if (dsa_port >= 0)
- 		mtk_foe_entry_set_dsa(foe, dsa_port);
+-	int pse_port, dsa_port;
++	struct nf_conn *ct = NULL;
++	u32 ct_mark = 0;
++	int pse_port, dsa_port, queue;
+ 
+-	if (mtk_flow_get_wdma_info(dev, dest_mac, &info) == 0) {
++	if (f->flow && f->flow->ct) {
++		ct = f->flow->ct;
++		ct_mark = ct->mark;
++	}
++
++	if (mtk_flow_get_wdma_info(odev, dest_mac, &info) == 0) {
+ 		mtk_foe_entry_set_wdma(foe, info.wdma_idx, info.queue, info.bss,
+ 				       info.wcid);
+ 		pse_port = PSE_PPE0_PORT;
+@@ -205,18 +215,40 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
+ 		goto out;
+ 	}
  
-+	if (eth->qos_toggle == 2 && mtk_ppe_check_pppq_path(eth, foe, dsa_port))
-+		mtk_foe_entry_set_qid(foe, dsa_port & MTK_QDMA_TX_MASK);
+-	dsa_port = mtk_flow_get_dsa_port(&dev);
+-	if (dsa_port >= 0)
++	dsa_port = mtk_flow_get_dsa_port(&odev);
++	if (dsa_port >= 0) {
++		queue = dsa_port;
+ 		mtk_foe_entry_set_dsa(foe, dsa_port);
++	}
 +
- 	if (dev == eth->netdev[0])
++	if (eth->qos_toggle == 2 && mtk_ppe_check_pppq_path(idev, dsa_port))
++		mtk_foe_entry_set_qid(foe, queue & MTK_QDMA_TX_MASK);
+ 
+-	if (dev == eth->netdev[0])
++	if (odev == eth->netdev[0])
  		pse_port = PSE_GDM1_PORT;
- 	else if (dev == eth->netdev[1])
-@@ -217,6 +222,23 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
+-	else if (dev == eth->netdev[1])
++	else if (odev == eth->netdev[1])
+ 		pse_port = PSE_GDM2_PORT;
+ 	else
  		return -EOPNOTSUPP;
  
  out:
-+	if (eth->qos_toggle == 1 || (ct->mark & MTK_QDMA_TX_MASK) >= 6) {
++	if (eth->qos_toggle == 1 || (ct_mark & MTK_QDMA_TX_MASK) >= 6) {
 +		u8 qos_ul_toggle;
 +
 +		if (eth->qos_toggle == 2)
-+			qos_ul_toggle = ((ct->mark >> 16) & MTK_QDMA_TX_MASK) >= 6 ? 1 : 0;
++			qos_ul_toggle = ((ct_mark >> 16) & MTK_QDMA_TX_MASK) >= 6 ? 1 : 0;
 +		else
-+			qos_ul_toggle = ((ct->mark >> 16) & MTK_QDMA_TX_MASK) >= 1 ? 1 : 0;
++			qos_ul_toggle = ((ct_mark >> 16) & MTK_QDMA_TX_MASK) >= 1 ? 1 : 0;
 +
 +		if (qos_ul_toggle == 1) {
-+			if (dev == eth->netdev[1])
-+				mtk_foe_entry_set_qid(foe, (ct->mark >> 16) & MTK_QDMA_TX_MASK);
++			if (odev == eth->netdev[1])
++				mtk_foe_entry_set_qid(foe, (ct_mark >> 16) & MTK_QDMA_TX_MASK);
 +			else
-+				mtk_foe_entry_set_qid(foe, ct->mark & MTK_QDMA_TX_MASK);
++				mtk_foe_entry_set_qid(foe, ct_mark & MTK_QDMA_TX_MASK);
 +		} else
-+			mtk_foe_entry_set_qid(foe, ct->mark & MTK_QDMA_TX_MASK);
++			mtk_foe_entry_set_qid(foe, ct_mark & MTK_QDMA_TX_MASK);
 +	}
 +
  	mtk_foe_entry_set_pse_port(foe, pse_port);
  
  	return 0;
-@@ -447,7 +469,9 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
+@@ -447,7 +479,7 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
  	if (data.pppoe.num == 1)
  		mtk_foe_entry_set_pppoe(&foe, data.pppoe.sid);
  
 -	err = mtk_flow_set_output_device(eth, &foe, odev, data.eth.h_dest,
-+	mtk_foe_entry_set_sp(eth->ppe[ppe_index], &foe);
-+
-+	err = mtk_flow_set_output_device(eth, &foe, odev, f->flow->ct, data.eth.h_dest,
++	err = mtk_flow_set_output_device(eth, &foe, idev, odev, f, data.eth.h_dest,
  					 &wed_index);
  	if (err)
  		return err;
 diff --git a/drivers/net/ethernet/mediatek/mtk_qdma_debugfs.c b/drivers/net/ethernet/mediatek/mtk_qdma_debugfs.c
 new file mode 100644
-index 0000000..3d7f183
+index 0000000..e8839b7
 --- /dev/null
 +++ b/drivers/net/ethernet/mediatek/mtk_qdma_debugfs.c
 @@ -0,0 +1,135 @@
diff --git a/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3015-ethernet-update-ppe-from-netsys2-to-netsys3.patch b/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3015-ethernet-update-ppe-from-netsys2-to-netsys3.patch
index 52fc71c..d8b26b4 100644
--- a/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3015-ethernet-update-ppe-from-netsys2-to-netsys3.patch
+++ b/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3015-ethernet-update-ppe-from-netsys2-to-netsys3.patch
@@ -1,22 +1,22 @@
-From ff4a3d8474dae9eedbb2618049b3ea9e23e8760e Mon Sep 17 00:00:00 2001
+From d0e367a6b186ec998eae326c7fa3438a62585588 Mon Sep 17 00:00:00 2001
 From: "chak-kei.lam" <chak-kei.lam@mediatek.com>
-Date: Tue, 11 Mar 2025 17:25:41 +0800
+Date: Mon, 14 Jul 2025 14:30:14 +0800
 Subject: [PATCH] ethernet update ppe from netsys2 to netsys3
 
 ---
  drivers/net/ethernet/mediatek/mtk_eth_soc.c   | 13 +++-
- drivers/net/ethernet/mediatek/mtk_eth_soc.h   |  7 +-
+ drivers/net/ethernet/mediatek/mtk_eth_soc.h   |  5 +-
  drivers/net/ethernet/mediatek/mtk_ppe.c       | 74 +++++++++++++++++--
- drivers/net/ethernet/mediatek/mtk_ppe.h       | 44 ++++++++++--
+ drivers/net/ethernet/mediatek/mtk_ppe.h       | 44 +++++++++--
  .../net/ethernet/mediatek/mtk_ppe_offload.c   |  6 +-
- drivers/net/ethernet/mediatek/mtk_ppe_regs.h  |  8 +++
+ drivers/net/ethernet/mediatek/mtk_ppe_regs.h  |  8 ++
  6 files changed, 131 insertions(+), 19 deletions(-)
 
 diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-index 27a5645..8578897 100644
+index ca37ba5..01ddb22 100644
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -2741,7 +2741,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
+@@ -2730,7 +2730,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
  			skb_checksum_none_assert(skb);
  		skb->protocol = eth_type_trans(skb, netdev);
  
@@ -25,7 +25,7 @@
  		hash = trxd.rxd5 & MTK_RXD5_FOE_ENTRY_V2;
  		reason = FIELD_GET(MTK_RXD5_PPE_CPU_REASON_V2, trxd.rxd5);
  		if (hash != MTK_RXD5_FOE_ENTRY_V2)
-@@ -6643,7 +6643,8 @@ static int mtk_probe(struct platform_device *pdev)
+@@ -6694,7 +6694,8 @@ static int mtk_probe(struct platform_device *pdev)
  
  		for (i = 0; i < eth->ppe_num; i++) {
  			eth->ppe[i] = mtk_ppe_init(eth,
@@ -35,7 +35,7 @@
  						   i);
  			if (!eth->ppe[i]) {
  				err = -ENOMEM;
-@@ -6944,6 +6945,10 @@ static const struct mtk_soc_data mt7988_data = {
+@@ -6998,6 +6999,10 @@ static const struct mtk_soc_data mt7988_data = {
  	.required_clks = MT7988_CLKS_BITMAP,
  	.required_pctl = false,
  	.has_sram = true,
@@ -46,7 +46,7 @@
  	.rss_num = 4,
  	.txrx = {
  		.txd_size = sizeof(struct mtk_tx_dma_v2),
-@@ -6965,6 +6970,10 @@ static const struct mtk_soc_data mt7987_data = {
+@@ -7019,6 +7024,10 @@ static const struct mtk_soc_data mt7987_data = {
  	.required_clks = MT7987_CLKS_BITMAP,
  	.required_pctl = false,
  	.has_sram = true,
@@ -58,7 +58,7 @@
  	.txrx = {
  		.txd_size = sizeof(struct mtk_tx_dma_v2),
 diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-index fab7366..0628d22 100644
+index efad9eb..708e32c 100644
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
 @@ -195,9 +195,10 @@
@@ -73,15 +73,7 @@
  #else
  #define MTK_GDMA_TO_PPE0	0x4444
  #endif
-@@ -2458,14 +2459,14 @@ mtk_foe_get_entry(struct mtk_ppe *ppe, u16 hash)
- 
- static inline void mtk_set_ib1_sp(struct mtk_eth *eth, struct mtk_foe_entry *foe, u32 val)
- {
--#if defined(CONFIG_MEDIATEK_NETSYS_V2)
-+#if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
- 	foe->ib1 |= FIELD_PREP(MTK_FOE_IB1_UNBIND_SRC_PORT, val);
- #endif
- }
+@@ -2465,7 +2466,7 @@ mtk_foe_get_entry(struct mtk_ppe *ppe, u16 hash)
  
  static inline u32 mtk_get_ib1_sp(struct mtk_eth *eth, struct mtk_foe_entry *foe)
  {
@@ -91,7 +83,7 @@
  #else
  	return 0;
 diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
-index f14e96f..86e8f4f 100755
+index 62b500b..fdb6dc0 100755
 --- a/drivers/net/ethernet/mediatek/mtk_ppe.c
 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
 @@ -91,7 +91,7 @@ static int mtk_ppe_mib_wait_busy(struct mtk_ppe *ppe)
@@ -180,7 +172,7 @@
  	*ib2 |=  FIELD_PREP(MTK_FOE_IB2_RX_IDX, txq);
  
  	l2->winfo = FIELD_PREP(MTK_FOE_WINFO_WCID, wcid) |
-@@ -422,14 +454,34 @@ int mtk_foe_entry_set_wdma(struct mtk_foe_entry *entry, int wdma_idx, int txq,
+@@ -422,15 +454,33 @@ int mtk_foe_entry_set_wdma(struct mtk_foe_entry *entry, int wdma_idx, int txq,
  
  int mtk_foe_entry_set_qid(struct mtk_foe_entry *entry, int qid)
  {
@@ -191,13 +183,12 @@
  	*ib2 |= FIELD_PREP(MTK_FOE_IB2_QID, qid);
 +#if defined(CONFIG_MEDIATEK_NETSYS_V3)
 +	l2->tport_id = 1;
-+#else
- 	*ib2 |= MTK_FOE_IB2_PSE_QOS;
 +#endif
-+
-+	return 0;
-+}
-+
+ 	*ib2 |= MTK_FOE_IB2_PSE_QOS;
+ 
+ 	return 0;
+ }
+ 
 +int mtk_foe_entry_set_keep_dscp_ecn(struct mtk_foe_entry *entry, bool keep_en)
 +{
 +#if defined(CONFIG_MEDIATEK_NETSYS_V3)
@@ -208,14 +199,23 @@
 +	*udf |= FIELD_PREP(MTK_FOE_UDF_KEEP_ECN, keep_en) |
 +		FIELD_PREP(MTK_FOE_UDF_KEEP_DSCP, keep_en);
 +#endif
- 
- 	return 0;
- }
++
++	return 0;
++}
 +
  static inline bool mtk_foe_entry_usable(struct mtk_foe_entry *entry)
  {
  	return !(entry->ib1 & MTK_FOE_IB1_STATIC) &&
-@@ -950,14 +1000,20 @@ int mtk_ppe_start(struct mtk_ppe *ppe)
+@@ -606,7 +656,7 @@ __mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_foe_entry *entry,
+ 	timestamp &= MTK_FOE_IB1_BIND_TIMESTAMP;
+ 	entry->ib1 &= ~MTK_FOE_IB1_BIND_TIMESTAMP;
+ 	entry->ib1 |= FIELD_PREP(MTK_FOE_IB1_BIND_TIMESTAMP, timestamp);
+-#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++#if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
+ 	entry->ib1 &= ~MTK_FOE_IB1_BIND_SRC_PORT;
+ 	entry->ib1 |= FIELD_PREP(MTK_FOE_IB1_BIND_SRC_PORT,
+ 				 mtk_get_ib1_sp(eth, hwe));
+@@ -936,14 +986,20 @@ int mtk_ppe_start(struct mtk_ppe *ppe)
  	mtk_ppe_init_foe_table(ppe);
  	ppe_w32(ppe, MTK_PPE_TB_BASE, ppe->foe_phys);
  
@@ -238,7 +238,7 @@
  #endif
  	      FIELD_PREP(MTK_PPE_TB_CFG_SEARCH_MISS,
  			 MTK_PPE_SEARCH_MISS_ACTION_FORWARD_BUILD) |
-@@ -1016,12 +1072,16 @@ int mtk_ppe_start(struct mtk_ppe *ppe)
+@@ -1002,12 +1058,16 @@ int mtk_ppe_start(struct mtk_ppe *ppe)
  	      MTK_PPE_GLO_CFG_IP4_L4_CS_DROP |
  	      MTK_PPE_GLO_CFG_IP4_CS_DROP |
  	      MTK_PPE_GLO_CFG_MCAST_TB_EN |
@@ -257,7 +257,7 @@
  	ppe_w32(ppe, MTK_PPE_SBW_CTRL, 0x7f);
  #endif
 diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
-index 4beac4f..a5def6f 100644
+index c3fbbc5..d1d30c5 100644
 --- a/drivers/net/ethernet/mediatek/mtk_ppe.h
 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
 @@ -8,7 +8,10 @@
@@ -368,13 +368,13 @@
  int mtk_foe_entry_set_qid(struct mtk_foe_entry *entry, int qid);
 +int mtk_foe_entry_set_keep_dscp_ecn(struct mtk_foe_entry *entry, bool keep_en);
  bool mtk_foe_entry_match(struct mtk_foe_entry *entry, struct mtk_foe_entry *data);
- int mtk_foe_entry_set_sp(struct mtk_ppe *ppe, struct mtk_foe_entry *entry);
  int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_flow_entry *entry);
+ void mtk_foe_entry_clear(struct mtk_ppe *ppe, struct mtk_flow_entry *entry);
 diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
-index 3bc50a4..f0c63da 100755
+index 6eb5fe9..38af97c 100755
 --- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
 +++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
-@@ -195,7 +195,7 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
+@@ -283,7 +283,7 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
  		mtk_foe_entry_set_wdma(foe, info.wdma_idx, info.queue, info.bss,
  				       info.wcid);
  		pse_port = PSE_PPE0_PORT;
@@ -383,16 +383,16 @@
  		if (info.wdma_idx == 0)
  			pse_port = PSE_WDMA0_PORT;
  		else if (info.wdma_idx == 1)
-@@ -218,6 +218,8 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
+@@ -316,6 +316,8 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
  		pse_port = PSE_GDM1_PORT;
- 	else if (dev == eth->netdev[1])
+ 	else if (odev == eth->netdev[1])
  		pse_port = PSE_GDM2_PORT;
-+	else if (dev == eth->netdev[2])
++	else if (odev == eth->netdev[2])
 +		pse_port = PSE_GDM3_PORT;
  	else
  		return -EOPNOTSUPP;
  
-@@ -376,7 +378,7 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
+@@ -474,7 +476,7 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
  	if (err)
  		return err;
  
diff --git a/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3017-flow-offload-add-mtkhnat-dscp.patch b/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3017-flow-offload-add-mtkhnat-dscp.patch
index ff96352..e349802 100644
--- a/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3017-flow-offload-add-mtkhnat-dscp.patch
+++ b/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3017-flow-offload-add-mtkhnat-dscp.patch
@@ -25,7 +25,7 @@
  create mode 100644 net/netfilter/nf_conntrack_qos.c
 
 diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
-index 7d74302..e4d775f 100755
+index 6c5d648..40ef828 100755
 --- a/drivers/net/ethernet/mediatek/mtk_ppe.c
 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
 @@ -468,6 +468,16 @@ int mtk_foe_entry_set_qid(struct mtk_foe_entry *entry, int qid)
@@ -46,7 +46,7 @@
  {
  #if defined(CONFIG_MEDIATEK_NETSYS_V3)
 diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
-index a5def6f..961d548 100644
+index d1d30c5..6c80525 100644
 --- a/drivers/net/ethernet/mediatek/mtk_ppe.h
 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
 @@ -422,6 +422,7 @@ int mtk_foe_entry_set_tops_entry(struct mtk_foe_entry *entry, int tops_entry);
@@ -56,30 +56,30 @@
 +int mtk_foe_entry_set_dscp(struct mtk_foe_entry *entry, int dscp);
  int mtk_foe_entry_set_keep_dscp_ecn(struct mtk_foe_entry *entry, bool keep_en);
  bool mtk_foe_entry_match(struct mtk_foe_entry *entry, struct mtk_foe_entry *data);
- int mtk_foe_entry_set_sp(struct mtk_ppe *ppe, struct mtk_foe_entry *entry);
+ int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_flow_entry *entry);
 diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
-index c1cce76..b9983d7 100644
+index 41c08da..88379dd 100644
 --- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
 +++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
-@@ -186,7 +186,7 @@ mtk_flow_get_dsa_port(struct net_device **dev)
- static int
+@@ -267,7 +267,7 @@ static int
  mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
- 			   struct net_device *dev, struct nf_conn *ct, const u8 *dest_mac,
+ 			   struct net_device *idev, struct net_device *odev,
+ 			   struct flow_cls_offload *f, const u8 *dest_mac,
 -			   int *wed_index)
 +			   int *wed_index, int dscp)
  {
  	struct mtk_wdma_info info = {};
- 	int pse_port, dsa_port;
-@@ -224,6 +224,8 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
+ 	struct nf_conn *ct = NULL;
+@@ -322,6 +322,8 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
  		return -EOPNOTSUPP;
  
  out:
 +	mtk_foe_entry_set_dscp(foe, dscp);
 +
- 	if (eth->qos_toggle == 1 || (ct->mark & MTK_QDMA_TX_MASK) >= 6) {
+ 	if (eth->qos_toggle == 1 || (ct_mark & MTK_QDMA_TX_MASK) >= 6) {
  		u8 qos_ul_toggle;
  
-@@ -262,6 +264,7 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
+@@ -360,6 +362,7 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
  	int wed_index = -1;
  	u16 addr_type = 0;
  	u8 l4proto = 0;
@@ -87,7 +87,7 @@
  	int err = 0;
  	int i;
  
-@@ -298,6 +301,15 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
+@@ -396,6 +399,15 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
  		return -EOPNOTSUPP;
  	}
  
@@ -103,10 +103,10 @@
  	switch (addr_type) {
  	case 0:
  		offload_type = MTK_PPE_PKT_TYPE_BRIDGE;
-@@ -474,7 +486,7 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
- 	mtk_foe_entry_set_sp(eth->ppe[ppe_index], &foe);
+@@ -570,7 +582,7 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
+ 		mtk_foe_entry_set_pppoe(&foe, data.pppoe.sid);
  
- 	err = mtk_flow_set_output_device(eth, &foe, odev, f->flow->ct, data.eth.h_dest,
+ 	err = mtk_flow_set_output_device(eth, &foe, idev, odev, f, data.eth.h_dest,
 -					 &wed_index);
 +					 &wed_index, dscp);
  	if (err)
@@ -134,7 +134,7 @@
  #define NF_CT_EXT_TIMEOUT_TYPE struct nf_conn_timeout
 diff --git a/include/net/netfilter/nf_conntrack_qos.h b/include/net/netfilter/nf_conntrack_qos.h
 new file mode 100644
-index 0000000..67a9f2d
+index 0000000..d2934da
 --- /dev/null
 +++ b/include/net/netfilter/nf_conntrack_qos.h
 @@ -0,0 +1,64 @@
@@ -478,7 +478,7 @@
  }
  
 diff --git a/net/netfilter/nft_flow_offload.c b/net/netfilter/nft_flow_offload.c
-index ab542a0..a26936e 100644
+index ab542a0..9b06403 100644
 --- a/net/netfilter/nft_flow_offload.c
 +++ b/net/netfilter/nft_flow_offload.c
 @@ -11,6 +11,7 @@
diff --git a/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3019-mtk-wed-add-wed3-support.patch b/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3019-mtk-wed-add-wed3-support.patch
index 8bb6e79..47294ec 100644
--- a/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3019-mtk-wed-add-wed3-support.patch
+++ b/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3019-mtk-wed-add-wed3-support.patch
@@ -22,10 +22,10 @@
  mode change 100755 => 100644 drivers/net/ethernet/mediatek/mtk_ppe.c
 
 diff --git a/arch/arm64/boot/dts/mediatek/mt7988.dtsi b/arch/arm64/boot/dts/mediatek/mt7988.dtsi
-index b2b2fde..d6737fe 100644
+index 3e2f206..450169d 100644
 --- a/arch/arm64/boot/dts/mediatek/mt7988.dtsi
 +++ b/arch/arm64/boot/dts/mediatek/mt7988.dtsi
-@@ -241,44 +241,49 @@
+@@ -262,44 +262,49 @@
  		status = "disabled";
  	};
  
@@ -110,7 +110,7 @@
  	};
  
  	wdma: wdma@15104800 {
-@@ -288,15 +293,25 @@
+@@ -309,15 +314,25 @@
  		      <0 0x15105000 0 0x400>;
  	};
  
@@ -144,7 +144,7 @@
  	};
  
  	wocpu0_ilm: wocpu0_ilm@151E0000 {
-@@ -304,31 +319,53 @@
+@@ -325,31 +340,53 @@
  		reg = <0 0x151E0000 0 0x8000>;
  	};
  
@@ -212,7 +212,7 @@
  	};
  
  	reserved-memory {
-@@ -941,6 +978,7 @@
+@@ -963,6 +1000,7 @@
  					 <&topckgen CK_TOP_CB_SGM_325M>;
  		mediatek,ethsys = <&ethsys>;
  		mediatek,sgmiisys = <&sgmiisys0>, <&sgmiisys1>;
@@ -221,10 +221,10 @@
  		mediatek,xfi_pextp = <&xfi_pextp0>, <&xfi_pextp1>;
  		mediatek,xfi_pll = <&xfi_pll>;
 diff --git a/arch/arm64/boot/dts/mediatek/mt7988a-dsa-10g-spim-nor.dts b/arch/arm64/boot/dts/mediatek/mt7988a-dsa-10g-spim-nor.dts
-index e0f1326..2f50104 100644
+index f0e15ba..3452a0d 100644
 --- a/arch/arm64/boot/dts/mediatek/mt7988a-dsa-10g-spim-nor.dts
 +++ b/arch/arm64/boot/dts/mediatek/mt7988a-dsa-10g-spim-nor.dts
-@@ -435,9 +435,23 @@
+@@ -455,9 +455,23 @@
  	status = "okay";
  };
  
@@ -251,10 +251,10 @@
 +};
 \ No newline at end of file
 diff --git a/arch/arm64/boot/dts/mediatek/mt7988d-dsa-10g-spim-nor.dts b/arch/arm64/boot/dts/mediatek/mt7988d-dsa-10g-spim-nor.dts
-index 3df84cc..37b86dc 100644
+index 71732e5..00ff8a9 100644
 --- a/arch/arm64/boot/dts/mediatek/mt7988d-dsa-10g-spim-nor.dts
 +++ b/arch/arm64/boot/dts/mediatek/mt7988d-dsa-10g-spim-nor.dts
-@@ -445,9 +445,23 @@
+@@ -465,9 +465,23 @@
  	status = "okay";
  };
  
@@ -283,7 +283,7 @@
 diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
 old mode 100755
 new mode 100644
-index 2ff0426..71a161f
+index 40ef828..37cac84
 --- a/drivers/net/ethernet/mediatek/mtk_ppe.c
 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
 @@ -9,6 +9,7 @@
@@ -294,7 +294,7 @@
  #include "mtk_eth_soc.h"
  #include "mtk_ppe.h"
  #include "mtk_ppe_regs.h"
-@@ -407,7 +408,7 @@ int mtk_foe_entry_set_pppoe(struct mtk_foe_entry *entry, int sid)
+@@ -428,7 +429,7 @@ int mtk_foe_entry_set_tops_entry(struct mtk_foe_entry *entry, int tops_entry)
  }
  
  int mtk_foe_entry_set_wdma(struct mtk_foe_entry *entry, int wdma_idx, int txq,
@@ -303,7 +303,7 @@
  {
  	struct mtk_foe_mac_info *l2 = mtk_foe_entry_l2(entry);
  	u32 *ib2 = mtk_foe_entry_ib2(entry);
-@@ -419,6 +420,11 @@ int mtk_foe_entry_set_wdma(struct mtk_foe_entry *entry, int wdma_idx, int txq,
+@@ -440,6 +441,11 @@ int mtk_foe_entry_set_wdma(struct mtk_foe_entry *entry, int wdma_idx, int txq,
  
  	l2->winfo = FIELD_PREP(MTK_FOE_WINFO_WCID, wcid) |
  		    FIELD_PREP(MTK_FOE_WINFO_BSS, bss);
@@ -316,20 +316,20 @@
  	if (wdma_idx)
  		*ib2 |= MTK_FOE_IB2_WDMA_DEVIDX;
 diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
-index 43fbe1d..38a3776 100644
+index 6c80525..4356b2a 100644
 --- a/drivers/net/ethernet/mediatek/mtk_ppe.h
 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
-@@ -414,7 +414,7 @@ int mtk_foe_entry_set_dsa(struct mtk_foe_entry *entry, int port);
- int mtk_foe_entry_set_vlan(struct mtk_foe_entry *entry, int vid);
+@@ -420,7 +420,7 @@ int mtk_foe_entry_set_vlan(struct mtk_foe_entry *entry, int vid);
  int mtk_foe_entry_set_pppoe(struct mtk_foe_entry *entry, int sid);
+ int mtk_foe_entry_set_tops_entry(struct mtk_foe_entry *entry, int tops_entry);
  int mtk_foe_entry_set_wdma(struct mtk_foe_entry *entry, int wdma_idx, int txq,
 -			   int bss, int wcid);
 +			   int bss, int wcid, int tid, bool amsdu_en);
  int mtk_foe_entry_set_qid(struct mtk_foe_entry *entry, int qid);
  int mtk_foe_entry_set_dscp(struct mtk_foe_entry *entry, int dscp);
- bool mtk_foe_entry_match(struct mtk_foe_entry *entry, struct mtk_foe_entry *data);
+ int mtk_foe_entry_set_keep_dscp_ecn(struct mtk_foe_entry *entry, bool keep_en);
 diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
-index b9983d7..64b1d9e 100644
+index 88379dd..f3c3b21 100644
 --- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
 +++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
 @@ -88,7 +88,7 @@ mtk_flow_offload_mangle_eth(const struct flow_action_entry *act, void *eth)
@@ -358,12 +358,12 @@
  
  	return 0;
  }
-@@ -191,15 +194,17 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
- 	struct mtk_wdma_info info = {};
- 	int pse_port, dsa_port;
+@@ -279,15 +282,17 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
+ 		ct_mark = ct->mark;
+ 	}
  
--	if (mtk_flow_get_wdma_info(dev, dest_mac, &info) == 0) {
-+	if (mtk_flow_get_wdma_info(dev, dest_mac, &info, dscp) == 0) {
+-	if (mtk_flow_get_wdma_info(odev, dest_mac, &info) == 0) {
++	if (mtk_flow_get_wdma_info(odev, dest_mac, &info, dscp) == 0) {
  		mtk_foe_entry_set_wdma(foe, info.wdma_idx, info.queue, info.bss,
 -				       info.wcid);
 +				       info.wcid, info.tid, info.amsdu);
@@ -3649,10 +3649,10 @@
 +#define MTK_WED_PCIE_BASE2			0x11290000
  #endif
 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
-index 0a7eb9a..33e5f5f 100644
+index ccfc040..703a4cb 100644
 --- a/include/linux/netdevice.h
 +++ b/include/linux/netdevice.h
-@@ -880,6 +880,13 @@ struct net_device_path {
+@@ -883,6 +883,13 @@ struct net_device_path {
  			u8 queue;
  			u16 wcid;
  			u8 bss;
diff --git a/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3023-mtk-ppe-dispatch-short-packets-to-high-prio.patch b/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3023-mtk-ppe-dispatch-short-packets-to-high-prio.patch
index d0ad23e..d9e1771 100644
--- a/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3023-mtk-ppe-dispatch-short-packets-to-high-prio.patch
+++ b/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3023-mtk-ppe-dispatch-short-packets-to-high-prio.patch
@@ -1,58 +1,120 @@
 From e8a6054c824c5c65abd501bfd7437a3d7c5f2751 Mon Sep 17 00:00:00 2001
 From: Bo-Cun Chen <bc-bocun.chen@mediatek.com>
 Date: Tue, 28 Nov 2023 13:25:03 +0800
-Subject: [PATCH 23/24] 
- mtk-ppe-dispatch-short-packets-to-high-priority-TXQ-in-PPPQ
+Subject: [PATCH] mtk ppe dispatch short packets to high priority TXQ in PPPQ
 
 ---
- drivers/net/ethernet/mediatek/mtk_ppe.c | 27 +++++++++++++++++++++++++
- 1 file changed, 27 insertions(+)
+ .../net/ethernet/mediatek/mtk_ppe_offload.c   | 90 ++++++++++++++++++-
+ 1 file changed, 89 insertions(+), 1 deletion(-)
 
-diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
-index ae0acd5..547b5a0 100644
---- a/drivers/net/ethernet/mediatek/mtk_ppe.c
-+++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
-@@ -451,6 +451,31 @@ int mtk_foe_entry_set_qid(struct mtk_foe_entry *entry, int qid)
- 	return 0;
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
+index e901011..b0973f5 100644
+--- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
++++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
+@@ -190,6 +190,86 @@ mtk_flow_get_dsa_port(struct net_device **dev, int *proto)
+ #endif
  }
  
-+void mtk_foe_entry_adjust_qid(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
++static int
++mtk_flow_get_ct_dir(struct mtk_eth *eth, struct mtk_foe_entry *foe,
++		    struct nf_conn *ct)
 +{
-+	struct mtk_foe_mac_info *l2 = mtk_foe_entry_l2(&entry->data);
-+	u32 *ib2 = mtk_foe_entry_ib2(&entry->data);
-+	u8 qid;
++	const struct nf_conntrack_tuple *tuple;
++	struct mtk_foe_entry ct_entry = {0};
++	int i, j;
 +
-+#if defined(CONFIG_MEDIATEK_NETSYS_V3)
-+	if (l2->tport_id != 1)
-+		return;
-+#else
-+	if (!(*ib2 & MTK_FOE_IB2_PSE_QOS))
-+		return;
-+#endif
++	if (!eth || !foe || !ct)
++		return -EINVAL;
 +
-+	qid = FIELD_GET(MTK_FOE_IB2_QID, *ib2);
-+	/* To enhance performance in the unbalanced PHY rate test,
-+	 * dispatching short packets to the high priority TXQ.
-+	 */
-+	if (ppe->eth->qos_toggle == 2 && qid < 6) {
-+		qid += 6;
-+		*ib2 &= ~MTK_FOE_IB2_QID;
-+		*ib2 |= FIELD_PREP(MTK_FOE_IB2_QID, qid);
++	ct_entry.ib1 = foe->ib1;
++
++	for (i = 0; i < IP_CT_DIR_MAX; i++) {
++		tuple = &ct->tuplehash[i].tuple;
++
++		if (FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, foe->ib1) > MTK_PPE_PKT_TYPE_IPV4_DSLITE) {
++			if (nf_ct_l3num(ct) != AF_INET6)
++				return -EINVAL;
++
++			for (j = 0; j < 4; j++) {
++				ct_entry.ipv6.src_ip[j] = ntohl(tuple->src.u3.in6.s6_addr32[j]);
++				ct_entry.ipv6.dest_ip[j] = ntohl(tuple->dst.u3.in6.s6_addr32[j]);
++			}
++			ct_entry.ipv6.src_port = ntohs(tuple->src.u.tcp.port);
++			ct_entry.ipv6.dest_port = ntohs( tuple->dst.u.tcp.port);
++		} else {
++			if (nf_ct_l3num(ct) != AF_INET)
++				return -EINVAL;
++
++			ct_entry.ipv4.orig.src_ip = ntohl(tuple->src.u3.ip);
++			ct_entry.ipv4.orig.dest_ip = ntohl(tuple->dst.u3.ip);
++			ct_entry.ipv4.orig.src_port = ntohs(tuple->src.u.tcp.port);
++			ct_entry.ipv4.orig.dest_port = ntohs(tuple->dst.u.tcp.port);
++		}
++
++		if (mtk_foe_entry_match(&ct_entry, foe))
++			return i;
 +	}
++
++	return -EINVAL;
 +}
 +
- int mtk_foe_entry_set_dscp(struct mtk_foe_entry *entry, int dscp)
- {
- 	u32 *ib2 = mtk_foe_entry_ib2(entry);
-@@ -790,6 +815,9 @@ void __mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash)
- 			continue;
- 		}
- 
-+		if (skb && skb->len < 100)
-+			mtk_foe_entry_adjust_qid(ppe, entry);
++static bool
++mtk_flow_is_tcp_ack(struct mtk_eth *eth, struct mtk_foe_entry *foe,
++		    struct nf_conn *ct)
++{
++	const struct nf_conn_counter *counters;
++	struct nf_conn_acct *acct;
++	u64 packets[IP_CT_DIR_MAX], bytes[IP_CT_DIR_MAX], avg[IP_CT_DIR_MAX];
++	int dir;
 +
- 		entry->hash = hash;
- 		__mtk_foe_entry_commit(ppe, &entry->data, hash);
- 		found = true;
++	if (!ct)
++		return false;
++
++	dir = mtk_flow_get_ct_dir(eth, foe, ct);
++	if (dir < 0 || dir >= IP_CT_DIR_MAX)
++		return false;
++
++	acct = nf_conn_acct_find(ct);
++	if (!acct)
++		return false;
++
++	counters = acct->counter;
++	packets[dir] = atomic64_read(&counters[dir].packets);
++	bytes[dir] = atomic64_read(&counters[dir].bytes);
++	packets[!dir] = atomic64_read(&counters[!dir].packets);
++	bytes[!dir] = atomic64_read(&counters[!dir].bytes);
++
++	/* Avoid division by zero */
++	if (!packets[dir] || !packets[!dir])
++		return false;
++
++	avg[dir] = bytes[dir] / packets[dir];
++	avg[!dir] = bytes[!dir] / packets[!dir];
++
++	/* TCP ACKs are small packets (<= 64 bytes) compared to data packets */
++	return (avg[dir] <= 64 && avg[dir] < avg[!dir]);
++}
++
+ static int
+ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
+ 			   struct net_device *idev, struct net_device *odev,
+@@ -230,8 +310,16 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
+ 		mtk_foe_entry_set_dsa(foe, dsa_proto, dsa_port);
+ 	}
+ 
+-	if (eth->qos_toggle == 2 && mtk_ppe_check_pppq_path(idev, dsa_port))
++	if (eth->qos_toggle == 2 && mtk_ppe_check_pppq_path(idev, dsa_port)) {
++		if ((dsa_port >= 0) && ct && nf_ct_protonum(ct) == IPPROTO_TCP) {
++			/* Dispatch the IPv4/IPv6 TCP Ack packets to the high-priority
++			 * queue, assuming they are less than 64 bytes.
++			 */
++			if (mtk_flow_is_tcp_ack(eth, foe, ct))
++				queue += 6;
++		}
+ 		mtk_foe_entry_set_qid(foe, queue & MTK_QDMA_TX_MASK);
++	}
+ 
+ 	if (odev == eth->netdev[0])
+ 		pse_port = PSE_GDM1_PORT;
 -- 
-2.18.0
+2.45.2
diff --git a/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3025-flow-offload-add-mtkhnat-roaming.patch b/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3025-flow-offload-add-mtkhnat-roaming.patch
index ecd063c..4239737 100644
--- a/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3025-flow-offload-add-mtkhnat-roaming.patch
+++ b/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3025-flow-offload-add-mtkhnat-roaming.patch
@@ -12,10 +12,10 @@
  5 files changed, 260 insertions(+)
 
 diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-index 72fb677..60994c5 100644
+index 95b388b..cfb1035 100644
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -4233,6 +4233,12 @@ static int mtk_open(struct net_device *dev)
+@@ -4564,6 +4564,12 @@ static int mtk_open(struct net_device *dev)
  		if (err)
  			return err;
  
@@ -28,7 +28,7 @@
  
  		/* Indicates CDM to parse the MTK special tag from CPU */
  		if (netdev_uses_dsa(dev)) {
-@@ -4420,6 +4426,8 @@ static int mtk_stop(struct net_device *dev)
+@@ -4824,6 +4830,8 @@ static int mtk_stop(struct net_device *dev)
  	if (eth->soc->offload_version) {
  		for (i = 0; i < eth->ppe_num; i++)
  			mtk_ppe_stop(eth->ppe[i]);
@@ -38,12 +38,12 @@
  
  	return 0;
 diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-index dc0530c..81111b0 100644
+index 2f9e7db..5a69cac 100644
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-@@ -2008,10 +2008,14 @@ struct mtk_eth {
+@@ -2384,10 +2384,14 @@ struct mtk_eth {
+ 	spinlock_t			syscfg0_lock;
  	struct notifier_block		netdevice_notifier;
- 	struct timer_list		mtk_dma_monitor_timer;
  
 +	u8				debug_level;
  	u8				qos_toggle;
@@ -57,7 +57,7 @@
  
  /* struct mtk_mac -	the structure that holds the info about the MACs of the
 diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
-index 7aa9a8c..eb701ad 100644
+index e3b0388..4bf7c43 100644
 --- a/drivers/net/ethernet/mediatek/mtk_ppe.c
 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
 @@ -10,6 +10,7 @@
@@ -68,7 +68,7 @@
  #include "mtk_eth_soc.h"
  #include "mtk_ppe.h"
  #include "mtk_ppe_regs.h"
-@@ -510,6 +511,28 @@ bool mtk_foe_entry_match(struct mtk_foe_entry *entry, struct mtk_foe_entry *data
+@@ -545,6 +546,28 @@ bool mtk_foe_entry_match(struct mtk_foe_entry *entry, struct mtk_foe_entry *data
  	return !memcmp(&entry->data, &data->data, len - 4);
  }
  
@@ -94,10 +94,10 @@
 +	return false;
 +}
 +
- int mtk_foe_entry_set_sp(struct mtk_ppe *ppe, struct mtk_foe_entry *entry)
+ static bool
+ mtk_flow_entry_match(struct mtk_flow_entry *entry, struct mtk_foe_entry *data)
  {
- 	struct mtk_eth *eth = ppe->eth;
-@@ -1136,3 +1159,171 @@ int mtk_ppe_stop(struct mtk_ppe *ppe)
+@@ -1159,3 +1182,171 @@ int mtk_ppe_stop(struct mtk_ppe *ppe)
  
  	return 0;
  }
@@ -270,10 +270,10 @@
 +	return 0;
 +}
 diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
-index 38a3776..c74deae 100644
+index 4356b2a..36f8ecd 100644
 --- a/drivers/net/ethernet/mediatek/mtk_ppe.h
 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
-@@ -381,6 +381,8 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int index)
+@@ -386,6 +386,8 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int index)
  void mtk_ppe_deinit(struct mtk_eth *eth);
  int mtk_ppe_start(struct mtk_ppe *ppe);
  int mtk_ppe_stop(struct mtk_ppe *ppe);
diff --git a/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3033-flow-offload-add-mxl862-switch-dsa-tag-8021q-support.patch b/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3033-flow-offload-add-mxl862-switch-dsa-tag-8021q-support.patch
index a91995b..ec053cb 100644
--- a/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3033-flow-offload-add-mxl862-switch-dsa-tag-8021q-support.patch
+++ b/autobuild/autobuild_5.4_mac80211_release/target/linux/mediatek/patches-5.4/999-3033-flow-offload-add-mxl862-switch-dsa-tag-8021q-support.patch
@@ -4,13 +4,13 @@
 Subject: [PATCH] flow offload add mxl862 switch dsa tag 8021q support
 
 ---
- drivers/net/ethernet/mediatek/mtk_ppe.c       | 25 +++++++++-----
+ drivers/net/ethernet/mediatek/mtk_ppe.c       | 25 +++++++++++-----
  drivers/net/ethernet/mediatek/mtk_ppe.h       |  2 +-
- .../net/ethernet/mediatek/mtk_ppe_offload.c   | 34 +++++++++++--------
- 3 files changed, 37 insertions(+), 24 deletions(-)
+ .../net/ethernet/mediatek/mtk_ppe_offload.c   | 30 +++++++++++--------
+ 3 files changed, 35 insertions(+), 22 deletions(-)
 
 diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
-index 41428a9..48c39f7 100644
+index 4bf7c43..b26259b 100644
 --- a/drivers/net/ethernet/mediatek/mtk_ppe.c
 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
 @@ -365,20 +365,29 @@ int mtk_foe_entry_set_ipv6_tuple(struct mtk_foe_entry *entry,
@@ -52,7 +52,7 @@
  
  int mtk_foe_entry_set_vlan(struct mtk_foe_entry *entry, int vid)
 diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
-index 1aa2511..e1673b0 100644
+index 36f8ecd..81d870a 100644
 --- a/drivers/net/ethernet/mediatek/mtk_ppe.h
 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
 @@ -417,7 +417,7 @@ int mtk_foe_entry_set_ipv4_tuple(struct mtk_foe_entry *entry, bool orig,
@@ -65,7 +65,7 @@
  int mtk_foe_entry_set_pppoe(struct mtk_foe_entry *entry, int sid);
  int mtk_foe_entry_set_tops_entry(struct mtk_foe_entry *entry, int tops_entry);
 diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
-index e68d00f..cb430ce 100644
+index 93c08f0..8ad774b 100644
 --- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
 +++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
 @@ -166,7 +166,7 @@ mtk_flow_mangle_ipv4(const struct flow_action_entry *act,
@@ -92,28 +92,29 @@
  
  	return dp->index;
  #else
-@@ -193,7 +196,7 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
- 			   int *wed_index, int dscp)
- {
+@@ -276,7 +279,7 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
  	struct mtk_wdma_info info = {};
--	int pse_port, dsa_port;
-+	int pse_port, dsa_port, dsa_proto;
+ 	struct nf_conn *ct = NULL;
+ 	u32 ct_mark = 0;
+-	int pse_port, dsa_port, queue;
++	int pse_port, dsa_port, dsa_proto, queue;
  
- 	if (mtk_flow_get_wdma_info(dev, dest_mac, &info, dscp) == 0) {
- 		mtk_foe_entry_set_wdma(foe, info.wdma_idx, info.queue, info.bss,
-@@ -213,9 +216,9 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
+ 	if (f->flow && f->flow->ct) {
+ 		ct = f->flow->ct;
+@@ -301,10 +304,10 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
  		goto out;
  	}
  
--	dsa_port = mtk_flow_get_dsa_port(&dev);
-+	dsa_port = mtk_flow_get_dsa_port(&dev, &dsa_proto);
- 	if (dsa_port >= 0)
+-	dsa_port = mtk_flow_get_dsa_port(&odev);
++	dsa_port = mtk_flow_get_dsa_port(&odev, &dsa_proto);
+ 	if (dsa_port >= 0) {
+ 		queue = dsa_port;
 -		mtk_foe_entry_set_dsa(foe, dsa_port);
 +		mtk_foe_entry_set_dsa(foe, dsa_proto, dsa_port);
+ 	}
  
- 	if (eth->qos_toggle == 2 && mtk_ppe_check_pppq_path(eth, foe, dsa_port))
- 		mtk_foe_entry_set_qid(foe, dsa_port & MTK_QDMA_TX_MASK);
-@@ -397,6 +400,7 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
+ 	if (eth->qos_toggle == 2 && mtk_ppe_check_pppq_path(idev, dsa_port)) {
+@@ -495,6 +498,7 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
  		return err;
  
  #if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
@@ -121,13 +122,11 @@
  	if (idev && idev->netdev_ops->ndo_fill_receive_path) {
  		ctx.dev = idev;
  		idev->netdev_ops->ndo_fill_receive_path(&ctx, &path);
-@@ -477,6 +481,16 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
+@@ -575,6 +579,14 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
  			return err;
  	}
  
-+	mtk_foe_entry_set_sp(eth->ppe[ppe_index], &foe);
-+
-+	err = mtk_flow_set_output_device(eth, &foe, odev, f->flow->ct, data.eth.h_dest,
++	err = mtk_flow_set_output_device(eth, &foe, idev, odev, f, data.eth.h_dest,
 +					 &wed_index, dscp);
 +	if (err)
 +		return err;
@@ -138,13 +137,11 @@
  	if (offload_type == MTK_PPE_PKT_TYPE_BRIDGE)
  		foe.bridge.vlan = data.vlan_in;
  
-@@ -489,16 +503,6 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
+@@ -587,14 +599,6 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
  	if (data.pppoe.num == 1)
  		mtk_foe_entry_set_pppoe(&foe, data.pppoe.sid);
  
--	mtk_foe_entry_set_sp(eth->ppe[ppe_index], &foe);
--
--	err = mtk_flow_set_output_device(eth, &foe, odev, f->flow->ct, data.eth.h_dest,
+-	err = mtk_flow_set_output_device(eth, &foe, idev, odev, f, data.eth.h_dest,
 -					 &wed_index, dscp);
 -	if (err)
 -		return err;