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>
This commit is contained in:
Shun Hao 2022-11-08 10:50:34 +02:00 committed by Raslan Darawsheh
parent 5615d27b7a
commit 35f482afa2
2 changed files with 38 additions and 20 deletions

View File

@ -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)
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) {
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.");
}
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.");

View File

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