Skip to contentSkip to conversation

ice: Fix VSIs unable to share unicast MAC

PATCH In review Mateusz Palczewski 2 participants 2 messages Jul 11, 2022 – Jul 12, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ice: Fix VSIs unable to share unicast MAC

From: Anirudh Venkataramanan <[email protected]>

The driver currently does not allow two VSIs in the same PF domain to have the same unicast MAC address. This is incorrect in the sense that a policy decision is being made in the driver when it must be left to the user. Remove this restriction. Doing this also allows use to remove some additional code that's checking if a unicast MAC filter already exists.

Rename ucast_shared to umac_shared, as "umac" is a more widely used shorthand for "unicast MAC".

Also add a helper function to set this flag. This helper is expected to be called by core drivers.

Fixes 47ebc7b02485 ("ice: Check if unicast MAC exists before setting VF MAC")
---
 drivers/net/ethernet/intel/ice/ice_common.c | 11 ++++++
 drivers/net/ethernet/intel/ice/ice_common.h |  1 +
 drivers/net/ethernet/intel/ice/ice_main.c   |  2 ++
 drivers/net/ethernet/intel/ice/ice_sriov.c  | 40 ---------------------
 drivers/net/ethernet/intel/ice/ice_switch.c |  8 ++---
 drivers/net/ethernet/intel/ice/ice_type.h   |  3 +-
 6 files changed, 20 insertions(+), 45 deletions(-)
drivers/net/ethernet/intel/ice/ice_common.c +11 -0
index 9619bdb9e49a..64748ecebabe 100644
@@ -899,6 +899,17 @@ static void ice_get_itr_intrl_gran(struct ice_hw *hw)
 	}
 }
 
