@@ -156,3 +156,82 @@ int ibv_cmd_reg_dmabuf_mr(struct ibv_pd *pd, uint64_t offset, size_t length,
156
156
vmr -> mr_type = IBV_MR_TYPE_DMABUF_MR ;
157
157
return 0 ;
158
158
}
159
+
160
+ int ibv_cmd_reg_mr_ex (struct ibv_pd * pd , struct verbs_mr * vmr ,
161
+ struct ibv_reg_mr_in * in )
162
+ {
163
+ DECLARE_COMMAND_BUFFER (cmdb , UVERBS_OBJECT_MR ,
164
+ UVERBS_METHOD_REG_MR , 11 );
165
+ bool fd_based = (in -> comp_mask & IBV_REG_MR_MASK_FD );
166
+ struct ib_uverbs_attr * handle ;
167
+ uint64_t length = in -> length ;
168
+ uint32_t lkey , rkey ;
169
+ int ret ;
170
+
171
+ if (fd_based ) {
172
+ if (!(in -> comp_mask & IBV_REG_MR_MASK_FD_OFFSET ) ||
173
+ (in -> comp_mask & IBV_REG_MR_MASK_ADDR )) {
174
+ errno = EINVAL ;
175
+ return EINVAL ;
176
+ }
177
+ fill_attr_in_uint64 (cmdb , UVERBS_ATTR_REG_MR_FD_OFFSET , in -> fd_offset );
178
+ fill_attr_in_fd (cmdb , UVERBS_ATTR_REG_MR_FD ,
179
+ in -> fd );
180
+ } else {
181
+ if ((in -> comp_mask & IBV_REG_MR_MASK_FD_OFFSET ) ||
182
+ !(in -> comp_mask & IBV_REG_MR_MASK_ADDR )) {
183
+ errno = EINVAL ;
184
+ return EINVAL ;
185
+ }
186
+
187
+ fill_attr_in_uint64 (cmdb , UVERBS_ATTR_REG_MR_ADDR , (uintptr_t )in -> addr );
188
+ if (in -> access & IBV_ACCESS_ON_DEMAND ) {
189
+ if (in -> length == SIZE_MAX && in -> addr ) {
190
+ errno = EINVAL ;
191
+ return EINVAL ;
192
+ }
193
+ if (in -> length == SIZE_MAX )
194
+ length = UINT64_MAX ;
195
+ }
196
+ }
197
+
198
+ if (in -> comp_mask & IBV_REG_MR_MASK_IOVA ) {
199
+ fill_attr_in_uint64 (cmdb , UVERBS_ATTR_REG_MR_IOVA , in -> iova );
200
+ } else {
201
+ if (!fd_based ) {
202
+ fill_attr_in_uint64 (cmdb , UVERBS_ATTR_REG_MR_IOVA ,
203
+ (uintptr_t )in -> addr );
204
+ } else {
205
+ /* iova is a must from kernel point of view */
206
+ errno = EINVAL ;
207
+ return EINVAL ;
208
+ }
209
+ }
210
+
211
+ handle = fill_attr_out_obj (cmdb , UVERBS_ATTR_REG_MR_HANDLE );
212
+ fill_attr_out_ptr (cmdb , UVERBS_ATTR_REG_MR_RESP_LKEY , & lkey );
213
+ fill_attr_out_ptr (cmdb , UVERBS_ATTR_REG_MR_RESP_RKEY , & rkey );
214
+ fill_attr_in_obj (cmdb , UVERBS_ATTR_REG_MR_PD_HANDLE , pd -> handle );
215
+ fill_attr_in_uint64 (cmdb , UVERBS_ATTR_REG_MR_LENGTH , length );
216
+ fill_attr_in_uint32 (cmdb , UVERBS_ATTR_REG_MR_ACCESS_FLAGS , in -> access );
217
+
218
+ if (in -> comp_mask & IBV_REG_MR_MASK_DMAH )
219
+ fill_attr_in_obj (cmdb , UVERBS_ATTR_REG_MR_DMA_HANDLE ,
220
+ verbs_get_dmah (in -> dmah )-> handle );
221
+
222
+ ret = execute_ioctl (pd -> context , cmdb );
223
+ if (ret )
224
+ return errno ;
225
+
226
+ vmr -> ibv_mr .handle = read_attr_obj (UVERBS_ATTR_REG_MR_HANDLE ,
227
+ handle );
228
+ vmr -> ibv_mr .context = pd -> context ;
229
+ vmr -> ibv_mr .lkey = lkey ;
230
+ vmr -> ibv_mr .rkey = rkey ;
231
+ if (fd_based )
232
+ vmr -> mr_type = IBV_MR_TYPE_DMABUF_MR ;
233
+ else
234
+ vmr -> mr_type = IBV_MR_TYPE_MR ;
235
+
236
+ return 0 ;
237
+ }
0 commit comments