xref: /openbmc/linux/include/uapi/linux/if_xdp.h (revision d2574c33)
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 
50 struct xdp_umem_reg {
51 	__u64 addr; /* Start of packet data area */
52 	__u64 len; /* Length of packet data area */
53 	__u32 chunk_size;
54 	__u32 headroom;
55 };
56 
57 struct xdp_statistics {
58 	__u64 rx_dropped; /* Dropped for reasons other than invalid desc */
59 	__u64 rx_invalid_descs; /* Dropped due to invalid descriptor */
60 	__u64 tx_invalid_descs; /* Dropped due to invalid descriptor */
61 };
62 
63 /* Pgoff for mmaping the rings */
64 #define XDP_PGOFF_RX_RING			  0
65 #define XDP_PGOFF_TX_RING		 0x80000000
66 #define XDP_UMEM_PGOFF_FILL_RING	0x100000000ULL
67 #define XDP_UMEM_PGOFF_COMPLETION_RING	0x180000000ULL
68 
69 /* Rx/Tx descriptor */
70 struct xdp_desc {
71 	__u64 addr;
72 	__u32 len;
73 	__u32 options;
74 };
75 
76 /* UMEM descriptor is __u64 */
77 
78 #endif /* _LINUX_IF_XDP_H */
79