]> Pileus Git - ~andy/linux/commitdiff
IB/ipoib: Add more rtnl_link_ops callbacks
authorOr Gerlitz <ogerlitz@mellanox.com>
Thu, 27 Sep 2012 12:06:02 +0000 (12:06 +0000)
committerDavid S. Miller <davem@davemloft.net>
Mon, 1 Oct 2012 21:12:22 +0000 (17:12 -0400)
Add the rtnl_link_ops changelink and fill_info callbacks, through
which the admin can now set/get the driver mode, etc policies.
Maintain the proprietary sysfs entries only for legacy childs.

For child devices, set dev->iflink to point to the parent
device ifindex, such that user space tools can now correctly
show the uplink relation as done for vlan, macvlan, etc
devices. Pointed out by Patrick McHardy <kaber@trash.net>

Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/infiniband/ulp/ipoib/ipoib.h
drivers/infiniband/ulp/ipoib/ipoib_cm.c
drivers/infiniband/ulp/ipoib/ipoib_main.c
drivers/infiniband/ulp/ipoib/ipoib_netlink.c
drivers/infiniband/ulp/ipoib/ipoib_vlan.c
include/linux/if_link.h

index ac48f86f2384164566d5ea098bdf2dd22fd058e8..196eb52f003519c15cafdf97dd0a08703e33111b 100644 (file)
@@ -523,6 +523,9 @@ int __ipoib_vlan_add(struct ipoib_dev_priv *ppriv, struct ipoib_dev_priv *priv,
 int  __init ipoib_netlink_init(void);
 void __exit ipoib_netlink_fini(void);
 
+void ipoib_set_umcast(struct net_device *ndev, int umcast_val);
+int  ipoib_set_mode(struct net_device *dev, const char *buf);
+
 void ipoib_setup(struct net_device *dev);
 
 void ipoib_pkey_poll(struct work_struct *work);
index 24683fda8e21cdbaca2973cc69454013a2bbb995..175581cf478c2188c101dbb14a264b4e35c14c1b 100644 (file)
@@ -1448,15 +1448,10 @@ static ssize_t show_mode(struct device *d, struct device_attribute *attr,
                return sprintf(buf, "datagram\n");
 }
 
-static ssize_t set_mode(struct device *d, struct device_attribute *attr,
-                       const char *buf, size_t count)
+int ipoib_set_mode(struct net_device *dev, const char *buf)
 {
-       struct net_device *dev = to_net_dev(d);
        struct ipoib_dev_priv *priv = netdev_priv(dev);
 
-       if (!rtnl_trylock())
-               return restart_syscall();
-
        /* flush paths if we switch modes so that connections are restarted */
        if (IPOIB_CM_SUPPORTED(dev->dev_addr) && !strcmp(buf, "connected\n")) {
                set_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
@@ -1467,7 +1462,8 @@ static ssize_t set_mode(struct device *d, struct device_attribute *attr,
                priv->tx_wr.send_flags &= ~IB_SEND_IP_CSUM;
 
                ipoib_flush_paths(dev);
-               return count;
+               rtnl_lock();
+               return 0;
        }
 
        if (!strcmp(buf, "datagram\n")) {
@@ -1476,14 +1472,32 @@ static ssize_t set_mode(struct device *d, struct device_attribute *attr,
                dev_set_mtu(dev, min(priv->mcast_mtu, dev->mtu));
                rtnl_unlock();
                ipoib_flush_paths(dev);
-
-               return count;
+               rtnl_lock();
+               return 0;
        }
-       rtnl_unlock();
 
        return -EINVAL;
 }
 
+static ssize_t set_mode(struct device *d, struct device_attribute *attr,
+                       const char *buf, size_t count)
+{
+       struct net_device *dev = to_net_dev(d);
+       int ret;
+
+       if (!rtnl_trylock())
+               return restart_syscall();
+
+       ret = ipoib_set_mode(dev, buf);
+
+       rtnl_unlock();
+
+       if (!ret)
+               return count;
+
+       return ret;
+}
+
 static DEVICE_ATTR(mode, S_IWUSR | S_IRUGO, show_mode, set_mode);
 
 int ipoib_cm_add_mode_attr(struct net_device *dev)
index 128fab1020547089c80be6ff6151f18cb7f74758..3f9a9ba2f9ecc3a6414c2978738e15fb703e9e06 100644 (file)
@@ -1381,12 +1381,9 @@ static ssize_t show_umcast(struct device *dev,
        return sprintf(buf, "%d\n", test_bit(IPOIB_FLAG_UMCAST, &priv->flags));
 }
 
-static ssize_t set_umcast(struct device *dev,
-                         struct device_attribute *attr,
-                         const char *buf, size_t count)
+void ipoib_set_umcast(struct net_device *ndev, int umcast_val)
 {
-       struct ipoib_dev_priv *priv = netdev_priv(to_net_dev(dev));
-       unsigned long umcast_val = simple_strtoul(buf, NULL, 0);
+       struct ipoib_dev_priv *priv = netdev_priv(ndev);
 
        if (umcast_val > 0) {
                set_bit(IPOIB_FLAG_UMCAST, &priv->flags);
@@ -1394,6 +1391,15 @@ static ssize_t set_umcast(struct device *dev,
                                "by userspace\n");
        } else
                clear_bit(IPOIB_FLAG_UMCAST, &priv->flags);
+}
+
+static ssize_t set_umcast(struct device *dev,
+                         struct device_attribute *attr,
+                         const char *buf, size_t count)
+{
+       unsigned long umcast_val = simple_strtoul(buf, NULL, 0);
+
+       ipoib_set_umcast(to_net_dev(dev), umcast_val);
 
        return count;
 }
index a7dc5ea8370ea3535158c570e8b7a53d43b3db04..74685936c9482be96c09a09e5af6f314bdc2b741 100644 (file)
 
 static const struct nla_policy ipoib_policy[IFLA_IPOIB_MAX + 1] = {
        [IFLA_IPOIB_PKEY]       = { .type = NLA_U16 },
+       [IFLA_IPOIB_MODE]       = { .type = NLA_U16 },
+       [IFLA_IPOIB_UMCAST]     = { .type = NLA_U16 },
 };
 
+static int ipoib_fill_info(struct sk_buff *skb, const struct net_device *dev)
+{
+       struct ipoib_dev_priv *priv = netdev_priv(dev);
+       u16 val;
+
+       if (nla_put_u16(skb, IFLA_IPOIB_PKEY, priv->pkey))
+               goto nla_put_failure;
+
+       val = test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
+       if (nla_put_u16(skb, IFLA_IPOIB_MODE, val))
+               goto nla_put_failure;
+
+       val = test_bit(IPOIB_FLAG_UMCAST, &priv->flags);
+       if (nla_put_u16(skb, IFLA_IPOIB_UMCAST, val))
+               goto nla_put_failure;
+
+       return 0;
+
+nla_put_failure:
+       return -EMSGSIZE;
+}
+
+static int ipoib_changelink(struct net_device *dev,
+                           struct nlattr *tb[], struct nlattr *data[])
+{
+       u16 mode, umcast;
+       int ret = 0;
+
+       if (data[IFLA_IPOIB_MODE]) {
+               mode  = nla_get_u16(data[IFLA_IPOIB_MODE]);
+               if (mode == IPOIB_MODE_DATAGRAM)
+                       ret = ipoib_set_mode(dev, "datagram\n");
+               else if (mode == IPOIB_MODE_CONNECTED)
+                       ret = ipoib_set_mode(dev, "connected\n");
+               else
+                       ret = -EINVAL;
+
+               if (ret < 0)
+                       goto out_err;
+       }
+
+       if (data[IFLA_IPOIB_UMCAST]) {
+               umcast = nla_get_u16(data[IFLA_IPOIB_UMCAST]);
+               ipoib_set_umcast(dev, umcast);
+       }
+
+out_err:
+       return ret;
+}
+
 static int ipoib_new_child_link(struct net *src_net, struct net_device *dev,
                               struct nlattr *tb[], struct nlattr *data[])
 {
@@ -69,6 +121,8 @@ static int ipoib_new_child_link(struct net *src_net, struct net_device *dev,
 
        err = __ipoib_vlan_add(ppriv, netdev_priv(dev), child_pkey, IPOIB_RTNL_CHILD);
 
+       if (!err && data)
+               err = ipoib_changelink(dev, tb, data);
        return err;
 }
 
@@ -87,7 +141,9 @@ static void ipoib_unregister_child_dev(struct net_device *dev, struct list_head
 
 static size_t ipoib_get_size(const struct net_device *dev)
 {
-       return nla_total_size(2);       /* IFLA_IPOIB_PKEY */
+       return nla_total_size(2) +      /* IFLA_IPOIB_PKEY   */
+               nla_total_size(2) +     /* IFLA_IPOIB_MODE   */
+               nla_total_size(2);      /* IFLA_IPOIB_UMCAST */
 }
 
 static struct rtnl_link_ops ipoib_link_ops __read_mostly = {
@@ -97,8 +153,10 @@ static struct rtnl_link_ops ipoib_link_ops __read_mostly = {
        .priv_size      = sizeof(struct ipoib_dev_priv),
        .setup          = ipoib_setup,
        .newlink        = ipoib_new_child_link,
+       .changelink     = ipoib_changelink,
        .dellink        = ipoib_unregister_child_dev,
        .get_size       = ipoib_get_size,
+       .fill_info      = ipoib_fill_info,
 };
 
 int __init ipoib_netlink_init(void)
index 238bbf9b2bea8bba67fdcefc42245037df6da23c..8292554bccb5de2387d7e858eaaa1d27ddb6b8b4 100644 (file)
@@ -88,17 +88,21 @@ int __ipoib_vlan_add(struct ipoib_dev_priv *ppriv, struct ipoib_dev_priv *priv,
 
        ipoib_create_debug_files(priv->dev);
 
-       if (ipoib_cm_add_mode_attr(priv->dev))
-               goto sysfs_failed;
-       if (ipoib_add_pkey_attr(priv->dev))
-               goto sysfs_failed;
-       if (ipoib_add_umcast_attr(priv->dev))
-               goto sysfs_failed;
-
-       if (device_create_file(&priv->dev->dev, &dev_attr_parent))
-               goto sysfs_failed;
+       /* RTNL childs don't need proprietary sysfs entries */
+       if (type == IPOIB_LEGACY_CHILD) {
+               if (ipoib_cm_add_mode_attr(priv->dev))
+                       goto sysfs_failed;
+               if (ipoib_add_pkey_attr(priv->dev))
+                       goto sysfs_failed;
+               if (ipoib_add_umcast_attr(priv->dev))
+                       goto sysfs_failed;
+
+               if (device_create_file(&priv->dev->dev, &dev_attr_parent))
+                       goto sysfs_failed;
+       }
 
-       priv->child_type = type;
+       priv->child_type  = type;
+       priv->dev->iflink = ppriv->dev->ifindex;
        list_add_tail(&priv->list, &ppriv->child_intfs);
 
        return 0;
index 24c0dd09af54d3b529f5b0e93742344f28a66a0b..4491177e984d124a841deb1bffabfc72ad809ce6 100644 (file)
@@ -404,9 +404,16 @@ struct ifla_port_vsi {
 enum {
        IFLA_IPOIB_UNSPEC,
        IFLA_IPOIB_PKEY,
+       IFLA_IPOIB_MODE,
+       IFLA_IPOIB_UMCAST,
        __IFLA_IPOIB_MAX
 };
 
+enum {
+       IPOIB_MODE_DATAGRAM  = 0, /* using unreliable datagram QPs */
+       IPOIB_MODE_CONNECTED = 1, /* using connected QPs */
+};
+
 #define IFLA_IPOIB_MAX (__IFLA_IPOIB_MAX - 1)
 
 #endif /* _LINUX_IF_LINK_H */