net/ena: update version to 2.0.1
[dpdk.git] / drivers / net / ice / base / ice_switch.c
index 4bdff58..be43c8b 100644 (file)
@@ -53,84 +53,297 @@ static const u8 dummy_eth_header[DUMMY_ETH_HDR_LEN] = { 0x2, 0, 0, 0, 0, 0,
         sizeof(((struct ice_sw_rule_vsi_list *)0)->vsi) + \
         ((n) * sizeof(((struct ice_sw_rule_vsi_list *)0)->vsi)))
 
+struct ice_dummy_pkt_offsets {
+       enum ice_protocol_type type;
+       u16 offset; /* ICE_PROTOCOL_LAST indicates end of list */
+};
+
 static const
-u8 dummy_gre_packet[] = { 0, 0, 0, 0,          /* Ether starts */
+struct ice_dummy_pkt_offsets dummy_gre_packet_offsets[] = {
+       { ICE_MAC_OFOS,         0 },
+       { ICE_ETYPE_OL,         12 },
+       { ICE_IPV4_OFOS,        14 },
+       { ICE_NVGRE,            34 },
+       { ICE_MAC_IL,           42 },
+       { ICE_IPV4_IL,          56 },
+       { ICE_PROTOCOL_LAST,    0 },
+};
+
+static const
+u8 dummy_gre_packet[] = { 0, 0, 0, 0,          /* ICE_MAC_OFOS 0 */
                          0, 0, 0, 0,
                          0, 0, 0, 0,
-                         0x08, 0,              /* Ether ends */
-                         0x45, 0, 0, 0x3E,     /* IP starts */
+                         0x08, 0,              /* ICE_ETYPE_OL 12 */
+                         0x45, 0, 0, 0x3E,     /* ICE_IPV4_OFOS 14 */
                          0, 0, 0, 0,
                          0, 0x2F, 0, 0,
                          0, 0, 0, 0,
-                         0, 0, 0, 0,           /* IP ends */
-                         0x80, 0, 0x65, 0x58,  /* GRE starts */
-                         0, 0, 0, 0,           /* GRE ends */
-                         0, 0, 0, 0,           /* Ether starts */
                          0, 0, 0, 0,
+                         0x80, 0, 0x65, 0x58,  /* ICE_NVGRE 34 */
                          0, 0, 0, 0,
-                         0x08, 0,              /* Ether ends */
-                         0x45, 0, 0, 0x14,     /* IP starts */
+                         0, 0, 0, 0,           /* ICE_MAC_IL 42 */
                          0, 0, 0, 0,
                          0, 0, 0, 0,
+                         0x08, 0,
+                         0x45, 0, 0, 0x14,     /* ICE_IPV4_IL 54 */
                          0, 0, 0, 0,
-                         0, 0, 0, 0            /* IP ends */
-                       };
-
-static const u8
-dummy_udp_tun_packet[] = {0, 0, 0, 0,          /* Ether starts */
-                         0, 0, 0, 0,
-                         0, 0, 0, 0,
-                         0x08, 0,              /* Ether ends */
-                         0x45, 0, 0, 0x32,     /* IP starts */
                          0, 0, 0, 0,
-                         0, 0x11, 0, 0,
                          0, 0, 0, 0,
-                         0, 0, 0, 0,           /* IP ends */
-                         0, 0, 0x12, 0xB5,     /* UDP start*/
-                         0, 0x1E, 0, 0,        /* UDP end*/
-                         0, 0, 0, 0,           /* VXLAN start */
-                         0, 0, 0, 0,           /* VXLAN end*/
-                         0, 0, 0, 0,           /* Ether starts */
-                         0, 0, 0, 0,
-                         0, 0, 0, 0,
-                         0, 0                  /* Ether ends */
+                         0, 0, 0, 0
                        };
 
+static const
+struct ice_dummy_pkt_offsets dummy_udp_tun_tcp_packet_offsets[] = {
+       { ICE_MAC_OFOS,         0 },
+       { ICE_ETYPE_OL,         12 },
+       { ICE_IPV4_OFOS,        14 },
+       { ICE_UDP_OF,           34 },
+       { ICE_VXLAN,            42 },
+       { ICE_MAC_IL,           50 },
+       { ICE_IPV4_IL,          64 },
+       { ICE_TCP_IL,           84 },
+       { ICE_PROTOCOL_LAST,    0 },
+};
+
+static const
+u8 dummy_udp_tun_tcp_packet[] = {
+       0x00, 0x00, 0x00, 0x00,  /* ICE_MAC_OFOS 0 */
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+
+       0x08, 0x00,             /* ICE_ETYPE_OL 12 */
+
+       0x45, 0x00, 0x00, 0x5a, /* ICE_IPV4_OFOS 14 */
+       0x00, 0x01, 0x00, 0x00,
+       0x40, 0x11, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+
+       0x00, 0x00, 0x12, 0xb5, /* ICE_UDP_OF 34 */
+       0x00, 0x46, 0x00, 0x00,
+
+       0x04, 0x00, 0x00, 0x03, /* ICE_VXLAN 42 */
+       0x00, 0x00, 0x00, 0x00,
+
+       0x00, 0x00, 0x00, 0x00, /* ICE_MAC_IL 50 */
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x08, 0x00,
+
+       0x45, 0x00, 0x00, 0x28, /* ICE_IPV4_IL 64 */
+       0x00, 0x01, 0x00, 0x00,
+       0x40, 0x06, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+
+       0x00, 0x00, 0x00, 0x00, /* ICE_TCP_IL 84 */
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x50, 0x02, 0x20, 0x00,
+       0x00, 0x00, 0x00, 0x00
+};
+
+static const
+struct ice_dummy_pkt_offsets dummy_udp_tun_udp_packet_offsets[] = {
+       { ICE_MAC_OFOS,         0 },
+       { ICE_ETYPE_OL,         12 },
+       { ICE_IPV4_OFOS,        14 },
+       { ICE_UDP_OF,           34 },
+       { ICE_VXLAN,            42 },
+       { ICE_MAC_IL,           50 },
+       { ICE_IPV4_IL,          64 },
+       { ICE_UDP_ILOS,         84 },
+       { ICE_PROTOCOL_LAST,    0 },
+};
+
+static const
+u8 dummy_udp_tun_udp_packet[] = {
+       0x00, 0x00, 0x00, 0x00,  /* ICE_MAC_OFOS 0 */
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+
+       0x08, 0x00,             /* ICE_ETYPE_OL 12 */
+
+       0x45, 0x00, 0x00, 0x4e, /* ICE_IPV4_OFOS 14 */
+       0x00, 0x01, 0x00, 0x00,
+       0x00, 0x11, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+
+       0x00, 0x00, 0x12, 0xb5, /* ICE_UDP_OF 34 */
+       0x00, 0x3a, 0x00, 0x00,
+
+       0x0c, 0x00, 0x00, 0x03, /* ICE_VXLAN 42 */
+       0x00, 0x00, 0x00, 0x00,
+
+       0x00, 0x00, 0x00, 0x00, /* ICE_MAC_IL 50 */
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x08, 0x00,
+
+       0x45, 0x00, 0x00, 0x1c, /* ICE_IPV4_IL 64 */
+       0x00, 0x01, 0x00, 0x00,
+       0x00, 0x11, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+
+       0x00, 0x00, 0x00, 0x00, /* ICE_UDP_ILOS 84 */
+       0x00, 0x08, 0x00, 0x00,
+};
+
+static const
+struct ice_dummy_pkt_offsets dummy_udp_packet_offsets[] = {
+       { ICE_MAC_OFOS,         0 },
+       { ICE_ETYPE_OL,         12 },
+       { ICE_IPV4_OFOS,        14 },
+       { ICE_UDP_ILOS,         34 },
+       { ICE_PROTOCOL_LAST,    0 },
+};
+
 static const u8
-dummy_tcp_tun_packet[] = {0, 0, 0, 0,          /* Ether starts */
-                         0, 0, 0, 0,
-                         0, 0, 0, 0,
-                         0x08, 0,              /* Ether ends */
-                         0x45, 0, 0, 0x28,     /* IP starts */
-                         0, 0x01, 0, 0,
-                         0x40, 0x06, 0xF5, 0x69,
-                         0, 0, 0, 0,
-                         0, 0, 0, 0,   /* IP ends */
-                         0, 0, 0, 0,
-                         0, 0, 0, 0,
-                         0, 0, 0, 0,
-                         0x50, 0x02, 0x20,
-                         0, 0x9, 0x79, 0, 0,
-                         0, 0 /* 2 bytes padding for 4 byte alignment*/
-                       };
+dummy_udp_packet[] = {
+       0x00, 0x00, 0x00, 0x00, /* ICE_MAC_OFOS 0 */
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+
+       0x08, 0x00,             /* ICE_ETYPE_OL 12 */
+
+       0x45, 0x00, 0x00, 0x1c, /* ICE_IPV4_OFOS 14 */
+       0x00, 0x01, 0x00, 0x00,
+       0x00, 0x11, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+
+       0x00, 0x00, 0x00, 0x00, /* ICE_UDP_ILOS 34 */
+       0x00, 0x08, 0x00, 0x00,
+
+       0x00, 0x00,     /* 2 bytes for 4 byte alignment */
+};
+
+static const
+struct ice_dummy_pkt_offsets dummy_tcp_packet_offsets[] = {
+       { ICE_MAC_OFOS,         0 },
+       { ICE_ETYPE_OL,         12 },
+       { ICE_IPV4_OFOS,        14 },
+       { ICE_TCP_IL,           34 },
+       { ICE_PROTOCOL_LAST,    0 },
+};
+
+static const u8
+dummy_tcp_packet[] = {
+       0x00, 0x00, 0x00, 0x00, /* ICE_MAC_OFOS 0 */
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+
+       0x08, 0x00,             /* ICE_ETYPE_OL 12 */
+
+       0x45, 0x00, 0x00, 0x28, /* ICE_IPV4_OFOS 14 */
+       0x00, 0x01, 0x00, 0x00,
+       0x00, 0x06, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+
+       0x00, 0x00, 0x00, 0x00, /* ICE_TCP_IL 34 */
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x50, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+
+       0x00, 0x00,     /* 2 bytes for 4 byte alignment */
+};
+
+static const
+struct ice_dummy_pkt_offsets dummy_tcp_ipv6_packet_offsets[] = {
+       { ICE_MAC_OFOS,         0 },
+       { ICE_ETYPE_OL,         12 },
+       { ICE_IPV6_OFOS,        14 },
+       { ICE_TCP_IL,           54 },
+       { ICE_PROTOCOL_LAST,    0 },
+};
+
+static const u8
+dummy_tcp_ipv6_packet[] = {
+       0x00, 0x00, 0x00, 0x00, /* ICE_MAC_OFOS 0 */
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+
+       0x86, 0xDD,             /* ICE_ETYPE_OL 12 */
+
+       0x60, 0x00, 0x00, 0x00, /* ICE_IPV6_OFOS 40 */
+       0x00, 0x14, 0x06, 0x00, /* Next header is TCP */
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+
+       0x00, 0x00, 0x00, 0x00, /* ICE_TCP_IL 54 */
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x50, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+
+       0x00, 0x00, /* 2 bytes for 4 byte alignment */
+};
+
+static const
+struct ice_dummy_pkt_offsets dummy_udp_ipv6_packet_offsets[] = {
+       { ICE_MAC_OFOS,         0 },
+       { ICE_ETYPE_OL,         12 },
+       { ICE_IPV6_OFOS,        14 },
+       { ICE_UDP_ILOS,         54 },
+       { ICE_PROTOCOL_LAST,    0 },
+};
+
+static const u8
+dummy_udp_ipv6_packet[] = {
+       0x00, 0x00, 0x00, 0x00, /* ICE_MAC_OFOS 0 */
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+
+       0x86, 0xDD,             /* ICE_ETYPE_OL 12 */
+
+       0x60, 0x00, 0x00, 0x00, /* ICE_IPV6_OFOS 40 */
+       0x00, 0x08, 0x11, 0x00, /* Next header UDP*/
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+
+       0x00, 0x00, 0x00, 0x00, /* ICE_UDP_ILOS 54 */
+       0x00, 0x08, 0x00, 0x00,
+
+       0x00, 0x00, /* 2 bytes for 4 byte alignment */
+};
 
 /* this is a recipe to profile bitmap association */
 static ice_declare_bitmap(recipe_to_profile[ICE_MAX_NUM_RECIPES],
                          ICE_MAX_NUM_PROFILES);
 static ice_declare_bitmap(available_result_ids, ICE_CHAIN_FV_INDEX_START + 1);
 
+static void ice_get_recp_to_prof_map(struct ice_hw *hw);
+
 /**
  * ice_get_recp_frm_fw - update SW bookkeeping from FW recipe entries
  * @hw: pointer to hardware structure
  * @recps: struct that we need to populate
  * @rid: recipe ID that we are populating
+ * @refresh_required: true if we should get recipe to profile mapping from FW
  *
  * This function is used to populate all the necessary entries into our
  * bookkeeping so that we have a current list of all the recipes that are
  * programmed in the firmware.
  */
 static enum ice_status
-ice_get_recp_frm_fw(struct ice_hw *hw, struct ice_sw_recipe *recps, u8 rid)
+ice_get_recp_frm_fw(struct ice_hw *hw, struct ice_sw_recipe *recps, u8 rid,
+                   bool *refresh_required)
 {
        u16 i, sub_recps, fv_word_idx = 0, result_idx = 0;
        ice_declare_bitmap(r_bitmap, ICE_MAX_NUM_PROFILES);
@@ -151,6 +364,19 @@ ice_get_recp_frm_fw(struct ice_hw *hw, struct ice_sw_recipe *recps, u8 rid)
        /* non-zero status meaning recipe doesn't exist */
        if (status)
                goto err_unroll;
+
+       /* Get recipe to profile map so that we can get the fv from lkups that
+        * we read for a recipe from FW. Since we want to minimize the number of
+        * times we make this FW call, just make one call and cache the copy
+        * until a new recipe is added. This operation is only required the
+        * first time to get the changes from FW. Then to search existing
+        * entries we don't need to update the cache again until another recipe
+        * gets added.
+        */
+       if (*refresh_required) {
+               ice_get_recp_to_prof_map(hw);
+               *refresh_required = false;
+       }
        lkup_exts = &recps[rid].lkup_exts;
        /* start populating all the entries for recps[rid] based on lkups from
         * firmware
@@ -184,6 +410,9 @@ ice_get_recp_frm_fw(struct ice_hw *hw, struct ice_sw_recipe *recps, u8 rid)
                        u8 lkup_indx = root_bufs.content.lkup_indx[i + 1];
 
                        rg_entry->fv_idx[i] = lkup_indx;
+                       rg_entry->fv_mask[i] =
+                               LE16_TO_CPU(root_bufs.content.mask[i + 1]);
+
                        /* If the recipe is a chained recipe then all its
                         * child recipe's result will have a result index.
                         * To fill fv_words we should not use those result
@@ -687,10 +916,7 @@ static void ice_clear_vsi_ctx(struct ice_hw *hw, u16 vsi_handle)
 
        vsi = ice_get_vsi_ctx(hw, vsi_handle);
        if (vsi) {
-               if (!LIST_EMPTY(&vsi->rss_list_head))
-                       ice_rem_all_rss_vsi_ctx(hw, vsi_handle);
                ice_clear_vsi_q_ctx(hw, vsi_handle);
-               ice_destroy_lock(&vsi->rss_locks);
                ice_free(hw, vsi);
                hw->vsi_ctx[vsi_handle] = NULL;
        }
@@ -741,8 +967,7 @@ ice_add_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
                        return ICE_ERR_NO_MEMORY;
                }
                *tmp_vsi_ctx = *vsi_ctx;
-               ice_init_lock(&tmp_vsi_ctx->rss_locks);
-               INIT_LIST_HEAD(&tmp_vsi_ctx->rss_list_head);
+
                ice_save_vsi_ctx(hw, vsi_handle, tmp_vsi_ctx);
        } else {
                /* update with new HW VSI num */
@@ -864,7 +1089,7 @@ ice_aq_add_update_mir_rule(struct ice_hw *hw, u16 rule_type, u16 dest_vsi,
                        return ICE_ERR_PARAM;
 
                buf_size = count * sizeof(__le16);
-               mr_list = (__le16 *)ice_malloc(hw, buf_size);
+               mr_list = (_FORCE_ __le16 *)ice_malloc(hw, buf_size);
                if (!mr_list)
                        return ICE_ERR_NO_MEMORY;
                break;
@@ -1464,7 +1689,6 @@ static int ice_ilog2(u64 n)
        return -1;
 }
 
-
 /**
  * ice_fill_sw_rule - Helper function to fill switch rule structure
  * @hw: pointer to the hardware structure
@@ -1484,7 +1708,6 @@ ice_fill_sw_rule(struct ice_hw *hw, struct ice_fltr_info *f_info,
        __be16 *off;
        u8 q_rgn;
 
-
        if (opc == ice_aqc_opc_remove_sw_rules) {
                s_rule->pdata.lkup_tx_rx.act = 0;
                s_rule->pdata.lkup_tx_rx.index =
@@ -1560,7 +1783,7 @@ ice_fill_sw_rule(struct ice_hw *hw, struct ice_fltr_info *f_info,
                daddr = f_info->l_data.ethertype_mac.mac_addr;
                /* fall-through */
        case ICE_SW_LKUP_ETHERTYPE:
-               off = (__be16 *)(eth_hdr + ICE_ETH_ETHTYPE_OFFSET);
+               off = (_FORCE_ __be16 *)(eth_hdr + ICE_ETH_ETHTYPE_OFFSET);
                *off = CPU_TO_BE16(f_info->l_data.ethertype_mac.ethertype);
                break;
        case ICE_SW_LKUP_MAC_VLAN:
@@ -1591,7 +1814,7 @@ ice_fill_sw_rule(struct ice_hw *hw, struct ice_fltr_info *f_info,
                           ICE_NONDMA_TO_NONDMA);
 
        if (!(vlan_id > ICE_MAX_VLAN_ID)) {
-               off = (__be16 *)(eth_hdr + ICE_ETH_VLAN_TCI_OFFSET);
+               off = (_FORCE_ __be16 *)(eth_hdr + ICE_ETH_VLAN_TCI_OFFSET);
                *off = CPU_TO_BE16(vlan_id);
        }
 
@@ -2218,17 +2441,38 @@ ice_find_vsi_list_entry(struct ice_hw *hw, u8 recp_id, u16 vsi_handle,
 {
        struct ice_vsi_list_map_info *map_info = NULL;
        struct ice_switch_info *sw = hw->switch_info;
-       struct ice_fltr_mgmt_list_entry *list_itr;
        struct LIST_HEAD_TYPE *list_head;
 
        list_head = &sw->recp_list[recp_id].filt_rules;
-       LIST_FOR_EACH_ENTRY(list_itr, list_head, ice_fltr_mgmt_list_entry,
-                           list_entry) {
-               if (list_itr->vsi_count == 1 && list_itr->vsi_list_info) {
-                       map_info = list_itr->vsi_list_info;
-                       if (ice_is_bit_set(map_info->vsi_map, vsi_handle)) {
-                               *vsi_list_id = map_info->vsi_list_id;
-                               return map_info;
+       if (sw->recp_list[recp_id].adv_rule) {
+               struct ice_adv_fltr_mgmt_list_entry *list_itr;
+
+               LIST_FOR_EACH_ENTRY(list_itr, list_head,
+                                   ice_adv_fltr_mgmt_list_entry,
+                                   list_entry) {
+                       if (list_itr->vsi_list_info) {
+                               map_info = list_itr->vsi_list_info;
+                               if (ice_is_bit_set(map_info->vsi_map,
+                                                  vsi_handle)) {
+                                       *vsi_list_id = map_info->vsi_list_id;
+                                       return map_info;
+                               }
+                       }
+               }
+       } else {
+               struct ice_fltr_mgmt_list_entry *list_itr;
+
+               LIST_FOR_EACH_ENTRY(list_itr, list_head,
+                                   ice_fltr_mgmt_list_entry,
+                                   list_entry) {
+                       if (list_itr->vsi_count == 1 &&
+                           list_itr->vsi_list_info) {
+                               map_info = list_itr->vsi_list_info;
+                               if (ice_is_bit_set(map_info->vsi_map,
+                                                  vsi_handle)) {
+                                       *vsi_list_id = map_info->vsi_list_id;
+                                       return map_info;
+                               }
                        }
                }
        }
@@ -2273,14 +2517,15 @@ ice_add_rule_internal(struct ice_hw *hw, u8 recp_id,
 
        m_entry = ice_find_rule_entry(hw, recp_id, new_fltr);
        if (!m_entry) {
-               ice_release_lock(rule_lock);
-               return ice_create_pkt_fwd_rule(hw, f_entry);
+               status = ice_create_pkt_fwd_rule(hw, f_entry);
+               goto exit_add_rule_internal;
        }
 
        cur_fltr = &m_entry->fltr_info;
        status = ice_add_update_vsi_list(hw, m_entry, cur_fltr, new_fltr);
-       ice_release_lock(rule_lock);
 
+exit_add_rule_internal:
+       ice_release_lock(rule_lock);
        return status;
 }
 
@@ -2918,7 +3163,6 @@ ice_add_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *v_list)
        return ICE_SUCCESS;
 }
 
-#ifndef NO_MACVLAN_SUPPORT
 /**
  * ice_add_mac_vlan - Add MAC and VLAN pair based filter rule
  * @hw: pointer to the hardware structure
@@ -2953,18 +3197,24 @@ ice_add_mac_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *mv_list)
        }
        return ICE_SUCCESS;
 }
-#endif
 
 /**
  * ice_add_eth_mac - Add ethertype and MAC based filter rule
  * @hw: pointer to the hardware structure
  * @em_list: list of ether type MAC filter, MAC is optional
+ *
+ * This function requires the caller to populate the entries in
+ * the filter list with the necessary fields (including flags to
+ * indicate Tx or Rx rules).
  */
 enum ice_status
 ice_add_eth_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *em_list)
 {
        struct ice_fltr_list_entry *em_list_itr;
 
+       if (!em_list || !hw)
+               return ICE_ERR_PARAM;
+
        LIST_FOR_EACH_ENTRY(em_list_itr, em_list, ice_fltr_list_entry,
                            list_entry) {
                enum ice_sw_lkup_type l_type =
@@ -2974,7 +3224,6 @@ ice_add_eth_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *em_list)
                    l_type != ICE_SW_LKUP_ETHERTYPE)
                        return ICE_ERR_PARAM;
 
-               em_list_itr->fltr_info.flag = ICE_FLTR_TX;
                em_list_itr->status = ice_add_rule_internal(hw, l_type,
                                                            em_list_itr);
                if (em_list_itr->status)
@@ -3034,6 +3283,27 @@ ice_rem_sw_rule_info(struct ice_hw *hw, struct LIST_HEAD_TYPE *rule_head)
        }
 }
 
+/**
+ * ice_rem_adv_rule_info
+ * @hw: pointer to the hardware structure
+ * @rule_head: pointer to the switch list structure that we want to delete
+ */
+static void
+ice_rem_adv_rule_info(struct ice_hw *hw, struct LIST_HEAD_TYPE *rule_head)
+{
+       struct ice_adv_fltr_mgmt_list_entry *tmp_entry;
+       struct ice_adv_fltr_mgmt_list_entry *lst_itr;
+
+       if (LIST_EMPTY(rule_head))
+               return;
+
+       LIST_FOR_EACH_ENTRY_SAFE(lst_itr, tmp_entry, rule_head,
+                                ice_adv_fltr_mgmt_list_entry, list_entry) {
+               LIST_DEL(&lst_itr->list_entry);
+               ice_free(hw, lst_itr->lkups);
+               ice_free(hw, lst_itr);
+       }
+}
 
 /**
  * ice_rem_all_sw_rules_info
@@ -3050,6 +3320,8 @@ void ice_rem_all_sw_rules_info(struct ice_hw *hw)
                rule_head = &sw->recp_list[i].filt_rules;
                if (!sw->recp_list[i].adv_rule)
                        ice_rem_sw_rule_info(hw, rule_head);
+               else
+                       ice_rem_adv_rule_info(hw, rule_head);
        }
 }
 
@@ -3141,6 +3413,39 @@ out:
        return status;
 }
 
+/**
+ * ice_find_ucast_rule_entry - Search for a unicast MAC filter rule entry
+ * @hw: pointer to the hardware structure
+ * @recp_id: lookup type for which the specified rule needs to be searched
+ * @f_info: rule information
+ *
+ * Helper function to search for a unicast rule entry - this is to be used
+ * to remove unicast MAC filter that is not shared with other VSIs on the
+ * PF switch.
+ *
+ * Returns pointer to entry storing the rule if found
+ */
+static struct ice_fltr_mgmt_list_entry *
+ice_find_ucast_rule_entry(struct ice_hw *hw, u8 recp_id,
+                         struct ice_fltr_info *f_info)
+{
+       struct ice_switch_info *sw = hw->switch_info;
+       struct ice_fltr_mgmt_list_entry *list_itr;
+       struct LIST_HEAD_TYPE *list_head;
+
+       list_head = &sw->recp_list[recp_id].filt_rules;
+       LIST_FOR_EACH_ENTRY(list_itr, list_head, ice_fltr_mgmt_list_entry,
+                           list_entry) {
+               if (!memcmp(&f_info->l_data, &list_itr->fltr_info.l_data,
+                           sizeof(f_info->l_data)) &&
+                   f_info->fwd_id.hw_vsi_id ==
+                   list_itr->fltr_info.fwd_id.hw_vsi_id &&
+                   f_info->flag == list_itr->fltr_info.flag)
+                       return list_itr;
+       }
+       return NULL;
+}
+
 /**
  * ice_remove_mac - remove a MAC address based filter rule
  * @hw: pointer to the hardware structure
@@ -3158,16 +3463,40 @@ enum ice_status
 ice_remove_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *m_list)
 {
        struct ice_fltr_list_entry *list_itr, *tmp;
+       struct ice_lock *rule_lock; /* Lock to protect filter rule list */
 
        if (!m_list)
                return ICE_ERR_PARAM;
 
+       rule_lock = &hw->switch_info->recp_list[ICE_SW_LKUP_MAC].filt_rule_lock;
        LIST_FOR_EACH_ENTRY_SAFE(list_itr, tmp, m_list, ice_fltr_list_entry,
                                 list_entry) {
                enum ice_sw_lkup_type l_type = list_itr->fltr_info.lkup_type;
+               u8 *add = &list_itr->fltr_info.l_data.mac.mac_addr[0];
+               u16 vsi_handle;
 
                if (l_type != ICE_SW_LKUP_MAC)
                        return ICE_ERR_PARAM;
+
+               vsi_handle = list_itr->fltr_info.vsi_handle;
+               if (!ice_is_vsi_valid(hw, vsi_handle))
+                       return ICE_ERR_PARAM;
+
+               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) {
+                       /* Don't remove the unicast address that belongs to
+                        * another VSI on the switch, since it is not being
+                        * shared...
+                        */
+                       ice_acquire_lock(rule_lock);
+                       if (!ice_find_ucast_rule_entry(hw, ICE_SW_LKUP_MAC,
+                                                      &list_itr->fltr_info)) {
+                               ice_release_lock(rule_lock);
+                               return ICE_ERR_DOES_NOT_EXIST;
+                       }
+                       ice_release_lock(rule_lock);
+               }
                list_itr->status = ice_remove_rule_internal(hw,
                                                            ICE_SW_LKUP_MAC,
                                                            list_itr);
@@ -3205,7 +3534,6 @@ ice_remove_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *v_list)
        return ICE_SUCCESS;
 }
 
