Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 |
| 2 | * AF_XDP internal functions |
| 3 | * Copyright(c) 2018 Intel Corporation. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU General Public License, |
| 7 | * version 2, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | */ |
| 14 | |
| 15 | #ifndef _LINUX_XDP_SOCK_H |
| 16 | #define _LINUX_XDP_SOCK_H |
| 17 | |
| 18 | #include <linux/mutex.h> |
| 19 | #include <net/sock.h> |
| 20 | |
Björn Töpel | b9b6b68 | 2018-05-02 13:01:25 +0200 | [diff] [blame] | 21 | struct net_device; |
| 22 | struct xsk_queue; |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 23 | struct xdp_umem; |
| 24 | |
| 25 | struct xdp_sock { |
| 26 | /* struct sock must be the first member of struct xdp_sock */ |
| 27 | struct sock sk; |
Björn Töpel | b9b6b68 | 2018-05-02 13:01:25 +0200 | [diff] [blame] | 28 | struct xsk_queue *rx; |
| 29 | struct net_device *dev; |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 30 | struct xdp_umem *umem; |
Björn Töpel | fbfc504 | 2018-05-02 13:01:28 +0200 | [diff] [blame^] | 31 | struct list_head flush_node; |
Magnus Karlsson | 965a990 | 2018-05-02 13:01:26 +0200 | [diff] [blame] | 32 | u16 queue_id; |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 33 | /* Protects multiple processes in the control path */ |
| 34 | struct mutex mutex; |
Björn Töpel | c497176 | 2018-05-02 13:01:27 +0200 | [diff] [blame] | 35 | u64 rx_dropped; |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 36 | }; |
| 37 | |
Björn Töpel | c497176 | 2018-05-02 13:01:27 +0200 | [diff] [blame] | 38 | struct xdp_buff; |
| 39 | #ifdef CONFIG_XDP_SOCKETS |
| 40 | int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp); |
| 41 | int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp); |
| 42 | void xsk_flush(struct xdp_sock *xs); |
Björn Töpel | fbfc504 | 2018-05-02 13:01:28 +0200 | [diff] [blame^] | 43 | 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] | 44 | #else |
| 45 | static inline int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp) |
| 46 | { |
| 47 | return -ENOTSUPP; |
| 48 | } |
| 49 | |
| 50 | static inline int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp) |
| 51 | { |
| 52 | return -ENOTSUPP; |
| 53 | } |
| 54 | |
| 55 | static inline void xsk_flush(struct xdp_sock *xs) |
| 56 | { |
| 57 | } |
Björn Töpel | fbfc504 | 2018-05-02 13:01:28 +0200 | [diff] [blame^] | 58 | |
| 59 | static inline bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs) |
| 60 | { |
| 61 | return false; |
| 62 | } |
Björn Töpel | c497176 | 2018-05-02 13:01:27 +0200 | [diff] [blame] | 63 | #endif /* CONFIG_XDP_SOCKETS */ |
| 64 | |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 65 | #endif /* _LINUX_XDP_SOCK_H */ |