[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20191122224126.24847-7-saeedm@mellanox.com>
Date: Fri, 22 Nov 2019 22:41:55 +0000
From: Saeed Mahameed <saeedm@...lanox.com>
To: "David S. Miller" <davem@...emloft.net>
CC: "netdev@...r.kernel.org" <netdev@...r.kernel.org>,
Jiri Pirko <jiri@...lanox.com>,
Saeed Mahameed <saeedm@...lanox.com>
Subject: [PATCH V2 net-next 6/6] net/mlxfw: Macro for error reporting
Add a macro to simplify error message reporting, instead of always
calling both mlxfw_err and NL_SET_ERR_MSG_MOD with the same message,
use a macro instead.
This is doable now since NL_SET_ERR_MSG_MOD can accept formattable
messages.
Signed-off-by: Saeed Mahameed <saeedm@...lanox.com>
Acked-by: Jiri Pirko <jiri@...lanox.com>
---
.../net/ethernet/mellanox/mlxfw/mlxfw_fsm.c | 78 ++++++++++---------
1 file changed, 41 insertions(+), 37 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlxfw/mlxfw_fsm.c b/drivers/net/ethernet/mellanox/mlxfw/mlxfw_fsm.c
index 2726f17a68fe..cc333368a367 100644
--- a/drivers/net/ethernet/mellanox/mlxfw/mlxfw_fsm.c
+++ b/drivers/net/ethernet/mellanox/mlxfw/mlxfw_fsm.c
@@ -52,6 +52,12 @@ static const int mlxfw_fsm_state_errno[] = {
[MLXFW_FSM_STATE_ERR_MAX] = -EINVAL
};
+#define MLXFW_ERR_MSG(mlxfw_dev, extack, fmt, ...) \
+({ \
+ mlxfw_err(mlxfw_dev, fmt "\n", ## __VA_ARGS__); \
+ NL_SET_ERR_MSG_MOD(extack, fmt, ## __VA_ARGS__);\
+})
+
static int mlxfw_fsm_state_err(struct mlxfw_dev *mlxfw_dev,
struct netlink_ext_ack *extack,
enum mlxfw_fsm_state_err fsm_state_err)
@@ -61,10 +67,8 @@ static int mlxfw_fsm_state_err(struct mlxfw_dev *mlxfw_dev,
fsm_state_err = min_t(enum mlxfw_fsm_state_err, fsm_state_err,
MLXFW_FSM_STATE_ERR_MAX);
- mlxfw_err(mlxfw_dev, MLXFW_ERR_PRFX "%s\n",
- mlxfw_fsm_state_err_str[fsm_state_err]);
- NL_SET_ERR_MSG_MOD(extack, MLXFW_ERR_PRFX "%s",
- mlxfw_fsm_state_err_str[fsm_state_err]);
+ MLXFW_ERR_MSG(mlxfw_dev, extack, MLXFW_ERR_PRFX "%s",
+ mlxfw_fsm_state_err_str[fsm_state_err]);
return mlxfw_fsm_state_errno[fsm_state_err];
};
@@ -82,8 +86,8 @@ static int mlxfw_fsm_state_wait(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
err = mlxfw_dev->ops->fsm_query_state(mlxfw_dev, fwhandle,
&curr_fsm_state, &fsm_state_err);
if (err) {
- NL_SET_ERR_MSG_MOD(extack, "FSM state query failed, err (%d)",
- err);
+ MLXFW_ERR_MSG(mlxfw_dev, extack, "FSM state query failed, err (%d)",
+ err);
return err;
}
@@ -92,8 +96,8 @@ static int mlxfw_fsm_state_wait(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
if (curr_fsm_state != fsm_state) {
if (--times == 0) {
- mlxfw_err(mlxfw_dev, "Timeout reached on FSM state change\n");
- NL_SET_ERR_MSG_MOD(extack, "Timeout reached on FSM state change");
+ MLXFW_ERR_MSG(mlxfw_dev, extack,
+ "Timeout reached on FSM state change");
return -ETIMEDOUT;
}
msleep(MLXFW_FSM_STATE_WAIT_CYCLE_MS);
@@ -134,17 +138,17 @@ static int mlxfw_flash_component(struct mlxfw_dev *mlxfw_dev,
&comp_max_size, &comp_align_bits,
&comp_max_write_size);
if (err) {
- NL_SET_ERR_MSG_MOD(extack,
- "FSM component query failed, comp_name(%s) err (%d)",
- comp_name, err);
+ MLXFW_ERR_MSG(mlxfw_dev, extack,
+ "FSM component query failed, comp_name(%s) err (%d)",
+ comp_name, err);
return err;
}
comp_max_size = min_t(u32, comp_max_size, MLXFW_FSM_MAX_COMPONENT_SIZE);
if (comp->data_size > comp_max_size) {
- mlxfw_err(mlxfw_dev, "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");
+ MLXFW_ERR_MSG(mlxfw_dev, extack,
+ "Component size is bigger than limit, Component %d size %d limit %d",
+ comp->index, comp->data_size, comp_max_size);
return -EINVAL;
}
@@ -157,9 +161,9 @@ static int mlxfw_flash_component(struct mlxfw_dev *mlxfw_dev,
comp->index,
comp->data_size);
if (err) {
- NL_SET_ERR_MSG_MOD(extack,
- "FSM component update failed, comp_name(%s) err (%d)",
- comp_name, err);
+ MLXFW_ERR_MSG(mlxfw_dev, extack,
+ "FSM component update failed, comp_name(%s) err (%d)",
+ comp_name, err);
return err;
}
@@ -181,9 +185,9 @@ static int mlxfw_flash_component(struct mlxfw_dev *mlxfw_dev,
block_ptr, block_size,
offset);
if (err) {
- NL_SET_ERR_MSG_MOD(extack,
- "Component download failed, comp_name(%s) err (%d)",
- comp_name, err);
+ MLXFW_ERR_MSG(mlxfw_dev, extack,
+ "Component download failed, comp_name(%s) err (%d)",
+ comp_name, err);
goto err_out;
}
mlxfw_status_notify(mlxfw_dev, "Downloading component",
@@ -196,9 +200,9 @@ static int mlxfw_flash_component(struct mlxfw_dev *mlxfw_dev,
err = mlxfw_dev->ops->fsm_component_verify(mlxfw_dev, fwhandle,
comp->index);
if (err) {
- NL_SET_ERR_MSG_MOD(extack,
- "FSM component verify failed, comp_name(%s) err (%d)",
- comp_name, err);
+ MLXFW_ERR_MSG(mlxfw_dev, extack,
+ "FSM component verify failed, comp_name(%s) err (%d)",
+ comp_name, err);
goto err_out;
}
@@ -225,8 +229,9 @@ static int mlxfw_flash_components(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
mlxfw_dev->psid_size,
&component_count);
if (err) {
- mlxfw_err(mlxfw_dev, "Could not find device PSID in MFA2 file\n");
- NL_SET_ERR_MSG_MOD(extack, "Could not find device PSID in MFA2 file");
+ MLXFW_ERR_MSG(mlxfw_dev, extack,
+ "Could not find device PSID in MFA2 file, err (%d)",
+ err);
return err;
}
@@ -237,9 +242,9 @@ static int mlxfw_flash_components(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
mlxfw_dev->psid_size, i);
if (IS_ERR(comp)) {
err = PTR_ERR(comp);
- NL_SET_ERR_MSG_MOD(extack,
- "Failed to get MFA2 component, component (%d) err (%d)",
- i, err);
+ MLXFW_ERR_MSG(mlxfw_dev, extack,
+ "Failed to get MFA2 component, component (%d) err (%d)",
+ i, err);
return err;
}
@@ -262,17 +267,16 @@ int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
int err;
if (!mlxfw_mfa2_check(firmware)) {
- mlxfw_err(mlxfw_dev, "Firmware file is not MFA2\n");
- NL_SET_ERR_MSG_MOD(extack, "Firmware file is not MFA2");
+ MLXFW_ERR_MSG(mlxfw_dev, extack, "Firmware file is not MFA2");
return -EINVAL;
}
mfa2_file = mlxfw_mfa2_file_init(firmware);
if (IS_ERR(mfa2_file)) {
err = PTR_ERR(mfa2_file);
- NL_SET_ERR_MSG_MOD(extack,
- "Failed to initialize MFA2 firmware file, err (%d)",
- err);
+ MLXFW_ERR_MSG(mlxfw_dev, extack,
+ "Failed to initialize MFA2 firmware file, err (%d)",
+ err);
return err;
}
@@ -282,8 +286,8 @@ int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
NULL, 0, 0);
err = mlxfw_dev->ops->fsm_lock(mlxfw_dev, &fwhandle);
if (err) {
- mlxfw_err(mlxfw_dev, "Could not lock the firmware FSM\n");
- NL_SET_ERR_MSG_MOD(extack, "Could not lock the firmware FSM");
+ MLXFW_ERR_MSG(mlxfw_dev, extack,
+ "Could not lock the firmware FSM, err (%d)", err);
goto err_fsm_lock;
}
@@ -300,8 +304,8 @@ int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
mlxfw_status_notify(mlxfw_dev, "Activating image", NULL, 0, 0);
err = mlxfw_dev->ops->fsm_activate(mlxfw_dev, fwhandle);
if (err) {
- mlxfw_err(mlxfw_dev, "Could not activate the downloaded image\n");
- NL_SET_ERR_MSG_MOD(extack, "Could not activate the downloaded image");
+ MLXFW_ERR_MSG(mlxfw_dev, extack,
+ "Could not activate the downloaded image, err (%d)", err);
goto err_fsm_activate;
}
--
2.21.0
Powered by blists - more mailing lists