if_vtnet - Handle missing IFCAP_VLAN_* flags nicer. Comment IFCAP_LOR stuff. master
authorImre Vadász <imre@vdsz.com>
Tue, 17 Oct 2017 20:06:23 +0000 (22:06 +0200)
committerImre Vadász <imre@vdsz.com>
Tue, 17 Oct 2017 22:41:04 +0000 (00:41 +0200)
* The if_vtnet driver used to define the IFCAP_LRO, IFCAP_VLAN_HWFILTER and
  IFCAP_VLAN_HWTSO flags itself, to make the code from FreeBSD build.
  Instead define IFCAP_VLAN_HWFILTER and IFCAP_VLAN_HWTSO to 0, when they
  are not defined already. This allows the code to build, but all checks
  for the flags fail. (Inspired by the vmxnet3 driver port).

* The IFCAP_LRO flag is unavailable in DragonFly, but the LRO offload seems
  to work somehow.

* According to the virtio specification, LRO support should be possible
  without rx checksum support as well.

sys/dev/virtual/virtio/net/if_vtnet.c
sys/dev/virtual/virtio/net/if_vtnetvar.h

index 467e190..cf996ec 100644 (file)
@@ -485,16 +485,15 @@ vtnet_negotiate_features(struct vtnet_softc *sc)
         */
        mask |= VIRTIO_NET_F_GUEST_CSUM;
 
-        /*
-        * TSO and LRO are only available when their corresponding checksum
-        * offload feature is also negotiated.
+       /*
+        * TSO is only available when the tx checksum offload feature is also
+        * negotiated.
         */
-
        if (vtnet_csum_disable || vtnet_tso_disable)
                mask |= VIRTIO_NET_F_HOST_TSO4 | VIRTIO_NET_F_HOST_TSO6 |
                    VIRTIO_NET_F_HOST_ECN;
 
-       if (vtnet_csum_disable || vtnet_lro_disable)
+       if (vtnet_lro_disable)
                mask |= VTNET_LRO_FEATURES;
 
        features = VTNET_FEATURES & ~mask;
@@ -642,15 +641,16 @@ vtnet_setup_interface(struct vtnet_softc *sc)
                        sc->vtnet_flags |= VTNET_FLAG_TSO_ECN;
        }
 
-       if (virtio_with_feature(dev, VIRTIO_NET_F_GUEST_CSUM)) {
+       if (virtio_with_feature(dev, VIRTIO_NET_F_GUEST_CSUM))
                ifp->if_capabilities |= IFCAP_RXCSUM;
 
-               if (virtio_with_feature(dev, VIRTIO_NET_F_GUEST_TSO4) ||
-                   virtio_with_feature(dev, VIRTIO_NET_F_GUEST_TSO6))
-                       ifp->if_capabilities |= IFCAP_LRO;
-       }
+#if 0  /* IFCAP_LRO doesn't exist in DragonFly. */
+       if (virtio_with_feature(dev, VIRTIO_NET_F_GUEST_TSO4) ||
+           virtio_with_feature(dev, VIRTIO_NET_F_GUEST_TSO6))
+               ifp->if_capabilities |= IFCAP_LRO;
+#endif
 
-       if (ifp->if_capabilities & IFCAP_HWCSUM) {
+       if ((ifp->if_capabilities & IFCAP_HWCSUM) == IFCAP_HWCSUM) {
                /*
                 * VirtIO does not support VLAN tagging, but we can fake
                 * it by inserting and removing the 802.1Q header during
@@ -897,10 +897,12 @@ vtnet_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data,struct ucred *cr)
                        reinit = 1;
                }
 
+#if 0  /* IFCAP_LRO doesn't exist in DragonFly. */
                if (mask & IFCAP_LRO) {
                        ifp->if_capenable ^= IFCAP_LRO;
                        reinit = 1;
                }
+#endif
 
                if (mask & IFCAP_VLAN_HWFILTER) {
                        ifp->if_capenable ^= IFCAP_VLAN_HWFILTER;
@@ -2022,10 +2024,12 @@ vtnet_virtio_reinit(struct vtnet_softc *sc)
                        features &= ~VIRTIO_NET_F_GUEST_CSUM;
        }
 
+#if 0  /* IFCAP_LRO doesn't exist in DragonFly. */
        if (ifp->if_capabilities & IFCAP_LRO) {
                if ((ifp->if_capenable & IFCAP_LRO) == 0)
                        features &= ~VTNET_LRO_FEATURES;
        }
+#endif
 
        if (ifp->if_capabilities & IFCAP_VLAN_HWFILTER) {
                if ((ifp->if_capenable & IFCAP_VLAN_HWFILTER) == 0)
index 820b477..7b7eeef 100644 (file)
@@ -207,9 +207,22 @@ struct vtnet_mac_filter {
 #define VTNET_MIN_TX_SEGS      4
 #define VTNET_MAX_TX_SEGS      64
 
+#if 0  /* Copied from FreeBSD's net/if.h at some time, but not usable. */
 #define IFCAP_LRO               0x00400 /* can do Large Receive Offload */
 #define IFCAP_VLAN_HWFILTER     0x10000 /* interface hw can filter vlan tag */
 #define IFCAP_VLAN_HWTSO        0x40000 /* can do IFCAP_TSO on VLANs */
+#endif
+
+/*
+ * This allows lots of code to at least build, even if it's never executed
+ * at the moment.
+ */
+#ifndef IFCAP_VLAN_HWFILTER
+#define IFCAP_VLAN_HWFILTER    0
+#endif
+#ifndef IFCAP_VLAN_HWTSO
+#define IFCAP_VLAN_HWTSO       0
+#endif
 
 /*
  * Assert we can receive and transmit the maximum with regular