Skip to content

Commit 198eb7e

Browse files
michalx-jaronanguy11
authored andcommitted
i40e: Fix set max_tx_rate when it is lower than 1 Mbps
While converting max_tx_rate from bytes to Mbps, this value was set to 0, if the original value was lower than 125000 bytes (1 Mbps). This would cause no transmission rate limiting to occur. This happened due to lack of check of max_tx_rate against the 1 Mbps value for max_tx_rate and the following division by 125000. Fix this issue by adding a helper i40e_bw_bytes_to_mbits() which sets max_tx_rate to minimum usable value of 50 Mbps, if its value is less than 1 Mbps, otherwise do the required conversion by dividing by 125000. Fixes: 5ecae41 ("i40e: Refactor VF BW rate limiting") Signed-off-by: Michal Jaron <[email protected]> Signed-off-by: Andrii Staikov <[email protected]> Tested-by: Bharathi Sreenivas <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 372539d commit 198eb7e

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

drivers/net/ethernet/intel/i40e/i40e_main.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5908,6 +5908,26 @@ static int i40e_get_link_speed(struct i40e_vsi *vsi)
59085908
}
59095909
}
59105910

5911+
/**
5912+
* i40e_bw_bytes_to_mbits - Convert max_tx_rate from bytes to mbits
5913+
* @vsi: Pointer to vsi structure
5914+
* @max_tx_rate: max TX rate in bytes to be converted into Mbits
5915+
*
5916+
* Helper function to convert units before send to set BW limit
5917+
**/
5918+
static u64 i40e_bw_bytes_to_mbits(struct i40e_vsi *vsi, u64 max_tx_rate)
5919+
{
5920+
if (max_tx_rate < I40E_BW_MBPS_DIVISOR) {
5921+
dev_warn(&vsi->back->pdev->dev,
5922+
"Setting max tx rate to minimum usable value of 50Mbps.\n");
5923+
max_tx_rate = I40E_BW_CREDIT_DIVISOR;
5924+
} else {
5925+
do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR);
5926+
}
5927+
5928+
return max_tx_rate;
5929+
}
5930+
59115931
/**
59125932
* i40e_set_bw_limit - setup BW limit for Tx traffic based on max_tx_rate
59135933
* @vsi: VSI to be configured
@@ -5930,10 +5950,10 @@ int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u64 max_tx_rate)
59305950
max_tx_rate, seid);
59315951
return -EINVAL;
59325952
}
5933-
if (max_tx_rate && max_tx_rate < 50) {
5953+
if (max_tx_rate && max_tx_rate < I40E_BW_CREDIT_DIVISOR) {
59345954
dev_warn(&pf->pdev->dev,
59355955
"Setting max tx rate to minimum usable value of 50Mbps.\n");
5936-
max_tx_rate = 50;
5956+
max_tx_rate = I40E_BW_CREDIT_DIVISOR;
59375957
}
59385958

59395959
/* Tx rate credits are in values of 50Mbps, 0 is disabled */
@@ -8224,9 +8244,9 @@ static int i40e_setup_tc(struct net_device *netdev, void *type_data)
82248244

82258245
if (i40e_is_tc_mqprio_enabled(pf)) {
82268246
if (vsi->mqprio_qopt.max_rate[0]) {
8227-
u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
8247+
u64 max_tx_rate = i40e_bw_bytes_to_mbits(vsi,
8248+
vsi->mqprio_qopt.max_rate[0]);
82288249

8229-
do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR);
82308250
ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
82318251
if (!ret) {
82328252
u64 credits = max_tx_rate;
@@ -10971,10 +10991,10 @@ static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired)
1097110991
}
1097210992

1097310993
if (vsi->mqprio_qopt.max_rate[0]) {
10974-
u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
10994+
u64 max_tx_rate = i40e_bw_bytes_to_mbits(vsi,
10995+
vsi->mqprio_qopt.max_rate[0]);
1097510996
u64 credits = 0;
1097610997

10977-
do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR);
1097810998
ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
1097910999
if (ret)
1098011000
goto end_unlock;

0 commit comments

Comments
 (0)