[][MAC80211][hnat][Revert Flowblock framework patch]
[Description]
Rollback and revert commit of "Sync Flowblock framework to the OpenWRT_trunk_20230525 patch"
Side effect of uplink traffic only with 2~3Gbps
[Release-log]
N/A
Change-Id: I4b1d5a3d543cfafd2f0282ee6ad33329f2fd7c9d
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/7637426
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3003-mt7986-backport-nf-hw-offload-framework-230525.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3003-mt7622-backport-nf-hw-offload-framework-and-ups.patch
similarity index 79%
rename from autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3003-mt7986-backport-nf-hw-offload-framework-230525.patch
rename to autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3003-mt7622-backport-nf-hw-offload-framework-and-ups.patch
index 4072c31..b52782f 100755
--- a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3003-mt7986-backport-nf-hw-offload-framework-230525.patch
+++ b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3003-mt7622-backport-nf-hw-offload-framework-and-ups.patch
@@ -1,20 +1,21 @@
-From 4c2019ace3cb414c5a8b7939a7368266d6a6339a Mon Sep 17 00:00:00 2001
-From: Bo-Cun Chen <bc-bocun.chen@mediatek.com>
-Date: Wed, 14 Jun 2023 16:24:07 +0800
-Subject: [PATCH] 999-3003-mt7986-backport-nf-hw-offload-framework-230525
+From 6ad9bd65769003ab526e504577e0f747eba14287 Mon Sep 17 00:00:00 2001
+From: Bo Jiao <Bo.Jiao@mediatek.com>
+Date: Wed, 22 Jun 2022 09:42:19 +0800
+Subject: [PATCH 1/8]
+ 9990-mt7622-backport-nf-hw-offload-framework-and-upstream-hnat-plus-xt-FLOWOFFLOAD-update-v2
---
drivers/net/ethernet/mediatek/Makefile | 3 +-
- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 86 +-
- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 111 +-
- drivers/net/ethernet/mediatek/mtk_ppe.c | 1089 +++++++++++++++
- drivers/net/ethernet/mediatek/mtk_ppe.h | 384 ++++++
- .../net/ethernet/mediatek/mtk_ppe_debugfs.c | 221 +++
- .../net/ethernet/mediatek/mtk_ppe_offload.c | 566 ++++++++
- drivers/net/ethernet/mediatek/mtk_ppe_regs.h | 172 +++
+ drivers/net/ethernet/mediatek/mtk_eth_soc.c | 28 +-
+ drivers/net/ethernet/mediatek/mtk_eth_soc.h | 20 +-
+ drivers/net/ethernet/mediatek/mtk_ppe.c | 509 +++++++
+ drivers/net/ethernet/mediatek/mtk_ppe.h | 288 ++++
+ .../net/ethernet/mediatek/mtk_ppe_debugfs.c | 214 +++
+ .../net/ethernet/mediatek/mtk_ppe_offload.c | 526 ++++++++
+ drivers/net/ethernet/mediatek/mtk_ppe_regs.h | 144 ++
drivers/net/ppp/ppp_generic.c | 22 +
drivers/net/ppp/pppoe.c | 24 +
- include/linux/netdevice.h | 71 +
+ include/linux/netdevice.h | 60 +
include/linux/ppp_channel.h | 3 +
include/net/dsa.h | 10 +
include/net/flow_offload.h | 4 +
@@ -22,7 +23,7 @@
.../net/netfilter/ipv6/nf_conntrack_ipv6.h | 3 -
include/net/netfilter/nf_conntrack.h | 12 +
include/net/netfilter/nf_conntrack_acct.h | 11 +
- include/net/netfilter/nf_flow_table.h | 265 +++-
+ include/net/netfilter/nf_flow_table.h | 264 +++-
include/net/netns/conntrack.h | 6 +
.../linux/netfilter/nf_conntrack_common.h | 9 +-
include/uapi/linux/netfilter/xt_FLOWOFFLOAD.h | 17 +
@@ -32,7 +33,7 @@
net/bridge/br_vlan.c | 55 +
net/core/dev.c | 46 +
net/dsa/dsa.c | 9 +
- net/dsa/slave.c | 37 +-
+ net/dsa/slave.c | 41 +-
net/ipv4/netfilter/Kconfig | 4 +-
net/ipv6/ip6_output.c | 2 +-
net/ipv6/netfilter/Kconfig | 3 +-
@@ -43,11 +44,11 @@
net/netfilter/nf_conntrack_proto_tcp.c | 4 +
net/netfilter/nf_conntrack_proto_udp.c | 4 +
net/netfilter/nf_conntrack_standalone.c | 34 +-
- net/netfilter/nf_flow_table_core.c | 445 +++---
- net/netfilter/nf_flow_table_ip.c | 450 ++++---
- net/netfilter/nf_flow_table_offload.c | 1194 +++++++++++++++++
- net/netfilter/xt_FLOWOFFLOAD.c | 795 +++++++++++
- 43 files changed, 5883 insertions(+), 443 deletions(-)
+ net/netfilter/nf_flow_table_core.c | 446 +++---
+ net/netfilter/nf_flow_table_ip.c | 455 ++++---
+ net/netfilter/nf_flow_table_offload.c | 1191 +++++++++++++++++
+ net/netfilter/xt_FLOWOFFLOAD.c | 719 ++++++++++
+ 43 files changed, 4913 insertions(+), 432 deletions(-)
create mode 100644 drivers/net/ethernet/mediatek/mtk_ppe.c
create mode 100644 drivers/net/ethernet/mediatek/mtk_ppe.h
create mode 100644 drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
@@ -58,10 +59,10 @@
create mode 100644 net/netfilter/xt_FLOWOFFLOAD.c
diff --git a/drivers/net/ethernet/mediatek/Makefile b/drivers/net/ethernet/mediatek/Makefile
-index 13d852c..cfffde4 100755
+index 13c5b4e8f..0a6af99f1 100755
--- a/drivers/net/ethernet/mediatek/Makefile
+++ b/drivers/net/ethernet/mediatek/Makefile
-@@ -4,6 +4,7 @@
+@@ -4,5 +4,6 @@
#
obj-$(CONFIG_NET_MEDIATEK_SOC) += mtk_eth.o
@@ -69,100 +70,41 @@
+mtk_eth-y := mtk_eth_soc.o mtk_sgmii.o mtk_usxgmii.o mtk_eth_path.o mtk_eth_dbg.o mtk_eth_reset.o \
+ mtk_ppe.o mtk_ppe_debugfs.o mtk_ppe_offload.o
obj-$(CONFIG_NET_MEDIATEK_HNAT) += mtk_hnat/
- obj-$(CONFIG_XFRM_OFFLOAD) += mtk_ipsec.o
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-index 23e2172..76ba1e8 100755
+index 2b21f7ed0..819d8a0be 100755
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -2108,6 +2108,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
- unsigned int pktlen, *rxdcsum;
- struct net_device *netdev = NULL;
- dma_addr_t dma_addr = 0;
-+ u32 hash, reason;
- int mac = 0;
-
- if (eth->hwlro)
-@@ -2188,10 +2189,21 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
- skb->dev = netdev;
- skb_put(skb, pktlen);
-
-- if ((MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_RX_V2)))
-+ if ((MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_RX_V2))) {
-+ reason = FIELD_GET(MTK_RXD5_PPE_CPU_REASON, trxd.rxd5);
-+ hash = trxd.rxd5 & MTK_RXD5_FOE_ENTRY;
-+ if (hash != MTK_RXD5_FOE_ENTRY)
-+ skb_set_hash(skb, jhash_1word(hash, 0),
-+ PKT_HASH_TYPE_L4);
- rxdcsum = &trxd.rxd3;
-- else
-+ } else {
-+ reason = FIELD_GET(MTK_RXD4_PPE_CPU_REASON, trxd.rxd4);
-+ hash = trxd.rxd4 & MTK_RXD4_FOE_ENTRY;
-+ if (hash != MTK_RXD4_FOE_ENTRY)
-+ skb_set_hash(skb, jhash_1word(hash, 0),
-+ PKT_HASH_TYPE_L4);
- rxdcsum = &trxd.rxd4;
-+ }
-
- if (*rxdcsum & eth->soc->txrx.rx_dma_l4_valid)
- skb->ip_summed = CHECKSUM_UNNECESSARY;
-@@ -2199,6 +2211,9 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
- skb_checksum_none_assert(skb);
- skb->protocol = eth_type_trans(skb, netdev);
-
-+ if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED)
-+ mtk_ppe_check_skb(eth->ppe[0], skb, hash);
-+
- if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) {
- if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_RX_V2)) {
- if (trxd.rxd3 & RX_DMA_VTAG_V2)
-@@ -3472,8 +3487,10 @@ static int mtk_open(struct net_device *dev)
- {
- struct mtk_mac *mac = netdev_priv(dev);
- struct mtk_eth *eth = mac->hw;
-+ const struct mtk_soc_data *soc = eth->soc;
+@@ -3081,6 +3081,7 @@ static int mtk_open(struct net_device *d
struct mtk_phylink_priv *phylink_priv = &mac->phylink_priv;
- u32 id = mtk_mac2xgmii_id(eth, mac->id);
-+ u32 gdm_config;
int err, i;
struct device_node *phy_node;
-
-@@ -3487,10 +3504,11 @@ static int mtk_open(struct net_device *dev)
- /* we run 2 netdevs on the same dma ring so we only bring it up once */
- if (!refcount_read(ð->dma_refcnt)) {
- int err = mtk_start_dma(eth);
--
- if (err)
- return err;
++ u32 gdm_config = MTK_GDMA_TO_PDMA;
-+ for (i = 0; i < ARRAY_SIZE(eth->ppe); i++)
-+ mtk_ppe_start(eth->ppe[i]);
-
- /* Indicates CDM to parse the MTK special tag from CPU */
- if (netdev_uses_dsa(dev)) {
-@@ -3553,7 +3571,10 @@ static int mtk_open(struct net_device *dev)
- regmap_write(eth->sgmii->pcs[id].regmap,
- SGMSYS_QPHY_PWR_STATE_CTRL, 0);
+ err = phylink_of_phy_connect(mac->phylink, mac->of_node, 0);
+ if (err) {
+@@ -3157,7 +3158,10 @@ static int mtk_open(struct net_device *d
+ if (!phy_node && eth->xgmii->regmap_sgmii[mac->id])
+ regmap_write(eth->xgmii->regmap_sgmii[mac->id], SGMSYS_QPHY_PWR_STATE_CTRL, 0);
- mtk_gdm_config(eth, mac->id, MTK_GDMA_TO_PDMA);
-+ gdm_config = soc->offload_version ? soc->reg_map->gdma_to_ppe0
-+ : MTK_GDMA_TO_PDMA;
++ if (eth->soc->offload_version && mtk_ppe_start(ð->ppe) == 0)
++ gdm_config = MTK_GDMA_TO_PPE;
+
+ mtk_gdm_config(eth, mac->id, gdm_config);
return 0;
}
-@@ -3633,6 +3654,9 @@ static int mtk_stop(struct net_device *dev)
+@@ -3238,6 +3242,9 @@ static int mtk_stop(struct net_device *d
mtk_dma_free(eth);
-+ for (i = 0; i < ARRAY_SIZE(eth->ppe); i++)
-+ mtk_ppe_stop(eth->ppe[i]);
++ if (eth->soc->offload_version)
++ mtk_ppe_stop(ð->ppe);
+
return 0;
}
-@@ -4408,6 +4432,7 @@ static const struct net_device_ops mtk_netdev_ops = {
+@@ -3915,6 +3922,7 @@ static const struct net_device_ops mtk_n
#ifdef CONFIG_NET_POLL_CONTROLLER
.ndo_poll_controller = mtk_poll_controller,
#endif
@@ -170,25 +112,15 @@
};
static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
-@@ -4828,6 +4853,27 @@ static int mtk_probe(struct platform_device *pdev)
+@@ -4308,6 +4316,17 @@ static int mtk_probe(struct platform_dev
goto err_free_dev;
}
+ if (eth->soc->offload_version) {
-+ u32 num_ppe;
-+
-+ num_ppe = MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ? 2 : 1;
-+ num_ppe = min_t(u32, ARRAY_SIZE(eth->ppe), num_ppe);
-+ for (i = 0; i < num_ppe; i++) {
-+ u32 ppe_addr = eth->soc->reg_map->ppe_base[i];
-+
-+ eth->ppe[i] = mtk_ppe_init(eth, eth->base + ppe_addr, i);
-+
-+ if (!eth->ppe[i]) {
-+ err = -ENOMEM;
-+ goto err_free_dev;
-+ }
-+ }
++ err = mtk_ppe_init(ð->ppe, eth->dev,
++ eth->base + MTK_ETH_PPE_BASE, 2);
++ if (err)
++ goto err_free_dev;
+
+ err = mtk_eth_offload_init(eth);
+ if (err)
@@ -198,96 +130,40 @@
for (i = 0; i < MTK_MAX_DEVS; i++) {
if (!eth->netdev[i])
continue;
-@@ -4931,6 +4977,10 @@ static const struct mtk_soc_data mt2701_data = {
+@@ -4410,6 +4429,7 @@ static const struct mtk_soc_data mt2701_
.required_clks = MT7623_CLKS_BITMAP,
.required_pctl = true,
.has_sram = false,
-+ .has_accounting = false,
-+ .hash_offset = 2,
-+ .offload_version = 1,
-+ .foe_entry_size = sizeof(struct mtk_foe_entry) - 16,
- .rss_num = 0,
++ .offload_version = 2,
+ .rss_num = 0,
.txrx = {
.txd_size = sizeof(struct mtk_tx_dma),
-@@ -4948,6 +4998,10 @@ static const struct mtk_soc_data mt7621_data = {
+@@ -4424,6 +4444,7 @@ static const struct mtk_soc_data mt7621_
.required_clks = MT7621_CLKS_BITMAP,
.required_pctl = false,
.has_sram = false,
-+ .has_accounting = false,
-+ .hash_offset = 2,
-+ .offload_version = 1,
-+ .foe_entry_size = sizeof(struct mtk_foe_entry) - 16,
- .rss_num = 0,
++ .offload_version = 2,
+ .rss_num = 0,
.txrx = {
.txd_size = sizeof(struct mtk_tx_dma),
-@@ -4966,6 +5020,10 @@ static const struct mtk_soc_data mt7622_data = {
+@@ -4439,6 +4460,7 @@ static const struct mtk_soc_data mt7622_
.required_clks = MT7622_CLKS_BITMAP,
.required_pctl = false,
.has_sram = false,
-+ .has_accounting = true,
-+ .hash_offset = 2,
+ .offload_version = 2,
-+ .foe_entry_size = sizeof(struct mtk_foe_entry) - 16,
- .rss_num = 0,
+ .rss_num = 0,
.txrx = {
.txd_size = sizeof(struct mtk_tx_dma),
-@@ -4983,6 +5041,10 @@ static const struct mtk_soc_data mt7623_data = {
+@@ -4453,6 +4475,7 @@ static const struct mtk_soc_data mt7623_
.required_clks = MT7623_CLKS_BITMAP,
.required_pctl = true,
.has_sram = false,
-+ .has_accounting = false,
-+ .hash_offset = 2,
-+ .offload_version = 1,
-+ .foe_entry_size = sizeof(struct mtk_foe_entry) - 16,
- .rss_num = 0,
- .txrx = {
- .txd_size = sizeof(struct mtk_tx_dma),
-@@ -5001,6 +5063,10 @@ static const struct mtk_soc_data mt7629_data = {
- .required_clks = MT7629_CLKS_BITMAP,
- .required_pctl = false,
- .has_sram = false,
-+ .has_accounting = true,
-+ .hash_offset = 2,
+ .offload_version = 2,
-+ .foe_entry_size = sizeof(struct mtk_foe_entry) - 16,
- .rss_num = 0,
+ .rss_num = 0,
.txrx = {
.txd_size = sizeof(struct mtk_tx_dma),
-@@ -5019,6 +5085,10 @@ static const struct mtk_soc_data mt7986_data = {
- .required_clks = MT7986_CLKS_BITMAP,
- .required_pctl = false,
- .has_sram = true,
-+ .has_accounting = true,
-+ .hash_offset = 4,
-+ .offload_version = 2,
-+ .foe_entry_size = sizeof(struct mtk_foe_entry),
- .rss_num = 0,
- .txrx = {
- .txd_size = sizeof(struct mtk_tx_dma_v2),
-@@ -5037,6 +5107,10 @@ static const struct mtk_soc_data mt7981_data = {
- .required_clks = MT7981_CLKS_BITMAP,
- .required_pctl = false,
- .has_sram = true,
-+ .has_accounting = true,
-+ .hash_offset = 4,
-+ .offload_version = 2,
-+ .foe_entry_size = sizeof(struct mtk_foe_entry),
- .rss_num = 0,
- .txrx = {
- .txd_size = sizeof(struct mtk_tx_dma_v2),
-@@ -5072,6 +5146,10 @@ static const struct mtk_soc_data rt5350_data = {
- .required_clks = MT7628_CLKS_BITMAP,
- .required_pctl = false,
- .has_sram = false,
-+ .has_accounting = false,
-+ .hash_offset = 2,
-+ .offload_version = 1,
-+ .foe_entry_size = sizeof(struct mtk_foe_entry) - 16,
- .rss_num = 0,
- .txrx = {
- .txd_size = sizeof(struct mtk_tx_dma),
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-index 06c2b0a..54790df 100755
+index b6380ffeb..349f98503 100755
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
@@ -15,6 +15,8 @@
@@ -299,7 +175,7 @@
#define MTK_QDMA_PAGE_SIZE 2048
#define MTK_MAX_RX_LENGTH 1536
-@@ -44,7 +46,8 @@
+@@ -37,7 +39,8 @@
NETIF_F_HW_VLAN_CTAG_TX | \
NETIF_F_SG | NETIF_F_TSO | \
NETIF_F_TSO6 | \
@@ -309,15 +185,15 @@
#define MTK_SET_FEATURES (NETIF_F_LRO | \
NETIF_F_HW_VLAN_CTAG_RX)
#define MTK_HW_FEATURES_MT7628 (NETIF_F_SG | NETIF_F_RXCSUM)
-@@ -121,6 +124,7 @@
+@@ -107,6 +110,7 @@
+ #define MTK_GDMA_TCS_EN BIT(21)
#define MTK_GDMA_UCS_EN BIT(20)
- #define MTK_GDMA_STRP_CRC BIT(16)
#define MTK_GDMA_TO_PDMA 0x0
+#define MTK_GDMA_TO_PPE 0x4444
#define MTK_GDMA_DROP_ALL 0x7777
- /* GDM Egress Control Register */
-@@ -604,11 +608,22 @@
+ /* Unicast Filter MAC Address Register - Low */
+@@ -547,6 +551,12 @@
#define RX_DMA_TCI(_x) ((_x) & (VLAN_PRIO_MASK | VLAN_VID_MASK))
#define RX_DMA_VPID(_x) (((_x) >> 16) & 0xffff)
@@ -330,153 +206,38 @@
/* QDMA descriptor rxd4 */
#define RX_DMA_L4_VALID BIT(24)
#define RX_DMA_L4_VALID_PDMA BIT(30) /* when PDMA is used */
- #define RX_DMA_SPECIAL_TAG BIT(22) /* switch header in packet */
-
-+/* PDMA descriptor rxd5 */
-+#define MTK_RXD5_FOE_ENTRY GENMASK(14, 0)
-+#define MTK_RXD5_PPE_CPU_REASON GENMASK(22, 18)
-+#define MTK_RXD5_SRC_PORT GENMASK(29, 26)
-+
- #define RX_DMA_GET_SPORT(_x) (((_x) >> RX_DMA_SPORT_SHIFT) & RX_DMA_SPORT_MASK)
- #define RX_DMA_GET_SPORT_V2(_x) (((_x) >> RX_DMA_SPORT_SHIFT_V2) & RX_DMA_SPORT_MASK_V2)
-
-@@ -1598,6 +1613,10 @@ struct mtk_reg_map {
- * the target SoC
- * @required_pctl A bool value to show whether the SoC requires
- * the extra setup for those pins used by GMAC.
-+ * @hash_offset Flow table hash offset.
-+ * @foe_entry_size Foe table entry size.
-+ * @has_accounting Bool indicating support for accounting of
-+ * offloaded flows.
- * @txd_size Tx DMA descriptor size.
- * @rxd_size Rx DMA descriptor size.
- * @rx_dma_l4_valid Rx DMA valid register mask.
-@@ -1611,8 +1630,12 @@ struct mtk_soc_data {
- u64 caps;
- u64 required_clks;
+@@ -1158,6 +1168,7 @@ struct mtk_soc_data {
+ u32 caps;
+ u32 required_clks;
bool required_pctl;
+ u8 offload_version;
-+ u8 hash_offset;
-+ u16 foe_entry_size;
netdev_features_t hw_features;
bool has_sram;
-+ bool has_accounting;
- struct {
- u32 txd_size;
- u32 rxd_size;
-@@ -1803,6 +1826,9 @@ struct mtk_eth {
+ };
+@@ -1271,6 +1282,9 @@ struct mtk_eth {
int ip_align;
spinlock_t syscfg0_lock;
struct timer_list mtk_dma_monitor_timer;
+
-+ struct mtk_ppe *ppe[2];
++ struct mtk_ppe ppe;
+ struct rhashtable flow_table;
};
/* struct mtk_mac - the structure that holds the info about the MACs of the
-@@ -1838,6 +1864,86 @@ extern const struct of_device_id of_mtk_match[];
- extern u32 mtk_hwlro_stats_ebl;
- extern u32 dbg_show_level;
-
-+static inline struct mtk_foe_entry *
-+mtk_foe_get_entry(struct mtk_ppe *ppe, u16 hash)
-+{
-+ const struct mtk_soc_data *soc = ppe->eth->soc;
-+
-+ return ppe->foe_table + hash * soc->foe_entry_size;
-+}
-+
-+static inline u32 mtk_get_ib1_ts_mask(struct mtk_eth *eth)
-+{
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
-+ return MTK_FOE_IB1_BIND_TIMESTAMP_V2;
-+
-+ return MTK_FOE_IB1_BIND_TIMESTAMP;
-+}
-+
-+static inline u32 mtk_get_ib1_ppoe_mask(struct mtk_eth *eth)
-+{
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
-+ return MTK_FOE_IB1_BIND_PPPOE_V2;
-+
-+ return MTK_FOE_IB1_BIND_PPPOE;
-+}
-+
-+static inline u32 mtk_get_ib1_vlan_tag_mask(struct mtk_eth *eth)
-+{
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
-+ return MTK_FOE_IB1_BIND_VLAN_TAG_V2;
-+
-+ return MTK_FOE_IB1_BIND_VLAN_TAG;
-+}
-+
-+static inline u32 mtk_get_ib1_vlan_layer_mask(struct mtk_eth *eth)
-+{
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
-+ return MTK_FOE_IB1_BIND_VLAN_LAYER_V2;
-+
-+ return MTK_FOE_IB1_BIND_VLAN_LAYER;
-+}
-+
-+static inline u32 mtk_prep_ib1_vlan_layer(struct mtk_eth *eth, u32 val)
-+{
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
-+ return FIELD_PREP(MTK_FOE_IB1_BIND_VLAN_LAYER_V2, val);
-+
-+ return FIELD_PREP(MTK_FOE_IB1_BIND_VLAN_LAYER, val);
-+}
-+
-+static inline u32 mtk_get_ib1_vlan_layer(struct mtk_eth *eth, u32 val)
-+{
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
-+ return FIELD_GET(MTK_FOE_IB1_BIND_VLAN_LAYER_V2, val);
-+
-+ return FIELD_GET(MTK_FOE_IB1_BIND_VLAN_LAYER, val);
-+}
-+
-+static inline u32 mtk_get_ib1_pkt_type_mask(struct mtk_eth *eth)
-+{
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
-+ return MTK_FOE_IB1_PACKET_TYPE_V2;
-+
-+ return MTK_FOE_IB1_PACKET_TYPE;
-+}
-+
-+static inline u32 mtk_get_ib1_pkt_type(struct mtk_eth *eth, u32 val)
-+{
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
-+ return FIELD_GET(MTK_FOE_IB1_PACKET_TYPE_V2, val);
-+
-+ return FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, val);
-+}
-+
-+static inline u32 mtk_get_ib2_multicast_mask(struct mtk_eth *eth)
-+{
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
-+ return MTK_FOE_IB2_MULTICAST_V2;
-+
-+ return MTK_FOE_IB2_MULTICAST;
-+}
-+
- /* read the hardware status register */
- void mtk_stats_update_mac(struct mtk_mac *mac);
-
-@@ -1863,6 +1969,9 @@ int mtk_usxgmii_init(struct mtk_eth *eth, struct device_node *r);
- int mtk_toprgu_init(struct mtk_eth *eth, struct device_node *r);
+@@ -1319,4 +1333,7 @@ int mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id);
+ void mtk_usxgmii_reset(struct mtk_xgmii *ss, int mac_id);
int mtk_dump_usxgmii(struct regmap *pmap, char *name, u32 offset, u32 range);
+int mtk_eth_offload_init(struct mtk_eth *eth);
+int mtk_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,
+ void *type_data);
void mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev);
- int mtk_rss_set_indr_tbl(struct mtk_eth *eth, int num);
- #endif /* MTK_ETH_H */
diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
new file mode 100644
-index 0000000..de34366
+index 000000000..66298e223
--- /dev/null
+++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
-@@ -0,0 +1,1089 @@
+@@ -0,0 +1,509 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (C) 2020 Felix Fietkau <nbd@nbd.name> */
+
@@ -485,23 +246,9 @@
+#include <linux/iopoll.h>
+#include <linux/etherdevice.h>
+#include <linux/platform_device.h>
-+#include <linux/if_ether.h>
-+#include <linux/if_vlan.h>
-+#include <net/dst_metadata.h>
-+#include <net/dsa.h>
-+#include "mtk_eth_soc.h"
+#include "mtk_ppe.h"
+#include "mtk_ppe_regs.h"
+
-+static DEFINE_SPINLOCK(ppe_lock);
-+
-+static const struct rhashtable_params mtk_flow_l2_ht_params = {
-+ .head_offset = offsetof(struct mtk_flow_entry, l2_node),
-+ .key_offset = offsetof(struct mtk_flow_entry, data.bridge),
-+ .key_len = offsetof(struct mtk_foe_bridge, key_end),
-+ .automatic_shrinking = true,
-+};
-+
+static void ppe_w32(struct mtk_ppe *ppe, u32 reg, u32 val)
+{
+ writel(val, ppe->base + reg);
@@ -534,11 +281,6 @@
+ return ppe_m32(ppe, reg, val, 0);
+}
+
-+static u32 mtk_eth_timestamp(struct mtk_eth *eth)
-+{
-+ return mtk_r32(eth, 0x0010) & mtk_get_ib1_ts_mask(eth);
-+}
-+
+static int mtk_ppe_wait_busy(struct mtk_ppe *ppe)
+{
+ int ret;
@@ -554,63 +296,6 @@
+ return ret;
+}
+
-+static int mtk_ppe_mib_wait_busy(struct mtk_ppe *ppe)
-+{
-+ int ret;
-+ u32 val;
-+
-+ ret = readl_poll_timeout_atomic(ppe->base + MTK_PPE_MIB_SER_CR, val,
-+ !(val & MTK_PPE_MIB_SER_CR_ST),
-+ 20, MTK_PPE_WAIT_TIMEOUT_US);
-+
-+ if (ret)
-+ dev_err(ppe->dev, "MIB table busy");
-+
-+ return ret;
-+}
-+
-+static inline struct mtk_foe_accounting *
-+mtk_ppe_acct_data(struct mtk_ppe *ppe, u16 index)
-+{
-+ if (!ppe->acct_table)
-+ return NULL;
-+
-+ return ppe->acct_table + index * sizeof(struct mtk_foe_accounting);
-+}
-+
-+struct mtk_foe_accounting *mtk_ppe_mib_entry_read(struct mtk_ppe *ppe, u16 index)
-+{
-+ u32 byte_cnt_low, byte_cnt_high, pkt_cnt_low, pkt_cnt_high;
-+ u32 val, cnt_r0, cnt_r1, cnt_r2;
-+ struct mtk_foe_accounting *acct;
-+ int ret;
-+
-+ val = FIELD_PREP(MTK_PPE_MIB_SER_CR_ADDR, index) | MTK_PPE_MIB_SER_CR_ST;
-+ ppe_w32(ppe, MTK_PPE_MIB_SER_CR, val);
-+
-+ acct = mtk_ppe_acct_data(ppe, index);
-+ if (!acct)
-+ return NULL;
-+
-+ ret = mtk_ppe_mib_wait_busy(ppe);
-+ if (ret)
-+ return acct;
-+
-+ cnt_r0 = readl(ppe->base + MTK_PPE_MIB_SER_R0);
-+ cnt_r1 = readl(ppe->base + MTK_PPE_MIB_SER_R1);
-+ cnt_r2 = readl(ppe->base + MTK_PPE_MIB_SER_R2);
-+
-+ byte_cnt_low = FIELD_GET(MTK_PPE_MIB_SER_R0_BYTE_CNT_LOW, cnt_r0);
-+ byte_cnt_high = FIELD_GET(MTK_PPE_MIB_SER_R1_BYTE_CNT_HIGH, cnt_r1);
-+ pkt_cnt_low = FIELD_GET(MTK_PPE_MIB_SER_R1_PKT_CNT_LOW, cnt_r1);
-+ pkt_cnt_high = FIELD_GET(MTK_PPE_MIB_SER_R2_PKT_CNT_HIGH, cnt_r2);
-+
-+ acct->bytes += ((u64)byte_cnt_high << 32) | byte_cnt_low;
-+ acct->packets += (pkt_cnt_high << 16) | pkt_cnt_low;
-+
-+ return acct;
-+}
-+
+static void mtk_ppe_cache_clear(struct mtk_ppe *ppe)
+{
+ ppe_set(ppe, MTK_PPE_CACHE_CTL, MTK_PPE_CACHE_CTL_CLEAR);
@@ -625,12 +310,19 @@
+ enable * MTK_PPE_CACHE_CTL_EN);
+}
+
-+static u32 mtk_ppe_hash_entry(struct mtk_eth *eth, struct mtk_foe_entry *e)
++static u32 mtk_ppe_hash_entry(struct mtk_foe_entry *e)
+{
+ u32 hv1, hv2, hv3;
+ u32 hash;
+
-+ switch (mtk_get_ib1_pkt_type(eth, e->ib1)) {
++ switch (FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, e->ib1)) {
++ case MTK_PPE_PKT_TYPE_BRIDGE:
++ hv1 = e->bridge.src_mac_lo;
++ hv1 ^= ((e->bridge.src_mac_hi & 0xffff) << 16);
++ hv2 = e->bridge.src_mac_hi >> 16;
++ hv2 ^= e->bridge.dest_mac_lo;
++ hv3 = e->bridge.dest_mac_hi;
++ break;
+ case MTK_PPE_PKT_TYPE_IPV4_ROUTE:
+ case MTK_PPE_PKT_TYPE_IPV4_HNAPT:
+ hv1 = e->ipv4.orig.ports;
@@ -659,19 +351,16 @@
+ hash = (hash >> 24) | ((hash & 0xffffff) << 8);
+ hash ^= hv1 ^ hv2 ^ hv3;
+ hash ^= hash >> 16;
-+ hash <<= (ffs(eth->soc->hash_offset) - 1);
++ hash <<= 1;
+ hash &= MTK_PPE_ENTRIES - 1;
+
+ return hash;
+}
+
+static inline struct mtk_foe_mac_info *
-+mtk_foe_entry_l2(struct mtk_eth *eth, struct mtk_foe_entry *entry)
++mtk_foe_entry_l2(struct mtk_foe_entry *entry)
+{
-+ int type = mtk_get_ib1_pkt_type(eth, entry->ib1);
-+
-+ if (type == MTK_PPE_PKT_TYPE_BRIDGE)
-+ return &entry->bridge.l2;
++ int type = FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, entry->ib1);
+
+ if (type >= MTK_PPE_PKT_TYPE_IPV4_DSLITE)
+ return &entry->ipv6.l2;
@@ -680,12 +369,9 @@
+}
+
+static inline u32 *
-+mtk_foe_entry_ib2(struct mtk_eth *eth, struct mtk_foe_entry *entry)
++mtk_foe_entry_ib2(struct mtk_foe_entry *entry)
+{
-+ int type = mtk_get_ib1_pkt_type(eth, entry->ib1);
-+
-+ if (type == MTK_PPE_PKT_TYPE_BRIDGE)
-+ return &entry->bridge.ib2;
++ int type = FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, entry->ib1);
+
+ if (type >= MTK_PPE_PKT_TYPE_IPV4_DSLITE)
+ return &entry->ipv6.ib2;
@@ -693,40 +379,27 @@
+ return &entry->ipv4.ib2;
+}
+
-+int mtk_foe_entry_prepare(struct mtk_eth *eth, struct mtk_foe_entry *entry,
-+ int type, int l4proto, u8 pse_port, u8 *src_mac,
-+ u8 *dest_mac)
++int mtk_foe_entry_prepare(struct mtk_foe_entry *entry, int type, int l4proto,
++ u8 pse_port, u8 *src_mac, u8 *dest_mac)
+{
+ struct mtk_foe_mac_info *l2;
+ u32 ports_pad, val;
+
+ memset(entry, 0, sizeof(*entry));
+
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
-+ val = FIELD_PREP(MTK_FOE_IB1_STATE, MTK_FOE_STATE_BIND) |
-+ FIELD_PREP(MTK_FOE_IB1_PACKET_TYPE_V2, type) |
-+ FIELD_PREP(MTK_FOE_IB1_UDP, l4proto == IPPROTO_UDP) |
-+ MTK_FOE_IB1_BIND_CACHE_V2 | MTK_FOE_IB1_BIND_TTL_V2;
-+ entry->ib1 = val;
-+
-+ val = FIELD_PREP(MTK_FOE_IB2_DEST_PORT_V2, pse_port) |
-+ FIELD_PREP(MTK_FOE_IB2_PORT_AG_V2, 0xf);
-+ } else {
-+ int port_mg = eth->soc->offload_version > 1 ? 0 : 0x3f;
-+
-+ val = FIELD_PREP(MTK_FOE_IB1_STATE, MTK_FOE_STATE_BIND) |
-+ FIELD_PREP(MTK_FOE_IB1_PACKET_TYPE, type) |
-+ FIELD_PREP(MTK_FOE_IB1_UDP, l4proto == IPPROTO_UDP) |
-+ MTK_FOE_IB1_BIND_CACHE | MTK_FOE_IB1_BIND_TTL;
-+ entry->ib1 = val;
++ val = FIELD_PREP(MTK_FOE_IB1_STATE, MTK_FOE_STATE_BIND) |
++ FIELD_PREP(MTK_FOE_IB1_PACKET_TYPE, type) |
++ FIELD_PREP(MTK_FOE_IB1_UDP, l4proto == IPPROTO_UDP) |
++ MTK_FOE_IB1_BIND_TTL |
++ MTK_FOE_IB1_BIND_CACHE;
++ entry->ib1 = val;
+
-+ val = FIELD_PREP(MTK_FOE_IB2_DEST_PORT, pse_port) |
-+ FIELD_PREP(MTK_FOE_IB2_PORT_MG, port_mg) |
-+ FIELD_PREP(MTK_FOE_IB2_PORT_AG, 0x1f);
-+ }
++ val = FIELD_PREP(MTK_FOE_IB2_PORT_MG, 0x3f) |
++ FIELD_PREP(MTK_FOE_IB2_PORT_AG, 0x1f) |
++ FIELD_PREP(MTK_FOE_IB2_DEST_PORT, pse_port);
+
+ if (is_multicast_ether_addr(dest_mac))
-+ val |= mtk_get_ib2_multicast_mask(eth);
++ val |= MTK_FOE_IB2_MULTICAST;
+
+ ports_pad = 0xa5a5a500 | (l4proto & 0xff);
+ if (type == MTK_PPE_PKT_TYPE_IPV4_ROUTE)
@@ -734,12 +407,7 @@
+ if (type == MTK_PPE_PKT_TYPE_IPV6_ROUTE_3T)
+ entry->ipv6.ports = ports_pad;
+
-+ if (type == MTK_PPE_PKT_TYPE_BRIDGE) {
-+ ether_addr_copy(entry->bridge.src_mac, src_mac);
-+ ether_addr_copy(entry->bridge.dest_mac, dest_mac);
-+ entry->bridge.ib2 = val;
-+ l2 = &entry->bridge.l2;
-+ } else if (type >= MTK_PPE_PKT_TYPE_IPV4_DSLITE) {
++ if (type >= MTK_PPE_PKT_TYPE_IPV4_DSLITE) {
+ entry->ipv6.ib2 = val;
+ l2 = &entry->ipv6.l2;
+ } else {
@@ -760,30 +428,24 @@
+ return 0;
+}
+
-+int mtk_foe_entry_set_pse_port(struct mtk_eth *eth,
-+ struct mtk_foe_entry *entry, u8 port)
++int mtk_foe_entry_set_pse_port(struct mtk_foe_entry *entry, u8 port)
+{
-+ u32 *ib2 = mtk_foe_entry_ib2(eth, entry);
-+ u32 val = *ib2;
++ u32 *ib2 = mtk_foe_entry_ib2(entry);
++ u32 val;
+
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
-+ val &= ~MTK_FOE_IB2_DEST_PORT_V2;
-+ val |= FIELD_PREP(MTK_FOE_IB2_DEST_PORT_V2, port);
-+ } else {
-+ val &= ~MTK_FOE_IB2_DEST_PORT;
-+ val |= FIELD_PREP(MTK_FOE_IB2_DEST_PORT, port);
-+ }
++ val = *ib2;
++ val &= ~MTK_FOE_IB2_DEST_PORT;
++ val |= FIELD_PREP(MTK_FOE_IB2_DEST_PORT, port);
+ *ib2 = val;
+
+ return 0;
+}
+
-+int mtk_foe_entry_set_ipv4_tuple(struct mtk_eth *eth,
-+ struct mtk_foe_entry *entry, bool egress,
++int mtk_foe_entry_set_ipv4_tuple(struct mtk_foe_entry *entry, bool egress,
+ __be32 src_addr, __be16 src_port,
+ __be32 dest_addr, __be16 dest_port)
+{
-+ int type = mtk_get_ib1_pkt_type(eth, entry->ib1);
++ int type = FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, entry->ib1);
+ struct mtk_ipv4_tuple *t;
+
+ switch (type) {
@@ -818,12 +480,11 @@
+ return 0;
+}
+
-+int mtk_foe_entry_set_ipv6_tuple(struct mtk_eth *eth,
-+ struct mtk_foe_entry *entry,
++int mtk_foe_entry_set_ipv6_tuple(struct mtk_foe_entry *entry,
+ __be32 *src_addr, __be16 src_port,
+ __be32 *dest_addr, __be16 dest_port)
+{
-+ int type = mtk_get_ib1_pkt_type(eth, entry->ib1);
++ int type = FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, entry->ib1);
+ u32 *src, *dest;
+ int i;
+
@@ -854,41 +515,39 @@
+ return 0;
+}
+
-+int mtk_foe_entry_set_dsa(struct mtk_eth *eth, struct mtk_foe_entry *entry,
-+ int port)
++int mtk_foe_entry_set_dsa(struct mtk_foe_entry *entry, int port)
+{
-+ struct mtk_foe_mac_info *l2 = mtk_foe_entry_l2(eth, entry);
++ struct mtk_foe_mac_info *l2 = mtk_foe_entry_l2(entry);
+
+ l2->etype = BIT(port);
+
-+ if (!(entry->ib1 & mtk_get_ib1_vlan_layer_mask(eth)))
-+ entry->ib1 |= mtk_prep_ib1_vlan_layer(eth, 1);
++ if (!(entry->ib1 & MTK_FOE_IB1_BIND_VLAN_LAYER))
++ entry->ib1 |= FIELD_PREP(MTK_FOE_IB1_BIND_VLAN_LAYER, 1);
+ else
+ l2->etype |= BIT(8);
+
-+ entry->ib1 &= ~mtk_get_ib1_vlan_tag_mask(eth);
++ entry->ib1 &= ~MTK_FOE_IB1_BIND_VLAN_TAG;
+
+ return 0;
+}
+
-+int mtk_foe_entry_set_vlan(struct mtk_eth *eth, struct mtk_foe_entry *entry,
-+ int vid)
++int mtk_foe_entry_set_vlan(struct mtk_foe_entry *entry, int vid)
+{
-+ struct mtk_foe_mac_info *l2 = mtk_foe_entry_l2(eth, entry);
++ struct mtk_foe_mac_info *l2 = mtk_foe_entry_l2(entry);
+
-+ switch (mtk_get_ib1_vlan_layer(eth, entry->ib1)) {
++ switch (FIELD_GET(MTK_FOE_IB1_BIND_VLAN_LAYER, entry->ib1)) {
+ case 0:
-+ entry->ib1 |= mtk_get_ib1_vlan_tag_mask(eth) |
-+ mtk_prep_ib1_vlan_layer(eth, 1);
++ entry->ib1 |= MTK_FOE_IB1_BIND_VLAN_TAG |
++ FIELD_PREP(MTK_FOE_IB1_BIND_VLAN_LAYER, 1);
+ l2->vlan1 = vid;
+ return 0;
+ case 1:
-+ if (!(entry->ib1 & mtk_get_ib1_vlan_tag_mask(eth))) {
++ if (!(entry->ib1 & MTK_FOE_IB1_BIND_VLAN_TAG)) {
+ l2->vlan1 = vid;
+ l2->etype |= BIT(8);
+ } else {
+ l2->vlan2 = vid;
-+ entry->ib1 += mtk_prep_ib1_vlan_layer(eth, 1);
++ entry->ib1 += FIELD_PREP(MTK_FOE_IB1_BIND_VLAN_LAYER, 1);
+ }
+ return 0;
+ default:
@@ -896,522 +555,79 @@
+ }
+}
+
-+int mtk_foe_entry_set_pppoe(struct mtk_eth *eth, struct mtk_foe_entry *entry,
-+ int sid)
++int mtk_foe_entry_set_pppoe(struct mtk_foe_entry *entry, int sid)
+{
-+ struct mtk_foe_mac_info *l2 = mtk_foe_entry_l2(eth, entry);
++ struct mtk_foe_mac_info *l2 = mtk_foe_entry_l2(entry);
+
-+ if (!(entry->ib1 & mtk_get_ib1_vlan_layer_mask(eth)) ||
-+ (entry->ib1 & mtk_get_ib1_vlan_tag_mask(eth)))
++ if (!(entry->ib1 & MTK_FOE_IB1_BIND_VLAN_LAYER) ||
++ (entry->ib1 & MTK_FOE_IB1_BIND_VLAN_TAG))
+ l2->etype = ETH_P_PPP_SES;
+
-+ entry->ib1 |= mtk_get_ib1_ppoe_mask(eth);
++ entry->ib1 |= MTK_FOE_IB1_BIND_PPPOE;
+ l2->pppoe_id = sid;
+
+ return 0;
+}
+
-+int mtk_foe_entry_set_wdma(struct mtk_eth *eth, struct mtk_foe_entry *entry,
-+ int wdma_idx, int txq, int bss, int wcid)
-+{
-+ struct mtk_foe_mac_info *l2 = mtk_foe_entry_l2(eth, entry);
-+ u32 *ib2 = mtk_foe_entry_ib2(eth, entry);
-+
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
-+ *ib2 &= ~MTK_FOE_IB2_PORT_MG_V2;
-+ *ib2 |= FIELD_PREP(MTK_FOE_IB2_RX_IDX, txq) |
-+ MTK_FOE_IB2_WDMA_WINFO_V2;
-+ l2->winfo = FIELD_PREP(MTK_FOE_WINFO_WCID, wcid) |
-+ FIELD_PREP(MTK_FOE_WINFO_BSS, bss);
-+ } else {
-+ *ib2 &= ~MTK_FOE_IB2_PORT_MG;
-+ *ib2 |= MTK_FOE_IB2_WDMA_WINFO;
-+ if (wdma_idx)
-+ *ib2 |= MTK_FOE_IB2_WDMA_DEVIDX;
-+ l2->vlan2 = FIELD_PREP(MTK_FOE_VLAN2_WINFO_BSS, bss) |
-+ FIELD_PREP(MTK_FOE_VLAN2_WINFO_WCID, wcid) |
-+ FIELD_PREP(MTK_FOE_VLAN2_WINFO_RING, txq);
-+ }
-+
-+ return 0;
-+}
-+
+static inline bool mtk_foe_entry_usable(struct mtk_foe_entry *entry)
+{
+ return !(entry->ib1 & MTK_FOE_IB1_STATIC) &&
+ FIELD_GET(MTK_FOE_IB1_STATE, entry->ib1) != MTK_FOE_STATE_BIND;
+}
+
-+int mtk_foe_entry_set_queue(struct mtk_eth *eth, struct mtk_foe_entry *entry,
-+ unsigned int queue)
++int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_foe_entry *entry,
++ u16 timestamp)
+{
-+ u32 *ib2 = mtk_foe_entry_ib2(eth, entry);
-+
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
-+ *ib2 &= ~MTK_FOE_IB2_QID_V2;
-+ *ib2 |= FIELD_PREP(MTK_FOE_IB2_QID_V2, queue);
-+ *ib2 |= MTK_FOE_IB2_PSE_QOS_V2;
-+ } else {
-+ *ib2 &= ~MTK_FOE_IB2_QID;
-+ *ib2 |= FIELD_PREP(MTK_FOE_IB2_QID, queue);
-+ *ib2 |= MTK_FOE_IB2_PSE_QOS;
-+ }
-+
-+ return 0;
-+}
-+
-+static int
-+mtk_flow_entry_match_len(struct mtk_eth *eth, struct mtk_foe_entry *entry)
-+{
-+ int type = mtk_get_ib1_pkt_type(eth, entry->ib1);
-+
-+ if (type > MTK_PPE_PKT_TYPE_IPV4_DSLITE)
-+ return offsetof(struct mtk_foe_entry, ipv6._rsv);
-+ else
-+ return offsetof(struct mtk_foe_entry, ipv4.ib2);
-+}
-+
-+static bool
-+mtk_flow_entry_match(struct mtk_eth *eth, struct mtk_flow_entry *entry,
-+ struct mtk_foe_entry *data, int len)
-+{
-+ if ((data->ib1 ^ entry->data.ib1) & MTK_FOE_IB1_UDP)
-+ return false;
-+
-+ return !memcmp(&entry->data.data, &data->data, len - 4);
-+}
-+
-+static void
-+__mtk_foe_entry_clear(struct mtk_ppe *ppe, struct mtk_flow_entry *entry,
-+ bool set_state)
-+{
-+ struct hlist_node *tmp;
-+
-+ if (entry->type == MTK_FLOW_TYPE_L2) {
-+ rhashtable_remove_fast(&ppe->l2_flows, &entry->l2_node,
-+ mtk_flow_l2_ht_params);
-+
-+ hlist_for_each_entry_safe(entry, tmp, &entry->l2_flows, l2_list)
-+ __mtk_foe_entry_clear(ppe, entry, set_state);
-+ return;
-+ }
-+
-+ if (entry->hash != 0xffff && set_state) {
-+ struct mtk_foe_entry *hwe = mtk_foe_get_entry(ppe, entry->hash);
-+
-+ hwe->ib1 &= ~MTK_FOE_IB1_STATE;
-+ hwe->ib1 |= FIELD_PREP(MTK_FOE_IB1_STATE, MTK_FOE_STATE_INVALID);
-+ dma_wmb();
-+ mtk_ppe_cache_clear(ppe);
-+ }
-+ entry->hash = 0xffff;
-+
-+ if (entry->type != MTK_FLOW_TYPE_L2_SUBFLOW)
-+ return;
-+
-+ hlist_del_init(&entry->l2_list);
-+ hlist_del_init(&entry->list);
-+ kfree(entry);
-+}
-+
-+static int __mtk_foe_entry_idle_time(struct mtk_ppe *ppe, u32 ib1)
-+{
-+ u32 ib1_ts_mask = mtk_get_ib1_ts_mask(ppe->eth);
-+ u16 now = mtk_eth_timestamp(ppe->eth);
-+ u16 timestamp = ib1 & ib1_ts_mask;
-+
-+ if (timestamp > now)
-+ return ib1_ts_mask + 1 - timestamp + now;
-+ else
-+ return now - timestamp;
-+}
-+
-+static bool
-+mtk_flow_entry_update(struct mtk_ppe *ppe, struct mtk_flow_entry *entry,
-+ u64 *packets, u64 *bytes)
-+{
-+ struct mtk_foe_accounting *acct;
-+ struct mtk_foe_entry foe = {};
+ struct mtk_foe_entry *hwe;
-+ u16 hash = entry->hash;
-+ bool ret = false;
-+ int len;
-+
-+ if (hash == 0xffff)
-+ return false;
-+
-+ hwe = mtk_foe_get_entry(ppe, hash);
-+ len = mtk_flow_entry_match_len(ppe->eth, &entry->data);
-+ memcpy(&foe, hwe, len);
-+
-+ if (!mtk_flow_entry_match(ppe->eth, entry, &foe, len) ||
-+ FIELD_GET(MTK_FOE_IB1_STATE, foe.ib1) != MTK_FOE_STATE_BIND) {
-+ acct = mtk_ppe_acct_data(ppe, hash);
-+ if (acct) {
-+ entry->prev_packets += acct->packets;
-+ entry->prev_bytes += acct->bytes;
-+ }
-+
-+ goto out;
-+ }
-+
-+ entry->data.ib1 = foe.ib1;
-+ acct = mtk_ppe_mib_entry_read(ppe, hash);
-+ ret = true;
-+
-+out:
-+ if (acct) {
-+ *packets += acct->packets;
-+ *bytes += acct->bytes;
-+ }
-+
-+ return ret;
-+}
-+
-+static void
-+mtk_flow_entry_update_l2(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
-+{
-+ u32 ib1_ts_mask = mtk_get_ib1_ts_mask(ppe->eth);
-+ u64 *packets = &entry->packets;
-+ u64 *bytes = &entry->bytes;
-+ struct mtk_flow_entry *cur;
-+ struct hlist_node *tmp;
-+ int idle;
-+
-+ idle = __mtk_foe_entry_idle_time(ppe, entry->data.ib1);
-+ hlist_for_each_entry_safe(cur, tmp, &entry->l2_flows, l2_list) {
-+ int cur_idle;
-+
-+ if (!mtk_flow_entry_update(ppe, cur, packets, bytes)) {
-+ entry->prev_packets += cur->prev_packets;
-+ entry->prev_bytes += cur->prev_bytes;
-+ __mtk_foe_entry_clear(ppe, entry, false);
-+ continue;
-+ }
-+
-+ cur_idle = __mtk_foe_entry_idle_time(ppe, cur->data.ib1);
-+ if (cur_idle >= idle)
-+ continue;
-+
-+ idle = cur_idle;
-+ entry->data.ib1 &= ~ib1_ts_mask;
-+ entry->data.ib1 |= cur->data.ib1 & ib1_ts_mask;
-+ }
-+}
-+
-+void mtk_foe_entry_get_stats(struct mtk_ppe *ppe, struct mtk_flow_entry *entry,
-+ int *idle)
-+{
-+ entry->packets = entry->prev_packets;
-+ entry->bytes = entry->prev_bytes;
-+
-+ spin_lock_bh(&ppe_lock);
-+
-+ if (entry->type == MTK_FLOW_TYPE_L2)
-+ mtk_flow_entry_update_l2(ppe, entry);
-+ else
-+ mtk_flow_entry_update(ppe, entry, &entry->packets, &entry->bytes);
-+
-+ *idle = __mtk_foe_entry_idle_time(ppe, entry->data.ib1);
++ u32 hash;
+
-+ spin_unlock_bh(&ppe_lock);
-+}
++ timestamp &= MTK_FOE_IB1_BIND_TIMESTAMP;
++ entry->ib1 &= ~MTK_FOE_IB1_BIND_TIMESTAMP;
++ entry->ib1 |= FIELD_PREP(MTK_FOE_IB1_BIND_TIMESTAMP, timestamp);
+
-+static void
-+__mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_foe_entry *entry,
-+ u16 hash)
-+{
-+ struct mtk_foe_accounting *acct;
-+ struct mtk_eth *eth = ppe->eth;
-+ u16 timestamp = mtk_eth_timestamp(eth);
-+ struct mtk_foe_entry *hwe;
-+ u32 val;
++ hash = mtk_ppe_hash_entry(entry);
++ hwe = &ppe->foe_table[hash];
++ if (!mtk_foe_entry_usable(hwe)) {
++ hwe++;
++ hash++;
+
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
-+ entry->ib1 &= ~MTK_FOE_IB1_BIND_TIMESTAMP_V2;
-+ entry->ib1 |= FIELD_PREP(MTK_FOE_IB1_BIND_TIMESTAMP_V2,
-+ timestamp);
-+ } else {
-+ entry->ib1 &= ~MTK_FOE_IB1_BIND_TIMESTAMP;
-+ entry->ib1 |= FIELD_PREP(MTK_FOE_IB1_BIND_TIMESTAMP,
-+ timestamp);
++ if (!mtk_foe_entry_usable(hwe))
++ return -ENOSPC;
+ }
+
-+ hwe = mtk_foe_get_entry(ppe, hash);
-+ memcpy(&hwe->data, &entry->data, eth->soc->foe_entry_size - sizeof(hwe->ib1));
++ memcpy(&hwe->data, &entry->data, sizeof(hwe->data));
+ wmb();
+ hwe->ib1 = entry->ib1;
+
-+ if (ppe->accounting) {
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
-+ val = MTK_FOE_IB2_MIB_CNT_V2;
-+ else
-+ val = MTK_FOE_IB2_MIB_CNT;
-+ *mtk_foe_entry_ib2(eth, hwe) |= val;
-+ }
-+
+ dma_wmb();
+
-+ acct = mtk_ppe_mib_entry_read(ppe, hash);
-+ if (acct) {
-+ acct->packets = 0;
-+ acct->bytes = 0;
-+ }
-+
+ mtk_ppe_cache_clear(ppe);
-+}
-+
-+void mtk_foe_entry_clear(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
-+{
-+ spin_lock_bh(&ppe_lock);
-+ __mtk_foe_entry_clear(ppe, entry, true);
-+ hlist_del_init(&entry->list);
-+ spin_unlock_bh(&ppe_lock);
-+}
-+
-+static int
-+mtk_foe_entry_commit_l2(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
-+{
-+ struct mtk_flow_entry *prev;
-+
-+ entry->type = MTK_FLOW_TYPE_L2;
-+
-+ prev = rhashtable_lookup_get_insert_fast(&ppe->l2_flows, &entry->l2_node,
-+ mtk_flow_l2_ht_params);
-+ if (likely(!prev))
-+ return 0;
-+
-+ if (IS_ERR(prev))
-+ return PTR_ERR(prev);
-+
-+ return rhashtable_replace_fast(&ppe->l2_flows, &prev->l2_node,
-+ &entry->l2_node, mtk_flow_l2_ht_params);
-+}
-+
-+int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
-+{
-+ const struct mtk_soc_data *soc = ppe->eth->soc;
-+ int type = mtk_get_ib1_pkt_type(ppe->eth, entry->data.ib1);
-+ u32 hash;
-+
-+ if (type == MTK_PPE_PKT_TYPE_BRIDGE)
-+ return mtk_foe_entry_commit_l2(ppe, entry);
-+
-+ hash = mtk_ppe_hash_entry(ppe->eth, &entry->data);
-+ entry->hash = 0xffff;
-+ spin_lock_bh(&ppe_lock);
-+ hlist_add_head(&entry->list, &ppe->foe_flow[hash / soc->hash_offset]);
-+ spin_unlock_bh(&ppe_lock);
-+
-+ return 0;
-+}
-+
-+static void
-+mtk_foe_entry_commit_subflow(struct mtk_ppe *ppe, struct mtk_flow_entry *entry,
-+ u16 hash)
-+{
-+ const struct mtk_soc_data *soc = ppe->eth->soc;
-+ struct mtk_flow_entry *flow_info;
-+ struct mtk_foe_mac_info *l2;
-+ struct mtk_foe_entry *hwe;
-+ u32 ib1_mask = mtk_get_ib1_pkt_type_mask(ppe->eth) | MTK_FOE_IB1_UDP;
-+ int type;
-+
-+ flow_info = kzalloc(sizeof(*flow_info), GFP_ATOMIC);
-+ if (!flow_info)
-+ return;
+
-+ flow_info->type = MTK_FLOW_TYPE_L2_SUBFLOW;
-+ flow_info->hash = hash;
-+ hlist_add_head(&flow_info->list,
-+ &ppe->foe_flow[hash / soc->hash_offset]);
-+ hlist_add_head(&flow_info->l2_list, &entry->l2_flows);
-+
-+ hwe = mtk_foe_get_entry(ppe, hash);
-+ memcpy(&flow_info->data, hwe, soc->foe_entry_size);
-+ flow_info->data.ib1 &= ib1_mask;
-+ flow_info->data.ib1 |= entry->data.ib1 & ~ib1_mask;
-+
-+ l2 = mtk_foe_entry_l2(ppe->eth, &flow_info->data);
-+ memcpy(l2, &entry->data.bridge.l2, sizeof(*l2));
-+
-+ type = mtk_get_ib1_pkt_type(ppe->eth, flow_info->data.ib1);
-+ if (type == MTK_PPE_PKT_TYPE_IPV4_HNAPT)
-+ memcpy(&flow_info->data.ipv4.new, &flow_info->data.ipv4.orig,
-+ sizeof(flow_info->data.ipv4.new));
-+ else if (type >= MTK_PPE_PKT_TYPE_IPV6_ROUTE_3T && l2->etype == ETH_P_IP)
-+ l2->etype = ETH_P_IPV6;
-+
-+ *mtk_foe_entry_ib2(ppe->eth, &flow_info->data) = entry->data.bridge.ib2;
-+
-+ __mtk_foe_entry_commit(ppe, &flow_info->data, hash);
-+}
-+
-+void __mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash)
-+{
-+ const struct mtk_soc_data *soc = ppe->eth->soc;
-+ struct hlist_head *head = &ppe->foe_flow[hash / soc->hash_offset];
-+ struct mtk_foe_entry *hwe = mtk_foe_get_entry(ppe, hash);
-+ struct mtk_flow_entry *entry;
-+ struct mtk_foe_bridge key = {};
-+ struct mtk_foe_entry foe = {};
-+ struct hlist_node *n;
-+ struct ethhdr *eh;
-+ bool found = false;
-+ int entry_len;
-+ u8 *tag;
-+
-+ spin_lock_bh(&ppe_lock);
-+
-+ if (FIELD_GET(MTK_FOE_IB1_STATE, hwe->ib1) == MTK_FOE_STATE_BIND)
-+ goto out;
-+
-+ entry_len = mtk_flow_entry_match_len(ppe->eth, hwe);
-+ memcpy(&foe, hwe, entry_len);
-+
-+ hlist_for_each_entry_safe(entry, n, head, list) {
-+ if (found ||
-+ !mtk_flow_entry_match(ppe->eth, entry, &foe, entry_len)) {
-+ if (entry->hash != 0xffff)
-+ __mtk_foe_entry_clear(ppe, entry, false);
-+ continue;
-+ }
-+
-+ entry->hash = hash;
-+ __mtk_foe_entry_commit(ppe, &entry->data, hash);
-+ found = true;
-+ }
-+
-+ if (found)
-+ goto out;
-+
-+ if (!skb)
-+ goto out;
-+
-+ eh = eth_hdr(skb);
-+ ether_addr_copy(key.dest_mac, eh->h_dest);
-+ ether_addr_copy(key.src_mac, eh->h_source);
-+ tag = skb->data - 2;
-+ key.vlan = 0;
-+ switch (skb->protocol) {
-+#if IS_ENABLED(CONFIG_NET_DSA)
-+ case htons(ETH_P_XDSA):
-+ if (!netdev_uses_dsa(skb->dev) ||
-+ skb->dev->dsa_ptr->tag_ops->proto != DSA_TAG_PROTO_MTK)
-+ goto out;
-+
-+ if (!skb_metadata_dst(skb))
-+ tag += 4;
-+
-+ if (get_unaligned_be16(tag) != ETH_P_8021Q)
-+ break;
-+
-+ fallthrough;
-+#endif
-+ case htons(ETH_P_8021Q):
-+ key.vlan = get_unaligned_be16(tag + 2) & VLAN_VID_MASK;
-+ break;
-+ default:
-+ break;
-+ }
-+
-+ entry = rhashtable_lookup_fast(&ppe->l2_flows, &key, mtk_flow_l2_ht_params);
-+ if (!entry)
-+ goto out;
-+
-+ mtk_foe_entry_commit_subflow(ppe, entry, hash);
-+
-+out:
-+ spin_unlock_bh(&ppe_lock);
-+}
-+
-+int mtk_ppe_prepare_reset(struct mtk_ppe *ppe)
-+{
-+ if (!ppe)
-+ return -EINVAL;
-+
-+ /* disable KA */
-+ ppe_clear(ppe, MTK_PPE_TB_CFG, MTK_PPE_TB_CFG_KEEPALIVE);
-+ ppe_clear(ppe, MTK_PPE_BIND_LMT1, MTK_PPE_NTU_KEEPALIVE);
-+ ppe_w32(ppe, MTK_PPE_KEEPALIVE, 0);
-+ usleep_range(10000, 11000);
-+
-+ /* set KA timer to maximum */
-+ ppe_set(ppe, MTK_PPE_BIND_LMT1, MTK_PPE_NTU_KEEPALIVE);
-+ ppe_w32(ppe, MTK_PPE_KEEPALIVE, 0xffffffff);
-+
-+ /* set KA tick select */
-+ ppe_set(ppe, MTK_PPE_TB_CFG, MTK_PPE_TB_TICK_SEL);
-+ ppe_set(ppe, MTK_PPE_TB_CFG, MTK_PPE_TB_CFG_KEEPALIVE);
-+ usleep_range(10000, 11000);
-+
-+ /* disable scan mode */
-+ ppe_clear(ppe, MTK_PPE_TB_CFG, MTK_PPE_TB_CFG_SCAN_MODE);
-+ usleep_range(10000, 11000);
-+
-+ return mtk_ppe_wait_busy(ppe);
++ return hash;
+}
+
-+struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int index)
++int mtk_ppe_init(struct mtk_ppe *ppe, struct device *dev, void __iomem *base,
++ int version)
+{
-+ bool accounting = eth->soc->has_accounting;
-+ const struct mtk_soc_data *soc = eth->soc;
-+ struct mtk_foe_accounting *acct;
-+ struct device *dev = eth->dev;
-+ struct mtk_mib_entry *mib;
-+ struct mtk_ppe *ppe;
-+ u32 foe_flow_size;
-+ void *foe;
-+
-+ ppe = devm_kzalloc(dev, sizeof(*ppe), GFP_KERNEL);
-+ if (!ppe)
-+ return NULL;
-+
-+ rhashtable_init(&ppe->l2_flows, &mtk_flow_l2_ht_params);
++ struct mtk_foe_entry *foe;
+
+ /* need to allocate a separate device, since it PPE DMA access is
+ * not coherent.
+ */
+ ppe->base = base;
-+ ppe->eth = eth;
+ ppe->dev = dev;
-+ ppe->version = eth->soc->offload_version;
-+ ppe->accounting = accounting;
++ ppe->version = version;
+
-+ foe = dmam_alloc_coherent(ppe->dev,
-+ MTK_PPE_ENTRIES * soc->foe_entry_size,
++ foe = dmam_alloc_coherent(ppe->dev, MTK_PPE_ENTRIES * sizeof(*foe),
+ &ppe->foe_phys, GFP_KERNEL);
+ if (!foe)
-+ return NULL;
++ return -ENOMEM;
+
+ ppe->foe_table = foe;
+
-+ foe_flow_size = (MTK_PPE_ENTRIES / soc->hash_offset) *
-+ sizeof(*ppe->foe_flow);
-+ ppe->foe_flow = devm_kzalloc(dev, foe_flow_size, GFP_KERNEL);
-+ if (!ppe->foe_flow)
-+ return NULL;
-+
-+ if (accounting) {
-+ mib = dmam_alloc_coherent(ppe->dev, MTK_PPE_ENTRIES * sizeof(*mib),
-+ &ppe->mib_phys, GFP_KERNEL);
-+ if (!mib)
-+ return NULL;
-+
-+ ppe->mib_table = mib;
-+
-+ acct = devm_kzalloc(dev, MTK_PPE_ENTRIES * sizeof(*acct),
-+ GFP_KERNEL);
++ mtk_ppe_debugfs_init(ppe);
+
-+ if (!acct)
-+ return NULL;
-+
-+ ppe->acct_table = acct;
-+ }
-+
-+ mtk_ppe_debugfs_init(ppe, index);
-+
-+ return ppe;
++ return 0;
+}
+
+static void mtk_ppe_init_foe_table(struct mtk_ppe *ppe)
@@ -1419,30 +635,21 @@
+ static const u8 skip[] = { 12, 25, 38, 51, 76, 89, 102 };
+ int i, k;
+
-+ memset(ppe->foe_table, 0,
-+ MTK_PPE_ENTRIES * ppe->eth->soc->foe_entry_size);
++ memset(ppe->foe_table, 0, MTK_PPE_ENTRIES * sizeof(*ppe->foe_table));
+
+ if (!IS_ENABLED(CONFIG_SOC_MT7621))
+ return;
+
+ /* skip all entries that cross the 1024 byte boundary */
-+ for (i = 0; i < MTK_PPE_ENTRIES; i += 128) {
-+ for (k = 0; k < ARRAY_SIZE(skip); k++) {
-+ struct mtk_foe_entry *hwe;
-+
-+ hwe = mtk_foe_get_entry(ppe, i + skip[k]);
-+ hwe->ib1 |= MTK_FOE_IB1_STATIC;
-+ }
-+ }
++ for (i = 0; i < MTK_PPE_ENTRIES; i += 128)
++ for (k = 0; k < ARRAY_SIZE(skip); k++)
++ ppe->foe_table[i + skip[k]].ib1 |= MTK_FOE_IB1_STATIC;
+}
+
-+void mtk_ppe_start(struct mtk_ppe *ppe)
++int mtk_ppe_start(struct mtk_ppe *ppe)
+{
+ u32 val;
+
-+ if (!ppe)
-+ return;
-+
+ mtk_ppe_init_foe_table(ppe);
+ ppe_w32(ppe, MTK_PPE_TB_BASE, ppe->foe_phys);
+
@@ -1461,8 +668,6 @@
+ MTK_PPE_SCAN_MODE_KEEPALIVE_AGE) |
+ FIELD_PREP(MTK_PPE_TB_CFG_ENTRY_NUM,
+ MTK_PPE_ENTRIES_SHIFT);
-+ if (MTK_HAS_CAPS(ppe->eth->soc->caps, MTK_NETSYS_V2))
-+ val |= MTK_PPE_TB_CFG_INFO_SEL;
+ ppe_w32(ppe, MTK_PPE_TB_CFG, val);
+
+ ppe_w32(ppe, MTK_PPE_IP_PROTO_CHK,
@@ -1470,33 +675,28 @@
+
+ mtk_ppe_cache_enable(ppe, true);
+
-+ val = MTK_PPE_FLOW_CFG_IP6_3T_ROUTE |
++ val = MTK_PPE_FLOW_CFG_IP4_TCP_FRAG |
++ MTK_PPE_FLOW_CFG_IP4_UDP_FRAG |
++ MTK_PPE_FLOW_CFG_IP6_3T_ROUTE |
+ MTK_PPE_FLOW_CFG_IP6_5T_ROUTE |
+ MTK_PPE_FLOW_CFG_IP6_6RD |
+ MTK_PPE_FLOW_CFG_IP4_NAT |
+ MTK_PPE_FLOW_CFG_IP4_NAPT |
+ MTK_PPE_FLOW_CFG_IP4_DSLITE |
++ MTK_PPE_FLOW_CFG_L2_BRIDGE |
+ MTK_PPE_FLOW_CFG_IP4_NAT_FRAG;
-+ if (MTK_HAS_CAPS(ppe->eth->soc->caps, MTK_NETSYS_V2))
-+ val |= MTK_PPE_MD_TOAP_BYP_CRSN0 |
-+ MTK_PPE_MD_TOAP_BYP_CRSN1 |
-+ MTK_PPE_MD_TOAP_BYP_CRSN2 |
-+ MTK_PPE_FLOW_CFG_IP4_HASH_GRE_KEY;
-+ else
-+ val |= MTK_PPE_FLOW_CFG_IP4_TCP_FRAG |
-+ MTK_PPE_FLOW_CFG_IP4_UDP_FRAG;
+ ppe_w32(ppe, MTK_PPE_FLOW_CFG, val);
+
+ val = FIELD_PREP(MTK_PPE_UNBIND_AGE_MIN_PACKETS, 1000) |
+ FIELD_PREP(MTK_PPE_UNBIND_AGE_DELTA, 3);
+ ppe_w32(ppe, MTK_PPE_UNBIND_AGE, val);
+
-+ val = FIELD_PREP(MTK_PPE_BIND_AGE0_DELTA_UDP, 12) |
++ val = FIELD_PREP(MTK_PPE_BIND_AGE0_DELTA_UDP, 30) |
+ FIELD_PREP(MTK_PPE_BIND_AGE0_DELTA_NON_L4, 1);
+ ppe_w32(ppe, MTK_PPE_BIND_AGE0, val);
+
+ val = FIELD_PREP(MTK_PPE_BIND_AGE1_DELTA_TCP_FIN, 1) |
-+ FIELD_PREP(MTK_PPE_BIND_AGE1_DELTA_TCP, 7);
++ FIELD_PREP(MTK_PPE_BIND_AGE1_DELTA_TCP, 30);
+ ppe_w32(ppe, MTK_PPE_BIND_AGE1, val);
+
+ val = MTK_PPE_BIND_LIMIT0_QUARTER | MTK_PPE_BIND_LIMIT0_HALF;
@@ -1519,20 +719,7 @@
+
+ ppe_w32(ppe, MTK_PPE_DEFAULT_CPU_PORT, 0);
+
-+ if (MTK_HAS_CAPS(ppe->eth->soc->caps, MTK_NETSYS_V2)) {
-+ ppe_w32(ppe, MTK_PPE_DEFAULT_CPU_PORT1, 0xcb777);
-+ ppe_w32(ppe, MTK_PPE_SBW_CTRL, 0x7f);
-+ }
-+
-+ if (ppe->accounting && ppe->mib_phys) {
-+ ppe_w32(ppe, MTK_PPE_MIB_TB_BASE, ppe->mib_phys);
-+ ppe_m32(ppe, MTK_PPE_MIB_CFG, MTK_PPE_MIB_CFG_EN,
-+ MTK_PPE_MIB_CFG_EN);
-+ ppe_m32(ppe, MTK_PPE_MIB_CFG, MTK_PPE_MIB_CFG_RD_CLR,
-+ MTK_PPE_MIB_CFG_RD_CLR);
-+ ppe_m32(ppe, MTK_PPE_MIB_CACHE_CTL, MTK_PPE_MIB_CACHE_CTL_EN,
-+ MTK_PPE_MIB_CFG_RD_CLR);
-+ }
++ return 0;
+}
+
+int mtk_ppe_stop(struct mtk_ppe *ppe)
@@ -1540,15 +727,9 @@
+ u32 val;
+ int i;
+
-+ if (!ppe)
-+ return 0;
-+
-+ for (i = 0; i < MTK_PPE_ENTRIES; i++) {
-+ struct mtk_foe_entry *hwe = mtk_foe_get_entry(ppe, i);
-+
-+ hwe->ib1 = FIELD_PREP(MTK_FOE_IB1_STATE,
-+ MTK_FOE_STATE_INVALID);
-+ }
++ for (i = 0; i < MTK_PPE_ENTRIES; i++)
++ ppe->foe_table[i].ib1 = FIELD_PREP(MTK_FOE_IB1_STATE,
++ MTK_FOE_STATE_INVALID);
+
+ mtk_ppe_cache_enable(ppe, false);
+
@@ -1568,10 +749,10 @@
+}
diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
new file mode 100644
-index 0000000..1fdfb93
+index 000000000..242fb8f2a
--- /dev/null
+++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
-@@ -0,0 +1,384 @@
+@@ -0,0 +1,288 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (C) 2020 Felix Fietkau <nbd@nbd.name> */
+
@@ -1580,7 +761,8 @@
+
+#include <linux/kernel.h>
+#include <linux/bitfield.h>
-+#include <linux/rhashtable.h>
++
++#define MTK_ETH_PPE_BASE 0xc00
+
+#define MTK_PPE_ENTRIES_SHIFT 3
+#define MTK_PPE_ENTRIES (1024 << MTK_PPE_ENTRIES_SHIFT)
@@ -1606,15 +788,6 @@
+#define MTK_FOE_IB1_UDP BIT(30)
+#define MTK_FOE_IB1_STATIC BIT(31)
+
-+/* CONFIG_MEDIATEK_NETSYS_V2 */
-+#define MTK_FOE_IB1_BIND_TIMESTAMP_V2 GENMASK(7, 0)
-+#define MTK_FOE_IB1_BIND_VLAN_LAYER_V2 GENMASK(16, 14)
-+#define MTK_FOE_IB1_BIND_PPPOE_V2 BIT(17)
-+#define MTK_FOE_IB1_BIND_VLAN_TAG_V2 BIT(18)
-+#define MTK_FOE_IB1_BIND_CACHE_V2 BIT(20)
-+#define MTK_FOE_IB1_BIND_TTL_V2 BIT(22)
-+#define MTK_FOE_IB1_PACKET_TYPE_V2 GENMASK(27, 23)
-+
+enum {
+ MTK_PPE_PKT_TYPE_IPV4_HNAPT = 0,
+ MTK_PPE_PKT_TYPE_IPV4_ROUTE = 1,
@@ -1629,35 +802,20 @@
+#define MTK_FOE_IB2_PSE_QOS BIT(4)
+#define MTK_FOE_IB2_DEST_PORT GENMASK(7, 5)
+#define MTK_FOE_IB2_MULTICAST BIT(8)
-+#define MTK_FOE_IB2_MIB_CNT BIT(10)
+
-+#define MTK_FOE_IB2_WDMA_QID2 GENMASK(13, 12)
-+#define MTK_FOE_IB2_MIB_CNT_V2 BIT(15)
-+#define MTK_FOE_IB2_WDMA_DEVIDX BIT(16)
-+#define MTK_FOE_IB2_WDMA_WINFO BIT(17)
++#define MTK_FOE_IB2_WHNAT_QID2 GENMASK(13, 12)
++#define MTK_FOE_IB2_WHNAT_DEVIDX BIT(16)
++#define MTK_FOE_IB2_WHNAT_NAT BIT(17)
+
+#define MTK_FOE_IB2_PORT_MG GENMASK(17, 12)
+
-+#define MTK_FOE_IB2_RX_IDX GENMASK(18, 17)
+#define MTK_FOE_IB2_PORT_AG GENMASK(23, 18)
+
+#define MTK_FOE_IB2_DSCP GENMASK(31, 24)
+
-+/* CONFIG_MEDIATEK_NETSYS_V2 */
-+#define MTK_FOE_IB2_QID_V2 GENMASK(6, 0)
-+#define MTK_FOE_IB2_PORT_MG_V2 BIT(7)
-+#define MTK_FOE_IB2_PSE_QOS_V2 BIT(8)
-+#define MTK_FOE_IB2_DEST_PORT_V2 GENMASK(12, 9)
-+#define MTK_FOE_IB2_MULTICAST_V2 BIT(13)
-+#define MTK_FOE_IB2_WDMA_WINFO_V2 BIT(19)
-+#define MTK_FOE_IB2_PORT_AG_V2 GENMASK(23, 20)
-+
-+#define MTK_FOE_VLAN2_WINFO_BSS GENMASK(5, 0)
-+#define MTK_FOE_VLAN2_WINFO_WCID GENMASK(13, 6)
-+#define MTK_FOE_VLAN2_WINFO_RING GENMASK(15, 14)
-+
-+#define MTK_FOE_WINFO_BSS GENMASK(5, 0)
-+#define MTK_FOE_WINFO_WCID GENMASK(15, 6)
++#define MTK_FOE_VLAN2_WHNAT_BSS GEMMASK(5, 0)
++#define MTK_FOE_VLAN2_WHNAT_WCID GENMASK(13, 6)
++#define MTK_FOE_VLAN2_WHNAT_RING GENMASK(15, 14)
+
+enum {
+ MTK_FOE_STATE_INVALID,
@@ -1679,21 +837,21 @@
+
+ u16 pppoe_id;
+ u16 src_mac_lo;
-+
-+ u16 minfo;
-+ u16 winfo;
+};
+
-+/* software-only entry type */
+struct mtk_foe_bridge {
-+ u8 dest_mac[ETH_ALEN];
-+ u8 src_mac[ETH_ALEN];
-+ u16 vlan;
++ u32 dest_mac_hi;
++
++ u16 src_mac_lo;
++ u16 dest_mac_lo;
+
-+ struct {} key_end;
++ u32 src_mac_hi;
+
+ u32 ib2;
+
++ u32 _rsv[5];
++
++ u32 udf_tsid;
+ struct mtk_foe_mac_info l2;
+};
+
@@ -1799,7 +957,7 @@
+ struct mtk_foe_ipv4_dslite dslite;
+ struct mtk_foe_ipv6 ipv6;
+ struct mtk_foe_ipv6_6rd ipv6_6rd;
-+ u32 data[23];
++ u32 data[19];
+ };
+};
+
@@ -1832,136 +990,63 @@
+ MTK_PPE_CPU_REASON_INVALID = 0x1f,
+};
+
-+enum {
-+ MTK_FLOW_TYPE_L4,
-+ MTK_FLOW_TYPE_L2,
-+ MTK_FLOW_TYPE_L2_SUBFLOW,
-+};
-+
-+struct mtk_flow_entry {
-+ union {
-+ /* regular flows + L2 subflows */
-+ struct {
-+ struct hlist_node list;
-+ struct hlist_node l2_list;
-+ };
-+ /* L2 flows */
-+ struct {
-+ struct rhash_head l2_node;
-+ struct hlist_head l2_flows;
-+ };
-+ };
-+ u8 type;
-+ s8 wed_index;
-+ u8 ppe_index;
-+ u16 hash;
-+ struct mtk_foe_entry data;
-+ struct rhash_head node;
-+ unsigned long cookie;
-+ u64 prev_packets, prev_bytes;
-+ u64 packets, bytes;
-+};
-+
-+struct mtk_mib_entry {
-+ u32 byt_cnt_l;
-+ u16 byt_cnt_h;
-+ u32 pkt_cnt_l;
-+ u8 pkt_cnt_h;
-+ u8 _rsv0;
-+ u32 _rsv1;
-+} __packed;
-+
-+struct mtk_foe_accounting {
-+ u64 bytes;
-+ u64 packets;
-+};
-+
+struct mtk_ppe {
-+ struct mtk_eth *eth;
+ struct device *dev;
+ void __iomem *base;
+ int version;
-+ char dirname[5];
-+ bool accounting;
+
-+ void *foe_table;
++ struct mtk_foe_entry *foe_table;
+ dma_addr_t foe_phys;
+
-+ struct mtk_mib_entry *mib_table;
-+ dma_addr_t mib_phys;
-+
-+ u16 foe_check_time[MTK_PPE_ENTRIES];
-+ struct hlist_head *foe_flow;
-+
-+ struct rhashtable l2_flows;
-+
+ void *acct_table;
+};
+
-+struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int index);
-+void mtk_ppe_start(struct mtk_ppe *ppe);
++int mtk_ppe_init(struct mtk_ppe *ppe, struct device *dev, void __iomem *base,
++ int version);
++int mtk_ppe_start(struct mtk_ppe *ppe);
+int mtk_ppe_stop(struct mtk_ppe *ppe);
-+int mtk_ppe_prepare_reset(struct mtk_ppe *ppe);
-+struct mtk_foe_accounting *mtk_ppe_mib_entry_read(struct mtk_ppe *ppe, u16 index);
-+
-+void __mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash);
+
+static inline void
-+mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash)
++mtk_foe_entry_clear(struct mtk_ppe *ppe, u16 hash)
+{
-+ u16 now, diff;
-+
-+ if (!ppe)
-+ return;
++ ppe->foe_table[hash].ib1 = 0;
++ dma_wmb();
++}
+
-+ if (hash > MTK_PPE_HASH_MASK)
-+ return;
++static inline int
++mtk_foe_entry_timestamp(struct mtk_ppe *ppe, u16 hash)
++{
++ u32 ib1 = READ_ONCE(ppe->foe_table[hash].ib1);
+
-+ now = (u16)jiffies;
-+ diff = now - ppe->foe_check_time[hash];
-+ if (diff < HZ / 10)
-+ return;
++ if (FIELD_GET(MTK_FOE_IB1_STATE, ib1) != MTK_FOE_STATE_BIND)
++ return -1;
+
-+ ppe->foe_check_time[hash] = now;
-+ __mtk_ppe_check_skb(ppe, skb, hash);
++ return FIELD_GET(MTK_FOE_IB1_BIND_TIMESTAMP, ib1);
+}
+
-+int mtk_foe_entry_prepare(struct mtk_eth *eth, struct mtk_foe_entry *entry,
-+ int type, int l4proto, u8 pse_port, u8 *src_mac,
-+ u8 *dest_mac);
-+int mtk_foe_entry_set_pse_port(struct mtk_eth *eth,
-+ struct mtk_foe_entry *entry, u8 port);
-+int mtk_foe_entry_set_ipv4_tuple(struct mtk_eth *eth,
-+ struct mtk_foe_entry *entry, bool orig,
++int mtk_foe_entry_prepare(struct mtk_foe_entry *entry, int type, int l4proto,
++ u8 pse_port, u8 *src_mac, u8 *dest_mac);
++int mtk_foe_entry_set_pse_port(struct mtk_foe_entry *entry, u8 port);
++int mtk_foe_entry_set_ipv4_tuple(struct mtk_foe_entry *entry, bool orig,
+ __be32 src_addr, __be16 src_port,
+ __be32 dest_addr, __be16 dest_port);
-+int mtk_foe_entry_set_ipv6_tuple(struct mtk_eth *eth,
-+ struct mtk_foe_entry *entry,
++int mtk_foe_entry_set_ipv6_tuple(struct mtk_foe_entry *entry,
+ __be32 *src_addr, __be16 src_port,
+ __be32 *dest_addr, __be16 dest_port);
-+int mtk_foe_entry_set_dsa(struct mtk_eth *eth, struct mtk_foe_entry *entry,
-+ int port);
-+int mtk_foe_entry_set_vlan(struct mtk_eth *eth, struct mtk_foe_entry *entry,
-+ int vid);
-+int mtk_foe_entry_set_pppoe(struct mtk_eth *eth, struct mtk_foe_entry *entry,
-+ int sid);
-+int mtk_foe_entry_set_wdma(struct mtk_eth *eth, struct mtk_foe_entry *entry,
-+ int wdma_idx, int txq, int bss, int wcid);
-+int mtk_foe_entry_set_queue(struct mtk_eth *eth, struct mtk_foe_entry *entry,
-+ unsigned int queue);
-+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_ppe_debugfs_init(struct mtk_ppe *ppe, int index);
-+void mtk_foe_entry_get_stats(struct mtk_ppe *ppe, struct mtk_flow_entry *entry,
-+ int *idle);
++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);
++int mtk_foe_entry_set_pppoe(struct mtk_foe_entry *entry, int sid);
++int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_foe_entry *entry,
++ u16 timestamp);
++int mtk_ppe_debugfs_init(struct mtk_ppe *ppe);
+
+#endif
diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c b/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
new file mode 100644
-index 0000000..322b8f4
+index 000000000..d4b482340
--- /dev/null
+++ b/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
-@@ -0,0 +1,221 @@
+@@ -0,0 +1,214 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (C) 2020 Felix Fietkau <nbd@nbd.name> */
+
@@ -1996,6 +1081,7 @@
+ static const char * const type_str[] = {
+ [MTK_PPE_PKT_TYPE_IPV4_HNAPT] = "IPv4 5T",
+ [MTK_PPE_PKT_TYPE_IPV4_ROUTE] = "IPv4 3T",
++ [MTK_PPE_PKT_TYPE_BRIDGE] = "L2",
+ [MTK_PPE_PKT_TYPE_IPV4_DSLITE] = "DS-LITE",
+ [MTK_PPE_PKT_TYPE_IPV6_ROUTE_3T] = "IPv6 3T",
+ [MTK_PPE_PKT_TYPE_IPV6_ROUTE_5T] = "IPv6 5T",
@@ -2043,10 +1129,9 @@
+ int i;
+
+ for (i = 0; i < MTK_PPE_ENTRIES; i++) {
-+ struct mtk_foe_entry *entry = mtk_foe_get_entry(ppe, i);
++ struct mtk_foe_entry *entry = &ppe->foe_table[i];
+ struct mtk_foe_mac_info *l2;
+ struct mtk_flow_addr_info ai = {};
-+ struct mtk_foe_accounting *acct;
+ unsigned char h_source[ETH_ALEN];
+ unsigned char h_dest[ETH_ALEN];
+ int type, state;
@@ -2060,8 +1145,6 @@
+ if (bind && state != MTK_FOE_STATE_BIND)
+ continue;
+
-+ acct = mtk_ppe_mib_entry_read(ppe, i);
-+
+ type = FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, entry->ib1);
+ seq_printf(m, "%05x %s %7s", i,
+ mtk_foe_entry_state_str(state),
@@ -2120,11 +1203,9 @@
+ *((__be16 *)&h_dest[4]) = htons(l2->dest_mac_lo);
+
+ seq_printf(m, " eth=%pM->%pM etype=%04x"
-+ " vlan=%d,%d ib1=%08x ib2=%08x"
-+ " packets=%llu bytes=%llu\n",
++ " vlan=%d,%d ib1=%08x ib2=%08x\n",
+ h_source, h_dest, ntohs(l2->etype),
-+ l2->vlan1, l2->vlan2, entry->ib1, ib2,
-+ acct ? acct->packets : 0, acct ? acct->bytes : 0);
++ l2->vlan1, l2->vlan2, entry->ib1, ib2);
+ }
+
+ return 0;
@@ -2156,7 +1237,7 @@
+ inode->i_private);
+}
+
-+int mtk_ppe_debugfs_init(struct mtk_ppe *ppe, int index)
++int mtk_ppe_debugfs_init(struct mtk_ppe *ppe)
+{
+ static const struct file_operations fops_all = {
+ .open = mtk_ppe_debugfs_foe_open_all,
@@ -2164,20 +1245,17 @@
+ .llseek = seq_lseek,
+ .release = single_release,
+ };
++
+ static const struct file_operations fops_bind = {
+ .open = mtk_ppe_debugfs_foe_open_bind,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+ };
-+ struct dentry *root;
-+
-+ snprintf(ppe->dirname, sizeof(ppe->dirname), "ppe%d", index);
+
-+ root = debugfs_create_dir(ppe->dirname, NULL);
-+ if (!root)
-+ return -ENOMEM;
++ struct dentry *root;
+
++ root = debugfs_create_dir("mtk_ppe", NULL);
+ debugfs_create_file("entries", S_IRUGO, root, ppe, &fops_all);
+ debugfs_create_file("bind", S_IRUGO, root, ppe, &fops_bind);
+
@@ -2185,10 +1263,10 @@
+}
diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
new file mode 100644
-index 0000000..afe3780
+index 000000000..4294f0c74
--- /dev/null
+++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
-@@ -0,0 +1,566 @@
+@@ -0,0 +1,535 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2020 Felix Fietkau <nbd@nbd.name>
@@ -2221,8 +1299,6 @@
+ __be16 src_port;
+ __be16 dst_port;
+
-+ u16 vlan_in;
-+
+ struct {
+ u16 id;
+ __be16 proto;
@@ -2234,6 +1310,12 @@
+ } pppoe;
+};
+
++struct mtk_flow_entry {
++ struct rhash_head node;
++ unsigned long cookie;
++ u16 hash;
++};
++
+static const struct rhashtable_params mtk_flow_ht_params = {
+ .head_offset = offsetof(struct mtk_flow_entry, node),
+ .key_offset = offsetof(struct mtk_flow_entry, cookie),
@@ -2241,20 +1323,25 @@
+ .automatic_shrinking = true,
+};
+
++static u32
++mtk_eth_timestamp(struct mtk_eth *eth)
++{
++ return mtk_r32(eth, 0x0010) & MTK_FOE_IB1_BIND_TIMESTAMP;
++}
++
+static int
-+mtk_flow_set_ipv4_addr(struct mtk_eth *eth, struct mtk_foe_entry *foe,
-+ struct mtk_flow_data *data, bool egress)
++mtk_flow_set_ipv4_addr(struct mtk_foe_entry *foe, struct mtk_flow_data *data,
++ bool egress)
+{
-+ return mtk_foe_entry_set_ipv4_tuple(eth, foe, egress,
++ return mtk_foe_entry_set_ipv4_tuple(foe, egress,
+ data->v4.src_addr, data->src_port,
+ data->v4.dst_addr, data->dst_port);
+}
+
+static int
-+mtk_flow_set_ipv6_addr(struct mtk_eth *eth, struct mtk_foe_entry *foe,
-+ struct mtk_flow_data *data)
++mtk_flow_set_ipv6_addr(struct mtk_foe_entry *foe, struct mtk_flow_data *data)
+{
-+ return mtk_foe_entry_set_ipv6_tuple(eth, foe,
++ return mtk_foe_entry_set_ipv6_tuple(foe,
+ data->v6.src_addr.s6_addr32, data->src_port,
+ data->v6.dst_addr.s6_addr32, data->dst_port);
+}
@@ -2276,6 +1363,7 @@
+ memcpy(dest, src, act->mangle.mask ? 2 : 4);
+}
+
++
+static int
+mtk_flow_mangle_ports(const struct flow_action_entry *act,
+ struct mtk_flow_data *data)
@@ -2344,37 +1432,28 @@
+
+static int
+mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
-+ struct net_device *dev, const u8 *dest_mac,
-+ int *wed_index)
++ struct net_device *dev)
+{
-+ int pse_port, dsa_port, queue;
++ int pse_port, dsa_port;
+
+ dsa_port = mtk_flow_get_dsa_port(&dev);
++ if (dsa_port >= 0)
++ mtk_foe_entry_set_dsa(foe, dsa_port);
+
+ if (dev == eth->netdev[0])
-+ pse_port = 1;
++ pse_port = PSE_GDM1_PORT;
+ else if (dev == eth->netdev[1])
-+ pse_port = 2;
-+ else
-+ return -EOPNOTSUPP;
-+
-+ if (dsa_port >= 0) {
-+ mtk_foe_entry_set_dsa(eth, foe, dsa_port);
-+ queue = 3 + dsa_port;
-+ } else {
-+ queue = pse_port - 1;
-+ }
-+ mtk_foe_entry_set_queue(eth, foe, queue);
++ pse_port = PSE_GDM2_PORT;
++ else
++ return -EOPNOTSUPP;
+
-+out:
-+ mtk_foe_entry_set_pse_port(eth, foe, pse_port);
++ mtk_foe_entry_set_pse_port(foe, pse_port);
+
+ return 0;
+}
+
+static int
-+mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f,
-+ int ppe_index)
++mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
+{
+ struct flow_rule *rule = flow_cls_offload_flow_rule(f);
+ struct flow_action_entry *act;
@@ -2383,10 +1462,11 @@
+ struct net_device *odev = NULL;
+ struct mtk_flow_entry *entry;
+ int offload_type = 0;
-+ int wed_index = -1;
+ u16 addr_type = 0;
++ u32 timestamp;
+ u8 l4proto = 0;
+ int err = 0;
++ int hash;
+ int i;
+
+ if (rhashtable_lookup(ð->flow_table, &f->cookie, mtk_flow_ht_params))
@@ -2418,45 +1498,9 @@
+ return -EOPNOTSUPP;
+ }
+
-+ switch (addr_type) {
-+ case 0:
-+ offload_type = MTK_PPE_PKT_TYPE_BRIDGE;
-+ if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
-+ struct flow_match_eth_addrs match;
-+
-+ flow_rule_match_eth_addrs(rule, &match);
-+ memcpy(data.eth.h_dest, match.key->dst, ETH_ALEN);
-+ memcpy(data.eth.h_source, match.key->src, ETH_ALEN);
-+ } else {
-+ return -EOPNOTSUPP;
-+ }
-+
-+ if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_VLAN)) {
-+ struct flow_match_vlan match;
-+
-+ flow_rule_match_vlan(rule, &match);
-+
-+ if (match.key->vlan_tpid != cpu_to_be16(ETH_P_8021Q))
-+ return -EOPNOTSUPP;
-+
-+ data.vlan_in = match.key->vlan_id;
-+ }
-+ break;
-+ case FLOW_DISSECTOR_KEY_IPV4_ADDRS:
-+ offload_type = MTK_PPE_PKT_TYPE_IPV4_HNAPT;
-+ break;
-+ case FLOW_DISSECTOR_KEY_IPV6_ADDRS:
-+ offload_type = MTK_PPE_PKT_TYPE_IPV6_ROUTE_5T;
-+ break;
-+ default:
-+ return -EOPNOTSUPP;
-+ }
-+
+ flow_action_for_each(i, act, &rule->action) {
+ switch (act->id) {
+ case FLOW_ACTION_MANGLE:
-+ if (offload_type == MTK_PPE_PKT_TYPE_BRIDGE)
-+ return -EOPNOTSUPP;
+ if (act->mangle.htype == FLOW_ACT_MANGLE_HDR_TYPE_ETH)
+ mtk_flow_offload_mangle_eth(act, &data.eth);
+ break;
@@ -2488,25 +1532,34 @@
+ }
+ }
+
++ switch (addr_type) {
++ case FLOW_DISSECTOR_KEY_IPV4_ADDRS:
++ offload_type = MTK_PPE_PKT_TYPE_IPV4_HNAPT;
++ break;
++ case FLOW_DISSECTOR_KEY_IPV6_ADDRS:
++ offload_type = MTK_PPE_PKT_TYPE_IPV6_ROUTE_5T;
++ break;
++ default:
++ return -EOPNOTSUPP;
++ }
++
+ if (!is_valid_ether_addr(data.eth.h_source) ||
+ !is_valid_ether_addr(data.eth.h_dest))
+ return -EINVAL;
+
-+ err = mtk_foe_entry_prepare(eth, &foe, offload_type, l4proto, 0,
-+ data.eth.h_source, data.eth.h_dest);
++ err = mtk_foe_entry_prepare(&foe, offload_type, l4proto, 0,
++ data.eth.h_source,
++ data.eth.h_dest);
+ if (err)
+ return err;
+
+ if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_PORTS)) {
+ struct flow_match_ports ports;
+
-+ if (offload_type == MTK_PPE_PKT_TYPE_BRIDGE)
-+ return -EOPNOTSUPP;
-+
+ flow_rule_match_ports(rule, &ports);
+ data.src_port = ports.key->src;
+ data.dst_port = ports.key->dst;
-+ } else if (offload_type != MTK_PPE_PKT_TYPE_BRIDGE) {
++ } else {
+ return -EOPNOTSUPP;
+ }
+
@@ -2518,7 +1571,7 @@
+ data.v4.src_addr = addrs.key->src;
+ data.v4.dst_addr = addrs.key->dst;
+
-+ mtk_flow_set_ipv4_addr(eth, &foe, &data, false);
++ mtk_flow_set_ipv4_addr(&foe, &data, false);
+ }
+
+ if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) {
@@ -2529,16 +1582,13 @@
+ data.v6.src_addr = addrs.key->src;
+ data.v6.dst_addr = addrs.key->dst;
+
-+ mtk_flow_set_ipv6_addr(eth, &foe, &data);
++ mtk_flow_set_ipv6_addr(&foe, &data);
+ }
+
+ flow_action_for_each(i, act, &rule->action) {
+ if (act->id != FLOW_ACTION_MANGLE)
+ continue;
+
-+ if (offload_type == MTK_PPE_PKT_TYPE_BRIDGE)
-+ return -EOPNOTSUPP;
-+
+ switch (act->mangle.htype) {
+ case FLOW_ACT_MANGLE_HDR_TYPE_TCP:
+ case FLOW_ACT_MANGLE_HDR_TYPE_UDP:
@@ -2559,25 +1609,21 @@
+ }
+
+ if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
-+ err = mtk_flow_set_ipv4_addr(eth, &foe, &data, true);
++ err = mtk_flow_set_ipv4_addr(&foe, &data, true);
+ if (err)
+ return err;
+ }
+
-+ if (offload_type == MTK_PPE_PKT_TYPE_BRIDGE)
-+ foe.bridge.vlan = data.vlan_in;
-+
+ if (data.vlan.num == 1) {
+ if (data.vlan.proto != htons(ETH_P_8021Q))
+ return -EOPNOTSUPP;
+
-+ mtk_foe_entry_set_vlan(eth, &foe, data.vlan.id);
++ mtk_foe_entry_set_vlan(&foe, data.vlan.id);
+ }
+ if (data.pppoe.num == 1)
-+ mtk_foe_entry_set_pppoe(eth, &foe, data.pppoe.sid);
++ mtk_foe_entry_set_pppoe(&foe, data.pppoe.sid);
+
-+ err = mtk_flow_set_output_device(eth, &foe, odev, data.eth.h_dest,
-+ &wed_index);
++ err = mtk_flow_set_output_device(eth, &foe, odev);
+ if (err)
+ return err;
+
@@ -2586,22 +1632,22 @@
+ return -ENOMEM;
+
+ entry->cookie = f->cookie;
-+ memcpy(&entry->data, &foe, sizeof(entry->data));
-+ entry->ppe_index = ppe_index;
-+
-+ err = mtk_foe_entry_commit(eth->ppe[entry->ppe_index], entry);
-+ if (err < 0)
++ timestamp = mtk_eth_timestamp(eth);
++ hash = mtk_foe_entry_commit(ð->ppe, &foe, timestamp);
++ if (hash < 0) {
++ err = hash;
+ goto free;
++ }
+
++ entry->hash = hash;
+ err = rhashtable_insert_fast(ð->flow_table, &entry->node,
+ mtk_flow_ht_params);
+ if (err < 0)
-+ goto clear;
++ goto clear_flow;
+
+ return 0;
-+
-+clear:
-+ mtk_foe_entry_clear(eth->ppe[entry->ppe_index], entry);
++clear_flow:
++ mtk_foe_entry_clear(ð->ppe, hash);
+free:
+ kfree(entry);
+ return err;
@@ -2617,7 +1663,7 @@
+ if (!entry)
+ return -ENOENT;
+
-+ mtk_foe_entry_clear(eth->ppe[entry->ppe_index], entry);
++ mtk_foe_entry_clear(ð->ppe, entry->hash);
+ rhashtable_remove_fast(ð->flow_table, &entry->node,
+ mtk_flow_ht_params);
+ kfree(entry);
@@ -2629,19 +1675,19 @@
+mtk_flow_offload_stats(struct mtk_eth *eth, struct flow_cls_offload *f)
+{
+ struct mtk_flow_entry *entry;
-+ u64 packets, bytes;
-+ int idle;
++ int timestamp;
++ u32 idle;
+
+ entry = rhashtable_lookup(ð->flow_table, &f->cookie,
+ mtk_flow_ht_params);
+ if (!entry)
+ return -ENOENT;
+
-+ packets = entry->packets;
-+ bytes = entry->bytes;
-+ mtk_foe_entry_get_stats(eth->ppe[entry->ppe_index], entry, &idle);
-+ f->stats.pkts += entry->packets - packets;
-+ f->stats.bytes += entry->bytes - bytes;
++ timestamp = mtk_foe_entry_timestamp(ð->ppe, entry->hash);
++ if (timestamp < 0)
++ return -ETIMEDOUT;
++
++ idle = mtk_eth_timestamp(eth) - timestamp;
+ f->stats.lastused = jiffies - idle * HZ;
+
+ return 0;
@@ -2649,15 +1695,25 @@
+
+static DEFINE_MUTEX(mtk_flow_offload_mutex);
+
-+int mtk_flow_offload_cmd(struct mtk_eth *eth, struct flow_cls_offload *cls,
-+ int ppe_index)
++static int
++mtk_eth_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_priv)
+{
++ struct flow_cls_offload *cls = type_data;
++ struct net_device *dev = cb_priv;
++ struct mtk_mac *mac = netdev_priv(dev);
++ struct mtk_eth *eth = mac->hw;
+ int err;
+
++ if (!tc_can_offload(dev))
++ return -EOPNOTSUPP;
++
++ if (type != TC_SETUP_CLSFLOWER)
++ return -EOPNOTSUPP;
++
+ mutex_lock(&mtk_flow_offload_mutex);
+ switch (cls->command) {
+ case FLOW_CLS_REPLACE:
-+ err = mtk_flow_offload_replace(eth, cls, ppe_index);
++ err = mtk_flow_offload_replace(eth, cls);
+ break;
+ case FLOW_CLS_DESTROY:
+ err = mtk_flow_offload_destroy(eth, cls);
@@ -2675,23 +1731,6 @@
+}
+
+static int
-+mtk_eth_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_priv)
-+{
-+ struct flow_cls_offload *cls = type_data;
-+ struct net_device *dev = cb_priv;
-+ struct mtk_mac *mac = netdev_priv(dev);
-+ struct mtk_eth *eth = mac->hw;
-+
-+ if (!tc_can_offload(dev))
-+ return -EOPNOTSUPP;
-+
-+ if (type != TC_SETUP_CLSFLOWER)
-+ return -EOPNOTSUPP;
-+
-+ return mtk_flow_offload_cmd(eth, cls, 0);
-+}
-+
-+static int
+mtk_eth_setup_tc_block(struct net_device *dev, struct flow_block_offload *f)
+{
+ struct mtk_mac *mac = netdev_priv(dev);
@@ -2699,8 +1738,9 @@
+ static LIST_HEAD(block_cb_list);
+ struct flow_block_cb *block_cb;
+ flow_setup_cb_t *cb;
++ int err = 0;
+
-+ if (!eth->soc->offload_version)
++ if (!eth->ppe.foe_table)
+ return -EOPNOTSUPP;
+
+ if (f->binder_type != FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
@@ -2714,53 +1754,60 @@
+ block_cb = flow_block_cb_lookup(f->block, cb, dev);
+ if (block_cb) {
+ flow_block_cb_incref(block_cb);
-+ return 0;
++ goto unlock;
+ }
+ block_cb = flow_block_cb_alloc(cb, dev, dev, NULL);
-+ if (IS_ERR(block_cb))
-+ return PTR_ERR(block_cb);
++ if (IS_ERR(block_cb)) {
++ err = PTR_ERR(block_cb);
++ goto unlock;
++ }
+
-+ flow_block_cb_incref(block_cb);
+ flow_block_cb_add(block_cb, f);
+ list_add_tail(&block_cb->driver_list, &block_cb_list);
-+ return 0;
++ break;
+ case FLOW_BLOCK_UNBIND:
+ block_cb = flow_block_cb_lookup(f->block, cb, dev);
-+ if (!block_cb)
-+ return -ENOENT;
++ if (!block_cb) {
++ err = -ENOENT;
++ goto unlock;
++ }
+
-+ if (!flow_block_cb_decref(block_cb)) {
++ if (flow_block_cb_decref(block_cb)) {
+ flow_block_cb_remove(block_cb, f);
+ list_del(&block_cb->driver_list);
+ }
-+ return 0;
++ break;
+ default:
-+ return -EOPNOTSUPP;
++ err = -EOPNOTSUPP;
++ break;
+ }
++
++unlock:
++ return err;
+}
+
+int mtk_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,
+ void *type_data)
+{
-+ switch (type) {
-+ case TC_SETUP_BLOCK:
-+ case TC_SETUP_FT:
++ if (type == TC_SETUP_FT)
+ return mtk_eth_setup_tc_block(dev, type_data);
-+ default:
-+ return -EOPNOTSUPP;
-+ }
++
++ return -EOPNOTSUPP;
+}
+
+int mtk_eth_offload_init(struct mtk_eth *eth)
+{
++ if (!eth->ppe.foe_table)
++ return 0;
++
+ return rhashtable_init(ð->flow_table, &mtk_flow_ht_params);
+}
diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_regs.h b/drivers/net/ethernet/mediatek/mtk_ppe_regs.h
new file mode 100644
-index 0000000..a2e61b3
+index 000000000..0c45ea090
--- /dev/null
+++ b/drivers/net/ethernet/mediatek/mtk_ppe_regs.h
-@@ -0,0 +1,172 @@
+@@ -0,0 +1,144 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (C) 2020 Felix Fietkau <nbd@nbd.name> */
+
@@ -2784,9 +1831,6 @@
+#define MTK_PPE_GLO_CFG_BUSY BIT(31)
+
+#define MTK_PPE_FLOW_CFG 0x204
-+#define MTK_PPE_MD_TOAP_BYP_CRSN0 BIT(1)
-+#define MTK_PPE_MD_TOAP_BYP_CRSN1 BIT(2)
-+#define MTK_PPE_MD_TOAP_BYP_CRSN2 BIT(3)
+#define MTK_PPE_FLOW_CFG_IP4_TCP_FRAG BIT(6)
+#define MTK_PPE_FLOW_CFG_IP4_UDP_FRAG BIT(7)
+#define MTK_PPE_FLOW_CFG_IP6_3T_ROUTE BIT(8)
@@ -2820,13 +1864,6 @@
+#define MTK_PPE_TB_CFG_HASH_MODE GENMASK(15, 14)
+#define MTK_PPE_TB_CFG_SCAN_MODE GENMASK(17, 16)
+#define MTK_PPE_TB_CFG_HASH_DEBUG GENMASK(19, 18)
-+#define MTK_PPE_TB_CFG_INFO_SEL BIT(20)
-+#define MTK_PPE_TB_TICK_SEL BIT(24)
-+
-+#define MTK_PPE_BIND_LMT1 0x230
-+#define MTK_PPE_NTU_KEEPALIVE GENMASK(23, 16)
-+
-+#define MTK_PPE_KEEPALIVE 0x234
+
+enum {
+ MTK_PPE_SCAN_MODE_DISABLED,
@@ -2885,8 +1922,6 @@
+#define MTK_PPE_DEFAULT_CPU_PORT 0x248
+#define MTK_PPE_DEFAULT_CPU_PORT_MASK(_n) (GENMASK(2, 0) << ((_n) * 4))
+
-+#define MTK_PPE_DEFAULT_CPU_PORT1 0x24c
-+
+#define MTK_PPE_MTU_DROP 0x308
+
+#define MTK_PPE_VLAN_MTU0 0x30c
@@ -2912,29 +1947,13 @@
+
+#define MTK_PPE_MIB_TB_BASE 0x338
+
-+#define MTK_PPE_MIB_SER_CR 0x33C
-+#define MTK_PPE_MIB_SER_CR_ST BIT(16)
-+#define MTK_PPE_MIB_SER_CR_ADDR GENMASK(13, 0)
-+
-+#define MTK_PPE_MIB_SER_R0 0x340
-+#define MTK_PPE_MIB_SER_R0_BYTE_CNT_LOW GENMASK(31, 0)
-+
-+#define MTK_PPE_MIB_SER_R1 0x344
-+#define MTK_PPE_MIB_SER_R1_PKT_CNT_LOW GENMASK(31, 16)
-+#define MTK_PPE_MIB_SER_R1_BYTE_CNT_HIGH GENMASK(15, 0)
-+
-+#define MTK_PPE_MIB_SER_R2 0x348
-+#define MTK_PPE_MIB_SER_R2_PKT_CNT_HIGH GENMASK(23, 0)
-+
+#define MTK_PPE_MIB_CACHE_CTL 0x350
+#define MTK_PPE_MIB_CACHE_CTL_EN BIT(0)
+#define MTK_PPE_MIB_CACHE_CTL_FLUSH BIT(2)
+
-+#define MTK_PPE_SBW_CTRL 0x374
-+
+#endif
diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
-index 078c0f4..f8a98d8 100644
+index a085213dc..813e30495 100644
--- a/drivers/net/ppp/ppp_generic.c
+++ b/drivers/net/ppp/ppp_generic.c
@@ -1378,12 +1378,34 @@ static void ppp_dev_priv_destructor(struct net_device *dev)
@@ -2973,7 +1992,7 @@
static struct device_type ppp_type = {
diff --git a/drivers/net/ppp/pppoe.c b/drivers/net/ppp/pppoe.c
-index 087b016..7a8c246 100644
+index 087b01684..7a8c246ab 100644
--- a/drivers/net/ppp/pppoe.c
+++ b/drivers/net/ppp/pppoe.c
@@ -974,8 +974,32 @@ static int pppoe_xmit(struct ppp_channel *chan, struct sk_buff *skb)
@@ -3010,10 +2029,10 @@
static int pppoe_recvmsg(struct socket *sock, struct msghdr *m,
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
-index c2953e8..a921fa5 100644
+index 38af42bf8..9f64504ac 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
-@@ -838,6 +838,66 @@ typedef u16 (*select_queue_fallback_t)(struct net_device *dev,
+@@ -829,6 +829,59 @@ typedef u16 (*select_queue_fallback_t)(struct net_device *dev,
struct sk_buff *skb,
struct net_device *sb_dev);
@@ -3023,7 +2042,6 @@
+ DEV_PATH_BRIDGE,
+ DEV_PATH_PPPOE,
+ DEV_PATH_DSA,
-+ DEV_PATH_MTK_WDMA,
+};
+
+struct net_device_path {
@@ -3049,12 +2067,6 @@
+ int port;
+ u16 proto;
+ } dsa;
-+ struct {
-+ u8 wdma_idx;
-+ u8 queue;
-+ u16 wcid;
-+ u8 bss;
-+ } mtk_wdma;
+ };
+};
+
@@ -3080,7 +2092,7 @@
enum tc_setup_type {
TC_SETUP_QDISC_MQPRIO,
TC_SETUP_CLSU32,
-@@ -853,6 +913,7 @@ enum tc_setup_type {
+@@ -844,6 +897,7 @@ enum tc_setup_type {
TC_SETUP_ROOT_QDISC,
TC_SETUP_QDISC_GRED,
TC_SETUP_QDISC_TAPRIO,
@@ -3088,29 +2100,25 @@
};
/* These structures hold the attributes of bpf state that are being passed
-@@ -1248,6 +1309,10 @@ struct tlsdev_ops;
+@@ -1239,6 +1293,8 @@ struct tlsdev_ops;
* Get devlink port instance associated with a given netdev.
* Called with a reference on the netdevice and devlink locks only,
* rtnl_lock is not held.
+ * int (*ndo_fill_forward_path)(struct net_device_path_ctx *ctx, struct net_device_path *path);
+ * Get the forwarding path to reach the real device from the HW destination address
-+ * int (*ndo_fill_receive_path)(struct net_device_path_ctx *ctx, struct net_device_path *path);
-+ * Get the receiving path to reach the real device from the HW source address
*/
struct net_device_ops {
int (*ndo_init)(struct net_device *dev);
-@@ -1445,6 +1510,10 @@ struct net_device_ops {
+@@ -1436,6 +1492,8 @@ struct net_device_ops {
int (*ndo_xsk_wakeup)(struct net_device *dev,
u32 queue_id, u32 flags);
struct devlink_port * (*ndo_get_devlink_port)(struct net_device *dev);
+ int (*ndo_fill_forward_path)(struct net_device_path_ctx *ctx,
+ struct net_device_path *path);
-+ int (*ndo_fill_receive_path)(struct net_device_path_ctx *ctx,
-+ struct net_device_path *path);
};
/**
-@@ -2670,6 +2739,8 @@ void dev_remove_offload(struct packet_offload *po);
+@@ -2661,6 +2719,8 @@ void dev_remove_offload(struct packet_offload *po);
int dev_get_iflink(const struct net_device *dev);
int dev_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb);
@@ -3120,7 +2128,7 @@
unsigned short mask);
struct net_device *dev_get_by_name(struct net *net, const char *name);
diff --git a/include/linux/ppp_channel.h b/include/linux/ppp_channel.h
-index 9896606..91f9a92 100644
+index 98966064e..91f9a9283 100644
--- a/include/linux/ppp_channel.h
+++ b/include/linux/ppp_channel.h
@@ -28,6 +28,9 @@ struct ppp_channel_ops {
@@ -3134,10 +2142,10 @@
struct ppp_channel {
diff --git a/include/net/dsa.h b/include/net/dsa.h
-index d29ee9e..43f65cb 100644
+index 05f66d487..cafc74218 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
-@@ -562,6 +562,8 @@ struct dsa_switch_ops {
+@@ -561,6 +561,8 @@ struct dsa_switch_ops {
struct sk_buff *skb);
};
@@ -3146,7 +2154,7 @@
struct dsa_switch_driver {
struct list_head list;
const struct dsa_switch_ops *ops;
-@@ -654,6 +656,14 @@ static inline int call_dsa_notifiers(unsigned long val, struct net_device *dev,
+@@ -653,6 +655,14 @@ static inline int call_dsa_notifiers(unsigned long val, struct net_device *dev,
#define BRCM_TAG_GET_PORT(v) ((v) >> 8)
#define BRCM_TAG_GET_QUEUE(v) ((v) & 0xff)
@@ -3162,7 +2170,7 @@
netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev);
int dsa_port_get_phy_strings(struct dsa_port *dp, uint8_t *data);
diff --git a/include/net/flow_offload.h b/include/net/flow_offload.h
-index c6f7bd2..59b8736 100644
+index c6f7bd22d..59b873653 100644
--- a/include/net/flow_offload.h
+++ b/include/net/flow_offload.h
@@ -138,6 +138,7 @@ enum flow_action_id {
@@ -3184,7 +2192,7 @@
};
diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h
-index 2c739fc..89ab8f1 100644
+index 2c739fc75..89ab8f180 100644
--- a/include/net/ip6_route.h
+++ b/include/net/ip6_route.h
@@ -314,12 +314,13 @@ static inline bool rt6_duplicate_nexthop(struct fib6_info *a, struct fib6_info *
@@ -3204,7 +2212,7 @@
if (mtu)
goto out;
diff --git a/include/net/netfilter/ipv6/nf_conntrack_ipv6.h b/include/net/netfilter/ipv6/nf_conntrack_ipv6.h
-index 7b3c873..e954831 100644
+index 7b3c873f8..e95483192 100644
--- a/include/net/netfilter/ipv6/nf_conntrack_ipv6.h
+++ b/include/net/netfilter/ipv6/nf_conntrack_ipv6.h
@@ -4,7 +4,4 @@
@@ -3216,7 +2224,7 @@
-
#endif /* _NF_CONNTRACK_IPV6_H*/
diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h
-index 90690e3..ce0bc3e 100644
+index 90690e37a..ce0bc3e62 100644
--- a/include/net/netfilter/nf_conntrack.h
+++ b/include/net/netfilter/nf_conntrack.h
@@ -279,6 +279,18 @@ static inline bool nf_ct_should_gc(const struct nf_conn *ct)
@@ -3239,7 +2247,7 @@
int nf_conntrack_set_hashsize(const char *val, const struct kernel_param *kp);
diff --git a/include/net/netfilter/nf_conntrack_acct.h b/include/net/netfilter/nf_conntrack_acct.h
-index f7a060c..7f44a77 100644
+index f7a060c6e..7f44a7715 100644
--- a/include/net/netfilter/nf_conntrack_acct.h
+++ b/include/net/netfilter/nf_conntrack_acct.h
@@ -65,6 +65,17 @@ static inline void nf_ct_set_acct(struct net *net, bool enable)
@@ -3261,7 +2269,7 @@
int nf_conntrack_acct_init(void);
diff --git a/include/net/netfilter/nf_flow_table.h b/include/net/netfilter/nf_flow_table.h
-index 68d7fc9..7cf8976 100644
+index 68d7fc92..7cf89767 100644
--- a/include/net/netfilter/nf_flow_table.h
+++ b/include/net/netfilter/nf_flow_table.h
@@ -8,31 +8,99 @@
@@ -3401,7 +2409,7 @@
};
};
-@@ -67,52 +152,139 @@ struct flow_offload_tuple_rhash {
+@@ -67,52 +152,140 @@ struct flow_offload_tuple_rhash {
struct flow_offload_tuple tuple;
};
@@ -3414,6 +2422,7 @@
+ NF_FLOW_DNAT,
+ NF_FLOW_TEARDOWN,
+ NF_FLOW_HW,
++ NF_FLOW_HW_ACCT_DYING,
+ NF_FLOW_HW_DYING,
+ NF_FLOW_HW_DEAD,
+ NF_FLOW_HW_PENDING,
@@ -3572,7 +2581,7 @@
+void nf_flow_offload_del(struct nf_flowtable *flowtable,
+ struct flow_offload *flow);
+void nf_flow_offload_stats(struct nf_flowtable *flowtable,
-+ struct flow_offload *flow);
++ struct flow_offload *flow, bool force);
+
+void nf_flow_table_offload_flush(struct nf_flowtable *flowtable);
+int nf_flow_table_offload_setup(struct nf_flowtable *flowtable,
@@ -3606,7 +2615,7 @@
+
#endif /* _NF_FLOW_TABLE_H */
diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
-index 806454e..9e3963c 100644
+index 806454e76..9e3963c8f 100644
--- a/include/net/netns/conntrack.h
+++ b/include/net/netns/conntrack.h
@@ -27,6 +27,9 @@ struct nf_tcp_net {
@@ -3630,7 +2639,7 @@
struct nf_icmp_net {
diff --git a/include/uapi/linux/netfilter/nf_conntrack_common.h b/include/uapi/linux/netfilter/nf_conntrack_common.h
-index 336014b..ae698d1 100644
+index 336014bf8..ae698d11c 100644
--- a/include/uapi/linux/netfilter/nf_conntrack_common.h
+++ b/include/uapi/linux/netfilter/nf_conntrack_common.h
@@ -105,14 +105,19 @@ enum ip_conntrack_status {
@@ -3657,7 +2666,7 @@
/* Connection tracking event types */
diff --git a/include/uapi/linux/netfilter/xt_FLOWOFFLOAD.h b/include/uapi/linux/netfilter/xt_FLOWOFFLOAD.h
new file mode 100644
-index 0000000..5841bbe
+index 000000000..5841bbe0e
--- /dev/null
+++ b/include/uapi/linux/netfilter/xt_FLOWOFFLOAD.h
@@ -0,0 +1,17 @@
@@ -3679,7 +2688,7 @@
+
+#endif /* _XT_FLOWOFFLOAD_H */
diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c
-index 589615e..444ab5f 100644
+index 589615ec4..444ab5fae 100644
--- a/net/8021q/vlan_dev.c
+++ b/net/8021q/vlan_dev.c
@@ -747,6 +747,26 @@ static int vlan_dev_get_iflink(const struct net_device *dev)
@@ -3718,7 +2727,7 @@
static void vlan_dev_free(struct net_device *dev)
diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c
-index 501f77f..0940b44 100644
+index 501f77f0f..0940b44cd 100644
--- a/net/bridge/br_device.c
+++ b/net/bridge/br_device.c
@@ -377,6 +377,54 @@ static int br_del_slave(struct net_device *dev, struct net_device *slave_dev)
@@ -3785,7 +2794,7 @@
static struct device_type br_type = {
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
-index a736be8..4bd9e9b 100644
+index a736be8a1..4bd9e9b57 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -912,6 +912,13 @@ void br_vlan_port_event(struct net_bridge_port *p, unsigned long event);
@@ -3823,7 +2832,7 @@
const struct net_bridge *br)
{
diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
-index 9257292..bcfd169 100644
+index 9257292bd..bcfd16924 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -1268,6 +1268,61 @@ int br_vlan_get_pvid_rcu(const struct net_device *dev, u16 *p_pvid)
@@ -3889,7 +2898,7 @@
struct bridge_vlan_info *p_vinfo)
{
diff --git a/net/core/dev.c b/net/core/dev.c
-index 794c768..a1f046c 100644
+index fe2c856b9..4f0edb218 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -639,6 +639,52 @@ int dev_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb)
@@ -3946,7 +2955,7 @@
* __dev_get_by_name - find a device by its name
* @net: the applicable net namespace
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
-index ca80f86..35a1249 100644
+index ca80f8699..35a1249a9 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -329,6 +329,15 @@ int call_dsa_notifiers(unsigned long val, struct net_device *dev,
@@ -3966,10 +2975,10 @@
{
int rc;
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
-index e2b91b3..2dfaa1e 100644
+index 036fda317..2dfaa1eac 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
-@@ -1031,14 +1031,32 @@ static int dsa_slave_setup_tc_block(struct net_device *dev,
+@@ -1033,14 +1031,32 @@ static int dsa_slave_setup_tc_block(struct net_device *dev,
}
}
@@ -4003,7 +3012,7 @@
if (!ds->ops->port_setup_tc)
return -EOPNOTSUPP;
-@@ -1224,6 +1242,21 @@ static struct devlink_port *dsa_slave_get_devlink_port(struct net_device *dev)
+@@ -1226,6 +1242,21 @@ static struct devlink_port *dsa_slave_get_devlink_port(struct net_device *dev)
return dp->ds->devlink ? &dp->devlink_port : NULL;
}
@@ -4025,7 +3034,7 @@
static const struct net_device_ops dsa_slave_netdev_ops = {
.ndo_open = dsa_slave_open,
.ndo_stop = dsa_slave_close,
-@@ -1248,6 +1281,7 @@ static const struct net_device_ops dsa_slave_netdev_ops = {
+@@ -1250,6 +1281,7 @@ static const struct net_device_ops dsa_slave_netdev_ops = {
.ndo_vlan_rx_add_vid = dsa_slave_vlan_rx_add_vid,
.ndo_vlan_rx_kill_vid = dsa_slave_vlan_rx_kill_vid,
.ndo_get_devlink_port = dsa_slave_get_devlink_port,
@@ -4033,7 +3042,8 @@
};
static struct device_type dsa_type = {
-@@ -1499,6 +1533,7 @@ bool dsa_slave_dev_check(const struct net_device *dev)
+@@ -1497,7 +1529,8 @@ void dsa_slave_destroy(struct net_device *slave_dev)
+ bool dsa_slave_dev_check(const struct net_device *dev)
{
return dev->netdev_ops == &dsa_slave_netdev_ops;
}
@@ -4042,7 +3052,7 @@
static int dsa_slave_changeupper(struct net_device *dev,
struct netdev_notifier_changeupper_info *info)
diff --git a/net/ipv4/netfilter/Kconfig b/net/ipv4/netfilter/Kconfig
-index f17b402..803b92e 100644
+index f17b40211..803b92e4c 100644
--- a/net/ipv4/netfilter/Kconfig
+++ b/net/ipv4/netfilter/Kconfig
@@ -56,8 +56,6 @@ config NF_TABLES_ARP
@@ -4064,7 +3074,7 @@
tristate "Netfilter IPv4 packet duplication to alternate destination"
depends on !NF_CONNTRACK || NF_CONNTRACK
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
-index 457eb07..330f8e3 100644
+index 5585e3a94..bb76f6061 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -607,7 +607,7 @@ int ip6_forward(struct sk_buff *skb)
@@ -4077,7 +3087,7 @@
mtu = IPV6_MIN_MTU;
diff --git a/net/ipv6/netfilter/Kconfig b/net/ipv6/netfilter/Kconfig
-index 69443e9..0b481d2 100644
+index 69443e9a3..0b481d236 100644
--- a/net/ipv6/netfilter/Kconfig
+++ b/net/ipv6/netfilter/Kconfig
@@ -45,7 +45,6 @@ config NFT_FIB_IPV6
@@ -4098,7 +3108,7 @@
tristate "Netfilter IPv6 packet duplication to alternate destination"
depends on !NF_CONNTRACK || NF_CONNTRACK
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
-index 43d185c..82a752c 100644
+index 98aaf0b79..2b357ac71 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -83,7 +83,7 @@ enum rt6_nud_state {
@@ -4138,10 +3148,10 @@
/* MTU selection:
diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
-index b6e0a62..5d690ab 100644
+index b967763f5..c040e713a 100644
--- a/net/netfilter/Kconfig
+++ b/net/netfilter/Kconfig
-@@ -689,8 +689,6 @@ config NFT_FIB_NETDEV
+@@ -690,8 +690,6 @@ config NFT_FIB_NETDEV
endif # NF_TABLES_NETDEV
@@ -4150,7 +3160,7 @@
config NF_FLOW_TABLE_INET
tristate "Netfilter flow table mixed IPv4/IPv6 module"
depends on NF_FLOW_TABLE
-@@ -699,11 +697,12 @@ config NF_FLOW_TABLE_INET
+@@ -700,11 +698,12 @@ config NF_FLOW_TABLE_INET
To compile it as a module, choose M here.
@@ -4164,7 +3174,7 @@
help
This option adds the flow table core infrastructure.
-@@ -983,6 +982,15 @@ config NETFILTER_XT_TARGET_NOTRACK
+@@ -984,6 +983,15 @@ config NETFILTER_XT_TARGET_NOTRACK
depends on NETFILTER_ADVANCED
select NETFILTER_XT_TARGET_CT
@@ -4181,7 +3191,7 @@
tristate '"RATEEST" target support'
depends on NETFILTER_ADVANCED
diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
-index 4fc075b..d93a121 100644
+index 4fc075b61..d93a121bc 100644
--- a/net/netfilter/Makefile
+++ b/net/netfilter/Makefile
@@ -120,7 +120,8 @@ obj-$(CONFIG_NFT_FWD_NETDEV) += nft_fwd_netdev.o
@@ -4203,10 +3213,10 @@
obj-$(CONFIG_NETFILTER_XT_TARGET_HMARK) += xt_HMARK.o
obj-$(CONFIG_NETFILTER_XT_TARGET_LED) += xt_LED.o
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
-index f6ab6f4..f689e19 100644
+index f6ab6f484..f689e19d8 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
-@@ -864,9 +864,8 @@ nf_conntrack_hash_check_insert(struct nf_conn *ct)
+@@ -864,9 +864,8 @@ out:
}
EXPORT_SYMBOL_GPL(nf_conntrack_hash_check_insert);
@@ -4272,10 +3282,10 @@
return nf_ct_delete(ct, 0, 0);
}
diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c
-index e219b6f..5cdc627 100644
+index 7204f0366..3742bae21 100644
--- a/net/netfilter/nf_conntrack_proto_tcp.c
+++ b/net/netfilter/nf_conntrack_proto_tcp.c
-@@ -1463,6 +1463,10 @@ void nf_conntrack_tcp_init_net(struct net *net)
+@@ -1453,6 +1453,10 @@ void nf_conntrack_tcp_init_net(struct net *net)
tn->tcp_loose = nf_ct_tcp_loose;
tn->tcp_be_liberal = nf_ct_tcp_be_liberal;
tn->tcp_max_retrans = nf_ct_tcp_max_retrans;
@@ -4287,7 +3297,7 @@
const struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp =
diff --git a/net/netfilter/nf_conntrack_proto_udp.c b/net/netfilter/nf_conntrack_proto_udp.c
-index e3a2d01..a1579d6 100644
+index e3a2d018f..a1579d6c3 100644
--- a/net/netfilter/nf_conntrack_proto_udp.c
+++ b/net/netfilter/nf_conntrack_proto_udp.c
@@ -267,6 +267,10 @@ void nf_conntrack_udp_init_net(struct net *net)
@@ -4302,7 +3312,7 @@
const struct nf_conntrack_l4proto nf_conntrack_l4proto_udp =
diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
-index 236954e..be7513a 100644
+index 9c6259c28..10d9f93ce 100644
--- a/net/netfilter/nf_conntrack_standalone.c
+++ b/net/netfilter/nf_conntrack_standalone.c
@@ -353,7 +353,9 @@ static int ct_seq_show(struct seq_file *s, void *v)
@@ -4334,7 +3344,7 @@
NF_SYSCTL_CT_PROTO_TIMEOUT_ICMP,
NF_SYSCTL_CT_PROTO_TIMEOUT_ICMPV6,
#ifdef CONFIG_NF_CT_PROTO_SCTP
-@@ -811,6 +819,14 @@ static struct ctl_table nf_ct_sysctl_table[] = {
+@@ -812,6 +820,14 @@ static struct ctl_table nf_ct_sysctl_table[] = {
.mode = 0644,
.proc_handler = proc_dointvec_jiffies,
},
@@ -4349,7 +3359,7 @@
[NF_SYSCTL_CT_PROTO_TCP_LOOSE] = {
.procname = "nf_conntrack_tcp_loose",
.maxlen = sizeof(int),
-@@ -845,6 +861,14 @@ static struct ctl_table nf_ct_sysctl_table[] = {
+@@ -846,6 +862,14 @@ static struct ctl_table nf_ct_sysctl_table[] = {
.mode = 0644,
.proc_handler = proc_dointvec_jiffies,
},
@@ -4364,7 +3374,7 @@
[NF_SYSCTL_CT_PROTO_TIMEOUT_ICMP] = {
.procname = "nf_conntrack_icmp_timeout",
.maxlen = sizeof(unsigned int),
-@@ -1021,6 +1045,11 @@ static void nf_conntrack_standalone_init_tcp_sysctl(struct net *net,
+@@ -1028,6 +1052,11 @@ static void nf_conntrack_standalone_init_tcp_sysctl(struct net *net,
XASSIGN(LIBERAL, &tn->tcp_be_liberal);
XASSIGN(MAX_RETRANS, &tn->tcp_max_retrans);
#undef XASSIGN
@@ -4376,7 +3386,7 @@
}
static void nf_conntrack_standalone_init_sctp_sysctl(struct net *net,
-@@ -1107,6 +1136,9 @@ static int nf_conntrack_standalone_init_sysctl(struct net *net)
+@@ -1115,6 +1144,9 @@ static int nf_conntrack_standalone_init_sysctl(struct net *net)
table[NF_SYSCTL_CT_PROTO_TIMEOUT_ICMPV6].data = &nf_icmpv6_pernet(net)->timeout;
table[NF_SYSCTL_CT_PROTO_TIMEOUT_UDP].data = &un->timeouts[UDP_CT_UNREPLIED];
table[NF_SYSCTL_CT_PROTO_TIMEOUT_UDP_STREAM].data = &un->timeouts[UDP_CT_REPLIED];
@@ -4387,7 +3397,7 @@
nf_conntrack_standalone_init_tcp_sysctl(net, table);
nf_conntrack_standalone_init_sctp_sysctl(net, table);
diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
-index f212cec..0a701f0 100644
+index f212cec0..10365581 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -7,43 +7,21 @@
@@ -4480,11 +3490,11 @@
-
- if (!dst_hold_safe(route->tuple[FLOW_OFFLOAD_DIR_ORIGINAL].dst))
- goto err_dst_cache_original;
-+ flow->ct = ct;
-
+-
- if (!dst_hold_safe(route->tuple[FLOW_OFFLOAD_DIR_REPLY].dst))
- goto err_dst_cache_reply;
--
++ flow->ct = ct;
+
- entry->ct = ct;
-
- flow_offload_fill_dir(flow, ct, route, FLOW_OFFLOAD_DIR_ORIGINAL);
@@ -4508,7 +3518,7 @@
err_ct_refcnt:
nf_ct_put(ct);
-@@ -115,65 +73,155 @@ flow_offload_alloc(struct nf_conn *ct, struct nf_flow_route *route)
+@@ -115,40 +73,135 @@ flow_offload_alloc(struct nf_conn *ct, struct nf_flow_route *route)
}
EXPORT_SYMBOL_GPL(flow_offload_alloc);
@@ -4537,8 +3547,7 @@
+ struct flow_offload_tuple *flow_tuple = &flow->tuplehash[dir].tuple;
+ struct dst_entry *dst = route->tuple[dir].dst;
+ int i, j = 0;
-
--static inline __s32 nf_flow_timeout_delta(unsigned int timeout)
++
+ switch (flow_tuple->l3proto) {
+ case NFPROTO_IPV4:
+ flow_tuple->mtu = ip_dst_mtu_maybe_forward(dst, true);
@@ -4586,75 +3595,65 @@
+
+static void nft_flow_dst_release(struct flow_offload *flow,
+ enum flow_offload_tuple_dir dir)
- {
-- return (__s32)(timeout - (u32)jiffies);
++{
+ if (flow->tuplehash[dir].tuple.xmit_type == FLOW_OFFLOAD_XMIT_NEIGH ||
+ flow->tuplehash[dir].tuple.xmit_type == FLOW_OFFLOAD_XMIT_XFRM)
+ dst_release(flow->tuplehash[dir].tuple.dst_cache);
- }
-
--static void flow_offload_fixup_ct_timeout(struct nf_conn *ct)
++}
++
+int flow_offload_route_init(struct flow_offload *flow,
+ const struct nf_flow_route *route)
- {
-- const struct nf_conntrack_l4proto *l4proto;
-- int l4num = nf_ct_protonum(ct);
-- unsigned int timeout;
++{
+ int err;
-
-- l4proto = nf_ct_l4proto_find(l4num);
-- if (!l4proto)
-- return;
++
+ err = flow_offload_fill_route(flow, route, FLOW_OFFLOAD_DIR_ORIGINAL);
+ if (err < 0)
+ return err;
-
-- if (l4num == IPPROTO_TCP)
-- timeout = NF_FLOWTABLE_TCP_PICKUP_TIMEOUT;
-- else if (l4num == IPPROTO_UDP)
-- timeout = NF_FLOWTABLE_UDP_PICKUP_TIMEOUT;
-- else
-- return;
++
+ err = flow_offload_fill_route(flow, route, FLOW_OFFLOAD_DIR_REPLY);
+ if (err < 0)
+ goto err_route_reply;
+
+ flow->type = NF_FLOW_OFFLOAD_ROUTE;
-
-- if (nf_flow_timeout_delta(ct->timeout) > (__s32)timeout)
-- ct->timeout = nfct_time_stamp + timeout;
++
+ return 0;
+
+err_route_reply:
+ nft_flow_dst_release(flow, FLOW_OFFLOAD_DIR_ORIGINAL);
+
+ return err;
- }
++}
+EXPORT_SYMBOL_GPL(flow_offload_route_init);
--static void flow_offload_fixup_ct_state(struct nf_conn *ct)
+-static inline __s32 nf_flow_timeout_delta(unsigned int timeout)
+static void flow_offload_fixup_tcp(struct ip_ct_tcp *tcp)
{
-- if (nf_ct_protonum(ct) == IPPROTO_TCP)
-- flow_offload_fixup_tcp(&ct->proto.tcp);
+- return (__s32)(timeout - (u32)jiffies);
++ tcp->state = TCP_CONNTRACK_ESTABLISHED;
+ tcp->seen[0].td_maxwin = 0;
+ tcp->seen[1].td_maxwin = 0;
}
- static void flow_offload_fixup_ct(struct nf_conn *ct)
+ static void flow_offload_fixup_ct_timeout(struct nf_conn *ct)
{
-- flow_offload_fixup_ct_state(ct);
-- flow_offload_fixup_ct_timeout(ct);
+- const struct nf_conntrack_l4proto *l4proto;
+ struct net *net = nf_ct_net(ct);
-+ int l4num = nf_ct_protonum(ct);
+ int l4num = nf_ct_protonum(ct);
+- unsigned int timeout;
+ s32 timeout;
-+
+
+- l4proto = nf_ct_l4proto_find(l4num);
+- if (!l4proto)
+- return;
+ if (l4num == IPPROTO_TCP) {
+ struct nf_tcp_net *tn = nf_tcp_pernet(net);
-+
-+ flow_offload_fixup_tcp(&ct->proto.tcp);
-+
-+ timeout = tn->timeouts[ct->proto.tcp.state];
+
+- if (l4num == IPPROTO_TCP)
+- timeout = NF_FLOWTABLE_TCP_PICKUP_TIMEOUT;
+- else if (l4num == IPPROTO_UDP)
+- timeout = NF_FLOWTABLE_UDP_PICKUP_TIMEOUT;
+- else
++ timeout = tn->timeouts[TCP_CONNTRACK_ESTABLISHED];
+ timeout -= tn->offload_timeout;
+ } else if (l4num == IPPROTO_UDP) {
+ struct nf_udp_net *tn = nf_udp_pernet(net);
@@ -4662,16 +3661,23 @@
+ timeout = tn->timeouts[UDP_CT_REPLIED];
+ timeout -= tn->offload_timeout;
+ } else {
-+ return;
+ return;
+ }
+
+ if (timeout < 0)
+ timeout = 0;
-+
+
+- if (nf_flow_timeout_delta(ct->timeout) > (__s32)timeout)
+- ct->timeout = nfct_time_stamp + timeout;
+ if (nf_flow_timeout_delta(READ_ONCE(ct->timeout)) > (__s32)timeout)
+ WRITE_ONCE(ct->timeout, nfct_time_stamp + timeout);
}
+ static void flow_offload_fixup_ct_state(struct nf_conn *ct)
+@@ -163,17 +216,23 @@ static void flow_offload_fixup_ct(struct nf_conn *ct)
+ flow_offload_fixup_ct_timeout(ct);
+ }
+
-void flow_offload_free(struct flow_offload *flow)
+static void flow_offload_route_release(struct flow_offload *flow)
{
@@ -4701,7 +3707,7 @@
}
EXPORT_SYMBOL_GPL(flow_offload_free);
-@@ -181,14 +229,14 @@ static u32 flow_offload_hash(const void *data, u32 len, u32 seed)
+@@ -181,14 +240,14 @@ static u32 flow_offload_hash(const void *data, u32 len, u32 seed)
{
const struct flow_offload_tuple *tuple = data;
@@ -4718,7 +3724,7 @@
}
static int flow_offload_hash_cmp(struct rhashtable_compare_arg *arg,
-@@ -197,7 +245,7 @@ static int flow_offload_hash_cmp(struct rhashtable_compare_arg *arg,
+@@ -197,7 +256,7 @@ static int flow_offload_hash_cmp(struct rhashtable_compare_arg *arg,
const struct flow_offload_tuple *tuple = arg->key;
const struct flow_offload_tuple_rhash *x = ptr;
@@ -4727,7 +3733,7 @@
return 1;
return 0;
-@@ -211,30 +259,30 @@ static const struct rhashtable_params nf_flow_offload_rhash_params = {
+@@ -211,30 +270,30 @@ static const struct rhashtable_params nf_flow_offload_rhash_params = {
.automatic_shrinking = true,
};
@@ -4745,21 +3751,21 @@
+ unsigned long timeout = NF_FLOW_TIMEOUT;
+ struct net *net = nf_ct_net(flow->ct);
+ int l4num = nf_ct_protonum(flow->ct);
-+
+
+- entry = container_of(flow, struct flow_offload_entry, flow);
+- ct = entry->ct;
+ if (l4num == IPPROTO_TCP) {
+ struct nf_tcp_net *tn = nf_tcp_pernet(net);
-+
+
+- if (nf_ct_expires(ct) < DAY / 2)
+- ct->timeout = nfct_time_stamp + DAY;
+ timeout = tn->offload_timeout;
+ } else if (l4num == IPPROTO_UDP) {
+ struct nf_udp_net *tn = nf_udp_pernet(net);
-
-- entry = container_of(flow, struct flow_offload_entry, flow);
-- ct = entry->ct;
++
+ timeout = tn->offload_timeout;
+ }
-
-- if (nf_ct_expires(ct) < DAY / 2)
-- ct->timeout = nfct_time_stamp + DAY;
++
+ return timeout;
}
@@ -4773,7 +3779,7 @@
err = rhashtable_insert_fast(&flow_table->rhashtable,
&flow->tuplehash[0].node,
-@@ -252,10 +300,35 @@ int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow)
+@@ -252,10 +311,35 @@ int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow)
return err;
}
@@ -4809,7 +3815,7 @@
static inline bool nf_flow_has_expired(const struct flow_offload *flow)
{
return nf_flow_timeout_delta(flow->timeout) <= 0;
-@@ -264,37 +337,20 @@ static inline bool nf_flow_has_expired(const struct flow_offload *flow)
+@@ -264,8 +348,6 @@ static inline bool nf_flow_has_expired(const struct flow_offload *flow)
static void flow_offload_del(struct nf_flowtable *flow_table,
struct flow_offload *flow)
{
@@ -4818,21 +3824,25 @@
rhashtable_remove_fast(&flow_table->rhashtable,
&flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].node,
nf_flow_offload_rhash_params);
- rhashtable_remove_fast(&flow_table->rhashtable,
+@@ -273,28 +355,21 @@ static void flow_offload_del(struct nf_flowtable *flow_table,
&flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].node,
nf_flow_offload_rhash_params);
--
+
- e = container_of(flow, struct flow_offload_entry, flow);
- clear_bit(IPS_OFFLOAD_BIT, &e->ct->status);
--
-- if (nf_flow_has_expired(flow))
++ clear_bit(IPS_OFFLOAD_BIT, &flow->ct->status);
+
+ if (nf_flow_has_expired(flow))
- flow_offload_fixup_ct(e->ct);
- else if (flow->flags & FLOW_OFFLOAD_TEARDOWN)
- flow_offload_fixup_ct_timeout(e->ct);
-
- if (!(flow->flags & FLOW_OFFLOAD_TEARDOWN))
- flow_offload_fixup_ct_state(e->ct);
--
++ flow_offload_fixup_ct(flow->ct);
++ else
++ flow_offload_fixup_ct_timeout(flow->ct);
+
flow_offload_free(flow);
}
@@ -4841,16 +3851,15 @@
- struct flow_offload_entry *e;
-
- flow->flags |= FLOW_OFFLOAD_TEARDOWN;
--
++ set_bit(NF_FLOW_TEARDOWN, &flow->flags);
+
- e = container_of(flow, struct flow_offload_entry, flow);
- flow_offload_fixup_ct_state(e->ct);
-+ clear_bit(IPS_OFFLOAD_BIT, &flow->ct->status);
-+ set_bit(NF_FLOW_TEARDOWN, &flow->flags);
-+ flow_offload_fixup_ct(flow->ct);
++ flow_offload_fixup_ct_state(flow->ct);
}
EXPORT_SYMBOL_GPL(flow_offload_teardown);
-@@ -304,7 +360,6 @@ flow_offload_lookup(struct nf_flowtable *flow_table,
+@@ -304,7 +379,6 @@ flow_offload_lookup(struct nf_flowtable *flow_table,
{
struct flow_offload_tuple_rhash *tuplehash;
struct flow_offload *flow;
@@ -4858,7 +3867,7 @@
int dir;
tuplehash = rhashtable_lookup(&flow_table->rhashtable, tuple,
-@@ -314,19 +369,17 @@ flow_offload_lookup(struct nf_flowtable *flow_table,
+@@ -314,19 +388,17 @@ flow_offload_lookup(struct nf_flowtable *flow_table,
dir = tuplehash->tuple.dir;
flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]);
@@ -4881,7 +3890,7 @@
void (*iter)(struct flow_offload *flow, void *data),
void *data)
{
-@@ -339,7 +392,6 @@ nf_flow_table_iterate(struct nf_flowtable *flow_table,
+@@ -339,7 +411,6 @@ nf_flow_table_iterate(struct nf_flowtable *flow_table,
rhashtable_walk_start(&hti);
while ((tuplehash = rhashtable_walk_next(&hti))) {
@@ -4889,33 +3898,57 @@
if (IS_ERR(tuplehash)) {
if (PTR_ERR(tuplehash) != -EAGAIN) {
err = PTR_ERR(tuplehash);
-@@ -359,23 +411,28 @@ nf_flow_table_iterate(struct nf_flowtable *flow_table,
+@@ -359,23 +430,52 @@ nf_flow_table_iterate(struct nf_flowtable *flow_table,
return err;
}
+EXPORT_SYMBOL_GPL(nf_flow_table_iterate);
- static void nf_flow_offload_gc_step(struct flow_offload *flow, void *data)
+-static void nf_flow_offload_gc_step(struct flow_offload *flow, void *data)
++static bool flow_offload_stale_dst(struct flow_offload_tuple *tuple)
{
- struct nf_flowtable *flow_table = data;
+- struct nf_flowtable *flow_table = data;
- struct flow_offload_entry *e;
- bool teardown;
++ struct dst_entry *dst;
- e = container_of(flow, struct flow_offload_entry, flow);
--
++ if (tuple->xmit_type == FLOW_OFFLOAD_XMIT_NEIGH ||
++ tuple->xmit_type == FLOW_OFFLOAD_XMIT_XFRM) {
++ dst = tuple->dst_cache;
++ if (!dst_check(dst, tuple->dst_cookie))
++ return true;
++ }
+
- teardown = flow->flags & (FLOW_OFFLOAD_DYING |
- FLOW_OFFLOAD_TEARDOWN);
--
++ return false;
++}
+
- if (!teardown)
- nf_ct_offload_timeout(flow);
-+ if (nf_flow_has_expired(flow) ||
-+ nf_ct_is_dying(flow->ct))
-+ flow_offload_teardown(flow);
++static bool nf_flow_has_stale_dst(struct flow_offload *flow)
++{
++ return flow_offload_stale_dst(&flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple) ||
++ flow_offload_stale_dst(&flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].tuple);
++}
- if (nf_flow_has_expired(flow) || teardown)
- flow_offload_del(flow_table, flow);
++static void nf_flow_offload_gc_step(struct flow_offload *flow, void *data)
++{
++ struct nf_flowtable *flow_table = data;
++
++ if (nf_flow_has_expired(flow) ||
++ nf_ct_is_dying(flow->ct) ||
++ nf_flow_has_stale_dst(flow))
++ set_bit(NF_FLOW_TEARDOWN, &flow->flags);
++
+ if (test_bit(NF_FLOW_TEARDOWN, &flow->flags)) {
+ if (test_bit(NF_FLOW_HW, &flow->flags)) {
++ if (!test_and_set_bit(NF_FLOW_HW_ACCT_DYING, &flow->flags))
++ nf_flow_offload_stats(flow_table, flow, true);
++
+ if (!test_bit(NF_FLOW_HW_DYING, &flow->flags))
+ nf_flow_offload_del(flow_table, flow);
+ else if (test_bit(NF_FLOW_HW_DEAD, &flow->flags))
@@ -4924,12 +3957,12 @@
+ flow_offload_del(flow_table, flow);
+ }
+ } else if (test_bit(NF_FLOW_HW, &flow->flags)) {
-+ nf_flow_offload_stats(flow_table, flow);
++ nf_flow_offload_stats(flow_table, flow, false);
+ }
}
static void nf_flow_offload_work_gc(struct work_struct *work)
-@@ -387,30 +444,20 @@ static void nf_flow_offload_work_gc(struct work_struct *work)
+@@ -387,30 +484,20 @@ static void nf_flow_offload_work_gc(struct work_struct *work)
queue_delayed_work(system_power_efficient_wq, &flow_table->gc_work, HZ);
}
@@ -4964,7 +3997,7 @@
udph = (void *)(skb_network_header(skb) + thoff);
if (udph->check || skb->ip_summed == CHECKSUM_PARTIAL) {
inet_proto_csum_replace2(&udph->check, skb, port,
-@@ -418,38 +465,28 @@ static int nf_flow_nat_port_udp(struct sk_buff *skb, unsigned int thoff,
+@@ -418,38 +505,28 @@ static int nf_flow_nat_port_udp(struct sk_buff *skb, unsigned int thoff,
if (!udph->check)
udph->check = CSUM_MANGLED_0;
}
@@ -5010,7 +4043,7 @@
hdr = (void *)(skb_network_header(skb) + thoff);
switch (dir) {
-@@ -463,25 +500,19 @@ int nf_flow_snat_port(const struct flow_offload *flow,
+@@ -463,25 +540,19 @@ int nf_flow_snat_port(const struct flow_offload *flow,
new_port = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.src_port;
hdr->dest = new_port;
break;
@@ -5040,7 +4073,7 @@
hdr = (void *)(skb_network_header(skb) + thoff);
switch (dir) {
-@@ -495,11 +526,9 @@ int nf_flow_dnat_port(const struct flow_offload *flow,
+@@ -495,11 +566,9 @@ int nf_flow_dnat_port(const struct flow_offload *flow,
new_port = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.dst_port;
hdr->source = new_port;
break;
@@ -5053,7 +4086,7 @@
}
EXPORT_SYMBOL_GPL(nf_flow_dnat_port);
-@@ -507,7 +536,9 @@ int nf_flow_table_init(struct nf_flowtable *flowtable)
+@@ -507,7 +576,9 @@ int nf_flow_table_init(struct nf_flowtable *flowtable)
{
int err;
@@ -5064,7 +4097,7 @@
err = rhashtable_init(&flowtable->rhashtable,
&nf_flow_offload_rhash_params);
-@@ -528,25 +559,24 @@ EXPORT_SYMBOL_GPL(nf_flow_table_init);
+@@ -528,25 +599,24 @@ EXPORT_SYMBOL_GPL(nf_flow_table_init);
static void nf_flow_table_do_cleanup(struct flow_offload *flow, void *data)
{
struct net_device *dev = data;
@@ -5096,7 +4129,7 @@
}
void nf_flow_table_cleanup(struct net_device *dev)
-@@ -555,7 +585,7 @@ void nf_flow_table_cleanup(struct net_device *dev)
+@@ -555,7 +625,7 @@ void nf_flow_table_cleanup(struct net_device *dev)
mutex_lock(&flowtable_lock);
list_for_each_entry(flowtable, &flowtables, list)
@@ -5105,7 +4138,7 @@
mutex_unlock(&flowtable_lock);
}
EXPORT_SYMBOL_GPL(nf_flow_table_cleanup);
-@@ -565,9 +595,14 @@ void nf_flow_table_free(struct nf_flowtable *flow_table)
+@@ -565,9 +635,14 @@ void nf_flow_table_free(struct nf_flowtable *flow_table)
mutex_lock(&flowtable_lock);
list_del(&flow_table->list);
mutex_unlock(&flowtable_lock);
@@ -5120,7 +4153,7 @@
rhashtable_destroy(&flow_table->rhashtable);
}
EXPORT_SYMBOL_GPL(nf_flow_table_free);
-@@ -591,12 +626,23 @@ static struct notifier_block flow_offload_netdev_notifier = {
+@@ -591,12 +666,23 @@ static struct notifier_block flow_offload_netdev_notifier = {
static int __init nf_flow_table_module_init(void)
{
@@ -5145,13 +4178,13 @@
}
module_init(nf_flow_table_module_init);
-@@ -604,3 +650,4 @@ module_exit(nf_flow_table_module_exit);
+@@ -604,3 +690,4 @@ module_exit(nf_flow_table_module_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
+MODULE_DESCRIPTION("Netfilter flow table module");
diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c
-index 397129b..2802646 100644
+index 397129b2..6257d87c 100644
--- a/net/netfilter/nf_flow_table_ip.c
+++ b/net/netfilter/nf_flow_table_ip.c
@@ -7,11 +7,13 @@
@@ -5405,23 +4438,7 @@
return 0;
}
-@@ -215,6 +227,15 @@ static bool nf_flow_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)
- return true;
- }
-
-+static inline bool nf_flow_dst_check(struct flow_offload_tuple *tuple)
-+{
-+ if (tuple->xmit_type != FLOW_OFFLOAD_XMIT_NEIGH &&
-+ tuple->xmit_type != FLOW_OFFLOAD_XMIT_XFRM)
-+ return true;
-+
-+ return dst_check(tuple->dst_cache, tuple->dst_cookie);
-+}
-+
- static unsigned int nf_flow_xmit_xfrm(struct sk_buff *skb,
- const struct nf_hook_state *state,
- struct dst_entry *dst)
-@@ -225,6 +246,75 @@ static unsigned int nf_flow_xmit_xfrm(struct sk_buff *skb,
+@@ -225,6 +237,75 @@ static unsigned int nf_flow_xmit_xfrm(struct sk_buff *skb,
return NF_STOLEN;
}
@@ -5497,7 +4514,7 @@
unsigned int
nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state)
-@@ -235,15 +325,18 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
+@@ -235,15 +316,18 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
enum flow_offload_tuple_dir dir;
struct flow_offload *flow;
struct net_device *outdev;
@@ -5519,33 +4536,32 @@
return NF_ACCEPT;
tuplehash = flow_offload_lookup(flow_table, &tuple);
-@@ -252,75 +345,85 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
+@@ -252,75 +336,80 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
dir = tuplehash->tuple.dir;
flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]);
- rt = (struct rtable *)flow->tuplehash[dir].tuple.dst_cache;
- outdev = rt->dst.dev;
-
+-
- if (unlikely(nf_flow_exceeds_mtu(skb, flow->tuplehash[dir].tuple.mtu)))
-+ mtu = flow->tuplehash[dir].tuple.mtu + offset;
-+ if (unlikely(nf_flow_exceeds_mtu(skb, mtu)))
- return NF_ACCEPT;
+- return NF_ACCEPT;
- if (skb_try_make_writable(skb, sizeof(*iph)))
- return NF_DROP;
-
- thoff = ip_hdr(skb)->ihl * 4;
- if (nf_flow_state_check(flow, ip_hdr(skb)->protocol, skb, thoff))
-+ iph = (struct iphdr *)(skb_network_header(skb) + offset);
-+ thoff = (iph->ihl * 4) + offset;
-+ if (nf_flow_state_check(flow, iph->protocol, skb, thoff))
++ mtu = flow->tuplehash[dir].tuple.mtu + offset;
++ if (unlikely(nf_flow_exceeds_mtu(skb, mtu)))
return NF_ACCEPT;
- if (!dst_check(&rt->dst, 0)) {
-+ if (!nf_flow_dst_check(&tuplehash->tuple)) {
- flow_offload_teardown(flow);
+- flow_offload_teardown(flow);
++ iph = (struct iphdr *)(skb_network_header(skb) + offset);
++ thoff = (iph->ihl * 4) + offset;
++ if (nf_flow_state_check(flow, iph->protocol, skb, thoff))
return NF_ACCEPT;
- }
+- }
- if (nf_flow_nat_ip(flow, skb, thoff, dir) < 0)
+ if (skb_try_make_writable(skb, thoff + hdrsize))
@@ -5638,7 +4654,7 @@
udph = (void *)(skb_network_header(skb) + thoff);
if (udph->check || skb->ip_summed == CHECKSUM_PARTIAL) {
inet_proto_csum_replace16(&udph->check, skb, addr->s6_addr32,
-@@ -328,32 +431,26 @@ static int nf_flow_nat_ipv6_udp(struct sk_buff *skb, unsigned int thoff,
+@@ -328,32 +417,26 @@ static int nf_flow_nat_ipv6_udp(struct sk_buff *skb, unsigned int thoff,
if (!udph->check)
udph->check = CSUM_MANGLED_0;
}
@@ -5680,7 +4696,7 @@
{
struct in6_addr addr, new_addr;
-@@ -368,17 +465,15 @@ static int nf_flow_snat_ipv6(const struct flow_offload *flow,
+@@ -368,17 +451,15 @@ static int nf_flow_snat_ipv6(const struct flow_offload *flow,
new_addr = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.src_v6;
ip6h->daddr = new_addr;
break;
@@ -5703,7 +4719,7 @@
{
struct in6_addr addr, new_addr;
-@@ -393,56 +488,60 @@ static int nf_flow_dnat_ipv6(const struct flow_offload *flow,
+@@ -393,56 +474,60 @@ static int nf_flow_dnat_ipv6(const struct flow_offload *flow,
new_addr = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.dst_v6;
ip6h->saddr = new_addr;
break;
@@ -5789,7 +4805,7 @@
ports = (struct flow_ports *)(skb_network_header(skb) + thoff);
tuple->src_v6 = ip6h->saddr;
-@@ -452,6 +551,7 @@ static int nf_flow_tuple_ipv6(struct sk_buff *skb, const struct net_device *dev,
+@@ -452,6 +537,7 @@ static int nf_flow_tuple_ipv6(struct sk_buff *skb, const struct net_device *dev,
tuple->l3proto = AF_INET6;
tuple->l4proto = ip6h->nexthdr;
tuple->iifidx = dev->ifindex;
@@ -5797,7 +4813,7 @@
return 0;
}
-@@ -467,13 +567,17 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
+@@ -467,13 +553,17 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
const struct in6_addr *nexthop;
struct flow_offload *flow;
struct net_device *outdev;
@@ -5817,7 +4833,7 @@
return NF_ACCEPT;
tuplehash = flow_offload_lookup(flow_table, &tuple);
-@@ -482,44 +586,62 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
+@@ -482,44 +572,57 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
dir = tuplehash->tuple.dir;
flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]);
@@ -5837,11 +4853,10 @@
return NF_ACCEPT;
- if (!dst_check(&rt->dst, tuplehash->tuple.dst_cookie)) {
-+ if (!nf_flow_dst_check(&tuplehash->tuple)) {
- flow_offload_teardown(flow);
- return NF_ACCEPT;
- }
-
+- flow_offload_teardown(flow);
+- return NF_ACCEPT;
+- }
+-
- if (skb_try_make_writable(skb, sizeof(*ip6h)))
+ if (skb_try_make_writable(skb, thoff + hdrsize))
return NF_DROP;
@@ -5898,10 +4913,10 @@
EXPORT_SYMBOL_GPL(nf_flow_offload_ipv6_hook);
diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
new file mode 100644
-index 0000000..197f48a
+index 000000000..d94c6fb92
--- /dev/null
+++ b/net/netfilter/nf_flow_table_offload.c
-@@ -0,0 +1,1194 @@
+@@ -0,0 +1,1199 @@
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
@@ -6155,7 +5170,8 @@
+ flow_offload_mangle(entry1, FLOW_ACT_MANGLE_HDR_TYPE_ETH, 8,
+ &val, &mask);
+
-+ dev_put(dev);
++ if (dev)
++ dev_put(dev);
+
+ return 0;
+}
@@ -6276,12 +5292,12 @@
+ const __be32 *addr, const __be32 *mask)
+{
+ struct flow_action_entry *entry;
-+ int i;
++ int i, j;
+
-+ for (i = 0; i < sizeof(struct in6_addr) / sizeof(u32); i++) {
++ for (i = 0, j = 0; i < sizeof(struct in6_addr) / sizeof(u32); i += sizeof(u32), j++) {
+ entry = flow_action_entry_next(flow_rule);
+ flow_offload_mangle(entry, FLOW_ACT_MANGLE_HDR_TYPE_IP6,
-+ offset + i * sizeof(u32), &addr[i], mask);
++ offset + i, &addr[j], mask);
+ }
+}
+
@@ -6938,14 +5954,16 @@
+}
+
+void nf_flow_offload_stats(struct nf_flowtable *flowtable,
-+ struct flow_offload *flow)
++ struct flow_offload *flow, bool force)
+{
+ struct flow_offload_work *offload;
+ __s32 delta;
+
-+ delta = nf_flow_timeout_delta(flow->timeout);
-+ if ((delta >= (9 * flow_offload_get_timeout(flow)) / 10))
-+ return;
++ if (!force) {
++ delta = nf_flow_timeout_delta(flow->timeout);
++ if ((delta >= (9 * flow_offload_get_timeout(flow)) / 10))
++ return;
++ }
+
+ offload = nf_flow_offload_work_alloc(flowtable, flow, FLOW_CLS_STATS);
+ if (!offload)
@@ -6971,6 +5989,7 @@
+ int err = 0;
+
+ down_write(&flowtable->flow_block_lock);
++
+ switch (cmd) {
+ case FLOW_BLOCK_BIND:
+ list_splice(&bo->cb_list, &flowtable->flow_block.cb_list);
@@ -6985,6 +6004,7 @@
+ WARN_ON_ONCE(1);
+ err = -EOPNOTSUPP;
+ }
++
+ up_write(&flowtable->flow_block_lock);
+
+ return err;
@@ -7098,10 +6118,10 @@
+}
diff --git a/net/netfilter/xt_FLOWOFFLOAD.c b/net/netfilter/xt_FLOWOFFLOAD.c
new file mode 100644
-index 0000000..3437d6a
+index 0000000..12f067c
--- /dev/null
+++ b/net/netfilter/xt_FLOWOFFLOAD.c
-@@ -0,0 +1,795 @@
+@@ -0,0 +1,794 @@
+/*
+ * Copyright (C) 2018-2021 Felix Fietkau <nbd@nbd.name>
+ *
@@ -7852,7 +6872,6 @@
+{
+ INIT_DELAYED_WORK(&tbl->work, xt_flowoffload_hook_work);
+ tbl->ft.type = &flowtable_inet;
-+ tbl->ft.flags = NF_FLOWTABLE_COUNTER;
+
+ return nf_flow_table_init(&tbl->ft);
+}
@@ -7871,7 +6890,7 @@
+ if (ret)
+ goto cleanup;
+
-+ flowtable[1].ft.flags |= NF_FLOWTABLE_HW_OFFLOAD;
++ flowtable[1].ft.flags = NF_FLOWTABLE_HW_OFFLOAD;
+
+ ret = xt_register_target(&offload_tg_reg);
+ if (ret)
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3005-dts-mt7986-wed-changes.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3004-dts-mt7986-wed-changes.patch
similarity index 93%
rename from autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3005-dts-mt7986-wed-changes.patch
rename to autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3004-dts-mt7986-wed-changes.patch
index 4093be9..3b965ac 100755
--- a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3005-dts-mt7986-wed-changes.patch
+++ b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3004-dts-mt7986-wed-changes.patch
@@ -1,7 +1,7 @@
-From 9a3d5a75f4319e26342db10502e8b3055366ee05 Mon Sep 17 00:00:00 2001
+From b83743c16da6fa4da206df3e5a1a9c29485bb613 Mon Sep 17 00:00:00 2001
From: Bo Jiao <Bo.Jiao@mediatek.com>
-Date: Tue, 13 Jun 2023 16:58:53 +0800
-Subject: [PATCH] 999-3005-dts-mt7986-wed-changes
+Date: Wed, 22 Jun 2022 16:36:42 +0800
+Subject: [PATCH 3/8] 9992-dts-mt7986-wed-changes
---
arch/arm64/boot/dts/mediatek/mt7986a.dtsi | 33 ++++++++---------------
@@ -9,7 +9,7 @@
2 files changed, 22 insertions(+), 44 deletions(-)
diff --git a/arch/arm64/boot/dts/mediatek/mt7986a.dtsi b/arch/arm64/boot/dts/mediatek/mt7986a.dtsi
-index 81851a0..36de771 100644
+index ba27b95f5..7f78de6b9 100644
--- a/arch/arm64/boot/dts/mediatek/mt7986a.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt7986a.dtsi
@@ -58,32 +58,20 @@
@@ -55,7 +55,7 @@
};
ap2woccif: ap2woccif@151A5000 {
-@@ -507,6 +495,7 @@
+@@ -490,6 +478,7 @@
<&topckgen CK_TOP_CB_SGM_325M>;
mediatek,ethsys = <ðsys>;
mediatek,sgmiisys = <&sgmiisys0>, <&sgmiisys1>;
@@ -64,7 +64,7 @@
#address-cells = <1>;
#size-cells = <0>;
diff --git a/arch/arm64/boot/dts/mediatek/mt7986b.dtsi b/arch/arm64/boot/dts/mediatek/mt7986b.dtsi
-index 6fcfa57..7190874 100644
+index 523d585cb..0e5f116a2 100644
--- a/arch/arm64/boot/dts/mediatek/mt7986b.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt7986b.dtsi
@@ -58,32 +58,20 @@
@@ -110,7 +110,7 @@
};
ap2woccif: ap2woccif@151A5000 {
-@@ -409,6 +397,7 @@
+@@ -405,6 +393,7 @@
<&topckgen CK_TOP_CB_SGM_325M>;
mediatek,ethsys = <ðsys>;
mediatek,sgmiisys = <&sgmiisys0>, <&sgmiisys1>;
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3004-mt7986-internal-changes.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3004-mt7986-internal-changes.patch
deleted file mode 100644
index b9b8295..0000000
--- a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3004-mt7986-internal-changes.patch
+++ /dev/null
@@ -1,216 +0,0 @@
-From 1282ae34823d550e4faefe3500a1957d33790321 Mon Sep 17 00:00:00 2001
-From: Bo-Cun Chen <bc-bocun.chen@mediatek.com>
-Date: Tue, 13 Jun 2023 16:57:41 +0800
-Subject: [PATCH 02/17] 999-3004-mt7986-internal-changes
-
----
- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 2 ++
- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 1 +
- drivers/net/ethernet/mediatek/mtk_ppe.c | 3 +-
- drivers/net/ethernet/mediatek/mtk_ppe.h | 2 +-
- .../net/ethernet/mediatek/mtk_ppe_debugfs.c | 34 +++++++++++++------
- .../net/ethernet/mediatek/mtk_ppe_offload.c | 24 ++++++++++++-
- 6 files changed, 52 insertions(+), 14 deletions(-)
-
-diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-index 527e269..0ffb90d 100755
---- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -4872,6 +4872,8 @@ static int mtk_probe(struct platform_device *pdev)
- err = mtk_eth_offload_init(eth);
- if (err)
- goto err_free_dev;
-+
-+ mtk_ppe_debugfs_init(eth);
- }
-
- 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 54790df..ec22dc5 100755
---- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-@@ -1973,5 +1973,6 @@ int mtk_eth_offload_init(struct mtk_eth *eth);
- int mtk_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,
- void *type_data);
- void mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev);
-+int mtk_ppe_debugfs_init(struct mtk_eth *eth);
- int mtk_rss_set_indr_tbl(struct mtk_eth *eth, int num);
- #endif /* MTK_ETH_H */
-diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
-index de34366..b876411 100644
---- a/drivers/net/ethernet/mediatek/mtk_ppe.c
-+++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
-@@ -897,6 +897,7 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int index)
- ppe->eth = eth;
- ppe->dev = dev;
- ppe->version = eth->soc->offload_version;
-+ ppe->id = index;
- ppe->accounting = accounting;
-
- foe = dmam_alloc_coherent(ppe->dev,
-@@ -930,8 +931,6 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int index)
- ppe->acct_table = acct;
- }
-
-- mtk_ppe_debugfs_init(ppe, index);
--
- return ppe;
- }
-
-diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
-index 1fdfb93..fd7ece7 100644
---- a/drivers/net/ethernet/mediatek/mtk_ppe.h
-+++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
-@@ -307,6 +307,7 @@ struct mtk_ppe {
- struct device *dev;
- void __iomem *base;
- int version;
-+ int id;
- char dirname[5];
- bool accounting;
-
-@@ -377,7 +378,6 @@ int mtk_foe_entry_set_queue(struct mtk_eth *eth, struct mtk_foe_entry *entry,
- unsigned int queue);
- 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_ppe_debugfs_init(struct mtk_ppe *ppe, int index);
- void mtk_foe_entry_get_stats(struct mtk_ppe *ppe, struct mtk_flow_entry *entry,
- int *idle);
-
-diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c b/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
-index 322b8f4..747062a 100644
---- a/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
-+++ b/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
-@@ -73,11 +73,13 @@ mtk_print_addr_info(struct seq_file *m, struct mtk_flow_addr_info *ai)
- }
-
- static int
--mtk_ppe_debugfs_foe_show(struct seq_file *m, void *private, bool bind)
-+mtk_ppe_debugfs_foe_show(struct seq_file *m, struct mtk_ppe *ppe, bool bind)
- {
-- struct mtk_ppe *ppe = m->private;
- int i;
-
-+ if (!ppe)
-+ return -ENOENT;
-+
- for (i = 0; i < MTK_PPE_ENTRIES; i++) {
- struct mtk_foe_entry *entry = mtk_foe_get_entry(ppe, i);
- struct mtk_foe_mac_info *l2;
-@@ -125,6 +127,8 @@ mtk_ppe_debugfs_foe_show(struct seq_file *m, void *private, bool bind)
- break;
- }
-
-+ seq_printf(m, " ppe=%d", ppe->id);
-+
- seq_printf(m, " orig=");
- mtk_print_addr_info(m, &ai);
-
-@@ -169,13 +173,25 @@ mtk_ppe_debugfs_foe_show(struct seq_file *m, void *private, bool bind)
- static int
- mtk_ppe_debugfs_foe_show_all(struct seq_file *m, void *private)
- {
-- return mtk_ppe_debugfs_foe_show(m, private, false);
-+ struct mtk_eth *eth = m->private;
-+ int i;
-+
-+ for (i = 0; i < ARRAY_SIZE(eth->ppe); i++)
-+ mtk_ppe_debugfs_foe_show(m, eth->ppe[i], false);
-+
-+ return 0;
- }
-
- static int
- mtk_ppe_debugfs_foe_show_bind(struct seq_file *m, void *private)
- {
-- return mtk_ppe_debugfs_foe_show(m, private, true);
-+ struct mtk_eth *eth = m->private;
-+ int i;
-+
-+ for (i = 0; i < ARRAY_SIZE(eth->ppe); i++)
-+ mtk_ppe_debugfs_foe_show(m, eth->ppe[i], true);
-+
-+ return 0;
- }
-
- static int
-@@ -192,7 +208,7 @@ mtk_ppe_debugfs_foe_open_bind(struct inode *inode, struct file *file)
- inode->i_private);
- }
-
--int mtk_ppe_debugfs_init(struct mtk_ppe *ppe, int index)
-+int mtk_ppe_debugfs_init(struct mtk_eth *eth)
- {
- static const struct file_operations fops_all = {
- .open = mtk_ppe_debugfs_foe_open_all,
-@@ -208,14 +224,12 @@ int mtk_ppe_debugfs_init(struct mtk_ppe *ppe, int index)
- };
- struct dentry *root;
-
-- snprintf(ppe->dirname, sizeof(ppe->dirname), "ppe%d", index);
--
-- root = debugfs_create_dir(ppe->dirname, NULL);
-+ root = debugfs_create_dir("mtk_ppe", NULL);
- if (!root)
- return -ENOMEM;
-
-- debugfs_create_file("entries", S_IRUGO, root, ppe, &fops_all);
-- debugfs_create_file("bind", S_IRUGO, root, ppe, &fops_bind);
-+ debugfs_create_file("entries", S_IRUGO, root, eth, &fops_all);
-+ debugfs_create_file("bind", S_IRUGO, root, eth, &fops_bind);
-
- return 0;
- }
-diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
-index afe3780..30d2b02 100644
---- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
-+++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
-@@ -189,8 +189,10 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f,
- struct flow_action_entry *act;
- struct mtk_flow_data data = {};
- struct mtk_foe_entry foe;
-- struct net_device *odev = NULL;
-+ struct net_device *idev = NULL, *odev = NULL;
- struct mtk_flow_entry *entry;
-+ struct net_device_path_ctx ctx = {};
-+ struct net_device_path path = {};
- int offload_type = 0;
- int wed_index = -1;
- u16 addr_type = 0;
-@@ -205,6 +207,10 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f,
- struct flow_match_meta match;
-
- flow_rule_match_meta(rule, &match);
-+ idev = __dev_get_by_index(&init_net, match.key->ingress_ifindex);
-+
-+ if (!idev)
-+ pr_info("[%s] idev does not exist !\n", __func__);
- } else {
- return -EOPNOTSUPP;
- }
-@@ -394,6 +400,22 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f,
- if (!entry)
- return -ENOMEM;
-
-+ if (idev && idev->netdev_ops->ndo_fill_receive_path) {
-+ u32 num_ppe;
-+
-+ ctx.dev = idev;
-+ idev->netdev_ops->ndo_fill_receive_path(&ctx, &path);
-+ num_ppe = MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ? 2 : 1;
-+ num_ppe = min_t(u32, ARRAY_SIZE(eth->ppe), num_ppe);
-+ ppe_index = path.mtk_wdma.wdma_idx;
-+ if (ppe_index >= num_ppe) {
-+ if (printk_ratelimit())
-+ pr_info("[%s] PPE%d does not exist !\n", __func__, ppe_index);
-+
-+ return -EINVAL;
-+ }
-+ }
-+
- entry->cookie = f->cookie;
- memcpy(&entry->data, &foe, sizeof(entry->data));
- entry->ppe_index = ppe_index;
---
-2.18.0
-
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3006-add-wed.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3005-add-wed.patch
similarity index 63%
rename from autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3006-add-wed.patch
rename to autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3005-add-wed.patch
index dec793e..201a629 100755
--- a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3006-add-wed.patch
+++ b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3005-add-wed.patch
@@ -1,27 +1,33 @@
-From 7ae51d239ccbc103cbde499d40868f97df071d68 Mon Sep 17 00:00:00 2001
+From 342fdc50b761309e75974554cdcf790a2d09e134 Mon Sep 17 00:00:00 2001
From: Sujuan Chen <sujuan.chen@mediatek.com>
-Date: Tue, 13 Jun 2023 17:00:34 +0800
-Subject: [PATCH] 999-3006-add-wed
+Date: Thu, 2 Jun 2022 15:32:07 +0800
+Subject: [PATCH 4/8] 9993-add-wed
+Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com>
---
arch/arm64/boot/dts/mediatek/mt7622.dtsi | 32 +-
drivers/net/ethernet/mediatek/Kconfig | 4 +
drivers/net/ethernet/mediatek/Makefile | 5 +
- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 18 +
- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 3 +
- .../net/ethernet/mediatek/mtk_ppe_offload.c | 60 ++
+ drivers/net/ethernet/mediatek/mtk_eth_soc.c | 136 ++-
+ drivers/net/ethernet/mediatek/mtk_eth_soc.h | 14 +-
+ drivers/net/ethernet/mediatek/mtk_ppe.c | 373 +++++++-
+ drivers/net/ethernet/mediatek/mtk_ppe.h | 89 +-
+ .../net/ethernet/mediatek/mtk_ppe_debugfs.c | 4 +-
+ .../net/ethernet/mediatek/mtk_ppe_offload.c | 167 +++-
drivers/net/ethernet/mediatek/mtk_wed.c | 876 ++++++++++++++++++
drivers/net/ethernet/mediatek/mtk_wed.h | 135 +++
.../net/ethernet/mediatek/mtk_wed_debugfs.c | 175 ++++
drivers/net/ethernet/mediatek/mtk_wed_ops.c | 8 +
drivers/net/ethernet/mediatek/mtk_wed_regs.h | 251 +++++
+ include/linux/netdevice.h | 7 +
include/linux/soc/mediatek/mtk_wed.h | 131 +++
net/core/dev.c | 4 +
- 13 files changed, 1701 insertions(+), 1 deletion(-)
+ 17 files changed, 2283 insertions(+), 128 deletions(-)
mode change 100755 => 100644 drivers/net/ethernet/mediatek/Kconfig
mode change 100755 => 100644 drivers/net/ethernet/mediatek/Makefile
mode change 100755 => 100644 drivers/net/ethernet/mediatek/mtk_eth_soc.c
mode change 100755 => 100644 drivers/net/ethernet/mediatek/mtk_eth_soc.h
+ mode change 100644 => 100755 drivers/net/ethernet/mediatek/mtk_ppe.c
create mode 100644 drivers/net/ethernet/mediatek/mtk_wed.c
create mode 100644 drivers/net/ethernet/mediatek/mtk_wed.h
create mode 100644 drivers/net/ethernet/mediatek/mtk_wed_debugfs.c
@@ -30,7 +36,7 @@
create mode 100644 include/linux/soc/mediatek/mtk_wed.h
diff --git a/arch/arm64/boot/dts/mediatek/mt7622.dtsi b/arch/arm64/boot/dts/mediatek/mt7622.dtsi
-index 753a97a..e46566a 100644
+index 369e01389..d0fbc367e 100644
--- a/arch/arm64/boot/dts/mediatek/mt7622.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt7622.dtsi
@@ -338,7 +338,7 @@
@@ -42,7 +48,7 @@
interface-type = "ace";
reg = <0x5000 0x1000>;
};
-@@ -921,6 +921,11 @@
+@@ -920,6 +920,11 @@
};
};
@@ -54,7 +60,7 @@
ethsys: syscon@1b000000 {
compatible = "mediatek,mt7622-ethsys",
"syscon";
-@@ -939,6 +944,26 @@
+@@ -938,6 +943,26 @@
#dma-cells = <1>;
};
@@ -81,7 +87,7 @@
eth: ethernet@1b100000 {
compatible = "mediatek,mt7622-eth",
"mediatek,mt2701-eth",
-@@ -965,6 +990,11 @@
+@@ -964,6 +989,11 @@
power-domains = <&scpsys MT7622_POWER_DOMAIN_ETHSYS>;
mediatek,ethsys = <ðsys>;
mediatek,sgmiisys = <&sgmiisys>;
@@ -96,7 +102,7 @@
diff --git a/drivers/net/ethernet/mediatek/Kconfig b/drivers/net/ethernet/mediatek/Kconfig
old mode 100755
new mode 100644
-index 7bfc78b..1574af9
+index 42e6b38d2..8ab6615a3
--- a/drivers/net/ethernet/mediatek/Kconfig
+++ b/drivers/net/ethernet/mediatek/Kconfig
@@ -7,6 +7,10 @@ config NET_VENDOR_MEDIATEK
@@ -113,12 +119,12 @@
diff --git a/drivers/net/ethernet/mediatek/Makefile b/drivers/net/ethernet/mediatek/Makefile
old mode 100755
new mode 100644
-index cfffde4..87786bb
+index 0a6af99f1..3528f1b3c
--- a/drivers/net/ethernet/mediatek/Makefile
+++ b/drivers/net/ethernet/mediatek/Makefile
-@@ -6,5 +6,10 @@
+@@ -6,4 +6,9 @@
obj-$(CONFIG_NET_MEDIATEK_SOC) += mtk_eth.o
- mtk_eth-y := mtk_eth_soc.o mtk_sgmii.o mtk_usxgmii.o mtk_eth_path.o mtk_eth_dbg.o mtk_eth_reset.o \
+ mtk_eth-y := mtk_eth_soc.o mtk_sgmii.o mtk_eth_path.o mtk_eth_dbg.o mtk_eth_reset.o \
mtk_ppe.o mtk_ppe_debugfs.o mtk_ppe_offload.o
+mtk_eth-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed.o
+ifdef CONFIG_DEBUG_FS
@@ -126,14 +132,13 @@
+endif
+obj-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed_ops.o
obj-$(CONFIG_NET_MEDIATEK_HNAT) += mtk_hnat/
- obj-$(CONFIG_XFRM_OFFLOAD) += mtk_ipsec.o
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
old mode 100755
new mode 100644
-index 0ffb90d..cfe1290
+index 819d8a0be..2121335a1
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -21,12 +21,14 @@
+@@ -20,12 +21,14 @@
#include <linux/pinctrl/devinfo.h>
#include <linux/phylink.h>
#include <linux/gpio/consumer.h>
@@ -148,7 +153,42 @@
#if defined(CONFIG_NET_MEDIATEK_HNAT) || defined(CONFIG_NET_MEDIATEK_HNAT_MODULE)
#include "mtk_hnat/nf_hnat_mtk.h"
-@@ -4748,6 +4750,22 @@ static int mtk_probe(struct platform_device *pdev)
+@@ -1737,6 +1740,7 @@ static int mtk_poll_rx(struct napi_struc
+ struct net_device *netdev = NULL;
+ unsigned int pktlen;
+ dma_addr_t dma_addr = 0;
++ u32 hash, reason;
+ int mac = 0;
+
+ if (eth->hwlro)
+@@ -1827,6 +1831,17 @@ static int mtk_poll_rx(struct napi_struc
+ skb_checksum_none_assert(skb);
+ skb->protocol = eth_type_trans(skb, netdev);
+
++ 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);
++ }
++
++ reason = FIELD_GET(MTK_RXD4_PPE_CPU_REASON, trxd.rxd4);
++ if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED)
++ mtk_ppe_check_skb(eth->ppe, skb,
++ trxd.rxd4 & MTK_RXD4_FOE_ENTRY);
++
+ if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) {
+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
+ MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
+@@ -3243,7 +3258,7 @@ static int mtk_stop(struct net_device *d
+ mtk_dma_free(eth);
+
+ if (eth->soc->offload_version)
+- mtk_ppe_stop(ð->ppe);
++ mtk_ppe_stop(eth->ppe);
+
+ return 0;
+ }
+@@ -4217,6 +4278,22 @@ static int mtk_probe(struct platform_dev
}
}
@@ -169,15 +209,30 @@
+ }
+
for (i = 0; i < MTK_PDMA_IRQ_NUM; i++)
- eth->irq_pdma[i] = platform_get_irq(pdev, i);
+ eth->irq_pdma[i] = platform_get_irq(pdev, i);
+
+@@ -4320,10 +4397,11 @@ static int mtk_probe(struct platform_dev
+ }
+
+ if (eth->soc->offload_version) {
+- err = mtk_ppe_init(ð->ppe, eth->dev,
+- eth->base + MTK_ETH_PPE_BASE, 2);
+- if (err)
++ eth->ppe = mtk_ppe_init(eth, eth->base + MTK_ETH_PPE_BASE, 2);
++ if (!eth->ppe) {
++ err = -ENOMEM;
+ goto err_free_dev;
++ }
+ err = mtk_eth_offload_init(eth);
+ if (err)
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
old mode 100755
new mode 100644
-index ec22dc5..c2c5037
+index 349f98503..b52378bd6
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-@@ -565,6 +565,9 @@
+@@ -549,6 +549,9 @@
#define RX_DMA_SPORT_MASK 0x7
#define RX_DMA_SPORT_MASK_V2 0xf
@@ -187,8 +242,688 @@
/* QDMA descriptor txd4 */
#define TX_DMA_CHKSUM (0x7 << 29)
#define TX_DMA_TSO BIT(28)
+@@ -1596,7 +1607,7 @@ struct mtk_eth {
+ spinlock_t syscfg0_lock;
+ struct timer_list mtk_dma_monitor_timer;
+
+- struct mtk_ppe ppe;
++ struct mtk_ppe *ppe;
+ struct rhashtable flow_table;
+ };
+
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
+old mode 100644
+new mode 100755
+index 66298e223..3d75c22be
+--- a/drivers/net/ethernet/mediatek/mtk_ppe.c
++++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
+@@ -6,9 +6,22 @@
+ #include <linux/iopoll.h>
+ #include <linux/etherdevice.h>
+ #include <linux/platform_device.h>
++#include <linux/if_ether.h>
++#include <linux/if_vlan.h>
++#include <net/dsa.h>
++#include "mtk_eth_soc.h"
+ #include "mtk_ppe.h"
+ #include "mtk_ppe_regs.h"
+
++static DEFINE_SPINLOCK(ppe_lock);
++
++static const struct rhashtable_params mtk_flow_l2_ht_params = {
++ .head_offset = offsetof(struct mtk_flow_entry, l2_node),
++ .key_offset = offsetof(struct mtk_flow_entry, data.bridge),
++ .key_len = offsetof(struct mtk_foe_bridge, key_end),
++ .automatic_shrinking = true,
++};
++
+ static void ppe_w32(struct mtk_ppe *ppe, u32 reg, u32 val)
+ {
+ writel(val, ppe->base + reg);
+@@ -41,6 +54,11 @@ static u32 ppe_clear(struct mtk_ppe *ppe, u32 reg, u32 val)
+ return ppe_m32(ppe, reg, val, 0);
+ }
+
++static u32 mtk_eth_timestamp(struct mtk_eth *eth)
++{
++ return mtk_r32(eth, 0x0010) & MTK_FOE_IB1_BIND_TIMESTAMP;
++}
++
+ static int mtk_ppe_wait_busy(struct mtk_ppe *ppe)
+ {
+ int ret;
+@@ -76,13 +94,6 @@ static u32 mtk_ppe_hash_entry(struct mtk_foe_entry *e)
+ u32 hash;
+
+ switch (FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, e->ib1)) {
+- case MTK_PPE_PKT_TYPE_BRIDGE:
+- hv1 = e->bridge.src_mac_lo;
+- hv1 ^= ((e->bridge.src_mac_hi & 0xffff) << 16);
+- hv2 = e->bridge.src_mac_hi >> 16;
+- hv2 ^= e->bridge.dest_mac_lo;
+- hv3 = e->bridge.dest_mac_hi;
+- break;
+ case MTK_PPE_PKT_TYPE_IPV4_ROUTE:
+ case MTK_PPE_PKT_TYPE_IPV4_HNAPT:
+ hv1 = e->ipv4.orig.ports;
+@@ -122,6 +133,9 @@ mtk_foe_entry_l2(struct mtk_foe_entry *entry)
+ {
+ int type = FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, entry->ib1);
+
++ if (type == MTK_PPE_PKT_TYPE_BRIDGE)
++ return &entry->bridge.l2;
++
+ if (type >= MTK_PPE_PKT_TYPE_IPV4_DSLITE)
+ return &entry->ipv6.l2;
+
+@@ -133,6 +147,9 @@ mtk_foe_entry_ib2(struct mtk_foe_entry *entry)
+ {
+ int type = FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, entry->ib1);
+
++ if (type == MTK_PPE_PKT_TYPE_BRIDGE)
++ return &entry->bridge.ib2;
++
+ if (type >= MTK_PPE_PKT_TYPE_IPV4_DSLITE)
+ return &entry->ipv6.ib2;
+
+@@ -167,7 +184,12 @@ int mtk_foe_entry_prepare(struct mtk_foe_entry *entry, int type, int l4proto,
+ if (type == MTK_PPE_PKT_TYPE_IPV6_ROUTE_3T)
+ entry->ipv6.ports = ports_pad;
+
+- if (type >= MTK_PPE_PKT_TYPE_IPV4_DSLITE) {
++ if (type == MTK_PPE_PKT_TYPE_BRIDGE) {
++ ether_addr_copy(entry->bridge.src_mac, src_mac);
++ ether_addr_copy(entry->bridge.dest_mac, dest_mac);
++ entry->bridge.ib2 = val;
++ l2 = &entry->bridge.l2;
++ } else if (type >= MTK_PPE_PKT_TYPE_IPV4_DSLITE) {
+ entry->ipv6.ib2 = val;
+ l2 = &entry->ipv6.l2;
+ } else {
+@@ -329,32 +351,168 @@ int mtk_foe_entry_set_pppoe(struct mtk_foe_entry *entry, int sid)
+ return 0;
+ }
+
++int mtk_foe_entry_set_wdma(struct mtk_foe_entry *entry, int wdma_idx, int txq,
++ int bss, int wcid)
++{
++ struct mtk_foe_mac_info *l2 = mtk_foe_entry_l2(entry);
++ u32 *ib2 = mtk_foe_entry_ib2(entry);
++
++ *ib2 &= ~MTK_FOE_IB2_PORT_MG;
++ *ib2 |= MTK_FOE_IB2_WDMA_WINFO;
++ if (wdma_idx)
++ *ib2 |= MTK_FOE_IB2_WDMA_DEVIDX;
++
++ l2->vlan2 = FIELD_PREP(MTK_FOE_VLAN2_WINFO_BSS, bss) |
++ FIELD_PREP(MTK_FOE_VLAN2_WINFO_WCID, wcid) |
++ FIELD_PREP(MTK_FOE_VLAN2_WINFO_RING, txq);
++
++ return 0;
++}
++
+ static inline bool mtk_foe_entry_usable(struct mtk_foe_entry *entry)
+ {
+ return !(entry->ib1 & MTK_FOE_IB1_STATIC) &&
+ FIELD_GET(MTK_FOE_IB1_STATE, entry->ib1) != MTK_FOE_STATE_BIND;
+ }
+
+-int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_foe_entry *entry,
+- u16 timestamp)
++static bool
++mtk_flow_entry_match(struct mtk_flow_entry *entry, struct mtk_foe_entry *data)
++{
++ int type, len;
++
++ if ((data->ib1 ^ entry->data.ib1) & MTK_FOE_IB1_UDP)
++ return false;
++
++ type = FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, entry->data.ib1);
++ if (type > MTK_PPE_PKT_TYPE_IPV4_DSLITE)
++ len = offsetof(struct mtk_foe_entry, ipv6._rsv);
++ else
++ len = offsetof(struct mtk_foe_entry, ipv4.ib2);
++
++ return !memcmp(&entry->data.data, &data->data, len - 4);
++}
++
++static void
++__mtk_foe_entry_clear(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
++{
++ struct hlist_head *head;
++ struct hlist_node *tmp;
++
++ if (entry->type == MTK_FLOW_TYPE_L2) {
++ rhashtable_remove_fast(&ppe->l2_flows, &entry->l2_node,
++ mtk_flow_l2_ht_params);
++
++ head = &entry->l2_flows;
++ hlist_for_each_entry_safe(entry, tmp, head, l2_data.list)
++ __mtk_foe_entry_clear(ppe, entry);
++ return;
++ }
++
++ hlist_del_init(&entry->list);
++ if (entry->hash != 0xffff) {
++ ppe->foe_table[entry->hash].ib1 &= ~MTK_FOE_IB1_STATE;
++ ppe->foe_table[entry->hash].ib1 |= FIELD_PREP(MTK_FOE_IB1_STATE,
++ MTK_FOE_STATE_INVALID);
++ dma_wmb();
++ mtk_ppe_cache_clear(ppe);
++ }
++ entry->hash = 0xffff;
++
++ if (entry->type != MTK_FLOW_TYPE_L2_SUBFLOW)
++ return;
++
++ hlist_del_init(&entry->l2_data.list);
++ kfree(entry);
++}
++
++static int __mtk_foe_entry_idle_time(struct mtk_ppe *ppe, u32 ib1)
++{
++ u16 timestamp;
++ u16 now;
++
++ now = mtk_eth_timestamp(ppe->eth) & MTK_FOE_IB1_BIND_TIMESTAMP;
++ timestamp = ib1 & MTK_FOE_IB1_BIND_TIMESTAMP;
++
++ if (timestamp > now)
++ return MTK_FOE_IB1_BIND_TIMESTAMP + 1 - timestamp + now;
++ else
++ return now - timestamp;
++}
++
++static void
++mtk_flow_entry_update_l2(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
+ {
++ struct mtk_flow_entry *cur;
+ struct mtk_foe_entry *hwe;
+- u32 hash;
++ struct hlist_node *tmp;
++ int idle;
++
++ idle = __mtk_foe_entry_idle_time(ppe, entry->data.ib1);
++ hlist_for_each_entry_safe(cur, tmp, &entry->l2_flows, l2_data.list) {
++ int cur_idle;
++ u32 ib1;
++
++ hwe = &ppe->foe_table[cur->hash];
++ ib1 = READ_ONCE(hwe->ib1);
++
++ if (FIELD_GET(MTK_FOE_IB1_STATE, ib1) != MTK_FOE_STATE_BIND) {
++ cur->hash = 0xffff;
++ __mtk_foe_entry_clear(ppe, cur);
++ continue;
++ }
++
++ cur_idle = __mtk_foe_entry_idle_time(ppe, ib1);
++ if (cur_idle >= idle)
++ continue;
++
++ idle = cur_idle;
++ entry->data.ib1 &= ~MTK_FOE_IB1_BIND_TIMESTAMP;
++ entry->data.ib1 |= hwe->ib1 & MTK_FOE_IB1_BIND_TIMESTAMP;
++ }
++}
++
++static void
++mtk_flow_entry_update(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
++{
++ struct mtk_foe_entry *hwe;
++ struct mtk_foe_entry foe;
++
++ spin_lock_bh(&ppe_lock);
++
++ if (entry->type == MTK_FLOW_TYPE_L2) {
++ mtk_flow_entry_update_l2(ppe, entry);
++ goto out;
++ }
++
++ if (entry->hash == 0xffff)
++ goto out;
++
++ hwe = &ppe->foe_table[entry->hash];
++ memcpy(&foe, hwe, sizeof(foe));
++ if (!mtk_flow_entry_match(entry, &foe)) {
++ entry->hash = 0xffff;
++ goto out;
++ }
++
++ entry->data.ib1 = foe.ib1;
++
++out:
++ spin_unlock_bh(&ppe_lock);
++}
++
++static void
++__mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_foe_entry *entry,
++ u16 hash)
++{
++ struct mtk_foe_entry *hwe;
++ u16 timestamp;
+
++ 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);
+
+- hash = mtk_ppe_hash_entry(entry);
+ hwe = &ppe->foe_table[hash];
+- if (!mtk_foe_entry_usable(hwe)) {
+- hwe++;
+- hash++;
+-
+- if (!mtk_foe_entry_usable(hwe))
+- return -ENOSPC;
+- }
+-
+ memcpy(&hwe->data, &entry->data, sizeof(hwe->data));
+ wmb();
+ hwe->ib1 = entry->ib1;
+@@ -362,32 +519,201 @@ int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_foe_entry *entry,
+ dma_wmb();
+
+ mtk_ppe_cache_clear(ppe);
++}
+
+- return hash;
++void mtk_foe_entry_clear(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
++{
++ spin_lock_bh(&ppe_lock);
++ __mtk_foe_entry_clear(ppe, entry);
++ spin_unlock_bh(&ppe_lock);
++}
++
++static int
++mtk_foe_entry_commit_l2(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
++{
++ entry->type = MTK_FLOW_TYPE_L2;
++
++ return rhashtable_insert_fast(&ppe->l2_flows, &entry->l2_node,
++ mtk_flow_l2_ht_params);
++}
++
++int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
++{
++ int type = FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, entry->data.ib1);
++ u32 hash;
++
++ if (type == MTK_PPE_PKT_TYPE_BRIDGE)
++ return mtk_foe_entry_commit_l2(ppe, entry);
++
++ hash = mtk_ppe_hash_entry(&entry->data);
++ entry->hash = 0xffff;
++ spin_lock_bh(&ppe_lock);
++ hlist_add_head(&entry->list, &ppe->foe_flow[hash / 4]);
++ spin_unlock_bh(&ppe_lock);
++
++ return 0;
++}
++
++static void
++mtk_foe_entry_commit_subflow(struct mtk_ppe *ppe, struct mtk_flow_entry *entry,
++ u16 hash)
++{
++ struct mtk_flow_entry *flow_info;
++ struct mtk_foe_entry foe, *hwe;
++ struct mtk_foe_mac_info *l2;
++ u32 ib1_mask = MTK_FOE_IB1_PACKET_TYPE | MTK_FOE_IB1_UDP;
++ int type;
++
++ flow_info = kzalloc(offsetof(struct mtk_flow_entry, l2_data.end),
++ GFP_ATOMIC);
++ if (!flow_info)
++ return;
++
++ flow_info->l2_data.base_flow = entry;
++ flow_info->type = MTK_FLOW_TYPE_L2_SUBFLOW;
++ flow_info->hash = hash;
++ hlist_add_head(&flow_info->list, &ppe->foe_flow[hash / 4]);
++ hlist_add_head(&flow_info->l2_data.list, &entry->l2_flows);
++
++ hwe = &ppe->foe_table[hash];
++ memcpy(&foe, hwe, sizeof(foe));
++ foe.ib1 &= ib1_mask;
++ foe.ib1 |= entry->data.ib1 & ~ib1_mask;
++
++ l2 = mtk_foe_entry_l2(&foe);
++ memcpy(l2, &entry->data.bridge.l2, sizeof(*l2));
++
++ type = FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, foe.ib1);
++ if (type == MTK_PPE_PKT_TYPE_IPV4_HNAPT)
++ memcpy(&foe.ipv4.new, &foe.ipv4.orig, sizeof(foe.ipv4.new));
++ else if (type >= MTK_PPE_PKT_TYPE_IPV6_ROUTE_3T && l2->etype == ETH_P_IP)
++ l2->etype = ETH_P_IPV6;
++
++ *mtk_foe_entry_ib2(&foe) = entry->data.bridge.ib2;
++
++ __mtk_foe_entry_commit(ppe, &foe, hash);
+ }
+
+-int mtk_ppe_init(struct mtk_ppe *ppe, struct device *dev, void __iomem *base,
++void __mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash)
++{
++ struct hlist_head *head = &ppe->foe_flow[hash / 4];
++ struct mtk_foe_entry *hwe = &ppe->foe_table[hash];
++ struct mtk_flow_entry *entry;
++ struct mtk_foe_bridge key = {};
++ struct hlist_node *n;
++ struct ethhdr *eh;
++ bool found = false;
++ u8 *tag;
++
++ spin_lock_bh(&ppe_lock);
++
++ if (hash >= MTK_PPE_ENTRIES)
++ goto out;
++
++ if (FIELD_GET(MTK_FOE_IB1_STATE, hwe->ib1) == MTK_FOE_STATE_BIND)
++ goto out;
++
++ hlist_for_each_entry_safe(entry, n, head, list) {
++ if (entry->type == MTK_FLOW_TYPE_L2_SUBFLOW) {
++ if (unlikely(FIELD_GET(MTK_FOE_IB1_STATE, hwe->ib1) ==
++ MTK_FOE_STATE_BIND))
++ continue;
++
++ entry->hash = 0xffff;
++ __mtk_foe_entry_clear(ppe, entry);
++ continue;
++ }
++
++ if (found || !mtk_flow_entry_match(entry, hwe)) {
++ if (entry->hash != 0xffff)
++ entry->hash = 0xffff;
++ continue;
++ }
++
++ entry->hash = hash;
++ __mtk_foe_entry_commit(ppe, &entry->data, hash);
++ found = true;
++ }
++
++ if (found)
++ goto out;
++
++ if (!skb)
++ goto out;
++
++ eh = eth_hdr(skb);
++ ether_addr_copy(key.dest_mac, eh->h_dest);
++ ether_addr_copy(key.src_mac, eh->h_source);
++ tag = skb->data - 2;
++ key.vlan = 0;
++ switch (skb->protocol) {
++#if IS_ENABLED(CONFIG_NET_DSA)
++ case htons(ETH_P_XDSA):
++ if (!netdev_uses_dsa(skb->dev) ||
++ skb->dev->dsa_ptr->tag_ops->proto != DSA_TAG_PROTO_MTK)
++ goto out;
++
++ tag += 4;
++ if (get_unaligned_be16(tag) != ETH_P_8021Q)
++ break;
++
++ fallthrough;
++#endif
++ case htons(ETH_P_8021Q):
++ key.vlan = get_unaligned_be16(tag + 2) & VLAN_VID_MASK;
++ break;
++ default:
++ break;
++ }
++
++ entry = rhashtable_lookup_fast(&ppe->l2_flows, &key, mtk_flow_l2_ht_params);
++ if (!entry)
++ goto out;
++
++ mtk_foe_entry_commit_subflow(ppe, entry, hash);
++
++out:
++ spin_unlock_bh(&ppe_lock);
++}
++
++int mtk_foe_entry_idle_time(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
++{
++ mtk_flow_entry_update(ppe, entry);
++
++ return __mtk_foe_entry_idle_time(ppe, entry->data.ib1);
++}
++
++struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
+ int version)
+ {
++ struct device *dev = eth->dev;
+ struct mtk_foe_entry *foe;
++ struct mtk_ppe *ppe;
++
++ ppe = devm_kzalloc(dev, sizeof(*ppe), GFP_KERNEL);
++ if (!ppe)
++ return NULL;
++
++ rhashtable_init(&ppe->l2_flows, &mtk_flow_l2_ht_params);
+
+ /* need to allocate a separate device, since it PPE DMA access is
+ * not coherent.
+ */
+ ppe->base = base;
++ ppe->eth = eth;
+ ppe->dev = dev;
+ ppe->version = version;
+
+ foe = dmam_alloc_coherent(ppe->dev, MTK_PPE_ENTRIES * sizeof(*foe),
+ &ppe->foe_phys, GFP_KERNEL);
+ if (!foe)
+- return -ENOMEM;
++ return NULL;
+
+ ppe->foe_table = foe;
+
+ mtk_ppe_debugfs_init(ppe);
+
+- return 0;
++ return ppe;
+ }
+
+ static void mtk_ppe_init_foe_table(struct mtk_ppe *ppe)
+@@ -395,7 +717,7 @@ static void mtk_ppe_init_foe_table(struct mtk_ppe *ppe)
+ static const u8 skip[] = { 12, 25, 38, 51, 76, 89, 102 };
+ int i, k;
+
+- memset(ppe->foe_table, 0, MTK_PPE_ENTRIES * sizeof(*ppe->foe_table));
++ memset(ppe->foe_table, 0, MTK_PPE_ENTRIES * sizeof(ppe->foe_table));
+
+ if (!IS_ENABLED(CONFIG_SOC_MT7621))
+ return;
+@@ -443,7 +765,6 @@ int mtk_ppe_start(struct mtk_ppe *ppe)
+ MTK_PPE_FLOW_CFG_IP4_NAT |
+ MTK_PPE_FLOW_CFG_IP4_NAPT |
+ MTK_PPE_FLOW_CFG_IP4_DSLITE |
+- MTK_PPE_FLOW_CFG_L2_BRIDGE |
+ MTK_PPE_FLOW_CFG_IP4_NAT_FRAG;
+ ppe_w32(ppe, MTK_PPE_FLOW_CFG, val);
+
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
+index 242fb8f2a..1f5cf1c9a 100644
+--- a/drivers/net/ethernet/mediatek/mtk_ppe.h
++++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
+@@ -6,6 +6,7 @@
+
+ #include <linux/kernel.h>
+ #include <linux/bitfield.h>
++#include <linux/rhashtable.h>
+
+ #define MTK_ETH_PPE_BASE 0xc00
+
+@@ -48,9 +49,9 @@ enum {
+ #define MTK_FOE_IB2_DEST_PORT GENMASK(7, 5)
+ #define MTK_FOE_IB2_MULTICAST BIT(8)
+
+-#define MTK_FOE_IB2_WHNAT_QID2 GENMASK(13, 12)
+-#define MTK_FOE_IB2_WHNAT_DEVIDX BIT(16)
+-#define MTK_FOE_IB2_WHNAT_NAT BIT(17)
++#define MTK_FOE_IB2_WDMA_QID2 GENMASK(13, 12)
++#define MTK_FOE_IB2_WDMA_DEVIDX BIT(16)
++#define MTK_FOE_IB2_WDMA_WINFO BIT(17)
+
+ #define MTK_FOE_IB2_PORT_MG GENMASK(17, 12)
+
+@@ -58,9 +59,9 @@ enum {
+
+ #define MTK_FOE_IB2_DSCP GENMASK(31, 24)
+
+-#define MTK_FOE_VLAN2_WHNAT_BSS GEMMASK(5, 0)
+-#define MTK_FOE_VLAN2_WHNAT_WCID GENMASK(13, 6)
+-#define MTK_FOE_VLAN2_WHNAT_RING GENMASK(15, 14)
++#define MTK_FOE_VLAN2_WINFO_BSS GENMASK(5, 0)
++#define MTK_FOE_VLAN2_WINFO_WCID GENMASK(13, 6)
++#define MTK_FOE_VLAN2_WINFO_RING GENMASK(15, 14)
+
+ enum {
+ MTK_FOE_STATE_INVALID,
+@@ -84,19 +85,16 @@ struct mtk_foe_mac_info {
+ u16 src_mac_lo;
+ };
+
++/* software-only entry type */
+ struct mtk_foe_bridge {
+- u32 dest_mac_hi;
++ u8 dest_mac[ETH_ALEN];
++ u8 src_mac[ETH_ALEN];
++ u16 vlan;
+
+- u16 src_mac_lo;
+- u16 dest_mac_lo;
+-
+- u32 src_mac_hi;
++ struct {} key_end;
+
+ u32 ib2;
+
+- u32 _rsv[5];
+-
+- u32 udf_tsid;
+ struct mtk_foe_mac_info l2;
+ };
+
+@@ -235,7 +233,37 @@ enum {
+ MTK_PPE_CPU_REASON_INVALID = 0x1f,
+ };
+
++enum {
++ MTK_FLOW_TYPE_L4,
++ MTK_FLOW_TYPE_L2,
++ MTK_FLOW_TYPE_L2_SUBFLOW,
++};
++
++struct mtk_flow_entry {
++ union {
++ struct hlist_node list;
++ struct {
++ struct rhash_head l2_node;
++ struct hlist_head l2_flows;
++ };
++ };
++ u8 type;
++ s8 wed_index;
++ u16 hash;
++ union {
++ struct mtk_foe_entry data;
++ struct {
++ struct mtk_flow_entry *base_flow;
++ struct hlist_node list;
++ struct {} end;
++ } l2_data;
++ };
++ struct rhash_head node;
++ unsigned long cookie;
++};
++
+ struct mtk_ppe {
++ struct mtk_eth *eth;
+ struct device *dev;
+ void __iomem *base;
+ int version;
+@@ -243,19 +271,35 @@ struct mtk_ppe {
+ struct mtk_foe_entry *foe_table;
+ dma_addr_t foe_phys;
+
++ u16 foe_check_time[MTK_PPE_ENTRIES];
++ struct hlist_head foe_flow[MTK_PPE_ENTRIES / 2];
++
++ struct rhashtable l2_flows;
++
+ void *acct_table;
+ };
+
+-int mtk_ppe_init(struct mtk_ppe *ppe, struct device *dev, void __iomem *base,
+- int version);
++struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int version);
+ int mtk_ppe_start(struct mtk_ppe *ppe);
+ int mtk_ppe_stop(struct mtk_ppe *ppe);
+
++void __mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash);
++
+ static inline void
+-mtk_foe_entry_clear(struct mtk_ppe *ppe, u16 hash)
++mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash)
+ {
+- ppe->foe_table[hash].ib1 = 0;
+- dma_wmb();
++ u16 now, diff;
++
++ if (!ppe)
++ return;
++
++ now = (u16)jiffies;
++ diff = now - ppe->foe_check_time[hash];
++ if (diff < HZ / 10)
++ return;
++
++ ppe->foe_check_time[hash] = now;
++ __mtk_ppe_check_skb(ppe, skb, hash);
+ }
+
+ static inline int
+@@ -281,8 +325,11 @@ int mtk_foe_entry_set_ipv6_tuple(struct mtk_foe_entry *entry,
+ 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);
+ int mtk_foe_entry_set_pppoe(struct mtk_foe_entry *entry, int sid);
+-int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_foe_entry *entry,
+- u16 timestamp);
++int mtk_foe_entry_set_wdma(struct mtk_foe_entry *entry, int wdma_idx, int txq,
++ int bss, int wcid);
++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);
+ int mtk_ppe_debugfs_init(struct mtk_ppe *ppe);
+
+ #endif
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c b/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
+index d4b482340..a591ab1fd 100644
+--- a/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
++++ b/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
+@@ -32,7 +32,6 @@ static const char *mtk_foe_pkt_type_str(int type)
+ static const char * const type_str[] = {
+ [MTK_PPE_PKT_TYPE_IPV4_HNAPT] = "IPv4 5T",
+ [MTK_PPE_PKT_TYPE_IPV4_ROUTE] = "IPv4 3T",
+- [MTK_PPE_PKT_TYPE_BRIDGE] = "L2",
+ [MTK_PPE_PKT_TYPE_IPV4_DSLITE] = "DS-LITE",
+ [MTK_PPE_PKT_TYPE_IPV6_ROUTE_3T] = "IPv6 3T",
+ [MTK_PPE_PKT_TYPE_IPV6_ROUTE_5T] = "IPv6 5T",
+@@ -207,6 +206,9 @@ int mtk_ppe_debugfs_init(struct mtk_ppe *ppe)
+ struct dentry *root;
+
+ root = debugfs_create_dir("mtk_ppe", NULL);
++ if (!root)
++ return -ENOMEM;
++
+ debugfs_create_file("entries", S_IRUGO, root, ppe, &fops_all);
+ debugfs_create_file("bind", S_IRUGO, root, ppe, &fops_bind);
+
diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
-index 30d2b02..aa30abb 100644
+index 4294f0c74..d4a012608 100644
--- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
+++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
@@ -11,6 +11,7 @@
@@ -199,7 +934,42 @@
struct mtk_flow_data {
struct ethhdr eth;
-@@ -85,6 +86,35 @@ mtk_flow_offload_mangle_eth(const struct flow_action_entry *act, void *eth)
+@@ -30,6 +31,8 @@ struct mtk_flow_data {
+ __be16 src_port;
+ __be16 dst_port;
+
++ u16 vlan_in;
++
+ struct {
+ u16 id;
+ __be16 proto;
+@@ -41,12 +44,6 @@ struct mtk_flow_data {
+ } pppoe;
+ };
+
+-struct mtk_flow_entry {
+- struct rhash_head node;
+- unsigned long cookie;
+- u16 hash;
+-};
+-
+ static const struct rhashtable_params mtk_flow_ht_params = {
+ .head_offset = offsetof(struct mtk_flow_entry, node),
+ .key_offset = offsetof(struct mtk_flow_entry, cookie),
+@@ -54,12 +51,6 @@ static const struct rhashtable_params mtk_flow_ht_params = {
+ .automatic_shrinking = true,
+ };
+
+-static u32
+-mtk_eth_timestamp(struct mtk_eth *eth)
+-{
+- return mtk_r32(eth, 0x0010) & MTK_FOE_IB1_BIND_TIMESTAMP;
+-}
+-
+ static int
+ mtk_flow_set_ipv4_addr(struct mtk_foe_entry *foe, struct mtk_flow_data *data,
+ bool egress)
+@@ -94,6 +85,35 @@ mtk_flow_offload_mangle_eth(const struct flow_action_entry *act, void *eth)
memcpy(dest, src, act->mangle.mask ? 2 : 4);
}
@@ -232,41 +1002,158 @@
+ return 0;
+}
+
+
static int
mtk_flow_mangle_ports(const struct flow_action_entry *act,
- struct mtk_flow_data *data)
-@@ -156,8 +186,30 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
- struct net_device *dev, const u8 *dest_mac,
- int *wed_index)
+@@ -163,10 +183,20 @@ 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)
++ struct net_device *dev, const u8 *dest_mac,
++ int *wed_index)
{
+ struct mtk_wdma_info info = {};
- int pse_port, dsa_port, queue;
+ int pse_port, dsa_port;
+ if (mtk_flow_get_wdma_info(dev, dest_mac, &info) == 0) {
-+ mtk_foe_entry_set_wdma(eth, foe, info.wdma_idx, info.queue,
-+ info.bss, info.wcid);
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
-+ switch (info.wdma_idx) {
-+ case 0:
-+ pse_port = 8;
-+ break;
-+ case 1:
-+ pse_port = 9;
-+ break;
-+ default:
-+ return -EINVAL;
-+ }
-+ } else {
-+ pse_port = 3;
-+ }
++ mtk_foe_entry_set_wdma(foe, info.wdma_idx, info.queue, info.bss,
++ info.wcid);
++ pse_port = PSE_PPE0_PORT;
+ *wed_index = info.wdma_idx;
+ goto out;
+ }
+
dsa_port = mtk_flow_get_dsa_port(&dev);
+ if (dsa_port >= 0)
+ mtk_foe_entry_set_dsa(foe, dsa_port);
+@@ -178,6 +208,7 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
+ else
+ return -EOPNOTSUPP;
+
++out:
+ mtk_foe_entry_set_pse_port(foe, pse_port);
+
+ return 0;
+@@ -193,11 +224,10 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
+ struct net_device *odev = NULL;
+ struct mtk_flow_entry *entry;
+ int offload_type = 0;
++ int wed_index = -1;
+ u16 addr_type = 0;
+- u32 timestamp;
+ u8 l4proto = 0;
+ int err = 0;
+- int hash;
+ int i;
+
+ if (rhashtable_lookup(ð->flow_table, &f->cookie, mtk_flow_ht_params))
+@@ -229,9 +259,45 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
+ return -EOPNOTSUPP;
+ }
+
++ switch (addr_type) {
++ case 0:
++ offload_type = MTK_PPE_PKT_TYPE_BRIDGE;
++ if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
++ struct flow_match_eth_addrs match;
++
++ flow_rule_match_eth_addrs(rule, &match);
++ memcpy(data.eth.h_dest, match.key->dst, ETH_ALEN);
++ memcpy(data.eth.h_source, match.key->src, ETH_ALEN);
++ } else {
++ return -EOPNOTSUPP;
++ }
++
++ if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_VLAN)) {
++ struct flow_match_vlan match;
++
++ flow_rule_match_vlan(rule, &match);
++
++ if (match.key->vlan_tpid != cpu_to_be16(ETH_P_8021Q))
++ return -EOPNOTSUPP;
++
++ data.vlan_in = match.key->vlan_id;
++ }
++ break;
++ case FLOW_DISSECTOR_KEY_IPV4_ADDRS:
++ offload_type = MTK_PPE_PKT_TYPE_IPV4_HNAPT;
++ break;
++ case FLOW_DISSECTOR_KEY_IPV6_ADDRS:
++ offload_type = MTK_PPE_PKT_TYPE_IPV6_ROUTE_5T;
++ break;
++ default:
++ return -EOPNOTSUPP;
++ }
++
+ flow_action_for_each(i, act, &rule->action) {
+ switch (act->id) {
+ case FLOW_ACTION_MANGLE:
++ if (offload_type == MTK_PPE_PKT_TYPE_BRIDGE)
++ return -EOPNOTSUPP;
+ if (act->mangle.htype == FLOW_ACT_MANGLE_HDR_TYPE_ETH)
+ mtk_flow_offload_mangle_eth(act, &data.eth);
+ break;
+@@ -263,17 +329,6 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
+ }
+ }
+
+- switch (addr_type) {
+- case FLOW_DISSECTOR_KEY_IPV4_ADDRS:
+- offload_type = MTK_PPE_PKT_TYPE_IPV4_HNAPT;
+- break;
+- case FLOW_DISSECTOR_KEY_IPV6_ADDRS:
+- offload_type = MTK_PPE_PKT_TYPE_IPV6_ROUTE_5T;
+- break;
+- default:
+- return -EOPNOTSUPP;
+- }
+-
+ if (!is_valid_ether_addr(data.eth.h_source) ||
+ !is_valid_ether_addr(data.eth.h_dest))
+ return -EINVAL;
+@@ -287,10 +342,13 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
+ if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_PORTS)) {
+ struct flow_match_ports ports;
- if (dev == eth->netdev[0])
-@@ -396,6 +448,9 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f,
++ if (offload_type == MTK_PPE_PKT_TYPE_BRIDGE)
++ return -EOPNOTSUPP;
++
+ flow_rule_match_ports(rule, &ports);
+ data.src_port = ports.key->src;
+ data.dst_port = ports.key->dst;
+- } else {
++ } else if (offload_type != MTK_PPE_PKT_TYPE_BRIDGE) {
+ return -EOPNOTSUPP;
+ }
+
+@@ -320,6 +378,9 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
+ if (act->id != FLOW_ACTION_MANGLE)
+ continue;
+
++ if (offload_type == MTK_PPE_PKT_TYPE_BRIDGE)
++ return -EOPNOTSUPP;
++
+ switch (act->mangle.htype) {
+ case FLOW_ACT_MANGLE_HDR_TYPE_TCP:
+ case FLOW_ACT_MANGLE_HDR_TYPE_UDP:
+@@ -345,6 +406,9 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
+ return err;
+ }
+
++ if (offload_type == MTK_PPE_PKT_TYPE_BRIDGE)
++ foe.bridge.vlan = data.vlan_in;
++
+ if (data.vlan.num == 1) {
+ if (data.vlan.proto != htons(ETH_P_8021Q))
+ return -EOPNOTSUPP;
+@@ -354,33 +418,38 @@ 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);
++ err = mtk_flow_set_output_device(eth, &foe, odev, data.eth.h_dest,
++ &wed_index);
if (err)
return err;
@@ -276,16 +1163,32 @@
entry = kzalloc(sizeof(*entry), GFP_KERNEL);
if (!entry)
return -ENOMEM;
-@@ -418,6 +473,7 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f,
entry->cookie = f->cookie;
- memcpy(&entry->data, &foe, sizeof(entry->data));
+- timestamp = mtk_eth_timestamp(eth);
+- hash = mtk_foe_entry_commit(ð->ppe, &foe, timestamp);
+- if (hash < 0) {
+- err = hash;
++ memcpy(&entry->data, &foe, sizeof(entry->data));
+ entry->wed_index = wed_index;
- entry->ppe_index = ppe_index;
++
++ if (mtk_foe_entry_commit(eth->ppe, entry) < 0)
+ goto free;
+- }
- err = mtk_foe_entry_commit(eth->ppe[entry->ppe_index], entry);
-@@ -435,6 +491,8 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f,
- mtk_foe_entry_clear(eth->ppe[entry->ppe_index], entry);
+- entry->hash = hash;
+ err = rhashtable_insert_fast(ð->flow_table, &entry->node,
+ mtk_flow_ht_params);
+ if (err < 0)
+- goto clear_flow;
++ goto clear;
+
+ return 0;
+-clear_flow:
+- mtk_foe_entry_clear(ð->ppe, hash);
++
++clear:
++ mtk_foe_entry_clear(eth->ppe, entry);
free:
kfree(entry);
+ if (wed_index >= 0)
@@ -293,8 +1196,12 @@
return err;
}
-@@ -451,6 +509,8 @@ mtk_flow_offload_destroy(struct mtk_eth *eth, struct flow_cls_offload *f)
- mtk_foe_entry_clear(eth->ppe[entry->ppe_index], entry);
+@@ -394,9 +463,11 @@ mtk_flow_offload_destroy(struct mtk_eth *eth, struct flow_cls_offload *f)
+ if (!entry)
+ return -ENOENT;
+
+- mtk_foe_entry_clear(ð->ppe, entry->hash);
++ mtk_foe_entry_clear(eth->ppe, entry);
rhashtable_remove_fast(ð->flow_table, &entry->node,
mtk_flow_ht_params);
+ if (entry->wed_index >= 0)
@@ -302,9 +1209,62 @@
kfree(entry);
return 0;
+@@ -406,7 +477,6 @@ static int
+ mtk_flow_offload_stats(struct mtk_eth *eth, struct flow_cls_offload *f)
+ {
+ struct mtk_flow_entry *entry;
+- int timestamp;
+ u32 idle;
+
+ entry = rhashtable_lookup(ð->flow_table, &f->cookie,
+@@ -414,11 +484,7 @@ mtk_flow_offload_stats(struct mtk_eth *eth, struct flow_cls_offload *f)
+ if (!entry)
+ return -ENOENT;
+
+- timestamp = mtk_foe_entry_timestamp(ð->ppe, entry->hash);
+- if (timestamp < 0)
+- return -ETIMEDOUT;
+-
+- idle = mtk_eth_timestamp(eth) - timestamp;
++ idle = mtk_foe_entry_idle_time(eth->ppe, entry);
+ f->stats.lastused = jiffies - idle * HZ;
+
+ return 0;
+@@ -470,7 +536,7 @@ mtk_eth_setup_tc_block(struct net_device *dev, struct flow_block_offload *f)
+ struct flow_block_cb *block_cb;
+ flow_setup_cb_t *cb;
+
+- if (!eth->ppe.foe_table)
++ if (!eth->ppe || !eth->ppe->foe_table)
+ return -EOPNOTSUPP;
+
+ if (f->binder_type != FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
+@@ -511,15 +577,18 @@ mtk_eth_setup_tc_block(struct net_device *dev, struct flow_block_offload *f)
+ int mtk_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,
+ void *type_data)
+ {
+- if (type == TC_SETUP_FT)
++ switch (type) {
++ case TC_SETUP_BLOCK:
++ case TC_SETUP_FT:
+ return mtk_eth_setup_tc_block(dev, type_data);
+-
+- return -EOPNOTSUPP;
++ default:
++ return -EOPNOTSUPP;
++ }
+ }
+
+ int mtk_eth_offload_init(struct mtk_eth *eth)
+ {
+- if (!eth->ppe.foe_table)
++ if (!eth->ppe || !eth->ppe->foe_table)
+ return 0;
+
+ return rhashtable_init(ð->flow_table, &mtk_flow_ht_params);
diff --git a/drivers/net/ethernet/mediatek/mtk_wed.c b/drivers/net/ethernet/mediatek/mtk_wed.c
new file mode 100644
-index 0000000..ea1cbdf
+index 000000000..ea1cbdf1a
--- /dev/null
+++ b/drivers/net/ethernet/mediatek/mtk_wed.c
@@ -0,0 +1,876 @@
@@ -1186,7 +2146,7 @@
+}
diff --git a/drivers/net/ethernet/mediatek/mtk_wed.h b/drivers/net/ethernet/mediatek/mtk_wed.h
new file mode 100644
-index 0000000..981ec61
+index 000000000..981ec613f
--- /dev/null
+++ b/drivers/net/ethernet/mediatek/mtk_wed.h
@@ -0,0 +1,135 @@
@@ -1327,7 +2287,7 @@
+#endif
diff --git a/drivers/net/ethernet/mediatek/mtk_wed_debugfs.c b/drivers/net/ethernet/mediatek/mtk_wed_debugfs.c
new file mode 100644
-index 0000000..a81d3fd
+index 000000000..a81d3fd1a
--- /dev/null
+++ b/drivers/net/ethernet/mediatek/mtk_wed_debugfs.c
@@ -0,0 +1,175 @@
@@ -1508,7 +2468,7 @@
+}
diff --git a/drivers/net/ethernet/mediatek/mtk_wed_ops.c b/drivers/net/ethernet/mediatek/mtk_wed_ops.c
new file mode 100644
-index 0000000..a5d9d8a
+index 000000000..a5d9d8a5b
--- /dev/null
+++ b/drivers/net/ethernet/mediatek/mtk_wed_ops.c
@@ -0,0 +1,8 @@
@@ -1522,7 +2482,7 @@
+EXPORT_SYMBOL_GPL(mtk_soc_wed_ops);
diff --git a/drivers/net/ethernet/mediatek/mtk_wed_regs.h b/drivers/net/ethernet/mediatek/mtk_wed_regs.h
new file mode 100644
-index 0000000..0a0465e
+index 000000000..0a0465ea5
--- /dev/null
+++ b/drivers/net/ethernet/mediatek/mtk_wed_regs.h
@@ -0,0 +1,251 @@
@@ -1777,9 +2737,34 @@
+#define HIFSYS_DMA_AG_MAP 0x008
+
+#endif
+diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
+index 9f64504ac..35998b1a7 100644
+--- a/include/linux/netdevice.h
++++ b/include/linux/netdevice.h
+@@ -835,6 +835,7 @@ enum net_device_path_type {
+ DEV_PATH_BRIDGE,
+ DEV_PATH_PPPOE,
+ DEV_PATH_DSA,
++ DEV_PATH_MTK_WDMA,
+ };
+
+ struct net_device_path {
+@@ -860,6 +861,12 @@ struct net_device_path {
+ int port;
+ u16 proto;
+ } dsa;
++ struct {
++ u8 wdma_idx;
++ u8 queue;
++ u16 wcid;
++ u8 bss;
++ } mtk_wdma;
+ };
+ };
+
diff --git a/include/linux/soc/mediatek/mtk_wed.h b/include/linux/soc/mediatek/mtk_wed.h
new file mode 100644
-index 0000000..7e00cca
+index 000000000..7e00cca06
--- /dev/null
+++ b/include/linux/soc/mediatek/mtk_wed.h
@@ -0,0 +1,131 @@
@@ -1915,7 +2900,7 @@
+
+#endif
diff --git a/net/core/dev.c b/net/core/dev.c
-index a1f046c..b42ec06 100644
+index 4f0edb218..031ac7c6f 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -675,6 +675,10 @@ int dev_fill_forward_path(const struct net_device *dev, const u8 *daddr,
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3006-ethernet-update-ppe-from-mt7622-to-mt7986.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3006-ethernet-update-ppe-from-mt7622-to-mt7986.patch
new file mode 100755
index 0000000..c0efd12
--- /dev/null
+++ b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3006-ethernet-update-ppe-from-mt7622-to-mt7986.patch
@@ -0,0 +1,371 @@
+From d86af0076cbf7d99bdb4f28115159643b79ad3fa Mon Sep 17 00:00:00 2001
+From: Sujuan Chen <sujuan.chen@mediatek.com>
+Date: Wed, 18 May 2022 11:08:15 +0800
+Subject: [PATCH 5/8] 9994-ethernet-update-ppe-from-mt7622-to-mt7986
+
+Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com>
+---
+ drivers/net/ethernet/mediatek/mtk_eth_soc.c | 14 +++-
+ drivers/net/ethernet/mediatek/mtk_eth_soc.h | 7 +-
+ drivers/net/ethernet/mediatek/mtk_ppe.c | 24 ++++---
+ drivers/net/ethernet/mediatek/mtk_ppe.h | 69 ++++++++++---------
+ .../net/ethernet/mediatek/mtk_ppe_offload.c | 7 +-
+ drivers/net/ethernet/mediatek/mtk_ppe_regs.h | 10 +++
+ 6 files changed, 86 insertions(+), 45 deletions(-)
+
+diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+index 2121335a1..01fc1e5c0 100644
+--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
++++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+@@ -1467,16 +1467,27 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
+ skb_checksum_none_assert(skb);
+ skb->protocol = eth_type_trans(skb, netdev);
+
+- hash = trxd.rxd4 & MTK_RXD4_FOE_ENTRY;
++#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2)
++ hash = trxd.rxd5 & MTK_RXD5_FOE_ENTRY_V2;
++#else
++ hash = trxd.rxd4 & MTK_RXD4_FOE_ENTRY;
++#endif
+ if (hash != MTK_RXD4_FOE_ENTRY) {
+ hash = jhash_1word(hash, 0);
+ skb_set_hash(skb, hash, PKT_HASH_TYPE_L4);
+ }
+
++#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2)
++ reason = FIELD_GET(MTK_RXD5_PPE_CPU_REASON_V2, trxd.rxd5);
++ if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED)
++ mtk_ppe_check_skb(eth->ppe, skb,
++ trxd.rxd5 & MTK_RXD5_FOE_ENTRY_V2);
++#else
+ reason = FIELD_GET(MTK_RXD4_PPE_CPU_REASON, trxd.rxd4);
+ if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED)
+ mtk_ppe_check_skb(eth->ppe, skb,
+ trxd.rxd4 & MTK_RXD4_FOE_ENTRY);
++#endif
+
+ if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) {
+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
+@@ -3926,13 +3937,14 @@ static const struct mtk_soc_data mt7986_data = {
+ .required_clks = MT7986_CLKS_BITMAP,
+ .required_pctl = false,
+ .has_sram = true,
++ .offload_version = 2,
+ .rss_num = 0,
+ .txrx = {
+ .txd_size = sizeof(struct mtk_tx_dma_v2),
+ .rxd_size = sizeof(struct mtk_rx_dma),
+ .rx_dma_l4_valid = RX_DMA_L4_VALID_V2,
+ .dma_max_len = MTK_TX_DMA_BUF_LEN_V2,
+ .dma_len_offset = MTK_TX_DMA_BUF_SHIFT_V2,
+ },
+ };
+
+diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
+index b52378bd6..fce1a7172 100644
+--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
++++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
+@@ -110,7 +110,7 @@
+ #define MTK_GDMA_TCS_EN BIT(21)
+ #define MTK_GDMA_UCS_EN BIT(20)
+ #define MTK_GDMA_TO_PDMA 0x0
+-#define MTK_GDMA_TO_PPE 0x4444
++#define MTK_GDMA_TO_PPE 0x3333
+ #define MTK_GDMA_DROP_ALL 0x7777
+
+ /* Unicast Filter MAC Address Register - Low */
+@@ -560,6 +560,11 @@
+ #define MTK_RXD4_SRC_PORT GENMASK(21, 19)
+ #define MTK_RXD4_ALG GENMASK(31, 22)
+
++/* QDMA descriptor rxd4 */
++#define MTK_RXD5_FOE_ENTRY_V2 GENMASK(14, 0)
++#define MTK_RXD5_PPE_CPU_REASON_V2 GENMASK(22, 18)
++#define MTK_RXD5_SRC_PORT_V2 GENMASK(29, 26)
++
+ /* QDMA descriptor rxd4 */
+ #define RX_DMA_L4_VALID BIT(24)
+ #define RX_DMA_L4_VALID_PDMA BIT(30) /* when PDMA is used */
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
+index 3d75c22be..d46e91178 100755
+--- a/drivers/net/ethernet/mediatek/mtk_ppe.c
++++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
+@@ -122,7 +122,7 @@ static u32 mtk_ppe_hash_entry(struct mtk_foe_entry *e)
+ hash = (hash >> 24) | ((hash & 0xffffff) << 8);
+ hash ^= hv1 ^ hv2 ^ hv3;
+ hash ^= hash >> 16;
+- hash <<= 1;
++ hash <<= 2;
+ hash &= MTK_PPE_ENTRIES - 1;
+
+ return hash;
+@@ -171,8 +171,12 @@ int mtk_foe_entry_prepare(struct mtk_foe_entry *entry, int type, int l4proto,
+ MTK_FOE_IB1_BIND_CACHE;
+ entry->ib1 = val;
+
++#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++ val = FIELD_PREP(MTK_FOE_IB2_PORT_AG, 0xf) |
++#else
+ val = FIELD_PREP(MTK_FOE_IB2_PORT_MG, 0x3f) |
+ FIELD_PREP(MTK_FOE_IB2_PORT_AG, 0x1f) |
++#endif
+ FIELD_PREP(MTK_FOE_IB2_DEST_PORT, pse_port);
+
+ if (is_multicast_ether_addr(dest_mac))
+@@ -359,12 +358,19 @@ int mtk_foe_entry_set_wdma(struct mtk_foe_entry *entry, int wdma_idx, int txq,
+
+ *ib2 &= ~MTK_FOE_IB2_PORT_MG;
+ *ib2 |= MTK_FOE_IB2_WDMA_WINFO;
++#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++ *ib2 |= FIELD_PREP(MTK_FOE_IB2_RX_IDX, txq);
++
++ l2->winfo = FIELD_PREP(MTK_FOE_WINFO_WCID, wcid) |
++ FIELD_PREP(MTK_FOE_WINFO_BSS, bss);
++#else
+ if (wdma_idx)
+ *ib2 |= MTK_FOE_IB2_WDMA_DEVIDX;
+
+ l2->vlan2 = FIELD_PREP(MTK_FOE_VLAN2_WINFO_BSS, bss) |
+ FIELD_PREP(MTK_FOE_VLAN2_WINFO_WCID, wcid) |
+ FIELD_PREP(MTK_FOE_VLAN2_WINFO_RING, txq);
++#endif
+
+ return 0;
+ }
+@@ -741,6 +738,9 @@ int mtk_ppe_start(struct mtk_ppe *ppe)
+ MTK_PPE_TB_CFG_AGE_TCP |
+ MTK_PPE_TB_CFG_AGE_UDP |
+ MTK_PPE_TB_CFG_AGE_TCP_FIN |
++#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++ MTK_PPE_TB_CFG_INFO_SEL |
++#endif
+ FIELD_PREP(MTK_PPE_TB_CFG_SEARCH_MISS,
+ MTK_PPE_SEARCH_MISS_ACTION_FORWARD_BUILD) |
+ FIELD_PREP(MTK_PPE_TB_CFG_KEEPALIVE,
+@@ -757,7 +755,8 @@ int mtk_ppe_start(struct mtk_ppe *ppe)
+
+ mtk_ppe_cache_enable(ppe, true);
+
+- val = MTK_PPE_FLOW_CFG_IP4_TCP_FRAG |
++ val = MTK_PPE_MD_TOAP_BYP_CRSN0 |
++ MTK_PPE_MD_TOAP_BYP_CRSN1 |
++ MTK_PPE_MD_TOAP_BYP_CRSN2 |
+- MTK_PPE_FLOW_CFG_IP4_UDP_FRAG |
+ MTK_PPE_FLOW_CFG_IP6_3T_ROUTE |
+ MTK_PPE_FLOW_CFG_IP6_5T_ROUTE |
+@@ -765,7 +765,8 @@ int mtk_ppe_start(struct mtk_ppe *ppe)
+ MTK_PPE_FLOW_CFG_IP4_NAT |
+ MTK_PPE_FLOW_CFG_IP4_NAPT |
+ MTK_PPE_FLOW_CFG_IP4_DSLITE |
+- MTK_PPE_FLOW_CFG_IP4_NAT_FRAG;
++ MTK_PPE_FLOW_CFG_IP4_NAT_FRAG |
++ MTK_PPE_FLOW_CFG_IP4_HASH_GRE_KEY;
+ ppe_w32(ppe, MTK_PPE_FLOW_CFG, val);
+
+ val = FIELD_PREP(MTK_PPE_UNBIND_AGE_MIN_PACKETS, 1000) |
+@@ -800,6 +801,11 @@ int mtk_ppe_start(struct mtk_ppe *ppe)
+
+ ppe_w32(ppe, MTK_PPE_DEFAULT_CPU_PORT, 0);
+
++#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++ ppe_w32(ppe, MTK_PPE_DEFAULT_CPU_PORT1, 0xcb777);
++ ppe_w32(ppe, MTK_PPE_SBW_CTRL, 0x7f);
++#endif
++
+ return 0;
+ }
+
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
+index 1f5cf1c9a..a76f4b0ac 100644
+--- a/drivers/net/ethernet/mediatek/mtk_ppe.h
++++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
+@@ -8,7 +8,11 @@
+ #include <linux/bitfield.h>
+ #include <linux/rhashtable.h>
+
++#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++#define MTK_ETH_PPE_BASE 0x2000
++#else
+ #define MTK_ETH_PPE_BASE 0xc00
++#endif
+
+ #define MTK_PPE_ENTRIES_SHIFT 3
+ #define MTK_PPE_ENTRIES (1024 << MTK_PPE_ENTRIES_SHIFT)
+@@ -16,20 +16,40 @@
+ #define MTK_PPE_WAIT_TIMEOUT_US 1000000
+
+ #define MTK_FOE_IB1_UNBIND_TIMESTAMP GENMASK(7, 0)
++#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++#define MTK_FOE_IB1_UNBIND_SRC_PORT GENMASK(11, 8)
++#define MTK_FOE_IB1_UNBIND_PACKETS GENMASK(19, 12)
++#define MTK_FOE_IB1_UNBIND_PREBIND BIT(22)
++#define MTK_FOE_IB1_UNBIND_PACKET_TYPE GENMASK(27, 23)
++#define MTK_FOE_IB1_BIND_TIMESTAMP GENMASK(7, 0)
++#define MTK_FOE_IB1_BIND_SRC_PORT GENMASK(11, 8)
++#define MTK_FOE_IB1_BIND_MC BIT(12)
++#define MTK_FOE_IB1_BIND_KEEPALIVE BIT(13)
++#define MTK_FOE_IB1_BIND_VLAN_LAYER GENMASK(16, 14)
++#define MTK_FOE_IB1_BIND_PPPOE BIT(17)
++#define MTK_FOE_IB1_BIND_VLAN_TAG BIT(18)
++#define MTK_FOE_IB1_BIND_PKT_SAMPLE BIT(19)
++#define MTK_FOE_IB1_BIND_CACHE BIT(20)
++#define MTK_FOE_IB1_BIND_TUNNEL_DECAP BIT(21)
++#define MTK_FOE_IB1_BIND_TTL BIT(22)
++#define MTK_FOE_IB1_PACKET_TYPE GENMASK(27, 23)
++#else
+ #define MTK_FOE_IB1_UNBIND_PACKETS GENMASK(23, 8)
+ #define MTK_FOE_IB1_UNBIND_PREBIND BIT(24)
+
+ #define MTK_FOE_IB1_BIND_TIMESTAMP GENMASK(14, 0)
+ #define MTK_FOE_IB1_BIND_KEEPALIVE BIT(15)
+ #define MTK_FOE_IB1_BIND_VLAN_LAYER GENMASK(18, 16)
+ #define MTK_FOE_IB1_BIND_PPPOE BIT(19)
+ #define MTK_FOE_IB1_BIND_VLAN_TAG BIT(20)
+ #define MTK_FOE_IB1_BIND_PKT_SAMPLE BIT(21)
+ #define MTK_FOE_IB1_BIND_CACHE BIT(22)
+ #define MTK_FOE_IB1_BIND_TUNNEL_DECAP BIT(23)
+ #define MTK_FOE_IB1_BIND_TTL BIT(24)
+
+ #define MTK_FOE_IB1_PACKET_TYPE GENMASK(27, 25)
++#endif
++
+ #define MTK_FOE_IB1_STATE GENMASK(29, 28)
+ #define MTK_FOE_IB1_UDP BIT(30)
+ #define MTK_FOE_IB1_STATIC BIT(31)
+@@ -44,24 +47,42 @@ enum {
+ MTK_PPE_PKT_TYPE_IPV6_6RD = 7,
+ };
+
++#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++#define MTK_FOE_IB2_QID GENMASK(6, 0)
++#define MTK_FOE_IB2_PORT_MG BIT(7)
++#define MTK_FOE_IB2_PSE_QOS BIT(8)
++#define MTK_FOE_IB2_DEST_PORT GENMASK(12, 9)
++#define MTK_FOE_IB2_MULTICAST BIT(13)
++#define MTK_FOE_IB2_MIB_CNT BIT(15)
++#define MTK_FOE_IB2_RX_IDX GENMASK(18, 17)
++#define MTK_FOE_IB2_WDMA_WINFO BIT(19)
++#define MTK_FOE_IB2_PORT_AG GENMASK(23, 20)
++#else
+ #define MTK_FOE_IB2_QID GENMASK(3, 0)
+ #define MTK_FOE_IB2_PSE_QOS BIT(4)
+ #define MTK_FOE_IB2_DEST_PORT GENMASK(7, 5)
+ #define MTK_FOE_IB2_MULTICAST BIT(8)
+
+ #define MTK_FOE_IB2_WDMA_QID2 GENMASK(13, 12)
++#define MTK_FOE_IB2_MIB_CNT BIT(15)
+ #define MTK_FOE_IB2_WDMA_DEVIDX BIT(16)
+ #define MTK_FOE_IB2_WDMA_WINFO BIT(17)
+
+ #define MTK_FOE_IB2_PORT_MG GENMASK(17, 12)
+
+ #define MTK_FOE_IB2_PORT_AG GENMASK(23, 18)
++#endif
+
+ #define MTK_FOE_IB2_DSCP GENMASK(31, 24)
+
++#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++#define MTK_FOE_WINFO_BSS GENMASK(5, 0)
++#define MTK_FOE_WINFO_WCID GENMASK(15, 6)
++#else
+ #define MTK_FOE_VLAN2_WINFO_BSS GENMASK(5, 0)
+ #define MTK_FOE_VLAN2_WINFO_WCID GENMASK(13, 6)
+ #define MTK_FOE_VLAN2_WINFO_RING GENMASK(15, 14)
++#endif
+
+ enum {
+ MTK_FOE_STATE_INVALID,
+@@ -83,6 +81,11 @@ struct mtk_foe_mac_info {
+
+ u16 pppoe_id;
+ u16 src_mac_lo;
++
++#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++ u16 minfo;
++ u16 winfo;
++#endif
+ };
+
+ /* software-only entry type */
+@@ -200,7 +205,11 @@ struct mtk_foe_entry {
+ struct mtk_foe_ipv4_dslite dslite;
+ struct mtk_foe_ipv6 ipv6;
+ struct mtk_foe_ipv6_6rd ipv6_6rd;
++#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++ u32 data[23];
++#else
+ u32 data[19];
++#endif
+ };
+ };
+
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
+index d4a012608..5a4201447 100644
+--- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
++++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
+@@ -192,7 +192,15 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
+ if (mtk_flow_get_wdma_info(dev, dest_mac, &info) == 0) {
+ mtk_foe_entry_set_wdma(foe, info.wdma_idx, info.queue, info.bss,
+ info.wcid);
+ pse_port = PSE_PPE0_PORT;
++#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++ if (info.wdma_idx == 0)
++ pse_port = PSE_WDMA0_PORT;
++ else if (info.wdma_idx == 1)
++ pse_port = PSE_WDMA1_PORT;
++ else
++ return -EOPNOTSUPP;
++#endif
+ *wed_index = info.wdma_idx;
+ goto out;
+ }
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_regs.h b/drivers/net/ethernet/mediatek/mtk_ppe_regs.h
+index 0c45ea090..d319f1861 100644
+--- a/drivers/net/ethernet/mediatek/mtk_ppe_regs.h
++++ b/drivers/net/ethernet/mediatek/mtk_ppe_regs.h
+@@ -21,6 +21,9 @@
+ #define MTK_PPE_GLO_CFG_BUSY BIT(31)
+
+ #define MTK_PPE_FLOW_CFG 0x204
++#define MTK_PPE_MD_TOAP_BYP_CRSN0 BIT(1)
++#define MTK_PPE_MD_TOAP_BYP_CRSN1 BIT(2)
++#define MTK_PPE_MD_TOAP_BYP_CRSN2 BIT(3)
+ #define MTK_PPE_FLOW_CFG_IP4_TCP_FRAG BIT(6)
+ #define MTK_PPE_FLOW_CFG_IP4_UDP_FRAG BIT(7)
+ #define MTK_PPE_FLOW_CFG_IP6_3T_ROUTE BIT(8)
+@@ -35,6 +38,8 @@
+ #define MTK_PPE_FLOW_CFG_IP4_HASH_FLOW_LABEL BIT(18)
+ #define MTK_PPE_FLOW_CFG_IP4_HASH_GRE_KEY BIT(19)
+ #define MTK_PPE_FLOW_CFG_IP6_HASH_GRE_KEY BIT(20)
++#define MTK_PPE_FLOW_CFG_IPV4_MAPE_EN BIT(21)
++#define MTK_PPE_FLOW_CFG_IPV4_MAPT_EN BIT(22)
+
+ #define MTK_PPE_IP_PROTO_CHK 0x208
+ #define MTK_PPE_IP_PROTO_CHK_IPV4 GENMASK(15, 0)
+@@ -54,6 +59,7 @@
+ #define MTK_PPE_TB_CFG_HASH_MODE GENMASK(15, 14)
+ #define MTK_PPE_TB_CFG_SCAN_MODE GENMASK(17, 16)
+ #define MTK_PPE_TB_CFG_HASH_DEBUG GENMASK(19, 18)
++#define MTK_PPE_TB_CFG_INFO_SEL BIT(20)
+
+ enum {
+ MTK_PPE_SCAN_MODE_DISABLED,
+@@ -111,6 +117,8 @@ enum {
+
+ #define MTK_PPE_DEFAULT_CPU_PORT 0x248
+ #define MTK_PPE_DEFAULT_CPU_PORT_MASK(_n) (GENMASK(2, 0) << ((_n) * 4))
++#define MTK_PPE_DEFAULT_CPU_PORT1 0x24C
++#define MTK_PPE_DEFAULT_CPU_PORT_MASK(_n) (GENMASK(2, 0) << ((_n) * 4))
+
+ #define MTK_PPE_MTU_DROP 0x308
+
+@@ -141,4 +149,6 @@ enum {
+ #define MTK_PPE_MIB_CACHE_CTL_EN BIT(0)
+ #define MTK_PPE_MIB_CACHE_CTL_FLUSH BIT(2)
+
++#define MTK_PPE_SBW_CTRL 0x374
++
+ #endif
+--
+2.18.0
+
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3007-flow-offload-add-mkhnat-dual-ppe-new-v2.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3007-flow-offload-add-mkhnat-dual-ppe-new-v2.patch
new file mode 100755
index 0000000..954c6e2
--- /dev/null
+++ b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3007-flow-offload-add-mkhnat-dual-ppe-new-v2.patch
@@ -0,0 +1,485 @@
+From a59cb5c770a694cb34ab179ec59e91ba5c39908b Mon Sep 17 00:00:00 2001
+From: Bo Jiao <Bo.Jiao@mediatek.com>
+Date: Mon, 27 Jun 2022 14:48:35 +0800
+Subject: [PATCH 6/8] 9995-flow-offload-add-mkhnat-dual-ppe-new-v2
+
+---
+ arch/arm64/boot/dts/mediatek/mt7986a.dtsi | 1 +
+ drivers/net/ethernet/mediatek/mtk_eth_soc.c | 67 ++++++++++++++-----
+ drivers/net/ethernet/mediatek/mtk_eth_soc.h | 10 ++-
+ drivers/net/ethernet/mediatek/mtk_ppe.c | 5 +-
+ drivers/net/ethernet/mediatek/mtk_ppe.h | 7 +-
+ .../net/ethernet/mediatek/mtk_ppe_debugfs.c | 27 ++++++--
+ .../net/ethernet/mediatek/mtk_ppe_offload.c | 45 ++++++++++---
+ include/linux/netdevice.h | 4 ++
+ 8 files changed, 125 insertions(+), 41 deletions(-)
+ mode change 100644 => 100755 drivers/net/ethernet/mediatek/mtk_ppe_offload.c
+
+diff --git a/arch/arm64/boot/dts/mediatek/mt7986a.dtsi b/arch/arm64/boot/dts/mediatek/mt7986a.dtsi
+index 7f78de6b9..381136c21 100644
+--- a/arch/arm64/boot/dts/mediatek/mt7986a.dtsi
++++ b/arch/arm64/boot/dts/mediatek/mt7986a.dtsi
+@@ -479,6 +479,7 @@
+ mediatek,ethsys = <ðsys>;
+ mediatek,sgmiisys = <&sgmiisys0>, <&sgmiisys1>;
+ mediatek,wed = <&wed0>, <&wed1>;
++ mtketh-ppe-num = <2>;
+ #reset-cells = <1>;
+ #address-cells = <1>;
+ #size-cells = <0>;
+diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+index 01fc1e5c0..3f67bebfe 100644
+--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
++++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+@@ -1732,6 +1732,7 @@ static int mtk_poll_rx(struct napi_struc
+ u8 *data, *new_data;
+ struct mtk_rx_dma_v2 *rxd, trxd;
+ int done = 0;
++ int i;
+
+ if (unlikely(!ring))
+ goto rx_done;
+@@ -1843,14 +1844,20 @@ static int mtk_poll_rx(struct napi_struc
+
+ #if defined(CONFIG_MEDIATEK_NETSYS_RX_V2)
+ reason = FIELD_GET(MTK_RXD5_PPE_CPU_REASON_V2, trxd.rxd5);
+- if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED)
+- mtk_ppe_check_skb(eth->ppe, skb,
+- trxd.rxd5 & MTK_RXD5_FOE_ENTRY_V2);
++ if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED) {
++ for (i = 0; i < eth->ppe_num; i++) {
++ mtk_ppe_check_skb(eth->ppe[i], skb,
++ trxd.rxd5 & MTK_RXD5_FOE_ENTRY_V2);
++ }
++ }
+ #else
+ reason = FIELD_GET(MTK_RXD4_PPE_CPU_REASON, trxd.rxd4);
+- if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED)
+- mtk_ppe_check_skb(eth->ppe, skb,
+- trxd.rxd4 & MTK_RXD4_FOE_ENTRY);
++ if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED) {
++ for (i = 0; i < eth->ppe_num; i++) {
++ mtk_ppe_check_skb(eth->ppe[i], skb,
++ trxd.rxd4 & MTK_RXD4_FOE_ENTRY);
++ }
++ }
+ #endif
+
+ if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) {
+@@ -3184,8 +3191,12 @@ static int mtk_open(struct net_device *d
+ if (!phy_node && eth->xgmii->regmap_sgmii[mac->id])
+ regmap_write(eth->xgmii->regmap_sgmii[mac->id], SGMSYS_QPHY_PWR_STATE_CTRL, 0);
+
+- if (eth->soc->offload_version && mtk_ppe_start(ð->ppe) == 0)
+- gdm_config = MTK_GDMA_TO_PPE;
++ if (eth->soc->offload_version) {
++ gdm_config = MTK_GDMA_TO_PPE0;
++
++ for (i = 0; i < eth->ppe_num; i++)
++ mtk_ppe_start(eth->ppe[i]);
++ }
+
+ mtk_gdm_config(eth, mac->id, gdm_config);
+
+@@ -3268,8 +3279,10 @@ static int mtk_stop(struct net_device *d
+
+ mtk_dma_free(eth);
+
+- if (eth->soc->offload_version)
+- mtk_ppe_stop(eth->ppe);
++ if (eth->soc->offload_version) {
++ for (i = 0; i < eth->ppe_num; i++)
++ mtk_ppe_stop(eth->ppe[i]);
++ }
+
+ return 0;
+ }
+@@ -4408,15 +4421,35 @@ static int mtk_probe(struct platform_dev
+ }
+
+ if (eth->soc->offload_version) {
+- eth->ppe = mtk_ppe_init(eth, eth->base + MTK_ETH_PPE_BASE, 2);
+- if (!eth->ppe) {
+- err = -ENOMEM;
+- goto err_free_dev;
++ unsigned int val;
++
++ err = of_property_read_u32_index(pdev->dev.of_node, "mtketh-ppe-num", 0, &val);
++ if (err < 0)
++ eth->ppe_num = 1;
++ else
++ eth->ppe_num = val;
++
++ if (eth->ppe_num > MTK_MAX_PPE_NUM) {
++ dev_warn(&pdev->dev, "%d is not a valid ppe num, please check mtketh-ppe-num in dts !", eth->ppe_num);
++ eth->ppe_num = MTK_MAX_PPE_NUM;
+ }
+
+- err = mtk_eth_offload_init(eth);
+- if (err)
+- goto err_free_dev;
++ dev_info(&pdev->dev, "ppe num = %d\n", eth->ppe_num);
++
++ for (i = 0; i < eth->ppe_num; i++) {
++ eth->ppe[i] = mtk_ppe_init(eth,
++ eth->base + MTK_ETH_PPE_BASE + i * 0x400, 2, i);
++ if (!eth->ppe[i]) {
++ err = -ENOMEM;
++ goto err_free_dev;
++ }
++
++ err = mtk_eth_offload_init(eth, i);
++ if (err)
++ goto err_free_dev;
++ }
++
++ mtk_ppe_debugfs_init(eth);
+ }
+
+ 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 fce1a7172..b4de7c0c6 100644
+--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
++++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
+@@ -118,7 +118,12 @@
+ #define MTK_GDMA_UCS_EN BIT(20)
+ #define MTK_GDMA_STRP_CRC BIT(16)
+ #define MTK_GDMA_TO_PDMA 0x0
+-#define MTK_GDMA_TO_PPE 0x3333
++#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++#define MTK_GDMA_TO_PPE0 0x3333
++#define MTK_GDMA_TO_PPE1 0x4444
++#else
++#define MTK_GDMA_TO_PPE0 0x4444
++#endif
+ #define MTK_GDMA_DROP_ALL 0x7777
+
+ /* GDM Egress Control Register */
+@@ -1612,7 +1617,8 @@ struct mtk_eth {
+ spinlock_t syscfg0_lock;
+ struct timer_list mtk_dma_monitor_timer;
+
+- struct mtk_ppe *ppe;
++ u8 ppe_num;
++ struct mtk_ppe *ppe[MTK_MAX_PPE_NUM];
+ struct rhashtable flow_table;
+ };
+
+@@ -1668,9 +1674,11 @@ int mtk_gmac_usxgmii_path_setup(struct m
+ void mtk_usxgmii_reset(struct mtk_xgmii *ss, int mac_id);
+ int mtk_dump_usxgmii(struct regmap *pmap, char *name, u32 offset, u32 range);
+
+-int mtk_eth_offload_init(struct mtk_eth *eth);
++int mtk_eth_offload_init(struct mtk_eth *eth, int id);
+ int mtk_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,
+ void *type_data);
+ void mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev);
+ int mtk_rss_set_indr_tbl(struct mtk_eth *eth, int num);
++
++int mtk_ppe_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 d46e91178..3d6ff30ba 100755
+--- a/drivers/net/ethernet/mediatek/mtk_ppe.c
++++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
+@@ -677,7 +677,7 @@ int mtk_foe_entry_idle_time(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
+ }
+
+ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
+- int version)
++ int version, int id)
+ {
+ struct device *dev = eth->dev;
+ struct mtk_foe_entry *foe;
+@@ -696,6 +696,7 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
+ ppe->eth = eth;
+ ppe->dev = dev;
+ ppe->version = version;
++ ppe->id = id;
+
+ foe = dmam_alloc_coherent(ppe->dev, MTK_PPE_ENTRIES * sizeof(*foe),
+ &ppe->foe_phys, GFP_KERNEL);
+@@ -704,8 +705,6 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
+
+ ppe->foe_table = foe;
+
+- mtk_ppe_debugfs_init(ppe);
+-
+ return ppe;
+ }
+
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
+index a76f4b0ac..21cc55145 100644
+--- a/drivers/net/ethernet/mediatek/mtk_ppe.h
++++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
+@@ -8,10 +8,12 @@
+ #include <linux/bitfield.h>
+ #include <linux/rhashtable.h>
+
+ #if defined(CONFIG_MEDIATEK_NETSYS_V2)
++#define MTK_MAX_PPE_NUM 2
+ #define MTK_ETH_PPE_BASE 0x2000
+ #else
++#define MTK_MAX_PPE_NUM 1
+ #define MTK_ETH_PPE_BASE 0xc00
+ #endif
+
+ #define MTK_PPE_ENTRIES_SHIFT 3
+@@ -253,6 +255,7 @@ struct mtk_flow_entry {
+ };
+ };
+ u8 type;
++ s8 ppe_index;
+ s8 wed_index;
+ u16 hash;
+ union {
+@@ -272,6 +275,7 @@ struct mtk_ppe {
+ struct device *dev;
+ void __iomem *base;
+ int version;
++ int id;
+
+ struct mtk_foe_entry *foe_table;
+ dma_addr_t foe_phys;
+@@ -284,7 +288,7 @@ struct mtk_ppe {
+ void *acct_table;
+ };
+
+-struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int version);
++struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int version, int id);
+ int mtk_ppe_start(struct mtk_ppe *ppe);
+ int mtk_ppe_stop(struct mtk_ppe *ppe);
+
+@@ -335,6 +339,5 @@ int mtk_foe_entry_set_wdma(struct mtk_foe_entry *entry, int wdma_idx, int txq,
+ 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);
+-int mtk_ppe_debugfs_init(struct mtk_ppe *ppe);
+
+ #endif
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c b/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
+index a591ab1fd..f4ebe5944 100644
+--- a/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
++++ b/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
+@@ -73,9 +73,8 @@ mtk_print_addr_info(struct seq_file *m, struct mtk_flow_addr_info *ai)
+ }
+
+ static int
+-mtk_ppe_debugfs_foe_show(struct seq_file *m, void *private, bool bind)
++mtk_ppe_debugfs_foe_show(struct seq_file *m, struct mtk_ppe *ppe, bool bind)
+ {
+- struct mtk_ppe *ppe = m->private;
+ int i;
+
+ for (i = 0; i < MTK_PPE_ENTRIES; i++) {
+@@ -122,6 +121,8 @@ mtk_ppe_debugfs_foe_show(struct seq_file *m, void *private, bool bind)
+ break;
+ }
+
++ seq_printf(m, " ppe=%d", ppe->id);
++
+ seq_printf(m, " orig=");
+ mtk_print_addr_info(m, &ai);
+
+@@ -164,13 +165,25 @@ mtk_ppe_debugfs_foe_show(struct seq_file *m, void *private, bool bind)
+ static int
+ mtk_ppe_debugfs_foe_show_all(struct seq_file *m, void *private)
+ {
+- return mtk_ppe_debugfs_foe_show(m, private, false);
++ struct mtk_eth *eth = m->private;
++ int i;
++
++ for (i = 0; i < eth->ppe_num; i++)
++ mtk_ppe_debugfs_foe_show(m, eth->ppe[i], false);
++
++ return 0;
+ }
+
+ static int
+ mtk_ppe_debugfs_foe_show_bind(struct seq_file *m, void *private)
+ {
+- return mtk_ppe_debugfs_foe_show(m, private, true);
++ struct mtk_eth *eth = m->private;
++ int i;
++
++ for (i = 0; i < eth->ppe_num; i++)
++ mtk_ppe_debugfs_foe_show(m, eth->ppe[i], true);
++
++ return 0;
+ }
+
+ static int
+@@ -187,7 +200,7 @@ mtk_ppe_debugfs_foe_open_bind(struct inode *inode, struct file *file)
+ inode->i_private);
+ }
+
+-int mtk_ppe_debugfs_init(struct mtk_ppe *ppe)
++int mtk_ppe_debugfs_init(struct mtk_eth *eth)
+ {
+ static const struct file_operations fops_all = {
+ .open = mtk_ppe_debugfs_foe_open_all,
+@@ -209,8 +222,8 @@ int mtk_ppe_debugfs_init(struct mtk_ppe *ppe)
+ if (!root)
+ return -ENOMEM;
+
+- debugfs_create_file("entries", S_IRUGO, root, ppe, &fops_all);
+- debugfs_create_file("bind", S_IRUGO, root, ppe, &fops_bind);
++ debugfs_create_file("entries", S_IRUGO, root, eth, &fops_all);
++ debugfs_create_file("bind", S_IRUGO, root, eth, &fops_bind);
+
+ return 0;
+ }
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
+old mode 100644
+new mode 100755
+index 5a4201447..2f7d76d3b
+--- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
++++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
+@@ -226,8 +226,10 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
+ struct flow_action_entry *act;
+ struct mtk_flow_data data = {};
+ struct mtk_foe_entry foe;
+- struct net_device *odev = NULL;
++ struct net_device *idev = NULL, *odev = NULL;
+ struct mtk_flow_entry *entry;
++ struct net_device_path_ctx ctx = {};
++ struct net_device_path path = {};
+ int offload_type = 0;
+ int wed_index = -1;
+ u16 addr_type = 0;
+@@ -242,6 +244,10 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
+ struct flow_match_meta match;
+
+ flow_rule_match_meta(rule, &match);
++ idev = __dev_get_by_index(&init_net, match.key->ingress_ifindex);
++
++ if (!idev)
++ pr_info("[%s] idev doesn't exist !\n", __func__);
+ } else {
+ return -EOPNOTSUPP;
+ }
+@@ -435,11 +441,27 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
+ if (!entry)
+ return -ENOMEM;
+
++ i = 0;
++#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++ if (idev && idev->netdev_ops->ndo_fill_receive_path) {
++ ctx.dev = idev;
++ idev->netdev_ops->ndo_fill_receive_path(&ctx, &path);
++ i = path.mtk_wdma.wdma_idx;
++ if (i >= eth->ppe_num) {
++ if (printk_ratelimit())
++ pr_info("[%s] PPE%d doesn't exist, please check mtketh-ppe-num in dts !\n", __func__, i);
++
++ return -EINVAL;
++ }
++ }
++#endif
++
+ entry->cookie = f->cookie;
+ memcpy(&entry->data, &foe, sizeof(entry->data));
++ entry->ppe_index = i;
+ entry->wed_index = wed_index;
+
+- if (mtk_foe_entry_commit(eth->ppe, entry) < 0)
++ if (mtk_foe_entry_commit(eth->ppe[i], entry) < 0)
+ goto free;
+
+ err = rhashtable_insert_fast(ð->flow_table, &entry->node,
+@@ -450,7 +470,7 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
+ return 0;
+
+ clear:
+- mtk_foe_entry_clear(eth->ppe, entry);
++ mtk_foe_entry_clear(eth->ppe[i], entry);
+ free:
+ kfree(entry);
+ if (wed_index >= 0)
+@@ -462,13 +482,15 @@ static int
+ mtk_flow_offload_destroy(struct mtk_eth *eth, struct flow_cls_offload *f)
+ {
+ struct mtk_flow_entry *entry;
++ int i;
+
+ entry = rhashtable_lookup(ð->flow_table, &f->cookie,
+ mtk_flow_ht_params);
+ if (!entry)
+ return -ENOENT;
+
+- mtk_foe_entry_clear(eth->ppe, entry);
++ i = entry->ppe_index;
++ mtk_foe_entry_clear(eth->ppe[i], entry);
+ rhashtable_remove_fast(ð->flow_table, &entry->node,
+ mtk_flow_ht_params);
+ if (entry->wed_index >= 0)
+@@ -483,13 +505,15 @@ mtk_flow_offload_stats(struct mtk_eth *eth, struct flow_cls_offload *f)
+ {
+ struct mtk_flow_entry *entry;
+ u32 idle;
++ int i;
+
+ entry = rhashtable_lookup(ð->flow_table, &f->cookie,
+ mtk_flow_ht_params);
+ if (!entry)
+ return -ENOENT;
+
+- idle = mtk_foe_entry_idle_time(eth->ppe, entry);
++ i = entry->ppe_index;
++ idle = mtk_foe_entry_idle_time(eth->ppe[i], entry);
+ f->stats.lastused = jiffies - idle * HZ;
+
+ return 0;
+@@ -540,10 +564,12 @@ mtk_eth_setup_tc_block(struct net_device *dev, struct flow_block_offload *f)
+ static LIST_HEAD(block_cb_list);
+ struct flow_block_cb *block_cb;
+ flow_setup_cb_t *cb;
+- int err = 0;
++ int i, err = 0;
+
+- if (!eth->ppe || !eth->ppe->foe_table)
+- return -EOPNOTSUPP;
++ for (i = 0; i < eth->ppe_num; i++) {
++ if (!eth->ppe[i] || !eth->ppe[i]->foe_table)
++ return -EOPNOTSUPP;
++ }
+
+ if (f->binder_type != FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
+ return -EOPNOTSUPP;
+@@ -591,9 +618,9 @@ int mtk_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,
+ }
+ }
+
+-int mtk_eth_offload_init(struct mtk_eth *eth)
++int mtk_eth_offload_init(struct mtk_eth *eth, int id)
+ {
+- if (!eth->ppe || !eth->ppe->foe_table)
++ if (!eth->ppe[id] || !eth->ppe[id]->foe_table)
+ return 0;
+
+ return rhashtable_init(ð->flow_table, &mtk_flow_ht_params);
+diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
+index 35998b1a7..0ada2461b 100644
+--- a/include/linux/netdevice.h
++++ b/include/linux/netdevice.h
+@@ -1302,6 +1302,8 @@ struct tlsdev_ops;
+ * rtnl_lock is not held.
+ * int (*ndo_fill_forward_path)(struct net_device_path_ctx *ctx, struct net_device_path *path);
+ * Get the forwarding path to reach the real device from the HW destination address
++ * int (*ndo_fill_receive_path)(struct net_device_path_ctx *ctx, struct net_device_path *path);
++ * Get the receiving path to reach the real device from the HW source address
+ */
+ struct net_device_ops {
+ int (*ndo_init)(struct net_device *dev);
+@@ -1501,6 +1503,8 @@ struct net_device_ops {
+ struct devlink_port * (*ndo_get_devlink_port)(struct net_device *dev);
+ int (*ndo_fill_forward_path)(struct net_device_path_ctx *ctx,
+ struct net_device_path *path);
++ int (*ndo_fill_receive_path)(struct net_device_path_ctx *ctx,
++ struct net_device_path *path);
+ };
+
+ /**
+--
+2.18.0
+
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3007-add-wed-tx-support-for-mt7986.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3008-add-wed-tx-support-for-mt7986.patch
similarity index 96%
rename from autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3007-add-wed-tx-support-for-mt7986.patch
rename to autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3008-add-wed-tx-support-for-mt7986.patch
index d033830..7734ce2 100755
--- a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3007-add-wed-tx-support-for-mt7986.patch
+++ b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3008-add-wed-tx-support-for-mt7986.patch
@@ -1,7 +1,7 @@
-From 36d42fbf4ade428d85b92b0a717887c6321fb7ca Mon Sep 17 00:00:00 2001
+From c6b43d63c3d4229b5f15cb7391192494b07e0fa7 Mon Sep 17 00:00:00 2001
From: Bo Jiao <Bo.Jiao@mediatek.com>
-Date: Tue, 13 Jun 2023 17:02:03 +0800
-Subject: [PATCH] 999-3007-add-wed-tx-support-for-mt7986
+Date: Mon, 27 Jun 2022 14:53:54 +0800
+Subject: [PATCH 7/8] 9996-add-wed-tx-support-for-mt7986
---
arch/arm64/boot/dts/mediatek/mt7986a.dtsi | 2 +
@@ -11,12 +11,12 @@
drivers/net/ethernet/mediatek/mtk_wed.c | 502 +++++++++++++-----
drivers/net/ethernet/mediatek/mtk_wed.h | 18 +-
.../net/ethernet/mediatek/mtk_wed_debugfs.c | 3 +
- drivers/net/ethernet/mediatek/mtk_wed_regs.h | 130 ++++-
- include/linux/soc/mediatek/mtk_wed.h | 23 +
- 9 files changed, 545 insertions(+), 148 deletions(-)
+ drivers/net/ethernet/mediatek/mtk_wed_regs.h | 127 ++++-
+ include/linux/soc/mediatek/mtk_wed.h | 29 +-
+ 9 files changed, 546 insertions(+), 150 deletions(-)
diff --git a/arch/arm64/boot/dts/mediatek/mt7986a.dtsi b/arch/arm64/boot/dts/mediatek/mt7986a.dtsi
-index 36de771..6fe3583 100644
+index 381136c21..644255b35 100644
--- a/arch/arm64/boot/dts/mediatek/mt7986a.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt7986a.dtsi
@@ -64,6 +64,7 @@
@@ -36,7 +36,7 @@
ap2woccif: ap2woccif@151A5000 {
diff --git a/arch/arm64/boot/dts/mediatek/mt7986b.dtsi b/arch/arm64/boot/dts/mediatek/mt7986b.dtsi
-index 7190874..de5bf0b 100644
+index 0e5f116a2..67bf86f6a 100644
--- a/arch/arm64/boot/dts/mediatek/mt7986b.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt7986b.dtsi
@@ -64,6 +64,7 @@
@@ -56,10 +56,10 @@
ap2woccif: ap2woccif@151A5000 {
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-index cfe1290..933c0bb 100644
+index 3f67bebfe..ac021e2ed 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -4636,6 +4636,7 @@ static int mtk_probe(struct platform_device *pdev)
+@@ -3579,6 +3579,7 @@ static int mtk_probe(struct platform_device *pdev)
{
struct device_node *mac_np;
struct mtk_eth *eth;
@@ -67,15 +67,15 @@
int err, i;
eth = devm_kzalloc(&pdev->dev, sizeof(*eth), GFP_KERNEL);
-@@ -4657,7 +4658,6 @@ static int mtk_probe(struct platform_device *pdev)
- }
+@@ -3594,7 +3595,6 @@ static int mtk_probe(struct platform_device *pdev)
+ return PTR_ERR(eth->base);
if(eth->soc->has_sram) {
- struct resource *res;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (unlikely(!res))
return -EINVAL;
-@@ -4758,12 +4758,16 @@ static int mtk_probe(struct platform_device *pdev)
+@@ -3682,12 +3682,16 @@ static int mtk_probe(struct platform_device *pdev)
MTK_WDMA1_BASE
};
void __iomem *wdma;
@@ -92,14 +92,14 @@
+ mtk_wed_add_hw(np, eth, wdma, wdma_phy, i);
}
- for (i = 0; i < MTK_PDMA_IRQ_NUM; i++)
+ for (i = 0; i < MTK_MAX_IRQ_NUM; i++) {
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-index c2c5037..1e9a1af 100644
+index b4de7c0c6..4a69bd0cf 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-@@ -565,8 +565,13 @@
+@@ -518,8 +518,13 @@
#define RX_DMA_SPORT_MASK 0x7
- #define RX_DMA_SPORT_MASK_V2 0xf
+ #endif
+#if defined(CONFIG_MEDIATEK_NETSYS_V2)
+#define MTK_WDMA0_BASE 0x4800
@@ -112,7 +112,7 @@
/* QDMA descriptor txd4 */
#define TX_DMA_CHKSUM (0x7 << 29)
diff --git a/drivers/net/ethernet/mediatek/mtk_wed.c b/drivers/net/ethernet/mediatek/mtk_wed.c
-index ea1cbdf..48b0353 100644
+index ea1cbdf1a..48b0353bb 100644
--- a/drivers/net/ethernet/mediatek/mtk_wed.c
+++ b/drivers/net/ethernet/mediatek/mtk_wed.c
@@ -18,15 +18,6 @@
@@ -199,7 +199,7 @@
desc->info = 0;
desc++;
-@@ -202,12 +206,12 @@ mtk_wed_free_buffer(struct mtk_wed_device *dev)
+@@ -202,12 +206,12 @@ free_pagelist:
}
static void
@@ -845,7 +845,7 @@
val = wed_r32(dev, MTK_WED_INT_STATUS);
val &= mask;
-@@ -780,7 +1007,8 @@ void mtk_wed_flow_remove(int index)
+@@ -780,7 +1007,8 @@ out:
}
void mtk_wed_add_hw(struct device_node *np, struct mtk_eth *eth,
@@ -895,7 +895,7 @@
hw_list[index] = hw;
diff --git a/drivers/net/ethernet/mediatek/mtk_wed.h b/drivers/net/ethernet/mediatek/mtk_wed.h
-index 981ec61..9b17b74 100644
+index 981ec613f..9b17b7405 100644
--- a/drivers/net/ethernet/mediatek/mtk_wed.h
+++ b/drivers/net/ethernet/mediatek/mtk_wed.h
@@ -8,6 +8,19 @@
@@ -944,7 +944,7 @@
}
static inline void
diff --git a/drivers/net/ethernet/mediatek/mtk_wed_debugfs.c b/drivers/net/ethernet/mediatek/mtk_wed_debugfs.c
-index a81d3fd..f420f18 100644
+index a81d3fd1a..f420f187e 100644
--- a/drivers/net/ethernet/mediatek/mtk_wed_debugfs.c
+++ b/drivers/net/ethernet/mediatek/mtk_wed_debugfs.c
@@ -116,6 +116,9 @@ wed_txinfo_show(struct seq_file *s, void *data)
@@ -958,7 +958,7 @@
struct mtk_wed_hw *hw = s->private;
struct mtk_wed_device *dev = hw->wed_dev;
diff --git a/drivers/net/ethernet/mediatek/mtk_wed_regs.h b/drivers/net/ethernet/mediatek/mtk_wed_regs.h
-index 0a0465e..a9b9e2a 100644
+index 0a0465ea5..69f136ed4 100644
--- a/drivers/net/ethernet/mediatek/mtk_wed_regs.h
+++ b/drivers/net/ethernet/mediatek/mtk_wed_regs.h
@@ -4,9 +4,15 @@
@@ -992,7 +992,7 @@
#define MTK_WED_RESET 0x008
#define MTK_WED_RESET_TX_BM BIT(0)
#define MTK_WED_RESET_TX_FREE_AGENT BIT(4)
-@@ -41,6 +55,7 @@ struct mtk_wdma_desc {
+@@ -41,6 +51,7 @@ struct mtk_wdma_desc {
#define MTK_WED_CTRL_RESERVE_EN BIT(12)
#define MTK_WED_CTRL_RESERVE_BUSY BIT(13)
#define MTK_WED_CTRL_FINAL_DIDX_READ BIT(24)
@@ -1000,7 +1000,7 @@
#define MTK_WED_CTRL_MIB_READ_CLEAR BIT(28)
#define MTK_WED_EXT_INT_STATUS 0x020
-@@ -49,6 +64,10 @@ struct mtk_wdma_desc {
+@@ -49,6 +60,10 @@ struct mtk_wdma_desc {
#define MTK_WED_EXT_INT_STATUS_TKID_TITO_INVALID BIT(4)
#define MTK_WED_EXT_INT_STATUS_TX_FBUF_LO_TH BIT(8)
#define MTK_WED_EXT_INT_STATUS_TX_FBUF_HI_TH BIT(9)
@@ -1011,7 +1011,7 @@
#define MTK_WED_EXT_INT_STATUS_RX_FBUF_LO_TH BIT(12)
#define MTK_WED_EXT_INT_STATUS_RX_FBUF_HI_TH BIT(13)
#define MTK_WED_EXT_INT_STATUS_RX_DRV_R_RESP_ERR BIT(16)
-@@ -57,16 +76,23 @@ struct mtk_wdma_desc {
+@@ -57,16 +71,23 @@ struct mtk_wdma_desc {
#define MTK_WED_EXT_INT_STATUS_RX_DRV_INIT_WDMA_EN BIT(19)
#define MTK_WED_EXT_INT_STATUS_RX_DRV_BM_DMAD_COHERENT BIT(20)
#define MTK_WED_EXT_INT_STATUS_TX_DRV_R_RESP_ERR BIT(21)
@@ -1038,7 +1038,7 @@
#define MTK_WED_EXT_INT_MASK 0x028
-@@ -80,10 +106,6 @@ struct mtk_wdma_desc {
+@@ -80,10 +103,6 @@ struct mtk_wdma_desc {
#define MTK_WED_TX_BM_BASE 0x084
@@ -1049,7 +1049,7 @@
#define MTK_WED_TX_BM_BUF_LEN 0x08c
#define MTK_WED_TX_BM_INTF 0x09c
-@@ -93,9 +115,38 @@ struct mtk_wdma_desc {
+@@ -93,9 +112,38 @@ struct mtk_wdma_desc {
#define MTK_WED_TX_BM_INTF_TKID_READ BIT(29)
#define MTK_WED_TX_BM_DYN_THR 0x0a0
@@ -1088,7 +1088,7 @@
#define MTK_WED_INT_STATUS 0x200
#define MTK_WED_INT_MASK 0x204
-@@ -125,6 +176,7 @@ struct mtk_wdma_desc {
+@@ -125,6 +173,7 @@ struct mtk_wdma_desc {
#define MTK_WED_RESET_IDX_RX GENMASK(17, 16)
#define MTK_WED_TX_MIB(_n) (0x2a0 + (_n) * 4)
@@ -1096,7 +1096,7 @@
#define MTK_WED_RING_TX(_n) (0x300 + (_n) * 0x10)
-@@ -139,6 +191,19 @@ struct mtk_wdma_desc {
+@@ -139,6 +188,19 @@ struct mtk_wdma_desc {
#define MTK_WED_WPDMA_GLO_CFG_TX_DRV_BUSY BIT(1)
#define MTK_WED_WPDMA_GLO_CFG_RX_DRV_EN BIT(2)
#define MTK_WED_WPDMA_GLO_CFG_RX_DRV_BUSY BIT(3)
@@ -1116,7 +1116,7 @@
#define MTK_WED_WPDMA_GLO_CFG_RX_BT_SIZE GENMASK(5, 4)
#define MTK_WED_WPDMA_GLO_CFG_TX_WB_DDONE BIT(6)
#define MTK_WED_WPDMA_GLO_CFG_BIG_ENDIAN BIT(7)
-@@ -152,24 +217,54 @@ struct mtk_wdma_desc {
+@@ -152,24 +214,54 @@ struct mtk_wdma_desc {
#define MTK_WED_WPDMA_GLO_CFG_FIRST_TOKEN_ONLY BIT(26)
#define MTK_WED_WPDMA_GLO_CFG_OMIT_RX_INFO BIT(27)
#define MTK_WED_WPDMA_GLO_CFG_OMIT_TX_INFO BIT(28)
@@ -1172,7 +1172,7 @@
#define MTK_WED_WPDMA_TX_MIB(_n) (0x5a0 + (_n) * 4)
#define MTK_WED_WPDMA_TX_COHERENT_MIB(_n) (0x5d0 + (_n) * 4)
-@@ -203,14 +298,22 @@ struct mtk_wdma_desc {
+@@ -203,14 +295,22 @@ struct mtk_wdma_desc {
#define MTK_WED_WDMA_RESET_IDX_RX GENMASK(17, 16)
#define MTK_WED_WDMA_RESET_IDX_DRV GENMASK(25, 24)
@@ -1196,7 +1196,7 @@
#define MTK_WED_WDMA_RX_MIB(_n) (0xae0 + (_n) * 4)
#define MTK_WED_WDMA_RX_RECYCLE_MIB(_n) (0xae8 + (_n) * 4)
-@@ -221,14 +324,21 @@ struct mtk_wdma_desc {
+@@ -221,14 +321,21 @@ struct mtk_wdma_desc {
#define MTK_WED_RING_OFS_CPU_IDX 0x08
#define MTK_WED_RING_OFS_DMA_IDX 0x0c
@@ -1220,7 +1220,7 @@
#define MTK_WDMA_INT_MASK 0x228
#define MTK_WDMA_INT_MASK_TX_DONE GENMASK(3, 0)
diff --git a/include/linux/soc/mediatek/mtk_wed.h b/include/linux/soc/mediatek/mtk_wed.h
-index 7e00cca..ffd547a 100644
+index 7e00cca06..24742604b 100644
--- a/include/linux/soc/mediatek/mtk_wed.h
+++ b/include/linux/soc/mediatek/mtk_wed.h
@@ -8,6 +8,19 @@
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3008-add-wed-tx-wds-support-for-mt7986.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3009-add-wed-tx-wds-support-for-mt7986.patch
similarity index 89%
rename from autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3008-add-wed-tx-wds-support-for-mt7986.patch
rename to autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3009-add-wed-tx-wds-support-for-mt7986.patch
index 8183449..d17f43d 100755
--- a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3008-add-wed-tx-wds-support-for-mt7986.patch
+++ b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3009-add-wed-tx-wds-support-for-mt7986.patch
@@ -1,8 +1,9 @@
-From 0c163946c6bdabf89c0e121b6020432f9ccd6678 Mon Sep 17 00:00:00 2001
+From 3bddc232ca043699e893d279a3ec1f72ff6b9fae Mon Sep 17 00:00:00 2001
From: Sujuan Chen <sujuan.chen@mediatek.com>
-Date: Tue, 13 Jun 2023 17:03:12 +0800
-Subject: [PATCH] 999-3008-add-wed-tx-wds-support-for-mt7986
+Date: Sat, 10 Sep 2022 15:42:32 +0800
+Subject: [PATCH] 9996-add-wed-tx-wds-support-on-panther
+Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com>
---
drivers/net/ethernet/mediatek/mtk_wed.c | 8 +++++++-
drivers/net/ethernet/mediatek/mtk_wed_regs.h | 1 +
@@ -10,7 +11,7 @@
3 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/mediatek/mtk_wed.c b/drivers/net/ethernet/mediatek/mtk_wed.c
-index 48b0353..8b3a7eb 100644
+index 48b0353..472726e 100644
--- a/drivers/net/ethernet/mediatek/mtk_wed.c
+++ b/drivers/net/ethernet/mediatek/mtk_wed.c
@@ -797,7 +797,7 @@ mtk_wed_start(struct mtk_wed_device *dev, u32 irq_mask)
@@ -43,7 +44,7 @@
ret = mtk_wed_buffer_alloc(dev);
if (ret) {
diff --git a/drivers/net/ethernet/mediatek/mtk_wed_regs.h b/drivers/net/ethernet/mediatek/mtk_wed_regs.h
-index a9b9e2a..14e0e21 100644
+index e107de7..b189761 100644
--- a/drivers/net/ethernet/mediatek/mtk_wed_regs.h
+++ b/drivers/net/ethernet/mediatek/mtk_wed_regs.h
@@ -31,6 +31,7 @@ struct mtk_wdma_desc {
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3009-add-wed-rx-support-for-mt7896.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3010-add-wed-rx-support-for-mt7896.patch
similarity index 99%
rename from autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3009-add-wed-rx-support-for-mt7896.patch
rename to autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3010-add-wed-rx-support-for-mt7896.patch
index 7114425..053a4da 100755
--- a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3009-add-wed-rx-support-for-mt7896.patch
+++ b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3010-add-wed-rx-support-for-mt7896.patch
@@ -1,8 +1,9 @@
-From a2a123e8fa6755926b38ca22de61ba5fb5f22f85 Mon Sep 17 00:00:00 2001
+From 7c81104d65728fb1c0f156c46e3cfc5dec24b119 Mon Sep 17 00:00:00 2001
From: Sujuan Chen <sujuan.chen@mediatek.com>
-Date: Tue, 13 Jun 2023 17:04:31 +0800
-Subject: [PATCH] 999-3009-add-wed-rx-support-for-mt7896
+Date: Wed, 15 Jun 2022 14:38:54 +0800
+Subject: [PATCH 8/8] 9997-add-wed-rx-support-for-mt7896
+Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com>
---
arch/arm64/boot/dts/mediatek/mt7986a.dtsi | 42 +-
arch/arm64/boot/dts/mediatek/mt7986b.dtsi | 42 +-
@@ -18,7 +19,7 @@
drivers/net/ethernet/mediatek/mtk_wed_wo.c | 564 ++++++++++++++++
drivers/net/ethernet/mediatek/mtk_wed_wo.h | 324 +++++++++
include/linux/soc/mediatek/mtk_wed.h | 126 +++-
- 14 files changed, 2801 insertions(+), 83 deletions(-)
+ 14 files changed, 2796 insertions(+), 75 deletions(-)
create mode 100644 drivers/net/ethernet/mediatek/mtk_wed_ccif.c
create mode 100644 drivers/net/ethernet/mediatek/mtk_wed_ccif.h
create mode 100644 drivers/net/ethernet/mediatek/mtk_wed_mcu.c
@@ -27,7 +28,7 @@
create mode 100644 drivers/net/ethernet/mediatek/mtk_wed_wo.h
diff --git a/arch/arm64/boot/dts/mediatek/mt7986a.dtsi b/arch/arm64/boot/dts/mediatek/mt7986a.dtsi
-index 6fe3583..1ac36a7 100644
+index 87d2b11a9..6abc06db8 100644
--- a/arch/arm64/boot/dts/mediatek/mt7986a.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt7986a.dtsi
@@ -65,6 +65,12 @@
@@ -98,7 +99,7 @@
resets = <ðsysrst 0>;
reset-names = "wocpu_rst";
diff --git a/arch/arm64/boot/dts/mediatek/mt7986b.dtsi b/arch/arm64/boot/dts/mediatek/mt7986b.dtsi
-index de5bf0b..394282c 100644
+index 67bf86f6a..6710b388b 100644
--- a/arch/arm64/boot/dts/mediatek/mt7986b.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt7986b.dtsi
@@ -65,6 +65,12 @@
@@ -169,19 +170,18 @@
resets = <ðsysrst 0>;
reset-names = "wocpu_rst";
diff --git a/drivers/net/ethernet/mediatek/Makefile b/drivers/net/ethernet/mediatek/Makefile
-index 87786bb..498c002 100644
+index 3528f1b..0c724a5 100644
--- a/drivers/net/ethernet/mediatek/Makefile
+++ b/drivers/net/ethernet/mediatek/Makefile
-@@ -10,6 +10,6 @@ mtk_eth-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed.o
+@@ -10,5 +10,5 @@ mtk_eth-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed.o
ifdef CONFIG_DEBUG_FS
mtk_eth-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed_debugfs.o
endif
-obj-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed_ops.o
+obj-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed_ops.o mtk_wed_wo.o mtk_wed_mcu.o mtk_wed_ccif.o
obj-$(CONFIG_NET_MEDIATEK_HNAT) += mtk_hnat/
- obj-$(CONFIG_XFRM_OFFLOAD) += mtk_ipsec.o
diff --git a/drivers/net/ethernet/mediatek/mtk_wed.c b/drivers/net/ethernet/mediatek/mtk_wed.c
-index 8b3a7eb..ff8f658 100644
+index 2700176..b037d00 100644
--- a/drivers/net/ethernet/mediatek/mtk_wed.c
+++ b/drivers/net/ethernet/mediatek/mtk_wed.c
@@ -13,11 +13,19 @@
@@ -2301,7 +2301,7 @@
+
+#endif
diff --git a/drivers/net/ethernet/mediatek/mtk_wed_regs.h b/drivers/net/ethernet/mediatek/mtk_wed_regs.h
-index 14e0e21..31871f7 100644
+index b189761..9d021e2 100644
--- a/drivers/net/ethernet/mediatek/mtk_wed_regs.h
+++ b/drivers/net/ethernet/mediatek/mtk_wed_regs.h
@@ -4,6 +4,8 @@
@@ -2366,8 +2366,8 @@
+ MTK_WED_EXT_INT_STATUS_RX_FBUF_DMAD_ER | \
MTK_WED_EXT_INT_STATUS_RX_DRV_R_RESP_ERR | \
MTK_WED_EXT_INT_STATUS_RX_DRV_W_RESP_ERR | \
- MTK_WED_EXT_INT_STATUS_RX_DRV_INIT_WDMA_EN | \
-@@ -96,6 +105,8 @@ struct mtk_wdma_desc {
+ MTK_WED_EXT_INT_STATUS_RX_DRV_COHERENT | \
+@@ -97,6 +106,8 @@ struct mtk_wdma_desc {
MTK_WED_EXT_INT_STATUS_TX_DMA_W_RESP_ERR)
#define MTK_WED_EXT_INT_MASK 0x028
@@ -2376,7 +2376,7 @@
#define MTK_WED_STATUS 0x060
#define MTK_WED_STATUS_TX GENMASK(15, 8)
-@@ -183,6 +194,9 @@ struct mtk_wdma_desc {
+@@ -184,6 +195,9 @@ struct mtk_wdma_desc {
#define MTK_WED_RING_RX(_n) (0x400 + (_n) * 0x10)
@@ -2386,7 +2386,7 @@
#define MTK_WED_WPDMA_INT_TRIGGER 0x504
#define MTK_WED_WPDMA_INT_TRIGGER_RX_DONE BIT(1)
#define MTK_WED_WPDMA_INT_TRIGGER_TX_DONE GENMASK(5, 4)
-@@ -239,13 +253,19 @@ struct mtk_wdma_desc {
+@@ -240,13 +254,19 @@ struct mtk_wdma_desc {
#define MTK_WED_WPDMA_INT_CTRL_TX 0x530
#define MTK_WED_WPDMA_INT_CTRL_TX0_DONE_EN BIT(0)
@@ -2407,7 +2407,7 @@
#define MTK_WED_WPDMA_INT_CTRL_TX_FREE 0x538
#define MTK_WED_WPDMA_INT_CTRL_TX_FREE_DONE_EN BIT(0)
-@@ -270,13 +290,40 @@ struct mtk_wdma_desc {
+@@ -271,13 +291,40 @@ struct mtk_wdma_desc {
#define MTK_WED_WPDMA_TX_MIB(_n) (0x5a0 + (_n) * 4)
#define MTK_WED_WPDMA_TX_COHERENT_MIB(_n) (0x5d0 + (_n) * 4)
@@ -2448,7 +2448,7 @@
#define MTK_WED_WDMA_GLO_CFG_RX_DRV_EN BIT(2)
#define MTK_WED_WDMA_GLO_CFG_RX_DRV_BUSY BIT(3)
#define MTK_WED_WDMA_GLO_CFG_BT_SIZE GENMASK(5, 4)
-@@ -320,6 +367,20 @@ struct mtk_wdma_desc {
+@@ -321,6 +368,20 @@ struct mtk_wdma_desc {
#define MTK_WED_WDMA_RX_RECYCLE_MIB(_n) (0xae8 + (_n) * 4)
#define MTK_WED_WDMA_RX_PROCESSED_MIB(_n) (0xaf0 + (_n) * 4)
@@ -2469,7 +2469,7 @@
#define MTK_WED_RING_OFS_BASE 0x00
#define MTK_WED_RING_OFS_COUNT 0x04
#define MTK_WED_RING_OFS_CPU_IDX 0x08
-@@ -330,12 +391,13 @@ struct mtk_wdma_desc {
+@@ -331,12 +392,13 @@ struct mtk_wdma_desc {
#define MTK_WDMA_GLO_CFG 0x204
#define MTK_WDMA_GLO_CFG_TX_DMA_EN BIT(0)
@@ -2484,7 +2484,7 @@
#define MTK_WDMA_RESET_IDX 0x208
#define MTK_WDMA_RESET_IDX_TX GENMASK(3, 0)
#define MTK_WDMA_RESET_IDX_RX GENMASK(17, 16)
-@@ -359,4 +421,70 @@ struct mtk_wdma_desc {
+@@ -360,4 +422,70 @@ struct mtk_wdma_desc {
/* DMA channel mapping */
#define HIFSYS_DMA_AG_MAP 0x008
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3010-add-wed-ser-support.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3011-add-wed-ser-support.patch
similarity index 97%
rename from autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3010-add-wed-ser-support.patch
rename to autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3011-add-wed-ser-support.patch
index cf863b6..0d6a50f 100755
--- a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3010-add-wed-ser-support.patch
+++ b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3011-add-wed-ser-support.patch
@@ -1,8 +1,9 @@
-From 66b9d9d65bcbd16d124a5930e829fd78bb1d828a Mon Sep 17 00:00:00 2001
+From f70e83ccdca85840c3bf9e7a31fb871a12724dc2 Mon Sep 17 00:00:00 2001
From: Sujuan Chen <sujuan.chen@mediatek.com>
-Date: Tue, 13 Jun 2023 17:05:48 +0800
-Subject: [PATCH] 999-3010-add-wed-ser-support
+Date: Thu, 28 Jul 2022 14:49:16 +0800
+Subject: [PATCH 3/3] add wed ser support
+Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com>
---
drivers/net/ethernet/mediatek/mtk_eth_soc.c | 8 +
drivers/net/ethernet/mediatek/mtk_wed.c | 361 ++++++++++++++-----
@@ -12,10 +13,10 @@
5 files changed, 320 insertions(+), 99 deletions(-)
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-index 933c0bb..d3f445a 100644
+index 2b52fa0..2f98525 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -4044,6 +4044,9 @@ static void mtk_pending_work(struct work_struct *work)
+@@ -3680,6 +3680,9 @@ static void mtk_pending_work(struct work_struct *work)
for (i = 0; i < MTK_MAC_COUNT; i++) {
if (!eth->netdev[i])
continue;
@@ -25,15 +26,15 @@
if (mtk_reset_flag == MTK_FE_STOP_TRAFFIC) {
pr_info("send MTK_FE_STOP_TRAFFIC event\n");
call_netdevice_notifiers(MTK_FE_STOP_TRAFFIC,
-@@ -4069,6 +4072,7 @@ static void mtk_pending_work(struct work_struct *work)
+@@ -3693,6 +3696,7 @@ static void mtk_pending_work(struct work_struct *work)
+ if (!wait_for_completion_timeout(&wait_ser_done, 3000))
pr_warn("wait for MTK_FE_START_RESET\n");
- }
rtnl_lock();
+#endif
break;
}
-@@ -4107,6 +4111,9 @@ static void mtk_pending_work(struct work_struct *work)
+@@ -3731,6 +3735,9 @@ static void mtk_pending_work(struct work_struct *work)
for (i = 0; i < MTK_MAC_COUNT; i++) {
if (!eth->netdev[i])
continue;
@@ -43,7 +44,7 @@
if (mtk_reset_flag == MTK_FE_STOP_TRAFFIC) {
pr_info("send MTK_FE_START_TRAFFIC event\n");
call_netdevice_notifiers(MTK_FE_START_TRAFFIC,
-@@ -4116,6 +4123,7 @@ static void mtk_pending_work(struct work_struct *work)
+@@ -3740,6 +3747,7 @@ static void mtk_pending_work(struct work_struct *work)
call_netdevice_notifiers(MTK_FE_RESET_DONE,
eth->netdev[i]);
}
@@ -52,7 +53,7 @@
eth->netdev[i]);
break;
diff --git a/drivers/net/ethernet/mediatek/mtk_wed.c b/drivers/net/ethernet/mediatek/mtk_wed.c
-index ff8f658..1a615f2 100644
+index ff8f658..0917a5a 100644
--- a/drivers/net/ethernet/mediatek/mtk_wed.c
+++ b/drivers/net/ethernet/mediatek/mtk_wed.c
@@ -13,8 +13,10 @@
@@ -612,7 +613,7 @@
if (dev->ver == MTK_WED_V1)
regmap_update_bits(hw->hifsys, HIFSYS_DMA_AG_MAP,
BIT(hw->index), 0);
-@@ -1374,7 +1549,8 @@ mtk_wed_attach(struct mtk_wed_device *dev)
+@@ -1374,7 +1549,8 @@ out:
}
static int
@@ -705,7 +706,7 @@
#ifdef CONFIG_DEBUG_FS
diff --git a/drivers/net/ethernet/mediatek/mtk_wed_regs.h b/drivers/net/ethernet/mediatek/mtk_wed_regs.h
-index 31871f7..403a36b 100644
+index 9d021e2..cfcd94f 100644
--- a/drivers/net/ethernet/mediatek/mtk_wed_regs.h
+++ b/drivers/net/ethernet/mediatek/mtk_wed_regs.h
@@ -38,11 +38,15 @@ struct mtk_wdma_desc {
@@ -724,7 +725,7 @@
#define MTK_WED_RESET_WDMA_RX_DRV BIT(17)
#define MTK_WED_RESET_WDMA_INT_AGENT BIT(19)
#define MTK_WED_RESET_RX_RRO_QM BIT(20)
-@@ -185,7 +189,12 @@ struct mtk_wdma_desc {
+@@ -186,7 +190,12 @@ struct mtk_wdma_desc {
#define MTK_WED_RESET_IDX 0x20c
#define MTK_WED_RESET_IDX_TX GENMASK(3, 0)
@@ -737,7 +738,7 @@
#define MTK_WED_TX_MIB(_n) (0x2a0 + (_n) * 4)
#define MTK_WED_RX_MIB(_n) (0x2e0 + (_n) * 4)
-@@ -299,6 +308,9 @@ struct mtk_wdma_desc {
+@@ -300,6 +309,9 @@ struct mtk_wdma_desc {
#define MTK_WED_WPDMA_RX_D_GLO_CFG 0x75c
#define MTK_WED_WPDMA_RX_D_RX_DRV_EN BIT(0)
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3012-ethernet-update-ppe-backward-compatible-two-way-hash.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3012-ethernet-update-ppe-backward-compatible-two-way-hash.patch
new file mode 100755
index 0000000..cfe29e7
--- /dev/null
+++ b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3012-ethernet-update-ppe-backward-compatible-two-way-hash.patch
@@ -0,0 +1,192 @@
+diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+index 2c54c9c..d3ba9eb 100644
+--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
++++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+@@ -4442,7 +4442,8 @@ static int mtk_probe(struct platform_dev
+
+ for (i = 0; i < eth->ppe_num; i++) {
+ eth->ppe[i] = mtk_ppe_init(eth,
+- eth->base + MTK_ETH_PPE_BASE + i * 0x400, 2, i);
++ eth->base + MTK_ETH_PPE_BASE + i * 0x400,
++ 2, eth->soc->hash_way, i);
+ if (!eth->ppe[i]) {
+ err = -ENOMEM;
+ goto err_free_dev;
+@@ -4558,6 +4559,7 @@ static const struct mtk_soc_data mt2701_
+ .required_clks = MT7623_CLKS_BITMAP,
+ .required_pctl = true,
+ .has_sram = false,
++ .hash_way = 2,
+ .offload_version = 2,
+ .rss_num = 0,
+ .txrx = {
+@@ -4573,6 +4575,7 @@ static const struct mtk_soc_data mt7621_
+ .required_clks = MT7621_CLKS_BITMAP,
+ .required_pctl = false,
+ .has_sram = false,
++ .hash_way = 2,
+ .offload_version = 2,
+ .rss_num = 0,
+ .txrx = {
+@@ -4589,6 +4592,7 @@ static const struct mtk_soc_data mt7622_
+ .required_clks = MT7622_CLKS_BITMAP,
+ .required_pctl = false,
+ .has_sram = false,
++ .hash_way = 2,
+ .offload_version = 2,
+ .rss_num = 0,
+ .txrx = {
+@@ -4604,6 +4608,7 @@ static const struct mtk_soc_data mt7623_
+ .required_clks = MT7623_CLKS_BITMAP,
+ .required_pctl = true,
+ .has_sram = false,
++ .hash_way = 2,
+ .offload_version = 2,
+ .rss_num = 0,
+ .txrx = {
+@@ -4635,6 +4640,7 @@ static const struct mtk_soc_data mt7986_
+ .required_clks = MT7986_CLKS_BITMAP,
+ .required_pctl = false,
+ .has_sram = true,
++ .hash_way = 4,
+ .offload_version = 2,
+ .rss_num = 0,
+ .txrx = {
+@@ -4651,6 +4657,8 @@ static const struct mtk_soc_data mt7981_
+ .required_clks = MT7981_CLKS_BITMAP,
+ .required_pctl = false,
+ .has_sram = true,
++ .hash_way = 4,
++ .offload_version = 2,
+ .rss_num = 0,
+ .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 4a69bd0..35a7543 100644
+--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
++++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
+@@ -1472,6 +1472,7 @@ struct mtk_soc_data {
+ u64 caps;
+ u32 required_clks;
+ bool required_pctl;
++ u8 hash_way;
+ u8 offload_version;
+ netdev_features_t hw_features;
+ bool has_sram;
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
+index e4d50eb..918aa22 100755
+--- a/drivers/net/ethernet/mediatek/mtk_ppe.c
++++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
+@@ -88,7 +88,7 @@ static void mtk_ppe_cache_enable(struct mtk_ppe *ppe, bool enable)
+ enable * MTK_PPE_CACHE_CTL_EN);
+ }
+
+-static u32 mtk_ppe_hash_entry(struct mtk_foe_entry *e)
++static u32 mtk_ppe_hash_entry(struct mtk_ppe *ppe, struct mtk_foe_entry *e)
+ {
+ u32 hv1, hv2, hv3;
+ u32 hash;
+@@ -122,7 +122,7 @@ static u32 mtk_ppe_hash_entry(struct mtk_foe_entry *e)
+ hash = (hash >> 24) | ((hash & 0xffffff) << 8);
+ hash ^= hv1 ^ hv2 ^ hv3;
+ hash ^= hash >> 16;
+- hash <<= 2;
++ hash <<= (ffs(ppe->way) - 1);
+ hash &= MTK_PPE_ENTRIES - 1;
+
+ return hash;
+@@ -542,10 +542,10 @@ int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
+ if (type == MTK_PPE_PKT_TYPE_BRIDGE)
+ return mtk_foe_entry_commit_l2(ppe, entry);
+
+- hash = mtk_ppe_hash_entry(&entry->data);
++ hash = mtk_ppe_hash_entry(ppe, &entry->data);
+ entry->hash = 0xffff;
+ spin_lock_bh(&ppe_lock);
+- hlist_add_head(&entry->list, &ppe->foe_flow[hash / 4]);
++ hlist_add_head(&entry->list, &ppe->foe_flow[hash / ppe->way]);
+ spin_unlock_bh(&ppe_lock);
+
+ return 0;
+@@ -569,7 +569,7 @@ mtk_foe_entry_commit_subflow(struct mtk_ppe *ppe, struct mtk_flow_entry *entry,
+ flow_info->l2_data.base_flow = entry;
+ flow_info->type = MTK_FLOW_TYPE_L2_SUBFLOW;
+ flow_info->hash = hash;
+- hlist_add_head(&flow_info->list, &ppe->foe_flow[hash / 4]);
++ hlist_add_head(&flow_info->list, &ppe->foe_flow[hash / ppe->way]);
+ hlist_add_head(&flow_info->l2_data.list, &entry->l2_flows);
+
+ hwe = &ppe->foe_table[hash];
+@@ -593,7 +593,7 @@ mtk_foe_entry_commit_subflow(struct mtk_ppe *ppe, struct mtk_flow_entry *entry,
+
+ void __mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash)
+ {
+- struct hlist_head *head = &ppe->foe_flow[hash / 4];
++ struct hlist_head *head = &ppe->foe_flow[hash / ppe->way];
+ struct mtk_foe_entry *hwe = &ppe->foe_table[hash];
+ struct mtk_flow_entry *entry;
+ struct mtk_foe_bridge key = {};
+@@ -676,12 +676,12 @@ int mtk_foe_entry_idle_time(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
+ return __mtk_foe_entry_idle_time(ppe, entry->data.ib1);
+ }
+
+-struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
+- int version, int id)
++struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int version, int way, int id)
+ {
+ struct device *dev = eth->dev;
+ struct mtk_foe_entry *foe;
+ struct mtk_ppe *ppe;
++ struct hlist_head *flow;
+
+ ppe = devm_kzalloc(dev, sizeof(*ppe), GFP_KERNEL);
+ if (!ppe)
+@@ -695,6 +696,7 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int versio
+ ppe->eth = eth;
+ ppe->dev = dev;
+ ppe->version = version;
++ ppe->way = way;
+ ppe->id = id;
+
+ foe = dmam_alloc_coherent(ppe->dev, MTK_PPE_ENTRIES * sizeof(*foe),
+@@ -704,6 +706,13 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int versio
+
+ ppe->foe_table = foe;
+
++ flow = devm_kzalloc(dev, (MTK_PPE_ENTRIES / way) * sizeof(*flow),
++ GFP_KERNEL);
++ if (!flow)
++ return NULL;
++
++ ppe->foe_flow = flow;
++
+ return ppe;
+ }
+
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
+index 21cc551..3d6928c 100644
+--- a/drivers/net/ethernet/mediatek/mtk_ppe.h
++++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
+@@ -276,19 +276,20 @@ struct mtk_ppe {
+ void __iomem *base;
+ int version;
+ int id;
++ int way;
+
+ struct mtk_foe_entry *foe_table;
+ dma_addr_t foe_phys;
+
+ u16 foe_check_time[MTK_PPE_ENTRIES];
+- struct hlist_head foe_flow[MTK_PPE_ENTRIES / 2];
++ struct hlist_head *foe_flow;
+
+ struct rhashtable l2_flows;
+
+ void *acct_table;
+ };
+
+-struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int version, int id);
++struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int version, int way, int id);
+ int mtk_ppe_start(struct mtk_ppe *ppe);
+ int mtk_ppe_stop(struct mtk_ppe *ppe);
+
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3013-flow-offload-add-mtkhnat-flow-accounting.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3013-flow-offload-add-mtkhnat-flow-accounting.patch
new file mode 100755
index 0000000..ed90d2c
--- /dev/null
+++ b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3013-flow-offload-add-mtkhnat-flow-accounting.patch
@@ -0,0 +1,449 @@
+diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+index 4f53794..dc5d050 100644
+--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
++++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+@@ -3944,7 +3944,8 @@ static int mtk_probe(struct platform_device *pdev)
+ for (i = 0; i < eth->ppe_num; i++) {
+ eth->ppe[i] = mtk_ppe_init(eth,
+ eth->base + MTK_ETH_PPE_BASE + i * 0x400,
+- 2, eth->soc->hash_way, i);
++ 2, eth->soc->hash_way, i,
++ eth->soc->has_accounting);
+ if (!eth->ppe[i]) {
+ err = -ENOMEM;
+ goto err_free_dev;
+@@ -4057,6 +4058,7 @@ static const struct mtk_soc_data mt2701_data = {
+ .required_clks = MT7623_CLKS_BITMAP,
+ .required_pctl = true,
+ .has_sram = false,
++ .has_accounting = false,
+ .hash_way = 2,
+ .offload_version = 2,
+ .rss_num = 0,
+@@ -4073,6 +4075,7 @@ static const struct mtk_soc_data mt7621_data = {
+ .required_clks = MT7621_CLKS_BITMAP,
+ .required_pctl = false,
+ .has_sram = false,
++ .has_accounting = false,
+ .hash_way = 2,
+ .offload_version = 2,
+ .rss_num = 0,
+@@ -4090,6 +4093,7 @@ static const struct mtk_soc_data mt7622_data = {
+ .required_clks = MT7622_CLKS_BITMAP,
+ .required_pctl = false,
+ .has_sram = false,
++ .has_accounting = true,
+ .hash_way = 2,
+ .offload_version = 2,
+ .rss_num = 0,
+@@ -4106,6 +4110,7 @@ static const struct mtk_soc_data mt7623_data = {
+ .required_clks = MT7623_CLKS_BITMAP,
+ .required_pctl = true,
+ .has_sram = false,
++ .has_accounting = false,
+ .hash_way = 2,
+ .offload_version = 2,
+ .rss_num = 0,
+@@ -4123,6 +4128,7 @@ static const struct mtk_soc_data mt7629_data = {
+ .required_clks = MT7629_CLKS_BITMAP,
+ .required_pctl = false,
+ .has_sram = false,
++ .has_accounting = true,
+ .rss_num = 0,
+ .txrx = {
+ .txd_size = sizeof(struct mtk_tx_dma),
+@@ -4138,6 +4144,7 @@ static const struct mtk_soc_data mt7986_data = {
+ .required_clks = MT7986_CLKS_BITMAP,
+ .required_pctl = false,
+ .has_sram = true,
++ .has_accounting = true,
+ .hash_way = 4,
+ .offload_version = 2,
+ .rss_num = 0,
+@@ -4155,6 +4162,7 @@ static const struct mtk_soc_data mt7981_data = {
+ .required_clks = MT7981_CLKS_BITMAP,
+ .required_pctl = false,
+ .has_sram = true,
++ .has_accounting = true,
+ .hash_way = 4,
+ .offload_version = 2,
+ .rss_num = 0,
+@@ -4171,6 +4179,7 @@ static const struct mtk_soc_data rt5350_data = {
+ .required_clks = MT7628_CLKS_BITMAP,
+ .required_pctl = false,
+ .has_sram = false,
++ .has_accounting = false,
+ .rss_num = 0,
+ .txrx = {
+ .txd_size = sizeof(struct mtk_tx_dma),
+diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
+index f659633..5e16fa8 100644
+--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
++++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
+@@ -1213,6 +1213,7 @@ struct mtk_soc_data {
+ u8 offload_version;
+ netdev_features_t hw_features;
+ bool has_sram;
++ bool has_accounting;
+ struct {
+ u32 txd_size;
+ u32 rxd_size;
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
+index 918aa22..8c036cd 100755
+--- a/drivers/net/ethernet/mediatek/mtk_ppe.c
++++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
+@@ -74,6 +74,46 @@ static int mtk_ppe_wait_busy(struct mtk_ppe *ppe)
+ return ret;
+ }
+
++static int mtk_ppe_mib_wait_busy(struct mtk_ppe *ppe)
++{
++ int ret;
++ u32 val;
++
++ ret = readl_poll_timeout(ppe->base + MTK_PPE_MIB_SER_CR, val,
++ !(val & MTK_PPE_MIB_SER_CR_ST),
++ 20, MTK_PPE_WAIT_TIMEOUT_US);
++
++ if (ret)
++ dev_err(ppe->dev, "MIB table busy");
++
++ return ret;
++}
++
++int mtk_mib_entry_read(struct mtk_ppe *ppe, u16 index, u64 *bytes, u64 *packets)
++{
++ u32 val, cnt_r0, cnt_r1, cnt_r2;
++ u32 byte_cnt_low, byte_cnt_high, pkt_cnt_low, pkt_cnt_high;
++
++ val = FIELD_PREP(MTK_PPE_MIB_SER_CR_ADDR, index) | MTK_PPE_MIB_SER_CR_ST;
++ ppe_w32(ppe, MTK_PPE_MIB_SER_CR, val);
++
++ if (mtk_ppe_mib_wait_busy(ppe))
++ return -ETIMEDOUT;
++
++ cnt_r0 = readl(ppe->base + MTK_PPE_MIB_SER_R0);
++ cnt_r1 = readl(ppe->base + MTK_PPE_MIB_SER_R1);
++ cnt_r2 = readl(ppe->base + MTK_PPE_MIB_SER_R2);
++
++ byte_cnt_low = FIELD_GET(MTK_PPE_MIB_SER_R0_BYTE_CNT_LOW, cnt_r0);
++ byte_cnt_high = FIELD_GET(MTK_PPE_MIB_SER_R1_BYTE_CNT_HIGH, cnt_r1);
++ pkt_cnt_low = FIELD_GET(MTK_PPE_MIB_SER_R1_PKT_CNT_LOW, cnt_r1);
++ pkt_cnt_high = FIELD_GET(MTK_PPE_MIB_SER_R2_PKT_CNT_HIGH, cnt_r2);
++ *bytes = ((u64)byte_cnt_high << 32) | byte_cnt_low;
++ *packets = (pkt_cnt_high << 16) | pkt_cnt_low;
++
++ return 0;
++}
++
+ static void mtk_ppe_cache_clear(struct mtk_ppe *ppe)
+ {
+ ppe_set(ppe, MTK_PPE_CACHE_CTL, MTK_PPE_CACHE_CTL_CLEAR);
+@@ -412,7 +452,19 @@ __mtk_foe_entry_clear(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
+ MTK_FOE_STATE_INVALID);
+ dma_wmb();
+ mtk_ppe_cache_clear(ppe);
++
++ if (ppe->accounting) {
++ struct mtk_foe_accounting *acct, *acct_updated;
++
++ acct = ppe->acct_table + entry->hash * sizeof(*acct);
++ acct->packets = 0;
++ acct->bytes = 0;
++
++ acct_updated = ppe->acct_updated_table + entry->hash * sizeof(*acct_updated);
++ acct_updated->packets = 0;
++ acct_updated->bytes = 0;
++ }
+ }
+ entry->hash = 0xffff;
+
+ if (entry->type != MTK_FLOW_TYPE_L2_SUBFLOW)
+@@ -513,6 +560,16 @@ __mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_foe_entry *entry,
+ wmb();
+ hwe->ib1 = entry->ib1;
+
++ if (ppe->accounting) {
++ int type;
++
++ type = FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, entry->ib1);
++ if (type >= MTK_PPE_PKT_TYPE_IPV4_DSLITE)
++ hwe->ipv6.ib2 |= MTK_FOE_IB2_MIB_CNT;
++ else
++ hwe->ipv4.ib2 |= MTK_FOE_IB2_MIB_CNT;
++ }
++
+ dma_wmb();
+
+ mtk_ppe_cache_clear(ppe);
+@@ -618,8 +675,6 @@ void __mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash)
+ }
+
+ if (found || !mtk_flow_entry_match(entry, hwe)) {
+- if (entry->hash != 0xffff)
+- entry->hash = 0xffff;
+ continue;
+ }
+
+@@ -676,12 +731,44 @@ int mtk_foe_entry_idle_time(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
+ return __mtk_foe_entry_idle_time(ppe, entry->data.ib1);
+ }
+
+-struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int version, int way, int id)
++struct mtk_foe_accounting *mtk_foe_entry_get_mib(struct mtk_ppe *ppe, u32 index, struct mtk_foe_accounting *diff)
++{
++ struct mtk_foe_accounting *acct, *acct_updated;
++ int size = sizeof(struct mtk_foe_accounting);
++ u64 bytes, packets;
++
++ if (!ppe->accounting)
++ return NULL;
++
++ if (mtk_mib_entry_read(ppe, index, &bytes, &packets))
++ return NULL;
++
++ acct = ppe->acct_table + index * size;
++
++ acct->bytes += bytes;
++ acct->packets += packets;
++
++ if (diff) {
++ acct_updated = ppe->acct_updated_table + index * size;
++
++ diff->bytes = acct->bytes - acct_updated->bytes;
++ diff->packets = acct->packets - acct_updated->packets;
++ acct_updated->bytes += diff->bytes;
++ acct_updated->packets += diff->packets;
++ }
++
++ return acct;
++}
++
++struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int version, int way, int id,
++ int accounting)
+ {
+ struct device *dev = eth->dev;
+ struct mtk_foe_entry *foe;
++ struct mtk_mib_entry *mib;
+ struct mtk_ppe *ppe;
+ struct hlist_head *flow;
++ struct mtk_foe_accounting *acct, *acct_updated;
+
+ ppe = devm_kzalloc(dev, sizeof(*ppe), GFP_KERNEL);
+ if (!ppe)
+@@ -698,6 +781,7 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int versio
+ ppe->version = version;
+ ppe->way = way;
+ ppe->id = id;
++ ppe->accounting = accounting;
+
+ foe = dmam_alloc_coherent(ppe->dev, MTK_PPE_ENTRIES * sizeof(*foe),
+ &ppe->foe_phys, GFP_KERNEL);
+@@ -713,6 +797,31 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int versio
+
+ ppe->foe_flow = flow;
+
++ if (accounting) {
++ mib = dmam_alloc_coherent(ppe->dev, MTK_PPE_ENTRIES * sizeof(*mib),
++ &ppe->mib_phys, GFP_KERNEL);
++ if (!foe)
++ return NULL;
++
++ memset(mib, 0, MTK_PPE_ENTRIES * sizeof(*mib));
++
++ ppe->mib_table = mib;
++
++ acct = devm_kzalloc(dev, MTK_PPE_ENTRIES * sizeof(*acct),
++ GFP_KERNEL);
++ if (!acct)
++ return NULL;
++
++ ppe->acct_table = acct;
++
++ acct_updated = devm_kzalloc(dev, MTK_PPE_ENTRIES * sizeof(*acct_updated),
++ GFP_KERNEL);
++ if (!acct_updated)
++ return NULL;
++
++ ppe->acct_updated_table = acct_updated;
++ }
++
+ return ppe;
+ }
+
+@@ -811,6 +949,13 @@ int mtk_ppe_start(struct mtk_ppe *ppe)
+ ppe_w32(ppe, MTK_PPE_DEFAULT_CPU_PORT1, 0xcb777);
+ ppe_w32(ppe, MTK_PPE_SBW_CTRL, 0x7f);
+
++ if (ppe->accounting && ppe->mib_phys) {
++ ppe_w32(ppe, MTK_PPE_MIB_TB_BASE, ppe->mib_phys);
++ ppe_m32(ppe, MTK_PPE_MIB_CFG, MTK_PPE_MIB_CFG_EN, MTK_PPE_MIB_CFG_EN);
++ ppe_m32(ppe, MTK_PPE_MIB_CFG, MTK_PPE_MIB_CFG_RD_CLR, MTK_PPE_MIB_CFG_RD_CLR);
++ ppe_m32(ppe, MTK_PPE_MIB_CACHE_CTL, MTK_PPE_MIB_CACHE_CTL_EN, MTK_PPE_MIB_CFG_RD_CLR);
++ }
++
+ return 0;
+ }
+
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
+index 3d6928c..8076e5d 100644
+--- a/drivers/net/ethernet/mediatek/mtk_ppe.h
++++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
+@@ -270,6 +270,20 @@ struct mtk_flow_entry {
+ unsigned long cookie;
+ };
+
++struct mtk_mib_entry {
++ u32 byt_cnt_l;
++ u16 byt_cnt_h;
++ u32 pkt_cnt_l;
++ u8 pkt_cnt_h;
++ u8 _rsv0;
++ u32 _rsv1;
++} __packed;
++
++struct mtk_foe_accounting {
++ u64 bytes;
++ u64 packets;
++};
++
+ struct mtk_ppe {
+ struct mtk_eth *eth;
+ struct device *dev;
+@@ -277,10 +291,14 @@ struct mtk_ppe {
+ int version;
+ int id;
+ int way;
++ int accounting;
+
+ struct mtk_foe_entry *foe_table;
+ dma_addr_t foe_phys;
+
++ struct mtk_mib_entry *mib_table;
++ dma_addr_t mib_phys;
++
+ u16 foe_check_time[MTK_PPE_ENTRIES];
+ struct hlist_head *foe_flow;
+
+@@ -289,7 +307,9 @@ struct mtk_ppe {
+ void *acct_table;
++ void *acct_updated_table;
+ };
+
+-struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int version, int way, int id);
++struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int version, int way, int id,
++ int accounting);
+ int mtk_ppe_start(struct mtk_ppe *ppe);
+ int mtk_ppe_stop(struct mtk_ppe *ppe);
+
+@@ -340,5 +359,6 @@ int mtk_foe_entry_set_wdma(struct mtk_foe_entry *entry, int wdma_idx, int txq,
+ 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);
++struct mtk_foe_accounting *mtk_foe_entry_get_mib(struct mtk_ppe *ppe, u32 index, struct mtk_foe_accounting *diff);
+
+ #endif
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c b/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
+index f4ebe59..d713e2e 100644
+--- a/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
++++ b/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
+@@ -81,6 +81,7 @@ mtk_ppe_debugfs_foe_show(struct seq_file *m, struct mtk_ppe *ppe, bool bind)
+ struct mtk_foe_entry *entry = &ppe->foe_table[i];
+ struct mtk_foe_mac_info *l2;
+ struct mtk_flow_addr_info ai = {};
++ struct mtk_foe_accounting *acct;
+ unsigned char h_source[ETH_ALEN];
+ unsigned char h_dest[ETH_ALEN];
+ int type, state;
+@@ -94,6 +95,8 @@ mtk_ppe_debugfs_foe_show(struct seq_file *m, struct mtk_ppe *ppe, bool bind)
+ if (bind && state != MTK_FOE_STATE_BIND)
+ continue;
+
++ acct = mtk_foe_entry_get_mib(ppe, i, NULL);
++
+ type = FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, entry->ib1);
+ seq_printf(m, "%05x %s %7s", i,
+ mtk_foe_entry_state_str(state),
+@@ -154,9 +157,12 @@ mtk_ppe_debugfs_foe_show(struct seq_file *m, struct mtk_ppe *ppe, bool bind)
+ *((__be16 *)&h_dest[4]) = htons(l2->dest_mac_lo);
+
+ seq_printf(m, " eth=%pM->%pM etype=%04x"
+- " vlan=%d,%d ib1=%08x ib2=%08x\n",
++ " vlan=%d,%d ib1=%08x ib2=%08x"
++ " packets=%lld bytes=%lld\n",
+ h_source, h_dest, ntohs(l2->etype),
+- l2->vlan1, l2->vlan2, entry->ib1, ib2);
++ l2->vlan1, l2->vlan2, entry->ib1, ib2,
++ acct->packets, acct->bytes
++ );
+ }
+
+ return 0;
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
+index 2f7d76d..f258539 100755
+--- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
++++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
+@@ -504,6 +504,7 @@ static int
+ mtk_flow_offload_stats(struct mtk_eth *eth, struct flow_cls_offload *f)
+ {
+ struct mtk_flow_entry *entry;
++ struct mtk_foe_accounting diff;
+ u32 idle;
+ int i;
+
+@@ -516,6 +517,12 @@ mtk_flow_offload_stats(struct mtk_eth *eth, struct flow_cls_offload *f)
+ idle = mtk_foe_entry_idle_time(eth->ppe[i], entry);
+ f->stats.lastused = jiffies - idle * HZ;
+
++ if (entry->hash != 0xFFFF) {
++ mtk_foe_entry_get_mib(eth->ppe[i], entry->hash, &diff);
++ f->stats.pkts += diff.packets;
++ f->stats.bytes += diff.bytes;
++ }
++
+ return 0;
+ }
+
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_regs.h b/drivers/net/ethernet/mediatek/mtk_ppe_regs.h
+index d319f18..9eb7a0d 100644
+--- a/drivers/net/ethernet/mediatek/mtk_ppe_regs.h
++++ b/drivers/net/ethernet/mediatek/mtk_ppe_regs.h
+@@ -145,6 +146,20 @@ enum {
+
+ #define MTK_PPE_MIB_TB_BASE 0x338
+
++#define MTK_PPE_MIB_SER_CR 0x33C
++#define MTK_PPE_MIB_SER_CR_ST BIT(16)
++#define MTK_PPE_MIB_SER_CR_ADDR GENMASK(13, 0)
++
++#define MTK_PPE_MIB_SER_R0 0x340
++#define MTK_PPE_MIB_SER_R0_BYTE_CNT_LOW GENMASK(31, 0)
++
++#define MTK_PPE_MIB_SER_R1 0x344
++#define MTK_PPE_MIB_SER_R1_PKT_CNT_LOW GENMASK(31, 16)
++#define MTK_PPE_MIB_SER_R1_BYTE_CNT_HIGH GENMASK(15, 0)
++
++#define MTK_PPE_MIB_SER_R2 0x348
++#define MTK_PPE_MIB_SER_R2_PKT_CNT_HIGH GENMASK(23, 0)
++
+ #define MTK_PPE_MIB_CACHE_CTL 0x350
+ #define MTK_PPE_MIB_CACHE_CTL_EN BIT(0)
+ #define MTK_PPE_MIB_CACHE_CTL_FLUSH BIT(2)
+diff --git a/net/netfilter/xt_FLOWOFFLOAD.c b/net/netfilter/xt_FLOWOFFLOAD.c
+index 8547f4a..c175e4d 100644
+--- a/net/netfilter/xt_FLOWOFFLOAD.c
++++ b/net/netfilter/xt_FLOWOFFLOAD.c
+@@ -700,12 +781,12 @@ static int __init xt_flowoffload_tg_init(void)
+ if (ret)
+ goto cleanup;
+
+- flowtable[1].ft.flags = NF_FLOWTABLE_HW_OFFLOAD;
++ flowtable[1].ft.flags = NF_FLOWTABLE_HW_OFFLOAD | NF_FLOWTABLE_COUNTER;
+
+ ret = xt_register_target(&offload_tg_reg);
+ if (ret)
+ goto cleanup2;
+
+ return 0;
+
+ cleanup2:
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3014-ethernet-update-ppe-from-mt7986-to-mt7988.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3014-ethernet-update-ppe-from-mt7986-to-mt7988.patch
deleted file mode 100755
index b3af506..0000000
--- a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3014-ethernet-update-ppe-from-mt7986-to-mt7988.patch
+++ /dev/null
@@ -1,606 +0,0 @@
-From fbca8b0bbe49bc79b6ab04516095ee98d8ea4db7 Mon Sep 17 00:00:00 2001
-From: Bo-Cun Chen <bc-bocun.chen@mediatek.com>
-Date: Tue, 13 Jun 2023 22:37:57 +0800
-Subject: [PATCH] 999-3014-ethernet-update-ppe-from-mt7986-to-mt7988
-
----
- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 26 +++--
- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 29 +++--
- drivers/net/ethernet/mediatek/mtk_ppe.c | 106 +++++++++++++-----
- drivers/net/ethernet/mediatek/mtk_ppe.h | 48 +++++++-
- .../net/ethernet/mediatek/mtk_ppe_offload.c | 18 +--
- drivers/net/ethernet/mediatek/mtk_ppe_regs.h | 5 +
- 6 files changed, 171 insertions(+), 61 deletions(-)
- mode change 100755 => 100644 drivers/net/ethernet/mediatek/mtk_ppe_offload.c
-
-diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-index f22a11a..1226c68 100644
---- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -2191,7 +2191,8 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
- skb->dev = netdev;
- skb_put(skb, pktlen);
-
-- if ((MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_RX_V2))) {
-+ if ((MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_RX_V2)) ||
-+ (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))) {
- reason = FIELD_GET(MTK_RXD5_PPE_CPU_REASON, trxd.rxd5);
- hash = trxd.rxd5 & MTK_RXD5_FOE_ENTRY;
- if (hash != MTK_RXD5_FOE_ENTRY)
-@@ -4886,7 +4887,8 @@ static int mtk_probe(struct platform_device *pdev)
- if (eth->soc->offload_version) {
- u32 num_ppe;
-
-- num_ppe = MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ? 2 : 1;
-+ num_ppe = MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3) ? 3 :
-+ MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ? 2 : 1;
- num_ppe = min_t(u32, ARRAY_SIZE(eth->ppe), num_ppe);
- for (i = 0; i < num_ppe; i++) {
- u32 ppe_addr = eth->soc->reg_map->ppe_base[i];
-@@ -5014,7 +5016,7 @@ static const struct mtk_soc_data mt2701_data = {
- .has_accounting = false,
- .hash_offset = 2,
- .offload_version = 1,
-- .foe_entry_size = sizeof(struct mtk_foe_entry) - 16,
-+ .foe_entry_size = sizeof(struct mtk_foe_entry) - 48,
- .rss_num = 0,
- .txrx = {
- .txd_size = sizeof(struct mtk_tx_dma),
-@@ -5036,7 +5038,7 @@ static const struct mtk_soc_data mt7621_data = {
- .has_accounting = false,
- .hash_offset = 2,
- .offload_version = 1,
-- .foe_entry_size = sizeof(struct mtk_foe_entry) - 16,
-+ .foe_entry_size = sizeof(struct mtk_foe_entry) - 48,
- .rss_num = 0,
- .txrx = {
- .txd_size = sizeof(struct mtk_tx_dma),
-@@ -5059,7 +5061,7 @@ static const struct mtk_soc_data mt7622_data = {
- .has_accounting = true,
- .hash_offset = 2,
- .offload_version = 2,
-- .foe_entry_size = sizeof(struct mtk_foe_entry) - 16,
-+ .foe_entry_size = sizeof(struct mtk_foe_entry) - 48,
- .rss_num = 0,
- .txrx = {
- .txd_size = sizeof(struct mtk_tx_dma),
-@@ -5081,7 +5083,7 @@ static const struct mtk_soc_data mt7623_data = {
- .has_accounting = false,
- .hash_offset = 2,
- .offload_version = 1,
-- .foe_entry_size = sizeof(struct mtk_foe_entry) - 16,
-+ .foe_entry_size = sizeof(struct mtk_foe_entry) - 48,
- .rss_num = 0,
- .txrx = {
- .txd_size = sizeof(struct mtk_tx_dma),
-@@ -5104,7 +5106,7 @@ static const struct mtk_soc_data mt7629_data = {
- .has_accounting = true,
- .hash_offset = 2,
- .offload_version = 2,
-- .foe_entry_size = sizeof(struct mtk_foe_entry) - 16,
-+ .foe_entry_size = sizeof(struct mtk_foe_entry) - 48,
- .rss_num = 0,
- .txrx = {
- .txd_size = sizeof(struct mtk_tx_dma),
-@@ -5126,7 +5128,7 @@ static const struct mtk_soc_data mt7986_data = {
- .has_accounting = true,
- .hash_offset = 4,
- .offload_version = 2,
-- .foe_entry_size = sizeof(struct mtk_foe_entry),
-+ .foe_entry_size = sizeof(struct mtk_foe_entry) - 32,
- .rss_num = 0,
- .txrx = {
- .txd_size = sizeof(struct mtk_tx_dma_v2),
-@@ -5149,7 +5151,7 @@ static const struct mtk_soc_data mt7981_data = {
- .has_accounting = true,
- .hash_offset = 4,
- .offload_version = 2,
-- .foe_entry_size = sizeof(struct mtk_foe_entry),
-+ .foe_entry_size = sizeof(struct mtk_foe_entry) - 32,
- .rss_num = 0,
- .txrx = {
- .txd_size = sizeof(struct mtk_tx_dma_v2),
-@@ -5169,6 +5171,10 @@ static const struct mtk_soc_data mt7988_data = {
- .required_clks = MT7988_CLKS_BITMAP,
- .required_pctl = false,
- .has_sram = true,
-+ .has_accounting = true,
-+ .hash_offset = 4,
-+ .offload_version = 2,
-+ .foe_entry_size = sizeof(struct mtk_foe_entry),
- .rss_num = 4,
- .txrx = {
- .txd_size = sizeof(struct mtk_tx_dma_v2),
-@@ -5190,7 +5196,7 @@ static const struct mtk_soc_data rt5350_data = {
- .has_accounting = false,
- .hash_offset = 2,
- .offload_version = 1,
-- .foe_entry_size = sizeof(struct mtk_foe_entry) - 16,
-+ .foe_entry_size = sizeof(struct mtk_foe_entry) - 48,
- .rss_num = 0,
- .txrx = {
- .txd_size = sizeof(struct mtk_tx_dma),
-diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-index c85f573..3554d14 100644
---- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-@@ -1866,7 +1866,7 @@ struct mtk_eth {
- struct timer_list mtk_dma_monitor_timer;
-
- u8 qos_toggle;
-- struct mtk_ppe *ppe[2];
-+ struct mtk_ppe *ppe[3];
- struct rhashtable flow_table;
- };
-
-@@ -1913,7 +1913,8 @@ mtk_foe_get_entry(struct mtk_ppe *ppe, u16 hash)
-
- static inline u32 mtk_get_ib1_ts_mask(struct mtk_eth *eth)
- {
-- if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
-+ MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
- return MTK_FOE_IB1_BIND_TIMESTAMP_V2;
-
- return MTK_FOE_IB1_BIND_TIMESTAMP;
-@@ -1921,7 +1922,8 @@ static inline u32 mtk_get_ib1_ts_mask(struct mtk_eth *eth)
-
- static inline u32 mtk_get_ib1_ppoe_mask(struct mtk_eth *eth)
- {
-- if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
-+ MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
- return MTK_FOE_IB1_BIND_PPPOE_V2;
-
- return MTK_FOE_IB1_BIND_PPPOE;
-@@ -1929,7 +1931,8 @@ static inline u32 mtk_get_ib1_ppoe_mask(struct mtk_eth *eth)
-
- static inline u32 mtk_get_ib1_vlan_tag_mask(struct mtk_eth *eth)
- {
-- if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
-+ MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
- return MTK_FOE_IB1_BIND_VLAN_TAG_V2;
-
- return MTK_FOE_IB1_BIND_VLAN_TAG;
-@@ -1937,7 +1940,8 @@ static inline u32 mtk_get_ib1_vlan_tag_mask(struct mtk_eth *eth)
-
- static inline u32 mtk_get_ib1_vlan_layer_mask(struct mtk_eth *eth)
- {
-- if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
-+ MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
- return MTK_FOE_IB1_BIND_VLAN_LAYER_V2;
-
- return MTK_FOE_IB1_BIND_VLAN_LAYER;
-@@ -1945,7 +1949,8 @@ static inline u32 mtk_get_ib1_vlan_layer_mask(struct mtk_eth *eth)
-
- static inline u32 mtk_prep_ib1_vlan_layer(struct mtk_eth *eth, u32 val)
- {
-- if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
-+ MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
- return FIELD_PREP(MTK_FOE_IB1_BIND_VLAN_LAYER_V2, val);
-
- return FIELD_PREP(MTK_FOE_IB1_BIND_VLAN_LAYER, val);
-@@ -1953,7 +1958,8 @@ static inline u32 mtk_prep_ib1_vlan_layer(struct mtk_eth *eth, u32 val)
-
- static inline u32 mtk_get_ib1_vlan_layer(struct mtk_eth *eth, u32 val)
- {
-- if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
-+ MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
- return FIELD_GET(MTK_FOE_IB1_BIND_VLAN_LAYER_V2, val);
-
- return FIELD_GET(MTK_FOE_IB1_BIND_VLAN_LAYER, val);
-@@ -1961,7 +1967,8 @@ static inline u32 mtk_get_ib1_vlan_layer(struct mtk_eth *eth, u32 val)
-
- static inline u32 mtk_get_ib1_pkt_type_mask(struct mtk_eth *eth)
- {
-- if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
-+ MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
- return MTK_FOE_IB1_PACKET_TYPE_V2;
-
- return MTK_FOE_IB1_PACKET_TYPE;
-@@ -1969,7 +1976,8 @@ static inline u32 mtk_get_ib1_pkt_type_mask(struct mtk_eth *eth)
-
- static inline u32 mtk_get_ib1_pkt_type(struct mtk_eth *eth, u32 val)
- {
-- if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
-+ MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
- return FIELD_GET(MTK_FOE_IB1_PACKET_TYPE_V2, val);
-
- return FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, val);
-@@ -1977,7 +1985,8 @@ static inline u32 mtk_get_ib1_pkt_type(struct mtk_eth *eth, u32 val)
-
- static inline u32 mtk_get_ib2_multicast_mask(struct mtk_eth *eth)
- {
-- if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
-+ MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
- return MTK_FOE_IB2_MULTICAST_V2;
-
- return MTK_FOE_IB2_MULTICAST;
-diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
-index b876411..c4a630d 100644
---- a/drivers/net/ethernet/mediatek/mtk_ppe.c
-+++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
-@@ -102,7 +102,7 @@ mtk_ppe_acct_data(struct mtk_ppe *ppe, u16 index)
- struct mtk_foe_accounting *mtk_ppe_mib_entry_read(struct mtk_ppe *ppe, u16 index)
- {
- u32 byte_cnt_low, byte_cnt_high, pkt_cnt_low, pkt_cnt_high;
-- u32 val, cnt_r0, cnt_r1, cnt_r2;
-+ u32 val, cnt_r0, cnt_r1, cnt_r2, cnt_r3;
- struct mtk_foe_accounting *acct;
- int ret;
-
-@@ -120,14 +120,26 @@ struct mtk_foe_accounting *mtk_ppe_mib_entry_read(struct mtk_ppe *ppe, u16 index
- cnt_r0 = readl(ppe->base + MTK_PPE_MIB_SER_R0);
- cnt_r1 = readl(ppe->base + MTK_PPE_MIB_SER_R1);
- cnt_r2 = readl(ppe->base + MTK_PPE_MIB_SER_R2);
-+ if (MTK_HAS_CAPS(ppe->eth->soc->caps, MTK_NETSYS_V3))
-+ cnt_r3 = readl(ppe->base + MTK_PPE_MIB_SER_R3);
-
-- byte_cnt_low = FIELD_GET(MTK_PPE_MIB_SER_R0_BYTE_CNT_LOW, cnt_r0);
-- byte_cnt_high = FIELD_GET(MTK_PPE_MIB_SER_R1_BYTE_CNT_HIGH, cnt_r1);
-- pkt_cnt_low = FIELD_GET(MTK_PPE_MIB_SER_R1_PKT_CNT_LOW, cnt_r1);
-- pkt_cnt_high = FIELD_GET(MTK_PPE_MIB_SER_R2_PKT_CNT_HIGH, cnt_r2);
-+ if (MTK_HAS_CAPS(ppe->eth->soc->caps, MTK_NETSYS_V3)) {
-+ byte_cnt_low = FIELD_GET(MTK_PPE_MIB_SER_R0_BYTE_CNT_LOW, cnt_r0);
-+ byte_cnt_high = FIELD_GET(MTK_PPE_MIB_SER_R1_BYTE_CNT_HIGH_V2, cnt_r1);
-+ pkt_cnt_low = FIELD_GET(MTK_PPE_MIB_SER_R2_PKT_CNT_LOW_V2, cnt_r2);
-+ pkt_cnt_high = FIELD_GET(MTK_PPE_MIB_SER_R3_PKT_CNT_HIGH_V2, cnt_r3);
-
-- acct->bytes += ((u64)byte_cnt_high << 32) | byte_cnt_low;
-- acct->packets += (pkt_cnt_high << 16) | pkt_cnt_low;
-+ acct->bytes += ((u64)byte_cnt_high << 32) | byte_cnt_low;
-+ acct->packets += ((u64)pkt_cnt_high << 32) | pkt_cnt_low;
-+ } else {
-+ byte_cnt_low = FIELD_GET(MTK_PPE_MIB_SER_R0_BYTE_CNT_LOW, cnt_r0);
-+ byte_cnt_high = FIELD_GET(MTK_PPE_MIB_SER_R1_BYTE_CNT_HIGH, cnt_r1);
-+ pkt_cnt_low = FIELD_GET(MTK_PPE_MIB_SER_R1_PKT_CNT_LOW, cnt_r1);
-+ pkt_cnt_high = FIELD_GET(MTK_PPE_MIB_SER_R2_PKT_CNT_HIGH, cnt_r2);
-+
-+ acct->bytes += ((u64)byte_cnt_high << 32) | byte_cnt_low;
-+ acct->packets += (pkt_cnt_high << 16) | pkt_cnt_low;
-+ }
-
- return acct;
- }
-@@ -186,6 +198,20 @@ static u32 mtk_ppe_hash_entry(struct mtk_eth *eth, struct mtk_foe_entry *e)
- return hash;
- }
-
-+static inline u16 *
-+mtk_foe_entry_tport(struct mtk_eth *eth, struct mtk_foe_entry *entry)
-+{
-+ int type = mtk_get_ib1_pkt_type(eth, entry->ib1);
-+
-+ if (type == MTK_PPE_PKT_TYPE_BRIDGE)
-+ return &entry->bridge.tport_id;
-+
-+ if (type >= MTK_PPE_PKT_TYPE_IPV4_DSLITE)
-+ return &entry->ipv6.tport_id;
-+
-+ return &entry->ipv4.tport_id;
-+}
-+
- static inline struct mtk_foe_mac_info *
- mtk_foe_entry_l2(struct mtk_eth *eth, struct mtk_foe_entry *entry)
- {
-@@ -223,7 +249,8 @@ int mtk_foe_entry_prepare(struct mtk_eth *eth, struct mtk_foe_entry *entry,
-
- memset(entry, 0, sizeof(*entry));
-
-- if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
-+ MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
- val = FIELD_PREP(MTK_FOE_IB1_STATE, MTK_FOE_STATE_BIND) |
- FIELD_PREP(MTK_FOE_IB1_PACKET_TYPE_V2, type) |
- FIELD_PREP(MTK_FOE_IB1_UDP, l4proto == IPPROTO_UDP) |
-@@ -287,7 +314,8 @@ int mtk_foe_entry_set_pse_port(struct mtk_eth *eth,
- u32 *ib2 = mtk_foe_entry_ib2(eth, entry);
- u32 val = *ib2;
-
-- if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
-+ MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
- val &= ~MTK_FOE_IB2_DEST_PORT_V2;
- val |= FIELD_PREP(MTK_FOE_IB2_DEST_PORT_V2, port);
- } else {
-@@ -438,7 +466,13 @@ int mtk_foe_entry_set_wdma(struct mtk_eth *eth, struct mtk_foe_entry *entry,
- struct mtk_foe_mac_info *l2 = mtk_foe_entry_l2(eth, entry);
- u32 *ib2 = mtk_foe_entry_ib2(eth, entry);
-
-- if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
-+ *ib2 &= ~MTK_FOE_IB2_PORT_MG_V2;
-+ *ib2 |= FIELD_PREP(MTK_FOE_IB2_RX_IDX, txq) |
-+ MTK_FOE_IB2_WDMA_WINFO_V2;
-+ l2->winfo_v2 = FIELD_PREP(MTK_FOE_WINFO_WCID_V2, wcid) |
-+ FIELD_PREP(MTK_FOE_WINFO_BSS_V2, bss);
-+ } else if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
- *ib2 &= ~MTK_FOE_IB2_PORT_MG_V2;
- *ib2 |= FIELD_PREP(MTK_FOE_IB2_RX_IDX, txq) |
- MTK_FOE_IB2_WDMA_WINFO_V2;
-@@ -468,7 +502,12 @@ int mtk_foe_entry_set_queue(struct mtk_eth *eth, struct mtk_foe_entry *entry,
- {
- u32 *ib2 = mtk_foe_entry_ib2(eth, entry);
-
-- if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
-+ u16 *tport_id = mtk_foe_entry_tport(eth, entry);
-+ *ib2 &= ~MTK_FOE_IB2_QID_V2;
-+ *ib2 |= FIELD_PREP(MTK_FOE_IB2_QID_V2, queue);
-+ *tport_id = 1;
-+ } else if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
- *ib2 &= ~MTK_FOE_IB2_QID_V2;
- *ib2 |= FIELD_PREP(MTK_FOE_IB2_QID_V2, queue);
- *ib2 |= MTK_FOE_IB2_PSE_QOS_V2;
-@@ -648,7 +687,8 @@ __mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_foe_entry *entry,
- struct mtk_foe_entry *hwe;
- u32 val;
-
-- if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
-+ MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
- entry->ib1 &= ~MTK_FOE_IB1_BIND_TIMESTAMP_V2;
- entry->ib1 |= FIELD_PREP(MTK_FOE_IB1_BIND_TIMESTAMP_V2,
- timestamp);
-@@ -664,7 +704,8 @@ __mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_foe_entry *entry,
- hwe->ib1 = entry->ib1;
-
- if (ppe->accounting) {
-- if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
-+ MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
- val = MTK_FOE_IB2_MIB_CNT_V2;
- else
- val = MTK_FOE_IB2_MIB_CNT;
-@@ -958,7 +999,7 @@ static void mtk_ppe_init_foe_table(struct mtk_ppe *ppe)
-
- void mtk_ppe_start(struct mtk_ppe *ppe)
- {
-- u32 val;
-+ u32 val = 0;
-
- if (!ppe)
- return;
-@@ -966,22 +1007,24 @@ void mtk_ppe_start(struct mtk_ppe *ppe)
- mtk_ppe_init_foe_table(ppe);
- ppe_w32(ppe, MTK_PPE_TB_BASE, ppe->foe_phys);
-
-- val = MTK_PPE_TB_CFG_ENTRY_80B |
-- MTK_PPE_TB_CFG_AGE_NON_L4 |
-- MTK_PPE_TB_CFG_AGE_UNBIND |
-- MTK_PPE_TB_CFG_AGE_TCP |
-- MTK_PPE_TB_CFG_AGE_UDP |
-- MTK_PPE_TB_CFG_AGE_TCP_FIN |
-- FIELD_PREP(MTK_PPE_TB_CFG_SEARCH_MISS,
-- MTK_PPE_SEARCH_MISS_ACTION_FORWARD_BUILD) |
-- FIELD_PREP(MTK_PPE_TB_CFG_KEEPALIVE,
-- MTK_PPE_KEEPALIVE_DISABLE) |
-- FIELD_PREP(MTK_PPE_TB_CFG_HASH_MODE, 1) |
-- FIELD_PREP(MTK_PPE_TB_CFG_SCAN_MODE,
-- MTK_PPE_SCAN_MODE_KEEPALIVE_AGE) |
-- FIELD_PREP(MTK_PPE_TB_CFG_ENTRY_NUM,
-- MTK_PPE_ENTRIES_SHIFT);
-- if (MTK_HAS_CAPS(ppe->eth->soc->caps, MTK_NETSYS_V2))
-+ if (!MTK_HAS_CAPS(ppe->eth->soc->caps, MTK_NETSYS_V3))
-+ val |= MTK_PPE_TB_CFG_ENTRY_80B;
-+ val |= MTK_PPE_TB_CFG_AGE_NON_L4 |
-+ MTK_PPE_TB_CFG_AGE_UNBIND |
-+ MTK_PPE_TB_CFG_AGE_TCP |
-+ MTK_PPE_TB_CFG_AGE_UDP |
-+ MTK_PPE_TB_CFG_AGE_TCP_FIN |
-+ FIELD_PREP(MTK_PPE_TB_CFG_SEARCH_MISS,
-+ MTK_PPE_SEARCH_MISS_ACTION_FORWARD_BUILD) |
-+ FIELD_PREP(MTK_PPE_TB_CFG_KEEPALIVE,
-+ MTK_PPE_KEEPALIVE_DISABLE) |
-+ FIELD_PREP(MTK_PPE_TB_CFG_HASH_MODE, 1) |
-+ FIELD_PREP(MTK_PPE_TB_CFG_SCAN_MODE,
-+ MTK_PPE_SCAN_MODE_KEEPALIVE_AGE) |
-+ FIELD_PREP(MTK_PPE_TB_CFG_ENTRY_NUM,
-+ MTK_PPE_ENTRIES_SHIFT);
-+ if (MTK_HAS_CAPS(ppe->eth->soc->caps, MTK_NETSYS_V2) ||
-+ MTK_HAS_CAPS(ppe->eth->soc->caps, MTK_NETSYS_V3))
- val |= MTK_PPE_TB_CFG_INFO_SEL;
- ppe_w32(ppe, MTK_PPE_TB_CFG, val);
-
-@@ -997,7 +1040,8 @@ void mtk_ppe_start(struct mtk_ppe *ppe)
- MTK_PPE_FLOW_CFG_IP4_NAPT |
- MTK_PPE_FLOW_CFG_IP4_DSLITE |
- MTK_PPE_FLOW_CFG_IP4_NAT_FRAG;
-- if (MTK_HAS_CAPS(ppe->eth->soc->caps, MTK_NETSYS_V2))
-+ if (MTK_HAS_CAPS(ppe->eth->soc->caps, MTK_NETSYS_V2) ||
-+ MTK_HAS_CAPS(ppe->eth->soc->caps, MTK_NETSYS_V3))
- val |= MTK_PPE_MD_TOAP_BYP_CRSN0 |
- MTK_PPE_MD_TOAP_BYP_CRSN1 |
- MTK_PPE_MD_TOAP_BYP_CRSN2 |
-diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
-index fd7ece7..ba71884 100644
---- a/drivers/net/ethernet/mediatek/mtk_ppe.h
-+++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
-@@ -85,6 +85,18 @@ enum {
- #define MTK_FOE_WINFO_BSS GENMASK(5, 0)
- #define MTK_FOE_WINFO_WCID GENMASK(15, 6)
-
-+/* CONFIG_MEDIATEK_NETSYS_V3 */
-+#define MTK_FOE_WINFO_WCID_V2 GENMASK(15, 0)
-+#define MTK_FOE_WINFO_BSS_V2 GENMASK(23, 16)
-+
-+#define MTK_FOE_WINFO_PAO_USR_INFO GENMASK(15, 0)
-+#define MTK_FOE_WINFO_PAO_TID GENMASK(19, 16)
-+#define MTK_FOE_WINFO_PAO_IS_FIXEDRATE BIT(20)
-+#define MTK_FOE_WINFO_PAO_IS_PRIOR BIT(21)
-+#define MTK_FOE_WINFO_PAO_IS_SP BIT(22)
-+#define MTK_FOE_WINFO_PAO_HF BIT(23)
-+#define MTK_FOE_WINFO_PAO_AMSDU_EN BIT(24)
-+
- enum {
- MTK_FOE_STATE_INVALID,
- MTK_FOE_STATE_UNBIND,
-@@ -106,8 +118,18 @@ struct mtk_foe_mac_info {
- u16 pppoe_id;
- u16 src_mac_lo;
-
-- u16 minfo;
-- u16 winfo;
-+ union {
-+ struct {
-+ u16 minfo;
-+ u16 winfo;
-+ };
-+ struct {
-+ u16 minfo_v2;
-+ u16 _rsv0;
-+ u32 winfo_v2;
-+ u32 winfo_pao;
-+ };
-+ };
- };
-
- /* software-only entry type */
-@@ -121,6 +143,10 @@ struct mtk_foe_bridge {
- u32 ib2;
-
- struct mtk_foe_mac_info l2;
-+
-+ u8 cdrt_id;
-+ u8 tops_entry;
-+ u16 tport_id;
- };
-
- struct mtk_ipv4_tuple {
-@@ -152,6 +178,10 @@ struct mtk_foe_ipv4 {
- u32 udf_tsid;
-
- struct mtk_foe_mac_info l2;
-+
-+ u8 cdrt_id;
-+ u8 tops_entry;
-+ u16 tport_id;
- };
-
- struct mtk_foe_ipv4_dslite {
-@@ -168,6 +198,10 @@ struct mtk_foe_ipv4_dslite {
- u32 ib2;
-
- struct mtk_foe_mac_info l2;
-+
-+ u8 cdrt_id;
-+ u8 tops_entry;
-+ u16 tport_id;
- };
-
- struct mtk_foe_ipv6 {
-@@ -192,6 +226,10 @@ struct mtk_foe_ipv6 {
-
- u32 ib2;
- struct mtk_foe_mac_info l2;
-+
-+ u8 cdrt_id;
-+ u8 tops_entry;
-+ u16 tport_id;
- };
-
- struct mtk_foe_ipv6_6rd {
-@@ -214,6 +252,10 @@ struct mtk_foe_ipv6_6rd {
-
- u32 ib2;
- struct mtk_foe_mac_info l2;
-+
-+ u8 cdrt_id;
-+ u8 tops_entry;
-+ u16 tport_id;
- };
-
- struct mtk_foe_entry {
-@@ -225,7 +267,7 @@ struct mtk_foe_entry {
- struct mtk_foe_ipv4_dslite dslite;
- struct mtk_foe_ipv6 ipv6;
- struct mtk_foe_ipv6_6rd ipv6_6rd;
-- u32 data[23];
-+ u32 data[31];
- };
- };
-
-diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
-old mode 100755
-new mode 100644
-index 70f6374..8a20dce
---- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
-+++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
-@@ -194,19 +194,20 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
- if (mtk_flow_get_wdma_info(dev, dest_mac, &info) == 0) {
- mtk_foe_entry_set_wdma(eth, foe, info.wdma_idx, info.queue,
- info.bss, info.wcid);
-- if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
-+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
-+ MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
- switch (info.wdma_idx) {
- case 0:
-- pse_port = 8;
-+ pse_port = PSE_WDMA0_PORT;
- break;
- case 1:
-- pse_port = 9;
-+ pse_port = PSE_WDMA1_PORT;
- break;
- default:
- return -EINVAL;
- }
- } else {
-- pse_port = 3;
-+ pse_port = PSE_PPE0_PORT;
- }
- *wed_index = info.wdma_idx;
- goto out;
-@@ -215,9 +216,11 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
- dsa_port = mtk_flow_get_dsa_port(&dev);
-
- if (dev == eth->netdev[0])
-- pse_port = 1;
-+ pse_port = PSE_GDM1_PORT;
- else if (dev == eth->netdev[1])
-- pse_port = 2;
-+ pse_port = PSE_GDM2_PORT;
-+ else if (dev == eth->netdev[2])
-+ pse_port = PSE_GDM3_PORT;
- else
- return -EOPNOTSUPP;
-
-@@ -462,7 +465,8 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f,
-
- ctx.dev = idev;
- idev->netdev_ops->ndo_fill_receive_path(&ctx, &path);
-- num_ppe = MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ? 2 : 1;
-+ num_ppe = MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3) ? 3 :
-+ MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ? 2 : 1;
- num_ppe = min_t(u32, ARRAY_SIZE(eth->ppe), num_ppe);
- ppe_index = path.mtk_wdma.wdma_idx;
- if (ppe_index >= num_ppe) {
-diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_regs.h b/drivers/net/ethernet/mediatek/mtk_ppe_regs.h
-index a2e61b3..96e50b1 100644
---- a/drivers/net/ethernet/mediatek/mtk_ppe_regs.h
-+++ b/drivers/net/ethernet/mediatek/mtk_ppe_regs.h
-@@ -159,9 +159,14 @@ enum {
- #define MTK_PPE_MIB_SER_R1 0x344
- #define MTK_PPE_MIB_SER_R1_PKT_CNT_LOW GENMASK(31, 16)
- #define MTK_PPE_MIB_SER_R1_BYTE_CNT_HIGH GENMASK(15, 0)
-+#define MTK_PPE_MIB_SER_R1_BYTE_CNT_HIGH_V2 GENMASK(31, 0)
-
- #define MTK_PPE_MIB_SER_R2 0x348
- #define MTK_PPE_MIB_SER_R2_PKT_CNT_HIGH GENMASK(23, 0)
-+#define MTK_PPE_MIB_SER_R2_PKT_CNT_LOW_V2 GENMASK(31, 0)
-+
-+#define MTK_PPE_MIB_SER_R3 0x34C
-+#define MTK_PPE_MIB_SER_R3_PKT_CNT_HIGH_V2 GENMASK(31, 0)
-
- #define MTK_PPE_MIB_CACHE_CTL 0x350
- #define MTK_PPE_MIB_CACHE_CTL_EN BIT(0)
---
-2.18.0
-
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3011-flow-offload-add-mtkhnat-qdma-qos.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3014-flow-offload-add-mtkhnat-qdma-qos.patch
similarity index 86%
rename from autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3011-flow-offload-add-mtkhnat-qdma-qos.patch
rename to autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3014-flow-offload-add-mtkhnat-qdma-qos.patch
index e63a8bd..570fbcd 100755
--- a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3011-flow-offload-add-mtkhnat-qdma-qos.patch
+++ b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3014-flow-offload-add-mtkhnat-qdma-qos.patch
@@ -1,22 +1,5 @@
-From 6db71c3a156368394f728fc35f4c194da9888df7 Mon Sep 17 00:00:00 2001
-From: Bo-Cun Chen <bc-bocun.chen@mediatek.com>
-Date: Tue, 13 Jun 2023 17:07:23 +0800
-Subject: [PATCH] 999-3011-flow-offload-add-mtkhnat-qdma-qos
-
----
- drivers/net/ethernet/mediatek/Makefile | 2 +-
- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 10 +
- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 34 +-
- .../net/ethernet/mediatek/mtk_ppe_offload.c | 16 +-
- .../net/ethernet/mediatek/mtk_qdma_debugfs.c | 435 ++++++++++++++++++
- include/net/flow_offload.h | 1 +
- net/netfilter/nf_flow_table_offload.c | 4 +-
- 7 files changed, 492 insertions(+), 10 deletions(-)
- mode change 100644 => 100755 drivers/net/ethernet/mediatek/mtk_ppe_offload.c
- 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
-index 498c002..ec3b305 100644
+index 0c724a5..93cd55f 100644
--- a/drivers/net/ethernet/mediatek/Makefile
+++ b/drivers/net/ethernet/mediatek/Makefile
@@ -5,7 +5,7 @@
@@ -29,11 +12,11 @@
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 d3f445a..f22a11a 100644
+index ca76047..809c735 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -4904,6 +4904,8 @@ static int mtk_probe(struct platform_device *pdev)
- goto err_free_dev;
+@@ -4787,6 +4787,8 @@ static int mtk_probe(struct platform_device *pdev)
+ }
mtk_ppe_debugfs_init(eth);
+
@@ -41,7 +24,7 @@
}
for (i = 0; i < MTK_MAX_DEVS; i++) {
-@@ -5020,6 +5022,7 @@ static const struct mtk_soc_data mt2701_data = {
+@@ -4901,6 +4903,7 @@ static const struct mtk_soc_data mt2701_data = {
.rx_dma_l4_valid = RX_DMA_L4_VALID,
.dma_max_len = MTK_TX_DMA_BUF_LEN,
.dma_len_offset = MTK_TX_DMA_BUF_SHIFT,
@@ -49,7 +32,7 @@
},
};
-@@ -5041,6 +5044,7 @@ static const struct mtk_soc_data mt7621_data = {
+@@ -4920,6 +4923,7 @@ static const struct mtk_soc_data mt7621_data = {
.rxd_size = sizeof(struct mtk_rx_dma),
.dma_max_len = MTK_TX_DMA_BUF_LEN,
.dma_len_offset = MTK_TX_DMA_BUF_SHIFT,
@@ -57,7 +40,7 @@
},
};
-@@ -5063,6 +5067,7 @@ static const struct mtk_soc_data mt7622_data = {
+@@ -4940,6 +4944,7 @@ static const struct mtk_soc_data mt7622_data = {
.rx_dma_l4_valid = RX_DMA_L4_VALID,
.dma_max_len = MTK_TX_DMA_BUF_LEN,
.dma_len_offset = MTK_TX_DMA_BUF_SHIFT,
@@ -65,7 +48,7 @@
},
};
-@@ -5084,6 +5089,7 @@ static const struct mtk_soc_data mt7623_data = {
+@@ -4959,6 +4964,7 @@ static const struct mtk_soc_data mt7623_data = {
.rx_dma_l4_valid = RX_DMA_L4_VALID,
.dma_max_len = MTK_TX_DMA_BUF_LEN,
.dma_len_offset = MTK_TX_DMA_BUF_SHIFT,
@@ -73,7 +56,7 @@
},
};
-@@ -5128,6 +5134,7 @@ static const struct mtk_soc_data mt7986_data = {
+@@ -4997,6 +5003,7 @@ static const struct mtk_soc_data mt7986_data = {
.rx_dma_l4_valid = RX_DMA_L4_VALID_V2,
.dma_max_len = MTK_TX_DMA_BUF_LEN_V2,
.dma_len_offset = MTK_TX_DMA_BUF_SHIFT_V2,
@@ -81,7 +64,7 @@
},
};
-@@ -5150,6 +5157,7 @@ static const struct mtk_soc_data mt7981_data = {
+@@ -5017,6 +5024,7 @@ static const struct mtk_soc_data mt7981_data = {
.rx_dma_l4_valid = RX_DMA_L4_VALID_V2,
.dma_max_len = MTK_TX_DMA_BUF_LEN_V2,
.dma_len_offset = MTK_TX_DMA_BUF_SHIFT_V2,
@@ -89,7 +72,7 @@
},
};
-@@ -5168,6 +5176,7 @@ static const struct mtk_soc_data mt7988_data = {
+@@ -5034,6 +5042,7 @@ static const struct mtk_soc_data mt7988_data = {
.rx_dma_l4_valid = RX_DMA_L4_VALID_V2,
.dma_max_len = MTK_TX_DMA_BUF_LEN_V2,
.dma_len_offset = MTK_TX_DMA_BUF_SHIFT_V2,
@@ -97,7 +80,7 @@
},
};
-@@ -5189,6 +5198,7 @@ static const struct mtk_soc_data rt5350_data = {
+@@ -5051,6 +5060,7 @@ static const struct mtk_soc_data rt5350_data = {
.rx_dma_l4_valid = RX_DMA_L4_VALID_PDMA,
.dma_max_len = MTK_TX_DMA_BUF_LEN,
.dma_len_offset = MTK_TX_DMA_BUF_SHIFT,
@@ -106,10 +89,10 @@
};
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-index 1e9a1af..c85f573 100644
+index c6afff5..bd73c27 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-@@ -382,10 +382,21 @@
+@@ -385,10 +385,21 @@
/* QDMA TX Queue Configuration Registers */
#define MTK_QTX_CFG(x) (QDMA_BASE + (x * 0x10))
@@ -131,7 +114,7 @@
/* QDMA RX Base Pointer Register */
#define MTK_QRX_BASE_PTR0 (QDMA_BASE + 0x100)
-@@ -403,7 +414,9 @@
+@@ -406,7 +417,9 @@
#define MTK_QRX_DRX_IDX0 (QDMA_BASE + 0x10c)
/* QDMA Page Configuration Register */
@@ -142,7 +125,7 @@
/* QDMA Global Configuration Register */
#define MTK_QDMA_GLO_CFG (QDMA_BASE + 0x204)
-@@ -440,6 +453,9 @@
+@@ -443,6 +456,9 @@
#define FC_THRES_DROP_EN (7 << 16)
#define FC_THRES_MIN 0x4444
@@ -151,8 +134,8 @@
+
/* QDMA Interrupt Status Register */
#define MTK_QDMA_INT_STATUS (QDMA_BASE + 0x218)
- #if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
-@@ -476,6 +492,11 @@
+ #if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
+@@ -478,6 +494,11 @@
/* QDMA Interrupt Mask Register */
#define MTK_QDMA_HRED2 (QDMA_BASE + 0x244)
@@ -164,7 +147,7 @@
/* QDMA TX Forward CPU Pointer Register */
#define MTK_QTX_CTX_PTR (QDMA_BASE +0x300)
-@@ -503,6 +524,14 @@
+@@ -505,6 +526,14 @@
/* QDMA FQ Free Page Buffer Length Register */
#define MTK_QDMA_FQ_BLEN (QDMA_BASE +0x32c)
@@ -179,7 +162,7 @@
/* WDMA Registers */
#define MTK_WDMA_CTX_PTR(x) (WDMA_BASE(x) + 0x8)
#define MTK_WDMA_DTX_PTR(x) (WDMA_BASE(x) + 0xC)
-@@ -1650,6 +1679,7 @@ struct mtk_soc_data {
+@@ -1596,6 +1625,7 @@ struct mtk_soc_data {
u32 rx_dma_l4_valid;
u32 dma_max_len;
u32 dma_len_offset;
@@ -187,25 +170,56 @@
} txrx;
};
-@@ -1835,6 +1865,7 @@ struct mtk_eth {
+@@ -1736,6 +1766,7 @@ struct mtk_eth {
spinlock_t syscfg0_lock;
struct timer_list mtk_dma_monitor_timer;
+ u8 qos_toggle;
- struct mtk_ppe *ppe[2];
+ u8 ppe_num;
+ struct mtk_ppe *ppe[MTK_MAX_PPE_NUM];
struct rhashtable flow_table;
- };
-@@ -1982,5 +2013,6 @@ int mtk_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,
- void *type_data);
+@@ -1815,4 +1846,6 @@ int mtk_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,
void mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev);
+
int mtk_ppe_debugfs_init(struct mtk_eth *eth);
++
+int mtk_qdma_debugfs_init(struct mtk_eth *eth);
- int mtk_rss_set_indr_tbl(struct mtk_eth *eth, int num);
#endif /* MTK_ETH_H */
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
+index a49275f..1767823 100755
+--- a/drivers/net/ethernet/mediatek/mtk_ppe.c
++++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
+@@ -406,6 +406,16 @@ int mtk_foe_entry_set_wdma(struct mtk_foe_entry *entry, int wdma_idx, int txq,
+ return 0;
+ }
+
++int mtk_foe_entry_set_qid(struct mtk_foe_entry *entry, int qid)
++{
++ u32 *ib2 = mtk_foe_entry_ib2(entry);
++
++ *ib2 &= ~MTK_FOE_IB2_QID;
++ *ib2 |= FIELD_PREP(MTK_FOE_IB2_QID, qid);
++ *ib2 |= MTK_FOE_IB2_PSE_QOS;
++
++ return 0;
++}
+ static inline bool mtk_foe_entry_usable(struct mtk_foe_entry *entry)
+ {
+ return !(entry->ib1 & MTK_FOE_IB1_STATIC) &&
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
+index 8076e5d..c46c4d9 100644
+--- a/drivers/net/ethernet/mediatek/mtk_ppe.h
++++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
+@@ -356,6 +356,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_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);
+ 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);
diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
-old mode 100644
-new mode 100755
-index aa30abb..70f6374
+index f258539..3b17819 100755
--- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
+++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
@@ -9,6 +9,8 @@
@@ -226,36 +240,69 @@
int *wed_index)
{
struct mtk_wdma_info info = {};
-@@ -219,12 +221,12 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe,
- else
- return -EOPNOTSUPP;
+@@ -211,6 +211,11 @@ 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);
-- if (dsa_port >= 0) {
-+ if (dsa_port >= 0)
- mtk_foe_entry_set_dsa(eth, foe, dsa_port);
-- queue = 3 + dsa_port;
-- } else {
-- queue = pse_port - 1;
-- }
+ if (eth->qos_toggle == 1 || ct->mark >= 6)
-+ queue = ct->mark & MTK_QDMA_TX_MASK;
++ mtk_foe_entry_set_qid(foe, ct->mark & MTK_QDMA_TX_MASK);
+ if (eth->qos_toggle == 2 && dsa_port >= 0)
-+ queue = dsa_port & MTK_QDMA_TX_MASK;
- mtk_foe_entry_set_queue(eth, foe, queue);
-
- out:
-@@ -443,7 +445,7 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f,
++ mtk_foe_entry_set_qid(foe, dsa_port & MTK_QDMA_TX_MASK);
++
+ if (dev == eth->netdev[0])
+ pse_port = PSE_GDM1_PORT;
+ else if (dev == eth->netdev[1])
+@@ -433,7 +443,7 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
if (data.pppoe.num == 1)
- mtk_foe_entry_set_pppoe(eth, &foe, data.pppoe.sid);
+ mtk_foe_entry_set_pppoe(&foe, data.pppoe.sid);
- err = mtk_flow_set_output_device(eth, &foe, odev, data.eth.h_dest,
+ err = mtk_flow_set_output_device(eth, &foe, odev, f->flow->ct, data.eth.h_dest,
&wed_index);
if (err)
return err;
+diff --git a/include/net/flow_offload.h b/include/net/flow_offload.h
+index 59b8736..7261b6d 100644
+--- a/include/net/flow_offload.h
++++ b/include/net/flow_offload.h
+@@ -365,6 +378,7 @@ struct flow_cls_offload {
+ struct flow_cls_common_offload common;
+ enum flow_cls_command command;
+ unsigned long cookie;
++ struct flow_offload *flow;
+ struct flow_rule *rule;
+ struct flow_stats stats;
+ u32 classid;
+diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
+index d94c6fb..886ced5 100644
+--- a/net/netfilter/nf_flow_table_offload.c
++++ b/net/netfilter/nf_flow_table_offload.c
+@@ -810,11 +810,13 @@ static int nf_flow_offload_alloc(const struct flow_offload_work *offload,
+ }
+
+ static void nf_flow_offload_init(struct flow_cls_offload *cls_flow,
++ struct flow_offload *flow,
+ __be16 proto, int priority,
+ enum flow_cls_command cmd,
+ const struct flow_offload_tuple *tuple,
+ struct netlink_ext_ack *extack)
+ {
++ cls_flow->flow = flow;
+ cls_flow->common.protocol = proto;
+ cls_flow->common.prio = priority;
+ cls_flow->common.extack = extack;
+@@ -836,7 +838,7 @@ static int nf_flow_offload_tuple(struct nf_flowtable *flowtable,
+ __be16 proto = ETH_P_ALL;
+ int err, i = 0;
+
+- nf_flow_offload_init(&cls_flow, proto, priority, cmd,
++ nf_flow_offload_init(&cls_flow, flow, proto, priority, cmd,
+ &flow->tuplehash[dir].tuple, &extack);
+ if (cmd == FLOW_CLS_REPLACE)
+ cls_flow.rule = flow_rule->rule;
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..501cd2b
+index 0000000..198b924
--- /dev/null
+++ b/drivers/net/ethernet/mediatek/mtk_qdma_debugfs.c
@@ -0,0 +1,435 @@
@@ -694,45 +741,3 @@
+
+ return 0;
+}
-diff --git a/include/net/flow_offload.h b/include/net/flow_offload.h
-index 59b8736..c4eb45c 100644
---- a/include/net/flow_offload.h
-+++ b/include/net/flow_offload.h
-@@ -365,6 +365,7 @@ struct flow_cls_offload {
- struct flow_cls_common_offload common;
- enum flow_cls_command command;
- unsigned long cookie;
-+ struct flow_offload *flow;
- struct flow_rule *rule;
- struct flow_stats stats;
- u32 classid;
-diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
-index 197f48a..2927dbc 100644
---- a/net/netfilter/nf_flow_table_offload.c
-+++ b/net/netfilter/nf_flow_table_offload.c
-@@ -809,11 +809,13 @@ static int nf_flow_offload_alloc(const struct flow_offload_work *offload,
- }
-
- static void nf_flow_offload_init(struct flow_cls_offload *cls_flow,
-+ struct flow_offload *flow,
- __be16 proto, int priority,
- enum flow_cls_command cmd,
- const struct flow_offload_tuple *tuple,
- struct netlink_ext_ack *extack)
- {
-+ cls_flow->flow = flow;
- cls_flow->common.protocol = proto;
- cls_flow->common.prio = priority;
- cls_flow->common.extack = extack;
-@@ -835,7 +837,7 @@ static int nf_flow_offload_tuple(struct nf_flowtable *flowtable,
- __be16 proto = ETH_P_ALL;
- int err, i = 0;
-
-- nf_flow_offload_init(&cls_flow, proto, priority, cmd,
-+ nf_flow_offload_init(&cls_flow, flow, proto, priority, cmd,
- &flow->tuplehash[dir].tuple, &extack);
- if (cmd == FLOW_CLS_REPLACE)
- cls_flow.rule = flow_rule->rule;
---
-2.18.0
-
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3012-flow-offload-ovs-support.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3015-flow-offload-ovs-support.patch
similarity index 75%
rename from autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3012-flow-offload-ovs-support.patch
rename to autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3015-flow-offload-ovs-support.patch
index b9c0831..04e22a4 100755
--- a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3012-flow-offload-ovs-support.patch
+++ b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3015-flow-offload-ovs-support.patch
@@ -1,20 +1,11 @@
-From 81ebcc8c2e1f6c95c1bb27b1c74003277321cf2d Mon Sep 17 00:00:00 2001
-From: Bo-Cun Chen <bc-bocun.chen@mediatek.com>
-Date: Tue, 13 Jun 2023 17:08:22 +0800
-Subject: [PATCH] 999-3012-flow-offload-ovs-support
-
----
- net/openvswitch/vport-internal_dev.c | 46 ++++++++++++++++++++++++++++
- 1 file changed, 46 insertions(+)
-
-diff --git a/net/openvswitch/vport-internal_dev.c b/net/openvswitch/vport-internal_dev.c
-index 58a7b83..8475727 100644
+Index: net/openvswitch/vport-internal_dev.c
+===================================================================
--- a/net/openvswitch/vport-internal_dev.c
+++ b/net/openvswitch/vport-internal_dev.c
-@@ -113,12 +113,58 @@ internal_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats)
+@@ -113,12 +113,58 @@ internal_get_stats(struct net_device *de
}
}
-
+
+static int internal_dev_fill_forward_path(struct net_device_path_ctx *ctx, struct net_device_path *path)
+{
+ struct vport *vport;
@@ -68,8 +59,5 @@
.ndo_get_stats64 = internal_get_stats,
+ .ndo_fill_forward_path = internal_dev_fill_forward_path,
};
-
- static struct rtnl_link_ops internal_dev_link_ops __read_mostly = {
---
-2.18.0
+ static struct rtnl_link_ops internal_dev_link_ops __read_mostly = {
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3013-update-net-bridge-for-bridger.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3016-update-net-bridge-for-bridger.patch
similarity index 98%
rename from autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3013-update-net-bridge-for-bridger.patch
rename to autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3016-update-net-bridge-for-bridger.patch
index d913268..6fe3733 100755
--- a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3013-update-net-bridge-for-bridger.patch
+++ b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3016-update-net-bridge-for-bridger.patch
@@ -1,23 +1,3 @@
-From 8a33aae934a08e28dd1e924de1fdfd76f7ddbbd9 Mon Sep 17 00:00:00 2001
-From: Bo-Cun Chen <bc-bocun.chen@mediatek.com>
-Date: Tue, 13 Jun 2023 17:09:45 +0800
-Subject: [PATCH] 999-3013-update-net-bridge-for-bridger
-
----
- include/net/switchdev.h | 2 +
- net/bridge/Makefile | 2 +-
- net/bridge/br_mdb.c | 32 +-
- net/bridge/br_netlink.c | 6 +-
- net/bridge/br_netlink_tunnel.c | 4 +-
- net/bridge/br_private.h | 293 +++++++++++++-
- net/bridge/br_private_tunnel.h | 4 +
- net/bridge/br_vlan.c | 698 +++++++++++++++++++++++++++++++--
- net/bridge/br_vlan_options.c | 346 ++++++++++++++++
- net/core/rtnetlink.c | 1 +
- net/dsa/slave.c | 11 +
- 11 files changed, 1365 insertions(+), 34 deletions(-)
- create mode 100644 net/bridge/br_vlan_options.c
-
diff --git a/include/net/switchdev.h b/include/net/switchdev.h
index 191dc34..d4d71d9 100644
--- a/include/net/switchdev.h
@@ -1806,7 +1786,7 @@
+ return false;
+}
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
-index dbc9b2f..e12590e 100644
+index dbc9b2f..706b207 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1996,6 +1996,7 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
@@ -1841,6 +1821,3 @@
out_phy:
rtnl_lock();
phylink_disconnect_phy(p->dp->pl);
---
-2.18.0
-
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3017-ethernet-update-ppe-from-mt7986-to-mt7988.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3017-ethernet-update-ppe-from-mt7986-to-mt7988.patch
new file mode 100755
index 0000000..d9af44d
--- /dev/null
+++ b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3017-ethernet-update-ppe-from-mt7986-to-mt7988.patch
@@ -0,0 +1,249 @@
+diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+index 4075ec2..524c5d9 100644
+--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
++++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+@@ -1796,17 +1796,17 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
+ skb_checksum_none_assert(skb);
+ skb->protocol = eth_type_trans(skb, netdev);
+
+-#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2)
+- hash = trxd.rxd5 & MTK_RXD5_FOE_ENTRY_V2;
++#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
++ hash = trxd.rxd5 & MTK_RXD5_FOE_ENTRY_V2;
+ #else
+- hash = trxd.rxd4 & MTK_RXD4_FOE_ENTRY;
++ hash = trxd.rxd4 & MTK_RXD4_FOE_ENTRY;
+ #endif
+ if (hash != MTK_RXD4_FOE_ENTRY) {
+ hash = jhash_1word(hash, 0);
+ skb_set_hash(skb, hash, PKT_HASH_TYPE_L4);
+ }
+
+-#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2)
++#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
+ reason = FIELD_GET(MTK_RXD5_PPE_CPU_REASON_V2, trxd.rxd5);
+ if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED) {
+ for (i = 0; i < eth->ppe_num; i++) {
+@@ -4448,7 +4448,8 @@ static int mtk_probe(struct platform_device *pdev)
+
+ for (i = 0; i < eth->ppe_num; i++) {
+ eth->ppe[i] = mtk_ppe_init(eth,
+- eth->base + MTK_ETH_PPE_BASE + i * 0x400,
++ eth->base + MTK_ETH_PPE_BASE +
++ (i == 2 ? 0xC00 : i * 0x400),
+ 2, eth->soc->hash_way, i,
+ eth->soc->has_accounting);
+ if (!eth->ppe[i]) {
+@@ -4626,13 +4626,16 @@ static const struct mtk_soc_data mt7988_data = {
+ .required_clks = MT7988_CLKS_BITMAP,
+ .required_pctl = false,
+ .has_sram = true,
++ .has_accounting = true,
++ .hash_way = 4,
++ .offload_version = 2,
+ .rss_num = 4,
+ .txrx = {
+ .txd_size = sizeof(struct mtk_tx_dma_v2),
+ .rxd_size = sizeof(struct mtk_rx_dma_v2),
+ .rx_dma_l4_valid = RX_DMA_L4_VALID_V2,
+ .dma_max_len = MTK_TX_DMA_BUF_LEN_V2,
+ .dma_len_offset = MTK_TX_DMA_BUF_SHIFT_V2,
+ .qdma_tx_sch = 4,
+ },
+ };
+diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
+index 5b39d87..94bd423 100644
+--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
++++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
+@@ -118,7 +118,8 @@
+ #define MTK_GDMA_UCS_EN BIT(20)
+ #define MTK_GDMA_STRP_CRC BIT(16)
+ #define MTK_GDMA_TO_PDMA 0x0
+-#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++#if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
+ #define MTK_GDMA_TO_PPE0 0x3333
+ #define MTK_GDMA_TO_PPE1 0x4444
++#define MTK_GMAC_TO_PPE2 0xcccc
+ #else
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
+index 98f61fe..bd504d4 100755
+--- a/drivers/net/ethernet/mediatek/mtk_ppe.c
++++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
+@@ -211,7 +211,7 @@ int mtk_foe_entry_prepare(struct mtk_foe_entry *entry, int type, int l4proto,
+ MTK_FOE_IB1_BIND_CACHE;
+ entry->ib1 = val;
+
+-#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++#if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
+ val = FIELD_PREP(MTK_FOE_IB2_PORT_AG, 0xf) |
+ #else
+ val = FIELD_PREP(MTK_FOE_IB2_PORT_MG, 0x3f) |
+@@ -403,7 +403,7 @@ int mtk_foe_entry_set_wdma(struct mtk_foe_entry *entry, int wdma_idx, int txq,
+
+ *ib2 &= ~MTK_FOE_IB2_PORT_MG;
+ *ib2 |= MTK_FOE_IB2_WDMA_WINFO;
+-#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++#if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
+ *ib2 |= FIELD_PREP(MTK_FOE_IB2_RX_IDX, txq);
+
+ l2->winfo = FIELD_PREP(MTK_FOE_WINFO_WCID, wcid) |
+@@ -422,11 +422,16 @@ 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)
+ {
++ struct mtk_foe_mac_info *l2 = mtk_foe_entry_l2(entry);
+ u32 *ib2 = mtk_foe_entry_ib2(entry);
+
+ *ib2 &= ~MTK_FOE_IB2_QID;
+ *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;
+ }
+@@ -867,13 +867,16 @@ int mtk_ppe_start(struct mtk_ppe *ppe)
+ mtk_ppe_init_foe_table(ppe);
+ ppe_w32(ppe, MTK_PPE_TB_BASE, ppe->foe_phys);
+
+- val = MTK_PPE_TB_CFG_ENTRY_80B |
++ val =
++#if !defined(CONFIG_MEDIATEK_NETSYS_V3)
++ MTK_PPE_TB_CFG_ENTRY_80B |
++#endif
+ MTK_PPE_TB_CFG_AGE_NON_L4 |
+ MTK_PPE_TB_CFG_AGE_UNBIND |
+ MTK_PPE_TB_CFG_AGE_TCP |
+ MTK_PPE_TB_CFG_AGE_UDP |
+ MTK_PPE_TB_CFG_AGE_TCP_FIN |
+-#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++#if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
+ MTK_PPE_TB_CFG_INFO_SEL |
+ #endif
+ FIELD_PREP(MTK_PPE_TB_CFG_SEARCH_MISS,
+@@ -937,7 +940,7 @@ int mtk_ppe_start(struct mtk_ppe *ppe)
+
+ ppe_w32(ppe, MTK_PPE_DEFAULT_CPU_PORT, 0);
+
+-#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++#if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
+ ppe_w32(ppe, MTK_PPE_DEFAULT_CPU_PORT1, 0xcb777);
+ 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 703b2bd..03b4dfb 100644
+--- a/drivers/net/ethernet/mediatek/mtk_ppe.h
++++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
+@@ -8,7 +8,10 @@
+ #include <linux/bitfield.h>
+ #include <linux/rhashtable.h>
+
+-#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++#if defined(CONFIG_MEDIATEK_NETSYS_V3)
++#define MTK_MAX_PPE_NUM 3
++#define MTK_ETH_PPE_BASE 0x2000
++#elif defined(CONFIG_MEDIATEK_NETSYS_V2)
+ #define MTK_MAX_PPE_NUM 2
+ #define MTK_ETH_PPE_BASE 0x2000
+ #else
+@@ -22,7 +22,7 @@
+ #define MTK_PPE_WAIT_TIMEOUT_US 1000000
+
+ #define MTK_FOE_IB1_UNBIND_TIMESTAMP GENMASK(7, 0)
+-#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++#if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
+ #define MTK_FOE_IB1_UNBIND_SRC_PORT GENMASK(11, 8)
+ #define MTK_FOE_IB1_UNBIND_PACKETS GENMASK(19, 12)
+ #define MTK_FOE_IB1_UNBIND_PREBIND BIT(22)
+@@ -70,7 +70,7 @@ enum {
+ MTK_PPE_PKT_TYPE_IPV6_6RD = 7,
+ };
+
+-#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++#if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
+ #define MTK_FOE_IB2_QID GENMASK(6, 0)
+ #define MTK_FOE_IB2_PORT_MG BIT(7)
+ #define MTK_FOE_IB2_PSE_QOS BIT(8)
+@@ -98,7 +98,18 @@ enum {
+
+ #define MTK_FOE_IB2_DSCP GENMASK(31, 24)
+
+-#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++#if defined(CONFIG_MEDIATEK_NETSYS_V3)
++#define MTK_FOE_WINFO_WCID GENMASK(15, 0)
++#define MTK_FOE_WINFO_BSS GENMASK(23, 16)
++
++#define MTK_FOE_WINFO_PAO_USR_INFO GENMASK(15, 0)
++#define MTK_FOE_WINFO_PAO_TID GENMASK(19, 16)
++#define MTK_FOE_WINFO_PAO_IS_FIXEDRATE BIT(20)
++#define MTK_FOE_WINFO_PAO_IS_PRIOR BIT(21)
++#define MTK_FOE_WINFO_PAO_IS_SP BIT(22)
++#define MTK_FOE_WINFO_PAO_HF BIT(23)
++#define MTK_FOE_WINFO_PAO_AMSDU_EN BIT(24)
++#elif defined(CONFIG_MEDIATEK_NETSYS_V2)
+ #define MTK_FOE_WINFO_BSS GENMASK(5, 0)
+ #define MTK_FOE_WINFO_WCID GENMASK(15, 6)
+ #else
+@@ -128,7 +139,17 @@ struct mtk_foe_mac_info {
+ u16 pppoe_id;
+ u16 src_mac_lo;
+
+-#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++#if defined(CONFIG_MEDIATEK_NETSYS_V3)
++ u16 minfo;
++ u16 resv1;
++ u32 winfo;
++ u32 winfo_pao;
++ u16 cdrt_id:8;
++ u16 tops_entry:6;
++ u16 resv3:2;
++ u16 tport_id:4;
++ u16 resv4:12;
++#elif defined(CONFIG_MEDIATEK_NETSYS_V2)
+ u16 minfo;
+ u16 winfo;
+ #endif
+@@ -249,7 +265,9 @@ struct mtk_foe_entry {
+ struct mtk_foe_ipv4_dslite dslite;
+ struct mtk_foe_ipv6 ipv6;
+ struct mtk_foe_ipv6_6rd ipv6_6rd;
+-#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++#if defined(CONFIG_MEDIATEK_NETSYS_V3)
++ u32 data[31];
++#elif defined(CONFIG_MEDIATEK_NETSYS_V2)
+ u32 data[23];
+ #else
+ u32 data[19];
+diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
+index a5bf090..0e41ff2 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,
+ mtk_foe_entry_set_wdma(foe, info.wdma_idx, info.queue, info.bss,
+ info.wcid);
+ pse_port = PSE_PPE0_PORT;
+-#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++#if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
+ if (info.wdma_idx == 0)
+ pse_port = PSE_WDMA0_PORT;
+ else if (info.wdma_idx == 1)
+@@ -220,6 +220,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])
+ pse_port = PSE_GDM2_PORT;
++ else if (dev == eth->netdev[2])
++ pse_port = PSE_GDM3_PORT;
+ else
+ return -EOPNOTSUPP;
+
+@@ -452,7 +452,7 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
+ return -ENOMEM;
+
+ i = 0;
+-#if defined(CONFIG_MEDIATEK_NETSYS_V2)
++#if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
+ if (idev && idev->netdev_ops->ndo_fill_receive_path) {
+ ctx.dev = idev;
+ idev->netdev_ops->ndo_fill_receive_path(&ctx, &path);
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3015-mediatek-ethernet-add-wifi2wifi-offload-support.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3018-mediatek-ethernet-add-wifi2wifi-offload-support.patch
similarity index 82%
rename from autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3015-mediatek-ethernet-add-wifi2wifi-offload-support.patch
rename to autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3018-mediatek-ethernet-add-wifi2wifi-offload-support.patch
index 47ebeca..c810ff1 100755
--- a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3015-mediatek-ethernet-add-wifi2wifi-offload-support.patch
+++ b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3018-mediatek-ethernet-add-wifi2wifi-offload-support.patch
@@ -1,43 +1,47 @@
-From ac75819cd0f956f0cfe7f9023d9ee97770fb3191 Mon Sep 17 00:00:00 2001
+From 4c8f0a38d9c2df3815ace32133bb63d8a4345856 Mon Sep 17 00:00:00 2001
From: Sujuan Chen <sujuan.chen@mediatek.com>
-Date: Tue, 13 Jun 2023 17:11:49 +0800
-Subject: [PATCH]
- 999-3015-mediatek-ethernet-add-wifi2wifi-offload-support
+Date: Tue, 27 Dec 2022 10:14:35 +0800
+Subject: [PATCH] mediatek: ethernet: add wifi2wifi offload support
+Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com>
---
drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 ++
- .../net/ethernet/mediatek/mtk_ppe_offload.c | 34 ++++++++++++++-----
+ .../net/ethernet/mediatek/mtk_ppe_offload.c | 35 +++++++++++++------
drivers/net/ethernet/mediatek/mtk_wed.c | 13 +++++++
include/linux/soc/mediatek/mtk_wed.h | 6 +++-
- 4 files changed, 45 insertions(+), 10 deletions(-)
+ 4 files changed, 45 insertions(+), 11 deletions(-)
+ mode change 100755 => 100644 drivers/net/ethernet/mediatek/mtk_ppe_offload.c
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-index 3554d14..ee05787 100644
+index b935de6..acefa48 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-@@ -2020,6 +2020,8 @@ int mtk_dump_usxgmii(struct regmap *pmap, char *name, u32 offset, u32 range);
- int mtk_eth_offload_init(struct mtk_eth *eth);
+@@ -1767,6 +1767,8 @@ void ethsys_reset(struct mtk_eth *eth, u32 reset_bits);
+ int mtk_eth_offload_init(struct mtk_eth *eth, int id);
int mtk_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,
void *type_data);
+int mtk_eth_setup_tc_block(struct net_device *dev, struct flow_block_offload *f,
+ struct mtk_eth *eth);
void mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev);
+
int mtk_ppe_debugfs_init(struct mtk_eth *eth);
- int mtk_qdma_debugfs_init(struct mtk_eth *eth);
diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
-index 8a20dce..43371f3 100644
+old mode 100755
+new mode 100644
+index 2787a97..23d2048
--- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
+++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
-@@ -575,9 +575,20 @@ static int
+@@ -546,10 +546,20 @@ static int
mtk_eth_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_priv)
{
struct flow_cls_offload *cls = type_data;
- struct net_device *dev = cb_priv;
- struct mtk_mac *mac = netdev_priv(dev);
- struct mtk_eth *eth = mac->hw;
+- int err;
+ struct mtk_eth *eth = cb_priv;
+ struct net_device *dev = NULL;
-+ int i;
++ int i, err;
+
+ for (i = 0; i < MTK_MAC_COUNT; i++) {
+ if (!eth->netdev[i])
@@ -52,8 +56,8 @@
if (!tc_can_offload(dev))
return -EOPNOTSUPP;
-@@ -588,15 +599,20 @@ mtk_eth_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_pri
- return mtk_flow_offload_cmd(eth, cls, 0);
+@@ -577,14 +587,19 @@ mtk_eth_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_pri
+ return err;
}
-static int
@@ -68,25 +72,24 @@
static LIST_HEAD(block_cb_list);
struct flow_block_cb *block_cb;
flow_setup_cb_t *cb;
+ int i, err = 0;
+ if (!eth) {
+ mac = netdev_priv(dev);
+ eth = mac->hw;
+ }
+
- if (!eth->soc->offload_version)
- return -EOPNOTSUPP;
-
-@@ -613,7 +629,7 @@ mtk_eth_setup_tc_block(struct net_device *dev, struct flow_block_offload *f)
+ for (i = 0; i < eth->ppe_num; i++) {
+@@ -610,7 +625,7 @@ mtk_eth_setup_tc_block(struct net_device *dev, struct flow_block_offload *f)
flow_block_cb_incref(block_cb);
- return 0;
+ goto unlock;
}
- block_cb = flow_block_cb_alloc(cb, dev, dev, NULL);
+ block_cb = flow_block_cb_alloc(cb, dev, eth, NULL);
- if (IS_ERR(block_cb))
- return PTR_ERR(block_cb);
-
-@@ -642,7 +658,7 @@ int mtk_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,
+ if (IS_ERR(block_cb)) {
+ err = PTR_ERR(block_cb);
+ goto unlock;
+@@ -647,7 +662,7 @@ int mtk_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,
switch (type) {
case TC_SETUP_BLOCK:
case TC_SETUP_FT:
@@ -99,7 +102,7 @@
index 1a615f2..37a86c3 100644
--- a/drivers/net/ethernet/mediatek/mtk_wed.c
+++ b/drivers/net/ethernet/mediatek/mtk_wed.c
-@@ -1731,6 +1731,18 @@ void mtk_wed_flow_remove(int index)
+@@ -1731,6 +1731,18 @@ out:
mutex_unlock(&hw_lock);
}
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3016-flow-offload-add-mtkhnat-dscp.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3019-flow-offload-add-mtkhnat-dscp.patch
similarity index 68%
rename from autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3016-flow-offload-add-mtkhnat-dscp.patch
rename to autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3019-flow-offload-add-mtkhnat-dscp.patch
index 21152b4..fe278a7 100755
--- a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3016-flow-offload-add-mtkhnat-dscp.patch
+++ b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3019-flow-offload-add-mtkhnat-dscp.patch
@@ -1,29 +1,15 @@
-From e3e7531c6a986b0f033a1a346dd6ac8ed86bad11 Mon Sep 17 00:00:00 2001
-From: Bo-Cun Chen <bc-bocun.chen@mediatek.com>
-Date: Tue, 13 Jun 2023 17:12:50 +0800
-Subject: [PATCH] 999-3016-flow-offload-add-mtkhnat-dscp
-
----
- drivers/net/ethernet/mediatek/mtk_ppe.c | 11 +++++++
- drivers/net/ethernet/mediatek/mtk_ppe.h | 2 ++
- .../net/ethernet/mediatek/mtk_ppe_offload.c | 12 +++++++
- include/net/netfilter/nf_flow_table.h | 2 ++
- net/netfilter/nf_flow_table_offload.c | 7 +++-
- net/netfilter/xt_FLOWOFFLOAD.c | 32 +++++++++++++++++++
- 6 files changed, 65 insertions(+), 1 deletion(-)
-
diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
-index 0d7b83a..71b59ed 100644
+index c2416b1..bc13a9b 100755
--- a/drivers/net/ethernet/mediatek/mtk_ppe.c
+++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
-@@ -508,6 +508,17 @@ int mtk_foe_entry_set_queue(struct mtk_eth *eth, struct mtk_foe_entry *entry,
+@@ -435,6 +435,17 @@ int mtk_foe_entry_set_qid(struct mtk_foe_entry *entry, int qid)
+
return 0;
}
-
-+int mtk_foe_entry_set_dscp(struct mtk_eth *eth, struct mtk_foe_entry *entry,
-+ unsigned int dscp)
++
++int mtk_foe_entry_set_dscp(struct mtk_foe_entry *entry, int dscp)
+{
-+ u32 *ib2 = mtk_foe_entry_ib2(eth, entry);
++ u32 *ib2 = mtk_foe_entry_ib2(entry);
+
+ *ib2 &= ~MTK_FOE_IB2_DSCP;
+ *ib2 |= FIELD_PREP(MTK_FOE_IB2_DSCP, dscp);
@@ -31,27 +17,26 @@
+ return 0;
+}
+
- static int
- mtk_flow_entry_match_len(struct mtk_eth *eth, struct mtk_foe_entry *entry)
+ static inline bool mtk_foe_entry_usable(struct mtk_foe_entry *entry)
{
+ return !(entry->ib1 & MTK_FOE_IB1_STATIC) &&
diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
-index ba71884..d5f0aa7 100644
+index e7ecbf7..df10040 100644
--- a/drivers/net/ethernet/mediatek/mtk_ppe.h
+++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
-@@ -418,6 +418,8 @@ int mtk_foe_entry_set_wdma(struct mtk_eth *eth, struct mtk_foe_entry *entry,
- int wdma_idx, int txq, int bss, int wcid);
- int mtk_foe_entry_set_queue(struct mtk_eth *eth, struct mtk_foe_entry *entry,
- unsigned int queue);
-+int mtk_foe_entry_set_dscp(struct mtk_eth *eth, struct mtk_foe_entry *entry,
-+ unsigned int dscp);
+@@ -430,6 +430,7 @@ 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);
++int mtk_foe_entry_set_dscp(struct mtk_foe_entry *entry, int dscp);
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);
- void mtk_foe_entry_get_stats(struct mtk_ppe *ppe, struct mtk_flow_entry *entry,
+ int mtk_foe_entry_idle_time(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 43371f3..cb2bfac 100644
+index 23d2048..9bc0857 100644
--- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
+++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
-@@ -254,6 +254,7 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f,
+@@ -246,6 +246,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;
@@ -59,7 +44,7 @@
int err = 0;
int i;
-@@ -290,6 +291,15 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f,
+@@ -282,6 +283,15 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
return -EOPNOTSUPP;
}
@@ -75,17 +60,17 @@
switch (addr_type) {
case 0:
offload_type = MTK_PPE_PKT_TYPE_BRIDGE;
-@@ -448,6 +458,8 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f,
+@@ -441,6 +451,8 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
if (data.pppoe.num == 1)
- mtk_foe_entry_set_pppoe(eth, &foe, data.pppoe.sid);
+ mtk_foe_entry_set_pppoe(&foe, data.pppoe.sid);
-+ mtk_foe_entry_set_dscp(eth, &foe, dscp);
++ mtk_foe_entry_set_dscp(&foe, dscp);
+
err = mtk_flow_set_output_device(eth, &foe, odev, f->flow->ct, data.eth.h_dest,
&wed_index);
if (err)
diff --git a/include/net/netfilter/nf_flow_table.h b/include/net/netfilter/nf_flow_table.h
-index 7cf8976..8a84de3 100644
+index 55359dd..1a23c03 100644
--- a/include/net/netfilter/nf_flow_table.h
+++ b/include/net/netfilter/nf_flow_table.h
@@ -36,6 +36,7 @@ struct nf_flow_key {
@@ -105,7 +90,7 @@
struct flow_offload_tuple_rhash {
diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
-index 2927dbc..5593e28 100644
+index 61cc518..c1a5f64 100644
--- a/net/netfilter/nf_flow_table_offload.c
+++ b/net/netfilter/nf_flow_table_offload.c
@@ -104,6 +104,7 @@ static int nf_flow_rule_match(struct nf_flow_match *match,
@@ -133,7 +118,7 @@
}
diff --git a/net/netfilter/xt_FLOWOFFLOAD.c b/net/netfilter/xt_FLOWOFFLOAD.c
-index 3437d6a..c459b7a 100644
+index 2d5c3cc..b231dd7 100644
--- a/net/netfilter/xt_FLOWOFFLOAD.c
+++ b/net/netfilter/xt_FLOWOFFLOAD.c
@@ -49,6 +49,35 @@ static DEFINE_SPINLOCK(hooks_lock);
@@ -172,7 +157,7 @@
static unsigned int
xt_flowoffload_net_hook(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state)
-@@ -617,6 +646,9 @@ flowoffload_tg(struct sk_buff *skb, const struct xt_action_param *par)
+@@ -599,6 +628,9 @@ flowoffload_tg(struct sk_buff *skb, const struct xt_action_param *par)
if (flow_offload_route_init(flow, &route) < 0)
goto err_flow_add;
@@ -182,6 +167,3 @@
if (tcph) {
ct->proto.tcp.seen[0].flags |= IP_CT_TCP_FLAG_BE_LIBERAL;
ct->proto.tcp.seen[1].flags |= IP_CT_TCP_FLAG_BE_LIBERAL;
---
-2.18.0
-
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3017-flow-offload-add-mtkhnat-netlink.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3020-flow-offload-add-mtkhnat-netlink.patch
similarity index 92%
rename from autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3017-flow-offload-add-mtkhnat-netlink.patch
rename to autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3020-flow-offload-add-mtkhnat-netlink.patch
index cc58e81..3b9e863 100755
--- a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3017-flow-offload-add-mtkhnat-netlink.patch
+++ b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3020-flow-offload-add-mtkhnat-netlink.patch
@@ -1,18 +1,3 @@
-From f85fdb15ed758bdc2e8118e9b3efdf7aadb620a8 Mon Sep 17 00:00:00 2001
-From: Bo-Cun Chen <bc-bocun.chen@mediatek.com>
-Date: Tue, 13 Jun 2023 17:13:37 +0800
-Subject: [PATCH] 999-3017-flow-offload-add-mtkhnat-netlink
-
----
- include/net/netfilter/nf_flow_table.h | 1 +
- include/uapi/linux/netfilter/nfnetlink.h | 3 +-
- net/netfilter/Kconfig | 9 +
- net/netfilter/Makefile | 1 +
- net/netfilter/nf_flow_table_core.c | 23 +++
- net/netfilter/nf_flow_table_netlink.c | 239 +++++++++++++++++++++++
- 6 files changed, 275 insertions(+), 1 deletion(-)
- create mode 100644 net/netfilter/nf_flow_table_netlink.c
-
diff --git a/include/net/netfilter/nf_flow_table.h b/include/net/netfilter/nf_flow_table.h
index 8a84de3..1a23c03 100644
--- a/include/net/netfilter/nf_flow_table.h
@@ -72,10 +57,10 @@
# generic X tables
obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
-index 0a701f0..bf71317 100644
+index 1036558..a0f52f6 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
-@@ -354,6 +354,29 @@ void flow_offload_teardown(struct flow_offload *flow)
+@@ -373,6 +373,29 @@ void flow_offload_teardown(struct flow_offload *flow)
}
EXPORT_SYMBOL_GPL(flow_offload_teardown);
@@ -350,6 +335,3 @@
+MODULE_LICENSE("GPL");
+module_init(ftnetlink_init);
+module_exit(ftnetlink_exit);
---
-2.18.0
-