src/dpdk/drivers/net/txgbe/base/txgbe_dcb.c
s32 txgbe_dcb_calculate_tc_credits_cee(struct txgbe_hw *hw,
				   struct txgbe_dcb_config *dcb_config,
				   u32 max_frame_size, u8 direction)
{
	struct txgbe_dcb_tc_path *p;
	u32 min_multiplier	= 0;
	u16 min_percent		= 100;
	s32 ret_val =		0;
	/* Initialization values default for Tx settings */
	u32 min_credit		= 0;
	u32 credit_refill	= 0;
	u32 credit_max		= 0;
	u16 link_percentage	= 0;
	u8  bw_percent		= 0;
	u8  i;

	UNREFERENCED_PARAMETER(hw);

	if (dcb_config == NULL) {
		ret_val = TXGBE_ERR_CONFIG;
		goto out;
	}

	min_credit = ((max_frame_size / 2) + TXGBE_DCB_CREDIT_QUANTUM - 1) /
		     TXGBE_DCB_CREDIT_QUANTUM;

	/* Find smallest link percentage */
	for (i = 0; i < TXGBE_DCB_TC_MAX; i++) {
		p = &dcb_config->tc_config[i].path[direction];
		bw_percent = dcb_config->bw_percentage[p->bwg_id][direction];
		link_percentage = p->bwg_percent;

		link_percentage = (link_percentage * bw_percent) / 100;

		if (link_percentage && link_percentage < min_percent)
			min_percent = link_percentage;
	}

	/*
	 * The ratio between traffic classes will control the bandwidth
	 * percentages seen on the wire. To calculate this ratio we use
	 * a multiplier. It is required that the refill credits must be
	 * larger than the max frame size so here we find the smallest
	 * multiplier that will allow all bandwidth percentages to be
	 * greater than the max frame size.
	 */
	min_multiplier = (min_credit / min_percent) + 1;

	/* Find out the link percentage for each TC first */
	for (i = 0; i < TXGBE_DCB_TC_MAX; i++) {
		p = &dcb_config->tc_config[i].path[direction];
		bw_percent = dcb_config->bw_percentage[p->bwg_id][direction];

		link_percentage = p->bwg_percent;
		/* Must be careful of integer division for very small nums */
		link_percentage = (link_percentage * bw_percent) / 100;
		if (p->bwg_percent > 0 && link_percentage == 0)
			link_percentage = 1;

		/* Save link_percentage for reference */
		p->link_percent = (u8)link_percentage;

		/* Calculate credit refill ratio using multiplier */
		credit_refill = min(link_percentage * min_multiplier,
				    (u32)TXGBE_DCB_MAX_CREDIT_REFILL);

		/* Refill at least minimum credit */
		if (credit_refill < min_credit)
			credit_refill = min_credit;

		p->data_credits_refill = (u16)credit_refill;

		/* Calculate maximum credit for the TC */
		credit_max = (link_percentage * TXGBE_DCB_MAX_CREDIT) / 100;

		/*
		 * Adjustment based on rule checking, if the percentage
		 * of a TC is too small, the maximum credit may not be
		 * enough to send out a jumbo frame in data plane arbitration.
		 */
		if (credit_max < min_credit)
			credit_max = min_credit;

		if (direction == TXGBE_DCB_TX_CONFIG) {
			dcb_config->tc_config[i].desc_credits_max =
								(u16)credit_max;
		}

		p->data_credits_max = (u16)credit_max;
	}

out:
	return ret_val;
}
/**
 * txgbe_dcb_calculate_tc_credits_cee - Calculates traffic class credits
 * @hw: pointer to hardware structure
 * @dcb_config: Struct containing DCB settings
 * @max_frame_size: Maximum frame size
 * @direction: Configuring either Tx or Rx
 *
 * This function calculates the credits allocated to each traffic class.
 * It should be called only after the rules are checked by
 * txgbe_dcb_check_config_cee().
 */
Calculates traffic class credits
@hw: pointer to hardware structure
@dcb_config: Struct containing DCB settings
@max_frame_size: Maximum frame size
@direction: Configuring either Tx or Rx

