1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
3 * if_xdp: XDP socket user-space interface
4 * Copyright(c) 2018 Intel Corporation.
6 * Author(s): Björn Töpel <bjorn.topel@intel.com>
7 * Magnus Karlsson <magnus.karlsson@intel.com>
10 #ifndef _LINUX_IF_XDP_H
11 #define _LINUX_IF_XDP_H
13 #include <linux/types.h>
15 /* Options for the sxdp_flags field */
16 #define XDP_SHARED_UMEM (1 << 0)
17 #define XDP_COPY (1 << 1) /* Force copy-mode */
18 #define XDP_ZEROCOPY (1 << 2) /* Force zero-copy mode */
19 /* If this option is set, the driver might go sleep and in that case
20 * the XDP_RING_NEED_WAKEUP flag in the fill and/or Tx rings will be
21 * set. If it is set, the application need to explicitly wake up the
22 * driver with a poll() (Rx and Tx) or sendto() (Tx only). If you are
23 * running the driver and the application on the same core, you should
24 * use this option so that the kernel will yield to the user space
27 #define XDP_USE_NEED_WAKEUP (1 << 3)
28 /* By setting this option, userspace application indicates that it can
29 * handle multiple descriptors per packet thus enabling AF_XDP to split
30 * multi-buffer XDP frames into multiple Rx descriptors. Without this set
31 * such frames will be dropped.
33 #define XDP_USE_SG (1 << 4)
35 /* Flags for xsk_umem_config flags */
36 #define XDP_UMEM_UNALIGNED_CHUNK_FLAG (1 << 0)
38 /* Force checksum calculation in software. Can be used for testing or
39 * working around potential HW issues. This option causes performance
40 * degradation and only works in XDP_COPY mode.
42 #define XDP_UMEM_TX_SW_CSUM (1 << 1)
49 __u32 sxdp_shared_umem_fd;
53 #define XDP_RING_NEED_WAKEUP (1 << 0)
55 struct xdp_ring_offset {
62 struct xdp_mmap_offsets {
63 struct xdp_ring_offset rx;
64 struct xdp_ring_offset tx;
65 struct xdp_ring_offset fr; /* Fill */
66 struct xdp_ring_offset cr; /* Completion */
69 /* XDP socket options */
70 #define XDP_MMAP_OFFSETS 1
73 #define XDP_UMEM_REG 4
74 #define XDP_UMEM_FILL_RING 5
75 #define XDP_UMEM_COMPLETION_RING 6
76 #define XDP_STATISTICS 7
80 __u64 addr; /* Start of packet data area */
81 __u64 len; /* Length of packet data area */
85 __u32 tx_metadata_len;
88 struct xdp_statistics {
89 __u64 rx_dropped; /* Dropped for other reasons */
90 __u64 rx_invalid_descs; /* Dropped due to invalid descriptor */
91 __u64 tx_invalid_descs; /* Dropped due to invalid descriptor */
92 __u64 rx_ring_full; /* Dropped due to rx ring being full */
93 __u64 rx_fill_ring_empty_descs; /* Failed to retrieve item from fill ring */
94 __u64 tx_ring_empty_descs; /* Failed to retrieve item from tx ring */
101 /* Flags for the flags field of struct xdp_options */
102 #define XDP_OPTIONS_ZEROCOPY (1 << 0)
104 /* Pgoff for mmaping the rings */
105 #define XDP_PGOFF_RX_RING 0
106 #define XDP_PGOFF_TX_RING 0x80000000
107 #define XDP_UMEM_PGOFF_FILL_RING 0x100000000ULL
108 #define XDP_UMEM_PGOFF_COMPLETION_RING 0x180000000ULL
110 /* Masks for unaligned chunks mode */
111 #define XSK_UNALIGNED_BUF_OFFSET_SHIFT 48
112 #define XSK_UNALIGNED_BUF_ADDR_MASK \
113 ((1ULL << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1)
115 /* Request transmit timestamp. Upon completion, put it into tx_timestamp
116 * field of struct xsk_tx_metadata.
118 #define XDP_TXMD_FLAGS_TIMESTAMP (1 << 0)
120 /* Request transmit checksum offload. Checksum start position and offset
121 * are communicated via csum_start and csum_offset fields of struct
124 #define XDP_TXMD_FLAGS_CHECKSUM (1 << 1)
126 /* AF_XDP offloads request. 'request' union member is consumed by the driver
127 * when the packet is being transmitted. 'completion' union member is
128 * filled by the driver when the transmit completion arrives.
130 struct xsk_tx_metadata {
135 /* XDP_TXMD_FLAGS_CHECKSUM */
137 /* Offset from desc->addr where checksumming should start. */
139 /* Offset from csum_start where checksum should be stored. */
144 /* XDP_TXMD_FLAGS_TIMESTAMP */
150 /* Rx/Tx descriptor */
157 /* UMEM descriptor is __u64 */
159 /* Flag indicating that the packet continues with the buffer pointed out by the
160 * next frame in the ring. The end of the packet is signalled by setting this
161 * bit to zero. For single buffer packets, every descriptor has 'options' set
162 * to 0 and this maintains backward compatibility.
164 #define XDP_PKT_CONTD (1 << 0)
166 /* TX packet carries valid metadata. */
167 #define XDP_TX_METADATA (1 << 1)
169 #endif /* _LINUX_IF_XDP_H */