2 * Copyright (c) 2015, Mellanox Technologies. All rights reserved.
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
33 #include <linux/debugfs.h>
34 #include <linux/list.h>
36 #include <linux/ipv6.h>
37 #include <linux/tcp.h>
38 #include <linux/mlx5/fs.h>
39 #include <linux/mlx5/mpfs.h>
43 #include "en/fs_ethtool.h"
45 struct mlx5e_flow_steering {
46 struct work_struct set_rx_mode_work;
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;
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;
65 #ifdef CONFIG_MLX5_EN_TLS
66 struct mlx5e_accel_fs_tcp *accel_tcp;
68 struct mlx5e_fs_udp *udp;
69 struct mlx5e_fs_any *any;
70 struct mlx5e_ptp_fs *ptp_fs;
71 struct dentry *dfs_root;
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);
92 MLX5E_ACTION_NONE = 0,
97 struct mlx5e_l2_hash_node {
98 struct hlist_node hlist;
100 struct mlx5e_l2_rule ai;
104 static inline int mlx5e_hash_l2(const u8 *addr)
109 struct dentry *mlx5e_fs_get_debugfs_root(struct mlx5e_flow_steering *fs)
114 static void mlx5e_add_l2_to_hash(struct hlist_head *hash, const u8 *addr)
116 struct mlx5e_l2_hash_node *hn;
117 int ix = mlx5e_hash_l2(addr);
120 hlist_for_each_entry(hn, &hash[ix], hlist)
121 if (ether_addr_equal_64bits(hn->ai.addr, addr)) {
127 hn->action = MLX5E_ACTION_NONE;
131 hn = kzalloc(sizeof(*hn), GFP_ATOMIC);
135 ether_addr_copy(hn->ai.addr, addr);
136 hn->action = MLX5E_ACTION_ADD;
138 hlist_add_head(&hn->hlist, &hash[ix]);
141 static void mlx5e_del_l2_from_hash(struct mlx5e_l2_hash_node *hn)
143 hlist_del(&hn->hlist);
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;
160 unsigned long *mlx5e_vlan_get_active_svlans(struct mlx5e_vlan_table *vlan)
162 return vlan->active_svlans;
165 struct mlx5_flow_table *mlx5e_vlan_get_flowtable(struct mlx5e_vlan_table *vlan)
170 static int mlx5e_vport_context_update_vlans(struct mlx5e_flow_steering *fs)
180 for_each_set_bit(vlan, fs->vlan->active_cvlans, VLAN_N_VID)
183 max_list_size = 1 << MLX5_CAP_GEN(fs->mdev, log_max_vlan_list);
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;
191 vlans = kvcalloc(list_size, sizeof(*vlans), GFP_KERNEL);
196 for_each_set_bit(vlan, fs->vlan->active_cvlans, VLAN_N_VID) {
202 err = mlx5_modify_nic_vport_vlans(fs->mdev, vlans, list_size);
204 fs_err(fs, "Failed to modify vport vlans list err(%d)\n",
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,
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)
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);
229 dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
230 dest.ft = fs->l2.ft.t;
232 spec->match_criteria_enable = MLX5_MATCH_OUTER_HEADERS;
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)
240 rule_p = &fs->vlan->untagged_rule;
241 MLX5_SET_TO_ONES(fte_match_param, spec->match_criteria,
242 outer_headers.cvlan_tag);
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);
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);
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,
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,
278 if (WARN_ONCE(*rule_p, "VLAN rule already exists type %d", rule_type))
281 *rule_p = mlx5_add_flow_rules(ft, spec, &flow_act, &dest, 1);
283 if (IS_ERR(*rule_p)) {
284 err = PTR_ERR(*rule_p);
286 fs_err(fs, "add rule failed\n");
292 static int mlx5e_add_vlan_rule(struct mlx5e_flow_steering *fs,
293 enum mlx5e_vlan_rule_type rule_type, u16 vid)
295 struct mlx5_flow_spec *spec;
298 spec = kvzalloc(sizeof(*spec), GFP_KERNEL);
302 if (rule_type == MLX5E_VLAN_RULE_TYPE_MATCH_CTAG_VID)
303 mlx5e_vport_context_update_vlans(fs);
305 err = __mlx5e_add_vlan_rule(fs, rule_type, vid, spec);
312 static void mlx5e_fs_del_vlan_rule(struct mlx5e_flow_steering *fs,
313 enum mlx5e_vlan_rule_type rule_type, u16 vid)
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;
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;
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;
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;
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;
345 mlx5e_vport_context_update_vlans(fs);
350 static void mlx5e_fs_del_any_vid_rules(struct mlx5e_flow_steering *fs)
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);
356 static int mlx5e_fs_add_any_vid_rules(struct mlx5e_flow_steering *fs)
360 err = mlx5e_add_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_ANY_CTAG_VID, 0);
364 return mlx5e_add_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_ANY_STAG_VID, 0);
367 static struct mlx5_flow_handle *
368 mlx5e_add_trap_rule(struct mlx5_flow_table *ft, int trap_id, int tir_num)
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;
375 spec = kvzalloc(sizeof(*spec), GFP_KERNEL);
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;
383 rule = mlx5_add_flow_rules(ft, spec, &flow_act, &dest, 1);
388 int mlx5e_add_vlan_trap(struct mlx5e_flow_steering *fs, int trap_id, int tir_num)
390 struct mlx5_flow_table *ft = fs->vlan->ft.t;
391 struct mlx5_flow_handle *rule;
394 rule = mlx5e_add_trap_rule(ft, trap_id, tir_num);
397 fs->vlan->trap_rule = NULL;
398 fs_err(fs, "add VLAN trap rule failed, err %d\n", err);
401 fs->vlan->trap_rule = rule;
405 void mlx5e_remove_vlan_trap(struct mlx5e_flow_steering *fs)
407 if (fs->vlan->trap_rule) {
408 mlx5_del_flow_rules(fs->vlan->trap_rule);
409 fs->vlan->trap_rule = NULL;
413 int mlx5e_add_mac_trap(struct mlx5e_flow_steering *fs, int trap_id, int tir_num)
415 struct mlx5_flow_table *ft = fs->l2.ft.t;
416 struct mlx5_flow_handle *rule;
419 rule = mlx5e_add_trap_rule(ft, trap_id, tir_num);
422 fs->l2.trap_rule = NULL;
423 fs_err(fs, "add MAC trap rule failed, err %d\n", err);
426 fs->l2.trap_rule = rule;
430 void mlx5e_remove_mac_trap(struct mlx5e_flow_steering *fs)
432 if (fs->l2.trap_rule) {
433 mlx5_del_flow_rules(fs->l2.trap_rule);
434 fs->l2.trap_rule = NULL;
438 void mlx5e_enable_cvlan_filter(struct mlx5e_flow_steering *fs, bool promisc)
440 if (!fs->vlan->cvlan_filter_disabled)
443 fs->vlan->cvlan_filter_disabled = false;
446 mlx5e_fs_del_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_ANY_CTAG_VID, 0);
449 void mlx5e_disable_cvlan_filter(struct mlx5e_flow_steering *fs, bool promisc)
451 if (!fs->vlan || fs->vlan->cvlan_filter_disabled)
454 fs->vlan->cvlan_filter_disabled = true;
457 mlx5e_add_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_ANY_CTAG_VID, 0);
460 static int mlx5e_vlan_rx_add_cvid(struct mlx5e_flow_steering *fs, u16 vid)
464 set_bit(vid, fs->vlan->active_cvlans);
466 err = mlx5e_add_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_MATCH_CTAG_VID, vid);
468 clear_bit(vid, fs->vlan->active_cvlans);
473 static int mlx5e_vlan_rx_add_svid(struct mlx5e_flow_steering *fs,
474 struct net_device *netdev, u16 vid)
478 set_bit(vid, fs->vlan->active_svlans);
480 err = mlx5e_add_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_MATCH_STAG_VID, vid);
482 clear_bit(vid, fs->vlan->active_svlans);
486 /* Need to fix some features.. */
487 netdev_update_features(netdev);
491 int mlx5e_fs_vlan_rx_add_vid(struct mlx5e_flow_steering *fs,
492 struct net_device *netdev,
493 __be16 proto, u16 vid)
497 fs_err(fs, "Vlan doesn't exist\n");
501 if (be16_to_cpu(proto) == ETH_P_8021Q)
502 return mlx5e_vlan_rx_add_cvid(fs, vid);
503 else if (be16_to_cpu(proto) == ETH_P_8021AD)
504 return mlx5e_vlan_rx_add_svid(fs, netdev, vid);
509 int mlx5e_fs_vlan_rx_kill_vid(struct mlx5e_flow_steering *fs,
510 struct net_device *netdev,
511 __be16 proto, u16 vid)
514 fs_err(fs, "Vlan doesn't exist\n");
518 if (be16_to_cpu(proto) == ETH_P_8021Q) {
519 clear_bit(vid, fs->vlan->active_cvlans);
520 mlx5e_fs_del_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_MATCH_CTAG_VID, vid);
521 } else if (be16_to_cpu(proto) == ETH_P_8021AD) {
522 clear_bit(vid, fs->vlan->active_svlans);
523 mlx5e_fs_del_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_MATCH_STAG_VID, vid);
524 netdev_update_features(netdev);
530 static void mlx5e_fs_add_vlan_rules(struct mlx5e_flow_steering *fs)
534 mlx5e_add_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_UNTAGGED, 0);
536 for_each_set_bit(i, fs->vlan->active_cvlans, VLAN_N_VID) {
537 mlx5e_add_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_MATCH_CTAG_VID, i);
540 for_each_set_bit(i, fs->vlan->active_svlans, VLAN_N_VID)
541 mlx5e_add_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_MATCH_STAG_VID, i);
543 if (fs->vlan->cvlan_filter_disabled)
544 mlx5e_fs_add_any_vid_rules(fs);
547 static void mlx5e_del_vlan_rules(struct mlx5e_flow_steering *fs)
551 mlx5e_fs_del_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_UNTAGGED, 0);
553 for_each_set_bit(i, fs->vlan->active_cvlans, VLAN_N_VID) {
554 mlx5e_fs_del_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_MATCH_CTAG_VID, i);
557 for_each_set_bit(i, fs->vlan->active_svlans, VLAN_N_VID)
558 mlx5e_fs_del_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_MATCH_STAG_VID, i);
560 WARN_ON_ONCE(fs->state_destroy);
562 mlx5e_remove_vlan_trap(fs);
564 /* must be called after DESTROY bit is set and
565 * set_rx_mode is called and flushed
567 if (fs->vlan->cvlan_filter_disabled)
568 mlx5e_fs_del_any_vid_rules(fs);
571 #define mlx5e_for_each_hash_node(hn, tmp, hash, i) \
572 for (i = 0; i < MLX5E_L2_ADDR_HASH_SIZE; i++) \
573 hlist_for_each_entry_safe(hn, tmp, &hash[i], hlist)
575 static void mlx5e_execute_l2_action(struct mlx5e_flow_steering *fs,
576 struct mlx5e_l2_hash_node *hn)
578 u8 action = hn->action;
579 u8 mac_addr[ETH_ALEN];
582 ether_addr_copy(mac_addr, hn->ai.addr);
585 case MLX5E_ACTION_ADD:
586 mlx5e_add_l2_flow_rule(fs, &hn->ai, MLX5E_FULLMATCH);
587 if (!is_multicast_ether_addr(mac_addr)) {
588 l2_err = mlx5_mpfs_add_mac(fs->mdev, mac_addr);
591 hn->action = MLX5E_ACTION_NONE;
594 case MLX5E_ACTION_DEL:
595 if (!is_multicast_ether_addr(mac_addr) && hn->mpfs)
596 l2_err = mlx5_mpfs_del_mac(fs->mdev, mac_addr);
597 mlx5e_del_l2_flow_rule(fs, &hn->ai);
598 mlx5e_del_l2_from_hash(hn);
603 fs_warn(fs, "MPFS, failed to %s mac %pM, err(%d)\n",
604 action == MLX5E_ACTION_ADD ? "add" : "del",
608 static void mlx5e_sync_netdev_addr(struct mlx5e_flow_steering *fs,
609 struct net_device *netdev)
611 struct netdev_hw_addr *ha;
613 netif_addr_lock_bh(netdev);
615 mlx5e_add_l2_to_hash(fs->l2.netdev_uc, netdev->dev_addr);
616 netdev_for_each_uc_addr(ha, netdev)
617 mlx5e_add_l2_to_hash(fs->l2.netdev_uc, ha->addr);
619 netdev_for_each_mc_addr(ha, netdev)
620 mlx5e_add_l2_to_hash(fs->l2.netdev_mc, ha->addr);
622 netif_addr_unlock_bh(netdev);
625 static void mlx5e_fill_addr_array(struct mlx5e_flow_steering *fs, int list_type,
626 struct net_device *ndev,
627 u8 addr_array[][ETH_ALEN], int size)
629 bool is_uc = (list_type == MLX5_NVPRT_LIST_TYPE_UC);
630 struct mlx5e_l2_hash_node *hn;
631 struct hlist_head *addr_list;
632 struct hlist_node *tmp;
636 addr_list = is_uc ? fs->l2.netdev_uc : fs->l2.netdev_mc;
638 if (is_uc) /* Make sure our own address is pushed first */
639 ether_addr_copy(addr_array[i++], ndev->dev_addr);
640 else if (fs->l2.broadcast_enabled)
641 ether_addr_copy(addr_array[i++], ndev->broadcast);
643 mlx5e_for_each_hash_node(hn, tmp, addr_list, hi) {
644 if (ether_addr_equal(ndev->dev_addr, hn->ai.addr))
648 ether_addr_copy(addr_array[i++], hn->ai.addr);
652 static void mlx5e_vport_context_update_addr_list(struct mlx5e_flow_steering *fs,
653 struct net_device *netdev,
656 bool is_uc = (list_type == MLX5_NVPRT_LIST_TYPE_UC);
657 struct mlx5e_l2_hash_node *hn;
658 u8 (*addr_array)[ETH_ALEN] = NULL;
659 struct hlist_head *addr_list;
660 struct hlist_node *tmp;
666 size = is_uc ? 0 : (fs->l2.broadcast_enabled ? 1 : 0);
668 1 << MLX5_CAP_GEN(fs->mdev, log_max_current_uc_list) :
669 1 << MLX5_CAP_GEN(fs->mdev, log_max_current_mc_list);
671 addr_list = is_uc ? fs->l2.netdev_uc : fs->l2.netdev_mc;
672 mlx5e_for_each_hash_node(hn, tmp, addr_list, hi)
675 if (size > max_size) {
676 fs_warn(fs, "mdev %s list size (%d) > (%d) max vport list size, some addresses will be dropped\n",
677 is_uc ? "UC" : "MC", size, max_size);
682 addr_array = kcalloc(size, ETH_ALEN, GFP_KERNEL);
687 mlx5e_fill_addr_array(fs, list_type, netdev, addr_array, size);
690 err = mlx5_modify_nic_vport_mac_list(fs->mdev, list_type, addr_array, size);
693 fs_err(fs, "Failed to modify vport %s list err(%d)\n",
694 is_uc ? "UC" : "MC", err);
698 static void mlx5e_vport_context_update(struct mlx5e_flow_steering *fs,
699 struct net_device *netdev)
701 struct mlx5e_l2_table *ea = &fs->l2;
703 mlx5e_vport_context_update_addr_list(fs, netdev, MLX5_NVPRT_LIST_TYPE_UC);
704 mlx5e_vport_context_update_addr_list(fs, netdev, MLX5_NVPRT_LIST_TYPE_MC);
705 mlx5_modify_nic_vport_promisc(fs->mdev, 0,
706 ea->allmulti_enabled,
707 ea->promisc_enabled);
710 static void mlx5e_apply_netdev_addr(struct mlx5e_flow_steering *fs)
712 struct mlx5e_l2_hash_node *hn;
713 struct hlist_node *tmp;
716 mlx5e_for_each_hash_node(hn, tmp, fs->l2.netdev_uc, i)
717 mlx5e_execute_l2_action(fs, hn);
719 mlx5e_for_each_hash_node(hn, tmp, fs->l2.netdev_mc, i)
720 mlx5e_execute_l2_action(fs, hn);
723 static void mlx5e_handle_netdev_addr(struct mlx5e_flow_steering *fs,
724 struct net_device *netdev)
726 struct mlx5e_l2_hash_node *hn;
727 struct hlist_node *tmp;
730 mlx5e_for_each_hash_node(hn, tmp, fs->l2.netdev_uc, i)
731 hn->action = MLX5E_ACTION_DEL;
732 mlx5e_for_each_hash_node(hn, tmp, fs->l2.netdev_mc, i)
733 hn->action = MLX5E_ACTION_DEL;
735 if (fs->state_destroy)
736 mlx5e_sync_netdev_addr(fs, netdev);
738 mlx5e_apply_netdev_addr(fs);
741 #define MLX5E_PROMISC_GROUP0_SIZE BIT(0)
742 #define MLX5E_PROMISC_TABLE_SIZE MLX5E_PROMISC_GROUP0_SIZE
744 static int mlx5e_add_promisc_rule(struct mlx5e_flow_steering *fs)
746 struct mlx5_flow_table *ft = fs->promisc.ft.t;
747 struct mlx5_flow_destination dest = {};
748 struct mlx5_flow_handle **rule_p;
749 MLX5_DECLARE_FLOW_ACT(flow_act);
750 struct mlx5_flow_spec *spec;
753 spec = kvzalloc(sizeof(*spec), GFP_KERNEL);
756 dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
757 dest.ft = mlx5_get_ttc_flow_table(fs->ttc);
759 rule_p = &fs->promisc.rule;
760 *rule_p = mlx5_add_flow_rules(ft, spec, &flow_act, &dest, 1);
761 if (IS_ERR(*rule_p)) {
762 err = PTR_ERR(*rule_p);
764 fs_err(fs, "add promiscuous rule failed\n");
770 static int mlx5e_create_promisc_table(struct mlx5e_flow_steering *fs)
772 struct mlx5e_flow_table *ft = &fs->promisc.ft;
773 struct mlx5_flow_table_attr ft_attr = {};
776 ft_attr.max_fte = MLX5E_PROMISC_TABLE_SIZE;
777 ft_attr.autogroup.max_num_groups = 1;
778 ft_attr.level = MLX5E_PROMISC_FT_LEVEL;
779 ft_attr.prio = MLX5E_NIC_PRIO;
781 ft->t = mlx5_create_auto_grouped_flow_table(fs->ns, &ft_attr);
783 err = PTR_ERR(ft->t);
785 fs_err(fs, "fail to create promisc table err=%d\n", err);
789 err = mlx5e_add_promisc_rule(fs);
791 goto err_destroy_promisc_table;
795 err_destroy_promisc_table:
796 mlx5_destroy_flow_table(ft->t);
802 static void mlx5e_del_promisc_rule(struct mlx5e_flow_steering *fs)
804 if (WARN(!fs->promisc.rule, "Trying to remove non-existing promiscuous rule"))
806 mlx5_del_flow_rules(fs->promisc.rule);
807 fs->promisc.rule = NULL;
810 static void mlx5e_destroy_promisc_table(struct mlx5e_flow_steering *fs)
812 if (!fs->promisc.ft.t)
814 mlx5e_del_promisc_rule(fs);
815 mlx5_destroy_flow_table(fs->promisc.ft.t);
816 fs->promisc.ft.t = NULL;
819 void mlx5e_fs_set_rx_mode_work(struct mlx5e_flow_steering *fs,
820 struct net_device *netdev)
822 struct mlx5e_l2_table *ea = &fs->l2;
824 bool rx_mode_enable = fs->state_destroy;
825 bool promisc_enabled = rx_mode_enable && (netdev->flags & IFF_PROMISC);
826 bool allmulti_enabled = rx_mode_enable && (netdev->flags & IFF_ALLMULTI);
827 bool broadcast_enabled = rx_mode_enable;
829 bool enable_promisc = !ea->promisc_enabled && promisc_enabled;
830 bool disable_promisc = ea->promisc_enabled && !promisc_enabled;
831 bool enable_allmulti = !ea->allmulti_enabled && allmulti_enabled;
832 bool disable_allmulti = ea->allmulti_enabled && !allmulti_enabled;
833 bool enable_broadcast = !ea->broadcast_enabled && broadcast_enabled;
834 bool disable_broadcast = ea->broadcast_enabled && !broadcast_enabled;
837 if (enable_promisc) {
838 err = mlx5e_create_promisc_table(fs);
840 enable_promisc = false;
841 if (!fs->vlan_strip_disable && !err)
843 "S-tagged traffic will be dropped while C-tag vlan stripping is enabled\n");
846 mlx5e_add_l2_flow_rule(fs, &ea->allmulti, MLX5E_ALLMULTI);
847 if (enable_broadcast)
848 mlx5e_add_l2_flow_rule(fs, &ea->broadcast, MLX5E_FULLMATCH);
850 mlx5e_handle_netdev_addr(fs, netdev);
852 if (disable_broadcast)
853 mlx5e_del_l2_flow_rule(fs, &ea->broadcast);
854 if (disable_allmulti)
855 mlx5e_del_l2_flow_rule(fs, &ea->allmulti);
857 mlx5e_destroy_promisc_table(fs);
859 ea->promisc_enabled = promisc_enabled;
860 ea->allmulti_enabled = allmulti_enabled;
861 ea->broadcast_enabled = broadcast_enabled;
863 mlx5e_vport_context_update(fs, netdev);
866 static void mlx5e_destroy_groups(struct mlx5e_flow_table *ft)
870 for (i = ft->num_groups - 1; i >= 0; i--) {
871 if (!IS_ERR_OR_NULL(ft->g[i]))
872 mlx5_destroy_flow_group(ft->g[i]);
878 void mlx5e_fs_init_l2_addr(struct mlx5e_flow_steering *fs, struct net_device *netdev)
880 ether_addr_copy(fs->l2.broadcast.addr, netdev->broadcast);
883 void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft)
885 mlx5e_destroy_groups(ft);
887 mlx5_destroy_flow_table(ft->t);
891 static void mlx5e_set_inner_ttc_params(struct mlx5e_flow_steering *fs,
892 struct mlx5e_rx_res *rx_res,
893 struct ttc_params *ttc_params)
895 struct mlx5_flow_table_attr *ft_attr = &ttc_params->ft_attr;
898 memset(ttc_params, 0, sizeof(*ttc_params));
899 ttc_params->ns_type = MLX5_FLOW_NAMESPACE_KERNEL;
900 ft_attr->level = MLX5E_INNER_TTC_FT_LEVEL;
901 ft_attr->prio = MLX5E_NIC_PRIO;
903 for (tt = 0; tt < MLX5_NUM_TT; tt++) {
904 ttc_params->dests[tt].type = MLX5_FLOW_DESTINATION_TYPE_TIR;
905 ttc_params->dests[tt].tir_num =
907 mlx5e_rx_res_get_tirn_direct(rx_res, 0) :
908 mlx5e_rx_res_get_tirn_rss_inner(rx_res,
913 void mlx5e_set_ttc_params(struct mlx5e_flow_steering *fs,
914 struct mlx5e_rx_res *rx_res,
915 struct ttc_params *ttc_params, bool tunnel)
918 struct mlx5_flow_table_attr *ft_attr = &ttc_params->ft_attr;
921 memset(ttc_params, 0, sizeof(*ttc_params));
922 ttc_params->ns_type = MLX5_FLOW_NAMESPACE_KERNEL;
923 ft_attr->level = MLX5E_TTC_FT_LEVEL;
924 ft_attr->prio = MLX5E_NIC_PRIO;
926 for (tt = 0; tt < MLX5_NUM_TT; tt++) {
927 ttc_params->dests[tt].type = MLX5_FLOW_DESTINATION_TYPE_TIR;
928 ttc_params->dests[tt].tir_num =
930 mlx5e_rx_res_get_tirn_direct(rx_res, 0) :
931 mlx5e_rx_res_get_tirn_rss(rx_res, tt);
934 ttc_params->inner_ttc = tunnel;
935 if (!tunnel || !mlx5_tunnel_inner_ft_supported(fs->mdev))
938 for (tt = 0; tt < MLX5_NUM_TUNNEL_TT; tt++) {
939 ttc_params->tunnel_dests[tt].type =
940 MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
941 ttc_params->tunnel_dests[tt].ft =
942 mlx5_get_ttc_flow_table(fs->inner_ttc);
946 static void mlx5e_del_l2_flow_rule(struct mlx5e_flow_steering *fs,
947 struct mlx5e_l2_rule *ai)
949 if (!IS_ERR_OR_NULL(ai->rule)) {
950 mlx5_del_flow_rules(ai->rule);
955 static int mlx5e_add_l2_flow_rule(struct mlx5e_flow_steering *fs,
956 struct mlx5e_l2_rule *ai, int type)
958 struct mlx5_flow_table *ft = fs->l2.ft.t;
959 struct mlx5_flow_destination dest = {};
960 MLX5_DECLARE_FLOW_ACT(flow_act);
961 struct mlx5_flow_spec *spec;
966 spec = kvzalloc(sizeof(*spec), GFP_KERNEL);
970 mc_dmac = MLX5_ADDR_OF(fte_match_param, spec->match_criteria,
971 outer_headers.dmac_47_16);
972 mv_dmac = MLX5_ADDR_OF(fte_match_param, spec->match_value,
973 outer_headers.dmac_47_16);
975 dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
976 dest.ft = mlx5_get_ttc_flow_table(fs->ttc);
979 case MLX5E_FULLMATCH:
980 spec->match_criteria_enable = MLX5_MATCH_OUTER_HEADERS;
981 eth_broadcast_addr(mc_dmac);
982 ether_addr_copy(mv_dmac, ai->addr);
986 spec->match_criteria_enable = MLX5_MATCH_OUTER_HEADERS;
992 ai->rule = mlx5_add_flow_rules(ft, spec, &flow_act, &dest, 1);
993 if (IS_ERR(ai->rule)) {
994 fs_err(fs, "add l2 rule(mac:%pM) failed\n", mv_dmac);
995 err = PTR_ERR(ai->rule);
1004 #define MLX5E_NUM_L2_GROUPS 3
1005 #define MLX5E_L2_GROUP1_SIZE BIT(15)
1006 #define MLX5E_L2_GROUP2_SIZE BIT(0)
1007 #define MLX5E_L2_GROUP_TRAP_SIZE BIT(0) /* must be last */
1008 #define MLX5E_L2_TABLE_SIZE (MLX5E_L2_GROUP1_SIZE +\
1009 MLX5E_L2_GROUP2_SIZE +\
1010 MLX5E_L2_GROUP_TRAP_SIZE)
1011 static int mlx5e_create_l2_table_groups(struct mlx5e_l2_table *l2_table)
1013 int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
1014 struct mlx5e_flow_table *ft = &l2_table->ft;
1021 ft->g = kcalloc(MLX5E_NUM_L2_GROUPS, sizeof(*ft->g), GFP_KERNEL);
1024 in = kvzalloc(inlen, GFP_KERNEL);
1030 mc = MLX5_ADDR_OF(create_flow_group_in, in, match_criteria);
1031 mc_dmac = MLX5_ADDR_OF(fte_match_param, mc,
1032 outer_headers.dmac_47_16);
1033 /* Flow Group for full match */
1034 eth_broadcast_addr(mc_dmac);
1035 MLX5_SET_CFG(in, match_criteria_enable, MLX5_MATCH_OUTER_HEADERS);
1036 MLX5_SET_CFG(in, start_flow_index, ix);
1037 ix += MLX5E_L2_GROUP1_SIZE;
1038 MLX5_SET_CFG(in, end_flow_index, ix - 1);
1039 ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
1040 if (IS_ERR(ft->g[ft->num_groups]))
1041 goto err_destroy_groups;
1044 /* Flow Group for allmulti */
1045 eth_zero_addr(mc_dmac);
1047 MLX5_SET_CFG(in, start_flow_index, ix);
1048 ix += MLX5E_L2_GROUP2_SIZE;
1049 MLX5_SET_CFG(in, end_flow_index, ix - 1);
1050 ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
1051 if (IS_ERR(ft->g[ft->num_groups]))
1052 goto err_destroy_groups;
1055 /* Flow Group for l2 traps */
1056 memset(in, 0, inlen);
1057 MLX5_SET_CFG(in, start_flow_index, ix);
1058 ix += MLX5E_L2_GROUP_TRAP_SIZE;
1059 MLX5_SET_CFG(in, end_flow_index, ix - 1);
1060 ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
1061 if (IS_ERR(ft->g[ft->num_groups]))
1062 goto err_destroy_groups;
1069 err = PTR_ERR(ft->g[ft->num_groups]);
1070 ft->g[ft->num_groups] = NULL;
1071 mlx5e_destroy_groups(ft);
1078 static void mlx5e_destroy_l2_table(struct mlx5e_flow_steering *fs)
1080 mlx5e_destroy_flow_table(&fs->l2.ft);
1083 static int mlx5e_create_l2_table(struct mlx5e_flow_steering *fs)
1085 struct mlx5e_l2_table *l2_table = &fs->l2;
1086 struct mlx5e_flow_table *ft = &l2_table->ft;
1087 struct mlx5_flow_table_attr ft_attr = {};
1092 ft_attr.max_fte = MLX5E_L2_TABLE_SIZE;
1093 ft_attr.level = MLX5E_L2_FT_LEVEL;
1094 ft_attr.prio = MLX5E_NIC_PRIO;
1096 ft->t = mlx5_create_flow_table(fs->ns, &ft_attr);
1097 if (IS_ERR(ft->t)) {
1098 err = PTR_ERR(ft->t);
1103 err = mlx5e_create_l2_table_groups(l2_table);
1105 goto err_destroy_flow_table;
1109 err_destroy_flow_table:
1110 mlx5_destroy_flow_table(ft->t);
1116 #define MLX5E_NUM_VLAN_GROUPS 5
1117 #define MLX5E_VLAN_GROUP0_SIZE BIT(12)
1118 #define MLX5E_VLAN_GROUP1_SIZE BIT(12)
1119 #define MLX5E_VLAN_GROUP2_SIZE BIT(1)
1120 #define MLX5E_VLAN_GROUP3_SIZE BIT(0)
1121 #define MLX5E_VLAN_GROUP_TRAP_SIZE BIT(0) /* must be last */
1122 #define MLX5E_VLAN_TABLE_SIZE (MLX5E_VLAN_GROUP0_SIZE +\
1123 MLX5E_VLAN_GROUP1_SIZE +\
1124 MLX5E_VLAN_GROUP2_SIZE +\
1125 MLX5E_VLAN_GROUP3_SIZE +\
1126 MLX5E_VLAN_GROUP_TRAP_SIZE)
1128 static int __mlx5e_create_vlan_table_groups(struct mlx5e_flow_table *ft, u32 *in,
1133 u8 *mc = MLX5_ADDR_OF(create_flow_group_in, in, match_criteria);
1135 memset(in, 0, inlen);
1136 MLX5_SET_CFG(in, match_criteria_enable, MLX5_MATCH_OUTER_HEADERS);
1137 MLX5_SET_TO_ONES(fte_match_param, mc, outer_headers.cvlan_tag);
1138 MLX5_SET_TO_ONES(fte_match_param, mc, outer_headers.first_vid);
1139 MLX5_SET_CFG(in, start_flow_index, ix);
1140 ix += MLX5E_VLAN_GROUP0_SIZE;
1141 MLX5_SET_CFG(in, end_flow_index, ix - 1);
1142 ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
1143 if (IS_ERR(ft->g[ft->num_groups]))
1144 goto err_destroy_groups;
1147 memset(in, 0, inlen);
1148 MLX5_SET_CFG(in, match_criteria_enable, MLX5_MATCH_OUTER_HEADERS);
1149 MLX5_SET_TO_ONES(fte_match_param, mc, outer_headers.svlan_tag);
1150 MLX5_SET_TO_ONES(fte_match_param, mc, outer_headers.first_vid);
1151 MLX5_SET_CFG(in, start_flow_index, ix);
1152 ix += MLX5E_VLAN_GROUP1_SIZE;
1153 MLX5_SET_CFG(in, end_flow_index, ix - 1);
1154 ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
1155 if (IS_ERR(ft->g[ft->num_groups]))
1156 goto err_destroy_groups;
1159 memset(in, 0, inlen);
1160 MLX5_SET_CFG(in, match_criteria_enable, MLX5_MATCH_OUTER_HEADERS);
1161 MLX5_SET_TO_ONES(fte_match_param, mc, outer_headers.cvlan_tag);
1162 MLX5_SET_CFG(in, start_flow_index, ix);
1163 ix += MLX5E_VLAN_GROUP2_SIZE;
1164 MLX5_SET_CFG(in, end_flow_index, ix - 1);
1165 ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
1166 if (IS_ERR(ft->g[ft->num_groups]))
1167 goto err_destroy_groups;
1170 memset(in, 0, inlen);
1171 MLX5_SET_CFG(in, match_criteria_enable, MLX5_MATCH_OUTER_HEADERS);
1172 MLX5_SET_TO_ONES(fte_match_param, mc, outer_headers.svlan_tag);
1173 MLX5_SET_CFG(in, start_flow_index, ix);
1174 ix += MLX5E_VLAN_GROUP3_SIZE;
1175 MLX5_SET_CFG(in, end_flow_index, ix - 1);
1176 ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
1177 if (IS_ERR(ft->g[ft->num_groups]))
1178 goto err_destroy_groups;
1181 memset(in, 0, inlen);
1182 MLX5_SET_CFG(in, start_flow_index, ix);
1183 ix += MLX5E_VLAN_GROUP_TRAP_SIZE;
1184 MLX5_SET_CFG(in, end_flow_index, ix - 1);
1185 ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
1186 if (IS_ERR(ft->g[ft->num_groups]))
1187 goto err_destroy_groups;
1193 err = PTR_ERR(ft->g[ft->num_groups]);
1194 ft->g[ft->num_groups] = NULL;
1195 mlx5e_destroy_groups(ft);
1200 static int mlx5e_create_vlan_table_groups(struct mlx5e_flow_table *ft)
1203 int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
1206 in = kvzalloc(inlen, GFP_KERNEL);
1210 err = __mlx5e_create_vlan_table_groups(ft, in, inlen);
1216 static int mlx5e_fs_create_vlan_table(struct mlx5e_flow_steering *fs)
1218 struct mlx5_flow_table_attr ft_attr = {};
1219 struct mlx5e_flow_table *ft;
1225 ft_attr.max_fte = MLX5E_VLAN_TABLE_SIZE;
1226 ft_attr.level = MLX5E_VLAN_FT_LEVEL;
1227 ft_attr.prio = MLX5E_NIC_PRIO;
1229 ft->t = mlx5_create_flow_table(fs->ns, &ft_attr);
1231 return PTR_ERR(ft->t);
1233 ft->g = kcalloc(MLX5E_NUM_VLAN_GROUPS, sizeof(*ft->g), GFP_KERNEL);
1236 goto err_destroy_vlan_table;
1239 err = mlx5e_create_vlan_table_groups(ft);
1243 mlx5e_fs_add_vlan_rules(fs);
1249 err_destroy_vlan_table:
1250 mlx5_destroy_flow_table(ft->t);
1255 static void mlx5e_destroy_vlan_table(struct mlx5e_flow_steering *fs)
1257 mlx5e_del_vlan_rules(fs);
1258 mlx5e_destroy_flow_table(&fs->vlan->ft);
1261 static void mlx5e_destroy_inner_ttc_table(struct mlx5e_flow_steering *fs)
1263 if (!mlx5_tunnel_inner_ft_supported(fs->mdev))
1265 mlx5_destroy_ttc_table(fs->inner_ttc);
1268 void mlx5e_destroy_ttc_table(struct mlx5e_flow_steering *fs)
1270 mlx5_destroy_ttc_table(fs->ttc);
1273 static int mlx5e_create_inner_ttc_table(struct mlx5e_flow_steering *fs,
1274 struct mlx5e_rx_res *rx_res)
1276 struct ttc_params ttc_params = {};
1278 if (!mlx5_tunnel_inner_ft_supported(fs->mdev))
1281 mlx5e_set_inner_ttc_params(fs, rx_res, &ttc_params);
1282 fs->inner_ttc = mlx5_create_inner_ttc_table(fs->mdev,
1284 return PTR_ERR_OR_ZERO(fs->inner_ttc);
1287 int mlx5e_create_ttc_table(struct mlx5e_flow_steering *fs,
1288 struct mlx5e_rx_res *rx_res)
1290 struct ttc_params ttc_params = {};
1292 mlx5e_set_ttc_params(fs, rx_res, &ttc_params, true);
1293 fs->ttc = mlx5_create_ttc_table(fs->mdev, &ttc_params);
1294 return PTR_ERR_OR_ZERO(fs->ttc);
1297 int mlx5e_create_flow_steering(struct mlx5e_flow_steering *fs,
1298 struct mlx5e_rx_res *rx_res,
1299 const struct mlx5e_profile *profile,
1300 struct net_device *netdev)
1302 struct mlx5_flow_namespace *ns = mlx5_get_flow_namespace(fs->mdev,
1303 MLX5_FLOW_NAMESPACE_KERNEL);
1309 mlx5e_fs_set_ns(fs, ns, false);
1310 err = mlx5e_arfs_create_tables(fs, rx_res, mlx5e_fs_has_arfs(netdev));
1312 fs_err(fs, "Failed to create arfs tables, err=%d\n", err);
1313 netdev->hw_features &= ~NETIF_F_NTUPLE;
1316 err = mlx5e_create_inner_ttc_table(fs, rx_res);
1318 fs_err(fs, "Failed to create inner ttc table, err=%d\n", err);
1319 goto err_destroy_arfs_tables;
1322 err = mlx5e_create_ttc_table(fs, rx_res);
1324 fs_err(fs, "Failed to create ttc table, err=%d\n", err);
1325 goto err_destroy_inner_ttc_table;
1328 err = mlx5e_create_l2_table(fs);
1330 fs_err(fs, "Failed to create l2 table, err=%d\n", err);
1331 goto err_destroy_ttc_table;
1334 err = mlx5e_fs_create_vlan_table(fs);
1336 fs_err(fs, "Failed to create vlan table, err=%d\n", err);
1337 goto err_destroy_l2_table;
1340 err = mlx5e_ptp_alloc_rx_fs(fs, profile);
1342 goto err_destory_vlan_table;
1344 mlx5e_ethtool_init_steering(fs);
1348 err_destory_vlan_table:
1349 mlx5e_destroy_vlan_table(fs);
1350 err_destroy_l2_table:
1351 mlx5e_destroy_l2_table(fs);
1352 err_destroy_ttc_table:
1353 mlx5e_destroy_ttc_table(fs);
1354 err_destroy_inner_ttc_table:
1355 mlx5e_destroy_inner_ttc_table(fs);
1356 err_destroy_arfs_tables:
1357 mlx5e_arfs_destroy_tables(fs, mlx5e_fs_has_arfs(netdev));
1362 void mlx5e_destroy_flow_steering(struct mlx5e_flow_steering *fs, bool ntuple,
1363 const struct mlx5e_profile *profile)
1365 mlx5e_ptp_free_rx_fs(fs, profile);
1366 mlx5e_destroy_vlan_table(fs);
1367 mlx5e_destroy_l2_table(fs);
1368 mlx5e_destroy_ttc_table(fs);
1369 mlx5e_destroy_inner_ttc_table(fs);
1370 mlx5e_arfs_destroy_tables(fs, ntuple);
1371 mlx5e_ethtool_cleanup_steering(fs);
1374 static int mlx5e_fs_vlan_alloc(struct mlx5e_flow_steering *fs)
1376 fs->vlan = kvzalloc(sizeof(*fs->vlan), GFP_KERNEL);
1382 static void mlx5e_fs_vlan_free(struct mlx5e_flow_steering *fs)
1387 struct mlx5e_vlan_table *mlx5e_fs_get_vlan(struct mlx5e_flow_steering *fs)
1392 static int mlx5e_fs_tc_alloc(struct mlx5e_flow_steering *fs)
1394 fs->tc = mlx5e_tc_table_alloc();
1400 static void mlx5e_fs_tc_free(struct mlx5e_flow_steering *fs)
1402 mlx5e_tc_table_free(fs->tc);
1405 struct mlx5e_tc_table *mlx5e_fs_get_tc(struct mlx5e_flow_steering *fs)
1410 #ifdef CONFIG_MLX5_EN_RXNFC
1411 static int mlx5e_fs_ethtool_alloc(struct mlx5e_flow_steering *fs)
1413 return mlx5e_ethtool_alloc(&fs->ethtool);
1416 static void mlx5e_fs_ethtool_free(struct mlx5e_flow_steering *fs)
1418 mlx5e_ethtool_free(fs->ethtool);
1421 struct mlx5e_ethtool_steering *mlx5e_fs_get_ethtool(struct mlx5e_flow_steering *fs)
1426 static int mlx5e_fs_ethtool_alloc(struct mlx5e_flow_steering *fs)
1428 static void mlx5e_fs_ethtool_free(struct mlx5e_flow_steering *fs) { }
1431 static void mlx5e_fs_debugfs_init(struct mlx5e_flow_steering *fs,
1432 struct dentry *dfs_root)
1434 if (IS_ERR_OR_NULL(dfs_root))
1437 fs->dfs_root = debugfs_create_dir("fs", dfs_root);
1440 struct mlx5e_flow_steering *mlx5e_fs_init(const struct mlx5e_profile *profile,
1441 struct mlx5_core_dev *mdev,
1443 struct dentry *dfs_root)
1445 struct mlx5e_flow_steering *fs;
1448 fs = kvzalloc(sizeof(*fs), GFP_KERNEL);
1453 fs->state_destroy = state_destroy;
1454 if (mlx5e_profile_feature_cap(profile, FS_VLAN)) {
1455 err = mlx5e_fs_vlan_alloc(fs);
1460 if (mlx5e_profile_feature_cap(profile, FS_TC)) {
1461 err = mlx5e_fs_tc_alloc(fs);
1466 err = mlx5e_fs_ethtool_alloc(fs);
1470 mlx5e_fs_debugfs_init(fs, dfs_root);
1474 mlx5e_fs_tc_free(fs);
1476 mlx5e_fs_vlan_free(fs);
1483 void mlx5e_fs_cleanup(struct mlx5e_flow_steering *fs)
1487 debugfs_remove_recursive(fs->dfs_root);
1488 mlx5e_fs_ethtool_free(fs);
1489 mlx5e_fs_tc_free(fs);
1490 mlx5e_fs_vlan_free(fs);
1494 struct mlx5e_l2_table *mlx5e_fs_get_l2(struct mlx5e_flow_steering *fs)
1499 struct mlx5_flow_namespace *mlx5e_fs_get_ns(struct mlx5e_flow_steering *fs, bool egress)
1501 return egress ? fs->egress_ns : fs->ns;
1504 void mlx5e_fs_set_ns(struct mlx5e_flow_steering *fs, struct mlx5_flow_namespace *ns, bool egress)
1512 struct mlx5_ttc_table *mlx5e_fs_get_ttc(struct mlx5e_flow_steering *fs, bool inner)
1514 return inner ? fs->inner_ttc : fs->ttc;
1517 void mlx5e_fs_set_ttc(struct mlx5e_flow_steering *fs, struct mlx5_ttc_table *ttc, bool inner)
1522 fs->inner_ttc = ttc;
1525 #ifdef CONFIG_MLX5_EN_ARFS
1526 struct mlx5e_arfs_tables *mlx5e_fs_get_arfs(struct mlx5e_flow_steering *fs)
1531 void mlx5e_fs_set_arfs(struct mlx5e_flow_steering *fs, struct mlx5e_arfs_tables *arfs)
1537 struct mlx5e_ptp_fs *mlx5e_fs_get_ptp(struct mlx5e_flow_steering *fs)
1542 void mlx5e_fs_set_ptp(struct mlx5e_flow_steering *fs, struct mlx5e_ptp_fs *ptp_fs)
1544 fs->ptp_fs = ptp_fs;
1547 struct mlx5e_fs_any *mlx5e_fs_get_any(struct mlx5e_flow_steering *fs)
1552 void mlx5e_fs_set_any(struct mlx5e_flow_steering *fs, struct mlx5e_fs_any *any)
1557 #ifdef CONFIG_MLX5_EN_TLS
1558 struct mlx5e_accel_fs_tcp *mlx5e_fs_get_accel_tcp(struct mlx5e_flow_steering *fs)
1560 return fs->accel_tcp;
1563 void mlx5e_fs_set_accel_tcp(struct mlx5e_flow_steering *fs, struct mlx5e_accel_fs_tcp *accel_tcp)
1565 fs->accel_tcp = accel_tcp;
1569 void mlx5e_fs_set_state_destroy(struct mlx5e_flow_steering *fs, bool state_destroy)
1571 fs->state_destroy = state_destroy;
1574 void mlx5e_fs_set_vlan_strip_disable(struct mlx5e_flow_steering *fs,
1575 bool vlan_strip_disable)
1577 fs->vlan_strip_disable = vlan_strip_disable;
1580 struct mlx5e_fs_udp *mlx5e_fs_get_udp(struct mlx5e_flow_steering *fs)
1585 void mlx5e_fs_set_udp(struct mlx5e_flow_steering *fs, struct mlx5e_fs_udp *udp)
1590 struct mlx5_core_dev *mlx5e_fs_get_mdev(struct mlx5e_flow_steering *fs)