1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (C) 2020 Marvell International Ltd.
5 #include <rte_malloc.h>
6 #include <rte_regexdev.h>
8 #include "cn9k_regexdev.h"
9 #include "cn9k_regexdev_compiler.h"
11 #ifdef REE_COMPILER_SDK
12 #include <rxp-compiler.h>
15 ree_rule_db_compile(const struct rte_regexdev_rule *rules,
16 uint16_t nb_rules, struct rxp_rof **rof, struct rxp_rof **rofi,
17 struct rxp_rof *rof_for_incremental_compile,
18 struct rxp_rof *rofi_for_incremental_compile)
21 struct rxp_prefix_selection_control_list *prefix_selection_control_list
23 struct rxp_blacklist_data_sample *blacklist_sample_data = NULL;
24 struct rxp_rule_ids_to_remove *rule_ids_to_remove = NULL;
25 struct rxp_roff *roff_for_incremental_compile = NULL;
27 /*OPTIONS - setting default values*/
28 enum rxp_virtual_prefix_mode virtual_prefix_mode =
29 RXP_VIRTUAL_PREFIX_MODE_0;
30 enum rxp_prefix_capacity prefix_capacity = RXP_PREFIX_CAPACITY_32K;
31 /**< rxp_global_regex_options_flags*/
32 enum rxp_compiler_objective objective = RXP_COMPILER_OBJECTIVE_5;
33 enum rxp_tpe_data_width tpe_data_width = RXP_TPE_DATA_WIDTH_4;
34 uint32_t compiler_options = RXP_COMPILER_OPTIONS_FORCE;
35 /**< rxp_compiler_options_flags*/
36 enum rxp_verbose_level verbose = RXP_VERBOSE_LEVEL_3;
37 enum rxp_version set_rxp_version = RXP_VERSION_V5_8;
38 uint32_t compiler_output_flags = 0;
39 /**< rxp_compiler_output_flags*/
40 uint32_t global_regex_options = 0;
41 /**< rxp_global_regex_options_flags*/
42 float set_auto_blacklist = 0;
43 uint32_t max_rep_max = 65535;
44 uint32_t divide_ruleset = 1;
45 struct rxp_ruleset ruleset;
46 float ptpb_threshold = 0;
51 struct rxp_rule_direction_analysis *rule_direction_analysis = NULL;
52 struct rxp_compilation_statistics *compilation_statistics = NULL;
53 struct rxp_prefix_selection_control_list *generated_pscl = NULL;
54 struct rxp_uncompiled_rules_log *uncompiled_rules_log = NULL;
55 struct rxp_critical_rules_rank *critical_rules_rank = NULL;
56 struct rxp_compiled_rules_log *compiled_rules_log = NULL;
57 struct rxp_roff *roff = NULL;
62 ruleset.number_of_entries = nb_rules;
63 ruleset.rules = rte_malloc("rxp_rule_entry",
64 nb_rules*sizeof(struct rxp_rule_entry), 0);
66 if (ruleset.rules == NULL) {
67 cn9k_err("Could not allocate memory for rule compilation\n");
70 if (rof_for_incremental_compile)
71 compiler_options |= RXP_COMPILER_OPTIONS_INCREMENTAL;
72 if (rofi_for_incremental_compile)
73 compiler_options |= RXP_COMPILER_OPTIONS_CHECKSUM;
75 for (i = 0; i < nb_rules; i++) {
76 ruleset.rules[i].number_of_prefix_entries = 0;
77 ruleset.rules[i].prefix = NULL;
78 ruleset.rules[i].rule = rules[i].pcre_rule;
79 ruleset.rules[i].rule_id = rules[i].rule_id;
80 ruleset.rules[i].subset_id = rules[i].group_id;
81 ruleset.rules[i].rule_direction_type =
82 RXP_RULE_DIRECTION_TYPE_NONE;
85 ret = rxp_compile_advanced(
88 prefix_selection_control_list,
89 rof_for_incremental_compile,
90 roff_for_incremental_compile,
91 rofi_for_incremental_compile,
93 blacklist_sample_data,
109 compiler_output_flags,
113 &compilation_statistics,
115 &critical_rules_rank,
116 &rule_direction_analysis,
117 &uncompiled_rules_log,
122 rte_free(ruleset.rules);
128 cn9k_ree_rule_db_compile_prog(struct rte_regexdev *dev)
130 struct cn9k_ree_data *data = dev->data->dev_private;
131 struct roc_ree_vf *vf = &data->vf;
132 char compiler_version[] = "20.5.2.eda0fa2";
133 char timestamp[] = "19700101_000001";
134 uint32_t rule_db_len, rule_dbi_len;
135 struct rxp_rof *rofi_inc_p = NULL;
136 struct rxp_rof_entry rule_dbi[6];
137 char *rofi_rof_entries = NULL;
138 struct rxp_rof *rofi = NULL;
139 struct rxp_rof *rof = NULL;
140 struct rxp_rof rofi_inc;
141 struct rxp_rof rof_inc;
142 char *rule_db = NULL;
147 ret = roc_ree_rule_db_len_get(vf, &rule_db_len, &rule_dbi_len);
149 cn9k_err("Could not get rule db length");
153 if (rule_db_len > 0) {
154 cn9k_ree_dbg("Incremental compile, rule db len %d rule dbi len %d",
155 rule_db_len, rule_dbi_len);
156 rule_db = rte_malloc("ree_rule_db", rule_db_len, 0);
158 cn9k_err("Could not allocate memory for rule db");
162 ret = roc_ree_rule_db_get(vf, rule_db, rule_db_len,
163 (char *)rule_dbi, rule_dbi_len);
165 cn9k_err("Could not read rule db");
169 rof_inc.rof_revision = 0;
170 rof_inc.rof_version = 2;
171 rof_inc.rof_entries = (struct rxp_rof_entry *)rule_db;
172 rof_inc.rxp_compiler_version = compiler_version;
173 rof_inc.timestamp = timestamp;
174 rof_inc.number_of_entries =
175 (rule_db_len/sizeof(struct rxp_rof_entry));
177 if (rule_dbi_len > 0) {
178 /* incremental compilation not the first time */
179 rofi_inc.rof_revision = 0;
180 rofi_inc.rof_version = 2;
181 rofi_inc.rof_entries = rule_dbi;
182 rofi_inc.rxp_compiler_version = compiler_version;
183 rofi_inc.timestamp = timestamp;
184 rofi_inc.number_of_entries =
185 (rule_dbi_len/sizeof(struct rxp_rof_entry));
186 rofi_inc_p = &rofi_inc;
188 ret = ree_rule_db_compile(data->rules, data->nb_rules, &rof,
189 &rofi, &rof_inc, rofi_inc_p);
190 if (rofi->number_of_entries == 0) {
191 cn9k_ree_dbg("No change to rule db");
195 rule_dbi_len = rofi->number_of_entries *
196 sizeof(struct rxp_rof_entry);
197 rofi_rof_entries = (char *)rofi->rof_entries;
199 /* full compilation */
200 ret = ree_rule_db_compile(data->rules, data->nb_rules, &rof,
204 cn9k_err("Could not compile rule db");
207 rule_db_len = rof->number_of_entries * sizeof(struct rxp_rof_entry);
208 ret = roc_ree_rule_db_prog(vf, (char *)rof->rof_entries, rule_db_len,
209 rofi_rof_entries, rule_dbi_len);
211 cn9k_err("Could not program rule db");
214 rxp_free_structs(NULL, NULL, NULL, NULL, NULL, &rof, NULL, &rofi, NULL,
224 cn9k_ree_rule_db_compile_prog(struct rte_regexdev *dev)