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, num_levels_val, caps_val,\
44 ...) {.type = FS_TYPE_PRIO,\
45 .min_ft_level = min_level_val,\
46 .num_levels = num_levels_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, num_levels_val, ...)\
54 ADD_PRIO(num_prios_val, 0, num_levels_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_NUM_LEVELS 1
71 #define LEFTOVERS_NUM_PRIOS 1
73 #define BY_PASS_PRIO_NUM_LEVELS 1
74 #define BY_PASS_MIN_LEVEL (KERNEL_MIN_LEVEL + MLX5_BY_PASS_NUM_PRIOS +\
77 #define KERNEL_NIC_PRIO_NUM_LEVELS 3
78 #define KERNEL_NIC_NUM_PRIOS 1
79 /* One more level for tc */
80 #define KERNEL_MIN_LEVEL (KERNEL_NIC_PRIO_NUM_LEVELS + 1)
82 #define ANCHOR_NUM_LEVELS 1
83 #define ANCHOR_NUM_PRIOS 1
84 #define ANCHOR_MIN_LEVEL (BY_PASS_MIN_LEVEL + 1)
89 static struct init_tree_node {
90 enum fs_node_type type;
91 struct init_tree_node *children;
93 struct node_caps caps;
99 .type = FS_TYPE_NAMESPACE,
101 .children = (struct init_tree_node[]) {
102 ADD_PRIO(0, BY_PASS_MIN_LEVEL, 0,
103 FS_REQUIRED_CAPS(FS_CAP(flow_table_properties_nic_receive.flow_modify_en),
104 FS_CAP(flow_table_properties_nic_receive.modify_root),
105 FS_CAP(flow_table_properties_nic_receive.identified_miss_table_mode),
106 FS_CAP(flow_table_properties_nic_receive.flow_table_modify)),
107 ADD_NS(ADD_MULTIPLE_PRIO(MLX5_BY_PASS_NUM_PRIOS,
108 BY_PASS_PRIO_NUM_LEVELS))),
109 ADD_PRIO(0, KERNEL_MIN_LEVEL, 0, {},
110 ADD_NS(ADD_MULTIPLE_PRIO(1, 1),
111 ADD_MULTIPLE_PRIO(KERNEL_NIC_NUM_PRIOS,
112 KERNEL_NIC_PRIO_NUM_LEVELS))),
113 ADD_PRIO(0, BY_PASS_MIN_LEVEL, 0,
114 FS_REQUIRED_CAPS(FS_CAP(flow_table_properties_nic_receive.flow_modify_en),
115 FS_CAP(flow_table_properties_nic_receive.modify_root),
116 FS_CAP(flow_table_properties_nic_receive.identified_miss_table_mode),
117 FS_CAP(flow_table_properties_nic_receive.flow_table_modify)),
118 ADD_NS(ADD_MULTIPLE_PRIO(LEFTOVERS_NUM_PRIOS, LEFTOVERS_NUM_LEVELS))),
119 ADD_PRIO(0, ANCHOR_MIN_LEVEL, 0, {},
120 ADD_NS(ADD_MULTIPLE_PRIO(ANCHOR_NUM_PRIOS, ANCHOR_NUM_LEVELS))),
124 enum fs_i_mutex_lock_class {
125 FS_MUTEX_GRANDPARENT,
130 static void del_rule(struct fs_node *node);
131 static void del_flow_table(struct fs_node *node);
132 static void del_flow_group(struct fs_node *node);
133 static void del_fte(struct fs_node *node);
135 static void tree_init_node(struct fs_node *node,
136 unsigned int refcount,
137 void (*remove_func)(struct fs_node *))
139 atomic_set(&node->refcount, refcount);
140 INIT_LIST_HEAD(&node->list);
141 INIT_LIST_HEAD(&node->children);
142 mutex_init(&node->lock);
143 node->remove_func = remove_func;
146 static void tree_add_node(struct fs_node *node, struct fs_node *parent)
149 atomic_inc(&parent->refcount);
150 node->parent = parent;
152 /* Parent is the root */
156 node->root = parent->root;
159 static void tree_get_node(struct fs_node *node)
161 atomic_inc(&node->refcount);
164 static void nested_lock_ref_node(struct fs_node *node,
165 enum fs_i_mutex_lock_class class)
168 mutex_lock_nested(&node->lock, class);
169 atomic_inc(&node->refcount);
173 static void lock_ref_node(struct fs_node *node)
176 mutex_lock(&node->lock);
177 atomic_inc(&node->refcount);
181 static void unlock_ref_node(struct fs_node *node)
184 atomic_dec(&node->refcount);
185 mutex_unlock(&node->lock);
189 static void tree_put_node(struct fs_node *node)
191 struct fs_node *parent_node = node->parent;
193 lock_ref_node(parent_node);
194 if (atomic_dec_and_test(&node->refcount)) {
196 list_del_init(&node->list);
197 if (node->remove_func)
198 node->remove_func(node);
202 unlock_ref_node(parent_node);
203 if (!node && parent_node)
204 tree_put_node(parent_node);
207 static int tree_remove_node(struct fs_node *node)
209 if (atomic_read(&node->refcount) > 1) {
210 atomic_dec(&node->refcount);
217 static struct fs_prio *find_prio(struct mlx5_flow_namespace *ns,
220 struct fs_prio *iter_prio;
222 fs_for_each_prio(iter_prio, ns) {
223 if (iter_prio->prio == prio)
230 static bool masked_memcmp(void *mask, void *val1, void *val2, size_t size)
234 for (i = 0; i < size; i++, mask++, val1++, val2++)
235 if ((*((u8 *)val1) & (*(u8 *)mask)) !=
236 ((*(u8 *)val2) & (*(u8 *)mask)))
242 static bool compare_match_value(struct mlx5_flow_group_mask *mask,
243 void *fte_param1, void *fte_param2)
245 if (mask->match_criteria_enable &
246 1 << MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_OUTER_HEADERS) {
247 void *fte_match1 = MLX5_ADDR_OF(fte_match_param,
248 fte_param1, outer_headers);
249 void *fte_match2 = MLX5_ADDR_OF(fte_match_param,
250 fte_param2, outer_headers);
251 void *fte_mask = MLX5_ADDR_OF(fte_match_param,
252 mask->match_criteria, outer_headers);
254 if (!masked_memcmp(fte_mask, fte_match1, fte_match2,
255 MLX5_ST_SZ_BYTES(fte_match_set_lyr_2_4)))
259 if (mask->match_criteria_enable &
260 1 << MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_MISC_PARAMETERS) {
261 void *fte_match1 = MLX5_ADDR_OF(fte_match_param,
262 fte_param1, misc_parameters);
263 void *fte_match2 = MLX5_ADDR_OF(fte_match_param,
264 fte_param2, misc_parameters);
265 void *fte_mask = MLX5_ADDR_OF(fte_match_param,
266 mask->match_criteria, misc_parameters);
268 if (!masked_memcmp(fte_mask, fte_match1, fte_match2,
269 MLX5_ST_SZ_BYTES(fte_match_set_misc)))
273 if (mask->match_criteria_enable &
274 1 << MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_INNER_HEADERS) {
275 void *fte_match1 = MLX5_ADDR_OF(fte_match_param,
276 fte_param1, inner_headers);
277 void *fte_match2 = MLX5_ADDR_OF(fte_match_param,
278 fte_param2, inner_headers);
279 void *fte_mask = MLX5_ADDR_OF(fte_match_param,
280 mask->match_criteria, inner_headers);
282 if (!masked_memcmp(fte_mask, fte_match1, fte_match2,
283 MLX5_ST_SZ_BYTES(fte_match_set_lyr_2_4)))
289 static bool compare_match_criteria(u8 match_criteria_enable1,
290 u8 match_criteria_enable2,
291 void *mask1, void *mask2)
293 return match_criteria_enable1 == match_criteria_enable2 &&
294 !memcmp(mask1, mask2, MLX5_ST_SZ_BYTES(fte_match_param));
297 static struct mlx5_flow_root_namespace *find_root(struct fs_node *node)
299 struct fs_node *root;
300 struct mlx5_flow_namespace *ns;
304 if (WARN_ON(root->type != FS_TYPE_NAMESPACE)) {
305 pr_warn("mlx5: flow steering node is not in tree or garbaged\n");
309 ns = container_of(root, struct mlx5_flow_namespace, node);
310 return container_of(ns, struct mlx5_flow_root_namespace, ns);
313 static inline struct mlx5_core_dev *get_dev(struct fs_node *node)
315 struct mlx5_flow_root_namespace *root = find_root(node);
322 static void del_flow_table(struct fs_node *node)
324 struct mlx5_flow_table *ft;
325 struct mlx5_core_dev *dev;
326 struct fs_prio *prio;
329 fs_get_obj(ft, node);
330 dev = get_dev(&ft->node);
332 err = mlx5_cmd_destroy_flow_table(dev, ft);
334 pr_warn("flow steering can't destroy ft\n");
335 fs_get_obj(prio, ft->node.parent);
339 static void del_rule(struct fs_node *node)
341 struct mlx5_flow_rule *rule;
342 struct mlx5_flow_table *ft;
343 struct mlx5_flow_group *fg;
346 struct mlx5_core_dev *dev = get_dev(node);
347 int match_len = MLX5_ST_SZ_BYTES(fte_match_param);
350 match_value = mlx5_vzalloc(match_len);
352 pr_warn("failed to allocate inbox\n");
356 fs_get_obj(rule, node);
357 fs_get_obj(fte, rule->node.parent);
358 fs_get_obj(fg, fte->node.parent);
359 memcpy(match_value, fte->val, sizeof(fte->val));
360 fs_get_obj(ft, fg->node.parent);
361 list_del(&rule->node.list);
362 if (rule->sw_action == MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO) {
363 mutex_lock(&rule->dest_attr.ft->lock);
364 list_del(&rule->next_ft);
365 mutex_unlock(&rule->dest_attr.ft->lock);
367 if ((fte->action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) &&
369 err = mlx5_cmd_update_fte(dev, ft,
372 pr_warn("%s can't del rule fg id=%d fte_index=%d\n",
373 __func__, fg->id, fte->index);
378 static void del_fte(struct fs_node *node)
380 struct mlx5_flow_table *ft;
381 struct mlx5_flow_group *fg;
382 struct mlx5_core_dev *dev;
386 fs_get_obj(fte, node);
387 fs_get_obj(fg, fte->node.parent);
388 fs_get_obj(ft, fg->node.parent);
390 dev = get_dev(&ft->node);
391 err = mlx5_cmd_delete_fte(dev, ft,
394 pr_warn("flow steering can't delete fte in index %d of flow group id %d\n",
401 static void del_flow_group(struct fs_node *node)
403 struct mlx5_flow_group *fg;
404 struct mlx5_flow_table *ft;
405 struct mlx5_core_dev *dev;
407 fs_get_obj(fg, node);
408 fs_get_obj(ft, fg->node.parent);
409 dev = get_dev(&ft->node);
411 if (mlx5_cmd_destroy_flow_group(dev, ft, fg->id))
412 pr_warn("flow steering can't destroy fg %d of ft %d\n",
416 static struct fs_fte *alloc_fte(u8 action,
423 fte = kzalloc(sizeof(*fte), GFP_KERNEL);
425 return ERR_PTR(-ENOMEM);
427 memcpy(fte->val, match_value, sizeof(fte->val));
428 fte->node.type = FS_TYPE_FLOW_ENTRY;
429 fte->flow_tag = flow_tag;
431 fte->action = action;
436 static struct mlx5_flow_group *alloc_flow_group(u32 *create_fg_in)
438 struct mlx5_flow_group *fg;
439 void *match_criteria = MLX5_ADDR_OF(create_flow_group_in,
440 create_fg_in, match_criteria);
441 u8 match_criteria_enable = MLX5_GET(create_flow_group_in,
443 match_criteria_enable);
444 fg = kzalloc(sizeof(*fg), GFP_KERNEL);
446 return ERR_PTR(-ENOMEM);
448 fg->mask.match_criteria_enable = match_criteria_enable;
449 memcpy(&fg->mask.match_criteria, match_criteria,
450 sizeof(fg->mask.match_criteria));
451 fg->node.type = FS_TYPE_FLOW_GROUP;
452 fg->start_index = MLX5_GET(create_flow_group_in, create_fg_in,
454 fg->max_ftes = MLX5_GET(create_flow_group_in, create_fg_in,
455 end_flow_index) - fg->start_index + 1;
459 static struct mlx5_flow_table *alloc_flow_table(int level, int max_fte,
460 enum fs_flow_table_type table_type)
462 struct mlx5_flow_table *ft;
464 ft = kzalloc(sizeof(*ft), GFP_KERNEL);
469 ft->node.type = FS_TYPE_FLOW_TABLE;
470 ft->type = table_type;
471 ft->max_fte = max_fte;
472 INIT_LIST_HEAD(&ft->fwd_rules);
473 mutex_init(&ft->lock);
478 /* If reverse is false, then we search for the first flow table in the
479 * root sub-tree from start(closest from right), else we search for the
480 * last flow table in the root sub-tree till start(closest from left).
482 static struct mlx5_flow_table *find_closest_ft_recursive(struct fs_node *root,
483 struct list_head *start,
486 #define list_advance_entry(pos, reverse) \
487 ((reverse) ? list_prev_entry(pos, list) : list_next_entry(pos, list))
489 #define list_for_each_advance_continue(pos, head, reverse) \
490 for (pos = list_advance_entry(pos, reverse); \
491 &pos->list != (head); \
492 pos = list_advance_entry(pos, reverse))
494 struct fs_node *iter = list_entry(start, struct fs_node, list);
495 struct mlx5_flow_table *ft = NULL;
500 list_for_each_advance_continue(iter, &root->children, reverse) {
501 if (iter->type == FS_TYPE_FLOW_TABLE) {
502 fs_get_obj(ft, iter);
505 ft = find_closest_ft_recursive(iter, &iter->children, reverse);
513 /* If reverse if false then return the first flow table in next priority of
514 * prio in the tree, else return the last flow table in the previous priority
515 * of prio in the tree.
517 static struct mlx5_flow_table *find_closest_ft(struct fs_prio *prio, bool reverse)
519 struct mlx5_flow_table *ft = NULL;
520 struct fs_node *curr_node;
521 struct fs_node *parent;
523 parent = prio->node.parent;
524 curr_node = &prio->node;
525 while (!ft && parent) {
526 ft = find_closest_ft_recursive(parent, &curr_node->list, reverse);
528 parent = curr_node->parent;
533 /* Assuming all the tree is locked by mutex chain lock */
534 static struct mlx5_flow_table *find_next_chained_ft(struct fs_prio *prio)
536 return find_closest_ft(prio, false);
539 /* Assuming all the tree is locked by mutex chain lock */
540 static struct mlx5_flow_table *find_prev_chained_ft(struct fs_prio *prio)
542 return find_closest_ft(prio, true);
545 static int connect_fts_in_prio(struct mlx5_core_dev *dev,
546 struct fs_prio *prio,
547 struct mlx5_flow_table *ft)
549 struct mlx5_flow_table *iter;
553 fs_for_each_ft(iter, prio) {
555 err = mlx5_cmd_modify_flow_table(dev,
559 mlx5_core_warn(dev, "Failed to modify flow table %d\n",
561 /* The driver is out of sync with the FW */
570 /* Connect flow tables from previous priority of prio to ft */
571 static int connect_prev_fts(struct mlx5_core_dev *dev,
572 struct mlx5_flow_table *ft,
573 struct fs_prio *prio)
575 struct mlx5_flow_table *prev_ft;
577 prev_ft = find_prev_chained_ft(prio);
579 struct fs_prio *prev_prio;
581 fs_get_obj(prev_prio, prev_ft->node.parent);
582 return connect_fts_in_prio(dev, prev_prio, ft);
587 static int update_root_ft_create(struct mlx5_flow_table *ft, struct fs_prio
590 struct mlx5_flow_root_namespace *root = find_root(&prio->node);
591 int min_level = INT_MAX;
595 min_level = root->root_ft->level;
597 if (ft->level >= min_level)
600 err = mlx5_cmd_update_root_ft(root->dev, ft);
602 mlx5_core_warn(root->dev, "Update root flow table of id=%u failed\n",
610 int mlx5_modify_rule_destination(struct mlx5_flow_rule *rule,
611 struct mlx5_flow_destination *dest)
613 struct mlx5_flow_table *ft;
614 struct mlx5_flow_group *fg;
618 fs_get_obj(fte, rule->node.parent);
619 if (!(fte->action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST))
621 lock_ref_node(&fte->node);
622 fs_get_obj(fg, fte->node.parent);
623 fs_get_obj(ft, fg->node.parent);
625 memcpy(&rule->dest_attr, dest, sizeof(*dest));
626 err = mlx5_cmd_update_fte(get_dev(&ft->node),
628 unlock_ref_node(&fte->node);
633 /* Modify/set FWD rules that point on old_next_ft to point on new_next_ft */
634 static int connect_fwd_rules(struct mlx5_core_dev *dev,
635 struct mlx5_flow_table *new_next_ft,
636 struct mlx5_flow_table *old_next_ft)
638 struct mlx5_flow_destination dest;
639 struct mlx5_flow_rule *iter;
642 /* new_next_ft and old_next_ft could be NULL only
643 * when we create/destroy the anchor flow table.
645 if (!new_next_ft || !old_next_ft)
648 dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
649 dest.ft = new_next_ft;
651 mutex_lock(&old_next_ft->lock);
652 list_splice_init(&old_next_ft->fwd_rules, &new_next_ft->fwd_rules);
653 mutex_unlock(&old_next_ft->lock);
654 list_for_each_entry(iter, &new_next_ft->fwd_rules, next_ft) {
655 err = mlx5_modify_rule_destination(iter, &dest);
657 pr_err("mlx5_core: failed to modify rule to point on flow table %d\n",
663 static int connect_flow_table(struct mlx5_core_dev *dev, struct mlx5_flow_table *ft,
664 struct fs_prio *prio)
666 struct mlx5_flow_table *next_ft;
669 /* Connect_prev_fts and update_root_ft_create are mutually exclusive */
671 if (list_empty(&prio->node.children)) {
672 err = connect_prev_fts(dev, ft, prio);
676 next_ft = find_next_chained_ft(prio);
677 err = connect_fwd_rules(dev, ft, next_ft);
682 if (MLX5_CAP_FLOWTABLE(dev,
683 flow_table_properties_nic_receive.modify_root))
684 err = update_root_ft_create(ft, prio);
688 static void list_add_flow_table(struct mlx5_flow_table *ft,
689 struct fs_prio *prio)
691 struct list_head *prev = &prio->node.children;
692 struct mlx5_flow_table *iter;
694 fs_for_each_ft(iter, prio) {
695 if (iter->level > ft->level)
697 prev = &iter->node.list;
699 list_add(&ft->node.list, prev);
702 struct mlx5_flow_table *mlx5_create_flow_table(struct mlx5_flow_namespace *ns,
703 int prio, int max_fte,
706 struct mlx5_flow_table *next_ft = NULL;
707 struct mlx5_flow_table *ft;
710 struct mlx5_flow_root_namespace *root =
711 find_root(&ns->node);
712 struct fs_prio *fs_prio = NULL;
715 pr_err("mlx5: flow steering failed to find root of namespace\n");
716 return ERR_PTR(-ENODEV);
719 mutex_lock(&root->chain_lock);
720 fs_prio = find_prio(ns, prio);
725 if (level >= fs_prio->num_levels) {
729 /* The level is related to the
730 * priority level range.
732 level += fs_prio->start_level;
733 ft = alloc_flow_table(level,
734 roundup_pow_of_two(max_fte),
741 tree_init_node(&ft->node, 1, del_flow_table);
742 log_table_sz = ilog2(ft->max_fte);
743 next_ft = find_next_chained_ft(fs_prio);
744 err = mlx5_cmd_create_flow_table(root->dev, ft->type, ft->level,
745 log_table_sz, next_ft, &ft->id);
749 err = connect_flow_table(root->dev, ft, fs_prio);
752 lock_ref_node(&fs_prio->node);
753 tree_add_node(&ft->node, &fs_prio->node);
754 list_add_flow_table(ft, fs_prio);
756 unlock_ref_node(&fs_prio->node);
757 mutex_unlock(&root->chain_lock);
760 mlx5_cmd_destroy_flow_table(root->dev, ft);
764 mutex_unlock(&root->chain_lock);
768 struct mlx5_flow_table *mlx5_create_auto_grouped_flow_table(struct mlx5_flow_namespace *ns,
770 int num_flow_table_entries,
774 struct mlx5_flow_table *ft;
776 if (max_num_groups > num_flow_table_entries)
777 return ERR_PTR(-EINVAL);
779 ft = mlx5_create_flow_table(ns, prio, num_flow_table_entries, level);
783 ft->autogroup.active = true;
784 ft->autogroup.required_groups = max_num_groups;
788 EXPORT_SYMBOL(mlx5_create_auto_grouped_flow_table);
790 /* Flow table should be locked */
791 static struct mlx5_flow_group *create_flow_group_common(struct mlx5_flow_table *ft,
797 struct mlx5_flow_group *fg;
798 struct mlx5_core_dev *dev = get_dev(&ft->node);
802 return ERR_PTR(-ENODEV);
804 fg = alloc_flow_group(fg_in);
808 err = mlx5_cmd_create_flow_group(dev, ft, fg_in, &fg->id);
814 if (ft->autogroup.active)
815 ft->autogroup.num_groups++;
816 /* Add node to tree */
817 tree_init_node(&fg->node, !is_auto_fg, del_flow_group);
818 tree_add_node(&fg->node, &ft->node);
819 /* Add node to group list */
820 list_add(&fg->node.list, ft->node.children.prev);
825 struct mlx5_flow_group *mlx5_create_flow_group(struct mlx5_flow_table *ft,
828 struct mlx5_flow_group *fg;
830 if (ft->autogroup.active)
831 return ERR_PTR(-EPERM);
833 lock_ref_node(&ft->node);
834 fg = create_flow_group_common(ft, fg_in, &ft->node.children, false);
835 unlock_ref_node(&ft->node);
840 static struct mlx5_flow_rule *alloc_rule(struct mlx5_flow_destination *dest)
842 struct mlx5_flow_rule *rule;
844 rule = kzalloc(sizeof(*rule), GFP_KERNEL);
848 INIT_LIST_HEAD(&rule->next_ft);
849 rule->node.type = FS_TYPE_FLOW_DEST;
851 memcpy(&rule->dest_attr, dest, sizeof(*dest));
856 /* fte should not be deleted while calling this function */
857 static struct mlx5_flow_rule *add_rule_fte(struct fs_fte *fte,
858 struct mlx5_flow_group *fg,
859 struct mlx5_flow_destination *dest)
861 struct mlx5_flow_table *ft;
862 struct mlx5_flow_rule *rule;
865 rule = alloc_rule(dest);
867 return ERR_PTR(-ENOMEM);
869 fs_get_obj(ft, fg->node.parent);
870 /* Add dest to dests list- we need flow tables to be in the
871 * end of the list for forward to next prio rules.
873 tree_init_node(&rule->node, 1, del_rule);
874 if (dest && dest->type != MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE)
875 list_add(&rule->node.list, &fte->node.children);
877 list_add_tail(&rule->node.list, &fte->node.children);
880 if (fte->dests_size == 1 || !dest)
881 err = mlx5_cmd_create_fte(get_dev(&ft->node),
884 err = mlx5_cmd_update_fte(get_dev(&ft->node),
889 fte->status |= FS_FTE_STATUS_EXISTING;
894 list_del(&rule->node.list);
901 /* Assumed fg is locked */
902 static unsigned int get_free_fte_index(struct mlx5_flow_group *fg,
903 struct list_head **prev)
906 unsigned int start = fg->start_index;
909 *prev = &fg->node.children;
911 /* assumed list is sorted by index */
912 fs_for_each_fte(fte, fg) {
913 if (fte->index != start)
917 *prev = &fte->node.list;
923 /* prev is output, prev->next = new_fte */
924 static struct fs_fte *create_fte(struct mlx5_flow_group *fg,
928 struct list_head **prev)
933 index = get_free_fte_index(fg, prev);
934 fte = alloc_fte(action, flow_tag, match_value, index);
941 static struct mlx5_flow_group *create_autogroup(struct mlx5_flow_table *ft,
942 u8 match_criteria_enable,
945 int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
946 struct list_head *prev = &ft->node.children;
947 unsigned int candidate_index = 0;
948 struct mlx5_flow_group *fg;
949 void *match_criteria_addr;
950 unsigned int group_size = 0;
953 if (!ft->autogroup.active)
954 return ERR_PTR(-ENOENT);
956 in = mlx5_vzalloc(inlen);
958 return ERR_PTR(-ENOMEM);
960 if (ft->autogroup.num_groups < ft->autogroup.required_groups)
961 /* We save place for flow groups in addition to max types */
962 group_size = ft->max_fte / (ft->autogroup.required_groups + 1);
964 /* ft->max_fte == ft->autogroup.max_types */
968 /* sorted by start_index */
969 fs_for_each_fg(fg, ft) {
970 if (candidate_index + group_size > fg->start_index)
971 candidate_index = fg->start_index + fg->max_ftes;
974 prev = &fg->node.list;
977 if (candidate_index + group_size > ft->max_fte) {
978 fg = ERR_PTR(-ENOSPC);
982 MLX5_SET(create_flow_group_in, in, match_criteria_enable,
983 match_criteria_enable);
984 MLX5_SET(create_flow_group_in, in, start_flow_index, candidate_index);
985 MLX5_SET(create_flow_group_in, in, end_flow_index, candidate_index +
987 match_criteria_addr = MLX5_ADDR_OF(create_flow_group_in,
989 memcpy(match_criteria_addr, match_criteria,
990 MLX5_ST_SZ_BYTES(fte_match_param));
992 fg = create_flow_group_common(ft, in, prev, true);
998 static struct mlx5_flow_rule *find_flow_rule(struct fs_fte *fte,
999 struct mlx5_flow_destination *dest)
1001 struct mlx5_flow_rule *rule;
1003 list_for_each_entry(rule, &fte->node.children, node.list) {
1004 if (rule->dest_attr.type == dest->type) {
1005 if ((dest->type == MLX5_FLOW_DESTINATION_TYPE_VPORT &&
1006 dest->vport_num == rule->dest_attr.vport_num) ||
1007 (dest->type == MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE &&
1008 dest->ft == rule->dest_attr.ft) ||
1009 (dest->type == MLX5_FLOW_DESTINATION_TYPE_TIR &&
1010 dest->tir_num == rule->dest_attr.tir_num))
1017 static struct mlx5_flow_rule *add_rule_fg(struct mlx5_flow_group *fg,
1021 struct mlx5_flow_destination *dest)
1024 struct mlx5_flow_rule *rule;
1025 struct mlx5_flow_table *ft;
1026 struct list_head *prev;
1028 nested_lock_ref_node(&fg->node, FS_MUTEX_PARENT);
1029 fs_for_each_fte(fte, fg) {
1030 nested_lock_ref_node(&fte->node, FS_MUTEX_CHILD);
1031 if (compare_match_value(&fg->mask, match_value, &fte->val) &&
1032 action == fte->action && flow_tag == fte->flow_tag) {
1033 rule = find_flow_rule(fte, dest);
1035 atomic_inc(&rule->node.refcount);
1036 unlock_ref_node(&fte->node);
1037 unlock_ref_node(&fg->node);
1040 rule = add_rule_fte(fte, fg, dest);
1041 unlock_ref_node(&fte->node);
1047 unlock_ref_node(&fte->node);
1049 fs_get_obj(ft, fg->node.parent);
1050 if (fg->num_ftes >= fg->max_ftes) {
1051 rule = ERR_PTR(-ENOSPC);
1055 fte = create_fte(fg, match_value, action, flow_tag, &prev);
1060 tree_init_node(&fte->node, 0, del_fte);
1061 rule = add_rule_fte(fte, fg, dest);
1069 tree_add_node(&fte->node, &fg->node);
1070 list_add(&fte->node.list, prev);
1072 tree_add_node(&rule->node, &fte->node);
1074 unlock_ref_node(&fg->node);
1078 static bool dest_is_valid(struct mlx5_flow_destination *dest,
1080 struct mlx5_flow_table *ft)
1082 if (!(action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST))
1085 if (!dest || ((dest->type ==
1086 MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE) &&
1087 (dest->ft->level <= ft->level)))
1092 static struct mlx5_flow_rule *
1093 _mlx5_add_flow_rule(struct mlx5_flow_table *ft,
1094 u8 match_criteria_enable,
1095 u32 *match_criteria,
1099 struct mlx5_flow_destination *dest)
1101 struct mlx5_flow_group *g;
1102 struct mlx5_flow_rule *rule;
1104 if (!dest_is_valid(dest, action, ft))
1105 return ERR_PTR(-EINVAL);
1107 nested_lock_ref_node(&ft->node, FS_MUTEX_GRANDPARENT);
1108 fs_for_each_fg(g, ft)
1109 if (compare_match_criteria(g->mask.match_criteria_enable,
1110 match_criteria_enable,
1111 g->mask.match_criteria,
1113 rule = add_rule_fg(g, match_value,
1114 action, flow_tag, dest);
1115 if (!IS_ERR(rule) || PTR_ERR(rule) != -ENOSPC)
1119 g = create_autogroup(ft, match_criteria_enable, match_criteria);
1125 rule = add_rule_fg(g, match_value,
1126 action, flow_tag, dest);
1128 /* Remove assumes refcount > 0 and autogroup creates a group
1129 * with a refcount = 0.
1131 unlock_ref_node(&ft->node);
1132 tree_get_node(&g->node);
1133 tree_remove_node(&g->node);
1137 unlock_ref_node(&ft->node);
1141 static bool fwd_next_prio_supported(struct mlx5_flow_table *ft)
1143 return ((ft->type == FS_FT_NIC_RX) &&
1144 (MLX5_CAP_FLOWTABLE(get_dev(&ft->node), nic_rx_multi_path_tirs)));
1147 struct mlx5_flow_rule *
1148 mlx5_add_flow_rule(struct mlx5_flow_table *ft,
1149 u8 match_criteria_enable,
1150 u32 *match_criteria,
1154 struct mlx5_flow_destination *dest)
1156 struct mlx5_flow_root_namespace *root = find_root(&ft->node);
1157 struct mlx5_flow_destination gen_dest;
1158 struct mlx5_flow_table *next_ft = NULL;
1159 struct mlx5_flow_rule *rule = NULL;
1160 u32 sw_action = action;
1161 struct fs_prio *prio;
1163 fs_get_obj(prio, ft->node.parent);
1164 if (action == MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO) {
1165 if (!fwd_next_prio_supported(ft))
1166 return ERR_PTR(-EOPNOTSUPP);
1168 return ERR_PTR(-EINVAL);
1169 mutex_lock(&root->chain_lock);
1170 next_ft = find_next_chained_ft(prio);
1172 gen_dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
1173 gen_dest.ft = next_ft;
1175 action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
1177 mutex_unlock(&root->chain_lock);
1178 return ERR_PTR(-EOPNOTSUPP);
1182 rule = _mlx5_add_flow_rule(ft, match_criteria_enable, match_criteria,
1183 match_value, action, flow_tag, dest);
1185 if (sw_action == MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO) {
1186 if (!IS_ERR_OR_NULL(rule) &&
1187 (list_empty(&rule->next_ft))) {
1188 mutex_lock(&next_ft->lock);
1189 list_add(&rule->next_ft, &next_ft->fwd_rules);
1190 mutex_unlock(&next_ft->lock);
1191 rule->sw_action = MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO;
1193 mutex_unlock(&root->chain_lock);
1197 EXPORT_SYMBOL(mlx5_add_flow_rule);
1199 void mlx5_del_flow_rule(struct mlx5_flow_rule *rule)
1201 tree_remove_node(&rule->node);
1203 EXPORT_SYMBOL(mlx5_del_flow_rule);
1205 /* Assuming prio->node.children(flow tables) is sorted by level */
1206 static struct mlx5_flow_table *find_next_ft(struct mlx5_flow_table *ft)
1208 struct fs_prio *prio;
1210 fs_get_obj(prio, ft->node.parent);
1212 if (!list_is_last(&ft->node.list, &prio->node.children))
1213 return list_next_entry(ft, node.list);
1214 return find_next_chained_ft(prio);
1217 static int update_root_ft_destroy(struct mlx5_flow_table *ft)
1219 struct mlx5_flow_root_namespace *root = find_root(&ft->node);
1220 struct mlx5_flow_table *new_root_ft = NULL;
1222 if (root->root_ft != ft)
1225 new_root_ft = find_next_ft(ft);
1227 int err = mlx5_cmd_update_root_ft(root->dev, new_root_ft);
1230 mlx5_core_warn(root->dev, "Update root flow table of id=%u failed\n",
1234 root->root_ft = new_root_ft;
1239 /* Connect flow table from previous priority to
1240 * the next flow table.
1242 static int disconnect_flow_table(struct mlx5_flow_table *ft)
1244 struct mlx5_core_dev *dev = get_dev(&ft->node);
1245 struct mlx5_flow_table *next_ft;
1246 struct fs_prio *prio;
1249 err = update_root_ft_destroy(ft);
1253 fs_get_obj(prio, ft->node.parent);
1254 if (!(list_first_entry(&prio->node.children,
1255 struct mlx5_flow_table,
1259 next_ft = find_next_chained_ft(prio);
1260 err = connect_fwd_rules(dev, next_ft, ft);
1264 err = connect_prev_fts(dev, next_ft, prio);
1266 mlx5_core_warn(dev, "Failed to disconnect flow table %d\n",
1271 int mlx5_destroy_flow_table(struct mlx5_flow_table *ft)
1273 struct mlx5_flow_root_namespace *root = find_root(&ft->node);
1276 mutex_lock(&root->chain_lock);
1277 err = disconnect_flow_table(ft);
1279 mutex_unlock(&root->chain_lock);
1282 if (tree_remove_node(&ft->node))
1283 mlx5_core_warn(get_dev(&ft->node), "Flow table %d wasn't destroyed, refcount > 1\n",
1285 mutex_unlock(&root->chain_lock);
1289 EXPORT_SYMBOL(mlx5_destroy_flow_table);
1291 void mlx5_destroy_flow_group(struct mlx5_flow_group *fg)
1293 if (tree_remove_node(&fg->node))
1294 mlx5_core_warn(get_dev(&fg->node), "Flow group %d wasn't destroyed, refcount > 1\n",
1298 struct mlx5_flow_namespace *mlx5_get_flow_namespace(struct mlx5_core_dev *dev,
1299 enum mlx5_flow_namespace_type type)
1301 struct mlx5_flow_root_namespace *root_ns = dev->priv.root_ns;
1303 struct fs_prio *fs_prio;
1304 struct mlx5_flow_namespace *ns;
1310 case MLX5_FLOW_NAMESPACE_BYPASS:
1311 case MLX5_FLOW_NAMESPACE_KERNEL:
1312 case MLX5_FLOW_NAMESPACE_LEFTOVERS:
1313 case MLX5_FLOW_NAMESPACE_ANCHOR:
1316 case MLX5_FLOW_NAMESPACE_FDB:
1317 if (dev->priv.fdb_root_ns)
1318 return &dev->priv.fdb_root_ns->ns;
1325 fs_prio = find_prio(&root_ns->ns, prio);
1329 ns = list_first_entry(&fs_prio->node.children,
1335 EXPORT_SYMBOL(mlx5_get_flow_namespace);
1337 static struct fs_prio *fs_create_prio(struct mlx5_flow_namespace *ns,
1338 unsigned int prio, int num_levels)
1340 struct fs_prio *fs_prio;
1342 fs_prio = kzalloc(sizeof(*fs_prio), GFP_KERNEL);
1344 return ERR_PTR(-ENOMEM);
1346 fs_prio->node.type = FS_TYPE_PRIO;
1347 tree_init_node(&fs_prio->node, 1, NULL);
1348 tree_add_node(&fs_prio->node, &ns->node);
1349 fs_prio->num_levels = num_levels;
1350 fs_prio->prio = prio;
1351 list_add_tail(&fs_prio->node.list, &ns->node.children);
1356 static struct mlx5_flow_namespace *fs_init_namespace(struct mlx5_flow_namespace
1359 ns->node.type = FS_TYPE_NAMESPACE;
1364 static struct mlx5_flow_namespace *fs_create_namespace(struct fs_prio *prio)
1366 struct mlx5_flow_namespace *ns;
1368 ns = kzalloc(sizeof(*ns), GFP_KERNEL);
1370 return ERR_PTR(-ENOMEM);
1372 fs_init_namespace(ns);
1373 tree_init_node(&ns->node, 1, NULL);
1374 tree_add_node(&ns->node, &prio->node);
1375 list_add_tail(&ns->node.list, &prio->node.children);
1380 static int create_leaf_prios(struct mlx5_flow_namespace *ns, int prio,
1381 struct init_tree_node *prio_metadata)
1383 struct fs_prio *fs_prio;
1386 for (i = 0; i < prio_metadata->num_leaf_prios; i++) {
1387 fs_prio = fs_create_prio(ns, prio++, prio_metadata->num_levels);
1388 if (IS_ERR(fs_prio))
1389 return PTR_ERR(fs_prio);
1394 #define FLOW_TABLE_BIT_SZ 1
1395 #define GET_FLOW_TABLE_CAP(dev, offset) \
1396 ((be32_to_cpu(*((__be32 *)(dev->hca_caps_cur[MLX5_CAP_FLOW_TABLE]) + \
1398 (32 - FLOW_TABLE_BIT_SZ - (offset & 0x1f))) & FLOW_TABLE_BIT_SZ)
1399 static bool has_required_caps(struct mlx5_core_dev *dev, struct node_caps *caps)
1403 for (i = 0; i < caps->arr_sz; i++) {
1404 if (!GET_FLOW_TABLE_CAP(dev, caps->caps[i]))
1410 static int init_root_tree_recursive(struct mlx5_core_dev *dev,
1411 struct init_tree_node *init_node,
1412 struct fs_node *fs_parent_node,
1413 struct init_tree_node *init_parent_node,
1416 int max_ft_level = MLX5_CAP_FLOWTABLE(dev,
1417 flow_table_properties_nic_receive.
1419 struct mlx5_flow_namespace *fs_ns;
1420 struct fs_prio *fs_prio;
1421 struct fs_node *base;
1425 if (init_node->type == FS_TYPE_PRIO) {
1426 if ((init_node->min_ft_level > max_ft_level) ||
1427 !has_required_caps(dev, &init_node->caps))
1430 fs_get_obj(fs_ns, fs_parent_node);
1431 if (init_node->num_leaf_prios)
1432 return create_leaf_prios(fs_ns, prio, init_node);
1433 fs_prio = fs_create_prio(fs_ns, prio, init_node->num_levels);
1434 if (IS_ERR(fs_prio))
1435 return PTR_ERR(fs_prio);
1436 base = &fs_prio->node;
1437 } else if (init_node->type == FS_TYPE_NAMESPACE) {
1438 fs_get_obj(fs_prio, fs_parent_node);
1439 fs_ns = fs_create_namespace(fs_prio);
1441 return PTR_ERR(fs_ns);
1442 base = &fs_ns->node;
1447 for (i = 0; i < init_node->ar_size; i++) {
1448 err = init_root_tree_recursive(dev, &init_node->children[i],
1449 base, init_node, prio);
1452 if (init_node->children[i].type == FS_TYPE_PRIO &&
1453 init_node->children[i].num_leaf_prios) {
1454 prio += init_node->children[i].num_leaf_prios;
1461 static int init_root_tree(struct mlx5_core_dev *dev,
1462 struct init_tree_node *init_node,
1463 struct fs_node *fs_parent_node)
1466 struct mlx5_flow_namespace *fs_ns;
1469 fs_get_obj(fs_ns, fs_parent_node);
1470 for (i = 0; i < init_node->ar_size; i++) {
1471 err = init_root_tree_recursive(dev, &init_node->children[i],
1480 static struct mlx5_flow_root_namespace *create_root_ns(struct mlx5_core_dev *dev,
1481 enum fs_flow_table_type
1484 struct mlx5_flow_root_namespace *root_ns;
1485 struct mlx5_flow_namespace *ns;
1487 /* Create the root namespace */
1488 root_ns = mlx5_vzalloc(sizeof(*root_ns));
1493 root_ns->table_type = table_type;
1496 fs_init_namespace(ns);
1497 mutex_init(&root_ns->chain_lock);
1498 tree_init_node(&ns->node, 1, NULL);
1499 tree_add_node(&ns->node, NULL);
1504 static void set_prio_attrs_in_prio(struct fs_prio *prio, int acc_level);
1506 static int set_prio_attrs_in_ns(struct mlx5_flow_namespace *ns, int acc_level)
1508 struct fs_prio *prio;
1510 fs_for_each_prio(prio, ns) {
1511 /* This updates prio start_level and num_levels */
1512 set_prio_attrs_in_prio(prio, acc_level);
1513 acc_level += prio->num_levels;
1518 static void set_prio_attrs_in_prio(struct fs_prio *prio, int acc_level)
1520 struct mlx5_flow_namespace *ns;
1521 int acc_level_ns = acc_level;
1523 prio->start_level = acc_level;
1524 fs_for_each_ns(ns, prio)
1525 /* This updates start_level and num_levels of ns's priority descendants */
1526 acc_level_ns = set_prio_attrs_in_ns(ns, acc_level);
1527 if (!prio->num_levels)
1528 prio->num_levels = acc_level_ns - prio->start_level;
1529 WARN_ON(prio->num_levels < acc_level_ns - prio->start_level);
1532 static void set_prio_attrs(struct mlx5_flow_root_namespace *root_ns)
1534 struct mlx5_flow_namespace *ns = &root_ns->ns;
1535 struct fs_prio *prio;
1536 int start_level = 0;
1538 fs_for_each_prio(prio, ns) {
1539 set_prio_attrs_in_prio(prio, start_level);
1540 start_level += prio->num_levels;
1544 #define ANCHOR_PRIO 0
1545 #define ANCHOR_SIZE 1
1546 #define ANCHOR_LEVEL 0
1547 static int create_anchor_flow_table(struct mlx5_core_dev
1550 struct mlx5_flow_namespace *ns = NULL;
1551 struct mlx5_flow_table *ft;
1553 ns = mlx5_get_flow_namespace(dev, MLX5_FLOW_NAMESPACE_ANCHOR);
1556 ft = mlx5_create_flow_table(ns, ANCHOR_PRIO, ANCHOR_SIZE, ANCHOR_LEVEL);
1558 mlx5_core_err(dev, "Failed to create last anchor flow table");
1564 static int init_root_ns(struct mlx5_core_dev *dev)
1567 dev->priv.root_ns = create_root_ns(dev, FS_FT_NIC_RX);
1568 if (IS_ERR_OR_NULL(dev->priv.root_ns))
1571 if (init_root_tree(dev, &root_fs, &dev->priv.root_ns->ns.node))
1574 set_prio_attrs(dev->priv.root_ns);
1576 if (create_anchor_flow_table(dev))
1582 mlx5_cleanup_fs(dev);
1586 static void cleanup_single_prio_root_ns(struct mlx5_core_dev *dev,
1587 struct mlx5_flow_root_namespace *root_ns)
1589 struct fs_node *prio;
1594 if (!list_empty(&root_ns->ns.node.children)) {
1595 prio = list_first_entry(&root_ns->ns.node.children,
1598 if (tree_remove_node(prio))
1600 "Flow steering priority wasn't destroyed, refcount > 1\n");
1602 if (tree_remove_node(&root_ns->ns.node))
1604 "Flow steering namespace wasn't destroyed, refcount > 1\n");
1608 static void destroy_flow_tables(struct fs_prio *prio)
1610 struct mlx5_flow_table *iter;
1611 struct mlx5_flow_table *tmp;
1613 fs_for_each_ft_safe(iter, tmp, prio)
1614 mlx5_destroy_flow_table(iter);
1617 static void cleanup_root_ns(struct mlx5_core_dev *dev)
1619 struct mlx5_flow_root_namespace *root_ns = dev->priv.root_ns;
1620 struct fs_prio *iter_prio;
1622 if (!MLX5_CAP_GEN(dev, nic_flow_table))
1629 fs_for_each_prio(iter_prio, &root_ns->ns) {
1630 struct fs_node *node;
1631 struct mlx5_flow_namespace *iter_ns;
1633 fs_for_each_ns_or_ft(node, iter_prio) {
1634 if (node->type == FS_TYPE_FLOW_TABLE)
1636 fs_get_obj(iter_ns, node);
1637 while (!list_empty(&iter_ns->node.children)) {
1638 struct fs_prio *obj_iter_prio2;
1639 struct fs_node *iter_prio2 =
1640 list_first_entry(&iter_ns->node.children,
1644 fs_get_obj(obj_iter_prio2, iter_prio2);
1645 destroy_flow_tables(obj_iter_prio2);
1646 if (tree_remove_node(iter_prio2)) {
1648 "Priority %d wasn't destroyed, refcount > 1\n",
1649 obj_iter_prio2->prio);
1657 fs_for_each_prio(iter_prio, &root_ns->ns) {
1658 while (!list_empty(&iter_prio->node.children)) {
1659 struct fs_node *iter_ns =
1660 list_first_entry(&iter_prio->node.children,
1663 if (tree_remove_node(iter_ns)) {
1665 "Namespace wasn't destroyed, refcount > 1\n");
1672 while (!list_empty(&root_ns->ns.node.children)) {
1673 struct fs_prio *obj_prio_node;
1674 struct fs_node *prio_node =
1675 list_first_entry(&root_ns->ns.node.children,
1679 fs_get_obj(obj_prio_node, prio_node);
1680 if (tree_remove_node(prio_node)) {
1682 "Priority %d wasn't destroyed, refcount > 1\n",
1683 obj_prio_node->prio);
1688 if (tree_remove_node(&root_ns->ns.node)) {
1690 "root namespace wasn't destroyed, refcount > 1\n");
1694 dev->priv.root_ns = NULL;
1697 void mlx5_cleanup_fs(struct mlx5_core_dev *dev)
1699 cleanup_root_ns(dev);
1700 cleanup_single_prio_root_ns(dev, dev->priv.fdb_root_ns);
1703 static int init_fdb_root_ns(struct mlx5_core_dev *dev)
1705 struct fs_prio *prio;
1707 dev->priv.fdb_root_ns = create_root_ns(dev, FS_FT_FDB);
1708 if (!dev->priv.fdb_root_ns)
1711 /* Create single prio */
1712 prio = fs_create_prio(&dev->priv.fdb_root_ns->ns, 0, 1);
1714 cleanup_single_prio_root_ns(dev, dev->priv.fdb_root_ns);
1715 return PTR_ERR(prio);
1721 int mlx5_init_fs(struct mlx5_core_dev *dev)
1725 if (MLX5_CAP_GEN(dev, nic_flow_table)) {
1726 err = init_root_ns(dev);
1730 if (MLX5_CAP_GEN(dev, eswitch_flow_table)) {
1731 err = init_fdb_root_ns(dev);
1733 cleanup_root_ns(dev);