git: bdf79b356216 - stable/13 - netmap: drop compatibility FreeBSD code

From: Vincenzo Maffione <vmaffione_at_FreeBSD.org>
Date: Sat, 31 Dec 2022 12:07:09 UTC
The branch stable/13 has been updated by vmaffione:

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

commit bdf79b3562169ffec05613b1ad43129182b02029
Author:     Vincenzo Maffione <vmaffione@FreeBSD.org>
AuthorDate: 2022-12-24 14:31:14 +0000
Commit:     Vincenzo Maffione <vmaffione@FreeBSD.org>
CommitDate: 2022-12-31 12:06:22 +0000

    netmap: drop compatibility FreeBSD code
    
    Netmap users on FreeBSD are not supposed to import code from the
    github netmap repository anymore. They should use the code that
    is available in the src repo. We can therefore drop the compatibility
    code.
    
    MFC after:      7 days
    
    (cherry picked from commit 3da494d3246e30a19d2107c8bb8a293ffd5a9da6)
---
 sys/dev/netmap/if_ptnet.c       |  9 -----
 sys/dev/netmap/netmap_freebsd.c | 24 +-----------
 sys/dev/netmap/netmap_generic.c |  4 --
 sys/dev/netmap/netmap_kern.h    | 81 -----------------------------------------
 4 files changed, 1 insertion(+), 117 deletions(-)

diff --git a/sys/dev/netmap/if_ptnet.c b/sys/dev/netmap/if_ptnet.c
index 99d21c38f8ab..5a85027d7197 100644
--- a/sys/dev/netmap/if_ptnet.c
+++ b/sys/dev/netmap/if_ptnet.c
@@ -93,12 +93,7 @@
 #error "INET not defined, cannot support offloadings"
 #endif
 
-#if __FreeBSD_version >= 1100000
 static uint64_t	ptnet_get_counter(if_t, ift_counter);
-#else
-typedef struct ifnet *if_t;
-#define if_getsoftc(_ifp)   (_ifp)->if_softc
-#endif
 
 //#define PTNETMAP_STATS
 //#define DEBUG
@@ -419,9 +414,7 @@ ptnet_attach(device_t dev)
 	ifp->if_flags = IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX;
 	ifp->if_init = ptnet_init;
 	ifp->if_ioctl = ptnet_ioctl;
-#if __FreeBSD_version >= 1100000
 	ifp->if_get_counter = ptnet_get_counter;
-#endif
 	ifp->if_transmit = ptnet_transmit;
 	ifp->if_qflush = ptnet_qflush;
 
@@ -1015,7 +1008,6 @@ ptnet_media_change(if_t ifp)
 	return 0;
 }
 
-#if __FreeBSD_version >= 1100000
 static uint64_t
 ptnet_get_counter(if_t ifp, ift_counter cnt)
 {
@@ -1053,7 +1045,6 @@ ptnet_get_counter(if_t ifp, ift_counter cnt)
 		return (if_get_counter_default(ifp, cnt));
 	}
 }
-#endif
 
 
 #ifdef PTNETMAP_STATS
diff --git a/sys/dev/netmap/netmap_freebsd.c b/sys/dev/netmap/netmap_freebsd.c
index 2cedea4440fe..c1e19bc1a4a5 100644
--- a/sys/dev/netmap/netmap_freebsd.c
+++ b/sys/dev/netmap/netmap_freebsd.c
@@ -211,11 +211,7 @@ nm_os_ifnet_fini(void)
 unsigned
 nm_os_ifnet_mtu(struct ifnet *ifp)
 {
-#if __FreeBSD_version < 1100030
-	return ifp->if_data.ifi_mtu;
-#else /* __FreeBSD_version >= 1100030 */
 	return ifp->if_mtu;
-#endif
 }
 
 rawsum_t
@@ -423,26 +419,10 @@ nm_os_generic_xmit_frame(struct nm_os_gen_arg *a)
 	struct ifnet *ifp = a->ifp;
 	struct mbuf *m = a->m;
 
