Skip to content

Commit 9ae2a37

Browse files
wangxi11jgunthorpe
authored andcommitted
RDMA/hns: Refactor post recv flow
Refactor post recv flow by removing unnecessary checking and removing duplicated code. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Xi Wang <[email protected]> Signed-off-by: Weihang Li <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 3f31c41 commit 9ae2a37

File tree

1 file changed

+41
-40
lines changed

1 file changed

+41
-40
lines changed

drivers/infiniband/hw/hns/hns_roce_hw_v2.c

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
#include "hns_roce_hem.h"
4949
#include "hns_roce_hw_v2.h"
5050

51-
static void set_data_seg_v2(struct hns_roce_v2_wqe_data_seg *dseg,
52-
struct ib_sge *sg)
51+
static inline void set_data_seg_v2(struct hns_roce_v2_wqe_data_seg *dseg,
52+
struct ib_sge *sg)
5353
{
5454
dseg->lkey = cpu_to_le32(sg->lkey);
5555
dseg->addr = cpu_to_le64(sg->addr);
@@ -729,22 +729,50 @@ static int check_recv_valid(struct hns_roce_dev *hr_dev,
729729
return 0;
730730
}
731731

732+
static void fill_rq_wqe(struct hns_roce_qp *hr_qp, const struct ib_recv_wr *wr,
733+
u32 wqe_idx)
734+
{
735+
struct hns_roce_v2_wqe_data_seg *dseg;
736+
struct hns_roce_rinl_sge *sge_list;
737+
void *wqe = NULL;
738+
int i;
739+
740+
wqe = hns_roce_get_recv_wqe(hr_qp, wqe_idx);
741+
dseg = (struct hns_roce_v2_wqe_data_seg *)wqe;
742+
for (i = 0; i < wr->num_sge; i++) {
743+
if (!wr->sg_list[i].length)
744+
continue;
745+
set_data_seg_v2(dseg, wr->sg_list + i);
746+
dseg++;
747+
}
748+
749+
if (hr_qp->rq.rsv_sge) {
750+
dseg->lkey = cpu_to_le32(HNS_ROCE_INVALID_LKEY);
751+
dseg->addr = 0;
752+
dseg->len = cpu_to_le32(HNS_ROCE_INVALID_SGE_LENGTH);
753+
}
754+
755+
/* rq support inline data */
756+
if (hr_qp->rq_inl_buf.wqe_cnt) {
757+
sge_list = hr_qp->rq_inl_buf.wqe_list[wqe_idx].sg_list;
758+
hr_qp->rq_inl_buf.wqe_list[wqe_idx].sge_cnt = (u32)wr->num_sge;
759+
for (i = 0; i < wr->num_sge; i++) {
760+
sge_list[i].addr = (void *)(u64)wr->sg_list[i].addr;
761+
sge_list[i].len = wr->sg_list[i].length;
762+
}
763+
}
764+
}
765+
732766
static int hns_roce_v2_post_recv(struct ib_qp *ibqp,
733767
const struct ib_recv_wr *wr,
734768
const struct ib_recv_wr **bad_wr)
735769
{
736770
struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device);
737771
struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
738772
struct ib_device *ibdev = &hr_dev->ib_dev;
739-
struct hns_roce_v2_wqe_data_seg *dseg;
740-
struct hns_roce_rinl_sge *sge_list;
773+
u32 wqe_idx, nreq, max_sge;
741774
unsigned long flags;
742-
void *wqe = NULL;
743-
u32 wqe_idx;
744-
u32 max_sge;
745-
int nreq;
746775
int ret;
747-
int i;
748776

749777
spin_lock_irqsave(&hr_qp->rq.lock, flags);
750778

@@ -764,8 +792,6 @@ static int hns_roce_v2_post_recv(struct ib_qp *ibqp,
764792
goto out;
765793
}
766794

767-
wqe_idx = (hr_qp->rq.head + nreq) & (hr_qp->rq.wqe_cnt - 1);
768-
769795
if (unlikely(wr->num_sge > max_sge)) {
770796
ibdev_err(ibdev, "num_sge = %d >= max_sge = %u.\n",
771797
wr->num_sge, max_sge);
@@ -774,32 +800,8 @@ static int hns_roce_v2_post_recv(struct ib_qp *ibqp,
774800
goto out;
775801
}
776802

777-
wqe = hns_roce_get_recv_wqe(hr_qp, wqe_idx);
778-
dseg = (struct hns_roce_v2_wqe_data_seg *)wqe;
779-
for (i = 0; i < wr->num_sge; i++) {
780-
if (!wr->sg_list[i].length)
781-
continue;
782-
set_data_seg_v2(dseg, wr->sg_list + i);
783-
dseg++;
784-
}
785-
786-
if (hr_qp->rq.rsv_sge) {
787-
dseg->lkey = cpu_to_le32(HNS_ROCE_INVALID_LKEY);
788-
dseg->addr = 0;
789-
dseg->len = cpu_to_le32(HNS_ROCE_INVALID_SGE_LENGTH);
790-
}
791-
792-
/* rq support inline data */
793-
if (hr_qp->rq_inl_buf.wqe_cnt) {
794-
sge_list = hr_qp->rq_inl_buf.wqe_list[wqe_idx].sg_list;
795-
hr_qp->rq_inl_buf.wqe_list[wqe_idx].sge_cnt =
796-
(u32)wr->num_sge;
797-
for (i = 0; i < wr->num_sge; i++) {
798-
sge_list[i].addr =
799-
(void *)(u64)wr->sg_list[i].addr;
800-
sge_list[i].len = wr->sg_list[i].length;
801-
}
802-
}
803+
wqe_idx = (hr_qp->rq.head + nreq) & (hr_qp->rq.wqe_cnt - 1);
804+
fill_rq_wqe(hr_qp, wr, wqe_idx);
803805

804806
hr_qp->rq.wrid[wqe_idx] = wr->wr_id;
805807
}
@@ -928,9 +930,8 @@ static int hns_roce_v2_post_srq_recv(struct ib_srq *ibsrq,
928930
dseg = (struct hns_roce_v2_wqe_data_seg *)wqe;
929931

930932
for (i = 0; i < wr->num_sge; ++i) {
931-
dseg[i].len = cpu_to_le32(wr->sg_list[i].length);
932-
dseg[i].lkey = cpu_to_le32(wr->sg_list[i].lkey);
933-
dseg[i].addr = cpu_to_le64(wr->sg_list[i].addr);
933+
set_data_seg_v2(dseg, wr->sg_list + i);
934+
dseg++;
934935
}
935936

936937
if (srq->rsv_sge) {

0 commit comments

Comments
 (0)