1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2020 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)
30 hi_sig |= ((hi_sig % BNXT_ULP_ACT_HID_HIGH_PRIME) <<
31 BNXT_ULP_ACT_HID_SHFTL);
33 hash = (hash >> BNXT_ULP_ACT_HID_SHFTR) & BNXT_ULP_ACT_HID_MASK;
34 return (uint32_t)hash;
38 * Function to handle the matching of RTE Flows and validating
39 * the pattern masks against the flow templates.
42 ulp_matcher_pattern_match(struct ulp_rte_parser_params *params,
45 struct bnxt_ulp_class_match_info *class_match;
50 /* determine vf to vf flow */
51 if (params->dir == ULP_DIR_EGRESS &&
52 ULP_BITMAP_ISSET(params->act_bitmap.bits,
53 BNXT_ULP_ACTION_BIT_VNIC)) {
59 /* calculate the hash of the given flow */
60 class_hid = ulp_matcher_class_hash_calculate(params->hdr_bitmap.bits,
61 params->fld_bitmap.bits);
63 /* validate the calculate hash values */
64 if (class_hid >= BNXT_ULP_CLASS_SIG_TBL_MAX_SZ)
66 tmpl_id = ulp_class_sig_tbl[class_hid];
70 class_match = &ulp_class_match_list[tmpl_id];
71 if (ULP_BITMAP_CMP(¶ms->hdr_bitmap, &class_match->hdr_sig)) {
72 BNXT_TF_DBG(DEBUG, "Proto Header does not match\n");
75 if (ULP_BITMAP_CMP(¶ms->fld_bitmap, &class_match->field_sig)) {
76 BNXT_TF_DBG(DEBUG, "Field signature does not match\n");
79 if (vf_to_vf != class_match->act_vnic) {
80 BNXT_TF_DBG(DEBUG, "Vnic Match failed\n");
83 BNXT_TF_DBG(DEBUG, "Found matching pattern template %d\n",
84 class_match->class_tid);
85 *class_id = class_match->class_tid;
86 return BNXT_TF_RC_SUCCESS;
89 BNXT_TF_DBG(DEBUG, "Did not find any matching template\n");
91 return BNXT_TF_RC_ERROR;
95 * Function to handle the matching of RTE Flows and validating
96 * the action against the flow templates.
99 ulp_matcher_action_match(struct ulp_rte_parser_params *params,
104 struct bnxt_ulp_act_match_info *act_match;
106 /* calculate the hash of the given flow action */
107 act_hid = ulp_matcher_action_hash_calculate(params->act_bitmap.bits);
109 /* validate the calculate hash values */
110 if (act_hid >= BNXT_ULP_ACT_SIG_TBL_MAX_SZ)
112 tmpl_id = ulp_act_sig_tbl[act_hid];
116 act_match = &ulp_act_match_list[tmpl_id];
117 if (ULP_BITMAP_CMP(¶ms->act_bitmap, &act_match->act_sig)) {
118 BNXT_TF_DBG(DEBUG, "Action Header does not match\n");
121 *act_id = act_match->act_tid;
122 BNXT_TF_DBG(DEBUG, "Found matching action template %u\n", *act_id);
123 return BNXT_TF_RC_SUCCESS;
126 BNXT_TF_DBG(DEBUG, "Did not find any matching action template\n");
128 return BNXT_TF_RC_ERROR;