Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 Apr 2025 16:30:56 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: 3a9ebff23e85 - main - vtnet(4): Replaced compiletime checks for ALTQ support to runtime checks
Message-ID:  <202504281630.53SGUuFp089175@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=3a9ebff23e85332542e6c35f2d394d1357e0329b

commit 3a9ebff23e85332542e6c35f2d394d1357e0329b
Author:     Bjoern Jakobsen <Bjoern.Jakobsen@lrz.de>
AuthorDate: 2025-04-28 06:27:43 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2025-04-28 16:30:36 +0000

    vtnet(4): Replaced compiletime checks for ALTQ support to runtime checks
    
    Signed-off-by: Bjoern Jakobsen <Bjoern.Jakobsen@lrz.de>
    Reviewed by: imp
    Pull Request: https://github.com/freebsd/freebsd-src/pull/1679
---
 sys/dev/virtio/network/if_vtnet.c    | 99 +++++++++++++++++-------------------
 sys/dev/virtio/network/if_vtnetvar.h |  4 --
 2 files changed, 47 insertions(+), 56 deletions(-)

diff --git a/sys/dev/virtio/network/if_vtnet.c b/sys/dev/virtio/network/if_vtnet.c
index ddc691744190..2ff9be9680b8 100644
--- a/sys/dev/virtio/network/if_vtnet.c
+++ b/sys/dev/virtio/network/if_vtnet.c
@@ -163,24 +163,24 @@ static struct mbuf *
 static int	vtnet_txq_enqueue_buf(struct vtnet_txq *, struct mbuf **,
 		    struct vtnet_tx_header *);
 static int	vtnet_txq_encap(struct vtnet_txq *, struct mbuf **, int);
-#ifdef VTNET_LEGACY_TX
+
+/* Required for ALTQ */
 static void	vtnet_start_locked(struct vtnet_txq *, if_t);
 static void	vtnet_start(if_t);
-#else
+
+/* Required for MQ */
 static int	vtnet_txq_mq_start_locked(struct vtnet_txq *, struct mbuf *);
 static int	vtnet_txq_mq_start(if_t, struct mbuf *);
 static void	vtnet_txq_tq_deferred(void *, int);
-#endif
+static void	vtnet_qflush(if_t);
+
+
 static void	vtnet_txq_start(struct vtnet_txq *);
 static void	vtnet_txq_tq_intr(void *, int);
 static int	vtnet_txq_eof(struct vtnet_txq *);
 static void	vtnet_tx_vq_intr(void *);
 static void	vtnet_tx_start_all(struct vtnet_softc *);
 
-#ifndef VTNET_LEGACY_TX
-static void	vtnet_qflush(if_t);
-#endif
-
 static int	vtnet_watchdog(struct vtnet_txq *);
 static void	vtnet_accum_stats(struct vtnet_softc *,
 		    struct vtnet_rxq_stats *, struct vtnet_txq_stats *);
@@ -656,12 +656,9 @@ vtnet_negotiate_features(struct vtnet_softc *sc)
 	if (no_csum || vtnet_tunable_int(sc, "lro_disable", vtnet_lro_disable))
 		features &= ~VTNET_LRO_FEATURES;
 
-#ifndef VTNET_LEGACY_TX
-	if (vtnet_tunable_int(sc, "mq_disable", vtnet_mq_disable))
+	/* Deactivate MQ Feature flag, if driver has ALTQ enabled, or MQ is explicitly disabled */
+	if (VTNET_ALTQ_ENABLED || vtnet_tunable_int(sc, "mq_disable", vtnet_mq_disable))
 		features &= ~VIRTIO_NET_F_MQ;
-#else
-	features &= ~VIRTIO_NET_F_MQ;
-#endif
 
 	negotiated_features = virtio_negotiate_features(dev, features);
 
@@ -879,14 +876,14 @@ vtnet_init_txq(struct vtnet_softc *sc, int id)
 	if (txq->vtntx_sg == NULL)
 		return (ENOMEM);
 
