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__
12 struct mlx5e_tc_table {
13 struct mlx5_flow_table *t;
17 DECLARE_HASHTABLE(mod_hdr_tbl, 8);
18 DECLARE_HASHTABLE(hairpin_tbl, 8);
20 struct notifier_block netdevice_nb;
23 struct mlx5e_flow_table {
25 struct mlx5_flow_table *t;
26 struct mlx5_flow_group **g;
29 struct mlx5e_l2_rule {
30 u8 addr[ETH_ALEN + 2];
31 struct mlx5_flow_handle *rule;
34 #define MLX5E_L2_ADDR_HASH_SIZE BIT(BITS_PER_BYTE)
36 struct mlx5e_vlan_table {
37 struct mlx5e_flow_table ft;
38 DECLARE_BITMAP(active_cvlans, VLAN_N_VID);
39 DECLARE_BITMAP(active_svlans, VLAN_N_VID);
40 struct mlx5_flow_handle *active_cvlans_rule[VLAN_N_VID];
41 struct mlx5_flow_handle *active_svlans_rule[VLAN_N_VID];
42 struct mlx5_flow_handle *untagged_rule;
43 struct mlx5_flow_handle *any_cvlan_rule;
44 struct mlx5_flow_handle *any_svlan_rule;
45 bool cvlan_filter_disabled;
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 mlx5e_l2_rule promisc;
55 bool broadcast_enabled;
56 bool allmulti_enabled;
60 enum mlx5e_traffic_types {
65 MLX5E_TT_IPV4_IPSEC_AH,
66 MLX5E_TT_IPV6_IPSEC_AH,
67 MLX5E_TT_IPV4_IPSEC_ESP,
68 MLX5E_TT_IPV6_IPSEC_ESP,
73 MLX5E_NUM_INDIR_TIRS = MLX5E_TT_ANY,
76 struct mlx5e_tirc_config {
82 #define MLX5_HASH_IP (MLX5_HASH_FIELD_SEL_SRC_IP |\
83 MLX5_HASH_FIELD_SEL_DST_IP)
84 #define MLX5_HASH_IP_L4PORTS (MLX5_HASH_FIELD_SEL_SRC_IP |\
85 MLX5_HASH_FIELD_SEL_DST_IP |\
86 MLX5_HASH_FIELD_SEL_L4_SPORT |\
87 MLX5_HASH_FIELD_SEL_L4_DPORT)
88 #define MLX5_HASH_IP_IPSEC_SPI (MLX5_HASH_FIELD_SEL_SRC_IP |\
89 MLX5_HASH_FIELD_SEL_DST_IP |\
90 MLX5_HASH_FIELD_SEL_IPSEC_SPI)
92 enum mlx5e_tunnel_types {
98 /* L3/L4 traffic type classifier */
99 struct mlx5e_ttc_table {
100 struct mlx5e_flow_table ft;
101 struct mlx5_flow_handle *rules[MLX5E_NUM_TT];
102 struct mlx5_flow_handle *tunnel_rules[MLX5E_NUM_TUNNEL_TT];
107 MLX5E_VLAN_FT_LEVEL = 0,
110 MLX5E_INNER_TTC_FT_LEVEL,
111 #ifdef CONFIG_MLX5_EN_ARFS
116 #ifdef CONFIG_MLX5_EN_RXNFC
118 struct mlx5e_ethtool_table {
119 struct mlx5_flow_table *ft;
123 #define ETHTOOL_NUM_L3_L4_FTS 7
124 #define ETHTOOL_NUM_L2_FTS 4
126 struct mlx5e_ethtool_steering {
127 struct mlx5e_ethtool_table l3_l4_ft[ETHTOOL_NUM_L3_L4_FTS];
128 struct mlx5e_ethtool_table l2_ft[ETHTOOL_NUM_L2_FTS];
129 struct list_head rules;
133 void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv);
134 void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv);
135 int mlx5e_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd);
136 int mlx5e_get_rxnfc(struct net_device *dev,
137 struct ethtool_rxnfc *info, u32 *rule_locs);
139 static inline void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv) { }
140 static inline void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv) { }
141 #endif /* CONFIG_MLX5_EN_RXNFC */
143 #ifdef CONFIG_MLX5_EN_ARFS
144 #define ARFS_HASH_SHIFT BITS_PER_BYTE
145 #define ARFS_HASH_SIZE BIT(BITS_PER_BYTE)
148 struct mlx5e_flow_table ft;
149 struct mlx5_flow_handle *default_rule;
150 struct hlist_head rules_hash[ARFS_HASH_SIZE];
161 struct mlx5e_arfs_tables {
162 struct arfs_table arfs_tables[ARFS_NUM_TYPES];
163 /* Protect aRFS rules list */
164 spinlock_t arfs_lock;
165 struct list_head rules;
167 struct workqueue_struct *wq;
170 int mlx5e_arfs_create_tables(struct mlx5e_priv *priv);
171 void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv);
172 int mlx5e_arfs_enable(struct mlx5e_priv *priv);
173 int mlx5e_arfs_disable(struct mlx5e_priv *priv);
174 int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
175 u16 rxq_index, u32 flow_id);
177 static inline int mlx5e_arfs_create_tables(struct mlx5e_priv *priv) { return 0; }
178 static inline void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv) {}
179 static inline int mlx5e_arfs_enable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; }
180 static inline int mlx5e_arfs_disable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; }
183 struct mlx5e_flow_steering {
184 struct mlx5_flow_namespace *ns;
185 #ifdef CONFIG_MLX5_EN_RXNFC
186 struct mlx5e_ethtool_steering ethtool;
188 struct mlx5e_tc_table tc;
189 struct mlx5e_vlan_table vlan;
190 struct mlx5e_l2_table l2;
191 struct mlx5e_ttc_table ttc;
192 struct mlx5e_ttc_table inner_ttc;
193 #ifdef CONFIG_MLX5_EN_ARFS
194 struct mlx5e_arfs_tables arfs;
199 struct mlx5_flow_table_attr ft_attr;
201 u32 indir_tirn[MLX5E_NUM_INDIR_TIRS];
202 struct mlx5e_ttc_table *inner_ttc;
205 void mlx5e_set_ttc_basic_params(struct mlx5e_priv *priv, struct ttc_params *ttc_params);
206 void mlx5e_set_ttc_ft_params(struct ttc_params *ttc_params);
207 void mlx5e_set_inner_ttc_ft_params(struct ttc_params *ttc_params);
209 int mlx5e_create_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
210 struct mlx5e_ttc_table *ttc);
211 void mlx5e_destroy_ttc_table(struct mlx5e_priv *priv,
212 struct mlx5e_ttc_table *ttc);
214 int mlx5e_create_inner_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
215 struct mlx5e_ttc_table *ttc);
216 void mlx5e_destroy_inner_ttc_table(struct mlx5e_priv *priv,
217 struct mlx5e_ttc_table *ttc);
219 void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
221 void mlx5e_enable_cvlan_filter(struct mlx5e_priv *priv);
222 void mlx5e_disable_cvlan_filter(struct mlx5e_priv *priv);
224 int mlx5e_create_flow_steering(struct mlx5e_priv *priv);
225 void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv);
227 #endif /* __MLX5E_FLOW_STEER_H__ */