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.

Dependency Surface

Detected Declarations

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

Implementation Notes