Skip to contentSkip to conversation

kni: Add link status update

PATCH Superseded Vijayakumar Muthuvel Manickam 4 participants 11 messages May 18, 2015 – Jun 16, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kni: Add link status update

Add an ioctl command in rte_kni module to enable DPDK applications to propagate link state changes to kni virtual interfaces.

---
 .../linuxapp/eal/include/exec-env/rte_kni_common.h |  2 ++
 lib/librte_eal/linuxapp/kni/kni_misc.c             | 39 ++++++++++++++++++++++
 lib/librte_kni/rte_kni.c                           | 18 ++++++++++
 lib/librte_kni/rte_kni.h                           | 17 ++++++++++
 4 files changed, 76 insertions(+)
lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +2 -0
index 1e55c2d..b68001d 100644
@@ -163,6 +163,7 @@ struct rte_kni_device_info {
 
 	/* mbuf size */
 	unsigned mbuf_size;
+	uint8_t link_state;
 };
 
 #define KNI_DEVICE "kni"
@@ -170,5 +171,6 @@ struct rte_kni_device_info {
 #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_LINK_UPDATE _IOWR(0, 4, struct rte_kni_device_info)
 
 #endif /* _RTE_KNI_COMMON_H_ */
lib/librte_eal/linuxapp/kni/kni_misc.c +39 -0
index 1935d32..b1015cd 100644
@@ -548,6 +548,42 @@ kni_ioctl_release(unsigned int ioctl_num, unsigned long ioctl_param)
 }
 
 static int
+kni_ioctl_update_link_state(unsigned int ioctl_num, unsigned long ioctl_param)
+{
+	int ret = -EINVAL;
+	struct kni_dev *dev, *n;
+	struct rte_kni_device_info dev_info;
+
+	if (_IOC_SIZE(ioctl_num) > sizeof(dev_info))
+			return -EINVAL;
+
+	ret = copy_from_user(&dev_info, (void *)ioctl_param, sizeof(dev_info));
+	if (ret) {
+		KNI_ERR("copy_from_user in kni_ioctl_update_link_status");
+		return -EIO;
+	}
+
+	if (strlen(dev_info.name) == 0)
+		return ret;
+
+	down_write(&kni_list_lock);
+	list_for_each_entry_safe(dev, n, &kni_list_head, list) {
+		if (strncmp(dev->name, dev_info.name, RTE_KNI_NAMESIZE) != 0)
+			continue;
+
+		if (dev_info.link_state == 0)
+			netif_carrier_off(dev->net_dev);
+		else
+			netif_carrier_on(dev->net_dev);
+		ret = 0;
+		break;
+	}
+	up_write(&kni_list_lock);
+
+	return ret;
+}
+
+static int
 kni_ioctl(struct inode *inode,
 	unsigned int ioctl_num,
 	unsigned long ioctl_param)
@@ -569,6 +605,9 @@ kni_ioctl(struct inode *inode,
 	case _IOC_NR(RTE_KNI_IOCTL_RELEASE):
 		ret = kni_ioctl_release(ioctl_num, ioctl_param);
 		break;
+	case _IOC_NR(RTE_KNI_IOCTL_LINK_UPDATE):
+		ret = kni_ioctl_update_link_state(ioctl_num, ioctl_param);
+		break;
 	default:
 		KNI_DBG("IOCTL default \n");
 		break;
lib/librte_kni/rte_kni.c +18 -0
index 4e70fa0..b6eda8a 100644
@@ -512,6 +512,24 @@ rte_kni_release(struct rte_kni *kni)
 }
 
 int
