Commit 433e2802 authored by Peng Li's avatar Peng Li Committed by David S. Miller

net: hns3: refactor out hclgevf_cmd_convert_err_code()

To improve code readability and maintainability, refactor
hclgevf_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 1c9a98b0
...@@ -176,36 +176,35 @@ void hclgevf_cmd_setup_basic_desc(struct hclgevf_desc *desc, ...@@ -176,36 +176,35 @@ void hclgevf_cmd_setup_basic_desc(struct hclgevf_desc *desc,
desc->flag &= cpu_to_le16(~HCLGEVF_CMD_FLAG_WR); desc->flag &= cpu_to_le16(~HCLGEVF_CMD_FLAG_WR);
} }
struct vf_errcode {
u32 imp_errcode;
int common_errno;
};
static int hclgevf_cmd_convert_err_code(u16 desc_ret) static int hclgevf_cmd_convert_err_code(u16 desc_ret)
{ {
switch (desc_ret) { struct vf_errcode hclgevf_cmd_errcode[] = {
case HCLGEVF_CMD_EXEC_SUCCESS: {HCLGEVF_CMD_EXEC_SUCCESS, 0},
return 0; {HCLGEVF_CMD_NO_AUTH, -EPERM},
case HCLGEVF_CMD_NO_AUTH: {HCLGEVF_CMD_NOT_SUPPORTED, -EOPNOTSUPP},
return -EPERM; {HCLGEVF_CMD_QUEUE_FULL, -EXFULL},
case HCLGEVF_CMD_NOT_SUPPORTED: {HCLGEVF_CMD_NEXT_ERR, -ENOSR},
return -EOPNOTSUPP; {HCLGEVF_CMD_UNEXE_ERR, -ENOTBLK},
case HCLGEVF_CMD_QUEUE_FULL: {HCLGEVF_CMD_PARA_ERR, -EINVAL},
return -EXFULL; {HCLGEVF_CMD_RESULT_ERR, -ERANGE},
case HCLGEVF_CMD_NEXT_ERR: {HCLGEVF_CMD_TIMEOUT, -ETIME},
return -ENOSR; {HCLGEVF_CMD_HILINK_ERR, -ENOLINK},
case HCLGEVF_CMD_UNEXE_ERR: {HCLGEVF_CMD_QUEUE_ILLEGAL, -ENXIO},
return -ENOTBLK; {HCLGEVF_CMD_INVALID, -EBADR},
case HCLGEVF_CMD_PARA_ERR: };
return -EINVAL; u32 errcode_count = ARRAY_SIZE(hclgevf_cmd_errcode);
case HCLGEVF_CMD_RESULT_ERR: u32 i;
return -ERANGE;
case HCLGEVF_CMD_TIMEOUT: for (i = 0; i < errcode_count; i++)
return -ETIME; if (hclgevf_cmd_errcode[i].imp_errcode == desc_ret)
case HCLGEVF_CMD_HILINK_ERR: return hclgevf_cmd_errcode[i].common_errno;
return -ENOLINK;
case HCLGEVF_CMD_QUEUE_ILLEGAL: return -EIO;
return -ENXIO;
case HCLGEVF_CMD_INVALID:
return -EBADR;
default:
return -EIO;
}
} }
/* hclgevf_cmd_send - send command to command queue /* hclgevf_cmd_send - send command to command queue
......
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