From nobody Mon Sep 1 22:17:58 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4cG3Cp2l0mz65Pmx; Mon, 01 Sep 2025 22:17:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cG3Cp20Fqz40c9; Mon, 01 Sep 2025 22:17:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756765078; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=N7tbfr3vPcwrikhZ4H2DJrjhT2ziL3t0SMUMQNtYPgU=; b=lOXQcXFfkOof+nwFJALe2fHD6p5jrmCGKT3oyu/rzlYAYSndZnBF/gxLBsa/fqwqdDpFOu ZmuTgzPIlJJuOrwZPYEdIA3l1GWOnR03Mccd9PiXWoaWcmRFOWMA15C4LejFsAI3WnXE9/ m97c9N0ePO/3B7riUcOXG3dqjGsaFDEJoxFEU5/Sf5SQm9mqX4RqK/iTOq/BFFLSesRISf BasxAcx/XwieM0dGS2fLnCp0RJZutJlXjAgvZkQxFXecZC3YAHttCJtgwRpG7/ZwrbSaZr 2hGNsLR09cjZG5MowjJGDcu3YDoMm6MpF7nX+JBFaVrvBANmn6i3JnvyMLxCtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756765078; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=N7tbfr3vPcwrikhZ4H2DJrjhT2ziL3t0SMUMQNtYPgU=; b=EpMzFQn48JLQ+AQ3RRcfco50sebUmdk7xfHrwe9ANtcsjyKJ93mkxCxcZPvJAoI2YSJPe4 zIH9shyHiBoak1LYGTAKiGuX7ofakqcEg86Rysb24TXJNAPBudjLcKCPhVfhWIAzd3UiyJ T1YqUoo2hucaHlrjfqsx5LzKMTfYS8LEHxiAPpmsBhp8ilzUPhrGgKElR/D7+aNQAnQxDk fv6h7tw76NJVTnnSegVmpJQPLbWdAwaQ9ziWaLGrPaVZ+lOWvtgf8c4NriYPZqzkBGJ4HM XeYNHqU+9tuSLnGU/dp5/I1qb6Q0jhykR8WypCn4ANlE2/nOaIQ9I6/XDxyyYg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1756765078; a=rsa-sha256; cv=none; b=lfjQMDV3GbiCd8kY7YZaVODN6yGvNlafhayH2e3GSrnLD67wAXPJ+SOsT82Bx8RaNtD8Nb QQpBkMUN/WEhL0lKwMn1qkYvgNLUfnH6RBKIZCY6a50VegC/qdBRaF3UF7dWK/IjT2OzTL KKtksBQN/L1ncxoWuotedccp0IaRWCNM05GC7Epd/6QrxhlOZNEEyqwlXg36arLCwIExx6 iRVibfKB6rgVyLZ//MW1EUGwJUQ/ICXW34yIx8fv34sZUK+ZLiDxIdY1Kc5S7OlC4q2Cqi EaHaQLQDSFsM9LPHIlqEmneWzpFNZjC321pbraazm1Z/JyRmt2b4l7L+G+O6EQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4cG3Cp1FhZz33t; Mon, 01 Sep 2025 22:17:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 581MHwG1033931; Mon, 1 Sep 2025 22:17:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 581MHwPo033928; Mon, 1 Sep 2025 22:17:58 GMT (envelope-from git) Date: Mon, 1 Sep 2025 22:17:58 GMT Message-Id: <202509012217.581MHwPo033928@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Michael Tuexen Subject: git: e4ea162509e4 - main - epair: add support for checksum offloading List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tuexen X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e4ea162509e400340a2bc3e755071a92f3465e2d Auto-Submitted: auto-generated The branch main has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=e4ea162509e400340a2bc3e755071a92f3465e2d commit e4ea162509e400340a2bc3e755071a92f3465e2d Author: Timo Völker AuthorDate: 2025-09-01 22:03:47 +0000 Commit: Michael Tuexen CommitDate: 2025-09-01 22:15:51 +0000 epair: add support for checksum offloading Add capabilities RXCSUM and RXCSUM6 as well as TXCSUM and TXCSUM6 for for receive and transmit checksum offloading for TCP and UDP to the epair interface and enable them by default. RXCSUM and RXCSUM6 are enabled because an epair interface may receive a packet with the csum_flag CSUM_DATA_VALID set, which is expected only if these capabilities are enabled. Since it seems not helpful to remove this flag, it is not possible to disable these capabilities. TXCSUM and TXCSUM6 are synchronized between the two epair interface ends. If enabled/disabled on one end, it will be enabled/disabled on the other end. If the sending epair interface end has TXCSUM or TXCSUM6 enabled and the receiving end is in a bridge, it is assumed that all interfaces in the bridge have that capability enabled. Otherwise the bridge would have disabled that capability on the receiving epair interface end in the bridge which would have disabled that capability on the sending epair interface end as well due to the synchronization. Reviewed by: bcr, Seyed Pouria Mousavizadeh Tehrani MFC after: 4 weeks Differential Revision: https://reviews.freebsd.org/D51639 --- share/man/man4/epair.4 | 24 +++++++++++++++++++- sys/net/if_epair.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 82 insertions(+), 3 deletions(-) diff --git a/share/man/man4/epair.4 b/share/man/man4/epair.4 index 342b15b5612a..0014836b01ea 100644 --- a/share/man/man4/epair.4 +++ b/share/man/man4/epair.4 @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd August 12, 2025 +.Dd September 2, 2025 .Dt EPAIR 4 .Os .Sh NAME @@ -108,6 +108,28 @@ As with any other Ethernet interface, can have a .Xr vlan 4 configured on top of it. +.Pp +The +.Nm +has RXCSUM and RXCSUM6 enabled because it may receive a packet where the +checksum has already been validated by a physical interface. +The +.Nm +supports TXCSUM and TXCSUM6 for TCP and UDP, but only by forwarding the order +to compute the checksum. +Thus, when using an +.Nm +interface, a TCP or UDP sender can offload checksum computation +to a physical interface. +Note that, in case the packet does not leave the host, the checksum is +unnecessary and will be ignored if offloaded. +TXCSUM and TXCSUM6 are synchronized between the +.Nm +interface pair (i.e., enabling/disabling the capability on one end +enables/disables it on the other end). +In case one end is in a bridge and the bridge disabled TXCSUM or TXCSUM6, +this avoids a sender to send packets with checksum offloading into the +bridge by using the other end. .Sh SEE ALSO .Xr ioctl 2 , .Xr altq 4 , diff --git a/sys/net/if_epair.c b/sys/net/if_epair.c index 581c2434b8fb..fbffa8f359a0 100644 --- a/sys/net/if_epair.c +++ b/sys/net/if_epair.c @@ -69,6 +69,7 @@ #include #include #include +#include #include #ifdef RSS #include @@ -434,6 +435,21 @@ epair_media_status(struct ifnet *ifp __unused, struct ifmediareq *imr) imr->ifm_active = IFM_ETHER | IFM_10G_T | IFM_FDX; } +/* + * Update ifp->if_hwassist according to the current value of ifp->if_capenable. + */ +static void +epair_caps_changed(struct ifnet *ifp) +{ + uint64_t hwassist = 0; + + if (ifp->if_capenable & IFCAP_TXCSUM) + hwassist |= CSUM_IP_TCP | CSUM_IP_UDP; + if (ifp->if_capenable & IFCAP_TXCSUM_IPV6) + hwassist |= CSUM_IP6_TCP | CSUM_IP6_UDP; + ifp->if_hwassist = hwassist; +} + static int epair_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) { @@ -461,6 +477,44 @@ epair_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) error = 0; break; + case SIOCGIFCAP: + ifr->ifr_reqcap = ifp->if_capabilities; + ifr->ifr_curcap = ifp->if_capenable; + error = 0; + break; + case SIOCSIFCAP: + /* + * Enable/disable capabilities as requested, besides + * IFCAP_RXCSUM(_IPV6), which always remain enabled. + * Incoming packets may have the mbuf flag CSUM_DATA_VALID set. + * Without IFCAP_RXCSUM(_IPV6), this flag would have to be + * removed, which does not seem helpful. + */ + ifp->if_capenable = ifr->ifr_reqcap | IFCAP_RXCSUM | + IFCAP_RXCSUM_IPV6; + epair_caps_changed(ifp); + /* + * If IFCAP_TXCSUM(_IPV6) has been changed, change it on the + * other epair interface as well. + * A bridge disables IFCAP_TXCSUM(_IPV6) when adding one epair + * interface if another interface in the bridge has it disabled. + * In that case this capability needs to be disabled on the + * other epair interface to avoid sending packets in the bridge + * that rely on this capability. + */ + sc = ifp->if_softc; + if ((ifp->if_capenable ^ sc->oifp->if_capenable) & + (IFCAP_TXCSUM | IFCAP_TXCSUM_IPV6)) { + sc->oifp->if_capenable &= + ~(IFCAP_TXCSUM | IFCAP_TXCSUM_IPV6); + sc->oifp->if_capenable |= ifp->if_capenable & + (IFCAP_TXCSUM | IFCAP_TXCSUM_IPV6); + epair_caps_changed(sc->oifp); + } + VLAN_CAPABILITIES(ifp); + error = 0; + break; + default: /* Let the common ethernet handler process this. */ error = ether_ioctl(ifp, cmd, data); @@ -572,8 +626,11 @@ epair_setup_ifp(struct epair_softc *sc, char *name, int unit) ifp->if_dname = epairname; ifp->if_dunit = unit; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; - ifp->if_capabilities = IFCAP_VLAN_MTU; - ifp->if_capenable = IFCAP_VLAN_MTU; + ifp->if_capabilities = IFCAP_VLAN_MTU | IFCAP_TXCSUM | + IFCAP_TXCSUM_IPV6 | IFCAP_RXCSUM | IFCAP_RXCSUM_IPV6; + ifp->if_capenable = IFCAP_VLAN_MTU | IFCAP_TXCSUM | + IFCAP_TXCSUM_IPV6 | IFCAP_RXCSUM | IFCAP_RXCSUM_IPV6; + epair_caps_changed(ifp); ifp->if_transmit = epair_transmit; ifp->if_qflush = epair_qflush; ifp->if_start = epair_start;