+rte_kni_update_link_state(struct rte_kni *kni, uint8_t if_up)
+{
+	struct rte_kni_device_info dev_info;
+
+	if (!kni || !kni->in_use)
+		return -1;
+
+	snprintf(dev_info.name, sizeof(dev_info.name), "%s", kni->name);
+	dev_info.link_state = if_up;
+	if (ioctl(kni_fd, RTE_KNI_IOCTL_LINK_UPDATE, &dev_info) < 0) {
+		RTE_LOG(ERR, KNI, "Fail to update link state\n");
+		return -1;
+	}
+
+	return 0;
+}
+
+int
 rte_kni_handle_request(struct rte_kni *kni)
 {
 	unsigned ret;
lib/librte_kni/rte_kni.h +17 -0
index 98edd72..a1bafd9 100644
@@ -167,6 +167,23 @@ extern struct rte_kni *rte_kni_create(uint8_t port_id,
 extern int rte_kni_release(struct rte_kni *kni);
 
 /**
+ * Send link state changes to KNI interface in kernel space
+ *
+ * rte_kni_update_link_state is thread safe.
+ *
+ * @param kni
+ *  The pointer to the context of an existent KNI interface.
+ * @param if_up
+ *  interface link status
+ *
+ * @return
+ *  - 0 indicates success.
+ *  - negative value indicates failure.
+ */
+
+extern int rte_kni_update_link_state(struct rte_kni *kni, uint8_t if_up);
+
+/**
  * It is used to handle the request mbufs sent from kernel space.
  * Then analyzes it and calls the specific actions for the specific requests.
  * Finally constructs the response mbuf and puts it back to the resp_q.
Signature · 1 line
1.8.1.4
#1 lore raw

Hello

Quoted 26 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Vijayakumar Muthuvel Manickam
Sent: Tuesday, May 19, 2015 7:33 AM
To: [email protected]
Subject: [dpdk-dev] [PATCH] kni: Add link status update

Add an ioctl command in rte_kni module to enable DPDK applications to propagate link state changes to kni virtual interfaces.

---
 .../linuxapp/eal/include/exec-env/rte_kni_common.h |  2 ++
 lib/librte_eal/linuxapp/kni/kni_misc.c             | 39
++++++++++++++++++++++
 lib/librte_kni/rte_kni.c                           | 18 ++++++++++
 lib/librte_kni/rte_kni.h                           | 17 ++++++++++
 4 files changed, 76 insertions(+)

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 1e55c2d..b68001d 100644

lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h struct rte_kni_device_info { · line 166

Quoted 4 lines
lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +1 -0
@@ -163,6 +163,7 @@ struct rte_kni_device_info {
 
 	/* mbuf size */
 	unsigned mbuf_size;
+	uint8_t link_state;

How about transfer more states from user space to kernel space, such as link speed, duplex, etc?

Quoted 85 lines
lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +2 -0
 };
 
 #define KNI_DEVICE "kni"
@@ -170,5 +171,6 @@ struct rte_kni_device_info {
 #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_LINK_UPDATE _IOWR(0, 4, struct
+rte_kni_device_info)
 
 #endif /* _RTE_KNI_COMMON_H_ */
lib/librte_eal/linuxapp/kni/kni_misc.c +36 -0
index 1935d32..b1015cd 100644
@@ -548,6 +548,42 @@ kni_ioctl_release(unsigned int ioctl_num,
 unsigned long ioctl_param)  }
 
 static int
+kni_ioctl_update_link_state(unsigned int ioctl_num, unsigned long
+ioctl_param) {
+	int ret = -EINVAL;
+	struct kni_dev *dev, *n;
+	struct rte_kni_device_info dev_info;
+
+	if (_IOC_SIZE(ioctl_num) > sizeof(dev_info))
+			return -EINVAL;
+
+	ret = copy_from_user(&dev_info, (void *)ioctl_param,
 sizeof(dev_info));
+	if (ret) {
+		KNI_ERR("copy_from_user in kni_ioctl_update_link_status");
+		return -EIO;
+	}
+
+	if (strlen(dev_info.name) == 0)
+		return ret;
+
+	down_write(&kni_list_lock);
+	list_for_each_entry_safe(dev, n, &kni_list_head, list) {
+		if (strncmp(dev->name, dev_info.name, RTE_KNI_NAMESIZE) !=
 0)
+			continue;
+
+		if (dev_info.link_state == 0)
+			netif_carrier_off(dev->net_dev);
+		else
+			netif_carrier_on(dev->net_dev);
+		ret = 0;
+		break;
+	}
+	up_write(&kni_list_lock);
+
+	return ret;
+}
+
+static int
 kni_ioctl(struct inode *inode,
lib/librte_eal/linuxapp/kni/kni_misc.c +3 -0
 	unsigned int ioctl_num,
 	unsigned long ioctl_param)
@@ -569,6 +605,9 @@ kni_ioctl(struct inode *inode,
 	case _IOC_NR(RTE_KNI_IOCTL_RELEASE):
 		ret = kni_ioctl_release(ioctl_num, ioctl_param);
 		break;
+	case _IOC_NR(RTE_KNI_IOCTL_LINK_UPDATE):
+		ret = kni_ioctl_update_link_state(ioctl_num, ioctl_param);
+		break;
 	default:
 		KNI_DBG("IOCTL default \n");
 		break;
lib/librte_kni/rte_kni.c index renamed from lib/librte_kni/rte_kni.c +0 -0

4e70fa0..b6eda8a 100644

lib/librte_kni/rte_kni.c +6 -0
@@ -512,6 +512,24 @@ rte_kni_release(struct rte_kni *kni)  }
 
 int
+rte_kni_update_link_state(struct rte_kni *kni, uint8_t if_up) {
+	struct rte_kni_device_info dev_info;
+
+	if (!kni || !kni->in_use)
+		return -1;
+

lib/librte_kni/rte_kni.c rte_kni_release(struct rte_kni *kni) } · line 529

Quoted 10 lines
lib/librte_kni/rte_kni.c +10 -0
+	snprintf(dev_info.name, sizeof(dev_info.name), "%s", kni->name);
+	dev_info.link_state = if_up;
+	if (ioctl(kni_fd, RTE_KNI_IOCTL_LINK_UPDATE, &dev_info) < 0) {
+		RTE_LOG(ERR, KNI, "Fail to update link state\n");
+		return -1;
+	}
+
+	return 0;
+}
+

