From 08ec3c43bf9710fdf3ca664f7cd63436e67339d7 Mon Sep 17 00:00:00 2001 From: Wenpeng Liang Date: Tue, 11 May 2021 19:06:34 +0800 Subject: [PATCH 2/8] libhns: Fix the ownership of the head/tail pointer of SRQ WQE The CQE of SRQ is not generated in the order of wqe, so the wqe_idx corresponding to the idle WQE should be placed in a FIFO, then the hardware will be instructed to obtain the corresponding WQE. Therefore, the WQ of SRQ has no concept of head pointer and tail pointer, but the queue of wqe_idx does. Signed-off-by: Wenpeng Liang Signed-off-by: Weihang Li --- providers/hns/hns_roce_u.h | 4 ++-- providers/hns/hns_roce_u_hw_v2.c | 12 ++++++------ providers/hns/hns_roce_u_verbs.c | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/providers/hns/hns_roce_u.h b/providers/hns/hns_roce_u.h index 8f805dd1..b3f48113 100644 --- a/providers/hns/hns_roce_u.h +++ b/providers/hns/hns_roce_u.h @@ -205,6 +205,8 @@ struct hns_roce_idx_que { int entry_shift; unsigned long *bitmap; int bitmap_cnt; + unsigned int head; + unsigned int tail; }; struct hns_roce_srq { @@ -217,8 +219,6 @@ struct hns_roce_srq { unsigned int max_gs; unsigned int rsv_sge; unsigned int wqe_shift; - int head; - int tail; unsigned int *db; unsigned short counter; struct hns_roce_idx_que idx_que; diff --git a/providers/hns/hns_roce_u_hw_v2.c b/providers/hns/hns_roce_u_hw_v2.c index 4988943a..f947dbd7 100644 --- a/providers/hns/hns_roce_u_hw_v2.c +++ b/providers/hns/hns_roce_u_hw_v2.c @@ -262,7 +262,7 @@ static void hns_roce_free_srq_wqe(struct hns_roce_srq *srq, uint16_t ind) bitmap_num = ind / BIT_CNT_PER_LONG; bit_num = ind % BIT_CNT_PER_LONG; srq->idx_que.bitmap[bitmap_num] |= (1ULL << bit_num); - srq->tail++; + srq->idx_que.tail++; pthread_spin_unlock(&srq->lock); } @@ -1564,7 +1564,7 @@ static int hns_roce_u_v2_post_srq_recv(struct ibv_srq *ib_srq, pthread_spin_lock(&srq->lock); /* current idx of srqwq */ - ind = srq->head & (srq->wqe_cnt - 1); + ind = srq->idx_que.head & (srq->wqe_cnt - 1); max_sge = srq->max_gs - srq->rsv_sge; for (nreq = 0; wr; ++nreq, wr = wr->next) { @@ -1574,7 +1574,7 @@ static int hns_roce_u_v2_post_srq_recv(struct ibv_srq *ib_srq, break; } - if (srq->head == srq->tail) { + if (srq->idx_que.head == srq->idx_que.tail) { ret = -ENOMEM; *bad_wr = wr; break; @@ -1607,7 +1607,7 @@ static int hns_roce_u_v2_post_srq_recv(struct ibv_srq *ib_srq, } if (nreq) { - srq->head += nreq; + srq->idx_que.head += nreq; /* * Make sure that descriptors are written before @@ -1617,8 +1617,8 @@ static int hns_roce_u_v2_post_srq_recv(struct ibv_srq *ib_srq, srq_db.byte_4 = htole32(HNS_ROCE_V2_SRQ_DB << DB_BYTE_4_CMD_S | srq->srqn); - srq_db.parameter = - htole32(srq->head & DB_PARAM_SRQ_PRODUCER_COUNTER_M); + srq_db.parameter = htole32(srq->idx_que.head & + DB_PARAM_SRQ_PRODUCER_COUNTER_M); hns_roce_write64((uint32_t *)&srq_db, ctx, ROCEE_VF_DB_CFG0_OFFSET); diff --git a/providers/hns/hns_roce_u_verbs.c b/providers/hns/hns_roce_u_verbs.c index 30ab072a..9b4934b9 100644 --- a/providers/hns/hns_roce_u_verbs.c +++ b/providers/hns/hns_roce_u_verbs.c @@ -491,6 +491,9 @@ static int hns_roce_create_idx_que(struct hns_roce_srq *srq) for (i = 0; i < idx_que->bitmap_cnt; ++i) idx_que->bitmap[i] = ~(0UL); + idx_que->head = 0; + idx_que->tail = srq->wqe_cnt - 1; + return 0; } @@ -512,9 +515,6 @@ static int hns_roce_alloc_srq_buf(struct hns_roce_srq *srq) return ENOMEM; } - srq->head = 0; - srq->tail = srq->wqe_cnt - 1; - return 0; } -- 2.33.0