src/dpdk/drivers/net/bnxt/tf_core/bitalloc.c
static int
ba_alloc_reverse_helper(struct bitalloc *pool,
			int offset,
			int words,
			unsigned int size,
			int index,
			int *clear)
{
	bitalloc_word_t *storage = &pool->storage[offset];
	int loc = ba_fls(storage[index]);
	int r;

	if (loc == 0)
		return -1;

	loc--;

	if (pool->size > size) {
		r = ba_alloc_reverse_helper(pool,
					    offset + words + 1,
					    storage[words],
					    size * 32,
					    index * 32 + loc,
					    clear);
	} else {
		r = index * 32 + loc;
		*clear = 1;
		pool->free_count--;
	}

	if (*clear) {
		storage[index] &= ~(1 << loc);
		*clear = (storage[index] == 0);
	}

	return r;
}
/**
 * Help function to alloc entry from highest available index
 *
 * Searching the pool from highest index for the empty entry.
 *
 * [in] pool
 *   Pointer to the resource pool
 *
 * [in] offset
 *   Offset of the storage in the pool
 *
 * [in] words
 *   Number of words in this level
 *
 * [in] size
 *   Number of entries in this level
 *
 * [in] index
 *   Index of words that has the entry
 *
 * [in] clear
 *   Indicate if a bit needs to be clear due to the entry is allocated
 *
 * Returns:
 *     0 - Success
 *    -1 - Failure
 */
Help function to alloc entry from highest available index
Searching the pool from highest index for the empty entry.

[in] pool
Pointer to the resource pool

[in] offset
Offset of the storage in the pool

[in] words
Number of words in this level

[in] size
Number of entries in this level

[in] index
Index of words that has the entry

[in] clear
Indicate if a bit needs to be clear due to the entry is allocated

Failure
Help function to alloc entry from highest available index Searching the pool from highest index for the empty entry . [ in ] pool Pointer to the resource pool [ in ] offset Offset of the storage in the pool [ in ] words Number of words in this level [ in ] size Number of entries in this level [ in ] index Index of words that has the entry [ in ] clear Indicate if a bit needs to be clear due to the entry is allocated Failure
static int
ba_alloc_reverse_helper(struct bitalloc *pool,
			int offset,
			int words,
			unsigned int size,
			int index,
			int *clear)
{
	bitalloc_word_t *storage = &pool->storage[offset];
	int loc = ba_fls(storage[index]);
	int r;
	if (loc == 0)
		return -1;
	loc--;
	if (pool->size > size) {
		r = ba_alloc_reverse_helper(pool,
					    offset + words + 1,
					    storage[words],
					    size * 32,
					    index * 32 + loc,
					    clear);
	} else {
		r = index * 32 + loc;
		*clear = 1;
		pool->free_count--;
	}
	if (*clear) {
		storage[index] &= ~(1 << loc);
		*clear = (storage[index] == 0);
	}
	return r;
}
static int ba_alloc_reverse_helper ( struct bitalloc * pool , int offset , int words , unsigned int size , int index , int * clear ) { bitalloc_word_t * storage = & pool -> storage [ offset ] ; int loc = ba_fls ( storage [ index ] ) ; int r ; if ( loc == 0 ) return -1 ; loc -- ; if ( pool -> size > size ) { r = ba_alloc_reverse_helper ( pool , offset + words + 1 , storage [ words ] , size * 32 , index * 32 + loc , clear ) ; } else { r = index * 32 + loc ; * clear = 1 ; pool -> free_count -- ; } if ( * clear ) { storage [ index ] &= ~ ( 1 << loc ) ; * clear = ( storage [ index ] == 0 ) ; } return r ; }
Help function to alloc entry from highest available index
 Searching the pool from highest index for the empty entry.
Help function to alloc entry from highest available index Searching the pool from highest index for the empty entry .