@@ -2862,24 +2862,6 @@ static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg)
28622862 (u8 * )& stats , sizeof (stats ));
28632863}
28642864
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-
28832865#define I40E_MAX_MACVLAN_PER_HW 3072
28842866#define I40E_MAX_MACVLAN_PER_PF (num_ports ) (I40E_MAX_MACVLAN_PER_HW / \
28852867 (num_ports))
@@ -2918,8 +2900,10 @@ static inline int i40e_check_vf_permission(struct i40e_vf *vf,
29182900 struct i40e_pf * pf = vf -> pf ;
29192901 struct i40e_vsi * vsi = pf -> vsi [vf -> lan_vsi_idx ];
29202902 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 );
29232907
29242908 for (i = 0 ; i < al -> num_elements ; i ++ ) {
29252909 struct i40e_mac_filter * f ;
@@ -2939,9 +2923,8 @@ static inline int i40e_check_vf_permission(struct i40e_vf *vf,
29392923 * The VF may request to set the MAC address filter already
29402924 * assigned to it so do not return an error in that case.
29412925 */
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 )) {
29452928 dev_err (& pf -> pdev -> dev ,
29462929 "VF attempting to override administratively set MAC address, bring down and up the VF interface to resume normal operation\n" );
29472930 return - EPERM ;
@@ -2950,29 +2933,33 @@ static inline int i40e_check_vf_permission(struct i40e_vf *vf,
29502933 /*count filters that really will be added*/
29512934 f = i40e_find_mac (vsi , addr );
29522935 if (!f )
2953- ++ mac2add_cnt ;
2936+ ++ mac_add_cnt ;
29542937 }
29552938
29562939 /* 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.
29682943 * However to ensure that every trusted VF has appropriate number of
29692944 * resources, divide whole pool of resources per port and then across
29702945 * all VFs.
29712946 */
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 {
29762963 dev_err (& pf -> pdev -> dev ,
29772964 "Cannot add more MAC addresses, trusted VF exhausted it's resources\n" );
29782965 return - EPERM ;
0 commit comments