mlxsw: spectrum: Extend mlxsw_afa_ops for counter index and implement for Spectrum
authorArkadi Sharshevsky <arkadis@mellanox.com>
Fri, 19 Jan 2018 08:24:51 +0000 (09:24 +0100)
committerDavid S. Miller <davem@davemloft.net>
Sun, 21 Jan 2018 23:21:30 +0000 (18:21 -0500)
Introduce extension of mlxsw_afa_ops in order to add/del mirroring and
implement the ops for Spectrum.

Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_flex_actions.c

index c829bb4..ad48dda 100644 (file)
@@ -48,6 +48,10 @@ struct mlxsw_afa_ops {
        void (*kvdl_fwd_entry_del)(void *priv, u32 kvdl_index);
        int (*counter_index_get)(void *priv, unsigned int *p_counter_index);
        void (*counter_index_put)(void *priv, unsigned int counter_index);
+       int (*mirror_add)(void *priv, u8 locol_in_port, u8 local_out_port,
+                         bool ingress, int *p_span_id);
+       void (*mirror_del)(void *priv, u8 locol_in_port, u8 local_out_port,
+                          bool ingress);
 };
 
 struct mlxsw_afa *mlxsw_afa_create(unsigned int max_acts_per_set,
index dae4d02..6ca6894 100644 (file)
@@ -124,6 +124,52 @@ mlxsw_sp_act_counter_index_put(void *priv, unsigned int counter_index)
        mlxsw_sp_flow_counter_free(mlxsw_sp, counter_index);
 }
 
+static int
+mlxsw_sp_act_mirror_add(void *priv, u8 local_in_port, u8 local_out_port,
+                       bool ingress, int *p_span_id)
+{
+       struct mlxsw_sp_port *in_port, *out_port;
+       struct mlxsw_sp_span_entry *span_entry;
+       struct mlxsw_sp *mlxsw_sp = priv;
+       enum mlxsw_sp_span_type type;
+       int err;
+
+       type = ingress ? MLXSW_SP_SPAN_INGRESS : MLXSW_SP_SPAN_EGRESS;
+       out_port = mlxsw_sp->ports[local_out_port];
+       in_port = mlxsw_sp->ports[local_in_port];
+
+       err = mlxsw_sp_span_mirror_add(in_port, out_port, type, false);
+       if (err)
+               return err;
+
+       span_entry = mlxsw_sp_span_entry_find(mlxsw_sp, local_out_port);
+       if (!span_entry) {
+               err = -ENOENT;
+               goto err_span_entry_find;
+       }
+
+       *p_span_id = span_entry->id;
+       return 0;
+
+err_span_entry_find:
+       mlxsw_sp_span_mirror_del(in_port, local_out_port, type, false);
+       return err;
+}
+
+static void
+mlxsw_sp_act_mirror_del(void *priv, u8 local_in_port, u8 local_out_port,
+                       bool ingress)
+{
+       struct mlxsw_sp *mlxsw_sp = priv;
+       struct mlxsw_sp_port *in_port;
+       enum mlxsw_sp_span_type type;
+
+       type = ingress ? MLXSW_SP_SPAN_INGRESS : MLXSW_SP_SPAN_EGRESS;
+       in_port = mlxsw_sp->ports[local_in_port];
+
+       mlxsw_sp_span_mirror_del(in_port, local_out_port, type, false);
+}
+
 static const struct mlxsw_afa_ops mlxsw_sp_act_afa_ops = {
        .kvdl_set_add           = mlxsw_sp_act_kvdl_set_add,
        .kvdl_set_del           = mlxsw_sp_act_kvdl_set_del,
@@ -131,6 +177,8 @@ static const struct mlxsw_afa_ops mlxsw_sp_act_afa_ops = {
        .kvdl_fwd_entry_del     = mlxsw_sp_act_kvdl_fwd_entry_del,
        .counter_index_get      = mlxsw_sp_act_counter_index_get,
        .counter_index_put      = mlxsw_sp_act_counter_index_put,
+       .mirror_add             = mlxsw_sp_act_mirror_add,
+       .mirror_del             = mlxsw_sp_act_mirror_del,
 };
 
 int mlxsw_sp_afa_init(struct mlxsw_sp *mlxsw_sp)