memory_provider.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _NET_PAGE_POOL_MEMORY_PROVIDER_H
  3. #define _NET_PAGE_POOL_MEMORY_PROVIDER_H
  4. #include <net/netmem.h>
  5. #include <net/page_pool/types.h>
  6. struct netdev_rx_queue;
  7. struct netlink_ext_ack;
  8. struct sk_buff;
  9. struct memory_provider_ops {
  10. netmem_ref (*alloc_netmems)(struct page_pool *pool, gfp_t gfp);
  11. bool (*release_netmem)(struct page_pool *pool, netmem_ref netmem);
  12. int (*init)(struct page_pool *pool);
  13. void (*destroy)(struct page_pool *pool);
  14. int (*nl_fill)(void *mp_priv, struct sk_buff *rsp,
  15. struct netdev_rx_queue *rxq);
  16. void (*uninstall)(void *mp_priv, struct netdev_rx_queue *rxq);
  17. };
  18. bool net_mp_niov_set_dma_addr(struct net_iov *niov, dma_addr_t addr);
  19. void net_mp_niov_set_page_pool(struct page_pool *pool, struct net_iov *niov);
  20. void net_mp_niov_clear_page_pool(struct net_iov *niov);
  21. int net_mp_open_rxq(struct net_device *dev, unsigned ifq_idx,
  22. struct pp_memory_provider_params *p);
  23. int __net_mp_open_rxq(struct net_device *dev, unsigned int rxq_idx,
  24. const struct pp_memory_provider_params *p,
  25. struct netlink_ext_ack *extack);
  26. void net_mp_close_rxq(struct net_device *dev, unsigned ifq_idx,
  27. struct pp_memory_provider_params *old_p);
  28. void __net_mp_close_rxq(struct net_device *dev, unsigned int rxq_idx,
  29. const struct pp_memory_provider_params *old_p);
  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. #endif