mfd: wm8350-i2c: Make sure the i2c regmap functions are compiled
[linux/fpc-iii.git] / drivers / infiniband / ulp / ipoib / ipoib_netlink.c
blobf81abe16cf093d6c74ad31dd179f03f7dc90b997
1 /*
2 * Copyright (c) 2012 Mellanox Technologies. - All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
33 #include <linux/netdevice.h>
34 #include <linux/module.h>
35 #include <net/rtnetlink.h>
36 #include "ipoib.h"
38 static const struct nla_policy ipoib_policy[IFLA_IPOIB_MAX + 1] = {
39 [IFLA_IPOIB_PKEY] = { .type = NLA_U16 },
40 [IFLA_IPOIB_MODE] = { .type = NLA_U16 },
41 [IFLA_IPOIB_UMCAST] = { .type = NLA_U16 },
44 static int ipoib_fill_info(struct sk_buff *skb, const struct net_device *dev)
46 struct ipoib_dev_priv *priv = netdev_priv(dev);
47 u16 val;
49 if (nla_put_u16(skb, IFLA_IPOIB_PKEY, priv->pkey))
50 goto nla_put_failure;
52 val = test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
53 if (nla_put_u16(skb, IFLA_IPOIB_MODE, val))
54 goto nla_put_failure;
56 val = test_bit(IPOIB_FLAG_UMCAST, &priv->flags);
57 if (nla_put_u16(skb, IFLA_IPOIB_UMCAST, val))
58 goto nla_put_failure;
60 return 0;
62 nla_put_failure:
63 return -EMSGSIZE;
66 static int ipoib_changelink(struct net_device *dev,
67 struct nlattr *tb[], struct nlattr *data[])
69 u16 mode, umcast;
70 int ret = 0;
72 if (data[IFLA_IPOIB_MODE]) {
73 mode = nla_get_u16(data[IFLA_IPOIB_MODE]);
74 if (mode == IPOIB_MODE_DATAGRAM)
75 ret = ipoib_set_mode(dev, "datagram\n");
76 else if (mode == IPOIB_MODE_CONNECTED)
77 ret = ipoib_set_mode(dev, "connected\n");
78 else
79 ret = -EINVAL;
81 if (ret < 0)
82 goto out_err;
85 if (data[IFLA_IPOIB_UMCAST]) {
86 umcast = nla_get_u16(data[IFLA_IPOIB_UMCAST]);
87 ipoib_set_umcast(dev, umcast);
90 out_err:
91 return ret;
94 static int ipoib_new_child_link(struct net *src_net, struct net_device *dev,
95 struct nlattr *tb[], struct nlattr *data[])
97 struct net_device *pdev;
98 struct ipoib_dev_priv *ppriv;
99 u16 child_pkey;
100 int err;
102 if (!tb[IFLA_LINK])
103 return -EINVAL;
105 pdev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK]));
106 if (!pdev)
107 return -ENODEV;
109 ppriv = netdev_priv(pdev);
111 if (test_bit(IPOIB_FLAG_SUBINTERFACE, &ppriv->flags)) {
112 ipoib_warn(ppriv, "child creation disallowed for child devices\n");
113 return -EINVAL;
116 if (!data || !data[IFLA_IPOIB_PKEY]) {
117 ipoib_dbg(ppriv, "no pkey specified, using parent pkey\n");
118 child_pkey = ppriv->pkey;
119 } else
120 child_pkey = nla_get_u16(data[IFLA_IPOIB_PKEY]);
122 if (child_pkey == 0 || child_pkey == 0x8000)
123 return -EINVAL;
126 * Set the full membership bit, so that we join the right
127 * broadcast group, etc.
129 child_pkey |= 0x8000;
131 err = __ipoib_vlan_add(ppriv, netdev_priv(dev), child_pkey, IPOIB_RTNL_CHILD);
133 if (!err && data)
134 err = ipoib_changelink(dev, tb, data);
135 return err;
138 static void ipoib_unregister_child_dev(struct net_device *dev, struct list_head *head)
140 struct ipoib_dev_priv *priv, *ppriv;
142 priv = netdev_priv(dev);
143 ppriv = netdev_priv(priv->parent);
145 mutex_lock(&ppriv->vlan_mutex);
146 unregister_netdevice_queue(dev, head);
147 list_del(&priv->list);
148 mutex_unlock(&ppriv->vlan_mutex);
151 static size_t ipoib_get_size(const struct net_device *dev)
153 return nla_total_size(2) + /* IFLA_IPOIB_PKEY */
154 nla_total_size(2) + /* IFLA_IPOIB_MODE */
155 nla_total_size(2); /* IFLA_IPOIB_UMCAST */
158 static struct rtnl_link_ops ipoib_link_ops __read_mostly = {
159 .kind = "ipoib",
160 .maxtype = IFLA_IPOIB_MAX,
161 .policy = ipoib_policy,
162 .priv_size = sizeof(struct ipoib_dev_priv),
163 .setup = ipoib_setup,
164 .newlink = ipoib_new_child_link,
165 .changelink = ipoib_changelink,
166 .dellink = ipoib_unregister_child_dev,
167 .get_size = ipoib_get_size,
168 .fill_info = ipoib_fill_info,
171 int __init ipoib_netlink_init(void)
173 return rtnl_link_register(&ipoib_link_ops);
176 void __exit ipoib_netlink_fini(void)
178 rtnl_link_unregister(&ipoib_link_ops);
181 MODULE_ALIAS_RTNL_LINK("ipoib");