Skip to content

Commit 05201e0

Browse files
Weihang Lijgunthorpe
authored andcommitted
RDMA/hns: Refactor process of setting extended sge
The variable 'cnt' is used to represent the max number of sge an SQ WQE can use at first, then it means how many extended sge an SQ has. In addition, this function has no need to return a value. So refactor and encapsulate the parts of getting number of extended sge a WQE can use to make it easier to understand. Link: https://lore.kernel.org/r/1606558959-48510-4-git-send-email-liweihang@huawei.com Signed-off-by: Weihang Li <liweihang@huawei.com> Reviewed-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent d34895c commit 05201e0

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

drivers/infiniband/hw/hns/hns_roce_qp.c

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -465,42 +465,43 @@ static int set_rq_size(struct hns_roce_dev *hr_dev, struct ib_qp_cap *cap,
465465
return 0;
466466
}
467467

468-
static int set_extend_sge_param(struct hns_roce_dev *hr_dev, u32 sq_wqe_cnt,
469-
struct hns_roce_qp *hr_qp,
470-
struct ib_qp_cap *cap)
468+
static u32 get_wqe_ext_sge_cnt(struct hns_roce_qp *qp)
471469
{
472-
u32 cnt;
470+
/* GSI/UD QP only has extended sge */
471+
if (qp->ibqp.qp_type == IB_QPT_GSI || qp->ibqp.qp_type == IB_QPT_UD)
472+
return qp->sq.max_gs;
473473

474-
cnt = max(1U, cap->max_send_sge);
475-
if (hr_dev->hw_rev == HNS_ROCE_HW_VER1) {
476-
hr_qp->sq.max_gs = roundup_pow_of_two(cnt);
477-
hr_qp->sge.sge_cnt = 0;
474+
if (qp->sq.max_gs > HNS_ROCE_SGE_IN_WQE)
475+
return qp->sq.max_gs - HNS_ROCE_SGE_IN_WQE;
478476

479-
return 0;
480-
}
477+
return 0;
478+
}
481479

482-
hr_qp->sq.max_gs = cnt;
480+
static void set_ext_sge_param(struct hns_roce_dev *hr_dev, u32 sq_wqe_cnt,
481+
struct hns_roce_qp *hr_qp, struct ib_qp_cap *cap)
482+
{
483+
u32 total_sge_cnt;
484+
u32 wqe_sge_cnt;
483485

484-
/* UD sqwqe's sge use extend sge */
485-
if (hr_qp->ibqp.qp_type == IB_QPT_GSI ||
486-
hr_qp->ibqp.qp_type == IB_QPT_UD) {
487-
cnt = roundup_pow_of_two(sq_wqe_cnt * hr_qp->sq.max_gs);
488-
} else if (hr_qp->sq.max_gs > HNS_ROCE_SGE_IN_WQE) {
489-
cnt = roundup_pow_of_two(sq_wqe_cnt *
490-
(hr_qp->sq.max_gs - HNS_ROCE_SGE_IN_WQE));
491-
} else {
492-
cnt = 0;
486+
hr_qp->sge.sge_shift = HNS_ROCE_SGE_SHIFT;
487+
488+
if (hr_dev->hw_rev == HNS_ROCE_HW_VER1) {
489+
hr_qp->sq.max_gs = HNS_ROCE_SGE_IN_WQE;
490+
return;
493491
}
494492

495-
hr_qp->sge.sge_shift = HNS_ROCE_SGE_SHIFT;
493+
hr_qp->sq.max_gs = max(1U, cap->max_send_sge);
494+
495+
wqe_sge_cnt = get_wqe_ext_sge_cnt(hr_qp);
496496

497497
/* If the number of extended sge is not zero, they MUST use the
498498
* space of HNS_HW_PAGE_SIZE at least.
499499
*/
500-
hr_qp->sge.sge_cnt = cnt ?
501-
max(cnt, (u32)HNS_HW_PAGE_SIZE / HNS_ROCE_SGE_SIZE) : 0;
502-
503-
return 0;
500+
if (wqe_sge_cnt) {
501+
total_sge_cnt = roundup_pow_of_two(sq_wqe_cnt * wqe_sge_cnt);
502+
hr_qp->sge.sge_cnt = max(total_sge_cnt,
503+
(u32)HNS_HW_PAGE_SIZE / HNS_ROCE_SGE_SIZE);
504+
}
504505
}
505506

506507
static int check_sq_size_with_integrity(struct hns_roce_dev *hr_dev,
@@ -545,9 +546,7 @@ static int set_user_sq_size(struct hns_roce_dev *hr_dev,
545546
return ret;
546547
}
547548

548-
ret = set_extend_sge_param(hr_dev, cnt, hr_qp, cap);
549-
if (ret)
550-
return ret;
549+
set_ext_sge_param(hr_dev, cnt, hr_qp, cap);
551550

552551
hr_qp->sq.wqe_shift = ucmd->log_sq_stride;
553552
hr_qp->sq.wqe_cnt = cnt;
@@ -612,7 +611,6 @@ static int set_kernel_sq_size(struct hns_roce_dev *hr_dev,
612611
{
613612
struct ib_device *ibdev = &hr_dev->ib_dev;
614613
u32 cnt;
615-
int ret;
616614

617615
if (!cap->max_send_wr || cap->max_send_wr > hr_dev->caps.max_wqes ||
618616
cap->max_send_sge > hr_dev->caps.max_sq_sg) {
@@ -632,9 +630,7 @@ static int set_kernel_sq_size(struct hns_roce_dev *hr_dev,
632630
hr_qp->sq.wqe_shift = ilog2(hr_dev->caps.max_sq_desc_sz);
633631
hr_qp->sq.wqe_cnt = cnt;
634632

635-
ret = set_extend_sge_param(hr_dev, cnt, hr_qp, cap);
636-
if (ret)
637-
return ret;
633+
set_ext_sge_param(hr_dev, cnt, hr_qp, cap);
638634

639635
/* sync the parameters of kernel QP to user's configuration */
640636
cap->max_send_wr = cnt;

0 commit comments

Comments
 (0)