18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* Interface for implementing AF_XDP zero-copy support in drivers. 38c2ecf20Sopenharmony_ci * Copyright(c) 2020 Intel Corporation. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef _LINUX_XDP_SOCK_DRV_H 78c2ecf20Sopenharmony_ci#define _LINUX_XDP_SOCK_DRV_H 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <net/xdp_sock.h> 108c2ecf20Sopenharmony_ci#include <net/xsk_buff_pool.h> 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#ifdef CONFIG_XDP_SOCKETS 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_civoid xsk_tx_completed(struct xsk_buff_pool *pool, u32 nb_entries); 158c2ecf20Sopenharmony_cibool xsk_tx_peek_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc); 168c2ecf20Sopenharmony_civoid xsk_tx_release(struct xsk_buff_pool *pool); 178c2ecf20Sopenharmony_cistruct xsk_buff_pool *xsk_get_pool_from_qid(struct net_device *dev, 188c2ecf20Sopenharmony_ci u16 queue_id); 198c2ecf20Sopenharmony_civoid xsk_set_rx_need_wakeup(struct xsk_buff_pool *pool); 208c2ecf20Sopenharmony_civoid xsk_set_tx_need_wakeup(struct xsk_buff_pool *pool); 218c2ecf20Sopenharmony_civoid xsk_clear_rx_need_wakeup(struct xsk_buff_pool *pool); 228c2ecf20Sopenharmony_civoid xsk_clear_tx_need_wakeup(struct xsk_buff_pool *pool); 238c2ecf20Sopenharmony_cibool xsk_uses_need_wakeup(struct xsk_buff_pool *pool); 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_cistatic inline u32 xsk_pool_get_headroom(struct xsk_buff_pool *pool) 268c2ecf20Sopenharmony_ci{ 278c2ecf20Sopenharmony_ci return XDP_PACKET_HEADROOM + pool->headroom; 288c2ecf20Sopenharmony_ci} 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_cistatic inline u32 xsk_pool_get_chunk_size(struct xsk_buff_pool *pool) 318c2ecf20Sopenharmony_ci{ 328c2ecf20Sopenharmony_ci return pool->chunk_size; 338c2ecf20Sopenharmony_ci} 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_cistatic inline u32 xsk_pool_get_rx_frame_size(struct xsk_buff_pool *pool) 368c2ecf20Sopenharmony_ci{ 378c2ecf20Sopenharmony_ci return xsk_pool_get_chunk_size(pool) - xsk_pool_get_headroom(pool); 388c2ecf20Sopenharmony_ci} 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistatic inline void xsk_pool_set_rxq_info(struct xsk_buff_pool *pool, 418c2ecf20Sopenharmony_ci struct xdp_rxq_info *rxq) 428c2ecf20Sopenharmony_ci{ 438c2ecf20Sopenharmony_ci xp_set_rxq_info(pool, rxq); 448c2ecf20Sopenharmony_ci} 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cistatic inline void xsk_pool_dma_unmap(struct xsk_buff_pool *pool, 478c2ecf20Sopenharmony_ci unsigned long attrs) 488c2ecf20Sopenharmony_ci{ 498c2ecf20Sopenharmony_ci xp_dma_unmap(pool, attrs); 508c2ecf20Sopenharmony_ci} 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistatic inline int xsk_pool_dma_map(struct xsk_buff_pool *pool, 538c2ecf20Sopenharmony_ci struct device *dev, unsigned long attrs) 548c2ecf20Sopenharmony_ci{ 558c2ecf20Sopenharmony_ci struct xdp_umem *umem = pool->umem; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci return xp_dma_map(pool, dev, attrs, umem->pgs, umem->npgs); 588c2ecf20Sopenharmony_ci} 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_cistatic inline dma_addr_t xsk_buff_xdp_get_dma(struct xdp_buff *xdp) 618c2ecf20Sopenharmony_ci{ 628c2ecf20Sopenharmony_ci struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp); 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci return xp_get_dma(xskb); 658c2ecf20Sopenharmony_ci} 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_cistatic inline dma_addr_t xsk_buff_xdp_get_frame_dma(struct xdp_buff *xdp) 688c2ecf20Sopenharmony_ci{ 698c2ecf20Sopenharmony_ci struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp); 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci return xp_get_frame_dma(xskb); 728c2ecf20Sopenharmony_ci} 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_cistatic inline struct xdp_buff *xsk_buff_alloc(struct xsk_buff_pool *pool) 758c2ecf20Sopenharmony_ci{ 768c2ecf20Sopenharmony_ci return xp_alloc(pool); 778c2ecf20Sopenharmony_ci} 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_cistatic inline bool xsk_buff_can_alloc(struct xsk_buff_pool *pool, u32 count) 808c2ecf20Sopenharmony_ci{ 818c2ecf20Sopenharmony_ci return xp_can_alloc(pool, count); 828c2ecf20Sopenharmony_ci} 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_cistatic inline void xsk_buff_free(struct xdp_buff *xdp) 858c2ecf20Sopenharmony_ci{ 868c2ecf20Sopenharmony_ci struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp); 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci xp_free(xskb); 898c2ecf20Sopenharmony_ci} 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cistatic inline dma_addr_t xsk_buff_raw_get_dma(struct xsk_buff_pool *pool, 928c2ecf20Sopenharmony_ci u64 addr) 938c2ecf20Sopenharmony_ci{ 948c2ecf20Sopenharmony_ci return xp_raw_get_dma(pool, addr); 958c2ecf20Sopenharmony_ci} 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_cistatic inline void *xsk_buff_raw_get_data(struct xsk_buff_pool *pool, u64 addr) 988c2ecf20Sopenharmony_ci{ 998c2ecf20Sopenharmony_ci return xp_raw_get_data(pool, addr); 1008c2ecf20Sopenharmony_ci} 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_cistatic inline void xsk_buff_dma_sync_for_cpu(struct xdp_buff *xdp, struct xsk_buff_pool *pool) 1038c2ecf20Sopenharmony_ci{ 1048c2ecf20Sopenharmony_ci struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp); 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci if (!pool->dma_need_sync) 1078c2ecf20Sopenharmony_ci return; 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci xp_dma_sync_for_cpu(xskb); 1108c2ecf20Sopenharmony_ci} 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_cistatic inline void xsk_buff_raw_dma_sync_for_device(struct xsk_buff_pool *pool, 1138c2ecf20Sopenharmony_ci dma_addr_t dma, 1148c2ecf20Sopenharmony_ci size_t size) 1158c2ecf20Sopenharmony_ci{ 1168c2ecf20Sopenharmony_ci xp_dma_sync_for_device(pool, dma, size); 1178c2ecf20Sopenharmony_ci} 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci#else 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_cistatic inline void xsk_tx_completed(struct xsk_buff_pool *pool, u32 nb_entries) 1228c2ecf20Sopenharmony_ci{ 1238c2ecf20Sopenharmony_ci} 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_cistatic inline bool xsk_tx_peek_desc(struct xsk_buff_pool *pool, 1268c2ecf20Sopenharmony_ci struct xdp_desc *desc) 1278c2ecf20Sopenharmony_ci{ 1288c2ecf20Sopenharmony_ci return false; 1298c2ecf20Sopenharmony_ci} 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_cistatic inline void xsk_tx_release(struct xsk_buff_pool *pool) 1328c2ecf20Sopenharmony_ci{ 1338c2ecf20Sopenharmony_ci} 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_cistatic inline struct xsk_buff_pool * 1368c2ecf20Sopenharmony_cixsk_get_pool_from_qid(struct net_device *dev, u16 queue_id) 1378c2ecf20Sopenharmony_ci{ 1388c2ecf20Sopenharmony_ci return NULL; 1398c2ecf20Sopenharmony_ci} 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_cistatic inline void xsk_set_rx_need_wakeup(struct xsk_buff_pool *pool) 1428c2ecf20Sopenharmony_ci{ 1438c2ecf20Sopenharmony_ci} 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_cistatic inline void xsk_set_tx_need_wakeup(struct xsk_buff_pool *pool) 1468c2ecf20Sopenharmony_ci{ 1478c2ecf20Sopenharmony_ci} 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_cistatic inline void xsk_clear_rx_need_wakeup(struct xsk_buff_pool *pool) 1508c2ecf20Sopenharmony_ci{ 1518c2ecf20Sopenharmony_ci} 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_cistatic inline void xsk_clear_tx_need_wakeup(struct xsk_buff_pool *pool) 1548c2ecf20Sopenharmony_ci{ 1558c2ecf20Sopenharmony_ci} 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_cistatic inline bool xsk_uses_need_wakeup(struct xsk_buff_pool *pool) 1588c2ecf20Sopenharmony_ci{ 1598c2ecf20Sopenharmony_ci return false; 1608c2ecf20Sopenharmony_ci} 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_cistatic inline u32 xsk_pool_get_headroom(struct xsk_buff_pool *pool) 1638c2ecf20Sopenharmony_ci{ 1648c2ecf20Sopenharmony_ci return 0; 1658c2ecf20Sopenharmony_ci} 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_cistatic inline u32 xsk_pool_get_chunk_size(struct xsk_buff_pool *pool) 1688c2ecf20Sopenharmony_ci{ 1698c2ecf20Sopenharmony_ci return 0; 1708c2ecf20Sopenharmony_ci} 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_cistatic inline u32 xsk_pool_get_rx_frame_size(struct xsk_buff_pool *pool) 1738c2ecf20Sopenharmony_ci{ 1748c2ecf20Sopenharmony_ci return 0; 1758c2ecf20Sopenharmony_ci} 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_cistatic inline void xsk_pool_set_rxq_info(struct xsk_buff_pool *pool, 1788c2ecf20Sopenharmony_ci struct xdp_rxq_info *rxq) 1798c2ecf20Sopenharmony_ci{ 1808c2ecf20Sopenharmony_ci} 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_cistatic inline void xsk_pool_dma_unmap(struct xsk_buff_pool *pool, 1838c2ecf20Sopenharmony_ci unsigned long attrs) 1848c2ecf20Sopenharmony_ci{ 1858c2ecf20Sopenharmony_ci} 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_cistatic inline int xsk_pool_dma_map(struct xsk_buff_pool *pool, 1888c2ecf20Sopenharmony_ci struct device *dev, unsigned long attrs) 1898c2ecf20Sopenharmony_ci{ 1908c2ecf20Sopenharmony_ci return 0; 1918c2ecf20Sopenharmony_ci} 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_cistatic inline dma_addr_t xsk_buff_xdp_get_dma(struct xdp_buff *xdp) 1948c2ecf20Sopenharmony_ci{ 1958c2ecf20Sopenharmony_ci return 0; 1968c2ecf20Sopenharmony_ci} 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_cistatic inline dma_addr_t xsk_buff_xdp_get_frame_dma(struct xdp_buff *xdp) 1998c2ecf20Sopenharmony_ci{ 2008c2ecf20Sopenharmony_ci return 0; 2018c2ecf20Sopenharmony_ci} 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_cistatic inline struct xdp_buff *xsk_buff_alloc(struct xsk_buff_pool *pool) 2048c2ecf20Sopenharmony_ci{ 2058c2ecf20Sopenharmony_ci return NULL; 2068c2ecf20Sopenharmony_ci} 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_cistatic inline bool xsk_buff_can_alloc(struct xsk_buff_pool *pool, u32 count) 2098c2ecf20Sopenharmony_ci{ 2108c2ecf20Sopenharmony_ci return false; 2118c2ecf20Sopenharmony_ci} 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_cistatic inline void xsk_buff_free(struct xdp_buff *xdp) 2148c2ecf20Sopenharmony_ci{ 2158c2ecf20Sopenharmony_ci} 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_cistatic inline dma_addr_t xsk_buff_raw_get_dma(struct xsk_buff_pool *pool, 2188c2ecf20Sopenharmony_ci u64 addr) 2198c2ecf20Sopenharmony_ci{ 2208c2ecf20Sopenharmony_ci return 0; 2218c2ecf20Sopenharmony_ci} 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_cistatic inline void *xsk_buff_raw_get_data(struct xsk_buff_pool *pool, u64 addr) 2248c2ecf20Sopenharmony_ci{ 2258c2ecf20Sopenharmony_ci return NULL; 2268c2ecf20Sopenharmony_ci} 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_cistatic inline void xsk_buff_dma_sync_for_cpu(struct xdp_buff *xdp, struct xsk_buff_pool *pool) 2298c2ecf20Sopenharmony_ci{ 2308c2ecf20Sopenharmony_ci} 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_cistatic inline void xsk_buff_raw_dma_sync_for_device(struct xsk_buff_pool *pool, 2338c2ecf20Sopenharmony_ci dma_addr_t dma, 2348c2ecf20Sopenharmony_ci size_t size) 2358c2ecf20Sopenharmony_ci{ 2368c2ecf20Sopenharmony_ci} 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci#endif /* CONFIG_XDP_SOCKETS */ 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci#endif /* _LINUX_XDP_SOCK_DRV_H */ 241