From patchwork Thu Nov 10 12:46:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lijun Ou X-Patchwork-Id: 9420997 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 63C9560484 for ; Thu, 10 Nov 2016 12:29:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52F8429246 for ; Thu, 10 Nov 2016 12:29:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 47BB7292AC; Thu, 10 Nov 2016 12:29: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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 9FB1529246 for ; Thu, 10 Nov 2016 12:29:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755292AbcKJM3b (ORCPT ); Thu, 10 Nov 2016 07:29:31 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:31079 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755241AbcKJM3b (ORCPT ); Thu, 10 Nov 2016 07:29:31 -0500 Received: from 172.24.1.136 (EHLO szxeml427-hub.china.huawei.com) ([172.24.1.136]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DQK67380; Thu, 10 Nov 2016 20:29:14 +0800 (CST) Received: from linux-ioko.site (10.71.200.31) by szxeml427-hub.china.huawei.com (10.82.67.182) with Microsoft SMTP Server id 14.3.235.1; Thu, 10 Nov 2016 20:29:07 +0800 From: Lijun Ou To: , CC: Subject: [PATCH v3 rdma-core 3/7] libhns: Add verbs of pd and mr support Date: Thu, 10 Nov 2016 20:46:13 +0800 Message-ID: <1478781977-116803-4-git-send-email-oulijun@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1478781977-116803-1-git-send-email-oulijun@huawei.com> References: <1478781977-116803-1-git-send-email-oulijun@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.71.200.31] X-CFilter-Loop: Reflected 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 This patch mainly introduces the verbs with pd and mr, included alloc_pd, dealloc_pd, reg_mr and dereg_mr. Signed-off-by: Lijun Ou Signed-off-by: Wei Hu --- v3: This fixes the comments given by Leon Romanovsky on PATCHv2 v2: - No change over v1 v1: - The initial submit --- providers/hns/hns_roce_u.c | 4 ++ providers/hns/hns_roce_u.h | 18 +++++++++ providers/hns/hns_roce_u_abi.h | 6 +++ providers/hns/hns_roce_u_verbs.c | 79 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+) diff --git a/providers/hns/hns_roce_u.c b/providers/hns/hns_roce_u.c index c0f6fe9..53e2720 100644 --- a/providers/hns/hns_roce_u.c +++ b/providers/hns/hns_roce_u.c @@ -97,6 +97,10 @@ static struct ibv_context *hns_roce_alloc_context(struct ibv_device *ibdev, context->ibv_ctx.ops.query_device = hns_roce_u_query_device; context->ibv_ctx.ops.query_port = hns_roce_u_query_port; + context->ibv_ctx.ops.alloc_pd = hns_roce_u_alloc_pd; + context->ibv_ctx.ops.dealloc_pd = hns_roce_u_free_pd; + context->ibv_ctx.ops.reg_mr = hns_roce_u_reg_mr; + context->ibv_ctx.ops.dereg_mr = hns_roce_u_dereg_mr; if (hns_roce_u_query_device(&context->ibv_ctx, &dev_attrs)) goto tptr_free; diff --git a/providers/hns/hns_roce_u.h b/providers/hns/hns_roce_u.h index aa58ee6..5b73794 100644 --- a/providers/hns/hns_roce_u.h +++ b/providers/hns/hns_roce_u.h @@ -73,6 +73,11 @@ struct hns_roce_context { int max_cqe; }; +struct hns_roce_pd { + struct ibv_pd ibv_pd; + unsigned int pdn; +}; + static inline struct hns_roce_device *to_hr_dev(struct ibv_device *ibv_dev) { return container_of(ibv_dev, struct hns_roce_device, ibv_dev); @@ -83,8 +88,21 @@ static inline struct hns_roce_context *to_hr_ctx(struct ibv_context *ibv_ctx) return container_of(ibv_ctx, struct hns_roce_context, ibv_ctx); } +static inline struct hns_roce_pd *to_hr_pd(struct ibv_pd *ibv_pd) +{ + return container_of(ibv_pd, struct hns_roce_pd, ibv_pd); +} + int hns_roce_u_query_device(struct ibv_context *context, struct ibv_device_attr *attr); int hns_roce_u_query_port(struct ibv_context *context, uint8_t port, struct ibv_port_attr *attr); + +struct ibv_pd *hns_roce_u_alloc_pd(struct ibv_context *context); +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_dereg_mr(struct ibv_mr *mr); + #endif /* _HNS_ROCE_U_H */ diff --git a/providers/hns/hns_roce_u_abi.h b/providers/hns/hns_roce_u_abi.h index 4bfc8fa..0a0cd0c 100644 --- a/providers/hns/hns_roce_u_abi.h +++ b/providers/hns/hns_roce_u_abi.h @@ -40,4 +40,10 @@ struct hns_roce_alloc_ucontext_resp { __u32 qp_tab_size; }; +struct hns_roce_alloc_pd_resp { + struct ibv_alloc_pd_resp ibv_resp; + __u32 pdn; + __u32 reserved; +}; + #endif /* _HNS_ROCE_U_ABI_H */ diff --git a/providers/hns/hns_roce_u_verbs.c b/providers/hns/hns_roce_u_verbs.c index be55fe8..476b6ba 100644 --- a/providers/hns/hns_roce_u_verbs.c +++ b/providers/hns/hns_roce_u_verbs.c @@ -71,3 +71,82 @@ int hns_roce_u_query_port(struct ibv_context *context, uint8_t port, return ibv_cmd_query_port(context, port, attr, &cmd, sizeof(cmd)); } + +struct ibv_pd *hns_roce_u_alloc_pd(struct ibv_context *context) +{ + struct ibv_alloc_pd cmd; + struct hns_roce_pd *pd; + struct hns_roce_alloc_pd_resp resp; + + pd = (struct hns_roce_pd *)malloc(sizeof(*pd)); + if (!pd) + return NULL; + + if (ibv_cmd_alloc_pd(context, &pd->ibv_pd, &cmd, sizeof(cmd), + &resp.ibv_resp, sizeof(resp))) { + free(pd); + return NULL; + } + + pd->pdn = resp.pdn; + + return &pd->ibv_pd; +} + +int hns_roce_u_free_pd(struct ibv_pd *pd) +{ + int ret; + + ret = ibv_cmd_dealloc_pd(pd); + if (ret) + return ret; + + free(to_hr_pd(pd)); + + return ret; +} + +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 ibv_reg_mr cmd; + struct ibv_reg_mr_resp resp; + + if (!addr) { + fprintf(stderr, "2nd parm addr is NULL!\n"); + return NULL; + } + + if (!length) { + fprintf(stderr, "3st parm length is 0!\n"); + return NULL; + } + + mr = malloc(sizeof(*mr)); + if (!mr) + return NULL; + + ret = ibv_cmd_reg_mr(pd, addr, length, (uintptr_t) addr, access, mr, + &cmd, sizeof(cmd), &resp, sizeof(resp)); + if (ret) { + free(mr); + return NULL; + } + + return mr; +} + +int hns_roce_u_dereg_mr(struct ibv_mr *mr) +{ + int ret; + + ret = ibv_cmd_dereg_mr(mr); + if (ret) + return ret; + + free(mr); + + return ret; +}