xref: /openbmc/linux/include/net/xdp_sock.h (revision 77ab8d5d)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* AF_XDP internal functions
3  * Copyright(c) 2018 Intel Corporation.
4  */
5 
6 #ifndef _LINUX_XDP_SOCK_H
7 #define _LINUX_XDP_SOCK_H
8 
9 #include <linux/mutex.h>
10 #include <net/sock.h>
11 
12 struct net_device;
13 struct xsk_queue;
14 struct xdp_umem;
15 
16 struct xdp_sock {
17 	/* struct sock must be the first member of struct xdp_sock */
18 	struct sock sk;
19 	struct xsk_queue *rx;
20 	struct net_device *dev;
21 	struct xdp_umem *umem;
22 	struct list_head flush_node;
23 	u16 queue_id;
24 	struct xsk_queue *tx ____cacheline_aligned_in_smp;
25 	/* Protects multiple processes in the control path */
26 	struct mutex mutex;
27 	u64 rx_dropped;
28 };
29 
30 struct xdp_buff;
31 #ifdef CONFIG_XDP_SOCKETS
32 int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp);
33 int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp);
34 void xsk_flush(struct xdp_sock *xs);
35 bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs);
36 #else
37 static inline int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)
38 {
39 	return -ENOTSUPP;
40 }
41 
42 static inline int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)
43 {
44 	return -ENOTSUPP;
45 }
46 
47 static inline void xsk_flush(struct xdp_sock *xs)
48 {
49 }
50 
51 static inline bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs)
52 {
53 	return false;
54 }
55 #endif /* CONFIG_XDP_SOCKETS */
56 
57 #endif /* _LINUX_XDP_SOCK_H */
58