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