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};
75
76struct uverbs_obj_type {
77 const struct uverbs_obj_type_class * const type_class;
78 size_t obj_size;
79};
80
81
82
83
84
85
86
87
88struct uverbs_obj_idr_type {
89
90
91
92
93
94 struct uverbs_obj_type type;
95
96
97
98
99
100
101 int __must_check (*destroy_object)(struct ib_uobject *uobj,
102 enum rdma_remove_reason why,
103 struct uverbs_attr_bundle *attrs);
104};
105
106struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_api_object *obj,
107 struct ib_uverbs_file *ufile, s64 id,
108 enum rdma_lookup_mode mode,
109 struct uverbs_attr_bundle *attrs);
110void rdma_lookup_put_uobject(struct ib_uobject *uobj,
111 enum rdma_lookup_mode mode);
112struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_api_object *obj,
113 struct uverbs_attr_bundle *attrs);
114void rdma_alloc_abort_uobject(struct ib_uobject *uobj,
115 struct uverbs_attr_bundle *attrs,
116 bool hw_obj_valid);
117void rdma_alloc_commit_uobject(struct ib_uobject *uobj,
118 struct uverbs_attr_bundle *attrs);
119
120
121
122
123
124
125
126static inline void uverbs_uobject_get(struct ib_uobject *uobject)
127{
128 kref_get(&uobject->ref);
129}
130void uverbs_uobject_put(struct ib_uobject *uobject);
131
132struct uverbs_obj_fd_type {
133
134
135
136
137
138
139
140 struct uverbs_obj_type type;
141 int (*destroy_object)(struct ib_uobject *uobj,
142 enum rdma_remove_reason why);
143 const struct file_operations *fops;
144 const char *name;
145 int flags;
146};
147
148extern const struct uverbs_obj_type_class uverbs_idr_class;
149extern const struct uverbs_obj_type_class uverbs_fd_class;
150int uverbs_uobject_fd_release(struct inode *inode, struct file *filp);
151
152#define UVERBS_BUILD_BUG_ON(cond) (sizeof(char[1 - 2 * !!(cond)]) - \
153 sizeof(char))
154#define UVERBS_TYPE_ALLOC_FD(_obj_size, _destroy_object, _fops, _name, _flags) \
155 ((&((const struct uverbs_obj_fd_type) \
156 {.type = { \
157 .type_class = &uverbs_fd_class, \
158 .obj_size = (_obj_size) + \
159 UVERBS_BUILD_BUG_ON((_obj_size) < \
160 sizeof(struct ib_uobject)), \
161 }, \
162 .destroy_object = _destroy_object, \
163 .fops = _fops, \
164 .name = _name, \
165 .flags = _flags}))->type)
166#define UVERBS_TYPE_ALLOC_IDR_SZ(_size, _destroy_object) \
167 ((&((const struct uverbs_obj_idr_type) \
168 {.type = { \
169 .type_class = &uverbs_idr_class, \
170 .obj_size = (_size) + \
171 UVERBS_BUILD_BUG_ON((_size) < \
172 sizeof(struct ib_uobject)) \
173 }, \
174 .destroy_object = _destroy_object,}))->type)
175#define UVERBS_TYPE_ALLOC_IDR(_destroy_object) \
176 UVERBS_TYPE_ALLOC_IDR_SZ(sizeof(struct ib_uobject), \
177 _destroy_object)
178
179#endif
180