Skip to content

Commit 87cd064

Browse files
kliteynSaeed Mahameed
authored andcommitted
net/mlx5: DR, Support SW created encap actions for FW table
In some cases, steering might need to use SW-created action in FW table, which results in wrong packet reformat being used: mlx5_core 0000:81:00.1: mlx5_cmd_check:756:(pid 1154): SET_FLOW_TABLE_ENTRY(0×936) op_mod(0×0) failed, status bad resource(0×5), syndrome (0xf2ff71) This patch adds support for usage of SW-created packet reformat (encap) actions in FW tables, and adds clear error flow for attempt to use SW-created modify header on FW tables. Fixes: 6a48fae ("net/mlx5: Add direct rule fs_cmd implementation") Signed-off-by: Yevgeny Kliteynik <kliteyn@nvidia.com> Reviewed-by: Erez Shitrit <erezsh@nvidia.com> Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
1 parent fb7be47 commit 87cd064

File tree

6 files changed

+83
-15
lines changed

6 files changed

+83
-15
lines changed

drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,11 @@ static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev,
511511
struct mlx5_flow_rule *dst;
512512
void *in_flow_context, *vlan;
513513
void *in_match_value;
514+
int reformat_id = 0;
514515
unsigned int inlen;
515516
int dst_cnt_size;
517+
u32 *in, action;
516518
void *in_dests;
517-
u32 *in;
518519
int err;
519520

520521
if (mlx5_set_extended_dest(dev, fte, &extended_dest))
@@ -553,22 +554,42 @@ static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev,
553554

