Björn Töpel | dac09149 | 2018-05-18 14:00:21 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | /* AF_XDP internal functions | ||||
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 3 | * Copyright(c) 2018 Intel Corporation. |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 4 | */ |
5 | |||||
6 | #ifndef _LINUX_XDP_SOCK_H | ||||
7 | #define _LINUX_XDP_SOCK_H | ||||
8 | |||||
Jakub Kicinski | b645941 | 2021-12-28 16:49:13 -0800 | [diff] [blame] | 9 | #include <linux/bpf.h> |
Björn Töpel | e61e62b9 | 2018-06-04 14:05:51 +0200 | [diff] [blame] | 10 | #include <linux/workqueue.h> |
11 | #include <linux/if_xdp.h> | ||||
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 12 | #include <linux/mutex.h> |
Magnus Karlsson | ac98d8a | 2018-06-04 14:05:57 +0200 | [diff] [blame] | 13 | #include <linux/spinlock.h> |
Björn Töpel | e61e62b9 | 2018-06-04 14:05:51 +0200 | [diff] [blame] | 14 | #include <linux/mm.h> |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 15 | #include <net/sock.h> |
16 | |||||
Björn Töpel | b9b6b68 | 2018-05-02 13:01:25 +0200 | [diff] [blame] | 17 | struct net_device; |
18 | struct xsk_queue; | ||||
Magnus Karlsson | a71506a | 2020-05-20 21:20:51 +0200 | [diff] [blame] | 19 | struct xdp_buff; |
Björn Töpel | e61e62b9 | 2018-06-04 14:05:51 +0200 | [diff] [blame] | 20 | |
Björn Töpel | e61e62b9 | 2018-06-04 14:05:51 +0200 | [diff] [blame] | 21 | struct xdp_umem { |
Magnus Karlsson | 7f7ffa4 | 2020-08-28 10:26:21 +0200 | [diff] [blame] | 22 | void *addrs; |
Magnus Karlsson | 93ee30f | 2018-08-31 13:40:02 +0200 | [diff] [blame] | 23 | u64 size; |
Björn Töpel | e61e62b9 | 2018-06-04 14:05:51 +0200 | [diff] [blame] | 24 | u32 headroom; |
Björn Töpel | 2b43470 | 2020-05-20 21:20:53 +0200 | [diff] [blame] | 25 | u32 chunk_size; |
Magnus Karlsson | 1c1efc2 | 2020-08-28 10:26:17 +0200 | [diff] [blame] | 26 | u32 chunks; |
Magnus Karlsson | 8ef4e27 | 2020-08-28 10:26:23 +0200 | [diff] [blame] | 27 | u32 npgs; |
Björn Töpel | e61e62b9 | 2018-06-04 14:05:51 +0200 | [diff] [blame] | 28 | struct user_struct *user; |
Björn Töpel | e61e62b9 | 2018-06-04 14:05:51 +0200 | [diff] [blame] | 29 | refcount_t users; |
Magnus Karlsson | 77cd0d7 | 2019-08-14 09:27:17 +0200 | [diff] [blame] | 30 | u8 flags; |
Björn Töpel | 173d3ad | 2018-06-04 14:05:55 +0200 | [diff] [blame] | 31 | bool zc; |
Magnus Karlsson | 8ef4e27 | 2020-08-28 10:26:23 +0200 | [diff] [blame] | 32 | struct page **pgs; |
33 | int id; | ||||
Magnus Karlsson | 921b686 | 2020-08-28 10:26:22 +0200 | [diff] [blame] | 34 | struct list_head xsk_dma_list; |
Magnus Karlsson | 537cf4e | 2020-11-20 12:53:39 +0100 | [diff] [blame] | 35 | struct work_struct work; |
Björn Töpel | e61e62b9 | 2018-06-04 14:05:51 +0200 | [diff] [blame] | 36 | }; |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 37 | |
Björn Töpel | d817991 | 2019-11-01 12:03:46 +0100 | [diff] [blame] | 38 | struct xsk_map { |
39 | struct bpf_map map; | ||||
Björn Töpel | d817991 | 2019-11-01 12:03:46 +0100 | [diff] [blame] | 40 | spinlock_t lock; /* Synchronize map updates */ |
Toke Høiland-Jørgensen | 782347b | 2021-06-24 18:05:55 +0200 | [diff] [blame] | 41 | struct xdp_sock __rcu *xsk_map[]; |
Björn Töpel | d817991 | 2019-11-01 12:03:46 +0100 | [diff] [blame] | 42 | }; |
43 | |||||
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 44 | struct xdp_sock { |
45 | /* struct sock must be the first member of struct xdp_sock */ | ||||
46 | struct sock sk; | ||||
Magnus Karlsson | 8ef4e27 | 2020-08-28 10:26:23 +0200 | [diff] [blame] | 47 | struct xsk_queue *rx ____cacheline_aligned_in_smp; |
Björn Töpel | b9b6b68 | 2018-05-02 13:01:25 +0200 | [diff] [blame] | 48 | struct net_device *dev; |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 49 | struct xdp_umem *umem; |
Björn Töpel | fbfc504a | 2018-05-02 13:01:28 +0200 | [diff] [blame] | 50 | struct list_head flush_node; |
Magnus Karlsson | c465576 | 2020-08-28 10:26:16 +0200 | [diff] [blame] | 51 | struct xsk_buff_pool *pool; |
Magnus Karlsson | 965a990 | 2018-05-02 13:01:26 +0200 | [diff] [blame] | 52 | u16 queue_id; |
Magnus Karlsson | ac98d8a | 2018-06-04 14:05:57 +0200 | [diff] [blame] | 53 | bool zc; |
Ilya Maximets | 455302d | 2019-06-28 11:04:07 +0300 | [diff] [blame] | 54 | enum { |
55 | XSK_READY = 0, | ||||
56 | XSK_BOUND, | ||||
57 | XSK_UNBOUND, | ||||
58 | } state; | ||||
Magnus Karlsson | 8ef4e27 | 2020-08-28 10:26:23 +0200 | [diff] [blame] | 59 | |
Jonathan Lemon | fada7fd | 2019-06-06 13:59:40 -0700 | [diff] [blame] | 60 | struct xsk_queue *tx ____cacheline_aligned_in_smp; |
Magnus Karlsson | a5aa8e5 | 2020-08-28 10:26:20 +0200 | [diff] [blame] | 61 | struct list_head tx_list; |
Ilya Maximets | bf0bdd1 | 2019-07-03 15:09:16 +0300 | [diff] [blame] | 62 | /* Protects generic receive. */ |
63 | spinlock_t rx_lock; | ||||
Ciara Loftus | 8aa5a33 | 2020-07-08 07:28:33 +0000 | [diff] [blame] | 64 | |
65 | /* Statistics */ | ||||
Björn Töpel | c497176 | 2018-05-02 13:01:27 +0200 | [diff] [blame] | 66 | u64 rx_dropped; |
Ciara Loftus | 8aa5a33 | 2020-07-08 07:28:33 +0000 | [diff] [blame] | 67 | u64 rx_queue_full; |
68 | |||||
Björn Töpel | 0402acd | 2019-08-15 11:30:13 +0200 | [diff] [blame] | 69 | struct list_head map_list; |
70 | /* Protects map_list */ | ||||
71 | spinlock_t map_list_lock; | ||||
Magnus Karlsson | 8ef4e27 | 2020-08-28 10:26:23 +0200 | [diff] [blame] | 72 | /* Protects multiple processes in the control path */ |
73 | struct mutex mutex; | ||||
Magnus Karlsson | 7361f9c | 2020-08-28 10:26:18 +0200 | [diff] [blame] | 74 | struct xsk_queue *fq_tmp; /* Only as tmp storage before bind */ |
75 | struct xsk_queue *cq_tmp; /* Only as tmp storage before bind */ | ||||
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 76 | }; |
77 | |||||
Björn Töpel | c497176 | 2018-05-02 13:01:27 +0200 | [diff] [blame] | 78 | #ifdef CONFIG_XDP_SOCKETS |
Björn Töpel | 9025403 | 2018-08-28 14:44:27 +0200 | [diff] [blame] | 79 | |
Magnus Karlsson | a71506a | 2020-05-20 21:20:51 +0200 | [diff] [blame] | 80 | int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp); |
Björn Töpel | e312b9e | 2019-12-19 07:10:02 +0100 | [diff] [blame] | 81 | int __xsk_map_redirect(struct xdp_sock *xs, struct xdp_buff *xdp); |
82 | void __xsk_map_flush(void); | ||||
Björn Töpel | d817991 | 2019-11-01 12:03:46 +0100 | [diff] [blame] | 83 | |
Björn Töpel | c497176 | 2018-05-02 13:01:27 +0200 | [diff] [blame] | 84 | #else |
Magnus Karlsson | a71506a | 2020-05-20 21:20:51 +0200 | [diff] [blame] | 85 | |
Björn Töpel | c497176 | 2018-05-02 13:01:27 +0200 | [diff] [blame] | 86 | static inline int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp) |
87 | { | ||||
88 | return -ENOTSUPP; | ||||
89 | } | ||||
90 | |||||
Magnus Karlsson | a71506a | 2020-05-20 21:20:51 +0200 | [diff] [blame] | 91 | static inline int __xsk_map_redirect(struct xdp_sock *xs, struct xdp_buff *xdp) |
Maxim Mikityanskiy | d57d764 | 2019-06-26 17:35:24 +0300 | [diff] [blame] | 92 | { |
Magnus Karlsson | a71506a | 2020-05-20 21:20:51 +0200 | [diff] [blame] | 93 | return -EOPNOTSUPP; |
Maxim Mikityanskiy | d57d764 | 2019-06-26 17:35:24 +0300 | [diff] [blame] | 94 | } |
95 | |||||
Magnus Karlsson | a71506a | 2020-05-20 21:20:51 +0200 | [diff] [blame] | 96 | static inline void __xsk_map_flush(void) |
Björn Töpel | 9025403 | 2018-08-28 14:44:27 +0200 | [diff] [blame] | 97 | { |
98 | } | ||||
99 | |||||
Björn Töpel | c497176 | 2018-05-02 13:01:27 +0200 | [diff] [blame] | 100 | #endif /* CONFIG_XDP_SOCKETS */ |
101 | |||||
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 102 | #endif /* _LINUX_XDP_SOCK_H */ |