summaryrefslogtreecommitdiff
path: root/drivers/net/netdevsim/bpf.c
diff options
context:
space:
mode:
authorJiri Pirko <jiri@mellanox.com>2019-04-25 15:59:50 +0200
committerDavid S. Miller <davem@davemloft.net>2019-04-26 01:52:02 -0400
commitd514f41e793d2cbc737ba107d7ae26f387f5eecf (patch)
tree7ce954c9ecb7a413d3fb417e5b452332759556f7 /drivers/net/netdevsim/bpf.c
parenta60f9e48b7707b70a0701dd841e43492e1e68371 (diff)
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: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/netdevsim/bpf.c')
-rw-r--r--drivers/net/netdevsim/bpf.c79
1 files changed, 33 insertions, 46 deletions
diff --git a/drivers/net/netdevsim/bpf.c b/drivers/net/netdevsim/bpf.c
index a93aafe87db3..89980b223adc 100644
--- a/drivers/net/netdevsim/bpf.c
+++ b/drivers/net/netdevsim/bpf.c
@@ -27,7 +27,7 @@
bpf_verifier_log_write(env, "[netdevsim] " fmt, ##__VA_ARGS__)
struct nsim_bpf_bound_prog {
- struct netdevsim_shared_dev *sdev;
+ struct nsim_dev *nsim_dev;
struct bpf_prog *prog;
struct dentry *ddir;
const char *state;
@@ -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;
state = env->prog->aux->offload->dev_priv;
- if (state->sdev->bpf_bind_verifier_delay && !insn_idx)
- msleep(state->sdev->bpf_bind_verifier_delay);
+ if (state->nsim_dev->bpf_bind_verifier_delay && !insn_idx)
+ msleep(state->nsim_dev->bpf_bind_verifier_delay);
if (insn_idx == env->prog->len - 1)
pr_vlog(env, "Hello from netdevsim!\n");
@@ -213,7 +213,7 @@ nsim_xdp_set_prog(struct netdevsim *ns, struct netdev_bpf *bpf,
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 nsim_bpf_bound_prog *state;
@@ -223,13 +223,13 @@ static int nsim_bpf_create_prog(struct netdevsim_shared_dev *sdev,
if (!state)
return -ENOMEM;
- state->sdev = sdev;
+ state->nsim_dev = nsim_dev;
state->prog = prog;
state->state = "verify";
/* Program id is not populated yet when we create the state. */
- sprintf(name, "%u", sdev->prog_id_gen++);
- state->ddir = debugfs_create_dir(name, sdev->ddir_bpf_bound_progs);
+ sprintf(name, "%u", nsim_dev->prog_id_gen++);
+ state->ddir = debugfs_create_dir(name, nsim_dev->ddir_bpf_bound_progs);
if (IS_ERR_OR_NULL(state->ddir)) {
kfree(state);
return -ENOMEM;
@@ -240,7 +240,7 @@ static int nsim_bpf_create_prog(struct netdevsim_shared_dev *sdev,
&state->state, &nsim_bpf_string_fops);
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;
@@ -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)
{
- struct netdevsim_shared_dev *sdev =
+ struct nsim_dev *nsim_dev =
bpf_offload_dev_priv(prog->aux->offload->offdev);
- if (!sdev->bpf_bind_accept)
+ if (!nsim_dev->bpf_bind_accept)
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)
@@ -514,7 +514,7 @@ nsim_bpf_map_alloc(struct netdevsim *ns, struct bpf_offloaded_map *offmap)
}
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;
@@ -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;
- INIT_LIST_HEAD(&sdev->bpf_bound_progs);
- INIT_LIST_HEAD(&sdev->bpf_bound_maps);
+ INIT_LIST_HEAD(&nsim_dev->bpf_bound_progs);
+ INIT_LIST_HEAD(&nsim_dev->bpf_bound_maps);
- sdev->ddir_bpf_bound_progs =
- debugfs_create_dir("bpf_bound_progs", sdev->ddir);
- if (IS_ERR_OR_NULL(sdev->ddir_bpf_bound_progs))
+ nsim_dev->ddir_bpf_bound_progs = debugfs_create_dir("bpf_bound_progs",
+ nsim_dev->ddir);
+ if (IS_ERR_OR_NULL(nsim_dev->ddir_bpf_bound_progs))
return -ENOMEM;
- sdev->bpf_dev = bpf_offload_dev_create(&nsim_bpf_dev_ops, sdev);
- err = PTR_ERR_OR_ZERO(sdev->bpf_dev);
+ nsim_dev->bpf_dev = bpf_offload_dev_create(&nsim_bpf_dev_ops, nsim_dev);
+ err = PTR_ERR_OR_ZERO(nsim_dev->bpf_dev);
if (err)
return err;
- sdev->bpf_bind_accept = true;
- debugfs_create_bool("bpf_bind_accept", 0600, sdev->ddir,
- &sdev->bpf_bind_accept);
- debugfs_create_u32("bpf_bind_verifier_delay", 0600, sdev->ddir,
- &sdev->bpf_bind_verifier_delay);
+ nsim_dev->bpf_bind_accept = true;
+ debugfs_create_bool("bpf_bind_accept", 0600, nsim_dev->ddir,
+ &nsim_dev->bpf_bind_accept);
+ debugfs_create_u32("bpf_bind_verifier_delay", 0600, nsim_dev->ddir,
+ &nsim_dev->bpf_bind_verifier_delay);
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(&sdev->bpf_bound_maps));
- bpf_offload_dev_destroy(sdev->bpf_dev);
+ WARN_ON(!list_empty(&nsim_dev->bpf_bound_progs));
+ WARN_ON(!list_empty(&nsim_dev->bpf_bound_maps));
+ bpf_offload_dev_destroy(nsim_dev->bpf_dev);
}
int nsim_bpf_init(struct netdevsim *ns)
{
int err;
- if (ns->sdev->refcnt == 1) {
- err = nsim_bpf_sdev_init(ns->sdev);
- if (err)
- return err;
- }
-
- err = bpf_offload_dev_netdev_register(ns->sdev->bpf_dev, ns->netdev);
+ err = bpf_offload_dev_netdev_register(ns->nsim_dev->bpf_dev,
+ ns->netdev);
if (err)
- goto err_bpf_sdev_uninit;
+ return err;
debugfs_create_u32("bpf_offloaded_id", 0400, ns->ddir,
&ns->bpf_offloaded_id);
@@ -644,11 +639,6 @@ int nsim_bpf_init(struct netdevsim *ns)
&ns->bpf_map_accept);
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)
@@ -656,8 +646,5 @@ void nsim_bpf_uninit(struct netdevsim *ns)
WARN_ON(ns->xdp.prog);
WARN_ON(ns->xdp_hw.prog);
WARN_ON(ns->bpf_offloaded);
- bpf_offload_dev_netdev_unregister(ns->sdev->bpf_dev, ns->netdev);
-
- if (ns->sdev->refcnt == 1)
- nsim_bpf_sdev_uninit(ns->sdev);
+ bpf_offload_dev_netdev_unregister(ns->nsim_dev->bpf_dev, ns->netdev);
}