xref: /linux/include/net/page_pool/memory_provider.h (revision 2f435137a0484f11b47554281091ef4908f8cb31)
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 sk_buff;
10 
11 struct memory_provider_ops {
12 	netmem_ref (*alloc_netmems)(struct page_pool *pool, gfp_t gfp);
13 	bool (*release_netmem)(struct page_pool *pool, netmem_ref netmem);
14 	int (*init)(struct page_pool *pool);
15 	void (*destroy)(struct page_pool *pool);
16 	int (*nl_fill)(void *mp_priv, struct sk_buff *rsp,
17 		       struct netdev_rx_queue *rxq);
18 	void (*uninstall)(void *mp_priv, struct netdev_rx_queue *rxq);
19 };
20 
21 bool net_mp_niov_set_dma_addr(struct net_iov *niov, dma_addr_t addr);
22 void net_mp_niov_set_page_pool(struct page_pool *pool, struct net_iov *niov);
23 void net_mp_niov_clear_page_pool(struct net_iov *niov);
24 
25 int net_mp_open_rxq(struct net_device *dev, unsigned ifq_idx,
26 		    struct pp_memory_provider_params *p);
27 void net_mp_close_rxq(struct net_device *dev, unsigned ifq_idx,
28 		      struct pp_memory_provider_params *old_p);
29 
30 /**
31   * net_mp_netmem_place_in_cache() - give a netmem to a page pool
32   * @pool:      the page pool to place the netmem into
33   * @netmem:    netmem to give
34   *
35   * Push an accounted netmem into the page pool's allocation cache. The caller
36   * must ensure that there is space in the cache. It should only be called off
37   * the mp_ops->alloc_netmems() path.
38   */
39 static inline void net_mp_netmem_place_in_cache(struct page_pool *pool,
40 						netmem_ref netmem)
41 {
42 	pool->alloc.cache[pool->alloc.count++] = netmem;
43 }
44 
45 #endif
46