Commit 1c9a98b0 authored by Peng Li's avatar Peng Li Committed by David S. Miller

net: hns3: refactor out hclge_cmd_convert_err_code()

To improve code readability and maintainability, refactor
hclge_cmd_convert_err_code() with an array of imp_errcode
and common_errno mapping, instead of a bloated switch/case.
Signed-off-by: default avatarPeng Li <lipeng321@huawei.com>
Signed-off-by: default avatarHuazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4fb37e72
...@@ -189,36 +189,35 @@ static bool hclge_is_special_opcode(u16 opcode) ...@@ -189,36 +189,35 @@ static bool hclge_is_special_opcode(u16 opcode)
return false; return false;
} }
struct errcode {
u32 imp_errcode;
int common_errno;
};
static int hclge_cmd_convert_err_code(u16 desc_ret) static int hclge_cmd_convert_err_code(u16 desc_ret)
{ {
switch (desc_ret) { struct errcode hclge_cmd_errcode[] = {
case HCLGE_CMD_EXEC_SUCCESS: {HCLGE_CMD_EXEC_SUCCESS, 0},
return 0; {HCLGE_CMD_NO_AUTH, -EPERM},
case HCLGE_CMD_NO_AUTH: {HCLGE_CMD_NOT_SUPPORTED, -EOPNOTSUPP},
return -EPERM; {HCLGE_CMD_QUEUE_FULL, -EXFULL},
case HCLGE_CMD_NOT_SUPPORTED: {HCLGE_CMD_NEXT_ERR, -ENOSR},
return -EOPNOTSUPP; {HCLGE_CMD_UNEXE_ERR, -ENOTBLK},
case HCLGE_CMD_QUEUE_FULL: {HCLGE_CMD_PARA_ERR, -EINVAL},
return -EXFULL; {HCLGE_CMD_RESULT_ERR, -ERANGE},
case HCLGE_CMD_NEXT_ERR: {HCLGE_CMD_TIMEOUT, -ETIME},
return -ENOSR; {HCLGE_CMD_HILINK_ERR, -ENOLINK},
case HCLGE_CMD_UNEXE_ERR: {HCLGE_CMD_QUEUE_ILLEGAL, -ENXIO},
return -ENOTBLK; {HCLGE_CMD_INVALID, -EBADR},
case HCLGE_CMD_PARA_ERR: };
return -EINVAL; u32 errcode_count = ARRAY_SIZE(hclge_cmd_errcode);
case HCLGE_CMD_RESULT_ERR: u32 i;
return -ERANGE;
case HCLGE_CMD_TIMEOUT: for (i = 0; i < errcode_count; i++)
return -ETIME; if (hclge_cmd_errcode[i].imp_errcode == desc_ret)
case HCLGE_CMD_HILINK_ERR: return hclge_cmd_errcode[i].common_errno;
return -ENOLINK;
case HCLGE_CMD_QUEUE_ILLEGAL: return -EIO;
return -ENXIO;
case HCLGE_CMD_INVALID:
return -EBADR;
default:
return -EIO;
}
} }
static int hclge_cmd_check_retval(struct hclge_hw *hw, struct hclge_desc *desc, static int hclge_cmd_check_retval(struct hclge_hw *hw, struct hclge_desc *desc,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment