Skip to content

Commit cfb1d57

Browse files
ksornekanguy11
authored andcommitted
i40e: Add ensurance of MacVlan resources for every trusted VF
Trusted VF can use up every resource available, leaving nothing to other trusted VFs. Introduce define, which calculates MacVlan resources available based on maximum available MacVlan resources, bare minimum for each VF and number of currently allocated VFs. Signed-off-by: Przemyslaw Patynowski <[email protected]> Signed-off-by: Karen Sornek <[email protected]> Tested-by: Tony Brelinski <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent c25af83 commit cfb1d57

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

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

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,12 +2704,21 @@ static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg)
27042704
(u8 *)&stats, sizeof(stats));
27052705
}
27062706

2707+
#define I40E_MAX_MACVLAN_PER_HW 3072
2708+
#define I40E_MAX_MACVLAN_PER_PF(num_ports) (I40E_MAX_MACVLAN_PER_HW / \
2709+
(num_ports))
27072710
/* If the VF is not trusted restrict the number of MAC/VLAN it can program
27082711
* MAC filters: 16 for multicast, 1 for MAC, 1 for broadcast
27092712
*/
27102713
#define I40E_VC_MAX_MAC_ADDR_PER_VF (16 + 1 + 1)
27112714
#define I40E_VC_MAX_VLAN_PER_VF 16
27122715

2716+
#define I40E_VC_MAX_MACVLAN_PER_TRUSTED_VF(vf_num, num_ports) \
2717+
({ typeof(vf_num) vf_num_ = (vf_num); \
2718+
typeof(num_ports) num_ports_ = (num_ports); \
2719+
((I40E_MAX_MACVLAN_PER_PF(num_ports_) - vf_num_ * \
2720+
I40E_VC_MAX_MAC_ADDR_PER_VF) / vf_num_) + \
2721+
I40E_VC_MAX_MAC_ADDR_PER_VF; })
27132722
/**
27142723
* i40e_check_vf_permission
27152724
* @vf: pointer to the VF info
@@ -2734,6 +2743,7 @@ static inline int i40e_check_vf_permission(struct i40e_vf *vf,
27342743
{
27352744
struct i40e_pf *pf = vf->pf;
27362745
struct i40e_vsi *vsi = pf->vsi[vf->lan_vsi_idx];
2746+
struct i40e_hw *hw = &pf->hw;
27372747
int mac2add_cnt = 0;
27382748
int i;
27392749

@@ -2775,12 +2785,26 @@ static inline int i40e_check_vf_permission(struct i40e_vf *vf,
27752785
* number of addresses. Check to make sure that the additions do not
27762786
* push us over the limit.
27772787
*/
2778-
if (!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) &&
2779-
(i40e_count_filters(vsi) + mac2add_cnt) >
2788+
if (!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps)) {
2789+
if ((i40e_count_filters(vsi) + mac2add_cnt) >
27802790
I40E_VC_MAX_MAC_ADDR_PER_VF) {
2781-
dev_err(&pf->pdev->dev,
2782-
"Cannot add more MAC addresses, VF is not trusted, switch the VF to trusted to add more functionality\n");
2783-
return -EPERM;
2791+
dev_err(&pf->pdev->dev,
2792+
"Cannot add more MAC addresses, VF is not trusted, switch the VF to trusted to add more functionality\n");
2793+
return -EPERM;
2794+
}
2795+
/* If this VF is trusted, it can use more resources than untrusted.
2796+
* However to ensure that every trusted VF has appropriate number of
2797+
* resources, divide whole pool of resources per port and then across
2798+
* all VFs.
2799+
*/
2800+
} else {
2801+
if ((i40e_count_filters(vsi) + mac2add_cnt) >
2802+
I40E_VC_MAX_MACVLAN_PER_TRUSTED_VF(pf->num_alloc_vfs,
2803+
hw->num_ports)) {
2804+
dev_err(&pf->pdev->dev,
2805+
"Cannot add more MAC addresses, trusted VF exhausted it's resources\n");
2806+
return -EPERM;
2807+
}
27842808
}
27852809
return 0;
27862810
}

0 commit comments

Comments
 (0)