]> git.openfabrics.org - ~shefty/rdma-win.git/commitdiff
librdmacm: add rdma_create_ep and rdma_destroy_ep
authorSean Hefty <sean.hefty@intel.com>
Mon, 16 Aug 2010 18:10:48 +0000 (11:10 -0700)
committerSean Hefty <sean.hefty@intel.com>
Mon, 16 Aug 2010 19:03:34 +0000 (12:03 -0700)
trunk/ulp/librdmacm/src/cma.cpp

index 77cceb0b9f0e0b6fa61a18dd9da956759361ecac..6e1f93a61853e9021dd1a7734abce23f9e6200a6 100644 (file)
@@ -74,6 +74,8 @@ struct cma_id_private
        int                                                     index;\r
        volatile LONG                           refcnt;\r
        struct rdma_cm_id                       **req_list;\r
+       struct ibv_pd                           *pd;\r
+       struct ibv_qp_init_attr         *qp_init_attr;\r
        uint8_t                                         initiator_depth;\r
        uint8_t                                         responder_resources;\r
 };\r
@@ -948,6 +950,12 @@ int rdma_get_request(struct rdma_cm_id *listen, struct rdma_cm_id **id)
                goto err;\r
        }\r
 \r
+       if (id_priv->qp_init_attr) {\r
+               ret = rdma_create_qp(event->id, id_priv->pd, id_priv->qp_init_attr);\r
+               if (ret)\r
+                       goto err;\r
+       }\r
+\r
        *id = event->id;\r
        (*id)->event = event;\r
        return 0;\r
@@ -1343,6 +1351,84 @@ int rdma_migrate_id(struct rdma_cm_id *id, struct rdma_event_channel *channel)
        return 0;\r
 }\r
 \r
+static int ucma_passive_ep(struct rdma_cm_id *id, struct rdma_addrinfo *res,\r
+                                                  struct ibv_pd *pd, struct ibv_qp_init_attr *qp_init_attr)\r
+{\r
+       struct cma_id_private *id_priv;\r
+       int ret;\r
+\r
+       ret = rdma_bind_addr(id, res->ai_src_addr);\r
+       if (ret)\r
+               return ret;\r
+\r
+       id_priv = CONTAINING_RECORD(id, struct cma_id_private, id);\r
+       id_priv->pd = pd;\r
+\r
+       if (qp_init_attr) {\r
+               id_priv->qp_init_attr = new struct ibv_qp_init_attr;\r
+               if (!id_priv->qp_init_attr)\r
+                       return rdma_seterrno(ENOMEM);\r
+\r
+               *id_priv->qp_init_attr = *qp_init_attr;\r
+               id_priv->qp_init_attr->qp_type = (enum ibv_qp_type) res->ai_qp_type;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+int rdma_create_ep(struct rdma_cm_id **id, struct rdma_addrinfo *res,\r
+                                  struct ibv_pd *pd, struct ibv_qp_init_attr *qp_init_attr)\r
+{\r
+       struct rdma_cm_id *cm_id;\r
+       int ret;\r
+\r
+       ret = rdma_create_id(NULL, &cm_id, NULL, (enum rdma_port_space) res->ai_port_space);\r
+       if (ret)\r
+               return ret;\r
+\r
+       if (res->ai_flags & RAI_PASSIVE) {\r
+               ret = ucma_passive_ep(cm_id, res, pd, qp_init_attr);\r
+               if (ret)\r
+                       goto err;\r
+               goto out;\r
+       }\r
+\r
+       ret = rdma_resolve_addr(cm_id, res->ai_src_addr, res->ai_dst_addr, 2000);\r
+       if (ret)\r
+               goto err;\r
+\r
+       ret = rdma_resolve_route(cm_id, 2000);\r
+       if (ret)\r
+               goto err;\r
+\r
+       qp_init_attr->qp_type = (enum ibv_qp_type) res->ai_qp_type;\r
+       ret = rdma_create_qp(cm_id, pd, qp_init_attr);\r
+       if (ret)\r
+               goto err;\r
+\r
+out:\r
+       *id = cm_id;\r
+       return 0;\r
+\r
+err:\r
+       rdma_destroy_ep(cm_id);\r
+       return ret;\r
+}\r
+\r
+void rdma_destroy_ep(struct rdma_cm_id *id)\r
+{\r
+       struct cma_id_private *id_priv;\r
+\r
+       if (id->qp)\r
+               rdma_destroy_qp(id);\r
+\r
+       id_priv = CONTAINING_RECORD(id, struct cma_id_private, id);\r
+       if (id_priv->qp_init_attr) {\r
+               delete id_priv->qp_init_attr;\r
+       }\r
+       rdma_destroy_id(id);\r
+}\r
+\r
 __declspec(dllexport)\r
 int rdmaw_wsa_errno(int wsa_err)\r
 {\r