xref: /linux/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h (revision f61389a9cd26b424485acade726ccfff96c749de)
1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2018 Mellanox Technologies. */
3 
4 #ifndef __MLX5E_FLOW_STEER_H__
5 #define __MLX5E_FLOW_STEER_H__
6 
7 #include "mod_hdr.h"
8 #include "lib/fs_ttc.h"
9 
10 struct mlx5e_post_act;
11 struct mlx5e_tc_table;
12 
13 enum {
14 	MLX5E_TC_FT_LEVEL = 0,
15 	MLX5E_TC_TTC_FT_LEVEL,
16 	MLX5E_TC_MISS_LEVEL,
17 };
18 
19 enum {
20 	MLX5E_TC_PRIO = 0,
21 	MLX5E_PROMISC_PRIO,
22 	MLX5E_NIC_PRIO,
23 };
24 
25 struct mlx5e_flow_table {
26 	int num_groups;
27 	struct mlx5_flow_table *t;
28 	struct mlx5_flow_group **g;
29 };
30 
31 struct mlx5e_l2_rule {
32 	u8  addr[ETH_ALEN + 2];
33 	struct mlx5_flow_handle *rule;
34 };
35 
36 #define MLX5E_L2_ADDR_HASH_SIZE BIT(BITS_PER_BYTE)
37 
38 struct mlx5e_promisc_table {
39 	struct mlx5e_flow_table	ft;
40 	struct mlx5_flow_handle	*rule;
41 };
42 
43 /* Forward declaration and APIs to get private fields of vlan_table */
44 struct mlx5e_vlan_table;
45 unsigned long *mlx5e_vlan_get_active_svlans(struct mlx5e_vlan_table *vlan);
46 struct mlx5_flow_table *mlx5e_vlan_get_flowtable(struct mlx5e_vlan_table *vlan);
47 
48 struct mlx5e_l2_table {
49 	struct mlx5e_flow_table    ft;
50 	struct hlist_head          netdev_uc[MLX5E_L2_ADDR_HASH_SIZE];
51 	struct hlist_head          netdev_mc[MLX5E_L2_ADDR_HASH_SIZE];
52 	struct mlx5e_l2_rule	   broadcast;
53 	struct mlx5e_l2_rule	   allmulti;
54 	struct mlx5_flow_handle    *trap_rule;
55 	bool                       broadcast_enabled;
56 	bool                       allmulti_enabled;
57 	bool                       promisc_enabled;
58 };
59 
60 #define MLX5E_NUM_INDIR_TIRS (MLX5_NUM_TT - 1)
61 
62 #define MLX5_HASH_IP		(MLX5_HASH_FIELD_SEL_SRC_IP   |\
63 				 MLX5_HASH_FIELD_SEL_DST_IP)
64 #define MLX5_HASH_IP_L4PORTS	(MLX5_HASH_FIELD_SEL_SRC_IP   |\
65 				 MLX5_HASH_FIELD_SEL_DST_IP   |\
66 				 MLX5_HASH_FIELD_SEL_L4_SPORT |\
67 				 MLX5_HASH_FIELD_SEL_L4_DPORT)
68 #define MLX5_HASH_IP_IPSEC_SPI	(MLX5_HASH_FIELD_SEL_SRC_IP   |\
69 				 MLX5_HASH_FIELD_SEL_DST_IP   |\
70 				 MLX5_HASH_FIELD_SEL_IPSEC_SPI)
71 
72 /* NIC promisc FT level */
73 enum {
74 	MLX5E_PROMISC_FT_LEVEL,
75 };
76 
77 /* NIC prio FTS */
78 enum {
79 	MLX5E_VLAN_FT_LEVEL,
80 	MLX5E_L2_FT_LEVEL,
81 	MLX5E_TTC_FT_LEVEL,
82 	MLX5E_INNER_TTC_FT_LEVEL,
83 	MLX5E_FS_TT_UDP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
84 	MLX5E_FS_TT_ANY_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
85 #ifdef CONFIG_MLX5_EN_TLS
86 	MLX5E_ACCEL_FS_TCP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
87 #endif
88 #ifdef CONFIG_MLX5_EN_ARFS
89 	MLX5E_ARFS_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
90 #endif
91 #ifdef CONFIG_MLX5_EN_IPSEC
92 	MLX5E_ACCEL_FS_ESP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
93 	MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL,
94 	MLX5E_ACCEL_FS_POL_FT_LEVEL,
95 	MLX5E_ACCEL_FS_ESP_FT_ROCE_LEVEL,
96 #endif
97 };
98 
99 struct mlx5e_flow_steering;
100 struct mlx5e_rx_res;
101 
102 #ifdef CONFIG_MLX5_EN_ARFS
103 struct mlx5e_arfs_tables;
104 
105 int mlx5e_arfs_create_tables(struct mlx5e_flow_steering *fs,
106 			     struct mlx5e_rx_res *rx_res, bool ntuple);
107 void mlx5e_arfs_destroy_tables(struct mlx5e_flow_steering *fs, bool ntuple);
108 int mlx5e_arfs_enable(struct mlx5e_flow_steering *fs);
109 int mlx5e_arfs_disable(struct mlx5e_flow_steering *fs);
110 int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
111 			u16 rxq_index, u32 flow_id);
112 #else
mlx5e_arfs_create_tables(struct mlx5e_flow_steering * fs,struct mlx5e_rx_res * rx_res,bool ntuple)113 static inline int mlx5e_arfs_create_tables(struct mlx5e_flow_steering *fs,
114 					   struct mlx5e_rx_res *rx_res, bool ntuple)
115 { return 0; }
mlx5e_arfs_destroy_tables(struct mlx5e_flow_steering * fs,bool ntuple)116 static inline void mlx5e_arfs_destroy_tables(struct mlx5e_flow_steering *fs, bool ntuple) {}
mlx5e_arfs_enable(struct mlx5e_flow_steering * fs)117 static inline int mlx5e_arfs_enable(struct mlx5e_flow_steering *fs)
118 { return -EOPNOTSUPP; }
mlx5e_arfs_disable(struct mlx5e_flow_steering * fs)119 static inline int mlx5e_arfs_disable(struct mlx5e_flow_steering *fs)
120 { return -EOPNOTSUPP; }
121 #endif
122 
123 #ifdef CONFIG_MLX5_EN_TLS
124 struct mlx5e_accel_fs_tcp;
125 #endif
126 
127 struct mlx5e_profile;
128 struct mlx5e_fs_udp;
129 struct mlx5e_fs_any;
130 struct mlx5e_ptp_fs;
131 
132 void mlx5e_set_ttc_params(struct mlx5e_flow_steering *fs,
133 			  struct mlx5e_rx_res *rx_res,
134 			  struct ttc_params *ttc_params, bool tunnel);
135 
136 void mlx5e_destroy_ttc_table(struct mlx5e_flow_steering *fs);
137 int mlx5e_create_ttc_table(struct mlx5e_flow_steering  *fs,
138 			   struct mlx5e_rx_res *rx_res);
139 
140 void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
141 
142 void mlx5e_enable_cvlan_filter(struct mlx5e_flow_steering *fs, bool promisc);
143 void mlx5e_disable_cvlan_filter(struct mlx5e_flow_steering *fs, bool promisc);
144 
145 int mlx5e_create_flow_steering(struct mlx5e_flow_steering *fs,
146 			       struct mlx5e_rx_res *rx_res,
147 			       const struct mlx5e_profile *profile,
148 			       struct net_device *netdev);
149 void mlx5e_destroy_flow_steering(struct mlx5e_flow_steering *fs, bool ntuple,
150 				 const struct mlx5e_profile *profile);
151 
152 struct mlx5e_flow_steering *mlx5e_fs_init(const struct mlx5e_profile *profile,
153 					  struct mlx5_core_dev *mdev,
154 					  bool state_destroy,
155 					  struct dentry *dfs_root);
156 void mlx5e_fs_cleanup(struct mlx5e_flow_steering *fs);
157 struct mlx5e_vlan_table *mlx5e_fs_get_vlan(struct mlx5e_flow_steering *fs);
158 struct mlx5e_tc_table *mlx5e_fs_get_tc(struct mlx5e_flow_steering *fs);
159 struct mlx5e_l2_table *mlx5e_fs_get_l2(struct mlx5e_flow_steering *fs);
160 struct mlx5_flow_namespace *mlx5e_fs_get_ns(struct mlx5e_flow_steering *fs, bool egress);
161 void mlx5e_fs_set_ns(struct mlx5e_flow_steering *fs, struct mlx5_flow_namespace *ns, bool egress);
162 
mlx5e_fs_has_arfs(struct net_device * netdev)163 static inline bool mlx5e_fs_has_arfs(struct net_device *netdev)
164 {
165 	return IS_ENABLED(CONFIG_MLX5_EN_ARFS) &&
166 		netdev->hw_features & NETIF_F_NTUPLE;
167 }
168 
mlx5e_fs_want_arfs(struct net_device * netdev)169 static inline bool mlx5e_fs_want_arfs(struct net_device *netdev)
170 {
171 	return IS_ENABLED(CONFIG_MLX5_EN_ARFS) &&
172 		netdev->features & NETIF_F_NTUPLE;
173 }
174 
175 #ifdef CONFIG_MLX5_EN_RXNFC
176 struct mlx5e_ethtool_steering *mlx5e_fs_get_ethtool(struct mlx5e_flow_steering *fs);
177 #endif
178 struct mlx5_ttc_table *mlx5e_fs_get_ttc(struct mlx5e_flow_steering *fs, bool inner);
179 void mlx5e_fs_set_ttc(struct mlx5e_flow_steering *fs, struct mlx5_ttc_table *ttc, bool inner);
180 #ifdef CONFIG_MLX5_EN_ARFS
181 struct mlx5e_arfs_tables *mlx5e_fs_get_arfs(struct mlx5e_flow_steering *fs);
182 void mlx5e_fs_set_arfs(struct mlx5e_flow_steering *fs, struct mlx5e_arfs_tables *arfs);
183 #endif
184 struct mlx5e_ptp_fs *mlx5e_fs_get_ptp(struct mlx5e_flow_steering *fs);
185 void mlx5e_fs_set_ptp(struct mlx5e_flow_steering *fs, struct mlx5e_ptp_fs *ptp_fs);
186 struct mlx5e_fs_any *mlx5e_fs_get_any(struct mlx5e_flow_steering *fs);
187 void mlx5e_fs_set_any(struct mlx5e_flow_steering *fs, struct mlx5e_fs_any *any);
188 struct mlx5e_fs_udp *mlx5e_fs_get_udp(struct mlx5e_flow_steering *fs);
189 void mlx5e_fs_set_udp(struct mlx5e_flow_steering *fs, struct mlx5e_fs_udp *udp);
190 #ifdef CONFIG_MLX5_EN_TLS
191 struct mlx5e_accel_fs_tcp *mlx5e_fs_get_accel_tcp(struct mlx5e_flow_steering *fs);
192 void mlx5e_fs_set_accel_tcp(struct mlx5e_flow_steering *fs, struct mlx5e_accel_fs_tcp *accel_tcp);
193 #endif
194 void mlx5e_fs_set_state_destroy(struct mlx5e_flow_steering *fs, bool state_destroy);
195 void mlx5e_fs_set_vlan_strip_disable(struct mlx5e_flow_steering *fs, bool vlan_strip_disable);
196 
197 struct mlx5_core_dev *mlx5e_fs_get_mdev(struct mlx5e_flow_steering *fs);
198 int mlx5e_add_vlan_trap(struct mlx5e_flow_steering *fs, int  trap_id, int tir_num);
199 void mlx5e_remove_vlan_trap(struct mlx5e_flow_steering *fs);
200 int mlx5e_add_mac_trap(struct mlx5e_flow_steering *fs, int  trap_id, int tir_num);
201 void mlx5e_remove_mac_trap(struct mlx5e_flow_steering *fs);
202 void mlx5e_fs_set_rx_mode_work(struct mlx5e_flow_steering *fs, struct net_device *netdev);
203 int mlx5e_fs_vlan_rx_add_vid(struct mlx5e_flow_steering *fs,
204 			     struct net_device *netdev,
205 			     __be16 proto, u16 vid);
206 int mlx5e_fs_vlan_rx_kill_vid(struct mlx5e_flow_steering *fs,
207 			      struct net_device *netdev,
208 			      __be16 proto, u16 vid);
209 void mlx5e_fs_init_l2_addr(struct mlx5e_flow_steering *fs, struct net_device *netdev);
210 
211 struct dentry *mlx5e_fs_get_debugfs_root(struct mlx5e_flow_steering *fs);
212 
213 #define fs_err(fs, fmt, ...) \
214 	mlx5_core_err(mlx5e_fs_get_mdev(fs), fmt, ##__VA_ARGS__)
215 
216 #define fs_dbg(fs, fmt, ...) \
217 	mlx5_core_dbg(mlx5e_fs_get_mdev(fs), fmt, ##__VA_ARGS__)
218 
219 #define fs_warn(fs, fmt, ...) \
220 	mlx5_core_warn(mlx5e_fs_get_mdev(fs), fmt, ##__VA_ARGS__)
221 
222 #define fs_warn_once(fs, fmt, ...) \
223 	mlx5_core_warn_once(mlx5e_fs_get_mdev(fs), fmt, ##__VA_ARGS__)
224 
225 #endif /* __MLX5E_FLOW_STEER_H__ */
226 
227