[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220726124105.495652-1-jiri@resnulli.us>
Date: Tue, 26 Jul 2022 14:41:05 +0200
From: Jiri Pirko <jiri@...nulli.us>
To: netdev@...r.kernel.org
Cc: davem@...emloft.net, kuba@...nel.org, pabeni@...hat.com,
edumazet@...gle.com, andrew@...n.ch, vivien.didelot@...il.com,
f.fainelli@...il.com, olteanv@...il.com
Subject: [patch net-next RFC] net: dsa: move port_setup/teardown to be called outside devlink port registered area
From: Jiri Pirko <jiri@...dia.com>
Move port_setup() op to be called before devlink_port_register() and
port_teardown() after devlink_port_unregister().
RFC note: I don't see why this would not work, but I have no way to
test this does not break things. But I think it makes sense to move this
alongside the rest of the devlink port code, the reinit() function
also gets much nicer, as clearly the fact that
port_setup()->devlink_port_region_create() was called in dsa_port_setup
did not fit the flow.
Signed-off-by: Jiri Pirko <jiri@...dia.com>
---
net/dsa/dsa2.c | 64 +++++++++++++++++---------------------------------
1 file changed, 21 insertions(+), 43 deletions(-)
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index cac48a741f27..a8b6c6434df2 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -451,19 +451,12 @@ static int dsa_port_setup(struct dsa_port *dp)
{
struct devlink_port *dlp = &dp->devlink_port;
bool dsa_port_link_registered = false;
- struct dsa_switch *ds = dp->ds;
bool dsa_port_enabled = false;
int err = 0;
if (dp->setup)
return 0;
- if (ds->ops->port_setup) {
- err = ds->ops->port_setup(ds, dp->index);
- if (err)
- return err;
- }
-
switch (dp->type) {
case DSA_PORT_TYPE_UNUSED:
dsa_port_disable(dp);
@@ -506,11 +499,6 @@ static int dsa_port_setup(struct dsa_port *dp)
dsa_port_disable(dp);
if (err && dsa_port_link_registered)
dsa_port_link_unregister_of(dp);
- if (err) {
- if (ds->ops->port_teardown)
- ds->ops->port_teardown(ds, dp->index);
- return err;
- }
dp->setup = true;
@@ -523,10 +511,17 @@ static int dsa_port_devlink_setup(struct dsa_port *dp)
struct dsa_switch_tree *dst = dp->ds->dst;
struct devlink_port_attrs attrs = {};
struct devlink *dl = dp->ds->devlink;
+ struct dsa_switch *ds = dp->ds;
const unsigned char *id;
unsigned char len;
int err;
+ if (ds->ops->port_setup) {
+ err = ds->ops->port_setup(ds, dp->index);
+ if (err)
+ return err;
+ }
+
id = (const unsigned char *)&dst->index;
len = sizeof(dst->index);
@@ -552,24 +547,23 @@ static int dsa_port_devlink_setup(struct dsa_port *dp)
devlink_port_attrs_set(dlp, &attrs);
err = devlink_port_register(dl, dlp, dp->index);
+ if (err) {
+ if (ds->ops->port_teardown)
+ ds->ops->port_teardown(ds, dp->index);
+ return err;
+ }
+ dp->devlink_port_setup = true;
- if (!err)
- dp->devlink_port_setup = true;
-
- return err;
+ return 0;
}
static void dsa_port_teardown(struct dsa_port *dp)
{
struct devlink_port *dlp = &dp->devlink_port;
- struct dsa_switch *ds = dp->ds;
if (!dp->setup)
return;
- if (ds->ops->port_teardown)
- ds->ops->port_teardown(ds, dp->index);
-
devlink_port_type_clear(dlp);
switch (dp->type) {
@@ -597,40 +591,24 @@ static void dsa_port_teardown(struct dsa_port *dp)
static void dsa_port_devlink_teardown(struct dsa_port *dp)
{
struct devlink_port *dlp = &dp->devlink_port;
+ struct dsa_switch *ds = dp->ds;
- if (dp->devlink_port_setup)
+ if (dp->devlink_port_setup) {
devlink_port_unregister(dlp);
+ if (ds->ops->port_teardown)
+ ds->ops->port_teardown(ds, dp->index);
+ }
dp->devlink_port_setup = false;
}
/* Destroy the current devlink port, and create a new one which has the UNUSED
- * flavour. At this point, any call to ds->ops->port_setup has been already
- * balanced out by a call to ds->ops->port_teardown, so we know that any
- * devlink port regions the driver had are now unregistered. We then call its
- * ds->ops->port_setup again, in order for the driver to re-create them on the
- * new devlink port.
+ * flavour.
*/
static int dsa_port_reinit_as_unused(struct dsa_port *dp)
{
- struct dsa_switch *ds = dp->ds;
- int err;
-
dsa_port_devlink_teardown(dp);
dp->type = DSA_PORT_TYPE_UNUSED;
- err = dsa_port_devlink_setup(dp);
- if (err)
- return err;
-
- if (ds->ops->port_setup) {
- /* On error, leave the devlink port registered,
- * dsa_switch_teardown will clean it up later.
- */
- err = ds->ops->port_setup(ds, dp->index);
- if (err)
- return err;
- }
-
- return 0;
+ return dsa_port_devlink_setup(dp);
}
static int dsa_devlink_info_get(struct devlink *dl,
--
2.35.3
Powered by blists - more mailing lists