From patchwork Mon Jan 8 21:26:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10150603 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 DA4F46056F for ; Mon, 8 Jan 2018 21:26:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7E9727D29 for ; Mon, 8 Jan 2018 21:26:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCC9E2823E; Mon, 8 Jan 2018 21:26:54 +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 33FD527EED for ; Mon, 8 Jan 2018 21:26:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753810AbeAHV0w (ORCPT ); Mon, 8 Jan 2018 16:26:52 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:41141 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753793AbeAHV0r (ORCPT ); Mon, 8 Jan 2018 16:26:47 -0500 Received: by mail-wr0-f193.google.com with SMTP id o7so9406475wro.8 for ; Mon, 08 Jan 2018 13:26:47 -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=9EyLEx5/BiVcJK+jZF/dvw8gHBrLIkmaDZRRpO6Fn88=; b=BrsaqEmEA92nJE/2slvn8URshQ7oakMS6jPtAFXUEuVn9QufDVL+tPK3tPZuK2SkmN JXl+LbiHlB/iHipKjLrNHYRFZv48qFDoLlx2JTTUvb9VYBEZ2qyuttN+5gk60O7Gzbuw d5tMzMuIFkqDUEWQ75yCeZTNe5DKYSmokJPooP93yCm8pTUgAZSVqUYuNcbHlLLRRajw GmEeMOsClwXuR3T1ZPUFhG58Mr3mne6Q0Lw8D2LbL8NfWgUg6YXCeqPC/H2mObNhLuMz DiDHu3Fnsyi572kHsgUl3lPjPSzlxQr6P1B4T/emSz8UpL0S/Td0ZyNDJS/LJve+URxn cn+w== 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=9EyLEx5/BiVcJK+jZF/dvw8gHBrLIkmaDZRRpO6Fn88=; b=V5pgQnnW1SHuaZxLqF31bqbUo3pFA4aqTq25bqvQ1SnTctVfgMA2D71xXojLPav10T blxT9UdZ/mqgexT7jezTei55jpq6nEtIaJwNUlO7L1iysLpIxyJjb+BzkZWKvnvXQEmE +eWmdXXr7xPVRH3V3JQjWziq0a3be6P7PfItOuG0fGE5lV356Ppxg2XPKHoVj0692FlH lW3j5qdxusWX1c3hMXWQTtpW4DJv7bQ7MmJMXswgk99RQpXzgUJg9gKpv72LIa1X7pSL YlaKlLPSW/J4qxPnMMsj7pb+xvHOajImiRremh6uqV8tPNTuqRu5kCebuF3RiuVWM0Y3 teSA== X-Gm-Message-State: AKGB3mKjTJMpm7GA+tvZblm855oF99lhw1v6xxSRgUIa6b+3II5BmjEG SROMlpY9fsPqQafASTUHiRn8rFo8iTg= X-Google-Smtp-Source: ACJfBotinAFSAgbZ9lhzJBWpBriydQKOWuZSky9KD9vLjqPtsTCeVPziAelrS4pb0+6fNnxGdXnL5A== X-Received: by 10.223.161.22 with SMTP id o22mr12154223wro.34.1515446806028; Mon, 08 Jan 2018 13:26:46 -0800 (PST) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [70.74.179.152]) by smtp.gmail.com with ESMTPSA id g26sm13389307wrb.51.2018.01.08.13.26.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jan 2018 13:26:45 -0800 (PST) Received: from jgg by mlx.ziepe.ca with local (Exim 4.86_2) (envelope-from ) id 1eYewJ-0001OM-Op; Mon, 08 Jan 2018 14:26:39 -0700 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Jason Gunthorpe , Yishai Hadas Subject: [PATCH 3/8] mlx4: Convert from init_context to alloc_context Date: Mon, 8 Jan 2018 14:26:27 -0700 Message-Id: <20180108212632.5183-4-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/mlx4/dbrec.c | 4 ++-- providers/mlx4/mlx4.c | 53 ++++++++++++++++++++++++++++---------------------- providers/mlx4/mlx4.h | 4 ++-- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/providers/mlx4/dbrec.c b/providers/mlx4/dbrec.c index e6d45fcff05a5b..57cd472dd2b381 100644 --- a/providers/mlx4/dbrec.c +++ b/providers/mlx4/dbrec.c @@ -55,7 +55,7 @@ static struct mlx4_db_page *__add_page(struct mlx4_context *context, enum mlx4_db_type type) { struct mlx4_db_page *page; - int ps = to_mdev(context->ibv_ctx.device)->page_size; + int ps = to_mdev(context->ibv_ctx.context.device)->page_size; int pp; int i; @@ -120,7 +120,7 @@ void mlx4_free_db(struct mlx4_context *context, enum mlx4_db_type type, __be32 *db) { struct mlx4_db_page *page; - uintptr_t ps = to_mdev(context->ibv_ctx.device)->page_size; + uintptr_t ps = to_mdev(context->ibv_ctx.context.device)->page_size; int i; pthread_mutex_lock(&context->db_list_mutex); diff --git a/providers/mlx4/mlx4.c b/providers/mlx4/mlx4.c index 56bf1298b48734..3d64b8c8ebae65 100644 --- a/providers/mlx4/mlx4.c +++ b/providers/mlx4/mlx4.c @@ -146,8 +146,8 @@ static int mlx4_map_internal_clock(struct mlx4_device *mdev, return 0; } -static int mlx4_init_context(struct verbs_device *v_device, - struct ibv_context *ibv_ctx, int cmd_fd) +static struct verbs_context *mlx4_alloc_context(struct ibv_device *ibdev, + int cmd_fd) { struct mlx4_context *context; struct ibv_get_context cmd; @@ -155,21 +155,21 @@ static int mlx4_init_context(struct verbs_device *v_device, int i; struct mlx4_alloc_ucontext_resp_v3 resp_v3; __u16 bf_reg_size; - struct mlx4_device *dev = to_mdev(&v_device->device); - struct verbs_context *verbs_ctx = verbs_get_ctx(ibv_ctx); + struct mlx4_device *dev = to_mdev(ibdev); + struct verbs_context *verbs_ctx; struct ibv_device_attr_ex dev_attrs; - /* memory footprint of mlx4_context and verbs_context share - * struct ibv_context. - */ - context = to_mctx(ibv_ctx); - ibv_ctx->cmd_fd = cmd_fd; + context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx); + if (!context) + return NULL; + + verbs_ctx = &context->ibv_ctx; mlx4_read_env(); if (dev->abi_version <= MLX4_UVERBS_NO_DEV_CAPS_ABI_VERSION) { if (ibv_cmd_get_context(verbs_ctx, &cmd, sizeof(cmd), &resp_v3.ibv_resp, sizeof(resp_v3))) - return errno; + goto failed; context->num_qps = resp_v3.qp_tab_size; bf_reg_size = resp_v3.bf_reg_size; @@ -177,7 +177,7 @@ static int mlx4_init_context(struct verbs_device *v_device, } else { if (ibv_cmd_get_context(verbs_ctx, &cmd, sizeof(cmd), &resp.ibv_resp, sizeof(resp))) - return errno; + goto failed; context->num_qps = resp.qp_tab_size; bf_reg_size = resp.bf_reg_size; @@ -205,7 +205,7 @@ static int mlx4_init_context(struct verbs_device *v_device, context->uar = mmap(NULL, dev->page_size, PROT_WRITE, MAP_SHARED, cmd_fd, 0); if (context->uar == MAP_FAILED) - return errno; + goto failed; if (bf_reg_size) { context->bf_page = mmap(NULL, dev->page_size, @@ -226,16 +226,16 @@ static int mlx4_init_context(struct verbs_device *v_device, context->bf_buf_size = 0; } - ibv_ctx->ops = mlx4_ctx_ops; + verbs_ctx->context.ops = mlx4_ctx_ops; context->hca_core_clock = NULL; memset(&dev_attrs, 0, sizeof(dev_attrs)); - if (!mlx4_query_device_ex(ibv_ctx, NULL, &dev_attrs, + if (!mlx4_query_device_ex(&verbs_ctx->context, NULL, &dev_attrs, sizeof(struct ibv_device_attr_ex))) { context->max_qp_wr = dev_attrs.orig_attr.max_qp_wr; context->max_sge = dev_attrs.orig_attr.max_sge; if (context->core_clock.offset_valid) - mlx4_map_internal_clock(dev, ibv_ctx); + mlx4_map_internal_clock(dev, &verbs_ctx->context); } verbs_ctx->close_xrcd = mlx4_close_xrcd; @@ -256,21 +256,28 @@ static int mlx4_init_context(struct verbs_device *v_device, verbs_ctx->destroy_rwq_ind_table = mlx4_destroy_rwq_ind_table; verbs_ctx->modify_cq = mlx4_modify_cq; - return 0; + return verbs_ctx; +failed: + verbs_uninit_context(&context->ibv_ctx); + free(context); + return NULL; } -static void mlx4_uninit_context(struct verbs_device *v_device, - struct ibv_context *ibv_ctx) +static void mlx4_free_context(struct ibv_context *ibv_ctx) { struct mlx4_context *context = to_mctx(ibv_ctx); + struct mlx4_device *mdev = to_mdev(ibv_ctx->device); - munmap(context->uar, to_mdev(&v_device->device)->page_size); + munmap(context->uar, mdev->page_size); if (context->bf_page) - munmap(context->bf_page, to_mdev(&v_device->device)->page_size); + munmap(context->bf_page, mdev->page_size); if (context->hca_core_clock) munmap(context->hca_core_clock - context->core_clock.offset, - to_mdev(&v_device->device)->page_size); + mdev->page_size); + + verbs_uninit_context(&context->ibv_ctx); + free(context); } static void mlx4_uninit_device(struct verbs_device *verbs_device) @@ -305,8 +312,8 @@ static const struct verbs_device_ops mlx4_dev_ops = { .match_table = hca_table, .alloc_device = mlx4_device_alloc, .uninit_device = mlx4_uninit_device, - .init_context = mlx4_init_context, - .uninit_context = mlx4_uninit_context, + .alloc_context = mlx4_alloc_context, + .free_context = mlx4_free_context, }; PROVIDER_DRIVER(mlx4_dev_ops); diff --git a/providers/mlx4/mlx4.h b/providers/mlx4/mlx4.h index a71e42f5c6e25f..e78f6ab0d099e5 100644 --- a/providers/mlx4/mlx4.h +++ b/providers/mlx4/mlx4.h @@ -99,7 +99,7 @@ struct mlx4_device { struct mlx4_db_page; struct mlx4_context { - struct ibv_context ibv_ctx; + struct verbs_context ibv_ctx; void *uar; @@ -260,7 +260,7 @@ static inline struct mlx4_device *to_mdev(struct ibv_device *ibdev) static inline struct mlx4_context *to_mctx(struct ibv_context *ibctx) { - return to_mxxx(ctx, context); + return container_of(ibctx, struct mlx4_context, ibv_ctx.context); } static inline struct mlx4_pd *to_mpd(struct ibv_pd *ibpd)