[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221205152257.454610-3-jiri@resnulli.us>
Date: Mon, 5 Dec 2022 16:22:51 +0100
From: Jiri Pirko <jiri@...nulli.us>
To: netdev@...r.kernel.org
Cc: davem@...emloft.net, kuba@...nel.org, pabeni@...hat.com,
edumazet@...gle.com, michael.chan@...adcom.com,
ioana.ciornei@....com, dmichail@...gible.com,
jesse.brandeburg@...el.com, anthony.l.nguyen@...el.com,
tchornyi@...vell.com, tariqt@...dia.com, saeedm@...dia.com,
leon@...nel.org, idosch@...dia.com, petrm@...dia.com,
vladimir.oltean@....com, claudiu.manoil@....com,
alexandre.belloni@...tlin.com, simon.horman@...igine.com,
shannon.nelson@....com, brett.creeley@....com
Subject: [patch net-next 2/8] netdevsim: call devl_port_register/unregister() on registered instance
From: Jiri Pirko <jiri@...dia.com>
Move the code so devl_port_register/unregister() are called only
then devlink is registered.
Signed-off-by: Jiri Pirko <jiri@...dia.com>
---
RFC->v1:
- shortened patch subject
---
drivers/net/netdevsim/dev.c | 31 +++++++++++++++++++++++++------
1 file changed, 25 insertions(+), 6 deletions(-)
diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c
index b962fc8e1397..8ed235ac986f 100644
--- a/drivers/net/netdevsim/dev.c
+++ b/drivers/net/netdevsim/dev.c
@@ -949,6 +949,7 @@ static void nsim_dev_traps_exit(struct devlink *devlink)
static int nsim_dev_reload_create(struct nsim_dev *nsim_dev,
struct netlink_ext_ack *extack);
+static void nsim_dev_reload_ports_destroy(struct nsim_dev *nsim_dev);
static void nsim_dev_reload_destroy(struct nsim_dev *nsim_dev);
static int nsim_dev_reload_down(struct devlink *devlink, bool netns_change,
@@ -965,6 +966,7 @@ static int nsim_dev_reload_down(struct devlink *devlink, bool netns_change,
return -EOPNOTSUPP;
}
+ nsim_dev_reload_ports_destroy(nsim_dev);
nsim_dev_reload_destroy(nsim_dev);
return 0;
}
@@ -1600,17 +1602,22 @@ int nsim_drv_probe(struct nsim_bus_dev *nsim_bus_dev)
if (err)
goto err_psample_exit;
- err = nsim_dev_port_add_all(nsim_dev, nsim_bus_dev->port_count);
- if (err)
- goto err_hwstats_exit;
-
nsim_dev->esw_mode = DEVLINK_ESWITCH_MODE_LEGACY;
devlink_set_features(devlink, DEVLINK_F_RELOAD);
devl_unlock(devlink);
devlink_register(devlink);
+
+ devl_lock(devlink);
+ err = nsim_dev_port_add_all(nsim_dev, nsim_bus_dev->port_count);
+ devl_unlock(devlink);
+ if (err)
+ goto err_devlink_unregister;
+
return 0;
-err_hwstats_exit:
+err_devlink_unregister:
+ devlink_unregister(devlink);
+ devl_lock(devlink);
nsim_dev_hwstats_exit(nsim_dev);
err_psample_exit:
nsim_dev_psample_exit(nsim_dev);
@@ -1640,6 +1647,15 @@ int nsim_drv_probe(struct nsim_bus_dev *nsim_bus_dev)
return err;
}
+static void nsim_dev_reload_ports_destroy(struct nsim_dev *nsim_dev)
+{
+ struct devlink *devlink = priv_to_devlink(nsim_dev);
+
+ if (devlink_is_reload_failed(devlink))
+ return;
+ nsim_dev_port_del_all(nsim_dev);
+}
+
static void nsim_dev_reload_destroy(struct nsim_dev *nsim_dev)
{
struct devlink *devlink = priv_to_devlink(nsim_dev);
@@ -1654,7 +1670,6 @@ static void nsim_dev_reload_destroy(struct nsim_dev *nsim_dev)
nsim_esw_legacy_enable(nsim_dev, NULL);
}
- nsim_dev_port_del_all(nsim_dev);
nsim_dev_hwstats_exit(nsim_dev);
nsim_dev_psample_exit(nsim_dev);
nsim_dev_health_exit(nsim_dev);
@@ -1668,6 +1683,10 @@ void nsim_drv_remove(struct nsim_bus_dev *nsim_bus_dev)
struct nsim_dev *nsim_dev = dev_get_drvdata(&nsim_bus_dev->dev);
struct devlink *devlink = priv_to_devlink(nsim_dev);
+ devl_lock(devlink);
+ nsim_dev_reload_ports_destroy(nsim_dev);
+ devl_unlock(devlink);
+
devlink_unregister(devlink);
devl_lock(devlink);
nsim_dev_reload_destroy(nsim_dev);
--
2.37.3
Powered by blists - more mailing lists