drivers/net/ethernet/cavium/thunder/nicvf_queues.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/cavium/thunder/nicvf_queues.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/cavium/thunder/nicvf_queues.c- Extension
.c- Size
- 52459 bytes
- Lines
- 1972
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/pci.hlinux/netdevice.hlinux/ip.hlinux/etherdevice.hlinux/iommu.hnet/ip.hnet/tso.huapi/linux/bpf.hnic_reg.hnic.hq_struct.hnicvf_queues.h
Detected Declarations
function nicvf_get_pagefunction nicvf_poll_regfunction nicvf_alloc_q_desc_memfunction nicvf_free_q_desc_memfunction nicvf_alloc_rcv_bufferfunction nicvf_init_rbdrfunction nicvf_free_rbdrfunction nicvf_refill_rbdrfunction nicvf_rbdr_workfunction nicvf_rbdr_taskfunction nicvf_init_cmp_queuefunction nicvf_free_cmp_queuefunction nicvf_init_snd_queuefunction nicvf_unmap_sndq_buffersfunction nicvf_free_snd_queuefunction nicvf_reclaim_snd_queuefunction nicvf_reclaim_rcv_queuefunction nicvf_reclaim_cmp_queuefunction nicvf_reclaim_rbdrfunction nicvf_config_vlan_strippingfunction nicvf_reset_rcv_queue_statsfunction nicvf_rcv_queue_configfunction nicvf_cmp_queue_configfunction nicvf_snd_queue_configfunction nicvf_rbdr_configfunction nicvf_qset_configfunction nicvf_free_resourcesfunction nicvf_alloc_resourcesfunction nicvf_set_qset_resourcesfunction nicvf_config_data_transferfunction nicvf_get_sq_descfunction nicvf_rollback_sq_descfunction nicvf_put_sq_descfunction nicvf_get_nxt_sqentryfunction nicvf_sq_enablefunction nicvf_sq_disablefunction nicvf_sq_free_used_descsfunction nicvf_xdp_sq_doorbellfunction nicvf_xdp_sq_add_hdr_subdescfunction nicvf_xdp_sq_append_pktfunction nicvf_tso_count_subdescsfunction nicvf_sq_subdesc_requiredfunction nicvf_sq_add_hdr_subdescfunction nicvf_sq_add_gather_subdescfunction nicvf_sq_add_cqe_subdescfunction nicvf_sq_doorbellfunction nicvf_sq_append_tsofunction nicvf_sq_append_skb
Annotated Snippet
if (rbdr->is_xdp) {
if (ref_count == pgcache->ref_count)
pgcache->ref_count--;
else
page = NULL;
} else if (ref_count != 1) {
page = NULL;
}
}
if (!page) {
page = alloc_pages(gfp | __GFP_COMP | __GFP_NOWARN, 0);
if (!page)
return NULL;
this_cpu_inc(nic->pnicvf->drv_stats->page_alloc);
/* Check for space */
if (rbdr->pgalloc >= rbdr->pgcnt) {
/* Page can still be used */
nic->rb_page = page;
return NULL;
}
/* Save the page in page cache */
pgcache->page = page;
pgcache->dma_addr = 0;
pgcache->ref_count = 0;
rbdr->pgalloc++;
}
/* Take additional page references for recycling */
if (rbdr->is_xdp) {
/* Since there is single RBDR (i.e single core doing
* page recycling) per 8 Rx queues, in XDP mode adjusting
* page references atomically is the biggest bottleneck, so
* take bunch of references at a time.
*
* So here, below reference counts defer by '1'.
*/
if (!pgcache->ref_count) {
pgcache->ref_count = XDP_PAGE_REFCNT_REFILL;
page_ref_add(page, XDP_PAGE_REFCNT_REFILL);
}
} else {
/* In non-XDP case, single 64K page is divided across multiple
* receive buffers, so cost of recycling is less anyway.
* So we can do with just one extra reference.
*/
page_ref_add(page, 1);
}
rbdr->pgidx++;
rbdr->pgidx &= (rbdr->pgcnt - 1);
/* Prefetch refcount of next page in page cache */
next = &rbdr->pgcache[rbdr->pgidx];
page = next->page;
if (page)
prefetch(&page->_refcount);
return pgcache;
}
/* Allocate buffer for packet reception */
static inline int nicvf_alloc_rcv_buffer(struct nicvf *nic, struct rbdr *rbdr,
gfp_t gfp, u32 buf_len, u64 *rbuf)
{
struct pgcache *pgcache = NULL;
/* Check if request can be accomodated in previous allocated page.
* But in XDP mode only one buffer per page is permitted.
*/
if (!rbdr->is_xdp && nic->rb_page &&
((nic->rb_page_offset + buf_len) <= PAGE_SIZE)) {
nic->rb_pageref++;
goto ret;
}
nicvf_get_page(nic);
nic->rb_page = NULL;
/* Get new page, either recycled or new one */
pgcache = nicvf_alloc_page(nic, rbdr, gfp);
if (!pgcache && !nic->rb_page) {
this_cpu_inc(nic->pnicvf->drv_stats->rcv_buffer_alloc_failures);
return -ENOMEM;
}
nic->rb_page_offset = 0;
Annotation
- Immediate include surface: `linux/pci.h`, `linux/netdevice.h`, `linux/ip.h`, `linux/etherdevice.h`, `linux/iommu.h`, `net/ip.h`, `net/tso.h`, `uapi/linux/bpf.h`.
- Detected declarations: `function nicvf_get_page`, `function nicvf_poll_reg`, `function nicvf_alloc_q_desc_mem`, `function nicvf_free_q_desc_mem`, `function nicvf_alloc_rcv_buffer`, `function nicvf_init_rbdr`, `function nicvf_free_rbdr`, `function nicvf_refill_rbdr`, `function nicvf_rbdr_work`, `function nicvf_rbdr_task`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.