netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: Fix test for VLAN TX checksum offload capability
@ 2008-06-13 22:38 Ben Hutchings
  2008-06-13 22:43 ` Stephen Hemminger
  2008-06-14  8:08 ` Patrick McHardy
  0 siblings, 2 replies; 6+ messages in thread
From: Ben Hutchings @ 2008-06-13 22:38 UTC (permalink / raw)
  To: David Miller; +Cc: Patrick McHardy, netdev, linux-net-drivers

Selected device feature bits can be propagated to VLAN devices, so we
can make use of TX checksum offload and TSO on VLAN-tagged packets.
However, if the physical device does not do VLAN tag insertion or
generic checksum offload then the test for TX checksum offload in
dev_queue_xmit() will see a protocol of htons(ETH_P_8021Q) and yield
false.

This splits the checksum offload test into two functions:

- can_checksum_protocol() tests a given protocol against a feature bitmask

- dev_can_checksum() first tests the skb protocol against the device
  features; if that fails and the protocol is htons(ETH_P_8021Q) then
  it tests the encapsulated protocol against the effective device
  features for VLANs

Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
---
 net/core/dev.c |   34 ++++++++++++++++++++++++++--------
 1 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index 5829630..68d8df0 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -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"
 
@@ -1362,6 +1363,29 @@ void netif_device_attach(struct net_device *dev)
 }
 EXPORT_SYMBOL(netif_device_attach);
 
