xref: /dpdk/lib/regexdev/rte_regexdev_core.h (revision c6552d9a8deffa448de2d5e2e726f50508c1efd2)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2020 Mellanox Technologies, Ltd
3  */
4 
5 #ifndef _RTE_REGEX_CORE_H_
6 #define _RTE_REGEX_CORE_H_
7 
8 /**
9  * @file
10  *
11  * RTE RegEx Device internal header.
12  *
13  * This header contains internal data types, that are used by the RegEx devices
14  * in order to expose their ops to the class.
15  *
16  * Applications should not use these API directly.
17  */
18 
19 struct rte_regexdev;
20 
21 typedef int (*regexdev_info_get_t)(struct rte_regexdev *dev,
22 				   struct rte_regexdev_info *info);
23 /**< @internal Get the RegEx device info. */
24 
25 typedef int (*regexdev_configure_t)(struct rte_regexdev *dev,
26 				    const struct rte_regexdev_config *cfg);
27 /**< @internal Configure the RegEx device. */
28 
29 typedef int (*regexdev_qp_setup_t)(struct rte_regexdev *dev, uint16_t id,
30 				   const struct rte_regexdev_qp_conf *qp_conf);
31 /**< @internal Setup a queue pair.*/
32 
33 typedef int (*regexdev_start_t)(struct rte_regexdev *dev);
34 /**< @internal Start the RegEx device. */
35 
36 typedef int (*regexdev_stop_t)(struct rte_regexdev *dev);
37 /**< @internal Stop the RegEx device. */
38 
39 typedef int (*regexdev_close_t)(struct rte_regexdev *dev);
40 /**< @internal Close the RegEx device. */
41 
42 typedef int (*regexdev_attr_get_t)(struct rte_regexdev *dev,
43 				   enum rte_regexdev_attr_id id,
44 				   void *value);
45 /**< @internal Get selected attribute from RegEx device. */
46 
47 typedef int (*regexdev_attr_set_t)(struct rte_regexdev *dev,
48 				   enum rte_regexdev_attr_id id,
49 				   const void *value);
50 /**< @internal Set selected attribute to RegEx device. */
51 
52 typedef int (*regexdev_rule_db_update_t)(struct rte_regexdev *dev,
53 					 const struct rte_regexdev_rule *rules,
54 					 uint16_t nb_rules);
55 /**< @internal Update the rule database for the RegEx device. */
56 
57 typedef int (*regexdev_rule_db_compile_activate_t)(struct rte_regexdev *dev);
58 /**< @internal Compile the rule database and activate it. */
59 
60 typedef int (*regexdev_rule_db_import_t)(struct rte_regexdev *dev,
61 					 const  char *rule_db,
62 					 uint32_t rule_db_len);
63 /**< @internal Upload a pre created rule database to the RegEx device. */
64 
65 typedef int (*regexdev_rule_db_export_t)(struct rte_regexdev *dev,
66 					 char *rule_db);
67 /**< @internal Export the current rule database from the RegEx device. */
68 
69 typedef int (*regexdev_xstats_names_get_t)(struct rte_regexdev *dev,
70 					   struct rte_regexdev_xstats_map
71 					   *xstats_map);
72 /**< @internal Get xstats name map for the RegEx device. */
73 
74 typedef int (*regexdev_xstats_get_t)(struct rte_regexdev *dev,
75 				     const uint16_t *ids, uint64_t *values,
76 				     uint16_t nb_values);
77 /**< @internal Get xstats values for the RegEx device. */
78 
79 typedef int (*regexdev_xstats_by_name_get_t)(struct rte_regexdev *dev,
80 					     const char *name, uint16_t *id,
81 					     uint64_t *value);
82 /**< @internal Get xstat value for the RegEx device based on the xstats name. */
83 
84 typedef int (*regexdev_xstats_reset_t)(struct rte_regexdev *dev,
85 				       const uint16_t *ids,
86 				       uint16_t nb_ids);
87 /**< @internal Reset xstats values for the RegEx device. */
88 
89 typedef int (*regexdev_selftest_t)(struct rte_regexdev *dev);
90 /**< @internal Trigger RegEx self test. */
91 
92 typedef int (*regexdev_dump_t)(struct rte_regexdev *dev, FILE *f);
93 /**< @internal Dump internal information about the RegEx device. */
94 
95 typedef uint16_t (*regexdev_enqueue_t)(struct rte_regexdev *dev, uint16_t qp_id,
96 				       struct rte_regex_ops **ops,
97 				       uint16_t nb_ops);
98 /**< @internal Enqueue a burst of scan requests to a queue on RegEx device. */
99 
100 typedef uint16_t (*regexdev_dequeue_t)(struct rte_regexdev *dev, uint16_t qp_id,
101 				       struct rte_regex_ops **ops,
102 				       uint16_t nb_ops);
103 /**< @internal Dequeue a burst of scan response from a queue on RegEx device. */
104 
105 /**
106  * RegEx device operations
107  */
108 struct rte_regexdev_ops {
109 	regexdev_info_get_t dev_info_get;
110 	regexdev_configure_t dev_configure;
111 	regexdev_qp_setup_t dev_qp_setup;
112 	regexdev_start_t dev_start;
113 	regexdev_stop_t dev_stop;
114 	regexdev_close_t dev_close;
115 	regexdev_attr_get_t dev_attr_get;
116 	regexdev_attr_set_t dev_attr_set;
117 	regexdev_rule_db_update_t dev_rule_db_update;
118 	regexdev_rule_db_compile_activate_t dev_rule_db_compile_activate;
119 	regexdev_rule_db_import_t dev_db_import;
120 	regexdev_rule_db_export_t dev_db_export;
121 	regexdev_xstats_names_get_t dev_xstats_names_get;
122 	regexdev_xstats_get_t dev_xstats_get;
123 	regexdev_xstats_by_name_get_t dev_xstats_by_name_get;
124 	regexdev_xstats_reset_t dev_xstats_reset;
125 	regexdev_selftest_t dev_selftest;
126 	regexdev_dump_t dev_dump;
127 };
128 
129 /**
130  * Possible states of a RegEx device.
131  */
132 enum rte_regexdev_state {
133 	RTE_REGEXDEV_UNUSED = 0, /**< Device is unused. */
134 	RTE_REGEXDEV_REGISTERED,
135 	/**< Device is registered, but not ready to be used. */
136 	RTE_REGEXDEV_READY,
137 	/**< Device is ready for use. This is set by the PMD. */
138 };
139 
140 /**
141  * @internal
142  * The data part, with no function pointers, associated with each RegEx device.
143  *
144  * This structure is safe to place in shared memory to be common among different
145  * processes in a multi-process configuration.
146  */
147 struct __rte_cache_aligned rte_regexdev_data {
148 	void *dev_private; /**< PMD-specific private data. */
149 	char dev_name[RTE_REGEXDEV_NAME_MAX_LEN]; /**< Unique identifier name */
150 	uint16_t dev_id; /**< Device [external]  identifier. */
151 	struct rte_regexdev_config dev_conf; /**< RegEx configuration. */
152 	uint8_t dev_started : 1; /**< Device started to work. */
153 };
154 
155 /**
156  * @internal
157  * The generic data structure associated with each RegEx device.
158  *
159  * Pointers to burst-oriented packet receive and transmit functions are
160  * located at the beginning of the structure, along with the pointer to
161  * where all the data elements for the particular device are stored in shared
162  * memory. This split allows the function pointer and driver data to be per-
163  * process, while the actual configuration data for the device is shared.
164  */
165 struct __rte_cache_aligned rte_regexdev {
166 	regexdev_enqueue_t enqueue;
167 	regexdev_dequeue_t dequeue;
168 	const struct rte_regexdev_ops *dev_ops;
169 	/**< Functions exported by PMD */
170 	struct rte_device *device; /**< Backing device */
171 	enum rte_regexdev_state state; /**< The device state. */
172 	struct rte_regexdev_data *data;  /**< Pointer to device data. */
173 };
174 
175 /**
176  * @internal
177  * The pool of *rte_regexdev* structures. The size of the pool
178  * is configured at compile-time in the <rte_regexdev.c> file.
179  */
180 extern struct rte_regexdev rte_regex_devices[];
181 
182 #endif /* _RTE_REGEX_CORE_H_ */
183