xref: /dpdk/lib/regexdev/rte_regexdev_core.h (revision c6552d9a8deffa448de2d5e2e726f50508c1efd2)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright 2020 Mellanox Technologies, Ltd
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef _RTE_REGEX_CORE_H_
699a2dd95SBruce Richardson #define _RTE_REGEX_CORE_H_
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson /**
999a2dd95SBruce Richardson  * @file
1099a2dd95SBruce Richardson  *
1199a2dd95SBruce Richardson  * RTE RegEx Device internal header.
1299a2dd95SBruce Richardson  *
1399a2dd95SBruce Richardson  * This header contains internal data types, that are used by the RegEx devices
1499a2dd95SBruce Richardson  * in order to expose their ops to the class.
1599a2dd95SBruce Richardson  *
1699a2dd95SBruce Richardson  * Applications should not use these API directly.
1799a2dd95SBruce Richardson  */
1899a2dd95SBruce Richardson 
1999a2dd95SBruce Richardson struct rte_regexdev;
2099a2dd95SBruce Richardson 
2199a2dd95SBruce Richardson typedef int (*regexdev_info_get_t)(struct rte_regexdev *dev,
2299a2dd95SBruce Richardson 				   struct rte_regexdev_info *info);
2399a2dd95SBruce Richardson /**< @internal Get the RegEx device info. */
2499a2dd95SBruce Richardson 
2599a2dd95SBruce Richardson typedef int (*regexdev_configure_t)(struct rte_regexdev *dev,
2699a2dd95SBruce Richardson 				    const struct rte_regexdev_config *cfg);
2799a2dd95SBruce Richardson /**< @internal Configure the RegEx device. */
2899a2dd95SBruce Richardson 
2999a2dd95SBruce Richardson typedef int (*regexdev_qp_setup_t)(struct rte_regexdev *dev, uint16_t id,
3099a2dd95SBruce Richardson 				   const struct rte_regexdev_qp_conf *qp_conf);
3199a2dd95SBruce Richardson /**< @internal Setup a queue pair.*/
3299a2dd95SBruce Richardson 
3399a2dd95SBruce Richardson typedef int (*regexdev_start_t)(struct rte_regexdev *dev);
3499a2dd95SBruce Richardson /**< @internal Start the RegEx device. */
3599a2dd95SBruce Richardson 
3699a2dd95SBruce Richardson typedef int (*regexdev_stop_t)(struct rte_regexdev *dev);
3799a2dd95SBruce Richardson /**< @internal Stop the RegEx device. */
3899a2dd95SBruce Richardson 
3999a2dd95SBruce Richardson typedef int (*regexdev_close_t)(struct rte_regexdev *dev);
4099a2dd95SBruce Richardson /**< @internal Close the RegEx device. */
4199a2dd95SBruce Richardson 
4299a2dd95SBruce Richardson typedef int (*regexdev_attr_get_t)(struct rte_regexdev *dev,
4399a2dd95SBruce Richardson 				   enum rte_regexdev_attr_id id,
4499a2dd95SBruce Richardson 				   void *value);
4599a2dd95SBruce Richardson /**< @internal Get selected attribute from RegEx device. */
4699a2dd95SBruce Richardson 
4799a2dd95SBruce Richardson typedef int (*regexdev_attr_set_t)(struct rte_regexdev *dev,
4899a2dd95SBruce Richardson 				   enum rte_regexdev_attr_id id,
4999a2dd95SBruce Richardson 				   const void *value);
5099a2dd95SBruce Richardson /**< @internal Set selected attribute to RegEx device. */
5199a2dd95SBruce Richardson 
5299a2dd95SBruce Richardson typedef int (*regexdev_rule_db_update_t)(struct rte_regexdev *dev,
5399a2dd95SBruce Richardson 					 const struct rte_regexdev_rule *rules,
5499a2dd95SBruce Richardson 					 uint16_t nb_rules);
5599a2dd95SBruce Richardson /**< @internal Update the rule database for the RegEx device. */
5699a2dd95SBruce Richardson 
5799a2dd95SBruce Richardson typedef int (*regexdev_rule_db_compile_activate_t)(struct rte_regexdev *dev);
5899a2dd95SBruce Richardson /**< @internal Compile the rule database and activate it. */
5999a2dd95SBruce Richardson 
6099a2dd95SBruce Richardson typedef int (*regexdev_rule_db_import_t)(struct rte_regexdev *dev,
6199a2dd95SBruce Richardson 					 const  char *rule_db,
6299a2dd95SBruce Richardson 					 uint32_t rule_db_len);
6399a2dd95SBruce Richardson /**< @internal Upload a pre created rule database to the RegEx device. */
6499a2dd95SBruce Richardson 
6599a2dd95SBruce Richardson typedef int (*regexdev_rule_db_export_t)(struct rte_regexdev *dev,
6699a2dd95SBruce Richardson 					 char *rule_db);
6799a2dd95SBruce Richardson /**< @internal Export the current rule database from the RegEx device. */
6899a2dd95SBruce Richardson 
6999a2dd95SBruce Richardson typedef int (*regexdev_xstats_names_get_t)(struct rte_regexdev *dev,
7099a2dd95SBruce Richardson 					   struct rte_regexdev_xstats_map
7199a2dd95SBruce Richardson 					   *xstats_map);
7299a2dd95SBruce Richardson /**< @internal Get xstats name map for the RegEx device. */
7399a2dd95SBruce Richardson 
7499a2dd95SBruce Richardson typedef int (*regexdev_xstats_get_t)(struct rte_regexdev *dev,
7599a2dd95SBruce Richardson 				     const uint16_t *ids, uint64_t *values,
7699a2dd95SBruce Richardson 				     uint16_t nb_values);
7799a2dd95SBruce Richardson /**< @internal Get xstats values for the RegEx device. */
7899a2dd95SBruce Richardson 
7999a2dd95SBruce Richardson typedef int (*regexdev_xstats_by_name_get_t)(struct rte_regexdev *dev,
8099a2dd95SBruce Richardson 					     const char *name, uint16_t *id,
8199a2dd95SBruce Richardson 					     uint64_t *value);
8299a2dd95SBruce Richardson /**< @internal Get xstat value for the RegEx device based on the xstats name. */
8399a2dd95SBruce Richardson 
8499a2dd95SBruce Richardson typedef int (*regexdev_xstats_reset_t)(struct rte_regexdev *dev,
8599a2dd95SBruce Richardson 				       const uint16_t *ids,
8699a2dd95SBruce Richardson 				       uint16_t nb_ids);
8799a2dd95SBruce Richardson /**< @internal Reset xstats values for the RegEx device. */
8899a2dd95SBruce Richardson 
8999a2dd95SBruce Richardson typedef int (*regexdev_selftest_t)(struct rte_regexdev *dev);
9099a2dd95SBruce Richardson /**< @internal Trigger RegEx self test. */
9199a2dd95SBruce Richardson 
9299a2dd95SBruce Richardson typedef int (*regexdev_dump_t)(struct rte_regexdev *dev, FILE *f);
9399a2dd95SBruce Richardson /**< @internal Dump internal information about the RegEx device. */
9499a2dd95SBruce Richardson 
9599a2dd95SBruce Richardson typedef uint16_t (*regexdev_enqueue_t)(struct rte_regexdev *dev, uint16_t qp_id,
9699a2dd95SBruce Richardson 				       struct rte_regex_ops **ops,
9799a2dd95SBruce Richardson 				       uint16_t nb_ops);
9899a2dd95SBruce Richardson /**< @internal Enqueue a burst of scan requests to a queue on RegEx device. */
9999a2dd95SBruce Richardson 
10099a2dd95SBruce Richardson typedef uint16_t (*regexdev_dequeue_t)(struct rte_regexdev *dev, uint16_t qp_id,
10199a2dd95SBruce Richardson 				       struct rte_regex_ops **ops,
10299a2dd95SBruce Richardson 				       uint16_t nb_ops);
10399a2dd95SBruce Richardson /**< @internal Dequeue a burst of scan response from a queue on RegEx device. */
10499a2dd95SBruce Richardson 
10599a2dd95SBruce Richardson /**
10699a2dd95SBruce Richardson  * RegEx device operations
10799a2dd95SBruce Richardson  */
10899a2dd95SBruce Richardson struct rte_regexdev_ops {
10999a2dd95SBruce Richardson 	regexdev_info_get_t dev_info_get;
11099a2dd95SBruce Richardson 	regexdev_configure_t dev_configure;
11199a2dd95SBruce Richardson 	regexdev_qp_setup_t dev_qp_setup;
11299a2dd95SBruce Richardson 	regexdev_start_t dev_start;
11399a2dd95SBruce Richardson 	regexdev_stop_t dev_stop;
11499a2dd95SBruce Richardson 	regexdev_close_t dev_close;
11599a2dd95SBruce Richardson 	regexdev_attr_get_t dev_attr_get;
11699a2dd95SBruce Richardson 	regexdev_attr_set_t dev_attr_set;
11799a2dd95SBruce Richardson 	regexdev_rule_db_update_t dev_rule_db_update;
11899a2dd95SBruce Richardson 	regexdev_rule_db_compile_activate_t dev_rule_db_compile_activate;
11999a2dd95SBruce Richardson 	regexdev_rule_db_import_t dev_db_import;
12099a2dd95SBruce Richardson 	regexdev_rule_db_export_t dev_db_export;
12199a2dd95SBruce Richardson 	regexdev_xstats_names_get_t dev_xstats_names_get;
12299a2dd95SBruce Richardson 	regexdev_xstats_get_t dev_xstats_get;
12399a2dd95SBruce Richardson 	regexdev_xstats_by_name_get_t dev_xstats_by_name_get;
12499a2dd95SBruce Richardson 	regexdev_xstats_reset_t dev_xstats_reset;
12599a2dd95SBruce Richardson 	regexdev_selftest_t dev_selftest;
12699a2dd95SBruce Richardson 	regexdev_dump_t dev_dump;
12799a2dd95SBruce Richardson };
12899a2dd95SBruce Richardson 
12999a2dd95SBruce Richardson /**
13099a2dd95SBruce Richardson  * Possible states of a RegEx device.
13199a2dd95SBruce Richardson  */
13299a2dd95SBruce Richardson enum rte_regexdev_state {
13399a2dd95SBruce Richardson 	RTE_REGEXDEV_UNUSED = 0, /**< Device is unused. */
13499a2dd95SBruce Richardson 	RTE_REGEXDEV_REGISTERED,
13599a2dd95SBruce Richardson 	/**< Device is registered, but not ready to be used. */
13699a2dd95SBruce Richardson 	RTE_REGEXDEV_READY,
13799a2dd95SBruce Richardson 	/**< Device is ready for use. This is set by the PMD. */
13899a2dd95SBruce Richardson };
13999a2dd95SBruce Richardson 
14099a2dd95SBruce Richardson /**
14199a2dd95SBruce Richardson  * @internal
14299a2dd95SBruce Richardson  * The data part, with no function pointers, associated with each RegEx device.
14399a2dd95SBruce Richardson  *
14499a2dd95SBruce Richardson  * This structure is safe to place in shared memory to be common among different
14599a2dd95SBruce Richardson  * processes in a multi-process configuration.
14699a2dd95SBruce Richardson  */
147*c6552d9aSTyler Retzlaff struct __rte_cache_aligned rte_regexdev_data {
14899a2dd95SBruce Richardson 	void *dev_private; /**< PMD-specific private data. */
14999a2dd95SBruce Richardson 	char dev_name[RTE_REGEXDEV_NAME_MAX_LEN]; /**< Unique identifier name */
15099a2dd95SBruce Richardson 	uint16_t dev_id; /**< Device [external]  identifier. */
15199a2dd95SBruce Richardson 	struct rte_regexdev_config dev_conf; /**< RegEx configuration. */
15299a2dd95SBruce Richardson 	uint8_t dev_started : 1; /**< Device started to work. */
153*c6552d9aSTyler Retzlaff };
15499a2dd95SBruce Richardson 
15599a2dd95SBruce Richardson /**
15699a2dd95SBruce Richardson  * @internal
15799a2dd95SBruce Richardson  * The generic data structure associated with each RegEx device.
15899a2dd95SBruce Richardson  *
15999a2dd95SBruce Richardson  * Pointers to burst-oriented packet receive and transmit functions are
16099a2dd95SBruce Richardson  * located at the beginning of the structure, along with the pointer to
16199a2dd95SBruce Richardson  * where all the data elements for the particular device are stored in shared
16299a2dd95SBruce Richardson  * memory. This split allows the function pointer and driver data to be per-
16399a2dd95SBruce Richardson  * process, while the actual configuration data for the device is shared.
16499a2dd95SBruce Richardson  */
165*c6552d9aSTyler Retzlaff struct __rte_cache_aligned rte_regexdev {
16699a2dd95SBruce Richardson 	regexdev_enqueue_t enqueue;
16799a2dd95SBruce Richardson 	regexdev_dequeue_t dequeue;
16899a2dd95SBruce Richardson 	const struct rte_regexdev_ops *dev_ops;
16999a2dd95SBruce Richardson 	/**< Functions exported by PMD */
17099a2dd95SBruce Richardson 	struct rte_device *device; /**< Backing device */
17199a2dd95SBruce Richardson 	enum rte_regexdev_state state; /**< The device state. */
17299a2dd95SBruce Richardson 	struct rte_regexdev_data *data;  /**< Pointer to device data. */
173*c6552d9aSTyler Retzlaff };
17499a2dd95SBruce Richardson 
17599a2dd95SBruce Richardson /**
17699a2dd95SBruce Richardson  * @internal
17799a2dd95SBruce Richardson  * The pool of *rte_regexdev* structures. The size of the pool
17899a2dd95SBruce Richardson  * is configured at compile-time in the <rte_regexdev.c> file.
17999a2dd95SBruce Richardson  */
18099a2dd95SBruce Richardson extern struct rte_regexdev rte_regex_devices[];
18199a2dd95SBruce Richardson 
18299a2dd95SBruce Richardson #endif /* _RTE_REGEX_CORE_H_ */
183