Commit 20afb9bc authored by Ido Schimmel's avatar Ido Schimmel Committed by David S. Miller
Browse files

mlxsw: spectrum_matchall: Split sampling support between ASICs



Sampling of ingress packets is supported using a dedicated sampling
mechanism on all Spectrum ASICs. However, Spectrum-2 and later ASICs
support more sophisticated sampling by mirroring packets to the CPU.

As a preparation for more advanced sampling configurations, split the
sampling operations between Spectrum-1 and later ASICs.

Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2dcbd920
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -2804,6 +2804,7 @@ static int mlxsw_sp1_init(struct mlxsw_core *mlxsw_core,
	mlxsw_sp->span_ops = &mlxsw_sp1_span_ops;
	mlxsw_sp->span_ops = &mlxsw_sp1_span_ops;
	mlxsw_sp->policer_core_ops = &mlxsw_sp1_policer_core_ops;
	mlxsw_sp->policer_core_ops = &mlxsw_sp1_policer_core_ops;
	mlxsw_sp->trap_ops = &mlxsw_sp1_trap_ops;
	mlxsw_sp->trap_ops = &mlxsw_sp1_trap_ops;
	mlxsw_sp->mall_ops = &mlxsw_sp1_mall_ops;
	mlxsw_sp->listeners = mlxsw_sp1_listener;
	mlxsw_sp->listeners = mlxsw_sp1_listener;
	mlxsw_sp->listeners_count = ARRAY_SIZE(mlxsw_sp1_listener);
	mlxsw_sp->listeners_count = ARRAY_SIZE(mlxsw_sp1_listener);
	mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP1;
	mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP1;
@@ -2833,6 +2834,7 @@ static int mlxsw_sp2_init(struct mlxsw_core *mlxsw_core,
	mlxsw_sp->span_ops = &mlxsw_sp2_span_ops;
	mlxsw_sp->span_ops = &mlxsw_sp2_span_ops;
	mlxsw_sp->policer_core_ops = &mlxsw_sp2_policer_core_ops;
	mlxsw_sp->policer_core_ops = &mlxsw_sp2_policer_core_ops;
	mlxsw_sp->trap_ops = &mlxsw_sp2_trap_ops;
	mlxsw_sp->trap_ops = &mlxsw_sp2_trap_ops;
	mlxsw_sp->mall_ops = &mlxsw_sp2_mall_ops;
	mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP2;
	mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP2;


	return mlxsw_sp_init(mlxsw_core, mlxsw_bus_info, extack);
	return mlxsw_sp_init(mlxsw_core, mlxsw_bus_info, extack);
@@ -2860,6 +2862,7 @@ static int mlxsw_sp3_init(struct mlxsw_core *mlxsw_core,
	mlxsw_sp->span_ops = &mlxsw_sp3_span_ops;
	mlxsw_sp->span_ops = &mlxsw_sp3_span_ops;
	mlxsw_sp->policer_core_ops = &mlxsw_sp2_policer_core_ops;
	mlxsw_sp->policer_core_ops = &mlxsw_sp2_policer_core_ops;
	mlxsw_sp->trap_ops = &mlxsw_sp2_trap_ops;
	mlxsw_sp->trap_ops = &mlxsw_sp2_trap_ops;
	mlxsw_sp->mall_ops = &mlxsw_sp2_mall_ops;
	mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP3;
	mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP3;


	return mlxsw_sp_init(mlxsw_core, mlxsw_bus_info, extack);
	return mlxsw_sp_init(mlxsw_core, mlxsw_bus_info, extack);
+11 −0
Original line number Original line Diff line number Diff line
@@ -179,6 +179,7 @@ struct mlxsw_sp {
	const struct mlxsw_sp_span_ops *span_ops;
	const struct mlxsw_sp_span_ops *span_ops;
	const struct mlxsw_sp_policer_core_ops *policer_core_ops;
	const struct mlxsw_sp_policer_core_ops *policer_core_ops;
	const struct mlxsw_sp_trap_ops *trap_ops;
	const struct mlxsw_sp_trap_ops *trap_ops;
	const struct mlxsw_sp_mall_ops *mall_ops;
	const struct mlxsw_listener *listeners;
	const struct mlxsw_listener *listeners;
	size_t listeners_count;
	size_t listeners_count;
	u32 lowest_shaper_bs;
	u32 lowest_shaper_bs;
@@ -1033,6 +1034,16 @@ extern const struct mlxsw_afk_ops mlxsw_sp1_afk_ops;
extern const struct mlxsw_afk_ops mlxsw_sp2_afk_ops;
extern const struct mlxsw_afk_ops mlxsw_sp2_afk_ops;


/* spectrum_matchall.c */
/* spectrum_matchall.c */
struct mlxsw_sp_mall_ops {
	int (*sample_add)(struct mlxsw_sp *mlxsw_sp,
			  struct mlxsw_sp_port *mlxsw_sp_port, u32 rate);
	void (*sample_del)(struct mlxsw_sp *mlxsw_sp,
			   struct mlxsw_sp_port *mlxsw_sp_port);
};

extern const struct mlxsw_sp_mall_ops mlxsw_sp1_mall_ops;
extern const struct mlxsw_sp_mall_ops mlxsw_sp2_mall_ops;

enum mlxsw_sp_mall_action_type {
enum mlxsw_sp_mall_action_type {
	MLXSW_SP_MALL_ACTION_TYPE_MIRROR,
	MLXSW_SP_MALL_ACTION_TYPE_MIRROR,
	MLXSW_SP_MALL_ACTION_TYPE_SAMPLE,
	MLXSW_SP_MALL_ACTION_TYPE_SAMPLE,
+29 −3
Original line number Original line Diff line number Diff line
@@ -96,6 +96,7 @@ static int
mlxsw_sp_mall_port_sample_add(struct mlxsw_sp_port *mlxsw_sp_port,
mlxsw_sp_mall_port_sample_add(struct mlxsw_sp_port *mlxsw_sp_port,
			      struct mlxsw_sp_mall_entry *mall_entry)
			      struct mlxsw_sp_mall_entry *mall_entry)
{
{
	struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
	int err;
	int err;


	if (rtnl_dereference(mlxsw_sp_port->sample)) {
	if (rtnl_dereference(mlxsw_sp_port->sample)) {
@@ -104,7 +105,7 @@ mlxsw_sp_mall_port_sample_add(struct mlxsw_sp_port *mlxsw_sp_port,
	}
	}
	rcu_assign_pointer(mlxsw_sp_port->sample, &mall_entry->sample);
	rcu_assign_pointer(mlxsw_sp_port->sample, &mall_entry->sample);


	err = mlxsw_sp_mall_port_sample_set(mlxsw_sp_port, true,
	err = mlxsw_sp->mall_ops->sample_add(mlxsw_sp, mlxsw_sp_port,
					     mall_entry->sample.rate);
					     mall_entry->sample.rate);
	if (err)
	if (err)
		goto err_port_sample_set;
		goto err_port_sample_set;
@@ -118,10 +119,12 @@ mlxsw_sp_mall_port_sample_add(struct mlxsw_sp_port *mlxsw_sp_port,
static void
static void
mlxsw_sp_mall_port_sample_del(struct mlxsw_sp_port *mlxsw_sp_port)
mlxsw_sp_mall_port_sample_del(struct mlxsw_sp_port *mlxsw_sp_port)
{
{
	struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;

	if (!mlxsw_sp_port->sample)
	if (!mlxsw_sp_port->sample)
		return;
		return;


	mlxsw_sp_mall_port_sample_set(mlxsw_sp_port, false, 1);
	mlxsw_sp->mall_ops->sample_del(mlxsw_sp, mlxsw_sp_port);
	RCU_INIT_POINTER(mlxsw_sp_port->sample, NULL);
	RCU_INIT_POINTER(mlxsw_sp_port->sample, NULL);
}
}


@@ -356,3 +359,26 @@ int mlxsw_sp_mall_prio_get(struct mlxsw_sp_flow_block *block, u32 chain_index,
	*p_max_prio = block->mall.max_prio;
	*p_max_prio = block->mall.max_prio;
	return 0;
	return 0;
}
}

static int mlxsw_sp1_mall_sample_add(struct mlxsw_sp *mlxsw_sp,
				     struct mlxsw_sp_port *mlxsw_sp_port,
				     u32 rate)
{
	return mlxsw_sp_mall_port_sample_set(mlxsw_sp_port, true, rate);
}

static void mlxsw_sp1_mall_sample_del(struct mlxsw_sp *mlxsw_sp,
				      struct mlxsw_sp_port *mlxsw_sp_port)
{
	mlxsw_sp_mall_port_sample_set(mlxsw_sp_port, false, 1);
}

const struct mlxsw_sp_mall_ops mlxsw_sp1_mall_ops = {
	.sample_add = mlxsw_sp1_mall_sample_add,
	.sample_del = mlxsw_sp1_mall_sample_del,
};

const struct mlxsw_sp_mall_ops mlxsw_sp2_mall_ops = {
	.sample_add = mlxsw_sp1_mall_sample_add,
	.sample_del = mlxsw_sp1_mall_sample_del,
};