Use the new ports list instead of iterating over switches and their
ports when setting up the switches and their ports.
At the same time, provide setup states and messages for ports and
switches as it is done for the trees.
Signed-off-by: Vivien Didelot <[email protected]>
---
include/net/dsa.h | 4 ++
net/dsa/dsa2.c | 101 ++++++++++++++++++++++------------------------
2 files changed, 53 insertions(+), 52 deletions(-)
diff --git a/include/net/dsa.h b/include/net/dsa.h
index 938de9518c61..b199a8ca6393 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -215,9 +215,13 @@ struct dsa_port {
* Original copy of the master netdev net_device_ops
*/
const struct net_device_ops *orig_ndo_ops;
+
+ bool setup;
};
struct dsa_switch {
+ bool setup;
+
struct device *dev;
/*
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index b6536641ac99..fd2b7f157f97 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -267,6 +267,9 @@ static int dsa_port_setup(struct dsa_port *dp)
bool dsa_port_enabled = false;
int err = 0;
+ if (dp->setup)
+ return 0;
+
switch (dp->type) {
case DSA_PORT_TYPE_UNUSED:
dsa_port_disable(dp);
@@ -335,14 +338,23 @@ static int dsa_port_setup(struct dsa_port *dp)
dsa_port_link_unregister_of(dp);
if (err && devlink_port_registered)
devlink_port_unregister(dlp);
+ if (err)
+ return err;
- return err;
+ dp->setup = true;
+
+ pr_info("DSA: switch %d port %d setup\n", dp->ds->index, dp->index);
+
+ return 0;
}
static void dsa_port_teardown(struct dsa_port *dp)
{
struct devlink_port *dlp = &dp->devlink_port;
+ if (!dp->setup)
+ return;
+
switch (dp->type) {
case DSA_PORT_TYPE_UNUSED:
break;
@@ -365,11 +377,18 @@ static void dsa_port_teardown(struct dsa_port *dp)
}
break;
}
+
+ dp->setup = false;
+
+ pr_info("DSA: switch %d port %d torn down\n", dp->ds->index, dp->index);
}
static int dsa_switch_setup(struct dsa_switch *ds)
{
- int err = 0;
+ int err;
+
+ if (ds->setup)
+ return 0;
/* Initialize ds->phys_mii_mask before registering the slave MDIO bus
* driver and before ops->setup() has run, since the switch drivers and
@@ -411,6 +430,10 @@ static int dsa_switch_setup(struct dsa_switch *ds)
goto unregister_notifier;
}
+ ds->setup = true;
+
+ pr_info("DSA: switch %d setup\n", ds->index);
+
return 0;
unregister_notifier:
@@ -426,6 +449,9 @@ static int dsa_switch_setup(struct dsa_switch *ds)
static void dsa_switch_teardown(struct dsa_switch *ds)
{
+ if (!ds->setup)
+ return;
+
if (ds->slave_mii_bus && ds->ops->phy_read)
mdiobus_unregister(ds->slave_mii_bus);
@@ -440,78 +466,49 @@ static void dsa_switch_teardown(struct dsa_switch *ds)
ds->devlink = NULL;
}
+ ds->setup = false;
+
+ pr_info("DSA: switch %d torn down\n", ds->index);
}
static int dsa_tree_setup_switches(struct dsa_switch_tree *dst)
{
- struct dsa_switch *ds;
struct dsa_port *dp;
- int device, port, i;
- int err = 0;
-
- for (device = 0; device < DSA_MAX_SWITCHES; device++) {
- ds = dst->ds[device];
- if (!ds)
- continue;
+ int err;
- err = dsa_switch_setup(ds);
+ list_for_each_entry(dp, &dst->ports, list) {
+ err = dsa_switch_setup(dp->ds);
if (err)
- goto switch_teardown;
-
- for (port = 0; port < ds->num_ports; port++) {
- dp = &ds->ports[port];
+ goto teardown;
+ }
- err = dsa_port_setup(dp);
- if (err)
- goto ports_teardown;
- }
+ list_for_each_entry(dp, &dst->ports, list) {
+ err = dsa_port_setup(dp);
+ if (err)
+ goto teardown;
}
return 0;
-ports_teardown:
- for (i = 0; i < port; i++)
- dsa_port_teardown(&ds->ports[i]);
-
- dsa_switch_teardown(ds);
-
-switch_teardown:
- for (i = 0; i < device; i++) {
- ds = dst->ds[i];
- if (!ds)
- continue;
-
- for (port = 0; port < ds->num_ports; port++) {
- dp = &ds->ports[port];
-
- dsa_port_teardown(dp);
- }
+teardown:
+ list_for_each_entry(dp, &dst->ports, list)
+ dsa_port_teardown(dp);
- dsa_switch_teardown(ds);
- }
+ list_for_each_entry(dp, &dst->ports, list)
+ dsa_switch_teardown(dp->ds);
return err;
}
static void dsa_tree_teardown_switches(struct dsa_switch_tree *dst)
{
- struct dsa_switch *ds;
struct dsa_port *dp;
- int device, port;
-
- for (device = 0; device < DSA_MAX_SWITCHES; device++) {
- ds = dst->ds[device];
- if (!ds)
- continue;
- for (port = 0; port < ds->num_ports; port++) {
- dp = &ds->ports[port];
+ list_for_each_entry(dp, &dst->ports, list)
+ dsa_port_teardown(dp);
- dsa_port_teardown(dp);
- }
-
- dsa_switch_teardown(ds);
- }
+ list_for_each_entry(dp, &dst->ports, list)
+ dsa_switch_teardown(dp->ds);
}
static int dsa_tree_setup_master(struct dsa_switch_tree *dst)
--
2.23.0
On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> Use the new ports list instead of iterating over switches and their
> ports when setting up the switches and their ports.
>
> At the same time, provide setup states and messages for ports and
> switches as it is done for the trees.
Humm, that becomes quite noisy, would it make sense to have those
messages only for non-user ports that are not already visible because
they do not have a net_device?
If you have multiple switches in a fabric, it might be convenient to use
dev_info(dp->ds->dev, ...) to print your message so you can clearly
identify which port belongs to which switch, which becomes even more
important as it is all flattened thanks to lists now. What do you think?
--
Florian
On Sun, Oct 20, 2019 at 07:42:15PM -0700, Florian Fainelli wrote:
>
>
> On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> > Use the new ports list instead of iterating over switches and their
> > ports when setting up the switches and their ports.
> >
> > At the same time, provide setup states and messages for ports and
> > switches as it is done for the trees.
>
> Humm, that becomes quite noisy, would it make sense to have those
> messages only for non-user ports that are not already visible because
> they do not have a net_device?
I agree, it looks noise. Maybe change them to _dbg()?
> If you have multiple switches in a fabric, it might be convenient to use
> dev_info(dp->ds->dev, ...) to print your message so you can clearly
> identify which port belongs to which switch, which becomes even more
> important as it is all flattened thanks to lists now. What do you think?
I do think it needs to identify both the dst and the ds.
Andrew
On Mon, 21 Oct 2019 14:49:02 +0200, Andrew Lunn <[email protected]> wrote:
> On Sun, Oct 20, 2019 at 07:42:15PM -0700, Florian Fainelli wrote:
> >
> >
> > On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> > > Use the new ports list instead of iterating over switches and their
> > > ports when setting up the switches and their ports.
> > >
> > > At the same time, provide setup states and messages for ports and
> > > switches as it is done for the trees.
> >
> > Humm, that becomes quite noisy, would it make sense to have those
> > messages only for non-user ports that are not already visible because
> > they do not have a net_device?
>
> I agree, it looks noise. Maybe change them to _dbg()?
>
> > If you have multiple switches in a fabric, it might be convenient to use
> > dev_info(dp->ds->dev, ...) to print your message so you can clearly
> > identify which port belongs to which switch, which becomes even more
> > important as it is all flattened thanks to lists now. What do you think?
>
> I do think it needs to identify both the dst and the ds.
It is noise indeed and doesn't add much value, I'll remove them.
Thanks,
Vivien