From patchwork Mon Jan 8 21:26:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10150593 X-Patchwork-Delegate: leon@leon.nu 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 C5F2160210 for ; Mon, 8 Jan 2018 21:26:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4B2A28449 for ; Mon, 8 Jan 2018 21:26:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A9333284B5; Mon, 8 Jan 2018 21:26:47 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 278AF28449 for ; Mon, 8 Jan 2018 21:26:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753980AbeAHV0p (ORCPT ); Mon, 8 Jan 2018 16:26:45 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:35201 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753338AbeAHV0o (ORCPT ); Mon, 8 Jan 2018 16:26:44 -0500 Received: by mail-wm0-f66.google.com with SMTP id a79so16783910wma.0 for ; Mon, 08 Jan 2018 13:26:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6XPNMbuFNBLzlxWMQdLZxe1Mss34kzs8pKwMRfdv8yA=; b=kMAF8dT8zrIXiPsMuceJamjNWWuyUAzJGZOz4LxTai1F+fEkTUfQ+C91MXixAptL79 MPebaRkFO0gBxp9HrwTPZ7Rc3ai00olL6DOgs0ctljeDkZhsuxUZ2yXOZmxdqMvZGWhp wfcQwJu9c5QLYGNhv6Bxn0ZOMvRdZxhQyfnpSbNTs6xrEdn/g2N9ySALcV+er+RfJ7jK /jP7poY95JqBs7UwtXP1wAAVtUfbVmZtVEpR9YAL3wyipoms6/TrBgp40gYvoanPMSRn NmGGVjpKJpdz5jwodSqLLh99yi3gSAli2YhNJrvK+r0e11cATap6GAoZ89k/2tyU6Qht rthA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6XPNMbuFNBLzlxWMQdLZxe1Mss34kzs8pKwMRfdv8yA=; b=sBiAjXoFrheEQ9FXFUNyhSqPeDYN7A9hUCoG2uyjNO7z3YQQBNACsuPf8MMnXDg931 4AeMAw6bXLbXrAeeT/uSzoM+zMbErtl/eCEO/ctyAi48XqUjhFgC9uiJBORGgbjSVaGt suL5SLMfBFYLhUbzuUnJq0GVcLuy2ha+3TTaWdi4dKR/iOIDEtun7K7f4CvGysI67RA1 Gnwxff9wwlSPwZ0eLT7/3VGufP4S/ysIOil773OzJLl96uEBHJfXJJJQu1i7Engh1wl9 gJ4HSu3aepMkXzZq9lkHHwYuSoarIgglVHPuHuHXR/PqzF9OWxia1pYjzR/MWKlu/RR9 pYag== X-Gm-Message-State: AKGB3mKEtvD//7SEOQTquXSW6l8dtvEn9BI32HznkOfFUFXPQHcLsSYj mVFRBUsM+y28NRLDnCuQDr40ptZnb5E= X-Google-Smtp-Source: ACJfBouV7xvtaDW3ZCDnr3qZ8hQPE0rnIFDrelpu/CpwKkHXCy0qrGGhst8U4ABsI3lBwfp6uXmkSg== X-Received: by 10.28.138.14 with SMTP id m14mr11523368wmd.52.1515446803107; Mon, 08 Jan 2018 13:26:43 -0800 (PST) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [70.74.179.152]) by smtp.gmail.com with ESMTPSA id x10sm11894950wmf.44.2018.01.08.13.26.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jan 2018 13:26:42 -0800 (PST) Received: from jgg by mlx.ziepe.ca with local (Exim 4.86_2) (envelope-from ) id 1eYewJ-0001O9-N9; Mon, 08 Jan 2018 14:26:39 -0700 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Jason Gunthorpe , Devesh Sharma Subject: [PATCH 2/8] bnxt_re: Convert from init_context to alloc_context Date: Mon, 8 Jan 2018 14:26:26 -0700 Message-Id: <20180108212632.5183-3-jgg@ziepe.ca> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180108212632.5183-1-jgg@ziepe.ca> References: <20180108212632.5183-1-jgg@ziepe.ca> 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: Jason Gunthorpe Now that alloc_context can create a verbs_context directly we do not need two init APIs. Signed-off-by: Jason Gunthorpe --- providers/bnxt_re/main.c | 45 +++++++++++++++++++++++---------------------- providers/bnxt_re/main.h | 4 ++-- providers/bnxt_re/verbs.c | 4 ++-- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/providers/bnxt_re/main.c b/providers/bnxt_re/main.c index 5e83f9d1c12f35..c225f09eaa58f7 100644 --- a/providers/bnxt_re/main.c +++ b/providers/bnxt_re/main.c @@ -104,23 +104,22 @@ static struct ibv_context_ops bnxt_re_cntx_ops = { }; /* Context Init functions */ -static int bnxt_re_init_context(struct verbs_device *vdev, - struct ibv_context *ibvctx, int cmd_fd) +static struct verbs_context *bnxt_re_alloc_context(struct ibv_device *vdev, + int cmd_fd) { struct ibv_get_context cmd; struct bnxt_re_cntx_resp resp; - struct bnxt_re_dev *dev; + struct bnxt_re_dev *dev = to_bnxt_re_dev(vdev); struct bnxt_re_context *cntx; - struct verbs_context *verbs_ctx = verbs_get_ctx(ibvctx); - dev = to_bnxt_re_dev(&vdev->device); - cntx = to_bnxt_re_context(ibvctx); + cntx = verbs_init_and_alloc_context(vdev, cmd_fd, cntx, ibvctx); + if (!cntx) + return NULL; memset(&resp, 0, sizeof(resp)); - ibvctx->cmd_fd = cmd_fd; - if (ibv_cmd_get_context(verbs_ctx, &cmd, sizeof(cmd), &resp.resp, - sizeof(resp))) - return errno; + if (ibv_cmd_get_context(&cntx->ibvctx, &cmd, sizeof(cmd), + &resp.resp, sizeof(resp))) + goto failed; cntx->dev_id = resp.dev_id; cntx->max_qp = resp.max_qp; @@ -137,22 +136,21 @@ static int bnxt_re_init_context(struct verbs_device *vdev, } pthread_mutex_init(&cntx->shlock, NULL); - ibvctx->ops = bnxt_re_cntx_ops; + cntx->ibvctx.context.ops = bnxt_re_cntx_ops; + + return &cntx->ibvctx; - return 0; failed: - fprintf(stderr, DEV "Failed to allocate context for device\n"); - return errno; + verbs_uninit_context(&cntx->ibvctx); + free(cntx); + return NULL; } -static void bnxt_re_uninit_context(struct verbs_device *vdev, - struct ibv_context *ibvctx) +static void bnxt_re_free_context(struct ibv_context *ibvctx) { - struct bnxt_re_dev *dev; - struct bnxt_re_context *cntx; + struct bnxt_re_context *cntx = to_bnxt_re_context(ibvctx); + struct bnxt_re_dev *dev = to_bnxt_re_dev(ibvctx->device); - dev = to_bnxt_re_dev(&vdev->device); - cntx = to_bnxt_re_context(ibvctx); /* Unmap if anything device specific was mapped in init_context. */ pthread_mutex_destroy(&cntx->shlock); if (cntx->shpg) @@ -167,6 +165,9 @@ static void bnxt_re_uninit_context(struct verbs_device *vdev, munmap(cntx->udpi.dbpage, dev->pg_size); cntx->udpi.dbpage = NULL; } + + verbs_uninit_context(&cntx->ibvctx); + free(cntx); } static struct verbs_device * @@ -191,7 +192,7 @@ static const struct verbs_device_ops bnxt_re_dev_ops = { .match_max_abi_version = BNXT_RE_ABI_VERSION, .match_table = cna_table, .alloc_device = bnxt_re_device_alloc, - .init_context = bnxt_re_init_context, - .uninit_context = bnxt_re_uninit_context, + .alloc_context = bnxt_re_alloc_context, + .free_context = bnxt_re_free_context, }; PROVIDER_DRIVER(bnxt_re_dev_ops); diff --git a/providers/bnxt_re/main.h b/providers/bnxt_re/main.h index 33f531ba6d4b1d..affe24f01141ed 100644 --- a/providers/bnxt_re/main.h +++ b/providers/bnxt_re/main.h @@ -141,7 +141,7 @@ struct bnxt_re_dev { }; struct bnxt_re_context { - struct ibv_context ibvctx; + struct verbs_context ibvctx; uint32_t dev_id; uint32_t max_qp; uint32_t max_srq; @@ -167,7 +167,7 @@ static inline struct bnxt_re_dev *to_bnxt_re_dev(struct ibv_device *ibvdev) static inline struct bnxt_re_context *to_bnxt_re_context( struct ibv_context *ibvctx) { - return container_of(ibvctx, struct bnxt_re_context, ibvctx); + return container_of(ibvctx, struct bnxt_re_context, ibvctx.context); } static inline struct bnxt_re_pd *to_bnxt_re_pd(struct ibv_pd *ibvpd) diff --git a/providers/bnxt_re/verbs.c b/providers/bnxt_re/verbs.c index 9d4e02bb328fae..bab2d732d71fa3 100644 --- a/providers/bnxt_re/verbs.c +++ b/providers/bnxt_re/verbs.c @@ -730,7 +730,7 @@ static int bnxt_re_check_qp_limits(struct bnxt_re_context *cntx, struct ibv_device_attr devattr; int ret; - ret = bnxt_re_query_device(&cntx->ibvctx, &devattr); + ret = bnxt_re_query_device(&cntx->ibvctx.context, &devattr); if (ret) return ret; if (attr->cap.max_send_sge > devattr.max_sge) @@ -865,7 +865,7 @@ struct ibv_qp *bnxt_re_create_qp(struct ibv_pd *ibvpd, struct bnxt_re_qpcap *cap; struct bnxt_re_context *cntx = to_bnxt_re_context(ibvpd->context); - struct bnxt_re_dev *dev = to_bnxt_re_dev(cntx->ibvctx.device); + struct bnxt_re_dev *dev = to_bnxt_re_dev(cntx->ibvctx.context.device); if (bnxt_re_check_qp_limits(cntx, attr)) return NULL;