1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2021 Mellanox Technologies Ltd */
3 
4 #ifndef __LIB_MLX5_SF_H__
5 #define __LIB_MLX5_SF_H__
6 
7 #include <linux/mlx5/driver.h>
8 
mlx5_sf_start_function_id(const struct mlx5_core_dev * dev)9 static inline u16 mlx5_sf_start_function_id(const struct mlx5_core_dev *dev)
10 {
11 	return MLX5_CAP_GEN(dev, sf_base_id);
12 }
13 
14 #ifdef CONFIG_MLX5_SF
15 
mlx5_sf_supported(const struct mlx5_core_dev * dev)16 static inline bool mlx5_sf_supported(const struct mlx5_core_dev *dev)
17 {
18 	return MLX5_CAP_GEN(dev, sf);
19 }
20 
mlx5_sf_max_functions(const struct mlx5_core_dev * dev)21 static inline u16 mlx5_sf_max_functions(const struct mlx5_core_dev *dev)
22 {
23 	if (!mlx5_sf_supported(dev))
24 		return 0;
25 	if (MLX5_CAP_GEN(dev, max_num_sf))
26 		return MLX5_CAP_GEN(dev, max_num_sf);
27 	else
28 		return 1 << MLX5_CAP_GEN(dev, log_max_sf);
29 }
30 
31 #else
32 
mlx5_sf_supported(const struct mlx5_core_dev * dev)33 static inline bool mlx5_sf_supported(const struct mlx5_core_dev *dev)
34 {
35 	return false;
36 }
37 
mlx5_sf_max_functions(const struct mlx5_core_dev * dev)38 static inline u16 mlx5_sf_max_functions(const struct mlx5_core_dev *dev)
39 {
40 	return 0;
41 }
42 
43 #endif
44 
45 #endif
46