mlxsw: spectrum_span: Add support for global mirroring triggers
authorIdo Schimmel <idosch@mellanox.com>
Fri, 10 Jul 2020 21:55:08 +0000 (00:55 +0300)
committerDavid S. Miller <davem@davemloft.net>
Tue, 14 Jul 2020 00:22:22 +0000 (17:22 -0700)
Global mirroring triggers are triggers that are only keyed by their
trigger, as opposed to per-port triggers, which are keyed by their
trigger and port.

Such triggers allow mirroring packets that were tail/early dropped or
ECN marked to a SPAN agent.

Implement the previously added trigger operations for these global
triggers. Since such triggers are only supported from Spectrum-2
onwards, have the Spectrum-1 operations return an error.

Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Reviewed-by: Petr Machata <petrm@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Petr Machata <petrm@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c
drivers/net/ethernet/mellanox/mlxsw/spectrum_span.h

index b20422d..fa223c1 100644 (file)
@@ -49,6 +49,7 @@ struct mlxsw_sp_span_trigger_entry {
 
 enum mlxsw_sp_span_trigger_type {
        MLXSW_SP_SPAN_TRIGGER_TYPE_PORT,
+       MLXSW_SP_SPAN_TRIGGER_TYPE_GLOBAL,
 };
 
 struct mlxsw_sp_span_trigger_ops {
@@ -1140,9 +1141,101 @@ mlxsw_sp_span_trigger_port_ops = {
        .matches = mlxsw_sp_span_trigger_port_matches,
 };
 
+static int
+mlxsw_sp1_span_trigger_global_bind(struct mlxsw_sp_span_trigger_entry *
+                                  trigger_entry)
+{
+       return -EOPNOTSUPP;
+}
+
+static void
+mlxsw_sp1_span_trigger_global_unbind(struct mlxsw_sp_span_trigger_entry *
+                                    trigger_entry)
+{
+}
+
+static bool
+mlxsw_sp1_span_trigger_global_matches(struct mlxsw_sp_span_trigger_entry *
+                                     trigger_entry,
+                                     enum mlxsw_sp_span_trigger trigger,
+                                     struct mlxsw_sp_port *mlxsw_sp_port)
+{
+       WARN_ON_ONCE(1);
+       return false;
+}
+
+static const struct mlxsw_sp_span_trigger_ops
+mlxsw_sp1_span_trigger_global_ops = {
+       .bind = mlxsw_sp1_span_trigger_global_bind,
+       .unbind = mlxsw_sp1_span_trigger_global_unbind,
+       .matches = mlxsw_sp1_span_trigger_global_matches,
+};
+
+static const struct mlxsw_sp_span_trigger_ops *
+mlxsw_sp1_span_trigger_ops_arr[] = {
+       [MLXSW_SP_SPAN_TRIGGER_TYPE_PORT] = &mlxsw_sp_span_trigger_port_ops,
+       [MLXSW_SP_SPAN_TRIGGER_TYPE_GLOBAL] =
+               &mlxsw_sp1_span_trigger_global_ops,
+};
+
+static int
+mlxsw_sp2_span_trigger_global_bind(struct mlxsw_sp_span_trigger_entry *
+                                  trigger_entry)
+{
+       struct mlxsw_sp *mlxsw_sp = trigger_entry->span->mlxsw_sp;
+       enum mlxsw_reg_mpagr_trigger trigger;
+       char mpagr_pl[MLXSW_REG_MPAGR_LEN];
+
+       switch (trigger_entry->trigger) {
+       case MLXSW_SP_SPAN_TRIGGER_TAIL_DROP:
+               trigger = MLXSW_REG_MPAGR_TRIGGER_INGRESS_SHARED_BUFFER;
+               break;
+       case MLXSW_SP_SPAN_TRIGGER_EARLY_DROP:
+               trigger = MLXSW_REG_MPAGR_TRIGGER_INGRESS_WRED;
+               break;
+       case MLXSW_SP_SPAN_TRIGGER_ECN:
+               trigger = MLXSW_REG_MPAGR_TRIGGER_EGRESS_ECN;
+               break;
+       default:
+               WARN_ON_ONCE(1);
+               return -EINVAL;
+       }
+
+       mlxsw_reg_mpagr_pack(mpagr_pl, trigger, trigger_entry->parms.span_id,
+                            1);
+       return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(mpagr), mpagr_pl);
+}
+
+static void
+mlxsw_sp2_span_trigger_global_unbind(struct mlxsw_sp_span_trigger_entry *
+                                    trigger_entry)
+{
+       /* There is no unbinding for global triggers. The trigger should be
+        * disabled on all ports by now.
+        */
+}
+
+static bool
+mlxsw_sp2_span_trigger_global_matches(struct mlxsw_sp_span_trigger_entry *
+                                     trigger_entry,
+                                     enum mlxsw_sp_span_trigger trigger,
+                                     struct mlxsw_sp_port *mlxsw_sp_port)
+{
+       return trigger_entry->trigger == trigger;
+}
+
+static const struct mlxsw_sp_span_trigger_ops
+mlxsw_sp2_span_trigger_global_ops = {
+       .bind = mlxsw_sp2_span_trigger_global_bind,
+       .unbind = mlxsw_sp2_span_trigger_global_unbind,
+       .matches = mlxsw_sp2_span_trigger_global_matches,
+};
+
 static const struct mlxsw_sp_span_trigger_ops *
-mlxsw_sp_span_trigger_ops_arr[] = {
+mlxsw_sp2_span_trigger_ops_arr[] = {
        [MLXSW_SP_SPAN_TRIGGER_TYPE_PORT] = &mlxsw_sp_span_trigger_port_ops,
+       [MLXSW_SP_SPAN_TRIGGER_TYPE_GLOBAL] =
+               &mlxsw_sp2_span_trigger_global_ops,
 };
 
 static void
@@ -1156,6 +1249,11 @@ mlxsw_sp_span_trigger_ops_set(struct mlxsw_sp_span_trigger_entry *trigger_entry)
        case MLXSW_SP_SPAN_TRIGGER_EGRESS:
                type = MLXSW_SP_SPAN_TRIGGER_TYPE_PORT;
                break;
+       case MLXSW_SP_SPAN_TRIGGER_TAIL_DROP: /* fall-through */
+       case MLXSW_SP_SPAN_TRIGGER_EARLY_DROP: /* fall-through */
+       case MLXSW_SP_SPAN_TRIGGER_ECN:
+               type = MLXSW_SP_SPAN_TRIGGER_TYPE_GLOBAL;
+               break;
        default:
                WARN_ON_ONCE(1);
                return;
@@ -1286,7 +1384,7 @@ void mlxsw_sp_span_agent_unbind(struct mlxsw_sp *mlxsw_sp,
 
 static int mlxsw_sp1_span_init(struct mlxsw_sp *mlxsw_sp)
 {
-       mlxsw_sp->span->span_trigger_ops_arr = mlxsw_sp_span_trigger_ops_arr;
+       mlxsw_sp->span->span_trigger_ops_arr = mlxsw_sp1_span_trigger_ops_arr;
 
        return 0;
 }
@@ -1303,7 +1401,7 @@ const struct mlxsw_sp_span_ops mlxsw_sp1_span_ops = {
 
 static int mlxsw_sp2_span_init(struct mlxsw_sp *mlxsw_sp)
 {
-       mlxsw_sp->span->span_trigger_ops_arr = mlxsw_sp_span_trigger_ops_arr;
+       mlxsw_sp->span->span_trigger_ops_arr = mlxsw_sp2_span_trigger_ops_arr;
 
        return 0;
 }
index b9aceca..bb7939b 100644 (file)
@@ -26,6 +26,9 @@ struct mlxsw_sp_span_parms {
 enum mlxsw_sp_span_trigger {
        MLXSW_SP_SPAN_TRIGGER_INGRESS,
        MLXSW_SP_SPAN_TRIGGER_EGRESS,
+       MLXSW_SP_SPAN_TRIGGER_TAIL_DROP,
+       MLXSW_SP_SPAN_TRIGGER_EARLY_DROP,
+       MLXSW_SP_SPAN_TRIGGER_ECN,
 };
 
 struct mlxsw_sp_span_trigger_parms {