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) 46 47 #define DECLARE_UVERBS_NAMED_METHOD(id, ...) \ 48 DECLARE_UVERBS_METHOD(UVERBS_METHOD(id), id, UVERBS_HANDLER(id), ##__VA_ARGS__) 49 50 #define DECLARE_UVERBS_NAMED_METHOD_WITH_HANDLER(id, handler, ...) \ 51 DECLARE_UVERBS_METHOD(UVERBS_METHOD(id), id, handler, ##__VA_ARGS__) 52 53 #define DECLARE_UVERBS_NAMED_METHOD_NO_OVERRIDE(id, handler, ...) \ 54 DECLARE_UVERBS_METHOD(UVERBS_METHOD(id), id, NULL, ##__VA_ARGS__) 55 56 #define DECLARE_UVERBS_NAMED_OBJECT(id, ...) \ 57 DECLARE_UVERBS_OBJECT(UVERBS_OBJECT(id), id, ##__VA_ARGS__) 58 59 #define _UVERBS_COMP_NAME(x, y, z) _UVERBS_NAME(_UVERBS_NAME(x, y), z) 60 61 #define UVERBS_NO_OVERRIDE NULL 62 63 /* This declares a parsing tree with one object and one method. This is usually 64 * used for merging driver attributes to the common attributes. The driver has 65 * a chance to override the handler and type attrs of the original object. 66 * The __VA_ARGS__ just contains a list of attributes. 67 */ 68 #define ADD_UVERBS_ATTRIBUTES(_name, _object, _method, _type_attrs, _handler, ...) \ 69 static DECLARE_UVERBS_METHOD(_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, \ 70 _method_, _name), \ 71 _method, _handler, ##__VA_ARGS__); \ 72 \ 73 static DECLARE_UVERBS_OBJECT(_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, \ 74 _object_, _name), \ 75 _object, _type_attrs, \ 76 &_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, \ 77 _method_, _name)); \ 78 \ 79 static DECLARE_UVERBS_OBJECT_TREE(_name, \ 80 &_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, \ 81 _object_, _name)) 82 83 /* A very common use case is that the driver doesn't override the handler and 84 * type_attrs. Therefore, we provide a simplified macro for this common case. 85 */ 86 #define ADD_UVERBS_ATTRIBUTES_SIMPLE(_name, _object, _method, ...) \ 87 ADD_UVERBS_ATTRIBUTES(_name, _object, _method, UVERBS_NO_OVERRIDE, \ 88 UVERBS_NO_OVERRIDE, ##__VA_ARGS__) 89 90 #endif 91