1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ 2 /* Copyright (c) 2024 NVIDIA Corporation & Affiliates */ 3 4 #ifndef __MLX5_FS_POOL_H__ 5 #define __MLX5_FS_POOL_H__ 6 7 #include <linux/mlx5/driver.h> 8 9 struct mlx5_fs_bulk { 10 struct list_head pool_list; 11 int bulk_len; 12 unsigned long *bitmask; 13 }; 14 15 struct mlx5_fs_pool_index { 16 struct mlx5_fs_bulk *fs_bulk; 17 int index; 18 }; 19 20 struct mlx5_fs_pool; 21 22 struct mlx5_fs_pool_ops { 23 int (*bulk_destroy)(struct mlx5_core_dev *dev, struct mlx5_fs_bulk *bulk); 24 struct mlx5_fs_bulk * (*bulk_create)(struct mlx5_core_dev *dev, 25 void *pool_ctx); 26 void (*update_threshold)(struct mlx5_fs_pool *pool); 27 }; 28 29 struct mlx5_fs_pool { 30 struct mlx5_core_dev *dev; 31 void *pool_ctx; 32 const struct mlx5_fs_pool_ops *ops; 33 struct mutex pool_lock; /* protects pool lists */ 34 struct list_head fully_used; 35 struct list_head partially_used; 36 struct list_head unused; 37 int available_units; 38 int used_units; 39 int threshold; 40 }; 41 42 int mlx5_fs_bulk_init(struct mlx5_core_dev *dev, struct mlx5_fs_bulk *fs_bulk, 43 int bulk_len); 44 void mlx5_fs_bulk_cleanup(struct mlx5_fs_bulk *fs_bulk); 45 int mlx5_fs_bulk_get_free_amount(struct mlx5_fs_bulk *bulk); 46 47 void mlx5_fs_pool_init(struct mlx5_fs_pool *pool, struct mlx5_core_dev *dev, 48 const struct mlx5_fs_pool_ops *ops, void *pool_ctx); 49 void mlx5_fs_pool_cleanup(struct mlx5_fs_pool *pool); 50 int mlx5_fs_pool_acquire_index(struct mlx5_fs_pool *fs_pool, 51 struct mlx5_fs_pool_index *pool_index); 52 int mlx5_fs_pool_release_index(struct mlx5_fs_pool *fs_pool, 53 struct mlx5_fs_pool_index *pool_index); 54 55 #endif /* __MLX5_FS_POOL_H__ */ 56