Linux Audio

Check our new training course

Yocto distribution development and maintenance

Need a Yocto distribution for your embedded project?
Loading...
v6.8
  1/*
  2 * Copyright (c) 2012 Mellanox Technologies. -  All rights reserved.
  3 *
  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:
  9 *
 10 *     Redistribution and use in source and binary forms, with or
 11 *     without modification, are permitted provided that the following
 12 *     conditions are met:
 13 *
 14 *      - Redistributions of source code must retain the above
 15 *        copyright notice, this list of conditions and the following
 16 *        disclaimer.
 17 *
 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.
 22 *
 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.
 31 */
 32
 33#include <linux/netdevice.h>
 34#include <linux/if_arp.h>      /* For ARPHRD_xxx */
 
 35#include <net/rtnetlink.h>
 36#include "ipoib.h"
 37
 38static 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 },
 42};
 43
 44static unsigned int ipoib_get_max_num_queues(void)
 45{
 46	return min_t(unsigned int, num_possible_cpus(), 128);
 47}
 48
 49static int ipoib_fill_info(struct sk_buff *skb, const struct net_device *dev)
 50{
 51	struct ipoib_dev_priv *priv = ipoib_priv(dev);
 52	u16 val;
 53
 54	if (nla_put_u16(skb, IFLA_IPOIB_PKEY, priv->pkey))
 55		goto nla_put_failure;
 56
 57	val = test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
 58	if (nla_put_u16(skb, IFLA_IPOIB_MODE, val))
 59		goto nla_put_failure;
 60
 61	val = test_bit(IPOIB_FLAG_UMCAST, &priv->flags);
 62	if (nla_put_u16(skb, IFLA_IPOIB_UMCAST, val))
 63		goto nla_put_failure;
 64
 65	return 0;
 66
 67nla_put_failure:
 68	return -EMSGSIZE;
 69}
 70
 71static int ipoib_changelink(struct net_device *dev, struct nlattr *tb[],
 72			    struct nlattr *data[],
 73			    struct netlink_ext_ack *extack)
 74{
 75	u16 mode, umcast;
 76	int ret = 0;
 77
 78	if (data[IFLA_IPOIB_MODE]) {
 79		mode  = nla_get_u16(data[IFLA_IPOIB_MODE]);
 80		if (mode == IPOIB_MODE_DATAGRAM)
 81			ret = ipoib_set_mode(dev, "datagram\n");
 82		else if (mode == IPOIB_MODE_CONNECTED)
 83			ret = ipoib_set_mode(dev, "connected\n");
 84		else
 85			ret = -EINVAL;
 86
 87		if (ret < 0)
 88			goto out_err;
 89	}
 90
 91	if (data[IFLA_IPOIB_UMCAST]) {
 92		umcast = nla_get_u16(data[IFLA_IPOIB_UMCAST]);
 93		ipoib_set_umcast(dev, umcast);
 94	}
 95
 96out_err:
 97	return ret;
 98}
 99
