From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 31E615699 for ; Fri, 30 Jun 2017 18:52:04 +0200 (CEST) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Jun 2017 09:51:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,287,1496127600"; d="scan'208";a="103233221" Received: from silpixa00372839.ir.intel.com (HELO silpixa00372839.ger.corp.intel.com) ([10.237.222.154]) by orsmga004.jf.intel.com with ESMTP; 30 Jun 2017 09:51:56 -0700 From: Ferruh Yigit To: dev@dpdk.org Cc: Ferruh Yigit , Stephen Hemminger , Bruce Richardson , Anatoly Burakov Date: Fri, 30 Jun 2017 17:51:29 +0100 Message-Id: <20170630165140.59594-10-ferruh.yigit@intel.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170630165140.59594-1-ferruh.yigit@intel.com> References: <20170621110651.75299-1-ferruh.yigit@intel.com> <20170630165140.59594-1-ferruh.yigit@intel.com> Subject: [dpdk-dev] [PATCH v9 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: Fri, 30 Jun 2017 16:52:05 -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 + .../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 diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile index 640afd088..401160bc9 100644 --- a/lib/librte_eal/linuxapp/eal/Makefile +++ b/lib/librte_eal/linuxapp/eal/Makefile @@ -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)) diff --git a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_unci_common.h b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_unci_common.h new file mode 100644 index 000000000..d90423a07 --- /dev/null +++ b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_unci_common.h @@ -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_ */ 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 +#include #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_ */ diff --git a/lib/librte_eal/linuxapp/unci/unci_net.c b/lib/librte_eal/linuxapp/unci/unci_net.c index b8ef409d3..ee23b0e4d 100644 --- a/lib/librte_eal/linuxapp/unci/unci_net.c +++ b/lib/librte_eal/linuxapp/unci/unci_net.c @@ -23,17 +23,53 @@ */ #include +#include #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); -- 2.13.0