]> git.openfabrics.org - ~shefty/librdmacm.git/commitdiff
r4022: Add port_num field to struct rdma_cm_id to make it easier for clients to
authorSean Hefty <sean.hefty@intel.com>
Fri, 11 Nov 2005 19:45:42 +0000 (19:45 +0000)
committerSean Hefty <sean.hefty@intel.com>
Fri, 11 Nov 2005 19:45:42 +0000 (19:45 +0000)
identify which port they are currently using.

Remove a few unneeded variable initializations, and fix a bug where the
IB address was not set after calling rdma_bind_addr() in userspace.

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
include/rdma/rdma_cma.h
include/rdma/rdma_cma_abi.h
src/cma.c

index 40e4c588467157dfa0e3b7fc58ca097bb467502c..89afbe264e0f6753ddb9f48e736f38ea2300a463 100644 (file)
@@ -79,6 +79,7 @@ struct rdma_cm_id {
        void                    *context;
        struct ibv_qp           *qp;
        struct rdma_route        route;
+       uint8_t                  port_num;
 };
 
 struct rdma_cm_event {
index 950f655dcbd461854856603cf91a7db246668236..40290b27f333fc84dcf56375c1469ec498b3dc95 100644 (file)
@@ -91,10 +91,6 @@ struct ucma_abi_bind_addr {
        __u32 id;
 };
 
-struct ucma_abi_bind_addr_resp {
-       __u64 node_guid;
-};
-
 struct ucma_abi_resolve_addr {
        struct sockaddr_in6 src_addr;
        struct sockaddr_in6 dst_addr;
@@ -118,6 +114,8 @@ struct ucma_abi_query_route_resp {
        struct ib_kern_path_rec ib_route[2];
        struct sockaddr_in6 src_addr;
        __u32 num_paths;
+       __u8 port_num;
+       __u8 reserved[7];
 };
 
 struct ucma_abi_conn_param {
index 309a51d9aa3a61ce7a25f1690ae1c91d32f903aa..7afae4bceddd4c137b3c580bbaca7c2c0baa96c6 100644 (file)
--- a/src/cma.c
+++ b/src/cma.c
@@ -291,9 +291,54 @@ static int ucma_addrlen(struct sockaddr *addr)
        }
 }
 
+static int ucma_query_route(struct rdma_cm_id *id)
+{
+       struct ucma_abi_query_route_resp *resp;
+       struct ucma_abi_query_route *cmd;
+       struct cma_id_private *id_priv;
+       void *msg;
+       int ret, size, i;
+       
+       CMA_CREATE_MSG_CMD_RESP(msg, cmd, resp, UCMA_CMD_QUERY_ROUTE, size);
+       id_priv = container_of(id, struct cma_id_private, id);
+       cmd->id = id_priv->handle;
+
+       ret = write(cma_fd, msg, size);
+       if (ret != size)
+               return (ret > 0) ? -ENODATA : ret;
+
+       if (resp->num_paths) {
+               id->route.path_rec = malloc(sizeof *id->route.path_rec *
+                                           resp->num_paths);
+               if (!id->route.path_rec)
+                       return -ENOMEM;
+
+               id->route.num_paths = resp->num_paths;
+               for (i = 0; i < resp->num_paths; i++)
+                       ib_copy_path_rec_from_kern(&id->route.path_rec[i],
+                                                  &resp->ib_route[i]);
+       }
+
+       memcpy(id->route.addr.addr.ibaddr.sgid.raw, resp->ib_route[0].sgid,
+              sizeof id->route.addr.addr.ibaddr.sgid);
+       memcpy(id->route.addr.addr.ibaddr.dgid.raw, resp->ib_route[0].dgid,
+              sizeof id->route.addr.addr.ibaddr.dgid);
+       id->route.addr.addr.ibaddr.pkey = resp->ib_route[0].pkey;
+       memcpy(&id->route.addr.src_addr, &resp->src_addr,
+              sizeof id->route.addr.src_addr);
+
+       if (!id_priv->cma_dev && resp->node_guid) {
+               ret = ucma_get_device(id_priv, resp->node_guid);
+               if (ret)
+                       return ret;
+               id_priv->id.port_num = resp->port_num;
+       }
+
+       return 0;
+}
+
 int rdma_bind_addr(struct rdma_cm_id *id, struct sockaddr *addr)
 {
-       struct ucma_abi_bind_addr_resp *resp;
        struct ucma_abi_bind_addr *cmd;
        struct cma_id_private *id_priv;
        void *msg;
@@ -303,7 +348,7 @@ int rdma_bind_addr(struct rdma_cm_id *id, struct sockaddr *addr)
        if (!addrlen)
                return -EINVAL;
 
-       CMA_CREATE_MSG_CMD_RESP(msg, cmd, resp, UCMA_CMD_BIND_ADDR, size);
+       CMA_CREATE_MSG_CMD(msg, cmd, UCMA_CMD_BIND_ADDR, size);
        id_priv = container_of(id, struct cma_id_private, id);
        cmd->id = id_priv->handle;
        memcpy(&cmd->addr, addr, addrlen);
@@ -312,11 +357,9 @@ int rdma_bind_addr(struct rdma_cm_id *id, struct sockaddr *addr)
        if (ret != size)
                return (ret > 0) ? -ENODATA : ret;
 
-       if (resp->node_guid) {
-               ret = ucma_get_device(id_priv, resp->node_guid);
-               if (ret)
-                       return ret;
-       }
+       ret = ucma_query_route(id);
+       if (ret)
+               return ret;
 
        memcpy(&id->route.addr.src_addr, addr, addrlen);
        return 0;
@@ -442,24 +485,6 @@ static int ucma_modify_qp_err(struct rdma_cm_id *id)
        return ibv_modify_qp(id->qp, &qp_attr, IBV_QP_STATE);
 }
 
-static int ucma_find_gid(struct cma_device *cma_dev, union ibv_gid *gid,
-                        uint8_t *port_num)
-{
-       int port, ret, i;
-       union ibv_gid chk_gid;
-
-       for (port = 1; port <= cma_dev->port_cnt; port++)
-               for (i = 0, ret = 0; !ret; i++) {
-                       ret = ibv_query_gid(cma_dev->verbs, port, i, &chk_gid);
-                       if (!ret && !memcmp(gid, &chk_gid, sizeof *gid)) {
-                               *port_num = port;
-                               return 0;
-                       }
-               }
-
-       return -EINVAL;
-}
-
 static int ucma_find_pkey(struct cma_device *cma_dev, uint8_t port_num,
                          uint16_t pkey, uint16_t *pkey_index)
 {
@@ -483,19 +508,15 @@ static int ucma_init_ib_qp(struct cma_id_private *id_priv, struct ibv_qp *qp)
        struct ib_addr *ibaddr;
        int ret;
 
-       qp_attr.qp_state = IBV_QPS_INIT;
-       qp_attr.qp_access_flags = IBV_ACCESS_LOCAL_WRITE;
-
        ibaddr = &id_priv->id.route.addr.addr.ibaddr;
-       ret = ucma_find_gid(id_priv->cma_dev, &ibaddr->sgid, &qp_attr.port_num);
-       if (ret)
-               return ret;
-
-       ret = ucma_find_pkey(id_priv->cma_dev, qp_attr.port_num, ibaddr->pkey,
-                            &qp_attr.pkey_index);
+       ret = ucma_find_pkey(id_priv->cma_dev, id_priv->id.port_num,
+                            ibaddr->pkey, &qp_attr.pkey_index);
        if (ret)
                return ret;
 
+       qp_attr.port_num = id_priv->id.port_num;
+       qp_attr.qp_state = IBV_QPS_INIT;
+       qp_attr.qp_access_flags = IBV_ACCESS_LOCAL_WRITE;
        return ibv_modify_qp(qp, &qp_attr, IBV_QP_STATE | IBV_QP_ACCESS_FLAGS |
                                           IBV_QP_PKEY_INDEX | IBV_QP_PORT);
 }
@@ -531,51 +552,6 @@ void rdma_destroy_qp(struct rdma_cm_id *id)
        ibv_destroy_qp(id->qp);
 }
 
