51d609cde179e948098d9ef4c6fcd2502e731a43
[librecmc/librecmc.git] /
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Wed, 24 Mar 2021 02:30:37 +0100
3 Subject: [PATCH] net: dsa: resolve forwarding path for dsa slave ports
4
5 Add .ndo_fill_forward_path for dsa slave port devices
6
7 Signed-off-by: Felix Fietkau <nbd@nbd.name>
8 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 ---
10
11 --- a/include/linux/netdevice.h
12 +++ b/include/linux/netdevice.h
13 @@ -846,6 +846,7 @@ enum net_device_path_type {
14         DEV_PATH_VLAN,
15         DEV_PATH_BRIDGE,
16         DEV_PATH_PPPOE,
17 +       DEV_PATH_DSA,
18  };
19  
20  struct net_device_path {
21 @@ -866,6 +867,10 @@ struct net_device_path {
22                         u16             vlan_id;
23                         __be16          vlan_proto;
24                 } bridge;
25 +               struct {
26 +                       int port;
27 +                       u16 proto;
28 +               } dsa;
29         };
30  };
31  
32 --- a/net/dsa/slave.c
33 +++ b/net/dsa/slave.c
34 @@ -1619,6 +1619,21 @@ static struct devlink_port *dsa_slave_ge
35         return dp->ds->devlink ? &dp->devlink_port : NULL;
36  }
37  
38 +static int dsa_slave_fill_forward_path(struct net_device_path_ctx *ctx,
39 +                                      struct net_device_path *path)
40 +{
41 +       struct dsa_port *dp = dsa_slave_to_port(ctx->dev);
42 +       struct dsa_port *cpu_dp = dp->cpu_dp;
43 +
44 +       path->dev = ctx->dev;
45 +       path->type = DEV_PATH_DSA;
46 +       path->dsa.proto = cpu_dp->tag_ops->proto;
47 +       path->dsa.port = dp->index;
48 +       ctx->dev = cpu_dp->master;
49 +
50 +       return 0;
51 +}
52 +
53  static const struct net_device_ops dsa_slave_netdev_ops = {
54         .ndo_open               = dsa_slave_open,
55         .ndo_stop               = dsa_slave_close,
56 @@ -1644,6 +1659,7 @@ static const struct net_device_ops dsa_s
57         .ndo_vlan_rx_kill_vid   = dsa_slave_vlan_rx_kill_vid,
58         .ndo_get_devlink_port   = dsa_slave_get_devlink_port,
59         .ndo_change_mtu         = dsa_slave_change_mtu,
60 +       .ndo_fill_forward_path  = dsa_slave_fill_forward_path,
61  };
62  
63  static struct device_type dsa_type = {