+/**
+ * ice_set_umac_shared
+ * @hw: pointer to the hw struct
+ *
+ * Set boolean flag to allow unicast MAC sharing
+ */
+void ice_set_umac_shared(struct ice_hw *hw)
+{
+	hw->umac_shared = true;
+}
+
 /**
  * ice_init_hw - main hardware initialization routine
  * @hw: pointer to the hardware structure
drivers/net/ethernet/intel/ice/ice_common.h +1 -0
index 872ea7d2332d..8a66f86c8893 100644
@@ -16,6 +16,7 @@
 #define ICE_SQ_SEND_DELAY_TIME_MS	10
 #define ICE_SQ_SEND_MAX_EXECUTE		3
 
+void ice_set_umac_shared(struct ice_hw *hw);
 int ice_init_hw(struct ice_hw *hw);
 void ice_deinit_hw(struct ice_hw *hw);
 int ice_check_reset(struct ice_hw *hw);
drivers/net/ethernet/intel/ice/ice_main.c +2 -0
index ff2eac2f8c64..ff798a410365 100644
@@ -4656,6 +4656,8 @@ ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent)
 		ice_set_safe_mode_caps(hw);
 	}
 
+	ice_set_umac_shared(hw);
+
 	err = ice_init_pf(pf);
 	if (err) {
 		dev_err(dev, "ice_init_pf failed: %d\n", err);
drivers/net/ethernet/intel/ice/ice_sriov.c +0 -40
index bb1721f1321d..f4907a3c2d19 100644
@@ -1309,39 +1309,6 @@ ice_get_vf_cfg(struct net_device *netdev, int vf_id, struct ifla_vf_info *ivi)
 	return ret;
 }
 
-/**
- * ice_unicast_mac_exists - check if the unicast MAC exists on the PF's switch
- * @pf: PF used to reference the switch's rules
- * @umac: unicast MAC to compare against existing switch rules
- *
- * Return true on the first/any match, else return false
- */
-static bool ice_unicast_mac_exists(struct ice_pf *pf, u8 *umac)
-{
-	struct ice_sw_recipe *mac_recipe_list =
-		&pf->hw.switch_info->recp_list[ICE_SW_LKUP_MAC];
-	struct ice_fltr_mgmt_list_entry *list_itr;
-	struct list_head *rule_head;
-	struct mutex *rule_lock; /* protect MAC filter list access */
-
-	rule_head = &mac_recipe_list->filt_rules;
-	rule_lock = &mac_recipe_list->filt_rule_lock;
-
-	mutex_lock(rule_lock);
-	list_for_each_entry(list_itr, rule_head, list_entry) {
-		u8 *existing_mac = &list_itr->fltr_info.l_data.mac.mac_addr[0];
-
-		if (ether_addr_equal(existing_mac, umac)) {
-			mutex_unlock(rule_lock);
-			return true;
-		}
-	}
-
-	mutex_unlock(rule_lock);
-
-	return false;
-}
-
 /**
  * ice_set_vf_mac
  * @netdev: network interface device structure
@@ -1376,13 +1343,6 @@ int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
 	if (ret)
 		goto out_put_vf;
 
-	if (ice_unicast_mac_exists(pf, mac)) {
-		netdev_err(netdev, "Unicast MAC %pM already exists on this PF. Preventing setting VF %u unicast MAC address to %pM\n",
-			   mac, vf_id, mac);
-		ret = -EINVAL;
-		goto out_put_vf;
-	}
-
 	mutex_lock(&vf->cfg_lock);
 
 	/* VF is notified of its new MAC via the PF's response to the
drivers/net/ethernet/intel/ice/ice_switch.c +4 -4
index 8d8f3eec79ee..95e4b99928b7 100644
@@ -3425,7 +3425,7 @@ bool ice_vlan_fltr_exist(struct ice_hw *hw, u16 vlan_id, u16 vsi_handle)
  * @hw: pointer to the hardware structure
  * @m_list: list of MAC addresses and forwarding information
  *
- * IMPORTANT: When the ucast_shared flag is set to false and m_list has
+ * IMPORTANT: When the umac_shared flag is set to false and m_list has
  * multiple unicast addresses, the function assumes that all the
  * addresses are unique in a given add_mac call. It doesn't
  * check for duplicates in this case, removing duplicates from a given
@@ -3467,7 +3467,7 @@ int ice_add_mac(struct ice_hw *hw, struct list_head *m_list)
 		if (m_list_itr->fltr_info.lkup_type != ICE_SW_LKUP_MAC ||
 		    is_zero_ether_addr(add))
 			return -EINVAL;
-		if (is_unicast_ether_addr(add) && !hw->ucast_shared) {
+		if (is_unicast_ether_addr(add) && !hw->umac_shared) {
 			/* Don't overwrite the unicast address */
 			mutex_lock(rule_lock);
 			if (ice_find_rule_entry(hw, ICE_SW_LKUP_MAC,
@@ -3478,7 +3478,7 @@ int ice_add_mac(struct ice_hw *hw, struct list_head *m_list)
 			mutex_unlock(rule_lock);
 			num_unicast++;
 		} else if (is_multicast_ether_addr(add) ||
-			   (is_unicast_ether_addr(add) && hw->ucast_shared)) {
+			   (is_unicast_ether_addr(add) && hw->umac_shared)) {
 			m_list_itr->status =
 				ice_add_rule_internal(hw, ICE_SW_LKUP_MAC,
 						      m_list_itr);
@@ -4000,7 +4000,7 @@ int ice_remove_mac(struct ice_hw *hw, struct list_head *m_list)
 
 		list_itr->fltr_info.fwd_id.hw_vsi_id =
 					ice_get_hw_vsi_num(hw, vsi_handle);
-		if (is_unicast_ether_addr(add) && !hw->ucast_shared) {
+		if (is_unicast_ether_addr(add) && !hw->umac_shared) {
 			/* Don't remove the unicast address that belongs to
 			 * another VSI on the switch, since it is not being
 			 * shared...
drivers/net/ethernet/intel/ice/ice_type.h +2 -1
index f2a518a1fd94..bef7c3ba1a20 100644
@@ -889,7 +889,8 @@ struct ice_hw {
 	/* INTRL granularity in 1 us */
 	u8 intrl_gran;
 
-	u8 ucast_shared;	/* true if VSIs can share unicast addr */
+	/* true if VSIs can share unicast MAC addr */
+	u8 umac_shared;
 
 #define ICE_PHY_PER_NAC		1
 #define ICE_MAX_QUAD		2
Signature · 6 lines
2.27.0

_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
maintainer
#1 lore raw
Quoted 178 lines · Mateusz Palczewski

From: Anirudh Venkataramanan <[email protected]>

The driver currently does not allow two VSIs in the same PF domain to have the same unicast MAC address. This is incorrect in the sense that a policy decision is being made in the driver when it must be left to the user. Remove this restriction. Doing this also allows use to remove some additional code that's checking if a unicast MAC filter already exists.

Rename ucast_shared to umac_shared, as "umac" is a more widely used shorthand for "unicast MAC".

Also add a helper function to set this flag. This helper is expected to be called by core drivers.

Fixes 47ebc7b02485 ("ice: Check if unicast MAC exists before setting VF MAC")
---
  drivers/net/ethernet/intel/ice/ice_common.c | 11 ++++++
  drivers/net/ethernet/intel/ice/ice_common.h |  1 +
  drivers/net/ethernet/intel/ice/ice_main.c   |  2 ++
  drivers/net/ethernet/intel/ice/ice_sriov.c  | 40 ---------------------
  drivers/net/ethernet/intel/ice/ice_switch.c |  8 ++---
  drivers/net/ethernet/intel/ice/ice_type.h   |  3 +-
  6 files changed, 20 insertions(+), 45 deletions(-)
drivers/net/ethernet/intel/ice/ice_common.c +11 -0
index 9619bdb9e49a..64748ecebabe 100644
@@ -899,6 +899,17 @@ static void ice_get_itr_intrl_gran(struct ice_hw *hw)
  	}
  }
 
+/**
+ * ice_set_umac_shared
+ * @hw: pointer to the hw struct
+ *
+ * Set boolean flag to allow unicast MAC sharing
+ */
+void ice_set_umac_shared(struct ice_hw *hw)
+{
+	hw->umac_shared = true;
+}
+
  /**
   * ice_init_hw - main hardware initialization routine
   * @hw: pointer to the hardware structure
drivers/net/ethernet/intel/ice/ice_common.h +1 -0
index 872ea7d2332d..8a66f86c8893 100644
@@ -16,6 +16,7 @@
  #define ICE_SQ_SEND_DELAY_TIME_MS	10
  #define ICE_SQ_SEND_MAX_EXECUTE		3
 
+void ice_set_umac_shared(struct ice_hw *hw);
  int ice_init_hw(struct ice_hw *hw);
  void ice_deinit_hw(struct ice_hw *hw);
  int ice_check_reset(struct ice_hw *hw);
drivers/net/ethernet/intel/ice/ice_main.c +2 -0
index ff2eac2f8c64..ff798a410365 100644
@@ -4656,6 +4656,8 @@ ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent)
  		ice_set_safe_mode_caps(hw);
  	}
 
+	ice_set_umac_shared(hw);
+
  	err = ice_init_pf(pf);
  	if (err) {
  		dev_err(dev, "ice_init_pf failed: %d\n", err);
drivers/net/ethernet/intel/ice/ice_sriov.c +0 -40
index bb1721f1321d..f4907a3c2d19 100644
@@ -1309,39 +1309,6 @@ ice_get_vf_cfg(struct net_device *netdev, int vf_id, struct ifla_vf_info *ivi)
  	return ret;
  }
 
-/**
- * ice_unicast_mac_exists - check if the unicast MAC exists on the PF's switch
- * @pf: PF used to reference the switch's rules
- * @umac: unicast MAC to compare against existing switch rules
- *
- * Return true on the first/any match, else return false
- */
-static bool ice_unicast_mac_exists(struct ice_pf *pf, u8 *umac)
-{
-	struct ice_sw_recipe *mac_recipe_list =
-		&pf->hw.switch_info->recp_list[ICE_SW_LKUP_MAC];
-	struct ice_fltr_mgmt_list_entry *list_itr;
-	struct list_head *rule_head;
-	struct mutex *rule_lock; /* protect MAC filter list access */
-
-	rule_head = &mac_recipe_list->filt_rules;
-	rule_lock = &mac_recipe_list->filt_rule_lock;
-
-	mutex_lock(rule_lock);
-	list_for_each_entry(list_itr, rule_head, list_entry) {
-		u8 *existing_mac = &list_itr->fltr_info.l_data.mac.mac_addr[0];
-
-		if (ether_addr_equal(existing_mac, umac)) {
-			mutex_unlock(rule_lock);
-			return true;
-		}
-	}
-
-	mutex_unlock(rule_lock);
-
-	return false;
-}
-
  /**
   * ice_set_vf_mac
   * @netdev: network interface device structure
@@ -1376,13 +1343,6 @@ int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
  	if (ret)
  		goto out_put_vf;
 
-	if (ice_unicast_mac_exists(pf, mac)) {
-		netdev_err(netdev, "Unicast MAC %pM already exists on this PF. Preventing setting VF %u unicast MAC address to %pM\n",
-			   mac, vf_id, mac);
-		ret = -EINVAL;
-		goto out_put_vf;
-	}
-
  	mutex_lock(&vf->cfg_lock);
 
  	/* VF is notified of its new MAC via the PF's response to the
drivers/net/ethernet/intel/ice/ice_switch.c +4 -4
index 8d8f3eec79ee..95e4b99928b7 100644
@@ -3425,7 +3425,7 @@ bool ice_vlan_fltr_exist(struct ice_hw *hw, u16 vlan_id, u16 vsi_handle)
   * @hw: pointer to the hardware structure
   * @m_list: list of MAC addresses and forwarding information
   *
- * IMPORTANT: When the ucast_shared flag is set to false and m_list has
+ * IMPORTANT: When the umac_shared flag is set to false and m_list has
   * multiple unicast addresses, the function assumes that all the
   * addresses are unique in a given add_mac call. It doesn't
   * check for duplicates in this case, removing duplicates from a given
@@ -3467,7 +3467,7 @@ int ice_add_mac(struct ice_hw *hw, struct list_head *m_list)
  		if (m_list_itr->fltr_info.lkup_type != ICE_SW_LKUP_MAC ||
  		    is_zero_ether_addr(add))
  			return -EINVAL;
-		if (is_unicast_ether_addr(add) && !hw->ucast_shared) {
+		if (is_unicast_ether_addr(add) && !hw->umac_shared) {
  			/* Don't overwrite the unicast address */
  			mutex_lock(rule_lock);
  			if (ice_find_rule_entry(hw, ICE_SW_LKUP_MAC,
@@ -3478,7 +3478,7 @@ int ice_add_mac(struct ice_hw *hw, struct list_head *m_list)
  			mutex_unlock(rule_lock);
  			num_unicast++;
  		} else if (is_multicast_ether_addr(add) ||
-			   (is_unicast_ether_addr(add) && hw->ucast_shared)) {
+			   (is_unicast_ether_addr(add) && hw->umac_shared)) {
  			m_list_itr->status =
  				ice_add_rule_internal(hw, ICE_SW_LKUP_MAC,
  						      m_list_itr);
@@ -4000,7 +4000,7 @@ int ice_remove_mac(struct ice_hw *hw, struct list_head *m_list)
 
  		list_itr->fltr_info.fwd_id.hw_vsi_id =
  					ice_get_hw_vsi_num(hw, vsi_handle);
-		if (is_unicast_ether_addr(add) && !hw->ucast_shared) {
+		if (is_unicast_ether_addr(add) && !hw->umac_shared) {
  			/* Don't remove the unicast address that belongs to
  			 * another VSI on the switch, since it is not being
  			 * shared...
drivers/net/ethernet/intel/ice/ice_type.h +0 -0
index f2a518a1fd94..bef7c3ba1a20 100644

drivers/net/ethernet/intel/ice/ice_type.h struct ice_hw { · line 893

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_type.h +2 -1
@@ -889,7 +889,8 @@ struct ice_hw {
  	/* INTRL granularity in 1 us */
  	u8 intrl_gran;
 
-	u8 ucast_shared;	/* true if VSIs can share unicast addr */
+	/* true if VSIs can share unicast MAC addr */
+	u8 umac_shared;

This field doesn't look necessary at all. This is set to true and never changed. It seems this can be removed and the conditions updated.

drivers/net/ethernet/intel/ice/ice_type.h struct ice_hw { · line 896

Quoted 3 lines
drivers/net/ethernet/intel/ice/ice_type.h +0 -0
  #define ICE_PHY_PER_NAC		1
  #define ICE_MAX_QUAD		2

_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan