Commit 5009010f authored by Matan Barak's avatar Matan Barak Committed by Doug Ledford

IB/core: Declare an object instead of declaring only type attributes

Switch all uverbs_type_attrs_xxxx with DECLARE_UVERBS_OBJECT
macros. This will be later used in order to embed the object
specific methods in the objects as well.
Signed-off-by: default avatarMatan Barak <matanb@mellanox.com>
Reviewed-by: default avatarYishai Hadas <yishaih@mellanox.com>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent fac9658c
...@@ -209,67 +209,51 @@ static int uverbs_hot_unplug_completion_event_file(struct ib_uobject_file *uobj_ ...@@ -209,67 +209,51 @@ static int uverbs_hot_unplug_completion_event_file(struct ib_uobject_file *uobj_
return 0; return 0;
}; };
const struct uverbs_obj_fd_type uverbs_type_attrs_comp_channel = { DECLARE_UVERBS_OBJECT(uverbs_object_comp_channel,
.type = UVERBS_TYPE_ALLOC_FD(sizeof(struct ib_uverbs_completion_event_file), 0), UVERBS_OBJECT_COMP_CHANNEL,
.context_closed = uverbs_hot_unplug_completion_event_file, &UVERBS_TYPE_ALLOC_FD(0,
.fops = &uverbs_event_fops, sizeof(struct ib_uverbs_completion_event_file),
.name = "[infinibandevent]", uverbs_hot_unplug_completion_event_file,
.flags = O_RDONLY, &uverbs_event_fops,
}; "[infinibandevent]", O_RDONLY));
const struct uverbs_obj_idr_type uverbs_type_attrs_cq = { DECLARE_UVERBS_OBJECT(uverbs_object_cq, UVERBS_OBJECT_CQ,
.type = UVERBS_TYPE_ALLOC_IDR_SZ(sizeof(struct ib_ucq_object), 0), &UVERBS_TYPE_ALLOC_IDR_SZ(sizeof(struct ib_ucq_object), 0,
.destroy_object = uverbs_free_cq, uverbs_free_cq));
};
DECLARE_UVERBS_OBJECT(uverbs_object_qp, UVERBS_OBJECT_QP,
const struct uverbs_obj_idr_type uverbs_type_attrs_qp = { &UVERBS_TYPE_ALLOC_IDR_SZ(sizeof(struct ib_uqp_object), 0,
.type = UVERBS_TYPE_ALLOC_IDR_SZ(sizeof(struct ib_uqp_object), 0), uverbs_free_qp));
.destroy_object = uverbs_free_qp,
}; DECLARE_UVERBS_OBJECT(uverbs_object_mw, UVERBS_OBJECT_MW,
&UVERBS_TYPE_ALLOC_IDR(0, uverbs_free_mw));
const struct uverbs_obj_idr_type uverbs_type_attrs_mw = {
.type = UVERBS_TYPE_ALLOC_IDR(0), DECLARE_UVERBS_OBJECT(uverbs_object_mr, UVERBS_OBJECT_MR,
.destroy_object = uverbs_free_mw,
};
const struct uverbs_obj_idr_type uverbs_type_attrs_mr = {
/* 1 is used in order to free the MR after all the MWs */ /* 1 is used in order to free the MR after all the MWs */
.type = UVERBS_TYPE_ALLOC_IDR(1), &UVERBS_TYPE_ALLOC_IDR(1, uverbs_free_mr));
.destroy_object = uverbs_free_mr,
};
const struct uverbs_obj_idr_type uverbs_type_attrs_srq = { DECLARE_UVERBS_OBJECT(uverbs_object_srq, UVERBS_OBJECT_SRQ,
.type = UVERBS_TYPE_ALLOC_IDR_SZ(sizeof(struct ib_usrq_object), 0), &UVERBS_TYPE_ALLOC_IDR_SZ(sizeof(struct ib_usrq_object), 0,
.destroy_object = uverbs_free_srq, uverbs_free_srq));
};
const struct uverbs_obj_idr_type uverbs_type_attrs_ah = { DECLARE_UVERBS_OBJECT(uverbs_object_ah, UVERBS_OBJECT_AH,
.type = UVERBS_TYPE_ALLOC_IDR(0), &UVERBS_TYPE_ALLOC_IDR(0, uverbs_free_ah));
.destroy_object = uverbs_free_ah,
};
const struct uverbs_obj_idr_type uverbs_type_attrs_flow = { DECLARE_UVERBS_OBJECT(uverbs_object_flow, UVERBS_OBJECT_FLOW,
.type = UVERBS_TYPE_ALLOC_IDR(0), &UVERBS_TYPE_ALLOC_IDR(0, uverbs_free_flow));
.destroy_object = uverbs_free_flow,
};
const struct uverbs_obj_idr_type uverbs_type_attrs_wq = { DECLARE_UVERBS_OBJECT(uverbs_object_wq, UVERBS_OBJECT_WQ,
.type = UVERBS_TYPE_ALLOC_IDR_SZ(sizeof(struct ib_uwq_object), 0), &UVERBS_TYPE_ALLOC_IDR_SZ(sizeof(struct ib_uwq_object), 0,
.destroy_object = uverbs_free_wq, uverbs_free_wq));
};
const struct uverbs_obj_idr_type uverbs_type_attrs_rwq_ind_table = { DECLARE_UVERBS_OBJECT(uverbs_object_rwq_ind_table,
.type = UVERBS_TYPE_ALLOC_IDR(0), UVERBS_OBJECT_RWQ_IND_TBL,
.destroy_object = uverbs_free_rwq_ind_tbl, &UVERBS_TYPE_ALLOC_IDR(0, uverbs_free_rwq_ind_tbl));
};
const struct uverbs_obj_idr_type uverbs_type_attrs_xrcd = { DECLARE_UVERBS_OBJECT(uverbs_object_xrcd, UVERBS_OBJECT_XRCD,
.type = UVERBS_TYPE_ALLOC_IDR_SZ(sizeof(struct ib_uxrcd_object), 0), &UVERBS_TYPE_ALLOC_IDR_SZ(sizeof(struct ib_uxrcd_object), 0,
.destroy_object = uverbs_free_xrcd, uverbs_free_xrcd));
};
const struct uverbs_obj_idr_type uverbs_type_attrs_pd = { DECLARE_UVERBS_OBJECT(uverbs_object_pd, UVERBS_OBJECT_PD,
/* 2 is used in order to free the PD after MRs */ /* 2 is used in order to free the PD after MRs */
.type = UVERBS_TYPE_ALLOC_IDR(2), &UVERBS_TYPE_ALLOC_IDR(2, uverbs_free_pd));
.destroy_object = uverbs_free_pd,
};
...@@ -127,6 +127,22 @@ struct uverbs_root_spec { ...@@ -127,6 +127,22 @@ struct uverbs_root_spec {
struct uverbs_object_spec_hash *object_buckets[0]; struct uverbs_object_spec_hash *object_buckets[0];
}; };
/*
* =======================================
* Verbs definitions
* =======================================
*/
struct uverbs_object_def {
const struct uverbs_obj_type *type_attrs;
};
#define _UVERBS_OBJECT(_id, _type_attrs, ...) \
((const struct uverbs_object_def) { \
.type_attrs = _type_attrs})
#define DECLARE_UVERBS_OBJECT(_name, _id, _type_attrs, ...) \
const struct uverbs_object_def _name = \
_UVERBS_OBJECT(_id, _type_attrs, ##__VA_ARGS__)
/* ================================================= /* =================================================
* Parsing infrastructure * Parsing infrastructure
* ================================================= * =================================================
......
...@@ -35,18 +35,18 @@ ...@@ -35,18 +35,18 @@
#include <rdma/uverbs_types.h> #include <rdma/uverbs_types.h>
extern const struct uverbs_obj_fd_type uverbs_type_attrs_comp_channel; extern const struct uverbs_object_def uverbs_object_comp_channel;
extern const struct uverbs_obj_idr_type uverbs_type_attrs_cq; extern const struct uverbs_object_def uverbs_object_cq;
extern const struct uverbs_obj_idr_type uverbs_type_attrs_qp; extern const struct uverbs_object_def uverbs_object_qp;
extern const struct uverbs_obj_idr_type uverbs_type_attrs_rwq_ind_table; extern const struct uverbs_object_def uverbs_object_rwq_ind_table;
extern const struct uverbs_obj_idr_type uverbs_type_attrs_wq; extern const struct uverbs_object_def uverbs_object_wq;
extern const struct uverbs_obj_idr_type uverbs_type_attrs_srq; extern const struct uverbs_object_def uverbs_object_srq;
extern const struct uverbs_obj_idr_type uverbs_type_attrs_ah; extern const struct uverbs_object_def uverbs_object_ah;
extern const struct uverbs_obj_idr_type uverbs_type_attrs_flow; extern const struct uverbs_object_def uverbs_object_flow;
extern const struct uverbs_obj_idr_type uverbs_type_attrs_mr; extern const struct uverbs_object_def uverbs_object_mr;
extern const struct uverbs_obj_idr_type uverbs_type_attrs_mw; extern const struct uverbs_object_def uverbs_object_mw;
extern const struct uverbs_obj_idr_type uverbs_type_attrs_pd; extern const struct uverbs_object_def uverbs_object_pd;
extern const struct uverbs_obj_idr_type uverbs_type_attrs_xrcd; extern const struct uverbs_object_def uverbs_object_xrcd;
static inline struct ib_uobject *__uobj_get(const struct uverbs_obj_type *type, static inline struct ib_uobject *__uobj_get(const struct uverbs_obj_type *type,
bool write, bool write,
...@@ -56,22 +56,22 @@ static inline struct ib_uobject *__uobj_get(const struct uverbs_obj_type *type, ...@@ -56,22 +56,22 @@ static inline struct ib_uobject *__uobj_get(const struct uverbs_obj_type *type,
return rdma_lookup_get_uobject(type, ucontext, id, write); return rdma_lookup_get_uobject(type, ucontext, id, write);
} }
#define uobj_get_type(_type) uverbs_type_attrs_##_type.type #define uobj_get_type(_object) uverbs_object_##_object.type_attrs
#define uobj_get_read(_type, _id, _ucontext) \ #define uobj_get_read(_type, _id, _ucontext) \
__uobj_get(&(_type), false, _ucontext, _id) __uobj_get(_type, false, _ucontext, _id)
#define uobj_get_obj_read(_type, _id, _ucontext) \ #define uobj_get_obj_read(_object, _id, _ucontext) \
({ \ ({ \
struct ib_uobject *uobj = \ struct ib_uobject *__uobj = \
__uobj_get(&uobj_get_type(_type), \ __uobj_get(uverbs_object_##_object.type_attrs, \
false, _ucontext, _id); \ false, _ucontext, _id); \
\ \
(struct ib_##_type *)(IS_ERR(uobj) ? NULL : uobj->object); \ (struct ib_##_object *)(IS_ERR(__uobj) ? NULL : __uobj->object);\
}) })
#define uobj_get_write(_type, _id, _ucontext) \ #define uobj_get_write(_type, _id, _ucontext) \
__uobj_get(&(_type), true, _ucontext, _id) __uobj_get(_type, true, _ucontext, _id)
static inline void uobj_put_read(struct ib_uobject *uobj) static inline void uobj_put_read(struct ib_uobject *uobj)
{ {
...@@ -108,7 +108,7 @@ static inline struct ib_uobject *__uobj_alloc(const struct uverbs_obj_type *type ...@@ -108,7 +108,7 @@ static inline struct ib_uobject *__uobj_alloc(const struct uverbs_obj_type *type
} }
#define uobj_alloc(_type, ucontext) \ #define uobj_alloc(_type, ucontext) \
__uobj_alloc(&(_type), ucontext) __uobj_alloc(_type, ucontext)
#endif #endif
...@@ -151,22 +151,30 @@ extern const struct uverbs_obj_type_class uverbs_fd_class; ...@@ -151,22 +151,30 @@ extern const struct uverbs_obj_type_class uverbs_fd_class;
#define UVERBS_BUILD_BUG_ON(cond) (sizeof(char[1 - 2 * !!(cond)]) - \ #define UVERBS_BUILD_BUG_ON(cond) (sizeof(char[1 - 2 * !!(cond)]) - \
sizeof(char)) sizeof(char))
#define UVERBS_TYPE_ALLOC_FD(_size, _order) \ #define UVERBS_TYPE_ALLOC_FD(_order, _obj_size, _context_closed, _fops, _name, _flags)\
{ \ ((&((const struct uverbs_obj_fd_type) \
{.type = { \
.destroy_order = _order, \ .destroy_order = _order, \
.type_class = &uverbs_fd_class, \ .type_class = &uverbs_fd_class, \
.obj_size = (_size) + \ .obj_size = (_obj_size) + \
UVERBS_BUILD_BUG_ON((_size) < \ UVERBS_BUILD_BUG_ON((_obj_size) < sizeof(struct ib_uobject_file)), \
sizeof(struct ib_uobject_file)),\ }, \
} .context_closed = _context_closed, \
#define UVERBS_TYPE_ALLOC_IDR_SZ(_size, _order) \ .fops = _fops, \
{ \ .name = _name, \
.flags = _flags}))->type)
#define UVERBS_TYPE_ALLOC_IDR_SZ(_size, _order, _destroy_object) \
((&((const struct uverbs_obj_idr_type) \
{.type = { \
.destroy_order = _order, \ .destroy_order = _order, \
.type_class = &uverbs_idr_class, \ .type_class = &uverbs_idr_class, \
.obj_size = (_size) + \ .obj_size = (_size) + \
UVERBS_BUILD_BUG_ON((_size) < \ UVERBS_BUILD_BUG_ON((_size) < \
sizeof(struct ib_uobject)), \ sizeof(struct ib_uobject)) \
} }, \
#define UVERBS_TYPE_ALLOC_IDR(_order) \ .destroy_object = _destroy_object,}))->type)
UVERBS_TYPE_ALLOC_IDR_SZ(sizeof(struct ib_uobject), _order) #define UVERBS_TYPE_ALLOC_IDR(_order, _destroy_object) \
UVERBS_TYPE_ALLOC_IDR_SZ(sizeof(struct ib_uobject), _order, \
_destroy_object)
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment