src/dpdk/drivers/net/ixgbe/base/ixgbe_82599.c
s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw,
			       ixgbe_link_speed speed,
			       bool autoneg_wait_to_complete)
{
	bool autoneg = false;
	s32 status = IXGBE_SUCCESS;
	u32 pma_pmd_1g, link_mode;
	u32 current_autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC); /* holds the value of AUTOC register at this current point in time */
	u32 orig_autoc = 0; /* holds the cached value of AUTOC register */
	u32 autoc = current_autoc; /* Temporary variable used for comparison purposes */
	u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
	u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK;
	u32 links_reg;
	u32 i;
	ixgbe_link_speed link_capabilities = IXGBE_LINK_SPEED_UNKNOWN;

	DEBUGFUNC("ixgbe_setup_mac_link_82599");

	/* Check to see if speed passed in is supported. */
	status = ixgbe_get_link_capabilities(hw, &link_capabilities, &autoneg);
	if (status)
		goto out;

	speed &= link_capabilities;

	if (speed == IXGBE_LINK_SPEED_UNKNOWN) {
		status = IXGBE_ERR_LINK_SETUP;
		goto out;
	}

	/* Use stored value (EEPROM defaults) of AUTOC to find KR/KX4 support*/
	if (hw->mac.orig_link_settings_stored)
		orig_autoc = hw->mac.orig_autoc;
	else
		orig_autoc = autoc;

	link_mode = autoc & IXGBE_AUTOC_LMS_MASK;
	pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;

	if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
	    link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
	    link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
		/* Set KX4/KX/KR support according to speed requested */
		autoc &= ~(IXGBE_AUTOC_KX4_KX_SUPP_MASK | IXGBE_AUTOC_KR_SUPP);
		if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
			if (orig_autoc & IXGBE_AUTOC_KX4_SUPP)
				autoc |= IXGBE_AUTOC_KX4_SUPP;
			if ((orig_autoc & IXGBE_AUTOC_KR_SUPP) &&
			    (hw->phy.smart_speed_active == false))
				autoc |= IXGBE_AUTOC_KR_SUPP;
		}
		if (speed & IXGBE_LINK_SPEED_1GB_FULL)
			autoc |= IXGBE_AUTOC_KX_SUPP;
	} else if ((pma_pmd_1g == IXGBE_AUTOC_1G_SFI) &&
		   (link_mode == IXGBE_AUTOC_LMS_1G_LINK_NO_AN ||
		    link_mode == IXGBE_AUTOC_LMS_1G_AN)) {
		/* Switch from 1G SFI to 10G SFI if requested */
		if ((speed == IXGBE_LINK_SPEED_10GB_FULL) &&
		    (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI)) {
			autoc &= ~IXGBE_AUTOC_LMS_MASK;
			autoc |= IXGBE_AUTOC_LMS_10G_SERIAL;
		}
	} else if ((pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI) &&
		   (link_mode == IXGBE_AUTOC_LMS_10G_SERIAL)) {
		/* Switch from 10G SFI to 1G SFI if requested */
		if ((speed == IXGBE_LINK_SPEED_1GB_FULL) &&
		    (pma_pmd_1g == IXGBE_AUTOC_1G_SFI)) {
			autoc &= ~IXGBE_AUTOC_LMS_MASK;
			if (autoneg || hw->phy.type == ixgbe_phy_qsfp_intel)
				autoc |= IXGBE_AUTOC_LMS_1G_AN;
			else
				autoc |= IXGBE_AUTOC_LMS_1G_LINK_NO_AN;
		}
	}

	if (autoc != current_autoc) {
		/* Restart link */
		status = hw->mac.ops.prot_autoc_write(hw, autoc, false);
		if (status != IXGBE_SUCCESS)
			goto out;

		/* Only poll for autoneg to complete if specified to do so */
		if (autoneg_wait_to_complete) {
			if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
			    link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
			    link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
				links_reg = 0; /*Just in case Autoneg time=0*/
				for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
					links_reg =
					       IXGBE_READ_REG(hw, IXGBE_LINKS);
					if (links_reg & IXGBE_LINKS_KX_AN_COMP)
						break;
					msec_delay(100);
				}
				if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
					status =
						IXGBE_ERR_AUTONEG_NOT_COMPLETE;
					DEBUGOUT("Autoneg did not complete.\n");
				}
			}
		}

		/* Add delay to filter out noises during initial link setup */
		msec_delay(50);
	}

out:
	return status;
}
/**
 * ixgbe_setup_mac_link_82599 - Set MAC link speed
 * @hw: pointer to hardware structure
 * @speed: new link speed
 * @autoneg_wait_to_complete: true when waiting for completion is needed
 *
 * Set the link speed in the AUTOC register and restarts link.
 **/
