Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
0002 /*
0003  * Copyright (c) 2018, Mellanox Technologies inc.  All rights reserved.
0004  */
0005 
0006 #ifndef _UVERBS_NAMED_IOCTL_
0007 #define _UVERBS_NAMED_IOCTL_
0008 
0009 #include <rdma/uverbs_ioctl.h>
0010 
0011 #ifndef UVERBS_MODULE_NAME
0012 #error "Please #define UVERBS_MODULE_NAME before including rdma/uverbs_named_ioctl.h"
0013 #endif
0014 
0015 #define _UVERBS_PASTE(x, y) x ## y
0016 #define _UVERBS_NAME(x, y)  _UVERBS_PASTE(x, y)
0017 #define UVERBS_METHOD(id)   _UVERBS_NAME(UVERBS_MODULE_NAME, _method_##id)
0018 #define UVERBS_HANDLER(id)  _UVERBS_NAME(UVERBS_MODULE_NAME, _handler_##id)
0019 #define UVERBS_OBJECT(id)   _UVERBS_NAME(UVERBS_MODULE_NAME, _object_##id)
0020 
0021 /* These are static so they do not need to be qualified */
0022 #define UVERBS_METHOD_ATTRS(method_id) _method_attrs_##method_id
0023 #define UVERBS_OBJECT_METHODS(object_id) _UVERBS_NAME(_object_methods_##object_id, __LINE__)
0024 
0025 #define DECLARE_UVERBS_NAMED_METHOD(_method_id, ...)                           \
0026     static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS(        \
0027         _method_id)[] = { __VA_ARGS__ };                               \
0028     static const struct uverbs_method_def UVERBS_METHOD(_method_id) = {    \
0029         .id = _method_id,                                              \
0030         .handler = UVERBS_HANDLER(_method_id),                         \
0031         .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)),      \
0032         .attrs = &UVERBS_METHOD_ATTRS(_method_id),                     \
0033     }
0034 
0035 /* Create a standard destroy method using the default handler. The handle_attr
0036  * argument must be the attribute specifying the handle to destroy, the
0037  * default handler does not support any other attributes.
0038  */
0039 #define DECLARE_UVERBS_NAMED_METHOD_DESTROY(_method_id, _handle_attr)          \
0040     static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS(        \
0041         _method_id)[] = { _handle_attr };                              \
0042     static const struct uverbs_method_def UVERBS_METHOD(_method_id) = {    \
0043         .id = _method_id,                                              \
0044         .handler = uverbs_destroy_def_handler,                         \
0045         .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)),      \
0046         .attrs = &UVERBS_METHOD_ATTRS(_method_id),                     \
0047     }
0048 
0049 #define DECLARE_UVERBS_NAMED_OBJECT(_object_id, _type_attrs, ...)              \
0050     static const struct uverbs_method_def *const UVERBS_OBJECT_METHODS(    \
0051         _object_id)[] = { __VA_ARGS__ };                               \
0052     static const struct uverbs_object_def UVERBS_OBJECT(_object_id) = {    \
0053         .id = _object_id,                                              \
0054         .type_attrs = &_type_attrs,                                    \
0055         .num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)),  \
0056         .methods = &UVERBS_OBJECT_METHODS(_object_id)                  \
0057     }
0058 
0059 /*
0060  * Declare global methods. These still have a unique object_id because we
0061  * identify all uapi methods with a (object,method) tuple. However, they have
0062  * no type pointer.
0063  */
0064 #define DECLARE_UVERBS_GLOBAL_METHODS(_object_id, ...)                         \
0065     static const struct uverbs_method_def *const UVERBS_OBJECT_METHODS(    \
0066         _object_id)[] = { __VA_ARGS__ };                               \
0067     static const struct uverbs_object_def UVERBS_OBJECT(_object_id) = {    \
0068         .id = _object_id,                                              \
0069         .num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)),  \
0070         .methods = &UVERBS_OBJECT_METHODS(_object_id)                  \
0071     }
0072 
0073 /* Used by drivers to declare a complete parsing tree for new methods
0074  */
0075 #define ADD_UVERBS_METHODS(_name, _object_id, ...)                             \
0076     static const struct uverbs_method_def *const UVERBS_OBJECT_METHODS(    \
0077         _object_id)[] = { __VA_ARGS__ };                               \
0078     static const struct uverbs_object_def _name = {                        \
0079         .id = _object_id,                                              \
0080         .num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)),  \
0081         .methods = &UVERBS_OBJECT_METHODS(_object_id)                  \
0082     };
0083 
0084 /* Used by drivers to declare a complete parsing tree for a single method that
0085  * differs only in having additional driver specific attributes.
0086  */
0087 #define ADD_UVERBS_ATTRIBUTES_SIMPLE(_name, _object_id, _method_id, ...)       \
0088     static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS(        \
0089         _method_id)[] = { __VA_ARGS__ };                               \
0090     static const struct uverbs_method_def UVERBS_METHOD(_method_id) = {    \
0091         .id = _method_id,                                              \
0092         .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)),      \
0093         .attrs = &UVERBS_METHOD_ATTRS(_method_id),                     \
0094     };                                                                     \
0095     ADD_UVERBS_METHODS(_name, _object_id, &UVERBS_METHOD(_method_id))
0096 
0097 #endif