1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(C) 2019 Marvell International Ltd. 3 * Copyright 2020 Mellanox Technologies, Ltd 4 * Copyright(c) 2020 Intel Corporation 5 */ 6 7 #ifndef _RTE_REGEXDEV_H_ 8 #define _RTE_REGEXDEV_H_ 9 10 /** 11 * @file 12 * 13 * RTE RegEx Device API 14 * 15 * Defines RTE RegEx Device APIs for RegEx operations and its provisioning. 16 * 17 * The RegEx Device API is composed of two parts: 18 * 19 * - The application-oriented RegEx API that includes functions to setup 20 * a RegEx device (configure it, setup its queue pairs and start it), 21 * update the rule database and so on. 22 * 23 * - The driver-oriented RegEx API that exports a function allowing 24 * a RegEx poll Mode Driver (PMD) to simultaneously register itself as 25 * a RegEx device driver. 26 * 27 * RegEx device components and definitions: 28 * 29 * +-----------------+ 30 * | | 31 * | o---------+ rte_regexdev_[en|de]queue_burst() 32 * | PCRE based o------+ | | 33 * | RegEx pattern | | | +--------+ | 34 * | matching engine o------+--+--o | | +------+ 35 * | | | | | queue |<==o===>|Core 0| 36 * | o----+ | | | pair 0 | | | 37 * | | | | | +--------+ +------+ 38 * +-----------------+ | | | 39 * ^ | | | +--------+ 40 * | | | | | | +------+ 41 * | | +--+--o queue |<======>|Core 1| 42 * Rule|Database | | | pair 1 | | | 43 * +------+----------+ | | +--------+ +------+ 44 * | Group 0 | | | 45 * | +-------------+ | | | +--------+ +------+ 46 * | | Rules 0..n | | | | | | |Core 2| 47 * | +-------------+ | | +--o queue |<======>| | 48 * | Group 1 | | | pair 2 | +------+ 49 * | +-------------+ | | +--------+ 50 * | | Rules 0..n | | | 51 * | +-------------+ | | +--------+ 52 * | Group 2 | | | | +------+ 53 * | +-------------+ | | | queue |<======>|Core n| 54 * | | Rules 0..n | | +-------o pair n | | | 55 * | +-------------+ | +--------+ +------+ 56 * | Group n | 57 * | +-------------+ |<-------rte_regexdev_rule_db_update() 58 * | | | |<-------rte_regexdev_rule_db_compile_activate() 59 * | | Rules 0..n | |<-------rte_regexdev_rule_db_import() 60 * | +-------------+ |------->rte_regexdev_rule_db_export() 61 * +-----------------+ 62 * 63 * RegEx: A regular expression is a concise and flexible means for matching 64 * strings of text, such as particular characters, words, or patterns of 65 * characters. A common abbreviation for this is “RegEx”. 66 * 67 * RegEx device: A hardware or software-based implementation of RegEx 68 * device API for PCRE based pattern matching syntax and semantics. 69 * 70 * PCRE RegEx syntax and semantics specification: 71 * http://regexkit.sourceforge.net/Documentation/pcre/pcrepattern.html 72 * 73 * RegEx queue pair: Each RegEx device should have one or more queue pair to 74 * transmit a burst of pattern matching request and receive a burst of 75 * receive the pattern matching response. The pattern matching request/response 76 * embedded in *rte_regex_ops* structure. 77 * 78 * Rule: A pattern matching rule expressed in PCRE RegEx syntax along with 79 * Match ID and Group ID to identify the rule upon the match. 80 * 81 * Rule database: The RegEx device accepts regular expressions and converts them 82 * into a compiled rule database that can then be used to scan data. 83 * Compilation allows the device to analyze the given pattern(s) and 84 * pre-determine how to scan for these patterns in an optimized fashion that 85 * would be far too expensive to compute at run-time. A rule database contains 86 * a set of rules that compiled in device specific binary form. 87 * 88 * Match ID or Rule ID: A unique identifier provided at the time of rule 89 * creation for the application to identify the rule upon match. 90 * 91 * Group ID: Group of rules can be grouped under one group ID to enable 92 * rule isolation and effective pattern matching. A unique group identifier 93 * provided at the time of rule creation for the application to identify the 94 * rule upon match. 95 * 96 * Scan: A pattern matching request through *enqueue* API. 97 * 98 * It may possible that a given RegEx device may not support all the features 99 * of PCRE. The application may probe unsupported features through 100 * struct rte_regexdev_info::pcre_unsup_flags 101 * 102 * By default, all the functions of the RegEx Device API exported by a PMD 103 * are lock-free functions which assume to not be invoked in parallel on 104 * different logical cores to work on the same target object. For instance, 105 * the dequeue function of a PMD cannot be invoked in parallel on two logical 106 * cores to operates on same RegEx queue pair. Of course, this function 107 * can be invoked in parallel by different logical core on different queue pair. 108 * It is the responsibility of the upper level application to enforce this rule. 109 * 110 * In all functions of the RegEx API, the RegEx device is 111 * designated by an integer >= 0 named the device identifier *dev_id* 112 * 113 * At the RegEx driver level, RegEx devices are represented by a generic 114 * data structure of type *rte_regexdev*. 115 * 116 * RegEx devices are dynamically registered during the PCI/SoC device probing 117 * phase performed at EAL initialization time. 118 * When a RegEx device is being probed, a *rte_regexdev* structure and 119 * a new device identifier are allocated for that device. Then, the 120 * regexdev_init() function supplied by the RegEx driver matching the probed 121 * device is invoked to properly initialize the device. 122 * 123 * The role of the device init function consists of resetting the hardware or 124 * software RegEx driver implementations. 125 * 126 * If the device init operation is successful, the correspondence between 127 * the device identifier assigned to the new device and its associated 128 * *rte_regexdev* structure is effectively registered. 129 * Otherwise, both the *rte_regexdev* structure and the device identifier are 130 * freed. 131 * 132 * The functions exported by the application RegEx API to setup a device 133 * designated by its device identifier must be invoked in the following order: 134 * - rte_regexdev_configure() 135 * - rte_regexdev_queue_pair_setup() 136 * - rte_regexdev_start() 137 * 138 * Then, the application can invoke, in any order, the functions 139 * exported by the RegEx API to enqueue pattern matching job, dequeue pattern 140 * matching response, get the stats, update the rule database, 141 * get/set device attributes and so on 142 * 143 * If the application wants to change the configuration (i.e. call 144 * rte_regexdev_configure() or rte_regexdev_queue_pair_setup()), it must call 145 * rte_regexdev_stop() first to stop the device and then do the reconfiguration 146 * before calling rte_regexdev_start() again. The enqueue and dequeue 147 * functions should not be invoked when the device is stopped. 148 * 149 * Finally, an application can close a RegEx device by invoking the 150 * rte_regexdev_close() function. 151 * 152 * Each function of the application RegEx API invokes a specific function 153 * of the PMD that controls the target device designated by its device 154 * identifier. 155 * 156 * For this purpose, all device-specific functions of a RegEx driver are 157 * supplied through a set of pointers contained in a generic structure of type 158 * *regexdev_ops*. 159 * The address of the *regexdev_ops* structure is stored in the *rte_regexdev* 160 * structure by the device init function of the RegEx driver, which is 161 * invoked during the PCI/SoC device probing phase, as explained earlier. 162 * 163 * In other words, each function of the RegEx API simply retrieves the 164 * *rte_regexdev* structure associated with the device identifier and 165 * performs an indirect invocation of the corresponding driver function 166 * supplied in the *regexdev_ops* structure of the *rte_regexdev* structure. 167 * 168 * For performance reasons, the address of the fast-path functions of the 169 * RegEx driver is not contained in the *regexdev_ops* structure. 170 * Instead, they are directly stored at the beginning of the *rte_regexdev* 171 * structure to avoid an extra indirect memory access during their invocation. 172 * 173 * RTE RegEx device drivers do not use interrupts for enqueue or dequeue 174 * operation. Instead, RegEx drivers export Poll-Mode enqueue and dequeue 175 * functions to applications. 176 * 177 * The *enqueue* operation submits a burst of RegEx pattern matching request 178 * to the RegEx device and the *dequeue* operation gets a burst of pattern 179 * matching response for the ones submitted through *enqueue* operation. 180 * 181 * Typical application utilisation of the RegEx device API will follow the 182 * following programming flow. 183 * 184 * - rte_regexdev_configure() 185 * - rte_regexdev_queue_pair_setup() 186 * - rte_regexdev_rule_db_update() Needs to invoke if precompiled rule database 187 * not provided in rte_regexdev_config::rule_db for rte_regexdev_configure() 188 * and/or application needs to update rule database. 189 * - rte_regexdev_rule_db_compile_activate() Needs to invoke if 190 * rte_regexdev_rule_db_update function was used. 191 * - Create or reuse exiting mempool for *rte_regex_ops* objects. 192 * - rte_regexdev_start() 193 * - rte_regexdev_enqueue_burst() 194 * - rte_regexdev_dequeue_burst() 195 */ 196 197 #ifdef __cplusplus 198 extern "C" { 199 #endif 200 201 #include <rte_compat.h> 202 #include <rte_common.h> 203 #include <rte_dev.h> 204 #include <rte_mbuf.h> 205 206 #define RTE_REGEXDEV_NAME_MAX_LEN RTE_DEV_NAME_MAX_LEN 207 208 extern int rte_regexdev_logtype; 209 210 #define RTE_REGEXDEV_LOG(level, ...) \ 211 rte_log(RTE_LOG_ ## level, rte_regexdev_logtype, "" __VA_ARGS__) 212 213 /* Macros to check for valid port */ 214 #define RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, retval) do { \ 215 if (!rte_regexdev_is_valid_dev(dev_id)) { \ 216 RTE_REGEXDEV_LOG(ERR, "Invalid dev_id=%u\n", dev_id); \ 217 return retval; \ 218 } \ 219 } while (0) 220 221 #define RTE_REGEXDEV_VALID_DEV_ID_OR_RET(dev_id) do { \ 222 if (!rte_regexdev_is_valid_dev(dev_id)) { \ 223 RTE_REGEXDEV_LOG(ERR, "Invalid dev_id=%u\n", dev_id); \ 224 return; \ 225 } \ 226 } while (0) 227 228 /** 229 * @warning 230 * @b EXPERIMENTAL: this API may change without prior notice. 231 * 232 * Check if dev_id is ready. 233 * 234 * @param dev_id 235 * The dev identifier of the RegEx device. 236 * 237 * @return 238 * - 0 if device state is not in ready state. 239 * - 1 if device state is ready state. 240 */ 241 __rte_experimental 242 int rte_regexdev_is_valid_dev(uint16_t dev_id); 243 244 /** 245 * @warning 246 * @b EXPERIMENTAL: this API may change without prior notice. 247 * 248 * Get the total number of RegEx devices that have been successfully 249 * initialised. 250 * 251 * @return 252 * The total number of usable RegEx devices. 253 */ 254 __rte_experimental 255 uint8_t 256 rte_regexdev_count(void); 257 258 /** 259 * @warning 260 * @b EXPERIMENTAL: this API may change without prior notice. 261 * 262 * Get the device identifier for the named RegEx device. 263 * 264 * @param name 265 * RegEx device name to select the RegEx device identifier. 266 * 267 * @return 268 * Returns RegEx device identifier on success. 269 * - <0: Failure to find named RegEx device. 270 */ 271 __rte_experimental 272 int 273 rte_regexdev_get_dev_id(const char *name); 274 275 /* Enumerates RegEx device capabilities */ 276 #define RTE_REGEXDEV_CAPA_RUNTIME_COMPILATION_F (1ULL << 0) 277 /**< RegEx device does support compiling the rules at runtime unlike 278 * loading only the pre-built rule database using 279 * struct rte_regexdev_config::rule_db in rte_regexdev_configure() 280 * 281 * @see struct rte_regexdev_config::rule_db, rte_regexdev_configure() 282 * @see struct rte_regexdev_info::regexdev_capa 283 */ 284 285 #define RTE_REGEXDEV_CAPA_SUPP_PCRE_START_ANCHOR_F (1ULL << 1) 286 /**< RegEx device support PCRE Anchor to start of match flag. 287 * Example RegEx is `/\Gfoo\d/`. Here `\G` asserts position at the end of the 288 * previous match or the start of the string for the first match. 289 * This position will change each time the RegEx is applied to the subject 290 * string. If the RegEx is applied to `foo1foo2Zfoo3` the first two matches will 291 * be successful for `foo1foo2` and fail for `Zfoo3`. 292 * 293 * @see struct rte_regexdev_info::regexdev_capa 294 */ 295 296 #define RTE_REGEXDEV_CAPA_SUPP_PCRE_ATOMIC_GROUPING_F (1ULL << 2) 297 /**< RegEx device support PCRE Atomic grouping. 298 * Atomic groups are represented by `(?>)`. An atomic group is a group that, 299 * when the RegEx engine exits from it, automatically throws away all 300 * backtracking positions remembered by any tokens inside the group. 301 * Example RegEx is `a(?>bc|b)c` if the given patterns are `abc` and `abcc` then 302 * `a(bc|b)c` matches both where as `a(?>bc|b)c` matches only abcc because 303 * atomic groups don't allow backtracking back to `b`. 304 * 305 * @see struct rte_regexdev_info::regexdev_capa 306 */ 307 308 #define RTE_REGEXDEV_SUPP_PCRE_BACKTRACKING_CTRL_F (1ULL << 3) 309 /**< RegEx device support PCRE backtracking control verbs. 310 * Some examples of backtracking verbs are (*COMMIT), (*ACCEPT), (*FAIL), 311 * (*SKIP), (*PRUNE). 312 * 313 * @see struct rte_regexdev_info::regexdev_capa 314 */ 315 316 #define RTE_REGEXDEV_SUPP_PCRE_CALLOUTS_F (1ULL << 4) 317 /**< RegEx device support PCRE callouts. 318 * PCRE supports calling external function in between matches by using `(?C)`. 319 * Example RegEx `ABC(?C)D` if a given patter is `ABCD` then the RegEx engine 320 * will parse ABC perform a userdefined callout and return a successful match at 321 * D. 322 * 323 * @see struct rte_regexdev_info::regexdev_capa 324 */ 325 326 #define RTE_REGEXDEV_SUPP_PCRE_BACKREFERENCE_F (1ULL << 5) 327 /**< RegEx device support PCRE backreference. 328 * Example RegEx is `(\2ABC|(GHI))+` `\2` matches the same text as most recently 329 * matched by the 2nd capturing group i.e. `GHI`. 330 * 331 * @see struct rte_regexdev_info::regexdev_capa 332 */ 333 334 #define RTE_REGEXDEV_SUPP_PCRE_GREEDY_F (1ULL << 6) 335 /**< RegEx device support PCRE Greedy mode. 336 * For example if the RegEx is `AB\d*?` then `*?` represents zero or unlimited 337 * matches. In greedy mode the pattern `AB12345` will be matched completely 338 * where as the ungreedy mode `AB` will be returned as the match. 339 * 340 * @see struct rte_regexdev_info::regexdev_capa 341 */ 342 343 #define RTE_REGEXDEV_SUPP_PCRE_MATCH_ALL_F (1ULL << 7) 344 /**< RegEx device support match all mode. 345 * For example if the RegEx is `AB\d*?` then `*?` represents zero or unlimited 346 * matches. In match all mode the pattern `AB12345` will return 6 matches. 347 * AB, AB1, AB12, AB123, AB1234, AB12345. 348 * 349 * @see struct rte_regexdev_info::regexdev_capa 350 */ 351 352 #define RTE_REGEXDEV_SUPP_PCRE_LOOKAROUND_ASRT_F (1ULL << 8) 353 /**< RegEx device support PCRE Lookaround assertions 354 * (Zero-width assertions). Example RegEx is `[a-z]+\d+(?=!{3,})` if 355 * the given pattern is `dwad1234!` the RegEx engine doesn't report any matches 356 * because the assert `(?=!{3,})` fails. The pattern `dwad123!!!` would return a 357 * successful match. 358 * 359 * @see struct rte_regexdev_info::regexdev_capa 360 */ 361 362 #define RTE_REGEXDEV_SUPP_PCRE_MATCH_POINT_RST_F (1ULL << 9) 363 /**< RegEx device doesn't support PCRE match point reset directive. 364 * Example RegEx is `[a-z]+\K\d+` if the pattern is `dwad123` 365 * then even though the entire pattern matches only `123` 366 * is reported as a match. 367 * 368 * @see struct rte_regexdev_info::regexdev_capa 369 */ 370 371 #define RTE_REGEXDEV_SUPP_NEWLINE_CONVENTIONS_F (1ULL << 10) 372 /**< RegEx support PCRE newline convention. 373 * Newline conventions are represented as follows: 374 * (*CR) carriage return 375 * (*LF) linefeed 376 * (*CRLF) carriage return, followed by linefeed 377 * (*ANYCRLF) any of the three above 378 * (*ANY) all Unicode newline sequences 379 * 380 * @see struct rte_regexdev_info::regexdev_capa 381 */ 382 383 #define RTE_REGEXDEV_SUPP_PCRE_NEWLINE_SEQ_F (1ULL << 11) 384 /**< RegEx device support PCRE newline sequence. 385 * The escape sequence `\R` will match any newline sequence. 386 * It is equivalent to: `(?>\r\n|\n|\x0b|\f|\r|\x85)`. 387 * 388 * @see struct rte_regexdev_info::regexdev_capa 389 */ 390 391 #define RTE_REGEXDEV_SUPP_PCRE_POSSESSIVE_QUALIFIERS_F (1ULL << 12) 392 /**< RegEx device support PCRE possessive qualifiers. 393 * Example RegEx possessive qualifiers `*+`, `++`, `?+`, `{m,n}+`. 394 * Possessive quantifier repeats the token as many times as possible and it does 395 * not give up matches as the engine backtracks. With a possessive quantifier, 396 * the deal is all or nothing. 397 * 398 * @see struct rte_regexdev_info::regexdev_capa 399 */ 400 401 #define RTE_REGEXDEV_SUPP_PCRE_SUBROUTINE_REFERENCES_F (1ULL << 13) 402 /**< RegEx device support PCRE Subroutine references. 403 * PCRE Subroutine references allow for sub patterns to be assessed 404 * as part of the RegEx. Example RegEx is `(foo|fuzz)\g<1>+bar` matches the 405 * pattern `foofoofuzzfoofuzzbar`. 406 * 407 * @see struct rte_regexdev_info::regexdev_capa 408 */ 409 410 #define RTE_REGEXDEV_SUPP_PCRE_UTF_8_F (1ULL << 14) 411 /**< RegEx device support UTF-8 character encoding. 412 * 413 * @see struct rte_regexdev_info::pcre_unsup_flags 414 */ 415 416 #define RTE_REGEXDEV_SUPP_PCRE_UTF_16_F (1ULL << 15) 417 /**< RegEx device support UTF-16 character encoding. 418 * 419 * @see struct rte_regexdev_info::regexdev_capa 420 */ 421 422 #define RTE_REGEXDEV_SUPP_PCRE_UTF_32_F (1ULL << 16) 423 /**< RegEx device support UTF-32 character encoding. 424 * 425 * @see struct rte_regexdev_info::regexdev_capa 426 */ 427 428 #define RTE_REGEXDEV_SUPP_PCRE_WORD_BOUNDARY_F (1ULL << 17) 429 /**< RegEx device support word boundaries. 430 * The meta character `\b` represents word boundary anchor. 431 * 432 * @see struct rte_regexdev_info::regexdev_capa 433 */ 434 435 #define RTE_REGEXDEV_SUPP_PCRE_FORWARD_REFERENCES_F (1ULL << 18) 436 /**< RegEx device support Forward references. 437 * Forward references allow you to use a back reference to a group that appears 438 * later in the RegEx. Example RegEx is `(\3ABC|(DEF|(GHI)))+` matches the 439 * following string `GHIGHIABCDEF`. 440 * 441 * @see struct rte_regexdev_info::regexdev_capa 442 */ 443 444 #define RTE_REGEXDEV_SUPP_MATCH_AS_END_F (1ULL << 19) 445 /**< RegEx device support match as end. 446 * Match as end means that the match result holds the end offset of the 447 * detected match. No len value is set. 448 * If the device doesn't support this feature it means the match 449 * result holds the starting position of match and the length of the match. 450 * 451 * @see struct rte_regexdev_info::regexdev_capa 452 */ 453 454 #define RTE_REGEXDEV_SUPP_CROSS_BUFFER_F (1ULL << 20) 455 /**< RegEx device support cross buffer match. 456 * Cross buffer matching means that the match can be detected even if the 457 * string was started in previous buffer. 458 * In case the device is configured as RTE_REGEXDEV_CFG_MATCH_AS_END 459 * the end offset will be relative for the first packet. 460 * For example RegEx is ABC the first buffer is xxxx second buffer yyyA and 461 * the last buffer BCzz. 462 * In case the match as end is configured the end offset will be 10. 463 * 464 * @see RTE_REGEXDEV_CFG_MATCH_AS_END_F 465 * @see RTE_REGEXDEV_CFG_CROSS_BUFFER_SCAN_F 466 * @see RTE_REGEX_OPS_RSP_PMI_SOJ_F 467 * @see RTE_REGEX_OPS_RSP_PMI_EOJ_F 468 */ 469 470 #define RTE_REGEXDEV_SUPP_MATCH_ALL_F (1ULL << 21) 471 /**< RegEx device support match all. 472 * Match all means that the RegEx engine will return all possible matches. 473 * For example, assume the RegEx is `A+b`, given the input AAAb the 474 * returned matches will be: Ab, AAb and AAAb. 475 * 476 * @see RTE_REGEXDEV_CFG_MATCH_ALL_F 477 */ 478 479 #define RTE_REGEXDEV_CAPA_QUEUE_PAIR_OOS_F (1ULL << 22) 480 /**< RegEx device supports out of order scan. 481 * Out of order scan means the response of a specific job can be returned as 482 * soon as it is ready even if previous jobs on the same queue didn't complete. 483 * 484 * @see RTE_REGEX_QUEUE_PAIR_CFG_OOS_F 485 * @see struct rte_regexdev_info::regexdev_capa 486 */ 487 488 /* Enumerates PCRE rule flags */ 489 #define RTE_REGEX_PCRE_RULE_ALLOW_EMPTY_F (1ULL << 0) 490 /**< When this flag is set, the pattern that can match against an empty string, 491 * such as `.*` are allowed. 492 * 493 * @see struct rte_regexdev_info::rule_flags 494 * @see struct rte_regexdev_rule::rule_flags 495 */ 496 497 #define RTE_REGEX_PCRE_RULE_ANCHORED_F (1ULL << 1) 498 /**< When this flag is set, the pattern is forced to be "anchored", that is, it 499 * is constrained to match only at the first matching point in the string that 500 * is being searched. Similar to `^` and represented by `\A`. 501 * 502 * @see struct rte_regexdev_info::rule_flags 503 * @see struct rte_regexdev_rule::rule_flags 504 */ 505 506 #define RTE_REGEX_PCRE_RULE_CASELESS_F (1ULL << 2) 507 /**< When this flag is set, letters in the pattern match both upper and lower 508 * case letters in the subject. 509 * 510 * @see struct rte_regexdev_info::rule_flags 511 * @see struct rte_regexdev_rule::rule_flags 512 */ 513 514 #define RTE_REGEX_PCRE_RULE_DOTALL_F (1ULL << 3) 515 /**< When this flag is set, a dot metacharacter in the pattern matches any 516 * character, including one that indicates a newline. 517 * 518 * @see struct rte_regexdev_info::rule_flags 519 * @see struct rte_regexdev_rule::rule_flags 520 */ 521 522 #define RTE_REGEX_PCRE_RULE_DUPNAMES_F (1ULL << 4) 523 /**< When this flag is set, names used to identify capture groups need not be 524 * unique. 525 * 526 * @see struct rte_regexdev_info::rule_flags 527 * @see struct rte_regexdev_rule::rule_flags 528 */ 529 530 #define RTE_REGEX_PCRE_RULE_EXTENDED_F (1ULL << 5) 531 /**< When this flag is set, most white space characters in the pattern are 532 * totally ignored except when escaped or inside a character class. 533 * 534 * @see struct rte_regexdev_info::rule_flags 535 * @see struct rte_regexdev_rule::rule_flags 536 */ 537 538 #define RTE_REGEX_PCRE_RULE_MATCH_UNSET_BACKREF_F (1ULL << 6) 539 /**< When this flag is set, a backreference to an unset capture group matches an 540 * empty string. 541 * 542 * @see struct rte_regexdev_info::rule_flags 543 * @see struct rte_regexdev_rule::rule_flags 544 */ 545 546 #define RTE_REGEX_PCRE_RULE_MULTILINE_F (1ULL << 7) 547 /**< When this flag is set, the `^` and `$` constructs match immediately 548 * following or immediately before internal newlines in the subject string, 549 * respectively, as well as at the very start and end. 550 * 551 * @see struct rte_regexdev_info::rule_flags 552 * @see struct rte_regexdev_rule::rule_flags 553 */ 554 555 #define RTE_REGEX_PCRE_RULE_NO_AUTO_CAPTURE_F (1ULL << 8) 556 /**< When this Flag is set, it disables the use of numbered capturing 557 * parentheses in the pattern. References to capture groups (backreferences or 558 * recursion/subroutine calls) may only refer to named groups, though the 559 * reference can be by name or by number. 560 * 561 * @see struct rte_regexdev_info::rule_flags 562 * @see struct rte_regexdev_rule::rule_flags 563 */ 564 565 #define RTE_REGEX_PCRE_RULE_UCP_F (1ULL << 9) 566 /**< By default, only ASCII characters are recognized, When this flag is set, 567 * Unicode properties are used instead to classify characters. 568 * 569 * @see struct rte_regexdev_info::rule_flags 570 * @see struct rte_regexdev_rule::rule_flags 571 */ 572 573 #define RTE_REGEX_PCRE_RULE_UNGREEDY_F (1ULL << 10) 574 /**< When this flag is set, the "greediness" of the quantifiers is inverted 575 * so that they are not greedy by default, but become greedy if followed by 576 * `?`. 577 * 578 * @see struct rte_regexdev_info::rule_flags 579 * @see struct rte_regexdev_rule::rule_flags 580 */ 581 582 #define RTE_REGEX_PCRE_RULE_UTF_F (1ULL << 11) 583 /**< When this flag is set, RegEx engine has to regard both the pattern and the 584 * subject strings that are subsequently processed as strings of UTF characters 585 * instead of single-code-unit strings. 586 * 587 * @see struct rte_regexdev_info::rule_flags 588 * @see struct rte_regexdev_rule::rule_flags 589 */ 590 591 #define RTE_REGEX_PCRE_RULE_NEVER_BACKSLASH_C_F (1ULL << 12) 592 /**< This flag locks out the use of `\C` in the pattern that is being compiled. 593 * This escape matches one data unit, even in UTF mode which can cause 594 * unpredictable behavior in UTF-8 or UTF-16 modes, because it may leave the 595 * current matching point in the mi:set hlsearchddle of a multi-code-unit 596 * character. 597 * 598 * @see struct rte_regexdev_info::rule_flags 599 * @see struct rte_regexdev_rule::rule_flags 600 */ 601 602 /** 603 * RegEx device information 604 */ 605 struct rte_regexdev_info { 606 const char *driver_name; /**< RegEx driver name. */ 607 struct rte_device *dev; /**< Device information. */ 608 uint16_t max_matches; 609 /**< Maximum matches per scan supported by this device. */ 610 uint16_t max_queue_pairs; 611 /**< Maximum queue pairs supported by this device. */ 612 uint16_t max_payload_size; 613 /**< Maximum payload size for a pattern match request or scan. 614 * @see RTE_REGEXDEV_CFG_CROSS_BUFFER_SCAN_F 615 */ 616 uint16_t max_segs; 617 /**< Maximum number of mbuf segments that can be chained together. */ 618 uint32_t max_rules_per_group; 619 /**< Maximum rules supported per group by this device. */ 620 uint16_t max_groups; 621 /**< Maximum groups supported by this device. */ 622 uint32_t regexdev_capa; 623 /**< RegEx device capabilities. @see RTE_REGEXDEV_CAPA_* */ 624 uint64_t rule_flags; 625 /**< Supported compiler rule flags. 626 * @see RTE_REGEX_PCRE_RULE_*, struct rte_regexdev_rule::rule_flags 627 */ 628 }; 629 630 /** 631 * @warning 632 * @b EXPERIMENTAL: this API may change without prior notice. 633 * 634 * Retrieve the contextual information of a RegEx device. 635 * 636 * @param dev_id 637 * The identifier of the device. 638 * 639 * @param[out] dev_info 640 * A pointer to a structure of type *rte_regexdev_info* to be filled with the 641 * contextual information of the device. 642 * 643 * @return 644 * - 0: Success, driver updates the contextual information of the RegEx device 645 * - <0: Error code returned by the driver info get function. 646 */ 647 __rte_experimental 648 int 649 rte_regexdev_info_get(uint8_t dev_id, struct rte_regexdev_info *dev_info); 650 651 /* Enumerates RegEx device configuration flags */ 652 #define RTE_REGEXDEV_CFG_CROSS_BUFFER_SCAN_F (1ULL << 0) 653 /**< Cross buffer scan refers to the ability to be able to detect 654 * matches that occur across buffer boundaries, where the buffers are related 655 * to each other in some way. Enable this flag when to scan payload size 656 * greater than struct rte_regexdev_info::max_payload_size and/or 657 * matches can present across scan buffer boundaries. 658 * 659 * @see struct rte_regexdev_info::max_payload_size 660 * @see struct rte_regexdev_config::dev_cfg_flags, rte_regexdev_configure() 661 * @see RTE_REGEX_OPS_RSP_PMI_SOJ_F 662 * @see RTE_REGEX_OPS_RSP_PMI_EOJ_F 663 */ 664 665 #define RTE_REGEXDEV_CFG_MATCH_AS_END_F (1ULL << 1) 666 /**< Match as end is the ability to return the result as ending offset. 667 * When this flag is set, the result for each match will hold the ending 668 * offset of the match in end_offset. 669 * If this flag is not set, then the match result will hold the starting offset 670 * in start_offset, and the length of the match in len. 671 * 672 * @see RTE_REGEXDEV_SUPP_MATCH_AS_END_F 673 */ 674 675 #define RTE_REGEXDEV_CFG_MATCH_ALL_F (1ULL << 2) 676 /**< Match all is the ability to return all possible results. 677 * 678 * @see RTE_REGEXDEV_SUPP_MATCH_ALL_F 679 */ 680 681 /** RegEx device configuration structure */ 682 struct rte_regexdev_config { 683 uint16_t nb_max_matches; 684 /**< Maximum matches per scan configured on this device. 685 * This value cannot exceed the *max_matches* 686 * which previously provided in rte_regexdev_info_get(). 687 * The value 0 is allowed, in which case, value 1 used. 688 * @see struct rte_regexdev_info::max_matches 689 */ 690 uint16_t nb_queue_pairs; 691 /**< Number of RegEx queue pairs to configure on this device. 692 * This value cannot exceed the *max_queue_pairs* which previously 693 * provided in rte_regexdev_info_get(). 694 * @see struct rte_regexdev_info::max_queue_pairs 695 */ 696 uint32_t nb_rules_per_group; 697 /**< Number of rules per group to configure on this device. 698 * This value cannot exceed the *max_rules_per_group* 699 * which previously provided in rte_regexdev_info_get(). 700 * The value 0 is allowed, in which case, 701 * struct rte_regexdev_info::max_rules_per_group used. 702 * @see struct rte_regexdev_info::max_rules_per_group 703 */ 704 uint16_t nb_groups; 705 /**< Number of groups to configure on this device. 706 * This value cannot exceed the *max_groups* 707 * which previously provided in rte_regexdev_info_get(). 708 * @see struct rte_regexdev_info::max_groups 709 */ 710 const char *rule_db; 711 /**< Import initial set of prebuilt rule database on this device. 712 * The value NULL is allowed, in which case, the device will not 713 * be configured prebuilt rule database. Application may use 714 * rte_regexdev_rule_db_update() or rte_regexdev_rule_db_import() API 715 * to update or import rule database after the 716 * rte_regexdev_configure(). 717 * @see rte_regexdev_rule_db_update(), rte_regexdev_rule_db_import() 718 */ 719 uint32_t rule_db_len; 720 /**< Length of *rule_db* buffer. */ 721 uint32_t dev_cfg_flags; 722 /**< RegEx device configuration flags, See RTE_REGEXDEV_CFG_* */ 723 }; 724 725 /** 726 * @warning 727 * @b EXPERIMENTAL: this API may change without prior notice. 728 * 729 * Configure a RegEx device. 730 * 731 * This function must be invoked first before any other function in the 732 * API. This function can also be re-invoked when a device is in the 733 * stopped state. 734 * 735 * The caller may use rte_regexdev_info_get() to get the capability of each 736 * resources available for this regex device. 737 * 738 * @param dev_id 739 * The identifier of the device to configure. 740 * @param cfg 741 * The RegEx device configuration structure. 742 * 743 * @return 744 * - 0: Success, device configured. Otherwise negative errno is returned. 745 */ 746 __rte_experimental 747 int 748 rte_regexdev_configure(uint8_t dev_id, const struct rte_regexdev_config *cfg); 749 750 /* Enumerates RegEx queue pair configuration flags */ 751 #define RTE_REGEX_QUEUE_PAIR_CFG_OOS_F (1ULL << 0) 752 /**< Out of order scan, If not set, a scan must retire after previously issued 753 * in-order scans to this queue pair. If set, this scan can be retired as soon 754 * as device returns completion. Application should not set out of order scan 755 * flag if it needs to maintain the ingress order of scan request. 756 * 757 * @see struct rte_regexdev_qp_conf::qp_conf_flags 758 * @see rte_regexdev_queue_pair_setup() 759 */ 760 761 struct rte_regex_ops; 762 typedef void (*regexdev_stop_flush_t)(uint8_t dev_id, uint16_t qp_id, 763 struct rte_regex_ops *op); 764 /**< Callback function called during rte_regexdev_stop(), invoked once per 765 * flushed RegEx op. 766 */ 767 768 /** RegEx queue pair configuration structure */ 769 struct rte_regexdev_qp_conf { 770 uint32_t qp_conf_flags; 771 /**< Queue pair config flags, See RTE_REGEX_QUEUE_PAIR_CFG_* */ 772 uint16_t nb_desc; 773 /**< The number of descriptors to allocate for this queue pair. */ 774 regexdev_stop_flush_t cb; 775 /**< Callback function called during rte_regexdev_stop(), invoked 776 * once per flushed regex op. Value NULL is allowed, in which case 777 * callback will not be invoked. This function can be used to properly 778 * dispose of outstanding regex ops from response queue, 779 * for example ops containing memory pointers. 780 * @see rte_regexdev_stop() 781 */ 782 }; 783 784 /** 785 * @warning 786 * @b EXPERIMENTAL: this API may change without prior notice. 787 * 788 * Allocate and set up a RegEx queue pair for a RegEx device. 789 * 790 * @param dev_id 791 * The identifier of the device. 792 * @param queue_pair_id 793 * The index of the RegEx queue pair to setup. The value must be in the range 794 * [0, nb_queue_pairs - 1] previously supplied to rte_regexdev_configure(). 795 * @param qp_conf 796 * The pointer to the configuration data to be used for the RegEx queue pair. 797 * NULL value is allowed, in which case default configuration used. 798 * 799 * @return 800 * 0 on success. Otherwise negative errno is returned. 801 */ 802 __rte_experimental 803 int 804 rte_regexdev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id, 805 const struct rte_regexdev_qp_conf *qp_conf); 806 807 /** 808 * @warning 809 * @b EXPERIMENTAL: this API may change without prior notice. 810 * 811 * Start a RegEx device. 812 * 813 * The device start step is the last one and consists of setting the RegEx 814 * queues to start accepting the pattern matching scan requests. 815 * 816 * On success, all basic functions exported by the API (RegEx enqueue, 817 * RegEx dequeue and so on) can be invoked. 818 * 819 * @param dev_id 820 * RegEx device identifier. 821 * 822 * @return 823 * 0 on success. Otherwise negative errno is returned. 824 */ 825 __rte_experimental 826 int 827 rte_regexdev_start(uint8_t dev_id); 828 829 /** 830 * @warning 831 * @b EXPERIMENTAL: this API may change without prior notice. 832 * 833 * Stop a RegEx device. 834 * 835 * Stop a RegEx device. The device can be restarted with a call to 836 * rte_regexdev_start(). 837 * 838 * This function causes all queued response regex ops to be drained in the 839 * response queue. While draining ops out of the device, 840 * struct rte_regexdev_qp_conf::cb will be invoked for each ops. 841 * 842 * @param dev_id 843 * RegEx device identifier. 844 * 845 * @return 846 * 0 on success. Otherwise negative errno is returned. 847 */ 848 __rte_experimental 849 int 850 rte_regexdev_stop(uint8_t dev_id); 851 852 /** 853 * @warning 854 * @b EXPERIMENTAL: this API may change without prior notice. 855 * 856 * Close a RegEx device. The device cannot be restarted! 857 * 858 * @param dev_id 859 * RegEx device identifier 860 * 861 * @return 862 * 0 on success. Otherwise negative errno is returned. 863 */ 864 __rte_experimental 865 int 866 rte_regexdev_close(uint8_t dev_id); 867 868 /* Device get/set attributes */ 869 870 /** Enumerates RegEx device attribute identifier */ 871 enum rte_regexdev_attr_id { 872 RTE_REGEXDEV_ATTR_SOCKET_ID, 873 /**< The NUMA socket id to which the device is connected or 874 * a default of zero if the socket could not be determined. 875 * datatype: *int* 876 * operation: *get* 877 */ 878 RTE_REGEXDEV_ATTR_MAX_MATCHES, 879 /**< Maximum number of matches per scan. 880 * datatype: *uint8_t* 881 * operation: *get* and *set* 882 * @see RTE_REGEX_OPS_RSP_MAX_MATCH_F 883 */ 884 RTE_REGEXDEV_ATTR_MAX_SCAN_TIMEOUT, 885 /**< Upper bound scan time in ns. 886 * datatype: *uint16_t* 887 * operation: *get* and *set* 888 * @see RTE_REGEX_OPS_RSP_MAX_SCAN_TIMEOUT_F 889 */ 890 RTE_REGEXDEV_ATTR_MAX_PREFIX, 891 /**< Maximum number of prefix detected per scan. 892 * This would be useful for denial of service detection. 893 * datatype: *uint16_t* 894 * operation: *get* and *set* 895 * @see RTE_REGEX_OPS_RSP_MAX_PREFIX_F 896 */ 897 }; 898 899 /** 900 * @warning 901 * @b EXPERIMENTAL: this API may change without prior notice. 902 * 903 * Get an attribute from a RegEx device. 904 * 905 * @param dev_id 906 * RegEx device identifier. 907 * @param attr_id 908 * The attribute ID to retrieve. 909 * @param attr_value 910 * A pointer that will be filled in with the attribute 911 * value if successful. 912 * 913 * @return 914 * - 0: Successfully retrieved attribute value. 915 * - -EINVAL: Invalid device or *attr_id* provided, or *attr_value* is NULL. 916 * - -ENOTSUP: if the device doesn't support specific *attr_id*. 917 */ 918 __rte_experimental 919 int 920 rte_regexdev_attr_get(uint8_t dev_id, enum rte_regexdev_attr_id attr_id, 921 void *attr_value); 922 923 /** 924 * @warning 925 * @b EXPERIMENTAL: this API may change without prior notice. 926 * 927 * Set an attribute to a RegEx device. 928 * 929 * @param dev_id 930 * RegEx device identifier. 931 * @param attr_id 932 * The attribute ID to retrieve. 933 * @param attr_value 934 * Pointer that will be filled in with the attribute value 935 * by the application. 936 * 937 * @return 938 * - 0: Successfully applied the attribute value. 939 * - -EINVAL: Invalid device or *attr_id* provided, or *attr_value* is NULL. 940 * - -ENOTSUP: if the device doesn't support specific *attr_id*. 941 */ 942 __rte_experimental 943 int 944 rte_regexdev_attr_set(uint8_t dev_id, enum rte_regexdev_attr_id attr_id, 945 const void *attr_value); 946 947 /* Rule related APIs */ 948 /** Enumerates RegEx rule operation. */ 949 enum rte_regexdev_rule_op { 950 RTE_REGEX_RULE_OP_ADD, 951 /**< Add RegEx rule to rule database. */ 952 RTE_REGEX_RULE_OP_REMOVE 953 /**< Remove RegEx rule from rule database. */ 954 }; 955 956 /** Structure to hold a RegEx rule attributes. */ 957 struct rte_regexdev_rule { 958 enum rte_regexdev_rule_op op; 959 /**< OP type of the rule either a OP_ADD or OP_DELETE. */ 960 uint16_t group_id; 961 /**< Group identifier to which the rule belongs to. */ 962 uint32_t rule_id; 963 /**< Rule identifier which is returned on successful match. */ 964 const char *pcre_rule; 965 /**< Buffer to hold the PCRE rule. */ 966 uint16_t pcre_rule_len; 967 /**< Length of the PCRE rule. */ 968 uint64_t rule_flags; 969 /* PCRE rule flags. Supported device specific PCRE rules enumerated 970 * in struct rte_regexdev_info::rule_flags. For successful rule 971 * database update, application needs to provide only supported 972 * rule flags. 973 * @See RTE_REGEX_PCRE_RULE_*, struct rte_regexdev_info::rule_flags 974 */ 975 }; 976 977 /** 978 * @warning 979 * @b EXPERIMENTAL: this API may change without prior notice. 980 * 981 * Update the local rule set. 982 * This functions only modify the rule set in memory. 983 * In order for the changes to take effect, the function 984 * rte_regexdev_rule_db_compile_active must be called. 985 * 986 * @param dev_id 987 * RegEx device identifier. 988 * @param rules 989 * Points to an array of *nb_rules* objects of type *rte_regexdev_rule* 990 * structure which contain the regex rules attributes to be updated 991 * in rule database. 992 * @param nb_rules 993 * The number of PCRE rules to update the rule database. 994 * 995 * @return 996 * The number of regex rules actually updated on the regex device's rule 997 * database. The return value can be less than the value of the *nb_rules* 998 * parameter when the regex devices fails to update the rule database or 999 * if invalid parameters are specified in a *rte_regexdev_rule*. 1000 * If the return value is less than *nb_rules*, the remaining PCRE rules 1001 * at the end of *rules* are not consumed and the caller has to take 1002 * care of them and rte_errno is set accordingly. 1003 * Possible errno values include: 1004 * - -EINVAL: Invalid device ID or rules is NULL 1005 * - -ENOTSUP: The last processed rule is not supported on this device. 1006 * - -ENOSPC: No space available in rule database. 1007 * 1008 * @see rte_regexdev_rule_db_import(), rte_regexdev_rule_db_export(), 1009 * rte_regexdev_rule_db_compile_activate() 1010 */ 1011 __rte_experimental 1012 int 1013 rte_regexdev_rule_db_update(uint8_t dev_id, 1014 const struct rte_regexdev_rule *rules, 1015 uint32_t nb_rules); 1016 1017 /** 1018 * @warning 1019 * @b EXPERIMENTAL: this API may change without prior notice. 1020 * 1021 * Compile local rule set and burn the complied result to the 1022 * RegEx device. 1023 * 1024 * @param dev_id 1025 * RegEx device identifier. 1026 * 1027 * @return 1028 * 0 on success, otherwise negative errno. 1029 * 1030 * @see rte_regexdev_rule_db_import(), rte_regexdev_rule_db_export(), 1031 * rte_regexdev_rule_db_update() 1032 */ 1033 __rte_experimental 1034 int 1035 rte_regexdev_rule_db_compile_activate(uint8_t dev_id); 1036 1037 /** 1038 * @warning 1039 * @b EXPERIMENTAL: this API may change without prior notice. 1040 * 1041 * Import a prebuilt rule database from a buffer to a RegEx device. 1042 * 1043 * @param dev_id 1044 * RegEx device identifier. 1045 * @param rule_db 1046 * Points to prebuilt rule database. 1047 * @param rule_db_len 1048 * Length of the rule database. 1049 * 1050 * @return 1051 * - 0: Successfully updated the prebuilt rule database. 1052 * - -EINVAL: Invalid device ID or rule_db is NULL 1053 * - -ENOTSUP: Rule database import is not supported on this device. 1054 * - -ENOSPC: No space available in rule database. 1055 * 1056 * @see rte_regexdev_rule_db_update(), rte_regexdev_rule_db_export() 1057 */ 1058 __rte_experimental 1059 int 1060 rte_regexdev_rule_db_import(uint8_t dev_id, const char *rule_db, 1061 uint32_t rule_db_len); 1062 1063 /** 1064 * @warning 1065 * @b EXPERIMENTAL: this API may change without prior notice. 1066 * 1067 * Export the prebuilt rule database from a RegEx device to the buffer. 1068 * 1069 * @param dev_id 1070 * RegEx device identifier. 1071 * @param[out] rule_db 1072 * Block of memory to insert the rule database. Must be at least size in 1073 * capacity. If set to NULL, function returns required capacity. 1074 * 1075 * @return 1076 * - 0: Successfully exported the prebuilt rule database. 1077 * - size: If rule_db set to NULL then required capacity for *rule_db* 1078 * - -EINVAL: Invalid device ID 1079 * - -ENOTSUP: Rule database export is not supported on this device. 1080 * 1081 * @see rte_regexdev_rule_db_update(), rte_regexdev_rule_db_import() 1082 */ 1083 __rte_experimental 1084 int 1085 rte_regexdev_rule_db_export(uint8_t dev_id, char *rule_db); 1086 1087 /* Extended statistics */ 1088 /** Maximum name length for extended statistics counters */ 1089 #define RTE_REGEXDEV_XSTATS_NAME_SIZE 64 1090 1091 /** 1092 * A name-key lookup element for extended statistics. 1093 * 1094 * This structure is used to map between names and ID numbers 1095 * for extended RegEx device statistics. 1096 */ 1097 struct rte_regexdev_xstats_map { 1098 uint16_t id; 1099 /**< xstat identifier */ 1100 char name[RTE_REGEXDEV_XSTATS_NAME_SIZE]; 1101 /**< xstat name */ 1102 }; 1103 1104 /** 1105 * @warning 1106 * @b EXPERIMENTAL: this API may change without prior notice. 1107 * 1108 * Retrieve names of extended statistics of a regex device. 1109 * 1110 * @param dev_id 1111 * The identifier of the regex device. 1112 * @param[out] xstats_map 1113 * Block of memory to insert id and names into. Must be at least size in 1114 * capacity. If set to NULL, function returns required capacity. 1115 * @return 1116 * - Positive value on success: 1117 * -The return value is the number of entries filled in the stats map. 1118 * -If xstats_map set to NULL then required capacity for xstats_map. 1119 * - Negative value on error: 1120 * -ENODEV for invalid *dev_id* 1121 * -ENOTSUP if the device doesn't support this function. 1122 */ 1123 __rte_experimental 1124 int 1125 rte_regexdev_xstats_names_get(uint8_t dev_id, 1126 struct rte_regexdev_xstats_map *xstats_map); 1127 1128 /** 1129 * @warning 1130 * @b EXPERIMENTAL: this API may change without prior notice. 1131 * 1132 * Retrieve extended statistics of an regex device. 1133 * 1134 * @param dev_id 1135 * The identifier of the device. 1136 * @param ids 1137 * The id numbers of the stats to get. The ids can be got from the stat 1138 * position in the stat list from rte_regexdev_xstats_names_get(), or 1139 * by using rte_regexdev_xstats_by_name_get(). 1140 * @param values 1141 * The values for each stats request by ID. 1142 * @param nb_values 1143 * The number of stats requested. 1144 * @return 1145 * - Positive value: number of stat entries filled into the values array 1146 * - Negative value on error: 1147 * -ENODEV for invalid *dev_id* 1148 * -ENOTSUP if the device doesn't support this function. 1149 */ 1150 __rte_experimental 1151 int 1152 rte_regexdev_xstats_get(uint8_t dev_id, const uint16_t *ids, 1153 uint64_t *values, uint16_t nb_values); 1154 1155 /** 1156 * @warning 1157 * @b EXPERIMENTAL: this API may change without prior notice. 1158 * 1159 * Retrieve the value of a single stat by requesting it by name. 1160 * 1161 * @param dev_id 1162 * The identifier of the device. 1163 * @param name 1164 * The stat name to retrieve. 1165 * @param id 1166 * If non-NULL, the numerical id of the stat will be returned, so that further 1167 * requests for the stat can be got using rte_regexdev_xstats_get, which will 1168 * be faster as it doesn't need to scan a list of names for the stat. 1169 * @param[out] value 1170 * Must be non-NULL, retrieved xstat value will be stored in this address. 1171 * 1172 * @return 1173 * - 0: Successfully retrieved xstat value. 1174 * - -EINVAL: invalid parameters 1175 * - -ENOTSUP: if not supported. 1176 */ 1177 __rte_experimental 1178 int 1179 rte_regexdev_xstats_by_name_get(uint8_t dev_id, const char *name, 1180 uint16_t *id, uint64_t *value); 1181 1182 /** 1183 * @warning 1184 * @b EXPERIMENTAL: this API may change without prior notice. 1185 * 1186 * Reset the values of the xstats of the selected component in the device. 1187 * 1188 * @param dev_id 1189 * The identifier of the device. 1190 * @param ids 1191 * Selects specific statistics to be reset. When NULL, all statistics will be 1192 * reset. If non-NULL, must point to array of at least *nb_ids* size. 1193 * @param nb_ids 1194 * The number of ids available from the *ids* array. Ignored when ids is NULL. 1195 * 1196 * @return 1197 * - 0: Successfully reset the statistics to zero. 1198 * - -EINVAL: invalid parameters. 1199 * - -ENOTSUP: if not supported. 1200 */ 1201 __rte_experimental 1202 int 1203 rte_regexdev_xstats_reset(uint8_t dev_id, const uint16_t *ids, 1204 uint16_t nb_ids); 1205 1206 /** 1207 * @warning 1208 * @b EXPERIMENTAL: this API may change without prior notice. 1209 * 1210 * Trigger the RegEx device self test. 1211 * 1212 * @param dev_id 1213 * The identifier of the device. 1214 * @return 1215 * - 0: Selftest successful. 1216 * - -ENOTSUP if the device doesn't support selftest. 1217 * - other values < 0 on failure. 1218 */ 1219 __rte_experimental 1220 int 1221 rte_regexdev_selftest(uint8_t dev_id); 1222 1223 /** 1224 * @warning 1225 * @b EXPERIMENTAL: this API may change without prior notice. 1226 * 1227 * Dump internal information about *dev_id* to the FILE* provided in *f*. 1228 * 1229 * @param dev_id 1230 * The identifier of the device. 1231 * @param f 1232 * A pointer to a file for output. 1233 * 1234 * @return 1235 * 0 on success, negative errno on failure. 1236 */ 1237 __rte_experimental 1238 int 1239 rte_regexdev_dump(uint8_t dev_id, FILE *f); 1240 1241 /* Fast path APIs */ 1242 1243 /** 1244 * The generic *rte_regexdev_match* structure to hold the RegEx match 1245 * attributes. 1246 * @see struct rte_regex_ops::matches 1247 */ 1248 struct rte_regexdev_match { 1249 RTE_STD_C11 1250 union { 1251 uint64_t u64; 1252 struct { 1253 uint32_t rule_id:20; 1254 /**< Rule identifier to which the pattern matched. 1255 * @see struct rte_regexdev_rule::rule_id 1256 */ 1257 uint32_t group_id:12; 1258 /**< Group identifier of the rule which the pattern 1259 * matched. @see struct rte_regexdev_rule::group_id 1260 */ 1261 uint16_t start_offset; 1262 /**< Starting Byte Position for matched rule. */ 1263 RTE_STD_C11 1264 union { 1265 uint16_t len; 1266 /**< Length of match in bytes */ 1267 uint16_t end_offset; 1268 /**< The end offset of the match. In case 1269 * MATCH_AS_END configuration is enabled. 1270 * @see RTE_REGEXDEV_CFG_MATCH_AS_END 1271 */ 1272 }; 1273 }; 1274 }; 1275 }; 1276 1277 /* Enumerates RegEx request flags. */ 1278 #define RTE_REGEX_OPS_REQ_GROUP_ID0_VALID_F (1 << 0) 1279 /**< Set when struct rte_regexdev_rule::group_id0 is valid. */ 1280 1281 #define RTE_REGEX_OPS_REQ_GROUP_ID1_VALID_F (1 << 1) 1282 /**< Set when struct rte_regexdev_rule::group_id1 is valid. */ 1283 1284 #define RTE_REGEX_OPS_REQ_GROUP_ID2_VALID_F (1 << 2) 1285 /**< Set when struct rte_regexdev_rule::group_id2 is valid. */ 1286 1287 #define RTE_REGEX_OPS_REQ_GROUP_ID3_VALID_F (1 << 3) 1288 /**< Set when struct rte_regexdev_rule::group_id3 is valid. */ 1289 1290 #define RTE_REGEX_OPS_REQ_STOP_ON_MATCH_F (1 << 4) 1291 /**< The RegEx engine will stop scanning and return the first match. */ 1292 1293 #define RTE_REGEX_OPS_REQ_MATCH_HIGH_PRIORITY_F (1 << 5) 1294 /**< In High Priority mode a maximum of one match will be returned per scan to 1295 * reduce the post-processing required by the application. The match with the 1296 * lowest Rule id, lowest start pointer and lowest match length will be 1297 * returned. 1298 * 1299 * @see struct rte_regex_ops::nb_actual_matches 1300 * @see struct rte_regex_ops::nb_matches 1301 */ 1302 1303 1304 /* Enumerates RegEx response flags. */ 1305 #define RTE_REGEX_OPS_RSP_PMI_SOJ_F (1 << 0) 1306 /**< Indicates that the RegEx device has encountered a partial match at the 1307 * start of scan in the given buffer. 1308 * 1309 * @see RTE_REGEXDEV_CFG_CROSS_BUFFER_SCAN_F 1310 */ 1311 1312 #define RTE_REGEX_OPS_RSP_PMI_EOJ_F (1 << 1) 1313 /**< Indicates that the RegEx device has encountered a partial match at the 1314 * end of scan in the given buffer. 1315 * 1316 * @see RTE_REGEXDEV_CFG_CROSS_BUFFER_SCAN_F 1317 */ 1318 1319 #define RTE_REGEX_OPS_RSP_MAX_SCAN_TIMEOUT_F (1 << 2) 1320 /**< Indicates that the RegEx device has exceeded the max timeout while 1321 * scanning the given buffer. 1322 * 1323 * @see RTE_REGEXDEV_ATTR_MAX_SCAN_TIMEOUT 1324 */ 1325 1326 #define RTE_REGEX_OPS_RSP_MAX_MATCH_F (1 << 3) 1327 /**< Indicates that the RegEx device has exceeded the max matches while 1328 * scanning the given buffer. 1329 * 1330 * @see RTE_REGEXDEV_ATTR_MAX_MATCHES 1331 */ 1332 1333 #define RTE_REGEX_OPS_RSP_MAX_PREFIX_F (1 << 4) 1334 /**< Indicates that the RegEx device has reached the max allowed prefix length 1335 * while scanning the given buffer. 1336 * 1337 * @see RTE_REGEXDEV_ATTR_MAX_PREFIX 1338 */ 1339 1340 #define RTE_REGEX_OPS_RSP_RESOURCE_LIMIT_REACHED_F (1 << 4) 1341 /**< Indicates that the RegEx device has reached the max allowed resource 1342 * allowed while scanning the given buffer. 1343 */ 1344 1345 /** 1346 * The generic *rte_regex_ops* structure to hold the RegEx attributes 1347 * for enqueue and dequeue operation. 1348 */ 1349 struct rte_regex_ops { 1350 /* W0 */ 1351 uint16_t req_flags; 1352 /**< Request flags for the RegEx ops. 1353 * @see RTE_REGEX_OPS_REQ_* 1354 */ 1355 uint16_t rsp_flags; 1356 /**< Response flags for the RegEx ops. 1357 * @see RTE_REGEX_OPS_RSP_* 1358 */ 1359 uint16_t nb_actual_matches; 1360 /**< The total number of actual matches detected by the Regex device.*/ 1361 uint16_t nb_matches; 1362 /**< The total number of matches returned by the RegEx device for this 1363 * scan. The size of *rte_regex_ops::matches* zero length array will be 1364 * this value. 1365 * 1366 * @see struct rte_regex_ops::matches, struct rte_regexdev_match 1367 */ 1368 1369 /* W1 */ 1370 struct rte_mbuf *mbuf; /**< source mbuf, to search in. */ 1371 1372 /* W2 */ 1373 uint16_t group_id0; 1374 /**< First group_id to match the rule against. At minimum one group 1375 * should be valid. Behaviour is undefined non of the groups are valid. 1376 * 1377 * @see RTE_REGEX_OPS_REQ_GROUP_ID0_VALID_F 1378 */ 1379 uint16_t group_id1; 1380 /**< Second group_id to match the rule against. 1381 * 1382 * @see RTE_REGEX_OPS_REQ_GROUP_ID1_VALID_F 1383 */ 1384 uint16_t group_id2; 1385 /**< Third group_id to match the rule against. 1386 * 1387 * @see RTE_REGEX_OPS_REQ_GROUP_ID2_VALID_F 1388 */ 1389 uint16_t group_id3; 1390 /**< Forth group_id to match the rule against. 1391 * 1392 * @see RTE_REGEX_OPS_REQ_GROUP_ID3_VALID_F 1393 */ 1394 1395 /* W3 */ 1396 RTE_STD_C11 1397 union { 1398 uint64_t user_id; 1399 /**< Application specific opaque value. An application may use 1400 * this field to hold application specific value to share 1401 * between dequeue and enqueue operation. 1402 * Implementation should not modify this field. 1403 */ 1404 void *user_ptr; 1405 /**< Pointer representation of *user_id* */ 1406 }; 1407 1408 /* W4 */ 1409 RTE_STD_C11 1410 union { 1411 uint64_t cross_buf_id; 1412 /**< ID used by the RegEx device in order to support cross 1413 * packet detection. 1414 * This ID is returned from the RegEx device on the dequeue 1415 * function. The application must send it back when calling 1416 * enqueue with the following packet. 1417 */ 1418 void *cross_buf_ptr; 1419 /**< Pointer representation of *corss_buf_id* */ 1420 }; 1421 1422 /* W5 */ 1423 struct rte_regexdev_match matches[]; 1424 /**< Zero length array to hold the match tuples. 1425 * The struct rte_regex_ops::nb_matches value holds the number of 1426 * elements in this array. 1427 * 1428 * @see struct rte_regex_ops::nb_matches 1429 */ 1430 }; 1431 1432 #include "rte_regexdev_core.h" 1433 1434 /** 1435 * @warning 1436 * @b EXPERIMENTAL: this API may change without prior notice. 1437 * 1438 * Enqueue a burst of scan request on a RegEx device. 1439 * 1440 * The rte_regexdev_enqueue_burst() function is invoked to place 1441 * regex operations on the queue *qp_id* of the device designated by 1442 * its *dev_id*. 1443 * 1444 * The *nb_ops* parameter is the number of operations to process which are 1445 * supplied in the *ops* array of *rte_regexdev_op* structures. 1446 * 1447 * The rte_regexdev_enqueue_burst() function returns the number of 1448 * operations it actually enqueued for processing. A return value equal to 1449 * *nb_ops* means that all packets have been enqueued. 1450 * 1451 * @param dev_id 1452 * The identifier of the device. 1453 * @param qp_id 1454 * The index of the queue pair which packets are to be enqueued for 1455 * processing. The value must be in the range [0, nb_queue_pairs - 1] 1456 * previously supplied to rte_regexdev_configure(). 1457 * @param ops 1458 * The address of an array of *nb_ops* pointers to *rte_regexdev_op* 1459 * structures which contain the regex operations to be processed. 1460 * @param nb_ops 1461 * The number of operations to process. 1462 * 1463 * @return 1464 * The number of operations actually enqueued on the regex device. The return 1465 * value can be less than the value of the *nb_ops* parameter when the 1466 * regex devices queue is full or if invalid parameters are specified in 1467 * a *rte_regexdev_op*. If the return value is less than *nb_ops*, the 1468 * remaining ops at the end of *ops* are not consumed and the caller has 1469 * to take care of them. 1470 */ 1471 __rte_experimental 1472 static inline uint16_t 1473 rte_regexdev_enqueue_burst(uint8_t dev_id, uint16_t qp_id, 1474 struct rte_regex_ops **ops, uint16_t nb_ops) 1475 { 1476 struct rte_regexdev *dev = &rte_regex_devices[dev_id]; 1477 #ifdef RTE_LIBRTE_REGEXDEV_DEBUG 1478 RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL); 1479 if (*dev->enqueue == NULL) 1480 return -ENOTSUP; 1481 if (qp_id >= dev->data->dev_conf.nb_queue_pairs) { 1482 RTE_REGEXDEV_LOG(ERR, "Invalid queue %d\n", qp_id); 1483 return -EINVAL; 1484 } 1485 #endif 1486 return (*dev->enqueue)(dev, qp_id, ops, nb_ops); 1487 } 1488 1489 /** 1490 * @warning 1491 * @b EXPERIMENTAL: this API may change without prior notice. 1492 * 1493 * Dequeue a burst of scan response from a queue on the RegEx device. 1494 * The dequeued operation are stored in *rte_regexdev_op* structures 1495 * whose pointers are supplied in the *ops* array. 1496 * 1497 * The rte_regexdev_dequeue_burst() function returns the number of ops 1498 * actually dequeued, which is the number of *rte_regexdev_op* data structures 1499 * effectively supplied into the *ops* array. 1500 * 1501 * A return value equal to *nb_ops* indicates that the queue contained 1502 * at least *nb_ops* operations, and this is likely to signify that other 1503 * processed operations remain in the devices output queue. Applications 1504 * implementing a "retrieve as many processed operations as possible" policy 1505 * can check this specific case and keep invoking the 1506 * rte_regexdev_dequeue_burst() function until a value less than 1507 * *nb_ops* is returned. 1508 * 1509 * The rte_regexdev_dequeue_burst() function does not provide any error 1510 * notification to avoid the corresponding overhead. 1511 * 1512 * @param dev_id 1513 * The RegEx device identifier 1514 * @param qp_id 1515 * The index of the queue pair from which to retrieve processed packets. 1516 * The value must be in the range [0, nb_queue_pairs - 1] previously 1517 * supplied to rte_regexdev_configure(). 1518 * @param ops 1519 * The address of an array of pointers to *rte_regexdev_op* structures 1520 * that must be large enough to store *nb_ops* pointers in it. 1521 * @param nb_ops 1522 * The maximum number of operations to dequeue. 1523 * 1524 * @return 1525 * The number of operations actually dequeued, which is the number 1526 * of pointers to *rte_regexdev_op* structures effectively supplied to the 1527 * *ops* array. If the return value is less than *nb_ops*, the remaining 1528 * ops at the end of *ops* are not consumed and the caller has to take care 1529 * of them. 1530 */ 1531 __rte_experimental 1532 static inline uint16_t 1533 rte_regexdev_dequeue_burst(uint8_t dev_id, uint16_t qp_id, 1534 struct rte_regex_ops **ops, uint16_t nb_ops) 1535 { 1536 struct rte_regexdev *dev = &rte_regex_devices[dev_id]; 1537 #ifdef RTE_LIBRTE_REGEXDEV_DEBUG 1538 RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL); 1539 if (*dev->dequeue == NULL) 1540 return -ENOTSUP; 1541 if (qp_id >= dev->data->dev_conf.nb_queue_pairs) { 1542 RTE_REGEXDEV_LOG(ERR, "Invalid queue %d\n", qp_id); 1543 return -EINVAL; 1544 } 1545 #endif 1546 return (*dev->dequeue)(dev, qp_id, ops, nb_ops); 1547 } 1548 1549 #ifdef __cplusplus 1550 } 1551 #endif 1552 1553 #endif /* _RTE_REGEXDEV_H_ */ 1554