xref: /linux/drivers/net/ethernet/mellanox/mlx5/core/lib/sd.h (revision 91ec2035134982b98fab0609a9fd8480e8217dc1)
1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */
3 
4 #ifndef __MLX5_LIB_SD_H__
5 #define __MLX5_LIB_SD_H__
6 
7 #include <linux/types.h>
8 
9 #define MLX5_SD_MIN_GROUP_SZ 2
10 #define MLX5_SD_MAX_GROUP_SZ 2
11 
12 struct mlx5_sd;
13 
14 struct mlx5_core_dev *mlx5_sd_get_primary(struct mlx5_core_dev *dev);
15 bool mlx5_sd_is_primary(struct mlx5_core_dev *dev);
16 int mlx5_sd_pf_num_get(struct mlx5_core_dev *dev);
17 struct mlx5_core_dev *mlx5_sd_primary_get_peer(struct mlx5_core_dev *primary, int idx);
18 int mlx5_sd_ch_ix_get_dev_ix(struct mlx5_core_dev *dev, int ch_ix);
19 int mlx5_sd_ch_ix_get_vec_ix(struct mlx5_core_dev *dev, int ch_ix);
20 struct mlx5_core_dev *mlx5_sd_ch_ix_get_dev(struct mlx5_core_dev *primary, int ch_ix);
21 struct auxiliary_device *mlx5_sd_get_adev(struct mlx5_core_dev *dev,
22 					  struct auxiliary_device *adev,
23 					  int idx);
24 void mlx5_sd_put_adev(struct auxiliary_device *actual_adev,
25 		      struct auxiliary_device *adev);
26 
27 #ifdef CONFIG_MLX5_CORE_EN
28 bool mlx5_sd_is_supported(struct mlx5_core_dev *dev);
29 #else
mlx5_sd_is_supported(struct mlx5_core_dev * dev)30 static inline bool mlx5_sd_is_supported(struct mlx5_core_dev *dev)
31 {
32 	return false;
33 }
34 #endif
35 
36 int mlx5_sd_init(struct mlx5_core_dev *dev);
37 void mlx5_sd_cleanup(struct mlx5_core_dev *dev);
38 
39 #ifdef CONFIG_MLX5_CORE_EN
40 struct mlx5_devcom_comp_dev *mlx5_sd_get_devcom(struct mlx5_core_dev *dev);
41 #else
42 static inline struct mlx5_devcom_comp_dev *
mlx5_sd_get_devcom(struct mlx5_core_dev * dev)43 mlx5_sd_get_devcom(struct mlx5_core_dev *dev)
44 {
45 	return NULL;
46 }
47 #endif
48 
49 #ifdef CONFIG_MLX5_ESWITCH
50 void mlx5_sd_eswitch_mode_set(struct mlx5_core_dev *dev, u16 mlx5_mode);
51 #else
52 static inline void
mlx5_sd_eswitch_mode_set(struct mlx5_core_dev * dev,u16 mlx5_mode)53 mlx5_sd_eswitch_mode_set(struct mlx5_core_dev *dev, u16 mlx5_mode) { return; }
54 #endif
55 
56 #define mlx5_sd_for_each_dev_from_to(i, primary, ix_from, to, pos)	\
57 	for (i = ix_from;							\
58 	     (pos = mlx5_sd_primary_get_peer(primary, i)) && pos != (to); i++)
59 
60 #define mlx5_sd_for_each_dev(i, primary, pos)				\
61 	mlx5_sd_for_each_dev_from_to(i, primary, 0, NULL, pos)
62 
63 #define mlx5_sd_for_each_dev_to(i, primary, to, pos)			\
64 	mlx5_sd_for_each_dev_from_to(i, primary, 0, to, pos)
65 
66 #define mlx5_sd_for_each_secondary(i, primary, pos)			\
67 	mlx5_sd_for_each_dev_from_to(i, primary, 1, NULL, pos)
68 
69 #define mlx5_sd_for_each_secondary_to(i, primary, to, pos)		\
70 	mlx5_sd_for_each_dev_from_to(i, primary, 1, to, pos)
71 
72 #endif /* __MLX5_LIB_SD_H__ */
73