Skip to content

Commit fa4dfc4

Browse files
jpirkodavem330
authored andcommitted
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>
1 parent 8f1956f commit fa4dfc4

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

‎drivers/net/netdevsim/dev.c‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev)
3838
nsim_dev->ports_ddir = debugfs_create_dir("ports", nsim_dev->ddir);
3939
if (IS_ERR_OR_NULL(nsim_dev->ports_ddir))
4040
return PTR_ERR_OR_ZERO(nsim_dev->ports_ddir) ?: -EINVAL;
41+
debugfs_create_bool("fw_update_status", 0600, nsim_dev->ddir,
42+
&nsim_dev->fw_update_status);
4143
return 0;
4244
}
4345

@@ -220,8 +222,49 @@ static int nsim_dev_reload(struct devlink *devlink,
220222
return 0;
221223
}
222224

225+
#define NSIM_DEV_FLASH_SIZE 500000
226+
#define NSIM_DEV_FLASH_CHUNK_SIZE 1000
227+
#define NSIM_DEV_FLASH_CHUNK_TIME_MS 10
228+
229+
static int nsim_dev_flash_update(struct devlink *devlink, const char *file_name,
230+
const char *component,
231+
struct netlink_ext_ack *extack)
232+
{
233+
struct nsim_dev *nsim_dev = devlink_priv(devlink);
234+
int i;
235+
236+
if (nsim_dev->fw_update_status) {
237+
devlink_flash_update_begin_notify(devlink);
238+
devlink_flash_update_status_notify(devlink,
239+
"Preparing to flash",
240+
component, 0, 0);
241+
}
242+
243+
for (i = 0; i < NSIM_DEV_FLASH_SIZE / NSIM_DEV_FLASH_CHUNK_SIZE; i++) {
244+
if (nsim_dev->fw_update_status)
245+
devlink_flash_update_status_notify(devlink, "Flashing",
246+
component,
247+
i * NSIM_DEV_FLASH_CHUNK_SIZE,
248+
NSIM_DEV_FLASH_SIZE);
249+
msleep(NSIM_DEV_FLASH_CHUNK_TIME_MS);
250+
}
251+
252+
if (nsim_dev->fw_update_status) {
253+
devlink_flash_update_status_notify(devlink, "Flashing",
254+
component,
255+
NSIM_DEV_FLASH_SIZE,
256+
NSIM_DEV_FLASH_SIZE);
257+
devlink_flash_update_status_notify(devlink, "Flashing done",
258+
component, 0, 0);
259+
devlink_flash_update_end_notify(devlink);
260+
}
261+
262+
return 0;
263+
}
264+
223265
static const struct devlink_ops nsim_dev_devlink_ops = {
224266
.reload = nsim_dev_reload,
267+
.flash_update = nsim_dev_flash_update,
225268
};
226269

227270
static struct nsim_dev *
@@ -240,6 +283,7 @@ nsim_dev_create(struct nsim_bus_dev *nsim_bus_dev, unsigned int port_count)
240283
get_random_bytes(nsim_dev->switch_id.id, nsim_dev->switch_id.id_len);
241284
INIT_LIST_HEAD(&nsim_dev->port_list);
242285
mutex_init(&nsim_dev->port_list_lock);
286+
nsim_dev->fw_update_status = true;
243287

244288
nsim_dev->fib_data = nsim_fib_create();
245289
if (IS_ERR(nsim_dev->fib_data)) {

‎drivers/net/netdevsim/netdevsim.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ struct nsim_dev {
157157
struct netdev_phys_item_id switch_id;
158158
struct list_head port_list;
159159
struct mutex port_list_lock; /* protects port list */
160+
bool fw_update_status;
160161
};
161162

162163
int nsim_dev_init(void);

0 commit comments

Comments
 (0)