2 * Copyright (c) 2018, Mellanox Technologies inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #include <rdma/uverbs_std_types.h>
36 static int uverbs_free_mr(struct ib_uobject *uobject,
37 enum rdma_remove_reason why)
39 return ib_dereg_mr((struct ib_mr *)uobject->object);
42 static int UVERBS_HANDLER(UVERBS_METHOD_DM_MR_REG)(
43 struct uverbs_attr_bundle *attrs)
45 struct ib_dm_mr_attr attr = {};
46 struct ib_uobject *uobj =
47 uverbs_attr_get_uobject(attrs, UVERBS_ATTR_REG_DM_MR_HANDLE);
49 uverbs_attr_get_obj(attrs, UVERBS_ATTR_REG_DM_MR_DM_HANDLE);
51 uverbs_attr_get_obj(attrs, UVERBS_ATTR_REG_DM_MR_PD_HANDLE);
52 struct ib_device *ib_dev = pd->device;
57 if (!ib_dev->reg_dm_mr)
60 ret = uverbs_copy_from(&attr.offset, attrs, UVERBS_ATTR_REG_DM_MR_OFFSET);
64 ret = uverbs_copy_from(&attr.length, attrs,
65 UVERBS_ATTR_REG_DM_MR_LENGTH);
69 ret = uverbs_get_flags32(&attr.access_flags, attrs,
70 UVERBS_ATTR_REG_DM_MR_ACCESS_FLAGS,
75 if (!(attr.access_flags & IB_ZERO_BASED))
78 ret = ib_check_mr_access(attr.access_flags);
82 if (attr.offset > dm->length || attr.length > dm->length ||
83 attr.length > dm->length - attr.offset)
86 mr = pd->device->reg_dm_mr(pd, dm, &attr, attrs);
90 mr->device = pd->device;
94 atomic_inc(&pd->usecnt);
95 atomic_inc(&dm->usecnt);
99 ret = uverbs_copy_to(attrs, UVERBS_ATTR_REG_DM_MR_RESP_LKEY, &mr->lkey,
104 ret = uverbs_copy_to(attrs, UVERBS_ATTR_REG_DM_MR_RESP_RKEY,
105 &mr->rkey, sizeof(mr->rkey));
117 DECLARE_UVERBS_NAMED_METHOD(
118 UVERBS_METHOD_DM_MR_REG,
119 UVERBS_ATTR_IDR(UVERBS_ATTR_REG_DM_MR_HANDLE,
123 UVERBS_ATTR_PTR_IN(UVERBS_ATTR_REG_DM_MR_OFFSET,
124 UVERBS_ATTR_TYPE(u64),
126 UVERBS_ATTR_PTR_IN(UVERBS_ATTR_REG_DM_MR_LENGTH,
127 UVERBS_ATTR_TYPE(u64),
129 UVERBS_ATTR_IDR(UVERBS_ATTR_REG_DM_MR_PD_HANDLE,
133 UVERBS_ATTR_FLAGS_IN(UVERBS_ATTR_REG_DM_MR_ACCESS_FLAGS,
134 enum ib_access_flags),
135 UVERBS_ATTR_IDR(UVERBS_ATTR_REG_DM_MR_DM_HANDLE,
139 UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_REG_DM_MR_RESP_LKEY,
140 UVERBS_ATTR_TYPE(u32),
142 UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_REG_DM_MR_RESP_RKEY,
143 UVERBS_ATTR_TYPE(u32),
146 DECLARE_UVERBS_NAMED_OBJECT(
148 UVERBS_TYPE_ALLOC_IDR(uverbs_free_mr),
149 &UVERBS_METHOD(UVERBS_METHOD_DM_MR_REG));
151 const struct uapi_definition uverbs_def_obj_mr[] = {
152 UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_MR,
153 UAPI_DEF_OBJ_NEEDS_FN(dereg_mr)),