FreeBSD/sys/dev/netmap/netmap_vale.c
/* Bridge wrapper code (bwrap).
 * This is used to connect a non-VALE-port netmap_adapter (hwna) to a
 * VALE switch.
 * The main task is to swap the meaning of tx and rx rings to match the
 * expectations of the VALE switch code (see nm_bdg_flush).
 *
 * The bwrap works by interposing a netmap_bwrap_adapter between the
 * rest of the system and the hwna. The netmap_bwrap_adapter looks like
 * a netmap_vp_adapter to the rest the system, but, internally, it
 * translates all callbacks to what the hwna expects.
 *
 * Note that we have to intercept callbacks coming from two sides:
 *
 *  - callbacks coming from the netmap module are intercepted by
 *    passing around the netmap_bwrap_adapter instead of the hwna
 *
 *  - callbacks coming from outside of the netmap module only know
 *    about the hwna. This, however, only happens in interrupt
 *    handlers, where only the hwna->nm_notify callback is called.
 *    What the bwrap does is to overwrite the hwna->nm_notify callback
 *    with its own netmap_bwrap_intr_notify.
 *    XXX This assumes that the hwna->nm_notify callback was the
 *    standard netmap_notify(), as it is the case for nic adapters.
 *    Any additional action performed by hwna->nm_notify will not be
 *    performed by netmap_bwrap_intr_notify.
 *
 * Additionally, the bwrap can optionally attach the host rings pair
 * of the wrapped adapter to a different port of the switch.
 */
Bridge wrapper code (bwrap).
This is used to connect a non-VALE-port netmap_adapter (hwna) to a
VALE switch.
The main task is to swap the meaning of tx and rx rings to match the
expectations of the VALE switch code .

The bwrap works by interposing a netmap_bwrap_adapter between the
rest of the system and the hwna. The netmap_bwrap_adapter looks like
a netmap_vp_adapter to the rest the system, but, internally, it
translates all callbacks to what the hwna expects.

Note that we have to intercept callbacks coming from two sides.

- callbacks coming from the netmap module are intercepted by
passing around the netmap_bwrap_adapter instead of the hwna

- callbacks coming from outside of the netmap module only know
about the hwna. This, however, only happens in interrupt
handlers, where only the hwna->nm_notify callback is called.
What the bwrap does is to overwrite the hwna->nm_notify callback
with its own netmap_bwrap_intr_notify.
XXX This assumes that the hwna->nm_notify callback was the
standard netmap_notify(), as it is the case for nic adapters.
Any additional action performed by hwna->nm_notify will not be
performed by netmap_bwrap_intr_notify.

Additionally, the bwrap can optionally attach the host rings pair
of the wrapped adapter to a different port of the switch.
Bridge wrapper code ( bwrap ) . This is used to connect a non - VALE - port netmap_adapter ( hwna ) to a VALE switch . The main task is to swap the meaning of tx and rx rings to match the expectations of the VALE switch code . The bwrap works by interposing a netmap_bwrap_adapter between the rest of the system and the hwna . The netmap_bwrap_adapter looks like a netmap_vp_adapter to the rest the system but internally it translates all callbacks to what the hwna expects . Note that we have to intercept callbacks coming from two sides . - callbacks coming from the netmap module are intercepted by passing around the netmap_bwrap_adapter instead of the hwna - callbacks coming from outside of the netmap module only know about the hwna . This however only happens in interrupt handlers where only the hwna - > nm_notify callback is called . What the bwrap does is to overwrite the hwna - > nm_notify callback with its own netmap_bwrap_intr_notify . XXX This assumes that the hwna - > nm_notify callback was the standard netmap_notify () as it is the case for nic adapters . Any additional action performed by hwna - > nm_notify will not be performed by netmap_bwrap_intr_notify . Additionally the bwrap can optionally attach the host rings pair of the wrapped adapter to a different port of the switch .
static void
netmap_bwrap_dtor(struct netmap_adapter *na)
{
	struct netmap_bwrap_adapter *bna = (struct netmap_bwrap_adapter*)na;
	struct netmap_adapter *hwna = bna->hwna;
	ND("na %p", na);
	na->ifp = NULL;
	bna->host.up.ifp = NULL;
	hwna->nm_mem = bna->save_nmd;
	hwna->na_private = NULL;
	hwna->na_vp = hwna->na_hostvp = NULL;
	hwna->na_flags &= ~NAF_BUSY;
	netmap_adapter_put(hwna);
}
static void netmap_bwrap_dtor ( struct netmap_adapter * na ) { struct netmap_bwrap_adapter * bna = ( struct netmap_bwrap_adapter * ) na ; struct netmap_adapter * hwna = bna -> hwna ; ND ( " " , na ) ; na -> ifp = NULL ; bna -> host . up . ifp = NULL ; hwna -> nm_mem = bna -> save_nmd ; hwna -> na_private = NULL ; hwna -> na_vp = hwna -> na_hostvp = NULL ; hwna -> na_flags &= ~ NAF_BUSY ; netmap_adapter_put ( hwna ) ; }
Bridge wrapper code (bwrap).
Bridge wrapper code ( bwrap ) .
/* drop reference to hwna->ifp.
	 * If we don't do this, netmap_detach_common(na)
	 * will think it has set NA(na->ifp) to NULL
	 */ /* for safety, also drop the possible reference
	 * in the hostna
	 */