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

netdevsim: merge sdev into dev

As previously introduce dev which is mapped 1:1 to a bus device covers
the purpose of the original shared device, merge the sdev code into dev.
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a60f9e48
...@@ -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 bus.o netdev.o dev.o fib.o bus.o
ifeq ($(CONFIG_BPF_SYSCALL),y) ifeq ($(CONFIG_BPF_SYSCALL),y)
netdevsim-objs += \ netdevsim-objs += \
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
bpf_verifier_log_write(env, "[netdevsim] " fmt, ##__VA_ARGS__) bpf_verifier_log_write(env, "[netdevsim] " fmt, ##__VA_ARGS__)
struct nsim_bpf_bound_prog { struct nsim_bpf_bound_prog {
struct netdevsim_shared_dev *sdev; struct nsim_dev *nsim_dev;
struct bpf_prog *prog; struct bpf_prog *prog;
struct dentry *ddir; struct dentry *ddir;
const char *state; const char *state;
...@@ -65,8 +65,8 @@ nsim_bpf_verify_insn(struct bpf_verifier_env *env, int insn_idx, int prev_insn) ...@@ -65,8 +65,8 @@ nsim_bpf_verify_insn(struct bpf_verifier_env *env, int insn_idx, int prev_insn)
struct nsim_bpf_bound_prog *state; struct nsim_bpf_bound_prog *state;
state = env->prog->aux->offload->dev_priv; state = env->prog->aux->offload->dev_priv;
if (state->sdev->bpf_bind_verifier_delay && !insn_idx) if (state->nsim_dev->bpf_bind_verifier_delay && !insn_idx)
msleep(state->sdev->bpf_bind_verifier_delay); msleep(state->nsim_dev->bpf_bind_verifier_delay);
if (insn_idx == env->prog->len - 1) if (insn_idx == env->prog->len - 1)
pr_vlog(env, "Hello from netdevsim!\n"); pr_vlog(env, "Hello from netdevsim!\n");
...@@ -213,7 +213,7 @@ nsim_xdp_set_prog(struct netdevsim *ns, struct netdev_bpf *bpf, ...@@ -213,7 +213,7 @@ nsim_xdp_set_prog(struct netdevsim *ns, struct netdev_bpf *bpf,
return 0; return 0;
} }
static int nsim_bpf_create_prog(struct netdevsim_shared_dev *sdev, static int nsim_bpf_create_prog(struct nsim_dev *nsim_dev,
struct bpf_prog *prog) struct bpf_prog *prog)
{ {
struct nsim_bpf_bound_prog *state; struct nsim_bpf_bound_prog *state;
...@@ -223,13 +223,13 @@ static int nsim_bpf_create_prog(struct netdevsim_shared_dev *sdev, ...@@ -223,13 +223,13 @@ static int nsim_bpf_create_prog(struct netdevsim_shared_dev *sdev,
if (!state) if (!state)
return -ENOMEM; return -ENOMEM;
state->sdev = sdev; state->nsim_dev = nsim_dev;
state->prog = prog; state->prog = prog;
state->state = "verify"; state->state = "verify";
/* Program id is not populated yet when we create the state. */ /* Program id is not populated yet when we create the state. */
sprintf(name, "%u", sdev->prog_id_gen++); sprintf(name, "%u", nsim_dev->prog_id_gen++);
state->ddir = debugfs_create_dir(name, sdev->ddir_bpf_bound_progs); state->ddir = debugfs_create_dir(name, nsim_dev->ddir_bpf_bound_progs);
if (IS_ERR_OR_NULL(state->ddir)) { if (IS_ERR_OR_NULL(state->ddir)) {
kfree(state); kfree(state);
return -ENOMEM; return -ENOMEM;
...@@ -240,7 +240,7 @@ static int nsim_bpf_create_prog(struct netdevsim_shared_dev *sdev, ...@@ -240,7 +240,7 @@ static int nsim_bpf_create_prog(struct netdevsim_shared_dev *sdev,
&state->state, &nsim_bpf_string_fops); &state->state, &nsim_bpf_string_fops);
debugfs_create_bool("loaded", 0400, state->ddir, &state->is_loaded); debugfs_create_bool("loaded", 0400, state->ddir, &state->is_loaded);
list_add_tail(&state->l, &sdev->bpf_bound_progs); list_add_tail(&state->l, &nsim_dev->bpf_bound_progs);
prog->aux->offload->dev_priv = state; prog->aux->offload->dev_priv = state;
...@@ -249,13 +249,13 @@ static int nsim_bpf_create_prog(struct netdevsim_shared_dev *sdev, ...@@ -249,13 +249,13 @@ static int nsim_bpf_create_prog(struct netdevsim_shared_dev *sdev,
static int nsim_bpf_verifier_prep(struct bpf_prog *prog) static int nsim_bpf_verifier_prep(struct bpf_prog *prog)
{ {
struct netdevsim_shared_dev *sdev = struct nsim_dev *nsim_dev =
bpf_offload_dev_priv(prog->aux->offload->offdev); bpf_offload_dev_priv(prog->aux->offload->offdev);
if (!sdev->bpf_bind_accept) if (!nsim_dev->bpf_bind_accept)
return -EOPNOTSUPP; return -EOPNOTSUPP;
return nsim_bpf_create_prog(sdev, prog); return nsim_bpf_create_prog(nsim_dev, prog);
} }
static int nsim_bpf_translate(struct bpf_prog *prog) static int nsim_bpf_translate(struct bpf_prog *prog)
...@@ -514,7 +514,7 @@ nsim_bpf_map_alloc(struct netdevsim *ns, struct bpf_offloaded_map *offmap) ...@@ -514,7 +514,7 @@ nsim_bpf_map_alloc(struct netdevsim *ns, struct bpf_offloaded_map *offmap)
} }
offmap->dev_ops = &nsim_bpf_map_ops; offmap->dev_ops = &nsim_bpf_map_ops;
list_add_tail(&nmap->l, &ns->sdev->bpf_bound_maps); list_add_tail(&nmap->l, &ns->nsim_dev->bpf_bound_maps);
return 0; return 0;
...@@ -578,51 +578,46 @@ int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf) ...@@ -578,51 +578,46 @@ int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf)
} }
} }
static int nsim_bpf_sdev_init(struct netdevsim_shared_dev *sdev) int nsim_bpf_dev_init(struct nsim_dev *nsim_dev)
{ {
int err; int err;
INIT_LIST_HEAD(&sdev->bpf_bound_progs); INIT_LIST_HEAD(&nsim_dev->bpf_bound_progs);
INIT_LIST_HEAD(&sdev->bpf_bound_maps); INIT_LIST_HEAD(&nsim_dev->bpf_bound_maps);
sdev->ddir_bpf_bound_progs = nsim_dev->ddir_bpf_bound_progs = debugfs_create_dir("bpf_bound_progs",
debugfs_create_dir("bpf_bound_progs", sdev->ddir); nsim_dev->ddir);
if (IS_ERR_OR_NULL(sdev->ddir_bpf_bound_progs)) if (IS_ERR_OR_NULL(nsim_dev->ddir_bpf_bound_progs))
return -ENOMEM; return -ENOMEM;
sdev->bpf_dev = bpf_offload_dev_create(&nsim_bpf_dev_ops, sdev); nsim_dev->bpf_dev = bpf_offload_dev_create(&nsim_bpf_dev_ops, nsim_dev);
err = PTR_ERR_OR_ZERO(sdev->bpf_dev); err = PTR_ERR_OR_ZERO(nsim_dev->bpf_dev);
if (err) if (err)
return err; return err;
sdev->bpf_bind_accept = true; nsim_dev->bpf_bind_accept = true;
debugfs_create_bool("bpf_bind_accept", 0600, sdev->ddir, debugfs_create_bool("bpf_bind_accept", 0600, nsim_dev->ddir,
&sdev->bpf_bind_accept); &nsim_dev->bpf_bind_accept);
debugfs_create_u32("bpf_bind_verifier_delay", 0600, sdev->ddir, debugfs_create_u32("bpf_bind_verifier_delay", 0600, nsim_dev->ddir,
&sdev->bpf_bind_verifier_delay); &nsim_dev->bpf_bind_verifier_delay);
return 0; return 0;
} }
static void nsim_bpf_sdev_uninit(struct netdevsim_shared_dev *sdev) void nsim_bpf_dev_exit(struct nsim_dev *nsim_dev)
{ {
WARN_ON(!list_empty(&sdev->bpf_bound_progs)); WARN_ON(!list_empty(&nsim_dev->bpf_bound_progs));
WARN_ON(!list_empty(&sdev->bpf_bound_maps)); WARN_ON(!list_empty(&nsim_dev->bpf_bound_maps));
bpf_offload_dev_destroy(sdev->bpf_dev); bpf_offload_dev_destroy(nsim_dev->bpf_dev);
} }
int nsim_bpf_init(struct netdevsim *ns) int nsim_bpf_init(struct netdevsim *ns)
{ {
int err; int err;
if (ns->sdev->refcnt == 1) { err = bpf_offload_dev_netdev_register(ns->nsim_dev->bpf_dev,
err = nsim_bpf_sdev_init(ns->sdev); ns->netdev);
if (err) if (err)
return err; return err;
}
err = bpf_offload_dev_netdev_register(ns->sdev->bpf_dev, ns->netdev);
if (err)
goto err_bpf_sdev_uninit;
debugfs_create_u32("bpf_offloaded_id", 0400, ns->ddir, debugfs_create_u32("bpf_offloaded_id", 0400, ns->ddir,
&ns->bpf_offloaded_id); &ns->bpf_offloaded_id);
...@@ -644,11 +639,6 @@ int nsim_bpf_init(struct netdevsim *ns) ...@@ -644,11 +639,6 @@ int nsim_bpf_init(struct netdevsim *ns)
&ns->bpf_map_accept); &ns->bpf_map_accept);
return 0; return 0;
err_bpf_sdev_uninit:
if (ns->sdev->refcnt == 1)
nsim_bpf_sdev_uninit(ns->sdev);
return err;
} }
void nsim_bpf_uninit(struct netdevsim *ns) void nsim_bpf_uninit(struct netdevsim *ns)
...@@ -656,8 +646,5 @@ void nsim_bpf_uninit(struct netdevsim *ns) ...@@ -656,8 +646,5 @@ void nsim_bpf_uninit(struct netdevsim *ns)
WARN_ON(ns->xdp.prog); WARN_ON(ns->xdp.prog);
WARN_ON(ns->xdp_hw.prog); WARN_ON(ns->xdp_hw.prog);
WARN_ON(ns->bpf_offloaded); WARN_ON(ns->bpf_offloaded);
bpf_offload_dev_netdev_unregister(ns->sdev->bpf_dev, ns->netdev); bpf_offload_dev_netdev_unregister(ns->nsim_dev->bpf_dev, ns->netdev);
if (ns->sdev->refcnt == 1)
nsim_bpf_sdev_uninit(ns->sdev);
} }
...@@ -15,12 +15,31 @@ ...@@ -15,12 +15,31 @@
* THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. * THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
*/ */
#include <linux/debugfs.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/rtnetlink.h> #include <linux/rtnetlink.h>
#include <net/devlink.h> #include <net/devlink.h>
#include "netdevsim.h" #include "netdevsim.h"
static struct dentry *nsim_dev_ddir;
static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev)
{
char dev_ddir_name[10];
sprintf(dev_ddir_name, "%u", nsim_dev->nsim_bus_dev->dev.id);
nsim_dev->ddir = debugfs_create_dir(dev_ddir_name, nsim_dev_ddir);
if (IS_ERR_OR_NULL(nsim_dev->ddir))
return PTR_ERR_OR_ZERO(nsim_dev->ddir) ?: -EINVAL;
return 0;
}
static void nsim_dev_debugfs_exit(struct nsim_dev *nsim_dev)
{
debugfs_remove_recursive(nsim_dev->ddir);
}
static u64 nsim_dev_ipv4_fib_resource_occ_get(void *priv) static u64 nsim_dev_ipv4_fib_resource_occ_get(void *priv)
{ {
struct nsim_dev *nsim_dev = priv; struct nsim_dev *nsim_dev = priv;
...@@ -184,6 +203,7 @@ static struct nsim_dev *nsim_dev_create(struct nsim_bus_dev *nsim_bus_dev) ...@@ -184,6 +203,7 @@ static struct nsim_dev *nsim_dev_create(struct nsim_bus_dev *nsim_bus_dev)
if (!devlink) if (!devlink)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
nsim_dev = devlink_priv(devlink); nsim_dev = devlink_priv(devlink);
nsim_dev->nsim_bus_dev = nsim_bus_dev;
nsim_dev->fib_data = nsim_fib_create(); nsim_dev->fib_data = nsim_fib_create();
if (IS_ERR(nsim_dev->fib_data)) { if (IS_ERR(nsim_dev->fib_data)) {
...@@ -199,8 +219,20 @@ static struct nsim_dev *nsim_dev_create(struct nsim_bus_dev *nsim_bus_dev) ...@@ -199,8 +219,20 @@ static struct nsim_dev *nsim_dev_create(struct nsim_bus_dev *nsim_bus_dev)
if (err) if (err)
goto err_resources_unregister; goto err_resources_unregister;
err = nsim_dev_debugfs_init(nsim_dev);
if (err)
goto err_dl_unregister;
err = nsim_bpf_dev_init(nsim_dev);
if (err)
goto err_debugfs_exit;
return nsim_dev; return nsim_dev;
err_debugfs_exit:
nsim_dev_debugfs_exit(nsim_dev);
err_dl_unregister:
devlink_unregister(devlink);
err_resources_unregister: err_resources_unregister:
devlink_resources_unregister(devlink, NULL); devlink_resources_unregister(devlink, NULL);
err_fib_destroy: err_fib_destroy:
...@@ -228,8 +260,23 @@ void nsim_dev_destroy(struct nsim_dev *nsim_dev) ...@@ -228,8 +260,23 @@ void nsim_dev_destroy(struct nsim_dev *nsim_dev)
{ {
struct devlink *devlink = priv_to_devlink(nsim_dev); struct devlink *devlink = priv_to_devlink(nsim_dev);
nsim_bpf_dev_exit(nsim_dev);
nsim_dev_debugfs_exit(nsim_dev);
devlink_unregister(devlink); devlink_unregister(devlink);
devlink_resources_unregister(devlink, NULL); devlink_resources_unregister(devlink, NULL);
nsim_fib_destroy(nsim_dev->fib_data); nsim_fib_destroy(nsim_dev->fib_data);
devlink_free(devlink); devlink_free(devlink);
} }
int nsim_dev_init(void)
{
nsim_dev_ddir = debugfs_create_dir(DRV_NAME "_dev", NULL);
if (IS_ERR_OR_NULL(nsim_dev_ddir))
return -ENOMEM;
return 0;
}
void nsim_dev_exit(void)
{
debugfs_remove_recursive(nsim_dev_ddir);
}
...@@ -32,24 +32,24 @@ static int nsim_get_port_parent_id(struct net_device *dev, ...@@ -32,24 +32,24 @@ static int nsim_get_port_parent_id(struct net_device *dev,
{ {
struct netdevsim *ns = netdev_priv(dev); struct netdevsim *ns = netdev_priv(dev);
ppid->id_len = sizeof(ns->sdev->switch_id); ppid->id_len = sizeof(ns->nsim_dev->nsim_bus_dev->dev.id);
memcpy(&ppid->id, &ns->sdev->switch_id, ppid->id_len); memcpy(&ppid->id, &ns->nsim_dev->nsim_bus_dev->dev.id, ppid->id_len);
return 0; return 0;
} }
static int nsim_init(struct net_device *dev) static int nsim_init(struct net_device *dev)
{ {
struct netdevsim *ns = netdev_priv(dev); struct netdevsim *ns = netdev_priv(dev);
char sdev_link_name[32]; char dev_link_name[32];
int err; int err;
ns->ddir = debugfs_create_dir(netdev_name(dev), nsim_ddir); ns->ddir = debugfs_create_dir(netdev_name(dev), nsim_ddir);
if (IS_ERR_OR_NULL(ns->ddir)) if (IS_ERR_OR_NULL(ns->ddir))
return -ENOMEM; return -ENOMEM;
sprintf(sdev_link_name, "../../" DRV_NAME "_sdev/%u", sprintf(dev_link_name, "../../" DRV_NAME "_dev/%u",
ns->sdev->switch_id); ns->nsim_dev->nsim_bus_dev->dev.id);
debugfs_create_symlink("sdev", ns->ddir, sdev_link_name); debugfs_create_symlink("dev", ns->ddir, dev_link_name);
err = nsim_bpf_init(ns); err = nsim_bpf_init(ns);
if (err) if (err)
...@@ -80,7 +80,6 @@ static void nsim_free(struct net_device *dev) ...@@ -80,7 +80,6 @@ static void nsim_free(struct net_device *dev)
nsim_dev_destroy(ns->nsim_dev); nsim_dev_destroy(ns->nsim_dev);
nsim_bus_dev_del(ns->nsim_bus_dev); nsim_bus_dev_del(ns->nsim_bus_dev);
/* netdev and vf state will be freed out of device_release() */ /* netdev and vf state will be freed out of device_release() */
nsim_sdev_put(ns->sdev);
} }
static netdev_tx_t nsim_start_xmit(struct sk_buff *skb, struct net_device *dev) static netdev_tx_t nsim_start_xmit(struct sk_buff *skb, struct net_device *dev)
...@@ -366,31 +365,11 @@ static int nsim_newlink(struct net *src_net, struct net_device *dev, ...@@ -366,31 +365,11 @@ static int nsim_newlink(struct net *src_net, struct net_device *dev,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct netdevsim *ns = netdev_priv(dev); struct netdevsim *ns = netdev_priv(dev);
struct netdevsim *joinns = NULL;
int err; int err;
if (tb[IFLA_LINK]) {
struct net_device *joindev;
joindev = __dev_get_by_index(src_net,
nla_get_u32(tb[IFLA_LINK]));
if (!joindev)
return -ENODEV;
if (joindev->netdev_ops != &nsim_netdev_ops)
return -EINVAL;
joinns = netdev_priv(joindev);
}
ns->sdev = nsim_sdev_get(joinns);
if (IS_ERR(ns->sdev))
return PTR_ERR(ns->sdev);
ns->nsim_bus_dev = nsim_bus_dev_new(~0, 0); ns->nsim_bus_dev = nsim_bus_dev_new(~0, 0);
if (IS_ERR(ns->nsim_bus_dev)) { if (IS_ERR(ns->nsim_bus_dev))
err = PTR_ERR(ns->nsim_bus_dev); return PTR_ERR(ns->nsim_bus_dev);
goto err_sdev_put;
}
SET_NETDEV_DEV(dev, &ns->nsim_bus_dev->dev); SET_NETDEV_DEV(dev, &ns->nsim_bus_dev->dev);
ns->netdev = dev; ns->netdev = dev;
...@@ -410,8 +389,6 @@ static int nsim_newlink(struct net *src_net, struct net_device *dev, ...@@ -410,8 +389,6 @@ static int nsim_newlink(struct net *src_net, struct net_device *dev,
nsim_dev_destroy(ns->nsim_dev); nsim_dev_destroy(ns->nsim_dev);
err_dev_del: err_dev_del:
nsim_bus_dev_del(ns->nsim_bus_dev); nsim_bus_dev_del(ns->nsim_bus_dev);
err_sdev_put:
nsim_sdev_put(ns->sdev);
return err; return err;
} }
...@@ -431,13 +408,13 @@ static int __init nsim_module_init(void) ...@@ -431,13 +408,13 @@ static int __init nsim_module_init(void)
if (IS_ERR_OR_NULL(nsim_ddir)) if (IS_ERR_OR_NULL(nsim_ddir))
return -ENOMEM; return -ENOMEM;
err = nsim_sdev_init(); err = nsim_dev_init();
if (err) if (err)
goto err_debugfs_destroy; goto err_debugfs_destroy;
err = nsim_bus_init(); err = nsim_bus_init();
if (err) if (err)
goto err_sdev_exit; goto err_dev_exit;
err = rtnl_link_register(&nsim_link_ops); err = rtnl_link_register(&nsim_link_ops);
if (err) if (err)
...@@ -447,8 +424,8 @@ static int __init nsim_module_init(void) ...@@ -447,8 +424,8 @@ static int __init nsim_module_init(void)
err_bus_exit: err_bus_exit:
nsim_bus_exit(); nsim_bus_exit();
err_sdev_exit: err_dev_exit:
nsim_sdev_exit(); nsim_dev_exit();
err_debugfs_destroy: err_debugfs_destroy:
debugfs_remove_recursive(nsim_ddir); debugfs_remove_recursive(nsim_ddir);
return err; return err;
...@@ -458,7 +435,7 @@ static void __exit nsim_module_exit(void) ...@@ -458,7 +435,7 @@ static void __exit nsim_module_exit(void)
{ {
rtnl_link_unregister(&nsim_link_ops); rtnl_link_unregister(&nsim_link_ops);
nsim_bus_exit(); nsim_bus_exit();
nsim_sdev_exit(); nsim_dev_exit();
debugfs_remove_recursive(nsim_ddir); debugfs_remove_recursive(nsim_ddir);
} }
......
...@@ -26,37 +26,6 @@ ...@@ -26,37 +26,6 @@
#define NSIM_EA(extack, msg) NL_SET_ERR_MSG_MOD((extack), msg) #define NSIM_EA(extack, msg) NL_SET_ERR_MSG_MOD((extack), msg)
struct bpf_prog;
struct bpf_offload_dev;
struct dentry;
struct nsim_vf_config;
struct nsim_fib_data;
struct netdevsim_shared_dev {
unsigned int refcnt;
u32 switch_id;
struct dentry *ddir;
struct bpf_offload_dev *bpf_dev;
bool bpf_bind_accept;
u32 bpf_bind_verifier_delay;
struct dentry *ddir_bpf_bound_progs;
u32 prog_id_gen;
struct list_head bpf_bound_progs;
struct list_head bpf_bound_maps;
};
struct netdevsim;
struct netdevsim_shared_dev *nsim_sdev_get(struct netdevsim *joinns);
void nsim_sdev_put(struct netdevsim_shared_dev *sdev);
int nsim_sdev_init(void);
void nsim_sdev_exit(void);
#define NSIM_IPSEC_MAX_SA_COUNT 33 #define NSIM_IPSEC_MAX_SA_COUNT 33
#define NSIM_IPSEC_VALID BIT(31) #define NSIM_IPSEC_VALID BIT(31)
...@@ -87,7 +56,6 @@ struct netdevsim { ...@@ -87,7 +56,6 @@ struct netdevsim {
struct u64_stats_sync syncp; struct u64_stats_sync syncp;
struct nsim_bus_dev *nsim_bus_dev; struct nsim_bus_dev *nsim_bus_dev;
struct netdevsim_shared_dev *sdev;
struct dentry *ddir; struct dentry *ddir;
...@@ -107,6 +75,8 @@ struct netdevsim { ...@@ -107,6 +75,8 @@ struct netdevsim {
}; };
#ifdef CONFIG_BPF_SYSCALL #ifdef CONFIG_BPF_SYSCALL
int nsim_bpf_dev_init(struct nsim_dev *nsim_dev);
void nsim_bpf_dev_exit(struct nsim_dev *nsim_dev);
int nsim_bpf_init(struct netdevsim *ns); int nsim_bpf_init(struct netdevsim *ns);
void nsim_bpf_uninit(struct netdevsim *ns); void nsim_bpf_uninit(struct netdevsim *ns);
int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf); int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf);
...@@ -114,6 +84,15 @@ int nsim_bpf_disable_tc(struct netdevsim *ns); ...@@ -114,6 +84,15 @@ int nsim_bpf_disable_tc(struct netdevsim *ns);
int nsim_bpf_setup_tc_block_cb(enum tc_setup_type type, int nsim_bpf_setup_tc_block_cb(enum tc_setup_type type,
void *type_data, void *cb_priv); void *type_data, void *cb_priv);
#else #else
static inline int nsim_bpf_dev_init(struct nsim_dev *nsim_dev)
{
return 0;
}
static inline void nsim_bpf_dev_exit(struct nsim_dev *nsim_dev)
{
}
static inline int nsim_bpf_init(struct netdevsim *ns) static inline int nsim_bpf_init(struct netdevsim *ns)
{ {
return 0; return 0;
...@@ -152,13 +131,24 @@ enum nsim_resource_id { ...@@ -152,13 +131,24 @@ enum nsim_resource_id {
}; };
struct nsim_dev { struct nsim_dev {
struct nsim_bus_dev *nsim_bus_dev;
struct nsim_fib_data *fib_data; struct nsim_fib_data *fib_data;
struct dentry *ddir;
struct bpf_offload_dev *bpf_dev;
bool bpf_bind_accept;
u32 bpf_bind_verifier_delay;
struct dentry *ddir_bpf_bound_progs;
u32 prog_id_gen;
struct list_head bpf_bound_progs;
struct list_head bpf_bound_maps;
}; };
struct nsim_dev * struct nsim_dev *
nsim_dev_create_with_ns(struct nsim_bus_dev *nsim_bus_dev, nsim_dev_create_with_ns(struct nsim_bus_dev *nsim_bus_dev,
struct netdevsim *ns); struct netdevsim *ns);
void nsim_dev_destroy(struct nsim_dev *nsim_dev); void nsim_dev_destroy(struct nsim_dev *nsim_dev);
int nsim_dev_init(void);
void nsim_dev_exit(void);
struct nsim_fib_data *nsim_fib_create(void); struct nsim_fib_data *nsim_fib_create(void);
void nsim_fib_destroy(struct nsim_fib_data *fib_data); void nsim_fib_destroy(struct nsim_fib_data *fib_data);
......
...@@ -335,7 +335,7 @@ class NetdevSim: ...@@ -335,7 +335,7 @@ class NetdevSim:
self.ns = "" self.ns = ""
self.dfs_dir = '/sys/kernel/debug/netdevsim/%s' % (self.dev['ifname']) self.dfs_dir = '/sys/kernel/debug/netdevsim/%s' % (self.dev['ifname'])
self.sdev_dir = self.dfs_dir + '/sdev/' self.dev_dir = self.dfs_dir + '/dev/'
self.dfs_refresh() self.dfs_refresh()
def __getitem__(self, key): def __getitem__(self, key):
...@@ -368,12 +368,12 @@ class NetdevSim: ...@@ -368,12 +368,12 @@ class NetdevSim:
return data.strip() return data.strip()
def dfs_num_bound_progs(self): def dfs_num_bound_progs(self):
path = os.path.join(self.sdev_dir, "bpf_bound_progs") path = os.path.join(self.dev_dir, "bpf_bound_progs")
_, progs = cmd('ls %s' % (path)) _, progs = cmd('ls %s' % (path))
return len(progs.split()) return len(progs.split())
def dfs_get_bound_progs(self, expected): def dfs_get_bound_progs(self, expected):
progs = DebugfsDir(os.path.join(self.sdev_dir, "bpf_bound_progs")) progs = DebugfsDir(os.path.join(self.dev_dir, "bpf_bound_progs"))
if expected is not None: if expected is not None:
if len(progs) != expected: if len(progs) != expected:
fail(True, "%d BPF programs bound, expected %d" % fail(True, "%d BPF programs bound, expected %d" %
...@@ -1055,7 +1055,7 @@ try: ...@@ -1055,7 +1055,7 @@ try:
start_test("Test if netdev removal waits for translation...") start_test("Test if netdev removal waits for translation...")
delay_msec = 500 delay_msec = 500
sim.dfs["sdev/bpf_bind_verifier_delay"] = delay_msec sim.dfs["dev/bpf_bind_verifier_delay"] = delay_msec
start = time.time() start = time.time()
cmd_line = "tc filter add dev %s ingress bpf %s da skip_sw" % \ cmd_line = "tc filter add dev %s ingress bpf %s da skip_sw" % \
(sim['ifname'], obj) (sim['ifname'], obj)
......
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