Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Jun 2014 02:45:54 +0000 (UTC)
From:      Bryan Venteicher <bryanv@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r267253 - head/sys/dev/vmware/vmxnet3
Message-ID:  <201406090245.s592jspf015201@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bryanv
Date: Mon Jun  9 02:45:53 2014
New Revision: 267253
URL: http://svnweb.freebsd.org/changeset/base/267253

Log:
  Fix TSO support on VMware Fusion
  
  Apparently for VMware Fusion (and presumably VMware Workstation/Player
  since the PR states TSO is broken there too, but I cannot test), the
  TCP header pseudo checksum calculated should only include the protocol
  (IPPROTO_TCP) value, not also the lengths as the stack does instead.
  
  VMware ESXi seems to ignore whatever value is in the TCP header checksum,
  and it is a bit surprising there is a different behavior between the
  VMware products. And it is unfortunate that on ESXi we are forced to do
  this extra bit of work.
  
  PR:		kern/185849
  MFC after:	3 days

Modified:
  head/sys/dev/vmware/vmxnet3/if_vmx.c

Modified: head/sys/dev/vmware/vmxnet3/if_vmx.c
==============================================================================
--- head/sys/dev/vmware/vmxnet3/if_vmx.c	Mon Jun  9 02:39:05 2014	(r267252)
+++ head/sys/dev/vmware/vmxnet3/if_vmx.c	Mon Jun  9 02:45:53 2014	(r267253)
@@ -57,6 +57,8 @@ __FBSDID("$FreeBSD$");
 #include <netinet/udp.h>
 #include <netinet/tcp.h>
 
+#include <machine/in_cksum.h>
+
 #include <machine/bus.h>
 #include <machine/resource.h>
 #include <sys/bus.h>
@@ -2604,6 +2606,12 @@ vmxnet3_txq_offload_ctx(struct vmxnet3_t
 {
 	struct ether_vlan_header *evh;
 	int offset;
+#if defined(INET)
+	struct ip *ip, iphdr;
+#endif
+#if defined(INET6)
+	struct ip6_hdr *ip6, ip6hdr;
+#endif
 
 	evh = mtod(m, struct ether_vlan_header *);
 	if (evh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
@@ -2617,8 +2625,7 @@ vmxnet3_txq_offload_ctx(struct vmxnet3_t
 
 	switch (*etype) {
 #if defined(INET)
-	case ETHERTYPE_IP: {
-		struct ip *ip, iphdr;
+	case ETHERTYPE_IP:
 		if (__predict_false(m->m_len < offset + sizeof(struct ip))) {
 			m_copydata(m, offset, sizeof(struct ip),
 			    (caddr_t) &iphdr);
@@ -2628,10 +2635,16 @@ vmxnet3_txq_offload_ctx(struct vmxnet3_t
 		*proto = ip->ip_p;
 		*start = offset + (ip->ip_hl << 2);
 		break;
-	}
 #endif
 #if defined(INET6)
 	case ETHERTYPE_IPV6:
+		if (__predict_false(m->m_len <
+		    offset + sizeof(struct ip6_hdr))) {
+			m_copydata(m, offset, sizeof(struct ip6_hdr),
+			    (caddr_t) &ip6hdr);
+			ip6 = &ip6hdr;
+		} else
+			ip6 = mtodo(m, offset);
 		*proto = -1;
 		*start = ip6_lasthdr(m, offset, IPPROTO_IPV6, proto);
 		/* Assert the network stack sent us a valid packet. */
@@ -2646,6 +2659,7 @@ vmxnet3_txq_offload_ctx(struct vmxnet3_t
 
 	if (m->m_pkthdr.csum_flags & CSUM_TSO) {
 		struct tcphdr *tcp, tcphdr;
+		uint16_t sum;
 
 		if (__predict_false(*proto != IPPROTO_TCP)) {
 			/* Likely failed to correctly parse the mbuf. */
@@ -2654,16 +2668,38 @@ vmxnet3_txq_offload_ctx(struct vmxnet3_t
 
 		txq->vxtxq_stats.vmtxs_tso++;
 
-		/*
-		 * For TSO, the size of the protocol header is also
-		 * included in the descriptor header size.
-		 */
+		switch (*etype) {
+#if defined(INET)
+		case ETHERTYPE_IP:
+			sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr,
+			    htons(IPPROTO_TCP));
+			break;
+#endif
+#if defined(INET6)
+		case ETHERTYPE_IPV6:
+			sum = in6_cksum_pseudo(ip6, 0, IPPROTO_TCP, 0);
+			break;
+#endif
+		default:
+			sum = 0;
+			break;
+		}
+
 		if (m->m_len < *start + sizeof(struct tcphdr)) {
-			m_copydata(m, offset, sizeof(struct tcphdr),
+			m_copyback(m, *start + offsetof(struct tcphdr, th_sum),
+			    sizeof(uint16_t), (caddr_t) &sum);
+			m_copydata(m, *start, sizeof(struct tcphdr),
 			    (caddr_t) &tcphdr);
 			tcp = &tcphdr;
-		} else
+		} else {
 			tcp = mtodo(m, *start);
+			tcp->th_sum = sum;
+		}
+
+		/*
+		 * For TSO, the size of the protocol header is also
+		 * included in the descriptor header size.
+		 */
 		*start += (tcp->th_off << 2);
 	} else
 		txq->vxtxq_stats.vmtxs_csum++;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201406090245.s592jspf015201>