DPDK patches and discussions
 help / color / mirror / Atom feed
From: Shun Hao <shunh@nvidia.com>
To: <viacheslavo@nvidia.com>, <matan@nvidia.com>, <orika@nvidia.com>,
	"Sean Zhang" <xiazhang@nvidia.com>
Cc: <dev@dpdk.org>, <rasland@nvidia.com>, <stable@dpdk.org>
Subject: [PATCH v1] net/mlx5: fix representor item and meter
Date: Tue, 8 Nov 2022 10:50:34 +0200	[thread overview]
Message-ID: <20221108085034.872530-1-shunh@nvidia.com> (raw)

When creating flow matching port representor item with meter action, it
will fail due to incorrect parsing the item.

This patch fixes this issue by adding the correct item parse for port
representor in validation.

Fixes: 707d5e7d79 ("net/mlx5: support flow matching on representor ID")
Cc: stable@dpdk.org

Signed-off-by: Shun Hao <shunh@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 drivers/net/mlx5/mlx5_flow.c    | 50 ++++++++++++++++++++-------------
 drivers/net/mlx5/mlx5_flow_dv.c |  6 ++++
 2 files changed, 37 insertions(+), 19 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index ea88882b88..f67bfce515 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -5469,6 +5469,7 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 		switch (item_type) {
 		case RTE_FLOW_ITEM_TYPE_PORT_ID:
 		case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
+		case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
 			if (mlx5_flow_get_item_vport_id(dev, items, &flow_src_port, NULL, error))
 				return -rte_errno;
 			if (!fm->def_policy && wks->policy->is_hierarchy &&
@@ -5483,11 +5484,6 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 			memcpy(sfx_items, items, sizeof(*sfx_items));
 			sfx_items++;
 			break;
-		case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
-			flow_src_port = 0;
-			memcpy(sfx_items, items, sizeof(*sfx_items));
-			sfx_items++;
-			break;
 		case RTE_FLOW_ITEM_TYPE_VLAN:
 			/* Determine if copy vlan item below. */
 			vlan_item_src = items;
@@ -11402,27 +11398,43 @@ int mlx5_flow_get_item_vport_id(struct rte_eth_dev *dev,
 				struct rte_flow_error *error)
 {
 	struct mlx5_priv *port_priv;
-	const struct rte_flow_item_port_id *pid_v;
+	const struct rte_flow_item_port_id *pid_v = NULL;
+	const struct rte_flow_item_ethdev *dev_v = NULL;
 	uint32_t esw_mgr_port;
+	uint32_t src_port;
 
-	if (item->type != RTE_FLOW_ITEM_TYPE_PORT_ID &&
-	    item->type != RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT)
+	if (all_ports)
+		*all_ports = false;
+	switch (item->type) {
+	case RTE_FLOW_ITEM_TYPE_PORT_ID:
+		pid_v = item->spec;
+		if (!pid_v)
+			return 0;
+		src_port = pid_v->id;
+		esw_mgr_port = MLX5_PORT_ESW_MGR;
+		break;
+	case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
+		dev_v = item->spec;
+		if (!dev_v) {
+			if (all_ports)
+				*all_ports = true;
+			return 0;
+		}
+		src_port = dev_v->port_id;
+		esw_mgr_port = MLX5_REPRESENTED_PORT_ESW_MGR;
+		break;
+	case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
+		src_port = MLX5_REPRESENTED_PORT_ESW_MGR;
+		esw_mgr_port = MLX5_REPRESENTED_PORT_ESW_MGR;
+		break;
+	default:
 		return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
 					  NULL, "Incorrect item type.");
-	pid_v = item->spec;
-	if (!pid_v) {
-		if (all_ports)
-			*all_ports = (item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT);
-		return 0;
 	}
-	if (all_ports)
-		*all_ports = false;
-	esw_mgr_port = (item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT) ?
-				MLX5_REPRESENTED_PORT_ESW_MGR : MLX5_PORT_ESW_MGR;
-	if (pid_v->id == esw_mgr_port) {
+	if (src_port == esw_mgr_port) {
 		*vport_id = mlx5_flow_get_esw_manager_vport_id(dev);
 	} else {
-		port_priv = mlx5_port_to_eswitch_info(pid_v->id, false);
+		port_priv = mlx5_port_to_eswitch_info(src_port, false);
 		if (!port_priv)
 			return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
 						  NULL, "Failed to get port info.");
diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index acd7ea8b79..6ce87e310b 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -17056,6 +17056,9 @@ __flow_dv_create_policy_flow(struct rte_eth_dev *dev,
 		if (item && item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT)
 			ret = flow_dv_translate_item_represented_port(dev, value.buf,
 						item, attr, MLX5_SET_MATCHER_SW_V);
+		else if (item && item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR)
+			ret = flow_dv_translate_item_port_representor(dev, value.buf,
+								      MLX5_SET_MATCHER_SW_V);
 		else
 			ret = flow_dv_translate_item_port_id(dev, value.buf,
 						item, attr, MLX5_SET_MATCHER_SW_V);
@@ -17110,6 +17113,9 @@ __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
 		if (item && item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT)
 			ret = flow_dv_translate_item_represented_port(dev, matcher.mask.buf,
 						item, attr, MLX5_SET_MATCHER_SW_M);
+		else if (item && item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR)
+			ret = flow_dv_translate_item_port_representor(dev, matcher.mask.buf,
+								      MLX5_SET_MATCHER_SW_M);
 		else
 			ret = flow_dv_translate_item_port_id(dev, matcher.mask.buf,
 						item, attr, MLX5_SET_MATCHER_SW_M);
-- 
2.20.0


             reply	other threads:[~2022-11-08  8:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-08  8:50 Shun Hao [this message]
2022-11-08 17:36 ` 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=20221108085034.872530-1-shunh@nvidia.com \
    --to=shunh@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=matan@nvidia.com \
    --cc=orika@nvidia.com \
    --cc=rasland@nvidia.com \
    --cc=stable@dpdk.org \
    --cc=viacheslavo@nvidia.com \
    --cc=xiazhang@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).