diff --git a/sys/dev/netmap/if_vtnet_netmap.h b/sys/dev/netmap/if_vtnet_netmap.h index 113a85655531..fc667738a1f5 100644 --- a/sys/dev/netmap/if_vtnet_netmap.h +++ b/sys/dev/netmap/if_vtnet_netmap.h @@ -33,25 +33,6 @@ #include /* vtophys ? */ #include -/* - * 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) diff --git a/sys/dev/netmap/netmap_kern.h b/sys/dev/netmap/netmap_kern.h index 14896ebaa6a5..3786826d8e38 100644 --- a/sys/dev/netmap/netmap_kern.h +++ b/sys/dev/netmap/netmap_kern.h @@ -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) { diff --git a/sys/dev/virtio/network/if_vtnet.c b/sys/dev/virtio/network/if_vtnet.c index 570528738ee6..68fcfb4cb9db 100644 --- a/sys/dev/virtio/network/if_vtnet.c +++ b/sys/dev/virtio/network/if_vtnet.c @@ -1249,17 +1249,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); } @@ -2074,17 +2074,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); }