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 /* Vlan, mac, ttc, aRFS */
78 #define KERNEL_NIC_PRIO_NUM_LEVELS 4
79 #define KERNEL_NIC_NUM_PRIOS 1
80 /* One more level for tc */
81 #define KERNEL_MIN_LEVEL (KERNEL_NIC_PRIO_NUM_LEVELS + 1)
83 #define ANCHOR_NUM_LEVELS 1
84 #define ANCHOR_NUM_PRIOS 1
85 #define ANCHOR_MIN_LEVEL (BY_PASS_MIN_LEVEL + 1)
90 static struct init_tree_node {
91 enum fs_node_type type;
92 struct init_tree_node *children;
94 struct node_caps caps;
100 .type = FS_TYPE_NAMESPACE,
102 .children = (struct init_tree_node[]) {
103 ADD_PRIO(0, BY_PASS_MIN_LEVEL, 0,
104 FS_REQUIRED_CAPS(FS_CAP(flow_table_properties_nic_receive.flow_modify_en),
105 FS_CAP(flow_table_properties_nic_receive.modify_root),
106 FS_CAP(flow_table_properties_nic_receive.identified_miss_table_mode),
107 FS_CAP(flow_table_properties_nic_receive.flow_table_modify)),
108 ADD_NS(ADD_MULTIPLE_PRIO(MLX5_BY_PASS_NUM_PRIOS,
109 BY_PASS_PRIO_NUM_LEVELS))),
110 ADD_PRIO(0, KERNEL_MIN_LEVEL, 0, {},
111 ADD_NS(ADD_MULTIPLE_PRIO(1, 1),
112 ADD_MULTIPLE_PRIO(KERNEL_NIC_NUM_PRIOS,
113 KERNEL_NIC_PRIO_NUM_LEVELS))),
114 ADD_PRIO(0, BY_PASS_MIN_LEVEL, 0,
115 FS_REQUIRED_CAPS(FS_CAP(flow_table_properties_nic_receive.flow_modify_en),
116 FS_CAP(flow_table_properties_nic_receive.modify_root),
117 FS_CAP(flow_table_properties_nic_receive.identified_miss_table_mode),
118 FS_CAP(flow_table_properties_nic_receive.flow_table_modify)),
119 ADD_NS(ADD_MULTIPLE_PRIO(LEFTOVERS_NUM_PRIOS, LEFTOVERS_NUM_LEVELS))),
120 ADD_PRIO(0, ANCHOR_MIN_LEVEL, 0, {},
121 ADD_NS(ADD_MULTIPLE_PRIO(ANCHOR_NUM_PRIOS, ANCHOR_NUM_LEVELS))),
125 enum fs_i_mutex_lock_class {
126 FS_MUTEX_GRANDPARENT,
131 static void del_rule(struct fs_node *node);
132 static void del_flow_table(struct fs_node *node);
133 static void del_flow_group(struct fs_node *node);
134 static void del_fte(struct fs_node *node);
136 static void tree_init_node(struct fs_node *node,
137 unsigned int refcount,
138 void (*remove_func)(struct fs_node *))
140 atomic_set(&node->refcount, refcount);
141 INIT_LIST_HEAD(&node->list);
142 INIT_LIST_HEAD(&node->children);
143 mutex_init(&node->lock);
144 node->remove_func = remove_func;
147 static void tree_add_node(struct fs_node *node, struct fs_node *parent)
150 atomic_inc(&parent->refcount);
151 node->parent = parent;
153 /* Parent is the root */
157 node->root = parent->root;
160 static void tree_get_node(struct fs_node *node)
162 atomic_inc(&node->refcount);
165 static void nested_lock_ref_node(struct fs_node *node,
166 enum fs_i_mutex_lock_class class)
169 mutex_lock_nested(&node->lock, class);
170 atomic_inc(&node->refcount);
174 static void lock_ref_node(struct fs_node *node)
177 mutex_lock(&node->lock);
178 atomic_inc(&node->refcount);
182 static void unlock_ref_node(struct fs_node *node)
185 atomic_dec(&node->refcount);
186 mutex_unlock(&node->lock);
190 static void tree_put_node(struct fs_node *node)
192 struct fs_node *parent_node = node->parent;
194 lock_ref_node(parent_node);
195 if (atomic_dec_and_test(&node->refcount)) {
197 list_del_init(&node->list);
198 if (node->remove_func)
199 node->remove_func(node);
203 unlock_ref_node(parent_node);
204 if (!node && parent_node)
205 tree_put_node(parent_node);
208 static int tree_remove_node(struct fs_node *node)
210 if (atomic_read(&node->refcount) > 1) {
211 atomic_dec(&node->refcount);
218 static struct fs_prio *find_prio(struct mlx5_flow_namespace *ns,
221 struct fs_prio *iter_prio;
223 fs_for_each_prio(iter_prio, ns) {
224 if (iter_prio->prio == prio)
231 static bool masked_memcmp(void *mask, void *val1, void *val2, size_t size)
235 for (i = 0; i < size; i++, mask++, val1++, val2++)
236 if ((*((u8 *)val1) & (*(u8 *)mask)) !=
237 ((*(u8 *)val2) & (*(u8 *)mask)))
243 static bool compare_match_value(struct mlx5_flow_group_mask *mask,
244 void *fte_param1, void *fte_param2)
246 if (mask->match_criteria_enable &
247 1 << MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_OUTER_HEADERS) {
248 void *fte_match1 = MLX5_ADDR_OF(fte_match_param,
249 fte_param1, outer_headers);
250 void *fte_match2 = MLX5_ADDR_OF(fte_match_param,
251 fte_param2, outer_headers);
252 void *fte_mask = MLX5_ADDR_OF(fte_match_param,
253 mask->match_criteria, outer_headers);
255 if (!masked_memcmp(fte_mask, fte_match1, fte_match2,
256 MLX5_ST_SZ_BYTES(fte_match_set_lyr_2_4)))
260 if (mask->match_criteria_enable &
261 1 << MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_MISC_PARAMETERS) {
262 void *fte_match1 = MLX5_ADDR_OF(fte_match_param,
263 fte_param1, misc_parameters);
264 void *fte_match2 = MLX5_ADDR_OF(fte_match_param,
265 fte_param2, misc_parameters);
266 void *fte_mask = MLX5_ADDR_OF(fte_match_param,
267 mask->match_criteria, misc_parameters);
269 if (!masked_memcmp(fte_mask, fte_match1, fte_match2,
270 MLX5_ST_SZ_BYTES(fte_match_set_misc)))
274 if (mask->match_criteria_enable &
275 1 << MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_INNER_HEADERS) {
276 void *fte_match1 = MLX5_ADDR_OF(fte_match_param,
277 fte_param1, inner_headers);
278 void *fte_match2 = MLX5_ADDR_OF(fte_match_param,
279 fte_param2, inner_headers);
280 void *fte_mask = MLX5_ADDR_OF(fte_match_param,
281 mask->match_criteria, inner_headers);
283 if (!masked_memcmp(fte_mask, fte_match1, fte_match2,
284 MLX5_ST_SZ_BYTES(fte_match_set_lyr_2_4)))
290 static bool compare_match_criteria(u8 match_criteria_enable1,
291 u8 match_criteria_enable2,
292 void *mask1, void *mask2)
294 return match_criteria_enable1 == match_criteria_enable2 &&
295 !memcmp(mask1, mask2, MLX5_ST_SZ_BYTES(fte_match_param));
298 static struct mlx5_flow_root_namespace *find_root(struct fs_node *node)
300 struct fs_node *root;
301 struct mlx5_flow_namespace *ns;
305 if (WARN_ON(root->type != FS_TYPE_NAMESPACE)) {
306 pr_warn("mlx5: flow steering node is not in tree or garbaged\n");
310 ns = container_of(root, struct mlx5_flow_namespace, node);
311 return container_of(ns, struct mlx5_flow_root_namespace, ns);
314 static inline struct mlx5_core_dev *get_dev(struct fs_node *node)
316 struct mlx5_flow_root_namespace *root = find_root(node);
323 static void del_flow_table(struct fs_node *node)
325 struct mlx5_flow_table *ft;
326 struct mlx5_core_dev *dev;
327 struct fs_prio *prio;
330 fs_get_obj(ft, node);
331 dev = get_dev(&ft->node);
333 err = mlx5_cmd_destroy_flow_table(dev, ft);
335 pr_warn("flow steering can't destroy ft\n");
336 fs_get_obj(prio, ft->node.parent);
340 static void del_rule(struct fs_node *node)
342 struct mlx5_flow_rule *rule;
343 struct mlx5_flow_table *ft;
344 struct mlx5_flow_group *fg;
347 struct mlx5_core_dev *dev = get_dev(node);
348 int match_len = MLX5_ST_SZ_BYTES(fte_match_param);
351 match_value = mlx5_vzalloc(match_len);
353 pr_warn("failed to allocate inbox\n");
357 fs_get_obj(rule, node);
358 fs_get_obj(fte, rule->node.parent);
359 fs_get_obj(fg, fte->node.parent);
360 memcpy(match_value, fte->val, sizeof(fte->val));
361 fs_get_obj(ft, fg->node.parent);
362 list_del(&rule->node.list);
363 if (rule->sw_action == MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO) {
364 mutex_lock(&rule->dest_attr.ft->lock);
365 list_del(&rule->next_ft);
366 mutex_unlock(&rule->dest_attr.ft->lock);
368 if ((fte->action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) &&
370 err = mlx5_cmd_update_fte(dev, ft,
373 pr_warn("%s can't del rule fg id=%d fte_index=%d\n",
374 __func__, fg->id, fte->index);
379 static void del_fte(struct fs_node *node)
381 struct mlx5_flow_table *ft;
382 struct mlx5_flow_group *fg;
383 struct mlx5_core_dev *dev;
387 fs_get_obj(fte, node);
388 fs_get_obj(fg, fte->node.parent);
389 fs_get_obj(ft, fg->node.parent);
391 dev = get_dev(&ft->node);
392 err = mlx5_cmd_delete_fte(dev, ft,
395 pr_warn("flow steering can't delete fte in index %d of flow group id %d\n",
402 static void del_flow_group(struct fs_node *node)
404 struct mlx5_flow_group *fg;
405 struct mlx5_flow_table *ft;
406 struct mlx5_core_dev *dev;
408 fs_get_obj(fg, node);
409 fs_get_obj(ft, fg->node.parent);
410 dev = get_dev(&ft->node);
412 if (mlx5_cmd_destroy_flow_group(dev, ft, fg->id))
413 pr_warn("flow steering can't destroy fg %d of ft %d\n",
417 static struct fs_fte *alloc_fte(u8 action,
424 fte = kzalloc(sizeof(*fte), GFP_KERNEL);
426 return ERR_PTR(-ENOMEM);
428 memcpy(fte->val, match_value, sizeof(fte->val));
429 fte->node.type = FS_TYPE_FLOW_ENTRY;
430 fte->flow_tag = flow_tag;
432 fte->action = action;
437 static struct mlx5_flow_group *alloc_flow_group(u32 *create_fg_in)
439 struct mlx5_flow_group *fg;
440 void *match_criteria = MLX5_ADDR_OF(create_flow_group_in,
441 create_fg_in, match_criteria);
442 u8 match_criteria_enable = MLX5_GET(create_flow_group_in,
444 match_criteria_enable);
445 fg = kzalloc(sizeof(*fg), GFP_KERNEL);
447 return ERR_PTR(-ENOMEM);
449 fg->mask.match_criteria_enable = match_criteria_enable;
450 memcpy(&fg->mask.match_criteria, match_criteria,
451 sizeof(fg->mask.match_criteria));
452 fg->node.type = FS_TYPE_FLOW_GROUP;
453 fg->start_index = MLX5_GET(create_flow_group_in, create_fg_in,
455 fg->max_ftes = MLX5_GET(create_flow_group_in, create_fg_in,
456 end_flow_index) - fg->start_index + 1;
460 static struct mlx5_flow_table *alloc_flow_table(int level, int max_fte,
461 enum fs_flow_table_type table_type)
463 struct mlx5_flow_table *ft;
465 ft = kzalloc(sizeof(*ft), GFP_KERNEL);
470 ft->node.type = FS_TYPE_FLOW_TABLE;
471 ft->type = table_type;
472 ft->max_fte = max_fte;
473 INIT_LIST_HEAD(&ft->fwd_rules);
474 mutex_init(&ft->lock);
479 /* If reverse is false, then we search for the first flow table in the
480 * root sub-tree from start(closest from right), else we search for the
481 * last flow table in the root sub-tree till start(closest from left).
483 static struct mlx5_flow_table *find_closest_ft_recursive(struct fs_node *root,
484 struct list_head *start,
487 #define list_advance_entry(pos, reverse) \
488 ((reverse) ? list_prev_entry(pos, list) : list_next_entry(pos, list))
490 #define list_for_each_advance_continue(pos, head, reverse) \
491 for (pos = list_advance_entry(pos, reverse); \
492 &pos->list != (head); \
493 pos = list_advance_entry(pos, reverse))
495 struct fs_node *iter = list_entry(start, struct fs_node, list);
496 struct mlx5_flow_table *ft = NULL;
501 list_for_each_advance_continue(iter, &root->children, reverse) {
502 if (iter->type == FS_TYPE_FLOW_TABLE) {
503 fs_get_obj(ft, iter);
506 ft = find_closest_ft_recursive(iter, &iter->children, reverse);
514 /* If reverse if false then return the first flow table in next priority of
515 * prio in the tree, else return the last flow table in the previous priority
516 * of prio in the tree.
518 static struct mlx5_flow_table *find_closest_ft(struct fs_prio *prio, bool reverse)
520 struct mlx5_flow_table *ft = NULL;
521 struct fs_node *curr_node;
522 struct fs_node *parent;
524 parent = prio->node.parent;
525 curr_node = &prio->node;
526 while (!ft && parent) {
527 ft = find_closest_ft_recursive(parent, &curr_node->list, reverse);
529 parent = curr_node->parent;
534 /* Assuming all the tree is locked by mutex chain lock */
535 static struct mlx5_flow_table *find_next_chained_ft(struct fs_prio *prio)
537 return find_closest_ft(prio, false);
540 /* Assuming all the tree is locked by mutex chain lock */
541 static struct mlx5_flow_table *find_prev_chained_ft(struct fs_prio *prio)
543 return find_closest_ft(prio, true);
546 static int connect_fts_in_prio(struct mlx5_core_dev *dev,
547 struct fs_prio *prio,
548 struct mlx5_flow_table *ft)
550 struct mlx5_flow_table *iter;
554 fs_for_each_ft(iter, prio) {
556 err = mlx5_cmd_modify_flow_table(dev,
560 mlx5_core_warn(dev, "Failed to modify flow table %d\n",
562 /* The driver is out of sync with the FW */
571 /* Connect flow tables from previous priority of prio to ft */
572 static int connect_prev_fts(struct mlx5_core_dev *dev,
573 struct mlx5_flow_table *ft,
574 struct fs_prio *prio)
576 struct mlx5_flow_table *prev_ft;
578 prev_ft = find_prev_chained_ft(prio);
580 struct fs_prio *prev_prio;
582 fs_get_obj(prev_prio, prev_ft->node.parent);
583 return connect_fts_in_prio(dev, prev_prio, ft);
588 static int update_root_ft_create(struct mlx5_flow_table *ft, struct fs_prio
591 struct mlx5_flow_root_namespace *root = find_root(&prio->node);
592 int min_level = INT_MAX;
596 min_level = root->root_ft->level;
598 if (ft->level >= min_level)
601 err = mlx5_cmd_update_root_ft(root->dev, ft);
603 mlx5_core_warn(root->dev, "Update root flow table of id=%u failed\n",
611 int mlx5_modify_rule_destination(struct mlx5_flow_rule *rule,
612 struct mlx5_flow_destination *dest)
614 struct mlx5_flow_table *ft;
615 struct mlx5_flow_group *fg;
619 fs_get_obj(fte, rule->node.parent);
620 if (!(fte->action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST))
622 lock_ref_node(&fte->node);
623 fs_get_obj(fg, fte->node.parent);
624 fs_get_obj(ft, fg->node.parent);
626 memcpy(&rule->dest_attr, dest, sizeof(*dest));
627 err = mlx5_cmd_update_fte(get_dev(&ft->node),
629 unlock_ref_node(&fte->node);
634 /* Modify/set FWD rules that point on old_next_ft to point on new_next_ft */
635 static int connect_fwd_rules(struct mlx5_core_dev *dev,
636 struct mlx5_flow_table *new_next_ft,
637 struct mlx5_flow_table *old_next_ft)
639 struct mlx5_flow_destination dest;
640 struct mlx5_flow_rule *iter;
643 /* new_next_ft and old_next_ft could be NULL only
644 * when we create/destroy the anchor flow table.
646 if (!new_next_ft || !old_next_ft)
649 dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
650 dest.ft = new_next_ft;
652 mutex_lock(&old_next_ft->lock);
653 list_splice_init(&old_next_ft->fwd_rules, &new_next_ft->fwd_rules);
654 mutex_unlock(&old_next_ft->lock);
655 list_for_each_entry(iter, &new_next_ft->fwd_rules, next_ft) {
656 err = mlx5_modify_rule_destination(iter, &dest);
658 pr_err("mlx5_core: failed to modify rule to point on flow table %d\n",
664 static int connect_flow_table(struct mlx5_core_dev *dev, struct mlx5_flow_table *ft,
665 struct fs_prio *prio)
667 struct mlx5_flow_table *next_ft;
670 /* Connect_prev_fts and update_root_ft_create are mutually exclusive */
672 if (list_empty(&prio->node.children)) {
673 err = connect_prev_fts(dev, ft, prio);
677 next_ft = find_next_chained_ft(prio);
678 err = connect_fwd_rules(dev, ft, next_ft);
683 if (MLX5_CAP_FLOWTABLE(dev,
684 flow_table_properties_nic_receive.modify_root))
685 err = update_root_ft_create(ft, prio);
689 static void list_add_flow_table(struct mlx5_flow_table *ft,
690 struct fs_prio *prio)
692 struct list_head *prev = &prio->node.children;
693 struct mlx5_flow_table *iter;
695 fs_for_each_ft(iter, prio) {
696 if (iter->level > ft->level)
698 prev = &iter->node.list;
700 list_add(&ft->node.list, prev);
703 struct mlx5_flow_table *mlx5_create_flow_table(struct mlx5_flow_namespace *ns,
704 int prio, int max_fte,
707 struct mlx5_flow_table *next_ft = NULL;
708 struct mlx5_flow_table *ft;
711 struct mlx5_flow_root_namespace *root =
712 find_root(&ns->node);
713 struct fs_prio *fs_prio = NULL;
716 pr_err("mlx5: flow steering failed to find root of namespace\n");
717 return ERR_PTR(-ENODEV);
720 mutex_lock(&root->chain_lock);
721 fs_prio = find_prio(ns, prio);
726 if (level >= fs_prio->num_levels) {
730 /* The level is related to the
731 * priority level range.
733 level += fs_prio->start_level;
734 ft = alloc_flow_table(level,
735 roundup_pow_of_two(max_fte),
742 tree_init_node(&ft->node, 1, del_flow_table);
743 log_table_sz = ilog2(ft->max_fte);
744 next_ft = find_next_chained_ft(fs_prio);
745 err = mlx5_cmd_create_flow_table(root->dev, ft->type, ft->level,
746 log_table_sz, next_ft, &ft->id);
750 err = connect_flow_table(root->dev, ft, fs_prio);
753 lock_ref_node(&fs_prio->node);
754 tree_add_node(&ft->node, &fs_prio->node);
755 list_add_flow_table(ft, fs_prio);
757 unlock_ref_node(&fs_prio->node);
758 mutex_unlock(&root->chain_lock);
761 mlx5_cmd_destroy_flow_table(root->dev, ft);
765 mutex_unlock(&root->chain_lock);
769 struct mlx5_flow_table *mlx5_create_auto_grouped_flow_table(struct mlx5_flow_namespace *ns,
771 int num_flow_table_entries,
775 struct mlx5_flow_table *ft;
777 if (max_num_groups > num_flow_table_entries)
778 return ERR_PTR(-EINVAL);
780 ft = mlx5_create_flow_table(ns, prio, num_flow_table_entries, level);
784 ft->autogroup.active = true;
785 ft->autogroup.required_groups = max_num_groups;
789 EXPORT_SYMBOL(mlx5_create_auto_grouped_flow_table);
791 /* Flow table should be locked */
792 static struct mlx5_flow_group *create_flow_group_common(struct mlx5_flow_table *ft,
798 struct mlx5_flow_group *fg;
799 struct mlx5_core_dev *dev = get_dev(&ft->node);
803 return ERR_PTR(-ENODEV);
805 fg = alloc_flow_group(fg_in);
809 err = mlx5_cmd_create_flow_group(dev, ft, fg_in, &fg->id);
815 if (ft->autogroup.active)
816 ft->autogroup.num_groups++;
817 /* Add node to tree */
818 tree_init_node(&fg->node, !is_auto_fg, del_flow_group);
819 tree_add_node(&fg->node, &ft->node);
820 /* Add node to group list */
821 list_add(&fg->node.list, ft->node.children.prev);
826 struct mlx5_flow_group *mlx5_create_flow_group(struct mlx5_flow_table *ft,
829 struct mlx5_flow_group *fg;
831 if (ft->autogroup.active)
832 return ERR_PTR(-EPERM);
834 lock_ref_node(&ft->node);
835 fg = create_flow_group_common(ft, fg_in, &ft->node.children, false);
836 unlock_ref_node(&ft->node);
841 static struct mlx5_flow_rule *alloc_rule(struct mlx5_flow_destination *dest)
843 struct mlx5_flow_rule *rule;
845 rule = kzalloc(sizeof(*rule), GFP_KERNEL);
849 INIT_LIST_HEAD(&rule->next_ft);
850 rule->node.type = FS_TYPE_FLOW_DEST;
852 memcpy(&rule->dest_attr, dest, sizeof(*dest));
857 /* fte should not be deleted while calling this function */
858 static struct mlx5_flow_rule *add_rule_fte(struct fs_fte *fte,
859 struct mlx5_flow_group *fg,
860 struct mlx5_flow_destination *dest)
862 struct mlx5_flow_table *ft;
863 struct mlx5_flow_rule *rule;
866 rule = alloc_rule(dest);
868 return ERR_PTR(-ENOMEM);
870 fs_get_obj(ft, fg->node.parent);
871 /* Add dest to dests list- we need flow tables to be in the
872 * end of the list for forward to next prio rules.
874 tree_init_node(&rule->node, 1, del_rule);
875 if (dest && dest->type != MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE)
876 list_add(&rule->node.list, &fte->node.children);
878 list_add_tail(&rule->node.list, &fte->node.children);
881 if (fte->dests_size == 1 || !dest)
882 err = mlx5_cmd_create_fte(get_dev(&ft->node),
885 err = mlx5_cmd_update_fte(get_dev(&ft->node),
890 fte->status |= FS_FTE_STATUS_EXISTING;
895 list_del(&rule->node.list);
902 /* Assumed fg is locked */
903 static unsigned int get_free_fte_index(struct mlx5_flow_group *fg,
904 struct list_head **prev)
907 unsigned int start = fg->start_index;
910 *prev = &fg->node.children;
912 /* assumed list is sorted by index */
913 fs_for_each_fte(fte, fg) {
914 if (fte->index != start)
918 *prev = &fte->node.list;
924 /* prev is output, prev->next = new_fte */
925 static struct fs_fte *create_fte(struct mlx5_flow_group *fg,
929 struct list_head **prev)
934 index = get_free_fte_index(fg, prev);
935 fte = alloc_fte(action, flow_tag, match_value, index);
942 static struct mlx5_flow_group *create_autogroup(struct mlx5_flow_table *ft,
943 u8 match_criteria_enable,
946 int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
947 struct list_head *prev = &ft->node.children;
948 unsigned int candidate_index = 0;
949 struct mlx5_flow_group *fg;
950 void *match_criteria_addr;
951 unsigned int group_size = 0;
954 if (!ft->autogroup.active)
955 return ERR_PTR(-ENOENT);
957 in = mlx5_vzalloc(inlen);
959 return ERR_PTR(-ENOMEM);
961 if (ft->autogroup.num_groups < ft->autogroup.required_groups)
962 /* We save place for flow groups in addition to max types */
963 group_size = ft->max_fte / (ft->autogroup.required_groups + 1);
965 /* ft->max_fte == ft->autogroup.max_types */
969 /* sorted by start_index */
970 fs_for_each_fg(fg, ft) {
971 if (candidate_index + group_size > fg->start_index)
972 candidate_index = fg->start_index + fg->max_ftes;
975 prev = &fg->node.list;
978 if (candidate_index + group_size > ft->max_fte) {
979 fg = ERR_PTR(-ENOSPC);
983 MLX5_SET(create_flow_group_in, in, match_criteria_enable,
984 match_criteria_enable);
985 MLX5_SET(create_flow_group_in, in, start_flow_index, candidate_index);
986 MLX5_SET(create_flow_group_in, in, end_flow_index, candidate_index +
988 match_criteria_addr = MLX5_ADDR_OF(create_flow_group_in,
990 memcpy(match_criteria_addr, match_criteria,
991 MLX5_ST_SZ_BYTES(fte_match_param));
993 fg = create_flow_group_common(ft, in, prev, true);
999 static struct mlx5_flow_rule *find_flow_rule(struct fs_fte *fte,
1000 struct mlx5_flow_destination *dest)
1002 struct mlx5_flow_rule *rule;
1004 list_for_each_entry(rule, &fte->node.children, node.list) {
1005 if (rule->dest_attr.type == dest->type) {
1006 if ((dest->type == MLX5_FLOW_DESTINATION_TYPE_VPORT &&
1007 dest->vport_num == rule->dest_attr.vport_num) ||
1008 (dest->type == MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE &&
1009 dest->ft == rule->dest_attr.ft) ||
1010 (dest->type == MLX5_FLOW_DESTINATION_TYPE_TIR &&
1011 dest->tir_num == rule->dest_attr.tir_num))
1018 static struct mlx5_flow_rule *add_rule_fg(struct mlx5_flow_group *fg,
1022 struct mlx5_flow_destination *dest)
1025 struct mlx5_flow_rule *rule;
1026 struct mlx5_flow_table *ft;
1027 struct list_head *prev;
1029 nested_lock_ref_node(&fg->node, FS_MUTEX_PARENT);
1030 fs_for_each_fte(fte, fg) {
1031 nested_lock_ref_node(&fte->node, FS_MUTEX_CHILD);
1032 if (compare_match_value(&fg->mask, match_value, &fte->val) &&
1033 action == fte->action && flow_tag == fte->flow_tag) {
1034 rule = find_flow_rule(fte, dest);
1036 atomic_inc(&rule->node.refcount);
1037 unlock_ref_node(&fte->node);
1038 unlock_ref_node(&fg->node);
1041 rule = add_rule_fte(fte, fg, dest);
1042 unlock_ref_node(&fte->node);
1048 unlock_ref_node(&fte->node);
1050 fs_get_obj(ft, fg->node.parent);
1051 if (fg->num_ftes >= fg->max_ftes) {
1052 rule = ERR_PTR(-ENOSPC);
1056 fte = create_fte(fg, match_value, action, flow_tag, &prev);
1061 tree_init_node(&fte->node, 0, del_fte);
1062 rule = add_rule_fte(fte, fg, dest);
1070 tree_add_node(&fte->node, &fg->node);
1071 list_add(&fte->node.list, prev);
1073 tree_add_node(&rule->node, &fte->node);
1075 unlock_ref_node(&fg->node);
1079 static bool dest_is_valid(struct mlx5_flow_destination *dest,
1081 struct mlx5_flow_table *ft)
1083 if (!(action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST))
1086 if (!dest || ((dest->type ==
1087 MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE) &&
1088 (dest->ft->level <= ft->level)))
1093 static struct mlx5_flow_rule *
1094 _mlx5_add_flow_rule(struct mlx5_flow_table *ft,
1095 u8 match_criteria_enable,
1096 u32 *match_criteria,
1100 struct mlx5_flow_destination *dest)
1102 struct mlx5_flow_group *g;
1103 struct mlx5_flow_rule *rule;
1105 if (!dest_is_valid(dest, action, ft))
1106 return ERR_PTR(-EINVAL);
1108 nested_lock_ref_node(&ft->node, FS_MUTEX_GRANDPARENT);
1109 fs_for_each_fg(g, ft)
1110 if (compare_match_criteria(g->mask.match_criteria_enable,
1111 match_criteria_enable,
1112 g->mask.match_criteria,
1114 rule = add_rule_fg(g, match_value,
1115 action, flow_tag, dest);
1116 if (!IS_ERR(rule) || PTR_ERR(rule) != -ENOSPC)
1120 g = create_autogroup(ft, match_criteria_enable, match_criteria);
1126 rule = add_rule_fg(g, match_value,
1127 action, flow_tag, dest);
1129 /* Remove assumes refcount > 0 and autogroup creates a group
1130 * with a refcount = 0.
1132 unlock_ref_node(&ft->node);
1133 tree_get_node(&g->node);
1134 tree_remove_node(&g->node);
1138 unlock_ref_node(&ft->node);
1142 static bool fwd_next_prio_supported(struct mlx5_flow_table *ft)
1144 return ((ft->type == FS_FT_NIC_RX) &&
1145 (MLX5_CAP_FLOWTABLE(get_dev(&ft->node), nic_rx_multi_path_tirs)));
1148 struct mlx5_flow_rule *
1149 mlx5_add_flow_rule(struct mlx5_flow_table *ft,
1150 u8 match_criteria_enable,
1151 u32 *match_criteria,
1155 struct mlx5_flow_destination *dest)
1157 struct mlx5_flow_root_namespace *root = find_root(&ft->node);
1158 struct mlx5_flow_destination gen_dest;
1159 struct mlx5_flow_table *next_ft = NULL;
1160 struct mlx5_flow_rule *rule = NULL;
1161 u32 sw_action = action;
1162 struct fs_prio *prio;
1164 fs_get_obj(prio, ft->node.parent);
1165 if (action == MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO) {
1166 if (!fwd_next_prio_supported(ft))
1167 return ERR_PTR(-EOPNOTSUPP);
1169 return ERR_PTR(-EINVAL);
1170 mutex_lock(&root->chain_lock);
1171 next_ft = find_next_chained_ft(prio);
1173 gen_dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
1174 gen_dest.ft = next_ft;
1176 action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
1178 mutex_unlock(&root->chain_lock);
1179 return ERR_PTR(-EOPNOTSUPP);
1183 rule = _mlx5_add_flow_rule(ft, match_criteria_enable, match_criteria,
1184 match_value, action, flow_tag, dest);
1186 if (sw_action == MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO) {
1187 if (!IS_ERR_OR_NULL(rule) &&
1188 (list_empty(&rule->next_ft))) {
1189 mutex_lock(&next_ft->lock);
1190 list_add(&rule->next_ft, &next_ft->fwd_rules);
1191 mutex_unlock(&next_ft->lock);
1192 rule->sw_action = MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO;
1194 mutex_unlock(&root->chain_lock);
1198 EXPORT_SYMBOL(mlx5_add_flow_rule);
1200 void mlx5_del_flow_rule(struct mlx5_flow_rule *rule)
1202 tree_remove_node(&rule->node);
1204 EXPORT_SYMBOL(mlx5_del_flow_rule);
1206 /* Assuming prio->node.children(flow tables) is sorted by level */
1207 static struct mlx5_flow_table *find_next_ft(struct mlx5_flow_table *ft)
1209 struct fs_prio *prio;
1211 fs_get_obj(prio, ft->node.parent);
1213 if (!list_is_last(&ft->node.list, &prio->node.children))
1214 return list_next_entry(ft, node.list);
1215 return find_next_chained_ft(prio);
1218 static int update_root_ft_destroy(struct mlx5_flow_table *ft)
1220 struct mlx5_flow_root_namespace *root = find_root(&ft->node);
1221 struct mlx5_flow_table *new_root_ft = NULL;
1223 if (root->root_ft != ft)
1226 new_root_ft = find_next_ft(ft);
1228 int err = mlx5_cmd_update_root_ft(root->dev, new_root_ft);
1231 mlx5_core_warn(root->dev, "Update root flow table of id=%u failed\n",
1235 root->root_ft = new_root_ft;
1240 /* Connect flow table from previous priority to
1241 * the next flow table.
1243 static int disconnect_flow_table(struct mlx5_flow_table *ft)
1245 struct mlx5_core_dev *dev = get_dev(&ft->node);
1246 struct mlx5_flow_table *next_ft;
1247 struct fs_prio *prio;
1250 err = update_root_ft_destroy(ft);
1254 fs_get_obj(prio, ft->node.parent);
1255 if (!(list_first_entry(&prio->node.children,
1256 struct mlx5_flow_table,
1260 next_ft = find_next_chained_ft(prio);
1261 err = connect_fwd_rules(dev, next_ft, ft);
1265 err = connect_prev_fts(dev, next_ft, prio);
1267 mlx5_core_warn(dev, "Failed to disconnect flow table %d\n",
1272 int mlx5_destroy_flow_table(struct mlx5_flow_table *ft)
1274 struct mlx5_flow_root_namespace *root = find_root(&ft->node);
1277 mutex_lock(&root->chain_lock);
1278 err = disconnect_flow_table(ft);
1280 mutex_unlock(&root->chain_lock);
1283 if (tree_remove_node(&ft->node))
1284 mlx5_core_warn(get_dev(&ft->node), "Flow table %d wasn't destroyed, refcount > 1\n",
1286 mutex_unlock(&root->chain_lock);
1290 EXPORT_SYMBOL(mlx5_destroy_flow_table);
1292 void mlx5_destroy_flow_group(struct mlx5_flow_group *fg)
1294 if (tree_remove_node(&fg->node))
1295 mlx5_core_warn(get_dev(&fg->node), "Flow group %d wasn't destroyed, refcount > 1\n",
1299 struct mlx5_flow_namespace *mlx5_get_flow_namespace(struct mlx5_core_dev *dev,
1300 enum mlx5_flow_namespace_type type)
1302 struct mlx5_flow_root_namespace *root_ns = dev->priv.root_ns;
1304 struct fs_prio *fs_prio;
1305 struct mlx5_flow_namespace *ns;
1311 case MLX5_FLOW_NAMESPACE_BYPASS:
1312 case MLX5_FLOW_NAMESPACE_KERNEL:
1313 case MLX5_FLOW_NAMESPACE_LEFTOVERS:
1314 case MLX5_FLOW_NAMESPACE_ANCHOR:
1317 case MLX5_FLOW_NAMESPACE_FDB:
1318 if (dev->priv.fdb_root_ns)
1319 return &dev->priv.fdb_root_ns->ns;
1326 fs_prio = find_prio(&root_ns->ns, prio);
1330 ns = list_first_entry(&fs_prio->node.children,
1336 EXPORT_SYMBOL(mlx5_get_flow_namespace);
1338 static struct fs_prio *fs_create_prio(struct mlx5_flow_namespace *ns,
1339 unsigned int prio, int num_levels)
1341 struct fs_prio *fs_prio;
1343 fs_prio = kzalloc(sizeof(*fs_prio), GFP_KERNEL);
1345 return ERR_PTR(-ENOMEM);
1347 fs_prio->node.type = FS_TYPE_PRIO;
1348 tree_init_node(&fs_prio->node, 1, NULL);
1349 tree_add_node(&fs_prio->node, &ns->node);
1350 fs_prio->num_levels = num_levels;
1351 fs_prio->prio = prio;
1352 list_add_tail(&fs_prio->node.list, &ns->node.children);
1357 static struct mlx5_flow_namespace *fs_init_namespace(struct mlx5_flow_namespace
1360 ns->node.type = FS_TYPE_NAMESPACE;
1365 static struct mlx5_flow_namespace *fs_create_namespace(struct fs_prio *prio)
1367 struct mlx5_flow_namespace *ns;
1369 ns = kzalloc(sizeof(*ns), GFP_KERNEL);
1371 return ERR_PTR(-ENOMEM);
1373 fs_init_namespace(ns);
1374 tree_init_node(&ns->node, 1, NULL);
1375 tree_add_node(&ns->node, &prio->node);
1376 list_add_tail(&ns->node.list, &prio->node.children);
1381 static int create_leaf_prios(struct mlx5_flow_namespace *ns, int prio,
1382 struct init_tree_node *prio_metadata)
1384 struct fs_prio *fs_prio;
1387 for (i = 0; i < prio_metadata->num_leaf_prios; i++) {
1388 fs_prio = fs_create_prio(ns, prio++, prio_metadata->num_levels);
1389 if (IS_ERR(fs_prio))
1390 return PTR_ERR(fs_prio);
1395 #define FLOW_TABLE_BIT_SZ 1
1396 #define GET_FLOW_TABLE_CAP(dev, offset) \
1397 ((be32_to_cpu(*((__be32 *)(dev->hca_caps_cur[MLX5_CAP_FLOW_TABLE]) + \
1399 (32 - FLOW_TABLE_BIT_SZ - (offset & 0x1f))) & FLOW_TABLE_BIT_SZ)
1400 static bool has_required_caps(struct mlx5_core_dev *dev, struct node_caps *caps)
1404 for (i = 0; i < caps->arr_sz; i++) {
1405 if (!GET_FLOW_TABLE_CAP(dev, caps->caps[i]))
1411 static int init_root_tree_recursive(struct mlx5_core_dev *dev,
1412 struct init_tree_node *init_node,
1413 struct fs_node *fs_parent_node,
1414 struct init_tree_node *init_parent_node,
1417 int max_ft_level = MLX5_CAP_FLOWTABLE(dev,
1418 flow_table_properties_nic_receive.
1420 struct mlx5_flow_namespace *fs_ns;
1421 struct fs_prio *fs_prio;
1422 struct fs_node *base;
1426 if (init_node->type == FS_TYPE_PRIO) {
1427 if ((init_node->min_ft_level > max_ft_level) ||
1428 !has_required_caps(dev, &init_node->caps))
1431 fs_get_obj(fs_ns, fs_parent_node);
1432 if (init_node->num_leaf_prios)
1433 return create_leaf_prios(fs_ns, prio, init_node);
1434 fs_prio = fs_create_prio(fs_ns, prio, init_node->num_levels);
1435 if (IS_ERR(fs_prio))
1436 return PTR_ERR(fs_prio);
1437 base = &fs_prio->node;
1438 } else if (init_node->type == FS_TYPE_NAMESPACE) {
1439 fs_get_obj(fs_prio, fs_parent_node);
1440 fs_ns = fs_create_namespace(fs_prio);
1442 return PTR_ERR(fs_ns);
1443 base = &fs_ns->node;
1448 for (i = 0; i < init_node->ar_size; i++) {
1449 err = init_root_tree_recursive(dev, &init_node->children[i],
1450 base, init_node, prio);
1453 if (init_node->children[i].type == FS_TYPE_PRIO &&
1454 init_node->children[i].num_leaf_prios) {
1455 prio += init_node->children[i].num_leaf_prios;
1462 static int init_root_tree(struct mlx5_core_dev *dev,
1463 struct init_tree_node *init_node,
1464 struct fs_node *fs_parent_node)
1467 struct mlx5_flow_namespace *fs_ns;
1470 fs_get_obj(fs_ns, fs_parent_node);
1471 for (i = 0; i < init_node->ar_size; i++) {
1472 err = init_root_tree_recursive(dev, &init_node->children[i],
1481 static struct mlx5_flow_root_namespace *create_root_ns(struct mlx5_core_dev *dev,
1482 enum fs_flow_table_type
1485 struct mlx5_flow_root_namespace *root_ns;
1486 struct mlx5_flow_namespace *ns;
1488 /* Create the root namespace */
1489 root_ns = mlx5_vzalloc(sizeof(*root_ns));
1494 root_ns->table_type = table_type;
1497 fs_init_namespace(ns);
1498 mutex_init(&root_ns->chain_lock);
1499 tree_init_node(&ns->node, 1, NULL);
1500 tree_add_node(&ns->node, NULL);
1505 static void set_prio_attrs_in_prio(struct fs_prio *prio, int acc_level);
1507 static int set_prio_attrs_in_ns(struct mlx5_flow_namespace *ns, int acc_level)
1509 struct fs_prio *prio;
1511 fs_for_each_prio(prio, ns) {
1512 /* This updates prio start_level and num_levels */
1513 set_prio_attrs_in_prio(prio, acc_level);
1514 acc_level += prio->num_levels;
1519 static void set_prio_attrs_in_prio(struct fs_prio *prio, int acc_level)
1521 struct mlx5_flow_namespace *ns;
1522 int acc_level_ns = acc_level;
1524 prio->start_level = acc_level;
1525 fs_for_each_ns(ns, prio)
1526 /* This updates start_level and num_levels of ns's priority descendants */
1527 acc_level_ns = set_prio_attrs_in_ns(ns, acc_level);
1528 if (!prio->num_levels)
1529 prio->num_levels = acc_level_ns - prio->start_level;
1530 WARN_ON(prio->num_levels < acc_level_ns - prio->start_level);
1533 static void set_prio_attrs(struct mlx5_flow_root_namespace *root_ns)
1535 struct mlx5_flow_namespace *ns = &root_ns->ns;
1536 struct fs_prio *prio;
1537 int start_level = 0;
1539 fs_for_each_prio(prio, ns) {
1540 set_prio_attrs_in_prio(prio, start_level);
1541 start_level += prio->num_levels;
1545 #define ANCHOR_PRIO 0
1546 #define ANCHOR_SIZE 1
1547 #define ANCHOR_LEVEL 0
1548 static int create_anchor_flow_table(struct mlx5_core_dev
1551 struct mlx5_flow_namespace *ns = NULL;
1552 struct mlx5_flow_table *ft;
1554 ns = mlx5_get_flow_namespace(dev, MLX5_FLOW_NAMESPACE_ANCHOR);
1557 ft = mlx5_create_flow_table(ns, ANCHOR_PRIO, ANCHOR_SIZE, ANCHOR_LEVEL);
1559 mlx5_core_err(dev, "Failed to create last anchor flow table");
1565 static int init_root_ns(struct mlx5_core_dev *dev)
1568 dev->priv.root_ns = create_root_ns(dev, FS_FT_NIC_RX);
1569 if (IS_ERR_OR_NULL(dev->priv.root_ns))
1572 if (init_root_tree(dev, &root_fs, &dev->priv.root_ns->ns.node))
1575 set_prio_attrs(dev->priv.root_ns);
1577 if (create_anchor_flow_table(dev))
1583 mlx5_cleanup_fs(dev);
1587 static void cleanup_single_prio_root_ns(struct mlx5_core_dev *dev,
1588 struct mlx5_flow_root_namespace *root_ns)
1590 struct fs_node *prio;
1595 if (!list_empty(&root_ns->ns.node.children)) {
1596 prio = list_first_entry(&root_ns->ns.node.children,
1599 if (tree_remove_node(prio))
1601 "Flow steering priority wasn't destroyed, refcount > 1\n");
1603 if (tree_remove_node(&root_ns->ns.node))
1605 "Flow steering namespace wasn't destroyed, refcount > 1\n");
1609 static void destroy_flow_tables(struct fs_prio *prio)
1611 struct mlx5_flow_table *iter;
1612 struct mlx5_flow_table *tmp;
1614 fs_for_each_ft_safe(iter, tmp, prio)
1615 mlx5_destroy_flow_table(iter);
1618 static void cleanup_root_ns(struct mlx5_core_dev *dev)
1620 struct mlx5_flow_root_namespace *root_ns = dev->priv.root_ns;
1621 struct fs_prio *iter_prio;
1623 if (!MLX5_CAP_GEN(dev, nic_flow_table))
1630 fs_for_each_prio(iter_prio, &root_ns->ns) {
1631 struct fs_node *node;
1632 struct mlx5_flow_namespace *iter_ns;
1634 fs_for_each_ns_or_ft(node, iter_prio) {
1635 if (node->type == FS_TYPE_FLOW_TABLE)
1637 fs_get_obj(iter_ns, node);
1638 while (!list_empty(&iter_ns->node.children)) {
1639 struct fs_prio *obj_iter_prio2;
1640 struct fs_node *iter_prio2 =
1641 list_first_entry(&iter_ns->node.children,
1645 fs_get_obj(obj_iter_prio2, iter_prio2);
1646 destroy_flow_tables(obj_iter_prio2);
1647 if (tree_remove_node(iter_prio2)) {
1649 "Priority %d wasn't destroyed, refcount > 1\n",
1650 obj_iter_prio2->prio);
1658 fs_for_each_prio(iter_prio, &root_ns->ns) {
1659 while (!list_empty(&iter_prio->node.children)) {
1660 struct fs_node *iter_ns =
1661 list_first_entry(&iter_prio->node.children,
1664 if (tree_remove_node(iter_ns)) {
1666 "Namespace wasn't destroyed, refcount > 1\n");
1673 while (!list_empty(&root_ns->ns.node.children)) {
1674 struct fs_prio *obj_prio_node;
1675 struct fs_node *prio_node =
1676 list_first_entry(&root_ns->ns.node.children,
1680 fs_get_obj(obj_prio_node, prio_node);
1681 if (tree_remove_node(prio_node)) {
1683 "Priority %d wasn't destroyed, refcount > 1\n",
1684 obj_prio_node->prio);
1689 if (tree_remove_node(&root_ns->ns.node)) {
1691 "root namespace wasn't destroyed, refcount > 1\n");
1695 dev->priv.root_ns = NULL;
1698 void mlx5_cleanup_fs(struct mlx5_core_dev *dev)
1700 cleanup_root_ns(dev);
1701 cleanup_single_prio_root_ns(dev, dev->priv.fdb_root_ns);
1704 static int init_fdb_root_ns(struct mlx5_core_dev *dev)
1706 struct fs_prio *prio;
1708 dev->priv.fdb_root_ns = create_root_ns(dev, FS_FT_FDB);
1709 if (!dev->priv.fdb_root_ns)
1712 /* Create single prio */
1713 prio = fs_create_prio(&dev->priv.fdb_root_ns->ns, 0, 1);
1715 cleanup_single_prio_root_ns(dev, dev->priv.fdb_root_ns);
1716 return PTR_ERR(prio);
1722 int mlx5_init_fs(struct mlx5_core_dev *dev)
1726 if (MLX5_CAP_GEN(dev, nic_flow_table)) {
1727 err = init_root_ns(dev);
1731 if (MLX5_CAP_GEN(dev, eswitch_flow_table)) {
1732 err = init_fdb_root_ns(dev);
1734 cleanup_root_ns(dev);