DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bing Zhao <bingz@nvidia.com>
To: <orika@nvidia.com>, <aman.deep.singh@intel.com>,
	<dsosnowski@nvidia.com>,  <viacheslavo@nvidia.com>,
	<suanmingm@nvidia.com>, <matan@nvidia.com>, <thomas@monjalon.net>,
	<ferruh.yigit@amd.com>, <dev@dpdk.org>, <rasland@nvidia.com>
Cc: <yuying.zhang@intel.com>, <andrew.rybchenko@oktetlabs.ru>
Subject: [PATCH v4 3/5] net/mlx5: create NAT64 actions during configuration
Date: Wed, 28 Feb 2024 17:09:11 +0200	[thread overview]
Message-ID: <20240228150913.32603-4-bingz@nvidia.com> (raw)
In-Reply-To: <20240228150913.32603-1-bingz@nvidia.com>

The NAT64 DR actions can be shared among the tables. All these
actions can be created during configuring the flow queues and saved
for the future usage.

Even the actions can be shared now, inside per each flow rule, the
actual hardware resources are unique.

Signed-off-by: Bing Zhao <bingz@nvidia.com>
---
 doc/guides/nics/features/mlx5.ini      |  1 +
 doc/guides/nics/mlx5.rst               | 10 ++++
 doc/guides/rel_notes/release_24_03.rst |  7 +++
 drivers/net/mlx5/mlx5.h                |  9 ++++
 drivers/net/mlx5/mlx5_flow.h           | 11 +++++
 drivers/net/mlx5/mlx5_flow_dv.c        |  4 +-
 drivers/net/mlx5/mlx5_flow_hw.c        | 65 ++++++++++++++++++++++++++
 7 files changed, 106 insertions(+), 1 deletion(-)

diff --git a/doc/guides/nics/features/mlx5.ini b/doc/guides/nics/features/mlx5.ini
index 30027f2ba1..81a7067cc3 100644
--- a/doc/guides/nics/features/mlx5.ini
+++ b/doc/guides/nics/features/mlx5.ini
@@ -117,6 +117,7 @@ mark                 = Y
 meter                = Y
 meter_mark           = Y
 modify_field         = Y
+nat64                = Y
 nvgre_decap          = Y
 nvgre_encap          = Y
 of_pop_vlan          = Y
diff --git a/doc/guides/nics/mlx5.rst b/doc/guides/nics/mlx5.rst
index 329b98f68f..c0294f268d 100644
--- a/doc/guides/nics/mlx5.rst
+++ b/doc/guides/nics/mlx5.rst
@@ -168,6 +168,7 @@ Features
 - Sub-Function.
 - Matching on represented port.
 - Matching on aggregated affinity.
+- NAT64.
 
 
 Limitations
@@ -886,6 +887,15 @@ Limitations
   if preceding active application rules are still present and vice versa.
 
 
+- NAT64 action:
+  - Supported only with HW Steering enabled (``dv_flow_en`` = 2).
+  - FW version: at least ``XX.39.1002``.
+  - Supported only on non-root table.
+  - Actions order limitation should follow the modify fields action.
+  - The last 2 TAG registers will be used implicitly in address backup mode.
+  - Even if the action can be shared, new steering entries will be created per flow rule. It is recommended a single rule with NAT64 should be shared to reduce the duplication of entries. The default address and other fields covertion will be handled with NAT64 action. To support other address, new rule(s) with modify fields on the IP addresses should be created.
+  - TOS / Traffic Class is not supported now.
+
 Statistics
 ----------
 
diff --git a/doc/guides/rel_notes/release_24_03.rst b/doc/guides/rel_notes/release_24_03.rst
index 23ac6568ac..744f530ead 100644
--- a/doc/guides/rel_notes/release_24_03.rst
+++ b/doc/guides/rel_notes/release_24_03.rst
@@ -101,6 +101,11 @@ New Features
   * ``rte_flow_template_table_resize_complete()``.
     Complete table resize.
 
+* **Added a flow action type for NAT64.**
+
+  Added ``RTE_FLOW_ACTION_TYPE_NAT64`` to support offloading of header conversion
+  between IPv4 and IPv6.
+
 * **Updated Atomic Rules' Arkville driver.**
 
   * Added support for Atomic Rules' TK242 packet-capture family of devices
