Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2014-2023 Broadcom 3 : : * All rights reserved. 4 : : */ 5 : : 6 : : #include "ulp_matcher.h" 7 : : #include "ulp_utils.h" 8 : : 9 : : /* Utility function to calculate the class matcher hash */ 10 : : static uint32_t 11 : : ulp_matcher_class_hash_calculate(uint64_t hi_sig, uint64_t lo_sig) 12 : : { 13 : : uint64_t hash; 14 : : 15 : 0 : hi_sig |= ((hi_sig % BNXT_ULP_CLASS_HID_HIGH_PRIME) << 16 : : BNXT_ULP_CLASS_HID_SHFTL); 17 : 0 : lo_sig |= ((lo_sig % BNXT_ULP_CLASS_HID_LOW_PRIME) << 18 : : (BNXT_ULP_CLASS_HID_SHFTL + 2)); 19 : 0 : hash = hi_sig ^ lo_sig; 20 : 0 : hash = (hash >> BNXT_ULP_CLASS_HID_SHFTR) & BNXT_ULP_CLASS_HID_MASK; 21 : 0 : return (uint32_t)hash; 22 : : } 23 : : 24 : : /* Utility function to calculate the action matcher hash */ 25 : : static uint32_t 26 : : ulp_matcher_action_hash_calculate(uint64_t hi_sig, uint64_t app_id) 27 : : { 28 : : uint64_t hash; 29 : : 30 : 0 : hi_sig |= ((hi_sig % BNXT_ULP_ACT_HID_HIGH_PRIME) << 31 : : BNXT_ULP_ACT_HID_SHFTL); 32 : 0 : app_id |= ((app_id % BNXT_ULP_ACT_HID_LOW_PRIME) << 33 : : (BNXT_ULP_ACT_HID_SHFTL + 2)); 34 : 0 : hash = hi_sig ^ app_id; 35 : 0 : hash = (hash >> BNXT_ULP_ACT_HID_SHFTR) & BNXT_ULP_ACT_HID_MASK; 36 : 0 : return (uint32_t)hash; 37 : : } 38 : : 39 : : /* 40 : : * Function to handle the matching of RTE Flows and validating 41 : : * the pattern masks against the flow templates. 42 : : */ 43 : : int32_t 44 : 0 : ulp_matcher_pattern_match(struct ulp_rte_parser_params *params, 45 : : uint32_t *class_id) 46 : : { 47 : : struct bnxt_ulp_class_match_info *class_match; 48 : : uint32_t class_hid; 49 : : uint16_t tmpl_id; 50 : : 51 : : /* calculate the hash of the given flow */ 52 : 0 : class_hid = ulp_matcher_class_hash_calculate((params->hdr_bitmap.bits ^ 53 : 0 : params->app_id), 54 : : params->fld_s_bitmap.bits); 55 : : 56 : : /* validate the calculate hash values */ 57 : : if (class_hid >= BNXT_ULP_CLASS_SIG_TBL_MAX_SZ) 58 : : goto error; 59 : 0 : tmpl_id = ulp_class_sig_tbl[class_hid]; 60 [ # # ]: 0 : if (!tmpl_id) 61 : 0 : goto error; 62 : : 63 : 0 : class_match = &ulp_class_match_list[tmpl_id]; 64 [ # # ]: 0 : if (ULP_BITMAP_CMP(¶ms->hdr_bitmap, &class_match->hdr_sig)) { 65 : 0 : BNXT_TF_DBG(DEBUG, "Proto Header does not match\n"); 66 : 0 : goto error; 67 : : } 68 [ # # ]: 0 : if (ULP_BITMAP_CMP(¶ms->fld_s_bitmap, &class_match->field_sig)) { 69 : 0 : BNXT_TF_DBG(DEBUG, "Field signature does not match\n"); 70 : 0 : goto error; 71 : : } 72 : : 73 : : /* Match the application id before proceeding */ 74 [ # # ]: 0 : if (params->app_id != class_match->app_sig) { 75 : 0 : BNXT_TF_DBG(DEBUG, "Field to match the app id %u:%u\n", 76 : : params->app_id, class_match->app_sig); 77 : 0 : goto error; 78 : : } 79 : : 80 : 0 : BNXT_TF_DBG(DEBUG, "Found matching pattern template %d\n", 81 : : class_match->class_tid); 82 : 0 : *class_id = class_match->class_tid; 83 : 0 : params->hdr_sig_id = class_match->hdr_sig_id; 84 : 0 : params->flow_sig_id = class_match->flow_sig_id; 85 : 0 : params->flow_pattern_id = class_match->flow_pattern_id; 86 : 0 : return BNXT_TF_RC_SUCCESS; 87 : : 88 : 0 : error: 89 : 0 : BNXT_TF_DBG(DEBUG, "Did not find any matching template\n"); 90 : 0 : *class_id = 0; 91 : 0 : return BNXT_TF_RC_ERROR; 92 : : } 93 : : 94 : : /* 95 : : * Function to handle the matching of RTE Flows and validating 96 : : * the action against the flow templates. 97 : : */ 98 : : int32_t 99 : 0 : ulp_matcher_action_match(struct ulp_rte_parser_params *params, 100 : : uint32_t *act_id) 101 : : { 102 : : uint32_t act_hid; 103 : : uint16_t tmpl_id; 104 : : struct bnxt_ulp_act_match_info *act_match; 105 : : 106 : : /* calculate the hash of the given flow action */ 107 : 0 : act_hid = ulp_matcher_action_hash_calculate(params->act_bitmap.bits, 108 : 0 : params->app_id); 109 : : 110 : : /* validate the calculate hash values */ 111 : : if (act_hid >= BNXT_ULP_ACT_SIG_TBL_MAX_SZ) 112 : : goto error; 113 : 0 : tmpl_id = ulp_act_sig_tbl[act_hid]; 114 [ # # ]: 0 : if (!tmpl_id) 115 : 0 : goto error; 116 : : 117 : 0 : act_match = &ulp_act_match_list[tmpl_id]; 118 [ # # ]: 0 : if (ULP_BITMAP_CMP(¶ms->act_bitmap, &act_match->act_sig)) { 119 : 0 : BNXT_TF_DBG(DEBUG, "Action Header does not match\n"); 120 : 0 : goto error; 121 : : } 122 : : 123 : : /* Match the application id before proceeding */ 124 [ # # ]: 0 : if (params->app_id != act_match->app_sig) { 125 : 0 : BNXT_TF_DBG(DEBUG, "Field to match the app id %u:%u\n", 126 : : params->app_id, act_match->app_sig); 127 : 0 : goto error; 128 : : } 129 : : 130 : 0 : *act_id = act_match->act_tid; 131 : 0 : params->act_pattern_id = act_match->act_pattern_id; 132 : 0 : BNXT_TF_DBG(DEBUG, "Found matching action template %u\n", *act_id); 133 : 0 : return BNXT_TF_RC_SUCCESS; 134 : : 135 : 0 : error: 136 : 0 : BNXT_TF_DBG(DEBUG, "Did not find any matching action template\n"); 137 : 0 : *act_id = 0; 138 : 0 : return BNXT_TF_RC_ERROR; 139 : : }