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;
34 struct mlx5e_flow_table {
36 struct mlx5_flow_table *t;
37 struct mlx5_flow_group **g;
40 struct mlx5e_l2_rule {
41 u8 addr[ETH_ALEN + 2];
42 struct mlx5_flow_handle *rule;
45 #define MLX5E_L2_ADDR_HASH_SIZE BIT(BITS_PER_BYTE)
47 struct mlx5e_promisc_table {
48 struct mlx5e_flow_table ft;
49 struct mlx5_flow_handle *rule;
52 /* Forward declaration and APIs to get private fields of vlan_table */
53 struct mlx5e_vlan_table;
54 unsigned long *mlx5e_vlan_get_active_svlans(struct mlx5e_vlan_table *vlan);
55 struct mlx5_flow_table *mlx5e_vlan_get_flowtable(struct mlx5e_vlan_table *vlan);
57 struct mlx5e_l2_table {
58 struct mlx5e_flow_table ft;
59 struct hlist_head netdev_uc[MLX5E_L2_ADDR_HASH_SIZE];
60 struct hlist_head netdev_mc[MLX5E_L2_ADDR_HASH_SIZE];
61 struct mlx5e_l2_rule broadcast;
62 struct mlx5e_l2_rule allmulti;
63 struct mlx5_flow_handle *trap_rule;
64 bool broadcast_enabled;
65 bool allmulti_enabled;
69 enum mlx5e_traffic_types {
74 MLX5E_TT_IPV4_IPSEC_AH,
75 MLX5E_TT_IPV6_IPSEC_AH,
76 MLX5E_TT_IPV4_IPSEC_ESP,
77 MLX5E_TT_IPV6_IPSEC_ESP,
82 MLX5E_NUM_INDIR_TIRS = MLX5E_TT_ANY,
85 struct mlx5e_tirc_config {
91 #define MLX5_HASH_IP (MLX5_HASH_FIELD_SEL_SRC_IP |\
92 MLX5_HASH_FIELD_SEL_DST_IP)
93 #define MLX5_HASH_IP_L4PORTS (MLX5_HASH_FIELD_SEL_SRC_IP |\
94 MLX5_HASH_FIELD_SEL_DST_IP |\
95 MLX5_HASH_FIELD_SEL_L4_SPORT |\
96 MLX5_HASH_FIELD_SEL_L4_DPORT)
97 #define MLX5_HASH_IP_IPSEC_SPI (MLX5_HASH_FIELD_SEL_SRC_IP |\
98 MLX5_HASH_FIELD_SEL_DST_IP |\
99 MLX5_HASH_FIELD_SEL_IPSEC_SPI)
101 enum mlx5e_tunnel_types {
111 bool mlx5e_tunnel_inner_ft_supported(struct mlx5_core_dev *mdev);
113 struct mlx5e_ttc_rule {
114 struct mlx5_flow_handle *rule;
115 struct mlx5_flow_destination default_dest;
118 /* L3/L4 traffic type classifier */
119 struct mlx5e_ttc_table {
120 struct mlx5e_flow_table ft;
121 struct mlx5e_ttc_rule rules[MLX5E_NUM_TT];
122 struct mlx5_flow_handle *tunnel_rules[MLX5E_NUM_TUNNEL_TT];
127 MLX5E_PROMISC_FT_LEVEL,
131 MLX5E_INNER_TTC_FT_LEVEL,
132 MLX5E_FS_TT_UDP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
133 MLX5E_FS_TT_ANY_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
134 #ifdef CONFIG_MLX5_EN_TLS
135 MLX5E_ACCEL_FS_TCP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
137 #ifdef CONFIG_MLX5_EN_ARFS
138 MLX5E_ARFS_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
140 #ifdef CONFIG_MLX5_EN_IPSEC
141 MLX5E_ACCEL_FS_ESP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
142 MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL,
146 #define MLX5E_TTC_NUM_GROUPS 3
147 #define MLX5E_TTC_GROUP1_SIZE (BIT(3) + MLX5E_NUM_TUNNEL_TT)
148 #define MLX5E_TTC_GROUP2_SIZE BIT(1)
149 #define MLX5E_TTC_GROUP3_SIZE BIT(0)
150 #define MLX5E_TTC_TABLE_SIZE (MLX5E_TTC_GROUP1_SIZE +\
151 MLX5E_TTC_GROUP2_SIZE +\
152 MLX5E_TTC_GROUP3_SIZE)
154 #define MLX5E_INNER_TTC_NUM_GROUPS 3
155 #define MLX5E_INNER_TTC_GROUP1_SIZE BIT(3)
156 #define MLX5E_INNER_TTC_GROUP2_SIZE BIT(1)
157 #define MLX5E_INNER_TTC_GROUP3_SIZE BIT(0)
158 #define MLX5E_INNER_TTC_TABLE_SIZE (MLX5E_INNER_TTC_GROUP1_SIZE +\
159 MLX5E_INNER_TTC_GROUP2_SIZE +\
160 MLX5E_INNER_TTC_GROUP3_SIZE)
162 #ifdef CONFIG_MLX5_EN_RXNFC
164 struct mlx5e_ethtool_table {
165 struct mlx5_flow_table *ft;
169 #define ETHTOOL_NUM_L3_L4_FTS 7
170 #define ETHTOOL_NUM_L2_FTS 4
172 struct mlx5e_ethtool_steering {
173 struct mlx5e_ethtool_table l3_l4_ft[ETHTOOL_NUM_L3_L4_FTS];
174 struct mlx5e_ethtool_table l2_ft[ETHTOOL_NUM_L2_FTS];
175 struct list_head rules;
179 void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv);
180 void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv);
181 int mlx5e_ethtool_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd);
182 int mlx5e_ethtool_get_rxnfc(struct net_device *dev,
183 struct ethtool_rxnfc *info, u32 *rule_locs);
185 static inline void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv) { }
186 static inline void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv) { }
187 static inline int mlx5e_ethtool_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
188 { return -EOPNOTSUPP; }
189 static inline int mlx5e_ethtool_get_rxnfc(struct net_device *dev,
190 struct ethtool_rxnfc *info, u32 *rule_locs)
191 { return -EOPNOTSUPP; }
192 #endif /* CONFIG_MLX5_EN_RXNFC */
194 #ifdef CONFIG_MLX5_EN_ARFS
195 struct mlx5e_arfs_tables;
197 int mlx5e_arfs_create_tables(struct mlx5e_priv *priv);
198 void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv);
199 int mlx5e_arfs_enable(struct mlx5e_priv *priv);
200 int mlx5e_arfs_disable(struct mlx5e_priv *priv);
201 int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
202 u16 rxq_index, u32 flow_id);
204 static inline int mlx5e_arfs_create_tables(struct mlx5e_priv *priv) { return 0; }
205 static inline void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv) {}
206 static inline int mlx5e_arfs_enable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; }
207 static inline int mlx5e_arfs_disable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; }
210 #ifdef CONFIG_MLX5_EN_TLS
211 struct mlx5e_accel_fs_tcp;
218 struct mlx5e_flow_steering {
219 struct mlx5_flow_namespace *ns;
220 struct mlx5_flow_namespace *egress_ns;
221 #ifdef CONFIG_MLX5_EN_RXNFC
222 struct mlx5e_ethtool_steering ethtool;
224 struct mlx5e_tc_table tc;
225 struct mlx5e_promisc_table promisc;
226 struct mlx5e_vlan_table *vlan;
227 struct mlx5e_l2_table l2;
228 struct mlx5e_ttc_table ttc;
229 struct mlx5e_ttc_table inner_ttc;
230 #ifdef CONFIG_MLX5_EN_ARFS
231 struct mlx5e_arfs_tables *arfs;
233 #ifdef CONFIG_MLX5_EN_TLS
234 struct mlx5e_accel_fs_tcp *accel_tcp;
236 struct mlx5e_fs_udp *udp;
237 struct mlx5e_fs_any *any;
238 struct mlx5e_ptp_fs *ptp_fs;
242 struct mlx5_flow_table_attr ft_attr;
244 u32 indir_tirn[MLX5E_NUM_INDIR_TIRS];
245 struct mlx5e_ttc_table *inner_ttc;
248 void mlx5e_set_ttc_basic_params(struct mlx5e_priv *priv, struct ttc_params *ttc_params);
249 void mlx5e_set_ttc_ft_params(struct ttc_params *ttc_params);
250 void mlx5e_set_inner_ttc_ft_params(struct ttc_params *ttc_params);
252 int mlx5e_create_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
253 struct mlx5e_ttc_table *ttc);
254 void mlx5e_destroy_ttc_table(struct mlx5e_priv *priv,
255 struct mlx5e_ttc_table *ttc);
257 int mlx5e_create_inner_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
258 struct mlx5e_ttc_table *ttc);
259 void mlx5e_destroy_inner_ttc_table(struct mlx5e_priv *priv,
260 struct mlx5e_ttc_table *ttc);
262 void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
263 int mlx5e_ttc_fwd_dest(struct mlx5e_priv *priv, enum mlx5e_traffic_types type,
264 struct mlx5_flow_destination *new_dest);
265 struct mlx5_flow_destination
266 mlx5e_ttc_get_default_dest(struct mlx5e_priv *priv, enum mlx5e_traffic_types type);
267 int mlx5e_ttc_fwd_default_dest(struct mlx5e_priv *priv, enum mlx5e_traffic_types type);
269 void mlx5e_enable_cvlan_filter(struct mlx5e_priv *priv);
270 void mlx5e_disable_cvlan_filter(struct mlx5e_priv *priv);
272 int mlx5e_create_flow_steering(struct mlx5e_priv *priv);
273 void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv);
275 u8 mlx5e_get_proto_by_tunnel_type(enum mlx5e_tunnel_types tt);
276 int mlx5e_add_vlan_trap(struct mlx5e_priv *priv, int trap_id, int tir_num);
277 void mlx5e_remove_vlan_trap(struct mlx5e_priv *priv);
278 int mlx5e_add_mac_trap(struct mlx5e_priv *priv, int trap_id, int tir_num);
279 void mlx5e_remove_mac_trap(struct mlx5e_priv *priv);
281 #endif /* __MLX5E_FLOW_STEER_H__ */