Skip to content

Commit 925f5af

Browse files
jpirkodavem330
authored andcommitted
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: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8fb4bc6 commit 925f5af

4 files changed

Lines changed: 38 additions & 13 deletions

File tree

‎drivers/net/netdevsim/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
obj-$(CONFIG_NETDEVSIM) += netdevsim.o
44

55
netdevsim-objs := \
6-
netdev.o dev.o fib.o sdev.o
6+
netdev.o dev.o fib.o sdev.o bus.o
77

88
ifeq ($(CONFIG_BPF_SYSCALL),y)
99
netdevsim-objs += \

‎drivers/net/netdevsim/bus.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright (C) 2017 Netronome Systems, Inc.
3+
* Copyright (C) 2019 Mellanox Technologies. All rights reserved
4+
*/
5+
6+
#include <linux/device.h>
7+
8+
#include "netdevsim.h"
9+
10+
struct bus_type nsim_bus = {
11+
.name = DRV_NAME,
12+
.dev_name = DRV_NAME,
13+
.num_vf = nsim_num_vf,
14+
};
15+
16+
int nsim_bus_init(void)
17+
{
18+
return bus_register(&nsim_bus);
19+
}
20+
21+
void nsim_bus_exit(void)
22+
{
23+
bus_unregister(&nsim_bus);
24+
}

‎drivers/net/netdevsim/netdev.c‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,13 @@ struct nsim_vf_config {
4242

4343
static struct dentry *nsim_ddir;
4444

45-
static int nsim_num_vf(struct device *dev)
45+
int nsim_num_vf(struct device *dev)
4646
{
4747
struct netdevsim *ns = to_nsim(dev);
4848

4949
return ns->num_vfs;
5050
}
5151

52-
static struct bus_type nsim_bus = {
53-
.name = DRV_NAME,
54-
.dev_name = DRV_NAME,
55-
.num_vf = nsim_num_vf,
56-
};
57-
5852
static int nsim_vfs_enable(struct netdevsim *ns, unsigned int num_vfs)
5953
{
6054
ns->vfconfigs = kcalloc(num_vfs, sizeof(struct nsim_vf_config),
@@ -544,18 +538,18 @@ static int __init nsim_module_init(void)
544538
if (err)
545539
goto err_debugfs_destroy;
546540

547-
err = bus_register(&nsim_bus);
541+
err = nsim_bus_init();
548542
if (err)
549543
goto err_sdev_exit;
550544

551545
err = rtnl_link_register(&nsim_link_ops);
552546
if (err)
553-
goto err_unreg_bus;
547+
goto err_bus_exit;
554548

555549
return 0;
556550

557-
err_unreg_bus:
558-
bus_unregister(&nsim_bus);
551+
err_bus_exit:
552+
nsim_bus_exit();
559553
err_sdev_exit:
560554
nsim_sdev_exit();
561555
err_debugfs_destroy:
@@ -566,7 +560,7 @@ static int __init nsim_module_init(void)
566560
static void __exit nsim_module_exit(void)
567561
{
568562
rtnl_link_unregister(&nsim_link_ops);
569-
bus_unregister(&nsim_bus);
563+
nsim_bus_exit();
570564
nsim_sdev_exit();
571565
debugfs_remove_recursive(nsim_ddir);
572566
}

‎drivers/net/netdevsim/netdevsim.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,10 @@ static inline struct netdevsim *to_nsim(struct device *ptr)
188188
{
189189
return container_of(ptr, struct netdevsim, dev);
190190
}
191+
192+
int nsim_num_vf(struct device *dev);
193+
194+
extern struct bus_type nsim_bus;
195+
196+
int nsim_bus_init(void);
197+
void nsim_bus_exit(void);

0 commit comments

Comments
 (0)