1718cf2ccSPedro F. Giffuni /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni *
417885a7bSLuigi Rizzo * Copyright (C) 2011-2014 Luigi Rizzo. All rights reserved.
568b8534bSLuigi Rizzo *
668b8534bSLuigi Rizzo * Redistribution and use in source and binary forms, with or without
768b8534bSLuigi Rizzo * modification, are permitted provided that the following conditions
868b8534bSLuigi Rizzo * are met:
968b8534bSLuigi Rizzo * 1. Redistributions of source code must retain the above copyright
1068b8534bSLuigi Rizzo * notice, this list of conditions and the following disclaimer.
1168b8534bSLuigi Rizzo * 2. Redistributions in binary form must reproduce the above copyright
1268b8534bSLuigi Rizzo * notice, this list of conditions and the following disclaimer in the
1368b8534bSLuigi Rizzo * documentation and/or other materials provided with the distribution.
1468b8534bSLuigi Rizzo *
1568b8534bSLuigi Rizzo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1668b8534bSLuigi Rizzo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1768b8534bSLuigi Rizzo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1868b8534bSLuigi Rizzo * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1968b8534bSLuigi Rizzo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2068b8534bSLuigi Rizzo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2168b8534bSLuigi Rizzo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2268b8534bSLuigi Rizzo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2368b8534bSLuigi Rizzo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2468b8534bSLuigi Rizzo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2568b8534bSLuigi Rizzo * SUCH DAMAGE.
2668b8534bSLuigi Rizzo */
2768b8534bSLuigi Rizzo
2868b8534bSLuigi Rizzo /*
2968b8534bSLuigi Rizzo *
30f9790aebSLuigi Rizzo * netmap support for: re
31f9790aebSLuigi Rizzo *
32f9790aebSLuigi Rizzo * For more details on netmap support please see ixgbe_netmap.h
3368b8534bSLuigi Rizzo */
3468b8534bSLuigi Rizzo
3564ae02c3SLuigi Rizzo
3668b8534bSLuigi Rizzo #include <net/netmap.h>
3768b8534bSLuigi Rizzo #include <sys/selinfo.h>
3868b8534bSLuigi Rizzo #include <vm/vm.h>
3968b8534bSLuigi Rizzo #include <vm/pmap.h> /* vtophys ? */
4068b8534bSLuigi Rizzo #include <dev/netmap/netmap_kern.h>
4168b8534bSLuigi Rizzo
4268b8534bSLuigi Rizzo
4368b8534bSLuigi Rizzo /*
44f9790aebSLuigi Rizzo * Register/unregister. We are already under netmap lock.
4568b8534bSLuigi Rizzo */
4668b8534bSLuigi Rizzo static int
re_netmap_reg(struct netmap_adapter * na,int onoff)47f9790aebSLuigi Rizzo re_netmap_reg(struct netmap_adapter *na, int onoff)
4868b8534bSLuigi Rizzo {
49e330262fSJustin Hibbits if_t ifp = na->ifp;
50e330262fSJustin Hibbits struct rl_softc *adapter = if_getsoftc(ifp);
5168b8534bSLuigi Rizzo
52f9790aebSLuigi Rizzo RL_LOCK(adapter);
53f9790aebSLuigi Rizzo re_stop(adapter); /* also clears IFF_DRV_RUNNING */
5468b8534bSLuigi Rizzo if (onoff) {
55f9790aebSLuigi Rizzo nm_set_native_flags(na);
5668b8534bSLuigi Rizzo } else {
57f9790aebSLuigi Rizzo nm_clear_native_flags(na);
5868b8534bSLuigi Rizzo }
59f9790aebSLuigi Rizzo re_init_locked(adapter); /* also enables intr */
60f9790aebSLuigi Rizzo RL_UNLOCK(adapter);
61e330262fSJustin Hibbits return (if_getdrvflags(ifp) & IFF_DRV_RUNNING ? 0 : 1);
6268b8534bSLuigi Rizzo }
6368b8534bSLuigi Rizzo
6468b8534bSLuigi Rizzo
6568b8534bSLuigi Rizzo /*
6668b8534bSLuigi Rizzo * Reconcile kernel and user view of the transmit ring.
6768b8534bSLuigi Rizzo */
6868b8534bSLuigi Rizzo static int
re_netmap_txsync(struct netmap_kring * kring,int flags)694bf50f18SLuigi Rizzo re_netmap_txsync(struct netmap_kring *kring, int flags)
7068b8534bSLuigi Rizzo {
714bf50f18SLuigi Rizzo struct netmap_adapter *na = kring->na;
72e330262fSJustin Hibbits if_t ifp = na->ifp;
7368b8534bSLuigi Rizzo struct netmap_ring *ring = kring->ring;
74f9790aebSLuigi Rizzo u_int nm_i; /* index into the netmap ring */
75f9790aebSLuigi Rizzo u_int nic_i; /* index into the NIC ring */
7617885a7bSLuigi Rizzo u_int n;
77f9790aebSLuigi Rizzo u_int const lim = kring->nkr_num_slots - 1;
7817885a7bSLuigi Rizzo u_int const head = kring->rhead;
7968b8534bSLuigi Rizzo
80f9790aebSLuigi Rizzo /* device-specific */
81e330262fSJustin Hibbits struct rl_softc *sc = if_getsoftc(ifp);
82f9790aebSLuigi Rizzo struct rl_txdesc *txd = sc->rl_ldata.rl_tx_desc;
83f9790aebSLuigi Rizzo
8468b8534bSLuigi Rizzo bus_dmamap_sync(sc->rl_ldata.rl_tx_list_tag,
8568b8534bSLuigi Rizzo sc->rl_ldata.rl_tx_list_map,
86f9790aebSLuigi Rizzo BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); // XXX extra postwrite ?
8768b8534bSLuigi Rizzo
88f9790aebSLuigi Rizzo /*
89f9790aebSLuigi Rizzo * First part: process new packets to send.
90f9790aebSLuigi Rizzo */
91f9790aebSLuigi Rizzo nm_i = kring->nr_hwcur;
9217885a7bSLuigi Rizzo if (nm_i != head) { /* we have new packets to send */
93f9790aebSLuigi Rizzo nic_i = sc->rl_ldata.rl_tx_prodidx;
94f9790aebSLuigi Rizzo // XXX or netmap_idx_k2n(kring, nm_i);
9568b8534bSLuigi Rizzo
9617885a7bSLuigi Rizzo for (n = 0; nm_i != head; n++) {
97f9790aebSLuigi Rizzo struct netmap_slot *slot = &ring->slot[nm_i];
98f9790aebSLuigi Rizzo u_int len = slot->len;
996e10c8b8SLuigi Rizzo uint64_t paddr;
1004bf50f18SLuigi Rizzo void *addr = PNMB(na, slot, &paddr);
10168b8534bSLuigi Rizzo
102f9790aebSLuigi Rizzo /* device-specific */
103f9790aebSLuigi Rizzo struct rl_desc *desc = &sc->rl_ldata.rl_tx_list[nic_i];
104f9790aebSLuigi Rizzo int cmd = slot->len | RL_TDESC_CMD_EOF |
105f9790aebSLuigi Rizzo RL_TDESC_CMD_OWN | RL_TDESC_CMD_SOF ;
10668b8534bSLuigi Rizzo
1074bf50f18SLuigi Rizzo NM_CHECK_ADDR_LEN(na, addr, len);
108f9790aebSLuigi Rizzo
109f9790aebSLuigi Rizzo if (nic_i == lim) /* mark end of ring */
11068b8534bSLuigi Rizzo cmd |= RL_TDESC_CMD_EOR;
11168b8534bSLuigi Rizzo
11268b8534bSLuigi Rizzo if (slot->flags & NS_BUF_CHANGED) {
113f9790aebSLuigi Rizzo /* buffer has changed, reload map */
11468b8534bSLuigi Rizzo desc->rl_bufaddr_lo = htole32(RL_ADDR_LO(paddr));
11568b8534bSLuigi Rizzo desc->rl_bufaddr_hi = htole32(RL_ADDR_HI(paddr));
1164bf50f18SLuigi Rizzo netmap_reload_map(na, sc->rl_ldata.rl_tx_mtag,
117f9790aebSLuigi Rizzo txd[nic_i].tx_dmamap, addr);
11868b8534bSLuigi Rizzo }
119f9790aebSLuigi Rizzo slot->flags &= ~(NS_REPORT | NS_BUF_CHANGED);
12068b8534bSLuigi Rizzo
121f9790aebSLuigi Rizzo /* Fill the slot in the NIC ring. */
122f9790aebSLuigi Rizzo desc->rl_cmdstat = htole32(cmd);
123f9790aebSLuigi Rizzo
124f9790aebSLuigi Rizzo /* make sure changes to the buffer are synced */
125f9790aebSLuigi Rizzo bus_dmamap_sync(sc->rl_ldata.rl_tx_mtag,
126f9790aebSLuigi Rizzo txd[nic_i].tx_dmamap,
127f9790aebSLuigi Rizzo BUS_DMASYNC_PREWRITE);
128f9790aebSLuigi Rizzo
129f9790aebSLuigi Rizzo nm_i = nm_next(nm_i, lim);
130f9790aebSLuigi Rizzo nic_i = nm_next(nic_i, lim);
131f9790aebSLuigi Rizzo }
132f9790aebSLuigi Rizzo sc->rl_ldata.rl_tx_prodidx = nic_i;
13317885a7bSLuigi Rizzo kring->nr_hwcur = head;
134f9790aebSLuigi Rizzo
135f9790aebSLuigi Rizzo /* synchronize the NIC ring */
13668b8534bSLuigi Rizzo bus_dmamap_sync(sc->rl_ldata.rl_tx_list_tag,
13768b8534bSLuigi Rizzo sc->rl_ldata.rl_tx_list_map,
138f9790aebSLuigi Rizzo BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
13968b8534bSLuigi Rizzo
14068b8534bSLuigi Rizzo /* start ? */
14168b8534bSLuigi Rizzo CSR_WRITE_1(sc, sc->rl_txstart, RL_TXSTART_START);
14268b8534bSLuigi Rizzo }
143f9790aebSLuigi Rizzo
144f9790aebSLuigi Rizzo /*
145f9790aebSLuigi Rizzo * Second part: reclaim buffers for completed transmissions.
146f9790aebSLuigi Rizzo */
14717885a7bSLuigi Rizzo if (flags & NAF_FORCE_RECLAIM || nm_kr_txempty(kring)) {
148f9790aebSLuigi Rizzo nic_i = sc->rl_ldata.rl_tx_considx;
149f9790aebSLuigi Rizzo for (n = 0; nic_i != sc->rl_ldata.rl_tx_prodidx;
150f9790aebSLuigi Rizzo n++, nic_i = RL_TX_DESC_NXT(sc, nic_i)) {
151f9790aebSLuigi Rizzo uint32_t cmdstat =
152f9790aebSLuigi Rizzo le32toh(sc->rl_ldata.rl_tx_list[nic_i].rl_cmdstat);
153f9790aebSLuigi Rizzo if (cmdstat & RL_TDESC_STAT_OWN)
154f9790aebSLuigi Rizzo break;
155f9790aebSLuigi Rizzo }
156f9790aebSLuigi Rizzo if (n > 0) {
157f9790aebSLuigi Rizzo sc->rl_ldata.rl_tx_considx = nic_i;
158f9790aebSLuigi Rizzo sc->rl_ldata.rl_tx_free += n;
15917885a7bSLuigi Rizzo kring->nr_hwtail = nm_prev(netmap_idx_n2k(kring, nic_i), lim);
160f9790aebSLuigi Rizzo }
161f9790aebSLuigi Rizzo }
162f9790aebSLuigi Rizzo
16368b8534bSLuigi Rizzo return 0;
16468b8534bSLuigi Rizzo }
16568b8534bSLuigi Rizzo
16668b8534bSLuigi Rizzo
16768b8534bSLuigi Rizzo /*
16868b8534bSLuigi Rizzo * Reconcile kernel and user view of the receive ring.
16968b8534bSLuigi Rizzo */
17068b8534bSLuigi Rizzo static int
re_netmap_rxsync(struct netmap_kring * kring,int flags)1714bf50f18SLuigi Rizzo re_netmap_rxsync(struct netmap_kring *kring, int flags)
17268b8534bSLuigi Rizzo {
1734bf50f18SLuigi Rizzo struct netmap_adapter *na = kring->na;
174e330262fSJustin Hibbits if_t ifp = na->ifp;
17568b8534bSLuigi Rizzo struct netmap_ring *ring = kring->ring;
176f9790aebSLuigi Rizzo u_int nm_i; /* index into the netmap ring */
177f9790aebSLuigi Rizzo u_int nic_i; /* index into the NIC ring */
178f9790aebSLuigi Rizzo u_int const lim = kring->nkr_num_slots - 1;
179847bf383SLuigi Rizzo u_int const head = kring->rhead;
180ce3ee1e7SLuigi Rizzo int force_update = (flags & NAF_FORCE_READ) || kring->nr_kflags & NKR_PENDINTR;
18168b8534bSLuigi Rizzo
182f9790aebSLuigi Rizzo /* device-specific */
183e330262fSJustin Hibbits struct rl_softc *sc = if_getsoftc(ifp);
184f9790aebSLuigi Rizzo struct rl_rxdesc *rxd = sc->rl_ldata.rl_rx_desc;
185f9790aebSLuigi Rizzo
18617885a7bSLuigi Rizzo if (head > lim)
18768b8534bSLuigi Rizzo return netmap_ring_reinit(kring);
18868b8534bSLuigi Rizzo
18968b8534bSLuigi Rizzo bus_dmamap_sync(sc->rl_ldata.rl_rx_list_tag,
19068b8534bSLuigi Rizzo sc->rl_ldata.rl_rx_list_map,
19168b8534bSLuigi Rizzo BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
19268b8534bSLuigi Rizzo
19368b8534bSLuigi Rizzo /*
194f9790aebSLuigi Rizzo * First part: import newly received packets.
19564ae02c3SLuigi Rizzo *
196f9790aebSLuigi Rizzo * This device uses all the buffers in the ring, so we need
19768b8534bSLuigi Rizzo * another termination condition in addition to RL_RDESC_STAT_OWN
19817885a7bSLuigi Rizzo * cleared (all buffers could have it cleared). The easiest one
19917885a7bSLuigi Rizzo * is to stop right before nm_hwcur.
20068b8534bSLuigi Rizzo */
20164ae02c3SLuigi Rizzo if (netmap_no_pendintr || force_update) {
20217885a7bSLuigi Rizzo uint32_t stop_i = nm_prev(kring->nr_hwcur, lim);
2031dce924dSLuigi Rizzo
204f9790aebSLuigi Rizzo nic_i = sc->rl_ldata.rl_rx_prodidx; /* next pkt to check */
205f9790aebSLuigi Rizzo nm_i = netmap_idx_n2k(kring, nic_i);
206f9790aebSLuigi Rizzo
20717885a7bSLuigi Rizzo while (nm_i != stop_i) {
208f9790aebSLuigi Rizzo struct rl_desc *cur_rx = &sc->rl_ldata.rl_rx_list[nic_i];
20968b8534bSLuigi Rizzo uint32_t rxstat = le32toh(cur_rx->rl_cmdstat);
21068b8534bSLuigi Rizzo uint32_t total_len;
21168b8534bSLuigi Rizzo
21268b8534bSLuigi Rizzo if ((rxstat & RL_RDESC_STAT_OWN) != 0)
21368b8534bSLuigi Rizzo break;
21468b8534bSLuigi Rizzo total_len = rxstat & sc->rl_rxlenmask;
21568b8534bSLuigi Rizzo /* XXX subtract crc */
21668b8534bSLuigi Rizzo total_len = (total_len < 4) ? 0 : total_len - 4;
217f9790aebSLuigi Rizzo ring->slot[nm_i].len = total_len;
2184f80b14cSVincenzo Maffione ring->slot[nm_i].flags = 0;
21968b8534bSLuigi Rizzo /* sync was in re_newbuf() */
22068b8534bSLuigi Rizzo bus_dmamap_sync(sc->rl_ldata.rl_rx_mtag,
221f9790aebSLuigi Rizzo rxd[nic_i].rx_dmamap, BUS_DMASYNC_POSTREAD);
222c8dfaf38SGleb Smirnoff // if_inc_counter(sc->rl_ifp, IFCOUNTER_IPACKETS, 1);
223f9790aebSLuigi Rizzo nm_i = nm_next(nm_i, lim);
224f9790aebSLuigi Rizzo nic_i = nm_next(nic_i, lim);
22568b8534bSLuigi Rizzo }
226f9790aebSLuigi Rizzo sc->rl_ldata.rl_rx_prodidx = nic_i;
22717885a7bSLuigi Rizzo kring->nr_hwtail = nm_i;
22864ae02c3SLuigi Rizzo kring->nr_kflags &= ~NKR_PENDINTR;
22964ae02c3SLuigi Rizzo }
23068b8534bSLuigi Rizzo
231f9790aebSLuigi Rizzo /*
232f9790aebSLuigi Rizzo * Second part: skip past packets that userspace has released.
233f9790aebSLuigi Rizzo */
234f9790aebSLuigi Rizzo nm_i = kring->nr_hwcur;
23517885a7bSLuigi Rizzo if (nm_i != head) {
236f9790aebSLuigi Rizzo nic_i = netmap_idx_k2n(kring, nm_i);
2378bfedf58SDimitry Andric while (nm_i != head) {
238f9790aebSLuigi Rizzo struct netmap_slot *slot = &ring->slot[nm_i];
2396e10c8b8SLuigi Rizzo uint64_t paddr;
2404bf50f18SLuigi Rizzo void *addr = PNMB(na, slot, &paddr);
24168b8534bSLuigi Rizzo
242f9790aebSLuigi Rizzo struct rl_desc *desc = &sc->rl_ldata.rl_rx_list[nic_i];
2434bf50f18SLuigi Rizzo int cmd = NETMAP_BUF_SIZE(na) | RL_RDESC_CMD_OWN;
24468b8534bSLuigi Rizzo
2454bf50f18SLuigi Rizzo if (addr == NETMAP_BUF_BASE(na)) /* bad buf */
246f9790aebSLuigi Rizzo goto ring_reset;
247f9790aebSLuigi Rizzo
248f9790aebSLuigi Rizzo if (nic_i == lim) /* mark end of ring */
24968b8534bSLuigi Rizzo cmd |= RL_RDESC_CMD_EOR;
25068b8534bSLuigi Rizzo
25168b8534bSLuigi Rizzo if (slot->flags & NS_BUF_CHANGED) {
252f9790aebSLuigi Rizzo /* buffer has changed, reload map */
25364ae02c3SLuigi Rizzo desc->rl_bufaddr_lo = htole32(RL_ADDR_LO(paddr));
25464ae02c3SLuigi Rizzo desc->rl_bufaddr_hi = htole32(RL_ADDR_HI(paddr));
2554bf50f18SLuigi Rizzo netmap_reload_map(na, sc->rl_ldata.rl_rx_mtag,
256f9790aebSLuigi Rizzo rxd[nic_i].rx_dmamap, addr);
25768b8534bSLuigi Rizzo slot->flags &= ~NS_BUF_CHANGED;
25868b8534bSLuigi Rizzo }
25964ae02c3SLuigi Rizzo desc->rl_cmdstat = htole32(cmd);
26068b8534bSLuigi Rizzo bus_dmamap_sync(sc->rl_ldata.rl_rx_mtag,
261f9790aebSLuigi Rizzo rxd[nic_i].rx_dmamap,
262f9790aebSLuigi Rizzo BUS_DMASYNC_PREREAD);
263f9790aebSLuigi Rizzo nm_i = nm_next(nm_i, lim);
264f9790aebSLuigi Rizzo nic_i = nm_next(nic_i, lim);
26568b8534bSLuigi Rizzo }
26617885a7bSLuigi Rizzo kring->nr_hwcur = head;
26768b8534bSLuigi Rizzo
26868b8534bSLuigi Rizzo bus_dmamap_sync(sc->rl_ldata.rl_rx_list_tag,
26968b8534bSLuigi Rizzo sc->rl_ldata.rl_rx_list_map,
270f9790aebSLuigi Rizzo BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
27168b8534bSLuigi Rizzo }
272f9790aebSLuigi Rizzo
27368b8534bSLuigi Rizzo return 0;
274f9790aebSLuigi Rizzo
275f9790aebSLuigi Rizzo ring_reset:
276f9790aebSLuigi Rizzo return netmap_ring_reinit(kring);
27768b8534bSLuigi Rizzo }
27868b8534bSLuigi Rizzo
279f9790aebSLuigi Rizzo
280506cc70cSLuigi Rizzo /*
281506cc70cSLuigi Rizzo * Additional routines to init the tx and rx rings.
282506cc70cSLuigi Rizzo * In other drivers we do that inline in the main code.
283506cc70cSLuigi Rizzo */
28468b8534bSLuigi Rizzo static void
re_netmap_tx_init(struct rl_softc * sc)28568b8534bSLuigi Rizzo re_netmap_tx_init(struct rl_softc *sc)
28668b8534bSLuigi Rizzo {
28768b8534bSLuigi Rizzo struct rl_txdesc *txd;
28868b8534bSLuigi Rizzo struct rl_desc *desc;
289506cc70cSLuigi Rizzo int i, n;
29068b8534bSLuigi Rizzo struct netmap_adapter *na = NA(sc->rl_ifp);
291f9790aebSLuigi Rizzo struct netmap_slot *slot;
29268b8534bSLuigi Rizzo
293f9790aebSLuigi Rizzo slot = netmap_reset(na, NR_TX, 0, 0);
2944bf50f18SLuigi Rizzo /* slot is NULL if we are not in native netmap mode */
29568b8534bSLuigi Rizzo if (!slot)
2964bf50f18SLuigi Rizzo return;
29768b8534bSLuigi Rizzo /* in netmap mode, overwrite addresses and maps */
29868b8534bSLuigi Rizzo txd = sc->rl_ldata.rl_tx_desc;
29968b8534bSLuigi Rizzo desc = sc->rl_ldata.rl_tx_list;
300506cc70cSLuigi Rizzo n = sc->rl_ldata.rl_tx_desc_cnt;
30168b8534bSLuigi Rizzo
302506cc70cSLuigi Rizzo /* l points in the netmap ring, i points in the NIC ring */
303506cc70cSLuigi Rizzo for (i = 0; i < n; i++) {
304506cc70cSLuigi Rizzo uint64_t paddr;
3052ff91c17SVincenzo Maffione int l = netmap_idx_n2k(na->tx_rings[0], i);
3064bf50f18SLuigi Rizzo void *addr = PNMB(na, slot + l, &paddr);
307506cc70cSLuigi Rizzo
30868b8534bSLuigi Rizzo desc[i].rl_bufaddr_lo = htole32(RL_ADDR_LO(paddr));
30968b8534bSLuigi Rizzo desc[i].rl_bufaddr_hi = htole32(RL_ADDR_HI(paddr));
3104bf50f18SLuigi Rizzo netmap_load_map(na, sc->rl_ldata.rl_tx_mtag,
3116e10c8b8SLuigi Rizzo txd[i].tx_dmamap, addr);
31268b8534bSLuigi Rizzo }
31368b8534bSLuigi Rizzo }
31468b8534bSLuigi Rizzo
31568b8534bSLuigi Rizzo static void
re_netmap_rx_init(struct rl_softc * sc)31668b8534bSLuigi Rizzo re_netmap_rx_init(struct rl_softc *sc)
31768b8534bSLuigi Rizzo {
31868b8534bSLuigi Rizzo struct netmap_adapter *na = NA(sc->rl_ifp);
31968b8534bSLuigi Rizzo struct netmap_slot *slot = netmap_reset(na, NR_RX, 0, 0);
32068b8534bSLuigi Rizzo struct rl_desc *desc = sc->rl_ldata.rl_rx_list;
32168b8534bSLuigi Rizzo uint32_t cmdstat;
32217885a7bSLuigi Rizzo uint32_t nic_i, max_avail;
32317885a7bSLuigi Rizzo uint32_t const n = sc->rl_ldata.rl_rx_desc_cnt;
32468b8534bSLuigi Rizzo
32568b8534bSLuigi Rizzo if (!slot)
32668b8534bSLuigi Rizzo return;
3275644ccecSLuigi Rizzo /*
32817885a7bSLuigi Rizzo * Do not release the slots owned by userspace,
32917885a7bSLuigi Rizzo * and also keep one empty.
3305644ccecSLuigi Rizzo */
3312ff91c17SVincenzo Maffione max_avail = n - 1 - nm_kr_rxspace(na->rx_rings[0]);
33217885a7bSLuigi Rizzo for (nic_i = 0; nic_i < n; nic_i++) {
333506cc70cSLuigi Rizzo void *addr;
334506cc70cSLuigi Rizzo uint64_t paddr;
3352ff91c17SVincenzo Maffione uint32_t nm_i = netmap_idx_n2k(na->rx_rings[0], nic_i);
33668b8534bSLuigi Rizzo
3374bf50f18SLuigi Rizzo addr = PNMB(na, slot + nm_i, &paddr);
3386e10c8b8SLuigi Rizzo
3394bf50f18SLuigi Rizzo netmap_reload_map(na, sc->rl_ldata.rl_rx_mtag,
34017885a7bSLuigi Rizzo sc->rl_ldata.rl_rx_desc[nic_i].rx_dmamap, addr);
3416e10c8b8SLuigi Rizzo bus_dmamap_sync(sc->rl_ldata.rl_rx_mtag,
34217885a7bSLuigi Rizzo sc->rl_ldata.rl_rx_desc[nic_i].rx_dmamap, BUS_DMASYNC_PREREAD);
34317885a7bSLuigi Rizzo desc[nic_i].rl_bufaddr_lo = htole32(RL_ADDR_LO(paddr));
34417885a7bSLuigi Rizzo desc[nic_i].rl_bufaddr_hi = htole32(RL_ADDR_HI(paddr));
3454bf50f18SLuigi Rizzo cmdstat = NETMAP_BUF_SIZE(na);
34617885a7bSLuigi Rizzo if (nic_i == n - 1) /* mark the end of ring */
34768b8534bSLuigi Rizzo cmdstat |= RL_RDESC_CMD_EOR;
34817885a7bSLuigi Rizzo if (nic_i < max_avail)
349506cc70cSLuigi Rizzo cmdstat |= RL_RDESC_CMD_OWN;
35017885a7bSLuigi Rizzo desc[nic_i].rl_cmdstat = htole32(cmdstat);
35168b8534bSLuigi Rizzo }
35268b8534bSLuigi Rizzo }
35364ae02c3SLuigi Rizzo
35464ae02c3SLuigi Rizzo
35564ae02c3SLuigi Rizzo static void
re_netmap_attach(struct rl_softc * sc)35664ae02c3SLuigi Rizzo re_netmap_attach(struct rl_softc *sc)
35764ae02c3SLuigi Rizzo {
35864ae02c3SLuigi Rizzo struct netmap_adapter na;
35964ae02c3SLuigi Rizzo
36064ae02c3SLuigi Rizzo bzero(&na, sizeof(na));
36164ae02c3SLuigi Rizzo
36264ae02c3SLuigi Rizzo na.ifp = sc->rl_ifp;
363ce3ee1e7SLuigi Rizzo na.na_flags = NAF_BDG_MAYSLEEP;
36464ae02c3SLuigi Rizzo na.num_tx_desc = sc->rl_ldata.rl_tx_desc_cnt;
36564ae02c3SLuigi Rizzo na.num_rx_desc = sc->rl_ldata.rl_rx_desc_cnt;
36664ae02c3SLuigi Rizzo na.nm_txsync = re_netmap_txsync;
36764ae02c3SLuigi Rizzo na.nm_rxsync = re_netmap_rxsync;
36864ae02c3SLuigi Rizzo na.nm_register = re_netmap_reg;
369f9790aebSLuigi Rizzo na.num_tx_rings = na.num_rx_rings = 1;
370f9790aebSLuigi Rizzo netmap_attach(&na);
37164ae02c3SLuigi Rizzo }
372f9790aebSLuigi Rizzo
37364ae02c3SLuigi Rizzo /* end of file */
374