1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ 2 /* Copyright (c) 2020 Mellanox Technologies Ltd */ 3 4 #ifndef __MLX5_SF_H__ 5 #define __MLX5_SF_H__ 6 7 #include <linux/mlx5/driver.h> 8 9 static inline u16 mlx5_sf_start_function_id(const struct mlx5_core_dev *dev) 10 { 11 return MLX5_CAP_GEN(dev, sf_base_id); 12 } 13 14 #ifdef CONFIG_MLX5_SF 15 16 static inline bool mlx5_sf_supported(const struct mlx5_core_dev *dev) 17 { 18 return MLX5_CAP_GEN(dev, sf); 19 } 20 21 static inline u16 mlx5_sf_max_functions(const struct mlx5_core_dev *dev) 22 { 23 if (!mlx5_sf_supported(dev)) 24 return 0; 25 if (MLX5_CAP_GEN(dev, max_num_sf)) 26 return MLX5_CAP_GEN(dev, max_num_sf); 27 else 28 return 1 << MLX5_CAP_GEN(dev, log_max_sf); 29 } 30 31 #else 32 33 static inline bool mlx5_sf_supported(const struct mlx5_core_dev *dev) 34 { 35 return false; 36 } 37 38 static inline u16 mlx5_sf_max_functions(const struct mlx5_core_dev *dev) 39 { 40 return 0; 41 } 42 43 #endif 44 45 #ifdef CONFIG_MLX5_SF_MANAGER 46 47 int mlx5_sf_hw_table_init(struct mlx5_core_dev *dev); 48 void mlx5_sf_hw_table_cleanup(struct mlx5_core_dev *dev); 49 50 int mlx5_sf_hw_table_create(struct mlx5_core_dev *dev); 51 void mlx5_sf_hw_table_destroy(struct mlx5_core_dev *dev); 52 53 int mlx5_sf_table_init(struct mlx5_core_dev *dev); 54 void mlx5_sf_table_cleanup(struct mlx5_core_dev *dev); 55 56 int mlx5_devlink_sf_port_new(struct devlink *devlink, 57 const struct devlink_port_new_attrs *add_attr, 58 struct netlink_ext_ack *extack, 59 unsigned int *new_port_index); 60 int mlx5_devlink_sf_port_del(struct devlink *devlink, unsigned int port_index, 61 struct netlink_ext_ack *extack); 62 int mlx5_devlink_sf_port_fn_state_get(struct devlink *devlink, struct devlink_port *dl_port, 63 enum devlink_port_fn_state *state, 64 enum devlink_port_fn_opstate *opstate, 65 struct netlink_ext_ack *extack); 66 int mlx5_devlink_sf_port_fn_state_set(struct devlink *devlink, struct devlink_port *dl_port, 67 enum devlink_port_fn_state state, 68 struct netlink_ext_ack *extack); 69 #else 70 71 static inline int mlx5_sf_hw_table_init(struct mlx5_core_dev *dev) 72 { 73 return 0; 74 } 75 76 static inline void mlx5_sf_hw_table_cleanup(struct mlx5_core_dev *dev) 77 { 78 } 79 80 static inline int mlx5_sf_hw_table_create(struct mlx5_core_dev *dev) 81 { 82 return 0; 83 } 84 85 static inline void mlx5_sf_hw_table_destroy(struct mlx5_core_dev *dev) 86 { 87 } 88 89 static inline int mlx5_sf_table_init(struct mlx5_core_dev *dev) 90 { 91 return 0; 92 } 93 94 static inline void mlx5_sf_table_cleanup(struct mlx5_core_dev *dev) 95 { 96 } 97 98 #endif 99 100 #endif 101