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