From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 275B35592 for ; Tue, 4 Jul 2017 18:14:08 +0200 (CEST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jul 2017 09:14:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,309,1496127600"; d="scan'208";a="122666419" 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:05 -0700 From: Ferruh Yigit To: dev@dpdk.org Cc: Ferruh Yigit , Stephen Hemminger , Bruce Richardson , Anatoly Burakov Date: Tue, 4 Jul 2017 17:13:27 +0100 Message-Id: <20170704161337.45926-11-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 10/20] unci: init netlink 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 Initialize netlink socket. Userspace application will connect to the socket for data transfer. Signed-off-by: Ferruh Yigit --- .../linuxapp/eal/include/exec-env/unci.h | 33 ++++++++++ lib/librte_eal/linuxapp/unci/Makefile | 1 + lib/librte_eal/linuxapp/unci/unci_dev.h | 3 + lib/librte_eal/linuxapp/unci/unci_net.c | 7 +++ lib/librte_eal/linuxapp/unci/unci_nl.c | 72 ++++++++++++++++++++++ 5 files changed, 116 insertions(+) create mode 100644 lib/librte_eal/linuxapp/unci/unci_nl.c diff --git a/lib/librte_eal/linuxapp/eal/include/exec-env/unci.h b/lib/librte_eal/linuxapp/eal/include/exec-env/unci.h index 8d4a95777..6d3490aee 100644 --- a/lib/librte_eal/linuxapp/eal/include/exec-env/unci.h +++ b/lib/librte_eal/linuxapp/eal/include/exec-env/unci.h @@ -60,6 +60,20 @@ #define UNCI_DEVICE "unci" +#define UNCI_GENL_MSG_LEN 1536 + +#define UNCI_NL_MSG_LEN 500 +struct unci_nl_msg { + __u32 cmd_id; + __u32 port_id; + __u32 flag; + __u8 input_buffer[UNCI_NL_MSG_LEN]; + __u8 output_buffer[UNCI_NL_MSG_LEN]; + size_t input_buffer_len; + size_t output_buffer_len; + int err; +}; + /* can go into include/uapi/linux/if_link.h */ enum { IFLA_UNCI_UNSPEC, @@ -70,4 +84,23 @@ enum { #define IFLA_UNCI_MAX (__IFLA_UNCI_MAX - 1) + +#define UNCI_GENL_VERSION 1 + +enum { + UNCI_ATTR_UNSPEC, + UNCI_ATTR_MSG, + __UNCI_ATTR_MAX, +}; + +#define UNCI_ATTR_MAX (__UNCI_ATTR_MAX - 1) + +enum { + UNCI_CMD_UNSPEC, + UNCI_CMD_MSG, + __UNCI_CMD_MAX, +}; + +#define UNCI_CMD_MAX (__UNCI_CMD_MAX - 1) + #endif /* _UAPI_LINUX_UNCI_H_ */ diff --git a/lib/librte_eal/linuxapp/unci/Makefile b/lib/librte_eal/linuxapp/unci/Makefile index 02e354814..c2a81be7d 100644 --- a/lib/librte_eal/linuxapp/unci/Makefile +++ b/lib/librte_eal/linuxapp/unci/Makefile @@ -48,5 +48,6 @@ MODULE_CFLAGS += -Wall -Werror # all source are stored in SRCS-y # SRCS-$(CONFIG_RTE_UNCI_KMOD) := unci_net.c +SRCS-$(CONFIG_RTE_UNCI_KMOD) += unci_nl.c include $(RTE_SDK)/mk/rte.module.mk diff --git a/lib/librte_eal/linuxapp/unci/unci_dev.h b/lib/librte_eal/linuxapp/unci/unci_dev.h index 92b9b8383..a748abf98 100644 --- a/lib/librte_eal/linuxapp/unci/unci_dev.h +++ b/lib/librte_eal/linuxapp/unci/unci_dev.h @@ -39,4 +39,7 @@ struct unci_dev { __u32 pid; }; +int unci_nl_init(void); +void unci_nl_release(void); + #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 42fac3e63..1989b6d23 100644 --- a/lib/librte_eal/linuxapp/unci/unci_net.c +++ b/lib/librte_eal/linuxapp/unci/unci_net.c @@ -74,6 +74,12 @@ static struct rtnl_link_ops unci_link_ops __read_mostly = { static int __init unci_init(void) { + int ret; + + ret = unci_nl_init(); + if (ret) + return ret; + return rtnl_link_register(&unci_link_ops); } module_init(unci_init); @@ -81,6 +87,7 @@ module_init(unci_init); static void __exit unci_exit(void) { rtnl_link_unregister(&unci_link_ops); + unci_nl_release(); } module_exit(unci_exit); diff --git a/lib/librte_eal/linuxapp/unci/unci_nl.c b/lib/librte_eal/linuxapp/unci/unci_nl.c new file mode 100644 index 000000000..1461a3309 --- /dev/null +++ b/lib/librte_eal/linuxapp/unci/unci_nl.c @@ -0,0 +1,72 @@ +/*- + * GPL LICENSE SUMMARY + * + * 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 of the GNU 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + */ + +#include +#include + +#include "unci_dev.h" + +static int unci_genl_process(struct sk_buff *skb, struct genl_info *info) +{ + struct nlattr **attrs = info->attrs; + struct unci_nl_msg nl_msg; + + if (!attrs[UNCI_ATTR_MSG]) + return -EINVAL; + + nla_memcpy(&nl_msg, attrs[UNCI_ATTR_MSG], sizeof(struct unci_nl_msg)); + pr_debug("cmd: %u\n", nl_msg.cmd_id); + + return 0; +} + +static struct nla_policy unci_genl_policy[UNCI_ATTR_MAX + 1] = { + [UNCI_ATTR_MSG] = { .type = NLA_BINARY, .len = UNCI_GENL_MSG_LEN }, +}; + +static const struct genl_ops unci_ops[] = { + { + .cmd = UNCI_CMD_MSG, + .doit = unci_genl_process, + .policy = unci_genl_policy, + }, +}; + +static struct genl_family unci_genl_family __ro_after_init = { + .module = THIS_MODULE, + .name = UNCI_DEVICE, + .version = UNCI_GENL_VERSION, + .maxattr = UNCI_ATTR_MAX, + .ops = unci_ops, + .n_ops = ARRAY_SIZE(unci_ops), +}; + +int unci_nl_init(void) +{ + return genl_register_family(&unci_genl_family); +} + +void unci_nl_release(void) +{ + genl_unregister_family(&unci_genl_family); +} -- 2.13.0