net: dsa: introduce dsa_port_get_master()
authorVladimir Oltean <vladimir.oltean@nxp.com>
Sun, 11 Sep 2022 01:06:58 +0000 (04:06 +0300)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 20 Sep 2022 08:32:35 +0000 (10:32 +0200)
There is a desire to support for DSA masters in a LAG.

That configuration is intended to work by simply enslaving the master to
a bonding/team device. But the physical DSA master (the LAG slave) still
has a dev->dsa_ptr, and that cpu_dp still corresponds to the physical
CPU port.

However, we would like to be able to retrieve the LAG that's the upper
of the physical DSA master. In preparation for that, introduce a helper
called dsa_port_get_master() that replaces all occurrences of the
dp->cpu_dp->master pattern. The distinction between LAG and non-LAG will
be made later within the helper itself.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/dsa/bcm_sf2.c
drivers/net/dsa/bcm_sf2_cfp.c
drivers/net/dsa/lan9303-core.c
drivers/net/ethernet/mediatek/mtk_ppe_offload.c
include/net/dsa.h
net/dsa/dsa2.c
net/dsa/dsa_priv.h
net/dsa/port.c
net/dsa/slave.c
net/dsa/tag_8021q.c

index 572f7450b527abfc3276d1d890740d3f301240ca..6507663f35e5415f5cc501d66124b649b8e6f0c9 100644 (file)
@@ -983,7 +983,7 @@ static int bcm_sf2_sw_resume(struct dsa_switch *ds)
 static void bcm_sf2_sw_get_wol(struct dsa_switch *ds, int port,
                               struct ethtool_wolinfo *wol)
 {
-       struct net_device *p = dsa_to_port(ds, port)->cpu_dp->master;
+       struct net_device *p = dsa_port_to_master(dsa_to_port(ds, port));
        struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
        struct ethtool_wolinfo pwol = { };
 
@@ -1007,7 +1007,7 @@ static void bcm_sf2_sw_get_wol(struct dsa_switch *ds, int port,
 static int bcm_sf2_sw_set_wol(struct dsa_switch *ds, int port,
                              struct ethtool_wolinfo *wol)
 {
-       struct net_device *p = dsa_to_port(ds, port)->cpu_dp->master;
+       struct net_device *p = dsa_port_to_master(dsa_to_port(ds, port));
        struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
        s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
        struct ethtool_wolinfo pwol =  { };
index 22bc295bebdbeb125d7f4cb66ec0851b17d5b420..c4010b7bf08997d99b374813f7585520e034ee40 100644 (file)
@@ -1102,7 +1102,7 @@ static int bcm_sf2_cfp_rule_get_all(struct bcm_sf2_priv *priv,
 int bcm_sf2_get_rxnfc(struct dsa_switch *ds, int port,
                      struct ethtool_rxnfc *nfc, u32 *rule_locs)
 {
-       struct net_device *p = dsa_to_port(ds, port)->cpu_dp->master;
+       struct net_device *p = dsa_port_to_master(dsa_to_port(ds, port));
        struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
        int ret = 0;
 
@@ -1145,7 +1145,7 @@ int bcm_sf2_get_rxnfc(struct dsa_switch *ds, int port,
 int bcm_sf2_set_rxnfc(struct dsa_switch *ds, int port,
                      struct ethtool_rxnfc *nfc)
 {
-       struct net_device *p = dsa_to_port(ds, port)->cpu_dp->master;
+       struct net_device *p = dsa_port_to_master(dsa_to_port(ds, port));
        struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
        int ret = 0;
 
index 9e04541c314462bd6e56541bda554232550e62aa..438e46af03e9b5a8ae5404f64ccadee305cee45a 100644 (file)
@@ -1092,7 +1092,7 @@ static int lan9303_port_enable(struct dsa_switch *ds, int port,
        if (!dsa_port_is_user(dp))
                return 0;
 
-       vlan_vid_add(dp->cpu_dp->master, htons(ETH_P_8021Q), port);
+       vlan_vid_add(dsa_port_to_master(dp), htons(ETH_P_8021Q), port);
 
        return lan9303_enable_processing_port(chip, port);
 }
@@ -1105,7 +1105,7 @@ static void lan9303_port_disable(struct dsa_switch *ds, int port)
        if (!dsa_port_is_user(dp))
                return;
 
-       vlan_vid_del(dp->cpu_dp->master, htons(ETH_P_8021Q), port);
+       vlan_vid_del(dsa_port_to_master(dp), htons(ETH_P_8021Q), port);
 
        lan9303_disable_processing_port(chip, port);
        lan9303_phy_write(ds, chip->phy_addr_base + port, MII_BMCR, BMCR_PDOWN);
index 25dc3c3aa31d943b5a6c4ad5cb244e1656e9c1c0..5a1fc4bcd7a57ad4cecf5675beb0e6ee1bf1cffb 100644 (file)
@@ -173,7 +173,7 @@ mtk_flow_get_dsa_port(struct net_device **dev)
        if (dp->cpu_dp->tag_ops->proto != DSA_TAG_PROTO_MTK)
                return -ENODEV;
 
-       *dev = dp->cpu_dp->master;
+       *dev = dsa_port_to_master(dp);
 
        return dp->index;
 #else
index f2ce12860546ee462c9fa55ce481494aced2f1c8..23eac1bda843a3f74b8fdd3e124a2e928900f200 100644 (file)
@@ -718,6 +718,11 @@ static inline bool dsa_port_offloads_lag(struct dsa_port *dp,
        return dsa_port_lag_dev_get(dp) == lag->dev;
 }
 
+static inline struct net_device *dsa_port_to_master(const struct dsa_port *dp)
+{
+       return dp->cpu_dp->master;
+}
+
 static inline
 struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp)
 {
index ed56c7a554b8bd8c95910e4315a3e1b4b6d95b32..f1f96e2e56aa22404e5ffa71822e7e884733219d 100644 (file)
@@ -1263,11 +1263,11 @@ int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst,
         * attempts to change the tagging protocol. If we ever lift the IFF_UP
         * restriction, there needs to be another mutex which serializes this.
         */
-       list_for_each_entry(dp, &dst->ports, list) {
-               if (dsa_port_is_cpu(dp) && (dp->master->flags & IFF_UP))
+       dsa_tree_for_each_user_port(dp, dst) {
+               if (dsa_port_to_master(dp)->flags & IFF_UP)
                        goto out_unlock;
 
-               if (dsa_port_is_user(dp) && (dp->slave->flags & IFF_UP))
+               if (dp->slave->flags & IFF_UP)
                        goto out_unlock;
        }
 
@@ -1797,7 +1797,7 @@ void dsa_switch_shutdown(struct dsa_switch *ds)
        rtnl_lock();
 
        dsa_switch_for_each_user_port(dp, ds) {
-               master = dp->cpu_dp->master;
+               master = dsa_port_to_master(dp);
                slave_dev = dp->slave;
 
                netdev_upper_dev_unlink(master, slave_dev);
index 614fbba8fe396e2f799b00f4ee1d50336982c506..c48c5c8ba790093a44dbac916f213e98b836c0ba 100644 (file)
@@ -322,7 +322,7 @@ dsa_slave_to_master(const struct net_device *dev)
 {
        struct dsa_port *dp = dsa_slave_to_port(dev);
 
-       return dp->cpu_dp->master;
+       return dsa_port_to_master(dp);
 }
 
 /* If under a bridge with vlan_filtering=0, make sure to send pvid-tagged
index 7afc35db0c29c0cb4c70294e2ea1963f4e2ab9cb..4183e60db4f96820a4fb721e77509dd72f592ed8 100644 (file)
@@ -1026,7 +1026,7 @@ int dsa_port_standalone_host_fdb_add(struct dsa_port *dp,
 int dsa_port_bridge_host_fdb_add(struct dsa_port *dp,
                                 const unsigned char *addr, u16 vid)
 {
-       struct dsa_port *cpu_dp = dp->cpu_dp;
+       struct net_device *master = dsa_port_to_master(dp);
        struct dsa_db db = {
                .type = DSA_DB_BRIDGE,
                .bridge = *dp->bridge,
@@ -1037,8 +1037,8 @@ int dsa_port_bridge_host_fdb_add(struct dsa_port *dp,
         * requires rtnl_lock(), since we can't guarantee that is held here,
         * and we can't take it either.
         */
-       if (cpu_dp->master->priv_flags & IFF_UNICAST_FLT) {
-               err = dev_uc_add(cpu_dp->master, addr);
+       if (master->priv_flags & IFF_UNICAST_FLT) {
+               err = dev_uc_add(master, addr);
                if (err)
                        return err;
        }
@@ -1077,15 +1077,15 @@ int dsa_port_standalone_host_fdb_del(struct dsa_port *dp,
 int dsa_port_bridge_host_fdb_del(struct dsa_port *dp,
                                 const unsigned char *addr, u16 vid)
 {
-       struct dsa_port *cpu_dp = dp->cpu_dp;
+       struct net_device *master = dsa_port_to_master(dp);
        struct dsa_db db = {
                .type = DSA_DB_BRIDGE,
                .bridge = *dp->bridge,
        };
        int err;
 
-       if (cpu_dp->master->priv_flags & IFF_UNICAST_FLT) {
-               err = dev_uc_del(cpu_dp->master, addr);
+       if (master->priv_flags & IFF_UNICAST_FLT) {
+               err = dev_uc_del(master, addr);
                if (err)
                        return err;
        }
@@ -1208,14 +1208,14 @@ int dsa_port_standalone_host_mdb_add(const struct dsa_port *dp,
 int dsa_port_bridge_host_mdb_add(const struct dsa_port *dp,
                                 const struct switchdev_obj_port_mdb *mdb)
 {
-       struct dsa_port *cpu_dp = dp->cpu_dp;
+       struct net_device *master = dsa_port_to_master(dp);
        struct dsa_db db = {
                .type = DSA_DB_BRIDGE,
                .bridge = *dp->bridge,
        };
        int err;
 
-       err = dev_mc_add(cpu_dp->master, mdb->addr);
+       err = dev_mc_add(master, mdb->addr);
        if (err)
                return err;
 
@@ -1252,14 +1252,14 @@ int dsa_port_standalone_host_mdb_del(const struct dsa_port *dp,
 int dsa_port_bridge_host_mdb_del(const struct dsa_port *dp,
                                 const struct switchdev_obj_port_mdb *mdb)
 {
-       struct dsa_port *cpu_dp = dp->cpu_dp;
+       struct net_device *master = dsa_port_to_master(dp);
        struct dsa_db db = {
                .type = DSA_DB_BRIDGE,
                .bridge = *dp->bridge,
        };
        int err;
 
-       err = dev_mc_del(cpu_dp->master, mdb->addr);
+       err = dev_mc_del(master, mdb->addr);
        if (err)
                return err;
 
@@ -1294,19 +1294,19 @@ int dsa_port_host_vlan_add(struct dsa_port *dp,
                           const struct switchdev_obj_port_vlan *vlan,
                           struct netlink_ext_ack *extack)
 {
+       struct net_device *master = dsa_port_to_master(dp);
        struct dsa_notifier_vlan_info info = {
                .dp = dp,
                .vlan = vlan,
                .extack = extack,
        };
-       struct dsa_port *cpu_dp = dp->cpu_dp;
        int err;
 
        err = dsa_port_notify(dp, DSA_NOTIFIER_HOST_VLAN_ADD, &info);
        if (err && err != -EOPNOTSUPP)
                return err;
 
-       vlan_vid_add(cpu_dp->master, htons(ETH_P_8021Q), vlan->vid);
+       vlan_vid_add(master, htons(ETH_P_8021Q), vlan->vid);
 
        return err;
 }
@@ -1314,18 +1314,18 @@ int dsa_port_host_vlan_add(struct dsa_port *dp,
 int dsa_port_host_vlan_del(struct dsa_port *dp,
                           const struct switchdev_obj_port_vlan *vlan)
 {
+       struct net_device *master = dsa_port_to_master(dp);
        struct dsa_notifier_vlan_info info = {
                .dp = dp,
                .vlan = vlan,
        };
-       struct dsa_port *cpu_dp = dp->cpu_dp;
        int err;
 
        err = dsa_port_notify(dp, DSA_NOTIFIER_HOST_VLAN_DEL, &info);
        if (err && err != -EOPNOTSUPP)
                return err;
 
-       vlan_vid_del(cpu_dp->master, htons(ETH_P_8021Q), vlan->vid);
+       vlan_vid_del(master, htons(ETH_P_8021Q), vlan->vid);
 
        return err;
 }
index 345106b1ed78b4e14fb12e1663d97e4112613e27..55094b94a5ae947034502c6e25ebe0d8a48e7b5c 100644 (file)
@@ -1503,8 +1503,7 @@ static int dsa_slave_setup_tc_block(struct net_device *dev,
 static int dsa_slave_setup_ft_block(struct dsa_switch *ds, int port,
                                    void *type_data)
 {
-       struct dsa_port *cpu_dp = dsa_to_port(ds, port)->cpu_dp;
-       struct net_device *master = cpu_dp->master;
+       struct net_device *master = dsa_port_to_master(dsa_to_port(ds, port));
 
        if (!master->netdev_ops->ndo_setup_tc)
                return -EOPNOTSUPP;
@@ -2147,13 +2146,14 @@ static int dsa_slave_fill_forward_path(struct net_device_path_ctx *ctx,
                                       struct net_device_path *path)
 {
        struct dsa_port *dp = dsa_slave_to_port(ctx->dev);
+       struct net_device *master = dsa_port_to_master(dp);
        struct dsa_port *cpu_dp = dp->cpu_dp;
 
        path->dev = ctx->dev;
        path->type = DEV_PATH_DSA;
        path->dsa.proto = cpu_dp->tag_ops->proto;
        path->dsa.port = dp->index;
-       ctx->dev = cpu_dp->master;
+       ctx->dev = master;
 
        return 0;
 }
@@ -2271,9 +2271,9 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev)
 void dsa_slave_setup_tagger(struct net_device *slave)
 {
        struct dsa_port *dp = dsa_slave_to_port(slave);
+       struct net_device *master = dsa_port_to_master(dp);
        struct dsa_slave_priv *p = netdev_priv(slave);
        const struct dsa_port *cpu_dp = dp->cpu_dp;
-       struct net_device *master = cpu_dp->master;
        const struct dsa_switch *ds = dp->ds;
 
        slave->needed_headroom = cpu_dp->tag_ops->needed_headroom;
@@ -2330,8 +2330,7 @@ int dsa_slave_resume(struct net_device *slave_dev)
 
 int dsa_slave_create(struct dsa_port *port)
 {
-       const struct dsa_port *cpu_dp = port->cpu_dp;
-       struct net_device *master = cpu_dp->master;
+       struct net_device *master = dsa_port_to_master(port);
        struct dsa_switch *ds = port->ds;
        const char *name = port->name;
        struct net_device *slave_dev;
index b5f80bc45cebd70cb2f3dc8ae2e8cfb3fa1bb63a..34e5ec5d3e236ecb8478950019e6f16b48877583 100644 (file)
@@ -330,7 +330,7 @@ static int dsa_tag_8021q_port_setup(struct dsa_switch *ds, int port)
        if (!dsa_port_is_user(dp))
                return 0;
 
-       master = dp->cpu_dp->master;
+       master = dsa_port_to_master(dp);
 
        err = dsa_port_tag_8021q_vlan_add(dp, vid, false);
        if (err) {
@@ -359,7 +359,7 @@ static void dsa_tag_8021q_port_teardown(struct dsa_switch *ds, int port)
        if (!dsa_port_is_user(dp))
                return;
 
-       master = dp->cpu_dp->master;
+       master = dsa_port_to_master(dp);
 
        dsa_port_tag_8021q_vlan_del(dp, vid, false);