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>,
Devesh Sharma
<Devesh.sharma-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>
Subject: [PATCH 2/8] bnxt_re: Convert from init_context to alloc_context
Date: Mon, 8 Jan 2018 14:26:26 -0700 [thread overview]
Message-ID: <20180108212632.5183-3-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/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;
--
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 ` Jason Gunthorpe [this message]
[not found] ` <20180108212632.5183-3-jgg-uk2M96/98Pc@public.gmane.org>
2018-01-10 5:53 ` [PATCH 2/8] bnxt_re: Convert from init_context to alloc_context 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 ` [PATCH 3/8] mlx4: " Jason Gunthorpe
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-3-jgg@ziepe.ca \
--to=jgg-uk2m96/98pc@public.gmane.org \
--cc=Devesh.sharma-dY08KVG/lbpWk0Htik3J/w@public.gmane.org \
--cc=jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@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