net: dsa: use ports list to setup default CPU port
authorVivien Didelot <vivien.didelot@gmail.com>
Mon, 21 Oct 2019 20:51:24 +0000 (16:51 -0400)
committerJakub Kicinski <jakub.kicinski@netronome.com>
Tue, 22 Oct 2019 19:37:07 +0000 (12:37 -0700)
Use the new ports list instead of iterating over switches and their
ports when setting up the default CPU port. Unassign it on teardown.

Now that we can iterate over multiple CPU ports, remove dst->cpu_dp.

At the same time, provide a better error message for CPU-less tree.

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
include/net/dsa.h
net/dsa/dsa2.c

index bd08bdee8341886c75c7fe2c8b37322e85a3db1b..f572134eb5dee6c93c88fe47b3b2564de0ac50a7 100644 (file)
@@ -120,11 +120,6 @@ struct dsa_switch_tree {
         */
        struct dsa_platform_data        *pd;
 
-       /*
-        * The switch port to which the CPU is attached.
-        */
-       struct dsa_port         *cpu_dp;
-
        /* List of switch ports */
        struct list_head ports;
 
index 80191c7702a94541cbc5ada8c7147211f3a1d441..bf8b4e0fcb4fbafcfae385a446dd4eba75ebdc9a 100644 (file)
@@ -197,38 +197,29 @@ static struct dsa_port *dsa_tree_find_first_cpu(struct dsa_switch_tree *dst)
 
 static int dsa_tree_setup_default_cpu(struct dsa_switch_tree *dst)
 {
-       struct dsa_switch *ds;
-       struct dsa_port *dp;
-       int device, port;
+       struct dsa_port *cpu_dp, *dp;
 
-       /* DSA currently only supports a single CPU port */
-       dst->cpu_dp = dsa_tree_find_first_cpu(dst);
-       if (!dst->cpu_dp) {
-               pr_warn("Tree has no master device\n");
+       cpu_dp = dsa_tree_find_first_cpu(dst);
+       if (!cpu_dp) {
+               pr_err("DSA: tree %d has no CPU port\n", dst->index);
                return -EINVAL;
        }
 
        /* Assign the default CPU port to all ports of the fabric */
-       for (device = 0; device < DSA_MAX_SWITCHES; device++) {
-               ds = dst->ds[device];
-               if (!ds)
-                       continue;
-
-               for (port = 0; port < ds->num_ports; port++) {
-                       dp = &ds->ports[port];
-
-                       if (dsa_port_is_user(dp) || dsa_port_is_dsa(dp))
-                               dp->cpu_dp = dst->cpu_dp;
-               }
-       }
+       list_for_each_entry(dp, &dst->ports, list)
+               if (dsa_port_is_user(dp) || dsa_port_is_dsa(dp))
+                       dp->cpu_dp = cpu_dp;
 
        return 0;
 }
 
 static void dsa_tree_teardown_default_cpu(struct dsa_switch_tree *dst)
 {
-       /* DSA currently only supports a single CPU port */
-       dst->cpu_dp = NULL;
+       struct dsa_port *dp;
+
+       list_for_each_entry(dp, &dst->ports, list)
+               if (dsa_port_is_user(dp) || dsa_port_is_dsa(dp))
+                       dp->cpu_dp = NULL;
 }
 
 static int dsa_port_setup(struct dsa_port *dp)