From: Dan Gora <dg@adax.com>
To: dev@dpdk.org
Cc: Igor Ryzhov <iryzhov@nfware.com>,
Stephen Hemminger <stephen@networkplumber.org>,
Ferruh Yigit <ferruh.yigit@intel.com>, Dan Gora <dg@adax.com>
Subject: [dpdk-dev] [PATCH 1/2] kni: add API to set link status on kernel interface
Date: Tue, 11 Sep 2018 20:14:17 -0300 [thread overview]
Message-ID: <20180911231417.17222-1-dg@adax.com> (raw)
In-Reply-To: <20180629015508.26599-11-dg@adax.com>
Add a new API function to KNI, rte_kni_update_link() to allow DPDK
applications to update the link status for KNI network interfaces in
the linux kernel.
Signed-off-by: Dan Gora <dg@adax.com>
---
lib/librte_kni/rte_kni.c | 57 ++++++++++++++++++++++++++++++++++++++++
lib/librte_kni/rte_kni.h | 18 +++++++++++++
2 files changed, 75 insertions(+)
diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c
index 65f6a2b03..afe1d7410 100644
--- a/lib/librte_kni/rte_kni.c
+++ b/lib/librte_kni/rte_kni.c
@@ -790,6 +790,63 @@ rte_kni_unregister_handlers(struct rte_kni *kni)
return 0;
}
+
+int
+rte_kni_update_link(struct rte_kni *kni, struct rte_eth_link *link)
+{
+ char path[64];
+ char carrier[2];
+ const char *new_carrier;
+ int fd, ret;
+
+ if (kni == NULL || link == NULL)
+ return -1;
+
+ snprintf(path, sizeof(path), "/sys/devices/virtual/net/%s/carrier",
+ kni->name);
+
+ fd = open(path, O_RDWR);
+ if (fd == -1) {
+ RTE_LOG(ERR, KNI, "Failed to open file: %s.\n", path);
+ return -1;
+ }
+
+ ret = read(fd, carrier, 2);
+ if (ret < 1) {
+ /* Cannot read carrier until interface is marked
+ * 'up', so don't log an error.
+ */
+ close(fd);
+ return -1;
+ }
+
+ new_carrier = (link->link_status == ETH_LINK_UP) ? "1" : "0";
+ ret = write(fd, new_carrier, 1);
+ if (ret < 1) {
+ RTE_LOG(ERR, KNI, "Failed to write file: %s.\n", path);
+ close(fd);
+ return -1;
+ }
+
+ if (strncmp(carrier, new_carrier, 1)) {
+ if (link->link_status == ETH_LINK_UP) {
+ RTE_LOG(INFO, KNI, "%s NIC Link is Up %d Mbps %s %s.\n",
+ kni->name,
+ link->link_speed,
+ link->link_autoneg ? "(Fixed)" : "(AutoNeg)",
+ link->link_duplex ?
+ "Full Duplex" : "Half Duplex");
+ } else {
+ RTE_LOG(INFO, KNI, "%s NIC Link is Down.\n",
+ kni->name);
+ }
+ }
+
+ close(fd);
+
+ return 0;
+}
+
void
rte_kni_close(void)
{
diff --git a/lib/librte_kni/rte_kni.h b/lib/librte_kni/rte_kni.h
index 99055e2c2..4118ae97a 100644
--- a/lib/librte_kni/rte_kni.h
+++ b/lib/librte_kni/rte_kni.h
@@ -21,6 +21,7 @@
#include <rte_memory.h>
#include <rte_mempool.h>
#include <rte_ether.h>
+#include <rte_ethdev.h>
#include <exec-env/rte_kni_common.h>
@@ -228,6 +229,23 @@ int rte_kni_register_handlers(struct rte_kni *kni, struct rte_kni_ops *ops);
*/
int rte_kni_unregister_handlers(struct rte_kni *kni);
+/**
+ * Update link status info for KNI port.
+ *
+ * Update the linkup/linkdown status of a KNI interface in the kernel.
+ *
+ * @param kni
+ * pointer to struct rte_kni.
+ * @param link
+ * pointer to struct rte_eth_link containing new interface status.
+ *
+ * @return
+ * On success: 0
+ * On failure: -1
+ */
+int __rte_experimental
+rte_kni_update_link(struct rte_kni *kni, struct rte_eth_link *link);
+
/**
* Close KNI device.
*/
--
2.19.0
next prev parent reply other threads:[~2018-09-11 23:14 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-28 22:45 [dpdk-dev] [PATCH 00/10] kni: Interface detach and link status fixes Dan Gora
2018-06-29 1:54 ` Dan Gora
2018-06-29 1:54 ` [dpdk-dev] [PATCH v2 01/10] kni: remove unused variables from struct kni_dev Dan Gora
2018-08-29 10:29 ` Ferruh Yigit
2018-06-29 1:55 ` [dpdk-dev] [PATCH v2 02/10] kni: separate releasing netdev from freeing KNI interface Dan Gora
2018-08-29 10:59 ` Ferruh Yigit
2018-09-04 0:20 ` Dan Gora
2018-09-04 0:36 ` Dan Gora
2018-10-10 17:24 ` Ferruh Yigit
2018-10-10 18:18 ` Dan Gora
2018-10-10 22:51 ` Ferruh Yigit
2018-10-10 23:38 ` Dan Gora
2018-06-29 1:55 ` [dpdk-dev] [PATCH v2 03/10] kni: don't touch struct kni_dev after freeing Dan Gora
2018-06-29 1:55 ` [dpdk-dev] [PATCH v2 04/10] kni: add rte_kni_free to KNI library Dan Gora
2018-06-29 1:55 ` [dpdk-dev] [PATCH v2 05/10] kni: don't run rte_kni_handle_request after interface release Dan Gora
2018-06-29 1:55 ` [dpdk-dev] [PATCH v2 06/10] kni: increase length of timeout for KNI responses Dan Gora
2018-06-29 1:55 ` [dpdk-dev] [PATCH v2 07/10] kni: update kni test for rte_kni_free Dan Gora
2018-06-29 1:55 ` [dpdk-dev] [PATCH v2 08/10] kni: add rte_kni_free to KNI example app Dan Gora
2018-06-29 1:55 ` [dpdk-dev] [PATCH v2 09/10] kni: add rte_kni_free to KNI vdev driver Dan Gora
2018-06-29 1:55 ` [dpdk-dev] [PATCH v2 10/10] kni: add API to set link status on kernel interface Dan Gora
2018-08-29 11:48 ` Ferruh Yigit
2018-08-29 21:10 ` Dan Gora
2018-08-29 22:01 ` Stephen Hemminger
2018-08-29 15:54 ` Stephen Hemminger
2018-08-29 21:02 ` Dan Gora
2018-08-29 22:00 ` Stephen Hemminger
2018-08-29 22:12 ` Dan Gora
2018-08-29 22:41 ` Dan Gora
2018-08-29 23:10 ` Stephen Hemminger
2018-08-30 9:49 ` Igor Ryzhov
2018-08-30 10:32 ` Igor Ryzhov
2018-08-30 21:41 ` Dan Gora
2018-08-30 22:09 ` Stephen Hemminger
2018-08-30 22:11 ` Dan Gora
2018-09-04 0:47 ` Dan Gora
2018-09-05 12:57 ` Stephen Hemminger
2018-09-11 21:45 ` Dan Gora
2018-09-11 21:52 ` Stephen Hemminger
2018-09-11 22:07 ` Dan Gora
2018-09-11 23:14 ` Stephen Hemminger
2018-09-12 4:02 ` Jason Wang
2018-09-11 23:14 ` [dpdk-dev] [PATCH 0/2] " Dan Gora
2018-09-11 23:14 ` Dan Gora [this message]
2018-09-11 23:18 ` [dpdk-dev] [PATCH 1/2] " Dan Gora
2018-07-20 11:36 ` [dpdk-dev] [PATCH 00/10] kni: Interface detach and link status fixes Ferruh Yigit
2018-09-11 23:29 [dpdk-dev] [PATCH 0/2] kni: add API to set link status on kernel interface Dan Gora
2018-09-11 23:29 ` [dpdk-dev] [PATCH 1/2] " Dan Gora
2018-09-18 16:54 ` Ferruh Yigit
2018-09-18 17:41 ` Dan Gora
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=20180911231417.17222-1-dg@adax.com \
--to=dg@adax.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@intel.com \
--cc=iryzhov@nfware.com \
--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).