mediatek: fix hardware flow offload
[openwrt/staging/rmilecki.git] / target / linux / generic / pending-5.4 / 647-net-dsa-support-hardware-flow-table-offload.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Thu, 17 Sep 2020 18:41:23 +0200
3 Subject: [PATCH] net: dsa: support hardware flow table offload
4
5 Look up the master device and the port id
6
7 Signed-off-by: Felix Fietkau <nbd@nbd.name>
8 ---
9
10 --- a/include/net/netfilter/nf_flow_table.h
11 +++ b/include/net/netfilter/nf_flow_table.h
12 @@ -90,6 +90,7 @@ struct flow_offload {
13 #define FLOW_OFFLOAD_PATH_ETHERNET BIT(0)
14 #define FLOW_OFFLOAD_PATH_VLAN BIT(1)
15 #define FLOW_OFFLOAD_PATH_PPPOE BIT(2)
16 +#define FLOW_OFFLOAD_PATH_DSA BIT(3)
17
18 struct flow_offload_hw_path {
19 struct net_device *dev;
20 @@ -100,6 +101,7 @@ struct flow_offload_hw_path {
21 u16 vlan_proto;
22 u16 vlan_id;
23 u16 pppoe_sid;
24 + u16 dsa_port;
25 };
26
27 #define NF_FLOW_TIMEOUT (30 * HZ)
28 --- a/net/dsa/slave.c
29 +++ b/net/dsa/slave.c
30 @@ -19,6 +19,10 @@
31 #include <linux/if_bridge.h>
32 #include <linux/netpoll.h>
33 #include <linux/ptp_classify.h>
34 +#if IS_ENABLED(CONFIG_NF_FLOW_TABLE)
35 +#include <linux/netfilter.h>
36 +#include <net/netfilter/nf_flow_table.h>
37 +#endif
38
39 #include "dsa_priv.h"
40
41 @@ -1221,6 +1225,27 @@ static struct devlink_port *dsa_slave_ge
42 return dp->ds->devlink ? &dp->devlink_port : NULL;
43 }
44
45 +#if IS_ENABLED(CONFIG_NF_FLOW_TABLE)
46 +static int dsa_flow_offload_check(struct flow_offload_hw_path *path)
47 +{
48 + struct net_device *dev = path->dev;
49 + struct dsa_port *dp;
50 +
51 + if (!(path->flags & FLOW_OFFLOAD_PATH_ETHERNET))
52 + return -EINVAL;
53 +
54 + dp = dsa_slave_to_port(dev);
55 + path->dsa_port = dp->index;
56 + path->dev = dsa_slave_to_master(dev);
57 + path->flags |= FLOW_OFFLOAD_PATH_DSA;
58 +
59 + if (path->dev->netdev_ops->ndo_flow_offload_check)
60 + return path->dev->netdev_ops->ndo_flow_offload_check(path);
61 +
62 + return 0;
63 +}
64 +#endif /* CONFIG_NF_FLOW_TABLE */
65 +
66 static const struct net_device_ops dsa_slave_netdev_ops = {
67 .ndo_open = dsa_slave_open,
68 .ndo_stop = dsa_slave_close,
69 @@ -1245,6 +1270,9 @@ static const struct net_device_ops dsa_s
70 .ndo_vlan_rx_add_vid = dsa_slave_vlan_rx_add_vid,
71 .ndo_vlan_rx_kill_vid = dsa_slave_vlan_rx_kill_vid,
72 .ndo_get_devlink_port = dsa_slave_get_devlink_port,
73 +#if IS_ENABLED(CONFIG_NF_FLOW_TABLE)
74 + .ndo_flow_offload_check = dsa_flow_offload_check,
75 +#endif
76 };
77
78 static struct device_type dsa_type = {