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