drivers/net/ethernet/netronome/nfp/bpf/offload.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/netronome/nfp/bpf/offload.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/netronome/nfp/bpf/offload.c- Extension
.c- Size
- 15195 bytes
- Lines
- 619
- 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/bpf.hlinux/kernel.hlinux/netdevice.hlinux/pci.hlinux/jiffies.hlinux/timer.hlinux/list.hlinux/mm.hnet/pkt_cls.hnet/tc_act/tc_gact.hnet/tc_act/tc_mirred.hmain.h../ccm.h../nfp_app.h../nfp_net_ctrl.h../nfp_net.h
Detected Declarations
function nfp_map_ptr_recordfunction nfp_map_ptrs_forgetfunction nfp_map_ptrs_recordfunction nfp_prog_preparefunction nfp_prog_freefunction list_for_each_entry_safefunction nfp_bpf_verifier_prepfunction nfp_bpf_translatefunction nfp_bpf_destroyfunction nfp_map_bpf_byte_swapfunction nfp_map_bpf_byte_swap_recordfunction nfp_bpf_map_lookup_entryfunction nfp_bpf_map_update_entryfunction nfp_bpf_map_get_next_keyfunction nfp_bpf_map_delete_elemfunction nfp_bpf_map_allocfunction nfp_bpf_map_freefunction nfp_ndo_bpffunction nfp_bpf_perf_event_copyfunction nfp_bpf_event_outputfunction nfp_bpf_offload_check_mtufunction nfp_net_bpf_loadfunction nfp_net_bpf_startfunction nfp_net_bpf_stopfunction nfp_net_bpf_offload
Annotated Snippet
if (--nfp_prog->map_records[i]->count) {
nfp_prog->map_records[i] = NULL;
continue;
}
WARN_ON(rhashtable_remove_fast(&bpf->maps_neutral,
&nfp_prog->map_records[i]->l,
nfp_bpf_maps_neutral_params));
freed = true;
}
if (freed) {
synchronize_rcu();
for (i = 0; i < nfp_prog->map_records_cnt; i++)
if (nfp_prog->map_records[i]) {
bpf_map_put(nfp_prog->map_records[i]->ptr);
kfree(nfp_prog->map_records[i]);
}
}
kfree(nfp_prog->map_records);
nfp_prog->map_records = NULL;
nfp_prog->map_records_cnt = 0;
}
static int
nfp_map_ptrs_record(struct nfp_app_bpf *bpf, struct nfp_prog *nfp_prog,
struct bpf_prog *prog)
{
int i, cnt, err = 0;
mutex_lock(&prog->aux->used_maps_mutex);
/* Quickly count the maps we will have to remember */
cnt = 0;
for (i = 0; i < prog->aux->used_map_cnt; i++)
if (bpf_map_offload_neutral(prog->aux->used_maps[i]))
cnt++;
if (!cnt)
goto out;
nfp_prog->map_records = kmalloc_objs(nfp_prog->map_records[0], cnt);
if (!nfp_prog->map_records) {
err = -ENOMEM;
goto out;
}
for (i = 0; i < prog->aux->used_map_cnt; i++)
if (bpf_map_offload_neutral(prog->aux->used_maps[i])) {
err = nfp_map_ptr_record(bpf, nfp_prog,
prog->aux->used_maps[i]);
if (err) {
nfp_map_ptrs_forget(bpf, nfp_prog);
goto out;
}
}
WARN_ON(cnt != nfp_prog->map_records_cnt);
out:
mutex_unlock(&prog->aux->used_maps_mutex);
return err;
}
static int
nfp_prog_prepare(struct nfp_prog *nfp_prog, const struct bpf_insn *prog,
unsigned int cnt)
{
struct nfp_insn_meta *meta;
unsigned int i;
for (i = 0; i < cnt; i++) {
meta = kzalloc_obj(*meta);
if (!meta)
return -ENOMEM;
meta->insn = prog[i];
meta->n = i;
if (is_mbpf_alu(meta)) {
meta->umin_src = U64_MAX;
meta->umin_dst = U64_MAX;
}
list_add_tail(&meta->l, &nfp_prog->insns);
}
nfp_prog->n_insns = cnt;
nfp_bpf_jit_prepare(nfp_prog);
return 0;
Annotation
- Immediate include surface: `linux/bpf.h`, `linux/kernel.h`, `linux/netdevice.h`, `linux/pci.h`, `linux/jiffies.h`, `linux/timer.h`, `linux/list.h`, `linux/mm.h`.
- Detected declarations: `function nfp_map_ptr_record`, `function nfp_map_ptrs_forget`, `function nfp_map_ptrs_record`, `function nfp_prog_prepare`, `function nfp_prog_free`, `function list_for_each_entry_safe`, `function nfp_bpf_verifier_prep`, `function nfp_bpf_translate`, `function nfp_bpf_destroy`, `function nfp_map_bpf_byte_swap`.
- 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.