From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 69C5AA0A0A; Fri, 22 Jan 2021 11:20:46 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 36EFD140F59; Fri, 22 Jan 2021 11:19:31 +0100 (CET) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by mails.dpdk.org (Postfix) with ESMTP id B0B6B140F0C for ; Fri, 22 Jan 2021 11:19:17 +0100 (CET) Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DMZvy0BWRzjBy6; Fri, 22 Jan 2021 18:18:06 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Fri, 22 Jan 2021 18:19:10 +0800 From: Lijun Ou To: , CC: , Date: Fri, 22 Jan 2021 18:18:41 +0800 Message-ID: <1611310732-51975-4-git-send-email-oulijun@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1611310732-51975-1-git-send-email-oulijun@huawei.com> References: <1611310732-51975-1-git-send-email-oulijun@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH 03/14] net/hns3: use array instead of switch-case X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Heres uses errno array instead of switch-case for refactor the hns3_cmd_convert_err_code function. Besides, we add a type for ROH(RDMA Over HCCS) check cmdq return error in Kunpeng930 NIC hardware. Signed-off-by: Lijun Ou --- drivers/net/hns3/hns3_cmd.c | 54 ++++++++++++++++++++++----------------------- drivers/net/hns3/hns3_cmd.h | 1 + 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/drivers/net/hns3/hns3_cmd.c b/drivers/net/hns3/hns3_cmd.c index f58f4f7..4c301cb 100644 --- a/drivers/net/hns3/hns3_cmd.c +++ b/drivers/net/hns3/hns3_cmd.c @@ -247,34 +247,32 @@ hns3_is_special_opcode(uint16_t opcode) static int hns3_cmd_convert_err_code(uint16_t desc_ret) { - switch (desc_ret) { - case HNS3_CMD_EXEC_SUCCESS: - return 0; - case HNS3_CMD_NO_AUTH: - return -EPERM; - case HNS3_CMD_NOT_SUPPORTED: - return -EOPNOTSUPP; - case HNS3_CMD_QUEUE_FULL: - return -EXFULL; - case HNS3_CMD_NEXT_ERR: - return -ENOSR; - case HNS3_CMD_UNEXE_ERR: - return -ENOTBLK; - case HNS3_CMD_PARA_ERR: - return -EINVAL; - case HNS3_CMD_RESULT_ERR: - return -ERANGE; - case HNS3_CMD_TIMEOUT: - return -ETIME; - case HNS3_CMD_HILINK_ERR: - return -ENOLINK; - case HNS3_CMD_QUEUE_ILLEGAL: - return -ENXIO; - case HNS3_CMD_INVALID: - return -EBADR; - default: - return -EREMOTEIO; - } + static const struct { + uint16_t imp_errcode; + int linux_errcode; + } hns3_cmdq_status[] = { + {HNS3_CMD_EXEC_SUCCESS, 0}, + {HNS3_CMD_NO_AUTH, -EPERM}, + {HNS3_CMD_NOT_SUPPORTED, -EOPNOTSUPP}, + {HNS3_CMD_QUEUE_FULL, -EXFULL}, + {HNS3_CMD_NEXT_ERR, -ENOSR}, + {HNS3_CMD_UNEXE_ERR, -ENOTBLK}, + {HNS3_CMD_PARA_ERR, -EINVAL}, + {HNS3_CMD_RESULT_ERR, -ERANGE}, + {HNS3_CMD_TIMEOUT, -ETIME}, + {HNS3_CMD_HILINK_ERR, -ENOLINK}, + {HNS3_CMD_QUEUE_ILLEGAL, -ENXIO}, + {HNS3_CMD_INVALID, -EBADR}, + {HNS3_CMD_ROH_CHECK_FAIL, -EINVAL} + }; + + uint32_t i; + + for (i = 0; i < ARRAY_SIZE(hns3_cmdq_status); i++) + if (hns3_cmdq_status[i].imp_errcode == desc_ret) + return hns3_cmdq_status[i].linux_errcode; + + return -EREMOTEIO; } static int diff --git a/drivers/net/hns3/hns3_cmd.h b/drivers/net/hns3/hns3_cmd.h index e40293b..6152f6e 100644 --- a/drivers/net/hns3/hns3_cmd.h +++ b/drivers/net/hns3/hns3_cmd.h @@ -52,6 +52,7 @@ enum hns3_cmd_return_status { HNS3_CMD_HILINK_ERR = 9, HNS3_CMD_QUEUE_ILLEGAL = 10, HNS3_CMD_INVALID = 11, + HNS3_CMD_ROH_CHECK_FAIL = 12 }; enum hns3_cmd_status { -- 2.7.4