]>
Commit | Line | Data |
---|---|---|
a0aa309c MB |
1 | /* |
2 | * Copyright (c) 2017, 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_IOCTL_ | |
34 | #define _UVERBS_IOCTL_ | |
35 | ||
36 | #include <rdma/uverbs_types.h> | |
37 | ||
38 | /* | |
39 | * ======================================= | |
40 | * Verbs action specifications | |
41 | * ======================================= | |
42 | */ | |
43 | ||
f43dbebf MB |
44 | enum uverbs_attr_type { |
45 | UVERBS_ATTR_TYPE_NA, | |
fac9658c MB |
46 | UVERBS_ATTR_TYPE_PTR_IN, |
47 | UVERBS_ATTR_TYPE_PTR_OUT, | |
f43dbebf MB |
48 | UVERBS_ATTR_TYPE_IDR, |
49 | UVERBS_ATTR_TYPE_FD, | |
50 | }; | |
51 | ||
a0aa309c MB |
52 | enum uverbs_obj_access { |
53 | UVERBS_ACCESS_READ, | |
54 | UVERBS_ACCESS_WRITE, | |
55 | UVERBS_ACCESS_NEW, | |
56 | UVERBS_ACCESS_DESTROY | |
57 | }; | |
58 | ||
fac9658c MB |
59 | enum { |
60 | UVERBS_ATTR_SPEC_F_MANDATORY = 1U << 0, | |
61 | /* Support extending attributes by length */ | |
62 | UVERBS_ATTR_SPEC_F_MIN_SZ = 1U << 1, | |
63 | }; | |
64 | ||
f43dbebf MB |
65 | struct uverbs_attr_spec { |
66 | enum uverbs_attr_type type; | |
fac9658c MB |
67 | union { |
68 | u16 len; | |
69 | struct { | |
70 | /* | |
71 | * higher bits mean the namespace and lower bits mean | |
72 | * the type id within the namespace. | |
73 | */ | |
74 | u16 obj_type; | |
75 | u8 access; | |
76 | } obj; | |
77 | }; | |
78 | /* Combination of bits from enum UVERBS_ATTR_SPEC_F_XXXX */ | |
79 | u8 flags; | |
f43dbebf MB |
80 | }; |
81 | ||
82 | struct uverbs_attr_spec_hash { | |
83 | size_t num_attrs; | |
fac9658c | 84 | unsigned long *mandatory_attrs_bitmask; |
f43dbebf MB |
85 | struct uverbs_attr_spec attrs[0]; |
86 | }; | |
87 | ||
fac9658c MB |
88 | struct uverbs_attr_bundle; |
89 | struct ib_uverbs_file; | |
90 | ||
91 | enum { | |
92 | /* | |
93 | * Action marked with this flag creates a context (or root for all | |
94 | * objects). | |
95 | */ | |
96 | UVERBS_ACTION_FLAG_CREATE_ROOT = 1U << 0, | |
97 | }; | |
98 | ||
99 | struct uverbs_method_spec { | |
100 | /* Combination of bits from enum UVERBS_ACTION_FLAG_XXXX */ | |
101 | u32 flags; | |
102 | size_t num_buckets; | |
103 | size_t num_child_attrs; | |
104 | int (*handler)(struct ib_device *ib_dev, struct ib_uverbs_file *ufile, | |
105 | struct uverbs_attr_bundle *ctx); | |
106 | struct uverbs_attr_spec_hash *attr_buckets[0]; | |
107 | }; | |
108 | ||
109 | struct uverbs_method_spec_hash { | |
110 | size_t num_methods; | |
111 | struct uverbs_method_spec *methods[0]; | |
112 | }; | |
113 | ||
114 | struct uverbs_object_spec { | |
115 | const struct uverbs_obj_type *type_attrs; | |
116 | size_t num_buckets; | |
117 | struct uverbs_method_spec_hash *method_buckets[0]; | |
118 | }; | |
119 | ||
120 | struct uverbs_object_spec_hash { | |
121 | size_t num_objects; | |
122 | struct uverbs_object_spec *objects[0]; | |
123 | }; | |
124 | ||
125 | struct uverbs_root_spec { | |
126 | size_t num_buckets; | |
127 | struct uverbs_object_spec_hash *object_buckets[0]; | |
128 | }; | |
129 | ||
5009010f MB |
130 | /* |
131 | * ======================================= | |
132 | * Verbs definitions | |
133 | * ======================================= | |
134 | */ | |
135 | ||
09e3ebf8 MB |
136 | struct uverbs_attr_def { |
137 | u16 id; | |
138 | struct uverbs_attr_spec attr; | |
139 | }; | |
140 | ||
141 | struct uverbs_method_def { | |
142 | u16 id; | |
143 | /* Combination of bits from enum UVERBS_ACTION_FLAG_XXXX */ | |
144 | u32 flags; | |
145 | size_t num_attrs; | |
146 | const struct uverbs_attr_def * const (*attrs)[]; | |
147 | int (*handler)(struct ib_device *ib_dev, struct ib_uverbs_file *ufile, | |
148 | struct uverbs_attr_bundle *ctx); | |
149 | }; | |
150 | ||
5009010f | 151 | struct uverbs_object_def { |
09e3ebf8 | 152 | u16 id; |
5009010f | 153 | const struct uverbs_obj_type *type_attrs; |
09e3ebf8 MB |
154 | size_t num_methods; |
155 | const struct uverbs_method_def * const (*methods)[]; | |
156 | }; | |
157 | ||
158 | struct uverbs_object_tree_def { | |
159 | size_t num_objects; | |
160 | const struct uverbs_object_def * const (*objects)[]; | |
5009010f MB |
161 | }; |
162 | ||
163 | #define _UVERBS_OBJECT(_id, _type_attrs, ...) \ | |
164 | ((const struct uverbs_object_def) { \ | |
09e3ebf8 | 165 | .id = _id, \ |
5009010f MB |
166 | .type_attrs = _type_attrs}) |
167 | #define DECLARE_UVERBS_OBJECT(_name, _id, _type_attrs, ...) \ | |
168 | const struct uverbs_object_def _name = \ | |
169 | _UVERBS_OBJECT(_id, _type_attrs, ##__VA_ARGS__) | |
09e3ebf8 MB |
170 | #define _UVERBS_TREE_OBJECTS_SZ(...) \ |
171 | (sizeof((const struct uverbs_object_def * const []){__VA_ARGS__}) / \ | |
172 | sizeof(const struct uverbs_object_def *)) | |
173 | #define _UVERBS_OBJECT_TREE(...) \ | |
174 | ((const struct uverbs_object_tree_def) { \ | |
175 | .num_objects = _UVERBS_TREE_OBJECTS_SZ(__VA_ARGS__), \ | |
176 | .objects = &(const struct uverbs_object_def * const []){__VA_ARGS__} }) | |
177 | #define DECLARE_UVERBS_OBJECT_TREE(_name, ...) \ | |
178 | const struct uverbs_object_tree_def _name = \ | |
179 | _UVERBS_OBJECT_TREE(__VA_ARGS__) | |
180 | ||
fac9658c MB |
181 | /* ================================================= |
182 | * Parsing infrastructure | |
183 | * ================================================= | |
184 | */ | |
185 | ||
186 | struct uverbs_ptr_attr { | |
187 | union { | |
188 | u64 data; | |
189 | void __user *ptr; | |
190 | }; | |
191 | u16 len; | |
192 | /* Combination of bits from enum UVERBS_ATTR_F_XXXX */ | |
193 | u16 flags; | |
194 | }; | |
195 | ||
f43dbebf | 196 | struct uverbs_obj_attr { |
fac9658c MB |
197 | /* pointer to the kernel descriptor -> type, access, etc */ |
198 | const struct uverbs_obj_type *type; | |
f43dbebf | 199 | struct ib_uobject *uobject; |
fac9658c MB |
200 | /* fd or id in idr of this object */ |
201 | int id; | |
f43dbebf MB |
202 | }; |
203 | ||
204 | struct uverbs_attr { | |
fac9658c MB |
205 | /* |
206 | * pointer to the user-space given attribute, in order to write the | |
207 | * new uobject's id or update flags. | |
208 | */ | |
209 | struct ib_uverbs_attr __user *uattr; | |
210 | union { | |
211 | struct uverbs_ptr_attr ptr_attr; | |
212 | struct uverbs_obj_attr obj_attr; | |
213 | }; | |
f43dbebf MB |
214 | }; |
215 | ||
216 | struct uverbs_attr_bundle_hash { | |
217 | /* if bit i is set, it means attrs[i] contains valid information */ | |
218 | unsigned long *valid_bitmap; | |
219 | size_t num_attrs; | |
220 | /* | |
221 | * arrays of attributes, each element corresponds to the specification | |
222 | * of the attribute in the same index. | |
223 | */ | |
224 | struct uverbs_attr *attrs; | |
225 | }; | |
226 | ||
227 | struct uverbs_attr_bundle { | |
228 | size_t num_buckets; | |
229 | struct uverbs_attr_bundle_hash hash[]; | |
230 | }; | |
231 | ||
232 | static inline bool uverbs_attr_is_valid_in_hash(const struct uverbs_attr_bundle_hash *attrs_hash, | |
233 | unsigned int idx) | |
234 | { | |
235 | return test_bit(idx, attrs_hash->valid_bitmap); | |
236 | } | |
237 | ||
a0aa309c MB |
238 | #endif |
239 |