blob: 7a647c56ec153286d3b2032bcdb3f05232a6694a [file] [log] [blame]
Björn Töpeldac09142018-05-18 14:00:21 +02001/* SPDX-License-Identifier: GPL-2.0 */
2/* AF_XDP internal functions
Björn Töpelc0c77d82018-05-02 13:01:23 +02003 * Copyright(c) 2018 Intel Corporation.
Björn Töpelc0c77d82018-05-02 13:01:23 +02004 */
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öpelb9b6b682018-05-02 13:01:25 +020012struct net_device;
13struct xsk_queue;
Björn Töpelc0c77d82018-05-02 13:01:23 +020014struct xdp_umem;
15
16struct xdp_sock {
17 /* struct sock must be the first member of struct xdp_sock */
18 struct sock sk;
Björn Töpelb9b6b682018-05-02 13:01:25 +020019 struct xsk_queue *rx;
20 struct net_device *dev;
Björn Töpelc0c77d82018-05-02 13:01:23 +020021 struct xdp_umem *umem;
Björn Töpelfbfc5042018-05-02 13:01:28 +020022 struct list_head flush_node;
Magnus Karlsson965a9902018-05-02 13:01:26 +020023 u16 queue_id;
Magnus Karlssonf6145902018-05-02 13:01:32 +020024 struct xsk_queue *tx ____cacheline_aligned_in_smp;
Björn Töpelc0c77d82018-05-02 13:01:23 +020025 /* Protects multiple processes in the control path */
26 struct mutex mutex;
Björn Töpelc4971762018-05-02 13:01:27 +020027 u64 rx_dropped;
Björn Töpelc0c77d82018-05-02 13:01:23 +020028};
29
Björn Töpelc4971762018-05-02 13:01:27 +020030struct xdp_buff;
31#ifdef CONFIG_XDP_SOCKETS
32int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp);
33int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp);
34void xsk_flush(struct xdp_sock *xs);
Björn Töpelfbfc5042018-05-02 13:01:28 +020035bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs);
Björn Töpelc4971762018-05-02 13:01:27 +020036#else
37static inline int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)
38{
39 return -ENOTSUPP;
40}
41
42static inline int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)
43{
44 return -ENOTSUPP;
45}
46
47static inline void xsk_flush(struct xdp_sock *xs)
48{
49}
Björn Töpelfbfc5042018-05-02 13:01:28 +020050
51static inline bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs)
52{
53 return false;
54}
Björn Töpelc4971762018-05-02 13:01:27 +020055#endif /* CONFIG_XDP_SOCKETS */
56
Björn Töpelc0c77d82018-05-02 13:01:23 +020057#endif /* _LINUX_XDP_SOCK_H */