This new interface should be called at the end of rte_kni_alloc() to notify the link status after a KNI interface is created.

Thanks,
Helin

Quoted 34 lines
lib/librte_kni/rte_kni.c +1 -0
+int
 rte_kni_handle_request(struct rte_kni *kni)  {
 	unsigned ret;
lib/librte_kni/rte_kni.h index renamed from lib/librte_kni/rte_kni.h +0 -0

98edd72..a1bafd9 100644

lib/librte_kni/rte_kni.h +18 -1
@@ -167,6 +167,23 @@ extern struct rte_kni *rte_kni_create(uint8_t
 port_id,  extern int rte_kni_release(struct rte_kni *kni);
 
 /**
+ * Send link state changes to KNI interface in kernel space
+ *
+ * rte_kni_update_link_state is thread safe.
+ *
+ * @param kni
+ *  The pointer to the context of an existent KNI interface.
+ * @param if_up
+ *  interface link status
+ *
+ * @return
+ *  - 0 indicates success.
+ *  - negative value indicates failure.
+ */
+
+extern int rte_kni_update_link_state(struct rte_kni *kni, uint8_t
+if_up);
+
+/**
  * It is used to handle the request mbufs sent from kernel space.
  * Then analyzes it and calls the specific actions for the specific requests.
  * Finally constructs the response mbuf and puts it back to the resp_q.
--

1.8.1.4

#10 lore raw
In reply to Vijayakumar Muthuvel Manickam

I agree that this looks like a good facility to have but this is not the right way to do it.

There are already several facilities to accomplish the same thing.

1. You can use the operstate functionality in kernel to manipulate carrier from another application (read Documentation/operstate.txt)

2. It is possible with sysfs to change carrier state. The KNI driver just has to provide an .ndo_change_carrier callback.

Introducing more ioctl's is not a good thing. KNI needs to get rid of the quick and dirty ioctl approach and follow current best practices for Linux network drivers. It should really be using netlink instead of ioctl(). Ioctl's have several compatibility issues that make them unacceptable upstream. There is a standard API for create/destroy with netlink and the custom ioctl's could be banished into the attic of dead API's.

PS: Has anybody even attempted to get KNI upstream? I can see lots
of style (and security) issues that would need to be fixed.

#2 lore raw
In reply to Zhang, Helin

Any response for my comments? Did I miss anything?

- Helin

Quoted 176 lines

-----Original Message-----
From: Zhang, Helin
Sent: Tuesday, May 19, 2015 8:54 AM
To: Vijayakumar Muthuvel Manickam; [email protected]
Subject: RE: [dpdk-dev] [PATCH] kni: Add link status update

Hello

Quoted 26 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Vijayakumar Muthuvel Manickam
Sent: Tuesday, May 19, 2015 7:33 AM
To: [email protected]
Subject: [dpdk-dev] [PATCH] kni: Add link status update

Add an ioctl command in rte_kni module to enable DPDK applications to propagate link state changes to kni virtual interfaces.

---
 .../linuxapp/eal/include/exec-env/rte_kni_common.h |  2 ++
 lib/librte_eal/linuxapp/kni/kni_misc.c             | 39
++++++++++++++++++++++
 lib/librte_kni/rte_kni.c                           | 18 ++++++++++
 lib/librte_kni/rte_kni.h                           | 17 ++++++++++
 4 files changed, 76 insertions(+)

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 1e55c2d..b68001d 100644

lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h struct rte_kni_device_info { · line 166

Quoted 4 lines
lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +1 -0
@@ -163,6 +163,7 @@ struct rte_kni_device_info {
 
 	/* mbuf size */
 	unsigned mbuf_size;
+	uint8_t link_state;

How about transfer more states from user space to kernel space, such as link speed, duplex, etc?

Quoted 85 lines
lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +0 -0
 };
 
 #define KNI_DEVICE "kni"
@@ -170,5 +171,6 @@ struct rte_kni_device_info {
 #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)

lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +2 -0
+#define RTE_KNI_IOCTL_LINK_UPDATE _IOWR(0, 4, struct
+rte_kni_device_info)
 
 #endif /* _RTE_KNI_COMMON_H_ */
lib/librte_eal/linuxapp/kni/kni_misc.c +36 -0
index 1935d32..b1015cd 100644
@@ -548,6 +548,42 @@ kni_ioctl_release(unsigned int ioctl_num,
 unsigned long ioctl_param)  }
 
 static int
