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/mutex.h>
34 #include <linux/mlx5/driver.h>
36 #include "mlx5_core.h"
40 #define INIT_TREE_NODE_ARRAY_SIZE(...) (sizeof((struct init_tree_node[]){__VA_ARGS__}) /\
41 sizeof(struct init_tree_node))
43 #define ADD_PRIO(num_prios_val, min_level_val, max_ft_val, caps_val,\
44 ...) {.type = FS_TYPE_PRIO,\
45 .min_ft_level = min_level_val,\
46 .max_ft = max_ft_val,\
47 .num_leaf_prios = num_prios_val,\
49 .children = (struct init_tree_node[]) {__VA_ARGS__},\
50 .ar_size = INIT_TREE_NODE_ARRAY_SIZE(__VA_ARGS__) \
53 #define ADD_MULTIPLE_PRIO(num_prios_val, max_ft_val, ...)\
54 ADD_PRIO(num_prios_val, 0, max_ft_val, {},\
57 #define ADD_NS(...) {.type = FS_TYPE_NAMESPACE,\
58 .children = (struct init_tree_node[]) {__VA_ARGS__},\
59 .ar_size = INIT_TREE_NODE_ARRAY_SIZE(__VA_ARGS__) \
62 #define INIT_CAPS_ARRAY_SIZE(...) (sizeof((long[]){__VA_ARGS__}) /\
65 #define FS_CAP(cap) (__mlx5_bit_off(flow_table_nic_cap, cap))
67 #define FS_REQUIRED_CAPS(...) {.arr_sz = INIT_CAPS_ARRAY_SIZE(__VA_ARGS__), \
68 .caps = (long[]) {__VA_ARGS__} }
70 #define LEFTOVERS_MAX_FT 1
71 #define LEFTOVERS_NUM_PRIOS 1
72 #define BY_PASS_PRIO_MAX_FT 1
73 #define BY_PASS_MIN_LEVEL (KENREL_MIN_LEVEL + MLX5_BY_PASS_NUM_PRIOS +\
76 #define KERNEL_MAX_FT 3
77 #define KERNEL_NUM_PRIOS 2
78 #define KENREL_MIN_LEVEL 2
80 #define ANCHOR_MAX_FT 1
81 #define ANCHOR_NUM_PRIOS 1
82 #define ANCHOR_MIN_LEVEL (BY_PASS_MIN_LEVEL + 1)
87 static struct init_tree_node {
88 enum fs_node_type type;
89 struct init_tree_node *children;
91 struct node_caps caps;
97 .type = FS_TYPE_NAMESPACE,
99 .children = (struct init_tree_node[]) {
100 ADD_PRIO(0, BY_PASS_MIN_LEVEL, 0,
101 FS_REQUIRED_CAPS(FS_CAP(flow_table_properties_nic_receive.flow_modify_en),
102 FS_CAP(flow_table_properties_nic_receive.modify_root),
103 FS_CAP(flow_table_properties_nic_receive.identified_miss_table_mode),
104 FS_CAP(flow_table_properties_nic_receive.flow_table_modify)),
105 ADD_NS(ADD_MULTIPLE_PRIO(MLX5_BY_PASS_NUM_PRIOS, BY_PASS_PRIO_MAX_FT))),
106 ADD_PRIO(0, KENREL_MIN_LEVEL, 0, {},
107 ADD_NS(ADD_MULTIPLE_PRIO(KERNEL_NUM_PRIOS, KERNEL_MAX_FT))),
108 ADD_PRIO(0, BY_PASS_MIN_LEVEL, 0,
109 FS_REQUIRED_CAPS(FS_CAP(flow_table_properties_nic_receive.flow_modify_en),
110 FS_CAP(flow_table_properties_nic_receive.modify_root),
111 FS_CAP(flow_table_properties_nic_receive.identified_miss_table_mode),
112 FS_CAP(flow_table_properties_nic_receive.flow_table_modify)),
113 ADD_NS(ADD_MULTIPLE_PRIO(LEFTOVERS_NUM_PRIOS, LEFTOVERS_MAX_FT))),
114 ADD_PRIO(0, ANCHOR_MIN_LEVEL, 0, {},
115 ADD_NS(ADD_MULTIPLE_PRIO(ANCHOR_NUM_PRIOS, ANCHOR_MAX_FT))),
119 enum fs_i_mutex_lock_class {
120 FS_MUTEX_GRANDPARENT,
125 static void del_rule(struct fs_node *node);
126 static void del_flow_table(struct fs_node *node);
127 static void del_flow_group(struct fs_node *node);
128 static void del_fte(struct fs_node *node);
130 static void tree_init_node(struct fs_node *node,
131 unsigned int refcount,
132 void (*remove_func)(struct fs_node *))
134 atomic_set(&node->refcount, refcount);
135 INIT_LIST_HEAD(&node->list);
136 INIT_LIST_HEAD(&node->children);
137 mutex_init(&node->lock);
138 node->remove_func = remove_func;
141 static void tree_add_node(struct fs_node *node, struct fs_node *parent)
144 atomic_inc(&parent->refcount);
145 node->parent = parent;
147 /* Parent is the root */
151 node->root = parent->root;
154 static void tree_get_node(struct fs_node *node)
156 atomic_inc(&node->refcount);
159 static void nested_lock_ref_node(struct fs_node *node,
160 enum fs_i_mutex_lock_class class)
163 mutex_lock_nested(&node->lock, class);
164 atomic_inc(&node->refcount);
168 static void lock_ref_node(struct fs_node *node)
171 mutex_lock(&node->lock);
172 atomic_inc(&node->refcount);
176 static void unlock_ref_node(struct fs_node *node)
179 atomic_dec(&node->refcount);
180 mutex_unlock(&node->lock);
184 static void tree_put_node(struct fs_node *node)
186 struct fs_node *parent_node = node->parent;
188 lock_ref_node(parent_node);
189 if (atomic_dec_and_test(&node->refcount)) {
191 list_del_init(&node->list);
192 if (node->remove_func)
193 node->remove_func(node);
197 unlock_ref_node(parent_node);
198 if (!node && parent_node)
199 tree_put_node(parent_node);
202 static int tree_remove_node(struct fs_node *node)
204 if (atomic_read(&node->refcount) > 1) {
205 atomic_dec(&node->refcount);
212 static struct fs_prio *find_prio(struct mlx5_flow_namespace *ns,
215 struct fs_prio *iter_prio;
217 fs_for_each_prio(iter_prio, ns) {
218 if (iter_prio->prio == prio)
225 static unsigned int find_next_free_level(struct fs_prio *prio)
227 if (!list_empty(&prio->node.children)) {
228 struct mlx5_flow_table *ft;
230 ft = list_last_entry(&prio->node.children,
231 struct mlx5_flow_table,
233 return ft->level + 1;
235 return prio->start_level;
238 static bool masked_memcmp(void *mask, void *val1, void *val2, size_t size)
242 for (i = 0; i < size; i++, mask++, val1++, val2++)
243 if ((*((u8 *)val1) & (*(u8 *)mask)) !=
244 ((*(u8 *)val2) & (*(u8 *)mask)))
250 static bool compare_match_value(struct mlx5_flow_group_mask *mask,
251 void *fte_param1, void *fte_param2)
253 if (mask->match_criteria_enable &
254 1 << MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_OUTER_HEADERS) {
255 void *fte_match1 = MLX5_ADDR_OF(fte_match_param,
256 fte_param1, outer_headers);
257 void *fte_match2 = MLX5_ADDR_OF(fte_match_param,
258 fte_param2, outer_headers);
259 void *fte_mask = MLX5_ADDR_OF(fte_match_param,
260 mask->match_criteria, outer_headers);
262 if (!masked_memcmp(fte_mask, fte_match1, fte_match2,
263 MLX5_ST_SZ_BYTES(fte_match_set_lyr_2_4)))
267 if (mask->match_criteria_enable &
268 1 << MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_MISC_PARAMETERS) {
269 void *fte_match1 = MLX5_ADDR_OF(fte_match_param,
270 fte_param1, misc_parameters);
271 void *fte_match2 = MLX5_ADDR_OF(fte_match_param,
272 fte_param2, misc_parameters);
273 void *fte_mask = MLX5_ADDR_OF(fte_match_param,
274 mask->match_criteria, misc_parameters);
276 if (!masked_memcmp(fte_mask, fte_match1, fte_match2,
277 MLX5_ST_SZ_BYTES(fte_match_set_misc)))
281 if (mask->match_criteria_enable &
282 1 << MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_INNER_HEADERS) {
283 void *fte_match1 = MLX5_ADDR_OF(fte_match_param,
284 fte_param1, inner_headers);
285 void *fte_match2 = MLX5_ADDR_OF(fte_match_param,
286 fte_param2, inner_headers);
287 void *fte_mask = MLX5_ADDR_OF(fte_match_param,
288 mask->match_criteria, inner_headers);
290 if (!masked_memcmp(fte_mask, fte_match1, fte_match2,
291 MLX5_ST_SZ_BYTES(fte_match_set_lyr_2_4)))
297 static bool compare_match_criteria(u8 match_criteria_enable1,
298 u8 match_criteria_enable2,
299 void *mask1, void *mask2)
301 return match_criteria_enable1 == match_criteria_enable2 &&
302 !memcmp(mask1, mask2, MLX5_ST_SZ_BYTES(fte_match_param));
305 static struct mlx5_flow_root_namespace *find_root(struct fs_node *node)
307 struct fs_node *root;
308 struct mlx5_flow_namespace *ns;
312 if (WARN_ON(root->type != FS_TYPE_NAMESPACE)) {
313 pr_warn("mlx5: flow steering node is not in tree or garbaged\n");
317 ns = container_of(root, struct mlx5_flow_namespace, node);
318 return container_of(ns, struct mlx5_flow_root_namespace, ns);
321 static inline struct mlx5_core_dev *get_dev(struct fs_node *node)
323 struct mlx5_flow_root_namespace *root = find_root(node);
330 static void del_flow_table(struct fs_node *node)
332 struct mlx5_flow_table *ft;
333 struct mlx5_core_dev *dev;
334 struct fs_prio *prio;
337 fs_get_obj(ft, node);
338 dev = get_dev(&ft->node);
340 err = mlx5_cmd_destroy_flow_table(dev, ft);
342 pr_warn("flow steering can't destroy ft\n");
343 fs_get_obj(prio, ft->node.parent);
347 static void del_rule(struct fs_node *node)
349 struct mlx5_flow_rule *rule;
350 struct mlx5_flow_table *ft;
351 struct mlx5_flow_group *fg;
354 struct mlx5_core_dev *dev = get_dev(node);
355 int match_len = MLX5_ST_SZ_BYTES(fte_match_param);
358 match_value = mlx5_vzalloc(match_len);
360 pr_warn("failed to allocate inbox\n");
364 fs_get_obj(rule, node);
365 fs_get_obj(fte, rule->node.parent);
366 fs_get_obj(fg, fte->node.parent);
367 memcpy(match_value, fte->val, sizeof(fte->val));
368 fs_get_obj(ft, fg->node.parent);
369 list_del(&rule->node.list);
370 if (rule->sw_action == MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO) {
371 mutex_lock(&rule->dest_attr.ft->lock);
372 list_del(&rule->next_ft);
373 mutex_unlock(&rule->dest_attr.ft->lock);
375 if ((fte->action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) &&
377 err = mlx5_cmd_update_fte(dev, ft,
380 pr_warn("%s can't del rule fg id=%d fte_index=%d\n",
381 __func__, fg->id, fte->index);
386 static void del_fte(struct fs_node *node)
388 struct mlx5_flow_table *ft;
389 struct mlx5_flow_group *fg;
390 struct mlx5_core_dev *dev;
394 fs_get_obj(fte, node);
395 fs_get_obj(fg, fte->node.parent);
396 fs_get_obj(ft, fg->node.parent);
398 dev = get_dev(&ft->node);
399 err = mlx5_cmd_delete_fte(dev, ft,
402 pr_warn("flow steering can't delete fte in index %d of flow group id %d\n",
409 static void del_flow_group(struct fs_node *node)
411 struct mlx5_flow_group *fg;
412 struct mlx5_flow_table *ft;
413 struct mlx5_core_dev *dev;
415 fs_get_obj(fg, node);
416 fs_get_obj(ft, fg->node.parent);
417 dev = get_dev(&ft->node);
419 if (mlx5_cmd_destroy_flow_group(dev, ft, fg->id))
420 pr_warn("flow steering can't destroy fg %d of ft %d\n",
424 static struct fs_fte *alloc_fte(u8 action,
431 fte = kzalloc(sizeof(*fte), GFP_KERNEL);
433 return ERR_PTR(-ENOMEM);
435 memcpy(fte->val, match_value, sizeof(fte->val));
436 fte->node.type = FS_TYPE_FLOW_ENTRY;
437 fte->flow_tag = flow_tag;
439 fte->action = action;
444 static struct mlx5_flow_group *alloc_flow_group(u32 *create_fg_in)
446 struct mlx5_flow_group *fg;
447 void *match_criteria = MLX5_ADDR_OF(create_flow_group_in,
448 create_fg_in, match_criteria);
449 u8 match_criteria_enable = MLX5_GET(create_flow_group_in,
451 match_criteria_enable);
452 fg = kzalloc(sizeof(*fg), GFP_KERNEL);
454 return ERR_PTR(-ENOMEM);
456 fg->mask.match_criteria_enable = match_criteria_enable;
457 memcpy(&fg->mask.match_criteria, match_criteria,
458 sizeof(fg->mask.match_criteria));
459 fg->node.type = FS_TYPE_FLOW_GROUP;
460 fg->start_index = MLX5_GET(create_flow_group_in, create_fg_in,
462 fg->max_ftes = MLX5_GET(create_flow_group_in, create_fg_in,
463 end_flow_index) - fg->start_index + 1;
467 static struct mlx5_flow_table *alloc_flow_table(int level, int max_fte,
468 enum fs_flow_table_type table_type)
470 struct mlx5_flow_table *ft;
472 ft = kzalloc(sizeof(*ft), GFP_KERNEL);
477 ft->node.type = FS_TYPE_FLOW_TABLE;
478 ft->type = table_type;
479 ft->max_fte = max_fte;
480 INIT_LIST_HEAD(&ft->fwd_rules);
481 mutex_init(&ft->lock);
486 /* If reverse is false, then we search for the first flow table in the
487 * root sub-tree from start(closest from right), else we search for the
488 * last flow table in the root sub-tree till start(closest from left).
490 static struct mlx5_flow_table *find_closest_ft_recursive(struct fs_node *root,
491 struct list_head *start,
494 #define list_advance_entry(pos, reverse) \
495 ((reverse) ? list_prev_entry(pos, list) : list_next_entry(pos, list))
497 #define list_for_each_advance_continue(pos, head, reverse) \
498 for (pos = list_advance_entry(pos, reverse); \
499 &pos->list != (head); \
500 pos = list_advance_entry(pos, reverse))
502 struct fs_node *iter = list_entry(start, struct fs_node, list);
503 struct mlx5_flow_table *ft = NULL;
508 list_for_each_advance_continue(iter, &root->children, reverse) {
509 if (iter->type == FS_TYPE_FLOW_TABLE) {
510 fs_get_obj(ft, iter);
513 ft = find_closest_ft_recursive(iter, &iter->children, reverse);
521 /* If reverse if false then return the first flow table in next priority of
522 * prio in the tree, else return the last flow table in the previous priority
523 * of prio in the tree.
525 static struct mlx5_flow_table *find_closest_ft(struct fs_prio *prio, bool reverse)
527 struct mlx5_flow_table *ft = NULL;
528 struct fs_node *curr_node;
529 struct fs_node *parent;
531 parent = prio->node.parent;
532 curr_node = &prio->node;
533 while (!ft && parent) {
534 ft = find_closest_ft_recursive(parent, &curr_node->list, reverse);
536 parent = curr_node->parent;
541 /* Assuming all the tree is locked by mutex chain lock */
542 static struct mlx5_flow_table *find_next_chained_ft(struct fs_prio *prio)
544 return find_closest_ft(prio, false);
547 /* Assuming all the tree is locked by mutex chain lock */
548 static struct mlx5_flow_table *find_prev_chained_ft(struct fs_prio *prio)
550 return find_closest_ft(prio, true);
553 static int connect_fts_in_prio(struct mlx5_core_dev *dev,
554 struct fs_prio *prio,
555 struct mlx5_flow_table *ft)
557 struct mlx5_flow_table *iter;
561 fs_for_each_ft(iter, prio) {
563 err = mlx5_cmd_modify_flow_table(dev,
567 mlx5_core_warn(dev, "Failed to modify flow table %d\n",
569 /* The driver is out of sync with the FW */
578 /* Connect flow tables from previous priority of prio to ft */
579 static int connect_prev_fts(struct mlx5_core_dev *dev,
580 struct mlx5_flow_table *ft,
581 struct fs_prio *prio)
583 struct mlx5_flow_table *prev_ft;
585 prev_ft = find_prev_chained_ft(prio);
587 struct fs_prio *prev_prio;
589 fs_get_obj(prev_prio, prev_ft->node.parent);
590 return connect_fts_in_prio(dev, prev_prio, ft);
595 static int update_root_ft_create(struct mlx5_flow_table *ft, struct fs_prio
598 struct mlx5_flow_root_namespace *root = find_root(&prio->node);
599 int min_level = INT_MAX;
603 min_level = root->root_ft->level;
605 if (ft->level >= min_level)
608 err = mlx5_cmd_update_root_ft(root->dev, ft);
610 mlx5_core_warn(root->dev, "Update root flow table of id=%u failed\n",
618 static int mlx5_modify_rule_destination(struct mlx5_flow_rule *rule,
619 struct mlx5_flow_destination *dest)
621 struct mlx5_flow_table *ft;
622 struct mlx5_flow_group *fg;
626 fs_get_obj(fte, rule->node.parent);
627 if (!(fte->action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST))
629 lock_ref_node(&fte->node);
630 fs_get_obj(fg, fte->node.parent);
631 fs_get_obj(ft, fg->node.parent);
633 memcpy(&rule->dest_attr, dest, sizeof(*dest));
634 err = mlx5_cmd_update_fte(get_dev(&ft->node),
636 unlock_ref_node(&fte->node);
641 /* Modify/set FWD rules that point on old_next_ft to point on new_next_ft */
642 static int connect_fwd_rules(struct mlx5_core_dev *dev,
643 struct mlx5_flow_table *new_next_ft,
644 struct mlx5_flow_table *old_next_ft)
646 struct mlx5_flow_destination dest;
647 struct mlx5_flow_rule *iter;
650 /* new_next_ft and old_next_ft could be NULL only
651 * when we create/destroy the anchor flow table.
653 if (!new_next_ft || !old_next_ft)
656 dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
657 dest.ft = new_next_ft;
659 mutex_lock(&old_next_ft->lock);
660 list_splice_init(&old_next_ft->fwd_rules, &new_next_ft->fwd_rules);
661 mutex_unlock(&old_next_ft->lock);
662 list_for_each_entry(iter, &new_next_ft->fwd_rules, next_ft) {
663 err = mlx5_modify_rule_destination(iter, &dest);
665 pr_err("mlx5_core: failed to modify rule to point on flow table %d\n",
671 static int connect_flow_table(struct mlx5_core_dev *dev, struct mlx5_flow_table *ft,
672 struct fs_prio *prio)
674 struct mlx5_flow_table *next_ft;
677 /* Connect_prev_fts and update_root_ft_create are mutually exclusive */
679 if (list_empty(&prio->node.children)) {
680 err = connect_prev_fts(dev, ft, prio);
684 next_ft = find_next_chained_ft(prio);
685 err = connect_fwd_rules(dev, ft, next_ft);
690 if (MLX5_CAP_FLOWTABLE(dev,
691 flow_table_properties_nic_receive.modify_root))
692 err = update_root_ft_create(ft, prio);
696 struct mlx5_flow_table *mlx5_create_flow_table(struct mlx5_flow_namespace *ns,
700 struct mlx5_flow_table *next_ft = NULL;
701 struct mlx5_flow_table *ft;
704 struct mlx5_flow_root_namespace *root =
705 find_root(&ns->node);
706 struct fs_prio *fs_prio = NULL;
709 pr_err("mlx5: flow steering failed to find root of namespace\n");
710 return ERR_PTR(-ENODEV);
713 mutex_lock(&root->chain_lock);
714 fs_prio = find_prio(ns, prio);
719 if (fs_prio->num_ft == fs_prio->max_ft) {
724 ft = alloc_flow_table(find_next_free_level(fs_prio),
725 roundup_pow_of_two(max_fte),
732 tree_init_node(&ft->node, 1, del_flow_table);
733 log_table_sz = ilog2(ft->max_fte);
734 next_ft = find_next_chained_ft(fs_prio);
735 err = mlx5_cmd_create_flow_table(root->dev, ft->type, ft->level,
736 log_table_sz, next_ft, &ft->id);
740 err = connect_flow_table(root->dev, ft, fs_prio);
743 lock_ref_node(&fs_prio->node);
744 tree_add_node(&ft->node, &fs_prio->node);
745 list_add_tail(&ft->node.list, &fs_prio->node.children);
747 unlock_ref_node(&fs_prio->node);
748 mutex_unlock(&root->chain_lock);
751 mlx5_cmd_destroy_flow_table(root->dev, ft);
755 mutex_unlock(&root->chain_lock);
759 struct mlx5_flow_table *mlx5_create_auto_grouped_flow_table(struct mlx5_flow_namespace *ns,
761 int num_flow_table_entries,
764 struct mlx5_flow_table *ft;
766 if (max_num_groups > num_flow_table_entries)
767 return ERR_PTR(-EINVAL);
769 ft = mlx5_create_flow_table(ns, prio, num_flow_table_entries);
773 ft->autogroup.active = true;
774 ft->autogroup.required_groups = max_num_groups;
778 EXPORT_SYMBOL(mlx5_create_auto_grouped_flow_table);
780 /* Flow table should be locked */
781 static struct mlx5_flow_group *create_flow_group_common(struct mlx5_flow_table *ft,
787 struct mlx5_flow_group *fg;
788 struct mlx5_core_dev *dev = get_dev(&ft->node);
792 return ERR_PTR(-ENODEV);
794 fg = alloc_flow_group(fg_in);
798 err = mlx5_cmd_create_flow_group(dev, ft, fg_in, &fg->id);
804 if (ft->autogroup.active)
805 ft->autogroup.num_groups++;
806 /* Add node to tree */
807 tree_init_node(&fg->node, !is_auto_fg, del_flow_group);
808 tree_add_node(&fg->node, &ft->node);
809 /* Add node to group list */
810 list_add(&fg->node.list, ft->node.children.prev);
815 struct mlx5_flow_group *mlx5_create_flow_group(struct mlx5_flow_table *ft,
818 struct mlx5_flow_group *fg;
820 if (ft->autogroup.active)
821 return ERR_PTR(-EPERM);
823 lock_ref_node(&ft->node);
824 fg = create_flow_group_common(ft, fg_in, &ft->node.children, false);
825 unlock_ref_node(&ft->node);
830 static struct mlx5_flow_rule *alloc_rule(struct mlx5_flow_destination *dest)
832 struct mlx5_flow_rule *rule;
834 rule = kzalloc(sizeof(*rule), GFP_KERNEL);
838 INIT_LIST_HEAD(&rule->next_ft);
839 rule->node.type = FS_TYPE_FLOW_DEST;
841 memcpy(&rule->dest_attr, dest, sizeof(*dest));
846 /* fte should not be deleted while calling this function */
847 static struct mlx5_flow_rule *add_rule_fte(struct fs_fte *fte,
848 struct mlx5_flow_group *fg,
849 struct mlx5_flow_destination *dest)
851 struct mlx5_flow_table *ft;
852 struct mlx5_flow_rule *rule;
855 rule = alloc_rule(dest);
857 return ERR_PTR(-ENOMEM);
859 fs_get_obj(ft, fg->node.parent);
860 /* Add dest to dests list- we need flow tables to be in the
861 * end of the list for forward to next prio rules.
863 tree_init_node(&rule->node, 1, del_rule);
864 if (dest && dest->type != MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE)
865 list_add(&rule->node.list, &fte->node.children);
867 list_add_tail(&rule->node.list, &fte->node.children);
870 if (fte->dests_size == 1 || !dest)
871 err = mlx5_cmd_create_fte(get_dev(&ft->node),
874 err = mlx5_cmd_update_fte(get_dev(&ft->node),
879 fte->status |= FS_FTE_STATUS_EXISTING;
884 list_del(&rule->node.list);
891 /* Assumed fg is locked */
892 static unsigned int get_free_fte_index(struct mlx5_flow_group *fg,
893 struct list_head **prev)
896 unsigned int start = fg->start_index;
899 *prev = &fg->node.children;
901 /* assumed list is sorted by index */
902 fs_for_each_fte(fte, fg) {
903 if (fte->index != start)
907 *prev = &fte->node.list;
913 /* prev is output, prev->next = new_fte */
914 static struct fs_fte *create_fte(struct mlx5_flow_group *fg,
918 struct list_head **prev)
923 index = get_free_fte_index(fg, prev);
924 fte = alloc_fte(action, flow_tag, match_value, index);
931 static struct mlx5_flow_group *create_autogroup(struct mlx5_flow_table *ft,
932 u8 match_criteria_enable,
935 int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
936 struct list_head *prev = &ft->node.children;
937 unsigned int candidate_index = 0;
938 struct mlx5_flow_group *fg;
939 void *match_criteria_addr;
940 unsigned int group_size = 0;
943 if (!ft->autogroup.active)
944 return ERR_PTR(-ENOENT);
946 in = mlx5_vzalloc(inlen);
948 return ERR_PTR(-ENOMEM);
950 if (ft->autogroup.num_groups < ft->autogroup.required_groups)
951 /* We save place for flow groups in addition to max types */
952 group_size = ft->max_fte / (ft->autogroup.required_groups + 1);
954 /* ft->max_fte == ft->autogroup.max_types */
958 /* sorted by start_index */
959 fs_for_each_fg(fg, ft) {
960 if (candidate_index + group_size > fg->start_index)
961 candidate_index = fg->start_index + fg->max_ftes;
964 prev = &fg->node.list;
967 if (candidate_index + group_size > ft->max_fte) {
968 fg = ERR_PTR(-ENOSPC);
972 MLX5_SET(create_flow_group_in, in, match_criteria_enable,
973 match_criteria_enable);
974 MLX5_SET(create_flow_group_in, in, start_flow_index, candidate_index);
975 MLX5_SET(create_flow_group_in, in, end_flow_index, candidate_index +
977 match_criteria_addr = MLX5_ADDR_OF(create_flow_group_in,
979 memcpy(match_criteria_addr, match_criteria,
980 MLX5_ST_SZ_BYTES(fte_match_param));
982 fg = create_flow_group_common(ft, in, prev, true);
988 static struct mlx5_flow_rule *find_flow_rule(struct fs_fte *fte,
989 struct mlx5_flow_destination *dest)
991 struct mlx5_flow_rule *rule;
993 list_for_each_entry(rule, &fte->node.children, node.list) {
994 if (rule->dest_attr.type == dest->type) {
995 if ((dest->type == MLX5_FLOW_DESTINATION_TYPE_VPORT &&
996 dest->vport_num == rule->dest_attr.vport_num) ||
997 (dest->type == MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE &&
998 dest->ft == rule->dest_attr.ft) ||
999 (dest->type == MLX5_FLOW_DESTINATION_TYPE_TIR &&
1000 dest->tir_num == rule->dest_attr.tir_num))
1007 static struct mlx5_flow_rule *add_rule_fg(struct mlx5_flow_group *fg,
1011 struct mlx5_flow_destination *dest)
1014 struct mlx5_flow_rule *rule;
1015 struct mlx5_flow_table *ft;
1016 struct list_head *prev;
1018 nested_lock_ref_node(&fg->node, FS_MUTEX_PARENT);
1019 fs_for_each_fte(fte, fg) {
1020 nested_lock_ref_node(&fte->node, FS_MUTEX_CHILD);
1021 if (compare_match_value(&fg->mask, match_value, &fte->val) &&
1022 action == fte->action && flow_tag == fte->flow_tag) {
1023 rule = find_flow_rule(fte, dest);
1025 atomic_inc(&rule->node.refcount);
1026 unlock_ref_node(&fte->node);
1027 unlock_ref_node(&fg->node);
1030 rule = add_rule_fte(fte, fg, dest);
1031 unlock_ref_node(&fte->node);
1037 unlock_ref_node(&fte->node);
1039 fs_get_obj(ft, fg->node.parent);
1040 if (fg->num_ftes >= fg->max_ftes) {
1041 rule = ERR_PTR(-ENOSPC);
1045 fte = create_fte(fg, match_value, action, flow_tag, &prev);
1050 tree_init_node(&fte->node, 0, del_fte);
1051 rule = add_rule_fte(fte, fg, dest);
1059 tree_add_node(&fte->node, &fg->node);
1060 list_add(&fte->node.list, prev);
1062 tree_add_node(&rule->node, &fte->node);
1064 unlock_ref_node(&fg->node);
1068 static struct mlx5_flow_rule *
1069 _mlx5_add_flow_rule(struct mlx5_flow_table *ft,
1070 u8 match_criteria_enable,
1071 u32 *match_criteria,
1075 struct mlx5_flow_destination *dest)
1077 struct mlx5_flow_group *g;
1078 struct mlx5_flow_rule *rule;
1080 if ((action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) && !dest)
1081 return ERR_PTR(-EINVAL);
1083 nested_lock_ref_node(&ft->node, FS_MUTEX_GRANDPARENT);
1084 fs_for_each_fg(g, ft)
1085 if (compare_match_criteria(g->mask.match_criteria_enable,
1086 match_criteria_enable,
1087 g->mask.match_criteria,
1089 rule = add_rule_fg(g, match_value,
1090 action, flow_tag, dest);
1091 if (!IS_ERR(rule) || PTR_ERR(rule) != -ENOSPC)
1095 g = create_autogroup(ft, match_criteria_enable, match_criteria);
1101 rule = add_rule_fg(g, match_value,
1102 action, flow_tag, dest);
1104 /* Remove assumes refcount > 0 and autogroup creates a group
1105 * with a refcount = 0.
1107 unlock_ref_node(&ft->node);
1108 tree_get_node(&g->node);
1109 tree_remove_node(&g->node);
1113 unlock_ref_node(&ft->node);
1117 static bool fwd_next_prio_supported(struct mlx5_flow_table *ft)
1119 return ((ft->type == FS_FT_NIC_RX) &&
1120 (MLX5_CAP_FLOWTABLE(get_dev(&ft->node), nic_rx_multi_path_tirs)));
1123 struct mlx5_flow_rule *
1124 mlx5_add_flow_rule(struct mlx5_flow_table *ft,
1125 u8 match_criteria_enable,
1126 u32 *match_criteria,
1130 struct mlx5_flow_destination *dest)
1132 struct mlx5_flow_root_namespace *root = find_root(&ft->node);
1133 struct mlx5_flow_destination gen_dest;
1134 struct mlx5_flow_table *next_ft = NULL;
1135 struct mlx5_flow_rule *rule = NULL;
1136 u32 sw_action = action;
1137 struct fs_prio *prio;
1139 fs_get_obj(prio, ft->node.parent);
1140 if (action == MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO) {
1141 if (!fwd_next_prio_supported(ft))
1142 return ERR_PTR(-EOPNOTSUPP);
1144 return ERR_PTR(-EINVAL);
1145 mutex_lock(&root->chain_lock);
1146 next_ft = find_next_chained_ft(prio);
1148 gen_dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
1149 gen_dest.ft = next_ft;
1151 action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
1153 mutex_unlock(&root->chain_lock);
1154 return ERR_PTR(-EOPNOTSUPP);
1158 rule = _mlx5_add_flow_rule(ft, match_criteria_enable, match_criteria,
1159 match_value, action, flow_tag, dest);
1161 if (sw_action == MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO) {
1162 if (!IS_ERR_OR_NULL(rule) &&
1163 (list_empty(&rule->next_ft))) {
1164 mutex_lock(&next_ft->lock);
1165 list_add(&rule->next_ft, &next_ft->fwd_rules);
1166 mutex_unlock(&next_ft->lock);
1167 rule->sw_action = MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO;
1169 mutex_unlock(&root->chain_lock);
1173 EXPORT_SYMBOL(mlx5_add_flow_rule);
1175 void mlx5_del_flow_rule(struct mlx5_flow_rule *rule)
1177 tree_remove_node(&rule->node);
1179 EXPORT_SYMBOL(mlx5_del_flow_rule);
1181 /* Assuming prio->node.children(flow tables) is sorted by level */
1182 static struct mlx5_flow_table *find_next_ft(struct mlx5_flow_table *ft)
1184 struct fs_prio *prio;
1186 fs_get_obj(prio, ft->node.parent);
1188 if (!list_is_last(&ft->node.list, &prio->node.children))
1189 return list_next_entry(ft, node.list);
1190 return find_next_chained_ft(prio);
1193 static int update_root_ft_destroy(struct mlx5_flow_table *ft)
1195 struct mlx5_flow_root_namespace *root = find_root(&ft->node);
1196 struct mlx5_flow_table *new_root_ft = NULL;
1198 if (root->root_ft != ft)
1201 new_root_ft = find_next_ft(ft);
1203 int err = mlx5_cmd_update_root_ft(root->dev, new_root_ft);
1206 mlx5_core_warn(root->dev, "Update root flow table of id=%u failed\n",
1210 root->root_ft = new_root_ft;
1215 /* Connect flow table from previous priority to
1216 * the next flow table.
1218 static int disconnect_flow_table(struct mlx5_flow_table *ft)
1220 struct mlx5_core_dev *dev = get_dev(&ft->node);
1221 struct mlx5_flow_table *next_ft;
1222 struct fs_prio *prio;
1225 err = update_root_ft_destroy(ft);
1229 fs_get_obj(prio, ft->node.parent);
1230 if (!(list_first_entry(&prio->node.children,
1231 struct mlx5_flow_table,
1235 next_ft = find_next_chained_ft(prio);
1236 err = connect_fwd_rules(dev, next_ft, ft);
1240 err = connect_prev_fts(dev, next_ft, prio);
1242 mlx5_core_warn(dev, "Failed to disconnect flow table %d\n",
1247 int mlx5_destroy_flow_table(struct mlx5_flow_table *ft)
1249 struct mlx5_flow_root_namespace *root = find_root(&ft->node);
1252 mutex_lock(&root->chain_lock);
1253 err = disconnect_flow_table(ft);
1255 mutex_unlock(&root->chain_lock);
1258 if (tree_remove_node(&ft->node))
1259 mlx5_core_warn(get_dev(&ft->node), "Flow table %d wasn't destroyed, refcount > 1\n",
1261 mutex_unlock(&root->chain_lock);
1265 EXPORT_SYMBOL(mlx5_destroy_flow_table);
1267 void mlx5_destroy_flow_group(struct mlx5_flow_group *fg)
1269 if (tree_remove_node(&fg->node))
1270 mlx5_core_warn(get_dev(&fg->node), "Flow group %d wasn't destroyed, refcount > 1\n",
1274 struct mlx5_flow_namespace *mlx5_get_flow_namespace(struct mlx5_core_dev *dev,
1275 enum mlx5_flow_namespace_type type)
1277 struct mlx5_flow_root_namespace *root_ns = dev->priv.root_ns;
1279 struct fs_prio *fs_prio;
1280 struct mlx5_flow_namespace *ns;
1286 case MLX5_FLOW_NAMESPACE_BYPASS:
1287 case MLX5_FLOW_NAMESPACE_KERNEL:
1288 case MLX5_FLOW_NAMESPACE_LEFTOVERS:
1289 case MLX5_FLOW_NAMESPACE_ANCHOR:
1292 case MLX5_FLOW_NAMESPACE_FDB:
1293 if (dev->priv.fdb_root_ns)
1294 return &dev->priv.fdb_root_ns->ns;
1301 fs_prio = find_prio(&root_ns->ns, prio);
1305 ns = list_first_entry(&fs_prio->node.children,
1311 EXPORT_SYMBOL(mlx5_get_flow_namespace);
1313 static struct fs_prio *fs_create_prio(struct mlx5_flow_namespace *ns,
1314 unsigned prio, int max_ft)
1316 struct fs_prio *fs_prio;
1318 fs_prio = kzalloc(sizeof(*fs_prio), GFP_KERNEL);
1320 return ERR_PTR(-ENOMEM);
1322 fs_prio->node.type = FS_TYPE_PRIO;
1323 tree_init_node(&fs_prio->node, 1, NULL);
1324 tree_add_node(&fs_prio->node, &ns->node);
1325 fs_prio->max_ft = max_ft;
1326 fs_prio->prio = prio;
1327 list_add_tail(&fs_prio->node.list, &ns->node.children);
1332 static struct mlx5_flow_namespace *fs_init_namespace(struct mlx5_flow_namespace
1335 ns->node.type = FS_TYPE_NAMESPACE;
1340 static struct mlx5_flow_namespace *fs_create_namespace(struct fs_prio *prio)
1342 struct mlx5_flow_namespace *ns;
1344 ns = kzalloc(sizeof(*ns), GFP_KERNEL);
1346 return ERR_PTR(-ENOMEM);
1348 fs_init_namespace(ns);
1349 tree_init_node(&ns->node, 1, NULL);
1350 tree_add_node(&ns->node, &prio->node);
1351 list_add_tail(&ns->node.list, &prio->node.children);
1356 static int create_leaf_prios(struct mlx5_flow_namespace *ns, struct init_tree_node
1359 struct fs_prio *fs_prio;
1362 for (i = 0; i < prio_metadata->num_leaf_prios; i++) {
1363 fs_prio = fs_create_prio(ns, i, prio_metadata->max_ft);
1364 if (IS_ERR(fs_prio))
1365 return PTR_ERR(fs_prio);
1370 #define FLOW_TABLE_BIT_SZ 1
1371 #define GET_FLOW_TABLE_CAP(dev, offset) \
1372 ((be32_to_cpu(*((__be32 *)(dev->hca_caps_cur[MLX5_CAP_FLOW_TABLE]) + \
1374 (32 - FLOW_TABLE_BIT_SZ - (offset & 0x1f))) & FLOW_TABLE_BIT_SZ)
1375 static bool has_required_caps(struct mlx5_core_dev *dev, struct node_caps *caps)
1379 for (i = 0; i < caps->arr_sz; i++) {
1380 if (!GET_FLOW_TABLE_CAP(dev, caps->caps[i]))
1386 static int init_root_tree_recursive(struct mlx5_core_dev *dev,
1387 struct init_tree_node *init_node,
1388 struct fs_node *fs_parent_node,
1389 struct init_tree_node *init_parent_node,
1392 int max_ft_level = MLX5_CAP_FLOWTABLE(dev,
1393 flow_table_properties_nic_receive.
1395 struct mlx5_flow_namespace *fs_ns;
1396 struct fs_prio *fs_prio;
1397 struct fs_node *base;
1401 if (init_node->type == FS_TYPE_PRIO) {
1402 if ((init_node->min_ft_level > max_ft_level) ||
1403 !has_required_caps(dev, &init_node->caps))
1406 fs_get_obj(fs_ns, fs_parent_node);
1407 if (init_node->num_leaf_prios)
1408 return create_leaf_prios(fs_ns, init_node);
1409 fs_prio = fs_create_prio(fs_ns, index, init_node->max_ft);
1410 if (IS_ERR(fs_prio))
1411 return PTR_ERR(fs_prio);
1412 base = &fs_prio->node;
1413 } else if (init_node->type == FS_TYPE_NAMESPACE) {
1414 fs_get_obj(fs_prio, fs_parent_node);
1415 fs_ns = fs_create_namespace(fs_prio);
1417 return PTR_ERR(fs_ns);
1418 base = &fs_ns->node;
1422 for (i = 0; i < init_node->ar_size; i++) {
1423 err = init_root_tree_recursive(dev, &init_node->children[i],
1424 base, init_node, i);
1432 static int init_root_tree(struct mlx5_core_dev *dev,
1433 struct init_tree_node *init_node,
1434 struct fs_node *fs_parent_node)
1437 struct mlx5_flow_namespace *fs_ns;
1440 fs_get_obj(fs_ns, fs_parent_node);
1441 for (i = 0; i < init_node->ar_size; i++) {
1442 err = init_root_tree_recursive(dev, &init_node->children[i],
1451 static struct mlx5_flow_root_namespace *create_root_ns(struct mlx5_core_dev *dev,
1452 enum fs_flow_table_type
1455 struct mlx5_flow_root_namespace *root_ns;
1456 struct mlx5_flow_namespace *ns;
1458 /* Create the root namespace */
1459 root_ns = mlx5_vzalloc(sizeof(*root_ns));
1464 root_ns->table_type = table_type;
1467 fs_init_namespace(ns);
1468 mutex_init(&root_ns->chain_lock);
1469 tree_init_node(&ns->node, 1, NULL);
1470 tree_add_node(&ns->node, NULL);
1475 static void set_prio_attrs_in_prio(struct fs_prio *prio, int acc_level);
1477 static int set_prio_attrs_in_ns(struct mlx5_flow_namespace *ns, int acc_level)
1479 struct fs_prio *prio;
1481 fs_for_each_prio(prio, ns) {
1482 /* This updates prio start_level and max_ft */
1483 set_prio_attrs_in_prio(prio, acc_level);
1484 acc_level += prio->max_ft;
1489 static void set_prio_attrs_in_prio(struct fs_prio *prio, int acc_level)
1491 struct mlx5_flow_namespace *ns;
1492 int acc_level_ns = acc_level;
1494 prio->start_level = acc_level;
1495 fs_for_each_ns(ns, prio)
1496 /* This updates start_level and max_ft of ns's priority descendants */
1497 acc_level_ns = set_prio_attrs_in_ns(ns, acc_level);
1499 prio->max_ft = acc_level_ns - prio->start_level;
1500 WARN_ON(prio->max_ft < acc_level_ns - prio->start_level);
1503 static void set_prio_attrs(struct mlx5_flow_root_namespace *root_ns)
1505 struct mlx5_flow_namespace *ns = &root_ns->ns;
1506 struct fs_prio *prio;
1507 int start_level = 0;
1509 fs_for_each_prio(prio, ns) {
1510 set_prio_attrs_in_prio(prio, start_level);
1511 start_level += prio->max_ft;
1515 #define ANCHOR_PRIO 0
1516 #define ANCHOR_SIZE 1
1517 static int create_anchor_flow_table(struct mlx5_core_dev
1520 struct mlx5_flow_namespace *ns = NULL;
1521 struct mlx5_flow_table *ft;
1523 ns = mlx5_get_flow_namespace(dev, MLX5_FLOW_NAMESPACE_ANCHOR);
1526 ft = mlx5_create_flow_table(ns, ANCHOR_PRIO, ANCHOR_SIZE);
1528 mlx5_core_err(dev, "Failed to create last anchor flow table");
1534 static int init_root_ns(struct mlx5_core_dev *dev)
1537 dev->priv.root_ns = create_root_ns(dev, FS_FT_NIC_RX);
1538 if (IS_ERR_OR_NULL(dev->priv.root_ns))
1541 if (init_root_tree(dev, &root_fs, &dev->priv.root_ns->ns.node))
1544 set_prio_attrs(dev->priv.root_ns);
1546 if (create_anchor_flow_table(dev))
1552 mlx5_cleanup_fs(dev);
1556 static void cleanup_single_prio_root_ns(struct mlx5_core_dev *dev,
1557 struct mlx5_flow_root_namespace *root_ns)
1559 struct fs_node *prio;
1564 if (!list_empty(&root_ns->ns.node.children)) {
1565 prio = list_first_entry(&root_ns->ns.node.children,
1568 if (tree_remove_node(prio))
1570 "Flow steering priority wasn't destroyed, refcount > 1\n");
1572 if (tree_remove_node(&root_ns->ns.node))
1574 "Flow steering namespace wasn't destroyed, refcount > 1\n");
1578 static void destroy_flow_tables(struct fs_prio *prio)
1580 struct mlx5_flow_table *iter;
1581 struct mlx5_flow_table *tmp;
1583 fs_for_each_ft_safe(iter, tmp, prio)
1584 mlx5_destroy_flow_table(iter);
1587 static void cleanup_root_ns(struct mlx5_core_dev *dev)
1589 struct mlx5_flow_root_namespace *root_ns = dev->priv.root_ns;
1590 struct fs_prio *iter_prio;
1592 if (!MLX5_CAP_GEN(dev, nic_flow_table))
1599 fs_for_each_prio(iter_prio, &root_ns->ns) {
1600 struct fs_node *node;
1601 struct mlx5_flow_namespace *iter_ns;
1603 fs_for_each_ns_or_ft(node, iter_prio) {
1604 if (node->type == FS_TYPE_FLOW_TABLE)
1606 fs_get_obj(iter_ns, node);
1607 while (!list_empty(&iter_ns->node.children)) {
1608 struct fs_prio *obj_iter_prio2;
1609 struct fs_node *iter_prio2 =
1610 list_first_entry(&iter_ns->node.children,
1614 fs_get_obj(obj_iter_prio2, iter_prio2);
1615 destroy_flow_tables(obj_iter_prio2);
1616 if (tree_remove_node(iter_prio2)) {
1618 "Priority %d wasn't destroyed, refcount > 1\n",
1619 obj_iter_prio2->prio);
1627 fs_for_each_prio(iter_prio, &root_ns->ns) {
1628 while (!list_empty(&iter_prio->node.children)) {
1629 struct fs_node *iter_ns =
1630 list_first_entry(&iter_prio->node.children,
1633 if (tree_remove_node(iter_ns)) {
1635 "Namespace wasn't destroyed, refcount > 1\n");
1642 while (!list_empty(&root_ns->ns.node.children)) {
1643 struct fs_prio *obj_prio_node;
1644 struct fs_node *prio_node =
1645 list_first_entry(&root_ns->ns.node.children,
1649 fs_get_obj(obj_prio_node, prio_node);
1650 if (tree_remove_node(prio_node)) {
1652 "Priority %d wasn't destroyed, refcount > 1\n",
1653 obj_prio_node->prio);
1658 if (tree_remove_node(&root_ns->ns.node)) {
1660 "root namespace wasn't destroyed, refcount > 1\n");
1664 dev->priv.root_ns = NULL;
1667 void mlx5_cleanup_fs(struct mlx5_core_dev *dev)
1669 cleanup_root_ns(dev);
1670 cleanup_single_prio_root_ns(dev, dev->priv.fdb_root_ns);
1673 static int init_fdb_root_ns(struct mlx5_core_dev *dev)
1675 struct fs_prio *prio;
1677 dev->priv.fdb_root_ns = create_root_ns(dev, FS_FT_FDB);
1678 if (!dev->priv.fdb_root_ns)
1681 /* Create single prio */
1682 prio = fs_create_prio(&dev->priv.fdb_root_ns->ns, 0, 1);
1684 cleanup_single_prio_root_ns(dev, dev->priv.fdb_root_ns);
1685 return PTR_ERR(prio);
1691 int mlx5_init_fs(struct mlx5_core_dev *dev)
1695 if (MLX5_CAP_GEN(dev, nic_flow_table)) {
1696 err = init_root_ns(dev);
1700 if (MLX5_CAP_GEN(dev, eswitch_flow_table)) {
1701 err = init_fdb_root_ns(dev);
1703 cleanup_root_ns(dev);