[dpdk-dev,v9,09/20] unci: add rtnl newlink
Checks
Commit Message
Use rtnl to create a new interface. Interface is not setup yet.
Pid and port_id should be provided by userspace application that does
the call for interface creation.
Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
lib/librte_eal/linuxapp/eal/Makefile | 1 +
.../eal/include/exec-env/rte_unci_common.h | 72 ++++++++++++++++++++++
lib/librte_eal/linuxapp/unci/unci_dev.h | 5 ++
lib/librte_eal/linuxapp/unci/unci_net.c | 38 +++++++++++-
4 files changed, 115 insertions(+), 1 deletion(-)
create mode 100644 lib/librte_eal/linuxapp/eal/include/exec-env/rte_unci_common.h
Comments
On Fri, 30 Jun 2017 17:51:29 +0100
Ferruh Yigit <ferruh.yigit@intel.com> wrote:
> +
> +#ifndef _RTE_UNCI_COMMON_H_
> +#define _RTE_UNCI_COMMON_H_
> +
> +#define UNCI_DEVICE "unci"
> +
> +enum {
> + IFLA_UNCI_UNSPEC,
> + IFLA_UNCI_PORTID,
> + IFLA_UNCI_PID,
> + __IFLA_UNCI_MAX,
> +};
> +
> +#define IFLA_UNCI_MAX (__IFLA_UNCI_MAX - 1)
> +
> +#endif /* _RTE_UNCI_COMMON_H_ */
> diff --git a/lib/librte_eal/linuxapp/unci/unci_dev.h b/lib/librte_eal/linuxapp/unci/unci_dev.h
> index 0337fa82b..b0a215f1b 100644
> --- a/lib/librte_eal/linuxapp/unci/unci_dev.h
> +++ b/lib/librte_eal/linuxapp/unci/unci_dev.h
> @@ -26,11 +26,16 @@
> #define _UNCI_DEV_H_
>
> #include <linux/netdevice.h>
> +#include <exec-env/rte_unci_common.h>
>
> #ifdef pr_fmt
> #undef pr_fmt
> #endif
> #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>
> +struct unci_dev {
> + u8 port_id;
> + u32 pid;
> +};
These are to/from user space so should be __u8, __u32.
Also, probably want to support more than 256 ports at some time in future.
So make them both __u32.
>
> #endif /* _UNCI_DEV_H_ */
Since you want to target this for upstream kernel. Please try and layout
the includes in an easy manner to do this and avoid using rte_ in names.
@@ -127,6 +127,7 @@ CFLAGS_eal_thread.o += -Wno-return-type
endif
INC := rte_interrupts.h rte_kni_common.h rte_dom0_common.h
+INC += rte_unci_common.h
SYMLINK-$(CONFIG_RTE_EXEC_ENV_LINUXAPP)-include/exec-env := \
$(addprefix include/exec-env/,$(INC))
new file mode 100644
@@ -0,0 +1,72 @@
+/*-
+ * This file is provided under a dual BSD/LGPLv2 license. When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GNU LESSER GENERAL PUBLIC LICENSE
+ *
+ * Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2.1 of the GNU Lesser General Public License
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program;
+ *
+ * Contact Information:
+ * Intel Corporation
+ *
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2017 Intel Corporation. All rights reserved.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef _RTE_UNCI_COMMON_H_
+#define _RTE_UNCI_COMMON_H_
+
+#define UNCI_DEVICE "unci"
+
+enum {
+ IFLA_UNCI_UNSPEC,
+ IFLA_UNCI_PORTID,
+ IFLA_UNCI_PID,
+ __IFLA_UNCI_MAX,
+};
+
+#define IFLA_UNCI_MAX (__IFLA_UNCI_MAX - 1)
+
+#endif /* _RTE_UNCI_COMMON_H_ */
@@ -26,11 +26,16 @@
#define _UNCI_DEV_H_
#include <linux/netdevice.h>
+#include <exec-env/rte_unci_common.h>
#ifdef pr_fmt
#undef pr_fmt
#endif
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+struct unci_dev {
+ u8 port_id;
+ u32 pid;
+};
#endif /* _UNCI_DEV_H_ */
@@ -23,17 +23,53 @@
*/
#include <linux/module.h>
+#include <net/rtnetlink.h>
#include "unci_dev.h"
+static const struct net_device_ops unci_net_netdev_ops = { 0 };
+
+static void unci_net_setup(struct net_device *dev)
+{
+ ether_setup(dev);
+ dev->netdev_ops = &unci_net_netdev_ops;
+}
+
+static int unci_net_newlink(struct net *net, struct net_device *dev,
+ struct nlattr *tb[], struct nlattr *data[])
+{
+ struct unci_dev *unci = netdev_priv(dev);
+
+ if (data && data[IFLA_UNCI_PORTID])
+ unci->port_id = nla_get_u8(data[IFLA_UNCI_PORTID]);
+ else
+ unci->port_id = 0;
+
+ if (data && data[IFLA_UNCI_PID])
+ unci->pid = nla_get_u32(data[IFLA_UNCI_PID]);
+ else
+ unci->pid = 0;
+
+ return register_netdevice(dev);
+}
+
+static struct rtnl_link_ops unci_link_ops __read_mostly = {
+ .kind = UNCI_DEVICE,
+ .priv_size = sizeof(struct unci_dev),
+ .setup = unci_net_setup,
+ .maxtype = IFLA_UNCI_MAX,
+ .newlink = unci_net_newlink,
+};
+
static int __init unci_init(void)
{
- return 0;
+ return rtnl_link_register(&unci_link_ops);
}
module_init(unci_init);
static void __exit unci_exit(void)
{
+ rtnl_link_unregister(&unci_link_ops);
}
module_exit(unci_exit);