提交 fb35c60c 编写于 作者: V Vivien Didelot 提交者: Jakub Kicinski

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: NVivien Didelot <vivien.didelot@gmail.com>
Signed-off-by: NJakub Kicinski <jakub.kicinski@netronome.com>
上级 7b9a2f4b
......@@ -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;
/*
......
......@@ -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 @@ 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 +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;
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;
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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册