mlxfw: Propagate error messages through extack
authorJiri Pirko <jiri@mellanox.com>
Tue, 4 Jun 2019 13:40:39 +0000 (15:40 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 4 Jun 2019 21:21:40 +0000 (14:21 -0700)
Currently the error messages are printed to dmesg. Propagate them also
to directly to user doing the flashing through extack.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Reviewed-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlx5/core/fw.c
drivers/net/ethernet/mellanox/mlx5/core/main.c
drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h
drivers/net/ethernet/mellanox/mlxfw/mlxfw.h
drivers/net/ethernet/mellanox/mlxfw/mlxfw_fsm.c
drivers/net/ethernet/mellanox/mlxsw/spectrum.c

index 1ab6f7e3bec6268d542e8adecccca38f295edc16..e8fedb307b2c748f20e2ba5614c60b252139185c 100644 (file)
@@ -552,7 +552,8 @@ static const struct mlxfw_dev_ops mlx5_mlxfw_dev_ops = {
 };
 
 int mlx5_firmware_flash(struct mlx5_core_dev *dev,
-                       const struct firmware *firmware)
+                       const struct firmware *firmware,
+                       struct netlink_ext_ack *extack)
 {
        struct mlx5_mlxfw_dev mlx5_mlxfw_dev = {
                .mlxfw_dev = {
@@ -571,5 +572,6 @@ int mlx5_firmware_flash(struct mlx5_core_dev *dev,
                return -EOPNOTSUPP;
        }
 
-       return mlxfw_firmware_flash(&mlx5_mlxfw_dev.mlxfw_dev, firmware);
+       return mlxfw_firmware_flash(&mlx5_mlxfw_dev.mlxfw_dev,
+                                   firmware, extack);
 }
index 2fc2162901de6d06bcd8601247f9266aad9b73d9..7ec135eaabc628d555913186c7154a23f57a564f 100644 (file)
@@ -1230,7 +1230,7 @@ static int mlx5_devlink_flash_update(struct devlink *devlink,
        if (err)
                return err;
 
-       return mlx5_firmware_flash(dev, fw);
+       return mlx5_firmware_flash(dev, fw, extack);
 }
 
 static const struct devlink_ops mlx5_devlink_ops = {
index 22e69d4813e41586baea8cbf52ff2ba0462ae42a..d4dd8c1ae55c668abb379ddadee350127165a5f3 100644 (file)
@@ -184,7 +184,8 @@ int mlx5_set_mtppse(struct mlx5_core_dev *mdev, u8 pin, u8 arm, u8 mode);
                            MLX5_CAP_MCAM_FEATURE((mdev), mtpps_fs) &&  \
                            MLX5_CAP_MCAM_FEATURE((mdev), mtpps_enh_out_per_adj))
 
-int mlx5_firmware_flash(struct mlx5_core_dev *dev, const struct firmware *fw);
+int mlx5_firmware_flash(struct mlx5_core_dev *dev, const struct firmware *fw,
+                       struct netlink_ext_ack *extack);
 
 void mlx5e_init(void);
 void mlx5e_cleanup(void);
index 14c0c62f8e737ec15dd269f9956e8260136d45b2..83286b90593f57076803664a874a10487c653cb9 100644 (file)
@@ -5,6 +5,7 @@
 #define _MLXFW_H
 
 #include <linux/firmware.h>
+#include <linux/netlink.h>
 
 enum mlxfw_fsm_state {
        MLXFW_FSM_STATE_IDLE,
@@ -67,11 +68,13 @@ struct mlxfw_dev {
 
 #if IS_REACHABLE(CONFIG_MLXFW)
 int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
-                        const struct firmware *firmware);
+                        const struct firmware *firmware,
+                        struct netlink_ext_ack *extack);
 #else
 static inline
 int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
-                        const struct firmware *firmware)
+                        const struct firmware *firmware,
+                        struct netlink_ext_ack *extack)
 {
        return -EOPNOTSUPP;
 }
