svn commit: r362304 - in stable/12/sys/dev: netmap virtio/network
Vincenzo Maffione
vmaffione at FreeBSD.org
Thu Jun 18 10:03:18 UTC 2020
Author: vmaffione
Date: Thu Jun 18 10:03:17 2020
New Revision: 362304
URL: https://svnweb.freebsd.org/changeset/base/362304
Log:
MFC r362076
netmap: introduce netmap_kring_on()
This function returns NULL if the ring identified by
queue id and direction is in netmap mode. Otherwise
return the corresponding kring.
Use this function to replace vtnet_netmap_queue_on().
Modified:
stable/12/sys/dev/netmap/if_vtnet_netmap.h
stable/12/sys/dev/netmap/netmap_kern.h
stable/12/sys/dev/virtio/network/if_vtnet.c
Directory Properties:
stable/12/ (props changed)
Modified: stable/12/sys/dev/netmap/if_vtnet_netmap.h
==============================================================================
--- stable/12/sys/dev/netmap/if_vtnet_netmap.h Thu Jun 18 08:38:54 2020 (r362303)
+++ stable/12/sys/dev/netmap/if_vtnet_netmap.h Thu Jun 18 10:03:17 2020 (r362304)
@@ -33,25 +33,6 @@
#include <vm/pmap.h> /* vtophys ? */
#include <dev/netmap/netmap_kern.h>
-/*
- * Return 1 if the queue identified by 't' and 'idx' is in netmap mode.
- */
-static int
-vtnet_netmap_queue_on(struct vtnet_softc *sc, enum txrx t, int idx)
-{
- struct netmap_adapter *na = NA(sc->vtnet_ifp);
-
- if (!nm_native_on(na))
- return 0;
-
- if (t == NR_RX)
- return !!(idx < na->num_rx_rings &&
- na->rx_rings[idx]->nr_mode == NKR_NETMAP_ON);
-
- return !!(idx < na->num_tx_rings &&
- na->tx_rings[idx]->nr_mode == NKR_NETMAP_ON);
-}
-
/* Register and unregister. */
static int
vtnet_netmap_reg(struct netmap_adapter *na, int state)
Modified: stable/12/sys/dev/netmap/netmap_kern.h
==============================================================================
--- stable/12/sys/dev/netmap/netmap_kern.h Thu Jun 18 08:38:54 2020 (r362303)
+++ stable/12/sys/dev/netmap/netmap_kern.h Thu Jun 18 10:03:17 2020 (r362304)
@@ -1353,6 +1353,24 @@ nm_native_on(struct netmap_adapter *na)
return nm_netmap_on(na) && (na->na_flags & NAF_NATIVE);
}
+static inline struct netmap_kring *
+netmap_kring_on(struct netmap_adapter *na, u_int q, enum txrx t)
+{
+ struct netmap_kring *kring = NULL;
+
+ if (!nm_native_on(na))
+ return NULL;
+
+ if (t == NR_RX && q < na->num_rx_rings)
+ kring = na->rx_rings[q];
+ else if (t == NR_TX && q < na->num_tx_rings)
+ kring = na->tx_rings[q];
+ else
+ return NULL;
+
+ return (kring->nr_mode == NKR_NETMAP_ON) ? kring : NULL;
+}
+
static inline int
nm_iszombie(struct netmap_adapter *na)
{
Modified: stable/12/sys/dev/virtio/network/if_vtnet.c
==============================================================================
--- stable/12/sys/dev/virtio/network/if_vtnet.c Thu Jun 18 08:38:54 2020 (r362303)
+++ stable/12/sys/dev/virtio/network/if_vtnet.c Thu Jun 18 10:03:17 2020 (r362304)
@@ -1227,17 +1227,17 @@ vtnet_rxq_free_mbufs(struct vtnet_rxq *rxq)
struct mbuf *m;
int last;
#ifdef DEV_NETMAP
- int netmap_bufs = vtnet_netmap_queue_on(rxq->vtnrx_sc, NR_RX,
- rxq->vtnrx_id);
+ struct netmap_kring *kring = netmap_kring_on(NA(rxq->vtnrx_sc->vtnet_ifp),
+ rxq->vtnrx_id, NR_RX);
#else /* !DEV_NETMAP */
- int netmap_bufs = 0;
+ void *kring = NULL;
#endif /* !DEV_NETMAP */
vq = rxq->vtnrx_vq;
last = 0;
while ((m = virtqueue_drain(vq, &last)) != NULL) {
- if (!netmap_bufs)
+ if (kring == NULL)
m_freem(m);
}
@@ -2007,17 +2007,17 @@ vtnet_txq_free_mbufs(struct vtnet_txq *txq)
struct vtnet_tx_header *txhdr;
int last;
#ifdef DEV_NETMAP
- int netmap_bufs = vtnet_netmap_queue_on(txq->vtntx_sc, NR_TX,
- txq->vtntx_id);
+ struct netmap_kring *kring = netmap_kring_on(NA(txq->vtntx_sc->vtnet_ifp),
+ txq->vtntx_id, NR_TX);
#else /* !DEV_NETMAP */
- int netmap_bufs = 0;
+ void *kring = NULL;
#endif /* !DEV_NETMAP */
vq = txq->vtntx_vq;
last = 0;
while ((txhdr = virtqueue_drain(vq, &last)) != NULL) {
- if (!netmap_bufs) {
+ if (kring == NULL) {
m_freem(txhdr->vth_mbuf);
uma_zfree(vtnet_tx_header_zone, txhdr);
}
More information about the svn-src-stable-12
mailing list