1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /* Copyright (c) 2016-2018 Mellanox Technologies. All rights reserved */
4 #include <linux/kernel.h>
5 #include <linux/slab.h>
10 const struct mlxsw_sp_kvdl_ops *kvdl_ops;
11 unsigned long priv[0];
12 /* priv has to be always the last item */
15 int mlxsw_sp_kvdl_init(struct mlxsw_sp *mlxsw_sp)
17 const struct mlxsw_sp_kvdl_ops *kvdl_ops = mlxsw_sp->kvdl_ops;
18 struct mlxsw_sp_kvdl *kvdl;
21 kvdl = kzalloc(sizeof(*mlxsw_sp->kvdl) + kvdl_ops->priv_size,
25 kvdl->kvdl_ops = kvdl_ops;
26 mlxsw_sp->kvdl = kvdl;
28 err = kvdl_ops->init(mlxsw_sp, kvdl->priv);
38 void mlxsw_sp_kvdl_fini(struct mlxsw_sp *mlxsw_sp)
40 struct mlxsw_sp_kvdl *kvdl = mlxsw_sp->kvdl;
42 kvdl->kvdl_ops->fini(mlxsw_sp, kvdl->priv);
46 int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp,
47 enum mlxsw_sp_kvdl_entry_type type,
48 unsigned int entry_count, u32 *p_entry_index)
50 struct mlxsw_sp_kvdl *kvdl = mlxsw_sp->kvdl;
52 return kvdl->kvdl_ops->alloc(mlxsw_sp, kvdl->priv, type,
53 entry_count, p_entry_index);
56 void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp,
57 enum mlxsw_sp_kvdl_entry_type type,
58 unsigned int entry_count, int entry_index)
60 struct mlxsw_sp_kvdl *kvdl = mlxsw_sp->kvdl;
62 kvdl->kvdl_ops->free(mlxsw_sp, kvdl->priv, type,
63 entry_count, entry_index);
66 int mlxsw_sp_kvdl_alloc_count_query(struct mlxsw_sp *mlxsw_sp,
67 enum mlxsw_sp_kvdl_entry_type type,
68 unsigned int entry_count,
69 unsigned int *p_alloc_count)
71 struct mlxsw_sp_kvdl *kvdl = mlxsw_sp->kvdl;
73 return kvdl->kvdl_ops->alloc_size_query(mlxsw_sp, kvdl->priv, type,
74 entry_count, p_alloc_count);