DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [memnic PATCH v2 5/5] linux: support MTU change
@ 2014-06-18 10:57 Hiroshi Shimamoto
  0 siblings, 0 replies; only message in thread
From: Hiroshi Shimamoto @ 2014-06-18 10:57 UTC (permalink / raw)
  To: dev; +Cc: Hayato Momma

From: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>

Add the capability to change MTU.

On MTU change, remember the corresponding frame size and request new
frame size to the host on reset, if the host MEMNIC has that feature.

Don't trust framesz of header in general usage, because host might change
the value unexpectedly.

v2: forgot to update netdev->mtu on change, fix it.

Signed-off-by: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
Reviewed-by: Hayato Momma <h-momma@ce.jp.nec.com>
---
 linux/memnic_net.c | 41 ++++++++++++++++++++++++++++++++++++++---
 linux/memnic_net.h |  5 +++++
 2 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/linux/memnic_net.c b/linux/memnic_net.c
index 02b5acc..f92cbd1 100644
--- a/linux/memnic_net.c
+++ b/linux/memnic_net.c
@@ -31,6 +31,7 @@
 
 #include <linux/etherdevice.h>
 #include <linux/kthread.h>
+#include <linux/if_vlan.h>
 
 #include "memnic_net.h"
 #include "memnic.h"
@@ -152,19 +153,31 @@ static int memnic_open(struct net_device *netdev)
 {
 	struct memnic_net *memnic = netdev_priv(netdev);
 	struct memnic_area *nic = memnic->dev->base_addr;
+	struct memnic_header *hdr = &nic->hdr;
 	struct task_struct *kthread;
 
 	/* clear stats */
 	memset(&memnic->stats, 0, sizeof(memnic->stats));
 	/* invalidate and reset here */
-	nic->hdr.valid = 0;
+	hdr->valid = 0;
+
+	/* setup parameters */
+	if (memnic->request.features & MEMNIC_FEAT_FRAME_SIZE)
+		hdr->framesz = memnic->request.framesz;
+	hdr->request = memnic->request.features;
+
 	smp_wmb();
-	nic->hdr.reset = 1;
+	hdr->reset = 1;
+
+	while (ACCESS_ONCE(hdr->reset))
+		schedule_timeout_interruptible(HZ/100);
+
 	/* clear index */
 	memnic->up = 0;
 	memnic->down = 0;
 	memnic->framesz = MEMNIC_MAX_FRAME_LEN;
-	/* will become valid after reset handling in vswitch */
+	if (memnic->request.features & MEMNIC_FEAT_FRAME_SIZE)
+		memnic->framesz = hdr->framesz;
 
 	/* already run */
 	if (memnic->kthread)
@@ -260,6 +273,26 @@ static int memnic_set_mac(struct net_device *netdev, void *p)
 
 static int memnic_change_mtu(struct net_device *netdev, int new_mtu)
 {
+	struct memnic_net *memnic = netdev_priv(netdev);
+	struct memnic_area *nic = memnic->dev->base_addr;
+	struct memnic_header *hdr = &nic->hdr;
+	uint32_t framesz = new_mtu + ETH_HLEN + VLAN_HLEN;
+
+	if (!(hdr->features & MEMNIC_FEAT_FRAME_SIZE))
+		return -ENOSYS;
+
+	/* new_mtu less than 68 might cause problem */
+	if (new_mtu < 68 || framesz > MEMNIC_MAX_JUMBO_FRAME_LEN)
+		return -EINVAL;
+
+	printk(KERN_INFO "MEMNIC: Changing MTU from %u to %u\n",
+		netdev->mtu, new_mtu);
+
+	memnic->request.features |= MEMNIC_FEAT_FRAME_SIZE;
+	memnic->request.framesz = framesz;
+
+	netdev->mtu = new_mtu;
+
 	return 0;
 }
 
@@ -298,6 +331,8 @@ struct memnic_net *memnic_net_create(struct memnic_dev *dev)
 
 	memnic->netdev = netdev;
 	memnic->dev = dev;
+	memnic->framesz = MEMNIC_MAX_FRAME_LEN;
+	memnic->request.features = 0;
 
 	netdev->netdev_ops = &memnic_netdev_ops;
 
diff --git a/linux/memnic_net.h b/linux/memnic_net.h
index 10c8eed..b6c57ab 100644
--- a/linux/memnic_net.h
+++ b/linux/memnic_net.h
@@ -44,6 +44,11 @@ struct memnic_net {
 	struct net_device_stats stats;
 	int up, down;
 	uint32_t framesz;
+	/* request to host */
+	struct {
+		uint32_t features;
+		uint32_t framesz;
+	} request;
 };
 
 struct memnic_net *memnic_net_create(struct memnic_dev *dev);
-- 
1.8.4

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-06-18 10:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-18 10:57 [dpdk-dev] [memnic PATCH v2 5/5] linux: support MTU change Hiroshi Shimamoto

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