include/net/libeth/xdp.h
Source file repositories/reference/linux-study-clean/include/net/libeth/xdp.h
File Facts
- System
- Linux kernel
- Corpus path
include/net/libeth/xdp.h- Extension
.h- Size
- 57634 bytes
- Lines
- 1871
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bpf_trace.hlinux/unroll.hnet/libeth/rx.hnet/libeth/tx.hnet/xsk_buff_pool.h
Detected Declarations
struct libeth_xdp_buffstruct libeth_xdp_tx_framestruct libeth_xdp_tx_bulkstruct libeth_xdpsqstruct libeth_xdp_tx_descfunction sendingfunction libeth_xdpsq_sharedfunction libeth_xdpsq_idfunction libeth_xdpsq_getfunction libeth_xdpsq_putfunction libeth_xdpsq_lockfunction libeth_xdpsq_unlockfunction libeth_xdpsq_deinit_timerfunction secondfunction LIBETH_XDP_DEFINE_TIMERfunction libeth_xdp_tx_xmit_bulkfunction libeth_xdp_tx_queue_headfunction libeth_xdp_tx_queue_fragfunction libeth_xdp_tx_queue_bulkfunction libeth_xdp_tx_fill_buffunction __libeth_xdp_tx_flush_bulkfunction LIBETH_XDP_DEFINE_FLUSH_TXfunction libeth_xdp_xmit_queue_headfunction libeth_xdp_xmit_queue_fragfunction libeth_xdp_xmit_queue_bulkfunction libeth_xdp_xmit_fill_buffunction __libeth_xdp_xmit_do_bulkfunction libeth_xdp_init_bufffunction libeth_xdp_save_bufffunction libeth_xdp_return_stashfunction libeth_xdp_return_vafunction libeth_xdp_return_fragsfunction __libeth_xdp_return_bufffunction libeth_xdp_prepare_bufffunction libeth_xdp_process_bufffunction __libeth_xdp_run_passfunction __libeth_xdp_run_progfunction __libeth_xdp_run_flushfunction __libeth_xdp_run_passfunction libeth_xdp_prep_descfunction __libeth_xdp_finalize_rxfunction fieldsfunction libeth_tx_complete_anyfunction libeth_xdp_complete_tx
Annotated Snippet
struct libeth_xdp_buff {
union {
struct xdp_buff base;
void *data;
};
const void *desc;
unsigned long priv[]
__aligned(__LIBETH_XDP_BUFF_ALIGN);
} __aligned(__LIBETH_XDP_BUFF_ALIGN);
static_assert(offsetof(struct libeth_xdp_buff, data) ==
offsetof(struct xdp_buff_xsk, xdp.data));
static_assert(offsetof(struct libeth_xdp_buff, desc) ==
offsetof(struct xdp_buff_xsk, cb));
static_assert(IS_ALIGNED(sizeof(struct xdp_buff_xsk),
__alignof(struct libeth_xdp_buff)));
/**
* __LIBETH_XDP_ONSTACK_BUFF - declare a &libeth_xdp_buff on the stack
* @name: name of the variable to declare
* @...: sizeof() of the driver-private data
*/
#define __LIBETH_XDP_ONSTACK_BUFF(name, ...) \
___LIBETH_XDP_ONSTACK_BUFF(name, ##__VA_ARGS__)
/**
* LIBETH_XDP_ONSTACK_BUFF - declare a &libeth_xdp_buff on the stack
* @name: name of the variable to declare
* @...: type or variable name of the driver-private data
*/
#define LIBETH_XDP_ONSTACK_BUFF(name, ...) \
__LIBETH_XDP_ONSTACK_BUFF(name, __libeth_xdp_priv_sz(__VA_ARGS__))
#define ___LIBETH_XDP_ONSTACK_BUFF(name, ...) \
__DEFINE_FLEX(struct libeth_xdp_buff, name, priv, \
LIBETH_XDP_PRIV_SZ(__VA_ARGS__ + 0), \
__uninitialized); \
LIBETH_XDP_ASSERT_PRIV_SZ(__VA_ARGS__ + 0)
#define __libeth_xdp_priv_sz(...) \
CONCATENATE(__libeth_xdp_psz, COUNT_ARGS(__VA_ARGS__))(__VA_ARGS__)
#define __libeth_xdp_psz0(...)
#define __libeth_xdp_psz1(...) sizeof(__VA_ARGS__)
#define LIBETH_XDP_PRIV_SZ(sz) \
(ALIGN(sz, __alignof(struct libeth_xdp_buff)) / sizeof(long))
/* Performs XSK_CHECK_PRIV_TYPE() */
#define LIBETH_XDP_ASSERT_PRIV_SZ(sz) \
static_assert(offsetofend(struct xdp_buff_xsk, cb) >= \
struct_size_t(struct libeth_xdp_buff, priv, \
LIBETH_XDP_PRIV_SZ(sz)))
/* XDPSQ sharing */
DECLARE_STATIC_KEY_FALSE(libeth_xdpsq_share);
/**
* libeth_xdpsq_num - calculate optimal number of XDPSQs for this device + sys
* @rxq: current number of active Rx queues
* @txq: current number of active Tx queues
* @max: maximum number of Tx queues
*
* Each RQ must have its own XDPSQ for XSk pairs, each CPU must have own XDPSQ
* for lockless sending (``XDP_TX``, .ndo_xdp_xmit()). Cap the maximum of these
* two with the number of SQs the device can have (minus used ones).
*
* Return: number of XDP Tx queues the device needs to use.
*/
static inline u32 libeth_xdpsq_num(u32 rxq, u32 txq, u32 max)
{
return min(max(nr_cpu_ids, rxq), max - txq);
}
/**
* libeth_xdpsq_shared - whether XDPSQs can be shared between several CPUs
* @num: number of active XDPSQs
*
* Return: true if there's no 1:1 XDPSQ/CPU association, false otherwise.
*/
static inline bool libeth_xdpsq_shared(u32 num)
{
return num < nr_cpu_ids;
}
/**
* libeth_xdpsq_id - get XDPSQ index corresponding to this CPU
* @num: number of active XDPSQs
*
* Helper for libeth_xdp routines, do not use in drivers directly.
Annotation
- Immediate include surface: `linux/bpf_trace.h`, `linux/unroll.h`, `net/libeth/rx.h`, `net/libeth/tx.h`, `net/xsk_buff_pool.h`.
- Detected declarations: `struct libeth_xdp_buff`, `struct libeth_xdp_tx_frame`, `struct libeth_xdp_tx_bulk`, `struct libeth_xdpsq`, `struct libeth_xdp_tx_desc`, `function sending`, `function libeth_xdpsq_shared`, `function libeth_xdpsq_id`, `function libeth_xdpsq_get`, `function libeth_xdpsq_put`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- 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.