net: dsa: Associate slave network device with CPU port
authorFlorian Fainelli <f.fainelli@gmail.com>
Tue, 13 Jun 2017 20:27:21 +0000 (13:27 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 13 Jun 2017 20:35:03 +0000 (16:35 -0400)
In preparation for supporting multiple CPU ports with DSA, have the
dsa_port structure know which CPU it is associated with. This will be
important in order to make sure the correct CPU is used for transmission
of the frames. If not for functional reasons, for performance (e.g: load
balancing) and forwarding decisions.

Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/dsa.h
net/dsa/dsa2.c
net/dsa/dsa_priv.h
net/dsa/legacy.c
net/dsa/slave.c

index 7e93869819f926f0723fa15cd4819c34910a915b..58969b9a090cc8f0e0e9e1ede7b5484ab4b959bd 100644 (file)
@@ -171,6 +171,7 @@ struct dsa_port {
        struct dsa_switch       *ds;
        unsigned int            index;
        const char              *name;
+       struct dsa_port         *cpu_dp;
        struct net_device       *netdev;
        struct device_node      *dn;
        unsigned int            ageing_time;
index ab48c4f989da9a305d5c08ef9dff38888b91e042..52af8401af077c5b196b8f2616ae0d4130040d75 100644 (file)
@@ -490,6 +490,8 @@ static int dsa_cpu_parse(struct dsa_port *port, u32 index,
        enum dsa_tag_protocol tag_protocol;
        struct net_device *ethernet_dev;
        struct device_node *ethernet;
+       struct dsa_port *p;
+       unsigned int i;
 
        if (port->dn) {
                ethernet = of_parse_phandle(port->dn, "ethernet", 0);
@@ -507,6 +509,15 @@ static int dsa_cpu_parse(struct dsa_port *port, u32 index,
        if (!dst->cpu_dp) {
                dst->cpu_dp = port;
                dst->cpu_dp->netdev = ethernet_dev;
+
+               for (i = 0; i < ds->num_ports; i++) {
+                       p = &ds->ports[i];
+                       if (!dsa_port_is_valid(p) ||
+                           i == index)
+                               continue;
+
+                       p->cpu_dp = port;
+               }
        }
 
        tag_protocol = ds->ops->get_tag_protocol(ds);
index 5c510f4ba0cea67715455cd5f85759d2df1f22bb..7c2326f3b538f29fbc339b45fde22a1c01112099 100644 (file)
@@ -185,7 +185,7 @@ extern const struct dsa_device_ops trailer_netdev_ops;
 
 static inline struct net_device *dsa_master_netdev(struct dsa_slave_priv *p)
 {
-       return p->dp->ds->dst->cpu_dp->netdev;
+       return p->dp->cpu_dp->netdev;
 }
 
 #endif
index 5d4f6ffa34242e41450e10cdb29f79a8d76d751f..e60906125375eaca0768e89157c53557f7589887 100644 (file)
@@ -129,6 +129,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
                        ds->dsa_port_mask |= 1 << i;
                } else {
                        ds->enabled_port_mask |= 1 << i;
+                       ds->ports[i].cpu_dp = dst->cpu_dp;
                }
                valid_name_found = true;
        }
index 9bf4c27f33930e7284eee22ef1b32f43d8314f7b..a80b46777a048373c166d03374cd4f1dc436cb3b 100644 (file)
@@ -1140,9 +1140,11 @@ int dsa_slave_create(struct dsa_switch *ds, struct device *parent,
        struct net_device *master;
        struct net_device *slave_dev;
        struct dsa_slave_priv *p;
+       struct dsa_port *cpu_dp;
        int ret;
 
-       master = ds->dst->cpu_dp->netdev;
+       cpu_dp = ds->dst->cpu_dp;
+       master = cpu_dp->netdev;
 
        slave_dev = alloc_netdev(sizeof(struct dsa_slave_priv), name,
                                 NET_NAME_UNKNOWN, ether_setup);