DPDK  23.03.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_compat.h>
202 #include <rte_common.h>
203 #include <rte_dev.h>
204 #include <rte_mbuf.h>
205 
206 #define RTE_REGEXDEV_NAME_MAX_LEN RTE_DEV_NAME_MAX_LEN
207 
208 extern int rte_regexdev_logtype;
209 
210 #define RTE_REGEXDEV_LOG(level, ...) \
211  rte_log(RTE_LOG_ ## level, rte_regexdev_logtype, "" __VA_ARGS__)
212 
213 /* Macros to check for valid port */
214 #define RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, retval) do { \
215  if (!rte_regexdev_is_valid_dev(dev_id)) { \
216  RTE_REGEXDEV_LOG(ERR, "Invalid dev_id=%u\n", dev_id); \
217  return retval; \
218  } \
219 } while (0)
220 
221 #define RTE_REGEXDEV_VALID_DEV_ID_OR_RET(dev_id) do { \
222  if (!rte_regexdev_is_valid_dev(dev_id)) { \
223  RTE_REGEXDEV_LOG(ERR, "Invalid dev_id=%u\n", dev_id); \
224  return; \
225  } \
226 } while (0)
227 
241 __rte_experimental
242 int rte_regexdev_is_valid_dev(uint16_t dev_id);
243 
254 __rte_experimental
255 uint8_t
256 rte_regexdev_count(void);
257 
271 __rte_experimental
272 int
273 rte_regexdev_get_dev_id(const char *name);
274 
275 /* Enumerates RegEx device capabilities */
276 #define RTE_REGEXDEV_CAPA_RUNTIME_COMPILATION_F (1ULL << 0)
277 
285 #define RTE_REGEXDEV_CAPA_SUPP_PCRE_START_ANCHOR_F (1ULL << 1)
286 
296 #define RTE_REGEXDEV_CAPA_SUPP_PCRE_ATOMIC_GROUPING_F (1ULL << 2)
297 
308 #define RTE_REGEXDEV_SUPP_PCRE_BACKTRACKING_CTRL_F (1ULL << 3)
309 
316 #define RTE_REGEXDEV_SUPP_PCRE_CALLOUTS_F (1ULL << 4)
317 
326 #define RTE_REGEXDEV_SUPP_PCRE_BACKREFERENCE_F (1ULL << 5)
327 
334 #define RTE_REGEXDEV_SUPP_PCRE_GREEDY_F (1ULL << 6)
335 
343 #define RTE_REGEXDEV_SUPP_PCRE_MATCH_ALL_F (1ULL << 7)
344 
352 #define RTE_REGEXDEV_SUPP_PCRE_LOOKAROUND_ASRT_F (1ULL << 8)
353 
362 #define RTE_REGEXDEV_SUPP_PCRE_MATCH_POINT_RST_F (1ULL << 9)
363 
371 #define RTE_REGEXDEV_SUPP_NEWLINE_CONVENTIONS_F (1ULL << 10)
372 
383 #define RTE_REGEXDEV_SUPP_PCRE_NEWLINE_SEQ_F (1ULL << 11)
384 
391 #define RTE_REGEXDEV_SUPP_PCRE_POSSESSIVE_QUALIFIERS_F (1ULL << 12)
392 
401 #define RTE_REGEXDEV_SUPP_PCRE_SUBROUTINE_REFERENCES_F (1ULL << 13)
402 
410 #define RTE_REGEXDEV_SUPP_PCRE_UTF_8_F (1ULL << 14)
411 
416 #define RTE_REGEXDEV_SUPP_PCRE_UTF_16_F (1ULL << 15)
417 
422 #define RTE_REGEXDEV_SUPP_PCRE_UTF_32_F (1ULL << 16)
423 
428 #define RTE_REGEXDEV_SUPP_PCRE_WORD_BOUNDARY_F (1ULL << 17)
429 
435 #define RTE_REGEXDEV_SUPP_PCRE_FORWARD_REFERENCES_F (1ULL << 18)
436 
444 #define RTE_REGEXDEV_SUPP_MATCH_AS_END_F (1ULL << 19)
445 
454 #define RTE_REGEXDEV_SUPP_CROSS_BUFFER_F (1ULL << 20)
455 
470 #define RTE_REGEXDEV_SUPP_MATCH_ALL_F (1ULL << 21)
471 
479 #define RTE_REGEXDEV_CAPA_QUEUE_PAIR_OOS_F (1ULL << 22)
480 
488 /* Enumerates PCRE rule flags */
489 #define RTE_REGEX_PCRE_RULE_ALLOW_EMPTY_F (1ULL << 0)
490 
497 #define RTE_REGEX_PCRE_RULE_ANCHORED_F (1ULL << 1)
498 
506 #define RTE_REGEX_PCRE_RULE_CASELESS_F (1ULL << 2)
507 
514 #define RTE_REGEX_PCRE_RULE_DOTALL_F (1ULL << 3)
515 
522 #define RTE_REGEX_PCRE_RULE_DUPNAMES_F (1ULL << 4)
523 
530 #define RTE_REGEX_PCRE_RULE_EXTENDED_F (1ULL << 5)
531 
538 #define RTE_REGEX_PCRE_RULE_MATCH_UNSET_BACKREF_F (1ULL << 6)
539 
546 #define RTE_REGEX_PCRE_RULE_MULTILINE_F (1ULL << 7)
547 
555 #define RTE_REGEX_PCRE_RULE_NO_AUTO_CAPTURE_F (1ULL << 8)
556 
565 #define RTE_REGEX_PCRE_RULE_UCP_F (1ULL << 9)
566 
573 #define RTE_REGEX_PCRE_RULE_UNGREEDY_F (1ULL << 10)
574 
582 #define RTE_REGEX_PCRE_RULE_UTF_F (1ULL << 11)
583 
591 #define RTE_REGEX_PCRE_RULE_NEVER_BACKSLASH_C_F (1ULL << 12)
592 
606  const char *driver_name;
607  struct rte_device *dev;
608  uint16_t max_matches;
610  uint16_t max_queue_pairs;
616  uint16_t max_segs;
620  uint16_t max_groups;
622  uint32_t regexdev_capa;
624  uint64_t rule_flags;
628 };
629 
647 __rte_experimental
648 int
649 rte_regexdev_info_get(uint8_t dev_id, struct rte_regexdev_info *dev_info);
650 
651 /* Enumerates RegEx device configuration flags */
652 #define RTE_REGEXDEV_CFG_CROSS_BUFFER_SCAN_F (1ULL << 0)
653 
665 #define RTE_REGEXDEV_CFG_MATCH_AS_END_F (1ULL << 1)
666 
675 #define RTE_REGEXDEV_CFG_MATCH_ALL_F (1ULL << 2)
676 
683  uint16_t nb_max_matches;
690  uint16_t nb_queue_pairs;
704  uint16_t nb_groups;
710  const char *rule_db;
719  uint32_t rule_db_len;
721  uint32_t dev_cfg_flags;
723 };
724 
746 __rte_experimental
747 int
748 rte_regexdev_configure(uint8_t dev_id, const struct rte_regexdev_config *cfg);
749 
750 /* Enumerates RegEx queue pair configuration flags */
751 #define RTE_REGEX_QUEUE_PAIR_CFG_OOS_F (1ULL << 0)
752 
761 struct rte_regex_ops;
762 typedef void (*regexdev_stop_flush_t)(uint8_t dev_id, uint16_t qp_id,
763  struct rte_regex_ops *op);
770  uint32_t qp_conf_flags;
772  uint16_t nb_desc;
782 };
783 
802 __rte_experimental
803 int
804 rte_regexdev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
805  const struct rte_regexdev_qp_conf *qp_conf);
806 
825 __rte_experimental
826 int
827 rte_regexdev_start(uint8_t dev_id);
828 
848 __rte_experimental
849 int
850 rte_regexdev_stop(uint8_t dev_id);
851 
864 __rte_experimental
865 int
866 rte_regexdev_close(uint8_t dev_id);
867 
868 /* Device get/set attributes */
869 
897 };
898 
918 __rte_experimental
919 int
920 rte_regexdev_attr_get(uint8_t dev_id, enum rte_regexdev_attr_id attr_id,
921  void *attr_value);
922 
942 __rte_experimental
943 int
944 rte_regexdev_attr_set(uint8_t dev_id, enum rte_regexdev_attr_id attr_id,
945  const void *attr_value);
946 
947 /* Rule related APIs */
954 };
955 
960  uint16_t group_id;
962  uint32_t rule_id;
964  const char *pcre_rule;
966  uint16_t pcre_rule_len;
968  uint64_t rule_flags;
969  /* PCRE rule flags. Supported device specific PCRE rules enumerated
970  * in struct rte_regexdev_info::rule_flags. For successful rule
971  * database update, application needs to provide only supported
972  * rule flags.
973  * @See RTE_REGEX_PCRE_RULE_*, struct rte_regexdev_info::rule_flags
974  */
975 };
976 
1011 __rte_experimental
1012 int
1013 rte_regexdev_rule_db_update(uint8_t dev_id,
1014  const struct rte_regexdev_rule *rules,
1015  uint32_t nb_rules);
1016 
1033 __rte_experimental
1034 int
1036 
1058 __rte_experimental
1059 int
1060 rte_regexdev_rule_db_import(uint8_t dev_id, const char *rule_db,
1061  uint32_t rule_db_len);
1062 
1083 __rte_experimental
1084 int
1085 rte_regexdev_rule_db_export(uint8_t dev_id, char *rule_db);
1086 
1087 /* Extended statistics */
1089 #define RTE_REGEXDEV_XSTATS_NAME_SIZE 64
1090 
1098  uint16_t id;
1102 };
1103 
1123 __rte_experimental
1124 int
1125 rte_regexdev_xstats_names_get(uint8_t dev_id,
1126  struct rte_regexdev_xstats_map *xstats_map);
1127 
1150 __rte_experimental
1151 int
1152 rte_regexdev_xstats_get(uint8_t dev_id, const uint16_t *ids,
1153  uint64_t *values, uint16_t nb_values);
1154 
1177 __rte_experimental
1178 int
1179 rte_regexdev_xstats_by_name_get(uint8_t dev_id, const char *name,
1180  uint16_t *id, uint64_t *value);
1181 
1201 __rte_experimental
1202 int
1203 rte_regexdev_xstats_reset(uint8_t dev_id, const uint16_t *ids,
1204  uint16_t nb_ids);
1205 
1219 __rte_experimental
1220 int
1221 rte_regexdev_selftest(uint8_t dev_id);
1222 
1237 __rte_experimental
1238 int
1239 rte_regexdev_dump(uint8_t dev_id, FILE *f);
1240 
1241 /* Fast path APIs */
1242 
1249  RTE_STD_C11
1250  union {
1251  uint64_t u64;
1252  struct {
1253  uint32_t rule_id:20;
1257  uint32_t group_id:12;
1261  uint16_t start_offset;
1263  RTE_STD_C11
1264  union {
1265  uint16_t len;
1267  uint16_t end_offset;
1272  };
1273  };
1274  };
1275 };
1276 
1277 /* Enumerates RegEx request flags. */
1278 #define RTE_REGEX_OPS_REQ_GROUP_ID0_VALID_F (1 << 0)
1279 
1281 #define RTE_REGEX_OPS_REQ_GROUP_ID1_VALID_F (1 << 1)
1282 
1284 #define RTE_REGEX_OPS_REQ_GROUP_ID2_VALID_F (1 << 2)
1285 
1287 #define RTE_REGEX_OPS_REQ_GROUP_ID3_VALID_F (1 << 3)
1288 
1290 #define RTE_REGEX_OPS_REQ_STOP_ON_MATCH_F (1 << 4)
1291 
1293 #define RTE_REGEX_OPS_REQ_MATCH_HIGH_PRIORITY_F (1 << 5)
1294 
1304 /* Enumerates RegEx response flags. */
1305 #define RTE_REGEX_OPS_RSP_PMI_SOJ_F (1 << 0)
1306 
1312 #define RTE_REGEX_OPS_RSP_PMI_EOJ_F (1 << 1)
1313 
1319 #define RTE_REGEX_OPS_RSP_MAX_SCAN_TIMEOUT_F (1 << 2)
1320 
1326 #define RTE_REGEX_OPS_RSP_MAX_MATCH_F (1 << 3)
1327 
1333 #define RTE_REGEX_OPS_RSP_MAX_PREFIX_F (1 << 4)
1334 
1340 #define RTE_REGEX_OPS_RSP_RESOURCE_LIMIT_REACHED_F (1 << 4)
1341 
1350  /* W0 */
1351  uint16_t req_flags;
1355  uint16_t rsp_flags;
1361  uint16_t nb_matches;
1369  /* W1 */
1370  struct rte_mbuf *mbuf;
1372  /* W2 */
1373  uint16_t group_id0;
1379  uint16_t group_id1;
1384  uint16_t group_id2;
1389  uint16_t group_id3;
1395  /* W3 */
1396  RTE_STD_C11
1397  union {
1398  uint64_t user_id;
1404  void *user_ptr;
1406  };
1407 
1408  /* W4 */
1409  RTE_STD_C11
1410  union {
1411  uint64_t cross_buf_id;
1420  };
1421 
1422  /* W5 */
1423  struct rte_regexdev_match matches[];
1430 };
1431 
1432 #include "rte_regexdev_core.h"
1433 
1471 __rte_experimental
1472 static inline uint16_t
1473 rte_regexdev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
1474  struct rte_regex_ops **ops, uint16_t nb_ops)
1475 {
1476  struct rte_regexdev *dev = &rte_regex_devices[dev_id];
1477 #ifdef RTE_LIBRTE_REGEXDEV_DEBUG
1478  RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL);
1479  if (*dev->enqueue == NULL)
1480  return -ENOTSUP;
1481  if (qp_id >= dev->data->dev_conf.nb_queue_pairs) {
1482  RTE_REGEXDEV_LOG(ERR, "Invalid queue %d\n", qp_id);
1483  return -EINVAL;
1484  }
1485 #endif
1486  return (*dev->enqueue)(dev, qp_id, ops, nb_ops);
1487 }
1488 
1531 __rte_experimental
1532 static inline uint16_t
1533 rte_regexdev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
1534  struct rte_regex_ops **ops, uint16_t nb_ops)
1535 {
1536  struct rte_regexdev *dev = &rte_regex_devices[dev_id];
1537 #ifdef RTE_LIBRTE_REGEXDEV_DEBUG
1538  RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL);
1539  if (*dev->dequeue == NULL)
1540  return -ENOTSUP;
1541  if (qp_id >= dev->data->dev_conf.nb_queue_pairs) {
1542  RTE_REGEXDEV_LOG(ERR, "Invalid queue %d\n", qp_id);
1543  return -EINVAL;
1544  }
1545 #endif
1546  return (*dev->dequeue)(dev, qp_id, ops, nb_ops);
1547 }
1548 
1549 #ifdef __cplusplus
1550 }
1551 #endif
1552 
1553 #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:610
__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:696
#define RTE_REGEXDEV_XSTATS_NAME_SIZE
rte_regexdev_rule_op
Definition: rte_regexdev.h:949
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)
uint16_t max_matches
Definition: rte_regexdev.h:608
__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)
uint16_t nb_actual_matches
const char * rule_db
Definition: rte_regexdev.h:710
__rte_experimental int rte_regexdev_get_dev_id(const char *name)
uint16_t pcre_rule_len
Definition: rte_regexdev.h:966
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:762
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:622
rte_regexdev_attr_id
Definition: rte_regexdev.h:871
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:618
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:39
uint16_t max_payload_size
Definition: rte_regexdev.h:612
__rte_experimental int rte_regexdev_is_valid_dev(uint16_t dev_id)
__rte_experimental int rte_regexdev_rule_db_export(uint8_t dev_id, char *rule_db)
const char * driver_name
Definition: rte_regexdev.h:606
__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:774
const char * pcre_rule
Definition: rte_regexdev.h:964
struct rte_device * dev
Definition: rte_regexdev.h:607
__rte_experimental int rte_regexdev_attr_get(uint8_t dev_id, enum rte_regexdev_attr_id attr_id, void *attr_value)
__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