1 /*
2  * Copyright (c) 2015, Mellanox Technologies. All rights reserved.
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and/or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  */
32 
33 #include <linux/debugfs.h>
34 #include <linux/list.h>
35 #include <linux/ip.h>
36 #include <linux/ipv6.h>
37 #include <linux/tcp.h>
38 #include <linux/mlx5/fs.h>
39 #include <linux/mlx5/mpfs.h>
40 #include "en_tc.h"
41 #include "lib/mpfs.h"
42 #include "en/ptp.h"
43 #include "en/fs_ethtool.h"
44 
45 struct mlx5e_flow_steering {
46 	struct work_struct		set_rx_mode_work;
47 	bool				state_destroy;
48 	bool				vlan_strip_disable;
49 	struct mlx5_core_dev		*mdev;
50 	struct net_device		*netdev;
51 	struct mlx5_flow_namespace      *ns;
52 	struct mlx5_flow_namespace      *egress_ns;
53 #ifdef CONFIG_MLX5_EN_RXNFC
54 	struct mlx5e_ethtool_steering   *ethtool;
55 #endif
56 	struct mlx5e_tc_table           *tc;
57 	struct mlx5e_promisc_table      promisc;
58 	struct mlx5e_vlan_table         *vlan;
59 	struct mlx5e_l2_table           l2;
60 	struct mlx5_ttc_table           *ttc;
61 	struct mlx5_ttc_table           *inner_ttc;
62 #ifdef CONFIG_MLX5_EN_ARFS
63 	struct mlx5e_arfs_tables       *arfs;
64 #endif
65 #ifdef CONFIG_MLX5_EN_TLS
66 	struct mlx5e_accel_fs_tcp      *accel_tcp;
67 #endif
68 	struct mlx5e_fs_udp            *udp;
69 	struct mlx5e_fs_any            *any;
70 	struct mlx5e_ptp_fs            *ptp_fs;
71 	struct dentry                  *dfs_root;
72 };
73 
74 static int mlx5e_add_l2_flow_rule(struct mlx5e_flow_steering *fs,
75 				  struct mlx5e_l2_rule *ai, int type);
76 static void mlx5e_del_l2_flow_rule(struct mlx5e_flow_steering *fs,
77 				   struct mlx5e_l2_rule *ai);
78 
79 enum {
80 	MLX5E_FULLMATCH = 0,
81 	MLX5E_ALLMULTI  = 1,
82 };
83 
84 enum {
85 	MLX5E_UC        = 0,
86 	MLX5E_MC_IPV4   = 1,
87 	MLX5E_MC_IPV6   = 2,
88 	MLX5E_MC_OTHER  = 3,
89 };
90 
91 enum {
92 	MLX5E_ACTION_NONE = 0,
93 	MLX5E_ACTION_ADD  = 1,
94 	MLX5E_ACTION_DEL  = 2,
95 };
96 
97 struct mlx5e_l2_hash_node {
98 	struct hlist_node          hlist;
99 	u8                         action;
100 	struct mlx5e_l2_rule ai;
101 	bool   mpfs;
102 };
103 
mlx5e_hash_l2(const u8 * addr)104 static inline int mlx5e_hash_l2(const u8 *addr)
105 {
106 	return addr[5];
107 }
108 
mlx5e_fs_get_debugfs_root(struct mlx5e_flow_steering * fs)109 struct dentry *mlx5e_fs_get_debugfs_root(struct mlx5e_flow_steering *fs)
110 {
111 	return fs->dfs_root;
112 }
113 
mlx5e_add_l2_to_hash(struct hlist_head * hash,const u8 * addr)114 static void mlx5e_add_l2_to_hash(struct hlist_head *hash, const u8 *addr)
115 {
116 	struct mlx5e_l2_hash_node *hn;
117 	int ix = mlx5e_hash_l2(addr);
118 	int found = 0;
119 
120 	hlist_for_each_entry(hn, &hash[ix], hlist)
121 		if (ether_addr_equal_64bits(hn->ai.addr, addr)) {
122 			found = 1;
123 			break;
124 		}
125 
126 	if (found) {
127 		hn->action = MLX5E_ACTION_NONE;
128 		return;
129 	}
130 
131 	hn = kzalloc(sizeof(*hn), GFP_ATOMIC);
132 	if (!hn)
133 		return;
134 
135 	ether_addr_copy(hn->ai.addr, addr);
136 	hn->action = MLX5E_ACTION_ADD;
137 
138 	hlist_add_head(&hn->hlist, &hash[ix]);
139 }
140 
mlx5e_del_l2_from_hash(struct mlx5e_l2_hash_node * hn)141 static void mlx5e_del_l2_from_hash(struct mlx5e_l2_hash_node *hn)
142 {
143 	hlist_del(&hn->hlist);
144 	kfree(hn);
145 }
146 
147 struct mlx5e_vlan_table {
148 	struct mlx5e_flow_table		ft;
149 	DECLARE_BITMAP(active_cvlans, VLAN_N_VID);
150 	DECLARE_BITMAP(active_svlans, VLAN_N_VID);
151 	struct mlx5_flow_handle	*active_cvlans_rule[VLAN_N_VID];
152 	struct mlx5_flow_handle	*active_svlans_rule[VLAN_N_VID];
153 	struct mlx5_flow_handle	*untagged_rule;
154 	struct mlx5_flow_handle	*any_cvlan_rule;
155 	struct mlx5_flow_handle	*any_svlan_rule;
156 	struct mlx5_flow_handle	*trap_rule;
157 	bool			cvlan_filter_disabled;
158 };
159 
mlx5e_vlan_get_active_svlans(struct mlx5e_vlan_table * vlan)160 unsigned long *mlx5e_vlan_get_active_svlans(struct mlx5e_vlan_table *vlan)
161 {
162 	return vlan->active_svlans;
163 }
164 
mlx5e_vlan_get_flowtable(struct mlx5e_vlan_table * vlan)165 struct mlx5_flow_table *mlx5e_vlan_get_flowtable(struct mlx5e_vlan_table *vlan)
166 {
167 	return vlan->ft.t;
168 }
169 
mlx5e_vport_context_update_vlans(struct mlx5e_flow_steering * fs)170 static int mlx5e_vport_context_update_vlans(struct mlx5e_flow_steering *fs)
171 {
172 	int max_list_size;
173 	int list_size;
174 	u16 *vlans;
175 	int vlan;
176 	int err;
177 	int i;
178 
179 	list_size = 0;
180 	for_each_set_bit(vlan, fs->vlan->active_cvlans, VLAN_N_VID)
181 		list_size++;
182 
183 	max_list_size = 1 << MLX5_CAP_GEN(fs->mdev, log_max_vlan_list);
184 
185 	if (list_size > max_list_size) {
186 		fs_warn(fs, "netdev vlans list size (%d) > (%d) max vport list size, some vlans will be dropped\n",
187 			list_size, max_list_size);
188 		list_size = max_list_size;
189 	}
190 
191 	vlans = kvcalloc(list_size, sizeof(*vlans), GFP_KERNEL);
192 	if (!vlans)
193 		return -ENOMEM;
194 
195 	i = 0;
196 	for_each_set_bit(vlan, fs->vlan->active_cvlans, VLAN_N_VID) {
197 		if (i >= list_size)
198 			break;
199 		vlans[i++] = vlan;
200 	}
201 
202 	err = mlx5_modify_nic_vport_vlans(fs->mdev, vlans, list_size);
203 	if (err)
204 		fs_err(fs, "Failed to modify vport vlans list err(%d)\n",
205 		       err);
206 
207 	kvfree(vlans);
208 	return err;
209 }
210 
211 enum mlx5e_vlan_rule_type {
212 	MLX5E_VLAN_RULE_TYPE_UNTAGGED,
213 	MLX5E_VLAN_RULE_TYPE_ANY_CTAG_VID,
214 	MLX5E_VLAN_RULE_TYPE_ANY_STAG_VID,
215 	MLX5E_VLAN_RULE_TYPE_MATCH_CTAG_VID,
216 	MLX5E_VLAN_RULE_TYPE_MATCH_STAG_VID,
217 };
218 
__mlx5e_add_vlan_rule(struct mlx5e_flow_steering * fs,enum mlx5e_vlan_rule_type rule_type,u16 vid,struct mlx5_flow_spec * spec)219 static int __mlx5e_add_vlan_rule(struct mlx5e_flow_steering *fs,
220 				 enum mlx5e_vlan_rule_type rule_type,
221 				 u16 vid, struct mlx5_flow_spec *spec)
222 {
223 	struct mlx5_flow_table *ft = fs->vlan->ft.t;
224 	struct mlx5_flow_destination dest = {};
225 	struct mlx5_flow_handle **rule_p;
226 	MLX5_DECLARE_FLOW_ACT(flow_act);
227 	int err = 0;
228 
229 	dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
230 	dest.ft = fs->l2.ft.t;
231 
232 	spec->match_criteria_enable = MLX5_MATCH_OUTER_HEADERS;
233 
234 	switch (rule_type) {
235 	case MLX5E_VLAN_RULE_TYPE_UNTAGGED:
236 		/* cvlan_tag enabled in match criteria and
237 		 * disabled in match value means both S & C tags
238 		 * don't exist (untagged of both)
239 		 */
240 		rule_p = &fs->vlan->untagged_rule;
241 		MLX5_SET_TO_ONES(fte_match_param, spec->match_criteria,
242 				 outer_headers.cvlan_tag);
243 		break;
244 	case MLX5E_VLAN_RULE_TYPE_ANY_CTAG_VID:
245 		rule_p = &fs->vlan->any_cvlan_rule;
246 		MLX5_SET_TO_ONES(fte_match_param, spec->match_criteria,
247 				 outer_headers.cvlan_tag);
248 		MLX5_SET(fte_match_param, spec->match_value, outer_headers.cvlan_tag, 1);
249 		break;
250 	case MLX5E_VLAN_RULE_TYPE_ANY_STAG_VID:
251 		rule_p = &fs->vlan->any_svlan_rule;
252 		MLX5_SET_TO_ONES(fte_match_param, spec->match_criteria,
253 				 outer_headers.svlan_tag);
254 		MLX5_SET(fte_match_param, spec->match_value, outer_headers.svlan_tag, 1);
255 		break;
256 	case MLX5E_VLAN_RULE_TYPE_MATCH_STAG_VID:
257 		rule_p = &fs->vlan->active_svlans_rule[vid];
258 		MLX5_SET_TO_ONES(fte_match_param, spec->match_criteria,
259 				 outer_headers.svlan_tag);
260 		MLX5_SET(fte_match_param, spec->match_value, outer_headers.svlan_tag, 1);
261 		MLX5_SET_TO_ONES(fte_match_param, spec->match_criteria,
262 				 outer_headers.first_vid);
263 		MLX5_SET(fte_match_param, spec->match_value, outer_headers.first_vid,
264 			 vid);
265 		break;
266 	default: /* MLX5E_VLAN_RULE_TYPE_MATCH_CTAG_VID */
267 		rule_p = &fs->vlan->active_cvlans_rule[vid];
268 		MLX5_SET_TO_ONES(fte_match_param, spec->match_criteria,
269 				 outer_headers.cvlan_tag);
270 		MLX5_SET(fte_match_param, spec->match_value, outer_headers.cvlan_tag, 1);
271 		MLX5_SET_TO_ONES(fte_match_param, spec->match_criteria,
272 				 outer_headers.first_vid);
273 		MLX5_SET(fte_match_param, spec->match_value, outer_headers.first_vid,
274 			 vid);
275 		break;
276 	}
277 
278 	if (WARN_ONCE(*rule_p, "VLAN rule already exists type %d", rule_type))
279 		return 0;
280 
281 	*rule_p = mlx5_add_flow_rules(ft, spec, &flow_act, &dest, 1);
282 
283 	if (IS_ERR(*rule_p)) {
284 		err = PTR_ERR(*rule_p);
285 		*rule_p = NULL;
286 		fs_err(fs, "%s: add rule failed\n", __func__);
287 	}
288 
289 	return err;
290 }
291 
mlx5e_add_vlan_rule(struct mlx5e_flow_steering * fs,enum mlx5e_vlan_rule_type rule_type,u16 vid)292 static int mlx5e_add_vlan_rule(struct mlx5e_flow_steering *fs,
293 			       enum mlx5e_vlan_rule_type rule_type, u16 vid)
294 {
295 	struct mlx5_flow_spec *spec;
296 	int err = 0;
297 
298 	spec = kvzalloc(sizeof(*spec), GFP_KERNEL);
299 	if (!spec)
300 		return -ENOMEM;
301 
302 	if (rule_type == MLX5E_VLAN_RULE_TYPE_MATCH_CTAG_VID)
303 		mlx5e_vport_context_update_vlans(fs);
304 
305 	err = __mlx5e_add_vlan_rule(fs, rule_type, vid, spec);
306 
307 	kvfree(spec);
308 
309 	return err;
310 }
311 
mlx5e_fs_del_vlan_rule(struct mlx5e_flow_steering * fs,enum mlx5e_vlan_rule_type rule_type,u16 vid)312 static void mlx5e_fs_del_vlan_rule(struct mlx5e_flow_steering *fs,
313 				   enum mlx5e_vlan_rule_type rule_type, u16 vid)
314 {
315 	switch (rule_type) {
316 	case MLX5E_VLAN_RULE_TYPE_UNTAGGED:
317 		if (fs->vlan->untagged_rule) {
318 			mlx5_del_flow_rules(fs->vlan->untagged_rule);
319 			fs->vlan->untagged_rule = NULL;
320 		}
321 		break;
322 	case MLX5E_VLAN_RULE_TYPE_ANY_CTAG_VID:
323 		if (fs->vlan->any_cvlan_rule) {
324 			mlx5_del_flow_rules(fs->vlan->any_cvlan_rule);
325 			fs->vlan->any_cvlan_rule = NULL;
326 		}
327 		break;
328 	case MLX5E_VLAN_RULE_TYPE_ANY_STAG_VID:
329 		if (fs->vlan->any_svlan_rule) {
330 			mlx5_del_flow_rules(fs->vlan->any_svlan_rule);
331 			fs->vlan->any_svlan_rule = NULL;
332 		}
333 		break;
334 	case MLX5E_VLAN_RULE_TYPE_MATCH_STAG_VID:
335 		if (fs->vlan->active_svlans_rule[vid]) {
336 			mlx5_del_flow_rules(fs->vlan->active_svlans_rule[vid]);
337 			fs->vlan->active_svlans_rule[vid] = NULL;
338 		}
339 		break;
340 	case MLX5E_VLAN_RULE_TYPE_MATCH_CTAG_VID:
341 		if (fs->vlan->active_cvlans_rule[vid]) {
342 			mlx5_del_flow_rules(fs->vlan->active_cvlans_rule[vid]);
343 			fs->vlan->active_cvlans_rule[vid] = NULL;
344 		}
345 		mlx5e_vport_context_update_vlans(fs);
346 		break;
347 	}
348 }
349 
mlx5e_fs_del_any_vid_rules(struct mlx5e_flow_steering * fs)350 static void mlx5e_fs_del_any_vid_rules(struct mlx5e_flow_steering *fs)
351 {
352 	mlx5e_fs_del_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_ANY_CTAG_VID, 0);
353 	mlx5e_fs_del_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_ANY_STAG_VID, 0);
354 }
355 
mlx5e_fs_add_any_vid_rules(struct mlx5e_flow_steering * fs)356 static int mlx5e_fs_add_any_vid_rules(struct mlx5e_flow_steering *fs)
357 {
358 	int err;
359 
360 	err = mlx5e_add_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_ANY_CTAG_VID, 0);
361 	if (err)
362 		return err;
363 
364 	return mlx5e_add_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_ANY_STAG_VID, 0);
365 }
366 
367 static struct mlx5_flow_handle *
mlx5e_add_trap_rule(struct mlx5_flow_table * ft,int trap_id,int tir_num)368 mlx5e_add_trap_rule(struct mlx5_flow_table *ft, int trap_id, int tir_num)
369 {
370 	struct mlx5_flow_destination dest = {};
371 	MLX5_DECLARE_FLOW_ACT(flow_act);
372 	struct mlx5_flow_handle *rule;
373 	struct mlx5_flow_spec *spec;
374 
375 	spec = kvzalloc(sizeof(*spec), GFP_KERNEL);
376 	if (!spec)
377 		return ERR_PTR(-ENOMEM);
378 	spec->flow_context.flags |= FLOW_CONTEXT_HAS_TAG;
379 	spec->flow_context.flow_tag = trap_id;
380 	dest.type = MLX5_FLOW_DESTINATION_TYPE_TIR;
381 	dest.tir_num = tir_num;
382 
383 	rule = mlx5_add_flow_rules(ft, spec, &flow_act, &dest, 1);
384 	kvfree(spec);
385 	return rule;
386 }
387 
mlx5e_add_vlan_trap(struct mlx5e_flow_steering * fs,int trap_id,int tir_num)388 int mlx5e_add_vlan_trap(struct mlx5e_flow_steering *fs, int trap_id, int tir_num)
389 {
390 	struct mlx5_flow_table *ft = fs->vlan->ft.t;
391 	struct mlx5_flow_handle *rule;
392 	int err;
393 
394 	rule = mlx5e_add_trap_rule(ft, trap_id, tir_num);
395 	if (IS_ERR(rule)) {
396 		err = PTR_ERR(rule);
397 		fs->vlan->trap_rule = NULL;
398 		fs_err(fs, "%s: add VLAN trap rule failed, err %d\n",
399 		       __func__, err);
400 		return err;
401 	}
402 	fs->vlan->trap_rule = rule;
403 	return 0;
404 }
405 
mlx5e_remove_vlan_trap(struct mlx5e_flow_steering * fs)406 void mlx5e_remove_vlan_trap(struct mlx5e_flow_steering *fs)
407 {
408 	if (fs->vlan->trap_rule) {
409 		mlx5_del_flow_rules(fs->vlan->trap_rule);
410 		fs->vlan->trap_rule = NULL;
411 	}
412 }
413 
mlx5e_add_mac_trap(struct mlx5e_flow_steering * fs,int trap_id,int tir_num)414 int mlx5e_add_mac_trap(struct mlx5e_flow_steering *fs, int trap_id, int tir_num)
415 {
416 	struct mlx5_flow_table *ft = fs->l2.ft.t;
417 	struct mlx5_flow_handle *rule;
418 	int err;
419 
420 	rule = mlx5e_add_trap_rule(ft, trap_id, tir_num);
421 	if (IS_ERR(rule)) {
422 		err = PTR_ERR(rule);
423 		fs->l2.trap_rule = NULL;
424 		fs_err(fs, "%s: add MAC trap rule failed, err %d\n",
425 		       __func__, err);
426 		return err;
427 	}
428 	fs->l2.trap_rule = rule;
429 	return 0;
430 }
431 
mlx5e_remove_mac_trap(struct mlx5e_flow_steering * fs)432 void mlx5e_remove_mac_trap(struct mlx5e_flow_steering *fs)
433 {
434 	if (fs->l2.trap_rule) {
435 		mlx5_del_flow_rules(fs->l2.trap_rule);
436 		fs->l2.trap_rule = NULL;
437 	}
438 }
439 
mlx5e_enable_cvlan_filter(struct mlx5e_flow_steering * fs,bool promisc)440 void mlx5e_enable_cvlan_filter(struct mlx5e_flow_steering *fs, bool promisc)
441 {
442 	if (!fs->vlan->cvlan_filter_disabled)
443 		return;
444 
445 	fs->vlan->cvlan_filter_disabled = false;
446 	if (promisc)
447 		return;
448 	mlx5e_fs_del_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_ANY_CTAG_VID, 0);
449 }
450 
mlx5e_disable_cvlan_filter(struct mlx5e_flow_steering * fs,bool promisc)451 void mlx5e_disable_cvlan_filter(struct mlx5e_flow_steering *fs, bool promisc)
452 {
453 	if (!fs->vlan || fs->vlan->cvlan_filter_disabled)
454 		return;
455 
456 	fs->vlan->cvlan_filter_disabled = true;
457 	if (promisc)
458 		return;
459 	mlx5e_add_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_ANY_CTAG_VID, 0);
460 }
461 
mlx5e_vlan_rx_add_cvid(struct mlx5e_flow_steering * fs,u16 vid)462 static int mlx5e_vlan_rx_add_cvid(struct mlx5e_flow_steering *fs, u16 vid)
463 {
464 	int err;
465 
466 	set_bit(vid, fs->vlan->active_cvlans);
467 
468 	err = mlx5e_add_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_MATCH_CTAG_VID, vid);
469 	if (err)
470 		clear_bit(vid, fs->vlan->active_cvlans);
471 
472 	return err;
473 }
474 
mlx5e_vlan_rx_add_svid(struct mlx5e_flow_steering * fs,struct net_device * netdev,u16 vid)475 static int mlx5e_vlan_rx_add_svid(struct mlx5e_flow_steering *fs,
476 				  struct net_device *netdev, u16 vid)
477 {
478 	int err;
479 
480 	set_bit(vid, fs->vlan->active_svlans);
481 
482 	err = mlx5e_add_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_MATCH_STAG_VID, vid);
483 	if (err) {
484 		clear_bit(vid, fs->vlan->active_svlans);
485 		return err;
486 	}
487 
488 	/* Need to fix some features.. */
489 	netdev_update_features(netdev);
490 	return err;
491 }
492 
mlx5e_fs_vlan_rx_add_vid(struct mlx5e_flow_steering * fs,struct net_device * netdev,__be16 proto,u16 vid)493 int mlx5e_fs_vlan_rx_add_vid(struct mlx5e_flow_steering *fs,
494 			     struct net_device *netdev,
495 			     __be16 proto, u16 vid)
496 {
497 
498 	if (!fs->vlan) {
499 		fs_err(fs, "Vlan doesn't exist\n");
500 		return -EINVAL;
501 	}
502 
503 	if (be16_to_cpu(proto) == ETH_P_8021Q)
504 		return mlx5e_vlan_rx_add_cvid(fs, vid);
505 	else if (be16_to_cpu(proto) == ETH_P_8021AD)
506 		return mlx5e_vlan_rx_add_svid(fs, netdev, vid);
507 
508 	return -EOPNOTSUPP;
509 }
510 
mlx5e_fs_vlan_rx_kill_vid(struct mlx5e_flow_steering * fs,struct net_device * netdev,__be16 proto,u16 vid)511 int mlx5e_fs_vlan_rx_kill_vid(struct mlx5e_flow_steering *fs,
512 			      struct net_device *netdev,
513 			      __be16 proto, u16 vid)
514 {
515 	if (!fs->vlan) {
516 		fs_err(fs, "Vlan doesn't exist\n");
517 		return -EINVAL;
518 	}
519 
520 	if (be16_to_cpu(proto) == ETH_P_8021Q) {
521 		clear_bit(vid, fs->vlan->active_cvlans);
522 		mlx5e_fs_del_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_MATCH_CTAG_VID, vid);
523 	} else if (be16_to_cpu(proto) == ETH_P_8021AD) {
524 		clear_bit(vid, fs->vlan->active_svlans);
525 		mlx5e_fs_del_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_MATCH_STAG_VID, vid);
526 		netdev_update_features(netdev);
527 	}
528 
529 	return 0;
530 }
531 
mlx5e_fs_add_vlan_rules(struct mlx5e_flow_steering * fs)532 static void mlx5e_fs_add_vlan_rules(struct mlx5e_flow_steering *fs)
533 {
534 	int i;
535 
536 	mlx5e_add_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_UNTAGGED, 0);
537 
538 	for_each_set_bit(i, fs->vlan->active_cvlans, VLAN_N_VID) {
539 		mlx5e_add_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_MATCH_CTAG_VID, i);
540 	}
541 
542 	for_each_set_bit(i, fs->vlan->active_svlans, VLAN_N_VID)
543 		mlx5e_add_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_MATCH_STAG_VID, i);
544 
545 	if (fs->vlan->cvlan_filter_disabled)
546 		mlx5e_fs_add_any_vid_rules(fs);
547 }
548 
mlx5e_del_vlan_rules(struct mlx5e_flow_steering * fs)549 static void mlx5e_del_vlan_rules(struct mlx5e_flow_steering *fs)
550 {
551 	int i;
552 
553 	mlx5e_fs_del_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_UNTAGGED, 0);
554 
555 	for_each_set_bit(i, fs->vlan->active_cvlans, VLAN_N_VID) {
556 		mlx5e_fs_del_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_MATCH_CTAG_VID, i);
557 	}
558 
559 	for_each_set_bit(i, fs->vlan->active_svlans, VLAN_N_VID)
560 		mlx5e_fs_del_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_MATCH_STAG_VID, i);
561 
562 	WARN_ON_ONCE(fs->state_destroy);
563 
564 	mlx5e_remove_vlan_trap(fs);
565 
566 	/* must be called after DESTROY bit is set and
567 	 * set_rx_mode is called and flushed
568 	 */
569 	if (fs->vlan->cvlan_filter_disabled)
570 		mlx5e_fs_del_any_vid_rules(fs);
571 }
572 
573 #define mlx5e_for_each_hash_node(hn, tmp, hash, i) \
574 	for (i = 0; i < MLX5E_L2_ADDR_HASH_SIZE; i++) \
575 		hlist_for_each_entry_safe(hn, tmp, &hash[i], hlist)
576 
mlx5e_execute_l2_action(struct mlx5e_flow_steering * fs,struct mlx5e_l2_hash_node * hn)577 static void mlx5e_execute_l2_action(struct mlx5e_flow_steering *fs,
578 				    struct mlx5e_l2_hash_node *hn)
579 {
580 	u8 action = hn->action;
581 	u8 mac_addr[ETH_ALEN];
582 	int l2_err = 0;
583 
584 	ether_addr_copy(mac_addr, hn->ai.addr);
585 
586 	switch (action) {
587 	case MLX5E_ACTION_ADD:
588 		mlx5e_add_l2_flow_rule(fs, &hn->ai, MLX5E_FULLMATCH);
589 		if (!is_multicast_ether_addr(mac_addr)) {
590 			l2_err = mlx5_mpfs_add_mac(fs->mdev, mac_addr);
591 			hn->mpfs = !l2_err;
592 		}
593 		hn->action = MLX5E_ACTION_NONE;
594 		break;
595 
596 	case MLX5E_ACTION_DEL:
597 		if (!is_multicast_ether_addr(mac_addr) && hn->mpfs)
598 			l2_err = mlx5_mpfs_del_mac(fs->mdev, mac_addr);
599 		mlx5e_del_l2_flow_rule(fs, &hn->ai);
600 		mlx5e_del_l2_from_hash(hn);
601 		break;
602 	}
603 
604 	if (l2_err)
605 		fs_warn(fs, "MPFS, failed to %s mac %pM, err(%d)\n",
606 			action == MLX5E_ACTION_ADD ? "add" : "del",
607 			mac_addr, l2_err);
608 }
609 
mlx5e_sync_netdev_addr(struct mlx5e_flow_steering * fs,struct net_device * netdev)610 static void mlx5e_sync_netdev_addr(struct mlx5e_flow_steering *fs,
611 				   struct net_device *netdev)
612 {
613 	struct netdev_hw_addr *ha;
614 
615 	netif_addr_lock_bh(netdev);
616 
617 	mlx5e_add_l2_to_hash(fs->l2.netdev_uc, netdev->dev_addr);
618 	netdev_for_each_uc_addr(ha, netdev)
619 		mlx5e_add_l2_to_hash(fs->l2.netdev_uc, ha->addr);
620 
621 	netdev_for_each_mc_addr(ha, netdev)
622 		mlx5e_add_l2_to_hash(fs->l2.netdev_mc, ha->addr);
623 
624 	netif_addr_unlock_bh(netdev);
625 }
626 
mlx5e_fill_addr_array(struct mlx5e_flow_steering * fs,int list_type,struct net_device * ndev,u8 addr_array[][ETH_ALEN],int size)627 static void mlx5e_fill_addr_array(struct mlx5e_flow_steering *fs, int list_type,
628 				  struct net_device *ndev,
629 				  u8 addr_array[][ETH_ALEN], int size)
630 {
631 	bool is_uc = (list_type == MLX5_NVPRT_LIST_TYPE_UC);
632 	struct mlx5e_l2_hash_node *hn;
633 	struct hlist_head *addr_list;
634 	struct hlist_node *tmp;
635 	int i = 0;
636 	int hi;
637 
638 	addr_list = is_uc ? fs->l2.netdev_uc : fs->l2.netdev_mc;
639 
640 	if (is_uc) /* Make sure our own address is pushed first */
641 		ether_addr_copy(addr_array[i++], ndev->dev_addr);
642 	else if (fs->l2.broadcast_enabled)
643 		ether_addr_copy(addr_array[i++], ndev->broadcast);
644 
645 	mlx5e_for_each_hash_node(hn, tmp, addr_list, hi) {
646 		if (ether_addr_equal(ndev->dev_addr, hn->ai.addr))
647 			continue;
648 		if (i >= size)
649 			break;
650 		ether_addr_copy(addr_array[i++], hn->ai.addr);
651 	}
652 }
653 
mlx5e_vport_context_update_addr_list(struct mlx5e_flow_steering * fs,struct net_device * netdev,int list_type)654 static void mlx5e_vport_context_update_addr_list(struct mlx5e_flow_steering *fs,
655 						 struct net_device *netdev,
656 						 int list_type)
657 {
658 	bool is_uc = (list_type == MLX5_NVPRT_LIST_TYPE_UC);
659 	struct mlx5e_l2_hash_node *hn;
660 	u8 (*addr_array)[ETH_ALEN] = NULL;
661 	struct hlist_head *addr_list;
662 	struct hlist_node *tmp;
663 	int max_size;
664 	int size;
665 	int err;
666 	int hi;
667 
668 	size = is_uc ? 0 : (fs->l2.broadcast_enabled ? 1 : 0);
669 	max_size = is_uc ?
670 		1 << MLX5_CAP_GEN(fs->mdev, log_max_current_uc_list) :
671 		1 << MLX5_CAP_GEN(fs->mdev, log_max_current_mc_list);
672 
673 	addr_list = is_uc ? fs->l2.netdev_uc : fs->l2.netdev_mc;
674 	mlx5e_for_each_hash_node(hn, tmp, addr_list, hi)
675 		size++;
676 
677 	if (size > max_size) {
678 		fs_warn(fs, "mdev %s list size (%d) > (%d) max vport list size, some addresses will be dropped\n",
679 			is_uc ? "UC" : "MC", size, max_size);
680 		size = max_size;
681 	}
682 
683 	if (size) {
684 		addr_array = kcalloc(size, ETH_ALEN, GFP_KERNEL);
685 		if (!addr_array) {
686 			err = -ENOMEM;
687 			goto out;
688 		}
689 		mlx5e_fill_addr_array(fs, list_type, netdev, addr_array, size);
690 	}
691 
692 	err = mlx5_modify_nic_vport_mac_list(fs->mdev, list_type, addr_array, size);
693 out:
694 	if (err)
695 		fs_err(fs, "Failed to modify vport %s list err(%d)\n",
696 		       is_uc ? "UC" : "MC", err);
697 	kfree(addr_array);
698 }
699 
mlx5e_vport_context_update(struct mlx5e_flow_steering * fs,struct net_device * netdev)700 static void mlx5e_vport_context_update(struct mlx5e_flow_steering *fs,
701 				       struct net_device *netdev)
702 {
703 	struct mlx5e_l2_table *ea = &fs->l2;
704 
705 	mlx5e_vport_context_update_addr_list(fs, netdev, MLX5_NVPRT_LIST_TYPE_UC);
706 	mlx5e_vport_context_update_addr_list(fs, netdev, MLX5_NVPRT_LIST_TYPE_MC);
707 	mlx5_modify_nic_vport_promisc(fs->mdev, 0,
708 				      ea->allmulti_enabled,
709 				      ea->promisc_enabled);
710 }
711 
mlx5e_apply_netdev_addr(struct mlx5e_flow_steering * fs)712 static void mlx5e_apply_netdev_addr(struct mlx5e_flow_steering *fs)
713 {
714 	struct mlx5e_l2_hash_node *hn;
715 	struct hlist_node *tmp;
716 	int i;
717 
718 	mlx5e_for_each_hash_node(hn, tmp, fs->l2.netdev_uc, i)
719 		mlx5e_execute_l2_action(fs, hn);
720 
721 	mlx5e_for_each_hash_node(hn, tmp, fs->l2.netdev_mc, i)
722 		mlx5e_execute_l2_action(fs, hn);
723 }
724 
mlx5e_handle_netdev_addr(struct mlx5e_flow_steering * fs,struct net_device * netdev)725 static void mlx5e_handle_netdev_addr(struct mlx5e_flow_steering *fs,
726 				     struct net_device *netdev)
727 {
728 	struct mlx5e_l2_hash_node *hn;
729 	struct hlist_node *tmp;
730 	int i;
731 
732 	mlx5e_for_each_hash_node(hn, tmp, fs->l2.netdev_uc, i)
733 		hn->action = MLX5E_ACTION_DEL;
734 	mlx5e_for_each_hash_node(hn, tmp, fs->l2.netdev_mc, i)
735 		hn->action = MLX5E_ACTION_DEL;
736 
737 	if (fs->state_destroy)
738 		mlx5e_sync_netdev_addr(fs, netdev);
739 
740 	mlx5e_apply_netdev_addr(fs);
741 }
742 
743 #define MLX5E_PROMISC_GROUP0_SIZE BIT(0)
744 #define MLX5E_PROMISC_TABLE_SIZE MLX5E_PROMISC_GROUP0_SIZE
745 
mlx5e_add_promisc_rule(struct mlx5e_flow_steering * fs)746 static int mlx5e_add_promisc_rule(struct mlx5e_flow_steering *fs)
747 {
748 	struct mlx5_flow_table *ft = fs->promisc.ft.t;
749 	struct mlx5_flow_destination dest = {};
750 	struct mlx5_flow_handle **rule_p;
751 	MLX5_DECLARE_FLOW_ACT(flow_act);
752 	struct mlx5_flow_spec *spec;
753 	int err = 0;
754 
755 	spec = kvzalloc(sizeof(*spec), GFP_KERNEL);
756 	if (!spec)
757 		return -ENOMEM;
758 	dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
759 	dest.ft = mlx5_get_ttc_flow_table(fs->ttc);
760 
761 	rule_p = &fs->promisc.rule;
762 	*rule_p = mlx5_add_flow_rules(ft, spec, &flow_act, &dest, 1);
763 	if (IS_ERR(*rule_p)) {
764 		err = PTR_ERR(*rule_p);
765 		*rule_p = NULL;
766 		fs_err(fs, "%s: add promiscuous rule failed\n", __func__);
767 	}
768 	kvfree(spec);
769 	return err;
770 }
771 
mlx5e_create_promisc_table(struct mlx5e_flow_steering * fs)772 static int mlx5e_create_promisc_table(struct mlx5e_flow_steering *fs)
773 {
774 	struct mlx5e_flow_table *ft = &fs->promisc.ft;
775 	struct mlx5_flow_table_attr ft_attr = {};
776 	int err;
777 
778 	ft_attr.max_fte = MLX5E_PROMISC_TABLE_SIZE;
779 	ft_attr.autogroup.max_num_groups = 1;
780 	ft_attr.level = MLX5E_PROMISC_FT_LEVEL;
781 	ft_attr.prio = MLX5E_NIC_PRIO;
782 
783 	ft->t = mlx5_create_auto_grouped_flow_table(fs->ns, &ft_attr);
784 	if (IS_ERR(ft->t)) {
785 		err = PTR_ERR(ft->t);
786 		fs_err(fs, "fail to create promisc table err=%d\n", err);
787 		return err;
788 	}
789 
790 	err = mlx5e_add_promisc_rule(fs);
791 	if (err)
792 		goto err_destroy_promisc_table;
793 
794 	return 0;
795 
796 err_destroy_promisc_table:
797 	mlx5_destroy_flow_table(ft->t);
798 	ft->t = NULL;
799 
800 	return err;
801 }
802 
mlx5e_del_promisc_rule(struct mlx5e_flow_steering * fs)803 static void mlx5e_del_promisc_rule(struct mlx5e_flow_steering *fs)
804 {
805 	if (WARN(!fs->promisc.rule, "Trying to remove non-existing promiscuous rule"))
806 		return;
807 	mlx5_del_flow_rules(fs->promisc.rule);
808 	fs->promisc.rule = NULL;
809 }
810 
mlx5e_destroy_promisc_table(struct mlx5e_flow_steering * fs)811 static void mlx5e_destroy_promisc_table(struct mlx5e_flow_steering *fs)
812 {
813 	if (WARN(!fs->promisc.ft.t, "Trying to remove non-existing promiscuous table"))
814 		return;
815 	mlx5e_del_promisc_rule(fs);
816 	mlx5_destroy_flow_table(fs->promisc.ft.t);
817 	fs->promisc.ft.t = NULL;
818 }
819 
mlx5e_fs_set_rx_mode_work(struct mlx5e_flow_steering * fs,struct net_device * netdev)820 void mlx5e_fs_set_rx_mode_work(struct mlx5e_flow_steering *fs,
821 			       struct net_device *netdev)
822 {
823 	struct mlx5e_l2_table *ea = &fs->l2;
824 
825 	bool rx_mode_enable  = fs->state_destroy;
826 	bool promisc_enabled   = rx_mode_enable && (netdev->flags & IFF_PROMISC);
827 	bool allmulti_enabled  = rx_mode_enable && (netdev->flags & IFF_ALLMULTI);
828 	bool broadcast_enabled = rx_mode_enable;
829 
830 	bool enable_promisc    = !ea->promisc_enabled   &&  promisc_enabled;
831 	bool disable_promisc   =  ea->promisc_enabled   && !promisc_enabled;
832 	bool enable_allmulti   = !ea->allmulti_enabled  &&  allmulti_enabled;
833 	bool disable_allmulti  =  ea->allmulti_enabled  && !allmulti_enabled;
834 	bool enable_broadcast  = !ea->broadcast_enabled &&  broadcast_enabled;
835 	bool disable_broadcast =  ea->broadcast_enabled && !broadcast_enabled;
836 	int err;
837 
838 	if (enable_promisc) {
839 		err = mlx5e_create_promisc_table(fs);
840 		if (err)
841 			enable_promisc = false;
842 		if (!fs->vlan_strip_disable && !err)
843 			fs_warn_once(fs,
844 				     "S-tagged traffic will be dropped while C-tag vlan stripping is enabled\n");
845 	}
846 	if (enable_allmulti)
847 		mlx5e_add_l2_flow_rule(fs, &ea->allmulti, MLX5E_ALLMULTI);
848 	if (enable_broadcast)
849 		mlx5e_add_l2_flow_rule(fs, &ea->broadcast, MLX5E_FULLMATCH);
850 
851 	mlx5e_handle_netdev_addr(fs, netdev);
852 
853 	if (disable_broadcast)
854 		mlx5e_del_l2_flow_rule(fs, &ea->broadcast);
855 	if (disable_allmulti)
856 		mlx5e_del_l2_flow_rule(fs, &ea->allmulti);
857 	if (disable_promisc)
858 		mlx5e_destroy_promisc_table(fs);
859 
860 	ea->promisc_enabled   = promisc_enabled;
861 	ea->allmulti_enabled  = allmulti_enabled;
862 	ea->broadcast_enabled = broadcast_enabled;
863 
864 	mlx5e_vport_context_update(fs, netdev);
865 }
866 
mlx5e_destroy_groups(struct mlx5e_flow_table * ft)867 static void mlx5e_destroy_groups(struct mlx5e_flow_table *ft)
868 {
869 	int i;
870 
871 	for (i = ft->num_groups - 1; i >= 0; i--) {
872 		if (!IS_ERR_OR_NULL(ft->g[i]))
873 			mlx5_destroy_flow_group(ft->g[i]);
874 		ft->g[i] = NULL;
875 	}
876 	ft->num_groups = 0;
877 }
878 
mlx5e_fs_init_l2_addr(struct mlx5e_flow_steering * fs,struct net_device * netdev)879 void mlx5e_fs_init_l2_addr(struct mlx5e_flow_steering *fs, struct net_device *netdev)
880 {
881 	ether_addr_copy(fs->l2.broadcast.addr, netdev->broadcast);
882 }
883 
mlx5e_destroy_flow_table(struct mlx5e_flow_table * ft)884 void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft)
885 {
886 	mlx5e_destroy_groups(ft);
887 	kfree(ft->g);
888 	mlx5_destroy_flow_table(ft->t);
889 	ft->t = NULL;
890 }
891 
mlx5e_set_inner_ttc_params(struct mlx5e_flow_steering * fs,struct mlx5e_rx_res * rx_res,struct ttc_params * ttc_params)892 static void mlx5e_set_inner_ttc_params(struct mlx5e_flow_steering *fs,
893 				       struct mlx5e_rx_res *rx_res,
894 				       struct ttc_params *ttc_params)
895 {
896 	struct mlx5_flow_table_attr *ft_attr = &ttc_params->ft_attr;
897 	int tt;
898 
899 	memset(ttc_params, 0, sizeof(*ttc_params));
900 	ttc_params->ns = mlx5_get_flow_namespace(fs->mdev,
901 						 MLX5_FLOW_NAMESPACE_KERNEL);
902 	ft_attr->level = MLX5E_INNER_TTC_FT_LEVEL;
903 	ft_attr->prio = MLX5E_NIC_PRIO;
904 
905 	for (tt = 0; tt < MLX5_NUM_TT; tt++) {
906 		ttc_params->dests[tt].type = MLX5_FLOW_DESTINATION_TYPE_TIR;
907 		ttc_params->dests[tt].tir_num =
908 			tt == MLX5_TT_ANY ?
909 				mlx5e_rx_res_get_tirn_direct(rx_res, 0) :
910 				mlx5e_rx_res_get_tirn_rss_inner(rx_res,
911 								tt);
912 	}
913 }
914 
mlx5e_set_ttc_params(struct mlx5e_flow_steering * fs,struct mlx5e_rx_res * rx_res,struct ttc_params * ttc_params,bool tunnel)915 void mlx5e_set_ttc_params(struct mlx5e_flow_steering *fs,
916 			  struct mlx5e_rx_res *rx_res,
917 			  struct ttc_params *ttc_params, bool tunnel)
918 
919 {
920 	struct mlx5_flow_table_attr *ft_attr = &ttc_params->ft_attr;
921 	int tt;
922 
923 	memset(ttc_params, 0, sizeof(*ttc_params));
924 	ttc_params->ns = mlx5_get_flow_namespace(fs->mdev,
925 						 MLX5_FLOW_NAMESPACE_KERNEL);
926 	ft_attr->level = MLX5E_TTC_FT_LEVEL;
927 	ft_attr->prio = MLX5E_NIC_PRIO;
928 
929 	for (tt = 0; tt < MLX5_NUM_TT; tt++) {
930 		ttc_params->dests[tt].type = MLX5_FLOW_DESTINATION_TYPE_TIR;
931 		ttc_params->dests[tt].tir_num =
932 			tt == MLX5_TT_ANY ?
933 				mlx5e_rx_res_get_tirn_direct(rx_res, 0) :
934 				mlx5e_rx_res_get_tirn_rss(rx_res, tt);
935 	}
936 
937 	ttc_params->inner_ttc = tunnel;
938 	if (!tunnel || !mlx5_tunnel_inner_ft_supported(fs->mdev))
939 		return;
940 
941 	for (tt = 0; tt < MLX5_NUM_TUNNEL_TT; tt++) {
942 		ttc_params->tunnel_dests[tt].type =
943 			MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
944 		ttc_params->tunnel_dests[tt].ft =
945 			mlx5_get_ttc_flow_table(fs->inner_ttc);
946 	}
947 }
948 
mlx5e_del_l2_flow_rule(struct mlx5e_flow_steering * fs,struct mlx5e_l2_rule * ai)949 static void mlx5e_del_l2_flow_rule(struct mlx5e_flow_steering *fs,
950 				   struct mlx5e_l2_rule *ai)
951 {
952 	if (!IS_ERR_OR_NULL(ai->rule)) {
953 		mlx5_del_flow_rules(ai->rule);
954 		ai->rule = NULL;
955 	}
956 }
957 
mlx5e_add_l2_flow_rule(struct mlx5e_flow_steering * fs,struct mlx5e_l2_rule * ai,int type)958 static int mlx5e_add_l2_flow_rule(struct mlx5e_flow_steering *fs,
959 				  struct mlx5e_l2_rule *ai, int type)
960 {
961 	struct mlx5_flow_table *ft = fs->l2.ft.t;
962 	struct mlx5_flow_destination dest = {};
963 	MLX5_DECLARE_FLOW_ACT(flow_act);
964 	struct mlx5_flow_spec *spec;
965 	int err = 0;
966 	u8 *mc_dmac;
967 	u8 *mv_dmac;
968 
969 	spec = kvzalloc(sizeof(*spec), GFP_KERNEL);
970 	if (!spec)
971 		return -ENOMEM;
972 
973 	mc_dmac = MLX5_ADDR_OF(fte_match_param, spec->match_criteria,
974 			       outer_headers.dmac_47_16);
975 	mv_dmac = MLX5_ADDR_OF(fte_match_param, spec->match_value,
976 			       outer_headers.dmac_47_16);
977 
978 	dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
979 	dest.ft = mlx5_get_ttc_flow_table(fs->ttc);
980 
981 	switch (type) {
982 	case MLX5E_FULLMATCH:
983 		spec->match_criteria_enable = MLX5_MATCH_OUTER_HEADERS;
984 		eth_broadcast_addr(mc_dmac);
985 		ether_addr_copy(mv_dmac, ai->addr);
986 		break;
987 
988 	case MLX5E_ALLMULTI:
989 		spec->match_criteria_enable = MLX5_MATCH_OUTER_HEADERS;
990 		mc_dmac[0] = 0x01;
991 		mv_dmac[0] = 0x01;
992 		break;
993 	}
994 
995 	ai->rule = mlx5_add_flow_rules(ft, spec, &flow_act, &dest, 1);
996 	if (IS_ERR(ai->rule)) {
997 		fs_err(fs, "%s: add l2 rule(mac:%pM) failed\n", __func__, mv_dmac);
998 		err = PTR_ERR(ai->rule);
999 		ai->rule = NULL;
1000 	}
1001 
1002 	kvfree(spec);
1003 
1004 	return err;
1005 }
1006 
1007 #define MLX5E_NUM_L2_GROUPS	   3
1008 #define MLX5E_L2_GROUP1_SIZE	   BIT(15)
1009 #define MLX5E_L2_GROUP2_SIZE	   BIT(0)
1010 #define MLX5E_L2_GROUP_TRAP_SIZE   BIT(0) /* must be last */
1011 #define MLX5E_L2_TABLE_SIZE	   (MLX5E_L2_GROUP1_SIZE +\
1012 				    MLX5E_L2_GROUP2_SIZE +\
1013 				    MLX5E_L2_GROUP_TRAP_SIZE)
mlx5e_create_l2_table_groups(struct mlx5e_l2_table * l2_table)1014 static int mlx5e_create_l2_table_groups(struct mlx5e_l2_table *l2_table)
1015 {
1016 	int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
1017 	struct mlx5e_flow_table *ft = &l2_table->ft;
1018 	int ix = 0;
1019 	u8 *mc_dmac;
1020 	u32 *in;
1021 	int err;
1022 	u8 *mc;
1023 
1024 	ft->g = kcalloc(MLX5E_NUM_L2_GROUPS, sizeof(*ft->g), GFP_KERNEL);
1025 	if (!ft->g)
1026 		return -ENOMEM;
1027 	in = kvzalloc(inlen, GFP_KERNEL);
1028 	if (!in) {
1029 		kfree(ft->g);
1030 		return -ENOMEM;
1031 	}
1032 
1033 	mc = MLX5_ADDR_OF(create_flow_group_in, in, match_criteria);
1034 	mc_dmac = MLX5_ADDR_OF(fte_match_param, mc,
1035 			       outer_headers.dmac_47_16);
1036 	/* Flow Group for full match */
1037 	eth_broadcast_addr(mc_dmac);
1038 	MLX5_SET_CFG(in, match_criteria_enable, MLX5_MATCH_OUTER_HEADERS);
1039 	MLX5_SET_CFG(in, start_flow_index, ix);
1040 	ix += MLX5E_L2_GROUP1_SIZE;
1041 	MLX5_SET_CFG(in, end_flow_index, ix - 1);
1042 	ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
1043 	if (IS_ERR(ft->g[ft->num_groups]))
1044 		goto err_destroy_groups;
1045 	ft->num_groups++;
1046 
1047 	/* Flow Group for allmulti */
1048 	eth_zero_addr(mc_dmac);
1049 	mc_dmac[0] = 0x01;
1050 	MLX5_SET_CFG(in, start_flow_index, ix);
1051 	ix += MLX5E_L2_GROUP2_SIZE;
1052 	MLX5_SET_CFG(in, end_flow_index, ix - 1);
1053 	ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
1054 	if (IS_ERR(ft->g[ft->num_groups]))
1055 		goto err_destroy_groups;
1056 	ft->num_groups++;
1057 
1058 	/* Flow Group for l2 traps */
1059 	memset(in, 0, inlen);
1060 	MLX5_SET_CFG(in, start_flow_index, ix);
1061 	ix += MLX5E_L2_GROUP_TRAP_SIZE;
1062 	MLX5_SET_CFG(in, end_flow_index, ix - 1);
1063 	ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
1064 	if (IS_ERR(ft->g[ft->num_groups]))
1065 		goto err_destroy_groups;
1066 	ft->num_groups++;
1067 
1068 	kvfree(in);
1069 	return 0;
1070 
1071 err_destroy_groups:
1072 	err = PTR_ERR(ft->g[ft->num_groups]);
1073 	ft->g[ft->num_groups] = NULL;
1074 	mlx5e_destroy_groups(ft);
1075 	kvfree(in);
1076 	kfree(ft->g);
1077 
1078 	return err;
1079 }
1080 
mlx5e_destroy_l2_table(struct mlx5e_flow_steering * fs)1081 static void mlx5e_destroy_l2_table(struct mlx5e_flow_steering *fs)
1082 {
1083 	mlx5e_destroy_flow_table(&fs->l2.ft);
1084 }
1085 
mlx5e_create_l2_table(struct mlx5e_flow_steering * fs)1086 static int mlx5e_create_l2_table(struct mlx5e_flow_steering *fs)
1087 {
1088 	struct mlx5e_l2_table *l2_table = &fs->l2;
1089 	struct mlx5e_flow_table *ft = &l2_table->ft;
1090 	struct mlx5_flow_table_attr ft_attr = {};
1091 	int err;
1092 
1093 	ft->num_groups = 0;
1094 
1095 	ft_attr.max_fte = MLX5E_L2_TABLE_SIZE;
1096 	ft_attr.level = MLX5E_L2_FT_LEVEL;
1097 	ft_attr.prio = MLX5E_NIC_PRIO;
1098 
1099 	ft->t = mlx5_create_flow_table(fs->ns, &ft_attr);
1100 	if (IS_ERR(ft->t)) {
1101 		err = PTR_ERR(ft->t);
1102 		ft->t = NULL;
1103 		return err;
1104 	}
1105 
1106 	err = mlx5e_create_l2_table_groups(l2_table);
1107 	if (err)
1108 		goto err_destroy_flow_table;
1109 
1110 	return 0;
1111 
1112 err_destroy_flow_table:
1113 	mlx5_destroy_flow_table(ft->t);
1114 	ft->t = NULL;
1115 
1116 	return err;
1117 }
1118 
1119 #define MLX5E_NUM_VLAN_GROUPS	5
1120 #define MLX5E_VLAN_GROUP0_SIZE	BIT(12)
1121 #define MLX5E_VLAN_GROUP1_SIZE	BIT(12)
1122 #define MLX5E_VLAN_GROUP2_SIZE	BIT(1)
1123 #define MLX5E_VLAN_GROUP3_SIZE	BIT(0)
1124 #define MLX5E_VLAN_GROUP_TRAP_SIZE BIT(0) /* must be last */
1125 #define MLX5E_VLAN_TABLE_SIZE	(MLX5E_VLAN_GROUP0_SIZE +\
1126 				 MLX5E_VLAN_GROUP1_SIZE +\
1127 				 MLX5E_VLAN_GROUP2_SIZE +\
1128 				 MLX5E_VLAN_GROUP3_SIZE +\
1129 				 MLX5E_VLAN_GROUP_TRAP_SIZE)
1130 
__mlx5e_create_vlan_table_groups(struct mlx5e_flow_table * ft,u32 * in,int inlen)1131 static int __mlx5e_create_vlan_table_groups(struct mlx5e_flow_table *ft, u32 *in,
1132 					    int inlen)
1133 {
1134 	int err;
1135 	int ix = 0;
1136 	u8 *mc = MLX5_ADDR_OF(create_flow_group_in, in, match_criteria);
1137 
1138 	memset(in, 0, inlen);
1139 	MLX5_SET_CFG(in, match_criteria_enable, MLX5_MATCH_OUTER_HEADERS);
1140 	MLX5_SET_TO_ONES(fte_match_param, mc, outer_headers.cvlan_tag);
1141 	MLX5_SET_TO_ONES(fte_match_param, mc, outer_headers.first_vid);
1142 	MLX5_SET_CFG(in, start_flow_index, ix);
1143 	ix += MLX5E_VLAN_GROUP0_SIZE;
1144 	MLX5_SET_CFG(in, end_flow_index, ix - 1);
1145 	ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
1146 	if (IS_ERR(ft->g[ft->num_groups]))
1147 		goto err_destroy_groups;
1148 	ft->num_groups++;
1149 
1150 	memset(in, 0, inlen);
1151 	MLX5_SET_CFG(in, match_criteria_enable, MLX5_MATCH_OUTER_HEADERS);
1152 	MLX5_SET_TO_ONES(fte_match_param, mc, outer_headers.svlan_tag);
1153 	MLX5_SET_TO_ONES(fte_match_param, mc, outer_headers.first_vid);
1154 	MLX5_SET_CFG(in, start_flow_index, ix);
1155 	ix += MLX5E_VLAN_GROUP1_SIZE;
1156 	MLX5_SET_CFG(in, end_flow_index, ix - 1);
1157 	ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
1158 	if (IS_ERR(ft->g[ft->num_groups]))
1159 		goto err_destroy_groups;
1160 	ft->num_groups++;
1161 
1162 	memset(in, 0, inlen);
1163 	MLX5_SET_CFG(in, match_criteria_enable, MLX5_MATCH_OUTER_HEADERS);
1164 	MLX5_SET_TO_ONES(fte_match_param, mc, outer_headers.cvlan_tag);
1165 	MLX5_SET_CFG(in, start_flow_index, ix);
1166 	ix += MLX5E_VLAN_GROUP2_SIZE;
1167 	MLX5_SET_CFG(in, end_flow_index, ix - 1);
1168 	ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
1169 	if (IS_ERR(ft->g[ft->num_groups]))
1170 		goto err_destroy_groups;
1171 	ft->num_groups++;
1172 
1173 	memset(in, 0, inlen);
1174 	MLX5_SET_CFG(in, match_criteria_enable, MLX5_MATCH_OUTER_HEADERS);
1175 	MLX5_SET_TO_ONES(fte_match_param, mc, outer_headers.svlan_tag);
1176 	MLX5_SET_CFG(in, start_flow_index, ix);
1177 	ix += MLX5E_VLAN_GROUP3_SIZE;
1178 	MLX5_SET_CFG(in, end_flow_index, ix - 1);
1179 	ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
1180 	if (IS_ERR(ft->g[ft->num_groups]))
1181 		goto err_destroy_groups;
1182 	ft->num_groups++;
1183 
1184 	memset(in, 0, inlen);
1185 	MLX5_SET_CFG(in, start_flow_index, ix);
1186 	ix += MLX5E_VLAN_GROUP_TRAP_SIZE;
1187 	MLX5_SET_CFG(in, end_flow_index, ix - 1);
1188 	ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
1189 	if (IS_ERR(ft->g[ft->num_groups]))
1190 		goto err_destroy_groups;
1191 	ft->num_groups++;
1192 
1193 	return 0;
1194 
1195 err_destroy_groups:
1196 	err = PTR_ERR(ft->g[ft->num_groups]);
1197 	ft->g[ft->num_groups] = NULL;
1198 	mlx5e_destroy_groups(ft);
1199 
1200 	return err;
1201 }
1202 
mlx5e_create_vlan_table_groups(struct mlx5e_flow_table * ft)1203 static int mlx5e_create_vlan_table_groups(struct mlx5e_flow_table *ft)
1204 {
1205 	u32 *in;
1206 	int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
1207 	int err;
1208 
1209 	in = kvzalloc(inlen, GFP_KERNEL);
1210 	if (!in)
1211 		return -ENOMEM;
1212 
1213 	err = __mlx5e_create_vlan_table_groups(ft, in, inlen);
1214 
1215 	kvfree(in);
1216 	return err;
1217 }
1218 
mlx5e_fs_create_vlan_table(struct mlx5e_flow_steering * fs)1219 static int mlx5e_fs_create_vlan_table(struct mlx5e_flow_steering *fs)
1220 {
1221 	struct mlx5_flow_table_attr ft_attr = {};
1222 	struct mlx5e_flow_table *ft;
1223 	int err;
1224 
1225 	ft = &fs->vlan->ft;
1226 	ft->num_groups = 0;
1227 
1228 	ft_attr.max_fte = MLX5E_VLAN_TABLE_SIZE;
1229 	ft_attr.level = MLX5E_VLAN_FT_LEVEL;
1230 	ft_attr.prio = MLX5E_NIC_PRIO;
1231 
1232 	ft->t = mlx5_create_flow_table(fs->ns, &ft_attr);
1233 	if (IS_ERR(ft->t))
1234 		return PTR_ERR(ft->t);
1235 
1236 	ft->g = kcalloc(MLX5E_NUM_VLAN_GROUPS, sizeof(*ft->g), GFP_KERNEL);
1237 	if (!ft->g) {
1238 		err = -ENOMEM;
1239 		goto err_destroy_vlan_table;
1240 	}
1241 
1242 	err = mlx5e_create_vlan_table_groups(ft);
1243 	if (err)
1244 		goto err_free_g;
1245 
1246 	mlx5e_fs_add_vlan_rules(fs);
1247 
1248 	return 0;
1249 
1250 err_free_g:
1251 	kfree(ft->g);
1252 err_destroy_vlan_table:
1253 	mlx5_destroy_flow_table(ft->t);
1254 
1255 	return err;
1256 }
1257 
mlx5e_destroy_vlan_table(struct mlx5e_flow_steering * fs)1258 static void mlx5e_destroy_vlan_table(struct mlx5e_flow_steering *fs)
1259 {
1260 	mlx5e_del_vlan_rules(fs);
1261 	mlx5e_destroy_flow_table(&fs->vlan->ft);
1262 }
1263 
mlx5e_destroy_inner_ttc_table(struct mlx5e_flow_steering * fs)1264 static void mlx5e_destroy_inner_ttc_table(struct mlx5e_flow_steering *fs)
1265 {
1266 	if (!mlx5_tunnel_inner_ft_supported(fs->mdev))
1267 		return;
1268 	mlx5_destroy_ttc_table(fs->inner_ttc);
1269 }
1270 
mlx5e_destroy_ttc_table(struct mlx5e_flow_steering * fs)1271 void mlx5e_destroy_ttc_table(struct mlx5e_flow_steering *fs)
1272 {
1273 	mlx5_destroy_ttc_table(fs->ttc);
1274 }
1275 
mlx5e_create_inner_ttc_table(struct mlx5e_flow_steering * fs,struct mlx5e_rx_res * rx_res)1276 static int mlx5e_create_inner_ttc_table(struct mlx5e_flow_steering *fs,
1277 					struct mlx5e_rx_res *rx_res)
1278 {
1279 	struct ttc_params ttc_params = {};
1280 
1281 	if (!mlx5_tunnel_inner_ft_supported(fs->mdev))
1282 		return 0;
1283 
1284 	mlx5e_set_inner_ttc_params(fs, rx_res, &ttc_params);
1285 	fs->inner_ttc = mlx5_create_inner_ttc_table(fs->mdev,
1286 						    &ttc_params);
1287 	if (IS_ERR(fs->inner_ttc))
1288 		return PTR_ERR(fs->inner_ttc);
1289 	return 0;
1290 }
1291 
mlx5e_create_ttc_table(struct mlx5e_flow_steering * fs,struct mlx5e_rx_res * rx_res)1292 int mlx5e_create_ttc_table(struct mlx5e_flow_steering *fs,
1293 			   struct mlx5e_rx_res *rx_res)
1294 {
1295 	struct ttc_params ttc_params = {};
1296 
1297 	mlx5e_set_ttc_params(fs, rx_res, &ttc_params, true);
1298 	fs->ttc = mlx5_create_ttc_table(fs->mdev, &ttc_params);
1299 	if (IS_ERR(fs->ttc))
1300 		return PTR_ERR(fs->ttc);
1301 	return 0;
1302 }
1303 
mlx5e_create_flow_steering(struct mlx5e_flow_steering * fs,struct mlx5e_rx_res * rx_res,const struct mlx5e_profile * profile,struct net_device * netdev)1304 int mlx5e_create_flow_steering(struct mlx5e_flow_steering *fs,
1305 			       struct mlx5e_rx_res *rx_res,
1306 			       const struct mlx5e_profile *profile,
1307 			       struct net_device *netdev)
1308 {
1309 	struct mlx5_flow_namespace *ns = mlx5_get_flow_namespace(fs->mdev,
1310 								 MLX5_FLOW_NAMESPACE_KERNEL);
1311 	int err;
1312 
1313 	if (!ns)
1314 		return -EOPNOTSUPP;
1315 
1316 	mlx5e_fs_set_ns(fs, ns, false);
1317 	err = mlx5e_arfs_create_tables(fs, rx_res,
1318 				       !!(netdev->hw_features & NETIF_F_NTUPLE));
1319 	if (err) {
1320 		fs_err(fs, "Failed to create arfs tables, err=%d\n", err);
1321 		netdev->hw_features &= ~NETIF_F_NTUPLE;
1322 	}
1323 
1324 	err = mlx5e_create_inner_ttc_table(fs, rx_res);
1325 	if (err) {
1326 		fs_err(fs, "Failed to create inner ttc table, err=%d\n", err);
1327 		goto err_destroy_arfs_tables;
1328 	}
1329 
1330 	err = mlx5e_create_ttc_table(fs, rx_res);
1331 	if (err) {
1332 		fs_err(fs, "Failed to create ttc table, err=%d\n", err);
1333 		goto err_destroy_inner_ttc_table;
1334 	}
1335 
1336 	err = mlx5e_create_l2_table(fs);
1337 	if (err) {
1338 		fs_err(fs, "Failed to create l2 table, err=%d\n", err);
1339 		goto err_destroy_ttc_table;
1340 	}
1341 
1342 	err = mlx5e_fs_create_vlan_table(fs);
1343 	if (err) {
1344 		fs_err(fs, "Failed to create vlan table, err=%d\n", err);
1345 		goto err_destroy_l2_table;
1346 	}
1347 
1348 	err = mlx5e_ptp_alloc_rx_fs(fs, profile);
1349 	if (err)
1350 		goto err_destory_vlan_table;
1351 
1352 	mlx5e_ethtool_init_steering(fs);
1353 
1354 	return 0;
1355 
1356 err_destory_vlan_table:
1357 	mlx5e_destroy_vlan_table(fs);
1358 err_destroy_l2_table:
1359 	mlx5e_destroy_l2_table(fs);
1360 err_destroy_ttc_table:
1361 	mlx5e_destroy_ttc_table(fs);
1362 err_destroy_inner_ttc_table:
1363 	mlx5e_destroy_inner_ttc_table(fs);
1364 err_destroy_arfs_tables:
1365 	mlx5e_arfs_destroy_tables(fs, !!(netdev->hw_features & NETIF_F_NTUPLE));
1366 
1367 	return err;
1368 }
1369 
mlx5e_destroy_flow_steering(struct mlx5e_flow_steering * fs,bool ntuple,const struct mlx5e_profile * profile)1370 void mlx5e_destroy_flow_steering(struct mlx5e_flow_steering *fs, bool ntuple,
1371 				 const struct mlx5e_profile *profile)
1372 {
1373 	mlx5e_ptp_free_rx_fs(fs, profile);
1374 	mlx5e_destroy_vlan_table(fs);
1375 	mlx5e_destroy_l2_table(fs);
1376 	mlx5e_destroy_ttc_table(fs);
1377 	mlx5e_destroy_inner_ttc_table(fs);
1378 	mlx5e_arfs_destroy_tables(fs, ntuple);
1379 	mlx5e_ethtool_cleanup_steering(fs);
1380 }
1381 
mlx5e_fs_vlan_alloc(struct mlx5e_flow_steering * fs)1382 static int mlx5e_fs_vlan_alloc(struct mlx5e_flow_steering *fs)
1383 {
1384 	fs->vlan = kvzalloc(sizeof(*fs->vlan), GFP_KERNEL);
1385 	if (!fs->vlan)
1386 		return -ENOMEM;
1387 	return 0;
1388 }
1389 
mlx5e_fs_vlan_free(struct mlx5e_flow_steering * fs)1390 static void mlx5e_fs_vlan_free(struct mlx5e_flow_steering *fs)
1391 {
1392 	kvfree(fs->vlan);
1393 }
1394 
mlx5e_fs_get_vlan(struct mlx5e_flow_steering * fs)1395 struct mlx5e_vlan_table *mlx5e_fs_get_vlan(struct mlx5e_flow_steering *fs)
1396 {
1397 	return fs->vlan;
1398 }
1399 
mlx5e_fs_tc_alloc(struct mlx5e_flow_steering * fs)1400 static int mlx5e_fs_tc_alloc(struct mlx5e_flow_steering *fs)
1401 {
1402 	fs->tc = mlx5e_tc_table_alloc();
1403 	if (IS_ERR(fs->tc))
1404 		return -ENOMEM;
1405 	return 0;
1406 }
1407 
mlx5e_fs_tc_free(struct mlx5e_flow_steering * fs)1408 static void mlx5e_fs_tc_free(struct mlx5e_flow_steering *fs)
1409 {
1410 	mlx5e_tc_table_free(fs->tc);
1411 }
1412 
mlx5e_fs_get_tc(struct mlx5e_flow_steering * fs)1413 struct mlx5e_tc_table *mlx5e_fs_get_tc(struct mlx5e_flow_steering *fs)
1414 {
1415 	return fs->tc;
1416 }
1417 
1418 #ifdef CONFIG_MLX5_EN_RXNFC
mlx5e_fs_ethtool_alloc(struct mlx5e_flow_steering * fs)1419 static int mlx5e_fs_ethtool_alloc(struct mlx5e_flow_steering *fs)
1420 {
1421 	return mlx5e_ethtool_alloc(&fs->ethtool);
1422 }
1423 
mlx5e_fs_ethtool_free(struct mlx5e_flow_steering * fs)1424 static void mlx5e_fs_ethtool_free(struct mlx5e_flow_steering *fs)
1425 {
1426 	mlx5e_ethtool_free(fs->ethtool);
1427 }
1428 
mlx5e_fs_get_ethtool(struct mlx5e_flow_steering * fs)1429 struct mlx5e_ethtool_steering *mlx5e_fs_get_ethtool(struct mlx5e_flow_steering *fs)
1430 {
1431 	return fs->ethtool;
1432 }
1433 #else
mlx5e_fs_ethtool_alloc(struct mlx5e_flow_steering * fs)1434 static int mlx5e_fs_ethtool_alloc(struct mlx5e_flow_steering *fs)
1435 { return 0; }
mlx5e_fs_ethtool_free(struct mlx5e_flow_steering * fs)1436 static void mlx5e_fs_ethtool_free(struct mlx5e_flow_steering *fs) { }
1437 #endif
1438 
mlx5e_fs_debugfs_init(struct mlx5e_flow_steering * fs,struct dentry * dfs_root)1439 static void mlx5e_fs_debugfs_init(struct mlx5e_flow_steering *fs,
1440 				  struct dentry *dfs_root)
1441 {
1442 	if (IS_ERR_OR_NULL(dfs_root))
1443 		return;
1444 
1445 	fs->dfs_root = debugfs_create_dir("fs", dfs_root);
1446 }
1447 
mlx5e_fs_init(const struct mlx5e_profile * profile,struct mlx5_core_dev * mdev,bool state_destroy,struct dentry * dfs_root)1448 struct mlx5e_flow_steering *mlx5e_fs_init(const struct mlx5e_profile *profile,
1449 					  struct mlx5_core_dev *mdev,
1450 					  bool state_destroy,
1451 					  struct dentry *dfs_root)
1452 {
1453 	struct mlx5e_flow_steering *fs;
1454 	int err;
1455 
1456 	fs = kvzalloc(sizeof(*fs), GFP_KERNEL);
1457 	if (!fs)
1458 		goto err;
1459 
1460 	fs->mdev = mdev;
1461 	fs->state_destroy = state_destroy;
1462 	if (mlx5e_profile_feature_cap(profile, FS_VLAN)) {
1463 		err = mlx5e_fs_vlan_alloc(fs);
1464 		if (err)
1465 			goto err_free_fs;
1466 	}
1467 
1468 	if (mlx5e_profile_feature_cap(profile, FS_TC)) {
1469 		err = mlx5e_fs_tc_alloc(fs);
1470 		if (err)
1471 			goto err_free_vlan;
1472 	}
1473 
1474 	err = mlx5e_fs_ethtool_alloc(fs);
1475 	if (err)
1476 		goto err_free_tc;
1477 
1478 	mlx5e_fs_debugfs_init(fs, dfs_root);
1479 
1480 	return fs;
1481 err_free_tc:
1482 	mlx5e_fs_tc_free(fs);
1483 err_free_vlan:
1484 	mlx5e_fs_vlan_free(fs);
1485 err_free_fs:
1486 	kvfree(fs);
1487 err:
1488 	return NULL;
1489 }
1490 
mlx5e_fs_cleanup(struct mlx5e_flow_steering * fs)1491 void mlx5e_fs_cleanup(struct mlx5e_flow_steering *fs)
1492 {
1493 	debugfs_remove_recursive(fs->dfs_root);
1494 	mlx5e_fs_ethtool_free(fs);
1495 	mlx5e_fs_tc_free(fs);
1496 	mlx5e_fs_vlan_free(fs);
1497 	kvfree(fs);
1498 }
1499 
mlx5e_fs_get_l2(struct mlx5e_flow_steering * fs)1500 struct mlx5e_l2_table *mlx5e_fs_get_l2(struct mlx5e_flow_steering *fs)
1501 {
1502 	return &fs->l2;
1503 }
1504 
mlx5e_fs_get_ns(struct mlx5e_flow_steering * fs,bool egress)1505 struct mlx5_flow_namespace *mlx5e_fs_get_ns(struct mlx5e_flow_steering *fs, bool egress)
1506 {
1507 	return  egress ? fs->egress_ns : fs->ns;
1508 }
1509 
mlx5e_fs_set_ns(struct mlx5e_flow_steering * fs,struct mlx5_flow_namespace * ns,bool egress)1510 void mlx5e_fs_set_ns(struct mlx5e_flow_steering *fs, struct mlx5_flow_namespace *ns, bool egress)
1511 {
1512 	if (!egress)
1513 		fs->ns = ns;
1514 	else
1515 		fs->egress_ns = ns;
1516 }
1517 
mlx5e_fs_get_ttc(struct mlx5e_flow_steering * fs,bool inner)1518 struct mlx5_ttc_table *mlx5e_fs_get_ttc(struct mlx5e_flow_steering *fs, bool inner)
1519 {
1520 	return inner ? fs->inner_ttc : fs->ttc;
1521 }
1522 
mlx5e_fs_set_ttc(struct mlx5e_flow_steering * fs,struct mlx5_ttc_table * ttc,bool inner)1523 void mlx5e_fs_set_ttc(struct mlx5e_flow_steering *fs, struct mlx5_ttc_table *ttc, bool inner)
1524 {
1525 	if (!inner)
1526 		fs->ttc = ttc;
1527 	else
1528 		fs->inner_ttc = ttc;
1529 }
1530 
1531 #ifdef CONFIG_MLX5_EN_ARFS
mlx5e_fs_get_arfs(struct mlx5e_flow_steering * fs)1532 struct mlx5e_arfs_tables *mlx5e_fs_get_arfs(struct mlx5e_flow_steering *fs)
1533 {
1534 	return fs->arfs;
1535 }
1536 
mlx5e_fs_set_arfs(struct mlx5e_flow_steering * fs,struct mlx5e_arfs_tables * arfs)1537 void mlx5e_fs_set_arfs(struct mlx5e_flow_steering *fs, struct mlx5e_arfs_tables *arfs)
1538 {
1539 	fs->arfs = arfs;
1540 }
1541 #endif
1542 
mlx5e_fs_get_ptp(struct mlx5e_flow_steering * fs)1543 struct mlx5e_ptp_fs *mlx5e_fs_get_ptp(struct mlx5e_flow_steering *fs)
1544 {
1545 	return fs->ptp_fs;
1546 }
1547 
mlx5e_fs_set_ptp(struct mlx5e_flow_steering * fs,struct mlx5e_ptp_fs * ptp_fs)1548 void mlx5e_fs_set_ptp(struct mlx5e_flow_steering *fs, struct mlx5e_ptp_fs *ptp_fs)
1549 {
1550 	fs->ptp_fs = ptp_fs;
1551 }
1552 
mlx5e_fs_get_any(struct mlx5e_flow_steering * fs)1553 struct mlx5e_fs_any *mlx5e_fs_get_any(struct mlx5e_flow_steering *fs)
1554 {
1555 	return fs->any;
1556 }
1557 
mlx5e_fs_set_any(struct mlx5e_flow_steering * fs,struct mlx5e_fs_any * any)1558 void mlx5e_fs_set_any(struct mlx5e_flow_steering *fs, struct mlx5e_fs_any *any)
1559 {
1560 	fs->any = any;
1561 }
1562 
1563 #ifdef CONFIG_MLX5_EN_TLS
mlx5e_fs_get_accel_tcp(struct mlx5e_flow_steering * fs)1564 struct mlx5e_accel_fs_tcp *mlx5e_fs_get_accel_tcp(struct mlx5e_flow_steering *fs)
1565 {
1566 	return fs->accel_tcp;
1567 }
1568 
mlx5e_fs_set_accel_tcp(struct mlx5e_flow_steering * fs,struct mlx5e_accel_fs_tcp * accel_tcp)1569 void mlx5e_fs_set_accel_tcp(struct mlx5e_flow_steering *fs, struct mlx5e_accel_fs_tcp *accel_tcp)
1570 {
1571 	fs->accel_tcp = accel_tcp;
1572 }
1573 #endif
1574 
mlx5e_fs_set_state_destroy(struct mlx5e_flow_steering * fs,bool state_destroy)1575 void mlx5e_fs_set_state_destroy(struct mlx5e_flow_steering *fs, bool state_destroy)
1576 {
1577 	fs->state_destroy = state_destroy;
1578 }
1579 
mlx5e_fs_set_vlan_strip_disable(struct mlx5e_flow_steering * fs,bool vlan_strip_disable)1580 void mlx5e_fs_set_vlan_strip_disable(struct mlx5e_flow_steering *fs,
1581 				     bool vlan_strip_disable)
1582 {
1583 	fs->vlan_strip_disable = vlan_strip_disable;
1584 }
1585 
mlx5e_fs_get_udp(struct mlx5e_flow_steering * fs)1586 struct mlx5e_fs_udp *mlx5e_fs_get_udp(struct mlx5e_flow_steering *fs)
1587 {
1588 	return fs->udp;
1589 }
1590 
mlx5e_fs_set_udp(struct mlx5e_flow_steering * fs,struct mlx5e_fs_udp * udp)1591 void mlx5e_fs_set_udp(struct mlx5e_flow_steering *fs, struct mlx5e_fs_udp *udp)
1592 {
1593 	fs->udp = udp;
1594 }
1595 
mlx5e_fs_get_mdev(struct mlx5e_flow_steering * fs)1596 struct mlx5_core_dev *mlx5e_fs_get_mdev(struct mlx5e_flow_steering *fs)
1597 {
1598 	return fs->mdev;
1599 }
1600