Set MAC link speed
@hw: pointer to hardware structure
@speed: new link speed
@autoneg_wait_to_complete: true when waiting for completion is needed

Set the link speed in the AUTOC register and restarts link.
Set MAC link speed @hw : pointer to hardware structure @speed : new link speed @autoneg_wait_to_complete : true when waiting for completion is needed Set the link speed in the AUTOC register and restarts link .
s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw,
			       ixgbe_link_speed speed,
			       bool autoneg_wait_to_complete)
{
	bool autoneg = false;
	s32 status = IXGBE_SUCCESS;
	u32 pma_pmd_1g, link_mode;
	u32 current_autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC); 
	u32 orig_autoc = 0; 
	u32 autoc = current_autoc; 
	u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
	u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK;
	u32 links_reg;
	u32 i;
	ixgbe_link_speed link_capabilities = IXGBE_LINK_SPEED_UNKNOWN;
	DEBUGFUNC("ixgbe_setup_mac_link_82599");
	status = ixgbe_get_link_capabilities(hw, &link_capabilities, &autoneg);
	if (status)
		goto out;
	speed &= link_capabilities;
	if (speed == IXGBE_LINK_SPEED_UNKNOWN) {
		status = IXGBE_ERR_LINK_SETUP;
		goto out;
	}
	if (hw->mac.orig_link_settings_stored)
		orig_autoc = hw->mac.orig_autoc;
	else
		orig_autoc = autoc;
	link_mode = autoc & IXGBE_AUTOC_LMS_MASK;
	pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;
	if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
	    link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
	    link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
		autoc &= ~(IXGBE_AUTOC_KX4_KX_SUPP_MASK | IXGBE_AUTOC_KR_SUPP);
		if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
			if (orig_autoc & IXGBE_AUTOC_KX4_SUPP)
				autoc |= IXGBE_AUTOC_KX4_SUPP;
			if ((orig_autoc & IXGBE_AUTOC_KR_SUPP) &&
			    (hw->phy.smart_speed_active == false))
				autoc |= IXGBE_AUTOC_KR_SUPP;
		}
		if (speed & IXGBE_LINK_SPEED_1GB_FULL)
			autoc |= IXGBE_AUTOC_KX_SUPP;
	} else if ((pma_pmd_1g == IXGBE_AUTOC_1G_SFI) &&
		   (link_mode == IXGBE_AUTOC_LMS_1G_LINK_NO_AN ||
		    link_mode == IXGBE_AUTOC_LMS_1G_AN)) {
		if ((speed == IXGBE_LINK_SPEED_10GB_FULL) &&
		    (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI)) {
			autoc &= ~IXGBE_AUTOC_LMS_MASK;
			autoc |= IXGBE_AUTOC_LMS_10G_SERIAL;
		}
	} else if ((pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI) &&
		   (link_mode == IXGBE_AUTOC_LMS_10G_SERIAL)) {
		if ((speed == IXGBE_LINK_SPEED_1GB_FULL) &&
		    (pma_pmd_1g == IXGBE_AUTOC_1G_SFI)) {
			autoc &= ~IXGBE_AUTOC_LMS_MASK;
			if (autoneg || hw->phy.type == ixgbe_phy_qsfp_intel)
				autoc |= IXGBE_AUTOC_LMS_1G_AN;
			else
				autoc |= IXGBE_AUTOC_LMS_1G_LINK_NO_AN;
		}
	}
	if (autoc != current_autoc) {
		status = hw->mac.ops.prot_autoc_write(hw, autoc, false);
		if (status != IXGBE_SUCCESS)
			goto out;
		if (autoneg_wait_to_complete) {
			if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
			    link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
			    link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
				links_reg = 0; 
				for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
					links_reg =
					       IXGBE_READ_REG(hw, IXGBE_LINKS);
					if (links_reg & IXGBE_LINKS_KX_AN_COMP)
						break;
					msec_delay(100);
				}
				if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
					status =
						IXGBE_ERR_AUTONEG_NOT_COMPLETE;
					DEBUGOUT("Autoneg did not complete.\n");
				}
			}
		}
		msec_delay(50);
	}
