[v1] net/mlx5: fix representor item and meter

Message ID 20221108085034.872530-1-shunh@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: Raslan Darawsheh
Headers
Series [v1] net/mlx5: fix representor item and meter |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance fail Performance Testing issues

Commit Message

Shun Hao Nov. 8, 2022, 8:50 a.m. UTC
  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(-)
  

Comments

Raslan Darawsheh Nov. 8, 2022, 5:36 p.m. UTC | #1
Hi,

> -----Original Message-----
> From: Shun Hao <shunh@nvidia.com>
> Sent: Tuesday, November 8, 2022 10:51 AM
> To: Slava Ovsiienko <viacheslavo@nvidia.com>; Matan Azrad
> <matan@nvidia.com>; Ori Kam <orika@nvidia.com>; Sean Zhang
> (Networking SW) <xiazhang@nvidia.com>
> Cc: dev@dpdk.org; Raslan Darawsheh <rasland@nvidia.com>;
> stable@dpdk.org
> Subject: [PATCH v1] net/mlx5: fix representor item and meter
> 
Small change to the commit title:
net/mlx5: fix representor item with meter

> 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>

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh
  

Patch

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);