Commit 172369c5 authored by Sagi Grimberg's avatar Sagi Grimberg Committed by Nicholas Bellinger

iser-target: Introduce isert_[alloc|free]_comps

Move the code for completion context handling to dedicated
routines. This simplifies the code and removes code duplication.
Signed-off-by: default avatarSagi Grimberg <sagig@mellanox.com>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent 40fc069a
...@@ -275,39 +275,31 @@ isert_free_rx_descriptors(struct isert_conn *isert_conn) ...@@ -275,39 +275,31 @@ isert_free_rx_descriptors(struct isert_conn *isert_conn)
static void isert_cq_work(struct work_struct *); static void isert_cq_work(struct work_struct *);
static void isert_cq_callback(struct ib_cq *, void *); static void isert_cq_callback(struct ib_cq *, void *);
static int static void
isert_create_device_ib_res(struct isert_device *device) isert_free_comps(struct isert_device *device)
{ {
struct ib_device *ib_dev = device->ib_device; int i;
struct ib_device_attr *dev_attr;
int ret = 0, i;
int max_cqe;
dev_attr = &device->dev_attr;
ret = isert_query_device(ib_dev, dev_attr);
if (ret)
return ret;
max_cqe = min(ISER_MAX_CQ_LEN, dev_attr->max_cqe); for (i = 0; i < device->comps_used; i++) {
struct isert_comp *comp = &device->comps[i];
/* asign function handlers */ if (comp->cq) {
if (dev_attr->device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS && cancel_work_sync(&comp->work);
dev_attr->device_cap_flags & IB_DEVICE_SIGNATURE_HANDOVER) { ib_destroy_cq(comp->cq);
device->use_fastreg = 1; }
device->reg_rdma_mem = isert_reg_rdma;
device->unreg_rdma_mem = isert_unreg_rdma;
} else {
device->use_fastreg = 0;
device->reg_rdma_mem = isert_map_rdma;
device->unreg_rdma_mem = isert_unmap_cmd;
} }
kfree(device->comps);
}
/* Check signature cap */ static int
device->pi_capable = dev_attr->device_cap_flags & isert_alloc_comps(struct isert_device *device,
IB_DEVICE_SIGNATURE_HANDOVER ? true : false; struct ib_device_attr *attr)
{
int i, max_cqe, ret = 0;
device->comps_used = min(ISERT_MAX_CQ, min_t(int, num_online_cpus(), device->comps_used = min(ISERT_MAX_CQ, min_t(int, num_online_cpus(),
device->ib_device->num_comp_vectors)); device->ib_device->num_comp_vectors));
isert_info("Using %d CQs, %s supports %d vectors support " isert_info("Using %d CQs, %s supports %d vectors support "
"Fast registration %d pi_capable %d\n", "Fast registration %d pi_capable %d\n",
device->comps_used, device->ib_device->name, device->comps_used, device->ib_device->name,
...@@ -321,6 +313,8 @@ isert_create_device_ib_res(struct isert_device *device) ...@@ -321,6 +313,8 @@ isert_create_device_ib_res(struct isert_device *device)
return -ENOMEM; return -ENOMEM;
} }
max_cqe = min(ISER_MAX_CQ_LEN, attr->max_cqe);
for (i = 0; i < device->comps_used; i++) { for (i = 0; i < device->comps_used; i++) {
struct isert_comp *comp = &device->comps[i]; struct isert_comp *comp = &device->comps[i];
...@@ -332,6 +326,7 @@ isert_create_device_ib_res(struct isert_device *device) ...@@ -332,6 +326,7 @@ isert_create_device_ib_res(struct isert_device *device)
(void *)comp, (void *)comp,
max_cqe, i); max_cqe, i);
if (IS_ERR(comp->cq)) { if (IS_ERR(comp->cq)) {
isert_err("Unable to allocate cq\n");
ret = PTR_ERR(comp->cq); ret = PTR_ERR(comp->cq);
comp->cq = NULL; comp->cq = NULL;
goto out_cq; goto out_cq;
...@@ -342,6 +337,40 @@ isert_create_device_ib_res(struct isert_device *device) ...@@ -342,6 +337,40 @@ isert_create_device_ib_res(struct isert_device *device)
goto out_cq; goto out_cq;
} }
return 0;
out_cq:
isert_free_comps(device);
return ret;
}
static int
isert_create_device_ib_res(struct isert_device *device)
{
struct ib_device *ib_dev = device->ib_device;
struct ib_device_attr *dev_attr;
int ret = 0;
dev_attr = &device->dev_attr;
ret = isert_query_device(ib_dev, dev_attr);
if (ret)
return ret;
/* asign function handlers */
if (dev_attr->device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS &&
dev_attr->device_cap_flags & IB_DEVICE_SIGNATURE_HANDOVER) {
device->use_fastreg = 1;
device->reg_rdma_mem = isert_reg_rdma;
device->unreg_rdma_mem = isert_unreg_rdma;
} else {
device->use_fastreg = 0;
device->reg_rdma_mem = isert_map_rdma;
device->unreg_rdma_mem = isert_unmap_cmd;
}
ret = isert_alloc_comps(device, dev_attr);
if (ret)
return ret;
device->pd = ib_alloc_pd(device->ib_device); device->pd = ib_alloc_pd(device->ib_device);
if (IS_ERR(device->pd)) { if (IS_ERR(device->pd)) {
ret = PTR_ERR(device->pd); ret = PTR_ERR(device->pd);
...@@ -358,42 +387,27 @@ isert_create_device_ib_res(struct isert_device *device) ...@@ -358,42 +387,27 @@ isert_create_device_ib_res(struct isert_device *device)
goto out_mr; goto out_mr;
} }
/* Check signature cap */
device->pi_capable = dev_attr->device_cap_flags &
IB_DEVICE_SIGNATURE_HANDOVER ? true : false;
return 0; return 0;
out_mr: out_mr:
ib_dealloc_pd(device->pd); ib_dealloc_pd(device->pd);
out_cq: out_cq:
for (i = 0; i < device->comps_used; i++) { isert_free_comps(device);
struct isert_comp *comp = &device->comps[i];
if (comp->cq) {
cancel_work_sync(&comp->work);
ib_destroy_cq(comp->cq);
}
}
kfree(device->comps);
return ret; return ret;
} }
static void static void
isert_free_device_ib_res(struct isert_device *device) isert_free_device_ib_res(struct isert_device *device)
{ {
int i;
isert_info("device %p\n", device); isert_info("device %p\n", device);
ib_dereg_mr(device->mr); ib_dereg_mr(device->mr);
ib_dealloc_pd(device->pd); ib_dealloc_pd(device->pd);
for (i = 0; i < device->comps_used; i++) { isert_free_comps(device);
struct isert_comp *comp = &device->comps[i];
cancel_work_sync(&comp->work);
ib_destroy_cq(comp->cq);
comp->cq = NULL;
}
kfree(device->comps);
} }
static void static void
......
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