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 
9 struct mlx5_fs_chains;
10 struct mlx5_mapped_obj;
11 
12 enum 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 
18 struct 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 
30 bool
31 mlx5_chains_prios_supported(struct mlx5_fs_chains *chains);
32 bool mlx5_chains_ignore_flow_level_supported(struct mlx5_fs_chains *chains);
33 bool
34 mlx5_chains_backwards_supported(struct mlx5_fs_chains *chains);
35 u32
36 mlx5_chains_get_prio_range(struct mlx5_fs_chains *chains);
37 u32
38 mlx5_chains_get_chain_range(struct mlx5_fs_chains *chains);
39 u32
40 mlx5_chains_get_nf_ft_chain(struct mlx5_fs_chains *chains);
41 
42 struct mlx5_flow_table *
43 mlx5_chains_get_table(struct mlx5_fs_chains *chains, u32 chain, u32 prio,
44 		      u32 level);
45 void
46 mlx5_chains_put_table(struct mlx5_fs_chains *chains, u32 chain, u32 prio,
47 		      u32 level);
48 
49 struct mlx5_flow_table *
50 mlx5_chains_get_tc_end_ft(struct mlx5_fs_chains *chains);
51 
52 struct mlx5_flow_table *
53 mlx5_chains_create_global_table(struct mlx5_fs_chains *chains);
54 void
55 mlx5_chains_destroy_global_table(struct mlx5_fs_chains *chains,
56 				 struct mlx5_flow_table *ft);
57 
58 int
59 mlx5_chains_get_chain_mapping(struct mlx5_fs_chains *chains, u32 chain,
60 			      u32 *chain_mapping);
61 int
62 mlx5_chains_put_chain_mapping(struct mlx5_fs_chains *chains,
63 			      u32 chain_mapping);
64 
65 struct mlx5_fs_chains *
66 mlx5_chains_create(struct mlx5_core_dev *dev, struct mlx5_chains_attr *attr);
67 void mlx5_chains_destroy(struct mlx5_fs_chains *chains);
68 
69 void
70 mlx5_chains_set_end_ft(struct mlx5_fs_chains *chains,
71 		       struct mlx5_flow_table *ft);
72 void
73 mlx5_chains_print_info(struct mlx5_fs_chains *chains);
74 
75 #else /* CONFIG_MLX5_CLS_ACT */
76 
77 static inline bool
78 mlx5_chains_ignore_flow_level_supported(struct mlx5_fs_chains *chains)
79 { return false; }
80 
81 static inline struct mlx5_flow_table *
82 mlx5_chains_get_table(struct mlx5_fs_chains *chains, u32 chain, u32 prio,
83 		      u32 level) { return ERR_PTR(-EOPNOTSUPP); }
84 static inline void
85 mlx5_chains_put_table(struct mlx5_fs_chains *chains, u32 chain, u32 prio,
86 		      u32 level) {};
87 
88 static inline struct mlx5_flow_table *
89 mlx5_chains_get_tc_end_ft(struct mlx5_fs_chains *chains) { return ERR_PTR(-EOPNOTSUPP); }
90 
91 static inline struct mlx5_fs_chains *
92 mlx5_chains_create(struct mlx5_core_dev *dev, struct mlx5_chains_attr *attr)
93 { return NULL; }
94 static inline void
95 mlx5_chains_destroy(struct mlx5_fs_chains *chains) {}
96 static inline void
97 mlx5_chains_print_info(struct mlx5_fs_chains *chains) {}
98 
99 #endif /* CONFIG_MLX5_CLS_ACT */
100 
101 #endif /* __ML5_ESW_CHAINS_H__ */
102