Leon Romanovsky | 6bf9d8f | 2020-07-19 10:25:21 +0300 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ |
Matan Barak | 1f7ff9d | 2018-03-19 15:02:33 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2018, Mellanox Technologies inc. All rights reserved. |
Matan Barak | 1f7ff9d | 2018-03-19 15:02:33 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef _UVERBS_NAMED_IOCTL_ |
| 7 | #define _UVERBS_NAMED_IOCTL_ |
| 8 | |
| 9 | #include <rdma/uverbs_ioctl.h> |
| 10 | |
| 11 | #ifndef UVERBS_MODULE_NAME |
| 12 | #error "Please #define UVERBS_MODULE_NAME before including rdma/uverbs_named_ioctl.h" |
| 13 | #endif |
| 14 | |
| 15 | #define _UVERBS_PASTE(x, y) x ## y |
| 16 | #define _UVERBS_NAME(x, y) _UVERBS_PASTE(x, y) |
| 17 | #define UVERBS_METHOD(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _method_##id) |
| 18 | #define UVERBS_HANDLER(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _handler_##id) |
Leon Romanovsky | c471de1 | 2018-12-06 12:19:05 +0200 | [diff] [blame] | 19 | #define UVERBS_OBJECT(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _object_##id) |
Matan Barak | 1f7ff9d | 2018-03-19 15:02:33 +0200 | [diff] [blame] | 20 | |
Jason Gunthorpe | 6c61d2a | 2018-07-04 08:50:27 +0300 | [diff] [blame] | 21 | /* These are static so they do not need to be qualified */ |
| 22 | #define UVERBS_METHOD_ATTRS(method_id) _method_attrs_##method_id |
| 23 | #define UVERBS_OBJECT_METHODS(object_id) _object_methods_##object_id |
Matan Barak | 1f7ff9d | 2018-03-19 15:02:33 +0200 | [diff] [blame] | 24 | |
Jason Gunthorpe | 595c773 | 2018-07-04 08:50:26 +0300 | [diff] [blame] | 25 | #define DECLARE_UVERBS_NAMED_METHOD(_method_id, ...) \ |
| 26 | static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \ |
| 27 | _method_id)[] = { __VA_ARGS__ }; \ |
| 28 | static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \ |
| 29 | .id = _method_id, \ |
| 30 | .handler = UVERBS_HANDLER(_method_id), \ |
| 31 | .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \ |
| 32 | .attrs = &UVERBS_METHOD_ATTRS(_method_id), \ |
| 33 | } |
Matan Barak | 1f7ff9d | 2018-03-19 15:02:33 +0200 | [diff] [blame] | 34 | |
Jason Gunthorpe | 595c773 | 2018-07-04 08:50:26 +0300 | [diff] [blame] | 35 | /* Create a standard destroy method using the default handler. The handle_attr |
| 36 | * argument must be the attribute specifying the handle to destroy, the |
| 37 | * default handler does not support any other attributes. |
| 38 | */ |
| 39 | #define DECLARE_UVERBS_NAMED_METHOD_DESTROY(_method_id, _handle_attr) \ |
| 40 | static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \ |
| 41 | _method_id)[] = { _handle_attr }; \ |
| 42 | static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \ |
| 43 | .id = _method_id, \ |
| 44 | .handler = uverbs_destroy_def_handler, \ |
| 45 | .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \ |
| 46 | .attrs = &UVERBS_METHOD_ATTRS(_method_id), \ |
| 47 | } |
Matan Barak | 1f7ff9d | 2018-03-19 15:02:33 +0200 | [diff] [blame] | 48 | |
Jason Gunthorpe | 6c61d2a | 2018-07-04 08:50:27 +0300 | [diff] [blame] | 49 | #define DECLARE_UVERBS_NAMED_OBJECT(_object_id, _type_attrs, ...) \ |
| 50 | static const struct uverbs_method_def *const UVERBS_OBJECT_METHODS( \ |
| 51 | _object_id)[] = { __VA_ARGS__ }; \ |
Jason Gunthorpe | 8889f6f | 2020-01-30 11:21:21 -0400 | [diff] [blame] | 52 | static const struct uverbs_object_def UVERBS_OBJECT(_object_id) = { \ |
Jason Gunthorpe | 6c61d2a | 2018-07-04 08:50:27 +0300 | [diff] [blame] | 53 | .id = _object_id, \ |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 54 | .type_attrs = &_type_attrs, \ |
Jason Gunthorpe | 6c61d2a | 2018-07-04 08:50:27 +0300 | [diff] [blame] | 55 | .num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)), \ |
| 56 | .methods = &UVERBS_OBJECT_METHODS(_object_id) \ |
| 57 | } |
Matan Barak | 1f7ff9d | 2018-03-19 15:02:33 +0200 | [diff] [blame] | 58 | |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 59 | /* |
| 60 | * Declare global methods. These still have a unique object_id because we |
| 61 | * identify all uapi methods with a (object,method) tuple. However, they have |
| 62 | * no type pointer. |
| 63 | */ |
Jason Gunthorpe | 8889f6f | 2020-01-30 11:21:21 -0400 | [diff] [blame] | 64 | #define DECLARE_UVERBS_GLOBAL_METHODS(_object_id, ...) \ |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 65 | static const struct uverbs_method_def *const UVERBS_OBJECT_METHODS( \ |
| 66 | _object_id)[] = { __VA_ARGS__ }; \ |
Jason Gunthorpe | 8889f6f | 2020-01-30 11:21:21 -0400 | [diff] [blame] | 67 | static const struct uverbs_object_def UVERBS_OBJECT(_object_id) = { \ |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 68 | .id = _object_id, \ |
| 69 | .num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)), \ |
| 70 | .methods = &UVERBS_OBJECT_METHODS(_object_id) \ |
| 71 | } |
Yishai Hadas | e502a86 | 2018-06-17 12:59:58 +0300 | [diff] [blame] | 72 | |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 73 | /* Used by drivers to declare a complete parsing tree for new methods |
| 74 | */ |
| 75 | #define ADD_UVERBS_METHODS(_name, _object_id, ...) \ |
| 76 | static const struct uverbs_method_def *const UVERBS_OBJECT_METHODS( \ |
| 77 | _object_id)[] = { __VA_ARGS__ }; \ |
Jason Gunthorpe | 0cbf432 | 2018-11-12 22:59:50 +0200 | [diff] [blame] | 78 | static const struct uverbs_object_def _name = { \ |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 79 | .id = _object_id, \ |
| 80 | .num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)), \ |
| 81 | .methods = &UVERBS_OBJECT_METHODS(_object_id) \ |
Jason Gunthorpe | 0cbf432 | 2018-11-12 22:59:50 +0200 | [diff] [blame] | 82 | }; |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 83 | |
Jason Gunthorpe | 595c773 | 2018-07-04 08:50:26 +0300 | [diff] [blame] | 84 | /* Used by drivers to declare a complete parsing tree for a single method that |
| 85 | * differs only in having additional driver specific attributes. |
Matan Barak | 3d64add | 2018-03-19 15:02:39 +0200 | [diff] [blame] | 86 | */ |
Jason Gunthorpe | 595c773 | 2018-07-04 08:50:26 +0300 | [diff] [blame] | 87 | #define ADD_UVERBS_ATTRIBUTES_SIMPLE(_name, _object_id, _method_id, ...) \ |
| 88 | static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \ |
| 89 | _method_id)[] = { __VA_ARGS__ }; \ |
| 90 | static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \ |
| 91 | .id = _method_id, \ |
| 92 | .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \ |
| 93 | .attrs = &UVERBS_METHOD_ATTRS(_method_id), \ |
| 94 | }; \ |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 95 | ADD_UVERBS_METHODS(_name, _object_id, &UVERBS_METHOD(_method_id)) |
Matan Barak | 3d64add | 2018-03-19 15:02:39 +0200 | [diff] [blame] | 96 | |
Matan Barak | 1f7ff9d | 2018-03-19 15:02:33 +0200 | [diff] [blame] | 97 | #endif |