Commit 8f6a19c0 authored by Vladimir Oltean's avatar Vladimir Oltean Committed by Paolo Abeni

net: dsa: introduce dsa_port_get_master()

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: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent db01868b
...@@ -983,7 +983,7 @@ static int bcm_sf2_sw_resume(struct dsa_switch *ds) ...@@ -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, static void bcm_sf2_sw_get_wol(struct dsa_switch *ds, int port,
struct ethtool_wolinfo *wol) 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 bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
struct ethtool_wolinfo pwol = { }; struct ethtool_wolinfo pwol = { };
...@@ -1007,7 +1007,7 @@ static void bcm_sf2_sw_get_wol(struct dsa_switch *ds, int port, ...@@ -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, static int bcm_sf2_sw_set_wol(struct dsa_switch *ds, int port,
struct ethtool_wolinfo *wol) 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 bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index; s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
struct ethtool_wolinfo pwol = { }; struct ethtool_wolinfo pwol = { };
......
...@@ -1102,7 +1102,7 @@ static int bcm_sf2_cfp_rule_get_all(struct bcm_sf2_priv *priv, ...@@ -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, int bcm_sf2_get_rxnfc(struct dsa_switch *ds, int port,
struct ethtool_rxnfc *nfc, u32 *rule_locs) 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); struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
int ret = 0; int ret = 0;
...@@ -1145,7 +1145,7 @@ int bcm_sf2_get_rxnfc(struct dsa_switch *ds, int port, ...@@ -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, int bcm_sf2_set_rxnfc(struct dsa_switch *ds, int port,
struct ethtool_rxnfc *nfc) 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); struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
int ret = 0; int ret = 0;
......
...@@ -1092,7 +1092,7 @@ static int lan9303_port_enable(struct dsa_switch *ds, int port, ...@@ -1092,7 +1092,7 @@ static int lan9303_port_enable(struct dsa_switch *ds, int port,
if (!dsa_port_is_user(dp)) if (!dsa_port_is_user(dp))
return 0; 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); return lan9303_enable_processing_port(chip, port);
} }
...@@ -1105,7 +1105,7 @@ static void lan9303_port_disable(struct dsa_switch *ds, int port) ...@@ -1105,7 +1105,7 @@ static void lan9303_port_disable(struct dsa_switch *ds, int port)
if (!dsa_port_is_user(dp)) if (!dsa_port_is_user(dp))
return; 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_disable_processing_port(chip, port);
lan9303_phy_write(ds, chip->phy_addr_base + port, MII_BMCR, BMCR_PDOWN); lan9303_phy_write(ds, chip->phy_addr_base + port, MII_BMCR, BMCR_PDOWN);
......
...@@ -173,7 +173,7 @@ mtk_flow_get_dsa_port(struct net_device **dev) ...@@ -173,7 +173,7 @@ mtk_flow_get_dsa_port(struct net_device **dev)
if (dp->cpu_dp->tag_ops->proto != DSA_TAG_PROTO_MTK) if (dp->cpu_dp->tag_ops->proto != DSA_TAG_PROTO_MTK)
return -ENODEV; return -ENODEV;
*dev = dp->cpu_dp->master; *dev = dsa_port_to_master(dp);
return dp->index; return dp->index;
#else #else
......
...@@ -718,6 +718,11 @@ static inline bool dsa_port_offloads_lag(struct dsa_port *dp, ...@@ -718,6 +718,11 @@ static inline bool dsa_port_offloads_lag(struct dsa_port *dp,
return dsa_port_lag_dev_get(dp) == lag->dev; 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 static inline
struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp) struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp)
{ {
......
...@@ -1263,11 +1263,11 @@ int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst, ...@@ -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 * attempts to change the tagging protocol. If we ever lift the IFF_UP
* restriction, there needs to be another mutex which serializes this. * restriction, there needs to be another mutex which serializes this.
*/ */
list_for_each_entry(dp, &dst->ports, list) { dsa_tree_for_each_user_port(dp, dst) {
if (dsa_port_is_cpu(dp) && (dp->master->flags & IFF_UP)) if (dsa_port_to_master(dp)->flags & IFF_UP)
goto out_unlock; goto out_unlock;
if (dsa_port_is_user(dp) && (dp->slave->flags & IFF_UP)) if (dp->slave->flags & IFF_UP)
goto out_unlock; goto out_unlock;
} }
...@@ -1797,7 +1797,7 @@ void dsa_switch_shutdown(struct dsa_switch *ds) ...@@ -1797,7 +1797,7 @@ void dsa_switch_shutdown(struct dsa_switch *ds)
rtnl_lock(); rtnl_lock();
dsa_switch_for_each_user_port(dp, ds) { dsa_switch_for_each_user_port(dp, ds) {
master = dp->cpu_dp->master; master = dsa_port_to_master(dp);
slave_dev = dp->slave; slave_dev = dp->slave;
netdev_upper_dev_unlink(master, slave_dev); netdev_upper_dev_unlink(master, slave_dev);
......
...@@ -322,7 +322,7 @@ dsa_slave_to_master(const struct net_device *dev) ...@@ -322,7 +322,7 @@ dsa_slave_to_master(const struct net_device *dev)
{ {
struct dsa_port *dp = dsa_slave_to_port(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 /* If under a bridge with vlan_filtering=0, make sure to send pvid-tagged
......
...@@ -1026,7 +1026,7 @@ int dsa_port_standalone_host_fdb_add(struct dsa_port *dp, ...@@ -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, int dsa_port_bridge_host_fdb_add(struct dsa_port *dp,
const unsigned char *addr, u16 vid) 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 = { struct dsa_db db = {
.type = DSA_DB_BRIDGE, .type = DSA_DB_BRIDGE,
.bridge = *dp->bridge, .bridge = *dp->bridge,
...@@ -1037,8 +1037,8 @@ int dsa_port_bridge_host_fdb_add(struct dsa_port *dp, ...@@ -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, * requires rtnl_lock(), since we can't guarantee that is held here,
* and we can't take it either. * and we can't take it either.
*/ */
if (cpu_dp->master->priv_flags & IFF_UNICAST_FLT) { if (master->priv_flags & IFF_UNICAST_FLT) {
err = dev_uc_add(cpu_dp->master, addr); err = dev_uc_add(master, addr);
if (err) if (err)
return err; return err;
} }
...@@ -1077,15 +1077,15 @@ int dsa_port_standalone_host_fdb_del(struct dsa_port *dp, ...@@ -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, int dsa_port_bridge_host_fdb_del(struct dsa_port *dp,
const unsigned char *addr, u16 vid) 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 = { struct dsa_db db = {
.type = DSA_DB_BRIDGE, .type = DSA_DB_BRIDGE,
.bridge = *dp->bridge, .bridge = *dp->bridge,
}; };
int err; int err;
if (cpu_dp->master->priv_flags & IFF_UNICAST_FLT) { if (master->priv_flags & IFF_UNICAST_FLT) {
err = dev_uc_del(cpu_dp->master, addr); err = dev_uc_del(master, addr);
if (err) if (err)
return err; return err;
} }
...@@ -1208,14 +1208,14 @@ int dsa_port_standalone_host_mdb_add(const struct dsa_port *dp, ...@@ -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, int dsa_port_bridge_host_mdb_add(const struct dsa_port *dp,
const struct switchdev_obj_port_mdb *mdb) 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 = { struct dsa_db db = {
.type = DSA_DB_BRIDGE, .type = DSA_DB_BRIDGE,
.bridge = *dp->bridge, .bridge = *dp->bridge,
}; };
int err; int err;
err = dev_mc_add(cpu_dp->master, mdb->addr); err = dev_mc_add(master, mdb->addr);
if (err) if (err)
return err; return err;
...@@ -1252,14 +1252,14 @@ int dsa_port_standalone_host_mdb_del(const struct dsa_port *dp, ...@@ -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, int dsa_port_bridge_host_mdb_del(const struct dsa_port *dp,
const struct switchdev_obj_port_mdb *mdb) 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 = { struct dsa_db db = {
.type = DSA_DB_BRIDGE, .type = DSA_DB_BRIDGE,
.bridge = *dp->bridge, .bridge = *dp->bridge,
}; };
int err; int err;
err = dev_mc_del(cpu_dp->master, mdb->addr); err = dev_mc_del(master, mdb->addr);
if (err) if (err)
return err; return err;
...@@ -1294,19 +1294,19 @@ int dsa_port_host_vlan_add(struct dsa_port *dp, ...@@ -1294,19 +1294,19 @@ int dsa_port_host_vlan_add(struct dsa_port *dp,
const struct switchdev_obj_port_vlan *vlan, const struct switchdev_obj_port_vlan *vlan,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct net_device *master = dsa_port_to_master(dp);
struct dsa_notifier_vlan_info info = { struct dsa_notifier_vlan_info info = {
.dp = dp, .dp = dp,
.vlan = vlan, .vlan = vlan,
.extack = extack, .extack = extack,
}; };
struct dsa_port *cpu_dp = dp->cpu_dp;
int err; int err;
err = dsa_port_notify(dp, DSA_NOTIFIER_HOST_VLAN_ADD, &info); err = dsa_port_notify(dp, DSA_NOTIFIER_HOST_VLAN_ADD, &info);
if (err && err != -EOPNOTSUPP) if (err && err != -EOPNOTSUPP)
return err; 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; return err;
} }
...@@ -1314,18 +1314,18 @@ int dsa_port_host_vlan_add(struct dsa_port *dp, ...@@ -1314,18 +1314,18 @@ int dsa_port_host_vlan_add(struct dsa_port *dp,
int dsa_port_host_vlan_del(struct dsa_port *dp, int dsa_port_host_vlan_del(struct dsa_port *dp,
const struct switchdev_obj_port_vlan *vlan) const struct switchdev_obj_port_vlan *vlan)
{ {
struct net_device *master = dsa_port_to_master(dp);
struct dsa_notifier_vlan_info info = { struct dsa_notifier_vlan_info info = {
.dp = dp, .dp = dp,
.vlan = vlan, .vlan = vlan,
}; };
struct dsa_port *cpu_dp = dp->cpu_dp;
int err; int err;
err = dsa_port_notify(dp, DSA_NOTIFIER_HOST_VLAN_DEL, &info); err = dsa_port_notify(dp, DSA_NOTIFIER_HOST_VLAN_DEL, &info);
if (err && err != -EOPNOTSUPP) if (err && err != -EOPNOTSUPP)
return err; 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; return err;
} }
......
...@@ -1503,8 +1503,7 @@ static int dsa_slave_setup_tc_block(struct net_device *dev, ...@@ -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, static int dsa_slave_setup_ft_block(struct dsa_switch *ds, int port,
void *type_data) void *type_data)
{ {
struct dsa_port *cpu_dp = dsa_to_port(ds, port)->cpu_dp; struct net_device *master = dsa_port_to_master(dsa_to_port(ds, port));
struct net_device *master = cpu_dp->master;
if (!master->netdev_ops->ndo_setup_tc) if (!master->netdev_ops->ndo_setup_tc)
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -2147,13 +2146,14 @@ static int dsa_slave_fill_forward_path(struct net_device_path_ctx *ctx, ...@@ -2147,13 +2146,14 @@ static int dsa_slave_fill_forward_path(struct net_device_path_ctx *ctx,
struct net_device_path *path) struct net_device_path *path)
{ {
struct dsa_port *dp = dsa_slave_to_port(ctx->dev); 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; struct dsa_port *cpu_dp = dp->cpu_dp;
path->dev = ctx->dev; path->dev = ctx->dev;
path->type = DEV_PATH_DSA; path->type = DEV_PATH_DSA;
path->dsa.proto = cpu_dp->tag_ops->proto; path->dsa.proto = cpu_dp->tag_ops->proto;
path->dsa.port = dp->index; path->dsa.port = dp->index;
ctx->dev = cpu_dp->master; ctx->dev = master;
return 0; return 0;
} }
...@@ -2271,9 +2271,9 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev) ...@@ -2271,9 +2271,9 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev)
void dsa_slave_setup_tagger(struct net_device *slave) void dsa_slave_setup_tagger(struct net_device *slave)
{ {
struct dsa_port *dp = dsa_slave_to_port(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); struct dsa_slave_priv *p = netdev_priv(slave);
const struct dsa_port *cpu_dp = dp->cpu_dp; const struct dsa_port *cpu_dp = dp->cpu_dp;
struct net_device *master = cpu_dp->master;
const struct dsa_switch *ds = dp->ds; const struct dsa_switch *ds = dp->ds;
slave->needed_headroom = cpu_dp->tag_ops->needed_headroom; slave->needed_headroom = cpu_dp->tag_ops->needed_headroom;
...@@ -2330,8 +2330,7 @@ int dsa_slave_resume(struct net_device *slave_dev) ...@@ -2330,8 +2330,7 @@ int dsa_slave_resume(struct net_device *slave_dev)
int dsa_slave_create(struct dsa_port *port) int dsa_slave_create(struct dsa_port *port)
{ {
const struct dsa_port *cpu_dp = port->cpu_dp; struct net_device *master = dsa_port_to_master(port);
struct net_device *master = cpu_dp->master;
struct dsa_switch *ds = port->ds; struct dsa_switch *ds = port->ds;
const char *name = port->name; const char *name = port->name;
struct net_device *slave_dev; struct net_device *slave_dev;
......
...@@ -330,7 +330,7 @@ static int dsa_tag_8021q_port_setup(struct dsa_switch *ds, int port) ...@@ -330,7 +330,7 @@ static int dsa_tag_8021q_port_setup(struct dsa_switch *ds, int port)
if (!dsa_port_is_user(dp)) if (!dsa_port_is_user(dp))
return 0; return 0;
master = dp->cpu_dp->master; master = dsa_port_to_master(dp);
err = dsa_port_tag_8021q_vlan_add(dp, vid, false); err = dsa_port_tag_8021q_vlan_add(dp, vid, false);
if (err) { if (err) {
...@@ -359,7 +359,7 @@ static void dsa_tag_8021q_port_teardown(struct dsa_switch *ds, int port) ...@@ -359,7 +359,7 @@ static void dsa_tag_8021q_port_teardown(struct dsa_switch *ds, int port)
if (!dsa_port_is_user(dp)) if (!dsa_port_is_user(dp))
return; return;
master = dp->cpu_dp->master; master = dsa_port_to_master(dp);
dsa_port_tag_8021q_vlan_del(dp, vid, false); dsa_port_tag_8021q_vlan_del(dp, vid, false);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment