Skip to content

Commit f71f1bc

Browse files
committed
Merge tag 'mlx5-updates-2021-12-14' of git://git.kernel.org/pub/scm/linux/kernel/git/saeed/linux
Saed Mahameed says: ==================== mlx5-updates-2021-12-14 Parsing Infrastructure for TC actions: The series introduce a TC action infrastructure to help parsing TC actions in a generic way for both FDB and NIC rules. To help maintain the parsing code of TC actions, we the parsing code to action parser per action TC type in separate files, instead of having one big switch case loop, duplicated between FDB and NIC parsers as before this patchset. Each TC flow_action->id is represented by a dedicated mlx5e_tc_act handler which has callbacks to check if the specific action is offload supported and to parse the specific action. We move each case (TC action) handling into the specific handler, which is responsible for parsing and determining if the action is supported. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 5a21bf5 + 35bb524 commit f71f1bc

File tree

25 files changed

+1855
-995
lines changed

25 files changed

+1855
-995
lines changed

drivers/net/ethernet/mellanox/mlx5/core/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ mlx5_core-$(CONFIG_MLX5_CLS_ACT) += en_tc.o en/rep/tc.o en/rep/neigh.o \
4646
en/tc_tun_vxlan.o en/tc_tun_gre.o en/tc_tun_geneve.o \
4747
en/tc_tun_mplsoudp.o diag/en_tc_tracepoint.o \
4848
en/tc/post_act.o en/tc/int_port.o
49+
50+
mlx5_core-$(CONFIG_MLX5_CLS_ACT) += en/tc/act/act.o en/tc/act/drop.o en/tc/act/trap.o \
51+
en/tc/act/accept.o en/tc/act/mark.o en/tc/act/goto.o \
52+
en/tc/act/tun.o en/tc/act/csum.o en/tc/act/pedit.o \
53+
en/tc/act/vlan.o en/tc/act/vlan_mangle.o en/tc/act/mpls.o \
54+
en/tc/act/mirred.o en/tc/act/mirred_nic.o \
55+
en/tc/act/ct.o en/tc/act/sample.o en/tc/act/ptype.o \
56+
en/tc/act/redirect_ingress.o
57+
4958
mlx5_core-$(CONFIG_MLX5_TC_CT) += en/tc_ct.o
5059
mlx5_core-$(CONFIG_MLX5_TC_SAMPLE) += en/tc/sample.o
5160

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2+
// Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
4+
#include "act.h"
5+
#include "en/tc_priv.h"
6+
7+
static bool
8+
tc_act_can_offload_accept(struct mlx5e_tc_act_parse_state *parse_state,
9+
const struct flow_action_entry *act,
10+
int act_index)
11+
{
12+
return true;
13+
}
14+
15+
static int
16+
tc_act_parse_accept(struct mlx5e_tc_act_parse_state *parse_state,
17+
const struct flow_action_entry *act,
18+
struct mlx5e_priv *priv,
19+
struct mlx5_flow_attr *attr)
20+
{
21+
attr->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
22+
MLX5_FLOW_CONTEXT_ACTION_COUNT;
23+
attr->flags |= MLX5_ESW_ATTR_FLAG_ACCEPT;
24+
25+
return 0;
26+
}
27+
28+
struct mlx5e_tc_act mlx5e_tc_act_accept = {
29+
.can_offload = tc_act_can_offload_accept,
30+
.parse_action = tc_act_parse_accept,
31+
};
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2+
// Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
4+
#include "act.h"
5+
#include "en/tc_priv.h"
6+
#include "mlx5_core.h"
7+
8+
/* Must be aligned with enum flow_action_id. */
9+
static struct mlx5e_tc_act *tc_acts_fdb[NUM_FLOW_ACTIONS] = {
10+
&mlx5e_tc_act_accept,
11+
&mlx5e_tc_act_drop,
12+
&mlx5e_tc_act_trap,
13+
&mlx5e_tc_act_goto,
14+
&mlx5e_tc_act_mirred,
15+
&mlx5e_tc_act_mirred,
16+
&mlx5e_tc_act_redirect_ingress,
17+
NULL, /* FLOW_ACTION_MIRRED_INGRESS, */
18+
&mlx5e_tc_act_vlan,
19+
&mlx5e_tc_act_vlan,
20+
&mlx5e_tc_act_vlan_mangle,
21+
&mlx5e_tc_act_tun_encap,
22+
&mlx5e_tc_act_tun_decap,
23+
&mlx5e_tc_act_pedit,
24+
&mlx5e_tc_act_pedit,
25+
&mlx5e_tc_act_csum,
26+
NULL, /* FLOW_ACTION_MARK, */
27+
&mlx5e_tc_act_ptype,
28+
NULL, /* FLOW_ACTION_PRIORITY, */
29+
NULL, /* FLOW_ACTION_WAKE, */
30+
NULL, /* FLOW_ACTION_QUEUE, */
31+
&mlx5e_tc_act_sample,
32+
NULL, /* FLOW_ACTION_POLICE, */
33+
&mlx5e_tc_act_ct,
34+
NULL, /* FLOW_ACTION_CT_METADATA, */
35+
&mlx5e_tc_act_mpls_push,
36+
&mlx5e_tc_act_mpls_pop,
37+
};
38+
39+
/* Must be aligned with enum flow_action_id. */
40+
static struct mlx5e_tc_act *tc_acts_nic[NUM_FLOW_ACTIONS] = {
41+
&mlx5e_tc_act_accept,
42+
&mlx5e_tc_act_drop,
43+
NULL, /* FLOW_ACTION_TRAP, */
44+
&mlx5e_tc_act_goto,
45+
&mlx5e_tc_act_mirred_nic,
46+
NULL, /* FLOW_ACTION_MIRRED, */
47+
NULL, /* FLOW_ACTION_REDIRECT_INGRESS, */
48+
NULL, /* FLOW_ACTION_MIRRED_INGRESS, */
49+
NULL, /* FLOW_ACTION_VLAN_PUSH, */
50+
NULL, /* FLOW_ACTION_VLAN_POP, */
51+
NULL, /* FLOW_ACTION_VLAN_MANGLE, */
52+
NULL, /* FLOW_ACTION_TUNNEL_ENCAP, */
53+
NULL, /* FLOW_ACTION_TUNNEL_DECAP, */
54+
&mlx5e_tc_act_pedit,
55+
&mlx5e_tc_act_pedit,
56+
&mlx5e_tc_act_csum,
57+
&mlx5e_tc_act_mark,
58+
NULL, /* FLOW_ACTION_PTYPE, */
59+
NULL, /* FLOW_ACTION_PRIORITY, */
60+
NULL, /* FLOW_ACTION_WAKE, */
61+
NULL, /* FLOW_ACTION_QUEUE, */
62+
NULL, /* FLOW_ACTION_SAMPLE, */
63+
NULL, /* FLOW_ACTION_POLICE, */
64+
&mlx5e_tc_act_ct,
65+
};
66+
67+
/**
68+
* mlx5e_tc_act_get() - Get an action parser for an action id.
69+
* @act_id: Flow action id.
70+
* @ns_type: flow namespace type.
71+
*/
72+
struct mlx5e_tc_act *
73+
mlx5e_tc_act_get(enum flow_action_id act_id,
74+
enum mlx5_flow_namespace_type ns_type)
75+
{
76+
struct mlx5e_tc_act **tc_acts;
77+
78+
tc_acts = ns_type == MLX5_FLOW_NAMESPACE_FDB ? tc_acts_fdb : tc_acts_nic;
79+
80+
return tc_acts[act_id];
81+
}
82+
83+
/**
84+
* mlx5e_tc_act_init_parse_state() - Init a new parse_state.
85+
* @parse_state: Parsing state.
86+
* @flow: mlx5e tc flow being handled.
87+
* @flow_action: flow action to parse.
88+
* @extack: to set an error msg.
89+
*
90+
* The same parse_state should be passed to action parsers
91+
* for tracking the current parsing state.
92+
*/
93+
void
94+
mlx5e_tc_act_init_parse_state(struct mlx5e_tc_act_parse_state *parse_state,
95+
struct mlx5e_tc_flow *flow,
96+
struct flow_action *flow_action,
97+
struct netlink_ext_ack *extack)
98+
{
99+
memset(parse_state, 0, sizeof(*parse_state));
100+
parse_state->flow = flow;
101+
parse_state->num_actions = flow_action->num_entries;
102+
parse_state->extack = extack;
103+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2+
/* Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */
3+
4+
#ifndef __MLX5_EN_TC_ACT_H__
5+
#define __MLX5_EN_TC_ACT_H__
6+
7+
#include <net/tc_act/tc_pedit.h>
8+
#include <net/flow_offload.h>
9+
#include <linux/netlink.h>
10+
#include "eswitch.h"
11+
#include "pedit.h"
12+
13+
struct mlx5_flow_attr;
14+
15+
struct mlx5e_tc_act_parse_state {
16+
unsigned int num_actions;
17+
struct mlx5e_tc_flow *flow;
18+
struct netlink_ext_ack *extack;
19+
bool encap;
20+
bool decap;
21+
bool mpls_push;
22+
bool ptype_host;
23+
const struct ip_tunnel_info *tun_info;
24+
struct pedit_headers_action hdrs[__PEDIT_CMD_MAX];
25+
int ifindexes[MLX5_MAX_FLOW_FWD_VPORTS];
26+
int if_count;
27+
struct mlx5_tc_ct_priv *ct_priv;
28+
};
29+
30+
struct mlx5e_tc_act {
31+
bool (*can_offload)(struct mlx5e_tc_act_parse_state *parse_state,
32+
const struct flow_action_entry *act,
33+
int act_index);
34+
35+
int (*parse_action)(struct mlx5e_tc_act_parse_state *parse_state,
36+
const struct flow_action_entry *act,
37+
struct mlx5e_priv *priv,
38+
struct mlx5_flow_attr *attr);
39+
40+
int (*post_parse)(struct mlx5e_tc_act_parse_state *parse_state,
41+
struct mlx5e_priv *priv,
42+
struct mlx5_flow_attr *attr);
43+
};
44+
45+
extern struct mlx5e_tc_act mlx5e_tc_act_drop;
46+
extern struct mlx5e_tc_act mlx5e_tc_act_trap;
47+
extern struct mlx5e_tc_act mlx5e_tc_act_accept;
48+
extern struct mlx5e_tc_act mlx5e_tc_act_mark;
49+
extern struct mlx5e_tc_act mlx5e_tc_act_goto;
50+
extern struct mlx5e_tc_act mlx5e_tc_act_tun_encap;
51+
extern struct mlx5e_tc_act mlx5e_tc_act_tun_decap;
52+
extern struct mlx5e_tc_act mlx5e_tc_act_csum;
53+
extern struct mlx5e_tc_act mlx5e_tc_act_pedit;
54+
extern struct mlx5e_tc_act mlx5e_tc_act_vlan;
55+
extern struct mlx5e_tc_act mlx5e_tc_act_vlan_mangle;
56+
extern struct mlx5e_tc_act mlx5e_tc_act_mpls_push;
57+
extern struct mlx5e_tc_act mlx5e_tc_act_mpls_pop;
58+
extern struct mlx5e_tc_act mlx5e_tc_act_mirred;
59+
extern struct mlx5e_tc_act mlx5e_tc_act_mirred_nic;
60+
extern struct mlx5e_tc_act mlx5e_tc_act_ct;
61+
extern struct mlx5e_tc_act mlx5e_tc_act_sample;
62+
extern struct mlx5e_tc_act mlx5e_tc_act_ptype;
63+
extern struct mlx5e_tc_act mlx5e_tc_act_redirect_ingress;
64+
65+
struct mlx5e_tc_act *
66+
mlx5e_tc_act_get(enum flow_action_id act_id,
67+
enum mlx5_flow_namespace_type ns_type);
68+
69+
void
70+
mlx5e_tc_act_init_parse_state(struct mlx5e_tc_act_parse_state *parse_state,
71+
struct mlx5e_tc_flow *flow,
72+
struct flow_action *flow_action,
73+
struct netlink_ext_ack *extack);
74+
75+
#endif /* __MLX5_EN_TC_ACT_H__ */
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2+
// Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
4+
#include <linux/tc_act/tc_csum.h>
5+
#include "act.h"
6+
#include "en/tc_priv.h"
7+
8+
static bool
9+
csum_offload_supported(struct mlx5e_priv *priv,
10+
u32 action,
11+
u32 update_flags,
12+
struct netlink_ext_ack *extack)
13+
{
14+
u32 prot_flags = TCA_CSUM_UPDATE_FLAG_IPV4HDR | TCA_CSUM_UPDATE_FLAG_TCP |
15+
TCA_CSUM_UPDATE_FLAG_UDP;
16+
17+
/* The HW recalcs checksums only if re-writing headers */
18+
if (!(action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR)) {
19+
NL_SET_ERR_MSG_MOD(extack,
20+
"TC csum action is only offloaded with pedit");
21+
netdev_warn(priv->netdev,
22+
"TC csum action is only offloaded with pedit\n");
23+
return false;
24+
}
25+
26+
if (update_flags & ~prot_flags) {
27+
NL_SET_ERR_MSG_MOD(extack,
28+
"can't offload TC csum action for some header/s");
29+
netdev_warn(priv->netdev,
30+
"can't offload TC csum action for some header/s - flags %#x\n",
31+
update_flags);
32+
return false;
33+
}
34+
35+
return true;
36+
}
37+
38+
static bool
39+
tc_act_can_offload_csum(struct mlx5e_tc_act_parse_state *parse_state,
40+
const struct flow_action_entry *act,
41+
int act_index)
42+
{
43+
struct mlx5e_tc_flow *flow = parse_state->flow;
44+
45+
return csum_offload_supported(flow->priv, flow->attr->action,
46+
act->csum_flags, parse_state->extack);
47+
}
48+
49+
static int
50+
tc_act_parse_csum(struct mlx5e_tc_act_parse_state *parse_state,
51+
const struct flow_action_entry *act,
52+
struct mlx5e_priv *priv,
53+
struct mlx5_flow_attr *attr)
54+
{
55+
return 0;
56+
}
57+
58+
struct mlx5e_tc_act mlx5e_tc_act_csum = {
59+
.can_offload = tc_act_can_offload_csum,
60+
.parse_action = tc_act_parse_csum,
61+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2+
// Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
4+
#include "act.h"
5+
#include "en/tc_priv.h"
6+
#include "en/tc_ct.h"
7+
8+
static bool
9+
tc_act_can_offload_ct(struct mlx5e_tc_act_parse_state *parse_state,
10+
const struct flow_action_entry *act,
11+
int act_index)
12+
{
13+
struct netlink_ext_ack *extack = parse_state->extack;
14+
15+
if (flow_flag_test(parse_state->flow, SAMPLE)) {
16+
NL_SET_ERR_MSG_MOD(extack,
17+
"Sample action with connection tracking is not supported");
18+
return false;
19+
}
20+
21+
return true;
22+
}
23+
24+
static int
25+
tc_act_parse_ct(struct mlx5e_tc_act_parse_state *parse_state,
26+
const struct flow_action_entry *act,
27+
struct mlx5e_priv *priv,
28+
struct mlx5_flow_attr *attr)
29+
{
30+
int err;
31+
32+
err = mlx5_tc_ct_parse_action(parse_state->ct_priv, attr,
33+
&attr->parse_attr->mod_hdr_acts,
34+
act, parse_state->extack);
35+
if (err)
36+
return err;
37+
38+
flow_flag_set(parse_state->flow, CT);
39+
40+
if (mlx5e_is_eswitch_flow(parse_state->flow))
41+
attr->esw_attr->split_count = attr->esw_attr->out_count;
42+
43+
return 0;
44+
}
45+
46+
struct mlx5e_tc_act mlx5e_tc_act_ct = {
47+
.can_offload = tc_act_can_offload_ct,
48+
.parse_action = tc_act_parse_ct,
49+
};
50+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2+
// Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
4+
#include "act.h"
5+
#include "en/tc_priv.h"
6+
7+
static bool
8+
tc_act_can_offload_drop(struct mlx5e_tc_act_parse_state *parse_state,
9+
const struct flow_action_entry *act,
10+
int act_index)
11+
{
12+
return true;
13+
}
14+
15+
static int
16+
tc_act_parse_drop(struct mlx5e_tc_act_parse_state *parse_state,
17+
const struct flow_action_entry *act,
18+
struct mlx5e_priv *priv,
19+
struct mlx5_flow_attr *attr)
20+
{
21+
attr->action |= MLX5_FLOW_CONTEXT_ACTION_DROP |
22+
MLX5_FLOW_CONTEXT_ACTION_COUNT;
23+
24+
return 0;
25+
}
26+
27+
struct mlx5e_tc_act mlx5e_tc_act_drop = {
28+
.can_offload = tc_act_can_offload_drop,
29+
.parse_action = tc_act_parse_drop,
30+
};

0 commit comments

Comments
 (0)