[17/39] net/ice/base: support custom DDP buildin recipe

Message ID 20220407105706.18889-18-kevinx.liu@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Qi Zhang
Headers
Series support full function of DCF |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Kevin Liu April 7, 2022, 10:56 a.m. UTC
  From: Alvin Zhang <alvinx.zhang@intel.com>

Add control flag and data pointer for custom DDP package buildin recipe.
Init the data pointer of buildin recipe.
Support dumping buildin recipe lookup info.

Signed-off-by: Steven Zou <steven.zou@intel.com>
Signed-off-by: Alvin Zhang <alvinx.zhang@intel.com>
Signed-off-by: Kevin Liu <kevinx.liu@intel.com>
---
 drivers/net/ice/base/ice_common.c | 25 +++++++++++++++
 drivers/net/ice/base/ice_switch.c | 52 ++++++++++++++++++++++++++++++-
 drivers/net/ice/base/ice_type.h   |  2 ++
 3 files changed, 78 insertions(+), 1 deletion(-)
  

Patch

diff --git a/drivers/net/ice/base/ice_common.c b/drivers/net/ice/base/ice_common.c
index db87bacd97..5d5ce894ff 100644
--- a/drivers/net/ice/base/ice_common.c
+++ b/drivers/net/ice/base/ice_common.c
@@ -732,6 +732,28 @@  ice_aq_set_mac_cfg(struct ice_hw *hw, u16 max_frame_size, struct ice_sq_cd *cd)
 	return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
 }
 
+static int ice_buildin_recipe_init(struct ice_hw *hw)
+{
+	struct ice_switch_info *sw = hw->switch_info;
+	struct ice_sw_recipe *recipe;
+
+	sw->buildin_recipes = ice_malloc(hw,
+			sizeof(sw->buildin_recipes[0]) * ICE_MAX_NUM_RECIPES);
+
+	if (!sw->buildin_recipes)
+		return ICE_ERR_NO_MEMORY;
+
+	recipe = &sw->buildin_recipes[10];
+	recipe->is_root = 1;
+
+	recipe->lkup_exts.n_val_words = 1;
+	recipe->lkup_exts.field_mask[0] = 0x00ff;
+	recipe->lkup_exts.fv_words[0].off = 8;
+	recipe->lkup_exts.fv_words[0].prot_id = 32;
+
+	return ICE_SUCCESS;
+}
+
 /**
  * ice_init_fltr_mgmt_struct - initializes filter management list and locks
  * @hw: pointer to the HW struct
@@ -752,6 +774,8 @@  enum ice_status ice_init_fltr_mgmt_struct(struct ice_hw *hw)
 	INIT_LIST_HEAD(&sw->vsi_list_map_head);
 	sw->prof_res_bm_init = 0;
 
+	ice_buildin_recipe_init(hw);
+
 	status = ice_init_def_sw_recp(hw, &hw->switch_info->recp_list);
 	if (status) {
 		ice_free(hw, hw->switch_info);
@@ -822,6 +846,7 @@  ice_cleanup_fltr_mgmt_single(struct ice_hw *hw, struct ice_switch_info *sw)
 			ice_free(hw, recps[i].root_buf);
 	}
 	ice_rm_sw_replay_rule_info(hw, sw);
+	ice_free(hw, sw->buildin_recipes);
 	ice_free(hw, sw->recp_list);
 	ice_free(hw, sw);
 }
diff --git a/drivers/net/ice/base/ice_switch.c b/drivers/net/ice/base/ice_switch.c
index b0c50c8f40..d9bb1e7c31 100644
--- a/drivers/net/ice/base/ice_switch.c
+++ b/drivers/net/ice/base/ice_switch.c
@@ -6910,6 +6910,47 @@  static struct ice_protocol_entry ice_prot_id_tbl[ICE_PROTOCOL_LAST] = {
 	{ ICE_VLAN_IN,		ICE_VLAN_OL_HW },
 };
 
+static u16 buildin_recipe_get(struct ice_switch_info *sw,
+			      struct ice_prot_lkup_ext *lkup_exts)
+{
+	int i;
+
+	if (!sw->buildin_recipes)
+		return ICE_MAX_NUM_RECIPES;
+
+	for (i = 10; i < ICE_MAX_NUM_RECIPES; i++) {
+		struct ice_sw_recipe *recp = &sw->buildin_recipes[i];
+		struct ice_fv_word *a = lkup_exts->fv_words;
+		struct ice_fv_word *b = recp->lkup_exts.fv_words;
+		u16 *c = recp->lkup_exts.field_mask;
+		u16 *d = lkup_exts->field_mask;
+		bool found = true;
+		u8 p, q;
+
+		if (!recp->is_root)
+			continue;
+
+		if (recp->lkup_exts.n_val_words != lkup_exts->n_val_words)
+			continue;
+
+		for (p = 0; p < lkup_exts->n_val_words; p++) {
+			for (q = 0; q < recp->lkup_exts.n_val_words; q++) {
+				if (a[p].off == b[q].off &&
+				    a[p].prot_id == b[q].prot_id &&
+				    d[p] == c[q])
+					break;
+			}
+			if (q >= recp->lkup_exts.n_val_words) {
+				found = false;
+				break;
+			}
+		}
+		if (found)
+			return i;
+	}
+	return ICE_MAX_NUM_RECIPES;
+}
+
 /**
  * ice_find_recp - find a recipe
  * @hw: pointer to the hardware structure
@@ -6922,8 +6963,15 @@  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 buildin_rid;
 	u8 i;
 
+	if (hw->use_buildin_recipe) {
+		buildin_rid = buildin_recipe_get(hw->switch_info, lkup_exts);
+		if (buildin_rid < ICE_MAX_NUM_RECIPES)
+			return buildin_rid;
+	}
+
 	/* Walk through existing recipes to find a match */
 	recp = hw->switch_info->recp_list;
 	for (i = 0; i < ICE_MAX_NUM_RECIPES; i++) {
@@ -9457,8 +9505,10 @@  ice_rem_adv_rule_by_id(struct ice_hw *hw,
 	struct ice_switch_info *sw;
 
 	sw = hw->switch_info;
-	if (!sw->recp_list[remove_entry->rid].recp_created)
+	if (!sw->buildin_recipes[remove_entry->rid].is_root &&
+	    !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) {
diff --git a/drivers/net/ice/base/ice_type.h b/drivers/net/ice/base/ice_type.h
index d81984633a..48144ea065 100644
--- a/drivers/net/ice/base/ice_type.h
+++ b/drivers/net/ice/base/ice_type.h
@@ -1107,6 +1107,7 @@  struct ice_switch_info {
 	u16 max_used_prof_index;
 
 	ice_declare_bitmap(prof_res_bm[ICE_MAX_NUM_PROFILES], ICE_MAX_FV_WORDS);
+	struct ice_sw_recipe *buildin_recipes;
 };
 
 /* Port hardware description */
@@ -1263,6 +1264,7 @@  struct ice_hw {
 	ice_declare_bitmap(hw_ptype, ICE_FLOW_PTYPE_MAX);
 	u8 dvm_ena;
 	__le16 io_expander_handle;
+	u8 use_buildin_recipe;
 };
 
 /* Statistics collected by each port, VSI, VEB, and S-channel */