diff options
author | luigi <luigi@FreeBSD.org> | 2012-02-15 23:13:29 +0000 |
---|---|---|
committer | luigi <luigi@FreeBSD.org> | 2012-02-15 23:13:29 +0000 |
commit | 626117dcad75e9526ae6bc4c7b0e7d93aea9a8c1 (patch) | |
tree | ff5d6ba38e3c75e6316b850d0cfb7877385f0bdc /sys/dev/netmap/if_re_netmap.h | |
parent | c73b374c7d18d2132436080cbdf957c5bf7aba58 (diff) | |
download | FreeBSD-src-626117dcad75e9526ae6bc4c7b0e7d93aea9a8c1.zip FreeBSD-src-626117dcad75e9526ae6bc4c7b0e7d93aea9a8c1.tar.gz |
(This commit only touches code within the DEV_NETMAP blocks)
Introduce some functions to map NIC ring indexes into netmap ring
indexes and vice versa. This way we can implement the bound
checks only in one place (and hopefully in a correct way).
On passing, make the code and comments more uniform across the
various drivers.
Diffstat (limited to 'sys/dev/netmap/if_re_netmap.h')
-rw-r--r-- | sys/dev/netmap/if_re_netmap.h | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/sys/dev/netmap/if_re_netmap.h b/sys/dev/netmap/if_re_netmap.h index af8e21a..d0b8919 100644 --- a/sys/dev/netmap/if_re_netmap.h +++ b/sys/dev/netmap/if_re_netmap.h @@ -263,7 +263,7 @@ re_netmap_rxsync(struct ifnet *ifp, u_int ring_nr, int do_lock) * is to limit the amount of data reported up to 'lim' */ l = sc->rl_ldata.rl_rx_prodidx; /* next pkt to check */ - j = l + kring->nkr_hwofs; + j = netmap_ridx_n2k(na, ring_nr, l); /* the kring index */ for (n = kring->nr_hwavail; n < lim ; n++) { struct rl_desc *cur_rx = &sc->rl_ldata.rl_rx_list[l]; uint32_t rxstat = le32toh(cur_rx->rl_cmdstat); @@ -296,9 +296,7 @@ re_netmap_rxsync(struct ifnet *ifp, u_int ring_nr, int do_lock) j = kring->nr_hwcur; if (j != k) { /* userspace has read some packets. */ n = 0; - l = kring->nr_hwcur - kring->nkr_hwofs; - if (l < 0) - l += lim + 1; + l = netmap_ridx_k2n(na, ring_nr, j); /* the NIC index */ while (j != k) { struct netmap_slot *slot = ring->slot + j; struct rl_desc *desc = &sc->rl_ldata.rl_rx_list[l]; @@ -370,11 +368,7 @@ re_netmap_tx_init(struct rl_softc *sc) for (i = 0; i < n; i++) { void *addr; uint64_t paddr; - struct netmap_kring *kring = &na->tx_rings[0]; - int l = i + kring->nkr_hwofs; - - if (l >= n) - l -= n; + int l = netmap_tidx_n2k(na, 0, i); addr = PNMB(slot + l, &paddr); desc[i].rl_bufaddr_lo = htole32(RL_ADDR_LO(paddr)); @@ -391,19 +385,21 @@ re_netmap_rx_init(struct rl_softc *sc) struct netmap_slot *slot = netmap_reset(na, NR_RX, 0, 0); struct rl_desc *desc = sc->rl_ldata.rl_rx_list; uint32_t cmdstat; - int i, n; + int i, n, max_avail; if (!slot) return; n = sc->rl_ldata.rl_rx_desc_cnt; + /* + * Userspace owned hwavail packets before the reset, + * so the NIC that last hwavail descriptors of the ring + * are still owned by the driver (and keep one empty). + */ + max_avail = n - 1 - na->rx_rings[0].nr_hwavail; for (i = 0; i < n; i++) { void *addr; uint64_t paddr; - struct netmap_kring *kring = &na->rx_rings[0]; - int l = i + kring->nkr_hwofs; - - if (l >= n) - l -= n; + int l = netmap_ridx_n2k(na, 0, i); addr = PNMB(slot + l, &paddr); @@ -414,14 +410,9 @@ re_netmap_rx_init(struct rl_softc *sc) desc[i].rl_bufaddr_lo = htole32(RL_ADDR_LO(paddr)); desc[i].rl_bufaddr_hi = htole32(RL_ADDR_HI(paddr)); cmdstat = na->buff_size; - if (i == n - 1) + if (i == n - 1) /* mark the end of ring */ cmdstat |= RL_RDESC_CMD_EOR; - /* - * userspace knows that hwavail packets were ready before the - * reset, so we need to tell the NIC that last hwavail - * descriptors of the ring are still owned by the driver. - */ - if (i < n - 1 - kring->nr_hwavail) // XXX + 1 ? + if (i < max_avail) cmdstat |= RL_RDESC_CMD_OWN; desc[i].rl_cmdstat = htole32(cmdstat); } |