Skip to content

Commit

Permalink
netdevsim: add support for flash_update overwrite mask
Browse files Browse the repository at this point in the history
The devlink interface recently gained support for a new "overwrite mask"
parameter that allows specifying how various sub-sections of a flash
component are modified when updating.

Add support for this to netdevsim, to enable easily testing the
interface. Make the allowed overwrite mask values controllable via
a debugfs parameter. This enables testing a flow where the driver
rejects an unsupportable overwrite mask.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jacob Keller authored and David S. Miller committed Sep 26, 2020
1 parent 5d5b412 commit cbb5836
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
10 changes: 9 additions & 1 deletion drivers/net/netdevsim/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev)
return PTR_ERR(nsim_dev->ports_ddir);
debugfs_create_bool("fw_update_status", 0600, nsim_dev->ddir,
&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("max_macs", 0600, nsim_dev->ddir,
&nsim_dev->max_macs);
debugfs_create_bool("test1", 0600, nsim_dev->ddir,
Expand Down Expand Up @@ -749,6 +751,9 @@ static int nsim_dev_flash_update(struct devlink *devlink,
struct nsim_dev *nsim_dev = devlink_priv(devlink);
int i;

if ((params->overwrite_mask & ~nsim_dev->fw_update_overwrite_mask) != 0)
return -EOPNOTSUPP;

if (nsim_dev->fw_update_status) {
devlink_flash_update_begin_notify(devlink);
devlink_flash_update_status_notify(devlink,
Expand Down Expand Up @@ -879,7 +884,8 @@ nsim_dev_devlink_trap_policer_counter_get(struct devlink *devlink,
}

static const struct devlink_ops nsim_dev_devlink_ops = {
.supported_flash_update_params = DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT,
.supported_flash_update_params = DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT |
DEVLINK_SUPPORT_FLASH_UPDATE_OVERWRITE_MASK,
.reload_down = nsim_dev_reload_down,
.reload_up = nsim_dev_reload_up,
.info_get = nsim_dev_info_get,
Expand Down Expand Up @@ -994,6 +1000,7 @@ static int nsim_dev_reload_create(struct nsim_dev *nsim_dev,
INIT_LIST_HEAD(&nsim_dev->port_list);
mutex_init(&nsim_dev->port_list_lock);
nsim_dev->fw_update_status = true;
nsim_dev->fw_update_overwrite_mask = 0;

nsim_dev->fib_data = nsim_fib_create(devlink, extack);
if (IS_ERR(nsim_dev->fib_data))
Expand Down Expand Up @@ -1052,6 +1059,7 @@ int nsim_dev_probe(struct nsim_bus_dev *nsim_bus_dev)
INIT_LIST_HEAD(&nsim_dev->port_list);
mutex_init(&nsim_dev->port_list_lock);
nsim_dev->fw_update_status = true;
nsim_dev->fw_update_overwrite_mask = 0;
nsim_dev->max_macs = NSIM_DEV_MAX_MACS_DEFAULT;
nsim_dev->test1 = NSIM_DEV_TEST1_DEFAULT;
spin_lock_init(&nsim_dev->fa_cookie_lock);
Expand Down
1 change: 1 addition & 0 deletions drivers/net/netdevsim/netdevsim.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ struct nsim_dev {
struct list_head port_list;
struct mutex port_list_lock; /* protects port list */
bool fw_update_status;
u32 fw_update_overwrite_mask;
u32 max_macs;
bool test1;
bool dont_allow_reload;
Expand Down
18 changes: 18 additions & 0 deletions tools/testing/selftests/drivers/net/netdevsim/devlink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ fw_flash_test()
devlink dev flash $DL_HANDLE file dummy component fw.mgmt
check_err $? "Failed to flash with component attribute"

devlink dev flash $DL_HANDLE file dummy overwrite settings
check_fail $? "Flash with overwrite settings should be rejected"

echo "1"> $DEBUGFS_DIR/fw_update_overwrite_mask
check_err $? "Failed to change allowed overwrite mask"

devlink dev flash $DL_HANDLE file dummy overwrite settings
check_err $? "Failed to flash with settings overwrite enabled"

devlink dev flash $DL_HANDLE file dummy overwrite identifiers
check_fail $? "Flash with overwrite settings should be identifiers"

echo "3"> $DEBUGFS_DIR/fw_update_overwrite_mask
check_err $? "Failed to change allowed overwrite mask"

devlink dev flash $DL_HANDLE file dummy overwrite identifiers overwrite settings
check_err $? "Failed to flash with settings and identifiers overwrite enabled"

echo "n"> $DEBUGFS_DIR/fw_update_status
check_err $? "Failed to disable status updates"

Expand Down

0 comments on commit cbb5836

Please sign in to comment.