Matan Barak | 1f7ff9d | 2018-03-19 15:02:33 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, Mellanox Technologies inc. All rights reserved. |
| 3 | * |
| 4 | * This software is available to you under a choice of one of two |
| 5 | * licenses. You may choose to be licensed under the terms of the GNU |
| 6 | * General Public License (GPL) Version 2, available from the file |
| 7 | * COPYING in the main directory of this source tree, or the |
| 8 | * OpenIB.org BSD license below: |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or |
| 11 | * without modification, are permitted provided that the following |
| 12 | * conditions are met: |
| 13 | * |
| 14 | * - Redistributions of source code must retain the above |
| 15 | * copyright notice, this list of conditions and the following |
| 16 | * disclaimer. |
| 17 | * |
| 18 | * - Redistributions in binary form must reproduce the above |
| 19 | * copyright notice, this list of conditions and the following |
| 20 | * disclaimer in the documentation and/or other materials |
| 21 | * provided with the distribution. |
| 22 | * |
| 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 27 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 30 | * SOFTWARE. |
| 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) |
Leon Romanovsky | c471de1 | 2018-12-06 12:19:05 +0200 | [diff] [blame^] | 46 | #define UVERBS_OBJECT(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _object_##id) |
Matan Barak | 1f7ff9d | 2018-03-19 15:02:33 +0200 | [diff] [blame] | 47 | |
Jason Gunthorpe | 6c61d2a | 2018-07-04 08:50:27 +0300 | [diff] [blame] | 48 | /* These are static so they do not need to be qualified */ |
| 49 | #define UVERBS_METHOD_ATTRS(method_id) _method_attrs_##method_id |
| 50 | #define UVERBS_OBJECT_METHODS(object_id) _object_methods_##object_id |
Matan Barak | 1f7ff9d | 2018-03-19 15:02:33 +0200 | [diff] [blame] | 51 | |
Jason Gunthorpe | 595c773 | 2018-07-04 08:50:26 +0300 | [diff] [blame] | 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 | } |
Matan Barak | 1f7ff9d | 2018-03-19 15:02:33 +0200 | [diff] [blame] | 61 | |
Jason Gunthorpe | 595c773 | 2018-07-04 08:50:26 +0300 | [diff] [blame] | 62 | /* Create a standard destroy method using the default handler. The handle_attr |
| 63 | * argument must be the attribute specifying the handle to destroy, the |
| 64 | * default handler does not support any other attributes. |
| 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 | } |
Matan Barak | 1f7ff9d | 2018-03-19 15:02:33 +0200 | [diff] [blame] | 75 | |
Jason Gunthorpe | 6c61d2a | 2018-07-04 08:50:27 +0300 | [diff] [blame] | 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, \ |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 81 | .type_attrs = &_type_attrs, \ |
Jason Gunthorpe | 6c61d2a | 2018-07-04 08:50:27 +0300 | [diff] [blame] | 82 | .num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)), \ |
| 83 | .methods = &UVERBS_OBJECT_METHODS(_object_id) \ |
| 84 | } |
Matan Barak | 1f7ff9d | 2018-03-19 15:02:33 +0200 | [diff] [blame] | 85 | |
Jason Gunthorpe | 9a119cd | 2018-07-04 08:50:28 +0300 | [diff] [blame] | 86 | /* |
| 87 | * Declare global methods. These still have a unique object_id because we |
| 88 | * identify all uapi methods with a (object,method) tuple. However, they have |
| 89 | * no type pointer. |
| 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 | } |
Yishai Hadas | e502a86 | 2018-06-17 12:59:58 +0300 | [diff] [blame] | 99 | |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 100 | /* Used by drivers to declare a complete parsing tree for new methods |
| 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__ }; \ |
Jason Gunthorpe | 0cbf432 | 2018-11-12 22:59:50 +0200 | [diff] [blame] | 105 | static const struct uverbs_object_def _name = { \ |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 106 | .id = _object_id, \ |
| 107 | .num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)), \ |
| 108 | .methods = &UVERBS_OBJECT_METHODS(_object_id) \ |
Jason Gunthorpe | 0cbf432 | 2018-11-12 22:59:50 +0200 | [diff] [blame] | 109 | }; |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 110 | |
Jason Gunthorpe | 595c773 | 2018-07-04 08:50:26 +0300 | [diff] [blame] | 111 | /* Used by drivers to declare a complete parsing tree for a single method that |
| 112 | * differs only in having additional driver specific attributes. |
Matan Barak | 3d64add | 2018-03-19 15:02:39 +0200 | [diff] [blame] | 113 | */ |
Jason Gunthorpe | 595c773 | 2018-07-04 08:50:26 +0300 | [diff] [blame] | 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 | }; \ |
Yishai Hadas | 3226944 | 2018-07-23 15:25:09 +0300 | [diff] [blame] | 122 | ADD_UVERBS_METHODS(_name, _object_id, &UVERBS_METHOD(_method_id)) |
Matan Barak | 3d64add | 2018-03-19 15:02:39 +0200 | [diff] [blame] | 123 | |
Matan Barak | 1f7ff9d | 2018-03-19 15:02:33 +0200 | [diff] [blame] | 124 | #endif |