Skip to contentSkip to conversation

TSO for VLAN devices without VLAN tag insertion

RFC PATCH In review Ben Hutchings 2 participants 2 messages Jun 10, 2008 – Jun 12, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 TSO for VLAN devices without VLAN tag insertion

The SFC4000 controller can set IP header, TCP and UDP checksums in IPv4 packets, with or without VLAN encapsulation. However it does not do VLAN tag insertion.

When I try to make TSO work for VLAN devices via the new vlan_features, dev_queue_xmit() finds skb->ip_summed == CHECKSUM_PARTIAL && skb->protocol == htons(ETH_P_8021Q) and calls skb_checksum_help(), which sets skb->ip_summed = CHECKSUM_NONE.

This causes netif_needs_gso() to return true when called by dev_hard_start_xmit(), and GSO then does its worst.

Below is a patch which worked for me, but I'm not sure whether it's the best way to fix the problem (so I'm not submitting or signing it off yet).

Ben.

net/core/dev.c +16 -5
@@ -119,6 +119,7 @@
 #include <linux/err.h>
 #include <linux/ctype.h>
 #include <linux/if_arp.h>
+#include <linux/if_vlan.h>
 
 #include "net-sysfs.h"
 
@@ -1638,14 +1639,24 @@ int dev_queue_xmit(struct sk_buff *skb)
 	 * checksumming for this protocol, complete checksumming here.
 	 */
 	if (skb->ip_summed == CHECKSUM_PARTIAL) {
+		unsigned long features = dev->features;
+		__be16 protocol = skb->protocol;
+
+		if (protocol == htons(ETH_P_8021Q)) {
+			struct vlan_ethhdr *veh =
+				(struct vlan_ethhdr *)skb->data;
+			features &= dev->vlan_features;
+			protocol = veh->h_vlan_encapsulated_proto;
+		}
+
 		skb_set_transport_header(skb, skb->csum_start -
 					      skb_headroom(skb));
 
-		if (!(dev->features & NETIF_F_GEN_CSUM) &&
-		    !((dev->features & NETIF_F_IP_CSUM) &&
-		      skb->protocol == htons(ETH_P_IP)) &&
-		    !((dev->features & NETIF_F_IPV6_CSUM) &&
-		      skb->protocol == htons(ETH_P_IPV6)))
+		if (!(features & NETIF_F_GEN_CSUM) &&
+		    !((features & NETIF_F_IP_CSUM) &&
+		      protocol == htons(ETH_P_IP)) &&
+		    !((features & NETIF_F_IPV6_CSUM) &&
+		      protocol == htons(ETH_P_IPV6)))
 			if (skb_checksum_help(skb))
 				goto out_kfree_skb;
 	}
Signature · 2 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
#1 lore raw
Quoted 9 lines · Ben Hutchings

The SFC4000 controller can set IP header, TCP and UDP checksums in IPv4 packets, with or without VLAN encapsulation. However it does not do VLAN tag insertion.

When I try to make TSO work for VLAN devices via the new vlan_features, dev_queue_xmit() finds skb->ip_summed == CHECKSUM_PARTIAL && skb->protocol == htons(ETH_P_8021Q) and calls skb_checksum_help(), which sets skb->ip_summed = CHECKSUM_NONE.

Quoted 5 lines

This causes netif_needs_gso() to return true when called by dev_hard_start_xmit(), and GSO then does its worst.

Below is a patch which worked for me, but I'm not sure whether it's the best way to fix the problem (so I'm not submitting or signing it off yet).

It looks reasonable - I can't think of a different way to handle this case, although its a bit unfortunate that we have to put this in dev_queue_xmit().