Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Feb 2024 05:45:35 GMT
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 0ea4b4084845 - main - vtnet: Avoid ifdefs based on __NO_STRICT_ALIGNMENT
Message-ID:  <202402050545.4155jZ9s074024@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by imp:

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

commit 0ea4b4084845bfeedc8c692e4d34252023b78cb3
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2024-02-05 05:43:49 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-02-05 05:43:49 +0000

    vtnet: Avoid ifdefs based on __NO_STRICT_ALIGNMENT
    
    Some platforms require an adjustment of the ethernet hearders. Rather
    than make this be on __NO_STRICT_ALIGNMENT being defined, define
    VTNET_ETHER_ALIGN to be either 0 or ETHER_ALIGN (aka 2). Add a test to
    the if statements to only do them when != 0. This eliminates the #ifdef
    sprinkled in the code, still communicates the intent and gives the same
    compiled results.
    
    Sponsored by:           Netflix
    Reviewed by:            bz, bryanv
    Differential Revision:  https://reviews.freebsd.org/D43654
---
 sys/dev/virtio/network/if_vtnet.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/sys/dev/virtio/network/if_vtnet.c b/sys/dev/virtio/network/if_vtnet.c
index 3d85fee122c7..1c731b496f12 100644
--- a/sys/dev/virtio/network/if_vtnet.c
+++ b/sys/dev/virtio/network/if_vtnet.c
@@ -89,6 +89,12 @@
 #include <machine/in_cksum.h>
 #endif
 
+#ifdef __NO_STRICT_ALIGNMENT
+#define VTNET_ETHER_ALIGN 0
+#else /* Strict alignment */
+#define VTNET_ETHER_ALIGN ETHER_ALIGN
+#endif
+
 static int	vtnet_modevent(module_t, int, void *);
 
 static int	vtnet_probe(device_t);
@@ -1223,15 +1229,13 @@ vtnet_rx_cluster_size(struct vtnet_softc *sc, int mtu)
 	} else
 		framesz = sizeof(struct vtnet_rx_header);
 	framesz += sizeof(struct ether_vlan_header) + mtu;
-#ifndef __NO_STRICT_ALIGNMENT
 	/*
 	 * Account for the offsetting we'll do elsewhere so we allocate the
 	 * right size for the mtu.
 	 */
-	if (sc->vtnet_hdr_size % 4 == 0) {
-		framesz += ETHER_ALIGN;
+	if (VTNET_ETHER_ALIGN != 0 && sc->vtnet_hdr_size % 4 == 0) {
+		framesz += VTNET_ETHER_ALIGN;
 	}
-#endif
 
 	if (framesz <= MCLBYTES)
 		return (MCLBYTES);
@@ -1543,15 +1547,13 @@ vtnet_rx_alloc_buf(struct vtnet_softc *sc, int nbufs, struct mbuf **m_tailp)
 		}
 
 		m->m_len = size;
-#ifndef __NO_STRICT_ALIGNMENT
 		/*
 		 * Need to offset the mbuf if the header we're going to add
 		 * will misalign.
 		 */
-		if (sc->vtnet_hdr_size % 4 == 0) {
-			m_adj(m, ETHER_ALIGN);
+		if (VTNET_ETHER_ALIGN != 0 && sc->vtnet_hdr_size % 4 == 0) {
+			m_adj(m, VTNET_ETHER_ALIGN);
 		}
-#endif
 		if (m_head != NULL) {
 			m_tail->m_next = m;
 			m_tail = m;
@@ -1578,14 +1580,12 @@ vtnet_rxq_replace_lro_nomrg_buf(struct vtnet_rxq *rxq, struct mbuf *m0,
 
 	sc = rxq->vtnrx_sc;
 	clustersz = sc->vtnet_rx_clustersz;
-#ifndef __NO_STRICT_ALIGNMENT
 	/*
 	 * Need to offset the mbuf if the header we're going to add will
 	 * misalign, account for that here.
 	 */
-	if (sc->vtnet_hdr_size % 4 == 0)
-		clustersz -= ETHER_ALIGN;
-#endif
+	if (VTNET_ETHER_ALIGN != 0 && sc->vtnet_hdr_size % 4 == 0)
+		clustersz -= VTNET_ETHER_ALIGN;
 
 	m_prev = NULL;
 	m_tail = NULL;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202402050545.4155jZ9s074024>