From patchwork Wed Jun 20 16:28:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 10477897 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AD9E760210 for ; Wed, 20 Jun 2018 16:30:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96C2A28A1A for ; Wed, 20 Jun 2018 16:30:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AF4928DFB; Wed, 20 Jun 2018 16:30:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0ED928A1A for ; Wed, 20 Jun 2018 16:30:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754433AbeFTQa3 (ORCPT ); Wed, 20 Jun 2018 12:30:29 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:55882 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932264AbeFTQ2q (ORCPT ); Wed, 20 Jun 2018 12:28:46 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 20 Jun 2018 19:31:12 +0300 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [10.7.2.17]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w5KGSdTN011998; Wed, 20 Jun 2018 19:28:39 +0300 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [127.0.0.1]) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8) with ESMTP id w5KGSdAk024821; Wed, 20 Jun 2018 19:28:39 +0300 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id w5KGSdvg024820; Wed, 20 Jun 2018 19:28:39 +0300 From: Yishai Hadas To: linux-rdma@vger.kernel.org Cc: yishaih@mellanox.com, yonatanc@mellanox.com, majd@mellanox.com Subject: [PATCH rdma-core 3/5] verbs: Replace ibv_mr with verbs_mr Date: Wed, 20 Jun 2018 19:28:20 +0300 Message-Id: <1529512102-24740-4-git-send-email-yishaih@mellanox.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1529512102-24740-1-git-send-email-yishaih@mellanox.com> References: <1529512102-24740-1-git-send-email-yishaih@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Yonatan Cohen This is a pre-patch for introduction of ibv_alloc_null_mr. The driver should not depend on ibv semantics but instead use its own private data structures and methods to comply with user verbs. Signed-off-by: Yonatan Cohen Reviewed-by: Guy Levi Signed-off-by: Yishai Hadas --- libibverbs/cmd.c | 30 ++++++++++++++------------- libibverbs/cmd_dm.c | 18 ++++++++-------- libibverbs/driver.h | 26 +++++++++++++++++------ libibverbs/dummy_ops.c | 6 +++--- libibverbs/verbs.c | 7 ++++--- providers/bnxt_re/main.h | 2 +- providers/bnxt_re/verbs.c | 10 ++++----- providers/bnxt_re/verbs.h | 2 +- providers/cxgb3/iwch.h | 8 ++++---- providers/cxgb3/verbs.c | 20 +++++++++--------- providers/cxgb4/libcxgb4.h | 8 ++++---- providers/cxgb4/verbs.c | 18 ++++++++-------- providers/hfi1verbs/hfiverbs.h | 2 +- providers/hfi1verbs/verbs.c | 18 ++++++++-------- providers/hns/hns_roce_u.h | 4 ++-- providers/hns/hns_roce_u_verbs.c | 22 ++++++++++---------- providers/i40iw/i40iw_umain.h | 6 +++--- providers/i40iw/i40iw_uverbs.c | 43 +++++++++++++++++++++------------------ providers/ipathverbs/ipathverbs.h | 2 +- providers/ipathverbs/verbs.c | 18 ++++++++-------- providers/mlx4/mlx4.h | 4 ++-- providers/mlx4/verbs.c | 24 +++++++++++----------- providers/mlx5/mlx5.h | 8 ++++---- providers/mlx5/verbs.c | 21 +++++++++---------- providers/mthca/ah.c | 2 +- providers/mthca/mthca.h | 2 +- providers/mthca/verbs.c | 36 ++++++++++++++++---------------- providers/nes/nes_umain.h | 6 +++--- providers/nes/nes_uverbs.c | 39 ++++++++++++++++++----------------- providers/ocrdma/ocrdma_main.h | 4 ++-- providers/ocrdma/ocrdma_verbs.c | 12 +++++------ providers/qedr/qelr.h | 2 +- providers/qedr/qelr_main.h | 2 +- providers/qedr/qelr_verbs.c | 18 ++++++++-------- providers/qedr/qelr_verbs.h | 2 +- providers/rxe/rxe.c | 19 ++++++++--------- providers/vmw_pvrdma/pvrdma.h | 2 +- providers/vmw_pvrdma/verbs.c | 18 ++++++++-------- 38 files changed, 256 insertions(+), 235 deletions(-) diff --git a/libibverbs/cmd.c b/libibverbs/cmd.c index d3832f8..572ef58 100644 --- a/libibverbs/cmd.c +++ b/libibverbs/cmd.c @@ -390,7 +390,7 @@ int ibv_cmd_close_xrcd(struct verbs_xrcd *xrcd) int ibv_cmd_reg_mr(struct ibv_pd *pd, void *addr, size_t length, uint64_t hca_va, int access, - struct ibv_mr *mr, struct ibv_reg_mr *cmd, + struct verbs_mr *vmr, struct ibv_reg_mr *cmd, size_t cmd_size, struct ib_uverbs_reg_mr_resp *resp, size_t resp_size) { @@ -408,15 +408,16 @@ int ibv_cmd_reg_mr(struct ibv_pd *pd, void *addr, size_t length, (void) VALGRIND_MAKE_MEM_DEFINED(resp, resp_size); - mr->handle = resp->mr_handle; - mr->lkey = resp->lkey; - mr->rkey = resp->rkey; - mr->context = pd->context; + vmr->ibv_mr.handle = resp->mr_handle; + vmr->ibv_mr.lkey = resp->lkey; + vmr->ibv_mr.rkey = resp->rkey; + vmr->ibv_mr.context = pd->context; + vmr->mr_type = IBV_MR_TYPE_MR; return 0; } -int ibv_cmd_rereg_mr(struct ibv_mr *mr, uint32_t flags, void *addr, +int ibv_cmd_rereg_mr(struct verbs_mr *vmr, uint32_t flags, void *addr, size_t length, uint64_t hca_va, int access, struct ibv_pd *pd, struct ibv_rereg_mr *cmd, size_t cmd_sz, struct ib_uverbs_rereg_mr_resp *resp, @@ -424,7 +425,7 @@ int ibv_cmd_rereg_mr(struct ibv_mr *mr, uint32_t flags, void *addr, { IBV_INIT_CMD_RESP(cmd, cmd_sz, REREG_MR, resp, resp_sz); - cmd->mr_handle = mr->handle; + cmd->mr_handle = vmr->ibv_mr.handle; cmd->flags = flags; cmd->start = (uintptr_t)addr; cmd->length = length; @@ -432,27 +433,28 @@ int ibv_cmd_rereg_mr(struct ibv_mr *mr, uint32_t flags, void *addr, cmd->pd_handle = (flags & IBV_REREG_MR_CHANGE_PD) ? pd->handle : 0; cmd->access_flags = access; - if (write(mr->context->cmd_fd, cmd, cmd_sz) != cmd_sz) + if (write(vmr->ibv_mr.context->cmd_fd, cmd, cmd_sz) != cmd_sz) return errno; (void)VALGRIND_MAKE_MEM_DEFINED(resp, resp_sz); - mr->lkey = resp->lkey; - mr->rkey = resp->rkey; + vmr->ibv_mr.lkey = resp->lkey; + vmr->ibv_mr.rkey = resp->rkey; if (flags & IBV_REREG_MR_CHANGE_PD) - mr->context = pd->context; + vmr->ibv_mr.context = pd->context; return 0; } -int ibv_cmd_dereg_mr(struct ibv_mr *mr) +int ibv_cmd_dereg_mr(struct verbs_mr *vmr) { struct ibv_dereg_mr cmd; IBV_INIT_CMD(&cmd, sizeof cmd, DEREG_MR); - cmd.mr_handle = mr->handle; + cmd.mr_handle = vmr->ibv_mr.handle; - if (write(mr->context->cmd_fd, &cmd, sizeof cmd) != sizeof cmd) + if (write(vmr->ibv_mr.context->cmd_fd, &cmd, sizeof(cmd)) != + sizeof(cmd)) return errno; return 0; diff --git a/libibverbs/cmd_dm.c b/libibverbs/cmd_dm.c index 9a010bc..e2018c3 100644 --- a/libibverbs/cmd_dm.c +++ b/libibverbs/cmd_dm.c @@ -70,7 +70,7 @@ int ibv_cmd_free_dm(struct verbs_dm *dm) int ibv_cmd_reg_dm_mr(struct ibv_pd *pd, struct verbs_dm *dm, uint64_t offset, size_t length, - unsigned int access, struct ibv_mr *mr, + unsigned int access, struct verbs_mr *vmr, struct ibv_command_buffer *link) { DECLARE_COMMAND_BUFFER_LINK(cmdb, UVERBS_OBJECT_MR, UVERBS_METHOD_DM_MR_REG, @@ -102,13 +102,15 @@ int ibv_cmd_reg_dm_mr(struct ibv_pd *pd, struct verbs_dm *dm, if (ret) return errno; - mr->handle = read_attr_obj(UVERBS_ATTR_REG_DM_MR_HANDLE, handle); - mr->context = pd->context; - mr->lkey = lkey; - mr->rkey = rkey; - mr->length = length; - mr->pd = pd; - mr->addr = NULL; + vmr->ibv_mr.handle = + read_attr_obj(UVERBS_ATTR_REG_DM_MR_HANDLE, handle); + vmr->ibv_mr.context = pd->context; + vmr->ibv_mr.lkey = lkey; + vmr->ibv_mr.rkey = rkey; + vmr->ibv_mr.length = length; + vmr->ibv_mr.pd = pd; + vmr->ibv_mr.addr = NULL; + vmr->mr_type = IBV_MR_TYPE_MR; return 0; } diff --git a/libibverbs/driver.h b/libibverbs/driver.h index 752121c..43077f7 100644 --- a/libibverbs/driver.h +++ b/libibverbs/driver.h @@ -85,6 +85,20 @@ enum ibv_gid_type { IBV_GID_TYPE_ROCE_V2, }; +enum ibv_mr_type { + IBV_MR_TYPE_MR, +}; + +struct verbs_mr { + struct ibv_mr ibv_mr; + enum ibv_mr_type mr_type; +}; + +static inline struct verbs_mr *verbs_get_mr(struct ibv_mr *mr) +{ + return container_of(mr, struct verbs_mr, ibv_mr); +} + struct verbs_qp { struct ibv_qp qp; uint32_t comp_mask; @@ -252,7 +266,7 @@ struct verbs_context_ops { int (*dealloc_mw)(struct ibv_mw *mw); int (*dealloc_pd)(struct ibv_pd *pd); int (*dealloc_td)(struct ibv_td *td); - int (*dereg_mr)(struct ibv_mr *mr); + int (*dereg_mr)(struct verbs_mr *vmr); int (*destroy_ah)(struct ibv_ah *ah); int (*destroy_counters)(struct ibv_counters *counters); int (*destroy_cq)(struct ibv_cq *cq); @@ -313,7 +327,7 @@ struct verbs_context_ops { struct ibv_mr *(*reg_mr)(struct ibv_pd *pd, void *addr, size_t length, int access); int (*req_notify_cq)(struct ibv_cq *cq, int solicited_only); - int (*rereg_mr)(struct ibv_mr *mr, int flags, struct ibv_pd *pd, + int (*rereg_mr)(struct verbs_mr *vmr, int flags, struct ibv_pd *pd, void *addr, size_t length, int access); int (*resize_cq)(struct ibv_cq *cq, int cqe); }; @@ -406,15 +420,15 @@ int ibv_cmd_open_xrcd(struct ibv_context *context, struct verbs_xrcd *xrcd, int ibv_cmd_close_xrcd(struct verbs_xrcd *xrcd); int ibv_cmd_reg_mr(struct ibv_pd *pd, void *addr, size_t length, uint64_t hca_va, int access, - struct ibv_mr *mr, struct ibv_reg_mr *cmd, + struct verbs_mr *vmr, struct ibv_reg_mr *cmd, size_t cmd_size, struct ib_uverbs_reg_mr_resp *resp, size_t resp_size); -int ibv_cmd_rereg_mr(struct ibv_mr *mr, uint32_t flags, void *addr, +int ibv_cmd_rereg_mr(struct verbs_mr *vmr, uint32_t flags, void *addr, size_t length, uint64_t hca_va, int access, struct ibv_pd *pd, struct ibv_rereg_mr *cmd, size_t cmd_sz, struct ib_uverbs_rereg_mr_resp *resp, size_t resp_sz); -int ibv_cmd_dereg_mr(struct ibv_mr *mr); +int ibv_cmd_dereg_mr(struct verbs_mr *vmr); int ibv_cmd_alloc_mw(struct ibv_pd *pd, enum ibv_mw_type type, struct ibv_mw *mw, struct ibv_alloc_mw *cmd, size_t cmd_size, @@ -562,7 +576,7 @@ int ibv_cmd_alloc_dm(struct ibv_context *ctx, int ibv_cmd_free_dm(struct verbs_dm *dm); int ibv_cmd_reg_dm_mr(struct ibv_pd *pd, struct verbs_dm *dm, uint64_t offset, size_t length, - unsigned int access, struct ibv_mr *mr, + unsigned int access, struct verbs_mr *vmr, struct ibv_command_buffer *link); /* diff --git a/libibverbs/dummy_ops.c b/libibverbs/dummy_ops.c index dfb56b0..1fd8f84 100644 --- a/libibverbs/dummy_ops.c +++ b/libibverbs/dummy_ops.c @@ -200,7 +200,7 @@ static int dealloc_td(struct ibv_td *td) return ENOSYS; } -static int dereg_mr(struct ibv_mr *mr) +static int dereg_mr(struct verbs_mr *vmr) { return ENOSYS; } @@ -406,8 +406,8 @@ static int req_notify_cq(struct ibv_cq *cq, int solicited_only) return ENOSYS; } -static int rereg_mr(struct ibv_mr *mr, int flags, struct ibv_pd *pd, void *addr, - size_t length, int access) +static int rereg_mr(struct verbs_mr *vmr, int flags, struct ibv_pd *pd, + void *addr, size_t length, int access) { errno = ENOSYS; return IBV_REREG_MR_ERR_INPUT; diff --git a/libibverbs/verbs.c b/libibverbs/verbs.c index d281004..dd74e64 100644 --- a/libibverbs/verbs.c +++ b/libibverbs/verbs.c @@ -278,8 +278,9 @@ LATEST_SYMVER_FUNC(ibv_rereg_mr, 1_1, "IBVERBS_1.1", old_addr = mr->addr; old_len = mr->length; - err = get_ops(mr->context) - ->rereg_mr(mr, flags, pd, addr, length, access); + err = get_ops(mr->context)->rereg_mr(verbs_get_mr(mr), + flags, pd, addr, + length, access); if (!err) { if (flags & IBV_REREG_MR_CHANGE_PD) mr->pd = pd; @@ -309,7 +310,7 @@ LATEST_SYMVER_FUNC(ibv_dereg_mr, 1_1, "IBVERBS_1.1", void *addr = mr->addr; size_t length = mr->length; - ret = get_ops(mr->context)->dereg_mr(mr); + ret = get_ops(mr->context)->dereg_mr(verbs_get_mr(mr)); if (!ret) ibv_dofork_range(addr, length); diff --git a/providers/bnxt_re/main.h b/providers/bnxt_re/main.h index 08aa277..edac40e 100644 --- a/providers/bnxt_re/main.h +++ b/providers/bnxt_re/main.h @@ -126,7 +126,7 @@ struct bnxt_re_qp { }; struct bnxt_re_mr { - struct ibv_mr ibvmr; + struct verbs_mr vmr; }; struct bnxt_re_ah { diff --git a/providers/bnxt_re/verbs.c b/providers/bnxt_re/verbs.c index c90581d..7c597bc 100644 --- a/providers/bnxt_re/verbs.c +++ b/providers/bnxt_re/verbs.c @@ -145,21 +145,21 @@ struct ibv_mr *bnxt_re_reg_mr(struct ibv_pd *ibvpd, void *sva, size_t len, if (!mr) return NULL; - if (ibv_cmd_reg_mr(ibvpd, sva, len, (uintptr_t)sva, access, &mr->ibvmr, + if (ibv_cmd_reg_mr(ibvpd, sva, len, (uintptr_t)sva, access, &mr->vmr, &cmd, sizeof(cmd), &resp.ibv_resp, sizeof(resp))) { free(mr); return NULL; } - return &mr->ibvmr; + return &mr->vmr.ibv_mr; } -int bnxt_re_dereg_mr(struct ibv_mr *ibvmr) +int bnxt_re_dereg_mr(struct verbs_mr *vmr) { - struct bnxt_re_mr *mr = (struct bnxt_re_mr *)ibvmr; + struct bnxt_re_mr *mr = (struct bnxt_re_mr *)vmr; int status; - status = ibv_cmd_dereg_mr(ibvmr); + status = ibv_cmd_dereg_mr(vmr); if (status) return status; free(mr); diff --git a/providers/bnxt_re/verbs.h b/providers/bnxt_re/verbs.h index 1b2a4a7..6e5f092 100644 --- a/providers/bnxt_re/verbs.h +++ b/providers/bnxt_re/verbs.h @@ -63,7 +63,7 @@ struct ibv_pd *bnxt_re_alloc_pd(struct ibv_context *uctx); int bnxt_re_free_pd(struct ibv_pd *ibvpd); struct ibv_mr *bnxt_re_reg_mr(struct ibv_pd *ibvpd, void *buf, size_t len, int ibv_access_flags); -int bnxt_re_dereg_mr(struct ibv_mr *ibvmr); +int bnxt_re_dereg_mr(struct verbs_mr *vmr); struct ibv_cq *bnxt_re_create_cq(struct ibv_context *uctx, int ncqe, struct ibv_comp_channel *ch, int vec); diff --git a/providers/cxgb3/iwch.h b/providers/cxgb3/iwch.h index 0b8060c..a6fea23 100644 --- a/providers/cxgb3/iwch.h +++ b/providers/cxgb3/iwch.h @@ -79,7 +79,7 @@ struct iwch_pd { }; struct iwch_mr { - struct ibv_mr ibv_mr; + struct verbs_mr vmr; uint64_t va_fbo; uint32_t page_size; uint32_t pbl_addr; @@ -129,9 +129,9 @@ static inline struct iwch_qp *to_iwch_qp(struct ibv_qp *ibqp) return to_iwch_xxx(qp, qp); } -static inline struct iwch_mr *to_iwch_mr(struct ibv_mr *ibmr) +static inline struct iwch_mr *to_iwch_mr(struct verbs_mr *vmr) { - return to_iwch_xxx(mr, mr); + return container_of(vmr, struct iwch_mr, vmr); } static inline unsigned long long_log2(unsigned long x) @@ -152,7 +152,7 @@ extern int iwch_free_pd(struct ibv_pd *pd); extern struct ibv_mr *iwch_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access); -extern int iwch_dereg_mr(struct ibv_mr *mr); +extern int iwch_dereg_mr(struct verbs_mr *mr); struct ibv_cq *iwch_create_cq(struct ibv_context *context, int cqe, struct ibv_comp_channel *channel, diff --git a/providers/cxgb3/verbs.c b/providers/cxgb3/verbs.c index 0424104..67eb588 100644 --- a/providers/cxgb3/verbs.c +++ b/providers/cxgb3/verbs.c @@ -117,7 +117,7 @@ static struct ibv_mr *__iwch_reg_mr(struct ibv_pd *pd, void *addr, return NULL; if (ibv_cmd_reg_mr(pd, addr, length, hca_va, - access, &mhp->ibv_mr, &cmd, sizeof cmd, + access, &mhp->vmr, &cmd, sizeof(cmd), &resp.ibv_resp, sizeof resp)) { free(mhp); return NULL; @@ -128,16 +128,16 @@ static struct ibv_mr *__iwch_reg_mr(struct ibv_pd *pd, void *addr, mhp->pbl_addr = resp.pbl_addr; mhp->len = length; - PDBG("%s stag 0x%x va_fbo 0x%" PRIx64 + PDBG("%s stag 0x%x va_fbo 0x%" PRIx64 " page_size %d pbl_addr 0x%x len %d\n", - __FUNCTION__, mhp->ibv_mr.rkey, mhp->va_fbo, + __func__, mhp->vmr.ibv_mr.rkey, mhp->va_fbo, mhp->page_size, mhp->pbl_addr, mhp->len); pthread_spin_lock(&dev->lock); - dev->mmid2ptr[t3_mmid(mhp->ibv_mr.lkey)] = mhp; + dev->mmid2ptr[t3_mmid(mhp->vmr.ibv_mr.lkey)] = mhp; pthread_spin_unlock(&dev->lock); - return &mhp->ibv_mr; + return &mhp->vmr.ibv_mr; } struct ibv_mr *iwch_reg_mr(struct ibv_pd *pd, void *addr, @@ -147,20 +147,20 @@ struct ibv_mr *iwch_reg_mr(struct ibv_pd *pd, void *addr, return __iwch_reg_mr(pd, addr, length, (uintptr_t) addr, access); } -int iwch_dereg_mr(struct ibv_mr *mr) +int iwch_dereg_mr(struct verbs_mr *vmr) { int ret; - struct iwch_device *dev = to_iwch_dev(mr->pd->context->device); + struct iwch_device *dev = to_iwch_dev(vmr->ibv_mr.pd->context->device); - ret = ibv_cmd_dereg_mr(mr); + ret = ibv_cmd_dereg_mr(vmr); if (ret) return ret; pthread_spin_lock(&dev->lock); - dev->mmid2ptr[t3_mmid(mr->lkey)] = NULL; + dev->mmid2ptr[t3_mmid(vmr->ibv_mr.lkey)] = NULL; pthread_spin_unlock(&dev->lock); - free(to_iwch_mr(mr)); + free(to_iwch_mr(vmr)); return 0; } diff --git a/providers/cxgb4/libcxgb4.h b/providers/cxgb4/libcxgb4.h index 8eda822..d6e0d78 100644 --- a/providers/cxgb4/libcxgb4.h +++ b/providers/cxgb4/libcxgb4.h @@ -90,7 +90,7 @@ struct c4iw_pd { }; struct c4iw_mr { - struct ibv_mr ibv_mr; + struct verbs_mr vmr; uint64_t va_fbo; uint32_t len; }; @@ -147,9 +147,9 @@ static inline struct c4iw_qp *to_c4iw_qp(struct ibv_qp *ibqp) return to_c4iw_xxx(qp, qp); } -static inline struct c4iw_mr *to_c4iw_mr(struct ibv_mr *ibmr) +static inline struct c4iw_mr *to_c4iw_mr(struct verbs_mr *vmr) { - return to_c4iw_xxx(mr, mr); + return container_of(vmr, struct c4iw_mr, vmr); } static inline struct c4iw_qp *get_qhp(struct c4iw_dev *rhp, u32 qid) @@ -180,7 +180,7 @@ int c4iw_free_pd(struct ibv_pd *pd); struct ibv_mr *c4iw_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access); -int c4iw_dereg_mr(struct ibv_mr *mr); +int c4iw_dereg_mr(struct verbs_mr *vmr); struct ibv_cq *c4iw_create_cq(struct ibv_context *context, int cqe, struct ibv_comp_channel *channel, diff --git a/providers/cxgb4/verbs.c b/providers/cxgb4/verbs.c index 988b62a..b8e316f 100644 --- a/providers/cxgb4/verbs.c +++ b/providers/cxgb4/verbs.c @@ -121,7 +121,7 @@ static struct ibv_mr *__c4iw_reg_mr(struct ibv_pd *pd, void *addr, return NULL; if (ibv_cmd_reg_mr(pd, addr, length, hca_va, - access, &mhp->ibv_mr, &cmd, sizeof cmd, + access, &mhp->vmr, &cmd, sizeof(cmd), &resp, sizeof resp)) { free(mhp); return NULL; @@ -131,13 +131,13 @@ static struct ibv_mr *__c4iw_reg_mr(struct ibv_pd *pd, void *addr, mhp->len = length; PDBG("%s stag 0x%x va_fbo 0x%" PRIx64 " len %d\n", - __func__, mhp->ibv_mr.rkey, mhp->va_fbo, mhp->len); + __func__, mhp->vmr.ibv_mr.rkey, mhp->va_fbo, mhp->len); pthread_spin_lock(&dev->lock); - dev->mmid2ptr[c4iw_mmid(mhp->ibv_mr.lkey)] = mhp; + dev->mmid2ptr[c4iw_mmid(mhp->vmr.ibv_mr.lkey)] = mhp; pthread_spin_unlock(&dev->lock); INC_STAT(mr); - return &mhp->ibv_mr; + return &mhp->vmr.ibv_mr; } struct ibv_mr *c4iw_reg_mr(struct ibv_pd *pd, void *addr, @@ -147,20 +147,20 @@ struct ibv_mr *c4iw_reg_mr(struct ibv_pd *pd, void *addr, return __c4iw_reg_mr(pd, addr, length, (uintptr_t) addr, access); } -int c4iw_dereg_mr(struct ibv_mr *mr) +int c4iw_dereg_mr(struct verbs_mr *vmr) { int ret; - struct c4iw_dev *dev = to_c4iw_dev(mr->pd->context->device); + struct c4iw_dev *dev = to_c4iw_dev(vmr->ibv_mr.pd->context->device); - ret = ibv_cmd_dereg_mr(mr); + ret = ibv_cmd_dereg_mr(vmr); if (ret) return ret; pthread_spin_lock(&dev->lock); - dev->mmid2ptr[c4iw_mmid(mr->lkey)] = NULL; + dev->mmid2ptr[c4iw_mmid(vmr->ibv_mr.lkey)] = NULL; pthread_spin_unlock(&dev->lock); - free(to_c4iw_mr(mr)); + free(to_c4iw_mr(vmr)); return 0; } diff --git a/providers/hfi1verbs/hfiverbs.h b/providers/hfi1verbs/hfiverbs.h index e7a05a0..070a01c 100644 --- a/providers/hfi1verbs/hfiverbs.h +++ b/providers/hfi1verbs/hfiverbs.h @@ -207,7 +207,7 @@ int hfi1_free_pd(struct ibv_pd *pd); struct ibv_mr *hfi1_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access); -int hfi1_dereg_mr(struct ibv_mr *mr); +int hfi1_dereg_mr(struct verbs_mr *vmr); struct ibv_cq *hfi1_create_cq(struct ibv_context *context, int cqe, struct ibv_comp_channel *channel, diff --git a/providers/hfi1verbs/verbs.c b/providers/hfi1verbs/verbs.c index 5a93bcb..ff001f6 100644 --- a/providers/hfi1verbs/verbs.c +++ b/providers/hfi1verbs/verbs.c @@ -132,35 +132,35 @@ int hfi1_free_pd(struct ibv_pd *pd) struct ibv_mr *hfi1_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access) { - struct ibv_mr *mr; + struct verbs_mr *vmr; struct ibv_reg_mr cmd; struct ib_uverbs_reg_mr_resp resp; int ret; - mr = malloc(sizeof *mr); - if (!mr) + vmr = malloc(sizeof(*vmr)); + if (!vmr) return NULL; - ret = ibv_cmd_reg_mr(pd, addr, length, (uintptr_t)addr, access, mr, + ret = ibv_cmd_reg_mr(pd, addr, length, (uintptr_t)addr, access, vmr, &cmd, sizeof cmd, &resp, sizeof resp); if (ret) { - free(mr); + free(vmr); return NULL; } - return mr; + return &vmr->ibv_mr; } -int hfi1_dereg_mr(struct ibv_mr *mr) +int hfi1_dereg_mr(struct verbs_mr *vmr) { int ret; - ret = ibv_cmd_dereg_mr(mr); + ret = ibv_cmd_dereg_mr(vmr); if (ret) return ret; - free(mr); + free(vmr); return 0; } diff --git a/providers/hns/hns_roce_u.h b/providers/hns/hns_roce_u.h index b07424d..8426569 100644 --- a/providers/hns/hns_roce_u.h +++ b/providers/hns/hns_roce_u.h @@ -270,9 +270,9 @@ int hns_roce_u_free_pd(struct ibv_pd *pd); struct ibv_mr *hns_roce_u_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access); -int hns_roce_u_rereg_mr(struct ibv_mr *mr, int flags, struct ibv_pd *pd, +int hns_roce_u_rereg_mr(struct verbs_mr *mr, int flags, struct ibv_pd *pd, void *addr, size_t length, int access); -int hns_roce_u_dereg_mr(struct ibv_mr *mr); +int hns_roce_u_dereg_mr(struct verbs_mr *mr); struct ibv_cq *hns_roce_u_create_cq(struct ibv_context *context, int cqe, struct ibv_comp_channel *channel, diff --git a/providers/hns/hns_roce_u_verbs.c b/providers/hns/hns_roce_u_verbs.c index d5eddf4..13b6d71 100644 --- a/providers/hns/hns_roce_u_verbs.c +++ b/providers/hns/hns_roce_u_verbs.c @@ -123,7 +123,7 @@ struct ibv_mr *hns_roce_u_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access) { int ret; - struct ibv_mr *mr; + struct verbs_mr *vmr; struct ibv_reg_mr cmd; struct ib_uverbs_reg_mr_resp resp; @@ -137,40 +137,40 @@ struct ibv_mr *hns_roce_u_reg_mr(struct ibv_pd *pd, void *addr, size_t length, return NULL; } - mr = malloc(sizeof(*mr)); - if (!mr) + vmr = malloc(sizeof(*vmr)); + if (!vmr) return NULL; - ret = ibv_cmd_reg_mr(pd, addr, length, (uintptr_t) addr, access, mr, + ret = ibv_cmd_reg_mr(pd, addr, length, (uintptr_t)addr, access, vmr, &cmd, sizeof(cmd), &resp, sizeof(resp)); if (ret) { - free(mr); + free(vmr); return NULL; } - return mr; + return &vmr->ibv_mr; } -int hns_roce_u_rereg_mr(struct ibv_mr *mr, int flags, struct ibv_pd *pd, +int hns_roce_u_rereg_mr(struct verbs_mr *vmr, int flags, struct ibv_pd *pd, void *addr, size_t length, int access) { struct ibv_rereg_mr cmd; struct ib_uverbs_rereg_mr_resp resp; - return ibv_cmd_rereg_mr(mr, flags, addr, length, (uintptr_t)addr, + return ibv_cmd_rereg_mr(vmr, flags, addr, length, (uintptr_t)addr, access, pd, &cmd, sizeof(cmd), &resp, sizeof(resp)); } -int hns_roce_u_dereg_mr(struct ibv_mr *mr) +int hns_roce_u_dereg_mr(struct verbs_mr *vmr) { int ret; - ret = ibv_cmd_dereg_mr(mr); + ret = ibv_cmd_dereg_mr(vmr); if (ret) return ret; - free(mr); + free(vmr); return ret; } diff --git a/providers/i40iw/i40iw_umain.h b/providers/i40iw/i40iw_umain.h index a2f4fa8..80c1727 100644 --- a/providers/i40iw/i40iw_umain.h +++ b/providers/i40iw/i40iw_umain.h @@ -96,7 +96,7 @@ struct i40iw_uqp; struct i40iw_ucq { struct ibv_cq ibv_cq; - struct ibv_mr mr; + struct verbs_mr vmr; struct ibv_mr mr_shadow_area; pthread_spinlock_t lock; uint8_t is_armed; @@ -112,7 +112,7 @@ struct i40iw_uqp { struct ibv_qp ibv_qp; struct i40iw_ucq *send_cq; struct i40iw_ucq *recv_cq; - struct ibv_mr mr; + struct verbs_mr vmr; uint32_t i40iw_drv_opt; pthread_spinlock_t lock; u32 *push_db; /* mapped as uncached memory*/ @@ -161,7 +161,7 @@ int i40iw_uquery_port(struct ibv_context *, uint8_t, struct ibv_port_attr *); struct ibv_pd *i40iw_ualloc_pd(struct ibv_context *); int i40iw_ufree_pd(struct ibv_pd *); struct ibv_mr *i40iw_ureg_mr(struct ibv_pd *, void *, size_t, int); -int i40iw_udereg_mr(struct ibv_mr *); +int i40iw_udereg_mr(struct verbs_mr *vmr); struct ibv_cq *i40iw_ucreate_cq(struct ibv_context *, int, struct ibv_comp_channel *, int); int i40iw_uresize_cq(struct ibv_cq *, int); int i40iw_udestroy_cq(struct ibv_cq *); diff --git a/providers/i40iw/i40iw_uverbs.c b/providers/i40iw/i40iw_uverbs.c index 9a363b9..a213d8f 100644 --- a/providers/i40iw/i40iw_uverbs.c +++ b/providers/i40iw/i40iw_uverbs.c @@ -151,39 +151,39 @@ int i40iw_ufree_pd(struct ibv_pd *pd) */ struct ibv_mr *i40iw_ureg_mr(struct ibv_pd *pd, void *addr, size_t length, int access) { - struct ibv_mr *mr; + struct verbs_mr *vmr; struct i40iw_ureg_mr cmd; struct ib_uverbs_reg_mr_resp resp; - mr = malloc(sizeof(*mr)); - if (!mr) + vmr = malloc(sizeof(*vmr)); + if (!vmr) return NULL; cmd.reg_type = IW_MEMREG_TYPE_MEM; if (ibv_cmd_reg_mr(pd, addr, length, (uintptr_t)addr, - access, mr, &cmd.ibv_cmd, sizeof(cmd), + access, vmr, &cmd.ibv_cmd, sizeof(cmd), &resp, sizeof(resp))) { fprintf(stderr, PFX "%s: Failed to register memory\n", __func__); - free(mr); + free(vmr); return NULL; } - return mr; + return &vmr->ibv_mr; } /** * i40iw_udereg_mr - re-register memory region * @mr: mr that was allocated */ -int i40iw_udereg_mr(struct ibv_mr *mr) +int i40iw_udereg_mr(struct verbs_mr *vmr) { int ret; - ret = ibv_cmd_dereg_mr(mr); + ret = ibv_cmd_dereg_mr(vmr); if (ret) return ret; - free(mr); + free(vmr); return 0; } @@ -258,10 +258,11 @@ struct ibv_cq *i40iw_ucreate_cq(struct ibv_context *context, int cqe, reg_mr_cmd.cq_pages = cq_pages; - ret = ibv_cmd_reg_mr(&iwvctx->iwupd->ibv_pd, (void *)info.cq_base, totalsize, - (uintptr_t)info.cq_base, IBV_ACCESS_LOCAL_WRITE, - &iwucq->mr, ®_mr_cmd.ibv_cmd, sizeof(reg_mr_cmd), ®_mr_resp, - sizeof(reg_mr_resp)); + ret = ibv_cmd_reg_mr(&iwvctx->iwupd->ibv_pd, (void *)info.cq_base, + totalsize, (uintptr_t)info.cq_base, + IBV_ACCESS_LOCAL_WRITE, &iwucq->vmr, + ®_mr_cmd.ibv_cmd, sizeof(reg_mr_cmd), + ®_mr_resp, sizeof(reg_mr_resp)); if (ret) { fprintf(stderr, PFX "%s: failed to pin memory for CQ\n", __func__); goto err; @@ -272,7 +273,7 @@ struct ibv_cq *i40iw_ucreate_cq(struct ibv_context *context, int cqe, &iwucq->ibv_cq, &cmd.ibv_cmd, sizeof(cmd), &resp.ibv_resp, sizeof(resp)); if (ret) { - ibv_cmd_dereg_mr(&iwucq->mr); + ibv_cmd_dereg_mr(&iwucq->vmr); fprintf(stderr, PFX "%s: failed to create CQ\n", __func__); goto err; } @@ -312,7 +313,7 @@ int i40iw_udestroy_cq(struct ibv_cq *cq) if (ret) return ret; - ibv_cmd_dereg_mr(&iwucq->mr); + ibv_cmd_dereg_mr(&iwucq->vmr); free(iwucq->cq.cq_base); free(iwucq); @@ -478,7 +479,7 @@ static int i40iw_destroy_vmapped_qp(struct i40iw_uqp *iwuqp, if (iwuqp->push_wqe) munmap(iwuqp->push_wqe, I40IW_HW_PAGE_SIZE); - ibv_cmd_dereg_mr(&iwuqp->mr); + ibv_cmd_dereg_mr(&iwuqp->vmr); free((void *)sq_base); return 0; @@ -530,9 +531,11 @@ static int i40iw_vmapped_qp(struct i40iw_uqp *iwuqp, struct ibv_pd *pd, reg_mr_cmd.sq_pages = sq_pages; reg_mr_cmd.rq_pages = rq_pages; - ret = ibv_cmd_reg_mr(pd, (void *)info->sq, totalqpsize, (uintptr_t)info->sq, - IBV_ACCESS_LOCAL_WRITE, &iwuqp->mr, ®_mr_cmd.ibv_cmd, - sizeof(reg_mr_cmd), ®_mr_resp, sizeof(reg_mr_resp)); + ret = ibv_cmd_reg_mr(pd, (void *)info->sq, totalqpsize, + (uintptr_t)info->sq, IBV_ACCESS_LOCAL_WRITE, + &iwuqp->vmr, ®_mr_cmd.ibv_cmd, + sizeof(reg_mr_cmd), ®_mr_resp, + sizeof(reg_mr_resp)); if (ret) { fprintf(stderr, PFX "%s: failed to pin memory for SQ\n", __func__); free(info->sq); @@ -545,7 +548,7 @@ static int i40iw_vmapped_qp(struct i40iw_uqp *iwuqp, struct ibv_pd *pd, &resp->ibv_resp, sizeof(struct i40iw_ucreate_qp_resp)); if (ret) { fprintf(stderr, PFX "%s: failed to create QP, status %d\n", __func__, ret); - ibv_cmd_dereg_mr(&iwuqp->mr); + ibv_cmd_dereg_mr(&iwuqp->vmr); free(info->sq); return 0; } diff --git a/providers/ipathverbs/ipathverbs.h b/providers/ipathverbs/ipathverbs.h index d26a2a1..cfb5cc3 100644 --- a/providers/ipathverbs/ipathverbs.h +++ b/providers/ipathverbs/ipathverbs.h @@ -186,7 +186,7 @@ int ipath_free_pd(struct ibv_pd *pd); struct ibv_mr *ipath_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access); -int ipath_dereg_mr(struct ibv_mr *mr); +int ipath_dereg_mr(struct verbs_mr *vmr); struct ibv_cq *ipath_create_cq(struct ibv_context *context, int cqe, struct ibv_comp_channel *channel, diff --git a/providers/ipathverbs/verbs.c b/providers/ipathverbs/verbs.c index 5ae76fb..de4722b 100644 --- a/providers/ipathverbs/verbs.c +++ b/providers/ipathverbs/verbs.c @@ -112,34 +112,34 @@ int ipath_free_pd(struct ibv_pd *pd) struct ibv_mr *ipath_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access) { - struct ibv_mr *mr; + struct verbs_mr *vmr; struct ibv_reg_mr cmd; struct ib_uverbs_reg_mr_resp resp; int ret; - mr = malloc(sizeof *mr); - if (!mr) + vmr = malloc(sizeof(*vmr)); + if (!vmr) return NULL; - ret = ibv_cmd_reg_mr(pd, addr, length, (uintptr_t)addr, access, mr, + ret = ibv_cmd_reg_mr(pd, addr, length, (uintptr_t)addr, access, vmr, &cmd, sizeof cmd, &resp, sizeof resp); if (ret) { - free(mr); + free(vmr); return NULL; } - return mr; + return &vmr->ibv_mr; } -int ipath_dereg_mr(struct ibv_mr *mr) +int ipath_dereg_mr(struct verbs_mr *vmr) { int ret; - ret = ibv_cmd_dereg_mr(mr); + ret = ibv_cmd_dereg_mr(vmr); if (ret) return ret; - free(mr); + free(vmr); return 0; } diff --git a/providers/mlx4/mlx4.h b/providers/mlx4/mlx4.h index c97785d..1627131 100644 --- a/providers/mlx4/mlx4.h +++ b/providers/mlx4/mlx4.h @@ -329,9 +329,9 @@ int mlx4_close_xrcd(struct ibv_xrcd *xrcd); struct ibv_mr *mlx4_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access); -int mlx4_rereg_mr(struct ibv_mr *mr, int flags, struct ibv_pd *pd, +int mlx4_rereg_mr(struct verbs_mr *vmr, int flags, struct ibv_pd *pd, void *addr, size_t length, int access); -int mlx4_dereg_mr(struct ibv_mr *mr); +int mlx4_dereg_mr(struct verbs_mr *vmr); struct ibv_mw *mlx4_alloc_mw(struct ibv_pd *pd, enum ibv_mw_type type); int mlx4_dealloc_mw(struct ibv_mw *mw); diff --git a/providers/mlx4/verbs.c b/providers/mlx4/verbs.c index 4b5c06f..c2ba512 100644 --- a/providers/mlx4/verbs.c +++ b/providers/mlx4/verbs.c @@ -273,27 +273,27 @@ int mlx4_close_xrcd(struct ibv_xrcd *ib_xrcd) struct ibv_mr *mlx4_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access) { - struct ibv_mr *mr; + struct verbs_mr *vmr; struct ibv_reg_mr cmd; struct ib_uverbs_reg_mr_resp resp; int ret; - mr = malloc(sizeof *mr); - if (!mr) + vmr = malloc(sizeof(*vmr)); + if (!vmr) return NULL; ret = ibv_cmd_reg_mr(pd, addr, length, (uintptr_t) addr, - access, mr, &cmd, sizeof cmd, - &resp, sizeof resp); + access, vmr, &cmd, sizeof(cmd), + &resp, sizeof(resp)); if (ret) { - free(mr); + free(vmr); return NULL; } - return mr; + return &vmr->ibv_mr; } -int mlx4_rereg_mr(struct ibv_mr *mr, +int mlx4_rereg_mr(struct verbs_mr *vmr, int flags, struct ibv_pd *pd, void *addr, size_t length, int access) @@ -304,22 +304,22 @@ int mlx4_rereg_mr(struct ibv_mr *mr, if (flags & IBV_REREG_MR_KEEP_VALID) return ENOTSUP; - return ibv_cmd_rereg_mr(mr, flags, addr, length, + return ibv_cmd_rereg_mr(vmr, flags, addr, length, (uintptr_t)addr, access, pd, &cmd, sizeof(cmd), &resp, sizeof(resp)); } -int mlx4_dereg_mr(struct ibv_mr *mr) +int mlx4_dereg_mr(struct verbs_mr *vmr) { int ret; - ret = ibv_cmd_dereg_mr(mr); + ret = ibv_cmd_dereg_mr(vmr); if (ret && !cleanup_on_fatal(ret)) return ret; - free(mr); + free(vmr); return 0; } diff --git a/providers/mlx5/mlx5.h b/providers/mlx5/mlx5.h index e26e291..737a09e 100644 --- a/providers/mlx5/mlx5.h +++ b/providers/mlx5/mlx5.h @@ -479,7 +479,7 @@ struct mlx5_dm { }; struct mlx5_mr { - struct ibv_mr ibv_mr; + struct verbs_mr vmr; struct mlx5_buf buf; uint32_t alloc_flags; }; @@ -657,7 +657,7 @@ static inline struct mlx5_dm *to_mdm(struct ibv_dm *ibdm) static inline struct mlx5_mr *to_mmr(struct ibv_mr *ibmr) { - return to_mxxx(mr, mr); + return container_of(ibmr, struct mlx5_mr, vmr.ibv_mr); } static inline struct mlx5_ah *to_mah(struct ibv_ah *ibah) @@ -737,9 +737,9 @@ int mlx5_free_pd(struct ibv_pd *pd); struct ibv_mr *mlx5_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access); -int mlx5_rereg_mr(struct ibv_mr *mr, int flags, struct ibv_pd *pd, void *addr, +int mlx5_rereg_mr(struct verbs_mr *mr, int flags, struct ibv_pd *pd, void *addr, size_t length, int access); -int mlx5_dereg_mr(struct ibv_mr *mr); +int mlx5_dereg_mr(struct verbs_mr *mr); struct ibv_mw *mlx5_alloc_mw(struct ibv_pd *pd, enum ibv_mw_type); int mlx5_dealloc_mw(struct ibv_mw *mw); int mlx5_bind_mw(struct ibv_qp *qp, struct ibv_mw *mw, diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c index 10f89ee..2949c2e 100644 --- a/providers/mlx5/verbs.c +++ b/providers/mlx5/verbs.c @@ -384,7 +384,7 @@ struct ibv_mr *mlx5_reg_mr(struct ibv_pd *pd, void *addr, size_t length, return NULL; ret = ibv_cmd_reg_mr(pd, addr, length, (uintptr_t)addr, access, - &(mr->ibv_mr), &cmd, sizeof(cmd), &resp, + &mr->vmr, &cmd, sizeof(cmd), &resp, sizeof resp); if (ret) { mlx5_free_buf(&(mr->buf)); @@ -393,7 +393,7 @@ struct ibv_mr *mlx5_reg_mr(struct ibv_pd *pd, void *addr, size_t length, } mr->alloc_flags = acc; - return &mr->ibv_mr; + return &mr->vmr.ibv_mr; } enum { @@ -424,7 +424,7 @@ struct ibv_mr *mlx5_reg_dm_mr(struct ibv_pd *pd, struct ibv_dm *ibdm, } ret = ibv_cmd_reg_dm_mr(pd, &dm->verbs_dm, dm_offset, length, acc, - &mr->ibv_mr, NULL); + &mr->vmr, NULL); if (ret) { free(mr); return NULL; @@ -432,11 +432,11 @@ struct ibv_mr *mlx5_reg_dm_mr(struct ibv_pd *pd, struct ibv_dm *ibdm, mr->alloc_flags = acc; - return &mr->ibv_mr; + return &mr->vmr.ibv_mr; } -int mlx5_rereg_mr(struct ibv_mr *ibmr, int flags, struct ibv_pd *pd, void *addr, - size_t length, int access) +int mlx5_rereg_mr(struct verbs_mr *vmr, int flags, struct ibv_pd *pd, + void *addr, size_t length, int access) { struct ibv_rereg_mr cmd; struct ib_uverbs_rereg_mr_resp resp; @@ -444,21 +444,20 @@ int mlx5_rereg_mr(struct ibv_mr *ibmr, int flags, struct ibv_pd *pd, void *addr, if (flags & IBV_REREG_MR_KEEP_VALID) return ENOTSUP; - return ibv_cmd_rereg_mr(ibmr, flags, addr, length, (uintptr_t)addr, + return ibv_cmd_rereg_mr(vmr, flags, addr, length, (uintptr_t)addr, access, pd, &cmd, sizeof(cmd), &resp, sizeof(resp)); } -int mlx5_dereg_mr(struct ibv_mr *ibmr) +int mlx5_dereg_mr(struct verbs_mr *vmr) { int ret; - struct mlx5_mr *mr = to_mmr(ibmr); - ret = ibv_cmd_dereg_mr(ibmr); + ret = ibv_cmd_dereg_mr(vmr); if (ret) return ret; - free(mr); + free(vmr); return 0; } diff --git a/providers/mthca/ah.c b/providers/mthca/ah.c index 625e3b8..df0cb28 100644 --- a/providers/mthca/ah.c +++ b/providers/mthca/ah.c @@ -179,7 +179,7 @@ void mthca_free_av(struct mthca_ah *ah) if (page->next) page->next->prev = page->prev; - mthca_dereg_mr(page->mr); + mthca_dereg_mr(verbs_get_mr(page->mr)); mthca_free_buf(&page->buf); free(page); } diff --git a/providers/mthca/mthca.h b/providers/mthca/mthca.h index d788f76..61042de 100644 --- a/providers/mthca/mthca.h +++ b/providers/mthca/mthca.h @@ -282,7 +282,7 @@ int mthca_free_pd(struct ibv_pd *pd); struct ibv_mr *mthca_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access); -int mthca_dereg_mr(struct ibv_mr *mr); +int mthca_dereg_mr(struct verbs_mr *mr); struct ibv_cq *mthca_create_cq(struct ibv_context *context, int cqe, struct ibv_comp_channel *channel, diff --git a/providers/mthca/verbs.c b/providers/mthca/verbs.c index ebe804a..e7a1c35 100644 --- a/providers/mthca/verbs.c +++ b/providers/mthca/verbs.c @@ -117,7 +117,7 @@ static struct ibv_mr *__mthca_reg_mr(struct ibv_pd *pd, void *addr, int access, int dma_sync) { - struct ibv_mr *mr; + struct verbs_mr *vmr; struct umthca_reg_mr cmd; struct ib_uverbs_reg_mr_resp resp; int ret; @@ -131,18 +131,18 @@ static struct ibv_mr *__mthca_reg_mr(struct ibv_pd *pd, void *addr, cmd.mr_attrs = dma_sync ? MTHCA_MR_DMASYNC : 0; cmd.reserved = 0; - mr = malloc(sizeof *mr); - if (!mr) + vmr = malloc(sizeof(*vmr)); + if (!vmr) return NULL; - ret = ibv_cmd_reg_mr(pd, addr, length, hca_va, access, mr, &cmd.ibv_cmd, - sizeof cmd, &resp, sizeof resp); + ret = ibv_cmd_reg_mr(pd, addr, length, hca_va, access, vmr, + &cmd.ibv_cmd, sizeof(cmd), &resp, sizeof(resp)); if (ret) { - free(mr); + free(vmr); return NULL; } - return mr; + return &vmr->ibv_mr; } struct ibv_mr *mthca_reg_mr(struct ibv_pd *pd, void *addr, @@ -151,15 +151,15 @@ struct ibv_mr *mthca_reg_mr(struct ibv_pd *pd, void *addr, return __mthca_reg_mr(pd, addr, length, (uintptr_t) addr, access, 0); } -int mthca_dereg_mr(struct ibv_mr *mr) +int mthca_dereg_mr(struct verbs_mr *vmr) { int ret; - ret = ibv_cmd_dereg_mr(mr); + ret = ibv_cmd_dereg_mr(vmr); if (ret) return ret; - free(mr); + free(vmr); return 0; } @@ -258,7 +258,7 @@ err_set_db: cq->set_ci_db_index); err_unreg: - mthca_dereg_mr(cq->mr); + mthca_dereg_mr(verbs_get_mr(cq->mr)); err_buf: mthca_free_buf(&cq->buf); @@ -312,14 +312,14 @@ int mthca_resize_cq(struct ibv_cq *ibcq, int cqe) ret = ibv_cmd_resize_cq(ibcq, cqe - 1, &cmd.ibv_cmd, sizeof cmd, &resp, sizeof resp); if (ret) { - mthca_dereg_mr(mr); + mthca_dereg_mr(verbs_get_mr(mr)); mthca_free_buf(&buf); goto out; } mthca_cq_resize_copy_cqes(cq, buf.buf, old_cqe); - mthca_dereg_mr(cq->mr); + mthca_dereg_mr(verbs_get_mr(cq->mr)); mthca_free_buf(&cq->buf); cq->buf = buf; @@ -345,7 +345,7 @@ int mthca_destroy_cq(struct ibv_cq *cq) to_mcq(cq)->arm_db_index); } - mthca_dereg_mr(to_mcq(cq)->mr); + mthca_dereg_mr(verbs_get_mr(to_mcq(cq)->mr)); mthca_free_buf(&to_mcq(cq)->buf); free(to_mcq(cq)); @@ -437,7 +437,7 @@ err_db: srq->db_index); err_unreg: - mthca_dereg_mr(srq->mr); + mthca_dereg_mr(verbs_get_mr(srq->mr)); err_free: free(srq->wrid); @@ -478,7 +478,7 @@ int mthca_destroy_srq(struct ibv_srq *srq) mthca_free_db(to_mctx(srq->context)->db_tab, MTHCA_DB_TYPE_SRQ, to_msrq(srq)->db_index); - mthca_dereg_mr(to_msrq(srq)->mr); + mthca_dereg_mr(verbs_get_mr(to_msrq(srq)->mr)); mthca_free_buf(&to_msrq(srq)->buf); free(to_msrq(srq)->wrid); @@ -588,7 +588,7 @@ err_sq_db: qp->sq.db_index); err_unreg: - mthca_dereg_mr(qp->mr); + mthca_dereg_mr(verbs_get_mr(qp->mr)); err_free: free(qp->wrid); @@ -698,7 +698,7 @@ int mthca_destroy_qp(struct ibv_qp *qp) to_mqp(qp)->sq.db_index); } - mthca_dereg_mr(to_mqp(qp)->mr); + mthca_dereg_mr(verbs_get_mr(to_mqp(qp)->mr)); mthca_free_buf(&to_mqp(qp)->buf); free(to_mqp(qp)->wrid); free(to_mqp(qp)); diff --git a/providers/nes/nes_umain.h b/providers/nes/nes_umain.h index 2750c12..b377508 100644 --- a/providers/nes/nes_umain.h +++ b/providers/nes/nes_umain.h @@ -276,7 +276,7 @@ struct nes_uqp; struct nes_ucq { struct ibv_cq ibv_cq; struct nes_hw_cqe volatile *cqes; - struct ibv_mr mr; + struct verbs_mr vmr; pthread_spinlock_t lock; uint32_t cq_id; uint16_t size; @@ -297,7 +297,7 @@ struct nes_uqp { uint32_t qp_id; struct nes_ucq *send_cq; struct nes_ucq *recv_cq; - struct ibv_mr mr; + struct verbs_mr vmr; uint32_t nes_drv_opt; pthread_spinlock_t lock; uint16_t sq_db_index; @@ -356,7 +356,7 @@ int nes_uquery_port(struct ibv_context *, uint8_t, struct ibv_port_attr *); struct ibv_pd *nes_ualloc_pd(struct ibv_context *); int nes_ufree_pd(struct ibv_pd *); struct ibv_mr *nes_ureg_mr(struct ibv_pd *, void *, size_t, int); -int nes_udereg_mr(struct ibv_mr *); +int nes_udereg_mr(struct verbs_mr *vmr); struct ibv_cq *nes_ucreate_cq(struct ibv_context *, int, struct ibv_comp_channel *, int); int nes_uresize_cq(struct ibv_cq *, int); int nes_udestroy_cq(struct ibv_cq *); diff --git a/providers/nes/nes_uverbs.c b/providers/nes/nes_uverbs.c index 5f13c1b..fd14849 100644 --- a/providers/nes/nes_uverbs.c +++ b/providers/nes/nes_uverbs.c @@ -168,39 +168,39 @@ int nes_ufree_pd(struct ibv_pd *pd) struct ibv_mr *nes_ureg_mr(struct ibv_pd *pd, void *addr, size_t length, int access) { - struct ibv_mr *mr; + struct verbs_mr *vmr; struct nes_ureg_mr cmd; struct ib_uverbs_reg_mr_resp resp; - mr = malloc(sizeof *mr); - if (!mr) + vmr = malloc(sizeof(*vmr)); + if (!vmr) return NULL; cmd.reg_type = IWNES_MEMREG_TYPE_MEM; if (ibv_cmd_reg_mr(pd, addr, length, (uintptr_t) addr, - access, mr, &cmd.ibv_cmd, sizeof cmd, - &resp, sizeof resp)) { - free(mr); + access, vmr, &cmd.ibv_cmd, sizeof(cmd), + &resp, sizeof(resp))) { + free(vmr); return NULL; } - return mr; + return &vmr->ibv_mr; } /** * nes_udereg_mr */ -int nes_udereg_mr(struct ibv_mr *mr) +int nes_udereg_mr(struct verbs_mr *vmr) { int ret; - ret = ibv_cmd_dereg_mr(mr); + ret = ibv_cmd_dereg_mr(vmr); if (ret) return ret; - free(mr); + free(vmr); return 0; } @@ -243,9 +243,9 @@ struct ibv_cq *nes_ucreate_cq(struct ibv_context *context, int cqe, ret = ibv_cmd_reg_mr(&nesvctx->nesupd->ibv_pd, (void *)nesucq->cqes, (nesucq->size*sizeof(struct nes_hw_cqe)), - (uintptr_t)nesucq->cqes, IBV_ACCESS_LOCAL_WRITE, &nesucq->mr, - ®_mr_cmd.ibv_cmd, sizeof reg_mr_cmd, - ®_mr_resp, sizeof reg_mr_resp); + (uintptr_t)nesucq->cqes, IBV_ACCESS_LOCAL_WRITE, + &nesucq->vmr, ®_mr_cmd.ibv_cmd, sizeof(reg_mr_cmd), + ®_mr_resp, sizeof(reg_mr_resp)); if (ret) { /* fprintf(stderr, "ibv_cmd_reg_mr failed (ret = %d).\n", ret); */ free((struct nes_hw_cqe *)nesucq->cqes); @@ -300,7 +300,7 @@ int nes_udestroy_cq(struct ibv_cq *cq) if (ret) return ret; - ret = ibv_cmd_dereg_mr(&nesucq->mr); + ret = ibv_cmd_dereg_mr(&nesucq->vmr); if (ret) fprintf(stderr, PFX "%s: Failed to deregister CQ Memory Region.\n", __FUNCTION__); @@ -957,9 +957,10 @@ static int nes_vmapped_qp(struct nes_uqp *nesuqp, struct ibv_pd *pd, struct ibv_ // nesuqp->rq_vbase, nesuqp->sq_vbase, &nesuqp->mr); ret = ibv_cmd_reg_mr(pd, (void *)nesuqp->sq_vbase,totalqpsize, - (uintptr_t) nesuqp->sq_vbase, IBV_ACCESS_LOCAL_WRITE, - &nesuqp->mr, ®_mr_cmd.ibv_cmd, sizeof reg_mr_cmd, - ®_mr_resp, sizeof reg_mr_resp); + (uintptr_t)nesuqp->sq_vbase, + IBV_ACCESS_LOCAL_WRITE, &nesuqp->vmr, + ®_mr_cmd.ibv_cmd, sizeof(reg_mr_cmd), + ®_mr_resp, sizeof(reg_mr_resp)); if (ret) { // fprintf(stderr, PFX "%s ibv_cmd_reg_mr failed (ret = %d).\n", __FUNCTION__, ret); free((void *) nesuqp->sq_vbase); @@ -972,7 +973,7 @@ static int nes_vmapped_qp(struct nes_uqp *nesuqp, struct ibv_pd *pd, struct ibv_ ret = ibv_cmd_create_qp(pd, &nesuqp->ibv_qp, attr, &cmd.ibv_cmd, sizeof cmd, &resp->ibv_resp, sizeof (struct nes_ucreate_qp_resp) ); if (ret) { - ibv_cmd_dereg_mr(&nesuqp->mr); + ibv_cmd_dereg_mr(&nesuqp->vmr); free((void *)nesuqp->sq_vbase); return 0; } @@ -1155,7 +1156,7 @@ int nes_udestroy_qp(struct ibv_qp *qp) // fprintf(stderr, PFX "%s addr&mr= %p \n", __FUNCTION__, &nesuqp->mr ); if (nesuqp->mapping == NES_QP_VMAP) { - ret = ibv_cmd_dereg_mr(&nesuqp->mr); + ret = ibv_cmd_dereg_mr(&nesuqp->vmr); if (ret) fprintf(stderr, PFX "%s dereg_mr FAILED\n", __FUNCTION__); free((void *)nesuqp->sq_vbase); diff --git a/providers/ocrdma/ocrdma_main.h b/providers/ocrdma/ocrdma_main.h index e414223..33def78 100644 --- a/providers/ocrdma/ocrdma_main.h +++ b/providers/ocrdma/ocrdma_main.h @@ -82,7 +82,7 @@ struct ocrdma_pd { }; struct ocrdma_mr { - struct ibv_mr ibv_mr; + struct verbs_mr vmr; }; struct ocrdma_cq { @@ -271,7 +271,7 @@ struct ibv_pd *ocrdma_alloc_pd(struct ibv_context *); int ocrdma_free_pd(struct ibv_pd *); struct ibv_mr *ocrdma_reg_mr(struct ibv_pd *, void *, size_t, int ibv_access_flags); -int ocrdma_dereg_mr(struct ibv_mr *); +int ocrdma_dereg_mr(struct verbs_mr *vmr); struct ibv_cq *ocrdma_create_cq(struct ibv_context *, int, struct ibv_comp_channel *, int); diff --git a/providers/ocrdma/ocrdma_verbs.c b/providers/ocrdma/ocrdma_verbs.c index b9fa7d6..8ce5c0c 100644 --- a/providers/ocrdma/ocrdma_verbs.c +++ b/providers/ocrdma/ocrdma_verbs.c @@ -200,24 +200,24 @@ struct ibv_mr *ocrdma_reg_mr(struct ibv_pd *pd, void *addr, bzero(mr, sizeof *mr); if (ibv_cmd_reg_mr(pd, addr, len, hca_va, - access, &mr->ibv_mr, &cmd, sizeof cmd, - &resp.ibv_resp, sizeof resp)) { + access, &mr->vmr, &cmd, sizeof(cmd), + &resp.ibv_resp, sizeof(resp))) { free(mr); return NULL; } - return &mr->ibv_mr; + return &mr->vmr.ibv_mr; } /* * ocrdma_dereg_mr */ -int ocrdma_dereg_mr(struct ibv_mr *mr) +int ocrdma_dereg_mr(struct verbs_mr *vmr) { int status; - status = ibv_cmd_dereg_mr(mr); + status = ibv_cmd_dereg_mr(vmr); if (status) return status; - free(mr); + free(vmr); return 0; } diff --git a/providers/qedr/qelr.h b/providers/qedr/qelr.h index faa8e99..0b2e4a2 100644 --- a/providers/qedr/qelr.h +++ b/providers/qedr/qelr.h @@ -139,7 +139,7 @@ struct qelr_pd { }; struct qelr_mr { - struct ibv_mr ibv_mr; + struct verbs_mr vmr; }; union db_prod64 { diff --git a/providers/qedr/qelr_main.h b/providers/qedr/qelr_main.h index f0b16d9..ef05acb 100644 --- a/providers/qedr/qelr_main.h +++ b/providers/qedr/qelr_main.h @@ -48,7 +48,7 @@ int qelr_dealloc_pd(struct ibv_pd *); struct ibv_mr *qelr_reg_mr(struct ibv_pd *, void *, size_t, int ibv_access_flags); -int qelr_dereg_mr(struct ibv_mr *); +int qelr_dereg_mr(struct verbs_mr *vmr); struct ibv_cq *qelr_create_cq(struct ibv_context *, int, struct ibv_comp_channel *, int); diff --git a/providers/qedr/qelr_verbs.c b/providers/qedr/qelr_verbs.c index 2ee1c83..28ea094 100644 --- a/providers/qedr/qelr_verbs.c +++ b/providers/qedr/qelr_verbs.c @@ -175,7 +175,7 @@ struct ibv_mr *qelr_reg_mr(struct ibv_pd *ibpd, void *addr, bzero(mr, sizeof(*mr)); if (ibv_cmd_reg_mr(ibpd, addr, len, hca_va, - access, &mr->ibv_mr, &cmd, sizeof(cmd), + access, &mr->vmr, &cmd, sizeof(cmd), &resp.ibv_resp, sizeof(resp))) { free(mr); return NULL; @@ -183,25 +183,25 @@ struct ibv_mr *qelr_reg_mr(struct ibv_pd *ibpd, void *addr, DP_VERBOSE(cxt->dbg_fp, QELR_MSG_MR, "MR Register %p completed successfully pd_id=%d addr=%p len=%zu access=%d lkey=%x rkey=%x\n", - mr, pd->pd_id, addr, len, access, mr->ibv_mr.lkey, - mr->ibv_mr.rkey); + mr, pd->pd_id, addr, len, access, mr->vmr.ibv_mr.lkey, + mr->vmr.ibv_mr.rkey); - return &mr->ibv_mr; + return &mr->vmr.ibv_mr; } -int qelr_dereg_mr(struct ibv_mr *mr) +int qelr_dereg_mr(struct verbs_mr *vmr) { - struct qelr_devctx *cxt = get_qelr_ctx(mr->context); + struct qelr_devctx *cxt = get_qelr_ctx(vmr->ibv_mr.context); int rc; - rc = ibv_cmd_dereg_mr(mr); + rc = ibv_cmd_dereg_mr(vmr); if (rc) return rc; - free(mr); + free(vmr); DP_VERBOSE(cxt->dbg_fp, QELR_MSG_MR, - "MR DERegister %p completed successfully\n", mr); + "MR DERegister %p completed successfully\n", vmr); return 0; } diff --git a/providers/qedr/qelr_verbs.h b/providers/qedr/qelr_verbs.h index 28ad18c..50d1182 100644 --- a/providers/qedr/qelr_verbs.h +++ b/providers/qedr/qelr_verbs.h @@ -50,7 +50,7 @@ int qelr_dealloc_pd(struct ibv_pd *ibpd); struct ibv_mr *qelr_reg_mr(struct ibv_pd *ibpd, void *addr, size_t len, int access); -int qelr_dereg_mr(struct ibv_mr *mr); +int qelr_dereg_mr(struct verbs_mr *mr); struct ibv_cq *qelr_create_cq(struct ibv_context *context, int cqe, struct ibv_comp_channel *channel, diff --git a/providers/rxe/rxe.c b/providers/rxe/rxe.c index b10868d..b9b6c6f 100644 --- a/providers/rxe/rxe.c +++ b/providers/rxe/rxe.c @@ -125,35 +125,34 @@ static int rxe_dealloc_pd(struct ibv_pd *pd) static struct ibv_mr *rxe_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access) { - struct ibv_mr *mr; + struct verbs_mr *vmr; struct ibv_reg_mr cmd; struct ib_uverbs_reg_mr_resp resp; int ret; - mr = malloc(sizeof *mr); - if (!mr) { + vmr = malloc(sizeof(*vmr)); + if (!vmr) return NULL; - } - ret = ibv_cmd_reg_mr(pd, addr, length, (uintptr_t)addr, access, mr, + ret = ibv_cmd_reg_mr(pd, addr, length, (uintptr_t)addr, access, vmr, &cmd, sizeof cmd, &resp, sizeof resp); if (ret) { - free(mr); + free(vmr); return NULL; } - return mr; + return &vmr->ibv_mr; } -static int rxe_dereg_mr(struct ibv_mr *mr) +static int rxe_dereg_mr(struct verbs_mr *vmr) { int ret; - ret = ibv_cmd_dereg_mr(mr); + ret = ibv_cmd_dereg_mr(vmr); if (ret) return ret; - free(mr); + free(vmr); return 0; } diff --git a/providers/vmw_pvrdma/pvrdma.h b/providers/vmw_pvrdma/pvrdma.h index 23c1e91..ebd50ce 100644 --- a/providers/vmw_pvrdma/pvrdma.h +++ b/providers/vmw_pvrdma/pvrdma.h @@ -283,7 +283,7 @@ int pvrdma_free_pd(struct ibv_pd *pd); struct ibv_mr *pvrdma_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access); -int pvrdma_dereg_mr(struct ibv_mr *mr); +int pvrdma_dereg_mr(struct verbs_mr *mr); struct ibv_cq *pvrdma_create_cq(struct ibv_context *context, int cqe, struct ibv_comp_channel *channel, diff --git a/providers/vmw_pvrdma/verbs.c b/providers/vmw_pvrdma/verbs.c index 86d5580..b981939 100644 --- a/providers/vmw_pvrdma/verbs.c +++ b/providers/vmw_pvrdma/verbs.c @@ -114,35 +114,35 @@ int pvrdma_free_pd(struct ibv_pd *pd) struct ibv_mr *pvrdma_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access) { - struct ibv_mr *mr; + struct verbs_mr *vmr; struct ibv_reg_mr cmd; struct ib_uverbs_reg_mr_resp resp; int ret; - mr = malloc(sizeof(*mr)); - if (!mr) + vmr = malloc(sizeof(*vmr)); + if (!vmr) return NULL; ret = ibv_cmd_reg_mr(pd, addr, length, (uintptr_t) addr, - access, mr, &cmd, sizeof(cmd), + access, vmr, &cmd, sizeof(cmd), &resp, sizeof(resp)); if (ret) { - free(mr); + free(vmr); return NULL; } - return mr; + return &vmr->ibv_mr; } -int pvrdma_dereg_mr(struct ibv_mr *mr) +int pvrdma_dereg_mr(struct verbs_mr *vmr) { int ret; - ret = ibv_cmd_dereg_mr(mr); + ret = ibv_cmd_dereg_mr(vmr); if (ret) return ret; - free(mr); + free(vmr); return 0; }