Skip to content

Commit bdd66ac

Browse files
ogerlitzSaeed Mahameed
authored and
Saeed Mahameed
committed
net/mlx5e: Disallow TC offloading of unsupported match/action combinations
When offloading header re-write, the HW may need to adjust checksums along the packet. For IP traffic, and a case where we are asked to modify fields in the IP header, current HW supports that only for TCP and UDP. Enforce it, in this case fail the offloading attempt for non TCP/UDP packets. Fixes: d7e75a3 ('net/mlx5e: Add offloading of E-Switch TC pedit (header re-write) actions') Fixes: 2f4fe4c ('net/mlx5e: Add offloading of NIC TC pedit (header re-write) actions') Signed-off-by: Or Gerlitz <[email protected]> Reviewed-by: Paul Blakey <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent ace7432 commit bdd66ac

File tree

1 file changed

+70
-0
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+70
-0
lines changed

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,69 @@ static bool csum_offload_supported(struct mlx5e_priv *priv, u32 action, u32 upda
13171317
return true;
13181318
}
13191319

1320+
static bool modify_header_match_supported(struct mlx5_flow_spec *spec,
1321+
struct tcf_exts *exts)
1322+
{
1323+
const struct tc_action *a;
1324+
bool modify_ip_header;
1325+
LIST_HEAD(actions);
1326+
u8 htype, ip_proto;
1327+
void *headers_v;
1328+
u16 ethertype;
1329+
int nkeys, i;
1330+
1331+
headers_v = MLX5_ADDR_OF(fte_match_param, spec->match_value, outer_headers);
1332+
ethertype = MLX5_GET(fte_match_set_lyr_2_4, headers_v, ethertype);
1333+
1334+
/* for non-IP we only re-write MACs, so we're okay */
1335+
if (ethertype != ETH_P_IP && ethertype != ETH_P_IPV6)
1336+
goto out_ok;
1337+
1338+
modify_ip_header = false;
1339+
tcf_exts_to_list(exts, &actions);
1340+
list_for_each_entry(a, &actions, list) {
1341+
if (!is_tcf_pedit(a))
1342+
continue;
1343+
1344+
nkeys = tcf_pedit_nkeys(a);
1345+
for (i = 0; i < nkeys; i++) {
1346+
htype = tcf_pedit_htype(a, i);
1347+
if (htype == TCA_PEDIT_KEY_EX_HDR_TYPE_IP4 ||
1348+
htype == TCA_PEDIT_KEY_EX_HDR_TYPE_IP6) {
1349+
modify_ip_header = true;
1350+
break;
1351+
}
1352+
}
1353+
}
1354+
1355+
ip_proto = MLX5_GET(fte_match_set_lyr_2_4, headers_v, ip_protocol);
1356+
if (modify_ip_header && ip_proto != IPPROTO_TCP && ip_proto != IPPROTO_UDP) {
1357+
pr_info("can't offload re-write of ip proto %d\n", ip_proto);
1358+
return false;
1359+
}
1360+
1361+
out_ok:
1362+
return true;
1363+
}
1364+
1365+
static bool actions_match_supported(struct mlx5e_priv *priv,
1366+
struct tcf_exts *exts,
1367+
struct mlx5e_tc_flow_parse_attr *parse_attr,
1368+
struct mlx5e_tc_flow *flow)
1369+
{
1370+
u32 actions;
1371+
1372+
if (flow->flags & MLX5E_TC_FLOW_ESWITCH)
1373+
actions = flow->esw_attr->action;
1374+
else
1375+
actions = flow->nic_attr->action;
1376+
1377+
if (actions & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR)
1378+
return modify_header_match_supported(&parse_attr->spec, exts);
1379+
1380+
return true;
1381+
}
1382+
13201383
static int parse_tc_nic_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
13211384
struct mlx5e_tc_flow_parse_attr *parse_attr,
13221385
struct mlx5e_tc_flow *flow)
@@ -1378,6 +1441,9 @@ static int parse_tc_nic_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
13781441
return -EINVAL;
13791442
}
13801443

1444+
if (!actions_match_supported(priv, exts, parse_attr, flow))
1445+
return -EOPNOTSUPP;
1446+
13811447
return 0;
13821448
}
13831449

@@ -1936,6 +2002,10 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
19362002

19372003
return -EINVAL;
19382004
}
2005+
2006+
if (!actions_match_supported(priv, exts, parse_attr, flow))
2007+
return -EOPNOTSUPP;
2008+
19392009
return err;
19402010
}
19412011

0 commit comments

Comments
 (0)