1fe6d86b3SSaeed Mahameed /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2fe6d86b3SSaeed Mahameed /* Copyright (c) 2018 Mellanox Technologies. */
3fe6d86b3SSaeed Mahameed 
4fe6d86b3SSaeed Mahameed #ifndef __MLX5E_FLOW_STEER_H__
5fe6d86b3SSaeed Mahameed #define __MLX5E_FLOW_STEER_H__
6fe6d86b3SSaeed Mahameed 
7b2fdf3d0SPaul Blakey #include "mod_hdr.h"
8371cf74eSMaor Gottlieb #include "lib/fs_ttc.h"
9b2fdf3d0SPaul Blakey 
10f0da4daaSChris Mi struct mlx5e_post_act;
11f52f2faeSLama Kayal struct mlx5e_tc_table;
12f0da4daaSChris Mi 
1344f68ae0SSaeed Mahameed enum {
1444f68ae0SSaeed Mahameed 	MLX5E_TC_FT_LEVEL = 0,
1544f68ae0SSaeed Mahameed 	MLX5E_TC_TTC_FT_LEVEL,
1666cb64e2SMaor Dickman 	MLX5E_TC_MISS_LEVEL,
1744f68ae0SSaeed Mahameed };
1844f68ae0SSaeed Mahameed 
194e0ecc17SLama Kayal enum {
204e0ecc17SLama Kayal 	MLX5E_TC_PRIO = 0,
214e0ecc17SLama Kayal 	MLX5E_NIC_PRIO
224e0ecc17SLama Kayal };
234e0ecc17SLama Kayal 
24ec080045SSaeed Mahameed struct mlx5e_flow_table {
25ec080045SSaeed Mahameed 	int num_groups;
26ec080045SSaeed Mahameed 	struct mlx5_flow_table *t;
27ec080045SSaeed Mahameed 	struct mlx5_flow_group **g;
28ec080045SSaeed Mahameed };
29ec080045SSaeed Mahameed 
3044f68ae0SSaeed Mahameed struct mlx5e_l2_rule {
3144f68ae0SSaeed Mahameed 	u8  addr[ETH_ALEN + 2];
3244f68ae0SSaeed Mahameed 	struct mlx5_flow_handle *rule;
3344f68ae0SSaeed Mahameed };
3444f68ae0SSaeed Mahameed 
3544f68ae0SSaeed Mahameed #define MLX5E_L2_ADDR_HASH_SIZE BIT(BITS_PER_BYTE)
3644f68ae0SSaeed Mahameed 
371c46d740SAya Levin struct mlx5e_promisc_table {
381c46d740SAya Levin 	struct mlx5e_flow_table	ft;
391c46d740SAya Levin 	struct mlx5_flow_handle	*rule;
401c46d740SAya Levin };
411c46d740SAya Levin 
426783f0a2SVu Pham /* Forward declaration and APIs to get private fields of vlan_table */
436783f0a2SVu Pham struct mlx5e_vlan_table;
446783f0a2SVu Pham unsigned long *mlx5e_vlan_get_active_svlans(struct mlx5e_vlan_table *vlan);
456783f0a2SVu Pham struct mlx5_flow_table *mlx5e_vlan_get_flowtable(struct mlx5e_vlan_table *vlan);
4644f68ae0SSaeed Mahameed 
4744f68ae0SSaeed Mahameed struct mlx5e_l2_table {
4844f68ae0SSaeed Mahameed 	struct mlx5e_flow_table    ft;
4944f68ae0SSaeed Mahameed 	struct hlist_head          netdev_uc[MLX5E_L2_ADDR_HASH_SIZE];
5044f68ae0SSaeed Mahameed 	struct hlist_head          netdev_mc[MLX5E_L2_ADDR_HASH_SIZE];
5144f68ae0SSaeed Mahameed 	struct mlx5e_l2_rule	   broadcast;
5244f68ae0SSaeed Mahameed 	struct mlx5e_l2_rule	   allmulti;
53ceef1b66SAya Levin 	struct mlx5_flow_handle    *trap_rule;
5444f68ae0SSaeed Mahameed 	bool                       broadcast_enabled;
5544f68ae0SSaeed Mahameed 	bool                       allmulti_enabled;
5644f68ae0SSaeed Mahameed 	bool                       promisc_enabled;
5744f68ae0SSaeed Mahameed };
5844f68ae0SSaeed Mahameed 
59d443c6f6SMaor Gottlieb #define MLX5E_NUM_INDIR_TIRS (MLX5_NUM_TT - 1)
60d443c6f6SMaor Gottlieb 
61d930ac79SAya Levin #define MLX5_HASH_IP		(MLX5_HASH_FIELD_SEL_SRC_IP   |\
62d930ac79SAya Levin 				 MLX5_HASH_FIELD_SEL_DST_IP)
63d930ac79SAya Levin #define MLX5_HASH_IP_L4PORTS	(MLX5_HASH_FIELD_SEL_SRC_IP   |\
64d930ac79SAya Levin 				 MLX5_HASH_FIELD_SEL_DST_IP   |\
65d930ac79SAya Levin 				 MLX5_HASH_FIELD_SEL_L4_SPORT |\
66d930ac79SAya Levin 				 MLX5_HASH_FIELD_SEL_L4_DPORT)
67d930ac79SAya Levin #define MLX5_HASH_IP_IPSEC_SPI	(MLX5_HASH_FIELD_SEL_SRC_IP   |\
68d930ac79SAya Levin 				 MLX5_HASH_FIELD_SEL_DST_IP   |\
69d930ac79SAya Levin 				 MLX5_HASH_FIELD_SEL_IPSEC_SPI)
70d930ac79SAya Levin 
7144f68ae0SSaeed Mahameed /* NIC prio FTS */
7244f68ae0SSaeed Mahameed enum {
731c46d740SAya Levin 	MLX5E_PROMISC_FT_LEVEL,
741c46d740SAya Levin 	MLX5E_VLAN_FT_LEVEL,
7544f68ae0SSaeed Mahameed 	MLX5E_L2_FT_LEVEL,
7644f68ae0SSaeed Mahameed 	MLX5E_TTC_FT_LEVEL,
7744f68ae0SSaeed Mahameed 	MLX5E_INNER_TTC_FT_LEVEL,
781c80bd68SAya Levin 	MLX5E_FS_TT_UDP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
790f575c20SAya Levin 	MLX5E_FS_TT_ANY_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
80c062d52aSBoris Pismenny #ifdef CONFIG_MLX5_EN_TLS
81c809cf66SAya Levin 	MLX5E_ACCEL_FS_TCP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
82c062d52aSBoris Pismenny #endif
8344f68ae0SSaeed Mahameed #ifdef CONFIG_MLX5_EN_ARFS
84c809cf66SAya Levin 	MLX5E_ARFS_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
855e466345SHuy Nguyen #endif
865e466345SHuy Nguyen #ifdef CONFIG_MLX5_EN_IPSEC
878c17295bSLeon Romanovsky 	MLX5E_ACCEL_FS_POL_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
888c17295bSLeon Romanovsky 	MLX5E_ACCEL_FS_ESP_FT_LEVEL,
895e466345SHuy Nguyen 	MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL,
90*89957760SMark Zhang 	MLX5E_ACCEL_FS_ESP_FT_ROCE_LEVEL,
9144f68ae0SSaeed Mahameed #endif
9244f68ae0SSaeed Mahameed };
9344f68ae0SSaeed Mahameed 
94f52f2faeSLama Kayal struct mlx5e_flow_steering;
9545b83c6cSLama Kayal struct mlx5e_rx_res;
963f22d6c7SMaxim Mikityanskiy 
97ec080045SSaeed Mahameed #ifdef CONFIG_MLX5_EN_ARFS
98f6755b80SVu Pham struct mlx5e_arfs_tables;
99ec080045SSaeed Mahameed 
10045b83c6cSLama Kayal int mlx5e_arfs_create_tables(struct mlx5e_flow_steering *fs,
10145b83c6cSLama Kayal 			     struct mlx5e_rx_res *rx_res, bool ntuple);
10245b83c6cSLama Kayal void mlx5e_arfs_destroy_tables(struct mlx5e_flow_steering *fs, bool ntuple);
10345b83c6cSLama Kayal int mlx5e_arfs_enable(struct mlx5e_flow_steering *fs);
10445b83c6cSLama Kayal int mlx5e_arfs_disable(struct mlx5e_flow_steering *fs);
105ec080045SSaeed Mahameed int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
106ec080045SSaeed Mahameed 			u16 rxq_index, u32 flow_id);
107ec080045SSaeed Mahameed #else
mlx5e_arfs_create_tables(struct mlx5e_flow_steering * fs,struct mlx5e_rx_res * rx_res,bool ntuple)10845b83c6cSLama Kayal static inline int mlx5e_arfs_create_tables(struct mlx5e_flow_steering *fs,
10945b83c6cSLama Kayal 					   struct mlx5e_rx_res *rx_res, bool ntuple)
11045b83c6cSLama Kayal { return 0; }
mlx5e_arfs_destroy_tables(struct mlx5e_flow_steering * fs,bool ntuple)11145b83c6cSLama Kayal static inline void mlx5e_arfs_destroy_tables(struct mlx5e_flow_steering *fs, bool ntuple) {}
mlx5e_arfs_enable(struct mlx5e_flow_steering * fs)11245b83c6cSLama Kayal static inline int mlx5e_arfs_enable(struct mlx5e_flow_steering *fs)
11345b83c6cSLama Kayal { return -EOPNOTSUPP; }
mlx5e_arfs_disable(struct mlx5e_flow_steering * fs)11445b83c6cSLama Kayal static inline int mlx5e_arfs_disable(struct mlx5e_flow_steering *fs)
11545b83c6cSLama Kayal { return -EOPNOTSUPP; }
116ec080045SSaeed Mahameed #endif
117ec080045SSaeed Mahameed 
118c062d52aSBoris Pismenny #ifdef CONFIG_MLX5_EN_TLS
119c062d52aSBoris Pismenny struct mlx5e_accel_fs_tcp;
120c062d52aSBoris Pismenny #endif
121c062d52aSBoris Pismenny 
122af8bbf73SLama Kayal struct mlx5e_profile;
1231c80bd68SAya Levin struct mlx5e_fs_udp;
1240f575c20SAya Levin struct mlx5e_fs_any;
125e5fe4946SAya Levin struct mlx5e_ptp_fs;
1261c80bd68SAya Levin 
127ca959d97SLama Kayal void mlx5e_set_ttc_params(struct mlx5e_flow_steering *fs,
128ca959d97SLama Kayal 			  struct mlx5e_rx_res *rx_res,
129bc29764eSMaor Gottlieb 			  struct ttc_params *ttc_params, bool tunnel);
13044f68ae0SSaeed Mahameed 
131ca959d97SLama Kayal void mlx5e_destroy_ttc_table(struct mlx5e_flow_steering *fs);
132ca959d97SLama Kayal int mlx5e_create_ttc_table(struct mlx5e_flow_steering  *fs,
133ca959d97SLama Kayal 			   struct mlx5e_rx_res *rx_res);
134f4b45940SMaor Gottlieb 
13544f68ae0SSaeed Mahameed void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
13644f68ae0SSaeed Mahameed 
137d494dd2bSLama Kayal void mlx5e_enable_cvlan_filter(struct mlx5e_flow_steering *fs, bool promisc);
138d494dd2bSLama Kayal void mlx5e_disable_cvlan_filter(struct mlx5e_flow_steering *fs, bool promisc);
13944f68ae0SSaeed Mahameed 
140d494dd2bSLama Kayal int mlx5e_create_flow_steering(struct mlx5e_flow_steering *fs,
141d494dd2bSLama Kayal 			       struct mlx5e_rx_res *rx_res,
142d494dd2bSLama Kayal 			       const struct mlx5e_profile *profile,
143d494dd2bSLama Kayal 			       struct net_device *netdev);
144d494dd2bSLama Kayal void mlx5e_destroy_flow_steering(struct mlx5e_flow_steering *fs, bool ntuple,
145d494dd2bSLama Kayal 				 const struct mlx5e_profile *profile);
14644f68ae0SSaeed Mahameed 
1477bb70715SLama Kayal struct mlx5e_flow_steering *mlx5e_fs_init(const struct mlx5e_profile *profile,
1485b031addSLama Kayal 					  struct mlx5_core_dev *mdev,
1495b031addSLama Kayal 					  bool state_destroy,
150af8bbf73SLama Kayal 					  struct dentry *dfs_root);
151f52f2faeSLama Kayal void mlx5e_fs_cleanup(struct mlx5e_flow_steering *fs);
152f52f2faeSLama Kayal struct mlx5e_vlan_table *mlx5e_fs_get_vlan(struct mlx5e_flow_steering *fs);
153f52f2faeSLama Kayal void mlx5e_fs_set_tc(struct mlx5e_flow_steering *fs, struct mlx5e_tc_table *tc);
154f52f2faeSLama Kayal struct mlx5e_tc_table *mlx5e_fs_get_tc(struct mlx5e_flow_steering *fs);
155f52f2faeSLama Kayal struct mlx5e_l2_table *mlx5e_fs_get_l2(struct mlx5e_flow_steering *fs);
156f52f2faeSLama Kayal struct mlx5_flow_namespace *mlx5e_fs_get_ns(struct mlx5e_flow_steering *fs, bool egress);
157f52f2faeSLama Kayal void mlx5e_fs_set_ns(struct mlx5e_flow_steering *fs, struct mlx5_flow_namespace *ns, bool egress);
158f52f2faeSLama Kayal #ifdef CONFIG_MLX5_EN_RXNFC
159f52f2faeSLama Kayal struct mlx5e_ethtool_steering *mlx5e_fs_get_ethtool(struct mlx5e_flow_steering *fs);
160f52f2faeSLama Kayal #endif
161f52f2faeSLama Kayal struct mlx5_ttc_table *mlx5e_fs_get_ttc(struct mlx5e_flow_steering *fs, bool inner);
162f52f2faeSLama Kayal void mlx5e_fs_set_ttc(struct mlx5e_flow_steering *fs, struct mlx5_ttc_table *ttc, bool inner);
163f52f2faeSLama Kayal #ifdef CONFIG_MLX5_EN_ARFS
164f52f2faeSLama Kayal struct mlx5e_arfs_tables *mlx5e_fs_get_arfs(struct mlx5e_flow_steering *fs);
165f52f2faeSLama Kayal void mlx5e_fs_set_arfs(struct mlx5e_flow_steering *fs, struct mlx5e_arfs_tables *arfs);
166f52f2faeSLama Kayal #endif
167f52f2faeSLama Kayal struct mlx5e_ptp_fs *mlx5e_fs_get_ptp(struct mlx5e_flow_steering *fs);
168f52f2faeSLama Kayal void mlx5e_fs_set_ptp(struct mlx5e_flow_steering *fs, struct mlx5e_ptp_fs *ptp_fs);
169f52f2faeSLama Kayal struct mlx5e_fs_any *mlx5e_fs_get_any(struct mlx5e_flow_steering *fs);
170f52f2faeSLama Kayal void mlx5e_fs_set_any(struct mlx5e_flow_steering *fs, struct mlx5e_fs_any *any);
171f52f2faeSLama Kayal struct mlx5e_fs_udp *mlx5e_fs_get_udp(struct mlx5e_flow_steering *fs);
172f52f2faeSLama Kayal void mlx5e_fs_set_udp(struct mlx5e_flow_steering *fs, struct mlx5e_fs_udp *udp);
173f52f2faeSLama Kayal #ifdef CONFIG_MLX5_EN_TLS
174f52f2faeSLama Kayal struct mlx5e_accel_fs_tcp *mlx5e_fs_get_accel_tcp(struct mlx5e_flow_steering *fs);
175f52f2faeSLama Kayal void mlx5e_fs_set_accel_tcp(struct mlx5e_flow_steering *fs, struct mlx5e_accel_fs_tcp *accel_tcp);
176f52f2faeSLama Kayal #endif
177f52f2faeSLama Kayal void mlx5e_fs_set_state_destroy(struct mlx5e_flow_steering *fs, bool state_destroy);
17868e66e1aSMoshe Shemesh void mlx5e_fs_set_vlan_strip_disable(struct mlx5e_flow_steering *fs, bool vlan_strip_disable);
179f52f2faeSLama Kayal 
180d494dd2bSLama Kayal struct mlx5_core_dev *mlx5e_fs_get_mdev(struct mlx5e_flow_steering *fs);
181d494dd2bSLama Kayal int mlx5e_add_vlan_trap(struct mlx5e_flow_steering *fs, int  trap_id, int tir_num);
182d494dd2bSLama Kayal void mlx5e_remove_vlan_trap(struct mlx5e_flow_steering *fs);
183d494dd2bSLama Kayal int mlx5e_add_mac_trap(struct mlx5e_flow_steering *fs, int  trap_id, int tir_num);
1845b031addSLama Kayal void mlx5e_remove_mac_trap(struct mlx5e_flow_steering *fs);
185a02c07eaSLama Kayal void mlx5e_fs_set_rx_mode_work(struct mlx5e_flow_steering *fs, struct net_device *netdev);
186a02c07eaSLama Kayal int mlx5e_fs_vlan_rx_add_vid(struct mlx5e_flow_steering *fs,
187a02c07eaSLama Kayal 			     struct net_device *netdev,
188a02c07eaSLama Kayal 			     __be16 proto, u16 vid);
189a02c07eaSLama Kayal int mlx5e_fs_vlan_rx_kill_vid(struct mlx5e_flow_steering *fs,
190a02c07eaSLama Kayal 			      struct net_device *netdev,
191069448b2SLama Kayal 			      __be16 proto, u16 vid);
19293a07599SLama Kayal void mlx5e_fs_init_l2_addr(struct mlx5e_flow_steering *fs, struct net_device *netdev);
19393a07599SLama Kayal 
19493a07599SLama Kayal struct dentry *mlx5e_fs_get_debugfs_root(struct mlx5e_flow_steering *fs);
19593a07599SLama Kayal 
19693a07599SLama Kayal #define fs_err(fs, fmt, ...) \
19793a07599SLama Kayal 	mlx5_core_err(mlx5e_fs_get_mdev(fs), fmt, ##__VA_ARGS__)
19893a07599SLama Kayal 
19993a07599SLama Kayal #define fs_dbg(fs, fmt, ...) \
20093a07599SLama Kayal 	mlx5_core_dbg(mlx5e_fs_get_mdev(fs), fmt, ##__VA_ARGS__)
20193a07599SLama Kayal 
20293a07599SLama Kayal #define fs_warn(fs, fmt, ...) \
20393a07599SLama Kayal 	mlx5_core_warn(mlx5e_fs_get_mdev(fs), fmt, ##__VA_ARGS__)
20493a07599SLama Kayal 
205fe6d86b3SSaeed Mahameed #define fs_warn_once(fs, fmt, ...) \
206fe6d86b3SSaeed Mahameed 	mlx5_core_warn_once(mlx5e_fs_get_mdev(fs), fmt, ##__VA_ARGS__)
207 
208 #endif /* __MLX5E_FLOW_STEER_H__ */
209 
210