1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* AF_XDP internal functions
3 * Copyright(c) 2018 Intel Corporation.
6 #ifndef _LINUX_XDP_SOCK_H
7 #define _LINUX_XDP_SOCK_H
9 #include <linux/workqueue.h>
10 #include <linux/if_xdp.h>
11 #include <linux/mutex.h>
12 #include <linux/spinlock.h>
23 struct xsk_buff_pool *pool;
27 struct user_struct *user;
29 struct work_struct work;
36 struct net_device *dev;
38 spinlock_t xsk_tx_list_lock;
39 struct list_head xsk_tx_list;
44 spinlock_t lock; /* Synchronize map updates */
45 struct xdp_sock *xsk_map[];
49 /* struct sock must be the first member of struct xdp_sock */
52 struct net_device *dev;
53 struct xdp_umem *umem;
54 struct list_head flush_node;
62 /* Protects multiple processes in the control path */
64 struct xsk_queue *tx ____cacheline_aligned_in_smp;
65 struct list_head list;
66 /* Mutual exclusion of NAPI TX thread and sendmsg error paths
67 * in the SKB destructor callback.
69 spinlock_t tx_completion_lock;
70 /* Protects generic receive. */
73 struct list_head map_list;
74 /* Protects map_list */
75 spinlock_t map_list_lock;
78 #ifdef CONFIG_XDP_SOCKETS
80 int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp);
81 int __xsk_map_redirect(struct xdp_sock *xs, struct xdp_buff *xdp);
82 void __xsk_map_flush(void);
84 static inline struct xdp_sock *__xsk_map_lookup_elem(struct bpf_map *map,
87 struct xsk_map *m = container_of(map, struct xsk_map, map);
90 if (key >= map->max_entries)
93 xs = READ_ONCE(m->xsk_map[key]);
99 static inline int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)
104 static inline int __xsk_map_redirect(struct xdp_sock *xs, struct xdp_buff *xdp)
109 static inline void __xsk_map_flush(void)
113 static inline struct xdp_sock *__xsk_map_lookup_elem(struct bpf_map *map,
119 #endif /* CONFIG_XDP_SOCKETS */
121 #endif /* _LINUX_XDP_SOCK_H */