1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2021 Broadcom
6 #include "ulp_matcher.h"
9 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
10 #include "ulp_template_debug_proto.h"
13 /* Utility function to calculate the class matcher hash */
15 ulp_matcher_class_hash_calculate(uint64_t hi_sig, uint64_t lo_sig)
19 hi_sig |= ((hi_sig % BNXT_ULP_CLASS_HID_HIGH_PRIME) <<
20 BNXT_ULP_CLASS_HID_SHFTL);
21 lo_sig |= ((lo_sig % BNXT_ULP_CLASS_HID_LOW_PRIME) <<
22 (BNXT_ULP_CLASS_HID_SHFTL + 2));
23 hash = hi_sig ^ lo_sig;
24 hash = (hash >> BNXT_ULP_CLASS_HID_SHFTR) & BNXT_ULP_CLASS_HID_MASK;
25 return (uint32_t)hash;
28 /* Utility function to calculate the action matcher hash */
30 ulp_matcher_action_hash_calculate(uint64_t hi_sig, uint64_t app_id)
34 hi_sig |= ((hi_sig % BNXT_ULP_ACT_HID_HIGH_PRIME) <<
35 BNXT_ULP_ACT_HID_SHFTL);
36 app_id |= ((app_id % BNXT_ULP_CLASS_HID_LOW_PRIME) <<
37 (BNXT_ULP_CLASS_HID_SHFTL + 2));
38 hash = hi_sig ^ app_id;
39 hash = (hash >> BNXT_ULP_ACT_HID_SHFTR) & BNXT_ULP_ACT_HID_MASK;
40 return (uint32_t)hash;
44 * Function to handle the matching of RTE Flows and validating
45 * the pattern masks against the flow templates.
48 ulp_matcher_pattern_match(struct ulp_rte_parser_params *params,
51 struct bnxt_ulp_class_match_info *class_match;
56 /* Get vf to vf flow */
57 vf_to_vf = ULP_COMP_FLD_IDX_RD(params, BNXT_ULP_CF_IDX_VF_TO_VF);
59 /* calculate the hash of the given flow */
60 class_hid = ulp_matcher_class_hash_calculate((params->hdr_bitmap.bits ^
62 params->fld_s_bitmap.bits);
64 /* validate the calculate hash values */
65 if (class_hid >= BNXT_ULP_CLASS_SIG_TBL_MAX_SZ)
67 tmpl_id = ulp_class_sig_tbl[class_hid];
71 class_match = &ulp_class_match_list[tmpl_id];
72 if (ULP_BITMAP_CMP(¶ms->hdr_bitmap, &class_match->hdr_sig)) {
73 BNXT_TF_DBG(DEBUG, "Proto Header does not match\n");
76 if (ULP_BITMAP_CMP(¶ms->fld_s_bitmap, &class_match->field_sig)) {
77 BNXT_TF_DBG(DEBUG, "Field signature does not match\n");
81 /* Match the application id before proceeding */
82 if (params->app_id != class_match->app_sig) {
83 BNXT_TF_DBG(DEBUG, "Field to match the app id %u:%u\n",
84 params->app_id, class_match->app_sig);
88 if (vf_to_vf != class_match->act_vnic) {
89 BNXT_TF_DBG(DEBUG, "Vnic Match failed\n");
92 BNXT_TF_DBG(DEBUG, "Found matching pattern template %d\n",
93 class_match->class_tid);
94 *class_id = class_match->class_tid;
95 params->hdr_sig_id = class_match->hdr_sig_id;
96 params->flow_sig_id = class_match->flow_sig_id;
97 params->flow_pattern_id = class_match->flow_pattern_id;
98 return BNXT_TF_RC_SUCCESS;
101 BNXT_TF_DBG(DEBUG, "Did not find any matching template\n");
102 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
103 BNXT_TF_DBG(DEBUG, "class_hid:0x%x, Hdr:%" PRIX64 " Fld:%" PRIX64 "\n",
104 class_hid, params->hdr_bitmap.bits,
105 params->fld_bitmap.bits);
108 return BNXT_TF_RC_ERROR;
112 * Function to handle the matching of RTE Flows and validating
113 * the action against the flow templates.
116 ulp_matcher_action_match(struct ulp_rte_parser_params *params,
121 struct bnxt_ulp_act_match_info *act_match;
123 /* calculate the hash of the given flow action */
124 act_hid = ulp_matcher_action_hash_calculate(params->act_bitmap.bits,
127 /* validate the calculate hash values */
128 if (act_hid >= BNXT_ULP_ACT_SIG_TBL_MAX_SZ)
130 tmpl_id = ulp_act_sig_tbl[act_hid];
134 act_match = &ulp_act_match_list[tmpl_id];
135 if (ULP_BITMAP_CMP(¶ms->act_bitmap, &act_match->act_sig)) {
136 BNXT_TF_DBG(DEBUG, "Action Header does not match\n");
140 /* Match the application id before proceeding */
141 if (params->app_id != act_match->app_sig) {
142 BNXT_TF_DBG(DEBUG, "Field to match the app id %u:%u\n",
143 params->app_id, act_match->app_sig);
147 *act_id = act_match->act_tid;
148 params->act_pattern_id = act_match->act_pattern_id;
149 BNXT_TF_DBG(DEBUG, "Found matching action template %u\n", *act_id);
150 return BNXT_TF_RC_SUCCESS;
153 BNXT_TF_DBG(DEBUG, "Did not find any matching action template\n");
154 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
155 BNXT_TF_DBG(DEBUG, "act_hid:0x%x, Hdr:%" PRIX64 "\n",
156 act_hid, params->act_bitmap.bits);
159 return BNXT_TF_RC_ERROR;