netdevsim: add couple of fw_update_flash_* debugfs knobs
Subsystems (4)
PATCH v2 1/1 netdevsim: add couple of fw_update_flash_* debugfs knobs
From: Jiri Pirko <[email protected]>
Netdevsim emulates firmware update and it takes 5 seconds to complete. For some usecases, this is too long and unnecessary. Allow user to configure the time by exposing debugfs knobs to set flash size, chunk size and chunk time.
---v1->v2:
- added sanitiazation of the tunables before using them
--- drivers/net/netdevsim/dev.c | 42 ++++++++++++++----- drivers/net/netdevsim/netdevsim.h | 3 ++ .../drivers/net/netdevsim/devlink.sh | 4 ++ 3 files changed, 39 insertions(+), 10 deletions(-)
drivers/net/netdevsim/dev.c +32 -10
@@ -314,6 +314,12 @@ static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev) &nsim_dev->fw_update_status);debugfs_create_u32 ("fw_update_overwrite_mask" ,0600 , nsim_dev->ddir, &nsim_dev->fw_update_overwrite_mask); +debugfs_create_u32 ("fw_update_flash_size" ,0600 , nsim_dev->ddir, + &nsim_dev->fw_update_flash_size); +debugfs_create_u32 ("fw_update_flash_chunk_size" ,0600 , nsim_dev->ddir, + &nsim_dev->fw_update_flash_chunk_size); +debugfs_create_u32 ("fw_update_flash_chunk_time_ms" ,0600 , nsim_dev->ddir, + &nsim_dev->fw_update_flash_chunk_time_ms);debugfs_create_u32 ("max_macs" ,0600 , nsim_dev->ddir, &nsim_dev->max_macs); debugfs_create_bool("test1", 0600, nsim_dev->ddir,
@@ -1015,15 +1021,14 @@ static int nsim_dev_info_get(struct devlink *devlink, DEVLINK_INFO_VERSION_TYPE_COMPONENT); } -#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,struct devlink_flash_update_params *params,struct netlink_ext_ack *extack) {struct nsim_dev *nsim_dev =devlink_priv (devlink); +u32 flash_size = nsim_dev->fw_update_flash_size; +u32 flash_chunk_size = nsim_dev->fw_update_flash_chunk_size; +u32 flash_chunk_time_ms = nsim_dev->fw_update_flash_chunk_time_ms;int i;if ((params->overwrite_mask & ~nsim_dev->fw_update_overwrite_mask) !=0 )
@@ -1035,20 +1040,30 @@ static int nsim_dev_flash_update(struct devlink *devlink, params->component, 0, 0); } -for (i =0 ; i <NSIM_DEV_FLASH_SIZE /NSIM_DEV_FLASH_CHUNK_SIZE ; i++) { +/* Sanitize flash sizes and time. */ +if (!flash_chunk_size) + flash_chunk_size =1 ; +if (flash_chunk_size > flash_size) + flash_chunk_size = flash_size; +else if (flash_size % flash_chunk_size) + flash_size = flash_size / flash_chunk_size * flash_chunk_size; +if (!flash_chunk_time_ms) + flash_chunk_time_ms =1 ; + +for (i =0 ; i < flash_size / flash_chunk_size; i++) {if (nsim_dev->fw_update_status)devlink_flash_update_status_notify (devlink,"Flashing" , params->component, - i *NSIM_DEV_FLASH_CHUNK_SIZE , -NSIM_DEV_FLASH_SIZE ); -msleep (NSIM_DEV_FLASH_CHUNK_TIME_MS ); + i * flash_chunk_size, + flash_size); +msleep (flash_chunk_time_ms); }if (nsim_dev->fw_update_status) {devlink_flash_update_status_notify (devlink,"Flashing" , params->component, -NSIM_DEV_FLASH_SIZE , -NSIM_DEV_FLASH_SIZE ); + flash_size, + flash_size);devlink_flash_update_timeout_notify (devlink,"Flash select" , params->component,81 ); devlink_flash_update_status_notify(devlink, "Flashing done",
@@ -1567,6 +1582,10 @@ static int nsim_dev_reload_create(struct nsim_dev *nsim_dev,return err; } +#define NSIM_DEV_FLASH_SIZE_DEFAULT 500000 +#define NSIM_DEV_FLASH_CHUNK_SIZE_DEFAULT 1000 +#define NSIM_DEV_FLASH_CHUNK_TIME_MS_DEFAULT 10 +int nsim_drv_probe (struct nsim_bus_dev *nsim_bus_dev) {struct nsim_dev *nsim_dev;
@@ -1585,6 +1604,9 @@ int nsim_drv_probe(struct nsim_bus_dev *nsim_bus_dev)INIT_LIST_HEAD (&nsim_dev->port_list); nsim_dev->fw_update_status = true; nsim_dev->fw_update_overwrite_mask =0 ; + nsim_dev->fw_update_flash_size =NSIM_DEV_FLASH_SIZE_DEFAULT ; + nsim_dev->fw_update_flash_chunk_size =NSIM_DEV_FLASH_CHUNK_SIZE_DEFAULT ; + nsim_dev->fw_update_flash_chunk_time_ms =NSIM_DEV_FLASH_CHUNK_TIME_MS_DEFAULT ; nsim_dev->max_macs =NSIM_DEV_MAX_MACS_DEFAULT ; nsim_dev->test1 =NSIM_DEV_TEST1_DEFAULT ;spin_lock_init (&nsim_dev->fa_cookie_lock);
drivers/net/netdevsim/netdevsim.h +3 -0
@@ -317,6 +317,9 @@ struct nsim_dev {struct list_head port_list;bool fw_update_status;u32 fw_update_overwrite_mask; +u32 fw_update_flash_size; +u32 fw_update_flash_chunk_size; +u32 fw_update_flash_chunk_time_ms;u32 max_macs;bool test1;bool dont_allow_reload;
tools/testing/selftests/drivers/net/netdevsim/devlink.sh +4 -0
@@ -40,6 +40,10 @@ fw_flash_test() return fi + echo "1024"> $DEBUGFS_DIR/fw_update_flash_size + echo "128"> $DEBUGFS_DIR/fw_update_flash_chunk_size + echo "10"> $DEBUGFS_DIR/fw_update_flash_chunk_time_ms + devlink dev flash $DL_HANDLE file $DUMMYFILE check_err $? "Failed to flash with status updates on"
Signature · 1 line
2.50.1
Quoted 11 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Netdevsim emulates firmware update and it takes 5 seconds to complete. For some usecases, this is too long and unnecessary. Allow user to configure the time by exposing debugfs knobs to set flash size, chunk size and chunk time.
Signed-off-by Jiri Pirko <[email protected]>---
v1->v2:
- added sanitiazation of the tunables before using them
Thanks for the update.
This version looks good to me.
Jakub Kicinski
maintainerQuoted 4 lines · On Sun, 20 Jul 2025 23:27:34 +0200 Jiri Pirko wrote:
Netdevsim emulates firmware update and it takes 5 seconds to complete. For some usecases, this is too long and unnecessary. Allow user to configure the time by exposing debugfs knobs to set flash size, chunk size and chunk time.
FWIW I also find the long delays annoying when running the test manually. But do we need knobs for all the constants? Maybe cut down the size to something more reasonable and expose just one knob to control the length of the msleep()?
Signature · 1 line
pw-bot: cr
Quoted 10 lines · Tue, Jul 22, 2025 at 01:04:57AM +0200, [email protected] wrote:
Quoted 4 lines · On Sun, 20 Jul 2025 23:27:34 +0200 Jiri Pirko wrote:
Netdevsim emulates firmware update and it takes 5 seconds to complete. For some usecases, this is too long and unnecessary. Allow user to configure the time by exposing debugfs knobs to set flash size, chunk size and chunk time.
FWIW I also find the long delays annoying when running the test manually. But do we need knobs for all the constants? Maybe cut down the size to something more reasonable and expose just one knob to control the length of the
msleep()?
Sure.
Quoted 2 lines
Signature · 1 line
pw-bot: cr