DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 0/2] kni: add API to set link status on kernel interface
@ 2018-09-11 23:29 Dan Gora
  2018-09-11 23:29 ` [dpdk-dev] [PATCH 1/2] " Dan Gora
                   ` (13 more replies)
  0 siblings, 14 replies; 94+ messages in thread
From: Dan Gora @ 2018-09-11 23:29 UTC (permalink / raw)
  To: dev; +Cc: Igor Ryzhov, Stephen Hemminger, Ferruh Yigit, Dan Gora

Hi All,

The following patches are to add support for DPDK applications to be
able to change the carrier state of Linux network interfaces in the
KNI kernel module.

The carrier state is changed by writing to the Linux /sys file:
/sys/devices/virtual/net/<name>/carrier, where <name> is the KNI
interface name.

These patches supercede:
'[PATCH v2 10/10] kni: add API to set link status on kernel interface'
https://mails.dpdk.org/archives/dev/2018-August/110383.html

Dan Gora (2):
  kni: add API to set link status on kernel interface
  kni: set default carrier state to 'off'

 kernel/linux/kni/kni_misc.c |  2 ++
 kernel/linux/kni/kni_net.c  |  2 ++
 lib/librte_kni/rte_kni.c    | 57 +++++++++++++++++++++++++++++++++++++
 lib/librte_kni/rte_kni.h    | 18 ++++++++++++
 4 files changed, 79 insertions(+)

-- 
2.19.0

