+++ /dev/null
-From 6563f43c89765e075e8784d921e17bd680d01189 Mon Sep 17 00:00:00 2001
-From: Sasha Levin <sashal@kernel.org>
-Date: Tue, 20 Sep 2022 12:11:15 +0200
-Subject: net: ethernet: mtk_eth_soc: move gdma_to_ppe and ppe_base definitions
- in mtk register map
-
-From: Lorenzo Bianconi <lorenzo@kernel.org>
-
-[ Upstream commit 329bce5139cfb00dba40f038ec090572b81ff2a9 ]
-
-This is a preliminary patch to introduce mt7986 hw packet engine.
-
-Tested-by: Daniel Golle <daniel@makrotopia.org>
-Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
-Signed-off-by: Paolo Abeni <pabeni@redhat.com>
-Stable-dep-of: 8110437e5961 ("net: ethernet: mtk_eth_soc: fix resource leak in error path")
-Signed-off-by: Sasha Levin <sashal@kernel.org>
----
- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 15 +++++++++++----
- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 3 ++-
- drivers/net/ethernet/mediatek/mtk_ppe.h | 2 --
- 3 files changed, 13 insertions(+), 7 deletions(-)
-
-diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-index 916b570bdbf4..83c636d44142 100644
---- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -73,6 +73,8 @@ static const struct mtk_reg_map mtk_reg_map = {
- .fq_blen = 0x1b2c,
- },
- .gdm1_cnt = 0x2400,
-+ .gdma_to_ppe = 0x4444,
-+ .ppe_base = 0x0c00,
- };
-
- static const struct mtk_reg_map mt7628_reg_map = {
-@@ -126,6 +128,8 @@ static const struct mtk_reg_map mt7986_reg_map = {
- .fq_blen = 0x472c,
- },
- .gdm1_cnt = 0x1c00,
-+ .gdma_to_ppe = 0x3333,
-+ .ppe_base = 0x2000,
- };
-
- /* strings used by ethtool */
-@@ -2978,6 +2982,7 @@ 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)) {
-+ const struct mtk_soc_data *soc = eth->soc;
- u32 gdm_config = MTK_GDMA_TO_PDMA;
-
- err = mtk_start_dma(eth);
-@@ -2986,15 +2991,15 @@ static int mtk_open(struct net_device *dev)
- return err;
- }
-
-- if (eth->soc->offload_version && mtk_ppe_start(eth->ppe) == 0)
-- gdm_config = MTK_GDMA_TO_PPE;
-+ if (soc->offload_version && mtk_ppe_start(eth->ppe) == 0)
-+ gdm_config = soc->reg_map->gdma_to_ppe;
-
- mtk_gdm_config(eth, gdm_config);
-
- napi_enable(ð->tx_napi);
- napi_enable(ð->rx_napi);
- mtk_tx_irq_enable(eth, MTK_TX_DONE_INT);
-- mtk_rx_irq_enable(eth, eth->soc->txrx.rx_irq_done_mask);
-+ mtk_rx_irq_enable(eth, soc->txrx.rx_irq_done_mask);
- refcount_set(ð->dma_refcnt, 1);
- }
- else
-@@ -4104,7 +4109,9 @@ static int mtk_probe(struct platform_device *pdev)
- }
-
- if (eth->soc->offload_version) {
-- eth->ppe = mtk_ppe_init(eth, eth->base + MTK_ETH_PPE_BASE, 2);
-+ u32 ppe_addr = eth->soc->reg_map->ppe_base;
-+
-+ eth->ppe = mtk_ppe_init(eth, eth->base + ppe_addr, 2);
- if (!eth->ppe) {
- err = -ENOMEM;
- goto err_free_dev;
-diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-index 0f9668a4079d..511752729f5c 100644
---- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-@@ -105,7 +105,6 @@
- #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_DROP_ALL 0x7777
-
- /* Unicast Filter MAC Address Register - Low */
-@@ -955,6 +954,8 @@ struct mtk_reg_map {
- u32 fq_blen; /* fq free page buffer length */
- } qdma;
- u32 gdm1_cnt;
-+ u32 gdma_to_ppe;
-+ u32 ppe_base;
- };
-
- /* struct mtk_eth_data - This is the structure holding all differences
-diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
-index 69ffce04d630..ceb7dfe281de 100644
---- a/drivers/net/ethernet/mediatek/mtk_ppe.h
-+++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
-@@ -8,8 +8,6 @@
- #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)
- #define MTK_PPE_HASH_MASK (MTK_PPE_ENTRIES - 1)
---
-2.35.1
-
+++ /dev/null
-From b034d1ecdd1dbd4497d9c5c8da4fe32fb429d1c3 Mon Sep 17 00:00:00 2001
-From: Sasha Levin <sashal@kernel.org>
-Date: Tue, 20 Sep 2022 12:11:16 +0200
-Subject: net: ethernet: mtk_eth_soc: move ppe table hash offset to
- mtk_soc_data structure
-
-From: Lorenzo Bianconi <lorenzo@kernel.org>
-
-[ Upstream commit ba2fc48c5e1e9e1934939f0d12ff8b985dcc6e5d ]
-
-This is a preliminary patch to introduce mt7986 hw packet engine.
-
-Tested-by: Daniel Golle <daniel@makrotopia.org>
-Co-developed-by: Bo Jiao <Bo.Jiao@mediatek.com>
-Signed-off-by: Bo Jiao <Bo.Jiao@mediatek.com>
-Co-developed-by: Sujuan Chen <sujuan.chen@mediatek.com>
-Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com>
-Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
-Signed-off-by: Paolo Abeni <pabeni@redhat.com>
-Stable-dep-of: 8110437e5961 ("net: ethernet: mtk_eth_soc: fix resource leak in error path")
-Signed-off-by: Sasha Levin <sashal@kernel.org>
----
- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 ++++
- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 ++
- drivers/net/ethernet/mediatek/mtk_ppe.c | 24 +++++++++++++++------
- drivers/net/ethernet/mediatek/mtk_ppe.h | 2 +-
- 4 files changed, 25 insertions(+), 7 deletions(-)
-
-diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-index 83c636d44142..3db24ddd1261 100644
---- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -4210,6 +4210,7 @@ static const struct mtk_soc_data mt7621_data = {
- .required_clks = MT7621_CLKS_BITMAP,
- .required_pctl = false,
- .offload_version = 2,
-+ .hash_offset = 2,
- .txrx = {
- .txd_size = sizeof(struct mtk_tx_dma),
- .rxd_size = sizeof(struct mtk_rx_dma),
-@@ -4228,6 +4229,7 @@ static const struct mtk_soc_data mt7622_data = {
- .required_clks = MT7622_CLKS_BITMAP,
- .required_pctl = false,
- .offload_version = 2,
-+ .hash_offset = 2,
- .txrx = {
- .txd_size = sizeof(struct mtk_tx_dma),
- .rxd_size = sizeof(struct mtk_rx_dma),
-@@ -4245,6 +4247,7 @@ static const struct mtk_soc_data mt7623_data = {
- .required_clks = MT7623_CLKS_BITMAP,
- .required_pctl = true,
- .offload_version = 2,
-+ .hash_offset = 2,
- .txrx = {
- .txd_size = sizeof(struct mtk_tx_dma),
- .rxd_size = sizeof(struct mtk_rx_dma),
-@@ -4278,6 +4281,7 @@ static const struct mtk_soc_data mt7986_data = {
- .caps = MT7986_CAPS,
- .required_clks = MT7986_CLKS_BITMAP,
- .required_pctl = false,
-+ .hash_offset = 4,
- .txrx = {
- .txd_size = sizeof(struct mtk_tx_dma_v2),
- .rxd_size = sizeof(struct mtk_rx_dma_v2),
-diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-index 511752729f5c..26ed1c8b77c3 100644
---- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-@@ -969,6 +969,7 @@ 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.
- * @txd_size Tx DMA descriptor size.
- * @rxd_size Rx DMA descriptor size.
- * @rx_irq_done_mask Rx irq done register mask.
-@@ -983,6 +984,7 @@ struct mtk_soc_data {
- u32 required_clks;
- bool required_pctl;
- u8 offload_version;
-+ u8 hash_offset;
- netdev_features_t hw_features;
- struct {
- u32 txd_size;
-diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
-index 148ea636ef97..6ecac461fd76 100644
---- 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_eth *eth, 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 <<= 1;
-+ hash <<= (ffs(eth->soc->hash_offset) - 1);
- hash &= MTK_PPE_ENTRIES - 1;
-
- return hash;
-@@ -540,15 +540,16 @@ mtk_foe_entry_commit_l2(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
- 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);
-+ const struct mtk_soc_data *soc = ppe->eth->soc;
- u32 hash;
-
- 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->eth, &entry->data);
- entry->hash = 0xffff;
- spin_lock_bh(&ppe_lock);
-- hlist_add_head(&entry->list, &ppe->foe_flow[hash / 2]);
-+ hlist_add_head(&entry->list, &ppe->foe_flow[hash / soc->hash_offset]);
- spin_unlock_bh(&ppe_lock);
-
- return 0;
-@@ -558,6 +559,7 @@ 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_entry foe, *hwe;
- struct mtk_foe_mac_info *l2;
-@@ -572,7 +574,8 @@ 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 / 2]);
-+ hlist_add_head(&flow_info->list,
-+ &ppe->foe_flow[hash / soc->hash_offset]);
- hlist_add_head(&flow_info->l2_data.list, &entry->l2_flows);
-
- hwe = &ppe->foe_table[hash];
-@@ -596,7 +599,8 @@ 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 / 2];
-+ 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 = &ppe->foe_table[hash];
- struct mtk_flow_entry *entry;
- struct mtk_foe_bridge key = {};
-@@ -680,9 +684,11 @@ 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)
- {
-+ const struct mtk_soc_data *soc = eth->soc;
- struct device *dev = eth->dev;
- struct mtk_foe_entry *foe;
- struct mtk_ppe *ppe;
-+ u32 foe_flow_size;
-
- ppe = devm_kzalloc(dev, sizeof(*ppe), GFP_KERNEL);
- if (!ppe)
-@@ -705,6 +711,12 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
-
- 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;
-+
- 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 ceb7dfe281de..7a16503690f3 100644
---- a/drivers/net/ethernet/mediatek/mtk_ppe.h
-+++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
-@@ -270,7 +270,7 @@ struct mtk_ppe {
- 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;
-
---
-2.35.1
-