1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#ifndef _UVERBS_TYPES_
34#define _UVERBS_TYPES_
35
36#include <linux/kernel.h>
37#include <rdma/ib_verbs.h>
38
39struct uverbs_obj_type;
40struct uverbs_api_object;
41
42enum rdma_lookup_mode {
43 UVERBS_LOOKUP_READ,
44 UVERBS_LOOKUP_WRITE,
45
46
47
48
49
50 UVERBS_LOOKUP_DESTROY,
51};
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84struct uverbs_obj_type_class {
85 struct ib_uobject *(*alloc_begin)(const struct uverbs_api_object *obj,
86 struct ib_uverbs_file *ufile);
87
88 int (*alloc_commit)(struct ib_uobject *uobj);
89
90 void (*alloc_abort)(struct ib_uobject *uobj);
91
92 struct ib_uobject *(*lookup_get)(const struct uverbs_api_object *obj,
93 struct ib_uverbs_file *ufile, s64 id,
94 enum rdma_lookup_mode mode);
95 void (*lookup_put)(struct ib_uobject *uobj, enum rdma_lookup_mode mode);
96
97 int __must_check (*destroy_hw)(struct ib_uobject *uobj,
98 enum rdma_remove_reason why,
99 struct uverbs_attr_bundle *attrs);
100 void (*remove_handle)(struct ib_uobject *uobj);
101 u8 needs_kfree_rcu;
102};
103
104struct uverbs_obj_type {
105 const struct uverbs_obj_type_class * const type_class;
106 size_t obj_size;
107};
108
109
110
111
112
113
114
115
116struct uverbs_obj_idr_type {
117
118
119
120
121
122 struct uverbs_obj_type type;
123
124
125
126
127
128
129 int __must_check (*destroy_object)(struct ib_uobject *uobj,
130 enum rdma_remove_reason why,
131 struct uverbs_attr_bundle *attrs);
132};
133
134struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_api_object *obj,
135 struct ib_uverbs_file *ufile, s64 id,
136 enum rdma_lookup_mode mode,
137 struct uverbs_attr_bundle *attrs);
138void rdma_lookup_put_uobject(struct ib_uobject *uobj,
139 enum rdma_lookup_mode mode);
140struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_api_object *obj,
141 struct ib_uverbs_file *ufile,
142 struct uverbs_attr_bundle *attrs);
143void rdma_alloc_abort_uobject(struct ib_uobject *uobj,
144 struct uverbs_attr_bundle *attrs);
145int __must_check rdma_alloc_commit_uobject(struct ib_uobject *uobj,
146 struct uverbs_attr_bundle *attrs);
147
148struct uverbs_obj_fd_type {
149
150
151
152
153
154
155
156 struct uverbs_obj_type type;
157 int (*context_closed)(struct ib_uobject *uobj,
158 enum rdma_remove_reason why);
159 const struct file_operations *fops;
160 const char *name;
161 int flags;
162};
163
164extern const struct uverbs_obj_type_class uverbs_idr_class;
165extern const struct uverbs_obj_type_class uverbs_fd_class;
166void uverbs_close_fd(struct file *f);
167
168#define UVERBS_BUILD_BUG_ON(cond) (sizeof(char[1 - 2 * !!(cond)]) - \
169 sizeof(char))
170#define UVERBS_TYPE_ALLOC_FD(_obj_size, _context_closed, _fops, _name, _flags)\
171 ((&((const struct uverbs_obj_fd_type) \
172 {.type = { \
173 .type_class = &uverbs_fd_class, \
174 .obj_size = (_obj_size) + \
175 UVERBS_BUILD_BUG_ON((_obj_size) < \
176 sizeof(struct ib_uobject)), \
177 }, \
178 .context_closed = _context_closed, \
179 .fops = _fops, \
180 .name = _name, \
181 .flags = _flags}))->type)
182#define UVERBS_TYPE_ALLOC_IDR_SZ(_size, _destroy_object) \
183 ((&((const struct uverbs_obj_idr_type) \
184 {.type = { \
185 .type_class = &uverbs_idr_class, \
186 .obj_size = (_size) + \
187 UVERBS_BUILD_BUG_ON((_size) < \
188 sizeof(struct ib_uobject)) \
189 }, \
190 .destroy_object = _destroy_object,}))->type)
191#define UVERBS_TYPE_ALLOC_IDR(_destroy_object) \
192 UVERBS_TYPE_ALLOC_IDR_SZ(sizeof(struct ib_uobject), \
193 _destroy_object)
194
195#endif
196