^ permalink raw reply	[flat|nested] 94+ messages in thread
* [dpdk-dev] [PATCH v2 10/10] kni: add API to set link status on kernel interface
@ 2018-06-29  1:55 Dan Gora
  2018-09-11 23:14 ` [dpdk-dev] [PATCH 1/2] " Dan Gora
  0 siblings, 1 reply; 94+ messages in thread
From: Dan Gora @ 2018-06-29  1:55 UTC (permalink / raw)
  To: ferruh.yigit; +Cc: dev, Dan Gora

Add a new API function to KNI, rte_kni_update_link() to allow DPDK
applications to update the link state for the KNI network interfaces
in the linux kernel.

Note that the default carrier state is set to off when the interface
is opened.

Signed-off-by: Dan Gora <dg@adax.com>
---
 kernel/linux/kni/kni_misc.c                   | 63 +++++++++++++++++++
 kernel/linux/kni/kni_net.c                    |  2 +
 .../eal/include/exec-env/rte_kni_common.h     | 19 ++++++
 lib/librte_kni/rte_kni.c                      | 37 ++++++++++-
 lib/librte_kni/rte_kni.h                      | 16 +++++
 5 files changed, 136 insertions(+), 1 deletion(-)

diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c
index 1c38cfa1a..b5784ad1b 100644
--- a/kernel/linux/kni/kni_misc.c
+++ b/kernel/linux/kni/kni_misc.c
@@ -585,6 +585,66 @@ kni_ioctl_free(struct net *net, uint32_t ioctl_num,
 	return ret;
 }
 
+static int
+kni_ioctl_linkstat(struct net *net, uint32_t ioctl_num,
+		unsigned long ioctl_param)
+{
+	struct kni_net *knet = net_generic(net, kni_net_id);
+	int ret = -EINVAL;
+	struct kni_dev *dev, *n;
+	struct rte_kni_link_info link_info;
+	struct net_device *netdev;
+	uint16_t link;
+
+	if (_IOC_SIZE(ioctl_num) > sizeof(link_info))
+		return -EINVAL;
+
+	ret = copy_from_user(&link_info, (void *)ioctl_param,
+			     sizeof(link_info));
+	if (ret) {
+		pr_err("copy_from_user in kni_ioctl_release");
+		return -EIO;
+	}
+
+	/* Release the network device according to its name */
+	if (strlen(link_info.name) == 0)
+		return ret;
+
+	down_read(&knet->kni_list_lock);
+	list_for_each_entry_safe(dev, n, &knet->kni_list_head, list) {
+		if (strncmp(dev->name, link_info.name, RTE_KNI_NAMESIZE) != 0)
+			continue;
+
+		netdev = dev->net_dev;
+		if (netdev == NULL) {
+			up_read(&knet->kni_list_lock);
+			return ret;
+		}
+
+		link = link_info.link_status;
+
+		if (!netif_carrier_ok(netdev) && link) {
+			pr_info("%s NIC Link is Up %d Mbps %s.\n",
+				netdev->name,
+				link_info.link_speed,
+				link_info.link_duplex ==
+					RTE_KNI_LINK_FULL_DUPLEX ?
+					"Full Duplex" : "Half Duplex");
+			netif_carrier_on(netdev);
+		} else if (netif_carrier_ok(netdev) && !link) {
+			pr_info("%s NIC Link is Down.\n",
+				netdev->name);
+			netif_carrier_off(netdev);
+		}
+
+		ret = 0;
+		break;
+	}
+	up_read(&knet->kni_list_lock);
+
+	return ret;
+}
+
 static int
 kni_ioctl(struct inode *inode, uint32_t ioctl_num, unsigned long ioctl_param)
 {
@@ -609,6 +669,9 @@ kni_ioctl(struct inode *inode, uint32_t ioctl_num, unsigned long ioctl_param)
 	case _IOC_NR(RTE_KNI_IOCTL_FREE):
 		ret = kni_ioctl_free(net, ioctl_num, ioctl_param);
 		break;
+	case _IOC_NR(RTE_KNI_IOCTL_LINKSTAT):
+		ret = kni_ioctl_linkstat(net, ioctl_num, ioctl_param);
+		break;
 	default:
 		pr_debug("IOCTL default\n");
 		break;
diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
index 0850be434..fea3ec7e7 100644
--- a/kernel/linux/kni/kni_net.c
+++ b/kernel/linux/kni/kni_net.c
@@ -134,6 +134,7 @@ kni_net_open(struct net_device *dev)
 	struct kni_dev *kni = netdev_priv(dev);
 
 	netif_start_queue(dev);
+	netif_carrier_off(dev);
 
 	memset(&req, 0, sizeof(req));
 	req.req_id = RTE_KNI_REQ_CFG_NETWORK_IF;
@@ -153,6 +154,7 @@ kni_net_release(struct net_device *dev)
 	struct kni_dev *kni = netdev_priv(dev);
 
 	netif_stop_queue(dev); /* can't transmit any more */
+	netif_carrier_off(dev);
 
 	memset(&req, 0, sizeof(req));
 	req.req_id = RTE_KNI_REQ_CFG_NETWORK_IF;
diff --git a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h
index 318a3f939..f617d8026 100644
--- a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h
+++ b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h
@@ -124,11 +124,30 @@ struct rte_kni_device_info {
 	char mac_addr[6];
 };
 
+
+struct rte_kni_link_info {
+	char name[RTE_KNI_NAMESIZE];  /**< Network device name for KNI */
+	uint32_t link_speed;        /**< ETH_SPEED_NUM_ */
+
+#define RTE_KNI_LINK_HALF_DUPLEX 0 /**< Half-duplex connection. */
+#define RTE_KNI_LINK_FULL_DUPLEX 1 /**< Full-duplex connection. */
+	uint16_t link_duplex  : 1;  /**< RTE_KNI_LINK_[HALF/FULL]_DUPLEX */
+
+#define RTE_KNI_LINK_FIXED       0 /**< No autonegotiation. */
+#define RTE_KNI_LINK_AUTONEG     1 /**< Autonegotiated. */
+	uint16_t link_autoneg : 1;  /**< RTE_KNI_LINK_[AUTONEG/FIXED] */
+
+#define RTE_KNI_LINK_DOWN        0 /**< Link is down. */
+#define RTE_KNI_LINK_UP          1 /**< Link is up. */
+	uint16_t link_status  : 1;  /**< RTE_KNI_LINK_[DOWN/UP] */
+};
+
 #define KNI_DEVICE "kni"
 
 #define RTE_KNI_IOCTL_TEST    _IOWR(0, 1, int)
 #define RTE_KNI_IOCTL_CREATE  _IOWR(0, 2, struct rte_kni_device_info)
 #define RTE_KNI_IOCTL_RELEASE _IOWR(0, 3, struct rte_kni_device_info)
 #define RTE_KNI_IOCTL_FREE    _IOWR(0, 4, struct rte_kni_device_info)
+#define RTE_KNI_IOCTL_LINKSTAT _IOWR(0, 5, struct rte_kni_link_info)
 
 #endif /* _RTE_KNI_COMMON_H_ */
diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c
index 6ef0859bf..aa3559306 100644
--- a/lib/librte_kni/rte_kni.c
+++ b/lib/librte_kni/rte_kni.c
@@ -13,7 +13,6 @@
 
 #include <rte_spinlock.h>
 #include <rte_string_fns.h>
-#include <rte_ethdev.h>
 #include <rte_malloc.h>
 #include <rte_log.h>
 #include <rte_kni.h>
@@ -817,6 +816,42 @@ rte_kni_unregister_handlers(struct rte_kni *kni)
 
 	return 0;
 }
+
+int
+rte_kni_update_link(struct rte_kni *kni, struct rte_eth_link *link)
+{
+	struct rte_kni_link_info link_info;
+
+	if (kni == NULL || !kni->in_use || link == NULL)
+		return -1;
+
+	snprintf(link_info.name, sizeof(link_info.name), "%s", kni->name);
+
+	link_info.link_speed = link->link_speed;
+	if (link->link_duplex == ETH_LINK_FULL_DUPLEX)
+		link_info.link_duplex = RTE_KNI_LINK_FULL_DUPLEX;
+	else
+		link_info.link_duplex = RTE_KNI_LINK_FULL_DUPLEX;
+
+	if (link->link_autoneg == ETH_LINK_FIXED)
+		link_info.link_autoneg = RTE_KNI_LINK_FIXED;
+	else
+		link_info.link_autoneg = RTE_KNI_LINK_AUTONEG;
+
+	if (link->link_status == ETH_LINK_UP)
+		link_info.link_status = RTE_KNI_LINK_UP;
+	else
+		link_info.link_status = RTE_KNI_LINK_DOWN;
+
+	if (ioctl(kni_fd, RTE_KNI_IOCTL_LINKSTAT, &link_info) < 0) {
+		RTE_LOG(ERR, KNI,
+			"Failed to update kni link info for dev '%s'.\n",
+			kni->name);
+		return -1;
+	}
+	return 0;
+}
+
 void
 rte_kni_close(void)
 {
diff --git a/lib/librte_kni/rte_kni.h b/lib/librte_kni/rte_kni.h
index 94516c38f..02d781a32 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>
 
@@ -255,6 +256,21 @@ 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.
+ *
+ *  @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.18.0.rc1.1.g6f333ff2f

^ permalink raw reply	[flat|nested] 94+ messages in thread

end of thread, other threads:[~2018-10-26 17:43 UTC | newest]

Thread overview: 94+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2018-09-11 23:29 ` [dpdk-dev] [PATCH 2/2] kni: set default carrier state to 'off' Dan Gora
2018-09-18 16:15   ` Ferruh Yigit
2018-09-18 16:48     ` Ferruh Yigit
2018-09-18 18:34       ` Dan Gora
2018-09-19 19:55 ` [dpdk-dev] [PATCH v2 0/5] kni: add API to set link status on kernel interface Dan Gora
2018-09-19 19:55   ` [dpdk-dev] [PATCH v2 1/5] " Dan Gora
2018-09-26 13:59     ` Ferruh Yigit
2018-09-26 14:55       ` Dan Gora
2018-09-26 16:42         ` Ferruh Yigit
2018-09-26 18:56           ` Dan Gora
2018-09-27 11:35             ` Ferruh Yigit
2018-09-27 15:40               ` Dan Gora
2018-09-27 21:49                 ` Ferruh Yigit
2018-09-27 23:05                   ` Dan Gora
2018-09-27 23:44                     ` Ferruh Yigit
2018-09-27 23:51                       ` Dan Gora
2018-09-28  8:02                         ` Igor Ryzhov
2018-09-28  8:03                         ` Ferruh Yigit
2018-10-03 19:07                           ` Dan Gora
2018-10-10 14:09                             ` Ferruh Yigit
2018-10-10 14:57                               ` Dan Gora
2018-09-19 19:55   ` [dpdk-dev] [PATCH v2 2/5] kni: set default carrier state to 'off' Dan Gora
2018-09-26 13:59     ` Ferruh Yigit
2018-09-19 19:55   ` [dpdk-dev] [PATCH v2 3/5] examples/kni: monitor and update link status continually Dan Gora
2018-09-26 14:00     ` Ferruh Yigit
2018-09-26 19:16       ` Dan Gora
2018-09-27 11:54         ` Ferruh Yigit
2018-09-19 19:55   ` [dpdk-dev] [PATCH v2 4/5] examples/kni: add log msgs to show and clear stats Dan Gora
2018-09-26 14:00     ` Ferruh Yigit
2018-09-19 19:55   ` [dpdk-dev] [PATCH v2 5/5] examples/kni: improve zeroing statistics Dan Gora
2018-09-26 14:01     ` Ferruh Yigit
2018-09-26 14:48       ` Dan Gora
2018-09-27 11:40         ` Ferruh Yigit
2018-09-27 15:53           ` Dan Gora
2018-09-27 22:04             ` Ferruh Yigit
2018-09-27 22:40               ` Dan Gora
2018-09-27  0:32 ` [dpdk-dev] [PATCH v3 0/6] kni: add API to set link status on kernel interface Dan Gora
2018-09-27  0:32   ` [dpdk-dev] [PATCH v3 1/6] " Dan Gora
2018-09-27  0:32   ` [dpdk-dev] [PATCH v3 2/6] kni: add link status test Dan Gora
2018-09-27  0:32   ` [dpdk-dev] [PATCH v3 3/6] kni: set default carrier state to 'off' Dan Gora
2018-09-27  0:32   ` [dpdk-dev] [PATCH v3 4/6] examples/kni: monitor and update link status continually Dan Gora
2018-09-27  0:32   ` [dpdk-dev] [PATCH v3 5/6] examples/kni: add log msgs to show and clear stats Dan Gora
2018-09-27  0:32   ` [dpdk-dev] [PATCH v3 6/6] examples/kni: improve zeroing statistics Dan Gora
2018-10-10 14:16   ` [dpdk-dev] [PATCH v3 0/6] kni: add API to set link status on kernel interface Ferruh Yigit
2018-10-10 15:01     ` Dan Gora
2018-10-10 23:00       ` Ferruh Yigit
2018-10-10 23:36         ` Dan Gora
2018-10-17  1:04 ` [dpdk-dev] [PATCH v4 " Dan Gora
2018-10-17 15:29   ` Ferruh Yigit
2018-10-17  1:04 ` [dpdk-dev] [PATCH v4 1/6] " Dan Gora
2018-10-18 13:44   ` Ferruh Yigit
2018-10-18 19:00     ` Dan Gora
2018-10-17  1:04 ` [dpdk-dev] [PATCH v4 2/6] kni: add link status test Dan Gora
2018-10-17  1:04 ` [dpdk-dev] [PATCH v4 3/6] kni: set default carrier state of interface Dan Gora
2018-10-17 15:20   ` Ferruh Yigit
2018-10-17  1:04 ` [dpdk-dev] [PATCH v4 4/6] examples/kni: monitor and update link status continually Dan Gora
2018-10-17  1:04 ` [dpdk-dev] [PATCH v4 5/6] examples/kni: add log msgs to show and clear stats Dan Gora
2018-10-17  1:04 ` [dpdk-dev] [PATCH v4 6/6] examples/kni: improve zeroing statistics Dan Gora
2018-10-19  0:23 ` [dpdk-dev] [PATCH v5 0/5] kni: add API to set link status on kernel interface Dan Gora
2018-10-19  0:23   ` [dpdk-dev] [PATCH v5 1/5] " Dan Gora
2018-10-19  0:23   ` [dpdk-dev] [PATCH v5 2/5] kni: set default carrier state of interface Dan Gora
2018-10-19  0:23   ` [dpdk-dev] [PATCH v5 3/5] examples/kni: monitor and update link status continually Dan Gora
2018-10-22 12:51     ` Ferruh Yigit
2018-10-22 20:04       ` Dan Gora
2018-10-19  0:23   ` [dpdk-dev] [PATCH v5 4/5] examples/kni: add log msgs to show and clear stats Dan Gora
2018-10-19  0:23   ` [dpdk-dev] [PATCH v5 5/5] examples/kni: improve zeroing statistics Dan Gora
2018-10-22 13:03   ` [dpdk-dev] [PATCH v5 0/5] kni: add API to set link status on kernel interface Ferruh Yigit
2018-10-22 13:08     ` Thomas Monjalon
2018-10-22 13:14       ` Ferruh Yigit
2018-10-22 13:18         ` Thomas Monjalon
2018-10-24 20:27 ` [dpdk-dev] [PATCH v6 " Dan Gora
2018-10-24 20:27   ` [dpdk-dev] [PATCH v6 1/5] " Dan Gora
2018-10-24 20:27   ` [dpdk-dev] [PATCH v6 2/5] kni: set default carrier state of interface Dan Gora
2018-10-24 20:27   ` [dpdk-dev] [PATCH v6 3/5] examples/kni: monitor and update link status continually Dan Gora
2018-10-24 20:27   ` [dpdk-dev] [PATCH v6 4/5] examples/kni: add log msgs to show and clear stats Dan Gora
2018-10-24 20:46     ` Stephen Hemminger
2018-10-24 20:56       ` Dan Gora
2018-10-24 21:17         ` Stephen Hemminger
2018-10-24 21:45           ` Dan Gora
2018-10-24 20:27   ` [dpdk-dev] [PATCH v6 5/5] examples/kni: improve zeroing statistics Dan Gora
2018-10-24 22:26 ` [dpdk-dev] [PATCH v7 0/5] kni: add API to set link status on kernel interface Dan Gora
2018-10-24 22:26   ` [dpdk-dev] [PATCH v7 1/5] " Dan Gora
2018-10-24 22:26   ` [dpdk-dev] [PATCH v7 2/5] kni: set default carrier state of interface Dan Gora
2018-10-24 22:26   ` [dpdk-dev] [PATCH v7 3/5] examples/kni: monitor and update link status continually Dan Gora
2018-10-24 22:26   ` [dpdk-dev] [PATCH v7 4/5] examples/kni: add log msgs to show and clear stats Dan Gora
2018-10-24 22:26   ` [dpdk-dev] [PATCH v7 5/5] examples/kni: improve zeroing statistics Dan Gora
2018-10-25 12:30   ` [dpdk-dev] [PATCH v7 0/5] kni: add API to set link status on kernel interface Ferruh Yigit
2018-10-26 17:43     ` Thomas Monjalon
  -- strict thread matches above, loose matches on Subject: below --
2018-06-29  1:55 [dpdk-dev] [PATCH v2 10/10] " Dan Gora
2018-09-11 23:14 ` [dpdk-dev] [PATCH 1/2] " Dan Gora
2018-09-11 23:18   ` Dan Gora

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).