blob: 0eb1117c5079330d92bc9e6540d9bdc1e4a66f4a [file] [log] [blame]
developer8cb3ac72022-07-04 10:55:14 +08001From a59cb5c770a694cb34ab179ec59e91ba5c39908b Mon Sep 17 00:00:00 2001
2From: Bo Jiao <Bo.Jiao@mediatek.com>
3Date: Mon, 27 Jun 2022 14:48:35 +0800
4Subject: [PATCH 6/8] 9995-flow-offload-add-mkhnat-dual-ppe-new-v2
5
6---
7 arch/arm64/boot/dts/mediatek/mt7986a.dtsi | 1 +
8 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 67 ++++++++++++++-----
9 drivers/net/ethernet/mediatek/mtk_eth_soc.h | 10 ++-
10 drivers/net/ethernet/mediatek/mtk_ppe.c | 5 +-
11 drivers/net/ethernet/mediatek/mtk_ppe.h | 7 +-
12 .../net/ethernet/mediatek/mtk_ppe_debugfs.c | 27 ++++++--
13 .../net/ethernet/mediatek/mtk_ppe_offload.c | 45 ++++++++++---
14 include/linux/netdevice.h | 4 ++
15 8 files changed, 125 insertions(+), 41 deletions(-)
16 mode change 100644 => 100755 drivers/net/ethernet/mediatek/mtk_ppe_offload.c
17
18diff --git a/arch/arm64/boot/dts/mediatek/mt7986a.dtsi b/arch/arm64/boot/dts/mediatek/mt7986a.dtsi
19index 7f78de6b9..381136c21 100644
20--- a/arch/arm64/boot/dts/mediatek/mt7986a.dtsi
21+++ b/arch/arm64/boot/dts/mediatek/mt7986a.dtsi
22@@ -479,6 +479,7 @@
23 mediatek,ethsys = <&ethsys>;
24 mediatek,sgmiisys = <&sgmiisys0>, <&sgmiisys1>;
25 mediatek,wed = <&wed0>, <&wed1>;
26+ mtketh-ppe-num = <2>;
27 #reset-cells = <1>;
28 #address-cells = <1>;
29 #size-cells = <0>;
30diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
31index 01fc1e5c0..3f67bebfe 100644
32--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
33+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
34@@ -1379,6 +1379,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
35 u8 *data, *new_data;
36 struct mtk_rx_dma *rxd, trxd;
37 int done = 0;
38+ int i;
39
40 if (unlikely(!ring))
41 goto rx_done;
42@@ -1479,14 +1480,20 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
43
44 #if defined(CONFIG_MEDIATEK_NETSYS_V2)
45 reason = FIELD_GET(MTK_RXD5_PPE_CPU_REASON_V2, trxd.rxd5);
46- if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED)
47- mtk_ppe_check_skb(eth->ppe, skb,
48- trxd.rxd5 & MTK_RXD5_FOE_ENTRY_V2);
49+ if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED) {
50+ for (i = 0; i < eth->ppe_num; i++) {
51+ mtk_ppe_check_skb(eth->ppe[i], skb,
52+ trxd.rxd5 & MTK_RXD5_FOE_ENTRY_V2);
53+ }
54+ }
55 #else
56 reason = FIELD_GET(MTK_RXD4_PPE_CPU_REASON, trxd.rxd4);
57- if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED)
58- mtk_ppe_check_skb(eth->ppe, skb,
59- trxd.rxd4 & MTK_RXD4_FOE_ENTRY);
60+ if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED) {
61+ for (i = 0; i < eth->ppe_num; i++) {
62+ mtk_ppe_check_skb(eth->ppe[i], skb,
63+ trxd.rxd4 & MTK_RXD4_FOE_ENTRY);
64+ }
65+ }
66 #endif
67
68 if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) {
69@@ -2687,8 +2694,12 @@ static int mtk_open(struct net_device *dev)
70 if (err)
71 return err;
72
73- if (eth->soc->offload_version && mtk_ppe_start(eth->ppe) == 0)
74- gdm_config = MTK_GDMA_TO_PPE;
75+ if (eth->soc->offload_version) {
76+ gdm_config = MTK_GDMA_TO_PPE0;
77+
78+ for (i = 0; i < eth->ppe_num; i++)
79+ mtk_ppe_start(eth->ppe[i]);
80+ }
81
82 mtk_gdm_config(eth, gdm_config);
83
84@@ -2803,8 +2814,10 @@ static int mtk_stop(struct net_device *dev)
85
86 mtk_dma_free(eth);
87
88- if (eth->soc->offload_version)
89- mtk_ppe_stop(eth->ppe);
90+ if (eth->soc->offload_version) {
91+ for (i = 0; i < eth->ppe_num; i++)
92+ mtk_ppe_stop(eth->ppe[i]);
93+ }
94
95 return 0;
96 }
97@@ -3780,15 +3793,35 @@ static int mtk_probe(struct platform_device *pdev)
98 }
99
100 if (eth->soc->offload_version) {
101- eth->ppe = mtk_ppe_init(eth, eth->base + MTK_ETH_PPE_BASE, 2);
102- if (!eth->ppe) {
103- err = -ENOMEM;
104- goto err_free_dev;
105+ unsigned int val;
106+
107+ err = of_property_read_u32_index(pdev->dev.of_node, "mtketh-ppe-num", 0, &val);
108+ if (err < 0)
109+ eth->ppe_num = 1;
110+ else
111+ eth->ppe_num = val;
112+
113+ if (eth->ppe_num > MTK_MAX_PPE_NUM) {
114+ dev_warn(&pdev->dev, "%d is not a valid ppe num, please check mtketh-ppe-num in dts !", eth->ppe_num);
115+ eth->ppe_num = MTK_MAX_PPE_NUM;
116 }
117
118- err = mtk_eth_offload_init(eth);
119- if (err)
120- goto err_free_dev;
121+ dev_info(&pdev->dev, "ppe num = %d\n", eth->ppe_num);
122+
123+ for (i = 0; i < eth->ppe_num; i++) {
124+ eth->ppe[i] = mtk_ppe_init(eth,
125+ eth->base + MTK_ETH_PPE_BASE + i * 0x400, 2, i);
126+ if (!eth->ppe[i]) {
127+ err = -ENOMEM;
128+ goto err_free_dev;
129+ }
130+
131+ err = mtk_eth_offload_init(eth, i);
132+ if (err)
133+ goto err_free_dev;
134+ }
135+
136+ mtk_ppe_debugfs_init(eth);
137 }
138
139 for (i = 0; i < MTK_MAX_DEVS; i++) {
140diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
141index fce1a7172..b4de7c0c6 100644
142--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
143+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
144@@ -110,7 +110,8 @@
145 #define MTK_GDMA_TCS_EN BIT(21)
146 #define MTK_GDMA_UCS_EN BIT(20)
147 #define MTK_GDMA_TO_PDMA 0x0
148-#define MTK_GDMA_TO_PPE 0x3333
149+#define MTK_GDMA_TO_PPE0 0x3333
150+#define MTK_GDMA_TO_PPE1 0x4444
151 #define MTK_GDMA_DROP_ALL 0x7777
152
153 /* Unicast Filter MAC Address Register - Low */
154@@ -1299,7 +1300,8 @@ struct mtk_eth {
155 spinlock_t syscfg0_lock;
156 struct timer_list mtk_dma_monitor_timer;
157
158- struct mtk_ppe *ppe;
159+ u8 ppe_num;
160+ struct mtk_ppe *ppe[MTK_MAX_PPE_NUM];
161 struct rhashtable flow_table;
162 };
163
164@@ -1349,9 +1351,11 @@ int mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id);
165 void mtk_gdm_config(struct mtk_eth *eth, u32 config);
166 void ethsys_reset(struct mtk_eth *eth, u32 reset_bits);
167
168-int mtk_eth_offload_init(struct mtk_eth *eth);
169+int mtk_eth_offload_init(struct mtk_eth *eth, int id);
170 int mtk_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,
171 void *type_data);
172 void mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev);
173
174+int mtk_ppe_debugfs_init(struct mtk_eth *eth);
175+
176 #endif /* MTK_ETH_H */
177diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
178index d46e91178..3d6ff30ba 100755
179--- a/drivers/net/ethernet/mediatek/mtk_ppe.c
180+++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
181@@ -677,7 +677,7 @@ int mtk_foe_entry_idle_time(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
182 }
183
184 struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
185- int version)
186+ int version, int id)
187 {
188 struct device *dev = eth->dev;
189 struct mtk_foe_entry *foe;
190@@ -696,6 +696,7 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
191 ppe->eth = eth;
192 ppe->dev = dev;
193 ppe->version = version;
194+ ppe->id = id;
195
196 foe = dmam_alloc_coherent(ppe->dev, MTK_PPE_ENTRIES * sizeof(*foe),
197 &ppe->foe_phys, GFP_KERNEL);
198@@ -704,8 +705,6 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
199
200 ppe->foe_table = foe;
201
202- mtk_ppe_debugfs_init(ppe);
203-
204 return ppe;
205 }
206
207diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
208index a76f4b0ac..21cc55145 100644
209--- a/drivers/net/ethernet/mediatek/mtk_ppe.h
210+++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
211@@ -8,6 +8,8 @@
212 #include <linux/bitfield.h>
213 #include <linux/rhashtable.h>
214
215+#define MTK_MAX_PPE_NUM 2
216+
217 #define MTK_ETH_PPE_BASE 0x2000
218
219 #define MTK_PPE_ENTRIES_SHIFT 3
220@@ -253,6 +255,7 @@ struct mtk_flow_entry {
221 };
222 };
223 u8 type;
224+ s8 ppe_index;
225 s8 wed_index;
226 u16 hash;
227 union {
228@@ -272,6 +275,7 @@ struct mtk_ppe {
229 struct device *dev;
230 void __iomem *base;
231 int version;
232+ int id;
233
234 struct mtk_foe_entry *foe_table;
235 dma_addr_t foe_phys;
236@@ -284,7 +288,7 @@ struct mtk_ppe {
237 void *acct_table;
238 };
239
240-struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int version);
241+struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int version, int id);
242 int mtk_ppe_start(struct mtk_ppe *ppe);
243 int mtk_ppe_stop(struct mtk_ppe *ppe);
244
245@@ -335,6 +339,5 @@ int mtk_foe_entry_set_wdma(struct mtk_foe_entry *entry, int wdma_idx, int txq,
246 int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_flow_entry *entry);
247 void mtk_foe_entry_clear(struct mtk_ppe *ppe, struct mtk_flow_entry *entry);
248 int mtk_foe_entry_idle_time(struct mtk_ppe *ppe, struct mtk_flow_entry *entry);
249-int mtk_ppe_debugfs_init(struct mtk_ppe *ppe);
250
251 #endif
252diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c b/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
253index a591ab1fd..f4ebe5944 100644
254--- a/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
255+++ b/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
256@@ -73,9 +73,8 @@ mtk_print_addr_info(struct seq_file *m, struct mtk_flow_addr_info *ai)
257 }
258
259 static int
260-mtk_ppe_debugfs_foe_show(struct seq_file *m, void *private, bool bind)
261+mtk_ppe_debugfs_foe_show(struct seq_file *m, struct mtk_ppe *ppe, bool bind)
262 {
263- struct mtk_ppe *ppe = m->private;
264 int i;
265
266 for (i = 0; i < MTK_PPE_ENTRIES; i++) {
267@@ -122,6 +121,8 @@ mtk_ppe_debugfs_foe_show(struct seq_file *m, void *private, bool bind)
268 break;
269 }
270
271+ seq_printf(m, " ppe=%d", ppe->id);
272+
273 seq_printf(m, " orig=");
274 mtk_print_addr_info(m, &ai);
275
276@@ -164,13 +165,25 @@ mtk_ppe_debugfs_foe_show(struct seq_file *m, void *private, bool bind)
277 static int
278 mtk_ppe_debugfs_foe_show_all(struct seq_file *m, void *private)
279 {
280- return mtk_ppe_debugfs_foe_show(m, private, false);
281+ struct mtk_eth *eth = m->private;
282+ int i;
283+
284+ for (i = 0; i < eth->ppe_num; i++)
285+ mtk_ppe_debugfs_foe_show(m, eth->ppe[i], false);
286+
287+ return 0;
288 }
289
290 static int
291 mtk_ppe_debugfs_foe_show_bind(struct seq_file *m, void *private)
292 {
293- return mtk_ppe_debugfs_foe_show(m, private, true);
294+ struct mtk_eth *eth = m->private;
295+ int i;
296+
297+ for (i = 0; i < eth->ppe_num; i++)
298+ mtk_ppe_debugfs_foe_show(m, eth->ppe[i], true);
299+
300+ return 0;
301 }
302
303 static int
304@@ -187,7 +200,7 @@ mtk_ppe_debugfs_foe_open_bind(struct inode *inode, struct file *file)
305 inode->i_private);
306 }
307
308-int mtk_ppe_debugfs_init(struct mtk_ppe *ppe)
309+int mtk_ppe_debugfs_init(struct mtk_eth *eth)
310 {
311 static const struct file_operations fops_all = {
312 .open = mtk_ppe_debugfs_foe_open_all,
313@@ -209,8 +222,8 @@ int mtk_ppe_debugfs_init(struct mtk_ppe *ppe)
314 if (!root)
315 return -ENOMEM;
316
317- debugfs_create_file("entries", S_IRUGO, root, ppe, &fops_all);
318- debugfs_create_file("bind", S_IRUGO, root, ppe, &fops_bind);
319+ debugfs_create_file("entries", S_IRUGO, root, eth, &fops_all);
320+ debugfs_create_file("bind", S_IRUGO, root, eth, &fops_bind);
321
322 return 0;
323 }
324diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
325old mode 100644
326new mode 100755
327index 5a4201447..2f7d76d3b
328--- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
329+++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
330@@ -226,8 +226,10 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
331 struct flow_action_entry *act;
332 struct mtk_flow_data data = {};
333 struct mtk_foe_entry foe;
334- struct net_device *odev = NULL;
335+ struct net_device *idev = NULL, *odev = NULL;
336 struct mtk_flow_entry *entry;
337+ struct net_device_path_ctx ctx = {};
338+ struct net_device_path path = {};
339 int offload_type = 0;
340 int wed_index = -1;
341 u16 addr_type = 0;
342@@ -242,6 +244,10 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
343 struct flow_match_meta match;
344
345 flow_rule_match_meta(rule, &match);
346+ idev = __dev_get_by_index(&init_net, match.key->ingress_ifindex);
347+
348+ if (!idev)
349+ pr_info("[%s] idev doesn't exist !\n", __func__);
350 } else {
351 return -EOPNOTSUPP;
352 }
353@@ -435,11 +441,25 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
354 if (!entry)
355 return -ENOMEM;
356
357+ i = 0;
358+ if (idev && idev->netdev_ops->ndo_fill_receive_path) {
359+ ctx.dev = idev;
360+ idev->netdev_ops->ndo_fill_receive_path(&ctx, &path);
361+ i = path.mtk_wdma.wdma_idx;
362+ if (i >= eth->ppe_num) {
363+ if (printk_ratelimit())
364+ pr_info("[%s] PPE%d doesn't exist, please check mtketh-ppe-num in dts !\n", __func__, i);
365+
366+ return -EINVAL;
367+ }
368+ }
369+
370 entry->cookie = f->cookie;
371 memcpy(&entry->data, &foe, sizeof(entry->data));
372+ entry->ppe_index = i;
373 entry->wed_index = wed_index;
374
375- if (mtk_foe_entry_commit(eth->ppe, entry) < 0)
376+ if (mtk_foe_entry_commit(eth->ppe[i], entry) < 0)
377 goto free;
378
379 err = rhashtable_insert_fast(&eth->flow_table, &entry->node,
380@@ -450,7 +470,7 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
381 return 0;
382
383 clear:
384- mtk_foe_entry_clear(eth->ppe, entry);
385+ mtk_foe_entry_clear(eth->ppe[i], entry);
386 free:
387 kfree(entry);
388 if (wed_index >= 0)
389@@ -462,13 +482,15 @@ static int
390 mtk_flow_offload_destroy(struct mtk_eth *eth, struct flow_cls_offload *f)
391 {
392 struct mtk_flow_entry *entry;
393+ int i;
394
395 entry = rhashtable_lookup(&eth->flow_table, &f->cookie,
396 mtk_flow_ht_params);
397 if (!entry)
398 return -ENOENT;
399
400- mtk_foe_entry_clear(eth->ppe, entry);
401+ i = entry->ppe_index;
402+ mtk_foe_entry_clear(eth->ppe[i], entry);
403 rhashtable_remove_fast(&eth->flow_table, &entry->node,
404 mtk_flow_ht_params);
405 if (entry->wed_index >= 0)
406@@ -483,13 +505,15 @@ mtk_flow_offload_stats(struct mtk_eth *eth, struct flow_cls_offload *f)
407 {
408 struct mtk_flow_entry *entry;
409 u32 idle;
410+ int i;
411
412 entry = rhashtable_lookup(&eth->flow_table, &f->cookie,
413 mtk_flow_ht_params);
414 if (!entry)
415 return -ENOENT;
416
417- idle = mtk_foe_entry_idle_time(eth->ppe, entry);
418+ i = entry->ppe_index;
419+ idle = mtk_foe_entry_idle_time(eth->ppe[i], entry);
420 f->stats.lastused = jiffies - idle * HZ;
421
422 return 0;
423@@ -540,9 +564,12 @@ mtk_eth_setup_tc_block(struct net_device *dev, struct flow_block_offload *f)
424 static LIST_HEAD(block_cb_list);
425 struct flow_block_cb *block_cb;
426 flow_setup_cb_t *cb;
427+ int i;
428
429- if (!eth->ppe || !eth->ppe->foe_table)
430- return -EOPNOTSUPP;
431+ for (i = 0; i < eth->ppe_num; i++) {
432+ if (!eth->ppe[i] || !eth->ppe[i]->foe_table)
433+ return -EOPNOTSUPP;
434+ }
435
436 if (f->binder_type != FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
437 return -EOPNOTSUPP;
438@@ -591,9 +618,9 @@ int mtk_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,
439 }
440 }
441
442-int mtk_eth_offload_init(struct mtk_eth *eth)
443+int mtk_eth_offload_init(struct mtk_eth *eth, int id)
444 {
445- if (!eth->ppe || !eth->ppe->foe_table)
446+ if (!eth->ppe[id] || !eth->ppe[id]->foe_table)
447 return 0;
448
449 return rhashtable_init(&eth->flow_table, &mtk_flow_ht_params);
450diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
451index 35998b1a7..0ada2461b 100644
452--- a/include/linux/netdevice.h
453+++ b/include/linux/netdevice.h
454@@ -1302,6 +1302,8 @@ struct tlsdev_ops;
455 * rtnl_lock is not held.
456 * int (*ndo_fill_forward_path)(struct net_device_path_ctx *ctx, struct net_device_path *path);
457 * Get the forwarding path to reach the real device from the HW destination address
458+ * int (*ndo_fill_receive_path)(struct net_device_path_ctx *ctx, struct net_device_path *path);
459+ * Get the receiving path to reach the real device from the HW source address
460 */
461 struct net_device_ops {
462 int (*ndo_init)(struct net_device *dev);
463@@ -1501,6 +1503,8 @@ struct net_device_ops {
464 struct devlink_port * (*ndo_get_devlink_port)(struct net_device *dev);
465 int (*ndo_fill_forward_path)(struct net_device_path_ctx *ctx,
466 struct net_device_path *path);
467+ int (*ndo_fill_receive_path)(struct net_device_path_ctx *ctx,
468+ struct net_device_path *path);
469 };
470
471 /**
472--
4732.18.0
474