Lines Matching +full:txrx +full:-
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (C) 2014-2018 Giuseppe Lettieri
95 if (npipes <= na->na_max_pipes) in nm_pipe_alloc()
99 if (npipes < na->na_next_pipe || npipes > NM_MAXPIPES) in nm_pipe_alloc()
102 old_len = sizeof(struct netmap_pipe_adapter *)*na->na_max_pipes; in nm_pipe_alloc()
104 npa = nm_os_realloc(na->na_pipes, len, old_len); in nm_pipe_alloc()
108 na->na_pipes = npa; in nm_pipe_alloc()
109 na->na_max_pipes = npipes; in nm_pipe_alloc()
118 if (na->na_pipes) { in netmap_pipe_dealloc()
119 if (na->na_next_pipe > 0) { in netmap_pipe_dealloc()
121 na->name, na->na_next_pipe); in netmap_pipe_dealloc()
123 nm_os_free(na->na_pipes); in netmap_pipe_dealloc()
124 na->na_pipes = NULL; in netmap_pipe_dealloc()
125 na->na_max_pipes = 0; in netmap_pipe_dealloc()
126 na->na_next_pipe = 0; in netmap_pipe_dealloc()
137 for (i = 0; i < parent->na_next_pipe; i++) { in netmap_pipe_find()
139 na = parent->na_pipes[i]; in netmap_pipe_find()
140 na_pipe_id = strrchr(na->up.name, in netmap_pipe_find()
141 na->role == NM_PIPE_ROLE_MASTER ? '{' : '}'); in netmap_pipe_find()
155 if (parent->na_next_pipe >= parent->na_max_pipes) { in netmap_pipe_add()
156 u_int npipes = parent->na_max_pipes ? 2*parent->na_max_pipes : 2; in netmap_pipe_add()
162 parent->na_pipes[parent->na_next_pipe] = na; in netmap_pipe_add()
163 na->parent_slot = parent->na_next_pipe; in netmap_pipe_add()
164 parent->na_next_pipe++; in netmap_pipe_add()
173 n = --parent->na_next_pipe; in netmap_pipe_remove()
174 if (n != na->parent_slot) { in netmap_pipe_remove()
176 &parent->na_pipes[na->parent_slot]; in netmap_pipe_remove()
177 *p = parent->na_pipes[n]; in netmap_pipe_remove()
178 (*p)->parent_slot = na->parent_slot; in netmap_pipe_remove()
180 parent->na_pipes[n] = NULL; in netmap_pipe_remove()
186 struct netmap_kring *rxkring = txkring->pipe; in netmap_pipe_txsync()
187 u_int k, lim = txkring->nkr_num_slots - 1, nk; in netmap_pipe_txsync()
190 struct netmap_ring *txring = txkring->ring, *rxring = rxkring->ring; in netmap_pipe_txsync()
192 nm_prdis("%p: %s %x -> %s", txkring, txkring->name, flags, rxkring->name); in netmap_pipe_txsync()
194 txkring->nr_hwcur, txkring->nr_hwtail, in netmap_pipe_txsync()
195 txkring->rcur, txkring->rhead, txkring->rtail); in netmap_pipe_txsync()
198 txkring->nr_hwtail = txkring->pipe_tail; in netmap_pipe_txsync()
200 m = txkring->rhead - txkring->nr_hwcur; /* new slots */ in netmap_pipe_txsync()
202 m += txkring->nkr_num_slots; in netmap_pipe_txsync()
209 for (k = txkring->nr_hwcur, nk = lim + 1, complete = 0; m; in netmap_pipe_txsync()
210 m--, k = nm_next(k, lim), nk = (complete ? k : nk)) { in netmap_pipe_txsync()
211 struct netmap_slot *rs = &rxring->slot[k]; in netmap_pipe_txsync()
212 struct netmap_slot *ts = &txring->slot[k]; in netmap_pipe_txsync()
219 if (ts->flags & NS_BUF_CHANGED) { in netmap_pipe_txsync()
220 ts->flags &= ~NS_BUF_CHANGED; in netmap_pipe_txsync()
222 complete = !(ts->flags & NS_MOREFRAG); in netmap_pipe_txsync()
225 txkring->nr_hwcur = k; in netmap_pipe_txsync()
228 txkring->nr_hwcur, txkring->nr_hwtail, in netmap_pipe_txsync()
229 txkring->rcur, txkring->rhead, txkring->rtail, k); in netmap_pipe_txsync()
233 rxkring->pipe_tail = nk; /* only publish complete packets */ in netmap_pipe_txsync()
234 rxkring->nm_notify(rxkring, 0); in netmap_pipe_txsync()
243 struct netmap_kring *txkring = rxkring->pipe; in netmap_pipe_rxsync()
244 u_int k, lim = rxkring->nkr_num_slots - 1; in netmap_pipe_rxsync()
246 struct netmap_ring *txring = txkring->ring, *rxring = rxkring->ring; in netmap_pipe_rxsync()
248 nm_prdis("%p: %s %x -> %s", txkring, txkring->name, flags, rxkring->name); in netmap_pipe_rxsync()
250 rxkring->nr_hwcur, rxkring->nr_hwtail, in netmap_pipe_rxsync()
251 rxkring->rcur, rxkring->rhead, rxkring->rtail); in netmap_pipe_rxsync()
254 rxkring->nr_hwtail = rxkring->pipe_tail; in netmap_pipe_rxsync()
256 m = rxkring->rhead - rxkring->nr_hwcur; /* released slots */ in netmap_pipe_rxsync()
258 m += rxkring->nkr_num_slots; in netmap_pipe_rxsync()
265 for (k = rxkring->nr_hwcur; m; m--, k = nm_next(k, lim)) { in netmap_pipe_rxsync()
266 struct netmap_slot *rs = &rxring->slot[k]; in netmap_pipe_rxsync()
267 struct netmap_slot *ts = &txring->slot[k]; in netmap_pipe_rxsync()
271 if (rs->flags & NS_BUF_CHANGED) { in netmap_pipe_rxsync()
272 rs->flags &= ~NS_BUF_CHANGED; in netmap_pipe_rxsync()
277 txkring->pipe_tail = nm_prev(k, lim); in netmap_pipe_rxsync()
278 rxkring->nr_hwcur = k; in netmap_pipe_rxsync()
281 rxkring->nr_hwcur, rxkring->nr_hwtail, in netmap_pipe_rxsync()
282 rxkring->rcur, rxkring->rhead, rxkring->rtail, k); in netmap_pipe_rxsync()
284 txkring->nm_notify(txkring, 0); in netmap_pipe_rxsync()
298 * state A) user1 --> endpoint1 --> endpoint2
303 * state B) user1 --> endpoint1 endpoint2 <--- user2
321 enum txrx t; in netmap_pipe_krings_create_both()
338 enum txrx r = nm_txrx_swap(t); /* swap NR_TX <-> NR_RX */ in netmap_pipe_krings_create_both()
342 k1->pipe = k2; in netmap_pipe_krings_create_both()
343 k2->pipe = k1; in netmap_pipe_krings_create_both()
344 /* mark all peer-adapter rings as fake */ in netmap_pipe_krings_create_both()
345 k2->nr_kflags |= NKR_FAKERING; in netmap_pipe_krings_create_both()
347 k1->pipe_tail = k1->nr_hwtail; in netmap_pipe_krings_create_both()
348 k2->pipe_tail = k2->nr_hwtail; in netmap_pipe_krings_create_both()
365 * usr1 --> e1 --> e2
372 * usr1 --> e1 --> e2
382 struct netmap_adapter *ona = &pna->peer->up; in netmap_pipe_krings_create()
384 if (pna->peer_ref) in netmap_pipe_krings_create()
394 enum txrx t; in netmap_pipe_reg_both()
402 kring->pipe->nr_kflags |= NKR_NEEDRING; in netmap_pipe_reg_both()
421 kring->nr_mode = NKR_NETMAP_ON; in netmap_pipe_reg_both()
422 if ((kring->nr_kflags & NKR_FAKERING) && in netmap_pipe_reg_both()
423 (kring->pipe->nr_kflags & NKR_FAKERING)) { in netmap_pipe_reg_both()
424 /* this is a re-open of a pipe in netmap_pipe_reg_both()
425 * end-point kept alive by the other end. in netmap_pipe_reg_both()
431 /* copy the buffers from the non-fake ring in netmap_pipe_reg_both()
434 memcpy(kring->pipe->ring->slot, in netmap_pipe_reg_both()
435 kring->ring->slot, in netmap_pipe_reg_both()
437 kring->nkr_num_slots); in netmap_pipe_reg_both()
438 /* copy the offset-related fields */ in netmap_pipe_reg_both()
439 *(uint64_t *)(uintptr_t)&kring->pipe->ring->offset_mask = in netmap_pipe_reg_both()
440 kring->ring->offset_mask; in netmap_pipe_reg_both()
441 *(uint64_t *)(uintptr_t)&kring->pipe->ring->buf_align = in netmap_pipe_reg_both()
442 kring->ring->buf_align; in netmap_pipe_reg_both()
449 kring->nr_kflags |= in netmap_pipe_reg_both()
451 kring->nr_mode = NKR_NETMAP_ON; in netmap_pipe_reg_both()
465 * usr1 --> e1 --> e2
472 * usr1 --> e1 --> e2 <-- usr2
480 * usr1 --> e1 --> e2
487 * usr1 --> e1 e2 <-- usr2
497 struct netmap_adapter *ona = &pna->peer->up; in netmap_pipe_reg()
506 if (na->active_fds == 0) in netmap_pipe_reg()
507 na->na_flags |= NAF_NETMAP_ON; in netmap_pipe_reg()
509 if (na->active_fds == 0) in netmap_pipe_reg()
510 na->na_flags &= ~NAF_NETMAP_ON; in netmap_pipe_reg()
514 if (na->active_fds) { in netmap_pipe_reg()
515 nm_prdis("active_fds %d", na->active_fds); in netmap_pipe_reg()
519 if (pna->peer_ref) { in netmap_pipe_reg()
525 pna->peer->peer_ref = 0; in netmap_pipe_reg()
530 pna->peer->peer_ref = 1; in netmap_pipe_reg()
540 enum txrx t; in netmap_pipe_krings_delete_both()
545 /* To avoid double-frees we zero-out all the buffers in the kernel part in netmap_pipe_krings_delete_both()
557 struct netmap_ring *ring = kring->ring; in netmap_pipe_krings_delete_both()
558 uint32_t j, lim = kring->nkr_num_slots - 1; in netmap_pipe_krings_delete_both()
561 kring->name, ring, kring->nr_hwtail, kring->nr_hwcur); in netmap_pipe_krings_delete_both()
566 if (kring->tx == NR_RX) in netmap_pipe_krings_delete_both()
567 ring->slot[kring->pipe_tail].buf_idx = 0; in netmap_pipe_krings_delete_both()
569 for (j = nm_next(kring->pipe_tail, lim); in netmap_pipe_krings_delete_both()
570 j != kring->nr_hwcur; in netmap_pipe_krings_delete_both()
573 nm_prdis("%s[%d] %u", kring->name, j, ring->slot[j].buf_idx); in netmap_pipe_krings_delete_both()
574 ring->slot[j].buf_idx = 0; in netmap_pipe_krings_delete_both()
576 kring->nr_kflags &= ~(NKR_FAKERING | NKR_NEEDRING); in netmap_pipe_krings_delete_both()
580 if (sna != ona && ona->tx_rings) { in netmap_pipe_krings_delete_both()
588 if (ona->tx_rings == NULL) { in netmap_pipe_krings_delete_both()
590 * cleanup-after-error path */ in netmap_pipe_krings_delete_both()
603 * usr1 --> e1 --> e2
610 * usr1 --> e1 e2 <-- usr2
624 if (!pna->peer_ref) { in netmap_pipe_krings_delete()
628 ona = &pna->peer->up; in netmap_pipe_krings_delete()
638 nm_prdis("%p %p", na, pna->parent_ifp); in netmap_pipe_dtor()
639 if (pna->peer_ref) { in netmap_pipe_dtor()
641 pna->peer_ref = 0; in netmap_pipe_dtor()
642 netmap_adapter_put(&pna->peer->up); in netmap_pipe_dtor()
644 if (pna->role == NM_PIPE_ROLE_MASTER) in netmap_pipe_dtor()
645 netmap_pipe_remove(pna->parent, pna); in netmap_pipe_dtor()
646 if (pna->parent_ifp) in netmap_pipe_dtor()
647 if_rele(pna->parent_ifp); in netmap_pipe_dtor()
648 netmap_adapter_put(pna->parent); in netmap_pipe_dtor()
649 pna->parent = NULL; in netmap_pipe_dtor()
656 struct nmreq_register *req = (struct nmreq_register *)(uintptr_t)hdr->nr_body; in netmap_get_pipe_na()
666 cbra = strrchr(hdr->nr_name, '{'); in netmap_get_pipe_na()
670 cbra = strrchr(hdr->nr_name, '}'); in netmap_get_pipe_na()
680 if (*pipe_id == '\0' || cbra == hdr->nr_name) { in netmap_get_pipe_na()
687 if (req->nr_mode != NR_REG_ALL_NIC && req->nr_mode != NR_REG_ONE_NIC) { in netmap_get_pipe_na()
733 if (mna->role == role) { in netmap_get_pipe_na()
734 nm_prdis("found %s directly at %d", pipe_id, mna->parent_slot); in netmap_get_pipe_na()
737 nm_prdis("found %s indirectly at %d", pipe_id, mna->parent_slot); in netmap_get_pipe_na()
738 reqna = mna->peer; in netmap_get_pipe_na()
760 snprintf(mna->up.name, sizeof(mna->up.name), "%s{%s", pna->name, pipe_id); in netmap_get_pipe_na()
762 mna->role = NM_PIPE_ROLE_MASTER; in netmap_get_pipe_na()
763 mna->parent = pna; in netmap_get_pipe_na()
764 mna->parent_ifp = ifp; in netmap_get_pipe_na()
766 mna->up.nm_txsync = netmap_pipe_txsync; in netmap_get_pipe_na()
767 mna->up.nm_rxsync = netmap_pipe_rxsync; in netmap_get_pipe_na()
768 mna->up.nm_register = netmap_pipe_reg; in netmap_get_pipe_na()
769 mna->up.nm_dtor = netmap_pipe_dtor; in netmap_get_pipe_na()
770 mna->up.nm_krings_create = netmap_pipe_krings_create; in netmap_get_pipe_na()
771 mna->up.nm_krings_delete = netmap_pipe_krings_delete; in netmap_get_pipe_na()
772 mna->up.nm_mem = netmap_mem_get(pna->nm_mem); in netmap_get_pipe_na()
773 mna->up.na_flags |= NAF_MEM_OWNER | NAF_OFFSETS; in netmap_get_pipe_na()
774 mna->up.na_lut = pna->na_lut; in netmap_get_pipe_na()
776 mna->up.num_tx_rings = req->nr_tx_rings; in netmap_get_pipe_na()
777 nm_bound_var(&mna->up.num_tx_rings, 1, in netmap_get_pipe_na()
779 mna->up.num_rx_rings = req->nr_rx_rings; in netmap_get_pipe_na()
780 nm_bound_var(&mna->up.num_rx_rings, 1, in netmap_get_pipe_na()
782 mna->up.num_tx_desc = req->nr_tx_slots; in netmap_get_pipe_na()
783 nm_bound_var(&mna->up.num_tx_desc, pna->num_tx_desc, in netmap_get_pipe_na()
785 mna->up.num_rx_desc = req->nr_rx_slots; in netmap_get_pipe_na()
786 nm_bound_var(&mna->up.num_rx_desc, pna->num_rx_desc, in netmap_get_pipe_na()
788 error = netmap_attach_common(&mna->up); in netmap_get_pipe_na()
804 sna->up.nm_mem = netmap_mem_get(mna->up.nm_mem); in netmap_get_pipe_na()
806 sna->up.num_tx_rings = mna->up.num_rx_rings; in netmap_get_pipe_na()
807 sna->up.num_tx_desc = mna->up.num_rx_desc; in netmap_get_pipe_na()
808 sna->up.num_rx_rings = mna->up.num_tx_rings; in netmap_get_pipe_na()
809 sna->up.num_rx_desc = mna->up.num_tx_desc; in netmap_get_pipe_na()
810 snprintf(sna->up.name, sizeof(sna->up.name), "%s}%s", pna->name, pipe_id); in netmap_get_pipe_na()
811 sna->role = NM_PIPE_ROLE_SLAVE; in netmap_get_pipe_na()
812 error = netmap_attach_common(&sna->up); in netmap_get_pipe_na()
817 mna->peer = sna; in netmap_get_pipe_na()
818 sna->peer = mna; in netmap_get_pipe_na()
830 mna->peer_ref = 1; in netmap_get_pipe_na()
831 netmap_adapter_get(&sna->up); in netmap_get_pipe_na()
834 sna->peer_ref = 1; in netmap_get_pipe_na()
835 netmap_adapter_get(&mna->up); in netmap_get_pipe_na()
841 (reqna->role == NM_PIPE_ROLE_MASTER ? "master" : "slave"), reqna); in netmap_get_pipe_na()
842 *na = &reqna->up; in netmap_get_pipe_na()