DPDK patches and discussions
 help / color / mirror / Atom feed
From: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
To: "dev@dpdk.org" <dev@dpdk.org>
Cc: Hayato Momma <h-momma@ce.jp.nec.com>
Subject: [dpdk-dev] [memnic PATCH v2 5/5] linux: support MTU change
Date: Wed, 18 Jun 2014 10:57:15 +0000	[thread overview]
Message-ID: <7F861DC0615E0C47A872E6F3C5FCDDBD0111AFB0@BPXM14GP.gisp.nec.co.jp> (raw)

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

                 reply	other threads:[~2014-06-18 10:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=7F861DC0615E0C47A872E6F3C5FCDDBD0111AFB0@BPXM14GP.gisp.nec.co.jp \
    --to=h-shimamoto@ct.jp.nec.com \
    --cc=dev@dpdk.org \
    --cc=h-momma@ce.jp.nec.com \
    /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).