Lines Matching refs:lpm_tree
146 static void mlxsw_sp_lpm_tree_hold(struct mlxsw_sp_lpm_tree *lpm_tree);
148 struct mlxsw_sp_lpm_tree *lpm_tree);
435 struct mlxsw_sp_lpm_tree *lpm_tree; member
456 struct mlxsw_sp_lpm_tree *lpm_tree; in mlxsw_sp_fib_create() local
460 lpm_tree = mlxsw_sp->router->lpm.proto_trees[proto]; in mlxsw_sp_fib_create()
470 fib->lpm_tree = lpm_tree; in mlxsw_sp_fib_create()
471 mlxsw_sp_lpm_tree_hold(lpm_tree); in mlxsw_sp_fib_create()
472 err = mlxsw_sp_vr_lpm_tree_bind(mlxsw_sp, fib, lpm_tree->id); in mlxsw_sp_fib_create()
478 mlxsw_sp_lpm_tree_put(mlxsw_sp, lpm_tree); in mlxsw_sp_fib_create()
488 mlxsw_sp_lpm_tree_put(mlxsw_sp, fib->lpm_tree); in mlxsw_sp_fib_destroy()
497 static struct mlxsw_sp_lpm_tree *lpm_tree; in mlxsw_sp_lpm_tree_find_unused() local
501 lpm_tree = &mlxsw_sp->router->lpm.trees[i]; in mlxsw_sp_lpm_tree_find_unused()
502 if (lpm_tree->ref_count == 0) in mlxsw_sp_lpm_tree_find_unused()
503 return lpm_tree; in mlxsw_sp_lpm_tree_find_unused()
509 struct mlxsw_sp_lpm_tree *lpm_tree) in mlxsw_sp_lpm_tree_alloc() argument
514 (enum mlxsw_reg_ralxx_protocol) lpm_tree->proto, in mlxsw_sp_lpm_tree_alloc()
515 lpm_tree->id); in mlxsw_sp_lpm_tree_alloc()
520 struct mlxsw_sp_lpm_tree *lpm_tree) in mlxsw_sp_lpm_tree_free() argument
525 (enum mlxsw_reg_ralxx_protocol) lpm_tree->proto, in mlxsw_sp_lpm_tree_free()
526 lpm_tree->id); in mlxsw_sp_lpm_tree_free()
533 struct mlxsw_sp_lpm_tree *lpm_tree) in mlxsw_sp_lpm_tree_left_struct_set() argument
543 mlxsw_reg_ralst_pack(ralst_pl, root_bin, lpm_tree->id); in mlxsw_sp_lpm_tree_left_struct_set()
559 struct mlxsw_sp_lpm_tree *lpm_tree; in mlxsw_sp_lpm_tree_create() local
562 lpm_tree = mlxsw_sp_lpm_tree_find_unused(mlxsw_sp); in mlxsw_sp_lpm_tree_create()
563 if (!lpm_tree) in mlxsw_sp_lpm_tree_create()
565 lpm_tree->proto = proto; in mlxsw_sp_lpm_tree_create()
566 err = mlxsw_sp_lpm_tree_alloc(mlxsw_sp, lpm_tree); in mlxsw_sp_lpm_tree_create()
571 lpm_tree); in mlxsw_sp_lpm_tree_create()
574 memcpy(&lpm_tree->prefix_usage, prefix_usage, in mlxsw_sp_lpm_tree_create()
575 sizeof(lpm_tree->prefix_usage)); in mlxsw_sp_lpm_tree_create()
576 memset(&lpm_tree->prefix_ref_count, 0, in mlxsw_sp_lpm_tree_create()
577 sizeof(lpm_tree->prefix_ref_count)); in mlxsw_sp_lpm_tree_create()
578 lpm_tree->ref_count = 1; in mlxsw_sp_lpm_tree_create()
579 return lpm_tree; in mlxsw_sp_lpm_tree_create()
582 mlxsw_sp_lpm_tree_free(mlxsw_sp, lpm_tree); in mlxsw_sp_lpm_tree_create()
587 struct mlxsw_sp_lpm_tree *lpm_tree) in mlxsw_sp_lpm_tree_destroy() argument
589 mlxsw_sp_lpm_tree_free(mlxsw_sp, lpm_tree); in mlxsw_sp_lpm_tree_destroy()
597 struct mlxsw_sp_lpm_tree *lpm_tree; in mlxsw_sp_lpm_tree_get() local
601 lpm_tree = &mlxsw_sp->router->lpm.trees[i]; in mlxsw_sp_lpm_tree_get()
602 if (lpm_tree->ref_count != 0 && in mlxsw_sp_lpm_tree_get()
603 lpm_tree->proto == proto && in mlxsw_sp_lpm_tree_get()
604 mlxsw_sp_prefix_usage_eq(&lpm_tree->prefix_usage, in mlxsw_sp_lpm_tree_get()
606 mlxsw_sp_lpm_tree_hold(lpm_tree); in mlxsw_sp_lpm_tree_get()
607 return lpm_tree; in mlxsw_sp_lpm_tree_get()
613 static void mlxsw_sp_lpm_tree_hold(struct mlxsw_sp_lpm_tree *lpm_tree) in mlxsw_sp_lpm_tree_hold() argument
615 lpm_tree->ref_count++; in mlxsw_sp_lpm_tree_hold()
619 struct mlxsw_sp_lpm_tree *lpm_tree) in mlxsw_sp_lpm_tree_put() argument
621 if (--lpm_tree->ref_count == 0) in mlxsw_sp_lpm_tree_put()
622 mlxsw_sp_lpm_tree_destroy(mlxsw_sp, lpm_tree); in mlxsw_sp_lpm_tree_put()
630 struct mlxsw_sp_lpm_tree *lpm_tree; in mlxsw_sp_lpm_init() local
646 lpm_tree = &mlxsw_sp->router->lpm.trees[i]; in mlxsw_sp_lpm_init()
647 lpm_tree->id = i + MLXSW_SP_LPM_TREE_MIN; in mlxsw_sp_lpm_init()
650 lpm_tree = mlxsw_sp_lpm_tree_get(mlxsw_sp, &req_prefix_usage, in mlxsw_sp_lpm_init()
652 if (IS_ERR(lpm_tree)) { in mlxsw_sp_lpm_init()
653 err = PTR_ERR(lpm_tree); in mlxsw_sp_lpm_init()
656 mlxsw_sp->router->lpm.proto_trees[MLXSW_SP_L3_PROTO_IPV4] = lpm_tree; in mlxsw_sp_lpm_init()
658 lpm_tree = mlxsw_sp_lpm_tree_get(mlxsw_sp, &req_prefix_usage, in mlxsw_sp_lpm_init()
660 if (IS_ERR(lpm_tree)) { in mlxsw_sp_lpm_init()
661 err = PTR_ERR(lpm_tree); in mlxsw_sp_lpm_init()
664 mlxsw_sp->router->lpm.proto_trees[MLXSW_SP_L3_PROTO_IPV6] = lpm_tree; in mlxsw_sp_lpm_init()
669 lpm_tree = mlxsw_sp->router->lpm.proto_trees[MLXSW_SP_L3_PROTO_IPV4]; in mlxsw_sp_lpm_init()
670 mlxsw_sp_lpm_tree_put(mlxsw_sp, lpm_tree); in mlxsw_sp_lpm_init()
678 struct mlxsw_sp_lpm_tree *lpm_tree; in mlxsw_sp_lpm_fini() local
680 lpm_tree = mlxsw_sp->router->lpm.proto_trees[MLXSW_SP_L3_PROTO_IPV6]; in mlxsw_sp_lpm_fini()
681 mlxsw_sp_lpm_tree_put(mlxsw_sp, lpm_tree); in mlxsw_sp_lpm_fini()
683 lpm_tree = mlxsw_sp->router->lpm.proto_trees[MLXSW_SP_L3_PROTO_IPV4]; in mlxsw_sp_lpm_fini()
684 mlxsw_sp_lpm_tree_put(mlxsw_sp, lpm_tree); in mlxsw_sp_lpm_fini()
874 if (fib->lpm_tree->id == tree_id) in mlxsw_sp_vr_lpm_tree_should_replace()
883 struct mlxsw_sp_lpm_tree *old_tree = fib->lpm_tree; in mlxsw_sp_vr_lpm_tree_replace()
886 fib->lpm_tree = new_tree; in mlxsw_sp_vr_lpm_tree_replace()
896 fib->lpm_tree = old_tree; in mlxsw_sp_vr_lpm_tree_replace()
4537 struct mlxsw_sp_lpm_tree *lpm_tree; in mlxsw_sp_fib_lpm_tree_link() local
4540 lpm_tree = mlxsw_sp->router->lpm.proto_trees[fib->proto]; in mlxsw_sp_fib_lpm_tree_link()
4541 if (lpm_tree->prefix_ref_count[fib_node->key.prefix_len] != 0) in mlxsw_sp_fib_lpm_tree_link()
4544 mlxsw_sp_prefix_usage_cpy(&req_prefix_usage, &lpm_tree->prefix_usage); in mlxsw_sp_fib_lpm_tree_link()
4546 lpm_tree = mlxsw_sp_lpm_tree_get(mlxsw_sp, &req_prefix_usage, in mlxsw_sp_fib_lpm_tree_link()
4548 if (IS_ERR(lpm_tree)) in mlxsw_sp_fib_lpm_tree_link()
4549 return PTR_ERR(lpm_tree); in mlxsw_sp_fib_lpm_tree_link()
4551 err = mlxsw_sp_vrs_lpm_tree_replace(mlxsw_sp, fib, lpm_tree); in mlxsw_sp_fib_lpm_tree_link()
4556 lpm_tree->prefix_ref_count[fib_node->key.prefix_len]++; in mlxsw_sp_fib_lpm_tree_link()
4560 mlxsw_sp_lpm_tree_put(mlxsw_sp, lpm_tree); in mlxsw_sp_fib_lpm_tree_link()
4567 struct mlxsw_sp_lpm_tree *lpm_tree = fib_node->fib->lpm_tree; in mlxsw_sp_fib_lpm_tree_unlink() local
4572 if (--lpm_tree->prefix_ref_count[fib_node->key.prefix_len] != 0) in mlxsw_sp_fib_lpm_tree_unlink()
4577 mlxsw_sp_prefix_usage_cpy(&req_prefix_usage, &lpm_tree->prefix_usage); in mlxsw_sp_fib_lpm_tree_unlink()
4580 lpm_tree = mlxsw_sp_lpm_tree_get(mlxsw_sp, &req_prefix_usage, in mlxsw_sp_fib_lpm_tree_unlink()
4582 if (IS_ERR(lpm_tree)) in mlxsw_sp_fib_lpm_tree_unlink()
4585 err = mlxsw_sp_vrs_lpm_tree_replace(mlxsw_sp, fib, lpm_tree); in mlxsw_sp_fib_lpm_tree_unlink()
4592 mlxsw_sp_lpm_tree_put(mlxsw_sp, lpm_tree); in mlxsw_sp_fib_lpm_tree_unlink()