-#ifndef NO_MACVLAN_SUPPORT
 /**
  * ice_remove_mac_vlan - Remove MAC VLAN based filter rule
  * @hw: pointer to the hardware structure
@@ -3233,7 +3561,6 @@ ice_remove_mac_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *v_list)
        }
        return ICE_SUCCESS;
 }
-#endif /* !NO_MACVLAN_SUPPORT */
 
 /**
  * ice_vsi_uses_fltr - Determine if given VSI uses specified filter
@@ -3748,11 +4075,7 @@ ice_remove_vsi_lkup_fltr(struct ice_hw *hw, u16 vsi_handle,
                ice_remove_promisc(hw, lkup, &remove_list_head);
                break;
        case ICE_SW_LKUP_MAC_VLAN:
-#ifndef NO_MACVLAN_SUPPORT
                ice_remove_mac_vlan(hw, &remove_list_head);
-#else
-               ice_debug(hw, ICE_DBG_SW, "MAC VLAN look up is not supported yet\n");
-#endif /* !NO_MACVLAN_SUPPORT */
                break;
        case ICE_SW_LKUP_ETHERTYPE:
        case ICE_SW_LKUP_ETHERTYPE_MAC:
@@ -4145,6 +4468,7 @@ exit_error:
 static const struct ice_prot_ext_tbl_entry ice_prot_ext[] = {
        { ICE_MAC_OFOS,         { 0, 2, 4, 6, 8, 10, 12 } },
        { ICE_MAC_IL,           { 0, 2, 4, 6, 8, 10, 12 } },
+       { ICE_ETYPE_OL,         { 0 } },
        { ICE_IPV4_OFOS,        { 0, 2, 4, 6, 8, 10, 12, 14, 16, 18 } },
        { ICE_IPV4_IL,          { 0, 2, 4, 6, 8, 10, 12, 14, 16, 18 } },
        { ICE_IPV6_IL,          { 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24,
@@ -4152,12 +4476,13 @@ static const struct ice_prot_ext_tbl_entry ice_prot_ext[] = {
        { ICE_IPV6_OFOS,        { 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24,
                                 26, 28, 30, 32, 34, 36, 38 } },
        { ICE_TCP_IL,           { 0, 2 } },
+       { ICE_UDP_OF,           { 0, 2 } },
        { ICE_UDP_ILOS,         { 0, 2 } },
        { ICE_SCTP_IL,          { 0, 2 } },
-       { ICE_VXLAN,            { 8, 10, 12 } },
-       { ICE_GENEVE,           { 8, 10, 12 } },
+       { ICE_VXLAN,            { 8, 10, 12, 14 } },
+       { ICE_GENEVE,           { 8, 10, 12, 14 } },
        { ICE_VXLAN_GPE,        { 0, 2, 4 } },
-       { ICE_NVGRE,            { 0, 2 } },
+       { ICE_NVGRE,            { 0, 2, 4, 6 } },
        { ICE_PROTOCOL_LAST,    { 0 } }
 };
 
@@ -4168,21 +4493,26 @@ static const struct ice_prot_ext_tbl_entry ice_prot_ext[] = {
  */
 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 } } },
+             { 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 } } },
-       {2, { { ICE_IPV4_IL_HW, 0, 0 }, { ICE_IPV4_IL_HW, 2, 0 } } },
-       {2, { { ICE_IPV4_IL_HW, 12, 0 }, { ICE_IPV4_IL_HW, 14, 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 },
        { ICE_MAC_IL,           ICE_MAC_IL_HW },
+       { ICE_ETYPE_OL,         ICE_ETYPE_OL_HW },
        { ICE_IPV4_OFOS,        ICE_IPV4_OFOS_HW },
        { ICE_IPV4_IL,          ICE_IPV4_IL_HW },
        { ICE_IPV6_OFOS,        ICE_IPV6_OFOS_HW },
        { ICE_IPV6_IL,          ICE_IPV6_IL_HW },
        { ICE_TCP_IL,           ICE_TCP_IL_HW },
+       { ICE_UDP_OF,           ICE_UDP_OF_HW },
        { ICE_UDP_ILOS,         ICE_UDP_ILOS_HW },
        { ICE_SCTP_IL,          ICE_SCTP_IL_HW },
        { ICE_VXLAN,            ICE_UDP_OF_HW },
@@ -4201,10 +4531,10 @@ static const struct ice_protocol_entry ice_prot_id_tbl[] = {
  */
 static u16 ice_find_recp(struct ice_hw *hw, struct ice_prot_lkup_ext *lkup_exts)
 {
+       bool refresh_required = true;
        struct ice_sw_recipe *recp;
        u16 i;
 
-       ice_get_recp_to_prof_map(hw);
        /* Initialize available_result_ids which tracks available result idx */
        for (i = 0; i <= ICE_CHAIN_FV_INDEX_START; i++)
                ice_set_bit(ICE_CHAIN_FV_INDEX_START - i,
@@ -4220,7 +4550,8 @@ static u16 ice_find_recp(struct ice_hw *hw, struct ice_prot_lkup_ext *lkup_exts)
                 */
                if (!recp[i].recp_created)
                        if (ice_get_recp_frm_fw(hw,
-                                               hw->switch_info->recp_list, i))
+                                               hw->switch_info->recp_list, i,
+                                               &refresh_required))
                                continue;
 
                /* if number of words we are looking for match */
@@ -4301,8 +4632,8 @@ ice_fill_valid_words(struct ice_adv_lkup_elem *rule,
        word = lkup_exts->n_val_words;
 
        for (j = 0; j < sizeof(rule->m_u) / sizeof(u16); j++)
-               if (((u16 *)&rule->m_u)[j] == 0xffff &&
-                   rule->type < ARRAY_SIZE(ice_prot_ext)) {
+               if (((u16 *)&rule->m_u)[j] &&
+                   (unsigned long)rule->type < ARRAY_SIZE(ice_prot_ext)) {
                        /* No more space to accommodate */
                        if (word >= ICE_MAX_CHAIN_WORDS)
                                return 0;
@@ -4310,6 +4641,7 @@ ice_fill_valid_words(struct ice_adv_lkup_elem *rule,
                                ice_prot_ext[rule->type].offs[j];
                        lkup_exts->fv_words[word].prot_id =
                                ice_prot_id_tbl[rule->type].protocol_id;
+                       lkup_exts->field_mask[word] = ((u16 *)&rule->m_u)[j];
                        word++;
                }
 
@@ -4433,6 +4765,7 @@ ice_create_first_fit_recp_def(struct ice_hw *hw,
                                lkup_exts->fv_words[j].prot_id;
                        grp->pairs[grp->n_val_pairs].off =
                                lkup_exts->fv_words[j].off;
+                       grp->mask[grp->n_val_pairs] = lkup_exts->field_mask[j];
                        grp->n_val_pairs++;
                }
 
@@ -4467,14 +4800,22 @@ ice_fill_fv_word_index(struct ice_hw *hw, struct LIST_HEAD_TYPE *fv_list,
 
                for (i = 0; i < rg->r_group.n_val_pairs; i++) {
                        struct ice_fv_word *pr;
+                       u16 mask;
                        u8 j;
 
                        pr = &rg->r_group.pairs[i];
+                       mask = rg->r_group.mask[i];
+
                        for (j = 0; j < hw->blk[ICE_BLK_SW].es.fvw; j++)
                                if (fv_ext[j].prot_id == pr->prot_id &&
                                    fv_ext[j].off == pr->off) {
                                        /* Store index of field vector */
                                        rg->fv_idx[i] = j;
+                                       /* Mask is given by caller as big
+                                        * endian, but sent to FW as little
+                                        * endian
+                                        */
+                                       rg->fv_mask[i] = mask << 8 | mask >> 8;
                                        break;
                                }
                }
@@ -4572,7 +4913,8 @@ ice_add_sw_recipe(struct ice_hw *hw, struct ice_sw_recipe *rm,
 
                for (i = 0; i < entry->r_group.n_val_pairs; i++) {
                        buf[recps].content.lkup_indx[i + 1] = entry->fv_idx[i];
-                       buf[recps].content.mask[i + 1] = CPU_TO_LE16(0xFFFF);
+                       buf[recps].content.mask[i + 1] =
+                               CPU_TO_LE16(entry->fv_mask[i]);
                }
 
                if (rm->n_grp_count > 1) {
@@ -4795,6 +5137,8 @@ ice_create_recipe_group(struct ice_hw *hw, struct ice_sw_recipe *rm,
                rm->n_ext_words = lkup_exts->n_val_words;
                ice_memcpy(&rm->ext_words, lkup_exts->fv_words,
                           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;
        }
 
@@ -4996,16 +5340,8 @@ err_free_lkup_exts:
        return status;
 }
 
-#define ICE_MAC_HDR_OFFSET     0
-#define ICE_IP_HDR_OFFSET      14
-#define ICE_GRE_HDR_OFFSET     34
-#define ICE_MAC_IL_HDR_OFFSET  42
-#define ICE_IP_IL_HDR_OFFSET   56
-#define ICE_L4_HDR_OFFSET      34
-#define ICE_UDP_TUN_HDR_OFFSET 42
-
 /**
- * ice_find_dummy_packet - find dummy packet with given match criteria
+ * ice_find_dummy_packet - find dummy packet by tunnel type
  *
  * @lkups: lookup elements or match criteria for the advanced recipe, one
  *        structure per protocol header
@@ -5013,37 +5349,68 @@ err_free_lkup_exts:
  * @tun_type: tunnel type from the match criteria
  * @pkt: dummy packet to fill according to filter match criteria
  * @pkt_len: packet length of dummy packet
+ * @offsets: pointer to receive the pointer to the offsets for the packet
  */
 static void
 ice_find_dummy_packet(struct ice_adv_lkup_elem *lkups, u16 lkups_cnt,
                      enum ice_sw_tunnel_type tun_type, const u8 **pkt,
-                     u16 *pkt_len)
+                     u16 *pkt_len,
+                     const struct ice_dummy_pkt_offsets **offsets)
 {
+       bool tcp = false, udp = false, ipv6 = false;
        u16 i;
 
+       for (i = 0; i < lkups_cnt; i++) {
+               if (lkups[i].type == ICE_UDP_ILOS)
+                       udp = true;
+               else if (lkups[i].type == ICE_TCP_IL)
+                       tcp = true;
+               else if (lkups[i].type == ICE_IPV6_OFOS)
+                       ipv6 = true;
+       }
+
        if (tun_type == ICE_SW_TUN_NVGRE || tun_type == ICE_ALL_TUNNELS) {
                *pkt = dummy_gre_packet;
                *pkt_len = sizeof(dummy_gre_packet);
+               *offsets = dummy_gre_packet_offsets;
                return;
        }
 
        if (tun_type == ICE_SW_TUN_VXLAN || tun_type == ICE_SW_TUN_GENEVE ||
-           tun_type == ICE_SW_TUN_VXLAN_GPE) {
-               *pkt = dummy_udp_tun_packet;
-               *pkt_len = sizeof(dummy_udp_tun_packet);
+           tun_type == ICE_SW_TUN_VXLAN_GPE || tun_type == ICE_SW_TUN_UDP) {
+               if (tcp) {
+                       *pkt = dummy_udp_tun_tcp_packet;
+                       *pkt_len = sizeof(dummy_udp_tun_tcp_packet);
+                       *offsets = dummy_udp_tun_tcp_packet_offsets;
+                       return;
+               }
+
+               *pkt = dummy_udp_tun_udp_packet;
+               *pkt_len = sizeof(dummy_udp_tun_udp_packet);
+               *offsets = dummy_udp_tun_udp_packet_offsets;
                return;
        }
 
-       for (i = 0; i < lkups_cnt; i++) {
-               if (lkups[i].type == ICE_UDP_ILOS) {
-                       *pkt = dummy_udp_tun_packet;
-                       *pkt_len = sizeof(dummy_udp_tun_packet);
-                       return;
-               }
+       if (udp && !ipv6) {
+               *pkt = dummy_udp_packet;
+               *pkt_len = sizeof(dummy_udp_packet);
+               *offsets = dummy_udp_packet_offsets;
+               return;
+       } else if (udp && ipv6) {
+               *pkt = dummy_udp_ipv6_packet;
+               *pkt_len = sizeof(dummy_udp_ipv6_packet);
+               *offsets = dummy_udp_ipv6_packet_offsets;
+               return;
+       } else if ((tcp && ipv6) || ipv6) {
+               *pkt = dummy_tcp_ipv6_packet;
+               *pkt_len = sizeof(dummy_tcp_ipv6_packet);
+               *offsets = dummy_tcp_ipv6_packet_offsets;
+               return;
        }
 
-       *pkt = dummy_tcp_tun_packet;
-       *pkt_len = sizeof(dummy_tcp_tun_packet);
+       *pkt = dummy_tcp_packet;
+       *pkt_len = sizeof(dummy_tcp_packet);
+       *offsets = dummy_tcp_packet_offsets;
 }
 
 /**
@@ -5052,16 +5419,16 @@ ice_find_dummy_packet(struct ice_adv_lkup_elem *lkups, u16 lkups_cnt,
  * @lkups: lookup elements or match criteria for the advanced recipe, one
  *        structure per protocol header
  * @lkups_cnt: number of protocols
- * @tun_type: to know if the dummy packet is supposed to be tunnel packet
  * @s_rule: stores rule information from the match criteria
  * @dummy_pkt: dummy packet to fill according to filter match criteria
  * @pkt_len: packet length of dummy packet
+ * @offsets: offset info for the dummy packet
  */
-static void
+static enum ice_status
 ice_fill_adv_dummy_packet(struct ice_adv_lkup_elem *lkups, u16 lkups_cnt,
-                         enum ice_sw_tunnel_type tun_type,
                          struct ice_aqc_sw_rules_elem *s_rule,
-                         const u8 *dummy_pkt, u16 pkt_len)
+                         const u8 *dummy_pkt, u16 pkt_len,
+                         const struct ice_dummy_pkt_offsets *offsets)
 {
        u8 *pkt;
        u16 i;
@@ -5074,124 +5441,84 @@ ice_fill_adv_dummy_packet(struct ice_adv_lkup_elem *lkups, u16 lkups_cnt,
        ice_memcpy(pkt, dummy_pkt, pkt_len, ICE_NONDMA_TO_NONDMA);
 
        for (i = 0; i < lkups_cnt; i++) {
-               u32 len, pkt_off, hdr_size, field_off;
+               enum ice_protocol_type type;
+               u16 offset = 0, len = 0, j;
+               bool found = false;
+
+               /* find the start of this layer; it should be found since this
+                * was already checked when search for the dummy packet
+                */
+               type = lkups[i].type;
+               for (j = 0; offsets[j].type != ICE_PROTOCOL_LAST; j++) {
+                       if (type == offsets[j].type) {
+                               offset = offsets[j].offset;
+                               found = true;
+                               break;
+                       }
+               }
+               /* this should never happen in a correct calling sequence */
+               if (!found)
+                       return ICE_ERR_PARAM;
 
                switch (lkups[i].type) {
                case ICE_MAC_OFOS:
                case ICE_MAC_IL:
-                       pkt_off = offsetof(struct ice_ether_hdr, dst_addr) +
-                               ((lkups[i].type == ICE_MAC_IL) ?
-                                ICE_MAC_IL_HDR_OFFSET : 0);
-                       len = sizeof(lkups[i].h_u.eth_hdr.dst_addr);
-                       if ((tun_type == ICE_SW_TUN_VXLAN ||
-                            tun_type == ICE_SW_TUN_GENEVE ||
-                            tun_type == ICE_SW_TUN_VXLAN_GPE) &&
-                            lkups[i].type == ICE_MAC_IL) {
-                               pkt_off += sizeof(struct ice_udp_tnl_hdr);
-                       }
-
-                       ice_memcpy(&pkt[pkt_off],
-                                  &lkups[i].h_u.eth_hdr.dst_addr, len,
-                                  ICE_NONDMA_TO_NONDMA);
-                       pkt_off = offsetof(struct ice_ether_hdr, src_addr) +
-                               ((lkups[i].type == ICE_MAC_IL) ?
-                                ICE_MAC_IL_HDR_OFFSET : 0);
-                       len = sizeof(lkups[i].h_u.eth_hdr.src_addr);
-                       if ((tun_type == ICE_SW_TUN_VXLAN ||
-                            tun_type == ICE_SW_TUN_GENEVE ||
-                            tun_type == ICE_SW_TUN_VXLAN_GPE) &&
-                            lkups[i].type == ICE_MAC_IL) {
-                               pkt_off += sizeof(struct ice_udp_tnl_hdr);
-                       }
-                       ice_memcpy(&pkt[pkt_off],
-                                  &lkups[i].h_u.eth_hdr.src_addr, len,
-                                  ICE_NONDMA_TO_NONDMA);
-                       if (lkups[i].h_u.eth_hdr.ethtype_id) {
-                               pkt_off = offsetof(struct ice_ether_hdr,
-                                                  ethtype_id) +
-                                       ((lkups[i].type == ICE_MAC_IL) ?
-                                        ICE_MAC_IL_HDR_OFFSET : 0);
-                               len = sizeof(lkups[i].h_u.eth_hdr.ethtype_id);
-                               if ((tun_type == ICE_SW_TUN_VXLAN ||
-                                    tun_type == ICE_SW_TUN_GENEVE ||
-                                    tun_type == ICE_SW_TUN_VXLAN_GPE) &&
-                                    lkups[i].type == ICE_MAC_IL) {
-                                       pkt_off +=
-                                               sizeof(struct ice_udp_tnl_hdr);
-                               }
-                               ice_memcpy(&pkt[pkt_off],
-                                          &lkups[i].h_u.eth_hdr.ethtype_id,
-                                          len, ICE_NONDMA_TO_NONDMA);
-                       }
+                       len = sizeof(struct ice_ether_hdr);
                        break;
-               case ICE_IPV4_OFOS:
-                       hdr_size = sizeof(struct ice_ipv4_hdr);
-                       if (lkups[i].h_u.ipv4_hdr.dst_addr) {
-                               pkt_off = ICE_IP_HDR_OFFSET +
-                                          offsetof(struct ice_ipv4_hdr,
-                                                   dst_addr);
-                               field_off = offsetof(struct ice_ipv4_hdr,
-                                                    dst_addr);
-                               len = hdr_size - field_off;
-                               ice_memcpy(&pkt[pkt_off],
-                                          &lkups[i].h_u.ipv4_hdr.dst_addr,
-                                          len, ICE_NONDMA_TO_NONDMA);
-                       }
-                       if (lkups[i].h_u.ipv4_hdr.src_addr) {
-                               pkt_off = ICE_IP_HDR_OFFSET +
-                                          offsetof(struct ice_ipv4_hdr,
-                                                   src_addr);
-                               field_off = offsetof(struct ice_ipv4_hdr,
-                                                    src_addr);
-                               len = hdr_size - field_off;
-                               ice_memcpy(&pkt[pkt_off],
-                                          &lkups[i].h_u.ipv4_hdr.src_addr,
-                                          len, ICE_NONDMA_TO_NONDMA);
-                       }
+               case ICE_ETYPE_OL:
+                       len = sizeof(struct ice_ethtype_hdr);
                        break;
+               case ICE_IPV4_OFOS:
                case ICE_IPV4_IL:
+                       len = sizeof(struct ice_ipv4_hdr);
+                       break;
+               case ICE_IPV6_OFOS:
+               case ICE_IPV6_IL:
+                       len = sizeof(struct ice_ipv6_hdr);
                        break;
                case ICE_TCP_IL:
+               case ICE_UDP_OF:
                case ICE_UDP_ILOS:
+                       len = sizeof(struct ice_l4_hdr);
+                       break;
                case ICE_SCTP_IL:
-                       hdr_size = sizeof(struct ice_udp_tnl_hdr);
-                       if (lkups[i].h_u.l4_hdr.dst_port) {
-                               pkt_off = ICE_L4_HDR_OFFSET +
-                                          offsetof(struct ice_l4_hdr,
-                                                   dst_port);
-                               field_off = offsetof(struct ice_l4_hdr,
-                                                    dst_port);
-                               len =  hdr_size - field_off;
-                               ice_memcpy(&pkt[pkt_off],
-                                          &lkups[i].h_u.l4_hdr.dst_port,
-                                          len, ICE_NONDMA_TO_NONDMA);
-                       }
-                       if (lkups[i].h_u.l4_hdr.src_port) {
-                               pkt_off = ICE_L4_HDR_OFFSET +
-                                       offsetof(struct ice_l4_hdr, src_port);
-                               field_off = offsetof(struct ice_l4_hdr,
-                                                    src_port);
-                               len =  hdr_size - field_off;
-                               ice_memcpy(&pkt[pkt_off],
-                                          &lkups[i].h_u.l4_hdr.src_port,
-                                          len, ICE_NONDMA_TO_NONDMA);
-                       }
+                       len = sizeof(struct ice_sctp_hdr);
+                       break;
+               case ICE_NVGRE:
+                       len = sizeof(struct ice_nvgre);
                        break;
                case ICE_VXLAN:
                case ICE_GENEVE:
                case ICE_VXLAN_GPE:
-                       pkt_off = ICE_UDP_TUN_HDR_OFFSET +
-                                  offsetof(struct ice_udp_tnl_hdr, vni);
-                       field_off = offsetof(struct ice_udp_tnl_hdr, vni);
-                       len =  sizeof(struct ice_udp_tnl_hdr) - field_off;
-                       ice_memcpy(&pkt[pkt_off], &lkups[i].h_u.tnl_hdr.vni,
-                                  len, ICE_NONDMA_TO_NONDMA);
+                       len = sizeof(struct ice_udp_tnl_hdr);
                        break;
                default:
-                       break;
+                       return ICE_ERR_PARAM;
                }
+
+               /* the length should be a word multiple */
+               if (len % ICE_BYTES_PER_WORD)
+                       return ICE_ERR_CFG;
+
+               /* We have the offset to the header start, the length, the
+                * caller's header values and mask. Use this information to
+                * copy the data into the dummy packet appropriately based on
+                * the mask. Note that we need to only write the bits as
+                * indicated by the mask to make sure we don't improperly write
+                * over any significant packet data.
+                */
+               for (j = 0; j < len / sizeof(u16); j++)
+                       if (((u16 *)&lkups[i].m_u)[j])
+                               ((u16 *)(pkt + offset))[j] =
+                                       (((u16 *)(pkt + offset))[j] &
+                                        ~((u16 *)&lkups[i].m_u)[j]) |
+                                       (((u16 *)&lkups[i].h_u)[j] &
+                                        ((u16 *)&lkups[i].m_u)[j]);
        }
+
        s_rule->pdata.lkup_tx_rx.hdr_len = CPU_TO_LE16(pkt_len);
+
+       return ICE_SUCCESS;
 }
 
 /**
@@ -5345,7 +5672,7 @@ ice_adv_add_update_vsi_list(struct ice_hw *hw,
 }
 
 /**
- * ice_add_adv_rule - create an advanced switch rule
+ * ice_add_adv_rule - helper function to create an advanced switch rule
  * @hw: pointer to the hardware structure
  * @lkups: information on the words that needs to be looked up. All words
  * together makes one recipe
@@ -5369,12 +5696,15 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
 {
        struct ice_adv_fltr_mgmt_list_entry *m_entry, *adv_fltr = NULL;
        u16 rid = 0, i, pkt_len, rule_buf_sz, vsi_handle;
-       struct ice_aqc_sw_rules_elem *s_rule;
+       const struct ice_dummy_pkt_offsets *pkt_offsets;
+       struct ice_aqc_sw_rules_elem *s_rule = NULL;
        struct LIST_HEAD_TYPE *rule_head;
        struct ice_switch_info *sw;
        enum ice_status status;
        const u8 *pkt = NULL;
+       bool found = false;
        u32 act = 0;
+       u8 q_rgn;
 
        if (!lkups_cnt)
                return ICE_ERR_PARAM;
@@ -5382,17 +5712,30 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
        for (i = 0; i < lkups_cnt; i++) {
                u16 j, *ptr;
 
-               /* Validate match masks to make sure they match complete 16-bit
-                * words.
+               /* Validate match masks to make sure that there is something
+                * to match.
                 */
-               ptr = (u16 *)&lkups->m_u;
+               ptr = (u16 *)&lkups[i].m_u;
                for (j = 0; j < sizeof(lkups->m_u) / sizeof(u16); j++)
-                       if (ptr[j] != 0 && ptr[j] != 0xffff)
-                               return ICE_ERR_PARAM;
+                       if (ptr[j] != 0) {
+                               found = true;
+                               break;
+                       }
+       }
+       if (!found)
+               return ICE_ERR_PARAM;
+
+       /* make sure that we can locate a dummy packet */
+       ice_find_dummy_packet(lkups, lkups_cnt, rinfo->tun_type, &pkt, &pkt_len,
+                             &pkt_offsets);
+       if (!pkt) {
+               status = ICE_ERR_PARAM;
+               goto err_ice_add_adv_rule;
        }
 
        if (!(rinfo->sw_act.fltr_act == ICE_FWD_TO_VSI ||
              rinfo->sw_act.fltr_act == ICE_FWD_TO_Q ||
+             rinfo->sw_act.fltr_act == ICE_FWD_TO_QGRP ||
              rinfo->sw_act.fltr_act == ICE_DROP_PACKET))
                return ICE_ERR_CFG;
 
@@ -5429,8 +5772,6 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
                }
                return status;
        }
-       ice_find_dummy_packet(lkups, lkups_cnt, rinfo->tun_type, &pkt,
-                             &pkt_len);
        rule_buf_sz = ICE_SW_RULE_RX_TX_NO_HDR_SIZE + pkt_len;
        s_rule = (struct ice_aqc_sw_rules_elem *)ice_malloc(hw, rule_buf_sz);
        if (!s_rule)
@@ -5447,6 +5788,15 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
                act |= (rinfo->sw_act.fwd_id.q_id << ICE_SINGLE_ACT_Q_INDEX_S) &
                       ICE_SINGLE_ACT_Q_INDEX_M;
                break;
+       case ICE_FWD_TO_QGRP:
+               q_rgn = rinfo->sw_act.qgrp_size > 0 ?
+                       (u8)ice_ilog2(rinfo->sw_act.qgrp_size) : 0;
+               act |= ICE_SINGLE_ACT_TO_Q;
+               act |= (rinfo->sw_act.fwd_id.q_id << ICE_SINGLE_ACT_Q_INDEX_S) &
+                      ICE_SINGLE_ACT_Q_INDEX_M;
+               act |= (q_rgn << ICE_SINGLE_ACT_Q_REGION_S) &
+                      ICE_SINGLE_ACT_Q_REGION_M;
+               break;
        case ICE_DROP_PACKET:
                act |= ICE_SINGLE_ACT_VSI_FORWARDING | ICE_SINGLE_ACT_DROP |
                       ICE_SINGLE_ACT_VALID_BIT;
@@ -5475,8 +5825,8 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
        s_rule->pdata.lkup_tx_rx.recipe_id = CPU_TO_LE16(rid);
        s_rule->pdata.lkup_tx_rx.act = CPU_TO_LE32(act);
 
-       ice_fill_adv_dummy_packet(lkups, lkups_cnt, rinfo->tun_type, s_rule,
-                                 pkt, pkt_len);
+       ice_fill_adv_dummy_packet(lkups, lkups_cnt, s_rule, pkt, pkt_len,
+                                 pkt_offsets);
 
        status = ice_aq_sw_rules(hw, (struct ice_aqc_sw_rules *)s_rule,
                                 rule_buf_sz, 1, ice_aqc_opc_add_sw_rules,
@@ -5541,6 +5891,279 @@ err_ice_add_adv_rule:
 
        return status;
 }
+
+/**
+ * ice_adv_rem_update_vsi_list
+ * @hw: pointer to the hardware structure
+ * @vsi_handle: VSI handle of the VSI to remove
+ * @fm_list: filter management entry for which the VSI list management needs to
+ *          be done
+ */
+static enum ice_status
+ice_adv_rem_update_vsi_list(struct ice_hw *hw, u16 vsi_handle,
+                           struct ice_adv_fltr_mgmt_list_entry *fm_list)
+{
+       struct ice_vsi_list_map_info *vsi_list_info;
+       enum ice_sw_lkup_type lkup_type;
+       enum ice_status status;
+       u16 vsi_list_id;
+
+       if (fm_list->rule_info.sw_act.fltr_act != ICE_FWD_TO_VSI_LIST ||
+           fm_list->vsi_count == 0)
+               return ICE_ERR_PARAM;
+
+       /* A rule with the VSI being removed does not exist */
+       if (!ice_is_bit_set(fm_list->vsi_list_info->vsi_map, vsi_handle))
+               return ICE_ERR_DOES_NOT_EXIST;
+
+       lkup_type = ICE_SW_LKUP_LAST;
+       vsi_list_id = fm_list->rule_info.sw_act.fwd_id.vsi_list_id;
+       status = ice_update_vsi_list_rule(hw, &vsi_handle, 1, vsi_list_id, true,
+                                         ice_aqc_opc_update_sw_rules,
+                                         lkup_type);
+       if (status)
+               return status;
+
+       fm_list->vsi_count--;
+       ice_clear_bit(vsi_handle, fm_list->vsi_list_info->vsi_map);
+       vsi_list_info = fm_list->vsi_list_info;
+       if (fm_list->vsi_count == 1) {
+               struct ice_fltr_info tmp_fltr;
+               u16 rem_vsi_handle;
+
+               rem_vsi_handle = ice_find_first_bit(vsi_list_info->vsi_map,
+                                                   ICE_MAX_VSI);
+               if (!ice_is_vsi_valid(hw, rem_vsi_handle))
+                       return ICE_ERR_OUT_OF_RANGE;
+
+               /* Make sure VSI list is empty before removing it below */
+               status = ice_update_vsi_list_rule(hw, &rem_vsi_handle, 1,
+                                                 vsi_list_id, true,
+                                                 ice_aqc_opc_update_sw_rules,
+                                                 lkup_type);
+               if (status)
+                       return status;
+               tmp_fltr.fltr_rule_id = fm_list->rule_info.fltr_rule_id;
+               fm_list->rule_info.sw_act.fltr_act = ICE_FWD_TO_VSI;
+               tmp_fltr.fltr_act = ICE_FWD_TO_VSI;
+               tmp_fltr.fwd_id.hw_vsi_id =
+                       ice_get_hw_vsi_num(hw, rem_vsi_handle);
+               fm_list->rule_info.sw_act.fwd_id.hw_vsi_id =
+                       ice_get_hw_vsi_num(hw, rem_vsi_handle);
+
+               /* Update the previous switch rule of "MAC forward to VSI" to
+                * "MAC fwd to VSI list"
+                */
+               status = ice_update_pkt_fwd_rule(hw, &tmp_fltr);
+               if (status) {
+                       ice_debug(hw, ICE_DBG_SW,
+                                 "Failed to update pkt fwd rule to FWD_TO_VSI on HW VSI %d, error %d\n",
+                                 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) {
+                       ice_debug(hw, ICE_DBG_SW,
+                                 "Failed to remove VSI list %d, error %d\n",
+                                 vsi_list_id, status);
+                       return status;
+               }
+
+               LIST_DEL(&vsi_list_info->list_entry);
+               ice_free(hw, vsi_list_info);
+               fm_list->vsi_list_info = NULL;
+       }
+
+       return status;
+}
+
+/**
+ * ice_rem_adv_rule - removes existing advanced switch rule
+ * @hw: pointer to the hardware structure
+ * @lkups: information on the words that needs to be looked up. All words
+ *         together makes one recipe
+ * @lkups_cnt: num of entries in the lkups array
+ * @rinfo: Its the pointer to the rule information for the rule
+ *
+ * This function can be used to remove 1 rule at a time. The lkups is
+ * used to describe all the words that forms the "lookup" portion of the
+ * rule. These words can span multiple protocols. Callers to this function
+ * need to pass in a list of protocol headers with lookup information along
+ * and mask that determines which words are valid from the given protocol
+ * header. rinfo describes other information related to this rule such as
+ * forwarding IDs, priority of this rule, etc.
+ */
+enum ice_status
+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;
+
+       ice_memset(&lkup_exts, 0, sizeof(lkup_exts), ICE_NONDMA_MEM);
+       for (i = 0; i < lkups_cnt; i++) {
+               u16 count;
+
+               if (lkups[i].type >= ICE_PROTOCOL_LAST)
+                       return ICE_ERR_CFG;
+
+               count = ice_fill_valid_words(&lkups[i], &lkup_exts);
+               if (!count)
+                       return ICE_ERR_CFG;
+       }
+       rid = ice_find_recp(hw, &lkup_exts);
+       /* If did not find a recipe that match the existing criteria */
+       if (rid == ICE_MAX_NUM_RECIPES)
+               return ICE_ERR_PARAM;
+
+       rule_lock = &hw->switch_info->recp_list[rid].filt_rule_lock;
+       list_elem = ice_find_adv_rule_entry(hw, lkups, lkups_cnt, rid, rinfo);
+       /* the rule is already removed */
+       if (!list_elem)
+               return ICE_SUCCESS;
+       ice_acquire_lock(rule_lock);
+       if (list_elem->rule_info.sw_act.fltr_act != ICE_FWD_TO_VSI_LIST) {
+               remove_rule = true;
+       } else if (list_elem->vsi_count > 1) {
+               list_elem->vsi_list_info->ref_cnt--;
+               remove_rule = false;
+               vsi_handle = rinfo->sw_act.vsi_handle;
+               status = ice_adv_rem_update_vsi_list(hw, vsi_handle, list_elem);
+       } else {
+               vsi_handle = rinfo->sw_act.vsi_handle;
+               status = ice_adv_rem_update_vsi_list(hw, vsi_handle, list_elem);
+               if (status) {
+                       ice_release_lock(rule_lock);
+                       return status;
+               }
+               if (list_elem->vsi_count == 0)
+                       remove_rule = true;
+       }
+       ice_release_lock(rule_lock);
+       if (remove_rule) {
+               struct ice_aqc_sw_rules_elem *s_rule;
+
+               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;
+               s_rule =
+                       (struct ice_aqc_sw_rules_elem *)ice_malloc(hw,
+                                                                  rule_buf_sz);
+               if (!s_rule)
+                       return ICE_ERR_NO_MEMORY;
+               s_rule->pdata.lkup_tx_rx.act = 0;
+               s_rule->pdata.lkup_tx_rx.index =
+                       CPU_TO_LE16(list_elem->rule_info.fltr_rule_id);
+               s_rule->pdata.lkup_tx_rx.hdr_len = 0;
+               status = ice_aq_sw_rules(hw, (struct ice_aqc_sw_rules *)s_rule,
+                                        rule_buf_sz, 1,
+                                        ice_aqc_opc_remove_sw_rules, NULL);
+               if (status == ICE_SUCCESS) {
+                       ice_acquire_lock(rule_lock);
+                       LIST_DEL(&list_elem->list_entry);
+                       ice_free(hw, list_elem->lkups);
+                       ice_free(hw, list_elem);
+                       ice_release_lock(rule_lock);
+               }
+               ice_free(hw, s_rule);
+       }
+       return status;
+}
+
+/**
+ * ice_rem_adv_rule_by_id - removes existing advanced switch rule by ID
+ * @hw: pointer to the hardware structure
+ * @remove_entry: data struct which holds rule_id, VSI handle and recipe ID
+ *
+ * This function is used to remove 1 rule at a time. The removal is based on
+ * the remove_entry parameter. This function will remove rule for a given
+ * vsi_handle with a given rule_id which is passed as parameter in remove_entry
+ */
+enum ice_status
+ice_rem_adv_rule_by_id(struct ice_hw *hw,
+                      struct ice_rule_query_data *remove_entry)
+{
+       struct ice_adv_fltr_mgmt_list_entry *list_itr;
+       struct LIST_HEAD_TYPE *list_head;
+       struct ice_adv_rule_info rinfo;
+       struct ice_switch_info *sw;
+
+       sw = hw->switch_info;
+       if (!sw->recp_list[remove_entry->rid].recp_created)
+               return ICE_ERR_PARAM;
+       list_head = &sw->recp_list[remove_entry->rid].filt_rules;
+       LIST_FOR_EACH_ENTRY(list_itr, list_head, ice_adv_fltr_mgmt_list_entry,
+                           list_entry) {
+               if (list_itr->rule_info.fltr_rule_id ==
+                   remove_entry->rule_id) {
+                       rinfo = list_itr->rule_info;
+                       rinfo.sw_act.vsi_handle = remove_entry->vsi_handle;
+                       return ice_rem_adv_rule(hw, list_itr->lkups,
+                                               list_itr->lkups_cnt, &rinfo);
+               }
+       }
+       return ICE_ERR_PARAM;
+}
+
+/**
+ * ice_rem_adv_for_vsi - removes existing advanced switch rules for a
+ *                       given VSI handle
+ * @hw: pointer to the hardware structure
+ * @vsi_handle: VSI handle for which we are supposed to remove all the rules.
+ *
+ * This function is used to remove all the rules for a given VSI and as soon
+ * as removing a rule fails, it will return immediately with the error code,
+ * else it will return ICE_SUCCESS
+ */
+enum ice_status
+ice_rem_adv_rule_for_vsi(struct ice_hw *hw, u16 vsi_handle)
+{
+       struct ice_adv_fltr_mgmt_list_entry *list_itr;
+       struct ice_vsi_list_map_info *map_info;
+       struct LIST_HEAD_TYPE *list_head;
+       struct ice_adv_rule_info rinfo;
+       struct ice_switch_info *sw;
+       enum ice_status status;
+       u16 vsi_list_id = 0;
+       u8 rid;
+
+       sw = hw->switch_info;
+       for (rid = 0; rid < ICE_MAX_NUM_RECIPES; rid++) {
+               if (!sw->recp_list[rid].recp_created)
+                       continue;
+               if (!sw->recp_list[rid].adv_rule)
+                       continue;
+               list_head = &sw->recp_list[rid].filt_rules;
+               map_info = NULL;
+               LIST_FOR_EACH_ENTRY(list_itr, list_head,
+                                   ice_adv_fltr_mgmt_list_entry, list_entry) {
+                       map_info = ice_find_vsi_list_entry(hw, rid, vsi_handle,
+                                                          &vsi_list_id);
+                       if (!map_info)
+                               continue;
+                       rinfo = list_itr->rule_info;
+                       rinfo.sw_act.vsi_handle = vsi_handle;
+                       status = ice_rem_adv_rule(hw, list_itr->lkups,
+                                                 list_itr->lkups_cnt, &rinfo);
+                       if (status)
+                               return status;
+                       map_info = NULL;
+               }
+       }
+       return ICE_SUCCESS;
+}
+
 /**
  * ice_replay_fltr - Replay all the filters stored by a specific list head
  * @hw: pointer to the hardware structure
@@ -5689,6 +6312,38 @@ end:
        return status;
 }
 
+/**
+ * ice_replay_vsi_adv_rule - Replay advanced rule for requested VSI
+ * @hw: pointer to the hardware structure
+ * @vsi_handle: driver VSI handle
+ * @list_head: list for which filters need to be replayed
+ *
+ * Replay the advanced rule for the given VSI.
+ */
+static enum ice_status
+ice_replay_vsi_adv_rule(struct ice_hw *hw, u16 vsi_handle,
+                       struct LIST_HEAD_TYPE *list_head)
+{
+       struct ice_rule_query_data added_entry = { 0 };
+       struct ice_adv_fltr_mgmt_list_entry *adv_fltr;
+       enum ice_status status = ICE_SUCCESS;
+
+       if (LIST_EMPTY(list_head))
+               return status;
+       LIST_FOR_EACH_ENTRY(adv_fltr, list_head, ice_adv_fltr_mgmt_list_entry,
+                           list_entry) {
+               struct ice_adv_rule_info *rinfo = &adv_fltr->rule_info;
+               u16 lk_cnt = adv_fltr->lkups_cnt;
+
+               if (vsi_handle != rinfo->sw_act.vsi_handle)
+                       continue;
+               status = ice_add_adv_rule(hw, adv_fltr->lkups, lk_cnt, rinfo,
+                                         &added_entry);
+               if (status)
+                       break;
+       }
+       return status;
+}
 
 /**
  * ice_replay_vsi_all_fltr - replay all filters stored in bookkeeping lists
@@ -5700,23 +6355,23 @@ end:
 enum ice_status ice_replay_vsi_all_fltr(struct ice_hw *hw, u16 vsi_handle)
 {
        struct ice_switch_info *sw = hw->switch_info;
-       enum ice_status status = ICE_SUCCESS;
+       enum ice_status status;
        u8 i;
 
+       /* Update the recipes that were created */
        for (i = 0; i < ICE_MAX_NUM_RECIPES; i++) {
-               /* Update the default recipe lines and ones that were created */
-               if (i < ICE_MAX_NUM_RECIPES || sw->recp_list[i].recp_created) {
-                       struct LIST_HEAD_TYPE *head;
+               struct LIST_HEAD_TYPE *head;
 
-                       head = &sw->recp_list[i].filt_replay_rules;
-                       if (!sw->recp_list[i].adv_rule)
-                               status = ice_replay_vsi_fltr(hw, vsi_handle, i,
-                                                            head);
-                       if (status != ICE_SUCCESS)
-                               return status;
-               }
+               head = &sw->recp_list[i].filt_replay_rules;
+               if (!sw->recp_list[i].adv_rule)
+                       status = ice_replay_vsi_fltr(hw, vsi_handle, i, head);
+               else
+                       status = ice_replay_vsi_adv_rule(hw, vsi_handle, head);
+               if (status != ICE_SUCCESS)
+                       return status;
        }
-       return status;
+
+       return ICE_SUCCESS;
 }
 
 /**
@@ -5740,6 +6395,8 @@ void ice_rm_all_sw_replay_rule_info(struct ice_hw *hw)
                        l_head = &sw->recp_list[i].filt_replay_rules;
                        if (!sw->recp_list[i].adv_rule)
                                ice_rem_sw_rule_info(hw, l_head);
+                       else
+                               ice_rem_adv_rule_info(hw, l_head);
                }
        }
 }