Commit 862096a8 authored by Or Gerlitz's avatar Or Gerlitz Committed by David S. Miller

IB/ipoib: Add more rtnl_link_ops callbacks

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: default avatarOr Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d7559982
...@@ -523,6 +523,9 @@ int __ipoib_vlan_add(struct ipoib_dev_priv *ppriv, struct ipoib_dev_priv *priv, ...@@ -523,6 +523,9 @@ int __ipoib_vlan_add(struct ipoib_dev_priv *ppriv, struct ipoib_dev_priv *priv,
int __init ipoib_netlink_init(void); int __init ipoib_netlink_init(void);
void __exit ipoib_netlink_fini(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_setup(struct net_device *dev);
void ipoib_pkey_poll(struct work_struct *work); void ipoib_pkey_poll(struct work_struct *work);
......
...@@ -1448,15 +1448,10 @@ static ssize_t show_mode(struct device *d, struct device_attribute *attr, ...@@ -1448,15 +1448,10 @@ static ssize_t show_mode(struct device *d, struct device_attribute *attr,
return sprintf(buf, "datagram\n"); return sprintf(buf, "datagram\n");
} }
static ssize_t set_mode(struct device *d, struct device_attribute *attr, int ipoib_set_mode(struct net_device *dev, const char *buf)
const char *buf, size_t count)
{ {
struct net_device *dev = to_net_dev(d);
struct ipoib_dev_priv *priv = netdev_priv(dev); 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 */ /* flush paths if we switch modes so that connections are restarted */
if (IPOIB_CM_SUPPORTED(dev->dev_addr) && !strcmp(buf, "connected\n")) { if (IPOIB_CM_SUPPORTED(dev->dev_addr) && !strcmp(buf, "connected\n")) {
set_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags); set_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
...@@ -1467,7 +1462,8 @@ static ssize_t set_mode(struct device *d, struct device_attribute *attr, ...@@ -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; priv->tx_wr.send_flags &= ~IB_SEND_IP_CSUM;
ipoib_flush_paths(dev); ipoib_flush_paths(dev);
return count; rtnl_lock();
return 0;
} }
if (!strcmp(buf, "datagram\n")) { if (!strcmp(buf, "datagram\n")) {
...@@ -1476,14 +1472,32 @@ static ssize_t set_mode(struct device *d, struct device_attribute *attr, ...@@ -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)); dev_set_mtu(dev, min(priv->mcast_mtu, dev->mtu));
rtnl_unlock(); rtnl_unlock();
ipoib_flush_paths(dev); ipoib_flush_paths(dev);
rtnl_lock();
return count; return 0;
} }
rtnl_unlock();
return -EINVAL; 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); static DEVICE_ATTR(mode, S_IWUSR | S_IRUGO, show_mode, set_mode);
int ipoib_cm_add_mode_attr(struct net_device *dev) int ipoib_cm_add_mode_attr(struct net_device *dev)
......
...@@ -1381,12 +1381,9 @@ static ssize_t show_umcast(struct device *dev, ...@@ -1381,12 +1381,9 @@ static ssize_t show_umcast(struct device *dev,
return sprintf(buf, "%d\n", test_bit(IPOIB_FLAG_UMCAST, &priv->flags)); return sprintf(buf, "%d\n", test_bit(IPOIB_FLAG_UMCAST, &priv->flags));
} }
static ssize_t set_umcast(struct device *dev, void ipoib_set_umcast(struct net_device *ndev, int umcast_val)
struct device_attribute *attr,
const char *buf, size_t count)
{ {
struct ipoib_dev_priv *priv = netdev_priv(to_net_dev(dev)); struct ipoib_dev_priv *priv = netdev_priv(ndev);
unsigned long umcast_val = simple_strtoul(buf, NULL, 0);
if (umcast_val > 0) { if (umcast_val > 0) {
set_bit(IPOIB_FLAG_UMCAST, &priv->flags); set_bit(IPOIB_FLAG_UMCAST, &priv->flags);
...@@ -1394,6 +1391,15 @@ static ssize_t set_umcast(struct device *dev, ...@@ -1394,6 +1391,15 @@ static ssize_t set_umcast(struct device *dev,
"by userspace\n"); "by userspace\n");
} else } else
clear_bit(IPOIB_FLAG_UMCAST, &priv->flags); 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; return count;
} }
......
...@@ -37,8 +37,60 @@ ...@@ -37,8 +37,60 @@
static const struct nla_policy ipoib_policy[IFLA_IPOIB_MAX + 1] = { static const struct nla_policy ipoib_policy[IFLA_IPOIB_MAX + 1] = {
[IFLA_IPOIB_PKEY] = { .type = NLA_U16 }, [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, static int ipoib_new_child_link(struct net *src_net, struct net_device *dev,
struct nlattr *tb[], struct nlattr *data[]) struct nlattr *tb[], struct nlattr *data[])
{ {
...@@ -69,6 +121,8 @@ static int ipoib_new_child_link(struct net *src_net, struct net_device *dev, ...@@ -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); err = __ipoib_vlan_add(ppriv, netdev_priv(dev), child_pkey, IPOIB_RTNL_CHILD);
if (!err && data)
err = ipoib_changelink(dev, tb, data);
return err; return err;
} }
...@@ -87,7 +141,9 @@ static void ipoib_unregister_child_dev(struct net_device *dev, struct list_head ...@@ -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) 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 = { static struct rtnl_link_ops ipoib_link_ops __read_mostly = {
...@@ -97,8 +153,10 @@ 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), .priv_size = sizeof(struct ipoib_dev_priv),
.setup = ipoib_setup, .setup = ipoib_setup,
.newlink = ipoib_new_child_link, .newlink = ipoib_new_child_link,
.changelink = ipoib_changelink,
.dellink = ipoib_unregister_child_dev, .dellink = ipoib_unregister_child_dev,
.get_size = ipoib_get_size, .get_size = ipoib_get_size,
.fill_info = ipoib_fill_info,
}; };
int __init ipoib_netlink_init(void) int __init ipoib_netlink_init(void)
......
...@@ -88,17 +88,21 @@ int __ipoib_vlan_add(struct ipoib_dev_priv *ppriv, struct ipoib_dev_priv *priv, ...@@ -88,17 +88,21 @@ int __ipoib_vlan_add(struct ipoib_dev_priv *ppriv, struct ipoib_dev_priv *priv,
ipoib_create_debug_files(priv->dev); ipoib_create_debug_files(priv->dev);
if (ipoib_cm_add_mode_attr(priv->dev)) /* RTNL childs don't need proprietary sysfs entries */
goto sysfs_failed; if (type == IPOIB_LEGACY_CHILD) {
if (ipoib_add_pkey_attr(priv->dev)) if (ipoib_cm_add_mode_attr(priv->dev))
goto sysfs_failed; goto sysfs_failed;
if (ipoib_add_umcast_attr(priv->dev)) if (ipoib_add_pkey_attr(priv->dev))
goto sysfs_failed; goto sysfs_failed;
if (ipoib_add_umcast_attr(priv->dev))
if (device_create_file(&priv->dev->dev, &dev_attr_parent)) goto sysfs_failed;
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); list_add_tail(&priv->list, &ppriv->child_intfs);
return 0; return 0;
......
...@@ -404,9 +404,16 @@ struct ifla_port_vsi { ...@@ -404,9 +404,16 @@ struct ifla_port_vsi {
enum { enum {
IFLA_IPOIB_UNSPEC, IFLA_IPOIB_UNSPEC,
IFLA_IPOIB_PKEY, IFLA_IPOIB_PKEY,
IFLA_IPOIB_MODE,
IFLA_IPOIB_UMCAST,
__IFLA_IPOIB_MAX __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) #define IFLA_IPOIB_MAX (__IFLA_IPOIB_MAX - 1)
#endif /* _LINUX_IF_LINK_H */ #endif /* _LINUX_IF_LINK_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment