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