Skip to content

Commit 22ec3d2

Browse files
jacob-kellerdavem330
authored andcommitted
devlink: check flash_update parameter support in net core
When implementing .flash_update, drivers which do not support per-component update are manually checking the component parameter to verify that it is NULL. Without this check, the driver might accept an update request with a component specified even though it will not honor such a request. Instead of having each driver check this, move the logic into net/core/devlink.c, and use a new `supported_flash_update_params` field in the devlink_ops. Drivers which will support per-component update must now specify this by setting DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT in the supported_flash_update_params in their devlink_ops. This helps ensure that drivers do not forget to check for a NULL component if they do not support per-component update. This also enables a slightly better error message by enabling the core stack to set the netlink bad attribute message to indicate precisely the unsupported attribute in the message. Going forward, any new additional parameter to flash update will require a bit in the supported_flash_update_params bitfield. Signed-off-by: Jacob Keller <jacob.e.keller@intel.com> Reviewed-by: Jakub Kicinski <kuba@kernel.org> Cc: Jiri Pirko <jiri@mellanox.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Michael Chan <michael.chan@broadcom.com> Cc: Bin Luo <luobin9@huawei.com> Cc: Saeed Mahameed <saeedm@mellanox.com> Cc: Leon Romanovsky <leon@kernel.org> Cc: Ido Schimmel <idosch@mellanox.com> Cc: Danielle Ratson <danieller@mellanox.com> Cc: Shannon Nelson <snelson@pensando.io> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6fba737 commit 22ec3d2

10 files changed

Lines changed: 34 additions & 32 deletions

File tree

‎drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,19 @@ bnxt_dl_flash_update(struct devlink *dl, const char *filename,
2323
struct bnxt *bp = bnxt_get_bp_from_dl(dl);
2424
int rc;
2525

26-
if (region)
27-
return -EOPNOTSUPP;
28-
2926
if (!BNXT_PF(bp)) {
3027
NL_SET_ERR_MSG_MOD(extack,
3128
"flash update not supported from a VF");
3229
return -EPERM;
3330
}
3431

3532
devlink_flash_update_begin_notify(dl);
36-
devlink_flash_update_status_notify(dl, "Preparing to flash", region, 0,
37-
0);
33+
devlink_flash_update_status_notify(dl, "Preparing to flash", NULL, 0, 0);
3834
rc = bnxt_flash_package_from_file(bp->dev, filename, 0);
3935
if (!rc)
40-
devlink_flash_update_status_notify(dl, "Flashing done", region,
41-
0, 0);
36+
devlink_flash_update_status_notify(dl, "Flashing done", NULL, 0, 0);
4237
else
43-
devlink_flash_update_status_notify(dl, "Flashing failed",
44-
region, 0, 0);
38+
devlink_flash_update_status_notify(dl, "Flashing failed", NULL, 0, 0);
4539
devlink_flash_update_end_notify(dl);
4640
return rc;
4741
}

