[dpdk-dev] [RFC PATCH 7/8] examples/vhost:support tso in vhost sample

Jijiang Liu jijiang.liu at intel.com
Mon Aug 31 11:41:47 CEST 2015


Change the vhost sample in order to support and test TSO offload.

Signed-off-by: Jijiang Liu <jijiang.liu at intel.com>
---
 examples/vhost/main.c |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 1b137b9..482f7af 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -50,6 +50,7 @@
 #include <rte_string_fns.h>
 #include <rte_malloc.h>
 #include <rte_virtio_net.h>
+#include <rte_tcp.h>
 
 #include "main.h"
 
@@ -441,6 +442,9 @@ port_init(uint8_t port)
 
 	if (port >= rte_eth_dev_count()) return -1;
 
+	if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO)
+		rte_vhost_feature_enable(1ULL << VIRTIO_NET_F_HOST_TSO4);
+
 	rx_rings = (uint16_t)dev_info.max_rx_queues;
 	/* Configure ethernet device. */
 	retval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf);
@@ -1148,6 +1152,13 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 	len = tx_q->len;
 
 	nh = rte_pktmbuf_mtod(m, struct ether_hdr *);
+	m->l2_len = sizeof(struct ether_hdr);
+	m->l3_len = sizeof(struct ipv4_hdr);
+	if (m->tso_segsz) {
+		m->l4_len = sizeof(struct tcp_hdr);
+		m->ol_flags |= PKT_TX_IP_CKSUM;
+	}
+
 	if (unlikely(nh->ether_type == rte_cpu_to_be_16(ETHER_TYPE_VLAN))) {
 		/* Guest has inserted the vlan tag. */
 		struct vlan_hdr *vh = (struct vlan_hdr *) (nh + 1);
@@ -1155,8 +1166,9 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 		if ((vm2vm_mode == VM2VM_HARDWARE) &&
 			(vh->vlan_tci != vlan_tag_be))
 			vh->vlan_tci = vlan_tag_be;
+		m->l2_len += sizeof(struct vlan_hdr); 
 	} else {
-		m->ol_flags = PKT_TX_VLAN_PKT;
+		m->ol_flags |= PKT_TX_VLAN_PKT;
 
 		/*
 		 * Find the right seg to adjust the data len when offset is
@@ -1841,10 +1853,14 @@ virtio_tx_route_zcp(struct virtio_net *dev, struct rte_mbuf *m,
 		mbuf->buf_physaddr = m->buf_physaddr;
 		mbuf->buf_addr = m->buf_addr;
 	}
-	mbuf->ol_flags = PKT_TX_VLAN_PKT;
+	mbuf->ol_flags |= PKT_TX_VLAN_PKT;
 	mbuf->vlan_tci = vlan_tag;
 	mbuf->l2_len = sizeof(struct ether_hdr);
 	mbuf->l3_len = sizeof(struct ipv4_hdr);
+	if (mbuf->tso_segsz) {
+		mbuf->l4_len = sizeof(struct tcp_hdr);
+		mbuf->ol_flags |= PKT_TX_IP_CKSUM;
+	}
 	MBUF_HEADROOM_UINT32(mbuf) = (uint32_t)desc_idx;
 
 	tx_q->m_table[len] = mbuf;
-- 
1.7.7.6



More information about the dev mailing list