Lines Matching refs:id_tbl
656 static int cnic_init_id_tbl(struct cnic_id_tbl *id_tbl, u32 size, u32 start_id, in cnic_init_id_tbl() argument
659 id_tbl->start = start_id; in cnic_init_id_tbl()
660 id_tbl->max = size; in cnic_init_id_tbl()
661 id_tbl->next = next; in cnic_init_id_tbl()
662 spin_lock_init(&id_tbl->lock); in cnic_init_id_tbl()
663 id_tbl->table = kcalloc(BITS_TO_LONGS(size), sizeof(long), GFP_KERNEL); in cnic_init_id_tbl()
664 if (!id_tbl->table) in cnic_init_id_tbl()
670 static void cnic_free_id_tbl(struct cnic_id_tbl *id_tbl) in cnic_free_id_tbl() argument
672 kfree(id_tbl->table); in cnic_free_id_tbl()
673 id_tbl->table = NULL; in cnic_free_id_tbl()
676 static int cnic_alloc_id(struct cnic_id_tbl *id_tbl, u32 id) in cnic_alloc_id() argument
680 id -= id_tbl->start; in cnic_alloc_id()
681 if (id >= id_tbl->max) in cnic_alloc_id()
684 spin_lock(&id_tbl->lock); in cnic_alloc_id()
685 if (!test_bit(id, id_tbl->table)) { in cnic_alloc_id()
686 set_bit(id, id_tbl->table); in cnic_alloc_id()
689 spin_unlock(&id_tbl->lock); in cnic_alloc_id()
694 static u32 cnic_alloc_new_id(struct cnic_id_tbl *id_tbl) in cnic_alloc_new_id() argument
698 spin_lock(&id_tbl->lock); in cnic_alloc_new_id()
699 id = find_next_zero_bit(id_tbl->table, id_tbl->max, id_tbl->next); in cnic_alloc_new_id()
700 if (id >= id_tbl->max) { in cnic_alloc_new_id()
702 if (id_tbl->next != 0) { in cnic_alloc_new_id()
703 id = find_first_zero_bit(id_tbl->table, id_tbl->next); in cnic_alloc_new_id()
704 if (id >= id_tbl->next) in cnic_alloc_new_id()
709 if (id < id_tbl->max) { in cnic_alloc_new_id()
710 set_bit(id, id_tbl->table); in cnic_alloc_new_id()
711 id_tbl->next = (id + 1) & (id_tbl->max - 1); in cnic_alloc_new_id()
712 id += id_tbl->start; in cnic_alloc_new_id()
715 spin_unlock(&id_tbl->lock); in cnic_alloc_new_id()
720 static void cnic_free_id(struct cnic_id_tbl *id_tbl, u32 id) in cnic_free_id() argument
725 id -= id_tbl->start; in cnic_free_id()
726 if (id >= id_tbl->max) in cnic_free_id()
729 clear_bit(id, id_tbl->table); in cnic_free_id()