mlxsw: spectrum_acl: Implement basic ERP rehash hits creation
authorJiri Pirko <jiri@mellanox.com>
Thu, 7 Feb 2019 11:22:51 +0000 (11:22 +0000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 8 Feb 2019 23:02:49 +0000 (15:02 -0800)
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>
drivers/net/ethernet/mellanox/mlxsw/spectrum.h
drivers/net/ethernet/mellanox/mlxsw/spectrum2_acl_tcam.c
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_atcam.c
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_erp.c
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.h

index 4fe0996c7cddb8c2ad0dee198f498ea0a76cff70..6432a1ce51f341be8ef03047b86affb03bc388cf 100644 (file)
@@ -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);
index d380b34039603585e38dbdfcbb0738c6d617ae26..4808b29294d0b03ffd5fdc7dcab89c29d92457c4 100644 (file)
@@ -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)
 {
@@ -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,
index a74a390901ac82a0afe924dd51cf73225fa4f130..e98037e4d03e00108fe178e12a3fe14ef5810672 100644 (file)
@@ -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);
+}
index 302070a74f2e7f981ee2fa5f7ce15851fcdd987c..013ab43a7727dd43573f80e0854fe67cd7ab28de 100644 (file)
@@ -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;
index c6d4aac82ddbb278979d06a617823f7ea25da6c2..a90942bc1fe9bcf4e8d6c71ee9995815c409615f 100644 (file)
@@ -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;
 
@@ -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,