Björn Töpel | dac0914 | 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 | |
| 9 | #include <linux/mutex.h> |
| 10 | #include <net/sock.h> |
| 11 | |
Björn Töpel | b9b6b68 | 2018-05-02 13:01:25 +0200 | [diff] [blame] | 12 | struct net_device; |
| 13 | struct xsk_queue; |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 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; |
Björn Töpel | b9b6b68 | 2018-05-02 13:01:25 +0200 | [diff] [blame] | 19 | struct xsk_queue *rx; |
| 20 | struct net_device *dev; |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 21 | struct xdp_umem *umem; |
Björn Töpel | fbfc504 | 2018-05-02 13:01:28 +0200 | [diff] [blame] | 22 | struct list_head flush_node; |
Magnus Karlsson | 965a990 | 2018-05-02 13:01:26 +0200 | [diff] [blame] | 23 | u16 queue_id; |
Magnus Karlsson | f614590 | 2018-05-02 13:01:32 +0200 | [diff] [blame] | 24 | struct xsk_queue *tx ____cacheline_aligned_in_smp; |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 25 | /* Protects multiple processes in the control path */ |
| 26 | struct mutex mutex; |
Björn Töpel | c497176 | 2018-05-02 13:01:27 +0200 | [diff] [blame] | 27 | u64 rx_dropped; |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 28 | }; |
| 29 | |
Björn Töpel | c497176 | 2018-05-02 13:01:27 +0200 | [diff] [blame] | 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); |
Björn Töpel | fbfc504 | 2018-05-02 13:01:28 +0200 | [diff] [blame] | 35 | bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs); |
Björn Töpel | c497176 | 2018-05-02 13:01:27 +0200 | [diff] [blame] | 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 | } |
Björn Töpel | fbfc504 | 2018-05-02 13:01:28 +0200 | [diff] [blame] | 50 | |
| 51 | static inline bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs) |
| 52 | { |
| 53 | return false; |
| 54 | } |
Björn Töpel | c497176 | 2018-05-02 13:01:27 +0200 | [diff] [blame] | 55 | #endif /* CONFIG_XDP_SOCKETS */ |
| 56 | |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 57 | #endif /* _LINUX_XDP_SOCK_H */ |