mlxsw: spectrum: Register switched port analyzers (SPAN) as resource

The switch supports an enhanced switched port analyzer that enables
selecting network traffic for analysis by a network analyzer.

SPAN agents are configured and consumed whenever a tc filter is added
with a mirror action to a new destination. The destination can either be
a physical port (e.g., swp1), a VLAN device or a gretap.

Expose the maximum number of SPAN agents and their current usage to the
user.

Signed-off-by: Danielle Ratson <danieller@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Danielle Ratson 2019-10-17 09:55:14 +03:00 committed by David S. Miller
parent f86854a2e7
commit 868678c574
3 changed files with 73 additions and 2 deletions

View File

@ -5202,14 +5202,61 @@ static int mlxsw_sp2_resources_kvd_register(struct mlxsw_core *mlxsw_core)
&kvd_size_params);
}
static int mlxsw_sp_resources_span_register(struct mlxsw_core *mlxsw_core)
{
struct devlink *devlink = priv_to_devlink(mlxsw_core);
struct devlink_resource_size_params span_size_params;
u32 max_span;
if (!MLXSW_CORE_RES_VALID(mlxsw_core, MAX_SPAN))
return -EIO;
max_span = MLXSW_CORE_RES_GET(mlxsw_core, MAX_SPAN);
devlink_resource_size_params_init(&span_size_params, max_span, max_span,
1, DEVLINK_RESOURCE_UNIT_ENTRY);
return devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_SPAN,
max_span, MLXSW_SP_RESOURCE_SPAN,
DEVLINK_RESOURCE_ID_PARENT_TOP,
&span_size_params);
}
static int mlxsw_sp1_resources_register(struct mlxsw_core *mlxsw_core)
{
return mlxsw_sp1_resources_kvd_register(mlxsw_core);
int err;
err = mlxsw_sp1_resources_kvd_register(mlxsw_core);
if (err)
return err;
err = mlxsw_sp_resources_span_register(mlxsw_core);
if (err)
goto err_resources_span_register;
return 0;
err_resources_span_register:
devlink_resources_unregister(priv_to_devlink(mlxsw_core), NULL);
return err;
}
static int mlxsw_sp2_resources_register(struct mlxsw_core *mlxsw_core)
{
return mlxsw_sp2_resources_kvd_register(mlxsw_core);
int err;
err = mlxsw_sp2_resources_kvd_register(mlxsw_core);
if (err)
return err;
err = mlxsw_sp_resources_span_register(mlxsw_core);
if (err)
goto err_resources_span_register;
return 0;
err_resources_span_register:
devlink_resources_unregister(priv_to_devlink(mlxsw_core), NULL);
return err;
}
static int mlxsw_sp_kvd_sizes_get(struct mlxsw_core *mlxsw_core,

View File

@ -48,6 +48,8 @@
#define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_CHUNKS "chunks"
#define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_LARGE_CHUNKS "large_chunks"
#define MLXSW_SP_RESOURCE_NAME_SPAN "span_agents"
enum mlxsw_sp_resource_id {
MLXSW_SP_RESOURCE_KVD = 1,
MLXSW_SP_RESOURCE_KVD_LINEAR,
@ -56,6 +58,7 @@ enum mlxsw_sp_resource_id {
MLXSW_SP_RESOURCE_KVD_LINEAR_SINGLE,
MLXSW_SP_RESOURCE_KVD_LINEAR_CHUNKS,
MLXSW_SP_RESOURCE_KVD_LINEAR_LARGE_CHUNKS,
MLXSW_SP_RESOURCE_SPAN,
};
struct mlxsw_sp_port;

View File

@ -14,8 +14,23 @@
#include "spectrum_span.h"
#include "spectrum_switchdev.h"
static u64 mlxsw_sp_span_occ_get(void *priv)
{
const struct mlxsw_sp *mlxsw_sp = priv;
u64 occ = 0;
int i;
for (i = 0; i < mlxsw_sp->span.entries_count; i++) {
if (mlxsw_sp->span.entries[i].ref_count)
occ++;
}
return occ;
}
int mlxsw_sp_span_init(struct mlxsw_sp *mlxsw_sp)
{
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
int i;
if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, MAX_SPAN))
@ -36,13 +51,19 @@ int mlxsw_sp_span_init(struct mlxsw_sp *mlxsw_sp)
curr->id = i;
}
devlink_resource_occ_get_register(devlink, MLXSW_SP_RESOURCE_SPAN,
mlxsw_sp_span_occ_get, mlxsw_sp);
return 0;
}
void mlxsw_sp_span_fini(struct mlxsw_sp *mlxsw_sp)
{
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
int i;
devlink_resource_occ_get_unregister(devlink, MLXSW_SP_RESOURCE_SPAN);
for (i = 0; i < mlxsw_sp->span.entries_count; i++) {
struct mlxsw_sp_span_entry *curr = &mlxsw_sp->span.entries[i];