Skip to content

Commit

Permalink
bnxt_re/lib: Adapt align and roundup_pow_of_two helpers
Browse files Browse the repository at this point in the history
Use align and roundup_pow_of_two helper functions from the utils.
This is required to fix compilation issues seen while including utils.h
in subsequent patches.

Signed-off-by: Chandramohan Akula <[email protected]>
Signed-off-by: Selvin Xavier <[email protected]>
  • Loading branch information
chandramohan-akula authored and selvintxavier committed Aug 2, 2023
1 parent 3a1e777 commit ff78468
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
3 changes: 2 additions & 1 deletion providers/bnxt_re/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include <string.h>
#include <sys/mman.h>
#include <util/util.h>

#include "main.h"

Expand All @@ -47,7 +48,7 @@ int bnxt_re_alloc_aligned(struct bnxt_re_queue *que, uint32_t pg_size)
int ret, bytes;

bytes = (que->depth * que->stride);
que->bytes = get_aligned(bytes, pg_size);
que->bytes = align(bytes, pg_size);
que->va = mmap(NULL, que->bytes, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (que->va == MAP_FAILED) {
Expand Down
18 changes: 0 additions & 18 deletions providers/bnxt_re/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,6 @@ struct bnxt_re_queue {
pthread_spinlock_t qlock;
};

static inline unsigned long get_aligned(uint32_t size, uint32_t al_size)
{
return (unsigned long)(size + al_size - 1) & ~(al_size - 1);
}

static inline unsigned long roundup_pow_of_two(unsigned long val)
{
unsigned long roundup = 1;

if (val == 1)
return (roundup << 1);

while (roundup < val)
roundup <<= 1;

return roundup;
}

int bnxt_re_alloc_aligned(struct bnxt_re_queue *que, uint32_t pg_size);
void bnxt_re_free_aligned(struct bnxt_re_queue *que);

Expand Down
7 changes: 4 additions & 3 deletions providers/bnxt_re/verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <unistd.h>

#include <util/compiler.h>
#include <util/util.h>

#include "main.h"
#include "verbs.h"
Expand Down Expand Up @@ -1138,13 +1139,13 @@ static int bnxt_re_get_sq_slots(struct bnxt_re_dev *rdev,
hdr_sz = bnxt_re_get_sqe_hdr_sz();
stride = sizeof(struct bnxt_re_sge);
max_wqesz = bnxt_re_calc_wqe_sz(rdev->devattr.max_sge);
ilsize = get_aligned(*ils, hdr_sz);
ilsize = align(*ils, hdr_sz);

wqe_size = bnxt_re_calc_wqe_sz(nsge);
if (ilsize) {
cal_ils = hdr_sz + ilsize;
wqe_size = MAX(cal_ils, wqe_size);
wqe_size = get_aligned(wqe_size, hdr_sz);
wqe_size = align(wqe_size, hdr_sz);
}
if (wqe_size > max_wqesz)
return -EINVAL;
Expand Down Expand Up @@ -1431,7 +1432,7 @@ static inline int bnxt_re_calc_inline_len(struct ibv_send_wr *swr)
illen = 0;
for (indx = 0; indx < swr->num_sge; indx++)
illen += swr->sg_list[indx].length;
return get_aligned(illen, sizeof(struct bnxt_re_sge));
return align(illen, sizeof(struct bnxt_re_sge));
}

static int bnxt_re_put_inline(struct bnxt_re_queue *que, uint32_t *idx,
Expand Down

0 comments on commit ff78468

Please sign in to comment.