FreeBSD/sys/dev/e1000/if_igb.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
igb_setup_interface(device_t dev, struct adapter *adapter)
{
	struct ifnet   *ifp;
	INIT_DEBUGOUT("igb_setup_interface: begin");
	ifp = adapter->ifp = if_alloc(IFT_ETHER);
	if (ifp == NULL) {
		device_printf(dev, "can not allocate ifnet structure\n");
		return (-1);
	}
	if_initname(ifp, device_get_name(dev), device_get_unit(dev));
	ifp->if_init =  igb_init;
	ifp->if_softc = adapter;
	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
	ifp->if_ioctl = igb_ioctl;
	ifp->if_get_counter = igb_get_counter;
	ifp->if_hw_tsomax = IP_MAXPACKET;
	ifp->if_hw_tsomaxsegcount = IGB_MAX_SCATTER;
	ifp->if_hw_tsomaxsegsize = IGB_TSO_SEG_SIZE;
#ifndef IGB_LEGACY_TX
	ifp->if_transmit = igb_mq_start;
	ifp->if_qflush = igb_qflush;
#else
	ifp->if_start = igb_start;
	IFQ_SET_MAXLEN(&ifp->if_snd, adapter->num_tx_desc - 1);
	ifp->if_snd.ifq_drv_maxlen = adapter->num_tx_desc - 1;
	IFQ_SET_READY(&ifp->if_snd);
#endif
	ether_ifattach(ifp, adapter->hw.mac.addr);
	ifp->if_capabilities = ifp->if_capenable = 0;
	ifp->if_capabilities = IFCAP_HWCSUM | IFCAP_VLAN_HWCSUM;
#if __FreeBSD_version >= 1000000
	ifp->if_capabilities |= IFCAP_HWCSUM_IPV6;
#endif
	ifp->if_capabilities |= IFCAP_TSO;
	ifp->if_capabilities |= IFCAP_JUMBO_MTU;
	ifp->if_capenable = ifp->if_capabilities;
	ifp->if_capabilities |= IFCAP_LRO;
#ifdef DEVICE_POLLING
	ifp->if_capabilities |= IFCAP_POLLING;
#endif
	ifp->if_hdrlen = sizeof(struct ether_vlan_header);
	ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING
			     |  IFCAP_VLAN_HWTSO
			     |  IFCAP_VLAN_MTU;
	ifp->if_capenable |= IFCAP_VLAN_HWTAGGING
			  |  IFCAP_VLAN_HWTSO
			  |  IFCAP_VLAN_MTU;
	ifp->if_capabilities |= IFCAP_VLAN_HWFILTER;
	ifmedia_init(&adapter->media, IFM_IMASK,
	    igb_media_change, igb_media_status);
	if ((adapter->hw.phy.media_type == e1000_media_type_fiber) ||
	    (adapter->hw.phy.media_type == e1000_media_type_internal_serdes)) {
		ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_SX | IFM_FDX, 
			    0, NULL);
		ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_SX, 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 igb_setup_interface ( device_t dev , struct adapter * adapter ) { struct ifnet * ifp ; INIT_DEBUGOUT ( " " ) ; ifp = adapter -> ifp = if_alloc ( IFT_ETHER ) ; if ( ifp == NULL ) { device_printf ( dev , " \n " ) ; return ( -1 ) ; } if_initname ( ifp , device_get_name ( dev ) , device_get_unit ( dev ) ) ; ifp -> if_init = igb_init ; ifp -> if_softc = adapter ; ifp -> if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST ; ifp -> if_ioctl = igb_ioctl ; ifp -> if_get_counter = igb_get_counter ; ifp -> if_hw_tsomax = IP_MAXPACKET ; ifp -> if_hw_tsomaxsegcount = IGB_MAX_SCATTER ; ifp -> if_hw_tsomaxsegsize = IGB_TSO_SEG_SIZE ; #ifndef IGB_LEGACY_TX ifp -> if_transmit = igb_mq_start ; ifp -> if_qflush = igb_qflush ; #else ifp -> if_start = igb_start ; IFQ_SET_MAXLEN ( & ifp -> if_snd , adapter -> num_tx_desc - 1 ) ; ifp -> if_snd . ifq_drv_maxlen = adapter -> num_tx_desc - 1 ; IFQ_SET_READY ( & ifp -> if_snd ) ; #endif ether_ifattach ( ifp , adapter -> hw . mac . addr ) ; ifp -> if_capabilities = ifp -> if_capenable = 0 ; ifp -> if_capabilities = IFCAP_HWCSUM | IFCAP_VLAN_HWCSUM ; #if __FreeBSD_version >= 1000000 ifp -> if_capabilities |= IFCAP_HWCSUM_IPV6 ; #endif ifp -> if_capabilities |= IFCAP_TSO ; ifp -> if_capabilities |= IFCAP_JUMBO_MTU ; ifp -> if_capenable = ifp -> if_capabilities ; ifp -> if_capabilities |= IFCAP_LRO ; #ifdef DEVICE_POLLING ifp -> if_capabilities |= IFCAP_POLLING ; #endif ifp -> if_hdrlen = sizeof ( struct ether_vlan_header ) ; ifp -> if_capabilities |= IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_HWTSO | IFCAP_VLAN_MTU ; ifp -> if_capenable |= IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_HWTSO | IFCAP_VLAN_MTU ; ifp -> if_capabilities |= IFCAP_VLAN_HWFILTER ; ifmedia_init ( & adapter -> media , IFM_IMASK , igb_media_change , igb_media_status ) ; if ( ( adapter -> hw . phy . media_type == e1000_media_type_fiber ) || ( adapter -> hw . phy . media_type == e1000_media_type_internal_serdes ) ) { ifmedia_add ( & adapter -> media , IFM_ETHER | IFM_1000_SX | IFM_FDX , 0 , NULL ) ; ifmedia_add ( & adapter -> media , IFM_ETHER | IFM_1000_SX , 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 */ /* Don't enable LRO by default */ /*
	 * 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 igb driver you can
	** enable this and get full hardware tag filtering.
	*/ /*
	 * Specify the media types supported by this adapter and register
	 * callbacks to update media and link information
	 */