100static int ipoib_new_child_link(struct net *src_net, struct net_device *dev,
101				struct nlattr *tb[], struct nlattr *data[],
102				struct netlink_ext_ack *extack)
103{
104	struct net_device *pdev;
105	struct ipoib_dev_priv *ppriv;
106	u16 child_pkey;
107	int err;
108
109	if (!tb[IFLA_LINK])
110		return -EINVAL;
111
112	pdev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK]));
113	if (!pdev || pdev->type != ARPHRD_INFINIBAND)
114		return -ENODEV;
115
116	ppriv = ipoib_priv(pdev);
117
118	if (test_bit(IPOIB_FLAG_SUBINTERFACE, &ppriv->flags)) {
119		ipoib_warn(ppriv, "child creation disallowed for child devices\n");
120		return -EINVAL;
121	}
122
123	if (!data || !data[IFLA_IPOIB_PKEY]) {
124		ipoib_dbg(ppriv, "no pkey specified, using parent pkey\n");
125		child_pkey  = ppriv->pkey;
126	} else
127		child_pkey  = nla_get_u16(data[IFLA_IPOIB_PKEY]);
128
129	err = ipoib_intf_init(ppriv->ca, ppriv->port, dev->name, dev);
130	if (err) {
131		ipoib_warn(ppriv, "failed to initialize pkey device\n");
132		return err;
133	}
134
135	err = __ipoib_vlan_add(ppriv, ipoib_priv(dev),
136			       child_pkey, IPOIB_RTNL_CHILD);
137	if (err)
138		return err;
139
140	if (data) {
141		err = ipoib_changelink(dev, tb, data, extack);
142		if (err) {
143			unregister_netdevice(dev);
144			return err;
145		}
146	}
147
148	return 0;
149}
150
151static void ipoib_del_child_link(struct net_device *dev, struct list_head *head)
152{
153	struct ipoib_dev_priv *priv = ipoib_priv(dev);
154
155	if (!priv->parent)
156		return;
157
158	unregister_netdevice_queue(dev, head);
159}
160
161static size_t ipoib_get_size(const struct net_device *dev)
162{
163	return nla_total_size(2) +	/* IFLA_IPOIB_PKEY   */
164		nla_total_size(2) +	/* IFLA_IPOIB_MODE   */
165		nla_total_size(2);	/* IFLA_IPOIB_UMCAST */
166}
167
168static struct rtnl_link_ops ipoib_link_ops __read_mostly = {
169	.kind		= "ipoib",
170	.netns_refund   = true,
171	.maxtype	= IFLA_IPOIB_MAX,
172	.policy		= ipoib_policy,
173	.priv_size	= sizeof(struct ipoib_dev_priv),
174	.setup		= ipoib_setup_common,
175	.newlink	= ipoib_new_child_link,
176	.dellink	= ipoib_del_child_link,
177	.changelink	= ipoib_changelink,
178	.get_size	= ipoib_get_size,
179	.fill_info	= ipoib_fill_info,
180	.get_num_rx_queues = ipoib_get_max_num_queues,
181	.get_num_tx_queues = ipoib_get_max_num_queues,
182};
183
184struct rtnl_link_ops *ipoib_get_link_ops(void)
185{
186	return &ipoib_link_ops;
187}
188
189int __init ipoib_netlink_init(void)
190{
191	return rtnl_link_register(&ipoib_link_ops);
192}
193
194void __exit ipoib_netlink_fini(void)
195{
196	rtnl_link_unregister(&ipoib_link_ops);
197}
198
199MODULE_ALIAS_RTNL_LINK("ipoib");
v5.4
  1/*
  2 * Copyright (c) 2012 Mellanox Technologies. -  All rights reserved.
  3 *
  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:
  9 *
 10 *     Redistribution and use in source and binary forms, with or
 11 *     without modification, are permitted provided that the following
 12 *     conditions are met:
 13 *
 14 *      - Redistributions of source code must retain the above
 15 *        copyright notice, this list of conditions and the following
 16 *        disclaimer.
 17 *
 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.
 22 *
 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.
 31 */
 32
 33#include <linux/netdevice.h>
 34#include <linux/if_arp.h>      /* For ARPHRD_xxx */
 35#include <linux/module.h>
 36#include <net/rtnetlink.h>
 37#include "ipoib.h"
 38
 39static const struct nla_policy ipoib_policy[IFLA_IPOIB_MAX + 1] = {
 40	[IFLA_IPOIB_PKEY]	= { .type = NLA_U16 },
 41	[IFLA_IPOIB_MODE]	= { .type = NLA_U16 },
 42	[IFLA_IPOIB_UMCAST]	= { .type = NLA_U16 },
 43};
 44
 
 
 
 
 
 45static int ipoib_fill_info(struct sk_buff *skb, const struct net_device *dev)
 46{
 47	struct ipoib_dev_priv *priv = ipoib_priv(dev);
 48	u16 val;
 49
 50	if (nla_put_u16(skb, IFLA_IPOIB_PKEY, priv->pkey))
 51		goto nla_put_failure;
 52
 53	val = test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
 54	if (nla_put_u16(skb, IFLA_IPOIB_MODE, val))
 55		goto nla_put_failure;
 56
 57	val = test_bit(IPOIB_FLAG_UMCAST, &priv->flags);
 58	if (nla_put_u16(skb, IFLA_IPOIB_UMCAST, val))
 59		goto nla_put_failure;
 60
 61	return 0;
 62
 63nla_put_failure:
 64	return -EMSGSIZE;
 65}
 66
 67static int ipoib_changelink(struct net_device *dev, struct nlattr *tb[],
 68			    struct nlattr *data[],
 69			    struct netlink_ext_ack *extack)
 70{
 71	u16 mode, umcast;
 72	int ret = 0;
 73
 74	if (data[IFLA_IPOIB_MODE]) {
 75		mode  = nla_get_u16(data[IFLA_IPOIB_MODE]);
 76		if (mode == IPOIB_MODE_DATAGRAM)
 77			ret = ipoib_set_mode(dev, "datagram\n");
 78		else if (mode == IPOIB_MODE_CONNECTED)
 79			ret = ipoib_set_mode(dev, "connected\n");
 80		else
 81			ret = -EINVAL;
 82
 83		if (ret < 0)
 84			goto out_err;
 85	}
 86
 87	if (data[IFLA_IPOIB_UMCAST]) {
 88		umcast = nla_get_u16(data[IFLA_IPOIB_UMCAST]);
 89		ipoib_set_umcast(dev, umcast);
 90	}
 91
 92out_err:
 93	return ret;
 94}
 95
 96static int ipoib_new_child_link(struct net *src_net, struct net_device *dev,
 97				struct nlattr *tb[], struct nlattr *data[],
 98				struct netlink_ext_ack *extack)
 99{
100	struct net_device *pdev;
101	struct ipoib_dev_priv *ppriv;
102	u16 child_pkey;
103	int err;
104
105	if (!tb[IFLA_LINK])
106		return -EINVAL;
107
108	pdev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK]));
109	if (!pdev || pdev->type != ARPHRD_INFINIBAND)
110		return -ENODEV;
111
112	ppriv = ipoib_priv(pdev);
113
114	if (test_bit(IPOIB_FLAG_SUBINTERFACE, &ppriv->flags)) {
115		ipoib_warn(ppriv, "child creation disallowed for child devices\n");
116		return -EINVAL;
117	}
118
119	if (!data || !data[IFLA_IPOIB_PKEY]) {
120		ipoib_dbg(ppriv, "no pkey specified, using parent pkey\n");
121		child_pkey  = ppriv->pkey;
122	} else
123		child_pkey  = nla_get_u16(data[IFLA_IPOIB_PKEY]);
124
125	err = ipoib_intf_init(ppriv->ca, ppriv->port, dev->name, dev);
126	if (err) {
127		ipoib_warn(ppriv, "failed to initialize pkey device\n");
128		return err;
129	}
130
131	err = __ipoib_vlan_add(ppriv, ipoib_priv(dev),
132			       child_pkey, IPOIB_RTNL_CHILD);
133	if (err)
134		return err;
135
136	if (data) {
137		err = ipoib_changelink(dev, tb, data, extack);
138		if (err) {
139			unregister_netdevice(dev);
140			return err;
141		}
142	}
143
144	return 0;
145}
146
 
 
 
 
 
 
 
 
 
 
147static size_t ipoib_get_size(const struct net_device *dev)
148{
149	return nla_total_size(2) +	/* IFLA_IPOIB_PKEY   */
150		nla_total_size(2) +	/* IFLA_IPOIB_MODE   */
151		nla_total_size(2);	/* IFLA_IPOIB_UMCAST */
152}
153
154static struct rtnl_link_ops ipoib_link_ops __read_mostly = {
155	.kind		= "ipoib",
 
156	.maxtype	= IFLA_IPOIB_MAX,
157	.policy		= ipoib_policy,
158	.priv_size	= sizeof(struct ipoib_dev_priv),
159	.setup		= ipoib_setup_common,
160	.newlink	= ipoib_new_child_link,
 
161	.changelink	= ipoib_changelink,
162	.get_size	= ipoib_get_size,
163	.fill_info	= ipoib_fill_info,
 
 
164};
165
166struct rtnl_link_ops *ipoib_get_link_ops(void)
167{
168	return &ipoib_link_ops;
169}
170
171int __init ipoib_netlink_init(void)
172{
173	return rtnl_link_register(&ipoib_link_ops);
174}
175
176void __exit ipoib_netlink_fini(void)
177{
178	rtnl_link_unregister(&ipoib_link_ops);
179}
180
181MODULE_ALIAS_RTNL_LINK("ipoib");