forked from paravmellanox/rtool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathioctl.c
More file actions
245 lines (226 loc) · 7.32 KB
/
ioctl.c
File metadata and controls
245 lines (226 loc) · 7.32 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#include <stdint.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include "rdma_user_ioctl_cmds.h"
#include "ib_user_ioctl_cmds.h"
static int get_object_handles(int fd, int obj_type, int max_count,
uint32_t *handles,
uint32_t *ret_count)
{
struct cmd {
struct ib_uverbs_ioctl_hdr hdr;
struct ib_uverbs_attr attrs[3];
};
struct cmd op = {
.hdr = {
.length = sizeof(op),
.object_id = UVERBS_OBJECT_DEVICE,
.method_id = UVERBS_METHOD_INFO_HANDLES,
.num_attrs = 3,
.driver_id = RDMA_DRIVER_MLX5,
},
.attrs[0] = {
.attr_id = UVERBS_ATTR_INFO_HANDLES_LIST,
.flags = UVERBS_ATTR_F_MANDATORY,
.data.data = (uintptr_t)handles,
.len = max_count * sizeof(*handles),
},
.attrs[1] = {
.attr_id = UVERBS_ATTR_INFO_OBJECT_ID,
.flags = UVERBS_ATTR_F_MANDATORY,
.data.data = obj_type,
.len = sizeof(uint64_t),
},
.attrs[2] = {
.attr_id = UVERBS_ATTR_INFO_TOTAL_HANDLES,
.flags = UVERBS_ATTR_F_MANDATORY,
.data.data = (uintptr_t)ret_count,
.len = sizeof(uint32_t),
},
};
if (ioctl(fd, RDMA_VERBS_IOCTL, &op))
return errno;
return 0;
}
/**
* rdma_core_get_obj_handles - Get list of MR handles.
* @fd: file descriptor of the ucontext shared via fd sharing
* @max_count: maximum number of handles that caller likes to
* receive in the response.
* @handles: Pointer to handles, where array will of handles will be
* allocated.
* @ret_count: Number of handles filled up in the handles array.
* This could be same or less than the value specificed in
* max_count when API returns success.
* rdma_core_get_obj_handles() allocates and returns pointer to handles array
* when it returns succussful completion. max_count could be a any large
* reasonable value. Caller must free memory returned at handles once caller
* is done accessing handles array.
*/
int rdma_core_get_obj_handles(int fd, int max_count, uint32_t obj_type,
uint32_t **handles, uint32_t *ret_count)
{
uint32_t *handles_array;
int ret;
handles_array = calloc(max_count, sizeof(uint32_t));
if (!handles_array)
return -ENOMEM;
ret = get_object_handles(fd, obj_type, max_count,
handles_array, ret_count);
if (ret < 0)
goto err;
*handles = handles_array;
return 0;
err:
free(handles_array);
return ret;
}
/**
* rdma_core_destroy_obj_by_handle - destroy obj by its handle.
*
* @fd: file descriptor of the ucontext shared via fd sharing
* @handle: handle returned by rdma_core_get_obj_handles()
* @type: object type such as MR, PD, CQ etc
* @attr_id: respective attribute id for the given object type
* rdma_core_destroy_mr_by_handle() destroys an object by its handle.
* It returns 0 on success and failure error code otherwise.
*/
static int
rdma_core_destroy_obj_by_handle(int fd, uint32_t type, uint32_t method,
uint32_t attr_id, uint32_t handle)
{
struct cmd {
struct ib_uverbs_ioctl_hdr hdr;
struct ib_uverbs_attr attrs[1];
};
struct cmd op = {
.hdr = {
.length = sizeof(op),
.object_id = type,
.method_id = method,
.num_attrs = 1,
.driver_id = RDMA_DRIVER_MLX5,
},
.attrs[0] = {
.attr_id = attr_id,
.flags = UVERBS_ATTR_F_MANDATORY,
.data.data = handle,
},
};
if (ioctl(fd, RDMA_VERBS_IOCTL, &op))
return errno;
return 0;
}
/**
* rdma_core_destroy_mr_by_handle - destroy mr by its handle.
*
* @fd: file descriptor of the ucontext shared via fd sharing
* @handle: handle returned by rdma_core_get_obj_handles()
*
* rdma_core_destroy_mr_by_handle() destroys a MR by its handle.
* It returns 0 on success and failure error code otherwise.
*/
int rdma_core_destroy_mr_by_handle(int fd, uint32_t handle)
{
return rdma_core_destroy_obj_by_handle(fd, UVERBS_OBJECT_MR,
UVERBS_METHOD_MR_DESTROY,
UVERBS_ATTR_DESTROY_MR_HANDLE,
handle);
}
/**
* rdma_core_destroy_pd_by_handle - destroy pd by its handle.
*
* @fd: file descriptor of the ucontext shared via fd sharing
* @handle: handle returned by rdma_core_get_obj_handles()
*
* rdma_core_destroy_pd_by_handle() destroys a PD by its handle.
* It returns 0 on success and failure error code otherwise.
*/
int rdma_core_destroy_pd_by_handle(int fd, uint32_t handle)
{
return rdma_core_destroy_obj_by_handle(fd, UVERBS_OBJECT_PD,
UVERBS_METHOD_PD_DESTROY,
UVERBS_ATTR_DESTROY_PD_HANDLE,
handle);
}
/**
* rdma_core_destroy_mw_by_handle - destroy mw by its handle.
*
* @fd: file descriptor of the ucontext shared via fd sharing
* @handle: handle returned by rdma_core_get_obj_handles()
*
* rdma_core_destroy_mw_by_handle() destroys a MW by its handle.
* It returns 0 on success and failure error code otherwise.
*/
int rdma_core_destroy_mw_by_handle(int fd, uint32_t handle)
{
return rdma_core_destroy_obj_by_handle(fd, UVERBS_OBJECT_MW,
UVERBS_METHOD_MW_DESTROY,
UVERBS_ATTR_DESTROY_MW_HANDLE,
handle);
}
/**
* rdma_core_destroy_xrcd_by_handle - destroy xrcd by its handle.
*
* @fd: file descriptor of the ucontext shared via fd sharing
* @handle: handle returned by rdma_core_get_obj_handles()
*
* rdma_core_destroy_xrcd_by_handle() destroys a XRCD by its handle.
* It returns 0 on success and failure error code otherwise.
*/
int rdma_core_destroy_xrcd_by_handle(int fd, uint32_t handle)
{
return rdma_core_destroy_obj_by_handle(fd, UVERBS_OBJECT_XRCD,
UVERBS_METHOD_XRCD_DESTROY,
UVERBS_ATTR_DESTROY_XRCD_HANDLE,
handle);
}
/**
* rdma_core_destroy_rwq_ind_tbl_by_handle - destroy RQ indirection table by its handle.
*
* @fd: file descriptor of the ucontext shared via fd sharing
* @handle: handle returned by rdma_core_get_obj_handles()
*
* rdma_core_destroy_rwq_ind_tbl_by_handle() destroy RQ indirection table by its handle.
* It returns 0 on success and failure error code otherwise.
*/
int rdma_core_destroy_rwq_ind_tbl_by_handle(int fd, uint32_t handle)
{
return rdma_core_destroy_obj_by_handle(fd, UVERBS_OBJECT_RWQ_IND_TBL,
UVERBS_METHOD_RWQ_IND_TBL_DESTROY,
UVERBS_ATTR_DESTROY_RWQ_IND_TBL_HANDLE,
handle);
}
/**
* rdma_core_destroy_ah_by_handle - destroy ah by its handle.
*
* @fd: file descriptor of the ucontext shared via fd sharing
* @handle: handle returned by rdma_core_get_obj_handles()
*
* rdma_core_destroy_ah_by_handle() destroys an AH by its handle.
* It returns 0 on success and failure error code otherwise.
*/
int rdma_core_destroy_ah_by_handle(int fd, uint32_t handle)
{
return rdma_core_destroy_obj_by_handle(fd, UVERBS_OBJECT_AH,
UVERBS_METHOD_AH_DESTROY,
UVERBS_ATTR_DESTROY_AH_HANDLE,
handle);
}
/**
* rdma_core_destroy_flow_by_handle - destroy flow by its handle.
*
* @fd: file descriptor of the ucontext shared via fd sharing
* @handle: handle returned by rdma_core_get_obj_handles()
*
* rdma_core_destroy_flow_by_handle() destroys an FLOW by its handle.
* It returns 0 on success and failure error code otherwise.
*/
int rdma_core_destroy_flow_by_handle(int fd, uint32_t handle)
{
return rdma_core_destroy_obj_by_handle(fd, UVERBS_OBJECT_FLOW,
UVERBS_METHOD_FLOW_DESTROY,
UVERBS_ATTR_DESTROY_FLOW_HANDLE,
handle);
}