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 #define MLX5_DEVCOM_PORTS_SUPPORTED 4 10 11 enum mlx5_devcom_components { 12 MLX5_DEVCOM_ESW_OFFLOADS, 13 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 *mlx5_devcom_register_device(struct mlx5_core_dev *dev); 22 void mlx5_devcom_unregister_device(struct mlx5_devcom *devcom); 23 24 void mlx5_devcom_register_component(struct mlx5_devcom *devcom, 25 enum mlx5_devcom_components id, 26 mlx5_devcom_event_handler_t handler, 27 void *data); 28 void mlx5_devcom_unregister_component(struct mlx5_devcom *devcom, 29 enum mlx5_devcom_components id); 30 31 int mlx5_devcom_send_event(struct mlx5_devcom *devcom, 32 enum mlx5_devcom_components id, 33 int event, int rollback_event, 34 void *event_data); 35 36 void mlx5_devcom_comp_set_ready(struct mlx5_devcom *devcom, 37 enum mlx5_devcom_components id, 38 bool ready); 39 bool mlx5_devcom_comp_is_ready(struct mlx5_devcom *devcom, 40 enum mlx5_devcom_components id); 41 42 bool mlx5_devcom_for_each_peer_begin(struct mlx5_devcom *devcom, 43 enum mlx5_devcom_components id); 44 void mlx5_devcom_for_each_peer_end(struct mlx5_devcom *devcom, 45 enum mlx5_devcom_components id); 46 void *mlx5_devcom_get_next_peer_data(struct mlx5_devcom *devcom, 47 enum mlx5_devcom_components id, int *i); 48 49 #define mlx5_devcom_for_each_peer_entry(devcom, id, data, i) \ 50 for (i = 0, data = mlx5_devcom_get_next_peer_data(devcom, id, &i); \ 51 data; \ 52 data = mlx5_devcom_get_next_peer_data(devcom, id, &i)) 53 54 void *mlx5_devcom_get_next_peer_data_rcu(struct mlx5_devcom *devcom, 55 enum mlx5_devcom_components id, int *i); 56 57 #define mlx5_devcom_for_each_peer_entry_rcu(devcom, id, data, i) \ 58 for (i = 0, data = mlx5_devcom_get_next_peer_data_rcu(devcom, id, &i); \ 59 data; \ 60 data = mlx5_devcom_get_next_peer_data_rcu(devcom, id, &i)) 61 62 #endif 63