Skip to content

Commit

Permalink
mlxsw: spectrum_acl: Implement basic ERP rehash hits creation
Browse files Browse the repository at this point in the history
Introduce an initial implementation of rehash logic in ERP code.
Currently, the rehash is considered as needed only in case number of
roots in the hints is smaller than the number of roots actually in use.
In that case return hints pointer and let it be obtained through the
callpath through the Spectrum-2 TCAM op.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jiri Pirko authored and David S. Miller committed Feb 8, 2019
1 parent c4c2dc5 commit 29a2102
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/net/ethernet/mellanox/mlxsw/spectrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,8 @@ struct mlxsw_sp_acl_tcam_ops {
void (*region_fini)(struct mlxsw_sp *mlxsw_sp, void *region_priv);
int (*region_associate)(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_acl_tcam_region *region);
void * (*region_rehash_hints_get)(void *region_priv);
void (*region_rehash_hints_put)(void *hints_priv);
size_t chunk_priv_size;
void (*chunk_init)(void *region_priv, void *chunk_priv,
unsigned int priority);
Expand Down
14 changes: 14 additions & 0 deletions drivers/net/ethernet/mellanox/mlxsw/spectrum2_acl_tcam.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ mlxsw_sp2_acl_tcam_region_associate(struct mlxsw_sp *mlxsw_sp,
return mlxsw_sp_acl_atcam_region_associate(mlxsw_sp, region->id);
}

static void *mlxsw_sp2_acl_tcam_region_rehash_hints_get(void *region_priv)
{
struct mlxsw_sp2_acl_tcam_region *region = region_priv;

return mlxsw_sp_acl_atcam_rehash_hints_get(&region->aregion);
}

static void mlxsw_sp2_acl_tcam_region_rehash_hints_put(void *hints_priv)
{
mlxsw_sp_acl_atcam_rehash_hints_put(hints_priv);
}

static void mlxsw_sp2_acl_tcam_chunk_init(void *region_priv, void *chunk_priv,
unsigned int priority)
{
Expand Down Expand Up @@ -243,6 +255,8 @@ const struct mlxsw_sp_acl_tcam_ops mlxsw_sp2_acl_tcam_ops = {
.region_init = mlxsw_sp2_acl_tcam_region_init,
.region_fini = mlxsw_sp2_acl_tcam_region_fini,
.region_associate = mlxsw_sp2_acl_tcam_region_associate,
.region_rehash_hints_get = mlxsw_sp2_acl_tcam_region_rehash_hints_get,
.region_rehash_hints_put = mlxsw_sp2_acl_tcam_region_rehash_hints_put,
.chunk_priv_size = sizeof(struct mlxsw_sp2_acl_tcam_chunk),
.chunk_init = mlxsw_sp2_acl_tcam_chunk_init,
.chunk_fini = mlxsw_sp2_acl_tcam_chunk_fini,
Expand Down
11 changes: 11 additions & 0 deletions drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_atcam.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,3 +634,14 @@ void mlxsw_sp_acl_atcam_fini(struct mlxsw_sp *mlxsw_sp,
{
mlxsw_sp_acl_erps_fini(mlxsw_sp, atcam);
}

void *
mlxsw_sp_acl_atcam_rehash_hints_get(struct mlxsw_sp_acl_atcam_region *aregion)
{
return mlxsw_sp_acl_erp_rehash_hints_get(aregion);
}

void mlxsw_sp_acl_atcam_rehash_hints_put(void *hints_priv)
{
mlxsw_sp_acl_erp_rehash_hints_put(hints_priv);
}
74 changes: 74 additions & 0 deletions drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_erp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,80 @@ mlxsw_sp_acl_erp_region_param_init(struct mlxsw_sp_acl_atcam_region *aregion)
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pererp), pererp_pl);
}

static int
mlxsw_sp_acl_erp_hints_check(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_acl_atcam_region *aregion,
struct objagg_hints *hints, bool *p_rehash_needed)
{
struct objagg *objagg = aregion->erp_table->objagg;
const struct objagg_stats *ostats;
const struct objagg_stats *hstats;
int err;

*p_rehash_needed = false;

ostats = objagg_stats_get(objagg);
if (IS_ERR(ostats)) {
dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Failed to get ERP stats\n");
return PTR_ERR(ostats);
}

hstats = objagg_hints_stats_get(hints);
if (IS_ERR(hstats)) {
dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Failed to get ERP hints stats\n");
err = PTR_ERR(hstats);
goto err_hints_stats_get;
}

/* Very basic criterion for now. */
if (hstats->root_count < ostats->root_count)
*p_rehash_needed = true;

err = 0;

objagg_stats_put(hstats);
err_hints_stats_get:
objagg_stats_put(ostats);
return err;
}

void *
mlxsw_sp_acl_erp_rehash_hints_get(struct mlxsw_sp_acl_atcam_region *aregion)
{
struct mlxsw_sp *mlxsw_sp = aregion->region->mlxsw_sp;
struct objagg_hints *hints;
bool rehash_needed;
int err;

hints = objagg_hints_get(aregion->erp_table->objagg,
OBJAGG_OPT_ALGO_SIMPLE_GREEDY);
if (IS_ERR(hints)) {
dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Failed to create ERP hints\n");
return ERR_CAST(hints);
}
err = mlxsw_sp_acl_erp_hints_check(mlxsw_sp, aregion, hints,
&rehash_needed);
if (err)
goto errout;

if (!rehash_needed) {
err = -EAGAIN;
goto errout;
}
return hints;

errout:
objagg_hints_put(hints);
return ERR_PTR(err);
}

void mlxsw_sp_acl_erp_rehash_hints_put(void *hints_priv)
{
struct objagg_hints *hints = hints_priv;

objagg_hints_put(hints);
}

int mlxsw_sp_acl_erp_region_init(struct mlxsw_sp_acl_atcam_region *aregion)
{
struct mlxsw_sp_acl_erp_table *erp_table;
Expand Down
6 changes: 6 additions & 0 deletions drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ int mlxsw_sp_acl_atcam_init(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_acl_atcam *atcam);
void mlxsw_sp_acl_atcam_fini(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_acl_atcam *atcam);
void *
mlxsw_sp_acl_atcam_rehash_hints_get(struct mlxsw_sp_acl_atcam_region *aregion);
void mlxsw_sp_acl_atcam_rehash_hints_put(void *hints_priv);

struct mlxsw_sp_acl_erp_delta;

Expand Down Expand Up @@ -259,6 +262,9 @@ void mlxsw_sp_acl_erp_bf_remove(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_acl_atcam_region *aregion,
struct mlxsw_sp_acl_erp_mask *erp_mask,
struct mlxsw_sp_acl_atcam_entry *aentry);
void *
mlxsw_sp_acl_erp_rehash_hints_get(struct mlxsw_sp_acl_atcam_region *aregion);
void mlxsw_sp_acl_erp_rehash_hints_put(void *hints_priv);
int mlxsw_sp_acl_erp_region_init(struct mlxsw_sp_acl_atcam_region *aregion);
void mlxsw_sp_acl_erp_region_fini(struct mlxsw_sp_acl_atcam_region *aregion);
int mlxsw_sp_acl_erps_init(struct mlxsw_sp *mlxsw_sp,
Expand Down

0 comments on commit 29a2102

Please sign in to comment.