out:
	return status;
}
s32 ixgbe_setup_mac_link_82599 ( struct ixgbe_hw * hw , ixgbe_link_speed speed , bool autoneg_wait_to_complete ) { bool autoneg = false ; s32 status = IXGBE_SUCCESS ; u32 pma_pmd_1g , link_mode ; u32 current_autoc = IXGBE_READ_REG ( hw , IXGBE_AUTOC ) ; u32 orig_autoc = 0 ; u32 autoc = current_autoc ; u32 autoc2 = IXGBE_READ_REG ( hw , IXGBE_AUTOC2 ) ; u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK ; u32 links_reg ; u32 i ; ixgbe_link_speed link_capabilities = IXGBE_LINK_SPEED_UNKNOWN ; DEBUGFUNC ( " " ) ; status = ixgbe_get_link_capabilities ( hw , & link_capabilities , & autoneg ) ; if ( status ) goto out ; speed &= link_capabilities ; if ( speed == IXGBE_LINK_SPEED_UNKNOWN ) { status = IXGBE_ERR_LINK_SETUP ; goto out ; } if ( hw -> mac . orig_link_settings_stored ) orig_autoc = hw -> mac . orig_autoc ; else orig_autoc = autoc ; link_mode = autoc & IXGBE_AUTOC_LMS_MASK ; pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK ; if ( link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR || link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN || link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII ) { autoc &= ~ ( IXGBE_AUTOC_KX4_KX_SUPP_MASK | IXGBE_AUTOC_KR_SUPP ) ; if ( speed & IXGBE_LINK_SPEED_10GB_FULL ) { if ( orig_autoc & IXGBE_AUTOC_KX4_SUPP ) autoc |= IXGBE_AUTOC_KX4_SUPP ; if ( ( orig_autoc & IXGBE_AUTOC_KR_SUPP ) && ( hw -> phy . smart_speed_active == false ) ) autoc |= IXGBE_AUTOC_KR_SUPP ; } if ( speed & IXGBE_LINK_SPEED_1GB_FULL ) autoc |= IXGBE_AUTOC_KX_SUPP ; } else if ( ( pma_pmd_1g == IXGBE_AUTOC_1G_SFI ) && ( link_mode == IXGBE_AUTOC_LMS_1G_LINK_NO_AN || link_mode == IXGBE_AUTOC_LMS_1G_AN ) ) { if ( ( speed == IXGBE_LINK_SPEED_10GB_FULL ) && ( pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI ) ) { autoc &= ~ IXGBE_AUTOC_LMS_MASK ; autoc |= IXGBE_AUTOC_LMS_10G_SERIAL ; } } else if ( ( pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI ) && ( link_mode == IXGBE_AUTOC_LMS_10G_SERIAL ) ) { if ( ( speed == IXGBE_LINK_SPEED_1GB_FULL ) && ( pma_pmd_1g == IXGBE_AUTOC_1G_SFI ) ) { autoc &= ~ IXGBE_AUTOC_LMS_MASK ; if ( autoneg || hw -> phy . type == ixgbe_phy_qsfp_intel ) autoc |= IXGBE_AUTOC_LMS_1G_AN ; else autoc |= IXGBE_AUTOC_LMS_1G_LINK_NO_AN ; } } if ( autoc != current_autoc ) { status = hw -> mac . ops . prot_autoc_write ( hw , autoc , false ) ; if ( status != IXGBE_SUCCESS ) goto out ; if ( autoneg_wait_to_complete ) { if ( link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR || link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN || link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII ) { links_reg = 0 ; for ( i = 0 ; i < IXGBE_AUTO_NEG_TIME ; i ++ ) { links_reg = IXGBE_READ_REG ( hw , IXGBE_LINKS ) ; if ( links_reg & IXGBE_LINKS_KX_AN_COMP ) break ; msec_delay ( 100 ) ; } if ( ! ( links_reg & IXGBE_LINKS_KX_AN_COMP ) ) { status = IXGBE_ERR_AUTONEG_NOT_COMPLETE ; DEBUGOUT ( " \n " ) ; } } } msec_delay ( 50 ) ; } out : return status ; }
ixgbe_setup_mac_link_82599 - Set MAC link speed
 @hw: pointer to hardware structure
 @speed: new link speed
 @autoneg_wait_to_complete: true when waiting for completion is needed
ixgbe_setup_mac_link_82599 - Set MAC link speed @hw : pointer to hardware structure @speed : new link speed @autoneg_wait_to_complete : true when waiting for completion is needed
/* holds the value of AUTOC register at this current point in time */ /* holds the cached value of AUTOC register */ /* Temporary variable used for comparison purposes */ /* Check to see if speed passed in is supported. */ /* Use stored value (EEPROM defaults) of AUTOC to find KR/KX4 support*/ /* Set KX4/KX/KR support according to speed requested */ /* Switch from 1G SFI to 10G SFI if requested */ /* Switch from 10G SFI to 1G SFI if requested */ /* Restart link */ /* Only poll for autoneg to complete if specified to do so */ /*Just in case Autoneg time=0*/ /* Add delay to filter out noises during initial link setup */