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

netdevsim: put netdevsim bus code into separate file

As the code related to netdevsim bus is going to get bigger, move the
existing code to a separate file.
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8fb4bc6f
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
obj-$(CONFIG_NETDEVSIM) += netdevsim.o obj-$(CONFIG_NETDEVSIM) += netdevsim.o
netdevsim-objs := \ netdevsim-objs := \
netdev.o dev.o fib.o sdev.o netdev.o dev.o fib.o sdev.o bus.o
ifeq ($(CONFIG_BPF_SYSCALL),y) ifeq ($(CONFIG_BPF_SYSCALL),y)
netdevsim-objs += \ netdevsim-objs += \
......
// SPDX-License-Identifier: GPL-2.0
/* Copyright (C) 2017 Netronome Systems, Inc.
* Copyright (C) 2019 Mellanox Technologies. All rights reserved
*/
#include <linux/device.h>
#include "netdevsim.h"
struct bus_type nsim_bus = {
.name = DRV_NAME,
.dev_name = DRV_NAME,
.num_vf = nsim_num_vf,
};
int nsim_bus_init(void)
{
return bus_register(&nsim_bus);
}
void nsim_bus_exit(void)
{
bus_unregister(&nsim_bus);
}
...@@ -42,19 +42,13 @@ struct nsim_vf_config { ...@@ -42,19 +42,13 @@ struct nsim_vf_config {
static struct dentry *nsim_ddir; static struct dentry *nsim_ddir;
static int nsim_num_vf(struct device *dev) int nsim_num_vf(struct device *dev)
{ {
struct netdevsim *ns = to_nsim(dev); struct netdevsim *ns = to_nsim(dev);
return ns->num_vfs; return ns->num_vfs;
} }
static struct bus_type nsim_bus = {
.name = DRV_NAME,
.dev_name = DRV_NAME,
.num_vf = nsim_num_vf,
};
static int nsim_vfs_enable(struct netdevsim *ns, unsigned int num_vfs) static int nsim_vfs_enable(struct netdevsim *ns, unsigned int num_vfs)
{ {
ns->vfconfigs = kcalloc(num_vfs, sizeof(struct nsim_vf_config), ns->vfconfigs = kcalloc(num_vfs, sizeof(struct nsim_vf_config),
...@@ -544,18 +538,18 @@ static int __init nsim_module_init(void) ...@@ -544,18 +538,18 @@ static int __init nsim_module_init(void)
if (err) if (err)
goto err_debugfs_destroy; goto err_debugfs_destroy;
err = bus_register(&nsim_bus); err = nsim_bus_init();
if (err) if (err)
goto err_sdev_exit; goto err_sdev_exit;
err = rtnl_link_register(&nsim_link_ops); err = rtnl_link_register(&nsim_link_ops);
if (err) if (err)
goto err_unreg_bus; goto err_bus_exit;
return 0; return 0;
err_unreg_bus: err_bus_exit:
bus_unregister(&nsim_bus); nsim_bus_exit();
err_sdev_exit: err_sdev_exit:
nsim_sdev_exit(); nsim_sdev_exit();
err_debugfs_destroy: err_debugfs_destroy:
...@@ -566,7 +560,7 @@ static int __init nsim_module_init(void) ...@@ -566,7 +560,7 @@ static int __init nsim_module_init(void)
static void __exit nsim_module_exit(void) static void __exit nsim_module_exit(void)
{ {
rtnl_link_unregister(&nsim_link_ops); rtnl_link_unregister(&nsim_link_ops);
bus_unregister(&nsim_bus); nsim_bus_exit();
nsim_sdev_exit(); nsim_sdev_exit();
debugfs_remove_recursive(nsim_ddir); debugfs_remove_recursive(nsim_ddir);
} }
......
...@@ -188,3 +188,10 @@ static inline struct netdevsim *to_nsim(struct device *ptr) ...@@ -188,3 +188,10 @@ static inline struct netdevsim *to_nsim(struct device *ptr)
{ {
return container_of(ptr, struct netdevsim, dev); return container_of(ptr, struct netdevsim, dev);
} }
int nsim_num_vf(struct device *dev);
extern struct bus_type nsim_bus;
int nsim_bus_init(void);
void nsim_bus_exit(void);
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