Lines Matching defs:id_tbl
588 static int cnic_init_id_tbl(struct cnic_id_tbl *id_tbl, u32 size, u32 start_id)
590 id_tbl->start = start_id;
591 id_tbl->max = size;
592 id_tbl->next = 0;
593 spin_lock_init(&id_tbl->lock);
594 id_tbl->table = kzalloc(DIV_ROUND_UP(size, 32) * 4, GFP_KERNEL);
595 if (!id_tbl->table)
601 static void cnic_free_id_tbl(struct cnic_id_tbl *id_tbl)
603 kfree(id_tbl->table);
604 id_tbl->table = NULL;
607 static int cnic_alloc_id(struct cnic_id_tbl *id_tbl, u32 id)
611 id -= id_tbl->start;
612 if (id >= id_tbl->max)
615 spin_lock(&id_tbl->lock);
616 if (!test_bit(id, id_tbl->table)) {
617 set_bit(id, id_tbl->table);
620 spin_unlock(&id_tbl->lock);
625 static u32 cnic_alloc_new_id(struct cnic_id_tbl *id_tbl)
629 spin_lock(&id_tbl->lock);
630 id = find_next_zero_bit(id_tbl->table, id_tbl->max, id_tbl->next);
631 if (id >= id_tbl->max) {
633 if (id_tbl->next != 0) {
634 id = find_first_zero_bit(id_tbl->table, id_tbl->next);
635 if (id >= id_tbl->next)
640 if (id < id_tbl->max) {
641 set_bit(id, id_tbl->table);
642 id_tbl->next = (id + 1) & (id_tbl->max - 1);
643 id += id_tbl->start;
646 spin_unlock(&id_tbl->lock);
651 static void cnic_free_id(struct cnic_id_tbl *id_tbl, u32 id)
656 id -= id_tbl->start;
657 if (id >= id_tbl->max)
660 clear_bit(id, id_tbl->table);