xref: /linux/drivers/net/ethernet/mellanox/mlx5/core/lib/sd.h (revision fcee7d82f27d6a8b1ddc5bbefda59b4e441e9bc0)
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 #define MLX5_SD_MAX_GROUP_SZ 2
8 
9 struct mlx5_sd;
10 
11 struct mlx5_core_dev *mlx5_sd_primary_get_peer(struct mlx5_core_dev *primary, int idx);
12 int mlx5_sd_ch_ix_get_dev_ix(struct mlx5_core_dev *dev, int ch_ix);
13 int mlx5_sd_ch_ix_get_vec_ix(struct mlx5_core_dev *dev, int ch_ix);
14 struct mlx5_core_dev *mlx5_sd_ch_ix_get_dev(struct mlx5_core_dev *primary, int ch_ix);
15 struct auxiliary_device *mlx5_sd_get_adev(struct mlx5_core_dev *dev,
16 					  struct auxiliary_device *adev,
17 					  int idx);
18 void mlx5_sd_put_adev(struct auxiliary_device *actual_adev,
19 		      struct auxiliary_device *adev);
20 
21 int mlx5_sd_init(struct mlx5_core_dev *dev);
22 void mlx5_sd_cleanup(struct mlx5_core_dev *dev);
23 
24 #define mlx5_sd_for_each_dev_from_to(i, primary, ix_from, to, pos)	\
25 	for (i = ix_from;							\
26 	     (pos = mlx5_sd_primary_get_peer(primary, i)) && pos != (to); i++)
27 
28 #define mlx5_sd_for_each_dev(i, primary, pos)				\
29 	mlx5_sd_for_each_dev_from_to(i, primary, 0, NULL, pos)
30 
31 #define mlx5_sd_for_each_dev_to(i, primary, to, pos)			\
32 	mlx5_sd_for_each_dev_from_to(i, primary, 0, to, pos)
33 
34 #define mlx5_sd_for_each_secondary(i, primary, pos)			\
35 	mlx5_sd_for_each_dev_from_to(i, primary, 1, NULL, pos)
36 
37 #define mlx5_sd_for_each_secondary_to(i, primary, to, pos)		\
38 	mlx5_sd_for_each_dev_from_to(i, primary, 1, to, pos)
39 
40 #endif /* __MLX5_LIB_SD_H__ */
41