Merge tag 'block-5.9-2020-08-14' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / include / net / xdp_sock_drv.h
blobccf848f7efa4b5810e13cf2b0e6c3b061d396b70
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Interface for implementing AF_XDP zero-copy support in drivers.
3 * Copyright(c) 2020 Intel Corporation.
4 */
6 #ifndef _LINUX_XDP_SOCK_DRV_H
7 #define _LINUX_XDP_SOCK_DRV_H
9 #include <net/xdp_sock.h>
10 #include <net/xsk_buff_pool.h>
12 #ifdef CONFIG_XDP_SOCKETS
14 void xsk_umem_complete_tx(struct xdp_umem *umem, u32 nb_entries);
15 bool xsk_umem_consume_tx(struct xdp_umem *umem, struct xdp_desc *desc);
16 void xsk_umem_consume_tx_done(struct xdp_umem *umem);
17 struct xdp_umem *xdp_get_umem_from_qid(struct net_device *dev, u16 queue_id);
18 void xsk_set_rx_need_wakeup(struct xdp_umem *umem);
19 void xsk_set_tx_need_wakeup(struct xdp_umem *umem);
20 void xsk_clear_rx_need_wakeup(struct xdp_umem *umem);
21 void xsk_clear_tx_need_wakeup(struct xdp_umem *umem);
22 bool xsk_umem_uses_need_wakeup(struct xdp_umem *umem);
24 static inline u32 xsk_umem_get_headroom(struct xdp_umem *umem)
26 return XDP_PACKET_HEADROOM + umem->headroom;
29 static inline u32 xsk_umem_get_chunk_size(struct xdp_umem *umem)
31 return umem->chunk_size;
34 static inline u32 xsk_umem_get_rx_frame_size(struct xdp_umem *umem)
36 return xsk_umem_get_chunk_size(umem) - xsk_umem_get_headroom(umem);
39 static inline void xsk_buff_set_rxq_info(struct xdp_umem *umem,
40 struct xdp_rxq_info *rxq)
42 xp_set_rxq_info(umem->pool, rxq);
45 static inline void xsk_buff_dma_unmap(struct xdp_umem *umem,
46 unsigned long attrs)
48 xp_dma_unmap(umem->pool, attrs);
51 static inline int xsk_buff_dma_map(struct xdp_umem *umem, struct device *dev,
52 unsigned long attrs)
54 return xp_dma_map(umem->pool, dev, attrs, umem->pgs, umem->npgs);
57 static inline dma_addr_t xsk_buff_xdp_get_dma(struct xdp_buff *xdp)
59 struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp);
61 return xp_get_dma(xskb);
64 static inline dma_addr_t xsk_buff_xdp_get_frame_dma(struct xdp_buff *xdp)
66 struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp);
68 return xp_get_frame_dma(xskb);
71 static inline struct xdp_buff *xsk_buff_alloc(struct xdp_umem *umem)
73 return xp_alloc(umem->pool);
76 static inline bool xsk_buff_can_alloc(struct xdp_umem *umem, u32 count)
78 return xp_can_alloc(umem->pool, count);
81 static inline void xsk_buff_free(struct xdp_buff *xdp)
83 struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp);
85 xp_free(xskb);
88 static inline dma_addr_t xsk_buff_raw_get_dma(struct xdp_umem *umem, u64 addr)
90 return xp_raw_get_dma(umem->pool, addr);
93 static inline void *xsk_buff_raw_get_data(struct xdp_umem *umem, u64 addr)
95 return xp_raw_get_data(umem->pool, addr);
98 static inline void xsk_buff_dma_sync_for_cpu(struct xdp_buff *xdp)
100 struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp);
102 xp_dma_sync_for_cpu(xskb);
105 static inline void xsk_buff_raw_dma_sync_for_device(struct xdp_umem *umem,
106 dma_addr_t dma,
107 size_t size)
109 xp_dma_sync_for_device(umem->pool, dma, size);
112 #else
114 static inline void xsk_umem_complete_tx(struct xdp_umem *umem, u32 nb_entries)
118 static inline bool xsk_umem_consume_tx(struct xdp_umem *umem,
119 struct xdp_desc *desc)
121 return false;
124 static inline void xsk_umem_consume_tx_done(struct xdp_umem *umem)
128 static inline struct xdp_umem *xdp_get_umem_from_qid(struct net_device *dev,
129 u16 queue_id)
131 return NULL;
134 static inline void xsk_set_rx_need_wakeup(struct xdp_umem *umem)
138 static inline void xsk_set_tx_need_wakeup(struct xdp_umem *umem)
142 static inline void xsk_clear_rx_need_wakeup(struct xdp_umem *umem)
146 static inline void xsk_clear_tx_need_wakeup(struct xdp_umem *umem)
150 static inline bool xsk_umem_uses_need_wakeup(struct xdp_umem *umem)
152 return false;
155 static inline u32 xsk_umem_get_headroom(struct xdp_umem *umem)
157 return 0;
160 static inline u32 xsk_umem_get_chunk_size(struct xdp_umem *umem)
162 return 0;
165 static inline u32 xsk_umem_get_rx_frame_size(struct xdp_umem *umem)
167 return 0;
170 static inline void xsk_buff_set_rxq_info(struct xdp_umem *umem,
171 struct xdp_rxq_info *rxq)
175 static inline void xsk_buff_dma_unmap(struct xdp_umem *umem,
176 unsigned long attrs)
180 static inline int xsk_buff_dma_map(struct xdp_umem *umem, struct device *dev,
181 unsigned long attrs)
183 return 0;
186 static inline dma_addr_t xsk_buff_xdp_get_dma(struct xdp_buff *xdp)
188 return 0;
191 static inline dma_addr_t xsk_buff_xdp_get_frame_dma(struct xdp_buff *xdp)
193 return 0;
196 static inline struct xdp_buff *xsk_buff_alloc(struct xdp_umem *umem)
198 return NULL;
201 static inline bool xsk_buff_can_alloc(struct xdp_umem *umem, u32 count)
203 return false;
206 static inline void xsk_buff_free(struct xdp_buff *xdp)
210 static inline dma_addr_t xsk_buff_raw_get_dma(struct xdp_umem *umem, u64 addr)
212 return 0;
215 static inline void *xsk_buff_raw_get_data(struct xdp_umem *umem, u64 addr)
217 return NULL;
220 static inline void xsk_buff_dma_sync_for_cpu(struct xdp_buff *xdp)
224 static inline void xsk_buff_raw_dma_sync_for_device(struct xdp_umem *umem,
225 dma_addr_t dma,
226 size_t size)
230 #endif /* CONFIG_XDP_SOCKETS */
232 #endif /* _LINUX_XDP_SOCK_DRV_H */