mlxsw: spectrum_kvdl: Pass entry type to alloc/free
authorJiri Pirko <jiri@mellanox.com>
Sun, 8 Jul 2018 20:51:17 +0000 (23:51 +0300)
committerDavid S. Miller <davem@davemloft.net>
Mon, 9 Jul 2018 23:24:16 +0000 (16:24 -0700)
Future Spectrum-2 KVD linear manager implementation needs to know type
of the entry to alloc and free. So define the types in an enum and
pass it down to alloc and free functions. Once the entry type
is passed down, KVDL common part knows sizes of each entry types,
so replace size function arg with entry count.

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/spectrum1_kvdl.c
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_flex_actions.c
drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c
drivers/net/ethernet/mellanox/mlxsw/spectrum_mr_tcam.c
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c

index 334cdb6a70102066f3ee812b22863a3326365696..a67d1dd8a607364b06a8d5ef2a7424e0fffd5b34 100644 (file)
@@ -438,28 +438,55 @@ mlxsw_sp_port_vlan_router_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
 void mlxsw_sp_rif_destroy(struct mlxsw_sp_rif *rif);
 
 /* spectrum_kvdl.c */
+enum mlxsw_sp_kvdl_entry_type {
+       MLXSW_SP_KVDL_ENTRY_TYPE_ADJ,
+       MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET,
+       MLXSW_SP_KVDL_ENTRY_TYPE_PBS,
+       MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR,
+};
+
+static inline unsigned int
+mlxsw_sp_kvdl_entry_size(enum mlxsw_sp_kvdl_entry_type type)
+{
+       switch (type) {
+       case MLXSW_SP_KVDL_ENTRY_TYPE_ADJ: /* fall through */
+       case MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET: /* fall through */
+       case MLXSW_SP_KVDL_ENTRY_TYPE_PBS: /* fall through */
+       case MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR: /* fall through */
+       default:
+               return 1;
+       }
+}
+
 struct mlxsw_sp_kvdl_ops {
        size_t priv_size;
        int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
        void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
        int (*alloc)(struct mlxsw_sp *mlxsw_sp, void *priv,
+                    enum mlxsw_sp_kvdl_entry_type type,
                     unsigned int entry_count, u32 *p_entry_index);
        void (*free)(struct mlxsw_sp *mlxsw_sp, void *priv,
+                    enum mlxsw_sp_kvdl_entry_type type,
                     int entry_index);
        int (*alloc_size_query)(struct mlxsw_sp *mlxsw_sp, void *priv,
+                               enum mlxsw_sp_kvdl_entry_type type,
                                unsigned int entry_count,
-                               unsigned int *p_alloc_size);
+                               unsigned int *p_alloc_count);
        int (*resources_register)(struct mlxsw_sp *mlxsw_sp, void *priv);
 };
 
 int mlxsw_sp_kvdl_init(struct mlxsw_sp *mlxsw_sp);
 void mlxsw_sp_kvdl_fini(struct mlxsw_sp *mlxsw_sp);
-int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp, unsigned int entry_count,
-                       u32 *p_entry_index);
-void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp, int entry_index);
-int mlxsw_sp_kvdl_alloc_size_query(struct mlxsw_sp *mlxsw_sp,
-                                  unsigned int entry_count,
-                                  unsigned int *p_alloc_size);
+int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp,
+                       enum mlxsw_sp_kvdl_entry_type type,
+                       unsigned int entry_count, u32 *p_entry_index);
+void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp,
+                       enum mlxsw_sp_kvdl_entry_type type,
+                       int entry_index);
+int mlxsw_sp_kvdl_alloc_count_query(struct mlxsw_sp *mlxsw_sp,
+                                   enum mlxsw_sp_kvdl_entry_type type,
+                                   unsigned int entry_count,
+                                   unsigned int *p_alloc_count);
 
 /* spectrum1_kvdl.c */
 extern const struct mlxsw_sp_kvdl_ops mlxsw_sp1_kvdl_ops;
