net: dsa: store CPU port pointer in the tree
authorVivien Didelot <vivien.didelot@savoirfairelinux.com>
Tue, 16 May 2017 18:10:33 +0000 (14:10 -0400)
committerDavid S. Miller <davem@davemloft.net>
Wed, 17 May 2017 18:19:12 +0000 (14:19 -0400)
A dsa_switch_tree instance holds a dsa_switch pointer and a port index
to identify the switch port to which the CPU is attached.

Now that the DSA layer has a dsa_port structure to hold this data, use
it to point the switch CPU port.

This patch simply substitutes s/dst->cpu_switch/dst->cpu_dp->ds/ and
s/dst->cpu_port/dst->cpu_dp->index/.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/b53/b53_common.c
drivers/net/dsa/bcm_sf2.c
drivers/net/dsa/mv88e6060.c
drivers/net/dsa/qca8k.c
include/net/dsa.h
net/dsa/dsa2.c
net/dsa/legacy.c
net/dsa/slave.c
net/dsa/tag_brcm.c
net/dsa/tag_qca.c
net/dsa/tag_trailer.c

index fa0eece21eef9825e716dd7744c556211a0b41c3..658a12c888a8798913ab915ef3c39bfe920c692f 100644 (file)
@@ -1344,7 +1344,7 @@ EXPORT_SYMBOL(b53_fdb_dump);
 int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br)
 {
        struct b53_device *dev = ds->priv;
-       s8 cpu_port = ds->dst->cpu_port;
+       s8 cpu_port = ds->dst->cpu_dp->index;
        u16 pvlan, reg;
        unsigned int i;
 
@@ -1390,7 +1390,7 @@ void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *br)
 {
        struct b53_device *dev = ds->priv;
        struct b53_vlan *vl = &dev->vlans[0];
-       s8 cpu_port = ds->dst->cpu_port;
+       s8 cpu_port = ds->dst->cpu_dp->index;
        unsigned int i;
        u16 pvlan, reg, pvid;
 
index 2be963252ca56a6caeb64434a694f08e1cc7719f..215d41c1e71fb5c5b966ad153878d13baed176c6 100644 (file)
@@ -228,7 +228,7 @@ static int bcm_sf2_port_setup(struct dsa_switch *ds, int port,
                              struct phy_device *phy)
 {
        struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
-       s8 cpu_port = ds->dst[ds->index].cpu_port;
+       s8 cpu_port = ds->dst->cpu_dp->index;
        unsigned int i;
        u32 reg;
 
@@ -832,7 +832,7 @@ static int bcm_sf2_sw_set_wol(struct dsa_switch *ds, int port,
 {
        struct net_device *p = ds->dst[ds->index].master_netdev;
        struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
-       s8 cpu_port = ds->dst[ds->index].cpu_port;
+       s8 cpu_port = ds->dst->cpu_dp->index;
        struct ethtool_wolinfo pwol;
 
        p->ethtool_ops->get_wol(p, &pwol);
index 5934b7a4c448e9654c1a8ea5ef147756d5d56fe1..dce7fa57eb553a477faadd3f15d6f0e1dcf394af 100644 (file)
@@ -176,7 +176,7 @@ static int mv88e6060_setup_port(struct dsa_switch *ds, int p)
                  ((p & 0xf) << PORT_VLAN_MAP_DBNUM_SHIFT) |
                   (dsa_is_cpu_port(ds, p) ?
                        ds->enabled_port_mask :
-                       BIT(ds->dst->cpu_port)));
+                       BIT(ds->dst->cpu_dp->index)));
 
        /* Port Association Vector: when learning source addresses
         * of packets, add the address to the address database using
index a4fd4ccf7b67794e22fc3259d96cc2f9aa6b8723..942b9ac7f92aca97202f9abd3a41ba4a0451cc7b 100644 (file)
@@ -507,7 +507,7 @@ qca8k_setup(struct dsa_switch *ds)
                pr_warn("regmap initialization failed");
 
        /* Initialize CPU port pad mode (xMII type, delays...) */
-       phy_mode = of_get_phy_mode(ds->ports[ds->dst->cpu_port].dn);
+       phy_mode = of_get_phy_mode(ds->dst->cpu_dp->dn);
        if (phy_mode < 0) {
                pr_err("Can't find phy-mode for master device\n");
                return phy_mode;
index 8e24677b1c62a5842f81496d7d18c071d2cf0af6..118a8bd2fd9a4f48b8068441c2897a596d1d7e52 100644 (file)
@@ -137,10 +137,9 @@ struct dsa_switch_tree {
        const struct ethtool_ops *master_orig_ethtool_ops;
 
        /*
-        * The switch and port to which the CPU is attached.
+        * The switch port to which the CPU is attached.
         */
-       struct dsa_switch       *cpu_switch;
-       s8                      cpu_port;
+       struct dsa_port         *cpu_dp;
 
        /*
         * Data for the individual switch chips.
@@ -251,7 +250,7 @@ struct dsa_switch {
 
 static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
 {
-       return !!(ds == ds->dst->cpu_switch && p == ds->dst->cpu_port);
+       return ds->dst->cpu_dp == &ds->ports[p];
 }
 
 static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p)
@@ -279,10 +278,10 @@ static inline u8 dsa_upstream_port(struct dsa_switch *ds)
         * Else return the (DSA) port number that connects to the
         * switch that is one hop closer to the cpu.
         */
-       if (dst->cpu_switch == ds)
-               return dst->cpu_port;
+       if (dst->cpu_dp->ds == ds)
+               return dst->cpu_dp->index;
        else
-               return ds->rtable[dst->cpu_switch->index];
+               return ds->rtable[dst->cpu_dp->ds->index];
 }
 
 struct switchdev_trans;
index 033b3bfb63dc1887b15b3e08f00a00f70b706ec4..2ac62349ba12a85aff5992132be6f399a3a203c8 100644 (file)
@@ -443,8 +443,8 @@ static int dsa_dst_apply(struct dsa_switch_tree *dst)
                        return err;
        }
 
-       if (dst->cpu_switch) {
-               err = dsa_cpu_port_ethtool_setup(dst->cpu_switch);
+       if (dst->cpu_dp) {
+               err = dsa_cpu_port_ethtool_setup(dst->cpu_dp->ds);
                if (err)
                        return err;
        }
@@ -484,8 +484,8 @@ static void dsa_dst_unapply(struct dsa_switch_tree *dst)
                dsa_ds_unapply(dst, ds);
        }
 
-       if (dst->cpu_switch)
-               dsa_cpu_port_ethtool_restore(dst->cpu_switch);
+       if (dst->cpu_dp)
+               dsa_cpu_port_ethtool_restore(dst->cpu_dp->ds);
 
        pr_info("DSA: tree %d unapplied\n", dst->tree);
        dst->applied = false;
@@ -518,10 +518,8 @@ static int dsa_cpu_parse(struct dsa_port *port, u32 index,
        if (!dst->master_netdev)
                dst->master_netdev = ethernet_dev;
 
-       if (!dst->cpu_switch) {
-               dst->cpu_switch = ds;
-               dst->cpu_port = index;
-       }
+       if (!dst->cpu_dp)
+               dst->cpu_dp = port;
 
        tag_protocol = ds->ops->get_tag_protocol(ds);
        dst->tag_ops = dsa_resolve_tag_protocol(tag_protocol);
index ad345c8b0b0693cc214b212ccbb402859d910134..bb28b011ba5adda1fa0de44e7e00dd2ad2baf904 100644 (file)
@@ -115,13 +115,12 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
                        continue;
 
                if (!strcmp(name, "cpu")) {
-                       if (dst->cpu_switch) {
+                       if (dst->cpu_dp) {
                                netdev_err(dst->master_netdev,
                                           "multiple cpu ports?!\n");
                                return -EINVAL;
                        }
-                       dst->cpu_switch = ds;
-                       dst->cpu_port = i;
+                       dst->cpu_dp = &ds->ports[i];
                        ds->cpu_port_mask |= 1 << i;
                } else if (!strcmp(name, "dsa")) {
                        ds->dsa_port_mask |= 1 << i;
@@ -144,7 +143,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
         * tagging protocol to the preferred tagging format of this
         * switch.
         */
-       if (dst->cpu_switch == ds) {
+       if (dst->cpu_dp->ds == ds) {
                enum dsa_tag_protocol tag_protocol;
 
                tag_protocol = ops->get_tag_protocol(ds);
@@ -624,7 +623,6 @@ static int dsa_setup_dst(struct dsa_switch_tree *dst, struct net_device *dev,
 
        dst->pd = pd;
        dst->master_netdev = dev;
-       dst->cpu_port = -1;
 
        for (i = 0; i < pd->nr_chips; i++) {
                struct dsa_switch *ds;
@@ -735,7 +733,7 @@ static void dsa_remove_dst(struct dsa_switch_tree *dst)
                        dsa_switch_destroy(ds);
        }
 
-       dsa_cpu_port_ethtool_restore(dst->cpu_switch);
+       dsa_cpu_port_ethtool_restore(dst->cpu_dp->ds);
 
        dev_put(dst->master_netdev);
 }
index 7693182df81e61d14540cd43be3ae7e134eef576..77324c483d14b5d88dec90e1a7d14740eee68c1e 100644 (file)
@@ -821,8 +821,8 @@ static void dsa_cpu_port_get_ethtool_stats(struct net_device *dev,
                                           uint64_t *data)
 {
        struct dsa_switch_tree *dst = dev->dsa_ptr;
-       struct dsa_switch *ds = dst->cpu_switch;
-       s8 cpu_port = dst->cpu_port;
+       struct dsa_switch *ds = dst->cpu_dp->ds;
+       s8 cpu_port = dst->cpu_dp->index;
        int count = 0;
 
        if (dst->master_ethtool_ops.get_sset_count) {
@@ -838,7 +838,7 @@ static void dsa_cpu_port_get_ethtool_stats(struct net_device *dev,
 static int dsa_cpu_port_get_sset_count(struct net_device *dev, int sset)
 {
        struct dsa_switch_tree *dst = dev->dsa_ptr;
-       struct dsa_switch *ds = dst->cpu_switch;
+       struct dsa_switch *ds = dst->cpu_dp->ds;
        int count = 0;
 
        if (dst->master_ethtool_ops.get_sset_count)
@@ -854,8 +854,8 @@ static void dsa_cpu_port_get_strings(struct net_device *dev,
                                     uint32_t stringset, uint8_t *data)
 {
        struct dsa_switch_tree *dst = dev->dsa_ptr;
-       struct dsa_switch *ds = dst->cpu_switch;
-       s8 cpu_port = dst->cpu_port;
+       struct dsa_switch *ds = dst->cpu_dp->ds;
+       s8 cpu_port = dst->cpu_dp->index;
        int len = ETH_GSTRING_LEN;
        int mcount = 0, count;
        unsigned int i;
index 2a9b52c5af86b5308d7d71a3340a0e48768bdb60..658ddee63dc99c43050cf1b71c26c9242d7f7712 100644 (file)
@@ -101,7 +101,7 @@ static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
        int source_port;
        u8 *brcm_tag;
 
-       ds = dst->cpu_switch;
+       ds = dst->cpu_dp->ds;
 
        if (unlikely(!pskb_may_pull(skb, BRCM_TAG_LEN)))
                goto out_drop;
index 3ba3f59f7a3433b3731a5b3dc501eb22660d7cce..be3b67750ac85f016e6f2edb07de4edff669f233 100644 (file)
@@ -99,7 +99,7 @@ static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev,
        /* This protocol doesn't support cascading multiple switches so it's
         * safe to assume the switch is first in the tree
         */
-       ds = dst->cpu_switch;
+       ds = dst->cpu_dp->ds;
        if (!ds)
                goto out_drop;
 
index aafc2fc74c3067dd05c67c409e40e8ceef33cf0c..aa05e276ea2250bbde177ab889d93b2ed6616277 100644 (file)
@@ -67,7 +67,7 @@ static struct sk_buff *trailer_rcv(struct sk_buff *skb, struct net_device *dev,
        u8 *trailer;
        int source_port;
 
-       ds = dst->cpu_switch;
+       ds = dst->cpu_dp->ds;
 
        if (skb_linearize(skb))
                goto out_drop;