DPDK  24.07.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 #define RTE_LOGTYPE_REGEXDEV rte_regexdev_logtype
210 
211 #define RTE_REGEXDEV_LOG_LINE(level, ...) \
212  RTE_LOG_LINE(level, REGEXDEV, "" __VA_ARGS__)
213 
214 /* Macros to check for valid port */
215 #define RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, retval) do { \
216  if (!rte_regexdev_is_valid_dev(dev_id)) { \
217  RTE_REGEXDEV_LOG_LINE(ERR, "Invalid dev_id=%u", dev_id); \
218  return retval; \
219  } \
220 } while (0)
221 
222 #define RTE_REGEXDEV_VALID_DEV_ID_OR_RET(dev_id) do { \
223  if (!rte_regexdev_is_valid_dev(dev_id)) { \
224  RTE_REGEXDEV_LOG_LINE(ERR, "Invalid dev_id=%u", dev_id); \
225  return; \
226  } \
227 } while (0)
228 
242 __rte_experimental
243 int rte_regexdev_is_valid_dev(uint16_t dev_id);
244 
255 __rte_experimental
256 uint8_t
257 rte_regexdev_count(void);
258 
272 __rte_experimental
273 int
274 rte_regexdev_get_dev_id(const char *name);
275 
276 /* Enumerates RegEx device capabilities */
277 #define RTE_REGEXDEV_CAPA_RUNTIME_COMPILATION_F (1ULL << 0)
278 
286 #define RTE_REGEXDEV_CAPA_SUPP_PCRE_START_ANCHOR_F (1ULL << 1)
287 
297 #define RTE_REGEXDEV_CAPA_SUPP_PCRE_ATOMIC_GROUPING_F (1ULL << 2)
298 
309 #define RTE_REGEXDEV_SUPP_PCRE_BACKTRACKING_CTRL_F (1ULL << 3)
310 
317 #define RTE_REGEXDEV_SUPP_PCRE_CALLOUTS_F (1ULL << 4)
318 
327 #define RTE_REGEXDEV_SUPP_PCRE_BACKREFERENCE_F (1ULL << 5)
328 
335 #define RTE_REGEXDEV_SUPP_PCRE_GREEDY_F (1ULL << 6)
336 
344 #define RTE_REGEXDEV_SUPP_PCRE_MATCH_ALL_F (1ULL << 7)
345 
353 #define RTE_REGEXDEV_SUPP_PCRE_LOOKAROUND_ASRT_F (1ULL << 8)
354 
363 #define RTE_REGEXDEV_SUPP_PCRE_MATCH_POINT_RST_F (1ULL << 9)
364 
372 #define RTE_REGEXDEV_SUPP_NEWLINE_CONVENTIONS_F (1ULL << 10)
373 
384 #define RTE_REGEXDEV_SUPP_PCRE_NEWLINE_SEQ_F (1ULL << 11)
385 
392 #define RTE_REGEXDEV_SUPP_PCRE_POSSESSIVE_QUALIFIERS_F (1ULL << 12)
393 
402 #define RTE_REGEXDEV_SUPP_PCRE_SUBROUTINE_REFERENCES_F (1ULL << 13)
403 
411 #define RTE_REGEXDEV_SUPP_PCRE_UTF_8_F (1ULL << 14)
412 
417 #define RTE_REGEXDEV_SUPP_PCRE_UTF_16_F (1ULL << 15)
418 
423 #define RTE_REGEXDEV_SUPP_PCRE_UTF_32_F (1ULL << 16)
424 
429 #define RTE_REGEXDEV_SUPP_PCRE_WORD_BOUNDARY_F (1ULL << 17)
430 
436 #define RTE_REGEXDEV_SUPP_PCRE_FORWARD_REFERENCES_F (1ULL << 18)
437 
445 #define RTE_REGEXDEV_SUPP_MATCH_AS_END_F (1ULL << 19)
446 
455 #define RTE_REGEXDEV_SUPP_CROSS_BUFFER_F (1ULL << 20)
456 
471 #define RTE_REGEXDEV_SUPP_MATCH_ALL_F (1ULL << 21)
472 
480 #define RTE_REGEXDEV_CAPA_QUEUE_PAIR_OOS_F (1ULL << 22)
481 
489 /* Enumerates PCRE rule flags */
490 #define RTE_REGEX_PCRE_RULE_ALLOW_EMPTY_F (1ULL << 0)
491 
498 #define RTE_REGEX_PCRE_RULE_ANCHORED_F (1ULL << 1)
499 
507 #define RTE_REGEX_PCRE_RULE_CASELESS_F (1ULL << 2)
508 
515 #define RTE_REGEX_PCRE_RULE_DOTALL_F (1ULL << 3)
516 
523 #define RTE_REGEX_PCRE_RULE_DUPNAMES_F (1ULL << 4)
524 
531 #define RTE_REGEX_PCRE_RULE_EXTENDED_F (1ULL << 5)
532 
539 #define RTE_REGEX_PCRE_RULE_MATCH_UNSET_BACKREF_F (1ULL << 6)
540 
547 #define RTE_REGEX_PCRE_RULE_MULTILINE_F (1ULL << 7)
548 
556 #define RTE_REGEX_PCRE_RULE_NO_AUTO_CAPTURE_F (1ULL << 8)
557 
566 #define RTE_REGEX_PCRE_RULE_UCP_F (1ULL << 9)
567 
574 #define RTE_REGEX_PCRE_RULE_UNGREEDY_F (1ULL << 10)
575 
583 #define RTE_REGEX_PCRE_RULE_UTF_F (1ULL << 11)
584 
592 #define RTE_REGEX_PCRE_RULE_NEVER_BACKSLASH_C_F (1ULL << 12)
593 
607  const char *driver_name;
608  struct rte_device *dev;
609  uint16_t max_matches;
611  uint16_t max_queue_pairs;
617  uint16_t max_segs;
621  uint16_t max_groups;
623  uint32_t regexdev_capa;
625  uint64_t rule_flags;
629 };
630 
648 __rte_experimental
649 int
650 rte_regexdev_info_get(uint8_t dev_id, struct rte_regexdev_info *dev_info);
651 
652 /* Enumerates RegEx device configuration flags */
653 #define RTE_REGEXDEV_CFG_CROSS_BUFFER_SCAN_F (1ULL << 0)
654 
666 #define RTE_REGEXDEV_CFG_MATCH_AS_END_F (1ULL << 1)
667 
676 #define RTE_REGEXDEV_CFG_MATCH_ALL_F (1ULL << 2)
677 
684  uint16_t nb_max_matches;
691  uint16_t nb_queue_pairs;
705  uint16_t nb_groups;
711  const char *rule_db;
720  uint32_t rule_db_len;
722  uint32_t dev_cfg_flags;
724 };
725 
747 __rte_experimental
748 int
749 rte_regexdev_configure(uint8_t dev_id, const struct rte_regexdev_config *cfg);
750 
751 /* Enumerates RegEx queue pair configuration flags */
752 #define RTE_REGEX_QUEUE_PAIR_CFG_OOS_F (1ULL << 0)
753 
762 struct rte_regex_ops;
763 typedef void (*regexdev_stop_flush_t)(uint8_t dev_id, uint16_t qp_id,
764  struct rte_regex_ops *op);
771  uint32_t qp_conf_flags;
773  uint16_t nb_desc;
783 };
784 
803 __rte_experimental
804 int
805 rte_regexdev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
806  const struct rte_regexdev_qp_conf *qp_conf);
807 
826 __rte_experimental
827 int
828 rte_regexdev_start(uint8_t dev_id);
829 
849 __rte_experimental
850 int
851 rte_regexdev_stop(uint8_t dev_id);
852 
865 __rte_experimental
866 int
867 rte_regexdev_close(uint8_t dev_id);
868 
869 /* Device get/set attributes */
870 
898 };
899 
919 __rte_experimental
920 int
921 rte_regexdev_attr_get(uint8_t dev_id, enum rte_regexdev_attr_id attr_id,
922  void *attr_value);
923 
943 __rte_experimental
944 int
945 rte_regexdev_attr_set(uint8_t dev_id, enum rte_regexdev_attr_id attr_id,
946  const void *attr_value);
947 
948 /* Rule related APIs */
955 };
956 
961  uint16_t group_id;
963  uint32_t rule_id;
965  const char *pcre_rule;
967  uint16_t pcre_rule_len;
969  uint64_t rule_flags;
970  /* PCRE rule flags. Supported device specific PCRE rules enumerated
971  * in struct rte_regexdev_info::rule_flags. For successful rule
972  * database update, application needs to provide only supported
973  * rule flags.
974  * @See RTE_REGEX_PCRE_RULE_*, struct rte_regexdev_info::rule_flags
975  */
976 };
977 
1012 __rte_experimental
1013 int
1014 rte_regexdev_rule_db_update(uint8_t dev_id,
1015  const struct rte_regexdev_rule *rules,
1016  uint32_t nb_rules);
1017 
1034 __rte_experimental
1035 int
1037 
1059 __rte_experimental
1060 int
1061 rte_regexdev_rule_db_import(uint8_t dev_id, const char *rule_db,
1062  uint32_t rule_db_len);
1063 
1084 __rte_experimental
1085 int
1086 rte_regexdev_rule_db_export(uint8_t dev_id, char *rule_db);
1087 
1088 /* Extended statistics */
1090 #define RTE_REGEXDEV_XSTATS_NAME_SIZE 64
1091 
1099  uint16_t id;
1103 };
1104 
1124 __rte_experimental
1125 int
1126 rte_regexdev_xstats_names_get(uint8_t dev_id,
1127  struct rte_regexdev_xstats_map *xstats_map);
1128 
1151 __rte_experimental
1152 int
1153 rte_regexdev_xstats_get(uint8_t dev_id, const uint16_t *ids,
1154  uint64_t *values, uint16_t nb_values);
1155 
1178 __rte_experimental
1179 int
1180 rte_regexdev_xstats_by_name_get(uint8_t dev_id, const char *name,
1181  uint16_t *id, uint64_t *value);
1182 
1202 __rte_experimental
1203 int
1204 rte_regexdev_xstats_reset(uint8_t dev_id, const uint16_t *ids,
1205  uint16_t nb_ids);
1206 
1220 __rte_experimental
1221 int
1222 rte_regexdev_selftest(uint8_t dev_id);
1223 
1238 __rte_experimental
1239 int
1240 rte_regexdev_dump(uint8_t dev_id, FILE *f);
1241 
1242 /* Fast path APIs */
1243 
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  union {
1264  uint16_t len;
1266  uint16_t end_offset;
1271  };
1272  };
1273  };
1274 };
1275 
1276 /* Enumerates RegEx request flags. */
1277 #define RTE_REGEX_OPS_REQ_GROUP_ID0_VALID_F (1 << 0)
1278 
1280 #define RTE_REGEX_OPS_REQ_GROUP_ID1_VALID_F (1 << 1)
1281 
1283 #define RTE_REGEX_OPS_REQ_GROUP_ID2_VALID_F (1 << 2)
1284 
1286 #define RTE_REGEX_OPS_REQ_GROUP_ID3_VALID_F (1 << 3)
1287 
1289 #define RTE_REGEX_OPS_REQ_STOP_ON_MATCH_F (1 << 4)
1290 
1292 #define RTE_REGEX_OPS_REQ_MATCH_HIGH_PRIORITY_F (1 << 5)
1293 
1303 /* Enumerates RegEx response flags. */
1304 #define RTE_REGEX_OPS_RSP_PMI_SOJ_F (1 << 0)
1305 
1311 #define RTE_REGEX_OPS_RSP_PMI_EOJ_F (1 << 1)
1312 
1318 #define RTE_REGEX_OPS_RSP_MAX_SCAN_TIMEOUT_F (1 << 2)
1319 
1325 #define RTE_REGEX_OPS_RSP_MAX_MATCH_F (1 << 3)
1326 
1332 #define RTE_REGEX_OPS_RSP_MAX_PREFIX_F (1 << 4)
1333 
1339 #define RTE_REGEX_OPS_RSP_RESOURCE_LIMIT_REACHED_F (1 << 4)
1340 
1349  /* W0 */
1350  uint16_t req_flags;
1354  uint16_t rsp_flags;
1360  uint16_t nb_matches;
1368  /* W1 */
1369  struct rte_mbuf *mbuf;
1371  /* W2 */
1372  uint16_t group_id0;
1378  uint16_t group_id1;
1383  uint16_t group_id2;
1388  uint16_t group_id3;
1394  /* W3 */
1395  union {
1396  uint64_t user_id;
1402  void *user_ptr;
1404  };
1405 
1406  /* W4 */
1407  union {
1408  uint64_t cross_buf_id;
1417  };
1418 
1419  /* W5 */
1420  struct rte_regexdev_match matches[];
1427 };
1428 
1429 #include "rte_regexdev_core.h"
1430 
1468 __rte_experimental
1469 static inline uint16_t
1470 rte_regexdev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
1471  struct rte_regex_ops **ops, uint16_t nb_ops)
1472 {
1473  struct rte_regexdev *dev = &rte_regex_devices[dev_id];
1474 #ifdef RTE_LIBRTE_REGEXDEV_DEBUG
1475  RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL);
1476  if (*dev->enqueue == NULL)
1477  return -ENOTSUP;
1478  if (qp_id >= dev->data->dev_conf.nb_queue_pairs) {
1479  RTE_REGEXDEV_LOG_LINE(ERR, "Invalid queue %d", qp_id);
1480  return -EINVAL;
1481  }
1482 #endif
1483  return (*dev->enqueue)(dev, qp_id, ops, nb_ops);
1484 }
1485 
1528 __rte_experimental
1529 static inline uint16_t
1530 rte_regexdev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
1531  struct rte_regex_ops **ops, uint16_t nb_ops)
1532 {
1533  struct rte_regexdev *dev = &rte_regex_devices[dev_id];
1534 #ifdef RTE_LIBRTE_REGEXDEV_DEBUG
1535  RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL);
1536  if (*dev->dequeue == NULL)
1537  return -ENOTSUP;
1538  if (qp_id >= dev->data->dev_conf.nb_queue_pairs) {
1539  RTE_REGEXDEV_LOG_LINE(ERR, "Invalid queue %d", qp_id);
1540  return -EINVAL;
1541  }
1542 #endif
1543  return (*dev->dequeue)(dev, qp_id, ops, nb_ops);
1544 }
1545 
1546 #ifdef __cplusplus
1547 }
1548 #endif
1549 
1550 #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:611
__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:697
#define RTE_REGEXDEV_XSTATS_NAME_SIZE
rte_regexdev_rule_op
Definition: rte_regexdev.h:950
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:609
__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:711
__rte_experimental int rte_regexdev_get_dev_id(const char *name)
uint16_t pcre_rule_len
Definition: rte_regexdev.h:967
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:763
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:623
rte_regexdev_attr_id
Definition: rte_regexdev.h:872
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:619
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
uint16_t max_payload_size
Definition: rte_regexdev.h:613
__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:607
__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:775
const char * pcre_rule
Definition: rte_regexdev.h:965
struct rte_device * dev
Definition: rte_regexdev.h:608
__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