net: page pool: allow to pass zero flags to page_pool_init()
Subsystems (3)
PATCH 1/1 net: page pool: allow to pass zero flags to page_pool_init()
page pool API can be useful for non-DMA cases like xen-netfront driver so let's allow to pass zero flags to page pool flags.
--- net/core/page_pool.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-)
net/core/page_pool.c +19 -17
@@ -39,27 +39,29 @@ static int page_pool_init(struct page_pool *pool,if (ring_qsize >32768 )return -E2BIG ; -/* DMA direction is either DMA_FROM_DEVICE or DMA_BIDIRECTIONAL. -* DMA_BIDIRECTIONAL is for allowing page used for DMA sending, -* which is the XDP_TX use-case. -*/ -if ((pool->p.dma_dir !=DMA_FROM_DEVICE ) && - (pool->p.dma_dir !=DMA_BIDIRECTIONAL )) -return -EINVAL ; - -if (pool->p.flags &PP_FLAG_DMA_SYNC_DEV ) { -/* In order to request DMA-sync-for-device the page -* needs to be mapped +if (pool->p.flags) { +/* DMA direction is either DMA_FROM_DEVICE or DMA_BIDIRECTIONAL. +* DMA_BIDIRECTIONAL is for allowing page used for DMA sending, +* which is the XDP_TX use-case. */ -if (!(pool->p.flags &PP_FLAG_DMA_MAP )) +if ((pool->p.dma_dir !=DMA_FROM_DEVICE ) && + (pool->p.dma_dir !=DMA_BIDIRECTIONAL ))return -EINVAL ; -if (!pool->p.max_len) -return -EINVAL ; +if (pool->p.flags &PP_FLAG_DMA_SYNC_DEV ) { +/* In order to request DMA-sync-for-device the page +* needs to be mapped +*/ +if (!(pool->p.flags &PP_FLAG_DMA_MAP )) +return -EINVAL ; -/* pool->p.offset has to be set according to the address -* offset used by the DMA engine to start copying rx data -*/ +if (!pool->p.max_len) +return -EINVAL ; + +/* pool->p.offset has to be set according to the address +* offset used by the DMA engine to start copying rx data +*/ + } }if (ptr_ring_init (&pool->ring, ring_qsize,GFP_KERNEL ) <0 )
Signature · 1 line
1.8.3.1
Quoted 8 lines · On Wed, 25 Mar 2020 17:12:55 +0300 Denis Kirjanov <[email protected]> wrote:
page pool API can be useful for non-DMA cases like xen-netfront driver so let's allow to pass zero flags to page pool flags.
Signed-off-by Denis Kirjanov <[email protected]>--- net/core/page_pool.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-)
The pool->p.dma_dir is only used when flag PP_FLAG_DMA_MAP is used, so it looks more simple to do:
$ git diff
net/core/page_pool.c +5 -3
@@ -43,9 +43,11 @@ static int page_pool_init(struct page_pool *pool,* DMA_BIDIRECTIONAL is for allowing page used for DMA sending, * which is the XDP_TX use-case. */ -if ((pool->p.dma_dir !=DMA_FROM_DEVICE ) && - (pool->p.dma_dir !=DMA_BIDIRECTIONAL )) -return -EINVAL ; +if (pool->p.flags &PP_FLAG_DMA_MAP ) { +if ((pool->p.dma_dir !=DMA_FROM_DEVICE ) && + (pool->p.dma_dir !=DMA_BIDIRECTIONAL )) +return -EINVAL ; + }
Quoted 51 lines
net/core/page_pool.c +19
-17@@ -39,27 +39,29 @@ static int page_pool_init(struct page_pool *pool,if (ring_qsize >32768 )return -E2BIG ; -/* DMA direction is either DMA_FROM_DEVICE or DMA_BIDIRECTIONAL. -* DMA_BIDIRECTIONAL is for allowing page used for DMA sending, -* which is the XDP_TX use-case. -*/ -if ((pool->p.dma_dir !=DMA_FROM_DEVICE ) && - (pool->p.dma_dir !=DMA_BIDIRECTIONAL )) -return -EINVAL ; - -if (pool->p.flags &PP_FLAG_DMA_SYNC_DEV ) { -/* In order to request DMA-sync-for-device the page -* needs to be mapped +if (pool->p.flags) { +/* DMA direction is either DMA_FROM_DEVICE or DMA_BIDIRECTIONAL. +* DMA_BIDIRECTIONAL is for allowing page used for DMA sending, +* which is the XDP_TX use-case. */ -if (!(pool->p.flags &PP_FLAG_DMA_MAP )) +if ((pool->p.dma_dir !=DMA_FROM_DEVICE ) && + (pool->p.dma_dir !=DMA_BIDIRECTIONAL ))return -EINVAL ; -if (!pool->p.max_len) -return -EINVAL ; +if (pool->p.flags &PP_FLAG_DMA_SYNC_DEV ) { +/* In order to request DMA-sync-for-device the page +* needs to be mapped +*/ +if (!(pool->p.flags &PP_FLAG_DMA_MAP )) +return -EINVAL ; -/* pool->p.offset has to be set according to the address -* offset used by the DMA engine to start copying rx data -*/ +if (!pool->p.max_len) +return -EINVAL ; + +/* pool->p.offset has to be set according to the address +* offset used by the DMA engine to start copying rx data +*/ + } }if (ptr_ring_init (&pool->ring, ring_qsize,GFP_KERNEL ) <0 )
Signature · 4 lines
Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer
Quoted 7 lines · Jesper Dangaard Brouer
Quoted 4 lines · On Wed, 25 Mar 2020 17:12:55 +0300 Denis Kirjanov <[email protected]> wrote:
page pool API can be useful for non-DMA cases like xen-netfront driver so let's allow to pass zero flags to page pool flags.
Quoted 7 lines
Quoted 4 lines
Signed-off-by Denis Kirjanov <[email protected]>--- net/core/page_pool.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-)The
pool->p.dma_diris only used when flagPP_FLAG_DMA_MAPis used, so it looks more simple to do:
Yeap, agreed. Thanks!
Quoted 82 lines
$ git diffnet/core/page_pool.c +5
-3@@ -43,9 +43,11 @@ static int page_pool_init(struct page_pool *pool,* DMA_BIDIRECTIONAL is for allowing page used for DMA sending, * which is the XDP_TX use-case. */ -if ((pool->p.dma_dir !=DMA_FROM_DEVICE ) && - (pool->p.dma_dir !=DMA_BIDIRECTIONAL )) -return -EINVAL ; +if (pool->p.flags &PP_FLAG_DMA_MAP ) { +if ((pool->p.dma_dir !=DMA_FROM_DEVICE ) && + (pool->p.dma_dir !=DMA_BIDIRECTIONAL )) +return -EINVAL ; + }Quoted 41 lines
net/core/page_pool.c +12
-17@@ -39,27 +39,29 @@ static int page_pool_init(struct page_pool *pool,if (ring_qsize >32768 )return -E2BIG ; -/* DMA direction is either DMA_FROM_DEVICE or DMA_BIDIRECTIONAL. -* DMA_BIDIRECTIONAL is for allowing page used for DMA sending, -* which is the XDP_TX use-case. -*/ -if ((pool->p.dma_dir !=DMA_FROM_DEVICE ) && - (pool->p.dma_dir !=DMA_BIDIRECTIONAL )) -return -EINVAL ; - -if (pool->p.flags &PP_FLAG_DMA_SYNC_DEV ) { -/* In order to request DMA-sync-for-device the page -* needs to be mapped +if (pool->p.flags) { +/* DMA direction is either DMA_FROM_DEVICE or DMA_BIDIRECTIONAL. +* DMA_BIDIRECTIONAL is for allowing page used for DMA sending, +* which is the XDP_TX use-case. */ -if (!(pool->p.flags &PP_FLAG_DMA_MAP )) +if ((pool->p.dma_dir !=DMA_FROM_DEVICE ) && + (pool->p.dma_dir !=DMA_BIDIRECTIONAL ))return -EINVAL ; -if (!pool->p.max_len) -return -EINVAL ; +if (pool->p.flags &PP_FLAG_DMA_SYNC_DEV ) { +/* In order to request DMA-sync-for-device the page +* needs to be mapped +*/ +if (!(pool->p.flags &PP_FLAG_DMA_MAP )) +return -EINVAL ; -/* pool->p.offset has to be set according to the address -* offset used by the DMA engine to start copying rx data -*/ net/core/page_pool.c static int page_pool_init(struct page_pool *pool, · line 67
Quoted 10 lines
net/core/page_pool.c +7
-0+if (!pool->p.max_len) +return -EINVAL ; + +/* pool->p.offset has to be set according to the address +* offset used by the DMA engine to start copying rx data +*/ + } }if (ptr_ring_init (&pool->ring, ring_qsize,GFP_KERNEL ) <0 )--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Principal Kernel Engineer at Red Hat
LinkedIn: http://www.linkedin.com/in/brouer