Skip to contentSkip to conversation

net: drivers: set TSO/UFO offload option explicitly

PATCH In review Shan Wei 3 participants 4 messages Apr 29, 2011 – May 5, 2011

Subsystems (3)
lore
Share & tools
lore

Shan Wei

author
#0 lore raw

PATCH 2/2 net: drivers: set TSO/UFO offload option explicitly

The device drivers should not use NETIF_F_ALL_TSO mask to set hw_features(or features), but have to explicitly set offload option. Because, This would make drivers automatically clain to support any new TSO feature an the moment of NETIF_F_ALL_TSO is expanded.

Some code style tuning. Just compile test.

---
 drivers/net/loopback.c   |   18 ++++++++----------
 drivers/net/virtio_net.c |    9 ++++++---
 2 files changed, 14 insertions(+), 13 deletions(-)
drivers/net/loopback.c +8 -10
index d70fb76..bfb6a4a 100644
@@ -152,6 +152,9 @@ static const struct net_device_ops loopback_ops = {
 	.ndo_get_stats64 = loopback_get_stats64,
 };
 
+#define LOOPBACK_USER_FEATURES (NETIF_F_TSO | NETIF_F_TSO_ECN | \
+				NETIF_F_TSO6 | NETIF_F_UFO)
+
 /*
  * The loopback device is special. There is only one instance
  * per network namespace.
@@ -165,16 +168,11 @@ static void loopback_setup(struct net_device *dev)
 	dev->type		= ARPHRD_LOOPBACK;	/* 0x0001*/
 	dev->flags		= IFF_LOOPBACK;
 	dev->priv_flags	       &= ~IFF_XMIT_DST_RELEASE;
-	dev->hw_features	= NETIF_F_ALL_TSO | NETIF_F_UFO;
-	dev->features 		= NETIF_F_SG | NETIF_F_FRAGLIST
-		| NETIF_F_ALL_TSO
-		| NETIF_F_UFO
-		| NETIF_F_NO_CSUM
-		| NETIF_F_RXCSUM
-		| NETIF_F_HIGHDMA
-		| NETIF_F_LLTX
-		| NETIF_F_NETNS_LOCAL
-		| NETIF_F_VLAN_CHALLENGED;
+	dev->hw_features	= LOOPBACK_USER_FEATURES;
+	dev->features		= NETIF_F_SG | NETIF_F_FRAGLIST
+		| LOOPBACK_USER_FEATURES | NETIF_F_NO_CSUM | NETIF_F_RXCSUM
+		| NETIF_F_HIGHDMA | NETIF_F_LLTX
+		| NETIF_F_NETNS_LOCAL | NETIF_F_VLAN_CHALLENGED;
 	dev->ethtool_ops	= &loopback_ethtool_ops;
 	dev->header_ops		= &eth_header_ops;
 	dev->netdev_ops		= &loopback_ops;
drivers/net/virtio_net.c +6 -3
index 0cb0b06..addde86 100644
@@ -875,6 +875,9 @@ static void virtnet_config_changed(struct virtio_device *vdev)
 	virtnet_update_status(vi);
 }
 
+#define VIRTNET_USER_FEATURES (NETIF_F_TSO | NETIF_F_TSO_ECN | \
+			       NETIF_F_TSO6 | NETIF_F_UFO)
+
 static int virtnet_probe(struct virtio_device *vdev)
 {
 	int err;
@@ -904,8 +907,7 @@ static int virtnet_probe(struct virtio_device *vdev)
 			dev->features |= NETIF_F_HW_CSUM|NETIF_F_SG|NETIF_F_FRAGLIST;
 
 		if (virtio_has_feature(vdev, VIRTIO_NET_F_GSO)) {
-			dev->hw_features |= NETIF_F_TSO | NETIF_F_UFO
-				| NETIF_F_TSO_ECN | NETIF_F_TSO6;
+			dev->hw_features |= VIRTNET_USER_FEATURES;
 		}
 		/* Individual feature bits: what can host handle? */
 		if (virtio_has_feature(vdev, VIRTIO_NET_F_HOST_TSO4))
@@ -918,7 +920,8 @@ static int virtnet_probe(struct virtio_device *vdev)
 			dev->hw_features |= NETIF_F_UFO;
 
 		if (gso)
-			dev->features |= dev->hw_features & (NETIF_F_ALL_TSO|NETIF_F_UFO);
+			dev->features |= dev->hw_features &
+					 VIRTNET_USER_FEATURES;
 		/* (!csum && gso) case will be fixed by register_netdev() */
 	}
 
