1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2021 Broadcom
6 #include "ulp_matcher.h"
9 /* Utility function to calculate the class matcher hash */
11 ulp_matcher_class_hash_calculate(uint64_t hi_sig, uint64_t lo_sig)
15 hi_sig |= ((hi_sig % BNXT_ULP_CLASS_HID_HIGH_PRIME) <<
16 BNXT_ULP_CLASS_HID_SHFTL);
17 lo_sig |= ((lo_sig % BNXT_ULP_CLASS_HID_LOW_PRIME) <<
18 (BNXT_ULP_CLASS_HID_SHFTL + 2));
19 hash = hi_sig ^ lo_sig;
20 hash = (hash >> BNXT_ULP_CLASS_HID_SHFTR) & BNXT_ULP_CLASS_HID_MASK;
21 return (uint32_t)hash;
24 /* Utility function to calculate the action matcher hash */
26 ulp_matcher_action_hash_calculate(uint64_t hi_sig, uint64_t app_id)
30 hi_sig |= ((hi_sig % BNXT_ULP_ACT_HID_HIGH_PRIME) <<
31 BNXT_ULP_ACT_HID_SHFTL);
32 app_id |= ((app_id % BNXT_ULP_CLASS_HID_LOW_PRIME) <<
33 (BNXT_ULP_CLASS_HID_SHFTL + 2));
34 hash = hi_sig ^ app_id;
35 hash = (hash >> BNXT_ULP_ACT_HID_SHFTR) & BNXT_ULP_ACT_HID_MASK;
36 return (uint32_t)hash;
40 * Function to handle the matching of RTE Flows and validating
41 * the pattern masks against the flow templates.
44 ulp_matcher_pattern_match(struct ulp_rte_parser_params *params,
47 struct bnxt_ulp_class_match_info *class_match;
52 /* Get vf to vf flow */
53 vf_to_vf = ULP_COMP_FLD_IDX_RD(params, BNXT_ULP_CF_IDX_VF_TO_VF);
55 /* calculate the hash of the given flow */
56 class_hid = ulp_matcher_class_hash_calculate((params->hdr_bitmap.bits ^
58 params->fld_s_bitmap.bits);
60 /* validate the calculate hash values */
61 if (class_hid >= BNXT_ULP_CLASS_SIG_TBL_MAX_SZ)
63 tmpl_id = ulp_class_sig_tbl[class_hid];
67 class_match = &ulp_class_match_list[tmpl_id];
68 if (ULP_BITMAP_CMP(¶ms->hdr_bitmap, &class_match->hdr_sig)) {
69 BNXT_TF_DBG(DEBUG, "Proto Header does not match\n");
72 if (ULP_BITMAP_CMP(¶ms->fld_s_bitmap, &class_match->field_sig)) {
73 BNXT_TF_DBG(DEBUG, "Field signature does not match\n");
77 /* Match the application id before proceeding */
78 if (params->app_id != class_match->app_sig) {
79 BNXT_TF_DBG(DEBUG, "Field to match the app id %u:%u\n",
80 params->app_id, class_match->app_sig);
84 if (vf_to_vf != class_match->act_vnic) {
85 BNXT_TF_DBG(DEBUG, "Vnic Match failed\n");
88 BNXT_TF_DBG(DEBUG, "Found matching pattern template %d\n",
89 class_match->class_tid);
90 *class_id = class_match->class_tid;
91 params->hdr_sig_id = class_match->hdr_sig_id;
92 params->flow_sig_id = class_match->flow_sig_id;
93 params->flow_pattern_id = class_match->flow_pattern_id;
94 return BNXT_TF_RC_SUCCESS;
97 BNXT_TF_DBG(DEBUG, "Did not find any matching template\n");
99 return BNXT_TF_RC_ERROR;
103 * Function to handle the matching of RTE Flows and validating
104 * the action against the flow templates.
107 ulp_matcher_action_match(struct ulp_rte_parser_params *params,
112 struct bnxt_ulp_act_match_info *act_match;
114 /* calculate the hash of the given flow action */
115 act_hid = ulp_matcher_action_hash_calculate(params->act_bitmap.bits,
118 /* validate the calculate hash values */
119 if (act_hid >= BNXT_ULP_ACT_SIG_TBL_MAX_SZ)
121 tmpl_id = ulp_act_sig_tbl[act_hid];
125 act_match = &ulp_act_match_list[tmpl_id];
126 if (ULP_BITMAP_CMP(¶ms->act_bitmap, &act_match->act_sig)) {
127 BNXT_TF_DBG(DEBUG, "Action Header does not match\n");
131 /* Match the application id before proceeding */
132 if (params->app_id != act_match->app_sig) {
133 BNXT_TF_DBG(DEBUG, "Field to match the app id %u:%u\n",
134 params->app_id, act_match->app_sig);
138 *act_id = act_match->act_tid;
139 params->act_pattern_id = act_match->act_pattern_id;
140 BNXT_TF_DBG(DEBUG, "Found matching action template %u\n", *act_id);
141 return BNXT_TF_RC_SUCCESS;
144 BNXT_TF_DBG(DEBUG, "Did not find any matching action template\n");
146 return BNXT_TF_RC_ERROR;