src/dpdk/drivers/net/txgbe/base/txgbe_hw.c
s32 txgbe_setup_mac_link_smartspeed(struct txgbe_hw *hw,
				    u32 speed,
				    bool autoneg_wait_to_complete)
{
	s32 status = 0;
	u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
	s32 i, j;
	bool link_up = false;
	u32 autoc_reg = rd32_epcs(hw, SR_AN_MMD_ADV_REG1);

	DEBUGFUNC("txgbe_setup_mac_link_smartspeed");

	 /* Set autoneg_advertised value based on input link speed */
	hw->phy.autoneg_advertised = 0;

	if (speed & TXGBE_LINK_SPEED_10GB_FULL)
		hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_10GB_FULL;

	if (speed & TXGBE_LINK_SPEED_1GB_FULL)
		hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_1GB_FULL;

	if (speed & TXGBE_LINK_SPEED_100M_FULL)
		hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_100M_FULL;

	/*
	 * Implement Intel SmartSpeed algorithm.  SmartSpeed will reduce the
	 * autoneg advertisement if link is unable to be established at the
	 * highest negotiated rate.  This can sometimes happen due to integrity
	 * issues with the physical media connection.
	 */

	/* First, try to get link with full advertisement */
	hw->phy.smart_speed_active = false;
	for (j = 0; j < TXGBE_SMARTSPEED_MAX_RETRIES; j++) {
		status = txgbe_setup_mac_link(hw, speed,
						    autoneg_wait_to_complete);
		if (status != 0)
			goto out;

		/*
		 * Wait for the controller to acquire link.  Per IEEE 802.3ap,
		 * Section 73.10.2, we may have to wait up to 500ms if KR is
		 * attempted, or 200ms if KX/KX4/BX/BX4 is attempted, per
		 * Table 9 in the AN MAS.
		 */
		for (i = 0; i < 5; i++) {
			msec_delay(100);

			/* If we have link, just jump out */
			status = hw->mac.check_link(hw, &link_speed, &link_up,
						  false);
			if (status != 0)
				goto out;

			if (link_up)
				goto out;
		}
	}

	/*
	 * We didn't get link.  If we advertised KR plus one of KX4/KX
	 * (or BX4/BX), then disable KR and try again.
	 */
	if (((autoc_reg & TXGBE_AUTOC_KR_SUPP) == 0) ||
	    ((autoc_reg & TXGBE_AUTOC_KX_SUPP) == 0 &&
	     (autoc_reg & TXGBE_AUTOC_KX4_SUPP) == 0))
		goto out;

	/* Turn SmartSpeed on to disable KR support */
	hw->phy.smart_speed_active = true;
	status = txgbe_setup_mac_link(hw, speed,
					    autoneg_wait_to_complete);
	if (status != 0)
		goto out;

	/*
	 * Wait for the controller to acquire link.  600ms will allow for
	 * the AN link_fail_inhibit_timer as well for multiple cycles of
	 * parallel detect, both 10g and 1g. This allows for the maximum
	 * connect attempts as defined in the AN MAS table 73-7.
	 */
	for (i = 0; i < 6; i++) {
		msec_delay(100);

		/* If we have link, just jump out */
		status = hw->mac.check_link(hw, &link_speed, &link_up, false);
		if (status != 0)
			goto out;

		if (link_up)
			goto out;
	}

	/* We didn't get link.  Turn SmartSpeed back off. */
	hw->phy.smart_speed_active = false;
	status = txgbe_setup_mac_link(hw, speed,
					    autoneg_wait_to_complete);

out:
	if (link_up && link_speed == TXGBE_LINK_SPEED_1GB_FULL)
		DEBUGOUT("Smartspeed has downgraded the link speed "
		"from the maximum advertised\n");
	return status;
}
/**
 *  txgbe_setup_mac_link_smartspeed - Set MAC link speed using SmartSpeed
 *  @hw: pointer to hardware structure
 *  @speed: new link speed
 *  @autoneg_wait_to_complete: true when waiting for completion is needed
 *
 *  Implements the Intel SmartSpeed algorithm.
 **/
Set MAC link speed using SmartSpeed
@hw: pointer to hardware structure
@speed: new link speed
@autoneg_wait_to_complete: true when waiting for completion is needed

