Linux Audio

Check our new training course

Linux debugging, profiling, tracing and performance analysis training

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