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