aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/netmap/netmap.c
diff options
context:
space:
mode:
authorVincenzo Maffione <vmaffione@FreeBSD.org>2019-02-12 09:07:46 +0000
committerVincenzo Maffione <vmaffione@FreeBSD.org>2019-02-12 09:07:46 +0000
commit01e8e2c2d6d31a2e328e090ab1feda3a68c0d094 (patch)
treec31a9050e739bd2a451025ca5f14a5c744aa1860 /sys/dev/netmap/netmap.c
parent845ef9bc3f13b52e6d5f21f78acf02621ca596d0 (diff)
Notes
Diffstat (limited to 'sys/dev/netmap/netmap.c')
-rw-r--r--sys/dev/netmap/netmap.c79
1 files changed, 49 insertions, 30 deletions
diff --git a/sys/dev/netmap/netmap.c b/sys/dev/netmap/netmap.c
index 52df4f408867..fc5cba2dbaca 100644
--- a/sys/dev/netmap/netmap.c
+++ b/sys/dev/netmap/netmap.c
@@ -893,7 +893,7 @@ netmap_krings_create(struct netmap_adapter *na, u_int tailroom)
kring->rtail = kring->nr_hwtail = (t == NR_TX ? ndesc - 1 : 0);
snprintf(kring->name, sizeof(kring->name) - 1, "%s %s%d", na->name,
nm_txrx2str(t), i);
- ND("ktx %s h %d c %d t %d",
+ nm_prdis("ktx %s h %d c %d t %d",
kring->name, kring->rhead, kring->rcur, kring->rtail);
mtx_init(&kring->q_lock, (t == NR_TX ? "nm_txq_lock" : "nm_rxq_lock"), NULL, MTX_DEF);
nm_os_selinfo_init(&kring->si);
@@ -946,7 +946,7 @@ netmap_hw_krings_delete(struct netmap_adapter *na)
for (i = nma_get_nrings(na, NR_RX); i < lim; i++) {
struct mbq *q = &NMR(na, NR_RX)[i]->rx_queue;
- ND("destroy sw mbq with len %d", mbq_len(q));
+ nm_prdis("destroy sw mbq with len %d", mbq_len(q));
mbq_purge(q);
mbq_safe_fini(q);
}
@@ -1167,7 +1167,7 @@ netmap_grab_packets(struct netmap_kring *kring, struct mbq *q, int force)
if ((slot->flags & NS_FORWARD) == 0 && !force)
continue;
if (slot->len < 14 || slot->len > NETMAP_BUF_SIZE(na)) {
- RD(5, "bad pkt at %d len %d", n, slot->len);
+ nm_prlim(5, "bad pkt at %d len %d", n, slot->len);
continue;
}
slot->flags &= ~NS_FORWARD; // XXX needed ?
@@ -1281,7 +1281,7 @@ netmap_txsync_to_host(struct netmap_kring *kring, int flags)
*/
mbq_init(&q);
netmap_grab_packets(kring, &q, 1 /* force */);
- ND("have %d pkts in queue", mbq_len(&q));
+ nm_prdis("have %d pkts in queue", mbq_len(&q));
kring->nr_hwcur = head;
kring->nr_hwtail = head + lim;
if (kring->nr_hwtail > lim)
@@ -1329,7 +1329,7 @@ netmap_rxsync_from_host(struct netmap_kring *kring, int flags)
struct netmap_slot *slot = &ring->slot[nm_i];
m_copydata(m, 0, len, NMB(na, slot));
- ND("nm %d len %d", nm_i, len);
+ nm_prdis("nm %d len %d", nm_i, len);
if (netmap_debug & NM_DEBUG_HOST)
nm_prinf("%s", nm_dump_buf(NMB(na, slot),len, 128, NULL));
@@ -1594,7 +1594,7 @@ netmap_unget_na(struct netmap_adapter *na, struct ifnet *ifp)
#define NM_FAIL_ON(t) do { \
if (unlikely(t)) { \
- RD(5, "%s: fail '" #t "' " \
+ nm_prlim(5, "%s: fail '" #t "' " \
"h %d c %d t %d " \
"rh %d rc %d rt %d " \
"hc %d ht %d", \
@@ -1626,7 +1626,7 @@ nm_txsync_prologue(struct netmap_kring *kring, struct netmap_ring *ring)
u_int cur = ring->cur; /* read only once */
u_int n = kring->nkr_num_slots;
- ND(5, "%s kcur %d ktail %d head %d cur %d tail %d",
+ nm_prdis(5, "%s kcur %d ktail %d head %d cur %d tail %d",
kring->name,
kring->nr_hwcur, kring->nr_hwtail,
ring->head, ring->cur, ring->tail);
@@ -1662,7 +1662,7 @@ nm_txsync_prologue(struct netmap_kring *kring, struct netmap_ring *ring)
}
}
if (ring->tail != kring->rtail) {
- RD(5, "%s tail overwritten was %d need %d", kring->name,
+ nm_prlim(5, "%s tail overwritten was %d need %d", kring->name,
ring->tail, kring->rtail);
ring->tail = kring->rtail;
}
@@ -1689,7 +1689,7 @@ nm_rxsync_prologue(struct netmap_kring *kring, struct netmap_ring *ring)
uint32_t const n = kring->nkr_num_slots;
uint32_t head, cur;
- ND(5,"%s kc %d kt %d h %d c %d t %d",
+ nm_prdis(5,"%s kc %d kt %d h %d c %d t %d",
kring->name,
kring->nr_hwcur, kring->nr_hwtail,
ring->head, ring->cur, ring->tail);
@@ -1724,7 +1724,7 @@ nm_rxsync_prologue(struct netmap_kring *kring, struct netmap_ring *ring)
}
}
if (ring->tail != kring->rtail) {
- RD(5, "%s tail overwritten was %d need %d",
+ nm_prlim(5, "%s tail overwritten was %d need %d",
kring->name,
ring->tail, kring->rtail);
ring->tail = kring->rtail;
@@ -1753,7 +1753,7 @@ netmap_ring_reinit(struct netmap_kring *kring)
int errors = 0;
// XXX KASSERT nm_kr_tryget
- RD(10, "called for %s", kring->name);
+ nm_prlim(10, "called for %s", kring->name);
// XXX probably wrong to trust userspace
kring->rhead = ring->head;
kring->rcur = ring->cur;
@@ -1769,17 +1769,17 @@ netmap_ring_reinit(struct netmap_kring *kring)
u_int idx = ring->slot[i].buf_idx;
u_int len = ring->slot[i].len;
if (idx < 2 || idx >= kring->na->na_lut.objtotal) {
- RD(5, "bad index at slot %d idx %d len %d ", i, idx, len);
+ nm_prlim(5, "bad index at slot %d idx %d len %d ", i, idx, len);
ring->slot[i].buf_idx = 0;
ring->slot[i].len = 0;
} else if (len > NETMAP_BUF_SIZE(kring->na)) {
ring->slot[i].len = 0;
- RD(5, "bad len at slot %d idx %d len %d", i, idx, len);
+ nm_prlim(5, "bad len at slot %d idx %d len %d", i, idx, len);
}
}
if (errors) {
- RD(10, "total %d errors", errors);
- RD(10, "%s reinit, cur %d -> %d tail %d -> %d",
+ nm_prlim(10, "total %d errors", errors);
+ nm_prlim(10, "%s reinit, cur %d -> %d tail %d -> %d",
kring->name,
ring->cur, kring->nr_hwcur,
ring->tail, kring->nr_hwtail);
@@ -1816,7 +1816,7 @@ netmap_interp_ringid(struct netmap_priv_d *priv, uint32_t nr_mode,
case NR_REG_NULL:
priv->np_qfirst[t] = 0;
priv->np_qlast[t] = nma_get_nrings(na, t);
- ND("ALL/PIPE: %s %d %d", nm_txrx2str(t),
+ nm_prdis("ALL/PIPE: %s %d %d", nm_txrx2str(t),
priv->np_qfirst[t], priv->np_qlast[t]);
break;
case NR_REG_SW:
@@ -1828,7 +1828,7 @@ netmap_interp_ringid(struct netmap_priv_d *priv, uint32_t nr_mode,
priv->np_qfirst[t] = (nr_mode == NR_REG_SW ?
nma_get_nrings(na, t) : 0);
priv->np_qlast[t] = netmap_all_rings(na, t);
- ND("%s: %s %d %d", nr_mode == NR_REG_SW ? "SW" : "NIC+SW",
+ nm_prdis("%s: %s %d %d", nr_mode == NR_REG_SW ? "SW" : "NIC+SW",
nm_txrx2str(t),
priv->np_qfirst[t], priv->np_qlast[t]);
break;
@@ -1844,7 +1844,7 @@ netmap_interp_ringid(struct netmap_priv_d *priv, uint32_t nr_mode,
j = 0;
priv->np_qfirst[t] = j;
priv->np_qlast[t] = j + 1;
- ND("ONE_NIC: %s %d %d", nm_txrx2str(t),
+ nm_prdis("ONE_NIC: %s %d %d", nm_txrx2str(t),
priv->np_qfirst[t], priv->np_qlast[t]);
break;
default:
@@ -1953,7 +1953,7 @@ netmap_krings_get(struct netmap_priv_d *priv)
if ((kring->nr_kflags & NKR_EXCLUSIVE) ||
(kring->users && excl))
{
- ND("ring %s busy", kring->name);
+ nm_prdis("ring %s busy", kring->name);
return EBUSY;
}
}
@@ -1988,7 +1988,7 @@ netmap_krings_put(struct netmap_priv_d *priv)
int excl = (priv->np_flags & NR_EXCLUSIVE);
enum txrx t;
- ND("%s: releasing tx [%d, %d) rx [%d, %d)",
+ nm_prdis("%s: releasing tx [%d, %d) rx [%d, %d)",
na->name,
priv->np_qfirst[NR_TX],
priv->np_qlast[NR_TX],
@@ -2253,7 +2253,7 @@ netmap_do_regif(struct netmap_priv_d *priv, struct netmap_adapter *na,
error = netmap_mem_get_lut(na->nm_mem, &na->na_lut);
if (error)
goto err_drop_mem;
- ND("lut %p bufs %u size %u", na->na_lut.lut, na->na_lut.objtotal,
+ nm_prdis("lut %p bufs %u size %u", na->na_lut.lut, na->na_lut.objtotal,
na->na_lut.objsize);
/* ring configuration may have changed, fetch from the card */
@@ -2275,7 +2275,7 @@ netmap_do_regif(struct netmap_priv_d *priv, struct netmap_adapter *na,
/* This netmap adapter is attached to an ifnet. */
unsigned mtu = nm_os_ifnet_mtu(na->ifp);
- ND("%s: mtu %d rx_buf_maxsize %d netmap_buf_size %d",
+ nm_prdis("%s: mtu %d rx_buf_maxsize %d netmap_buf_size %d",
na->name, mtu, na->rx_buf_maxsize, NETMAP_BUF_SIZE(na));
if (na->rx_buf_maxsize == 0) {
@@ -2372,7 +2372,7 @@ nm_sync_finalize(struct netmap_kring *kring)
*/
kring->ring->tail = kring->rtail = kring->nr_hwtail;
- ND(5, "%s now hwcur %d hwtail %d head %d cur %d tail %d",
+ nm_prdis(5, "%s now hwcur %d hwtail %d head %d cur %d tail %d",
kring->name, kring->nr_hwcur, kring->nr_hwtail,
kring->rhead, kring->rcur, kring->rtail);
}
@@ -3770,7 +3770,7 @@ netmap_hw_krings_create(struct netmap_adapter *na)
for (i = na->num_rx_rings; i < lim; i++) {
mbq_safe_init(&NMR(na, NR_RX)[i]->rx_queue);
}
- ND("initialized sw rx queue %d", na->num_rx_rings);
+ nm_prdis("initialized sw rx queue %d", na->num_rx_rings);
}
return ret;
}
@@ -3871,13 +3871,13 @@ netmap_transmit(struct ifnet *ifp, struct mbuf *m)
if (!netmap_generic_hwcsum) {
if (nm_os_mbuf_has_csum_offld(m)) {
- RD(1, "%s drop mbuf that needs checksum offload", na->name);
+ nm_prlim(1, "%s drop mbuf that needs checksum offload", na->name);
goto done;
}
}
if (nm_os_mbuf_has_seg_offld(m)) {
- RD(1, "%s drop mbuf that needs generic segmentation offload", na->name);
+ nm_prlim(1, "%s drop mbuf that needs generic segmentation offload", na->name);
goto done;
}
@@ -3897,11 +3897,11 @@ netmap_transmit(struct ifnet *ifp, struct mbuf *m)
if (busy < 0)
busy += kring->nkr_num_slots;
if (busy + mbq_len(q) >= kring->nkr_num_slots - 1) {
- RD(2, "%s full hwcur %d hwtail %d qlen %d", na->name,
+ nm_prlim(2, "%s full hwcur %d hwtail %d qlen %d", na->name,
kring->nr_hwcur, kring->nr_hwtail, mbq_len(q));
} else {
mbq_enqueue(q, m);
- ND(2, "%s %d bufs in queue", na->name, mbq_len(q));
+ nm_prdis(2, "%s %d bufs in queue", na->name, mbq_len(q));
/* notify outside the lock */
m = NULL;
error = 0;
@@ -3937,7 +3937,7 @@ netmap_reset(struct netmap_adapter *na, enum txrx tx, u_int n,
int new_hwofs, lim;
if (!nm_native_on(na)) {
- ND("interface not in native netmap mode");
+ nm_prdis("interface not in native netmap mode");
return NULL; /* nothing to reinitialize */
}
@@ -4079,7 +4079,7 @@ netmap_rx_irq(struct ifnet *ifp, u_int q, u_int *work_done)
return NM_IRQ_PASS;
if (na->na_flags & NAF_SKIP_INTR) {
- ND("use regular interrupt");
+ nm_prdis("use regular interrupt");
return NM_IRQ_PASS;
}
@@ -4120,6 +4120,25 @@ nm_clear_native_flags(struct netmap_adapter *na)
na->na_flags &= ~NAF_NETMAP_ON;
}
+void
+netmap_krings_mode_commit(struct netmap_adapter *na, int onoff)
+{
+ enum txrx t;
+
+ for_rx_tx(t) {
+ int i;
+
+ for (i = 0; i < netmap_real_rings(na, t); i++) {
+ struct netmap_kring *kring = NMR(na, t)[i];
+
+ if (onoff && nm_kring_pending_on(kring))
+ kring->nr_mode = NKR_NETMAP_ON;
+ else if (!onoff && nm_kring_pending_off(kring))
+ kring->nr_mode = NKR_NETMAP_OFF;
+ }
+ }
+}
+
/*
* Module loader and unloader
*