src/dpdk/drivers/net/txgbe/base/txgbe_hw.c
s32 txgbe_setup_mac_link_multispeed_fiber(struct txgbe_hw *hw,
					  u32 speed,
					  bool autoneg_wait_to_complete)
{
	u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
	u32 highest_link_speed = TXGBE_LINK_SPEED_UNKNOWN;
	s32 status = 0;
	u32 speedcnt = 0;
	u32 i = 0;
	bool autoneg, link_up = false;

	DEBUGFUNC("txgbe_setup_mac_link_multispeed_fiber");

	/* Mask off requested but non-supported speeds */
	status = hw->mac.get_link_capabilities(hw, &link_speed, &autoneg);
	if (status != 0)
		return status;

	speed &= link_speed;

	/* Try each speed one by one, highest priority first.  We do this in
	 * software because 10Gb fiber doesn't support speed autonegotiation.
	 */
	if (speed & TXGBE_LINK_SPEED_10GB_FULL) {
		speedcnt++;
		highest_link_speed = TXGBE_LINK_SPEED_10GB_FULL;

		/* Set the module link speed */
		switch (hw->phy.media_type) {
		case txgbe_media_type_fiber:
			hw->mac.set_rate_select_speed(hw,
				TXGBE_LINK_SPEED_10GB_FULL);
			break;
		case txgbe_media_type_fiber_qsfp:
			/* QSFP module automatically detects MAC link speed */
			break;
		default:
			DEBUGOUT("Unexpected media type.\n");
			break;
		}

		/* Allow module to change analog characteristics (1G->10G) */
		msec_delay(40);

		status = hw->mac.setup_mac_link(hw,
				TXGBE_LINK_SPEED_10GB_FULL,
				autoneg_wait_to_complete);
		if (status != 0)
			return status;

		/* Flap the Tx laser if it has not already been done */
		hw->mac.flap_tx_laser(hw);

		/* 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.  uses the same timing for 10g SFI.
		 */
		for (i = 0; i < 5; i++) {
			/* Wait for the link partner to also set speed */
			msec_delay(100);

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

			if (link_up)
				goto out;
		}
	}

	if (speed & TXGBE_LINK_SPEED_1GB_FULL) {
		speedcnt++;
		if (highest_link_speed == TXGBE_LINK_SPEED_UNKNOWN)
			highest_link_speed = TXGBE_LINK_SPEED_1GB_FULL;

		/* Set the module link speed */
		switch (hw->phy.media_type) {
		case txgbe_media_type_fiber:
			hw->mac.set_rate_select_speed(hw,
				TXGBE_LINK_SPEED_1GB_FULL);
			break;
		case txgbe_media_type_fiber_qsfp:
			/* QSFP module automatically detects link speed */
			break;
		default:
			DEBUGOUT("Unexpected media type.\n");
			break;
		}

		/* Allow module to change analog characteristics (10G->1G) */
		msec_delay(40);

		status = hw->mac.setup_mac_link(hw,
				TXGBE_LINK_SPEED_1GB_FULL,
				autoneg_wait_to_complete);
		if (status != 0)
			return status;

		/* Flap the Tx laser if it has not already been done */
		hw->mac.flap_tx_laser(hw);

		/* Wait for the link partner to also set speed */
		msec_delay(100);

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

		if (link_up)
			goto out;
	}

	/* We didn't get link.  Configure back to the highest speed we tried,
	 * (if there was more than one).  We call ourselves back with just the
	 * single highest speed that the user requested.
	 */
	if (speedcnt > 1)
		status = txgbe_setup_mac_link_multispeed_fiber(hw,
						      highest_link_speed,
						      autoneg_wait_to_complete);

out:
	/* 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;

	return status;
}
/**
 *  txgbe_setup_mac_link_multispeed_fiber - 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 MAC and/or PHY 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 MAC and/or PHY 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 MAC and / or PHY register and restarts link .
s32 txgbe_setup_mac_link_multispeed_fiber(struct txgbe_hw *hw,
					  u32 speed,
					  bool autoneg_wait_to_complete)
{
	u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
	u32 highest_link_speed = TXGBE_LINK_SPEED_UNKNOWN;
	s32 status = 0;
	u32 speedcnt = 0;
	u32 i = 0;
	bool autoneg, link_up = false;
	DEBUGFUNC("txgbe_setup_mac_link_multispeed_fiber");
	status = hw->mac.get_link_capabilities(hw, &link_speed, &autoneg);
	if (status != 0)
		return status;
	speed &= link_speed;
	if (speed & TXGBE_LINK_SPEED_10GB_FULL) {
		speedcnt++;
		highest_link_speed = TXGBE_LINK_SPEED_10GB_FULL;
		switch (hw->phy.media_type) {
		case txgbe_media_type_fiber:
			hw->mac.set_rate_select_speed(hw,
				TXGBE_LINK_SPEED_10GB_FULL);
			break;
		case txgbe_media_type_fiber_qsfp:
			break;
		default:
			DEBUGOUT("Unexpected media type.\n");
			break;
		}
		msec_delay(40);
		status = hw->mac.setup_mac_link(hw,
				TXGBE_LINK_SPEED_10GB_FULL,
				autoneg_wait_to_complete);
		if (status != 0)
			return status;
		hw->mac.flap_tx_laser(hw);
		for (i = 0; i < 5; i++) {
			msec_delay(100);
			status = hw->mac.check_link(hw, &link_speed,
				&link_up, false);
			if (status != 0)
				return status;
			if (link_up)
				goto out;
		}
	}
	if (speed & TXGBE_LINK_SPEED_1GB_FULL) {
		speedcnt++;
		if (highest_link_speed == TXGBE_LINK_SPEED_UNKNOWN)
			highest_link_speed = TXGBE_LINK_SPEED_1GB_FULL;
		switch (hw->phy.media_type) {
		case txgbe_media_type_fiber:
			hw->mac.set_rate_select_speed(hw,
				TXGBE_LINK_SPEED_1GB_FULL);
			break;
		case txgbe_media_type_fiber_qsfp:
			break;
		default:
			DEBUGOUT("Unexpected media type.\n");
			break;
		}
		msec_delay(40);
		status = hw->mac.setup_mac_link(hw,
				TXGBE_LINK_SPEED_1GB_FULL,
				autoneg_wait_to_complete);
		if (status != 0)
			return status;
		hw->mac.flap_tx_laser(hw);
		msec_delay(100);
		status = hw->mac.check_link(hw, &link_speed, &link_up, false);
		if (status != 0)
			return status;
		if (link_up)
			goto out;
	}
	if (speedcnt > 1)
		status = txgbe_setup_mac_link_multispeed_fiber(hw,
						      highest_link_speed,
						      autoneg_wait_to_complete);
out:
	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;
	return status;
}
s32 txgbe_setup_mac_link_multispeed_fiber ( struct txgbe_hw * hw , u32 speed , bool autoneg_wait_to_complete ) { u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN ; u32 highest_link_speed = TXGBE_LINK_SPEED_UNKNOWN ; s32 status = 0 ; u32 speedcnt = 0 ; u32 i = 0 ; bool autoneg , link_up = false ; DEBUGFUNC ( " " ) ; status = hw -> mac . get_link_capabilities ( hw , & link_speed , & autoneg ) ; if ( status != 0 ) return status ; speed &= link_speed ; if ( speed & TXGBE_LINK_SPEED_10GB_FULL ) { speedcnt ++ ; highest_link_speed = TXGBE_LINK_SPEED_10GB_FULL ; switch ( hw -> phy . media_type ) { case txgbe_media_type_fiber : hw -> mac . set_rate_select_speed ( hw , TXGBE_LINK_SPEED_10GB_FULL ) ; break ; case txgbe_media_type_fiber_qsfp : break ; default : DEBUGOUT ( " \n " ) ; break ; } msec_delay ( 40 ) ; status = hw -> mac . setup_mac_link ( hw , TXGBE_LINK_SPEED_10GB_FULL , autoneg_wait_to_complete ) ; if ( status != 0 ) return status ; hw -> mac . flap_tx_laser ( hw ) ; for ( i = 0 ; i < 5 ; i ++ ) { msec_delay ( 100 ) ; status = hw -> mac . check_link ( hw , & link_speed , & link_up , false ) ; if ( status != 0 ) return status ; if ( link_up ) goto out ; } } if ( speed & TXGBE_LINK_SPEED_1GB_FULL ) { speedcnt ++ ; if ( highest_link_speed == TXGBE_LINK_SPEED_UNKNOWN ) highest_link_speed = TXGBE_LINK_SPEED_1GB_FULL ; switch ( hw -> phy . media_type ) { case txgbe_media_type_fiber : hw -> mac . set_rate_select_speed ( hw , TXGBE_LINK_SPEED_1GB_FULL ) ; break ; case txgbe_media_type_fiber_qsfp : break ; default : DEBUGOUT ( " \n " ) ; break ; } msec_delay ( 40 ) ; status = hw -> mac . setup_mac_link ( hw , TXGBE_LINK_SPEED_1GB_FULL , autoneg_wait_to_complete ) ; if ( status != 0 ) return status ; hw -> mac . flap_tx_laser ( hw ) ; msec_delay ( 100 ) ; status = hw -> mac . check_link ( hw , & link_speed , & link_up , false ) ; if ( status != 0 ) return status ; if ( link_up ) goto out ; } if ( speedcnt > 1 ) status = txgbe_setup_mac_link_multispeed_fiber ( hw , highest_link_speed , autoneg_wait_to_complete ) ; out : 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 ; return status ; }
txgbe_setup_mac_link_multispeed_fiber - Set MAC link speed
  @hw: pointer to hardware structure
  @speed: new link speed
  @autoneg_wait_to_complete: true when waiting for completion is needed
txgbe_setup_mac_link_multispeed_fiber - Set MAC link speed @hw : pointer to hardware structure @speed : new link speed @autoneg_wait_to_complete : true when waiting for completion is needed
/* Mask off requested but non-supported speeds */ /* Try each speed one by one, highest priority first.  We do this in
	 * software because 10Gb fiber doesn't support speed autonegotiation.
	 */ /* Set the module link speed */ /* QSFP module automatically detects MAC link speed */ /* Allow module to change analog characteristics (1G->10G) */ /* Flap the Tx laser if it has not already been done */ /* 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.  uses the same timing for 10g SFI.
		 */ /* Wait for the link partner to also set speed */ /* If we have link, just jump out */ /* Set the module link speed */ /* QSFP module automatically detects link speed */ /* Allow module to change analog characteristics (10G->1G) */ /* Flap the Tx laser if it has not already been done */ /* Wait for the link partner to also set speed */ /* If we have link, just jump out */ /* We didn't get link.  Configure back to the highest speed we tried,
	 * (if there was more than one).  We call ourselves back with just the
	 * single highest speed that the user requested.
	 */ /* Set autoneg_advertised value based on input link speed */