diff options
author | Jiri Pirko | 2019-06-04 15:40:43 +0200 |
---|---|---|
committer | David S. Miller | 2019-06-04 23:21:40 +0200 |
commit | fa4dfc4a94da180a5ab7e91a501fed86352abfd4 (patch) | |
tree | 11592990cfdcf5417918bc073ec089e69f16cbd9 /drivers/net/netdevsim/dev.c | |
parent | mlxsw: Implement flash update status notifications (diff) | |
download | kernel-qcow2-linux-fa4dfc4a94da180a5ab7e91a501fed86352abfd4.tar.gz kernel-qcow2-linux-fa4dfc4a94da180a5ab7e91a501fed86352abfd4.tar.xz kernel-qcow2-linux-fa4dfc4a94da180a5ab7e91a501fed86352abfd4.zip |
netdevsim: implement fake flash updating with notifications
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/netdevsim/dev.c')
-rw-r--r-- | drivers/net/netdevsim/dev.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index b509b941d5ca..c5c417a3c0ce 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -38,6 +38,8 @@ static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev) nsim_dev->ports_ddir = debugfs_create_dir("ports", nsim_dev->ddir); if (IS_ERR_OR_NULL(nsim_dev->ports_ddir)) return PTR_ERR_OR_ZERO(nsim_dev->ports_ddir) ?: -EINVAL; + debugfs_create_bool("fw_update_status", 0600, nsim_dev->ddir, + &nsim_dev->fw_update_status); return 0; } @@ -220,8 +222,49 @@ static int nsim_dev_reload(struct devlink *devlink, return 0; } +#define NSIM_DEV_FLASH_SIZE 500000 +#define NSIM_DEV_FLASH_CHUNK_SIZE 1000 +#define NSIM_DEV_FLASH_CHUNK_TIME_MS 10 + +static int nsim_dev_flash_update(struct devlink *devlink, const char *file_name, + const char *component, + struct netlink_ext_ack *extack) +{ + struct nsim_dev *nsim_dev = devlink_priv(devlink); + int i; + + if (nsim_dev->fw_update_status) { + devlink_flash_update_begin_notify(devlink); + devlink_flash_update_status_notify(devlink, + "Preparing to flash", + component, 0, 0); + } + + for (i = 0; i < NSIM_DEV_FLASH_SIZE / NSIM_DEV_FLASH_CHUNK_SIZE; i++) { + if (nsim_dev->fw_update_status) + devlink_flash_update_status_notify(devlink, "Flashing", + component, + i * NSIM_DEV_FLASH_CHUNK_SIZE, + NSIM_DEV_FLASH_SIZE); + msleep(NSIM_DEV_FLASH_CHUNK_TIME_MS); + } + + if (nsim_dev->fw_update_status) { + devlink_flash_update_status_notify(devlink, "Flashing", + component, + NSIM_DEV_FLASH_SIZE, + NSIM_DEV_FLASH_SIZE); + devlink_flash_update_status_notify(devlink, "Flashing done", + component, 0, 0); + devlink_flash_update_end_notify(devlink); + } + + return 0; +} + static const struct devlink_ops nsim_dev_devlink_ops = { .reload = nsim_dev_reload, + .flash_update = nsim_dev_flash_update, }; static struct nsim_dev * @@ -240,6 +283,7 @@ nsim_dev_create(struct nsim_bus_dev *nsim_bus_dev, unsigned int port_count) get_random_bytes(nsim_dev->switch_id.id, nsim_dev->switch_id.id_len); INIT_LIST_HEAD(&nsim_dev->port_list); mutex_init(&nsim_dev->port_list_lock); + nsim_dev->fw_update_status = true; nsim_dev->fib_data = nsim_fib_create(); if (IS_ERR(nsim_dev->fib_data)) { |