Lines Matching refs:id_tbl

607 static int cnic_init_id_tbl(struct cnic_id_tbl *id_tbl, u32 size, u32 start_id)  in cnic_init_id_tbl()  argument
609 id_tbl->start = start_id; in cnic_init_id_tbl()
610 id_tbl->max = size; in cnic_init_id_tbl()
611 id_tbl->next = 0; in cnic_init_id_tbl()
612 spin_lock_init(&id_tbl->lock); in cnic_init_id_tbl()
613 id_tbl->table = kzalloc(DIV_ROUND_UP(size, 32) * 4, GFP_KERNEL); in cnic_init_id_tbl()
614 if (!id_tbl->table) in cnic_init_id_tbl()
620 static void cnic_free_id_tbl(struct cnic_id_tbl *id_tbl) in cnic_free_id_tbl() argument
622 kfree(id_tbl->table); in cnic_free_id_tbl()
623 id_tbl->table = NULL; in cnic_free_id_tbl()
626 static int cnic_alloc_id(struct cnic_id_tbl *id_tbl, u32 id) in cnic_alloc_id() argument
630 id -= id_tbl->start; in cnic_alloc_id()
631 if (id >= id_tbl->max) in cnic_alloc_id()
634 spin_lock(&id_tbl->lock); in cnic_alloc_id()
635 if (!test_bit(id, id_tbl->table)) { in cnic_alloc_id()
636 set_bit(id, id_tbl->table); in cnic_alloc_id()
639 spin_unlock(&id_tbl->lock); in cnic_alloc_id()
644 static u32 cnic_alloc_new_id(struct cnic_id_tbl *id_tbl) in cnic_alloc_new_id() argument
648 spin_lock(&id_tbl->lock); in cnic_alloc_new_id()
649 id = find_next_zero_bit(id_tbl->table, id_tbl->max, id_tbl->next); in cnic_alloc_new_id()
650 if (id >= id_tbl->max) { in cnic_alloc_new_id()
652 if (id_tbl->next != 0) { in cnic_alloc_new_id()
653 id = find_first_zero_bit(id_tbl->table, id_tbl->next); in cnic_alloc_new_id()
654 if (id >= id_tbl->next) in cnic_alloc_new_id()
659 if (id < id_tbl->max) { in cnic_alloc_new_id()
660 set_bit(id, id_tbl->table); in cnic_alloc_new_id()
661 id_tbl->next = (id + 1) & (id_tbl->max - 1); in cnic_alloc_new_id()
662 id += id_tbl->start; in cnic_alloc_new_id()
665 spin_unlock(&id_tbl->lock); in cnic_alloc_new_id()
670 static void cnic_free_id(struct cnic_id_tbl *id_tbl, u32 id) in cnic_free_id() argument
675 id -= id_tbl->start; in cnic_free_id()
676 if (id >= id_tbl->max) in cnic_free_id()
679 clear_bit(id, id_tbl->table); in cnic_free_id()