FreeBSD/sys/dev/e1000/if_em.c
/*********************************************************************
 *
 *  Setup networking device structure and register an interface.
 *
 **********************************************************************/
Setup networking device structure and register an interface.
Setup networking device structure and register an interface .
static int
em_setup_interface(device_t dev, struct adapter *adapter)
{
	if_t ifp;
	INIT_DEBUGOUT("em_setup_interface: begin");
	ifp = adapter->ifp = if_gethandle(IFT_ETHER);
	if (ifp == 0) {
		device_printf(dev, "can not allocate ifnet structure\n");
		return (-1);
	}
	if_initname(ifp, device_get_name(dev), device_get_unit(dev));
	if_setdev(ifp, dev);
	if_setinitfn(ifp, em_init);
	if_setsoftc(ifp, adapter);
	if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
	if_setioctlfn(ifp, em_ioctl);
	if_setgetcounterfn(ifp, em_get_counter);
	ifp->if_hw_tsomax = IP_MAXPACKET;
	ifp->if_hw_tsomaxsegcount = EM_MAX_SCATTER - 5;
	ifp->if_hw_tsomaxsegsize = EM_TSO_SEG_SIZE;
#ifdef EM_MULTIQUEUE
	if_settransmitfn(ifp, em_mq_start);
	if_setqflushfn(ifp, em_qflush);
#else
	if_setstartfn(ifp, em_start);
	if_setsendqlen(ifp, adapter->num_tx_desc - 1);
	if_setsendqready(ifp);
#endif	
	ether_ifattach(ifp, adapter->hw.mac.addr);
	if_setcapabilities(ifp, 0);
	if_setcapenable(ifp, 0);
	if_setcapabilitiesbit(ifp, IFCAP_HWCSUM | IFCAP_VLAN_HWCSUM |
	    IFCAP_TSO4, 0);
	if_setifheaderlen(ifp, sizeof(struct ether_vlan_header));
	if_setcapabilitiesbit(ifp, IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_HWTSO |
	    IFCAP_VLAN_MTU, 0);
	if_setcapenable(ifp, if_getcapabilities(ifp));
	if_setcapabilitiesbit(ifp, IFCAP_VLAN_HWFILTER,0);
#ifdef DEVICE_POLLING
	if_setcapabilitiesbit(ifp, IFCAP_POLLING,0);
#endif
	if (adapter->wol) {
		if_setcapabilitiesbit(ifp, IFCAP_WOL, 0);
		if_setcapenablebit(ifp, IFCAP_WOL_MAGIC, 0);
	}
	ifmedia_init(&adapter->media, IFM_IMASK,
	    em_media_change, em_media_status);
	if ((adapter->hw.phy.media_type == e1000_media_type_fiber) ||
	    (adapter->hw.phy.media_type == e1000_media_type_internal_serdes)) {
		u_char fiber_type = IFM_1000_SX;	
		ifmedia_add(&adapter->media, IFM_ETHER | fiber_type | IFM_FDX, 
			    0, NULL);
		ifmedia_add(&adapter->media, IFM_ETHER | fiber_type, 0, NULL);
	} else {
		ifmedia_add(&adapter->media, IFM_ETHER | IFM_10_T, 0, NULL);
		ifmedia_add(&adapter->media, IFM_ETHER | IFM_10_T | IFM_FDX,
			    0, NULL);
		ifmedia_add(&adapter->media, IFM_ETHER | IFM_100_TX,
			    0, NULL);
		ifmedia_add(&adapter->media, IFM_ETHER | IFM_100_TX | IFM_FDX,
			    0, NULL);
		if (adapter->hw.phy.type != e1000_phy_ife) {
			ifmedia_add(&adapter->media,
				IFM_ETHER | IFM_1000_T | IFM_FDX, 0, NULL);
			ifmedia_add(&adapter->media,
				IFM_ETHER | IFM_1000_T, 0, NULL);
		}
	}
	ifmedia_add(&adapter->media, IFM_ETHER | IFM_AUTO, 0, NULL);
	ifmedia_set(&adapter->media, IFM_ETHER | IFM_AUTO);
	return (0);
}
static int em_setup_interface ( device_t dev , struct adapter * adapter ) { if_t ifp ; INIT_DEBUGOUT ( " " ) ; ifp = adapter -> ifp = if_gethandle ( IFT_ETHER ) ; if ( ifp == 0 ) { device_printf ( dev , " \n " ) ; return ( -1 ) ; } if_initname ( ifp , device_get_name ( dev ) , device_get_unit ( dev ) ) ; if_setdev ( ifp , dev ) ; if_setinitfn ( ifp , em_init ) ; if_setsoftc ( ifp , adapter ) ; if_setflags ( ifp , IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST ) ; if_setioctlfn ( ifp , em_ioctl ) ; if_setgetcounterfn ( ifp , em_get_counter ) ; ifp -> if_hw_tsomax = IP_MAXPACKET ; ifp -> if_hw_tsomaxsegcount = EM_MAX_SCATTER - 5 ; ifp -> if_hw_tsomaxsegsize = EM_TSO_SEG_SIZE ; #ifdef EM_MULTIQUEUE if_settransmitfn ( ifp , em_mq_start ) ; if_setqflushfn ( ifp , em_qflush ) ; #else if_setstartfn ( ifp , em_start ) ; if_setsendqlen ( ifp , adapter -> num_tx_desc - 1 ) ; if_setsendqready ( ifp ) ; #endif ether_ifattach ( ifp , adapter -> hw . mac . addr ) ; if_setcapabilities ( ifp , 0 ) ; if_setcapenable ( ifp , 0 ) ; if_setcapabilitiesbit ( ifp , IFCAP_HWCSUM | IFCAP_VLAN_HWCSUM | IFCAP_TSO4 , 0 ) ; if_setifheaderlen ( ifp , sizeof ( struct ether_vlan_header ) ) ; if_setcapabilitiesbit ( ifp , IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_HWTSO | IFCAP_VLAN_MTU , 0 ) ; if_setcapenable ( ifp , if_getcapabilities ( ifp ) ) ; if_setcapabilitiesbit ( ifp , IFCAP_VLAN_HWFILTER , 0 ) ; #ifdef DEVICE_POLLING if_setcapabilitiesbit ( ifp , IFCAP_POLLING , 0 ) ; #endif if ( adapter -> wol ) { if_setcapabilitiesbit ( ifp , IFCAP_WOL , 0 ) ; if_setcapenablebit ( ifp , IFCAP_WOL_MAGIC , 0 ) ; } ifmedia_init ( & adapter -> media , IFM_IMASK , em_media_change , em_media_status ) ; if ( ( adapter -> hw . phy . media_type == e1000_media_type_fiber ) || ( adapter -> hw . phy . media_type == e1000_media_type_internal_serdes ) ) { u_char fiber_type = IFM_1000_SX ; ifmedia_add ( & adapter -> media , IFM_ETHER | fiber_type | IFM_FDX , 0 , NULL ) ; ifmedia_add ( & adapter -> media , IFM_ETHER | fiber_type , 0 , NULL ) ; } else { ifmedia_add ( & adapter -> media , IFM_ETHER | IFM_10_T , 0 , NULL ) ; ifmedia_add ( & adapter -> media , IFM_ETHER | IFM_10_T | IFM_FDX , 0 , NULL ) ; ifmedia_add ( & adapter -> media , IFM_ETHER | IFM_100_TX , 0 , NULL ) ; ifmedia_add ( & adapter -> media , IFM_ETHER | IFM_100_TX | IFM_FDX , 0 , NULL ) ; if ( adapter -> hw . phy . type != e1000_phy_ife ) { ifmedia_add ( & adapter -> media , IFM_ETHER | IFM_1000_T | IFM_FDX , 0 , NULL ) ; ifmedia_add ( & adapter -> media , IFM_ETHER | IFM_1000_T , 0 , NULL ) ; } } ifmedia_add ( & adapter -> media , IFM_ETHER | IFM_AUTO , 0 , NULL ) ; ifmedia_set ( & adapter -> media , IFM_ETHER | IFM_AUTO ) ; return ( 0 ) ; }
Setup networking device structure and register an interface.
Setup networking device structure and register an interface .
/* TSO parameters */ /* Take m_pullup(9)'s in em_xmit() w/ TSO into acount. */ /* Multiqueue stack interface */ /*
	 * Tell the upper layer(s) we
	 * support full VLAN capability
	 */ /*
	** Don't turn this on by default, if vlans are
	** created on another pseudo device (eg. lagg)
	** then vlan events are not passed thru, breaking
	** operation, but with HW FILTER off it works. If
	** using vlans directly on the em driver you can
	** enable this and get full hardware tag filtering.
	*/ /* Enable only WOL MAGIC by default */ /*
	 * Specify the media types supported by this adapter and register
	 * callbacks to update media and link information
	 */ /* default type */