DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ferruh Yigit <ferruh.yigit@intel.com>
To: dev@dpdk.org
Cc: Ferruh Yigit <ferruh.yigit@intel.com>,
	Stephen Hemminger <stephen@networkplumber.org>,
	Bruce Richardson <bruce.richardson@intel.com>,
	Anatoly Burakov <anatoly.burakov@intel.com>
Subject: [dpdk-dev] [PATCH v9 12/20] unci: add netdevice ops
Date: Fri, 30 Jun 2017 17:51:32 +0100	[thread overview]
Message-ID: <20170630165140.59594-13-ferruh.yigit@intel.com> (raw)
In-Reply-To: <20170630165140.59594-1-ferruh.yigit@intel.com>

Add ndos for virtual interface. Almost all ndos use netlink exec
to pass command to userspace and read response.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 .../eal/include/exec-env/rte_unci_common.h         |  17 +++
 lib/librte_eal/linuxapp/unci/unci_net.c            | 132 ++++++++++++++++++++-
 2 files changed, 148 insertions(+), 1 deletion(-)

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
index 474f62606..3daa8a6ec 100644
--- 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
@@ -89,4 +89,21 @@ enum {
 
 #define IFLA_UNCI_MAX (__IFLA_UNCI_MAX - 1)
 
+/*
+ * Request id.
+ */
+enum unci_req_id {
+	UNCI_REQ_UNKNOWN = (1 << 16),
+	UNCI_REQ_CHANGE_MTU,
+	UNCI_REQ_CFG_NETWORK_IF,
+	UNCI_REQ_GET_STATS,
+	UNCI_REQ_GET_MAC,
+	UNCI_REQ_SET_MAC,
+	UNCI_REQ_START_PORT,
+	UNCI_REQ_STOP_PORT,
+	UNCI_REQ_SET_PROMISC,
+	UNCI_REQ_SET_ALLMULTI,
+	UNCI_REQ_MAX,
+};
+
 #endif /* _RTE_UNCI_COMMON_H_ */
diff --git a/lib/librte_eal/linuxapp/unci/unci_net.c b/lib/librte_eal/linuxapp/unci/unci_net.c
index 72099e596..2ce337a48 100644
--- a/lib/librte_eal/linuxapp/unci/unci_net.c
+++ b/lib/librte_eal/linuxapp/unci/unci_net.c
@@ -22,12 +22,142 @@
  *   Intel Corporation
  */
 
+#include <linux/version.h>
 #include <linux/module.h>
+#include <linux/etherdevice.h>
 #include <net/rtnetlink.h>
 
 #include "unci_dev.h"
 
-static const struct net_device_ops unci_net_netdev_ops = { 0 };
+static int unci_net_init(struct net_device *dev)
+{
+	u8 mac[ETH_ALEN] = {0};
+
+	unci_nl_exec(UNCI_REQ_GET_MAC, dev, NULL, 0, mac, ETH_ALEN);
+	memcpy(dev->dev_addr, mac, dev->addr_len);
+	return 0;
+}
+
+static int unci_net_open(struct net_device *dev)
+{
+	/* DPDK port already started, stop it first */
+	unci_nl_exec(UNCI_REQ_STOP_PORT, dev, NULL, 0, NULL, 0);
+	unci_nl_exec(UNCI_REQ_START_PORT, dev, NULL, 0, NULL, 0);
+	netif_start_queue(dev);
+	return 0;
+}
+
+static int unci_net_close(struct net_device *dev)
+{
+	unci_nl_exec(UNCI_REQ_STOP_PORT, dev, NULL, 0, NULL, 0);
+	netif_stop_queue(dev);
+	return 0;
+}
+
+static int unci_net_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+	dev_kfree_skb(skb);
+	return NETDEV_TX_OK;
+}
+
+static void unci_net_change_rx_flags(struct net_device *dev, int flags)
+{
+	u32 on = 1;
+	u32 off = 0;
+
+	if (flags & IFF_PROMISC)
+		unci_nl_exec(UNCI_REQ_SET_PROMISC, dev,
+				dev->flags & IFF_PROMISC ?  &on : &off,
+				sizeof(u32), NULL, 0);
+
+	if (flags & IFF_ALLMULTI)
+		unci_nl_exec(UNCI_REQ_SET_ALLMULTI, dev,
+				dev->flags & IFF_ALLMULTI ?  &on : &off,
+				sizeof(u32), NULL, 0);
+}
+
+static int unci_net_set_mac(struct net_device *dev, void *p)
+{
+	struct sockaddr *addr = p;
+	int err;
+
+	if (!is_valid_ether_addr(addr->sa_data))
+		return -EADDRNOTAVAIL;
+
+	err = unci_nl_exec(UNCI_REQ_SET_MAC, dev, addr->sa_data,
+			dev->addr_len, NULL, 0);
+	if (err < 0)
+		return -EADDRNOTAVAIL;
+
+	memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
+
+	return 0;
+}
+
+static int unci_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
+{
+	return -EOPNOTSUPP;
+}
+
+/*
+ * Configuration changes (passed on by ifconfig)
+ */
+static int unci_net_config(struct net_device *dev, struct ifmap *map)
+{
+	if (dev->flags & IFF_UP)
+		return -EBUSY;
+
+	return -EOPNOTSUPP;
+}
+
+static int unci_net_change_mtu(struct net_device *dev, int new_mtu)
+{
+	int err = 0;
+
+	err = unci_nl_exec(UNCI_REQ_CHANGE_MTU, dev, &new_mtu, sizeof(int),
+			NULL, 0);
+
+	if (err == 0)
+		dev->mtu = new_mtu;
+
+	return err;
+}
+
+static void unci_net_stats64(struct net_device *dev,
+		struct rtnl_link_stats64 *stats)
+{
+	int err;
+
+	err = unci_nl_exec(UNCI_REQ_GET_STATS, dev, NULL, 0,
+			stats, sizeof(struct rtnl_link_stats64));
+}
+
+#if (KERNEL_VERSION(3, 9, 0) <= LINUX_VERSION_CODE)
+static int unci_net_change_carrier(struct net_device *dev, bool new_carrier)
+{
+	if (new_carrier)
+		netif_carrier_on(dev);
+	else
+		netif_carrier_off(dev);
+	return 0;
+}
+#endif
+
+static const struct net_device_ops unci_net_netdev_ops = {
+	.ndo_init = unci_net_init,
+	.ndo_open = unci_net_open,
+	.ndo_stop = unci_net_close,
+	.ndo_start_xmit = unci_net_xmit,
+	.ndo_change_rx_flags = unci_net_change_rx_flags,
+	.ndo_set_mac_address = unci_net_set_mac,
+	.ndo_do_ioctl = unci_net_ioctl,
+	.ndo_set_config = unci_net_config,
+	.ndo_change_mtu = unci_net_change_mtu,
+	.ndo_get_stats64 = unci_net_stats64,
+#if (KERNEL_VERSION(3, 9, 0) <= LINUX_VERSION_CODE)
+	.ndo_change_carrier = unci_net_change_carrier,
+#endif
+};
 
 static void unci_net_setup(struct net_device *dev)
 {
-- 
2.13.0

  parent reply	other threads:[~2017-06-30 16:52 UTC|newest]

Thread overview: 91+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-26 16:52 [dpdk-dev] [RFC] Kernel Control Path (KCP) Ferruh Yigit
2017-05-28 16:55 ` Wiles, Keith
2017-05-29  9:26   ` Bruce Richardson
2017-05-29 17:29     ` Wiles, Keith
2017-06-16 15:54   ` Ferruh Yigit
2017-06-20 12:33     ` Ferruh Yigit
2017-05-30 10:55 ` Thomas Monjalon
2017-06-13 17:21   ` Ferruh Yigit
2017-06-13 18:00     ` Jay Rolette
2017-06-13 18:04       ` Dumitrescu, Cristian
2017-06-13 18:18         ` Wiles, Keith
2017-06-15 12:07           ` Alex Rosenbaum
2017-06-16 15:27             ` Ferruh Yigit
2017-06-16 16:48               ` Stephen Hemminger
2017-06-13 18:17       ` Wiles, Keith
2017-06-21 11:06 ` [dpdk-dev] [PATCH v8 0/4] Userspace Network Control Interface (UNCI) Ferruh Yigit
2017-06-21 11:06   ` [dpdk-dev] [PATCH v8 1/4] ethtool: move from sample folder to lib folder Ferruh Yigit
2017-06-26 11:02     ` Bruce Richardson
2017-06-21 11:06   ` [dpdk-dev] [PATCH v8 2/4] unci: add kernel control path kernel module Ferruh Yigit
2017-06-21 15:23     ` Stephen Hemminger
2017-06-30 17:02       ` Ferruh Yigit
2017-06-21 11:06   ` [dpdk-dev] [PATCH v8 3/4] rte_ctrl_if: add control interface library Ferruh Yigit
2017-06-26 11:09     ` Bruce Richardson
2017-06-26 11:30     ` Bruce Richardson
2017-06-21 11:06   ` [dpdk-dev] [PATCH v8 4/4] ethdev: add control interface support Ferruh Yigit
2017-06-21 15:24     ` Stephen Hemminger
2017-06-30 17:06       ` Ferruh Yigit
2017-06-26 11:39   ` [dpdk-dev] [PATCH v8 0/4] Userspace Network Control Interface (UNCI) Bruce Richardson
2017-06-29 16:13     ` Ferruh Yigit
2017-06-30 16:56       ` Ferruh Yigit
2017-06-30 16:51   ` [dpdk-dev] [PATCH v9 00/20] " Ferruh Yigit
2017-06-30 16:51     ` [dpdk-dev] [PATCH v9 01/20] ethtool: add library skeleton Ferruh Yigit
2017-06-30 16:51     ` [dpdk-dev] [PATCH v9 02/20] ethtool: move from sample folder into lib folder Ferruh Yigit
2017-06-30 16:51     ` [dpdk-dev] [PATCH v9 03/20] ethtool: remove PMD specific API call Ferruh Yigit
2017-06-30 16:51     ` [dpdk-dev] [PATCH v9 04/20] ethtool: update header doxygen syntax Ferruh Yigit
2017-06-30 16:51     ` [dpdk-dev] [PATCH v9 05/20] ethtool: enable library Ferruh Yigit
2017-06-30 16:51     ` [dpdk-dev] [PATCH v9 06/20] doc: add ethtool library documentation Ferruh Yigit
2017-07-02 20:18       ` Mcnamara, John
2017-06-30 16:51     ` [dpdk-dev] [PATCH v9 07/20] doc: update ethtool sample app doc Ferruh Yigit
2017-07-02 20:17       ` Mcnamara, John
2017-06-30 16:51     ` [dpdk-dev] [PATCH v9 08/20] unci: add module skeleton Ferruh Yigit
2017-06-30 16:51     ` [dpdk-dev] [PATCH v9 09/20] unci: add rtnl newlink Ferruh Yigit
2017-06-30 17:27       ` Stephen Hemminger
2017-06-30 16:51     ` [dpdk-dev] [PATCH v9 10/20] unci: init netlink Ferruh Yigit
2017-06-30 17:28       ` Stephen Hemminger
2017-06-30 17:29       ` Stephen Hemminger
2017-06-30 16:51     ` [dpdk-dev] [PATCH v9 11/20] unci: add netlink exec Ferruh Yigit
2017-06-30 16:51     ` Ferruh Yigit [this message]
2017-06-30 16:51     ` [dpdk-dev] [PATCH v9 13/20] unci: add ethtool support Ferruh Yigit
2017-06-30 16:51     ` [dpdk-dev] [PATCH v9 14/20] ctrl_if: add library skeleton Ferruh Yigit
2017-06-30 16:51     ` [dpdk-dev] [PATCH v9 15/20] ctrl_if: add create destroy interface APIs Ferruh Yigit
2017-06-30 16:51     ` [dpdk-dev] [PATCH v9 16/20] ctrl_if: initialize netlink interface Ferruh Yigit
2017-06-30 16:51     ` [dpdk-dev] [PATCH v9 17/20] ctrl_if: process control messages Ferruh Yigit
2017-06-30 16:51     ` [dpdk-dev] [PATCH v9 18/20] ctrl_if: process ethtool messages Ferruh Yigit
2017-06-30 16:51     ` [dpdk-dev] [PATCH v9 19/20] doc: add control interface library documentation Ferruh Yigit
2017-07-02 20:16       ` Mcnamara, John
2017-06-30 16:51     ` [dpdk-dev] [PATCH v9 20/20] ethdev: add control interface support Ferruh Yigit
2017-07-04 16:13     ` [dpdk-dev] [PATCH v10 00/20] Userspace Network Control Interface (UNCI) Ferruh Yigit
2017-07-04 16:13       ` [dpdk-dev] [PATCH v10 01/20] ethtool: add library skeleton Ferruh Yigit
2017-07-04 16:13       ` [dpdk-dev] [PATCH v10 02/20] ethtool: move from sample folder into lib folder Ferruh Yigit
2017-07-04 16:13       ` [dpdk-dev] [PATCH v10 03/20] ethtool: remove PMD specific API call Ferruh Yigit
2017-07-04 16:13       ` [dpdk-dev] [PATCH v10 04/20] ethtool: update header doxygen syntax Ferruh Yigit
2017-07-06  9:18         ` Burakov, Anatoly
2017-07-04 16:13       ` [dpdk-dev] [PATCH v10 05/20] ethtool: enable library Ferruh Yigit
2017-07-04 16:13       ` [dpdk-dev] [PATCH v10 06/20] doc: add ethtool library documentation Ferruh Yigit
2017-07-04 16:13       ` [dpdk-dev] [PATCH v10 07/20] doc: update ethtool sample app doc Ferruh Yigit
2017-07-04 16:13       ` [dpdk-dev] [PATCH v10 08/20] unci: add module skeleton Ferruh Yigit
2017-07-06  9:25         ` Burakov, Anatoly
2017-07-04 16:13       ` [dpdk-dev] [PATCH v10 09/20] unci: add rtnl newlink Ferruh Yigit
2017-07-04 16:13       ` [dpdk-dev] [PATCH v10 10/20] unci: init netlink Ferruh Yigit
2017-07-06  9:32         ` Burakov, Anatoly
2017-07-04 16:13       ` [dpdk-dev] [PATCH v10 11/20] unci: add netlink exec Ferruh Yigit
2017-07-05 19:07         ` Stephen Hemminger
2017-07-06 10:45           ` Ferruh Yigit
2017-07-07  0:25             ` Stephen Hemminger
2017-07-05 19:15         ` Stephen Hemminger
2017-07-04 16:13       ` [dpdk-dev] [PATCH v10 12/20] unci: add netdevice ops Ferruh Yigit
2017-07-05 19:12         ` Stephen Hemminger
2017-07-05 19:12         ` Stephen Hemminger
2017-07-04 16:13       ` [dpdk-dev] [PATCH v10 13/20] unci: add ethtool support Ferruh Yigit
2017-07-05 19:07         ` Stephen Hemminger
2017-07-05 19:08         ` Stephen Hemminger
2017-07-04 16:13       ` [dpdk-dev] [PATCH v10 14/20] ctrl_if: add library skeleton Ferruh Yigit
2017-07-04 16:13       ` [dpdk-dev] [PATCH v10 15/20] ctrl_if: add create destroy interface APIs Ferruh Yigit
2017-07-04 16:13       ` [dpdk-dev] [PATCH v10 16/20] ctrl_if: initialize generic netlink interface Ferruh Yigit
2017-07-04 16:13       ` [dpdk-dev] [PATCH v10 17/20] ctrl_if: process control messages Ferruh Yigit
2017-07-04 16:13       ` [dpdk-dev] [PATCH v10 18/20] ctrl_if: process ethtool messages Ferruh Yigit
2017-07-04 16:13       ` [dpdk-dev] [PATCH v10 19/20] doc: add control interface library documentation Ferruh Yigit
2017-07-04 16:13       ` [dpdk-dev] [PATCH v10 20/20] ethdev: add control interface support Ferruh Yigit
2017-07-08  6:28         ` Yuanhan Liu
2017-07-20 14:55           ` Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170630165140.59594-13-ferruh.yigit@intel.com \
    --to=ferruh.yigit@intel.com \
    --cc=anatoly.burakov@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).