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_NUM_COMPONENTS,
12 };
13 
14 typedef int (*mlx5_devcom_event_handler_t)(int event,
15 					   void *my_data,
16 					   void *event_data);
17 
18 struct mlx5_devcom_dev *mlx5_devcom_register_device(struct mlx5_core_dev *dev);
19 void mlx5_devcom_unregister_device(struct mlx5_devcom_dev *devc);
20 
21 struct mlx5_devcom_comp_dev *
22 mlx5_devcom_register_component(struct mlx5_devcom_dev *devc,
23 			       enum mlx5_devcom_component id,
24 			       u64 key,
25 			       mlx5_devcom_event_handler_t handler,
26 			       void *data);
27 void mlx5_devcom_unregister_component(struct mlx5_devcom_comp_dev *devcom);
28 
29 int mlx5_devcom_send_event(struct mlx5_devcom_comp_dev *devcom,
30 			   int event, int rollback_event,
31 			   void *event_data);
32 
33 void mlx5_devcom_comp_set_ready(struct mlx5_devcom_comp_dev *devcom, bool ready);
34 bool mlx5_devcom_comp_is_ready(struct mlx5_devcom_comp_dev *devcom);
35 
36 bool mlx5_devcom_for_each_peer_begin(struct mlx5_devcom_comp_dev *devcom);
37 void mlx5_devcom_for_each_peer_end(struct mlx5_devcom_comp_dev *devcom);
38 void *mlx5_devcom_get_next_peer_data(struct mlx5_devcom_comp_dev *devcom,
39 				     struct mlx5_devcom_comp_dev **pos);
40 
41 #define mlx5_devcom_for_each_peer_entry(devcom, data, pos)                    \
42 	for (pos = NULL, data = mlx5_devcom_get_next_peer_data(devcom, &pos); \
43 	     data;                                                            \
44 	     data = mlx5_devcom_get_next_peer_data(devcom, &pos))
45 
46 void *mlx5_devcom_get_next_peer_data_rcu(struct mlx5_devcom_comp_dev *devcom,
47 					 struct mlx5_devcom_comp_dev **pos);
48 
49 #define mlx5_devcom_for_each_peer_entry_rcu(devcom, data, pos)                    \
50 	for (pos = NULL, data = mlx5_devcom_get_next_peer_data_rcu(devcom, &pos); \
51 	     data;								  \
52 	     data = mlx5_devcom_get_next_peer_data_rcu(devcom, &pos))
53 
54 #endif /* __LIB_MLX5_DEVCOM_H__ */
55