18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2018, Mellanox Technologies inc. All rights reserved. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef _UVERBS_NAMED_IOCTL_ 78c2ecf20Sopenharmony_ci#define _UVERBS_NAMED_IOCTL_ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <rdma/uverbs_ioctl.h> 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#ifndef UVERBS_MODULE_NAME 128c2ecf20Sopenharmony_ci#error "Please #define UVERBS_MODULE_NAME before including rdma/uverbs_named_ioctl.h" 138c2ecf20Sopenharmony_ci#endif 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define _UVERBS_PASTE(x, y) x ## y 168c2ecf20Sopenharmony_ci#define _UVERBS_NAME(x, y) _UVERBS_PASTE(x, y) 178c2ecf20Sopenharmony_ci#define UVERBS_METHOD(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _method_##id) 188c2ecf20Sopenharmony_ci#define UVERBS_HANDLER(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _handler_##id) 198c2ecf20Sopenharmony_ci#define UVERBS_OBJECT(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _object_##id) 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci/* These are static so they do not need to be qualified */ 228c2ecf20Sopenharmony_ci#define UVERBS_METHOD_ATTRS(method_id) _method_attrs_##method_id 238c2ecf20Sopenharmony_ci#define UVERBS_OBJECT_METHODS(object_id) _object_methods_##object_id 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#define DECLARE_UVERBS_NAMED_METHOD(_method_id, ...) \ 268c2ecf20Sopenharmony_ci static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \ 278c2ecf20Sopenharmony_ci _method_id)[] = { __VA_ARGS__ }; \ 288c2ecf20Sopenharmony_ci static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \ 298c2ecf20Sopenharmony_ci .id = _method_id, \ 308c2ecf20Sopenharmony_ci .handler = UVERBS_HANDLER(_method_id), \ 318c2ecf20Sopenharmony_ci .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \ 328c2ecf20Sopenharmony_ci .attrs = &UVERBS_METHOD_ATTRS(_method_id), \ 338c2ecf20Sopenharmony_ci } 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/* Create a standard destroy method using the default handler. The handle_attr 368c2ecf20Sopenharmony_ci * argument must be the attribute specifying the handle to destroy, the 378c2ecf20Sopenharmony_ci * default handler does not support any other attributes. 388c2ecf20Sopenharmony_ci */ 398c2ecf20Sopenharmony_ci#define DECLARE_UVERBS_NAMED_METHOD_DESTROY(_method_id, _handle_attr) \ 408c2ecf20Sopenharmony_ci static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \ 418c2ecf20Sopenharmony_ci _method_id)[] = { _handle_attr }; \ 428c2ecf20Sopenharmony_ci static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \ 438c2ecf20Sopenharmony_ci .id = _method_id, \ 448c2ecf20Sopenharmony_ci .handler = uverbs_destroy_def_handler, \ 458c2ecf20Sopenharmony_ci .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \ 468c2ecf20Sopenharmony_ci .attrs = &UVERBS_METHOD_ATTRS(_method_id), \ 478c2ecf20Sopenharmony_ci } 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci#define DECLARE_UVERBS_NAMED_OBJECT(_object_id, _type_attrs, ...) \ 508c2ecf20Sopenharmony_ci static const struct uverbs_method_def *const UVERBS_OBJECT_METHODS( \ 518c2ecf20Sopenharmony_ci _object_id)[] = { __VA_ARGS__ }; \ 528c2ecf20Sopenharmony_ci static const struct uverbs_object_def UVERBS_OBJECT(_object_id) = { \ 538c2ecf20Sopenharmony_ci .id = _object_id, \ 548c2ecf20Sopenharmony_ci .type_attrs = &_type_attrs, \ 558c2ecf20Sopenharmony_ci .num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)), \ 568c2ecf20Sopenharmony_ci .methods = &UVERBS_OBJECT_METHODS(_object_id) \ 578c2ecf20Sopenharmony_ci } 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci/* 608c2ecf20Sopenharmony_ci * Declare global methods. These still have a unique object_id because we 618c2ecf20Sopenharmony_ci * identify all uapi methods with a (object,method) tuple. However, they have 628c2ecf20Sopenharmony_ci * no type pointer. 638c2ecf20Sopenharmony_ci */ 648c2ecf20Sopenharmony_ci#define DECLARE_UVERBS_GLOBAL_METHODS(_object_id, ...) \ 658c2ecf20Sopenharmony_ci static const struct uverbs_method_def *const UVERBS_OBJECT_METHODS( \ 668c2ecf20Sopenharmony_ci _object_id)[] = { __VA_ARGS__ }; \ 678c2ecf20Sopenharmony_ci static const struct uverbs_object_def UVERBS_OBJECT(_object_id) = { \ 688c2ecf20Sopenharmony_ci .id = _object_id, \ 698c2ecf20Sopenharmony_ci .num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)), \ 708c2ecf20Sopenharmony_ci .methods = &UVERBS_OBJECT_METHODS(_object_id) \ 718c2ecf20Sopenharmony_ci } 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci/* Used by drivers to declare a complete parsing tree for new methods 748c2ecf20Sopenharmony_ci */ 758c2ecf20Sopenharmony_ci#define ADD_UVERBS_METHODS(_name, _object_id, ...) \ 768c2ecf20Sopenharmony_ci static const struct uverbs_method_def *const UVERBS_OBJECT_METHODS( \ 778c2ecf20Sopenharmony_ci _object_id)[] = { __VA_ARGS__ }; \ 788c2ecf20Sopenharmony_ci static const struct uverbs_object_def _name = { \ 798c2ecf20Sopenharmony_ci .id = _object_id, \ 808c2ecf20Sopenharmony_ci .num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)), \ 818c2ecf20Sopenharmony_ci .methods = &UVERBS_OBJECT_METHODS(_object_id) \ 828c2ecf20Sopenharmony_ci }; 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci/* Used by drivers to declare a complete parsing tree for a single method that 858c2ecf20Sopenharmony_ci * differs only in having additional driver specific attributes. 868c2ecf20Sopenharmony_ci */ 878c2ecf20Sopenharmony_ci#define ADD_UVERBS_ATTRIBUTES_SIMPLE(_name, _object_id, _method_id, ...) \ 888c2ecf20Sopenharmony_ci static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \ 898c2ecf20Sopenharmony_ci _method_id)[] = { __VA_ARGS__ }; \ 908c2ecf20Sopenharmony_ci static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \ 918c2ecf20Sopenharmony_ci .id = _method_id, \ 928c2ecf20Sopenharmony_ci .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \ 938c2ecf20Sopenharmony_ci .attrs = &UVERBS_METHOD_ATTRS(_method_id), \ 948c2ecf20Sopenharmony_ci }; \ 958c2ecf20Sopenharmony_ci ADD_UVERBS_METHODS(_name, _object_id, &UVERBS_METHOD(_method_id)) 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci#endif 98