mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 01:55:51 +02:00
RDMA/bnxt_re: Refactor bnxt_re_init_user_qp()
The umem changes for CQ added a helper - bnxt_re_setup_sginfo(). Use the same helper for QP creation since we support only 4K pages for QP ring memory too. Add a new helper function bnxt_re_get_psn_bytes() to improve readability as this code will be updated in subsequent patches. Link: https://patch.msgid.link/r/20260519150041.7251-2-sriharsha.basavapatna@broadcom.com Signed-off-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com> Reviewed-by: Selvin Xavier <selvin.xavier@broadcom.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
This commit is contained in:
parent
67464f388d
commit
9a79dcbedc
|
|
@ -1136,34 +1136,64 @@ static int bnxt_re_setup_swqe_size(struct bnxt_re_qp *qp,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int bnxt_re_setup_sginfo(struct bnxt_re_dev *rdev,
|
||||
struct ib_umem *umem,
|
||||
struct bnxt_qplib_sg_info *sginfo)
|
||||
{
|
||||
unsigned long page_size;
|
||||
|
||||
if (!umem)
|
||||
return -EINVAL;
|
||||
|
||||
page_size = ib_umem_find_best_pgsz(umem, SZ_4K, 0);
|
||||
if (!page_size || page_size != SZ_4K)
|
||||
return -EINVAL;
|
||||
|
||||
sginfo->umem = umem;
|
||||
sginfo->npages = ib_umem_num_dma_blocks(umem, page_size);
|
||||
sginfo->pgsize = page_size;
|
||||
sginfo->pgshft = __builtin_ctz(page_size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bnxt_re_get_psn_bytes(struct bnxt_re_dev *rdev,
|
||||
struct bnxt_re_ucontext *cntx,
|
||||
struct bnxt_qplib_qp *qplib_qp,
|
||||
struct bnxt_re_qp_req *ureq)
|
||||
{
|
||||
int psn_sz, psn_nume;
|
||||
|
||||
psn_sz = bnxt_qplib_is_chip_gen_p5_p7(rdev->chip_ctx) ?
|
||||
sizeof(struct sq_psn_search_ext) :
|
||||
sizeof(struct sq_psn_search);
|
||||
if (cntx && bnxt_re_is_var_size_supported(rdev, cntx)) {
|
||||
psn_nume = ureq->sq_slots;
|
||||
} else {
|
||||
psn_nume = (qplib_qp->wqe_mode == BNXT_QPLIB_WQE_MODE_STATIC) ?
|
||||
qplib_qp->sq.max_wqe : ((qplib_qp->sq.max_wqe * qplib_qp->sq.wqe_size) /
|
||||
sizeof(struct bnxt_qplib_sge));
|
||||
}
|
||||
if (_is_host_msn_table(rdev->qplib_res.dattr->dev_cap_flags2))
|
||||
psn_nume = roundup_pow_of_two(psn_nume);
|
||||
|
||||
return psn_nume * psn_sz;
|
||||
}
|
||||
|
||||
static int bnxt_re_init_user_qp(struct bnxt_re_dev *rdev, struct bnxt_re_pd *pd,
|
||||
struct bnxt_re_qp *qp, struct bnxt_re_ucontext *cntx,
|
||||
struct bnxt_re_qp_req *ureq)
|
||||
{
|
||||
struct bnxt_qplib_qp *qplib_qp;
|
||||
int bytes = 0, psn_sz;
|
||||
struct ib_umem *umem;
|
||||
int psn_nume;
|
||||
int bytes;
|
||||
int rc;
|
||||
|
||||
qplib_qp = &qp->qplib_qp;
|
||||
|
||||
bytes = (qplib_qp->sq.max_wqe * qplib_qp->sq.wqe_size);
|
||||
/* Consider mapping PSN search memory only for RC QPs. */
|
||||
if (qplib_qp->type == CMDQ_CREATE_QP_TYPE_RC) {
|
||||
psn_sz = bnxt_qplib_is_chip_gen_p5_p7(rdev->chip_ctx) ?
|
||||
sizeof(struct sq_psn_search_ext) :
|
||||
sizeof(struct sq_psn_search);
|
||||
if (cntx && bnxt_re_is_var_size_supported(rdev, cntx)) {
|
||||
psn_nume = ureq->sq_slots;
|
||||
} else {
|
||||
psn_nume = (qplib_qp->wqe_mode == BNXT_QPLIB_WQE_MODE_STATIC) ?
|
||||
qplib_qp->sq.max_wqe : ((qplib_qp->sq.max_wqe * qplib_qp->sq.wqe_size) /
|
||||
sizeof(struct bnxt_qplib_sge));
|
||||
}
|
||||
if (_is_host_msn_table(rdev->qplib_res.dattr->dev_cap_flags2))
|
||||
psn_nume = roundup_pow_of_two(psn_nume);
|
||||
bytes += (psn_nume * psn_sz);
|
||||
}
|
||||
if (qplib_qp->type == CMDQ_CREATE_QP_TYPE_RC)
|
||||
bytes += bnxt_re_get_psn_bytes(rdev, cntx, qplib_qp, ureq);
|
||||
|
||||
bytes = PAGE_ALIGN(bytes);
|
||||
umem = ib_umem_get(&rdev->ibdev, ureq->qpsva, bytes,
|
||||
|
|
@ -1172,33 +1202,42 @@ static int bnxt_re_init_user_qp(struct bnxt_re_dev *rdev, struct bnxt_re_pd *pd,
|
|||
return PTR_ERR(umem);
|
||||
|
||||
qp->sumem = umem;
|
||||
qplib_qp->sq.sg_info.umem = umem;
|
||||
qplib_qp->sq.sg_info.pgsize = PAGE_SIZE;
|
||||
qplib_qp->sq.sg_info.pgshft = PAGE_SHIFT;
|
||||
qplib_qp->qp_handle = ureq->qp_handle;
|
||||
rc = bnxt_re_setup_sginfo(rdev, qp->sumem, &qplib_qp->sq.sg_info);
|
||||
if (rc)
|
||||
goto fail;
|
||||
|
||||
if (!qp->qplib_qp.srq) {
|
||||
bytes = (qplib_qp->rq.max_wqe * qplib_qp->rq.wqe_size);
|
||||
bytes = PAGE_ALIGN(bytes);
|
||||
umem = ib_umem_get(&rdev->ibdev, ureq->qprva, bytes,
|
||||
IB_ACCESS_LOCAL_WRITE);
|
||||
if (IS_ERR(umem))
|
||||
goto rqfail;
|
||||
qp->rumem = umem;
|
||||
qplib_qp->rq.sg_info.umem = umem;
|
||||
qplib_qp->rq.sg_info.pgsize = PAGE_SIZE;
|
||||
qplib_qp->rq.sg_info.pgshft = PAGE_SHIFT;
|
||||
if (qp->qplib_qp.srq)
|
||||
goto done;
|
||||
|
||||
bytes = (qplib_qp->rq.max_wqe * qplib_qp->rq.wqe_size);
|
||||
bytes = PAGE_ALIGN(bytes);
|
||||
umem = ib_umem_get(&rdev->ibdev, ureq->qprva, bytes,
|
||||
IB_ACCESS_LOCAL_WRITE);
|
||||
if (IS_ERR(umem)) {
|
||||
rc = PTR_ERR(umem);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
qp->rumem = umem;
|
||||
rc = bnxt_re_setup_sginfo(rdev, qp->rumem, &qplib_qp->rq.sg_info);
|
||||
if (rc)
|
||||
goto rqfail;
|
||||
|
||||
done:
|
||||
qplib_qp->qp_handle = ureq->qp_handle;
|
||||
qplib_qp->dpi = &cntx->dpi;
|
||||
qplib_qp->is_user = true;
|
||||
return 0;
|
||||
|
||||
rqfail:
|
||||
ib_umem_release(qp->rumem);
|
||||
qp->rumem = NULL;
|
||||
memset(&qplib_qp->rq.sg_info, 0, sizeof(qplib_qp->rq.sg_info));
|
||||
fail:
|
||||
ib_umem_release(qp->sumem);
|
||||
qp->sumem = NULL;
|
||||
memset(&qplib_qp->sq.sg_info, 0, sizeof(qplib_qp->sq.sg_info));
|
||||
|
||||
return PTR_ERR(umem);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static struct bnxt_re_ah *bnxt_re_create_shadow_qp_ah
|
||||
|
|
@ -3345,26 +3384,6 @@ int bnxt_re_destroy_cq(struct ib_cq *ib_cq, struct ib_udata *udata)
|
|||
return ib_respond_empty_udata(udata);
|
||||
}
|
||||
|
||||
static int bnxt_re_setup_sginfo(struct bnxt_re_dev *rdev,
|
||||
struct ib_umem *umem,
|
||||
struct bnxt_qplib_sg_info *sginfo)
|
||||
{
|
||||
unsigned long page_size;
|
||||
|
||||
if (!umem)
|
||||
return -EINVAL;
|
||||
|
||||
page_size = ib_umem_find_best_pgsz(umem, SZ_4K, 0);
|
||||
if (!page_size || page_size != SZ_4K)
|
||||
return -EINVAL;
|
||||
|
||||
sginfo->umem = umem;
|
||||
sginfo->npages = ib_umem_num_dma_blocks(umem, page_size);
|
||||
sginfo->pgsize = page_size;
|
||||
sginfo->pgshft = __builtin_ctz(page_size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bnxt_re_create_user_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
|
||||
struct uverbs_attr_bundle *attrs)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user