Merge tag 'input-for-v5.20-rc0' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-block.git] / include / uapi / linux / if_xdp.h
CommitLineData
dac09149
BT
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
c0c77d8f
BT
3 * if_xdp: XDP socket user-space interface
4 * Copyright(c) 2018 Intel Corporation.
5 *
c0c77d8f
BT
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
965a9909 15/* Options for the sxdp_flags field */
173d3adb
BT
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 */
77cd0d7b
MK
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)
965a9909 28
c05cd364
KL
29/* Flags for xsk_umem_config flags */
30#define XDP_UMEM_UNALIGNED_CHUNK_FLAG (1 << 0)
31
965a9909
MK
32struct sockaddr_xdp {
33 __u16 sxdp_family;
ad75646c 34 __u16 sxdp_flags;
965a9909
MK
35 __u32 sxdp_ifindex;
36 __u32 sxdp_queue_id;
37 __u32 sxdp_shared_umem_fd;
965a9909
MK
38};
39
77cd0d7b
MK
40/* XDP_RING flags */
41#define XDP_RING_NEED_WAKEUP (1 << 0)
42
b3a9e0be
BT
43struct xdp_ring_offset {
44 __u64 producer;
45 __u64 consumer;
46 __u64 desc;
77cd0d7b 47 __u64 flags;
b3a9e0be
BT
48};
49
50struct xdp_mmap_offsets {
51 struct xdp_ring_offset rx;
52 struct xdp_ring_offset tx;
53 struct xdp_ring_offset fr; /* Fill */
54 struct xdp_ring_offset cr; /* Completion */
55};
56
c0c77d8f 57/* XDP socket options */
b3a9e0be
BT
58#define XDP_MMAP_OFFSETS 1
59#define XDP_RX_RING 2
60#define XDP_TX_RING 3
61#define XDP_UMEM_REG 4
62#define XDP_UMEM_FILL_RING 5
63#define XDP_UMEM_COMPLETION_RING 6
64#define XDP_STATISTICS 7
2640d3c8 65#define XDP_OPTIONS 8
c0c77d8f
BT
66
67struct xdp_umem_reg {
68 __u64 addr; /* Start of packet data area */
69 __u64 len; /* Length of packet data area */
bbff2f32
BT
70 __u32 chunk_size;
71 __u32 headroom;
c05cd364 72 __u32 flags;
c0c77d8f
BT
73};
74
af75d9e0 75struct xdp_statistics {
8aa5a335 76 __u64 rx_dropped; /* Dropped for other reasons */
af75d9e0
MK
77 __u64 rx_invalid_descs; /* Dropped due to invalid descriptor */
78 __u64 tx_invalid_descs; /* Dropped due to invalid descriptor */
8aa5a335
CL
79 __u64 rx_ring_full; /* Dropped due to rx ring being full */
80 __u64 rx_fill_ring_empty_descs; /* Failed to retrieve item from fill ring */
81 __u64 tx_ring_empty_descs; /* Failed to retrieve item from tx ring */
af75d9e0
MK
82};
83
2640d3c8
MM
84struct xdp_options {
85 __u32 flags;
86};
87
88/* Flags for the flags field of struct xdp_options */
89#define XDP_OPTIONS_ZEROCOPY (1 << 0)
90
423f3832 91/* Pgoff for mmaping the rings */
b9b6b68e 92#define XDP_PGOFF_RX_RING 0
f6145903 93#define XDP_PGOFF_TX_RING 0x80000000
a5a16e43
GU
94#define XDP_UMEM_PGOFF_FILL_RING 0x100000000ULL
95#define XDP_UMEM_PGOFF_COMPLETION_RING 0x180000000ULL
423f3832 96
c05cd364
KL
97/* Masks for unaligned chunks mode */
98#define XSK_UNALIGNED_BUF_OFFSET_SHIFT 48
99#define XSK_UNALIGNED_BUF_ADDR_MASK \
100 ((1ULL << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1)
101
b3a9e0be 102/* Rx/Tx descriptor */
b9b6b68e 103struct xdp_desc {
bbff2f32 104 __u64 addr;
b9b6b68e 105 __u32 len;
bbff2f32 106 __u32 options;
b9b6b68e
BT
107};
108
bbff2f32 109/* UMEM descriptor is __u64 */
423f3832 110
c0c77d8f 111#endif /* _LINUX_IF_XDP_H */