Skip to contentSkip to conversation

support NAT64 action

PATCH Superseded Bing Zhao 4 participants 36 messages Dec 27, 2023 – Feb 29, 2024 Network drivers

lore
Share & tools
lore

Bing Zhao

author
#0 lore raw

cover support NAT64 action

This patchset introduce the NAT64 action support for rte_flow.

Bing Zhao (7):
ethdev: introduce NAT64 action
app/testpmd: add support for NAT64 in the command line net/mlx5: fetch the available registers for NAT64 common/mlx5: add new modify field defininations net/mlx5: create NAT64 actions during configuration net/mlx5: add NAT64 action support in rule creation net/mlx5: validate the actions combination with NAT64

Erez Shitrit (1):
net/mlx5/hws: support NAT64 action

 app/test-pmd/cmdline_flow.c                 |  23 ++
 doc/guides/nics/features/default.ini        |   1 +
 doc/guides/nics/features/mlx5.ini           |   1 +
 doc/guides/nics/mlx5.rst                    |   9 +-
 doc/guides/prog_guide/rte_flow.rst          |   8 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |   4 +
 drivers/common/mlx5/mlx5_prm.h              |   5 +
 drivers/net/mlx5/hws/mlx5dr.h               |  29 ++
 drivers/net/mlx5/hws/mlx5dr_action.c        | 437 +++++++++++++++++++-
 drivers/net/mlx5/hws/mlx5dr_action.h        |  35 ++
 drivers/net/mlx5/hws/mlx5dr_debug.c         |   1 +
 drivers/net/mlx5/mlx5.c                     |   9 +
 drivers/net/mlx5/mlx5.h                     |   8 +
 drivers/net/mlx5/mlx5_flow.h                |  12 +
 drivers/net/mlx5/mlx5_flow_dv.c             |   4 +-
 drivers/net/mlx5/mlx5_flow_hw.c             |  91 ++++
 lib/ethdev/rte_flow.c                       |   1 +
 lib/ethdev/rte_flow.h                       |  27 ++
 18 files changed, 702 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 1/8 ethdev: introduce NAT64 action

In order to support the communication between IPv4 and IPv6 nodes in the network, different technologies are used, like dual-stacks, tunneling and NAT64. In some IPv4-only clients, it is hard to deploy new software and(or) hardware to support IPv6 protocol.

NAT64 is a choice and it will also reduce the unnecessary overhead of the traffic in the network. The NAT64 gateways take the responsibility of the packet headers translation between the IPv6 clouds and IPv4-only clouds.

The commit introduce the NAT64 flow action to offload the software involvement to the hardware.

This action should support the offloading of the IP headers' translation. The following fields should be reset correctly in the translation.
- Version
- Traffic Class / TOS
- Flow Label (0 in v4)
- Payload Length / Total length
- Next Header
- Hop Limit / TTL

The PMD needs to support the basic conversion of the fields above, and the well-known prefix will be used when translating IPv4 address to IPv6 address. Another modify fields can be used after the NAT64 to support other modes with different prefix and offset.

The ICMP* and transport layers protocol is out of the scope of NAT64 rte_flow action.

Reference links:
- https://datatracker.ietf.org/doc/html/rfc6146
- https://datatracker.ietf.org/doc/html/rfc6052
- https://datatracker.ietf.org/doc/html/rfc6145

---
 doc/guides/nics/features/default.ini |  1 +
 doc/guides/prog_guide/rte_flow.rst   |  8 ++++++++
 lib/ethdev/rte_flow.c                |  1 +
 lib/ethdev/rte_flow.h                | 27 +++++++++++++++++++++++++++
 4 files changed, 37 insertions(+)
doc/guides/nics/features/default.ini +1 -0
index 806cb033ff..f8a47a055a 100644
@@ -170,6 +170,7 @@ mark                 =
 meter                =
 meter_mark           =
 modify_field         =
+nat64                =
 nvgre_decap          =
 nvgre_encap          =
 of_copy_ttl_in       =
doc/guides/prog_guide/rte_flow.rst +8 -0
index 627b845bfb..f87628e9dc 100644
@@ -3506,6 +3506,14 @@ The packets will be received by the kernel driver sharing the same device
 as the DPDK port on which this action is configured.
 
 
+Action: ``NAT64``
+^^^^^^^^^^^^^^^^^
+
+This action does the header translation between IPv4 and IPv6. Besides
+converting the IP addresses, other fields in the IP header are handled as
+well. The ``type`` field should be provided as defined in the
+``rte_flow_action_nat64`` when creating the action.
+
 Negative types
 ~~~~~~~~~~~~~~
 
lib/ethdev/rte_flow.c +1 -0
index 549e329558..502df3bfd1 100644
@@ -268,6 +268,7 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = {
 		       sizeof(struct rte_flow_action_indirect_list)),
 	MK_FLOW_ACTION(PROG,
 		       sizeof(struct rte_flow_action_prog)),
+	MK_FLOW_ACTION(NAT64, sizeof(struct rte_flow_action_nat64)),
 };
 
 int
lib/ethdev/rte_flow.h +27 -0
index affdc8121b..da2afaef83 100644
@@ -3022,6 +3022,13 @@ enum rte_flow_action_type {
 	 * @see struct rte_flow_action_prog.
 	 */
 	RTE_FLOW_ACTION_TYPE_PROG,
+
+	/**
+	 * Support the NAT64 translation.
+	 *
+	 * @see struct rte_flow_action_nat64
+	 */
+	RTE_FLOW_ACTION_TYPE_NAT64,
 };
 
 /**
@@ -4150,6 +4157,26 @@ rte_flow_dynf_metadata_set(struct rte_mbuf *m, uint32_t v)
 	*RTE_FLOW_DYNF_METADATA(m) = v;
 }
 
+/**
+ * NAT64 translation type for IP headers.
+ */
+enum rte_flow_nat64_type {
+	RTE_FLOW_NAT64_6TO4 = 0, /**< IPv6 to IPv4 headers translation. */
+	RTE_FLOW_NAT64_4TO6 = 1, /**< IPv4 to IPv6 headers translation. */
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_NAT64
+ *
+ * Specify the NAT64 translation type.
+ */
+struct rte_flow_action_nat64 {
+	enum rte_flow_nat64_type type;
+};
+
 /**
  * Definition of a single action.
  *
Signature · 1 line
2.25.1
author
#2 lore raw

PATCH 2/8 app/testpmd: add support for NAT64 in the command line

In reply to Bing Zhao

The type of NAT64 action will be parsed.

Usage example with template API:
...
flow actions_template 0 create ingress actions_template_id 1 \
template count / nat64 / jump / end mask count / nat64 / \
jump / end

  flow template_table 0 create group 1 priority 0 ingress table_id \
    0x1 rules_number 8 pattern_template 0 actions_template 1

flow queue 0 create 2 template_table 0x1 pattern_template 0 \
actions_template 0 postpone no pattern eth / end actions count / \
nat64 type 1 / jump group 2 / end
...

---
 app/test-pmd/cmdline_flow.c                 | 23 +++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  4 ++++
 2 files changed, 27 insertions(+)
app/test-pmd/cmdline_flow.c +23 -0
index ce71818705..6fb252d3d5 100644
@@ -728,6 +728,8 @@ enum index {
 	ACTION_IPV6_EXT_PUSH,
 	ACTION_IPV6_EXT_PUSH_INDEX,
 	ACTION_IPV6_EXT_PUSH_INDEX_VALUE,
+	ACTION_NAT64,
+	ACTION_NAT64_MODE,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -2193,6 +2195,7 @@ static const enum index next_action[] = {
 	ACTION_QUOTA_QU,
 	ACTION_IPV6_EXT_REMOVE,
 	ACTION_IPV6_EXT_PUSH,
+	ACTION_NAT64,
 	ZERO,
 };
 
@@ -2534,6 +2537,12 @@ static const enum index action_represented_port[] = {
 	ZERO,
 };
 
+static const enum index action_nat64[] = {
+	ACTION_NAT64_MODE,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static int parse_set_raw_encap_decap(struct context *, const struct token *,
 				     const char *, unsigned int,
 				     void *, unsigned int);
@@ -7022,6 +7031,20 @@ static const struct token token_list[] = {
 		.call = parse_vc_action_ipv6_ext_push_index,
 		.comp = comp_set_ipv6_ext_index,
 	},
+	[ACTION_NAT64] = {
+		.name = "nat64",
+		.help = "NAT64 IP headers translation",
+		.priv = PRIV_ACTION(NAT64, sizeof(struct rte_flow_action_nat64)),
+		.next = NEXT(action_nat64),
+		.call = parse_vc,
+	},
+	[ACTION_NAT64_MODE] = {
+		.name = "type",
+		.help = "NAT64 translation type",
+		.next = NEXT(action_nat64, NEXT_ENTRY(COMMON_UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_nat64, type)),
+		.call = parse_vc_conf,
+	},
 	/* Top level command. */
 	[SET] = {
 		.name = "set",
doc/guides/testpmd_app_ug/testpmd_funcs.rst +4 -0
index 447e28e694..01044043d0 100644
@@ -4151,6 +4151,10 @@ This section lists supported actions and their attributes, if any.
   - ``src_ptr``: pointer to source immediate value.
   - ``width``: number of bits to copy.
 
+- ``nat64``: NAT64 IP headers translation
+
+  - ``type {unsigned}``: NAT64 translation type
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
Signature · 1 line
2.25.1
author
#3 lore raw

PATCH 3/8 net/mlx5: fetch the available registers for NAT64

In reply to Bing Zhao

REG_C_6 is used as the 1st one and since it is reserved internally by default, there is no impact.

The remaining 2 registers will be fetched from the available TAGs array from right to left. They will not be masked in the array due to the fact that not all the rules will use NAT64 action.

---
 drivers/net/mlx5/mlx5.c | 9 +++++++++
 drivers/net/mlx5/mlx5.h | 2 ++
 2 files changed, 11 insertions(+)
drivers/net/mlx5/mlx5.c +9 -0
index 3a182de248..6f7b2aaa77 100644
@@ -1643,6 +1643,15 @@ mlx5_init_hws_flow_tags_registers(struct mlx5_dev_ctx_shared *sh)
 		if (!!((1 << i) & masks))
 			reg->hw_avl_tags[j++] = mlx5_regc_value(i);
 	}
+	/*
+	 * Set the registers for NAT64 usage internally. REG_C_6 is always used.
+	 * The other 2 registers will be fetched from right to left, at least 2
+	 * tag registers should be available.
+	 */
+	MLX5_ASSERT(j >= (MLX5_FLOW_NAT64_REGS_MAX - 1));
+	reg->nat64_regs[0] = REG_C_6;
+	reg->nat64_regs[1] = reg->hw_avl_tags[j - 2];
+	reg->nat64_regs[2] = reg->hw_avl_tags[j - 1];
 }
 
 static void
drivers/net/mlx5/mlx5.h +2 -0
index 263ebead7f..b73ab78870 100644
@@ -1407,10 +1407,12 @@ struct mlx5_hws_cnt_svc_mng {
 };
 
 #define MLX5_FLOW_HW_TAGS_MAX 12
+#define MLX5_FLOW_NAT64_REGS_MAX 3
 
 struct mlx5_dev_registers {
 	enum modify_reg aso_reg;
 	enum modify_reg hw_avl_tags[MLX5_FLOW_HW_TAGS_MAX];
+	enum modify_reg nat64_regs[MLX5_FLOW_NAT64_REGS_MAX];
 };
 
 #if defined(HAVE_MLX5DV_DR) && \
Signature · 1 line
2.25.1
author
#4 lore raw

PATCH 4/8 common/mlx5: add new modify field defininations

In reply to Bing Zhao

