Skip to content

Commit 1482bd3

Browse files
jialiu02Saeed Mahameed
authored andcommitted
net/mlx5e: Refactor tc vlan push/pop actions offloading
Extract actions offloading code to a new function, and also extend data structures for double vlan actions. Signed-off-by: Jianbo Liu <[email protected]> Reviewed-by: Or Gerlitz <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 699e96d commit 1482bd3

File tree

3 files changed

+41
-28
lines changed

3 files changed

+41
-28
lines changed

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

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,6 +2578,32 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv,
25782578
return err;
25792579
}
25802580

2581+
static int parse_tc_vlan_action(struct mlx5e_priv *priv,
2582+
const struct tc_action *a,
2583+
struct mlx5_esw_flow_attr *attr,
2584+
u32 *action)
2585+
{
2586+
if (tcf_vlan_action(a) == TCA_VLAN_ACT_POP) {
2587+
*action |= MLX5_FLOW_CONTEXT_ACTION_VLAN_POP;
2588+
} else if (tcf_vlan_action(a) == TCA_VLAN_ACT_PUSH) {
2589+
*action |= MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH;
2590+
attr->vlan_vid[0] = tcf_vlan_push_vid(a);
2591+
if (mlx5_eswitch_vlan_actions_supported(priv->mdev)) {
2592+
attr->vlan_prio[0] = tcf_vlan_push_prio(a);
2593+
attr->vlan_proto[0] = tcf_vlan_push_proto(a);
2594+
if (!attr->vlan_proto[0])
2595+
attr->vlan_proto[0] = htons(ETH_P_8021Q);
2596+
} else if (tcf_vlan_push_proto(a) != htons(ETH_P_8021Q) ||
2597+
tcf_vlan_push_prio(a)) {
2598+
return -EOPNOTSUPP;
2599+
}
2600+
} else { /* action is TCA_VLAN_ACT_MODIFY */
2601+
return -EOPNOTSUPP;
2602+
}
2603+
2604+
return 0;
2605+
}
2606+
25812607
static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
25822608
struct mlx5e_tc_flow_parse_attr *parse_attr,
25832609
struct mlx5e_tc_flow *flow)
@@ -2589,6 +2615,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
25892615
LIST_HEAD(actions);
25902616
bool encap = false;
25912617
u32 action = 0;
2618+
int err;
25922619

25932620
if (!tcf_exts_has_actions(exts))
25942621
return -EINVAL;
@@ -2605,8 +2632,6 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
26052632
}
26062633

26072634
if (is_tcf_pedit(a)) {
2608-
int err;
2609-
26102635
err = parse_tc_pedit_action(priv, a, MLX5_FLOW_NAMESPACE_FDB,
26112636
parse_attr);
26122637
if (err)
@@ -2673,23 +2698,11 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
26732698
}
26742699

26752700
if (is_tcf_vlan(a)) {
2676-
if (tcf_vlan_action(a) == TCA_VLAN_ACT_POP) {
2677-
action |= MLX5_FLOW_CONTEXT_ACTION_VLAN_POP;
2678-
} else if (tcf_vlan_action(a) == TCA_VLAN_ACT_PUSH) {
2679-
action |= MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH;
2680-
attr->vlan_vid = tcf_vlan_push_vid(a);
2681-
if (mlx5_eswitch_vlan_actions_supported(priv->mdev)) {
2682-
attr->vlan_prio = tcf_vlan_push_prio(a);
2683-
attr->vlan_proto = tcf_vlan_push_proto(a);
2684-
if (!attr->vlan_proto)
2685-
attr->vlan_proto = htons(ETH_P_8021Q);
2686-
} else if (tcf_vlan_push_proto(a) != htons(ETH_P_8021Q) ||
2687-
tcf_vlan_push_prio(a)) {
2688-
return -EOPNOTSUPP;
2689-
}
2690-
} else { /* action is TCA_VLAN_ACT_MODIFY */
2691-
return -EOPNOTSUPP;
2692-
}
2701+
err = parse_tc_vlan_action(priv, a, attr, &action);
2702+
2703+
if (err)
2704+
return err;
2705+
26932706
attr->mirror_count = attr->out_count;
26942707
continue;
26952708
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ struct mlx5_esw_flow_attr {
256256
int out_count;
257257

258258
int action;
259-
__be16 vlan_proto;
260-
u16 vlan_vid;
261-
u8 vlan_prio;
259+
__be16 vlan_proto[1];
260+
u16 vlan_vid[1];
261+
u8 vlan_prio[1];
262262
bool vlan_handled;
263263
u32 encap_id;
264264
u32 mod_hdr_id;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw,
7070
flow_act.action &= ~(MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH |
7171
MLX5_FLOW_CONTEXT_ACTION_VLAN_POP);
7272
else if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH) {
73-
flow_act.vlan[0].ethtype = ntohs(attr->vlan_proto);
74-
flow_act.vlan[0].vid = attr->vlan_vid;
75-
flow_act.vlan[0].prio = attr->vlan_prio;
73+
flow_act.vlan[0].ethtype = ntohs(attr->vlan_proto[0]);
74+
flow_act.vlan[0].vid = attr->vlan_vid[0];
75+
flow_act.vlan[0].prio = attr->vlan_prio[0];
7676
}
7777

7878
if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) {
@@ -266,7 +266,7 @@ static int esw_add_vlan_action_check(struct mlx5_esw_flow_attr *attr,
266266
/* protects against (1) setting rules with different vlans to push and
267267
* (2) setting rules w.o vlans (attr->vlan = 0) && w. vlans to push (!= 0)
268268
*/
269-
if (push && in_rep->vlan_refcount && (in_rep->vlan != attr->vlan_vid))
269+
if (push && in_rep->vlan_refcount && (in_rep->vlan != attr->vlan_vid[0]))
270270
goto out_notsupp;
271271

272272
return 0;
@@ -324,11 +324,11 @@ int mlx5_eswitch_add_vlan_action(struct mlx5_eswitch *esw,
324324
if (vport->vlan_refcount)
325325
goto skip_set_push;
326326

327-
err = __mlx5_eswitch_set_vport_vlan(esw, vport->vport, attr->vlan_vid, 0,
327+
err = __mlx5_eswitch_set_vport_vlan(esw, vport->vport, attr->vlan_vid[0], 0,
328328
SET_VLAN_INSERT | SET_VLAN_STRIP);
329329
if (err)
330330
goto out;
331-
vport->vlan = attr->vlan_vid;
331+
vport->vlan = attr->vlan_vid[0];
332332
skip_set_push:
333333
vport->vlan_refcount++;
334334
}

0 commit comments

Comments
 (0)