]>
Commit | Line | Data |
---|---|---|
6be60aed MB |
1 | /* |
2 | * Copyright (c) 2017, Mellanox Technologies inc. All rights reserved. | |
3 | * | |
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: | |
9 | * | |
10 | * Redistribution and use in source and binary forms, with or | |
11 | * without modification, are permitted provided that the following | |
12 | * conditions are met: | |
13 | * | |
14 | * - Redistributions of source code must retain the above | |
15 | * copyright notice, this list of conditions and the following | |
16 | * disclaimer. | |
17 | * | |
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. | |
22 | * | |
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 | |
30 | * SOFTWARE. | |
31 | */ | |
32 | ||
33 | #ifndef _UVERBS_STD_TYPES__ | |
34 | #define _UVERBS_STD_TYPES__ | |
35 | ||
36 | #include <rdma/uverbs_types.h> | |
37 | ||
09e3ebf8 MB |
38 | enum uverbs_default_objects { |
39 | UVERBS_OBJECT_DEVICE, /* No instances of DEVICE are allowed */ | |
40 | UVERBS_OBJECT_PD, | |
41 | UVERBS_OBJECT_COMP_CHANNEL, | |
42 | UVERBS_OBJECT_CQ, | |
43 | UVERBS_OBJECT_QP, | |
44 | UVERBS_OBJECT_SRQ, | |
45 | UVERBS_OBJECT_AH, | |
46 | UVERBS_OBJECT_MR, | |
47 | UVERBS_OBJECT_MW, | |
48 | UVERBS_OBJECT_FLOW, | |
49 | UVERBS_OBJECT_XRCD, | |
50 | UVERBS_OBJECT_RWQ_IND_TBL, | |
51 | UVERBS_OBJECT_WQ, | |
52 | UVERBS_OBJECT_LAST, | |
53 | }; | |
54 | ||
5009010f MB |
55 | extern const struct uverbs_object_def uverbs_object_comp_channel; |
56 | extern const struct uverbs_object_def uverbs_object_cq; | |
57 | extern const struct uverbs_object_def uverbs_object_qp; | |
58 | extern const struct uverbs_object_def uverbs_object_rwq_ind_table; | |
59 | extern const struct uverbs_object_def uverbs_object_wq; | |
60 | extern const struct uverbs_object_def uverbs_object_srq; | |
61 | extern const struct uverbs_object_def uverbs_object_ah; | |
62 | extern const struct uverbs_object_def uverbs_object_flow; | |
63 | extern const struct uverbs_object_def uverbs_object_mr; | |
64 | extern const struct uverbs_object_def uverbs_object_mw; | |
65 | extern const struct uverbs_object_def uverbs_object_pd; | |
66 | extern const struct uverbs_object_def uverbs_object_xrcd; | |
09e3ebf8 | 67 | extern const struct uverbs_object_def uverbs_object_device; |
fd3c7904 MB |
68 | |
69 | static inline struct ib_uobject *__uobj_get(const struct uverbs_obj_type *type, | |
70 | bool write, | |
71 | struct ib_ucontext *ucontext, | |
72 | int id) | |
73 | { | |
74 | return rdma_lookup_get_uobject(type, ucontext, id, write); | |
75 | } | |
76 | ||
5009010f | 77 | #define uobj_get_type(_object) uverbs_object_##_object.type_attrs |
fd3c7904 MB |
78 | |
79 | #define uobj_get_read(_type, _id, _ucontext) \ | |
5009010f | 80 | __uobj_get(_type, false, _ucontext, _id) |
fd3c7904 | 81 | |
5009010f | 82 | #define uobj_get_obj_read(_object, _id, _ucontext) \ |
fd3c7904 | 83 | ({ \ |
5009010f MB |
84 | struct ib_uobject *__uobj = \ |
85 | __uobj_get(uverbs_object_##_object.type_attrs, \ | |
fd3c7904 MB |
86 | false, _ucontext, _id); \ |
87 | \ | |
5009010f | 88 | (struct ib_##_object *)(IS_ERR(__uobj) ? NULL : __uobj->object);\ |
fd3c7904 MB |
89 | }) |
90 | ||
91 | #define uobj_get_write(_type, _id, _ucontext) \ | |
5009010f | 92 | __uobj_get(_type, true, _ucontext, _id) |
fd3c7904 MB |
93 | |
94 | static inline void uobj_put_read(struct ib_uobject *uobj) | |
95 | { | |
96 | rdma_lookup_put_uobject(uobj, false); | |
97 | } | |
98 | ||
99 | #define uobj_put_obj_read(_obj) \ | |
100 | uobj_put_read((_obj)->uobject) | |
101 | ||
102 | static inline void uobj_put_write(struct ib_uobject *uobj) | |
103 | { | |
104 | rdma_lookup_put_uobject(uobj, true); | |
105 | } | |
106 | ||
107 | static inline int __must_check uobj_remove_commit(struct ib_uobject *uobj) | |
108 | { | |
109 | return rdma_remove_commit_uobject(uobj); | |
110 | } | |
111 | ||
112 | static inline void uobj_alloc_commit(struct ib_uobject *uobj) | |
113 | { | |
114 | rdma_alloc_commit_uobject(uobj); | |
115 | } | |
116 | ||
117 | static inline void uobj_alloc_abort(struct ib_uobject *uobj) | |
118 | { | |
119 | rdma_alloc_abort_uobject(uobj); | |
120 | } | |
121 | ||
122 | static inline struct ib_uobject *__uobj_alloc(const struct uverbs_obj_type *type, | |
123 | struct ib_ucontext *ucontext) | |
124 | { | |
125 | return rdma_alloc_begin_uobject(type, ucontext); | |
126 | } | |
127 | ||
128 | #define uobj_alloc(_type, ucontext) \ | |
5009010f | 129 | __uobj_alloc(_type, ucontext) |
fd3c7904 | 130 | |
6be60aed MB |
131 | #endif |
132 |