net/ice/base: remove unnecessary if branch
[dpdk.git] / drivers / net / ice / base / ice_switch.c
index 9e85da5..3ae53d3 100644 (file)
@@ -3977,7 +3977,7 @@ ice_clear_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
        if (!ice_is_vsi_valid(hw, vsi_handle))
                return ICE_ERR_PARAM;
 
-       if (vid)
+       if (promisc_mask & (ICE_PROMISC_VLAN_RX | ICE_PROMISC_VLAN_TX))
                recipe_id = ICE_SW_LKUP_PROMISC_VLAN;
        else
                recipe_id = ICE_SW_LKUP_PROMISC;
@@ -3990,13 +3990,18 @@ ice_clear_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
        ice_acquire_lock(rule_lock);
        LIST_FOR_EACH_ENTRY(itr, rule_head,
                            ice_fltr_mgmt_list_entry, list_entry) {
+               struct ice_fltr_info *fltr_info;
                u8 fltr_promisc_mask = 0;
 
                if (!ice_vsi_uses_fltr(itr, vsi_handle))
                        continue;
+               fltr_info = &itr->fltr_info;
+
+               if (recipe_id == ICE_SW_LKUP_PROMISC_VLAN &&
+                   vid != fltr_info->l_data.mac_vlan.vlan_id)
+                       continue;
 
-               fltr_promisc_mask |=
-                       ice_determine_promisc_mask(&itr->fltr_info);
+               fltr_promisc_mask |= ice_determine_promisc_mask(fltr_info);
 
                /* Skip if filter is not completely specified by given mask */
                if (fltr_promisc_mask & ~promisc_mask)
@@ -4004,7 +4009,7 @@ ice_clear_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
 
                status = ice_add_entry_to_vsi_fltr_list(hw, vsi_handle,
                                                        &remove_list_head,
-                                                       &itr->fltr_info);
+                                                       fltr_info);
                if (status) {
                        ice_release_lock(rule_lock);
                        goto free_fltr_list;
@@ -4650,17 +4655,6 @@ static const struct ice_prot_ext_tbl_entry ice_prot_ext[] = {
  * following combinations, then the recipe needs to be chained as per the
  * following policy.
  */
-static const struct ice_pref_recipe_group ice_recipe_pack[] = {
-       {3, { { ICE_MAC_OFOS_HW, 0, 0 }, { ICE_MAC_OFOS_HW, 2, 0 },
-             { ICE_MAC_OFOS_HW, 4, 0 } }, { 0xffff, 0xffff, 0xffff, 0xffff } },
-       {4, { { ICE_MAC_IL_HW, 0, 0 }, { ICE_MAC_IL_HW, 2, 0 },
-             { ICE_MAC_IL_HW, 4, 0 }, { ICE_META_DATA_ID_HW, 44, 0 } },
-               { 0xffff, 0xffff, 0xffff, 0xffff } },
-       {2, { { ICE_IPV4_IL_HW, 0, 0 }, { ICE_IPV4_IL_HW, 2, 0 } },
-               { 0xffff, 0xffff, 0xffff, 0xffff } },
-       {2, { { ICE_IPV4_IL_HW, 12, 0 }, { ICE_IPV4_IL_HW, 14, 0 } },
-               { 0xffff, 0xffff, 0xffff, 0xffff } },
-};
 
 static const struct ice_protocol_entry ice_prot_id_tbl[] = {
        { ICE_MAC_OFOS,         ICE_MAC_OFOS_HW },
@@ -4807,75 +4801,7 @@ ice_fill_valid_words(struct ice_adv_lkup_elem *rule,
        return ret_val;
 }
 
-/**
- * ice_find_prot_off_ind - check for specific ID and offset in rule
- * @lkup_exts: an array of protocol header extractions
- * @prot_type: protocol type to check
- * @off: expected offset of the extraction
- *
- * Check if the prot_ext has given protocol ID and offset
- */
-static u8
-ice_find_prot_off_ind(struct ice_prot_lkup_ext *lkup_exts, u8 prot_type,
-                     u16 off)
-{
-       u8 j;
-
-       for (j = 0; j < lkup_exts->n_val_words; j++)
-               if (lkup_exts->fv_words[j].off == off &&
-                   lkup_exts->fv_words[j].prot_id == prot_type)
-                       return j;
-
-       return ICE_MAX_CHAIN_WORDS;
-}
-
-/**
- * ice_is_recipe_subset - check if recipe group policy is a subset of lookup
- * @lkup_exts: an array of protocol header extractions
- * @r_policy: preferred recipe grouping policy
- *
- * Helper function to check if given recipe group is subset we need to check if
- * all the words described by the given recipe group exist in the advanced rule
- * look up information
- */
-static bool
-ice_is_recipe_subset(struct ice_prot_lkup_ext *lkup_exts,
-                    const struct ice_pref_recipe_group *r_policy)
-{
-       u8 ind[ICE_NUM_WORDS_RECIPE];
-       u8 count = 0;
-       u8 i;
-
-       /* check if everything in the r_policy is part of the entire rule */
-       for (i = 0; i < r_policy->n_val_pairs; i++) {
-               u8 j;
-
-               j = ice_find_prot_off_ind(lkup_exts, r_policy->pairs[i].prot_id,
-                                         r_policy->pairs[i].off);
-               if (j >= ICE_MAX_CHAIN_WORDS)
-                       return false;
-
-               /* store the indexes temporarily found by the find function
-                * this will be used to mark the words as 'done'
-                */
-               ind[count++] = j;
-       }
 
-       /* If the entire policy recipe was a true match, then mark the fields
-        * that are covered by the recipe as 'done' meaning that these words
-        * will be clumped together in one recipe.
-        * "Done" here means in our searching if certain recipe group
-        * matches or is subset of the given rule, then we mark all
-        * the corresponding offsets as found. So the remaining recipes should
-        * be created with whatever words that were left.
-        */
-       for (i = 0; i < count; i++) {
-               u8 in = ind[i];
-
-               ice_set_bit(in, lkup_exts->done);
-       }
-       return true;
-}
 
 /**
  * ice_create_first_fit_recp_def - Create a recipe grouping
@@ -5384,51 +5310,11 @@ static enum ice_status
 ice_create_recipe_group(struct ice_hw *hw, struct ice_sw_recipe *rm,
                        struct ice_prot_lkup_ext *lkup_exts)
 {
-       struct ice_recp_grp_entry *entry;
-       struct ice_recp_grp_entry *tmp;
        enum ice_status status;
        u8 recp_count = 0;
-       u16 groups, i;
 
        rm->n_grp_count = 0;
 
-
-       if (lkup_exts->n_val_words > ICE_NUM_WORDS_RECIPE) {
-               /* Each switch recipe can match up to 5 words or metadata. One
-                * word in each recipe is used to match the switch ID. Four
-                * words are left for matching other values. If the new advanced
-                * recipe requires more than 4 words, it needs to be split into
-                * multiple recipes which are chained together using the
-                * intermediate result that each produces as input to the other
-                * recipes in the sequence.
-                */
-               groups = ARRAY_SIZE(ice_recipe_pack);
-
-               /* Check if any of the preferred recipes from the grouping
-                * policy matches.
-                */
-               for (i = 0; i < groups; i++)
-                       /* Check if the recipe from the preferred grouping
-                        * matches or is a subset of the fields that needs to be
-                        * looked up.
-                        */
-                       if (ice_is_recipe_subset(lkup_exts,
-                                                &ice_recipe_pack[i])) {
-                               /* This recipe can be used by itself or grouped
-                                * with other recipes.
-                                */
-                               entry = (struct ice_recp_grp_entry *)
-                                       ice_malloc(hw, sizeof(*entry));
-                               if (!entry) {
-                                       status = ICE_ERR_NO_MEMORY;
-                                       goto err_unroll;
-                               }
-                               entry->r_group = ice_recipe_pack[i];
-                               LIST_ADD(&entry->l_entry, &rm->rg_list);
-                               rm->n_grp_count++;
-                       }
-       }
-
        /* Create recipes for words that are marked not done by packing them
         * as best fit.
         */
@@ -5441,17 +5327,8 @@ ice_create_recipe_group(struct ice_hw *hw, struct ice_sw_recipe *rm,
                           sizeof(rm->ext_words), ICE_NONDMA_TO_NONDMA);
                ice_memcpy(rm->word_masks, lkup_exts->field_mask,
                           sizeof(rm->word_masks), ICE_NONDMA_TO_NONDMA);
-               goto out;
-       }
-
-err_unroll:
-       LIST_FOR_EACH_ENTRY_SAFE(entry, tmp, &rm->rg_list, ice_recp_grp_entry,
-                                l_entry) {
-               LIST_DEL(&entry->l_entry);
-               ice_free(hw, entry);
        }
 
-out:
        return status;
 }
 
