aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/e1000
diff options
context:
space:
mode:
authorLuigi Rizzo <luigi@FreeBSD.org>2012-02-15 23:13:29 +0000
committerLuigi Rizzo <luigi@FreeBSD.org>2012-02-15 23:13:29 +0000
commit5644ccec612ab2b8c38f1752bb75919f86970a27 (patch)
treeff5d6ba38e3c75e6316b850d0cfb7877385f0bdc /sys/dev/e1000
parenta7d022e777918b571b508b3391108a7d874b921c (diff)
(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.
Notes
Notes: svn path=/head/; revision=231796
Diffstat (limited to 'sys/dev/e1000')
-rw-r--r--sys/dev/e1000/if_em.c9
-rw-r--r--sys/dev/e1000/if_igb.c11
-rw-r--r--sys/dev/e1000/if_lem.c12
3 files changed, 9 insertions, 23 deletions
diff --git a/sys/dev/e1000/if_em.c b/sys/dev/e1000/if_em.c
index 95d8b9a3da80..9495c7948475 100644
--- a/sys/dev/e1000/if_em.c
+++ b/sys/dev/e1000/if_em.c
@@ -3296,12 +3296,10 @@ em_setup_transmit_ring(struct tx_ring *txr)
}
#ifdef DEV_NETMAP
if (slot) {
- int si = i + na->tx_rings[txr->me].nkr_hwofs;
+ int si = netmap_tidx_n2k(na, txr->me, i);
uint64_t paddr;
void *addr;
- if (si >= na->num_tx_desc)
- si -= na->num_tx_desc;
addr = PNMB(slot + si, &paddr);
txr->tx_base[i].buffer_addr = htole64(paddr);
/* reload the map for netmap mode */
@@ -4053,13 +4051,10 @@ em_setup_receive_ring(struct rx_ring *rxr)
rxbuf = &rxr->rx_buffers[j];
#ifdef DEV_NETMAP
if (slot) {
- /* slot si is mapped to the j-th NIC-ring entry */
- int si = j + na->rx_rings[0].nkr_hwofs;
+ int si = netmap_ridx_n2k(na, rxr->me, j);
uint64_t paddr;
void *addr;
- if (si > na->num_rx_desc)
- si -= na->num_rx_desc;
addr = PNMB(slot + si, &paddr);
netmap_load_map(rxr->rxtag, rxbuf->map, addr);
/* Update descriptor */
diff --git a/sys/dev/e1000/if_igb.c b/sys/dev/e1000/if_igb.c
index 2c0caa448a2c..a70b4adce937 100644
--- a/sys/dev/e1000/if_igb.c
+++ b/sys/dev/e1000/if_igb.c
@@ -3315,11 +3315,8 @@ igb_setup_transmit_ring(struct tx_ring *txr)
}
#ifdef DEV_NETMAP
if (slot) {
- /* slot si is mapped to the i-th NIC-ring entry */
- int si = i + na->tx_rings[txr->me].nkr_hwofs;
-
- if (si < 0)
- si += na->num_tx_desc;
+ int si = netmap_tidx_n2k(na, txr->me, i);
+ /* no need to set the address */
netmap_load_map(txr->txtag, txbuf->map, NMB(slot + si));
}
#endif /* DEV_NETMAP */
@@ -4060,12 +4057,10 @@ igb_setup_receive_ring(struct rx_ring *rxr)
#ifdef DEV_NETMAP
if (slot) {
/* slot sj is mapped to the i-th NIC-ring entry */
- int sj = j + na->rx_rings[rxr->me].nkr_hwofs;
+ int sj = netmap_ridx_n2k(na, rxr->me, j);
uint64_t paddr;
void *addr;
- if (sj < 0)
- sj += na->num_rx_desc;
addr = PNMB(slot + sj, &paddr);
netmap_load_map(rxr->ptag, rxbuf->pmap, addr);
/* Update descriptor */
diff --git a/sys/dev/e1000/if_lem.c b/sys/dev/e1000/if_lem.c
index 0774cb99f5cb..be4626054a53 100644
--- a/sys/dev/e1000/if_lem.c
+++ b/sys/dev/e1000/if_lem.c
@@ -2668,13 +2668,11 @@ lem_setup_transmit_structures(struct adapter *adapter)
tx_buffer->m_head = NULL;
#ifdef DEV_NETMAP
if (slot) {
- /* slot si is mapped to the i-th NIC-ring entry */
- int si = i + na->tx_rings[0].nkr_hwofs;
+ /* the i-th NIC entry goes to slot si */
+ int si = netmap_tidx_n2k(na, 0, i);
uint64_t paddr;
void *addr;
- if (si > na->num_tx_desc)
- si -= na->num_tx_desc;
addr = PNMB(slot + si, &paddr);
adapter->tx_desc_base[si].buffer_addr = htole64(paddr);
/* reload the map for netmap mode */
@@ -3244,13 +3242,11 @@ lem_setup_receive_structures(struct adapter *adapter)
for (i = 0; i < adapter->num_rx_desc; i++) {
#ifdef DEV_NETMAP
if (slot) {
- /* slot si is mapped to the i-th NIC-ring entry */
- int si = i + na->rx_rings[0].nkr_hwofs;
+ /* the i-th NIC entry goes to slot si */
+ int si = netmap_ridx_n2k(na, 0, i);
uint64_t paddr;
void *addr;
- if (si > na->num_rx_desc)
- si -= na->num_rx_desc;
addr = PNMB(slot + si, &paddr);
netmap_load_map(adapter->rxtag, rx_buffer->map, addr);
/* Update descriptor */