net/ice/base: clean up
[dpdk.git] / drivers / net / ice / base / ice_flex_pipe.c
index 8f8cab8..1598efd 100644 (file)
@@ -470,6 +470,7 @@ static void ice_init_pkg_hints(struct ice_hw *hw, struct ice_seg *ice_seg)
        int i;
 
        ice_memset(&hw->tnl, 0, sizeof(hw->tnl), ICE_NONDMA_MEM);
+       ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
 
        if (!ice_seg)
                return;
@@ -1517,6 +1518,8 @@ ice_get_sw_fv_bitmap(struct ice_hw *hw, enum ice_prof_type type,
        struct ice_seg *ice_seg;
        struct ice_fv *fv;
 
+       ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
+
        if (type == ICE_PROF_ALL) {
                u16 i;
 
@@ -1573,6 +1576,8 @@ ice_get_sw_fv_list(struct ice_hw *hw, u16 *prot_ids, u8 ids_cnt,
        struct ice_fv *fv;
        u32 offset;
 
+       ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
+
        if (!ids_cnt || !hw->seg)
                return ICE_ERR_PARAM;
 
@@ -1633,16 +1638,17 @@ err:
 }
 
 /**
- * ice_init_profile_to_result_bm - Initialize the profile result index bitmap
+ * ice_init_prof_result_bm - Initialize the profile result index bitmap
  * @hw: pointer to hardware structure
  */
-void
-ice_init_prof_result_bm(struct ice_hw *hw)
+void ice_init_prof_result_bm(struct ice_hw *hw)
 {
        struct ice_pkg_enum state;
        struct ice_seg *ice_seg;
        struct ice_fv *fv;
 
+       ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
+
        if (!hw->seg)
                return;
 
@@ -2125,8 +2131,7 @@ ice_ptg_find_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 *ptg)
  * This function allocates a given packet type group ID specified by the ptg
  * parameter.
  */
-static
-void ice_ptg_alloc_val(struct ice_hw *hw, enum ice_block blk, u8 ptg)
+static void ice_ptg_alloc_val(struct ice_hw *hw, enum ice_block blk, u8 ptg)
 {
        hw->blk[blk].xlt1.ptg_tbl[ptg].in_use = true;
 }
@@ -2686,34 +2691,7 @@ ice_find_prof_id_with_mask(struct ice_hw *hw, enum ice_block blk,
                        continue;
 
                /* check if masks settings are the same for this profile */
-               if (!ice_prof_has_mask(hw, blk, i, masks))
-                       continue;
-
-               *prof_id = i;
-               return ICE_SUCCESS;
-       }
-
-       return ICE_ERR_DOES_NOT_EXIST;
-}
-
-/**
- * ice_find_prof_id - find profile ID for a given field vector
- * @hw: pointer to the hardware structure
- * @blk: HW block
- * @fv: field vector to search for
- * @prof_id: receives the profile ID
- */
-static enum ice_status
-ice_find_prof_id(struct ice_hw *hw, enum ice_block blk,
-                struct ice_fv_word *fv, u8 *prof_id)
-{
-       struct ice_es *es = &hw->blk[blk].es;
-       u16 off, i;
-
-       for (i = 0; i < es->count; i++) {
-               off = i * es->fvw;
-
-               if (memcmp(&es->t[off], fv, es->fvw * sizeof(*fv)))
+               if (masks && !ice_prof_has_mask(hw, blk, i, masks))
                        continue;
 
                *prof_id = i;
@@ -3091,7 +3069,8 @@ ice_free_prof_mask(struct ice_hw *hw, enum ice_block blk, u16 mask_idx)
        hw->blk[blk].masks.masks[mask_idx].idx = 0;
 
        /* update mask as unused entry */
-       ice_debug(hw, ICE_DBG_PKG, "Free mask, blk %d, mask %d", blk, mask_idx);
+       ice_debug(hw, ICE_DBG_PKG, "Free mask, blk %d, mask %d\n", blk,
+                 mask_idx);
        ice_write_prof_mask_reg(hw, blk, mask_idx, 0, 0);
 
 exit_ice_free_prof_mask:
@@ -3307,8 +3286,7 @@ static const u32 ice_blk_sids[ICE_BLK_COUNT][ICE_SID_OFF_COUNT] = {
  * @hw: pointer to the hardware structure
  * @blk: the HW block to initialize
  */
-static
-void ice_init_sw_xlt1_db(struct ice_hw *hw, enum ice_block blk)
+static void ice_init_sw_xlt1_db(struct ice_hw *hw, enum ice_block blk)
 {
        u16 pt;
 
@@ -3640,6 +3618,61 @@ static void ice_init_flow_profs(struct ice_hw *hw, u8 blk_idx)
        INIT_LIST_HEAD(&hw->fl_profs[blk_idx]);
 }
 
+/**
+ * ice_clear_hw_tbls - clear HW tables and flow profiles
+ * @hw: pointer to the hardware structure
+ */
+void ice_clear_hw_tbls(struct ice_hw *hw)
+{
+       u8 i;
+
+       for (i = 0; i < ICE_BLK_COUNT; i++) {
+               struct ice_prof_redir *prof_redir = &hw->blk[i].prof_redir;
+               struct ice_prof_tcam *prof = &hw->blk[i].prof;
+               struct ice_xlt1 *xlt1 = &hw->blk[i].xlt1;
+               struct ice_xlt2 *xlt2 = &hw->blk[i].xlt2;
+               struct ice_es *es = &hw->blk[i].es;
+
+               if (hw->blk[i].is_list_init) {
+                       ice_free_prof_map(hw, i);
+                       ice_free_flow_profs(hw, i);
+               }
+
+               ice_free_vsig_tbl(hw, (enum ice_block)i);
+
+               ice_memset(xlt1->ptypes, 0, xlt1->count * sizeof(*xlt1->ptypes),
+                          ICE_NONDMA_MEM);
+               ice_memset(xlt1->ptg_tbl, 0,
+                          ICE_MAX_PTGS * sizeof(*xlt1->ptg_tbl),
+                          ICE_NONDMA_MEM);
+               ice_memset(xlt1->t, 0, xlt1->count * sizeof(*xlt1->t),
+                          ICE_NONDMA_MEM);
+
+               ice_memset(xlt2->vsis, 0, xlt2->count * sizeof(*xlt2->vsis),
+                          ICE_NONDMA_MEM);
+               ice_memset(xlt2->vsig_tbl, 0,
+                          xlt2->count * sizeof(*xlt2->vsig_tbl),
+                          ICE_NONDMA_MEM);
+               ice_memset(xlt2->t, 0, xlt2->count * sizeof(*xlt2->t),
+                          ICE_NONDMA_MEM);
+
+               ice_memset(prof->t, 0, prof->count * sizeof(*prof->t),
+                          ICE_NONDMA_MEM);
+               ice_memset(prof_redir->t, 0,
+                          prof_redir->count * sizeof(*prof_redir->t),
+                          ICE_NONDMA_MEM);
+
+               ice_memset(es->t, 0, es->count * sizeof(*es->t),
+                          ICE_NONDMA_MEM);
+               ice_memset(es->ref_count, 0, es->count * sizeof(*es->ref_count),
+                          ICE_NONDMA_MEM);
+               ice_memset(es->written, 0, es->count * sizeof(*es->written),
+                          ICE_NONDMA_MEM);
+               ice_memset(es->mask_ena, 0, es->count * sizeof(*es->mask_ena),
+                          ICE_NONDMA_MEM);
+       }
+}
+
 /**
  * ice_init_hw_tbls - init hardware table memory
  * @hw: pointer to the hardware structure
@@ -4141,7 +4174,7 @@ ice_upd_prof_hw(struct ice_hw *hw, enum ice_block blk,
        /* update package */
        status = ice_update_pkg(hw, ice_pkg_buf(b), 1);
        if (status == ICE_ERR_AQ_ERROR)
-               ice_debug(hw, ICE_DBG_INIT, "Unable to update HW profile.");
+               ice_debug(hw, ICE_DBG_INIT, "Unable to update HW profile\n");
 
 error_tmp:
        ice_pkg_buf_free(hw, b);
@@ -4358,127 +4391,58 @@ ice_update_fd_swap(struct ice_hw *hw, u16 prof_id, struct ice_fv_word *es)
        return ICE_SUCCESS;
 }
 
+/* The entries here needs to match the order of enum ice_ptype_attrib */
+static const struct ice_ptype_attrib_info ice_ptype_attributes[] = {
+       { ICE_GTP_PDU_EH,       ICE_GTP_PDU_FLAG_MASK },
+       { ICE_GTP_SESSION,      ICE_GTP_FLAGS_MASK },
+       { ICE_GTP_DOWNLINK,     ICE_GTP_FLAGS_MASK },
+       { ICE_GTP_UPLINK,       ICE_GTP_FLAGS_MASK },
+};
+
 /**
- * ice_add_prof_with_mask - add profile
- * @hw: pointer to the HW struct
- * @blk: hardware block
- * @id: profile tracking ID
- * @ptypes: array of bitmaps indicating ptypes (ICE_FLOW_PTYPE_MAX bits)
- * @es: extraction sequence (length of array is determined by the block)
- * @masks: extraction sequence (length of array is determined by the block)
- *
- * This function registers a profile, which matches a set of PTYPES with a
- * particular extraction sequence. While the hardware profile is allocated
- * it will not be written until the first call to ice_add_flow that specifies
- * the ID value used here.
+ * ice_get_ptype_attrib_info - get ptype attribute information
+ * @type: attribute type
+ * @info: pointer to variable to the attribute information
  */
-enum ice_status
-ice_add_prof_with_mask(struct ice_hw *hw, enum ice_block blk, u64 id,
-                      u8 ptypes[], struct ice_fv_word *es, u16 *masks)
+static void
+ice_get_ptype_attrib_info(enum ice_ptype_attrib_type type,
+                         struct ice_ptype_attrib_info *info)
 {
-       u32 bytes = DIVIDE_AND_ROUND_UP(ICE_FLOW_PTYPE_MAX, BITS_PER_BYTE);
-       ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT);
-       struct ice_prof_map *prof;
-       enum ice_status status;
-       u32 byte = 0;
-       u8 prof_id;
-
-       ice_zero_bitmap(ptgs_used, ICE_XLT1_CNT);
-
-       ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
-
-       /* search for existing profile */
-       status = ice_find_prof_id_with_mask(hw, blk, es, masks, &prof_id);
-       if (status) {
-               /* allocate profile ID */
-               status = ice_alloc_prof_id(hw, blk, &prof_id);
-               if (status)
-                       goto err_ice_add_prof;
-               if (blk == ICE_BLK_FD) {
-                       /* For Flow Director block, the extraction sequence may
-                        * need to be altered in the case where there are paired
-                        * fields that have no match. This is necessary because
-                        * for Flow Director, src and dest fields need to paired
-                        * for filter programming and these values are swapped
-                        * during Tx.
-                        */
-                       status = ice_update_fd_swap(hw, prof_id, es);
-                       if (status)
-                               goto err_ice_add_prof;
-               }
-               status = ice_update_prof_masking(hw, blk, prof_id, es, masks);
-               if (status)
-                       goto err_ice_add_prof;
-
-               /* and write new es */
-               ice_write_es(hw, blk, prof_id, es);
-       }
-
-       ice_prof_inc_ref(hw, blk, prof_id);
-
-       /* add profile info */
-
-       prof = (struct ice_prof_map *)ice_malloc(hw, sizeof(*prof));
-       if (!prof)
-               goto err_ice_add_prof;
-
-       prof->profile_cookie = id;
-       prof->prof_id = prof_id;
-       prof->ptg_cnt = 0;
-       prof->context = 0;
-
-       /* build list of ptgs */
-       while (bytes && prof->ptg_cnt < ICE_MAX_PTG_PER_PROFILE) {
-               u32 bit;
-
-               if (!ptypes[byte]) {
-                       bytes--;
-                       byte++;
-                       continue;
-               }
-               /* Examine 8 bits per byte */
-               for (bit = 0; bit < 8; bit++) {
-                       if (ptypes[byte] & BIT(bit)) {
-                               u16 ptype;
-                               u8 ptg;
-                               u8 m;
-
-                               ptype = byte * BITS_PER_BYTE + bit;
-
-                               /* The package should place all ptypes in a
-                                * non-zero PTG, so the following call should
-                                * never fail.
-                                */
-                               if (ice_ptg_find_ptype(hw, blk, ptype, &ptg))
-                                       continue;
+       *info = ice_ptype_attributes[type];
+}
 
-                               /* If PTG is already added, skip and continue */
-                               if (ice_is_bit_set(ptgs_used, ptg))
-                                       continue;
+/**
+ * ice_add_prof_attrib - add any ptg with attributes to profile
+ * @prof: pointer to the profile to which ptg entries will be added
+ * @ptg: PTG to be added
+ * @ptype: PTYPE that needs to be looked up
+ * @attr: array of attributes that will be considered
+ * @attr_cnt: number of elements in the attribute array
+ */
+static enum ice_status
+ice_add_prof_attrib(struct ice_prof_map *prof, u8 ptg, u16 ptype,
+                   const struct ice_ptype_attributes *attr, u16 attr_cnt)
+{
+       bool found = false;
+       u16 i;
 
-                               ice_set_bit(ptg, ptgs_used);
-                               prof->ptg[prof->ptg_cnt] = ptg;
+       for (i = 0; i < attr_cnt; i++) {
+               if (attr[i].ptype == ptype) {
+                       found = true;
 
-                               if (++prof->ptg_cnt >= ICE_MAX_PTG_PER_PROFILE)
-                                       break;
+                       prof->ptg[prof->ptg_cnt] = ptg;
+                       ice_get_ptype_attrib_info(attr[i].attrib,
+                                                 &prof->attr[prof->ptg_cnt]);
 
-                               /* nothing left in byte, then exit */
-                               m = ~((1 << (bit + 1)) - 1);
-                               if (!(ptypes[byte] & m))
-                                       break;
-                       }
+                       if (++prof->ptg_cnt >= ICE_MAX_PTG_PER_PROFILE)
+                               return ICE_ERR_MAX_LIMIT;
                }
-
-               bytes--;
-               byte++;
        }
 
-       LIST_ADD(&prof->list, &hw->blk[blk].es.prof_map);
-       status = ICE_SUCCESS;
+       if (!found)
+               return ICE_ERR_DOES_NOT_EXIST;
 
-err_ice_add_prof:
-       ice_release_lock(&hw->blk[blk].es.prof_map_lock);
-       return status;
+       return ICE_SUCCESS;
 }
 
 /**
@@ -4487,16 +4451,20 @@ err_ice_add_prof:
  * @blk: hardware block
  * @id: profile tracking ID
  * @ptypes: array of bitmaps indicating ptypes (ICE_FLOW_PTYPE_MAX bits)
+ * @attr: array of attributes
+ * @attr_cnt: number of elements in attrib array
  * @es: extraction sequence (length of array is determined by the block)
+ * @masks: mask for extraction sequence
  *
- * This function registers a profile, which matches a set of PTGs with a
+ * This function registers a profile, which matches a set of PTYPES with a
  * particular extraction sequence. While the hardware profile is allocated
  * it will not be written until the first call to ice_add_flow that specifies
  * the ID value used here.
  */
 enum ice_status
 ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[],
-            struct ice_fv_word *es)
+            const struct ice_ptype_attributes *attr, u16 attr_cnt,
+            struct ice_fv_word *es, u16 *masks)
 {
        u32 bytes = DIVIDE_AND_ROUND_UP(ICE_FLOW_PTYPE_MAX, BITS_PER_BYTE);
        ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT);
@@ -4510,7 +4478,7 @@ ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[],
        ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
 
        /* search for existing profile */
-       status = ice_find_prof_id(hw, blk, es, &prof_id);
+       status = ice_find_prof_id_with_mask(hw, blk, es, masks, &prof_id);
        if (status) {
                /* allocate profile ID */
                status = ice_alloc_prof_id(hw, blk, &prof_id);
@@ -4528,6 +4496,9 @@ ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[],
                        if (status)
                                goto err_ice_add_prof;
                }
+               status = ice_update_prof_masking(hw, blk, prof_id, es, masks);
+               if (status)
+                       goto err_ice_add_prof;
 
                /* and write new es */
                ice_write_es(hw, blk, prof_id, es);
@@ -4576,10 +4547,25 @@ ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[],
                                        continue;
 
                                ice_set_bit(ptg, ptgs_used);
-                               prof->ptg[prof->ptg_cnt] = ptg;
-
-                               if (++prof->ptg_cnt >= ICE_MAX_PTG_PER_PROFILE)
+                               /* Check to see there are any attributes for
+                                * this ptype, and add them if found.
+                                */
+                               status = ice_add_prof_attrib(prof, ptg, ptype,
+                                                            attr, attr_cnt);
+                               if (status == ICE_ERR_MAX_LIMIT)
                                        break;
+                               if (status) {
+                                       /* This is simple a ptype/ptg with no
+                                        * attribute
+                                        */
+                                       prof->ptg[prof->ptg_cnt] = ptg;
+                                       prof->attr[prof->ptg_cnt].flags = 0;
+                                       prof->attr[prof->ptg_cnt].mask = 0;
+
+                                       if (++prof->ptg_cnt >=
+                                           ICE_MAX_PTG_PER_PROFILE)
+                                               break;
+                               }
 
                                /* nothing left in byte, then exit */
                                m = ~((1 << (bit + 1)) - 1);
@@ -4922,6 +4908,7 @@ ice_get_prof(struct ice_hw *hw, enum ice_block blk, u64 hdl,
                        p->type = ICE_PTG_ES_ADD;
                        p->ptype = 0;
                        p->ptg = map->ptg[i];
+                       p->attr = map->attr[i];
                        p->add_ptg = 0;
 
                        p->add_prof = 1;
@@ -5011,6 +4998,7 @@ ice_add_prof_to_lst(struct ice_hw *hw, enum ice_block blk,
                p->tcam[i].prof_id = map->prof_id;
                p->tcam[i].tcam_idx = ICE_INVALID_TCAM;
                p->tcam[i].ptg = map->ptg[i];
+               p->tcam[i].attr = map->attr[i];
        }
 
        LIST_ADD(&p->list, lst);
@@ -5057,6 +5045,39 @@ ice_move_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig,
        return ICE_SUCCESS;
 }
 
+/**
+ * ice_set_tcam_flags - set tcam flag don't care mask
+ * @mask: mask for flags
+ * @dc_mask: pointer to the don't care mask
+ */
+static void ice_set_tcam_flags(u16 mask, u8 dc_mask[ICE_TCAM_KEY_VAL_SZ])
+{
+       u16 *flag_word;
+
+       /* flags are lowest u16 */
+       flag_word = (u16 *)dc_mask;
+       *flag_word = ~mask;
+}
+
+/**
+ * ice_rem_chg_tcam_ent - remove a specific tcam entry from change list
+ * @hw: pointer to the HW struct
+ * @idx: the index of the tcam entry to remove
+ * @chg: the list of change structures to search
+ */
+static void
+ice_rem_chg_tcam_ent(struct ice_hw *hw, u16 idx, struct LIST_HEAD_TYPE *chg)
+{
+       struct ice_chs_chg *pos, *tmp;
+
+       LIST_FOR_EACH_ENTRY_SAFE(tmp, pos, chg, ice_chs_chg, list_entry) {
+               if (tmp->type == ICE_TCAM_ADD && tmp->tcam_idx == idx) {
+                       LIST_DEL(&tmp->list_entry);
+                       ice_free(hw, tmp);
+               }
+       }
+}
+
 /**
  * ice_prof_tcam_ena_dis - add enable or disable TCAM change
  * @hw: pointer to the HW struct
@@ -5076,14 +5097,19 @@ ice_prof_tcam_ena_dis(struct ice_hw *hw, enum ice_block blk, bool enable,
        enum ice_status status;
        struct ice_chs_chg *p;
 
-       /* Default: enable means change the low flag bit to don't care */
-       u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
+       u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
+       u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0x00, 0x00, 0x00 };
        u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
-       u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
 
        /* if disabling, free the tcam */
        if (!enable) {
-               status = ice_free_tcam_ent(hw, blk, tcam->tcam_idx);
+               status = ice_rel_tcam_idx(hw, blk, tcam->tcam_idx);
+
+               /* if we have already created a change for this tcam entry, then
+                * we need to remove that entry, in order to prevent writing to
+                * a tcam entry we no longer will have ownership of.
+                */
+               ice_rem_chg_tcam_ent(hw, tcam->tcam_idx, chg);
                tcam->tcam_idx = 0;
                tcam->in_use = 0;
                return status;
@@ -5099,9 +5125,12 @@ ice_prof_tcam_ena_dis(struct ice_hw *hw, enum ice_block blk, bool enable,
        if (!p)
                return ICE_ERR_NO_MEMORY;
 
+       /* set don't care masks for tcam flags */
+       ice_set_tcam_flags(tcam->attr.mask, dc_msk);
+
        status = ice_tcam_write_entry(hw, blk, tcam->tcam_idx, tcam->prof_id,
-                                     tcam->ptg, vsig, 0, 0, vl_msk, dc_msk,
-                                     nm_msk);
+                                     tcam->ptg, vsig, 0, tcam->attr.flags,
+                                     vl_msk, dc_msk, nm_msk);
        if (status)
                goto err_ice_prof_tcam_ena_dis;
 
@@ -5199,11 +5228,12 @@ ice_adj_prof_priorities(struct ice_hw *hw, enum ice_block blk, u16 vsig,
  * @blk: hardware block
  * @vsig: the VSIG to which this profile is to be added
  * @hdl: the profile handle indicating the profile to add
+ * @rev: true to add entries to the end of the list
  * @chg: the change list
  */
 static enum ice_status
 ice_add_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
-                    struct LIST_HEAD_TYPE *chg)
+                    bool rev, struct LIST_HEAD_TYPE *chg)
 {
        /* Masks that ignore flags */
        u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
@@ -5212,7 +5242,7 @@ ice_add_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
        struct ice_prof_map *map;
        struct ice_vsig_prof *t;
        struct ice_chs_chg *p;
-       u16 i;
+       u16 vsig_idx, i;
 
        /* Get the details on the profile specified by the handle ID */
        map = ice_search_prof_id(hw, blk, hdl);
@@ -5252,6 +5282,7 @@ ice_add_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
                t->tcam[i].ptg = map->ptg[i];
                t->tcam[i].prof_id = map->prof_id;
                t->tcam[i].tcam_idx = tcam_idx;
+               t->tcam[i].attr = map->attr[i];
                t->tcam[i].in_use = true;
 
                p->type = ICE_TCAM_ADD;
@@ -5261,11 +5292,15 @@ ice_add_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
                p->vsig = vsig;
                p->tcam_idx = t->tcam[i].tcam_idx;
 
+               /* set don't care masks for tcam flags */
+               ice_set_tcam_flags(t->tcam[i].attr.mask, dc_msk);
+
                /* write the TCAM entry */
                status = ice_tcam_write_entry(hw, blk, t->tcam[i].tcam_idx,
                                              t->tcam[i].prof_id,
-                                             t->tcam[i].ptg, vsig, 0, 0,
-                                             vl_msk, dc_msk, nm_msk);
+                                             t->tcam[i].ptg, vsig, 0,
+                                             t->tcam[i].attr.flags, vl_msk,
+                                             dc_msk, nm_msk);
                if (status)
                        goto err_ice_add_prof_id_vsig;
 
@@ -5274,8 +5309,13 @@ ice_add_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
        }
 
        /* add profile to VSIG */
