DPDK  21.02.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 #define RTE_REGEXDEV_CAPA_QUEUE_PAIR_OOS_F (1ULL << 22)
478 
486 /* Enumerates PCRE rule flags */
487 #define RTE_REGEX_PCRE_RULE_ALLOW_EMPTY_F (1ULL << 0)
488 
495 #define RTE_REGEX_PCRE_RULE_ANCHORED_F (1ULL << 1)
496 
504 #define RTE_REGEX_PCRE_RULE_CASELESS_F (1ULL << 2)
505 
512 #define RTE_REGEX_PCRE_RULE_DOTALL_F (1ULL << 3)
513 
520 #define RTE_REGEX_PCRE_RULE_DUPNAMES_F (1ULL << 4)
521 
528 #define RTE_REGEX_PCRE_RULE_EXTENDED_F (1ULL << 5)
529 
536 #define RTE_REGEX_PCRE_RULE_MATCH_UNSET_BACKREF_F (1ULL << 6)
537 
544 #define RTE_REGEX_PCRE_RULE_MULTILINE_F (1ULL << 7)
545 
553 #define RTE_REGEX_PCRE_RULE_NO_AUTO_CAPTURE_F (1ULL << 8)
554 
563 #define RTE_REGEX_PCRE_RULE_UCP_F (1ULL << 9)
564 
571 #define RTE_REGEX_PCRE_RULE_UNGREEDY_F (1ULL << 10)
572 
580 #define RTE_REGEX_PCRE_RULE_UTF_F (1ULL << 11)
581 
589 #define RTE_REGEX_PCRE_RULE_NEVER_BACKSLASH_C_F (1ULL << 12)
590 
604  const char *driver_name;
605  struct rte_device *dev;
606  uint16_t max_matches;
608  uint16_t max_queue_pairs;
616  uint16_t max_groups;
618  uint32_t regexdev_capa;
620  uint64_t rule_flags;
624 };
625 
643 __rte_experimental
644 int
645 rte_regexdev_info_get(uint8_t dev_id, struct rte_regexdev_info *dev_info);
646 
647 /* Enumerates RegEx device configuration flags */
648 #define RTE_REGEXDEV_CFG_CROSS_BUFFER_SCAN_F (1ULL << 0)
649 
661 #define RTE_REGEXDEV_CFG_MATCH_AS_END_F (1ULL << 1)
662 
671 #define RTE_REGEXDEV_CFG_MATCH_ALL_F (1ULL << 2)
672 
679  uint16_t nb_max_matches;
686  uint16_t nb_queue_pairs;
700  uint16_t nb_groups;
706  const char *rule_db;
715  uint32_t rule_db_len;
717  uint32_t dev_cfg_flags;
719 };
720 
742 __rte_experimental
743 int
744 rte_regexdev_configure(uint8_t dev_id, const struct rte_regexdev_config *cfg);
745 
746 /* Enumerates RegEx queue pair configuration flags */
747 #define RTE_REGEX_QUEUE_PAIR_CFG_OOS_F (1ULL << 0)
748 
757 struct rte_regex_ops;
758 typedef void (*regexdev_stop_flush_t)(uint8_t dev_id, uint16_t qp_id,
759  struct rte_regex_ops *op);
766  uint32_t qp_conf_flags;
768  uint16_t nb_desc;
778 };
779 
798 __rte_experimental
799 int
800 rte_regexdev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
801  const struct rte_regexdev_qp_conf *qp_conf);
802 
821 __rte_experimental
822 int
823 rte_regexdev_start(uint8_t dev_id);
824 
844 __rte_experimental
845 int
846 rte_regexdev_stop(uint8_t dev_id);
847 
860 __rte_experimental
861 int
862 rte_regexdev_close(uint8_t dev_id);
863 
864 /* Device get/set attributes */
865 
893 };
894 
914 __rte_experimental
915 int
916 rte_regexdev_attr_get(uint8_t dev_id, enum rte_regexdev_attr_id attr_id,
917  void *attr_value);
918 
938 __rte_experimental
939 int
940 rte_regexdev_attr_set(uint8_t dev_id, enum rte_regexdev_attr_id attr_id,
941  const void *attr_value);
942 
943 /* Rule related APIs */
950 };
951 
956  uint16_t group_id;
958  uint32_t rule_id;
960  const char *pcre_rule;
962  uint16_t pcre_rule_len;
964  uint64_t rule_flags;
965  /* PCRE rule flags. Supported device specific PCRE rules enumerated
966  * in struct rte_regexdev_info::rule_flags. For successful rule
967  * database update, application needs to provide only supported
968  * rule flags.
969  * @See RTE_REGEX_PCRE_RULE_*, struct rte_regexdev_info::rule_flags
970  */
971 };
972 
1007 __rte_experimental
1008 int
1009 rte_regexdev_rule_db_update(uint8_t dev_id,
1010  const struct rte_regexdev_rule *rules,
1011  uint32_t nb_rules);
1012 
1029 __rte_experimental
1030 int
1032 
1054 __rte_experimental
1055 int
1056 rte_regexdev_rule_db_import(uint8_t dev_id, const char *rule_db,
1057  uint32_t rule_db_len);
1058 
1079 __rte_experimental
1080 int
1081 rte_regexdev_rule_db_export(uint8_t dev_id, char *rule_db);
1082 
1083 /* Extended statistics */
1085 #define RTE_REGEXDEV_XSTATS_NAME_SIZE 64
1086 
1094  uint16_t id;
1098 };
1099 
1119 __rte_experimental
1120 int
1121 rte_regexdev_xstats_names_get(uint8_t dev_id,
1122  struct rte_regexdev_xstats_map *xstats_map);
1123 
1146 __rte_experimental
1147 int
1148 rte_regexdev_xstats_get(uint8_t dev_id, const uint16_t *ids,
1149  uint64_t *values, uint16_t nb_values);
1150 
1173 __rte_experimental
1174 int
1175 rte_regexdev_xstats_by_name_get(uint8_t dev_id, const char *name,
1176  uint16_t *id, uint64_t *value);
1177 
1197 __rte_experimental
1198 int
1199 rte_regexdev_xstats_reset(uint8_t dev_id, const uint16_t *ids,
1200  uint16_t nb_ids);
1201 
1215 __rte_experimental
1216 int
1217 rte_regexdev_selftest(uint8_t dev_id);
1218 
1233 __rte_experimental
1234 int
1235 rte_regexdev_dump(uint8_t dev_id, FILE *f);
1236 
1237 /* Fast path APIs */
1238 
1245  RTE_STD_C11
1246  union {
1247  uint64_t u64;
1248  struct {
1249  uint32_t rule_id:20;
1253  uint32_t group_id:12;
1257  uint16_t start_offset;
1259  RTE_STD_C11
1260  union {
1261  uint16_t len;
1263  uint16_t end_offset;
1268  };
1269  };
1270  };
1271 };
1272 
1273 /* Enumerates RegEx request flags. */
1274 #define RTE_REGEX_OPS_REQ_GROUP_ID0_VALID_F (1 << 0)
1275 
1277 #define RTE_REGEX_OPS_REQ_GROUP_ID1_VALID_F (1 << 1)
1278 
1280 #define RTE_REGEX_OPS_REQ_GROUP_ID2_VALID_F (1 << 2)
1281 
1283 #define RTE_REGEX_OPS_REQ_GROUP_ID3_VALID_F (1 << 3)
1284 
1286 #define RTE_REGEX_OPS_REQ_STOP_ON_MATCH_F (1 << 4)
1287 
1289 #define RTE_REGEX_OPS_REQ_MATCH_HIGH_PRIORITY_F (1 << 5)
1290 
1300 /* Enumerates RegEx response flags. */
1301 #define RTE_REGEX_OPS_RSP_PMI_SOJ_F (1 << 0)
1302 
1308 #define RTE_REGEX_OPS_RSP_PMI_EOJ_F (1 << 1)
1309 
1315 #define RTE_REGEX_OPS_RSP_MAX_SCAN_TIMEOUT_F (1 << 2)
1316 
1322 #define RTE_REGEX_OPS_RSP_MAX_MATCH_F (1 << 3)
1323 
1329 #define RTE_REGEX_OPS_RSP_MAX_PREFIX_F (1 << 4)
1330 
1336 #define RTE_REGEX_OPS_RSP_RESOURCE_LIMIT_REACHED_F (1 << 4)
1337 
1346  /* W0 */
1347  uint16_t req_flags;
1351  uint16_t rsp_flags;
1357  uint16_t nb_matches;
1365  /* W1 */
1366  struct rte_mbuf *mbuf;
1368  /* W2 */
1369  uint16_t group_id0;
1375  uint16_t group_id1;
1380  uint16_t group_id2;
1385  uint16_t group_id3;
1391  /* W3 */
1392  RTE_STD_C11
1393  union {
1394  uint64_t user_id;
1400  void *user_ptr;
1402  };
1403 
1404  /* W4 */
1405  RTE_STD_C11
1406  union {
1407  uint64_t cross_buf_id;
1416  };
1417 
1418  /* W5 */
1426 };
1427 
1428 #include "rte_regexdev_core.h"
1429 
1467 __rte_experimental
1468 static inline uint16_t
1469 rte_regexdev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
1470  struct rte_regex_ops **ops, uint16_t nb_ops)
1471 {
1472  struct rte_regexdev *dev = &rte_regex_devices[dev_id];
1473 #ifdef RTE_LIBRTE_REGEXDEV_DEBUG
1474  RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL);
1475  RTE_FUNC_PTR_OR_ERR_RET(*dev->enqueue, -ENOTSUP);
1476  if (qp_id >= dev->data->dev_conf.nb_queue_pairs) {
1477  RTE_REGEXDEV_LOG(ERR, "Invalid queue %d\n", qp_id);
1478  return -EINVAL;
1479  }
1480 #endif
1481  return (*dev->enqueue)(dev, qp_id, ops, nb_ops);
1482 }
1483 
1526 __rte_experimental
1527 static inline uint16_t
1528 rte_regexdev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
1529  struct rte_regex_ops **ops, uint16_t nb_ops)
1530 {
1531  struct rte_regexdev *dev = &rte_regex_devices[dev_id];
1532 #ifdef RTE_LIBRTE_REGEXDEV_DEBUG
1533  RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL);
1534  RTE_FUNC_PTR_OR_ERR_RET(*dev->dequeue, -ENOTSUP);
1535  if (qp_id >= dev->data->dev_conf.nb_queue_pairs) {
1536  RTE_REGEXDEV_LOG(ERR, "Invalid queue %d\n", qp_id);
1537  return -EINVAL;
1538  }
1539 #endif
1540  return (*dev->dequeue)(dev, qp_id, ops, nb_ops);
1541 }
1542 
1543 #ifdef __cplusplus
1544 }
1545 #endif
1546 
1547 #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:608
__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:692
#define RTE_REGEXDEV_XSTATS_NAME_SIZE
rte_regexdev_rule_op
Definition: rte_regexdev.h:945
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:954
uint16_t max_matches
Definition: rte_regexdev.h:606
__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:706
__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:962
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:758
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:618
rte_regexdev_attr_id
Definition: rte_regexdev.h:867
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:614
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:610
__rte_experimental int rte_regexdev_rule_db_export(uint8_t dev_id, char *rule_db)
const char * driver_name
Definition: rte_regexdev.h:604
__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:770
const char * pcre_rule
Definition: rte_regexdev.h:960
struct rte_device * dev
Definition: rte_regexdev.h:605
__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