+kni_ioctl_update_link_state(unsigned int ioctl_num, unsigned long
+ioctl_param) {
+	int ret = -EINVAL;
+	struct kni_dev *dev, *n;
+	struct rte_kni_device_info dev_info;
+
+	if (_IOC_SIZE(ioctl_num) > sizeof(dev_info))
+			return -EINVAL;
+
+	ret = copy_from_user(&dev_info, (void *)ioctl_param,
 sizeof(dev_info));
+	if (ret) {
+		KNI_ERR("copy_from_user in kni_ioctl_update_link_status");
+		return -EIO;
+	}
+
+	if (strlen(dev_info.name) == 0)
+		return ret;
+
+	down_write(&kni_list_lock);
+	list_for_each_entry_safe(dev, n, &kni_list_head, list) {
+		if (strncmp(dev->name, dev_info.name, RTE_KNI_NAMESIZE) !=
 0)
+			continue;
+
+		if (dev_info.link_state == 0)
+			netif_carrier_off(dev->net_dev);
+		else
+			netif_carrier_on(dev->net_dev);
+		ret = 0;
+		break;
+	}
+	up_write(&kni_list_lock);
+
+	return ret;
+}
+
+static int
 kni_ioctl(struct inode *inode,
lib/librte_eal/linuxapp/kni/kni_misc.c +3 -0
 	unsigned int ioctl_num,
 	unsigned long ioctl_param)
@@ -569,6 +605,9 @@ kni_ioctl(struct inode *inode,
 	case _IOC_NR(RTE_KNI_IOCTL_RELEASE):
 		ret = kni_ioctl_release(ioctl_num, ioctl_param);
 		break;
+	case _IOC_NR(RTE_KNI_IOCTL_LINK_UPDATE):
+		ret = kni_ioctl_update_link_state(ioctl_num, ioctl_param);
+		break;
 	default:
 		KNI_DBG("IOCTL default \n");
 		break;
lib/librte_kni/rte_kni.c index renamed from lib/librte_kni/rte_kni.c +0 -0

4e70fa0..b6eda8a 100644

lib/librte_kni/rte_kni.c +6 -0
@@ -512,6 +512,24 @@ rte_kni_release(struct rte_kni *kni)  }
 
 int
+rte_kni_update_link_state(struct rte_kni *kni, uint8_t if_up) {
+	struct rte_kni_device_info dev_info;
+
+	if (!kni || !kni->in_use)
+		return -1;
+

lib/librte_kni/rte_kni.c rte_kni_release(struct rte_kni *kni) } · line 529

Quoted 10 lines
lib/librte_kni/rte_kni.c +10 -0
+	snprintf(dev_info.name, sizeof(dev_info.name), "%s", kni->name);
+	dev_info.link_state = if_up;
+	if (ioctl(kni_fd, RTE_KNI_IOCTL_LINK_UPDATE, &dev_info) < 0) {
+		RTE_LOG(ERR, KNI, "Fail to update link state\n");
+		return -1;
+	}
+
+	return 0;
+}
+

This new interface should be called at the end of rte_kni_alloc() to notify the link status after a KNI interface is created.

Thanks,
Helin

Quoted 34 lines
lib/librte_kni/rte_kni.c +1 -0
+int
 rte_kni_handle_request(struct rte_kni *kni)  {
 	unsigned ret;
lib/librte_kni/rte_kni.h index renamed from lib/librte_kni/rte_kni.h +0 -0

98edd72..a1bafd9 100644

lib/librte_kni/rte_kni.h +18 -1
@@ -167,6 +167,23 @@ extern struct rte_kni *rte_kni_create(uint8_t
 port_id,  extern int rte_kni_release(struct rte_kni *kni);
 
 /**
+ * Send link state changes to KNI interface in kernel space
+ *
+ * rte_kni_update_link_state is thread safe.
+ *
+ * @param kni
+ *  The pointer to the context of an existent KNI interface.
+ * @param if_up
+ *  interface link status
+ *
+ * @return
+ *  - 0 indicates success.
+ *  - negative value indicates failure.
+ */
+
+extern int rte_kni_update_link_state(struct rte_kni *kni, uint8_t
+if_up);
+
+/**
  * It is used to handle the request mbufs sent from kernel space.
  * Then analyzes it and calls the specific actions for the specific requests.
  * Finally constructs the response mbuf and puts it back to the resp_q.
--

1.8.1.4

#3 lore raw

Hi Helin,

Since Stepthen pointed out ioctl is not the best way to add this facility, I have a patch that will enable link status update through sysfs by implementing .ndo_change_carrier. I will submit it today.
I will submit a separate patch for transferring link speed,duplex etc., this week.

Thanks,
Vijay

Quoted 186 lines · Helin

Any response for my comments? Did I miss anything?

- Helin

Quoted 35 lines

-----Original Message-----
From: Zhang, Helin
Sent: Tuesday, May 19, 2015 8:54 AM
To: Vijayakumar Muthuvel Manickam; [email protected]
Subject: RE: [dpdk-dev] [PATCH] kni: Add link status update

Hello

Quoted 27 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Vijayakumar Muthuvel Manickam
Sent: Tuesday, May 19, 2015 7:33 AM
To: [email protected]
Subject: [dpdk-dev] [PATCH] kni: Add link status update

Add an ioctl command in rte_kni module to enable DPDK applications to propagate link state changes to kni virtual interfaces.

---
 .../linuxapp/eal/include/exec-env/rte_kni_common.h |  2 ++
 lib/librte_eal/linuxapp/kni/kni_misc.c             | 39
++++++++++++++++++++++
 lib/librte_kni/rte_kni.c                           | 18 ++++++++++
 lib/librte_kni/rte_kni.h                           | 17 ++++++++++
 4 files changed, 76 insertions(+)

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 1e55c2d..b68001d 100644

lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +0 -0
@@ -163,6 +163,7 @@ struct rte_kni_device_info {
 
Quoted 4 lines

lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h struct rte_kni_device_info { · line 166

Quoted 3 lines
lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +1 -0
    /* mbuf size */
    unsigned mbuf_size;
+   uint8_t link_state;

How about transfer more states from user space to kernel space, such as

link

Quoted 90 lines

speed, duplex, etc?

Quoted 88 lines
lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +0 -0
 };
 
 #define KNI_DEVICE "kni"
@@ -170,5 +171,6 @@ struct rte_kni_device_info {
 #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)

lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +2 -0
+#define RTE_KNI_IOCTL_LINK_UPDATE _IOWR(0, 4, struct
+rte_kni_device_info)
 
 #endif /* _RTE_KNI_COMMON_H_ */
lib/librte_eal/linuxapp/kni/kni_misc.c +36 -0
index 1935d32..b1015cd 100644
@@ -548,6 +548,42 @@ kni_ioctl_release(unsigned int ioctl_num,
 unsigned long ioctl_param)  }
 
 static int
