All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lijun Ou <oulijun@huawei.com>
To: <dledford@redhat.com>, <jgg@ziepe.ca>
Cc: <leon@kernel.org>, <linux-rdma@vger.kernel.org>, <linuxarm@huawei.com>
Subject: [PATCH V4 for-next 11/14] RDMA/hns: Refactor hns_roce_v2_set_hem for hip08
Date: Thu, 8 Aug 2019 22:53:51 +0800	[thread overview]
Message-ID: <1565276034-97329-12-git-send-email-oulijun@huawei.com> (raw)
In-Reply-To: <1565276034-97329-1-git-send-email-oulijun@huawei.com>

From: Yangyang Li <liyangyang20@huawei.com>

In order to reduce the complexity of hns_roce_v2_set_hem, extract
the implementation of op as a function.

Signed-off-by: Yangyang Li <liyangyang20@huawei.com>
---
 drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 75 +++++++++++++++++-------------
 1 file changed, 42 insertions(+), 33 deletions(-)

diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
index de02612..c7f1585 100644
--- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
+++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
@@ -2903,11 +2903,49 @@ static int hns_roce_v2_poll_cq(struct ib_cq *ibcq, int num_entries,
 	return npolled;
 }
 
+static int get_op_for_set_hem(struct hns_roce_dev *hr_dev, u32 type,
+			      int step_idx)
+{
+	int op;
+
+	if (type == HEM_TYPE_SCCC && step_idx)
+		return -EINVAL;
+
+	switch (type) {
+	case HEM_TYPE_QPC:
+		op = HNS_ROCE_CMD_WRITE_QPC_BT0;
+		break;
+	case HEM_TYPE_MTPT:
+		op = HNS_ROCE_CMD_WRITE_MPT_BT0;
+		break;
+	case HEM_TYPE_CQC:
+		op = HNS_ROCE_CMD_WRITE_CQC_BT0;
+		break;
+	case HEM_TYPE_SRQC:
+		op = HNS_ROCE_CMD_WRITE_SRQC_BT0;
+		break;
+	case HEM_TYPE_SCCC:
+		op = HNS_ROCE_CMD_WRITE_SCCC_BT0;
+		break;
+	case HEM_TYPE_QPC_TIMER:
+		op = HNS_ROCE_CMD_WRITE_QPC_TIMER_BT0;
+		break;
+	case HEM_TYPE_CQC_TIMER:
+		op = HNS_ROCE_CMD_WRITE_CQC_TIMER_BT0;
+		break;
+	default:
+		dev_warn(hr_dev->dev,
+			 "Table %d not to be written by mailbox!\n", type);
+		return -EINVAL;
+	}
+
+	return op + step_idx;
+}
+
 static int hns_roce_v2_set_hem(struct hns_roce_dev *hr_dev,
 			       struct hns_roce_hem_table *table, int obj,
 			       int step_idx)
 {
-	struct device *dev = hr_dev->dev;
 	struct hns_roce_cmd_mailbox *mailbox;
 	struct hns_roce_hem_iter iter;
 	struct hns_roce_hem_mhop mhop;
@@ -2920,7 +2958,7 @@ static int hns_roce_v2_set_hem(struct hns_roce_dev *hr_dev,
 	u64 bt_ba = 0;
 	u32 chunk_ba_num;
 	u32 hop_num;
-	u16 op = 0xff;
+	int op;
 
 	if (!hns_roce_check_whether_mhop(hr_dev, table->type))
 		return 0;
@@ -2942,38 +2980,9 @@ static int hns_roce_v2_set_hem(struct hns_roce_dev *hr_dev,
 		hem_idx = i;
 	}
 
-	switch (table->type) {
-	case HEM_TYPE_QPC:
-		op = HNS_ROCE_CMD_WRITE_QPC_BT0;
-		break;
-	case HEM_TYPE_MTPT:
-		op = HNS_ROCE_CMD_WRITE_MPT_BT0;
-		break;
-	case HEM_TYPE_CQC:
-		op = HNS_ROCE_CMD_WRITE_CQC_BT0;
-		break;
-	case HEM_TYPE_SRQC:
-		op = HNS_ROCE_CMD_WRITE_SRQC_BT0;
-		break;
-	case HEM_TYPE_SCCC:
-		op = HNS_ROCE_CMD_WRITE_SCCC_BT0;
-		break;
-	case HEM_TYPE_QPC_TIMER:
-		op = HNS_ROCE_CMD_WRITE_QPC_TIMER_BT0;
-		break;
-	case HEM_TYPE_CQC_TIMER:
-		op = HNS_ROCE_CMD_WRITE_CQC_TIMER_BT0;
-		break;
-	default:
-		dev_warn(dev, "Table %d not to be written by mailbox!\n",
-			 table->type);
+	op = get_op_for_set_hem(hr_dev, table->type, step_idx);
+	if (op == -EINVAL)
 		return 0;
-	}
-
-	if (table->type == HEM_TYPE_SCCC && step_idx)
-		return 0;
-
-	op += step_idx;
 
 	mailbox = hns_roce_alloc_cmd_mailbox(hr_dev);
 	if (IS_ERR(mailbox))
-- 
1.9.1


  parent reply	other threads:[~2019-08-08 14:58 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-08 14:53 [PATCH V4 for-next 00/14] Updates for 5.3-rc2 Lijun Ou
2019-08-08 14:53 ` [PATCH V4 for-next 01/14] RDMA/hns: Encapsulate some lines for setting sq size in user mode Lijun Ou
2019-08-08 14:53 ` [PATCH V4 for-next 02/14] RDMA/hns: Optimize hns_roce_modify_qp function Lijun Ou
2019-08-08 14:53 ` [PATCH V4 for-next 03/14] RDMA/hns: Update the prompt message for creating and destroy qp Lijun Ou
2019-08-12 14:47   ` Doug Ledford
2019-08-08 14:53 ` [PATCH V4 for-next 04/14] RDMA/hns: Remove unnessary init for cmq reg Lijun Ou
2019-08-08 14:53 ` [PATCH V4 for-next 05/14] RDMA/hns: Clean up unnecessary initial assignment Lijun Ou
2019-08-08 14:53 ` [PATCH V4 for-next 06/14] RDMA/hns: Update some comments style Lijun Ou
2019-08-08 14:53 ` [PATCH V4 for-next 07/14] RDMA/hns: Handling the error return value of hem function Lijun Ou
2019-08-08 14:53 ` [PATCH V4 for-next 08/14] RDMA/hns: Split bool statement and assign statement Lijun Ou
2019-08-08 14:53 ` [PATCH V4 for-next 09/14] RDMA/hns: Refactor irq request code Lijun Ou
2019-08-08 14:53 ` [PATCH V4 for-next 10/14] RDMA/hns: Remove unnecessary kzalloc Lijun Ou
2019-08-08 14:53 ` Lijun Ou [this message]
2019-08-08 14:53 ` [PATCH V4 for-next 12/14] RDMA/hns: Remove redundant print in hns_roce_v2_ceq_int() Lijun Ou
2019-08-08 14:53 ` [PATCH V4 for-next 13/14] RDMA/hns: Disable alw_lcl_lpbk of SSU Lijun Ou
2019-08-08 14:53 ` [PATCH V4 for-next 14/14] RDMA/hns: Use the new APIs for printing log Lijun Ou
2019-08-12 14:48   ` Doug Ledford
2019-08-13  9:13     ` oulijun
2019-08-13  9:31       ` oulijun
2019-08-13 13:33         ` Doug Ledford
2019-08-12 14:48 ` [PATCH V4 for-next 00/14] Updates for 5.3-rc2 Doug Ledford

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=1565276034-97329-12-git-send-email-oulijun@huawei.com \
    --to=oulijun@huawei.com \
    --cc=dledford@redhat.com \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    /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.