Signature · 1 line
1.7.3.1
#1 lore raw

2011/4/29 Shan Wei <[email protected]>:

Quoted 45 lines

The device drivers should not use NETIF_F_ALL_TSO mask to set hw_features(or features), but have to explicitly set offload option. Because, This would make drivers automatically clain to support any new TSO feature an the moment of NETIF_F_ALL_TSO is expanded.

Some code style tuning. Just compile test.

---
 drivers/net/loopback.c   |   18 ++++++++---------- drivers/net/virtio_net.c |    9 ++++++---

 2 files changed, 14 insertions(+), 13 deletions(-)
drivers/net/loopback.c +3 -0
index d70fb76..bfb6a4a 100644
@@ -152,6 +152,9 @@ static const struct net_device_ops loopback_ops = {
        .ndo_get_stats64 = loopback_get_stats64,
  };
 
+#define LOOPBACK_USER_FEATURES (NETIF_F_TSO | NETIF_F_TSO_ECN | \
+                               NETIF_F_TSO6 | NETIF_F_UFO)
+
  /*
  * The loopback device is special. There is only one instance
  * per network namespace.
@@ -165,16 +168,11 @@ static void loopback_setup(struct net_device *dev)

       dev->type               = ARPHRD_LOOPBACK;      /* 0x0001*/ dev->flags              = IFF_LOOPBACK; dev->priv_flags        &= ~IFF_XMIT_DST_RELEASE;
-       dev->hw_features        = NETIF_F_ALL_TSO | NETIF_F_UFO;
-       dev->features           = NETIF_F_SG | NETIF_F_FRAGLIST

-               | NETIF_F_ALL_TSO
-               | NETIF_F_UFO
-               | NETIF_F_NO_CSUM
-               | NETIF_F_RXCSUM
-               | NETIF_F_HIGHDMA
-               | NETIF_F_LLTX
-               | NETIF_F_NETNS_LOCAL
-               | NETIF_F_VLAN_CHALLENGED;
+       dev->hw_features        = LOOPBACK_USER_FEATURES;
+       dev->features           = NETIF_F_SG | NETIF_F_FRAGLIST
+               | LOOPBACK_USER_FEATURES | NETIF_F_NO_CSUM | NETIF_F_RXCSUM
+               | NETIF_F_HIGHDMA | NETIF_F_LLTX
+               | NETIF_F_NETNS_LOCAL | NETIF_F_VLAN_CHALLENGED;
Quoted 3 lines

       dev->ethtool_ops        = &loopback_ethtool_ops; dev->header_ops         = &eth_header_ops; dev->netdev_ops         = &loopback_ops;

You can add NETIF_F_HIGHDMA and NETIF_F_NO_CSUM to LOOPBACK_USER_FEATURES in one go. NETIF_F_RXCSUM could match NETIF_F_NO_CSUM state (this needs ndo_fix_features callback), but this won't have much real functional impact.

Best Regards,
Michał Mirosław

author
#2 lore raw

Michał Mirosław wrote, at 05/04/2011 08:36 PM:

Quoted 46 lines

2011/4/29 Shan Wei <[email protected]>:

Quoted 45 lines

The device drivers should not use NETIF_F_ALL_TSO mask to set hw_features(or features), but have to explicitly set offload option. Because, This would make drivers automatically clain to support any new TSO feature an the moment of NETIF_F_ALL_TSO is expanded.

