1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2018 Mellanox Technologies */
3 
4 #ifndef __LIB_MLX5_DEVCOM_H__
5 #define __LIB_MLX5_DEVCOM_H__
6 
7 #include <linux/mlx5/driver.h>
8 
9 enum mlx5_devcom_component {
10 	MLX5_DEVCOM_ESW_OFFLOADS,
11 	MLX5_DEVCOM_MPV,
12 	MLX5_DEVCOM_HCA_PORTS,
13 	MLX5_DEVCOM_NUM_COMPONENTS,
14 };
15 
16 typedef int (*mlx5_devcom_event_handler_t)(int event,
17 					   void *my_data,
18 					   void *event_data);
19 
20 struct mlx5_devcom_dev *mlx5_devcom_register_device(struct mlx5_core_dev *dev);
21 void mlx5_devcom_unregister_device(struct mlx5_devcom_dev *devc);
22 
23 struct mlx5_devcom_comp_dev *
24 mlx5_devcom_register_component(struct mlx5_devcom_dev *devc,
25 			       enum mlx5_devcom_component id,
26 			       u64 key,
27 			       mlx5_devcom_event_handler_t handler,
28 			       void *data);
29 void mlx5_devcom_unregister_component(struct mlx5_devcom_comp_dev *devcom);
30 
31 int mlx5_devcom_send_event(struct mlx5_devcom_comp_dev *devcom,
32 			   int event, int rollback_event,
33 			   void *event_data);
34 int mlx5_devcom_comp_get_size(struct mlx5_devcom_comp_dev *devcom);
35 
36 void mlx5_devcom_comp_set_ready(struct mlx5_devcom_comp_dev *devcom, bool ready);
37 bool mlx5_devcom_comp_is_ready(struct mlx5_devcom_comp_dev *devcom);
38 
39 bool mlx5_devcom_for_each_peer_begin(struct mlx5_devcom_comp_dev *devcom);
40 void mlx5_devcom_for_each_peer_end(struct mlx5_devcom_comp_dev *devcom);
41 void *mlx5_devcom_get_next_peer_data(struct mlx5_devcom_comp_dev *devcom,
42 				     struct mlx5_devcom_comp_dev **pos);
43 
44 #define mlx5_devcom_for_each_peer_entry(devcom, data, pos)                    \
45 	for (pos = NULL, data = mlx5_devcom_get_next_peer_data(devcom, &pos); \
46 	     data;                                                            \
47 	     data = mlx5_devcom_get_next_peer_data(devcom, &pos))
48 
49 void *mlx5_devcom_get_next_peer_data_rcu(struct mlx5_devcom_comp_dev *devcom,
50 					 struct mlx5_devcom_comp_dev **pos);
51 
52 #define mlx5_devcom_for_each_peer_entry_rcu(devcom, data, pos)                    \
53 	for (pos = NULL, data = mlx5_devcom_get_next_peer_data_rcu(devcom, &pos); \
54 	     data;								  \
55 	     data = mlx5_devcom_get_next_peer_data_rcu(devcom, &pos))
56 
57 void mlx5_devcom_comp_lock(struct mlx5_devcom_comp_dev *devcom);
58 void mlx5_devcom_comp_unlock(struct mlx5_devcom_comp_dev *devcom);
59 int mlx5_devcom_comp_trylock(struct mlx5_devcom_comp_dev *devcom);
60 
61 #endif /* __LIB_MLX5_DEVCOM_H__ */
62