]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mlxsw: spectrum_matchall: Implement sampling using mirroring
authorIdo Schimmel <idosch@nvidia.com>
Thu, 11 Mar 2021 12:24:16 +0000 (14:24 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 12 Mar 2021 00:22:39 +0000 (16:22 -0800)
Spectrum-2 and later ASICs support sampling of packets by mirroring to
the CPU with probability. There are several advantages compared to the
legacy dedicated sampling mechanism:

* Extra metadata per-packet: Egress port, egress traffic class, traffic
  class occupancy and end-to-end latency
* Ability to sample packets on egress / per-flow

Convert Spectrum-2 and later ASICs to perform sampling by mirroring to
the CPU with probability.

Subsequent patches will add support for egress / per-flow sampling and
expose the extra metadata.

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

index 1ec9a3c48a424698c31afd3f2cb22ba8cf7c4df2..bc7006de7873bb05d9a88edaa39dc5db9a3507cb 100644 (file)
@@ -238,6 +238,7 @@ struct mlxsw_sp_port_sample {
        u32 trunc_size;
        u32 rate;
        bool truncate;
+       int span_id;    /* Relevant for Spectrum-2 onwards. */
 };
 
 struct mlxsw_sp_bridge_port;
index ad1209df81ea4b01f65db44816773f6ef0d09d56..841a2de37f3607a4c80bd7a85a8f0890ddb8aee3 100644 (file)
@@ -378,7 +378,60 @@ const struct mlxsw_sp_mall_ops mlxsw_sp1_mall_ops = {
        .sample_del = mlxsw_sp1_mall_sample_del,
 };
 
+static int mlxsw_sp2_mall_sample_add(struct mlxsw_sp *mlxsw_sp,
+                                    struct mlxsw_sp_port *mlxsw_sp_port,
+                                    u32 rate)
+{
+       struct mlxsw_sp_span_trigger_parms trigger_parms = {};
+       struct mlxsw_sp_span_agent_parms agent_parms = {
+               .to_dev = NULL, /* Mirror to CPU. */
+               .session_id = MLXSW_SP_SPAN_SESSION_ID_SAMPLING,
+       };
+       struct mlxsw_sp_port_sample *sample;
+       int err;
+
+       sample = rtnl_dereference(mlxsw_sp_port->sample);
+
+       err = mlxsw_sp_span_agent_get(mlxsw_sp, &sample->span_id, &agent_parms);
+       if (err)
+               return err;
+
+       err = mlxsw_sp_span_analyzed_port_get(mlxsw_sp_port, true);
+       if (err)
+               goto err_analyzed_port_get;
+
+       trigger_parms.span_id = sample->span_id;
+       trigger_parms.probability_rate = rate;
+       err = mlxsw_sp_span_agent_bind(mlxsw_sp, MLXSW_SP_SPAN_TRIGGER_INGRESS,
+                                      mlxsw_sp_port, &trigger_parms);
+       if (err)
+               goto err_agent_bind;
+
+       return 0;
+
+err_agent_bind:
+       mlxsw_sp_span_analyzed_port_put(mlxsw_sp_port, true);
+err_analyzed_port_get:
+       mlxsw_sp_span_agent_put(mlxsw_sp, sample->span_id);
+       return err;
+}
+
+static void mlxsw_sp2_mall_sample_del(struct mlxsw_sp *mlxsw_sp,
+                                     struct mlxsw_sp_port *mlxsw_sp_port)
+{
+       struct mlxsw_sp_span_trigger_parms trigger_parms = {};
+       struct mlxsw_sp_port_sample *sample;
+
+       sample = rtnl_dereference(mlxsw_sp_port->sample);
+
+       trigger_parms.span_id = sample->span_id;
+       mlxsw_sp_span_agent_unbind(mlxsw_sp, MLXSW_SP_SPAN_TRIGGER_INGRESS,
+                                  mlxsw_sp_port, &trigger_parms);
+       mlxsw_sp_span_analyzed_port_put(mlxsw_sp_port, true);
+       mlxsw_sp_span_agent_put(mlxsw_sp, sample->span_id);
+}
+
 const struct mlxsw_sp_mall_ops mlxsw_sp2_mall_ops = {
-       .sample_add = mlxsw_sp1_mall_sample_add,
-       .sample_del = mlxsw_sp1_mall_sample_del,
+       .sample_add = mlxsw_sp2_mall_sample_add,
+       .sample_del = mlxsw_sp2_mall_sample_del,
 };
index dea1c0d31310b86d554142a7c0141a442e9e07ed..efaefd1ae8636dbfeb068358c59fa32ddb0dd3ef 100644 (file)
@@ -21,6 +21,7 @@ struct mlxsw_sp_port;
  */
 enum mlxsw_sp_span_session_id {
        MLXSW_SP_SPAN_SESSION_ID_BUFFER,
+       MLXSW_SP_SPAN_SESSION_ID_SAMPLING,
 
        __MLXSW_SP_SPAN_SESSION_ID_MAX = 8,
 };
index 6ecc77fde095fc29ccc1cb7d2ffb07f8e9abc5cb..e0e6ee58d31a70715980eab06036e85023c877fd 100644 (file)
@@ -49,6 +49,8 @@ enum {
 #define MLXSW_SP_TRAP_METADATA DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT
 
 enum {
+       /* Packet was mirrored from ingress. */
+       MLXSW_SP_MIRROR_REASON_INGRESS = 1,
        /* Packet was early dropped. */
        MLXSW_SP_MIRROR_REASON_INGRESS_WRED = 9,
 };
@@ -1753,6 +1755,7 @@ mlxsw_sp2_trap_group_items_arr[] = {
                .group = DEVLINK_TRAP_GROUP_GENERIC(ACL_SAMPLE, 0),
                .hw_group_id = MLXSW_REG_HTGT_TRAP_GROUP_SP_PKT_SAMPLE,
                .priority = 0,
+               .fixed_policer = true,
        },
 };
 
@@ -1769,8 +1772,9 @@ mlxsw_sp2_trap_items_arr[] = {
                .trap = MLXSW_SP_TRAP_CONTROL(FLOW_ACTION_SAMPLE, ACL_SAMPLE,
                                              MIRROR),
                .listeners_arr = {
-                       MLXSW_RXL(mlxsw_sp_rx_sample_listener, PKT_SAMPLE,
-                                 MIRROR_TO_CPU, false, SP_PKT_SAMPLE, DISCARD),
+                       MLXSW_RXL_MIRROR(mlxsw_sp_rx_sample_listener, 1,
+                                        SP_PKT_SAMPLE,
+                                        MLXSW_SP_MIRROR_REASON_INGRESS),
                },
        },
 };