+kni_ioctl_update_link_state(unsigned int ioctl_num, unsigned long
+ioctl_param) {
+   int ret = -EINVAL;
+   struct kni_dev *dev, *n;
+   struct rte_kni_device_info dev_info;
+
+   if (_IOC_SIZE(ioctl_num) > sizeof(dev_info))
+                   return -EINVAL;
+
+   ret = copy_from_user(&dev_info, (void *)ioctl_param,
 sizeof(dev_info));
+   if (ret) {
+           KNI_ERR("copy_from_user in kni_ioctl_update_link_status");
+           return -EIO;
+   }
+
+   if (strlen(dev_info.name) == 0)
+           return ret;
+
+   down_write(&kni_list_lock);
+   list_for_each_entry_safe(dev, n, &kni_list_head, list) {
+           if (strncmp(dev->name, dev_info.name, RTE_KNI_NAMESIZE) !=
 0)
+                   continue;
+
+           if (dev_info.link_state == 0)
+                   netif_carrier_off(dev->net_dev);
+           else
+                   netif_carrier_on(dev->net_dev);
+           ret = 0;
+           break;
+   }
+   up_write(&kni_list_lock);
+
+   return ret;
+}
+
+static int
 kni_ioctl(struct inode *inode,

unsigned int ioctl_num,
unsigned long ioctl_param)

lib/librte_eal/linuxapp/kni/kni_misc.c +3 -0
@@ -569,6 +605,9 @@ kni_ioctl(struct inode *inode,
    case _IOC_NR(RTE_KNI_IOCTL_RELEASE):
            ret = kni_ioctl_release(ioctl_num, ioctl_param);
            break;
+   case _IOC_NR(RTE_KNI_IOCTL_LINK_UPDATE):
+           ret = kni_ioctl_update_link_state(ioctl_num, ioctl_param);
+           break;
    default:
            KNI_DBG("IOCTL default \n");
            break;
lib/librte_kni/rte_kni.c index renamed from lib/librte_kni/rte_kni.c +0 -0

4e70fa0..b6eda8a 100644

lib/librte_kni/rte_kni.c +9 -0
@@ -512,6 +512,24 @@ rte_kni_release(struct rte_kni *kni)  }
 
 int
+rte_kni_update_link_state(struct rte_kni *kni, uint8_t if_up) {
+   struct rte_kni_device_info dev_info;
+
+   if (!kni || !kni->in_use)
+           return -1;
+
+   snprintf(dev_info.name, sizeof(dev_info.name), "%s", kni->name);
+   dev_info.link_state = if_up;
+   if (ioctl(kni_fd, RTE_KNI_IOCTL_LINK_UPDATE, &dev_info) < 0) {
Quoted 8 lines

lib/librte_kni/rte_kni.c rte_kni_release(struct rte_kni *kni) · line 531

Quoted 7 lines
lib/librte_kni/rte_kni.c +7 -0
+           RTE_LOG(ERR, KNI, "Fail to update link state\n");
+           return -1;
+   }
+
+   return 0;
+}
+

This new interface should be called at the end of rte_kni_alloc() to

notify the link

Quoted 28 lines

status after a KNI interface is created.

Thanks,
Helin

