6b7f3d6018c583037b6ba4ac960d8f501e6dbedb
[openwrt/staging/ldir.git] /
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Tue, 8 Nov 2022 15:03:15 +0100
3 Subject: [PATCH] net: dsa: add support for DSA rx offloading via
4 metadata dst
5
6 If a metadata dst is present with the type METADATA_HW_PORT_MUX on a dsa cpu
7 port netdev, assume that it carries the port number and that there is no DSA
8 tag present in the skb data.
9
10 Signed-off-by: Felix Fietkau <nbd@nbd.name>
11 ---
12
13 --- a/net/core/flow_dissector.c
14 +++ b/net/core/flow_dissector.c
15 @@ -971,12 +971,14 @@ bool __skb_flow_dissect(const struct net
16 #if IS_ENABLED(CONFIG_NET_DSA)
17 if (unlikely(skb->dev && netdev_uses_dsa(skb->dev) &&
18 proto == htons(ETH_P_XDSA))) {
19 + struct metadata_dst *md_dst = skb_metadata_dst(skb);
20 const struct dsa_device_ops *ops;
21 int offset = 0;
22
23 ops = skb->dev->dsa_ptr->tag_ops;
24 /* Only DSA header taggers break flow dissection */
25 - if (ops->needed_headroom) {
26 + if (ops->needed_headroom &&
27 + (!md_dst || md_dst->type != METADATA_HW_PORT_MUX)) {
28 if (ops->flow_dissect)
29 ops->flow_dissect(skb, &proto, &offset);
30 else
31 --- a/net/dsa/dsa.c
32 +++ b/net/dsa/dsa.c
33 @@ -11,6 +11,7 @@
34 #include <linux/netdevice.h>
35 #include <linux/sysfs.h>
36 #include <linux/ptp_classify.h>
37 +#include <net/dst_metadata.h>
38
39 #include "dsa_priv.h"
40
41 @@ -216,6 +217,7 @@ static bool dsa_skb_defer_rx_timestamp(s
42 static int dsa_switch_rcv(struct sk_buff *skb, struct net_device *dev,
43 struct packet_type *pt, struct net_device *unused)
44 {
45 + struct metadata_dst *md_dst = skb_metadata_dst(skb);
46 struct dsa_port *cpu_dp = dev->dsa_ptr;
47 struct sk_buff *nskb = NULL;
48 struct dsa_slave_priv *p;
49 @@ -229,7 +231,22 @@ static int dsa_switch_rcv(struct sk_buff
50 if (!skb)
51 return 0;
52
53 - nskb = cpu_dp->rcv(skb, dev);
54 + if (md_dst && md_dst->type == METADATA_HW_PORT_MUX) {
55 + unsigned int port = md_dst->u.port_info.port_id;
56 +
57 + skb_dst_drop(skb);
58 + if (!skb_has_extensions(skb))
59 + skb->slow_gro = 0;
60 +
61 + skb->dev = dsa_master_find_slave(dev, 0, port);
62 + if (likely(skb->dev)) {
63 + dsa_default_offload_fwd_mark(skb);
64 + nskb = skb;
65 + }
66 + } else {
67 + nskb = cpu_dp->rcv(skb, dev);
68 + }
69 +
70 if (!nskb) {
71 kfree_skb(skb);
72 return 0;