DPDK patches and discussions
 help / color / mirror / Atom feed
From: Itamar Gozlan <igozlan@nvidia.com>
To: <igozlan@nvidia.com>, <erezsh@nvidia.com>, <hamdani@nvidia.com>,
	<kliteyn@nvidia.com>, <valex@nvidia.com>,
	<viacheslavo@nvidia.com>, <thomas@monjalon.net>,
	Dariusz Sosnowski <dsosnowski@nvidia.com>,
	Ori Kam <orika@nvidia.com>, Suanming Mou <suanmingm@nvidia.com>,
	Matan Azrad <matan@nvidia.com>
Cc: <dev@dpdk.org>, <mkashani@nvidia.com>
Subject: [PATCH 13/13] net/mlx5/hws: fix port ID for root matcher and rule
Date: Thu, 14 Mar 2024 13:42:20 +0200	[thread overview]
Message-ID: <20240314114220.203241-13-igozlan@nvidia.com> (raw)
In-Reply-To: <20240314114220.203241-1-igozlan@nvidia.com>

From: Erez Shitrit <erezsh@nvidia.com>

In root tables matcher and rule need to have their port-id, otherwise
the translate function that done in dpdk layer will not get the right
attributes.
For that whenever the matcher is matching the source-port we need to get
the relevant port-id before calling the translate function.

Fixes: 405242c52dd5 ("net/mlx5/hws: add rule object")
Signed-off-by: Erez Shitrit <erezsh@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 drivers/net/mlx5/hws/mlx5dr_matcher.c | 17 +++++++++++++++++
 drivers/net/mlx5/hws/mlx5dr_rule.c    | 18 ++++++++++++++++++
 drivers/net/mlx5/mlx5_flow.h          | 18 ++++++++++++++++++
 3 files changed, 53 insertions(+)

diff --git a/drivers/net/mlx5/hws/mlx5dr_matcher.c b/drivers/net/mlx5/hws/mlx5dr_matcher.c
index 78d525e578..394244b55b 100644
--- a/drivers/net/mlx5/hws/mlx5dr_matcher.c
+++ b/drivers/net/mlx5/hws/mlx5dr_matcher.c
@@ -1227,6 +1227,7 @@ static int mlx5dr_matcher_init_root(struct mlx5dr_matcher *matcher)
 	struct mlx5dv_flow_match_parameters *mask;
 	struct mlx5_flow_attr flow_attr = {0};
 	struct rte_flow_error rte_error;
+	struct rte_flow_item *item;
 	uint8_t match_criteria;
 	int ret;
 
@@ -1255,6 +1256,22 @@ static int mlx5dr_matcher_init_root(struct mlx5dr_matcher *matcher)
 		return rte_errno;
 	}
 
