From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id DDD4D6841 for ; Tue, 4 Jul 2017 18:14:08 +0200 (CEST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jul 2017 09:14:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,309,1496127600"; d="scan'208";a="122666403" Received: from silpixa00372839.ir.intel.com (HELO silpixa00372839.ger.corp.intel.com) ([10.237.222.154]) by fmsmga006.fm.intel.com with ESMTP; 04 Jul 2017 09:14:03 -0700 From: Ferruh Yigit To: dev@dpdk.org Cc: Ferruh Yigit , Stephen Hemminger , Bruce Richardson , Anatoly Burakov Date: Tue, 4 Jul 2017 17:13:26 +0100 Message-Id: <20170704161337.45926-10-ferruh.yigit@intel.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170704161337.45926-1-ferruh.yigit@intel.com> References: <20170630165140.59594-1-ferruh.yigit@intel.com> <20170704161337.45926-1-ferruh.yigit@intel.com> Subject: [dpdk-dev] [PATCH v10 09/20] unci: add rtnl newlink X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Jul 2017 16:14:09 -0000 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 --- lib/librte_eal/linuxapp/eal/Makefile | 1 + .../linuxapp/eal/include/exec-env/unci.h | 73 ++++++++++++++++++++++ lib/librte_eal/linuxapp/unci/unci_dev.h | 8 +++ lib/librte_eal/linuxapp/unci/unci_net.c | 50 ++++++++++++++- 4 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 lib/librte_eal/linuxapp/eal/include/exec-env/unci.h diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile index 8651e2783..139e56033 100644 --- a/lib/librte_eal/linuxapp/eal/Makefile +++ b/lib/librte_eal/linuxapp/eal/Makefile @@ -130,6 +130,7 @@ CFLAGS_eal_thread.o += -Wno-return-type endif INC := rte_interrupts.h rte_kni_common.h rte_dom0_common.h +INC += unci.h SYMLINK-$(CONFIG_RTE_EXEC_ENV_LINUXAPP)-include/exec-env := \ $(addprefix include/exec-env/,$(INC)) diff --git a/lib/librte_eal/linuxapp/eal/include/exec-env/unci.h b/lib/librte_eal/linuxapp/eal/include/exec-env/unci.h new file mode 100644 index 000000000..8d4a95777 --- /dev/null +++ b/lib/librte_eal/linuxapp/eal/include/exec-env/unci.h @@ -0,0 +1,73 @@ +/*- + * 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 _UAPI_LINUX_UNCI_H_ +#define _UAPI_LINUX_UNCI_H_ + +#define UNCI_DEVICE "unci" + +/* can go into include/uapi/linux/if_link.h */ +enum { + IFLA_UNCI_UNSPEC, + IFLA_UNCI_PORTID, + IFLA_UNCI_PID, + __IFLA_UNCI_MAX, +}; + +#define IFLA_UNCI_MAX (__IFLA_UNCI_MAX - 1) + +#endif /* _UAPI_LINUX_UNCI_H_ */ diff --git a/lib/librte_eal/linuxapp/unci/unci_dev.h b/lib/librte_eal/linuxapp/unci/unci_dev.h index 102409020..92b9b8383 100644 --- a/lib/librte_eal/linuxapp/unci/unci_dev.h +++ b/lib/librte_eal/linuxapp/unci/unci_dev.h @@ -25,10 +25,18 @@ #ifndef _UNCI_DEV_H_ #define _UNCI_DEV_H_ +#include + +#include + #ifdef pr_fmt #undef pr_fmt #endif #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +struct unci_dev { + __u32 port_id; + __u32 pid; +}; #endif /* _UNCI_DEV_H_ */ diff --git a/lib/librte_eal/linuxapp/unci/unci_net.c b/lib/librte_eal/linuxapp/unci/unci_net.c index b8ef409d3..42fac3e63 100644 --- a/lib/librte_eal/linuxapp/unci/unci_net.c +++ b/lib/librte_eal/linuxapp/unci/unci_net.c @@ -23,20 +23,68 @@ */ #include +#include #include "unci_dev.h" -static int __init unci_init(void) +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); + + unci->port_id = nla_get_u32(data[IFLA_UNCI_PORTID]); + unci->pid = nla_get_u32(data[IFLA_UNCI_PID]); + + return register_netdevice(dev); +} + +static const struct nla_policy unci_policy[IFLA_UNCI_MAX + 1] = { + [IFLA_UNCI_PORTID] = { .type = NLA_U32 }, + [IFLA_UNCI_PID] = { .type = NLA_U32 }, +}; + +static int unci_validate(struct nlattr *tb[], struct nlattr *data[]) { + if (!data) + return -EINVAL; + + if (!data[IFLA_UNCI_PID] || !data[IFLA_UNCI_PORTID]) + return -EINVAL; + return 0; } + +static struct rtnl_link_ops unci_link_ops __read_mostly = { + .kind = UNCI_DEVICE, + .priv_size = sizeof(struct unci_dev), + .maxtype = IFLA_UNCI_MAX, + .setup = unci_net_setup, + .newlink = unci_net_newlink, + .policy = unci_policy, + .validate = unci_validate, +}; + +static int __init unci_init(void) +{ + 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); MODULE_LICENSE("Dual BSD/GPL"); MODULE_AUTHOR("Intel Corporation"); MODULE_DESCRIPTION("Kernel Module for managing unci devices"); +MODULE_ALIAS_RTNL_LINK(UNCI_DEVICE); -- 2.13.0