Skip to content

Commit 5ecae41

Browse files
anambiarinJeff Kirsher
authored andcommitted
i40e: Refactor VF BW rate limiting
This patch refactors the BW rate limiting for Tx traffic on the VF to be reused in the next patch for rate limiting Tx traffic for the VSIs on the PF as well. Signed-off-by: Amritha Nambiar <[email protected]> Tested-by: Andrew Bowers <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent a9ce82f commit 5ecae41

File tree

3 files changed

+71
-43
lines changed

3 files changed

+71
-43
lines changed

drivers/net/ethernet/intel/i40e/i40e.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@
128128
/* default to trying for four seconds */
129129
#define I40E_TRY_LINK_TIMEOUT (4 * HZ)
130130

131+
/* BW rate limiting */
132+
#define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
133+
#define I40E_MAX_BW_INACTIVE_ACCUM 4 /* accumulate 4 credits max */
134+
131135
/* driver state flags */
132136
enum i40e_state_t {
133137
__I40E_TESTING,
@@ -1039,4 +1043,5 @@ static inline bool i40e_enabled_xdp_vsi(struct i40e_vsi *vsi)
10391043
}
10401044

10411045
int i40e_create_queue_channel(struct i40e_vsi *vsi, struct i40e_channel *ch);
1046+
int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u64 max_tx_rate);
10421047
#endif /* _I40E_H_ */

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5399,6 +5399,70 @@ static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
53995399
return ret;
54005400
}
54015401

5402+
/**
5403+
* i40e_get_link_speed - Returns link speed for the interface
5404+
* @vsi: VSI to be configured
5405+
*
5406+
**/
5407+
int i40e_get_link_speed(struct i40e_vsi *vsi)
5408+
{
5409+
struct i40e_pf *pf = vsi->back;
5410+
5411+
switch (pf->hw.phy.link_info.link_speed) {
5412+
case I40E_LINK_SPEED_40GB:
5413+
return 40000;
5414+
case I40E_LINK_SPEED_25GB:
5415+
return 25000;
5416+
case I40E_LINK_SPEED_20GB:
5417+
return 20000;
5418+
case I40E_LINK_SPEED_10GB:
5419+
return 10000;
5420+
case I40E_LINK_SPEED_1GB:
5421+
return 1000;
5422+
default:
5423+
return -EINVAL;
5424+
}
5425+
}
5426+
5427+
/**
5428+
* i40e_set_bw_limit - setup BW limit for Tx traffic based on max_tx_rate
5429+
* @vsi: VSI to be configured
5430+
* @seid: seid of the channel/VSI
5431+
* @max_tx_rate: max TX rate to be configured as BW limit
5432+
*
5433+
* Helper function to set BW limit for a given VSI
5434+
**/
5435+
int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u64 max_tx_rate)
5436+
{
5437+
struct i40e_pf *pf = vsi->back;
5438+
int speed = 0;
5439+
int ret = 0;
5440+
5441+
speed = i40e_get_link_speed(vsi);
5442+
if (max_tx_rate > speed) {
5443+
dev_err(&pf->pdev->dev,
5444+
"Invalid max tx rate %llu specified for VSI seid %d.",
5445+
max_tx_rate, seid);
5446+
return -EINVAL;
5447+
}
5448+
if (max_tx_rate && max_tx_rate < 50) {
5449+
dev_warn(&pf->pdev->dev,
5450+
"Setting max tx rate to minimum usable value of 50Mbps.\n");
5451+
max_tx_rate = 50;
5452+
}
5453+
5454+
/* Tx rate credits are in values of 50Mbps, 0 is disabled */
5455+
ret = i40e_aq_config_vsi_bw_limit(&pf->hw, seid,
5456+
max_tx_rate / I40E_BW_CREDIT_DIVISOR,
5457+
I40E_MAX_BW_INACTIVE_ACCUM, NULL);
5458+
if (ret)
5459+
dev_err(&pf->pdev->dev,
5460+
"Failed set tx rate (%llu Mbps) for vsi->seid %u, err %s aq_err %s\n",
5461+
max_tx_rate, seid, i40e_stat_str(&pf->hw, ret),
5462+
i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
5463+
return ret;
5464+
}
5465+
54025466
/**
54035467
* i40e_remove_queue_channels - Remove queue channels for the TCs
54045468
* @vsi: VSI to be configured

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

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3117,8 +3117,6 @@ int i40e_ndo_set_vf_port_vlan(struct net_device *netdev, int vf_id,
31173117
return ret;
31183118
}
31193119

3120-
#define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
3121-
#define I40E_MAX_BW_INACTIVE_ACCUM 4 /* device can accumulate 4 credits max */
31223120
/**
31233121
* i40e_ndo_set_vf_bw
31243122
* @netdev: network interface device structure
@@ -3134,7 +3132,6 @@ int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate,
31343132
struct i40e_pf *pf = np->vsi->back;
31353133
struct i40e_vsi *vsi;
31363134
struct i40e_vf *vf;
3137-
int speed = 0;
31383135
int ret = 0;
31393136

31403137
/* validate the request */
@@ -3159,48 +3156,10 @@ int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate,
31593156
goto error;
31603157
}
31613158

3162-
switch (pf->hw.phy.link_info.link_speed) {
3163-
case I40E_LINK_SPEED_40GB:
3164-
speed = 40000;
3165-
break;
3166-
case I40E_LINK_SPEED_25GB:
3167-
speed = 25000;
3168-
break;
3169-
case I40E_LINK_SPEED_20GB:
3170-
speed = 20000;
3171-
break;
3172-
case I40E_LINK_SPEED_10GB:
3173-
speed = 10000;
3174-
break;
3175-
case I40E_LINK_SPEED_1GB:
3176-
speed = 1000;
3177-
break;
3178-
default:
3179-
break;
3180-
}
3181-
3182-
if (max_tx_rate > speed) {
3183-
dev_err(&pf->pdev->dev, "Invalid max tx rate %d specified for VF %d.\n",
3184-
max_tx_rate, vf->vf_id);
3185-
ret = -EINVAL;
3159+
ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
3160+
if (ret)
31863161
goto error;
3187-
}
31883162

3189-
if ((max_tx_rate < 50) && (max_tx_rate > 0)) {
3190-
dev_warn(&pf->pdev->dev, "Setting max Tx rate to minimum usable value of 50Mbps.\n");
3191-
max_tx_rate = 50;
3192-
}
3193-
3194-
/* Tx rate credits are in values of 50Mbps, 0 is disabled*/
3195-
ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
3196-
max_tx_rate / I40E_BW_CREDIT_DIVISOR,
3197-
I40E_MAX_BW_INACTIVE_ACCUM, NULL);
3198-
if (ret) {
3199-
dev_err(&pf->pdev->dev, "Unable to set max tx rate, error code %d.\n",
3200-
ret);
3201-
ret = -EIO;
3202-
goto error;
3203-
}
32043163
vf->tx_rate = max_tx_rate;
32053164
error:
32063165
return ret;

0 commit comments

Comments
 (0)