drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c
Extension
.c
Size
118777 bytes
Lines
4838
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

struct npc_defrag_node {
	u8 idx;
	u8 key_type;
	bool valid;
	bool refs;
	u16 free_cnt;
	u16 vidx_cnt;
	u16 *vidx;
	struct list_head list;
};

static bool npc_defrag_skip_restricted_sb(int sb_id)
{
	int i;

	if (!restrict_valid)
		return false;

	for (i = 0; i < ARRAY_SIZE(npc_subbank_restricted_idxs); i++)
		if (sb_id == npc_subbank_restricted_idxs[i])
			return true;
	return false;
}

/* Find subbank with minimum number of virtual indexes */
static struct npc_defrag_node *npc_subbank_min_vidx(struct list_head *lh)
{
	struct npc_defrag_node *node, *tnode = NULL;
	int min = INT_MAX;

	list_for_each_entry(node, lh, list) {
		if (!node->valid)
			continue;

		/* if subbank has ref allocated mcam indexes, that subbank
		 * is not a good candidate to move out indexes.
		 */
		if (node->refs)
			continue;

		if (min > node->vidx_cnt) {
			min = node->vidx_cnt;
			tnode = node;
		}
	}

	return tnode;
}

/* Find subbank with maximum number of free spaces */
static struct npc_defrag_node *npc_subbank_max_free(struct list_head *lh)
{
	struct npc_defrag_node *node, *tnode = NULL;
	int max = INT_MIN;

	list_for_each_entry(node, lh, list) {
		if (!node->valid)
			continue;

		if (max < node->free_cnt) {
			max = node->free_cnt;
			tnode = node;
		}
	}

	return tnode;
}

static int npc_defrag_alloc_free_slots(struct rvu *rvu,
				       struct npc_defrag_node *f,
				       int cnt, u16 *save)
{
	int alloc_cnt1, alloc_cnt2;
	struct npc_subbank *sb;
	int rc, sb_off, i, err;
	bool deleted;

	sb = &npc_priv->sb[f->idx];

	alloc_cnt1 = 0;
	alloc_cnt2 = 0;

	rc = __npc_subbank_alloc(rvu, sb,
				 NPC_MCAM_KEY_X2, sb->b0b,
				 sb->b0t,
				 NPC_MCAM_LOWER_PRIO,
				 false, cnt, save, cnt, true,
				 &alloc_cnt1);

	if (alloc_cnt1 < cnt) {

Annotation

Implementation Notes