From 96058fd825847c8e639add8d1a5c4da85f450e28 Mon Sep 17 00:00:00 2001 From: Konstantin Taranov Date: Tue, 14 May 2024 10:38:17 +0200 Subject: [PATCH] providers/mana: fix align_hw_size and improve get_wqe_size [ Upstream commit f79e367f8c4d6405a43f8ba1126168b8c9b24827 ] Mana HW expects buffers to be a power of 2 and be at least 4KB. The existing align_hw_size returns 1 when input is 0, providing incorrect buffer size for empty queues. Change the order of align and pow to get 4096 for the input 0, which is expected by the HW. Use uint32_t in the get_wqe_size helper. Fixes: 443f196deee0 ("mana: Microsoft Azure Network Adapter (MANA) RDMA provider") Signed-off-by: Konstantin Taranov Signed-off-by: Nicolas Morey --- providers/mana/mana.c | 4 +--- providers/mana/mana.h | 20 +++++--------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/providers/mana/mana.c b/providers/mana/mana.c index 90aabd9d5..3545c579b 100644 --- a/providers/mana/mana.c +++ b/providers/mana/mana.c @@ -215,9 +215,7 @@ struct ibv_cq *mana_create_cq(struct ibv_context *context, int cqe, if (!cq) return NULL; - cq_size = cqe * COMP_ENTRY_SIZE; - cq_size = roundup_pow_of_two(cq_size); - cq_size = align(cq_size, MANA_PAGE_SIZE); + cq_size = align_hw_size(cqe * COMP_ENTRY_SIZE); cq->buf = ctx->extern_alloc.alloc(cq_size, ctx->extern_alloc.data); if (!cq->buf) { diff --git a/providers/mana/mana.h b/providers/mana/mana.h index 50d747314..6042b1b14 100644 --- a/providers/mana/mana.h +++ b/providers/mana/mana.h @@ -24,25 +24,15 @@ #define DOORBELL_PAGE_SIZE 4096 #define MANA_PAGE_SIZE 4096 -static inline int align_next_power2(int size) +static inline uint32_t align_hw_size(uint32_t size) { - int val = 1; - - while (val < size) - val <<= 1; - - return val; -} - -static inline int align_hw_size(int size) -{ - size = align(size, MANA_PAGE_SIZE); - return align_next_power2(size); + size = roundup_pow_of_two(size); + return align(size, MANA_PAGE_SIZE); } -static inline int get_wqe_size(int sge) +static inline uint32_t get_wqe_size(uint32_t sge) { - int wqe_size = sge * SGE_SIZE + DMA_OOB_SIZE + INLINE_OOB_SMALL_SIZE; + uint32_t wqe_size = sge * SGE_SIZE + DMA_OOB_SIZE + INLINE_OOB_SMALL_SIZE; return align(wqe_size, GDMA_WQE_ALIGNMENT_UNIT_SIZE); }