FreeBSD/sys/dev/xen/netfront/netfront.c
/**
 * Create a network device.
 * @param dev  Newbus device representing this virtual NIC.
 */
Create a network device.
@param dev  Newbus device representing this virtual NIC.
Create a network device . @param dev Newbus device representing this virtual NIC .
int
create_netdev(device_t dev)
{
	struct netfront_info *np;
	int err;
	struct ifnet *ifp;
	np = device_get_softc(dev);
	np->xbdev         = dev;
	mtx_init(&np->sc_lock, "xnsc", "netfront softc lock", MTX_DEF);
	ifmedia_init(&np->sc_media, 0, xn_ifmedia_upd, xn_ifmedia_sts);
	ifmedia_add(&np->sc_media, IFM_ETHER|IFM_MANUAL, 0, NULL);
	ifmedia_set(&np->sc_media, IFM_ETHER|IFM_MANUAL);
	err = xen_net_read_mac(dev, np->mac);
	if (err != 0)
		goto error;
	ifp = np->xn_ifp = if_alloc(IFT_ETHER);
    	ifp->if_softc = np;
    	if_initname(ifp, "xn",  device_get_unit(dev));
    	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
    	ifp->if_ioctl = xn_ioctl;
	ifp->if_transmit = xn_txq_mq_start;
	ifp->if_qflush = xn_qflush;
    	ifp->if_init = xn_ifinit;
    	ifp->if_hwassist = XN_CSUM_FEATURES;
	ifp->if_capenable = ifp->if_capabilities =
	    IFCAP_HWCSUM|IFCAP_TSO4|IFCAP_LRO;
	ifp->if_hw_tsomax = 65536 - (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN);
	ifp->if_hw_tsomaxsegcount = MAX_TX_REQ_FRAGS;
	ifp->if_hw_tsomaxsegsize = PAGE_SIZE;
    	ether_ifattach(ifp, np->mac);
	netfront_carrier_off(np);
	return (0);
error:
	KASSERT(err != 0, ("Error path with no error code specified"));
	return (err);
}
int create_netdev ( device_t dev ) { struct netfront_info * np ; int err ; struct ifnet * ifp ; np = device_get_softc ( dev ) ; np -> xbdev = dev ; mtx_init ( & np -> sc_lock , " " , " " , MTX_DEF ) ; ifmedia_init ( & np -> sc_media , 0 , xn_ifmedia_upd , xn_ifmedia_sts ) ; ifmedia_add ( & np -> sc_media , IFM_ETHER | IFM_MANUAL , 0 , NULL ) ; ifmedia_set ( & np -> sc_media , IFM_ETHER | IFM_MANUAL ) ; err = xen_net_read_mac ( dev , np -> mac ) ; if ( err != 0 ) goto error ; ifp = np -> xn_ifp = if_alloc ( IFT_ETHER ) ; ifp -> if_softc = np ; if_initname ( ifp , " " , device_get_unit ( dev ) ) ; ifp -> if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST ; ifp -> if_ioctl = xn_ioctl ; ifp -> if_transmit = xn_txq_mq_start ; ifp -> if_qflush = xn_qflush ; ifp -> if_init = xn_ifinit ; ifp -> if_hwassist = XN_CSUM_FEATURES ; ifp -> if_capenable = ifp -> if_capabilities = IFCAP_HWCSUM | IFCAP_TSO4 | IFCAP_LRO ; ifp -> if_hw_tsomax = 65536 - ( ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN ) ; ifp -> if_hw_tsomaxsegcount = MAX_TX_REQ_FRAGS ; ifp -> if_hw_tsomaxsegsize = PAGE_SIZE ; ether_ifattach ( ifp , np -> mac ) ; netfront_carrier_off ( np ) ; return ( 0 ) ; error : KASSERT ( err != 0 , ( " " ) ) ; return ( err ) ; }
Create a network device.
Create a network device .
/* Set up ifnet structure */ /* Enable all supported features at device creation. */