DPDK patches and discussions
 help / color / mirror / Atom feed
From: Francis Kelly <fkelly@nvidia.com>
To: <tmonjalon@nvidia.com>, Ori Kam <orika@nvidia.com>
Cc: <jamhunter@nvidia.com>, <aagbarih@nvidia.com>, <dev@dpdk.org>,
	Ady Agbarih <adypodoman@gmail.com>
Subject: [dpdk-dev] [PATCH 05/10] regex/mlx5: move RXP to CrSpace
Date: Fri, 22 Oct 2021 15:45:55 +0000	[thread overview]
Message-ID: <20211022154600.2180938-5-fkelly@nvidia.com> (raw)
In-Reply-To: <20211022154600.2180938-1-fkelly@nvidia.com>

From: Ady Agbarih <adypodoman@gmail.com>

Add patch for programming the regex database through rof file,
using the firmware instead of manually through the software.
No need to setup the DB anymore, the regex-daemon is responsible
for that always.
In the new flow the regex driver only has to program rof rules
by using set params devx cmd, requires rof mkey creation.
The rules file has to be read into 4KB aligned memory.

Signed-off-by: Ady Agbarih <adypodoman@gmail.com>
---
 drivers/regex/mlx5/mlx5_regex.h |  12 ----
 drivers/regex/mlx5/mlx5_rxp.c   | 111 ++++++++++++++++++++------------
 drivers/regex/mlx5/mlx5_rxp.h   |   4 +-
 3 files changed, 72 insertions(+), 55 deletions(-)

diff --git a/drivers/regex/mlx5/mlx5_regex.h b/drivers/regex/mlx5/mlx5_regex.h
index 09b360a1ab..9741421e7a 100644
--- a/drivers/regex/mlx5/mlx5_regex.h
+++ b/drivers/regex/mlx5/mlx5_regex.h
@@ -46,16 +46,6 @@ struct mlx5_regex_qp {
 	struct mlx5_mr_ctrl mr_ctrl;
 };
 