index afcadaad8eddd327e467f3064799c7de91197575..86e0b993f8b37795d613296c1f7320ae8505d702 100644 (file)
@@ -175,6 +175,7 @@ static void mlxsw_sp1_kvdl_part_free(struct mlxsw_sp1_kvdl_part *part,
 }
 
 static int mlxsw_sp1_kvdl_alloc(struct mlxsw_sp *mlxsw_sp, void *priv,
+                               enum mlxsw_sp_kvdl_entry_type type,
                                unsigned int entry_count,
                                u32 *p_entry_index)
 {
@@ -192,6 +193,7 @@ static int mlxsw_sp1_kvdl_alloc(struct mlxsw_sp *mlxsw_sp, void *priv,
 }
 
 static void mlxsw_sp1_kvdl_free(struct mlxsw_sp *mlxsw_sp, void *priv,
+                               enum mlxsw_sp_kvdl_entry_type type,
                                int entry_index)
 {
        struct mlxsw_sp1_kvdl *kvdl = priv;
@@ -204,7 +206,9 @@ static void mlxsw_sp1_kvdl_free(struct mlxsw_sp *mlxsw_sp, void *priv,
 }
 
 static int mlxsw_sp1_kvdl_alloc_size_query(struct mlxsw_sp *mlxsw_sp,
-                                          void *priv, unsigned int entry_count,
+                                          void *priv,
+                                          enum mlxsw_sp_kvdl_entry_type type,
+                                          unsigned int entry_count,
                                           unsigned int *p_alloc_size)
 {
        struct mlxsw_sp1_kvdl *kvdl = priv;
index 5ab070916949d5a9d6891c2d4b9722eb909d4c22..f98fb2c76cd8efc4355c304e58b82d0c920c6aca 100644 (file)
@@ -37,8 +37,6 @@
 #include "core_acl_flex_actions.h"
 #include "spectrum_span.h"
 
-#define MLXSW_SP_KVDL_ACT_EXT_SIZE 1
-
 static int mlxsw_sp_act_kvdl_set_add(void *priv, u32 *p_kvdl_index,
                                     char *enc_actions, bool is_first)
 {
@@ -53,8 +51,8 @@ static int mlxsw_sp_act_kvdl_set_add(void *priv, u32 *p_kvdl_index,
        if (is_first)
                return 0;
 
-       err = mlxsw_sp_kvdl_alloc(mlxsw_sp, MLXSW_SP_KVDL_ACT_EXT_SIZE,
-                                 &kvdl_index);
+       err = mlxsw_sp_kvdl_alloc(mlxsw_sp, MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET,
+                                 1, &kvdl_index);
        if (err)
                return err;
        mlxsw_reg_pefa_pack(pefa_pl, kvdl_index, enc_actions);
@@ -65,7 +63,8 @@ static int mlxsw_sp_act_kvdl_set_add(void *priv, u32 *p_kvdl_index,
        return 0;
 
 err_pefa_write:
-       mlxsw_sp_kvdl_free(mlxsw_sp, kvdl_index);
+       mlxsw_sp_kvdl_free(mlxsw_sp, MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET,
+                          kvdl_index);
        return err;
 }
 
@@ -76,7 +75,8 @@ static void mlxsw_sp_act_kvdl_set_del(void *priv, u32 kvdl_index,
 
        if (is_first)
                return;
-       mlxsw_sp_kvdl_free(mlxsw_sp, kvdl_index);
+       mlxsw_sp_kvdl_free(mlxsw_sp, MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET,
+                          kvdl_index);
 }
 
 static int mlxsw_sp_act_kvdl_fwd_entry_add(void *priv, u32 *p_kvdl_index,
@@ -87,7 +87,8 @@ static int mlxsw_sp_act_kvdl_fwd_entry_add(void *priv, u32 *p_kvdl_index,
        u32 kvdl_index;
        int err;
 
-       err = mlxsw_sp_kvdl_alloc(mlxsw_sp, 1, &kvdl_index);
+       err = mlxsw_sp_kvdl_alloc(mlxsw_sp, MLXSW_SP_KVDL_ENTRY_TYPE_PBS,
+                                 1, &kvdl_index);
        if (err)
                return err;
        mlxsw_reg_ppbs_pack(ppbs_pl, kvdl_index, local_port);
@@ -98,7 +99,8 @@ static int mlxsw_sp_act_kvdl_fwd_entry_add(void *priv, u32 *p_kvdl_index,
        return 0;
 
 err_ppbs_write:
-       mlxsw_sp_kvdl_free(mlxsw_sp, kvdl_index);
+       mlxsw_sp_kvdl_free(mlxsw_sp, MLXSW_SP_KVDL_ENTRY_TYPE_PBS,
+                          kvdl_index);
        return err;
 }
 
@@ -106,7 +108,8 @@ static void mlxsw_sp_act_kvdl_fwd_entry_del(void *priv, u32 kvdl_index)
 {
        struct mlxsw_sp *mlxsw_sp = priv;
 
-       mlxsw_sp_kvdl_free(mlxsw_sp, kvdl_index);
+       mlxsw_sp_kvdl_free(mlxsw_sp, MLXSW_SP_KVDL_ENTRY_TYPE_PBS,
+                          kvdl_index);
 }
 
 static int
index 2b514e47ca2be0333403a671a8f331d8a7478c7e..3f9130afe5eaab1dd54787288dffda091514f530 100644 (file)
@@ -74,28 +74,32 @@ void mlxsw_sp_kvdl_fini(struct mlxsw_sp *mlxsw_sp)
        kfree(kvdl);
 }
 
-int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp, unsigned int entry_count,
-                       u32 *p_entry_index)
+int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp,
+                       enum mlxsw_sp_kvdl_entry_type type,
+                       unsigned int entry_count, u32 *p_entry_index)
 {
        struct mlxsw_sp_kvdl *kvdl = mlxsw_sp->kvdl;
 
-       return kvdl->kvdl_ops->alloc(mlxsw_sp, kvdl->priv,
+       return kvdl->kvdl_ops->alloc(mlxsw_sp, kvdl->priv, type,
                                     entry_count, p_entry_index);
 }
 
-void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp, int entry_index)
+void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp,
+                       enum mlxsw_sp_kvdl_entry_type type,
+                       int entry_index)
 {
        struct mlxsw_sp_kvdl *kvdl = mlxsw_sp->kvdl;
 
-       kvdl->kvdl_ops->free(mlxsw_sp, kvdl->priv, entry_index);
+       kvdl->kvdl_ops->free(mlxsw_sp, kvdl->priv, type, entry_index);
 }
 
-int mlxsw_sp_kvdl_alloc_size_query(struct mlxsw_sp *mlxsw_sp,
-                                  unsigned int entry_count,
-                                  unsigned int *p_alloc_size)
+int mlxsw_sp_kvdl_alloc_count_query(struct mlxsw_sp *mlxsw_sp,
+                                   enum mlxsw_sp_kvdl_entry_type type,
+                                   unsigned int entry_count,
+                                   unsigned int *p_alloc_count)
 {
        struct mlxsw_sp_kvdl *kvdl = mlxsw_sp->kvdl;
 
-       return kvdl->kvdl_ops->alloc_size_query(mlxsw_sp, kvdl->priv,
-                                               entry_count, p_alloc_size);
+       return kvdl->kvdl_ops->alloc_size_query(mlxsw_sp, kvdl->priv, type,
+                                               entry_count, p_alloc_count);
 }
index 4f4c0d31188364a9f9821a5dbcd6653622ac3461..d1fd85ade4250b5cd7bbd1de38a3b16d65c5a3e4 100644 (file)
@@ -84,8 +84,6 @@ mlxsw_sp_mr_erif_list_init(struct mlxsw_sp_mr_tcam_erif_list *erif_list)
        INIT_LIST_HEAD(&erif_list->erif_sublists);
 }
 
-#define MLXSW_SP_KVDL_RIGR2_SIZE 1
-
 static struct mlxsw_sp_mr_erif_sublist *
 mlxsw_sp_mr_erif_sublist_create(struct mlxsw_sp *mlxsw_sp,
                                struct mlxsw_sp_mr_tcam_erif_list *erif_list)
@@ -96,8 +94,8 @@ mlxsw_sp_mr_erif_sublist_create(struct mlxsw_sp *mlxsw_sp,
        erif_sublist = kzalloc(sizeof(*erif_sublist), GFP_KERNEL);
        if (!erif_sublist)
                return ERR_PTR(-ENOMEM);
-       err = mlxsw_sp_kvdl_alloc(mlxsw_sp, MLXSW_SP_KVDL_RIGR2_SIZE,
-                                 &erif_sublist->rigr2_kvdl_index);
+       err = mlxsw_sp_kvdl_alloc(mlxsw_sp, MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR,
+                                 1, &erif_sublist->rigr2_kvdl_index);
        if (err) {
                kfree(erif_sublist);
                return ERR_PTR(err);
@@ -112,7 +110,8 @@ mlxsw_sp_mr_erif_sublist_destroy(struct mlxsw_sp *mlxsw_sp,
                                 struct mlxsw_sp_mr_erif_sublist *erif_sublist)
 {
        list_del(&erif_sublist->list);
-       mlxsw_sp_kvdl_free(mlxsw_sp, erif_sublist->rigr2_kvdl_index);
+       mlxsw_sp_kvdl_free(mlxsw_sp, MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR,
+                          erif_sublist->rigr2_kvdl_index);
        kfree(erif_sublist);
 }
 
index 79dcadb40857631473b3c55fbe08de4e56d839e7..fb5980e92e3b61eb6e4044c69ffd69a733d349f3 100644 (file)
@@ -1106,7 +1106,8 @@ mlxsw_sp_fib_entry_decap_init(struct mlxsw_sp *mlxsw_sp,
        u32 tunnel_index;
        int err;
 
-       err = mlxsw_sp_kvdl_alloc(mlxsw_sp, 1, &tunnel_index);
+       err = mlxsw_sp_kvdl_alloc(mlxsw_sp, MLXSW_SP_KVDL_ENTRY_TYPE_ADJ,
+                                 1, &tunnel_index);
        if (err)
                return err;
 
@@ -1122,7 +1123,8 @@ static void mlxsw_sp_fib_entry_decap_fini(struct mlxsw_sp *mlxsw_sp,
        /* Unlink this node from the IPIP entry that it's the decap entry of. */
        fib_entry->decap.ipip_entry->decap_fib_entry = NULL;
        fib_entry->decap.ipip_entry = NULL;
-       mlxsw_sp_kvdl_free(mlxsw_sp, fib_entry->decap.tunnel_index);
+       mlxsw_sp_kvdl_free(mlxsw_sp, MLXSW_SP_KVDL_ENTRY_TYPE_ADJ,
+                          fib_entry->decap.tunnel_index);
 }
 
 static struct mlxsw_sp_fib_node *
@@ -3162,8 +3164,9 @@ static int mlxsw_sp_fix_adj_grp_size(struct mlxsw_sp *mlxsw_sp,
         * by the device and make sure the request can be satisfied.
         */
        mlxsw_sp_adj_grp_size_round_up(p_adj_grp_size);
-       err = mlxsw_sp_kvdl_alloc_size_query(mlxsw_sp, *p_adj_grp_size,
-                                            &alloc_size);
+       err = mlxsw_sp_kvdl_alloc_count_query(mlxsw_sp,
+                                             MLXSW_SP_KVDL_ENTRY_TYPE_ADJ,
+                                             *p_adj_grp_size, &alloc_size);
        if (err)
                return err;
        /* It is possible the allocation results in more allocated
@@ -3275,7 +3278,8 @@ mlxsw_sp_nexthop_group_refresh(struct mlxsw_sp *mlxsw_sp,
                /* No valid allocation size available. */
                goto set_trap;
 
-       err = mlxsw_sp_kvdl_alloc(mlxsw_sp, ecmp_size, &adj_index);
+       err = mlxsw_sp_kvdl_alloc(mlxsw_sp, MLXSW_SP_KVDL_ENTRY_TYPE_ADJ,
+                                 ecmp_size, &adj_index);
        if (err) {
                /* We ran out of KVD linear space, just set the
                 * trap and let everything flow through kernel.
@@ -3310,7 +3314,8 @@ mlxsw_sp_nexthop_group_refresh(struct mlxsw_sp *mlxsw_sp,
 
        err = mlxsw_sp_adj_index_mass_update(mlxsw_sp, nh_grp,
                                             old_adj_index, old_ecmp_size);
-       mlxsw_sp_kvdl_free(mlxsw_sp, old_adj_index);
+       mlxsw_sp_kvdl_free(mlxsw_sp, MLXSW_SP_KVDL_ENTRY_TYPE_ADJ,
+                          old_adj_index);
        if (err) {
                dev_warn(mlxsw_sp->bus_info->dev, "Failed to mass-update adjacency index for nexthop group.\n");
                goto set_trap;
@@ -3332,7 +3337,8 @@ set_trap:
        if (err)
                dev_warn(mlxsw_sp->bus_info->dev, "Failed to set traps for fib entries.\n");
        if (old_adj_index_valid)
-               mlxsw_sp_kvdl_free(mlxsw_sp, nh_grp->adj_index);
+               mlxsw_sp_kvdl_free(mlxsw_sp, MLXSW_SP_KVDL_ENTRY_TYPE_ADJ,
+                                  nh_grp->adj_index);
 }
 
 static void __mlxsw_sp_nexthop_neigh_update(struct mlxsw_sp_nexthop *nh,