提交 6c61d2a5 编写于 作者: J Jason Gunthorpe

RDMA/uverbs: Simplify UVERBS_OBJECT and _TREE family of macros

Instead of the large set of indirecting macros, define the few needed
macros to directly instantiate the struct uverbs_oject_tree_def and
associated objects list.

This is small amount of code duplication but the readability is far
better.
Signed-off-by: NJason Gunthorpe <jgg@mellanox.com>
Signed-off-by: NLeon Romanovsky <leonro@mellanox.com>
上级 595c7736
...@@ -238,8 +238,6 @@ void ib_uverbs_detach_umcast(struct ib_qp *qp, ...@@ -238,8 +238,6 @@ void ib_uverbs_detach_umcast(struct ib_qp *qp,
struct ib_uqp_object *uobj); struct ib_uqp_object *uobj);
void create_udata(struct uverbs_attr_bundle *ctx, struct ib_udata *udata); void create_udata(struct uverbs_attr_bundle *ctx, struct ib_udata *udata);
extern const struct uverbs_attr_def uverbs_uhw_compat_in;
extern const struct uverbs_attr_def uverbs_uhw_compat_out;
long ib_uverbs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); long ib_uverbs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
int uverbs_destroy_def_handler(struct ib_device *ib_dev, int uverbs_destroy_def_handler(struct ib_device *ib_dev,
struct ib_uverbs_file *file, struct ib_uverbs_file *file,
......
...@@ -216,18 +216,6 @@ int uverbs_destroy_def_handler(struct ib_device *ib_dev, ...@@ -216,18 +216,6 @@ int uverbs_destroy_def_handler(struct ib_device *ib_dev,
return 0; return 0;
} }
/*
* This spec is used in order to pass information to the hardware driver in a
* legacy way. Every verb that could get driver specific data should get this
* spec.
*/
const struct uverbs_attr_def uverbs_uhw_compat_in =
UVERBS_ATTR_PTR_IN(UVERBS_ATTR_UHW_IN, UVERBS_ATTR_MIN_SIZE(0),
UA_FLAGS(UVERBS_ATTR_SPEC_F_MIN_SZ_OR_ZERO));
const struct uverbs_attr_def uverbs_uhw_compat_out =
UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_UHW_OUT, UVERBS_ATTR_MIN_SIZE(0),
UA_FLAGS(UVERBS_ATTR_SPEC_F_MIN_SZ_OR_ZERO));
void create_udata(struct uverbs_attr_bundle *ctx, struct ib_udata *udata) void create_udata(struct uverbs_attr_bundle *ctx, struct ib_udata *udata)
{ {
/* /*
...@@ -300,7 +288,7 @@ DECLARE_UVERBS_NAMED_OBJECT(UVERBS_OBJECT_PD, ...@@ -300,7 +288,7 @@ DECLARE_UVERBS_NAMED_OBJECT(UVERBS_OBJECT_PD,
DECLARE_UVERBS_NAMED_OBJECT(UVERBS_OBJECT_DEVICE, NULL); DECLARE_UVERBS_NAMED_OBJECT(UVERBS_OBJECT_DEVICE, NULL);
static DECLARE_UVERBS_OBJECT_TREE(uverbs_default_objects, DECLARE_UVERBS_OBJECT_TREE(uverbs_default_objects,
&UVERBS_OBJECT(UVERBS_OBJECT_DEVICE), &UVERBS_OBJECT(UVERBS_OBJECT_DEVICE),
&UVERBS_OBJECT(UVERBS_OBJECT_PD), &UVERBS_OBJECT(UVERBS_OBJECT_PD),
&UVERBS_OBJECT(UVERBS_OBJECT_MR), &UVERBS_OBJECT(UVERBS_OBJECT_MR),
......
...@@ -165,7 +165,7 @@ DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_CQ_CREATE, ...@@ -165,7 +165,7 @@ DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_CQ_CREATE,
&UVERBS_ATTR_PTR_IN(UVERBS_ATTR_CREATE_CQ_FLAGS, UVERBS_ATTR_TYPE(u32)), &UVERBS_ATTR_PTR_IN(UVERBS_ATTR_CREATE_CQ_FLAGS, UVERBS_ATTR_TYPE(u32)),
&UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_CREATE_CQ_RESP_CQE, UVERBS_ATTR_TYPE(u32), &UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_CREATE_CQ_RESP_CQE, UVERBS_ATTR_TYPE(u32),
UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY)), UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY)),
&uverbs_uhw_compat_in, &uverbs_uhw_compat_out); UVERBS_ATTR_UHW());
static int UVERBS_HANDLER(UVERBS_METHOD_CQ_DESTROY)(struct ib_device *ib_dev, static int UVERBS_HANDLER(UVERBS_METHOD_CQ_DESTROY)(struct ib_device *ib_dev,
struct ib_uverbs_file *file, struct ib_uverbs_file *file,
......
...@@ -1079,24 +1079,24 @@ DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_OBJ_QUERY, ...@@ -1079,24 +1079,24 @@ DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_OBJ_QUERY,
UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY | UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY |
UVERBS_ATTR_SPEC_F_MIN_SZ_OR_ZERO))); UVERBS_ATTR_SPEC_F_MIN_SZ_OR_ZERO)));
static DECLARE_UVERBS_GLOBAL_METHODS(MLX5_IB_OBJECT_DEVX, DECLARE_UVERBS_GLOBAL_METHODS(MLX5_IB_OBJECT_DEVX,
&UVERBS_METHOD(MLX5_IB_METHOD_DEVX_OTHER), &UVERBS_METHOD(MLX5_IB_METHOD_DEVX_OTHER),
&UVERBS_METHOD(MLX5_IB_METHOD_DEVX_QUERY_UAR), &UVERBS_METHOD(MLX5_IB_METHOD_DEVX_QUERY_UAR),
&UVERBS_METHOD(MLX5_IB_METHOD_DEVX_QUERY_EQN)); &UVERBS_METHOD(MLX5_IB_METHOD_DEVX_QUERY_EQN));
static DECLARE_UVERBS_NAMED_OBJECT(MLX5_IB_OBJECT_DEVX_OBJ, DECLARE_UVERBS_NAMED_OBJECT(MLX5_IB_OBJECT_DEVX_OBJ,
&UVERBS_TYPE_ALLOC_IDR(devx_obj_cleanup), &UVERBS_TYPE_ALLOC_IDR(devx_obj_cleanup),
&UVERBS_METHOD(MLX5_IB_METHOD_DEVX_OBJ_CREATE), &UVERBS_METHOD(MLX5_IB_METHOD_DEVX_OBJ_CREATE),
&UVERBS_METHOD(MLX5_IB_METHOD_DEVX_OBJ_DESTROY), &UVERBS_METHOD(MLX5_IB_METHOD_DEVX_OBJ_DESTROY),
&UVERBS_METHOD(MLX5_IB_METHOD_DEVX_OBJ_MODIFY), &UVERBS_METHOD(MLX5_IB_METHOD_DEVX_OBJ_MODIFY),
&UVERBS_METHOD(MLX5_IB_METHOD_DEVX_OBJ_QUERY)); &UVERBS_METHOD(MLX5_IB_METHOD_DEVX_OBJ_QUERY));
static DECLARE_UVERBS_NAMED_OBJECT(MLX5_IB_OBJECT_DEVX_UMEM, DECLARE_UVERBS_NAMED_OBJECT(MLX5_IB_OBJECT_DEVX_UMEM,
&UVERBS_TYPE_ALLOC_IDR(devx_umem_cleanup), &UVERBS_TYPE_ALLOC_IDR(devx_umem_cleanup),
&UVERBS_METHOD(MLX5_IB_METHOD_DEVX_UMEM_REG), &UVERBS_METHOD(MLX5_IB_METHOD_DEVX_UMEM_REG),
&UVERBS_METHOD(MLX5_IB_METHOD_DEVX_UMEM_DEREG)); &UVERBS_METHOD(MLX5_IB_METHOD_DEVX_UMEM_DEREG));
static DECLARE_UVERBS_OBJECT_TREE(devx_objects, DECLARE_UVERBS_OBJECT_TREE(devx_objects,
&UVERBS_OBJECT(MLX5_IB_OBJECT_DEVX), &UVERBS_OBJECT(MLX5_IB_OBJECT_DEVX),
&UVERBS_OBJECT(MLX5_IB_OBJECT_DEVX_OBJ), &UVERBS_OBJECT(MLX5_IB_OBJECT_DEVX_OBJ),
&UVERBS_OBJECT(MLX5_IB_OBJECT_DEVX_UMEM)); &UVERBS_OBJECT(MLX5_IB_OBJECT_DEVX_UMEM));
......
...@@ -253,33 +253,33 @@ struct uverbs_object_tree_def { ...@@ -253,33 +253,33 @@ struct uverbs_object_tree_def {
__VA_ARGS__ }, \ __VA_ARGS__ }, \
}) })
/*
* This spec is used in order to pass information to the hardware driver in a
* legacy way. Every verb that could get driver specific data should get this
* spec.
*/
#define UVERBS_ATTR_UHW() \
&UVERBS_ATTR_PTR_IN(UVERBS_ATTR_UHW_IN, \
UVERBS_ATTR_SIZE(0, USHRT_MAX), \
UA_FLAGS(UVERBS_ATTR_SPEC_F_MIN_SZ_OR_ZERO)), \
&UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_UHW_OUT, \
UVERBS_ATTR_SIZE(0, USHRT_MAX), \
UA_FLAGS(UVERBS_ATTR_SPEC_F_MIN_SZ_OR_ZERO))
/* /*
* ======================================= * =======================================
* Declaration helpers * Declaration helpers
* ======================================= * =======================================
*/ */
#define _UVERBS_OBJECT_METHODS_SZ(...) \
(sizeof((const struct uverbs_method_def * const []){__VA_ARGS__}) / \
sizeof(const struct uverbs_method_def *))
#define _UVERBS_OBJECT(_id, _type_attrs, ...) \
((const struct uverbs_object_def) { \
.id = _id, \
.type_attrs = _type_attrs, \
.num_methods = _UVERBS_OBJECT_METHODS_SZ(__VA_ARGS__), \
.methods = &(const struct uverbs_method_def * const []){__VA_ARGS__} })
#define DECLARE_UVERBS_OBJECT(_name, _id, _type_attrs, ...) \
const struct uverbs_object_def _name = \
_UVERBS_OBJECT(_id, _type_attrs, ##__VA_ARGS__)
#define _UVERBS_TREE_OBJECTS_SZ(...) \
(sizeof((const struct uverbs_object_def * const []){__VA_ARGS__}) / \
sizeof(const struct uverbs_object_def *))
#define _UVERBS_OBJECT_TREE(...) \
((const struct uverbs_object_tree_def) { \
.num_objects = _UVERBS_TREE_OBJECTS_SZ(__VA_ARGS__), \
.objects = &(const struct uverbs_object_def * const []){__VA_ARGS__} })
#define DECLARE_UVERBS_OBJECT_TREE(_name, ...) \ #define DECLARE_UVERBS_OBJECT_TREE(_name, ...) \
const struct uverbs_object_tree_def _name = \ static const struct uverbs_object_def *const _name##_ptr[] = { \
_UVERBS_OBJECT_TREE(__VA_ARGS__) __VA_ARGS__, \
}; \
static const struct uverbs_object_tree_def _name = { \
.num_objects = ARRAY_SIZE(_name##_ptr), \
.objects = &_name##_ptr, \
}
/* ================================================= /* =================================================
* Parsing infrastructure * Parsing infrastructure
......
...@@ -45,8 +45,9 @@ ...@@ -45,8 +45,9 @@
#define UVERBS_HANDLER(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _handler_##id) #define UVERBS_HANDLER(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _handler_##id)
#define UVERBS_OBJECT(id) _UVERBS_NAME(UVERBS_MOUDLE_NAME, _object_##id) #define UVERBS_OBJECT(id) _UVERBS_NAME(UVERBS_MOUDLE_NAME, _object_##id)
#define UVERBS_METHOD_ATTRS(id) \ /* These are static so they do not need to be qualified */
_UVERBS_NAME(UVERBS_MODULE_NAME, _method_attrs_##id) #define UVERBS_METHOD_ATTRS(method_id) _method_attrs_##method_id
#define UVERBS_OBJECT_METHODS(object_id) _object_methods_##object_id
#define DECLARE_UVERBS_NAMED_METHOD(_method_id, ...) \ #define DECLARE_UVERBS_NAMED_METHOD(_method_id, ...) \
static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \ static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \
...@@ -72,14 +73,19 @@ ...@@ -72,14 +73,19 @@
.attrs = &UVERBS_METHOD_ATTRS(_method_id), \ .attrs = &UVERBS_METHOD_ATTRS(_method_id), \
} }
#define DECLARE_UVERBS_NAMED_OBJECT(id, ...) \ #define DECLARE_UVERBS_NAMED_OBJECT(_object_id, _type_attrs, ...) \
DECLARE_UVERBS_OBJECT(UVERBS_OBJECT(id), id, ##__VA_ARGS__) static const struct uverbs_method_def *const UVERBS_OBJECT_METHODS( \
_object_id)[] = { __VA_ARGS__ }; \
const struct uverbs_object_def UVERBS_OBJECT(_object_id) = { \
.id = _object_id, \
.type_attrs = _type_attrs, \
.num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)), \
.methods = &UVERBS_OBJECT_METHODS(_object_id) \
}
#define DECLARE_UVERBS_GLOBAL_METHODS(_name, ...) \ #define DECLARE_UVERBS_GLOBAL_METHODS(_name, ...) \
DECLARE_UVERBS_NAMED_OBJECT(_name, NULL, ##__VA_ARGS__) DECLARE_UVERBS_NAMED_OBJECT(_name, NULL, ##__VA_ARGS__)
#define _UVERBS_COMP_NAME(x, y, z) _UVERBS_NAME(_UVERBS_NAME(x, y), z)
/* Used by drivers to declare a complete parsing tree for a single method that /* Used by drivers to declare a complete parsing tree for a single method that
* differs only in having additional driver specific attributes. * differs only in having additional driver specific attributes.
*/ */
...@@ -91,11 +97,19 @@ ...@@ -91,11 +97,19 @@
.num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \ .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \
.attrs = &UVERBS_METHOD_ATTRS(_method_id), \ .attrs = &UVERBS_METHOD_ATTRS(_method_id), \
}; \ }; \
static DECLARE_UVERBS_OBJECT( \ static const struct uverbs_method_def *const UVERBS_OBJECT_METHODS( \
_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, _object_id, _name), \ _object_id)[] = { &UVERBS_METHOD(_method_id) }; \
_object_id, NULL, &UVERBS_METHOD(_method_id)); \ static const struct uverbs_object_def _name##_struct = { \
static DECLARE_UVERBS_OBJECT_TREE( \ .id = _object_id, \
_name, \ .num_methods = 1, \
&_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, _object_id, _name)) .methods = &UVERBS_OBJECT_METHODS(_object_id) \
}; \
static const struct uverbs_object_def *const _name##_ptrs[] = { \
&_name##_struct, \
}; \
static const struct uverbs_object_tree_def _name = { \
.num_objects = 1, \
.objects = &_name##_ptrs, \
}
#endif #endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册