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
34
35
36
37#ifndef RDMA_CORE_H
38#define RDMA_CORE_H
39
40#include <linux/idr.h>
41#include <rdma/uverbs_types.h>
42#include <rdma/uverbs_ioctl.h>
43#include <rdma/ib_verbs.h>
44#include <linux/mutex.h>
45
46struct ib_uverbs_device;
47
48void uverbs_destroy_ufile_hw(struct ib_uverbs_file *ufile,
49 enum rdma_remove_reason reason);
50
51int uobj_destroy(struct ib_uobject *uobj, struct uverbs_attr_bundle *attrs);
52
53
54
55
56
57
58
59
60
61
62struct ib_uobject *
63uverbs_get_uobject_from_file(u16 object_id, enum uverbs_obj_access access,
64 s64 id, struct uverbs_attr_bundle *attrs);
65
66void uverbs_finalize_object(struct ib_uobject *uobj,
67 enum uverbs_obj_access access, bool hw_obj_valid,
68 bool commit, struct uverbs_attr_bundle *attrs);
69
70int uverbs_output_written(const struct uverbs_attr_bundle *bundle, size_t idx);
71
72void setup_ufile_idr_uobject(struct ib_uverbs_file *ufile);
73void release_ufile_idr_uobject(struct ib_uverbs_file *ufile);
74
75struct ib_udata *uverbs_get_cleared_udata(struct uverbs_attr_bundle *attrs);
76
77
78
79
80
81
82
83
84
85
86
87struct uverbs_api_ioctl_method {
88 int(__rcu *handler)(struct uverbs_attr_bundle *attrs);
89 DECLARE_BITMAP(attr_mandatory, UVERBS_API_ATTR_BKEY_LEN);
90 u16 bundle_size;
91 u8 use_stack:1;
92 u8 driver_method:1;
93 u8 disabled:1;
94 u8 has_udata:1;
95 u8 key_bitmap_len;
96 u8 destroy_bkey;
97};
98
99struct uverbs_api_write_method {
100 int (*handler)(struct uverbs_attr_bundle *attrs);
101 u8 disabled:1;
102 u8 is_ex:1;
103 u8 has_udata:1;
104 u8 has_resp:1;
105 u8 req_size;
106 u8 resp_size;
107};
108
109struct uverbs_api_attr {
110 struct uverbs_attr_spec spec;
111};
112
113struct uverbs_api {
114
115 struct radix_tree_root radix;
116 enum rdma_driver_id driver_id;
117
118 unsigned int num_write;
119 unsigned int num_write_ex;
120 struct uverbs_api_write_method notsupp_method;
121 const struct uverbs_api_write_method **write_methods;
122 const struct uverbs_api_write_method **write_ex_methods;
123};
124
125
126
127
128
129
130static inline const struct uverbs_api_object *
131uapi_get_object(struct uverbs_api *uapi, u16 object_id)
132{
133 const struct uverbs_api_object *res;
134
135 if (object_id == UVERBS_IDR_ANY_OBJECT)
136 return ERR_PTR(-ENOMSG);
137
138 res = radix_tree_lookup(&uapi->radix, uapi_key_obj(object_id));
139 if (!res)
140 return ERR_PTR(-ENOENT);
141
142 return res;
143}
144
145char *uapi_key_format(char *S, unsigned int key);
146struct uverbs_api *uverbs_alloc_api(struct ib_device *ibdev);
147void uverbs_disassociate_api_pre(struct ib_uverbs_device *uverbs_dev);
148void uverbs_disassociate_api(struct uverbs_api *uapi);
149void uverbs_destroy_api(struct uverbs_api *uapi);
150void uapi_compute_bundle_size(struct uverbs_api_ioctl_method *method_elm,
151 unsigned int num_attrs);
152void uverbs_user_mmap_disassociate(struct ib_uverbs_file *ufile);
153
154extern const struct uapi_definition uverbs_def_obj_async_fd[];
155extern const struct uapi_definition uverbs_def_obj_counters[];
156extern const struct uapi_definition uverbs_def_obj_cq[];
157extern const struct uapi_definition uverbs_def_obj_device[];
158extern const struct uapi_definition uverbs_def_obj_dm[];
159extern const struct uapi_definition uverbs_def_obj_flow_action[];
160extern const struct uapi_definition uverbs_def_obj_intf[];
161extern const struct uapi_definition uverbs_def_obj_mr[];
162extern const struct uapi_definition uverbs_def_obj_qp[];
163extern const struct uapi_definition uverbs_def_obj_srq[];
164extern const struct uapi_definition uverbs_def_obj_wq[];
165extern const struct uapi_definition uverbs_def_write_intf[];
166
167static inline const struct uverbs_api_write_method *
168uapi_get_method(const struct uverbs_api *uapi, u32 command)
169{
170 u32 cmd_idx = command & IB_USER_VERBS_CMD_COMMAND_MASK;
171
172 if (command & ~(u32)(IB_USER_VERBS_CMD_FLAG_EXTENDED |
173 IB_USER_VERBS_CMD_COMMAND_MASK))
174 return ERR_PTR(-EINVAL);
175
176 if (command & IB_USER_VERBS_CMD_FLAG_EXTENDED) {
177 if (cmd_idx >= uapi->num_write_ex)
178 return ERR_PTR(-EOPNOTSUPP);
179 return uapi->write_ex_methods[cmd_idx];
180 }
181
182 if (cmd_idx >= uapi->num_write)
183 return ERR_PTR(-EOPNOTSUPP);
184 return uapi->write_methods[cmd_idx];
185}
186
187void uverbs_fill_udata(struct uverbs_attr_bundle *bundle,
188 struct ib_udata *udata, unsigned int attr_in,
189 unsigned int attr_out);
190
191#endif
192