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);
21 struct mlx5e_flow_table {
23 struct mlx5_flow_table *t;
24 struct mlx5_flow_group **g;
27 struct mlx5e_l2_rule {
28 u8 addr[ETH_ALEN + 2];
29 struct mlx5_flow_handle *rule;
32 #define MLX5E_L2_ADDR_HASH_SIZE BIT(BITS_PER_BYTE)
34 struct mlx5e_vlan_table {
35 struct mlx5e_flow_table ft;
36 DECLARE_BITMAP(active_cvlans, VLAN_N_VID);
37 DECLARE_BITMAP(active_svlans, VLAN_N_VID);
38 struct mlx5_flow_handle *active_cvlans_rule[VLAN_N_VID];
39 struct mlx5_flow_handle *active_svlans_rule[VLAN_N_VID];
40 struct mlx5_flow_handle *untagged_rule;
41 struct mlx5_flow_handle *any_cvlan_rule;
42 struct mlx5_flow_handle *any_svlan_rule;
43 bool cvlan_filter_disabled;
46 struct mlx5e_l2_table {
47 struct mlx5e_flow_table ft;
48 struct hlist_head netdev_uc[MLX5E_L2_ADDR_HASH_SIZE];
49 struct hlist_head netdev_mc[MLX5E_L2_ADDR_HASH_SIZE];
50 struct mlx5e_l2_rule broadcast;
51 struct mlx5e_l2_rule allmulti;
52 struct mlx5e_l2_rule promisc;
53 bool broadcast_enabled;
54 bool allmulti_enabled;
58 enum mlx5e_traffic_types {
63 MLX5E_TT_IPV4_IPSEC_AH,
64 MLX5E_TT_IPV6_IPSEC_AH,
65 MLX5E_TT_IPV4_IPSEC_ESP,
66 MLX5E_TT_IPV6_IPSEC_ESP,
71 MLX5E_NUM_INDIR_TIRS = MLX5E_TT_ANY,
74 enum mlx5e_tunnel_types {
80 /* L3/L4 traffic type classifier */
81 struct mlx5e_ttc_table {
82 struct mlx5e_flow_table ft;
83 struct mlx5_flow_handle *rules[MLX5E_NUM_TT];
84 struct mlx5_flow_handle *tunnel_rules[MLX5E_NUM_TUNNEL_TT];
89 MLX5E_VLAN_FT_LEVEL = 0,
92 MLX5E_INNER_TTC_FT_LEVEL,
93 #ifdef CONFIG_MLX5_EN_ARFS
98 #ifdef CONFIG_MLX5_EN_RXNFC
100 struct mlx5e_ethtool_table {
101 struct mlx5_flow_table *ft;
105 #define ETHTOOL_NUM_L3_L4_FTS 7
106 #define ETHTOOL_NUM_L2_FTS 4
108 struct mlx5e_ethtool_steering {
109 struct mlx5e_ethtool_table l3_l4_ft[ETHTOOL_NUM_L3_L4_FTS];
110 struct mlx5e_ethtool_table l2_ft[ETHTOOL_NUM_L2_FTS];
111 struct list_head rules;
115 void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv);
116 void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv);
117 int mlx5e_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd);
118 int mlx5e_get_rxnfc(struct net_device *dev,
119 struct ethtool_rxnfc *info, u32 *rule_locs);
121 static inline void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv) { }
122 static inline void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv) { }
123 #endif /* CONFIG_MLX5_EN_RXNFC */
125 #ifdef CONFIG_MLX5_EN_ARFS
126 #define ARFS_HASH_SHIFT BITS_PER_BYTE
127 #define ARFS_HASH_SIZE BIT(BITS_PER_BYTE)
130 struct mlx5e_flow_table ft;
131 struct mlx5_flow_handle *default_rule;
132 struct hlist_head rules_hash[ARFS_HASH_SIZE];
143 struct mlx5e_arfs_tables {
144 struct arfs_table arfs_tables[ARFS_NUM_TYPES];
145 /* Protect aRFS rules list */
146 spinlock_t arfs_lock;
147 struct list_head rules;
149 struct workqueue_struct *wq;
152 int mlx5e_arfs_create_tables(struct mlx5e_priv *priv);
153 void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv);
154 int mlx5e_arfs_enable(struct mlx5e_priv *priv);
155 int mlx5e_arfs_disable(struct mlx5e_priv *priv);
156 int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
157 u16 rxq_index, u32 flow_id);
159 static inline int mlx5e_arfs_create_tables(struct mlx5e_priv *priv) { return 0; }
160 static inline void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv) {}
161 static inline int mlx5e_arfs_enable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; }
162 static inline int mlx5e_arfs_disable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; }
165 struct mlx5e_flow_steering {
166 struct mlx5_flow_namespace *ns;
167 #ifdef CONFIG_MLX5_EN_RXNFC
168 struct mlx5e_ethtool_steering ethtool;
170 struct mlx5e_tc_table tc;
171 struct mlx5e_vlan_table vlan;
172 struct mlx5e_l2_table l2;
173 struct mlx5e_ttc_table ttc;
174 struct mlx5e_ttc_table inner_ttc;
175 #ifdef CONFIG_MLX5_EN_ARFS
176 struct mlx5e_arfs_tables arfs;
181 struct mlx5_flow_table_attr ft_attr;
183 u32 indir_tirn[MLX5E_NUM_INDIR_TIRS];
184 struct mlx5e_ttc_table *inner_ttc;
187 void mlx5e_set_ttc_basic_params(struct mlx5e_priv *priv, struct ttc_params *ttc_params);
188 void mlx5e_set_ttc_ft_params(struct ttc_params *ttc_params);
189 void mlx5e_set_inner_ttc_ft_params(struct ttc_params *ttc_params);
191 int mlx5e_create_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
192 struct mlx5e_ttc_table *ttc);
193 void mlx5e_destroy_ttc_table(struct mlx5e_priv *priv,
194 struct mlx5e_ttc_table *ttc);
196 int mlx5e_create_inner_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
197 struct mlx5e_ttc_table *ttc);
198 void mlx5e_destroy_inner_ttc_table(struct mlx5e_priv *priv,
199 struct mlx5e_ttc_table *ttc);
201 void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
203 void mlx5e_enable_cvlan_filter(struct mlx5e_priv *priv);
204 void mlx5e_disable_cvlan_filter(struct mlx5e_priv *priv);
206 int mlx5e_create_flow_steering(struct mlx5e_priv *priv);
207 void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv);
209 #endif /* __MLX5E_FLOW_STEER_H__ */