net: dsa: use ports list to setup switches

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 <vivien.didelot@gmail.com>
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
This commit is contained in:
Vivien Didelot 2019-10-21 16:51:19 -04:00 committed by Jakub Kicinski
parent 7b9a2f4bac
commit fb35c60cba
2 changed files with 45 additions and 52 deletions

View File

@ -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;
/*

View File

@ -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,21 @@ 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;
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 +375,16 @@ static void dsa_port_teardown(struct dsa_port *dp)
}
break;
}
dp->setup = false;
}
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 +426,8 @@ static int dsa_switch_setup(struct dsa_switch *ds)
goto unregister_notifier;
}
ds->setup = true;
return 0;
unregister_notifier:
@ -426,6 +443,9 @@ free_devlink:
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 +460,47 @@ static void dsa_switch_teardown(struct dsa_switch *ds)
ds->devlink = NULL;
}
ds->setup = false;
}
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;
int err;
for (device = 0; device < DSA_MAX_SWITCHES; device++) {
ds = dst->ds[device];
if (!ds)
continue;
err = dsa_switch_setup(ds);
list_for_each_entry(dp, &dst->ports, list) {
err = dsa_switch_setup(dp->ds);
if (err)
goto switch_teardown;
goto teardown;
}
for (port = 0; port < ds->num_ports; port++) {
dp = &ds->ports[port];
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]);
teardown:
list_for_each_entry(dp, &dst->ports, list)
dsa_port_teardown(dp);
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);
}
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;
list_for_each_entry(dp, &dst->ports, list)
dsa_port_teardown(dp);
for (port = 0; port < ds->num_ports; port++) {
dp = &ds->ports[port];
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)