blob: ccf848f7efa4b5810e13cf2b0e6c3b061d396b70 [file] [log] [blame]
Magnus Karlssona71506a2020-05-20 21:20:51 +02001/* SPDX-License-Identifier: GPL-2.0 */
2/* Interface for implementing AF_XDP zero-copy support in drivers.
3 * Copyright(c) 2020 Intel Corporation.
4 */
5
6#ifndef _LINUX_XDP_SOCK_DRV_H
7#define _LINUX_XDP_SOCK_DRV_H
8
9#include <net/xdp_sock.h>
Björn Töpel2b434702020-05-20 21:20:53 +020010#include <net/xsk_buff_pool.h>
Magnus Karlssona71506a2020-05-20 21:20:51 +020011
12#ifdef CONFIG_XDP_SOCKETS
13
Magnus Karlssona71506a2020-05-20 21:20:51 +020014void xsk_umem_complete_tx(struct xdp_umem *umem, u32 nb_entries);
15bool xsk_umem_consume_tx(struct xdp_umem *umem, struct xdp_desc *desc);
16void xsk_umem_consume_tx_done(struct xdp_umem *umem);
Magnus Karlssona71506a2020-05-20 21:20:51 +020017struct xdp_umem *xdp_get_umem_from_qid(struct net_device *dev, u16 queue_id);
18void xsk_set_rx_need_wakeup(struct xdp_umem *umem);
19void xsk_set_tx_need_wakeup(struct xdp_umem *umem);
20void xsk_clear_rx_need_wakeup(struct xdp_umem *umem);
21void xsk_clear_tx_need_wakeup(struct xdp_umem *umem);
22bool xsk_umem_uses_need_wakeup(struct xdp_umem *umem);
23
Björn Töpel2b434702020-05-20 21:20:53 +020024static inline u32 xsk_umem_get_headroom(struct xdp_umem *umem)
25{
26 return XDP_PACKET_HEADROOM + umem->headroom;
27}
28
29static inline u32 xsk_umem_get_chunk_size(struct xdp_umem *umem)
30{
31 return umem->chunk_size;
32}
33
34static inline u32 xsk_umem_get_rx_frame_size(struct xdp_umem *umem)
35{
36 return xsk_umem_get_chunk_size(umem) - xsk_umem_get_headroom(umem);
37}
38
39static inline void xsk_buff_set_rxq_info(struct xdp_umem *umem,
40 struct xdp_rxq_info *rxq)
41{
42 xp_set_rxq_info(umem->pool, rxq);
43}
44
45static inline void xsk_buff_dma_unmap(struct xdp_umem *umem,
46 unsigned long attrs)
47{
48 xp_dma_unmap(umem->pool, attrs);
49}
50
51static inline int xsk_buff_dma_map(struct xdp_umem *umem, struct device *dev,
52 unsigned long attrs)
53{
54 return xp_dma_map(umem->pool, dev, attrs, umem->pgs, umem->npgs);
55}
56
57static inline dma_addr_t xsk_buff_xdp_get_dma(struct xdp_buff *xdp)
58{
59 struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp);
60
61 return xp_get_dma(xskb);
62}
63
64static inline dma_addr_t xsk_buff_xdp_get_frame_dma(struct xdp_buff *xdp)
65{
66 struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp);
67
68 return xp_get_frame_dma(xskb);
69}
70
71static inline struct xdp_buff *xsk_buff_alloc(struct xdp_umem *umem)
72{
73 return xp_alloc(umem->pool);
74}
75
76static inline bool xsk_buff_can_alloc(struct xdp_umem *umem, u32 count)
77{
78 return xp_can_alloc(umem->pool, count);
79}
80
81static inline void xsk_buff_free(struct xdp_buff *xdp)
82{
83 struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp);
84
85 xp_free(xskb);
86}
87
88static inline dma_addr_t xsk_buff_raw_get_dma(struct xdp_umem *umem, u64 addr)
89{
90 return xp_raw_get_dma(umem->pool, addr);
91}
92
93static inline void *xsk_buff_raw_get_data(struct xdp_umem *umem, u64 addr)
94{
95 return xp_raw_get_data(umem->pool, addr);
96}
97
98static inline void xsk_buff_dma_sync_for_cpu(struct xdp_buff *xdp)
99{
100 struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp);
101
102 xp_dma_sync_for_cpu(xskb);
103}
104
105static inline void xsk_buff_raw_dma_sync_for_device(struct xdp_umem *umem,
106 dma_addr_t dma,
107 size_t size)
108{
109 xp_dma_sync_for_device(umem->pool, dma, size);
110}
111
Magnus Karlssona71506a2020-05-20 21:20:51 +0200112#else
113
Magnus Karlssona71506a2020-05-20 21:20:51 +0200114static inline void xsk_umem_complete_tx(struct xdp_umem *umem, u32 nb_entries)
115{
116}
117
118static inline bool xsk_umem_consume_tx(struct xdp_umem *umem,
119 struct xdp_desc *desc)
120{
121 return false;
122}
123
124static inline void xsk_umem_consume_tx_done(struct xdp_umem *umem)
125{
126}
127
Magnus Karlssona71506a2020-05-20 21:20:51 +0200128static inline struct xdp_umem *xdp_get_umem_from_qid(struct net_device *dev,
129 u16 queue_id)
130{
131 return NULL;
132}
133
Magnus Karlssona71506a2020-05-20 21:20:51 +0200134static inline void xsk_set_rx_need_wakeup(struct xdp_umem *umem)
135{
136}
137
138static inline void xsk_set_tx_need_wakeup(struct xdp_umem *umem)
139{
140}
141
142static inline void xsk_clear_rx_need_wakeup(struct xdp_umem *umem)
143{
144}
145
146static inline void xsk_clear_tx_need_wakeup(struct xdp_umem *umem)
147{
148}
149
150static inline bool xsk_umem_uses_need_wakeup(struct xdp_umem *umem)
151{
152 return false;
153}
154
Björn Töpel2b434702020-05-20 21:20:53 +0200155static inline u32 xsk_umem_get_headroom(struct xdp_umem *umem)
156{
157 return 0;
158}
159
160static inline u32 xsk_umem_get_chunk_size(struct xdp_umem *umem)
161{
162 return 0;
163}
164
165static inline u32 xsk_umem_get_rx_frame_size(struct xdp_umem *umem)
166{
167 return 0;
168}
169
170static inline void xsk_buff_set_rxq_info(struct xdp_umem *umem,
171 struct xdp_rxq_info *rxq)
172{
173}
174
175static inline void xsk_buff_dma_unmap(struct xdp_umem *umem,
176 unsigned long attrs)
177{
178}
179
180static inline int xsk_buff_dma_map(struct xdp_umem *umem, struct device *dev,
181 unsigned long attrs)
182{
183 return 0;
184}
185
186static inline dma_addr_t xsk_buff_xdp_get_dma(struct xdp_buff *xdp)
187{
188 return 0;
189}
190
191static inline dma_addr_t xsk_buff_xdp_get_frame_dma(struct xdp_buff *xdp)
192{
193 return 0;
194}
195
196static inline struct xdp_buff *xsk_buff_alloc(struct xdp_umem *umem)
197{
198 return NULL;
199}
200
201static inline bool xsk_buff_can_alloc(struct xdp_umem *umem, u32 count)
202{
203 return false;
204}
205
206static inline void xsk_buff_free(struct xdp_buff *xdp)
207{
208}
209
210static inline dma_addr_t xsk_buff_raw_get_dma(struct xdp_umem *umem, u64 addr)
211{
212 return 0;
213}
214
215static inline void *xsk_buff_raw_get_data(struct xdp_umem *umem, u64 addr)
216{
217 return NULL;
218}
219
220static inline void xsk_buff_dma_sync_for_cpu(struct xdp_buff *xdp)
221{
222}
223
224static inline void xsk_buff_raw_dma_sync_for_device(struct xdp_umem *umem,
225 dma_addr_t dma,
226 size_t size)
227{
228}
229
Magnus Karlssona71506a2020-05-20 21:20:51 +0200230#endif /* CONFIG_XDP_SOCKETS */
231
232#endif /* _LINUX_XDP_SOCK_DRV_H */