blob: 7a0601526d6fc6d773bbedb47b0d7bfea3c131ac [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
developer57382532022-07-06 11:59:11 +0800144@@ -110,7 +110,12 @@
developer8cb3ac72022-07-04 10:55:14 +0800145 #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
developer57382532022-07-06 11:59:11 +0800149+#if defined(CONFIG_MEDIATEK_NETSYS_V2)
developer8cb3ac72022-07-04 10:55:14 +0800150+#define MTK_GDMA_TO_PPE0 0x3333
151+#define MTK_GDMA_TO_PPE1 0x4444
developer57382532022-07-06 11:59:11 +0800152+#else
153+#define MTK_GDMA_TO_PPE0 0x4444
154+#endif
developer8cb3ac72022-07-04 10:55:14 +0800155 #define MTK_GDMA_DROP_ALL 0x7777
156
157 /* Unicast Filter MAC Address Register - Low */
158@@ -1299,7 +1300,8 @@ struct mtk_eth {
159 spinlock_t syscfg0_lock;
160 struct timer_list mtk_dma_monitor_timer;
161
162- struct mtk_ppe *ppe;
163+ u8 ppe_num;
164+ struct mtk_ppe *ppe[MTK_MAX_PPE_NUM];
165 struct rhashtable flow_table;
166 };
167
168@@ -1349,9 +1351,11 @@ int mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id);
169 void mtk_gdm_config(struct mtk_eth *eth, u32 config);
170 void ethsys_reset(struct mtk_eth *eth, u32 reset_bits);
171
172-int mtk_eth_offload_init(struct mtk_eth *eth);
173+int mtk_eth_offload_init(struct mtk_eth *eth, int id);
174 int mtk_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,
175 void *type_data);
176 void mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev);
177
178+int mtk_ppe_debugfs_init(struct mtk_eth *eth);
179+
180 #endif /* MTK_ETH_H */
181diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
182index d46e91178..3d6ff30ba 100755
183--- a/drivers/net/ethernet/mediatek/mtk_ppe.c
184+++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
185@@ -677,7 +677,7 @@ int mtk_foe_entry_idle_time(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
186 }
187
188 struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
189- int version)
190+ int version, int id)
191 {
192 struct device *dev = eth->dev;
193 struct mtk_foe_entry *foe;
194@@ -696,6 +696,7 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
195 ppe->eth = eth;
196 ppe->dev = dev;
197 ppe->version = version;
198+ ppe->id = id;
199
200 foe = dmam_alloc_coherent(ppe->dev, MTK_PPE_ENTRIES * sizeof(*foe),
201 &ppe->foe_phys, GFP_KERNEL);
202@@ -704,8 +705,6 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
203
204 ppe->foe_table = foe;
205
206- mtk_ppe_debugfs_init(ppe);
207-
208 return ppe;
209 }
210
211diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
212index a76f4b0ac..21cc55145 100644
213--- a/drivers/net/ethernet/mediatek/mtk_ppe.h
214+++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
215@@ -8,6 +8,8 @@
216 #include <linux/bitfield.h>
217 #include <linux/rhashtable.h>
218
219+#define MTK_MAX_PPE_NUM 2
220+
221 #define MTK_ETH_PPE_BASE 0x2000
222
223 #define MTK_PPE_ENTRIES_SHIFT 3
224@@ -253,6 +255,7 @@ struct mtk_flow_entry {
225 };
226 };
227 u8 type;
228+ s8 ppe_index;
229 s8 wed_index;
230 u16 hash;
231 union {
232@@ -272,6 +275,7 @@ struct mtk_ppe {
233 struct device *dev;
234 void __iomem *base;
235 int version;
236+ int id;
237
238 struct mtk_foe_entry *foe_table;
239 dma_addr_t foe_phys;
240@@ -284,7 +288,7 @@ struct mtk_ppe {
241 void *acct_table;
242 };
243
244-struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int version);
245+struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int version, int id);
246 int mtk_ppe_start(struct mtk_ppe *ppe);
247 int mtk_ppe_stop(struct mtk_ppe *ppe);
248
249@@ -335,6 +339,5 @@ int mtk_foe_entry_set_wdma(struct mtk_foe_entry *entry, int wdma_idx, int txq,
250 int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_flow_entry *entry);
251 void mtk_foe_entry_clear(struct mtk_ppe *ppe, struct mtk_flow_entry *entry);
252 int mtk_foe_entry_idle_time(struct mtk_ppe *ppe, struct mtk_flow_entry *entry);
253-int mtk_ppe_debugfs_init(struct mtk_ppe *ppe);
254
255 #endif
256diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c b/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
257index a591ab1fd..f4ebe5944 100644
258--- a/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
259+++ b/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
260@@ -73,9 +73,8 @@ mtk_print_addr_info(struct seq_file *m, struct mtk_flow_addr_info *ai)
261 }
262
263 static int
264-mtk_ppe_debugfs_foe_show(struct seq_file *m, void *private, bool bind)
265+mtk_ppe_debugfs_foe_show(struct seq_file *m, struct mtk_ppe *ppe, bool bind)
266 {
267- struct mtk_ppe *ppe = m->private;
268 int i;
269
270 for (i = 0; i < MTK_PPE_ENTRIES; i++) {
271@@ -122,6 +121,8 @@ mtk_ppe_debugfs_foe_show(struct seq_file *m, void *private, bool bind)
272 break;
273 }
274
275+ seq_printf(m, " ppe=%d", ppe->id);
276+
277 seq_printf(m, " orig=");
278 mtk_print_addr_info(m, &ai);
279
280@@ -164,13 +165,25 @@ mtk_ppe_debugfs_foe_show(struct seq_file *m, void *private, bool bind)
281 static int
282 mtk_ppe_debugfs_foe_show_all(struct seq_file *m, void *private)
283 {
284- return mtk_ppe_debugfs_foe_show(m, private, false);
285+ struct mtk_eth *eth = m->private;
286+ int i;
287+
288+ for (i = 0; i < eth->ppe_num; i++)
289+ mtk_ppe_debugfs_foe_show(m, eth->ppe[i], false);
290+
291+ return 0;
292 }
293
294 static int
295 mtk_ppe_debugfs_foe_show_bind(struct seq_file *m, void *private)
296 {
297- return mtk_ppe_debugfs_foe_show(m, private, true);
298+ struct mtk_eth *eth = m->private;
299+ int i;
300+
301+ for (i = 0; i < eth->ppe_num; i++)
302+ mtk_ppe_debugfs_foe_show(m, eth->ppe[i], true);
303+
304+ return 0;
305 }
306
307 static int
308@@ -187,7 +200,7 @@ mtk_ppe_debugfs_foe_open_bind(struct inode *inode, struct file *file)
309 inode->i_private);
310 }
311
312-int mtk_ppe_debugfs_init(struct mtk_ppe *ppe)
313+int mtk_ppe_debugfs_init(struct mtk_eth *eth)
314 {
315 static const struct file_operations fops_all = {
316 .open = mtk_ppe_debugfs_foe_open_all,
317@@ -209,8 +222,8 @@ int mtk_ppe_debugfs_init(struct mtk_ppe *ppe)
318 if (!root)
319 return -ENOMEM;
320
321- debugfs_create_file("entries", S_IRUGO, root, ppe, &fops_all);
322- debugfs_create_file("bind", S_IRUGO, root, ppe, &fops_bind);
323+ debugfs_create_file("entries", S_IRUGO, root, eth, &fops_all);
324+ debugfs_create_file("bind", S_IRUGO, root, eth, &fops_bind);
325
326 return 0;
327 }
328diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
329old mode 100644
330new mode 100755
331index 5a4201447..2f7d76d3b
332--- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
333+++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
334@@ -226,8 +226,10 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
335 struct flow_action_entry *act;
336 struct mtk_flow_data data = {};
337 struct mtk_foe_entry foe;
338- struct net_device *odev = NULL;
339+ struct net_device *idev = NULL, *odev = NULL;
340 struct mtk_flow_entry *entry;
341+ struct net_device_path_ctx ctx = {};
342+ struct net_device_path path = {};
343 int offload_type = 0;
344 int wed_index = -1;
345 u16 addr_type = 0;
346@@ -242,6 +244,10 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
347 struct flow_match_meta match;
348
349 flow_rule_match_meta(rule, &match);
350+ idev = __dev_get_by_index(&init_net, match.key->ingress_ifindex);
351+
352+ if (!idev)
353+ pr_info("[%s] idev doesn't exist !\n", __func__);
354 } else {
355 return -EOPNOTSUPP;
356 }
357@@ -435,11 +441,25 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
358 if (!entry)
359 return -ENOMEM;
360
361+ i = 0;
362+ if (idev && idev->netdev_ops->ndo_fill_receive_path) {
363+ ctx.dev = idev;
364+ idev->netdev_ops->ndo_fill_receive_path(&ctx, &path);
365+ i = path.mtk_wdma.wdma_idx;
366+ if (i >= eth->ppe_num) {
367+ if (printk_ratelimit())
368+ pr_info("[%s] PPE%d doesn't exist, please check mtketh-ppe-num in dts !\n", __func__, i);
369+
370+ return -EINVAL;
371+ }
372+ }
373+
374 entry->cookie = f->cookie;
375 memcpy(&entry->data, &foe, sizeof(entry->data));
376+ entry->ppe_index = i;
377 entry->wed_index = wed_index;
378
379- if (mtk_foe_entry_commit(eth->ppe, entry) < 0)
380+ if (mtk_foe_entry_commit(eth->ppe[i], entry) < 0)
381 goto free;
382
383 err = rhashtable_insert_fast(&eth->flow_table, &entry->node,
384@@ -450,7 +470,7 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f)
385 return 0;
386
387 clear:
388- mtk_foe_entry_clear(eth->ppe, entry);
389+ mtk_foe_entry_clear(eth->ppe[i], entry);
390 free:
391 kfree(entry);
392 if (wed_index >= 0)
393@@ -462,13 +482,15 @@ static int
394 mtk_flow_offload_destroy(struct mtk_eth *eth, struct flow_cls_offload *f)
395 {
396 struct mtk_flow_entry *entry;
397+ int i;
398
399 entry = rhashtable_lookup(&eth->flow_table, &f->cookie,
400 mtk_flow_ht_params);
401 if (!entry)
402 return -ENOENT;
403
404- mtk_foe_entry_clear(eth->ppe, entry);
405+ i = entry->ppe_index;
406+ mtk_foe_entry_clear(eth->ppe[i], entry);
407 rhashtable_remove_fast(&eth->flow_table, &entry->node,
408 mtk_flow_ht_params);
409 if (entry->wed_index >= 0)
410@@ -483,13 +505,15 @@ mtk_flow_offload_stats(struct mtk_eth *eth, struct flow_cls_offload *f)
411 {
412 struct mtk_flow_entry *entry;
413 u32 idle;
414+ int i;
415
416 entry = rhashtable_lookup(&eth->flow_table, &f->cookie,
417 mtk_flow_ht_params);
418 if (!entry)
419 return -ENOENT;
420
421- idle = mtk_foe_entry_idle_time(eth->ppe, entry);
422+ i = entry->ppe_index;
423+ idle = mtk_foe_entry_idle_time(eth->ppe[i], entry);
424 f->stats.lastused = jiffies - idle * HZ;
425
426 return 0;
427@@ -540,9 +564,12 @@ mtk_eth_setup_tc_block(struct net_device *dev, struct flow_block_offload *f)
428 static LIST_HEAD(block_cb_list);
429 struct flow_block_cb *block_cb;
430 flow_setup_cb_t *cb;
431+ int i;
432
433- if (!eth->ppe || !eth->ppe->foe_table)
434- return -EOPNOTSUPP;
435+ for (i = 0; i < eth->ppe_num; i++) {
436+ if (!eth->ppe[i] || !eth->ppe[i]->foe_table)
437+ return -EOPNOTSUPP;
438+ }
439
440 if (f->binder_type != FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
441 return -EOPNOTSUPP;
442@@ -591,9 +618,9 @@ int mtk_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,
443 }
444 }
445
446-int mtk_eth_offload_init(struct mtk_eth *eth)
447+int mtk_eth_offload_init(struct mtk_eth *eth, int id)
448 {
449- if (!eth->ppe || !eth->ppe->foe_table)
450+ if (!eth->ppe[id] || !eth->ppe[id]->foe_table)
451 return 0;
452
453 return rhashtable_init(&eth->flow_table, &mtk_flow_ht_params);
454diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
455index 35998b1a7..0ada2461b 100644
456--- a/include/linux/netdevice.h
457+++ b/include/linux/netdevice.h
458@@ -1302,6 +1302,8 @@ struct tlsdev_ops;
459 * rtnl_lock is not held.
460 * int (*ndo_fill_forward_path)(struct net_device_path_ctx *ctx, struct net_device_path *path);
461 * Get the forwarding path to reach the real device from the HW destination address
462+ * int (*ndo_fill_receive_path)(struct net_device_path_ctx *ctx, struct net_device_path *path);
463+ * Get the receiving path to reach the real device from the HW source address
464 */
465 struct net_device_ops {
466 int (*ndo_init)(struct net_device *dev);
467@@ -1501,6 +1503,8 @@ struct net_device_ops {
468 struct devlink_port * (*ndo_get_devlink_port)(struct net_device *dev);
469 int (*ndo_fill_forward_path)(struct net_device_path_ctx *ctx,
470 struct net_device_path *path);
471+ int (*ndo_fill_receive_path)(struct net_device_path_ctx *ctx,
472+ struct net_device_path *path);
473 };
474
475 /**
476--
4772.18.0
478