This commit adds TCP data offset, IPv4 total length, IPv4 IHL, IPv6 payload length in modify field operation.

Also redefine the out protocol(next header) for both IPv4 and IPv6.

---
 drivers/common/mlx5/mlx5_prm.h | 5 +++++
 1 file changed, 5 insertions(+)
drivers/common/mlx5/mlx5_prm.h +5 -0
index 9e22dce6da..2f009f81ea 100644
@@ -839,6 +839,7 @@ enum mlx5_modification_field {
 	MLX5_MODI_IN_MPLS_LABEL_2,
 	MLX5_MODI_IN_MPLS_LABEL_3,
 	MLX5_MODI_IN_MPLS_LABEL_4,
+	MLX5_MODI_OUT_IP_PROTOCOL = 0x4A,
 	MLX5_MODI_OUT_IPV6_NEXT_HDR = 0x4A,
 	MLX5_MODI_META_REG_C_8 = 0x8F,
 	MLX5_MODI_META_REG_C_9 = 0x90,
@@ -848,6 +849,10 @@ enum mlx5_modification_field {
 	MLX5_MODI_META_REG_C_13 = 0x94,
 	MLX5_MODI_META_REG_C_14 = 0x95,
 	MLX5_MODI_META_REG_C_15 = 0x96,
+	MLX5_MODI_OUT_IPV4_TOTAL_LEN = 0x11D,
+	MLX5_MODI_OUT_IPV6_PAYLOAD_LEN = 0x11E,
+	MLX5_MODI_OUT_IPV4_IHL = 0x11F,
+	MLX5_MODI_OUT_TCP_DATA_OFFSET = 0x120,
 	MLX5_MODI_INVALID = INT_MAX,
 };
 
Signature · 1 line
2.25.1
author
#5 lore raw

PATCH 5/8 net/mlx5/hws: support NAT64 action

In reply to Bing Zhao

From: Erez Shitrit <[email protected]>

Add support of new action mlx5dr_action_create_nat64.
The new action allows to modify IP packets from version to version, IPV6 to IPV4 and vice versa.

---
 drivers/net/mlx5/hws/mlx5dr.h        |  29 ++
 drivers/net/mlx5/hws/mlx5dr_action.c | 437 ++++++++++++++++++++++++++-
 drivers/net/mlx5/hws/mlx5dr_action.h |  35 +++
 drivers/net/mlx5/hws/mlx5dr_debug.c  |   1 +
 4 files changed, 501 insertions(+), 1 deletion(-)
drivers/net/mlx5/hws/mlx5dr.h +29 -0
index d88f73ab57..44fff5db25 100644
@@ -51,6 +51,7 @@ enum mlx5dr_action_type {
 	MLX5DR_ACTION_TYP_DEST_ARRAY,
 	MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT,
 	MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT,
+	MLX5DR_ACTION_TYP_NAT64,
 	MLX5DR_ACTION_TYP_MAX,
 };
 
@@ -796,6 +797,34 @@ mlx5dr_action_create_reformat_ipv6_ext(struct mlx5dr_context *ctx,
 				       uint32_t log_bulk_size,
 				       uint32_t flags);
 
+enum mlx5dr_action_nat64_flags {
+	MLX5DR_ACTION_NAT64_V4_TO_V6 = 1 << 0,
+	MLX5DR_ACTION_NAT64_V6_TO_V4 = 1 << 1,
+	/* Indicates if to backup ipv4 addresses in last two registers */
+	MLX5DR_ACTION_NAT64_BACKUP_ADDR = 1 << 2,
+};
+
+struct mlx5dr_action_nat64_attr {
+	uint8_t num_of_registers;
+	uint8_t *registers;
+	enum mlx5dr_action_nat64_flags flags;
+};
+
+/* Create direct rule nat64 action.
+ *
+ * @param[in] ctx
+ *	The context in which the new action will be created.
+ * @param[in] attr
+ * 	The relevant attiribute of the NAT action.
+  * @param[in] flags
+ *	Action creation flags. (enum mlx5dr_action_flags)
+ * @return pointer to mlx5dr_action on success NULL otherwise.
+ */
+struct mlx5dr_action *
+mlx5dr_action_create_nat64(struct mlx5dr_context *ctx,
+			   struct mlx5dr_action_nat64_attr *attr,
+			   uint32_t flags);
+
 /* Destroy direct rule action.
  *
  * @param[in] action
drivers/net/mlx5/hws/mlx5dr_action.c +436 -1

491 lines not on this page · raw message

drivers/net/mlx5/hws/mlx5dr_action.h +35 -0
index fad35a845b..49c2a9bc6b 100644
@@ -11,6 +11,9 @@
 /* Max number of internal subactions of ipv6_ext */
 #define MLX5DR_ACTION_IPV6_EXT_MAX_SA 4
 
+/* Number of MH in NAT64 */
+#define MLX5DR_ACTION_NAT64_STAGES 3
+
 enum mlx5dr_action_stc_idx {
 	MLX5DR_ACTION_STC_IDX_CTRL = 0,
 	MLX5DR_ACTION_STC_IDX_HIT = 1,
@@ -68,6 +71,34 @@ enum mlx5dr_action_stc_reparse {
 	MLX5DR_ACTION_STC_REPARSE_OFF,
 };
 
+ /* 2' comp to 20, to get -20 in add operation */
+#define MLX5DR_ACTION_NAT64_DEC_20 0xffffffec
+
+enum {
+	MLX5DR_ACTION_NAT64_MAX_MODIFY_ACTIONS = 20,
+	MLX5DR_ACTION_NAT64_ADD_20 = 20,
+	MLX5DR_ACTION_NAT64_HEADER_MINUS_ONE = 9,
+	MLX5DR_ACTION_NAT64_IPV6_HEADER = 10,
+	MLX5DR_ACTION_NAT64_IPV4_HEADER = 5,
+	MLX5DR_ACTION_NAT64_IPV6_VER = 0x60000000,
+	MLX5DR_ACTION_NAT64_IPV4_VER = 0x45000000,
+};
+
+/* 3 stages for the nat64 action */
+enum mlx5dr_action_nat64_stages {
+	MLX5DR_ACTION_NAT64_STAGE_COPY = 0,
+	MLX5DR_ACTION_NAT64_STAGE_REPLACE = 1,
+	MLX5DR_ACTION_NAT64_STAGE_COPYBACK = 2,
+};
+
+/* Registers for keeping data from stage to stage */
+enum {
+	MLX5DR_ACTION_NAT64_REG_CONTROL = 0,
+	MLX5DR_ACTION_NAT64_REG_SRC_IP = 1,
+	MLX5DR_ACTION_NAT64_REG_DST_IP = 2,
+	MLX5DR_ACTION_NAT64_REG_MAX = 3,
+};
+
 struct mlx5dr_action_default_stc {
 	struct mlx5dr_pool_chunk nop_ctr;
 	struct mlx5dr_pool_chunk nop_dw5;
@@ -109,6 +140,7 @@ struct mlx5dr_actions_wqe_setter {
 	uint8_t idx_double;
 	uint8_t idx_ctr;
 	uint8_t idx_hit;
+	uint8_t stage_idx;
 	uint8_t flags;
 	uint8_t extra_data;
 };
@@ -182,6 +214,9 @@ struct mlx5dr_action {
 					uint8_t num_of_words;
 					bool decap;
 				} remove_header;
+				struct {
+					struct mlx5dr_action *stages[MLX5DR_ACTION_NAT64_STAGES];
+				} nat64;
 			};
 		};
 
drivers/net/mlx5/hws/mlx5dr_debug.c +1 -0
index 11557bcab8..39e168d556 100644
@@ -28,6 +28,7 @@ const char *mlx5dr_debug_action_type_str[] = {
 	[MLX5DR_ACTION_TYP_REMOVE_HEADER] = "REMOVE_HEADER",
 	[MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT] = "POP_IPV6_ROUTE_EXT",
 	[MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT] = "PUSH_IPV6_ROUTE_EXT",
+	[MLX5DR_ACTION_TYP_NAT64] = "NAT64",
 };
 
 static_assert(ARRAY_SIZE(mlx5dr_debug_action_type_str) == MLX5DR_ACTION_TYP_MAX,
Signature · 1 line
2.25.1
author
#6 lore raw

PATCH 6/8 net/mlx5: create NAT64 actions during configuration

In reply to Bing Zhao

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.

---
 doc/guides/nics/features/mlx5.ini |  1 +
 doc/guides/nics/mlx5.rst          |  9 ++++-
 drivers/net/mlx5/mlx5.h           |  6 +++
 drivers/net/mlx5/mlx5_flow.h      | 11 ++++++
 drivers/net/mlx5/mlx5_flow_dv.c   |  4 +-
 drivers/net/mlx5/mlx5_flow_hw.c   | 65 +++++++++++++++++++++++++++++++
 6 files changed, 94 insertions(+), 2 deletions(-)
doc/guides/nics/features/mlx5.ini +1 -0
index 0739fe9d63..f074ff20db 100644
@@ -115,6 +115,7 @@ mark                 = Y
 meter                = Y
 meter_mark           = Y
 modify_field         = Y
+nat64                = Y
 nvgre_decap          = Y
 nvgre_encap          = Y
 of_pop_vlan          = Y
doc/guides/nics/mlx5.rst +8 -1
index 6b52fb93c5..920cd1e62f 100644
@@ -167,7 +167,7 @@ Features
 - Sub-Function.
 - Matching on represented port.
 - Matching on aggregated affinity.
-
+- NAT64.
 
 Limitations
 -----------
@@ -779,6 +779,13 @@ Limitations
   if preceding active application rules are still present and vice versa.
 
 
+- NAT64 action:
+  - Supported only with HW Steering enabled (``dv_flow_en`` = 2).
+  - 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.
+
 Statistics
 ----------
 
drivers/net/mlx5/mlx5.h +6 -0
index b73ab78870..860c77a4dd 100644
@@ -1967,6 +1967,12 @@ 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. */
+	/*
+	 * 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. */
drivers/net/mlx5/mlx5_flow.h +11 -0
index 6dde9de688..81026632ed 100644
@@ -159,6 +159,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_covert_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,
drivers/net/mlx5/mlx5_flow_dv.c +3 -1
index 115d730317..97915a54ef 100644
@@ -958,7 +958,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,
@@ -976,6 +976,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.
  *
drivers/net/mlx5/mlx5_flow_hw.c +65 -0

89 lines not on this page · raw message

Signature · 1 line
2.25.1
author
#7 lore raw

PATCH 7/8 net/mlx5: add NAT64 action support in rule creation

In reply to Bing Zhao

The action will handle the IPv4 and IPv6 headers translation. It will add / remove IPv6 address prefix by default.

To use the user specific address, another rule to modify the addresses of the IP header is needed.

---
 drivers/net/mlx5/mlx5_flow_hw.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/net/mlx5/mlx5_flow_hw.c +22 -0
index 9b9ad8de2d..9b60233549 100644
@@ -2479,6 +2479,19 @@ __flow_hw_actions_translate(struct rte_eth_dev *dev,
 			}
 			acts->rule_acts[dr_pos].action = priv->hw_def_miss;
 			break;
+		case RTE_FLOW_ACTION_TYPE_NAT64:
+			if (masks->conf &&
+			    ((const struct rte_flow_action_nat64 *)masks->conf)->type) {
+				const struct rte_flow_action_nat64 *nat64_c =
+					(const struct rte_flow_action_nat64 *)actions->conf;
+
+				acts->rule_acts[dr_pos].action =
+					priv->action_nat64[type][nat64_c->type];
+			} else if (__flow_hw_act_data_general_append(priv, acts,
+								     actions->type,
+								     src_pos, dr_pos))
+				goto err;
+			break;
 		case RTE_FLOW_ACTION_TYPE_END:
 			actions_end = true;
 			break;
@@ -2912,6 +2925,7 @@ flow_hw_actions_construct(struct rte_eth_dev *dev,
 	const struct rte_flow_action_ethdev *port_action = NULL;
 	const struct rte_flow_action_meter *meter = NULL;
 	const struct rte_flow_action_age *age = NULL;
+	const struct rte_flow_action_nat64 *nat64_c = NULL;
 	uint8_t *buf = job->encap_data;
 	uint8_t *push_buf = job->push_data;
 	struct rte_flow_attr attr = {
@@ -3179,6 +3193,13 @@ flow_hw_actions_construct(struct rte_eth_dev *dev,
 			if (ret != 0)
 				return ret;
 			break;
+		case RTE_FLOW_ACTION_TYPE_NAT64:
+			nat64_c = action->conf;
+			if (!priv->action_nat64[table->type][nat64_c->type])
+				return -1;
+			rule_acts[act_data->action_dst].action =
+				priv->action_nat64[table->type][nat64_c->type];
+			break;
 		default:
 			break;
 		}
@@ -5872,6 +5893,7 @@ static enum mlx5dr_action_type mlx5_hw_dr_action_types[] = {
 	[RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL] = MLX5DR_ACTION_TYP_DEST_ROOT,
 	[RTE_FLOW_ACTION_TYPE_IPV6_EXT_PUSH] = MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT,
 	[RTE_FLOW_ACTION_TYPE_IPV6_EXT_REMOVE] = MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT,
+	[RTE_FLOW_ACTION_TYPE_NAT64] = MLX5DR_ACTION_TYP_NAT64,
 };
 
 static inline void
Signature · 1 line
2.25.1
author
#8 lore raw

PATCH 8/8 net/mlx5: validate the actions combination with NAT64

In reply to Bing Zhao

NAT64 is treated as a modify header action. The action order and limitation should be the same as that of modify header in each domain.

Since the last 2 TAG registers will be used implicitly in the address backup mode, the values in these registers are no longer valid after the NAT64 action. The application should not try to match these TAGs after the rule that contains NAT64 action.

---
 drivers/net/mlx5/mlx5_flow.h    | 1 +
 drivers/net/mlx5/mlx5_flow_hw.c | 4 ++++
 2 files changed, 5 insertions(+)
drivers/net/mlx5/mlx5_flow.h +1 -0
index 81026632ed..6bdd350aef 100644
@@ -376,6 +376,7 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_PORT_REPRESENTOR (1ull << 47)
 #define MLX5_FLOW_ACTION_IPV6_ROUTING_REMOVE (1ull << 48)
 #define MLX5_FLOW_ACTION_IPV6_ROUTING_PUSH (1ull << 49)
+#define MLX5_FLOW_ACTION_NAT64 (1ull << 50)
 
 #define MLX5_FLOW_DROP_INCLUSIVE_ACTIONS \
 	(MLX5_FLOW_ACTION_COUNT | MLX5_FLOW_ACTION_SAMPLE | MLX5_FLOW_ACTION_AGE)
drivers/net/mlx5/mlx5_flow_hw.c +4 -0
index 9b60233549..09ae49faa4 100644
@@ -5841,6 +5841,10 @@ mlx5_flow_hw_actions_validate(struct rte_eth_dev *dev,
 				MLX5_HW_VLAN_PUSH_VID_IDX;
 			action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
 			break;
+		case RTE_FLOW_ACTION_TYPE_NAT64:
+			/* TODO: Validation logic */
+			action_flags |= MLX5_FLOW_ACTION_NAT64;
+			break;
 		case RTE_FLOW_ACTION_TYPE_END:
 			actions_end = true;
 			break;
Signature · 1 line
2.25.1
author
#9 lore raw

v2 cover support NAT64 action

In reply to Bing Zhao

This patchset introduce the NAT64 action support for rte_flow.

---
v2: split the common part and PMD part.
---

Bing Zhao (2):
ethdev: introduce NAT64 action
app/testpmd: add support for NAT64 in the command line

 app/test-pmd/cmdline_flow.c                 | 23 ++++++++++++++++++
 doc/guides/nics/features/default.ini        |  1 +
 doc/guides/prog_guide/rte_flow.rst          |  8 ++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  4 +++
 lib/ethdev/rte_flow.c                       |  1 +
 lib/ethdev/rte_flow.h                       | 27 +++++++++++++++++++++
 6 files changed, 64 insertions(+)
Signature · 1 line
2.34.1
author
#10 lore raw

PATCH v2 1/2 ethdev: introduce NAT64 action

In order to support the communication between IPv4 and IPv6 nodes in the network, different technologies are used, like dual-stacks, tunneling and NAT64. In some IPv4-only clients, it is hard to deploy new software and(or) hardware to support IPv6 protocol.

NAT64 is a choice and it will also reduce the unnecessary overhead of the traffic in the network. The NAT64 gateways take the responsibility of the packet headers translation between the IPv6 clouds and IPv4-only clouds.

The commit introduce the NAT64 flow action to offload the software involvement to the hardware.

This action should support the offloading of the IP headers' translation. The following fields should be reset correctly in the translation.
- Version
- Traffic Class / TOS
- Flow Label (0 in v4)
- Payload Length / Total length
- Next Header
- Hop Limit / TTL

The PMD needs to support the basic conversion of the fields above, and the well-known prefix will be used when translating IPv4 address to IPv6 address. Another modify fields can be used after the NAT64 to support other modes with different prefix and offset.

The ICMP* and transport layers protocol is out of the scope of NAT64 rte_flow action.

Reference links:
- https://datatracker.ietf.org/doc/html/rfc6146
- https://datatracker.ietf.org/doc/html/rfc6052
- https://datatracker.ietf.org/doc/html/rfc6145

---
 doc/guides/nics/features/default.ini |  1 +
 doc/guides/prog_guide/rte_flow.rst   |  8 ++++++++
 lib/ethdev/rte_flow.c                |  1 +
 lib/ethdev/rte_flow.h                | 27 +++++++++++++++++++++++++++
 4 files changed, 37 insertions(+)
doc/guides/nics/features/default.ini +1 -0
index 6d50236292..4db7e41193 100644
@@ -171,6 +171,7 @@ mark                 =
 meter                =
 meter_mark           =
 modify_field         =
+nat64                =
 nvgre_decap          =
 nvgre_encap          =
 of_copy_ttl_in       =
doc/guides/prog_guide/rte_flow.rst +8 -0
index 900fdaefb6..7af329bd93 100644
@@ -3520,6 +3520,14 @@ The packets will be received by the kernel driver sharing the same device
 as the DPDK port on which this action is configured.
 
 
+Action: ``NAT64``
+^^^^^^^^^^^^^^^^^
+
+This action does the header translation between IPv4 and IPv6. Besides
+converting the IP addresses, other fields in the IP header are handled as
+well. The ``type`` field should be provided as defined in the
+``rte_flow_action_nat64`` when creating the action.
+
 Negative types
 ~~~~~~~~~~~~~~
 
lib/ethdev/rte_flow.c +1 -0
index 3f58d792f9..156545454c 100644
@@ -271,6 +271,7 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = {
 		       sizeof(struct rte_flow_action_indirect_list)),
 	MK_FLOW_ACTION(PROG,
 		       sizeof(struct rte_flow_action_prog)),
+	MK_FLOW_ACTION(NAT64, sizeof(struct rte_flow_action_nat64)),
 };
 
 int
lib/ethdev/rte_flow.h +27 -0
index 1267c146e5..1dded812ec 100644
@@ -3051,6 +3051,13 @@ enum rte_flow_action_type {
 	 * @see struct rte_flow_action_prog.
 	 */
 	RTE_FLOW_ACTION_TYPE_PROG,
+
+	/**
+	 * Support the NAT64 translation.
+	 *
+	 * @see struct rte_flow_action_nat64
+	 */
+	RTE_FLOW_ACTION_TYPE_NAT64,
 };
 
 /**
@@ -4180,6 +4187,26 @@ rte_flow_dynf_metadata_set(struct rte_mbuf *m, uint32_t v)
 	*RTE_FLOW_DYNF_METADATA(m) = v;
 }
 
+/**
+ * NAT64 translation type for IP headers.
+ */
+enum rte_flow_nat64_type {
+	RTE_FLOW_NAT64_6TO4 = 0, /**< IPv6 to IPv4 headers translation. */
+	RTE_FLOW_NAT64_4TO6 = 1, /**< IPv4 to IPv6 headers translation. */
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_NAT64
+ *
+ * Specify the NAT64 translation type.
+ */
+struct rte_flow_action_nat64 {
+	enum rte_flow_nat64_type type;
+};
+
 /**
  * Definition of a single action.
  *
Signature · 1 line
2.34.1
Acked-by on v2 1/2
#11 lore raw

RE: [PATCH v2 1/2] ethdev: introduce NAT64 action

Hi Bing

Quoted 35 lines

-----Original Message-----
From: Bing Zhao <[email protected]>
Sent: Wednesday, January 31, 2024 11:38 AM

In order to support the communication between IPv4 and IPv6 nodes in the network, different technologies are used, like dual-stacks, tunneling and NAT64. In some IPv4-only clients, it is hard to deploy new software and(or) hardware to support IPv6 protocol.

NAT64 is a choice and it will also reduce the unnecessary overhead of the traffic in the network. The NAT64 gateways take the responsibility of the packet headers translation between the IPv6 clouds and IPv4-only clouds.

The commit introduce the NAT64 flow action to offload the software involvement to the hardware.

This action should support the offloading of the IP headers' translation. The following fields should be reset correctly in the translation.
- Version
- Traffic Class / TOS
- Flow Label (0 in v4)
- Payload Length / Total length
- Next Header
- Hop Limit / TTL

The PMD needs to support the basic conversion of the fields above, and the well-known prefix will be used when translating IPv4 address to IPv6 address. Another modify fields can be used after the NAT64 to support other modes with different prefix and offset.

The ICMP* and transport layers protocol is out of the scope of NAT64 rte_flow action.

Quoted 7 lines

Reference links:
- https://datatracker.ietf.org/doc/html/rfc6146
- https://datatracker.ietf.org/doc/html/rfc6052
- https://datatracker.ietf.org/doc/html/rfc6145

---

Best,
Ori

author
#12 lore raw

PATCH v2 2/2 app/testpmd: add support for NAT64 in the command line

In reply to Bing Zhao

The type of NAT64 action will be parsed.

Usage example with template API:
...
flow actions_template 0 create ingress actions_template_id 1 \
template count / nat64 / jump / end mask count / nat64 / \
jump / end

  flow template_table 0 create group 1 priority 0 ingress table_id \
    0x1 rules_number 8 pattern_template 0 actions_template 1

flow queue 0 create 2 template_table 0x1 pattern_template 0 \
actions_template 0 postpone no pattern eth / end actions count / \
nat64 type 1 / jump group 2 / end
...

---
 app/test-pmd/cmdline_flow.c                 | 23 +++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  4 ++++
 2 files changed, 27 insertions(+)
app/test-pmd/cmdline_flow.c +23 -0
index 4062879552..d26986a9ab 100644
@@ -733,6 +733,8 @@ enum index {
 	ACTION_IPV6_EXT_PUSH,
 	ACTION_IPV6_EXT_PUSH_INDEX,
 	ACTION_IPV6_EXT_PUSH_INDEX_VALUE,
+	ACTION_NAT64,
+	ACTION_NAT64_MODE,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -2209,6 +2211,7 @@ static const enum index next_action[] = {
 	ACTION_QUOTA_QU,
 	ACTION_IPV6_EXT_REMOVE,
 	ACTION_IPV6_EXT_PUSH,
+	ACTION_NAT64,
 	ZERO,
 };
 
@@ -2550,6 +2553,12 @@ static const enum index action_represented_port[] = {
 	ZERO,
 };
 
+static const enum index action_nat64[] = {
+	ACTION_NAT64_MODE,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static int parse_set_raw_encap_decap(struct context *, const struct token *,
 				     const char *, unsigned int,
 				     void *, unsigned int);
@@ -7077,6 +7086,20 @@ static const struct token token_list[] = {
 		.call = parse_vc_action_ipv6_ext_push_index,
 		.comp = comp_set_ipv6_ext_index,
 	},
+	[ACTION_NAT64] = {
+		.name = "nat64",
+		.help = "NAT64 IP headers translation",
+		.priv = PRIV_ACTION(NAT64, sizeof(struct rte_flow_action_nat64)),
+		.next = NEXT(action_nat64),
+		.call = parse_vc,
+	},
+	[ACTION_NAT64_MODE] = {
+		.name = "type",
+		.help = "NAT64 translation type",
+		.next = NEXT(action_nat64, NEXT_ENTRY(COMMON_UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_nat64, type)),
+		.call = parse_vc_conf,
+	},
 	/* Top level command. */
 	[SET] = {
 		.name = "set",
doc/guides/testpmd_app_ug/testpmd_funcs.rst +4 -0
index 38ab421547..d1801c1b26 100644
@@ -4169,6 +4169,10 @@ This section lists supported actions and their attributes, if any.
   - ``src_ptr``: pointer to source immediate value.
   - ``width``: number of bits to copy.
 
+- ``nat64``: NAT64 IP headers translation
+
+  - ``type {unsigned}``: NAT64 translation type
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
Signature · 1 line
2.34.1
Acked-by on v2 2/2
#13 lore raw

RE: [PATCH v2 2/2] app/testpmd: add support for NAT64 in the command line

Quoted 103 lines

-----Original Message-----
From: Bing Zhao <[email protected]>
Sent: Wednesday, January 31, 2024 11:38 AM

The type of NAT64 action will be parsed.

Usage example with template API:
...
flow actions_template 0 create ingress actions_template_id 1 \
template count / nat64 / jump / end mask count / nat64 / \
jump / end

  flow template_table 0 create group 1 priority 0 ingress table_id \
    0x1 rules_number 8 pattern_template 0 actions_template 1

flow queue 0 create 2 template_table 0x1 pattern_template 0 \
actions_template 0 postpone no pattern eth / end actions count / \
nat64 type 1 / jump group 2 / end
...

---
 app/test-pmd/cmdline_flow.c                 | 23 +++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  4 ++++
 2 files changed, 27 insertions(+)
app/test-pmd/cmdline_flow.c +9 -0
index 4062879552..d26986a9ab 100644
@@ -733,6 +733,8 @@ enum index {
 	ACTION_IPV6_EXT_PUSH,
 	ACTION_IPV6_EXT_PUSH_INDEX,
 	ACTION_IPV6_EXT_PUSH_INDEX_VALUE,
+	ACTION_NAT64,
+	ACTION_NAT64_MODE,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -2209,6 +2211,7 @@ static const enum index next_action[] = {
 	ACTION_QUOTA_QU,
 	ACTION_IPV6_EXT_REMOVE,
 	ACTION_IPV6_EXT_PUSH,
+	ACTION_NAT64,
 	ZERO,
 };
 
@@ -2550,6 +2553,12 @@ static const enum index
 action_represented_port[] = {
 	ZERO,
 };
 
+static const enum index action_nat64[] = {
+	ACTION_NAT64_MODE,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static int parse_set_raw_encap_decap(struct context *, const struct token *,
 				     const char *, unsigned int,
app/test-pmd/cmdline_flow.c +14 -0
 				     void *, unsigned int);
@@ -7077,6 +7086,20 @@ static const struct token token_list[] = {
 		.call = parse_vc_action_ipv6_ext_push_index,
 		.comp = comp_set_ipv6_ext_index,
 	},
+	[ACTION_NAT64] = {
+		.name = "nat64",
+		.help = "NAT64 IP headers translation",
+		.priv = PRIV_ACTION(NAT64, sizeof(struct
 rte_flow_action_nat64)),
+		.next = NEXT(action_nat64),
+		.call = parse_vc,
+	},
+	[ACTION_NAT64_MODE] = {
+		.name = "type",
+		.help = "NAT64 translation type",
+		.next = NEXT(action_nat64,
 NEXT_ENTRY(COMMON_UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_nat64,
 type)),
+		.call = parse_vc_conf,
+	},
app/test-pmd/cmdline_flow.c +0 -0
 	/* Top level command. */
 	[SET] = {
 		.name = "set",
doc/guides/testpmd_app_ug/testpmd_funcs.rst +0 -0
index 38ab421547..d1801c1b26 100644
@@ -4169,6 +4169,10 @@ This section lists supported actions and their

attributes, if any.
- ``src_ptr``: pointer to source immediate value.
- ``width``: number of bits to copy.

+- ``nat64``: NAT64 IP headers translation

doc/guides/testpmd_app_ug/testpmd_funcs.rst +3 -1
+
+  - ``type {unsigned}``: NAT64 translation type
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
--
Quoted 1 line

2.34.1

Best,
Ori

Applied
#14 lore raw
In reply to Bing Zhao
Quoted 2 lines · Bing Zhao

This patchset introduce the NAT64 action support for rte_flow.

Applied, thanks!

[1/2] ethdev: introduce NAT64 action

      commit: 8d06f5a2da9991ebd514869a72f5136e0ee1eaf1
[2/2] app/testpmd: add support for NAT64 in the command line
      commit: 1d14e0581427004de88ac95e25529761f4492621

Best regards,

Signature · 1 line
Ferruh Yigit <[email protected]>
#15 lore raw
Quoted 5 lines · Ferruh Yigit
Quoted 2 lines · Bing Zhao

This patchset introduce the NAT64 action support for rte_flow.

Quoted 9 lines

Applied, thanks!

[1/2] ethdev: introduce NAT64 action

      commit: 8d06f5a2da9991ebd514869a72f5136e0ee1eaf1
[2/2] app/testpmd: add support for NAT64 in the command line
      commit: 1d14e0581427004de88ac95e25529761f4492621

Best regards,

Hi sub-tree maintainers,

I sent above applied message from console using "b4 ty" tool [1], in case it helps you, FYI.

[1]
https://www.mankier.com/5/b4#Subcommand_Options-b4_ty

author
#16 lore raw

v2 cover NAT64 support in mlx5 PMD

In reply to Bing Zhao

This patch set contains the mlx5 PMD implementation for NAT64.

Update in v2:
1. separate from the RTE and testpmd common part.
2. reorder the commits.
3. bug fix, code polishing and document update.

Bing Zhao (4):
net/mlx5: fetch the available registers for NAT64 net/mlx5: create NAT64 actions during configuration net/mlx5: add NAT64 action support in rule creation net/mlx5: validate the actions combination with NAT64

Erez Shitrit (1):
net/mlx5/hws: support NAT64 action

 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/hws/mlx5dr.h          |  29 ++
 drivers/net/mlx5/hws/mlx5dr_action.c   | 437 ++++++++++++++++++++++++-
 drivers/net/mlx5/hws/mlx5dr_action.h   |  35 ++
 drivers/net/mlx5/hws/mlx5dr_debug.c    |   1 +
 drivers/net/mlx5/mlx5.c                |   9 +
 drivers/net/mlx5/mlx5.h                |   8 +
 drivers/net/mlx5/mlx5_flow.h           |  12 +
 drivers/net/mlx5/mlx5_flow_dv.c        |   4 +-
 drivers/net/mlx5/mlx5_flow_hw.c        | 136 ++++++++
 12 files changed, 687 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
author
#17 lore raw

PATCH v2 1/5 net/mlx5/hws: support NAT64 action

From: Erez Shitrit <[email protected]>

Add support of new action mlx5dr_action_create_nat64.
The new action allows to modify IP packets from version to version, IPV6 to IPV4 and vice versa.

---
 drivers/net/mlx5/hws/mlx5dr.h        |  29 ++
 drivers/net/mlx5/hws/mlx5dr_action.c | 437 ++++++++++++++++++++++++++-
 drivers/net/mlx5/hws/mlx5dr_action.h |  35 +++
 drivers/net/mlx5/hws/mlx5dr_debug.c  |   1 +
 4 files changed, 501 insertions(+), 1 deletion(-)
drivers/net/mlx5/hws/mlx5dr.h +29 -0
index 9c5b068c93..9ee6503439 100644
@@ -51,6 +51,7 @@ enum mlx5dr_action_type {
 	MLX5DR_ACTION_TYP_DEST_ARRAY,
 	MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT,
 	MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT,
+	MLX5DR_ACTION_TYP_NAT64,
 	MLX5DR_ACTION_TYP_MAX,
 };
 
@@ -817,6 +818,34 @@ mlx5dr_action_create_reformat_ipv6_ext(struct mlx5dr_context *ctx,
 				       uint32_t log_bulk_size,
 				       uint32_t flags);
 
+enum mlx5dr_action_nat64_flags {
+	MLX5DR_ACTION_NAT64_V4_TO_V6 = 1 << 0,
+	MLX5DR_ACTION_NAT64_V6_TO_V4 = 1 << 1,
+	/* Indicates if to backup ipv4 addresses in last two registers */
+	MLX5DR_ACTION_NAT64_BACKUP_ADDR = 1 << 2,
+};
+
+struct mlx5dr_action_nat64_attr {
+	uint8_t num_of_registers;
+	uint8_t *registers;
+	enum mlx5dr_action_nat64_flags flags;
+};
+
+/* Create direct rule nat64 action.
+ *
+ * @param[in] ctx
+ *	The context in which the new action will be created.
+ * @param[in] attr
+ * 	The relevant attiribute of the NAT action.
+  * @param[in] flags
+ *	Action creation flags. (enum mlx5dr_action_flags)
+ * @return pointer to mlx5dr_action on success NULL otherwise.
+ */
+struct mlx5dr_action *
+mlx5dr_action_create_nat64(struct mlx5dr_context *ctx,
+			   struct mlx5dr_action_nat64_attr *attr,
+			   uint32_t flags);
+
 /* Destroy direct rule action.
  *
  * @param[in] action
drivers/net/mlx5/hws/mlx5dr_action.c +436 -1

491 lines not on this page · raw message

drivers/net/mlx5/hws/mlx5dr_action.h +35 -0
index fad35a845b..49c2a9bc6b 100644
@@ -11,6 +11,9 @@
 /* Max number of internal subactions of ipv6_ext */
 #define MLX5DR_ACTION_IPV6_EXT_MAX_SA 4
 
+/* Number of MH in NAT64 */
+#define MLX5DR_ACTION_NAT64_STAGES 3
+
 enum mlx5dr_action_stc_idx {
 	MLX5DR_ACTION_STC_IDX_CTRL = 0,
 	MLX5DR_ACTION_STC_IDX_HIT = 1,
@@ -68,6 +71,34 @@ enum mlx5dr_action_stc_reparse {
 	MLX5DR_ACTION_STC_REPARSE_OFF,
 };
 
+ /* 2' comp to 20, to get -20 in add operation */
+#define MLX5DR_ACTION_NAT64_DEC_20 0xffffffec
+
+enum {
+	MLX5DR_ACTION_NAT64_MAX_MODIFY_ACTIONS = 20,
+	MLX5DR_ACTION_NAT64_ADD_20 = 20,
+	MLX5DR_ACTION_NAT64_HEADER_MINUS_ONE = 9,
+	MLX5DR_ACTION_NAT64_IPV6_HEADER = 10,
+	MLX5DR_ACTION_NAT64_IPV4_HEADER = 5,
+	MLX5DR_ACTION_NAT64_IPV6_VER = 0x60000000,
+	MLX5DR_ACTION_NAT64_IPV4_VER = 0x45000000,
+};
+
+/* 3 stages for the nat64 action */
+enum mlx5dr_action_nat64_stages {
+	MLX5DR_ACTION_NAT64_STAGE_COPY = 0,
+	MLX5DR_ACTION_NAT64_STAGE_REPLACE = 1,
+	MLX5DR_ACTION_NAT64_STAGE_COPYBACK = 2,
+};
+
+/* Registers for keeping data from stage to stage */
+enum {
+	MLX5DR_ACTION_NAT64_REG_CONTROL = 0,
+	MLX5DR_ACTION_NAT64_REG_SRC_IP = 1,
+	MLX5DR_ACTION_NAT64_REG_DST_IP = 2,
+	MLX5DR_ACTION_NAT64_REG_MAX = 3,
+};
+
 struct mlx5dr_action_default_stc {
 	struct mlx5dr_pool_chunk nop_ctr;
 	struct mlx5dr_pool_chunk nop_dw5;
@@ -109,6 +140,7 @@ struct mlx5dr_actions_wqe_setter {
 	uint8_t idx_double;
 	uint8_t idx_ctr;
 	uint8_t idx_hit;
+	uint8_t stage_idx;
 	uint8_t flags;
 	uint8_t extra_data;
 };
@@ -182,6 +214,9 @@ struct mlx5dr_action {
 					uint8_t num_of_words;
 					bool decap;
 				} remove_header;
+				struct {
+					struct mlx5dr_action *stages[MLX5DR_ACTION_NAT64_STAGES];
+				} nat64;
 			};
 		};
 
drivers/net/mlx5/hws/mlx5dr_debug.c +1 -0
index 11557bcab8..39e168d556 100644
@@ -28,6 +28,7 @@ const char *mlx5dr_debug_action_type_str[] = {
 	[MLX5DR_ACTION_TYP_REMOVE_HEADER] = "REMOVE_HEADER",
 	[MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT] = "POP_IPV6_ROUTE_EXT",
 	[MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT] = "PUSH_IPV6_ROUTE_EXT",
+	[MLX5DR_ACTION_TYP_NAT64] = "NAT64",
 };
 
 static_assert(ARRAY_SIZE(mlx5dr_debug_action_type_str) == MLX5DR_ACTION_TYP_MAX,
Signature · 1 line
2.34.1
author
#18 lore raw

PATCH v2 2/5 net/mlx5: fetch the available registers for NAT64

In reply to Bing Zhao

REG_C_6 is used as the 1st one and since it is reserved internally by default, there is no impact.

The remaining 2 registers will be fetched from the available TAGs array from right to left. They will not be masked in the array due to the fact that not all the rules will use NAT64 action.

---
 drivers/net/mlx5/mlx5.c | 9 +++++++++
 drivers/net/mlx5/mlx5.h | 2 ++
 2 files changed, 11 insertions(+)
drivers/net/mlx5/mlx5.c +9 -0
index 881c42a97a..9c3b9946e3 100644
@@ -1644,6 +1644,15 @@ mlx5_init_hws_flow_tags_registers(struct mlx5_dev_ctx_shared *sh)
 		if (!!((1 << i) & masks))
 			reg->hw_avl_tags[j++] = mlx5_regc_value(i);
 	}
+	/*
+	 * Set the registers for NAT64 usage internally. REG_C_6 is always used.
+	 * The other 2 registers will be fetched from right to left, at least 2
+	 * tag registers should be available.
+	 */
+	MLX5_ASSERT(j >= (MLX5_FLOW_NAT64_REGS_MAX - 1));
+	reg->nat64_regs[0] = REG_C_6;
+	reg->nat64_regs[1] = reg->hw_avl_tags[j - 2];
+	reg->nat64_regs[2] = reg->hw_avl_tags[j - 1];
 }
 
 static void
drivers/net/mlx5/mlx5.h +2 -0
index 5265d1aa1f..544cf35069 100644
@@ -1407,10 +1407,12 @@ struct mlx5_hws_cnt_svc_mng {
 };
 
 #define MLX5_FLOW_HW_TAGS_MAX 12
+#define MLX5_FLOW_NAT64_REGS_MAX 3
 
 struct mlx5_dev_registers {
 	enum modify_reg aso_reg;
 	enum modify_reg hw_avl_tags[MLX5_FLOW_HW_TAGS_MAX];
+	enum modify_reg nat64_regs[MLX5_FLOW_NAT64_REGS_MAX];
 };
 
 #if defined(HAVE_MLX5DV_DR) && \
Signature · 1 line
2.34.1
author
#19 lore raw

PATCH v2 3/5 net/mlx5: create NAT64 actions during configuration

In reply to Bing Zhao

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.

---
 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                |  6 +++
 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, 103 insertions(+), 1 deletion(-)
doc/guides/nics/features/mlx5.ini +1 -0
index 30027f2ba1..81a7067cc3 100644
@@ -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
doc/guides/nics/mlx5.rst +10 -0
index fa013b03bb..248e4e41fa 100644
@@ -168,6 +168,7 @@ Features
 - Matching on represented port.
 - Matching on aggregated affinity.
 - Matching on random value.
+- NAT64.
 
 
 Limitations
@@ -824,6 +825,15 @@ Limitations
   - Only match with compare result between packet fields is supported.
 
 
+- 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
 ----------
 
doc/guides/rel_notes/release_24_03.rst +7 -0
index 619459baae..492c77ff4f 100644
@@ -102,6 +102,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 PMD.**
 
   * Added support for Atomic Rules' TK242 packet-capture family of devices
@@ -133,6 +138,8 @@ New Features
   * Added HW steering support for modify field ``RTE_FLOW_FIELD_ESP_SEQ_NUM`` flow action.
   * Added HW steering support for modify field ``RTE_FLOW_FIELD_ESP_PROTO`` flow action.
 
+  * Added support for ``RTE_FLOW_ACTION_TYPE_NAT64`` flow action in HW Steering flow engine.
+
 
 Removed Items
 -------------
drivers/net/mlx5/mlx5.h +6 -0
index 544cf35069..1ad40e38e1 100644
@@ -1986,6 +1986,12 @@ 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. */
+	/*
+	 * 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. */
drivers/net/mlx5/mlx5_flow.h +11 -0
index a4d0ff7b13..da13f1f210 100644
@@ -159,6 +159,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_covert_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,
drivers/net/mlx5/mlx5_flow_dv.c +3 -1
index 6fded15d91..17c405508d 100644
@@ -968,7 +968,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,
@@ -986,6 +986,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.
  *
drivers/net/mlx5/mlx5_flow_hw.c +65 -0

89 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#20 lore raw

PATCH v2 4/5 net/mlx5: add NAT64 action support in rule creation

In reply to Bing Zhao

The action will handle the IPv4 and IPv6 headers translation. It will add / remove IPv6 address prefix by default.

To use the user specific address, another rule to modify the addresses of the IP header is needed.

---
 drivers/net/mlx5/mlx5_flow_hw.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/mlx5/mlx5_flow_hw.c +20 -0
index f53df40041..abe7159ad1 100644
@@ -2492,6 +2492,19 @@ __flow_hw_actions_translate(struct rte_eth_dev *dev,
 			}
 			acts->rule_acts[dr_pos].action = priv->hw_def_miss;
 			break;
+		case RTE_FLOW_ACTION_TYPE_NAT64:
+			if (masks->conf &&
+			    ((const struct rte_flow_action_nat64 *)masks->conf)->type) {
+				const struct rte_flow_action_nat64 *nat64_c =
+					(const struct rte_flow_action_nat64 *)actions->conf;
+
+				acts->rule_acts[dr_pos].action =
+					priv->action_nat64[type][nat64_c->type];
+			} else if (__flow_hw_act_data_general_append(priv, acts,
+								     actions->type,
+								     src_pos, dr_pos))
+				goto err;
+			break;
 		case RTE_FLOW_ACTION_TYPE_END:
 			actions_end = true;
 			break;
@@ -2934,6 +2947,7 @@ flow_hw_actions_construct(struct rte_eth_dev *dev,
 	const struct rte_flow_action_ethdev *port_action = NULL;
 	const struct rte_flow_action_meter *meter = NULL;
 	const struct rte_flow_action_age *age = NULL;
+	const struct rte_flow_action_nat64 *nat64_c = NULL;
 	uint8_t *buf = job->encap_data;
 	uint8_t *push_buf = job->push_data;
 	struct rte_flow_attr attr = {
@@ -3201,6 +3215,11 @@ flow_hw_actions_construct(struct rte_eth_dev *dev,
 			if (ret != 0)
 				return ret;
 			break;
+		case RTE_FLOW_ACTION_TYPE_NAT64:
+			nat64_c = action->conf;
+			rule_acts[act_data->action_dst].action =
+				priv->action_nat64[table->type][nat64_c->type];
+			break;
 		default:
 			break;
 		}
@@ -5959,6 +5978,7 @@ static enum mlx5dr_action_type mlx5_hw_dr_action_types[] = {
 	[RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL] = MLX5DR_ACTION_TYP_DEST_ROOT,
 	[RTE_FLOW_ACTION_TYPE_IPV6_EXT_PUSH] = MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT,
 	[RTE_FLOW_ACTION_TYPE_IPV6_EXT_REMOVE] = MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT,
+	[RTE_FLOW_ACTION_TYPE_NAT64] = MLX5DR_ACTION_TYP_NAT64,
 };
 
 static inline void
Signature · 1 line
2.34.1
author
#21 lore raw

PATCH v2 5/5 net/mlx5: validate the actions combination with NAT64

In reply to Bing Zhao

NAT64 is treated as a modify header action. The action order and limitation should be the same as that of modify header in each domain.

Since the last 2 TAG registers will be used implicitly in the address backup mode, the values in these registers are no longer valid after the NAT64 action. The application should not try to match these TAGs after the rule that contains NAT64 action.

---
 drivers/net/mlx5/mlx5_flow.h    |  1 +
 drivers/net/mlx5/mlx5_flow_hw.c | 51 +++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)
drivers/net/mlx5/mlx5_flow.h +1 -0
index da13f1f210..c3e053d730 100644
@@ -382,6 +382,7 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_PORT_REPRESENTOR (1ull << 47)
 #define MLX5_FLOW_ACTION_IPV6_ROUTING_REMOVE (1ull << 48)
 #define MLX5_FLOW_ACTION_IPV6_ROUTING_PUSH (1ull << 49)
+#define MLX5_FLOW_ACTION_NAT64 (1ull << 50)
 
 #define MLX5_FLOW_DROP_INCLUSIVE_ACTIONS \
 	(MLX5_FLOW_ACTION_COUNT | MLX5_FLOW_ACTION_SAMPLE | MLX5_FLOW_ACTION_AGE)
drivers/net/mlx5/mlx5_flow_hw.c +51 -0

63 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#22 lore raw

v3 cover NAT64 support in mlx5 PMD

In reply to Bing Zhao

This patch set contains the mlx5 PMD implementation for NAT64.

Update in v3:
1. code style and typo.

Update in v2:
1. separate from the RTE and testpmd common part.
2. reorder the commits.
3. bug fix, code polishing and document update.

Bing Zhao (4):
net/mlx5: fetch the available registers for NAT64 net/mlx5: create NAT64 actions during configuration net/mlx5: add NAT64 action support in rule creation net/mlx5: validate the actions combination with NAT64

Erez Shitrit (1):
net/mlx5/hws: support NAT64 action

 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/hws/mlx5dr.h          |  29 ++
 drivers/net/mlx5/hws/mlx5dr_action.c   | 436 ++++++++++++++++++++++++-
 drivers/net/mlx5/hws/mlx5dr_action.h   |  35 ++
 drivers/net/mlx5/hws/mlx5dr_debug.c    |   1 +
 drivers/net/mlx5/mlx5.c                |   9 +
 drivers/net/mlx5/mlx5.h                |   8 +
 drivers/net/mlx5/mlx5_flow.h           |  12 +
 drivers/net/mlx5/mlx5_flow_dv.c        |   4 +-
 drivers/net/mlx5/mlx5_flow_hw.c        | 136 ++++++++
 12 files changed, 686 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
author
#23 lore raw

PATCH v3 1/5 net/mlx5/hws: support NAT64 action

From: Erez Shitrit <[email protected]>

Add support of new action mlx5dr_action_create_nat64.
The new action allows to modify IP packets from version to version, IPV6 to IPV4 and vice versa.

---
 drivers/net/mlx5/hws/mlx5dr.h        |  29 ++
 drivers/net/mlx5/hws/mlx5dr_action.c | 436 ++++++++++++++++++++++++++-
 drivers/net/mlx5/hws/mlx5dr_action.h |  35 +++
 drivers/net/mlx5/hws/mlx5dr_debug.c  |   1 +
 4 files changed, 500 insertions(+), 1 deletion(-)
drivers/net/mlx5/hws/mlx5dr.h +29 -0
index 9c5b068c93..557fc1eef5 100644
@@ -51,6 +51,7 @@ enum mlx5dr_action_type {
 	MLX5DR_ACTION_TYP_DEST_ARRAY,
 	MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT,
 	MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT,
+	MLX5DR_ACTION_TYP_NAT64,
 	MLX5DR_ACTION_TYP_MAX,
 };
 
@@ -817,6 +818,34 @@ mlx5dr_action_create_reformat_ipv6_ext(struct mlx5dr_context *ctx,
 				       uint32_t log_bulk_size,
 				       uint32_t flags);
 
+enum mlx5dr_action_nat64_flags {
+	MLX5DR_ACTION_NAT64_V4_TO_V6 = 1 << 0,
+	MLX5DR_ACTION_NAT64_V6_TO_V4 = 1 << 1,
+	/* Indicates if to backup ipv4 addresses in last two registers */
+	MLX5DR_ACTION_NAT64_BACKUP_ADDR = 1 << 2,
+};
+
+struct mlx5dr_action_nat64_attr {
+	uint8_t num_of_registers;
+	uint8_t *registers;
+	enum mlx5dr_action_nat64_flags flags;
+};
+
+/* Create direct rule nat64 action.
+ *
+ * @param[in] ctx
+ *	The context in which the new action will be created.
+ * @param[in] attr
+ *	The relevant attribute of the NAT action.
+ * @param[in] flags
+ *	Action creation flags. (enum mlx5dr_action_flags)
+ * @return pointer to mlx5dr_action on success NULL otherwise.
+ */
+struct mlx5dr_action *
+mlx5dr_action_create_nat64(struct mlx5dr_context *ctx,
+			   struct mlx5dr_action_nat64_attr *attr,
+			   uint32_t flags);
+
 /* Destroy direct rule action.
  *
  * @param[in] action
drivers/net/mlx5/hws/mlx5dr_action.c +435 -1

490 lines not on this page · raw message

drivers/net/mlx5/hws/mlx5dr_action.h +35 -0
index fad35a845b..49c2a9bc6b 100644
@@ -11,6 +11,9 @@
 /* Max number of internal subactions of ipv6_ext */
 #define MLX5DR_ACTION_IPV6_EXT_MAX_SA 4
 
+/* Number of MH in NAT64 */
+#define MLX5DR_ACTION_NAT64_STAGES 3
+
 enum mlx5dr_action_stc_idx {
 	MLX5DR_ACTION_STC_IDX_CTRL = 0,
 	MLX5DR_ACTION_STC_IDX_HIT = 1,
@@ -68,6 +71,34 @@ enum mlx5dr_action_stc_reparse {
 	MLX5DR_ACTION_STC_REPARSE_OFF,
 };
 
+ /* 2' comp to 20, to get -20 in add operation */
+#define MLX5DR_ACTION_NAT64_DEC_20 0xffffffec
+
+enum {
+	MLX5DR_ACTION_NAT64_MAX_MODIFY_ACTIONS = 20,
+	MLX5DR_ACTION_NAT64_ADD_20 = 20,
+	MLX5DR_ACTION_NAT64_HEADER_MINUS_ONE = 9,
+	MLX5DR_ACTION_NAT64_IPV6_HEADER = 10,
+	MLX5DR_ACTION_NAT64_IPV4_HEADER = 5,
+	MLX5DR_ACTION_NAT64_IPV6_VER = 0x60000000,
+	MLX5DR_ACTION_NAT64_IPV4_VER = 0x45000000,
+};
+
+/* 3 stages for the nat64 action */
+enum mlx5dr_action_nat64_stages {
+	MLX5DR_ACTION_NAT64_STAGE_COPY = 0,
+	MLX5DR_ACTION_NAT64_STAGE_REPLACE = 1,
+	MLX5DR_ACTION_NAT64_STAGE_COPYBACK = 2,
+};
+
+/* Registers for keeping data from stage to stage */
+enum {
+	MLX5DR_ACTION_NAT64_REG_CONTROL = 0,
+	MLX5DR_ACTION_NAT64_REG_SRC_IP = 1,
+	MLX5DR_ACTION_NAT64_REG_DST_IP = 2,
+	MLX5DR_ACTION_NAT64_REG_MAX = 3,
+};
+
 struct mlx5dr_action_default_stc {
 	struct mlx5dr_pool_chunk nop_ctr;
 	struct mlx5dr_pool_chunk nop_dw5;
@@ -109,6 +140,7 @@ struct mlx5dr_actions_wqe_setter {
 	uint8_t idx_double;
 	uint8_t idx_ctr;
 	uint8_t idx_hit;
+	uint8_t stage_idx;
 	uint8_t flags;
 	uint8_t extra_data;
 };
@@ -182,6 +214,9 @@ struct mlx5dr_action {
 					uint8_t num_of_words;
 					bool decap;
 				} remove_header;
+				struct {
+					struct mlx5dr_action *stages[MLX5DR_ACTION_NAT64_STAGES];
+				} nat64;
 			};
 		};
 
drivers/net/mlx5/hws/mlx5dr_debug.c +1 -0
index 11557bcab8..39e168d556 100644
@@ -28,6 +28,7 @@ const char *mlx5dr_debug_action_type_str[] = {
 	[MLX5DR_ACTION_TYP_REMOVE_HEADER] = "REMOVE_HEADER",
 	[MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT] = "POP_IPV6_ROUTE_EXT",
 	[MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT] = "PUSH_IPV6_ROUTE_EXT",
+	[MLX5DR_ACTION_TYP_NAT64] = "NAT64",
 };
 
 static_assert(ARRAY_SIZE(mlx5dr_debug_action_type_str) == MLX5DR_ACTION_TYP_MAX,
Signature · 1 line
2.34.1
author
#24 lore raw

PATCH v3 2/5 net/mlx5: fetch the available registers for NAT64

In reply to Bing Zhao

REG_C_6 is used as the 1st one and since it is reserved internally by default, there is no impact.

The remaining 2 registers will be fetched from the available TAGs array from right to left. They will not be masked in the array due to the fact that not all the rules will use NAT64 action.

---
 drivers/net/mlx5/mlx5.c | 9 +++++++++
 drivers/net/mlx5/mlx5.h | 2 ++
 2 files changed, 11 insertions(+)
drivers/net/mlx5/mlx5.c +9 -0
index 881c42a97a..9c3b9946e3 100644
@@ -1644,6 +1644,15 @@ mlx5_init_hws_flow_tags_registers(struct mlx5_dev_ctx_shared *sh)
 		if (!!((1 << i) & masks))
 			reg->hw_avl_tags[j++] = mlx5_regc_value(i);
 	}
+	/*
+	 * Set the registers for NAT64 usage internally. REG_C_6 is always used.
+	 * The other 2 registers will be fetched from right to left, at least 2
+	 * tag registers should be available.
+	 */
+	MLX5_ASSERT(j >= (MLX5_FLOW_NAT64_REGS_MAX - 1));
+	reg->nat64_regs[0] = REG_C_6;
+	reg->nat64_regs[1] = reg->hw_avl_tags[j - 2];
+	reg->nat64_regs[2] = reg->hw_avl_tags[j - 1];
 }
 
 static void
drivers/net/mlx5/mlx5.h +2 -0
index 5265d1aa1f..544cf35069 100644
@@ -1407,10 +1407,12 @@ struct mlx5_hws_cnt_svc_mng {
 };
 
 #define MLX5_FLOW_HW_TAGS_MAX 12
+#define MLX5_FLOW_NAT64_REGS_MAX 3
 
 struct mlx5_dev_registers {
 	enum modify_reg aso_reg;
 	enum modify_reg hw_avl_tags[MLX5_FLOW_HW_TAGS_MAX];
+	enum modify_reg nat64_regs[MLX5_FLOW_NAT64_REGS_MAX];
 };
 
 #if defined(HAVE_MLX5DV_DR) && \
Signature · 1 line
2.34.1
author
#25 lore raw

PATCH v3 3/5 net/mlx5: create NAT64 actions during configuration

In reply to Bing Zhao

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.

---
 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                |  6 +++
 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, 103 insertions(+), 1 deletion(-)
doc/guides/nics/features/mlx5.ini +1 -0
index 30027f2ba1..81a7067cc3 100644
@@ -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
doc/guides/nics/mlx5.rst +10 -0
index fa013b03bb..248e4e41fa 100644
@@ -168,6 +168,7 @@ Features
 - Matching on represented port.
 - Matching on aggregated affinity.
 - Matching on random value.
+- NAT64.
 
 
 Limitations
@@ -824,6 +825,15 @@ Limitations
   - Only match with compare result between packet fields is supported.
 
 
+- 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
 ----------
 
doc/guides/rel_notes/release_24_03.rst +7 -0
index 619459baae..492c77ff4f 100644
@@ -102,6 +102,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 PMD.**
 
   * Added support for Atomic Rules' TK242 packet-capture family of devices
@@ -133,6 +138,8 @@ New Features
   * Added HW steering support for modify field ``RTE_FLOW_FIELD_ESP_SEQ_NUM`` flow action.
   * Added HW steering support for modify field ``RTE_FLOW_FIELD_ESP_PROTO`` flow action.
 
+  * Added support for ``RTE_FLOW_ACTION_TYPE_NAT64`` flow action in HW Steering flow engine.
+
 
 Removed Items
 -------------
drivers/net/mlx5/mlx5.h +6 -0
index 544cf35069..1ad40e38e1 100644
@@ -1986,6 +1986,12 @@ 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. */
+	/*
+	 * 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. */
drivers/net/mlx5/mlx5_flow.h +11 -0
index a4d0ff7b13..af41fd2112 100644
@@ -159,6 +159,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,
drivers/net/mlx5/mlx5_flow_dv.c +3 -1
index 6fded15d91..17c405508d 100644
@@ -968,7 +968,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,
@@ -986,6 +986,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.
  *
drivers/net/mlx5/mlx5_flow_hw.c +65 -0

89 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#26 lore raw

PATCH v3 4/5 net/mlx5: add NAT64 action support in rule creation

In reply to Bing Zhao

The action will handle the IPv4 and IPv6 headers translation. It will add / remove IPv6 address prefix by default.

To use the user specific address, another rule to modify the addresses of the IP header is needed.

---
 drivers/net/mlx5/mlx5_flow_hw.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/mlx5/mlx5_flow_hw.c +20 -0
index 386f6d1ae1..a2e2c6769a 100644
@@ -2492,6 +2492,19 @@ __flow_hw_actions_translate(struct rte_eth_dev *dev,
 			}
 			acts->rule_acts[dr_pos].action = priv->hw_def_miss;
 			break;
+		case RTE_FLOW_ACTION_TYPE_NAT64:
+			if (masks->conf &&
+			    ((const struct rte_flow_action_nat64 *)masks->conf)->type) {
+				const struct rte_flow_action_nat64 *nat64_c =
+					(const struct rte_flow_action_nat64 *)actions->conf;
+
+				acts->rule_acts[dr_pos].action =
+					priv->action_nat64[type][nat64_c->type];
+			} else if (__flow_hw_act_data_general_append(priv, acts,
+								     actions->type,
+								     src_pos, dr_pos))
+				goto err;
+			break;
 		case RTE_FLOW_ACTION_TYPE_END:
 			actions_end = true;
 			break;
@@ -2934,6 +2947,7 @@ flow_hw_actions_construct(struct rte_eth_dev *dev,
 	const struct rte_flow_action_ethdev *port_action = NULL;
 	const struct rte_flow_action_meter *meter = NULL;
 	const struct rte_flow_action_age *age = NULL;
+	const struct rte_flow_action_nat64 *nat64_c = NULL;
 	uint8_t *buf = job->encap_data;
 	uint8_t *push_buf = job->push_data;
 	struct rte_flow_attr attr = {
@@ -3201,6 +3215,11 @@ flow_hw_actions_construct(struct rte_eth_dev *dev,
 			if (ret != 0)
 				return ret;
 			break;
+		case RTE_FLOW_ACTION_TYPE_NAT64:
+			nat64_c = action->conf;
+			rule_acts[act_data->action_dst].action =
+				priv->action_nat64[table->type][nat64_c->type];
+			break;
 		default:
 			break;
 		}
@@ -5959,6 +5978,7 @@ static enum mlx5dr_action_type mlx5_hw_dr_action_types[] = {
 	[RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL] = MLX5DR_ACTION_TYP_DEST_ROOT,
 	[RTE_FLOW_ACTION_TYPE_IPV6_EXT_PUSH] = MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT,
 	[RTE_FLOW_ACTION_TYPE_IPV6_EXT_REMOVE] = MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT,
+	[RTE_FLOW_ACTION_TYPE_NAT64] = MLX5DR_ACTION_TYP_NAT64,
 };
 
 static inline void
Signature · 1 line
2.34.1
author
#27 lore raw

PATCH v3 5/5 net/mlx5: validate the actions combination with NAT64

In reply to Bing Zhao

NAT64 is treated as a modify header action. The action order and limitation should be the same as that of modify header in each domain.

Since the last 2 TAG registers will be used implicitly in the address backup mode, the values in these registers are no longer valid after the NAT64 action. The application should not try to match these TAGs after the rule that contains NAT64 action.

---
 drivers/net/mlx5/mlx5_flow.h    |  1 +
 drivers/net/mlx5/mlx5_flow_hw.c | 51 +++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)
drivers/net/mlx5/mlx5_flow.h +1 -0
index af41fd2112..52994fa3ee 100644
@@ -382,6 +382,7 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_PORT_REPRESENTOR (1ull << 47)
 #define MLX5_FLOW_ACTION_IPV6_ROUTING_REMOVE (1ull << 48)
 #define MLX5_FLOW_ACTION_IPV6_ROUTING_PUSH (1ull << 49)
+#define MLX5_FLOW_ACTION_NAT64 (1ull << 50)
 
 #define MLX5_FLOW_DROP_INCLUSIVE_ACTIONS \
 	(MLX5_FLOW_ACTION_COUNT | MLX5_FLOW_ACTION_SAMPLE | MLX5_FLOW_ACTION_AGE)
drivers/net/mlx5/mlx5_flow_hw.c +51 -0

63 lines not on this page · raw message

Signature · 1 line
2.34.1
#28 lore raw

RE: [PATCH v3 0/5] NAT64 support in mlx5 PMD

In reply to Bing Zhao
Quoted 39 lines

-----Original Message-----
From: Bing Zhao <[email protected]>
Sent: Tuesday, February 20, 2024 4:37 PM

This patch set contains the mlx5 PMD implementation for NAT64.

Update in v3:
1. code style and typo.

Update in v2:
1. separate from the RTE and testpmd common part.
2. reorder the commits.
3. bug fix, code polishing and document update.

Bing Zhao (4):
net/mlx5: fetch the available registers for NAT64 net/mlx5: create NAT64 actions during configuration net/mlx5: add NAT64 action support in rule creation net/mlx5: validate the actions combination with NAT64

Erez Shitrit (1):
net/mlx5/hws: support NAT64 action

 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/hws/mlx5dr.h          |  29 ++
 drivers/net/mlx5/hws/mlx5dr_action.c   | 436 ++++++++++++++++++++++++-
 drivers/net/mlx5/hws/mlx5dr_action.h   |  35 ++
 drivers/net/mlx5/hws/mlx5dr_debug.c    |   1 +
 drivers/net/mlx5/mlx5.c                |   9 +
 drivers/net/mlx5/mlx5.h                |   8 +
 drivers/net/mlx5/mlx5_flow.h           |  12 +
 drivers/net/mlx5/mlx5_flow_dv.c        |   4 +-
 drivers/net/mlx5/mlx5_flow_hw.c        | 136 ++++++++
 12 files changed, 686 insertions(+), 2 deletions(-)
Quoted 2 lines

--
2.34.1

Best,
Ori

author
#29 lore raw

v4 cover NAT64 support in mlx5 PMD

In reply to Bing Zhao

This patch set contains the mlx5 PMD implementation for NAT64.

Update in v4:
1. rebase to solve the conflicts.
2. fix the old NIC startup issue in a separate patch:

     https://patches.dpdk.org/project/dpdk/patch/[email protected]/

Update in v3:
1. code style and typo.

Update in v2:
1. separate from the RTE and testpmd common part.
2. reorder the commits.
3. bug fix, code polishing and document update.

Bing Zhao (4):
net/mlx5: fetch the available registers for NAT64 net/mlx5: create NAT64 actions during configuration net/mlx5: add NAT64 action support in rule creation net/mlx5: validate the actions combination with NAT64

Erez Shitrit (1):
net/mlx5/hws: support NAT64 action

 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/hws/mlx5dr.h          |  29 ++
 drivers/net/mlx5/hws/mlx5dr_action.c   | 436 ++++++++++++++++++++++++-
 drivers/net/mlx5/hws/mlx5dr_action.h   |  35 ++
 drivers/net/mlx5/hws/mlx5dr_debug.c    |   1 +
 drivers/net/mlx5/mlx5.c                |   9 +
 drivers/net/mlx5/mlx5.h                |  11 +
 drivers/net/mlx5/mlx5_flow.h           |  12 +
 drivers/net/mlx5/mlx5_flow_dv.c        |   4 +-
 drivers/net/mlx5/mlx5_flow_hw.c        | 136 ++++++++
 12 files changed, 689 insertions(+), 2 deletions(-)
Signature · 1 line
2.39.3
author
#30 lore raw

PATCH v4 1/5 net/mlx5/hws: support NAT64 action

From: Erez Shitrit <[email protected]>

Add support of new action mlx5dr_action_create_nat64.
The new action allows to modify IP packets from version to version, IPV6 to IPV4 and vice versa.

---
 drivers/net/mlx5/hws/mlx5dr.h        |  29 ++
 drivers/net/mlx5/hws/mlx5dr_action.c | 436 ++++++++++++++++++++++++++-
 drivers/net/mlx5/hws/mlx5dr_action.h |  35 +++
 drivers/net/mlx5/hws/mlx5dr_debug.c  |   1 +
 4 files changed, 500 insertions(+), 1 deletion(-)
drivers/net/mlx5/hws/mlx5dr.h +29 -0
index d612f300c6..8441ae97e9 100644
@@ -51,6 +51,7 @@ enum mlx5dr_action_type {
 	MLX5DR_ACTION_TYP_DEST_ARRAY,
 	MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT,
 	MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT,
+	MLX5DR_ACTION_TYP_NAT64,
 	MLX5DR_ACTION_TYP_MAX,
 };
 
@@ -868,6 +869,34 @@ mlx5dr_action_create_reformat_ipv6_ext(struct mlx5dr_context *ctx,
 				       uint32_t log_bulk_size,
 				       uint32_t flags);
 
+enum mlx5dr_action_nat64_flags {
+	MLX5DR_ACTION_NAT64_V4_TO_V6 = 1 << 0,
+	MLX5DR_ACTION_NAT64_V6_TO_V4 = 1 << 1,
+	/* Indicates if to backup ipv4 addresses in last two registers */
+	MLX5DR_ACTION_NAT64_BACKUP_ADDR = 1 << 2,
+};
+
+struct mlx5dr_action_nat64_attr {
+	uint8_t num_of_registers;
+	uint8_t *registers;
+	enum mlx5dr_action_nat64_flags flags;
+};
+
+/* Create direct rule nat64 action.
+ *
+ * @param[in] ctx
+ *	The context in which the new action will be created.
+ * @param[in] attr
+ *	The relevant attribute of the NAT action.
+ * @param[in] flags
+ *	Action creation flags. (enum mlx5dr_action_flags)
+ * @return pointer to mlx5dr_action on success NULL otherwise.
+ */
+struct mlx5dr_action *
+mlx5dr_action_create_nat64(struct mlx5dr_context *ctx,
+			   struct mlx5dr_action_nat64_attr *attr,
+			   uint32_t flags);
+
 /* Destroy direct rule action.
  *
  * @param[in] action
drivers/net/mlx5/hws/mlx5dr_action.c +435 -1

490 lines not on this page · raw message

drivers/net/mlx5/hws/mlx5dr_action.h +35 -0
index 0c8e4bbb5a..064c18a90c 100644
@@ -11,6 +11,9 @@
 /* Max number of internal subactions of ipv6_ext */
 #define MLX5DR_ACTION_IPV6_EXT_MAX_SA 4
 
+/* Number of MH in NAT64 */
+#define MLX5DR_ACTION_NAT64_STAGES 3
+
 enum mlx5dr_action_stc_idx {
 	MLX5DR_ACTION_STC_IDX_CTRL = 0,
 	MLX5DR_ACTION_STC_IDX_HIT = 1,
@@ -68,6 +71,34 @@ enum mlx5dr_action_stc_reparse {
 	MLX5DR_ACTION_STC_REPARSE_OFF,
 };
 
+ /* 2' comp to 20, to get -20 in add operation */
+#define MLX5DR_ACTION_NAT64_DEC_20 0xffffffec
+
+enum {
+	MLX5DR_ACTION_NAT64_MAX_MODIFY_ACTIONS = 20,
+	MLX5DR_ACTION_NAT64_ADD_20 = 20,
+	MLX5DR_ACTION_NAT64_HEADER_MINUS_ONE = 9,
+	MLX5DR_ACTION_NAT64_IPV6_HEADER = 10,
+	MLX5DR_ACTION_NAT64_IPV4_HEADER = 5,
+	MLX5DR_ACTION_NAT64_IPV6_VER = 0x60000000,
+	MLX5DR_ACTION_NAT64_IPV4_VER = 0x45000000,
+};
+
+/* 3 stages for the nat64 action */
+enum mlx5dr_action_nat64_stages {
+	MLX5DR_ACTION_NAT64_STAGE_COPY = 0,
+	MLX5DR_ACTION_NAT64_STAGE_REPLACE = 1,
+	MLX5DR_ACTION_NAT64_STAGE_COPYBACK = 2,
+};
+
+/* Registers for keeping data from stage to stage */
+enum {
+	MLX5DR_ACTION_NAT64_REG_CONTROL = 0,
+	MLX5DR_ACTION_NAT64_REG_SRC_IP = 1,
+	MLX5DR_ACTION_NAT64_REG_DST_IP = 2,
+	MLX5DR_ACTION_NAT64_REG_MAX = 3,
+};
+
 struct mlx5dr_action_default_stc {
 	struct mlx5dr_pool_chunk nop_ctr;
 	struct mlx5dr_pool_chunk nop_dw5;
@@ -109,6 +140,7 @@ struct mlx5dr_actions_wqe_setter {
 	uint8_t idx_double;
 	uint8_t idx_ctr;
 	uint8_t idx_hit;
+	uint8_t stage_idx;
 	uint8_t flags;
 	uint8_t extra_data;
 };
@@ -184,6 +216,9 @@ struct mlx5dr_action {
 					uint8_t num_of_words;
 					bool decap;
 				} remove_header;
+				struct {
+					struct mlx5dr_action *stages[MLX5DR_ACTION_NAT64_STAGES];
+				} nat64;
 			};
 		};
 
drivers/net/mlx5/hws/mlx5dr_debug.c +1 -0
index a9094cd35b..8f07c7fd66 100644
@@ -28,6 +28,7 @@ const char *mlx5dr_debug_action_type_str[] = {
 	[MLX5DR_ACTION_TYP_REMOVE_HEADER] = "REMOVE_HEADER",
 	[MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT] = "POP_IPV6_ROUTE_EXT",
 	[MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT] = "PUSH_IPV6_ROUTE_EXT",
+	[MLX5DR_ACTION_TYP_NAT64] = "NAT64",
 };
 
 static_assert(ARRAY_SIZE(mlx5dr_debug_action_type_str) == MLX5DR_ACTION_TYP_MAX,
Signature · 1 line
2.39.3
author
#31 lore raw

PATCH v4 2/5 net/mlx5: fetch the available registers for NAT64

In reply to Bing Zhao

REG_C_6 is used as the 1st one and since it is reserved internally by default, there is no impact.

The remaining 2 registers will be fetched from the available TAGs array from right to left. They will not be masked in the array due to the fact that not all the rules will use NAT64 action.

---
 drivers/net/mlx5/mlx5.c | 9 +++++++++
 drivers/net/mlx5/mlx5.h | 2 ++
 2 files changed, 11 insertions(+)
drivers/net/mlx5/mlx5.c +9 -0
index f2ca0ae4c2..cc7cd6adf5 100644
@@ -1644,6 +1644,15 @@ mlx5_init_hws_flow_tags_registers(struct mlx5_dev_ctx_shared *sh)
 		if (!!((1 << i) & masks))
 			reg->hw_avl_tags[j++] = mlx5_regc_value(i);
 	}
+	/*
+	 * Set the registers for NAT64 usage internally. REG_C_6 is always used.
+	 * The other 2 registers will be fetched from right to left, at least 2
+	 * tag registers should be available.
+	 */
+	MLX5_ASSERT(j >= (MLX5_FLOW_NAT64_REGS_MAX - 1));
+	reg->nat64_regs[0] = REG_C_6;
+	reg->nat64_regs[1] = reg->hw_avl_tags[j - 2];
+	reg->nat64_regs[2] = reg->hw_avl_tags[j - 1];
 }
 
 static void
drivers/net/mlx5/mlx5.h +2 -0
index 99850a58af..ee17a30454 100644
@@ -1407,10 +1407,12 @@ struct mlx5_hws_cnt_svc_mng {
 };
 
 #define MLX5_FLOW_HW_TAGS_MAX 12
+#define MLX5_FLOW_NAT64_REGS_MAX 3
 
 struct mlx5_dev_registers {
 	enum modify_reg aso_reg;
 	enum modify_reg hw_avl_tags[MLX5_FLOW_HW_TAGS_MAX];
+	enum modify_reg nat64_regs[MLX5_FLOW_NAT64_REGS_MAX];
 };
 
 #if defined(HAVE_MLX5DV_DR) && \
Signature · 1 line
2.39.3
author
#32 lore raw

PATCH v4 3/5 net/mlx5: create NAT64 actions during configuration

In reply to Bing Zhao

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.

---
 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(-)
doc/guides/nics/features/mlx5.ini +1 -0
index 30027f2ba1..81a7067cc3 100644
@@ -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
doc/guides/nics/mlx5.rst +10 -0
index 329b98f68f..c0294f268d 100644
@@ -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
 ----------
 
doc/guides/rel_notes/release_24_03.rst +7 -0
index 23ac6568ac..744f530ead 100644
@@ -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
 -------------
drivers/net/mlx5/mlx5.h +9 -0
index ee17a30454..c47712a146 100644
@@ -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. */
drivers/net/mlx5/mlx5_flow.h +11 -0
index 187f440893..897a283716 100644
@@ -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,
drivers/net/mlx5/mlx5_flow_dv.c +3 -1
index ddf19e9a51..18f09b22be 100644
@@ -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.
  *
drivers/net/mlx5/mlx5_flow_hw.c +65 -0

89 lines not on this page · raw message

Signature · 1 line
2.39.3
author
#33 lore raw

PATCH v4 4/5 net/mlx5: add NAT64 action support in rule creation

In reply to Bing Zhao

The action will handle the IPv4 and IPv6 headers translation. It will add / remove IPv6 address prefix by default.

To use the user specific address, another rule to modify the addresses of the IP header is needed.

---
 drivers/net/mlx5/mlx5_flow_hw.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/mlx5/mlx5_flow_hw.c +20 -0
index 77f0aff91e..f32bdff98f 100644
@@ -2499,6 +2499,19 @@ __flow_hw_actions_translate(struct rte_eth_dev *dev,
 			}
 			acts->rule_acts[dr_pos].action = priv->hw_def_miss;
 			break;
+		case RTE_FLOW_ACTION_TYPE_NAT64:
+			if (masks->conf &&
+			    ((const struct rte_flow_action_nat64 *)masks->conf)->type) {
+				const struct rte_flow_action_nat64 *nat64_c =
+					(const struct rte_flow_action_nat64 *)actions->conf;
+
+				acts->rule_acts[dr_pos].action =
+					priv->action_nat64[type][nat64_c->type];
+			} else if (__flow_hw_act_data_general_append(priv, acts,
+								     actions->type,
+								     src_pos, dr_pos))
+				goto err;
+			break;
 		case RTE_FLOW_ACTION_TYPE_END:
 			actions_end = true;
 			break;
@@ -2941,6 +2954,7 @@ flow_hw_actions_construct(struct rte_eth_dev *dev,
 	const struct rte_flow_action_ethdev *port_action = NULL;
 	const struct rte_flow_action_meter *meter = NULL;
 	const struct rte_flow_action_age *age = NULL;
+	const struct rte_flow_action_nat64 *nat64_c = NULL;
 	uint8_t *buf = job->encap_data;
 	uint8_t *push_buf = job->push_data;
 	struct rte_flow_attr attr = {
@@ -3208,6 +3222,11 @@ flow_hw_actions_construct(struct rte_eth_dev *dev,
 			if (ret != 0)
 				return ret;
 			break;
+		case RTE_FLOW_ACTION_TYPE_NAT64:
+			nat64_c = action->conf;
+			rule_acts[act_data->action_dst].action =
+				priv->action_nat64[table->type][nat64_c->type];
+			break;
 		default:
 			break;
 		}
@@ -6099,6 +6118,7 @@ static enum mlx5dr_action_type mlx5_hw_dr_action_types[] = {
 	[RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL] = MLX5DR_ACTION_TYP_DEST_ROOT,
 	[RTE_FLOW_ACTION_TYPE_IPV6_EXT_PUSH] = MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT,
 	[RTE_FLOW_ACTION_TYPE_IPV6_EXT_REMOVE] = MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT,
+	[RTE_FLOW_ACTION_TYPE_NAT64] = MLX5DR_ACTION_TYP_NAT64,
 };
 
 static inline void
Signature · 1 line
2.39.3
author
#34 lore raw

PATCH v4 5/5 net/mlx5: validate the actions combination with NAT64

In reply to Bing Zhao

NAT64 is treated as a modify header action. The action order and limitation should be the same as that of modify header in each domain.

Since the last 2 TAG registers will be used implicitly in the address backup mode, the values in these registers are no longer valid after the NAT64 action. The application should not try to match these TAGs after the rule that contains NAT64 action.

---
 drivers/net/mlx5/mlx5_flow.h    |  1 +
 drivers/net/mlx5/mlx5_flow_hw.c | 51 +++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)
drivers/net/mlx5/mlx5_flow.h +1 -0
index 897a283716..ea428a8c21 100644
@@ -392,6 +392,7 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_PORT_REPRESENTOR (1ull << 47)
 #define MLX5_FLOW_ACTION_IPV6_ROUTING_REMOVE (1ull << 48)
 #define MLX5_FLOW_ACTION_IPV6_ROUTING_PUSH (1ull << 49)
+#define MLX5_FLOW_ACTION_NAT64 (1ull << 50)
 
 #define MLX5_FLOW_DROP_INCLUSIVE_ACTIONS \
 	(MLX5_FLOW_ACTION_COUNT | MLX5_FLOW_ACTION_SAMPLE | MLX5_FLOW_ACTION_AGE)
drivers/net/mlx5/mlx5_flow_hw.c +51 -0

63 lines not on this page · raw message

Signature · 1 line
2.39.3
#35 lore raw

RE: [PATCH v4 0/5] NAT64 support in mlx5 PMD

In reply to Bing Zhao

Hi,

Quoted 54 lines

-----Original Message-----
From: Bing Zhao <[email protected]>
Sent: Wednesday, February 28, 2024 5:09 PM
To: Ori Kam <[email protected]>; [email protected]; Dariusz Sosnowski <[email protected]>; Slava Ovsiienko <[email protected]>; Suanming Mou <[email protected]>; Matan Azrad <[email protected]>; NBU-Contact-Thomas Monjalon (EXTERNAL) <[email protected]>; [email protected]; [email protected]; Raslan Darawsheh <[email protected]>
Cc: [email protected]; [email protected]
Subject: [PATCH v4 0/5] NAT64 support in mlx5 PMD

This patch set contains the mlx5 PMD implementation for NAT64.

Update in v4:
1. rebase to solve the conflicts.
2. fix the old NIC startup issue in a separate patch:

     https://patches.dpdk.org/project/dpdk/patch/20240227152627.25749-

[email protected]/

Update in v3:
1. code style and typo.

Update in v2:
1. separate from the RTE and testpmd common part.
2. reorder the commits.
3. bug fix, code polishing and document update.

Bing Zhao (4):
net/mlx5: fetch the available registers for NAT64 net/mlx5: create NAT64 actions during configuration net/mlx5: add NAT64 action support in rule creation net/mlx5: validate the actions combination with NAT64

Erez Shitrit (1):
net/mlx5/hws: support NAT64 action

 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/hws/mlx5dr.h          |  29 ++
 drivers/net/mlx5/hws/mlx5dr_action.c   | 436
++++++++++++++++++++++++-
 drivers/net/mlx5/hws/mlx5dr_action.h   |  35 ++
 drivers/net/mlx5/hws/mlx5dr_debug.c    |   1 +
 drivers/net/mlx5/mlx5.c                |   9 +
 drivers/net/mlx5/mlx5.h                |  11 +
 drivers/net/mlx5/mlx5_flow.h           |  12 +
 drivers/net/mlx5/mlx5_flow_dv.c        |   4 +-
 drivers/net/mlx5/mlx5_flow_hw.c        | 136 ++++++++
 12 files changed, 689 insertions(+), 2 deletions(-)
Quoted 2 lines

--
2.39.3

Series applied to next-net-mlx,
Kindest regards
Raslan Darawsheh