Hi Keir:
[LINUX] netfront: Cleanup and fix TSO/GSO/CHECKSUM conditionals
This patch tries to minimise the amount of code that is conditionally
compiled. This is desirable (and the Linux way) as it helps to prevent
people breaking code unwittingly since conditionals may hide compile
problems.
It also adds a missing conditional around the TSO ethtool operations.
This also helps the building of netfront under Linux 2.4 which
doesn't have TSO.
Signed-off-by: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
diff -r 840b9df48b6a drivers/xen/netfront/netfront.c
--- a/drivers/xen/netfront/netfront.c Tue Aug 07 09:37:41 2007 +0100
+++ b/drivers/xen/netfront/netfront.c Mon Aug 13 14:30:37 2007 +0800
@@ -99,6 +99,7 @@ static const int MODPARM_rx_flip = 0;
#if defined(NETIF_F_GSO)
#define HAVE_GSO 1
#define HAVE_TSO 1 /* TSO is a subset of GSO */
+#define HAVE_CSUM_OFFLOAD 1
static inline void dev_disable_gso_features(struct net_device *dev)
{
/* Turn off all GSO bits except ROBUST. */
@@ -106,6 +107,7 @@ static inline void dev_disable_gso_featu
dev->features |= NETIF_F_GSO_ROBUST;
}
#elif defined(NETIF_F_TSO)
+#define HAVE_GSO 0
#define HAVE_TSO 1
/* Some older kernels cannot cope with incorrect checksums,
@@ -113,7 +115,7 @@ static inline void dev_disable_gso_featu
* with the presence of NETIF_F_TSO but it appears to be a good first
* approximiation.
*/
-#define HAVE_NO_CSUM_OFFLOAD 1
+#define HAVE_CSUM_OFFLOAD 0
#define gso_size tso_size
#define gso_segs tso_segs
@@ -138,8 +140,12 @@ static inline int netif_needs_gso(struct
unlikely(skb->ip_summed != CHECKSUM_HW));
}
#else
+#define HAVE_GSO 0
+#define HAVE_TSO 0
+#define HAVE_CSUM_OFFLOAD 0
#define netif_needs_gso(dev, skb) 0
#define dev_disable_gso_features(dev) ((void)0)
+#define ethtool_op_set_tso(dev, data) (-ENOSYS)
#endif
#define GRANT_INVALID_REF 0
@@ -412,13 +418,12 @@ again:
goto abort_transaction;
}
-#ifdef HAVE_NO_CSUM_OFFLOAD
- err = xenbus_printf(xbt, dev->nodename, "feature-no-csum-offload",
"%d", 1);
+ err = xenbus_printf(xbt, dev->nodename, "feature-no-csum-offload",
+ "%d", !HAVE_CSUM_OFFLOAD);
if (err) {
message = "writing feature-no-csum-offload";
goto abort_transaction;
}
-#endif
err = xenbus_printf(xbt, dev->nodename, "feature-sg", "%d", 1);
if (err) {
@@ -426,13 +431,12 @@ again:
goto abort_transaction;
}
-#ifdef HAVE_TSO
- err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv4", "%d", 1);
+ err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv4", "%d",
+ HAVE_TSO);
if (err) {
message = "writing feature-gso-tcpv4";
goto abort_transaction;
}
-#endif
err = xenbus_transaction_end(xbt, 0);
if (err) {
@@ -983,7 +987,7 @@ static int network_start_xmit(struct sk_
tx->flags |= NETTXF_data_validated;
#endif
-#ifdef HAVE_TSO
+#if HAVE_TSO
if (skb_shinfo(skb)->gso_size) {
struct netif_extra_info *gso = (struct netif_extra_info *)
RING_GET_REQUEST(&np->tx, ++i);
@@ -1279,9 +1283,9 @@ static int xennet_set_skb_gso(struct sk_
return -EINVAL;
}
-#ifdef HAVE_TSO
+#if HAVE_TSO
skb_shinfo(skb)->gso_size = gso->u.gso.size;
-#ifdef HAVE_GSO
+#if HAVE_GSO
skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
/* Header must be checked, and gso_segs computed. */
@@ -1701,7 +1705,6 @@ static int xennet_set_sg(struct net_devi
static int xennet_set_tso(struct net_device *dev, u32 data)
{
-#ifdef HAVE_TSO
if (data) {
struct netfront_info *np = netdev_priv(dev);
int val;
@@ -1714,9 +1717,6 @@ static int xennet_set_tso(struct net_dev
}
return ethtool_op_set_tso(dev, data);
-#else
- return -ENOSYS;
-#endif
}
static void xennet_set_features(struct net_device *dev)
@@ -1734,10 +1734,8 @@ static void xennet_set_features(struct n
/* Before 2.6.9 TSO seems to be unreliable so do not enable it
* on older kernels.
*/
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,9)
- xennet_set_tso(dev, 1);
-#endif
-
+ if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,9))
+ xennet_set_tso(dev, 1);
}
static int network_connect(struct net_device *dev)
@@ -1865,8 +1863,10 @@ static struct ethtool_ops network_ethtoo
.set_tx_csum = ethtool_op_set_tx_csum,
.get_sg = ethtool_op_get_sg,
.set_sg = xennet_set_sg,
+#if HAVE_TSO
.get_tso = ethtool_op_get_tso,
.set_tso = xennet_set_tso,
+#endif
.get_link = ethtool_op_get_link,
};
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|