#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;
.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;
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();
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);
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);
{
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);
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:
struct netdevsim {
struct net_device *netdev;
+ struct nsim_dev *nsim_dev;
u64 tx_packets;
u64 tx_bytes;
bool bpf_xdpoffload_accept;
bool bpf_map_accept;
- struct devlink *devlink;
struct nsim_ipsec ipsec;
};
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);