From: Jason Gunthorpe <jgg-uk2M96/98Pc@public.gmane.org>
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>,
Yishai Hadas <yishaih-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Subject: [PATCH 3/8] mlx4: Convert from init_context to alloc_context
Date: Mon, 8 Jan 2018 14:26:27 -0700 [thread overview]
Message-ID: <20180108212632.5183-4-jgg@ziepe.ca> (raw)
In-Reply-To: <20180108212632.5183-1-jgg-uk2M96/98Pc@public.gmane.org>
From: Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Now that alloc_context can create a verbs_context directly we do
not need two init APIs.
Signed-off-by: Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
---
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)
--
2.15.1
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2018-01-08 21:26 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-08 21:26 [PATCH rdma-core 0/8] Revise provider initialization Jason Gunthorpe
[not found] ` <20180108212632.5183-1-jgg-uk2M96/98Pc@public.gmane.org>
2018-01-08 21:26 ` [PATCH 1/8] verbs: Always allocate a verbs_context Jason Gunthorpe
[not found] ` <20180108212632.5183-2-jgg-uk2M96/98Pc@public.gmane.org>
2018-01-10 5:46 ` Devesh Sharma
[not found] ` <CANjDDBjCUtdVcQBze0PVjC5EaXj5BGTQ5tcn6VcuG0P7auuxoA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-01-10 17:34 ` Jason Gunthorpe
[not found] ` <20180110173427.GE4776-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2018-01-11 17:44 ` Devesh Sharma
[not found] ` <CANjDDBgmueZ3fiRJsHEb+p5+H5gX8-7z0NbJShc2bk8yXrh+pg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-01-11 17:54 ` Jason Gunthorpe
[not found] ` <20180111175422.GG30208-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2018-01-12 11:08 ` Devesh Sharma
2018-01-08 21:26 ` [PATCH 2/8] bnxt_re: Convert from init_context to alloc_context Jason Gunthorpe
[not found] ` <20180108212632.5183-3-jgg-uk2M96/98Pc@public.gmane.org>
2018-01-10 5:53 ` Devesh Sharma
[not found] ` <CANjDDBjwmtO2aOtY5NCObrU_VJVmHjw=fdJOk_VvfZx+8+4Ejw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-01-10 17:36 ` Jason Gunthorpe
2018-01-08 21:26 ` Jason Gunthorpe [this message]
2018-01-08 21:26 ` [PATCH 4/8] mlx5: " Jason Gunthorpe
2018-01-08 21:26 ` [PATCH 5/8] verbs: Remove init_context/uninit_context Jason Gunthorpe
[not found] ` <20180108212632.5183-6-jgg-uk2M96/98Pc@public.gmane.org>
2018-01-10 5:59 ` Devesh Sharma
2018-01-08 21:26 ` [PATCH 6/8] verbs: Provide a default implementation for every verbs op Jason Gunthorpe
2018-01-08 21:26 ` [PATCH 7/8] verbs: Convert all providers to use verbs_set_ops Jason Gunthorpe
2018-01-08 21:26 ` [PATCH 8/8] verbs: Remove tests for NULL ops Jason Gunthorpe
2018-01-10 22:05 ` [PATCH rdma-core 0/8] Revise provider initialization Steve Wise
2018-01-10 22:06 ` Steve Wise
2018-01-10 22:27 ` Jason Gunthorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180108212632.5183-4-jgg@ziepe.ca \
--to=jgg-uk2m96/98pc@public.gmane.org \
--cc=jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=yishaih-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox