Commit a60f9e48 authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

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: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f9d9db47
......@@ -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 @@ static int __nsim_dev_init(struct netdevsim *ns)
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);
......
......@@ -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:
......
......@@ -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);
......
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