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

netdevsim: implement support for devlink region and snapshots

Implement dummy region of size 32K and allow user to create snapshots
or random data using debugfs file trigger.
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent bd00cc36
...@@ -27,6 +27,41 @@ ...@@ -27,6 +27,41 @@
static struct dentry *nsim_dev_ddir; static struct dentry *nsim_dev_ddir;
#define NSIM_DEV_DUMMY_REGION_SIZE (1024 * 32)
static ssize_t nsim_dev_take_snapshot_write(struct file *file,
const char __user *data,
size_t count, loff_t *ppos)
{
struct nsim_dev *nsim_dev = file->private_data;
void *dummy_data;
int err;
u32 id;
dummy_data = kmalloc(NSIM_DEV_DUMMY_REGION_SIZE, GFP_KERNEL);
if (!dummy_data)
return -ENOMEM;
get_random_bytes(dummy_data, NSIM_DEV_DUMMY_REGION_SIZE);
id = devlink_region_shapshot_id_get(priv_to_devlink(nsim_dev));
err = devlink_region_snapshot_create(nsim_dev->dummy_region,
dummy_data, id, kfree);
if (err) {
pr_err("Failed to create region snapshot\n");
kfree(dummy_data);
return err;
}
return count;
}
static const struct file_operations nsim_dev_take_snapshot_fops = {
.open = simple_open,
.write = nsim_dev_take_snapshot_write,
.llseek = generic_file_llseek,
};
static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev) static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev)
{ {
char dev_ddir_name[16]; char dev_ddir_name[16];
...@@ -44,6 +79,8 @@ static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev) ...@@ -44,6 +79,8 @@ static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev)
&nsim_dev->max_macs); &nsim_dev->max_macs);
debugfs_create_bool("test1", 0600, nsim_dev->ddir, debugfs_create_bool("test1", 0600, nsim_dev->ddir,
&nsim_dev->test1); &nsim_dev->test1);
debugfs_create_file("take_snapshot", 0200, nsim_dev->ddir, nsim_dev,
&nsim_dev_take_snapshot_fops);
return 0; return 0;
} }
...@@ -248,6 +285,23 @@ static void nsim_devlink_param_load_driverinit_values(struct devlink *devlink) ...@@ -248,6 +285,23 @@ static void nsim_devlink_param_load_driverinit_values(struct devlink *devlink)
nsim_dev->test1 = saved_value.vbool; nsim_dev->test1 = saved_value.vbool;
} }
#define NSIM_DEV_DUMMY_REGION_SNAPSHOT_MAX 16
static int nsim_dev_dummy_region_init(struct nsim_dev *nsim_dev,
struct devlink *devlink)
{
nsim_dev->dummy_region =
devlink_region_create(devlink, "dummy",
NSIM_DEV_DUMMY_REGION_SNAPSHOT_MAX,
NSIM_DEV_DUMMY_REGION_SIZE);
return PTR_ERR_OR_ZERO(nsim_dev->dummy_region);
}
static void nsim_dev_dummy_region_exit(struct nsim_dev *nsim_dev)
{
devlink_region_destroy(nsim_dev->dummy_region);
}
static int nsim_dev_reload(struct devlink *devlink, static int nsim_dev_reload(struct devlink *devlink,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
...@@ -363,10 +417,14 @@ nsim_dev_create(struct nsim_bus_dev *nsim_bus_dev, unsigned int port_count) ...@@ -363,10 +417,14 @@ nsim_dev_create(struct nsim_bus_dev *nsim_bus_dev, unsigned int port_count)
goto err_dl_unregister; goto err_dl_unregister;
nsim_devlink_set_params_init_values(nsim_dev, devlink); nsim_devlink_set_params_init_values(nsim_dev, devlink);
err = nsim_dev_debugfs_init(nsim_dev); err = nsim_dev_dummy_region_init(nsim_dev, devlink);
if (err) if (err)
goto err_params_unregister; goto err_params_unregister;
err = nsim_dev_debugfs_init(nsim_dev);
if (err)
goto err_dummy_region_exit;
err = nsim_bpf_dev_init(nsim_dev); err = nsim_bpf_dev_init(nsim_dev);
if (err) if (err)
goto err_debugfs_exit; goto err_debugfs_exit;
...@@ -376,6 +434,8 @@ nsim_dev_create(struct nsim_bus_dev *nsim_bus_dev, unsigned int port_count) ...@@ -376,6 +434,8 @@ nsim_dev_create(struct nsim_bus_dev *nsim_bus_dev, unsigned int port_count)
err_debugfs_exit: err_debugfs_exit:
nsim_dev_debugfs_exit(nsim_dev); nsim_dev_debugfs_exit(nsim_dev);
err_dummy_region_exit:
nsim_dev_dummy_region_exit(nsim_dev);
err_params_unregister: err_params_unregister:
devlink_params_unregister(devlink, nsim_devlink_params, devlink_params_unregister(devlink, nsim_devlink_params,
ARRAY_SIZE(nsim_devlink_params)); ARRAY_SIZE(nsim_devlink_params));
...@@ -396,6 +456,7 @@ static void nsim_dev_destroy(struct nsim_dev *nsim_dev) ...@@ -396,6 +456,7 @@ static void nsim_dev_destroy(struct nsim_dev *nsim_dev)
nsim_bpf_dev_exit(nsim_dev); nsim_bpf_dev_exit(nsim_dev);
nsim_dev_debugfs_exit(nsim_dev); nsim_dev_debugfs_exit(nsim_dev);
nsim_dev_dummy_region_exit(nsim_dev);
devlink_params_unregister(devlink, nsim_devlink_params, devlink_params_unregister(devlink, nsim_devlink_params,
ARRAY_SIZE(nsim_devlink_params)); ARRAY_SIZE(nsim_devlink_params));
devlink_unregister(devlink); devlink_unregister(devlink);
......
...@@ -160,6 +160,7 @@ struct nsim_dev { ...@@ -160,6 +160,7 @@ struct nsim_dev {
bool fw_update_status; bool fw_update_status;
u32 max_macs; u32 max_macs;
bool test1; bool test1;
struct devlink_region *dummy_region;
}; };
int nsim_dev_init(void); int nsim_dev_init(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