From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <fyigit@ecsmtp.ir.intel.com>
Received: from mga11.intel.com (mga11.intel.com [192.55.52.93])
 by dpdk.org (Postfix) with ESMTP id 726DA9AF3
 for <dev@dpdk.org>; Tue,  1 Mar 2016 16:42:53 +0100 (CET)
Received: from fmsmga001.fm.intel.com ([10.253.24.23])
 by fmsmga102.fm.intel.com with ESMTP; 01 Mar 2016 07:42:53 -0800
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.22,523,1449561600"; d="scan'208";a="914477425"
Received: from irvmail001.ir.intel.com ([163.33.26.43])
 by fmsmga001.fm.intel.com with ESMTP; 01 Mar 2016 07:42:51 -0800
Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com
 [10.237.217.46])
 by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id
 u21FgnTR024684; Tue, 1 Mar 2016 15:42:49 GMT
Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1])
 by sivswdev02.ir.intel.com with ESMTP id u21FgoX4028839;
 Tue, 1 Mar 2016 15:42:50 GMT
Received: (from fyigit@localhost)
 by sivswdev02.ir.intel.com with  id u21Fgo44028835;
 Tue, 1 Mar 2016 15:42:50 GMT
From: Ferruh Yigit <ferruh.yigit@intel.com>
To: dev@dpdk.org
Date: Tue,  1 Mar 2016 15:42:00 +0000
Message-Id: <1456846920-28770-5-git-send-email-ferruh.yigit@intel.com>
X-Mailer: git-send-email 1.7.4.1
In-Reply-To: <1456846920-28770-1-git-send-email-ferruh.yigit@intel.com>
References: <1456495841-15749-1-git-send-email-ferruh.yigit@intel.com>
 <1456846920-28770-1-git-send-email-ferruh.yigit@intel.com>
Subject: [dpdk-dev] [PATCH v4 4/4] examples/ethtool: add control interface
	support to the application
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Tue, 01 Mar 2016 15:42:54 -0000

Control interface APIs added into the sample application.

To have the support corresponding kernel module (KCP) needs to be inserted.
If kernel module is not there, application will run as it is without
kernel control path support.

When KCP module inserted, running application creates a virtual Linux
network interface (dpdk$) per DPDK port. This interface can be used by
traditional Linux tools.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Remy Horton <remy.horton@intel.com>
---

v4:
* No update

v3:
* Use blocking mode control interface processing, instead of poll mode

v2:
* No update on sample app
---
 doc/guides/sample_app_ug/ethtool.rst | 41 ++++++++++++++++++++++++++++++++++++
 examples/ethtool/main.c              | 31 +++++++++++++++++++++++++--
 2 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/doc/guides/sample_app_ug/ethtool.rst b/doc/guides/sample_app_ug/ethtool.rst
index 65240ae..af591c2 100644
--- a/doc/guides/sample_app_ug/ethtool.rst
+++ b/doc/guides/sample_app_ug/ethtool.rst
@@ -130,3 +130,44 @@ interface that accepts commands as described in `using the
 application`_. Individual call-back functions handle the detail
 associated with each command, which make use of librte_ethtool
 library.
+
+Control Interface
+~~~~~~~~~~~~~~~~~
+
+If Kernel Control Path (KCP) kernel module (rte_kcp.ko) inserted,
+virtual interfaces created for each DPDK port for control purposes.
+
+Created interfaces are named as dpdk#, like:
+
+.. code-block:: console
+
+        # ifconfig dpdk0; ifconfig dpdk1
+        dpdk0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
+                ether 90:e2:ba:0e:49:b9  txqueuelen 1000  (Ethernet)
+                RX packets 0  bytes 0 (0.0 B)
+                RX errors 0  dropped 0  overruns 0  frame 0
+                TX packets 0  bytes 0 (0.0 B)
+                TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
+
+        dpdk1: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
+                ether 00:1b:21:76:fa:21  txqueuelen 1000  (Ethernet)
+                RX packets 0  bytes 0 (0.0 B)
+                RX errors 0  dropped 0  overruns 0  frame 0
+                TX packets 0  bytes 0 (0.0 B)
+                TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
+
+Regular Linux commands can be issued on interfaces:
+
+.. code-block:: console
+
+        # ethtool -i dpdk0
+        driver: rte_ixgbe_pmd
+        version: RTE 2.3.0-rc0
+        firmware-version:
+        expansion-rom-version:
+        bus-info: 0000:08:00.1
+        supports-statistics: yes
+        supports-test: no
+        supports-eeprom-access: yes
+        supports-register-dump: yes
+        supports-priv-flags: no
diff --git a/examples/ethtool/main.c b/examples/ethtool/main.c
index 2c655d8..72fbe4c 100644
--- a/examples/ethtool/main.c
+++ b/examples/ethtool/main.c
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2015 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2015-2016 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -44,6 +44,7 @@
 #include <rte_memory.h>
 #include <rte_mempool.h>
 #include <rte_mbuf.h>
+#include <rte_ctrl_if.h>
 
 #include "ethapp.h"
 
@@ -54,7 +55,6 @@
 #define PKTPOOL_EXTRA_SIZE 512
 #define PKTPOOL_CACHE 32
 
-
 struct txq_port {
 	uint16_t cnt_unsent;
 	struct rte_mbuf *buf_frames[MAX_BURST_LENGTH];
@@ -259,11 +259,32 @@ static int slave_main(__attribute__((unused)) void *ptr_data)
 	return 0;
 }
 
+static void *
+control_function(__attribute__((unused)) void *arg)
+{
+	int port_id;
+
+	while (1) {
+		/* blocking call with 1 sec timeout */
+		port_id = rte_eth_control_interface_msg_exist(1);
+		if (port_id < 0)
+			continue;
+
+		lock_port(port_id);
+		rte_eth_control_interface_msg_process(
+			RTE_ETHTOOL_CTRL_IF_PROCESS_MSG);
+		unlock_port(port_id);
+	}
+
+	return 0;
+}
+
 int main(int argc, char **argv)
 {
 	int cnt_args_parsed;
 	uint32_t id_core;
 	uint32_t cnt_ports;
+	pthread_t control_thread;
 
 	/* Init runtime enviornment */
 	cnt_args_parsed = rte_eal_init(argc, argv);
@@ -293,6 +314,9 @@ int main(int argc, char **argv)
 	id_core = rte_get_next_lcore(id_core, 1, 1);
 	rte_eal_remote_launch(slave_main, NULL, id_core);
 
+	pthread_create(&control_thread, NULL, control_function, NULL);
+	rte_eth_control_interface_create();
+
 	ethapp_main();
 
 	app_cfg.exit_now = 1;
@@ -301,5 +325,8 @@ int main(int argc, char **argv)
 			return -1;
 	}
 
+	rte_eth_control_interface_destroy();
+	pthread_cancel(control_thread);
+
 	return 0;
 }
-- 
2.5.0