net: dsa: Introduce dsa_get_cpu_port()
authorFlorian Fainelli <f.fainelli@gmail.com>
Tue, 13 Jun 2017 20:27:22 +0000 (13:27 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 13 Jun 2017 20:35:03 +0000 (16:35 -0400)
Introduce a helper function which will return a reference to the CPU
port used in a dsa_switch_tree. Right now this is a singleton, but this
will change once we introduce multi-CPU port support, so ease the
transition by converting the affected code paths.

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>
net/dsa/dsa_priv.h
net/dsa/slave.c
net/dsa/tag_brcm.c
net/dsa/tag_ksz.c
net/dsa/tag_qca.c
net/dsa/tag_trailer.c

index 7c2326f3b538f29fbc339b45fde22a1c01112099..55982cc39b24d79077f3120f47f54d4e621286c6 100644 (file)
@@ -188,4 +188,9 @@ static inline struct net_device *dsa_master_netdev(struct dsa_slave_priv *p)
        return p->dp->cpu_dp->netdev;
 }
 
+static inline struct dsa_port *dsa_get_cpu_port(struct dsa_switch_tree *dst)
+{
+       return dst->cpu_dp;
+}
+
 #endif
index a80b46777a048373c166d03374cd4f1dc436cb3b..9507bd38cf0441578de213178e23a692d8aed072 100644 (file)
@@ -520,14 +520,14 @@ 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_dp->ds;
-       s8 cpu_port = dst->cpu_dp->index;
+       struct dsa_port *cpu_dp = dsa_get_cpu_port(dst);
+       struct dsa_switch *ds = cpu_dp->ds;
+       s8 cpu_port = cpu_dp->index;
        int count = 0;
 
-       if (dst->cpu_dp->ethtool_ops.get_sset_count) {
-               count = dst->cpu_dp->ethtool_ops.get_sset_count(dev,
-                                                              ETH_SS_STATS);
-               dst->cpu_dp->ethtool_ops.get_ethtool_stats(dev, stats, data);
+       if (cpu_dp->ethtool_ops.get_sset_count) {
+               count = cpu_dp->ethtool_ops.get_sset_count(dev, ETH_SS_STATS);
+               cpu_dp->ethtool_ops.get_ethtool_stats(dev, stats, data);
        }
 
        if (ds->ops->get_ethtool_stats)
@@ -537,11 +537,12 @@ 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_dp->ds;
+       struct dsa_port *cpu_dp = dsa_get_cpu_port(dst);
+       struct dsa_switch *ds = cpu_dp->ds;
        int count = 0;
 
-       if (dst->cpu_dp->ethtool_ops.get_sset_count)
-               count += dst->cpu_dp->ethtool_ops.get_sset_count(dev, sset);
+       if (cpu_dp->ethtool_ops.get_sset_count)
+               count += cpu_dp->ethtool_ops.get_sset_count(dev, sset);
 
        if (sset == ETH_SS_STATS && ds->ops->get_sset_count)
                count += ds->ops->get_sset_count(ds);
@@ -553,8 +554,9 @@ 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_dp->ds;
-       s8 cpu_port = dst->cpu_dp->index;
+       struct dsa_port *cpu_dp = dsa_get_cpu_port(dst);
+       struct dsa_switch *ds = cpu_dp->ds;
+       s8 cpu_port = cpu_dp->index;
        int len = ETH_GSTRING_LEN;
        int mcount = 0, count;
        unsigned int i;
@@ -565,10 +567,9 @@ static void dsa_cpu_port_get_strings(struct net_device *dev,
        /* We do not want to be NULL-terminated, since this is a prefix */
        pfx[sizeof(pfx) - 1] = '_';
 
-       if (dst->cpu_dp->ethtool_ops.get_sset_count) {
-               mcount = dst->cpu_dp->ethtool_ops.get_sset_count(dev,
-                                                               ETH_SS_STATS);
-               dst->cpu_dp->ethtool_ops.get_strings(dev, stringset, data);
+       if (cpu_dp->ethtool_ops.get_sset_count) {
+               mcount = cpu_dp->ethtool_ops.get_sset_count(dev, ETH_SS_STATS);
+               cpu_dp->ethtool_ops.get_strings(dev, stringset, data);
        }
 
        if (stringset == ETH_SS_STATS && ds->ops->get_strings) {
index c03860907f281dfc3e543fcca82a14dff15d455b..c697d981517744fbc523d3bd0e3b8204a3a427f8 100644 (file)
@@ -93,12 +93,11 @@ static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
                                    struct net_device *orig_dev)
 {
        struct dsa_switch_tree *dst = dev->dsa_ptr;
-       struct dsa_switch *ds;
+       struct dsa_port *cpu_dp = dsa_get_cpu_port(dst);
+       struct dsa_switch *ds = cpu_dp->ds;
        int source_port;
        u8 *brcm_tag;
 
-       ds = dst->cpu_dp->ds;
-
        if (unlikely(!pskb_may_pull(skb, BRCM_TAG_LEN)))
                return NULL;
 
index b94a334a1d02080a6f92fb2434e3813cc1443d9b..fab41de8e9837b512709b3c853ffb4831fe08317 100644 (file)
@@ -75,12 +75,11 @@ static struct sk_buff *ksz_rcv(struct sk_buff *skb, struct net_device *dev,
                               struct net_device *orig_dev)
 {
        struct dsa_switch_tree *dst = dev->dsa_ptr;
-       struct dsa_switch *ds;
+       struct dsa_port *cpu_dp = dsa_get_cpu_port(dst);
+       struct dsa_switch *ds = cpu_dp->ds;
        u8 *tag;
        int source_port;
 
-       ds = dst->cpu_dp->ds;
-
        tag = skb_tail_pointer(skb) - KSZ_EGRESS_TAG_LEN;
 
        source_port = tag[0] & 7;
index 4f43cf0b4eff13d4a2dd76980d447572a6459778..1867a3d11f280d8c345d57386acd3ef357833b19 100644 (file)
@@ -67,6 +67,7 @@ static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev,
                                   struct net_device *orig_dev)
 {
        struct dsa_switch_tree *dst = dev->dsa_ptr;
+       struct dsa_port *cpu_dp = dsa_get_cpu_port(dst);
        struct dsa_switch *ds;
        u8 ver;
        int port;
@@ -95,7 +96,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_dp->ds;
+       ds = cpu_dp->ds;
        if (!ds)
                return NULL;
 
index b4f6db0944093ce15640d09e2f6b8508dbecebbc..172f1316789622487214678cde9b628a9c85f550 100644 (file)
@@ -61,12 +61,11 @@ static struct sk_buff *trailer_rcv(struct sk_buff *skb, struct net_device *dev,
                                   struct net_device *orig_dev)
 {
        struct dsa_switch_tree *dst = dev->dsa_ptr;
-       struct dsa_switch *ds;
+       struct dsa_port *cpu_dp = dsa_get_cpu_port(dst);
+       struct dsa_switch *ds = cpu_dp->ds;
        u8 *trailer;
        int source_port;
 
-       ds = dst->cpu_dp->ds;
-
        if (skb_linearize(skb))
                return NULL;