-#ifndef VTNET_LEGACY_TX
-	txq->vtntx_br = buf_ring_alloc(VTNET_DEFAULT_BUFRING_SIZE, M_DEVBUF,
-	    M_NOWAIT, &txq->vtntx_mtx);
-	if (txq->vtntx_br == NULL)
-		return (ENOMEM);
+	if (!VTNET_ALTQ_ENABLED) {
+		txq->vtntx_br = buf_ring_alloc(VTNET_DEFAULT_BUFRING_SIZE, M_DEVBUF,
+		    M_NOWAIT, &txq->vtntx_mtx);
+		if (txq->vtntx_br == NULL)
+			return (ENOMEM);
 
-	TASK_INIT(&txq->vtntx_defrtask, 0, vtnet_txq_tq_deferred, txq);
-#endif
+		TASK_INIT(&txq->vtntx_defrtask, 0, vtnet_txq_tq_deferred, txq);
+	}
 	TASK_INIT(&txq->vtntx_intrtask, 0, vtnet_txq_tq_intr, txq);
 	txq->vtntx_tq = taskqueue_create(txq->vtntx_name, M_NOWAIT,
 	    taskqueue_thread_enqueue, &txq->vtntx_tq);
@@ -957,12 +954,12 @@ vtnet_destroy_txq(struct vtnet_txq *txq)
 		txq->vtntx_sg = NULL;
 	}
 
-#ifndef VTNET_LEGACY_TX
-	if (txq->vtntx_br != NULL) {
-		buf_ring_free(txq->vtntx_br, M_DEVBUF);
-		txq->vtntx_br = NULL;
+	if (!VTNET_ALTQ_ENABLED) {
+		if (txq->vtntx_br != NULL) {
+			buf_ring_free(txq->vtntx_br, M_DEVBUF);
+			txq->vtntx_br = NULL;
+		}
 	}
-#endif
 
 	if (mtx_initialized(&txq->vtntx_mtx) != 0)
 		mtx_destroy(&txq->vtntx_mtx);
@@ -1106,15 +1103,16 @@ vtnet_setup_interface(struct vtnet_softc *sc)
 	if_setinitfn(ifp, vtnet_init);
 	if_setioctlfn(ifp, vtnet_ioctl);
 	if_setgetcounterfn(ifp, vtnet_get_counter);
-#ifndef VTNET_LEGACY_TX
-	if_settransmitfn(ifp, vtnet_txq_mq_start);
-	if_setqflushfn(ifp, vtnet_qflush);
-#else
-	struct virtqueue *vq = sc->vtnet_txqs[0].vtntx_vq;
-	if_setstartfn(ifp, vtnet_start);
-	if_setsendqlen(ifp, virtqueue_size(vq) - 1);
-	if_setsendqready(ifp);
-#endif
+
+	if (!VTNET_ALTQ_ENABLED) {
+		if_settransmitfn(ifp, vtnet_txq_mq_start);
+		if_setqflushfn(ifp, vtnet_qflush);
+	} else {
+		struct virtqueue *vq = sc->vtnet_txqs[0].vtntx_vq;
+		if_setstartfn(ifp, vtnet_start);
+		if_setsendqlen(ifp, virtqueue_size(vq) - 1);
+		if_setsendqready(ifp);
+	}
 
 	vtnet_get_macaddr(sc);
 
@@ -2627,7 +2625,6 @@ fail:
 	return (error);
 }
 
-#ifdef VTNET_LEGACY_TX
 
 static void
 vtnet_start_locked(struct vtnet_txq *txq, if_t ifp)
@@ -2693,7 +2690,6 @@ vtnet_start(if_t ifp)
 	VTNET_TXQ_UNLOCK(txq);
 }
 
-#else /* !VTNET_LEGACY_TX */
 
 static int
 vtnet_txq_mq_start_locked(struct vtnet_txq *txq, struct mbuf *m)
@@ -2804,7 +2800,6 @@ vtnet_txq_tq_deferred(void *xtxq, int pending __unused)
 	VTNET_TXQ_UNLOCK(txq);
 }
 
-#endif /* VTNET_LEGACY_TX */
 
 static void
 vtnet_txq_start(struct vtnet_txq *txq)
