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 "otx2_regexdev.h"
9 #include "otx2_regexdev_compiler.h"
10 #include "otx2_regexdev_mbox.h"
12 #ifdef REE_COMPILER_SDK
13 #include <rxp-compiler.h>
16 ree_rule_db_compile(const struct rte_regexdev_rule *rules,
17 uint16_t nb_rules, struct rxp_rof **rof, struct rxp_rof **rofi,
18 struct rxp_rof *rof_for_incremental_compile,
19 struct rxp_rof *rofi_for_incremental_compile)
22 struct rxp_prefix_selection_control_list *prefix_selection_control_list
24 struct rxp_blacklist_data_sample *blacklist_sample_data = NULL;
25 struct rxp_rule_ids_to_remove *rule_ids_to_remove = NULL;
26 struct rxp_roff *roff_for_incremental_compile = NULL;
28 /*OPTIONS - setting default values*/
29 enum rxp_virtual_prefix_mode virtual_prefix_mode =
30 RXP_VIRTUAL_PREFIX_MODE_0;
31 enum rxp_prefix_capacity prefix_capacity = RXP_PREFIX_CAPACITY_32K;
32 /**< rxp_global_regex_options_flags*/
33 enum rxp_compiler_objective objective = RXP_COMPILER_OBJECTIVE_5;
34 enum rxp_tpe_data_width tpe_data_width = RXP_TPE_DATA_WIDTH_4;
35 uint32_t compiler_options = RXP_COMPILER_OPTIONS_FORCE;
36 /**< rxp_compiler_options_flags*/
37 enum rxp_verbose_level verbose = RXP_VERBOSE_LEVEL_3;
38 enum rxp_version set_rxp_version = RXP_VERSION_V5_8;
39 uint32_t compiler_output_flags = 0;
40 /**< rxp_compiler_output_flags*/
41 uint32_t global_regex_options = 0;
42 /**< rxp_global_regex_options_flags*/
43 float set_auto_blacklist = 0;
44 uint32_t max_rep_max = 65535;
45 uint32_t divide_ruleset = 1;
46 struct rxp_ruleset ruleset;
47 float ptpb_threshold = 0;
52 struct rxp_rule_direction_analysis *rule_direction_analysis = NULL;
53 struct rxp_compilation_statistics *compilation_statistics = NULL;
54 struct rxp_prefix_selection_control_list *generated_pscl = NULL;
55 struct rxp_uncompiled_rules_log *uncompiled_rules_log = NULL;
56 struct rxp_critical_rules_rank *critical_rules_rank = NULL;
57 struct rxp_compiled_rules_log *compiled_rules_log = NULL;
58 struct rxp_roff *roff = NULL;
63 ruleset.number_of_entries = nb_rules;
64 ruleset.rules = rte_malloc("rxp_rule_entry",
65 nb_rules*sizeof(struct rxp_rule_entry), 0);
67 if (ruleset.rules == NULL) {
68 otx2_err("Could not allocate memory for rule compilation\n");
71 if (rof_for_incremental_compile)
72 compiler_options |= RXP_COMPILER_OPTIONS_INCREMENTAL;
73 if (rofi_for_incremental_compile)
74 compiler_options |= RXP_COMPILER_OPTIONS_CHECKSUM;
76 for (i = 0; i < nb_rules; i++) {
77 ruleset.rules[i].number_of_prefix_entries = 0;
78 ruleset.rules[i].prefix = NULL;
79 ruleset.rules[i].rule = rules[i].pcre_rule;
80 ruleset.rules[i].rule_id = rules[i].rule_id;
81 ruleset.rules[i].subset_id = rules[i].group_id;
82 ruleset.rules[i].rule_direction_type =
83 RXP_RULE_DIRECTION_TYPE_NONE;
86 ret = rxp_compile_advanced(
89 prefix_selection_control_list,
90 rof_for_incremental_compile,
91 roff_for_incremental_compile,
92 rofi_for_incremental_compile,
94 blacklist_sample_data,
110 compiler_output_flags,
114 &compilation_statistics,
116 &critical_rules_rank,
117 &rule_direction_analysis,
118 &uncompiled_rules_log,
123 rte_free(ruleset.rules);
129 otx2_ree_rule_db_compile_prog(struct rte_regexdev *dev)
131 struct otx2_ree_data *data = dev->data->dev_private;
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 = otx2_ree_rule_db_len_get(dev, &rule_db_len, &rule_dbi_len);
149 otx2_err("Could not get rule db length");
153 if (rule_db_len > 0) {
154 otx2_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 otx2_err("Could not allocate memory for rule db");
162 ret = otx2_ree_rule_db_get(dev, rule_db, rule_db_len,
163 (char *)rule_dbi, rule_dbi_len);
165 otx2_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 otx2_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 otx2_err("Could not compile rule db");
207 rule_db_len = rof->number_of_entries * sizeof(struct rxp_rof_entry);
208 ret = otx2_ree_rule_db_prog(dev, (char *)rof->rof_entries, rule_db_len,
209 rofi_rof_entries, rule_dbi_len);
211 otx2_err("Could not program rule db");
214 rxp_free_structs(NULL, NULL, NULL, NULL, NULL, &rof, NULL, &rofi, NULL,
224 otx2_ree_rule_db_compile_prog(struct rte_regexdev *dev)