xref: /openbmc/linux/include/uapi/linux/if_xdp.h (revision b830f94f)
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 
20 struct sockaddr_xdp {
21 	__u16 sxdp_family;
22 	__u16 sxdp_flags;
23 	__u32 sxdp_ifindex;
24 	__u32 sxdp_queue_id;
25 	__u32 sxdp_shared_umem_fd;
26 };
27 
28 struct xdp_ring_offset {
29 	__u64 producer;
30 	__u64 consumer;
31 	__u64 desc;
32 };
33 
34 struct xdp_mmap_offsets {
35 	struct xdp_ring_offset rx;
36 	struct xdp_ring_offset tx;
37 	struct xdp_ring_offset fr; /* Fill */
38 	struct xdp_ring_offset cr; /* Completion */
39 };
40 
41 /* XDP socket options */
42 #define XDP_MMAP_OFFSETS		1
43 #define XDP_RX_RING			2
44 #define XDP_TX_RING			3
45 #define XDP_UMEM_REG			4
46 #define XDP_UMEM_FILL_RING		5
47 #define XDP_UMEM_COMPLETION_RING	6
48 #define XDP_STATISTICS			7
49 #define XDP_OPTIONS			8
50 
51 struct xdp_umem_reg {
52 	__u64 addr; /* Start of packet data area */
53 	__u64 len; /* Length of packet data area */
54 	__u32 chunk_size;
55 	__u32 headroom;
56 };
57 
58 struct xdp_statistics {
59 	__u64 rx_dropped; /* Dropped for reasons other than invalid desc */
60 	__u64 rx_invalid_descs; /* Dropped due to invalid descriptor */
61 	__u64 tx_invalid_descs; /* Dropped due to invalid descriptor */
62 };
63 
64 struct xdp_options {
65 	__u32 flags;
66 };
67 
68 /* Flags for the flags field of struct xdp_options */
69 #define XDP_OPTIONS_ZEROCOPY (1 << 0)
70 
71 /* Pgoff for mmaping the rings */
72 #define XDP_PGOFF_RX_RING			  0
73 #define XDP_PGOFF_TX_RING		 0x80000000
74 #define XDP_UMEM_PGOFF_FILL_RING	0x100000000ULL
75 #define XDP_UMEM_PGOFF_COMPLETION_RING	0x180000000ULL
76 
77 /* Rx/Tx descriptor */
78 struct xdp_desc {
79 	__u64 addr;
80 	__u32 len;
81 	__u32 options;
82 };
83 
84 /* UMEM descriptor is __u64 */
85 
86 #endif /* _LINUX_IF_XDP_H */
87