@@ -5078,6 +5078,10 @@ void netif_set_tso_max_segs(struct net_device *dev, unsigned int segs);
void netif_inherit_tso_max(struct net_device *to,
const struct net_device *from);
+struct page_pool_iov *
+netdev_alloc_devmem(struct netdev_dmabuf_binding *binding);
+void netdev_free_devmem(struct page_pool_iov *ppiov);
+
void netdev_unbind_dmabuf_to_queue(struct netdev_dmabuf_binding *binding);
int netdev_bind_dmabuf_to_queue(struct net_device *dev, unsigned int dmabuf_fd,
u32 rxq_idx,
@@ -197,6 +197,32 @@ struct page_pool_iov {
refcount_t refcount;
};
+static inline struct dmabuf_genpool_chunk_owner *
+page_pool_iov_owner(const struct page_pool_iov *ppiov)
+{
+ return ppiov->owner;
+}
+
+static inline unsigned int page_pool_iov_idx(const struct page_pool_iov *ppiov)
+{
+ return ppiov - page_pool_iov_owner(ppiov)->ppiovs;
+}
+
+static inline dma_addr_t
+page_pool_iov_dma_addr(const struct page_pool_iov *ppiov)
+{
+ struct dmabuf_genpool_chunk_owner *owner = page_pool_iov_owner(ppiov);
+
+ return owner->base_dma_addr +
+ ((dma_addr_t)page_pool_iov_idx(ppiov) << PAGE_SHIFT);
+}
+
+static inline struct netdev_dmabuf_binding *
+page_pool_iov_binding(const struct page_pool_iov *ppiov)
+{
+ return page_pool_iov_owner(ppiov)->binding;
+}
+
struct page_pool {
struct page_pool_params p;
@@ -2072,6 +2072,42 @@ void __netdev_devmem_binding_free(struct netdev_dmabuf_binding *binding)
kfree(binding);
}
+struct page_pool_iov *netdev_alloc_devmem(struct netdev_dmabuf_binding *binding)
+{
+ struct dmabuf_genpool_chunk_owner *owner;
+ struct page_pool_iov *ppiov;
+ unsigned long dma_addr;
+ ssize_t offset;
+ ssize_t index;
+
+ dma_addr = gen_pool_alloc_owner(binding->chunk_pool, PAGE_SIZE,
+ (void **)&owner);
+ if (!dma_addr)
+ return NULL;
+
+ offset = dma_addr - owner->base_dma_addr;
+ index = offset / PAGE_SIZE;
+ ppiov = &owner->ppiovs[index];
+
+ netdev_devmem_binding_get(binding);
+
+ return ppiov;
+}
+
+void netdev_free_devmem(struct page_pool_iov *ppiov)
+{
+ struct netdev_dmabuf_binding *binding = page_pool_iov_binding(ppiov);
+
+ refcount_set(&ppiov->refcount, 1);
+
+ if (gen_pool_has_addr(binding->chunk_pool,
+ page_pool_iov_dma_addr(ppiov), PAGE_SIZE))
+ gen_pool_free(binding->chunk_pool,
+ page_pool_iov_dma_addr(ppiov), PAGE_SIZE);
+
+ netdev_devmem_binding_put(binding);
+}
+
void netdev_unbind_dmabuf_to_queue(struct netdev_dmabuf_binding *binding)
{
struct netdev_rx_queue *rxq;