1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _NET_PAGE_POOL_MEMORY_PROVIDER_H 3 #define _NET_PAGE_POOL_MEMORY_PROVIDER_H 4 5 #include <net/netmem.h> 6 #include <net/page_pool/types.h> 7 8 struct netdev_rx_queue; 9 struct netlink_ext_ack; 10 struct sk_buff; 11 12 /* Memory providers allocate underlying memory (struct net_iov or struct page), 13 * cast it to netmem_ref, and supply it to page_pool. While current memory 14 * providers only return struct net_iov, they are not architecturally limited to 15 * net_iov; a provider returning page-backed netmems is allowed. New code must 16 * not assume a memory provider implies net_iov and should, as much as possible, 17 * generalize existing limitations to match the design principles. 18 * 19 * Per-provider custom logic must be delegated to memory_provider_ops rather 20 * than handled directly in page_pool core code. 21 */ 22 struct memory_provider_ops { 23 netmem_ref (*alloc_netmems)(struct page_pool *pool, gfp_t gfp); 24 bool (*release_netmem)(struct page_pool *pool, netmem_ref netmem); 25 int (*init)(struct page_pool *pool); 26 void (*destroy)(struct page_pool *pool); 27 int (*nl_fill)(void *mp_priv, struct sk_buff *rsp, 28 struct netdev_rx_queue *rxq); 29 void (*uninstall)(void *mp_priv, struct netdev_rx_queue *rxq); 30 }; 31 32 bool net_mp_niov_set_dma_addr(struct net_iov *niov, dma_addr_t addr); 33 void net_mp_niov_set_page_pool(struct page_pool *pool, struct net_iov *niov); 34 void net_mp_niov_clear_page_pool(struct net_iov *niov); 35 36 int netif_mp_open_rxq(struct net_device *dev, unsigned int rxq_idx, 37 const struct pp_memory_provider_params *p, 38 struct netlink_ext_ack *extack); 39 void netif_mp_close_rxq(struct net_device *dev, unsigned int rxq_idx, 40 const struct pp_memory_provider_params *old_p); 41 42 /** 43 * net_mp_netmem_place_in_cache() - give a netmem to a page pool 44 * @pool: the page pool to place the netmem into 45 * @netmem: netmem to give 46 * 47 * Push an accounted netmem into the page pool's allocation cache. The caller 48 * must ensure that there is space in the cache. It should only be called off 49 * the mp_ops->alloc_netmems() path. 50 */ 51 static inline void net_mp_netmem_place_in_cache(struct page_pool *pool, 52 netmem_ref netmem) 53 { 54 pool->alloc.cache[pool->alloc.count++] = netmem; 55 } 56 57 #endif 58