FreeBSD/sys/dev/netmap/netmap_vale.c
/* create a netmap_vp_adapter that describes a VALE port.
 * Only persistent VALE ports have a non-null ifp.
 */
create a netmap_vp_adapter that describes a VALE port.
Only persistent VALE ports have a non-null ifp.
create a netmap_vp_adapter that describes a VALE port . Only persistent VALE ports have a non - null ifp .
static int
netmap_vp_create(struct nmreq *nmr, struct ifnet *ifp, struct netmap_vp_adapter **ret)
{
	struct netmap_vp_adapter *vpna;
	struct netmap_adapter *na;
	int error;
	u_int npipes = 0;
	vpna = malloc(sizeof(*vpna), M_DEVBUF, M_NOWAIT | M_ZERO);
	if (vpna == NULL)
		return ENOMEM;
 	na = &vpna->up;
	na->ifp = ifp;
	strncpy(na->name, nmr->nr_name, sizeof(na->name));
	na->num_tx_rings = nmr->nr_tx_rings;
	nm_bound_var(&na->num_tx_rings, 1, 1, NM_BDG_MAXRINGS, NULL);
	nmr->nr_tx_rings = na->num_tx_rings; 
	na->num_rx_rings = nmr->nr_rx_rings;
	nm_bound_var(&na->num_rx_rings, 1, 1, NM_BDG_MAXRINGS, NULL);
	nmr->nr_rx_rings = na->num_rx_rings; 
	nm_bound_var(&nmr->nr_tx_slots, NM_BRIDGE_RINGSIZE,
			1, NM_BDG_MAXSLOTS, NULL);
	na->num_tx_desc = nmr->nr_tx_slots;
	nm_bound_var(&nmr->nr_rx_slots, NM_BRIDGE_RINGSIZE,
			1, NM_BDG_MAXSLOTS, NULL);
	npipes = nmr->nr_arg1;
	nm_bound_var(&npipes, 2, 1, NM_MAXPIPES, NULL);
	nmr->nr_arg1 = npipes;	
	nm_bound_var(&nmr->nr_arg3, 0, 0,
			128*NM_BDG_MAXSLOTS, NULL);
	na->num_rx_desc = nmr->nr_rx_slots;
	vpna->virt_hdr_len = 0;
	vpna->mfs = 1514;
	vpna->last_smac = ~0llu;
        if (netmap_verbose)
		D("max frame size %u", vpna->mfs);
	na->na_flags |= NAF_BDG_MAYSLEEP;
	if (ifp)
		na->na_flags |= NAF_NATIVE;
	na->nm_txsync = netmap_vp_txsync;
	na->nm_rxsync = netmap_vp_rxsync;
	na->nm_register = netmap_vp_reg;
	na->nm_krings_create = netmap_vp_krings_create;
	na->nm_krings_delete = netmap_vp_krings_delete;
	na->nm_dtor = netmap_vp_dtor;
	na->nm_mem = netmap_mem_private_new(na->name,
			na->num_tx_rings, na->num_tx_desc,
			na->num_rx_rings, na->num_rx_desc,
			nmr->nr_arg3, npipes, &error);
	if (na->nm_mem == NULL)
		goto err;
	na->nm_bdg_attach = netmap_vp_bdg_attach;
	error = netmap_attach_common(na);
	if (error)
		goto err;
	*ret = vpna;
	return 0;
err:
	if (na->nm_mem != NULL)
		netmap_mem_delete(na->nm_mem);
	free(vpna, M_DEVBUF);
	return error;
}
static int netmap_vp_create ( struct nmreq * nmr , struct ifnet * ifp , struct netmap_vp_adapter * * ret ) { struct netmap_vp_adapter * vpna ; struct netmap_adapter * na ; int error ; u_int npipes = 0 ; vpna = malloc ( sizeof ( * vpna ) , M_DEVBUF , M_NOWAIT | M_ZERO ) ; if ( vpna == NULL ) return ENOMEM ; na = & vpna -> up ; na -> ifp = ifp ; strncpy ( na -> name , nmr -> nr_name , sizeof ( na -> name ) ) ; na -> num_tx_rings = nmr -> nr_tx_rings ; nm_bound_var ( & na -> num_tx_rings , 1 , 1 , NM_BDG_MAXRINGS , NULL ) ; nmr -> nr_tx_rings = na -> num_tx_rings ; na -> num_rx_rings = nmr -> nr_rx_rings ; nm_bound_var ( & na -> num_rx_rings , 1 , 1 , NM_BDG_MAXRINGS , NULL ) ; nmr -> nr_rx_rings = na -> num_rx_rings ; nm_bound_var ( & nmr -> nr_tx_slots , NM_BRIDGE_RINGSIZE , 1 , NM_BDG_MAXSLOTS , NULL ) ; na -> num_tx_desc = nmr -> nr_tx_slots ; nm_bound_var ( & nmr -> nr_rx_slots , NM_BRIDGE_RINGSIZE , 1 , NM_BDG_MAXSLOTS , NULL ) ; npipes = nmr -> nr_arg1 ; nm_bound_var ( & npipes , 2 , 1 , NM_MAXPIPES , NULL ) ; nmr -> nr_arg1 = npipes ; nm_bound_var ( & nmr -> nr_arg3 , 0 , 0 , 128 * NM_BDG_MAXSLOTS , NULL ) ; na -> num_rx_desc = nmr -> nr_rx_slots ; vpna -> virt_hdr_len = 0 ; vpna -> mfs = 1514 ; vpna -> last_smac = ~ 0llu ; if ( netmap_verbose ) D ( " " , vpna -> mfs ) ; na -> na_flags |= NAF_BDG_MAYSLEEP ; if ( ifp ) na -> na_flags |= NAF_NATIVE ; na -> nm_txsync = netmap_vp_txsync ; na -> nm_rxsync = netmap_vp_rxsync ; na -> nm_register = netmap_vp_reg ; na -> nm_krings_create = netmap_vp_krings_create ; na -> nm_krings_delete = netmap_vp_krings_delete ; na -> nm_dtor = netmap_vp_dtor ; na -> nm_mem = netmap_mem_private_new ( na -> name , na -> num_tx_rings , na -> num_tx_desc , na -> num_rx_rings , na -> num_rx_desc , nmr -> nr_arg3 , npipes , & error ) ; if ( na -> nm_mem == NULL ) goto err ; na -> nm_bdg_attach = netmap_vp_bdg_attach ; error = netmap_attach_common ( na ) ; if ( error ) goto err ; * ret = vpna ; return 0 ; err : if ( na -> nm_mem != NULL ) netmap_mem_delete ( na -> nm_mem ) ; free ( vpna , M_DEVBUF ) ; return error ; }
create a netmap_vp_adapter that describes a VALE port.
create a netmap_vp_adapter that describes a VALE port .
/* bound checking */ // write back // write back /* validate number of pipes. We want at least 1,
	 * but probably can do with some more.
	 * So let's use 2 as default (when 0 is supplied)
	 */ /* write back */ /* validate extra bufs */ /*if (vpna->mfs > netmap_buf_size)  TODO netmap_buf_size is zero??
		vpna->mfs = netmap_buf_size; */ /* persistent VALE ports look like hw devices
	 * with a native netmap adapter
	 */ /* other nmd fields are set in the common routine */