diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index 0751697..0c5028a 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -36,6 +36,7 @@
 #include <linux/random.h>
 #include <linux/idr.h>
 #include <linux/inetdevice.h>
+#include <linux/if_arp.h>
#include <net/tcp.h> @@ -200,6 +201,43 @@ struct sdp_hah {
 #define CMA_VERSION 0x00
 #define SDP_MAJ_VERSION 0x2
+struct ib_device *ipaddr_to_ibdev(u32 addr)
+{
+       struct rdma_dev_addr dev_addr;
+       struct cma_device *cma_dev;
+       struct net_device *dev;
+       union ib_gid gid;
+
+       dev = ip_dev_find(addr);
+       if (!dev)
+               goto out;
+
+       rdma_copy_addr(&dev_addr, dev, NULL);
+
+       switch (dev->type) {
+       case ARPHRD_INFINIBAND:
+               ib_addr_get_sgid(&dev_addr, &gid);
+               break;
+       case ARPHRD_ETHER:
+               iw_addr_get_sgid(&dev_addr, &gid);
+               break;
+       default:
+               goto out;
+       }
+
+       list_for_each_entry(cma_dev, &dev_list, list) {
+               int ret;
+               u8 port;
+
+               ret = ib_find_cached_gid(cma_dev->device, &gid, &port, NULL);
+               if (!ret)
+                       return cma_dev->device;
+       }
+out:
+       return NULL;
+}
+EXPORT_SYMBOL(ipaddr_to_ibdev);
+
 static int cma_comp(struct rdma_id_private *id_priv, enum cma_state comp)
 {
        unsigned long flags;

Pending our discussion on whether this service will even survive, there is a bug in it. Function ip_dev_find() keeps a reference on the netdev. So before returning, this function should do a dev_put(dev) to release the reference...


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

To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general

Reply via email to