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