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