Lines Matching refs:lpm_tree
164 static void mlxsw_sp_lpm_tree_hold(struct mlxsw_sp_lpm_tree *lpm_tree);
166 struct mlxsw_sp_lpm_tree *lpm_tree);
515 struct mlxsw_sp_lpm_tree *lpm_tree; member
536 struct mlxsw_sp_lpm_tree *lpm_tree; in mlxsw_sp_fib_create() local
540 lpm_tree = mlxsw_sp->router->lpm.proto_trees[proto]; in mlxsw_sp_fib_create()
550 fib->lpm_tree = lpm_tree; in mlxsw_sp_fib_create()
551 mlxsw_sp_lpm_tree_hold(lpm_tree); in mlxsw_sp_fib_create()
552 err = mlxsw_sp_vr_lpm_tree_bind(mlxsw_sp, fib, lpm_tree->id); in mlxsw_sp_fib_create()
558 mlxsw_sp_lpm_tree_put(mlxsw_sp, lpm_tree); in mlxsw_sp_fib_create()
568 mlxsw_sp_lpm_tree_put(mlxsw_sp, fib->lpm_tree); in mlxsw_sp_fib_destroy()
577 static struct mlxsw_sp_lpm_tree *lpm_tree; in mlxsw_sp_lpm_tree_find_unused() local
581 lpm_tree = &mlxsw_sp->router->lpm.trees[i]; in mlxsw_sp_lpm_tree_find_unused()
582 if (refcount_read(&lpm_tree->ref_count) == 0) in mlxsw_sp_lpm_tree_find_unused()
583 return lpm_tree; in mlxsw_sp_lpm_tree_find_unused()
589 struct mlxsw_sp_lpm_tree *lpm_tree) in mlxsw_sp_lpm_tree_alloc() argument
594 (enum mlxsw_reg_ralxx_protocol) lpm_tree->proto, in mlxsw_sp_lpm_tree_alloc()
595 lpm_tree->id); in mlxsw_sp_lpm_tree_alloc()
600 struct mlxsw_sp_lpm_tree *lpm_tree) in mlxsw_sp_lpm_tree_free() argument
605 (enum mlxsw_reg_ralxx_protocol) lpm_tree->proto, in mlxsw_sp_lpm_tree_free()
606 lpm_tree->id); in mlxsw_sp_lpm_tree_free()
613 struct mlxsw_sp_lpm_tree *lpm_tree) in mlxsw_sp_lpm_tree_left_struct_set() argument
623 mlxsw_reg_ralst_pack(ralst_pl, root_bin, lpm_tree->id); in mlxsw_sp_lpm_tree_left_struct_set()
639 struct mlxsw_sp_lpm_tree *lpm_tree; in mlxsw_sp_lpm_tree_create() local
642 lpm_tree = mlxsw_sp_lpm_tree_find_unused(mlxsw_sp); in mlxsw_sp_lpm_tree_create()
643 if (!lpm_tree) in mlxsw_sp_lpm_tree_create()
645 lpm_tree->proto = proto; in mlxsw_sp_lpm_tree_create()
646 err = mlxsw_sp_lpm_tree_alloc(mlxsw_sp, lpm_tree); in mlxsw_sp_lpm_tree_create()
651 lpm_tree); in mlxsw_sp_lpm_tree_create()
654 memcpy(&lpm_tree->prefix_usage, prefix_usage, in mlxsw_sp_lpm_tree_create()
655 sizeof(lpm_tree->prefix_usage)); in mlxsw_sp_lpm_tree_create()
656 memset(&lpm_tree->prefix_ref_count, 0, in mlxsw_sp_lpm_tree_create()
657 sizeof(lpm_tree->prefix_ref_count)); in mlxsw_sp_lpm_tree_create()
658 refcount_set(&lpm_tree->ref_count, 1); in mlxsw_sp_lpm_tree_create()
659 return lpm_tree; in mlxsw_sp_lpm_tree_create()
662 mlxsw_sp_lpm_tree_free(mlxsw_sp, lpm_tree); in mlxsw_sp_lpm_tree_create()
667 struct mlxsw_sp_lpm_tree *lpm_tree) in mlxsw_sp_lpm_tree_destroy() argument
669 mlxsw_sp_lpm_tree_free(mlxsw_sp, lpm_tree); in mlxsw_sp_lpm_tree_destroy()
677 struct mlxsw_sp_lpm_tree *lpm_tree; in mlxsw_sp_lpm_tree_get() local
681 lpm_tree = &mlxsw_sp->router->lpm.trees[i]; in mlxsw_sp_lpm_tree_get()
682 if (refcount_read(&lpm_tree->ref_count) && in mlxsw_sp_lpm_tree_get()
683 lpm_tree->proto == proto && in mlxsw_sp_lpm_tree_get()
684 mlxsw_sp_prefix_usage_eq(&lpm_tree->prefix_usage, in mlxsw_sp_lpm_tree_get()
686 mlxsw_sp_lpm_tree_hold(lpm_tree); in mlxsw_sp_lpm_tree_get()
687 return lpm_tree; in mlxsw_sp_lpm_tree_get()
693 static void mlxsw_sp_lpm_tree_hold(struct mlxsw_sp_lpm_tree *lpm_tree) in mlxsw_sp_lpm_tree_hold() argument
695 refcount_inc(&lpm_tree->ref_count); in mlxsw_sp_lpm_tree_hold()
699 struct mlxsw_sp_lpm_tree *lpm_tree) in mlxsw_sp_lpm_tree_put() argument
701 if (!refcount_dec_and_test(&lpm_tree->ref_count)) in mlxsw_sp_lpm_tree_put()
703 mlxsw_sp_lpm_tree_destroy(mlxsw_sp, lpm_tree); in mlxsw_sp_lpm_tree_put()
711 struct mlxsw_sp_lpm_tree *lpm_tree; in mlxsw_sp_lpm_init() local
727 lpm_tree = &mlxsw_sp->router->lpm.trees[i]; in mlxsw_sp_lpm_init()
728 lpm_tree->id = i + MLXSW_SP_LPM_TREE_MIN; in mlxsw_sp_lpm_init()
731 lpm_tree = mlxsw_sp_lpm_tree_get(mlxsw_sp, &req_prefix_usage, in mlxsw_sp_lpm_init()
733 if (IS_ERR(lpm_tree)) { in mlxsw_sp_lpm_init()
734 err = PTR_ERR(lpm_tree); in mlxsw_sp_lpm_init()
737 mlxsw_sp->router->lpm.proto_trees[MLXSW_SP_L3_PROTO_IPV4] = lpm_tree; in mlxsw_sp_lpm_init()
739 lpm_tree = mlxsw_sp_lpm_tree_get(mlxsw_sp, &req_prefix_usage, in mlxsw_sp_lpm_init()
741 if (IS_ERR(lpm_tree)) { in mlxsw_sp_lpm_init()
742 err = PTR_ERR(lpm_tree); in mlxsw_sp_lpm_init()
745 mlxsw_sp->router->lpm.proto_trees[MLXSW_SP_L3_PROTO_IPV6] = lpm_tree; in mlxsw_sp_lpm_init()
750 lpm_tree = mlxsw_sp->router->lpm.proto_trees[MLXSW_SP_L3_PROTO_IPV4]; in mlxsw_sp_lpm_init()
751 mlxsw_sp_lpm_tree_put(mlxsw_sp, lpm_tree); in mlxsw_sp_lpm_init()
759 struct mlxsw_sp_lpm_tree *lpm_tree; in mlxsw_sp_lpm_fini() local
761 lpm_tree = mlxsw_sp->router->lpm.proto_trees[MLXSW_SP_L3_PROTO_IPV6]; in mlxsw_sp_lpm_fini()
762 mlxsw_sp_lpm_tree_put(mlxsw_sp, lpm_tree); in mlxsw_sp_lpm_fini()
764 lpm_tree = mlxsw_sp->router->lpm.proto_trees[MLXSW_SP_L3_PROTO_IPV4]; in mlxsw_sp_lpm_fini()
765 mlxsw_sp_lpm_tree_put(mlxsw_sp, lpm_tree); in mlxsw_sp_lpm_fini()
962 if (fib->lpm_tree->id == tree_id) in mlxsw_sp_vr_lpm_tree_should_replace()
971 struct mlxsw_sp_lpm_tree *old_tree = fib->lpm_tree; in mlxsw_sp_vr_lpm_tree_replace()
974 fib->lpm_tree = new_tree; in mlxsw_sp_vr_lpm_tree_replace()
984 fib->lpm_tree = old_tree; in mlxsw_sp_vr_lpm_tree_replace()
6622 struct mlxsw_sp_lpm_tree *lpm_tree; in mlxsw_sp_fib_lpm_tree_link() local
6625 lpm_tree = mlxsw_sp->router->lpm.proto_trees[fib->proto]; in mlxsw_sp_fib_lpm_tree_link()
6626 if (lpm_tree->prefix_ref_count[fib_node->key.prefix_len] != 0) in mlxsw_sp_fib_lpm_tree_link()
6629 mlxsw_sp_prefix_usage_cpy(&req_prefix_usage, &lpm_tree->prefix_usage); in mlxsw_sp_fib_lpm_tree_link()
6631 lpm_tree = mlxsw_sp_lpm_tree_get(mlxsw_sp, &req_prefix_usage, in mlxsw_sp_fib_lpm_tree_link()
6633 if (IS_ERR(lpm_tree)) in mlxsw_sp_fib_lpm_tree_link()
6634 return PTR_ERR(lpm_tree); in mlxsw_sp_fib_lpm_tree_link()
6636 err = mlxsw_sp_vrs_lpm_tree_replace(mlxsw_sp, fib, lpm_tree); in mlxsw_sp_fib_lpm_tree_link()
6641 lpm_tree->prefix_ref_count[fib_node->key.prefix_len]++; in mlxsw_sp_fib_lpm_tree_link()
6645 mlxsw_sp_lpm_tree_put(mlxsw_sp, lpm_tree); in mlxsw_sp_fib_lpm_tree_link()
6652 struct mlxsw_sp_lpm_tree *lpm_tree = fib_node->fib->lpm_tree; in mlxsw_sp_fib_lpm_tree_unlink() local
6657 if (--lpm_tree->prefix_ref_count[fib_node->key.prefix_len] != 0) in mlxsw_sp_fib_lpm_tree_unlink()
6662 mlxsw_sp_prefix_usage_cpy(&req_prefix_usage, &lpm_tree->prefix_usage); in mlxsw_sp_fib_lpm_tree_unlink()
6665 lpm_tree = mlxsw_sp_lpm_tree_get(mlxsw_sp, &req_prefix_usage, in mlxsw_sp_fib_lpm_tree_unlink()
6667 if (IS_ERR(lpm_tree)) in mlxsw_sp_fib_lpm_tree_unlink()
6670 err = mlxsw_sp_vrs_lpm_tree_replace(mlxsw_sp, fib, lpm_tree); in mlxsw_sp_fib_lpm_tree_unlink()
6677 mlxsw_sp_lpm_tree_put(mlxsw_sp, lpm_tree); in mlxsw_sp_fib_lpm_tree_unlink()