net/mlx5e: Offload tc vlan push/pop using HW action
[sfrench/cifs-2.6.git] / drivers / net / ethernet / mellanox / mlx5 / core / eswitch_offloads.c
index 0a8303c1b52f662e42b6d9fb62e1eebaa2e8abfc..35e256eb2f6e40de5cc4a78fed19327fafacec7c 100644 (file)
@@ -58,8 +58,16 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw,
        if (esw->mode != SRIOV_OFFLOADS)
                return ERR_PTR(-EOPNOTSUPP);
 
-       /* per flow vlan pop/push is emulated, don't set that into the firmware */
-       flow_act.action = attr->action & ~(MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH | MLX5_FLOW_CONTEXT_ACTION_VLAN_POP);
+       flow_act.action = attr->action;
+       /* if per flow vlan pop/push is emulated, don't set that into the firmware */
+       if (!mlx5_eswitch_vlan_actions_supported(esw->dev))
+               flow_act.action &= ~(MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH |
+                                    MLX5_FLOW_CONTEXT_ACTION_VLAN_POP);
+       else if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH) {
+               flow_act.vlan.ethtype = ntohs(attr->vlan_proto);
+               flow_act.vlan.vid = attr->vlan_vid;
+               flow_act.vlan.prio = attr->vlan_prio;
+       }
 
        if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) {
                dest[i].type = MLX5_FLOW_DESTINATION_TYPE_VPORT;
@@ -88,10 +96,10 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw,
        if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_DECAP)
                spec->match_criteria_enable |= MLX5_MATCH_INNER_HEADERS;
 
-       if (attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR)
+       if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR)
                flow_act.modify_id = attr->mod_hdr_id;
 
-       if (attr->action & MLX5_FLOW_CONTEXT_ACTION_ENCAP)
+       if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_ENCAP)
                flow_act.encap_id = attr->encap_id;
 
        rule = mlx5_add_flow_rules((struct mlx5_flow_table *)esw->fdb_table.fdb,
@@ -185,7 +193,7 @@ static int esw_add_vlan_action_check(struct mlx5_esw_flow_attr *attr,
        /* protects against (1) setting rules with different vlans to push and
         * (2) setting rules w.o vlans (attr->vlan = 0) && w. vlans to push (!= 0)
         */
-       if (push && in_rep->vlan_refcount && (in_rep->vlan != attr->vlan))
+       if (push && in_rep->vlan_refcount && (in_rep->vlan != attr->vlan_vid))
                goto out_notsupp;
 
        return 0;
@@ -202,6 +210,10 @@ int mlx5_eswitch_add_vlan_action(struct mlx5_eswitch *esw,
        bool push, pop, fwd;
        int err = 0;
 
+       /* nop if we're on the vlan push/pop non emulation mode */
+       if (mlx5_eswitch_vlan_actions_supported(esw->dev))
+               return 0;
+
        push = !!(attr->action & MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH);
        pop  = !!(attr->action & MLX5_FLOW_CONTEXT_ACTION_VLAN_POP);
        fwd  = !!(attr->action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST);
@@ -239,11 +251,11 @@ int mlx5_eswitch_add_vlan_action(struct mlx5_eswitch *esw,
                if (vport->vlan_refcount)
                        goto skip_set_push;
 
-               err = __mlx5_eswitch_set_vport_vlan(esw, vport->vport, attr->vlan, 0,
+               err = __mlx5_eswitch_set_vport_vlan(esw, vport->vport, attr->vlan_vid, 0,
                                                    SET_VLAN_INSERT | SET_VLAN_STRIP);
                if (err)
                        goto out;
-               vport->vlan = attr->vlan;
+               vport->vlan = attr->vlan_vid;
 skip_set_push:
                vport->vlan_refcount++;
        }
@@ -261,6 +273,10 @@ int mlx5_eswitch_del_vlan_action(struct mlx5_eswitch *esw,
        bool push, pop, fwd;
        int err = 0;
 
+       /* nop if we're on the vlan push/pop non emulation mode */
+       if (mlx5_eswitch_vlan_actions_supported(esw->dev))
+               return 0;
+
        if (!attr->vlan_handled)
                return 0;