FreeBSD/sys/dev/ixl/ixl_pf_main.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 .
int
ixl_setup_interface(device_t dev, struct ixl_vsi *vsi)
{
	struct ifnet		*ifp;
	struct i40e_hw		*hw = vsi->hw;
	struct ixl_queue	*que = vsi->queues;
	struct i40e_aq_get_phy_abilities_resp abilities;
	enum i40e_status_code aq_error = 0;
	INIT_DEBUGOUT("ixl_setup_interface: begin");
	ifp = vsi->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_mtu = ETHERMTU;
	ifp->if_baudrate = IF_Gbps(40);
	ifp->if_init = ixl_init;
	ifp->if_softc = vsi;
	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
	ifp->if_ioctl = ixl_ioctl;
#if __FreeBSD_version >= 1100036
	if_setgetcounterfn(ifp, ixl_get_counter);
#endif
	ifp->if_transmit = ixl_mq_start;
	ifp->if_qflush = ixl_qflush;
	ifp->if_snd.ifq_maxlen = que->num_desc - 2;
	vsi->max_frame_size =
	    ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN
	    + ETHER_VLAN_ENCAP_LEN;
	ifp->if_hw_tsomax = IP_MAXPACKET - (ETHER_HDR_LEN + ETHER_CRC_LEN);
	ifp->if_hw_tsomaxsegcount = IXL_MAX_TSO_SEGS;
	ifp->if_hw_tsomaxsegsize = PAGE_SIZE;
	ifp->if_hdrlen = sizeof(struct ether_vlan_header);
	ifp->if_capabilities |= IFCAP_HWCSUM;
	ifp->if_capabilities |= IFCAP_HWCSUM_IPV6;
	ifp->if_capabilities |= IFCAP_TSO;
	ifp->if_capabilities |= IFCAP_JUMBO_MTU;
	ifp->if_capabilities |= IFCAP_LRO;
	ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING
			     |  IFCAP_VLAN_HWTSO
			     |  IFCAP_VLAN_MTU
			     |  IFCAP_VLAN_HWCSUM;
	ifp->if_capenable = ifp->if_capabilities;
	ifp->if_capabilities |= IFCAP_VLAN_HWFILTER;
	ifmedia_init(&vsi->media, IFM_IMASK, ixl_media_change,
		     ixl_media_status);
	aq_error = i40e_aq_get_phy_capabilities(hw,
	    FALSE, TRUE, &abilities, NULL);
	if (aq_error == I40E_ERR_UNKNOWN_PHY) {
		i40e_msec_delay(200);
		aq_error = i40e_aq_get_phy_capabilities(hw, FALSE,
		    TRUE, &abilities, NULL);
	}
	if (aq_error) {
		if (aq_error == I40E_ERR_UNKNOWN_PHY)
			device_printf(dev, "Unknown PHY type detected!\n");
		else
			device_printf(dev,
			    "Error getting supported media types, err %d,"
			    " AQ error %d\n", aq_error, hw->aq.asq_last_status);
		return (0);
	}
	ixl_add_ifmedia(vsi, abilities.phy_type);
	ifmedia_add(&vsi->media, IFM_ETHER | IFM_AUTO, 0, NULL);
	ifmedia_set(&vsi->media, IFM_ETHER | IFM_AUTO);
	ether_ifattach(ifp, hw->mac.addr);
	return (0);
}
int ixl_setup_interface ( device_t dev , struct ixl_vsi * vsi ) { struct ifnet * ifp ; struct i40e_hw * hw = vsi -> hw ; struct ixl_queue * que = vsi -> queues ; struct i40e_aq_get_phy_abilities_resp abilities ; enum i40e_status_code aq_error = 0 ; INIT_DEBUGOUT ( " " ) ; ifp = vsi -> 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_mtu = ETHERMTU ; ifp -> if_baudrate = IF_Gbps ( 40 ) ; ifp -> if_init = ixl_init ; ifp -> if_softc = vsi ; ifp -> if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST ; ifp -> if_ioctl = ixl_ioctl ; #if __FreeBSD_version >= 1100036 if_setgetcounterfn ( ifp , ixl_get_counter ) ; #endif ifp -> if_transmit = ixl_mq_start ; ifp -> if_qflush = ixl_qflush ; ifp -> if_snd . ifq_maxlen = que -> num_desc - 2 ; vsi -> max_frame_size = ifp -> if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN + ETHER_VLAN_ENCAP_LEN ; ifp -> if_hw_tsomax = IP_MAXPACKET - ( ETHER_HDR_LEN + ETHER_CRC_LEN ) ; ifp -> if_hw_tsomaxsegcount = IXL_MAX_TSO_SEGS ; ifp -> if_hw_tsomaxsegsize = PAGE_SIZE ; ifp -> if_hdrlen = sizeof ( struct ether_vlan_header ) ; ifp -> if_capabilities |= IFCAP_HWCSUM ; ifp -> if_capabilities |= IFCAP_HWCSUM_IPV6 ; ifp -> if_capabilities |= IFCAP_TSO ; ifp -> if_capabilities |= IFCAP_JUMBO_MTU ; ifp -> if_capabilities |= IFCAP_LRO ; ifp -> if_capabilities |= IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_HWTSO | IFCAP_VLAN_MTU | IFCAP_VLAN_HWCSUM ; ifp -> if_capenable = ifp -> if_capabilities ; ifp -> if_capabilities |= IFCAP_VLAN_HWFILTER ; ifmedia_init ( & vsi -> media , IFM_IMASK , ixl_media_change , ixl_media_status ) ; aq_error = i40e_aq_get_phy_capabilities ( hw , FALSE , TRUE , & abilities , NULL ) ; if ( aq_error == I40E_ERR_UNKNOWN_PHY ) { i40e_msec_delay ( 200 ) ; aq_error = i40e_aq_get_phy_capabilities ( hw , FALSE , TRUE , & abilities , NULL ) ; } if ( aq_error ) { if ( aq_error == I40E_ERR_UNKNOWN_PHY ) device_printf ( dev , " \n " ) ; else device_printf ( dev , " " " \n " , aq_error , hw -> aq . asq_last_status ) ; return ( 0 ) ; } ixl_add_ifmedia ( vsi , abilities . phy_type ) ; ifmedia_add ( & vsi -> media , IFM_ETHER | IFM_AUTO , 0 , NULL ) ; ifmedia_set ( & vsi -> media , IFM_ETHER | IFM_AUTO ) ; ether_ifattach ( ifp , hw -> mac . addr ) ; return ( 0 ) ; }
Setup networking device structure and register an interface.
Setup networking device structure and register an interface .
/* Set TSO limits */ /*
	 * Tell the upper layer(s) we support long frames.
	 */ /* VLAN capabilties */ /*
	** 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 ixl 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
	 */ /* May need delay to detect fiber correctly */ /* Use autoselect media by default */