blob: 3a6cd88f179dacb7f38386c36fdcc3ed17516a2b [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
Björn Töpele61e62b2018-06-04 14:05:51 +02009#include <linux/workqueue.h>
10#include <linux/if_xdp.h>
Björn Töpelc0c77d82018-05-02 13:01:23 +020011#include <linux/mutex.h>
Björn Töpele61e62b2018-06-04 14:05:51 +020012#include <linux/mm.h>
Björn Töpelc0c77d82018-05-02 13:01:23 +020013#include <net/sock.h>
14
Björn Töpelb9b6b682018-05-02 13:01:25 +020015struct net_device;
16struct xsk_queue;
Björn Töpele61e62b2018-06-04 14:05:51 +020017
18struct xdp_umem_props {
19 u64 chunk_mask;
20 u64 size;
21};
22
23struct xdp_umem {
24 struct xsk_queue *fq;
25 struct xsk_queue *cq;
26 struct page **pgs;
27 struct xdp_umem_props props;
28 u32 headroom;
29 u32 chunk_size_nohr;
30 struct user_struct *user;
31 struct pid *pid;
32 unsigned long address;
33 refcount_t users;
34 struct work_struct work;
35 u32 npgs;
36};
Björn Töpelc0c77d82018-05-02 13:01:23 +020037
38struct xdp_sock {
39 /* struct sock must be the first member of struct xdp_sock */
40 struct sock sk;
Björn Töpelb9b6b682018-05-02 13:01:25 +020041 struct xsk_queue *rx;
42 struct net_device *dev;
Björn Töpelc0c77d82018-05-02 13:01:23 +020043 struct xdp_umem *umem;
Björn Töpelfbfc5042018-05-02 13:01:28 +020044 struct list_head flush_node;
Magnus Karlsson965a9902018-05-02 13:01:26 +020045 u16 queue_id;
Magnus Karlssonf6145902018-05-02 13:01:32 +020046 struct xsk_queue *tx ____cacheline_aligned_in_smp;
Björn Töpelc0c77d82018-05-02 13:01:23 +020047 /* Protects multiple processes in the control path */
48 struct mutex mutex;
Björn Töpelc4971762018-05-02 13:01:27 +020049 u64 rx_dropped;
Björn Töpelc0c77d82018-05-02 13:01:23 +020050};
51
Björn Töpelc4971762018-05-02 13:01:27 +020052struct xdp_buff;
53#ifdef CONFIG_XDP_SOCKETS
54int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp);
55int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp);
56void xsk_flush(struct xdp_sock *xs);
Björn Töpelfbfc5042018-05-02 13:01:28 +020057bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs);
Björn Töpelc4971762018-05-02 13:01:27 +020058#else
59static inline int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)
60{
61 return -ENOTSUPP;
62}
63
64static inline int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)
65{
66 return -ENOTSUPP;
67}
68
69static inline void xsk_flush(struct xdp_sock *xs)
70{
71}
Björn Töpelfbfc5042018-05-02 13:01:28 +020072
73static inline bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs)
74{
75 return false;
76}
Björn Töpelc4971762018-05-02 13:01:27 +020077#endif /* CONFIG_XDP_SOCKETS */
78
Björn Töpelc0c77d82018-05-02 13:01:23 +020079#endif /* _LINUX_XDP_SOCK_H */