* [PATCH rdma-core 0/8] Revise provider initialization
@ 2018-01-08 21:26 Jason Gunthorpe
[not found] ` <20180108212632.5183-1-jgg-uk2M96/98Pc@public.gmane.org>
0 siblings, 1 reply; 20+ messages in thread
From: Jason Gunthorpe @ 2018-01-08 21:26 UTC (permalink / raw)
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA; +Cc: Jason Gunthorpe
From: Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
This make all the context creation uniform by having every driver create a
struct verbs_context using the same startup flow.
Long ago we had a new and old flow, where the new flow was intended to support
a stable provider ABI, but now that the ABI is private we do not need that.
By having every single provider having a verbs_context we can now rely on
things like the priv existing and a sane init ordering where the priv can
exist even before the first command runs.
Having priv always available is a necessary component to introduce support for
the new ioctl kabi.
Finally, the last three patches rework the ops setup to use a struct of
function pointers scheme and provides defaults for every function. The
defaults return ENOSYS which fixes a bunch of cases where the user could have
called a function without driver support and got a crash.
This is github PR:
https://github.com/linux-rdma/rdma-core/pull/281
Jason Gunthorpe (8):
verbs: Always allocate a verbs_context
bnxt_re: Convert from init_context to alloc_context
mlx4: Convert from init_context to alloc_context
mlx5: Convert from init_context to alloc_context
verbs: Remove init_context/uninit_context
verbs: Provide a default implementation for every verbs op
verbs: Convert all providers to use verbs_set_ops
verbs: Remove tests for NULL ops
CMakeLists.txt | 2 +-
debian/libibverbs1.symbols | 2 +-
libibverbs/CMakeLists.txt | 1 +
libibverbs/cmd.c | 12 +-
libibverbs/device.c | 186 ++++++++-------
libibverbs/driver.h | 130 ++++++++--
libibverbs/dummy_ops.c | 469 +++++++++++++++++++++++++++++++++++++
libibverbs/ibverbs.h | 1 +
libibverbs/libibverbs.map.in | 3 +
libibverbs/verbs.c | 14 +-
providers/bnxt_re/main.c | 48 ++--
providers/bnxt_re/main.h | 4 +-
providers/bnxt_re/verbs.c | 4 +-
providers/cxgb3/iwch.c | 39 +--
providers/cxgb3/iwch.h | 4 +-
providers/cxgb4/dev.c | 35 +--
providers/cxgb4/libcxgb4.h | 4 +-
providers/hfi1verbs/hfiverbs.c | 47 ++--
providers/hfi1verbs/hfiverbs.h | 4 +-
providers/hns/hns_roce_u.c | 53 +++--
providers/hns/hns_roce_u.h | 4 +-
providers/hns/hns_roce_u_verbs.c | 6 +-
providers/i40iw/i40iw_umain.c | 23 +-
providers/i40iw/i40iw_umain.h | 4 +-
providers/ipathverbs/ipathverbs.c | 45 ++--
providers/ipathverbs/ipathverbs.h | 4 +-
providers/mlx4/dbrec.c | 4 +-
providers/mlx4/mlx4.c | 105 +++++----
providers/mlx4/mlx4.h | 4 +-
providers/mlx5/buf.c | 2 +-
providers/mlx5/cq.c | 2 +-
providers/mlx5/dbrec.c | 4 +-
providers/mlx5/mlx5.c | 111 +++++----
providers/mlx5/mlx5.h | 4 +-
providers/mthca/mthca.c | 59 ++---
providers/mthca/mthca.h | 4 +-
providers/nes/nes_umain.c | 32 ++-
providers/nes/nes_umain.h | 4 +-
providers/ocrdma/ocrdma_main.c | 17 +-
providers/ocrdma/ocrdma_main.h | 4 +-
providers/qedr/qelr.h | 4 +-
providers/qedr/qelr_main.c | 17 +-
providers/qedr/qelr_verbs.c | 2 +-
providers/rxe/rxe.c | 16 +-
providers/rxe/rxe.h | 4 +-
providers/vmw_pvrdma/pvrdma.h | 4 +-
providers/vmw_pvrdma/pvrdma_main.c | 17 +-
47 files changed, 1087 insertions(+), 481 deletions(-)
create mode 100644 libibverbs/dummy_ops.c
--
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
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 1/8] verbs: Always allocate a verbs_context
[not found] ` <20180108212632.5183-1-jgg-uk2M96/98Pc@public.gmane.org>
@ 2018-01-08 21:26 ` Jason Gunthorpe
[not found] ` <20180108212632.5183-2-jgg-uk2M96/98Pc@public.gmane.org>
2018-01-08 21:26 ` [PATCH 2/8] bnxt_re: Convert from init_context to alloc_context Jason Gunthorpe
` (7 subsequent siblings)
8 siblings, 1 reply; 20+ messages in thread
From: Jason Gunthorpe @ 2018-01-08 21:26 UTC (permalink / raw)
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA
Cc: Jason Gunthorpe, Benjamin Drung, Doug Ledford, Yishai Hadas,
Devesh Sharma, Steve Wise, Mike Marciniszyn, Dennis Dalessandro,
Lijun Ou, Wei Hu(Xavier), Tatyana Nikolova, Vladimir Sokolovsky,
Ram Amrani, Ariel Elior, Moni Shoua, Adit Ranadive,
Leon Romanovsky, Nicolas Morey-Chaisemartin, Alex
From: Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Now that everything is in one tree we can revise the legacy init_context
path to always allocate a verbs_context by swapping the ibv_context
for a verbs_context in all of the provider's wrapper struct.
To keep the provider diffs minimal this single patch does several things
at once:
- Introduce the verbs_init_and_alloc_context() macro.
This allocates, zeros and initializes the verbs_context for each driver.
Notably this new macro correctly sets errno as required upon failure.
- Remove boilerplate from all drivers, calloc, malloc, memset, cmd_fd and
device assignment
- Along with the verbs_init scheme necessarily comes the verbs_uninit
scheme which lowers the uninit call into the provder not the common
code. This allows us to properly uninit on the init error path.
Together this follows the fairly successful pattern we see in the kernel
for driver init to a subsystem.
Also this changes ibv_cmd_get_context to accept a verbs_context since
the majority of callers are now providing that, this keeps the diff
smaller.
This makes the entire flow more consistent and will let us eliminate the
init_context flow.
Signed-off-by: Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
---
CMakeLists.txt | 2 +-
debian/libibverbs1.symbols | 2 +-
libibverbs/cmd.c | 12 +--
libibverbs/device.c | 206 +++++++++++++++++++++++--------------
libibverbs/driver.h | 23 ++++-
libibverbs/libibverbs.map.in | 2 +
providers/bnxt_re/main.c | 5 +-
providers/cxgb3/iwch.c | 30 +++---
providers/cxgb3/iwch.h | 4 +-
providers/cxgb4/dev.c | 29 +++---
providers/cxgb4/libcxgb4.h | 4 +-
providers/hfi1verbs/hfiverbs.c | 36 ++++---
providers/hfi1verbs/hfiverbs.h | 4 +-
providers/hns/hns_roce_u.c | 53 +++++-----
providers/hns/hns_roce_u.h | 4 +-
providers/hns/hns_roce_u_verbs.c | 6 +-
providers/i40iw/i40iw_umain.c | 16 +--
providers/i40iw/i40iw_umain.h | 4 +-
providers/ipathverbs/ipathverbs.c | 36 ++++---
providers/ipathverbs/ipathverbs.h | 4 +-
providers/mlx4/mlx4.c | 8 +-
providers/mlx5/mlx5.c | 8 +-
providers/mthca/mthca.c | 48 +++++----
providers/mthca/mthca.h | 4 +-
providers/nes/nes_umain.c | 19 ++--
providers/nes/nes_umain.h | 4 +-
providers/ocrdma/ocrdma_main.c | 14 ++-
providers/ocrdma/ocrdma_main.h | 4 +-
providers/qedr/qelr.h | 4 +-
providers/qedr/qelr_main.c | 14 +--
providers/qedr/qelr_verbs.c | 2 +-
providers/rxe/rxe.c | 13 ++-
providers/rxe/rxe.h | 4 +-
providers/vmw_pvrdma/pvrdma.h | 4 +-
providers/vmw_pvrdma/pvrdma_main.c | 14 +--
35 files changed, 359 insertions(+), 287 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b1467317b68561..e8f4a948ad9610 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -52,7 +52,7 @@ set(PACKAGE_VERSION "17.0")
# When this is changed the values in these files need changing too:
# debian/libibverbs1.symbols
# libibverbs/libibverbs.map
-set(IBVERBS_PABI_VERSION "16")
+set(IBVERBS_PABI_VERSION "17")
set(IBVERBS_PROVIDER_SUFFIX "-rdmav${IBVERBS_PABI_VERSION}.so")
#-------------------------
diff --git a/debian/libibverbs1.symbols b/debian/libibverbs1.symbols
index 2678fa6e98acf7..7c7659e434bc63 100644
--- a/debian/libibverbs1.symbols
+++ b/debian/libibverbs1.symbols
@@ -1,7 +1,7 @@
libibverbs.so.1 libibverbs1 #MINVER#
IBVERBS_1.0@IBVERBS_1.0 1.1.6
IBVERBS_1.1@IBVERBS_1.1 1.1.6
- (symver)IBVERBS_PRIVATE_16 16
+ (symver)IBVERBS_PRIVATE_17 17
ibv_ack_async_event@IBVERBS_1.0 1.1.6
ibv_ack_async_event@IBVERBS_1.1 1.1.6
ibv_ack_cq_events@IBVERBS_1.0 1.1.6
diff --git a/libibverbs/cmd.c b/libibverbs/cmd.c
index b957550ed6fbdb..bcec94f5b0ce72 100644
--- a/libibverbs/cmd.c
+++ b/libibverbs/cmd.c
@@ -44,22 +44,22 @@
#include "ibverbs.h"
#include <ccan/minmax.h>
-int ibv_cmd_get_context(struct ibv_context *context, struct ibv_get_context *cmd,
- size_t cmd_size, struct ibv_get_context_resp *resp,
- size_t resp_size)
+int ibv_cmd_get_context(struct verbs_context *context_ex,
+ struct ibv_get_context *cmd, size_t cmd_size,
+ struct ibv_get_context_resp *resp, size_t resp_size)
{
if (abi_ver < IB_USER_VERBS_MIN_ABI_VERSION)
return ENOSYS;
IBV_INIT_CMD_RESP(cmd, cmd_size, GET_CONTEXT, resp, resp_size);
- if (write(context->cmd_fd, cmd, cmd_size) != cmd_size)
+ if (write(context_ex->context.cmd_fd, cmd, cmd_size) != cmd_size)
return errno;
(void) VALGRIND_MAKE_MEM_DEFINED(resp, resp_size);
- context->async_fd = resp->async_fd;
- context->num_comp_vectors = resp->num_comp_vectors;
+ context_ex->context.async_fd = resp->async_fd;
+ context_ex->context.num_comp_vectors = resp->num_comp_vectors;
return 0;
}
diff --git a/libibverbs/device.c b/libibverbs/device.c
index 4fb759c6474ad7..e42e37bd0a1f8d 100644
--- a/libibverbs/device.c
+++ b/libibverbs/device.c
@@ -162,7 +162,8 @@ static struct ibv_cq_ex *
__lib_ibv_create_cq_ex(struct ibv_context *context,
struct ibv_cq_init_attr_ex *cq_attr)
{
- struct verbs_context *vctx = verbs_get_ctx(context);
+ struct verbs_context *vctx =
+ container_of(context, struct verbs_context, context);
struct ibv_cq_ex *cq;
if (cq_attr->wc_flags & ~IBV_CREATE_CQ_SUP_WC_FLAGS) {
@@ -179,14 +180,115 @@ __lib_ibv_create_cq_ex(struct ibv_context *context,
return cq;
}
+/*
+ * Ownership of cmd_fd is transferred into this function, and it will either
+ * be released during the matching call to verbs_uninit_contxt or during the
+ * failure path of this function.
+ */
+int verbs_init_context(struct verbs_context *context_ex,
+ struct ibv_device *device, int cmd_fd)
+{
+ struct ibv_context *context = &context_ex->context;
+
+ ibverbs_device_hold(device);
+
+ context->device = device;
+ context->cmd_fd = cmd_fd;
+ context->async_fd = -1;
+ pthread_mutex_init(&context->mutex, NULL);
+
+ context_ex->context.abi_compat = __VERBS_ABI_IS_EXTENDED;
+ context_ex->sz = sizeof(*context_ex);
+
+ /*
+ * In order to maintain backward/forward binary compatibility
+ * with apps compiled against libibverbs-1.1.8 that use the
+ * flow steering addition, we need to set the two
+ * ABI_placeholder entries to match the driver set flow
+ * entries. This is because apps compiled against
+ * libibverbs-1.1.8 use an inline ibv_create_flow and
+ * ibv_destroy_flow function that looks in the placeholder
+ * spots for the proper entry points. For apps compiled
+ * against libibverbs-1.1.9 and later, the inline functions
+ * will be looking in the right place.
+ */
+ context_ex->ABI_placeholder1 =
+ (void (*)(void))context_ex->ibv_create_flow;
+ context_ex->ABI_placeholder2 =
+ (void (*)(void))context_ex->ibv_destroy_flow;
+
+ context_ex->priv = calloc(1, sizeof(context_ex->priv));
+ if (!context_ex->priv) {
+ errno = ENOMEM;
+ close(cmd_fd);
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ * Allocate and initialize a context structure. This is called to create the
+ * driver wrapper, and context_offset is the number of bytes into the wrapper
+ * structure where the verbs_context starts.
+ */
+void *_verbs_init_and_alloc_context(struct ibv_device *device, int cmd_fd,
+ size_t alloc_size,
+ struct verbs_context *context_offset)
+{
+ void *drv_context;
+ struct verbs_context *context;
+
+ drv_context = calloc(1, alloc_size);
+ if (!drv_context) {
+ errno = ENOMEM;
+ close(cmd_fd);
+ return NULL;
+ }
+
+ context = (struct verbs_context *)((uint8_t *)drv_context +
+ (uintptr_t)context_offset);
+
+ if (verbs_init_context(context, device, cmd_fd))
+ goto err_free;
+
+ return drv_context;
+
+err_free:
+ free(drv_context);
+ return NULL;
+}
+
+/* Use the init_context flow to create a verbs_context */
+static struct verbs_context *alloc_context(struct verbs_device *device,
+ int cmd_fd)
+{
+ struct verbs_context *context;
+
+ context = _verbs_init_and_alloc_context(
+ &device->device, cmd_fd,
+ sizeof(*context) + device->size_of_context, NULL);
+ if (!context)
+ return NULL;
+
+ if (device->ops->init_context(device, &context->context, cmd_fd))
+ goto err_uninit;
+
+ return context;
+
+err_uninit:
+ verbs_uninit_context(context);
+ free(context);
+ return NULL;
+}
+
LATEST_SYMVER_FUNC(ibv_open_device, 1_1, "IBVERBS_1.1",
struct ibv_context *,
struct ibv_device *device)
{
struct verbs_device *verbs_device = verbs_get_device(device);
char *devpath;
- int cmd_fd, ret;
- struct ibv_context *context;
+ int cmd_fd;
struct verbs_context *context_ex;
if (asprintf(&devpath, "/dev/infiniband/%s", device->dev_name) < 0)
@@ -202,96 +304,50 @@ LATEST_SYMVER_FUNC(ibv_open_device, 1_1, "IBVERBS_1.1",
if (cmd_fd < 0)
return NULL;
- if (!verbs_device->ops->init_context) {
- context = verbs_device->ops->alloc_context(device, cmd_fd);
- if (!context)
- goto err;
- } else {
- struct verbs_ex_private *priv;
-
- /* Library now allocates the context */
- context_ex = calloc(1, sizeof(*context_ex) +
- verbs_device->size_of_context);
- if (!context_ex) {
- errno = ENOMEM;
- goto err;
- }
-
- priv = calloc(1, sizeof(*priv));
- if (!priv) {
- errno = ENOMEM;
- free(context_ex);
- goto err;
- }
-
- context_ex->priv = priv;
- context_ex->context.abi_compat = __VERBS_ABI_IS_EXTENDED;
- context_ex->sz = sizeof(*context_ex);
-
- context = &context_ex->context;
- ret = verbs_device->ops->init_context(verbs_device, context, cmd_fd);
- if (ret)
- goto verbs_err;
- /*
- * In order to maintain backward/forward binary compatibility
- * with apps compiled against libibverbs-1.1.8 that use the
- * flow steering addition, we need to set the two
- * ABI_placeholder entries to match the driver set flow
- * entries. This is because apps compiled against
- * libibverbs-1.1.8 use an inline ibv_create_flow and
- * ibv_destroy_flow function that looks in the placeholder
- * spots for the proper entry points. For apps compiled
- * against libibverbs-1.1.9 and later, the inline functions
- * will be looking in the right place.
- */
- context_ex->ABI_placeholder1 = (void (*)(void)) context_ex->ibv_create_flow;
- context_ex->ABI_placeholder2 = (void (*)(void)) context_ex->ibv_destroy_flow;
-
- if (context_ex->create_cq_ex) {
- priv->create_cq_ex = context_ex->create_cq_ex;
- context_ex->create_cq_ex = __lib_ibv_create_cq_ex;
- }
- }
+ if (!verbs_device->ops->init_context)
+ context_ex = verbs_device->ops->alloc_context(device, cmd_fd);
+ else
+ context_ex = alloc_context(verbs_device, cmd_fd);
- context->device = device;
- context->cmd_fd = cmd_fd;
- pthread_mutex_init(&context->mutex, NULL);
+ /*
+ * cmd_fd ownership is transferred into alloc_context, if it fails
+ * then it closes cmd_fd and returns NULL
+ */
+ if (context_ex == NULL)
+ return NULL;
- ibverbs_device_hold(device);
+ if (context_ex->create_cq_ex) {
+ context_ex->priv->create_cq_ex = context_ex->create_cq_ex;
+ context_ex->create_cq_ex = __lib_ibv_create_cq_ex;
+ }
- return context;
+ return &context_ex->context;
+}
-verbs_err:
+void verbs_uninit_context(struct verbs_context *context_ex)
+{
free(context_ex->priv);
- free(context_ex);
-err:
- close(cmd_fd);
- return NULL;
+ close(context_ex->context.cmd_fd);
+ close(context_ex->context.async_fd);
+ ibverbs_device_put(context_ex->context.device);
}
LATEST_SYMVER_FUNC(ibv_close_device, 1_1, "IBVERBS_1.1",
int,
struct ibv_context *context)
{
- int async_fd = context->async_fd;
- int cmd_fd = context->cmd_fd;
- struct verbs_context *context_ex;
struct verbs_device *verbs_device = verbs_get_device(context->device);
- struct ibv_device *device = context->device;
- context_ex = verbs_get_ctx(context);
- if (context_ex) {
+ if (verbs_device->ops->uninit_context) {
+ struct verbs_context *context_ex =
+ container_of(context, struct verbs_context, context);
+
verbs_device->ops->uninit_context(verbs_device, context);
- free(context_ex->priv);
- free(context_ex);
+ verbs_uninit_context(context_ex);
} else {
verbs_device->ops->free_context(context);
}
- close(async_fd);
- close(cmd_fd);
- ibverbs_device_put(device);
-
return 0;
}
diff --git a/libibverbs/driver.h b/libibverbs/driver.h
index 4698ba4e609f34..809c4f5c8cdf39 100644
--- a/libibverbs/driver.h
+++ b/libibverbs/driver.h
@@ -153,8 +153,8 @@ struct verbs_device_ops {
bool (*match_device)(struct verbs_sysfs_dev *sysfs_dev);
/* Old interface, do not use in new code. */
- struct ibv_context *(*alloc_context)(struct ibv_device *device,
- int cmd_fd);
+ struct verbs_context *(*alloc_context)(struct ibv_device *device,
+ int cmd_fd);
void (*free_context)(struct ibv_context *context);
/* New interface */
@@ -205,13 +205,26 @@ void verbs_register_driver(const struct verbs_device_ops *ops);
verbs_register_driver(&drv); \
}
+void *_verbs_init_and_alloc_context(struct ibv_device *device, int cmd_fd,
+ size_t alloc_size,
+ struct verbs_context *context_offset);
+
+#define verbs_init_and_alloc_context(ibdev, cmd_fd, drv_ctx_ptr, ctx_memb) \
+ ((typeof(drv_ctx_ptr))_verbs_init_and_alloc_context( \
+ ibdev, cmd_fd, sizeof(*drv_ctx_ptr), \
+ &((typeof(drv_ctx_ptr))NULL)->ctx_memb))
+
+int verbs_init_context(struct verbs_context *context_ex,
+ struct ibv_device *device, int cmd_fd);
+void verbs_uninit_context(struct verbs_context *context);
+
void verbs_init_cq(struct ibv_cq *cq, struct ibv_context *context,
struct ibv_comp_channel *channel,
void *cq_context);
-int ibv_cmd_get_context(struct ibv_context *context, struct ibv_get_context *cmd,
- size_t cmd_size, struct ibv_get_context_resp *resp,
- size_t resp_size);
+int ibv_cmd_get_context(struct verbs_context *context,
+ struct ibv_get_context *cmd, size_t cmd_size,
+ struct ibv_get_context_resp *resp, size_t resp_size);
int ibv_cmd_query_device(struct ibv_context *context,
struct ibv_device_attr *device_attr,
uint64_t *raw_fw_ver,
diff --git a/libibverbs/libibverbs.map.in b/libibverbs/libibverbs.map.in
index 3f635a94b82d58..b787b051b4c381 100644
--- a/libibverbs/libibverbs.map.in
+++ b/libibverbs/libibverbs.map.in
@@ -113,6 +113,7 @@ IBVERBS_1.1 {
IBVERBS_PRIVATE_@IBVERBS_PABI_VERSION@ {
global:
/* These historical symbols are now private to libibverbs */
+ _verbs_init_and_alloc_context;
ibv_cmd_alloc_mw;
ibv_cmd_alloc_pd;
ibv_cmd_attach_mcast;
@@ -162,6 +163,7 @@ IBVERBS_PRIVATE_@IBVERBS_PABI_VERSION@ {
ibv_query_gid_type;
ibv_register_driver;
verbs_register_driver_@IBVERBS_PABI_VERSION@;
+ verbs_uninit_context;
verbs_init_cq;
ibv_cmd_modify_cq;
};
diff --git a/providers/bnxt_re/main.c b/providers/bnxt_re/main.c
index 998c9fe3313389..5e83f9d1c12f35 100644
--- a/providers/bnxt_re/main.c
+++ b/providers/bnxt_re/main.c
@@ -111,14 +111,15 @@ static int bnxt_re_init_context(struct verbs_device *vdev,
struct bnxt_re_cntx_resp resp;
struct bnxt_re_dev *dev;
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);
memset(&resp, 0, sizeof(resp));
ibvctx->cmd_fd = cmd_fd;
- if (ibv_cmd_get_context(ibvctx, &cmd, sizeof(cmd),
- &resp.resp, sizeof(resp)))
+ if (ibv_cmd_get_context(verbs_ctx, &cmd, sizeof(cmd), &resp.resp,
+ sizeof(resp)))
return errno;
cntx->dev_id = resp.dev_id;
diff --git a/providers/cxgb3/iwch.c b/providers/cxgb3/iwch.c
index da9179fbbe2a8d..d4d5a96ffd524e 100644
--- a/providers/cxgb3/iwch.c
+++ b/providers/cxgb3/iwch.c
@@ -104,42 +104,38 @@ unsigned long iwch_page_size;
unsigned long iwch_page_shift;
unsigned long iwch_page_mask;
-static struct ibv_context *iwch_alloc_context(struct ibv_device *ibdev,
- int cmd_fd)
+static struct verbs_context *iwch_alloc_context(struct ibv_device *ibdev,
+ int cmd_fd)
{
struct iwch_context *context;
struct ibv_get_context cmd;
struct iwch_alloc_ucontext_resp resp;
struct iwch_device *rhp = to_iwch_dev(ibdev);
- context = malloc(sizeof *context);
+ context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx);
if (!context)
return NULL;
- memset(context, 0, sizeof *context);
- context->ibv_ctx.cmd_fd = cmd_fd;
-
if (ibv_cmd_get_context(&context->ibv_ctx, &cmd, sizeof cmd,
&resp.ibv_resp, sizeof resp))
goto err_free;
- context->ibv_ctx.device = ibdev;
- context->ibv_ctx.ops = iwch_ctx_ops;
+ context->ibv_ctx.context.ops = iwch_ctx_ops;
switch (rhp->hca_type) {
case CHELSIO_T3B:
PDBG("%s T3B device\n", __FUNCTION__);
- context->ibv_ctx.ops.async_event = t3b_async_event;
- context->ibv_ctx.ops.post_send = t3b_post_send;
- context->ibv_ctx.ops.post_recv = t3b_post_recv;
- context->ibv_ctx.ops.poll_cq = t3b_poll_cq;
+ context->ibv_ctx.context.ops.async_event = t3b_async_event;
+ context->ibv_ctx.context.ops.post_send = t3b_post_send;
+ context->ibv_ctx.context.ops.post_recv = t3b_post_recv;
+ context->ibv_ctx.context.ops.poll_cq = t3b_poll_cq;
break;
case CHELSIO_T3A:
PDBG("%s T3A device\n", __FUNCTION__);
- context->ibv_ctx.ops.async_event = NULL;
- context->ibv_ctx.ops.post_send = t3a_post_send;
- context->ibv_ctx.ops.post_recv = t3a_post_recv;
- context->ibv_ctx.ops.poll_cq = t3a_poll_cq;
+ context->ibv_ctx.context.ops.async_event = NULL;
+ context->ibv_ctx.context.ops.post_send = t3a_post_send;
+ context->ibv_ctx.context.ops.post_recv = t3a_post_recv;
+ context->ibv_ctx.context.ops.poll_cq = t3a_poll_cq;
break;
default:
PDBG("%s unknown hca type %d\n", __FUNCTION__, rhp->hca_type);
@@ -150,6 +146,7 @@ static struct ibv_context *iwch_alloc_context(struct ibv_device *ibdev,
return &context->ibv_ctx;
err_free:
+ verbs_uninit_context(&context->ibv_ctx);
free(context);
return NULL;
}
@@ -158,6 +155,7 @@ static void iwch_free_context(struct ibv_context *ibctx)
{
struct iwch_context *context = to_iwch_ctx(ibctx);
+ verbs_uninit_context(&context->ibv_ctx);
free(context);
}
diff --git a/providers/cxgb3/iwch.h b/providers/cxgb3/iwch.h
index 1b95fec664ef11..0b8060cf7cfa8f 100644
--- a/providers/cxgb3/iwch.h
+++ b/providers/cxgb3/iwch.h
@@ -71,7 +71,7 @@ static inline int t3a_device(struct iwch_device *dev)
}
struct iwch_context {
- struct ibv_context ibv_ctx;
+ struct verbs_context ibv_ctx;
};
struct iwch_pd {
@@ -111,7 +111,7 @@ static inline struct iwch_device *to_iwch_dev(struct ibv_device *ibdev)
static inline struct iwch_context *to_iwch_ctx(struct ibv_context *ibctx)
{
- return to_iwch_xxx(ctx, context);
+ return container_of(ibctx, struct iwch_context, ibv_ctx.context);
}
static inline struct iwch_pd *to_iwch_pd(struct ibv_pd *ibpd)
diff --git a/providers/cxgb4/dev.c b/providers/cxgb4/dev.c
index b6775da8afeef7..3c309d9f5defb5 100644
--- a/providers/cxgb4/dev.c
+++ b/providers/cxgb4/dev.c
@@ -96,8 +96,8 @@ static struct ibv_context_ops c4iw_ctx_ops = {
.req_notify_cq = c4iw_arm_cq,
};
-static struct ibv_context *c4iw_alloc_context(struct ibv_device *ibdev,
- int cmd_fd)
+static struct verbs_context *c4iw_alloc_context(struct ibv_device *ibdev,
+ int cmd_fd)
{
struct c4iw_context *context;
struct ibv_get_context cmd;
@@ -107,13 +107,10 @@ static struct ibv_context *c4iw_alloc_context(struct ibv_device *ibdev,
uint64_t raw_fw_ver;
struct ibv_device_attr attr;
- context = malloc(sizeof *context);
+ context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx);
if (!context)
return NULL;
- memset(context, 0, sizeof *context);
- context->ibv_ctx.cmd_fd = cmd_fd;
-
resp.status_page_size = 0;
resp.reserved = 0;
if (ibv_cmd_get_context(&context->ibv_ctx, &cmd, sizeof cmd,
@@ -133,8 +130,7 @@ static struct ibv_context *c4iw_alloc_context(struct ibv_device *ibdev,
goto err_free;
}
- context->ibv_ctx.device = ibdev;
- context->ibv_ctx.ops = c4iw_ctx_ops;
+ context->ibv_ctx.context.ops = c4iw_ctx_ops;
switch (rhp->chip_version) {
case CHELSIO_T6:
@@ -143,11 +139,11 @@ static struct ibv_context *c4iw_alloc_context(struct ibv_device *ibdev,
PDBG("%s T5/T4 device\n", __FUNCTION__);
case CHELSIO_T4:
PDBG("%s T4 device\n", __FUNCTION__);
- context->ibv_ctx.ops.async_event = c4iw_async_event;
- context->ibv_ctx.ops.post_send = c4iw_post_send;
- context->ibv_ctx.ops.post_recv = c4iw_post_receive;
- context->ibv_ctx.ops.poll_cq = c4iw_poll_cq;
- context->ibv_ctx.ops.req_notify_cq = c4iw_arm_cq;
+ context->ibv_ctx.context.ops.async_event = c4iw_async_event;
+ context->ibv_ctx.context.ops.post_send = c4iw_post_send;
+ context->ibv_ctx.context.ops.post_recv = c4iw_post_receive;
+ context->ibv_ctx.context.ops.poll_cq = c4iw_poll_cq;
+ context->ibv_ctx.context.ops.req_notify_cq = c4iw_arm_cq;
break;
default:
PDBG("%s unknown hca type %d\n", __FUNCTION__,
@@ -159,8 +155,8 @@ static struct ibv_context *c4iw_alloc_context(struct ibv_device *ibdev,
if (!rhp->mmid2ptr) {
int ret;
- ret = ibv_cmd_query_device(&context->ibv_ctx, &attr, &raw_fw_ver, &qcmd,
- sizeof qcmd);
+ ret = ibv_cmd_query_device(&context->ibv_ctx.context, &attr,
+ &raw_fw_ver, &qcmd, sizeof(qcmd));
if (ret)
goto err_unmap;
rhp->max_mr = attr.max_mr;
@@ -201,6 +197,7 @@ err_free:
free(rhp->cqid2ptr);
if (rhp->mmid2ptr)
free(rhp->cqid2ptr);
+ verbs_uninit_context(&context->ibv_ctx);
free(context);
return NULL;
}
@@ -211,6 +208,8 @@ static void c4iw_free_context(struct ibv_context *ibctx)
if (context->status_page_size)
munmap(context->status_page, context->status_page_size);
+
+ verbs_uninit_context(&context->ibv_ctx);
free(context);
}
diff --git a/providers/cxgb4/libcxgb4.h b/providers/cxgb4/libcxgb4.h
index a5256f7e081770..893bd85d5f34b2 100644
--- a/providers/cxgb4/libcxgb4.h
+++ b/providers/cxgb4/libcxgb4.h
@@ -80,7 +80,7 @@ static inline int dev_is_t4(struct c4iw_dev *dev)
}
struct c4iw_context {
- struct ibv_context ibv_ctx;
+ struct verbs_context ibv_ctx;
struct t4_dev_status_page *status_page;
int status_page_size;
};
@@ -129,7 +129,7 @@ static inline struct c4iw_dev *to_c4iw_dev(struct ibv_device *ibdev)
static inline struct c4iw_context *to_c4iw_context(struct ibv_context *ibctx)
{
- return to_c4iw_xxx(ctx, context);
+ return container_of(ibctx, struct c4iw_context, ibv_ctx.context);
}
static inline struct c4iw_pd *to_c4iw_pd(struct ibv_pd *ibpd)
diff --git a/providers/hfi1verbs/hfiverbs.c b/providers/hfi1verbs/hfiverbs.c
index 7f8f5714db1630..6117f99fbc27a2 100644
--- a/providers/hfi1verbs/hfiverbs.c
+++ b/providers/hfi1verbs/hfiverbs.c
@@ -123,41 +123,42 @@ static struct ibv_context_ops hfi1_ctx_ops = {
.detach_mcast = ibv_cmd_detach_mcast
};
-static struct ibv_context *hfi1_alloc_context(struct ibv_device *ibdev,
- int cmd_fd)
+static struct verbs_context *hfi1_alloc_context(struct ibv_device *ibdev,
+ int cmd_fd)
{
struct hfi1_context *context;
struct ibv_get_context cmd;
struct ibv_get_context_resp resp;
struct hfi1_device *dev;
- context = malloc(sizeof *context);
+ context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx);
if (!context)
return NULL;
- memset(context, 0, sizeof *context);
- context->ibv_ctx.cmd_fd = cmd_fd;
+
if (ibv_cmd_get_context(&context->ibv_ctx, &cmd,
sizeof cmd, &resp, sizeof resp))
goto err_free;
- context->ibv_ctx.ops = hfi1_ctx_ops;
+ context->ibv_ctx.context.ops = hfi1_ctx_ops;
dev = to_idev(ibdev);
if (dev->abi_version == 1) {
- context->ibv_ctx.ops.create_cq = hfi1_create_cq_v1;
- context->ibv_ctx.ops.poll_cq = ibv_cmd_poll_cq;
- context->ibv_ctx.ops.resize_cq = hfi1_resize_cq_v1;
- context->ibv_ctx.ops.destroy_cq = hfi1_destroy_cq_v1;
- context->ibv_ctx.ops.create_srq = hfi1_create_srq_v1;
- context->ibv_ctx.ops.destroy_srq = hfi1_destroy_srq_v1;
- context->ibv_ctx.ops.modify_srq = hfi1_modify_srq_v1;
- context->ibv_ctx.ops.post_srq_recv = ibv_cmd_post_srq_recv;
- context->ibv_ctx.ops.create_qp = hfi1_create_qp_v1;
- context->ibv_ctx.ops.destroy_qp = hfi1_destroy_qp_v1;
- context->ibv_ctx.ops.post_recv = ibv_cmd_post_recv;
+ context->ibv_ctx.context.ops.create_cq = hfi1_create_cq_v1;
+ context->ibv_ctx.context.ops.poll_cq = ibv_cmd_poll_cq;
+ context->ibv_ctx.context.ops.resize_cq = hfi1_resize_cq_v1;
+ context->ibv_ctx.context.ops.destroy_cq = hfi1_destroy_cq_v1;
+ context->ibv_ctx.context.ops.create_srq = hfi1_create_srq_v1;
+ context->ibv_ctx.context.ops.destroy_srq = hfi1_destroy_srq_v1;
+ context->ibv_ctx.context.ops.modify_srq = hfi1_modify_srq_v1;
+ context->ibv_ctx.context.ops.post_srq_recv =
+ ibv_cmd_post_srq_recv;
+ context->ibv_ctx.context.ops.create_qp = hfi1_create_qp_v1;
+ context->ibv_ctx.context.ops.destroy_qp = hfi1_destroy_qp_v1;
+ context->ibv_ctx.context.ops.post_recv = ibv_cmd_post_recv;
}
return &context->ibv_ctx;
err_free:
+ verbs_uninit_context(&context->ibv_ctx);
free(context);
return NULL;
}
@@ -166,6 +167,7 @@ static void hfi1_free_context(struct ibv_context *ibctx)
{
struct hfi1_context *context = to_ictx(ibctx);
+ verbs_uninit_context(&context->ibv_ctx);
free(context);
}
diff --git a/providers/hfi1verbs/hfiverbs.h b/providers/hfi1verbs/hfiverbs.h
index e672dda4982527..e7a05a0c0a83db 100644
--- a/providers/hfi1verbs/hfiverbs.h
+++ b/providers/hfi1verbs/hfiverbs.h
@@ -74,7 +74,7 @@ struct hfi1_device {
};
struct hfi1_context {
- struct ibv_context ibv_ctx;
+ struct verbs_context ibv_ctx;
};
/*
@@ -158,7 +158,7 @@ struct hfi1_srq {
static inline struct hfi1_context *to_ictx(struct ibv_context *ibctx)
{
- return to_ixxx(ctx, context);
+ return container_of(ibctx, struct hfi1_context, ibv_ctx.context);
}
static inline struct hfi1_device *to_idev(struct ibv_device *ibdev)
diff --git a/providers/hns/hns_roce_u.c b/providers/hns/hns_roce_u.c
index 489b71614614fe..781825b3782044 100644
--- a/providers/hns/hns_roce_u.c
+++ b/providers/hns/hns_roce_u.c
@@ -61,8 +61,8 @@ static const struct verbs_match_ent hca_table[] = {
{}
};
-static struct ibv_context *hns_roce_alloc_context(struct ibv_device *ibdev,
- int cmd_fd)
+static struct verbs_context *hns_roce_alloc_context(struct ibv_device *ibdev,
+ int cmd_fd)
{
int i;
struct ibv_get_context cmd;
@@ -71,11 +71,10 @@ static struct ibv_context *hns_roce_alloc_context(struct ibv_device *ibdev,
struct hns_roce_alloc_ucontext_resp resp;
struct hns_roce_device *hr_dev = to_hr_dev(ibdev);
- context = calloc(1, sizeof(*context));
+ context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx);
if (!context)
return NULL;
- context->ibv_ctx.cmd_fd = cmd_fd;
if (ibv_cmd_get_context(&context->ibv_ctx, &cmd, sizeof(cmd),
&resp.ibv_resp, sizeof(resp)))
goto err_free;
@@ -113,28 +112,28 @@ static struct ibv_context *hns_roce_alloc_context(struct ibv_device *ibdev,
pthread_spin_init(&context->uar_lock, PTHREAD_PROCESS_PRIVATE);
- 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.rereg_mr = hns_roce_u_rereg_mr;
- context->ibv_ctx.ops.dereg_mr = hns_roce_u_dereg_mr;
-
- context->ibv_ctx.ops.create_cq = hns_roce_u_create_cq;
- context->ibv_ctx.ops.poll_cq = hr_dev->u_hw->poll_cq;
- context->ibv_ctx.ops.req_notify_cq = hr_dev->u_hw->arm_cq;
- context->ibv_ctx.ops.cq_event = hns_roce_u_cq_event;
- context->ibv_ctx.ops.destroy_cq = hns_roce_u_destroy_cq;
-
- context->ibv_ctx.ops.create_qp = hns_roce_u_create_qp;
- context->ibv_ctx.ops.query_qp = hns_roce_u_query_qp;
- context->ibv_ctx.ops.modify_qp = hr_dev->u_hw->modify_qp;
- context->ibv_ctx.ops.destroy_qp = hr_dev->u_hw->destroy_qp;
- context->ibv_ctx.ops.post_send = hr_dev->u_hw->post_send;
- context->ibv_ctx.ops.post_recv = hr_dev->u_hw->post_recv;
-
- if (hns_roce_u_query_device(&context->ibv_ctx, &dev_attrs))
+ context->ibv_ctx.context.ops.query_device = hns_roce_u_query_device;
+ context->ibv_ctx.context.ops.query_port = hns_roce_u_query_port;
+ context->ibv_ctx.context.ops.alloc_pd = hns_roce_u_alloc_pd;
+ context->ibv_ctx.context.ops.dealloc_pd = hns_roce_u_free_pd;
+ context->ibv_ctx.context.ops.reg_mr = hns_roce_u_reg_mr;
+ context->ibv_ctx.context.ops.rereg_mr = hns_roce_u_rereg_mr;
+ context->ibv_ctx.context.ops.dereg_mr = hns_roce_u_dereg_mr;
+
+ context->ibv_ctx.context.ops.create_cq = hns_roce_u_create_cq;
+ context->ibv_ctx.context.ops.poll_cq = hr_dev->u_hw->poll_cq;
+ context->ibv_ctx.context.ops.req_notify_cq = hr_dev->u_hw->arm_cq;
+ context->ibv_ctx.context.ops.cq_event = hns_roce_u_cq_event;
+ context->ibv_ctx.context.ops.destroy_cq = hns_roce_u_destroy_cq;
+
+ context->ibv_ctx.context.ops.create_qp = hns_roce_u_create_qp;
+ context->ibv_ctx.context.ops.query_qp = hns_roce_u_query_qp;
+ context->ibv_ctx.context.ops.modify_qp = hr_dev->u_hw->modify_qp;
+ context->ibv_ctx.context.ops.destroy_qp = hr_dev->u_hw->destroy_qp;
+ context->ibv_ctx.context.ops.post_send = hr_dev->u_hw->post_send;
+ context->ibv_ctx.context.ops.post_recv = hr_dev->u_hw->post_recv;
+
+ if (hns_roce_u_query_device(&context->ibv_ctx.context, &dev_attrs))
goto tptr_free;
context->max_qp_wr = dev_attrs.max_qp_wr;
@@ -155,6 +154,7 @@ db_free:
context->uar = NULL;
err_free:
+ verbs_uninit_context(&context->ibv_ctx);
free(context);
return NULL;
}
@@ -167,6 +167,7 @@ static void hns_roce_free_context(struct ibv_context *ibctx)
if (to_hr_dev(ibctx->device)->hw_version == HNS_ROCE_HW_VER1)
munmap(context->cq_tptr_base, HNS_ROCE_CQ_DB_BUF_SIZE);
+ verbs_uninit_context(&context->ibv_ctx);
free(context);
}
diff --git a/providers/hns/hns_roce_u.h b/providers/hns/hns_roce_u.h
index 101320b1f8f3ad..02912468e68a65 100644
--- a/providers/hns/hns_roce_u.h
+++ b/providers/hns/hns_roce_u.h
@@ -94,7 +94,7 @@ struct hns_roce_buf {
};
struct hns_roce_context {
- struct ibv_context ibv_ctx;
+ struct verbs_context ibv_ctx;
void *uar;
pthread_spinlock_t uar_lock;
@@ -221,7 +221,7 @@ static inline struct hns_roce_device *to_hr_dev(struct ibv_device *ibv_dev)
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);
+ return container_of(ibv_ctx, struct hns_roce_context, ibv_ctx.context);
}
static inline struct hns_roce_pd *to_hr_pd(struct ibv_pd *ibv_pd)
diff --git a/providers/hns/hns_roce_u_verbs.c b/providers/hns/hns_roce_u_verbs.c
index 046f0a4b849712..3def78d25a9a71 100644
--- a/providers/hns/hns_roce_u_verbs.c
+++ b/providers/hns/hns_roce_u_verbs.c
@@ -208,7 +208,8 @@ static void hns_roce_set_sq_sizes(struct hns_roce_qp *qp,
static int hns_roce_verify_cq(int *cqe, struct hns_roce_context *context)
{
- struct hns_roce_device *hr_dev = to_hr_dev(context->ibv_ctx.device);
+ struct hns_roce_device *hr_dev =
+ to_hr_dev(context->ibv_ctx.context.device);
if (hr_dev->hw_version == HNS_ROCE_HW_VER1)
if (*cqe < HNS_ROCE_MIN_CQE_NUM) {
@@ -328,7 +329,8 @@ int hns_roce_u_destroy_cq(struct ibv_cq *cq)
static int hns_roce_verify_qp(struct ibv_qp_init_attr *attr,
struct hns_roce_context *context)
{
- struct hns_roce_device *hr_dev = to_hr_dev(context->ibv_ctx.device);
+ struct hns_roce_device *hr_dev =
+ to_hr_dev(context->ibv_ctx.context.device);
if (hr_dev->hw_version == HNS_ROCE_HW_VER1) {
if (attr->cap.max_send_wr < HNS_ROCE_MIN_WQE_NUM) {
diff --git a/providers/i40iw/i40iw_umain.c b/providers/i40iw/i40iw_umain.c
index 77c1ced812499b..6ec40895efcfe0 100644
--- a/providers/i40iw/i40iw_umain.c
+++ b/providers/i40iw/i40iw_umain.c
@@ -131,19 +131,18 @@ static struct ibv_context_ops i40iw_uctx_ops = {
* context and getting back resource information to return as ibv_context.
*/
-static struct ibv_context *i40iw_ualloc_context(struct ibv_device *ibdev, int cmd_fd)
+static struct verbs_context *i40iw_ualloc_context(struct ibv_device *ibdev,
+ int cmd_fd)
{
struct ibv_pd *ibv_pd;
struct i40iw_uvcontext *iwvctx;
struct i40iw_get_context cmd;
struct i40iw_ualloc_ucontext_resp resp;
- iwvctx = malloc(sizeof(*iwvctx));
+ iwvctx = verbs_init_and_alloc_context(ibdev, cmd_fd, iwvctx, ibv_ctx);
if (!iwvctx)
return NULL;
- memset(iwvctx, 0, sizeof(*iwvctx));
- iwvctx->ibv_ctx.cmd_fd = cmd_fd;
cmd.userspace_ver = I40IW_ABI_VER;
memset(&resp, 0, sizeof(resp));
if (ibv_cmd_get_context(&iwvctx->ibv_ctx, (struct ibv_get_context *)&cmd,
@@ -162,24 +161,24 @@ static struct ibv_context *i40iw_ualloc_context(struct ibv_device *ibdev, int cm
goto err_free;
}
- iwvctx->ibv_ctx.device = ibdev;
- iwvctx->ibv_ctx.ops = i40iw_uctx_ops;
+ iwvctx->ibv_ctx.context.ops = i40iw_uctx_ops;
iwvctx->max_pds = resp.max_pds;
iwvctx->max_qps = resp.max_qps;
iwvctx->wq_size = resp.wq_size;
iwvctx->abi_ver = resp.kernel_ver;
i40iw_device_init_uk(&iwvctx->dev);
- ibv_pd = i40iw_ualloc_pd(&iwvctx->ibv_ctx);
+ ibv_pd = i40iw_ualloc_pd(&iwvctx->ibv_ctx.context);
if (!ibv_pd)
goto err_free;
- ibv_pd->context = &iwvctx->ibv_ctx;
+ ibv_pd->context = &iwvctx->ibv_ctx.context;
iwvctx->iwupd = to_i40iw_upd(ibv_pd);
return &iwvctx->ibv_ctx;
err_free:
fprintf(stderr, PFX "%s: failed to allocate context for device.\n", __func__);
+ verbs_uninit_context(&iwvctx->ibv_ctx);
free(iwvctx);
return NULL;
@@ -195,6 +194,7 @@ static void i40iw_ufree_context(struct ibv_context *ibctx)
i40iw_ufree_pd(&iwvctx->iwupd->ibv_pd);
+ verbs_uninit_context(&iwvctx->ibv_ctx);
free(iwvctx);
}
diff --git a/providers/i40iw/i40iw_umain.h b/providers/i40iw/i40iw_umain.h
index 109aba6bd92ef4..a2f4fa8f6b6bd9 100644
--- a/providers/i40iw/i40iw_umain.h
+++ b/providers/i40iw/i40iw_umain.h
@@ -83,7 +83,7 @@ struct i40iw_upd {
};
struct i40iw_uvcontext {
- struct ibv_context ibv_ctx;
+ struct verbs_context ibv_ctx;
struct i40iw_upd *iwupd;
uint32_t max_pds; /* maximum pds allowed for this user process */
uint32_t max_qps; /* maximum qps allowed for this user process */
@@ -137,7 +137,7 @@ static inline struct i40iw_udevice *to_i40iw_udev(struct ibv_device *ibdev)
static inline struct i40iw_uvcontext *to_i40iw_uctx(struct ibv_context *ibctx)
{
- return to_i40iw_uxxx(ctx, vcontext);
+ return container_of(ibctx, struct i40iw_uvcontext, ibv_ctx.context);
}
static inline struct i40iw_upd *to_i40iw_upd(struct ibv_pd *ibpd)
diff --git a/providers/ipathverbs/ipathverbs.c b/providers/ipathverbs/ipathverbs.c
index 449abb0489955a..3f7f170ed6b986 100644
--- a/providers/ipathverbs/ipathverbs.c
+++ b/providers/ipathverbs/ipathverbs.c
@@ -122,41 +122,42 @@ static struct ibv_context_ops ipath_ctx_ops = {
.detach_mcast = ibv_cmd_detach_mcast
};
-static struct ibv_context *ipath_alloc_context(struct ibv_device *ibdev,
- int cmd_fd)
+static struct verbs_context *ipath_alloc_context(struct ibv_device *ibdev,
+ int cmd_fd)
{
struct ipath_context *context;
struct ibv_get_context cmd;
struct ibv_get_context_resp resp;
struct ipath_device *dev;
- context = malloc(sizeof *context);
+ context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx);
if (!context)
return NULL;
- memset(context, 0, sizeof *context);
- context->ibv_ctx.cmd_fd = cmd_fd;
+
if (ibv_cmd_get_context(&context->ibv_ctx, &cmd,
sizeof cmd, &resp, sizeof resp))
goto err_free;
- context->ibv_ctx.ops = ipath_ctx_ops;
+ context->ibv_ctx.context.ops = ipath_ctx_ops;
dev = to_idev(ibdev);
if (dev->abi_version == 1) {
- context->ibv_ctx.ops.create_cq = ipath_create_cq_v1;
- context->ibv_ctx.ops.poll_cq = ibv_cmd_poll_cq;
- context->ibv_ctx.ops.resize_cq = ipath_resize_cq_v1;
- context->ibv_ctx.ops.destroy_cq = ipath_destroy_cq_v1;
- context->ibv_ctx.ops.create_srq = ipath_create_srq_v1;
- context->ibv_ctx.ops.destroy_srq = ipath_destroy_srq_v1;
- context->ibv_ctx.ops.modify_srq = ipath_modify_srq_v1;
- context->ibv_ctx.ops.post_srq_recv = ibv_cmd_post_srq_recv;
- context->ibv_ctx.ops.create_qp = ipath_create_qp_v1;
- context->ibv_ctx.ops.destroy_qp = ipath_destroy_qp_v1;
- context->ibv_ctx.ops.post_recv = ibv_cmd_post_recv;
+ context->ibv_ctx.context.ops.create_cq = ipath_create_cq_v1;
+ context->ibv_ctx.context.ops.poll_cq = ibv_cmd_poll_cq;
+ context->ibv_ctx.context.ops.resize_cq = ipath_resize_cq_v1;
+ context->ibv_ctx.context.ops.destroy_cq = ipath_destroy_cq_v1;
+ context->ibv_ctx.context.ops.create_srq = ipath_create_srq_v1;
+ context->ibv_ctx.context.ops.destroy_srq = ipath_destroy_srq_v1;
+ context->ibv_ctx.context.ops.modify_srq = ipath_modify_srq_v1;
+ context->ibv_ctx.context.ops.post_srq_recv =
+ ibv_cmd_post_srq_recv;
+ context->ibv_ctx.context.ops.create_qp = ipath_create_qp_v1;
+ context->ibv_ctx.context.ops.destroy_qp = ipath_destroy_qp_v1;
+ context->ibv_ctx.context.ops.post_recv = ibv_cmd_post_recv;
}
return &context->ibv_ctx;
err_free:
+ verbs_uninit_context(&context->ibv_ctx);
free(context);
return NULL;
}
@@ -165,6 +166,7 @@ static void ipath_free_context(struct ibv_context *ibctx)
{
struct ipath_context *context = to_ictx(ibctx);
+ verbs_uninit_context(&context->ibv_ctx);
free(context);
}
diff --git a/providers/ipathverbs/ipathverbs.h b/providers/ipathverbs/ipathverbs.h
index 5f2658e7942c8b..d26a2a1b29009e 100644
--- a/providers/ipathverbs/ipathverbs.h
+++ b/providers/ipathverbs/ipathverbs.h
@@ -54,7 +54,7 @@ struct ipath_device {
};
struct ipath_context {
- struct ibv_context ibv_ctx;
+ struct verbs_context ibv_ctx;
};
/*
@@ -137,7 +137,7 @@ struct ipath_srq {
static inline struct ipath_context *to_ictx(struct ibv_context *ibctx)
{
- return to_ixxx(ctx, context);
+ return container_of(ibctx, struct ipath_context, ibv_ctx.context);
}
static inline struct ipath_device *to_idev(struct ibv_device *ibdev)
diff --git a/providers/mlx4/mlx4.c b/providers/mlx4/mlx4.c
index d2ccd328625c80..56bf1298b48734 100644
--- a/providers/mlx4/mlx4.c
+++ b/providers/mlx4/mlx4.c
@@ -167,16 +167,16 @@ static int mlx4_init_context(struct verbs_device *v_device,
mlx4_read_env();
if (dev->abi_version <= MLX4_UVERBS_NO_DEV_CAPS_ABI_VERSION) {
- if (ibv_cmd_get_context(ibv_ctx, &cmd, sizeof cmd,
- &resp_v3.ibv_resp, sizeof resp_v3))
+ if (ibv_cmd_get_context(verbs_ctx, &cmd, sizeof(cmd),
+ &resp_v3.ibv_resp, sizeof(resp_v3)))
return errno;
context->num_qps = resp_v3.qp_tab_size;
bf_reg_size = resp_v3.bf_reg_size;
context->cqe_size = sizeof (struct mlx4_cqe);
} else {
- if (ibv_cmd_get_context(ibv_ctx, &cmd, sizeof cmd,
- &resp.ibv_resp, sizeof resp))
+ if (ibv_cmd_get_context(verbs_ctx, &cmd, sizeof(cmd),
+ &resp.ibv_resp, sizeof(resp)))
return errno;
context->num_qps = resp.qp_tab_size;
diff --git a/providers/mlx5/mlx5.c b/providers/mlx5/mlx5.c
index 36486218e31d81..a829cd5eb26473 100644
--- a/providers/mlx5/mlx5.c
+++ b/providers/mlx5/mlx5.c
@@ -549,7 +549,9 @@ static int mlx5_cmd_get_context(struct mlx5_context *context,
struct mlx5_alloc_ucontext_resp *resp,
size_t resp_len)
{
- if (!ibv_cmd_get_context(&context->ibv_ctx, &req->ibv_req,
+ struct verbs_context *verbs_ctx = verbs_get_ctx(&context->ibv_ctx);
+
+ if (!ibv_cmd_get_context(verbs_ctx, &req->ibv_req,
req_len, &resp->ibv_resp, resp_len))
return 0;
@@ -572,12 +574,12 @@ static int mlx5_cmd_get_context(struct mlx5_context *context,
* to do so. If zero is a valid response, we will add a new
* field that indicates whether the request was handled.
*/
- if (!ibv_cmd_get_context(&context->ibv_ctx, &req->ibv_req,
+ if (!ibv_cmd_get_context(verbs_ctx, &req->ibv_req,
offsetof(struct mlx5_alloc_ucontext, lib_caps),
&resp->ibv_resp, resp_len))
return 0;
- return ibv_cmd_get_context(&context->ibv_ctx, &req->ibv_req,
+ return ibv_cmd_get_context(verbs_ctx, &req->ibv_req,
offsetof(struct mlx5_alloc_ucontext,
cqe_version),
&resp->ibv_resp, resp_len);
diff --git a/providers/mthca/mthca.c b/providers/mthca/mthca.c
index 511b8d5139af9c..15827391986d3a 100644
--- a/providers/mthca/mthca.c
+++ b/providers/mthca/mthca.c
@@ -114,19 +114,18 @@ static struct ibv_context_ops mthca_ctx_ops = {
.detach_mcast = ibv_cmd_detach_mcast
};
-static struct ibv_context *mthca_alloc_context(struct ibv_device *ibdev, int cmd_fd)
+static struct verbs_context *mthca_alloc_context(struct ibv_device *ibdev,
+ int cmd_fd)
{
struct mthca_context *context;
struct ibv_get_context cmd;
struct mthca_alloc_ucontext_resp resp;
int i;
- context = calloc(1, sizeof *context);
+ context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx);
if (!context)
return NULL;
- context->ibv_ctx.cmd_fd = cmd_fd;
-
if (ibv_cmd_get_context(&context->ibv_ctx, &cmd, sizeof cmd,
&resp.ibv_resp, sizeof resp))
goto err_free;
@@ -135,13 +134,7 @@ static struct ibv_context *mthca_alloc_context(struct ibv_device *ibdev, int cmd
context->qp_table_shift = ffs(context->num_qps) - 1 - MTHCA_QP_TABLE_BITS;
context->qp_table_mask = (1 << context->qp_table_shift) - 1;
- /*
- * Need to set ibv_ctx.device because mthca_is_memfree() will
- * look at it to figure out the HCA type.
- */
- context->ibv_ctx.device = ibdev;
-
- if (mthca_is_memfree(&context->ibv_ctx)) {
+ if (mthca_is_memfree(&context->ibv_ctx.context)) {
context->db_tab = mthca_alloc_db_tab(resp.uarc_size);
if (!context->db_tab)
goto err_free;
@@ -159,26 +152,28 @@ static struct ibv_context *mthca_alloc_context(struct ibv_device *ibdev, int cmd
pthread_spin_init(&context->uar_lock, PTHREAD_PROCESS_PRIVATE);
- context->pd = mthca_alloc_pd(&context->ibv_ctx);
+ context->pd = mthca_alloc_pd(&context->ibv_ctx.context);
if (!context->pd)
goto err_unmap;
- context->pd->context = &context->ibv_ctx;
+ context->pd->context = &context->ibv_ctx.context;
- context->ibv_ctx.ops = mthca_ctx_ops;
+ context->ibv_ctx.context.ops = mthca_ctx_ops;
- if (mthca_is_memfree(&context->ibv_ctx)) {
- context->ibv_ctx.ops.req_notify_cq = mthca_arbel_arm_cq;
- context->ibv_ctx.ops.cq_event = mthca_arbel_cq_event;
- context->ibv_ctx.ops.post_send = mthca_arbel_post_send;
- context->ibv_ctx.ops.post_recv = mthca_arbel_post_recv;
- context->ibv_ctx.ops.post_srq_recv = mthca_arbel_post_srq_recv;
+ if (mthca_is_memfree(&context->ibv_ctx.context)) {
+ context->ibv_ctx.context.ops.req_notify_cq = mthca_arbel_arm_cq;
+ context->ibv_ctx.context.ops.cq_event = mthca_arbel_cq_event;
+ context->ibv_ctx.context.ops.post_send = mthca_arbel_post_send;
+ context->ibv_ctx.context.ops.post_recv = mthca_arbel_post_recv;
+ context->ibv_ctx.context.ops.post_srq_recv =
+ mthca_arbel_post_srq_recv;
} else {
- context->ibv_ctx.ops.req_notify_cq = mthca_tavor_arm_cq;
- context->ibv_ctx.ops.cq_event = NULL;
- context->ibv_ctx.ops.post_send = mthca_tavor_post_send;
- context->ibv_ctx.ops.post_recv = mthca_tavor_post_recv;
- context->ibv_ctx.ops.post_srq_recv = mthca_tavor_post_srq_recv;
+ context->ibv_ctx.context.ops.req_notify_cq = mthca_tavor_arm_cq;
+ context->ibv_ctx.context.ops.cq_event = NULL;
+ context->ibv_ctx.context.ops.post_send = mthca_tavor_post_send;
+ context->ibv_ctx.context.ops.post_recv = mthca_tavor_post_recv;
+ context->ibv_ctx.context.ops.post_srq_recv =
+ mthca_tavor_post_srq_recv;
}
return &context->ibv_ctx;
@@ -190,6 +185,7 @@ err_db_tab:
mthca_free_db_tab(context->db_tab);
err_free:
+ verbs_uninit_context(&context->ibv_ctx);
free(context);
return NULL;
}
@@ -201,6 +197,8 @@ static void mthca_free_context(struct ibv_context *ibctx)
mthca_free_pd(context->pd);
munmap(context->uar, to_mdev(ibctx->device)->page_size);
mthca_free_db_tab(context->db_tab);
+
+ verbs_uninit_context(&context->ibv_ctx);
free(context);
}
diff --git a/providers/mthca/mthca.h b/providers/mthca/mthca.h
index a67acf46c7c56d..d788f7613b439c 100644
--- a/providers/mthca/mthca.h
+++ b/providers/mthca/mthca.h
@@ -97,7 +97,7 @@ struct mthca_device {
struct mthca_db_table;
struct mthca_context {
- struct ibv_context ibv_ctx;
+ struct verbs_context ibv_ctx;
void *uar;
pthread_spinlock_t uar_lock;
struct mthca_db_table *db_tab;
@@ -229,7 +229,7 @@ static inline struct mthca_device *to_mdev(struct ibv_device *ibdev)
static inline struct mthca_context *to_mctx(struct ibv_context *ibctx)
{
- return to_mxxx(ctx, context);
+ return container_of(ibctx, struct mthca_context, ibv_ctx.context);
}
static inline struct mthca_pd *to_mpd(struct ibv_pd *ibpd)
diff --git a/providers/nes/nes_umain.c b/providers/nes/nes_umain.c
index bd0b6ac68cec40..a5ae678ecfe11c 100644
--- a/providers/nes/nes_umain.c
+++ b/providers/nes/nes_umain.c
@@ -98,7 +98,8 @@ static struct ibv_context_ops nes_uctx_ops = {
/**
* nes_ualloc_context
*/
-static struct ibv_context *nes_ualloc_context(struct ibv_device *ibdev, int cmd_fd)
+static struct verbs_context *nes_ualloc_context(struct ibv_device *ibdev,
+ int cmd_fd)
{
struct ibv_pd *ibv_pd;
struct nes_uvcontext *nesvctx;
@@ -109,16 +110,14 @@ static struct ibv_context *nes_ualloc_context(struct ibv_device *ibdev, int cmd_
page_size = sysconf(_SC_PAGESIZE);
- nesvctx = malloc(sizeof *nesvctx);
+ nesvctx = verbs_init_and_alloc_context(ibdev, cmd_fd, nesvctx, ibv_ctx);
if (!nesvctx)
return NULL;
- memset(nesvctx, 0, sizeof *nesvctx);
- nesvctx->ibv_ctx.cmd_fd = cmd_fd;
cmd.userspace_ver = NES_ABI_USERSPACE_VER;
if (ibv_cmd_get_context(&nesvctx->ibv_ctx, (struct ibv_get_context *)&cmd, sizeof cmd,
- &resp.ibv_resp, sizeof(resp)))
+ &resp.ibv_resp, sizeof(resp)))
goto err_free;
if (resp.kernel_ver != NES_ABI_KERNEL_VER) {
@@ -135,12 +134,10 @@ static struct ibv_context *nes_ualloc_context(struct ibv_device *ibdev, int cmd_
sscanf(value, "%d", &nes_drv_opt);
}
- nesvctx->ibv_ctx.device = ibdev;
-
if (nes_drv_opt & NES_DRV_OPT_NO_DB_READ)
nes_uctx_ops.poll_cq = nes_upoll_cq_no_db_read;
- nesvctx->ibv_ctx.ops = nes_uctx_ops;
+ nesvctx->ibv_ctx.context.ops = nes_uctx_ops;
nesvctx->max_pds = resp.max_pds;
nesvctx->max_qps = resp.max_qps;
nesvctx->wq_size = resp.wq_size;
@@ -148,16 +145,17 @@ static struct ibv_context *nes_ualloc_context(struct ibv_device *ibdev, int cmd_
nesvctx->mcrqf = 0;
/* Get a doorbell region for the CQs */
- ibv_pd = nes_ualloc_pd(&nesvctx->ibv_ctx);
+ ibv_pd = nes_ualloc_pd(&nesvctx->ibv_ctx.context);
if (!ibv_pd)
goto err_free;
- ibv_pd->context = &nesvctx->ibv_ctx;
+ ibv_pd->context = &nesvctx->ibv_ctx.context;
nesvctx->nesupd = to_nes_upd(ibv_pd);
return &nesvctx->ibv_ctx;
err_free:
fprintf(stderr, PFX "%s: Failed to allocate context for device.\n", __FUNCTION__);
+ verbs_uninit_context(&nesvctx->ibv_ctx);
free(nesvctx);
return NULL;
@@ -172,6 +170,7 @@ static void nes_ufree_context(struct ibv_context *ibctx)
struct nes_uvcontext *nesvctx = to_nes_uctx(ibctx);
nes_ufree_pd(&nesvctx->nesupd->ibv_pd);
+ verbs_uninit_context(&nesvctx->ibv_ctx);
free(nesvctx);
}
diff --git a/providers/nes/nes_umain.h b/providers/nes/nes_umain.h
index 0a832e7517bea6..2750c128d76ce7 100644
--- a/providers/nes/nes_umain.h
+++ b/providers/nes/nes_umain.h
@@ -261,7 +261,7 @@ struct nes_upd {
};
struct nes_uvcontext {
- struct ibv_context ibv_ctx;
+ struct verbs_context ibv_ctx;
struct nes_upd *nesupd;
uint32_t max_pds; /* maximum pds allowed for this user process */
uint32_t max_qps; /* maximum qps allowed for this user process */
@@ -331,7 +331,7 @@ static inline struct nes_udevice *to_nes_udev(struct ibv_device *ibdev)
static inline struct nes_uvcontext *to_nes_uctx(struct ibv_context *ibctx)
{
- return to_nes_uxxx(ctx, vcontext);
+ return container_of(ibctx, struct nes_uvcontext, ibv_ctx.context);
}
static inline struct nes_upd *to_nes_upd(struct ibv_pd *ibpd)
diff --git a/providers/ocrdma/ocrdma_main.c b/providers/ocrdma/ocrdma_main.c
index afd5d79c1884c0..5bb17eb8665bfc 100644
--- a/providers/ocrdma/ocrdma_main.c
+++ b/providers/ocrdma/ocrdma_main.c
@@ -105,27 +105,23 @@ static void ocrdma_uninit_device(struct verbs_device *verbs_device)
/*
* ocrdma_alloc_context
*/
-static struct ibv_context *ocrdma_alloc_context(struct ibv_device *ibdev,
- int cmd_fd)
+static struct verbs_context *ocrdma_alloc_context(struct ibv_device *ibdev,
+ int cmd_fd)
{
struct ocrdma_devctx *ctx;
struct ocrdma_get_context cmd;
struct ocrdma_alloc_ucontext_resp resp;
- ctx = calloc(1, sizeof(struct ocrdma_devctx));
+ ctx = verbs_init_and_alloc_context(ibdev, cmd_fd, ctx, ibv_ctx);
if (!ctx)
return NULL;
- memset(&resp, 0, sizeof(resp));
-
- ctx->ibv_ctx.cmd_fd = cmd_fd;
if (ibv_cmd_get_context(&ctx->ibv_ctx,
(struct ibv_get_context *)&cmd, sizeof cmd,
&resp.ibv_resp, sizeof(resp)))
goto cmd_err;
- ctx->ibv_ctx.device = ibdev;
- ctx->ibv_ctx.ops = ocrdma_ctx_ops;
+ ctx->ibv_ctx.context.ops = ocrdma_ctx_ops;
get_ocrdma_dev(ibdev)->id = resp.dev_id;
get_ocrdma_dev(ibdev)->max_inline_data = resp.max_inline_data;
get_ocrdma_dev(ibdev)->wqe_size = resp.wqe_size;
@@ -146,6 +142,7 @@ static struct ibv_context *ocrdma_alloc_context(struct ibv_device *ibdev,
cmd_err:
ocrdma_err("%s: Failed to allocate context for device.\n", __func__);
+ verbs_uninit_context(&ctx->ibv_ctx);
free(ctx);
return NULL;
}
@@ -160,6 +157,7 @@ static void ocrdma_free_context(struct ibv_context *ibctx)
if (ctx->ah_tbl)
munmap((void *)ctx->ah_tbl, ctx->ah_tbl_len);
+ verbs_uninit_context(&ctx->ibv_ctx);
free(ctx);
}
diff --git a/providers/ocrdma/ocrdma_main.h b/providers/ocrdma/ocrdma_main.h
index e5b2860f9dc45c..e414223d07cd83 100644
--- a/providers/ocrdma/ocrdma_main.h
+++ b/providers/ocrdma/ocrdma_main.h
@@ -68,7 +68,7 @@ struct ocrdma_device {
};
struct ocrdma_devctx {
- struct ibv_context ibv_ctx;
+ struct verbs_context ibv_ctx;
uint32_t *ah_tbl;
uint32_t ah_tbl_len;
pthread_mutex_t tbl_lock;
@@ -231,7 +231,7 @@ struct ocrdma_ah {
static inline struct ocrdma_devctx *get_ocrdma_ctx(struct ibv_context *ibctx)
{
- return get_ocrdma_xxx(ctx, devctx);
+ return container_of(ibctx, struct ocrdma_devctx, ibv_ctx.context);
}
static inline struct ocrdma_device *get_ocrdma_dev(struct ibv_device *ibdev)
diff --git a/providers/qedr/qelr.h b/providers/qedr/qelr.h
index b3faa0044137d8..faa8e99cfa0798 100644
--- a/providers/qedr/qelr.h
+++ b/providers/qedr/qelr.h
@@ -118,7 +118,7 @@ struct qelr_device {
};
struct qelr_devctx {
- struct ibv_context ibv_ctx;
+ struct verbs_context ibv_ctx;
FILE *dbg_fp;
void *db_addr;
uint64_t db_pa;
@@ -251,7 +251,7 @@ struct qelr_qp {
static inline struct qelr_devctx *get_qelr_ctx(struct ibv_context *ibctx)
{
- return container_of(ibctx, struct qelr_devctx, ibv_ctx);
+ return container_of(ibctx, struct qelr_devctx, ibv_ctx.context);
}
static inline struct qelr_device *get_qelr_dev(struct ibv_device *ibdev)
diff --git a/providers/qedr/qelr_main.c b/providers/qedr/qelr_main.c
index 4d62442a58dcb7..92a635cdcfca94 100644
--- a/providers/qedr/qelr_main.c
+++ b/providers/qedr/qelr_main.c
@@ -155,19 +155,18 @@ static void qelr_set_debug_mask(void)
qelr_dp_module = atoi(env);
}
-static struct ibv_context *qelr_alloc_context(struct ibv_device *ibdev,
- int cmd_fd)
+static struct verbs_context *qelr_alloc_context(struct ibv_device *ibdev,
+ int cmd_fd)
{
struct qelr_devctx *ctx;
struct qelr_get_context cmd;
struct qelr_alloc_ucontext_resp resp;
- ctx = calloc(1, sizeof(struct qelr_devctx));
+ ctx = verbs_init_and_alloc_context(ibdev, cmd_fd, ctx, ibv_ctx);
if (!ctx)
return NULL;
- memset(&resp, 0, sizeof(resp));
- ctx->ibv_ctx.cmd_fd = cmd_fd;
+ memset(&resp, 0, sizeof(resp));
qelr_open_debug_file(ctx);
qelr_set_debug_mask();
@@ -178,8 +177,7 @@ static struct ibv_context *qelr_alloc_context(struct ibv_device *ibdev,
goto cmd_err;
ctx->kernel_page_size = sysconf(_SC_PAGESIZE);
- ctx->ibv_ctx.device = ibdev;
- ctx->ibv_ctx.ops = qelr_ctx_ops;
+ ctx->ibv_ctx.context.ops = qelr_ctx_ops;
ctx->db_pa = resp.db_pa;
ctx->db_size = resp.db_size;
ctx->max_send_wr = resp.max_send_wr;
@@ -205,6 +203,7 @@ static struct ibv_context *qelr_alloc_context(struct ibv_device *ibdev,
cmd_err:
qelr_err("%s: Failed to allocate context for device.\n", __func__);
qelr_close_debug_file(ctx);
+ verbs_uninit_context(&ctx->ibv_ctx);
free(ctx);
return NULL;
}
@@ -217,6 +216,7 @@ static void qelr_free_context(struct ibv_context *ibctx)
munmap(ctx->db_addr, ctx->db_size);
qelr_close_debug_file(ctx);
+ verbs_uninit_context(&ctx->ibv_ctx);
free(ctx);
}
diff --git a/providers/qedr/qelr_verbs.c b/providers/qedr/qelr_verbs.c
index 7db0fb3216dde9..5d7aeb37453c44 100644
--- a/providers/qedr/qelr_verbs.c
+++ b/providers/qedr/qelr_verbs.c
@@ -887,7 +887,7 @@ static inline void qelr_init_dpm_info(struct qelr_devctx *cxt,
dpm->is_edpm = 0;
/* Currently dpm is not supported for iWARP */
- if (IS_IWARP(cxt->ibv_ctx.device))
+ if (IS_IWARP(cxt->ibv_ctx.context.device))
return;
if (qelr_chain_is_full(&qp->sq.chain) &&
diff --git a/providers/rxe/rxe.c b/providers/rxe/rxe.c
index 683ffaa2a8af9c..5cfdf1aac08a86 100644
--- a/providers/rxe/rxe.c
+++ b/providers/rxe/rxe.c
@@ -858,29 +858,27 @@ static struct ibv_context_ops rxe_ctx_ops = {
.detach_mcast = ibv_cmd_detach_mcast
};
-static struct ibv_context *rxe_alloc_context(struct ibv_device *ibdev,
- int cmd_fd)
+static struct verbs_context *rxe_alloc_context(struct ibv_device *ibdev,
+ int cmd_fd)
{
struct rxe_context *context;
struct ibv_get_context cmd;
struct ibv_get_context_resp resp;
- context = malloc(sizeof *context);
+ context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx);
if (!context)
return NULL;
- memset(context, 0, sizeof *context);
- context->ibv_ctx.cmd_fd = cmd_fd;
-
if (ibv_cmd_get_context(&context->ibv_ctx, &cmd,
sizeof cmd, &resp, sizeof resp))
goto out;
- context->ibv_ctx.ops = rxe_ctx_ops;
+ context->ibv_ctx.context.ops = rxe_ctx_ops;
return &context->ibv_ctx;
out:
+ verbs_uninit_context(&context->ibv_ctx);
free(context);
return NULL;
}
@@ -889,6 +887,7 @@ static void rxe_free_context(struct ibv_context *ibctx)
{
struct rxe_context *context = to_rctx(ibctx);
+ verbs_uninit_context(&context->ibv_ctx);
free(context);
}
diff --git a/providers/rxe/rxe.h b/providers/rxe/rxe.h
index 1f331662b2ba2d..3fc0436127e432 100644
--- a/providers/rxe/rxe.h
+++ b/providers/rxe/rxe.h
@@ -54,7 +54,7 @@ struct rxe_device {
};
struct rxe_context {
- struct ibv_context ibv_ctx;
+ struct verbs_context ibv_ctx;
};
struct rxe_cq {
@@ -98,7 +98,7 @@ struct rxe_srq {
static inline struct rxe_context *to_rctx(struct ibv_context *ibctx)
{
- return to_rxxx(ctx, context);
+ return container_of(ibctx, struct rxe_context, ibv_ctx.context);
}
static inline struct rxe_device *to_rdev(struct ibv_device *ibdev)
diff --git a/providers/vmw_pvrdma/pvrdma.h b/providers/vmw_pvrdma/pvrdma.h
index 3bcec1cb71d14d..58165cf434b721 100644
--- a/providers/vmw_pvrdma/pvrdma.h
+++ b/providers/vmw_pvrdma/pvrdma.h
@@ -105,7 +105,7 @@ struct pvrdma_device {
};
struct pvrdma_context {
- struct ibv_context ibv_ctx;
+ struct verbs_context ibv_ctx;
void *uar;
pthread_spinlock_t uar_lock;
int max_qp_wr;
@@ -201,7 +201,7 @@ static inline struct pvrdma_device *to_vdev(struct ibv_device *ibdev)
static inline struct pvrdma_context *to_vctx(struct ibv_context *ibctx)
{
- return container_of(ibctx, struct pvrdma_context, ibv_ctx);
+ return container_of(ibctx, struct pvrdma_context, ibv_ctx.context);
}
static inline struct pvrdma_pd *to_vpd(struct ibv_pd *ibpd)
diff --git a/providers/vmw_pvrdma/pvrdma_main.c b/providers/vmw_pvrdma/pvrdma_main.c
index 17736cd0079036..08b1d4e6d34f07 100644
--- a/providers/vmw_pvrdma/pvrdma_main.c
+++ b/providers/vmw_pvrdma/pvrdma_main.c
@@ -111,7 +111,7 @@ static int pvrdma_init_context_shared(struct pvrdma_context *context,
struct ibv_get_context cmd;
struct user_pvrdma_alloc_ucontext_resp resp;
- context->ibv_ctx.cmd_fd = cmd_fd;
+ context->ibv_ctx.context.cmd_fd = cmd_fd;
if (ibv_cmd_get_context(&context->ibv_ctx, &cmd, sizeof(cmd),
&resp.ibv_resp, sizeof(resp)))
return errno;
@@ -129,7 +129,7 @@ static int pvrdma_init_context_shared(struct pvrdma_context *context,
}
pthread_spin_init(&context->uar_lock, PTHREAD_PROCESS_PRIVATE);
- context->ibv_ctx.ops = pvrdma_ctx_ops;
+ context->ibv_ctx.context.ops = pvrdma_ctx_ops;
return 0;
}
@@ -141,18 +141,17 @@ static void pvrdma_free_context_shared(struct pvrdma_context *context,
free(context->qp_tbl);
}
-static struct ibv_context *pvrdma_alloc_context(struct ibv_device *ibdev,
- int cmd_fd)
+static struct verbs_context *pvrdma_alloc_context(struct ibv_device *ibdev,
+ int cmd_fd)
{
struct pvrdma_context *context;
- context = malloc(sizeof(*context));
+ context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx);
if (!context)
return NULL;
- memset(context, 0, sizeof(*context));
-
if (pvrdma_init_context_shared(context, ibdev, cmd_fd)) {
+ verbs_uninit_context(&context->ibv_ctx);
free(context);
return NULL;
}
@@ -165,6 +164,7 @@ static void pvrdma_free_context(struct ibv_context *ibctx)
struct pvrdma_context *context = to_vctx(ibctx);
pvrdma_free_context_shared(context, to_vdev(ibctx->device));
+ verbs_uninit_context(&context->ibv_ctx);
free(context);
}
--
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
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 2/8] bnxt_re: Convert from init_context to alloc_context
[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
@ 2018-01-08 21:26 ` Jason Gunthorpe
[not found] ` <20180108212632.5183-3-jgg-uk2M96/98Pc@public.gmane.org>
2018-01-08 21:26 ` [PATCH 3/8] mlx4: " Jason Gunthorpe
` (6 subsequent siblings)
8 siblings, 1 reply; 20+ messages in thread
From: Jason Gunthorpe @ 2018-01-08 21:26 UTC (permalink / raw)
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA; +Cc: Jason Gunthorpe, Devesh Sharma
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
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 3/8] mlx4: Convert from init_context to alloc_context
[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
2018-01-08 21:26 ` [PATCH 2/8] bnxt_re: Convert from init_context to alloc_context Jason Gunthorpe
@ 2018-01-08 21:26 ` Jason Gunthorpe
2018-01-08 21:26 ` [PATCH 4/8] mlx5: " Jason Gunthorpe
` (5 subsequent siblings)
8 siblings, 0 replies; 20+ messages in thread
From: Jason Gunthorpe @ 2018-01-08 21:26 UTC (permalink / raw)
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA; +Cc: Jason Gunthorpe, Yishai Hadas
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
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 4/8] mlx5: Convert from init_context to alloc_context
[not found] ` <20180108212632.5183-1-jgg-uk2M96/98Pc@public.gmane.org>
` (2 preceding siblings ...)
2018-01-08 21:26 ` [PATCH 3/8] mlx4: " Jason Gunthorpe
@ 2018-01-08 21:26 ` Jason Gunthorpe
2018-01-08 21:26 ` [PATCH 5/8] verbs: Remove init_context/uninit_context Jason Gunthorpe
` (4 subsequent siblings)
8 siblings, 0 replies; 20+ messages in thread
From: Jason Gunthorpe @ 2018-01-08 21:26 UTC (permalink / raw)
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA; +Cc: Jason Gunthorpe, Yishai Hadas
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/mlx5/buf.c | 2 +-
providers/mlx5/cq.c | 2 +-
providers/mlx5/dbrec.c | 4 ++--
providers/mlx5/mlx5.c | 45 +++++++++++++++++++++++++--------------------
providers/mlx5/mlx5.h | 4 ++--
5 files changed, 31 insertions(+), 26 deletions(-)
diff --git a/providers/mlx5/buf.c b/providers/mlx5/buf.c
index 72de5b0e55e462..89573caa73628b 100644
--- a/providers/mlx5/buf.c
+++ b/providers/mlx5/buf.c
@@ -538,7 +538,7 @@ int mlx5_alloc_buf_contig(struct mlx5_context *mctx,
int block_size_exp;
int max_block_log;
int min_block_log;
- struct ibv_context *context = &mctx->ibv_ctx;
+ struct ibv_context *context = &mctx->ibv_ctx.context;
off_t offset;
mlx5_alloc_get_env_info(&max_block_log,
diff --git a/providers/mlx5/cq.c b/providers/mlx5/cq.c
index e96418f6c66ad5..e62b2eb6ec1ea8 100644
--- a/providers/mlx5/cq.c
+++ b/providers/mlx5/cq.c
@@ -1717,7 +1717,7 @@ int mlx5_alloc_cq_buf(struct mlx5_context *mctx, struct mlx5_cq *cq,
{
struct mlx5_cqe64 *cqe;
int i;
- struct mlx5_device *dev = to_mdev(mctx->ibv_ctx.device);
+ struct mlx5_device *dev = to_mdev(mctx->ibv_ctx.context.device);
int ret;
enum mlx5_alloc_type type;
enum mlx5_alloc_type default_type = MLX5_ALLOC_TYPE_ANON;
diff --git a/providers/mlx5/dbrec.c b/providers/mlx5/dbrec.c
index 17aee0ba20eea6..d6a69a50b26901 100644
--- a/providers/mlx5/dbrec.c
+++ b/providers/mlx5/dbrec.c
@@ -49,7 +49,7 @@ struct mlx5_db_page {
static struct mlx5_db_page *__add_page(struct mlx5_context *context)
{
struct mlx5_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;
int nlong;
@@ -121,7 +121,7 @@ out:
void mlx5_free_db(struct mlx5_context *context, __be32 *db)
{
struct mlx5_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/mlx5/mlx5.c b/providers/mlx5/mlx5.c
index a829cd5eb26473..7e8dc9b1951192 100644
--- a/providers/mlx5/mlx5.c
+++ b/providers/mlx5/mlx5.c
@@ -549,7 +549,7 @@ static int mlx5_cmd_get_context(struct mlx5_context *context,
struct mlx5_alloc_ucontext_resp *resp,
size_t resp_len)
{
- struct verbs_context *verbs_ctx = verbs_get_ctx(&context->ibv_ctx);
+ struct verbs_context *verbs_ctx = &context->ibv_ctx;
if (!ibv_cmd_get_context(verbs_ctx, &req->ibv_req,
req_len, &resp->ibv_resp, resp_len))
@@ -856,8 +856,8 @@ static void adjust_uar_info(struct mlx5_device *mdev,
context->num_uars_per_page = resp.num_uars_per_page;
}
-static int mlx5_init_context(struct verbs_device *vdev,
- struct ibv_context *ctx, int cmd_fd)
+static struct verbs_context *mlx5_alloc_context(struct ibv_device *ibdev,
+ int cmd_fd)
{
struct mlx5_context *context;
struct mlx5_alloc_ucontext req;
@@ -868,7 +868,7 @@ static int mlx5_init_context(struct verbs_device *vdev,
int low_lat_uuars;
int gross_uuars;
int j;
- struct mlx5_device *mdev;
+ struct mlx5_device *mdev = to_mdev(ibdev);
struct verbs_context *v_ctx;
struct ibv_port_attr port_attr;
struct ibv_device_attr_ex device_attr;
@@ -876,14 +876,14 @@ static int mlx5_init_context(struct verbs_device *vdev,
int bfi;
int num_sys_page_map;
- mdev = to_mdev(&vdev->device);
- v_ctx = verbs_get_ctx(ctx);
+ context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx);
+ if (!context)
+ return NULL;
+
+ v_ctx = &context->ibv_ctx;
page_size = mdev->page_size;
mlx5_single_threaded = single_threaded_app();
- context = to_mctx(ctx);
- context->ibv_ctx.cmd_fd = cmd_fd;
-
open_debug_file(context);
set_debug_mask();
set_freeze_on_error();
@@ -1001,15 +1001,15 @@ static int mlx5_init_context(struct verbs_device *vdev,
sizeof(resp.hca_core_clock_offset) &&
resp.comp_mask & MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_CORE_CLOCK_OFFSET) {
context->core_clock.offset = resp.hca_core_clock_offset;
- mlx5_map_internal_clock(mdev, ctx);
+ mlx5_map_internal_clock(mdev, &v_ctx->context);
}
- mlx5_read_env(&vdev->device, context);
+ mlx5_read_env(ibdev, context);
mlx5_spinlock_init(&context->hugetlb_lock);
list_head_init(&context->hugetlb_list);
- context->ibv_ctx.ops = mlx5_ctx_ops;
+ v_ctx->context.ops = mlx5_ctx_ops;
v_ctx->create_qp_ex = mlx5_create_qp_ex;
v_ctx->open_xrcd = mlx5_open_xrcd;
@@ -1030,7 +1030,7 @@ static int mlx5_init_context(struct verbs_device *vdev,
v_ctx->modify_cq = mlx5_modify_cq;
memset(&device_attr, 0, sizeof(device_attr));
- if (!mlx5_query_device_ex(ctx, NULL, &device_attr,
+ if (!mlx5_query_device_ex(&v_ctx->context, NULL, &device_attr,
sizeof(struct ibv_device_attr_ex))) {
context->cached_device_cap_flags =
device_attr.orig_attr.device_cap_flags;
@@ -1040,11 +1040,11 @@ static int mlx5_init_context(struct verbs_device *vdev,
for (j = 0; j < min(MLX5_MAX_PORTS_NUM, context->num_ports); ++j) {
memset(&port_attr, 0, sizeof(port_attr));
- if (!mlx5_query_port(ctx, j + 1, &port_attr))
+ if (!mlx5_query_port(&v_ctx->context, j + 1, &port_attr))
context->cached_link_layer[j] = port_attr.link_layer;
}
- return 0;
+ return v_ctx;
err_free_bf:
free(context->bfs);
@@ -1055,11 +1055,13 @@ err_free:
munmap(context->uar[i].reg, page_size);
}
close_debug_file(context);
- return errno;
+
+ verbs_uninit_context(&context->ibv_ctx);
+ free(context);
+ return NULL;
}
-static void mlx5_cleanup_context(struct verbs_device *device,
- struct ibv_context *ibctx)
+static void mlx5_free_context(struct ibv_context *ibctx)
{
struct mlx5_context *context = to_mctx(ibctx);
int page_size = to_mdev(ibctx->device)->page_size;
@@ -1074,6 +1076,9 @@ static void mlx5_cleanup_context(struct verbs_device *device,
munmap(context->hca_core_clock - context->core_clock.offset,
page_size);
close_debug_file(context);
+
+ verbs_uninit_context(&context->ibv_ctx);
+ free(context);
}
static void mlx5_uninit_device(struct verbs_device *verbs_device)
@@ -1108,7 +1113,7 @@ static const struct verbs_device_ops mlx5_dev_ops = {
.match_table = hca_table,
.alloc_device = mlx5_device_alloc,
.uninit_device = mlx5_uninit_device,
- .init_context = mlx5_init_context,
- .uninit_context = mlx5_cleanup_context,
+ .alloc_context = mlx5_alloc_context,
+ .free_context = mlx5_free_context,
};
PROVIDER_DRIVER(mlx5_dev_ops);
diff --git a/providers/mlx5/mlx5.h b/providers/mlx5/mlx5.h
index 5a1f7c0a2bbafc..45778460610beb 100644
--- a/providers/mlx5/mlx5.h
+++ b/providers/mlx5/mlx5.h
@@ -230,7 +230,7 @@ struct mlx5_uar_info {
};
struct mlx5_context {
- struct ibv_context ibv_ctx;
+ struct verbs_context ibv_ctx;
int max_num_qps;
int bf_reg_size;
int tot_uuars;
@@ -548,7 +548,7 @@ static inline struct mlx5_device *to_mdev(struct ibv_device *ibdev)
static inline struct mlx5_context *to_mctx(struct ibv_context *ibctx)
{
- return to_mxxx(ctx, context);
+ return container_of(ibctx, struct mlx5_context, ibv_ctx.context);
}
static inline struct mlx5_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
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 5/8] verbs: Remove init_context/uninit_context
[not found] ` <20180108212632.5183-1-jgg-uk2M96/98Pc@public.gmane.org>
` (3 preceding siblings ...)
2018-01-08 21:26 ` [PATCH 4/8] mlx5: " Jason Gunthorpe
@ 2018-01-08 21:26 ` Jason Gunthorpe
[not found] ` <20180108212632.5183-6-jgg-uk2M96/98Pc@public.gmane.org>
2018-01-08 21:26 ` [PATCH 6/8] verbs: Provide a default implementation for every verbs op Jason Gunthorpe
` (3 subsequent siblings)
8 siblings, 1 reply; 20+ messages in thread
From: Jason Gunthorpe @ 2018-01-08 21:26 UTC (permalink / raw)
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA
Cc: Jason Gunthorpe, Doug Ledford, Yishai Hadas, Devesh Sharma
From: Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
All providers now use the alloc_context interface and support
verbs_context. Remove the dead code.
Signed-off-by: Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
---
libibverbs/device.c | 39 ++-------------------------------------
libibverbs/driver.h | 9 ---------
providers/bnxt_re/main.c | 4 ----
providers/mlx4/mlx4.c | 4 ----
providers/mlx5/mlx5.c | 4 ----
5 files changed, 2 insertions(+), 58 deletions(-)
diff --git a/libibverbs/device.c b/libibverbs/device.c
index e42e37bd0a1f8d..db6dae5b25af59 100644
--- a/libibverbs/device.c
+++ b/libibverbs/device.c
@@ -259,29 +259,6 @@ err_free:
return NULL;
}
-/* Use the init_context flow to create a verbs_context */
-static struct verbs_context *alloc_context(struct verbs_device *device,
- int cmd_fd)
-{
- struct verbs_context *context;
-
- context = _verbs_init_and_alloc_context(
- &device->device, cmd_fd,
- sizeof(*context) + device->size_of_context, NULL);
- if (!context)
- return NULL;
-
- if (device->ops->init_context(device, &context->context, cmd_fd))
- goto err_uninit;
-
- return context;
-
-err_uninit:
- verbs_uninit_context(context);
- free(context);
- return NULL;
-}
-
LATEST_SYMVER_FUNC(ibv_open_device, 1_1, "IBVERBS_1.1",
struct ibv_context *,
struct ibv_device *device)
@@ -304,15 +281,11 @@ LATEST_SYMVER_FUNC(ibv_open_device, 1_1, "IBVERBS_1.1",
if (cmd_fd < 0)
return NULL;
- if (!verbs_device->ops->init_context)
- context_ex = verbs_device->ops->alloc_context(device, cmd_fd);
- else
- context_ex = alloc_context(verbs_device, cmd_fd);
-
/*
* cmd_fd ownership is transferred into alloc_context, if it fails
* then it closes cmd_fd and returns NULL
*/
+ context_ex = verbs_device->ops->alloc_context(device, cmd_fd);
if (context_ex == NULL)
return NULL;
@@ -338,15 +311,7 @@ LATEST_SYMVER_FUNC(ibv_close_device, 1_1, "IBVERBS_1.1",
{
struct verbs_device *verbs_device = verbs_get_device(context->device);
- if (verbs_device->ops->uninit_context) {
- struct verbs_context *context_ex =
- container_of(context, struct verbs_context, context);
-
- verbs_device->ops->uninit_context(verbs_device, context);
- verbs_uninit_context(context_ex);
- } else {
- verbs_device->ops->free_context(context);
- }
+ verbs_device->ops->free_context(context);
return 0;
}
diff --git a/libibverbs/driver.h b/libibverbs/driver.h
index 809c4f5c8cdf39..00847a41bc468e 100644
--- a/libibverbs/driver.h
+++ b/libibverbs/driver.h
@@ -152,17 +152,10 @@ struct verbs_device_ops {
bool (*match_device)(struct verbs_sysfs_dev *sysfs_dev);
- /* Old interface, do not use in new code. */
struct verbs_context *(*alloc_context)(struct ibv_device *device,
int cmd_fd);
void (*free_context)(struct ibv_context *context);
- /* New interface */
- int (*init_context)(struct verbs_device *device,
- struct ibv_context *ctx, int cmd_fd);
- void (*uninit_context)(struct verbs_device *device,
- struct ibv_context *ctx);
-
struct verbs_device *(*alloc_device)(struct verbs_sysfs_dev *sysfs_dev);
void (*uninit_device)(struct verbs_device *device);
};
@@ -171,8 +164,6 @@ struct verbs_device_ops {
struct verbs_device {
struct ibv_device device; /* Must be first */
const struct verbs_device_ops *ops;
- size_t sz;
- size_t size_of_context;
atomic_int refcount;
struct list_node entry;
struct verbs_sysfs_dev *sysfs;
diff --git a/providers/bnxt_re/main.c b/providers/bnxt_re/main.c
index c225f09eaa58f7..d689b392d05b5d 100644
--- a/providers/bnxt_re/main.c
+++ b/providers/bnxt_re/main.c
@@ -179,10 +179,6 @@ bnxt_re_device_alloc(struct verbs_sysfs_dev *sysfs_dev)
if (!dev)
return NULL;
- dev->vdev.sz = sizeof(*dev);
- dev->vdev.size_of_context =
- sizeof(struct bnxt_re_context) - sizeof(struct ibv_context);
-
return &dev->vdev;
}
diff --git a/providers/mlx4/mlx4.c b/providers/mlx4/mlx4.c
index 3d64b8c8ebae65..f0d63b57792602 100644
--- a/providers/mlx4/mlx4.c
+++ b/providers/mlx4/mlx4.c
@@ -298,10 +298,6 @@ static struct verbs_device *mlx4_device_alloc(struct verbs_sysfs_dev *sysfs_dev)
dev->page_size = sysconf(_SC_PAGESIZE);
dev->abi_version = sysfs_dev->abi_ver;
- dev->verbs_dev.sz = sizeof(*dev);
- dev->verbs_dev.size_of_context =
- sizeof(struct mlx4_context) - sizeof(struct ibv_context);
-
return &dev->verbs_dev;
}
diff --git a/providers/mlx5/mlx5.c b/providers/mlx5/mlx5.c
index 7e8dc9b1951192..41b484fce29683 100644
--- a/providers/mlx5/mlx5.c
+++ b/providers/mlx5/mlx5.c
@@ -1099,10 +1099,6 @@ static struct verbs_device *mlx5_device_alloc(struct verbs_sysfs_dev *sysfs_dev)
dev->page_size = sysconf(_SC_PAGESIZE);
dev->driver_abi_ver = sysfs_dev->abi_ver;
- dev->verbs_dev.sz = sizeof(*dev);
- dev->verbs_dev.size_of_context = sizeof(struct mlx5_context) -
- sizeof(struct ibv_context);
-
return &dev->verbs_dev;
}
--
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
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 6/8] verbs: Provide a default implementation for every verbs op
[not found] ` <20180108212632.5183-1-jgg-uk2M96/98Pc@public.gmane.org>
` (4 preceding siblings ...)
2018-01-08 21:26 ` [PATCH 5/8] verbs: Remove init_context/uninit_context Jason Gunthorpe
@ 2018-01-08 21:26 ` Jason Gunthorpe
2018-01-08 21:26 ` [PATCH 7/8] verbs: Convert all providers to use verbs_set_ops Jason Gunthorpe
` (2 subsequent siblings)
8 siblings, 0 replies; 20+ messages in thread
From: Jason Gunthorpe @ 2018-01-08 21:26 UTC (permalink / raw)
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA
Cc: Jason Gunthorpe, Doug Ledford, Yishai Hadas
From: Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Some of the drivers do not provide implementations for all ops
eg bind_mw, modify_srq, etc.
Unfortunately the code doesn't always check for NULL, and even if it does
it doesn't always return the correct error code.
Solve this problem globally and permanently by providing dummy ops for
every single function op.
This patch just provides the dummy ops, they will still get overwritten until
all the providers switch to using verbs_set_ops.
Signed-off-by: Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
---
libibverbs/CMakeLists.txt | 1 +
libibverbs/device.c | 2 +
libibverbs/driver.h | 98 +++++++++
libibverbs/dummy_ops.c | 469 +++++++++++++++++++++++++++++++++++++++++++
libibverbs/ibverbs.h | 1 +
libibverbs/libibverbs.map.in | 1 +
6 files changed, 572 insertions(+)
create mode 100644 libibverbs/dummy_ops.c
diff --git a/libibverbs/CMakeLists.txt b/libibverbs/CMakeLists.txt
index af340a84cbed1c..6b41b875210cfb 100644
--- a/libibverbs/CMakeLists.txt
+++ b/libibverbs/CMakeLists.txt
@@ -28,6 +28,7 @@ rdma_library(ibverbs "${CMAKE_CURRENT_BINARY_DIR}/libibverbs.map"
cmd.c
compat-1_0.c
device.c
+ dummy_ops.c
enum_strs.c
init.c
marshall.c
diff --git a/libibverbs/device.c b/libibverbs/device.c
index db6dae5b25af59..491918b1999fb4 100644
--- a/libibverbs/device.c
+++ b/libibverbs/device.c
@@ -224,6 +224,8 @@ int verbs_init_context(struct verbs_context *context_ex,
return -1;
}
+ verbs_set_ops(context_ex, &verbs_dummy_ops);
+
return 0;
}
diff --git a/libibverbs/driver.h b/libibverbs/driver.h
index 00847a41bc468e..a0728f7c6bc071 100644
--- a/libibverbs/driver.h
+++ b/libibverbs/driver.h
@@ -169,6 +169,102 @@ struct verbs_device {
struct verbs_sysfs_dev *sysfs;
};
+/*
+ * Must change the PRIVATE IBVERBS_PRIVATE_ symbol if this is changed. This is
+ * the union of every op the driver can support. If new elements are added to
+ * this structure then verbs_dummy_ops must also be updated.
+ *
+ * Keep sorted.
+ */
+struct verbs_context_ops {
+ struct ibv_mw *(*alloc_mw)(struct ibv_pd *pd, enum ibv_mw_type type);
+ struct ibv_pd *(*alloc_pd)(struct ibv_context *context);
+ void (*async_event)(struct ibv_async_event *event);
+ int (*attach_mcast)(struct ibv_qp *qp, const union ibv_gid *gid,
+ uint16_t lid);
+ int (*bind_mw)(struct ibv_qp *qp, struct ibv_mw *mw,
+ struct ibv_mw_bind *mw_bind);
+ int (*close_xrcd)(struct ibv_xrcd *xrcd);
+ void (*cq_event)(struct ibv_cq *cq);
+ struct ibv_ah *(*create_ah)(struct ibv_pd *pd,
+ struct ibv_ah_attr *attr);
+ struct ibv_cq *(*create_cq)(struct ibv_context *context, int cqe,
+ struct ibv_comp_channel *channel,
+ int comp_vector);
+ struct ibv_cq_ex *(*create_cq_ex)(
+ struct ibv_context *context,
+ struct ibv_cq_init_attr_ex *init_attr);
+ struct ibv_flow *(*create_flow)(struct ibv_qp *qp,
+ struct ibv_flow_attr *flow_attr);
+ struct ibv_qp *(*create_qp)(struct ibv_pd *pd,
+ struct ibv_qp_init_attr *attr);
+ struct ibv_qp *(*create_qp_ex)(
+ struct ibv_context *context,
+ struct ibv_qp_init_attr_ex *qp_init_attr_ex);
+ struct ibv_rwq_ind_table *(*create_rwq_ind_table)(
+ struct ibv_context *context,
+ struct ibv_rwq_ind_table_init_attr *init_attr);
+ struct ibv_srq *(*create_srq)(struct ibv_pd *pd,
+ struct ibv_srq_init_attr *srq_init_attr);
+ struct ibv_srq *(*create_srq_ex)(
+ struct ibv_context *context,
+ struct ibv_srq_init_attr_ex *srq_init_attr_ex);
+ struct ibv_wq *(*create_wq)(struct ibv_context *context,
+ struct ibv_wq_init_attr *wq_init_attr);
+ int (*dealloc_mw)(struct ibv_mw *mw);
+ int (*dealloc_pd)(struct ibv_pd *pd);
+ int (*dereg_mr)(struct ibv_mr *mr);
+ int (*destroy_ah)(struct ibv_ah *ah);
+ int (*destroy_cq)(struct ibv_cq *cq);
+ int (*destroy_flow)(struct ibv_flow *flow);
+ int (*destroy_qp)(struct ibv_qp *qp);
+ int (*destroy_rwq_ind_table)(struct ibv_rwq_ind_table *rwq_ind_table);
+ int (*destroy_srq)(struct ibv_srq *srq);
+ int (*destroy_wq)(struct ibv_wq *wq);
+ int (*detach_mcast)(struct ibv_qp *qp, const union ibv_gid *gid,
+ uint16_t lid);
+ int (*get_srq_num)(struct ibv_srq *srq, uint32_t *srq_num);
+ int (*modify_cq)(struct ibv_cq *cq, struct ibv_modify_cq_attr *attr);
+ int (*modify_qp)(struct ibv_qp *qp, struct ibv_qp_attr *attr,
+ int attr_mask);
+ int (*modify_srq)(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr,
+ int srq_attr_mask);
+ int (*modify_wq)(struct ibv_wq *wq, struct ibv_wq_attr *wq_attr);
+ struct ibv_qp *(*open_qp)(struct ibv_context *context,
+ struct ibv_qp_open_attr *attr);
+ struct ibv_xrcd *(*open_xrcd)(
+ struct ibv_context *context,
+ struct ibv_xrcd_init_attr *xrcd_init_attr);
+ int (*poll_cq)(struct ibv_cq *cq, int num_entries, struct ibv_wc *wc);
+ int (*post_recv)(struct ibv_qp *qp, struct ibv_recv_wr *wr,
+ struct ibv_recv_wr **bad_wr);
+ int (*post_send)(struct ibv_qp *qp, struct ibv_send_wr *wr,
+ struct ibv_send_wr **bad_wr);
+ int (*post_srq_ops)(struct ibv_srq *srq, struct ibv_ops_wr *op,
+ struct ibv_ops_wr **bad_op);
+ int (*post_srq_recv)(struct ibv_srq *srq, struct ibv_recv_wr *recv_wr,
+ struct ibv_recv_wr **bad_recv_wr);
+ int (*query_device)(struct ibv_context *context,
+ struct ibv_device_attr *device_attr);
+ int (*query_device_ex)(struct ibv_context *context,
+ const struct ibv_query_device_ex_input *input,
+ struct ibv_device_attr_ex *attr,
+ size_t attr_size);
+ int (*query_port)(struct ibv_context *context, uint8_t port_num,
+ struct ibv_port_attr *port_attr);
+ int (*query_qp)(struct ibv_qp *qp, struct ibv_qp_attr *attr,
+ int attr_mask, struct ibv_qp_init_attr *init_attr);
+ int (*query_rt_values)(struct ibv_context *context,
+ struct ibv_values_ex *values);
+ int (*query_srq)(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr);
+ struct ibv_mr *(*reg_mr)(struct ibv_pd *pd, void *addr, size_t length,
+ int access);
+ int (*req_notify_cq)(struct ibv_cq *cq, int solicited_only);
+ int (*rereg_mr)(struct ibv_mr *mr, int flags, struct ibv_pd *pd,
+ void *addr, size_t length, int access);
+ int (*resize_cq)(struct ibv_cq *cq, int cqe);
+};
+
static inline struct verbs_device *
verbs_get_device(const struct ibv_device *dev)
{
@@ -208,6 +304,8 @@ void *_verbs_init_and_alloc_context(struct ibv_device *device, int cmd_fd,
int verbs_init_context(struct verbs_context *context_ex,
struct ibv_device *device, int cmd_fd);
void verbs_uninit_context(struct verbs_context *context);
+void verbs_set_ops(struct verbs_context *vctx,
+ const struct verbs_context_ops *ops);
void verbs_init_cq(struct ibv_cq *cq, struct ibv_context *context,
struct ibv_comp_channel *channel,
diff --git a/libibverbs/dummy_ops.c b/libibverbs/dummy_ops.c
new file mode 100644
index 00000000000000..88689d8aad9183
--- /dev/null
+++ b/libibverbs/dummy_ops.c
@@ -0,0 +1,469 @@
+/*
+ * Copyright (c) 2017 Mellanox Technologies, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses. You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include <infiniband/driver.h>
+#include "ibverbs.h"
+#include <errno.h>
+
+static struct ibv_mw *alloc_mw(struct ibv_pd *pd, enum ibv_mw_type type)
+{
+ errno = ENOSYS;
+ return NULL;
+}
+
+static struct ibv_pd *alloc_pd(struct ibv_context *context)
+{
+ errno = ENOSYS;
+ return NULL;
+}
+
+static void async_event(struct ibv_async_event *event)
+{
+}
+
+static int attach_mcast(struct ibv_qp *qp, const union ibv_gid *gid,
+ uint16_t lid)
+{
+ return ENOSYS;
+}
+
+static int bind_mw(struct ibv_qp *qp, struct ibv_mw *mw,
+ struct ibv_mw_bind *mw_bind)
+{
+ return ENOSYS;
+}
+
+static int close_xrcd(struct ibv_xrcd *xrcd)
+{
+ return ENOSYS;
+}
+
+static void cq_event(struct ibv_cq *cq)
+{
+}
+
+static struct ibv_ah *create_ah(struct ibv_pd *pd, struct ibv_ah_attr *attr)
+{
+ errno = ENOSYS;
+ return NULL;
+}
+
+static struct ibv_cq *create_cq(struct ibv_context *context, int cqe,
+ struct ibv_comp_channel *channel,
+ int comp_vector)
+{
+ errno = ENOSYS;
+ return NULL;
+}
+
+static struct ibv_cq_ex *create_cq_ex(struct ibv_context *context,
+ struct ibv_cq_init_attr_ex *init_attr)
+{
+ errno = ENOSYS;
+ return NULL;
+}
+
+static struct ibv_flow *create_flow(struct ibv_qp *qp,
+ struct ibv_flow_attr *flow_attr)
+{
+ errno = ENOSYS;
+ return NULL;
+}
+
+static struct ibv_qp *create_qp(struct ibv_pd *pd,
+ struct ibv_qp_init_attr *attr)
+{
+ errno = ENOSYS;
+ return NULL;
+}
+
+static struct ibv_qp *create_qp_ex(struct ibv_context *context,
+ struct ibv_qp_init_attr_ex *qp_init_attr_ex)
+{
+ errno = ENOSYS;
+ return NULL;
+}
+
+static struct ibv_rwq_ind_table *
+create_rwq_ind_table(struct ibv_context *context,
+ struct ibv_rwq_ind_table_init_attr *init_attr)
+{
+ errno = ENOSYS;
+ return NULL;
+}
+
+static struct ibv_srq *create_srq(struct ibv_pd *pd,
+ struct ibv_srq_init_attr *srq_init_attr)
+{
+ errno = ENOSYS;
+ return NULL;
+}
+
+static struct ibv_srq *
+create_srq_ex(struct ibv_context *context,
+ struct ibv_srq_init_attr_ex *srq_init_attr_ex)
+{
+ errno = ENOSYS;
+ return NULL;
+}
+
+static struct ibv_wq *create_wq(struct ibv_context *context,
+ struct ibv_wq_init_attr *wq_init_attr)
+{
+ errno = ENOSYS;
+ return NULL;
+}
+
+static int dealloc_mw(struct ibv_mw *mw)
+{
+ return ENOSYS;
+}
+
+static int dealloc_pd(struct ibv_pd *pd)
+{
+ return ENOSYS;
+}
+
+static int dereg_mr(struct ibv_mr *mr)
+{
+ return ENOSYS;
+}
+
+static int destroy_ah(struct ibv_ah *ah)
+{
+ return ENOSYS;
+}
+
+static int destroy_cq(struct ibv_cq *cq)
+{
+ return ENOSYS;
+}
+
+static int destroy_flow(struct ibv_flow *flow)
+{
+ return ENOSYS;
+}
+
+static int destroy_qp(struct ibv_qp *qp)
+{
+ return ENOSYS;
+}
+
+static int destroy_rwq_ind_table(struct ibv_rwq_ind_table *rwq_ind_table)
+{
+ return ENOSYS;
+}
+
+static int destroy_srq(struct ibv_srq *srq)
+{
+ return ENOSYS;
+}
+
+static int destroy_wq(struct ibv_wq *wq)
+{
+ return ENOSYS;
+}
+
+static int detach_mcast(struct ibv_qp *qp, const union ibv_gid *gid,
+ uint16_t lid)
+{
+ return ENOSYS;
+}
+
+static int get_srq_num(struct ibv_srq *srq, uint32_t *srq_num)
+{
+ return ENOSYS;
+}
+
+static int modify_cq(struct ibv_cq *cq, struct ibv_modify_cq_attr *attr)
+{
+ return ENOSYS;
+}
+
+static int modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, int attr_mask)
+{
+ return ENOSYS;
+}
+
+static int modify_srq(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr,
+ int srq_attr_mask)
+{
+ return ENOSYS;
+}
+
+static int modify_wq(struct ibv_wq *wq, struct ibv_wq_attr *wq_attr)
+{
+ return ENOSYS;
+}
+
+static struct ibv_qp *open_qp(struct ibv_context *context,
+ struct ibv_qp_open_attr *attr)
+{
+ errno = ENOSYS;
+ return NULL;
+}
+
+static struct ibv_xrcd *open_xrcd(struct ibv_context *context,
+ struct ibv_xrcd_init_attr *xrcd_init_attr)
+{
+ errno = ENOSYS;
+ return NULL;
+}
+
+static int poll_cq(struct ibv_cq *cq, int num_entries, struct ibv_wc *wc)
+{
+ return ENOSYS;
+}
+
+static int post_recv(struct ibv_qp *qp, struct ibv_recv_wr *wr,
+ struct ibv_recv_wr **bad_wr)
+{
+ return ENOSYS;
+}
+
+static int post_send(struct ibv_qp *qp, struct ibv_send_wr *wr,
+ struct ibv_send_wr **bad_wr)
+{
+ return ENOSYS;
+}
+
+static int post_srq_ops(struct ibv_srq *srq, struct ibv_ops_wr *op,
+ struct ibv_ops_wr **bad_op)
+{
+ return ENOSYS;
+}
+
+static int post_srq_recv(struct ibv_srq *srq, struct ibv_recv_wr *recv_wr,
+ struct ibv_recv_wr **bad_recv_wr)
+{
+ return ENOSYS;
+}
+
+static int query_device(struct ibv_context *context,
+ struct ibv_device_attr *device_attr)
+{
+ return ENOSYS;
+}
+
+static int query_device_ex(struct ibv_context *context,
+ const struct ibv_query_device_ex_input *input,
+ struct ibv_device_attr_ex *attr, size_t attr_size)
+{
+ return ENOSYS;
+}
+
+static int query_port(struct ibv_context *context, uint8_t port_num,
+ struct ibv_port_attr *port_attr)
+{
+ return ENOSYS;
+}
+
+static int query_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, int attr_mask,
+ struct ibv_qp_init_attr *init_attr)
+{
+ return ENOSYS;
+}
+
+static int query_rt_values(struct ibv_context *context,
+ struct ibv_values_ex *values)
+{
+ return ENOSYS;
+}
+
+static int query_srq(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr)
+{
+ return ENOSYS;
+}
+
+static struct ibv_mr *reg_mr(struct ibv_pd *pd, void *addr, size_t length,
+ int access)
+{
+ errno = ENOSYS;
+ return NULL;
+}
+
+static int req_notify_cq(struct ibv_cq *cq, int solicited_only)
+{
+ return ENOSYS;
+}
+
+static int rereg_mr(struct ibv_mr *mr, int flags, struct ibv_pd *pd, void *addr,
+ size_t length, int access)
+{
+ errno = ENOSYS;
+ return IBV_REREG_MR_ERR_INPUT;
+}
+
+static int resize_cq(struct ibv_cq *cq, int cqe)
+{
+ return ENOSYS;
+}
+
+/*
+ * Ops in verbs_dummy_ops simply return an ENOSYS error code when called, or
+ * do nothing. They are placed in the ops structures if the provider does not
+ * provide an op for the function.
+ *
+ * NOTE: This deliberately does not use named initializers to trigger a
+ * '-Wmissing-field-initializers' warning if the struct is changed without
+ * changing this.
+ *
+ * Keep sorted.
+ */
+const struct verbs_context_ops verbs_dummy_ops = {
+ alloc_mw,
+ alloc_pd,
+ async_event,
+ attach_mcast,
+ bind_mw,
+ close_xrcd,
+ cq_event,
+ create_ah,
+ create_cq,
+ create_cq_ex,
+ create_flow,
+ create_qp,
+ create_qp_ex,
+ create_rwq_ind_table,
+ create_srq,
+ create_srq_ex,
+ create_wq,
+ dealloc_mw,
+ dealloc_pd,
+ dereg_mr,
+ destroy_ah,
+ destroy_cq,
+ destroy_flow,
+ destroy_qp,
+ destroy_rwq_ind_table,
+ destroy_srq,
+ destroy_wq,
+ detach_mcast,
+ get_srq_num,
+ modify_cq,
+ modify_qp,
+ modify_srq,
+ modify_wq,
+ open_qp,
+ open_xrcd,
+ poll_cq,
+ post_recv,
+ post_send,
+ post_srq_ops,
+ post_srq_recv,
+ query_device,
+ query_device_ex,
+ query_port,
+ query_qp,
+ query_rt_values,
+ query_srq,
+ reg_mr,
+ req_notify_cq,
+ rereg_mr,
+ resize_cq,
+};
+
+/*
+ * Set the ops in a context. If the function pointer in op is NULL then it is
+ * not set. This allows the providers to call the function multiple times in
+ * order to have variations of the ops for different HW configurations.
+ */
+void verbs_set_ops(struct verbs_context *vctx,
+ const struct verbs_context_ops *ops)
+{
+ struct ibv_context_ops *ctx = &vctx->context.ops;
+
+#define SET_OP(ptr, name) \
+ do { \
+ if (ops->name) \
+ (ptr)->name = ops->name; \
+ } while (0)
+
+#define SET_OP2(ptr, iname, name) \
+ do { \
+ if (ops->name) \
+ (ptr)->iname = ops->name; \
+ } while (0)
+
+ SET_OP(ctx, alloc_mw);
+ SET_OP(ctx, alloc_pd);
+ SET_OP(ctx, async_event);
+ SET_OP(ctx, attach_mcast);
+ SET_OP(ctx, bind_mw);
+ SET_OP(vctx, close_xrcd);
+ SET_OP(ctx, cq_event);
+ SET_OP(ctx, create_ah);
+ SET_OP(ctx, create_cq);
+ SET_OP(vctx, create_cq_ex);
+ SET_OP2(vctx, ibv_create_flow, create_flow);
+ SET_OP(ctx, create_qp);
+ SET_OP(vctx, create_qp_ex);
+ SET_OP(vctx, create_rwq_ind_table);
+ SET_OP(ctx, create_srq);
+ SET_OP(vctx, create_srq_ex);
+ SET_OP(vctx, create_wq);
+ SET_OP(ctx, dealloc_mw);
+ SET_OP(ctx, dealloc_pd);
+ SET_OP(ctx, dereg_mr);
+ SET_OP(ctx, destroy_ah);
+ SET_OP(ctx, destroy_cq);
+ SET_OP2(vctx, ibv_destroy_flow, destroy_flow);
+ SET_OP(ctx, destroy_qp);
+ SET_OP(vctx, destroy_rwq_ind_table);
+ SET_OP(ctx, destroy_srq);
+ SET_OP(vctx, destroy_wq);
+ SET_OP(ctx, detach_mcast);
+ SET_OP(vctx, get_srq_num);
+ SET_OP(vctx, modify_cq);
+ SET_OP(ctx, modify_qp);
+ SET_OP(ctx, modify_srq);
+ SET_OP(vctx, modify_wq);
+ SET_OP(vctx, open_qp);
+ SET_OP(vctx, open_xrcd);
+ SET_OP(ctx, poll_cq);
+ SET_OP(ctx, post_recv);
+ SET_OP(ctx, post_send);
+ SET_OP(vctx, post_srq_ops);
+ SET_OP(ctx, post_srq_recv);
+ SET_OP(ctx, query_device);
+ SET_OP(vctx, query_device_ex);
+ SET_OP(ctx, query_port);
+ SET_OP(ctx, query_qp);
+ SET_OP(vctx, query_rt_values);
+ SET_OP(ctx, query_srq);
+ SET_OP(ctx, reg_mr);
+ SET_OP(ctx, req_notify_cq);
+ SET_OP(ctx, rereg_mr);
+ SET_OP(ctx, resize_cq);
+
+#undef SET_OP
+#undef SET_OP2
+}
diff --git a/libibverbs/ibverbs.h b/libibverbs/ibverbs.h
index 74f2ab81f5a95c..2da44967c4f1c0 100644
--- a/libibverbs/ibverbs.h
+++ b/libibverbs/ibverbs.h
@@ -50,6 +50,7 @@ struct ibv_abi_compat_v2 {
};
extern int abi_ver;
+extern const struct verbs_context_ops verbs_dummy_ops;
int ibverbs_get_device_list(struct list_head *list);
int ibverbs_init(void);
diff --git a/libibverbs/libibverbs.map.in b/libibverbs/libibverbs.map.in
index b787b051b4c381..e71376a67e9206 100644
--- a/libibverbs/libibverbs.map.in
+++ b/libibverbs/libibverbs.map.in
@@ -163,6 +163,7 @@ IBVERBS_PRIVATE_@IBVERBS_PABI_VERSION@ {
ibv_query_gid_type;
ibv_register_driver;
verbs_register_driver_@IBVERBS_PABI_VERSION@;
+ verbs_set_ops;
verbs_uninit_context;
verbs_init_cq;
ibv_cmd_modify_cq;
--
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
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 7/8] verbs: Convert all providers to use verbs_set_ops
[not found] ` <20180108212632.5183-1-jgg-uk2M96/98Pc@public.gmane.org>
` (5 preceding siblings ...)
2018-01-08 21:26 ` [PATCH 6/8] verbs: Provide a default implementation for every verbs op Jason Gunthorpe
@ 2018-01-08 21:26 ` 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
8 siblings, 0 replies; 20+ messages in thread
From: Jason Gunthorpe @ 2018-01-08 21:26 UTC (permalink / raw)
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA
Cc: Jason Gunthorpe, Devesh Sharma, Steve Wise, Mike Marciniszyn,
Dennis Dalessandro, Tatyana Nikolova, Yishai Hadas,
Vladimir Sokolovsky, Ram Amrani, Ariel Elior, Moni Shoua,
Adit Ranadive, intel-opa-hn68Rpc1hR1g9hUCZPvPmw,
infinipath-ral2JQCrhuEAvxtiuMwx3w,
pv-drivers-pghWNbHTmq7QT0dZR+AlfA
From: Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Using verbs_set_ops ensures the provider does not replace the dummy
function set by the core code with NULL.
Some providers have multiple sets of ops, those call verbs_set_ops multiple
times, and the calls overlap exactly as before.
This also fixes a few providers that were writing to the ops structure in
.data so we can also make them all const now.
Signed-off-by: Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
---
providers/bnxt_re/main.c | 4 +--
providers/cxgb3/iwch.c | 27 +++++++++++-------
providers/cxgb4/dev.c | 18 +++++++-----
providers/hfi1verbs/hfiverbs.c | 37 +++++++++++++-----------
providers/i40iw/i40iw_umain.c | 9 ++----
providers/ipathverbs/ipathverbs.c | 35 ++++++++++++-----------
providers/mlx4/mlx4.c | 42 +++++++++++++--------------
providers/mlx5/mlx5.c | 58 ++++++++++++++++++++------------------
providers/mthca/mthca.c | 39 +++++++++++++------------
providers/nes/nes_umain.c | 15 +++++-----
providers/ocrdma/ocrdma_main.c | 5 ++--
providers/qedr/qelr_main.c | 5 ++--
providers/rxe/rxe.c | 5 ++--
providers/vmw_pvrdma/pvrdma_main.c | 5 ++--
14 files changed, 161 insertions(+), 143 deletions(-)
diff --git a/providers/bnxt_re/main.c b/providers/bnxt_re/main.c
index d689b392d05b5d..520bf572621d18 100644
--- a/providers/bnxt_re/main.c
+++ b/providers/bnxt_re/main.c
@@ -75,7 +75,7 @@ static const struct verbs_match_ent cna_table[] = {
{}
};
-static struct ibv_context_ops bnxt_re_cntx_ops = {
+static const struct verbs_context_ops bnxt_re_cntx_ops = {
.query_device = bnxt_re_query_device,
.query_port = bnxt_re_query_port,
.alloc_pd = bnxt_re_alloc_pd,
@@ -136,7 +136,7 @@ static struct verbs_context *bnxt_re_alloc_context(struct ibv_device *vdev,
}
pthread_mutex_init(&cntx->shlock, NULL);
- cntx->ibvctx.context.ops = bnxt_re_cntx_ops;
+ verbs_set_ops(&cntx->ibvctx, &bnxt_re_cntx_ops);
return &cntx->ibvctx;
diff --git a/providers/cxgb3/iwch.c b/providers/cxgb3/iwch.c
index d4d5a96ffd524e..8e2405f1c0ff60 100644
--- a/providers/cxgb3/iwch.c
+++ b/providers/cxgb3/iwch.c
@@ -75,7 +75,7 @@ static const struct verbs_match_ent hca_table[] = {
{},
};
-static struct ibv_context_ops iwch_ctx_ops = {
+static const struct verbs_context_ops iwch_ctx_common_ops = {
.query_device = iwch_query_device,
.query_port = iwch_query_port,
.alloc_pd = iwch_alloc_pd,
@@ -100,6 +100,19 @@ static struct ibv_context_ops iwch_ctx_ops = {
.req_notify_cq = iwch_arm_cq,
};
+static const struct verbs_context_ops iwch_ctx_t3a_ops = {
+ .poll_cq = t3a_poll_cq,
+ .post_recv = t3a_post_recv,
+ .post_send = t3a_post_send,
+};
+
+static const struct verbs_context_ops iwch_ctx_t3b_ops = {
+ .async_event = t3b_async_event,
+ .poll_cq = t3b_poll_cq,
+ .post_recv = t3b_post_recv,
+ .post_send = t3b_post_send,
+};
+
unsigned long iwch_page_size;
unsigned long iwch_page_shift;
unsigned long iwch_page_mask;
@@ -120,22 +133,16 @@ static struct verbs_context *iwch_alloc_context(struct ibv_device *ibdev,
&resp.ibv_resp, sizeof resp))
goto err_free;
- context->ibv_ctx.context.ops = iwch_ctx_ops;
+ verbs_set_ops(&context->ibv_ctx, &iwch_ctx_common_ops);
switch (rhp->hca_type) {
case CHELSIO_T3B:
PDBG("%s T3B device\n", __FUNCTION__);
- context->ibv_ctx.context.ops.async_event = t3b_async_event;
- context->ibv_ctx.context.ops.post_send = t3b_post_send;
- context->ibv_ctx.context.ops.post_recv = t3b_post_recv;
- context->ibv_ctx.context.ops.poll_cq = t3b_poll_cq;
+ verbs_set_ops(&context->ibv_ctx, &iwch_ctx_t3b_ops);
break;
case CHELSIO_T3A:
PDBG("%s T3A device\n", __FUNCTION__);
- context->ibv_ctx.context.ops.async_event = NULL;
- context->ibv_ctx.context.ops.post_send = t3a_post_send;
- context->ibv_ctx.context.ops.post_recv = t3a_post_recv;
- context->ibv_ctx.context.ops.poll_cq = t3a_poll_cq;
+ verbs_set_ops(&context->ibv_ctx, &iwch_ctx_t3a_ops);
break;
default:
PDBG("%s unknown hca type %d\n", __FUNCTION__, rhp->hca_type);
diff --git a/providers/cxgb4/dev.c b/providers/cxgb4/dev.c
index 3c309d9f5defb5..4d6032768e4893 100644
--- a/providers/cxgb4/dev.c
+++ b/providers/cxgb4/dev.c
@@ -71,7 +71,7 @@ int t5_en_wc = 1;
static LIST_HEAD(devices);
-static struct ibv_context_ops c4iw_ctx_ops = {
+static const struct verbs_context_ops c4iw_ctx_common_ops = {
.query_device = c4iw_query_device,
.query_port = c4iw_query_port,
.alloc_pd = c4iw_alloc_pd,
@@ -96,6 +96,14 @@ static struct ibv_context_ops c4iw_ctx_ops = {
.req_notify_cq = c4iw_arm_cq,
};
+static const struct verbs_context_ops c4iw_ctx_t4_ops = {
+ .async_event = c4iw_async_event,
+ .poll_cq = c4iw_poll_cq,
+ .post_recv = c4iw_post_receive,
+ .post_send = c4iw_post_send,
+ .req_notify_cq = c4iw_arm_cq,
+};
+
static struct verbs_context *c4iw_alloc_context(struct ibv_device *ibdev,
int cmd_fd)
{
@@ -130,7 +138,7 @@ static struct verbs_context *c4iw_alloc_context(struct ibv_device *ibdev,
goto err_free;
}
- context->ibv_ctx.context.ops = c4iw_ctx_ops;
+ verbs_set_ops(&context->ibv_ctx, &c4iw_ctx_common_ops);
switch (rhp->chip_version) {
case CHELSIO_T6:
@@ -139,11 +147,7 @@ static struct verbs_context *c4iw_alloc_context(struct ibv_device *ibdev,
PDBG("%s T5/T4 device\n", __FUNCTION__);
case CHELSIO_T4:
PDBG("%s T4 device\n", __FUNCTION__);
- context->ibv_ctx.context.ops.async_event = c4iw_async_event;
- context->ibv_ctx.context.ops.post_send = c4iw_post_send;
- context->ibv_ctx.context.ops.post_recv = c4iw_post_receive;
- context->ibv_ctx.context.ops.poll_cq = c4iw_poll_cq;
- context->ibv_ctx.context.ops.req_notify_cq = c4iw_arm_cq;
+ verbs_set_ops(&context->ibv_ctx, &c4iw_ctx_t4_ops);
break;
default:
PDBG("%s unknown hca type %d\n", __FUNCTION__,
diff --git a/providers/hfi1verbs/hfiverbs.c b/providers/hfi1verbs/hfiverbs.c
index 6117f99fbc27a2..e9d3261f599e3f 100644
--- a/providers/hfi1verbs/hfiverbs.c
+++ b/providers/hfi1verbs/hfiverbs.c
@@ -85,7 +85,7 @@ static const struct verbs_match_ent hca_table[] = {
{}
};
-static struct ibv_context_ops hfi1_ctx_ops = {
+static const struct verbs_context_ops hfi1_ctx_common_ops = {
.query_device = hfi1_query_device,
.query_port = hfi1_query_port,
@@ -98,7 +98,6 @@ static struct ibv_context_ops hfi1_ctx_ops = {
.create_cq = hfi1_create_cq,
.poll_cq = hfi1_poll_cq,
.req_notify_cq = ibv_cmd_req_notify_cq,
- .cq_event = NULL,
.resize_cq = hfi1_resize_cq,
.destroy_cq = hfi1_destroy_cq,
@@ -123,6 +122,20 @@ static struct ibv_context_ops hfi1_ctx_ops = {
.detach_mcast = ibv_cmd_detach_mcast
};
+static const struct verbs_context_ops hfi1_ctx_v1_ops = {
+ .create_cq = hfi1_create_cq_v1,
+ .create_qp = hfi1_create_qp_v1,
+ .create_srq = hfi1_create_srq_v1,
+ .destroy_cq = hfi1_destroy_cq_v1,
+ .destroy_qp = hfi1_destroy_qp_v1,
+ .destroy_srq = hfi1_destroy_srq_v1,
+ .modify_srq = hfi1_modify_srq_v1,
+ .poll_cq = ibv_cmd_poll_cq,
+ .post_recv = ibv_cmd_post_recv,
+ .post_srq_recv = ibv_cmd_post_srq_recv,
+ .resize_cq = hfi1_resize_cq_v1,
+};
+
static struct verbs_context *hfi1_alloc_context(struct ibv_device *ibdev,
int cmd_fd)
{
@@ -139,22 +152,12 @@ static struct verbs_context *hfi1_alloc_context(struct ibv_device *ibdev,
sizeof cmd, &resp, sizeof resp))
goto err_free;
- context->ibv_ctx.context.ops = hfi1_ctx_ops;
+ verbs_set_ops(&context->ibv_ctx, &hfi1_ctx_common_ops);
+
dev = to_idev(ibdev);
- if (dev->abi_version == 1) {
- context->ibv_ctx.context.ops.create_cq = hfi1_create_cq_v1;
- context->ibv_ctx.context.ops.poll_cq = ibv_cmd_poll_cq;
- context->ibv_ctx.context.ops.resize_cq = hfi1_resize_cq_v1;
- context->ibv_ctx.context.ops.destroy_cq = hfi1_destroy_cq_v1;
- context->ibv_ctx.context.ops.create_srq = hfi1_create_srq_v1;
- context->ibv_ctx.context.ops.destroy_srq = hfi1_destroy_srq_v1;
- context->ibv_ctx.context.ops.modify_srq = hfi1_modify_srq_v1;
- context->ibv_ctx.context.ops.post_srq_recv =
- ibv_cmd_post_srq_recv;
- context->ibv_ctx.context.ops.create_qp = hfi1_create_qp_v1;
- context->ibv_ctx.context.ops.destroy_qp = hfi1_destroy_qp_v1;
- context->ibv_ctx.context.ops.post_recv = ibv_cmd_post_recv;
- }
+ if (dev->abi_version == 1)
+ verbs_set_ops(&context->ibv_ctx, &hfi1_ctx_v1_ops);
+
return &context->ibv_ctx;
err_free:
diff --git a/providers/i40iw/i40iw_umain.c b/providers/i40iw/i40iw_umain.c
index 6ec40895efcfe0..6e2526711ae211 100644
--- a/providers/i40iw/i40iw_umain.c
+++ b/providers/i40iw/i40iw_umain.c
@@ -91,7 +91,7 @@ static const struct verbs_match_ent hca_table[] = {
{}
};
-static struct ibv_context_ops i40iw_uctx_ops = {
+static const struct verbs_context_ops i40iw_uctx_ops = {
.query_device = i40iw_uquery_device,
.query_port = i40iw_uquery_port,
.alloc_pd = i40iw_ualloc_pd,
@@ -104,11 +104,6 @@ static struct ibv_context_ops i40iw_uctx_ops = {
.cq_event = i40iw_cq_event,
.resize_cq = i40iw_uresize_cq,
.destroy_cq = i40iw_udestroy_cq,
- .create_srq = NULL,
- .modify_srq = NULL,
- .query_srq = NULL,
- .destroy_srq = NULL,
- .post_srq_recv = NULL,
.create_qp = i40iw_ucreate_qp,
.query_qp = i40iw_uquery_qp,
.modify_qp = i40iw_umodify_qp,
@@ -161,7 +156,7 @@ static struct verbs_context *i40iw_ualloc_context(struct ibv_device *ibdev,
goto err_free;
}
- iwvctx->ibv_ctx.context.ops = i40iw_uctx_ops;
+ verbs_set_ops(&iwvctx->ibv_ctx, &i40iw_uctx_ops);
iwvctx->max_pds = resp.max_pds;
iwvctx->max_qps = resp.max_qps;
iwvctx->wq_size = resp.wq_size;
diff --git a/providers/ipathverbs/ipathverbs.c b/providers/ipathverbs/ipathverbs.c
index 3f7f170ed6b986..f2c96187d8cb5d 100644
--- a/providers/ipathverbs/ipathverbs.c
+++ b/providers/ipathverbs/ipathverbs.c
@@ -84,7 +84,7 @@ static const struct verbs_match_ent hca_table[] = {
{}
};
-static struct ibv_context_ops ipath_ctx_ops = {
+static const struct verbs_context_ops ipath_ctx_common_ops = {
.query_device = ipath_query_device,
.query_port = ipath_query_port,
@@ -97,7 +97,6 @@ static struct ibv_context_ops ipath_ctx_ops = {
.create_cq = ipath_create_cq,
.poll_cq = ipath_poll_cq,
.req_notify_cq = ibv_cmd_req_notify_cq,
- .cq_event = NULL,
.resize_cq = ipath_resize_cq,
.destroy_cq = ipath_destroy_cq,
@@ -122,6 +121,20 @@ static struct ibv_context_ops ipath_ctx_ops = {
.detach_mcast = ibv_cmd_detach_mcast
};
+static const struct verbs_context_ops ipath_ctx_v1_ops = {
+ .create_cq = ipath_create_cq_v1,
+ .poll_cq = ibv_cmd_poll_cq,
+ .resize_cq = ipath_resize_cq_v1,
+ .destroy_cq = ipath_destroy_cq_v1,
+ .create_srq = ipath_create_srq_v1,
+ .destroy_srq = ipath_destroy_srq_v1,
+ .modify_srq = ipath_modify_srq_v1,
+ .post_srq_recv = ibv_cmd_post_srq_recv,
+ .create_qp = ipath_create_qp_v1,
+ .destroy_qp = ipath_destroy_qp_v1,
+ .post_recv = ibv_cmd_post_recv,
+};
+
static struct verbs_context *ipath_alloc_context(struct ibv_device *ibdev,
int cmd_fd)
{
@@ -138,22 +151,10 @@ static struct verbs_context *ipath_alloc_context(struct ibv_device *ibdev,
sizeof cmd, &resp, sizeof resp))
goto err_free;
- context->ibv_ctx.context.ops = ipath_ctx_ops;
+ verbs_set_ops(&context->ibv_ctx, &ipath_ctx_common_ops);
dev = to_idev(ibdev);
- if (dev->abi_version == 1) {
- context->ibv_ctx.context.ops.create_cq = ipath_create_cq_v1;
- context->ibv_ctx.context.ops.poll_cq = ibv_cmd_poll_cq;
- context->ibv_ctx.context.ops.resize_cq = ipath_resize_cq_v1;
- context->ibv_ctx.context.ops.destroy_cq = ipath_destroy_cq_v1;
- context->ibv_ctx.context.ops.create_srq = ipath_create_srq_v1;
- context->ibv_ctx.context.ops.destroy_srq = ipath_destroy_srq_v1;
- context->ibv_ctx.context.ops.modify_srq = ipath_modify_srq_v1;
- context->ibv_ctx.context.ops.post_srq_recv =
- ibv_cmd_post_srq_recv;
- context->ibv_ctx.context.ops.create_qp = ipath_create_qp_v1;
- context->ibv_ctx.context.ops.destroy_qp = ipath_destroy_qp_v1;
- context->ibv_ctx.context.ops.post_recv = ibv_cmd_post_recv;
- }
+ if (dev->abi_version == 1)
+ verbs_set_ops(&context->ibv_ctx, &ipath_ctx_v1_ops);
return &context->ibv_ctx;
err_free:
diff --git a/providers/mlx4/mlx4.c b/providers/mlx4/mlx4.c
index f0d63b57792602..dd7b98b040185a 100644
--- a/providers/mlx4/mlx4.c
+++ b/providers/mlx4/mlx4.c
@@ -81,7 +81,7 @@ static const struct verbs_match_ent hca_table[] = {
{}
};
-static struct ibv_context_ops mlx4_ctx_ops = {
+static const struct verbs_context_ops mlx4_ctx_ops = {
.query_device = mlx4_query_device,
.query_port = mlx4_query_port,
.alloc_pd = mlx4_alloc_pd,
@@ -112,7 +112,25 @@ static struct ibv_context_ops mlx4_ctx_ops = {
.create_ah = mlx4_create_ah,
.destroy_ah = mlx4_destroy_ah,
.attach_mcast = ibv_cmd_attach_mcast,
- .detach_mcast = ibv_cmd_detach_mcast
+ .detach_mcast = ibv_cmd_detach_mcast,
+
+ .close_xrcd = mlx4_close_xrcd,
+ .create_cq_ex = mlx4_create_cq_ex,
+ .create_flow = mlx4_create_flow,
+ .create_qp_ex = mlx4_create_qp_ex,
+ .create_rwq_ind_table = mlx4_create_rwq_ind_table,
+ .create_srq_ex = mlx4_create_srq_ex,
+ .create_wq = mlx4_create_wq,
+ .destroy_flow = mlx4_destroy_flow,
+ .destroy_rwq_ind_table = mlx4_destroy_rwq_ind_table,
+ .destroy_wq = mlx4_destroy_wq,
+ .get_srq_num = verbs_get_srq_num,
+ .modify_cq = mlx4_modify_cq,
+ .modify_wq = mlx4_modify_wq,
+ .open_qp = mlx4_open_qp,
+ .open_xrcd = mlx4_open_xrcd,
+ .query_device_ex = mlx4_query_device_ex,
+ .query_rt_values = mlx4_query_rt_values,
};
static void mlx4_read_env(void)
@@ -226,7 +244,7 @@ static struct verbs_context *mlx4_alloc_context(struct ibv_device *ibdev,
context->bf_buf_size = 0;
}
- verbs_ctx->context.ops = mlx4_ctx_ops;
+ verbs_set_ops(verbs_ctx, &mlx4_ctx_ops);
context->hca_core_clock = NULL;
memset(&dev_attrs, 0, sizeof(dev_attrs));
@@ -238,24 +256,6 @@ static struct verbs_context *mlx4_alloc_context(struct ibv_device *ibdev,
mlx4_map_internal_clock(dev, &verbs_ctx->context);
}
- verbs_ctx->close_xrcd = mlx4_close_xrcd;
- verbs_ctx->open_xrcd = mlx4_open_xrcd;
- verbs_ctx->create_srq_ex = mlx4_create_srq_ex;
- verbs_ctx->get_srq_num = verbs_get_srq_num;
- verbs_ctx->create_qp_ex = mlx4_create_qp_ex;
- verbs_ctx->open_qp = mlx4_open_qp;
- verbs_ctx->ibv_create_flow = mlx4_create_flow;
- verbs_ctx->ibv_destroy_flow = mlx4_destroy_flow;
- verbs_ctx->create_cq_ex = mlx4_create_cq_ex;
- verbs_ctx->query_device_ex = mlx4_query_device_ex;
- verbs_ctx->query_rt_values = mlx4_query_rt_values;
- verbs_ctx->create_wq = mlx4_create_wq;
- verbs_ctx->modify_wq = mlx4_modify_wq;
- verbs_ctx->destroy_wq = mlx4_destroy_wq;
- verbs_ctx->create_rwq_ind_table = mlx4_create_rwq_ind_table;
- verbs_ctx->destroy_rwq_ind_table = mlx4_destroy_rwq_ind_table;
- verbs_ctx->modify_cq = mlx4_modify_cq;
-
return verbs_ctx;
failed:
diff --git a/providers/mlx5/mlx5.c b/providers/mlx5/mlx5.c
index 41b484fce29683..34d17d91da1b5d 100644
--- a/providers/mlx5/mlx5.c
+++ b/providers/mlx5/mlx5.c
@@ -81,7 +81,7 @@ static const struct verbs_match_ent hca_table[] = {
uint32_t mlx5_debug_mask = 0;
int mlx5_freeze_on_error_cqe;
-static struct ibv_context_ops mlx5_ctx_ops = {
+static const struct verbs_context_ops mlx5_ctx_common_ops = {
.query_device = mlx5_query_device,
.query_port = mlx5_query_port,
.alloc_pd = mlx5_alloc_pd,
@@ -112,7 +112,29 @@ static struct ibv_context_ops mlx5_ctx_ops = {
.create_ah = mlx5_create_ah,
.destroy_ah = mlx5_destroy_ah,
.attach_mcast = mlx5_attach_mcast,
- .detach_mcast = mlx5_detach_mcast
+ .detach_mcast = mlx5_detach_mcast,
+
+ .close_xrcd = mlx5_close_xrcd,
+ .create_cq_ex = mlx5_create_cq_ex,
+ .create_qp_ex = mlx5_create_qp_ex,
+ .create_rwq_ind_table = mlx5_create_rwq_ind_table,
+ .create_srq_ex = mlx5_create_srq_ex,
+ .create_wq = mlx5_create_wq,
+ .destroy_rwq_ind_table = mlx5_destroy_rwq_ind_table,
+ .destroy_wq = mlx5_destroy_wq,
+ .get_srq_num = mlx5_get_srq_num,
+ .create_flow = mlx5_create_flow,
+ .destroy_flow = mlx5_destroy_flow,
+ .modify_cq = mlx5_modify_cq,
+ .modify_wq = mlx5_modify_wq,
+ .open_xrcd = mlx5_open_xrcd,
+ .post_srq_ops = mlx5_post_srq_ops,
+ .query_device_ex = mlx5_query_device_ex,
+ .query_rt_values = mlx5_query_rt_values,
+};
+
+static const struct verbs_context_ops mlx5_ctx_cqev1_ops = {
+ .poll_cq = mlx5_poll_cq_v1,
};
static int read_number_from_line(const char *line, int *value)
@@ -932,12 +954,6 @@ static struct verbs_context *mlx5_alloc_context(struct ibv_device *ibdev,
context->max_srq_recv_wr = resp.max_srq_recv_wr;
context->cqe_version = resp.cqe_version;
- if (context->cqe_version) {
- if (context->cqe_version == MLX5_CQE_VERSION_V1)
- mlx5_ctx_ops.poll_cq = mlx5_poll_cq_v1;
- else
- goto err_free;
- }
adjust_uar_info(mdev, context, resp);
@@ -1009,25 +1025,13 @@ static struct verbs_context *mlx5_alloc_context(struct ibv_device *ibdev,
mlx5_spinlock_init(&context->hugetlb_lock);
list_head_init(&context->hugetlb_list);
- v_ctx->context.ops = mlx5_ctx_ops;
-
- v_ctx->create_qp_ex = mlx5_create_qp_ex;
- v_ctx->open_xrcd = mlx5_open_xrcd;
- v_ctx->close_xrcd = mlx5_close_xrcd;
- v_ctx->create_srq_ex = mlx5_create_srq_ex;
- v_ctx->get_srq_num = mlx5_get_srq_num;
- v_ctx->query_device_ex = mlx5_query_device_ex;
- v_ctx->query_rt_values = mlx5_query_rt_values;
- v_ctx->ibv_create_flow = mlx5_create_flow;
- v_ctx->ibv_destroy_flow = mlx5_destroy_flow;
- v_ctx->create_cq_ex = mlx5_create_cq_ex;
- v_ctx->create_wq = mlx5_create_wq;
- v_ctx->modify_wq = mlx5_modify_wq;
- v_ctx->destroy_wq = mlx5_destroy_wq;
- v_ctx->create_rwq_ind_table = mlx5_create_rwq_ind_table;
- v_ctx->destroy_rwq_ind_table = mlx5_destroy_rwq_ind_table;
- v_ctx->post_srq_ops = mlx5_post_srq_ops;
- v_ctx->modify_cq = mlx5_modify_cq;
+ verbs_set_ops(v_ctx, &mlx5_ctx_common_ops);
+ if (context->cqe_version) {
+ if (context->cqe_version == MLX5_CQE_VERSION_V1)
+ verbs_set_ops(v_ctx, &mlx5_ctx_cqev1_ops);
+ else
+ goto err_free;
+ }
memset(&device_attr, 0, sizeof(device_attr));
if (!mlx5_query_device_ex(&v_ctx->context, NULL, &device_attr,
diff --git a/providers/mthca/mthca.c b/providers/mthca/mthca.c
index 15827391986d3a..25cf31622dcb28 100644
--- a/providers/mthca/mthca.c
+++ b/providers/mthca/mthca.c
@@ -89,7 +89,7 @@ static const struct verbs_match_ent hca_table[] = {
{}
};
-static struct ibv_context_ops mthca_ctx_ops = {
+static const struct verbs_context_ops mthca_ctx_common_ops = {
.query_device = mthca_query_device,
.query_port = mthca_query_port,
.alloc_pd = mthca_alloc_pd,
@@ -114,6 +114,21 @@ static struct ibv_context_ops mthca_ctx_ops = {
.detach_mcast = ibv_cmd_detach_mcast
};
+static const struct verbs_context_ops mthca_ctx_arbel_ops = {
+ .cq_event = mthca_arbel_cq_event,
+ .post_recv = mthca_arbel_post_recv,
+ .post_send = mthca_arbel_post_send,
+ .post_srq_recv = mthca_arbel_post_srq_recv,
+ .req_notify_cq = mthca_arbel_arm_cq,
+};
+
+static const struct verbs_context_ops mthca_ctx_tavor_ops = {
+ .post_recv = mthca_tavor_post_recv,
+ .post_send = mthca_tavor_post_send,
+ .post_srq_recv = mthca_tavor_post_srq_recv,
+ .req_notify_cq = mthca_tavor_arm_cq,
+};
+
static struct verbs_context *mthca_alloc_context(struct ibv_device *ibdev,
int cmd_fd)
{
@@ -158,23 +173,11 @@ static struct verbs_context *mthca_alloc_context(struct ibv_device *ibdev,
context->pd->context = &context->ibv_ctx.context;
- context->ibv_ctx.context.ops = mthca_ctx_ops;
-
- if (mthca_is_memfree(&context->ibv_ctx.context)) {
- context->ibv_ctx.context.ops.req_notify_cq = mthca_arbel_arm_cq;
- context->ibv_ctx.context.ops.cq_event = mthca_arbel_cq_event;
- context->ibv_ctx.context.ops.post_send = mthca_arbel_post_send;
- context->ibv_ctx.context.ops.post_recv = mthca_arbel_post_recv;
- context->ibv_ctx.context.ops.post_srq_recv =
- mthca_arbel_post_srq_recv;
- } else {
- context->ibv_ctx.context.ops.req_notify_cq = mthca_tavor_arm_cq;
- context->ibv_ctx.context.ops.cq_event = NULL;
- context->ibv_ctx.context.ops.post_send = mthca_tavor_post_send;
- context->ibv_ctx.context.ops.post_recv = mthca_tavor_post_recv;
- context->ibv_ctx.context.ops.post_srq_recv =
- mthca_tavor_post_srq_recv;
- }
+ verbs_set_ops(&context->ibv_ctx, &mthca_ctx_common_ops);
+ if (mthca_is_memfree(&context->ibv_ctx.context))
+ verbs_set_ops(&context->ibv_ctx, &mthca_ctx_arbel_ops);
+ else
+ verbs_set_ops(&context->ibv_ctx, &mthca_ctx_tavor_ops);
return &context->ibv_ctx;
diff --git a/providers/nes/nes_umain.c b/providers/nes/nes_umain.c
index a5ae678ecfe11c..c2c8b03ebb58db 100644
--- a/providers/nes/nes_umain.c
+++ b/providers/nes/nes_umain.c
@@ -63,7 +63,7 @@ static const struct verbs_match_ent hca_table[] = {
{},
};
-static struct ibv_context_ops nes_uctx_ops = {
+static const struct verbs_context_ops nes_uctx_ops = {
.query_device = nes_uquery_device,
.query_port = nes_uquery_port,
.alloc_pd = nes_ualloc_pd,
@@ -76,11 +76,6 @@ static struct ibv_context_ops nes_uctx_ops = {
.cq_event = nes_cq_event,
.resize_cq = nes_uresize_cq,
.destroy_cq = nes_udestroy_cq,
- .create_srq = NULL,
- .modify_srq = NULL,
- .query_srq = NULL,
- .destroy_srq = NULL,
- .post_srq_recv = NULL,
.create_qp = nes_ucreate_qp,
.query_qp = nes_uquery_qp,
.modify_qp = nes_umodify_qp,
@@ -94,6 +89,10 @@ static struct ibv_context_ops nes_uctx_ops = {
.async_event = nes_async_event
};
+static const struct verbs_context_ops nes_uctx_no_db_ops = {
+ .poll_cq = nes_upoll_cq_no_db_read,
+};
+
/**
* nes_ualloc_context
@@ -134,10 +133,10 @@ static struct verbs_context *nes_ualloc_context(struct ibv_device *ibdev,
sscanf(value, "%d", &nes_drv_opt);
}
+ verbs_set_ops(&nesvctx->ibv_ctx, &nes_uctx_ops);
if (nes_drv_opt & NES_DRV_OPT_NO_DB_READ)
- nes_uctx_ops.poll_cq = nes_upoll_cq_no_db_read;
+ verbs_set_ops(&nesvctx->ibv_ctx, &nes_uctx_no_db_ops);
- nesvctx->ibv_ctx.context.ops = nes_uctx_ops;
nesvctx->max_pds = resp.max_pds;
nesvctx->max_qps = resp.max_qps;
nesvctx->wq_size = resp.wq_size;
diff --git a/providers/ocrdma/ocrdma_main.c b/providers/ocrdma/ocrdma_main.c
index 5bb17eb8665bfc..5fb57149b1e802 100644
--- a/providers/ocrdma/ocrdma_main.c
+++ b/providers/ocrdma/ocrdma_main.c
@@ -64,7 +64,7 @@ static const struct verbs_match_ent ucna_table[] = {
{}
};
-static struct ibv_context_ops ocrdma_ctx_ops = {
+static const struct verbs_context_ops ocrdma_ctx_ops = {
.query_device = ocrdma_query_device,
.query_port = ocrdma_query_port,
.alloc_pd = ocrdma_alloc_pd,
@@ -121,7 +121,8 @@ static struct verbs_context *ocrdma_alloc_context(struct ibv_device *ibdev,
&resp.ibv_resp, sizeof(resp)))
goto cmd_err;
- ctx->ibv_ctx.context.ops = ocrdma_ctx_ops;
+ verbs_set_ops(&ctx->ibv_ctx, &ocrdma_ctx_ops);
+
get_ocrdma_dev(ibdev)->id = resp.dev_id;
get_ocrdma_dev(ibdev)->max_inline_data = resp.max_inline_data;
get_ocrdma_dev(ibdev)->wqe_size = resp.wqe_size;
diff --git a/providers/qedr/qelr_main.c b/providers/qedr/qelr_main.c
index 92a635cdcfca94..9926f52207ad85 100644
--- a/providers/qedr/qelr_main.c
+++ b/providers/qedr/qelr_main.c
@@ -80,7 +80,7 @@ static const struct verbs_match_ent hca_table[] = {
{}
};
-static struct ibv_context_ops qelr_ctx_ops = {
+static const struct verbs_context_ops qelr_ctx_ops = {
.query_device = qelr_query_device,
.query_port = qelr_query_port,
.alloc_pd = qelr_alloc_pd,
@@ -176,8 +176,9 @@ static struct verbs_context *qelr_alloc_context(struct ibv_device *ibdev,
&resp.ibv_resp, sizeof(resp)))
goto cmd_err;
+ verbs_set_ops(&ctx->ibv_ctx, &qelr_ctx_ops);
+
ctx->kernel_page_size = sysconf(_SC_PAGESIZE);
- ctx->ibv_ctx.context.ops = qelr_ctx_ops;
ctx->db_pa = resp.db_pa;
ctx->db_size = resp.db_size;
ctx->max_send_wr = resp.max_send_wr;
diff --git a/providers/rxe/rxe.c b/providers/rxe/rxe.c
index 5cfdf1aac08a86..2856afc48cc243 100644
--- a/providers/rxe/rxe.c
+++ b/providers/rxe/rxe.c
@@ -828,7 +828,7 @@ static int rxe_destroy_ah(struct ibv_ah *ibah)
return 0;
}
-static struct ibv_context_ops rxe_ctx_ops = {
+static const struct verbs_context_ops rxe_ctx_ops = {
.query_device = rxe_query_device,
.query_port = rxe_query_port,
.alloc_pd = rxe_alloc_pd,
@@ -838,7 +838,6 @@ static struct ibv_context_ops rxe_ctx_ops = {
.create_cq = rxe_create_cq,
.poll_cq = rxe_poll_cq,
.req_notify_cq = ibv_cmd_req_notify_cq,
- .cq_event = NULL,
.resize_cq = rxe_resize_cq,
.destroy_cq = rxe_destroy_cq,
.create_srq = rxe_create_srq,
@@ -873,7 +872,7 @@ static struct verbs_context *rxe_alloc_context(struct ibv_device *ibdev,
sizeof cmd, &resp, sizeof resp))
goto out;
- context->ibv_ctx.context.ops = rxe_ctx_ops;
+ verbs_set_ops(&context->ibv_ctx, &rxe_ctx_ops);
return &context->ibv_ctx;
diff --git a/providers/vmw_pvrdma/pvrdma_main.c b/providers/vmw_pvrdma/pvrdma_main.c
index 08b1d4e6d34f07..ab23bec592b214 100644
--- a/providers/vmw_pvrdma/pvrdma_main.c
+++ b/providers/vmw_pvrdma/pvrdma_main.c
@@ -51,7 +51,7 @@
#define PCI_VENDOR_ID_VMWARE 0x15AD
#define PCI_DEVICE_ID_VMWARE_PVRDMA 0x0820
-static struct ibv_context_ops pvrdma_ctx_ops = {
+static const struct verbs_context_ops pvrdma_ctx_ops = {
.query_device = pvrdma_query_device,
.query_port = pvrdma_query_port,
.alloc_pd = pvrdma_alloc_pd,
@@ -129,7 +129,8 @@ static int pvrdma_init_context_shared(struct pvrdma_context *context,
}
pthread_spin_init(&context->uar_lock, PTHREAD_PROCESS_PRIVATE);
- context->ibv_ctx.context.ops = pvrdma_ctx_ops;
+
+ verbs_set_ops(&context->ibv_ctx, &pvrdma_ctx_ops);
return 0;
}
--
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
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 8/8] verbs: Remove tests for NULL ops
[not found] ` <20180108212632.5183-1-jgg-uk2M96/98Pc@public.gmane.org>
` (6 preceding siblings ...)
2018-01-08 21:26 ` [PATCH 7/8] verbs: Convert all providers to use verbs_set_ops Jason Gunthorpe
@ 2018-01-08 21:26 ` Jason Gunthorpe
2018-01-10 22:05 ` [PATCH rdma-core 0/8] Revise provider initialization Steve Wise
8 siblings, 0 replies; 20+ messages in thread
From: Jason Gunthorpe @ 2018-01-08 21:26 UTC (permalink / raw)
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA
Cc: Jason Gunthorpe, Doug Ledford, Yishai Hadas
From: Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
ops can no longer be null, the correct error return is generated inside
the dummy. This removes some overhead and fixes a missing errno = ENOSYS
in the create_srq path.
We cannot change the tests inlined the header file, since the app might link
to an older verbs.
Signed-off-by: Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
---
libibverbs/device.c | 3 +--
libibverbs/verbs.c | 14 +-------------
2 files changed, 2 insertions(+), 15 deletions(-)
diff --git a/libibverbs/device.c b/libibverbs/device.c
index 491918b1999fb4..e0cb16bae1bcf8 100644
--- a/libibverbs/device.c
+++ b/libibverbs/device.c
@@ -359,8 +359,7 @@ LATEST_SYMVER_FUNC(ibv_get_async_event, 1_1, "IBVERBS_1.1",
break;
}
- if (context->ops.async_event)
- context->ops.async_event(event);
+ context->ops.async_event(event);
return 0;
}
diff --git a/libibverbs/verbs.c b/libibverbs/verbs.c
index 65d9c1c8ca2fc4..c772335e06d71a 100644
--- a/libibverbs/verbs.c
+++ b/libibverbs/verbs.c
@@ -269,11 +269,6 @@ LATEST_SYMVER_FUNC(ibv_rereg_mr, 1_1, "IBVERBS_1.1",
return IBV_REREG_MR_ERR_INPUT;
}
- if (!mr->context->ops.rereg_mr) {
- errno = ENOSYS;
- return IBV_REREG_MR_ERR_INPUT;
- }
-
if (flags & IBV_REREG_MR_CHANGE_TRANSLATION) {
err = ibv_dontfork_range(addr, length);
if (err)
@@ -420,9 +415,6 @@ LATEST_SYMVER_FUNC(ibv_resize_cq, 1_1, "IBVERBS_1.1",
int,
struct ibv_cq *cq, int cqe)
{
- if (!cq->context->ops.resize_cq)
- return ENOSYS;
-
return cq->context->ops.resize_cq(cq, cqe);
}
@@ -459,8 +451,7 @@ LATEST_SYMVER_FUNC(ibv_get_cq_event, 1_1, "IBVERBS_1.1",
*cq = (struct ibv_cq *) (uintptr_t) ev.cq_handle;
*cq_context = (*cq)->cq_context;
- if ((*cq)->context->ops.cq_event)
- (*cq)->context->ops.cq_event(*cq);
+ (*cq)->context->ops.cq_event(*cq);
return 0;
}
@@ -482,9 +473,6 @@ LATEST_SYMVER_FUNC(ibv_create_srq, 1_1, "IBVERBS_1.1",
{
struct ibv_srq *srq;
- if (!pd->context->ops.create_srq)
- return NULL;
-
srq = pd->context->ops.create_srq(pd, srq_init_attr);
if (srq) {
srq->context = pd->context;
--
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
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH 1/8] verbs: Always allocate a verbs_context
[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>
0 siblings, 1 reply; 20+ messages in thread
From: Devesh Sharma @ 2018-01-10 5:46 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: linux-rdma, Jason Gunthorpe, Benjamin Drung, Doug Ledford,
Yishai Hadas, Steve Wise, Mike Marciniszyn, Dennis Dalessandro,
Lijun Ou, Wei Hu(Xavier), Tatyana Nikolova, Vladimir Sokolovsky,
Ram Amrani, Ariel Elior, Moni Shoua, Adit Ranadive,
Leon Romanovsky, Nicolas Morey-Chaisemartin, Alexey
On Tue, Jan 9, 2018 at 2:56 AM, Jason Gunthorpe <jgg-uk2M96/98Pc@public.gmane.org> wrote:
> From: Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
>
> Now that everything is in one tree we can revise the legacy init_context
> path to always allocate a verbs_context by swapping the ibv_context
> for a verbs_context in all of the provider's wrapper struct.
>
> To keep the provider diffs minimal this single patch does several things
> at once:
>
> - Introduce the verbs_init_and_alloc_context() macro.
> This allocates, zeros and initializes the verbs_context for each driver.
> Notably this new macro correctly sets errno as required upon failure.
>
> - Remove boilerplate from all drivers, calloc, malloc, memset, cmd_fd and
> device assignment
>
> - Along with the verbs_init scheme necessarily comes the verbs_uninit
> scheme which lowers the uninit call into the provder not the common
> code. This allows us to properly uninit on the init error path.
>
> Together this follows the fairly successful pattern we see in the kernel
> for driver init to a subsystem.
>
> Also this changes ibv_cmd_get_context to accept a verbs_context since
> the majority of callers are now providing that, this keeps the diff
> smaller.
>
> This makes the entire flow more consistent and will let us eliminate the
> init_context flow.
>
> Signed-off-by: Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
> ---
> CMakeLists.txt | 2 +-
> debian/libibverbs1.symbols | 2 +-
> libibverbs/cmd.c | 12 +--
> libibverbs/device.c | 206 +++++++++++++++++++++++--------------
> libibverbs/driver.h | 23 ++++-
> libibverbs/libibverbs.map.in | 2 +
> providers/bnxt_re/main.c | 5 +-
> providers/cxgb3/iwch.c | 30 +++---
> providers/cxgb3/iwch.h | 4 +-
> providers/cxgb4/dev.c | 29 +++---
> providers/cxgb4/libcxgb4.h | 4 +-
> providers/hfi1verbs/hfiverbs.c | 36 ++++---
> providers/hfi1verbs/hfiverbs.h | 4 +-
> providers/hns/hns_roce_u.c | 53 +++++-----
> providers/hns/hns_roce_u.h | 4 +-
> providers/hns/hns_roce_u_verbs.c | 6 +-
> providers/i40iw/i40iw_umain.c | 16 +--
> providers/i40iw/i40iw_umain.h | 4 +-
> providers/ipathverbs/ipathverbs.c | 36 ++++---
> providers/ipathverbs/ipathverbs.h | 4 +-
> providers/mlx4/mlx4.c | 8 +-
> providers/mlx5/mlx5.c | 8 +-
> providers/mthca/mthca.c | 48 +++++----
> providers/mthca/mthca.h | 4 +-
> providers/nes/nes_umain.c | 19 ++--
> providers/nes/nes_umain.h | 4 +-
> providers/ocrdma/ocrdma_main.c | 14 ++-
> providers/ocrdma/ocrdma_main.h | 4 +-
> providers/qedr/qelr.h | 4 +-
> providers/qedr/qelr_main.c | 14 +--
> providers/qedr/qelr_verbs.c | 2 +-
> providers/rxe/rxe.c | 13 ++-
> providers/rxe/rxe.h | 4 +-
> providers/vmw_pvrdma/pvrdma.h | 4 +-
> providers/vmw_pvrdma/pvrdma_main.c | 14 +--
> 35 files changed, 359 insertions(+), 287 deletions(-)
>
> diff --git a/CMakeLists.txt b/CMakeLists.txt
> index b1467317b68561..e8f4a948ad9610 100644
> --- a/CMakeLists.txt
> +++ b/CMakeLists.txt
> @@ -52,7 +52,7 @@ set(PACKAGE_VERSION "17.0")
> # When this is changed the values in these files need changing too:
> # debian/libibverbs1.symbols
> # libibverbs/libibverbs.map
> -set(IBVERBS_PABI_VERSION "16")
> +set(IBVERBS_PABI_VERSION "17")
> set(IBVERBS_PROVIDER_SUFFIX "-rdmav${IBVERBS_PABI_VERSION}.so")
>
> #-------------------------
> diff --git a/debian/libibverbs1.symbols b/debian/libibverbs1.symbols
> index 2678fa6e98acf7..7c7659e434bc63 100644
> --- a/debian/libibverbs1.symbols
> +++ b/debian/libibverbs1.symbols
> @@ -1,7 +1,7 @@
> libibverbs.so.1 libibverbs1 #MINVER#
> IBVERBS_1.0@IBVERBS_1.0 1.1.6
> IBVERBS_1.1@IBVERBS_1.1 1.1.6
> - (symver)IBVERBS_PRIVATE_16 16
> + (symver)IBVERBS_PRIVATE_17 17
> ibv_ack_async_event@IBVERBS_1.0 1.1.6
> ibv_ack_async_event@IBVERBS_1.1 1.1.6
> ibv_ack_cq_events@IBVERBS_1.0 1.1.6
> diff --git a/libibverbs/cmd.c b/libibverbs/cmd.c
> index b957550ed6fbdb..bcec94f5b0ce72 100644
> --- a/libibverbs/cmd.c
> +++ b/libibverbs/cmd.c
> @@ -44,22 +44,22 @@
> #include "ibverbs.h"
> #include <ccan/minmax.h>
>
> -int ibv_cmd_get_context(struct ibv_context *context, struct ibv_get_context *cmd,
> - size_t cmd_size, struct ibv_get_context_resp *resp,
> - size_t resp_size)
> +int ibv_cmd_get_context(struct verbs_context *context_ex,
> + struct ibv_get_context *cmd, size_t cmd_size,
> + struct ibv_get_context_resp *resp, size_t resp_size)
> {
> if (abi_ver < IB_USER_VERBS_MIN_ABI_VERSION)
> return ENOSYS;
>
> IBV_INIT_CMD_RESP(cmd, cmd_size, GET_CONTEXT, resp, resp_size);
>
> - if (write(context->cmd_fd, cmd, cmd_size) != cmd_size)
> + if (write(context_ex->context.cmd_fd, cmd, cmd_size) != cmd_size)
> return errno;
>
> (void) VALGRIND_MAKE_MEM_DEFINED(resp, resp_size);
>
> - context->async_fd = resp->async_fd;
> - context->num_comp_vectors = resp->num_comp_vectors;
> + context_ex->context.async_fd = resp->async_fd;
> + context_ex->context.num_comp_vectors = resp->num_comp_vectors;
>
> return 0;
> }
> diff --git a/libibverbs/device.c b/libibverbs/device.c
> index 4fb759c6474ad7..e42e37bd0a1f8d 100644
> --- a/libibverbs/device.c
> +++ b/libibverbs/device.c
> @@ -162,7 +162,8 @@ static struct ibv_cq_ex *
> __lib_ibv_create_cq_ex(struct ibv_context *context,
> struct ibv_cq_init_attr_ex *cq_attr)
> {
> - struct verbs_context *vctx = verbs_get_ctx(context);
> + struct verbs_context *vctx =
> + container_of(context, struct verbs_context, context);
> struct ibv_cq_ex *cq;
>
> if (cq_attr->wc_flags & ~IBV_CREATE_CQ_SUP_WC_FLAGS) {
> @@ -179,14 +180,115 @@ __lib_ibv_create_cq_ex(struct ibv_context *context,
> return cq;
> }
>
> +/*
> + * Ownership of cmd_fd is transferred into this function, and it will either
> + * be released during the matching call to verbs_uninit_contxt or during the
> + * failure path of this function.
> + */
> +int verbs_init_context(struct verbs_context *context_ex,
> + struct ibv_device *device, int cmd_fd)
> +{
> + struct ibv_context *context = &context_ex->context;
> +
> + ibverbs_device_hold(device);
> +
> + context->device = device;
> + context->cmd_fd = cmd_fd;
> + context->async_fd = -1;
> + pthread_mutex_init(&context->mutex, NULL);
> +
> + context_ex->context.abi_compat = __VERBS_ABI_IS_EXTENDED;
> + context_ex->sz = sizeof(*context_ex);
> +
> + /*
> + * In order to maintain backward/forward binary compatibility
> + * with apps compiled against libibverbs-1.1.8 that use the
> + * flow steering addition, we need to set the two
> + * ABI_placeholder entries to match the driver set flow
> + * entries. This is because apps compiled against
> + * libibverbs-1.1.8 use an inline ibv_create_flow and
> + * ibv_destroy_flow function that looks in the placeholder
> + * spots for the proper entry points. For apps compiled
> + * against libibverbs-1.1.9 and later, the inline functions
> + * will be looking in the right place.
> + */
> + context_ex->ABI_placeholder1 =
> + (void (*)(void))context_ex->ibv_create_flow;
> + context_ex->ABI_placeholder2 =
> + (void (*)(void))context_ex->ibv_destroy_flow;
> +
> + context_ex->priv = calloc(1, sizeof(context_ex->priv));
> + if (!context_ex->priv) {
> + errno = ENOMEM;
> + close(cmd_fd);
> + return -1;
> + }
> +
> + return 0;
> +}
> +
> +/*
> + * Allocate and initialize a context structure. This is called to create the
> + * driver wrapper, and context_offset is the number of bytes into the wrapper
> + * structure where the verbs_context starts.
> + */
> +void *_verbs_init_and_alloc_context(struct ibv_device *device, int cmd_fd,
> + size_t alloc_size,
> + struct verbs_context *context_offset)
> +{
> + void *drv_context;
> + struct verbs_context *context;
> +
> + drv_context = calloc(1, alloc_size);
> + if (!drv_context) {
> + errno = ENOMEM;
> + close(cmd_fd);
> + return NULL;
> + }
> +
> + context = (struct verbs_context *)((uint8_t *)drv_context +
> + (uintptr_t)context_offset);
A wrapper macro would do better here?
> +
> + if (verbs_init_context(context, device, cmd_fd))
> + goto err_free;
> +
> + return drv_context;
> +
> +err_free:
> + free(drv_context);
> + return NULL;
> +}
> +
> +/* Use the init_context flow to create a verbs_context */
> +static struct verbs_context *alloc_context(struct verbs_device *device,
> + int cmd_fd)
> +{
> + struct verbs_context *context;
> +
> + context = _verbs_init_and_alloc_context(
> + &device->device, cmd_fd,
> + sizeof(*context) + device->size_of_context, NULL);
> + if (!context)
> + return NULL;
> +
> + if (device->ops->init_context(device, &context->context, cmd_fd))
> + goto err_uninit;
> +
> + return context;
> +
> +err_uninit:
> + verbs_uninit_context(context);
> + free(context);
> + return NULL;
> +}
> +
> LATEST_SYMVER_FUNC(ibv_open_device, 1_1, "IBVERBS_1.1",
> struct ibv_context *,
> struct ibv_device *device)
> {
> struct verbs_device *verbs_device = verbs_get_device(device);
> char *devpath;
> - int cmd_fd, ret;
> - struct ibv_context *context;
> + int cmd_fd;
> struct verbs_context *context_ex;
>
> if (asprintf(&devpath, "/dev/infiniband/%s", device->dev_name) < 0)
> @@ -202,96 +304,50 @@ LATEST_SYMVER_FUNC(ibv_open_device, 1_1, "IBVERBS_1.1",
> if (cmd_fd < 0)
> return NULL;
>
> - if (!verbs_device->ops->init_context) {
> - context = verbs_device->ops->alloc_context(device, cmd_fd);
> - if (!context)
> - goto err;
> - } else {
> - struct verbs_ex_private *priv;
> -
> - /* Library now allocates the context */
> - context_ex = calloc(1, sizeof(*context_ex) +
> - verbs_device->size_of_context);
> - if (!context_ex) {
> - errno = ENOMEM;
> - goto err;
> - }
> -
> - priv = calloc(1, sizeof(*priv));
> - if (!priv) {
> - errno = ENOMEM;
> - free(context_ex);
> - goto err;
> - }
> -
> - context_ex->priv = priv;
> - context_ex->context.abi_compat = __VERBS_ABI_IS_EXTENDED;
> - context_ex->sz = sizeof(*context_ex);
> -
> - context = &context_ex->context;
> - ret = verbs_device->ops->init_context(verbs_device, context, cmd_fd);
> - if (ret)
> - goto verbs_err;
> - /*
> - * In order to maintain backward/forward binary compatibility
> - * with apps compiled against libibverbs-1.1.8 that use the
> - * flow steering addition, we need to set the two
> - * ABI_placeholder entries to match the driver set flow
> - * entries. This is because apps compiled against
> - * libibverbs-1.1.8 use an inline ibv_create_flow and
> - * ibv_destroy_flow function that looks in the placeholder
> - * spots for the proper entry points. For apps compiled
> - * against libibverbs-1.1.9 and later, the inline functions
> - * will be looking in the right place.
> - */
> - context_ex->ABI_placeholder1 = (void (*)(void)) context_ex->ibv_create_flow;
> - context_ex->ABI_placeholder2 = (void (*)(void)) context_ex->ibv_destroy_flow;
> -
> - if (context_ex->create_cq_ex) {
> - priv->create_cq_ex = context_ex->create_cq_ex;
> - context_ex->create_cq_ex = __lib_ibv_create_cq_ex;
> - }
> - }
> + if (!verbs_device->ops->init_context)
> + context_ex = verbs_device->ops->alloc_context(device, cmd_fd);
> + else
> + context_ex = alloc_context(verbs_device, cmd_fd);
>
> - context->device = device;
> - context->cmd_fd = cmd_fd;
> - pthread_mutex_init(&context->mutex, NULL);
> + /*
> + * cmd_fd ownership is transferred into alloc_context, if it fails
> + * then it closes cmd_fd and returns NULL
> + */
> + if (context_ex == NULL)
> + return NULL;
>
> - ibverbs_device_hold(device);
> + if (context_ex->create_cq_ex) {
> + context_ex->priv->create_cq_ex = context_ex->create_cq_ex;
> + context_ex->create_cq_ex = __lib_ibv_create_cq_ex;
> + }
>
> - return context;
> + return &context_ex->context;
> +}
>
> -verbs_err:
> +void verbs_uninit_context(struct verbs_context *context_ex)
> +{
> free(context_ex->priv);
> - free(context_ex);
> -err:
> - close(cmd_fd);
> - return NULL;
> + close(context_ex->context.cmd_fd);
> + close(context_ex->context.async_fd);
> + ibverbs_device_put(context_ex->context.device);
> }
>
> LATEST_SYMVER_FUNC(ibv_close_device, 1_1, "IBVERBS_1.1",
> int,
> struct ibv_context *context)
> {
> - int async_fd = context->async_fd;
> - int cmd_fd = context->cmd_fd;
> - struct verbs_context *context_ex;
> struct verbs_device *verbs_device = verbs_get_device(context->device);
> - struct ibv_device *device = context->device;
>
> - context_ex = verbs_get_ctx(context);
> - if (context_ex) {
> + if (verbs_device->ops->uninit_context) {
> + struct verbs_context *context_ex =
> + container_of(context, struct verbs_context, context);
> +
> verbs_device->ops->uninit_context(verbs_device, context);
> - free(context_ex->priv);
> - free(context_ex);
> + verbs_uninit_context(context_ex);
> } else {
> verbs_device->ops->free_context(context);
> }
>
> - close(async_fd);
> - close(cmd_fd);
> - ibverbs_device_put(device);
> -
> return 0;
> }
>
> diff --git a/libibverbs/driver.h b/libibverbs/driver.h
> index 4698ba4e609f34..809c4f5c8cdf39 100644
> --- a/libibverbs/driver.h
> +++ b/libibverbs/driver.h
> @@ -153,8 +153,8 @@ struct verbs_device_ops {
> bool (*match_device)(struct verbs_sysfs_dev *sysfs_dev);
>
> /* Old interface, do not use in new code. */
> - struct ibv_context *(*alloc_context)(struct ibv_device *device,
> - int cmd_fd);
> + struct verbs_context *(*alloc_context)(struct ibv_device *device,
> + int cmd_fd);
> void (*free_context)(struct ibv_context *context);
>
> /* New interface */
> @@ -205,13 +205,26 @@ void verbs_register_driver(const struct verbs_device_ops *ops);
> verbs_register_driver(&drv); \
> }
>
> +void *_verbs_init_and_alloc_context(struct ibv_device *device, int cmd_fd,
> + size_t alloc_size,
> + struct verbs_context *context_offset);
> +
> +#define verbs_init_and_alloc_context(ibdev, cmd_fd, drv_ctx_ptr, ctx_memb) \
> + ((typeof(drv_ctx_ptr))_verbs_init_and_alloc_context( \
> + ibdev, cmd_fd, sizeof(*drv_ctx_ptr), \
> + &((typeof(drv_ctx_ptr))NULL)->ctx_memb))
> +
> +int verbs_init_context(struct verbs_context *context_ex,
> + struct ibv_device *device, int cmd_fd);
> +void verbs_uninit_context(struct verbs_context *context);
> +
> void verbs_init_cq(struct ibv_cq *cq, struct ibv_context *context,
> struct ibv_comp_channel *channel,
> void *cq_context);
>
> -int ibv_cmd_get_context(struct ibv_context *context, struct ibv_get_context *cmd,
> - size_t cmd_size, struct ibv_get_context_resp *resp,
> - size_t resp_size);
> +int ibv_cmd_get_context(struct verbs_context *context,
> + struct ibv_get_context *cmd, size_t cmd_size,
> + struct ibv_get_context_resp *resp, size_t resp_size);
> int ibv_cmd_query_device(struct ibv_context *context,
> struct ibv_device_attr *device_attr,
> uint64_t *raw_fw_ver,
> diff --git a/libibverbs/libibverbs.map.in b/libibverbs/libibverbs.map.in
> index 3f635a94b82d58..b787b051b4c381 100644
> --- a/libibverbs/libibverbs.map.in
> +++ b/libibverbs/libibverbs.map.in
> @@ -113,6 +113,7 @@ IBVERBS_1.1 {
> IBVERBS_PRIVATE_@IBVERBS_PABI_VERSION@ {
> global:
> /* These historical symbols are now private to libibverbs */
> + _verbs_init_and_alloc_context;
> ibv_cmd_alloc_mw;
> ibv_cmd_alloc_pd;
> ibv_cmd_attach_mcast;
> @@ -162,6 +163,7 @@ IBVERBS_PRIVATE_@IBVERBS_PABI_VERSION@ {
> ibv_query_gid_type;
> ibv_register_driver;
> verbs_register_driver_@IBVERBS_PABI_VERSION@;
> + verbs_uninit_context;
> verbs_init_cq;
> ibv_cmd_modify_cq;
> };
> diff --git a/providers/bnxt_re/main.c b/providers/bnxt_re/main.c
> index 998c9fe3313389..5e83f9d1c12f35 100644
> --- a/providers/bnxt_re/main.c
> +++ b/providers/bnxt_re/main.c
> @@ -111,14 +111,15 @@ static int bnxt_re_init_context(struct verbs_device *vdev,
> struct bnxt_re_cntx_resp resp;
> struct bnxt_re_dev *dev;
> 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);
>
> memset(&resp, 0, sizeof(resp));
> ibvctx->cmd_fd = cmd_fd;
> - if (ibv_cmd_get_context(ibvctx, &cmd, sizeof(cmd),
> - &resp.resp, sizeof(resp)))
> + if (ibv_cmd_get_context(verbs_ctx, &cmd, sizeof(cmd), &resp.resp,
> + sizeof(resp)))
> return errno;
>
> cntx->dev_id = resp.dev_id;
> diff --git a/providers/cxgb3/iwch.c b/providers/cxgb3/iwch.c
> index da9179fbbe2a8d..d4d5a96ffd524e 100644
> --- a/providers/cxgb3/iwch.c
> +++ b/providers/cxgb3/iwch.c
> @@ -104,42 +104,38 @@ unsigned long iwch_page_size;
> unsigned long iwch_page_shift;
> unsigned long iwch_page_mask;
>
> -static struct ibv_context *iwch_alloc_context(struct ibv_device *ibdev,
> - int cmd_fd)
> +static struct verbs_context *iwch_alloc_context(struct ibv_device *ibdev,
> + int cmd_fd)
> {
> struct iwch_context *context;
> struct ibv_get_context cmd;
> struct iwch_alloc_ucontext_resp resp;
> struct iwch_device *rhp = to_iwch_dev(ibdev);
>
> - context = malloc(sizeof *context);
> + context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx);
> if (!context)
> return NULL;
>
> - memset(context, 0, sizeof *context);
> - context->ibv_ctx.cmd_fd = cmd_fd;
> -
> if (ibv_cmd_get_context(&context->ibv_ctx, &cmd, sizeof cmd,
> &resp.ibv_resp, sizeof resp))
> goto err_free;
>
> - context->ibv_ctx.device = ibdev;
> - context->ibv_ctx.ops = iwch_ctx_ops;
> + context->ibv_ctx.context.ops = iwch_ctx_ops;
>
> switch (rhp->hca_type) {
> case CHELSIO_T3B:
> PDBG("%s T3B device\n", __FUNCTION__);
> - context->ibv_ctx.ops.async_event = t3b_async_event;
> - context->ibv_ctx.ops.post_send = t3b_post_send;
> - context->ibv_ctx.ops.post_recv = t3b_post_recv;
> - context->ibv_ctx.ops.poll_cq = t3b_poll_cq;
> + context->ibv_ctx.context.ops.async_event = t3b_async_event;
> + context->ibv_ctx.context.ops.post_send = t3b_post_send;
> + context->ibv_ctx.context.ops.post_recv = t3b_post_recv;
> + context->ibv_ctx.context.ops.poll_cq = t3b_poll_cq;
> break;
> case CHELSIO_T3A:
> PDBG("%s T3A device\n", __FUNCTION__);
> - context->ibv_ctx.ops.async_event = NULL;
> - context->ibv_ctx.ops.post_send = t3a_post_send;
> - context->ibv_ctx.ops.post_recv = t3a_post_recv;
> - context->ibv_ctx.ops.poll_cq = t3a_poll_cq;
> + context->ibv_ctx.context.ops.async_event = NULL;
> + context->ibv_ctx.context.ops.post_send = t3a_post_send;
> + context->ibv_ctx.context.ops.post_recv = t3a_post_recv;
> + context->ibv_ctx.context.ops.poll_cq = t3a_poll_cq;
> break;
> default:
> PDBG("%s unknown hca type %d\n", __FUNCTION__, rhp->hca_type);
> @@ -150,6 +146,7 @@ static struct ibv_context *iwch_alloc_context(struct ibv_device *ibdev,
> return &context->ibv_ctx;
>
> err_free:
> + verbs_uninit_context(&context->ibv_ctx);
> free(context);
> return NULL;
> }
> @@ -158,6 +155,7 @@ static void iwch_free_context(struct ibv_context *ibctx)
> {
> struct iwch_context *context = to_iwch_ctx(ibctx);
>
> + verbs_uninit_context(&context->ibv_ctx);
> free(context);
> }
>
> diff --git a/providers/cxgb3/iwch.h b/providers/cxgb3/iwch.h
> index 1b95fec664ef11..0b8060cf7cfa8f 100644
> --- a/providers/cxgb3/iwch.h
> +++ b/providers/cxgb3/iwch.h
> @@ -71,7 +71,7 @@ static inline int t3a_device(struct iwch_device *dev)
> }
>
> struct iwch_context {
> - struct ibv_context ibv_ctx;
> + struct verbs_context ibv_ctx;
> };
>
> struct iwch_pd {
> @@ -111,7 +111,7 @@ static inline struct iwch_device *to_iwch_dev(struct ibv_device *ibdev)
>
> static inline struct iwch_context *to_iwch_ctx(struct ibv_context *ibctx)
> {
> - return to_iwch_xxx(ctx, context);
> + return container_of(ibctx, struct iwch_context, ibv_ctx.context);
> }
>
> static inline struct iwch_pd *to_iwch_pd(struct ibv_pd *ibpd)
> diff --git a/providers/cxgb4/dev.c b/providers/cxgb4/dev.c
> index b6775da8afeef7..3c309d9f5defb5 100644
> --- a/providers/cxgb4/dev.c
> +++ b/providers/cxgb4/dev.c
> @@ -96,8 +96,8 @@ static struct ibv_context_ops c4iw_ctx_ops = {
> .req_notify_cq = c4iw_arm_cq,
> };
>
> -static struct ibv_context *c4iw_alloc_context(struct ibv_device *ibdev,
> - int cmd_fd)
> +static struct verbs_context *c4iw_alloc_context(struct ibv_device *ibdev,
> + int cmd_fd)
> {
> struct c4iw_context *context;
> struct ibv_get_context cmd;
> @@ -107,13 +107,10 @@ static struct ibv_context *c4iw_alloc_context(struct ibv_device *ibdev,
> uint64_t raw_fw_ver;
> struct ibv_device_attr attr;
>
> - context = malloc(sizeof *context);
> + context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx);
> if (!context)
> return NULL;
>
> - memset(context, 0, sizeof *context);
> - context->ibv_ctx.cmd_fd = cmd_fd;
> -
> resp.status_page_size = 0;
> resp.reserved = 0;
> if (ibv_cmd_get_context(&context->ibv_ctx, &cmd, sizeof cmd,
> @@ -133,8 +130,7 @@ static struct ibv_context *c4iw_alloc_context(struct ibv_device *ibdev,
> goto err_free;
> }
>
> - context->ibv_ctx.device = ibdev;
> - context->ibv_ctx.ops = c4iw_ctx_ops;
> + context->ibv_ctx.context.ops = c4iw_ctx_ops;
>
> switch (rhp->chip_version) {
> case CHELSIO_T6:
> @@ -143,11 +139,11 @@ static struct ibv_context *c4iw_alloc_context(struct ibv_device *ibdev,
> PDBG("%s T5/T4 device\n", __FUNCTION__);
> case CHELSIO_T4:
> PDBG("%s T4 device\n", __FUNCTION__);
> - context->ibv_ctx.ops.async_event = c4iw_async_event;
> - context->ibv_ctx.ops.post_send = c4iw_post_send;
> - context->ibv_ctx.ops.post_recv = c4iw_post_receive;
> - context->ibv_ctx.ops.poll_cq = c4iw_poll_cq;
> - context->ibv_ctx.ops.req_notify_cq = c4iw_arm_cq;
> + context->ibv_ctx.context.ops.async_event = c4iw_async_event;
> + context->ibv_ctx.context.ops.post_send = c4iw_post_send;
> + context->ibv_ctx.context.ops.post_recv = c4iw_post_receive;
> + context->ibv_ctx.context.ops.poll_cq = c4iw_poll_cq;
> + context->ibv_ctx.context.ops.req_notify_cq = c4iw_arm_cq;
> break;
> default:
> PDBG("%s unknown hca type %d\n", __FUNCTION__,
> @@ -159,8 +155,8 @@ static struct ibv_context *c4iw_alloc_context(struct ibv_device *ibdev,
> if (!rhp->mmid2ptr) {
> int ret;
>
> - ret = ibv_cmd_query_device(&context->ibv_ctx, &attr, &raw_fw_ver, &qcmd,
> - sizeof qcmd);
> + ret = ibv_cmd_query_device(&context->ibv_ctx.context, &attr,
> + &raw_fw_ver, &qcmd, sizeof(qcmd));
> if (ret)
> goto err_unmap;
> rhp->max_mr = attr.max_mr;
> @@ -201,6 +197,7 @@ err_free:
> free(rhp->cqid2ptr);
> if (rhp->mmid2ptr)
> free(rhp->cqid2ptr);
> + verbs_uninit_context(&context->ibv_ctx);
> free(context);
> return NULL;
> }
> @@ -211,6 +208,8 @@ static void c4iw_free_context(struct ibv_context *ibctx)
>
> if (context->status_page_size)
> munmap(context->status_page, context->status_page_size);
> +
> + verbs_uninit_context(&context->ibv_ctx);
> free(context);
> }
>
> diff --git a/providers/cxgb4/libcxgb4.h b/providers/cxgb4/libcxgb4.h
> index a5256f7e081770..893bd85d5f34b2 100644
> --- a/providers/cxgb4/libcxgb4.h
> +++ b/providers/cxgb4/libcxgb4.h
> @@ -80,7 +80,7 @@ static inline int dev_is_t4(struct c4iw_dev *dev)
> }
>
> struct c4iw_context {
> - struct ibv_context ibv_ctx;
> + struct verbs_context ibv_ctx;
> struct t4_dev_status_page *status_page;
> int status_page_size;
> };
> @@ -129,7 +129,7 @@ static inline struct c4iw_dev *to_c4iw_dev(struct ibv_device *ibdev)
>
> static inline struct c4iw_context *to_c4iw_context(struct ibv_context *ibctx)
> {
> - return to_c4iw_xxx(ctx, context);
> + return container_of(ibctx, struct c4iw_context, ibv_ctx.context);
> }
>
> static inline struct c4iw_pd *to_c4iw_pd(struct ibv_pd *ibpd)
> diff --git a/providers/hfi1verbs/hfiverbs.c b/providers/hfi1verbs/hfiverbs.c
> index 7f8f5714db1630..6117f99fbc27a2 100644
> --- a/providers/hfi1verbs/hfiverbs.c
> +++ b/providers/hfi1verbs/hfiverbs.c
> @@ -123,41 +123,42 @@ static struct ibv_context_ops hfi1_ctx_ops = {
> .detach_mcast = ibv_cmd_detach_mcast
> };
>
> -static struct ibv_context *hfi1_alloc_context(struct ibv_device *ibdev,
> - int cmd_fd)
> +static struct verbs_context *hfi1_alloc_context(struct ibv_device *ibdev,
> + int cmd_fd)
> {
> struct hfi1_context *context;
> struct ibv_get_context cmd;
> struct ibv_get_context_resp resp;
> struct hfi1_device *dev;
>
> - context = malloc(sizeof *context);
> + context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx);
> if (!context)
> return NULL;
> - memset(context, 0, sizeof *context);
> - context->ibv_ctx.cmd_fd = cmd_fd;
> +
> if (ibv_cmd_get_context(&context->ibv_ctx, &cmd,
> sizeof cmd, &resp, sizeof resp))
> goto err_free;
>
> - context->ibv_ctx.ops = hfi1_ctx_ops;
> + context->ibv_ctx.context.ops = hfi1_ctx_ops;
> dev = to_idev(ibdev);
> if (dev->abi_version == 1) {
> - context->ibv_ctx.ops.create_cq = hfi1_create_cq_v1;
> - context->ibv_ctx.ops.poll_cq = ibv_cmd_poll_cq;
> - context->ibv_ctx.ops.resize_cq = hfi1_resize_cq_v1;
> - context->ibv_ctx.ops.destroy_cq = hfi1_destroy_cq_v1;
> - context->ibv_ctx.ops.create_srq = hfi1_create_srq_v1;
> - context->ibv_ctx.ops.destroy_srq = hfi1_destroy_srq_v1;
> - context->ibv_ctx.ops.modify_srq = hfi1_modify_srq_v1;
> - context->ibv_ctx.ops.post_srq_recv = ibv_cmd_post_srq_recv;
> - context->ibv_ctx.ops.create_qp = hfi1_create_qp_v1;
> - context->ibv_ctx.ops.destroy_qp = hfi1_destroy_qp_v1;
> - context->ibv_ctx.ops.post_recv = ibv_cmd_post_recv;
> + context->ibv_ctx.context.ops.create_cq = hfi1_create_cq_v1;
> + context->ibv_ctx.context.ops.poll_cq = ibv_cmd_poll_cq;
> + context->ibv_ctx.context.ops.resize_cq = hfi1_resize_cq_v1;
> + context->ibv_ctx.context.ops.destroy_cq = hfi1_destroy_cq_v1;
> + context->ibv_ctx.context.ops.create_srq = hfi1_create_srq_v1;
> + context->ibv_ctx.context.ops.destroy_srq = hfi1_destroy_srq_v1;
> + context->ibv_ctx.context.ops.modify_srq = hfi1_modify_srq_v1;
> + context->ibv_ctx.context.ops.post_srq_recv =
> + ibv_cmd_post_srq_recv;
> + context->ibv_ctx.context.ops.create_qp = hfi1_create_qp_v1;
> + context->ibv_ctx.context.ops.destroy_qp = hfi1_destroy_qp_v1;
> + context->ibv_ctx.context.ops.post_recv = ibv_cmd_post_recv;
> }
> return &context->ibv_ctx;
>
> err_free:
> + verbs_uninit_context(&context->ibv_ctx);
> free(context);
> return NULL;
> }
> @@ -166,6 +167,7 @@ static void hfi1_free_context(struct ibv_context *ibctx)
> {
> struct hfi1_context *context = to_ictx(ibctx);
>
> + verbs_uninit_context(&context->ibv_ctx);
> free(context);
> }
>
> diff --git a/providers/hfi1verbs/hfiverbs.h b/providers/hfi1verbs/hfiverbs.h
> index e672dda4982527..e7a05a0c0a83db 100644
> --- a/providers/hfi1verbs/hfiverbs.h
> +++ b/providers/hfi1verbs/hfiverbs.h
> @@ -74,7 +74,7 @@ struct hfi1_device {
> };
>
> struct hfi1_context {
> - struct ibv_context ibv_ctx;
> + struct verbs_context ibv_ctx;
> };
>
> /*
> @@ -158,7 +158,7 @@ struct hfi1_srq {
>
> static inline struct hfi1_context *to_ictx(struct ibv_context *ibctx)
> {
> - return to_ixxx(ctx, context);
> + return container_of(ibctx, struct hfi1_context, ibv_ctx.context);
> }
>
> static inline struct hfi1_device *to_idev(struct ibv_device *ibdev)
> diff --git a/providers/hns/hns_roce_u.c b/providers/hns/hns_roce_u.c
> index 489b71614614fe..781825b3782044 100644
> --- a/providers/hns/hns_roce_u.c
> +++ b/providers/hns/hns_roce_u.c
> @@ -61,8 +61,8 @@ static const struct verbs_match_ent hca_table[] = {
> {}
> };
>
> -static struct ibv_context *hns_roce_alloc_context(struct ibv_device *ibdev,
> - int cmd_fd)
> +static struct verbs_context *hns_roce_alloc_context(struct ibv_device *ibdev,
> + int cmd_fd)
> {
> int i;
> struct ibv_get_context cmd;
> @@ -71,11 +71,10 @@ static struct ibv_context *hns_roce_alloc_context(struct ibv_device *ibdev,
> struct hns_roce_alloc_ucontext_resp resp;
> struct hns_roce_device *hr_dev = to_hr_dev(ibdev);
>
> - context = calloc(1, sizeof(*context));
> + context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx);
> if (!context)
> return NULL;
>
> - context->ibv_ctx.cmd_fd = cmd_fd;
> if (ibv_cmd_get_context(&context->ibv_ctx, &cmd, sizeof(cmd),
> &resp.ibv_resp, sizeof(resp)))
> goto err_free;
> @@ -113,28 +112,28 @@ static struct ibv_context *hns_roce_alloc_context(struct ibv_device *ibdev,
>
> pthread_spin_init(&context->uar_lock, PTHREAD_PROCESS_PRIVATE);
>
> - 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.rereg_mr = hns_roce_u_rereg_mr;
> - context->ibv_ctx.ops.dereg_mr = hns_roce_u_dereg_mr;
> -
> - context->ibv_ctx.ops.create_cq = hns_roce_u_create_cq;
> - context->ibv_ctx.ops.poll_cq = hr_dev->u_hw->poll_cq;
> - context->ibv_ctx.ops.req_notify_cq = hr_dev->u_hw->arm_cq;
> - context->ibv_ctx.ops.cq_event = hns_roce_u_cq_event;
> - context->ibv_ctx.ops.destroy_cq = hns_roce_u_destroy_cq;
> -
> - context->ibv_ctx.ops.create_qp = hns_roce_u_create_qp;
> - context->ibv_ctx.ops.query_qp = hns_roce_u_query_qp;
> - context->ibv_ctx.ops.modify_qp = hr_dev->u_hw->modify_qp;
> - context->ibv_ctx.ops.destroy_qp = hr_dev->u_hw->destroy_qp;
> - context->ibv_ctx.ops.post_send = hr_dev->u_hw->post_send;
> - context->ibv_ctx.ops.post_recv = hr_dev->u_hw->post_recv;
> -
> - if (hns_roce_u_query_device(&context->ibv_ctx, &dev_attrs))
> + context->ibv_ctx.context.ops.query_device = hns_roce_u_query_device;
> + context->ibv_ctx.context.ops.query_port = hns_roce_u_query_port;
> + context->ibv_ctx.context.ops.alloc_pd = hns_roce_u_alloc_pd;
> + context->ibv_ctx.context.ops.dealloc_pd = hns_roce_u_free_pd;
> + context->ibv_ctx.context.ops.reg_mr = hns_roce_u_reg_mr;
> + context->ibv_ctx.context.ops.rereg_mr = hns_roce_u_rereg_mr;
> + context->ibv_ctx.context.ops.dereg_mr = hns_roce_u_dereg_mr;
> +
> + context->ibv_ctx.context.ops.create_cq = hns_roce_u_create_cq;
> + context->ibv_ctx.context.ops.poll_cq = hr_dev->u_hw->poll_cq;
> + context->ibv_ctx.context.ops.req_notify_cq = hr_dev->u_hw->arm_cq;
> + context->ibv_ctx.context.ops.cq_event = hns_roce_u_cq_event;
> + context->ibv_ctx.context.ops.destroy_cq = hns_roce_u_destroy_cq;
> +
> + context->ibv_ctx.context.ops.create_qp = hns_roce_u_create_qp;
> + context->ibv_ctx.context.ops.query_qp = hns_roce_u_query_qp;
> + context->ibv_ctx.context.ops.modify_qp = hr_dev->u_hw->modify_qp;
> + context->ibv_ctx.context.ops.destroy_qp = hr_dev->u_hw->destroy_qp;
> + context->ibv_ctx.context.ops.post_send = hr_dev->u_hw->post_send;
> + context->ibv_ctx.context.ops.post_recv = hr_dev->u_hw->post_recv;
> +
> + if (hns_roce_u_query_device(&context->ibv_ctx.context, &dev_attrs))
> goto tptr_free;
>
> context->max_qp_wr = dev_attrs.max_qp_wr;
> @@ -155,6 +154,7 @@ db_free:
> context->uar = NULL;
>
> err_free:
> + verbs_uninit_context(&context->ibv_ctx);
> free(context);
> return NULL;
> }
> @@ -167,6 +167,7 @@ static void hns_roce_free_context(struct ibv_context *ibctx)
> if (to_hr_dev(ibctx->device)->hw_version == HNS_ROCE_HW_VER1)
> munmap(context->cq_tptr_base, HNS_ROCE_CQ_DB_BUF_SIZE);
>
> + verbs_uninit_context(&context->ibv_ctx);
> free(context);
> }
>
> diff --git a/providers/hns/hns_roce_u.h b/providers/hns/hns_roce_u.h
> index 101320b1f8f3ad..02912468e68a65 100644
> --- a/providers/hns/hns_roce_u.h
> +++ b/providers/hns/hns_roce_u.h
> @@ -94,7 +94,7 @@ struct hns_roce_buf {
> };
>
> struct hns_roce_context {
> - struct ibv_context ibv_ctx;
> + struct verbs_context ibv_ctx;
> void *uar;
> pthread_spinlock_t uar_lock;
>
> @@ -221,7 +221,7 @@ static inline struct hns_roce_device *to_hr_dev(struct ibv_device *ibv_dev)
>
> 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);
> + return container_of(ibv_ctx, struct hns_roce_context, ibv_ctx.context);
> }
>
> static inline struct hns_roce_pd *to_hr_pd(struct ibv_pd *ibv_pd)
> diff --git a/providers/hns/hns_roce_u_verbs.c b/providers/hns/hns_roce_u_verbs.c
> index 046f0a4b849712..3def78d25a9a71 100644
> --- a/providers/hns/hns_roce_u_verbs.c
> +++ b/providers/hns/hns_roce_u_verbs.c
> @@ -208,7 +208,8 @@ static void hns_roce_set_sq_sizes(struct hns_roce_qp *qp,
>
> static int hns_roce_verify_cq(int *cqe, struct hns_roce_context *context)
> {
> - struct hns_roce_device *hr_dev = to_hr_dev(context->ibv_ctx.device);
> + struct hns_roce_device *hr_dev =
> + to_hr_dev(context->ibv_ctx.context.device);
>
> if (hr_dev->hw_version == HNS_ROCE_HW_VER1)
> if (*cqe < HNS_ROCE_MIN_CQE_NUM) {
> @@ -328,7 +329,8 @@ int hns_roce_u_destroy_cq(struct ibv_cq *cq)
> static int hns_roce_verify_qp(struct ibv_qp_init_attr *attr,
> struct hns_roce_context *context)
> {
> - struct hns_roce_device *hr_dev = to_hr_dev(context->ibv_ctx.device);
> + struct hns_roce_device *hr_dev =
> + to_hr_dev(context->ibv_ctx.context.device);
>
> if (hr_dev->hw_version == HNS_ROCE_HW_VER1) {
> if (attr->cap.max_send_wr < HNS_ROCE_MIN_WQE_NUM) {
> diff --git a/providers/i40iw/i40iw_umain.c b/providers/i40iw/i40iw_umain.c
> index 77c1ced812499b..6ec40895efcfe0 100644
> --- a/providers/i40iw/i40iw_umain.c
> +++ b/providers/i40iw/i40iw_umain.c
> @@ -131,19 +131,18 @@ static struct ibv_context_ops i40iw_uctx_ops = {
> * context and getting back resource information to return as ibv_context.
> */
>
> -static struct ibv_context *i40iw_ualloc_context(struct ibv_device *ibdev, int cmd_fd)
> +static struct verbs_context *i40iw_ualloc_context(struct ibv_device *ibdev,
> + int cmd_fd)
> {
> struct ibv_pd *ibv_pd;
> struct i40iw_uvcontext *iwvctx;
> struct i40iw_get_context cmd;
> struct i40iw_ualloc_ucontext_resp resp;
>
> - iwvctx = malloc(sizeof(*iwvctx));
> + iwvctx = verbs_init_and_alloc_context(ibdev, cmd_fd, iwvctx, ibv_ctx);
> if (!iwvctx)
> return NULL;
>
> - memset(iwvctx, 0, sizeof(*iwvctx));
> - iwvctx->ibv_ctx.cmd_fd = cmd_fd;
> cmd.userspace_ver = I40IW_ABI_VER;
> memset(&resp, 0, sizeof(resp));
> if (ibv_cmd_get_context(&iwvctx->ibv_ctx, (struct ibv_get_context *)&cmd,
> @@ -162,24 +161,24 @@ static struct ibv_context *i40iw_ualloc_context(struct ibv_device *ibdev, int cm
> goto err_free;
> }
>
> - iwvctx->ibv_ctx.device = ibdev;
> - iwvctx->ibv_ctx.ops = i40iw_uctx_ops;
> + iwvctx->ibv_ctx.context.ops = i40iw_uctx_ops;
> iwvctx->max_pds = resp.max_pds;
> iwvctx->max_qps = resp.max_qps;
> iwvctx->wq_size = resp.wq_size;
> iwvctx->abi_ver = resp.kernel_ver;
>
> i40iw_device_init_uk(&iwvctx->dev);
> - ibv_pd = i40iw_ualloc_pd(&iwvctx->ibv_ctx);
> + ibv_pd = i40iw_ualloc_pd(&iwvctx->ibv_ctx.context);
> if (!ibv_pd)
> goto err_free;
> - ibv_pd->context = &iwvctx->ibv_ctx;
> + ibv_pd->context = &iwvctx->ibv_ctx.context;
> iwvctx->iwupd = to_i40iw_upd(ibv_pd);
>
> return &iwvctx->ibv_ctx;
>
> err_free:
> fprintf(stderr, PFX "%s: failed to allocate context for device.\n", __func__);
> + verbs_uninit_context(&iwvctx->ibv_ctx);
> free(iwvctx);
>
> return NULL;
> @@ -195,6 +194,7 @@ static void i40iw_ufree_context(struct ibv_context *ibctx)
>
> i40iw_ufree_pd(&iwvctx->iwupd->ibv_pd);
>
> + verbs_uninit_context(&iwvctx->ibv_ctx);
> free(iwvctx);
> }
>
> diff --git a/providers/i40iw/i40iw_umain.h b/providers/i40iw/i40iw_umain.h
> index 109aba6bd92ef4..a2f4fa8f6b6bd9 100644
> --- a/providers/i40iw/i40iw_umain.h
> +++ b/providers/i40iw/i40iw_umain.h
> @@ -83,7 +83,7 @@ struct i40iw_upd {
> };
>
> struct i40iw_uvcontext {
> - struct ibv_context ibv_ctx;
> + struct verbs_context ibv_ctx;
> struct i40iw_upd *iwupd;
> uint32_t max_pds; /* maximum pds allowed for this user process */
> uint32_t max_qps; /* maximum qps allowed for this user process */
> @@ -137,7 +137,7 @@ static inline struct i40iw_udevice *to_i40iw_udev(struct ibv_device *ibdev)
>
> static inline struct i40iw_uvcontext *to_i40iw_uctx(struct ibv_context *ibctx)
> {
> - return to_i40iw_uxxx(ctx, vcontext);
> + return container_of(ibctx, struct i40iw_uvcontext, ibv_ctx.context);
> }
>
> static inline struct i40iw_upd *to_i40iw_upd(struct ibv_pd *ibpd)
> diff --git a/providers/ipathverbs/ipathverbs.c b/providers/ipathverbs/ipathverbs.c
> index 449abb0489955a..3f7f170ed6b986 100644
> --- a/providers/ipathverbs/ipathverbs.c
> +++ b/providers/ipathverbs/ipathverbs.c
> @@ -122,41 +122,42 @@ static struct ibv_context_ops ipath_ctx_ops = {
> .detach_mcast = ibv_cmd_detach_mcast
> };
>
> -static struct ibv_context *ipath_alloc_context(struct ibv_device *ibdev,
> - int cmd_fd)
> +static struct verbs_context *ipath_alloc_context(struct ibv_device *ibdev,
> + int cmd_fd)
> {
> struct ipath_context *context;
> struct ibv_get_context cmd;
> struct ibv_get_context_resp resp;
> struct ipath_device *dev;
>
> - context = malloc(sizeof *context);
> + context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx);
> if (!context)
> return NULL;
> - memset(context, 0, sizeof *context);
> - context->ibv_ctx.cmd_fd = cmd_fd;
> +
> if (ibv_cmd_get_context(&context->ibv_ctx, &cmd,
> sizeof cmd, &resp, sizeof resp))
> goto err_free;
>
> - context->ibv_ctx.ops = ipath_ctx_ops;
> + context->ibv_ctx.context.ops = ipath_ctx_ops;
> dev = to_idev(ibdev);
> if (dev->abi_version == 1) {
> - context->ibv_ctx.ops.create_cq = ipath_create_cq_v1;
> - context->ibv_ctx.ops.poll_cq = ibv_cmd_poll_cq;
> - context->ibv_ctx.ops.resize_cq = ipath_resize_cq_v1;
> - context->ibv_ctx.ops.destroy_cq = ipath_destroy_cq_v1;
> - context->ibv_ctx.ops.create_srq = ipath_create_srq_v1;
> - context->ibv_ctx.ops.destroy_srq = ipath_destroy_srq_v1;
> - context->ibv_ctx.ops.modify_srq = ipath_modify_srq_v1;
> - context->ibv_ctx.ops.post_srq_recv = ibv_cmd_post_srq_recv;
> - context->ibv_ctx.ops.create_qp = ipath_create_qp_v1;
> - context->ibv_ctx.ops.destroy_qp = ipath_destroy_qp_v1;
> - context->ibv_ctx.ops.post_recv = ibv_cmd_post_recv;
> + context->ibv_ctx.context.ops.create_cq = ipath_create_cq_v1;
> + context->ibv_ctx.context.ops.poll_cq = ibv_cmd_poll_cq;
> + context->ibv_ctx.context.ops.resize_cq = ipath_resize_cq_v1;
> + context->ibv_ctx.context.ops.destroy_cq = ipath_destroy_cq_v1;
> + context->ibv_ctx.context.ops.create_srq = ipath_create_srq_v1;
> + context->ibv_ctx.context.ops.destroy_srq = ipath_destroy_srq_v1;
> + context->ibv_ctx.context.ops.modify_srq = ipath_modify_srq_v1;
> + context->ibv_ctx.context.ops.post_srq_recv =
> + ibv_cmd_post_srq_recv;
> + context->ibv_ctx.context.ops.create_qp = ipath_create_qp_v1;
> + context->ibv_ctx.context.ops.destroy_qp = ipath_destroy_qp_v1;
> + context->ibv_ctx.context.ops.post_recv = ibv_cmd_post_recv;
> }
> return &context->ibv_ctx;
>
> err_free:
> + verbs_uninit_context(&context->ibv_ctx);
> free(context);
> return NULL;
> }
> @@ -165,6 +166,7 @@ static void ipath_free_context(struct ibv_context *ibctx)
> {
> struct ipath_context *context = to_ictx(ibctx);
>
> + verbs_uninit_context(&context->ibv_ctx);
> free(context);
> }
>
> diff --git a/providers/ipathverbs/ipathverbs.h b/providers/ipathverbs/ipathverbs.h
> index 5f2658e7942c8b..d26a2a1b29009e 100644
> --- a/providers/ipathverbs/ipathverbs.h
> +++ b/providers/ipathverbs/ipathverbs.h
> @@ -54,7 +54,7 @@ struct ipath_device {
> };
>
> struct ipath_context {
> - struct ibv_context ibv_ctx;
> + struct verbs_context ibv_ctx;
> };
>
> /*
> @@ -137,7 +137,7 @@ struct ipath_srq {
>
> static inline struct ipath_context *to_ictx(struct ibv_context *ibctx)
> {
> - return to_ixxx(ctx, context);
> + return container_of(ibctx, struct ipath_context, ibv_ctx.context);
> }
>
> static inline struct ipath_device *to_idev(struct ibv_device *ibdev)
> diff --git a/providers/mlx4/mlx4.c b/providers/mlx4/mlx4.c
> index d2ccd328625c80..56bf1298b48734 100644
> --- a/providers/mlx4/mlx4.c
> +++ b/providers/mlx4/mlx4.c
> @@ -167,16 +167,16 @@ static int mlx4_init_context(struct verbs_device *v_device,
>
> mlx4_read_env();
> if (dev->abi_version <= MLX4_UVERBS_NO_DEV_CAPS_ABI_VERSION) {
> - if (ibv_cmd_get_context(ibv_ctx, &cmd, sizeof cmd,
> - &resp_v3.ibv_resp, sizeof resp_v3))
> + if (ibv_cmd_get_context(verbs_ctx, &cmd, sizeof(cmd),
> + &resp_v3.ibv_resp, sizeof(resp_v3)))
> return errno;
>
> context->num_qps = resp_v3.qp_tab_size;
> bf_reg_size = resp_v3.bf_reg_size;
> context->cqe_size = sizeof (struct mlx4_cqe);
> } else {
> - if (ibv_cmd_get_context(ibv_ctx, &cmd, sizeof cmd,
> - &resp.ibv_resp, sizeof resp))
> + if (ibv_cmd_get_context(verbs_ctx, &cmd, sizeof(cmd),
> + &resp.ibv_resp, sizeof(resp)))
> return errno;
>
> context->num_qps = resp.qp_tab_size;
> diff --git a/providers/mlx5/mlx5.c b/providers/mlx5/mlx5.c
> index 36486218e31d81..a829cd5eb26473 100644
> --- a/providers/mlx5/mlx5.c
> +++ b/providers/mlx5/mlx5.c
> @@ -549,7 +549,9 @@ static int mlx5_cmd_get_context(struct mlx5_context *context,
> struct mlx5_alloc_ucontext_resp *resp,
> size_t resp_len)
> {
> - if (!ibv_cmd_get_context(&context->ibv_ctx, &req->ibv_req,
> + struct verbs_context *verbs_ctx = verbs_get_ctx(&context->ibv_ctx);
> +
> + if (!ibv_cmd_get_context(verbs_ctx, &req->ibv_req,
> req_len, &resp->ibv_resp, resp_len))
> return 0;
>
> @@ -572,12 +574,12 @@ static int mlx5_cmd_get_context(struct mlx5_context *context,
> * to do so. If zero is a valid response, we will add a new
> * field that indicates whether the request was handled.
> */
> - if (!ibv_cmd_get_context(&context->ibv_ctx, &req->ibv_req,
> + if (!ibv_cmd_get_context(verbs_ctx, &req->ibv_req,
> offsetof(struct mlx5_alloc_ucontext, lib_caps),
> &resp->ibv_resp, resp_len))
> return 0;
>
> - return ibv_cmd_get_context(&context->ibv_ctx, &req->ibv_req,
> + return ibv_cmd_get_context(verbs_ctx, &req->ibv_req,
> offsetof(struct mlx5_alloc_ucontext,
> cqe_version),
> &resp->ibv_resp, resp_len);
> diff --git a/providers/mthca/mthca.c b/providers/mthca/mthca.c
> index 511b8d5139af9c..15827391986d3a 100644
> --- a/providers/mthca/mthca.c
> +++ b/providers/mthca/mthca.c
> @@ -114,19 +114,18 @@ static struct ibv_context_ops mthca_ctx_ops = {
> .detach_mcast = ibv_cmd_detach_mcast
> };
>
> -static struct ibv_context *mthca_alloc_context(struct ibv_device *ibdev, int cmd_fd)
> +static struct verbs_context *mthca_alloc_context(struct ibv_device *ibdev,
> + int cmd_fd)
> {
> struct mthca_context *context;
> struct ibv_get_context cmd;
> struct mthca_alloc_ucontext_resp resp;
> int i;
>
> - context = calloc(1, sizeof *context);
> + context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx);
> if (!context)
> return NULL;
>
> - context->ibv_ctx.cmd_fd = cmd_fd;
> -
> if (ibv_cmd_get_context(&context->ibv_ctx, &cmd, sizeof cmd,
> &resp.ibv_resp, sizeof resp))
> goto err_free;
> @@ -135,13 +134,7 @@ static struct ibv_context *mthca_alloc_context(struct ibv_device *ibdev, int cmd
> context->qp_table_shift = ffs(context->num_qps) - 1 - MTHCA_QP_TABLE_BITS;
> context->qp_table_mask = (1 << context->qp_table_shift) - 1;
>
> - /*
> - * Need to set ibv_ctx.device because mthca_is_memfree() will
> - * look at it to figure out the HCA type.
> - */
> - context->ibv_ctx.device = ibdev;
> -
> - if (mthca_is_memfree(&context->ibv_ctx)) {
> + if (mthca_is_memfree(&context->ibv_ctx.context)) {
> context->db_tab = mthca_alloc_db_tab(resp.uarc_size);
> if (!context->db_tab)
> goto err_free;
> @@ -159,26 +152,28 @@ static struct ibv_context *mthca_alloc_context(struct ibv_device *ibdev, int cmd
>
> pthread_spin_init(&context->uar_lock, PTHREAD_PROCESS_PRIVATE);
>
> - context->pd = mthca_alloc_pd(&context->ibv_ctx);
> + context->pd = mthca_alloc_pd(&context->ibv_ctx.context);
> if (!context->pd)
> goto err_unmap;
>
> - context->pd->context = &context->ibv_ctx;
> + context->pd->context = &context->ibv_ctx.context;
>
> - context->ibv_ctx.ops = mthca_ctx_ops;
> + context->ibv_ctx.context.ops = mthca_ctx_ops;
>
> - if (mthca_is_memfree(&context->ibv_ctx)) {
> - context->ibv_ctx.ops.req_notify_cq = mthca_arbel_arm_cq;
> - context->ibv_ctx.ops.cq_event = mthca_arbel_cq_event;
> - context->ibv_ctx.ops.post_send = mthca_arbel_post_send;
> - context->ibv_ctx.ops.post_recv = mthca_arbel_post_recv;
> - context->ibv_ctx.ops.post_srq_recv = mthca_arbel_post_srq_recv;
> + if (mthca_is_memfree(&context->ibv_ctx.context)) {
> + context->ibv_ctx.context.ops.req_notify_cq = mthca_arbel_arm_cq;
> + context->ibv_ctx.context.ops.cq_event = mthca_arbel_cq_event;
> + context->ibv_ctx.context.ops.post_send = mthca_arbel_post_send;
> + context->ibv_ctx.context.ops.post_recv = mthca_arbel_post_recv;
> + context->ibv_ctx.context.ops.post_srq_recv =
> + mthca_arbel_post_srq_recv;
> } else {
> - context->ibv_ctx.ops.req_notify_cq = mthca_tavor_arm_cq;
> - context->ibv_ctx.ops.cq_event = NULL;
> - context->ibv_ctx.ops.post_send = mthca_tavor_post_send;
> - context->ibv_ctx.ops.post_recv = mthca_tavor_post_recv;
> - context->ibv_ctx.ops.post_srq_recv = mthca_tavor_post_srq_recv;
> + context->ibv_ctx.context.ops.req_notify_cq = mthca_tavor_arm_cq;
> + context->ibv_ctx.context.ops.cq_event = NULL;
> + context->ibv_ctx.context.ops.post_send = mthca_tavor_post_send;
> + context->ibv_ctx.context.ops.post_recv = mthca_tavor_post_recv;
> + context->ibv_ctx.context.ops.post_srq_recv =
> + mthca_tavor_post_srq_recv;
> }
>
> return &context->ibv_ctx;
> @@ -190,6 +185,7 @@ err_db_tab:
> mthca_free_db_tab(context->db_tab);
>
> err_free:
> + verbs_uninit_context(&context->ibv_ctx);
> free(context);
> return NULL;
> }
> @@ -201,6 +197,8 @@ static void mthca_free_context(struct ibv_context *ibctx)
> mthca_free_pd(context->pd);
> munmap(context->uar, to_mdev(ibctx->device)->page_size);
> mthca_free_db_tab(context->db_tab);
> +
> + verbs_uninit_context(&context->ibv_ctx);
> free(context);
> }
>
> diff --git a/providers/mthca/mthca.h b/providers/mthca/mthca.h
> index a67acf46c7c56d..d788f7613b439c 100644
> --- a/providers/mthca/mthca.h
> +++ b/providers/mthca/mthca.h
> @@ -97,7 +97,7 @@ struct mthca_device {
> struct mthca_db_table;
>
> struct mthca_context {
> - struct ibv_context ibv_ctx;
> + struct verbs_context ibv_ctx;
> void *uar;
> pthread_spinlock_t uar_lock;
> struct mthca_db_table *db_tab;
> @@ -229,7 +229,7 @@ static inline struct mthca_device *to_mdev(struct ibv_device *ibdev)
>
> static inline struct mthca_context *to_mctx(struct ibv_context *ibctx)
> {
> - return to_mxxx(ctx, context);
> + return container_of(ibctx, struct mthca_context, ibv_ctx.context);
> }
>
> static inline struct mthca_pd *to_mpd(struct ibv_pd *ibpd)
> diff --git a/providers/nes/nes_umain.c b/providers/nes/nes_umain.c
> index bd0b6ac68cec40..a5ae678ecfe11c 100644
> --- a/providers/nes/nes_umain.c
> +++ b/providers/nes/nes_umain.c
> @@ -98,7 +98,8 @@ static struct ibv_context_ops nes_uctx_ops = {
> /**
> * nes_ualloc_context
> */
> -static struct ibv_context *nes_ualloc_context(struct ibv_device *ibdev, int cmd_fd)
> +static struct verbs_context *nes_ualloc_context(struct ibv_device *ibdev,
> + int cmd_fd)
> {
> struct ibv_pd *ibv_pd;
> struct nes_uvcontext *nesvctx;
> @@ -109,16 +110,14 @@ static struct ibv_context *nes_ualloc_context(struct ibv_device *ibdev, int cmd_
>
> page_size = sysconf(_SC_PAGESIZE);
>
> - nesvctx = malloc(sizeof *nesvctx);
> + nesvctx = verbs_init_and_alloc_context(ibdev, cmd_fd, nesvctx, ibv_ctx);
> if (!nesvctx)
> return NULL;
>
> - memset(nesvctx, 0, sizeof *nesvctx);
> - nesvctx->ibv_ctx.cmd_fd = cmd_fd;
> cmd.userspace_ver = NES_ABI_USERSPACE_VER;
>
> if (ibv_cmd_get_context(&nesvctx->ibv_ctx, (struct ibv_get_context *)&cmd, sizeof cmd,
> - &resp.ibv_resp, sizeof(resp)))
> + &resp.ibv_resp, sizeof(resp)))
> goto err_free;
>
> if (resp.kernel_ver != NES_ABI_KERNEL_VER) {
> @@ -135,12 +134,10 @@ static struct ibv_context *nes_ualloc_context(struct ibv_device *ibdev, int cmd_
> sscanf(value, "%d", &nes_drv_opt);
> }
>
> - nesvctx->ibv_ctx.device = ibdev;
> -
> if (nes_drv_opt & NES_DRV_OPT_NO_DB_READ)
> nes_uctx_ops.poll_cq = nes_upoll_cq_no_db_read;
>
> - nesvctx->ibv_ctx.ops = nes_uctx_ops;
> + nesvctx->ibv_ctx.context.ops = nes_uctx_ops;
> nesvctx->max_pds = resp.max_pds;
> nesvctx->max_qps = resp.max_qps;
> nesvctx->wq_size = resp.wq_size;
> @@ -148,16 +145,17 @@ static struct ibv_context *nes_ualloc_context(struct ibv_device *ibdev, int cmd_
> nesvctx->mcrqf = 0;
>
> /* Get a doorbell region for the CQs */
> - ibv_pd = nes_ualloc_pd(&nesvctx->ibv_ctx);
> + ibv_pd = nes_ualloc_pd(&nesvctx->ibv_ctx.context);
> if (!ibv_pd)
> goto err_free;
> - ibv_pd->context = &nesvctx->ibv_ctx;
> + ibv_pd->context = &nesvctx->ibv_ctx.context;
> nesvctx->nesupd = to_nes_upd(ibv_pd);
>
> return &nesvctx->ibv_ctx;
>
> err_free:
> fprintf(stderr, PFX "%s: Failed to allocate context for device.\n", __FUNCTION__);
> + verbs_uninit_context(&nesvctx->ibv_ctx);
> free(nesvctx);
>
> return NULL;
> @@ -172,6 +170,7 @@ static void nes_ufree_context(struct ibv_context *ibctx)
> struct nes_uvcontext *nesvctx = to_nes_uctx(ibctx);
> nes_ufree_pd(&nesvctx->nesupd->ibv_pd);
>
> + verbs_uninit_context(&nesvctx->ibv_ctx);
> free(nesvctx);
> }
>
> diff --git a/providers/nes/nes_umain.h b/providers/nes/nes_umain.h
> index 0a832e7517bea6..2750c128d76ce7 100644
> --- a/providers/nes/nes_umain.h
> +++ b/providers/nes/nes_umain.h
> @@ -261,7 +261,7 @@ struct nes_upd {
> };
>
> struct nes_uvcontext {
> - struct ibv_context ibv_ctx;
> + struct verbs_context ibv_ctx;
> struct nes_upd *nesupd;
> uint32_t max_pds; /* maximum pds allowed for this user process */
> uint32_t max_qps; /* maximum qps allowed for this user process */
> @@ -331,7 +331,7 @@ static inline struct nes_udevice *to_nes_udev(struct ibv_device *ibdev)
>
> static inline struct nes_uvcontext *to_nes_uctx(struct ibv_context *ibctx)
> {
> - return to_nes_uxxx(ctx, vcontext);
> + return container_of(ibctx, struct nes_uvcontext, ibv_ctx.context);
> }
>
> static inline struct nes_upd *to_nes_upd(struct ibv_pd *ibpd)
> diff --git a/providers/ocrdma/ocrdma_main.c b/providers/ocrdma/ocrdma_main.c
> index afd5d79c1884c0..5bb17eb8665bfc 100644
> --- a/providers/ocrdma/ocrdma_main.c
> +++ b/providers/ocrdma/ocrdma_main.c
> @@ -105,27 +105,23 @@ static void ocrdma_uninit_device(struct verbs_device *verbs_device)
> /*
> * ocrdma_alloc_context
> */
> -static struct ibv_context *ocrdma_alloc_context(struct ibv_device *ibdev,
> - int cmd_fd)
> +static struct verbs_context *ocrdma_alloc_context(struct ibv_device *ibdev,
> + int cmd_fd)
> {
> struct ocrdma_devctx *ctx;
> struct ocrdma_get_context cmd;
> struct ocrdma_alloc_ucontext_resp resp;
>
> - ctx = calloc(1, sizeof(struct ocrdma_devctx));
> + ctx = verbs_init_and_alloc_context(ibdev, cmd_fd, ctx, ibv_ctx);
> if (!ctx)
> return NULL;
> - memset(&resp, 0, sizeof(resp));
> -
> - ctx->ibv_ctx.cmd_fd = cmd_fd;
>
> if (ibv_cmd_get_context(&ctx->ibv_ctx,
> (struct ibv_get_context *)&cmd, sizeof cmd,
> &resp.ibv_resp, sizeof(resp)))
> goto cmd_err;
>
> - ctx->ibv_ctx.device = ibdev;
> - ctx->ibv_ctx.ops = ocrdma_ctx_ops;
> + ctx->ibv_ctx.context.ops = ocrdma_ctx_ops;
> get_ocrdma_dev(ibdev)->id = resp.dev_id;
> get_ocrdma_dev(ibdev)->max_inline_data = resp.max_inline_data;
> get_ocrdma_dev(ibdev)->wqe_size = resp.wqe_size;
> @@ -146,6 +142,7 @@ static struct ibv_context *ocrdma_alloc_context(struct ibv_device *ibdev,
>
> cmd_err:
> ocrdma_err("%s: Failed to allocate context for device.\n", __func__);
> + verbs_uninit_context(&ctx->ibv_ctx);
> free(ctx);
> return NULL;
> }
> @@ -160,6 +157,7 @@ static void ocrdma_free_context(struct ibv_context *ibctx)
> if (ctx->ah_tbl)
> munmap((void *)ctx->ah_tbl, ctx->ah_tbl_len);
>
> + verbs_uninit_context(&ctx->ibv_ctx);
> free(ctx);
> }
>
> diff --git a/providers/ocrdma/ocrdma_main.h b/providers/ocrdma/ocrdma_main.h
> index e5b2860f9dc45c..e414223d07cd83 100644
> --- a/providers/ocrdma/ocrdma_main.h
> +++ b/providers/ocrdma/ocrdma_main.h
> @@ -68,7 +68,7 @@ struct ocrdma_device {
> };
>
> struct ocrdma_devctx {
> - struct ibv_context ibv_ctx;
> + struct verbs_context ibv_ctx;
> uint32_t *ah_tbl;
> uint32_t ah_tbl_len;
> pthread_mutex_t tbl_lock;
> @@ -231,7 +231,7 @@ struct ocrdma_ah {
>
> static inline struct ocrdma_devctx *get_ocrdma_ctx(struct ibv_context *ibctx)
> {
> - return get_ocrdma_xxx(ctx, devctx);
> + return container_of(ibctx, struct ocrdma_devctx, ibv_ctx.context);
> }
>
> static inline struct ocrdma_device *get_ocrdma_dev(struct ibv_device *ibdev)
> diff --git a/providers/qedr/qelr.h b/providers/qedr/qelr.h
> index b3faa0044137d8..faa8e99cfa0798 100644
> --- a/providers/qedr/qelr.h
> +++ b/providers/qedr/qelr.h
> @@ -118,7 +118,7 @@ struct qelr_device {
> };
>
> struct qelr_devctx {
> - struct ibv_context ibv_ctx;
> + struct verbs_context ibv_ctx;
> FILE *dbg_fp;
> void *db_addr;
> uint64_t db_pa;
> @@ -251,7 +251,7 @@ struct qelr_qp {
>
> static inline struct qelr_devctx *get_qelr_ctx(struct ibv_context *ibctx)
> {
> - return container_of(ibctx, struct qelr_devctx, ibv_ctx);
> + return container_of(ibctx, struct qelr_devctx, ibv_ctx.context);
> }
>
> static inline struct qelr_device *get_qelr_dev(struct ibv_device *ibdev)
> diff --git a/providers/qedr/qelr_main.c b/providers/qedr/qelr_main.c
> index 4d62442a58dcb7..92a635cdcfca94 100644
> --- a/providers/qedr/qelr_main.c
> +++ b/providers/qedr/qelr_main.c
> @@ -155,19 +155,18 @@ static void qelr_set_debug_mask(void)
> qelr_dp_module = atoi(env);
> }
>
> -static struct ibv_context *qelr_alloc_context(struct ibv_device *ibdev,
> - int cmd_fd)
> +static struct verbs_context *qelr_alloc_context(struct ibv_device *ibdev,
> + int cmd_fd)
> {
> struct qelr_devctx *ctx;
> struct qelr_get_context cmd;
> struct qelr_alloc_ucontext_resp resp;
>
> - ctx = calloc(1, sizeof(struct qelr_devctx));
> + ctx = verbs_init_and_alloc_context(ibdev, cmd_fd, ctx, ibv_ctx);
> if (!ctx)
> return NULL;
> - memset(&resp, 0, sizeof(resp));
>
> - ctx->ibv_ctx.cmd_fd = cmd_fd;
> + memset(&resp, 0, sizeof(resp));
>
> qelr_open_debug_file(ctx);
> qelr_set_debug_mask();
> @@ -178,8 +177,7 @@ static struct ibv_context *qelr_alloc_context(struct ibv_device *ibdev,
> goto cmd_err;
>
> ctx->kernel_page_size = sysconf(_SC_PAGESIZE);
> - ctx->ibv_ctx.device = ibdev;
> - ctx->ibv_ctx.ops = qelr_ctx_ops;
> + ctx->ibv_ctx.context.ops = qelr_ctx_ops;
> ctx->db_pa = resp.db_pa;
> ctx->db_size = resp.db_size;
> ctx->max_send_wr = resp.max_send_wr;
> @@ -205,6 +203,7 @@ static struct ibv_context *qelr_alloc_context(struct ibv_device *ibdev,
> cmd_err:
> qelr_err("%s: Failed to allocate context for device.\n", __func__);
> qelr_close_debug_file(ctx);
> + verbs_uninit_context(&ctx->ibv_ctx);
> free(ctx);
> return NULL;
> }
> @@ -217,6 +216,7 @@ static void qelr_free_context(struct ibv_context *ibctx)
> munmap(ctx->db_addr, ctx->db_size);
>
> qelr_close_debug_file(ctx);
> + verbs_uninit_context(&ctx->ibv_ctx);
> free(ctx);
> }
>
> diff --git a/providers/qedr/qelr_verbs.c b/providers/qedr/qelr_verbs.c
> index 7db0fb3216dde9..5d7aeb37453c44 100644
> --- a/providers/qedr/qelr_verbs.c
> +++ b/providers/qedr/qelr_verbs.c
> @@ -887,7 +887,7 @@ static inline void qelr_init_dpm_info(struct qelr_devctx *cxt,
> dpm->is_edpm = 0;
>
> /* Currently dpm is not supported for iWARP */
> - if (IS_IWARP(cxt->ibv_ctx.device))
> + if (IS_IWARP(cxt->ibv_ctx.context.device))
> return;
>
> if (qelr_chain_is_full(&qp->sq.chain) &&
> diff --git a/providers/rxe/rxe.c b/providers/rxe/rxe.c
> index 683ffaa2a8af9c..5cfdf1aac08a86 100644
> --- a/providers/rxe/rxe.c
> +++ b/providers/rxe/rxe.c
> @@ -858,29 +858,27 @@ static struct ibv_context_ops rxe_ctx_ops = {
> .detach_mcast = ibv_cmd_detach_mcast
> };
>
> -static struct ibv_context *rxe_alloc_context(struct ibv_device *ibdev,
> - int cmd_fd)
> +static struct verbs_context *rxe_alloc_context(struct ibv_device *ibdev,
> + int cmd_fd)
> {
> struct rxe_context *context;
> struct ibv_get_context cmd;
> struct ibv_get_context_resp resp;
>
> - context = malloc(sizeof *context);
> + context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx);
> if (!context)
> return NULL;
>
> - memset(context, 0, sizeof *context);
> - context->ibv_ctx.cmd_fd = cmd_fd;
> -
> if (ibv_cmd_get_context(&context->ibv_ctx, &cmd,
> sizeof cmd, &resp, sizeof resp))
> goto out;
>
> - context->ibv_ctx.ops = rxe_ctx_ops;
> + context->ibv_ctx.context.ops = rxe_ctx_ops;
>
> return &context->ibv_ctx;
>
> out:
> + verbs_uninit_context(&context->ibv_ctx);
> free(context);
> return NULL;
> }
> @@ -889,6 +887,7 @@ static void rxe_free_context(struct ibv_context *ibctx)
> {
> struct rxe_context *context = to_rctx(ibctx);
>
> + verbs_uninit_context(&context->ibv_ctx);
> free(context);
> }
>
> diff --git a/providers/rxe/rxe.h b/providers/rxe/rxe.h
> index 1f331662b2ba2d..3fc0436127e432 100644
> --- a/providers/rxe/rxe.h
> +++ b/providers/rxe/rxe.h
> @@ -54,7 +54,7 @@ struct rxe_device {
> };
>
> struct rxe_context {
> - struct ibv_context ibv_ctx;
> + struct verbs_context ibv_ctx;
> };
>
> struct rxe_cq {
> @@ -98,7 +98,7 @@ struct rxe_srq {
>
> static inline struct rxe_context *to_rctx(struct ibv_context *ibctx)
> {
> - return to_rxxx(ctx, context);
> + return container_of(ibctx, struct rxe_context, ibv_ctx.context);
> }
>
> static inline struct rxe_device *to_rdev(struct ibv_device *ibdev)
> diff --git a/providers/vmw_pvrdma/pvrdma.h b/providers/vmw_pvrdma/pvrdma.h
> index 3bcec1cb71d14d..58165cf434b721 100644
> --- a/providers/vmw_pvrdma/pvrdma.h
> +++ b/providers/vmw_pvrdma/pvrdma.h
> @@ -105,7 +105,7 @@ struct pvrdma_device {
> };
>
> struct pvrdma_context {
> - struct ibv_context ibv_ctx;
> + struct verbs_context ibv_ctx;
> void *uar;
> pthread_spinlock_t uar_lock;
> int max_qp_wr;
> @@ -201,7 +201,7 @@ static inline struct pvrdma_device *to_vdev(struct ibv_device *ibdev)
>
> static inline struct pvrdma_context *to_vctx(struct ibv_context *ibctx)
> {
> - return container_of(ibctx, struct pvrdma_context, ibv_ctx);
> + return container_of(ibctx, struct pvrdma_context, ibv_ctx.context);
> }
>
> static inline struct pvrdma_pd *to_vpd(struct ibv_pd *ibpd)
> diff --git a/providers/vmw_pvrdma/pvrdma_main.c b/providers/vmw_pvrdma/pvrdma_main.c
> index 17736cd0079036..08b1d4e6d34f07 100644
> --- a/providers/vmw_pvrdma/pvrdma_main.c
> +++ b/providers/vmw_pvrdma/pvrdma_main.c
> @@ -111,7 +111,7 @@ static int pvrdma_init_context_shared(struct pvrdma_context *context,
> struct ibv_get_context cmd;
> struct user_pvrdma_alloc_ucontext_resp resp;
>
> - context->ibv_ctx.cmd_fd = cmd_fd;
> + context->ibv_ctx.context.cmd_fd = cmd_fd;
> if (ibv_cmd_get_context(&context->ibv_ctx, &cmd, sizeof(cmd),
> &resp.ibv_resp, sizeof(resp)))
> return errno;
> @@ -129,7 +129,7 @@ static int pvrdma_init_context_shared(struct pvrdma_context *context,
> }
>
> pthread_spin_init(&context->uar_lock, PTHREAD_PROCESS_PRIVATE);
> - context->ibv_ctx.ops = pvrdma_ctx_ops;
> + context->ibv_ctx.context.ops = pvrdma_ctx_ops;
>
> return 0;
> }
> @@ -141,18 +141,17 @@ static void pvrdma_free_context_shared(struct pvrdma_context *context,
> free(context->qp_tbl);
> }
>
> -static struct ibv_context *pvrdma_alloc_context(struct ibv_device *ibdev,
> - int cmd_fd)
> +static struct verbs_context *pvrdma_alloc_context(struct ibv_device *ibdev,
> + int cmd_fd)
> {
> struct pvrdma_context *context;
>
> - context = malloc(sizeof(*context));
> + context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx);
> if (!context)
> return NULL;
>
> - memset(context, 0, sizeof(*context));
> -
> if (pvrdma_init_context_shared(context, ibdev, cmd_fd)) {
> + verbs_uninit_context(&context->ibv_ctx);
> free(context);
> return NULL;
> }
> @@ -165,6 +164,7 @@ static void pvrdma_free_context(struct ibv_context *ibctx)
> struct pvrdma_context *context = to_vctx(ibctx);
>
> pvrdma_free_context_shared(context, to_vdev(ibctx->device));
> + verbs_uninit_context(&context->ibv_ctx);
> free(context);
> }
>
> --
> 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
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 2/8] bnxt_re: Convert from init_context to alloc_context
[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>
0 siblings, 1 reply; 20+ messages in thread
From: Devesh Sharma @ 2018-01-10 5:53 UTC (permalink / raw)
To: Jason Gunthorpe; +Cc: linux-rdma, Jason Gunthorpe
On Tue, Jan 9, 2018 at 2:56 AM, Jason Gunthorpe <jgg-uk2M96/98Pc@public.gmane.org> wrote:
> 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
>
Looks good, will test and comeback if there are any failures seen.
Reveiwed-By: Devesh Sharma <devesh.sharma-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>
--
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
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 5/8] verbs: Remove init_context/uninit_context
[not found] ` <20180108212632.5183-6-jgg-uk2M96/98Pc@public.gmane.org>
@ 2018-01-10 5:59 ` Devesh Sharma
0 siblings, 0 replies; 20+ messages in thread
From: Devesh Sharma @ 2018-01-10 5:59 UTC (permalink / raw)
To: Jason Gunthorpe; +Cc: linux-rdma, Jason Gunthorpe, Doug Ledford, Yishai Hadas
On Tue, Jan 9, 2018 at 2:56 AM, Jason Gunthorpe <jgg-uk2M96/98Pc@public.gmane.org> wrote:
> From: Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
>
> All providers now use the alloc_context interface and support
> verbs_context. Remove the dead code.
>
> Signed-off-by: Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
> ---
> libibverbs/device.c | 39 ++-------------------------------------
> libibverbs/driver.h | 9 ---------
> providers/bnxt_re/main.c | 4 ----
> providers/mlx4/mlx4.c | 4 ----
> providers/mlx5/mlx5.c | 4 ----
> 5 files changed, 2 insertions(+), 58 deletions(-)
>
> diff --git a/libibverbs/device.c b/libibverbs/device.c
> index e42e37bd0a1f8d..db6dae5b25af59 100644
> --- a/libibverbs/device.c
> +++ b/libibverbs/device.c
> @@ -259,29 +259,6 @@ err_free:
> return NULL;
> }
>
> -/* Use the init_context flow to create a verbs_context */
> -static struct verbs_context *alloc_context(struct verbs_device *device,
> - int cmd_fd)
> -{
> - struct verbs_context *context;
> -
> - context = _verbs_init_and_alloc_context(
> - &device->device, cmd_fd,
> - sizeof(*context) + device->size_of_context, NULL);
> - if (!context)
> - return NULL;
> -
> - if (device->ops->init_context(device, &context->context, cmd_fd))
> - goto err_uninit;
> -
> - return context;
> -
> -err_uninit:
> - verbs_uninit_context(context);
> - free(context);
> - return NULL;
> -}
> -
> LATEST_SYMVER_FUNC(ibv_open_device, 1_1, "IBVERBS_1.1",
> struct ibv_context *,
> struct ibv_device *device)
> @@ -304,15 +281,11 @@ LATEST_SYMVER_FUNC(ibv_open_device, 1_1, "IBVERBS_1.1",
> if (cmd_fd < 0)
> return NULL;
>
> - if (!verbs_device->ops->init_context)
> - context_ex = verbs_device->ops->alloc_context(device, cmd_fd);
> - else
> - context_ex = alloc_context(verbs_device, cmd_fd);
> -
> /*
> * cmd_fd ownership is transferred into alloc_context, if it fails
> * then it closes cmd_fd and returns NULL
> */
> + context_ex = verbs_device->ops->alloc_context(device, cmd_fd);
> if (context_ex == NULL)
> return NULL;
>
> @@ -338,15 +311,7 @@ LATEST_SYMVER_FUNC(ibv_close_device, 1_1, "IBVERBS_1.1",
> {
> struct verbs_device *verbs_device = verbs_get_device(context->device);
>
> - if (verbs_device->ops->uninit_context) {
> - struct verbs_context *context_ex =
> - container_of(context, struct verbs_context, context);
> -
> - verbs_device->ops->uninit_context(verbs_device, context);
> - verbs_uninit_context(context_ex);
> - } else {
> - verbs_device->ops->free_context(context);
> - }
> + verbs_device->ops->free_context(context);
>
> return 0;
> }
> diff --git a/libibverbs/driver.h b/libibverbs/driver.h
> index 809c4f5c8cdf39..00847a41bc468e 100644
> --- a/libibverbs/driver.h
> +++ b/libibverbs/driver.h
> @@ -152,17 +152,10 @@ struct verbs_device_ops {
>
> bool (*match_device)(struct verbs_sysfs_dev *sysfs_dev);
>
> - /* Old interface, do not use in new code. */
> struct verbs_context *(*alloc_context)(struct ibv_device *device,
> int cmd_fd);
> void (*free_context)(struct ibv_context *context);
>
> - /* New interface */
> - int (*init_context)(struct verbs_device *device,
> - struct ibv_context *ctx, int cmd_fd);
> - void (*uninit_context)(struct verbs_device *device,
> - struct ibv_context *ctx);
> -
> struct verbs_device *(*alloc_device)(struct verbs_sysfs_dev *sysfs_dev);
> void (*uninit_device)(struct verbs_device *device);
> };
> @@ -171,8 +164,6 @@ struct verbs_device_ops {
> struct verbs_device {
> struct ibv_device device; /* Must be first */
> const struct verbs_device_ops *ops;
> - size_t sz;
> - size_t size_of_context;
> atomic_int refcount;
> struct list_node entry;
> struct verbs_sysfs_dev *sysfs;
> diff --git a/providers/bnxt_re/main.c b/providers/bnxt_re/main.c
> index c225f09eaa58f7..d689b392d05b5d 100644
> --- a/providers/bnxt_re/main.c
> +++ b/providers/bnxt_re/main.c
> @@ -179,10 +179,6 @@ bnxt_re_device_alloc(struct verbs_sysfs_dev *sysfs_dev)
> if (!dev)
> return NULL;
>
> - dev->vdev.sz = sizeof(*dev);
> - dev->vdev.size_of_context =
> - sizeof(struct bnxt_re_context) - sizeof(struct ibv_context);
> -
Looks good, for bnxt_re provider:
Reviewed-By: Devesh Sharma <devesh.sharma-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>
> return &dev->vdev;
> }
>
> diff --git a/providers/mlx4/mlx4.c b/providers/mlx4/mlx4.c
> index 3d64b8c8ebae65..f0d63b57792602 100644
> --- a/providers/mlx4/mlx4.c
> +++ b/providers/mlx4/mlx4.c
> @@ -298,10 +298,6 @@ static struct verbs_device *mlx4_device_alloc(struct verbs_sysfs_dev *sysfs_dev)
> dev->page_size = sysconf(_SC_PAGESIZE);
> dev->abi_version = sysfs_dev->abi_ver;
>
> - dev->verbs_dev.sz = sizeof(*dev);
> - dev->verbs_dev.size_of_context =
> - sizeof(struct mlx4_context) - sizeof(struct ibv_context);
> -
> return &dev->verbs_dev;
> }
>
> diff --git a/providers/mlx5/mlx5.c b/providers/mlx5/mlx5.c
> index 7e8dc9b1951192..41b484fce29683 100644
> --- a/providers/mlx5/mlx5.c
> +++ b/providers/mlx5/mlx5.c
> @@ -1099,10 +1099,6 @@ static struct verbs_device *mlx5_device_alloc(struct verbs_sysfs_dev *sysfs_dev)
> dev->page_size = sysconf(_SC_PAGESIZE);
> dev->driver_abi_ver = sysfs_dev->abi_ver;
>
> - dev->verbs_dev.sz = sizeof(*dev);
> - dev->verbs_dev.size_of_context = sizeof(struct mlx5_context) -
> - sizeof(struct ibv_context);
> -
> return &dev->verbs_dev;
> }
>
> --
> 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
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 1/8] verbs: Always allocate a verbs_context
[not found] ` <CANjDDBjCUtdVcQBze0PVjC5EaXj5BGTQ5tcn6VcuG0P7auuxoA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2018-01-10 17:34 ` Jason Gunthorpe
[not found] ` <20180110173427.GE4776-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
0 siblings, 1 reply; 20+ messages in thread
From: Jason Gunthorpe @ 2018-01-10 17:34 UTC (permalink / raw)
To: Devesh Sharma
Cc: linux-rdma, Benjamin Drung, Doug Ledford, Yishai Hadas,
Steve Wise, Mike Marciniszyn, Dennis Dalessandro, Lijun Ou,
Wei Hu(Xavier), Tatyana Nikolova, Vladimir Sokolovsky, Ram Amrani,
Ariel Elior, Moni Shoua, Adit Ranadive, Leon Romanovsky,
Nicolas Morey-Chaisemartin, Alexey Brodkin, Bar
On Wed, Jan 10, 2018 at 11:16:20AM +0530, Devesh Sharma wrote:
> > +/*
> > + * Allocate and initialize a context structure. This is called to create the
> > + * driver wrapper, and context_offset is the number of bytes into the wrapper
> > + * structure where the verbs_context starts.
> > + */
> > +void *_verbs_init_and_alloc_context(struct ibv_device *device, int cmd_fd,
> > + size_t alloc_size,
> > + struct verbs_context *context_offset)
> > +{
> > + void *drv_context;
> > + struct verbs_context *context;
> > +
> > + drv_context = calloc(1, alloc_size);
> > + if (!drv_context) {
> > + errno = ENOMEM;
> > + close(cmd_fd);
> > + return NULL;
> > + }
> > +
> > + context = (struct verbs_context *)((uint8_t *)drv_context +
> > + (uintptr_t)context_offset);
>
> A wrapper macro would do better here?
What would we call it? It is kinda of a reverse container of
Thing is, this is the only place that does this calculation and it is
intimately tied to the definition of the
verbs_init_and_alloc_context() macro, so it really is unique and
special to this function.
To elaborate on what is happening here..
The driver calls
cntx = verbs_init_and_alloc_context(vdev, cmd_fd, cntx, ibvctx);
Where:
struct bnxt_re_context *cntx;
And the name 'ibvctx' is like container_of, where it refers to the
struct member inside cntx:
struct bnxt_re_context {
struct verbs_context ibvctx;
This allows the allocation function to both return the 'struct
bnxt_re_context' and find the 'struct verbs_context' where the driver
placed it.
The alternative here is to force the driver to put the verbs_context
at the start of the struct, then eliminate the context_offset entirely
and replace it with a static assert scheme.
Do you think that is nicer?
Jason
--
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
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 2/8] bnxt_re: Convert from init_context to alloc_context
[not found] ` <CANjDDBjwmtO2aOtY5NCObrU_VJVmHjw=fdJOk_VvfZx+8+4Ejw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2018-01-10 17:36 ` Jason Gunthorpe
0 siblings, 0 replies; 20+ messages in thread
From: Jason Gunthorpe @ 2018-01-10 17:36 UTC (permalink / raw)
To: Devesh Sharma; +Cc: linux-rdma
On Wed, Jan 10, 2018 at 11:23:16AM +0530, Devesh Sharma wrote:
> Looks good, will test and comeback if there are any failures seen.
> Reveiwed-By: Devesh Sharma <devesh.sharma-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>
Thanks!
I didn't find any bugs when I first tested it, so I have optimisim
that the compiler static analysis is containing most of the mess :)
Jason
--
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
^ permalink raw reply [flat|nested] 20+ messages in thread
* RE: [PATCH rdma-core 0/8] Revise provider initialization
[not found] ` <20180108212632.5183-1-jgg-uk2M96/98Pc@public.gmane.org>
` (7 preceding siblings ...)
2018-01-08 21:26 ` [PATCH 8/8] verbs: Remove tests for NULL ops Jason Gunthorpe
@ 2018-01-10 22:05 ` Steve Wise
2018-01-10 22:06 ` Steve Wise
2018-01-10 22:27 ` Jason Gunthorpe
8 siblings, 2 replies; 20+ messages in thread
From: Steve Wise @ 2018-01-10 22:05 UTC (permalink / raw)
To: 'Jason Gunthorpe', linux-rdma-u79uwXL29TY76Z2rM5mHXA
Cc: 'Jason Gunthorpe'
>
> From: Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
>
> This make all the context creation uniform by having every driver create a
> struct verbs_context using the same startup flow.
>
> Long ago we had a new and old flow, where the new flow was intended to
> support
> a stable provider ABI, but now that the ABI is private we do not need
that.
>
> By having every single provider having a verbs_context we can now rely on
> things like the priv existing and a sane init ordering where the priv can
> exist even before the first command runs.
>
> Having priv always available is a necessary component to introduce support
for
> the new ioctl kabi.
>
> Finally, the last three patches rework the ops setup to use a struct of
> function pointers scheme and provides defaults for every function. The
> defaults return ENOSYS which fixes a bunch of cases where the user could
have
> called a function without driver support and got a crash.
>
> This is github PR:
>
> https://github.com/linux-rdma/rdma-core/pull/281
>
> Jason Gunthorpe (8):
> verbs: Always allocate a verbs_context
> bnxt_re: Convert from init_context to alloc_context
> mlx4: Convert from init_context to alloc_context
> mlx5: Convert from init_context to alloc_context
> verbs: Remove init_context/uninit_context
> verbs: Provide a default implementation for every verbs op
> verbs: Convert all providers to use verbs_set_ops
> verbs: Remove tests for NULL ops
Hey Jason,
For what it's worth, I built your ops_fix branch and tested over cxgb4.
Working worked, no problems.
Tested-by: Steve Wise <swise-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW@public.gmane.org>
Steve.
--
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
^ permalink raw reply [flat|nested] 20+ messages in thread
* RE: [PATCH rdma-core 0/8] Revise provider initialization
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
1 sibling, 0 replies; 20+ messages in thread
From: Steve Wise @ 2018-01-10 22:06 UTC (permalink / raw)
To: 'Jason Gunthorpe', linux-rdma-u79uwXL29TY76Z2rM5mHXA
Cc: 'Jason Gunthorpe'
> Hey Jason,
>
> For what it's worth, I built your ops_fix branch and tested over cxgb4.
> Working worked, no problems.
Eh, that's "rping worked..."
>
> Tested-by: Steve Wise <swise-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW@public.gmane.org>
>
> Steve.
>
> --
> 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
--
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
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH rdma-core 0/8] Revise provider initialization
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
1 sibling, 0 replies; 20+ messages in thread
From: Jason Gunthorpe @ 2018-01-10 22:27 UTC (permalink / raw)
To: Steve Wise; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA
On Wed, Jan 10, 2018 at 04:05:50PM -0600, Steve Wise wrote:
> For what it's worth, I built your ops_fix branch and tested over cxgb4.
> Working worked, no problems.
>
> Tested-by: Steve Wise <swise-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW@public.gmane.org>
Thanks, rping probably covers most of the areas I could have messed up
:)
Jason
--
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
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 1/8] verbs: Always allocate a verbs_context
[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>
0 siblings, 1 reply; 20+ messages in thread
From: Devesh Sharma @ 2018-01-11 17:44 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: linux-rdma, Benjamin Drung, Doug Ledford, Yishai Hadas,
Steve Wise, Mike Marciniszyn, Dennis Dalessandro, Lijun Ou,
Wei Hu(Xavier), Tatyana Nikolova, Vladimir Sokolovsky, Ram Amrani,
Ariel Elior, Moni Shoua, Adit Ranadive, Leon Romanovsky,
Nicolas Morey-Chaisemartin, Alexey Brodkin, Bar
On Wed, Jan 10, 2018 at 11:04 PM, Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org> wrote:
> On Wed, Jan 10, 2018 at 11:16:20AM +0530, Devesh Sharma wrote:
>
>> > +/*
>> > + * Allocate and initialize a context structure. This is called to create the
>> > + * driver wrapper, and context_offset is the number of bytes into the wrapper
>> > + * structure where the verbs_context starts.
>> > + */
>> > +void *_verbs_init_and_alloc_context(struct ibv_device *device, int cmd_fd,
>> > + size_t alloc_size,
>> > + struct verbs_context *context_offset)
>> > +{
>> > + void *drv_context;
>> > + struct verbs_context *context;
>> > +
>> > + drv_context = calloc(1, alloc_size);
>> > + if (!drv_context) {
>> > + errno = ENOMEM;
>> > + close(cmd_fd);
>> > + return NULL;
>> > + }
>> > +
>> > + context = (struct verbs_context *)((uint8_t *)drv_context +
>> > + (uintptr_t)context_offset);
>>
>> A wrapper macro would do better here?
>
> What would we call it? It is kinda of a reverse container of
may be get_ibverbs_context()
>
> Thing is, this is the only place that does this calculation and it is
> intimately tied to the definition of the
> verbs_init_and_alloc_context() macro, so it really is unique and
> special to this function.
If that is the case I don't mind leaving this as it is, may be it
would look better from code readability point of view if we wrap it.
>
> To elaborate on what is happening here..
>
> The driver calls
>
> cntx = verbs_init_and_alloc_context(vdev, cmd_fd, cntx, ibvctx);
>
> Where:
> struct bnxt_re_context *cntx;
>
> And the name 'ibvctx' is like container_of, where it refers to the
> struct member inside cntx:
>
> struct bnxt_re_context {
> struct verbs_context ibvctx;
>
> This allows the allocation function to both return the 'struct
> bnxt_re_context' and find the 'struct verbs_context' where the driver
> placed it.
>
> The alternative here is to force the driver to put the verbs_context
> at the start of the struct, then eliminate the context_offset entirely
> and replace it with a static assert scheme.
>
> Do you think that is nicer?
If there are no specific reasons to allow drivers to put this struct
anywhere in their defs,
then things could be simpler verb_context is placed in the beginning.
>
> Jason
--
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
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 1/8] verbs: Always allocate a verbs_context
[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>
0 siblings, 1 reply; 20+ messages in thread
From: Jason Gunthorpe @ 2018-01-11 17:54 UTC (permalink / raw)
To: Devesh Sharma
Cc: linux-rdma, Benjamin Drung, Doug Ledford, Yishai Hadas,
Steve Wise, Mike Marciniszyn, Dennis Dalessandro, Lijun Ou,
Wei Hu(Xavier), Tatyana Nikolova, Vladimir Sokolovsky, Ram Amrani,
Ariel Elior, Moni Shoua, Adit Ranadive, Leon Romanovsky,
Nicolas Morey-Chaisemartin, Alexey Brodkin, Bar
On Thu, Jan 11, 2018 at 11:14:33PM +0530, Devesh Sharma wrote:
> On Wed, Jan 10, 2018 at 11:04 PM, Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org> wrote:
> > On Wed, Jan 10, 2018 at 11:16:20AM +0530, Devesh Sharma wrote:
> >
> >> > +/*
> >> > + * Allocate and initialize a context structure. This is called to create the
> >> > + * driver wrapper, and context_offset is the number of bytes into the wrapper
> >> > + * structure where the verbs_context starts.
> >> > + */
> >> > +void *_verbs_init_and_alloc_context(struct ibv_device *device, int cmd_fd,
> >> > + size_t alloc_size,
> >> > + struct verbs_context *context_offset)
> >> > +{
> >> > + void *drv_context;
> >> > + struct verbs_context *context;
> >> > +
> >> > + drv_context = calloc(1, alloc_size);
> >> > + if (!drv_context) {
> >> > + errno = ENOMEM;
> >> > + close(cmd_fd);
> >> > + return NULL;
> >> > + }
> >> > +
> >> > + context = (struct verbs_context *)((uint8_t *)drv_context +
> >> > + (uintptr_t)context_offset);
> >>
> >> A wrapper macro would do better here?
> > Thing is, this is the only place that does this calculation and it is
> > intimately tied to the definition of the
> > verbs_init_and_alloc_context() macro, so it really is unique and
> > special to this function.
>
> If that is the case I don't mind leaving this as it is, may be it
> would look better from code readability point of view if we wrap it.
Maybe I should just embrace the Pointer-Arith gcc extension:
context = drv_context + (uintptr_t)context_offset;
Have to check first how prevalent it is already in the code.
Jason
--
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
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 1/8] verbs: Always allocate a verbs_context
[not found] ` <20180111175422.GG30208-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
@ 2018-01-12 11:08 ` Devesh Sharma
0 siblings, 0 replies; 20+ messages in thread
From: Devesh Sharma @ 2018-01-12 11:08 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: linux-rdma, Benjamin Drung, Doug Ledford, Yishai Hadas,
Steve Wise, Mike Marciniszyn, Dennis Dalessandro, Lijun Ou,
Wei Hu(Xavier), Tatyana Nikolova, Vladimir Sokolovsky, Ram Amrani,
Ariel Elior, Moni Shoua, Adit Ranadive, Leon Romanovsky,
Nicolas Morey-Chaisemartin, Alexey Brodkin, Bar
On Thu, Jan 11, 2018 at 11:24 PM, Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org> wrote:
> On Thu, Jan 11, 2018 at 11:14:33PM +0530, Devesh Sharma wrote:
>> On Wed, Jan 10, 2018 at 11:04 PM, Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org> wrote:
>> > On Wed, Jan 10, 2018 at 11:16:20AM +0530, Devesh Sharma wrote:
>> >
>> >> > +/*
>> >> > + * Allocate and initialize a context structure. This is called to create the
>> >> > + * driver wrapper, and context_offset is the number of bytes into the wrapper
>> >> > + * structure where the verbs_context starts.
>> >> > + */
>> >> > +void *_verbs_init_and_alloc_context(struct ibv_device *device, int cmd_fd,
>> >> > + size_t alloc_size,
>> >> > + struct verbs_context *context_offset)
>> >> > +{
>> >> > + void *drv_context;
>> >> > + struct verbs_context *context;
>> >> > +
>> >> > + drv_context = calloc(1, alloc_size);
>> >> > + if (!drv_context) {
>> >> > + errno = ENOMEM;
>> >> > + close(cmd_fd);
>> >> > + return NULL;
>> >> > + }
>> >> > +
>> >> > + context = (struct verbs_context *)((uint8_t *)drv_context +
>> >> > + (uintptr_t)context_offset);
>> >>
>> >> A wrapper macro would do better here?
>
>> > Thing is, this is the only place that does this calculation and it is
>> > intimately tied to the definition of the
>> > verbs_init_and_alloc_context() macro, so it really is unique and
>> > special to this function.
>>
>> If that is the case I don't mind leaving this as it is, may be it
>> would look better from code readability point of view if we wrap it.
>
> Maybe I should just embrace the Pointer-Arith gcc extension:
>
> context = drv_context + (uintptr_t)context_offset;
>
> Have to check first how prevalent it is already in the code.
>
Okay..
> Jason
--
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
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2018-01-12 11:08 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox