blob: 7161856bcf9c7f572943f6a78676df2aa458a5f7 [file] [log] [blame]
Björn Töpeldac091492018-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öpele61e62b92018-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>
Magnus Karlssonac98d8a2018-06-04 14:05:57 +020012#include <linux/spinlock.h>
Björn Töpele61e62b92018-06-04 14:05:51 +020013#include <linux/mm.h>
Björn Töpelc0c77d82018-05-02 13:01:23 +020014#include <net/sock.h>
15
Björn Töpelb9b6b682018-05-02 13:01:25 +020016struct net_device;
17struct xsk_queue;
Björn Töpele61e62b92018-06-04 14:05:51 +020018
19struct xdp_umem_props {
20 u64 chunk_mask;
21 u64 size;
22};
23
Björn Töpel8aef7342018-06-04 14:05:52 +020024struct xdp_umem_page {
25 void *addr;
Björn Töpel173d3ad2018-06-04 14:05:55 +020026 dma_addr_t dma;
Björn Töpel8aef7342018-06-04 14:05:52 +020027};
28
Björn Töpele61e62b92018-06-04 14:05:51 +020029struct xdp_umem {
30 struct xsk_queue *fq;
31 struct xsk_queue *cq;
Björn Töpel8aef7342018-06-04 14:05:52 +020032 struct xdp_umem_page *pages;
Björn Töpele61e62b92018-06-04 14:05:51 +020033 struct xdp_umem_props props;
34 u32 headroom;
35 u32 chunk_size_nohr;
36 struct user_struct *user;
37 struct pid *pid;
38 unsigned long address;
39 refcount_t users;
40 struct work_struct work;
Björn Töpel8aef7342018-06-04 14:05:52 +020041 struct page **pgs;
Björn Töpele61e62b92018-06-04 14:05:51 +020042 u32 npgs;
Björn Töpel173d3ad2018-06-04 14:05:55 +020043 struct net_device *dev;
44 u16 queue_id;
45 bool zc;
Magnus Karlssonac98d8a2018-06-04 14:05:57 +020046 spinlock_t xsk_list_lock;
47 struct list_head xsk_list;
Björn Töpele61e62b92018-06-04 14:05:51 +020048};
Björn Töpelc0c77d82018-05-02 13:01:23 +020049
50struct xdp_sock {
51 /* struct sock must be the first member of struct xdp_sock */
52 struct sock sk;
Björn Töpelb9b6b682018-05-02 13:01:25 +020053 struct xsk_queue *rx;
54 struct net_device *dev;
Björn Töpelc0c77d82018-05-02 13:01:23 +020055 struct xdp_umem *umem;
Björn Töpelfbfc504a2018-05-02 13:01:28 +020056 struct list_head flush_node;
Magnus Karlsson965a9902018-05-02 13:01:26 +020057 u16 queue_id;
Magnus Karlssonf6145902018-05-02 13:01:32 +020058 struct xsk_queue *tx ____cacheline_aligned_in_smp;
Magnus Karlssonac98d8a2018-06-04 14:05:57 +020059 struct list_head list;
60 bool zc;
Björn Töpelc0c77d82018-05-02 13:01:23 +020061 /* Protects multiple processes in the control path */
62 struct mutex mutex;
Magnus Karlssona9744f72018-06-29 09:48:20 +020063 /* Mutual exclusion of NAPI TX thread and sendmsg error paths
64 * in the SKB destructor callback.
65 */
66 spinlock_t tx_completion_lock;
Björn Töpelc4971762018-05-02 13:01:27 +020067 u64 rx_dropped;
Björn Töpelc0c77d82018-05-02 13:01:23 +020068};
69
Björn Töpelc4971762018-05-02 13:01:27 +020070struct xdp_buff;
71#ifdef CONFIG_XDP_SOCKETS
72int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp);
73int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp);
74void xsk_flush(struct xdp_sock *xs);
Björn Töpelfbfc504a2018-05-02 13:01:28 +020075bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs);
Magnus Karlssonac98d8a2018-06-04 14:05:57 +020076/* Used from netdev driver */
Björn Töpel173d3ad2018-06-04 14:05:55 +020077u64 *xsk_umem_peek_addr(struct xdp_umem *umem, u64 *addr);
78void xsk_umem_discard_addr(struct xdp_umem *umem);
Magnus Karlssonac98d8a2018-06-04 14:05:57 +020079void xsk_umem_complete_tx(struct xdp_umem *umem, u32 nb_entries);
80bool xsk_umem_consume_tx(struct xdp_umem *umem, dma_addr_t *dma, u32 *len);
81void xsk_umem_consume_tx_done(struct xdp_umem *umem);
Björn Töpelc4971762018-05-02 13:01:27 +020082#else
83static inline int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)
84{
85 return -ENOTSUPP;
86}
87
88static inline int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)
89{
90 return -ENOTSUPP;
91}
92
93static inline void xsk_flush(struct xdp_sock *xs)
94{
95}
Björn Töpelfbfc504a2018-05-02 13:01:28 +020096
97static inline bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs)
98{
99 return false;
100}
Björn Töpelc4971762018-05-02 13:01:27 +0200101#endif /* CONFIG_XDP_SOCKETS */
102
Björn Töpelc0c77d82018-05-02 13:01:23 +0200103#endif /* _LINUX_XDP_SOCK_H */