‎drivers/net/ethernet/huawei/hinic/hinic_devlink.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,6 @@ static int hinic_devlink_flash_update(struct devlink *devlink,
289289
const struct firmware *fw;
290290
int err;
291291

292-
if (component)
293-
return -EOPNOTSUPP;
294-
295292
err = request_firmware_direct(&fw, file_name,
296293
&priv->hwdev->hwif->pdev->dev);
297294
if (err)

‎drivers/net/ethernet/intel/ice/ice_devlink.c‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,12 @@ ice_devlink_flash_update(struct devlink *devlink, const char *path,
252252
const struct firmware *fw;
253253
int err;
254254

255-
/* individual component update is not yet supported */
256-
if (component)
257-
return -EOPNOTSUPP;
258-
259255
if (!hw->dev_caps.common_cap.nvm_unified_update) {
260256
NL_SET_ERR_MSG_MOD(extack, "Current firmware does not support unified update");
261257
return -EOPNOTSUPP;
262258
}
263259

264-
err = ice_check_for_pending_update(pf, component, extack);
260+
err = ice_check_for_pending_update(pf, NULL, extack);
265261
if (err)
266262
return err;
267263

@@ -272,8 +268,7 @@ ice_devlink_flash_update(struct devlink *devlink, const char *path,
272268
}
273269

274270
devlink_flash_update_begin_notify(devlink);
275-
devlink_flash_update_status_notify(devlink, "Preparing to flash",
276-
component, 0, 0);
271+
devlink_flash_update_status_notify(devlink, "Preparing to flash", NULL, 0, 0);
277272
err = ice_flash_pldm_image(pf, fw, extack);
278273
devlink_flash_update_end_notify(devlink);
279274

‎drivers/net/ethernet/mellanox/mlx5/core/devlink.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ static int mlx5_devlink_flash_update(struct devlink *devlink,
1616
const struct firmware *fw;
1717
int err;
1818

19-
if (component)
20-
return -EOPNOTSUPP;
21-
2219
err = request_firmware_direct(&fw, file_name, &dev->pdev->dev);
2320
if (err)
2421
return err;

‎drivers/net/ethernet/mellanox/mlxsw/core.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,9 +1108,6 @@ static int mlxsw_core_fw_flash_update(struct mlxsw_core *mlxsw_core,
11081108
const struct firmware *firmware;
11091109
int err;
11101110

1111-
if (component)
1112-
return -EOPNOTSUPP;
1113-
11141111
err = request_firmware_direct(&firmware, file_name, mlxsw_core->bus_info->dev);
11151112
if (err)
11161113
return err;

‎drivers/net/ethernet/netronome/nfp/nfp_devlink.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,6 @@ static int
332332
nfp_devlink_flash_update(struct devlink *devlink, const char *path,
333333
const char *component, struct netlink_ext_ack *extack)
334334
{
335-
if (component)
336-
return -EOPNOTSUPP;
337335
return nfp_flash_update_common(devlink_priv(devlink), path, extack);
338336
}
339337

‎drivers/net/ethernet/pensando/ionic/ionic_devlink.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ static int ionic_dl_flash_update(struct devlink *dl,
1616
{
1717
struct ionic *ionic = devlink_priv(dl);
1818

19-
if (component)
20-
return -EOPNOTSUPP;
21-
2219
return ionic_firmware_update(ionic->lif, fwname, extack);
2320
}
2421

‎drivers/net/netdevsim/dev.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ nsim_dev_devlink_trap_policer_counter_get(struct devlink *devlink,
879879
}
880880

881881
static const struct devlink_ops nsim_dev_devlink_ops = {
882+
.supported_flash_update_params = DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT,
882883
.reload_down = nsim_dev_reload_down,
883884
.reload_up = nsim_dev_reload_up,
884885
.info_get = nsim_dev_info_get,

‎include/net/devlink.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,8 @@ enum devlink_param_generic_id {
550550
/* Firmware bundle identifier */
551551
#define DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID "fw.bundle_id"
552552

553+
#define DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT BIT(0)
554+
553555
struct devlink_region;
554556
struct devlink_info_req;
555557

@@ -1037,6 +1039,12 @@ enum devlink_trap_group_generic_id {
10371039
}
10381040

10391041
struct devlink_ops {
1042+
/**
1043+
* @supported_flash_update_params:
1044+
* mask of parameters supported by the driver's .flash_update
1045+
* implemementation.
1046+
*/
1047+
u32 supported_flash_update_params;
10401048
int (*reload_down)(struct devlink *devlink, bool netns_change,
10411049
struct netlink_ext_ack *extack);
10421050
int (*reload_up)(struct devlink *devlink,
@@ -1097,6 +1105,13 @@ struct devlink_ops {
10971105
struct netlink_ext_ack *extack);
10981106
int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
10991107
struct netlink_ext_ack *extack);
1108+
/**
1109+
* @flash_update: Device flash update function
1110+
*
1111+
* Used to perform a flash update for the device. The set of
1112+
* parameters supported by the driver should be set in
1113+
* supported_flash_update_params.
1114+
*/
11001115
int (*flash_update)(struct devlink *devlink, const char *file_name,
11011116
const char *component,
11021117
struct netlink_ext_ack *extack);

‎net/core/devlink.c‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3148,18 +3148,29 @@ static int devlink_nl_cmd_flash_update(struct sk_buff *skb,
31483148
struct genl_info *info)
31493149
{
31503150
struct devlink *devlink = info->user_ptr[0];
3151-
const char *file_name, *component;
3151+
const char *file_name, *component = NULL;
31523152
struct nlattr *nla_component;
3153+
u32 supported_params;
31533154

31543155
if (!devlink->ops->flash_update)
31553156
return -EOPNOTSUPP;
31563157

31573158
if (!info->attrs[DEVLINK_ATTR_FLASH_UPDATE_FILE_NAME])
31583159
return -EINVAL;
3160+
3161+
supported_params = devlink->ops->supported_flash_update_params;
3162+
31593163
file_name = nla_data(info->attrs[DEVLINK_ATTR_FLASH_UPDATE_FILE_NAME]);
31603164

31613165
nla_component = info->attrs[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT];
3162-
component = nla_component ? nla_data(nla_component) : NULL;
3166+
if (nla_component) {
3167+
if (!(supported_params & DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT)) {
3168+
NL_SET_ERR_MSG_ATTR(info->extack, nla_component,
3169+
"component update is not supported by this device");
3170+
return -EOPNOTSUPP;
3171+
}
3172+
component = nla_data(nla_component);
3173+
}
31633174

31643175
return devlink->ops->flash_update(devlink, file_name, component,
31653176
info->extack);

0 commit comments

Comments
 (0)