Skip to contentSkip to conversation

net/mlx5: lazily allocate HWS actions

PATCH In review Dariusz Sosnowski 2 participants 11 messages Feb 25 – Mar 2

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover net/mlx5: lazily allocate HWS actions

In mlx5 PMD, HWS flow engine is configured either:

- implicitly on port start or
- explicitly on rte_flow_configure().

As part of flow engine configuration, PMD allocates a set of global HWS action objects. These are used to implement flow actions such as:

- DROP
- MARK and FLAG (HWS tag action)
- OF_PUSH_VLAN
- OF_POP_VLAN
- SEND_TO_KERNEL
- NAT64
- PORT_REPRESENTOR (HWS default miss action).

These actions can be allocated once, for each flow domain, and parametrized on runtime.
Allocation of these actions requires allocation of STCs, HW objects used to set up HW actions.
These STCs are allocated in bulk to reduce amount of syscalls needed.

In case of global actions listed above, these STCs were allocated always even if none of the related flow actions were used by the application. This caused unnecessary system memory usage which could reach 4 MB per port. On systems with multiple VFs/SFs, memory usage could reach couple of GBs.

This patchset addresses that by introducing lazy allocation of these actions:

- Patch 1 - Redefines mlx5dr_action_mh_pattern to use rte_be64_t instead of __be64. This is to prevent compilation issues when mlx5dr.h is included in new files.
- Patch 2 - Add helpers for translating HWS flow table type to HWS action flags used on allocation to simplify logic added in follow up patches.
- Patch 3 - Introduces dedicated internal interface for lazily allocating HWS actions. Drop action is handled first.
- Patch 4-9 - Each patch adjusts one action type to use lazy allocation.

Dariusz Sosnowski (9):
net/mlx5: use DPDK be64 type in modify header pattern net/mlx5/hws: add table type to action flags conversion net/mlx5: lazily allocate drop HWS action net/mlx5: lazily allocate tag HWS action net/mlx5: lazily allocate HWS pop VLAN action net/mlx5: lazily allocate HWS push VLAN action net/mlx5: lazily allocate HWS send to kernel action net/mlx5: lazily allocate HWS NAT64 action net/mlx5: lazily allocate HWS default miss action

 drivers/net/mlx5/hws/mlx5dr.h              |  19 +-
 drivers/net/mlx5/hws/mlx5dr_action.c       |  26 +-
 drivers/net/mlx5/hws/mlx5dr_pat_arg.c      |  20 +-
 drivers/net/mlx5/hws/mlx5dr_pat_arg.h      |   8 +-
 drivers/net/mlx5/hws/mlx5dr_table.c        |  75 +++
 drivers/net/mlx5/meson.build               |   1 +
 drivers/net/mlx5/mlx5.h                    |  21 +-
 drivers/net/mlx5/mlx5_flow.h               |   1 +
 drivers/net/mlx5/mlx5_flow_dv.c            |   2 +-
 drivers/net/mlx5/mlx5_flow_hw.c            | 557 ++++++---------------
 drivers/net/mlx5/mlx5_hws_global_actions.c | 273 ++++++++++
 drivers/net/mlx5/mlx5_hws_global_actions.h |  71 +++
 12 files changed, 611 insertions(+), 463 deletions(-)
 create mode 100644 drivers/net/mlx5/mlx5_hws_global_actions.c
 create mode 100644 drivers/net/mlx5/mlx5_hws_global_actions.h

--
2.47.3

#1 lore raw

PATCH 1/9 net/mlx5: use DPDK be64 type in modify header pattern

mlx5dr.h defines mlx5dr_action_mh_pattern struct. One of its fields is an array of modify field HW actions, each of 64 bit size and stored as big endian. Before this patch, this array was defined using __be64 typedef from "linux/types.h" header file.

This necessitated either inclusion of that header file or, in case of Windows build, addition of typedef directly whenever mlx5dr.h was included.
Follow up patches which add lazy allocation of global HWS actions will add additional source files which would include mlx5dr.h. To prevent additional includes/typedef definitions required for __be64, this patch changes this definition to use DPDK's typedef i.e., rte_be64_t.

---
 drivers/net/mlx5/hws/mlx5dr.h         |  3 ++-
 drivers/net/mlx5/hws/mlx5dr_action.c  | 26 +++++++++++++-------------
 drivers/net/mlx5/hws/mlx5dr_pat_arg.c | 20 ++++++++++----------
 drivers/net/mlx5/hws/mlx5dr_pat_arg.h |  8 ++++----
 drivers/net/mlx5/mlx5.h               |  2 --
 drivers/net/mlx5/mlx5_flow_dv.c       |  2 +-
 drivers/net/mlx5/mlx5_flow_hw.c       |  4 ++--
 7 files changed, 32 insertions(+), 33 deletions(-)
drivers/net/mlx5/hws/mlx5dr.h +2 -1
index c13316305f..d358178e5b 100644
@@ -5,6 +5,7 @@
 #ifndef MLX5DR_H_
 #define MLX5DR_H_
 
+#include <rte_byteorder.h>
 #include <rte_flow.h>
 
 struct mlx5dr_context;
@@ -248,7 +249,7 @@ struct mlx5dr_action_mh_pattern {
 	/* Byte size of modify actions provided by "data" */
 	size_t sz;
 	/* PRM format modify actions pattern */
-	__be64 *data;
+	rte_be64_t *data;
 };
 
 /* In actions that take offset, the offset is unique, pointing to a single
drivers/net/mlx5/hws/mlx5dr_action.c +13 -13
index b35bf07c3c..439592c5e4 100644
@@ -369,7 +369,7 @@ mlx5dr_action_create_nat64_copy_state(struct mlx5dr_context *ctx,
 				      struct mlx5dr_action_nat64_attr *attr,
 				      uint32_t flags)
 {
-	__be64 modify_action_data[MLX5DR_ACTION_NAT64_MAX_MODIFY_ACTIONS];
+	rte_be64_t modify_action_data[MLX5DR_ACTION_NAT64_MAX_MODIFY_ACTIONS];
 	struct mlx5dr_action_mh_pattern pat[2];
 	struct mlx5dr_action *action;
 	uint32_t packet_len_field;
@@ -484,7 +484,7 @@ mlx5dr_action_create_nat64_repalce_state(struct mlx5dr_context *ctx,
 					 uint32_t flags)
 {
 	uint32_t address_prefix[MLX5DR_ACTION_NAT64_HEADER_MINUS_ONE] = {0};
-	__be64 modify_action_data[MLX5DR_ACTION_NAT64_MAX_MODIFY_ACTIONS];
+	rte_be64_t modify_action_data[MLX5DR_ACTION_NAT64_MAX_MODIFY_ACTIONS];
 	struct mlx5dr_action_mh_pattern pat[2];
 	static struct mlx5dr_action *action;
 	uint8_t header_size_in_dw;
@@ -575,7 +575,7 @@ mlx5dr_action_create_nat64_copy_proto_state(struct mlx5dr_context *ctx,
 					    struct mlx5dr_action_nat64_attr *attr,
 					    uint32_t flags)
 {
-	__be64 modify_action_data[MLX5DR_ACTION_NAT64_MAX_MODIFY_ACTIONS];
+	rte_be64_t modify_action_data[MLX5DR_ACTION_NAT64_MAX_MODIFY_ACTIONS];
 	struct mlx5dr_action_mh_pattern pat[2];
 	struct mlx5dr_action *action;
 	uint8_t *action_ptr;
@@ -615,7 +615,7 @@ mlx5dr_action_create_nat64_copy_back_state(struct mlx5dr_context *ctx,
 					   struct mlx5dr_action_nat64_attr *attr,
 					   uint32_t flags)
 {
-	__be64 modify_action_data[MLX5DR_ACTION_NAT64_MAX_MODIFY_ACTIONS];
+	rte_be64_t modify_action_data[MLX5DR_ACTION_NAT64_MAX_MODIFY_ACTIONS];
 	struct mlx5dr_action_mh_pattern pat[2];
 	struct mlx5dr_action *action;
 	uint32_t packet_len_field;
@@ -2165,7 +2165,7 @@ mlx5dr_action_handle_tunnel_l3_to_l2(struct mlx5dr_action *action,
 
 	/* All DecapL3 cases require the same max arg size */
 	arg_obj = mlx5dr_arg_create_modify_header_arg(ctx,
-						      (__be64 *)mh_data,
+						      (rte_be64_t *)mh_data,
 						      num_of_actions,
 						      log_bulk_sz,
 						      action->flags & MLX5DR_ACTION_FLAG_SHARED);
