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_NUM_LEVELS 3
78 #define KERNEL_NUM_PRIOS 2
79 #define KERNEL_MIN_LEVEL 2
81 #define ANCHOR_NUM_LEVELS 1
82 #define ANCHOR_NUM_PRIOS 1
83 #define ANCHOR_MIN_LEVEL (BY_PASS_MIN_LEVEL + 1)
88 static struct init_tree_node {
89 enum fs_node_type type;
90 struct init_tree_node *children;
92 struct node_caps caps;
98 .type = FS_TYPE_NAMESPACE,
100 .children = (struct init_tree_node[]) {
101 ADD_PRIO(0, BY_PASS_MIN_LEVEL, 0,
102 FS_REQUIRED_CAPS(FS_CAP(flow_table_properties_nic_receive.flow_modify_en),
103 FS_CAP(flow_table_properties_nic_receive.modify_root),
104 FS_CAP(flow_table_properties_nic_receive.identified_miss_table_mode),
105 FS_CAP(flow_table_properties_nic_receive.flow_table_modify)),
106 ADD_NS(ADD_MULTIPLE_PRIO(MLX5_BY_PASS_NUM_PRIOS,
107 BY_PASS_PRIO_NUM_LEVELS))),
108 ADD_PRIO(0, KERNEL_MIN_LEVEL, 0, {},
109 ADD_NS(ADD_MULTIPLE_PRIO(KERNEL_NUM_PRIOS,
110 KERNEL_NUM_LEVELS))),
111 ADD_PRIO(0, BY_PASS_MIN_LEVEL, 0,
112 FS_REQUIRED_CAPS(FS_CAP(flow_table_properties_nic_receive.flow_modify_en),
113 FS_CAP(flow_table_properties_nic_receive.modify_root),
114 FS_CAP(flow_table_properties_nic_receive.identified_miss_table_mode),
115 FS_CAP(flow_table_properties_nic_receive.flow_table_modify)),
116 ADD_NS(ADD_MULTIPLE_PRIO(LEFTOVERS_NUM_PRIOS, LEFTOVERS_NUM_LEVELS))),
117 ADD_PRIO(0, ANCHOR_MIN_LEVEL, 0, {},
118 ADD_NS(ADD_MULTIPLE_PRIO(ANCHOR_NUM_PRIOS, ANCHOR_NUM_LEVELS))),
122 enum fs_i_mutex_lock_class {
123 FS_MUTEX_GRANDPARENT,
128 static void del_rule(struct fs_node *node);
129 static void del_flow_table(struct fs_node *node);
130 static void del_flow_group(struct fs_node *node);
131 static void del_fte(struct fs_node *node);
133 static void tree_init_node(struct fs_node *node,
134 unsigned int refcount,
135 void (*remove_func)(struct fs_node *))
137 atomic_set(&node->refcount, refcount);
138 INIT_LIST_HEAD(&node->list);
139 INIT_LIST_HEAD(&node->children);
140 mutex_init(&node->lock);
141 node->remove_func = remove_func;
144 static void tree_add_node(struct fs_node *node, struct fs_node *parent)
147 atomic_inc(&parent->refcount);
148 node->parent = parent;
150 /* Parent is the root */
154 node->root = parent->root;
157 static void tree_get_node(struct fs_node *node)
159 atomic_inc(&node->refcount);
162 static void nested_lock_ref_node(struct fs_node *node,
163 enum fs_i_mutex_lock_class class)
166 mutex_lock_nested(&node->lock, class);
167 atomic_inc(&node->refcount);
171 static void lock_ref_node(struct fs_node *node)
174 mutex_lock(&node->lock);
175 atomic_inc(&node->refcount);
179 static void unlock_ref_node(struct fs_node *node)
182 atomic_dec(&node->refcount);
183 mutex_unlock(&node->lock);
187 static void tree_put_node(struct fs_node *node)
189 struct fs_node *parent_node = node->parent;
191 lock_ref_node(parent_node);
192 if (atomic_dec_and_test(&node->refcount)) {
194 list_del_init(&node->list);
195 if (node->remove_func)
196 node->remove_func(node);
200 unlock_ref_node(parent_node);
201 if (!node && parent_node)
202 tree_put_node(parent_node);
205 static int tree_remove_node(struct fs_node *node)
207 if (atomic_read(&node->refcount) > 1) {
208 atomic_dec(&node->refcount);
215 static struct fs_prio *find_prio(struct mlx5_flow_namespace *ns,
218 struct fs_prio *iter_prio;
220 fs_for_each_prio(iter_prio, ns) {
221 if (iter_prio->prio == prio)
228 static unsigned int find_next_free_level(struct fs_prio *prio)
230 if (!list_empty(&prio->node.children)) {
231 struct mlx5_flow_table *ft;
233 ft = list_last_entry(&prio->node.children,
234 struct mlx5_flow_table,
236 return ft->level + 1;
238 return prio->start_level;
241 static bool masked_memcmp(void *mask, void *val1, void *val2, size_t size)
245 for (i = 0; i < size; i++, mask++, val1++, val2++)
246 if ((*((u8 *)val1) & (*(u8 *)mask)) !=
247 ((*(u8 *)val2) & (*(u8 *)mask)))
253 static bool compare_match_value(struct mlx5_flow_group_mask *mask,
254 void *fte_param1, void *fte_param2)
256 if (mask->match_criteria_enable &
257 1 << MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_OUTER_HEADERS) {
258 void *fte_match1 = MLX5_ADDR_OF(fte_match_param,
259 fte_param1, outer_headers);
260 void *fte_match2 = MLX5_ADDR_OF(fte_match_param,
261 fte_param2, outer_headers);
262 void *fte_mask = MLX5_ADDR_OF(fte_match_param,
263 mask->match_criteria, outer_headers);
265 if (!masked_memcmp(fte_mask, fte_match1, fte_match2,
266 MLX5_ST_SZ_BYTES(fte_match_set_lyr_2_4)))
270 if (mask->match_criteria_enable &
271 1 << MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_MISC_PARAMETERS) {
272 void *fte_match1 = MLX5_ADDR_OF(fte_match_param,
273 fte_param1, misc_parameters);
274 void *fte_match2 = MLX5_ADDR_OF(fte_match_param,
275 fte_param2, misc_parameters);
276 void *fte_mask = MLX5_ADDR_OF(fte_match_param,
277 mask->match_criteria, misc_parameters);
279 if (!masked_memcmp(fte_mask, fte_match1, fte_match2,
280 MLX5_ST_SZ_BYTES(fte_match_set_misc)))
284 if (mask->match_criteria_enable &
285 1 << MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_INNER_HEADERS) {
286 void *fte_match1 = MLX5_ADDR_OF(fte_match_param,
287 fte_param1, inner_headers);
288 void *fte_match2 = MLX5_ADDR_OF(fte_match_param,
289 fte_param2, inner_headers);
290 void *fte_mask = MLX5_ADDR_OF(fte_match_param,
291 mask->match_criteria, inner_headers);
293 if (!masked_memcmp(fte_mask, fte_match1, fte_match2,
294 MLX5_ST_SZ_BYTES(fte_match_set_lyr_2_4)))
300 static bool compare_match_criteria(u8 match_criteria_enable1,
301 u8 match_criteria_enable2,
302 void *mask1, void *mask2)
304 return match_criteria_enable1 == match_criteria_enable2 &&
305 !memcmp(mask1, mask2, MLX5_ST_SZ_BYTES(fte_match_param));
308 static struct mlx5_flow_root_namespace *find_root(struct fs_node *node)
310 struct fs_node *root;
311 struct mlx5_flow_namespace *ns;
315 if (WARN_ON(root->type != FS_TYPE_NAMESPACE)) {
316 pr_warn("mlx5: flow steering node is not in tree or garbaged\n");
320 ns = container_of(root, struct mlx5_flow_namespace, node);
321 return container_of(ns, struct mlx5_flow_root_namespace, ns);
324 static inline struct mlx5_core_dev *get_dev(struct fs_node *node)
326 struct mlx5_flow_root_namespace *root = find_root(node);
333 static void del_flow_table(struct fs_node *node)
335 struct mlx5_flow_table *ft;
336 struct mlx5_core_dev *dev;
337 struct fs_prio *prio;
340 fs_get_obj(ft, node);
341 dev = get_dev(&ft->node);
343 err = mlx5_cmd_destroy_flow_table(dev, ft);
345 pr_warn("flow steering can't destroy ft\n");
346 fs_get_obj(prio, ft->node.parent);
350 static void del_rule(struct fs_node *node)
352 struct mlx5_flow_rule *rule;
353 struct mlx5_flow_table *ft;
354 struct mlx5_flow_group *fg;
357 struct mlx5_core_dev *dev = get_dev(node);
358 int match_len = MLX5_ST_SZ_BYTES(fte_match_param);
361 match_value = mlx5_vzalloc(match_len);
363 pr_warn("failed to allocate inbox\n");
367 fs_get_obj(rule, node);
368 fs_get_obj(fte, rule->node.parent);
369 fs_get_obj(fg, fte->node.parent);
370 memcpy(match_value, fte->val, sizeof(fte->val));
371 fs_get_obj(ft, fg->node.parent);
372 list_del(&rule->node.list);
373 if (rule->sw_action == MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO) {
374 mutex_lock(&rule->dest_attr.ft->lock);
375 list_del(&rule->next_ft);
376 mutex_unlock(&rule->dest_attr.ft->lock);
378 if ((fte->action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) &&
380 err = mlx5_cmd_update_fte(dev, ft,
383 pr_warn("%s can't del rule fg id=%d fte_index=%d\n",
384 __func__, fg->id, fte->index);
389 static void del_fte(struct fs_node *node)
391 struct mlx5_flow_table *ft;
392 struct mlx5_flow_group *fg;
393 struct mlx5_core_dev *dev;
397 fs_get_obj(fte, node);
398 fs_get_obj(fg, fte->node.parent);
399 fs_get_obj(ft, fg->node.parent);
401 dev = get_dev(&ft->node);
402 err = mlx5_cmd_delete_fte(dev, ft,
405 pr_warn("flow steering can't delete fte in index %d of flow group id %d\n",
412 static void del_flow_group(struct fs_node *node)
414 struct mlx5_flow_group *fg;
415 struct mlx5_flow_table *ft;
416 struct mlx5_core_dev *dev;
418 fs_get_obj(fg, node);
419 fs_get_obj(ft, fg->node.parent);
420 dev = get_dev(&ft->node);
422 if (mlx5_cmd_destroy_flow_group(dev, ft, fg->id))
423 pr_warn("flow steering can't destroy fg %d of ft %d\n",
427 static struct fs_fte *alloc_fte(u8 action,
434 fte = kzalloc(sizeof(*fte), GFP_KERNEL);
436 return ERR_PTR(-ENOMEM);
438 memcpy(fte->val, match_value, sizeof(fte->val));
439 fte->node.type = FS_TYPE_FLOW_ENTRY;
440 fte->flow_tag = flow_tag;
442 fte->action = action;
447 static struct mlx5_flow_group *alloc_flow_group(u32 *create_fg_in)
449 struct mlx5_flow_group *fg;
450 void *match_criteria = MLX5_ADDR_OF(create_flow_group_in,
451 create_fg_in, match_criteria);
452 u8 match_criteria_enable = MLX5_GET(create_flow_group_in,
454 match_criteria_enable);
455 fg = kzalloc(sizeof(*fg), GFP_KERNEL);
457 return ERR_PTR(-ENOMEM);
459 fg->mask.match_criteria_enable = match_criteria_enable;
460 memcpy(&fg->mask.match_criteria, match_criteria,
461 sizeof(fg->mask.match_criteria));
462 fg->node.type = FS_TYPE_FLOW_GROUP;
463 fg->start_index = MLX5_GET(create_flow_group_in, create_fg_in,
465 fg->max_ftes = MLX5_GET(create_flow_group_in, create_fg_in,
466 end_flow_index) - fg->start_index + 1;
470 static struct mlx5_flow_table *alloc_flow_table(int level, int max_fte,
471 enum fs_flow_table_type table_type)
473 struct mlx5_flow_table *ft;
475 ft = kzalloc(sizeof(*ft), GFP_KERNEL);
480 ft->node.type = FS_TYPE_FLOW_TABLE;
481 ft->type = table_type;
482 ft->max_fte = max_fte;
483 INIT_LIST_HEAD(&ft->fwd_rules);
484 mutex_init(&ft->lock);
489 /* If reverse is false, then we search for the first flow table in the
490 * root sub-tree from start(closest from right), else we search for the
491 * last flow table in the root sub-tree till start(closest from left).
493 static struct mlx5_flow_table *find_closest_ft_recursive(struct fs_node *root,
494 struct list_head *start,
497 #define list_advance_entry(pos, reverse) \
498 ((reverse) ? list_prev_entry(pos, list) : list_next_entry(pos, list))
500 #define list_for_each_advance_continue(pos, head, reverse) \
501 for (pos = list_advance_entry(pos, reverse); \
502 &pos->list != (head); \
503 pos = list_advance_entry(pos, reverse))
505 struct fs_node *iter = list_entry(start, struct fs_node, list);
506 struct mlx5_flow_table *ft = NULL;
511 list_for_each_advance_continue(iter, &root->children, reverse) {
512 if (iter->type == FS_TYPE_FLOW_TABLE) {
513 fs_get_obj(ft, iter);
516 ft = find_closest_ft_recursive(iter, &iter->children, reverse);
524 /* If reverse if false then return the first flow table in next priority of
525 * prio in the tree, else return the last flow table in the previous priority
526 * of prio in the tree.
528 static struct mlx5_flow_table *find_closest_ft(struct fs_prio *prio, bool reverse)
530 struct mlx5_flow_table *ft = NULL;
531 struct fs_node *curr_node;
532 struct fs_node *parent;
534 parent = prio->node.parent;
535 curr_node = &prio->node;
536 while (!ft && parent) {
537 ft = find_closest_ft_recursive(parent, &curr_node->list, reverse);
539 parent = curr_node->parent;
544 /* Assuming all the tree is locked by mutex chain lock */
545 static struct mlx5_flow_table *find_next_chained_ft(struct fs_prio *prio)
547 return find_closest_ft(prio, false);
550 /* Assuming all the tree is locked by mutex chain lock */
551 static struct mlx5_flow_table *find_prev_chained_ft(struct fs_prio *prio)
553 return find_closest_ft(prio, true);
556 static int connect_fts_in_prio(struct mlx5_core_dev *dev,
557 struct fs_prio *prio,
558 struct mlx5_flow_table *ft)
560 struct mlx5_flow_table *iter;
564 fs_for_each_ft(iter, prio) {
566 err = mlx5_cmd_modify_flow_table(dev,
570 mlx5_core_warn(dev, "Failed to modify flow table %d\n",
572 /* The driver is out of sync with the FW */
581 /* Connect flow tables from previous priority of prio to ft */
582 static int connect_prev_fts(struct mlx5_core_dev *dev,
583 struct mlx5_flow_table *ft,
584 struct fs_prio *prio)
586 struct mlx5_flow_table *prev_ft;
588 prev_ft = find_prev_chained_ft(prio);
590 struct fs_prio *prev_prio;
592 fs_get_obj(prev_prio, prev_ft->node.parent);
593 return connect_fts_in_prio(dev, prev_prio, ft);
598 static int update_root_ft_create(struct mlx5_flow_table *ft, struct fs_prio
601 struct mlx5_flow_root_namespace *root = find_root(&prio->node);
602 int min_level = INT_MAX;
606 min_level = root->root_ft->level;
608 if (ft->level >= min_level)
611 err = mlx5_cmd_update_root_ft(root->dev, ft);
613 mlx5_core_warn(root->dev, "Update root flow table of id=%u failed\n",
621 int mlx5_modify_rule_destination(struct mlx5_flow_rule *rule,
622 struct mlx5_flow_destination *dest)
624 struct mlx5_flow_table *ft;
625 struct mlx5_flow_group *fg;
629 fs_get_obj(fte, rule->node.parent);
630 if (!(fte->action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST))
632 lock_ref_node(&fte->node);
633 fs_get_obj(fg, fte->node.parent);
634 fs_get_obj(ft, fg->node.parent);
636 memcpy(&rule->dest_attr, dest, sizeof(*dest));
637 err = mlx5_cmd_update_fte(get_dev(&ft->node),
639 unlock_ref_node(&fte->node);
644 /* Modify/set FWD rules that point on old_next_ft to point on new_next_ft */
645 static int connect_fwd_rules(struct mlx5_core_dev *dev,
646 struct mlx5_flow_table *new_next_ft,
647 struct mlx5_flow_table *old_next_ft)
649 struct mlx5_flow_destination dest;
650 struct mlx5_flow_rule *iter;
653 /* new_next_ft and old_next_ft could be NULL only
654 * when we create/destroy the anchor flow table.
656 if (!new_next_ft || !old_next_ft)
659 dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
660 dest.ft = new_next_ft;
662 mutex_lock(&old_next_ft->lock);
663 list_splice_init(&old_next_ft->fwd_rules, &new_next_ft->fwd_rules);
664 mutex_unlock(&old_next_ft->lock);
665 list_for_each_entry(iter, &new_next_ft->fwd_rules, next_ft) {
666 err = mlx5_modify_rule_destination(iter, &dest);
668 pr_err("mlx5_core: failed to modify rule to point on flow table %d\n",
674 static int connect_flow_table(struct mlx5_core_dev *dev, struct mlx5_flow_table *ft,
675 struct fs_prio *prio)
677 struct mlx5_flow_table *next_ft;
680 /* Connect_prev_fts and update_root_ft_create are mutually exclusive */
682 if (list_empty(&prio->node.children)) {
683 err = connect_prev_fts(dev, ft, prio);
687 next_ft = find_next_chained_ft(prio);
688 err = connect_fwd_rules(dev, ft, next_ft);
693 if (MLX5_CAP_FLOWTABLE(dev,
694 flow_table_properties_nic_receive.modify_root))
695 err = update_root_ft_create(ft, prio);
699 struct mlx5_flow_table *mlx5_create_flow_table(struct mlx5_flow_namespace *ns,
703 struct mlx5_flow_table *next_ft = NULL;
704 struct mlx5_flow_table *ft;
707 struct mlx5_flow_root_namespace *root =
708 find_root(&ns->node);
709 struct fs_prio *fs_prio = NULL;
712 pr_err("mlx5: flow steering failed to find root of namespace\n");
713 return ERR_PTR(-ENODEV);
716 mutex_lock(&root->chain_lock);
717 fs_prio = find_prio(ns, prio);
722 if (fs_prio->num_ft == fs_prio->num_levels) {
727 ft = alloc_flow_table(find_next_free_level(fs_prio),
728 roundup_pow_of_two(max_fte),
735 tree_init_node(&ft->node, 1, del_flow_table);
736 log_table_sz = ilog2(ft->max_fte);
737 next_ft = find_next_chained_ft(fs_prio);
738 err = mlx5_cmd_create_flow_table(root->dev, ft->type, ft->level,
739 log_table_sz, next_ft, &ft->id);
743 err = connect_flow_table(root->dev, ft, fs_prio);
746 lock_ref_node(&fs_prio->node);
747 tree_add_node(&ft->node, &fs_prio->node);
748 list_add_tail(&ft->node.list, &fs_prio->node.children);
750 unlock_ref_node(&fs_prio->node);
751 mutex_unlock(&root->chain_lock);
754 mlx5_cmd_destroy_flow_table(root->dev, ft);
758 mutex_unlock(&root->chain_lock);
762 struct mlx5_flow_table *mlx5_create_auto_grouped_flow_table(struct mlx5_flow_namespace *ns,
764 int num_flow_table_entries,
767 struct mlx5_flow_table *ft;
769 if (max_num_groups > num_flow_table_entries)
770 return ERR_PTR(-EINVAL);
772 ft = mlx5_create_flow_table(ns, prio, num_flow_table_entries);
776 ft->autogroup.active = true;
777 ft->autogroup.required_groups = max_num_groups;
781 EXPORT_SYMBOL(mlx5_create_auto_grouped_flow_table);
783 /* Flow table should be locked */
784 static struct mlx5_flow_group *create_flow_group_common(struct mlx5_flow_table *ft,
790 struct mlx5_flow_group *fg;
791 struct mlx5_core_dev *dev = get_dev(&ft->node);
795 return ERR_PTR(-ENODEV);
797 fg = alloc_flow_group(fg_in);
801 err = mlx5_cmd_create_flow_group(dev, ft, fg_in, &fg->id);
807 if (ft->autogroup.active)
808 ft->autogroup.num_groups++;
809 /* Add node to tree */
810 tree_init_node(&fg->node, !is_auto_fg, del_flow_group);
811 tree_add_node(&fg->node, &ft->node);
812 /* Add node to group list */
813 list_add(&fg->node.list, ft->node.children.prev);
818 struct mlx5_flow_group *mlx5_create_flow_group(struct mlx5_flow_table *ft,
821 struct mlx5_flow_group *fg;
823 if (ft->autogroup.active)
824 return ERR_PTR(-EPERM);
826 lock_ref_node(&ft->node);
827 fg = create_flow_group_common(ft, fg_in, &ft->node.children, false);
828 unlock_ref_node(&ft->node);
833 static struct mlx5_flow_rule *alloc_rule(struct mlx5_flow_destination *dest)
835 struct mlx5_flow_rule *rule;
837 rule = kzalloc(sizeof(*rule), GFP_KERNEL);
841 INIT_LIST_HEAD(&rule->next_ft);
842 rule->node.type = FS_TYPE_FLOW_DEST;
844 memcpy(&rule->dest_attr, dest, sizeof(*dest));
849 /* fte should not be deleted while calling this function */
850 static struct mlx5_flow_rule *add_rule_fte(struct fs_fte *fte,
851 struct mlx5_flow_group *fg,
852 struct mlx5_flow_destination *dest)
854 struct mlx5_flow_table *ft;
855 struct mlx5_flow_rule *rule;
858 rule = alloc_rule(dest);
860 return ERR_PTR(-ENOMEM);
862 fs_get_obj(ft, fg->node.parent);
863 /* Add dest to dests list- we need flow tables to be in the
864 * end of the list for forward to next prio rules.
866 tree_init_node(&rule->node, 1, del_rule);
867 if (dest && dest->type != MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE)
868 list_add(&rule->node.list, &fte->node.children);
870 list_add_tail(&rule->node.list, &fte->node.children);
873 if (fte->dests_size == 1 || !dest)
874 err = mlx5_cmd_create_fte(get_dev(&ft->node),
877 err = mlx5_cmd_update_fte(get_dev(&ft->node),
882 fte->status |= FS_FTE_STATUS_EXISTING;
887 list_del(&rule->node.list);
894 /* Assumed fg is locked */
895 static unsigned int get_free_fte_index(struct mlx5_flow_group *fg,
896 struct list_head **prev)
899 unsigned int start = fg->start_index;
902 *prev = &fg->node.children;
904 /* assumed list is sorted by index */
905 fs_for_each_fte(fte, fg) {
906 if (fte->index != start)
910 *prev = &fte->node.list;
916 /* prev is output, prev->next = new_fte */
917 static struct fs_fte *create_fte(struct mlx5_flow_group *fg,
921 struct list_head **prev)
926 index = get_free_fte_index(fg, prev);
927 fte = alloc_fte(action, flow_tag, match_value, index);
934 static struct mlx5_flow_group *create_autogroup(struct mlx5_flow_table *ft,
935 u8 match_criteria_enable,
938 int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
939 struct list_head *prev = &ft->node.children;
940 unsigned int candidate_index = 0;
941 struct mlx5_flow_group *fg;
942 void *match_criteria_addr;
943 unsigned int group_size = 0;
946 if (!ft->autogroup.active)
947 return ERR_PTR(-ENOENT);
949 in = mlx5_vzalloc(inlen);
951 return ERR_PTR(-ENOMEM);
953 if (ft->autogroup.num_groups < ft->autogroup.required_groups)
954 /* We save place for flow groups in addition to max types */
955 group_size = ft->max_fte / (ft->autogroup.required_groups + 1);
957 /* ft->max_fte == ft->autogroup.max_types */
961 /* sorted by start_index */
962 fs_for_each_fg(fg, ft) {
963 if (candidate_index + group_size > fg->start_index)
964 candidate_index = fg->start_index + fg->max_ftes;
967 prev = &fg->node.list;
970 if (candidate_index + group_size > ft->max_fte) {
971 fg = ERR_PTR(-ENOSPC);
975 MLX5_SET(create_flow_group_in, in, match_criteria_enable,
976 match_criteria_enable);
977 MLX5_SET(create_flow_group_in, in, start_flow_index, candidate_index);
978 MLX5_SET(create_flow_group_in, in, end_flow_index, candidate_index +
980 match_criteria_addr = MLX5_ADDR_OF(create_flow_group_in,
982 memcpy(match_criteria_addr, match_criteria,
983 MLX5_ST_SZ_BYTES(fte_match_param));
985 fg = create_flow_group_common(ft, in, prev, true);
991 static struct mlx5_flow_rule *find_flow_rule(struct fs_fte *fte,
992 struct mlx5_flow_destination *dest)
994 struct mlx5_flow_rule *rule;
996 list_for_each_entry(rule, &fte->node.children, node.list) {
997 if (rule->dest_attr.type == dest->type) {
998 if ((dest->type == MLX5_FLOW_DESTINATION_TYPE_VPORT &&
999 dest->vport_num == rule->dest_attr.vport_num) ||
1000 (dest->type == MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE &&
1001 dest->ft == rule->dest_attr.ft) ||
1002 (dest->type == MLX5_FLOW_DESTINATION_TYPE_TIR &&
1003 dest->tir_num == rule->dest_attr.tir_num))
1010 static struct mlx5_flow_rule *add_rule_fg(struct mlx5_flow_group *fg,
1014 struct mlx5_flow_destination *dest)
1017 struct mlx5_flow_rule *rule;
1018 struct mlx5_flow_table *ft;
1019 struct list_head *prev;
1021 nested_lock_ref_node(&fg->node, FS_MUTEX_PARENT);
1022 fs_for_each_fte(fte, fg) {
1023 nested_lock_ref_node(&fte->node, FS_MUTEX_CHILD);
1024 if (compare_match_value(&fg->mask, match_value, &fte->val) &&
1025 action == fte->action && flow_tag == fte->flow_tag) {
1026 rule = find_flow_rule(fte, dest);
1028 atomic_inc(&rule->node.refcount);
1029 unlock_ref_node(&fte->node);
1030 unlock_ref_node(&fg->node);
1033 rule = add_rule_fte(fte, fg, dest);
1034 unlock_ref_node(&fte->node);
1040 unlock_ref_node(&fte->node);
1042 fs_get_obj(ft, fg->node.parent);
1043 if (fg->num_ftes >= fg->max_ftes) {
1044 rule = ERR_PTR(-ENOSPC);
1048 fte = create_fte(fg, match_value, action, flow_tag, &prev);
1053 tree_init_node(&fte->node, 0, del_fte);
1054 rule = add_rule_fte(fte, fg, dest);
1062 tree_add_node(&fte->node, &fg->node);
1063 list_add(&fte->node.list, prev);
1065 tree_add_node(&rule->node, &fte->node);
1067 unlock_ref_node(&fg->node);
1071 static struct mlx5_flow_rule *
1072 _mlx5_add_flow_rule(struct mlx5_flow_table *ft,
1073 u8 match_criteria_enable,
1074 u32 *match_criteria,
1078 struct mlx5_flow_destination *dest)
1080 struct mlx5_flow_group *g;
1081 struct mlx5_flow_rule *rule;
1083 if ((action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) && !dest)
1084 return ERR_PTR(-EINVAL);
1086 nested_lock_ref_node(&ft->node, FS_MUTEX_GRANDPARENT);
1087 fs_for_each_fg(g, ft)
1088 if (compare_match_criteria(g->mask.match_criteria_enable,
1089 match_criteria_enable,
1090 g->mask.match_criteria,
1092 rule = add_rule_fg(g, match_value,
1093 action, flow_tag, dest);
1094 if (!IS_ERR(rule) || PTR_ERR(rule) != -ENOSPC)
1098 g = create_autogroup(ft, match_criteria_enable, match_criteria);
1104 rule = add_rule_fg(g, match_value,
1105 action, flow_tag, dest);
1107 /* Remove assumes refcount > 0 and autogroup creates a group
1108 * with a refcount = 0.
1110 unlock_ref_node(&ft->node);
1111 tree_get_node(&g->node);
1112 tree_remove_node(&g->node);
1116 unlock_ref_node(&ft->node);
1120 static bool fwd_next_prio_supported(struct mlx5_flow_table *ft)
1122 return ((ft->type == FS_FT_NIC_RX) &&
1123 (MLX5_CAP_FLOWTABLE(get_dev(&ft->node), nic_rx_multi_path_tirs)));
1126 struct mlx5_flow_rule *
1127 mlx5_add_flow_rule(struct mlx5_flow_table *ft,
1128 u8 match_criteria_enable,
1129 u32 *match_criteria,
1133 struct mlx5_flow_destination *dest)
1135 struct mlx5_flow_root_namespace *root = find_root(&ft->node);
1136 struct mlx5_flow_destination gen_dest;
1137 struct mlx5_flow_table *next_ft = NULL;
1138 struct mlx5_flow_rule *rule = NULL;
1139 u32 sw_action = action;
1140 struct fs_prio *prio;
1142 fs_get_obj(prio, ft->node.parent);
1143 if (action == MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO) {
1144 if (!fwd_next_prio_supported(ft))
1145 return ERR_PTR(-EOPNOTSUPP);
1147 return ERR_PTR(-EINVAL);
1148 mutex_lock(&root->chain_lock);
1149 next_ft = find_next_chained_ft(prio);
1151 gen_dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
1152 gen_dest.ft = next_ft;
1154 action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
1156 mutex_unlock(&root->chain_lock);
1157 return ERR_PTR(-EOPNOTSUPP);
1161 rule = _mlx5_add_flow_rule(ft, match_criteria_enable, match_criteria,
1162 match_value, action, flow_tag, dest);
1164 if (sw_action == MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO) {
1165 if (!IS_ERR_OR_NULL(rule) &&
1166 (list_empty(&rule->next_ft))) {
1167 mutex_lock(&next_ft->lock);
1168 list_add(&rule->next_ft, &next_ft->fwd_rules);
1169 mutex_unlock(&next_ft->lock);
1170 rule->sw_action = MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO;
1172 mutex_unlock(&root->chain_lock);
1176 EXPORT_SYMBOL(mlx5_add_flow_rule);
1178 void mlx5_del_flow_rule(struct mlx5_flow_rule *rule)
1180 tree_remove_node(&rule->node);
1182 EXPORT_SYMBOL(mlx5_del_flow_rule);
1184 /* Assuming prio->node.children(flow tables) is sorted by level */
1185 static struct mlx5_flow_table *find_next_ft(struct mlx5_flow_table *ft)
1187 struct fs_prio *prio;
1189 fs_get_obj(prio, ft->node.parent);
1191 if (!list_is_last(&ft->node.list, &prio->node.children))
1192 return list_next_entry(ft, node.list);
1193 return find_next_chained_ft(prio);
1196 static int update_root_ft_destroy(struct mlx5_flow_table *ft)
1198 struct mlx5_flow_root_namespace *root = find_root(&ft->node);
1199 struct mlx5_flow_table *new_root_ft = NULL;
1201 if (root->root_ft != ft)
1204 new_root_ft = find_next_ft(ft);
1206 int err = mlx5_cmd_update_root_ft(root->dev, new_root_ft);
1209 mlx5_core_warn(root->dev, "Update root flow table of id=%u failed\n",
1213 root->root_ft = new_root_ft;
1218 /* Connect flow table from previous priority to
1219 * the next flow table.
1221 static int disconnect_flow_table(struct mlx5_flow_table *ft)
1223 struct mlx5_core_dev *dev = get_dev(&ft->node);
1224 struct mlx5_flow_table *next_ft;
1225 struct fs_prio *prio;
1228 err = update_root_ft_destroy(ft);
1232 fs_get_obj(prio, ft->node.parent);
1233 if (!(list_first_entry(&prio->node.children,
1234 struct mlx5_flow_table,
1238 next_ft = find_next_chained_ft(prio);
1239 err = connect_fwd_rules(dev, next_ft, ft);
1243 err = connect_prev_fts(dev, next_ft, prio);
1245 mlx5_core_warn(dev, "Failed to disconnect flow table %d\n",
1250 int mlx5_destroy_flow_table(struct mlx5_flow_table *ft)
1252 struct mlx5_flow_root_namespace *root = find_root(&ft->node);
1255 mutex_lock(&root->chain_lock);
1256 err = disconnect_flow_table(ft);
1258 mutex_unlock(&root->chain_lock);
1261 if (tree_remove_node(&ft->node))
1262 mlx5_core_warn(get_dev(&ft->node), "Flow table %d wasn't destroyed, refcount > 1\n",
1264 mutex_unlock(&root->chain_lock);
1268 EXPORT_SYMBOL(mlx5_destroy_flow_table);
1270 void mlx5_destroy_flow_group(struct mlx5_flow_group *fg)
1272 if (tree_remove_node(&fg->node))
1273 mlx5_core_warn(get_dev(&fg->node), "Flow group %d wasn't destroyed, refcount > 1\n",
1277 struct mlx5_flow_namespace *mlx5_get_flow_namespace(struct mlx5_core_dev *dev,
1278 enum mlx5_flow_namespace_type type)
1280 struct mlx5_flow_root_namespace *root_ns = dev->priv.root_ns;
1282 struct fs_prio *fs_prio;
1283 struct mlx5_flow_namespace *ns;
1289 case MLX5_FLOW_NAMESPACE_BYPASS:
1290 case MLX5_FLOW_NAMESPACE_KERNEL:
1291 case MLX5_FLOW_NAMESPACE_LEFTOVERS:
1292 case MLX5_FLOW_NAMESPACE_ANCHOR:
1295 case MLX5_FLOW_NAMESPACE_FDB:
1296 if (dev->priv.fdb_root_ns)
1297 return &dev->priv.fdb_root_ns->ns;
1304 fs_prio = find_prio(&root_ns->ns, prio);
1308 ns = list_first_entry(&fs_prio->node.children,
1314 EXPORT_SYMBOL(mlx5_get_flow_namespace);
1316 static struct fs_prio *fs_create_prio(struct mlx5_flow_namespace *ns,
1317 unsigned int prio, int num_levels)
1319 struct fs_prio *fs_prio;
1321 fs_prio = kzalloc(sizeof(*fs_prio), GFP_KERNEL);
1323 return ERR_PTR(-ENOMEM);
1325 fs_prio->node.type = FS_TYPE_PRIO;
1326 tree_init_node(&fs_prio->node, 1, NULL);
1327 tree_add_node(&fs_prio->node, &ns->node);
1328 fs_prio->num_levels = num_levels;
1329 fs_prio->prio = prio;
1330 list_add_tail(&fs_prio->node.list, &ns->node.children);
1335 static struct mlx5_flow_namespace *fs_init_namespace(struct mlx5_flow_namespace
1338 ns->node.type = FS_TYPE_NAMESPACE;
1343 static struct mlx5_flow_namespace *fs_create_namespace(struct fs_prio *prio)
1345 struct mlx5_flow_namespace *ns;
1347 ns = kzalloc(sizeof(*ns), GFP_KERNEL);
1349 return ERR_PTR(-ENOMEM);
1351 fs_init_namespace(ns);
1352 tree_init_node(&ns->node, 1, NULL);
1353 tree_add_node(&ns->node, &prio->node);
1354 list_add_tail(&ns->node.list, &prio->node.children);
1359 static int create_leaf_prios(struct mlx5_flow_namespace *ns, struct init_tree_node
1362 struct fs_prio *fs_prio;
1365 for (i = 0; i < prio_metadata->num_leaf_prios; i++) {
1366 fs_prio = fs_create_prio(ns, i, prio_metadata->num_levels);
1367 if (IS_ERR(fs_prio))
1368 return PTR_ERR(fs_prio);
1373 #define FLOW_TABLE_BIT_SZ 1
1374 #define GET_FLOW_TABLE_CAP(dev, offset) \
1375 ((be32_to_cpu(*((__be32 *)(dev->hca_caps_cur[MLX5_CAP_FLOW_TABLE]) + \
1377 (32 - FLOW_TABLE_BIT_SZ - (offset & 0x1f))) & FLOW_TABLE_BIT_SZ)
1378 static bool has_required_caps(struct mlx5_core_dev *dev, struct node_caps *caps)
1382 for (i = 0; i < caps->arr_sz; i++) {
1383 if (!GET_FLOW_TABLE_CAP(dev, caps->caps[i]))
1389 static int init_root_tree_recursive(struct mlx5_core_dev *dev,
1390 struct init_tree_node *init_node,
1391 struct fs_node *fs_parent_node,
1392 struct init_tree_node *init_parent_node,
1395 int max_ft_level = MLX5_CAP_FLOWTABLE(dev,
1396 flow_table_properties_nic_receive.
1398 struct mlx5_flow_namespace *fs_ns;
1399 struct fs_prio *fs_prio;
1400 struct fs_node *base;
1404 if (init_node->type == FS_TYPE_PRIO) {
1405 if ((init_node->min_ft_level > max_ft_level) ||
1406 !has_required_caps(dev, &init_node->caps))
1409 fs_get_obj(fs_ns, fs_parent_node);
1410 if (init_node->num_leaf_prios)
1411 return create_leaf_prios(fs_ns, init_node);
1412 fs_prio = fs_create_prio(fs_ns, index, init_node->num_levels);
1413 if (IS_ERR(fs_prio))
1414 return PTR_ERR(fs_prio);
1415 base = &fs_prio->node;
1416 } else if (init_node->type == FS_TYPE_NAMESPACE) {
1417 fs_get_obj(fs_prio, fs_parent_node);
1418 fs_ns = fs_create_namespace(fs_prio);
1420 return PTR_ERR(fs_ns);
1421 base = &fs_ns->node;
1425 for (i = 0; i < init_node->ar_size; i++) {
1426 err = init_root_tree_recursive(dev, &init_node->children[i],
1427 base, init_node, i);
1435 static int init_root_tree(struct mlx5_core_dev *dev,
1436 struct init_tree_node *init_node,
1437 struct fs_node *fs_parent_node)
1440 struct mlx5_flow_namespace *fs_ns;
1443 fs_get_obj(fs_ns, fs_parent_node);
1444 for (i = 0; i < init_node->ar_size; i++) {
1445 err = init_root_tree_recursive(dev, &init_node->children[i],
1454 static struct mlx5_flow_root_namespace *create_root_ns(struct mlx5_core_dev *dev,
1455 enum fs_flow_table_type
1458 struct mlx5_flow_root_namespace *root_ns;
1459 struct mlx5_flow_namespace *ns;
1461 /* Create the root namespace */
1462 root_ns = mlx5_vzalloc(sizeof(*root_ns));
1467 root_ns->table_type = table_type;
1470 fs_init_namespace(ns);
1471 mutex_init(&root_ns->chain_lock);
1472 tree_init_node(&ns->node, 1, NULL);
1473 tree_add_node(&ns->node, NULL);
1478 static void set_prio_attrs_in_prio(struct fs_prio *prio, int acc_level);
1480 static int set_prio_attrs_in_ns(struct mlx5_flow_namespace *ns, int acc_level)
1482 struct fs_prio *prio;
1484 fs_for_each_prio(prio, ns) {
1485 /* This updates prio start_level and num_levels */
1486 set_prio_attrs_in_prio(prio, acc_level);
1487 acc_level += prio->num_levels;
1492 static void set_prio_attrs_in_prio(struct fs_prio *prio, int acc_level)
1494 struct mlx5_flow_namespace *ns;
1495 int acc_level_ns = acc_level;
1497 prio->start_level = acc_level;
1498 fs_for_each_ns(ns, prio)
1499 /* This updates start_level and num_levels of ns's priority descendants */
1500 acc_level_ns = set_prio_attrs_in_ns(ns, acc_level);
1501 if (!prio->num_levels)
1502 prio->num_levels = acc_level_ns - prio->start_level;
1503 WARN_ON(prio->num_levels < acc_level_ns - prio->start_level);
1506 static void set_prio_attrs(struct mlx5_flow_root_namespace *root_ns)
1508 struct mlx5_flow_namespace *ns = &root_ns->ns;
1509 struct fs_prio *prio;
1510 int start_level = 0;
1512 fs_for_each_prio(prio, ns) {
1513 set_prio_attrs_in_prio(prio, start_level);
1514 start_level += prio->num_levels;
1518 #define ANCHOR_PRIO 0
1519 #define ANCHOR_SIZE 1
1520 static int create_anchor_flow_table(struct mlx5_core_dev
1523 struct mlx5_flow_namespace *ns = NULL;
1524 struct mlx5_flow_table *ft;
1526 ns = mlx5_get_flow_namespace(dev, MLX5_FLOW_NAMESPACE_ANCHOR);
1529 ft = mlx5_create_flow_table(ns, ANCHOR_PRIO, ANCHOR_SIZE);
1531 mlx5_core_err(dev, "Failed to create last anchor flow table");
1537 static int init_root_ns(struct mlx5_core_dev *dev)
1540 dev->priv.root_ns = create_root_ns(dev, FS_FT_NIC_RX);
1541 if (IS_ERR_OR_NULL(dev->priv.root_ns))
1544 if (init_root_tree(dev, &root_fs, &dev->priv.root_ns->ns.node))
1547 set_prio_attrs(dev->priv.root_ns);
1549 if (create_anchor_flow_table(dev))
1555 mlx5_cleanup_fs(dev);
1559 static void cleanup_single_prio_root_ns(struct mlx5_core_dev *dev,
1560 struct mlx5_flow_root_namespace *root_ns)
1562 struct fs_node *prio;
1567 if (!list_empty(&root_ns->ns.node.children)) {
1568 prio = list_first_entry(&root_ns->ns.node.children,
1571 if (tree_remove_node(prio))
1573 "Flow steering priority wasn't destroyed, refcount > 1\n");
1575 if (tree_remove_node(&root_ns->ns.node))
1577 "Flow steering namespace wasn't destroyed, refcount > 1\n");
1581 static void destroy_flow_tables(struct fs_prio *prio)
1583 struct mlx5_flow_table *iter;
1584 struct mlx5_flow_table *tmp;
1586 fs_for_each_ft_safe(iter, tmp, prio)
1587 mlx5_destroy_flow_table(iter);
1590 static void cleanup_root_ns(struct mlx5_core_dev *dev)
1592 struct mlx5_flow_root_namespace *root_ns = dev->priv.root_ns;
1593 struct fs_prio *iter_prio;
1595 if (!MLX5_CAP_GEN(dev, nic_flow_table))
1602 fs_for_each_prio(iter_prio, &root_ns->ns) {
1603 struct fs_node *node;
1604 struct mlx5_flow_namespace *iter_ns;
1606 fs_for_each_ns_or_ft(node, iter_prio) {
1607 if (node->type == FS_TYPE_FLOW_TABLE)
1609 fs_get_obj(iter_ns, node);
1610 while (!list_empty(&iter_ns->node.children)) {
1611 struct fs_prio *obj_iter_prio2;
1612 struct fs_node *iter_prio2 =
1613 list_first_entry(&iter_ns->node.children,
1617 fs_get_obj(obj_iter_prio2, iter_prio2);
1618 destroy_flow_tables(obj_iter_prio2);
1619 if (tree_remove_node(iter_prio2)) {
1621 "Priority %d wasn't destroyed, refcount > 1\n",
1622 obj_iter_prio2->prio);
1630 fs_for_each_prio(iter_prio, &root_ns->ns) {
1631 while (!list_empty(&iter_prio->node.children)) {
1632 struct fs_node *iter_ns =
1633 list_first_entry(&iter_prio->node.children,
1636 if (tree_remove_node(iter_ns)) {
1638 "Namespace wasn't destroyed, refcount > 1\n");
1645 while (!list_empty(&root_ns->ns.node.children)) {
1646 struct fs_prio *obj_prio_node;
1647 struct fs_node *prio_node =
1648 list_first_entry(&root_ns->ns.node.children,
1652 fs_get_obj(obj_prio_node, prio_node);
1653 if (tree_remove_node(prio_node)) {
1655 "Priority %d wasn't destroyed, refcount > 1\n",
1656 obj_prio_node->prio);
1661 if (tree_remove_node(&root_ns->ns.node)) {
1663 "root namespace wasn't destroyed, refcount > 1\n");
1667 dev->priv.root_ns = NULL;
1670 void mlx5_cleanup_fs(struct mlx5_core_dev *dev)
1672 cleanup_root_ns(dev);
1673 cleanup_single_prio_root_ns(dev, dev->priv.fdb_root_ns);
1676 static int init_fdb_root_ns(struct mlx5_core_dev *dev)
1678 struct fs_prio *prio;
1680 dev->priv.fdb_root_ns = create_root_ns(dev, FS_FT_FDB);
1681 if (!dev->priv.fdb_root_ns)
1684 /* Create single prio */
1685 prio = fs_create_prio(&dev->priv.fdb_root_ns->ns, 0, 1);
1687 cleanup_single_prio_root_ns(dev, dev->priv.fdb_root_ns);
1688 return PTR_ERR(prio);
1694 int mlx5_init_fs(struct mlx5_core_dev *dev)
1698 if (MLX5_CAP_GEN(dev, nic_flow_table)) {
1699 err = init_root_ns(dev);
1703 if (MLX5_CAP_GEN(dev, eswitch_flow_table)) {
1704 err = init_fdb_root_ns(dev);
1706 cleanup_root_ns(dev);