Skip to content

Commit 17a22fc

Browse files
viviendavem330
authored andcommitted
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>
1 parent f070464 commit 17a22fc

File tree

4 files changed

+51
-39
lines changed

4 files changed

+51
-39
lines changed

net/dsa/dsa2.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,23 @@ static void dsa_ds_unapply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
469469

470470
}
471471

472+
static int dsa_tree_setup_master(struct dsa_switch_tree *dst)
473+
{
474+
struct dsa_port *cpu_dp = dst->cpu_dp;
475+
struct net_device *master = cpu_dp->master;
476+
477+
/* DSA currently supports a single pair of CPU port and master device */
478+
return dsa_master_setup(master, cpu_dp);
479+
}
480+
481+
static void dsa_tree_teardown_master(struct dsa_switch_tree *dst)
482+
{
483+
struct dsa_port *cpu_dp = dst->cpu_dp;
484+
struct net_device *master = cpu_dp->master;
485+
486+
return dsa_master_teardown(master);
487+
}
488+
472489
static int dsa_dst_apply(struct dsa_switch_tree *dst)
473490
{
474491
struct dsa_switch *ds;
@@ -489,14 +506,7 @@ static int dsa_dst_apply(struct dsa_switch_tree *dst)
489506
return err;
490507
}
491508

492-
/* If we use a tagging format that doesn't have an ethertype
493-
* field, make sure that all packets from this point on get
494-
* sent to the tag format's receive function.
495-
*/
496-
wmb();
497-
dst->cpu_dp->master->dsa_ptr = dst->cpu_dp;
498-
499-
err = dsa_master_ethtool_setup(dst->cpu_dp->master);
509+
err = dsa_tree_setup_master(dst);
500510
if (err)
501511
return err;
502512

@@ -513,15 +523,7 @@ static void dsa_dst_unapply(struct dsa_switch_tree *dst)
513523
if (!dst->applied)
514524
return;
515525

516-
dsa_master_ethtool_restore(dst->cpu_dp->master);
517-
518-
dst->cpu_dp->master->dsa_ptr = NULL;
519-
520-
/* If we used a tagging format that doesn't have an ethertype
521-
* field, make sure that all packets from this point get sent
522-
* without the tag and go through the regular receive path.
523-
*/
524-
wmb();
526+
dsa_tree_teardown_master(dst);
525527

526528
for (index = 0; index < DSA_MAX_SWITCHES; index++) {
527529
ds = dst->ds[index];

net/dsa/dsa_priv.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ int dsa_legacy_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
108108
const unsigned char *addr, u16 vid);
109109

110110
/* master.c */
111-
int dsa_master_ethtool_setup(struct net_device *dev);
112-
void dsa_master_ethtool_restore(struct net_device *dev);
111+
int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp);
112+
void dsa_master_teardown(struct net_device *dev);
113113

114114
static inline struct net_device *dsa_master_find_slave(struct net_device *dev,
115115
int device, int port)

net/dsa/legacy.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -593,15 +593,7 @@ static int dsa_setup_dst(struct dsa_switch_tree *dst, struct net_device *dev,
593593
if (!configured)
594594
return -EPROBE_DEFER;
595595

596-
/*
597-
* If we use a tagging format that doesn't have an ethertype
598-
* field, make sure that all packets from this point on get
599-
* sent to the tag format's receive function.
600-
*/
601-
wmb();
602-
dev->dsa_ptr = dst->cpu_dp;
603-
604-
return dsa_master_ethtool_setup(dst->cpu_dp->master);
596+
return dsa_master_setup(dst->cpu_dp->master, dst->cpu_dp);
605597
}
606598

607599
static int dsa_probe(struct platform_device *pdev)
@@ -666,15 +658,7 @@ static void dsa_remove_dst(struct dsa_switch_tree *dst)
666658
{
667659
int i;
668660

669-
dsa_master_ethtool_restore(dst->cpu_dp->master);
670-
671-
dst->cpu_dp->master->dsa_ptr = NULL;
672-
673-
/* If we used a tagging format that doesn't have an ethertype
674-
* field, make sure that all packets from this point get sent
675-
* without the tag and go through the regular receive path.
676-
*/
677-
wmb();
661+
dsa_master_teardown(dst->cpu_dp->master);
678662

679663
for (i = 0; i < dst->pd->nr_chips; i++) {
680664
struct dsa_switch *ds = dst->ds[i];

net/dsa/master.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static void dsa_master_get_strings(struct net_device *dev, uint32_t stringset,
8585
}
8686
}
8787

88-
int dsa_master_ethtool_setup(struct net_device *dev)
88+
static int dsa_master_ethtool_setup(struct net_device *dev)
8989
{
9090
struct dsa_port *cpu_dp = dev->dsa_ptr;
9191
struct dsa_switch *ds = cpu_dp->ds;
@@ -108,10 +108,36 @@ int dsa_master_ethtool_setup(struct net_device *dev)
108108
return 0;
109109
}
110110

111-
void dsa_master_ethtool_restore(struct net_device *dev)
111+
static void dsa_master_ethtool_teardown(struct net_device *dev)
112112
{
113113
struct dsa_port *cpu_dp = dev->dsa_ptr;
114114

115115
dev->ethtool_ops = cpu_dp->orig_ethtool_ops;
116116
cpu_dp->orig_ethtool_ops = NULL;
117117
}
118+
119+
int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp)
120+
{
121+
/* If we use a tagging format that doesn't have an ethertype
122+
* field, make sure that all packets from this point on get
123+
* sent to the tag format's receive function.
124+
*/
125+
wmb();
126+
127+
dev->dsa_ptr = cpu_dp;
128+
129+
return dsa_master_ethtool_setup(dev);
130+
}
131+
132+
void dsa_master_teardown(struct net_device *dev)
133+
{
134+
dsa_master_ethtool_teardown(dev);
135+
136+
dev->dsa_ptr = NULL;
137+
138+
/* If we used a tagging format that doesn't have an ethertype
139+
* field, make sure that all packets from this point get sent
140+
* without the tag and go through the regular receive path.
141+
*/
142+
wmb();
143+
}

0 commit comments

Comments
 (0)