From: Leon Romanovsky <leonro@xxxxxxxxxxxx> Adapt mlx5 to use restrack automatic QP allocation scheme and open create_qp callback to track all QP types except XRC. Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxxxx> --- drivers/infiniband/core/core_priv.h | 3 ++- drivers/infiniband/hw/mlx5/gsi.c | 5 ++++- drivers/infiniband/hw/mlx5/main.c | 2 ++ drivers/infiniband/hw/mlx5/qp.c | 17 +++++++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/core/core_priv.h b/drivers/infiniband/core/core_priv.h index cda2db1add39..fc068f80f566 100644 --- a/drivers/infiniband/core/core_priv.h +++ b/drivers/infiniband/core/core_priv.h @@ -299,7 +299,8 @@ static inline struct ib_qp *_ib_create_qp(struct ib_device *dev, * see mlx5 create_dev_resources() as an example. */ rdma_rt_set_type(&qp->res, RDMA_RESTRACK_QP); - if (attr->qp_type < IB_QPT_XRC_INI) { + if (attr->qp_type != IB_QPT_XRC_INI && + attr->qp_type != IB_QPT_XRC_TGT) { if (uobj) rdma_restrack_uadd(&qp->res); else diff --git a/drivers/infiniband/hw/mlx5/gsi.c b/drivers/infiniband/hw/mlx5/gsi.c index 4950df3f71b6..0aeff7e3dbf6 100644 --- a/drivers/infiniband/hw/mlx5/gsi.c +++ b/drivers/infiniband/hw/mlx5/gsi.c @@ -193,9 +193,12 @@ struct ib_qp *mlx5_ib_gsi_create_qp(struct ib_pd *pd, } dev->devr.ports[init_attr->port_num - 1].gsi = gsi; - mutex_unlock(&dev->devr.mutex); + gsi->ibqp.device = &dev->ib_dev; + rdma_rt_set_type(&gsi->ibqp.res, RDMA_RESTRACK_QP); + rdma_rt_set_id(&gsi->ibqp.res, gsi->ibqp.qp_num); + return &gsi->ibqp; err_destroy_cq: diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c index 3e1fb9d57724..12a038146105 100644 --- a/drivers/infiniband/hw/mlx5/main.c +++ b/drivers/infiniband/hw/mlx5/main.c @@ -6529,6 +6529,8 @@ static void *mlx5_ib_add(struct mlx5_core_dev *mdev) rdma_rt_set_id_range(&dev->ib_dev, RDMA_RESTRACK_PD, 0, 0); /* CQ ID managed by FW */ rdma_rt_set_id_range(&dev->ib_dev, RDMA_RESTRACK_CQ, 0, 0); + /* QP ID managed by HW */ + rdma_rt_set_id_range(&dev->ib_dev, RDMA_RESTRACK_QP, 0, 0); dev->mdev = mdev; dev->num_ports = max(MLX5_CAP_GEN(mdev, num_ports), diff --git a/drivers/infiniband/hw/mlx5/qp.c b/drivers/infiniband/hw/mlx5/qp.c index 44bde8dfebf6..d18e2156d395 100644 --- a/drivers/infiniband/hw/mlx5/qp.c +++ b/drivers/infiniband/hw/mlx5/qp.c @@ -2444,6 +2444,13 @@ static struct ib_qp *mlx5_ib_create_dct(struct ib_pd *pd, qp->state = IB_QPS_RESET; + qp->ibqp.device = pd->device; + rdma_rt_set_type(&qp->ibqp.res, RDMA_RESTRACK_QP); + rdma_rt_set_id(&qp->ibqp.res, qp->ibqp.qp_num); + err = rdma_restrack_add(&qp->ibqp.res); + if (err) + goto err_free; + return &qp->ibqp; err_free: kfree(qp); @@ -2607,6 +2614,15 @@ struct ib_qp *mlx5_ib_create_qp(struct ib_pd *pd, if (verbs_init_attr->qp_type == IB_QPT_DRIVER) qp->qp_sub_type = init_attr->qp_type; + qp->ibqp.device = &dev->ib_dev; + rdma_rt_set_type(&qp->ibqp.res, RDMA_RESTRACK_QP); + rdma_rt_set_id(&qp->ibqp.res, qp->ibqp.qp_num); + err = rdma_restrack_add(&qp->ibqp.res); + if (err) { + kfree(qp); + return ERR_PTR(err); + } + return &qp->ibqp; } @@ -2637,6 +2653,7 @@ int mlx5_ib_destroy_qp(struct ib_qp *qp) if (unlikely(qp->qp_type == IB_QPT_GSI)) return mlx5_ib_gsi_destroy_qp(qp); + rdma_restrack_del(&qp->res); if (mqp->qp_sub_type == MLX5_IB_QPT_DCT) return mlx5_ib_destroy_dct(mqp); -- 2.19.1