DPDK patches and discussions
 help / color / mirror / Atom feed
From: Maayan Kashani <mkashani@nvidia.com>
To: <dev@dpdk.org>
Cc: <mkashani@nvidia.com>, <dsosnowski@nvidia.com>,
	<rasland@nvidia.com>, "Bing Zhao" <bingz@nvidia.com>,
	Viacheslav Ovsiienko <viacheslavo@nvidia.com>,
	"Ori Kam" <orika@nvidia.com>, Suanming Mou <suanmingm@nvidia.com>,
	Matan Azrad <matan@nvidia.com>
Subject: [PATCH v6 03/11] net/mlx5: add basic actions support for non-template API
Date: Sun, 9 Jun 2024 11:55:52 +0300	[thread overview]
Message-ID: <20240609085600.87274-3-mkashani@nvidia.com> (raw)
In-Reply-To: <20240609085600.87274-1-mkashani@nvidia.com>

From: Bing Zhao <bingz@nvidia.com>

Support JUMP / DROP / QUEUE / MARK / FLAG now.

Signed-off-by: Bing Zhao <bingz@nvidia.com>
Acked-by: Dariusz Sosnowski <dsosnowski@nvidia.com>
---
 drivers/net/mlx5/mlx5_flow_hw.c | 153 ++++++++++++++++++++++++++++----
 1 file changed, 135 insertions(+), 18 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c
index 5f1e93c3aad..b5cf51ec58d 100644
--- a/drivers/net/mlx5/mlx5_flow_hw.c
+++ b/drivers/net/mlx5/mlx5_flow_hw.c
@@ -546,8 +546,7 @@ flow_hw_jump_release(struct rte_eth_dev *dev, struct mlx5_hw_jump_action *jump)
 	struct mlx5_priv *priv = dev->data->dev_private;
 	struct mlx5_flow_group *grp;
 
-	grp = container_of
-		(jump, struct mlx5_flow_group, jump);
+	grp = container_of(jump, struct mlx5_flow_group, jump);
 	mlx5_hlist_unregister(priv->sh->flow_tbls, &grp->entry);
 }
 
@@ -647,17 +646,9 @@ flow_hw_template_destroy_mhdr_action(struct mlx5_hw_modify_header_action *mhdr)
  *   Pointer to the template HW steering DR actions.
  */
 static void
