Commit 30471d4b authored by Leon Romanovsky's avatar Leon Romanovsky Committed by Jason Gunthorpe

RDMA/core: Share driver structure size with core

Add new macros to be used in drivers while registering ops structure and
IB/core while calling allocation routines, so drivers won't need to
perform kzalloc/kfree in their paths.

The change in allocation stage allows us to initialize common fields prior
to calling to drivers (e.g. restrack).
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent c66f6741
...@@ -1228,6 +1228,8 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops) ...@@ -1228,6 +1228,8 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
(ptr)->name = ops->name; \ (ptr)->name = ops->name; \
} while (0) } while (0)
#define SET_OBJ_SIZE(ptr, name) SET_DEVICE_OP(ptr, size_##name)
SET_DEVICE_OP(dev_ops, add_gid); SET_DEVICE_OP(dev_ops, add_gid);
SET_DEVICE_OP(dev_ops, advise_mr); SET_DEVICE_OP(dev_ops, advise_mr);
SET_DEVICE_OP(dev_ops, alloc_dm); SET_DEVICE_OP(dev_ops, alloc_dm);
......
...@@ -2264,6 +2264,19 @@ struct ib_counters_read_attr { ...@@ -2264,6 +2264,19 @@ struct ib_counters_read_attr {
struct uverbs_attr_bundle; struct uverbs_attr_bundle;
#define INIT_RDMA_OBJ_SIZE(ib_struct, drv_struct, member) \
.size_##ib_struct = \
(sizeof(struct drv_struct) + \
BUILD_BUG_ON_ZERO(offsetof(struct drv_struct, member)) + \
BUILD_BUG_ON_ZERO( \
!__same_type(((struct drv_struct *)NULL)->member, \
struct ib_struct)))
#define rdma_zalloc_drv_obj(ib_dev, ib_type) \
((struct ib_type *)kzalloc(ib_dev->ops.size_##ib_type, GFP_KERNEL))
#define DECLARE_RDMA_OBJ_SIZE(ib_struct) size_t size_##ib_struct
/** /**
* struct ib_device_ops - InfiniBand device operations * struct ib_device_ops - InfiniBand device operations
* This structure defines all the InfiniBand device operations, providers will * This structure defines all the InfiniBand device operations, providers will
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment