Deleted Added
full compact
if_re_netmap.h (260368) if_re_netmap.h (270063)
1/*
2 * Copyright (C) 2011-2014 Luigi Rizzo. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 10 unchanged lines hidden (view full) ---

19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26/*
1/*
2 * Copyright (C) 2011-2014 Luigi Rizzo. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 10 unchanged lines hidden (view full) ---

19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26/*
27 * $FreeBSD: head/sys/dev/netmap/if_re_netmap.h 260368 2014-01-06 12:53:15Z luigi $
27 * $FreeBSD: head/sys/dev/netmap/if_re_netmap.h 270063 2014-08-16 15:00:01Z luigi $
28 *
29 * netmap support for: re
30 *
31 * For more details on netmap support please see ixgbe_netmap.h
32 */
33
34
35#include <net/netmap.h>

--- 24 unchanged lines hidden (view full) ---

60 return (ifp->if_drv_flags & IFF_DRV_RUNNING ? 0 : 1);
61}
62
63
64/*
65 * Reconcile kernel and user view of the transmit ring.
66 */
67static int
28 *
29 * netmap support for: re
30 *
31 * For more details on netmap support please see ixgbe_netmap.h
32 */
33
34
35#include <net/netmap.h>

--- 24 unchanged lines hidden (view full) ---

