Commit 955222ca authored by Vivien Didelot's avatar Vivien Didelot Committed by David S. Miller

net: dsa: use a single switch statement for port setup

It is currently difficult to read the different steps involved in the
setup and teardown of ports in the DSA code. Keep it simple with a
single switch statement for each port type: UNUSED, CPU, DSA, or USER.

Also no need to call devlink_port_unregister from within dsa_port_setup
as this step is inconditionally handled by dsa_port_teardown on error.
Signed-off-by: default avatarVivien Didelot <vivien.didelot@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d2187f8e
...@@ -254,88 +254,79 @@ static void dsa_tree_teardown_default_cpu(struct dsa_switch_tree *dst) ...@@ -254,88 +254,79 @@ static void dsa_tree_teardown_default_cpu(struct dsa_switch_tree *dst)
static int dsa_port_setup(struct dsa_port *dp) static int dsa_port_setup(struct dsa_port *dp)
{ {
enum devlink_port_flavour flavour;
struct dsa_switch *ds = dp->ds; struct dsa_switch *ds = dp->ds;
struct dsa_switch_tree *dst = ds->dst; struct dsa_switch_tree *dst = ds->dst;
int err = 0; const unsigned char *id = (const unsigned char *)&dst->index;
const unsigned char len = sizeof(dst->index);
if (dp->type == DSA_PORT_TYPE_UNUSED) struct devlink_port *dlp = &dp->devlink_port;
return 0; struct devlink *dl = ds->devlink;
int err;
memset(&dp->devlink_port, 0, sizeof(dp->devlink_port));
dp->mac = of_get_mac_address(dp->dn);
switch (dp->type) {
case DSA_PORT_TYPE_CPU:
flavour = DEVLINK_PORT_FLAVOUR_CPU;
break;
case DSA_PORT_TYPE_DSA:
flavour = DEVLINK_PORT_FLAVOUR_DSA;
break;
case DSA_PORT_TYPE_USER: /* fall-through */
default:
flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
break;
}
/* dp->index is used now as port_number. However
* CPU and DSA ports should have separate numbering
* independent from front panel port numbers.
*/
devlink_port_attrs_set(&dp->devlink_port, flavour,
dp->index, false, 0,
(const char *) &dst->index, sizeof(dst->index));
err = devlink_port_register(ds->devlink, &dp->devlink_port,
dp->index);
if (err)
return err;
switch (dp->type) { switch (dp->type) {
case DSA_PORT_TYPE_UNUSED: case DSA_PORT_TYPE_UNUSED:
break; break;
case DSA_PORT_TYPE_CPU: case DSA_PORT_TYPE_CPU:
memset(dlp, 0, sizeof(*dlp));
devlink_port_attrs_set(dlp, DEVLINK_PORT_FLAVOUR_CPU,
dp->index, false, 0, id, len);
err = devlink_port_register(dl, dlp, dp->index);
if (err)
return err;
err = dsa_port_link_register_of(dp); err = dsa_port_link_register_of(dp);
if (err) if (err)
dev_err(ds->dev, "failed to setup link for port %d.%d\n", return err;
ds->index, dp->index);
break; break;
case DSA_PORT_TYPE_DSA: case DSA_PORT_TYPE_DSA:
memset(dlp, 0, sizeof(*dlp));
devlink_port_attrs_set(dlp, DEVLINK_PORT_FLAVOUR_DSA,
dp->index, false, 0, id, len);
err = devlink_port_register(dl, dlp, dp->index);
if (err)
return err;
err = dsa_port_link_register_of(dp); err = dsa_port_link_register_of(dp);
if (err) if (err)
dev_err(ds->dev, "failed to setup link for port %d.%d\n", return err;
ds->index, dp->index);
break; break;
case DSA_PORT_TYPE_USER: case DSA_PORT_TYPE_USER:
memset(dlp, 0, sizeof(*dlp));
devlink_port_attrs_set(dlp, DEVLINK_PORT_FLAVOUR_PHYSICAL,
dp->index, false, 0, id, len);
err = devlink_port_register(dl, dlp, dp->index);
if (err)
return err;
dp->mac = of_get_mac_address(dp->dn);
err = dsa_slave_create(dp); err = dsa_slave_create(dp);
if (err) if (err)
dev_err(ds->dev, "failed to create slave for port %d.%d\n", return err;
ds->index, dp->index);
else devlink_port_type_eth_set(dlp, dp->slave);
devlink_port_type_eth_set(&dp->devlink_port, dp->slave);
break; break;
} }
if (err) return 0;
devlink_port_unregister(&dp->devlink_port);
return err;
} }
static void dsa_port_teardown(struct dsa_port *dp) static void dsa_port_teardown(struct dsa_port *dp)
{ {
if (dp->type != DSA_PORT_TYPE_UNUSED) struct devlink_port *dlp = &dp->devlink_port;
devlink_port_unregister(&dp->devlink_port);
switch (dp->type) { switch (dp->type) {
case DSA_PORT_TYPE_UNUSED: case DSA_PORT_TYPE_UNUSED:
break; break;
case DSA_PORT_TYPE_CPU: case DSA_PORT_TYPE_CPU:
dsa_tag_driver_put(dp->tag_ops); dsa_tag_driver_put(dp->tag_ops);
/* fall-through */ devlink_port_unregister(dlp);
dsa_port_link_unregister_of(dp);
break;
case DSA_PORT_TYPE_DSA: case DSA_PORT_TYPE_DSA:
devlink_port_unregister(dlp);
dsa_port_link_unregister_of(dp); dsa_port_link_unregister_of(dp);
break; break;
case DSA_PORT_TYPE_USER: case DSA_PORT_TYPE_USER:
devlink_port_unregister(dlp);
if (dp->slave) { if (dp->slave) {
dsa_slave_destroy(dp->slave); dsa_slave_destroy(dp->slave);
dp->slave = NULL; dp->slave = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment