Skip to content

Commit bc75c05

Browse files
jacob-kellerdavem330
authored andcommitted
devlink: convert flash_update to use params structure
The devlink core recently gained support for checking whether the driver supports a flash_update parameter, via `supported_flash_update_params`. However, parameters are specified as function arguments. Adding a new parameter still requires modifying the signature of the .flash_update callback in all drivers. Convert the .flash_update function to take a new `struct devlink_flash_update_params` instead. By using this structure, and the `supported_flash_update_params` bit field, a new parameter to flash_update can be added without requiring modification to existing drivers. As before, all parameters except file_name will require driver opt-in. Because file_name is a necessary field to for the flash_update to make sense, no "SUPPORTED" bitflag is provided and it is always considered valid. All future additional parameters will require a new 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: Jakub Kicinski <kuba@kernel.org> 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> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 22ec3d2 commit bc75c05

11 files changed

Lines changed: 57 additions & 40 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
#include "bnxt_ethtool.h"
1818

1919
static int
20-
bnxt_dl_flash_update(struct devlink *dl, const char *filename,
21-
const char *region, struct netlink_ext_ack *extack)
20+
bnxt_dl_flash_update(struct devlink *dl,
21+
struct devlink_flash_update_params *params,
22+
struct netlink_ext_ack *extack)
2223
{
2324
struct bnxt *bp = bnxt_get_bp_from_dl(dl);
2425
int rc;
@@ -31,7 +32,7 @@ bnxt_dl_flash_update(struct devlink *dl, const char *filename,
3132

3233
devlink_flash_update_begin_notify(dl);
3334
devlink_flash_update_status_notify(dl, "Preparing to flash", NULL, 0, 0);
34-
rc = bnxt_flash_package_from_file(bp->dev, filename, 0);
35+
rc = bnxt_flash_package_from_file(bp->dev, params->file_name, 0);
3536
if (!rc)
3637
devlink_flash_update_status_notify(dl, "Flashing done", NULL, 0, 0);
3738
else

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,15 +281,14 @@ static int hinic_firmware_update(struct hinic_devlink_priv *priv,
281281
}
282282

283283
static int hinic_devlink_flash_update(struct devlink *devlink,
284-
const char *file_name,
285-
const char *component,
284+
struct devlink_flash_update_params *params,
286285
struct netlink_ext_ack *extack)
287286
{
288287
struct hinic_devlink_priv *priv = devlink_priv(devlink);
289288
const struct firmware *fw;
290289
int err;
291290

292-
err = request_firmware_direct(&fw, file_name,
291+
err = request_firmware_direct(&fw, params->file_name,
293292
&priv->hwdev->hwif->pdev->dev);
294293
if (err)
295294
return err;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,7 @@ static int ice_devlink_info_get(struct devlink *devlink,
233233
/**
234234
* ice_devlink_flash_update - Update firmware stored in flash on the device
235235
* @devlink: pointer to devlink associated with device to update
236-
* @path: the path of the firmware file to use via request_firmware
237-
* @component: name of the component to update, or NULL
236+
* @params: flash update parameters
238237
* @extack: netlink extended ACK structure
239238
*
240239
* Perform a device flash update. The bulk of the update logic is contained
@@ -243,8 +242,9 @@ static int ice_devlink_info_get(struct devlink *devlink,
243242
* Returns: zero on success, or an error code on failure.
244243
*/
245244
static int
246-
ice_devlink_flash_update(struct devlink *devlink, const char *path,
247-
const char *component, struct netlink_ext_ack *extack)
245+
ice_devlink_flash_update(struct devlink *devlink,
246+
struct devlink_flash_update_params *params,
247+
struct netlink_ext_ack *extack)
248248
{
249249
struct ice_pf *pf = devlink_priv(devlink);
250250
struct device *dev = &pf->pdev->dev;
@@ -261,7 +261,7 @@ ice_devlink_flash_update(struct devlink *devlink, const char *path,
261261
if (err)
262262
return err;
263263

264-
err = request_firmware(&fw, path, dev);
264+
err = request_firmware(&fw, params->file_name, dev);
265265
if (err) {
266266
NL_SET_ERR_MSG_MOD(extack, "Unable to read file from disk");
267267
return err;

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
#include "eswitch.h"
99

1010
static int mlx5_devlink_flash_update(struct devlink *devlink,
11-
const char *file_name,
12-
const char *component,
11+
struct devlink_flash_update_params *params,
1312
struct netlink_ext_ack *extack)
1413
{
1514
struct mlx5_core_dev *dev = devlink_priv(devlink);
1615
const struct firmware *fw;
1716
int err;
1817

19-
err = request_firmware_direct(&fw, file_name, &dev->pdev->dev);
18+
err = request_firmware_direct(&fw, params->file_name, &dev->pdev->dev);
2019
if (err)
2120
return err;
2221

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,13 +1102,13 @@ static int mlxsw_core_fw_rev_validate(struct mlxsw_core *mlxsw_core,
11021102
}
11031103

11041104
static int mlxsw_core_fw_flash_update(struct mlxsw_core *mlxsw_core,
1105-
const char *file_name, const char *component,
1105+
struct devlink_flash_update_params *params,
11061106
struct netlink_ext_ack *extack)
11071107
{
11081108
const struct firmware *firmware;
11091109
int err;
11101110

1111-
err = request_firmware_direct(&firmware, file_name, mlxsw_core->bus_info->dev);
1111+
err = request_firmware_direct(&firmware, params->file_name, mlxsw_core->bus_info->dev);
11121112
if (err)
11131113
return err;
11141114
err = mlxsw_core_fw_flash(mlxsw_core, firmware, extack);
@@ -1431,13 +1431,12 @@ mlxsw_devlink_core_bus_device_reload_up(struct devlink *devlink,
14311431
}
14321432

14331433
static int mlxsw_devlink_flash_update(struct devlink *devlink,
1434-
const char *file_name,
1435-
const char *component,
1434+
struct devlink_flash_update_params *params,
14361435
struct netlink_ext_ack *extack)
14371436
{
14381437
struct mlxsw_core *mlxsw_core = devlink_priv(devlink);
14391438

1440-
return mlxsw_core_fw_flash_update(mlxsw_core, file_name, component, extack);
1439+
return mlxsw_core_fw_flash_update(mlxsw_core, params, extack);
14411440
}
14421441

14431442
static int mlxsw_devlink_trap_init(struct devlink *devlink,

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,11 @@ nfp_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req,
329329
}
330330

331331
static int
332-
nfp_devlink_flash_update(struct devlink *devlink, const char *path,
333-
const char *component, struct netlink_ext_ack *extack)
332+
nfp_devlink_flash_update(struct devlink *devlink,
333+
struct devlink_flash_update_params *params,
334+
struct netlink_ext_ack *extack)
334335
{
335-
return nfp_flash_update_common(devlink_priv(devlink), path, extack);
336+
return nfp_flash_update_common(devlink_priv(devlink), params->file_name, extack);
336337
}
337338

338339
const struct devlink_ops nfp_devlink_ops = {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
#include "ionic_devlink.h"
1111

1212
static int ionic_dl_flash_update(struct devlink *dl,
13-
const char *fwname,
14-
const char *component,
13+
struct devlink_flash_update_params *params,
1514
struct netlink_ext_ack *extack)
1615
{
1716
struct ionic *ionic = devlink_priv(dl);
1817

19-
return ionic_firmware_update(ionic->lif, fwname, extack);
18+
return ionic_firmware_update(ionic->lif, params->file_name, extack);
2019
}
2120

2221
static int ionic_dl_info_get(struct devlink *dl, struct devlink_info_req *req,

‎drivers/net/netdevsim/dev.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,8 @@ static int nsim_dev_info_get(struct devlink *devlink,
742742
#define NSIM_DEV_FLASH_CHUNK_SIZE 1000
743743
#define NSIM_DEV_FLASH_CHUNK_TIME_MS 10
744744

745-
static int nsim_dev_flash_update(struct devlink *devlink, const char *file_name,
746-
const char *component,
745+
static int nsim_dev_flash_update(struct devlink *devlink,
746+
struct devlink_flash_update_params *params,
747747
struct netlink_ext_ack *extack)
748748
{
749749
struct nsim_dev *nsim_dev = devlink_priv(devlink);
@@ -753,27 +753,27 @@ static int nsim_dev_flash_update(struct devlink *devlink, const char *file_name,
753753
devlink_flash_update_begin_notify(devlink);
754754
devlink_flash_update_status_notify(devlink,
755755
"Preparing to flash",
756-
component, 0, 0);
756+
params->component, 0, 0);
757757
}
758758

759759
for (i = 0; i < NSIM_DEV_FLASH_SIZE / NSIM_DEV_FLASH_CHUNK_SIZE; i++) {
760760
if (nsim_dev->fw_update_status)
761761
devlink_flash_update_status_notify(devlink, "Flashing",
762-
component,
762+
params->component,
763763
i * NSIM_DEV_FLASH_CHUNK_SIZE,
764764
NSIM_DEV_FLASH_SIZE);
765765
msleep(NSIM_DEV_FLASH_CHUNK_TIME_MS);
766766
}
767767

768768
if (nsim_dev->fw_update_status) {
769769
devlink_flash_update_status_notify(devlink, "Flashing",
770-
component,
770+
params->component,
771771
NSIM_DEV_FLASH_SIZE,
772772
NSIM_DEV_FLASH_SIZE);
773773
devlink_flash_update_timeout_notify(devlink, "Flash select",
774-
component, 81);
774+
params->component, 81);
775775
devlink_flash_update_status_notify(devlink, "Flashing done",
776-
component, 0, 0);
776+
params->component, 0, 0);
777777
devlink_flash_update_end_notify(devlink);
778778
}
779779

‎include/net/devlink.h‎

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

553+
/**
554+
* struct devlink_flash_update_params - Flash Update parameters
555+
* @file_name: the name of the flash firmware file to update from
556+
* @component: the flash component to update
557+
*
558+
* With the exception of file_name, drivers must opt-in to parameters by
559+
* setting the appropriate bit in the supported_flash_update_params field in
560+
* their devlink_ops structure.
561+
*/
562+
struct devlink_flash_update_params {
563+
const char *file_name;
564+
const char *component;
565+
};
566+
553567
#define DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT BIT(0)
554568

555569
struct devlink_region;
@@ -1112,8 +1126,8 @@ struct devlink_ops {
11121126
* parameters supported by the driver should be set in
11131127
* supported_flash_update_params.
11141128
*/
1115-
int (*flash_update)(struct devlink *devlink, const char *file_name,
1116-
const char *component,
1129+
int (*flash_update)(struct devlink *devlink,
1130+
struct devlink_flash_update_params *params,
11171131
struct netlink_ext_ack *extack);
11181132
/**
11191133
* @trap_init: Trap initialization function.

‎net/core/devlink.c‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3147,8 +3147,8 @@ EXPORT_SYMBOL_GPL(devlink_flash_update_timeout_notify);
31473147
static int devlink_nl_cmd_flash_update(struct sk_buff *skb,
31483148
struct genl_info *info)
31493149
{
3150+
struct devlink_flash_update_params params = {};
31503151
struct devlink *devlink = info->user_ptr[0];
3151-
const char *file_name, *component = NULL;
31523152
struct nlattr *nla_component;
31533153
u32 supported_params;
31543154

@@ -3160,7 +3160,7 @@ static int devlink_nl_cmd_flash_update(struct sk_buff *skb,
31603160

31613161
supported_params = devlink->ops->supported_flash_update_params;
31623162

3163-
file_name = nla_data(info->attrs[DEVLINK_ATTR_FLASH_UPDATE_FILE_NAME]);
3163+
params.file_name = nla_data(info->attrs[DEVLINK_ATTR_FLASH_UPDATE_FILE_NAME]);
31643164

31653165
nla_component = info->attrs[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT];
31663166
if (nla_component) {
@@ -3169,11 +3169,10 @@ static int devlink_nl_cmd_flash_update(struct sk_buff *skb,
31693169
"component update is not supported by this device");
31703170
return -EOPNOTSUPP;
31713171
}
3172-
component = nla_data(nla_component);
3172+
params.component = nla_data(nla_component);
31733173
}
31743174

3175-
return devlink->ops->flash_update(devlink, file_name, component,
3176-
info->extack);
3175+
return devlink->ops->flash_update(devlink, &params, info->extack);
31773176
}
31783177

31793178
static const struct devlink_param devlink_param_generic[] = {
@@ -9651,6 +9650,7 @@ void devlink_compat_running_version(struct net_device *dev,
96519650

96529651
int devlink_compat_flash_update(struct net_device *dev, const char *file_name)
96539652
{
9653+
struct devlink_flash_update_params params = {};
96549654
struct devlink *devlink;
96559655
int ret;
96569656

@@ -9663,8 +9663,10 @@ int devlink_compat_flash_update(struct net_device *dev, const char *file_name)
96639663
goto out;
96649664
}
96659665

9666+
params.file_name = file_name;
9667+
96669668
mutex_lock(&devlink->lock);
9667-
ret = devlink->ops->flash_update(devlink, file_name, NULL, NULL);
9669+
ret = devlink->ops->flash_update(devlink, &params, NULL);
96689670
mutex_unlock(&devlink->lock);
96699671

96709672
out:

0 commit comments

Comments
 (0)