Linux 6.7-rc7
[linux-modified.git] / include / uapi / linux / if_xdp.h
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  * if_xdp: XDP socket user-space interface
4  * Copyright(c) 2018 Intel Corporation.
5  *
6  * Author(s): Björn Töpel <bjorn.topel@intel.com>
7  *            Magnus Karlsson <magnus.karlsson@intel.com>
8  */
9
10 #ifndef _LINUX_IF_XDP_H
11 #define _LINUX_IF_XDP_H
12
13 #include <linux/types.h>
14
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
25  * application.
26  */
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.
32  */
33 #define XDP_USE_SG      (1 << 4)
34
35 /* Flags for xsk_umem_config flags */
36 #define XDP_UMEM_UNALIGNED_CHUNK_FLAG (1 << 0)
37
38 struct sockaddr_xdp {
39         __u16 sxdp_family;
40         __u16 sxdp_flags;
41         __u32 sxdp_ifindex;
42         __u32 sxdp_queue_id;
43         __u32 sxdp_shared_umem_fd;
44 };
45
46 /* XDP_RING flags */
47 #define XDP_RING_NEED_WAKEUP (1 << 0)
48
49 struct xdp_ring_offset {
50         __u64 producer;
51         __u64 consumer;
52         __u64 desc;
53         __u64 flags;
54 };
55
56 struct xdp_mmap_offsets {
57         struct xdp_ring_offset rx;
58         struct xdp_ring_offset tx;
59         struct xdp_ring_offset fr; /* Fill */
60         struct xdp_ring_offset cr; /* Completion */
61 };
62
63 /* XDP socket options */
64 #define XDP_MMAP_OFFSETS                1
65 #define XDP_RX_RING                     2
66 #define XDP_TX_RING                     3
67 #define XDP_UMEM_REG                    4
68 #define XDP_UMEM_FILL_RING              5
69 #define XDP_UMEM_COMPLETION_RING        6
70 #define XDP_STATISTICS                  7
71 #define XDP_OPTIONS                     8
72
73 struct xdp_umem_reg {
74         __u64 addr; /* Start of packet data area */
75         __u64 len; /* Length of packet data area */
76         __u32 chunk_size;
77         __u32 headroom;
78         __u32 flags;
79 };
80
81 struct xdp_statistics {
82         __u64 rx_dropped; /* Dropped for other reasons */
83         __u64 rx_invalid_descs; /* Dropped due to invalid descriptor */
84         __u64 tx_invalid_descs; /* Dropped due to invalid descriptor */
85         __u64 rx_ring_full; /* Dropped due to rx ring being full */
86         __u64 rx_fill_ring_empty_descs; /* Failed to retrieve item from fill ring */
87         __u64 tx_ring_empty_descs; /* Failed to retrieve item from tx ring */
88 };
89
90 struct xdp_options {
91         __u32 flags;
92 };
93
94 /* Flags for the flags field of struct xdp_options */
95 #define XDP_OPTIONS_ZEROCOPY (1 << 0)
96
97 /* Pgoff for mmaping the rings */
98 #define XDP_PGOFF_RX_RING                         0
99 #define XDP_PGOFF_TX_RING                0x80000000
100 #define XDP_UMEM_PGOFF_FILL_RING        0x100000000ULL
101 #define XDP_UMEM_PGOFF_COMPLETION_RING  0x180000000ULL
102
103 /* Masks for unaligned chunks mode */
104 #define XSK_UNALIGNED_BUF_OFFSET_SHIFT 48
105 #define XSK_UNALIGNED_BUF_ADDR_MASK \
106         ((1ULL << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1)
107
108 /* Rx/Tx descriptor */
109 struct xdp_desc {
110         __u64 addr;
111         __u32 len;
112         __u32 options;
113 };
114
115 /* UMEM descriptor is __u64 */
116
117 /* Flag indicating that the packet continues with the buffer pointed out by the
118  * next frame in the ring. The end of the packet is signalled by setting this
119  * bit to zero. For single buffer packets, every descriptor has 'options' set
120  * to 0 and this maintains backward compatibility.
121  */
122 #define XDP_PKT_CONTD (1 << 0)
123
124 #endif /* _LINUX_IF_XDP_H */