-static int ucma_query_route(struct rdma_cm_id *id)
-{
-       struct ucma_abi_query_route_resp *resp;
-       struct ucma_abi_query_route *cmd;
-       struct cma_id_private *id_priv;
-       void *msg;
-       int ret, size, i;
-       
-       CMA_CREATE_MSG_CMD_RESP(msg, cmd, resp, UCMA_CMD_QUERY_ROUTE, size);
-       id_priv = container_of(id, struct cma_id_private, id);
-       cmd->id = id_priv->handle;
-
-       ret = write(cma_fd, msg, size);
-       if (ret != size)
-               return (ret > 0) ? -ENODATA : ret;
-
-       if (resp->num_paths) {
-               id->route.path_rec = malloc(sizeof *id->route.path_rec *
-                                           resp->num_paths);
-               if (!id->route.path_rec)
-                       return -ENOMEM;
-
-               id->route.num_paths = resp->num_paths;
-               for (i = 0; i < resp->num_paths; i++)
-                       ib_copy_path_rec_from_kern(&id->route.path_rec[i],
-                                                  &resp->ib_route[i]);
-       }
-
-       memcpy(id->route.addr.addr.ibaddr.sgid.raw, resp->ib_route[0].sgid,
-              sizeof id->route.addr.addr.ibaddr.sgid);
-       memcpy(id->route.addr.addr.ibaddr.dgid.raw, resp->ib_route[0].dgid,
-              sizeof id->route.addr.addr.ibaddr.dgid);
-       id->route.addr.addr.ibaddr.pkey = resp->ib_route[0].pkey;
-       memcpy(&id->route.addr.src_addr, &resp->src_addr,
-              sizeof id->route.addr.src_addr);
-
-       if (!id_priv->cma_dev) {
-               ret = ucma_get_device(id_priv, resp->node_guid);
-               if (ret)
-                       return ret;
-       }
-
-       return 0;
-}
-
 static void ucma_copy_conn_param_to_kern(struct ucma_abi_conn_param *dst,
                                         struct rdma_conn_param *src,
                                         struct ibv_qp *qp)