554555
MLX5_SET(flow_context, in_flow_context, extended_destination,
555556
extended_dest);
556-
if (extended_dest) {
557-
u32 action;
558557

559-
action = fte->action.action &
560-
~MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT;
561-
MLX5_SET(flow_context, in_flow_context, action, action);
562-
} else {
563-
MLX5_SET(flow_context, in_flow_context, action,
564-
fte->action.action);
565-
if (fte->action.pkt_reformat)
566-
MLX5_SET(flow_context, in_flow_context, packet_reformat_id,
567-
fte->action.pkt_reformat->id);
558+
action = fte->action.action;
559+
if (extended_dest)
560+
action &= ~MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT;
561+
562+
MLX5_SET(flow_context, in_flow_context, action, action);
563+
564+
if (!extended_dest && fte->action.pkt_reformat) {
565+
struct mlx5_pkt_reformat *pkt_reformat = fte->action.pkt_reformat;
566+
567+
if (pkt_reformat->owner == MLX5_FLOW_RESOURCE_OWNER_SW) {
568+
reformat_id = mlx5_fs_dr_action_get_pkt_reformat_id(pkt_reformat);
569+
if (reformat_id < 0) {
570+
mlx5_core_err(dev,
571+
"Unsupported SW-owned pkt_reformat type (%d) in FW-owned table\n",
572+
pkt_reformat->reformat_type);
573+
err = reformat_id;
574+
goto err_out;
575+
}
576+
} else {
577+
reformat_id = fte->action.pkt_reformat->id;
578+
}
568579
}
569-
if (fte->action.modify_hdr)
580+
581+
MLX5_SET(flow_context, in_flow_context, packet_reformat_id, (u32)reformat_id);
582+
583+
if (fte->action.modify_hdr) {
584+
if (fte->action.modify_hdr->owner == MLX5_FLOW_RESOURCE_OWNER_SW) {
585+
mlx5_core_err(dev, "Can't use SW-owned modify_hdr in FW-owned table\n");
586+
err = -EOPNOTSUPP;
587+
goto err_out;
588+
}
589+
570590
MLX5_SET(flow_context, in_flow_context, modify_header_id,
571591
fte->action.modify_hdr->id);
592+
}
572593

573594
MLX5_SET(flow_context, in_flow_context, encrypt_decrypt_type,
574595
fte->action.crypto.type);
@@ -885,6 +906,8 @@ static int mlx5_cmd_packet_reformat_alloc(struct mlx5_flow_root_namespace *ns,
885906

886907
pkt_reformat->id = MLX5_GET(alloc_packet_reformat_context_out,
887908
out, packet_reformat_id);
909+
pkt_reformat->owner = MLX5_FLOW_RESOURCE_OWNER_FW;
910+
888911
kfree(in);
889912
return err;
890913
}
@@ -969,6 +992,7 @@ static int mlx5_cmd_modify_header_alloc(struct mlx5_flow_root_namespace *ns,
969992
err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
970993

971994
modify_hdr->id = MLX5_GET(alloc_modify_header_context_out, out, modify_header_id);
995+
modify_hdr->owner = MLX5_FLOW_RESOURCE_OWNER_FW;
972996
kfree(in);
973997
return err;
974998
}

drivers/net/ethernet/mellanox/mlx5/core/fs_core.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,14 @@ struct mlx5_flow_definer {
5454
u32 id;
5555
};
5656

57+
enum mlx5_flow_resource_owner {
58+
MLX5_FLOW_RESOURCE_OWNER_FW,
59+
MLX5_FLOW_RESOURCE_OWNER_SW,
60+
};
61+
5762
struct mlx5_modify_hdr {
5863
enum mlx5_flow_namespace_type ns_type;
64+
enum mlx5_flow_resource_owner owner;
5965
union {
6066
struct mlx5_fs_dr_action action;
6167
u32 id;
@@ -65,6 +71,7 @@ struct mlx5_modify_hdr {
6571
struct mlx5_pkt_reformat {
6672
enum mlx5_flow_namespace_type ns_type;
6773
int reformat_type; /* from mlx5_ifc */
74+
enum mlx5_flow_resource_owner owner;
6875
union {
6976
struct mlx5_fs_dr_action action;
7077
u32 id;

drivers/net/ethernet/mellanox/mlx5/core/steering/dr_action.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,6 +2129,11 @@ mlx5dr_action_create_aso(struct mlx5dr_domain *dmn, u32 obj_id,
21292129
return action;
21302130
}
21312131

2132+
u32 mlx5dr_action_get_pkt_reformat_id(struct mlx5dr_action *action)
2133+
{
2134+
return action->reformat->id;
2135+
}
2136+
21322137
int mlx5dr_action_destroy(struct mlx5dr_action *action)
21332138
{
21342139
if (WARN_ON_ONCE(refcount_read(&action->refcount) > 1))

drivers/net/ethernet/mellanox/mlx5/core/steering/fs_dr.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,16 @@ static int mlx5_cmd_dr_create_fte(struct mlx5_flow_root_namespace *ns,
331331
}
332332

333333
if (fte->action.action & MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT) {
334-
bool is_decap = fte->action.pkt_reformat->reformat_type ==
335-
MLX5_REFORMAT_TYPE_L3_TUNNEL_TO_L2;
334+
bool is_decap;
335+
336+
if (fte->action.pkt_reformat->owner == MLX5_FLOW_RESOURCE_OWNER_FW) {
337+
err = -EINVAL;
338+
mlx5dr_err(domain, "FW-owned reformat can't be used in SW rule\n");
339+
goto free_actions;
340+
}
341+
342+
is_decap = fte->action.pkt_reformat->reformat_type ==
343+
MLX5_REFORMAT_TYPE_L3_TUNNEL_TO_L2;
336344

337345
if (is_decap)
338346
actions[num_actions++] =
@@ -661,6 +669,7 @@ static int mlx5_cmd_dr_packet_reformat_alloc(struct mlx5_flow_root_namespace *ns
661669
return -EINVAL;
662670
}
663671

672+
pkt_reformat->owner = MLX5_FLOW_RESOURCE_OWNER_SW;
664673
pkt_reformat->action.dr_action = action;
665674

666675
return 0;
@@ -691,6 +700,7 @@ static int mlx5_cmd_dr_modify_header_alloc(struct mlx5_flow_root_namespace *ns,
691700
return -EINVAL;
692701
}
693702

703+
modify_hdr->owner = MLX5_FLOW_RESOURCE_OWNER_SW;
694704
modify_hdr->action.dr_action = action;
695705

696706
return 0;
@@ -816,6 +826,19 @@ static u32 mlx5_cmd_dr_get_capabilities(struct mlx5_flow_root_namespace *ns,
816826
return steering_caps;
817827
}
818828

829+
int mlx5_fs_dr_action_get_pkt_reformat_id(struct mlx5_pkt_reformat *pkt_reformat)
830+
{
831+
switch (pkt_reformat->reformat_type) {
832+
case MLX5_REFORMAT_TYPE_L2_TO_VXLAN:
833+
case MLX5_REFORMAT_TYPE_L2_TO_NVGRE:
834+
case MLX5_REFORMAT_TYPE_L2_TO_L2_TUNNEL:
835+
case MLX5_REFORMAT_TYPE_L2_TO_L3_TUNNEL:
836+
case MLX5_REFORMAT_TYPE_INSERT_HDR:
837+
return mlx5dr_action_get_pkt_reformat_id(pkt_reformat->action.dr_action);
838+
}
839+
return -EOPNOTSUPP;
840+
}
841+
819842
bool mlx5_fs_dr_is_supported(struct mlx5_core_dev *dev)
820843
{
821844
return mlx5dr_is_supported(dev);

drivers/net/ethernet/mellanox/mlx5/core/steering/fs_dr.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ struct mlx5_fs_dr_table {
3838

3939
bool mlx5_fs_dr_is_supported(struct mlx5_core_dev *dev);
4040

41+
int mlx5_fs_dr_action_get_pkt_reformat_id(struct mlx5_pkt_reformat *pkt_reformat);
42+
4143
const struct mlx5_flow_cmds *mlx5_fs_cmd_get_dr_cmds(void);
4244

4345
#else
@@ -47,6 +49,11 @@ static inline const struct mlx5_flow_cmds *mlx5_fs_cmd_get_dr_cmds(void)
4749
return NULL;
4850
}
4951

52+
static inline u32 mlx5_fs_dr_action_get_pkt_reformat_id(struct mlx5_pkt_reformat *pkt_reformat)
53+
{
54+
return 0;
55+
}
56+
5057
static inline bool mlx5_fs_dr_is_supported(struct mlx5_core_dev *dev)
5158
{
5259
return false;

drivers/net/ethernet/mellanox/mlx5/core/steering/mlx5dr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ mlx5dr_action_create_dest_match_range(struct mlx5dr_domain *dmn,
150150

151151
int mlx5dr_action_destroy(struct mlx5dr_action *action);
152152

153+
u32 mlx5dr_action_get_pkt_reformat_id(struct mlx5dr_action *action);
154+
153155
int mlx5dr_definer_get(struct mlx5dr_domain *dmn, u16 format_id,
154156
u8 *dw_selectors, u8 *byte_selectors,
155157
u8 *match_mask, u32 *definer_id);

0 commit comments

Comments
 (0)