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.
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/xarray.hlinux/bitfield.hrvu.hnpc.hnpc_profile.hrvu_npc_hash.hrvu_npc.hcn20k/npc.hcn20k/reg.hrvu_npc_fs.h
Detected Declarations
struct npc_defrag_nodefunction npc_idx2vidxfunction npc_is_vidxfunction npc_vidx2idxfunction npc_cn20k_vidx2idxfunction npc_cn20k_idx2vidxfunction npc_vidx_maps_del_entryfunction npc_vidx_maps_modifyfunction npc_vidx_maps_add_entryfunction npc_config_kpmcamfunction npc_config_kpmactionfunction npc_program_single_kpm_profilefunction npc_enable_kpm_entryfunction npc_program_kpm_profilefunction npc_cn20k_parser_profile_initfunction npc_program_mkex_rxfunction npc_program_mkex_txfunction npc_program_mkex_profilefunction npc_cn20k_load_mkex_profilefunction npc_cn20k_enable_mcam_entryfunction npc_clear_x2_entryfunction npc_cn20k_clear_mcam_entryfunction npc_cn20k_get_keywordfunction npc_cn20k_config_kw_x2function npc_cn20k_config_kw_x4function npc_cn20k_config_mcam_entryfunction npc_cn20k_copy_mcam_entryfunction npc_cn20k_fill_entrywordfunction npc_cn20k_read_mcam_entryfunction rvu_mbox_handler_npc_cn20k_mcam_write_entryfunction rvu_mbox_handler_npc_cn20k_mcam_read_entryfunction rvu_mbox_handler_npc_cn20k_mcam_alloc_and_write_entryfunction rvu_npc_get_base_steer_rule_typefunction rvu_mbox_handler_npc_cn20k_read_base_steer_rulefunction npc_map2cn20k_flagfunction npc_cn20k_translate_action_flagsfunction npc_cn20k_update_action_entries_n_flagsfunction npc_cn20k_apply_custom_kpufunction NPC_KPU_VER_MAJfunction NPC_KPU_VER_MINfunction npc_mcam_idx_2_key_typefunction npc_subbank_idx_2_mcam_idxfunction npc_mcam_idx_2_subbank_idxfunction __npc_subbank_contig_allocfunction counterfunction __npc_subbank_non_contig_allocfunction __npc_subbank_sboff_2_offfunction __npc_subbank_mark_slot
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
- Immediate include surface: `linux/xarray.h`, `linux/bitfield.h`, `rvu.h`, `npc.h`, `npc_profile.h`, `rvu_npc_hash.h`, `rvu_npc.h`, `cn20k/npc.h`.
- Detected declarations: `struct npc_defrag_node`, `function npc_idx2vidx`, `function npc_is_vidx`, `function npc_vidx2idx`, `function npc_cn20k_vidx2idx`, `function npc_cn20k_idx2vidx`, `function npc_vidx_maps_del_entry`, `function npc_vidx_maps_modify`, `function npc_vidx_maps_add_entry`, `function npc_config_kpmcam`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.