Lines Matching refs:id_tbl
657 static int cnic_init_id_tbl(struct cnic_id_tbl *id_tbl, u32 size, u32 start_id, in cnic_init_id_tbl() argument
660 id_tbl->start = start_id; in cnic_init_id_tbl()
661 id_tbl->max = size; in cnic_init_id_tbl()
662 id_tbl->next = next; in cnic_init_id_tbl()
663 spin_lock_init(&id_tbl->lock); in cnic_init_id_tbl()
664 id_tbl->table = bitmap_zalloc(size, GFP_KERNEL); in cnic_init_id_tbl()
665 if (!id_tbl->table) in cnic_init_id_tbl()
671 static void cnic_free_id_tbl(struct cnic_id_tbl *id_tbl) in cnic_free_id_tbl() argument
673 bitmap_free(id_tbl->table); in cnic_free_id_tbl()
674 id_tbl->table = NULL; in cnic_free_id_tbl()
677 static int cnic_alloc_id(struct cnic_id_tbl *id_tbl, u32 id) in cnic_alloc_id() argument
681 id -= id_tbl->start; in cnic_alloc_id()
682 if (id >= id_tbl->max) in cnic_alloc_id()
685 spin_lock(&id_tbl->lock); in cnic_alloc_id()
686 if (!test_bit(id, id_tbl->table)) { in cnic_alloc_id()
687 set_bit(id, id_tbl->table); in cnic_alloc_id()
690 spin_unlock(&id_tbl->lock); in cnic_alloc_id()
695 static u32 cnic_alloc_new_id(struct cnic_id_tbl *id_tbl) in cnic_alloc_new_id() argument
699 spin_lock(&id_tbl->lock); in cnic_alloc_new_id()
700 id = find_next_zero_bit(id_tbl->table, id_tbl->max, id_tbl->next); in cnic_alloc_new_id()
701 if (id >= id_tbl->max) { in cnic_alloc_new_id()
703 if (id_tbl->next != 0) { in cnic_alloc_new_id()
704 id = find_first_zero_bit(id_tbl->table, id_tbl->next); in cnic_alloc_new_id()
705 if (id >= id_tbl->next) in cnic_alloc_new_id()
710 if (id < id_tbl->max) { in cnic_alloc_new_id()
711 set_bit(id, id_tbl->table); in cnic_alloc_new_id()
712 id_tbl->next = (id + 1) & (id_tbl->max - 1); in cnic_alloc_new_id()
713 id += id_tbl->start; in cnic_alloc_new_id()
716 spin_unlock(&id_tbl->lock); in cnic_alloc_new_id()
721 static void cnic_free_id(struct cnic_id_tbl *id_tbl, u32 id) in cnic_free_id() argument
726 id -= id_tbl->start; in cnic_free_id()
727 if (id >= id_tbl->max) in cnic_free_id()
730 clear_bit(id, id_tbl->table); in cnic_free_id()