@@ -5948,6 +5825,55 @@ ice_fill_adv_dummy_packet(struct ice_adv_lkup_elem *lkups, u16 lkups_cnt,
        return ICE_SUCCESS;
 }
 
+/**
+ * ice_fill_adv_packet_tun - fill dummy packet with udp tunnel port
+ * @hw: pointer to the hardware structure
+ * @tun_type: tunnel type
+ * @pkt: dummy packet to fill in
+ * @offsets: offset info for the dummy packet
+ */
+static enum ice_status
+ice_fill_adv_packet_tun(struct ice_hw *hw, enum ice_sw_tunnel_type tun_type,
+                       u8 *pkt, const struct ice_dummy_pkt_offsets *offsets)
+{
+       u16 open_port, i;
+
+       switch (tun_type) {
+       case ICE_SW_TUN_AND_NON_TUN:
+       case ICE_SW_TUN_VXLAN_GPE:
+       case ICE_SW_TUN_VXLAN:
+       case ICE_SW_TUN_UDP:
+               if (!ice_get_open_tunnel_port(hw, TNL_VXLAN, &open_port))
+                       return ICE_ERR_CFG;
+               break;
+
+       case ICE_SW_TUN_GENEVE:
+               if (!ice_get_open_tunnel_port(hw, TNL_GENEVE, &open_port))
+                       return ICE_ERR_CFG;
+               break;
+
+       default:
+               /* Nothing needs to be done for this tunnel type */
+               return ICE_SUCCESS;
+       }
+
+       /* Find the outer UDP protocol header and insert the port number */
+       for (i = 0; offsets[i].type != ICE_PROTOCOL_LAST; i++) {
+               if (offsets[i].type == ICE_UDP_OF) {
+                       struct ice_l4_hdr *hdr;
+                       u16 offset;
+
+                       offset = offsets[i].offset;
+                       hdr = (struct ice_l4_hdr *)&pkt[offset];
+                       hdr->dst_port = open_port << 8 | open_port >> 8;
+
+                       return ICE_SUCCESS;
+               }
+       }
+
+       return ICE_ERR_CFG;
+}
+
 /**
  * ice_find_adv_rule_entry - Search a rule entry
  * @hw: pointer to the hardware structure
@@ -6252,6 +6178,14 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
        ice_fill_adv_dummy_packet(lkups, lkups_cnt, s_rule, pkt, pkt_len,
                                  pkt_offsets);
 
+       if (rinfo->tun_type != ICE_NON_TUN) {
+               status = ice_fill_adv_packet_tun(hw, rinfo->tun_type,
+                                                s_rule->pdata.lkup_tx_rx.hdr,
+                                                pkt_offsets);
+               if (status)
+                       goto err_ice_add_adv_rule;
+       }
+
        status = ice_aq_sw_rules(hw, (struct ice_aqc_sw_rules *)s_rule,
                                 rule_buf_sz, 1, ice_aqc_opc_add_sw_rules,
                                 NULL);
@@ -6385,9 +6319,7 @@ ice_adv_rem_update_vsi_list(struct ice_hw *hw, u16 vsi_handle,
                                  tmp_fltr.fwd_id.hw_vsi_id, status);
                        return status;
                }
-       }
 
-       if (fm_list->vsi_count == 1) {
                /* Remove the VSI list since it is no longer used */
                status = ice_remove_vsi_list_rule(hw, vsi_list_id, lkup_type);
                if (status) {
@@ -6426,14 +6358,11 @@ ice_rem_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
                 u16 lkups_cnt, struct ice_adv_rule_info *rinfo)
 {
        struct ice_adv_fltr_mgmt_list_entry *list_elem;
-       const struct ice_dummy_pkt_offsets *offsets;
        struct ice_prot_lkup_ext lkup_exts;
-       u16 rule_buf_sz, pkt_len, i, rid;
        struct ice_lock *rule_lock; /* Lock to protect filter rule list */
        enum ice_status status = ICE_SUCCESS;
        bool remove_rule = false;
-       const u8 *pkt = NULL;
-       u16 vsi_handle;
+       u16 i, rid, vsi_handle;
 
        ice_memset(&lkup_exts, 0, sizeof(lkup_exts), ICE_NONDMA_MEM);
        for (i = 0; i < lkups_cnt; i++) {
@@ -6485,10 +6414,9 @@ ice_rem_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
        ice_release_lock(rule_lock);
        if (remove_rule) {
                struct ice_aqc_sw_rules_elem *s_rule;
+               u16 rule_buf_sz;
 
-               ice_find_dummy_packet(lkups, lkups_cnt, rinfo->tun_type, &pkt,
-                                     &pkt_len, &offsets);
-               rule_buf_sz = ICE_SW_RULE_RX_TX_NO_HDR_SIZE + pkt_len;
+               rule_buf_sz = ICE_SW_RULE_RX_TX_NO_HDR_SIZE;
                s_rule =
                        (struct ice_aqc_sw_rules_elem *)ice_malloc(hw,
                                                                   rule_buf_sz);