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