Message ID | 20180625221249.30730-5-jgg@ziepe.ca (mailing list archive) |
---|---|
State | Changes Requested |
Headers | show |
> diff --git a/include/rdma/uverbs_named_ioctl.h b/include/rdma/uverbs_named_ioctl.h > index 228421f2a427b6..06eac48ec4f233 100644 > --- a/include/rdma/uverbs_named_ioctl.h > +++ b/include/rdma/uverbs_named_ioctl.h > @@ -45,14 +45,32 @@ > #define UVERBS_HANDLER(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _handler_##id) > #define UVERBS_OBJECT(id) _UVERBS_NAME(UVERBS_MOUDLE_NAME, _object_##id) > > -#define DECLARE_UVERBS_NAMED_METHOD(id, ...) \ > - DECLARE_UVERBS_METHOD(UVERBS_METHOD(id), id, UVERBS_HANDLER(id), ##__VA_ARGS__) > +#define UVERBS_METHOD_ATTRS(id) \ > + _UVERBS_NAME(UVERBS_MODULE_NAME, _method_attrs_##id) > > -#define DECLARE_UVERBS_NAMED_METHOD_WITH_HANDLER(id, handler, ...) \ > - DECLARE_UVERBS_METHOD(UVERBS_METHOD(id), id, handler, ##__VA_ARGS__) > +#define DECLARE_UVERBS_NAMED_METHOD(_method_id, ...) \ Why do you insist to specify in macro's names the term 'NAMED' (same for the header file name)? There is another usage which is un-NAMED? -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, Jun 27, 2018 at 05:24:52AM -0600, Guy Levi(SW) wrote: > > diff --git a/include/rdma/uverbs_named_ioctl.h b/include/rdma/uverbs_named_ioctl.h > > index 228421f2a427b6..06eac48ec4f233 100644 > > +++ b/include/rdma/uverbs_named_ioctl.h > > @@ -45,14 +45,32 @@ > > #define UVERBS_HANDLER(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _handler_##id) > > #define UVERBS_OBJECT(id) _UVERBS_NAME(UVERBS_MOUDLE_NAME, _object_##id) > > > > -#define DECLARE_UVERBS_NAMED_METHOD(id, ...) \ > > - DECLARE_UVERBS_METHOD(UVERBS_METHOD(id), id, UVERBS_HANDLER(id), ##__VA_ARGS__) > > +#define UVERBS_METHOD_ATTRS(id) \ > > + _UVERBS_NAME(UVERBS_MODULE_NAME, _method_attrs_##id) > > > > -#define DECLARE_UVERBS_NAMED_METHOD_WITH_HANDLER(id, handler, ...) \ > > - DECLARE_UVERBS_METHOD(UVERBS_METHOD(id), id, handler, ##__VA_ARGS__) > > +#define DECLARE_UVERBS_NAMED_METHOD(_method_id, ...) \ > > Why do you insist to specify in macro's names the term 'NAMED' (same > for the header file name)? There is another usage which is > un-NAMED? It is a bit confusing but 'named' is supposed to refer to the use of UVERBS_MOUDLE_NAME - I think. Another series is needed to clean this and remove this entire confusing mechanism. I am just keeping it as it is for now to avoid getting a series that is too big. Jason -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 6/26/2018 1:12 AM, Jason Gunthorpe wrote: > From: Jason Gunthorpe <jgg@mellanox.com> > > Instead of the large set of indirecting macros, define the few needed > macros to directly instantiate the struct uverbs_method_def and associated > attributes list. > > This is small amount of code duplication but the readability is far > better. > > Signed-off-by: Jason Gunthorpe <jgg@mellanox.com> > --- > .../core/uverbs_std_types_counters.c | 7 +- > drivers/infiniband/core/uverbs_std_types_cq.c | 4 +- > drivers/infiniband/core/uverbs_std_types_dm.c | 5 +- > .../core/uverbs_std_types_flow_action.c | 7 +- > drivers/infiniband/core/uverbs_std_types_mr.c | 2 +- > drivers/infiniband/hw/mlx5/devx.c | 18 ++--- > include/rdma/uverbs_ioctl.h | 18 ----- > include/rdma/uverbs_named_ioctl.h | 73 ++++++++++--------- > 8 files changed, 60 insertions(+), 74 deletions(-) > > diff --git a/include/rdma/uverbs_named_ioctl.h b/include/rdma/uverbs_named_ioctl.h > index 228421f2a427b6..06eac48ec4f233 100644 > --- a/include/rdma/uverbs_named_ioctl.h > +++ b/include/rdma/uverbs_named_ioctl.h > @@ -45,14 +45,32 @@ > #define UVERBS_HANDLER(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _handler_##id) > #define UVERBS_OBJECT(id) _UVERBS_NAME(UVERBS_MOUDLE_NAME, _object_##id) > > -#define DECLARE_UVERBS_NAMED_METHOD(id, ...) \ > - DECLARE_UVERBS_METHOD(UVERBS_METHOD(id), id, UVERBS_HANDLER(id), ##__VA_ARGS__) > +#define UVERBS_METHOD_ATTRS(id) \ > + _UVERBS_NAME(UVERBS_MODULE_NAME, _method_attrs_##id) > > -#define DECLARE_UVERBS_NAMED_METHOD_WITH_HANDLER(id, handler, ...) \ > - DECLARE_UVERBS_METHOD(UVERBS_METHOD(id), id, handler, ##__VA_ARGS__) > +#define DECLARE_UVERBS_NAMED_METHOD(_method_id, ...) \ > + static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \ > + _method_id)[] = { __VA_ARGS__ }; \ > + static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \ > + .id = _method_id, \ > + .handler = UVERBS_HANDLER(_method_id), \ > + .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \ > + .attrs = &UVERBS_METHOD_ATTRS(_method_id), \ > + } > > -#define DECLARE_UVERBS_NAMED_METHOD_NO_OVERRIDE(id, handler, ...) \ > - DECLARE_UVERBS_METHOD(UVERBS_METHOD(id), id, NULL, ##__VA_ARGS__) > +/* Create a standard destroy method using the default handler. The handle_attr > + * argument must be the attribute specifying the handle to destroy, the > + * default handler does not support any other attributes. > + */ > +#define DECLARE_UVERBS_NAMED_METHOD_DESTROY(_method_id, _handle_attr) \ > + static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \ > + _method_id)[] = { _handle_attr }; \ > + static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \ > + .id = _method_id, \ > + .handler = uverbs_destroy_def_handler, \ > + .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \ > + .attrs = &UVERBS_METHOD_ATTRS(_method_id), \ > + } > > #define DECLARE_UVERBS_NAMED_OBJECT(id, ...) \ > DECLARE_UVERBS_OBJECT(UVERBS_OBJECT(id), id, ##__VA_ARGS__) > @@ -62,33 +80,22 @@ > > #define _UVERBS_COMP_NAME(x, y, z) _UVERBS_NAME(_UVERBS_NAME(x, y), z) > > -#define UVERBS_NO_OVERRIDE NULL > - > -/* This declares a parsing tree with one object and one method. This is usually > - * used for merging driver attributes to the common attributes. The driver has > - * a chance to override the handler and type attrs of the original object. > - * The __VA_ARGS__ just contains a list of attributes. > - */ > -#define ADD_UVERBS_ATTRIBUTES(_name, _object, _method, _type_attrs, _handler, ...) \ > -static DECLARE_UVERBS_METHOD(_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, \ > - _method_, _name), \ > - _method, _handler, ##__VA_ARGS__); \ > - \ > -static DECLARE_UVERBS_OBJECT(_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, \ > - _object_, _name), \ > - _object, _type_attrs, \ > - &_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, \ > - _method_, _name)); \ > - \ > -static DECLARE_UVERBS_OBJECT_TREE(_name, \ > - &_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, \ > - _object_, _name)) > - This patch removes the above macro which enables drivers to add a method with given attributes to an existing object. We are in progress in other series to use this functionality, let's please don't delete it without supplying an alternative macro for that. The below suggestion from Artemy looks that can be applicable for both use cases, better go with it as part of this patch. > -/* A very common use case is that the driver doesn't override the handler and > - * type_attrs. Therefore, we provide a simplified macro for this common case. > +/* Used by drivers to declare a complete parsing tree for a single method that > + * differs only in having additional driver specific attributes. > */ > -#define ADD_UVERBS_ATTRIBUTES_SIMPLE(_name, _object, _method, ...) \ > - ADD_UVERBS_ATTRIBUTES(_name, _object, _method, UVERBS_NO_OVERRIDE, \ > - UVERBS_NO_OVERRIDE, ##__VA_ARGS__) > +#define ADD_UVERBS_ATTRIBUTES_SIMPLE(_name, _object_id, _method_id, ...) \ > + static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \ > + _method_id)[] = { __VA_ARGS__ }; \ > + static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \ > + .id = _method_id, \ > + .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \ > + .attrs = &UVERBS_METHOD_ATTRS(_method_id), \ > + }; \ > + static DECLARE_UVERBS_OBJECT( \ > + _UVERBS_COMP_NAME(UVERBS_MODULE_NAME, _object_id, _name), \ > + _object_id, NULL, &UVERBS_METHOD(_method_id)); \ > + static DECLARE_UVERBS_OBJECT_TREE( \ > + _name, \ > + &_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, _object_id, _name)) > > #endif > /* Used by drivers to declare a complete parsing tree for new methods */ #define ADD_UVERBS_METHODS(_name, _object_id, ...) \ static const struct uverbs_method_def *const UVERBS_OBJECT_METHODS( _object_id)[] = { __VA_ARGS__ }; \ static const struct uverbs_object_def _name##_struct = { \ .id = _object_id, \ .num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)), \ .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, \ } /* Used by drivers to declare a complete parsing tree for a single method that * differs only in having additional driver specific attributes. */ #define ADD_UVERBS_ATTRIBUTES_SIMPLE(_name, _object_id, \ _method_id, ...) \ static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \ _method_id)[] = { __VA_ARGS__ }; \ static const struct uverbs_method_def UVERBS_METHOD(_method_id) = {\ .id = _method_id, \ .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \ .attrs = &UVERBS_METHOD_ATTRS(_method_id), \ }; \ ADD_UVERBS_METHODS(_name, _object_id, _method_id) -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Sun, Jul 01, 2018 at 05:38:26PM +0300, Yishai Hadas wrote: > On 6/26/2018 1:12 AM, Jason Gunthorpe wrote: > >From: Jason Gunthorpe <jgg@mellanox.com> > > > >Instead of the large set of indirecting macros, define the few needed > >macros to directly instantiate the struct uverbs_method_def and associated > >attributes list. > > > >This is small amount of code duplication but the readability is far > >better. > > > >Signed-off-by: Jason Gunthorpe <jgg@mellanox.com> > > .../core/uverbs_std_types_counters.c | 7 +- > > drivers/infiniband/core/uverbs_std_types_cq.c | 4 +- > > drivers/infiniband/core/uverbs_std_types_dm.c | 5 +- > > .../core/uverbs_std_types_flow_action.c | 7 +- > > drivers/infiniband/core/uverbs_std_types_mr.c | 2 +- > > drivers/infiniband/hw/mlx5/devx.c | 18 ++--- > > include/rdma/uverbs_ioctl.h | 18 ----- > > include/rdma/uverbs_named_ioctl.h | 73 ++++++++++--------- > > 8 files changed, 60 insertions(+), 74 deletions(-) > > > >diff --git a/include/rdma/uverbs_named_ioctl.h b/include/rdma/uverbs_named_ioctl.h > >index 228421f2a427b6..06eac48ec4f233 100644 > >+++ b/include/rdma/uverbs_named_ioctl.h > >@@ -45,14 +45,32 @@ > > #define UVERBS_HANDLER(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _handler_##id) > > #define UVERBS_OBJECT(id) _UVERBS_NAME(UVERBS_MOUDLE_NAME, _object_##id) > >-#define DECLARE_UVERBS_NAMED_METHOD(id, ...) \ > >- DECLARE_UVERBS_METHOD(UVERBS_METHOD(id), id, UVERBS_HANDLER(id), ##__VA_ARGS__) > >+#define UVERBS_METHOD_ATTRS(id) \ > >+ _UVERBS_NAME(UVERBS_MODULE_NAME, _method_attrs_##id) > >-#define DECLARE_UVERBS_NAMED_METHOD_WITH_HANDLER(id, handler, ...) \ > >- DECLARE_UVERBS_METHOD(UVERBS_METHOD(id), id, handler, ##__VA_ARGS__) > >+#define DECLARE_UVERBS_NAMED_METHOD(_method_id, ...) \ > >+ static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \ > >+ _method_id)[] = { __VA_ARGS__ }; \ > >+ static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \ > >+ .id = _method_id, \ > >+ .handler = UVERBS_HANDLER(_method_id), \ > >+ .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \ > >+ .attrs = &UVERBS_METHOD_ATTRS(_method_id), \ > >+ } > >-#define DECLARE_UVERBS_NAMED_METHOD_NO_OVERRIDE(id, handler, ...) \ > >- DECLARE_UVERBS_METHOD(UVERBS_METHOD(id), id, NULL, ##__VA_ARGS__) > >+/* Create a standard destroy method using the default handler. The handle_attr > >+ * argument must be the attribute specifying the handle to destroy, the > >+ * default handler does not support any other attributes. > >+ */ > >+#define DECLARE_UVERBS_NAMED_METHOD_DESTROY(_method_id, _handle_attr) \ > >+ static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \ > >+ _method_id)[] = { _handle_attr }; \ > >+ static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \ > >+ .id = _method_id, \ > >+ .handler = uverbs_destroy_def_handler, \ > >+ .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \ > >+ .attrs = &UVERBS_METHOD_ATTRS(_method_id), \ > >+ } > > #define DECLARE_UVERBS_NAMED_OBJECT(id, ...) \ > > DECLARE_UVERBS_OBJECT(UVERBS_OBJECT(id), id, ##__VA_ARGS__) > >@@ -62,33 +80,22 @@ > > #define _UVERBS_COMP_NAME(x, y, z) _UVERBS_NAME(_UVERBS_NAME(x, y), z) > >-#define UVERBS_NO_OVERRIDE NULL > >- > >-/* This declares a parsing tree with one object and one method. This is usually > >- * used for merging driver attributes to the common attributes. The driver has > >- * a chance to override the handler and type attrs of the original object. > >- * The __VA_ARGS__ just contains a list of attributes. > >- */ > >-#define ADD_UVERBS_ATTRIBUTES(_name, _object, _method, _type_attrs, _handler, ...) \ > >-static DECLARE_UVERBS_METHOD(_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, \ > >- _method_, _name), \ > >- _method, _handler, ##__VA_ARGS__); \ > >- \ > >-static DECLARE_UVERBS_OBJECT(_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, \ > >- _object_, _name), \ > >- _object, _type_attrs, \ > >- &_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, \ > >- _method_, _name)); \ > >- \ > >-static DECLARE_UVERBS_OBJECT_TREE(_name, \ > >- &_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, \ > >- _object_, _name)) > >- > > This patch removes the above macro which enables drivers to add a method > with given attributes to an existing object. We are in progress in other > series to use this functionality, let's please don't delete it without > supplying an alternative macro for that. Yes.. The patch below looked like the right direction, lets review it as part of a series that introduces a user please. Jason -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/drivers/infiniband/core/uverbs_std_types_counters.c b/drivers/infiniband/core/uverbs_std_types_counters.c index 03b182a684a640..d284ab6936540c 100644 --- a/drivers/infiniband/core/uverbs_std_types_counters.c +++ b/drivers/infiniband/core/uverbs_std_types_counters.c @@ -123,21 +123,20 @@ static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_READ)(struct ib_device *ib_dev, return ret; } -static DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_COUNTERS_CREATE, +DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_COUNTERS_CREATE, &UVERBS_ATTR_IDR(UVERBS_ATTR_CREATE_COUNTERS_HANDLE, UVERBS_OBJECT_COUNTERS, UVERBS_ACCESS_NEW, UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY))); -static DECLARE_UVERBS_NAMED_METHOD_WITH_HANDLER(UVERBS_METHOD_COUNTERS_DESTROY, - uverbs_destroy_def_handler, +DECLARE_UVERBS_NAMED_METHOD_DESTROY(UVERBS_METHOD_COUNTERS_DESTROY, &UVERBS_ATTR_IDR(UVERBS_ATTR_DESTROY_COUNTERS_HANDLE, UVERBS_OBJECT_COUNTERS, UVERBS_ACCESS_DESTROY, UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY))); #define MAX_COUNTERS_BUFF_SIZE USHRT_MAX -static DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_COUNTERS_READ, +DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_COUNTERS_READ, &UVERBS_ATTR_IDR(UVERBS_ATTR_READ_COUNTERS_HANDLE, UVERBS_OBJECT_COUNTERS, UVERBS_ACCESS_READ, diff --git a/drivers/infiniband/core/uverbs_std_types_cq.c b/drivers/infiniband/core/uverbs_std_types_cq.c index 3d293d01afea45..cd6cd83c1ed0c9 100644 --- a/drivers/infiniband/core/uverbs_std_types_cq.c +++ b/drivers/infiniband/core/uverbs_std_types_cq.c @@ -143,7 +143,7 @@ static int UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE)(struct ib_device *ib_dev, return ret; }; -static DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_CQ_CREATE, +DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_CQ_CREATE, &UVERBS_ATTR_IDR(UVERBS_ATTR_CREATE_CQ_HANDLE, UVERBS_OBJECT_CQ, UVERBS_ACCESS_NEW, UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY)), @@ -192,7 +192,7 @@ static int UVERBS_HANDLER(UVERBS_METHOD_CQ_DESTROY)(struct ib_device *ib_dev, sizeof(resp)); } -static DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_CQ_DESTROY, +DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_CQ_DESTROY, &UVERBS_ATTR_IDR(UVERBS_ATTR_DESTROY_CQ_HANDLE, UVERBS_OBJECT_CQ, UVERBS_ACCESS_DESTROY, UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY)), diff --git a/drivers/infiniband/core/uverbs_std_types_dm.c b/drivers/infiniband/core/uverbs_std_types_dm.c index 8b681575b61584..7f6849181330f3 100644 --- a/drivers/infiniband/core/uverbs_std_types_dm.c +++ b/drivers/infiniband/core/uverbs_std_types_dm.c @@ -83,7 +83,7 @@ static int UVERBS_HANDLER(UVERBS_METHOD_DM_ALLOC)(struct ib_device *ib_dev, return 0; } -static DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_DM_ALLOC, +DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_DM_ALLOC, &UVERBS_ATTR_IDR(UVERBS_ATTR_ALLOC_DM_HANDLE, UVERBS_OBJECT_DM, UVERBS_ACCESS_NEW, UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY)), @@ -94,8 +94,7 @@ static DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_DM_ALLOC, UVERBS_ATTR_TYPE(u32), UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY))); -static DECLARE_UVERBS_NAMED_METHOD_WITH_HANDLER(UVERBS_METHOD_DM_FREE, - uverbs_destroy_def_handler, +DECLARE_UVERBS_NAMED_METHOD_DESTROY(UVERBS_METHOD_DM_FREE, &UVERBS_ATTR_IDR(UVERBS_ATTR_FREE_DM_HANDLE, UVERBS_OBJECT_DM, UVERBS_ACCESS_DESTROY, diff --git a/drivers/infiniband/core/uverbs_std_types_flow_action.c b/drivers/infiniband/core/uverbs_std_types_flow_action.c index 295d46565f6576..673286809c384f 100644 --- a/drivers/infiniband/core/uverbs_std_types_flow_action.c +++ b/drivers/infiniband/core/uverbs_std_types_flow_action.c @@ -384,7 +384,7 @@ static const struct uverbs_attr_spec uverbs_flow_action_esp_replay[] = { }, }; -static DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_FLOW_ACTION_ESP_CREATE, +DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_FLOW_ACTION_ESP_CREATE, &UVERBS_ATTR_IDR(UVERBS_ATTR_CREATE_FLOW_ACTION_ESP_HANDLE, UVERBS_OBJECT_FLOW_ACTION, UVERBS_ACCESS_NEW, @@ -402,7 +402,7 @@ static DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_FLOW_ACTION_ESP_CREATE, &UVERBS_ATTR_PTR_IN(UVERBS_ATTR_FLOW_ACTION_ESP_ENCAP, UVERBS_ATTR_STRUCT(struct ib_uverbs_flow_action_esp_encap, type))); -static DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_FLOW_ACTION_ESP_MODIFY, +DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_FLOW_ACTION_ESP_MODIFY, &UVERBS_ATTR_IDR(UVERBS_ATTR_MODIFY_FLOW_ACTION_ESP_HANDLE, UVERBS_OBJECT_FLOW_ACTION, UVERBS_ACCESS_WRITE, @@ -418,8 +418,7 @@ static DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_FLOW_ACTION_ESP_MODIFY, &UVERBS_ATTR_PTR_IN(UVERBS_ATTR_FLOW_ACTION_ESP_ENCAP, UVERBS_ATTR_STRUCT(struct ib_uverbs_flow_action_esp_encap, type))); -static DECLARE_UVERBS_NAMED_METHOD_WITH_HANDLER(UVERBS_METHOD_FLOW_ACTION_DESTROY, - uverbs_destroy_def_handler, +DECLARE_UVERBS_NAMED_METHOD_DESTROY(UVERBS_METHOD_FLOW_ACTION_DESTROY, &UVERBS_ATTR_IDR(UVERBS_ATTR_DESTROY_FLOW_ACTION_HANDLE, UVERBS_OBJECT_FLOW_ACTION, UVERBS_ACCESS_DESTROY, diff --git a/drivers/infiniband/core/uverbs_std_types_mr.c b/drivers/infiniband/core/uverbs_std_types_mr.c index 68f7cadf088f88..32f70c83ba40d6 100644 --- a/drivers/infiniband/core/uverbs_std_types_mr.c +++ b/drivers/infiniband/core/uverbs_std_types_mr.c @@ -115,7 +115,7 @@ static int UVERBS_HANDLER(UVERBS_METHOD_DM_MR_REG)(struct ib_device *ib_dev, return ret; } -static DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_DM_MR_REG, +DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_DM_MR_REG, &UVERBS_ATTR_IDR(UVERBS_ATTR_REG_DM_MR_HANDLE, UVERBS_OBJECT_MR, UVERBS_ACCESS_NEW, UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY)), diff --git a/drivers/infiniband/hw/mlx5/devx.c b/drivers/infiniband/hw/mlx5/devx.c index 2dcd3804c7e0cd..cea45edf24bd55 100644 --- a/drivers/infiniband/hw/mlx5/devx.c +++ b/drivers/infiniband/hw/mlx5/devx.c @@ -984,7 +984,7 @@ static int devx_umem_cleanup(struct ib_uobject *uobject, return 0; } -static DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_UMEM_REG, +DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_UMEM_REG, &UVERBS_ATTR_IDR(MLX5_IB_ATTR_DEVX_UMEM_REG_HANDLE, MLX5_IB_OBJECT_DEVX_UMEM, UVERBS_ACCESS_NEW, @@ -998,25 +998,25 @@ static DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_UMEM_REG, &UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_DEVX_UMEM_REG_OUT_ID, UVERBS_ATTR_TYPE(u32), UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY))); -static DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_UMEM_DEREG, +DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_UMEM_DEREG, &UVERBS_ATTR_IDR(MLX5_IB_ATTR_DEVX_UMEM_DEREG_HANDLE, MLX5_IB_OBJECT_DEVX_UMEM, UVERBS_ACCESS_DESTROY, UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY))); -static DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_QUERY_EQN, +DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_QUERY_EQN, &UVERBS_ATTR_PTR_IN(MLX5_IB_ATTR_DEVX_QUERY_EQN_USER_VEC, UVERBS_ATTR_TYPE(u32), UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY)), &UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_DEVX_QUERY_EQN_DEV_EQN, UVERBS_ATTR_TYPE(u32), UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY))); -static DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_QUERY_UAR, +DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_QUERY_UAR, &UVERBS_ATTR_PTR_IN(MLX5_IB_ATTR_DEVX_QUERY_UAR_USER_IDX, UVERBS_ATTR_TYPE(u32), UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY)), &UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_DEVX_QUERY_UAR_DEV_IDX, UVERBS_ATTR_TYPE(u32), UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY))); -static DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_OTHER, +DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_OTHER, &UVERBS_ATTR_PTR_IN(MLX5_IB_ATTR_DEVX_OTHER_CMD_IN, UVERBS_ATTR_MIN_SIZE(MLX5_ST_SZ_BYTES(general_obj_in_cmd_hdr)), UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY | @@ -1028,7 +1028,7 @@ static DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_OTHER, UVERBS_ATTR_SPEC_F_MIN_SZ_OR_ZERO)) ); -static DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_OBJ_CREATE, +DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_OBJ_CREATE, &UVERBS_ATTR_IDR(MLX5_IB_ATTR_DEVX_OBJ_CREATE_HANDLE, MLX5_IB_OBJECT_DEVX_OBJ, UVERBS_ACCESS_NEW, @@ -1043,13 +1043,13 @@ static DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_OBJ_CREATE, UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY | UVERBS_ATTR_SPEC_F_MIN_SZ_OR_ZERO))); -static DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_OBJ_DESTROY, +DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_OBJ_DESTROY, &UVERBS_ATTR_IDR(MLX5_IB_ATTR_DEVX_OBJ_DESTROY_HANDLE, MLX5_IB_OBJECT_DEVX_OBJ, UVERBS_ACCESS_DESTROY, UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY))); -static DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_OBJ_MODIFY, +DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_OBJ_MODIFY, &UVERBS_ATTR_IDR(MLX5_IB_ATTR_DEVX_OBJ_MODIFY_HANDLE, MLX5_IB_OBJECT_DEVX_OBJ, UVERBS_ACCESS_WRITE, @@ -1064,7 +1064,7 @@ static DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_OBJ_MODIFY, UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY | UVERBS_ATTR_SPEC_F_MIN_SZ_OR_ZERO))); -static DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_OBJ_QUERY, +DECLARE_UVERBS_NAMED_METHOD(MLX5_IB_METHOD_DEVX_OBJ_QUERY, &UVERBS_ATTR_IDR(MLX5_IB_ATTR_DEVX_OBJ_QUERY_HANDLE, MLX5_IB_OBJECT_DEVX_OBJ, UVERBS_ACCESS_READ, diff --git a/include/rdma/uverbs_ioctl.h b/include/rdma/uverbs_ioctl.h index 8bbf02b46ffb60..1996c4ce2d2a74 100644 --- a/include/rdma/uverbs_ioctl.h +++ b/include/rdma/uverbs_ioctl.h @@ -260,24 +260,6 @@ struct uverbs_object_tree_def { * Declaration helpers * ======================================= */ -#define _UVERBS_METHOD_ATTRS_SZ(...) \ - (sizeof((const struct uverbs_attr_def * const []){__VA_ARGS__}) /\ - sizeof(const struct uverbs_attr_def *)) -#define _UVERBS_METHOD(_id, _handler, _flags, ...) \ - ((const struct uverbs_method_def) { \ - .id = _id, \ - .flags = _flags, \ - .handler = _handler, \ - .num_attrs = _UVERBS_METHOD_ATTRS_SZ(__VA_ARGS__), \ - .attrs = &(const struct uverbs_attr_def * const []){__VA_ARGS__} }) -#define DECLARE_UVERBS_METHOD(_name, _id, _handler, ...) \ - const struct uverbs_method_def _name = \ - _UVERBS_METHOD(_id, _handler, 0, ##__VA_ARGS__) -#define DECLARE_UVERBS_CTX_METHOD(_name, _id, _handler, _flags, ...) \ - const struct uverbs_method_def _name = \ - _UVERBS_METHOD(_id, _handler, \ - UVERBS_ACTION_FLAG_CREATE_ROOT, \ - ##__VA_ARGS__) #define _UVERBS_OBJECT_METHODS_SZ(...) \ (sizeof((const struct uverbs_method_def * const []){__VA_ARGS__}) / \ sizeof(const struct uverbs_method_def *)) diff --git a/include/rdma/uverbs_named_ioctl.h b/include/rdma/uverbs_named_ioctl.h index 228421f2a427b6..06eac48ec4f233 100644 --- a/include/rdma/uverbs_named_ioctl.h +++ b/include/rdma/uverbs_named_ioctl.h @@ -45,14 +45,32 @@ #define UVERBS_HANDLER(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _handler_##id) #define UVERBS_OBJECT(id) _UVERBS_NAME(UVERBS_MOUDLE_NAME, _object_##id) -#define DECLARE_UVERBS_NAMED_METHOD(id, ...) \ - DECLARE_UVERBS_METHOD(UVERBS_METHOD(id), id, UVERBS_HANDLER(id), ##__VA_ARGS__) +#define UVERBS_METHOD_ATTRS(id) \ + _UVERBS_NAME(UVERBS_MODULE_NAME, _method_attrs_##id) -#define DECLARE_UVERBS_NAMED_METHOD_WITH_HANDLER(id, handler, ...) \ - DECLARE_UVERBS_METHOD(UVERBS_METHOD(id), id, handler, ##__VA_ARGS__) +#define DECLARE_UVERBS_NAMED_METHOD(_method_id, ...) \ + static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \ + _method_id)[] = { __VA_ARGS__ }; \ + static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \ + .id = _method_id, \ + .handler = UVERBS_HANDLER(_method_id), \ + .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \ + .attrs = &UVERBS_METHOD_ATTRS(_method_id), \ + } -#define DECLARE_UVERBS_NAMED_METHOD_NO_OVERRIDE(id, handler, ...) \ - DECLARE_UVERBS_METHOD(UVERBS_METHOD(id), id, NULL, ##__VA_ARGS__) +/* Create a standard destroy method using the default handler. The handle_attr + * argument must be the attribute specifying the handle to destroy, the + * default handler does not support any other attributes. + */ +#define DECLARE_UVERBS_NAMED_METHOD_DESTROY(_method_id, _handle_attr) \ + static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \ + _method_id)[] = { _handle_attr }; \ + static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \ + .id = _method_id, \ + .handler = uverbs_destroy_def_handler, \ + .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \ + .attrs = &UVERBS_METHOD_ATTRS(_method_id), \ + } #define DECLARE_UVERBS_NAMED_OBJECT(id, ...) \ DECLARE_UVERBS_OBJECT(UVERBS_OBJECT(id), id, ##__VA_ARGS__) @@ -62,33 +80,22 @@ #define _UVERBS_COMP_NAME(x, y, z) _UVERBS_NAME(_UVERBS_NAME(x, y), z) -#define UVERBS_NO_OVERRIDE NULL - -/* This declares a parsing tree with one object and one method. This is usually - * used for merging driver attributes to the common attributes. The driver has - * a chance to override the handler and type attrs of the original object. - * The __VA_ARGS__ just contains a list of attributes. - */ -#define ADD_UVERBS_ATTRIBUTES(_name, _object, _method, _type_attrs, _handler, ...) \ -static DECLARE_UVERBS_METHOD(_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, \ - _method_, _name), \ - _method, _handler, ##__VA_ARGS__); \ - \ -static DECLARE_UVERBS_OBJECT(_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, \ - _object_, _name), \ - _object, _type_attrs, \ - &_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, \ - _method_, _name)); \ - \ -static DECLARE_UVERBS_OBJECT_TREE(_name, \ - &_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, \ - _object_, _name)) - -/* A very common use case is that the driver doesn't override the handler and - * type_attrs. Therefore, we provide a simplified macro for this common case. +/* Used by drivers to declare a complete parsing tree for a single method that + * differs only in having additional driver specific attributes. */ -#define ADD_UVERBS_ATTRIBUTES_SIMPLE(_name, _object, _method, ...) \ - ADD_UVERBS_ATTRIBUTES(_name, _object, _method, UVERBS_NO_OVERRIDE, \ - UVERBS_NO_OVERRIDE, ##__VA_ARGS__) +#define ADD_UVERBS_ATTRIBUTES_SIMPLE(_name, _object_id, _method_id, ...) \ + static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \ + _method_id)[] = { __VA_ARGS__ }; \ + static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \ + .id = _method_id, \ + .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \ + .attrs = &UVERBS_METHOD_ATTRS(_method_id), \ + }; \ + static DECLARE_UVERBS_OBJECT( \ + _UVERBS_COMP_NAME(UVERBS_MODULE_NAME, _object_id, _name), \ + _object_id, NULL, &UVERBS_METHOD(_method_id)); \ + static DECLARE_UVERBS_OBJECT_TREE( \ + _name, \ + &_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, _object_id, _name)) #endif