-struct mlx5_regex_db {
-	void *ptr; /* Pointer to the db memory. */
-	uint32_t len; /* The memory len. */
-	bool active; /* Active flag. */
-	uint8_t db_assigned_to_eng_num;
-	/**< To which engine the db is connected. */
-	struct mlx5_regex_umem umem;
-	/**< The umem struct. */
-};
-
 struct mlx5_regex_priv {
 	TAILQ_ENTRY(mlx5_regex_priv) next;
 	struct ibv_context *ctx; /* Device context. */
@@ -64,8 +54,6 @@ struct mlx5_regex_priv {
 	struct mlx5_regex_qp *qps; /* Pointer to the qp array. */
 	uint16_t nb_max_matches; /* Max number of matches. */
 	enum mlx5_rxp_program_mode prog_mode;
-	struct mlx5_regex_db db[MLX5_RXP_MAX_ENGINES +
-				MLX5_RXP_EM_COUNT];
 	uint32_t nb_engines; /* Number of RegEx engines. */
 	struct mlx5dv_devx_uar *uar; /* UAR object. */
 	struct ibv_pd *pd;
diff --git a/drivers/regex/mlx5/mlx5_rxp.c b/drivers/regex/mlx5/mlx5_rxp.c
index 8f54ab018e..59c68544ad 100644
--- a/drivers/regex/mlx5/mlx5_rxp.c
+++ b/drivers/regex/mlx5/mlx5_rxp.c
@@ -28,6 +28,12 @@
 #define MLX5_REGEX_RXP_ROF2_LINE_LEN 34
 
 /* Private Declarations */
+static int
+rxp_create_mkey(struct mlx5_regex_priv *priv, void *ptr, size_t size,
+	uint32_t access, struct mlx5_regex_mkey *mkey);
+static inline void
+rxp_destroy_mkey(struct mlx5_regex_mkey *mkey);
+
 int
 mlx5_regex_info_get(struct rte_regexdev *dev __rte_unused,
 		    struct rte_regexdev_info *info)
@@ -44,44 +50,46 @@ mlx5_regex_info_get(struct rte_regexdev *dev __rte_unused,
 }
 
 static int
-rxp_db_setup(struct mlx5_regex_priv *priv)
+rxp_create_mkey(struct mlx5_regex_priv *priv, void *ptr, size_t size,
+	uint32_t access, struct mlx5_regex_mkey *mkey)
 {
-	int ret;
-	uint8_t i;
+	struct mlx5_devx_mkey_attr mkey_attr;
 
-	/* Setup database memories for both RXP engines + reprogram memory. */
-	for (i = 0; i < (priv->nb_engines + MLX5_RXP_EM_COUNT); i++) {
-		priv->db[i].ptr = rte_malloc("", MLX5_MAX_DB_SIZE, 1 << 21);
-		if (!priv->db[i].ptr) {
-			DRV_LOG(ERR, "Failed to alloc db memory!");
-			ret = ENODEV;
-			goto tidyup_error;
-		}
-		/* Register the memory. */
-		priv->db[i].umem.umem = mlx5_glue->devx_umem_reg(priv->ctx,
-							priv->db[i].ptr,
-							MLX5_MAX_DB_SIZE, 7);
-		if (!priv->db[i].umem.umem) {
-			DRV_LOG(ERR, "Failed to register memory!");
-			ret = ENODEV;
-			goto tidyup_error;
-		}
-		/* Ensure set all DB memory to 0's before setting up DB. */
-		memset(priv->db[i].ptr, 0x00, MLX5_MAX_DB_SIZE);
-		/* No data currently in database. */
-		priv->db[i].len = 0;
-		priv->db[i].active = false;
-		priv->db[i].db_assigned_to_eng_num = MLX5_RXP_DB_NOT_ASSIGNED;
+	/* Register the memory. */
+	mkey->umem = mlx5_glue->devx_umem_reg(priv->ctx, ptr, size, access);
+	if (!mkey->umem) {
+		DRV_LOG(ERR, "Failed to register memory!");
+		return -ENODEV;
 	}
-	return 0;
-tidyup_error:
-	for (i = 0; i < (priv->nb_engines + MLX5_RXP_EM_COUNT); i++) {
-		if (priv->db[i].umem.umem)
-			mlx5_glue->devx_umem_dereg(priv->db[i].umem.umem);
-		rte_free(priv->db[i].ptr);
-		priv->db[i].ptr = NULL;
+	/* Create mkey */
+	mkey_attr = (struct mlx5_devx_mkey_attr) {
+		.addr = (uintptr_t)ptr,
+		.size = (uint32_t)size,
+		.umem_id = mlx5_os_get_umem_id(mkey->umem),
+		.pg_access = 1,
+		.umr_en = 0,
+	};
+#ifdef HAVE_IBV_FLOW_DV_SUPPORT
+	if (regex_get_pdn(priv->pd, &mkey_attr.pd) < 0) {
+		DRV_LOG(ERR, "Failed to get pdn!");
+		return -ENODEV;
+	}
+#endif
+	mkey->mkey = mlx5_devx_cmd_mkey_create(priv->ctx, &mkey_attr);
+	if (!mkey->mkey) {
+		DRV_LOG(ERR, "Failed to create direct mkey!");
+		return -ENODEV;
 	}
-	return -ret;
+	return 0;
+}
+
+static inline void
+rxp_destroy_mkey(struct mlx5_regex_mkey *mkey)
+{
+	if (mkey->mkey)
+		claim_zero(mlx5_devx_cmd_destroy(mkey->mkey));
+	if (mkey->umem)
+		claim_zero(mlx5_glue->devx_umem_dereg(mkey->umem));
 }
 
 int
@@ -89,6 +97,10 @@ mlx5_regex_rules_db_import(struct rte_regexdev *dev,
 		     const char *rule_db, uint32_t rule_db_len)
 {
 	struct mlx5_regex_priv *priv = dev->data->dev_private;
+	struct mlx5_regex_mkey mkey;
+	uint32_t id;
+	int ret;
+	void *ptr;
 
 	if (priv->prog_mode == MLX5_RXP_MODE_NOT_DEFINED) {
 		DRV_LOG(ERR, "RXP programming mode not set!");
@@ -100,8 +112,31 @@ mlx5_regex_rules_db_import(struct rte_regexdev *dev,
 	}
 	if (rule_db_len == 0)
 		return -EINVAL;
+	/* copy rules - rules have to be 4KB aligned. */
+	ptr = rte_malloc("", rule_db_len, 1 << 12);
+	if (!ptr) {
+		DRV_LOG(ERR, "Failed to allocate rules file memory.");
+		return -ENOMEM;
+	}
+	rte_memcpy(ptr, rule_db, rule_db_len);
+	/* Register umem and create rof mkey. */
+	ret = rxp_create_mkey(priv, ptr, rule_db_len, /*access=*/7, &mkey);
+	if (ret < 0)
+		return ret;
 
-	return 0;
+	for (id = 0; id < priv->nb_engines; id++) {
+		ret = mlx5_devx_regex_rules_program(priv->ctx, id,
+			mkey.mkey->id, rule_db_len, (uintptr_t)ptr);
+		if (ret < 0) {
+			DRV_LOG(ERR, "Failed to program rxp rules.");
+			ret = -ENODEV;
+			break;
+		}
+		ret = 0;
+	}
+	rxp_destroy_mkey(&mkey);
+	rte_free(ptr);
+	return ret;
 }
 
 int
@@ -123,12 +158,6 @@ mlx5_regex_configure(struct rte_regexdev *dev,
 		return -rte_errno;
 	}
 	priv->nb_max_matches = cfg->nb_max_matches;
-	/* Setup rxp db memories. */
-	if (rxp_db_setup(priv)) {
-		DRV_LOG(ERR, "Failed to setup RXP db memory");
-		rte_errno = ENOMEM;
-		return -rte_errno;
-	}
 	if (cfg->rule_db != NULL) {
 		ret = mlx5_regex_rules_db_import(dev, cfg->rule_db,
 						 cfg->rule_db_len);
diff --git a/drivers/regex/mlx5/mlx5_rxp.h b/drivers/regex/mlx5/mlx5_rxp.h
index 9686e24cdb..254e9cfa2b 100644
--- a/drivers/regex/mlx5/mlx5_rxp.h
+++ b/drivers/regex/mlx5/mlx5_rxp.h
@@ -129,9 +129,9 @@ enum mlx5_rxp_program_mode {
 #define MLX5_RXP_EM_COUNT 1u /* Extra External Memories to use. */
 #define MLX5_RXP_DB_NOT_ASSIGNED 0xFF
 
-struct mlx5_regex_umem {
+struct mlx5_regex_mkey {
 	struct mlx5dv_devx_umem *umem;
-	uint32_t id;
+	struct mlx5_devx_obj *mkey;
 	uint64_t offset;
 };
 
-- 
2.25.1


  parent reply	other threads:[~2021-10-22 15:48 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-22 15:45 [dpdk-dev] [PATCH 01/10] common/mlx5: update PRM definitions for regex availability Francis Kelly
2021-10-22 15:45 ` [dpdk-dev] [PATCH 02/10] regex/mlx5: add cleanup code Francis Kelly
2021-10-22 15:45 ` [dpdk-dev] [PATCH 03/10] common/mlx5: update regex DevX commands Francis Kelly
2021-10-24 13:39   ` Ori Kam
2021-10-22 15:45 ` [dpdk-dev] [PATCH 04/10] regex/mlx5: remove regexp register read/write Francis Kelly
2021-10-24 13:40   ` Ori Kam
2021-10-22 15:45 ` Francis Kelly [this message]
2021-10-24 13:41   ` [dpdk-dev] [PATCH 05/10] regex/mlx5: move RXP to CrSpace Ori Kam
2021-10-22 15:45 ` [dpdk-dev] [PATCH 06/10] regex/mlx5: remove start/stop engine API Francis Kelly
2021-10-22 15:45 ` [dpdk-dev] [PATCH 07/10] regex/mlx5: removed redundant rxp csr file Francis Kelly
2021-10-24 13:42   ` Ori Kam
2021-10-22 15:45 ` [dpdk-dev] [PATCH 08/10] regex/mlx5: fix uninitialized QP destroy Francis Kelly
2021-10-24 13:42   ` Ori Kam
2021-10-22 15:45 ` [dpdk-dev] [PATCH 09/10] regex/mlx5: prevent QP double setup Francis Kelly
2021-10-24 13:43   ` Ori Kam
2021-10-22 15:46 ` [dpdk-dev] [PATCH 10/10] doc: updated release notes and mlx5 file Francis Kelly
2021-10-24 13:43   ` Ori Kam
2021-11-03 22:13     ` Thomas Monjalon
2021-10-24 13:38 ` [dpdk-dev] [PATCH 01/10] common/mlx5: update PRM definitions for regex availability Ori Kam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211022154600.2180938-5-fkelly@nvidia.com \
    --to=fkelly@nvidia.com \
    --cc=aagbarih@nvidia.com \
    --cc=adypodoman@gmail.com \
    --cc=dev@dpdk.org \
    --cc=jamhunter@nvidia.com \
    --cc=orika@nvidia.com \
    --cc=tmonjalon@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).