-       LIST_ADD(&t->list,
-                &hw->blk[blk].xlt2.vsig_tbl[(vsig & ICE_VSIG_IDX_M)].prop_lst);
+       vsig_idx = vsig & ICE_VSIG_IDX_M;
+       if (rev)
+               LIST_ADD_TAIL(&t->list,
+                             &hw->blk[blk].xlt2.vsig_tbl[vsig_idx].prop_lst);
+       else
+               LIST_ADD(&t->list,
+                        &hw->blk[blk].xlt2.vsig_tbl[vsig_idx].prop_lst);
 
        return ICE_SUCCESS;
 
@@ -5315,7 +5355,7 @@ ice_create_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl,
        if (status)
                goto err_ice_create_prof_id_vsig;
 
-       status = ice_add_prof_id_vsig(hw, blk, new_vsig, hdl, chg);
+       status = ice_add_prof_id_vsig(hw, blk, new_vsig, hdl, false, chg);
        if (status)
                goto err_ice_create_prof_id_vsig;
 
@@ -5340,11 +5380,13 @@ err_ice_create_prof_id_vsig:
  * @blk: hardware block
  * @vsi: the initial VSI that will be in VSIG
  * @lst: the list of profile that will be added to the VSIG
+ * @new_vsig: return of new vsig
  * @chg: the change list
  */
 static enum ice_status
 ice_create_vsig_from_lst(struct ice_hw *hw, enum ice_block blk, u16 vsi,
-                        struct LIST_HEAD_TYPE *lst, struct LIST_HEAD_TYPE *chg)
+                        struct LIST_HEAD_TYPE *lst, u16 *new_vsig,
+                        struct LIST_HEAD_TYPE *chg)
 {
        struct ice_vsig_prof *t;
        enum ice_status status;
@@ -5359,12 +5401,15 @@ ice_create_vsig_from_lst(struct ice_hw *hw, enum ice_block blk, u16 vsi,
                return status;
 
        LIST_FOR_EACH_ENTRY(t, lst, ice_vsig_prof, list) {
+               /* Reverse the order here since we are copying the list */
                status = ice_add_prof_id_vsig(hw, blk, vsig, t->profile_cookie,
-                                             chg);
+                                             true, chg);
                if (status)
                        return status;
        }
 
+       *new_vsig = vsig;
+
        return ICE_SUCCESS;
 }
 
@@ -5528,7 +5573,8 @@ ice_add_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
                         * not sharing entries and we can simply add the new
                         * profile to the VSIG.
                         */
-                       status = ice_add_prof_id_vsig(hw, blk, vsig, hdl, &chg);
+                       status = ice_add_prof_id_vsig(hw, blk, vsig, hdl, false,
+                                                     &chg);
                        if (status)
                                goto err_ice_add_prof_id_flow;
 
@@ -5539,7 +5585,8 @@ ice_add_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
                } else {
                        /* No match, so we need a new VSIG */
                        status = ice_create_vsig_from_lst(hw, blk, vsi,
-                                                         &union_lst, &chg);
+                                                         &union_lst, &vsig,
+                                                         &chg);
                        if (status)
                                goto err_ice_add_prof_id_flow;
 
@@ -5711,7 +5758,8 @@ ice_rem_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
                                 * new VSIG and TCAM entries
                                 */
                                status = ice_create_vsig_from_lst(hw, blk, vsi,
-                                                                 &copy, &chg);
+                                                                 &copy, &vsig,
+                                                                 &chg);
                                if (status)
                                        goto err_ice_rem_prof_id_flow;