Path: blob/main/sys/ofed/include/rdma/uverbs_named_ioctl.h
39482 views
/*1* Copyright (c) 2018, Mellanox Technologies inc. All rights reserved.2*3* This software is available to you under a choice of one of two4* licenses. You may choose to be licensed under the terms of the GNU5* General Public License (GPL) Version 2, available from the file6* COPYING in the main directory of this source tree, or the7* OpenIB.org BSD license below:8*9* Redistribution and use in source and binary forms, with or10* without modification, are permitted provided that the following11* conditions are met:12*13* - Redistributions of source code must retain the above14* copyright notice, this list of conditions and the following15* disclaimer.16*17* - Redistributions in binary form must reproduce the above18* copyright notice, this list of conditions and the following19* disclaimer in the documentation and/or other materials20* provided with the distribution.21*22* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,23* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF24* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND25* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS26* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN27* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN28* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE29* SOFTWARE.30*/3132#ifndef _UVERBS_NAMED_IOCTL_33#define _UVERBS_NAMED_IOCTL_3435#include <rdma/uverbs_ioctl.h>3637#ifndef UVERBS_MODULE_NAME38#error "Please #define UVERBS_MODULE_NAME before including rdma/uverbs_named_ioctl.h"39#endif4041#define _UVERBS_PASTE(x, y) x ## y42#define _UVERBS_NAME(x, y) _UVERBS_PASTE(x, y)43#define UVERBS_METHOD(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _method_##id)44#define UVERBS_HANDLER(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _handler_##id)45#define UVERBS_OBJECT(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _object_##id)4647/* These are static so they do not need to be qualified */48#define UVERBS_METHOD_ATTRS(method_id) _method_attrs_##method_id49#define UVERBS_OBJECT_METHODS(object_id) _object_methods_##object_id5051#define DECLARE_UVERBS_NAMED_METHOD(_method_id, ...) \52static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \53_method_id)[] = { __VA_ARGS__ }; \54static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \55.id = _method_id, \56.handler = UVERBS_HANDLER(_method_id), \57.num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \58.attrs = &UVERBS_METHOD_ATTRS(_method_id), \59}6061/* Create a standard destroy method using the default handler. The handle_attr62* argument must be the attribute specifying the handle to destroy, the63* default handler does not support any other attributes.64*/65#define DECLARE_UVERBS_NAMED_METHOD_DESTROY(_method_id, _handle_attr) \66static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \67_method_id)[] = { _handle_attr }; \68static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \69.id = _method_id, \70.handler = uverbs_destroy_def_handler, \71.num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \72.attrs = &UVERBS_METHOD_ATTRS(_method_id), \73}7475#define DECLARE_UVERBS_NAMED_OBJECT(_object_id, _type_attrs, ...) \76static const struct uverbs_method_def *const UVERBS_OBJECT_METHODS( \77_object_id)[] = { __VA_ARGS__ }; \78static const struct uverbs_object_def UVERBS_OBJECT(_object_id) = { \79.id = _object_id, \80.type_attrs = &_type_attrs, \81.num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)), \82.methods = &UVERBS_OBJECT_METHODS(_object_id) \83}8485/*86* Declare global methods. These still have a unique object_id because we87* identify all uapi methods with a (object,method) tuple. However, they have88* no type pointer.89*/90#define DECLARE_UVERBS_GLOBAL_METHODS(_object_id, ...) \91static const struct uverbs_method_def *const UVERBS_OBJECT_METHODS( \92_object_id)[] = { __VA_ARGS__ }; \93static const struct uverbs_object_def UVERBS_OBJECT(_object_id) = { \94.id = _object_id, \95.num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)), \96.methods = &UVERBS_OBJECT_METHODS(_object_id) \97}9899/* Used by drivers to declare a complete parsing tree for new methods100*/101#define ADD_UVERBS_METHODS(_name, _object_id, ...) \102static const struct uverbs_method_def *const UVERBS_OBJECT_METHODS( \103_object_id)[] = { __VA_ARGS__ }; \104static const struct uverbs_object_def _name = { \105.id = _object_id, \106.num_methods = ARRAY_SIZE(UVERBS_OBJECT_METHODS(_object_id)), \107.methods = &UVERBS_OBJECT_METHODS(_object_id) \108};109110/* Used by drivers to declare a complete parsing tree for a single method that111* differs only in having additional driver specific attributes.112*/113#define ADD_UVERBS_ATTRIBUTES_SIMPLE(_name, _object_id, _method_id, ...) \114static const struct uverbs_attr_def *const UVERBS_METHOD_ATTRS( \115_method_id)[] = { __VA_ARGS__ }; \116static const struct uverbs_method_def UVERBS_METHOD(_method_id) = { \117.id = _method_id, \118.num_attrs = ARRAY_SIZE(UVERBS_METHOD_ATTRS(_method_id)), \119.attrs = &UVERBS_METHOD_ATTRS(_method_id), \120}; \121ADD_UVERBS_METHODS(_name, _object_id, &UVERBS_METHOD(_method_id))122123#endif124125126