1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Interface for implementing AF_XDP zero-copy support in drivers.
3 * Copyright(c) 2020 Intel Corporation.
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,
48 xp_dma_unmap(umem->pool, attrs);
51 static inline int xsk_buff_dma_map(struct xdp_umem *umem, struct device *dev,
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);
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,
109 xp_dma_sync_for_device(umem->pool, dma, size);
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)
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,
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)
155 static inline u32 xsk_umem_get_headroom(struct xdp_umem *umem)
160 static inline u32 xsk_umem_get_chunk_size(struct xdp_umem *umem)
165 static inline u32 xsk_umem_get_rx_frame_size(struct xdp_umem *umem)
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,
180 static inline int xsk_buff_dma_map(struct xdp_umem *umem, struct device *dev,
186 static inline dma_addr_t xsk_buff_xdp_get_dma(struct xdp_buff *xdp)
191 static inline dma_addr_t xsk_buff_xdp_get_frame_dma(struct xdp_buff *xdp)
196 static inline struct xdp_buff *xsk_buff_alloc(struct xdp_umem *umem)
201 static inline bool xsk_buff_can_alloc(struct xdp_umem *umem, u32 count)
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)
215 static inline void *xsk_buff_raw_get_data(struct xdp_umem *umem, u64 addr)
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,
230 #endif /* CONFIG_XDP_SOCKETS */
232 #endif /* _LINUX_XDP_SOCK_DRV_H */