This function calculates the credits allocated to each traffic class.
It should be called only after the rules are checked by
txgbe_dcb_check_config_cee().
Calculates traffic class credits @hw : pointer to hardware structure @dcb_config : Struct containing DCB settings @max_frame_size : Maximum frame size @direction : Configuring either Tx or Rx This function calculates the credits allocated to each traffic class . It should be called only after the rules are checked by txgbe_dcb_check_config_cee () .
s32 txgbe_dcb_calculate_tc_credits_cee(struct txgbe_hw *hw,
				   struct txgbe_dcb_config *dcb_config,
				   u32 max_frame_size, u8 direction)
{
	struct txgbe_dcb_tc_path *p;
	u32 min_multiplier	= 0;
	u16 min_percent		= 100;
	s32 ret_val =		0;
	u32 min_credit		= 0;
	u32 credit_refill	= 0;
	u32 credit_max		= 0;
	u16 link_percentage	= 0;
	u8  bw_percent		= 0;
	u8  i;
	UNREFERENCED_PARAMETER(hw);
	if (dcb_config == NULL) {
		ret_val = TXGBE_ERR_CONFIG;
		goto out;
	}
	min_credit = ((max_frame_size / 2) + TXGBE_DCB_CREDIT_QUANTUM - 1) /
		     TXGBE_DCB_CREDIT_QUANTUM;
	for (i = 0; i < TXGBE_DCB_TC_MAX; i++) {
		p = &dcb_config->tc_config[i].path[direction];
		bw_percent = dcb_config->bw_percentage[p->bwg_id][direction];
		link_percentage = p->bwg_percent;
		link_percentage = (link_percentage * bw_percent) / 100;
		if (link_percentage && link_percentage < min_percent)
			min_percent = link_percentage;
	}
	min_multiplier = (min_credit / min_percent) + 1;
	for (i = 0; i < TXGBE_DCB_TC_MAX; i++) {
		p = &dcb_config->tc_config[i].path[direction];
		bw_percent = dcb_config->bw_percentage[p->bwg_id][direction];
		link_percentage = p->bwg_percent;
		link_percentage = (link_percentage * bw_percent) / 100;
		if (p->bwg_percent > 0 && link_percentage == 0)
			link_percentage = 1;
		p->link_percent = (u8)link_percentage;
		credit_refill = min(link_percentage * min_multiplier,
				    (u32)TXGBE_DCB_MAX_CREDIT_REFILL);
		if (credit_refill < min_credit)
			credit_refill = min_credit;
		p->data_credits_refill = (u16)credit_refill;
		credit_max = (link_percentage * TXGBE_DCB_MAX_CREDIT) / 100;
		if (credit_max < min_credit)
			credit_max = min_credit;
		if (direction == TXGBE_DCB_TX_CONFIG) {
			dcb_config->tc_config[i].desc_credits_max =
								(u16)credit_max;
		}
		p->data_credits_max = (u16)credit_max;
	}
out:
	return ret_val;
}
s32 txgbe_dcb_calculate_tc_credits_cee ( struct txgbe_hw * hw , struct txgbe_dcb_config * dcb_config , u32 max_frame_size , u8 direction ) { struct txgbe_dcb_tc_path * p ; u32 min_multiplier = 0 ; u16 min_percent = 100 ; s32 ret_val = 0 ; u32 min_credit = 0 ; u32 credit_refill = 0 ; u32 credit_max = 0 ; u16 link_percentage = 0 ; u8 bw_percent = 0 ; u8 i ; UNREFERENCED_PARAMETER ( hw ) ; if ( dcb_config == NULL ) { ret_val = TXGBE_ERR_CONFIG ; goto out ; } min_credit = ( ( max_frame_size / 2 ) + TXGBE_DCB_CREDIT_QUANTUM - 1 ) / TXGBE_DCB_CREDIT_QUANTUM ; for ( i = 0 ; i < TXGBE_DCB_TC_MAX ; i ++ ) { p = & dcb_config -> tc_config [ i ] . path [ direction ] ; bw_percent = dcb_config -> bw_percentage [ p -> bwg_id ] [ direction ] ; link_percentage = p -> bwg_percent ; link_percentage = ( link_percentage * bw_percent ) / 100 ; if ( link_percentage && link_percentage < min_percent ) min_percent = link_percentage ; } min_multiplier = ( min_credit / min_percent ) + 1 ; for ( i = 0 ; i < TXGBE_DCB_TC_MAX ; i ++ ) { p = & dcb_config -> tc_config [ i ] . path [ direction ] ; bw_percent = dcb_config -> bw_percentage [ p -> bwg_id ] [ direction ] ; link_percentage = p -> bwg_percent ; link_percentage = ( link_percentage * bw_percent ) / 100 ; if ( p -> bwg_percent > 0 && link_percentage == 0 ) link_percentage = 1 ; p -> link_percent = ( u8 ) link_percentage ; credit_refill = min ( link_percentage * min_multiplier , ( u32 ) TXGBE_DCB_MAX_CREDIT_REFILL ) ; if ( credit_refill < min_credit ) credit_refill = min_credit ; p -> data_credits_refill = ( u16 ) credit_refill ; credit_max = ( link_percentage * TXGBE_DCB_MAX_CREDIT ) / 100 ; if ( credit_max < min_credit ) credit_max = min_credit ; if ( direction == TXGBE_DCB_TX_CONFIG ) { dcb_config -> tc_config [ i ] . desc_credits_max = ( u16 ) credit_max ; } p -> data_credits_max = ( u16 ) credit_max ; } out : return ret_val ; }
txgbe_dcb_calculate_tc_credits_cee - Calculates traffic class credits
 @hw: pointer to hardware structure
 @dcb_config: Struct containing DCB settings
 @max_frame_size: Maximum frame size
 @direction: Configuring either Tx or Rx
txgbe_dcb_calculate_tc_credits_cee - Calculates traffic class credits @hw : pointer to hardware structure @dcb_config : Struct containing DCB settings @max_frame_size : Maximum frame size @direction : Configuring either Tx or Rx
/* Initialization values default for Tx settings */ /* Find smallest link percentage */ /*
	 * The ratio between traffic classes will control the bandwidth
	 * percentages seen on the wire. To calculate this ratio we use
	 * a multiplier. It is required that the refill credits must be
	 * larger than the max frame size so here we find the smallest
	 * multiplier that will allow all bandwidth percentages to be
	 * greater than the max frame size.
	 */ /* Find out the link percentage for each TC first */ /* Must be careful of integer division for very small nums */ /* Save link_percentage for reference */ /* Calculate credit refill ratio using multiplier */ /* Refill at least minimum credit */ /* Calculate maximum credit for the TC */ /*
		 * Adjustment based on rule checking, if the percentage
		 * of a TC is too small, the maximum credit may not be
		 * enough to send out a jumbo frame in data plane arbitration.
		 */