]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
net/mlx5e: Parse mirroring action for offloaded TC eswitch flows
authorChris Mi <chrism@mellanox.com>
Fri, 4 May 2018 05:09:00 +0000 (14:09 +0900)
committerSaeed Mahameed <saeedm@mellanox.com>
Fri, 25 May 2018 21:11:00 +0000 (14:11 -0700)
Currently, we only support the mirred redirect TC sub-action. In order
to support flow based vport mirroring, add support to parse the mirred
mirror sub-action.

For mirroring, user-space will typically set the action order such that
the mirror port (mirror VF) sees packets as the original port (VF under
mirroring) sent them or as it will receive them.

In the general case, it means that packets are potentially sent to the
mirror port before or after some actions were applied on them. To
properly do that, we should follow on the exact action order as set for
the flow and make sure this will also be the case when we program the HW
offload.

We introduce a counter for the output ports (attr->out_count), which we
increase when parsing each mirred redirect/mirror sub-action and when
dealing with encap.

We introduce a counter (attr->mirror_count) telling us if split is
needed. If no split is needed and mirroring is just multicasting to
vport, the mirror count is zero, all the actions of the TC flow should
apply on that single HW flow.

If split is needed, the mirror count tells where to do the split, all
non-mirred tc actions should apply only after the split.

The mirror count is set while parsing the following actions encap/decap,
header re-write, vlan push/pop.

Signed-off-by: Chris Mi <chrism@mellanox.com>
Reviewed-by: Paul Blakey <paulb@mellanox.com>
Reviewed-by: Or Gerlitz <ogerlitz@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 a9c96fe8e4fe3c1751def6685c00e30e149c0d5b..302c5500f9addfcb2dec9a2911df3342e6a6f861 100644 (file)
@@ -844,8 +844,8 @@ mlx5e_tc_add_fdb_flow(struct mlx5e_priv *priv,
                }
                out_priv = netdev_priv(encap_dev);
                rpriv = out_priv->ppriv;
-               attr->out_rep = rpriv->rep;
-               attr->out_mdev = out_priv->mdev;
+               attr->out_rep[attr->out_count] = rpriv->rep;
+               attr->out_mdev[attr->out_count++] = out_priv->mdev;
        }
 
        err = mlx5_eswitch_add_vlan_action(esw, attr);
@@ -2537,6 +2537,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
                                return err;
 
                        action |= MLX5_FLOW_CONTEXT_ACTION_MOD_HDR;
+                       attr->mirror_count = attr->out_count;
                        continue;
                }
 
@@ -2548,12 +2549,18 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
                        return -EOPNOTSUPP;
                }
 
-               if (is_tcf_mirred_egress_redirect(a)) {
-                       struct net_device *out_dev;
+               if (is_tcf_mirred_egress_redirect(a) || is_tcf_mirred_egress_mirror(a)) {
                        struct mlx5e_priv *out_priv;
+                       struct net_device *out_dev;
 
                        out_dev = tcf_mirred_dev(a);
 
+                       if (attr->out_count >= MLX5_MAX_FLOW_FWD_VPORTS) {
+                               pr_err("can't support more than %d output ports, can't offload forwarding\n",
+                                      attr->out_count);
+                               return -EOPNOTSUPP;
+                       }
+
                        if (switchdev_port_same_parent_id(priv->netdev,
                                                          out_dev) ||
                            is_merged_eswitch_dev(priv, out_dev)) {
@@ -2561,8 +2568,8 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
                                          MLX5_FLOW_CONTEXT_ACTION_COUNT;
                                out_priv = netdev_priv(out_dev);
                                rpriv = out_priv->ppriv;
-                               attr->out_rep = rpriv->rep;
-                               attr->out_mdev = out_priv->mdev;
+                               attr->out_rep[attr->out_count] = rpriv->rep;
+                               attr->out_mdev[attr->out_count++] = out_priv->mdev;
                        } else if (encap) {
                                parse_attr->mirred_ifindex = out_dev->ifindex;
                                parse_attr->tun_info = *info;
@@ -2585,6 +2592,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
                                encap = true;
                        else
                                return -EOPNOTSUPP;
+                       attr->mirror_count = attr->out_count;
                        continue;
                }
 
@@ -2606,6 +2614,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
                        } else { /* action is TCA_VLAN_ACT_MODIFY */
                                return -EOPNOTSUPP;
                        }
+                       attr->mirror_count = attr->out_count;
                        continue;
                }
 
@@ -2621,6 +2630,11 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
        if (!actions_match_supported(priv, exts, parse_attr, flow))
                return -EOPNOTSUPP;
 
+       if (attr->out_count > 1 && !mlx5_esw_has_fwd_fdb(priv->mdev)) {
+               netdev_warn_once(priv->netdev, "current firmware doesn't support split rule for port mirroring\n");
+               return -EOPNOTSUPP;
+       }
+
        return 0;
 }
 
