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