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