xref: /openbmc/linux/include/uapi/linux/if_xdp.h (revision c4c8f39a57bf5057fc51a848d42b7e348ecfa31d)
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  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * Author(s): Björn Töpel <bjorn.topel@intel.com>
16  *	      Magnus Karlsson <magnus.karlsson@intel.com>
17  */
18 
19 #ifndef _LINUX_IF_XDP_H
20 #define _LINUX_IF_XDP_H
21 
22 #include <linux/types.h>
23 
24 /* Options for the sxdp_flags field */
25 #define XDP_SHARED_UMEM 1
26 
27 struct sockaddr_xdp {
28 	__u16 sxdp_family;
29 	__u32 sxdp_ifindex;
30 	__u32 sxdp_queue_id;
31 	__u32 sxdp_shared_umem_fd;
32 	__u16 sxdp_flags;
33 };
34 
35 /* XDP socket options */
36 #define XDP_RX_RING			1
37 #define XDP_TX_RING			2
38 #define XDP_UMEM_REG			3
39 #define XDP_UMEM_FILL_RING		4
40 #define XDP_UMEM_COMPLETION_RING	5
41 #define XDP_STATISTICS			6
42 
43 struct xdp_umem_reg {
44 	__u64 addr; /* Start of packet data area */
45 	__u64 len; /* Length of packet data area */
46 	__u32 frame_size; /* Frame size */
47 	__u32 frame_headroom; /* Frame head room */
48 };
49 
50 struct xdp_statistics {
51 	__u64 rx_dropped; /* Dropped for reasons other than invalid desc */
52 	__u64 rx_invalid_descs; /* Dropped due to invalid descriptor */
53 	__u64 tx_invalid_descs; /* Dropped due to invalid descriptor */
54 };
55 
56 /* Pgoff for mmaping the rings */
57 #define XDP_PGOFF_RX_RING			  0
58 #define XDP_PGOFF_TX_RING		 0x80000000
59 #define XDP_UMEM_PGOFF_FILL_RING	0x100000000
60 #define XDP_UMEM_PGOFF_COMPLETION_RING	0x180000000
61 
62 struct xdp_desc {
63 	__u32 idx;
64 	__u32 len;
65 	__u16 offset;
66 	__u8 flags;
67 	__u8 padding[5];
68 };
69 
70 struct xdp_ring {
71 	__u32 producer __attribute__((aligned(64)));
72 	__u32 consumer __attribute__((aligned(64)));
73 };
74 
75 /* Used for the RX and TX queues for packets */
76 struct xdp_rxtx_ring {
77 	struct xdp_ring ptrs;
78 	struct xdp_desc desc[0] __attribute__((aligned(64)));
79 };
80 
81 /* Used for the fill and completion queues for buffers */
82 struct xdp_umem_ring {
83 	struct xdp_ring ptrs;
84 	__u32 desc[0] __attribute__((aligned(64)));
85 };
86 
87 #endif /* _LINUX_IF_XDP_H */
88