Implements the Intel SmartSpeed algorithm.
Set MAC link speed using SmartSpeed @hw : pointer to hardware structure @speed : new link speed @autoneg_wait_to_complete : true when waiting for completion is needed Implements the Intel SmartSpeed algorithm .
s32 txgbe_setup_mac_link_smartspeed(struct txgbe_hw *hw,
				    u32 speed,
				    bool autoneg_wait_to_complete)
{
	s32 status = 0;
	u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
	s32 i, j;
	bool link_up = false;
	u32 autoc_reg = rd32_epcs(hw, SR_AN_MMD_ADV_REG1);
	DEBUGFUNC("txgbe_setup_mac_link_smartspeed");
	hw->phy.autoneg_advertised = 0;
	if (speed & TXGBE_LINK_SPEED_10GB_FULL)
		hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_10GB_FULL;
	if (speed & TXGBE_LINK_SPEED_1GB_FULL)
		hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_1GB_FULL;
	if (speed & TXGBE_LINK_SPEED_100M_FULL)
		hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_100M_FULL;
	hw->phy.smart_speed_active = false;
	for (j = 0; j < TXGBE_SMARTSPEED_MAX_RETRIES; j++) {
		status = txgbe_setup_mac_link(hw, speed,
						    autoneg_wait_to_complete);
		if (status != 0)
			goto out;
		for (i = 0; i < 5; i++) {
			msec_delay(100);
			status = hw->mac.check_link(hw, &link_speed, &link_up,
						  false);
			if (status != 0)
				goto out;
			if (link_up)
				goto out;
		}
	}
	if (((autoc_reg & TXGBE_AUTOC_KR_SUPP) == 0) ||
	    ((autoc_reg & TXGBE_AUTOC_KX_SUPP) == 0 &&
	     (autoc_reg & TXGBE_AUTOC_KX4_SUPP) == 0))
		goto out;
	hw->phy.smart_speed_active = true;
	status = txgbe_setup_mac_link(hw, speed,
					    autoneg_wait_to_complete);
	if (status != 0)
		goto out;
	for (i = 0; i < 6; i++) {
		msec_delay(100);
		status = hw->mac.check_link(hw, &link_speed, &link_up, false);
		if (status != 0)
			goto out;
		if (link_up)
			goto out;
	}
	hw->phy.smart_speed_active = false;
	status = txgbe_setup_mac_link(hw, speed,
					    autoneg_wait_to_complete);
out:
	if (link_up && link_speed == TXGBE_LINK_SPEED_1GB_FULL)
		DEBUGOUT("Smartspeed has downgraded the link speed "
		"from the maximum advertised\n");
	return status;
}
s32 txgbe_setup_mac_link_smartspeed ( struct txgbe_hw * hw , u32 speed , bool autoneg_wait_to_complete ) { s32 status = 0 ; u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN ; s32 i , j ; bool link_up = false ; u32 autoc_reg = rd32_epcs ( hw , SR_AN_MMD_ADV_REG1 ) ; DEBUGFUNC ( " " ) ; hw -> phy . autoneg_advertised = 0 ; if ( speed & TXGBE_LINK_SPEED_10GB_FULL ) hw -> phy . autoneg_advertised |= TXGBE_LINK_SPEED_10GB_FULL ; if ( speed & TXGBE_LINK_SPEED_1GB_FULL ) hw -> phy . autoneg_advertised |= TXGBE_LINK_SPEED_1GB_FULL ; if ( speed & TXGBE_LINK_SPEED_100M_FULL ) hw -> phy . autoneg_advertised |= TXGBE_LINK_SPEED_100M_FULL ; hw -> phy . smart_speed_active = false ; for ( j = 0 ; j < TXGBE_SMARTSPEED_MAX_RETRIES ; j ++ ) { status = txgbe_setup_mac_link ( hw , speed , autoneg_wait_to_complete ) ; if ( status != 0 ) goto out ; for ( i = 0 ; i < 5 ; i ++ ) { msec_delay ( 100 ) ; status = hw -> mac . check_link ( hw , & link_speed , & link_up , false ) ; if ( status != 0 ) goto out ; if ( link_up ) goto out ; } } if ( ( ( autoc_reg & TXGBE_AUTOC_KR_SUPP ) == 0 ) || ( ( autoc_reg & TXGBE_AUTOC_KX_SUPP ) == 0 && ( autoc_reg & TXGBE_AUTOC_KX4_SUPP ) == 0 ) ) goto out ; hw -> phy . smart_speed_active = true ; status = txgbe_setup_mac_link ( hw , speed , autoneg_wait_to_complete ) ; if ( status != 0 ) goto out ; for ( i = 0 ; i < 6 ; i ++ ) { msec_delay ( 100 ) ; status = hw -> mac . check_link ( hw , & link_speed , & link_up , false ) ; if ( status != 0 ) goto out ; if ( link_up ) goto out ; } hw -> phy . smart_speed_active = false ; status = txgbe_setup_mac_link ( hw , speed , autoneg_wait_to_complete ) ; out : if ( link_up && link_speed == TXGBE_LINK_SPEED_1GB_FULL ) DEBUGOUT ( " " " \n " ) ; return status ; }
txgbe_setup_mac_link_smartspeed - Set MAC link speed using SmartSpeed
  @hw: pointer to hardware structure
  @speed: new link speed
  @autoneg_wait_to_complete: true when waiting for completion is needed
txgbe_setup_mac_link_smartspeed - Set MAC link speed using SmartSpeed @hw : pointer to hardware structure @speed : new link speed @autoneg_wait_to_complete : true when waiting for completion is needed
/* Set autoneg_advertised value based on input link speed */ /*
	 * Implement Intel SmartSpeed algorithm.  SmartSpeed will reduce the
	 * autoneg advertisement if link is unable to be established at the
	 * highest negotiated rate.  This can sometimes happen due to integrity
	 * issues with the physical media connection.
	 */ /* First, try to get link with full advertisement */ /*
		 * Wait for the controller to acquire link.  Per IEEE 802.3ap,
		 * Section 73.10.2, we may have to wait up to 500ms if KR is
		 * attempted, or 200ms if KX/KX4/BX/BX4 is attempted, per
		 * Table 9 in the AN MAS.
		 */ /* If we have link, just jump out */ /*
	 * We didn't get link.  If we advertised KR plus one of KX4/KX
	 * (or BX4/BX), then disable KR and try again.
	 */ /* Turn SmartSpeed on to disable KR support */ /*
	 * Wait for the controller to acquire link.  600ms will allow for
	 * the AN link_fail_inhibit_timer as well for multiple cycles of
	 * parallel detect, both 10g and 1g. This allows for the maximum
	 * connect attempts as defined in the AN MAS table 73-7.
	 */ /* If we have link, just jump out */ /* We didn't get link.  Turn SmartSpeed back off. */