Commit 1a56ff6d authored by Artemy Kovalyov's avatar Artemy Kovalyov Committed by Doug Ledford

IB/core: Separate CQ handle in SRQ context

Before this change CQ attached to SRQ was part of XRC specific extension.
Moving CQ handle out makes it available to other types extending SRQ
functionality.
Signed-off-by: default avatarArtemy Kovalyov <artemyko@mellanox.com>
Reviewed-by: default avatarYossi Itigin <yosefe@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leon@kernel.org>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent 6938fc1e
...@@ -3497,10 +3497,12 @@ static int __uverbs_create_xsrq(struct ib_uverbs_file *file, ...@@ -3497,10 +3497,12 @@ static int __uverbs_create_xsrq(struct ib_uverbs_file *file,
obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object, uobject); obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object, uobject);
atomic_inc(&obj->uxrcd->refcnt); atomic_inc(&obj->uxrcd->refcnt);
}
attr.ext.xrc.cq = uobj_get_obj_read(cq, cmd->cq_handle, if (ib_srq_has_cq(cmd->srq_type)) {
attr.ext.cq = uobj_get_obj_read(cq, cmd->cq_handle,
file->ucontext); file->ucontext);
if (!attr.ext.xrc.cq) { if (!attr.ext.cq) {
ret = -EINVAL; ret = -EINVAL;
goto err_put_xrcd; goto err_put_xrcd;
} }
...@@ -3535,10 +3537,13 @@ static int __uverbs_create_xsrq(struct ib_uverbs_file *file, ...@@ -3535,10 +3537,13 @@ static int __uverbs_create_xsrq(struct ib_uverbs_file *file,
srq->event_handler = attr.event_handler; srq->event_handler = attr.event_handler;
srq->srq_context = attr.srq_context; srq->srq_context = attr.srq_context;
if (ib_srq_has_cq(cmd->srq_type)) {
srq->ext.cq = attr.ext.cq;
atomic_inc(&attr.ext.cq->usecnt);
}
if (cmd->srq_type == IB_SRQT_XRC) { if (cmd->srq_type == IB_SRQT_XRC) {
srq->ext.xrc.cq = attr.ext.xrc.cq;
srq->ext.xrc.xrcd = attr.ext.xrc.xrcd; srq->ext.xrc.xrcd = attr.ext.xrc.xrcd;
atomic_inc(&attr.ext.xrc.cq->usecnt);
atomic_inc(&attr.ext.xrc.xrcd->usecnt); atomic_inc(&attr.ext.xrc.xrcd->usecnt);
} }
...@@ -3561,10 +3566,12 @@ static int __uverbs_create_xsrq(struct ib_uverbs_file *file, ...@@ -3561,10 +3566,12 @@ static int __uverbs_create_xsrq(struct ib_uverbs_file *file,
goto err_copy; goto err_copy;
} }
if (cmd->srq_type == IB_SRQT_XRC) { if (cmd->srq_type == IB_SRQT_XRC)
uobj_put_read(xrcd_uobj); uobj_put_read(xrcd_uobj);
uobj_put_obj_read(attr.ext.xrc.cq);
} if (ib_srq_has_cq(cmd->srq_type))
uobj_put_obj_read(attr.ext.cq);
uobj_put_obj_read(pd); uobj_put_obj_read(pd);
uobj_alloc_commit(&obj->uevent.uobject); uobj_alloc_commit(&obj->uevent.uobject);
...@@ -3577,8 +3584,8 @@ static int __uverbs_create_xsrq(struct ib_uverbs_file *file, ...@@ -3577,8 +3584,8 @@ static int __uverbs_create_xsrq(struct ib_uverbs_file *file,
uobj_put_obj_read(pd); uobj_put_obj_read(pd);
err_put_cq: err_put_cq:
if (cmd->srq_type == IB_SRQT_XRC) if (ib_srq_has_cq(cmd->srq_type))
uobj_put_obj_read(attr.ext.xrc.cq); uobj_put_obj_read(attr.ext.cq);
err_put_xrcd: err_put_xrcd:
if (cmd->srq_type == IB_SRQT_XRC) { if (cmd->srq_type == IB_SRQT_XRC) {
......
...@@ -622,11 +622,13 @@ struct ib_srq *ib_create_srq(struct ib_pd *pd, ...@@ -622,11 +622,13 @@ struct ib_srq *ib_create_srq(struct ib_pd *pd,
srq->event_handler = srq_init_attr->event_handler; srq->event_handler = srq_init_attr->event_handler;
srq->srq_context = srq_init_attr->srq_context; srq->srq_context = srq_init_attr->srq_context;
srq->srq_type = srq_init_attr->srq_type; srq->srq_type = srq_init_attr->srq_type;
if (ib_srq_has_cq(srq->srq_type)) {
srq->ext.cq = srq_init_attr->ext.cq;
atomic_inc(&srq->ext.cq->usecnt);
}
if (srq->srq_type == IB_SRQT_XRC) { if (srq->srq_type == IB_SRQT_XRC) {
srq->ext.xrc.xrcd = srq_init_attr->ext.xrc.xrcd; srq->ext.xrc.xrcd = srq_init_attr->ext.xrc.xrcd;
srq->ext.xrc.cq = srq_init_attr->ext.xrc.cq;
atomic_inc(&srq->ext.xrc.xrcd->usecnt); atomic_inc(&srq->ext.xrc.xrcd->usecnt);
atomic_inc(&srq->ext.xrc.cq->usecnt);
} }
atomic_inc(&pd->usecnt); atomic_inc(&pd->usecnt);
atomic_set(&srq->usecnt, 0); atomic_set(&srq->usecnt, 0);
...@@ -667,19 +669,19 @@ int ib_destroy_srq(struct ib_srq *srq) ...@@ -667,19 +669,19 @@ int ib_destroy_srq(struct ib_srq *srq)
pd = srq->pd; pd = srq->pd;
srq_type = srq->srq_type; srq_type = srq->srq_type;
if (srq_type == IB_SRQT_XRC) { if (ib_srq_has_cq(srq_type))
cq = srq->ext.cq;
if (srq_type == IB_SRQT_XRC)
xrcd = srq->ext.xrc.xrcd; xrcd = srq->ext.xrc.xrcd;
cq = srq->ext.xrc.cq;
}
ret = srq->device->destroy_srq(srq); ret = srq->device->destroy_srq(srq);
if (!ret) { if (!ret) {
atomic_dec(&pd->usecnt); atomic_dec(&pd->usecnt);
if (srq_type == IB_SRQT_XRC) { if (srq_type == IB_SRQT_XRC)
atomic_dec(&xrcd->usecnt); atomic_dec(&xrcd->usecnt);
if (ib_srq_has_cq(srq_type))
atomic_dec(&cq->usecnt); atomic_dec(&cq->usecnt);
} }
}
return ret; return ret;
} }
......
...@@ -178,8 +178,8 @@ struct ib_srq *mlx4_ib_create_srq(struct ib_pd *pd, ...@@ -178,8 +178,8 @@ struct ib_srq *mlx4_ib_create_srq(struct ib_pd *pd,
} }
} }
cqn = (init_attr->srq_type == IB_SRQT_XRC) ? cqn = ib_srq_has_cq(init_attr->srq_type) ?
to_mcq(init_attr->ext.xrc.cq)->mcq.cqn : 0; to_mcq(init_attr->ext.cq)->mcq.cqn : 0;
xrcdn = (init_attr->srq_type == IB_SRQT_XRC) ? xrcdn = (init_attr->srq_type == IB_SRQT_XRC) ?
to_mxrcd(init_attr->ext.xrc.xrcd)->xrcdn : to_mxrcd(init_attr->ext.xrc.xrcd)->xrcdn :
(u16) dev->dev->caps.reserved_xrcds; (u16) dev->dev->caps.reserved_xrcds;
......
...@@ -3217,7 +3217,7 @@ static int create_dev_resources(struct mlx5_ib_resources *devr) ...@@ -3217,7 +3217,7 @@ static int create_dev_resources(struct mlx5_ib_resources *devr)
attr.attr.max_sge = 1; attr.attr.max_sge = 1;
attr.attr.max_wr = 1; attr.attr.max_wr = 1;
attr.srq_type = IB_SRQT_XRC; attr.srq_type = IB_SRQT_XRC;
attr.ext.xrc.cq = devr->c0; attr.ext.cq = devr->c0;
attr.ext.xrc.xrcd = devr->x0; attr.ext.xrc.xrcd = devr->x0;
devr->s0 = mlx5_ib_create_srq(devr->p0, &attr, NULL); devr->s0 = mlx5_ib_create_srq(devr->p0, &attr, NULL);
...@@ -3232,9 +3232,9 @@ static int create_dev_resources(struct mlx5_ib_resources *devr) ...@@ -3232,9 +3232,9 @@ static int create_dev_resources(struct mlx5_ib_resources *devr)
devr->s0->srq_context = NULL; devr->s0->srq_context = NULL;
devr->s0->srq_type = IB_SRQT_XRC; devr->s0->srq_type = IB_SRQT_XRC;
devr->s0->ext.xrc.xrcd = devr->x0; devr->s0->ext.xrc.xrcd = devr->x0;
devr->s0->ext.xrc.cq = devr->c0; devr->s0->ext.cq = devr->c0;
atomic_inc(&devr->s0->ext.xrc.xrcd->usecnt); atomic_inc(&devr->s0->ext.xrc.xrcd->usecnt);
atomic_inc(&devr->s0->ext.xrc.cq->usecnt); atomic_inc(&devr->s0->ext.cq->usecnt);
atomic_inc(&devr->p0->usecnt); atomic_inc(&devr->p0->usecnt);
atomic_set(&devr->s0->usecnt, 0); atomic_set(&devr->s0->usecnt, 0);
...@@ -3253,9 +3253,9 @@ static int create_dev_resources(struct mlx5_ib_resources *devr) ...@@ -3253,9 +3253,9 @@ static int create_dev_resources(struct mlx5_ib_resources *devr)
devr->s1->event_handler = NULL; devr->s1->event_handler = NULL;
devr->s1->srq_context = NULL; devr->s1->srq_context = NULL;
devr->s1->srq_type = IB_SRQT_BASIC; devr->s1->srq_type = IB_SRQT_BASIC;
devr->s1->ext.xrc.cq = devr->c0; devr->s1->ext.cq = devr->c0;
atomic_inc(&devr->p0->usecnt); atomic_inc(&devr->p0->usecnt);
atomic_set(&devr->s0->usecnt, 0); atomic_set(&devr->s1->usecnt, 0);
for (port = 0; port < ARRAY_SIZE(devr->ports); ++port) { for (port = 0; port < ARRAY_SIZE(devr->ports); ++port) {
INIT_WORK(&devr->ports[port].pkey_change_work, INIT_WORK(&devr->ports[port].pkey_change_work,
......
...@@ -292,13 +292,16 @@ struct ib_srq *mlx5_ib_create_srq(struct ib_pd *pd, ...@@ -292,13 +292,16 @@ struct ib_srq *mlx5_ib_create_srq(struct ib_pd *pd,
in.wqe_shift = srq->msrq.wqe_shift - 4; in.wqe_shift = srq->msrq.wqe_shift - 4;
if (srq->wq_sig) if (srq->wq_sig)
in.flags |= MLX5_SRQ_FLAG_WQ_SIG; in.flags |= MLX5_SRQ_FLAG_WQ_SIG;
if (init_attr->srq_type == IB_SRQT_XRC) {
if (init_attr->srq_type == IB_SRQT_XRC)
in.xrcd = to_mxrcd(init_attr->ext.xrc.xrcd)->xrcdn; in.xrcd = to_mxrcd(init_attr->ext.xrc.xrcd)->xrcdn;
in.cqn = to_mcq(init_attr->ext.xrc.cq)->mcq.cqn; else
} else if (init_attr->srq_type == IB_SRQT_BASIC) {
in.xrcd = to_mxrcd(dev->devr.x0)->xrcdn; in.xrcd = to_mxrcd(dev->devr.x0)->xrcdn;
if (ib_srq_has_cq(init_attr->srq_type))
in.cqn = to_mcq(init_attr->ext.cq)->mcq.cqn;
else
in.cqn = to_mcq(dev->devr.c0)->mcq.cqn; in.cqn = to_mcq(dev->devr.c0)->mcq.cqn;
}
in.pd = to_mpd(pd)->pdn; in.pd = to_mpd(pd)->pdn;
in.db_record = srq->db.dma; in.db_record = srq->db.dma;
......
...@@ -994,6 +994,11 @@ enum ib_srq_type { ...@@ -994,6 +994,11 @@ enum ib_srq_type {
IB_SRQT_XRC IB_SRQT_XRC
}; };
static inline bool ib_srq_has_cq(enum ib_srq_type srq_type)
{
return srq_type == IB_SRQT_XRC;
}
enum ib_srq_attr_mask { enum ib_srq_attr_mask {
IB_SRQ_MAX_WR = 1 << 0, IB_SRQ_MAX_WR = 1 << 0,
IB_SRQ_LIMIT = 1 << 1, IB_SRQ_LIMIT = 1 << 1,
...@@ -1011,11 +1016,13 @@ struct ib_srq_init_attr { ...@@ -1011,11 +1016,13 @@ struct ib_srq_init_attr {
struct ib_srq_attr attr; struct ib_srq_attr attr;
enum ib_srq_type srq_type; enum ib_srq_type srq_type;
struct {
struct ib_cq *cq;
union { union {
struct { struct {
struct ib_xrcd *xrcd; struct ib_xrcd *xrcd;
struct ib_cq *cq;
} xrc; } xrc;
};
} ext; } ext;
}; };
...@@ -1554,12 +1561,14 @@ struct ib_srq { ...@@ -1554,12 +1561,14 @@ struct ib_srq {
enum ib_srq_type srq_type; enum ib_srq_type srq_type;
atomic_t usecnt; atomic_t usecnt;
struct {
struct ib_cq *cq;
union { union {
struct { struct {
struct ib_xrcd *xrcd; struct ib_xrcd *xrcd;
struct ib_cq *cq;
u32 srq_num; u32 srq_num;
} xrc; } xrc;
};
} ext; } ext;
}; };
......
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