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 | |
Björn Töpel | e61e62b9 | 2018-06-04 14:05:51 +0200 | [diff] [blame] | 9 | #include <linux/workqueue.h> |
| 10 | #include <linux/if_xdp.h> |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 11 | #include <linux/mutex.h> |
Magnus Karlsson | ac98d8a | 2018-06-04 14:05:57 +0200 | [diff] [blame] | 12 | #include <linux/spinlock.h> |
Björn Töpel | e61e62b9 | 2018-06-04 14:05:51 +0200 | [diff] [blame] | 13 | #include <linux/mm.h> |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 14 | #include <net/sock.h> |
| 15 | |
Björn Töpel | b9b6b68 | 2018-05-02 13:01:25 +0200 | [diff] [blame] | 16 | struct net_device; |
| 17 | struct xsk_queue; |
Björn Töpel | e61e62b9 | 2018-06-04 14:05:51 +0200 | [diff] [blame] | 18 | |
| 19 | struct xdp_umem_props { |
| 20 | u64 chunk_mask; |
| 21 | u64 size; |
| 22 | }; |
| 23 | |
Björn Töpel | 8aef734 | 2018-06-04 14:05:52 +0200 | [diff] [blame] | 24 | struct xdp_umem_page { |
| 25 | void *addr; |
Björn Töpel | 173d3ad | 2018-06-04 14:05:55 +0200 | [diff] [blame] | 26 | dma_addr_t dma; |
Björn Töpel | 8aef734 | 2018-06-04 14:05:52 +0200 | [diff] [blame] | 27 | }; |
| 28 | |
Björn Töpel | e61e62b9 | 2018-06-04 14:05:51 +0200 | [diff] [blame] | 29 | struct xdp_umem { |
| 30 | struct xsk_queue *fq; |
| 31 | struct xsk_queue *cq; |
Björn Töpel | 8aef734 | 2018-06-04 14:05:52 +0200 | [diff] [blame] | 32 | struct xdp_umem_page *pages; |
Björn Töpel | e61e62b9 | 2018-06-04 14:05:51 +0200 | [diff] [blame] | 33 | struct xdp_umem_props props; |
| 34 | u32 headroom; |
| 35 | u32 chunk_size_nohr; |
| 36 | struct user_struct *user; |
| 37 | struct pid *pid; |
| 38 | unsigned long address; |
| 39 | refcount_t users; |
| 40 | struct work_struct work; |
Björn Töpel | 8aef734 | 2018-06-04 14:05:52 +0200 | [diff] [blame] | 41 | struct page **pgs; |
Björn Töpel | e61e62b9 | 2018-06-04 14:05:51 +0200 | [diff] [blame] | 42 | u32 npgs; |
Björn Töpel | 173d3ad | 2018-06-04 14:05:55 +0200 | [diff] [blame] | 43 | struct net_device *dev; |
| 44 | u16 queue_id; |
| 45 | bool zc; |
Magnus Karlsson | ac98d8a | 2018-06-04 14:05:57 +0200 | [diff] [blame] | 46 | spinlock_t xsk_list_lock; |
| 47 | struct list_head xsk_list; |
Björn Töpel | e61e62b9 | 2018-06-04 14:05:51 +0200 | [diff] [blame] | 48 | }; |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 49 | |
| 50 | struct xdp_sock { |
| 51 | /* struct sock must be the first member of struct xdp_sock */ |
| 52 | struct sock sk; |
Björn Töpel | b9b6b68 | 2018-05-02 13:01:25 +0200 | [diff] [blame] | 53 | struct xsk_queue *rx; |
| 54 | struct net_device *dev; |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 55 | struct xdp_umem *umem; |
Björn Töpel | fbfc504a | 2018-05-02 13:01:28 +0200 | [diff] [blame] | 56 | struct list_head flush_node; |
Magnus Karlsson | 965a990 | 2018-05-02 13:01:26 +0200 | [diff] [blame] | 57 | u16 queue_id; |
Magnus Karlsson | f614590 | 2018-05-02 13:01:32 +0200 | [diff] [blame] | 58 | struct xsk_queue *tx ____cacheline_aligned_in_smp; |
Magnus Karlsson | ac98d8a | 2018-06-04 14:05:57 +0200 | [diff] [blame] | 59 | struct list_head list; |
| 60 | bool zc; |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 61 | /* Protects multiple processes in the control path */ |
| 62 | struct mutex mutex; |
Magnus Karlsson | a9744f7 | 2018-06-29 09:48:20 +0200 | [diff] [blame] | 63 | /* Mutual exclusion of NAPI TX thread and sendmsg error paths |
| 64 | * in the SKB destructor callback. |
| 65 | */ |
| 66 | spinlock_t tx_completion_lock; |
Björn Töpel | c497176 | 2018-05-02 13:01:27 +0200 | [diff] [blame] | 67 | u64 rx_dropped; |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 68 | }; |
| 69 | |
Björn Töpel | c497176 | 2018-05-02 13:01:27 +0200 | [diff] [blame] | 70 | struct xdp_buff; |
| 71 | #ifdef CONFIG_XDP_SOCKETS |
| 72 | int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp); |
| 73 | int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp); |
| 74 | void xsk_flush(struct xdp_sock *xs); |
Björn Töpel | fbfc504a | 2018-05-02 13:01:28 +0200 | [diff] [blame] | 75 | bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs); |
Magnus Karlsson | ac98d8a | 2018-06-04 14:05:57 +0200 | [diff] [blame] | 76 | /* Used from netdev driver */ |
Björn Töpel | 173d3ad | 2018-06-04 14:05:55 +0200 | [diff] [blame] | 77 | u64 *xsk_umem_peek_addr(struct xdp_umem *umem, u64 *addr); |
| 78 | void xsk_umem_discard_addr(struct xdp_umem *umem); |
Magnus Karlsson | ac98d8a | 2018-06-04 14:05:57 +0200 | [diff] [blame] | 79 | void xsk_umem_complete_tx(struct xdp_umem *umem, u32 nb_entries); |
| 80 | bool xsk_umem_consume_tx(struct xdp_umem *umem, dma_addr_t *dma, u32 *len); |
| 81 | void xsk_umem_consume_tx_done(struct xdp_umem *umem); |
Björn Töpel | c497176 | 2018-05-02 13:01:27 +0200 | [diff] [blame] | 82 | #else |
| 83 | static inline int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp) |
| 84 | { |
| 85 | return -ENOTSUPP; |
| 86 | } |
| 87 | |
| 88 | static inline int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp) |
| 89 | { |
| 90 | return -ENOTSUPP; |
| 91 | } |
| 92 | |
| 93 | static inline void xsk_flush(struct xdp_sock *xs) |
| 94 | { |
| 95 | } |
Björn Töpel | fbfc504a | 2018-05-02 13:01:28 +0200 | [diff] [blame] | 96 | |
| 97 | static inline bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs) |
| 98 | { |
| 99 | return false; |
| 100 | } |
Björn Töpel | c497176 | 2018-05-02 13:01:27 +0200 | [diff] [blame] | 101 | #endif /* CONFIG_XDP_SOCKETS */ |
| 102 | |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 103 | #endif /* _LINUX_XDP_SOCK_H */ |