git: c50312b774e1 - releng/15.0 - vtnet: fix enabling/disabling tso

From: Colin Percival <cperciva_at_FreeBSD.org>
Date: Wed, 12 Nov 2025 18:46:30 UTC
The branch releng/15.0 has been updated by cperciva:

URL: https://cgit.FreeBSD.org/src/commit/?id=c50312b774e1f26e90d743ad7e02072738923a03

commit c50312b774e1f26e90d743ad7e02072738923a03
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2025-11-10 15:34:53 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2025-11-12 18:46:09 +0000

    vtnet: fix enabling/disabling tso
    
    Transmit segment offloading depends on transmit checksum offloading.
    Enforce that constraint. This also fixes a bug, since if_hwassist bits
    are from the CSUM_ space, not from the IFCAP_ space.
    
    Approved by:    re (cperciva)
    PR:                     290773
    Reviewed by:            Timo Völker
    Tested by:              lg@efficientip.com
    Differential Revision:  https://reviews.freebsd.org/D53629
    
    (cherry picked from commit 4c50ac68166caf7e08c5a9984d63fa91490fa50d)
    (cherry picked from commit 0fb0ba51d8bc1e6673e073c1c5a02922f997f6b8)
---
 sys/dev/virtio/network/if_vtnet.c | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/sys/dev/virtio/network/if_vtnet.c b/sys/dev/virtio/network/if_vtnet.c
index a61b0aac0bfa..d9daa5bfd70a 100644
--- a/sys/dev/virtio/network/if_vtnet.c
+++ b/sys/dev/virtio/network/if_vtnet.c
@@ -1346,20 +1346,40 @@ vtnet_ioctl_ifcap(struct vtnet_softc *sc, struct ifreq *ifr)
 	VTNET_CORE_LOCK_ASSERT(sc);
 
 	if (mask & IFCAP_TXCSUM) {
+		if (if_getcapenable(ifp) & IFCAP_TXCSUM &&
+		    if_getcapenable(ifp) & IFCAP_TSO4) {
+			/* Disable tso4, because txcsum will be disabled. */
+			if_setcapenablebit(ifp, 0, IFCAP_TSO4);
+			if_sethwassistbits(ifp, 0, CSUM_IP_TSO);
+			mask &= ~IFCAP_TSO4;
+		}
 		if_togglecapenable(ifp, IFCAP_TXCSUM);
 		if_togglehwassist(ifp, VTNET_CSUM_OFFLOAD);
 	}
 	if (mask & IFCAP_TXCSUM_IPV6) {
+		if (if_getcapenable(ifp) & IFCAP_TXCSUM_IPV6 &&
+		    if_getcapenable(ifp) & IFCAP_TSO6) {
+			/* Disable tso6, because txcsum6 will be disabled. */
+			if_setcapenablebit(ifp, 0, IFCAP_TSO6);
+			if_sethwassistbits(ifp, 0, CSUM_IP6_TSO);
+			mask &= ~IFCAP_TSO6;
+		}
 		if_togglecapenable(ifp, IFCAP_TXCSUM_IPV6);
 		if_togglehwassist(ifp, VTNET_CSUM_OFFLOAD_IPV6);
 	}
 	if (mask & IFCAP_TSO4) {
-		if_togglecapenable(ifp, IFCAP_TSO4);
-		if_togglehwassist(ifp, IFCAP_TSO4);
+		if (if_getcapenable(ifp) & (IFCAP_TXCSUM | IFCAP_TSO4)) {
+			/* tso4 can only be enabled, if txcsum is enabled. */
+			if_togglecapenable(ifp, IFCAP_TSO4);
+			if_togglehwassist(ifp, CSUM_IP_TSO);
+		}
 	}
 	if (mask & IFCAP_TSO6) {
-		if_togglecapenable(ifp, IFCAP_TSO6);
-		if_togglehwassist(ifp, IFCAP_TSO6);
+		if (if_getcapenable(ifp) & (IFCAP_TXCSUM_IPV6 | IFCAP_TSO6)) {
+			/* tso6 can only be enabled, if txcsum6 is enabled. */
+			if_togglecapenable(ifp, IFCAP_TSO6);
+			if_togglehwassist(ifp, CSUM_IP6_TSO);
+		}
 	}
 
 	if (mask & (IFCAP_RXCSUM | IFCAP_RXCSUM_IPV6 | IFCAP_LRO)) {