+static bool can_checksum_protocol(unsigned long features, __be16 protocol)
+{
+	return ((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)));
+}
+
+static bool dev_can_checksum(struct net_device *dev, struct sk_buff *skb)
+{
+	if (can_checksum_protocol(dev->features, skb->protocol))
+		return true;
+
+	if (skb->protocol == htons(ETH_P_8021Q)) {
+		struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
+		if (can_checksum_protocol(dev->features & dev->vlan_features,
+					  veh->h_vlan_encapsulated_proto))
+			return true;
+	}
+
+	return false;
+}
 
 /*
  * Invalidate hardware checksum when packet is to be mangled, and
@@ -1640,14 +1664,8 @@ int dev_queue_xmit(struct sk_buff *skb)
 	if (skb->ip_summed == CHECKSUM_PARTIAL) {
 		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 (skb_checksum_help(skb))
-				goto out_kfree_skb;
+		if (!dev_can_checksum(dev, skb) && skb_checksum_help(skb))
+			goto out_kfree_skb;
 	}
 
 gso:

-- 
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: Fix test for VLAN TX checksum offload capability
  2008-06-13 22:38 [PATCH] net: Fix test for VLAN TX checksum offload capability Ben Hutchings
@ 2008-06-13 22:43 ` Stephen Hemminger
  2008-06-13 23:11   ` Ben Hutchings
  2008-06-14  8:08 ` Patrick McHardy
  1 sibling, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2008-06-13 22:43 UTC (permalink / raw)
  To: Ben Hutchings; +Cc: David Miller, Patrick McHardy, netdev, linux-net-drivers

On Fri, 13 Jun 2008 23:38:16 +0100
Ben Hutchings <bhutchings@solarflare.com> wrote:

> Selected device feature bits can be propagated to VLAN devices, so we
> can make use of TX checksum offload and TSO on VLAN-tagged packets.
> However, if the physical device does not do VLAN tag insertion or
> generic checksum offload then the test for TX checksum offload in
> dev_queue_xmit() will see a protocol of htons(ETH_P_8021Q) and yield
> false.

Are you sure that some hardware isn't broken and can do vlan tag
insertion or checksumming but not both?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: Fix test for VLAN TX checksum offload capability
  2008-06-13 22:43 ` Stephen Hemminger
@ 2008-06-13 23:11   ` Ben Hutchings
  2008-06-14  8:09     ` Patrick McHardy
  0 siblings, 1 reply; 6+ messages in thread
From: Ben Hutchings @ 2008-06-13 23:11 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: David Miller, Patrick McHardy, netdev, linux-net-drivers

Stephen Hemminger wrote:
> On Fri, 13 Jun 2008 23:38:16 +0100
> Ben Hutchings <bhutchings@solarflare.com> wrote:
> 
> > Selected device feature bits can be propagated to VLAN devices, so we
> > can make use of TX checksum offload and TSO on VLAN-tagged packets.
> > However, if the physical device does not do VLAN tag insertion or
> > generic checksum offload then the test for TX checksum offload in
> > dev_queue_xmit() will see a protocol of htons(ETH_P_8021Q) and yield
> > false.
> 
> Are you sure that some hardware isn't broken and can do vlan tag
> insertion or checksumming but not both?

The second test uses dev->features & dev->vlan_features, so this should
be handled correctly, unless I'm missing some subtlety.

Ben.

-- 
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: Fix test for VLAN TX checksum offload capability
  2008-06-13 22:38 [PATCH] net: Fix test for VLAN TX checksum offload capability Ben Hutchings
  2008-06-13 22:43 ` Stephen Hemminger
@ 2008-06-14  8:08 ` Patrick McHardy
  2008-06-17  0:02   ` David Miller
  1 sibling, 1 reply; 6+ messages in thread
From: Patrick McHardy @ 2008-06-14  8:08 UTC (permalink / raw)
  To: Ben Hutchings; +Cc: David Miller, netdev, linux-net-drivers

Ben Hutchings wrote:
> Selected device feature bits can be propagated to VLAN devices, so we
> can make use of TX checksum offload and TSO on VLAN-tagged packets.
> However, if the physical device does not do VLAN tag insertion or
> generic checksum offload then the test for TX checksum offload in
> dev_queue_xmit() will see a protocol of htons(ETH_P_8021Q) and yield
> false.
> 
> This splits the checksum offload test into two functions:
> 
> - can_checksum_protocol() tests a given protocol against a feature bitmask
> 
> - dev_can_checksum() first tests the skb protocol against the device
>   features; if that fails and the protocol is htons(ETH_P_8021Q) then
>   it tests the encapsulated protocol against the effective device
>   features for VLANs
> 
> Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>

Acked-by: Patrick McHardy <kaber@trash.net>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: Fix test for VLAN TX checksum offload capability
  2008-06-13 23:11   ` Ben Hutchings
@ 2008-06-14  8:09     ` Patrick McHardy
  0 siblings, 0 replies; 6+ messages in thread
From: Patrick McHardy @ 2008-06-14  8:09 UTC (permalink / raw)
  To: Ben Hutchings; +Cc: Stephen Hemminger, David Miller, netdev, linux-net-drivers

Ben Hutchings wrote:
> Stephen Hemminger wrote:
>> On Fri, 13 Jun 2008 23:38:16 +0100
>> Ben Hutchings <bhutchings@solarflare.com> wrote:
>>
>>> Selected device feature bits can be propagated to VLAN devices, so we
>>> can make use of TX checksum offload and TSO on VLAN-tagged packets.
>>> However, if the physical device does not do VLAN tag insertion or
>>> generic checksum offload then the test for TX checksum offload in
>>> dev_queue_xmit() will see a protocol of htons(ETH_P_8021Q) and yield
>>> false.
>> Are you sure that some hardware isn't broken and can do vlan tag
>> insertion or checksumming but not both?
> 
> The second test uses dev->features & dev->vlan_features, so this should
> be handled correctly, unless I'm missing some subtlety.

It looks fine to me.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: Fix test for VLAN TX checksum offload capability
  2008-06-14  8:08 ` Patrick McHardy
@ 2008-06-17  0:02   ` David Miller
  0 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2008-06-17  0:02 UTC (permalink / raw)
  To: kaber; +Cc: bhutchings, netdev, linux-net-drivers

From: Patrick McHardy <kaber@trash.net>
Date: Sat, 14 Jun 2008 10:08:52 +0200

> Ben Hutchings wrote:
> > Selected device feature bits can be propagated to VLAN devices, so we
> > can make use of TX checksum offload and TSO on VLAN-tagged packets.
> > However, if the physical device does not do VLAN tag insertion or
> > generic checksum offload then the test for TX checksum offload in
> > dev_queue_xmit() will see a protocol of htons(ETH_P_8021Q) and yield
> > false.
> > 
> > This splits the checksum offload test into two functions:
> > 
> > - can_checksum_protocol() tests a given protocol against a feature bitmask
> > 
> > - dev_can_checksum() first tests the skb protocol against the device
> >   features; if that fails and the protocol is htons(ETH_P_8021Q) then
> >   it tests the encapsulated protocol against the effective device
> >   features for VLANs
> > 
> > Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
> 
> Acked-by: Patrick McHardy <kaber@trash.net>

Applied to net-2.6, thanks everyone!

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-06-17  0:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-13 22:38 [PATCH] net: Fix test for VLAN TX checksum offload capability Ben Hutchings
2008-06-13 22:43 ` Stephen Hemminger
2008-06-13 23:11   ` Ben Hutchings
2008-06-14  8:09     ` Patrick McHardy
2008-06-14  8:08 ` Patrick McHardy
2008-06-17  0:02   ` David Miller

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).