FILE
fs_ft_pool.c
File preview with syntax highlighting.
linux-6.19.14/drivers/net/ethernet/mellanox/mlx5/core/fs_ft_pool.c
1// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB 2/* Copyright (c) 2021 Mellanox Technologies. */ 3 4#include "fs_ft_pool.h" 5 6/* Firmware currently has 4 pool of 4 sizes that it supports (FT_POOLS), 7 * and a virtual memory region of 16M (MLX5_FT_SIZE), this region is duplicated 8 * for each flow table pool. We can allocate up to 16M of each pool, 9 * and we keep track of how much we used via mlx5_ft_pool_get_avail_sz. 10 * Firmware doesn't report any of this for now. 11 * ESW_POOL is expected to be sorted from large to small and match firmware 12 * pools. 13 */ 14#define FT_SIZE (16 * 1024 * 1024) 15static const unsigned int FT_POOLS[] = { 4 * 1024 * 1024, 16 1 * 1024 * 1024, 17 64 * 1024, 18 128, 19 1 /* size for termination tables */ }; 20struct mlx5_ft_pool { 21 int ft_left[ARRAY_SIZE(FT_POOLS)]; 22}; 23 24int mlx5_ft_pool_init(struct mlx5_core_dev *dev) 25{ 26 struct mlx5_ft_pool *ft_pool; 27 int i; 28 29 ft_pool = kzalloc(sizeof(*ft_pool), GFP_KERNEL); 30 if (!ft_pool) 31 return -ENOMEM; 32 33 for (i = ARRAY_SIZE(FT_POOLS) - 1; i >= 0; i--) 34 ft_pool->ft_left[i] = FT_SIZE / FT_POOLS[i]; 35 36 dev->priv.ft_pool = ft_pool; 37 return 0; 38} 39 40void mlx5_ft_pool_destroy(struct mlx5_core_dev *dev) 41{ 42 kfree(dev->priv.ft_pool); 43} 44 45int 46mlx5_ft_pool_get_avail_sz(struct mlx5_core_dev *dev, enum fs_flow_table_type table_type, 47 int desired_size) 48{ 49 u32 max_ft_size = 1 << MLX5_CAP_FLOWTABLE_TYPE(dev, log_max_ft_size, table_type); 50 int i, found_i = -1; 51 52 for (i = ARRAY_SIZE(FT_POOLS) - 1; i >= 0; i--) { 53 if (dev->priv.ft_pool->ft_left[i] && 54 (FT_POOLS[i] >= desired_size || 55 desired_size == MLX5_FS_MAX_POOL_SIZE) && 56 FT_POOLS[i] <= max_ft_size) { 57 found_i = i; 58 if (desired_size != MLX5_FS_MAX_POOL_SIZE) 59 break; 60 } 61 } 62 63 if (found_i != -1) { 64 --dev->priv.ft_pool->ft_left[found_i]; 65 return FT_POOLS[found_i]; 66 } 67 68 return 0; 69} 70 71void 72mlx5_ft_pool_put_sz(struct mlx5_core_dev *dev, int sz) 73{ 74 int i; 75 76 if (!sz) 77 return; 78 79 for (i = ARRAY_SIZE(FT_POOLS) - 1; i >= 0; i--) { 80 if (sz == FT_POOLS[i]) { 81 ++dev->priv.ft_pool->ft_left[i]; 82 return; 83 } 84 } 85 86 WARN_ONCE(1, "Couldn't find size %d in flow table size pool", sz); 87}
~/
Read-only file preview.