-__flow_hw_action_template_destroy(struct rte_eth_dev *dev,
-				 struct mlx5_hw_actions *acts)
+__flow_hw_actions_release(struct rte_eth_dev *dev, struct mlx5_hw_actions *acts)
 {
 	struct mlx5_priv *priv = dev->data->dev_private;
-	struct mlx5_action_construct_data *data;
-
-	while (!LIST_EMPTY(&acts->act_list)) {
-		data = LIST_FIRST(&acts->act_list);
-		LIST_REMOVE(data, next);
-		mlx5_ipool_free(priv->acts_ipool, data->idx);
-	}
 
 	if (acts->mark)
 		if (!(rte_atomic_fetch_sub_explicit(&priv->hws_mark_refcnt, 1,
@@ -702,6 +693,32 @@ __flow_hw_action_template_destroy(struct rte_eth_dev *dev,
 	}
 }
 
+/**
+ * Destroy DR actions created by action template.
+ *
+ * For DR actions created during table creation's action translate.
+ * Need to destroy the DR action when destroying the table.
+ *
+ * @param[in] dev
+ *   Pointer to the rte_eth_dev structure.
+ * @param[in] acts
+ *   Pointer to the template HW steering DR actions.
+ */
+static void
+__flow_hw_action_template_destroy(struct rte_eth_dev *dev, struct mlx5_hw_actions *acts)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct mlx5_action_construct_data *data;
+
+	while (!LIST_EMPTY(&acts->act_list)) {
+		data = LIST_FIRST(&acts->act_list);
+		LIST_REMOVE(data, next);
+		mlx5_ipool_free(priv->acts_ipool, data->idx);
+	}
+
+	__flow_hw_actions_release(dev, acts);
+}
+
 /**
  * Append dynamic action to the dynamic action list.
  *
@@ -12690,14 +12707,113 @@ static int flow_hw_prepare(struct rte_eth_dev *dev,
 	return 0;
 }
 
-static int flow_hw_translate_actions(struct rte_eth_dev *dev __rte_unused,
-					const struct rte_flow_attr *attr __rte_unused,
-					const struct rte_flow_action actions[] __rte_unused,
-					struct rte_flow_hw *flow __rte_unused,
-					struct rte_flow_error *error __rte_unused)
+static int
+flow_hw_translate_actions(struct rte_eth_dev *dev,
+			  const struct rte_flow_attr *attr,
+			  const struct rte_flow_action actions[],
+			  struct rte_flow_hw *flow,
+			  struct mlx5_hw_actions *hw_acts,
+			  bool external,
+			  struct rte_flow_error *error)
 {
-	/* TODO implement */
+	struct mlx5_priv *priv = dev->data->dev_private;
+	enum mlx5dr_table_type type;
+	enum mlx5_hw_action_flag_type flag_type;
+	bool actions_end = false;
+	uint64_t action_flags = 0; /* to be used when needed */
+	uint32_t actions_n = 0;
+	uint32_t mark_id;
+	uint32_t jump_group;
+	bool is_mark;
+	struct mlx5_flow_template_table_cfg tbl_cfg;
+	enum mlx5_flow_fate_type fate_type = MLX5_FLOW_FATE_NONE;
+
+	if (attr->transfer)
+		type = MLX5DR_TABLE_TYPE_FDB;
+	else if (attr->egress)
+		type = MLX5DR_TABLE_TYPE_NIC_TX;
+	else
+		type = MLX5DR_TABLE_TYPE_NIC_RX;
+	/* The group in the attribute translation was done in advance. */
+	flag_type = (attr->group == 0) ? MLX5_HW_ACTION_FLAG_ROOT :
+					 MLX5_HW_ACTION_FLAG_NONE_ROOT;
+	for (; !actions_end; actions++) {
+		switch (actions->type) {
+		case RTE_FLOW_ACTION_TYPE_VOID:
+			break;
+		case RTE_FLOW_ACTION_TYPE_DROP:
+			hw_acts->rule_acts[actions_n++].action = priv->hw_drop[flag_type];
+			fate_type = MLX5_FLOW_FATE_DROP;
+			break;
+		case RTE_FLOW_ACTION_TYPE_FLAG:
+		case RTE_FLOW_ACTION_TYPE_MARK:
+			is_mark = actions->type == RTE_FLOW_ACTION_TYPE_MARK;
+			mark_id = is_mark ?
+				  ((const struct rte_flow_action_mark *)(actions->conf))->id :
+				  MLX5_FLOW_MARK_DEFAULT;
+			hw_acts->rule_acts[actions_n].tag.value = mlx5_flow_mark_set(mark_id);
+			hw_acts->rule_acts[actions_n].action = priv->hw_tag[flag_type];
+			actions_n++;
+			action_flags |= is_mark ? MLX5_FLOW_ACTION_MARK : MLX5_FLOW_ACTION_FLAG;
+			hw_acts->mark = true;
+			rte_atomic_fetch_add_explicit(&priv->hws_mark_refcnt, 1,
+						      rte_memory_order_relaxed);
+			flow_hw_rxq_flag_set(dev, true);
+			break;
+		case RTE_FLOW_ACTION_TYPE_JUMP:
+			jump_group = ((const struct rte_flow_action_jump *)actions->conf)->group;
+			tbl_cfg.attr.flow_attr = *attr;
+			tbl_cfg.external = external;
+			/* The flow_hw_jump_action_register() can be refactored. */
+			hw_acts->jump = flow_hw_jump_action_register(dev, &tbl_cfg,
+								     jump_group, error);
+			if (hw_acts->jump == NULL)
+				goto clean_up;
+			hw_acts->rule_acts[actions_n++].action =
+				(flag_type == MLX5_HW_ACTION_FLAG_NONE_ROOT) ?
+				hw_acts->jump->hws_action : hw_acts->jump->root_action;
+			action_flags |= MLX5_FLOW_ACTION_JUMP;
+			fate_type = MLX5_FLOW_FATE_JUMP;
+			break;
+		case RTE_FLOW_ACTION_TYPE_QUEUE:
+			/* Right now, only Rx supports the TIR, validation is needed. */
+			hw_acts->tir = flow_hw_tir_action_register(dev,
+						mlx5_hw_act_flag[flag_type][type], actions);
+			if (hw_acts->tir == NULL) {
+				rte_flow_error_set(error, EINVAL,
+						   RTE_FLOW_ERROR_TYPE_ACTION, NULL,
+						   "Failed to translate queue.");
+				goto clean_up;
+			}
+			action_flags |= MLX5_FLOW_ACTION_QUEUE;
+			fate_type = MLX5_FLOW_FATE_QUEUE;
+			break;
+		case RTE_FLOW_ACTION_TYPE_END:
+			/*
+			 * Using NULL action right now, maybe a new API can be used
+			 * to create a dummy action with type MLX5DR_ACTION_TYP_LAST.
+			 */
+			hw_acts->rule_acts[actions_n++].action = priv->sh->hw_dummy_last;
+			actions_end = true;
+			break;
+		default:
+			break;
+		}
+	}
+	if (fate_type == MLX5_FLOW_FATE_QUEUE) {
+		hw_acts->rule_acts[actions_n++].action = hw_acts->tir->action;
+		flow->hrxq = hw_acts->tir;
+	} else {
+		if (fate_type == MLX5_FLOW_FATE_JUMP)
+			flow->jump = hw_acts->jump;
+	}
+	/* Total actions number should be validated before. */
+	MLX5_ASSERT(actions_n <= MLX5_HW_MAX_ACTS);
 	return 0;
+clean_up:
+	/* Make sure that there is no garbage in the actions. */
+	__flow_hw_actions_release(dev, hw_acts);
+	return -rte_errno;
 }
 
 static int flow_hw_register_matcher(struct rte_eth_dev *dev,
@@ -12891,7 +13007,8 @@ static int flow_hw_create_flow(struct rte_eth_dev *dev,
 	if (ret)
 		goto error;
 
-	ret = flow_hw_translate_actions(dev, attr, actions, *flow, error);
+	/* Note: the actions should be saved in the sub-flow rule itself for reference. */
+	ret = flow_hw_translate_actions(dev, attr, actions, *flow, &hw_act, external, error);
 	if (ret)
 		goto error;
 
-- 
2.21.0


  parent reply	other threads:[~2024-06-09  8:56 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-02 10:28 [PATCH 01/11] net/mlx5: initial design of non template to hws Maayan Kashani
2024-06-03  8:04 ` [PATCH v2 05/34] " Maayan Kashani
2024-06-03  8:04   ` [PATCH v2 06/34] net/mlx5: add dummy last action Maayan Kashani
2024-06-03  8:04   ` [PATCH v2 07/34] net/mlx5: add basic actions support for non-template API Maayan Kashani
2024-06-03  8:04   ` [PATCH v2 08/34] net/mlx5: add default miss action support in nt2hws mode Maayan Kashani
2024-06-03  8:04   ` [PATCH v2 09/34] net/mlx5: add ASO actions support to non-template mode Maayan Kashani
2024-06-03  8:04   ` [PATCH v2 10/34] net/mlx5: fix segfault on counter pool destroy Maayan Kashani
2024-06-03  8:05   ` [PATCH v2 11/34] net/mlx5: abstract action handling and enable reconfigure Maayan Kashani
2024-06-03  8:05   ` [PATCH v2 12/34] common/mlx5: read connection tracking attributes Maayan Kashani
2024-06-03  8:05   ` [PATCH v2 13/34] net/mlx5: support bulk actions in non template mode Maayan Kashani
2024-06-03  8:05   ` [PATCH v2 14/34] net/mlx5: use non const max number for ASO actions Maayan Kashani
2024-06-03  8:05   ` [PATCH v2 15/34] net/mlx5: initial design changes Maayan Kashani
2024-06-03 10:48 ` [PATCH v3 01/11] net/mlx5: initial design of non template to hws Maayan Kashani
2024-06-03 10:48   ` [PATCH v3 02/11] net/mlx5: add dummy last action Maayan Kashani
2024-06-03 10:48   ` [PATCH v3 03/11] net/mlx5: add basic actions support for non-template API Maayan Kashani
2024-06-03 10:48   ` [PATCH v3 04/11] net/mlx5: add default miss action support in nt2hws mode Maayan Kashani
2024-06-03 10:48   ` [PATCH v3 05/11] net/mlx5: add ASO actions support to non-template mode Maayan Kashani
2024-06-03 10:48   ` [PATCH v3 06/11] net/mlx5: fix segfault on counter pool destroy Maayan Kashani
2024-06-03 10:48   ` [PATCH v3 07/11] net/mlx5: abstract action handling and enable reconfigure Maayan Kashani
2024-06-03 10:48   ` [PATCH v3 08/11] common/mlx5: read connection tracking attributes Maayan Kashani
2024-06-03 10:48   ` [PATCH v3 09/11] net/mlx5: support bulk actions in non template mode Maayan Kashani
2024-06-03 10:48   ` [PATCH v3 10/11] net/mlx5: use non const max number for ASO actions Maayan Kashani
2024-06-03 10:48   ` [PATCH v3 11/11] net/mlx5: initial design changes Maayan Kashani
2024-06-06 10:23   ` [PATCH v4 00/11] non-template pmd basic func Maayan Kashani
2024-06-06 10:23     ` [PATCH v4 01/11] net/mlx5: initial design of non template to hws Maayan Kashani
2024-06-06 10:23     ` [PATCH v4 02/11] net/mlx5: add dummy last action Maayan Kashani
2024-06-06 10:23     ` [PATCH v4 03/11] net/mlx5: add basic actions support for non-template API Maayan Kashani
2024-06-06 10:23     ` [PATCH v4 04/11] net/mlx5: add default miss action support in nt2hws mode Maayan Kashani
2024-06-06 10:23     ` [PATCH v4 05/11] net/mlx5: add ASO actions support to non-template mode Maayan Kashani
2024-06-06 10:23     ` [PATCH v4 06/11] net/mlx5: fix segfault on counter pool destroy Maayan Kashani
2024-06-06 10:23     ` [PATCH v4 07/11] net/mlx5: abstract action handling and enable reconfigure Maayan Kashani
2024-06-06 10:23     ` [PATCH v4 08/11] common/mlx5: read connection tracking attributes Maayan Kashani
2024-06-06 10:23     ` [PATCH v4 09/11] net/mlx5: support bulk actions in non template mode Maayan Kashani
2024-06-06 10:23     ` [PATCH v4 10/11] net/mlx5: use non const max number for ASO actions Maayan Kashani
2024-06-06 10:23     ` [PATCH v4 11/11] net/mlx5: initial design changes Maayan Kashani
2024-06-06 12:32     ` [PATCH v5 01/11] net/mlx5: initial design of non template to hws Maayan Kashani
2024-06-06 12:32       ` [PATCH v5 02/11] net/mlx5: add dummy last action Maayan Kashani
2024-06-06 12:32       ` [PATCH v5 03/11] net/mlx5: add basic actions support for non-template API Maayan Kashani
2024-06-06 12:32       ` [PATCH v5 04/11] net/mlx5: add default miss action support in nt2hws mode Maayan Kashani
2024-06-06 12:32       ` [PATCH v5 05/11] net/mlx5: add ASO actions support to non-template mode Maayan Kashani
2024-06-06 12:32       ` [PATCH v5 06/11] net/mlx5: fix segfault on counter pool destroy Maayan Kashani
2024-06-06 12:32       ` [PATCH v5 07/11] net/mlx5: abstract action handling and enable reconfigure Maayan Kashani
2024-06-06 12:32       ` [PATCH v5 08/11] common/mlx5: read connection tracking attributes Maayan Kashani
2024-06-06 12:32       ` [PATCH v5 09/11] net/mlx5: support bulk actions in non template mode Maayan Kashani
2024-06-06 12:32       ` [PATCH v5 10/11] net/mlx5: use non const max number for ASO actions Maayan Kashani
2024-06-06 12:32       ` [PATCH v5 11/11] net/mlx5: initial design changes Maayan Kashani
2024-06-09  8:55       ` [PATCH v6 01/11] net/mlx5: initial design of non template to hws Maayan Kashani
2024-06-09  8:55         ` [PATCH v6 02/11] net/mlx5: add dummy last action Maayan Kashani
2024-06-09  8:55         ` Maayan Kashani [this message]
2024-06-09  8:55         ` [PATCH v6 04/11] net/mlx5: add default miss action support in nt2hws mode Maayan Kashani
2024-06-09  8:55         ` [PATCH v6 05/11] net/mlx5: add ASO actions support to non-template mode Maayan Kashani
2024-06-09  8:55         ` [PATCH v6 06/11] net/mlx5: fix segfault on counter pool destroy Maayan Kashani
2024-06-09  8:55         ` [PATCH v6 07/11] net/mlx5: abstract action handling and enable reconfigure Maayan Kashani
2024-06-09  8:55         ` [PATCH v6 08/11] common/mlx5: read connection tracking attributes Maayan Kashani
2024-06-09  8:55         ` [PATCH v6 09/11] net/mlx5: support bulk actions in non template mode Maayan Kashani
2024-06-09  8:55         ` [PATCH v6 10/11] net/mlx5: use non const max number for ASO actions Maayan Kashani
2024-06-09  8:56         ` [PATCH v6 11/11] net/mlx5: initial design changes Maayan Kashani
2024-06-09 11:00         ` [PATCH v7 01/11] net/mlx5: initial design of non template to hws Maayan Kashani
2024-06-09 11:00           ` [PATCH v7 02/11] net/mlx5: add dummy last action Maayan Kashani
2024-06-09 11:00           ` [PATCH v7 03/11] net/mlx5: add basic actions support for non-template API Maayan Kashani
2024-06-09 11:01           ` [PATCH v7 04/11] net/mlx5: add default miss action support in nt2hws mode Maayan Kashani
2024-06-09 11:01           ` [PATCH v7 05/11] net/mlx5: add ASO actions support to non-template mode Maayan Kashani
2024-06-09 11:01           ` [PATCH v7 06/11] net/mlx5: fix segfault on counter pool destroy Maayan Kashani
2024-06-09 11:01           ` [PATCH v7 07/11] net/mlx5: abstract action handling and enable reconfigure Maayan Kashani
2024-06-09 11:01           ` [PATCH v7 08/11] common/mlx5: read connection tracking attributes Maayan Kashani
2024-06-09 11:01           ` [PATCH v7 09/11] net/mlx5: support bulk actions in non template mode Maayan Kashani
2024-06-09 11:01           ` [PATCH v7 10/11] net/mlx5: use non const max number for ASO actions Maayan Kashani
2024-06-09 11:01           ` [PATCH v7 11/11] net/mlx5: initial design changes Maayan Kashani
2024-06-10  8:34           ` [PATCH v7 01/11] net/mlx5: initial design of non template to hws Raslan Darawsheh

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20240609085600.87274-3-mkashani@nvidia.com \
    --to=mkashani@nvidia.com \
    --cc=bingz@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=dsosnowski@nvidia.com \
    --cc=matan@nvidia.com \
    --cc=orika@nvidia.com \
    --cc=rasland@nvidia.com \
    --cc=suanmingm@nvidia.com \
    --cc=viacheslavo@nvidia.com \
    /path/to/YOUR_REPLY

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

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