summaryrefslogtreecommitdiffstats
path: root/drivers/net/netdevsim
diff options
context:
space:
mode:
authorJiri Pirko <jiri@mellanox.com>2019-04-25 15:59:49 +0200
committerDavid S. Miller <davem@davemloft.net>2019-04-26 07:52:02 +0200
commita60f9e48b7707b70a0701dd841e43492e1e68371 (patch)
tree7118ee84a693fcd6aeb52a0a7cc8f04afc955d23 /drivers/net/netdevsim
parentnetdevsim: add bus attributes to add new and delete devices (diff)
downloadlinux-a60f9e48b7707b70a0701dd841e43492e1e68371.tar.xz
linux-a60f9e48b7707b70a0701dd841e43492e1e68371.zip
netdevsim: rename dev_init/exit() functions and make them independent on ns
These functions are going to be called from bus probe/release(), therefore make them independent on ns struct and rename accordingly. Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/netdevsim')
-rw-r--r--drivers/net/netdevsim/dev.c32
-rw-r--r--drivers/net/netdevsim/netdev.c14
-rw-r--r--drivers/net/netdevsim/netdevsim.h12
3 files changed, 30 insertions, 28 deletions
diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c
index c83c08edf94f..664b9329a65c 100644
--- a/drivers/net/netdevsim/dev.c
+++ b/drivers/net/netdevsim/dev.c
@@ -21,10 +21,6 @@
#include "netdevsim.h"
-struct nsim_dev {
- struct nsim_fib_data *fib_data;
-};
-
static u64 nsim_dev_ipv4_fib_resource_occ_get(void *priv)
{
struct nsim_dev *nsim_dev = priv;
@@ -178,7 +174,7 @@ static const struct devlink_ops nsim_dev_devlink_ops = {
.reload = nsim_dev_reload,
};
-static int __nsim_dev_init(struct netdevsim *ns)
+static struct nsim_dev *nsim_dev_create(struct nsim_bus_dev *nsim_bus_dev)
{
struct nsim_dev *nsim_dev;
struct devlink *devlink;
@@ -186,7 +182,7 @@ static int __nsim_dev_init(struct netdevsim *ns)
devlink = devlink_alloc(&nsim_dev_devlink_ops, sizeof(*nsim_dev));
if (!devlink)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
nsim_dev = devlink_priv(devlink);
nsim_dev->fib_data = nsim_fib_create();
@@ -199,13 +195,11 @@ static int __nsim_dev_init(struct netdevsim *ns)
if (err)
goto err_fib_destroy;
- err = devlink_register(devlink, &ns->nsim_bus_dev->dev);
+ err = devlink_register(devlink, &nsim_bus_dev->dev);
if (err)
goto err_resources_unregister;
- ns->devlink = devlink;
-
- return 0;
+ return nsim_dev;
err_resources_unregister:
devlink_resources_unregister(devlink, NULL);
@@ -213,26 +207,26 @@ err_fib_destroy:
nsim_fib_destroy(nsim_dev->fib_data);
err_devlink_free:
devlink_free(devlink);
-
- return err;
+ return ERR_PTR(err);
}
-int nsim_dev_init(struct netdevsim *ns)
+struct nsim_dev *
+nsim_dev_create_with_ns(struct nsim_bus_dev *nsim_bus_dev,
+ struct netdevsim *ns)
{
- int err;
+ struct nsim_dev *nsim_dev;
dev_hold(ns->netdev);
rtnl_unlock();
- err = __nsim_dev_init(ns);
+ nsim_dev = nsim_dev_create(nsim_bus_dev);
rtnl_lock();
dev_put(ns->netdev);
- return err;
+ return nsim_dev;
}
-void nsim_dev_exit(struct netdevsim *ns)
+void nsim_dev_destroy(struct nsim_dev *nsim_dev)
{
- struct devlink *devlink = ns->devlink;
- struct nsim_dev *nsim_dev = devlink_priv(devlink);
+ struct devlink *devlink = priv_to_devlink(nsim_dev);
devlink_unregister(devlink);
devlink_resources_unregister(devlink, NULL);
diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
index 37a442ffcb8b..28231bfbc989 100644
--- a/drivers/net/netdevsim/netdev.c
+++ b/drivers/net/netdevsim/netdev.c
@@ -77,7 +77,7 @@ static void nsim_free(struct net_device *dev)
{
struct netdevsim *ns = netdev_priv(dev);
- nsim_dev_exit(ns);
+ nsim_dev_destroy(ns->nsim_dev);
nsim_bus_dev_del(ns->nsim_bus_dev);
/* netdev and vf state will be freed out of device_release() */
nsim_sdev_put(ns->sdev);
@@ -395,17 +395,19 @@ static int nsim_newlink(struct net *src_net, struct net_device *dev,
SET_NETDEV_DEV(dev, &ns->nsim_bus_dev->dev);
ns->netdev = dev;
- err = nsim_dev_init(ns);
- if (err)
+ ns->nsim_dev = nsim_dev_create_with_ns(ns->nsim_bus_dev, ns);
+ if (IS_ERR(ns->nsim_dev)) {
+ err = PTR_ERR(ns->nsim_dev);
goto err_dev_del;
+ }
err = register_netdevice(dev);
if (err)
- goto err_dev_exit;
+ goto err_dev_destroy;
return 0;
-err_dev_exit:
- nsim_dev_exit(ns);
+err_dev_destroy:
+ nsim_dev_destroy(ns->nsim_dev);
err_dev_del:
nsim_bus_dev_del(ns->nsim_bus_dev);
err_sdev_put:
diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
index 8d61fcb55f39..d6b3668f9afd 100644
--- a/drivers/net/netdevsim/netdevsim.h
+++ b/drivers/net/netdevsim/netdevsim.h
@@ -80,6 +80,7 @@ struct nsim_ipsec {
struct netdevsim {
struct net_device *netdev;
+ struct nsim_dev *nsim_dev;
u64 tx_packets;
u64 tx_bytes;
@@ -102,7 +103,6 @@ struct netdevsim {
bool bpf_xdpoffload_accept;
bool bpf_map_accept;
- struct devlink *devlink;
struct nsim_ipsec ipsec;
};
@@ -151,8 +151,14 @@ enum nsim_resource_id {
NSIM_RESOURCE_IPV6_FIB_RULES,
};
-int nsim_dev_init(struct netdevsim *ns);
-void nsim_dev_exit(struct netdevsim *ns);
+struct nsim_dev {
+ struct nsim_fib_data *fib_data;
+};
+
+struct nsim_dev *
+nsim_dev_create_with_ns(struct nsim_bus_dev *nsim_bus_dev,
+ struct netdevsim *ns);
+void nsim_dev_destroy(struct nsim_dev *nsim_dev);
struct nsim_fib_data *nsim_fib_create(void);
void nsim_fib_destroy(struct nsim_fib_data *fib_data);