@@ -2815,13 +2810,14 @@ vtnet_txq_start(struct vtnet_txq *txq)
 	sc = txq->vtntx_sc;
 	ifp = sc->vtnet_ifp;
 
-#ifdef VTNET_LEGACY_TX
-	if (!if_sendq_empty(ifp))
-		vtnet_start_locked(txq, ifp);
-#else
-	if (!drbr_empty(ifp, txq->vtntx_br))
-		vtnet_txq_mq_start_locked(txq, NULL);
-#endif
+	if (!VTNET_ALTQ_ENABLED) {
+		if (!drbr_empty(ifp, txq->vtntx_br))
+			vtnet_txq_mq_start_locked(txq, NULL);
+	} else {
+		if (!if_sendq_empty(ifp))
+			vtnet_start_locked(txq, ifp);
+
+	}
 }
 
 static void
@@ -2936,7 +2932,6 @@ vtnet_tx_start_all(struct vtnet_softc *sc)
 	}
 }
 
-#ifndef VTNET_LEGACY_TX
 static void
 vtnet_qflush(if_t ifp)
 {
@@ -2958,7 +2953,6 @@ vtnet_qflush(if_t ifp)
 
 	if_qflush(ifp);
 }
-#endif
 
 static int
 vtnet_watchdog(struct vtnet_txq *txq)
@@ -3039,12 +3033,14 @@ vtnet_get_counter(if_t ifp, ift_counter cnt)
 		return (rxaccum.vrxs_ierrors);
 	case IFCOUNTER_OPACKETS:
 		return (txaccum.vtxs_opackets);
-#ifndef VTNET_LEGACY_TX
 	case IFCOUNTER_OBYTES:
-		return (txaccum.vtxs_obytes);
+		if (!VTNET_ALTQ_ENABLED)
+			return (txaccum.vtxs_obytes);
+		/* FALLTHROUGH */
 	case IFCOUNTER_OMCASTS:
-		return (txaccum.vtxs_omcasts);
-#endif
+		if (!VTNET_ALTQ_ENABLED)
+			return (txaccum.vtxs_omcasts);
+		/* FALLTHROUGH */
 	default:
 		return (if_get_counter_default(ifp, cnt));
 	}
@@ -3148,9 +3144,8 @@ vtnet_drain_taskqueues(struct vtnet_softc *sc)
 		txq = &sc->vtnet_txqs[i];
 		if (txq->vtntx_tq != NULL) {
 			taskqueue_drain(txq->vtntx_tq, &txq->vtntx_intrtask);
-#ifndef VTNET_LEGACY_TX
-			taskqueue_drain(txq->vtntx_tq, &txq->vtntx_defrtask);
-#endif
+			if (!VTNET_ALTQ_ENABLED)
+				taskqueue_drain(txq->vtntx_tq, &txq->vtntx_defrtask);
 		}
 	}
 }
diff --git a/sys/dev/virtio/network/if_vtnetvar.h b/sys/dev/virtio/network/if_vtnetvar.h
index b47b15543dce..0144b0f3232d 100644
--- a/sys/dev/virtio/network/if_vtnetvar.h
+++ b/sys/dev/virtio/network/if_vtnetvar.h
@@ -114,18 +114,14 @@ struct vtnet_txq {
 	struct vtnet_softc	*vtntx_sc;
 	struct virtqueue	*vtntx_vq;
 	struct sglist		*vtntx_sg;
-#ifndef VTNET_LEGACY_TX
 	struct buf_ring		*vtntx_br;
-#endif
 	int			 vtntx_id;
 	int			 vtntx_watchdog;
 	int			 vtntx_intr_threshold;
 	struct vtnet_txq_stats	 vtntx_stats;
 	struct taskqueue	*vtntx_tq;
 	struct task		 vtntx_intrtask;
-#ifndef VTNET_LEGACY_TX
 	struct task		 vtntx_defrtask;
-#endif
 #ifdef DEV_NETMAP
 	struct virtio_net_hdr_mrg_rxbuf vtntx_shrhdr;
 #endif  /* DEV_NETMAP */



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