-#if __FreeBSD_version < 1100000
-	/*
-	 * Old FreeBSD versions. The mbuf has a cluster attached,
-	 * we need to copy from the cluster to the netmap buffer.
-	 */
-	if (MBUF_REFCNT(m) != 1) {
-		nm_prerr("invalid refcnt %d for %p", MBUF_REFCNT(m), m);
-		panic("in generic_xmit_frame");
-	}
-	if (m->m_ext.ext_size < len) {
-		nm_prlim(2, "size %d < len %d", m->m_ext.ext_size, len);
-		len = m->m_ext.ext_size;
-	}
-	bcopy(a->addr, m->m_data, len);
-#else  /* __FreeBSD_version >= 1100000 */
-	/* New FreeBSD versions. Link the external storage to
+	/* Link the external storage to
 	 * the netmap buffer, so that no copy is necessary. */
 	m->m_ext.ext_buf = m->m_data = a->addr;
 	m->m_ext.ext_size = len;
-#endif /* __FreeBSD_version >= 1100000 */
 
 	m->m_flags |= M_PKTHDR;
 	m->m_len = m->m_pkthdr.len = len;
@@ -460,13 +440,11 @@ nm_os_generic_xmit_frame(struct nm_os_gen_arg *a)
 }
 
 
-#if __FreeBSD_version >= 1100005
 struct netmap_adapter *
 netmap_getna(if_t ifp)
 {
 	return (NA((struct ifnet *)ifp));
 }
-#endif /* __FreeBSD_version >= 1100005 */
 
 /*
  * The following two functions are empty until we have a generic
diff --git a/sys/dev/netmap/netmap_generic.c b/sys/dev/netmap/netmap_generic.c
index 09ba550cae92..bf582fab875d 100644
--- a/sys/dev/netmap/netmap_generic.c
+++ b/sys/dev/netmap/netmap_generic.c
@@ -482,11 +482,7 @@ generic_mbuf_destructor(struct mbuf *m)
 	 * txsync. */
 	netmap_generic_irq(na, r, NULL);
 #ifdef __FreeBSD__
-#if __FreeBSD_version <= 1200050
-	void_mbuf_dtor(m, NULL, NULL);
-#else  /* __FreeBSD_version >= 1200051 */
 	void_mbuf_dtor(m);
-#endif /* __FreeBSD_version >= 1200051 */
 #endif
 }
 
diff --git a/sys/dev/netmap/netmap_kern.h b/sys/dev/netmap/netmap_kern.h
index 848562d5d1f9..ea124a332af8 100644
--- a/sys/dev/netmap/netmap_kern.h
+++ b/sys/dev/netmap/netmap_kern.h
@@ -110,23 +110,12 @@
 #define NM_ATOMIC_TEST_AND_SET(p)       (!atomic_cmpset_acq_int((p), 0, 1))
 #define NM_ATOMIC_CLEAR(p)              atomic_store_rel_int((p), 0)
 
-#if __FreeBSD_version >= 1100030
 #define	WNA(_ifp)	(_ifp)->if_netmap
-#else /* older FreeBSD */
-#define	WNA(_ifp)	(_ifp)->if_pspare[0]
-#endif /* older FreeBSD */
 
-#if __FreeBSD_version >= 1100005
 struct netmap_adapter *netmap_getna(if_t ifp);
-#endif
 
-#if __FreeBSD_version >= 1100027
 #define MBUF_REFCNT(m)		((m)->m_ext.ext_count)
 #define SET_MBUF_REFCNT(m, x)   (m)->m_ext.ext_count = x
-#else
-#define MBUF_REFCNT(m)		((m)->m_ext.ref_cnt ? *((m)->m_ext.ref_cnt) : -1)
-#define SET_MBUF_REFCNT(m, x)   *((m)->m_ext.ref_cnt) = x
-#endif
 
 #define MBUF_QUEUED(m)		1
 
