From bb50bb45f5f650873b202e644bfcd9f2992cdace Mon Sep 17 00:00:00 2001 From: Timo Völker Date: Thu, 27 Aug 2026 05:09:55 +0200 Subject: vtnet: move offload functions to virtio_net.h Move the functions vtnet_rxq_csum() and vtnet_txq_offload() and the subfunctions they call from if_vtnet.c to virtio_net.h. This allows us to call these functions from if_tuntap.c and if_ptnet.c. virtio_net.h already contained a copy of these functions, but a copy of an outdated version. The functions evolved in if_vtnet.c. In if_vtnet.c, the copy has never been used because it increments counters in their own functions. This patch removes the outdated copy from virtio_net.h and moves the new version of the functions from if_vtnet.c to virtio_net.h. if_tuntap.c, if_ptnet.c, and if_vtnet.c just call these functions, and if_vtnet.c increments its counters depending on the return value. Reviewed by: tuexen MFC after: 1 month MFC to: stable/15 Differential Revision: https://reviews.freebsd.org/D57299 --- sys/dev/netmap/if_ptnet.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'sys/dev/netmap') diff --git a/sys/dev/netmap/if_ptnet.c b/sys/dev/netmap/if_ptnet.c index 9c06f7fec530..660b1930aa76 100644 --- a/sys/dev/netmap/if_ptnet.c +++ b/sys/dev/netmap/if_ptnet.c @@ -1464,8 +1464,17 @@ ptnet_drain_transmit_queue(struct ptnet_queue *pq, unsigned int budget, * two 8-bytes-wide writes. */ memset(nmbuf, 0, PTNET_HDR_SIZE); if (mhead->m_pkthdr.csum_flags & PTNET_ALL_OFFLOAD) { - mhead = virtio_net_tx_offload(ifp, mhead, false, - vh); + /* + * Translate the CSUM_* flags in the mbuf to the + * corresponding flags in the VirtIO header. + * + * ptnet does not negotiate ECN and orders the + * bytes in the VirtIO header as if the VirtIO + * modern mode is not used. So, pass false for + * both. + */ + virtio_net_tx_offload(ifp, &mhead, vh, false, + false); if (unlikely(!mhead)) { /* Packet dropped because errors * occurred while preparing the vnet @@ -1842,7 +1851,14 @@ host_sync: } } - if (unlikely(have_vnet_hdr && virtio_net_rx_csum(mhead, vh))) { + /* + * Translate the VirtIO header flags to the corresponding + * CSUM_* flags in the mbuf. + */ + if (unlikely(have_vnet_hdr && + ((vh->flags & (VIRTIO_NET_HDR_F_NEEDS_CSUM | + VIRTIO_NET_HDR_F_DATA_VALID)) != 0) && + (virtio_net_rx_csum(mhead, vh) != 0))) { m_freem(mhead); nm_prlim(1, "Csum offload error: dropping"); pq->stats.iqdrops ++; -- cgit v1.3