From: Leon Romanovsky <leon@kernel.org>
To: Doug Ledford <dledford@redhat.com>, Jason Gunthorpe <jgg@mellanox.com>
Cc: Leon Romanovsky <leonro@mellanox.com>,
linux-rdma@vger.kernel.org, Maor Gottlieb <maorg@mellanox.com>
Subject: [PATCH rdma-next 01/18] RDMA/mlx5: Organize QP types checks in one place
Date: Mon, 20 Apr 2020 18:10:48 +0300 [thread overview]
Message-ID: <20200420151105.282848-2-leon@kernel.org> (raw)
In-Reply-To: <20200420151105.282848-1-leon@kernel.org>
From: Leon Romanovsky <leonro@mellanox.com>
Perform check if QP type is supported in one place at the beginning of
the create_qp function instead of current implementation with checks
buried inside of the code.
Reviewed-by: Maor Gottlieb <maorg@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
---
drivers/infiniband/hw/mlx5/qp.c | 129 +++++++++++++++++---------------
1 file changed, 68 insertions(+), 61 deletions(-)
diff --git a/drivers/infiniband/hw/mlx5/qp.c b/drivers/infiniband/hw/mlx5/qp.c
index 0f986ce22a96..df63ad38509b 100644
--- a/drivers/infiniband/hw/mlx5/qp.c
+++ b/drivers/infiniband/hw/mlx5/qp.c
@@ -2677,12 +2677,42 @@ static int set_mlx_qp_type(struct mlx5_ib_dev *dev,
}
}
- if (!MLX5_CAP_GEN(dev->mdev, dct)) {
- mlx5_ib_dbg(dev, "DC transport is not supported\n");
- return -EOPNOTSUPP;
+ return 0;
+}
+
+static int check_qp_type(struct mlx5_ib_dev *dev, struct ib_qp_init_attr *attr)
+{
+ if (attr->qp_type == IB_QPT_DRIVER && !MLX5_CAP_GEN(dev->mdev, dct))
+ goto out;
+
+ switch (attr->qp_type) {
+ case IB_QPT_XRC_TGT:
+ case IB_QPT_XRC_INI:
+ if (!MLX5_CAP_GEN(dev->mdev, xrc))
+ goto out;
+ fallthrough;
+ case IB_QPT_RAW_PACKET:
+ case IB_QPT_RC:
+ case IB_QPT_UC:
+ case IB_QPT_UD:
+ case IB_QPT_SMI:
+ case MLX5_IB_QPT_HW_GSI:
+ case MLX5_IB_QPT_REG_UMR:
+ case IB_QPT_DRIVER:
+ case IB_QPT_GSI:
+ return 0;
+ case IB_QPT_RAW_IPV6:
+ case IB_QPT_RAW_ETHERTYPE:
+ case IB_QPT_MAX:
+ default:
+ goto out;
}
return 0;
+
+out:
+ mlx5_ib_dbg(dev, "Unsupported QP type %d\n", attr->qp_type);
+ return -EOPNOTSUPP;
}
struct ib_qp *mlx5_ib_create_qp(struct ib_pd *pd,
@@ -2698,9 +2728,17 @@ struct ib_qp *mlx5_ib_create_qp(struct ib_pd *pd,
struct mlx5_ib_ucontext *ucontext = rdma_udata_to_drv_context(
udata, struct mlx5_ib_ucontext, ibucontext);
- if (pd) {
- dev = to_mdev(pd->device);
+ dev = pd ? to_mdev(pd->device) :
+ to_mdev(to_mxrcd(init_attr->xrcd)->ibxrcd.device);
+ err = check_qp_type(dev, init_attr);
+ if (err) {
+ mlx5_ib_dbg(dev, "Unsupported QP type %d\n",
+ init_attr->qp_type);
+ return ERR_PTR(err);
+ }
+
+ if (pd) {
if (init_attr->qp_type == IB_QPT_RAW_PACKET) {
if (!ucontext) {
mlx5_ib_dbg(dev, "Raw Packet QP is not supported for kernel consumers\n");
@@ -2718,7 +2756,6 @@ struct ib_qp *mlx5_ib_create_qp(struct ib_pd *pd,
ib_qp_type_str(init_attr->qp_type));
return ERR_PTR(-EINVAL);
}
- dev = to_mdev(to_mxrcd(init_attr->xrcd)->ibxrcd.device);
}
if (init_attr->qp_type == IB_QPT_DRIVER) {
@@ -2741,67 +2778,37 @@ struct ib_qp *mlx5_ib_create_qp(struct ib_pd *pd,
}
}
- switch (init_attr->qp_type) {
- case IB_QPT_XRC_TGT:
- case IB_QPT_XRC_INI:
- if (!MLX5_CAP_GEN(dev->mdev, xrc)) {
- mlx5_ib_dbg(dev, "XRC not supported\n");
- return ERR_PTR(-ENOSYS);
- }
- init_attr->recv_cq = NULL;
- if (init_attr->qp_type == IB_QPT_XRC_TGT) {
- xrcdn = to_mxrcd(init_attr->xrcd)->xrcdn;
- init_attr->send_cq = NULL;
- }
-
- /* fall through */
- case IB_QPT_RAW_PACKET:
- case IB_QPT_RC:
- case IB_QPT_UC:
- case IB_QPT_UD:
- case IB_QPT_SMI:
- case MLX5_IB_QPT_HW_GSI:
- case MLX5_IB_QPT_REG_UMR:
- case MLX5_IB_QPT_DCI:
- qp = kzalloc(sizeof(*qp), GFP_KERNEL);
- if (!qp)
- return ERR_PTR(-ENOMEM);
-
- err = create_qp_common(dev, pd, init_attr, udata, qp);
- if (err) {
- mlx5_ib_dbg(dev, "create_qp_common failed\n");
- kfree(qp);
- return ERR_PTR(err);
- }
+ if (init_attr->qp_type == IB_QPT_GSI)
+ return mlx5_ib_gsi_create_qp(pd, init_attr);
- if (is_qp0(init_attr->qp_type))
- qp->ibqp.qp_num = 0;
- else if (is_qp1(init_attr->qp_type))
- qp->ibqp.qp_num = 1;
- else
- qp->ibqp.qp_num = qp->trans_qp.base.mqp.qpn;
+ if (init_attr->qp_type == IB_QPT_XRC_TGT) {
+ init_attr->recv_cq = NULL;
+ xrcdn = to_mxrcd(init_attr->xrcd)->xrcdn;
+ init_attr->send_cq = NULL;
+ }
- mlx5_ib_dbg(dev, "ib qpnum 0x%x, mlx qpn 0x%x, rcqn 0x%x, scqn 0x%x\n",
- qp->ibqp.qp_num, qp->trans_qp.base.mqp.qpn,
- init_attr->recv_cq ? to_mcq(init_attr->recv_cq)->mcq.cqn : -1,
- init_attr->send_cq ? to_mcq(init_attr->send_cq)->mcq.cqn : -1);
+ if (init_attr->qp_type == IB_QPT_XRC_INI)
+ init_attr->recv_cq = NULL;
- qp->trans_qp.xrcdn = xrcdn;
+ qp = kzalloc(sizeof(*qp), GFP_KERNEL);
+ if (!qp)
+ return ERR_PTR(-ENOMEM);
- break;
+ err = create_qp_common(dev, pd, init_attr, udata, qp);
+ if (err) {
+ mlx5_ib_dbg(dev, "create_qp_common failed\n");
+ kfree(qp);
+ return ERR_PTR(err);
+ }
- case IB_QPT_GSI:
- return mlx5_ib_gsi_create_qp(pd, init_attr);
+ if (is_qp0(init_attr->qp_type))
+ qp->ibqp.qp_num = 0;
+ else if (is_qp1(init_attr->qp_type))
+ qp->ibqp.qp_num = 1;
+ else
+ qp->ibqp.qp_num = qp->trans_qp.base.mqp.qpn;
- case IB_QPT_RAW_IPV6:
- case IB_QPT_RAW_ETHERTYPE:
- case IB_QPT_MAX:
- default:
- mlx5_ib_dbg(dev, "unsupported qp type %d\n",
- init_attr->qp_type);
- /* Don't support raw QPs */
- return ERR_PTR(-EOPNOTSUPP);
- }
+ qp->trans_qp.xrcdn = xrcdn;
if (verbs_init_attr->qp_type == IB_QPT_DRIVER)
qp->qp_sub_type = init_attr->qp_type;
--
2.25.2
next prev parent reply other threads:[~2020-04-20 15:11 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-20 15:10 [PATCH rdma-next 00/18] Refactor mlx5_ib_create_qp (Part I) Leon Romanovsky
2020-04-20 15:10 ` Leon Romanovsky [this message]
2020-04-20 15:10 ` [PATCH rdma-next 02/18] RDMA/mlx5: Delete impossible GSI port check Leon Romanovsky
2020-04-20 15:10 ` [PATCH rdma-next 03/18] RDMA/mlx5: Perform check if QP creation flow is valid Leon Romanovsky
2020-04-20 15:10 ` [PATCH rdma-next 04/18] RDMA/mlx5: Prepare QP allocation for future removal Leon Romanovsky
2020-04-20 15:10 ` [PATCH rdma-next 05/18] RDMA/mlx5: Avoid setting redundant NULL for XRC QPs Leon Romanovsky
2020-04-20 15:10 ` [PATCH rdma-next 06/18] RDMA/mlx5: Set QP subtype immediately when it is known Leon Romanovsky
2020-04-20 15:10 ` [PATCH rdma-next 07/18] RDMA/mlx5: Separate create QP flows to be based on type Leon Romanovsky
2020-04-20 15:10 ` [PATCH rdma-next 08/18] RDMA/mlx5: Split scatter CQE configuration for DCT QP Leon Romanovsky
2020-04-20 15:10 ` [PATCH rdma-next 09/18] RDMA/mlx5: Update all DRIVER QP places to use QP subtype Leon Romanovsky
2020-04-20 15:10 ` [PATCH rdma-next 10/18] RDMA/mlx5: Move DRIVER QP flags check into separate function Leon Romanovsky
2020-04-20 15:10 ` [PATCH rdma-next 11/18] RDMA/mlx5: Remove second copy from user for non RSS RAW QPs Leon Romanovsky
2020-04-20 15:10 ` [PATCH rdma-next 12/18] RDMA/mlx5: Initial separation of RAW_PACKET QP from common flow Leon Romanovsky
2020-04-20 15:11 ` [PATCH rdma-next 13/18] RDMA/mlx5: Delete create QP flags obfuscation Leon Romanovsky
2020-04-20 15:11 ` [PATCH rdma-next 14/18] RDMA/mlx5: Process create QP flags in one place Leon Romanovsky
2020-04-23 18:53 ` Leon Romanovsky
2020-04-24 19:51 ` Jason Gunthorpe
2020-04-24 20:23 ` Leon Romanovsky
2020-04-20 15:11 ` [PATCH rdma-next 15/18] RDMA/mlx5: Use flags_en mechanism to mark QP created with WQE signature Leon Romanovsky
2020-04-20 15:11 ` [PATCH rdma-next 16/18] RDMA/mlx5: Change scatter CQE flag to be set like other vendor flags Leon Romanovsky
2020-04-20 15:11 ` [PATCH rdma-next 17/18] RDMA/mlx5: Return all configured create flags through query QP Leon Romanovsky
2020-04-20 15:11 ` [PATCH rdma-next 18/18] RDMA/mlx5: Process all vendor flags in one place Leon Romanovsky
2020-04-24 19:54 ` [PATCH rdma-next 00/18] Refactor mlx5_ib_create_qp (Part I) Jason Gunthorpe
2020-04-24 20:26 ` Leon Romanovsky
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=20200420151105.282848-2-leon@kernel.org \
--to=leon@kernel.org \
--cc=dledford@redhat.com \
--cc=jgg@mellanox.com \
--cc=leonro@mellanox.com \
--cc=linux-rdma@vger.kernel.org \
--cc=maorg@mellanox.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;
as well as URLs for NNTP newsgroup(s).