DPDK  20.08.0
rte_regexdev.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2019 Marvell International Ltd.
3  * Copyright 2020 Mellanox Technologies, Ltd
4  * Copyright(c) 2020 Intel Corporation
5  */
6 
7 #ifndef _RTE_REGEXDEV_H_
8 #define _RTE_REGEXDEV_H_
9 
197 #ifdef __cplusplus
198 extern "C" {
199 #endif
200 
201 #include <rte_common.h>
202 #include <rte_config.h>
203 #include <rte_dev.h>
204 #include <rte_errno.h>
205 #include <rte_mbuf.h>
206 #include <rte_memory.h>
207 
208 #define RTE_REGEXDEV_NAME_MAX_LEN RTE_DEV_NAME_MAX_LEN
209 
210 extern int rte_regexdev_logtype;
211 
212 #define RTE_REGEXDEV_LOG(level, ...) \
213  rte_log(RTE_LOG_ ## level, rte_regexdev_logtype, "" __VA_ARGS__)
214 
215 /* Macros to check for valid port */
216 #define RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, retval) do { \
217  if (!rte_regexdev_is_valid_dev(dev_id)) { \
218  RTE_REGEXDEV_LOG(ERR, "Invalid dev_id=%u\n", dev_id); \
219  return retval; \
220  } \
221 } while (0)
222 
223 #define RTE_REGEXDEV_VALID_DEV_ID_OR_RET(dev_id) do { \
224  if (!rte_regexdev_is_valid_dev(dev_id)) { \
225  RTE_REGEXDEV_LOG(ERR, "Invalid dev_id=%u\n", dev_id); \
226  return; \
227  } \
228 } while (0)
229 
240 int rte_regexdev_is_valid_dev(uint16_t dev_id);
241 
252 __rte_experimental
253 uint8_t
254 rte_regexdev_count(void);
255 
269 __rte_experimental
270 int
271 rte_regexdev_get_dev_id(const char *name);
272 
273 /* Enumerates RegEx device capabilities */
274 #define RTE_REGEXDEV_CAPA_RUNTIME_COMPILATION_F (1ULL << 0)
275 
283 #define RTE_REGEXDEV_CAPA_SUPP_PCRE_START_ANCHOR_F (1ULL << 1)
284 
294 #define RTE_REGEXDEV_CAPA_SUPP_PCRE_ATOMIC_GROUPING_F (1ULL << 2)
295 
306 #define RTE_REGEXDEV_SUPP_PCRE_BACKTRACKING_CTRL_F (1ULL << 3)
307 
314 #define RTE_REGEXDEV_SUPP_PCRE_CALLOUTS_F (1ULL << 4)
315 
324 #define RTE_REGEXDEV_SUPP_PCRE_BACKREFERENCE_F (1ULL << 5)
325 
332 #define RTE_REGEXDEV_SUPP_PCRE_GREEDY_F (1ULL << 6)
333 
341 #define RTE_REGEXDEV_SUPP_PCRE_MATCH_ALL_F (1ULL << 7)
342 
350 #define RTE_REGEXDEV_SUPP_PCRE_LOOKAROUND_ASRT_F (1ULL << 8)
351 
360 #define RTE_REGEXDEV_SUPP_PCRE_MATCH_POINT_RST_F (1ULL << 9)
361 
369 #define RTE_REGEXDEV_SUPP_NEWLINE_CONVENTIONS_F (1ULL << 10)
370 
381 #define RTE_REGEXDEV_SUPP_PCRE_NEWLINE_SEQ_F (1ULL << 11)
382 
389 #define RTE_REGEXDEV_SUPP_PCRE_POSSESSIVE_QUALIFIERS_F (1ULL << 12)
390 
399 #define RTE_REGEXDEV_SUPP_PCRE_SUBROUTINE_REFERENCES_F (1ULL << 13)
400 
408 #define RTE_REGEXDEV_SUPP_PCRE_UTF_8_F (1ULL << 14)
409 
414 #define RTE_REGEXDEV_SUPP_PCRE_UTF_16_F (1ULL << 15)
415 
420 #define RTE_REGEXDEV_SUPP_PCRE_UTF_32_F (1ULL << 16)
421 
426 #define RTE_REGEXDEV_SUPP_PCRE_WORD_BOUNDARY_F (1ULL << 17)
427 
433 #define RTE_REGEXDEV_SUPP_PCRE_FORWARD_REFERENCES_F (1ULL << 18)
434 
442 #define RTE_REGEXDEV_SUPP_MATCH_AS_END_F (1ULL << 19)
443 
452 #define RTE_REGEXDEV_SUPP_CROSS_BUFFER_F (1ULL << 20)
453 
468 #define RTE_REGEXDEV_SUPP_MATCH_ALL_F (1ULL << 21)
469 
477 /* Enumerates PCRE rule flags */
478 #define RTE_REGEX_PCRE_RULE_ALLOW_EMPTY_F (1ULL << 0)
479 
486 #define RTE_REGEX_PCRE_RULE_ANCHORED_F (1ULL << 1)
487 
495 #define RTE_REGEX_PCRE_RULE_CASELESS_F (1ULL << 2)
496 
503 #define RTE_REGEX_PCRE_RULE_DOTALL_F (1ULL << 3)
504 
511 #define RTE_REGEX_PCRE_RULE_DUPNAMES_F (1ULL << 4)
512 
519 #define RTE_REGEX_PCRE_RULE_EXTENDED_F (1ULL << 5)
520 
527 #define RTE_REGEX_PCRE_RULE_MATCH_UNSET_BACKREF_F (1ULL << 6)
528 
535 #define RTE_REGEX_PCRE_RULE_MULTILINE_F (1ULL << 7)
536 
544 #define RTE_REGEX_PCRE_RULE_NO_AUTO_CAPTURE_F (1ULL << 8)
545 
554 #define RTE_REGEX_PCRE_RULE_UCP_F (1ULL << 9)
555 
562 #define RTE_REGEX_PCRE_RULE_UNGREEDY_F (1ULL << 10)
563 
571 #define RTE_REGEX_PCRE_RULE_UTF_F (1ULL << 11)
572 
580 #define RTE_REGEX_PCRE_RULE_NEVER_BACKSLASH_C_F (1ULL << 12)
581 
595  const char *driver_name;
596  struct rte_device *dev;
597  uint16_t max_matches;
599  uint16_t max_queue_pairs;
607  uint16_t max_groups;
609  uint32_t regexdev_capa;
611  uint64_t rule_flags;
615 };
616 
634 __rte_experimental
635 int
636 rte_regexdev_info_get(uint8_t dev_id, struct rte_regexdev_info *dev_info);
637 
638 /* Enumerates RegEx device configuration flags */
639 #define RTE_REGEXDEV_CFG_CROSS_BUFFER_SCAN_F (1ULL << 0)
640 
652 #define RTE_REGEXDEV_CFG_MATCH_AS_END_F (1ULL << 1)
653 
662 #define RTE_REGEXDEV_CFG_MATCH_ALL_F (1ULL << 2)
663 
670  uint16_t nb_max_matches;
677  uint16_t nb_queue_pairs;
691  uint16_t nb_groups;
697  const char *rule_db;
706  uint32_t rule_db_len;
708  uint32_t dev_cfg_flags;
710 };
711 
733 __rte_experimental
734 int
735 rte_regexdev_configure(uint8_t dev_id, const struct rte_regexdev_config *cfg);
736 
737 /* Enumerates RegEx queue pair configuration flags */
738 #define RTE_REGEX_QUEUE_PAIR_CFG_OOS_F (1ULL << 0)
739 
748 struct rte_regex_ops;
749 typedef void (*regexdev_stop_flush_t)(uint8_t dev_id, uint16_t qp_id,
750  struct rte_regex_ops *op);
757  uint32_t qp_conf_flags;
759  uint16_t nb_desc;
769 };
770 
789 __rte_experimental
790 int
791 rte_regexdev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
792  const struct rte_regexdev_qp_conf *qp_conf);
793 
812 __rte_experimental
813 int
814 rte_regexdev_start(uint8_t dev_id);
815 
835 __rte_experimental
836 int
837 rte_regexdev_stop(uint8_t dev_id);
838 
851 __rte_experimental
852 int
853 rte_regexdev_close(uint8_t dev_id);
854 
855 /* Device get/set attributes */
856 
884 };
885 
905 __rte_experimental
906 int
907 rte_regexdev_attr_get(uint8_t dev_id, enum rte_regexdev_attr_id attr_id,
908  void *attr_value);
909 
929 __rte_experimental
930 int
931 rte_regexdev_attr_set(uint8_t dev_id, enum rte_regexdev_attr_id attr_id,
932  const void *attr_value);
933 
934 /* Rule related APIs */
941 };
942 
947  uint16_t group_id;
949  uint32_t rule_id;
951  const char *pcre_rule;
953  uint16_t pcre_rule_len;
955  uint64_t rule_flags;
956  /* PCRE rule flags. Supported device specific PCRE rules enumerated
957  * in struct rte_regexdev_info::rule_flags. For successful rule
958  * database update, application needs to provide only supported
959  * rule flags.
960  * @See RTE_REGEX_PCRE_RULE_*, struct rte_regexdev_info::rule_flags
961  */
962 };
963 
998 __rte_experimental
999 int
1000 rte_regexdev_rule_db_update(uint8_t dev_id,
1001  const struct rte_regexdev_rule *rules,
1002  uint32_t nb_rules);
1003 
1020 __rte_experimental
1021 int
1023 
1045 __rte_experimental
1046 int
1047 rte_regexdev_rule_db_import(uint8_t dev_id, const char *rule_db,
1048  uint32_t rule_db_len);
1049 
1070 __rte_experimental
1071 int
1072 rte_regexdev_rule_db_export(uint8_t dev_id, char *rule_db);
1073 
1074 /* Extended statistics */
1076 #define RTE_REGEXDEV_XSTATS_NAME_SIZE 64
1077 
1085  uint16_t id;
1089 };
1090 
1110 __rte_experimental
1111 int
1112 rte_regexdev_xstats_names_get(uint8_t dev_id,
1113  struct rte_regexdev_xstats_map *xstats_map);
1114 
1137 __rte_experimental
1138 int
1139 rte_regexdev_xstats_get(uint8_t dev_id, const uint16_t *ids,
1140  uint64_t *values, uint16_t nb_values);
1141 
1164 __rte_experimental
1165 int
1166 rte_regexdev_xstats_by_name_get(uint8_t dev_id, const char *name,
1167  uint16_t *id, uint64_t *value);
1168 
1188 __rte_experimental
1189 int
1190 rte_regexdev_xstats_reset(uint8_t dev_id, const uint16_t *ids,
1191  uint16_t nb_ids);
1192 
1206 __rte_experimental
1207 int
1208 rte_regexdev_selftest(uint8_t dev_id);
1209 
1224 __rte_experimental
1225 int
1226 rte_regexdev_dump(uint8_t dev_id, FILE *f);
1227 
1228 /* Fast path APIs */
1229 
1236  RTE_STD_C11
1237  union {
1238  uint64_t u64;
1239  struct {
1240  uint32_t rule_id:20;
1244  uint32_t group_id:12;
1248  uint16_t start_offset;
1250  RTE_STD_C11
1251  union {
1252  uint16_t len;
1254  uint16_t end_offset;
1259  };
1260  };
1261  };
1262 };
1263 
1264 /* Enumerates RegEx request flags. */
1265 #define RTE_REGEX_OPS_REQ_GROUP_ID0_VALID_F (1 << 0)
1266 
1268 #define RTE_REGEX_OPS_REQ_GROUP_ID1_VALID_F (1 << 1)
1269 
1271 #define RTE_REGEX_OPS_REQ_GROUP_ID2_VALID_F (1 << 2)
1272 
1274 #define RTE_REGEX_OPS_REQ_GROUP_ID3_VALID_F (1 << 3)
1275 
1277 #define RTE_REGEX_OPS_REQ_STOP_ON_MATCH_F (1 << 4)
1278 
1280 #define RTE_REGEX_OPS_REQ_MATCH_HIGH_PRIORITY_F (1 << 5)
1281 
1291 /* Enumerates RegEx response flags. */
1292 #define RTE_REGEX_OPS_RSP_PMI_SOJ_F (1 << 0)
1293 
1299 #define RTE_REGEX_OPS_RSP_PMI_EOJ_F (1 << 1)
1300 
1306 #define RTE_REGEX_OPS_RSP_MAX_SCAN_TIMEOUT_F (1 << 2)
1307 
1313 #define RTE_REGEX_OPS_RSP_MAX_MATCH_F (1 << 3)
1314 
1320 #define RTE_REGEX_OPS_RSP_MAX_PREFIX_F (1 << 4)
1321 
1332  /* W0 */
1333  uint16_t req_flags;
1337  uint16_t rsp_flags;
1343  uint16_t nb_matches;
1351  /* W1 */
1352  struct rte_mbuf *mbuf;
1354  /* W2 */
1355  uint16_t group_id0;
1361  uint16_t group_id1;
1366  uint16_t group_id2;
1371  uint16_t group_id3;
1377  /* W3 */
1378  RTE_STD_C11
1379  union {
1380  uint64_t user_id;
1386  void *user_ptr;
1388  };
1389 
1390  /* W4 */
1391  RTE_STD_C11
1392  union {
1393  uint64_t cross_buf_id;
1402  };
1403 
1404  /* W5 */
1412 };
1413 
1414 #include "rte_regexdev_core.h"
1415 
1453 __rte_experimental
1454 static inline uint16_t
1455 rte_regexdev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
1456  struct rte_regex_ops **ops, uint16_t nb_ops)
1457 {
1458  struct rte_regexdev *dev = &rte_regex_devices[dev_id];
1459 #ifdef RTE_LIBRTE_REGEXDEV_DEBUG
1460  RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL);
1461  RTE_FUNC_PTR_OR_ERR_RET(*dev->enqueue, -ENOTSUP);
1462  if (qp_id >= dev->data->dev_conf.nb_queue_pairs) {
1463  RTE_REGEXDEV_LOG(ERR, "Invalid queue %d\n", qp_id);
1464  return -EINVAL;
1465  }
1466 #endif
1467  return (*dev->enqueue)(dev, qp_id, ops, nb_ops);
1468 }
1469 
1512 __rte_experimental
1513 static inline uint16_t
1514 rte_regexdev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
1515  struct rte_regex_ops **ops, uint16_t nb_ops)
1516 {
1517  struct rte_regexdev *dev = &rte_regex_devices[dev_id];
1518 #ifdef RTE_LIBRTE_REGEXDEV_DEBUG
1519  RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL);
1520  RTE_FUNC_PTR_OR_ERR_RET(*dev->dequeue, -ENOTSUP);
1521  if (qp_id >= dev->data->dev_conf.nb_queue_pairs) {
1522  RTE_REGEXDEV_LOG(ERR, "Invalid queue %d\n", qp_id);
1523  return -EINVAL;
1524  }
1525 #endif
1526  return (*dev->dequeue)(dev, qp_id, ops, nb_ops);
1527 }
1528 
1529 #ifdef __cplusplus
1530 }
1531 #endif
1532 
1533 #endif /* _RTE_REGEXDEV_H_ */
__rte_experimental uint8_t rte_regexdev_count(void)
__rte_experimental int rte_regexdev_xstats_by_name_get(uint8_t dev_id, const char *name, uint16_t *id, uint64_t *value)
uint16_t group_id0
uint16_t max_queue_pairs
Definition: rte_regexdev.h:599
__rte_experimental int rte_regexdev_info_get(uint8_t dev_id, struct rte_regexdev_info *dev_info)
uint32_t nb_rules_per_group
Definition: rte_regexdev.h:683
#define RTE_REGEXDEV_XSTATS_NAME_SIZE
rte_regexdev_rule_op
Definition: rte_regexdev.h:936
static __rte_experimental uint16_t rte_regexdev_enqueue_burst(uint8_t dev_id, uint16_t qp_id, struct rte_regex_ops **ops, uint16_t nb_ops)
__rte_experimental int rte_regexdev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id, const struct rte_regexdev_qp_conf *qp_conf)
enum rte_regexdev_rule_op op
Definition: rte_regexdev.h:945
uint16_t max_matches
Definition: rte_regexdev.h:597
__rte_experimental int rte_regexdev_dump(uint8_t dev_id, FILE *f)
__rte_experimental int rte_regexdev_attr_set(uint8_t dev_id, enum rte_regexdev_attr_id attr_id, const void *attr_value)
__rte_experimental int rte_regexdev_xstats_names_get(uint8_t dev_id, struct rte_regexdev_xstats_map *xstats_map)
__rte_experimental int rte_regexdev_xstats_reset(uint8_t dev_id, const uint16_t *ids, uint16_t nb_ids)
int rte_regexdev_is_valid_dev(uint16_t dev_id)
uint16_t nb_actual_matches
const char * rule_db
Definition: rte_regexdev.h:697
__rte_experimental int rte_regexdev_get_dev_id(const char *name)
char name[RTE_REGEXDEV_XSTATS_NAME_SIZE]
uint16_t pcre_rule_len
Definition: rte_regexdev.h:953
uint16_t group_id2
__rte_experimental int rte_regexdev_close(uint8_t dev_id)
uint64_t cross_buf_id
void(* regexdev_stop_flush_t)(uint8_t dev_id, uint16_t qp_id, struct rte_regex_ops *op)
Definition: rte_regexdev.h:749
uint16_t group_id1
static __rte_experimental uint16_t rte_regexdev_dequeue_burst(uint8_t dev_id, uint16_t qp_id, struct rte_regex_ops **ops, uint16_t nb_ops)
uint32_t regexdev_capa
Definition: rte_regexdev.h:609
rte_regexdev_attr_id
Definition: rte_regexdev.h:858
uint16_t req_flags
__rte_experimental int rte_regexdev_xstats_get(uint8_t dev_id, const uint16_t *ids, uint64_t *values, uint16_t nb_values)
struct rte_mbuf * mbuf
uint32_t max_rules_per_group
Definition: rte_regexdev.h:605
uint16_t group_id3
__rte_experimental int rte_regexdev_stop(uint8_t dev_id)
__rte_experimental int rte_regexdev_rule_db_update(uint8_t dev_id, const struct rte_regexdev_rule *rules, uint32_t nb_rules)
__rte_experimental int rte_regexdev_start(uint8_t dev_id)
__rte_experimental int rte_regexdev_selftest(uint8_t dev_id)
uint16_t rsp_flags
#define RTE_STD_C11
Definition: rte_common.h:40
uint16_t max_payload_size
Definition: rte_regexdev.h:601
__rte_experimental int rte_regexdev_rule_db_export(uint8_t dev_id, char *rule_db)
const char * driver_name
Definition: rte_regexdev.h:595
__rte_experimental int rte_regexdev_rule_db_compile_activate(uint8_t dev_id)
uint64_t user_id
regexdev_stop_flush_t cb
Definition: rte_regexdev.h:761
const char * pcre_rule
Definition: rte_regexdev.h:951
struct rte_device * dev
Definition: rte_regexdev.h:596
__rte_experimental int rte_regexdev_attr_get(uint8_t dev_id, enum rte_regexdev_attr_id attr_id, void *attr_value)
struct rte_regexdev_match matches[]
__rte_experimental int rte_regexdev_rule_db_import(uint8_t dev_id, const char *rule_db, uint32_t rule_db_len)
uint16_t nb_matches
__rte_experimental int rte_regexdev_configure(uint8_t dev_id, const struct rte_regexdev_config *cfg)
void * cross_buf_ptr