9adb067015ee955388fc0b7f051e491c1b0a4379
[openwrt/staging/ldir.git] /
1 From: David Bentham <db260179@gmail.com>
2 Date: Mon, 21 Feb 2022 15:36:16 +0100
3 Subject: [PATCH] net: ethernet: mtk_eth_soc: add ipv6 flow offload
4 support
5
6 Add the missing IPv6 flow offloading support for routing only.
7 Hardware flow offloading is done by the packet processing engine (PPE)
8 of the Ethernet MAC and as it doesn't support mangling of IPv6 packets,
9 IPv6 NAT cannot be supported.
10
11 Signed-off-by: David Bentham <db260179@gmail.com>
12 Signed-off-by: Felix Fietkau <nbd@nbd.name>
13 ---
14
15 --- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
16 +++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
17 @@ -6,6 +6,7 @@
18 #include <linux/if_ether.h>
19 #include <linux/rhashtable.h>
20 #include <linux/ip.h>
21 +#include <linux/ipv6.h>
22 #include <net/flow_offload.h>
23 #include <net/pkt_cls.h>
24 #include <net/dsa.h>
25 @@ -20,6 +21,11 @@ struct mtk_flow_data {
26 __be32 src_addr;
27 __be32 dst_addr;
28 } v4;
29 +
30 + struct {
31 + struct in6_addr src_addr;
32 + struct in6_addr dst_addr;
33 + } v6;
34 };
35
36 __be16 src_port;
37 @@ -65,6 +71,14 @@ mtk_flow_set_ipv4_addr(struct mtk_foe_en
38 data->v4.dst_addr, data->dst_port);
39 }
40
41 +static int
42 +mtk_flow_set_ipv6_addr(struct mtk_foe_entry *foe, struct mtk_flow_data *data)
43 +{
44 + return mtk_foe_entry_set_ipv6_tuple(foe,
45 + data->v6.src_addr.s6_addr32, data->src_port,
46 + data->v6.dst_addr.s6_addr32, data->dst_port);
47 +}
48 +
49 static void
50 mtk_flow_offload_mangle_eth(const struct flow_action_entry *act, void *eth)
51 {
52 @@ -296,6 +310,9 @@ mtk_flow_offload_replace(struct mtk_eth
53 case FLOW_DISSECTOR_KEY_IPV4_ADDRS:
54 offload_type = MTK_PPE_PKT_TYPE_IPV4_HNAPT;
55 break;
56 + case FLOW_DISSECTOR_KEY_IPV6_ADDRS:
57 + offload_type = MTK_PPE_PKT_TYPE_IPV6_ROUTE_5T;
58 + break;
59 default:
60 return -EOPNOTSUPP;
61 }
62 @@ -331,6 +348,17 @@ mtk_flow_offload_replace(struct mtk_eth
63 mtk_flow_set_ipv4_addr(&foe, &data, false);
64 }
65
66 + if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) {
67 + struct flow_match_ipv6_addrs addrs;
68 +
69 + flow_rule_match_ipv6_addrs(rule, &addrs);
70 +
71 + data.v6.src_addr = addrs.key->src;
72 + data.v6.dst_addr = addrs.key->dst;
73 +
74 + mtk_flow_set_ipv6_addr(&foe, &data);
75 + }
76 +
77 flow_action_for_each(i, act, &rule->action) {
78 if (act->id != FLOW_ACTION_MANGLE)
79 continue;