xref: /linux/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.h (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
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_SD_GROUP,
14 	MLX5_DEVCOM_NUM_COMPONENTS,
15 };
16 
17 typedef int (*mlx5_devcom_event_handler_t)(int event,
18 					   void *my_data,
19 					   void *event_data);
20 
21 struct mlx5_devcom_dev *mlx5_devcom_register_device(struct mlx5_core_dev *dev);
22 void mlx5_devcom_unregister_device(struct mlx5_devcom_dev *devc);
23 
24 struct mlx5_devcom_comp_dev *
25 mlx5_devcom_register_component(struct mlx5_devcom_dev *devc,
26 			       enum mlx5_devcom_component id,
27 			       u64 key,
28 			       mlx5_devcom_event_handler_t handler,
29 			       void *data);
30 void mlx5_devcom_unregister_component(struct mlx5_devcom_comp_dev *devcom);
31 
32 int mlx5_devcom_send_event(struct mlx5_devcom_comp_dev *devcom,
33 			   int event, int rollback_event,
34 			   void *event_data);
35 int mlx5_devcom_comp_get_size(struct mlx5_devcom_comp_dev *devcom);
36 
37 void mlx5_devcom_comp_set_ready(struct mlx5_devcom_comp_dev *devcom, bool ready);
38 bool mlx5_devcom_comp_is_ready(struct mlx5_devcom_comp_dev *devcom);
39 
40 bool mlx5_devcom_for_each_peer_begin(struct mlx5_devcom_comp_dev *devcom);
41 void mlx5_devcom_for_each_peer_end(struct mlx5_devcom_comp_dev *devcom);
42 void *mlx5_devcom_get_next_peer_data(struct mlx5_devcom_comp_dev *devcom,
43 				     struct mlx5_devcom_comp_dev **pos);
44 
45 #define mlx5_devcom_for_each_peer_entry(devcom, data, pos)                    \
46 	for (pos = NULL, data = mlx5_devcom_get_next_peer_data(devcom, &pos); \
47 	     data;                                                            \
48 	     data = mlx5_devcom_get_next_peer_data(devcom, &pos))
49 
50 void *mlx5_devcom_get_next_peer_data_rcu(struct mlx5_devcom_comp_dev *devcom,
51 					 struct mlx5_devcom_comp_dev **pos);
52 
53 #define mlx5_devcom_for_each_peer_entry_rcu(devcom, data, pos)                    \
54 	for (pos = NULL, data = mlx5_devcom_get_next_peer_data_rcu(devcom, &pos); \
55 	     data;								  \
56 	     data = mlx5_devcom_get_next_peer_data_rcu(devcom, &pos))
57 
58 void mlx5_devcom_comp_lock(struct mlx5_devcom_comp_dev *devcom);
59 void mlx5_devcom_comp_unlock(struct mlx5_devcom_comp_dev *devcom);
60 int mlx5_devcom_comp_trylock(struct mlx5_devcom_comp_dev *devcom);
61 
62 #endif /* __LIB_MLX5_DEVCOM_H__ */
63