Quoted 23 lines
lib/librte_kni/rte_kni.c +1 -0
+int
 rte_kni_handle_request(struct rte_kni *kni)  {
    unsigned ret;
lib/librte_kni/rte_kni.h index renamed from lib/librte_kni/rte_kni.h +0 -0

98edd72..a1bafd9 100644

lib/librte_kni/rte_kni.h +12 -0
@@ -167,6 +167,23 @@ extern struct rte_kni *rte_kni_create(uint8_t
 port_id,  extern int rte_kni_release(struct rte_kni *kni);
 
 /**
+ * Send link state changes to KNI interface in kernel space
+ *
+ * rte_kni_update_link_state is thread safe.
+ *
+ * @param kni
+ *  The pointer to the context of an existent KNI interface.
+ * @param if_up
+ *  interface link status
+ *
+ * @return
+ *  - 0 indicates success.
+ *  - negative value indicates failure.
Quoted 8 lines

lib/librte_kni/rte_kni.h extern struct rte_kni *rte_kni_create(uint8_t port_id,

Quoted 8 lines
lib/librte_kni/rte_kni.h +6 -0
+ */
+
+extern int rte_kni_update_link_state(struct rte_kni *kni, uint8_t
+if_up);
+
+/**
  * It is used to handle the request mbufs sent from kernel space.
  * Then analyzes it and calls the specific actions for the specific

requests.

Quoted 1 line
Quoted 1 line

* Finally constructs the response mbuf and puts it back to the

resp_q.

Quoted 2 lines
Quoted 2 lines

--
1.8.1.4

#4 lore raw

That’s great. Thanks!

- Helin

From: Vijayakumar Muthuvel Manickam [mailto:[email protected]]
Sent: Monday, June 15, 2015 9:11 AM
To: Zhang, Helin
Cc: [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH] kni: Add link status update

Hi Helin,

Since Stepthen pointed out ioctl is not the best way to add this facility, I have a patch that will enable link status update through sysfs by implementing .ndo_change_carrier. I will submit it today. I will submit a separate patch for transferring link speed,duplex etc., this week.

Thanks,
Vijay

On Sun, Jun 14, 2015 at 5:57 PM, Zhang, Helin <[email protected]<mailto:[email protected]>> wrote:
Any response for my comments? Did I miss anything?

- Helin

Quoted 176 lines

-----Original Message-----
From: Zhang, Helin
Sent: Tuesday, May 19, 2015 8:54 AM
To: Vijayakumar Muthuvel Manickam; [email protected]<mailto:[email protected]>
Subject: RE: [dpdk-dev] [PATCH] kni: Add link status update

Hello

Quoted 26 lines

-----Original Message-----
From: dev [mailto:[email protected]<mailto:[email protected]>] On Behalf Of Vijayakumar Muthuvel Manickam
Sent: Tuesday, May 19, 2015 7:33 AM
To: [email protected]<mailto:[email protected]>
Subject: [dpdk-dev] [PATCH] kni: Add link status update

Add an ioctl command in rte_kni module to enable DPDK applications to propagate link state changes to kni virtual interfaces.

---
 .../linuxapp/eal/include/exec-env/rte_kni_common.h |  2 ++
 lib/librte_eal/linuxapp/kni/kni_misc.c             | 39
++++++++++++++++++++++
 lib/librte_kni/rte_kni.c                           | 18 ++++++++++
 lib/librte_kni/rte_kni.h                           | 17 ++++++++++
 4 files changed, 76 insertions(+)

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 1e55c2d..b68001d 100644

lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h struct rte_kni_device_info { · line 166

Quoted 4 lines
lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +1 -0
@@ -163,6 +163,7 @@ struct rte_kni_device_info {
 
    /* mbuf size */
    unsigned mbuf_size;
+   uint8_t link_state;

How about transfer more states from user space to kernel space, such as link speed, duplex, etc?

Quoted 85 lines
lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +0 -0
 };
 
 #define KNI_DEVICE "kni"
@@ -170,5 +171,6 @@ struct rte_kni_device_info {
 #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)

lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +2 -0
+#define RTE_KNI_IOCTL_LINK_UPDATE _IOWR(0, 4, struct
+rte_kni_device_info)
 
 #endif /* _RTE_KNI_COMMON_H_ */
lib/librte_eal/linuxapp/kni/kni_misc.c +36 -0
index 1935d32..b1015cd 100644
@@ -548,6 +548,42 @@ kni_ioctl_release(unsigned int ioctl_num,
 unsigned long ioctl_param)  }
 
 static int
