Skip to content

Commit 67954a6

Browse files
wangxi11jgunthorpe
authored andcommitted
RDMA/hns: Optimize SRQ buffer size calculating process
Optimize the SRQ's WQE buffer parameters calculating process to make the codes more readable by using new functions about multi-hop addressing to calculating capabilities of SRQ. 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 ffb1308 commit 67954a6

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

drivers/infiniband/hw/hns/hns_roce_device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ struct hns_roce_cq {
472472

473473
struct hns_roce_idx_que {
474474
struct hns_roce_mtr mtr;
475-
int entry_sz;
475+
int entry_shift;
476476
unsigned long *bitmap;
477477
};
478478

drivers/infiniband/hw/hns/hns_roce_hw_v2.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,12 @@ static void *get_srq_wqe(struct hns_roce_srq *srq, int n)
699699
return hns_roce_buf_offset(srq->buf_mtr.kmem, n << srq->wqe_shift);
700700
}
701701

702+
static void *get_idx_buf(struct hns_roce_idx_que *idx_que, int n)
703+
{
704+
return hns_roce_buf_offset(idx_que->mtr.kmem,
705+
n << idx_que->entry_shift);
706+
}
707+
702708
static void hns_roce_free_srq_wqe(struct hns_roce_srq *srq, int wqe_index)
703709
{
704710
/* always called with interrupts disabled. */
@@ -725,16 +731,6 @@ static int find_empty_entry(struct hns_roce_idx_que *idx_que,
725731
return wqe_idx;
726732
}
727733

728-
static void fill_idx_queue(struct hns_roce_idx_que *idx_que,
729-
int cur_idx, int wqe_idx)
730-
{
731-
unsigned int *addr;
732-
733-
addr = (unsigned int *)hns_roce_buf_offset(idx_que->mtr.kmem,
734-
cur_idx * idx_que->entry_sz);
735-
*addr = wqe_idx;
736-
}
737-
738734
static int hns_roce_v2_post_srq_recv(struct ib_srq *ibsrq,
739735
const struct ib_recv_wr *wr,
740736
const struct ib_recv_wr **bad_wr)
@@ -744,6 +740,7 @@ static int hns_roce_v2_post_srq_recv(struct ib_srq *ibsrq,
744740
struct hns_roce_v2_wqe_data_seg *dseg;
745741
struct hns_roce_v2_db srq_db;
746742
unsigned long flags;
743+
__le32 *srq_idx;
747744
int ret = 0;
748745
int wqe_idx;
749746
void *wqe;
@@ -775,7 +772,6 @@ static int hns_roce_v2_post_srq_recv(struct ib_srq *ibsrq,
775772
break;
776773
}
777774

778-
fill_idx_queue(&srq->idx_que, ind, wqe_idx);
779775
wqe = get_srq_wqe(srq, wqe_idx);
780776
dseg = (struct hns_roce_v2_wqe_data_seg *)wqe;
781777

@@ -791,6 +787,9 @@ static int hns_roce_v2_post_srq_recv(struct ib_srq *ibsrq,
791787
dseg[i].addr = 0;
792788
}
793789

790+
srq_idx = get_idx_buf(&srq->idx_que, ind);
791+
*srq_idx = cpu_to_le32(wqe_idx);
792+
794793
srq->wrid[wqe_idx] = wr->wr_id;
795794
ind = (ind + 1) & (srq->wqe_cnt - 1);
796795
}
@@ -4901,8 +4900,8 @@ static void hns_roce_v2_write_srqc(struct hns_roce_dev *hr_dev,
49014900
roce_set_field(srq_context->byte_4_srqn_srqst,
49024901
SRQC_BYTE_4_SRQ_WQE_HOP_NUM_M,
49034902
SRQC_BYTE_4_SRQ_WQE_HOP_NUM_S,
4904-
(hr_dev->caps.srqwqe_hop_num == HNS_ROCE_HOP_NUM_0 ? 0 :
4905-
hr_dev->caps.srqwqe_hop_num));
4903+
to_hr_hem_hopnum(hr_dev->caps.srqwqe_hop_num,
4904+
srq->wqe_cnt));
49064905
roce_set_field(srq_context->byte_4_srqn_srqst,
49074906
SRQC_BYTE_4_SRQ_SHIFT_M, SRQC_BYTE_4_SRQ_SHIFT_S,
49084907
ilog2(srq->wqe_cnt));
@@ -4944,8 +4943,8 @@ static void hns_roce_v2_write_srqc(struct hns_roce_dev *hr_dev,
49444943
roce_set_field(srq_context->byte_44_idxbufpgsz_addr,
49454944
SRQC_BYTE_44_SRQ_IDX_HOP_NUM_M,
49464945
SRQC_BYTE_44_SRQ_IDX_HOP_NUM_S,
4947-
hr_dev->caps.idx_hop_num == HNS_ROCE_HOP_NUM_0 ? 0 :
4948-
hr_dev->caps.idx_hop_num);
4946+
to_hr_hem_hopnum(hr_dev->caps.idx_hop_num,
4947+
srq->wqe_cnt));
49494948

49504949
roce_set_field(srq_context->byte_44_idxbufpgsz_addr,
49514950
SRQC_BYTE_44_SRQ_IDX_BA_PG_SZ_M,

drivers/infiniband/hw/hns/hns_roce_srq.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,15 @@ static int alloc_srq_buf(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq,
181181
{
182182
struct ib_device *ibdev = &hr_dev->ib_dev;
183183
struct hns_roce_buf_attr buf_attr = {};
184-
int sge_size;
185184
int err;
186185

187-
sge_size = roundup_pow_of_two(max(HNS_ROCE_SGE_SIZE,
188-
HNS_ROCE_SGE_SIZE * srq->max_gs));
189-
190-
srq->wqe_shift = ilog2(sge_size);
186+
srq->wqe_shift = ilog2(roundup_pow_of_two(max(HNS_ROCE_SGE_SIZE,
187+
HNS_ROCE_SGE_SIZE *
188+
srq->max_gs)));
191189

192190
buf_attr.page_shift = hr_dev->caps.srqwqe_buf_pg_sz + PAGE_ADDR_SHIFT;
193-
buf_attr.region[0].size = srq->wqe_cnt * sge_size;
191+
buf_attr.region[0].size = to_hr_hem_entries_size(srq->wqe_cnt,
192+
srq->wqe_shift);
194193
buf_attr.region[0].hopnum = hr_dev->caps.srqwqe_hop_num;
195194
buf_attr.region_count = 1;
196195
buf_attr.fixed_page = true;
@@ -217,10 +216,11 @@ static int alloc_srq_idx(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq,
217216
struct hns_roce_buf_attr buf_attr = {};
218217
int err;
219218

220-
srq->idx_que.entry_sz = HNS_ROCE_IDX_QUE_ENTRY_SZ;
219+
srq->idx_que.entry_shift = ilog2(HNS_ROCE_IDX_QUE_ENTRY_SZ);
221220

222221
buf_attr.page_shift = hr_dev->caps.idx_buf_pg_sz + PAGE_ADDR_SHIFT;
223-
buf_attr.region[0].size = srq->wqe_cnt * HNS_ROCE_IDX_QUE_ENTRY_SZ;
222+
buf_attr.region[0].size = to_hr_hem_entries_size(srq->wqe_cnt,
223+
srq->idx_que.entry_shift);
224224
buf_attr.region[0].hopnum = hr_dev->caps.idx_hop_num;
225225
buf_attr.region_count = 1;
226226
buf_attr.fixed_page = true;

0 commit comments

Comments
 (0)