net/mlx5e: Move flow attr reformat action bit to per dest flags
authorEli Britstein <elibr@mellanox.com>
Sat, 1 Dec 2018 07:40:43 +0000 (09:40 +0200)
committerSaeed Mahameed <saeedm@mellanox.com>
Tue, 11 Dec 2018 22:52:19 +0000 (14:52 -0800)
Flow attr reformat action bit is moved from the global action bits to a
per destination flags field, as a pre-step for adding additional flags
to support encapsulation properties per destination, with no
functionality change.

Signed-off-by: Eli Britstein <elibr@mellanox.com>
Reviewed-by: Oz Shlomo <ozsh@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

index b24b758f467d739c9b5e6c0753aadc2b9ff48cf2..e48fbb7d9735a2117fb7a81f3eab9985828a6b9a 100644 (file)
@@ -908,6 +908,7 @@ mlx5e_tc_add_fdb_flow(struct mlx5e_priv *priv,
        struct mlx5e_rep_priv *rpriv;
        struct mlx5e_priv *out_priv;
        int err = 0, encap_err = 0;
+       int out_index;
 
        /* if prios are not supported, keep the old behaviour of using same prio
         * for all offloaded rules.
@@ -927,7 +928,10 @@ mlx5e_tc_add_fdb_flow(struct mlx5e_priv *priv,
                goto err_max_prio_chain;
        }
 
-       if (attr->action & MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT) {
+       for (out_index = 0; out_index < MLX5_MAX_FLOW_FWD_VPORTS; out_index++) {
+               if (!(attr->dests[out_index].flags & MLX5_ESW_DEST_ENCAP))
+                       continue;
+
                out_dev = __dev_get_by_index(dev_net(priv->netdev),
                                             attr->parse_attr->mirred_ifindex);
                encap_err = mlx5e_attach_encap(priv, &parse_attr->tun_info,
@@ -991,8 +995,11 @@ err_create_counter:
 err_mod_hdr:
        mlx5_eswitch_del_vlan_action(esw, attr);
 err_add_vlan:
-       if (attr->action & MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT)
-               mlx5e_detach_encap(priv, flow);
+       for (out_index = 0; out_index < MLX5_MAX_FLOW_FWD_VPORTS; out_index++)
+               if (attr->dests[out_index].flags & MLX5_ESW_DEST_ENCAP) {
+                       mlx5e_detach_encap(priv, flow);
+                       break;
+               }
 err_attach_encap:
 err_max_prio_chain:
        return err;
@@ -1004,6 +1011,7 @@ static void mlx5e_tc_del_fdb_flow(struct mlx5e_priv *priv,
        struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
        struct mlx5_esw_flow_attr *attr = flow->esw_attr;
        struct mlx5_esw_flow_attr slow_attr;
+       int out_index;
 
        if (flow->flags & MLX5E_TC_FLOW_OFFLOADED) {
                if (flow->flags & MLX5E_TC_FLOW_SLOW)
@@ -1014,10 +1022,12 @@ static void mlx5e_tc_del_fdb_flow(struct mlx5e_priv *priv,
 
        mlx5_eswitch_del_vlan_action(esw, attr);
 
-       if (attr->action & MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT) {
-               mlx5e_detach_encap(priv, flow);
-               kvfree(attr->parse_attr);
-       }
+       for (out_index = 0; out_index < MLX5_MAX_FLOW_FWD_VPORTS; out_index++)
+               if (attr->dests[out_index].flags & MLX5_ESW_DEST_ENCAP) {
+                       mlx5e_detach_encap(priv, flow);
+                       break;
+               }
+       kvfree(attr->parse_attr);
 
        if (attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR)
                mlx5e_detach_mod_hdr(priv, flow);
@@ -2461,11 +2471,11 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
                                return -EOPNOTSUPP;
                        }
 
+                       action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
+                                 MLX5_FLOW_CONTEXT_ACTION_COUNT;
                        if (switchdev_port_same_parent_id(priv->netdev,
                                                          out_dev) ||
                            is_merged_eswitch_dev(priv, out_dev)) {
-                               action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
-                                         MLX5_FLOW_CONTEXT_ACTION_COUNT;
                                out_priv = netdev_priv(out_dev);
                                rpriv = out_priv->ppriv;
                                attr->dests[attr->out_count].rep = rpriv->rep;
@@ -2475,9 +2485,8 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
                                parse_attr->mirred_ifindex = out_dev->ifindex;
                                parse_attr->tun_info = *info;
                                attr->parse_attr = parse_attr;
-                               action |= MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT |
-                                         MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
-                                         MLX5_FLOW_CONTEXT_ACTION_COUNT;
+                               attr->dests[attr->out_count].flags |=
+                                       MLX5_ESW_DEST_ENCAP;
                                /* attr->dests[].rep is resolved when we
                                 * handle encap
                                 */
@@ -2657,10 +2666,6 @@ mlx5e_add_fdb_flow(struct mlx5e_priv *priv,
        if (err)
                goto err_free;
 
-       if (!(flow->esw_attr->action &
-             MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT))
-               kvfree(parse_attr);
-
        *__flow = flow;
 
        return 0;
index 5468975a1bdb32c9db230f3f2ee45d89a2fc6824..39363d4662b3363481aec8b5aa629cd136f560d1 100644 (file)
@@ -281,6 +281,10 @@ enum mlx5_flow_match_level {
 /* current maximum for flow based vport multicasting */
 #define MLX5_MAX_FLOW_FWD_VPORTS 2
 
+enum {
+       MLX5_ESW_DEST_ENCAP         = BIT(0),
+};
+
 struct mlx5_esw_flow_attr {
        struct mlx5_eswitch_rep *in_rep;
        struct mlx5_core_dev    *in_mdev;
@@ -296,6 +300,7 @@ struct mlx5_esw_flow_attr {
        bool    vlan_handled;
        u32     encap_id;
        struct {
+               u32 flags;
                struct mlx5_eswitch_rep *rep;
                struct mlx5_core_dev *mdev;
        } dests[MLX5_MAX_FLOW_FWD_VPORTS];
index 7cbe602129b7a41b29fad2a617c8c761614d0c2c..0387b5068be6f5d86ccff3d2a40449f8dec18d86 100644 (file)
@@ -128,6 +128,10 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw,
                                if (MLX5_CAP_ESW(esw->dev, merged_eswitch))
                                        dest[i].vport.flags |=
                                                MLX5_FLOW_DEST_VPORT_VHCA_ID;
+                               if (attr->dests[j].flags & MLX5_ESW_DEST_ENCAP) {
+                                       flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT;
+                                       flow_act.reformat_id = attr->encap_id;
+                               }
                                i++;
                        }
                }
@@ -164,9 +168,6 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw,
        if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR)
                flow_act.modify_id = attr->mod_hdr_id;
 
-       if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT)
-               flow_act.reformat_id = attr->encap_id;
-
        fdb = esw_get_prio_table(esw, attr->chain, attr->prio, !!split);
        if (IS_ERR(fdb)) {
                rule = ERR_CAST(fdb);