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(). MFC after: 1 week
This commit is contained in:
parent
e09fb42a9a
commit
6682323732
@ -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)
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user