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