[dpdk-dev] [memnic PATCH 4/5] linux: prepare to support variable frame size

Hiroshi Shimamoto h-shimamoto at ct.jp.nec.com
Fri Jun 6 13:07:15 CEST 2014


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

Add framesz field in memnic data structure, and initialized with the current
frame size.
Replace length check on TX/RX with the above frame size.

Signed-off-by: Hiroshi Shimamoto <h-shimamoto at ct.jp.nec.com>
Reviewed-by: Hayato Momma <h-momma at ce.jp.nec.com>
---
 linux/memnic_net.c | 7 +++++--
 linux/memnic_net.h | 1 +
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/linux/memnic_net.c b/linux/memnic_net.c
index a1b433a..02b5acc 100644
--- a/linux/memnic_net.c
+++ b/linux/memnic_net.c
@@ -46,6 +46,7 @@ static struct sk_buff *memnic_rx(struct memnic_net *memnic)
 	struct sk_buff *skb;
 	struct memnic_packet *p;
 	int idx, len;
+	uint32_t framesz = memnic->framesz;
 
 	idx = ACCESS_ONCE(memnic->up);
 	p = &up->packets[idx];
@@ -54,7 +55,7 @@ static struct sk_buff *memnic_rx(struct memnic_net *memnic)
 		return ERR_PTR(-ENOENT);
 
 	len = p->len;
-	if (len > MEMNIC_MAX_FRAME_LEN) {
+	if (len > framesz) {
 		p->status = MEMNIC_PKT_ST_FREE;
 		memnic->stats.rx_errors++;
 		skb = ERR_PTR(-EINVAL);
@@ -162,6 +163,7 @@ static int memnic_open(struct net_device *netdev)
 	/* clear index */
 	memnic->up = 0;
 	memnic->down = 0;
+	memnic->framesz = MEMNIC_MAX_FRAME_LEN;
 	/* will become valid after reset handling in vswitch */
 
 	/* already run */
@@ -196,12 +198,13 @@ static netdev_tx_t memnic_start_xmit(struct sk_buff *skb,
 	struct memnic_data *down = &nic->down;
 	struct memnic_packet *p;
 	int idx, old, len;
+	uint32_t framesz = memnic->framesz;
 
 	if (!(nic->hdr.valid))
 		goto drop;
 
 	len = skb->len;
-	if (len > MEMNIC_MAX_FRAME_LEN)
+	if (len > framesz)
 		goto drop;
 retry:
 	idx = ACCESS_ONCE(memnic->down);
diff --git a/linux/memnic_net.h b/linux/memnic_net.h
index 761ed0a..10c8eed 100644
--- a/linux/memnic_net.h
+++ b/linux/memnic_net.h
@@ -43,6 +43,7 @@ struct memnic_net {
 	struct task_struct *kthread;
 	struct net_device_stats stats;
 	int up, down;
+	uint32_t framesz;
 };
 
 struct memnic_net *memnic_net_create(struct memnic_dev *dev);
-- 
1.8.4



More information about the dev mailing list