From 5644ccec612ab2b8c38f1752bb75919f86970a27 Mon Sep 17 00:00:00 2001 From: Luigi Rizzo Date: Wed, 15 Feb 2012 23:13:29 +0000 Subject: (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. --- sys/dev/netmap/if_igb_netmap.h | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'sys/dev/netmap/if_igb_netmap.h') diff --git a/sys/dev/netmap/if_igb_netmap.h b/sys/dev/netmap/if_igb_netmap.h index 86dd331455b6..7bea4b146a79 100644 --- a/sys/dev/netmap/if_igb_netmap.h +++ b/sys/dev/netmap/if_igb_netmap.h @@ -169,9 +169,7 @@ igb_netmap_txsync(struct ifnet *ifp, u_int ring_nr, int do_lock) u32 olinfo_status = (adapter->hw.mac.type == e1000_82575) ? (txr->me << 4) : 0; - l = j - kring->nkr_hwofs; - if (l < 0) - l += lim + 1; + l = netmap_tidx_k2n(na, ring_nr, j); while (j != k) { struct netmap_slot *slot = &ring->slot[j]; union e1000_adv_tx_desc *curr = @@ -287,9 +285,7 @@ igb_netmap_rxsync(struct ifnet *ifp, u_int ring_nr, int do_lock) * j == (l + kring->nkr_hwofs) % ring_size */ l = rxr->next_to_check; - j = l + kring->nkr_hwofs; - if (j > lim) - j -= lim + 1; + j = netmap_ridx_n2k(na, ring_nr, l); for (n = 0; ; n++) { union e1000_adv_rx_desc *curr = &rxr->rx_base[l]; uint32_t staterr = le32toh(curr->wb.upper.status_error); @@ -311,9 +307,7 @@ igb_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 = j - kring->nkr_hwofs; - if (l < 0) - l += lim + 1; + l = netmap_ridx_k2n(na, ring_nr, j); while (j != k) { struct netmap_slot *slot = ring->slot + j; union e1000_adv_rx_desc *curr = &rxr->rx_base[l]; -- cgit v1.3