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 02/14] RDMA/hns: Optimize hns_roce_modify_qp function
Date: Thu, 8 Aug 2019 22:53:42 +0800 [thread overview]
Message-ID: <1565276034-97329-3-git-send-email-oulijun@huawei.com> (raw)
In-Reply-To: <1565276034-97329-1-git-send-email-oulijun@huawei.com>
Here mainly packages some code into some new functions in order to
reduce code compelexity.
Signed-off-by: Lijun Ou <oulijun@huawei.com>
---
V3->V4:
1. Remove the ibdev prefix print interface
2. Refactor the some lines for checking mtu function according to
Doug Ledford's reviews
V1->V2:
1. Use ibdev prefix print interface
---
drivers/infiniband/hw/hns/hns_roce_qp.c | 117 +++++++++++++++++++-------------
1 file changed, 69 insertions(+), 48 deletions(-)
diff --git a/drivers/infiniband/hw/hns/hns_roce_qp.c b/drivers/infiniband/hw/hns/hns_roce_qp.c
index 5fcc17e6..f76617b 100644
--- a/drivers/infiniband/hw/hns/hns_roce_qp.c
+++ b/drivers/infiniband/hw/hns/hns_roce_qp.c
@@ -1070,48 +1070,41 @@ int to_hr_qp_type(int qp_type)
return transport_type;
}
-int hns_roce_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
- int attr_mask, struct ib_udata *udata)
+static int check_mtu_validate(struct hns_roce_dev *hr_dev,
+ struct hns_roce_qp *hr_qp,
+ struct ib_qp_attr *attr, int attr_mask)
{
- struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device);
- struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
- enum ib_qp_state cur_state, new_state;
struct device *dev = hr_dev->dev;
- int ret = -EINVAL;
- int p;
enum ib_mtu active_mtu;
+ int p;
- mutex_lock(&hr_qp->mutex);
-
- cur_state = attr_mask & IB_QP_CUR_STATE ?
- attr->cur_qp_state : (enum ib_qp_state)hr_qp->state;
- new_state = attr_mask & IB_QP_STATE ?
- attr->qp_state : cur_state;
-
- if (ibqp->uobject &&
- (attr_mask & IB_QP_STATE) && new_state == IB_QPS_ERR) {
- if (hr_qp->sdb_en == 1) {
- hr_qp->sq.head = *(int *)(hr_qp->sdb.virt_addr);
+ p = attr_mask & IB_QP_PORT ? (attr->port_num - 1) : hr_qp->port;
+ active_mtu = iboe_get_mtu(hr_dev->iboe.netdevs[p]->mtu);
- if (hr_qp->rdb_en == 1)
- hr_qp->rq.head = *(int *)(hr_qp->rdb.virt_addr);
- } else {
- dev_warn(dev, "flush cqe is not supported in userspace!\n");
- goto out;
- }
+ if ((hr_dev->caps.max_mtu >= IB_MTU_2048 &&
+ attr->path_mtu > hr_dev->caps.max_mtu) ||
+ attr->path_mtu < IB_MTU_256 || attr->path_mtu > active_mtu) {
+ dev_err(dev, "attr path_mtu(%d)invalid while modify qp",
+ attr->path_mtu);
+ return -EINVAL;
}
- if (!ib_modify_qp_is_ok(cur_state, new_state, ibqp->qp_type,
- attr_mask)) {
- dev_err(dev, "ib_modify_qp_is_ok failed\n");
- goto out;
- }
+ return 0;
+}
+
+static int hns_roce_check_qp_attr(struct ib_qp *ibqp, struct ib_qp_attr *attr,
+ int attr_mask)
+{
+ struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device);
+ struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
+ struct device *dev = hr_dev->dev;
+ int p;
if ((attr_mask & IB_QP_PORT) &&
(attr->port_num == 0 || attr->port_num > hr_dev->caps.num_ports)) {
dev_err(dev, "attr port_num invalid.attr->port_num=%d\n",
attr->port_num);
- goto out;
+ return -EINVAL;
}
if (attr_mask & IB_QP_PKEY_INDEX) {
@@ -1119,23 +1112,7 @@ int hns_roce_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
if (attr->pkey_index >= hr_dev->caps.pkey_table_len[p]) {
dev_err(dev, "attr pkey_index invalid.attr->pkey_index=%d\n",
attr->pkey_index);
- goto out;
- }
- }
-
- if (attr_mask & IB_QP_PATH_MTU) {
- p = attr_mask & IB_QP_PORT ? (attr->port_num - 1) : hr_qp->port;
- active_mtu = iboe_get_mtu(hr_dev->iboe.netdevs[p]->mtu);
-
- if ((hr_dev->caps.max_mtu == IB_MTU_4096 &&
- attr->path_mtu > IB_MTU_4096) ||
- (hr_dev->caps.max_mtu == IB_MTU_2048 &&
- attr->path_mtu > IB_MTU_2048) ||
- attr->path_mtu < IB_MTU_256 ||
- attr->path_mtu > active_mtu) {
- dev_err(dev, "attr path_mtu(%d)invalid while modify qp",
- attr->path_mtu);
- goto out;
+ return -EINVAL;
}
}
@@ -1143,16 +1120,60 @@ int hns_roce_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
attr->max_rd_atomic > hr_dev->caps.max_qp_init_rdma) {
dev_err(dev, "attr max_rd_atomic invalid.attr->max_rd_atomic=%d\n",
attr->max_rd_atomic);
- goto out;
+ return -EINVAL;
}
if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC &&
attr->max_dest_rd_atomic > hr_dev->caps.max_qp_dest_rdma) {
dev_err(dev, "attr max_dest_rd_atomic invalid.attr->max_dest_rd_atomic=%d\n",
attr->max_dest_rd_atomic);
+ return -EINVAL;
+ }
+
+ if (attr_mask & IB_QP_PATH_MTU)
+ return check_mtu_validate(hr_dev, hr_qp, attr, attr_mask);
+
+ return 0;
+}
+
+int hns_roce_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
+ int attr_mask, struct ib_udata *udata)
+{
+ struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device);
+ struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
+ enum ib_qp_state cur_state, new_state;
+ struct device *dev = hr_dev->dev;
+ int ret = -EINVAL;
+
+ mutex_lock(&hr_qp->mutex);
+
+ cur_state = attr_mask & IB_QP_CUR_STATE ?
+ attr->cur_qp_state : (enum ib_qp_state)hr_qp->state;
+ new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state;
+
+ if (ibqp->uobject &&
+ (attr_mask & IB_QP_STATE) && new_state == IB_QPS_ERR) {
+ if (hr_qp->sdb_en == 1) {
+ hr_qp->sq.head = *(int *)(hr_qp->sdb.virt_addr);
+
+ if (hr_qp->rdb_en == 1)
+ hr_qp->rq.head = *(int *)(hr_qp->rdb.virt_addr);
+ } else {
+ dev_warn(dev, "flush cqe is not supported in userspace!\n");
+ goto out;
+ }
+ }
+
+ if (!ib_modify_qp_is_ok(cur_state, new_state, ibqp->qp_type,
+ attr_mask)) {
+ dev_err(dev, "ib_modify_qp_is_ok failed\n");
goto out;
}
+ ret = hns_roce_check_qp_attr(ibqp, attr, attr_mask);
+ if (ret)
+ goto out;
+
if (cur_state == new_state && cur_state == IB_QPS_RESET) {
if (hr_dev->caps.min_wqes) {
ret = -EPERM;
--
1.9.1
next prev 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 ` Lijun Ou [this message]
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 ` [PATCH V4 for-next 11/14] RDMA/hns: Refactor hns_roce_v2_set_hem for hip08 Lijun Ou
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-3-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox