drivers/net/ethernet/microchip/sparx5/sparx5_pool.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/microchip/sparx5/sparx5_pool.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/microchip/sparx5/sparx5_pool.c
Extension
.c
Size
1732 bytes
Lines
82
Domain
Driver Families
Bucket
drivers/net
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (e_itr->ref_cnt == 0) {
			*id = sparx5_pool_idx_to_id(i);
			return ++e_itr->ref_cnt;
		}
	}

	return -ENOSPC;
}

/* Get resource from pool that matches index.
 * Return reference count on success, otherwise return error.
 */
int sparx5_pool_get_with_idx(struct sparx5_pool_entry *pool, int size, u32 idx,
			     u32 *id)
{
	struct sparx5_pool_entry *e_itr;
	int i, ret = -ENOSPC;

	for (i = 0, e_itr = pool; i < size; i++, e_itr++) {
		/* Pool index of first free entry */
		if (e_itr->ref_cnt == 0 && ret == -ENOSPC)
			ret = i;
		/* Tc index already in use ? */
		if (e_itr->idx == idx && e_itr->ref_cnt > 0) {
			ret = i;
			break;
		}
	}

	/* Did we find a free entry? */
	if (ret >= 0) {
		*id = sparx5_pool_idx_to_id(ret);
		e_itr = (pool + ret);
		e_itr->idx = idx;
		return ++e_itr->ref_cnt;
	}

	return ret;
}

Annotation

Implementation Notes