@@ -145,6 +150,8 @@ New Features
     to support TLS v1.2, TLS v1.3 and DTLS v1.2.
   * Added PMD API to allow raw submission of instructions to CPT.
 
+  * Added support for ``RTE_FLOW_ACTION_TYPE_NAT64`` flow action in HW Steering flow engine.
+
 
 Removed Items
 -------------
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index ee17a30454..c47712a146 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -1997,7 +1997,16 @@ struct mlx5_priv {
 	struct mlx5_aso_mtr_pool *hws_mpool; /* HW steering's Meter pool. */
 	struct mlx5_flow_hw_ctrl_rx *hw_ctrl_rx;
 	/**< HW steering templates used to create control flow rules. */
+
 	struct rte_flow_actions_template *action_template_drop[MLX5DR_TABLE_TYPE_MAX];
+
+	/*
+	 * The NAT64 action can be shared among matchers per domain.
+	 * [0]: RTE_FLOW_NAT64_6TO4, [1]: RTE_FLOW_NAT64_4TO6
+	 * Todo: consider to add *_MAX macro.
+	 */
+	struct mlx5dr_action *action_nat64[MLX5DR_TABLE_TYPE_MAX][2];
+
 #endif
 	struct rte_eth_dev *shared_host; /* Host device for HW steering. */
 	uint16_t shared_refcnt; /* HW steering host reference counter. */
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index 187f440893..897a283716 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -169,6 +169,17 @@ struct mlx5_rte_flow_item_sq {
 	uint32_t queue; /* DevX SQ number */
 };
 
+/* Map from registers to modify fields. */
+extern enum mlx5_modification_field reg_to_field[];
+extern const size_t mlx5_mod_reg_size;
+
+static __rte_always_inline enum mlx5_modification_field
+mlx5_convert_reg_to_field(enum modify_reg reg)
+{
+	MLX5_ASSERT((size_t)reg < mlx5_mod_reg_size);
+	return reg_to_field[reg];
+}
+
 /* Feature name to allocate metadata register. */
 enum mlx5_feature_name {
 	MLX5_HAIRPIN_RX,
diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index ddf19e9a51..18f09b22be 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -971,7 +971,7 @@ flow_dv_convert_action_modify_tcp_ack
 					     MLX5_MODIFICATION_TYPE_ADD, error);
 }
 