Some code style tuning. Just compile test.

---
 drivers/net/loopback.c   |   18 ++++++++----------
 drivers/net/virtio_net.c |    9 ++++++---
 2 files changed, 14 insertions(+), 13 deletions(-)
drivers/net/loopback.c +8 -10
index d70fb76..bfb6a4a 100644
@@ -152,6 +152,9 @@ static const struct net_device_ops loopback_ops = {
       .ndo_get_stats64 = loopback_get_stats64,
 };
 
+#define LOOPBACK_USER_FEATURES (NETIF_F_TSO | NETIF_F_TSO_ECN | \
+                               NETIF_F_TSO6 | NETIF_F_UFO)
+
 /*
 * The loopback device is special. There is only one instance
 * per network namespace.
@@ -165,16 +168,11 @@ static void loopback_setup(struct net_device *dev)
       dev->type               = ARPHRD_LOOPBACK;      /* 0x0001*/
       dev->flags              = IFF_LOOPBACK;
       dev->priv_flags        &= ~IFF_XMIT_DST_RELEASE;
-       dev->hw_features        = NETIF_F_ALL_TSO | NETIF_F_UFO;
-       dev->features           = NETIF_F_SG | NETIF_F_FRAGLIST
-               | NETIF_F_ALL_TSO
-               | NETIF_F_UFO
-               | NETIF_F_NO_CSUM
-               | NETIF_F_RXCSUM
-               | NETIF_F_HIGHDMA
-               | NETIF_F_LLTX
-               | NETIF_F_NETNS_LOCAL
-               | NETIF_F_VLAN_CHALLENGED;
+       dev->hw_features        = LOOPBACK_USER_FEATURES;
+       dev->features           = NETIF_F_SG | NETIF_F_FRAGLIST
+               | LOOPBACK_USER_FEATURES | NETIF_F_NO_CSUM | NETIF_F_RXCSUM
+               | NETIF_F_HIGHDMA | NETIF_F_LLTX
+               | NETIF_F_NETNS_LOCAL | NETIF_F_VLAN_CHALLENGED;
Quoted 8 lines

drivers/net/loopback.c static void loopback_setup(struct net_device *dev) · line 178

Quoted 3 lines
drivers/net/loopback.c +0 -0
       dev->ethtool_ops        = &loopback_ethtool_ops;
       dev->header_ops         = &eth_header_ops;
       dev->netdev_ops         = &loopback_ops;

You can add NETIF_F_HIGHDMA and NETIF_F_NO_CSUM to LOOPBACK_USER_FEATURES in one go. NETIF_F_RXCSUM could match NETIF_F_NO_CSUM state (this needs ndo_fix_features callback), but this won't have much real functional impact.

Do you mean that defining LOOPBACK_USER_FEATURES as:
#define LOOPBACK_USER_FEATURES (NETIF_F_TSO | NETIF_F_TSO_ECN | \
NETIF_F_TSO6 | NETIF_F_UFO | NETIF_F_HIGHDMA | NETIF_F_NO_CSUM)

Is it necessary to add NETIF_F_NO_CSUM to hw_features?
After that, user can change TX hw csum offload(NETIF_F_NO_CSUM is disabled). But, this is not surportted before.

Signature · 3 lines
Best Regards
-----
Shan Wei
maintainer
#3 lore raw
In reply to Shan Wei

From: Shan Wei <[email protected]>
Date: Fri, 29 Apr 2011 13:34:45 +0800

Quoted 7 lines

The device drivers should not use NETIF_F_ALL_TSO mask to set hw_features(or features), but have to explicitly set offload option. Because, This would make drivers automatically clain to support any new TSO feature an the moment of NETIF_F_ALL_TSO is expanded.

Some code style tuning. Just compile test.

But loopback is special. It can support anything the kernel stack can emit.

So for loopback, using NETIF_F_ALL_TSO is in fact appropriate.