[v3,1/8] net/mlx5: extract target port validation

Message ID 20240626181428.1678402-2-dsosnowski@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: Raslan Darawsheh
Headers
Series net/mlx5: flow fast path validation |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Dariusz Sosnowski June 26, 2024, 6:14 p.m. UTC
Extract code responsible for validation if port specified in
configuration of RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT action
is correct. Allow for reuse of this logic for both
RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT actions and
RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT items.

Signed-off-by: Dariusz Sosnowski <dsosnowski@nvidia.com>
Acked-by: Ori Kam <orika@nvidia.com>
---
 drivers/net/mlx5/mlx5_flow_hw.c | 63 +++++++++++++++++++++------------
 1 file changed, 40 insertions(+), 23 deletions(-)
  

Patch

diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c
index b8d71b145d..c0d763198d 100644
--- a/drivers/net/mlx5/mlx5_flow_hw.c
+++ b/drivers/net/mlx5/mlx5_flow_hw.c
@@ -6051,6 +6051,42 @@  flow_hw_validate_action_port_representor(struct rte_eth_dev *dev __rte_unused,
 	return 0;
 }
 
+static int
+flow_hw_validate_target_port_id(struct rte_eth_dev *dev,
+				uint16_t target_port_id)
+{
+	struct mlx5_priv *port_priv;
+	struct mlx5_priv *dev_priv;
+
+	if (target_port_id == MLX5_REPRESENTED_PORT_ESW_MGR)
+		return 0;
+
+	port_priv = mlx5_port_to_eswitch_info(target_port_id, false);
+	if (!port_priv) {
+		rte_errno = EINVAL;
+		DRV_LOG(ERR, "Port %u Failed to obtain E-Switch info for port %u",
+			dev->data->port_id, target_port_id);
+		return -rte_errno;
+	}
+
+	dev_priv = mlx5_dev_to_eswitch_info(dev);
+	if (!dev_priv) {
+		rte_errno = EINVAL;
+		DRV_LOG(ERR, "Port %u Failed to obtain E-Switch info for transfer proxy",
+			dev->data->port_id);
+		return -rte_errno;
+	}
+
+	if (port_priv->domain_id != dev_priv->domain_id) {
+		rte_errno = EINVAL;
+		DRV_LOG(ERR, "Port %u Failed to obtain E-Switch info for transfer proxy",
+			dev->data->port_id);
+		return -rte_errno;
+	}
+
+	return 0;
+}
+
 static int
 flow_hw_validate_action_represented_port(struct rte_eth_dev *dev,
 					 const struct rte_flow_action *action,
@@ -6067,32 +6103,13 @@  flow_hw_validate_action_represented_port(struct rte_eth_dev *dev,
 					  "cannot use represented_port actions"
 					  " without an E-Switch");
 	if (mask_conf && mask_conf->port_id) {
-		struct mlx5_priv *port_priv;
-		struct mlx5_priv *dev_priv;
-
 		if (!action_conf)
 			return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
 						  action, "port index was not provided");
-		port_priv = mlx5_port_to_eswitch_info(action_conf->port_id, false);
-		if (!port_priv)
-			return rte_flow_error_set(error, rte_errno,
-						  RTE_FLOW_ERROR_TYPE_ACTION,
-						  action,
-						  "failed to obtain E-Switch"
-						  " info for port");
-		dev_priv = mlx5_dev_to_eswitch_info(dev);
-		if (!dev_priv)
-			return rte_flow_error_set(error, rte_errno,
-						  RTE_FLOW_ERROR_TYPE_ACTION,
-						  action,
-						  "failed to obtain E-Switch"
-						  " info for transfer proxy");
-		if (port_priv->domain_id != dev_priv->domain_id)
-			return rte_flow_error_set(error, rte_errno,
-						  RTE_FLOW_ERROR_TYPE_ACTION,
-						  action,
-						  "cannot forward to port from"
-						  " a different E-Switch");
+
+		if (flow_hw_validate_target_port_id(dev, action_conf->port_id))
+			return rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
+						  action, "port index is invalid");
 	}
 	return 0;
 }