1/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ 2/* Copyright (c) 2020 Mellanox Technologies. */ 3 4#ifndef __ML5_ESW_CHAINS_H__ 5#define __ML5_ESW_CHAINS_H__ 6 7#include <linux/mlx5/fs.h> 8 9struct mlx5_fs_chains; 10struct mlx5_mapped_obj; 11 12enum mlx5_chains_flags { 13 MLX5_CHAINS_AND_PRIOS_SUPPORTED = BIT(0), 14 MLX5_CHAINS_IGNORE_FLOW_LEVEL_SUPPORTED = BIT(1), 15 MLX5_CHAINS_FT_TUNNEL_SUPPORTED = BIT(2), 16}; 17 18struct mlx5_chains_attr { 19 enum mlx5_flow_namespace_type ns; 20 int fs_base_prio; 21 int fs_base_level; 22 u32 flags; 23 u32 max_grp_num; 24 struct mlx5_flow_table *default_ft; 25 struct mapping_ctx *mapping; 26}; 27 28#if IS_ENABLED(CONFIG_MLX5_CLS_ACT) 29 30bool 31mlx5_chains_prios_supported(struct mlx5_fs_chains *chains); 32bool mlx5_chains_ignore_flow_level_supported(struct mlx5_fs_chains *chains); 33bool 34mlx5_chains_backwards_supported(struct mlx5_fs_chains *chains); 35u32 36mlx5_chains_get_prio_range(struct mlx5_fs_chains *chains); 37u32 38mlx5_chains_get_chain_range(struct mlx5_fs_chains *chains); 39u32 40mlx5_chains_get_nf_ft_chain(struct mlx5_fs_chains *chains); 41 42struct mlx5_flow_table * 43mlx5_chains_get_table(struct mlx5_fs_chains *chains, u32 chain, u32 prio, 44 u32 level); 45void 46mlx5_chains_put_table(struct mlx5_fs_chains *chains, u32 chain, u32 prio, 47 u32 level); 48 49struct mlx5_flow_table * 50mlx5_chains_get_tc_end_ft(struct mlx5_fs_chains *chains); 51 52struct mlx5_flow_table * 53mlx5_chains_create_global_table(struct mlx5_fs_chains *chains); 54void 55mlx5_chains_destroy_global_table(struct mlx5_fs_chains *chains, 56 struct mlx5_flow_table *ft); 57 58int 59mlx5_chains_get_chain_mapping(struct mlx5_fs_chains *chains, u32 chain, 60 u32 *chain_mapping); 61int 62mlx5_chains_put_chain_mapping(struct mlx5_fs_chains *chains, 63 u32 chain_mapping); 64 65struct mlx5_fs_chains * 66mlx5_chains_create(struct mlx5_core_dev *dev, struct mlx5_chains_attr *attr); 67void mlx5_chains_destroy(struct mlx5_fs_chains *chains); 68 69void 70mlx5_chains_set_end_ft(struct mlx5_fs_chains *chains, 71 struct mlx5_flow_table *ft); 72void 73mlx5_chains_print_info(struct mlx5_fs_chains *chains); 74 75#else /* CONFIG_MLX5_CLS_ACT */ 76 77static inline bool 78mlx5_chains_ignore_flow_level_supported(struct mlx5_fs_chains *chains) 79{ return false; } 80 81static inline struct mlx5_flow_table * 82mlx5_chains_get_table(struct mlx5_fs_chains *chains, u32 chain, u32 prio, 83 u32 level) { return ERR_PTR(-EOPNOTSUPP); } 84static inline void 85mlx5_chains_put_table(struct mlx5_fs_chains *chains, u32 chain, u32 prio, 86 u32 level) {}; 87 88static inline struct mlx5_flow_table * 89mlx5_chains_get_tc_end_ft(struct mlx5_fs_chains *chains) { return ERR_PTR(-EOPNOTSUPP); } 90 91static inline struct mlx5_fs_chains * 92mlx5_chains_create(struct mlx5_core_dev *dev, struct mlx5_chains_attr *attr) 93{ return NULL; } 94static inline void 95mlx5_chains_destroy(struct mlx5_fs_chains *chains) {} 96static inline void 97mlx5_chains_print_info(struct mlx5_fs_chains *chains) {} 98 99#endif /* CONFIG_MLX5_CLS_ACT */ 100 101#endif /* __ML5_ESW_CHAINS_H__ */ 102