+kni_ioctl_update_link_state(unsigned int ioctl_num, unsigned long
+ioctl_param) {
+   int ret = -EINVAL;
+   struct kni_dev *dev, *n;
+   struct rte_kni_device_info dev_info;
+
+   if (_IOC_SIZE(ioctl_num) > sizeof(dev_info))
+                   return -EINVAL;
+
+   ret = copy_from_user(&dev_info, (void *)ioctl_param,
 sizeof(dev_info));
+   if (ret) {
+           KNI_ERR("copy_from_user in kni_ioctl_update_link_status");
+           return -EIO;
+   }
+
+   if (strlen(dev_info.name<http://dev_info.name>) == 0)
+           return ret;
+
+   down_write(&kni_list_lock);
+   list_for_each_entry_safe(dev, n, &kni_list_head, list) {
+           if (strncmp(dev->name, dev_info.name<http://dev_info.name>, RTE_KNI_NAMESIZE) !=
 0)
+                   continue;
+
+           if (dev_info.link_state == 0)
+                   netif_carrier_off(dev->net_dev);
+           else
+                   netif_carrier_on(dev->net_dev);
+           ret = 0;
+           break;
+   }
+   up_write(&kni_list_lock);
+
+   return ret;
+}
+
+static int
 kni_ioctl(struct inode *inode,

unsigned int ioctl_num,
unsigned long ioctl_param)

lib/librte_eal/linuxapp/kni/kni_misc.c +3 -0
@@ -569,6 +605,9 @@ kni_ioctl(struct inode *inode,
    case _IOC_NR(RTE_KNI_IOCTL_RELEASE):
            ret = kni_ioctl_release(ioctl_num, ioctl_param);
            break;
+   case _IOC_NR(RTE_KNI_IOCTL_LINK_UPDATE):
+           ret = kni_ioctl_update_link_state(ioctl_num, ioctl_param);
+           break;
    default:
            KNI_DBG("IOCTL default \n");
            break;
lib/librte_kni/rte_kni.c index renamed from lib/librte_kni/rte_kni.c +0 -0

4e70fa0..b6eda8a 100644

lib/librte_kni/rte_kni.c +6 -0
@@ -512,6 +512,24 @@ rte_kni_release(struct rte_kni *kni)  }
 
 int
+rte_kni_update_link_state(struct rte_kni *kni, uint8_t if_up) {
+   struct rte_kni_device_info dev_info;
+
+   if (!kni || !kni->in_use)
+           return -1;
+

lib/librte_kni/rte_kni.c rte_kni_release(struct rte_kni *kni) } · line 529

Quoted 10 lines
lib/librte_kni/rte_kni.c +10 -0
+   snprintf(dev_info.name<http://dev_info.name>, sizeof(dev_info.name<http://dev_info.name>), "%s", kni->name);
+   dev_info.link_state = if_up;
+   if (ioctl(kni_fd, RTE_KNI_IOCTL_LINK_UPDATE, &dev_info) < 0) {
+           RTE_LOG(ERR, KNI, "Fail to update link state\n");
+           return -1;
+   }
+
+   return 0;
+}
+

This new interface should be called at the end of rte_kni_alloc() to notify the link status after a KNI interface is created.

Thanks,
Helin

Quoted 34 lines
lib/librte_kni/rte_kni.c +1 -0
+int
 rte_kni_handle_request(struct rte_kni *kni)  {
    unsigned ret;
lib/librte_kni/rte_kni.h index renamed from lib/librte_kni/rte_kni.h +0 -0

98edd72..a1bafd9 100644

lib/librte_kni/rte_kni.h +18 -1
@@ -167,6 +167,23 @@ extern struct rte_kni *rte_kni_create(uint8_t
 port_id,  extern int rte_kni_release(struct rte_kni *kni);
 
 /**
+ * Send link state changes to KNI interface in kernel space
+ *
+ * rte_kni_update_link_state is thread safe.
+ *
+ * @param kni
+ *  The pointer to the context of an existent KNI interface.
+ * @param if_up
+ *  interface link status
+ *
+ * @return
+ *  - 0 indicates success.
+ *  - negative value indicates failure.
+ */
+
+extern int rte_kni_update_link_state(struct rte_kni *kni, uint8_t
+if_up);
+
+/**
  * It is used to handle the request mbufs sent from kernel space.
  * Then analyzes it and calls the specific actions for the specific requests.
  * Finally constructs the response mbuf and puts it back to the resp_q.
--

1.8.1.4

#5 lore raw

PATCH v2 1/1 kni: Add link status update

Implement .ndo_change_carrier to enable
DPDK applications to propagate link state changes to kni virtual interfaces through sysfs

---
Implemented .ndo_change_carrier instead of adding a new ioctl

 lib/librte_eal/linuxapp/kni/kni_net.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
lib/librte_eal/linuxapp/kni/kni_net.c +10 -0
index dd95db5..10c94ce 100644
@@ -632,6 +632,15 @@ static int kni_net_set_mac(struct net_device *netdev, void *p)
 	return 0;
 }
 
+static int kni_net_change_carrier(struct net_device *dev, bool new_carrier)
+{
+	if (new_carrier)
+		netif_carrier_on(dev);
+	else
+		netif_carrier_off(dev);
+	return 0;
+}
+
 static const struct header_ops kni_net_header_ops = {
 	.create  = kni_net_header,
 	.rebuild = kni_net_rebuild_header,
@@ -648,6 +657,7 @@ static const struct net_device_ops kni_net_netdev_ops = {
 	.ndo_get_stats = kni_net_stats,
 	.ndo_tx_timeout = kni_net_tx_timeout,
 	.ndo_set_mac_address = kni_net_set_mac,
+	.ndo_change_carrier = kni_net_change_carrier,
 };
 
 void
Signature · 1 line
1.8.1.4
Acked-by on v2 1/1
#6 lore raw
Quoted 32 lines · On Mon, 15 Jun 2015 04:21:43 -0400 Vijayakumar Muthuvel Manickam…

Implement .ndo_change_carrier to enable
DPDK applications to propagate link state changes to kni virtual interfaces through sysfs

---
Implemented .ndo_change_carrier instead of adding a new ioctl

 lib/librte_eal/linuxapp/kni/kni_net.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
lib/librte_eal/linuxapp/kni/kni_net.c +9 -0
index dd95db5..10c94ce 100644
@@ -632,6 +632,15 @@ static int kni_net_set_mac(struct net_device *netdev, void *p)
 	return 0;
 }
 
+static int kni_net_change_carrier(struct net_device *dev, bool new_carrier)
+{
+	if (new_carrier)
+		netif_carrier_on(dev);
+	else
+		netif_carrier_off(dev);
+	return 0;
+}
+
 static const struct header_ops kni_net_header_ops = {
 	.create  = kni_net_header,
 	.rebuild = kni_net_rebuild_header,

lib/librte_eal/linuxapp/kni/kni_net.c static const struct net_device_ops kni_net_netdev_ops = { · line 663

Quoted 7 lines
lib/librte_eal/linuxapp/kni/kni_net.c +1 -0
@@ -648,6 +657,7 @@ static const struct net_device_ops kni_net_netdev_ops = {
 	.ndo_get_stats = kni_net_stats,
 	.ndo_tx_timeout = kni_net_tx_timeout,
 	.ndo_set_mac_address = kni_net_set_mac,
+	.ndo_change_carrier = kni_net_change_carrier,
 };
 
 void

You might need to have a kernel version test?? since carrier change was introduced in 3.9 kernel

#7 lore raw

PATCH v3 1/1 kni: Add link status update

Implement .ndo_change_carrier to enable
DPDK applications to propagate link state changes to kni virtual interfaces through sysfs

---
Added kernel version check as .ndo_change_carrier is available only in kernel versions 3.9 and after

 lib/librte_eal/linuxapp/kni/kni_net.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
lib/librte_eal/linuxapp/kni/kni_net.c +14 -0
index dd95db5..9f9022b 100644
@@ -632,6 +632,17 @@ static int kni_net_set_mac(struct net_device *netdev, void *p)
 	return 0;
 }
 
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
+static int kni_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 header_ops kni_net_header_ops = {
 	.create  = kni_net_header,
 	.rebuild = kni_net_rebuild_header,
@@ -648,6 +659,9 @@ static const struct net_device_ops kni_net_netdev_ops = {
 	.ndo_get_stats = kni_net_stats,
 	.ndo_tx_timeout = kni_net_tx_timeout,
 	.ndo_set_mac_address = kni_net_set_mac,
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
+	.ndo_change_carrier = kni_net_change_carrier,
+#endif
 };
 
 void
Signature · 1 line
1.8.1.4
Acked-by on v3 1/1
#8 lore raw
Quoted 9 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Vijayakumar Muthuvel Manickam
Sent: Tuesday, June 16, 2015 2:40 PM
To: [email protected]
Subject: [dpdk-dev] [PATCH v3] kni: Add link status update

Quoted 5 lines

Implement .ndo_change_carrier to enable
DPDK applications to propagate link state changes to kni virtual interfaces through sysfs

Quoted 42 lines

---
Added kernel version check as .ndo_change_carrier is available only in kernel versions 3.9 and after

 lib/librte_eal/linuxapp/kni/kni_net.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
lib/librte_eal/linuxapp/kni/kni_net.c +12 -1
index dd95db5..9f9022b 100644
@@ -632,6 +632,17 @@ static int kni_net_set_mac(struct net_device *netdev,
 void *p)
 	return 0;
 }
 
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)) static int
+kni_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 header_ops kni_net_header_ops = {
 	.create  = kni_net_header,
 	.rebuild = kni_net_rebuild_header,
@@ -648,6 +659,9 @@ static const struct net_device_ops kni_net_netdev_ops =
 {
 	.ndo_get_stats = kni_net_stats,
 	.ndo_tx_timeout = kni_net_tx_timeout,
 	.ndo_set_mac_address = kni_net_set_mac,
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
+	.ndo_change_carrier = kni_net_change_carrier, #endif
 };
 
 void
--

1.8.1.4