index d06c1162912175bfda9670ea2f156249c0d44e4b..386b0e354c413ce6097541cea08997f8021eb683 100644 (file)
@@ -239,12 +239,18 @@ enum mlx5_flow_match_level {
        MLX5_MATCH_L4   = MLX5_INLINE_MODE_TCP_UDP,
 };
 
+/* current maximum for flow based vport multicasting */
+#define MLX5_MAX_FLOW_FWD_VPORTS 2
+
 struct mlx5_esw_flow_attr {
        struct mlx5_eswitch_rep *in_rep;
-       struct mlx5_eswitch_rep *out_rep;
-       struct mlx5_core_dev    *out_mdev;
+       struct mlx5_eswitch_rep *out_rep[MLX5_MAX_FLOW_FWD_VPORTS];
+       struct mlx5_core_dev    *out_mdev[MLX5_MAX_FLOW_FWD_VPORTS];
        struct mlx5_core_dev    *in_mdev;
 
+       int mirror_count;
+       int out_count;
+
        int     action;
        __be16  vlan_proto;
        u16     vlan_vid;
index 8ea11f24380ce07ff177171ce1ba21bcb0481a4f..7db8b9a419250bacc741726e58bd056337e17f58 100644 (file)
@@ -48,12 +48,12 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw,
                                struct mlx5_flow_spec *spec,
                                struct mlx5_esw_flow_attr *attr)
 {
-       struct mlx5_flow_destination dest[2] = {};
+       struct mlx5_flow_destination dest[MLX5_MAX_FLOW_FWD_VPORTS + 1] = {};
        struct mlx5_flow_act flow_act = {0};
        struct mlx5_fc *counter = NULL;
        struct mlx5_flow_handle *rule;
+       int j, i = 0;
        void *misc;
-       int i = 0;
 
        if (esw->mode != SRIOV_OFFLOADS)
                return ERR_PTR(-EOPNOTSUPP);
@@ -70,14 +70,16 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw,
        }
 
        if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) {
-               dest[i].type = MLX5_FLOW_DESTINATION_TYPE_VPORT;
-               dest[i].vport.num = attr->out_rep->vport;
-               if (MLX5_CAP_ESW(esw->dev, merged_eswitch)) {
-                       dest[i].vport.vhca_id =
-                               MLX5_CAP_GEN(attr->out_mdev, vhca_id);
-                       dest[i].vport.vhca_id_valid = 1;
+               for (j = attr->mirror_count; j < attr->out_count; j++) {
+                       dest[i].type = MLX5_FLOW_DESTINATION_TYPE_VPORT;
+                       dest[i].vport.num = attr->out_rep[j]->vport;
+                       if (MLX5_CAP_ESW(esw->dev, merged_eswitch)) {
+                               dest[i].vport.vhca_id =
+                                       MLX5_CAP_GEN(attr->out_mdev[j], vhca_id);
+                               dest[i].vport.vhca_id_valid = 1;
+                       }
+                       i++;
                }
-               i++;
        }
        if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_COUNT) {
                counter = mlx5_fc_create(esw->dev, true);
@@ -173,7 +175,7 @@ esw_vlan_action_get_vport(struct mlx5_esw_flow_attr *attr, bool push, bool pop)
        struct mlx5_eswitch_rep *in_rep, *out_rep, *vport = NULL;
 
        in_rep  = attr->in_rep;
-       out_rep = attr->out_rep;
+       out_rep = attr->out_rep[0];
 
        if (push)
                vport = in_rep;
@@ -194,7 +196,7 @@ static int esw_add_vlan_action_check(struct mlx5_esw_flow_attr *attr,
                goto out_notsupp;
 
        in_rep  = attr->in_rep;
-       out_rep = attr->out_rep;
+       out_rep = attr->out_rep[0];
 
        if (push && in_rep->vport == FDB_UPLINK_VPORT)
                goto out_notsupp;
@@ -245,7 +247,7 @@ int mlx5_eswitch_add_vlan_action(struct mlx5_eswitch *esw,
 
        if (!push && !pop && fwd) {
                /* tracks VF --> wire rules without vlan push action */
-               if (attr->out_rep->vport == FDB_UPLINK_VPORT) {
+               if (attr->out_rep[0]->vport == FDB_UPLINK_VPORT) {
                        vport->vlan_refcount++;
                        attr->vlan_handled = true;
                }
@@ -305,7 +307,7 @@ int mlx5_eswitch_del_vlan_action(struct mlx5_eswitch *esw,
 
        if (!push && !pop && fwd) {
                /* tracks VF --> wire rules without vlan push action */
-               if (attr->out_rep->vport == FDB_UPLINK_VPORT)
+               if (attr->out_rep[0]->vport == FDB_UPLINK_VPORT)
                        vport->vlan_refcount--;
 
                return 0;