+	/* We need the port id in case of matching representor */
+	item = matcher->mt[0].items;
+	while (item->type != RTE_FLOW_ITEM_TYPE_END) {
+		if (item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR ||
+		    item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT) {
+			ret = flow_hw_get_port_id_from_ctx(ctx, &flow_attr.port_id);
+			if (ret) {
+				DR_LOG(ERR, "Failed to get port id for dev %s",
+				       ctx->ibv_ctx->device->name);
+				rte_errno = EINVAL;
+				return rte_errno;
+			}
+		}
+		++item;
+	}
+
 	mask = simple_calloc(1, MLX5_ST_SZ_BYTES(fte_match_param) +
 			     offsetof(struct mlx5dv_flow_match_parameters, match_buf));
 	if (!mask) {
diff --git a/drivers/net/mlx5/hws/mlx5dr_rule.c b/drivers/net/mlx5/hws/mlx5dr_rule.c
index d56677a1a5..5dae4f3442 100644
--- a/drivers/net/mlx5/hws/mlx5dr_rule.c
+++ b/drivers/net/mlx5/hws/mlx5dr_rule.c
@@ -692,10 +692,28 @@ static int mlx5dr_rule_create_root(struct mlx5dr_rule *rule,
 	struct mlx5dv_flow_match_parameters *value;
 	struct mlx5_flow_attr flow_attr = {0};
 	struct mlx5dv_flow_action_attr *attr;
+	const struct rte_flow_item *cur_item;
 	struct rte_flow_error error;
 	uint8_t match_criteria;
 	int ret;
 
+	/* We need the port id in case of matching representor */
+	cur_item = items;
+	while (cur_item->type != RTE_FLOW_ITEM_TYPE_END) {
+		if (cur_item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR ||
+		    cur_item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT) {
+			ret = flow_hw_get_port_id_from_ctx(rule->matcher->tbl->ctx,
+							   &flow_attr.port_id);
+			if (ret) {
+				DR_LOG(ERR, "Failed to get port id for dev %s",
+				       rule->matcher->tbl->ctx->ibv_ctx->device->name);
+				rte_errno = EINVAL;
+				return rte_errno;
+			}
+		}
+		++cur_item;
+	}
+
 	attr = simple_calloc(num_actions, sizeof(*attr));
 	if (!attr) {
 		rte_errno = ENOMEM;
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index 34b5e0f45b..e435a686fd 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -2001,6 +2001,24 @@ flow_hw_get_reg_id(struct rte_eth_dev *dev,
 #endif
 }
 
+static __rte_always_inline int
+flow_hw_get_port_id_from_ctx(void *dr_ctx, uint32_t *port_val)
+{
+	uint32_t port;
+
+	MLX5_ETH_FOREACH_DEV(port, NULL) {
+		struct mlx5_priv *priv;
+		priv = rte_eth_devices[port].data->dev_private;
+
+		if (priv->dr_ctx == dr_ctx) {
+			*port_val = port;
+			return 0;
+		}
+	}
+
+	return -EINVAL;
+}
+
 /**
  * Get GENEVE TLV option FW information according type and class.
  *
-- 
2.39.3


  parent reply	other threads:[~2024-03-14 11:44 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-14 11:42 [PATCH 01/13] net/mlx5/hws: move warn into debug level when needed Itamar Gozlan
2024-03-14 11:42 ` [PATCH 02/13] common/mlx5: fix error in mlx5 prm structs Itamar Gozlan
2024-03-14 11:42 ` [PATCH 03/13] net/mlx5/hws: fix wrong comment in mlx5dr_send Itamar Gozlan
2024-03-14 11:42 ` [PATCH 04/13] net/mlx5/hws: remove unused capabilities and fields Itamar Gozlan
2024-03-14 11:42 ` [PATCH 05/13] net/mlx5/hws: return -rte_errno on rule creation failure Itamar Gozlan
2024-03-14 11:42 ` [PATCH 06/13] net/mlx5/hws: simplify send_queues_close code Itamar Gozlan
2024-03-14 11:42 ` [PATCH 07/13] net/mlx5/hws: fix error flow in mlx5dr_context_open Itamar Gozlan
2024-03-14 11:42 ` [PATCH 08/13] net/mlx5/hws: fix code analysis error in passing 0 enum val Itamar Gozlan
2024-03-14 11:42 ` [PATCH 09/13] net/mlx5/hws: simplify code for updating CQ doorbell record Itamar Gozlan
2024-03-14 11:42 ` [PATCH 10/13] net/mlx5/hws: fix rule is in resize check Itamar Gozlan
2024-03-14 11:42 ` [PATCH 11/13] net/mlx5/hws: drop at attach number of actions Itamar Gozlan
2024-03-14 11:42 ` [PATCH 12/13] net/mlx5/hws: extending tag saving for match and jumbo Itamar Gozlan
2024-03-14 11:42 ` Itamar Gozlan [this message]
2024-03-18 12:56 ` [PATCH 01/13] net/mlx5/hws: move warn into debug level when needed Raslan Darawsheh
2024-03-18 14:48   ` Thomas Monjalon
2024-03-19  7:33     ` Raslan Darawsheh
2024-03-20 16:35       ` Yevgeny Kliteynik
2024-05-06 11:44 ` [v2 01/16] " Itamar Gozlan
2024-05-06 11:44   ` [v2 02/16] common/mlx5: fix error in mlx5 prm structs Itamar Gozlan
2024-05-06 11:44   ` [v2 03/16] net/mlx5/hws: fix wrong comment in mlx5dr send Itamar Gozlan
2024-05-06 11:44   ` [v2 04/16] net/mlx5/hws: remove unused capabilities and fields Itamar Gozlan
2024-05-06 11:44   ` [v2 05/16] net/mlx5/hws: negating rte errno on rule creation failure Itamar Gozlan
2024-05-06 11:44   ` [v2 06/16] net/mlx5/hws: simplify send queues close code Itamar Gozlan
2024-05-06 11:44   ` [v2 07/16] net/mlx5/hws: fix error flow in mlx5dr context open Itamar Gozlan
2024-05-06 11:44   ` [v2 08/16] net/mlx5/hws: fix code analysis error in passing 0 enum val Itamar Gozlan
2024-05-06 11:44   ` [v2 09/16] net/mlx5/hws: simplify code for updating CQ doorbell record Itamar Gozlan
2024-05-06 11:44   ` [v2 10/16] net/mlx5/hws: drop at attach number of actions Itamar Gozlan
2024-05-06 11:44   ` [v2 11/16] net/mlx5/hws: extending tag saving for match and jumbo Itamar Gozlan
2024-05-06 11:44   ` [v2 12/16] net/mlx5/hws: dw order optimization code enhancement Itamar Gozlan
2024-05-06 11:44   ` [v2 13/16] net/mlx5/hws: set default miss when replacing table Itamar Gozlan
2024-05-06 11:44   ` [v2 14/16] net/mlx5/hws: fix invalid memory access in decapl3 Itamar Gozlan
2024-05-06 11:44   ` [v2 15/16] net/mlx5/hws: dump action ste arrays info Itamar Gozlan
2024-05-06 11:44   ` [v2 16/16] net/mlx5/hws: fix action template only term param dump print Itamar Gozlan
2024-05-20 10:50   ` [v2 01/16] net/mlx5/hws: move warn into debug level when needed 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=20240314114220.203241-13-igozlan@nvidia.com \
    --to=igozlan@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=dsosnowski@nvidia.com \
    --cc=erezsh@nvidia.com \
    --cc=hamdani@nvidia.com \
    --cc=kliteyn@nvidia.com \
    --cc=matan@nvidia.com \
    --cc=mkashani@nvidia.com \
    --cc=orika@nvidia.com \
    --cc=suanmingm@nvidia.com \
    --cc=thomas@monjalon.net \
    --cc=valex@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).