From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, mlxsw@mellanox.com, jakub.kicinski@netronome.com
Subject: [patch net-next rfc 04/15] netdevsim: put netdevsim bus code into separate file
Date: Sat, 13 Apr 2019 18:21:01 +0200 [thread overview]
Message-ID: <20190413162112.8203-5-jiri@resnulli.us> (raw)
In-Reply-To: <20190413162112.8203-1-jiri@resnulli.us>
From: Jiri Pirko <jiri@mellanox.com>
As the code related to netdevsim bus is going to get bigger, move the
existing code to a separate file.
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
drivers/net/netdevsim/Makefile | 2 +-
drivers/net/netdevsim/bus.c | 24 ++++++++++++++++++++++++
drivers/net/netdevsim/netdev.c | 18 ++++++------------
drivers/net/netdevsim/netdevsim.h | 7 +++++++
4 files changed, 38 insertions(+), 13 deletions(-)
create mode 100644 drivers/net/netdevsim/bus.c
diff --git a/drivers/net/netdevsim/Makefile b/drivers/net/netdevsim/Makefile
index d9486e05f4ea..eea6162f3886 100644
--- a/drivers/net/netdevsim/Makefile
+++ b/drivers/net/netdevsim/Makefile
@@ -3,7 +3,7 @@
obj-$(CONFIG_NETDEVSIM) += netdevsim.o
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)
netdevsim-objs += \
diff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c
new file mode 100644
index 000000000000..26b866b72afc
--- /dev/null
+++ b/drivers/net/netdevsim/bus.c
@@ -0,0 +1,24 @@
+// 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);
+}
diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
index 31fc6564d181..7bc0da8cc10d 100644
--- a/drivers/net/netdevsim/netdev.c
+++ b/drivers/net/netdevsim/netdev.c
@@ -42,19 +42,13 @@ struct nsim_vf_config {
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);
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)
{
ns->vfconfigs = kcalloc(num_vfs, sizeof(struct nsim_vf_config),
@@ -544,18 +538,18 @@ static int __init nsim_module_init(void)
if (err)
goto err_debugfs_destroy;
- err = bus_register(&nsim_bus);
+ err = nsim_bus_init();
if (err)
goto err_sdev_exit;
err = rtnl_link_register(&nsim_link_ops);
if (err)
- goto err_unreg_bus;
+ goto err_bus_exit;
return 0;
-err_unreg_bus:
- bus_unregister(&nsim_bus);
+err_bus_exit:
+ nsim_bus_exit();
err_sdev_exit:
nsim_sdev_exit();
err_debugfs_destroy:
@@ -566,7 +560,7 @@ static int __init nsim_module_init(void)
static void __exit nsim_module_exit(void)
{
rtnl_link_unregister(&nsim_link_ops);
- bus_unregister(&nsim_bus);
+ nsim_bus_exit();
nsim_sdev_exit();
debugfs_remove_recursive(nsim_ddir);
}
diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
index 23d19b461873..7a144aa7965a 100644
--- a/drivers/net/netdevsim/netdevsim.h
+++ b/drivers/net/netdevsim/netdevsim.h
@@ -188,3 +188,10 @@ static inline struct netdevsim *to_nsim(struct device *ptr)
{
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);
--
2.17.2
next prev parent reply other threads:[~2019-04-13 16:21 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-13 16:20 [patch net-next rfc 00/15] netdevsim: impement proper device model Jiri Pirko
2019-04-13 16:20 ` [patch net-next rfc 01/15] netdevsim: move device registration on bus to be done earlier in init Jiri Pirko
2019-04-13 16:20 ` [patch net-next rfc 02/15] netdevsim: create devlink instance per netdevsim instance Jiri Pirko
2019-04-15 2:24 ` David Ahern
2019-04-15 5:41 ` Jiri Pirko
2019-04-15 15:07 ` David Ahern
2019-04-15 15:39 ` Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 03/15] netdevsim: rename devlink.c to dev.c to contain per-dev(asic) items Jiri Pirko
2019-04-13 16:21 ` Jiri Pirko [this message]
2019-04-14 20:27 ` [patch net-next rfc 04/15] netdevsim: put netdevsim bus code into separate file David Miller
2019-04-15 5:40 ` Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 05/15] netdevsim: move device registration and related code to bus.c Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 06/15] netdevsim: add stub netdevsim driver implementation Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 07/15] netdevsim: use ida for bus device ids Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 08/15] netdevsim: add bus attributes to add new and delete devices Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 09/15] netdevsim: rename dev_init/exit() functions and make them independent on ns Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 10/15] netdevsim: merge sdev into dev Jiri Pirko
2019-04-15 20:49 ` Jakub Kicinski
2019-04-16 8:49 ` Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 11/15] netdevsim: generate random switch id instead of using dev id Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 12/15] netdevsim: change debugfs tree topology Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 13/15] netdevsim: implement dev probe/remove skeleton with port initialization Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 14/15] netdevsim: move netdev creation/destruction to dev probe Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 15/15] netdevsim: implement ndo_get_devlink_port Jiri Pirko
2019-04-15 19:27 ` [patch net-next rfc 00/15] netdevsim: impement proper device model Jakub Kicinski
2019-04-16 8:53 ` Jiri Pirko
2019-04-16 17:58 ` Jakub Kicinski
2019-04-16 8:59 ` Jiri Pirko
2019-04-16 18:04 ` Jakub Kicinski
2019-04-18 7:22 ` Jiri Pirko
2019-04-18 17:07 ` Jakub Kicinski
2019-04-19 5:25 ` Jiri Pirko
2019-04-19 21:00 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190413162112.8203-5-jiri@resnulli.us \
--to=jiri@resnulli.us \
--cc=davem@davemloft.net \
--cc=jakub.kicinski@netronome.com \
--cc=mlxsw@mellanox.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).