Commit f8b8b1cd authored by Vivien Didelot's avatar Vivien Didelot Committed by David S. Miller

net: dsa: split dsa_port's netdev member

The dsa_port structure has a "netdev" member, which can be used for
either the master device, or the slave device, depending on its type.

It is true that today, CPU port are not exposed to userspace, thus the
port's netdev member can be used to point to its master interface.

But it is still slightly confusing, so split it into more explicit
"master" and "slave" members inside an anonymous union.
Signed-off-by: default avatarVivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2231c43b
......@@ -601,7 +601,7 @@ static void bcm_sf2_sw_fixed_link_update(struct dsa_switch *ds, int port,
* state machine and make it go in PHY_FORCING state instead.
*/
if (!status->link)
netif_carrier_off(ds->ports[port].netdev);
netif_carrier_off(ds->ports[port].slave);
status->duplex = 1;
} else {
status->link = 1;
......@@ -690,7 +690,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 = ds->ports[port].cpu_dp->netdev;
struct net_device *p = ds->ports[port].cpu_dp->master;
struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
struct ethtool_wolinfo pwol;
......@@ -713,7 +713,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 = ds->ports[port].cpu_dp->netdev;
struct net_device *p = ds->ports[port].cpu_dp->master;
struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
s8 cpu_port = ds->ports[port].cpu_dp->index;
struct ethtool_wolinfo pwol;
......
......@@ -933,7 +933,7 @@ mt7530_setup(struct dsa_switch *ds)
* controller also is the container for two GMACs nodes representing
* as two netdev instances.
*/
dn = ds->ports[MT7530_CPU_PORT].netdev->dev.of_node->parent;
dn = ds->ports[MT7530_CPU_PORT].master->dev.of_node->parent;
priv->ethernet = syscon_node_to_regmap(dn);
if (IS_ERR(priv->ethernet))
return PTR_ERR(priv->ethernet);
......
......@@ -1137,7 +1137,7 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
continue;
if (!ds->ports[port].netdev)
if (!ds->ports[port].slave)
continue;
if (vlan.member[i] ==
......
......@@ -164,6 +164,14 @@ struct dsa_mall_tc_entry {
struct dsa_port {
/* A CPU port is physically connected to a master device.
* A user port exposed to userspace has a slave device.
*/
union {
struct net_device *master;
struct net_device *slave;
};
/* CPU port tagging operations used by master or slave devices */
const struct dsa_device_ops *tag_ops;
......@@ -176,7 +184,6 @@ struct dsa_port {
unsigned int index;
const char *name;
struct dsa_port *cpu_dp;
struct net_device *netdev;
struct device_node *dn;
unsigned int ageing_time;
u8 stp_state;
......
......@@ -201,7 +201,7 @@ static int dsa_switch_rcv(struct sk_buff *skb, struct net_device *dev,
#ifdef CONFIG_PM_SLEEP
static bool dsa_is_port_initialized(struct dsa_switch *ds, int p)
{
return ds->enabled_port_mask & (1 << p) && ds->ports[p].netdev;
return ds->enabled_port_mask & (1 << p) && ds->ports[p].slave;
}
int dsa_switch_suspend(struct dsa_switch *ds)
......@@ -213,7 +213,7 @@ int dsa_switch_suspend(struct dsa_switch *ds)
if (!dsa_is_port_initialized(ds, i))
continue;
ret = dsa_slave_suspend(ds->ports[i].netdev);
ret = dsa_slave_suspend(ds->ports[i].slave);
if (ret)
return ret;
}
......@@ -240,7 +240,7 @@ int dsa_switch_resume(struct dsa_switch *ds)
if (!dsa_is_port_initialized(ds, i))
continue;
ret = dsa_slave_resume(ds->ports[i].netdev);
ret = dsa_slave_resume(ds->ports[i].slave);
if (ret)
return ret;
}
......
......@@ -279,7 +279,7 @@ static int dsa_user_port_apply(struct dsa_port *port)
if (err) {
dev_warn(ds->dev, "Failed to create slave %d: %d\n",
port->index, err);
port->netdev = NULL;
port->slave = NULL;
return err;
}
......@@ -289,7 +289,7 @@ static int dsa_user_port_apply(struct dsa_port *port)
if (err)
return err;
devlink_port_type_eth_set(&port->devlink_port, port->netdev);
devlink_port_type_eth_set(&port->devlink_port, port->slave);
return 0;
}
......@@ -297,9 +297,9 @@ static int dsa_user_port_apply(struct dsa_port *port)
static void dsa_user_port_unapply(struct dsa_port *port)
{
devlink_port_unregister(&port->devlink_port);
if (port->netdev) {
dsa_slave_destroy(port->netdev);
port->netdev = NULL;
if (port->slave) {
dsa_slave_destroy(port->slave);
port->slave = NULL;
port->ds->enabled_port_mask &= ~(1 << port->index);
}
}
......@@ -432,9 +432,9 @@ static int dsa_dst_apply(struct dsa_switch_tree *dst)
* sent to the tag format's receive function.
*/
wmb();
dst->cpu_dp->netdev->dsa_ptr = dst->cpu_dp;
dst->cpu_dp->master->dsa_ptr = dst->cpu_dp;
err = dsa_master_ethtool_setup(dst->cpu_dp->netdev);
err = dsa_master_ethtool_setup(dst->cpu_dp->master);
if (err)
return err;
......@@ -451,9 +451,9 @@ static void dsa_dst_unapply(struct dsa_switch_tree *dst)
if (!dst->applied)
return;
dsa_master_ethtool_restore(dst->cpu_dp->netdev);
dsa_master_ethtool_restore(dst->cpu_dp->master);
dst->cpu_dp->netdev->dsa_ptr = NULL;
dst->cpu_dp->master->dsa_ptr = NULL;
/* If we used a tagging format that doesn't have an ethertype
* field, make sure that all packets from this point get sent
......@@ -499,7 +499,7 @@ static int dsa_cpu_parse(struct dsa_port *port, u32 index,
if (!dst->cpu_dp) {
dst->cpu_dp = port;
dst->cpu_dp->netdev = ethernet_dev;
dst->cpu_dp->master = ethernet_dev;
}
/* Initialize cpu_port_mask now for drv->setup()
......
......@@ -130,7 +130,7 @@ static inline struct net_device *dsa_master_find_slave(struct net_device *dev,
if (port < 0 || port >= ds->num_ports)
return NULL;
return ds->ports[port].netdev;
return ds->ports[port].slave;
}
/* port.c */
......@@ -181,7 +181,7 @@ dsa_slave_to_master(const struct net_device *dev)
{
struct dsa_port *dp = dsa_slave_to_port(dev);
return dp->cpu_dp->netdev;
return dp->cpu_dp->master;
}
/* switch.c */
......
......@@ -120,7 +120,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds,
return -EINVAL;
}
dst->cpu_dp = &ds->ports[i];
dst->cpu_dp->netdev = master;
dst->cpu_dp->master = master;
ds->cpu_port_mask |= 1 << i;
} else if (!strcmp(name, "dsa")) {
ds->dsa_port_mask |= 1 << i;
......@@ -261,10 +261,10 @@ static void dsa_switch_destroy(struct dsa_switch *ds)
if (!(ds->enabled_port_mask & (1 << port)))
continue;
if (!ds->ports[port].netdev)
if (!ds->ports[port].slave)
continue;
dsa_slave_destroy(ds->ports[port].netdev);
dsa_slave_destroy(ds->ports[port].slave);
}
/* Disable configuration of the CPU and DSA ports */
......@@ -601,7 +601,7 @@ static int dsa_setup_dst(struct dsa_switch_tree *dst, struct net_device *dev,
wmb();
dev->dsa_ptr = dst->cpu_dp;
return dsa_master_ethtool_setup(dst->cpu_dp->netdev);
return dsa_master_ethtool_setup(dst->cpu_dp->master);
}
static int dsa_probe(struct platform_device *pdev)
......@@ -666,9 +666,9 @@ static void dsa_remove_dst(struct dsa_switch_tree *dst)
{
int i;
dsa_master_ethtool_restore(dst->cpu_dp->netdev);
dsa_master_ethtool_restore(dst->cpu_dp->master);
dst->cpu_dp->netdev->dsa_ptr = NULL;
dst->cpu_dp->master->dsa_ptr = NULL;
/* If we used a tagging format that doesn't have an ethertype
* field, make sure that all packets from this point get sent
......@@ -683,7 +683,7 @@ static void dsa_remove_dst(struct dsa_switch_tree *dst)
dsa_switch_destroy(ds);
}
dev_put(dst->cpu_dp->netdev);
dev_put(dst->cpu_dp->master);
}
static int dsa_remove(struct platform_device *pdev)
......
......@@ -1123,7 +1123,7 @@ static void dsa_slave_notify(struct net_device *dev, unsigned long val)
int dsa_slave_create(struct dsa_port *port, const char *name)
{
struct dsa_port *cpu_dp = port->cpu_dp;
struct net_device *master = cpu_dp->netdev;
struct net_device *master = cpu_dp->master;
struct dsa_switch *ds = port->ds;
struct net_device *slave_dev;
struct dsa_slave_priv *p;
......@@ -1170,7 +1170,7 @@ int dsa_slave_create(struct dsa_port *port, const char *name)
p->old_link = -1;
p->old_duplex = -1;
port->netdev = slave_dev;
port->slave = slave_dev;
netif_carrier_off(slave_dev);
......@@ -1198,7 +1198,7 @@ int dsa_slave_create(struct dsa_port *port, const char *name)
out_free:
free_percpu(p->stats64);
free_netdev(slave_dev);
port->netdev = NULL;
port->slave = NULL;
return ret;
}
......
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