xref: /dpdk/lib/regexdev/rte_regexdev.h (revision 97433132c2edda70ff69843b8f9273853cac984c)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(C) 2019 Marvell International Ltd.
399a2dd95SBruce Richardson  * Copyright 2020 Mellanox Technologies, Ltd
499a2dd95SBruce Richardson  * Copyright(c) 2020 Intel Corporation
599a2dd95SBruce Richardson  */
699a2dd95SBruce Richardson 
799a2dd95SBruce Richardson #ifndef _RTE_REGEXDEV_H_
899a2dd95SBruce Richardson #define _RTE_REGEXDEV_H_
999a2dd95SBruce Richardson 
1099a2dd95SBruce Richardson /**
1199a2dd95SBruce Richardson  * @file
1299a2dd95SBruce Richardson  *
1399a2dd95SBruce Richardson  * RTE RegEx Device API
1499a2dd95SBruce Richardson  *
1599a2dd95SBruce Richardson  * Defines RTE RegEx Device APIs for RegEx operations and its provisioning.
1699a2dd95SBruce Richardson  *
1799a2dd95SBruce Richardson  * The RegEx Device API is composed of two parts:
1899a2dd95SBruce Richardson  *
1999a2dd95SBruce Richardson  * - The application-oriented RegEx API that includes functions to setup
2099a2dd95SBruce Richardson  *   a RegEx device (configure it, setup its queue pairs and start it),
2199a2dd95SBruce Richardson  *   update the rule database and so on.
2299a2dd95SBruce Richardson  *
2399a2dd95SBruce Richardson  * - The driver-oriented RegEx API that exports a function allowing
2499a2dd95SBruce Richardson  *   a RegEx poll Mode Driver (PMD) to simultaneously register itself as
2599a2dd95SBruce Richardson  *   a RegEx device driver.
2699a2dd95SBruce Richardson  *
2799a2dd95SBruce Richardson  * RegEx device components and definitions:
2899a2dd95SBruce Richardson  *
2999a2dd95SBruce Richardson  *     +-----------------+
3099a2dd95SBruce Richardson  *     |                 |
3199a2dd95SBruce Richardson  *     |                 o---------+    rte_regexdev_[en|de]queue_burst()
3299a2dd95SBruce Richardson  *     |   PCRE based    o------+  |               |
3399a2dd95SBruce Richardson  *     |  RegEx pattern  |      |  |  +--------+   |
3499a2dd95SBruce Richardson  *     | matching engine o------+--+--o        |   |    +------+
3599a2dd95SBruce Richardson  *     |                 |      |  |  | queue  |<==o===>|Core 0|
3699a2dd95SBruce Richardson  *     |                 o----+ |  |  | pair 0 |        |      |
3799a2dd95SBruce Richardson  *     |                 |    | |  |  +--------+        +------+
3899a2dd95SBruce Richardson  *     +-----------------+    | |  |
3999a2dd95SBruce Richardson  *            ^               | |  |  +--------+
4099a2dd95SBruce Richardson  *            |               | |  |  |        |        +------+
4199a2dd95SBruce Richardson  *            |               | +--+--o queue  |<======>|Core 1|
4299a2dd95SBruce Richardson  *        Rule|Database       |    |  | pair 1 |        |      |
4399a2dd95SBruce Richardson  *     +------+----------+    |    |  +--------+        +------+
4499a2dd95SBruce Richardson  *     |     Group 0     |    |    |
4599a2dd95SBruce Richardson  *     | +-------------+ |    |    |  +--------+        +------+
4699a2dd95SBruce Richardson  *     | | Rules 0..n  | |    |    |  |        |        |Core 2|
4799a2dd95SBruce Richardson  *     | +-------------+ |    |    +--o queue  |<======>|      |
4899a2dd95SBruce Richardson  *     |     Group 1     |    |       | pair 2 |        +------+
4999a2dd95SBruce Richardson  *     | +-------------+ |    |       +--------+
5099a2dd95SBruce Richardson  *     | | Rules 0..n  | |    |
5199a2dd95SBruce Richardson  *     | +-------------+ |    |       +--------+
5299a2dd95SBruce Richardson  *     |     Group 2     |    |       |        |        +------+
5399a2dd95SBruce Richardson  *     | +-------------+ |    |       | queue  |<======>|Core n|
5499a2dd95SBruce Richardson  *     | | Rules 0..n  | |    +-------o pair n |        |      |
5599a2dd95SBruce Richardson  *     | +-------------+ |            +--------+        +------+
5699a2dd95SBruce Richardson  *     |     Group n     |
5799a2dd95SBruce Richardson  *     | +-------------+ |<-------rte_regexdev_rule_db_update()
5899a2dd95SBruce Richardson  *     | |             | |<-------rte_regexdev_rule_db_compile_activate()
5999a2dd95SBruce Richardson  *     | | Rules 0..n  | |<-------rte_regexdev_rule_db_import()
6099a2dd95SBruce Richardson  *     | +-------------+ |------->rte_regexdev_rule_db_export()
6199a2dd95SBruce Richardson  *     +-----------------+
6299a2dd95SBruce Richardson  *
6399a2dd95SBruce Richardson  * RegEx: A regular expression is a concise and flexible means for matching
6499a2dd95SBruce Richardson  * strings of text, such as particular characters, words, or patterns of
6599a2dd95SBruce Richardson  * characters. A common abbreviation for this is “RegEx”.
6699a2dd95SBruce Richardson  *
6799a2dd95SBruce Richardson  * RegEx device: A hardware or software-based implementation of RegEx
6899a2dd95SBruce Richardson  * device API for PCRE based pattern matching syntax and semantics.
6999a2dd95SBruce Richardson  *
7099a2dd95SBruce Richardson  * PCRE RegEx syntax and semantics specification:
7199a2dd95SBruce Richardson  * http://regexkit.sourceforge.net/Documentation/pcre/pcrepattern.html
7299a2dd95SBruce Richardson  *
7399a2dd95SBruce Richardson  * RegEx queue pair: Each RegEx device should have one or more queue pair to
7499a2dd95SBruce Richardson  * transmit a burst of pattern matching request and receive a burst of
7599a2dd95SBruce Richardson  * receive the pattern matching response. The pattern matching request/response
7699a2dd95SBruce Richardson  * embedded in *rte_regex_ops* structure.
7799a2dd95SBruce Richardson  *
7899a2dd95SBruce Richardson  * Rule: A pattern matching rule expressed in PCRE RegEx syntax along with
7999a2dd95SBruce Richardson  * Match ID and Group ID to identify the rule upon the match.
8099a2dd95SBruce Richardson  *
8199a2dd95SBruce Richardson  * Rule database: The RegEx device accepts regular expressions and converts them
8299a2dd95SBruce Richardson  * into a compiled rule database that can then be used to scan data.
8399a2dd95SBruce Richardson  * Compilation allows the device to analyze the given pattern(s) and
8499a2dd95SBruce Richardson  * pre-determine how to scan for these patterns in an optimized fashion that
8599a2dd95SBruce Richardson  * would be far too expensive to compute at run-time. A rule database contains
8699a2dd95SBruce Richardson  * a set of rules that compiled in device specific binary form.
8799a2dd95SBruce Richardson  *
8899a2dd95SBruce Richardson  * Match ID or Rule ID: A unique identifier provided at the time of rule
8999a2dd95SBruce Richardson  * creation for the application to identify the rule upon match.
9099a2dd95SBruce Richardson  *
9199a2dd95SBruce Richardson  * Group ID: Group of rules can be grouped under one group ID to enable
9299a2dd95SBruce Richardson  * rule isolation and effective pattern matching. A unique group identifier
9399a2dd95SBruce Richardson  * provided at the time of rule creation for the application to identify the
9499a2dd95SBruce Richardson  * rule upon match.
9599a2dd95SBruce Richardson  *
9699a2dd95SBruce Richardson  * Scan: A pattern matching request through *enqueue* API.
9799a2dd95SBruce Richardson  *
9899a2dd95SBruce Richardson  * It may possible that a given RegEx device may not support all the features
9999a2dd95SBruce Richardson  * of PCRE. The application may probe unsupported features through
10099a2dd95SBruce Richardson  * struct rte_regexdev_info::pcre_unsup_flags
10199a2dd95SBruce Richardson  *
10299a2dd95SBruce Richardson  * By default, all the functions of the RegEx Device API exported by a PMD
10399a2dd95SBruce Richardson  * are lock-free functions which assume to not be invoked in parallel on
10499a2dd95SBruce Richardson  * different logical cores to work on the same target object. For instance,
10599a2dd95SBruce Richardson  * the dequeue function of a PMD cannot be invoked in parallel on two logical
10699a2dd95SBruce Richardson  * cores to operates on same RegEx queue pair. Of course, this function
10799a2dd95SBruce Richardson  * can be invoked in parallel by different logical core on different queue pair.
10899a2dd95SBruce Richardson  * It is the responsibility of the upper level application to enforce this rule.
10999a2dd95SBruce Richardson  *
11099a2dd95SBruce Richardson  * In all functions of the RegEx API, the RegEx device is
11199a2dd95SBruce Richardson  * designated by an integer >= 0 named the device identifier *dev_id*
11299a2dd95SBruce Richardson  *
11399a2dd95SBruce Richardson  * At the RegEx driver level, RegEx devices are represented by a generic
11499a2dd95SBruce Richardson  * data structure of type *rte_regexdev*.
11599a2dd95SBruce Richardson  *
11699a2dd95SBruce Richardson  * RegEx devices are dynamically registered during the PCI/SoC device probing
11799a2dd95SBruce Richardson  * phase performed at EAL initialization time.
11899a2dd95SBruce Richardson  * When a RegEx device is being probed, a *rte_regexdev* structure and
11999a2dd95SBruce Richardson  * a new device identifier are allocated for that device. Then, the
12099a2dd95SBruce Richardson  * regexdev_init() function supplied by the RegEx driver matching the probed
12199a2dd95SBruce Richardson  * device is invoked to properly initialize the device.
12299a2dd95SBruce Richardson  *
12399a2dd95SBruce Richardson  * The role of the device init function consists of resetting the hardware or
12499a2dd95SBruce Richardson  * software RegEx driver implementations.
12599a2dd95SBruce Richardson  *
12699a2dd95SBruce Richardson  * If the device init operation is successful, the correspondence between
12799a2dd95SBruce Richardson  * the device identifier assigned to the new device and its associated
12899a2dd95SBruce Richardson  * *rte_regexdev* structure is effectively registered.
12999a2dd95SBruce Richardson  * Otherwise, both the *rte_regexdev* structure and the device identifier are
13099a2dd95SBruce Richardson  * freed.
13199a2dd95SBruce Richardson  *
13299a2dd95SBruce Richardson  * The functions exported by the application RegEx API to setup a device
13399a2dd95SBruce Richardson  * designated by its device identifier must be invoked in the following order:
13499a2dd95SBruce Richardson  *     - rte_regexdev_configure()
13599a2dd95SBruce Richardson  *     - rte_regexdev_queue_pair_setup()
13699a2dd95SBruce Richardson  *     - rte_regexdev_start()
13799a2dd95SBruce Richardson  *
13899a2dd95SBruce Richardson  * Then, the application can invoke, in any order, the functions
13999a2dd95SBruce Richardson  * exported by the RegEx API to enqueue pattern matching job, dequeue pattern
14099a2dd95SBruce Richardson  * matching response, get the stats, update the rule database,
14199a2dd95SBruce Richardson  * get/set device attributes and so on
14299a2dd95SBruce Richardson  *
14399a2dd95SBruce Richardson  * If the application wants to change the configuration (i.e. call
14499a2dd95SBruce Richardson  * rte_regexdev_configure() or rte_regexdev_queue_pair_setup()), it must call
14599a2dd95SBruce Richardson  * rte_regexdev_stop() first to stop the device and then do the reconfiguration
14699a2dd95SBruce Richardson  * before calling rte_regexdev_start() again. The enqueue and dequeue
14799a2dd95SBruce Richardson  * functions should not be invoked when the device is stopped.
14899a2dd95SBruce Richardson  *
14999a2dd95SBruce Richardson  * Finally, an application can close a RegEx device by invoking the
15099a2dd95SBruce Richardson  * rte_regexdev_close() function.
15199a2dd95SBruce Richardson  *
15299a2dd95SBruce Richardson  * Each function of the application RegEx API invokes a specific function
15399a2dd95SBruce Richardson  * of the PMD that controls the target device designated by its device
15499a2dd95SBruce Richardson  * identifier.
15599a2dd95SBruce Richardson  *
15699a2dd95SBruce Richardson  * For this purpose, all device-specific functions of a RegEx driver are
15799a2dd95SBruce Richardson  * supplied through a set of pointers contained in a generic structure of type
15899a2dd95SBruce Richardson  * *regexdev_ops*.
15999a2dd95SBruce Richardson  * The address of the *regexdev_ops* structure is stored in the *rte_regexdev*
16099a2dd95SBruce Richardson  * structure by the device init function of the RegEx driver, which is
16199a2dd95SBruce Richardson  * invoked during the PCI/SoC device probing phase, as explained earlier.
16299a2dd95SBruce Richardson  *
16399a2dd95SBruce Richardson  * In other words, each function of the RegEx API simply retrieves the
16499a2dd95SBruce Richardson  * *rte_regexdev* structure associated with the device identifier and
16599a2dd95SBruce Richardson  * performs an indirect invocation of the corresponding driver function
16699a2dd95SBruce Richardson  * supplied in the *regexdev_ops* structure of the *rte_regexdev* structure.
16799a2dd95SBruce Richardson  *
16899a2dd95SBruce Richardson  * For performance reasons, the address of the fast-path functions of the
16999a2dd95SBruce Richardson  * RegEx driver is not contained in the *regexdev_ops* structure.
17099a2dd95SBruce Richardson  * Instead, they are directly stored at the beginning of the *rte_regexdev*
17199a2dd95SBruce Richardson  * structure to avoid an extra indirect memory access during their invocation.
17299a2dd95SBruce Richardson  *
17399a2dd95SBruce Richardson  * RTE RegEx device drivers do not use interrupts for enqueue or dequeue
17499a2dd95SBruce Richardson  * operation. Instead, RegEx drivers export Poll-Mode enqueue and dequeue
17599a2dd95SBruce Richardson  * functions to applications.
17699a2dd95SBruce Richardson  *
17799a2dd95SBruce Richardson  * The *enqueue* operation submits a burst of RegEx pattern matching request
17899a2dd95SBruce Richardson  * to the RegEx device and the *dequeue* operation gets a burst of pattern
17999a2dd95SBruce Richardson  * matching response for the ones submitted through *enqueue* operation.
18099a2dd95SBruce Richardson  *
18199a2dd95SBruce Richardson  * Typical application utilisation of the RegEx device API will follow the
18299a2dd95SBruce Richardson  * following programming flow.
18399a2dd95SBruce Richardson  *
18499a2dd95SBruce Richardson  * - rte_regexdev_configure()
18599a2dd95SBruce Richardson  * - rte_regexdev_queue_pair_setup()
18699a2dd95SBruce Richardson  * - rte_regexdev_rule_db_update() Needs to invoke if precompiled rule database
18799a2dd95SBruce Richardson  *   not provided in rte_regexdev_config::rule_db for rte_regexdev_configure()
18899a2dd95SBruce Richardson  *   and/or application needs to update rule database.
18999a2dd95SBruce Richardson  * - rte_regexdev_rule_db_compile_activate() Needs to invoke if
19099a2dd95SBruce Richardson  *   rte_regexdev_rule_db_update function was used.
19199a2dd95SBruce Richardson  * - Create or reuse exiting mempool for *rte_regex_ops* objects.
19299a2dd95SBruce Richardson  * - rte_regexdev_start()
19399a2dd95SBruce Richardson  * - rte_regexdev_enqueue_burst()
19499a2dd95SBruce Richardson  * - rte_regexdev_dequeue_burst()
19599a2dd95SBruce Richardson  */
19699a2dd95SBruce Richardson 
19799a2dd95SBruce Richardson #ifdef __cplusplus
19899a2dd95SBruce Richardson extern "C" {
19999a2dd95SBruce Richardson #endif
20099a2dd95SBruce Richardson 
2011094dd94SDavid Marchand #include <rte_compat.h>
20299a2dd95SBruce Richardson #include <rte_common.h>
20399a2dd95SBruce Richardson #include <rte_dev.h>
20499a2dd95SBruce Richardson #include <rte_mbuf.h>
20599a2dd95SBruce Richardson 
20699a2dd95SBruce Richardson #define RTE_REGEXDEV_NAME_MAX_LEN RTE_DEV_NAME_MAX_LEN
20799a2dd95SBruce Richardson 
20899a2dd95SBruce Richardson extern int rte_regexdev_logtype;
2090e21c7c0SDavid Marchand #define RTE_LOGTYPE_REGEXDEV rte_regexdev_logtype
21099a2dd95SBruce Richardson 
2110e21c7c0SDavid Marchand #define RTE_REGEXDEV_LOG_LINE(level, ...) \
212*97433132SDavid Marchand 	RTE_LOG_LINE(level, REGEXDEV, "" __VA_ARGS__)
21399a2dd95SBruce Richardson 
21499a2dd95SBruce Richardson /* Macros to check for valid port */
21599a2dd95SBruce Richardson #define RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, retval) do { \
21699a2dd95SBruce Richardson 	if (!rte_regexdev_is_valid_dev(dev_id)) { \
2170e21c7c0SDavid Marchand 		RTE_REGEXDEV_LOG_LINE(ERR, "Invalid dev_id=%u", dev_id); \
21899a2dd95SBruce Richardson 		return retval; \
21999a2dd95SBruce Richardson 	} \
22099a2dd95SBruce Richardson } while (0)
22199a2dd95SBruce Richardson 
22299a2dd95SBruce Richardson #define RTE_REGEXDEV_VALID_DEV_ID_OR_RET(dev_id) do { \
22399a2dd95SBruce Richardson 	if (!rte_regexdev_is_valid_dev(dev_id)) { \
2240e21c7c0SDavid Marchand 		RTE_REGEXDEV_LOG_LINE(ERR, "Invalid dev_id=%u", dev_id); \
22599a2dd95SBruce Richardson 		return; \
22699a2dd95SBruce Richardson 	} \
22799a2dd95SBruce Richardson } while (0)
22899a2dd95SBruce Richardson 
22999a2dd95SBruce Richardson /**
23089e290ebSThomas Monjalon  * @warning
23189e290ebSThomas Monjalon  * @b EXPERIMENTAL: this API may change without prior notice.
23289e290ebSThomas Monjalon  *
23399a2dd95SBruce Richardson  * Check if dev_id is ready.
23499a2dd95SBruce Richardson  *
23599a2dd95SBruce Richardson  * @param dev_id
23699a2dd95SBruce Richardson  *   The dev identifier of the RegEx device.
23799a2dd95SBruce Richardson  *
23899a2dd95SBruce Richardson  * @return
23999a2dd95SBruce Richardson  *   - 0 if device state is not in ready state.
24099a2dd95SBruce Richardson  *   - 1 if device state is ready state.
24199a2dd95SBruce Richardson  */
24289e290ebSThomas Monjalon __rte_experimental
24399a2dd95SBruce Richardson int rte_regexdev_is_valid_dev(uint16_t dev_id);
24499a2dd95SBruce Richardson 
24599a2dd95SBruce Richardson /**
24699a2dd95SBruce Richardson  * @warning
24799a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
24899a2dd95SBruce Richardson  *
24999a2dd95SBruce Richardson  * Get the total number of RegEx devices that have been successfully
25099a2dd95SBruce Richardson  * initialised.
25199a2dd95SBruce Richardson  *
25299a2dd95SBruce Richardson  * @return
25399a2dd95SBruce Richardson  *   The total number of usable RegEx devices.
25499a2dd95SBruce Richardson  */
25599a2dd95SBruce Richardson __rte_experimental
25699a2dd95SBruce Richardson uint8_t
25799a2dd95SBruce Richardson rte_regexdev_count(void);
25899a2dd95SBruce Richardson 
25999a2dd95SBruce Richardson /**
26099a2dd95SBruce Richardson  * @warning
26199a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
26299a2dd95SBruce Richardson  *
26399a2dd95SBruce Richardson  * Get the device identifier for the named RegEx device.
26499a2dd95SBruce Richardson  *
26599a2dd95SBruce Richardson  * @param name
26699a2dd95SBruce Richardson  *   RegEx device name to select the RegEx device identifier.
26799a2dd95SBruce Richardson  *
26899a2dd95SBruce Richardson  * @return
26999a2dd95SBruce Richardson  *   Returns RegEx device identifier on success.
27099a2dd95SBruce Richardson  *   - <0: Failure to find named RegEx device.
27199a2dd95SBruce Richardson  */
27299a2dd95SBruce Richardson __rte_experimental
27399a2dd95SBruce Richardson int
27499a2dd95SBruce Richardson rte_regexdev_get_dev_id(const char *name);
27599a2dd95SBruce Richardson 
27699a2dd95SBruce Richardson /* Enumerates RegEx device capabilities */
27799a2dd95SBruce Richardson #define RTE_REGEXDEV_CAPA_RUNTIME_COMPILATION_F (1ULL << 0)
27899a2dd95SBruce Richardson /**< RegEx device does support compiling the rules at runtime unlike
27999a2dd95SBruce Richardson  * loading only the pre-built rule database using
28099a2dd95SBruce Richardson  * struct rte_regexdev_config::rule_db in rte_regexdev_configure()
28199a2dd95SBruce Richardson  *
28299a2dd95SBruce Richardson  * @see struct rte_regexdev_config::rule_db, rte_regexdev_configure()
28399a2dd95SBruce Richardson  * @see struct rte_regexdev_info::regexdev_capa
28499a2dd95SBruce Richardson  */
28599a2dd95SBruce Richardson 
28699a2dd95SBruce Richardson #define RTE_REGEXDEV_CAPA_SUPP_PCRE_START_ANCHOR_F (1ULL << 1)
28799a2dd95SBruce Richardson /**< RegEx device support PCRE Anchor to start of match flag.
28899a2dd95SBruce Richardson  * Example RegEx is `/\Gfoo\d/`. Here `\G` asserts position at the end of the
28999a2dd95SBruce Richardson  * previous match or the start of the string for the first match.
29099a2dd95SBruce Richardson  * This position will change each time the RegEx is applied to the subject
29199a2dd95SBruce Richardson  * string. If the RegEx is applied to `foo1foo2Zfoo3` the first two matches will
29299a2dd95SBruce Richardson  * be successful for `foo1foo2` and fail for `Zfoo3`.
29399a2dd95SBruce Richardson  *
29499a2dd95SBruce Richardson  * @see struct rte_regexdev_info::regexdev_capa
29599a2dd95SBruce Richardson  */
29699a2dd95SBruce Richardson 
29799a2dd95SBruce Richardson #define RTE_REGEXDEV_CAPA_SUPP_PCRE_ATOMIC_GROUPING_F (1ULL << 2)
29899a2dd95SBruce Richardson /**< RegEx device support PCRE Atomic grouping.
29999a2dd95SBruce Richardson  * Atomic groups are represented by `(?>)`. An atomic group is a group that,
30099a2dd95SBruce Richardson  * when the RegEx engine exits from it, automatically throws away all
30199a2dd95SBruce Richardson  * backtracking positions remembered by any tokens inside the group.
30299a2dd95SBruce Richardson  * Example RegEx is `a(?>bc|b)c` if the given patterns are `abc` and `abcc` then
30399a2dd95SBruce Richardson  * `a(bc|b)c` matches both where as `a(?>bc|b)c` matches only abcc because
3047be78d02SJosh Soref  * atomic groups don't allow backtracking back to `b`.
30599a2dd95SBruce Richardson  *
30699a2dd95SBruce Richardson  * @see struct rte_regexdev_info::regexdev_capa
30799a2dd95SBruce Richardson  */
30899a2dd95SBruce Richardson 
30999a2dd95SBruce Richardson #define RTE_REGEXDEV_SUPP_PCRE_BACKTRACKING_CTRL_F (1ULL << 3)
31099a2dd95SBruce Richardson /**< RegEx device support PCRE backtracking control verbs.
3117be78d02SJosh Soref  * Some examples of backtracking verbs are (*COMMIT), (*ACCEPT), (*FAIL),
31299a2dd95SBruce Richardson  * (*SKIP), (*PRUNE).
31399a2dd95SBruce Richardson  *
31499a2dd95SBruce Richardson  * @see struct rte_regexdev_info::regexdev_capa
31599a2dd95SBruce Richardson  */
31699a2dd95SBruce Richardson 
31799a2dd95SBruce Richardson #define RTE_REGEXDEV_SUPP_PCRE_CALLOUTS_F (1ULL << 4)
31899a2dd95SBruce Richardson /**< RegEx device support PCRE callouts.
31999a2dd95SBruce Richardson  * PCRE supports calling external function in between matches by using `(?C)`.
32099a2dd95SBruce Richardson  * Example RegEx `ABC(?C)D` if a given patter is `ABCD` then the RegEx engine
32199a2dd95SBruce Richardson  * will parse ABC perform a userdefined callout and return a successful match at
32299a2dd95SBruce Richardson  * D.
32399a2dd95SBruce Richardson  *
32499a2dd95SBruce Richardson  * @see struct rte_regexdev_info::regexdev_capa
32599a2dd95SBruce Richardson  */
32699a2dd95SBruce Richardson 
32799a2dd95SBruce Richardson #define RTE_REGEXDEV_SUPP_PCRE_BACKREFERENCE_F (1ULL << 5)
32899a2dd95SBruce Richardson /**< RegEx device support PCRE backreference.
32999a2dd95SBruce Richardson  * Example RegEx is `(\2ABC|(GHI))+` `\2` matches the same text as most recently
33099a2dd95SBruce Richardson  * matched by the 2nd capturing group i.e. `GHI`.
33199a2dd95SBruce Richardson  *
33299a2dd95SBruce Richardson  * @see struct rte_regexdev_info::regexdev_capa
33399a2dd95SBruce Richardson  */
33499a2dd95SBruce Richardson 
33599a2dd95SBruce Richardson #define RTE_REGEXDEV_SUPP_PCRE_GREEDY_F (1ULL << 6)
33699a2dd95SBruce Richardson /**< RegEx device support PCRE Greedy mode.
33799a2dd95SBruce Richardson  * For example if the RegEx is `AB\d*?` then `*?` represents zero or unlimited
33899a2dd95SBruce Richardson  * matches. In greedy mode the pattern `AB12345` will be matched completely
33999a2dd95SBruce Richardson  * where as the ungreedy mode `AB` will be returned as the match.
34099a2dd95SBruce Richardson  *
34199a2dd95SBruce Richardson  * @see struct rte_regexdev_info::regexdev_capa
34299a2dd95SBruce Richardson  */
34399a2dd95SBruce Richardson 
34499a2dd95SBruce Richardson #define RTE_REGEXDEV_SUPP_PCRE_MATCH_ALL_F (1ULL << 7)
34599a2dd95SBruce Richardson /**< RegEx device support match all mode.
34699a2dd95SBruce Richardson  * For example if the RegEx is `AB\d*?` then `*?` represents zero or unlimited
34799a2dd95SBruce Richardson  * matches. In match all mode the pattern `AB12345` will return 6 matches.
34899a2dd95SBruce Richardson  * AB, AB1, AB12, AB123, AB1234, AB12345.
34999a2dd95SBruce Richardson  *
35099a2dd95SBruce Richardson  * @see struct rte_regexdev_info::regexdev_capa
35199a2dd95SBruce Richardson  */
35299a2dd95SBruce Richardson 
35399a2dd95SBruce Richardson #define RTE_REGEXDEV_SUPP_PCRE_LOOKAROUND_ASRT_F (1ULL << 8)
35499a2dd95SBruce Richardson /**< RegEx device support PCRE Lookaround assertions
35599a2dd95SBruce Richardson  * (Zero-width assertions). Example RegEx is `[a-z]+\d+(?=!{3,})` if
35699a2dd95SBruce Richardson  * the given pattern is `dwad1234!` the RegEx engine doesn't report any matches
35799a2dd95SBruce Richardson  * because the assert `(?=!{3,})` fails. The pattern `dwad123!!!` would return a
35899a2dd95SBruce Richardson  * successful match.
35999a2dd95SBruce Richardson  *
36099a2dd95SBruce Richardson  * @see struct rte_regexdev_info::regexdev_capa
36199a2dd95SBruce Richardson  */
36299a2dd95SBruce Richardson 
36399a2dd95SBruce Richardson #define RTE_REGEXDEV_SUPP_PCRE_MATCH_POINT_RST_F (1ULL << 9)
36499a2dd95SBruce Richardson /**< RegEx device doesn't support PCRE match point reset directive.
36599a2dd95SBruce Richardson  * Example RegEx is `[a-z]+\K\d+` if the pattern is `dwad123`
36699a2dd95SBruce Richardson  * then even though the entire pattern matches only `123`
36799a2dd95SBruce Richardson  * is reported as a match.
36899a2dd95SBruce Richardson  *
36999a2dd95SBruce Richardson  * @see struct rte_regexdev_info::regexdev_capa
37099a2dd95SBruce Richardson  */
37199a2dd95SBruce Richardson 
37299a2dd95SBruce Richardson #define RTE_REGEXDEV_SUPP_NEWLINE_CONVENTIONS_F (1ULL << 10)
37399a2dd95SBruce Richardson /**< RegEx support PCRE newline convention.
37499a2dd95SBruce Richardson  * Newline conventions are represented as follows:
37599a2dd95SBruce Richardson  * (*CR)        carriage return
37699a2dd95SBruce Richardson  * (*LF)        linefeed
37799a2dd95SBruce Richardson  * (*CRLF)      carriage return, followed by linefeed
37899a2dd95SBruce Richardson  * (*ANYCRLF)   any of the three above
37999a2dd95SBruce Richardson  * (*ANY)       all Unicode newline sequences
38099a2dd95SBruce Richardson  *
38199a2dd95SBruce Richardson  * @see struct rte_regexdev_info::regexdev_capa
38299a2dd95SBruce Richardson  */
38399a2dd95SBruce Richardson 
38499a2dd95SBruce Richardson #define RTE_REGEXDEV_SUPP_PCRE_NEWLINE_SEQ_F (1ULL << 11)
38599a2dd95SBruce Richardson /**< RegEx device support PCRE newline sequence.
38699a2dd95SBruce Richardson  * The escape sequence `\R` will match any newline sequence.
38799a2dd95SBruce Richardson  * It is equivalent to: `(?>\r\n|\n|\x0b|\f|\r|\x85)`.
38899a2dd95SBruce Richardson  *
38999a2dd95SBruce Richardson  * @see struct rte_regexdev_info::regexdev_capa
39099a2dd95SBruce Richardson  */
39199a2dd95SBruce Richardson 
39299a2dd95SBruce Richardson #define RTE_REGEXDEV_SUPP_PCRE_POSSESSIVE_QUALIFIERS_F (1ULL << 12)
39399a2dd95SBruce Richardson /**< RegEx device support PCRE possessive qualifiers.
39499a2dd95SBruce Richardson  * Example RegEx possessive qualifiers `*+`, `++`, `?+`, `{m,n}+`.
39599a2dd95SBruce Richardson  * Possessive quantifier repeats the token as many times as possible and it does
39699a2dd95SBruce Richardson  * not give up matches as the engine backtracks. With a possessive quantifier,
39799a2dd95SBruce Richardson  * the deal is all or nothing.
39899a2dd95SBruce Richardson  *
39999a2dd95SBruce Richardson  * @see struct rte_regexdev_info::regexdev_capa
40099a2dd95SBruce Richardson  */
40199a2dd95SBruce Richardson 
40299a2dd95SBruce Richardson #define RTE_REGEXDEV_SUPP_PCRE_SUBROUTINE_REFERENCES_F (1ULL << 13)
40399a2dd95SBruce Richardson /**< RegEx device support PCRE Subroutine references.
40499a2dd95SBruce Richardson  * PCRE Subroutine references allow for sub patterns to be assessed
40599a2dd95SBruce Richardson  * as part of the RegEx. Example RegEx is `(foo|fuzz)\g<1>+bar` matches the
40699a2dd95SBruce Richardson  * pattern `foofoofuzzfoofuzzbar`.
40799a2dd95SBruce Richardson  *
40899a2dd95SBruce Richardson  * @see struct rte_regexdev_info::regexdev_capa
40999a2dd95SBruce Richardson  */
41099a2dd95SBruce Richardson 
41199a2dd95SBruce Richardson #define RTE_REGEXDEV_SUPP_PCRE_UTF_8_F (1ULL << 14)
41299a2dd95SBruce Richardson /**< RegEx device support UTF-8 character encoding.
41399a2dd95SBruce Richardson  *
41499a2dd95SBruce Richardson  * @see struct rte_regexdev_info::pcre_unsup_flags
41599a2dd95SBruce Richardson  */
41699a2dd95SBruce Richardson 
41799a2dd95SBruce Richardson #define RTE_REGEXDEV_SUPP_PCRE_UTF_16_F (1ULL << 15)
41899a2dd95SBruce Richardson /**< RegEx device support UTF-16 character encoding.
41999a2dd95SBruce Richardson  *
42099a2dd95SBruce Richardson  * @see struct rte_regexdev_info::regexdev_capa
42199a2dd95SBruce Richardson  */
42299a2dd95SBruce Richardson 
42399a2dd95SBruce Richardson #define RTE_REGEXDEV_SUPP_PCRE_UTF_32_F (1ULL << 16)
42499a2dd95SBruce Richardson /**< RegEx device support UTF-32 character encoding.
42599a2dd95SBruce Richardson  *
42699a2dd95SBruce Richardson  * @see struct rte_regexdev_info::regexdev_capa
42799a2dd95SBruce Richardson  */
42899a2dd95SBruce Richardson 
42999a2dd95SBruce Richardson #define RTE_REGEXDEV_SUPP_PCRE_WORD_BOUNDARY_F (1ULL << 17)
43099a2dd95SBruce Richardson /**< RegEx device support word boundaries.
43199a2dd95SBruce Richardson  * The meta character `\b` represents word boundary anchor.
43299a2dd95SBruce Richardson  *
43399a2dd95SBruce Richardson  * @see struct rte_regexdev_info::regexdev_capa
43499a2dd95SBruce Richardson  */
43599a2dd95SBruce Richardson 
43699a2dd95SBruce Richardson #define RTE_REGEXDEV_SUPP_PCRE_FORWARD_REFERENCES_F (1ULL << 18)
43799a2dd95SBruce Richardson /**< RegEx device support Forward references.
43899a2dd95SBruce Richardson  * Forward references allow you to use a back reference to a group that appears
43999a2dd95SBruce Richardson  * later in the RegEx. Example RegEx is `(\3ABC|(DEF|(GHI)))+` matches the
44099a2dd95SBruce Richardson  * following string `GHIGHIABCDEF`.
44199a2dd95SBruce Richardson  *
44299a2dd95SBruce Richardson  * @see struct rte_regexdev_info::regexdev_capa
44399a2dd95SBruce Richardson  */
44499a2dd95SBruce Richardson 
44599a2dd95SBruce Richardson #define RTE_REGEXDEV_SUPP_MATCH_AS_END_F (1ULL << 19)
44699a2dd95SBruce Richardson /**< RegEx device support match as end.
44799a2dd95SBruce Richardson  * Match as end means that the match result holds the end offset of the
44899a2dd95SBruce Richardson  * detected match. No len value is set.
44999a2dd95SBruce Richardson  * If the device doesn't support this feature it means the match
45099a2dd95SBruce Richardson  * result holds the starting position of match and the length of the match.
45199a2dd95SBruce Richardson  *
45299a2dd95SBruce Richardson  * @see struct rte_regexdev_info::regexdev_capa
45399a2dd95SBruce Richardson  */
45499a2dd95SBruce Richardson 
45599a2dd95SBruce Richardson #define RTE_REGEXDEV_SUPP_CROSS_BUFFER_F (1ULL << 20)
45699a2dd95SBruce Richardson /**< RegEx device support cross buffer match.
45799a2dd95SBruce Richardson  * Cross buffer matching means that the match can be detected even if the
45899a2dd95SBruce Richardson  * string was started in previous buffer.
45999a2dd95SBruce Richardson  * In case the device is configured as RTE_REGEXDEV_CFG_MATCH_AS_END
46099a2dd95SBruce Richardson  * the end offset will be relative for the first packet.
46199a2dd95SBruce Richardson  * For example RegEx is ABC the first buffer is xxxx second buffer yyyA and
46299a2dd95SBruce Richardson  * the last buffer BCzz.
46399a2dd95SBruce Richardson  * In case the match as end is configured the end offset will be 10.
46499a2dd95SBruce Richardson  *
46599a2dd95SBruce Richardson  * @see RTE_REGEXDEV_CFG_MATCH_AS_END_F
46699a2dd95SBruce Richardson  * @see RTE_REGEXDEV_CFG_CROSS_BUFFER_SCAN_F
46799a2dd95SBruce Richardson  * @see RTE_REGEX_OPS_RSP_PMI_SOJ_F
46899a2dd95SBruce Richardson  * @see RTE_REGEX_OPS_RSP_PMI_EOJ_F
46999a2dd95SBruce Richardson  */
47099a2dd95SBruce Richardson 
47199a2dd95SBruce Richardson #define RTE_REGEXDEV_SUPP_MATCH_ALL_F (1ULL << 21)
47299a2dd95SBruce Richardson /**< RegEx device support match all.
47399a2dd95SBruce Richardson  * Match all means that the RegEx engine will return all possible matches.
47499a2dd95SBruce Richardson  * For example, assume the RegEx is `A+b`, given the input AAAb the
47599a2dd95SBruce Richardson  * returned matches will be: Ab, AAb and AAAb.
47699a2dd95SBruce Richardson  *
47799a2dd95SBruce Richardson  * @see RTE_REGEXDEV_CFG_MATCH_ALL_F
47899a2dd95SBruce Richardson  */
47999a2dd95SBruce Richardson 
48099a2dd95SBruce Richardson #define RTE_REGEXDEV_CAPA_QUEUE_PAIR_OOS_F (1ULL << 22)
48199a2dd95SBruce Richardson /**< RegEx device supports out of order scan.
48299a2dd95SBruce Richardson  * Out of order scan means the response of a specific job can be returned as
48399a2dd95SBruce Richardson  * soon as it is ready even if previous jobs on the same queue didn't complete.
48499a2dd95SBruce Richardson  *
48599a2dd95SBruce Richardson  * @see RTE_REGEX_QUEUE_PAIR_CFG_OOS_F
48699a2dd95SBruce Richardson  * @see struct rte_regexdev_info::regexdev_capa
48799a2dd95SBruce Richardson  */
48899a2dd95SBruce Richardson 
48999a2dd95SBruce Richardson /* Enumerates PCRE rule flags */
49099a2dd95SBruce Richardson #define RTE_REGEX_PCRE_RULE_ALLOW_EMPTY_F (1ULL << 0)
49199a2dd95SBruce Richardson /**< When this flag is set, the pattern that can match against an empty string,
49299a2dd95SBruce Richardson  * such as `.*` are allowed.
49399a2dd95SBruce Richardson  *
49499a2dd95SBruce Richardson  * @see struct rte_regexdev_info::rule_flags
49599a2dd95SBruce Richardson  * @see struct rte_regexdev_rule::rule_flags
49699a2dd95SBruce Richardson  */
49799a2dd95SBruce Richardson 
49899a2dd95SBruce Richardson #define RTE_REGEX_PCRE_RULE_ANCHORED_F (1ULL << 1)
49999a2dd95SBruce Richardson /**< When this flag is set, the pattern is forced to be "anchored", that is, it
50099a2dd95SBruce Richardson  * is constrained to match only at the first matching point in the string that
50199a2dd95SBruce Richardson  * is being searched. Similar to `^` and represented by `\A`.
50299a2dd95SBruce Richardson  *
50399a2dd95SBruce Richardson  * @see struct rte_regexdev_info::rule_flags
50499a2dd95SBruce Richardson  * @see struct rte_regexdev_rule::rule_flags
50599a2dd95SBruce Richardson  */
50699a2dd95SBruce Richardson 
50799a2dd95SBruce Richardson #define RTE_REGEX_PCRE_RULE_CASELESS_F (1ULL << 2)
50899a2dd95SBruce Richardson /**< When this flag is set, letters in the pattern match both upper and lower
50999a2dd95SBruce Richardson  * case letters in the subject.
51099a2dd95SBruce Richardson  *
51199a2dd95SBruce Richardson  * @see struct rte_regexdev_info::rule_flags
51299a2dd95SBruce Richardson  * @see struct rte_regexdev_rule::rule_flags
51399a2dd95SBruce Richardson  */
51499a2dd95SBruce Richardson 
51599a2dd95SBruce Richardson #define RTE_REGEX_PCRE_RULE_DOTALL_F (1ULL << 3)
51699a2dd95SBruce Richardson /**< When this flag is set, a dot metacharacter in the pattern matches any
51799a2dd95SBruce Richardson  * character, including one that indicates a newline.
51899a2dd95SBruce Richardson  *
51999a2dd95SBruce Richardson  * @see struct rte_regexdev_info::rule_flags
52099a2dd95SBruce Richardson  * @see struct rte_regexdev_rule::rule_flags
52199a2dd95SBruce Richardson  */
52299a2dd95SBruce Richardson 
52399a2dd95SBruce Richardson #define RTE_REGEX_PCRE_RULE_DUPNAMES_F (1ULL << 4)
52499a2dd95SBruce Richardson /**< When this flag is set, names used to identify capture groups need not be
52599a2dd95SBruce Richardson  * unique.
52699a2dd95SBruce Richardson  *
52799a2dd95SBruce Richardson  * @see struct rte_regexdev_info::rule_flags
52899a2dd95SBruce Richardson  * @see struct rte_regexdev_rule::rule_flags
52999a2dd95SBruce Richardson  */
53099a2dd95SBruce Richardson 
53199a2dd95SBruce Richardson #define RTE_REGEX_PCRE_RULE_EXTENDED_F (1ULL << 5)
53299a2dd95SBruce Richardson /**< When this flag is set, most white space characters in the pattern are
53399a2dd95SBruce Richardson  * totally ignored except when escaped or inside a character class.
53499a2dd95SBruce Richardson  *
53599a2dd95SBruce Richardson  * @see struct rte_regexdev_info::rule_flags
53699a2dd95SBruce Richardson  * @see struct rte_regexdev_rule::rule_flags
53799a2dd95SBruce Richardson  */
53899a2dd95SBruce Richardson 
53999a2dd95SBruce Richardson #define RTE_REGEX_PCRE_RULE_MATCH_UNSET_BACKREF_F (1ULL << 6)
54099a2dd95SBruce Richardson /**< When this flag is set, a backreference to an unset capture group matches an
54199a2dd95SBruce Richardson  * empty string.
54299a2dd95SBruce Richardson  *
54399a2dd95SBruce Richardson  * @see struct rte_regexdev_info::rule_flags
54499a2dd95SBruce Richardson  * @see struct rte_regexdev_rule::rule_flags
54599a2dd95SBruce Richardson  */
54699a2dd95SBruce Richardson 
54799a2dd95SBruce Richardson #define RTE_REGEX_PCRE_RULE_MULTILINE_F (1ULL << 7)
54899a2dd95SBruce Richardson /**< When this flag  is set, the `^` and `$` constructs match immediately
54999a2dd95SBruce Richardson  * following or immediately before internal newlines in the subject string,
55099a2dd95SBruce Richardson  * respectively, as well as at the very start and end.
55199a2dd95SBruce Richardson  *
55299a2dd95SBruce Richardson  * @see struct rte_regexdev_info::rule_flags
55399a2dd95SBruce Richardson  * @see struct rte_regexdev_rule::rule_flags
55499a2dd95SBruce Richardson  */
55599a2dd95SBruce Richardson 
55699a2dd95SBruce Richardson #define RTE_REGEX_PCRE_RULE_NO_AUTO_CAPTURE_F (1ULL << 8)
55799a2dd95SBruce Richardson /**< When this Flag is set, it disables the use of numbered capturing
55899a2dd95SBruce Richardson  * parentheses in the pattern. References to capture groups (backreferences or
55999a2dd95SBruce Richardson  * recursion/subroutine calls) may only refer to named groups, though the
56099a2dd95SBruce Richardson  * reference can be by name or by number.
56199a2dd95SBruce Richardson  *
56299a2dd95SBruce Richardson  * @see struct rte_regexdev_info::rule_flags
56399a2dd95SBruce Richardson  * @see struct rte_regexdev_rule::rule_flags
56499a2dd95SBruce Richardson  */
56599a2dd95SBruce Richardson 
56699a2dd95SBruce Richardson #define RTE_REGEX_PCRE_RULE_UCP_F (1ULL << 9)
56799a2dd95SBruce Richardson /**< By default, only ASCII characters are recognized, When this flag is set,
56899a2dd95SBruce Richardson  * Unicode properties are used instead to classify characters.
56999a2dd95SBruce Richardson  *
57099a2dd95SBruce Richardson  * @see struct rte_regexdev_info::rule_flags
57199a2dd95SBruce Richardson  * @see struct rte_regexdev_rule::rule_flags
57299a2dd95SBruce Richardson  */
57399a2dd95SBruce Richardson 
57499a2dd95SBruce Richardson #define RTE_REGEX_PCRE_RULE_UNGREEDY_F (1ULL << 10)
57599a2dd95SBruce Richardson /**< When this flag is set, the "greediness" of the quantifiers is inverted
57699a2dd95SBruce Richardson  * so that they are not greedy by default, but become greedy if followed by
57799a2dd95SBruce Richardson  * `?`.
57899a2dd95SBruce Richardson  *
57999a2dd95SBruce Richardson  * @see struct rte_regexdev_info::rule_flags
58099a2dd95SBruce Richardson  * @see struct rte_regexdev_rule::rule_flags
58199a2dd95SBruce Richardson  */
58299a2dd95SBruce Richardson 
58399a2dd95SBruce Richardson #define RTE_REGEX_PCRE_RULE_UTF_F (1ULL << 11)
58499a2dd95SBruce Richardson /**< When this flag is set, RegEx engine has to regard both the pattern and the
58599a2dd95SBruce Richardson  * subject strings that are subsequently processed as strings of UTF characters
58699a2dd95SBruce Richardson  * instead of single-code-unit strings.
58799a2dd95SBruce Richardson  *
58899a2dd95SBruce Richardson  * @see struct rte_regexdev_info::rule_flags
58999a2dd95SBruce Richardson  * @see struct rte_regexdev_rule::rule_flags
59099a2dd95SBruce Richardson  */
59199a2dd95SBruce Richardson 
59299a2dd95SBruce Richardson #define RTE_REGEX_PCRE_RULE_NEVER_BACKSLASH_C_F (1ULL << 12)
59399a2dd95SBruce Richardson /**< This flag locks out the use of `\C` in the pattern that is being compiled.
59499a2dd95SBruce Richardson  * This escape matches one data unit, even in UTF mode which can cause
59599a2dd95SBruce Richardson  * unpredictable behavior in UTF-8 or UTF-16 modes, because it may leave the
59699a2dd95SBruce Richardson  * current matching point in the mi:set hlsearchddle of a multi-code-unit
59799a2dd95SBruce Richardson  * character.
59899a2dd95SBruce Richardson  *
59999a2dd95SBruce Richardson  * @see struct rte_regexdev_info::rule_flags
60099a2dd95SBruce Richardson  * @see struct rte_regexdev_rule::rule_flags
60199a2dd95SBruce Richardson  */
60299a2dd95SBruce Richardson 
60399a2dd95SBruce Richardson /**
60499a2dd95SBruce Richardson  * RegEx device information
60599a2dd95SBruce Richardson  */
60699a2dd95SBruce Richardson struct rte_regexdev_info {
60799a2dd95SBruce Richardson 	const char *driver_name; /**< RegEx driver name. */
60899a2dd95SBruce Richardson 	struct rte_device *dev;	/**< Device information. */
60999a2dd95SBruce Richardson 	uint16_t max_matches;
61099a2dd95SBruce Richardson 	/**< Maximum matches per scan supported by this device. */
61199a2dd95SBruce Richardson 	uint16_t max_queue_pairs;
61299a2dd95SBruce Richardson 	/**< Maximum queue pairs supported by this device. */
61399a2dd95SBruce Richardson 	uint16_t max_payload_size;
61499a2dd95SBruce Richardson 	/**< Maximum payload size for a pattern match request or scan.
61599a2dd95SBruce Richardson 	 * @see RTE_REGEXDEV_CFG_CROSS_BUFFER_SCAN_F
61699a2dd95SBruce Richardson 	 */
61770f1ea71SGerry Gribbon 	uint16_t max_segs;
61870f1ea71SGerry Gribbon 	/**< Maximum number of mbuf segments that can be chained together. */
61999a2dd95SBruce Richardson 	uint32_t max_rules_per_group;
62099a2dd95SBruce Richardson 	/**< Maximum rules supported per group by this device. */
62199a2dd95SBruce Richardson 	uint16_t max_groups;
62299a2dd95SBruce Richardson 	/**< Maximum groups supported by this device. */
62399a2dd95SBruce Richardson 	uint32_t regexdev_capa;
62499a2dd95SBruce Richardson 	/**< RegEx device capabilities. @see RTE_REGEXDEV_CAPA_* */
62599a2dd95SBruce Richardson 	uint64_t rule_flags;
62699a2dd95SBruce Richardson 	/**< Supported compiler rule flags.
62799a2dd95SBruce Richardson 	 * @see RTE_REGEX_PCRE_RULE_*, struct rte_regexdev_rule::rule_flags
62899a2dd95SBruce Richardson 	 */
62999a2dd95SBruce Richardson };
63099a2dd95SBruce Richardson 
63199a2dd95SBruce Richardson /**
63299a2dd95SBruce Richardson  * @warning
63399a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
63499a2dd95SBruce Richardson  *
63599a2dd95SBruce Richardson  * Retrieve the contextual information of a RegEx device.
63699a2dd95SBruce Richardson  *
63799a2dd95SBruce Richardson  * @param dev_id
63899a2dd95SBruce Richardson  *   The identifier of the device.
63999a2dd95SBruce Richardson  *
64099a2dd95SBruce Richardson  * @param[out] dev_info
64199a2dd95SBruce Richardson  *   A pointer to a structure of type *rte_regexdev_info* to be filled with the
64299a2dd95SBruce Richardson  *   contextual information of the device.
64399a2dd95SBruce Richardson  *
64499a2dd95SBruce Richardson  * @return
64599a2dd95SBruce Richardson  *   - 0: Success, driver updates the contextual information of the RegEx device
64699a2dd95SBruce Richardson  *   - <0: Error code returned by the driver info get function.
64799a2dd95SBruce Richardson  */
64899a2dd95SBruce Richardson __rte_experimental
64999a2dd95SBruce Richardson int
65099a2dd95SBruce Richardson rte_regexdev_info_get(uint8_t dev_id, struct rte_regexdev_info *dev_info);
65199a2dd95SBruce Richardson 
65299a2dd95SBruce Richardson /* Enumerates RegEx device configuration flags */
65399a2dd95SBruce Richardson #define RTE_REGEXDEV_CFG_CROSS_BUFFER_SCAN_F (1ULL << 0)
65499a2dd95SBruce Richardson /**< Cross buffer scan refers to the ability to be able to detect
65599a2dd95SBruce Richardson  * matches that occur across buffer boundaries, where the buffers are related
65699a2dd95SBruce Richardson  * to each other in some way. Enable this flag when to scan payload size
65799a2dd95SBruce Richardson  * greater than struct rte_regexdev_info::max_payload_size and/or
65899a2dd95SBruce Richardson  * matches can present across scan buffer boundaries.
65999a2dd95SBruce Richardson  *
66099a2dd95SBruce Richardson  * @see struct rte_regexdev_info::max_payload_size
66199a2dd95SBruce Richardson  * @see struct rte_regexdev_config::dev_cfg_flags, rte_regexdev_configure()
66299a2dd95SBruce Richardson  * @see RTE_REGEX_OPS_RSP_PMI_SOJ_F
66399a2dd95SBruce Richardson  * @see RTE_REGEX_OPS_RSP_PMI_EOJ_F
66499a2dd95SBruce Richardson  */
66599a2dd95SBruce Richardson 
66699a2dd95SBruce Richardson #define RTE_REGEXDEV_CFG_MATCH_AS_END_F (1ULL << 1)
66799a2dd95SBruce Richardson /**< Match as end is the ability to return the result as ending offset.
66899a2dd95SBruce Richardson  * When this flag is set, the result for each match will hold the ending
66999a2dd95SBruce Richardson  * offset of the match in end_offset.
67099a2dd95SBruce Richardson  * If this flag is not set, then the match result will hold the starting offset
67199a2dd95SBruce Richardson  * in start_offset, and the length of the match in len.
67299a2dd95SBruce Richardson  *
67399a2dd95SBruce Richardson  * @see RTE_REGEXDEV_SUPP_MATCH_AS_END_F
67499a2dd95SBruce Richardson  */
67599a2dd95SBruce Richardson 
67699a2dd95SBruce Richardson #define RTE_REGEXDEV_CFG_MATCH_ALL_F (1ULL << 2)
67799a2dd95SBruce Richardson /**< Match all is the ability to return all possible results.
67899a2dd95SBruce Richardson  *
67999a2dd95SBruce Richardson  * @see RTE_REGEXDEV_SUPP_MATCH_ALL_F
68099a2dd95SBruce Richardson  */
68199a2dd95SBruce Richardson 
68299a2dd95SBruce Richardson /** RegEx device configuration structure */
68399a2dd95SBruce Richardson struct rte_regexdev_config {
68499a2dd95SBruce Richardson 	uint16_t nb_max_matches;
68599a2dd95SBruce Richardson 	/**< Maximum matches per scan configured on this device.
68699a2dd95SBruce Richardson 	 * This value cannot exceed the *max_matches*
68799a2dd95SBruce Richardson 	 * which previously provided in rte_regexdev_info_get().
68899a2dd95SBruce Richardson 	 * The value 0 is allowed, in which case, value 1 used.
68999a2dd95SBruce Richardson 	 * @see struct rte_regexdev_info::max_matches
69099a2dd95SBruce Richardson 	 */
69199a2dd95SBruce Richardson 	uint16_t nb_queue_pairs;
69299a2dd95SBruce Richardson 	/**< Number of RegEx queue pairs to configure on this device.
69399a2dd95SBruce Richardson 	 * This value cannot exceed the *max_queue_pairs* which previously
69499a2dd95SBruce Richardson 	 * provided in rte_regexdev_info_get().
69599a2dd95SBruce Richardson 	 * @see struct rte_regexdev_info::max_queue_pairs
69699a2dd95SBruce Richardson 	 */
69799a2dd95SBruce Richardson 	uint32_t nb_rules_per_group;
69899a2dd95SBruce Richardson 	/**< Number of rules per group to configure on this device.
69999a2dd95SBruce Richardson 	 * This value cannot exceed the *max_rules_per_group*
70099a2dd95SBruce Richardson 	 * which previously provided in rte_regexdev_info_get().
70199a2dd95SBruce Richardson 	 * The value 0 is allowed, in which case,
70299a2dd95SBruce Richardson 	 * struct rte_regexdev_info::max_rules_per_group used.
70399a2dd95SBruce Richardson 	 * @see struct rte_regexdev_info::max_rules_per_group
70499a2dd95SBruce Richardson 	 */
70599a2dd95SBruce Richardson 	uint16_t nb_groups;
70699a2dd95SBruce Richardson 	/**< Number of groups to configure on this device.
70799a2dd95SBruce Richardson 	 * This value cannot exceed the *max_groups*
70899a2dd95SBruce Richardson 	 * which previously provided in rte_regexdev_info_get().
70999a2dd95SBruce Richardson 	 * @see struct rte_regexdev_info::max_groups
71099a2dd95SBruce Richardson 	 */
71199a2dd95SBruce Richardson 	const char *rule_db;
71299a2dd95SBruce Richardson 	/**< Import initial set of prebuilt rule database on this device.
71399a2dd95SBruce Richardson 	 * The value NULL is allowed, in which case, the device will not
71499a2dd95SBruce Richardson 	 * be configured prebuilt rule database. Application may use
71599a2dd95SBruce Richardson 	 * rte_regexdev_rule_db_update() or rte_regexdev_rule_db_import() API
71699a2dd95SBruce Richardson 	 * to update or import rule database after the
71799a2dd95SBruce Richardson 	 * rte_regexdev_configure().
71899a2dd95SBruce Richardson 	 * @see rte_regexdev_rule_db_update(), rte_regexdev_rule_db_import()
71999a2dd95SBruce Richardson 	 */
72099a2dd95SBruce Richardson 	uint32_t rule_db_len;
72199a2dd95SBruce Richardson 	/**< Length of *rule_db* buffer. */
72299a2dd95SBruce Richardson 	uint32_t dev_cfg_flags;
72399a2dd95SBruce Richardson 	/**< RegEx device configuration flags, See RTE_REGEXDEV_CFG_*  */
72499a2dd95SBruce Richardson };
72599a2dd95SBruce Richardson 
72699a2dd95SBruce Richardson /**
72799a2dd95SBruce Richardson  * @warning
72899a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
72999a2dd95SBruce Richardson  *
73099a2dd95SBruce Richardson  * Configure a RegEx device.
73199a2dd95SBruce Richardson  *
73299a2dd95SBruce Richardson  * This function must be invoked first before any other function in the
73399a2dd95SBruce Richardson  * API. This function can also be re-invoked when a device is in the
73499a2dd95SBruce Richardson  * stopped state.
73599a2dd95SBruce Richardson  *
73699a2dd95SBruce Richardson  * The caller may use rte_regexdev_info_get() to get the capability of each
73799a2dd95SBruce Richardson  * resources available for this regex device.
73899a2dd95SBruce Richardson  *
73999a2dd95SBruce Richardson  * @param dev_id
74099a2dd95SBruce Richardson  *   The identifier of the device to configure.
74199a2dd95SBruce Richardson  * @param cfg
74299a2dd95SBruce Richardson  *   The RegEx device configuration structure.
74399a2dd95SBruce Richardson  *
74499a2dd95SBruce Richardson  * @return
74599a2dd95SBruce Richardson  *   - 0: Success, device configured. Otherwise negative errno is returned.
74699a2dd95SBruce Richardson  */
74799a2dd95SBruce Richardson __rte_experimental
74899a2dd95SBruce Richardson int
74999a2dd95SBruce Richardson rte_regexdev_configure(uint8_t dev_id, const struct rte_regexdev_config *cfg);
75099a2dd95SBruce Richardson 
75199a2dd95SBruce Richardson /* Enumerates RegEx queue pair configuration flags */
75299a2dd95SBruce Richardson #define RTE_REGEX_QUEUE_PAIR_CFG_OOS_F (1ULL << 0)
75399a2dd95SBruce Richardson /**< Out of order scan, If not set, a scan must retire after previously issued
75499a2dd95SBruce Richardson  * in-order scans to this queue pair. If set, this scan can be retired as soon
75599a2dd95SBruce Richardson  * as device returns completion. Application should not set out of order scan
75699a2dd95SBruce Richardson  * flag if it needs to maintain the ingress order of scan request.
75799a2dd95SBruce Richardson  *
75899a2dd95SBruce Richardson  * @see struct rte_regexdev_qp_conf::qp_conf_flags
75999a2dd95SBruce Richardson  * @see rte_regexdev_queue_pair_setup()
76099a2dd95SBruce Richardson  */
76199a2dd95SBruce Richardson 
76299a2dd95SBruce Richardson struct rte_regex_ops;
76399a2dd95SBruce Richardson typedef void (*regexdev_stop_flush_t)(uint8_t dev_id, uint16_t qp_id,
76499a2dd95SBruce Richardson 				      struct rte_regex_ops *op);
76599a2dd95SBruce Richardson /**< Callback function called during rte_regexdev_stop(), invoked once per
76699a2dd95SBruce Richardson  * flushed RegEx op.
76799a2dd95SBruce Richardson  */
76899a2dd95SBruce Richardson 
76999a2dd95SBruce Richardson /** RegEx queue pair configuration structure */
77099a2dd95SBruce Richardson struct rte_regexdev_qp_conf {
77199a2dd95SBruce Richardson 	uint32_t qp_conf_flags;
77299a2dd95SBruce Richardson 	/**< Queue pair config flags, See RTE_REGEX_QUEUE_PAIR_CFG_* */
77399a2dd95SBruce Richardson 	uint16_t nb_desc;
77499a2dd95SBruce Richardson 	/**< The number of descriptors to allocate for this queue pair. */
77599a2dd95SBruce Richardson 	regexdev_stop_flush_t cb;
77699a2dd95SBruce Richardson 	/**< Callback function called during rte_regexdev_stop(), invoked
77799a2dd95SBruce Richardson 	 * once per flushed regex op. Value NULL is allowed, in which case
77899a2dd95SBruce Richardson 	 * callback will not be invoked. This function can be used to properly
77999a2dd95SBruce Richardson 	 * dispose of outstanding regex ops from response queue,
78099a2dd95SBruce Richardson 	 * for example ops containing memory pointers.
78199a2dd95SBruce Richardson 	 * @see rte_regexdev_stop()
78299a2dd95SBruce Richardson 	 */
78399a2dd95SBruce Richardson };
78499a2dd95SBruce Richardson 
78599a2dd95SBruce Richardson /**
78699a2dd95SBruce Richardson  * @warning
78799a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
78899a2dd95SBruce Richardson  *
78999a2dd95SBruce Richardson  * Allocate and set up a RegEx queue pair for a RegEx device.
79099a2dd95SBruce Richardson  *
79199a2dd95SBruce Richardson  * @param dev_id
79299a2dd95SBruce Richardson  *   The identifier of the device.
79399a2dd95SBruce Richardson  * @param queue_pair_id
79499a2dd95SBruce Richardson  *   The index of the RegEx queue pair to setup. The value must be in the range
79599a2dd95SBruce Richardson  *   [0, nb_queue_pairs - 1] previously supplied to rte_regexdev_configure().
79699a2dd95SBruce Richardson  * @param qp_conf
79799a2dd95SBruce Richardson  *   The pointer to the configuration data to be used for the RegEx queue pair.
79899a2dd95SBruce Richardson  *   NULL value is allowed, in which case default configuration	used.
79999a2dd95SBruce Richardson  *
80099a2dd95SBruce Richardson  * @return
80199a2dd95SBruce Richardson  *   0 on success. Otherwise negative errno is returned.
80299a2dd95SBruce Richardson  */
80399a2dd95SBruce Richardson __rte_experimental
80499a2dd95SBruce Richardson int
80599a2dd95SBruce Richardson rte_regexdev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
80699a2dd95SBruce Richardson 			      const struct rte_regexdev_qp_conf *qp_conf);
80799a2dd95SBruce Richardson 
80899a2dd95SBruce Richardson /**
80999a2dd95SBruce Richardson  * @warning
81099a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
81199a2dd95SBruce Richardson  *
81299a2dd95SBruce Richardson  * Start a RegEx device.
81399a2dd95SBruce Richardson  *
81499a2dd95SBruce Richardson  * The device start step is the last one and consists of setting the RegEx
81599a2dd95SBruce Richardson  * queues to start accepting the pattern matching scan requests.
81699a2dd95SBruce Richardson  *
81799a2dd95SBruce Richardson  * On success, all basic functions exported by the API (RegEx enqueue,
81899a2dd95SBruce Richardson  * RegEx dequeue and so on) can be invoked.
81999a2dd95SBruce Richardson  *
82099a2dd95SBruce Richardson  * @param dev_id
82199a2dd95SBruce Richardson  *   RegEx device identifier.
82299a2dd95SBruce Richardson  *
82399a2dd95SBruce Richardson  * @return
82499a2dd95SBruce Richardson  *   0 on success. Otherwise negative errno is returned.
82599a2dd95SBruce Richardson  */
82699a2dd95SBruce Richardson __rte_experimental
82799a2dd95SBruce Richardson int
82899a2dd95SBruce Richardson rte_regexdev_start(uint8_t dev_id);
82999a2dd95SBruce Richardson 
83099a2dd95SBruce Richardson /**
83199a2dd95SBruce Richardson  * @warning
83299a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
83399a2dd95SBruce Richardson  *
83499a2dd95SBruce Richardson  * Stop a RegEx device.
83599a2dd95SBruce Richardson  *
83699a2dd95SBruce Richardson  * Stop a RegEx device. The device can be restarted with a call to
83799a2dd95SBruce Richardson  * rte_regexdev_start().
83899a2dd95SBruce Richardson  *
83999a2dd95SBruce Richardson  * This function causes all queued response regex ops to be drained in the
84099a2dd95SBruce Richardson  * response queue. While draining ops out of the device,
84199a2dd95SBruce Richardson  * struct rte_regexdev_qp_conf::cb will be invoked for each ops.
84299a2dd95SBruce Richardson  *
84399a2dd95SBruce Richardson  * @param dev_id
84499a2dd95SBruce Richardson  *   RegEx device identifier.
84599a2dd95SBruce Richardson  *
84699a2dd95SBruce Richardson  * @return
84799a2dd95SBruce Richardson  *   0 on success. Otherwise negative errno is returned.
84899a2dd95SBruce Richardson  */
84999a2dd95SBruce Richardson __rte_experimental
85099a2dd95SBruce Richardson int
85199a2dd95SBruce Richardson rte_regexdev_stop(uint8_t dev_id);
85299a2dd95SBruce Richardson 
85399a2dd95SBruce Richardson /**
85499a2dd95SBruce Richardson  * @warning
85599a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
85699a2dd95SBruce Richardson  *
85799a2dd95SBruce Richardson  * Close a RegEx device. The device cannot be restarted!
85899a2dd95SBruce Richardson  *
85999a2dd95SBruce Richardson  * @param dev_id
86099a2dd95SBruce Richardson  *   RegEx device identifier
86199a2dd95SBruce Richardson  *
86299a2dd95SBruce Richardson  * @return
86399a2dd95SBruce Richardson  *   0 on success. Otherwise negative errno is returned.
86499a2dd95SBruce Richardson  */
86599a2dd95SBruce Richardson __rte_experimental
86699a2dd95SBruce Richardson int
86799a2dd95SBruce Richardson rte_regexdev_close(uint8_t dev_id);
86899a2dd95SBruce Richardson 
86999a2dd95SBruce Richardson /* Device get/set attributes */
87099a2dd95SBruce Richardson 
87199a2dd95SBruce Richardson /** Enumerates RegEx device attribute identifier */
87299a2dd95SBruce Richardson enum rte_regexdev_attr_id {
87399a2dd95SBruce Richardson 	RTE_REGEXDEV_ATTR_SOCKET_ID,
87499a2dd95SBruce Richardson 	/**< The NUMA socket id to which the device is connected or
87599a2dd95SBruce Richardson 	 * a default of zero if the socket could not be determined.
87699a2dd95SBruce Richardson 	 * datatype: *int*
87799a2dd95SBruce Richardson 	 * operation: *get*
87899a2dd95SBruce Richardson 	 */
87999a2dd95SBruce Richardson 	RTE_REGEXDEV_ATTR_MAX_MATCHES,
88099a2dd95SBruce Richardson 	/**< Maximum number of matches per scan.
88199a2dd95SBruce Richardson 	 * datatype: *uint8_t*
88299a2dd95SBruce Richardson 	 * operation: *get* and *set*
88399a2dd95SBruce Richardson 	 * @see RTE_REGEX_OPS_RSP_MAX_MATCH_F
88499a2dd95SBruce Richardson 	 */
88599a2dd95SBruce Richardson 	RTE_REGEXDEV_ATTR_MAX_SCAN_TIMEOUT,
88699a2dd95SBruce Richardson 	/**< Upper bound scan time in ns.
88799a2dd95SBruce Richardson 	 * datatype: *uint16_t*
88899a2dd95SBruce Richardson 	 * operation: *get* and *set*
88999a2dd95SBruce Richardson 	 * @see RTE_REGEX_OPS_RSP_MAX_SCAN_TIMEOUT_F
89099a2dd95SBruce Richardson 	 */
89199a2dd95SBruce Richardson 	RTE_REGEXDEV_ATTR_MAX_PREFIX,
89299a2dd95SBruce Richardson 	/**< Maximum number of prefix detected per scan.
89399a2dd95SBruce Richardson 	 * This would be useful for denial of service detection.
89499a2dd95SBruce Richardson 	 * datatype: *uint16_t*
89599a2dd95SBruce Richardson 	 * operation: *get* and *set*
89699a2dd95SBruce Richardson 	 * @see RTE_REGEX_OPS_RSP_MAX_PREFIX_F
89799a2dd95SBruce Richardson 	 */
89899a2dd95SBruce Richardson };
89999a2dd95SBruce Richardson 
90099a2dd95SBruce Richardson /**
90199a2dd95SBruce Richardson  * @warning
90299a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
90399a2dd95SBruce Richardson  *
90499a2dd95SBruce Richardson  * Get an attribute from a RegEx device.
90599a2dd95SBruce Richardson  *
90699a2dd95SBruce Richardson  * @param dev_id
90799a2dd95SBruce Richardson  *   RegEx device identifier.
90899a2dd95SBruce Richardson  * @param attr_id
90999a2dd95SBruce Richardson  *   The attribute ID to retrieve.
91099a2dd95SBruce Richardson  * @param attr_value
91199a2dd95SBruce Richardson  *   A pointer that will be filled in with the attribute
91299a2dd95SBruce Richardson  *   value if successful.
91399a2dd95SBruce Richardson  *
91499a2dd95SBruce Richardson  * @return
91599a2dd95SBruce Richardson  *   - 0: Successfully retrieved attribute value.
91699a2dd95SBruce Richardson  *   - -EINVAL: Invalid device or  *attr_id* provided, or *attr_value* is NULL.
91799a2dd95SBruce Richardson  *   - -ENOTSUP: if the device doesn't support specific *attr_id*.
91899a2dd95SBruce Richardson  */
91999a2dd95SBruce Richardson __rte_experimental
92099a2dd95SBruce Richardson int
92199a2dd95SBruce Richardson rte_regexdev_attr_get(uint8_t dev_id, enum rte_regexdev_attr_id attr_id,
92299a2dd95SBruce Richardson 		      void *attr_value);
92399a2dd95SBruce Richardson 
92499a2dd95SBruce Richardson /**
92599a2dd95SBruce Richardson  * @warning
92699a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
92799a2dd95SBruce Richardson  *
92899a2dd95SBruce Richardson  * Set an attribute to a RegEx device.
92999a2dd95SBruce Richardson  *
93099a2dd95SBruce Richardson  * @param dev_id
93199a2dd95SBruce Richardson  *   RegEx device identifier.
93299a2dd95SBruce Richardson  * @param attr_id
93399a2dd95SBruce Richardson  *   The attribute ID to retrieve.
93499a2dd95SBruce Richardson  * @param attr_value
93599a2dd95SBruce Richardson  *   Pointer that will be filled in with the attribute value
93699a2dd95SBruce Richardson  *   by the application.
93799a2dd95SBruce Richardson  *
93899a2dd95SBruce Richardson  * @return
93999a2dd95SBruce Richardson  *   - 0: Successfully applied the attribute value.
94099a2dd95SBruce Richardson  *   - -EINVAL: Invalid device or  *attr_id* provided, or *attr_value* is NULL.
94199a2dd95SBruce Richardson  *   - -ENOTSUP: if the device doesn't support specific *attr_id*.
94299a2dd95SBruce Richardson  */
94399a2dd95SBruce Richardson __rte_experimental
94499a2dd95SBruce Richardson int
94599a2dd95SBruce Richardson rte_regexdev_attr_set(uint8_t dev_id, enum rte_regexdev_attr_id attr_id,
94699a2dd95SBruce Richardson 		      const void *attr_value);
94799a2dd95SBruce Richardson 
94899a2dd95SBruce Richardson /* Rule related APIs */
94999a2dd95SBruce Richardson /** Enumerates RegEx rule operation. */
95099a2dd95SBruce Richardson enum rte_regexdev_rule_op {
95199a2dd95SBruce Richardson 	RTE_REGEX_RULE_OP_ADD,
95299a2dd95SBruce Richardson 	/**< Add RegEx rule to rule database. */
95399a2dd95SBruce Richardson 	RTE_REGEX_RULE_OP_REMOVE
95499a2dd95SBruce Richardson 	/**< Remove RegEx rule from rule database. */
95599a2dd95SBruce Richardson };
95699a2dd95SBruce Richardson 
95799a2dd95SBruce Richardson /** Structure to hold a RegEx rule attributes. */
95899a2dd95SBruce Richardson struct rte_regexdev_rule {
95999a2dd95SBruce Richardson 	enum rte_regexdev_rule_op op;
96099a2dd95SBruce Richardson 	/**< OP type of the rule either a OP_ADD or OP_DELETE. */
96199a2dd95SBruce Richardson 	uint16_t group_id;
96299a2dd95SBruce Richardson 	/**< Group identifier to which the rule belongs to. */
96399a2dd95SBruce Richardson 	uint32_t rule_id;
96499a2dd95SBruce Richardson 	/**< Rule identifier which is returned on successful match. */
96599a2dd95SBruce Richardson 	const char *pcre_rule;
96699a2dd95SBruce Richardson 	/**< Buffer to hold the PCRE rule. */
96799a2dd95SBruce Richardson 	uint16_t pcre_rule_len;
96899a2dd95SBruce Richardson 	/**< Length of the PCRE rule. */
96999a2dd95SBruce Richardson 	uint64_t rule_flags;
97099a2dd95SBruce Richardson 	/* PCRE rule flags. Supported device specific PCRE rules enumerated
97199a2dd95SBruce Richardson 	 * in struct rte_regexdev_info::rule_flags. For successful rule
97299a2dd95SBruce Richardson 	 * database update, application needs to provide only supported
97399a2dd95SBruce Richardson 	 * rule flags.
97499a2dd95SBruce Richardson 	 * @See RTE_REGEX_PCRE_RULE_*, struct rte_regexdev_info::rule_flags
97599a2dd95SBruce Richardson 	 */
97699a2dd95SBruce Richardson };
97799a2dd95SBruce Richardson 
97899a2dd95SBruce Richardson /**
97999a2dd95SBruce Richardson  * @warning
98099a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
98199a2dd95SBruce Richardson  *
98299a2dd95SBruce Richardson  * Update the local rule set.
98399a2dd95SBruce Richardson  * This functions only modify the rule set in memory.
98499a2dd95SBruce Richardson  * In order for the changes to take effect, the function
98599a2dd95SBruce Richardson  * rte_regexdev_rule_db_compile_active must be called.
98699a2dd95SBruce Richardson  *
98799a2dd95SBruce Richardson  * @param dev_id
98899a2dd95SBruce Richardson  *   RegEx device identifier.
98999a2dd95SBruce Richardson  * @param rules
99099a2dd95SBruce Richardson  *   Points to an array of *nb_rules* objects of type *rte_regexdev_rule*
99199a2dd95SBruce Richardson  *   structure which contain the regex rules attributes to be updated
99299a2dd95SBruce Richardson  *   in rule database.
99399a2dd95SBruce Richardson  * @param nb_rules
99499a2dd95SBruce Richardson  *   The number of PCRE rules to update the rule database.
99599a2dd95SBruce Richardson  *
99699a2dd95SBruce Richardson  * @return
99799a2dd95SBruce Richardson  *   The number of regex rules actually updated on the regex device's rule
99899a2dd95SBruce Richardson  *   database. The return value can be less than the value of the *nb_rules*
99999a2dd95SBruce Richardson  *   parameter when the regex devices fails to update the rule database or
100099a2dd95SBruce Richardson  *   if invalid parameters are specified in a *rte_regexdev_rule*.
100199a2dd95SBruce Richardson  *   If the return value is less than *nb_rules*, the remaining PCRE rules
100299a2dd95SBruce Richardson  *   at the end of *rules* are not consumed and the caller has to take
100399a2dd95SBruce Richardson  *   care of them and rte_errno is set accordingly.
100499a2dd95SBruce Richardson  *   Possible errno values include:
100599a2dd95SBruce Richardson  *   - -EINVAL:  Invalid device ID or rules is NULL
100699a2dd95SBruce Richardson  *   - -ENOTSUP: The last processed rule is not supported on this device.
100799a2dd95SBruce Richardson  *   - -ENOSPC: No space available in rule database.
100899a2dd95SBruce Richardson  *
100999a2dd95SBruce Richardson  * @see rte_regexdev_rule_db_import(), rte_regexdev_rule_db_export(),
101099a2dd95SBruce Richardson  *   rte_regexdev_rule_db_compile_activate()
101199a2dd95SBruce Richardson  */
101299a2dd95SBruce Richardson __rte_experimental
101399a2dd95SBruce Richardson int
101499a2dd95SBruce Richardson rte_regexdev_rule_db_update(uint8_t dev_id,
101599a2dd95SBruce Richardson 			    const struct rte_regexdev_rule *rules,
101699a2dd95SBruce Richardson 			    uint32_t nb_rules);
101799a2dd95SBruce Richardson 
101899a2dd95SBruce Richardson /**
101999a2dd95SBruce Richardson  * @warning
102099a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
102199a2dd95SBruce Richardson  *
102299a2dd95SBruce Richardson  * Compile local rule set and burn the complied result to the
10237be78d02SJosh Soref  * RegEx device.
102499a2dd95SBruce Richardson  *
102599a2dd95SBruce Richardson  * @param dev_id
102699a2dd95SBruce Richardson  *   RegEx device identifier.
102799a2dd95SBruce Richardson  *
102899a2dd95SBruce Richardson  * @return
102999a2dd95SBruce Richardson  *   0 on success, otherwise negative errno.
103099a2dd95SBruce Richardson  *
103199a2dd95SBruce Richardson  * @see rte_regexdev_rule_db_import(), rte_regexdev_rule_db_export(),
103299a2dd95SBruce Richardson  *   rte_regexdev_rule_db_update()
103399a2dd95SBruce Richardson  */
103499a2dd95SBruce Richardson __rte_experimental
103599a2dd95SBruce Richardson int
103699a2dd95SBruce Richardson rte_regexdev_rule_db_compile_activate(uint8_t dev_id);
103799a2dd95SBruce Richardson 
103899a2dd95SBruce Richardson /**
103999a2dd95SBruce Richardson  * @warning
104099a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
104199a2dd95SBruce Richardson  *
104299a2dd95SBruce Richardson  * Import a prebuilt rule database from a buffer to a RegEx device.
104399a2dd95SBruce Richardson  *
104499a2dd95SBruce Richardson  * @param dev_id
104599a2dd95SBruce Richardson  *   RegEx device identifier.
104699a2dd95SBruce Richardson  * @param rule_db
104799a2dd95SBruce Richardson  *   Points to prebuilt rule database.
104899a2dd95SBruce Richardson  * @param rule_db_len
104999a2dd95SBruce Richardson  *   Length of the rule database.
105099a2dd95SBruce Richardson  *
105199a2dd95SBruce Richardson  * @return
105299a2dd95SBruce Richardson  *   - 0: Successfully updated the prebuilt rule database.
105399a2dd95SBruce Richardson  *   - -EINVAL:  Invalid device ID or rule_db is NULL
105499a2dd95SBruce Richardson  *   - -ENOTSUP: Rule database import is not supported on this device.
105599a2dd95SBruce Richardson  *   - -ENOSPC: No space available in rule database.
105699a2dd95SBruce Richardson  *
105799a2dd95SBruce Richardson  * @see rte_regexdev_rule_db_update(), rte_regexdev_rule_db_export()
105899a2dd95SBruce Richardson  */
105999a2dd95SBruce Richardson __rte_experimental
106099a2dd95SBruce Richardson int
106199a2dd95SBruce Richardson rte_regexdev_rule_db_import(uint8_t dev_id, const char *rule_db,
106299a2dd95SBruce Richardson 			    uint32_t rule_db_len);
106399a2dd95SBruce Richardson 
106499a2dd95SBruce Richardson /**
106599a2dd95SBruce Richardson  * @warning
106699a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
106799a2dd95SBruce Richardson  *
106899a2dd95SBruce Richardson  * Export the prebuilt rule database from a RegEx device to the buffer.
106999a2dd95SBruce Richardson  *
107099a2dd95SBruce Richardson  * @param dev_id
107199a2dd95SBruce Richardson  *   RegEx device identifier.
107299a2dd95SBruce Richardson  * @param[out] rule_db
107399a2dd95SBruce Richardson  *   Block of memory to insert the rule database. Must be at least size in
107499a2dd95SBruce Richardson  *   capacity. If set to NULL, function returns required capacity.
107599a2dd95SBruce Richardson  *
107699a2dd95SBruce Richardson  * @return
107799a2dd95SBruce Richardson  *   - 0: Successfully exported the prebuilt rule database.
107899a2dd95SBruce Richardson  *   - size: If rule_db set to NULL then required capacity for *rule_db*
107999a2dd95SBruce Richardson  *   - -EINVAL:  Invalid device ID
108099a2dd95SBruce Richardson  *   - -ENOTSUP: Rule database export is not supported on this device.
108199a2dd95SBruce Richardson  *
108299a2dd95SBruce Richardson  * @see rte_regexdev_rule_db_update(), rte_regexdev_rule_db_import()
108399a2dd95SBruce Richardson  */
108499a2dd95SBruce Richardson __rte_experimental
108599a2dd95SBruce Richardson int
108699a2dd95SBruce Richardson rte_regexdev_rule_db_export(uint8_t dev_id, char *rule_db);
108799a2dd95SBruce Richardson 
108899a2dd95SBruce Richardson /* Extended statistics */
108999a2dd95SBruce Richardson /** Maximum name length for extended statistics counters */
109099a2dd95SBruce Richardson #define RTE_REGEXDEV_XSTATS_NAME_SIZE 64
109199a2dd95SBruce Richardson 
109299a2dd95SBruce Richardson /**
109399a2dd95SBruce Richardson  * A name-key lookup element for extended statistics.
109499a2dd95SBruce Richardson  *
109599a2dd95SBruce Richardson  * This structure is used to map between names and ID numbers
109699a2dd95SBruce Richardson  * for extended RegEx device statistics.
109799a2dd95SBruce Richardson  */
109899a2dd95SBruce Richardson struct rte_regexdev_xstats_map {
109999a2dd95SBruce Richardson 	uint16_t id;
110099a2dd95SBruce Richardson 	/**< xstat identifier */
110199a2dd95SBruce Richardson 	char name[RTE_REGEXDEV_XSTATS_NAME_SIZE];
110299a2dd95SBruce Richardson 	/**< xstat name */
110399a2dd95SBruce Richardson };
110499a2dd95SBruce Richardson 
110599a2dd95SBruce Richardson /**
110699a2dd95SBruce Richardson  * @warning
110799a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
110899a2dd95SBruce Richardson  *
110999a2dd95SBruce Richardson  * Retrieve names of extended statistics of a regex device.
111099a2dd95SBruce Richardson  *
111199a2dd95SBruce Richardson  * @param dev_id
111299a2dd95SBruce Richardson  *   The identifier of the regex device.
111399a2dd95SBruce Richardson  * @param[out] xstats_map
111499a2dd95SBruce Richardson  *   Block of memory to insert id and names into. Must be at least size in
111599a2dd95SBruce Richardson  *   capacity. If set to NULL, function returns required capacity.
111699a2dd95SBruce Richardson  * @return
111799a2dd95SBruce Richardson  *   - Positive value on success:
111899a2dd95SBruce Richardson  *        -The return value is the number of entries filled in the stats map.
111999a2dd95SBruce Richardson  *        -If xstats_map set to NULL then required capacity for xstats_map.
112099a2dd95SBruce Richardson  *   - Negative value on error:
112199a2dd95SBruce Richardson  *      -ENODEV for invalid *dev_id*
112299a2dd95SBruce Richardson  *      -ENOTSUP if the device doesn't support this function.
112399a2dd95SBruce Richardson  */
112499a2dd95SBruce Richardson __rte_experimental
112599a2dd95SBruce Richardson int
112699a2dd95SBruce Richardson rte_regexdev_xstats_names_get(uint8_t dev_id,
112799a2dd95SBruce Richardson 			      struct rte_regexdev_xstats_map *xstats_map);
112899a2dd95SBruce Richardson 
112999a2dd95SBruce Richardson /**
113099a2dd95SBruce Richardson  * @warning
113199a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
113299a2dd95SBruce Richardson  *
113399a2dd95SBruce Richardson  * Retrieve extended statistics of an regex device.
113499a2dd95SBruce Richardson  *
113599a2dd95SBruce Richardson  * @param dev_id
113699a2dd95SBruce Richardson  *   The identifier of the device.
113799a2dd95SBruce Richardson  * @param ids
113899a2dd95SBruce Richardson  *   The id numbers of the stats to get. The ids can be got from the stat
113999a2dd95SBruce Richardson  *   position in the stat list from rte_regexdev_xstats_names_get(), or
114099a2dd95SBruce Richardson  *   by using rte_regexdev_xstats_by_name_get().
114199a2dd95SBruce Richardson  * @param values
114299a2dd95SBruce Richardson  *   The values for each stats request by ID.
114399a2dd95SBruce Richardson  * @param nb_values
114499a2dd95SBruce Richardson  *   The number of stats requested.
114599a2dd95SBruce Richardson  * @return
114699a2dd95SBruce Richardson  *   - Positive value: number of stat entries filled into the values array
114799a2dd95SBruce Richardson  *   - Negative value on error:
114899a2dd95SBruce Richardson  *      -ENODEV for invalid *dev_id*
114999a2dd95SBruce Richardson  *      -ENOTSUP if the device doesn't support this function.
115099a2dd95SBruce Richardson  */
115199a2dd95SBruce Richardson __rte_experimental
115299a2dd95SBruce Richardson int
115399a2dd95SBruce Richardson rte_regexdev_xstats_get(uint8_t dev_id, const uint16_t *ids,
115499a2dd95SBruce Richardson 			uint64_t *values, uint16_t nb_values);
115599a2dd95SBruce Richardson 
115699a2dd95SBruce Richardson /**
115799a2dd95SBruce Richardson  * @warning
115899a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
115999a2dd95SBruce Richardson  *
116099a2dd95SBruce Richardson  * Retrieve the value of a single stat by requesting it by name.
116199a2dd95SBruce Richardson  *
116299a2dd95SBruce Richardson  * @param dev_id
116399a2dd95SBruce Richardson  *   The identifier of the device.
116499a2dd95SBruce Richardson  * @param name
116599a2dd95SBruce Richardson  *   The stat name to retrieve.
116699a2dd95SBruce Richardson  * @param id
116799a2dd95SBruce Richardson  *   If non-NULL, the numerical id of the stat will be returned, so that further
116899a2dd95SBruce Richardson  *   requests for the stat can be got using rte_regexdev_xstats_get, which will
116999a2dd95SBruce Richardson  *   be faster as it doesn't need to scan a list of names for the stat.
117099a2dd95SBruce Richardson  * @param[out] value
117199a2dd95SBruce Richardson  *   Must be non-NULL, retrieved xstat value will be stored in this address.
117299a2dd95SBruce Richardson  *
117399a2dd95SBruce Richardson  * @return
117499a2dd95SBruce Richardson  *   - 0: Successfully retrieved xstat value.
117599a2dd95SBruce Richardson  *   - -EINVAL: invalid parameters
117699a2dd95SBruce Richardson  *   - -ENOTSUP: if not supported.
117799a2dd95SBruce Richardson  */
117899a2dd95SBruce Richardson __rte_experimental
117999a2dd95SBruce Richardson int
118099a2dd95SBruce Richardson rte_regexdev_xstats_by_name_get(uint8_t dev_id, const char *name,
118199a2dd95SBruce Richardson 				uint16_t *id, uint64_t *value);
118299a2dd95SBruce Richardson 
118399a2dd95SBruce Richardson /**
118499a2dd95SBruce Richardson  * @warning
118599a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
118699a2dd95SBruce Richardson  *
118799a2dd95SBruce Richardson  * Reset the values of the xstats of the selected component in the device.
118899a2dd95SBruce Richardson  *
118999a2dd95SBruce Richardson  * @param dev_id
119099a2dd95SBruce Richardson  *   The identifier of the device.
119199a2dd95SBruce Richardson  * @param ids
119299a2dd95SBruce Richardson  *   Selects specific statistics to be reset. When NULL, all statistics will be
119399a2dd95SBruce Richardson  *   reset. If non-NULL, must point to array of at least *nb_ids* size.
119499a2dd95SBruce Richardson  * @param nb_ids
119599a2dd95SBruce Richardson  *   The number of ids available from the *ids* array. Ignored when ids is NULL.
119699a2dd95SBruce Richardson  *
119799a2dd95SBruce Richardson  * @return
119899a2dd95SBruce Richardson  *   - 0: Successfully reset the statistics to zero.
119999a2dd95SBruce Richardson  *   - -EINVAL: invalid parameters.
120099a2dd95SBruce Richardson  *   - -ENOTSUP: if not supported.
120199a2dd95SBruce Richardson  */
120299a2dd95SBruce Richardson __rte_experimental
120399a2dd95SBruce Richardson int
120499a2dd95SBruce Richardson rte_regexdev_xstats_reset(uint8_t dev_id, const uint16_t *ids,
120599a2dd95SBruce Richardson 			  uint16_t nb_ids);
120699a2dd95SBruce Richardson 
120799a2dd95SBruce Richardson /**
120899a2dd95SBruce Richardson  * @warning
120999a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
121099a2dd95SBruce Richardson  *
121199a2dd95SBruce Richardson  * Trigger the RegEx device self test.
121299a2dd95SBruce Richardson  *
121399a2dd95SBruce Richardson  * @param dev_id
121499a2dd95SBruce Richardson  *   The identifier of the device.
121599a2dd95SBruce Richardson  * @return
121699a2dd95SBruce Richardson  *   - 0: Selftest successful.
121799a2dd95SBruce Richardson  *   - -ENOTSUP if the device doesn't support selftest.
121899a2dd95SBruce Richardson  *   - other values < 0 on failure.
121999a2dd95SBruce Richardson  */
122099a2dd95SBruce Richardson __rte_experimental
122199a2dd95SBruce Richardson int
122299a2dd95SBruce Richardson rte_regexdev_selftest(uint8_t dev_id);
122399a2dd95SBruce Richardson 
122499a2dd95SBruce Richardson /**
122599a2dd95SBruce Richardson  * @warning
122699a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
122799a2dd95SBruce Richardson  *
122899a2dd95SBruce Richardson  * Dump internal information about *dev_id* to the FILE* provided in *f*.
122999a2dd95SBruce Richardson  *
123099a2dd95SBruce Richardson  * @param dev_id
123199a2dd95SBruce Richardson  *   The identifier of the device.
123299a2dd95SBruce Richardson  * @param f
123399a2dd95SBruce Richardson  *   A pointer to a file for output.
123499a2dd95SBruce Richardson  *
123599a2dd95SBruce Richardson  * @return
123699a2dd95SBruce Richardson  *   0 on success, negative errno on failure.
123799a2dd95SBruce Richardson  */
123899a2dd95SBruce Richardson __rte_experimental
123999a2dd95SBruce Richardson int
124099a2dd95SBruce Richardson rte_regexdev_dump(uint8_t dev_id, FILE *f);
124199a2dd95SBruce Richardson 
124299a2dd95SBruce Richardson /* Fast path APIs */
124399a2dd95SBruce Richardson 
124499a2dd95SBruce Richardson /**
124599a2dd95SBruce Richardson  * The generic *rte_regexdev_match* structure to hold the RegEx match
124699a2dd95SBruce Richardson  * attributes.
124799a2dd95SBruce Richardson  * @see struct rte_regex_ops::matches
124899a2dd95SBruce Richardson  */
124999a2dd95SBruce Richardson struct rte_regexdev_match {
125099a2dd95SBruce Richardson 	union {
125199a2dd95SBruce Richardson 		uint64_t u64;
125299a2dd95SBruce Richardson 		struct {
125399a2dd95SBruce Richardson 			uint32_t rule_id:20;
125499a2dd95SBruce Richardson 			/**< Rule identifier to which the pattern matched.
125599a2dd95SBruce Richardson 			 * @see struct rte_regexdev_rule::rule_id
125699a2dd95SBruce Richardson 			 */
125799a2dd95SBruce Richardson 			uint32_t group_id:12;
125899a2dd95SBruce Richardson 			/**< Group identifier of the rule which the pattern
125999a2dd95SBruce Richardson 			 * matched. @see struct rte_regexdev_rule::group_id
126099a2dd95SBruce Richardson 			 */
126199a2dd95SBruce Richardson 			uint16_t start_offset;
126299a2dd95SBruce Richardson 			/**< Starting Byte Position for matched rule. */
126399a2dd95SBruce Richardson 			union {
126499a2dd95SBruce Richardson 				uint16_t len;
126599a2dd95SBruce Richardson 				/**< Length of match in bytes */
126699a2dd95SBruce Richardson 				uint16_t end_offset;
126799a2dd95SBruce Richardson 				/**< The end offset of the match. In case
126899a2dd95SBruce Richardson 				 * MATCH_AS_END configuration is enabled.
126999a2dd95SBruce Richardson 				 * @see RTE_REGEXDEV_CFG_MATCH_AS_END
127099a2dd95SBruce Richardson 				 */
127199a2dd95SBruce Richardson 			};
127299a2dd95SBruce Richardson 		};
127399a2dd95SBruce Richardson 	};
127499a2dd95SBruce Richardson };
127599a2dd95SBruce Richardson 
127699a2dd95SBruce Richardson /* Enumerates RegEx request flags. */
127799a2dd95SBruce Richardson #define RTE_REGEX_OPS_REQ_GROUP_ID0_VALID_F (1 << 0)
127899a2dd95SBruce Richardson /**< Set when struct rte_regexdev_rule::group_id0 is valid. */
127999a2dd95SBruce Richardson 
128099a2dd95SBruce Richardson #define RTE_REGEX_OPS_REQ_GROUP_ID1_VALID_F (1 << 1)
128199a2dd95SBruce Richardson /**< Set when struct rte_regexdev_rule::group_id1 is valid. */
128299a2dd95SBruce Richardson 
128399a2dd95SBruce Richardson #define RTE_REGEX_OPS_REQ_GROUP_ID2_VALID_F (1 << 2)
128499a2dd95SBruce Richardson /**< Set when struct rte_regexdev_rule::group_id2 is valid. */
128599a2dd95SBruce Richardson 
128699a2dd95SBruce Richardson #define RTE_REGEX_OPS_REQ_GROUP_ID3_VALID_F (1 << 3)
128799a2dd95SBruce Richardson /**< Set when struct rte_regexdev_rule::group_id3 is valid. */
128899a2dd95SBruce Richardson 
128999a2dd95SBruce Richardson #define RTE_REGEX_OPS_REQ_STOP_ON_MATCH_F (1 << 4)
129099a2dd95SBruce Richardson /**< The RegEx engine will stop scanning and return the first match. */
129199a2dd95SBruce Richardson 
129299a2dd95SBruce Richardson #define RTE_REGEX_OPS_REQ_MATCH_HIGH_PRIORITY_F (1 << 5)
129399a2dd95SBruce Richardson /**< In High Priority mode a maximum of one match will be returned per scan to
129499a2dd95SBruce Richardson  * reduce the post-processing required by the application. The match with the
129599a2dd95SBruce Richardson  * lowest Rule id, lowest start pointer and lowest match length will be
129699a2dd95SBruce Richardson  * returned.
129799a2dd95SBruce Richardson  *
129899a2dd95SBruce Richardson  * @see struct rte_regex_ops::nb_actual_matches
129999a2dd95SBruce Richardson  * @see struct rte_regex_ops::nb_matches
130099a2dd95SBruce Richardson  */
130199a2dd95SBruce Richardson 
130299a2dd95SBruce Richardson 
130399a2dd95SBruce Richardson /* Enumerates RegEx response flags. */
130499a2dd95SBruce Richardson #define RTE_REGEX_OPS_RSP_PMI_SOJ_F (1 << 0)
130599a2dd95SBruce Richardson /**< Indicates that the RegEx device has encountered a partial match at the
130699a2dd95SBruce Richardson  * start of scan in the given buffer.
130799a2dd95SBruce Richardson  *
130899a2dd95SBruce Richardson  * @see RTE_REGEXDEV_CFG_CROSS_BUFFER_SCAN_F
130999a2dd95SBruce Richardson  */
131099a2dd95SBruce Richardson 
131199a2dd95SBruce Richardson #define RTE_REGEX_OPS_RSP_PMI_EOJ_F (1 << 1)
131299a2dd95SBruce Richardson /**< Indicates that the RegEx device has encountered a partial match at the
131399a2dd95SBruce Richardson  * end of scan in the given buffer.
131499a2dd95SBruce Richardson  *
131599a2dd95SBruce Richardson  * @see RTE_REGEXDEV_CFG_CROSS_BUFFER_SCAN_F
131699a2dd95SBruce Richardson  */
131799a2dd95SBruce Richardson 
131899a2dd95SBruce Richardson #define RTE_REGEX_OPS_RSP_MAX_SCAN_TIMEOUT_F (1 << 2)
131999a2dd95SBruce Richardson /**< Indicates that the RegEx device has exceeded the max timeout while
132099a2dd95SBruce Richardson  * scanning the given buffer.
132199a2dd95SBruce Richardson  *
132299a2dd95SBruce Richardson  * @see RTE_REGEXDEV_ATTR_MAX_SCAN_TIMEOUT
132399a2dd95SBruce Richardson  */
132499a2dd95SBruce Richardson 
132599a2dd95SBruce Richardson #define RTE_REGEX_OPS_RSP_MAX_MATCH_F (1 << 3)
132699a2dd95SBruce Richardson /**< Indicates that the RegEx device has exceeded the max matches while
132799a2dd95SBruce Richardson  * scanning the given buffer.
132899a2dd95SBruce Richardson  *
132999a2dd95SBruce Richardson  * @see RTE_REGEXDEV_ATTR_MAX_MATCHES
133099a2dd95SBruce Richardson  */
133199a2dd95SBruce Richardson 
133299a2dd95SBruce Richardson #define RTE_REGEX_OPS_RSP_MAX_PREFIX_F (1 << 4)
133399a2dd95SBruce Richardson /**< Indicates that the RegEx device has reached the max allowed prefix length
133499a2dd95SBruce Richardson  * while scanning the given buffer.
133599a2dd95SBruce Richardson  *
133699a2dd95SBruce Richardson  * @see RTE_REGEXDEV_ATTR_MAX_PREFIX
133799a2dd95SBruce Richardson  */
133899a2dd95SBruce Richardson 
133999a2dd95SBruce Richardson #define RTE_REGEX_OPS_RSP_RESOURCE_LIMIT_REACHED_F (1 << 4)
134099a2dd95SBruce Richardson /**< Indicates that the RegEx device has reached the max allowed resource
134199a2dd95SBruce Richardson  * allowed while scanning the given buffer.
134299a2dd95SBruce Richardson  */
134399a2dd95SBruce Richardson 
134499a2dd95SBruce Richardson /**
134599a2dd95SBruce Richardson  * The generic *rte_regex_ops* structure to hold the RegEx attributes
134699a2dd95SBruce Richardson  * for enqueue and dequeue operation.
134799a2dd95SBruce Richardson  */
134899a2dd95SBruce Richardson struct rte_regex_ops {
134999a2dd95SBruce Richardson 	/* W0 */
135099a2dd95SBruce Richardson 	uint16_t req_flags;
135199a2dd95SBruce Richardson 	/**< Request flags for the RegEx ops.
135299a2dd95SBruce Richardson 	 * @see RTE_REGEX_OPS_REQ_*
135399a2dd95SBruce Richardson 	 */
135499a2dd95SBruce Richardson 	uint16_t rsp_flags;
135599a2dd95SBruce Richardson 	/**< Response flags for the RegEx ops.
135699a2dd95SBruce Richardson 	 * @see RTE_REGEX_OPS_RSP_*
135799a2dd95SBruce Richardson 	 */
135899a2dd95SBruce Richardson 	uint16_t nb_actual_matches;
135999a2dd95SBruce Richardson 	/**< The total number of actual matches detected by the Regex device.*/
136099a2dd95SBruce Richardson 	uint16_t nb_matches;
136199a2dd95SBruce Richardson 	/**< The total number of matches returned by the RegEx device for this
136299a2dd95SBruce Richardson 	 * scan. The size of *rte_regex_ops::matches* zero length array will be
136399a2dd95SBruce Richardson 	 * this value.
136499a2dd95SBruce Richardson 	 *
136599a2dd95SBruce Richardson 	 * @see struct rte_regex_ops::matches, struct rte_regexdev_match
136699a2dd95SBruce Richardson 	 */
136799a2dd95SBruce Richardson 
136899a2dd95SBruce Richardson 	/* W1 */
136999a2dd95SBruce Richardson 	struct rte_mbuf *mbuf; /**< source mbuf, to search in. */
137099a2dd95SBruce Richardson 
137199a2dd95SBruce Richardson 	/* W2 */
137299a2dd95SBruce Richardson 	uint16_t group_id0;
137399a2dd95SBruce Richardson 	/**< First group_id to match the rule against. At minimum one group
137499a2dd95SBruce Richardson 	 * should be valid. Behaviour is undefined non of the groups are valid.
137599a2dd95SBruce Richardson 	 *
137699a2dd95SBruce Richardson 	 * @see RTE_REGEX_OPS_REQ_GROUP_ID0_VALID_F
137799a2dd95SBruce Richardson 	 */
137899a2dd95SBruce Richardson 	uint16_t group_id1;
137999a2dd95SBruce Richardson 	/**< Second group_id to match the rule against.
138099a2dd95SBruce Richardson 	 *
138199a2dd95SBruce Richardson 	 * @see RTE_REGEX_OPS_REQ_GROUP_ID1_VALID_F
138299a2dd95SBruce Richardson 	 */
138399a2dd95SBruce Richardson 	uint16_t group_id2;
138499a2dd95SBruce Richardson 	/**< Third group_id to match the rule against.
138599a2dd95SBruce Richardson 	 *
138699a2dd95SBruce Richardson 	 * @see RTE_REGEX_OPS_REQ_GROUP_ID2_VALID_F
138799a2dd95SBruce Richardson 	 */
138899a2dd95SBruce Richardson 	uint16_t group_id3;
138999a2dd95SBruce Richardson 	/**< Forth group_id to match the rule against.
139099a2dd95SBruce Richardson 	 *
139199a2dd95SBruce Richardson 	 * @see RTE_REGEX_OPS_REQ_GROUP_ID3_VALID_F
139299a2dd95SBruce Richardson 	 */
139399a2dd95SBruce Richardson 
139499a2dd95SBruce Richardson 	/* W3 */
139599a2dd95SBruce Richardson 	union {
139699a2dd95SBruce Richardson 		uint64_t user_id;
139799a2dd95SBruce Richardson 		/**< Application specific opaque value. An application may use
139899a2dd95SBruce Richardson 		 * this field to hold application specific value to share
139999a2dd95SBruce Richardson 		 * between dequeue and enqueue operation.
140099a2dd95SBruce Richardson 		 * Implementation should not modify this field.
140199a2dd95SBruce Richardson 		 */
140299a2dd95SBruce Richardson 		void *user_ptr;
140399a2dd95SBruce Richardson 		/**< Pointer representation of *user_id* */
140499a2dd95SBruce Richardson 	};
140599a2dd95SBruce Richardson 
140699a2dd95SBruce Richardson 	/* W4 */
140799a2dd95SBruce Richardson 	union {
140899a2dd95SBruce Richardson 		uint64_t cross_buf_id;
140999a2dd95SBruce Richardson 		/**< ID used by the RegEx device in order to support cross
141099a2dd95SBruce Richardson 		 * packet detection.
141199a2dd95SBruce Richardson 		 * This ID is returned from the RegEx device on the dequeue
141299a2dd95SBruce Richardson 		 * function. The application must send it back when calling
141399a2dd95SBruce Richardson 		 * enqueue with the following packet.
141499a2dd95SBruce Richardson 		 */
141599a2dd95SBruce Richardson 		void *cross_buf_ptr;
141699a2dd95SBruce Richardson 		/**< Pointer representation of *corss_buf_id* */
141799a2dd95SBruce Richardson 	};
141899a2dd95SBruce Richardson 
141999a2dd95SBruce Richardson 	/* W5 */
142099a2dd95SBruce Richardson 	struct rte_regexdev_match matches[];
142199a2dd95SBruce Richardson 	/**< Zero length array to hold the match tuples.
142299a2dd95SBruce Richardson 	 * The struct rte_regex_ops::nb_matches value holds the number of
142399a2dd95SBruce Richardson 	 * elements in this array.
142499a2dd95SBruce Richardson 	 *
142599a2dd95SBruce Richardson 	 * @see struct rte_regex_ops::nb_matches
142699a2dd95SBruce Richardson 	 */
142799a2dd95SBruce Richardson };
142899a2dd95SBruce Richardson 
142999a2dd95SBruce Richardson #include "rte_regexdev_core.h"
143099a2dd95SBruce Richardson 
143199a2dd95SBruce Richardson /**
143299a2dd95SBruce Richardson  * @warning
143399a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
143499a2dd95SBruce Richardson  *
143599a2dd95SBruce Richardson  * Enqueue a burst of scan request on a RegEx device.
143699a2dd95SBruce Richardson  *
143799a2dd95SBruce Richardson  * The rte_regexdev_enqueue_burst() function is invoked to place
143899a2dd95SBruce Richardson  * regex operations on the queue *qp_id* of the device designated by
143999a2dd95SBruce Richardson  * its *dev_id*.
144099a2dd95SBruce Richardson  *
144199a2dd95SBruce Richardson  * The *nb_ops* parameter is the number of operations to process which are
144299a2dd95SBruce Richardson  * supplied in the *ops* array of *rte_regexdev_op* structures.
144399a2dd95SBruce Richardson  *
144499a2dd95SBruce Richardson  * The rte_regexdev_enqueue_burst() function returns the number of
144599a2dd95SBruce Richardson  * operations it actually enqueued for processing. A return value equal to
144699a2dd95SBruce Richardson  * *nb_ops* means that all packets have been enqueued.
144799a2dd95SBruce Richardson  *
144899a2dd95SBruce Richardson  * @param dev_id
144999a2dd95SBruce Richardson  *   The identifier of the device.
145099a2dd95SBruce Richardson  * @param qp_id
145199a2dd95SBruce Richardson  *   The index of the queue pair which packets are to be enqueued for
145299a2dd95SBruce Richardson  *   processing. The value must be in the range [0, nb_queue_pairs - 1]
145399a2dd95SBruce Richardson  *   previously supplied to rte_regexdev_configure().
145499a2dd95SBruce Richardson  * @param ops
145599a2dd95SBruce Richardson  *   The address of an array of *nb_ops* pointers to *rte_regexdev_op*
145699a2dd95SBruce Richardson  *   structures which contain the regex operations to be processed.
145799a2dd95SBruce Richardson  * @param nb_ops
145899a2dd95SBruce Richardson  *   The number of operations to process.
145999a2dd95SBruce Richardson  *
146099a2dd95SBruce Richardson  * @return
146199a2dd95SBruce Richardson  *   The number of operations actually enqueued on the regex device. The return
146299a2dd95SBruce Richardson  *   value can be less than the value of the *nb_ops* parameter when the
146399a2dd95SBruce Richardson  *   regex devices queue is full or if invalid parameters are specified in
146499a2dd95SBruce Richardson  *   a *rte_regexdev_op*. If the return value is less than *nb_ops*, the
146599a2dd95SBruce Richardson  *   remaining ops at the end of *ops* are not consumed and the caller has
146699a2dd95SBruce Richardson  *   to take care of them.
146799a2dd95SBruce Richardson  */
146899a2dd95SBruce Richardson __rte_experimental
146999a2dd95SBruce Richardson static inline uint16_t
147099a2dd95SBruce Richardson rte_regexdev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
147199a2dd95SBruce Richardson 			   struct rte_regex_ops **ops, uint16_t nb_ops)
147299a2dd95SBruce Richardson {
147399a2dd95SBruce Richardson 	struct rte_regexdev *dev = &rte_regex_devices[dev_id];
147499a2dd95SBruce Richardson #ifdef RTE_LIBRTE_REGEXDEV_DEBUG
147599a2dd95SBruce Richardson 	RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL);
14768f1d23ecSDavid Marchand 	if (*dev->enqueue == NULL)
14778f1d23ecSDavid Marchand 		return -ENOTSUP;
147899a2dd95SBruce Richardson 	if (qp_id >= dev->data->dev_conf.nb_queue_pairs) {
14790e21c7c0SDavid Marchand 		RTE_REGEXDEV_LOG_LINE(ERR, "Invalid queue %d", qp_id);
148099a2dd95SBruce Richardson 		return -EINVAL;
148199a2dd95SBruce Richardson 	}
148299a2dd95SBruce Richardson #endif
148399a2dd95SBruce Richardson 	return (*dev->enqueue)(dev, qp_id, ops, nb_ops);
148499a2dd95SBruce Richardson }
148599a2dd95SBruce Richardson 
148699a2dd95SBruce Richardson /**
148799a2dd95SBruce Richardson  * @warning
148899a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice.
148999a2dd95SBruce Richardson  *
149099a2dd95SBruce Richardson  * Dequeue a burst of scan response from a queue on the RegEx device.
149199a2dd95SBruce Richardson  * The dequeued operation are stored in *rte_regexdev_op* structures
149299a2dd95SBruce Richardson  * whose pointers are supplied in the *ops* array.
149399a2dd95SBruce Richardson  *
149499a2dd95SBruce Richardson  * The rte_regexdev_dequeue_burst() function returns the number of ops
149599a2dd95SBruce Richardson  * actually dequeued, which is the number of *rte_regexdev_op* data structures
149699a2dd95SBruce Richardson  * effectively supplied into the *ops* array.
149799a2dd95SBruce Richardson  *
149899a2dd95SBruce Richardson  * A return value equal to *nb_ops* indicates that the queue contained
149999a2dd95SBruce Richardson  * at least *nb_ops* operations, and this is likely to signify that other
150099a2dd95SBruce Richardson  * processed operations remain in the devices output queue. Applications
150199a2dd95SBruce Richardson  * implementing a "retrieve as many processed operations as possible" policy
150299a2dd95SBruce Richardson  * can check this specific case and keep invoking the
150399a2dd95SBruce Richardson  * rte_regexdev_dequeue_burst() function until a value less than
150499a2dd95SBruce Richardson  * *nb_ops* is returned.
150599a2dd95SBruce Richardson  *
150699a2dd95SBruce Richardson  * The rte_regexdev_dequeue_burst() function does not provide any error
150799a2dd95SBruce Richardson  * notification to avoid the corresponding overhead.
150899a2dd95SBruce Richardson  *
150999a2dd95SBruce Richardson  * @param dev_id
151099a2dd95SBruce Richardson  *   The RegEx device identifier
151199a2dd95SBruce Richardson  * @param qp_id
151299a2dd95SBruce Richardson  *   The index of the queue pair from which to retrieve processed packets.
151399a2dd95SBruce Richardson  *   The value must be in the range [0, nb_queue_pairs - 1] previously
151499a2dd95SBruce Richardson  *   supplied to rte_regexdev_configure().
151599a2dd95SBruce Richardson  * @param ops
151699a2dd95SBruce Richardson  *   The address of an array of pointers to *rte_regexdev_op* structures
151799a2dd95SBruce Richardson  *   that must be large enough to store *nb_ops* pointers in it.
151899a2dd95SBruce Richardson  * @param nb_ops
151999a2dd95SBruce Richardson  *   The maximum number of operations to dequeue.
152099a2dd95SBruce Richardson  *
152199a2dd95SBruce Richardson  * @return
152299a2dd95SBruce Richardson  *   The number of operations actually dequeued, which is the number
152399a2dd95SBruce Richardson  *   of pointers to *rte_regexdev_op* structures effectively supplied to the
152499a2dd95SBruce Richardson  *   *ops* array. If the return value is less than *nb_ops*, the remaining
152599a2dd95SBruce Richardson  *   ops at the end of *ops* are not consumed and the caller has to take care
152699a2dd95SBruce Richardson  *   of them.
152799a2dd95SBruce Richardson  */
152899a2dd95SBruce Richardson __rte_experimental
152999a2dd95SBruce Richardson static inline uint16_t
153099a2dd95SBruce Richardson rte_regexdev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
153199a2dd95SBruce Richardson 			   struct rte_regex_ops **ops, uint16_t nb_ops)
153299a2dd95SBruce Richardson {
153399a2dd95SBruce Richardson 	struct rte_regexdev *dev = &rte_regex_devices[dev_id];
153499a2dd95SBruce Richardson #ifdef RTE_LIBRTE_REGEXDEV_DEBUG
153599a2dd95SBruce Richardson 	RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL);
15368f1d23ecSDavid Marchand 	if (*dev->dequeue == NULL)
15378f1d23ecSDavid Marchand 		return -ENOTSUP;
153899a2dd95SBruce Richardson 	if (qp_id >= dev->data->dev_conf.nb_queue_pairs) {
15390e21c7c0SDavid Marchand 		RTE_REGEXDEV_LOG_LINE(ERR, "Invalid queue %d", qp_id);
154099a2dd95SBruce Richardson 		return -EINVAL;
154199a2dd95SBruce Richardson 	}
154299a2dd95SBruce Richardson #endif
154399a2dd95SBruce Richardson 	return (*dev->dequeue)(dev, qp_id, ops, nb_ops);
154499a2dd95SBruce Richardson }
154599a2dd95SBruce Richardson 
154699a2dd95SBruce Richardson #ifdef __cplusplus
154799a2dd95SBruce Richardson }
154899a2dd95SBruce Richardson #endif
154999a2dd95SBruce Richardson 
155099a2dd95SBruce Richardson #endif /* _RTE_REGEXDEV_H_ */
1551