IPoIB: Add API to retrieve ib device, port, and pkey

(I'm also attaching my patch to at.c which uses this; If this is
accepted, I will make up a patch for SDP as well.)

Signed-off-by: Hal Rosenstock <[EMAIL PROTECTED]>

Index: ipoib.h
===================================================================
--- ipoib.h     (revision 3683)
+++ ipoib.h     (working copy)
@@ -210,6 +210,12 @@ struct ipoib_neigh {
        struct list_head    list;
 };
 
+struct ipoib_info {
+       struct ib_device *dev;
+       int               port;
+       u16               pkey;
+};
+
 static inline struct ipoib_neigh **to_ipoib_neigh(struct neighbour *neigh)
 {
        return (struct ipoib_neigh **) (neigh->ha + 24 -
@@ -239,6 +245,8 @@ void ipoib_reap_ah(void *dev_ptr);
 void ipoib_flush_paths(struct net_device *dev);
 struct ipoib_dev_priv *ipoib_intf_alloc(const char *format);
 
+int ipoib_get_info(struct net_device *dev, struct ipoib_info *info);
+
 int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port);
 void ipoib_ib_dev_flush(void *dev);
 void ipoib_ib_dev_cleanup(struct net_device *dev);
Index: ipoib_ib.c
===================================================================
--- ipoib_ib.c  (revision 3683)
+++ ipoib_ib.c  (working copy)
@@ -38,6 +38,8 @@
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
 
+#include <linux/if_arp.h>      /* For ARPHRD_xxx */
+
 #include <rdma/ib_cache.h>
 
 #include "ipoib.h"
@@ -569,6 +571,29 @@ int ipoib_ib_dev_init(struct net_device 
        return 0;
 }
 
+int ipoib_get_info(struct net_device *dev, struct ipoib_info *info)
+{
+       struct ipoib_dev_priv *priv;
+
+       if (!info)
+               return -EINVAL;
+
+       /* Make sure IPoIB interface */
+       if (dev->type != ARPHRD_INFINIBAND)
+               return -ENODEV;
+
+       priv = netdev_priv(dev);
+       /* PKey assigned yet ? */
+       if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags))
+               return -ENOENT;
+
+       info->dev = priv->ca;
+       info->port = priv->port;
+       info->pkey = priv->pkey;        
+       return 0;
+}
+EXPORT_SYMBOL(ipoib_get_info);
+
 void ipoib_ib_dev_flush(void *_dev)
 {
        struct net_device *dev = (struct net_device *)_dev;
Index: at.c
===================================================================
--- at.c        (revision 3683)
+++ at.c        (working copy)
@@ -416,10 +416,10 @@ static void ib_at_ats_reg(void *data)
 static int resolve_ip(struct ib_at_src *src, u32 dst_ip, u32 src_ip,
                        int tos, union ib_gid *dgid)
 {
-       struct ipoib_dev_priv *priv;
        struct net_device *loopback = NULL;
        struct net_device *ipoib_dev;
        struct rtable *rt;
+       struct ipoib_info info;
        struct flowi fl = {
                .oif = 0,       /* oif */
                .nl_u = {
@@ -504,14 +504,16 @@ static int resolve_ip(struct ib_at_src *
        }
 
        /*
-        * lookup local info.
+        * Obtain ib_device, port, and PKey based on IPoIB net_device
         */
-       priv = ipoib_dev->priv;
-
        src->netdev = ipoib_dev;
-       src->dev = priv->ca;
-       src->port = priv->port;
-       src->pkey = cpu_to_be16(priv->pkey);
+       if ((r = ipoib_get_info(ipoib_dev, &info))) {
+               DEBUG("ipoib_get_pkey failed %d", r);
+               goto done;
+       }
+       src->dev = info.dev;
+       src->port = info.port;
+       src->pkey = cpu_to_be16(info.pkey);
        memcpy(&src->gid, ipoib_dev->dev_addr + 4, sizeof src->gid);
 
        if (!dgid) {




_______________________________________________
openib-general mailing list
[email protected]
http://openib.org/mailman/listinfo/openib-general

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

Reply via email to