@@ -2301,69 +2290,6 @@ ptnet_sync_tail(struct nm_csb_ktoa *ktoa, struct netmap_kring *kring)
 #ifdef __FreeBSD__
 /*
  * FreeBSD mbuf allocator/deallocator in emulation mode:
- */
-#if __FreeBSD_version < 1100000
-
-/*
- * For older versions of FreeBSD:
- *
- * We allocate EXT_PACKET mbuf+clusters, but need to set M_NOFREE
- * so that the destructor, if invoked, will not free the packet.
- * In principle we should set the destructor only on demand,
- * but since there might be a race we better do it on allocation.
- * As a consequence, we also need to set the destructor or we
- * would leak buffers.
- */
-
-/* mbuf destructor, also need to change the type to EXT_EXTREF,
- * add an M_NOFREE flag, and then clear the flag and
- * chain into uma_zfree(zone_pack, mf)
- * (or reinstall the buffer ?)
- */
-#define SET_MBUF_DESTRUCTOR(m, fn)	do {		\
-	(m)->m_ext.ext_free = (void *)fn;	\
-	(m)->m_ext.ext_type = EXT_EXTREF;	\
-} while (0)
-
-static int
-void_mbuf_dtor(struct mbuf *m, void *arg1, void *arg2)
-{
-	/* restore original mbuf */
-	m->m_ext.ext_buf = m->m_data = m->m_ext.ext_arg1;
-	m->m_ext.ext_arg1 = NULL;
-	m->m_ext.ext_type = EXT_PACKET;
-	m->m_ext.ext_free = NULL;
-	if (MBUF_REFCNT(m) == 0)
-		SET_MBUF_REFCNT(m, 1);
-	uma_zfree(zone_pack, m);
-
-	return 0;
-}
-
-static inline struct mbuf *
-nm_os_get_mbuf(struct ifnet *ifp, int len)
-{
-	struct mbuf *m;
-
-	(void)ifp;
-	m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
-	if (m) {
-		/* m_getcl() (mb_ctor_mbuf) has an assert that checks that
-		 * M_NOFREE flag is not specified as third argument,
-		 * so we have to set M_NOFREE after m_getcl(). */
-		m->m_flags |= M_NOFREE;
-		m->m_ext.ext_arg1 = m->m_ext.ext_buf; // XXX save
-		m->m_ext.ext_free = (void *)void_mbuf_dtor;
-		m->m_ext.ext_type = EXT_EXTREF;
-		nm_prdis(5, "create m %p refcnt %d", m, MBUF_REFCNT(m));
-	}
-	return m;
-}
-
-#else /* __FreeBSD_version >= 1100000 */
-
-/*
- * Newer versions of FreeBSD, using a straightforward scheme.
  *
  * We allocate mbufs with m_gethdr(), since the mbuf header is needed
  * by the driver. We also attach a customly-provided external storage,
@@ -2376,13 +2302,7 @@ nm_os_get_mbuf(struct ifnet *ifp, int len)
  * has a KASSERT(), checking that the mbuf dtor function is not NULL.
  */
 
-#if __FreeBSD_version <= 1200050
-static void void_mbuf_dtor(struct mbuf *m, void *arg1, void *arg2) { }
-#else  /* __FreeBSD_version >= 1200051 */
-/* The arg1 and arg2 pointers argument were removed by r324446, which
- * in included since version 1200051. */
 static void void_mbuf_dtor(struct mbuf *m) { }
-#endif /* __FreeBSD_version >= 1200051 */
 
 #define SET_MBUF_DESTRUCTOR(m, fn)	do {		\
 	(m)->m_ext.ext_free = (fn != NULL) ?		\
@@ -2408,7 +2328,6 @@ nm_os_get_mbuf(struct ifnet *ifp, int len)
 	return m;
 }
 
-#endif /* __FreeBSD_version >= 1100000 */
 #endif /* __FreeBSD__ */
 
 struct nmreq_option * nmreq_getoption(struct nmreq_header *, uint16_t);