From: Sean Hefty <[email protected]>
---
 trunk/ulp/librdmacm/include/rdma/rdma_cma.h |    4 ++
 trunk/ulp/librdmacm/src/cma.cpp             |   64 ++++++++++++++++++++++++++-
 2 files changed, 65 insertions(+), 3 deletions(-)

diff --git a/trunk/ulp/librdmacm/include/rdma/rdma_cma.h 
b/trunk/ulp/librdmacm/include/rdma/rdma_cma.h
index 3836483..16f7f21 100644
--- a/trunk/ulp/librdmacm/include/rdma/rdma_cma.h
+++ b/trunk/ulp/librdmacm/include/rdma/rdma_cma.h
@@ -140,6 +140,10 @@ struct rdma_cm_id
        }       ep;
 
        struct rdma_cm_event            *event;
+       struct ibv_comp_channel         *send_cq_channel;
+       struct ibv_cq                           *send_cq;
+       struct ibv_comp_channel         *recv_cq_channel;
+       struct ibv_cq                           *recv_cq;
 };
 
 struct rdma_conn_param
diff --git a/trunk/ulp/librdmacm/src/cma.cpp b/trunk/ulp/librdmacm/src/cma.cpp
index 3c7bed2..0d6e6f5 100644
--- a/trunk/ulp/librdmacm/src/cma.cpp
+++ b/trunk/ulp/librdmacm/src/cma.cpp
@@ -636,6 +636,55 @@ static int ucma_init_ud_qp(struct cma_id_private *id_priv, 
struct ibv_qp *qp)
                                                 (IBV_QP_STATE | 
IBV_QP_SQ_PSN));
 }
 
+static void ucma_destroy_cqs(struct rdma_cm_id *id)
+{
+       if (id->recv_cq)
+               ibv_destroy_cq(id->recv_cq);
+
+       if (id->recv_cq_channel)
+               ibv_destroy_comp_channel(id->recv_cq_channel);
+
+       if (id->send_cq)
+               ibv_destroy_cq(id->send_cq);
+
+       if (id->send_cq_channel)
+               ibv_destroy_comp_channel(id->send_cq_channel);
+}
+
+static int ucma_create_cqs(struct rdma_cm_id *id, struct ibv_qp_init_attr 
*attr)
+{
+       if (!attr->recv_cq) {
+               id->recv_cq_channel = ibv_create_comp_channel(id->verbs);
+               if (!id->recv_cq_channel)
+                       goto err;
+
+               id->recv_cq = ibv_create_cq(id->verbs, attr->cap.max_recv_wr,
+                                           id, id->recv_cq_channel, 0);
+               if (!id->recv_cq)
+                       goto err;
+
+               attr->recv_cq = id->recv_cq;
+       }
+
+       if (!attr->send_cq) {
+               id->send_cq_channel = ibv_create_comp_channel(id->verbs);
+               if (!id->send_cq_channel)
+                       goto err;
+
+               id->send_cq = ibv_create_cq(id->verbs, attr->cap.max_send_wr,
+                                           id, id->send_cq_channel, 0);
+               if (!id->send_cq)
+                       goto err;
+
+               attr->send_cq = id->send_cq;
+       }
+
+       return 0;
+err:
+       ucma_destroy_cqs(id);
+       return rdma_seterrno(ENOMEM);
+}
+
 __declspec(dllexport)
 int rdma_create_qp(struct rdma_cm_id *id, struct ibv_pd *pd,
                                   struct ibv_qp_init_attr *qp_init_attr)
@@ -651,9 +700,15 @@ int rdma_create_qp(struct rdma_cm_id *id, struct ibv_pd 
*pd,
                return rdma_seterrno(EINVAL);
        }
 
+       ret = ucma_create_cqs(id, qp_init_attr);
+       if (ret) {
+               return ret;
+       }
+
        qp = ibv_create_qp(pd, qp_init_attr);
        if (!qp) {
-               return -1;
+               ret = rdma_seterrno(ENOMEM);
+               goto err1;
        }
 
        if (id->ps == RDMA_PS_TCP) {
@@ -662,13 +717,15 @@ int rdma_create_qp(struct rdma_cm_id *id, struct ibv_pd 
*pd,
                ret = ucma_init_ud_qp(id_priv, qp);
        }
        if (ret) {
-               goto err;
+               goto err2;
        }
 
        id->qp = qp;
        return 0;
-err:
+err2:
        ibv_destroy_qp(qp);
+err1:
+       ucma_destroy_cqs(id);
        return ret;
 }
 
@@ -676,6 +733,7 @@ __declspec(dllexport)
 void rdma_destroy_qp(struct rdma_cm_id *id)
 {
        ibv_destroy_qp(id->qp);
+       ucma_destroy_cqs(id);
 }
 
 static int ucma_valid_param(struct cma_id_private *id_priv,

_______________________________________________
ofw mailing list
[email protected]
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/ofw

Reply via email to