index 240c027e5f07e63bd36befc834762c0b153612ac..61c32c43a309e2f598ad25b6a8f6e88b0245e898 100644 (file)
@@ -40,7 +40,8 @@ static const char * const mlxfw_fsm_state_err_str[] = {
 };
 
 static int mlxfw_fsm_state_wait(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
-                               enum mlxfw_fsm_state fsm_state)
+                               enum mlxfw_fsm_state fsm_state,
+                               struct netlink_ext_ack *extack)
 {
        enum mlxfw_fsm_state_err fsm_state_err;
        enum mlxfw_fsm_state curr_fsm_state;
@@ -57,11 +58,13 @@ retry:
        if (fsm_state_err != MLXFW_FSM_STATE_ERR_OK) {
                pr_err("Firmware flash failed: %s\n",
                       mlxfw_fsm_state_err_str[fsm_state_err]);
+               NL_SET_ERR_MSG_MOD(extack, "Firmware flash failed");
                return -EINVAL;
        }
        if (curr_fsm_state != fsm_state) {
                if (--times == 0) {
                        pr_err("Timeout reached on FSM state change");
+                       NL_SET_ERR_MSG_MOD(extack, "Timeout reached on FSM state change");
                        return -ETIMEDOUT;
                }
                msleep(MLXFW_FSM_STATE_WAIT_CYCLE_MS);
@@ -76,7 +79,8 @@ retry:
 
 static int mlxfw_flash_component(struct mlxfw_dev *mlxfw_dev,
                                 u32 fwhandle,
-                                struct mlxfw_mfa2_component *comp)
+                                struct mlxfw_mfa2_component *comp,
+                                struct netlink_ext_ack *extack)
 {
        u16 comp_max_write_size;
        u8 comp_align_bits;
@@ -96,6 +100,7 @@ static int mlxfw_flash_component(struct mlxfw_dev *mlxfw_dev,
        if (comp->data_size > comp_max_size) {
                pr_err("Component %d is of size %d which is bigger than limit %d\n",
                       comp->index, comp->data_size, comp_max_size);
+               NL_SET_ERR_MSG_MOD(extack, "Component is bigger than limit");
                return -EINVAL;
        }
 
@@ -110,7 +115,7 @@ static int mlxfw_flash_component(struct mlxfw_dev *mlxfw_dev,
                return err;
 
        err = mlxfw_fsm_state_wait(mlxfw_dev, fwhandle,
-                                  MLXFW_FSM_STATE_DOWNLOAD);
+                                  MLXFW_FSM_STATE_DOWNLOAD, extack);
        if (err)
                goto err_out;
 
@@ -134,7 +139,8 @@ static int mlxfw_flash_component(struct mlxfw_dev *mlxfw_dev,
        if (err)
                goto err_out;
 
-       err = mlxfw_fsm_state_wait(mlxfw_dev, fwhandle, MLXFW_FSM_STATE_LOCKED);
+       err = mlxfw_fsm_state_wait(mlxfw_dev, fwhandle,
+                                  MLXFW_FSM_STATE_LOCKED, extack);
        if (err)
                goto err_out;
        return 0;
@@ -145,7 +151,8 @@ err_out:
 }
 
 static int mlxfw_flash_components(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
-                                 struct mlxfw_mfa2_file *mfa2_file)
+                                 struct mlxfw_mfa2_file *mfa2_file,
+                                 struct netlink_ext_ack *extack)
 {
        u32 component_count;
        int err;
@@ -156,6 +163,7 @@ static int mlxfw_flash_components(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
                                              &component_count);
        if (err) {
                pr_err("Could not find device PSID in MFA2 file\n");
+               NL_SET_ERR_MSG_MOD(extack, "Could not find device PSID in MFA2 file");
                return err;
        }
 
@@ -168,7 +176,7 @@ static int mlxfw_flash_components(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
                        return PTR_ERR(comp);
 
                pr_info("Flashing component type %d\n", comp->index);
-               err = mlxfw_flash_component(mlxfw_dev, fwhandle, comp);
+               err = mlxfw_flash_component(mlxfw_dev, fwhandle, comp, extack);
                mlxfw_mfa2_file_component_put(comp);
                if (err)
                        return err;
@@ -177,7 +185,8 @@ static int mlxfw_flash_components(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
 }
 
 int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
-                        const struct firmware *firmware)
+                        const struct firmware *firmware,
+                        struct netlink_ext_ack *extack)
 {
        struct mlxfw_mfa2_file *mfa2_file;
        u32 fwhandle;
@@ -185,6 +194,7 @@ int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
 
        if (!mlxfw_mfa2_check(firmware)) {
                pr_err("Firmware file is not MFA2\n");
+               NL_SET_ERR_MSG_MOD(extack, "Firmware file is not MFA2");
                return -EINVAL;
        }
 
@@ -196,15 +206,16 @@ int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
        err = mlxfw_dev->ops->fsm_lock(mlxfw_dev, &fwhandle);
        if (err) {
                pr_err("Could not lock the firmware FSM\n");
+               NL_SET_ERR_MSG_MOD(extack, "Could not lock the firmware FSM");
                goto err_fsm_lock;
        }
 
        err = mlxfw_fsm_state_wait(mlxfw_dev, fwhandle,
-                                  MLXFW_FSM_STATE_LOCKED);
+                                  MLXFW_FSM_STATE_LOCKED, extack);
        if (err)
                goto err_state_wait_idle_to_locked;
 
-       err = mlxfw_flash_components(mlxfw_dev, fwhandle, mfa2_file);
+       err = mlxfw_flash_components(mlxfw_dev, fwhandle, mfa2_file, extack);
        if (err)
                goto err_flash_components;
 
@@ -212,10 +223,12 @@ int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
        err = mlxfw_dev->ops->fsm_activate(mlxfw_dev, fwhandle);
        if (err) {
                pr_err("Could not activate the downloaded image\n");
+               NL_SET_ERR_MSG_MOD(extack, "Could not activate the downloaded image");
                goto err_fsm_activate;
        }
 
-       err = mlxfw_fsm_state_wait(mlxfw_dev, fwhandle, MLXFW_FSM_STATE_LOCKED);
+       err = mlxfw_fsm_state_wait(mlxfw_dev, fwhandle,
+                                  MLXFW_FSM_STATE_LOCKED, extack);
        if (err)
                goto err_state_wait_activate_to_locked;
 
index 6f9ca943f50d520a09e24e860a94dec443e23555..2cba678863bd857f66f49e944453c91f12e6496e 100644 (file)
@@ -307,7 +307,8 @@ static const struct mlxfw_dev_ops mlxsw_sp_mlxfw_dev_ops = {
 };
 
 static int mlxsw_sp_firmware_flash(struct mlxsw_sp *mlxsw_sp,
-                                  const struct firmware *firmware)
+                                  const struct firmware *firmware,
+                                  struct netlink_ext_ack *extack)
 {
        struct mlxsw_sp_mlxfw_dev mlxsw_sp_mlxfw_dev = {
                .mlxfw_dev = {
@@ -320,7 +321,8 @@ static int mlxsw_sp_firmware_flash(struct mlxsw_sp *mlxsw_sp,
        int err;
 
        mlxsw_core_fw_flash_start(mlxsw_sp->core);
-       err = mlxfw_firmware_flash(&mlxsw_sp_mlxfw_dev.mlxfw_dev, firmware);
+       err = mlxfw_firmware_flash(&mlxsw_sp_mlxfw_dev.mlxfw_dev,
+                                  firmware, extack);
        mlxsw_core_fw_flash_end(mlxsw_sp->core);
 
        return err;
@@ -374,7 +376,7 @@ static int mlxsw_sp_fw_rev_validate(struct mlxsw_sp *mlxsw_sp)
                return err;
        }
 
-       err = mlxsw_sp_firmware_flash(mlxsw_sp, firmware);
+       err = mlxsw_sp_firmware_flash(mlxsw_sp, firmware, NULL);
        release_firmware(firmware);
        if (err)
                dev_err(mlxsw_sp->bus_info->dev, "Could not upgrade firmware\n");
@@ -403,7 +405,7 @@ static int mlxsw_sp_flash_update(struct mlxsw_core *mlxsw_core,
                                      mlxsw_sp->bus_info->dev);
        if (err)
                return err;
-       err = mlxsw_sp_firmware_flash(mlxsw_sp, firmware);
+       err = mlxsw_sp_firmware_flash(mlxsw_sp, firmware, extack);
        release_firmware(firmware);
 
        return err;