All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lijun Ou <oulijun@huawei.com>
To: <thomas@monjalon.net>, <ferruh.yigit@intel.com>
Cc: <dev@dpdk.org>, <linuxarm@openeuler.org>
Subject: [dpdk-dev] [PATCH 03/14] net/hns3: use array instead of switch-case
Date: Fri, 22 Jan 2021 18:18:41 +0800	[thread overview]
Message-ID: <1611310732-51975-4-git-send-email-oulijun@huawei.com> (raw)
In-Reply-To: <1611310732-51975-1-git-send-email-oulijun@huawei.com>

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 <oulijun@huawei.com>
---
 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


  parent reply	other threads:[~2021-01-22 10:20 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-22 10:18 [dpdk-dev] [PATCH 00/14] Misc updates for hns3 Lijun Ou
2021-01-22 10:18 ` [dpdk-dev] [PATCH 01/14] net/hns3: encapsulate dfx stats in Rx/Tx datapatch Lijun Ou
2021-01-22 10:18 ` [dpdk-dev] [PATCH 02/14] net/hns3: move queue stats to xstats Lijun Ou
2021-01-22 10:18 ` Lijun Ou [this message]
2021-01-22 10:18 ` [dpdk-dev] [PATCH 04/14] net/hns3: move judgment conditions to separated functions Lijun Ou
2021-01-22 10:18 ` [dpdk-dev] [PATCH 05/14] net/hns3: reconstruct the Rx interrupt map Lijun Ou
2021-01-22 10:18 ` [dpdk-dev] [PATCH 06/14] net/hns3: extract common judgments for all FDIR type Lijun Ou
2021-01-22 10:18 ` [dpdk-dev] [PATCH 07/14] net/hns3: refactor reset event report function Lijun Ou
2021-01-22 10:18 ` [dpdk-dev] [PATCH 08/14] net/hns3: fix memory leak with secondary process exit Lijun Ou
2021-01-22 10:18 ` [dpdk-dev] [PATCH 09/14] net/hns3: fix interrupt resources in Rx interrupt mode Lijun Ou
2021-01-22 10:18 ` [dpdk-dev] [PATCH 10/14] net/hns3: rename RSS functions Lijun Ou
2021-01-22 10:18 ` [dpdk-dev] [PATCH 11/14] net/hns3: adjust some comments Lijun Ou
2021-01-22 10:18 ` [dpdk-dev] [PATCH 12/14] net/hns3: remove unnecessary parentheses Lijun Ou
2021-01-22 10:18 ` [dpdk-dev] [PATCH 13/14] net/hns3: use %d instead of %u for enum variable Lijun Ou
2021-01-22 10:18 ` [dpdk-dev] [PATCH 14/14] net/hns3: support LSC event report Lijun Ou
2021-01-28 23:41   ` Ferruh Yigit
2021-01-29  1:49     ` oulijun
2021-02-02 12:06       ` Ferruh Yigit
2021-02-02 12:12   ` Ferruh Yigit
2021-01-28 23:58 ` [dpdk-dev] [PATCH 00/14] Misc updates for hns3 Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1611310732-51975-4-git-send-email-oulijun@huawei.com \
    --to=oulijun@huawei.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=linuxarm@openeuler.org \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.