DPDK  24.11.0-rc3
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 #include <rte_compat.h>
198 #include <rte_common.h>
199 #include <rte_dev.h>
200 #include <rte_mbuf.h>
201 
202 #define RTE_REGEXDEV_NAME_MAX_LEN RTE_DEV_NAME_MAX_LEN
203 
204 extern int rte_regexdev_logtype;
205 #define RTE_LOGTYPE_REGEXDEV rte_regexdev_logtype
206 
207 #define RTE_REGEXDEV_LOG_LINE(level, ...) \
208  RTE_LOG_LINE(level, REGEXDEV, "" __VA_ARGS__)
209 
210 /* Macros to check for valid port */
211 #define RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, retval) do { \
212  if (!rte_regexdev_is_valid_dev(dev_id)) { \
213  RTE_REGEXDEV_LOG_LINE(ERR, "Invalid dev_id=%u", dev_id); \
214  return retval; \
215  } \
216 } while (0)
217 
218 #define RTE_REGEXDEV_VALID_DEV_ID_OR_RET(dev_id) do { \
219  if (!rte_regexdev_is_valid_dev(dev_id)) { \
220  RTE_REGEXDEV_LOG_LINE(ERR, "Invalid dev_id=%u", dev_id); \
221  return; \
222  } \
223 } while (0)
224 
238 __rte_experimental
239 int rte_regexdev_is_valid_dev(uint16_t dev_id);
240 
251 __rte_experimental
252 uint8_t
253 rte_regexdev_count(void);
254 
268 __rte_experimental
269 int
270 rte_regexdev_get_dev_id(const char *name);
271 
272 /* Enumerates RegEx device capabilities */
273 #define RTE_REGEXDEV_CAPA_RUNTIME_COMPILATION_F (1ULL << 0)
274 
282 #define RTE_REGEXDEV_CAPA_SUPP_PCRE_START_ANCHOR_F (1ULL << 1)
283 
293 #define RTE_REGEXDEV_CAPA_SUPP_PCRE_ATOMIC_GROUPING_F (1ULL << 2)
294 
305 #define RTE_REGEXDEV_SUPP_PCRE_BACKTRACKING_CTRL_F (1ULL << 3)
306 
313 #define RTE_REGEXDEV_SUPP_PCRE_CALLOUTS_F (1ULL << 4)
314 
323 #define RTE_REGEXDEV_SUPP_PCRE_BACKREFERENCE_F (1ULL << 5)
324 
331 #define RTE_REGEXDEV_SUPP_PCRE_GREEDY_F (1ULL << 6)
332 
340 #define RTE_REGEXDEV_SUPP_PCRE_MATCH_ALL_F (1ULL << 7)
341 
349 #define RTE_REGEXDEV_SUPP_PCRE_LOOKAROUND_ASRT_F (1ULL << 8)
350 
359 #define RTE_REGEXDEV_SUPP_PCRE_MATCH_POINT_RST_F (1ULL << 9)
360 
368 #define RTE_REGEXDEV_SUPP_NEWLINE_CONVENTIONS_F (1ULL << 10)
369 
380 #define RTE_REGEXDEV_SUPP_PCRE_NEWLINE_SEQ_F (1ULL << 11)
381 
388 #define RTE_REGEXDEV_SUPP_PCRE_POSSESSIVE_QUALIFIERS_F (1ULL << 12)
389 
398 #define RTE_REGEXDEV_SUPP_PCRE_SUBROUTINE_REFERENCES_F (1ULL << 13)
399 
407 #define RTE_REGEXDEV_SUPP_PCRE_UTF_8_F (1ULL << 14)
408 
413 #define RTE_REGEXDEV_SUPP_PCRE_UTF_16_F (1ULL << 15)
414 
419 #define RTE_REGEXDEV_SUPP_PCRE_UTF_32_F (1ULL << 16)
420 
425 #define RTE_REGEXDEV_SUPP_PCRE_WORD_BOUNDARY_F (1ULL << 17)
426 
432 #define RTE_REGEXDEV_SUPP_PCRE_FORWARD_REFERENCES_F (1ULL << 18)
433 
441 #define RTE_REGEXDEV_SUPP_MATCH_AS_END_F (1ULL << 19)
442 
451 #define RTE_REGEXDEV_SUPP_CROSS_BUFFER_F (1ULL << 20)
452 
467 #define RTE_REGEXDEV_SUPP_MATCH_ALL_F (1ULL << 21)
468 
476 #define RTE_REGEXDEV_CAPA_QUEUE_PAIR_OOS_F (1ULL << 22)
477 
485 /* Enumerates PCRE rule flags */
486 #define RTE_REGEX_PCRE_RULE_ALLOW_EMPTY_F (1ULL << 0)
487 
494 #define RTE_REGEX_PCRE_RULE_ANCHORED_F (1ULL << 1)
495 
503 #define RTE_REGEX_PCRE_RULE_CASELESS_F (1ULL << 2)
504 
511 #define RTE_REGEX_PCRE_RULE_DOTALL_F (1ULL << 3)
512 
519 #define RTE_REGEX_PCRE_RULE_DUPNAMES_F (1ULL << 4)
520 
527 #define RTE_REGEX_PCRE_RULE_EXTENDED_F (1ULL << 5)
528 
535 #define RTE_REGEX_PCRE_RULE_MATCH_UNSET_BACKREF_F (1ULL << 6)
536 
543 #define RTE_REGEX_PCRE_RULE_MULTILINE_F (1ULL << 7)
544 
552 #define RTE_REGEX_PCRE_RULE_NO_AUTO_CAPTURE_F (1ULL << 8)
553 
562 #define RTE_REGEX_PCRE_RULE_UCP_F (1ULL << 9)
563 
570 #define RTE_REGEX_PCRE_RULE_UNGREEDY_F (1ULL << 10)
571 
579 #define RTE_REGEX_PCRE_RULE_UTF_F (1ULL << 11)
580 
588 #define RTE_REGEX_PCRE_RULE_NEVER_BACKSLASH_C_F (1ULL << 12)
589 
603  const char *driver_name;
604  struct rte_device *dev;
605  uint16_t max_matches;
607  uint16_t max_queue_pairs;
613  uint16_t max_segs;
617  uint16_t max_groups;
619  uint32_t regexdev_capa;
621  uint64_t rule_flags;
625 };
626 
644 __rte_experimental
645 int
646 rte_regexdev_info_get(uint8_t dev_id, struct rte_regexdev_info *dev_info);
647 
648 /* Enumerates RegEx device configuration flags */
649 #define RTE_REGEXDEV_CFG_CROSS_BUFFER_SCAN_F (1ULL << 0)
650 
662 #define RTE_REGEXDEV_CFG_MATCH_AS_END_F (1ULL << 1)
663 
672 #define RTE_REGEXDEV_CFG_MATCH_ALL_F (1ULL << 2)
673 
680  uint16_t nb_max_matches;
687  uint16_t nb_queue_pairs;
701  uint16_t nb_groups;
707  const char *rule_db;
716  uint32_t rule_db_len;
718  uint32_t dev_cfg_flags;
720 };
721 
743 __rte_experimental
744 int
745 rte_regexdev_configure(uint8_t dev_id, const struct rte_regexdev_config *cfg);
746 
747 /* Enumerates RegEx queue pair configuration flags */
748 #define RTE_REGEX_QUEUE_PAIR_CFG_OOS_F (1ULL << 0)
749 
758 struct rte_regex_ops;
759 typedef void (*regexdev_stop_flush_t)(uint8_t dev_id, uint16_t qp_id,
760  struct rte_regex_ops *op);
767  uint32_t qp_conf_flags;
769  uint16_t nb_desc;
779 };
780 
799 __rte_experimental
800 int
801 rte_regexdev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
802  const struct rte_regexdev_qp_conf *qp_conf);
803 
822 __rte_experimental
823 int
824 rte_regexdev_start(uint8_t dev_id);
825 
845 __rte_experimental
846 int
847 rte_regexdev_stop(uint8_t dev_id);
848 
861 __rte_experimental
862 int
863 rte_regexdev_close(uint8_t dev_id);
864 
865 /* Device get/set attributes */
866 
894 };
895 
915 __rte_experimental
916 int
917 rte_regexdev_attr_get(uint8_t dev_id, enum rte_regexdev_attr_id attr_id,
918  void *attr_value);
919 
939 __rte_experimental
940 int
941 rte_regexdev_attr_set(uint8_t dev_id, enum rte_regexdev_attr_id attr_id,
942  const void *attr_value);
943 
944 /* Rule related APIs */
951 };
952 
957  uint16_t group_id;
959  uint32_t rule_id;
961  const char *pcre_rule;
963  uint16_t pcre_rule_len;
965  uint64_t rule_flags;
966  /* PCRE rule flags. Supported device specific PCRE rules enumerated
967  * in struct rte_regexdev_info::rule_flags. For successful rule
968  * database update, application needs to provide only supported
969  * rule flags.
970  * @See RTE_REGEX_PCRE_RULE_*, struct rte_regexdev_info::rule_flags
971  */
972 };
973 
1008 __rte_experimental
1009 int
1010 rte_regexdev_rule_db_update(uint8_t dev_id,
1011  const struct rte_regexdev_rule *rules,
1012  uint32_t nb_rules);
1013 
1030 __rte_experimental
1031 int
1033 
1055 __rte_experimental
1056 int
1057 rte_regexdev_rule_db_import(uint8_t dev_id, const char *rule_db,
1058  uint32_t rule_db_len);
1059 
1080 __rte_experimental
1081 int
1082 rte_regexdev_rule_db_export(uint8_t dev_id, char *rule_db);
1083 
1084 /* Extended statistics */
1086 #define RTE_REGEXDEV_XSTATS_NAME_SIZE 64
1087 
1095  uint16_t id;
1099 };
1100 
1120 __rte_experimental
1121 int
1122 rte_regexdev_xstats_names_get(uint8_t dev_id,
1123  struct rte_regexdev_xstats_map *xstats_map);
1124 
1147 __rte_experimental
1148 int
1149 rte_regexdev_xstats_get(uint8_t dev_id, const uint16_t *ids,
1150  uint64_t *values, uint16_t nb_values);
1151 
1174 __rte_experimental
1175 int
1176 rte_regexdev_xstats_by_name_get(uint8_t dev_id, const char *name,
1177  uint16_t *id, uint64_t *value);
1178 
1198 __rte_experimental
1199 int
1200 rte_regexdev_xstats_reset(uint8_t dev_id, const uint16_t *ids,
1201  uint16_t nb_ids);
1202 
1216 __rte_experimental
1217 int
1218 rte_regexdev_selftest(uint8_t dev_id);
1219 
1234 __rte_experimental
1235 int
1236 rte_regexdev_dump(uint8_t dev_id, FILE *f);
1237 
1238 /* Fast path APIs */
1239 
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  union {
1260  uint16_t len;
1262  uint16_t end_offset;
1267  };
1268  };
1269  };
1270 };
1271 
1272 /* Enumerates RegEx request flags. */
1273 #define RTE_REGEX_OPS_REQ_GROUP_ID0_VALID_F (1 << 0)
1274 
1276 #define RTE_REGEX_OPS_REQ_GROUP_ID1_VALID_F (1 << 1)
1277 
1279 #define RTE_REGEX_OPS_REQ_GROUP_ID2_VALID_F (1 << 2)
1280 
1282 #define RTE_REGEX_OPS_REQ_GROUP_ID3_VALID_F (1 << 3)
1283 
1285 #define RTE_REGEX_OPS_REQ_STOP_ON_MATCH_F (1 << 4)
1286 
1288 #define RTE_REGEX_OPS_REQ_MATCH_HIGH_PRIORITY_F (1 << 5)
1289 
1299 /* Enumerates RegEx response flags. */
1300 #define RTE_REGEX_OPS_RSP_PMI_SOJ_F (1 << 0)
1301 
1307 #define RTE_REGEX_OPS_RSP_PMI_EOJ_F (1 << 1)
1308 
1314 #define RTE_REGEX_OPS_RSP_MAX_SCAN_TIMEOUT_F (1 << 2)
1315 
1321 #define RTE_REGEX_OPS_RSP_MAX_MATCH_F (1 << 3)
1322 
1328 #define RTE_REGEX_OPS_RSP_MAX_PREFIX_F (1 << 4)
1329 
1335 #define RTE_REGEX_OPS_RSP_RESOURCE_LIMIT_REACHED_F (1 << 4)
1336 
1345  /* W0 */
1346  uint16_t req_flags;
1350  uint16_t rsp_flags;
1356  uint16_t nb_matches;
1364  /* W1 */
1365  struct rte_mbuf *mbuf;
1367  /* W2 */
1368  uint16_t group_id0;
1374  uint16_t group_id1;
1379  uint16_t group_id2;
1384  uint16_t group_id3;
1390  /* W3 */
1391  union {
1392  uint64_t user_id;
1398  void *user_ptr;
1400  };
1401 
1402  /* W4 */
1403  union {
1404  uint64_t cross_buf_id;
1413  };
1414 
1415  /* W5 */
1416  struct rte_regexdev_match matches[];
1423 };
1424 
1425 #include "rte_regexdev_core.h"
1426 
1427 #ifdef __cplusplus
1428 extern "C" {
1429 #endif
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:607
__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:693
#define RTE_REGEXDEV_XSTATS_NAME_SIZE
rte_regexdev_rule_op
Definition: rte_regexdev.h:946
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:605
__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:707
__rte_experimental int rte_regexdev_get_dev_id(const char *name)
uint16_t pcre_rule_len
Definition: rte_regexdev.h:963
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:759
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:619
rte_regexdev_attr_id
Definition: rte_regexdev.h:868
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:615
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:609
__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:603
__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:771
const char * pcre_rule
Definition: rte_regexdev.h:961
struct rte_device * dev
Definition: rte_regexdev.h:604
__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