@@ -2862,24 +2862,6 @@ static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg)
2862
2862
(u8 * )& stats , sizeof (stats ));
2863
2863
}
2864
2864
2865
- /**
2866
- * i40e_can_vf_change_mac
2867
- * @vf: pointer to the VF info
2868
- *
2869
- * Return true if the VF is allowed to change its MAC filters, false otherwise
2870
- */
2871
- static bool i40e_can_vf_change_mac (struct i40e_vf * vf )
2872
- {
2873
- /* If the VF MAC address has been set administratively (via the
2874
- * ndo_set_vf_mac command), then deny permission to the VF to
2875
- * add/delete unicast MAC addresses, unless the VF is trusted
2876
- */
2877
- if (vf -> pf_set_mac && !vf -> trusted )
2878
- return false;
2879
-
2880
- return true;
2881
- }
2882
-
2883
2865
#define I40E_MAX_MACVLAN_PER_HW 3072
2884
2866
#define I40E_MAX_MACVLAN_PER_PF (num_ports ) (I40E_MAX_MACVLAN_PER_HW / \
2885
2867
(num_ports))
@@ -2918,8 +2900,10 @@ static inline int i40e_check_vf_permission(struct i40e_vf *vf,
2918
2900
struct i40e_pf * pf = vf -> pf ;
2919
2901
struct i40e_vsi * vsi = pf -> vsi [vf -> lan_vsi_idx ];
2920
2902
struct i40e_hw * hw = & pf -> hw ;
2921
- int mac2add_cnt = 0 ;
2922
- int i ;
2903
+ int i , mac_add_max , mac_add_cnt = 0 ;
2904
+ bool vf_trusted ;
2905
+
2906
+ vf_trusted = test_bit (I40E_VIRTCHNL_VF_CAP_PRIVILEGE , & vf -> vf_caps );
2923
2907
2924
2908
for (i = 0 ; i < al -> num_elements ; i ++ ) {
2925
2909
struct i40e_mac_filter * f ;
@@ -2939,9 +2923,8 @@ static inline int i40e_check_vf_permission(struct i40e_vf *vf,
2939
2923
* The VF may request to set the MAC address filter already
2940
2924
* assigned to it so do not return an error in that case.
2941
2925
*/
2942
- if (!i40e_can_vf_change_mac (vf ) &&
2943
- !is_multicast_ether_addr (addr ) &&
2944
- !ether_addr_equal (addr , vf -> default_lan_addr .addr )) {
2926
+ if (!vf_trusted && !is_multicast_ether_addr (addr ) &&
2927
+ vf -> pf_set_mac && !ether_addr_equal (addr , vf -> default_lan_addr .addr )) {
2945
2928
dev_err (& pf -> pdev -> dev ,
2946
2929
"VF attempting to override administratively set MAC address, bring down and up the VF interface to resume normal operation\n" );
2947
2930
return - EPERM ;
@@ -2950,29 +2933,33 @@ static inline int i40e_check_vf_permission(struct i40e_vf *vf,
2950
2933
/*count filters that really will be added*/
2951
2934
f = i40e_find_mac (vsi , addr );
2952
2935
if (!f )
2953
- ++ mac2add_cnt ;
2936
+ ++ mac_add_cnt ;
2954
2937
}
2955
2938
2956
2939
/* If this VF is not privileged, then we can't add more than a limited
2957
- * number of addresses. Check to make sure that the additions do not
2958
- * push us over the limit.
2959
- */
2960
- if (!test_bit (I40E_VIRTCHNL_VF_CAP_PRIVILEGE , & vf -> vf_caps )) {
2961
- if ((i40e_count_filters (vsi ) + mac2add_cnt ) >
2962
- I40E_VC_MAX_MAC_ADDR_PER_VF ) {
2963
- dev_err (& pf -> pdev -> dev ,
2964
- "Cannot add more MAC addresses, VF is not trusted, switch the VF to trusted to add more functionality\n" );
2965
- return - EPERM ;
2966
- }
2967
- /* If this VF is trusted, it can use more resources than untrusted.
2940
+ * number of addresses.
2941
+ *
2942
+ * If this VF is trusted, it can use more resources than untrusted.
2968
2943
* However to ensure that every trusted VF has appropriate number of
2969
2944
* resources, divide whole pool of resources per port and then across
2970
2945
* all VFs.
2971
2946
*/
2972
- } else {
2973
- if ((i40e_count_filters (vsi ) + mac2add_cnt ) >
2974
- I40E_VC_MAX_MACVLAN_PER_TRUSTED_VF (pf -> num_alloc_vfs ,
2975
- hw -> num_ports )) {
2947
+ if (!vf_trusted )
2948
+ mac_add_max = I40E_VC_MAX_MAC_ADDR_PER_VF ;
2949
+ else
2950
+ mac_add_max = I40E_VC_MAX_MACVLAN_PER_TRUSTED_VF (pf -> num_alloc_vfs , hw -> num_ports );
2951
+
2952
+ /* VF can replace all its filters in one step, in this case mac_add_max
2953
+ * will be added as active and another mac_add_max will be in
2954
+ * a to-be-removed state. Account for that.
2955
+ */
2956
+ if ((i40e_count_active_filters (vsi ) + mac_add_cnt ) > mac_add_max ||
2957
+ (i40e_count_all_filters (vsi ) + mac_add_cnt ) > 2 * mac_add_max ) {
2958
+ if (!vf_trusted ) {
2959
+ dev_err (& pf -> pdev -> dev ,
2960
+ "Cannot add more MAC addresses, VF is not trusted, switch the VF to trusted to add more functionality\n" );
2961
+ return - EPERM ;
2962
+ } else {
2976
2963
dev_err (& pf -> pdev -> dev ,
2977
2964
"Cannot add more MAC addresses, trusted VF exhausted it's resources\n" );
2978
2965
return - EPERM ;
0 commit comments