1 From patchwork Thu Sep 8 19:33:38 2022
2 Content-Type: text/plain; charset="utf-8"
4 Content-Transfer-Encoding: 7bit
5 X-Patchwork-Submitter: Lorenzo Bianconi <lorenzo@kernel.org>
6 X-Patchwork-Id: 12970557
7 X-Patchwork-Delegate: kuba@kernel.org
8 From: Lorenzo Bianconi <lorenzo@kernel.org>
9 To: netdev@vger.kernel.org
10 Cc: nbd@nbd.name, john@phrozen.org, sean.wang@mediatek.com,
11 Mark-MC.Lee@mediatek.com, davem@davemloft.net, edumazet@google.com,
12 kuba@kernel.org, pabeni@redhat.com, matthias.bgg@gmail.com,
13 linux-mediatek@lists.infradead.org, lorenzo.bianconi@redhat.com,
14 Bo.Jiao@mediatek.com, sujuan.chen@mediatek.com,
15 ryder.Lee@mediatek.com, evelyn.tsai@mediatek.com,
16 devicetree@vger.kernel.org, robh@kernel.org
17 Subject: [PATCH net-next 04/12] net: ethernet: mtk_eth_soc: move ppe table
18 hash offset to mtk_soc_data structure
19 Date: Thu, 8 Sep 2022 21:33:38 +0200
21 <cc263ffeaa3e1d7314e36a4f941e96d38e41a6bf.1662661555.git.lorenzo@kernel.org>
22 X-Mailer: git-send-email 2.37.3
23 In-Reply-To: <cover.1662661555.git.lorenzo@kernel.org>
24 References: <cover.1662661555.git.lorenzo@kernel.org>
27 List-ID: <netdev.vger.kernel.org>
28 X-Mailing-List: netdev@vger.kernel.org
29 X-Patchwork-Delegate: kuba@kernel.org
31 This is a preliminary patch to introduce mt7986 hw packet engine.
33 Co-developed-by: Bo Jiao <Bo.Jiao@mediatek.com>
34 Signed-off-by: Bo Jiao <Bo.Jiao@mediatek.com>
35 Co-developed-by: Sujuan Chen <sujuan.chen@mediatek.com>
36 Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com>
37 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
39 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 ++++
40 drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 ++
41 drivers/net/ethernet/mediatek/mtk_ppe.c | 24 +++++++++++++++------
42 drivers/net/ethernet/mediatek/mtk_ppe.h | 2 +-
43 4 files changed, 25 insertions(+), 7 deletions(-)
45 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
46 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
47 @@ -4150,6 +4150,7 @@ static const struct mtk_soc_data mt7621_
48 .required_clks = MT7621_CLKS_BITMAP,
49 .required_pctl = false,
53 .txd_size = sizeof(struct mtk_tx_dma),
54 .rxd_size = sizeof(struct mtk_rx_dma),
55 @@ -4168,6 +4169,7 @@ static const struct mtk_soc_data mt7622_
56 .required_clks = MT7622_CLKS_BITMAP,
57 .required_pctl = false,
61 .txd_size = sizeof(struct mtk_tx_dma),
62 .rxd_size = sizeof(struct mtk_rx_dma),
63 @@ -4185,6 +4187,7 @@ static const struct mtk_soc_data mt7623_
64 .required_clks = MT7623_CLKS_BITMAP,
65 .required_pctl = true,
69 .txd_size = sizeof(struct mtk_tx_dma),
70 .rxd_size = sizeof(struct mtk_rx_dma),
71 @@ -4218,6 +4221,7 @@ static const struct mtk_soc_data mt7986_
73 .required_clks = MT7986_CLKS_BITMAP,
74 .required_pctl = false,
77 .txd_size = sizeof(struct mtk_tx_dma_v2),
78 .rxd_size = sizeof(struct mtk_rx_dma_v2),
79 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
80 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
81 @@ -966,6 +966,7 @@ struct mtk_reg_map {
83 * @required_pctl A bool value to show whether the SoC requires
84 * the extra setup for those pins used by GMAC.
85 + * @hash_offset Flow table hash offset.
86 * @txd_size Tx DMA descriptor size.
87 * @rxd_size Rx DMA descriptor size.
88 * @rx_irq_done_mask Rx irq done register mask.
89 @@ -980,6 +981,7 @@ struct mtk_soc_data {
94 netdev_features_t hw_features;
97 --- a/drivers/net/ethernet/mediatek/mtk_ppe.c
98 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
99 @@ -88,7 +88,7 @@ static void mtk_ppe_cache_enable(struct
100 enable * MTK_PPE_CACHE_CTL_EN);
103 -static u32 mtk_ppe_hash_entry(struct mtk_foe_entry *e)
104 +static u32 mtk_ppe_hash_entry(struct mtk_eth *eth, struct mtk_foe_entry *e)
108 @@ -122,7 +122,7 @@ static u32 mtk_ppe_hash_entry(struct mtk
109 hash = (hash >> 24) | ((hash & 0xffffff) << 8);
110 hash ^= hv1 ^ hv2 ^ hv3;
113 + hash <<= (ffs(eth->soc->hash_offset) - 1);
114 hash &= MTK_PPE_ENTRIES - 1;
117 @@ -540,15 +540,16 @@ mtk_foe_entry_commit_l2(struct mtk_ppe *
118 int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
120 int type = FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, entry->data.ib1);
121 + const struct mtk_soc_data *soc = ppe->eth->soc;
124 if (type == MTK_PPE_PKT_TYPE_BRIDGE)
125 return mtk_foe_entry_commit_l2(ppe, entry);
127 - hash = mtk_ppe_hash_entry(&entry->data);
128 + hash = mtk_ppe_hash_entry(ppe->eth, &entry->data);
129 entry->hash = 0xffff;
130 spin_lock_bh(&ppe_lock);
131 - hlist_add_head(&entry->list, &ppe->foe_flow[hash / 2]);
132 + hlist_add_head(&entry->list, &ppe->foe_flow[hash / soc->hash_offset]);
133 spin_unlock_bh(&ppe_lock);
136 @@ -558,6 +559,7 @@ static void
137 mtk_foe_entry_commit_subflow(struct mtk_ppe *ppe, struct mtk_flow_entry *entry,
140 + const struct mtk_soc_data *soc = ppe->eth->soc;
141 struct mtk_flow_entry *flow_info;
142 struct mtk_foe_entry foe, *hwe;
143 struct mtk_foe_mac_info *l2;
144 @@ -572,7 +574,8 @@ mtk_foe_entry_commit_subflow(struct mtk_
145 flow_info->l2_data.base_flow = entry;
146 flow_info->type = MTK_FLOW_TYPE_L2_SUBFLOW;
147 flow_info->hash = hash;
148 - hlist_add_head(&flow_info->list, &ppe->foe_flow[hash / 2]);
149 + hlist_add_head(&flow_info->list,
150 + &ppe->foe_flow[hash / soc->hash_offset]);
151 hlist_add_head(&flow_info->l2_data.list, &entry->l2_flows);
153 hwe = &ppe->foe_table[hash];
154 @@ -596,7 +599,8 @@ mtk_foe_entry_commit_subflow(struct mtk_
156 void __mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash)
158 - struct hlist_head *head = &ppe->foe_flow[hash / 2];
159 + const struct mtk_soc_data *soc = ppe->eth->soc;
160 + struct hlist_head *head = &ppe->foe_flow[hash / soc->hash_offset];
161 struct mtk_foe_entry *hwe = &ppe->foe_table[hash];
162 struct mtk_flow_entry *entry;
163 struct mtk_foe_bridge key = {};
164 @@ -680,9 +684,11 @@ int mtk_foe_entry_idle_time(struct mtk_p
165 struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
168 + const struct mtk_soc_data *soc = eth->soc;
169 struct device *dev = eth->dev;
170 struct mtk_foe_entry *foe;
174 ppe = devm_kzalloc(dev, sizeof(*ppe), GFP_KERNEL);
176 @@ -705,6 +711,12 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_
178 ppe->foe_table = foe;
180 + foe_flow_size = (MTK_PPE_ENTRIES / soc->hash_offset) *
181 + sizeof(*ppe->foe_flow);
182 + ppe->foe_flow = devm_kzalloc(dev, foe_flow_size, GFP_KERNEL);
183 + if (!ppe->foe_flow)
186 mtk_ppe_debugfs_init(ppe);
189 --- a/drivers/net/ethernet/mediatek/mtk_ppe.h
190 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
191 @@ -270,7 +270,7 @@ struct mtk_ppe {
194 u16 foe_check_time[MTK_PPE_ENTRIES];
195 - struct hlist_head foe_flow[MTK_PPE_ENTRIES / 2];
196 + struct hlist_head *foe_flow;
198 struct rhashtable l2_flows;