1*99a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 2*99a2dd95SBruce Richardson * Copyright 2020 Mellanox Technologies, Ltd 3*99a2dd95SBruce Richardson */ 4*99a2dd95SBruce Richardson 5*99a2dd95SBruce Richardson #ifndef _RTE_REGEX_CORE_H_ 6*99a2dd95SBruce Richardson #define _RTE_REGEX_CORE_H_ 7*99a2dd95SBruce Richardson 8*99a2dd95SBruce Richardson /** 9*99a2dd95SBruce Richardson * @file 10*99a2dd95SBruce Richardson * 11*99a2dd95SBruce Richardson * RTE RegEx Device internal header. 12*99a2dd95SBruce Richardson * 13*99a2dd95SBruce Richardson * This header contains internal data types, that are used by the RegEx devices 14*99a2dd95SBruce Richardson * in order to expose their ops to the class. 15*99a2dd95SBruce Richardson * 16*99a2dd95SBruce Richardson * Applications should not use these API directly. 17*99a2dd95SBruce Richardson * 18*99a2dd95SBruce Richardson */ 19*99a2dd95SBruce Richardson 20*99a2dd95SBruce Richardson struct rte_regexdev; 21*99a2dd95SBruce Richardson 22*99a2dd95SBruce Richardson typedef int (*regexdev_info_get_t)(struct rte_regexdev *dev, 23*99a2dd95SBruce Richardson struct rte_regexdev_info *info); 24*99a2dd95SBruce Richardson /**< @internal Get the RegEx device info. */ 25*99a2dd95SBruce Richardson 26*99a2dd95SBruce Richardson typedef int (*regexdev_configure_t)(struct rte_regexdev *dev, 27*99a2dd95SBruce Richardson const struct rte_regexdev_config *cfg); 28*99a2dd95SBruce Richardson /**< @internal Configure the RegEx device. */ 29*99a2dd95SBruce Richardson 30*99a2dd95SBruce Richardson typedef int (*regexdev_qp_setup_t)(struct rte_regexdev *dev, uint16_t id, 31*99a2dd95SBruce Richardson const struct rte_regexdev_qp_conf *qp_conf); 32*99a2dd95SBruce Richardson /**< @internal Setup a queue pair.*/ 33*99a2dd95SBruce Richardson 34*99a2dd95SBruce Richardson typedef int (*regexdev_start_t)(struct rte_regexdev *dev); 35*99a2dd95SBruce Richardson /**< @internal Start the RegEx device. */ 36*99a2dd95SBruce Richardson 37*99a2dd95SBruce Richardson typedef int (*regexdev_stop_t)(struct rte_regexdev *dev); 38*99a2dd95SBruce Richardson /**< @internal Stop the RegEx device. */ 39*99a2dd95SBruce Richardson 40*99a2dd95SBruce Richardson typedef int (*regexdev_close_t)(struct rte_regexdev *dev); 41*99a2dd95SBruce Richardson /**< @internal Close the RegEx device. */ 42*99a2dd95SBruce Richardson 43*99a2dd95SBruce Richardson typedef int (*regexdev_attr_get_t)(struct rte_regexdev *dev, 44*99a2dd95SBruce Richardson enum rte_regexdev_attr_id id, 45*99a2dd95SBruce Richardson void *value); 46*99a2dd95SBruce Richardson /**< @internal Get selected attribute from RegEx device. */ 47*99a2dd95SBruce Richardson 48*99a2dd95SBruce Richardson typedef int (*regexdev_attr_set_t)(struct rte_regexdev *dev, 49*99a2dd95SBruce Richardson enum rte_regexdev_attr_id id, 50*99a2dd95SBruce Richardson const void *value); 51*99a2dd95SBruce Richardson /**< @internal Set selected attribute to RegEx device. */ 52*99a2dd95SBruce Richardson 53*99a2dd95SBruce Richardson typedef int (*regexdev_rule_db_update_t)(struct rte_regexdev *dev, 54*99a2dd95SBruce Richardson const struct rte_regexdev_rule *rules, 55*99a2dd95SBruce Richardson uint16_t nb_rules); 56*99a2dd95SBruce Richardson /**< @internal Update the rule database for the RegEx device. */ 57*99a2dd95SBruce Richardson 58*99a2dd95SBruce Richardson typedef int (*regexdev_rule_db_compile_activate_t)(struct rte_regexdev *dev); 59*99a2dd95SBruce Richardson /**< @internal Compile the rule database and activate it. */ 60*99a2dd95SBruce Richardson 61*99a2dd95SBruce Richardson typedef int (*regexdev_rule_db_import_t)(struct rte_regexdev *dev, 62*99a2dd95SBruce Richardson const char *rule_db, 63*99a2dd95SBruce Richardson uint32_t rule_db_len); 64*99a2dd95SBruce Richardson /**< @internal Upload a pre created rule database to the RegEx device. */ 65*99a2dd95SBruce Richardson 66*99a2dd95SBruce Richardson typedef int (*regexdev_rule_db_export_t)(struct rte_regexdev *dev, 67*99a2dd95SBruce Richardson char *rule_db); 68*99a2dd95SBruce Richardson /**< @internal Export the current rule database from the RegEx device. */ 69*99a2dd95SBruce Richardson 70*99a2dd95SBruce Richardson typedef int (*regexdev_xstats_names_get_t)(struct rte_regexdev *dev, 71*99a2dd95SBruce Richardson struct rte_regexdev_xstats_map 72*99a2dd95SBruce Richardson *xstats_map); 73*99a2dd95SBruce Richardson /**< @internal Get xstats name map for the RegEx device. */ 74*99a2dd95SBruce Richardson 75*99a2dd95SBruce Richardson typedef int (*regexdev_xstats_get_t)(struct rte_regexdev *dev, 76*99a2dd95SBruce Richardson const uint16_t *ids, uint64_t *values, 77*99a2dd95SBruce Richardson uint16_t nb_values); 78*99a2dd95SBruce Richardson /**< @internal Get xstats values for the RegEx device. */ 79*99a2dd95SBruce Richardson 80*99a2dd95SBruce Richardson typedef int (*regexdev_xstats_by_name_get_t)(struct rte_regexdev *dev, 81*99a2dd95SBruce Richardson const char *name, uint16_t *id, 82*99a2dd95SBruce Richardson uint64_t *value); 83*99a2dd95SBruce Richardson /**< @internal Get xstat value for the RegEx device based on the xstats name. */ 84*99a2dd95SBruce Richardson 85*99a2dd95SBruce Richardson typedef int (*regexdev_xstats_reset_t)(struct rte_regexdev *dev, 86*99a2dd95SBruce Richardson const uint16_t *ids, 87*99a2dd95SBruce Richardson uint16_t nb_ids); 88*99a2dd95SBruce Richardson /**< @internal Reset xstats values for the RegEx device. */ 89*99a2dd95SBruce Richardson 90*99a2dd95SBruce Richardson typedef int (*regexdev_selftest_t)(struct rte_regexdev *dev); 91*99a2dd95SBruce Richardson /**< @internal Trigger RegEx self test. */ 92*99a2dd95SBruce Richardson 93*99a2dd95SBruce Richardson typedef int (*regexdev_dump_t)(struct rte_regexdev *dev, FILE *f); 94*99a2dd95SBruce Richardson /**< @internal Dump internal information about the RegEx device. */ 95*99a2dd95SBruce Richardson 96*99a2dd95SBruce Richardson typedef uint16_t (*regexdev_enqueue_t)(struct rte_regexdev *dev, uint16_t qp_id, 97*99a2dd95SBruce Richardson struct rte_regex_ops **ops, 98*99a2dd95SBruce Richardson uint16_t nb_ops); 99*99a2dd95SBruce Richardson /**< @internal Enqueue a burst of scan requests to a queue on RegEx device. */ 100*99a2dd95SBruce Richardson 101*99a2dd95SBruce Richardson typedef uint16_t (*regexdev_dequeue_t)(struct rte_regexdev *dev, uint16_t qp_id, 102*99a2dd95SBruce Richardson struct rte_regex_ops **ops, 103*99a2dd95SBruce Richardson uint16_t nb_ops); 104*99a2dd95SBruce Richardson /**< @internal Dequeue a burst of scan response from a queue on RegEx device. */ 105*99a2dd95SBruce Richardson 106*99a2dd95SBruce Richardson /** 107*99a2dd95SBruce Richardson * RegEx device operations 108*99a2dd95SBruce Richardson */ 109*99a2dd95SBruce Richardson struct rte_regexdev_ops { 110*99a2dd95SBruce Richardson regexdev_info_get_t dev_info_get; 111*99a2dd95SBruce Richardson regexdev_configure_t dev_configure; 112*99a2dd95SBruce Richardson regexdev_qp_setup_t dev_qp_setup; 113*99a2dd95SBruce Richardson regexdev_start_t dev_start; 114*99a2dd95SBruce Richardson regexdev_stop_t dev_stop; 115*99a2dd95SBruce Richardson regexdev_close_t dev_close; 116*99a2dd95SBruce Richardson regexdev_attr_get_t dev_attr_get; 117*99a2dd95SBruce Richardson regexdev_attr_set_t dev_attr_set; 118*99a2dd95SBruce Richardson regexdev_rule_db_update_t dev_rule_db_update; 119*99a2dd95SBruce Richardson regexdev_rule_db_compile_activate_t dev_rule_db_compile_activate; 120*99a2dd95SBruce Richardson regexdev_rule_db_import_t dev_db_import; 121*99a2dd95SBruce Richardson regexdev_rule_db_export_t dev_db_export; 122*99a2dd95SBruce Richardson regexdev_xstats_names_get_t dev_xstats_names_get; 123*99a2dd95SBruce Richardson regexdev_xstats_get_t dev_xstats_get; 124*99a2dd95SBruce Richardson regexdev_xstats_by_name_get_t dev_xstats_by_name_get; 125*99a2dd95SBruce Richardson regexdev_xstats_reset_t dev_xstats_reset; 126*99a2dd95SBruce Richardson regexdev_selftest_t dev_selftest; 127*99a2dd95SBruce Richardson regexdev_dump_t dev_dump; 128*99a2dd95SBruce Richardson }; 129*99a2dd95SBruce Richardson 130*99a2dd95SBruce Richardson /** 131*99a2dd95SBruce Richardson * Possible states of a RegEx device. 132*99a2dd95SBruce Richardson */ 133*99a2dd95SBruce Richardson enum rte_regexdev_state { 134*99a2dd95SBruce Richardson RTE_REGEXDEV_UNUSED = 0, /**< Device is unused. */ 135*99a2dd95SBruce Richardson RTE_REGEXDEV_REGISTERED, 136*99a2dd95SBruce Richardson /**< Device is registered, but not ready to be used. */ 137*99a2dd95SBruce Richardson RTE_REGEXDEV_READY, 138*99a2dd95SBruce Richardson /**< Device is ready for use. This is set by the PMD. */ 139*99a2dd95SBruce Richardson }; 140*99a2dd95SBruce Richardson 141*99a2dd95SBruce Richardson /** 142*99a2dd95SBruce Richardson * @internal 143*99a2dd95SBruce Richardson * The data part, with no function pointers, associated with each RegEx device. 144*99a2dd95SBruce Richardson * 145*99a2dd95SBruce Richardson * This structure is safe to place in shared memory to be common among different 146*99a2dd95SBruce Richardson * processes in a multi-process configuration. 147*99a2dd95SBruce Richardson */ 148*99a2dd95SBruce Richardson struct rte_regexdev_data { 149*99a2dd95SBruce Richardson void *dev_private; /**< PMD-specific private data. */ 150*99a2dd95SBruce Richardson char dev_name[RTE_REGEXDEV_NAME_MAX_LEN]; /**< Unique identifier name */ 151*99a2dd95SBruce Richardson uint16_t dev_id; /**< Device [external] identifier. */ 152*99a2dd95SBruce Richardson struct rte_regexdev_config dev_conf; /**< RegEx configuration. */ 153*99a2dd95SBruce Richardson uint8_t dev_started : 1; /**< Device started to work. */ 154*99a2dd95SBruce Richardson } __rte_cache_aligned; 155*99a2dd95SBruce Richardson 156*99a2dd95SBruce Richardson /** 157*99a2dd95SBruce Richardson * @internal 158*99a2dd95SBruce Richardson * The generic data structure associated with each RegEx device. 159*99a2dd95SBruce Richardson * 160*99a2dd95SBruce Richardson * Pointers to burst-oriented packet receive and transmit functions are 161*99a2dd95SBruce Richardson * located at the beginning of the structure, along with the pointer to 162*99a2dd95SBruce Richardson * where all the data elements for the particular device are stored in shared 163*99a2dd95SBruce Richardson * memory. This split allows the function pointer and driver data to be per- 164*99a2dd95SBruce Richardson * process, while the actual configuration data for the device is shared. 165*99a2dd95SBruce Richardson */ 166*99a2dd95SBruce Richardson struct rte_regexdev { 167*99a2dd95SBruce Richardson regexdev_enqueue_t enqueue; 168*99a2dd95SBruce Richardson regexdev_dequeue_t dequeue; 169*99a2dd95SBruce Richardson const struct rte_regexdev_ops *dev_ops; 170*99a2dd95SBruce Richardson /**< Functions exported by PMD */ 171*99a2dd95SBruce Richardson struct rte_device *device; /**< Backing device */ 172*99a2dd95SBruce Richardson enum rte_regexdev_state state; /**< The device state. */ 173*99a2dd95SBruce Richardson struct rte_regexdev_data *data; /**< Pointer to device data. */ 174*99a2dd95SBruce Richardson } __rte_cache_aligned; 175*99a2dd95SBruce Richardson 176*99a2dd95SBruce Richardson /** 177*99a2dd95SBruce Richardson * @internal 178*99a2dd95SBruce Richardson * The pool of *rte_regexdev* structures. The size of the pool 179*99a2dd95SBruce Richardson * is configured at compile-time in the <rte_regexdev.c> file. 180*99a2dd95SBruce Richardson */ 181*99a2dd95SBruce Richardson extern struct rte_regexdev rte_regex_devices[]; 182*99a2dd95SBruce Richardson 183*99a2dd95SBruce Richardson #endif /* _RTE_REGEX_CORE_H_ */ 184