60 return (ifp->if_drv_flags & IFF_DRV_RUNNING ? 0 : 1);
61}
62
63
64/*
65 * Reconcile kernel and user view of the transmit ring.
66 */
67static int
68re_netmap_txsync(struct netmap_adapter *na, u_int ring_nr, int flags)
68re_netmap_txsync(struct netmap_kring *kring, int flags)
69{
69{
70 struct netmap_adapter *na = kring->na;
70 struct ifnet *ifp = na->ifp;
71 struct ifnet *ifp = na->ifp;
71 struct netmap_kring *kring = &na->tx_rings[ring_nr];
72 struct netmap_ring *ring = kring->ring;
73 u_int nm_i; /* index into the netmap ring */
74 u_int nic_i; /* index into the NIC ring */
75 u_int n;
76 u_int const lim = kring->nkr_num_slots - 1;
77 u_int const head = kring->rhead;
78
79 /* device-specific */

--- 11 unchanged lines hidden (view full) ---

91 if (nm_i != head) { /* we have new packets to send */
92 nic_i = sc->rl_ldata.rl_tx_prodidx;
93 // XXX or netmap_idx_k2n(kring, nm_i);
94
95 for (n = 0; nm_i != head; n++) {
96 struct netmap_slot *slot = &ring->slot[nm_i];
97 u_int len = slot->len;
98 uint64_t paddr;
72 struct netmap_ring *ring = kring->ring;
73 u_int nm_i; /* index into the netmap ring */
74 u_int nic_i; /* index into the NIC ring */
75 u_int n;
76 u_int const lim = kring->nkr_num_slots - 1;
77 u_int const head = kring->rhead;
78
79 /* device-specific */

--- 11 unchanged lines hidden (view full) ---

91 if (nm_i != head) { /* we have new packets to send */
92 nic_i = sc->rl_ldata.rl_tx_prodidx;
93 // XXX or netmap_idx_k2n(kring, nm_i);
94
95 for (n = 0; nm_i != head; n++) {
96 struct netmap_slot *slot = &ring->slot[nm_i];
97 u_int len = slot->len;
98 uint64_t paddr;
99 void *addr = PNMB(slot, &paddr);
99 void *addr = PNMB(na, slot, &paddr);
100
101 /* device-specific */
102 struct rl_desc *desc = &sc->rl_ldata.rl_tx_list[nic_i];
103 int cmd = slot->len | RL_TDESC_CMD_EOF |
104 RL_TDESC_CMD_OWN | RL_TDESC_CMD_SOF ;
105
100
101 /* device-specific */
102 struct rl_desc *desc = &sc->rl_ldata.rl_tx_list[nic_i];
103 int cmd = slot->len | RL_TDESC_CMD_EOF |
104 RL_TDESC_CMD_OWN | RL_TDESC_CMD_SOF ;
105
106 NM_CHECK_ADDR_LEN(addr, len);
106 NM_CHECK_ADDR_LEN(na, addr, len);
107
108 if (nic_i == lim) /* mark end of ring */
109 cmd |= RL_TDESC_CMD_EOR;
110
111 if (slot->flags & NS_BUF_CHANGED) {
112 /* buffer has changed, reload map */
113 desc->rl_bufaddr_lo = htole32(RL_ADDR_LO(paddr));
114 desc->rl_bufaddr_hi = htole32(RL_ADDR_HI(paddr));
107
108 if (nic_i == lim) /* mark end of ring */
109 cmd |= RL_TDESC_CMD_EOR;
110
111 if (slot->flags & NS_BUF_CHANGED) {
112 /* buffer has changed, reload map */
113 desc->rl_bufaddr_lo = htole32(RL_ADDR_LO(paddr));
114 desc->rl_bufaddr_hi = htole32(RL_ADDR_HI(paddr));
115 netmap_reload_map(sc->rl_ldata.rl_tx_mtag,
115 netmap_reload_map(na, sc->rl_ldata.rl_tx_mtag,
116 txd[nic_i].tx_dmamap, addr);
117 }
118 slot->flags &= ~(NS_REPORT | NS_BUF_CHANGED);
119
120 /* Fill the slot in the NIC ring. */
121 desc->rl_cmdstat = htole32(cmd);
122
123 /* make sure changes to the buffer are synced */

--- 40 unchanged lines hidden (view full) ---

164 return 0;
165}
166
167
168/*
169 * Reconcile kernel and user view of the receive ring.
170 */
171static int
116 txd[nic_i].tx_dmamap, addr);
117 }
118 slot->flags &= ~(NS_REPORT | NS_BUF_CHANGED);
119
120 /* Fill the slot in the NIC ring. */
121 desc->rl_cmdstat = htole32(cmd);
122
123 /* make sure changes to the buffer are synced */

--- 40 unchanged lines hidden (view full) ---

164 return 0;
165}
166
167
168/*
169 * Reconcile kernel and user view of the receive ring.
170 */
171static int
172re_netmap_rxsync(struct netmap_adapter *na, u_int ring_nr, int flags)
172re_netmap_rxsync(struct netmap_kring *kring, int flags)
173{
173{
174 struct netmap_adapter *na = kring->na;
174 struct ifnet *ifp = na->ifp;
175 struct ifnet *ifp = na->ifp;
175 struct netmap_kring *kring = &na->rx_rings[ring_nr];
176 struct netmap_ring *ring = kring->ring;
177 u_int nm_i; /* index into the netmap ring */
178 u_int nic_i; /* index into the NIC ring */
179 u_int n;
180 u_int const lim = kring->nkr_num_slots - 1;
181 u_int const head = nm_rxsync_prologue(kring);
182 int force_update = (flags & NAF_FORCE_READ) || kring->nr_kflags & NKR_PENDINTR;
183

--- 51 unchanged lines hidden (view full) ---

235 * Second part: skip past packets that userspace has released.
236 */
237 nm_i = kring->nr_hwcur;
238 if (nm_i != head) {
239 nic_i = netmap_idx_k2n(kring, nm_i);
240 for (n = 0; nm_i != head; n++) {
241 struct netmap_slot *slot = &ring->slot[nm_i];
242 uint64_t paddr;
176 struct netmap_ring *ring = kring->ring;
177 u_int nm_i; /* index into the netmap ring */
178 u_int nic_i; /* index into the NIC ring */
179 u_int n;
180 u_int const lim = kring->nkr_num_slots - 1;
181 u_int const head = nm_rxsync_prologue(kring);
182 int force_update = (flags & NAF_FORCE_READ) || kring->nr_kflags & NKR_PENDINTR;
183

--- 51 unchanged lines hidden (view full) ---

235 * Second part: skip past packets that userspace has released.
236 */
237 nm_i = kring->nr_hwcur;
238 if (nm_i != head) {
239 nic_i = netmap_idx_k2n(kring, nm_i);
240 for (n = 0; nm_i != head; n++) {
241 struct netmap_slot *slot = &ring->slot[nm_i];
242 uint64_t paddr;
243 void *addr = PNMB(slot, &paddr);
243 void *addr = PNMB(na, slot, &paddr);
244
245 struct rl_desc *desc = &sc->rl_ldata.rl_rx_list[nic_i];
244
245 struct rl_desc *desc = &sc->rl_ldata.rl_rx_list[nic_i];
246 int cmd = NETMAP_BUF_SIZE | RL_RDESC_CMD_OWN;
246 int cmd = NETMAP_BUF_SIZE(na) | RL_RDESC_CMD_OWN;
247
247
248 if (addr == netmap_buffer_base) /* bad buf */
248 if (addr == NETMAP_BUF_BASE(na)) /* bad buf */
249 goto ring_reset;
250
251 if (nic_i == lim) /* mark end of ring */
252 cmd |= RL_RDESC_CMD_EOR;
253
254 if (slot->flags & NS_BUF_CHANGED) {
255 /* buffer has changed, reload map */
256 desc->rl_bufaddr_lo = htole32(RL_ADDR_LO(paddr));
257 desc->rl_bufaddr_hi = htole32(RL_ADDR_HI(paddr));
249 goto ring_reset;
250
251 if (nic_i == lim) /* mark end of ring */
252 cmd |= RL_RDESC_CMD_EOR;
253
254 if (slot->flags & NS_BUF_CHANGED) {
255 /* buffer has changed, reload map */
256 desc->rl_bufaddr_lo = htole32(RL_ADDR_LO(paddr));
257 desc->rl_bufaddr_hi = htole32(RL_ADDR_HI(paddr));
258 netmap_reload_map(sc->rl_ldata.rl_rx_mtag,
258 netmap_reload_map(na, sc->rl_ldata.rl_rx_mtag,
259 rxd[nic_i].rx_dmamap, addr);
260 slot->flags &= ~NS_BUF_CHANGED;
261 }
262 desc->rl_cmdstat = htole32(cmd);
263 bus_dmamap_sync(sc->rl_ldata.rl_rx_mtag,
264 rxd[nic_i].rx_dmamap,
265 BUS_DMASYNC_PREREAD);
266 nm_i = nm_next(nm_i, lim);

--- 24 unchanged lines hidden (view full) ---

291re_netmap_tx_init(struct rl_softc *sc)
292{
293 struct rl_txdesc *txd;
294 struct rl_desc *desc;
295 int i, n;
296 struct netmap_adapter *na = NA(sc->rl_ifp);
297 struct netmap_slot *slot;
298
259 rxd[nic_i].rx_dmamap, addr);
260 slot->flags &= ~NS_BUF_CHANGED;
261 }
262 desc->rl_cmdstat = htole32(cmd);
263 bus_dmamap_sync(sc->rl_ldata.rl_rx_mtag,
264 rxd[nic_i].rx_dmamap,
265 BUS_DMASYNC_PREREAD);
266 nm_i = nm_next(nm_i, lim);

--- 24 unchanged lines hidden (view full) ---

291re_netmap_tx_init(struct rl_softc *sc)
292{
293 struct rl_txdesc *txd;
294 struct rl_desc *desc;
295 int i, n;
296 struct netmap_adapter *na = NA(sc->rl_ifp);
297 struct netmap_slot *slot;
298
299 if (!na || !(na->na_flags & NAF_NATIVE_ON)) {
300 return;
301 }
302
303 slot = netmap_reset(na, NR_TX, 0, 0);
299 slot = netmap_reset(na, NR_TX, 0, 0);
304 /* slot is NULL if we are not in netmap mode */
300 /* slot is NULL if we are not in native netmap mode */
305 if (!slot)
301 if (!slot)
306 return; // XXX cannot happen
302 return;
307 /* in netmap mode, overwrite addresses and maps */
308 txd = sc->rl_ldata.rl_tx_desc;
309 desc = sc->rl_ldata.rl_tx_list;
310 n = sc->rl_ldata.rl_tx_desc_cnt;
311
312 /* l points in the netmap ring, i points in the NIC ring */
313 for (i = 0; i < n; i++) {
314 uint64_t paddr;
315 int l = netmap_idx_n2k(&na->tx_rings[0], i);
303 /* in netmap mode, overwrite addresses and maps */
304 txd = sc->rl_ldata.rl_tx_desc;
305 desc = sc->rl_ldata.rl_tx_list;
306 n = sc->rl_ldata.rl_tx_desc_cnt;
307
308 /* l points in the netmap ring, i points in the NIC ring */
309 for (i = 0; i < n; i++) {
310 uint64_t paddr;
311 int l = netmap_idx_n2k(&na->tx_rings[0], i);
316 void *addr = PNMB(slot + l, &paddr);
312 void *addr = PNMB(na, slot + l, &paddr);
317
318 desc[i].rl_bufaddr_lo = htole32(RL_ADDR_LO(paddr));
319 desc[i].rl_bufaddr_hi = htole32(RL_ADDR_HI(paddr));
313
314 desc[i].rl_bufaddr_lo = htole32(RL_ADDR_LO(paddr));
315 desc[i].rl_bufaddr_hi = htole32(RL_ADDR_HI(paddr));
320 netmap_load_map(sc->rl_ldata.rl_tx_mtag,
316 netmap_load_map(na, sc->rl_ldata.rl_tx_mtag,
321 txd[i].tx_dmamap, addr);
322 }
323}
324
325static void
326re_netmap_rx_init(struct rl_softc *sc)
327{
328 struct netmap_adapter *na = NA(sc->rl_ifp);

--- 10 unchanged lines hidden (view full) ---

339 * and also keep one empty.
340 */
341 max_avail = n - 1 - nm_kr_rxspace(&na->rx_rings[0]);
342 for (nic_i = 0; nic_i < n; nic_i++) {
343 void *addr;
344 uint64_t paddr;
345 uint32_t nm_i = netmap_idx_n2k(&na->rx_rings[0], nic_i);
346
317 txd[i].tx_dmamap, addr);
318 }
319}
320
321static void
322re_netmap_rx_init(struct rl_softc *sc)
323{
324 struct netmap_adapter *na = NA(sc->rl_ifp);

--- 10 unchanged lines hidden (view full) ---

335 * and also keep one empty.
336 */
337 max_avail = n - 1 - nm_kr_rxspace(&na->rx_rings[0]);
338 for (nic_i = 0; nic_i < n; nic_i++) {
339 void *addr;
340 uint64_t paddr;
341 uint32_t nm_i = netmap_idx_n2k(&na->rx_rings[0], nic_i);
342
347 addr = PNMB(slot + nm_i, &paddr);
343 addr = PNMB(na, slot + nm_i, &paddr);
348
344
349 netmap_reload_map(sc->rl_ldata.rl_rx_mtag,
345 netmap_reload_map(na, sc->rl_ldata.rl_rx_mtag,
350 sc->rl_ldata.rl_rx_desc[nic_i].rx_dmamap, addr);
351 bus_dmamap_sync(sc->rl_ldata.rl_rx_mtag,
352 sc->rl_ldata.rl_rx_desc[nic_i].rx_dmamap, BUS_DMASYNC_PREREAD);
353 desc[nic_i].rl_bufaddr_lo = htole32(RL_ADDR_LO(paddr));
354 desc[nic_i].rl_bufaddr_hi = htole32(RL_ADDR_HI(paddr));
346 sc->rl_ldata.rl_rx_desc[nic_i].rx_dmamap, addr);
347 bus_dmamap_sync(sc->rl_ldata.rl_rx_mtag,
348 sc->rl_ldata.rl_rx_desc[nic_i].rx_dmamap, BUS_DMASYNC_PREREAD);
349 desc[nic_i].rl_bufaddr_lo = htole32(RL_ADDR_LO(paddr));
350 desc[nic_i].rl_bufaddr_hi = htole32(RL_ADDR_HI(paddr));
355 cmdstat = NETMAP_BUF_SIZE;
351 cmdstat = NETMAP_BUF_SIZE(na);
356 if (nic_i == n - 1) /* mark the end of ring */
357 cmdstat |= RL_RDESC_CMD_EOR;
358 if (nic_i < max_avail)
359 cmdstat |= RL_RDESC_CMD_OWN;
360 desc[nic_i].rl_cmdstat = htole32(cmdstat);
361 }
362}
363

--- 20 unchanged lines hidden ---
352 if (nic_i == n - 1) /* mark the end of ring */
353 cmdstat |= RL_RDESC_CMD_EOR;
354 if (nic_i < max_avail)
355 cmdstat |= RL_RDESC_CMD_OWN;
356 desc[nic_i].rl_cmdstat = htole32(cmdstat);
357 }
358}
359

--- 20 unchanged lines hidden ---