Subject: Re: [patch net-next v2 10/12] mlxsw: core_linecards: Implement line card device flashing

From: Ido Schimmel <[email-masked]>
Date: Wed, 20 Jul 2022 13:46:25 +0300

On Tue, Jul 19, 2022 at 08:48:45AM +0200, Jiri Pirko wrote:
> From: Jiri Pirko <[email-masked]>
> 
> Implement flash_update() devlink op for the line card devlink instance
> to allow user to update line card gearbox FW using MDDT register
> and mlxfw.
> 
> Example:
> $ devlink dev flash auxiliary/mlxsw_core.lc.0 file mellanox/fw-AGB-rel-19_2010_1312-022-EVB.mfa2

Need to mention that this is only possible when line card is
active/ready

> 
> Signed-off-by: Jiri Pirko <[email-masked]>

[...]

> +int mlxsw_linecard_flash_update(struct devlink *linecard_devlink,
> +				struct mlxsw_linecard *linecard,
> +				const struct firmware *firmware,
> +				struct netlink_ext_ack *extack)
> +{
> +	struct mlxsw_core *mlxsw_core = linecard->linecards->mlxsw_core;
> +	struct mlxsw_linecard_device_fw_info info = {
> +		.mlxfw_dev = {
> +			.ops = &mlxsw_linecard_device_dev_ops,
> +			.psid = linecard->device.info.psid,
> +			.psid_size = strlen(linecard->device.info.psid),
> +			.devlink = linecard_devlink,
> +		},
> +		.mlxsw_core = mlxsw_core,
> +		.linecard = linecard,
> +	};
> +	int err;
> +
> +	mutex_lock(&linecard->lock);
> +	if (WARN_ON(!linecard->ready)) {

Can't this be easily triggered from user space when executing the above
command for a provisioned line card? If so, please remove the WARN_ON()
and add an extack

> +		err = -EINVAL;
> +		goto unlock;
> +	}
> +	err = mlxsw_core_fw_flash(mlxsw_core, &info.mlxfw_dev,
> +				  firmware, extack);
> +unlock:
> +	mutex_unlock(&linecard->lock);
> +	return err;
> +}