1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 #ifndef _UVERBS_NAMED_IOCTL_
34 #define _UVERBS_NAMED_IOCTL_
35
36 #include <rdma/uverbs_ioctl.h>
37
38 #ifndef UVERBS_MODULE_NAME
39 #error "Please #define UVERBS_MODULE_NAME before including rdma/uverbs_named_ioctl.h"
40 #endif
41
42 #define _UVERBS_PASTE(x, y) x ## y
43 #define _UVERBS_NAME(x, y) _UVERBS_PASTE(x, y)
44 #define UVERBS_METHOD(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _method_##id)
45 #define UVERBS_HANDLER(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _handler_##id)
46 #define UVERBS_OBJECT(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _object_##id)
47
48
49 #define UVERBS_METHOD_ATTRS(method_id) _method_attrs_##method_id
50 #define UVERBS_OBJECT_METHODS(object_id) _object_methods_##object_id
51
52 #define DECLARE_UVERBS_NAMED_METHOD(_method_id, ...) \
53 static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \
54 _method_id)[] = { __VA_ARGS__ }; \
55 static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \
56 .id = _method_id, \
57 .handler = UVERBS_HANDLER(_method_id), \
58 .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \
59 .attrs = &UVERBS_METHOD_ATTRS(_method_id), \
60 }
61
62
63
64
65
66 #define DECLARE_UVERBS_NAMED_METHOD_DESTROY(_method_id, _handle_attr) \
67 static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \
68 _method_id)[] = { _handle_attr }; \
69 static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \
70 .id = _method_id, \
71 .handler = uverbs_destroy_def_handler, \
72 .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \
73 .attrs = &UVERBS_METHOD_ATTRS(_method_id), \
74 }
75
76 #define DECLARE_UVERBS_NAMED_OBJECT(_object_id, _type_attrs, ...) \
77 static const struct uverbs_method_def *const UVERBS_OBJECT_METHODS( \
78 _object_id)[] = { __VA_ARGS__ }; \
79 const struct uverbs_object_def UVERBS_OBJECT(_object_id) = { \
80 .id = _object_id, \
81 .type_attrs = &_type_attrs, \
82 .num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)), \
83 .methods = &UVERBS_OBJECT_METHODS(_object_id) \
84 }
85
86
87
88
89
90
91 #define DECLARE_UVERBS_GLOBAL_METHODS(_object_id, ...) \
92 static const struct uverbs_method_def *const UVERBS_OBJECT_METHODS( \
93 _object_id)[] = { __VA_ARGS__ }; \
94 const struct uverbs_object_def UVERBS_OBJECT(_object_id) = { \
95 .id = _object_id, \
96 .num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)), \
97 .methods = &UVERBS_OBJECT_METHODS(_object_id) \
98 }
99
100
101
102 #define ADD_UVERBS_METHODS(_name, _object_id, ...) \
103 static const struct uverbs_method_def *const UVERBS_OBJECT_METHODS( \
104 _object_id)[] = { __VA_ARGS__ }; \
105 static const struct uverbs_object_def _name = { \
106 .id = _object_id, \
107 .num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)), \
108 .methods = &UVERBS_OBJECT_METHODS(_object_id) \
109 };
110
111
112
113
114 #define ADD_UVERBS_ATTRIBUTES_SIMPLE(_name, _object_id, _method_id, ...) \
115 static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \
116 _method_id)[] = { __VA_ARGS__ }; \
117 static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \
118 .id = _method_id, \
119 .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \
120 .attrs = &UVERBS_METHOD_ATTRS(_method_id), \
121 }; \
122 ADD_UVERBS_METHODS(_name, _object_id, &UVERBS_METHOD(_method_id))
123
124 #endif