-static enum mlx5_modification_field reg_to_field[] = {
+enum mlx5_modification_field reg_to_field[] = {
 	[REG_NON] = MLX5_MODI_OUT_NONE,
 	[REG_A] = MLX5_MODI_META_DATA_REG_A,
 	[REG_B] = MLX5_MODI_META_DATA_REG_B,
@@ -989,6 +989,8 @@ static enum mlx5_modification_field reg_to_field[] = {
 	[REG_C_11] = MLX5_MODI_META_REG_C_11,
 };
 
+const size_t mlx5_mod_reg_size = RTE_DIM(reg_to_field);
+
 /**
  * Convert register set to DV specification.
  *
diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c
index 969f0dc85a..77f0aff91e 100644
--- a/drivers/net/mlx5/mlx5_flow_hw.c
+++ b/drivers/net/mlx5/mlx5_flow_hw.c
@@ -7832,6 +7832,66 @@ flow_hw_destroy_send_to_kernel_action(struct mlx5_priv *priv)
 	}
 }
 
+static void
+flow_hw_destroy_nat64_actions(struct mlx5_priv *priv)
+{
+	uint32_t i;
+
+	for (i = MLX5DR_TABLE_TYPE_NIC_RX; i < MLX5DR_TABLE_TYPE_MAX; i++) {
+		if (priv->action_nat64[i][RTE_FLOW_NAT64_6TO4]) {
+			(void)mlx5dr_action_destroy(priv->action_nat64[i][RTE_FLOW_NAT64_6TO4]);
+			priv->action_nat64[i][RTE_FLOW_NAT64_6TO4] = NULL;
+		}
+		if (priv->action_nat64[i][RTE_FLOW_NAT64_4TO6]) {
+			(void)mlx5dr_action_destroy(priv->action_nat64[i][RTE_FLOW_NAT64_4TO6]);
+			priv->action_nat64[i][RTE_FLOW_NAT64_4TO6] = NULL;
+		}
+	}
+}
+
+static int
+flow_hw_create_nat64_actions(struct mlx5_priv *priv, struct rte_flow_error *error)
+{
+	struct mlx5dr_action_nat64_attr attr;
+	uint8_t regs[MLX5_FLOW_NAT64_REGS_MAX];
+	uint32_t i;
+	const uint32_t flags[MLX5DR_TABLE_TYPE_MAX] = {
+		MLX5DR_ACTION_FLAG_HWS_RX | MLX5DR_ACTION_FLAG_SHARED,
+		MLX5DR_ACTION_FLAG_HWS_TX | MLX5DR_ACTION_FLAG_SHARED,
+		MLX5DR_ACTION_FLAG_HWS_FDB | MLX5DR_ACTION_FLAG_SHARED,
+	};
+	struct mlx5dr_action *act;
+
+	attr.registers = regs;
+	/* Try to use 3 registers by default. */
+	attr.num_of_registers = MLX5_FLOW_NAT64_REGS_MAX;
+	for (i = 0; i < MLX5_FLOW_NAT64_REGS_MAX; i++) {
+		MLX5_ASSERT(priv->sh->registers.nat64_regs[i] != REG_NON);
+		regs[i] = mlx5_convert_reg_to_field(priv->sh->registers.nat64_regs[i]);
+	}
+	for (i = MLX5DR_TABLE_TYPE_NIC_RX; i < MLX5DR_TABLE_TYPE_MAX; i++) {
+		if (i == MLX5DR_TABLE_TYPE_FDB && !priv->sh->config.dv_esw_en)
+			continue;
+		attr.flags = (enum mlx5dr_action_nat64_flags)
+			     (MLX5DR_ACTION_NAT64_V6_TO_V4 | MLX5DR_ACTION_NAT64_BACKUP_ADDR);
+		act = mlx5dr_action_create_nat64(priv->dr_ctx, &attr, flags[i]);
+		if (!act)
+			return rte_flow_error_set(error, rte_errno,
+						  RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+						  "Failed to create v6 to v4 action.");
+		priv->action_nat64[i][RTE_FLOW_NAT64_6TO4] = act;
+		attr.flags = (enum mlx5dr_action_nat64_flags)
+			     (MLX5DR_ACTION_NAT64_V4_TO_V6 | MLX5DR_ACTION_NAT64_BACKUP_ADDR);
+		act = mlx5dr_action_create_nat64(priv->dr_ctx, &attr, flags[i]);
+		if (!act)
+			return rte_flow_error_set(error, rte_errno,
+						  RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+						  "Failed to create v4 to v6 action.");
+		priv->action_nat64[i][RTE_FLOW_NAT64_4TO6] = act;
+	}
+	return 0;
+}
+
 /**
  * Create an egress pattern template matching on source SQ.
  *
@@ -10033,6 +10093,9 @@ flow_hw_configure(struct rte_eth_dev *dev,
 				   NULL, "Failed to VLAN actions.");
 		goto err;
 	}
+	if (flow_hw_create_nat64_actions(priv, error))
+		DRV_LOG(WARNING, "Cannot create NAT64 action on port %u, "
+			"please check the FW version", dev->data->port_id);
 	if (_queue_attr)
 		mlx5_free(_queue_attr);
 	if (port_attr->flags & RTE_FLOW_PORT_FLAG_STRICT_QUEUE)
@@ -10066,6 +10129,7 @@ flow_hw_configure(struct rte_eth_dev *dev,
 	}
 	if (priv->hw_def_miss)
 		mlx5dr_action_destroy(priv->hw_def_miss);
+	flow_hw_destroy_nat64_actions(priv);
 	flow_hw_destroy_vlan(dev);
 	if (dr_ctx)
 		claim_zero(mlx5dr_context_close(dr_ctx));
@@ -10147,6 +10211,7 @@ flow_hw_resource_release(struct rte_eth_dev *dev)
 	}
 	if (priv->hw_def_miss)
 		mlx5dr_action_destroy(priv->hw_def_miss);
+	flow_hw_destroy_nat64_actions(priv);
 	flow_hw_destroy_vlan(dev);
 	flow_hw_destroy_send_to_kernel_action(priv);
 	flow_hw_free_vport_actions(priv);
-- 
2.39.3


  parent reply	other threads:[~2024-02-28 15:11 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-27  9:07 [PATCH 0/8] support NAT64 action Bing Zhao
2023-12-27  9:07 ` [PATCH 1/8] ethdev: introduce " Bing Zhao
2023-12-27  9:07 ` [PATCH 2/8] app/testpmd: add support for NAT64 in the command line Bing Zhao
2023-12-27  9:07 ` [PATCH 3/8] net/mlx5: fetch the available registers for NAT64 Bing Zhao
2023-12-27  9:07 ` [PATCH 4/8] common/mlx5: add new modify field defininations Bing Zhao
2023-12-27  9:07 ` [PATCH 5/8] net/mlx5/hws: support NAT64 action Bing Zhao
2023-12-27  9:07 ` [PATCH 6/8] net/mlx5: create NAT64 actions during configuration Bing Zhao
2023-12-27  9:07 ` [PATCH 7/8] net/mlx5: add NAT64 action support in rule creation Bing Zhao
2023-12-27  9:07 ` [PATCH 8/8] net/mlx5: validate the actions combination with NAT64 Bing Zhao
2024-01-31  9:38 ` [PATCH v2 0/2] support NAT64 action Bing Zhao
2024-01-31  9:38   ` [PATCH v2 1/2] ethdev: introduce " Bing Zhao
2024-02-01  8:38     ` Ori Kam
2024-01-31  9:38   ` [PATCH v2 2/2] app/testpmd: add support for NAT64 in the command line Bing Zhao
2024-02-01  8:38     ` Ori Kam
2024-02-01 16:00   ` [PATCH v2 0/2] support NAT64 action Ferruh Yigit
2024-02-01 16:05     ` Ferruh Yigit
2024-02-20 14:10 ` [PATCH v2 0/5] NAT64 support in mlx5 PMD Bing Zhao
2024-02-20 14:10   ` [PATCH v2 1/5] net/mlx5/hws: support NAT64 action Bing Zhao
2024-02-20 14:10   ` [PATCH v2 2/5] net/mlx5: fetch the available registers for NAT64 Bing Zhao
2024-02-20 14:10   ` [PATCH v2 3/5] net/mlx5: create NAT64 actions during configuration Bing Zhao
2024-02-20 14:10   ` [PATCH v2 4/5] net/mlx5: add NAT64 action support in rule creation Bing Zhao
2024-02-20 14:10   ` [PATCH v2 5/5] net/mlx5: validate the actions combination with NAT64 Bing Zhao
2024-02-20 14:37 ` [PATCH v3 0/5] NAT64 support in mlx5 PMD Bing Zhao
2024-02-20 14:37   ` [PATCH v3 1/5] net/mlx5/hws: support NAT64 action Bing Zhao
2024-02-20 14:37   ` [PATCH v3 2/5] net/mlx5: fetch the available registers for NAT64 Bing Zhao
2024-02-20 14:37   ` [PATCH v3 3/5] net/mlx5: create NAT64 actions during configuration Bing Zhao
2024-02-20 14:37   ` [PATCH v3 4/5] net/mlx5: add NAT64 action support in rule creation Bing Zhao
2024-02-20 14:37   ` [PATCH v3 5/5] net/mlx5: validate the actions combination with NAT64 Bing Zhao
2024-02-21 13:14   ` [PATCH v3 0/5] NAT64 support in mlx5 PMD Ori Kam
2024-02-28 15:09 ` [PATCH v4 " Bing Zhao
2024-02-28 15:09   ` [PATCH v4 1/5] net/mlx5/hws: support NAT64 action Bing Zhao
2024-02-28 15:09   ` [PATCH v4 2/5] net/mlx5: fetch the available registers for NAT64 Bing Zhao
2024-02-28 15:09   ` Bing Zhao [this message]
2024-02-28 15:09   ` [PATCH v4 4/5] net/mlx5: add NAT64 action support in rule creation Bing Zhao
2024-02-28 15:09   ` [PATCH v4 5/5] net/mlx5: validate the actions combination with NAT64 Bing Zhao
2024-02-29 10:39   ` [PATCH v4 0/5] NAT64 support in mlx5 PMD Raslan Darawsheh

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=20240228150913.32603-4-bingz@nvidia.com \
    --to=bingz@nvidia.com \
    --cc=aman.deep.singh@intel.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=dsosnowski@nvidia.com \
    --cc=ferruh.yigit@amd.com \
    --cc=matan@nvidia.com \
    --cc=orika@nvidia.com \
    --cc=rasland@nvidia.com \
    --cc=suanmingm@nvidia.com \
    --cc=thomas@monjalon.net \
    --cc=viacheslavo@nvidia.com \
    --cc=yuying.zhang@intel.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).