0001
0002
0003
0004
0005
0006 #ifndef _UVERBS_TYPES_
0007 #define _UVERBS_TYPES_
0008
0009 #include <linux/kernel.h>
0010 #include <rdma/ib_verbs.h>
0011
0012 struct uverbs_obj_type;
0013 struct uverbs_api_object;
0014
0015 enum rdma_lookup_mode {
0016 UVERBS_LOOKUP_READ,
0017 UVERBS_LOOKUP_WRITE,
0018
0019
0020
0021
0022
0023 UVERBS_LOOKUP_DESTROY,
0024 };
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057 struct uverbs_obj_type_class {
0058 struct ib_uobject *(*alloc_begin)(const struct uverbs_api_object *obj,
0059 struct uverbs_attr_bundle *attrs);
0060
0061 void (*alloc_commit)(struct ib_uobject *uobj);
0062
0063 void (*alloc_abort)(struct ib_uobject *uobj);
0064
0065 struct ib_uobject *(*lookup_get)(const struct uverbs_api_object *obj,
0066 struct ib_uverbs_file *ufile, s64 id,
0067 enum rdma_lookup_mode mode);
0068 void (*lookup_put)(struct ib_uobject *uobj, enum rdma_lookup_mode mode);
0069
0070 int __must_check (*destroy_hw)(struct ib_uobject *uobj,
0071 enum rdma_remove_reason why,
0072 struct uverbs_attr_bundle *attrs);
0073 void (*remove_handle)(struct ib_uobject *uobj);
0074 void (*swap_uobjects)(struct ib_uobject *obj_old,
0075 struct ib_uobject *obj_new);
0076 };
0077
0078 struct uverbs_obj_type {
0079 const struct uverbs_obj_type_class * const type_class;
0080 size_t obj_size;
0081 };
0082
0083
0084
0085
0086
0087
0088
0089
0090 struct uverbs_obj_idr_type {
0091
0092
0093
0094
0095
0096 struct uverbs_obj_type type;
0097
0098
0099
0100
0101
0102
0103 int __must_check (*destroy_object)(struct ib_uobject *uobj,
0104 enum rdma_remove_reason why,
0105 struct uverbs_attr_bundle *attrs);
0106 };
0107
0108 struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_api_object *obj,
0109 struct ib_uverbs_file *ufile, s64 id,
0110 enum rdma_lookup_mode mode,
0111 struct uverbs_attr_bundle *attrs);
0112 void rdma_lookup_put_uobject(struct ib_uobject *uobj,
0113 enum rdma_lookup_mode mode);
0114 struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_api_object *obj,
0115 struct uverbs_attr_bundle *attrs);
0116 void rdma_alloc_abort_uobject(struct ib_uobject *uobj,
0117 struct uverbs_attr_bundle *attrs,
0118 bool hw_obj_valid);
0119 void rdma_alloc_commit_uobject(struct ib_uobject *uobj,
0120 struct uverbs_attr_bundle *attrs);
0121 void rdma_assign_uobject(struct ib_uobject *to_uobj,
0122 struct ib_uobject *new_uobj,
0123 struct uverbs_attr_bundle *attrs);
0124
0125
0126
0127
0128
0129
0130
0131 static inline void uverbs_uobject_get(struct ib_uobject *uobject)
0132 {
0133 kref_get(&uobject->ref);
0134 }
0135 void uverbs_uobject_put(struct ib_uobject *uobject);
0136
0137 struct uverbs_obj_fd_type {
0138
0139
0140
0141
0142
0143
0144
0145 struct uverbs_obj_type type;
0146 void (*destroy_object)(struct ib_uobject *uobj,
0147 enum rdma_remove_reason why);
0148 const struct file_operations *fops;
0149 const char *name;
0150 int flags;
0151 };
0152
0153 extern const struct uverbs_obj_type_class uverbs_idr_class;
0154 extern const struct uverbs_obj_type_class uverbs_fd_class;
0155 int uverbs_uobject_fd_release(struct inode *inode, struct file *filp);
0156
0157 #define UVERBS_BUILD_BUG_ON(cond) (sizeof(char[1 - 2 * !!(cond)]) - \
0158 sizeof(char))
0159 #define UVERBS_TYPE_ALLOC_FD(_obj_size, _destroy_object, _fops, _name, _flags) \
0160 ((&((const struct uverbs_obj_fd_type) \
0161 {.type = { \
0162 .type_class = &uverbs_fd_class, \
0163 .obj_size = (_obj_size) + \
0164 UVERBS_BUILD_BUG_ON((_obj_size) < \
0165 sizeof(struct ib_uobject)), \
0166 }, \
0167 .destroy_object = _destroy_object, \
0168 .fops = _fops, \
0169 .name = _name, \
0170 .flags = _flags}))->type)
0171 #define UVERBS_TYPE_ALLOC_IDR_SZ(_size, _destroy_object) \
0172 ((&((const struct uverbs_obj_idr_type) \
0173 {.type = { \
0174 .type_class = &uverbs_idr_class, \
0175 .obj_size = (_size) + \
0176 UVERBS_BUILD_BUG_ON((_size) < \
0177 sizeof(struct ib_uobject)) \
0178 }, \
0179 .destroy_object = _destroy_object,}))->type)
0180 #define UVERBS_TYPE_ALLOC_IDR(_destroy_object) \
0181 UVERBS_TYPE_ALLOC_IDR_SZ(sizeof(struct ib_uobject), \
0182 _destroy_object)
0183
0184 #endif