net: dsa: setup and teardown master device
Add DSA helpers to setup and teardown a master net device wired to its CPU port. This centralizes the dsa_ptr assignment. This also makes the master ethtool helpers static at the same time. Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
f070464cf0
commit
17a22fcfc8
|
@ -469,6 +469,23 @@ static void dsa_ds_unapply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int dsa_tree_setup_master(struct dsa_switch_tree *dst)
|
||||||
|
{
|
||||||
|
struct dsa_port *cpu_dp = dst->cpu_dp;
|
||||||
|
struct net_device *master = cpu_dp->master;
|
||||||
|
|
||||||
|
/* DSA currently supports a single pair of CPU port and master device */
|
||||||
|
return dsa_master_setup(master, cpu_dp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dsa_tree_teardown_master(struct dsa_switch_tree *dst)
|
||||||
|
{
|
||||||
|
struct dsa_port *cpu_dp = dst->cpu_dp;
|
||||||
|
struct net_device *master = cpu_dp->master;
|
||||||
|
|
||||||
|
return dsa_master_teardown(master);
|
||||||
|
}
|
||||||
|
|
||||||
static int dsa_dst_apply(struct dsa_switch_tree *dst)
|
static int dsa_dst_apply(struct dsa_switch_tree *dst)
|
||||||
{
|
{
|
||||||
struct dsa_switch *ds;
|
struct dsa_switch *ds;
|
||||||
|
@ -489,14 +506,7 @@ static int dsa_dst_apply(struct dsa_switch_tree *dst)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we use a tagging format that doesn't have an ethertype
|
err = dsa_tree_setup_master(dst);
|
||||||
* field, make sure that all packets from this point on get
|
|
||||||
* sent to the tag format's receive function.
|
|
||||||
*/
|
|
||||||
wmb();
|
|
||||||
dst->cpu_dp->master->dsa_ptr = dst->cpu_dp;
|
|
||||||
|
|
||||||
err = dsa_master_ethtool_setup(dst->cpu_dp->master);
|
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
@ -513,15 +523,7 @@ 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->master);
|
dsa_tree_teardown_master(dst);
|
||||||
|
|
||||||
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
|
|
||||||
* without the tag and go through the regular receive path.
|
|
||||||
*/
|
|
||||||
wmb();
|
|
||||||
|
|
||||||
for (index = 0; index < DSA_MAX_SWITCHES; index++) {
|
for (index = 0; index < DSA_MAX_SWITCHES; index++) {
|
||||||
ds = dst->ds[index];
|
ds = dst->ds[index];
|
||||||
|
|
|
@ -108,8 +108,8 @@ int dsa_legacy_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
|
||||||
const unsigned char *addr, u16 vid);
|
const unsigned char *addr, u16 vid);
|
||||||
|
|
||||||
/* master.c */
|
/* master.c */
|
||||||
int dsa_master_ethtool_setup(struct net_device *dev);
|
int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp);
|
||||||
void dsa_master_ethtool_restore(struct net_device *dev);
|
void dsa_master_teardown(struct net_device *dev);
|
||||||
|
|
||||||
static inline struct net_device *dsa_master_find_slave(struct net_device *dev,
|
static inline struct net_device *dsa_master_find_slave(struct net_device *dev,
|
||||||
int device, int port)
|
int device, int port)
|
||||||
|
|
|
@ -593,15 +593,7 @@ static int dsa_setup_dst(struct dsa_switch_tree *dst, struct net_device *dev,
|
||||||
if (!configured)
|
if (!configured)
|
||||||
return -EPROBE_DEFER;
|
return -EPROBE_DEFER;
|
||||||
|
|
||||||
/*
|
return dsa_master_setup(dst->cpu_dp->master, dst->cpu_dp);
|
||||||
* If we use a tagging format that doesn't have an ethertype
|
|
||||||
* field, make sure that all packets from this point on get
|
|
||||||
* sent to the tag format's receive function.
|
|
||||||
*/
|
|
||||||
wmb();
|
|
||||||
dev->dsa_ptr = dst->cpu_dp;
|
|
||||||
|
|
||||||
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,15 +658,7 @@ static void dsa_remove_dst(struct dsa_switch_tree *dst)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
dsa_master_ethtool_restore(dst->cpu_dp->master);
|
dsa_master_teardown(dst->cpu_dp->master);
|
||||||
|
|
||||||
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
|
|
||||||
* without the tag and go through the regular receive path.
|
|
||||||
*/
|
|
||||||
wmb();
|
|
||||||
|
|
||||||
for (i = 0; i < dst->pd->nr_chips; i++) {
|
for (i = 0; i < dst->pd->nr_chips; i++) {
|
||||||
struct dsa_switch *ds = dst->ds[i];
|
struct dsa_switch *ds = dst->ds[i];
|
||||||
|
|
|
@ -85,7 +85,7 @@ static void dsa_master_get_strings(struct net_device *dev, uint32_t stringset,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int dsa_master_ethtool_setup(struct net_device *dev)
|
static int dsa_master_ethtool_setup(struct net_device *dev)
|
||||||
{
|
{
|
||||||
struct dsa_port *cpu_dp = dev->dsa_ptr;
|
struct dsa_port *cpu_dp = dev->dsa_ptr;
|
||||||
struct dsa_switch *ds = cpu_dp->ds;
|
struct dsa_switch *ds = cpu_dp->ds;
|
||||||
|
@ -108,10 +108,36 @@ int dsa_master_ethtool_setup(struct net_device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dsa_master_ethtool_restore(struct net_device *dev)
|
static void dsa_master_ethtool_teardown(struct net_device *dev)
|
||||||
{
|
{
|
||||||
struct dsa_port *cpu_dp = dev->dsa_ptr;
|
struct dsa_port *cpu_dp = dev->dsa_ptr;
|
||||||
|
|
||||||
dev->ethtool_ops = cpu_dp->orig_ethtool_ops;
|
dev->ethtool_ops = cpu_dp->orig_ethtool_ops;
|
||||||
cpu_dp->orig_ethtool_ops = NULL;
|
cpu_dp->orig_ethtool_ops = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp)
|
||||||
|
{
|
||||||
|
/* If we use a tagging format that doesn't have an ethertype
|
||||||
|
* field, make sure that all packets from this point on get
|
||||||
|
* sent to the tag format's receive function.
|
||||||
|
*/
|
||||||
|
wmb();
|
||||||
|
|
||||||
|
dev->dsa_ptr = cpu_dp;
|
||||||
|
|
||||||
|
return dsa_master_ethtool_setup(dev);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dsa_master_teardown(struct net_device *dev)
|
||||||
|
{
|
||||||
|
dsa_master_ethtool_teardown(dev);
|
||||||
|
|
||||||
|
dev->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
|
||||||
|
* without the tag and go through the regular receive path.
|
||||||
|
*/
|
||||||
|
wmb();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue