Lines Matching refs:sw

54 static int prestera_nexthop_group_set(struct prestera_switch *sw,
57 prestera_nexthop_group_util_hw_state(struct prestera_switch *sw,
67 int prestera_router_hw_init(struct prestera_switch *sw) in prestera_router_hw_init() argument
71 err = rhashtable_init(&sw->router->nh_neigh_ht, in prestera_router_hw_init()
76 err = rhashtable_init(&sw->router->nexthop_group_ht, in prestera_router_hw_init()
81 err = rhashtable_init(&sw->router->fib_ht, in prestera_router_hw_init()
86 INIT_LIST_HEAD(&sw->router->vr_list); in prestera_router_hw_init()
87 INIT_LIST_HEAD(&sw->router->rif_entry_list); in prestera_router_hw_init()
92 rhashtable_destroy(&sw->router->nexthop_group_ht); in prestera_router_hw_init()
94 rhashtable_destroy(&sw->router->nh_neigh_ht); in prestera_router_hw_init()
99 void prestera_router_hw_fini(struct prestera_switch *sw) in prestera_router_hw_fini() argument
101 rhashtable_free_and_destroy(&sw->router->fib_ht, in prestera_router_hw_fini()
102 prestera_fib_node_destroy_ht_cb, sw); in prestera_router_hw_fini()
103 WARN_ON(!list_empty(&sw->router->vr_list)); in prestera_router_hw_fini()
104 WARN_ON(!list_empty(&sw->router->rif_entry_list)); in prestera_router_hw_fini()
105 rhashtable_destroy(&sw->router->fib_ht); in prestera_router_hw_fini()
106 rhashtable_destroy(&sw->router->nexthop_group_ht); in prestera_router_hw_fini()
107 rhashtable_destroy(&sw->router->nh_neigh_ht); in prestera_router_hw_fini()
110 static struct prestera_vr *__prestera_vr_find(struct prestera_switch *sw, in __prestera_vr_find() argument
115 list_for_each_entry(vr, &sw->router->vr_list, router_node) { in __prestera_vr_find()
123 static struct prestera_vr *__prestera_vr_create(struct prestera_switch *sw, in __prestera_vr_create() argument
138 err = prestera_hw_vr_create(sw, &vr->hw_vr_id); in __prestera_vr_create()
142 list_add(&vr->router_node, &sw->router->vr_list); in __prestera_vr_create()
152 static void __prestera_vr_destroy(struct prestera_switch *sw, in __prestera_vr_destroy() argument
156 prestera_hw_vr_delete(sw, vr->hw_vr_id); in __prestera_vr_destroy()
160 static struct prestera_vr *prestera_vr_get(struct prestera_switch *sw, u32 tb_id, in prestera_vr_get() argument
165 vr = __prestera_vr_find(sw, tb_id); in prestera_vr_get()
169 vr = __prestera_vr_create(sw, tb_id, extack); in prestera_vr_get()
179 static void prestera_vr_put(struct prestera_switch *sw, struct prestera_vr *vr) in prestera_vr_put() argument
182 __prestera_vr_destroy(sw, vr); in prestera_vr_put()
213 prestera_rif_entry_find(const struct prestera_switch *sw, in prestera_rif_entry_find() argument
222 list_for_each_entry(rif_entry, &sw->router->rif_entry_list, in prestera_rif_entry_find()
231 void prestera_rif_entry_destroy(struct prestera_switch *sw, in prestera_rif_entry_destroy() argument
240 prestera_hw_rif_delete(sw, e->hw_id, &iface); in prestera_rif_entry_destroy()
242 prestera_vr_put(sw, e->vr); in prestera_rif_entry_destroy()
247 prestera_rif_entry_create(struct prestera_switch *sw, in prestera_rif_entry_create() argument
262 e->vr = prestera_vr_get(sw, tb_id, NULL); in prestera_rif_entry_create()
271 err = prestera_hw_rif_create(sw, &iface, e->addr, &e->hw_id); in prestera_rif_entry_create()
275 list_add(&e->router_node, &sw->router->rif_entry_list); in prestera_rif_entry_create()
280 prestera_vr_put(sw, e->vr); in prestera_rif_entry_create()
288 static void __prestera_nh_neigh_destroy(struct prestera_switch *sw, in __prestera_nh_neigh_destroy() argument
291 rhashtable_remove_fast(&sw->router->nh_neigh_ht, in __prestera_nh_neigh_destroy()
298 __prestera_nh_neigh_create(struct prestera_switch *sw, in __prestera_nh_neigh_create() argument
311 err = rhashtable_insert_fast(&sw->router->nh_neigh_ht, in __prestera_nh_neigh_create()
326 prestera_nh_neigh_find(struct prestera_switch *sw, in prestera_nh_neigh_find() argument
331 nh_neigh = rhashtable_lookup_fast(&sw->router->nh_neigh_ht, in prestera_nh_neigh_find()
337 prestera_nh_neigh_get(struct prestera_switch *sw, in prestera_nh_neigh_get() argument
342 neigh = prestera_nh_neigh_find(sw, key); in prestera_nh_neigh_get()
344 return __prestera_nh_neigh_create(sw, key); in prestera_nh_neigh_get()
349 void prestera_nh_neigh_put(struct prestera_switch *sw, in prestera_nh_neigh_put() argument
353 __prestera_nh_neigh_destroy(sw, neigh); in prestera_nh_neigh_put()
357 int prestera_nh_neigh_set(struct prestera_switch *sw, in prestera_nh_neigh_set() argument
366 err = prestera_nexthop_group_set(sw, nh_grp); in prestera_nh_neigh_set()
374 bool prestera_nh_neigh_util_hw_state(struct prestera_switch *sw, in prestera_nh_neigh_util_hw_state() argument
383 state = prestera_nexthop_group_util_hw_state(sw, nh_head->this); in prestera_nh_neigh_util_hw_state()
393 __prestera_nexthop_group_create(struct prestera_switch *sw, in __prestera_nexthop_group_create() argument
409 nh_neigh = prestera_nh_neigh_get(sw, in __prestera_nexthop_group_create()
420 err = prestera_hw_nh_group_create(sw, nh_cnt, &nh_grp->grp_id); in __prestera_nexthop_group_create()
424 err = prestera_nexthop_group_set(sw, nh_grp); in __prestera_nexthop_group_create()
428 err = rhashtable_insert_fast(&sw->router->nexthop_group_ht, in __prestera_nexthop_group_create()
436 sw->router->nhgrp_hw_state_cache[gid / 8] &= ~BIT(gid % 8); in __prestera_nexthop_group_create()
442 prestera_hw_nh_group_delete(sw, nh_cnt, nh_grp->grp_id); in __prestera_nexthop_group_create()
447 prestera_nh_neigh_put(sw, nh_grp->nh_neigh_head[nh_cnt].neigh); in __prestera_nexthop_group_create()
456 __prestera_nexthop_group_destroy(struct prestera_switch *sw, in __prestera_nexthop_group_destroy() argument
462 rhashtable_remove_fast(&sw->router->nexthop_group_ht, in __prestera_nexthop_group_destroy()
472 prestera_nh_neigh_put(sw, nh_neigh); in __prestera_nexthop_group_destroy()
475 prestera_hw_nh_group_delete(sw, nh_cnt, nh_grp->grp_id); in __prestera_nexthop_group_destroy()
480 __prestera_nexthop_group_find(struct prestera_switch *sw, in __prestera_nexthop_group_find() argument
485 nh_grp = rhashtable_lookup_fast(&sw->router->nexthop_group_ht, in __prestera_nexthop_group_find()
491 prestera_nexthop_group_get(struct prestera_switch *sw, in prestera_nexthop_group_get() argument
496 nh_grp = __prestera_nexthop_group_find(sw, key); in prestera_nexthop_group_get()
500 nh_grp = __prestera_nexthop_group_create(sw, key); in prestera_nexthop_group_get()
510 static void prestera_nexthop_group_put(struct prestera_switch *sw, in prestera_nexthop_group_put() argument
514 __prestera_nexthop_group_destroy(sw, nh_grp); in prestera_nexthop_group_put()
518 static int prestera_nexthop_group_set(struct prestera_switch *sw, in prestera_nexthop_group_set() argument
534 return prestera_hw_nh_entries_set(sw, nh_cnt, &info[0], nh_grp->grp_id); in prestera_nexthop_group_set()
538 prestera_nexthop_group_util_hw_state(struct prestera_switch *sw, in prestera_nexthop_group_util_hw_state() argument
542 u32 buf_size = sw->size_tbl_router_nexthop / 8 + 1; in prestera_nexthop_group_util_hw_state()
544 u8 *cache = sw->router->nhgrp_hw_state_cache; in prestera_nexthop_group_util_hw_state()
551 if (!time_before(jiffies, sw->router->nhgrp_hw_cache_kick + in prestera_nexthop_group_util_hw_state()
553 err = prestera_hw_nhgrp_blk_get(sw, cache, buf_size); in prestera_nexthop_group_util_hw_state()
559 sw->router->nhgrp_hw_cache_kick = jiffies; in prestera_nexthop_group_util_hw_state()
569 prestera_fib_node_find(struct prestera_switch *sw, struct prestera_fib_key *key) in prestera_fib_node_find() argument
573 fib_node = rhashtable_lookup_fast(&sw->router->fib_ht, key, in prestera_fib_node_find()
578 static void __prestera_fib_node_destruct(struct prestera_switch *sw, in __prestera_fib_node_destruct() argument
584 prestera_hw_lpm_del(sw, vr->hw_vr_id, fib_node->key.addr.u.ipv4, in __prestera_fib_node_destruct()
588 prestera_nexthop_group_put(sw, fib_node->info.nh_grp); in __prestera_fib_node_destruct()
599 prestera_vr_put(sw, vr); in __prestera_fib_node_destruct()
602 void prestera_fib_node_destroy(struct prestera_switch *sw, in prestera_fib_node_destroy() argument
605 __prestera_fib_node_destruct(sw, fib_node); in prestera_fib_node_destroy()
606 rhashtable_remove_fast(&sw->router->fib_ht, &fib_node->ht_node, in prestera_fib_node_destroy()
614 struct prestera_switch *sw = arg; in prestera_fib_node_destroy_ht_cb() local
616 __prestera_fib_node_destruct(sw, node); in prestera_fib_node_destroy_ht_cb()
621 prestera_fib_node_create(struct prestera_switch *sw, in prestera_fib_node_create() argument
638 vr = prestera_vr_get(sw, key->tb_id, NULL); in prestera_fib_node_create()
652 fib_node->info.nh_grp = prestera_nexthop_group_get(sw, in prestera_fib_node_create()
664 err = prestera_hw_lpm_add(sw, vr->hw_vr_id, key->addr.u.ipv4, in prestera_fib_node_create()
669 err = rhashtable_insert_fast(&sw->router->fib_ht, &fib_node->ht_node, in prestera_fib_node_create()
677 prestera_hw_lpm_del(sw, vr->hw_vr_id, key->addr.u.ipv4, in prestera_fib_node_create()
681 prestera_nexthop_group_put(sw, fib_node->info.nh_grp); in prestera_fib_node_create()
683 prestera_vr_put(sw, vr); in prestera_fib_node_create()