#include "mlx5_regex.h"
#include "mlx5_regex_utils.h"
-#include "mlx5_rxp_csrs.h"
#define MLX5_REGEX_DRIVER_NAME regex_mlx5
int mlx5_regex_logtype;
-TAILQ_HEAD(regex_mem_event, mlx5_regex_priv) mlx5_mem_event_list =
- TAILQ_HEAD_INITIALIZER(mlx5_mem_event_list);
-static pthread_mutex_t mem_event_list_lock = PTHREAD_MUTEX_INITIALIZER;
-
const struct rte_regexdev_ops mlx5_regexdev_ops = {
.dev_info_get = mlx5_regex_info_get,
.dev_configure = mlx5_regex_configure,
};
int
-mlx5_regex_start(struct rte_regexdev *dev __rte_unused)
+mlx5_regex_start(struct rte_regexdev *dev)
{
- return 0;
+ struct mlx5_regex_priv *priv = dev->data->dev_private;
+
+ return mlx5_dev_mempool_subscribe(priv->cdev);
}
int
mlx5_regex_stop(struct rte_regexdev *dev __rte_unused)
{
+ struct mlx5_regex_priv *priv = dev->data->dev_private;
+
+ mlx5_regex_clean_ctrl(dev);
+ rte_free(priv->qps);
+ priv->qps = NULL;
+
return 0;
}
return 0;
}
-static int
-mlx5_regex_engines_status(struct ibv_context *ctx, int num_engines)
-{
- uint32_t fpga_ident = 0;
- int err;
- int i;
-
- for (i = 0; i < num_engines; i++) {
- err = mlx5_devx_regex_register_read(ctx, i,
- MLX5_RXP_CSR_IDENTIFIER,
- &fpga_ident);
- fpga_ident = (fpga_ident & (0x0000FFFF));
- if (err || fpga_ident != MLX5_RXP_IDENTIFIER) {
- DRV_LOG(ERR, "Failed setup RXP %d err %d database "
- "memory 0x%x", i, err, fpga_ident);
- if (!err)
- err = EINVAL;
- return err;
- }
- }
- return 0;
-}
-
static void
mlx5_regex_get_name(char *name, struct rte_device *dev)
{
sprintf(name, "mlx5_regex_%s", dev->name);
}
-/**
- * Callback for memory event.
- *
- * @param event_type
- * Memory event type.
- * @param addr
- * Address of memory.
- * @param len
- * Size of memory.
- */
-static void
-mlx5_regex_mr_mem_event_cb(enum rte_mem_event event_type, const void *addr,
- size_t len, void *arg __rte_unused)
-{
- struct mlx5_regex_priv *priv;
-
- /* Must be called from the primary process. */
- MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
- switch (event_type) {
- case RTE_MEM_EVENT_FREE:
- pthread_mutex_lock(&mem_event_list_lock);
- /* Iterate all the existing mlx5 devices. */
- TAILQ_FOREACH(priv, &mlx5_mem_event_list, mem_event_cb)
- mlx5_free_mr_by_addr(&priv->mr_scache,
- mlx5_os_get_ctx_device_name
- (priv->cdev->ctx),
- addr, len);
- pthread_mutex_unlock(&mem_event_list_lock);
- break;
- case RTE_MEM_EVENT_ALLOC:
- default:
- break;
- }
-}
-
static int
-mlx5_regex_dev_probe(struct mlx5_common_device *cdev)
+mlx5_regex_dev_probe(struct mlx5_common_device *cdev,
+ struct mlx5_kvargs_ctrl *mkvlist __rte_unused)
{
struct mlx5_regex_priv *priv = NULL;
- struct mlx5_hca_attr attr;
+ struct mlx5_hca_attr *attr = &cdev->config.hca_attr;
char name[RTE_REGEXDEV_NAME_MAX_LEN];
int ret;
- uint32_t val;
- ret = mlx5_devx_cmd_query_hca_attr(cdev->ctx, &attr);
- if (ret) {
- DRV_LOG(ERR, "Unable to read HCA capabilities.");
- rte_errno = ENOTSUP;
- return -rte_errno;
- } else if (((!attr.regex) && (!attr.mmo_regex_sq_en) &&
- (!attr.mmo_regex_qp_en)) || attr.regexp_num_of_engines == 0) {
+ if ((!attr->regexp_params && !attr->mmo_regex_sq_en && !attr->mmo_regex_qp_en)
+ || attr->regexp_num_of_engines == 0) {
DRV_LOG(ERR, "Not enough capabilities to support RegEx, maybe "
"old FW/OFED version?");
rte_errno = ENOTSUP;
return -rte_errno;
}
- if (mlx5_regex_engines_status(cdev->ctx, 2)) {
- DRV_LOG(ERR, "RegEx engine error.");
- rte_errno = ENOMEM;
- return -rte_errno;
- }
priv = rte_zmalloc("mlx5 regex device private", sizeof(*priv),
RTE_CACHE_LINE_SIZE);
if (!priv) {
rte_errno = ENOMEM;
return -rte_errno;
}
- priv->mmo_regex_qp_cap = attr.mmo_regex_qp_en;
- priv->mmo_regex_sq_cap = attr.mmo_regex_sq_en;
- priv->qp_ts_format = attr.qp_ts_format;
+ priv->mmo_regex_qp_cap = attr->mmo_regex_qp_en;
+ priv->mmo_regex_sq_cap = attr->mmo_regex_sq_en;
priv->cdev = cdev;
priv->nb_engines = 2; /* attr.regexp_num_of_engines */
- ret = mlx5_devx_regex_register_read(priv->cdev->ctx, 0,
- MLX5_RXP_CSR_IDENTIFIER, &val);
- if (ret) {
- DRV_LOG(ERR, "CSR read failed!");
- goto dev_error;
- }
- if (val == MLX5_RXP_BF2_IDENTIFIER)
+ if (attr->regexp_version == MLX5_RXP_BF2_IDENTIFIER)
priv->is_bf2 = 1;
/* Default RXP programming mode to Shared. */
priv->prog_mode = MLX5_RXP_SHARED_PROG_MODE;
rte_errno = rte_errno ? rte_errno : EINVAL;
goto dev_error;
}
- /*
- * This PMD always claims the write memory barrier on UAR
- * registers writings, it is safe to allocate UAR with any
- * memory mapping type.
- */
- priv->uar = mlx5_devx_alloc_uar(priv->cdev->ctx, -1);
- if (!priv->uar) {
- DRV_LOG(ERR, "can't allocate uar.");
- rte_errno = ENOMEM;
+ ret = mlx5_devx_uar_prepare(cdev, &priv->uar);
+ if (ret)
goto error;
- }
priv->regexdev->dev_ops = &mlx5_regexdev_ops;
priv->regexdev->enqueue = mlx5_regexdev_enqueue;
#ifdef HAVE_MLX5_UMR_IMKEY
- if (!attr.umr_indirect_mkey_disabled &&
- !attr.umr_modify_entity_size_disabled)
+ if (!attr->umr_indirect_mkey_disabled &&
+ !attr->umr_modify_entity_size_disabled)
priv->has_umr = 1;
if (priv->has_umr)
priv->regexdev->enqueue = mlx5_regexdev_enqueue_gga;
priv->regexdev->device = cdev->dev;
priv->regexdev->data->dev_private = priv;
priv->regexdev->state = RTE_REGEXDEV_READY;
- priv->mr_scache.reg_mr_cb = mlx5_common_verbs_reg_mr;
- priv->mr_scache.dereg_mr_cb = mlx5_common_verbs_dereg_mr;
- ret = mlx5_mr_btree_init(&priv->mr_scache.cache,
- MLX5_MR_BTREE_CACHE_N * 2,
- rte_socket_id());
- if (ret) {
- DRV_LOG(ERR, "MR init tree failed.");
- rte_errno = ENOMEM;
- goto error;
- }
- /* Register callback function for global shared MR cache management. */
- if (TAILQ_EMPTY(&mlx5_mem_event_list))
- rte_mem_event_callback_register("MLX5_MEM_EVENT_CB",
- mlx5_regex_mr_mem_event_cb,
- NULL);
- /* Add device to memory callback list. */
- pthread_mutex_lock(&mem_event_list_lock);
- TAILQ_INSERT_TAIL(&mlx5_mem_event_list, priv, mem_event_cb);
- pthread_mutex_unlock(&mem_event_list_lock);
DRV_LOG(INFO, "RegEx GGA is %s.",
priv->has_umr ? "supported" : "unsupported");
return 0;
error:
- if (priv->uar)
- mlx5_glue->devx_free_uar(priv->uar);
if (priv->regexdev)
rte_regexdev_unregister(priv->regexdev);
dev_error:
- if (priv)
- rte_free(priv);
+ rte_free(priv);
return -rte_errno;
}
return 0;
priv = dev->data->dev_private;
if (priv) {
- /* Remove from memory callback device list. */
- pthread_mutex_lock(&mem_event_list_lock);
- TAILQ_REMOVE(&mlx5_mem_event_list, priv, mem_event_cb);
- pthread_mutex_unlock(&mem_event_list_lock);
- if (TAILQ_EMPTY(&mlx5_mem_event_list))
- rte_mem_event_callback_unregister("MLX5_MEM_EVENT_CB",
- NULL);
- if (priv->mr_scache.cache.table)
- mlx5_mr_release_cache(&priv->mr_scache);
- if (priv->uar)
- mlx5_glue->devx_free_uar(priv->uar);
+ mlx5_devx_uar_release(&priv->uar);
if (priv->regexdev)
rte_regexdev_unregister(priv->regexdev);
rte_free(priv);