@@ -2177,7 +2177,7 @@ mlx5dr_action_handle_tunnel_l3_to_l2(struct mlx5dr_action *action,
 		mlx5dr_action_prepare_decap_l3_actions(hdrs[i].sz, mh_data, &num_of_actions);
 		mh_data_size = num_of_actions * MLX5DR_MODIFY_ACTION_SIZE;
 
-		pat_obj = mlx5dr_pat_get_pattern(ctx, (__be64 *)mh_data, mh_data_size);
+		pat_obj = mlx5dr_pat_get_pattern(ctx, (rte_be64_t *)mh_data, mh_data_size);
 		if (!pat_obj) {
 			DR_LOG(ERR, "Failed to allocate pattern for DecapL3");
 			goto free_stc_and_pat;
@@ -2189,7 +2189,7 @@ mlx5dr_action_handle_tunnel_l3_to_l2(struct mlx5dr_action *action,
 		action[i].modify_header.arg_obj = arg_obj;
 		action[i].modify_header.pat_obj = pat_obj;
 		action[i].modify_header.require_reparse =
-			mlx5dr_pat_require_reparse((__be64 *)mh_data, num_of_actions);
+			mlx5dr_pat_require_reparse((rte_be64_t *)mh_data, num_of_actions);
 
 		ret = mlx5dr_action_create_stcs(&action[i], NULL);
 		if (ret) {
@@ -2304,7 +2304,7 @@ mlx5dr_action_create_reformat(struct mlx5dr_context *ctx,
 static int
 mlx5dr_action_create_modify_header_root(struct mlx5dr_action *action,
 					size_t actions_sz,
-					__be64 *actions)
+					rte_be64_t *actions)
 {
 	enum mlx5dv_flow_table_type ft_type = 0;
 	struct ibv_context *local_ibv_ctx;
@@ -2897,7 +2897,7 @@ static void *
 mlx5dr_action_create_pop_ipv6_route_ext_mhdr1(struct mlx5dr_action *action)
 {
 	struct mlx5dr_action_mh_pattern pattern;
-	__be64 cmd[3] = {0};
+	rte_be64_t cmd[3] = {0};
 	uint16_t mod_id;
 
 	mod_id = flow_hw_get_ipv6_route_ext_mod_id_from_ctx(action->ctx, 0);
@@ -2943,7 +2943,7 @@ mlx5dr_action_create_pop_ipv6_route_ext_mhdr2(struct mlx5dr_action *action)
 		MLX5_MODI_OUT_DIPV6_31_0
 	};
 	struct mlx5dr_action_mh_pattern pattern;
-	__be64 cmd[5] = {0};
+	rte_be64_t cmd[5] = {0};
 	uint16_t mod_id;
 	uint32_t i;
 
@@ -3001,7 +3001,7 @@ mlx5dr_action_create_pop_ipv6_route_ext_mhdr3(struct mlx5dr_action *action)
 	MLX5_SET(copy_action_in, cmd, src_field, mod_id);
 	MLX5_SET(copy_action_in, cmd, dst_field, MLX5_MODI_OUT_IP_PROTOCOL);
 
-	pattern.data = (__be64 *)cmd;
+	pattern.data = (rte_be64_t *)cmd;
 	pattern.sz = sizeof(cmd);
 
 	return mlx5dr_action_create_modify_header_reparse(action->ctx, 1, &pattern, 0,
@@ -3063,7 +3063,7 @@ mlx5dr_action_create_push_ipv6_route_ext_mhdr1(struct mlx5dr_action *action)
 	MLX5_SET(set_action_in, cmd, field, MLX5_MODI_OUT_IP_PROTOCOL);
 	MLX5_SET(set_action_in, cmd, data, IPPROTO_ROUTING);
 
-	pattern.data = (__be64 *)cmd;
+	pattern.data = (rte_be64_t *)cmd;
 	pattern.sz = sizeof(cmd);
 
 	return mlx5dr_action_create_modify_header(action->ctx, 1, &pattern, 0,
@@ -3084,7 +3084,7 @@ mlx5dr_action_create_push_ipv6_route_ext_mhdr2(struct mlx5dr_action *action,
 	struct mlx5dr_action_mh_pattern pattern;
 	uint32_t *ipv6_dst_addr = NULL;
 	uint8_t seg_left, next_hdr;
-	__be64 cmd[5] = {0};
+	rte_be64_t cmd[5] = {0};
 	uint16_t mod_id;
 	uint32_t i;
 
drivers/net/mlx5/hws/mlx5dr_pat_arg.c +10 -10
index 513549ff3c..dfed5eb47a 100644
@@ -37,7 +37,7 @@ uint32_t mlx5dr_arg_get_arg_size(uint16_t num_of_actions)
 	return BIT(mlx5dr_arg_get_arg_log_size(num_of_actions));
 }
 
-bool mlx5dr_pat_require_reparse(__be64 *actions, uint16_t num_of_actions)
+bool mlx5dr_pat_require_reparse(rte_be64_t *actions, uint16_t num_of_actions)
 {
 	uint16_t i, field;
 	uint8_t action_id;
@@ -98,9 +98,9 @@ void mlx5dr_pat_uninit_pattern_cache(struct mlx5dr_pattern_cache *cache)
 }
 
 static bool mlx5dr_pat_compare_pattern(int cur_num_of_actions,
-				       __be64 cur_actions[],
+				       rte_be64_t cur_actions[],
 				       int num_of_actions,
-				       __be64 actions[])
+				       rte_be64_t actions[])
 {
 	int i;
 
@@ -129,13 +129,13 @@ static bool mlx5dr_pat_compare_pattern(int cur_num_of_actions,
 static struct mlx5dr_pattern_cache_item *
 mlx5dr_pat_find_cached_pattern(struct mlx5dr_pattern_cache *cache,
 			       uint16_t num_of_actions,
-			       __be64 *actions)
+			       rte_be64_t *actions)
 {
 	struct mlx5dr_pattern_cache_item *cached_pat;
 
 	LIST_FOREACH(cached_pat, &cache->head, next) {
 		if (mlx5dr_pat_compare_pattern(cached_pat->mh_data.num_of_actions,
-					       (__be64 *)cached_pat->mh_data.data,
+					       (rte_be64_t *)cached_pat->mh_data.data,
 					       num_of_actions,
 					       actions))
 			return cached_pat;
@@ -147,7 +147,7 @@ mlx5dr_pat_find_cached_pattern(struct mlx5dr_pattern_cache *cache,
 static struct mlx5dr_pattern_cache_item *
 mlx5dr_pat_get_existing_cached_pattern(struct mlx5dr_pattern_cache *cache,
 				       uint16_t num_of_actions,
-				       __be64 *actions)
+				       rte_be64_t *actions)
 {
 	struct mlx5dr_pattern_cache_item *cached_pattern;
 
@@ -166,7 +166,7 @@ static struct mlx5dr_pattern_cache_item *
 mlx5dr_pat_add_pattern_to_cache(struct mlx5dr_pattern_cache *cache,
 				struct mlx5dr_devx_obj *pattern_obj,
 				uint16_t num_of_actions,
-				__be64 *actions)
+				rte_be64_t *actions)
 {
 	struct mlx5dr_pattern_cache_item *cached_pattern;
 
@@ -248,7 +248,7 @@ void mlx5dr_pat_put_pattern(struct mlx5dr_context *ctx,
 
 struct mlx5dr_devx_obj *
 mlx5dr_pat_get_pattern(struct mlx5dr_context *ctx,
-		       __be64 *pattern, size_t pattern_sz)
+		       rte_be64_t *pattern, size_t pattern_sz)
 {
 	uint16_t num_of_actions = pattern_sz / MLX5DR_MODIFY_ACTION_SIZE;
 	struct mlx5dr_pattern_cache_item *cached_pattern;
@@ -458,7 +458,7 @@ mlx5dr_arg_create(struct mlx5dr_context *ctx,
 
 struct mlx5dr_devx_obj *
 mlx5dr_arg_create_modify_header_arg(struct mlx5dr_context *ctx,
-				    __be64 *data,
+				    rte_be64_t *data,
 				    uint8_t num_of_actions,
 				    uint32_t log_bulk_sz,
 				    bool write_data)
@@ -477,7 +477,7 @@ mlx5dr_arg_create_modify_header_arg(struct mlx5dr_context *ctx,
 	return arg_obj;
 }
 
-bool mlx5dr_pat_verify_actions(__be64 pattern[], size_t sz)
+bool mlx5dr_pat_verify_actions(rte_be64_t pattern[], size_t sz)
 {
 	size_t i;
 
drivers/net/mlx5/hws/mlx5dr_pat_arg.h +4 -4
index c4e0cbc843..3418469962 100644
@@ -51,7 +51,7 @@ int mlx5dr_pat_init_pattern_cache(struct mlx5dr_pattern_cache **cache);
 
 void mlx5dr_pat_uninit_pattern_cache(struct mlx5dr_pattern_cache *cache);
 
-bool mlx5dr_pat_verify_actions(__be64 pattern[], size_t sz);
+bool mlx5dr_pat_verify_actions(rte_be64_t pattern[], size_t sz);
 
 struct mlx5dr_devx_obj *
 mlx5dr_arg_create(struct mlx5dr_context *ctx,
@@ -62,14 +62,14 @@ mlx5dr_arg_create(struct mlx5dr_context *ctx,
 
 struct mlx5dr_devx_obj *
 mlx5dr_arg_create_modify_header_arg(struct mlx5dr_context *ctx,
-				    __be64 *data,
+				    rte_be64_t *data,
 				    uint8_t num_of_actions,
 				    uint32_t log_bulk_sz,
 				    bool write_data);
 
 struct mlx5dr_devx_obj *
 mlx5dr_pat_get_pattern(struct mlx5dr_context *ctx,
-		       __be64 *pattern,
+		       rte_be64_t *pattern,
 		       size_t pattern_sz);
 
 void mlx5dr_pat_put_pattern(struct mlx5dr_context *ctx,
@@ -78,7 +78,7 @@ void mlx5dr_pat_put_pattern(struct mlx5dr_context *ctx,
 bool mlx5dr_arg_is_valid_arg_request_size(struct mlx5dr_context *ctx,
 					  uint32_t arg_size);
 
-bool mlx5dr_pat_require_reparse(__be64 *actions, uint16_t num_of_actions);
+bool mlx5dr_pat_require_reparse(rte_be64_t *actions, uint16_t num_of_actions);
 
 void mlx5dr_arg_write(struct mlx5dr_send_engine *queue,
 		      void *comp_data,
drivers/net/mlx5/mlx5.h +0 -2
index b83dda5652..e9d855e345 100644
@@ -37,8 +37,6 @@
 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
 #ifndef RTE_EXEC_ENV_WINDOWS
 #define HAVE_MLX5_HWS_SUPPORT 1
-#else
-#define __be64 uint64_t
 #endif
 #include "hws/mlx5dr.h"
 #endif
drivers/net/mlx5/mlx5_flow_dv.c +1 -1
index 99ab0125a8..d1bed18077 100644
@@ -6294,7 +6294,7 @@ mlx5_flow_modify_create_cb(void *tool_ctx, void *cb_ctx)
 #ifdef HAVE_MLX5_HWS_SUPPORT
 		struct mlx5dr_action_mh_pattern pattern = {
 			.sz = data_len,
-			.data = (__be64 *)ref->actions
+			.data = (rte_be64_t *)ref->actions
 		};
 		entry->action = mlx5dr_action_create_modify_header(ctx->data2,
 			1,
drivers/net/mlx5/mlx5_flow_hw.c +2 -2
index 6ac6825c16..b29909f99d 100644
@@ -2436,7 +2436,7 @@ mlx5_tbl_translate_modify_header(struct rte_eth_dev *dev,
 					  NULL, "translate modify_header: no memory for modify header context");
 	rte_memcpy(acts->mhdr, mhdr, sizeof(*mhdr));
 	if (!mhdr->shared) {
-		pattern.data = (__be64 *)acts->mhdr->mhdr_cmds;
+		pattern.data = (rte_be64_t *)acts->mhdr->mhdr_cmds;
 		typeof(mp_ctx->mh) *mh = &mp_ctx->mh;
 		uint32_t idx = mh->elements_num;
 		mh->pattern[mh->elements_num++] = pattern;
@@ -2470,7 +2470,7 @@ mlx5_tbl_ensure_shared_modify_header(struct rte_eth_dev *dev,
 	uint16_t mhdr_ix = acts->mhdr->pos;
 	uint32_t flags = mlx5_hw_act_flag[!!attr->group][tbl_type] | MLX5DR_ACTION_FLAG_SHARED;
 
-	pattern.data = (__be64 *)acts->mhdr->mhdr_cmds;
+	pattern.data = (rte_be64_t *)acts->mhdr->mhdr_cmds;
 	acts->mhdr->action = mlx5dr_action_create_modify_header(priv->dr_ctx, 1,
 								&pattern, 0, flags);
 	if (!acts->mhdr->action)
Signature · 1 line
2.47.3
#2 lore raw

PATCH 2/9 net/mlx5/hws: add table type to action flags conversion

In reply to Dariusz Sosnowski

Add function for converting HWS table type to corresponding HWS action flag for both root and non-root tables.

---
 drivers/net/mlx5/hws/mlx5dr.h       | 16 ++++++
 drivers/net/mlx5/hws/mlx5dr_table.c | 75 +++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+)
drivers/net/mlx5/hws/mlx5dr.h +16 -0
index d358178e5b..078740a530 100644
@@ -369,6 +369,22 @@ mlx5dr_context_open(struct ibv_context *ibv_ctx,
  */
 int mlx5dr_context_close(struct mlx5dr_context *ctx);
 
+/**
+ * Convert given table type to corresponding action type.
+ *
+ * @param[in] table_type
+ *	Table type.
+ * @param[in] is_root
+ *	Whether table should be considered root or not.
+ * @param[out] action_flags
+ *	Corresponding action flags will be written here.
+ * @return
+ *	0 on success. Negative errno and rte_errno is set otherwise.
+ */
+int mlx5dr_table_type_to_action_flags(const enum mlx5dr_table_type table_type,
+				      const bool is_root,
+				      enum mlx5dr_action_flags *action_flags);
+
 /* Create a new direct rule table. Each table can contain multiple matchers.
  *
  * @param[in] ctx
drivers/net/mlx5/hws/mlx5dr_table.c +75 -0

81 lines not on this page · raw message

Signature · 1 line
2.47.3
#3 lore raw

PATCH 3/9 net/mlx5: lazily allocate drop HWS action

In reply to Dariusz Sosnowski

As of now, HWS drop action used for DROP flow action, is allocated either on port start or on rte_flow_configure(). This can cause unnecessary FW resource usage
if user does not use any DROP actions.

This patch adds dedicated internal API - mlx5_hws_global_actions - in mlx5 PMD for lazily allocating HWS drop action, to delay FW resource allocation until needed.
Instead of allocating HWS drop action supporting all possible domains (NIC Rx, NIC Tx, FDB if relevant) as it was previously, separate action will be allocated for each domain as needed to further minimize FW resource usage.

Follow up commits will extend this API with additional actions which are pre-allocated on port start or on rte_flow_configure().

---
 drivers/net/mlx5/meson.build               |  1 +
 drivers/net/mlx5/mlx5.h                    |  5 +-
 drivers/net/mlx5/mlx5_flow_hw.c            | 27 ++++-----
 drivers/net/mlx5/mlx5_hws_global_actions.c | 68 ++++++++++++++++++++++
 drivers/net/mlx5/mlx5_hws_global_actions.h | 39 +++++++++++++
 5 files changed, 123 insertions(+), 17 deletions(-)
 create mode 100644 drivers/net/mlx5/mlx5_hws_global_actions.c
 create mode 100644 drivers/net/mlx5/mlx5_hws_global_actions.h
drivers/net/mlx5/meson.build +1 -0
index 28275bed21..82a7dfe782 100644
@@ -53,6 +53,7 @@ if is_linux
             'mlx5_flow_quota.c',
             'mlx5_flow_verbs.c',
             'mlx5_hws_cnt.c',
+            'mlx5_hws_global_actions.c',
             'mlx5_nta_split.c',
             'mlx5_nta_sample.c',
     )
drivers/net/mlx5/mlx5.h +3 -2
index e9d855e345..54683cce7a 100644
@@ -39,6 +39,7 @@
 #define HAVE_MLX5_HWS_SUPPORT 1
 #endif
 #include "hws/mlx5dr.h"
+#include "mlx5_hws_global_actions.h"
 #endif
 
 #define MLX5_SH(dev) (((struct mlx5_priv *)(dev)->data->dev_private)->sh)
@@ -2112,8 +2113,8 @@ struct mlx5_priv {
 	struct mlx5dr_action *hw_push_vlan[MLX5DR_TABLE_TYPE_MAX];
 	struct mlx5dr_action *hw_pop_vlan[MLX5DR_TABLE_TYPE_MAX];
 	struct mlx5dr_action **hw_vport;
-	/* HW steering global drop action. */
-	struct mlx5dr_action *hw_drop[2];
+	/* HWS global actions. */
+	struct mlx5_hws_global_actions hw_global_actions;
 	/* HW steering global tag action. */
 	struct mlx5dr_action *hw_tag[2];
 	/* HW steering global default miss action. */
drivers/net/mlx5/mlx5_flow_hw.c +12 -15
index b29909f99d..80e156f26a 100644
@@ -2634,6 +2634,7 @@ __flow_hw_translate_actions_template(struct rte_eth_dev *dev,
 	int ret, err;
 	bool is_root = mlx5_group_id_is_root(cfg->attr.flow_attr.group);
 	bool unified_fdb = is_unified_fdb(priv);
+	struct mlx5dr_action *dr_action = NULL;
 
 	flow_hw_modify_field_init(&mhdr, at);
 	type = get_mlx5dr_table_type(attr, cfg->attr.specialize, unified_fdb);
@@ -2672,8 +2673,16 @@ __flow_hw_translate_actions_template(struct rte_eth_dev *dev,
 		case RTE_FLOW_ACTION_TYPE_VOID:
 			break;
 		case RTE_FLOW_ACTION_TYPE_DROP:
-			acts->rule_acts[dr_pos].action =
-				priv->hw_drop[!!attr->group];
+			dr_action = mlx5_hws_global_action_drop_get(priv, type, is_root);
+			if (dr_action == NULL) {
+				DRV_LOG(ERR, "port %u failed to allocate drop action",
+					priv->dev_data->port_id);
+				rte_flow_error_set(&sub_error, ENOMEM,
+						   RTE_FLOW_ERROR_TYPE_STATE, NULL,
+						   "failed to allocate drop action");
+				goto err;
+			}
+			acts->rule_acts[dr_pos].action = dr_action;
 			break;
 		case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
 			if (is_root) {
@@ -11965,8 +11974,6 @@ __mlx5_flow_hw_resource_release(struct rte_eth_dev *dev, bool ctx_close)
 		at = temp_at;
 	}
 	for (i = 0; i < MLX5_HW_ACTION_FLAG_MAX; i++) {
-		if (priv->hw_drop[i])
-			mlx5dr_action_destroy(priv->hw_drop[i]);
 		if (priv->hw_tag[i])
 			mlx5dr_action_destroy(priv->hw_tag[i]);
 	}
@@ -11995,6 +12002,7 @@ __mlx5_flow_hw_resource_release(struct rte_eth_dev *dev, bool ctx_close)
 		priv->ct_mng = NULL;
 	}
 	mlx5_flow_quota_destroy(dev);
+	mlx5_hws_global_actions_cleanup(priv);
 	if (priv->hw_q) {
 		for (i = 0; i < priv->nb_queue; i++) {
 			struct mlx5_hw_q *hwq = &priv->hw_q[i];
@@ -12345,29 +12353,18 @@ __flow_hw_configure(struct rte_eth_dev *dev,
 			goto err;
 	/* Add global actions. */
 	for (i = 0; i < MLX5_HW_ACTION_FLAG_MAX; i++) {
-		uint32_t act_flags = 0;
 		uint32_t tag_flags = mlx5_hw_act_flag[i][0];
 		bool tag_fdb_rx = !!priv->sh->cdev->config.hca_attr.fdb_rx_set_flow_tag_stc;
 
-		act_flags = mlx5_hw_act_flag[i][MLX5DR_TABLE_TYPE_NIC_RX] |
-			    mlx5_hw_act_flag[i][MLX5DR_TABLE_TYPE_NIC_TX];
 		if (is_proxy) {
 			if (unified_fdb) {
-				act_flags |=
-					(mlx5_hw_act_flag[i][MLX5DR_TABLE_TYPE_FDB_RX] |
-					 mlx5_hw_act_flag[i][MLX5DR_TABLE_TYPE_FDB_TX] |
-					 mlx5_hw_act_flag[i][MLX5DR_TABLE_TYPE_FDB_UNIFIED]);
 				if (i == MLX5_HW_ACTION_FLAG_NONE_ROOT && tag_fdb_rx)
 					tag_flags |= mlx5_hw_act_flag[i][MLX5DR_TABLE_TYPE_FDB_RX];
 			} else {
-				act_flags |= mlx5_hw_act_flag[i][MLX5DR_TABLE_TYPE_FDB];
 				if (i == MLX5_HW_ACTION_FLAG_NONE_ROOT && tag_fdb_rx)
 					tag_flags |= mlx5_hw_act_flag[i][MLX5DR_TABLE_TYPE_FDB];
 			}
 		}
-		priv->hw_drop[i] = mlx5dr_action_create_dest_drop(priv->dr_ctx, act_flags);
-		if (!priv->hw_drop[i])
-			goto err;
 		priv->hw_tag[i] = mlx5dr_action_create_tag
 			(priv->dr_ctx, tag_flags);
 		if (!priv->hw_tag[i])
drivers/net/mlx5/mlx5_hws_global_actions.c new file +68 -0

68 lines not on this page · raw message

drivers/net/mlx5/mlx5_hws_global_actions.h new file +39 -0
new file mode 100644
index 0000000000..3921004102
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2026 NVIDIA Corporation & Affiliates
+ */
+
+#ifndef RTE_PMD_MLX5_HWS_GLOBAL_ACTIONS_H_
+#define RTE_PMD_MLX5_HWS_GLOBAL_ACTIONS_H_
+
+#include <stdint.h>
+
+#include <rte_spinlock.h>
+
+#include "hws/mlx5dr.h"
+
+struct mlx5_priv;
+
+enum mlx5_hws_global_action_index {
+	MLX5_HWS_GLOBAL_ACTION_ROOT,
+	MLX5_HWS_GLOBAL_ACTION_NON_ROOT,
+	MLX5_HWS_GLOBAL_ACTION_MAX,
+};
+
+struct mlx5_hws_global_actions_array {
+	struct mlx5dr_action *arr[MLX5_HWS_GLOBAL_ACTION_MAX][MLX5DR_TABLE_TYPE_MAX];
+};
+
+struct mlx5_hws_global_actions {
+	struct mlx5_hws_global_actions_array drop;
+	rte_spinlock_t lock;
+};
+
+void mlx5_hws_global_actions_init(struct mlx5_priv *priv);
+
+void mlx5_hws_global_actions_cleanup(struct mlx5_priv *priv);
+
+struct mlx5dr_action *mlx5_hws_global_action_drop_get(struct mlx5_priv *priv,
+						      enum mlx5dr_table_type table_type,
+						      bool is_root);
+
+#endif /* !RTE_PMD_MLX5_HWS_GLOBAL_ACTIONS_H_ */
Signature · 1 line
2.47.3
#4 lore raw

PATCH 4/9 net/mlx5: lazily allocate tag HWS action

In reply to Dariusz Sosnowski

HWS tag action is used to implement FLAG and MARK rte_flow actions. It was allocated either on port start or on rte_flow_configure(). This could cause unnecessary FW resource usage
if user did not use any FLAG/MARK actions.

This patch extends global actions internal API, introduced in previous commit, to allow lazy allocation of HWS tag action. It will be allocated on first use of FLAG/MARK action and will be allocated per domain to minimize FW resource usage.

---
 drivers/net/mlx5/mlx5.h                    |  2 -
 drivers/net/mlx5/mlx5_flow_hw.c            | 47 +++++------
 drivers/net/mlx5/mlx5_hws_global_actions.c | 92 ++++++++++++++++++----
 drivers/net/mlx5/mlx5_hws_global_actions.h |  5 ++
 4 files changed, 100 insertions(+), 46 deletions(-)
drivers/net/mlx5/mlx5.h +0 -2
index 54683cce7a..43553b1f35 100644
@@ -2115,8 +2115,6 @@ struct mlx5_priv {
 	struct mlx5dr_action **hw_vport;
 	/* HWS global actions. */
 	struct mlx5_hws_global_actions hw_global_actions;
-	/* HW steering global tag action. */
-	struct mlx5dr_action *hw_tag[2];
 	/* HW steering global default miss action. */
 	struct mlx5dr_action *hw_def_miss;
 	/* HW steering global send to kernel action. */
drivers/net/mlx5/mlx5_flow_hw.c +20 -27

79 lines not on this page · raw message

drivers/net/mlx5/mlx5_hws_global_actions.c +75 -17

127 lines not on this page · raw message

drivers/net/mlx5/mlx5_hws_global_actions.h +5 -0
index 3921004102..bec9f3e0e8 100644
@@ -25,6 +25,7 @@ struct mlx5_hws_global_actions_array {
 
 struct mlx5_hws_global_actions {
 	struct mlx5_hws_global_actions_array drop;
+	struct mlx5_hws_global_actions_array tag;
 	rte_spinlock_t lock;
 };
 
@@ -36,4 +37,8 @@ struct mlx5dr_action *mlx5_hws_global_action_drop_get(struct mlx5_priv *priv,
 						      enum mlx5dr_table_type table_type,
 						      bool is_root);
 
+struct mlx5dr_action *mlx5_hws_global_action_tag_get(struct mlx5_priv *priv,
+						     enum mlx5dr_table_type table_type,
+						     bool is_root);
+
 #endif /* !RTE_PMD_MLX5_HWS_GLOBAL_ACTIONS_H_ */
Signature · 1 line
2.47.3
#5 lore raw

PATCH 5/9 net/mlx5: lazily allocate HWS pop VLAN action

In reply to Dariusz Sosnowski

HWS pop_vlan action is used to implement OF_POP_VLAN rte_flow action. It was allocated either on port start or on rte_flow_configure(). This could cause unnecessary FW resource usage
if user did not use any OF_POP_VLAN action.

This patch extends global actions internal API, introduced in previous commits, to allow lazy allocation of HWS pop_vlan action. It will be allocated on first use and will be allocated per domain to minimize FW resource usage.

---
 drivers/net/mlx5/mlx5.h                    |  1 -
 drivers/net/mlx5/mlx5_flow_hw.c            | 20 ++++++++++----------
 drivers/net/mlx5/mlx5_hws_global_actions.c | 21 +++++++++++++++++++++
 drivers/net/mlx5/mlx5_hws_global_actions.h |  5 +++++
 4 files changed, 36 insertions(+), 11 deletions(-)
drivers/net/mlx5/mlx5.h +0 -1
index 43553b1f35..9e46a8cee8 100644
@@ -2111,7 +2111,6 @@ struct mlx5_priv {
 	/* HW steering rte flow group list header */
 	LIST_HEAD(flow_hw_grp, mlx5_flow_group) flow_hw_grp;
 	struct mlx5dr_action *hw_push_vlan[MLX5DR_TABLE_TYPE_MAX];
-	struct mlx5dr_action *hw_pop_vlan[MLX5DR_TABLE_TYPE_MAX];
 	struct mlx5dr_action **hw_vport;
 	/* HWS global actions. */
 	struct mlx5_hws_global_actions hw_global_actions;
drivers/net/mlx5/mlx5_flow_hw.c +10 -10
index 54c30264b2..21c61bce90 100644
@@ -2753,8 +2753,16 @@ __flow_hw_translate_actions_template(struct rte_eth_dev *dev,
 			masks += of_vlan_offset;
 			break;
 		case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
-			acts->rule_acts[dr_pos].action =
-				priv->hw_pop_vlan[type];
+			dr_action = mlx5_hws_global_action_pop_vlan_get(priv, type, is_root);
+			if (dr_action == NULL) {
+				DRV_LOG(ERR, "port %u failed to allocate pop VLAN action",
+					priv->dev_data->port_id);
+				rte_flow_error_set(&sub_error, ENOMEM,
+						   RTE_FLOW_ERROR_TYPE_STATE, NULL,
+						   "failed to allocate pop VLAN action");
+				goto err;
+			}
+			acts->rule_acts[dr_pos].action = dr_action;
 			break;
 		case RTE_FLOW_ACTION_TYPE_JUMP:
 			if (masks->conf &&
@@ -11377,10 +11385,6 @@ flow_hw_destroy_vlan(struct rte_eth_dev *dev)
 	enum mlx5dr_table_type i;
 
 	for (i = MLX5DR_TABLE_TYPE_NIC_RX; i < MLX5DR_TABLE_TYPE_MAX; i++) {
-		if (priv->hw_pop_vlan[i]) {
-			mlx5dr_action_destroy(priv->hw_pop_vlan[i]);
-			priv->hw_pop_vlan[i] = NULL;
-		}
 		if (priv->hw_push_vlan[i]) {
 			mlx5dr_action_destroy(priv->hw_push_vlan[i]);
 			priv->hw_push_vlan[i] = NULL;
@@ -11401,10 +11405,6 @@ _create_vlan(struct mlx5_priv *priv, enum mlx5dr_table_type type)
 	};
 
 	/* rte_errno is set in the mlx5dr_action* functions. */
-	priv->hw_pop_vlan[type] =
-		mlx5dr_action_create_pop_vlan(priv->dr_ctx, flags[type]);
-	if (!priv->hw_pop_vlan[type])
-		return -rte_errno;
 	priv->hw_push_vlan[type] =
 		mlx5dr_action_create_push_vlan(priv->dr_ctx, flags[type]);
 	if (!priv->hw_push_vlan[type])
drivers/net/mlx5/mlx5_hws_global_actions.c +21 -0
index 1ca444ce98..236e6f1d1a 100644
@@ -41,6 +41,7 @@ mlx5_hws_global_actions_cleanup(struct mlx5_priv *priv)
 
 	global_actions_array_cleanup(priv, &priv->hw_global_actions.drop, "drop");
 	global_actions_array_cleanup(priv, &priv->hw_global_actions.tag, "tag");
+	global_actions_array_cleanup(priv, &priv->hw_global_actions.pop_vlan, "pop_vlan");
 
 	rte_spinlock_unlock(&priv->hw_global_actions.lock);
 }
@@ -62,6 +63,13 @@ action_create_tag_cb(struct mlx5dr_context *ctx,
 	return mlx5dr_action_create_tag(ctx, action_flags);
 }
 
+static struct mlx5dr_action *
+action_create_pop_vlan_cb(struct mlx5dr_context *ctx,
+			  uint32_t action_flags)
+{
+	return mlx5dr_action_create_pop_vlan(ctx, action_flags);
+}
+
 static struct mlx5dr_action *
 global_action_get(struct mlx5_priv *priv,
 		  struct mlx5_hws_global_actions_array *array,
@@ -124,3 +132,16 @@ mlx5_hws_global_action_tag_get(struct mlx5_priv *priv,
 				 is_root,
 				 action_create_tag_cb);
 }
+
+struct mlx5dr_action *
+mlx5_hws_global_action_pop_vlan_get(struct mlx5_priv *priv,
+				    enum mlx5dr_table_type table_type,
+				    bool is_root)
+{
+	return global_action_get(priv,
+				 &priv->hw_global_actions.pop_vlan,
+				 "pop_vlan",
+				 table_type,
+				 is_root,
+				 action_create_pop_vlan_cb);
+}
drivers/net/mlx5/mlx5_hws_global_actions.h +5 -0
index bec9f3e0e8..d04ebc42be 100644
@@ -26,6 +26,7 @@ struct mlx5_hws_global_actions_array {
 struct mlx5_hws_global_actions {
 	struct mlx5_hws_global_actions_array drop;
 	struct mlx5_hws_global_actions_array tag;
+	struct mlx5_hws_global_actions_array pop_vlan;
 	rte_spinlock_t lock;
 };
 
@@ -41,4 +42,8 @@ struct mlx5dr_action *mlx5_hws_global_action_tag_get(struct mlx5_priv *priv,
 						     enum mlx5dr_table_type table_type,
 						     bool is_root);
 
+struct mlx5dr_action *mlx5_hws_global_action_pop_vlan_get(struct mlx5_priv *priv,
+							  enum mlx5dr_table_type table_type,
+							  bool is_root);
+
 #endif /* !RTE_PMD_MLX5_HWS_GLOBAL_ACTIONS_H_ */
Signature · 1 line
2.47.3
#6 lore raw

PATCH 6/9 net/mlx5: lazily allocate HWS push VLAN action

In reply to Dariusz Sosnowski

HWS push_vlan action is used to implement OF_PUSH_VLAN rte_flow action. It was allocated either on port start or on rte_flow_configure(). This could cause unnecessary FW resource usage
if user did not use any OF_PUSH_VLAN action.

This patch extends global actions internal API, introduced in previous commits, to allow lazy allocation of HWS push_vlan action. It will be allocated on first use and will be allocated per domain to minimize FW resource usage.

---
 drivers/net/mlx5/mlx5.h                    |  1 -
 drivers/net/mlx5/mlx5_flow_hw.c            | 78 +++-------------------
 drivers/net/mlx5/mlx5_hws_global_actions.c | 21 ++++++
 drivers/net/mlx5/mlx5_hws_global_actions.h |  5 ++
 4 files changed, 36 insertions(+), 69 deletions(-)
drivers/net/mlx5/mlx5.h +0 -1
index 9e46a8cee8..94b4cb0d7b 100644
@@ -2110,7 +2110,6 @@ struct mlx5_priv {
 	LIST_HEAD(flow_hw_tbl, rte_flow_template_table) flow_hw_tbl;
 	/* HW steering rte flow group list header */
 	LIST_HEAD(flow_hw_grp, mlx5_flow_group) flow_hw_grp;
-	struct mlx5dr_action *hw_push_vlan[MLX5DR_TABLE_TYPE_MAX];
 	struct mlx5dr_action **hw_vport;
 	/* HWS global actions. */
 	struct mlx5_hws_global_actions hw_global_actions;
drivers/net/mlx5/mlx5_flow_hw.c +10 -68

102 lines not on this page · raw message

drivers/net/mlx5/mlx5_hws_global_actions.c +21 -0
index 236e6f1d1a..2bbfa5a24c 100644
@@ -42,6 +42,7 @@ mlx5_hws_global_actions_cleanup(struct mlx5_priv *priv)
 	global_actions_array_cleanup(priv, &priv->hw_global_actions.drop, "drop");
 	global_actions_array_cleanup(priv, &priv->hw_global_actions.tag, "tag");
 	global_actions_array_cleanup(priv, &priv->hw_global_actions.pop_vlan, "pop_vlan");
+	global_actions_array_cleanup(priv, &priv->hw_global_actions.push_vlan, "push_vlan");
 
 	rte_spinlock_unlock(&priv->hw_global_actions.lock);
 }
@@ -70,6 +71,13 @@ action_create_pop_vlan_cb(struct mlx5dr_context *ctx,
 	return mlx5dr_action_create_pop_vlan(ctx, action_flags);
 }
 
+static struct mlx5dr_action *
+action_create_push_vlan_cb(struct mlx5dr_context *ctx,
+			   uint32_t action_flags)
+{
+	return mlx5dr_action_create_push_vlan(ctx, action_flags);
+}
+
 static struct mlx5dr_action *
 global_action_get(struct mlx5_priv *priv,
 		  struct mlx5_hws_global_actions_array *array,
@@ -145,3 +153,16 @@ mlx5_hws_global_action_pop_vlan_get(struct mlx5_priv *priv,
 				 is_root,
 				 action_create_pop_vlan_cb);
 }
+
+struct mlx5dr_action *
+mlx5_hws_global_action_push_vlan_get(struct mlx5_priv *priv,
+				     enum mlx5dr_table_type table_type,
+				     bool is_root)
+{
+	return global_action_get(priv,
+				 &priv->hw_global_actions.push_vlan,
+				 "push_vlan",
+				 table_type,
+				 is_root,
+				 action_create_push_vlan_cb);
+}
drivers/net/mlx5/mlx5_hws_global_actions.h +5 -0
index d04ebc42be..4281ba701c 100644
@@ -27,6 +27,7 @@ struct mlx5_hws_global_actions {
 	struct mlx5_hws_global_actions_array drop;
 	struct mlx5_hws_global_actions_array tag;
 	struct mlx5_hws_global_actions_array pop_vlan;
+	struct mlx5_hws_global_actions_array push_vlan;
 	rte_spinlock_t lock;
 };
 
@@ -46,4 +47,8 @@ struct mlx5dr_action *mlx5_hws_global_action_pop_vlan_get(struct mlx5_priv *priv
 							  enum mlx5dr_table_type table_type,
 							  bool is_root);
 
+struct mlx5dr_action *mlx5_hws_global_action_push_vlan_get(struct mlx5_priv *priv,
+							   enum mlx5dr_table_type table_type,
+							   bool is_root);
+
 #endif /* !RTE_PMD_MLX5_HWS_GLOBAL_ACTIONS_H_ */
Signature · 1 line
2.47.3
#7 lore raw

PATCH 7/9 net/mlx5: lazily allocate HWS send to kernel action

In reply to Dariusz Sosnowski

HWS send_to_kernel action is used to implement SEND_TO_KERNEL rte_flow action.
It was allocated either on port start or on rte_flow_configure(). This could cause unnecessary FW resource usage
if user did not use any SEND_TO_KERNEL action.

This patch extends global actions internal API, introduced in previous commits, to allow lazy allocation of HWS send_to_kernel action. It will be allocated on first use and will be allocated per domain to minimize FW resource usage.

---
 drivers/net/mlx5/mlx5.h                    |  2 -
 drivers/net/mlx5/mlx5_flow_hw.c            | 90 ++++------------------
 drivers/net/mlx5/mlx5_hws_global_actions.c | 59 +++++++++++---
 drivers/net/mlx5/mlx5_hws_global_actions.h |  5 ++
 4 files changed, 66 insertions(+), 90 deletions(-)
drivers/net/mlx5/mlx5.h +0 -2
index 94b4cb0d7b..739b414faf 100644
@@ -2115,8 +2115,6 @@ struct mlx5_priv {
 	struct mlx5_hws_global_actions hw_global_actions;
 	/* HW steering global default miss action. */
 	struct mlx5dr_action *hw_def_miss;
-	/* HW steering global send to kernel action. */
-	struct mlx5dr_action *hw_send_to_kernel[MLX5DR_TABLE_TYPE_MAX];
 	/* HW steering create ongoing rte flow table list header. */
 	LIST_HEAD(flow_hw_tbl_ongo, rte_flow_template_table) flow_hw_tbl_ongo;
 	struct mlx5_indexed_pool *acts_ipool; /* Action data indexed pool. */
drivers/net/mlx5/mlx5_flow_hw.c +13 -77

133 lines not on this page · raw message

drivers/net/mlx5/mlx5_hws_global_actions.c +48 -11

129 lines not on this page · raw message

drivers/net/mlx5/mlx5_hws_global_actions.h +5 -0
index 4281ba701c..7fbca9fc96 100644
@@ -28,6 +28,7 @@ struct mlx5_hws_global_actions {
 	struct mlx5_hws_global_actions_array tag;
 	struct mlx5_hws_global_actions_array pop_vlan;
 	struct mlx5_hws_global_actions_array push_vlan;
+	struct mlx5_hws_global_actions_array send_to_kernel;
 	rte_spinlock_t lock;
 };
 
@@ -51,4 +52,8 @@ struct mlx5dr_action *mlx5_hws_global_action_push_vlan_get(struct mlx5_priv *pri
 							   enum mlx5dr_table_type table_type,
 							   bool is_root);
 
+struct mlx5dr_action *mlx5_hws_global_action_send_to_kernel_get(struct mlx5_priv *priv,
+								 enum mlx5dr_table_type table_type,
+								 uint16_t priority);
+
 #endif /* !RTE_PMD_MLX5_HWS_GLOBAL_ACTIONS_H_ */
Signature · 1 line
2.47.3
#8 lore raw

PATCH 8/9 net/mlx5: lazily allocate HWS NAT64 action

In reply to Dariusz Sosnowski

HWS NAT64 action is used to implement NAT64 rte_flow action. It was allocated either on port start or on rte_flow_configure(). This could cause unnecessary FW resource usage
if user did not use any NAT64 action.

This patch extends global actions internal API, introduced in previous commits, to allow lazy allocation of HWS NAT64 action. It will be allocated on first use and will be allocated per domain to minimize FW resource usage.

---
 drivers/net/mlx5/mlx5.h                    |   6 -
 drivers/net/mlx5/mlx5_flow.h               |   1 +
 drivers/net/mlx5/mlx5_flow_hw.c            | 215 ++++-----------------
 drivers/net/mlx5/mlx5_hws_global_actions.c |  45 +++++
 drivers/net/mlx5/mlx5_hws_global_actions.h |   7 +
 5 files changed, 94 insertions(+), 180 deletions(-)
drivers/net/mlx5/mlx5.h +0 -6
index 739b414faf..75e61d6b5b 100644
@@ -2127,12 +2127,6 @@ struct mlx5_priv {
 
 	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];
 	struct mlx5_indexed_pool *ptype_rss_groups;
 	struct mlx5_nta_sample_ctx *nta_sample_ctx;
 #endif
drivers/net/mlx5/mlx5_flow.h +1 -0
index c8af3fe0be..4c56e638ab 100644
@@ -1625,6 +1625,7 @@ struct mlx5_hw_actions {
 	uint32_t mark:1; /* Indicate the mark action. */
 	cnt_id_t cnt_id; /* Counter id. */
 	uint32_t mtr_id; /* Meter id. */
+	struct mlx5dr_action *nat64[2]; /* [RTE_FLOW_NAT64_6TO4], [RTE_FLOW_NAT64_4TO6] */
 	/* Translated DR action array from action template. */
 	struct mlx5dr_rule_action rule_acts[MLX5_HW_MAX_ACTS];
 };
drivers/net/mlx5/mlx5_flow_hw.c +41 -174

267 lines not on this page · raw message

drivers/net/mlx5/mlx5_hws_global_actions.c +45 -0

66 lines not on this page · raw message

drivers/net/mlx5/mlx5_hws_global_actions.h +7 -0
index 7fbca9fc96..788b5c124a 100644
@@ -7,6 +7,7 @@
 
 #include <stdint.h>
 
+#include <rte_flow.h>
 #include <rte_spinlock.h>
 
 #include "hws/mlx5dr.h"
@@ -29,6 +30,8 @@ struct mlx5_hws_global_actions {
 	struct mlx5_hws_global_actions_array pop_vlan;
 	struct mlx5_hws_global_actions_array push_vlan;
 	struct mlx5_hws_global_actions_array send_to_kernel;
+	struct mlx5_hws_global_actions_array nat64_6to4;
+	struct mlx5_hws_global_actions_array nat64_4to6;
 	rte_spinlock_t lock;
 };
 
@@ -56,4 +59,8 @@ struct mlx5dr_action *mlx5_hws_global_action_send_to_kernel_get(struct mlx5_priv
 								 enum mlx5dr_table_type table_type,
 								 uint16_t priority);
 
+struct mlx5dr_action *mlx5_hws_global_action_nat64_get(struct mlx5_priv *priv,
+						       enum mlx5dr_table_type table_type,
+						       enum rte_flow_nat64_type nat64_type);
+
 #endif /* !RTE_PMD_MLX5_HWS_GLOBAL_ACTIONS_H_ */
Signature · 1 line
2.47.3
#9 lore raw

PATCH 9/9 net/mlx5: lazily allocate HWS default miss action

In reply to Dariusz Sosnowski

HWS default miss action is used to implement PORT_REPRESENTOR rte_flow action and is used internally for LACP default rules. It was allocated either on port start or on rte_flow_configure(). This could cause unnecessary FW resource usage
even if user did not use PORT_REPRESENTOR or application was running on a setup without LACP.

This patch extends global actions internal API, introduced in previous commits, to allow lazy allocation of HWS default miss action. It will be allocated on first use and will be allocated per domain to minimize FW resource usage.

---
 drivers/net/mlx5/mlx5.h                    |  2 -
 drivers/net/mlx5/mlx5_flow_hw.c            | 76 ++++++++++------------
 drivers/net/mlx5/mlx5_hws_global_actions.c | 23 +++++++
 drivers/net/mlx5/mlx5_hws_global_actions.h |  5 ++
 4 files changed, 61 insertions(+), 45 deletions(-)
drivers/net/mlx5/mlx5.h +0 -2
index 75e61d6b5b..c54266ec26 100644
@@ -2113,8 +2113,6 @@ struct mlx5_priv {
 	struct mlx5dr_action **hw_vport;
 	/* HWS global actions. */
 	struct mlx5_hws_global_actions hw_global_actions;
-	/* HW steering global default miss action. */
-	struct mlx5dr_action *hw_def_miss;
 	/* HW steering create ongoing rte flow table list header. */
 	LIST_HEAD(flow_hw_tbl_ongo, rte_flow_template_table) flow_hw_tbl_ongo;
 	struct mlx5_indexed_pool *acts_ipool; /* Action data indexed pool. */
drivers/net/mlx5/mlx5_flow_hw.c +33 -43

147 lines not on this page · raw message

drivers/net/mlx5/mlx5_hws_global_actions.c +23 -0
index 6520879ae4..58b9c44752 100644
@@ -49,6 +49,7 @@ mlx5_hws_global_actions_cleanup(struct mlx5_priv *priv)
 				     "send_to_kernel");
 	global_actions_array_cleanup(priv, &priv->hw_global_actions.nat64_6to4, "nat64_6to4");
 	global_actions_array_cleanup(priv, &priv->hw_global_actions.nat64_4to6, "nat64_4to6");
+	global_actions_array_cleanup(priv, &priv->hw_global_actions.def_miss, "def_miss");
 
 	rte_spinlock_unlock(&priv->hw_global_actions.lock);
 }
@@ -111,6 +112,14 @@ action_create_nat64_cb(struct mlx5dr_context *ctx,
 					  action_flags | MLX5DR_ACTION_FLAG_SHARED);
 }
 
+static struct mlx5dr_action *
+action_create_def_miss_cb(struct mlx5dr_context *ctx,
+			  uint32_t action_flags,
+			  void *user_data __rte_unused)
+{
+	return mlx5dr_action_create_default_miss(ctx, action_flags);
+}
+
 static struct mlx5dr_action *
 global_action_get(struct mlx5_priv *priv,
 		  struct mlx5_hws_global_actions_array *array,
@@ -248,3 +257,17 @@ mlx5_hws_global_action_nat64_get(struct mlx5_priv *priv,
 	return global_action_get(priv, array, name, table_type,
 				 false, action_create_nat64_cb, &attr);
 }
+
+struct mlx5dr_action *
+mlx5_hws_global_action_def_miss_get(struct mlx5_priv *priv,
+				    enum mlx5dr_table_type table_type,
+				    bool is_root)
+{
+	return global_action_get(priv,
+				 &priv->hw_global_actions.def_miss,
+				 "def_miss",
+				 table_type,
+				 is_root,
+				 action_create_def_miss_cb,
+				 NULL);
+}
drivers/net/mlx5/mlx5_hws_global_actions.h +5 -0
index 788b5c124a..16dc8d7002 100644
@@ -32,6 +32,7 @@ struct mlx5_hws_global_actions {
 	struct mlx5_hws_global_actions_array send_to_kernel;
 	struct mlx5_hws_global_actions_array nat64_6to4;
 	struct mlx5_hws_global_actions_array nat64_4to6;
+	struct mlx5_hws_global_actions_array def_miss;
 	rte_spinlock_t lock;
 };
 
@@ -63,4 +64,8 @@ struct mlx5dr_action *mlx5_hws_global_action_nat64_get(struct mlx5_priv *priv,
 						       enum mlx5dr_table_type table_type,
 						       enum rte_flow_nat64_type nat64_type);
 
+struct mlx5dr_action *mlx5_hws_global_action_def_miss_get(struct mlx5_priv *priv,
+							   enum mlx5dr_table_type table_type,
+							   bool is_root);
+
 #endif /* !RTE_PMD_MLX5_HWS_GLOBAL_ACTIONS_H_ */
Signature · 1 line
2.47.3
#10 lore raw
In reply to Dariusz Sosnowski

Hi,

Quoted 61 lines · Dariusz Sosnowski

In mlx5 PMD, HWS flow engine is configured either:

- implicitly on port start or
- explicitly on rte_flow_configure().

As part of flow engine configuration, PMD allocates a set of global HWS action objects. These are used to implement flow actions such as:

- DROP
- MARK and FLAG (HWS tag action)
- OF_PUSH_VLAN
- OF_POP_VLAN
- SEND_TO_KERNEL
- NAT64
- PORT_REPRESENTOR (HWS default miss action).

These actions can be allocated once, for each flow domain, and parametrized on runtime.
Allocation of these actions requires allocation of STCs, HW objects used to set up HW actions.
These STCs are allocated in bulk to reduce amount of syscalls needed.

In case of global actions listed above, these STCs were allocated always even if none of the related flow actions were used by the application. This caused unnecessary system memory usage which could reach 4 MB per port. On systems with multiple VFs/SFs, memory usage could reach couple of GBs.

This patchset addresses that by introducing lazy allocation of these actions:

- Patch 1 - Redefines mlx5dr_action_mh_pattern to use rte_be64_t instead of __be64. This is to prevent compilation issues when mlx5dr.h is included in new files.
- Patch 2 - Add helpers for translating HWS flow table type to HWS action flags used on allocation to simplify logic added in follow up patches.
- Patch 3 - Introduces dedicated internal interface for lazily allocating HWS actions. Drop action is handled first.
- Patch 4-9 - Each patch adjusts one action type to use lazy allocation.

Dariusz Sosnowski (9):
net/mlx5: use DPDK be64 type in modify header pattern net/mlx5/hws: add table type to action flags conversion net/mlx5: lazily allocate drop HWS action net/mlx5: lazily allocate tag HWS action net/mlx5: lazily allocate HWS pop VLAN action net/mlx5: lazily allocate HWS push VLAN action net/mlx5: lazily allocate HWS send to kernel action net/mlx5: lazily allocate HWS NAT64 action net/mlx5: lazily allocate HWS default miss action

  drivers/net/mlx5/hws/mlx5dr.h              |  19 +-
  drivers/net/mlx5/hws/mlx5dr_action.c       |  26 +-
  drivers/net/mlx5/hws/mlx5dr_pat_arg.c      |  20 +-
  drivers/net/mlx5/hws/mlx5dr_pat_arg.h      |   8 +-
  drivers/net/mlx5/hws/mlx5dr_table.c        |  75 +++
  drivers/net/mlx5/meson.build               |   1 +
  drivers/net/mlx5/mlx5.h                    |  21 +-
  drivers/net/mlx5/mlx5_flow.h               |   1 +
  drivers/net/mlx5/mlx5_flow_dv.c            |   2 +-
  drivers/net/mlx5/mlx5_flow_hw.c            | 557 ++++++---------------
  drivers/net/mlx5/mlx5_hws_global_actions.c | 273 ++++++++++
  drivers/net/mlx5/mlx5_hws_global_actions.h |  71 +++
  12 files changed, 611 insertions(+), 463 deletions(-)
Quoted 6 lines

create mode 100644 drivers/net/mlx5/mlx5_hws_global_actions.c create mode 100644 drivers/net/mlx5/mlx5_hws_global_actions.h

--
2.47.3

Series applied to next-net-mlx,

Kindest regards
Raslan Darawsheh