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