net/ice/base: add profile validation on switch filter
[dpdk.git] / drivers / net / ice / base / ice_flex_pipe.c
index 703c3e0..f6a29f8 100644 (file)
@@ -218,7 +218,7 @@ ice_pkg_advance_sect(struct ice_seg *ice_seg, struct ice_pkg_enum *state)
  * When the function returns a NULL pointer, then the end of the matching
  * sections has been reached.
  */
-static void *
+void *
 ice_pkg_enum_section(struct ice_seg *ice_seg, struct ice_pkg_enum *state,
                     u32 sect_type)
 {
@@ -1785,8 +1785,12 @@ static enum ice_prof_type
 ice_get_sw_prof_type(struct ice_hw *hw, struct ice_fv *fv)
 {
        u16 i;
+       bool valid_prof = false;
 
        for (i = 0; i < hw->blk[ICE_BLK_SW].es.fvw; i++) {
+               if (fv->ew[i].off != ICE_NAN_OFFSET)
+                       valid_prof = true;
+
                /* UDP tunnel will have UDP_OF protocol ID and VNI offset */
                if (fv->ew[i].prot_id == (u8)ICE_PROT_UDP_OF &&
                    fv->ew[i].off == ICE_VNI_OFFSET)
@@ -1801,7 +1805,7 @@ ice_get_sw_prof_type(struct ice_hw *hw, struct ice_fv *fv)
                        return ICE_PROF_TUN_PPPOE;
        }
 
-       return ICE_PROF_NON_TUN;
+       return valid_prof ? ICE_PROF_NON_TUN : ICE_PROF_INVALID;
 }
 
 /**
@@ -1818,11 +1822,6 @@ ice_get_sw_fv_bitmap(struct ice_hw *hw, enum ice_prof_type req_profs,
        struct ice_seg *ice_seg;
        struct ice_fv *fv;
 
-       if (req_profs == ICE_PROF_ALL) {
-               ice_bitmap_set(bm, 0, ICE_MAX_NUM_PROFILES);
-               return;
-       }
-
        ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
        ice_zero_bitmap(bm, ICE_MAX_NUM_PROFILES);
        ice_seg = hw->seg;
@@ -4952,6 +4951,43 @@ ice_add_prof_attrib(struct ice_prof_map *prof, u8 ptg, u16 ptype,
        return ICE_SUCCESS;
 }
 
+/**
+ * ice_disable_fd_swap - set register appropriately to disable FD swap
+ * @hw: pointer to the HW struct
+ * @prof_id: profile ID
+ */
+void ice_disable_fd_swap(struct ice_hw *hw, u16 prof_id)
+{
+       u8 swap_val = ICE_SWAP_VALID;
+       u8 i;
+       /* Since the SWAP Flag in the Programming Desc doesn't work,
+        * here add method to disable the SWAP Option via setting
+        * certain SWAP and INSET register set.
+        */
+       for (i = 0; i < hw->blk[ICE_BLK_FD].es.fvw / 4; i++) {
+               u32 raw_swap = 0;
+               u32 raw_in = 0;
+               u8 j;
+
+               for (j = 0; j < 4; j++) {
+                       raw_swap |= (swap_val++) << (j * BITS_PER_BYTE);
+                       raw_in |= ICE_INSET_DFLT << (j * BITS_PER_BYTE);
+               }
+
+               /* write the FDIR swap register set */
+               wr32(hw, GLQF_FDSWAP(prof_id, i), raw_swap);
+
+               ice_debug(hw, ICE_DBG_INIT, "swap wr(%d, %d): %x = %08x\n",
+                               prof_id, i, GLQF_FDSWAP(prof_id, i), raw_swap);
+
+               /* write the FDIR inset register set */
+               wr32(hw, GLQF_FDINSET(prof_id, i), raw_in);
+
+               ice_debug(hw, ICE_DBG_INIT, "inset wr(%d, %d): %x = %08x\n",
+                               prof_id, i, GLQF_FDINSET(prof_id, i), raw_in);
+       }
+}
+
 /**
  * ice_add_prof - add profile
  * @hw: pointer to the HW struct
@@ -4962,6 +4998,7 @@ ice_add_prof_attrib(struct ice_prof_map *prof, u8 ptg, u16 ptype,
  * @attr_cnt: number of elements in attrib array
  * @es: extraction sequence (length of array is determined by the block)
  * @masks: mask for extraction sequence
+ * @fd_swap: enable/disable FDIR paired src/dst fields swap option
  *
  * This function registers a profile, which matches a set of PTYPES with a
  * particular extraction sequence. While the hardware profile is allocated
@@ -4971,7 +5008,7 @@ ice_add_prof_attrib(struct ice_prof_map *prof, u8 ptg, u16 ptype,
 enum ice_status
 ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[],
             const struct ice_ptype_attributes *attr, u16 attr_cnt,
-            struct ice_fv_word *es, u16 *masks)
+            struct ice_fv_word *es, u16 *masks, bool fd_swap)
 {
        u32 bytes = DIVIDE_AND_ROUND_UP(ICE_FLOW_PTYPE_MAX, BITS_PER_BYTE);
        ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT);
@@ -4991,7 +5028,7 @@ ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[],
                status = ice_alloc_prof_id(hw, blk, &prof_id);
                if (status)
                        goto err_ice_add_prof;
-               if (blk == ICE_BLK_FD) {
+               if (blk == ICE_BLK_FD && fd_swap) {
                        /* 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
@@ -5002,6 +5039,8 @@ ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[],
                        status = ice_update_fd_swap(hw, prof_id, es);
                        if (status)
                                goto err_ice_add_prof;
+               } else if (blk == ICE_BLK_FD) {
+                       ice_disable_fd_swap(hw, prof_id);
                }
                status = ice_update_prof_masking(hw, blk, prof_id, masks);
                if (status)
@@ -6325,3 +6364,52 @@ err_ice_rem_prof_id_flow:
 
        return status;
 }
+
+/**
+ * ice_flow_assoc_hw_prof - add profile id flow for main/ctrl VSI flow entry
+ * @hw: pointer to the HW struct
+ * @blk: HW block
+ * @dest_vsi_handle: dest VSI handle
+ * @fdir_vsi_handle: fdir programming VSI handle
+ * @id: profile id (handle)
+ *
+ * Calling this function will update the hardware tables to enable the
+ * profile indicated by the ID parameter for the VSIs specified in the VSI
+ * array. Once successfully called, the flow will be enabled.
+ */
+enum ice_status
+ice_flow_assoc_hw_prof(struct ice_hw *hw, enum ice_block blk,
+                      u16 dest_vsi_handle, u16 fdir_vsi_handle, int id)
+{
+       enum ice_status status = ICE_SUCCESS;
+       u16 vsi_num;
+
+       vsi_num = ice_get_hw_vsi_num(hw, dest_vsi_handle);
+       status = ice_add_prof_id_flow(hw, blk, vsi_num, id);
+       if (status) {
+               ice_debug(hw, ICE_DBG_FLOW, "HW profile add failed for main VSI flow entry, %d\n",
+                         status);
+               goto err_add_prof;
+       }
+
+       if (blk != ICE_BLK_FD)
+               return status;
+
+       vsi_num = ice_get_hw_vsi_num(hw, fdir_vsi_handle);
+       status = ice_add_prof_id_flow(hw, blk, vsi_num, id);
+       if (status) {
+               ice_debug(hw, ICE_DBG_FLOW, "HW profile add failed for ctrl VSI flow entry, %d\n",
+                         status);
+               goto err_add_entry;
+       }
+
+       return status;
+
+err_add_entry:
+       vsi_num = ice_get_hw_vsi_num(hw, dest_vsi_handle);
+       ice_rem_prof_id_flow(hw, blk, vsi_num, id);
+err_add_prof:
+       ice_flow_rem_prof(hw, blk, id);
+
+       return status;
+}