1bab9497eSJerin Jacob.. SPDX-License-Identifier: BSD-3-Clause 2bab9497eSJerin Jacob Copyright 2020 Mellanox Technologies, Ltd 3bab9497eSJerin Jacob 4*41dd9a6bSDavid YoungRegular Expression (RegEx) Device Library 5*41dd9a6bSDavid Young========================================= 6bab9497eSJerin Jacob 7bab9497eSJerin JacobThe RegEx library provides a RegEx device framework for management and 8bab9497eSJerin Jacobprovisioning of hardware and software RegEx poll mode drivers, defining generic 9bab9497eSJerin JacobAPIs which support a number of different RegEx operations. 10bab9497eSJerin Jacob 11bab9497eSJerin Jacob 12bab9497eSJerin JacobDesign Principles 13bab9497eSJerin Jacob----------------- 14bab9497eSJerin Jacob 15bab9497eSJerin JacobThe RegEx library follows the same basic principles as those used in DPDK's 16bab9497eSJerin JacobEthernet Device framework and the Crypto framework. The RegEx framework provides 17bab9497eSJerin Jacoba generic Crypto device framework which supports both physical (hardware) 18bab9497eSJerin Jacoband virtual (software) RegEx devices as well as a generic RegEx API which allows 19bab9497eSJerin JacobRegEx devices to be managed and configured and supports RegEx operations to be 20bab9497eSJerin Jacobprovisioned on RegEx poll mode driver. 21bab9497eSJerin Jacob 22bab9497eSJerin Jacob 23bab9497eSJerin JacobDevice Management 24bab9497eSJerin Jacob----------------- 25bab9497eSJerin Jacob 26bab9497eSJerin JacobDevice Creation 27bab9497eSJerin Jacob~~~~~~~~~~~~~~~ 28bab9497eSJerin Jacob 29bab9497eSJerin JacobPhysical RegEx devices are discovered during the PCI probe/enumeration of the 30bab9497eSJerin JacobEAL function which is executed at DPDK initialization, based on 31bab9497eSJerin Jacobtheir PCI device identifier, each unique PCI BDF (bus/bridge, device, 32bab9497eSJerin Jacobfunction). Specific physical ReEx devices, like other physical devices in DPDK 33db27370bSStephen Hemmingercan be listed using the EAL command line options. 34bab9497eSJerin Jacob 35bab9497eSJerin Jacob 36bab9497eSJerin JacobDevice Identification 37bab9497eSJerin Jacob~~~~~~~~~~~~~~~~~~~~~ 38bab9497eSJerin Jacob 39bab9497eSJerin JacobEach device, whether virtual or physical is uniquely designated by two 40bab9497eSJerin Jacobidentifiers: 41bab9497eSJerin Jacob 42bab9497eSJerin Jacob- A unique device index used to designate the RegEx device in all functions 43bab9497eSJerin Jacob exported by the regexdev API. 44bab9497eSJerin Jacob 45bab9497eSJerin Jacob- A device name used to designate the RegEx device in console messages, for 46bab9497eSJerin Jacob administration or debugging purposes. 47bab9497eSJerin Jacob 48bab9497eSJerin Jacob 49bab9497eSJerin JacobDevice Configuration 50bab9497eSJerin Jacob~~~~~~~~~~~~~~~~~~~~ 51bab9497eSJerin Jacob 52bab9497eSJerin JacobThe configuration of each RegEx device includes the following operations: 53bab9497eSJerin Jacob 54bab9497eSJerin Jacob- Allocation of resources, including hardware resources if a physical device. 55bab9497eSJerin Jacob- Resetting the device into a well-known default state. 56bab9497eSJerin Jacob- Initialization of statistics counters. 57bab9497eSJerin Jacob 58bab9497eSJerin JacobThe rte_regexdev_configure API is used to configure a RegEx device. 59bab9497eSJerin Jacob 60bab9497eSJerin Jacob.. code-block:: c 61bab9497eSJerin Jacob 62bab9497eSJerin Jacob int rte_regexdev_configure(uint8_t dev_id, 63bab9497eSJerin Jacob const struct rte_regexdev_config *cfg); 64bab9497eSJerin Jacob 65bab9497eSJerin JacobThe ``rte_regexdev_config`` structure is used to pass the configuration 66bab9497eSJerin Jacobparameters for the RegEx device for example number of queue pairs, number of 67bab9497eSJerin Jacobgroups, max number of matches and so on. 68bab9497eSJerin Jacob 69bab9497eSJerin Jacob.. code-block:: c 70bab9497eSJerin Jacob 71bab9497eSJerin Jacob struct rte_regexdev_config { 72bab9497eSJerin Jacob uint16_t nb_max_matches; 73bab9497eSJerin Jacob /**< Maximum matches per scan configured on this device. 74bab9497eSJerin Jacob * This value cannot exceed the *max_matches* 75bab9497eSJerin Jacob * which previously provided in rte_regexdev_info_get(). 76bab9497eSJerin Jacob * The value 0 is allowed, in which case, value 1 used. 77bab9497eSJerin Jacob * @see struct rte_regexdev_info::max_matches 78bab9497eSJerin Jacob */ 79bab9497eSJerin Jacob uint16_t nb_queue_pairs; 80bab9497eSJerin Jacob /**< Number of RegEx queue pairs to configure on this device. 81bab9497eSJerin Jacob * This value cannot exceed the *max_queue_pairs* which previously 82bab9497eSJerin Jacob * provided in rte_regexdev_info_get(). 83bab9497eSJerin Jacob * @see struct rte_regexdev_info::max_queue_pairs 84bab9497eSJerin Jacob */ 85bab9497eSJerin Jacob uint32_t nb_rules_per_group; 86bab9497eSJerin Jacob /**< Number of rules per group to configure on this device. 87bab9497eSJerin Jacob * This value cannot exceed the *max_rules_per_group* 88bab9497eSJerin Jacob * which previously provided in rte_regexdev_info_get(). 89bab9497eSJerin Jacob * The value 0 is allowed, in which case, 90bab9497eSJerin Jacob * struct rte_regexdev_info::max_rules_per_group used. 91bab9497eSJerin Jacob * @see struct rte_regexdev_info::max_rules_per_group 92bab9497eSJerin Jacob */ 93bab9497eSJerin Jacob uint16_t nb_groups; 94bab9497eSJerin Jacob /**< Number of groups to configure on this device. 95bab9497eSJerin Jacob * This value cannot exceed the *max_groups* 96bab9497eSJerin Jacob * which previously provided in rte_regexdev_info_get(). 97bab9497eSJerin Jacob * @see struct rte_regexdev_info::max_groups 98bab9497eSJerin Jacob */ 99bab9497eSJerin Jacob const char *rule_db; 100bab9497eSJerin Jacob /**< Import initial set of prebuilt rule database on this device. 101bab9497eSJerin Jacob * The value NULL is allowed, in which case, the device will not 102bab9497eSJerin Jacob * be configured prebuilt rule database. Application may use 103bab9497eSJerin Jacob * rte_regexdev_rule_db_update() or rte_regexdev_rule_db_import() API 104bab9497eSJerin Jacob * to update or import rule database after the 105bab9497eSJerin Jacob * rte_regexdev_configure(). 106bab9497eSJerin Jacob * @see rte_regexdev_rule_db_update(), rte_regexdev_rule_db_import() 107bab9497eSJerin Jacob */ 108bab9497eSJerin Jacob uint32_t rule_db_len; 109bab9497eSJerin Jacob /**< Length of *rule_db* buffer. */ 110bab9497eSJerin Jacob uint32_t dev_cfg_flags; 111bab9497eSJerin Jacob /**< RegEx device configuration flags, See RTE_REGEXDEV_CFG_* */ 112bab9497eSJerin Jacob }; 113bab9497eSJerin Jacob 114bab9497eSJerin Jacob 115bab9497eSJerin JacobConfiguration of Rules Database 116bab9497eSJerin Jacob~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 117bab9497eSJerin Jacob 118bab9497eSJerin JacobEach Regex device should be configured with the rule database. 119bab9497eSJerin JacobThere are two modes of setting the rule database, online or offline. 120bab9497eSJerin JacobThe online mode means, that the rule database in being compiled by the 121bab9497eSJerin JacobRegEx PMD while in the offline mode the rule database is compiled by external 122bab9497eSJerin Jacobcompiler, and is being loaded to the PMD as a buffer. 123bab9497eSJerin JacobThe configuration mode is depended on the PMD capabilities. 124bab9497eSJerin Jacob 125bab9497eSJerin JacobOnline rule configuration is done using the following API functions: 126bab9497eSJerin Jacob``rte_regexdev_rule_db_update`` which add / remove rules from the rules 1276825dc23SThomas Monjalonprecompiled list. 128bab9497eSJerin Jacob 129bab9497eSJerin JacobOffline rule configuration can be done by adding a pointer to the compiled 130bab9497eSJerin Jacobrule database in the configuration step, or by using 131bab9497eSJerin Jacob``rte_regexdev_rule_db_import`` API. 132bab9497eSJerin Jacob 133bab9497eSJerin Jacob 134bab9497eSJerin JacobConfiguration of Queue Pairs 135bab9497eSJerin Jacob~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 136bab9497eSJerin Jacob 137bab9497eSJerin JacobEach RegEx device can be configured with number of queue pairs. 138bab9497eSJerin JacobEach queue pair is configured using ``rte_regexdev_queue_pair_setup`` 139bab9497eSJerin Jacob 140bab9497eSJerin Jacob 141bab9497eSJerin JacobLogical Cores, Memory and Queues Pair Relationships 142bab9497eSJerin Jacob~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 143bab9497eSJerin Jacob 144bab9497eSJerin JacobMultiple logical cores should never share the same queue pair for enqueuing 145bab9497eSJerin Jacoboperations or dequeuing operations on the same RegEx device since this would 146bab9497eSJerin Jacobrequire global locks and hinder performance. 147bab9497eSJerin Jacob 148bab9497eSJerin Jacob 149bab9497eSJerin JacobDevice Features and Capabilities 150bab9497eSJerin Jacob--------------------------------- 151bab9497eSJerin Jacob 152bab9497eSJerin JacobRegEx devices may support different feature set. 153bab9497eSJerin JacobIn order to get the supported PMD feature ``rte_regexdev_info_get`` 154bab9497eSJerin JacobAPI which return the info of the device and it's supported features. 155bab9497eSJerin Jacob 156bab9497eSJerin Jacob 157bab9497eSJerin JacobEnqueue / Dequeue Burst APIs 158bab9497eSJerin Jacob~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 159bab9497eSJerin Jacob 160bab9497eSJerin JacobThe burst enqueue API uses a RegEx device identifier and a queue pair 161bab9497eSJerin Jacobidentifier to specify the device queue pair to schedule the processing on. 162bab9497eSJerin JacobThe ``nb_ops`` parameter is the number of operations to process which are 163bab9497eSJerin Jacobsupplied in the ``ops`` array of ``rte_regex_ops`` structures. 164bab9497eSJerin JacobThe enqueue function returns the number of operations it actually enqueued for 165bab9497eSJerin Jacobprocessing, a return value equal to ``nb_ops`` means that all packets have been 166bab9497eSJerin Jacobenqueued. 167bab9497eSJerin Jacob 168bab9497eSJerin JacobData pointed in each op, should not be released until the dequeue of for that 169bab9497eSJerin Jacobop. 170bab9497eSJerin Jacob 171bab9497eSJerin JacobThe dequeue API uses the same format as the enqueue API of processed but 172bab9497eSJerin Jacobthe ``nb_ops`` and ``ops`` parameters are now used to specify the max processed 173bab9497eSJerin Jacoboperations the user wishes to retrieve and the location in which to store them. 174bab9497eSJerin JacobThe API call returns the actual number of processed operations returned, this 175bab9497eSJerin Jacobcan never be larger than ``nb_ops``. 176