1*b633e08cSHans Petter Selasky /* 2*b633e08cSHans Petter Selasky * Copyright (c) 2018, Mellanox Technologies inc. All rights reserved. 3*b633e08cSHans Petter Selasky * 4*b633e08cSHans Petter Selasky * This software is available to you under a choice of one of two 5*b633e08cSHans Petter Selasky * licenses. You may choose to be licensed under the terms of the GNU 6*b633e08cSHans Petter Selasky * General Public License (GPL) Version 2, available from the file 7*b633e08cSHans Petter Selasky * COPYING in the main directory of this source tree, or the 8*b633e08cSHans Petter Selasky * OpenIB.org BSD license below: 9*b633e08cSHans Petter Selasky * 10*b633e08cSHans Petter Selasky * Redistribution and use in source and binary forms, with or 11*b633e08cSHans Petter Selasky * without modification, are permitted provided that the following 12*b633e08cSHans Petter Selasky * conditions are met: 13*b633e08cSHans Petter Selasky * 14*b633e08cSHans Petter Selasky * - Redistributions of source code must retain the above 15*b633e08cSHans Petter Selasky * copyright notice, this list of conditions and the following 16*b633e08cSHans Petter Selasky * disclaimer. 17*b633e08cSHans Petter Selasky * 18*b633e08cSHans Petter Selasky * - Redistributions in binary form must reproduce the above 19*b633e08cSHans Petter Selasky * copyright notice, this list of conditions and the following 20*b633e08cSHans Petter Selasky * disclaimer in the documentation and/or other materials 21*b633e08cSHans Petter Selasky * provided with the distribution. 22*b633e08cSHans Petter Selasky * 23*b633e08cSHans Petter Selasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24*b633e08cSHans Petter Selasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25*b633e08cSHans Petter Selasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26*b633e08cSHans Petter Selasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27*b633e08cSHans Petter Selasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28*b633e08cSHans Petter Selasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29*b633e08cSHans Petter Selasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30*b633e08cSHans Petter Selasky * SOFTWARE. 31*b633e08cSHans Petter Selasky */ 32*b633e08cSHans Petter Selasky 33*b633e08cSHans Petter Selasky #ifndef _UVERBS_NAMED_IOCTL_ 34*b633e08cSHans Petter Selasky #define _UVERBS_NAMED_IOCTL_ 35*b633e08cSHans Petter Selasky 36*b633e08cSHans Petter Selasky #include <rdma/uverbs_ioctl.h> 37*b633e08cSHans Petter Selasky 38*b633e08cSHans Petter Selasky #ifndef UVERBS_MODULE_NAME 39*b633e08cSHans Petter Selasky #error "Please #define UVERBS_MODULE_NAME before including rdma/uverbs_named_ioctl.h" 40*b633e08cSHans Petter Selasky #endif 41*b633e08cSHans Petter Selasky 42*b633e08cSHans Petter Selasky #define _UVERBS_PASTE(x, y) x ## y 43*b633e08cSHans Petter Selasky #define _UVERBS_NAME(x, y) _UVERBS_PASTE(x, y) 44*b633e08cSHans Petter Selasky #define UVERBS_METHOD(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _method_##id) 45*b633e08cSHans Petter Selasky #define UVERBS_HANDLER(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _handler_##id) 46*b633e08cSHans Petter Selasky #define UVERBS_OBJECT(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _object_##id) 47*b633e08cSHans Petter Selasky 48*b633e08cSHans Petter Selasky /* These are static so they do not need to be qualified */ 49*b633e08cSHans Petter Selasky #define UVERBS_METHOD_ATTRS(method_id) _method_attrs_##method_id 50*b633e08cSHans Petter Selasky #define UVERBS_OBJECT_METHODS(object_id) _object_methods_##object_id 51*b633e08cSHans Petter Selasky 52*b633e08cSHans Petter Selasky #define DECLARE_UVERBS_NAMED_METHOD(_method_id, ...) \ 53*b633e08cSHans Petter Selasky static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \ 54*b633e08cSHans Petter Selasky _method_id)[] = { __VA_ARGS__ }; \ 55*b633e08cSHans Petter Selasky static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \ 56*b633e08cSHans Petter Selasky .id = _method_id, \ 57*b633e08cSHans Petter Selasky .handler = UVERBS_HANDLER(_method_id), \ 58*b633e08cSHans Petter Selasky .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \ 59*b633e08cSHans Petter Selasky .attrs = &UVERBS_METHOD_ATTRS(_method_id), \ 60*b633e08cSHans Petter Selasky } 61*b633e08cSHans Petter Selasky 62*b633e08cSHans Petter Selasky /* Create a standard destroy method using the default handler. The handle_attr 63*b633e08cSHans Petter Selasky * argument must be the attribute specifying the handle to destroy, the 64*b633e08cSHans Petter Selasky * default handler does not support any other attributes. 65*b633e08cSHans Petter Selasky */ 66*b633e08cSHans Petter Selasky #define DECLARE_UVERBS_NAMED_METHOD_DESTROY(_method_id, _handle_attr) \ 67*b633e08cSHans Petter Selasky static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \ 68*b633e08cSHans Petter Selasky _method_id)[] = { _handle_attr }; \ 69*b633e08cSHans Petter Selasky static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \ 70*b633e08cSHans Petter Selasky .id = _method_id, \ 71*b633e08cSHans Petter Selasky .handler = uverbs_destroy_def_handler, \ 72*b633e08cSHans Petter Selasky .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \ 73*b633e08cSHans Petter Selasky .attrs = &UVERBS_METHOD_ATTRS(_method_id), \ 74*b633e08cSHans Petter Selasky } 75*b633e08cSHans Petter Selasky 76*b633e08cSHans Petter Selasky #define DECLARE_UVERBS_NAMED_OBJECT(_object_id, _type_attrs, ...) \ 77*b633e08cSHans Petter Selasky static const struct uverbs_method_def *const UVERBS_OBJECT_METHODS( \ 78*b633e08cSHans Petter Selasky _object_id)[] = { __VA_ARGS__ }; \ 79*b633e08cSHans Petter Selasky static const struct uverbs_object_def UVERBS_OBJECT(_object_id) = { \ 80*b633e08cSHans Petter Selasky .id = _object_id, \ 81*b633e08cSHans Petter Selasky .type_attrs = &_type_attrs, \ 82*b633e08cSHans Petter Selasky .num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)), \ 83*b633e08cSHans Petter Selasky .methods = &UVERBS_OBJECT_METHODS(_object_id) \ 84*b633e08cSHans Petter Selasky } 85*b633e08cSHans Petter Selasky 86*b633e08cSHans Petter Selasky /* 87*b633e08cSHans Petter Selasky * Declare global methods. These still have a unique object_id because we 88*b633e08cSHans Petter Selasky * identify all uapi methods with a (object,method) tuple. However, they have 89*b633e08cSHans Petter Selasky * no type pointer. 90*b633e08cSHans Petter Selasky */ 91*b633e08cSHans Petter Selasky #define DECLARE_UVERBS_GLOBAL_METHODS(_object_id, ...) \ 92*b633e08cSHans Petter Selasky static const struct uverbs_method_def *const UVERBS_OBJECT_METHODS( \ 93*b633e08cSHans Petter Selasky _object_id)[] = { __VA_ARGS__ }; \ 94*b633e08cSHans Petter Selasky static const struct uverbs_object_def UVERBS_OBJECT(_object_id) = { \ 95*b633e08cSHans Petter Selasky .id = _object_id, \ 96*b633e08cSHans Petter Selasky .num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)), \ 97*b633e08cSHans Petter Selasky .methods = &UVERBS_OBJECT_METHODS(_object_id) \ 98*b633e08cSHans Petter Selasky } 99*b633e08cSHans Petter Selasky 100*b633e08cSHans Petter Selasky /* Used by drivers to declare a complete parsing tree for new methods 101*b633e08cSHans Petter Selasky */ 102*b633e08cSHans Petter Selasky #define ADD_UVERBS_METHODS(_name, _object_id, ...) \ 103*b633e08cSHans Petter Selasky static const struct uverbs_method_def *const UVERBS_OBJECT_METHODS( \ 104*b633e08cSHans Petter Selasky _object_id)[] = { __VA_ARGS__ }; \ 105*b633e08cSHans Petter Selasky static const struct uverbs_object_def _name = { \ 106*b633e08cSHans Petter Selasky .id = _object_id, \ 107*b633e08cSHans Petter Selasky .num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)), \ 108*b633e08cSHans Petter Selasky .methods = &UVERBS_OBJECT_METHODS(_object_id) \ 109*b633e08cSHans Petter Selasky }; 110*b633e08cSHans Petter Selasky 111*b633e08cSHans Petter Selasky /* Used by drivers to declare a complete parsing tree for a single method that 112*b633e08cSHans Petter Selasky * differs only in having additional driver specific attributes. 113*b633e08cSHans Petter Selasky */ 114*b633e08cSHans Petter Selasky #define ADD_UVERBS_ATTRIBUTES_SIMPLE(_name, _object_id, _method_id, ...) \ 115*b633e08cSHans Petter Selasky static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \ 116*b633e08cSHans Petter Selasky _method_id)[] = { __VA_ARGS__ }; \ 117*b633e08cSHans Petter Selasky static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \ 118*b633e08cSHans Petter Selasky .id = _method_id, \ 119*b633e08cSHans Petter Selasky .num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \ 120*b633e08cSHans Petter Selasky .attrs = &UVERBS_METHOD_ATTRS(_method_id), \ 121*b633e08cSHans Petter Selasky }; \ 122*b633e08cSHans Petter Selasky ADD_UVERBS_METHODS(_name, _object_id, &UVERBS_METHOD(_method_id)) 123*b633e08cSHans Petter Selasky 124*b633e08cSHans Petter Selasky #endif 125