1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2018 Mellanox Technologies. */
4 #ifndef __MLX5E_FLOW_STEER_H__
5 #define __MLX5E_FLOW_STEER_H__
10 MLX5E_TC_FT_LEVEL = 0,
11 MLX5E_TC_TTC_FT_LEVEL,
14 struct mlx5e_tc_table {
15 /* Protects the dynamic assignment of the t parameter
16 * which is the nic tc root table.
19 struct mlx5_flow_table *t;
20 struct mlx5_fs_chains *chains;
24 struct mod_hdr_tbl mod_hdr;
25 struct mutex hairpin_tbl_lock; /* protects hairpin_tbl */
26 DECLARE_HASHTABLE(hairpin_tbl, 8);
28 struct notifier_block netdevice_nb;
29 struct netdev_net_notifier netdevice_nn;
31 struct mlx5_tc_ct_priv *ct;
32 struct mapping_ctx *mapping;
35 struct mlx5e_flow_table {
37 struct mlx5_flow_table *t;
38 struct mlx5_flow_group **g;
41 struct mlx5e_l2_rule {
42 u8 addr[ETH_ALEN + 2];
43 struct mlx5_flow_handle *rule;
46 #define MLX5E_L2_ADDR_HASH_SIZE BIT(BITS_PER_BYTE)
48 struct mlx5e_promisc_table {
49 struct mlx5e_flow_table ft;
50 struct mlx5_flow_handle *rule;
53 /* Forward declaration and APIs to get private fields of vlan_table */
54 struct mlx5e_vlan_table;
55 unsigned long *mlx5e_vlan_get_active_svlans(struct mlx5e_vlan_table *vlan);
56 struct mlx5_flow_table *mlx5e_vlan_get_flowtable(struct mlx5e_vlan_table *vlan);
58 struct mlx5e_l2_table {
59 struct mlx5e_flow_table ft;
60 struct hlist_head netdev_uc[MLX5E_L2_ADDR_HASH_SIZE];
61 struct hlist_head netdev_mc[MLX5E_L2_ADDR_HASH_SIZE];
62 struct mlx5e_l2_rule broadcast;
63 struct mlx5e_l2_rule allmulti;
64 struct mlx5_flow_handle *trap_rule;
65 bool broadcast_enabled;
66 bool allmulti_enabled;
70 enum mlx5e_traffic_types {
75 MLX5E_TT_IPV4_IPSEC_AH,
76 MLX5E_TT_IPV6_IPSEC_AH,
77 MLX5E_TT_IPV4_IPSEC_ESP,
78 MLX5E_TT_IPV6_IPSEC_ESP,
83 MLX5E_NUM_INDIR_TIRS = MLX5E_TT_ANY,
86 struct mlx5e_tirc_config {
92 #define MLX5_HASH_IP (MLX5_HASH_FIELD_SEL_SRC_IP |\
93 MLX5_HASH_FIELD_SEL_DST_IP)
94 #define MLX5_HASH_IP_L4PORTS (MLX5_HASH_FIELD_SEL_SRC_IP |\
95 MLX5_HASH_FIELD_SEL_DST_IP |\
96 MLX5_HASH_FIELD_SEL_L4_SPORT |\
97 MLX5_HASH_FIELD_SEL_L4_DPORT)
98 #define MLX5_HASH_IP_IPSEC_SPI (MLX5_HASH_FIELD_SEL_SRC_IP |\
99 MLX5_HASH_FIELD_SEL_DST_IP |\
100 MLX5_HASH_FIELD_SEL_IPSEC_SPI)
102 enum mlx5e_tunnel_types {
112 bool mlx5e_tunnel_inner_ft_supported(struct mlx5_core_dev *mdev);
114 struct mlx5e_ttc_rule {
115 struct mlx5_flow_handle *rule;
116 struct mlx5_flow_destination default_dest;
119 /* L3/L4 traffic type classifier */
120 struct mlx5e_ttc_table {
121 struct mlx5e_flow_table ft;
122 struct mlx5e_ttc_rule rules[MLX5E_NUM_TT];
123 struct mlx5_flow_handle *tunnel_rules[MLX5E_NUM_TUNNEL_TT];
128 MLX5E_PROMISC_FT_LEVEL,
132 MLX5E_INNER_TTC_FT_LEVEL,
133 MLX5E_FS_TT_UDP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
134 MLX5E_FS_TT_ANY_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
135 #ifdef CONFIG_MLX5_EN_TLS
136 MLX5E_ACCEL_FS_TCP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
138 #ifdef CONFIG_MLX5_EN_ARFS
139 MLX5E_ARFS_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
141 #ifdef CONFIG_MLX5_EN_IPSEC
142 MLX5E_ACCEL_FS_ESP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
143 MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL,
147 #define MLX5E_TTC_NUM_GROUPS 3
148 #define MLX5E_TTC_GROUP1_SIZE (BIT(3) + MLX5E_NUM_TUNNEL_TT)
149 #define MLX5E_TTC_GROUP2_SIZE BIT(1)
150 #define MLX5E_TTC_GROUP3_SIZE BIT(0)
151 #define MLX5E_TTC_TABLE_SIZE (MLX5E_TTC_GROUP1_SIZE +\
152 MLX5E_TTC_GROUP2_SIZE +\
153 MLX5E_TTC_GROUP3_SIZE)
155 #define MLX5E_INNER_TTC_NUM_GROUPS 3
156 #define MLX5E_INNER_TTC_GROUP1_SIZE BIT(3)
157 #define MLX5E_INNER_TTC_GROUP2_SIZE BIT(1)
158 #define MLX5E_INNER_TTC_GROUP3_SIZE BIT(0)
159 #define MLX5E_INNER_TTC_TABLE_SIZE (MLX5E_INNER_TTC_GROUP1_SIZE +\
160 MLX5E_INNER_TTC_GROUP2_SIZE +\
161 MLX5E_INNER_TTC_GROUP3_SIZE)
163 #ifdef CONFIG_MLX5_EN_RXNFC
165 struct mlx5e_ethtool_table {
166 struct mlx5_flow_table *ft;
170 #define ETHTOOL_NUM_L3_L4_FTS 7
171 #define ETHTOOL_NUM_L2_FTS 4
173 struct mlx5e_ethtool_steering {
174 struct mlx5e_ethtool_table l3_l4_ft[ETHTOOL_NUM_L3_L4_FTS];
175 struct mlx5e_ethtool_table l2_ft[ETHTOOL_NUM_L2_FTS];
176 struct list_head rules;
180 void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv);
181 void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv);
182 int mlx5e_ethtool_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd);
183 int mlx5e_ethtool_get_rxnfc(struct net_device *dev,
184 struct ethtool_rxnfc *info, u32 *rule_locs);
186 static inline void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv) { }
187 static inline void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv) { }
188 static inline int mlx5e_ethtool_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
189 { return -EOPNOTSUPP; }
190 static inline int mlx5e_ethtool_get_rxnfc(struct net_device *dev,
191 struct ethtool_rxnfc *info, u32 *rule_locs)
192 { return -EOPNOTSUPP; }
193 #endif /* CONFIG_MLX5_EN_RXNFC */
195 #ifdef CONFIG_MLX5_EN_ARFS
196 struct mlx5e_arfs_tables;
198 int mlx5e_arfs_create_tables(struct mlx5e_priv *priv);
199 void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv);
200 int mlx5e_arfs_enable(struct mlx5e_priv *priv);
201 int mlx5e_arfs_disable(struct mlx5e_priv *priv);
202 int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
203 u16 rxq_index, u32 flow_id);
205 static inline int mlx5e_arfs_create_tables(struct mlx5e_priv *priv) { return 0; }
206 static inline void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv) {}
207 static inline int mlx5e_arfs_enable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; }
208 static inline int mlx5e_arfs_disable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; }
211 #ifdef CONFIG_MLX5_EN_TLS
212 struct mlx5e_accel_fs_tcp;
219 struct mlx5e_flow_steering {
220 struct mlx5_flow_namespace *ns;
221 struct mlx5_flow_namespace *egress_ns;
222 #ifdef CONFIG_MLX5_EN_RXNFC
223 struct mlx5e_ethtool_steering ethtool;
225 struct mlx5e_tc_table tc;
226 struct mlx5e_promisc_table promisc;
227 struct mlx5e_vlan_table *vlan;
228 struct mlx5e_l2_table l2;
229 struct mlx5e_ttc_table ttc;
230 struct mlx5e_ttc_table inner_ttc;
231 #ifdef CONFIG_MLX5_EN_ARFS
232 struct mlx5e_arfs_tables *arfs;
234 #ifdef CONFIG_MLX5_EN_TLS
235 struct mlx5e_accel_fs_tcp *accel_tcp;
237 struct mlx5e_fs_udp *udp;
238 struct mlx5e_fs_any *any;
239 struct mlx5e_ptp_fs *ptp_fs;
243 struct mlx5_flow_table_attr ft_attr;
245 u32 indir_tirn[MLX5E_NUM_INDIR_TIRS];
246 struct mlx5e_ttc_table *inner_ttc;
249 void mlx5e_set_ttc_basic_params(struct mlx5e_priv *priv, struct ttc_params *ttc_params);
250 void mlx5e_set_ttc_ft_params(struct ttc_params *ttc_params);
251 void mlx5e_set_inner_ttc_ft_params(struct ttc_params *ttc_params);
253 int mlx5e_create_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
254 struct mlx5e_ttc_table *ttc);
255 void mlx5e_destroy_ttc_table(struct mlx5e_priv *priv,
256 struct mlx5e_ttc_table *ttc);
258 int mlx5e_create_inner_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
259 struct mlx5e_ttc_table *ttc);
260 void mlx5e_destroy_inner_ttc_table(struct mlx5e_priv *priv,
261 struct mlx5e_ttc_table *ttc);
263 void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
264 int mlx5e_ttc_fwd_dest(struct mlx5e_priv *priv, enum mlx5e_traffic_types type,
265 struct mlx5_flow_destination *new_dest);
266 struct mlx5_flow_destination
267 mlx5e_ttc_get_default_dest(struct mlx5e_priv *priv, enum mlx5e_traffic_types type);
268 int mlx5e_ttc_fwd_default_dest(struct mlx5e_priv *priv, enum mlx5e_traffic_types type);
270 void mlx5e_enable_cvlan_filter(struct mlx5e_priv *priv);
271 void mlx5e_disable_cvlan_filter(struct mlx5e_priv *priv);
273 int mlx5e_create_flow_steering(struct mlx5e_priv *priv);
274 void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv);
276 u8 mlx5e_get_proto_by_tunnel_type(enum mlx5e_tunnel_types tt);
277 int mlx5e_add_vlan_trap(struct mlx5e_priv *priv, int trap_id, int tir_num);
278 void mlx5e_remove_vlan_trap(struct mlx5e_priv *priv);
279 int mlx5e_add_mac_trap(struct mlx5e_priv *priv, int trap_id, int tir_num);
280 void mlx5e_remove_mac_trap(struct mlx5e_priv *priv);
282 #endif /* __MLX5E_FLOW_STEER_H__ */