Skip to content

Commit

Permalink
bnxt_re/lib: Get the shared CQ toggle page
Browse files Browse the repository at this point in the history
Implements the UAPI call to get the CQ toggle page.
Also, get the toggle bit from the shared page and
use it while arming the CQ.

Signed-off-by: Selvin Xavier <[email protected]>
  • Loading branch information
selvintxavier committed Dec 19, 2023
1 parent 0a0e0d0 commit d5d79c8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
9 changes: 7 additions & 2 deletions providers/bnxt_re/db.c
Expand Up @@ -178,12 +178,17 @@ void bnxt_re_ring_cq_db(struct bnxt_re_cq *cq)

void bnxt_re_ring_cq_arm_db(struct bnxt_re_cq *cq, uint8_t aflag)
{
uint32_t epoch, toggle = 0;
struct bnxt_re_db_hdr hdr;
uint32_t epoch;
uint32_t *pgptr;

pgptr = (uint32_t *)cq->toggle_map;
if (pgptr)
toggle = *pgptr;

bnxt_re_do_pacing(cq->cntx, &cq->rand);
epoch = (cq->cqq.flags & BNXT_RE_FLAG_EPOCH_HEAD_MASK) << BNXT_RE_DB_EPOCH_HEAD_SHIFT;
bnxt_re_init_db_hdr(&hdr, cq->cqq.head | epoch, cq->cqid, 0, aflag);
bnxt_re_init_db_hdr(&hdr, cq->cqq.head | epoch, cq->cqid, toggle, aflag);
bnxt_re_ring_db(cq->udpi, &hdr);
}

Expand Down
8 changes: 8 additions & 0 deletions providers/bnxt_re/main.h
Expand Up @@ -102,6 +102,9 @@ struct bnxt_re_cq {
uint32_t cqe_size;
uint8_t phase;
struct xorshift32_state rand;
uint32_t mem_handle;
void *toggle_map;
uint32_t toggle_size;
};

struct bnxt_re_push_buffer {
Expand Down Expand Up @@ -254,6 +257,8 @@ struct bnxt_re_mmap_info {
__u32 dpi;
__u64 alloc_offset;
__u32 alloc_size;
__u32 pg_offset;
__u32 res_id;
};

/* DB ring functions used internally*/
Expand Down Expand Up @@ -282,6 +287,9 @@ int bnxt_re_alloc_page(struct ibv_context *ibvctx,
struct bnxt_re_mmap_info *minfo,
uint32_t *page_handle);
int bnxt_re_notify_drv(struct ibv_context *ibvctx);
int bnxt_re_get_toggle_mem(struct ibv_context *ibvctx,
struct bnxt_re_mmap_info *minfo,
uint32_t *page_handle);

/* pointer conversion functions*/
static inline struct bnxt_re_dev *to_bnxt_re_dev(struct ibv_device *ibvdev)
Expand Down
46 changes: 46 additions & 0 deletions providers/bnxt_re/verbs.c
Expand Up @@ -104,6 +104,35 @@ static int bnxt_re_map_db_page(struct ibv_context *ibvctx,
return 0;
}

int bnxt_re_get_toggle_mem(struct ibv_context *ibvctx,
struct bnxt_re_mmap_info *minfo,
uint32_t *page_handle)
{
DECLARE_COMMAND_BUFFER(cmd,
BNXT_RE_OBJECT_GET_TOGGLE_MEM,
BNXT_RE_METHOD_GET_TOGGLE_MEM,
4);
struct ib_uverbs_attr *handle;
int ret;

handle = fill_attr_out_obj(cmd, BNXT_RE_TOGGLE_MEM_HANDLE);
fill_attr_const_in(cmd, BNXT_RE_TOGGLE_MEM_TYPE, minfo->type);
fill_attr_in(cmd, BNXT_RE_TOGGLE_MEM_RES_ID, &minfo->res_id, sizeof(minfo->res_id));
fill_attr_out_ptr(cmd, BNXT_RE_TOGGLE_MEM_MMAP_PAGE, &minfo->alloc_offset);
fill_attr_out_ptr(cmd, BNXT_RE_TOGGLE_MEM_MMAP_LENGTH, &minfo->alloc_size);
fill_attr_out_ptr(cmd, BNXT_RE_TOGGLE_MEM_MMAP_OFFSET, &minfo->pg_offset);


ret = execute_ioctl(ibvctx, cmd);

if (ret)
return ret;
if (page_handle)
*page_handle = read_attr_obj(BNXT_RE_TOGGLE_MEM_HANDLE, handle);
return 0;
}


int bnxt_re_notify_drv(struct ibv_context *ibvctx)
{
DECLARE_COMMAND_BUFFER(cmd,
Expand Down Expand Up @@ -275,6 +304,8 @@ struct ibv_cq *bnxt_re_create_cq(struct ibv_context *ibvctx, int ncqe,
struct bnxt_re_cq *cq;
struct ubnxt_re_cq cmd;
struct ubnxt_re_cq_resp resp;
struct bnxt_re_mmap_info minfo = {};
int ret;

struct bnxt_re_context *cntx = to_bnxt_re_context(ibvctx);
struct bnxt_re_dev *dev = to_bnxt_re_dev(ibvctx->device);
Expand Down Expand Up @@ -313,6 +344,19 @@ struct ibv_cq *bnxt_re_create_cq(struct ibv_context *ibvctx, int ncqe,
cq->cntx = cntx;
cq->rand.seed = cq->cqid;

if (resp.comp_mask & BNXT_RE_CQ_TOGGLE_PAGE_SUPPORT) {

minfo.type = BNXT_RE_CQ_TOGGLE_MEM;
minfo.res_id = resp.cqid;
ret = bnxt_re_get_toggle_mem(ibvctx, &minfo, &cq->mem_handle);
if (ret)
goto cmdfail;
cq->toggle_map = mmap(NULL, minfo.alloc_size, PROT_READ,
MAP_SHARED, ibvctx->cmd_fd, minfo.alloc_offset);
if (cq->toggle_map == MAP_FAILED)
goto cmdfail;
cq->toggle_size = minfo.alloc_size;
}
list_head_init(&cq->sfhead);
list_head_init(&cq->rfhead);
list_head_init(&cq->prev_cq_head);
Expand Down Expand Up @@ -414,6 +458,8 @@ int bnxt_re_destroy_cq(struct ibv_cq *ibvcq)
int status;
struct bnxt_re_cq *cq = to_bnxt_re_cq(ibvcq);

if (cq->toggle_map)
munmap(cq->toggle_map, cq->toggle_size);
status = ibv_cmd_destroy_cq(ibvcq);
if (status)
return status;
Expand Down

0 comments on commit d5d79c8

Please sign in to comment.