Skip to content

Commit c01cfd0

Browse files
jialiu02Saeed Mahameed
authored andcommitted
net/mlx5: E-Switch, Add match on vport metadata for rule in fast path
If FW's capabilities and configurations meet the requirement of vport metadata matching, this feature will be used. As the information about vport number and vhca_id related to packet is already stored to its metadata register, which is used as an indicator for perticular vport, now we can change to match on this metadata for all the offloading rules in fast path. Signed-off-by: Jianbo Liu <[email protected]> Reviewed-by: Eli Britstein <[email protected]> Reviewed-by: Roi Dayan <[email protected]> Reviewed-by: Mark Bloch <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 8d212ff commit c01cfd0

File tree

1 file changed

+51
-34
lines changed

1 file changed

+51
-34
lines changed

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

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,53 @@ u16 mlx5_eswitch_get_prio_range(struct mlx5_eswitch *esw)
8888
return 1;
8989
}
9090

91+
static void
92+
mlx5_eswitch_set_rule_source_port(struct mlx5_eswitch *esw,
93+
struct mlx5_flow_spec *spec,
94+
struct mlx5_esw_flow_attr *attr)
95+
{
96+
void *misc2;
97+
void *misc;
98+
99+
/* Use metadata matching because vport is not represented by single
100+
* VHCA in dual-port RoCE mode, and matching on source vport may fail.
101+
*/
102+
if (mlx5_eswitch_vport_match_metadata_enabled(esw)) {
103+
misc2 = MLX5_ADDR_OF(fte_match_param, spec->match_value, misc_parameters_2);
104+
MLX5_SET(fte_match_set_misc2, misc2, metadata_reg_c_0,
105+
mlx5_eswitch_get_vport_metadata_for_match(attr->in_mdev->priv.eswitch,
106+
attr->in_rep->vport));
107+
108+
misc2 = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, misc_parameters_2);
109+
MLX5_SET_TO_ONES(fte_match_set_misc2, misc2, metadata_reg_c_0);
110+
111+
spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS_2;
112+
misc = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, misc_parameters);
113+
if (memchr_inv(misc, 0, MLX5_ST_SZ_BYTES(fte_match_set_misc)))
114+
spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS;
115+
} else {
116+
misc = MLX5_ADDR_OF(fte_match_param, spec->match_value, misc_parameters);
117+
MLX5_SET(fte_match_set_misc, misc, source_port, attr->in_rep->vport);
118+
119+
if (MLX5_CAP_ESW(esw->dev, merged_eswitch))
120+
MLX5_SET(fte_match_set_misc, misc,
121+
source_eswitch_owner_vhca_id,
122+
MLX5_CAP_GEN(attr->in_mdev, vhca_id));
123+
124+
misc = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, misc_parameters);
125+
MLX5_SET_TO_ONES(fte_match_set_misc, misc, source_port);
126+
if (MLX5_CAP_ESW(esw->dev, merged_eswitch))
127+
MLX5_SET_TO_ONES(fte_match_set_misc, misc,
128+
source_eswitch_owner_vhca_id);
129+
130+
spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS;
131+
}
132+
133+
if (MLX5_CAP_ESW_FLOWTABLE(esw->dev, flow_source) &&
134+
attr->in_rep->vport == MLX5_VPORT_UPLINK)
135+
spec->flow_context.flow_source = MLX5_FLOW_CONTEXT_FLOW_SOURCE_UPLINK;
136+
}
137+
91138
struct mlx5_flow_handle *
92139
mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw,
93140
struct mlx5_flow_spec *spec,
@@ -99,7 +146,6 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw,
99146
struct mlx5_flow_handle *rule;
100147
struct mlx5_flow_table *fdb;
101148
int j, i = 0;
102-
void *misc;
103149

104150
if (esw->mode != SRIOV_OFFLOADS)
105151
return ERR_PTR(-EOPNOTSUPP);
@@ -159,21 +205,8 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw,
159205
i++;
160206
}
161207

162-
misc = MLX5_ADDR_OF(fte_match_param, spec->match_value, misc_parameters);
163-
MLX5_SET(fte_match_set_misc, misc, source_port, attr->in_rep->vport);
164-
165-
if (MLX5_CAP_ESW(esw->dev, merged_eswitch))
166-
MLX5_SET(fte_match_set_misc, misc,
167-
source_eswitch_owner_vhca_id,
168-
MLX5_CAP_GEN(attr->in_mdev, vhca_id));
208+
mlx5_eswitch_set_rule_source_port(esw, spec, attr);
169209

170-
misc = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, misc_parameters);
171-
MLX5_SET_TO_ONES(fte_match_set_misc, misc, source_port);
172-
if (MLX5_CAP_ESW(esw->dev, merged_eswitch))
173-
MLX5_SET_TO_ONES(fte_match_set_misc, misc,
174-
source_eswitch_owner_vhca_id);
175-
176-
spec->match_criteria_enable = MLX5_MATCH_MISC_PARAMETERS;
177210
if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_DECAP) {
178211
if (attr->tunnel_match_level != MLX5_MATCH_NONE)
179212
spec->match_criteria_enable |= MLX5_MATCH_OUTER_HEADERS;
@@ -219,7 +252,6 @@ mlx5_eswitch_add_fwd_rule(struct mlx5_eswitch *esw,
219252
struct mlx5_flow_table *fast_fdb;
220253
struct mlx5_flow_table *fwd_fdb;
221254
struct mlx5_flow_handle *rule;
222-
void *misc;
223255
int i;
224256

225257
fast_fdb = esw_get_prio_table(esw, attr->chain, attr->prio, 0);
@@ -251,25 +283,10 @@ mlx5_eswitch_add_fwd_rule(struct mlx5_eswitch *esw,
251283
dest[i].ft = fwd_fdb,
252284
i++;
253285

254-
misc = MLX5_ADDR_OF(fte_match_param, spec->match_value, misc_parameters);
255-
MLX5_SET(fte_match_set_misc, misc, source_port, attr->in_rep->vport);
256-
257-
if (MLX5_CAP_ESW(esw->dev, merged_eswitch))
258-
MLX5_SET(fte_match_set_misc, misc,
259-
source_eswitch_owner_vhca_id,
260-
MLX5_CAP_GEN(attr->in_mdev, vhca_id));
261-
262-
misc = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, misc_parameters);
263-
MLX5_SET_TO_ONES(fte_match_set_misc, misc, source_port);
264-
if (MLX5_CAP_ESW(esw->dev, merged_eswitch))
265-
MLX5_SET_TO_ONES(fte_match_set_misc, misc,
266-
source_eswitch_owner_vhca_id);
286+
mlx5_eswitch_set_rule_source_port(esw, spec, attr);
267287

268-
if (attr->match_level == MLX5_MATCH_NONE)
269-
spec->match_criteria_enable = MLX5_MATCH_MISC_PARAMETERS;
270-
else
271-
spec->match_criteria_enable = MLX5_MATCH_OUTER_HEADERS |
272-
MLX5_MATCH_MISC_PARAMETERS;
288+
if (attr->match_level != MLX5_MATCH_NONE)
289+
spec->match_criteria_enable |= MLX5_MATCH_OUTER_HEADERS;
273290

274291
rule = mlx5_add_flow_rules(fast_fdb, spec, &flow_act, dest, i);
275292

0 commit comments

Comments
 (0)