Refine API ice_cfg_dflt_vsi and add new API
ice_check_if_dflt_vsi.

Signed-off-by: Michal Wilczynski <michal.wilczyn...@intel.com>
Signed-off-by: Qi Zhang <qi.z.zh...@intel.com>
---
 drivers/net/ice/base/ice_switch.c | 95 +++++++++++++++++--------------
 drivers/net/ice/base/ice_switch.h |  2 +
 2 files changed, 53 insertions(+), 44 deletions(-)

diff --git a/drivers/net/ice/base/ice_switch.c 
b/drivers/net/ice/base/ice_switch.c
index b8e733f539..124b4fad1b 100644
--- a/drivers/net/ice/base/ice_switch.c
+++ b/drivers/net/ice/base/ice_switch.c
@@ -2382,6 +2382,9 @@ static void ice_get_recp_to_prof_map(struct ice_hw *hw)
        }
 }
 
+static bool
+ice_vsi_uses_fltr(struct ice_fltr_mgmt_list_entry *fm_entry, u16 vsi_handle);
+
 /**
  * ice_init_def_sw_recp - initialize the recipe book keeping tables
  * @hw: pointer to the HW struct
@@ -5496,24 +5499,19 @@ enum ice_status
 ice_cfg_dflt_vsi(struct ice_port_info *pi, u16 vsi_handle, bool set,
                 u8 direction)
 {
-       struct ice_aqc_sw_rules_elem *s_rule;
+       struct ice_fltr_list_entry f_list_entry;
+       struct ice_sw_recipe *recp_list;
        struct ice_fltr_info f_info;
        struct ice_hw *hw = pi->hw;
-       enum ice_adminq_opc opcode;
        enum ice_status status;
-       u16 s_rule_size;
+       u8 lport = pi->lport;
        u16 hw_vsi_id;
+       recp_list = &pi->hw->switch_info->recp_list[ICE_SW_LKUP_DFLT];
 
        if (!ice_is_vsi_valid(hw, vsi_handle))
                return ICE_ERR_PARAM;
-       hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
-
-       s_rule_size = set ? ICE_SW_RULE_RX_TX_ETH_HDR_SIZE :
-               ICE_SW_RULE_RX_TX_NO_HDR_SIZE;
 
-       s_rule = (struct ice_aqc_sw_rules_elem *)ice_malloc(hw, s_rule_size);
-       if (!s_rule)
-               return ICE_ERR_NO_MEMORY;
+       hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
 
        ice_memset(&f_info, 0, sizeof(f_info), ICE_NONDMA_MEM);
 
@@ -5521,54 +5519,63 @@ ice_cfg_dflt_vsi(struct ice_port_info *pi, u16 
vsi_handle, bool set,
        f_info.flag = direction;
        f_info.fltr_act = ICE_FWD_TO_VSI;
        f_info.fwd_id.hw_vsi_id = hw_vsi_id;
+       f_info.vsi_handle = vsi_handle;
 
        if (f_info.flag & ICE_FLTR_RX) {
                f_info.src = pi->lport;
                f_info.src_id = ICE_SRC_ID_LPORT;
-               if (!set)
-                       f_info.fltr_rule_id =
-                               pi->dflt_rx_vsi_rule_id;
        } else if (f_info.flag & ICE_FLTR_TX) {
                f_info.src_id = ICE_SRC_ID_VSI;
                f_info.src = hw_vsi_id;
-               if (!set)
-                       f_info.fltr_rule_id =
-                               pi->dflt_tx_vsi_rule_id;
        }
+       f_list_entry.fltr_info = f_info;
 
        if (set)
-               opcode = ice_aqc_opc_add_sw_rules;
+               status = ice_add_rule_internal(hw, recp_list, lport,
+                                              &f_list_entry);
        else
-               opcode = ice_aqc_opc_remove_sw_rules;
-
-       ice_fill_sw_rule(hw, &f_info, s_rule, opcode);
-
-       status = ice_aq_sw_rules(hw, s_rule, s_rule_size, 1, opcode, NULL);
-       if (status || !(f_info.flag & ICE_FLTR_TX_RX))
-               goto out;
-       if (set) {
-               u16 index = LE16_TO_CPU(s_rule->pdata.lkup_tx_rx.index);
-
-               if (f_info.flag & ICE_FLTR_TX) {
-                       pi->dflt_tx_vsi_num = hw_vsi_id;
-                       pi->dflt_tx_vsi_rule_id = index;
-               } else if (f_info.flag & ICE_FLTR_RX) {
-                       pi->dflt_rx_vsi_num = hw_vsi_id;
-                       pi->dflt_rx_vsi_rule_id = index;
-               }
-       } else {
-               if (f_info.flag & ICE_FLTR_TX) {
-                       pi->dflt_tx_vsi_num = ICE_DFLT_VSI_INVAL;
-                       pi->dflt_tx_vsi_rule_id = ICE_INVAL_ACT;
-               } else if (f_info.flag & ICE_FLTR_RX) {
-                       pi->dflt_rx_vsi_num = ICE_DFLT_VSI_INVAL;
-                       pi->dflt_rx_vsi_rule_id = ICE_INVAL_ACT;
+               status = ice_remove_rule_internal(hw, recp_list,
+                                                 &f_list_entry);
+
+       return status;
+}
+
+/**
+ * ice_check_if_dflt_vsi - check if VSI is default VSI
+ * @pi: pointer to the port_info structure
+ * @vsi_handle: vsi handle to check for in filter list
+ * @rule_exists: indicates if there are any VSI's in the rule list
+ *
+ * checks if the VSI is in a default VSI list, and also indicates
+ * if the default VSI list is empty
+ */
+bool ice_check_if_dflt_vsi(struct ice_port_info *pi, u16 vsi_handle,
+                          bool *rule_exists)
+{
+       struct ice_fltr_mgmt_list_entry *fm_entry;
+       struct LIST_HEAD_TYPE *rule_head;
+       struct ice_sw_recipe *recp_list;
+       struct ice_lock *rule_lock;
+       bool ret = false;
+       recp_list = &pi->hw->switch_info->recp_list[ICE_SW_LKUP_DFLT];
+       rule_lock = &recp_list->filt_rule_lock;
+       rule_head = &recp_list->filt_rules;
+
+       ice_acquire_lock(rule_lock);
+
+       if (rule_exists && !LIST_EMPTY(rule_head))
+               *rule_exists = true;
+
+       LIST_FOR_EACH_ENTRY(fm_entry, rule_head,
+                           ice_fltr_mgmt_list_entry, list_entry) {
+               if (ice_vsi_uses_fltr(fm_entry, vsi_handle)) {
+                       ret = true;
+                       break;
                }
        }
 
-out:
-       ice_free(hw, s_rule);
-       return status;
+       ice_release_lock(rule_lock);
+       return ret;
 }
 
 /**
diff --git a/drivers/net/ice/base/ice_switch.h 
b/drivers/net/ice/base/ice_switch.h
index c67cd09d21..ad1397ba5a 100644
--- a/drivers/net/ice/base/ice_switch.h
+++ b/drivers/net/ice/base/ice_switch.h
@@ -486,6 +486,8 @@ void ice_remove_vsi_fltr(struct ice_hw *hw, u16 vsi_handle);
 enum ice_status
 ice_cfg_dflt_vsi(struct ice_port_info *pi, u16 vsi_handle, bool set,
                 u8 direction);
+bool ice_check_if_dflt_vsi(struct ice_port_info *pi, u16 vsi_handle,
+                          bool *rule_exists);
 enum ice_status
 ice_set_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
                    u16 vid);
-- 
2.31.1

Reply via email to