diff mbox series

[V2,net-next,3/6] net/mlxfw: Improve FSM err message reporting and return codes

Message ID 20191122224126.24847-4-saeedm@mellanox.com
State Changes Requested
Delegated to: David Miller
Headers show
Series mlxfw: Improve error reporting | expand

Commit Message

Saeed Mahameed Nov. 22, 2019, 10:41 p.m. UTC
Report unique and standard error codes corresponding to the specific
FW flash error and report more detailed error messages to netlink.

Before:
$ devlink dev flash pci/0000:05:00.0 file ...
Error: mlxfw: Firmware flash failed.
devlink answers: Invalid argument

After:
$ devlink dev flash pci/0000:05:00.0 file ...
Error: mlxfw: Firmware flash failed: pending reset.
devlink answers: Operation already in progress

Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
Reviewed-by: Ido Schimmel <idosch@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
---
 .../net/ethernet/mellanox/mlxfw/mlxfw_fsm.c   | 35 +++++++++++++++----
 1 file changed, 29 insertions(+), 6 deletions(-)

Comments

Jakub Kicinski Nov. 24, 2019, 1 a.m. UTC | #1
On Fri, 22 Nov 2019 22:41:50 +0000, Saeed Mahameed wrote:
> +	NL_SET_ERR_MSG_MOD(extack, MLXFW_ERR_PRFX "%s",
> +			   mlxfw_fsm_state_err_str[fsm_state_err]);

Things like this also require a word of comment, because the intention
of wrapping all extact strings into the macro IIRC was to mark them for
possible translation. 

IDK if we still care about that (IMHO we should), we probably need at
least a new macro for cases like this so the strings in the error table
are marked for extraction for translators as well, no?
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlxfw/mlxfw_fsm.c b/drivers/net/ethernet/mellanox/mlxfw/mlxfw_fsm.c
index 663eac994a5c..803152ab6914 100644
--- a/drivers/net/ethernet/mellanox/mlxfw/mlxfw_fsm.c
+++ b/drivers/net/ethernet/mellanox/mlxfw/mlxfw_fsm.c
@@ -39,6 +39,32 @@  static const char * const mlxfw_fsm_state_err_str[] = {
 		"unknown error"
 };
 
+static const int mlxfw_fsm_state_errno[] = {
+	[MLXFW_FSM_STATE_ERR_ERROR] = -EREMOTEIO,
+	[MLXFW_FSM_STATE_ERR_REJECTED_DIGEST_ERR] = -EBADMSG,
+	[MLXFW_FSM_STATE_ERR_REJECTED_NOT_APPLICABLE] = -ENOENT,
+	[MLXFW_FSM_STATE_ERR_REJECTED_UNKNOWN_KEY] = -ENOKEY,
+	[MLXFW_FSM_STATE_ERR_REJECTED_AUTH_FAILED] = -EACCES,
+	[MLXFW_FSM_STATE_ERR_REJECTED_UNSIGNED] = -EKEYREVOKED,
+	[MLXFW_FSM_STATE_ERR_REJECTED_KEY_NOT_APPLICABLE] = -EKEYREJECTED,
+	[MLXFW_FSM_STATE_ERR_REJECTED_BAD_FORMAT] = -ENOEXEC,
+	[MLXFW_FSM_STATE_ERR_BLOCKED_PENDING_RESET] = -EALREADY,
+	[MLXFW_FSM_STATE_ERR_MAX] = -EINVAL
+};
+
+static int mlxfw_fsm_state_err(struct netlink_ext_ack *extack,
+			       enum mlxfw_fsm_state_err fsm_state_err)
+{
+#define MLXFW_ERR_PRFX "Firmware flash failed: "
+
+	fsm_state_err = min_t(enum mlxfw_fsm_state_err, fsm_state_err,
+			      MLXFW_FSM_STATE_ERR_MAX);
+	pr_err(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]);
+	return mlxfw_fsm_state_errno[fsm_state_err];
+};
+
 static int mlxfw_fsm_state_wait(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
 				enum mlxfw_fsm_state fsm_state,
 				struct netlink_ext_ack *extack)
@@ -55,12 +81,9 @@  static int mlxfw_fsm_state_wait(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
 	if (err)
 		return err;
 
-	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 (fsm_state_err != MLXFW_FSM_STATE_ERR_OK)
+		return mlxfw_fsm_state_err(extack, fsm_state_err);
+
 	if (curr_fsm_state != fsm_state) {
 		if (--times == 0) {
 			pr_err("Timeout reached on FSM state change");