Merge tag 'mt76-for-kvalo-2021-01-29' of https://github.com/nbd168/wireless
[linux-2.6-microblaze.git] / drivers / net / ethernet / mellanox / mlx5 / core / en / fs.h
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
9 enum {
10         MLX5E_TC_FT_LEVEL = 0,
11         MLX5E_TC_TTC_FT_LEVEL,
12 };
13
14 struct mlx5e_tc_table {
15         /* Protects the dynamic assignment of the t parameter
16          * which is the nic tc root table.
17          */
18         struct mutex                    t_lock;
19         struct mlx5_flow_table          *t;
20         struct mlx5_fs_chains           *chains;
21
22         struct rhashtable               ht;
23
24         struct mod_hdr_tbl mod_hdr;
25         struct mutex hairpin_tbl_lock; /* protects hairpin_tbl */
26         DECLARE_HASHTABLE(hairpin_tbl, 8);
27
28         struct notifier_block     netdevice_nb;
29         struct netdev_net_notifier      netdevice_nn;
30
31         struct mlx5_tc_ct_priv         *ct;
32 };
33
34 struct mlx5e_flow_table {
35         int num_groups;
36         struct mlx5_flow_table *t;
37         struct mlx5_flow_group **g;
38 };
39
40 struct mlx5e_l2_rule {
41         u8  addr[ETH_ALEN + 2];
42         struct mlx5_flow_handle *rule;
43 };
44
45 #define MLX5E_L2_ADDR_HASH_SIZE BIT(BITS_PER_BYTE)
46
47 struct mlx5e_promisc_table {
48         struct mlx5e_flow_table ft;
49         struct mlx5_flow_handle *rule;
50 };
51
52 struct mlx5e_vlan_table {
53         struct mlx5e_flow_table         ft;
54         DECLARE_BITMAP(active_cvlans, VLAN_N_VID);
55         DECLARE_BITMAP(active_svlans, VLAN_N_VID);
56         struct mlx5_flow_handle *active_cvlans_rule[VLAN_N_VID];
57         struct mlx5_flow_handle *active_svlans_rule[VLAN_N_VID];
58         struct mlx5_flow_handle *untagged_rule;
59         struct mlx5_flow_handle *any_cvlan_rule;
60         struct mlx5_flow_handle *any_svlan_rule;
61         struct mlx5_flow_handle *trap_rule;
62         bool                    cvlan_filter_disabled;
63 };
64
65 struct mlx5e_l2_table {
66         struct mlx5e_flow_table    ft;
67         struct hlist_head          netdev_uc[MLX5E_L2_ADDR_HASH_SIZE];
68         struct hlist_head          netdev_mc[MLX5E_L2_ADDR_HASH_SIZE];
69         struct mlx5e_l2_rule       broadcast;
70         struct mlx5e_l2_rule       allmulti;
71         struct mlx5_flow_handle    *trap_rule;
72         bool                       broadcast_enabled;
73         bool                       allmulti_enabled;
74         bool                       promisc_enabled;
75 };
76
77 enum mlx5e_traffic_types {
78         MLX5E_TT_IPV4_TCP,
79         MLX5E_TT_IPV6_TCP,
80         MLX5E_TT_IPV4_UDP,
81         MLX5E_TT_IPV6_UDP,
82         MLX5E_TT_IPV4_IPSEC_AH,
83         MLX5E_TT_IPV6_IPSEC_AH,
84         MLX5E_TT_IPV4_IPSEC_ESP,
85         MLX5E_TT_IPV6_IPSEC_ESP,
86         MLX5E_TT_IPV4,
87         MLX5E_TT_IPV6,
88         MLX5E_TT_ANY,
89         MLX5E_NUM_TT,
90         MLX5E_NUM_INDIR_TIRS = MLX5E_TT_ANY,
91 };
92
93 struct mlx5e_tirc_config {
94         u8 l3_prot_type;
95         u8 l4_prot_type;
96         u32 rx_hash_fields;
97 };
98
99 #define MLX5_HASH_IP            (MLX5_HASH_FIELD_SEL_SRC_IP   |\
100                                  MLX5_HASH_FIELD_SEL_DST_IP)
101 #define MLX5_HASH_IP_L4PORTS    (MLX5_HASH_FIELD_SEL_SRC_IP   |\
102                                  MLX5_HASH_FIELD_SEL_DST_IP   |\
103                                  MLX5_HASH_FIELD_SEL_L4_SPORT |\
104                                  MLX5_HASH_FIELD_SEL_L4_DPORT)
105 #define MLX5_HASH_IP_IPSEC_SPI  (MLX5_HASH_FIELD_SEL_SRC_IP   |\
106                                  MLX5_HASH_FIELD_SEL_DST_IP   |\
107                                  MLX5_HASH_FIELD_SEL_IPSEC_SPI)
108
109 enum mlx5e_tunnel_types {
110         MLX5E_TT_IPV4_GRE,
111         MLX5E_TT_IPV6_GRE,
112         MLX5E_TT_IPV4_IPIP,
113         MLX5E_TT_IPV6_IPIP,
114         MLX5E_TT_IPV4_IPV6,
115         MLX5E_TT_IPV6_IPV6,
116         MLX5E_NUM_TUNNEL_TT,
117 };
118
119 bool mlx5e_tunnel_inner_ft_supported(struct mlx5_core_dev *mdev);
120
121 struct mlx5e_ttc_rule {
122         struct mlx5_flow_handle *rule;
123         struct mlx5_flow_destination default_dest;
124 };
125
126 /* L3/L4 traffic type classifier */
127 struct mlx5e_ttc_table {
128         struct mlx5e_flow_table ft;
129         struct mlx5e_ttc_rule rules[MLX5E_NUM_TT];
130         struct mlx5_flow_handle *tunnel_rules[MLX5E_NUM_TUNNEL_TT];
131 };
132
133 /* NIC prio FTS */
134 enum {
135         MLX5E_PROMISC_FT_LEVEL,
136         MLX5E_VLAN_FT_LEVEL,
137         MLX5E_L2_FT_LEVEL,
138         MLX5E_TTC_FT_LEVEL,
139         MLX5E_INNER_TTC_FT_LEVEL,
140 #ifdef CONFIG_MLX5_EN_TLS
141         MLX5E_ACCEL_FS_TCP_FT_LEVEL,
142 #endif
143 #ifdef CONFIG_MLX5_EN_ARFS
144         MLX5E_ARFS_FT_LEVEL,
145 #endif
146 #ifdef CONFIG_MLX5_EN_IPSEC
147         MLX5E_ACCEL_FS_ESP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
148         MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL,
149 #endif
150 };
151
152 #define MLX5E_TTC_NUM_GROUPS    3
153 #define MLX5E_TTC_GROUP1_SIZE   (BIT(3) + MLX5E_NUM_TUNNEL_TT)
154 #define MLX5E_TTC_GROUP2_SIZE    BIT(1)
155 #define MLX5E_TTC_GROUP3_SIZE    BIT(0)
156 #define MLX5E_TTC_TABLE_SIZE    (MLX5E_TTC_GROUP1_SIZE +\
157                                  MLX5E_TTC_GROUP2_SIZE +\
158                                  MLX5E_TTC_GROUP3_SIZE)
159
160 #define MLX5E_INNER_TTC_NUM_GROUPS      3
161 #define MLX5E_INNER_TTC_GROUP1_SIZE     BIT(3)
162 #define MLX5E_INNER_TTC_GROUP2_SIZE     BIT(1)
163 #define MLX5E_INNER_TTC_GROUP3_SIZE     BIT(0)
164 #define MLX5E_INNER_TTC_TABLE_SIZE      (MLX5E_INNER_TTC_GROUP1_SIZE +\
165                                          MLX5E_INNER_TTC_GROUP2_SIZE +\
166                                          MLX5E_INNER_TTC_GROUP3_SIZE)
167
168 #ifdef CONFIG_MLX5_EN_RXNFC
169
170 struct mlx5e_ethtool_table {
171         struct mlx5_flow_table *ft;
172         int                    num_rules;
173 };
174
175 #define ETHTOOL_NUM_L3_L4_FTS 7
176 #define ETHTOOL_NUM_L2_FTS 4
177
178 struct mlx5e_ethtool_steering {
179         struct mlx5e_ethtool_table      l3_l4_ft[ETHTOOL_NUM_L3_L4_FTS];
180         struct mlx5e_ethtool_table      l2_ft[ETHTOOL_NUM_L2_FTS];
181         struct list_head                rules;
182         int                             tot_num_rules;
183 };
184
185 void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv);
186 void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv);
187 int mlx5e_ethtool_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd);
188 int mlx5e_ethtool_get_rxnfc(struct net_device *dev,
189                             struct ethtool_rxnfc *info, u32 *rule_locs);
190 #else
191 static inline void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv)    { }
192 static inline void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv) { }
193 static inline int mlx5e_ethtool_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
194 { return -EOPNOTSUPP; }
195 static inline int mlx5e_ethtool_get_rxnfc(struct net_device *dev,
196                                           struct ethtool_rxnfc *info, u32 *rule_locs)
197 { return -EOPNOTSUPP; }
198 #endif /* CONFIG_MLX5_EN_RXNFC */
199
200 #ifdef CONFIG_MLX5_EN_ARFS
201 #define ARFS_HASH_SHIFT BITS_PER_BYTE
202 #define ARFS_HASH_SIZE BIT(BITS_PER_BYTE)
203
204 struct arfs_table {
205         struct mlx5e_flow_table  ft;
206         struct mlx5_flow_handle  *default_rule;
207         struct hlist_head        rules_hash[ARFS_HASH_SIZE];
208 };
209
210 enum  arfs_type {
211         ARFS_IPV4_TCP,
212         ARFS_IPV6_TCP,
213         ARFS_IPV4_UDP,
214         ARFS_IPV6_UDP,
215         ARFS_NUM_TYPES,
216 };
217
218 struct mlx5e_arfs_tables {
219         struct arfs_table arfs_tables[ARFS_NUM_TYPES];
220         /* Protect aRFS rules list */
221         spinlock_t                     arfs_lock;
222         struct list_head               rules;
223         int                            last_filter_id;
224         struct workqueue_struct        *wq;
225 };
226
227 int mlx5e_arfs_create_tables(struct mlx5e_priv *priv);
228 void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv);
229 int mlx5e_arfs_enable(struct mlx5e_priv *priv);
230 int mlx5e_arfs_disable(struct mlx5e_priv *priv);
231 int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
232                         u16 rxq_index, u32 flow_id);
233 #else
234 static inline int mlx5e_arfs_create_tables(struct mlx5e_priv *priv) { return 0; }
235 static inline void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv) {}
236 static inline int mlx5e_arfs_enable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; }
237 static inline int mlx5e_arfs_disable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; }
238 #endif
239
240 #ifdef CONFIG_MLX5_EN_TLS
241 struct mlx5e_accel_fs_tcp;
242 #endif
243
244 struct mlx5e_flow_steering {
245         struct mlx5_flow_namespace      *ns;
246         struct mlx5_flow_namespace      *egress_ns;
247 #ifdef CONFIG_MLX5_EN_RXNFC
248         struct mlx5e_ethtool_steering   ethtool;
249 #endif
250         struct mlx5e_tc_table           tc;
251         struct mlx5e_promisc_table      promisc;
252         struct mlx5e_vlan_table         vlan;
253         struct mlx5e_l2_table           l2;
254         struct mlx5e_ttc_table          ttc;
255         struct mlx5e_ttc_table          inner_ttc;
256 #ifdef CONFIG_MLX5_EN_ARFS
257         struct mlx5e_arfs_tables        arfs;
258 #endif
259 #ifdef CONFIG_MLX5_EN_TLS
260         struct mlx5e_accel_fs_tcp      *accel_tcp;
261 #endif
262 };
263
264 struct ttc_params {
265         struct mlx5_flow_table_attr ft_attr;
266         u32 any_tt_tirn;
267         u32 indir_tirn[MLX5E_NUM_INDIR_TIRS];
268         struct mlx5e_ttc_table *inner_ttc;
269 };
270
271 void mlx5e_set_ttc_basic_params(struct mlx5e_priv *priv, struct ttc_params *ttc_params);
272 void mlx5e_set_ttc_ft_params(struct ttc_params *ttc_params);
273 void mlx5e_set_inner_ttc_ft_params(struct ttc_params *ttc_params);
274
275 int mlx5e_create_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
276                            struct mlx5e_ttc_table *ttc);
277 void mlx5e_destroy_ttc_table(struct mlx5e_priv *priv,
278                              struct mlx5e_ttc_table *ttc);
279
280 int mlx5e_create_inner_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
281                                  struct mlx5e_ttc_table *ttc);
282 void mlx5e_destroy_inner_ttc_table(struct mlx5e_priv *priv,
283                                    struct mlx5e_ttc_table *ttc);
284
285 void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
286 int mlx5e_ttc_fwd_dest(struct mlx5e_priv *priv, enum mlx5e_traffic_types type,
287                        struct mlx5_flow_destination *new_dest);
288 struct mlx5_flow_destination
289 mlx5e_ttc_get_default_dest(struct mlx5e_priv *priv, enum mlx5e_traffic_types type);
290 int mlx5e_ttc_fwd_default_dest(struct mlx5e_priv *priv, enum mlx5e_traffic_types type);
291
292 void mlx5e_enable_cvlan_filter(struct mlx5e_priv *priv);
293 void mlx5e_disable_cvlan_filter(struct mlx5e_priv *priv);
294
295 int mlx5e_create_flow_steering(struct mlx5e_priv *priv);
296 void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv);
297
298 u8 mlx5e_get_proto_by_tunnel_type(enum mlx5e_tunnel_types tt);
299 int mlx5e_add_vlan_trap(struct mlx5e_priv *priv, int  trap_id, int tir_num);
300 void mlx5e_remove_vlan_trap(struct mlx5e_priv *priv);
301 int mlx5e_add_mac_trap(struct mlx5e_priv *priv, int  trap_id, int tir_num);
302 void mlx5e_remove_mac_trap(struct mlx5e_priv *priv);
303
304 #endif /* __MLX5E_FLOW_STEER_H__ */
305